@logto/express 1.0.0-rc.0 → 1.0.0

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.
@@ -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;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"}
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;ACFzB,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 type { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport type { Request, Response, NextFunction } from 'express';\nimport { Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport type { 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.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;AAAA;;ACAA,MAAM,+CAAyB,OAAO,MAAM,CAAC;IAC3C,wBAAwB;AAC1B;AAIO,MAAM,kDAA0B;IAIrC,YAAY,IAA0B,EAAE,IAAc,CAAE;QACtD,KAAK,CAAC,4CAAsB,CAAC,KAAK;QAClC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,IAAI,GAAG;IACd;AACF;;;ACXe;IACb,YAA6B,QAA0B;uBAA1B;IAA2B;IAExD,MAAM,QAAQ,GAAe,EAAE,KAAa,EAAE;QAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG;IAC9B;IAEA,MAAM,QAAQ,GAAe,EAAE;QAC7B,MAAM,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI;QAEvC,IAAI,UAAU,WACZ,OAAO,IAAI;QAGb,OAAO,OAAO;IAChB;IAEA,MAAM,WAAW,GAAe,EAAE;QAChC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG;IAC9B;AACF;;;;AFJA,MAAM,yCAAmB,CACvB,SACA,UACA,SACG;IACH,yFAAyF;IACzF,uEAAuE;IACvE,IAAI,CAAC,QAAQ,OAAO,EAClB,MAAM,IAAI,CAAA,GAAA,yCAAgB,EAAE,0BAA0B;IAGxD,MAAM,UAAU,IAAI,CAAA,GAAA,wCAAa,EAAE;IAEnC,OAAO,IAAI,CAAA,GAAA,0CAAS,EAAE,QAAQ;iBAC5B;QACA,UAAU,CAAC,MAAQ;YACjB,SAAS,QAAQ,CAAC;QACpB;IACF;AACF;AAEO,MAAM,4CAAmB,CAAC,SAAuC;IACtE,mCAAmC;IACnC,MAAM,SAAS,CAAA,GAAA,qBAAM,AAAD;IAEpB,OAAO,GAAG,CAAC,kBAAkB,OAAO,SAAS,WAAa;QACxD,MAAM,UAAE,OAAM,EAAE,GAAG,QAAQ,MAAM;QACjC,MAAM,aAAa,uCAAiB,SAAS,UAAU;QAEvD,OAAQ;YACN,KAAK;gBACH,MAAM,WAAW,MAAM,CAAC,CAAC,EAAE,OAAO,OAAO,CAAC,uBAAuB,CAAC;gBAElE,KAAM;YAGR,KAAK;gBACH,IAAI,QAAQ,GAAG,EAAE;oBACf,MAAM,WAAW,oBAAoB,CAAC,CAAC,EAAE,OAAO,OAAO,CAAC,EAAE,QAAQ,WAAW,CAAC,CAAC;oBAC/E,SAAS,QAAQ,CAAC,OAAO,OAAO;gBAClC,CAAC;gBAED,KAAM;YAGR,KAAK;gBACH,MAAM,WAAW,OAAO,CAAC,OAAO,OAAO;gBAEvC,KAAM;YAGR;gBACE,SAAS,MAAM,CAAC,KAAK,GAAG;QAE5B;IACF;IAEA,OAAO;AACT;AAEO,MAAM,4CACX,CAAC,SACD,OAAO,SAA0B,UAAoB,OAAuB;QAC1E,MAAM,SAAS,uCAAiB,SAAS,UAAU;QACnD,MAAM,OAAO,MAAM,OAAO,UAAU,CAAC;YACnC,gBAAgB,OAAO,cAAc;YACrC,UAAU,OAAO,QAAQ;YACzB,eAAe,OAAO,aAAa;QACrC;QACA,8DAA8D;QAC9D,OAAO,cAAc,CAAC,SAAS,QAAQ;YAAE,YAAY,IAAI;YAAE,KAAK,IAAM;QAAK;QAC3E;IACF","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":"../../../"}
1
+ {"mappings":";;;;;;;;;;;;;;AAAA;;ACAA,MAAM,+CAAyB,OAAO,MAAM,CAAC;IAC3C,wBAAwB;AAC1B;AAIO,MAAM,kDAA0B;IAIrC,YAAY,IAA0B,EAAE,IAAc,CAAE;QACtD,KAAK,CAAC,4CAAsB,CAAC,KAAK;QAClC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,IAAI,GAAG;IACd;AACF;;;ACXe;IACb,YAA6B,QAA0B;uBAA1B;IAA2B;IAExD,MAAM,QAAQ,GAAe,EAAE,KAAa,EAAE;QAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG;IAC9B;IAEA,MAAM,QAAQ,GAAe,EAAE;QAC7B,MAAM,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI;QAEvC,IAAI,UAAU,WACZ,OAAO,IAAI;QAGb,OAAO,OAAO;IAChB;IAEA,MAAM,WAAW,GAAe,EAAE;QAChC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG;IAC9B;AACF;;;;AFHA,MAAM,yCAAmB,CACvB,SACA,UACA,SACG;IACH,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,QAAQ;YAAE,YAAY,IAAI;YAAE,KAAK,IAAM;QAAK;QAC3E;IACF","sources":["packages/express/src/index.ts","packages/express/src/errors.ts","packages/express/src/storage.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport type { Request, Response, NextFunction } from 'express';\nimport { Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport type { 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 type { IncomingMessage } from 'http';\n\nimport type { 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 +1 @@
1
- {"mappings":";;;AAAA;;ACAA,MAAM,+CAAyB,OAAO,MAAM,CAAC;IAC3C,wBAAwB;AAC1B;AAIO,MAAM,kDAA0B;IAIrC,YAAY,IAA0B,EAAE,IAAc,CAAE;QACtD,KAAK,CAAC,4CAAsB,CAAC,KAAK;QAClC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,IAAI,GAAG;IACd;AACF;;;ACXe;IACb,YAA6B,QAA0B;uBAA1B;IAA2B;IAExD,MAAM,QAAQ,GAAe,EAAE,KAAa,EAAE;QAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG;IAC9B;IAEA,MAAM,QAAQ,GAAe,EAAE;QAC7B,MAAM,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI;QAEvC,IAAI,UAAU,WAC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AiB,SAAS,UAAU;QACnD,MAAM,OAAO,MAAM,OAAO,UAAU,CAAC;YACnC,gBAAgB,OAAO,cAAc;YACrC,UAAU,OAAO,QAAQ;YACzB,eAAe,OAAO,aAAa;QACrC;QACA,8DAA8D;QAC9D,OAAO,cAAc,CAAC,SAAS,QAAQ;YAAE,YAAY,IAAI;YAAE,KAAK,IAAM;QAAK;QAC3E;IACF","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.mjs.map"}
1
+ {"mappings":";;;AAAA;;ACAA,MAAM,+CAAyB,OAAO,MAAM,CAAC;IAC3C,wBAAwB;AAC1B;AAIO,MAAM,kDAA0B;IAIrC,YAAY,IAA0B,EAAE,IAAc,CAAE;QACtD,KAAK,CAAC,4CAAsB,CAAC,KAAK;QAClC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,IAAI,GAAG;IACd;AACF;;;ACXe;IACb,YAA6B,QAA0B;uBAA1B;IAA2B;IAExD,MAAM,QAAQ,GAAe,EAAE,KAAa,EAAE;QAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,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E,SAAS,MAAM,CAAC,KAAK,GAAG;QAE5B;IACF;IAEA,OAAO;AACT;AAEO,MAAM,4CACX,CAAC,SACD,OAAO,SAA0B,UAAoB,OAAuB;QAC1E,MAAM,SAAS,uCAAiB,SAAS,UAAU;QACnD,MAAM,OAAO,MAAM,OAAO,UAAU,CAAC;YACnC,gBAAgB,OAAO,cAAc;YACrC,UAAU,OAAO,QAAQ;YACzB,eAAe,OAAO,aAAa;QACrC;QACA,8DAA8D;QAC9D,OAAO,cAAc,CAAC,SAAS,QAAQ;YAAE,YAAY,IAAI;YAAE,KAAK,IAAM;QAAK;QAC3E;IACF","sources":["packages/express/src/index.ts","packages/express/src/errors.ts","packages/express/src/storage.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\n\nimport NodeClient from '@logto/node';\nimport type { Request, Response, NextFunction } from 'express';\nimport { Router } from 'express';\n\nimport { LogtoExpressError } from './errors';\nimport ExpressStorage from './storage';\nimport type { 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 type { IncomingMessage } from 'http';\n\nimport type { 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.mjs.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/express",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.0",
4
4
  "source": "./src/index.ts",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {
@@ -29,16 +29,16 @@
29
29
  "prepack": "pnpm test"
30
30
  },
31
31
  "dependencies": {
32
- "@logto/node": "^1.0.0-rc.0"
32
+ "@logto/node": "^1.0.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@jest/types": "^27.5.1",
36
36
  "@parcel/core": "^2.8.3",
37
37
  "@parcel/packager-ts": "^2.8.3",
38
38
  "@parcel/transformer-typescript-types": "^2.8.3",
39
- "@silverhand/eslint-config": "^1.0.0",
39
+ "@silverhand/eslint-config": "^2.0.0",
40
40
  "@silverhand/ts-config": "^1.0.0",
41
- "@silverhand/ts-config-react": "^1.0.0",
41
+ "@silverhand/ts-config-react": "^2.0.0",
42
42
  "@types/cookie-parser": "^1.4.3",
43
43
  "@types/express": "^4.17.13",
44
44
  "@types/express-session": "^1.17.5",
@@ -56,7 +56,7 @@
56
56
  "prettier": "^2.7.1",
57
57
  "supertest": "^6.3.3",
58
58
  "ts-jest": "^27.0.4",
59
- "typescript": "4.7.4"
59
+ "typescript": "4.9.5"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "express": ">=4"
@@ -76,5 +76,5 @@
76
76
  }
77
77
  }
78
78
  },
79
- "gitHead": "98960287d1016efa9e68b6c4d4407885d6ec9dc6"
79
+ "gitHead": "fff27b23a74d5bd3a46fc83fbbc2901b6e054c72"
80
80
  }