@logto/express 1.0.0-beta.9 → 1.0.0-rc.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.
- package/lib/index.d.ts +2 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +24 -20
- package/lib/index.js.map +1 -1
- package/lib/module.d.mts +17 -0
- package/lib/{module.js → module.mjs} +6 -2
- package/lib/module.mjs.map +1 -0
- package/package.json +12 -12
- package/lib/module.js.map +0 -1
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
|
-
|
|
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>;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
1
|
+
var $7B6LY$logtonode = require("@logto/node");
|
|
2
|
+
var $7B6LY$express = require("express");
|
|
3
3
|
|
|
4
4
|
function $parcel$interopDefault(a) {
|
|
5
5
|
return a && a.__esModule ? a.default : a;
|
|
@@ -8,25 +8,25 @@ function $parcel$export(e, n, v, s) {
|
|
|
8
8
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
$parcel$export(module.exports, "handleAuthRoutes", () => $
|
|
12
|
-
$parcel$export(module.exports, "withLogto", () => $
|
|
13
|
-
$parcel$export(module.exports, "ReservedScope", () => $
|
|
14
|
-
$parcel$export(module.exports, "UserScope", () => $
|
|
11
|
+
$parcel$export(module.exports, "handleAuthRoutes", () => $e5532821beefe084$export$218129a5b761c252);
|
|
12
|
+
$parcel$export(module.exports, "withLogto", () => $e5532821beefe084$export$f9a8e793abe4305b);
|
|
13
|
+
$parcel$export(module.exports, "ReservedScope", () => $e5532821beefe084$re_export$ReservedScope);
|
|
14
|
+
$parcel$export(module.exports, "UserScope", () => $e5532821beefe084$re_export$UserScope);
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
const $
|
|
17
|
+
const $c0c4c8dcf2e7823b$var$logtoExpressErrorCodes = Object.freeze({
|
|
18
18
|
session_not_configured: "You should configure express-session before using Logto express SDK."
|
|
19
19
|
});
|
|
20
|
-
class $
|
|
20
|
+
class $c0c4c8dcf2e7823b$export$b838f54079ce95de extends Error {
|
|
21
21
|
constructor(code, data){
|
|
22
|
-
super($
|
|
22
|
+
super($c0c4c8dcf2e7823b$var$logtoExpressErrorCodes[code]);
|
|
23
23
|
this.code = code;
|
|
24
24
|
this.data = data;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
class $
|
|
29
|
+
class $27b238e5def1d471$export$2e2bcd8739ae039 {
|
|
30
30
|
constructor(request){
|
|
31
31
|
this.request = request;
|
|
32
32
|
}
|
|
@@ -45,24 +45,24 @@ class $8bf40595bbb9a575$export$2e2bcd8739ae039 {
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
const $
|
|
48
|
+
const $e5532821beefe084$var$createNodeClient = (request, response, config)=>{
|
|
49
49
|
// We assume that `session` is configured in the express app, but need to check it there.
|
|
50
50
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
51
|
-
if (!request.session) throw new (0, $
|
|
52
|
-
const storage = new (0, $
|
|
53
|
-
return new (0, ($parcel$interopDefault($
|
|
51
|
+
if (!request.session) throw new (0, $c0c4c8dcf2e7823b$export$b838f54079ce95de)("session_not_configured");
|
|
52
|
+
const storage = new (0, $27b238e5def1d471$export$2e2bcd8739ae039)(request);
|
|
53
|
+
return new (0, ($parcel$interopDefault($7B6LY$logtonode)))(config, {
|
|
54
54
|
storage: storage,
|
|
55
55
|
navigate: (url)=>{
|
|
56
56
|
response.redirect(url);
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
};
|
|
60
|
-
const $
|
|
60
|
+
const $e5532821beefe084$export$218129a5b761c252 = (config)=>{
|
|
61
61
|
// eslint-disable-next-line new-cap
|
|
62
|
-
const router = (0, $
|
|
62
|
+
const router = (0, $7B6LY$express.Router)();
|
|
63
63
|
router.use("/logto/:action", async (request, response)=>{
|
|
64
64
|
const { action: action } = request.params;
|
|
65
|
-
const nodeClient = $
|
|
65
|
+
const nodeClient = $e5532821beefe084$var$createNodeClient(request, response, config);
|
|
66
66
|
switch(action){
|
|
67
67
|
case "sign-in":
|
|
68
68
|
await nodeClient.signIn(`${config.baseUrl}/logto/sign-in-callback`);
|
|
@@ -82,9 +82,13 @@ const $84b1ad9735b720b5$export$218129a5b761c252 = (config)=>{
|
|
|
82
82
|
});
|
|
83
83
|
return router;
|
|
84
84
|
};
|
|
85
|
-
const $
|
|
86
|
-
const client = $
|
|
87
|
-
const user = await client.getContext(
|
|
85
|
+
const $e5532821beefe084$export$f9a8e793abe4305b = (config)=>async (request, response, next)=>{
|
|
86
|
+
const client = $e5532821beefe084$var$createNodeClient(request, response, config);
|
|
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":";;;;;;;;;;;;;;AAAA;;ACAA,MAAM,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;AAAA;;ACAA,MAAM,+CAAyB,OAAO,MAAM,CAAC;IAC3C,wBAAwB;AAC1B;AAIO,MAAM,kDAA0B;IAIrC,YAAY,IAA0B,EAAE,IAAc,CAAE;QACtD,KAAK,CAAC,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AoB,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":"../../../"}
|
package/lib/module.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GetContextParameters, LogtoConfig } from "@logto/node";
|
|
2
|
+
import { Request, Response, NextFunction, Router } from "express";
|
|
3
|
+
declare module 'http' {
|
|
4
|
+
interface IncomingMessage {
|
|
5
|
+
session: Record<string, string | undefined>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export type LogtoExpressConfig = LogtoConfig & {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
} & GetContextParameters;
|
|
11
|
+
export { ReservedScope, UserScope } from '@logto/node';
|
|
12
|
+
export type { LogtoContext } from '@logto/node';
|
|
13
|
+
export type Middleware = (request: Request, response: Response, next: NextFunction) => Promise<void>;
|
|
14
|
+
export const handleAuthRoutes: (config: LogtoExpressConfig) => Router;
|
|
15
|
+
export const withLogto: (config: LogtoExpressConfig) => Middleware;
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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(
|
|
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,
|
|
@@ -84,4 +88,4 @@ const $07dcc8bf26a4fe36$export$f9a8e793abe4305b = (config)=>async (request, resp
|
|
|
84
88
|
|
|
85
89
|
|
|
86
90
|
export {$07dcc8bf26a4fe36$export$218129a5b761c252 as handleAuthRoutes, $07dcc8bf26a4fe36$export$f9a8e793abe4305b as withLogto, $07dcc8bf26a4fe36$re_export$ReservedScope as ReservedScope, $07dcc8bf26a4fe36$re_export$UserScope as UserScope};
|
|
87
|
-
//# sourceMappingURL=module.
|
|
91
|
+
//# sourceMappingURL=module.mjs.map
|
|
@@ -0,0 +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,gBAAS,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,aAAM,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":"module.mjs.map"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/express",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.0",
|
|
4
4
|
"source": "./src/index.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
"require": "./lib/index.js",
|
|
8
|
-
"import": "./lib/module.
|
|
8
|
+
"import": "./lib/module.mjs"
|
|
9
9
|
},
|
|
10
|
-
"module": "./lib/module.
|
|
10
|
+
"module": "./lib/module.mjs",
|
|
11
11
|
"types": "./lib/index.d.ts",
|
|
12
12
|
"files": [
|
|
13
13
|
"lib"
|
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
|
|
23
23
|
"precommit": "lint-staged",
|
|
24
24
|
"check": "tsc --noEmit",
|
|
25
|
-
"build": "rm -rf lib/ && pnpm check && parcel build",
|
|
25
|
+
"build": "rm -rf lib/ && pnpm check && parcel build && cp lib/index.d.ts lib/module.d.mts",
|
|
26
26
|
"lint": "eslint --ext .ts src",
|
|
27
27
|
"test": "jest",
|
|
28
28
|
"test:coverage": "jest --silent --coverage",
|
|
29
29
|
"prepack": "pnpm test"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@logto/node": "^1.0.0-
|
|
32
|
+
"@logto/node": "^1.0.0-rc.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@jest/types": "^27.5.1",
|
|
36
|
-
"@parcel/core": "^2.
|
|
37
|
-
"@parcel/packager-ts": "^2.
|
|
38
|
-
"@parcel/transformer-typescript-types": "^2.
|
|
36
|
+
"@parcel/core": "^2.8.3",
|
|
37
|
+
"@parcel/packager-ts": "^2.8.3",
|
|
38
|
+
"@parcel/transformer-typescript-types": "^2.8.3",
|
|
39
39
|
"@silverhand/eslint-config": "^1.0.0",
|
|
40
40
|
"@silverhand/ts-config": "^1.0.0",
|
|
41
41
|
"@silverhand/ts-config-react": "^1.0.0",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"jest-location-mock": "^1.0.9",
|
|
53
53
|
"jest-matcher-specific-error": "^1.0.0",
|
|
54
54
|
"lint-staged": "^13.0.0",
|
|
55
|
-
"parcel": "^2.
|
|
55
|
+
"parcel": "^2.8.3",
|
|
56
56
|
"prettier": "^2.7.1",
|
|
57
|
-
"supertest": "^6.
|
|
57
|
+
"supertest": "^6.3.3",
|
|
58
58
|
"ts-jest": "^27.0.4",
|
|
59
59
|
"typescript": "4.7.4"
|
|
60
60
|
},
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"main": {
|
|
73
73
|
"context": "node",
|
|
74
74
|
"engines": {
|
|
75
|
-
"node": "
|
|
75
|
+
"node": ">=18.12.0"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "98960287d1016efa9e68b6c4d4407885d6ec9dc6"
|
|
80
80
|
}
|
package/lib/module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,I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,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"}
|