Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to @ory/client 1.0.1 #225

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"@ory/client": "^0.2.0-alpha.48",
"@ory/elements-markup": "^0.0.1-alpha.26",
"@ory/client": "^1.0.1",
"@ory/elements-markup": "^0.0.1-alpha.27",
"@ory/integrations": "^0.2.8",
"axios": "^0.27.2",
"cookie-parser": "^1.4.5",
Expand Down
6 changes: 3 additions & 3 deletions src/pkg/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
import { UiNode } from "@ory/client"
import { FrontendApi, UiNode } from "@ory/client"
import { Typography, Divider, ButtonLink, MenuLink } from "@ory/elements-markup"
import { filterNodesByGroups, getNodeLabel } from "@ory/integrations/ui"
import { AxiosError } from "axios"
Expand All @@ -23,11 +23,11 @@ export const getUrlForFlow = (
query ? `?${query.toString()}` : ""
}`

export const defaultConfig: RouteOptionsCreator = () => {
export const defaultConfig = () => {
return {
apiBaseUrl: apiBaseUrl,
kratosBrowserUrl: apiBaseUrl,
sdk,
frontend: new FrontendApi(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
frontend: new FrontendApi(),
...sdk

That way you have frontend (and the other APIs) available, but they're setup with the correct configuration.

}
}

Expand Down
12 changes: 6 additions & 6 deletions src/pkg/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const addSessionToRequest =
export const requireAuth =
(createHelpers: RouteOptionsCreator) =>
(req: Request, res: Response, next: NextFunction) => {
const { sdk, apiBaseUrl } = createHelpers(req)
sdk
const { frontend, apiBaseUrl } = createHelpers(req)
frontend
.toSession(undefined, req.header("cookie"))
.then(addSessionToRequest(req))
.then(() => next())
Expand All @@ -78,8 +78,8 @@ export const requireAuth =
export const setSession =
(createHelpers: RouteOptionsCreator) =>
(req: Request, res: Response, next: NextFunction) => {
const { sdk, apiBaseUrl } = createHelpers(req)
sdk
const { frontend, apiBaseUrl } = createHelpers(req)
frontend
.toSession(undefined, req.header("cookie"))
.then(addSessionToRequest(req))
.catch(maybeInitiate2FA(res, apiBaseUrl))
Expand All @@ -95,8 +95,8 @@ export const setSession =
export const requireNoAuth =
(createHelpers: RouteOptionsCreator) =>
(req: Request, res: Response, next: NextFunction) => {
const { sdk } = createHelpers(req)
sdk
const { frontend } = createHelpers(req)
frontend
.toSession(undefined, req.header("cookie"))
.then(() => {
res.redirect("welcome")
Expand Down
8 changes: 6 additions & 2 deletions src/pkg/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
import { V0alpha2ApiInterface } from "@ory/client"
import {
FrontendApi,
FrontendApiInterface,
OAuth2ApiInterface,
} from "@ory/client"
import { Application, NextFunction, Request, Response } from "express"

export interface RouteOptions {
sdk: V0alpha2ApiInterface
frontend: FrontendApi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
frontend: FrontendApi
frontend: FrontendApi
identity: IdentityApi
oauth2: OAuth2Api

apiBaseUrl: string
kratosBrowserUrl: string
logo?: string
Expand Down
18 changes: 11 additions & 7 deletions src/pkg/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
import { Configuration, V0alpha2Api } from "@ory/client"
import { Configuration, FrontendApi, IdentityApi, OAuth2Api } from "@ory/client"

const apiBaseUrlInternal =
process.env.KRATOS_PUBLIC_URL ||
Expand All @@ -9,12 +9,16 @@ const apiBaseUrlInternal =

export const apiBaseUrl = process.env.KRATOS_BROWSER_URL || apiBaseUrlInternal

const config = new Configuration({
basePath: apiBaseUrlInternal,
// accessToken: "Your Ory Cloud API Key / Personal Access Token"
})

// Sets up the SDK
let sdk = new V0alpha2Api(
new Configuration({
basePath: apiBaseUrlInternal,
// accessToken: "Your Ory Cloud API Key / Personal Access Token"
}),
)
const sdk = {
identity: new IdentityApi(config),
frontend: new FrontendApi(config),
oauth2: new OAuth2Api(config),
}

export default sdk
6 changes: 3 additions & 3 deletions src/routes/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ export const createErrorRoute: RouteCreator =
const { id } = req.query

// Get the SDK
const { sdk, logo } = createHelpers(req)
const { frontend, logo } = createHelpers(req)

if (!isQuerySet(id)) {
// No error was send, redirecting back to home.
res.redirect("welcome")
return
}

sdk
.getSelfServiceError(id)
frontend
.getFlowError(id)
.then(({ data }) => {
res.status(200).render("error", {
card: UserErrorCard({
Expand Down
14 changes: 7 additions & 7 deletions src/routes/login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
import { SelfServiceLoginFlow, UiNodeInputAttributes } from "@ory/client"
import { LoginFlow, UiNodeInputAttributes } from "@ory/client"
import { UserAuthCard, SelfServiceFlow } from "@ory/elements-markup"
import {
filterNodesByGroups,
Expand All @@ -27,7 +27,7 @@ export const createLoginRoute: RouteCreator =
return_to = "",
login_challenge,
} = req.query
const { sdk, kratosBrowserUrl, logo } = createHelpers(req)
const { frontend, kratosBrowserUrl, logo } = createHelpers(req)

const initFlowQuery = new URLSearchParams({
aal: aal.toString(),
Expand Down Expand Up @@ -57,14 +57,14 @@ export const createLoginRoute: RouteCreator =
// to give the user the option to sign out!
const logoutUrl =
(
await sdk
.createSelfServiceLogoutFlowUrlForBrowsers(req.header("cookie"))
await frontend
.createBrowserLogoutFlow(req.header("cookie"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing these parameters as named parameters, they're now passed in a single params object. Could you update the usage of these methods as well? It won't compile otherwise.

.catch(() => ({ data: { logout_url: "" } }))
).data.logout_url || ""

return sdk
.getSelfServiceLoginFlow(flow, req.header("cookie"))
.then(({ data: flow }: { data: SelfServiceLoginFlow & any }) => {
return frontend
.getLoginFlow(flow, req.header("cookie"))
.then(({ data: flow }: { data: LoginFlow & any }) => {
// Render the data using a view (e.g. Jade Template):

const initRegistrationQuery = new URLSearchParams({
Expand Down
6 changes: 3 additions & 3 deletions src/routes/recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const createRecoveryRoute: RouteCreator =
res.locals.projectName = "Recover account"

const { flow, return_to = "" } = req.query
const { sdk, kratosBrowserUrl, logo } = createHelpers(req)
const { frontend, kratosBrowserUrl, logo } = createHelpers(req)
const initFlowUrl = getUrlForFlow(
kratosBrowserUrl,
"recovery",
Expand All @@ -40,8 +40,8 @@ export const createRecoveryRoute: RouteCreator =
return
}

return sdk
.getSelfServiceRecoveryFlow(flow, req.header("cookie"))
return frontend
.getRecoveryFlow(flow, req.header("cookie"))
.then(({ data: flow }) => {
res.render("recovery", {
card: UserAuthCard({
Expand Down
10 changes: 5 additions & 5 deletions src/routes/registration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
import { SelfServiceRegistrationFlow, UiNodeInputAttributes } from "@ory/client"
import { RegistrationFlow, UiNodeInputAttributes } from "@ory/client"
import { UserAuthCard } from "@ory/elements-markup"
import {
filterNodesByGroups,
Expand All @@ -23,7 +23,7 @@ export const createRegistrationRoute: RouteCreator =
res.locals.projectName = "Create account"

const { flow, return_to = "", login_challenge } = req.query
const { sdk, kratosBrowserUrl, logo } = createHelpers(req)
const { frontend, kratosBrowserUrl, logo } = createHelpers(req)

const initFlowQuery = new URLSearchParams({
return_to: return_to.toString(),
Expand Down Expand Up @@ -54,9 +54,9 @@ export const createRegistrationRoute: RouteCreator =
return
}

sdk
.getSelfServiceRegistrationFlow(flow, req.header("Cookie"))
.then(({ data: flow }: { data: SelfServiceRegistrationFlow & any }) => {
frontend
.getRegistrationFlow(flow, req.header("Cookie"))
.then(({ data: flow }: { data: RegistrationFlow & any }) => {
// Render the data using a view (e.g. Jade Template):
const initLoginQuery = new URLSearchParams({
return_to: return_to.toString(),
Expand Down
6 changes: 3 additions & 3 deletions src/routes/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { navigationMenu } from "../pkg/ui"
export const createSessionsRoute: RouteCreator =
(createHelpers) => async (req, res) => {
res.locals.projectName = "Session Information"
const { sdk } = createHelpers(req)
const { frontend } = createHelpers(req)
const session = req.session

// Create a logout URL
const logoutUrl =
(
await sdk
.createSelfServiceLogoutFlowUrlForBrowsers(req.header("cookie"))
await frontend
.createBrowserLogoutFlow(req.header("cookie"))
.catch(() => ({ data: { logout_url: "" } }))
).data.logout_url || ""

Expand Down
10 changes: 5 additions & 5 deletions src/routes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const createSettingsRoute: RouteCreator =

const { flow, return_to = "" } = req.query
const helpers = createHelpers(req)
const { sdk, kratosBrowserUrl } = helpers
const { frontend, kratosBrowserUrl } = helpers
const initFlowUrl = getUrlForFlow(
kratosBrowserUrl,
"settings",
Expand All @@ -58,8 +58,8 @@ export const createSettingsRoute: RouteCreator =
// Create a logout URL
const logoutUrl =
(
await sdk
.createSelfServiceLogoutFlowUrlForBrowsers(req.header("cookie"))
await frontend
.createBrowserLogoutFlow(req.header("cookie"))
.catch(() => ({ data: { logout_url: "" } }))
).data.logout_url || ""

Expand All @@ -71,8 +71,8 @@ export const createSettingsRoute: RouteCreator =
? `You are currently logged in as ${identityCredentialTrait} `
: ""

return sdk
.getSelfServiceSettingsFlow(flow, undefined, req.header("cookie"))
return frontend
.getSettingsFlow(flow, undefined, req.header("cookie"))
.then(({ data: flow }) => {
const conditionalLinks: NavSectionLinks[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/routes/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const registerStaticRoutes: RouteRegistrator = (app) => {
app.use("/", express.static("public"))
app.use("/.well-known/ory/webauthn.js", (req, res) => {
res.contentType("text/javascript")
sdk.getWebAuthnJavaScript().then(({ data }) => {
sdk.frontend.getWebAuthnJavaScript().then(({ data }) => {
res.send(data)
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/routes/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const createVerificationRoute: RouteCreator =
res.locals.projectName = "Verify account"

const { flow, return_to = "" } = req.query
const { sdk, kratosBrowserUrl, logo } = createHelpers(req)
const { frontend, kratosBrowserUrl, logo } = createHelpers(req)
const initFlowUrl = getUrlForFlow(
kratosBrowserUrl,
"verification",
Expand All @@ -42,8 +42,8 @@ export const createVerificationRoute: RouteCreator =
}

return (
sdk
.getSelfServiceVerificationFlow(flow, req.header("cookie"))
frontend
.getVerificationFlow(flow, req.header("cookie"))
.then(({ data: flow }) => {
// Render the data using a view (e.g. Jade Template):
res.render("verification", {
Expand Down
6 changes: 3 additions & 3 deletions src/routes/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export const createWelcomeRoute: RouteCreator =
(createHelpers) => async (req, res) => {
res.locals.projectName = "Welcome to Ory"

const { sdk } = createHelpers(req)
const { frontend } = createHelpers(req)
const session = req.session

// Create a logout URL
const logoutUrl =
(
await sdk
.createSelfServiceLogoutFlowUrlForBrowsers(req.header("cookie"))
await frontend
.createBrowserLogoutFlow(req.header("cookie"))
.catch(() => ({ data: { logout_url: "" } }))
).data.logout_url || ""

Expand Down