UNPKG

@simulacrum/auth0-simulator

Version:

Run local instance of Auth0 API for local development and integration testing

29 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deriveScope = exports.createPersonQuery = void 0; const assert_ts_1 = require("assert-ts"); const createPersonQuery = (store) => (predicate) => { const users = store.schema.users.selectTableAsList(store.store.getState()); return users.find(predicate); }; exports.createPersonQuery = createPersonQuery; const deriveScope = ({ scopeConfig, clientID, audience, }) => { if (typeof scopeConfig === "string") return scopeConfig; let defaultScope = scopeConfig.find((application) => application.clientID === "default"); (0, assert_ts_1.assert)(!!clientID, `500::Did not have a clientID to derive the scope`); let application = scopeConfig.find((application) => application.clientID === clientID && (application.audience ? application.audience === audience : true)); if (!application) { let ignoreAudience = scopeConfig.find((application) => application.clientID === clientID); (0, assert_ts_1.assert)(ignoreAudience === undefined, `500::Found application matching clientID, ${ignoreAudience === null || ignoreAudience === void 0 ? void 0 : ignoreAudience.clientID}, but incorrect audience, configured: ${ignoreAudience === null || ignoreAudience === void 0 ? void 0 : ignoreAudience.audience} :: passed: ${audience}`); } if (!application && defaultScope) { application = defaultScope; } (0, assert_ts_1.assert)(!!application, `500::Could not find application with clientID: ${clientID}`); (0, assert_ts_1.assert)(!!application.scope, `500::${application.clientID} is expected to have a scope`); return application.scope; }; exports.deriveScope = deriveScope; //# sourceMappingURL=utils.js.map