@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
|
@@ -64,6 +64,105 @@ class PreconditionFailedError extends HttpError {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
// ../../src/core/contracts/applicationContext.ts
|
|
68
|
+
function getRequiredDependency(dependencies, key) {
|
|
69
|
+
const dependency = dependencies[key];
|
|
70
|
+
if (dependency === undefined) {
|
|
71
|
+
throw new Error(`Required dependency "${String(key)}" is not registered.`);
|
|
72
|
+
}
|
|
73
|
+
return dependency;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
77
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
78
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
79
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
80
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
81
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
82
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
83
|
+
|
|
84
|
+
// ../../src/core/logging/logger.ts
|
|
85
|
+
class Logger {
|
|
86
|
+
channel;
|
|
87
|
+
constructor(channel = "app") {
|
|
88
|
+
this.channel = channel;
|
|
89
|
+
}
|
|
90
|
+
write(level, message, context = {}) {
|
|
91
|
+
const entry = {
|
|
92
|
+
level,
|
|
93
|
+
channel: this.channel,
|
|
94
|
+
message,
|
|
95
|
+
timestamp: new Date().toISOString(),
|
|
96
|
+
...context
|
|
97
|
+
};
|
|
98
|
+
const line = JSON.stringify(entry);
|
|
99
|
+
if (level === "error") {
|
|
100
|
+
console.error(line);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
console.log(line);
|
|
104
|
+
}
|
|
105
|
+
debug(message, context) {
|
|
106
|
+
this.write("debug", message, context);
|
|
107
|
+
}
|
|
108
|
+
info(message, context) {
|
|
109
|
+
this.write("info", message, context);
|
|
110
|
+
}
|
|
111
|
+
warn(message, context) {
|
|
112
|
+
this.write("warn", message, context);
|
|
113
|
+
}
|
|
114
|
+
error(message, context) {
|
|
115
|
+
this.write("error", message, context);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
var appLogger = new Logger("app");
|
|
119
|
+
|
|
120
|
+
// ../../src/core/runtime/applicationRegistry.ts
|
|
121
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
122
|
+
var activeContext;
|
|
123
|
+
function readStoredApplicationContext() {
|
|
124
|
+
if (activeContext) {
|
|
125
|
+
return activeContext;
|
|
126
|
+
}
|
|
127
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
128
|
+
if (globalContext) {
|
|
129
|
+
activeContext = globalContext;
|
|
130
|
+
}
|
|
131
|
+
return activeContext;
|
|
132
|
+
}
|
|
133
|
+
function setActiveApplicationContext(context) {
|
|
134
|
+
activeContext = context;
|
|
135
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
136
|
+
}
|
|
137
|
+
function requireActiveApplicationContext() {
|
|
138
|
+
const context = readStoredApplicationContext();
|
|
139
|
+
if (!context) {
|
|
140
|
+
throw new Error("The application context has not been bootstrapped.");
|
|
141
|
+
}
|
|
142
|
+
return context;
|
|
143
|
+
}
|
|
144
|
+
function resolveApplicationCache() {
|
|
145
|
+
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
146
|
+
}
|
|
147
|
+
function resolveApplicationQueue() {
|
|
148
|
+
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
149
|
+
}
|
|
150
|
+
function resolveApplicationAuth() {
|
|
151
|
+
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
152
|
+
}
|
|
153
|
+
function resolveApplicationPolicyGate() {
|
|
154
|
+
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
155
|
+
}
|
|
156
|
+
function resolveApplicationConfig() {
|
|
157
|
+
return requireActiveApplicationContext().config;
|
|
158
|
+
}
|
|
159
|
+
function resolveApplicationLogger() {
|
|
160
|
+
return appLogger;
|
|
161
|
+
}
|
|
162
|
+
function resolveApplicationDependencies() {
|
|
163
|
+
return requireActiveApplicationContext().dependencies;
|
|
164
|
+
}
|
|
165
|
+
|
|
67
166
|
// ../../src/core/crypto/nonCryptographicHash.ts
|
|
68
167
|
function nonCryptographicDigest(input) {
|
|
69
168
|
return Bun.hash(input).toString(16);
|
|
@@ -167,195 +266,7 @@ function parsePositiveIntParam(value, name = "id") {
|
|
|
167
266
|
return parsed;
|
|
168
267
|
}
|
|
169
268
|
|
|
170
|
-
// ../../src/core/
|
|
171
|
-
class Logger {
|
|
172
|
-
channel;
|
|
173
|
-
constructor(channel = "app") {
|
|
174
|
-
this.channel = channel;
|
|
175
|
-
}
|
|
176
|
-
write(level, message, context = {}) {
|
|
177
|
-
const entry = {
|
|
178
|
-
level,
|
|
179
|
-
channel: this.channel,
|
|
180
|
-
message,
|
|
181
|
-
timestamp: new Date().toISOString(),
|
|
182
|
-
...context
|
|
183
|
-
};
|
|
184
|
-
const line = JSON.stringify(entry);
|
|
185
|
-
if (level === "error") {
|
|
186
|
-
console.error(line);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
console.log(line);
|
|
190
|
-
}
|
|
191
|
-
debug(message, context) {
|
|
192
|
-
this.write("debug", message, context);
|
|
193
|
-
}
|
|
194
|
-
info(message, context) {
|
|
195
|
-
this.write("info", message, context);
|
|
196
|
-
}
|
|
197
|
-
warn(message, context) {
|
|
198
|
-
this.write("warn", message, context);
|
|
199
|
-
}
|
|
200
|
-
error(message, context) {
|
|
201
|
-
this.write("error", message, context);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
var appLogger = new Logger("app");
|
|
205
|
-
|
|
206
|
-
// ../../src/bootstrap/config.ts
|
|
207
|
-
var APP_PORT_CONFIG_KEY = "app.port";
|
|
208
|
-
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
209
|
-
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
210
|
-
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
211
|
-
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
212
|
-
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
213
|
-
var CORE_CONFIG_TOKEN = "core.config";
|
|
214
|
-
var CORE_CACHE_TOKEN = "core.cache";
|
|
215
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
216
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
217
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
218
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
219
|
-
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
220
|
-
var DEFAULT_APP_PORT = 3000;
|
|
221
|
-
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
222
|
-
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
223
|
-
var DEFAULT_CACHE_DRIVER = "array";
|
|
224
|
-
var DEFAULT_API_TOKEN = "";
|
|
225
|
-
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
226
|
-
|
|
227
|
-
// ../../src/bootstrap/contracts.ts
|
|
228
|
-
class ServiceContainer {
|
|
229
|
-
services = new Map;
|
|
230
|
-
singletonFactories = new Map;
|
|
231
|
-
bindings = new Map;
|
|
232
|
-
set(key, value) {
|
|
233
|
-
this.singletonFactories.delete(key);
|
|
234
|
-
this.bindings.delete(key);
|
|
235
|
-
this.services.set(key, value);
|
|
236
|
-
return value;
|
|
237
|
-
}
|
|
238
|
-
singleton(key, factory) {
|
|
239
|
-
this.bindings.delete(key);
|
|
240
|
-
this.services.delete(key);
|
|
241
|
-
this.singletonFactories.set(key, factory);
|
|
242
|
-
}
|
|
243
|
-
bind(key, factory) {
|
|
244
|
-
this.singletonFactories.delete(key);
|
|
245
|
-
this.services.delete(key);
|
|
246
|
-
this.bindings.set(key, factory);
|
|
247
|
-
}
|
|
248
|
-
get(key) {
|
|
249
|
-
if (this.services.has(key)) {
|
|
250
|
-
return this.services.get(key);
|
|
251
|
-
}
|
|
252
|
-
const singletonFactory = this.singletonFactories.get(key);
|
|
253
|
-
if (singletonFactory) {
|
|
254
|
-
const value = singletonFactory(this);
|
|
255
|
-
this.services.set(key, value);
|
|
256
|
-
return value;
|
|
257
|
-
}
|
|
258
|
-
const binding = this.bindings.get(key);
|
|
259
|
-
if (binding) {
|
|
260
|
-
return binding(this);
|
|
261
|
-
}
|
|
262
|
-
throw new Error(`Service "${key}" is not registered.`);
|
|
263
|
-
}
|
|
264
|
-
resolve(key) {
|
|
265
|
-
return this.get(key);
|
|
266
|
-
}
|
|
267
|
-
has(key) {
|
|
268
|
-
return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
class ConfigStore {
|
|
273
|
-
values = new Map;
|
|
274
|
-
set(key, value) {
|
|
275
|
-
this.values.set(key, value);
|
|
276
|
-
return value;
|
|
277
|
-
}
|
|
278
|
-
get(key) {
|
|
279
|
-
return this.values.get(key);
|
|
280
|
-
}
|
|
281
|
-
require(key) {
|
|
282
|
-
if (!this.values.has(key)) {
|
|
283
|
-
throw new Error(`Config key "${key}" is not defined.`);
|
|
284
|
-
}
|
|
285
|
-
return this.values.get(key);
|
|
286
|
-
}
|
|
287
|
-
has(key) {
|
|
288
|
-
return this.values.has(key);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
var requiredDependencyKeys = [
|
|
292
|
-
"container",
|
|
293
|
-
"cache",
|
|
294
|
-
"storage"
|
|
295
|
-
];
|
|
296
|
-
function getRequiredDependency(dependencies, key) {
|
|
297
|
-
const dependency = dependencies[key];
|
|
298
|
-
if (dependency === undefined) {
|
|
299
|
-
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
300
|
-
}
|
|
301
|
-
return dependency;
|
|
302
|
-
}
|
|
303
|
-
function assertAppDependenciesComplete(dependencies) {
|
|
304
|
-
for (const key of requiredDependencyKeys) {
|
|
305
|
-
getRequiredDependency(dependencies, key);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
function resolveService(dependencies, token) {
|
|
309
|
-
return dependencies.container.resolve(token);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// ../../src/bootstrap/applicationRegistry.ts
|
|
313
|
-
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
314
|
-
var activeContext;
|
|
315
|
-
function readStoredApplicationContext() {
|
|
316
|
-
if (activeContext) {
|
|
317
|
-
return activeContext;
|
|
318
|
-
}
|
|
319
|
-
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
320
|
-
if (globalContext) {
|
|
321
|
-
activeContext = globalContext;
|
|
322
|
-
}
|
|
323
|
-
return activeContext;
|
|
324
|
-
}
|
|
325
|
-
function setActiveApplicationContext(context) {
|
|
326
|
-
activeContext = context;
|
|
327
|
-
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
328
|
-
}
|
|
329
|
-
function requireActiveApplicationContext() {
|
|
330
|
-
const context = readStoredApplicationContext();
|
|
331
|
-
if (!context) {
|
|
332
|
-
throw new Error("The application context has not been bootstrapped.");
|
|
333
|
-
}
|
|
334
|
-
return context;
|
|
335
|
-
}
|
|
336
|
-
function resolveApplicationCache() {
|
|
337
|
-
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
338
|
-
}
|
|
339
|
-
function resolveApplicationQueue() {
|
|
340
|
-
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
341
|
-
}
|
|
342
|
-
function resolveApplicationAuth() {
|
|
343
|
-
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
344
|
-
}
|
|
345
|
-
function resolveApplicationPolicyGate() {
|
|
346
|
-
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
347
|
-
}
|
|
348
|
-
function resolveApplicationConfig() {
|
|
349
|
-
return requireActiveApplicationContext().config;
|
|
350
|
-
}
|
|
351
|
-
function resolveApplicationLogger() {
|
|
352
|
-
return appLogger;
|
|
353
|
-
}
|
|
354
|
-
function resolveApplicationDependencies() {
|
|
355
|
-
return requireActiveApplicationContext().dependencies;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// ../../src/bootstrap/http/securedRouteModelBinding.ts
|
|
269
|
+
// ../../src/core/http/securedRouteModelBinding.ts
|
|
359
270
|
function isMutatingPolicyAction(action) {
|
|
360
271
|
return action === "update" || action === "delete";
|
|
361
272
|
}
|
|
@@ -74,6 +74,14 @@ function resolveRegisterRateLimit() {
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
78
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
79
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
80
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
81
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
82
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
83
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
84
|
+
|
|
77
85
|
// ../../src/bootstrap/config.ts
|
|
78
86
|
var APP_PORT_CONFIG_KEY = "app.port";
|
|
79
87
|
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
@@ -81,12 +89,6 @@ var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
|
81
89
|
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
82
90
|
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
83
91
|
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
84
|
-
var CORE_CONFIG_TOKEN = "core.config";
|
|
85
|
-
var CORE_CACHE_TOKEN = "core.cache";
|
|
86
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
87
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
88
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
89
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
90
92
|
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
91
93
|
var DEFAULT_APP_PORT = 3000;
|
|
92
94
|
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
@@ -1,4 +1,103 @@
|
|
|
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
|
+
|
|
19
|
+
// ../../src/core/logging/logger.ts
|
|
20
|
+
class Logger {
|
|
21
|
+
channel;
|
|
22
|
+
constructor(channel = "app") {
|
|
23
|
+
this.channel = channel;
|
|
24
|
+
}
|
|
25
|
+
write(level, message, context = {}) {
|
|
26
|
+
const entry = {
|
|
27
|
+
level,
|
|
28
|
+
channel: this.channel,
|
|
29
|
+
message,
|
|
30
|
+
timestamp: new Date().toISOString(),
|
|
31
|
+
...context
|
|
32
|
+
};
|
|
33
|
+
const line = JSON.stringify(entry);
|
|
34
|
+
if (level === "error") {
|
|
35
|
+
console.error(line);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.log(line);
|
|
39
|
+
}
|
|
40
|
+
debug(message, context) {
|
|
41
|
+
this.write("debug", message, context);
|
|
42
|
+
}
|
|
43
|
+
info(message, context) {
|
|
44
|
+
this.write("info", message, context);
|
|
45
|
+
}
|
|
46
|
+
warn(message, context) {
|
|
47
|
+
this.write("warn", message, context);
|
|
48
|
+
}
|
|
49
|
+
error(message, context) {
|
|
50
|
+
this.write("error", message, context);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var appLogger = new Logger("app");
|
|
54
|
+
|
|
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
|
+
}
|
|
100
|
+
|
|
2
101
|
// ../../src/core/errors/http.ts
|
|
3
102
|
class HttpError extends Error {
|
|
4
103
|
status;
|
|
@@ -301,195 +400,7 @@ class MembershipService {
|
|
|
301
400
|
}
|
|
302
401
|
var membershipService_default = MembershipService;
|
|
303
402
|
|
|
304
|
-
// ../../src/core/
|
|
305
|
-
class Logger {
|
|
306
|
-
channel;
|
|
307
|
-
constructor(channel = "app") {
|
|
308
|
-
this.channel = channel;
|
|
309
|
-
}
|
|
310
|
-
write(level, message, context = {}) {
|
|
311
|
-
const entry = {
|
|
312
|
-
level,
|
|
313
|
-
channel: this.channel,
|
|
314
|
-
message,
|
|
315
|
-
timestamp: new Date().toISOString(),
|
|
316
|
-
...context
|
|
317
|
-
};
|
|
318
|
-
const line = JSON.stringify(entry);
|
|
319
|
-
if (level === "error") {
|
|
320
|
-
console.error(line);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
console.log(line);
|
|
324
|
-
}
|
|
325
|
-
debug(message, context) {
|
|
326
|
-
this.write("debug", message, context);
|
|
327
|
-
}
|
|
328
|
-
info(message, context) {
|
|
329
|
-
this.write("info", message, context);
|
|
330
|
-
}
|
|
331
|
-
warn(message, context) {
|
|
332
|
-
this.write("warn", message, context);
|
|
333
|
-
}
|
|
334
|
-
error(message, context) {
|
|
335
|
-
this.write("error", message, context);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
var appLogger = new Logger("app");
|
|
339
|
-
|
|
340
|
-
// ../../src/bootstrap/config.ts
|
|
341
|
-
var APP_PORT_CONFIG_KEY = "app.port";
|
|
342
|
-
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
343
|
-
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
344
|
-
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
345
|
-
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
346
|
-
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
347
|
-
var CORE_CONFIG_TOKEN = "core.config";
|
|
348
|
-
var CORE_CACHE_TOKEN = "core.cache";
|
|
349
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
350
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
351
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
352
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
353
|
-
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
354
|
-
var DEFAULT_APP_PORT = 3000;
|
|
355
|
-
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
356
|
-
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
357
|
-
var DEFAULT_CACHE_DRIVER = "array";
|
|
358
|
-
var DEFAULT_API_TOKEN = "";
|
|
359
|
-
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
360
|
-
|
|
361
|
-
// ../../src/bootstrap/contracts.ts
|
|
362
|
-
class ServiceContainer {
|
|
363
|
-
services = new Map;
|
|
364
|
-
singletonFactories = new Map;
|
|
365
|
-
bindings = new Map;
|
|
366
|
-
set(key, value) {
|
|
367
|
-
this.singletonFactories.delete(key);
|
|
368
|
-
this.bindings.delete(key);
|
|
369
|
-
this.services.set(key, value);
|
|
370
|
-
return value;
|
|
371
|
-
}
|
|
372
|
-
singleton(key, factory) {
|
|
373
|
-
this.bindings.delete(key);
|
|
374
|
-
this.services.delete(key);
|
|
375
|
-
this.singletonFactories.set(key, factory);
|
|
376
|
-
}
|
|
377
|
-
bind(key, factory) {
|
|
378
|
-
this.singletonFactories.delete(key);
|
|
379
|
-
this.services.delete(key);
|
|
380
|
-
this.bindings.set(key, factory);
|
|
381
|
-
}
|
|
382
|
-
get(key) {
|
|
383
|
-
if (this.services.has(key)) {
|
|
384
|
-
return this.services.get(key);
|
|
385
|
-
}
|
|
386
|
-
const singletonFactory = this.singletonFactories.get(key);
|
|
387
|
-
if (singletonFactory) {
|
|
388
|
-
const value = singletonFactory(this);
|
|
389
|
-
this.services.set(key, value);
|
|
390
|
-
return value;
|
|
391
|
-
}
|
|
392
|
-
const binding = this.bindings.get(key);
|
|
393
|
-
if (binding) {
|
|
394
|
-
return binding(this);
|
|
395
|
-
}
|
|
396
|
-
throw new Error(`Service "${key}" is not registered.`);
|
|
397
|
-
}
|
|
398
|
-
resolve(key) {
|
|
399
|
-
return this.get(key);
|
|
400
|
-
}
|
|
401
|
-
has(key) {
|
|
402
|
-
return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
class ConfigStore {
|
|
407
|
-
values = new Map;
|
|
408
|
-
set(key, value) {
|
|
409
|
-
this.values.set(key, value);
|
|
410
|
-
return value;
|
|
411
|
-
}
|
|
412
|
-
get(key) {
|
|
413
|
-
return this.values.get(key);
|
|
414
|
-
}
|
|
415
|
-
require(key) {
|
|
416
|
-
if (!this.values.has(key)) {
|
|
417
|
-
throw new Error(`Config key "${key}" is not defined.`);
|
|
418
|
-
}
|
|
419
|
-
return this.values.get(key);
|
|
420
|
-
}
|
|
421
|
-
has(key) {
|
|
422
|
-
return this.values.has(key);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
var requiredDependencyKeys = [
|
|
426
|
-
"container",
|
|
427
|
-
"cache",
|
|
428
|
-
"storage"
|
|
429
|
-
];
|
|
430
|
-
function getRequiredDependency(dependencies, key) {
|
|
431
|
-
const dependency = dependencies[key];
|
|
432
|
-
if (dependency === undefined) {
|
|
433
|
-
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
434
|
-
}
|
|
435
|
-
return dependency;
|
|
436
|
-
}
|
|
437
|
-
function assertAppDependenciesComplete(dependencies) {
|
|
438
|
-
for (const key of requiredDependencyKeys) {
|
|
439
|
-
getRequiredDependency(dependencies, key);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
function resolveService(dependencies, token) {
|
|
443
|
-
return dependencies.container.resolve(token);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// ../../src/bootstrap/applicationRegistry.ts
|
|
447
|
-
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
448
|
-
var activeContext;
|
|
449
|
-
function readStoredApplicationContext() {
|
|
450
|
-
if (activeContext) {
|
|
451
|
-
return activeContext;
|
|
452
|
-
}
|
|
453
|
-
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
454
|
-
if (globalContext) {
|
|
455
|
-
activeContext = globalContext;
|
|
456
|
-
}
|
|
457
|
-
return activeContext;
|
|
458
|
-
}
|
|
459
|
-
function setActiveApplicationContext(context) {
|
|
460
|
-
activeContext = context;
|
|
461
|
-
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
462
|
-
}
|
|
463
|
-
function requireActiveApplicationContext() {
|
|
464
|
-
const context = readStoredApplicationContext();
|
|
465
|
-
if (!context) {
|
|
466
|
-
throw new Error("The application context has not been bootstrapped.");
|
|
467
|
-
}
|
|
468
|
-
return context;
|
|
469
|
-
}
|
|
470
|
-
function resolveApplicationCache() {
|
|
471
|
-
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
472
|
-
}
|
|
473
|
-
function resolveApplicationQueue() {
|
|
474
|
-
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
475
|
-
}
|
|
476
|
-
function resolveApplicationAuth() {
|
|
477
|
-
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
478
|
-
}
|
|
479
|
-
function resolveApplicationPolicyGate() {
|
|
480
|
-
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
481
|
-
}
|
|
482
|
-
function resolveApplicationConfig() {
|
|
483
|
-
return requireActiveApplicationContext().config;
|
|
484
|
-
}
|
|
485
|
-
function resolveApplicationLogger() {
|
|
486
|
-
return appLogger;
|
|
487
|
-
}
|
|
488
|
-
function resolveApplicationDependencies() {
|
|
489
|
-
return requireActiveApplicationContext().dependencies;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// ../../src/bootstrap/membershipService.ts
|
|
403
|
+
// ../../src/core/auth/resolveMembershipService.ts
|
|
493
404
|
function resolveMembershipService() {
|
|
494
405
|
const dependencies = resolveApplicationDependencies();
|
|
495
406
|
if (dependencies.container.has("core.membership")) {
|
|
@@ -79,6 +79,14 @@ function htmlResponse(html, init = {}) {
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
83
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
84
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
85
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
86
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
87
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
88
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
89
|
+
|
|
82
90
|
// ../../src/bootstrap/config.ts
|
|
83
91
|
var APP_PORT_CONFIG_KEY = "app.port";
|
|
84
92
|
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
@@ -86,12 +94,6 @@ var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
|
86
94
|
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
87
95
|
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
88
96
|
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
89
|
-
var CORE_CONFIG_TOKEN = "core.config";
|
|
90
|
-
var CORE_CACHE_TOKEN = "core.cache";
|
|
91
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
92
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
93
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
94
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
95
97
|
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
96
98
|
var DEFAULT_APP_PORT = 3000;
|
|
97
99
|
var DEFAULT_CACHE_TTL_MS = 3600000;
|