@getstrata/bootstrap 0.2.9 → 0.2.10

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.
@@ -1,4 +1,7 @@
1
1
  // @bun
2
+ // ../../src/bootstrap/membershipService.ts
3
+ import { resolveApplicationDependencies } from "@getstrata/core";
4
+
2
5
  // ../../src/core/errors/http.ts
3
6
  class HttpError extends Error {
4
7
  status;
@@ -44,9 +47,22 @@ class PreconditionFailedError extends HttpError {
44
47
  }
45
48
  }
46
49
 
47
- // ../../src/core/auth/authContext.ts
50
+ // ../../src/core/runtime/asyncContextStore.ts
48
51
  import { AsyncLocalStorage } from "async_hooks";
49
- var authContext = new AsyncLocalStorage;
52
+ function createAsyncContextStore(key) {
53
+ const symbol = Symbol.for(key);
54
+ const globalRecord = globalThis;
55
+ const existing = globalRecord[symbol];
56
+ if (existing) {
57
+ return existing;
58
+ }
59
+ const store = new AsyncLocalStorage;
60
+ globalRecord[symbol] = store;
61
+ return store;
62
+ }
63
+
64
+ // ../../src/core/auth/authContext.ts
65
+ var authContext = createAsyncContextStore("@getstrata/authContext");
50
66
  function currentAuthUser() {
51
67
  return authContext.getStore() ?? null;
52
68
  }
@@ -74,9 +90,6 @@ function resolveUserId(user) {
74
90
  return userId;
75
91
  }
76
92
 
77
- // ../../src/core/auth/membershipContext.ts
78
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
79
-
80
93
  // ../../src/config/database.ts
