@getstrata/bootstrap 0.2.12 → 0.2.16
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/dist/bootstrap/applicationRegistry.d.ts +1 -16
- package/dist/bootstrap/config.d.ts +2 -7
- package/dist/bootstrap/http/securedRouteModelBinding.d.ts +2 -11
- package/dist/bootstrap/membershipService.d.ts +1 -3
- package/dist/core/auth/membershipService.d.ts +1 -1
- package/dist/core/auth/resolveMembershipService.d.ts +3 -0
- package/dist/core/contracts/applicationContext.d.ts +18 -0
- package/dist/core/contracts/serviceTokens.d.ts +7 -0
- package/dist/core/http/securedRouteModelBinding.d.ts +11 -2
- package/dist/core/queue/createAppQueue.d.ts +0 -1
- package/dist/core/queue/jobRegistry.d.ts +0 -1
- package/dist/core/runtime/applicationRegistry.d.ts +15 -0
- package/dist/entries/applicationRegistry.js +18 -107
- package/dist/entries/config.js +8 -6
- package/dist/entries/context.js +207 -188
- package/dist/entries/createWebRoutes.js +8 -6
- package/dist/entries/http/securedRouteModelBinding.js +100 -189
- package/dist/entries/httpKernel.js +8 -6
- package/dist/entries/membershipService.js +100 -189
- package/dist/entries/providers/view.js +8 -6
- package/dist/entries/providers.js +229 -295
- package/dist/entries/queue/defaultJobs.js +29 -109
- package/dist/framework/public-api.d.ts +1 -2
- package/dist/index.js +164 -146
- package/package.json +3 -8
- package/dist/core/cache/modelCacheTags.d.ts +0 -1
- package/dist/entries/cache/modelCacheTags.js +0 -22
package/dist/entries/context.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// ../../src/core/contracts/applicationContext.ts
|
|
3
|
+
function getRequiredDependency(dependencies, key) {
|
|
4
|
+
const dependency = dependencies[key];
|
|
5
|
+
if (dependency === undefined) {
|
|
6
|
+
throw new Error(`Required dependency "${String(key)}" is not registered.`);
|
|
7
|
+
}
|
|
8
|
+
return dependency;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
12
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
13
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
14
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
15
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
16
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
17
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
18
|
+
|
|
2
19
|
// ../../src/core/logging/logger.ts
|
|
3
20
|
class Logger {
|
|
4
21
|
channel;
|
|
@@ -35,27 +52,51 @@ class Logger {
|
|
|
35
52
|
}
|
|
36
53
|
var appLogger = new Logger("app");
|
|
37
54
|
|
|
38
|
-
// ../../src/
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
// ../../src/core/runtime/applicationRegistry.ts
|
|
56
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
57
|
+
var activeContext;
|
|
58
|
+
function readStoredApplicationContext() {
|
|
59
|
+
if (activeContext) {
|
|
60
|
+
return activeContext;
|
|
61
|
+
}
|
|
62
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
63
|
+
if (globalContext) {
|
|
64
|
+
activeContext = globalContext;
|
|
65
|
+
}
|
|
66
|
+
return activeContext;
|
|
67
|
+
}
|
|
68
|
+
function setActiveApplicationContext(context) {
|
|
69
|
+
activeContext = context;
|
|
70
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
71
|
+
}
|
|
72
|
+
function requireActiveApplicationContext() {
|
|
73
|
+
const context = readStoredApplicationContext();
|
|
74
|
+
if (!context) {
|
|
75
|
+
throw new Error("The application context has not been bootstrapped.");
|
|
76
|
+
}
|
|
77
|
+
return context;
|
|
78
|
+
}
|
|
79
|
+
function resolveApplicationCache() {
|
|
80
|
+
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
81
|
+
}
|
|
82
|
+
function resolveApplicationQueue() {
|
|
83
|
+
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
84
|
+
}
|
|
85
|
+
function resolveApplicationAuth() {
|
|
86
|
+
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
87
|
+
}
|
|
88
|
+
function resolveApplicationPolicyGate() {
|
|
89
|
+
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
90
|
+
}
|
|
91
|
+
function resolveApplicationConfig() {
|
|
92
|
+
return requireActiveApplicationContext().config;
|
|
93
|
+
}
|
|
94
|
+
function resolveApplicationLogger() {
|
|
95
|
+
return appLogger;
|
|
96
|
+
}
|
|
97
|
+
function resolveApplicationDependencies() {
|
|
98
|
+
return requireActiveApplicationContext().dependencies;
|
|
99
|
+
}
|
|
59
100
|
// ../../src/bootstrap/contracts.ts
|
|
60
101
|
class ServiceContainer {
|
|
61
102
|
services = new Map;
|
|
@@ -125,7 +166,7 @@ var requiredDependencyKeys = [
|
|
|
125
166
|
"cache",
|
|
126
167
|
"storage"
|
|
127
168
|
];
|
|
128
|
-
function
|
|
169
|
+
function getRequiredDependency2(dependencies, key) {
|
|
129
170
|
const dependency = dependencies[key];
|
|
130
171
|
if (dependency === undefined) {
|
|
131
172
|
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
@@ -134,59 +175,13 @@ function getRequiredDependency(dependencies, key) {
|
|
|
134
175
|
}
|
|
135
176
|
function assertAppDependenciesComplete(dependencies) {
|
|
136
177
|
for (const key of requiredDependencyKeys) {
|
|
137
|
-
|
|
178
|
+
getRequiredDependency2(dependencies, key);
|
|
138
179
|
}
|
|
139
180
|
}
|
|
140
181
|
function resolveService(dependencies, token) {
|
|
141
182
|
return dependencies.container.resolve(token);
|
|
142
183
|
}
|
|
143
184
|
|
|
144
|
-
// ../../src/bootstrap/applicationRegistry.ts
|
|
145
|
-
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
146
|
-
var activeContext;
|
|
147
|
-
function readStoredApplicationContext() {
|
|
148
|
-
if (activeContext) {
|
|
149
|
-
return activeContext;
|
|
150
|
-
}
|
|
151
|
-
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
152
|
-
if (globalContext) {
|
|
153
|
-
activeContext = globalContext;
|
|
154
|
-
}
|
|
155
|
-
return activeContext;
|
|
156
|
-
}
|
|
157
|
-
function setActiveApplicationContext(context) {
|
|
158
|
-
activeContext = context;
|
|
159
|
-
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
160
|
-
}
|
|
161
|
-
function requireActiveApplicationContext() {
|
|
162
|
-
const context = readStoredApplicationContext();
|
|
163
|
-
if (!context) {
|
|
164
|
-
throw new Error("The application context has not been bootstrapped.");
|
|
165
|
-
}
|
|
166
|
-
return context;
|
|
167
|
-
}
|
|
168
|
-
function resolveApplicationCache() {
|
|
169
|
-
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
170
|
-
}
|
|
171
|
-
function resolveApplicationQueue() {
|
|
172
|
-
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
173
|
-
}
|
|
174
|
-
function resolveApplicationAuth() {
|
|
175
|
-
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
176
|
-
}
|
|
177
|
-
function resolveApplicationPolicyGate() {
|
|
178
|
-
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
179
|
-
}
|
|
180
|
-
function resolveApplicationConfig() {
|
|
181
|
-
return requireActiveApplicationContext().config;
|
|
182
|
-
}
|
|
183
|
-
function resolveApplicationLogger() {
|
|
184
|
-
return appLogger;
|
|
185
|
-
}
|
|
186
|
-
function resolveApplicationDependencies() {
|
|
187
|
-
return requireActiveApplicationContext().dependencies;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
185
|
// ../../src/bootstrap/discoverModules.ts
|
|
191
186
|
var appModules = [];
|
|
192
187
|
function discoverModules() {
|
|
@@ -236,6 +231,21 @@ function resolveAbilitiesForRole(role) {
|
|
|
236
231
|
return [...MEMBER_ABILITIES];
|
|
237
232
|
}
|
|
238
233
|
|
|
234
|
+
// ../../src/bootstrap/config.ts
|
|
235
|
+
var APP_PORT_CONFIG_KEY = "app.port";
|
|
236
|
+
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
237
|
+
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
238
|
+
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
239
|
+
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
240
|
+
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
241
|
+
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
242
|
+
var DEFAULT_APP_PORT = 3000;
|
|
243
|
+
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
244
|
+
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
245
|
+
var DEFAULT_CACHE_DRIVER = "array";
|
|
246
|
+
var DEFAULT_API_TOKEN = "";
|
|
247
|
+
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
248
|
+
|
|
239
249
|
// ../../src/modules/user/provider.ts
|
|
240
250
|
import { OidcProvider } from "@getstrata/core/auth/oauth/oidcProvider";
|
|
241
251
|
import { GitHubOAuthProvider, MockOAuthProvider } from "@getstrata/core/auth/oauth/providers";
|
|
@@ -3255,7 +3265,6 @@ var failedJobService_default = FailedJobService;
|
|
|
3255
3265
|
|
|
3256
3266
|
// ../../src/core/queue/jobRegistry.ts
|
|
3257
3267
|
class JobRegistry {
|
|
3258
|
-
constructor() {}
|
|
3259
3268
|
factories = new Map;
|
|
3260
3269
|
instances = new WeakMap;
|
|
3261
3270
|
register(name, factory) {
|
|
@@ -3279,7 +3288,17 @@ class JobRegistry {
|
|
|
3279
3288
|
return [...this.factories.keys()];
|
|
3280
3289
|
}
|
|
3281
3290
|
}
|
|
3282
|
-
var
|
|
3291
|
+
var JOB_REGISTRY_KEY = Symbol.for("@getstrata/jobRegistry");
|
|
3292
|
+
function readSharedJobRegistry() {
|
|
3293
|
+
const globalRegistry = globalThis[JOB_REGISTRY_KEY];
|
|
3294
|
+
if (globalRegistry) {
|
|
3295
|
+
return globalRegistry;
|
|
3296
|
+
}
|
|
3297
|
+
const registry = new JobRegistry;
|
|
3298
|
+
globalThis[JOB_REGISTRY_KEY] = registry;
|
|
3299
|
+
return registry;
|
|
3300
|
+
}
|
|
3301
|
+
var jobRegistry = readSharedJobRegistry();
|
|
3283
3302
|
|
|
3284
3303
|
// ../../src/core/queue/jobRunner.ts
|
|
3285
3304
|
async function runQueueJob(envelope, failedJobs) {
|
|
@@ -3395,6 +3414,123 @@ function createProductionQueue(driver, options = {}) {
|
|
|
3395
3414
|
return new ResilientQueue(failedJobs, driver === "async");
|
|
3396
3415
|
}
|
|
3397
3416
|
|
|
3417
|
+
// ../../src/core/queue/createAppQueue.ts
|
|
3418
|
+
var FAILED_JOB_SERVICE_TOKEN = "core.failedJobs";
|
|
3419
|
+
function createAppQueue(driver, redisUrl, failedJobs = createFailedJobService(), registerJobs) {
|
|
3420
|
+
return createProductionQueue(driver, {
|
|
3421
|
+
redisUrl,
|
|
3422
|
+
failedJobs,
|
|
3423
|
+
registerJobs
|
|
3424
|
+
});
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
// ../../src/bootstrap/cache/modelCacheTags.ts
|
|
3428
|
+
function cacheTagsForModelWrite(tableName, action) {
|
|
3429
|
+
const module = discoverModules().find((entry) => entry.tableName === tableName);
|
|
3430
|
+
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
3431
|
+
const isDelete = action === "deleted" || action === "force-deleted";
|
|
3432
|
+
const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
3433
|
+
return [...new Set([...baseTags, ...extraTags])];
|
|
3434
|
+
}
|
|
3435
|
+
function discoverModelTableNames() {
|
|
3436
|
+
return discoverModules().map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
// ../../src/bootstrap/listeners/invalidateCacheOnModelWrite.ts
|
|
3440
|
+
var MODEL_WRITE_ACTIONS = ["created", "updated", "deleted", "restored", "force-deleted"];
|
|
3441
|
+
function registerInvalidateCacheOnModelWriteListeners(bus = eventBus) {
|
|
3442
|
+
for (const tableName of discoverModelTableNames()) {
|
|
3443
|
+
for (const action of MODEL_WRITE_ACTIONS) {
|
|
3444
|
+
bus.listen(modelEventName(tableName, action), async () => {
|
|
3445
|
+
const tags = cacheTagsForModelWrite(tableName, action);
|
|
3446
|
+
if (tags.length === 0) {
|
|
3447
|
+
return;
|
|
3448
|
+
}
|
|
3449
|
+
let cache;
|
|
3450
|
+
let queue;
|
|
3451
|
+
try {
|
|
3452
|
+
cache = resolveApplicationCache();
|
|
3453
|
+
queue = resolveApplicationQueue();
|
|
3454
|
+
} catch {
|
|
3455
|
+
return;
|
|
3456
|
+
}
|
|
3457
|
+
const job = createTrackedJob("cache.invalidate-tags", new invalidateCacheTagsJob_default(cache));
|
|
3458
|
+
await queue.dispatch(job, { tags });
|
|
3459
|
+
});
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
|
|
3464
|
+
// ../../src/bootstrap/providers/listeners.ts
|
|
3465
|
+
var registeredListenerGroups = new Set;
|
|
3466
|
+
function registerListenerGroup(name, register) {
|
|
3467
|
+
if (registeredListenerGroups.has(name)) {
|
|
3468
|
+
return;
|
|
3469
|
+
}
|
|
3470
|
+
registeredListenerGroups.add(name);
|
|
3471
|
+
register();
|
|
3472
|
+
}
|
|
3473
|
+
var listenersProvider = {
|
|
3474
|
+
name: "core.listeners",
|
|
3475
|
+
boot() {
|
|
3476
|
+
registerListenerGroup("cache.invalidate-on-model-write", () => {
|
|
3477
|
+
registerInvalidateCacheOnModelWriteListeners();
|
|
3478
|
+
});
|
|
3479
|
+
for (const [index, registerListener] of discoverListeners().entries()) {
|
|
3480
|
+
registerListenerGroup(`app.listener.${index}`, registerListener);
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
};
|
|
3484
|
+
var listeners_default = listenersProvider;
|
|
3485
|
+
|
|
3486
|
+
// ../../src/core/auth/policy.ts
|
|
3487
|
+
var BLOCKED_POLICY_ACTIONS = new Set([
|
|
3488
|
+
"constructor",
|
|
3489
|
+
"toString",
|
|
3490
|
+
"valueOf",
|
|
3491
|
+
"hasOwnProperty",
|
|
3492
|
+
"isPrototypeOf",
|
|
3493
|
+
"propertyIsEnumerable",
|
|
3494
|
+
"__proto__"
|
|
3495
|
+
]);
|
|
3496
|
+
|
|
3497
|
+
class PolicyGate {
|
|
3498
|
+
constructor() {}
|
|
3499
|
+
policies = new Map;
|
|
3500
|
+
register(resource, policy) {
|
|
3501
|
+
this.policies.set(resource, policy);
|
|
3502
|
+
}
|
|
3503
|
+
allows(resource, action, user, model) {
|
|
3504
|
+
const policy = this.policies.get(resource);
|
|
3505
|
+
if (!policy) {
|
|
3506
|
+
return false;
|
|
3507
|
+
}
|
|
3508
|
+
if (BLOCKED_POLICY_ACTIONS.has(action) || !(action in policy)) {
|
|
3509
|
+
return false;
|
|
3510
|
+
}
|
|
3511
|
+
const handler = policy[action];
|
|
3512
|
+
if (typeof handler !== "function") {
|
|
3513
|
+
return false;
|
|
3514
|
+
}
|
|
3515
|
+
const resolvedUser = user === undefined ? currentAuthUser() : user;
|
|
3516
|
+
return model === undefined ? handler.call(policy, resolvedUser) : handler.call(policy, resolvedUser, model);
|
|
3517
|
+
}
|
|
3518
|
+
authorize(resource, action, user, model) {
|
|
3519
|
+
if (!this.allows(resource, action, user, model)) {
|
|
3520
|
+
throw new ForbiddenError2;
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
// ../../src/bootstrap/providers/policy.ts
|
|
3526
|
+
var policyProvider = {
|
|
3527
|
+
name: "core.policy",
|
|
3528
|
+
register({ container }) {
|
|
3529
|
+
container.set(CORE_POLICY_GATE_TOKEN, new PolicyGate);
|
|
3530
|
+
}
|
|
3531
|
+
};
|
|
3532
|
+
var policy_default = policyProvider;
|
|
3533
|
+
|
|
3398
3534
|
// ../../src/core/jobs/dispatchWebhookJob.ts
|
|
3399
3535
|
import { createHmac as createHmac2 } from "crypto";
|
|
3400
3536
|
|
|
@@ -3590,123 +3726,6 @@ function registerDefaultJobs() {
|
|
|
3590
3726
|
jobRegistry.register("webhook.dispatch", () => new dispatchWebhookJob_default);
|
|
3591
3727
|
}
|
|
3592
3728
|
|
|
3593
|
-
// ../../src/core/queue/createAppQueue.ts
|
|
3594
|
-
var FAILED_JOB_SERVICE_TOKEN = "core.failedJobs";
|
|
3595
|
-
function createAppQueue(driver, redisUrl, failedJobs = createFailedJobService(), registerJobs) {
|
|
3596
|
-
return createProductionQueue(driver, {
|
|
3597
|
-
redisUrl,
|
|
3598
|
-
failedJobs,
|
|
3599
|
-
registerJobs
|
|
3600
|
-
});
|
|
3601
|
-
}
|
|
3602
|
-
|
|
3603
|
-
// ../../src/bootstrap/cache/modelCacheTags.ts
|
|
3604
|
-
function cacheTagsForModelWrite(tableName, action) {
|
|
3605
|
-
const module = discoverModules().find((entry) => entry.tableName === tableName);
|
|
3606
|
-
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
3607
|
-
const isDelete = action === "deleted" || action === "force-deleted";
|
|
3608
|
-
const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
3609
|
-
return [...new Set([...baseTags, ...extraTags])];
|
|
3610
|
-
}
|
|
3611
|
-
function discoverModelTableNames() {
|
|
3612
|
-
return discoverModules().map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
3613
|
-
}
|
|
3614
|
-
|
|
3615
|
-
// ../../src/bootstrap/listeners/invalidateCacheOnModelWrite.ts
|
|
3616
|
-
var MODEL_WRITE_ACTIONS = ["created", "updated", "deleted", "restored", "force-deleted"];
|
|
3617
|
-
function registerInvalidateCacheOnModelWriteListeners(bus = eventBus) {
|
|
3618
|
-
for (const tableName of discoverModelTableNames()) {
|
|
3619
|
-
for (const action of MODEL_WRITE_ACTIONS) {
|
|
3620
|
-
bus.listen(modelEventName(tableName, action), async () => {
|
|
3621
|
-
const tags = cacheTagsForModelWrite(tableName, action);
|
|
3622
|
-
if (tags.length === 0) {
|
|
3623
|
-
return;
|
|
3624
|
-
}
|
|
3625
|
-
let cache;
|
|
3626
|
-
let queue;
|
|
3627
|
-
try {
|
|
3628
|
-
cache = resolveApplicationCache();
|
|
3629
|
-
queue = resolveApplicationQueue();
|
|
3630
|
-
} catch {
|
|
3631
|
-
return;
|
|
3632
|
-
}
|
|
3633
|
-
const job = createTrackedJob("cache.invalidate-tags", new invalidateCacheTagsJob_default(cache));
|
|
3634
|
-
await queue.dispatch(job, { tags });
|
|
3635
|
-
});
|
|
3636
|
-
}
|
|
3637
|
-
}
|
|
3638
|
-
}
|
|
3639
|
-
|
|
3640
|
-
// ../../src/bootstrap/providers/listeners.ts
|
|
3641
|
-
var registeredListenerGroups = new Set;
|
|
3642
|
-
function registerListenerGroup(name, register) {
|
|
3643
|
-
if (registeredListenerGroups.has(name)) {
|
|
3644
|
-
return;
|
|
3645
|
-
}
|
|
3646
|
-
registeredListenerGroups.add(name);
|
|
3647
|
-
register();
|
|
3648
|
-
}
|
|
3649
|
-
var listenersProvider = {
|
|
3650
|
-
name: "core.listeners",
|
|
3651
|
-
boot() {
|
|
3652
|
-
registerListenerGroup("cache.invalidate-on-model-write", () => {
|
|
3653
|
-
registerInvalidateCacheOnModelWriteListeners();
|
|
3654
|
-
});
|
|
3655
|
-
for (const [index, registerListener] of discoverListeners().entries()) {
|
|
3656
|
-
registerListenerGroup(`app.listener.${index}`, registerListener);
|
|
3657
|
-
}
|
|
3658
|
-
}
|
|
3659
|
-
};
|
|
3660
|
-
var listeners_default = listenersProvider;
|
|
3661
|
-
|
|
3662
|
-
// ../../src/core/auth/policy.ts
|
|
3663
|
-
var BLOCKED_POLICY_ACTIONS = new Set([
|
|
3664
|
-
"constructor",
|
|
3665
|
-
"toString",
|
|
3666
|
-
"valueOf",
|
|
3667
|
-
"hasOwnProperty",
|
|
3668
|
-
"isPrototypeOf",
|
|
3669
|
-
"propertyIsEnumerable",
|
|
3670
|
-
"__proto__"
|
|
3671
|
-
]);
|
|
3672
|
-
|
|
3673
|
-
class PolicyGate {
|
|
3674
|
-
constructor() {}
|
|
3675
|
-
policies = new Map;
|
|
3676
|
-
register(resource, policy) {
|
|
3677
|
-
this.policies.set(resource, policy);
|
|
3678
|
-
}
|
|
3679
|
-
allows(resource, action, user, model) {
|
|
3680
|
-
const policy = this.policies.get(resource);
|
|
3681
|
-
if (!policy) {
|
|
3682
|
-
return false;
|
|
3683
|
-
}
|
|
3684
|
-
if (BLOCKED_POLICY_ACTIONS.has(action) || !(action in policy)) {
|
|
3685
|
-
return false;
|
|
3686
|
-
}
|
|
3687
|
-
const handler = policy[action];
|
|
3688
|
-
if (typeof handler !== "function") {
|
|
3689
|
-
return false;
|
|
3690
|
-
}
|
|
3691
|
-
const resolvedUser = user === undefined ? currentAuthUser() : user;
|
|
3692
|
-
return model === undefined ? handler.call(policy, resolvedUser) : handler.call(policy, resolvedUser, model);
|
|
3693
|
-
}
|
|
3694
|
-
authorize(resource, action, user, model) {
|
|
3695
|
-
if (!this.allows(resource, action, user, model)) {
|
|
3696
|
-
throw new ForbiddenError2;
|
|
3697
|
-
}
|
|
3698
|
-
}
|
|
3699
|
-
}
|
|
3700
|
-
|
|
3701
|
-
// ../../src/bootstrap/providers/policy.ts
|
|
3702
|
-
var policyProvider = {
|
|
3703
|
-
name: "core.policy",
|
|
3704
|
-
register({ container }) {
|
|
3705
|
-
container.set(CORE_POLICY_GATE_TOKEN, new PolicyGate);
|
|
3706
|
-
}
|
|
3707
|
-
};
|
|
3708
|
-
var policy_default = policyProvider;
|
|
3709
|
-
|
|
3710
3729
|
// ../../src/bootstrap/providers/queue.ts
|
|
3711
3730
|
var queueProvider = {
|
|
3712
3731
|
name: "core.queue",
|
|
@@ -110,6 +110,14 @@ function htmlResponse(html, init = {}) {
|
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
114
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
115
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
116
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
117
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
118
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
119
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
120
|
+
|
|
113
121
|
// ../../src/bootstrap/config.ts
|
|
114
122
|
var APP_PORT_CONFIG_KEY = "app.port";
|
|
115
123
|
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
@@ -117,12 +125,6 @@ var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
|
117
125
|
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
118
126
|
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
119
127
|
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
120
|
-
var CORE_CONFIG_TOKEN = "core.config";
|
|
121
|
-
var CORE_CACHE_TOKEN = "core.cache";
|
|
122
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
123
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
124
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
125
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
126
128
|
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
127
129
|
var DEFAULT_APP_PORT = 3000;
|
|
128
130
|
var DEFAULT_CACHE_TTL_MS = 3600000;
|