@logto/express 1.1.2 → 2.0.1
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/{errors.mjs → errors.cjs} +3 -1
- package/lib/errors.js +1 -3
- package/lib/{index.mjs → index.cjs} +25 -11
- package/lib/index.d.ts +2 -2
- package/lib/index.js +11 -25
- package/lib/{storage.mjs → storage.cjs} +5 -1
- package/lib/storage.d.ts +1 -1
- package/lib/storage.js +1 -5
- package/lib/test-utils.d.ts +1 -1
- package/package.json +23 -24
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
const logtoExpressErrorCodes = Object.freeze({
|
|
2
4
|
session_not_configured: 'You should configure express-session before using Logto express SDK.',
|
|
3
5
|
});
|
|
@@ -9,4 +11,4 @@ class LogtoExpressError extends Error {
|
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
exports.LogtoExpressError = LogtoExpressError;
|
package/lib/errors.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const logtoExpressErrorCodes = Object.freeze({
|
|
4
2
|
session_not_configured: 'You should configure express-session before using Logto express SDK.',
|
|
5
3
|
});
|
|
@@ -11,4 +9,4 @@ class LogtoExpressError extends Error {
|
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
export { LogtoExpressError };
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var NodeClient = require('@logto/node');
|
|
4
|
+
var express = require('express');
|
|
5
|
+
var errors = require('./errors.cjs');
|
|
6
|
+
var storage = require('./storage.cjs');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var NodeClient__default = /*#__PURE__*/_interopDefault(NodeClient);
|
|
6
11
|
|
|
7
12
|
const createNodeClient = (request, response, config) => {
|
|
8
13
|
// We assume that `session` is configured in the express app, but need to check it there.
|
|
9
14
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
10
15
|
if (!request.session) {
|
|
11
|
-
throw new LogtoExpressError('session_not_configured');
|
|
16
|
+
throw new errors.LogtoExpressError('session_not_configured');
|
|
12
17
|
}
|
|
13
|
-
const storage = new
|
|
14
|
-
return new
|
|
15
|
-
storage,
|
|
18
|
+
const storage$1 = new storage.default(request);
|
|
19
|
+
return new NodeClient__default.default(config, {
|
|
20
|
+
storage: storage$1,
|
|
16
21
|
navigate: (url) => {
|
|
17
22
|
response.redirect(url);
|
|
18
23
|
},
|
|
@@ -20,7 +25,7 @@ const createNodeClient = (request, response, config) => {
|
|
|
20
25
|
};
|
|
21
26
|
const handleAuthRoutes = (config) => {
|
|
22
27
|
// eslint-disable-next-line new-cap
|
|
23
|
-
const router = Router();
|
|
28
|
+
const router = express.Router();
|
|
24
29
|
router.use('/logto/:action', async (request, response) => {
|
|
25
30
|
const { action } = request.params;
|
|
26
31
|
const nodeClient = createNodeClient(request, response, config);
|
|
@@ -63,4 +68,13 @@ const withLogto = (config) => async (request, response, next) => {
|
|
|
63
68
|
next();
|
|
64
69
|
};
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
Object.defineProperty(exports, 'ReservedScope', {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () { return NodeClient.ReservedScope; }
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, 'UserScope', {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () { return NodeClient.UserScope; }
|
|
78
|
+
});
|
|
79
|
+
exports.handleAuthRoutes = handleAuthRoutes;
|
|
80
|
+
exports.withLogto = withLogto;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Request, Response, NextFunction } from 'express';
|
|
2
2
|
import { Router } from 'express';
|
|
3
|
-
import type { LogtoExpressConfig } from './types';
|
|
3
|
+
import type { LogtoExpressConfig } from './types.js';
|
|
4
4
|
export { ReservedScope, UserScope } from '@logto/node';
|
|
5
5
|
export type { LogtoContext, InteractionMode } from '@logto/node';
|
|
6
|
-
export type { LogtoExpressConfig } from './types';
|
|
6
|
+
export type { LogtoExpressConfig } from './types.js';
|
|
7
7
|
export type Middleware = (request: Request, response: Response, next: NextFunction) => Promise<void>;
|
|
8
8
|
export declare const handleAuthRoutes: (config: LogtoExpressConfig) => Router;
|
|
9
9
|
export declare const withLogto: (config: LogtoExpressConfig) => Middleware;
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var storage = require('./storage.js');
|
|
7
|
-
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
var NodeClient__default = /*#__PURE__*/_interopDefault(NodeClient);
|
|
1
|
+
import NodeClient from '@logto/node';
|
|
2
|
+
export { ReservedScope, UserScope } from '@logto/node';
|
|
3
|
+
import { Router } from 'express';
|
|
4
|
+
import { LogtoExpressError } from './errors.js';
|
|
5
|
+
import ExpressStorage from './storage.js';
|
|
11
6
|
|
|
12
7
|
const createNodeClient = (request, response, config) => {
|
|
13
8
|
// We assume that `session` is configured in the express app, but need to check it there.
|
|
14
9
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
15
10
|
if (!request.session) {
|
|
16
|
-
throw new
|
|
11
|
+
throw new LogtoExpressError('session_not_configured');
|
|
17
12
|
}
|
|
18
|
-
const storage
|
|
19
|
-
return new
|
|
20
|
-
storage
|
|
13
|
+
const storage = new ExpressStorage(request);
|
|
14
|
+
return new NodeClient(config, {
|
|
15
|
+
storage,
|
|
21
16
|
navigate: (url) => {
|
|
22
17
|
response.redirect(url);
|
|
23
18
|
},
|
|
@@ -25,7 +20,7 @@ const createNodeClient = (request, response, config) => {
|
|
|
25
20
|
};
|
|
26
21
|
const handleAuthRoutes = (config) => {
|
|
27
22
|
// eslint-disable-next-line new-cap
|
|
28
|
-
const router =
|
|
23
|
+
const router = Router();
|
|
29
24
|
router.use('/logto/:action', async (request, response) => {
|
|
30
25
|
const { action } = request.params;
|
|
31
26
|
const nodeClient = createNodeClient(request, response, config);
|
|
@@ -68,13 +63,4 @@ const withLogto = (config) => async (request, response, next) => {
|
|
|
68
63
|
next();
|
|
69
64
|
};
|
|
70
65
|
|
|
71
|
-
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function () { return NodeClient.ReservedScope; }
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(exports, 'UserScope', {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
get: function () { return NodeClient.UserScope; }
|
|
78
|
-
});
|
|
79
|
-
exports.handleAuthRoutes = handleAuthRoutes;
|
|
80
|
-
exports.withLogto = withLogto;
|
|
66
|
+
export { handleAuthRoutes, withLogto };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
1
5
|
class ExpressStorage {
|
|
2
6
|
constructor(request) {
|
|
3
7
|
this.request = request;
|
|
@@ -17,4 +21,4 @@ class ExpressStorage {
|
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
exports.default = ExpressStorage;
|
package/lib/storage.d.ts
CHANGED
package/lib/storage.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
1
|
class ExpressStorage {
|
|
6
2
|
constructor(request) {
|
|
7
3
|
this.request = request;
|
|
@@ -21,4 +17,4 @@ class ExpressStorage {
|
|
|
21
17
|
}
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
export { ExpressStorage as default };
|
package/lib/test-utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response, Router } from 'express';
|
|
2
2
|
import request from 'supertest';
|
|
3
|
-
import type { Middleware } from '.';
|
|
3
|
+
import type { Middleware } from './index.js';
|
|
4
4
|
type TestMiddlewareParameters = {
|
|
5
5
|
middleware: Middleware;
|
|
6
6
|
url?: string;
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/express",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"main": "./lib/index.
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./lib/index.cjs",
|
|
6
|
+
"module": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
6
8
|
"exports": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
+
"types": "./lib/index.d.ts",
|
|
10
|
+
"require": "./lib/index.cjs",
|
|
11
|
+
"import": "./lib/index.js",
|
|
12
|
+
"default": "./lib/index.js"
|
|
9
13
|
},
|
|
10
|
-
"module": "./lib/index.mjs",
|
|
11
|
-
"types": "./lib/index.d.ts",
|
|
12
14
|
"files": [
|
|
13
15
|
"lib"
|
|
14
16
|
],
|
|
@@ -18,24 +20,13 @@
|
|
|
18
20
|
"url": "https://github.com/logto-io/js.git",
|
|
19
21
|
"directory": "packages/express"
|
|
20
22
|
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
|
|
23
|
-
"precommit": "lint-staged",
|
|
24
|
-
"check": "tsc --noEmit",
|
|
25
|
-
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
|
|
26
|
-
"lint": "eslint --ext .ts src",
|
|
27
|
-
"test": "jest",
|
|
28
|
-
"test:coverage": "jest --silent --coverage",
|
|
29
|
-
"prepack": "pnpm test"
|
|
30
|
-
},
|
|
31
23
|
"dependencies": {
|
|
32
|
-
"@logto/node": "^1.1
|
|
24
|
+
"@logto/node": "^2.1.1"
|
|
33
25
|
},
|
|
34
26
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@silverhand/
|
|
37
|
-
"@silverhand/ts-config": "^
|
|
38
|
-
"@silverhand/ts-config-react": "^2.0.0",
|
|
27
|
+
"@silverhand/eslint-config": "^3.0.1",
|
|
28
|
+
"@silverhand/ts-config": "^3.0.0",
|
|
29
|
+
"@silverhand/ts-config-react": "^3.0.0",
|
|
39
30
|
"@swc/core": "^1.3.50",
|
|
40
31
|
"@swc/jest": "^0.2.24",
|
|
41
32
|
"@types/cookie-parser": "^1.4.3",
|
|
@@ -73,5 +64,13 @@
|
|
|
73
64
|
}
|
|
74
65
|
}
|
|
75
66
|
},
|
|
76
|
-
"
|
|
77
|
-
|
|
67
|
+
"scripts": {
|
|
68
|
+
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
|
|
69
|
+
"precommit": "lint-staged",
|
|
70
|
+
"check": "tsc --noEmit",
|
|
71
|
+
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
|
|
72
|
+
"lint": "eslint --ext .ts src",
|
|
73
|
+
"test": "jest",
|
|
74
|
+
"test:coverage": "node test.cjs && jest --silent --coverage"
|
|
75
|
+
}
|
|
76
|
+
}
|