@logto/express 1.0.0-beta.10 → 1.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LogtoConfig } from "@logto/node";
1
+ import { GetContextParameters, LogtoConfig } from "@logto/node";
2
2
  import { Request, Response, NextFunction, Router } from "express";
3
3
  declare module 'http' {
4
4
  interface IncomingMessage {
@@ -7,9 +7,7 @@ declare module 'http' {
7
7
  }
8
8
  export type LogtoExpressConfig = LogtoConfig & {
9
9
  baseUrl: string;
10
- getAccessToken?: boolean;
11
- fetchUserInfo?: boolean;
12
- };
10
+ } & GetContextParameters;
13
11
  export { ReservedScope, UserScope } from '@logto/node';
14
12
  export type { LogtoContext } from '@logto/node';
15
13
  export type Middleware = (request: Request, response: Response, next: NextFunction) => Promise<void>;
@@ -1 +1 @@
1
- {"mappings":";;AEEA,eAAe,MAAM,CAAC;IAGpB,UAAU,eAAe;QACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;KAC7C;CACF;AAED,iCAAiC,WAAW,GAAG;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;ACLF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEvD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,yBAAyB,CACvB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,YAAY,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;AAuBnB,OAAO,MAAM,2BAA4B,kBAAkB,KAAG,MAqC7D,CAAC;AAEF,OAAO,MAAM,oBACF,kBAAkB,KAAG,UAO7B,CAAC","sources":["packages/express/src/src/errors.ts","packages/express/src/src/storage.ts","packages/express/src/src/types.ts","packages/express/src/src/index.ts","packages/express/src/index.ts"],"sourcesContent":[null,null,null,null,"import { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport { Request, Response, NextFunction, Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport { LogtoExpressConfig } from './types';\n\nexport { ReservedScope, UserScope } from '@logto/node';\n\nexport type { LogtoContext } from '@logto/node';\nexport type { LogtoExpressConfig } from './types';\n\nexport type Middleware = (\n request: Request,\n response: Response,\n next: NextFunction\n) => Promise<void>;\n\nconst createNodeClient = (\n request: IncomingMessage,\n response: Response,\n config: LogtoExpressConfig\n) => {\n // We assume that `session` is configured in the express app, but need to check it there.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!request.session) {\n throw new LogtoExpressError('session_not_configured');\n }\n\n const storage = new ExpressStorage(request);\n\n return new NodeClient(config, {\n storage,\n navigate: (url) => {\n response.redirect(url);\n },\n });\n};\n\nexport const handleAuthRoutes = (config: LogtoExpressConfig): Router => {\n // eslint-disable-next-line new-cap\n const router = Router();\n\n router.use('/logto/:action', async (request, response) => {\n const { action } = request.params;\n const nodeClient = createNodeClient(request, response, config);\n\n switch (action) {\n case 'sign-in': {\n await nodeClient.signIn(`${config.baseUrl}/logto/sign-in-callback`);\n\n break;\n }\n\n case 'sign-in-callback': {\n if (request.url) {\n await nodeClient.handleSignInCallback(`${config.baseUrl}${request.originalUrl}`);\n response.redirect(config.baseUrl);\n }\n\n break;\n }\n\n case 'sign-out': {\n await nodeClient.signOut(config.baseUrl);\n\n break;\n }\n\n default: {\n response.status(404).end();\n }\n }\n });\n\n return router;\n};\n\nexport const withLogto =\n (config: LogtoExpressConfig): Middleware =>\n async (request: IncomingMessage, response: Response, next: NextFunction) => {\n const client = createNodeClient(request, response, config);\n const user = await client.getContext(config.getAccessToken, config.fetchUserInfo);\n // eslint-disable-next-line @silverhand/fp/no-mutating-methods\n Object.defineProperty(request, 'user', { enumerable: true, get: () => user });\n next();\n };\n"],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":";;AEEA,eAAe,MAAM,CAAC;IAGpB,UAAU,eAAe;QACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;KAC7C;CACF;AAED,iCAAiC,WAAW,GAAG;IAC7C,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,oBAAoB,CAAC;ACHzB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEvD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,yBAAyB,CACvB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,YAAY,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;AAuBnB,OAAO,MAAM,2BAA4B,kBAAkB,KAAG,MAqC7D,CAAC;AAEF,OAAO,MAAM,oBACF,kBAAkB,KAAG,UAW7B,CAAC","sources":["packages/express/src/src/errors.ts","packages/express/src/src/storage.ts","packages/express/src/src/types.ts","packages/express/src/src/index.ts","packages/express/src/index.ts"],"sourcesContent":[null,null,null,null,"import { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport { Request, Response, NextFunction, Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport { LogtoExpressConfig } from './types';\n\nexport { ReservedScope, UserScope } from '@logto/node';\n\nexport type { LogtoContext } from '@logto/node';\nexport type { LogtoExpressConfig } from './types';\n\nexport type Middleware = (\n request: Request,\n response: Response,\n next: NextFunction\n) => Promise<void>;\n\nconst createNodeClient = (\n request: IncomingMessage,\n response: Response,\n config: LogtoExpressConfig\n) => {\n // We assume that `session` is configured in the express app, but need to check it there.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!request.session) {\n throw new LogtoExpressError('session_not_configured');\n }\n\n const storage = new ExpressStorage(request);\n\n return new NodeClient(config, {\n storage,\n navigate: (url) => {\n response.redirect(url);\n },\n });\n};\n\nexport const handleAuthRoutes = (config: LogtoExpressConfig): Router => {\n // eslint-disable-next-line new-cap\n const router = Router();\n\n router.use('/logto/:action', async (request, response) => {\n const { action } = request.params;\n const nodeClient = createNodeClient(request, response, config);\n\n switch (action) {\n case 'sign-in': {\n await nodeClient.signIn(`${config.baseUrl}/logto/sign-in-callback`);\n\n break;\n }\n\n case 'sign-in-callback': {\n if (request.url) {\n await nodeClient.handleSignInCallback(`${config.baseUrl}${request.originalUrl}`);\n response.redirect(config.baseUrl);\n }\n\n break;\n }\n\n case 'sign-out': {\n await nodeClient.signOut(config.baseUrl);\n\n break;\n }\n\n default: {\n response.status(404).end();\n }\n }\n });\n\n return router;\n};\n\nexport const withLogto =\n (config: LogtoExpressConfig): Middleware =>\n async (request: IncomingMessage, response: Response, next: NextFunction) => {\n const client = createNodeClient(request, response, config);\n const user = await client.getContext({\n getAccessToken: config.getAccessToken,\n resource: config.resource,\n fetchUserInfo: config.fetchUserInfo,\n });\n // eslint-disable-next-line @silverhand/fp/no-mutating-methods\n Object.defineProperty(request, 'user', { enumerable: true, get: () => user });\n next();\n };\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/lib/index.js CHANGED
@@ -84,7 +84,11 @@ const $84b1ad9735b720b5$export$218129a5b761c252 = (config)=>{
84
84
  };
85
85
  const $84b1ad9735b720b5$export$f9a8e793abe4305b = (config)=>async (request, response, next)=>{
86
86
  const client = $84b1ad9735b720b5$var$createNodeClient(request, response, config);
87
- const user = await client.getContext(config.getAccessToken, config.fetchUserInfo);
87
+ const user = await client.getContext({
88
+ getAccessToken: config.getAccessToken,
89
+ resource: config.resource,
90
+ fetchUserInfo: config.fetchUserInfo
91
+ });
88
92
  // eslint-disable-next-line @silverhand/fp/no-mutating-methods
89
93
  Object.defineProperty(request, "user", {
90
94
  enumerable: true,
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;AA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,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,AAAC;QAC3D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,AAAC;QAClF,8DAA8D;QAC9D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE;YAAE,UAAU,EAAE,IAAI;YAAE,GAAG,EAAE,IAAM,IAAI;SAAE,CAAC,CAAC;QAC9E,IAAI,EAAE,CAAC;KACR,AAAC","sources":["packages/express/src/index.ts","packages/express/src/errors.ts","packages/express/src/storage.ts"],"sourcesContent":["import { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport { Request, Response, NextFunction, Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport { LogtoExpressConfig } from './types';\n\nexport { ReservedScope, UserScope } from '@logto/node';\n\nexport type { LogtoContext } from '@logto/node';\nexport type { LogtoExpressConfig } from './types';\n\nexport type Middleware = (\n request: Request,\n response: Response,\n next: NextFunction\n) => Promise<void>;\n\nconst createNodeClient = (\n request: IncomingMessage,\n response: Response,\n config: LogtoExpressConfig\n) => {\n // We assume that `session` is configured in the express app, but need to check it there.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!request.session) {\n throw new LogtoExpressError('session_not_configured');\n }\n\n const storage = new ExpressStorage(request);\n\n return new NodeClient(config, {\n storage,\n navigate: (url) => {\n response.redirect(url);\n },\n });\n};\n\nexport const handleAuthRoutes = (config: LogtoExpressConfig): Router => {\n // eslint-disable-next-line new-cap\n const router = Router();\n\n router.use('/logto/:action', async (request, response) => {\n const { action } = request.params;\n const nodeClient = createNodeClient(request, response, config);\n\n switch (action) {\n case 'sign-in': {\n await nodeClient.signIn(`${config.baseUrl}/logto/sign-in-callback`);\n\n break;\n }\n\n case 'sign-in-callback': {\n if (request.url) {\n await nodeClient.handleSignInCallback(`${config.baseUrl}${request.originalUrl}`);\n response.redirect(config.baseUrl);\n }\n\n break;\n }\n\n case 'sign-out': {\n await nodeClient.signOut(config.baseUrl);\n\n break;\n }\n\n default: {\n response.status(404).end();\n }\n }\n });\n\n return router;\n};\n\nexport const withLogto =\n (config: LogtoExpressConfig): Middleware =>\n async (request: IncomingMessage, response: Response, next: NextFunction) => {\n const client = createNodeClient(request, response, config);\n const user = await client.getContext(config.getAccessToken, config.fetchUserInfo);\n // eslint-disable-next-line @silverhand/fp/no-mutating-methods\n Object.defineProperty(request, 'user', { enumerable: true, get: () => user });\n next();\n };\n","const logtoExpressErrorCodes = Object.freeze({\n session_not_configured: 'You should configure express-session before using Logto express SDK.',\n});\n\nexport type LogtoClientErrorCode = keyof typeof logtoExpressErrorCodes;\n\nexport class LogtoExpressError extends Error {\n code: LogtoClientErrorCode;\n data: unknown;\n\n constructor(code: LogtoClientErrorCode, data?: unknown) {\n super(logtoExpressErrorCodes[code]);\n this.code = code;\n this.data = data;\n }\n}\n","import { IncomingMessage } from 'http';\n\nimport { Storage, StorageKey } from '@logto/node';\n\nexport default class ExpressStorage implements Storage {\n constructor(private readonly request: IncomingMessage) {}\n\n async setItem(key: StorageKey, value: string) {\n this.request.session[key] = value;\n }\n\n async getItem(key: StorageKey) {\n const value = this.request.session[key];\n\n if (value === undefined) {\n return null;\n }\n\n return String(value);\n }\n\n async removeItem(key: StorageKey) {\n this.request.session[key] = undefined;\n }\n}\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../../"}
1
+ {"mappings":";;;;;;;;;;;;;;AAAA;;ACAA,MAAM,4CAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,sBAAsB,EAAE,sEAAsE;CAC/F,CAAC,AAAC;AAII,MAAM,yCAAiB,SAAS,KAAK;IAI1C,YAAY,IAA0B,EAAE,IAAc,CAAE;QACtD,KAAK,CAAC,4CAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,I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AAO,EAAE,MAAM,EAAE;YAAE,UAAU,EAAE,IAAI;YAAE,GAAG,EAAE,IAAM,IAAI;SAAE,CAAC,CAAC;QAC9E,IAAI,EAAE,CAAC;KACR,AAAC","sources":["packages/express/src/index.ts","packages/express/src/errors.ts","packages/express/src/storage.ts"],"sourcesContent":["import { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport { Request, Response, NextFunction, Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport { LogtoExpressConfig } from './types';\n\nexport { ReservedScope, UserScope } from '@logto/node';\n\nexport type { LogtoContext } from '@logto/node';\nexport type { LogtoExpressConfig } from './types';\n\nexport type Middleware = (\n request: Request,\n response: Response,\n next: NextFunction\n) => Promise<void>;\n\nconst createNodeClient = (\n request: IncomingMessage,\n response: Response,\n config: LogtoExpressConfig\n) => {\n // We assume that `session` is configured in the express app, but need to check it there.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!request.session) {\n throw new LogtoExpressError('session_not_configured');\n }\n\n const storage = new ExpressStorage(request);\n\n return new NodeClient(config, {\n storage,\n navigate: (url) => {\n response.redirect(url);\n },\n });\n};\n\nexport const handleAuthRoutes = (config: LogtoExpressConfig): Router => {\n // eslint-disable-next-line new-cap\n const router = Router();\n\n router.use('/logto/:action', async (request, response) => {\n const { action } = request.params;\n const nodeClient = createNodeClient(request, response, config);\n\n switch (action) {\n case 'sign-in': {\n await nodeClient.signIn(`${config.baseUrl}/logto/sign-in-callback`);\n\n break;\n }\n\n case 'sign-in-callback': {\n if (request.url) {\n await nodeClient.handleSignInCallback(`${config.baseUrl}${request.originalUrl}`);\n response.redirect(config.baseUrl);\n }\n\n break;\n }\n\n case 'sign-out': {\n await nodeClient.signOut(config.baseUrl);\n\n break;\n }\n\n default: {\n response.status(404).end();\n }\n }\n });\n\n return router;\n};\n\nexport const withLogto =\n (config: LogtoExpressConfig): Middleware =>\n async (request: IncomingMessage, response: Response, next: NextFunction) => {\n const client = createNodeClient(request, response, config);\n const user = await client.getContext({\n getAccessToken: config.getAccessToken,\n resource: config.resource,\n fetchUserInfo: config.fetchUserInfo,\n });\n // eslint-disable-next-line @silverhand/fp/no-mutating-methods\n Object.defineProperty(request, 'user', { enumerable: true, get: () => user });\n next();\n };\n","const logtoExpressErrorCodes = Object.freeze({\n session_not_configured: 'You should configure express-session before using Logto express SDK.',\n});\n\nexport type LogtoClientErrorCode = keyof typeof logtoExpressErrorCodes;\n\nexport class LogtoExpressError extends Error {\n code: LogtoClientErrorCode;\n data: unknown;\n\n constructor(code: LogtoClientErrorCode, data?: unknown) {\n super(logtoExpressErrorCodes[code]);\n this.code = code;\n this.data = data;\n }\n}\n","import { IncomingMessage } from 'http';\n\nimport { Storage, StorageKey } from '@logto/node';\n\nexport default class ExpressStorage implements Storage {\n constructor(private readonly request: IncomingMessage) {}\n\n async setItem(key: StorageKey, value: string) {\n this.request.session[key] = value;\n }\n\n async getItem(key: StorageKey) {\n const value = this.request.session[key];\n\n if (value === undefined) {\n return null;\n }\n\n return String(value);\n }\n\n async removeItem(key: StorageKey) {\n this.request.session[key] = undefined;\n }\n}\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../../"}
package/lib/module.js CHANGED
@@ -73,7 +73,11 @@ const $07dcc8bf26a4fe36$export$218129a5b761c252 = (config)=>{
73
73
  };
74
74
  const $07dcc8bf26a4fe36$export$f9a8e793abe4305b = (config)=>async (request, response, next)=>{
75
75
  const client = $07dcc8bf26a4fe36$var$createNodeClient(request, response, config);
76
- const user = await client.getContext(config.getAccessToken, config.fetchUserInfo);
76
+ const user = await client.getContext({
77
+ getAccessToken: config.getAccessToken,
78
+ resource: config.resource,
79
+ fetchUserInfo: config.fetchUserInfo
80
+ });
77
81
  // eslint-disable-next-line @silverhand/fp/no-mutating-methods
78
82
  Object.defineProperty(request, "user", {
79
83
  enumerable: true,
package/lib/module.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;ACAA,MAA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AE,QAAQ,EAAE,MAAM,CAAC,AAAC;QAC3D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,AAAC;QAClF,8DAA8D;QAC9D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE;YAAE,UAAU,EAAE,IAAI;YAAE,GAAG,EAAE,IAAM,IAAI;SAAE,CAAC,CAAC;QAC9E,IAAI,EAAE,CAAC;KACR,AAAC","sources":["packages/express/src/index.ts","packages/express/src/errors.ts","packages/express/src/storage.ts"],"sourcesContent":["import { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport { Request, Response, NextFunction, Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport { LogtoExpressConfig } from './types';\n\nexport { ReservedScope, UserScope } from '@logto/node';\n\nexport type { LogtoContext } from '@logto/node';\nexport type { LogtoExpressConfig } from './types';\n\nexport type Middleware = (\n request: Request,\n response: Response,\n next: NextFunction\n) => Promise<void>;\n\nconst createNodeClient = (\n request: IncomingMessage,\n response: Response,\n config: LogtoExpressConfig\n) => {\n // We assume that `session` is configured in the express app, but need to check it there.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!request.session) {\n throw new LogtoExpressError('session_not_configured');\n }\n\n const storage = new ExpressStorage(request);\n\n return new NodeClient(config, {\n storage,\n navigate: (url) => {\n response.redirect(url);\n },\n });\n};\n\nexport const handleAuthRoutes = (config: LogtoExpressConfig): Router => {\n // eslint-disable-next-line new-cap\n const router = Router();\n\n router.use('/logto/:action', async (request, response) => {\n const { action } = request.params;\n const nodeClient = createNodeClient(request, response, config);\n\n switch (action) {\n case 'sign-in': {\n await nodeClient.signIn(`${config.baseUrl}/logto/sign-in-callback`);\n\n break;\n }\n\n case 'sign-in-callback': {\n if (request.url) {\n await nodeClient.handleSignInCallback(`${config.baseUrl}${request.originalUrl}`);\n response.redirect(config.baseUrl);\n }\n\n break;\n }\n\n case 'sign-out': {\n await nodeClient.signOut(config.baseUrl);\n\n break;\n }\n\n default: {\n response.status(404).end();\n }\n }\n });\n\n return router;\n};\n\nexport const withLogto =\n (config: LogtoExpressConfig): Middleware =>\n async (request: IncomingMessage, response: Response, next: NextFunction) => {\n const client = createNodeClient(request, response, config);\n const user = await client.getContext(config.getAccessToken, config.fetchUserInfo);\n // eslint-disable-next-line @silverhand/fp/no-mutating-methods\n Object.defineProperty(request, 'user', { enumerable: true, get: () => user });\n next();\n };\n","const logtoExpressErrorCodes = Object.freeze({\n session_not_configured: 'You should configure express-session before using Logto express SDK.',\n});\n\nexport type LogtoClientErrorCode = keyof typeof logtoExpressErrorCodes;\n\nexport class LogtoExpressError extends Error {\n code: LogtoClientErrorCode;\n data: unknown;\n\n constructor(code: LogtoClientErrorCode, data?: unknown) {\n super(logtoExpressErrorCodes[code]);\n this.code = code;\n this.data = data;\n }\n}\n","import { IncomingMessage } from 'http';\n\nimport { Storage, StorageKey } from '@logto/node';\n\nexport default class ExpressStorage implements Storage {\n constructor(private readonly request: IncomingMessage) {}\n\n async setItem(key: StorageKey, value: string) {\n this.request.session[key] = value;\n }\n\n async getItem(key: StorageKey) {\n const value = this.request.session[key];\n\n if (value === undefined) {\n return null;\n }\n\n return String(value);\n }\n\n async removeItem(key: StorageKey) {\n this.request.session[key] = undefined;\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;ACAA,MAAM,4CAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,sBAAsB,EAAE,sEAAsE;CAC/F,CAAC,AAAC;AAII,MAAM,yCAAiB,SAAS,KAAK;IAI1C,YAAY,IAA0B,EAAE,IAAc,CAAE;QACtD,KAAK,CAAC,4CAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;KAClB;CAC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I;YAAE,GAAG,EAAE,IAAM,IAAI;SAAE,CAAC,CAAC;QAC9E,IAAI,EAAE,CAAC;KACR,AAAC","sources":["packages/express/src/index.ts","packages/express/src/errors.ts","packages/express/src/storage.ts"],"sourcesContent":["import { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport { Request, Response, NextFunction, Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport { LogtoExpressConfig } from './types';\n\nexport { ReservedScope, UserScope } from '@logto/node';\n\nexport type { LogtoContext } from '@logto/node';\nexport type { LogtoExpressConfig } from './types';\n\nexport type Middleware = (\n request: Request,\n response: Response,\n next: NextFunction\n) => Promise<void>;\n\nconst createNodeClient = (\n request: IncomingMessage,\n response: Response,\n config: LogtoExpressConfig\n) => {\n // We assume that `session` is configured in the express app, but need to check it there.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!request.session) {\n throw new LogtoExpressError('session_not_configured');\n }\n\n const storage = new ExpressStorage(request);\n\n return new NodeClient(config, {\n storage,\n navigate: (url) => {\n response.redirect(url);\n },\n });\n};\n\nexport const handleAuthRoutes = (config: LogtoExpressConfig): Router => {\n // eslint-disable-next-line new-cap\n const router = Router();\n\n router.use('/logto/:action', async (request, response) => {\n const { action } = request.params;\n const nodeClient = createNodeClient(request, response, config);\n\n switch (action) {\n case 'sign-in': {\n await nodeClient.signIn(`${config.baseUrl}/logto/sign-in-callback`);\n\n break;\n }\n\n case 'sign-in-callback': {\n if (request.url) {\n await nodeClient.handleSignInCallback(`${config.baseUrl}${request.originalUrl}`);\n response.redirect(config.baseUrl);\n }\n\n break;\n }\n\n case 'sign-out': {\n await nodeClient.signOut(config.baseUrl);\n\n break;\n }\n\n default: {\n response.status(404).end();\n }\n }\n });\n\n return router;\n};\n\nexport const withLogto =\n (config: LogtoExpressConfig): Middleware =>\n async (request: IncomingMessage, response: Response, next: NextFunction) => {\n const client = createNodeClient(request, response, config);\n const user = await client.getContext({\n getAccessToken: config.getAccessToken,\n resource: config.resource,\n fetchUserInfo: config.fetchUserInfo,\n });\n // eslint-disable-next-line @silverhand/fp/no-mutating-methods\n Object.defineProperty(request, 'user', { enumerable: true, get: () => user });\n next();\n };\n","const logtoExpressErrorCodes = Object.freeze({\n session_not_configured: 'You should configure express-session before using Logto express SDK.',\n});\n\nexport type LogtoClientErrorCode = keyof typeof logtoExpressErrorCodes;\n\nexport class LogtoExpressError extends Error {\n code: LogtoClientErrorCode;\n data: unknown;\n\n constructor(code: LogtoClientErrorCode, data?: unknown) {\n super(logtoExpressErrorCodes[code]);\n this.code = code;\n this.data = data;\n }\n}\n","import { IncomingMessage } from 'http';\n\nimport { Storage, StorageKey } from '@logto/node';\n\nexport default class ExpressStorage implements Storage {\n constructor(private readonly request: IncomingMessage) {}\n\n async setItem(key: StorageKey, value: string) {\n this.request.session[key] = value;\n }\n\n async getItem(key: StorageKey) {\n const value = this.request.session[key];\n\n if (value === undefined) {\n return null;\n }\n\n return String(value);\n }\n\n async removeItem(key: StorageKey) {\n this.request.session[key] = undefined;\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/express",
3
- "version": "1.0.0-beta.10",
3
+ "version": "1.0.0-beta.12",
4
4
  "source": "./src/index.ts",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {
@@ -29,7 +29,7 @@
29
29
  "prepack": "pnpm test"
30
30
  },
31
31
  "dependencies": {
32
- "@logto/node": "^1.0.0-beta.10"
32
+ "@logto/node": "^1.0.0-beta.12"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@jest/types": "^27.5.1",
@@ -76,5 +76,5 @@
76
76
  }
77
77
  }
78
78
  },
79
- "gitHead": "c79c3759b7f15c44bf5b476dcebd82e9c96e9dd8"
79
+ "gitHead": "8d3230e887abf2069c1eccd72632203fc04809cc"
80
80
  }