81
94
  function readInteger(name, fallback) {
82
95
  const parsed = Number.parseInt(process.env[name] ?? String(fallback), 10);
@@ -91,8 +104,7 @@ var databaseConfig = {
91
104
  };
92
105
 
93
106
  // ../../src/core/database/connectionContext.ts
94
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
95
- var activeConnection = new AsyncLocalStorage2;
107
+ var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
96
108
  function getActiveDatabaseConnection(fallback) {
97
109
  return activeConnection.getStore() ?? fallback;
98
110
  }
@@ -233,7 +245,7 @@ class OrganizationMemberRepository {
233
245
  var memberRepository_default = OrganizationMemberRepository;
234
246
 
235
247
  // ../../src/core/auth/membershipContext.ts
236
- var membershipContext = new AsyncLocalStorage3;
248
+ var membershipContext = createAsyncContextStore("@getstrata/membershipContext");
237
249
  var membershipRepository = new memberRepository_default;
238
250
 
239
251
  // ../../src/core/auth/membershipService.ts
@@ -292,181 +304,6 @@ class MembershipService {
292
304
  }
293
305
  var membershipService_default = MembershipService;
294
306
 
295
- // ../../src/core/logging/logger.ts
296
- class Logger {
297
- channel;
298
- constructor(channel = "app") {
299
- this.channel = channel;
300
- }
301
- write(level, message, context = {}) {
302
- const entry = {
303
- level,
304
- channel: this.channel,
305
- message,
306
- timestamp: new Date().toISOString(),
307
- ...context
308
- };
309
- const line = JSON.stringify(entry);
310
- if (level === "error") {
311
- console.error(line);
312
- return;
313
- }
314
- console.log(line);
315
- }
316
- debug(message, context) {
317
- this.write("debug", message, context);
318
- }
319
- info(message, context) {
320
- this.write("info", message, context);
321
- }
322
- warn(message, context) {
323
- this.write("warn", message, context);
324
- }
325
- error(message, context) {
326
- this.write("error", message, context);
327
- }
328
- }
329
- var appLogger = new Logger("app");
330
-
331
- // ../../src/bootstrap/config.ts
332
- var APP_PORT_CONFIG_KEY = "app.port";
333
- var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
334
- var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
335
- var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
336
- var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
337
- var DATABASE_URL_CONFIG_KEY = "database.url";
338
- var CORE_CONFIG_TOKEN = "core.config";
339
- var CORE_CACHE_TOKEN = "core.cache";
340
- var CORE_QUEUE_TOKEN = "core.queue";
341
- var CORE_POLICY_GATE_TOKEN = "core.policyGate";
342
- var CORE_AUTH_TOKEN = "core.auth";
343
- var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
344
- var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
345
- var DEFAULT_APP_PORT = 3000;
346
- var DEFAULT_CACHE_TTL_MS = 3600000;
347
- var DEFAULT_CACHE_MAX_ENTRIES = 100;
348
- var DEFAULT_CACHE_DRIVER = "array";
349
- var DEFAULT_API_TOKEN = "";
350
- var DEFAULT_QUEUE_DRIVER = "sync";
351
-
352
- // ../../src/bootstrap/contracts.ts
353
- class ServiceContainer {
354
- services = new Map;
355
- singletonFactories = new Map;
356
- bindings = new Map;
357
- set(key, value) {
358
- this.singletonFactories.delete(key);
359
- this.bindings.delete(key);
360
- this.services.set(key, value);
361
- return value;
362
- }
363
- singleton(key, factory) {
364
- this.bindings.delete(key);
365
- this.services.delete(key);
366
- this.singletonFactories.set(key, factory);
367
- }
368
- bind(key, factory) {
369
- this.singletonFactories.delete(key);
370
- this.services.delete(key);
371
- this.bindings.set(key, factory);
372
- }
373
- get(key) {
374
- if (this.services.has(key)) {
375
- return this.services.get(key);
376
- }
377
- const singletonFactory = this.singletonFactories.get(key);
378
- if (singletonFactory) {
379
- const value = singletonFactory(this);
380
- this.services.set(key, value);
381
- return value;
382
- }
383
- const binding = this.bindings.get(key);
384
- if (binding) {
385
- return binding(this);
386
- }
387
- throw new Error(`Service "${key}" is not registered.`);
388
- }
389
- resolve(key) {
390
- return this.get(key);
391
- }
392
- has(key) {
393
- return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
394
- }
395
- }
396
-
397
- class ConfigStore {
398
- values = new Map;
399
- set(key, value) {
400
- this.values.set(key, value);
401
- return value;
402
- }
403
- get(key) {
404
- return this.values.get(key);
405
- }
406
- require(key) {
407
- if (!this.values.has(key)) {
408
- throw new Error(`Config key "${key}" is not defined.`);
409
- }
410
- return this.values.get(key);
411
- }
412
- has(key) {
413
- return this.values.has(key);
414
- }
415
- }
416
- var requiredDependencyKeys = [
417
- "container",
418
- "cache",
419
- "storage"
420
- ];
421
- function getRequiredDependency(dependencies, key) {
422
- const dependency = dependencies[key];
423
- if (dependency === undefined) {
424
- throw new Error(`Required dependency "${key}" is not registered.`);
425
- }
426
- return dependency;
427
- }
428
- function assertAppDependenciesComplete(dependencies) {
429
- for (const key of requiredDependencyKeys) {
430
- getRequiredDependency(dependencies, key);
431
- }
432
- }
433
- function resolveService(dependencies, token) {
434
- return dependencies.container.resolve(token);
435
- }
436
-
437
- // ../../src/bootstrap/applicationRegistry.ts
438
- var activeContext;
439
- function setActiveApplicationContext(context) {
440
- activeContext = context;
441
- }
442
- function requireActiveApplicationContext() {
443
- if (!activeContext) {
444
- throw new Error("The application context has not been bootstrapped.");
445
- }
446
- return activeContext;
447
- }
448
- function resolveApplicationCache() {
449
- return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
450
- }
451
- function resolveApplicationQueue() {
452
- return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
453
- }
454
- function resolveApplicationAuth() {
455
- return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
456
- }
457
- function resolveApplicationPolicyGate() {
458
- return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
459
- }
460
- function resolveApplicationConfig() {
461
- return requireActiveApplicationContext().config;
462
- }
463
- function resolveApplicationLogger() {
464
- return appLogger;
465
- }
466
- function resolveApplicationDependencies() {
467
- return requireActiveApplicationContext().dependencies;
468
- }
469
-
470
307
  // ../../src/bootstrap/membershipService.ts
471
308
  function resolveMembershipService() {
472
309
  const dependencies = resolveApplicationDependencies();
@@ -14,9 +14,22 @@ function isViewsEnabled() {
14
14
  return readFrontendMode() === "server-htmx";
15
15
  }
16
16
 
17
- // ../../src/core/http/requestMetaContext.ts
17
+ // ../../src/core/runtime/asyncContextStore.ts
18
18
  import { AsyncLocalStorage } from "async_hooks";
19
- var requestMetaContext = new AsyncLocalStorage;
19
+ function createAsyncContextStore(key) {
20
+ const symbol = Symbol.for(key);
21
+ const globalRecord = globalThis;
22
+ const existing = globalRecord[symbol];
23
+ if (existing) {
24
+ return existing;
25
+ }
26
+ const store = new AsyncLocalStorage;
27
+ globalRecord[symbol] = store;
28
+ return store;
29
+ }
30
+
31
+ // ../../src/core/http/requestMetaContext.ts
32
+ var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
20
33
  function currentRequestMeta() {
21
34
  return requestMetaContext.getStore() ?? {
22
35
  ipAddress: null,
@@ -130,8 +143,7 @@ var databaseConfig = {
130
143
  };
131
144
 
132
145
  // ../../src/core/database/connectionContext.ts
133
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
134
- var activeConnection = new AsyncLocalStorage2;
146
+ var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
135
147
  function getActiveDatabaseConnection(fallback) {
136
148
  return activeConnection.getStore() ?? fallback;
137
149
  }
@@ -442,8 +454,7 @@ import { resolveDefaultTokenExpiryDays as resolveDefaultTokenExpiryDays2 } from
442
454
  var tokenServiceToken = CORE_TOKEN_SERVICE_TOKEN;
443
455
 
444
456
  // ../../src/core/auth/authContext.ts
445
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
446
- var authContext = new AsyncLocalStorage3;
457
+ var authContext = createAsyncContextStore("@getstrata/authContext");
447
458
  function currentAuthUser() {
448
459
  return authContext.getStore() ?? null;
449
460
  }
@@ -106,9 +106,22 @@ var databaseConfig = {
106
106
  connectionTimeoutSeconds: readInteger("DB_CONNECTION_TIMEOUT", 10)
107
107
  };
108
108
 
109
- // ../../src/core/database/connectionContext.ts
109
+ // ../../src/core/runtime/asyncContextStore.ts
110
110
  import { AsyncLocalStorage } from "async_hooks";
111
- var activeConnection = new AsyncLocalStorage;
111
+ function createAsyncContextStore(key) {
112
+ const symbol = Symbol.for(key);
113
+ const globalRecord = globalThis;
114
+ const existing = globalRecord[symbol];
115
+ if (existing) {
116
+ return existing;
117
+ }
118
+ const store = new AsyncLocalStorage;
119
+ globalRecord[symbol] = store;
120
+ return store;
121
+ }
122
+
123
+ // ../../src/core/database/connectionContext.ts
124
+ var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
112
125
  function getActiveDatabaseConnection(fallback) {
113
126
  return activeConnection.getStore() ?? fallback;
114
127
  }
@@ -424,8 +437,7 @@ class PreconditionFailedError extends HttpError {
424
437
  }
425
438
 
426
439
  // ../../src/core/auth/authContext.ts
427
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
428
- var authContext = new AsyncLocalStorage2;
440
+ var authContext = createAsyncContextStore("@getstrata/authContext");
429
441
  function currentAuthUser() {
430
442
  return authContext.getStore() ?? null;
431
443
  }
@@ -1299,6 +1311,9 @@ function discoverListeners() {
1299
1311
  return appListeners;
1300
1312
  }
1301
1313
 
1314
+ // ../../src/bootstrap/listeners/invalidateCacheOnModelWrite.ts
1315
+ import { resolveApplicationCache as resolveApplicationCache2, resolveApplicationQueue } from "@getstrata/core";
1316
+
1302
1317
  // ../../src/bootstrap/discoverModules.ts
1303
1318
  import { readdirSync as readdirSync2 } from "fs";
1304
1319
  import { join as join2 } from "path";
@@ -3246,6 +3261,9 @@ function createProductionQueue(driver, options = {}) {
3246
3261
  return new ResilientQueue(failedJobs, driver === "async");
3247
3262
  }
3248
3263
 
3264
+ // ../../src/bootstrap/queue/defaultJobs.ts
3265
+ import { resolveApplicationCache } from "@getstrata/core";
3266
+
3249
3267
  // ../../src/core/jobs/dispatchWebhookJob.ts
3250
3268
  import { createHmac as createHmac2 } from "crypto";
3251
3269
 
@@ -3433,160 +3451,6 @@ class DispatchWebhookJob extends Job {
3433
3451
  }
3434
3452
  var dispatchWebhookJob_default = DispatchWebhookJob;
3435
3453
 
3436
- // ../../src/core/logging/logger.ts
3437
- class Logger {
3438
- channel;
3439
- constructor(channel = "app") {
3440
- this.channel = channel;
3441
- }
3442
- write(level, message, context = {}) {
3443
- const entry = {
3444
- level,
3445
- channel: this.channel,
3446
- message,
3447
- timestamp: new Date().toISOString(),
3448
- ...context
3449
- };
3450
- const line = JSON.stringify(entry);
3451
- if (level === "error") {
3452
- console.error(line);
3453
- return;
3454
- }
3455
- console.log(line);
3456
- }
3457
- debug(message, context) {
3458
- this.write("debug", message, context);
3459
- }
3460
- info(message, context) {
3461
- this.write("info", message, context);
3462
- }
3463
- warn(message, context) {
3464
- this.write("warn", message, context);
3465
- }
3466
- error(message, context) {
3467
- this.write("error", message, context);
3468
- }
3469
- }
3470
- var appLogger = new Logger("app");
3471
-
3472
- // ../../src/bootstrap/contracts.ts
3473
- class ServiceContainer {
3474
- services = new Map;
3475
- singletonFactories = new Map;
3476
- bindings = new Map;
3477
- set(key, value) {
3478
- this.singletonFactories.delete(key);
3479
- this.bindings.delete(key);
3480
- this.services.set(key, value);
3481
- return value;
3482
- }
3483
- singleton(key, factory) {
3484
- this.bindings.delete(key);
3485
- this.services.delete(key);
3486
- this.singletonFactories.set(key, factory);
3487
- }
3488
- bind(key, factory) {
3489
- this.singletonFactories.delete(key);
3490
- this.services.delete(key);
3491
- this.bindings.set(key, factory);
3492
- }
3493
- get(key) {
3494
- if (this.services.has(key)) {
3495
- return this.services.get(key);
3496
- }
3497
- const singletonFactory = this.singletonFactories.get(key);
3498
- if (singletonFactory) {
3499
- const value = singletonFactory(this);
3500
- this.services.set(key, value);
3501
- return value;
3502
- }
3503
- const binding = this.bindings.get(key);
3504
- if (binding) {
3505
- return binding(this);
3506
- }
3507
- throw new Error(`Service "${key}" is not registered.`);
3508
- }
3509
- resolve(key) {
3510
- return this.get(key);
3511
- }
3512
- has(key) {
3513
- return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
3514
- }
3515
- }
3516
-
3517
- class ConfigStore {
3518
- values = new Map;
3519
- set(key, value) {
3520
- this.values.set(key, value);
3521
- return value;
3522
- }
3523
- get(key) {
3524
- return this.values.get(key);
3525
- }
3526
- require(key) {
3527
- if (!this.values.has(key)) {
3528
- throw new Error(`Config key "${key}" is not defined.`);
3529
- }
3530
- return this.values.get(key);
3531
- }
3532
- has(key) {
3533
- return this.values.has(key);
3534
- }
3535
- }
3536
- var requiredDependencyKeys = [
3537
- "container",
3538
- "cache",
3539
- "storage"
3540
- ];
3541
- function getRequiredDependency(dependencies, key) {
3542
- const dependency = dependencies[key];
3543
- if (dependency === undefined) {
3544
- throw new Error(`Required dependency "${key}" is not registered.`);
3545
- }
3546
- return dependency;
3547
- }
3548
- function assertAppDependenciesComplete(dependencies) {
3549
- for (const key of requiredDependencyKeys) {
3550
- getRequiredDependency(dependencies, key);
3551
- }
3552
- }
3553
- function resolveService(dependencies, token) {
3554
- return dependencies.container.resolve(token);
3555
- }
3556
-
3557
- // ../../src/bootstrap/applicationRegistry.ts
3558
- var activeContext;
3559
- function setActiveApplicationContext(context) {
3560
- activeContext = context;
3561
- }
3562
- function requireActiveApplicationContext() {
3563
- if (!activeContext) {
3564
- throw new Error("The application context has not been bootstrapped.");
3565
- }
3566
- return activeContext;
3567
- }
3568
- function resolveApplicationCache() {
3569
- return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
3570
- }
3571
- function resolveApplicationQueue() {
3572
- return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
3573
- }
3574
- function resolveApplicationAuth() {
3575
- return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
3576
- }
3577
- function resolveApplicationPolicyGate() {
3578
- return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
3579
- }
3580
- function resolveApplicationConfig() {
3581
- return requireActiveApplicationContext().config;
3582
- }
3583
- function resolveApplicationLogger() {
3584
- return appLogger;
3585
- }
3586
- function resolveApplicationDependencies() {
3587
- return requireActiveApplicationContext().dependencies;
3588
- }
3589
-
3590
3454
  // ../../src/bootstrap/queue/defaultJobs.ts
3591
3455
  function registerDefaultJobs() {
3592
3456
  jobRegistry.register("cache.invalidate-tags", () => {
@@ -3618,7 +3482,7 @@ function registerInvalidateCacheOnModelWriteListeners(bus = eventBus) {
3618
3482
  let cache;
3619
3483
  let queue;
3620
3484
  try {
3621
- cache = resolveApplicationCache();
3485
+ cache = resolveApplicationCache2();
3622
3486
  queue = resolveApplicationQueue();
3623
3487
  } catch {
3624
3488
  return;
@@ -3852,8 +3716,7 @@ function isViewsEnabled() {
3852
3716
  }
3853
3717
 
3854
3718
  // ../../src/core/http/requestMetaContext.ts
3855
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
3856
- var requestMetaContext = new AsyncLocalStorage3;
3719
+ var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
3857
3720
  function currentRequestMeta() {
3858
3721
  return requestMetaContext.getStore() ?? {
3859
3722
  ipAddress: null,