@simulacrum/auth0-simulator 0.9.0 → 0.10.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/README.md +28 -206
- package/bin/start.js +14 -0
- package/dist/auth/constants.d.ts.map +1 -1
- package/dist/auth/constants.js.map +1 -1
- package/dist/auth/date.d.ts.map +1 -1
- package/dist/auth/jwt.d.ts +1 -1
- package/dist/auth/jwt.d.ts.map +1 -1
- package/dist/auth/jwt.js +5 -5
- package/dist/auth/jwt.js.map +1 -1
- package/dist/auth/refresh-token.d.ts +2 -2
- package/dist/auth/refresh-token.d.ts.map +1 -1
- package/dist/auth/refresh-token.js +7 -8
- package/dist/auth/refresh-token.js.map +1 -1
- package/dist/config/get-config.d.ts +6 -6
- package/dist/config/get-config.d.ts.map +1 -1
- package/dist/config/get-config.js +10 -10
- package/dist/config/get-config.js.map +1 -1
- package/dist/handlers/auth0-handlers.d.ts +6 -10
- package/dist/handlers/auth0-handlers.d.ts.map +1 -1
- package/dist/handlers/auth0-handlers.js +96 -70
- package/dist/handlers/auth0-handlers.js.map +1 -1
- package/dist/handlers/index.d.ts +5 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +43 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/login-redirect.d.ts +2 -2
- package/dist/handlers/login-redirect.d.ts.map +1 -1
- package/dist/handlers/login-redirect.js.map +1 -1
- package/dist/handlers/oauth-handlers.d.ts +10 -9
- package/dist/handlers/oauth-handlers.d.ts.map +1 -1
- package/dist/handlers/oauth-handlers.js +56 -50
- package/dist/handlers/oauth-handlers.js.map +1 -1
- package/dist/handlers/openid-handlers.d.ts +4 -4
- package/dist/handlers/openid-handlers.d.ts.map +1 -1
- package/dist/handlers/openid-handlers.js +10 -10
- package/dist/handlers/openid-handlers.js.map +1 -1
- package/dist/handlers/url.d.ts.map +1 -1
- package/dist/handlers/url.js +1 -1
- package/dist/handlers/url.js.map +1 -1
- package/dist/handlers/utils.d.ts +11 -4
- package/dist/handlers/utils.d.ts.map +1 -1
- package/dist/handlers/utils.js +5 -4
- package/dist/handlers/utils.js.map +1 -1
- package/dist/handlers/web-message.d.ts +1 -1
- package/dist/handlers/web-message.d.ts.map +1 -1
- package/dist/handlers/web-message.js +3 -3
- package/dist/handlers/web-message.js.map +1 -1
- package/dist/index.d.ts +16 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -125
- package/dist/index.js.map +1 -1
- package/dist/middleware/create-cors.d.ts +1 -1
- package/dist/middleware/create-cors.js.map +1 -1
- package/dist/middleware/error-handling.d.ts +3 -0
- package/dist/middleware/error-handling.d.ts.map +1 -0
- package/dist/{error-handling-middleware.js → middleware/error-handling.js} +5 -8
- package/dist/middleware/error-handling.js.map +1 -0
- package/dist/middleware/no-cache.d.ts +1 -1
- package/dist/middleware/session.d.ts +1 -1
- package/dist/middleware/session.js.map +1 -1
- package/dist/rules/extensionless-file-name.d.ts.map +1 -1
- package/dist/rules/parse-rules-files.d.ts.map +1 -1
- package/dist/rules/parse-rules-files.js +7 -8
- package/dist/rules/parse-rules-files.js.map +1 -1
- package/dist/rules/rules-runner.d.ts +2 -2
- package/dist/rules/rules-runner.d.ts.map +1 -1
- package/dist/rules/rules-runner.js +49 -41
- package/dist/rules/rules-runner.js.map +1 -1
- package/dist/rules/types.d.ts +1 -1
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/store/entities.d.ts +111 -0
- package/dist/store/entities.d.ts.map +1 -0
- package/dist/store/entities.js +43 -0
- package/dist/store/entities.js.map +1 -0
- package/dist/store/index.d.ts +37 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +40 -0
- package/dist/store/index.js.map +1 -0
- package/dist/types.d.ts +20 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -11
- package/dist/types.js.map +1 -1
- package/dist/views/login.d.ts +2 -2
- package/dist/views/login.d.ts.map +1 -1
- package/dist/views/login.js +81 -30
- package/dist/views/login.js.map +1 -1
- package/dist/views/username-password.d.ts +2 -2
- package/dist/views/username-password.d.ts.map +1 -1
- package/dist/views/web-message.d.ts +1 -1
- package/dist/views/web-message.d.ts.map +1 -1
- package/dist/views/web-message.js.map +1 -1
- package/package.json +26 -41
- package/CHANGELOG.md +0 -176
- package/bin/index.js +0 -2
- package/dist/error-handling-middleware.d.ts +0 -3
- package/dist/error-handling-middleware.d.ts.map +0 -1
- package/dist/error-handling-middleware.js.map +0 -1
- package/dist/handlers/get-service-url.d.ts +0 -3
- package/dist/handlers/get-service-url.d.ts.map +0 -1
- package/dist/handlers/get-service-url.js +0 -11
- package/dist/handlers/get-service-url.js.map +0 -1
- package/dist/start.d.ts +0 -2
- package/dist/start.d.ts.map +0 -1
- package/dist/start.js +0 -77
- package/dist/start.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2EAI0C;AAC1C,+CAAwE;AACxE,kDAAmD;AACnD,qDAG6B;AAC7B,0DAAmD;AAoB5C,MAAM,UAAU,GAAmB,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE;;IACtD,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,kBAAkB,GAAG,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,CAAA;QAC5C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,qCAAuB,CAAC,KAAK,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,CAAC,CAAC;IACtD,OAAO,IAAA,uDAAgC,EAAC;QACtC,IAAI,EAAE,IAAI,EAAE,eAAe;QAC3B,QAAQ,EAAE,OAAO;QACjB,WAAW,EAAE,IAAA,sBAAW,EAAC,kBAAkB,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,0CAAE,WAAW,CAAC;QACvE,YAAY,EAAE,IAAA,uBAAY,EAAC,MAAM,CAAC;KACnC,CAAC,EAAE,CAAC;AACP,CAAC,CAAC;AAXW,QAAA,UAAU,cAWrB;AAEF,mDAAmE;AAA1D,8GAAA,eAAe,OAAA;AAAE,0GAAA,WAAW,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-cors.js","sourceRoot":"","sources":["../../src/middleware/create-cors.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;AAEjB,MAAM,UAAU,GAAG,GAAmB,EAAE,CAC7C,IAAA,cAAI,EAAC;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE;QACrB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"create-cors.js","sourceRoot":"","sources":["../../src/middleware/create-cors.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;AAEjB,MAAM,UAAU,GAAG,GAAmB,EAAE,CAC7C,IAAA,cAAI,EAAC;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE;QACrB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5B,CAAC;QAED,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAChB,CAAC;IACD,WAAW,EAAE,IAAI;CAClB,CAAC,CAAC;AAVQ,QAAA,UAAU,cAUlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling.d.ts","sourceRoot":"","sources":["../../src/middleware/error-handling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE/D,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,QA6BnB"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultErrorHandler =
|
|
3
|
+
exports.defaultErrorHandler = defaultErrorHandler;
|
|
4
4
|
function defaultErrorHandler(error, _req, res, next) {
|
|
5
5
|
var _a;
|
|
6
6
|
if (res.headersSent) {
|
|
7
7
|
return next(error);
|
|
8
8
|
}
|
|
9
|
-
let assertCondition =
|
|
9
|
+
let assertCondition = "Assert condition failed: ";
|
|
10
10
|
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.startsWith(assertCondition)) {
|
|
11
11
|
let errorCode = 500;
|
|
12
12
|
let errorResponse = error.message;
|
|
13
|
-
if (error.message.includes(
|
|
13
|
+
if (error.message.includes("::")) {
|
|
14
14
|
let errorMessage = error.message.slice(assertCondition.length);
|
|
15
15
|
errorCode = parseInt(errorMessage.slice(0, 3));
|
|
16
16
|
errorResponse = errorMessage.slice(5);
|
|
@@ -19,9 +19,7 @@ function defaultErrorHandler(error, _req, res, next) {
|
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
21
|
console.error(error);
|
|
22
|
-
res
|
|
23
|
-
.status(500)
|
|
24
|
-
.json({
|
|
22
|
+
res.status(500).json({
|
|
25
23
|
error: {
|
|
26
24
|
name: error.name,
|
|
27
25
|
message: error.message,
|
|
@@ -30,5 +28,4 @@ function defaultErrorHandler(error, _req, res, next) {
|
|
|
30
28
|
});
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=error-handling-middleware.js.map
|
|
31
|
+
//# sourceMappingURL=error-handling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling.js","sourceRoot":"","sources":["../../src/middleware/error-handling.ts"],"names":[],"mappings":";;AAEA,kDAiCC;AAjCD,SAAgB,mBAAmB,CACjC,KAAY,EACZ,IAAa,EACb,GAAa,EACb,IAAkB;;IAElB,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,IAAI,eAAe,GAAG,2BAA2B,CAAC;IAElD,IAAI,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,0CAAE,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QAChD,IAAI,SAAS,GAAG,GAAG,CAAC;QACpB,IAAI,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC;QAElC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAC/D,SAAS,GAAG,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/C,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;QAED,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC5C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,KAAK,EAAE;gBACL,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/middleware/session.ts"],"names":[],"mappings":";;;;;;AACA,oEAA2C;AAC3C,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAErC,MAAM,aAAa,GAAG,GAAmB,EAAE;IAChD,OAAO,IAAA,wBAAa,EAAC;QACnB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,CAAC,MAAM,CAAC;QACd,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,eAAe;QACvB,QAAQ,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/middleware/session.ts"],"names":[],"mappings":";;;;;;AACA,oEAA2C;AAC3C,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAErC,MAAM,aAAa,GAAG,GAAmB,EAAE;IAChD,OAAO,IAAA,wBAAa,EAAC;QACnB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,CAAC,MAAM,CAAC;QACd,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,eAAe;QACvB,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;AACL,CAAC,CAAC;AATW,QAAA,aAAa,iBASxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensionless-file-name.d.ts","sourceRoot":"","sources":["../../src/rules/extensionless-file-name.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"extensionless-file-name.d.ts","sourceRoot":"","sources":["../../src/rules/extensionless-file-name.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,KAAG,MAGT,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-rules-files.d.ts","sourceRoot":"","sources":["../../src/rules/parse-rules-files.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-rules-files.d.ts","sourceRoot":"","sources":["../../src/rules/parse-rules-files.ts"],"names":[],"mappings":"AAKA,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,CAmCtC"}
|
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseRulesFiles =
|
|
7
|
-
const
|
|
6
|
+
exports.parseRulesFiles = parseRulesFiles;
|
|
7
|
+
const extensionless_file_name_ts_1 = require("./extensionless-file-name.js");
|
|
8
8
|
const assert_ts_1 = require("assert-ts");
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
@@ -13,12 +13,12 @@ function parseRulesFiles(rulesPath) {
|
|
|
13
13
|
let ruleFiles = fs_1.default
|
|
14
14
|
.readdirSync(rulesPath)
|
|
15
15
|
.filter((f) => path_1.default.extname(f) === ".js");
|
|
16
|
-
return (_a = ruleFiles
|
|
16
|
+
return ((_a = ruleFiles
|
|
17
17
|
.map((r) => {
|
|
18
18
|
let filename = path_1.default.join(rulesPath, r);
|
|
19
|
-
let jsonFile = `${(0,
|
|
19
|
+
let jsonFile = `${(0, extensionless_file_name_ts_1.extensionlessFileName)(filename)}.json`;
|
|
20
20
|
(0, assert_ts_1.assert)(!!jsonFile, `no corresponding rule file for ${r}`);
|
|
21
|
-
let rawRule = fs_1.default.readFileSync(jsonFile,
|
|
21
|
+
let rawRule = fs_1.default.readFileSync(jsonFile, "utf8");
|
|
22
22
|
let { enabled, order = 0, stage = "login_success", } = JSON.parse(rawRule);
|
|
23
23
|
if (!enabled) {
|
|
24
24
|
return undefined;
|
|
@@ -28,8 +28,7 @@ function parseRulesFiles(rulesPath) {
|
|
|
28
28
|
});
|
|
29
29
|
return { code, filename, order, stage };
|
|
30
30
|
})
|
|
31
|
-
.flatMap(x => !!x ? x : [])
|
|
32
|
-
.sort((left, right) => left.order - right.order)) !== null && _a !== void 0 ? _a : [];
|
|
31
|
+
.flatMap((x) => (!!x ? x : []))
|
|
32
|
+
.sort((left, right) => left.order - right.order)) !== null && _a !== void 0 ? _a : []);
|
|
33
33
|
}
|
|
34
|
-
exports.parseRulesFiles = parseRulesFiles;
|
|
35
34
|
//# sourceMappingURL=parse-rules-files.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-rules-files.js","sourceRoot":"","sources":["../../src/rules/parse-rules-files.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-rules-files.js","sourceRoot":"","sources":["../../src/rules/parse-rules-files.ts"],"names":[],"mappings":";;;;;AAKA,0CAqCC;AA1CD,6EAAqE;AACrE,yCAAmC;AACnC,4CAAoB;AACpB,gDAAwB;AAExB,SAAgB,eAAe,CAC7B,SAAiB;;IAEjB,IAAI,SAAS,GAAG,YAAE;SACf,WAAW,CAAC,SAAS,CAAC;SACtB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;IAE5C,OAAO,CACL,MAAA,SAAS;SACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,IAAI,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAEvC,IAAI,QAAQ,GAAG,GAAG,IAAA,kDAAqB,EAAC,QAAQ,CAAC,OAAO,CAAC;QAEzD,IAAA,kBAAM,EAAC,CAAC,CAAC,QAAQ,EAAE,kCAAkC,CAAC,EAAE,CAAC,CAAC;QAE1D,IAAI,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEhD,IAAI,EACF,OAAO,EACP,KAAK,GAAG,CAAC,EACT,KAAK,GAAG,eAAe,GACxB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAExB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,IAAI,GAAG,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE;YACnC,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC;QAEH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC1C,CAAC,CAAC;SACD,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAC9B,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,mCAAI,EAAE,CACzD,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RuleContext, RuleUser } from
|
|
2
|
-
export
|
|
1
|
+
import type { RuleContext, RuleUser } from "./types.ts";
|
|
2
|
+
export type RulesRunner = <A, I>(user: RuleUser, context: RuleContext<A, I>) => void;
|
|
3
3
|
export declare function createRulesRunner(rulesPath?: string): RulesRunner;
|
|
4
4
|
//# sourceMappingURL=rules-runner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules-runner.d.ts","sourceRoot":"","sources":["../../src/rules/rules-runner.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAQ,WAAW,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rules-runner.d.ts","sourceRoot":"","sources":["../../src/rules/rules-runner.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAQ,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,EAAE,CAAC,EAC7B,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KACvB,IAAI,CAAC;AAwDV,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CA4BjE"}
|
|
@@ -1,42 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createRulesRunner =
|
|
15
|
+
exports.createRulesRunner = createRulesRunner;
|
|
7
16
|
const path_1 = __importDefault(require("path"));
|
|
8
17
|
const vm_1 = __importDefault(require("vm"));
|
|
9
18
|
const fs_1 = __importDefault(require("fs"));
|
|
10
19
|
const assert_ts_1 = require("assert-ts");
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
const parse_rules_files_ts_1 = require("./parse-rules-files.js");
|
|
21
|
+
function runRule(user, context, rule) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
yield new Promise((resolve, reject) => {
|
|
24
|
+
let sandbox = {
|
|
25
|
+
process,
|
|
26
|
+
Buffer,
|
|
27
|
+
clearImmediate,
|
|
28
|
+
clearInterval,
|
|
29
|
+
clearTimeout,
|
|
30
|
+
setImmediate,
|
|
31
|
+
setInterval,
|
|
32
|
+
setTimeout,
|
|
33
|
+
console,
|
|
34
|
+
require,
|
|
35
|
+
module,
|
|
36
|
+
resolve,
|
|
37
|
+
reject,
|
|
38
|
+
__simulator: Object.assign({
|
|
30
39
|
user,
|
|
31
|
-
context: {
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let script = new vm_1.default.Script(`
|
|
40
|
+
context: Object.assign({}, context),
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
let vmContext = vm_1.default.createContext(sandbox);
|
|
44
|
+
(0, assert_ts_1.assert)(typeof rule !== "undefined", "undefined rule");
|
|
45
|
+
let { code, filename } = rule;
|
|
46
|
+
console.debug(`executing rule ${path_1.default.basename(filename)}`);
|
|
47
|
+
let script = new vm_1.default.Script(`
|
|
40
48
|
(async function(exports) {
|
|
41
49
|
try {
|
|
42
50
|
await (${code})(__simulator.user, __simulator.context, resolve);
|
|
@@ -46,31 +54,31 @@ async function runRule(user, context, rule) {
|
|
|
46
54
|
}
|
|
47
55
|
})(module.exports)
|
|
48
56
|
`);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
script.runInContext(vmContext, {
|
|
58
|
+
filename,
|
|
59
|
+
displayErrors: true,
|
|
60
|
+
timeout: 20000,
|
|
61
|
+
});
|
|
62
|
+
}).catch((error) => console.error(error));
|
|
63
|
+
});
|
|
55
64
|
}
|
|
56
65
|
function createRulesRunner(rulesPath) {
|
|
57
66
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
67
|
let callback = (_user, _context) => { };
|
|
59
|
-
if (typeof rulesPath ===
|
|
68
|
+
if (typeof rulesPath === "undefined") {
|
|
60
69
|
return callback;
|
|
61
70
|
}
|
|
62
71
|
let fullPath = path_1.default.join(process.cwd(), rulesPath);
|
|
63
72
|
(0, assert_ts_1.assert)(fs_1.default.existsSync(fullPath), `no rules directory at ${fullPath}`);
|
|
64
|
-
let rules = (0,
|
|
73
|
+
let rules = (0, parse_rules_files_ts_1.parseRulesFiles)(rulesPath);
|
|
65
74
|
if (rules.length === 0) {
|
|
66
75
|
return callback;
|
|
67
76
|
}
|
|
68
|
-
return
|
|
77
|
+
return (user, context) => __awaiter(this, void 0, void 0, function* () {
|
|
69
78
|
console.debug(`applying ${rules.length} rules`);
|
|
70
79
|
for (let rule of rules) {
|
|
71
|
-
|
|
80
|
+
yield runRule(user, context, rule);
|
|
72
81
|
}
|
|
73
|
-
};
|
|
82
|
+
});
|
|
74
83
|
}
|
|
75
|
-
exports.createRulesRunner = createRulesRunner;
|
|
76
84
|
//# sourceMappingURL=rules-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules-runner.js","sourceRoot":"","sources":["../../src/rules/rules-runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules-runner.js","sourceRoot":"","sources":["../../src/rules/rules-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAkEA,8CA4BC;AA9FD,gDAAwB;AACxB,4CAAoB;AACpB,4CAAoB;AACpB,yCAAmC;AACnC,iEAAyD;AAQzD,SAAe,OAAO,CACpB,IAAc,EACd,OAA0B,EAC1B,IAAU;;QAEV,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,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CACnB,CAAC;AAEF,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE;QACX,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KAC1B,GAAG,CAAC,CAAC;IAEN,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { IdProp } from "@simulacrum/foundation-simulator";
|
|
3
|
+
export declare const auth0UserSchema: z.ZodEffects<z.ZodObject<{
|
|
4
|
+
id: z.ZodDefault<z.ZodString>;
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
password: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
7
|
+
email: z.ZodOptional<z.ZodString>;
|
|
8
|
+
picture: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
password: string;
|
|
13
|
+
email?: string | undefined;
|
|
14
|
+
picture?: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
name: string;
|
|
17
|
+
id?: string | undefined;
|
|
18
|
+
password?: string | undefined;
|
|
19
|
+
email?: string | undefined;
|
|
20
|
+
picture?: string | undefined;
|
|
21
|
+
}>, {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
password: string;
|
|
25
|
+
email?: string | undefined;
|
|
26
|
+
picture?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
name: string;
|
|
29
|
+
id?: string | undefined;
|
|
30
|
+
password?: string | undefined;
|
|
31
|
+
email?: string | undefined;
|
|
32
|
+
picture?: string | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
export type Auth0User = z.infer<typeof auth0UserSchema>;
|
|
35
|
+
export declare const defaultUser: {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
password: string;
|
|
39
|
+
email?: string | undefined;
|
|
40
|
+
picture?: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
export declare const auth0InitialStoreSchema: z.ZodObject<{
|
|
43
|
+
users: z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
44
|
+
id: z.ZodDefault<z.ZodString>;
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
password: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
47
|
+
email: z.ZodOptional<z.ZodString>;
|
|
48
|
+
picture: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
password: string;
|
|
53
|
+
email?: string | undefined;
|
|
54
|
+
picture?: string | undefined;
|
|
55
|
+
}, {
|
|
56
|
+
name: string;
|
|
57
|
+
id?: string | undefined;
|
|
58
|
+
password?: string | undefined;
|
|
59
|
+
email?: string | undefined;
|
|
60
|
+
picture?: string | undefined;
|
|
61
|
+
}>, {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
password: string;
|
|
65
|
+
email?: string | undefined;
|
|
66
|
+
picture?: string | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
name: string;
|
|
69
|
+
id?: string | undefined;
|
|
70
|
+
password?: string | undefined;
|
|
71
|
+
email?: string | undefined;
|
|
72
|
+
picture?: string | undefined;
|
|
73
|
+
}>, "many">;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
users: {
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
password: string;
|
|
79
|
+
email?: string | undefined;
|
|
80
|
+
picture?: string | undefined;
|
|
81
|
+
}[];
|
|
82
|
+
}, {
|
|
83
|
+
users: {
|
|
84
|
+
name: string;
|
|
85
|
+
id?: string | undefined;
|
|
86
|
+
password?: string | undefined;
|
|
87
|
+
email?: string | undefined;
|
|
88
|
+
picture?: string | undefined;
|
|
89
|
+
}[];
|
|
90
|
+
}>;
|
|
91
|
+
export type AuthSession = {
|
|
92
|
+
username: string;
|
|
93
|
+
nonce: string;
|
|
94
|
+
};
|
|
95
|
+
export type Auth0Store = z.output<typeof auth0InitialStoreSchema> & {
|
|
96
|
+
sessions: AuthSession[];
|
|
97
|
+
};
|
|
98
|
+
export type Auth0InitialStore = z.input<typeof auth0InitialStoreSchema>;
|
|
99
|
+
export declare const convertToObj: <T extends {
|
|
100
|
+
[k: string]: any;
|
|
101
|
+
}>(arrayOfObjects: T[], key?: IdProp) => Record<IdProp, T>;
|
|
102
|
+
export declare const convertInitialStateToStoreState: (initialState: Auth0InitialStore | undefined) => {
|
|
103
|
+
users: Record<IdProp, {
|
|
104
|
+
id: string;
|
|
105
|
+
name: string;
|
|
106
|
+
password: string;
|
|
107
|
+
email?: string | undefined;
|
|
108
|
+
picture?: string | undefined;
|
|
109
|
+
}>;
|
|
110
|
+
} | undefined;
|
|
111
|
+
//# sourceMappingURL=entities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/store/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAG1D,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcxB,CAAC;AACL,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACxD,eAAO,MAAM,WAAW;;;;;;CAGtB,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAElC,CAAC;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,GAAG;IAClE,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB,CAAC;AACF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EACzD,gBAAgB,CAAC,EAAE,EACnB,MAAK,MAAa,KACjB,MAAM,CAAC,MAAM,EAAE,CAAC,CAIU,CAAC;AAE9B,eAAO,MAAM,+BAA+B,GAC1C,cAAc,iBAAiB,GAAG,SAAS;;;;;;;;aAQ5C,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertInitialStateToStoreState = exports.convertToObj = exports.auth0InitialStoreSchema = exports.defaultUser = exports.auth0UserSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const faker_1 = require("@faker-js/faker");
|
|
6
|
+
exports.auth0UserSchema = zod_1.z
|
|
7
|
+
.object({
|
|
8
|
+
id: zod_1.z.string().default(""),
|
|
9
|
+
name: zod_1.z.string(),
|
|
10
|
+
password: zod_1.z.string().optional().default("12345"),
|
|
11
|
+
email: zod_1.z.string().email().optional(),
|
|
12
|
+
picture: zod_1.z.string().url().optional(),
|
|
13
|
+
})
|
|
14
|
+
.transform((user) => {
|
|
15
|
+
if (!user.email)
|
|
16
|
+
user.email = faker_1.faker.internet.email({ firstName: user.name });
|
|
17
|
+
user.id = faker_1.faker.database.mongodbObjectId();
|
|
18
|
+
if (!user.picture)
|
|
19
|
+
user.picture = faker_1.faker.image.avatar();
|
|
20
|
+
return user;
|
|
21
|
+
});
|
|
22
|
+
exports.defaultUser = exports.auth0UserSchema.parse({
|
|
23
|
+
name: "default",
|
|
24
|
+
email: "default@example.com",
|
|
25
|
+
});
|
|
26
|
+
exports.auth0InitialStoreSchema = zod_1.z.object({
|
|
27
|
+
users: zod_1.z.array(exports.auth0UserSchema),
|
|
28
|
+
});
|
|
29
|
+
const convertToObj = (arrayOfObjects, key = "id") => arrayOfObjects.reduce((final, obj) => {
|
|
30
|
+
final[obj[key]] = obj;
|
|
31
|
+
return final;
|
|
32
|
+
}, {});
|
|
33
|
+
exports.convertToObj = convertToObj;
|
|
34
|
+
const convertInitialStateToStoreState = (initialState) => {
|
|
35
|
+
if (!initialState)
|
|
36
|
+
return undefined;
|
|
37
|
+
const storeObject = {
|
|
38
|
+
users: (0, exports.convertToObj)(initialState.users, "id"),
|
|
39
|
+
};
|
|
40
|
+
return storeObject;
|
|
41
|
+
};
|
|
42
|
+
exports.convertInitialStateToStoreState = convertInitialStateToStoreState;
|
|
43
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/store/entities.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,2CAAwC;AAE3B,QAAA,eAAe,GAAG,OAAC;KAC7B,MAAM,CAAC;IACN,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;IAChD,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE;IACpC,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACrC,CAAC;KACD,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;IAClB,IAAI,CAAC,IA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ore, ExtendSimulationSchema, ExtendSimulationSchemaInput, ExtendSimulationActions, ExtendSimulationActionsInput, ExtendSimulationSelectors, ExtendSimulationSelectorsInput, TableOutput, AnyState } from "@simulacrum/foundation-simulator";
|
|
2
|
+
import { type Auth0User, type AuthSession, Auth0InitialStore } from "./entities.ts";
|
|
3
|
+
export type ExtendedSchema = ({ slice }: ExtendSimulationSchema) => {
|
|
4
|
+
sessions: (n: string) => TableOutput<AuthSession, AnyState, AuthSession | undefined>;
|
|
5
|
+
users: (n: string) => TableOutput<Auth0User, AnyState, Auth0User | undefined>;
|
|
6
|
+
};
|
|
7
|
+
type ExtendActions = typeof inputActions;
|
|
8
|
+
type ExtendSelectors = typeof inputSelectors;
|
|
9
|
+
export type ExtendedSimulationStore = SimulationStore<ReturnType<ExtendedSchema>, ReturnType<ExtendActions>, ReturnType<ExtendSelectors>>;
|
|
10
|
+
declare const inputActions: (args: ExtendSimulationActions<ExtendedSchema>) => {};
|
|
11
|
+
declare const inputSelectors: (args: ExtendSimulationSelectors<ExtendedSchema>) => {};
|
|
12
|
+
export declare const extendStore: <T>(initialState: Auth0InitialStore | undefined, extended: {
|
|
13
|
+
actions: ExtendSimulationActionsInput<any, ExtendSimulationSchemaInput<T>>;
|
|
14
|
+
selectors: ExtendSimulationSelectorsInput<any, ExtendSimulationSchemaInput<T>>;
|
|
15
|
+
schema?: ExtendSimulationSchemaInput<T>;
|
|
16
|
+
} | undefined) => {
|
|
17
|
+
actions: (args: ExtendSimulationActions<ExtendedSchema>) => any;
|
|
18
|
+
selectors: (args: ExtendSimulationSelectors<ExtendedSchema>) => any;
|
|
19
|
+
schema: ({ slice }: ExtendSimulationSchema) => {
|
|
20
|
+
sessions: (n: string) => TableOutput<AuthSession, AnyState, AuthSession | undefined>;
|
|
21
|
+
users: (n: string) => TableOutput<{
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
password: string;
|
|
25
|
+
email?: string | undefined;
|
|
26
|
+
picture?: string | undefined;
|
|
27
|
+
}, AnyState, {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
password: string;
|
|
31
|
+
email?: string | undefined;
|
|
32
|
+
picture?: string | undefined;
|
|
33
|
+
} | undefined>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,4BAA4B,EAC5B,yBAAyB,EACzB,8BAA8B,EAC9B,WAAW,EACX,QAAQ,EACT,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,sBAAsB,KAAK;IAClE,QAAQ,EAAE,CACR,CAAC,EAAE,MAAM,KACN,WAAW,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;IACjE,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;CAC/E,CAAC;AACF,KAAK,aAAa,GAAG,OAAO,YAAY,CAAC;AACzC,KAAK,eAAe,GAAG,OAAO,cAAc,CAAC;AAC7C,MAAM,MAAM,uBAAuB,GAAG,eAAe,CACnD,UAAU,CAAC,cAAc,CAAC,EAC1B,UAAU,CAAC,aAAa,CAAC,EACzB,UAAU,CAAC,eAAe,CAAC,CAC5B,CAAC;AA2BF,QAAA,MAAM,YAAY,GAAI,MAAM,uBAAuB,CAAC,cAAc,CAAC,OAElE,CAAC;AAWF,QAAA,MAAM,cAAc,GAAI,MAAM,yBAAyB,CAAC,cAAc,CAAC,OAGtE,CAAC;AAWF,eAAO,MAAM,WAAW,GAAI,CAAC,EAC3B,cAAc,iBAAiB,GAAG,SAAS,EAC3C,UACI;IACE,OAAO,EAAE,4BAA4B,CACnC,GAAG,EACH,2BAA2B,CAAC,CAAC,CAAC,CAC/B,CAAC;IACF,SAAS,EAAE,8BAA8B,CACvC,GAAG,EACH,2BAA2B,CAAC,CAAC,CAAC,CAC/B,CAAC;IACF,MAAM,CAAC,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAC;CACzC,GACD,SAAS;oBAnCN,uBAAuB,CAAC,cAAc,CAAC;sBAcvC,yBAAyB,CAAC,cAAc,CAAC;wBAxCpC,sBAAsB;;;;;;;;;;;;;;;;CAkElC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendStore = void 0;
|
|
4
|
+
const entities_ts_1 = require("./entities.js");
|
|
5
|
+
const inputSchema = (initialState, extendedSchema) => ({ slice }) => {
|
|
6
|
+
const storeInitialState = (0, entities_ts_1.convertInitialStateToStoreState)(initialState);
|
|
7
|
+
const extended = extendedSchema ? extendedSchema({ slice }) : {};
|
|
8
|
+
let slices = Object.assign({ sessions: slice.table(), users: slice.table(Object.assign({}, (!storeInitialState
|
|
9
|
+
? {
|
|
10
|
+
initialState: {
|
|
11
|
+
[entities_ts_1.defaultUser.id]: entities_ts_1.defaultUser,
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
: { initialState: storeInitialState.users }))) }, extended);
|
|
15
|
+
return slices;
|
|
16
|
+
};
|
|
17
|
+
const inputActions = (args) => {
|
|
18
|
+
return {};
|
|
19
|
+
};
|
|
20
|
+
const extendActions = (extendedActions) => (args) => {
|
|
21
|
+
return extendedActions
|
|
22
|
+
? // @ts-expect-error schema is cyclical, ignore extension for now
|
|
23
|
+
Object.assign(Object.assign({}, inputActions(args)), extendedActions(args)) : inputActions(args);
|
|
24
|
+
};
|
|
25
|
+
const inputSelectors = (args) => {
|
|
26
|
+
const { createSelector, schema } = args;
|
|
27
|
+
return {};
|
|
28
|
+
};
|
|
29
|
+
const extendSelectors = (extendedSelectors) => (args) => {
|
|
30
|
+
return extendedSelectors
|
|
31
|
+
? // @ts-expect-error schema is cyclical, ignore extension for now
|
|
32
|
+
Object.assign(Object.assign({}, inputSelectors(args)), extendedSelectors(args)) : inputSelectors(args);
|
|
33
|
+
};
|
|
34
|
+
const extendStore = (initialState, extended) => ({
|
|
35
|
+
actions: extendActions(extended === null || extended === void 0 ? void 0 : extended.actions),
|
|
36
|
+
selectors: extendSelectors(extended === null || extended === void 0 ? void 0 : extended.selectors),
|
|
37
|
+
schema: inputSchema(initialState, extended === null || extended === void 0 ? void 0 : extended.schema),
|
|
38
|
+
});
|
|
39
|
+
exports.extendStore = extendStore;
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":";;;AAWA,+CAMuB;AAgBvB,MAAM,WAAW,GACf,CACE,YAAgC,EAChC,cAA+C,EAC/C,EAAE,CACJ,CAAC,EAAE,KAAK,EAA0B,EAAE,EAAE;IACpC,MAAM,iBAAiB,GAAG,IAAA,6CAA+B,EAAC,YAAY,CAAC,CAAC;IAExE,MAAM,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,IAAI,MAAM,mBACR,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAe,EACpC,KAAK,EAAE,KAAK,CAAC,KAAK,mBACb,CAAC,CAAC,iBAAiB;YACpB,CAAC,CAAC;gBACE,YAAY,EAAE;oBACZ,CAAC,yBAAW,CAAC,EAAE,CAAC,EAAE,yBAAW;iBAC9B;aACF;YACH,CAA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