Skip to content

Commit

Permalink
chore: synchronize workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Nov 19, 2024
1 parent 8138000 commit 53178c6
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 17 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ export PATH := .bin:${PATH}
.PHONY: install
install:
npm install
npx playwright install --with-deps

.PHONY: test
test:
npm run test

.PHONY: build
build:
npm run build
npx nx run-many --target=build --all
npx nx run-many --all --target=build-storybook -- --stats-json

.PHONY: dev
dev:
npm run build
npx nx run-many --target=dev --all

test-containerized:
# https://github.com/microsoft/playwright/issues/26482
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { OryPageHeaderProps, useComponents } from "@ory/elements-react"
import { UserMenu } from "../ui/user-menu"
import { useSession } from "../../../../client"
import { useSession } from "@ory/elements-react/client"

export const DefaultPageHeader = (_props: OryPageHeaderProps) => {
const { Card } = useComponents()
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function getCookieHeader() {
return h.get("cookie") ?? undefined
}

export const onRedirect: OnRedirectHandler = (url, external) => {
export const onRedirect: OnRedirectHandler = (url) => {
redirect(url)
}

Expand All @@ -28,5 +28,5 @@ export async function getPublicUrl() {
}

export interface OryPageParams {
searchParams: URLSearchParams
searchParams: Promise<URLSearchParams>
}
2 changes: 1 addition & 1 deletion packages/nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export type { OryConfig } from "./types"
export { enhanceConfig } from "./utils/config"
export { enhanceOryConfig } from "./utils/config"
16 changes: 8 additions & 8 deletions packages/nextjs/src/utils/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import { enhanceConfig } from "./config"
import { enhanceOryConfig } from "./config"
import { isProduction } from "./sdk"
import { OryConfig } from "../types"

Expand All @@ -23,37 +23,37 @@ describe("enhanceConfig", () => {

it("should use forceSdkUrl if provided", () => {
const config: Partial<OryConfig> = {}
const result = enhanceConfig(config, "https://forced-url.com")
const result = enhanceOryConfig(config, "https://forced-url.com")
expect(result.sdk.url).toBe("https://forced-url.com")
})

it("should use NEXT_PUBLIC_ORY_SDK_URL if forceSdkUrl is not provided", () => {
process.env["NEXT_PUBLIC_ORY_SDK_URL"] = "https://public-sdk-url.com"
const config: Partial<OryConfig> = {}
const result = enhanceConfig(config)
const result = enhanceOryConfig(config)
expect(result.sdk.url).toBe("https://public-sdk-url.com")
})

it("should use ORY_SDK_URL if NEXT_PUBLIC_ORY_SDK_URL is not provided", () => {
process.env["ORY_SDK_URL"] = "https://sdk-url.com"
const config: Partial<OryConfig> = {}
const result = enhanceConfig(config)
const result = enhanceOryConfig(config)
expect(result.sdk.url).toBe("https://sdk-url.com")
})

it("should use __NEXT_PRIVATE_ORIGIN if not in production and forceSdkUrl is not provided", () => {
;(isProduction as jest.Mock).mockReturnValue(false)
process.env["__NEXT_PRIVATE_ORIGIN"] = "https://private-origin.com/"
const config: Partial<OryConfig> = {}
const result = enhanceConfig(config)
const result = enhanceOryConfig(config)
expect(result.sdk.url).toBe("https://private-origin.com")
})

it("should use VERCEL_URL if __NEXT_PRIVATE_ORIGIN is not provided", () => {
;(isProduction as jest.Mock).mockReturnValue(false)
process.env["VERCEL_URL"] = "vercel-url.com"
const config: Partial<OryConfig> = {}
const result = enhanceConfig(config)
const result = enhanceOryConfig(config)
expect(result.sdk.url).toBe("https://vercel-url.com")
})

Expand All @@ -71,7 +71,7 @@ describe("enhanceConfig", () => {
},
}) as unknown as Window & typeof globalThis,
)
const result = enhanceConfig(config)
const result = enhanceOryConfig(config)
expect(result.sdk.url).toBe("https://window-origin.com")
windowSpy.mockRestore()
})
Expand All @@ -83,7 +83,7 @@ describe("enhanceConfig", () => {
delete process.env["__NEXT_PRIVATE_ORIGIN"]
delete process.env["VERCEL_URL"]
const config: Partial<OryConfig> = {}
expect(() => enhanceConfig(config)).toThrow(
expect(() => enhanceOryConfig(config)).toThrow(
"Unable to determine SDK URL. Please set NEXT_PUBLIC_ORY_SDK_URL and/or ORY_SDK_URL or force the SDK URL using `useOryConfig(config, 'https://my-ory-sdk-url.com')`.",
)
})
Expand Down
17 changes: 16 additions & 1 deletion packages/nextjs/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
import { OryConfig } from "../types"
import { isProduction } from "./sdk"

export function enhanceConfig(
/**
* Enhances the Ory config with defaults and SDK URL. The SDK URL is determined as follows:
*
* 1. If `forceSdkUrl` is provided, it is used.
* 2. If `forceSdkUrl` is not provided, the following environment variables are checked:
* - `NEXT_PUBLIC_ORY_SDK_URL`
* - `ORY_SDK_URL`
* - `__NEXT_PRIVATE_ORIGIN` (if not in production)
* - `VERCEL_URL` (if not in production)
* - `window.location.origin` (if not in production)
* - If none of the above are set, an error is thrown.
*
* @param config
* @param forceSdkUrl
*/
export function enhanceOryConfig(
config: Partial<OryConfig>,
forceSdkUrl?: string,
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/utils/cookie.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("cookie guesser", () => {
test("understands public suffix list", () => {
expect(
guessCookieDomain(
"https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv",
"https://spark-public.s3.amazonaws.com/self-service/login",
{},
),
).toEqual("spark-public.s3.amazonaws.com")
Expand Down
9 changes: 9 additions & 0 deletions packages/nextjs/src/utils/rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ export function rewriteUrls(
new URL(selfUrl).toString().replace(/\/$/, ""),
)
}

/**
* Rewrites Ory SDK URLs in JSON responses (objects, arrays, strings) with the provided proxy URL.
*
* If `proxyUrl` is provided, the SDK URL is replaced with the proxy URL.
*
* @param obj
* @param proxyUrl
*/
export function rewriteJsonResponse<T extends object>(
obj: T,
proxyUrl?: string,
Expand Down
1 change: 0 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@ory/nextjs": ["packages/nextjs/src/index.ts"],
"storybook-host": ["libs/storybook-host/src/index.ts"]
}
},
Expand Down

0 comments on commit 53178c6

Please sign in to comment.