@getstrata/core 0.5.37 → 0.5.39

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.
@@ -0,0 +1,60 @@
1
+ // @bun
2
+ // ../../src/core/cache/taggedCache.ts
3
+ class TaggedCache {
4
+ store;
5
+ tags;
6
+ constructor(store, tags) {
7
+ this.store = store;
8
+ this.tags = tags;
9
+ }
10
+ async remember(key, callback, ttlMs) {
11
+ const value = await this.store.getOrSet(key, callback, ttlMs);
12
+ await this.store.attachTags(key, this.tags);
13
+ return value;
14
+ }
15
+ async flush() {
16
+ return this.store.flushTags(this.tags);
17
+ }
18
+ }
19
+ var taggedCache_default = TaggedCache;
20
+
21
+ // ../../src/core/cache/repository.ts
22
+ class CacheRepository {
23
+ store;
24
+ constructor(store) {
25
+ this.store = store;
26
+ }
27
+ async get(key) {
28
+ return this.store.get(key);
29
+ }
30
+ async remember(key, callback, ttlMs) {
31
+ return this.store.getOrSet(key, callback, ttlMs);
32
+ }
33
+ async forget(key) {
34
+ return this.store.invalidate(key);
35
+ }
36
+ async flush() {
37
+ await this.store.clear();
38
+ }
39
+ tags(...names) {
40
+ return new taggedCache_default(this.store, names);
41
+ }
42
+ async getOrSet(key, loader, ttlMs) {
43
+ return this.remember(key, loader, ttlMs);
44
+ }
45
+ async invalidate(key) {
46
+ return this.forget(key);
47
+ }
48
+ async invalidateByPrefix(prefix) {
49
+ return this.store.invalidateByPrefix(prefix);
50
+ }
51
+ async clear() {
52
+ await this.flush();
53
+ }
54
+ async size() {
55
+ return this.store.size();
56
+ }
57
+ }
58
+ export {
59
+ CacheRepository
60
+ };
@@ -1,4 +1,7 @@
1
1
  // @bun
2
+ // ../../src/core/jobs/dispatchWebhookJob.ts
3
+ import { createHmac } from "crypto";
4
+
2
5
  // ../../src/config/app.ts
3
6
  var appConfig = {
4
7
  name: "WorkHub",
@@ -316,3 +319,65 @@ async function safeFetch(input, init = {}, options = {}) {
316
319
  clearTimeout(timeout);
317
320
  }
318
321
  }
322
+
323
+ // ../../src/core/jobs/dispatchWebhookJob.ts
324
+ class DispatchWebhookJob extends Job {
325
+ maxAttempts = 3;
326
+ backoffMs = 2000;
327
+ async handle(payload) {
328
+ const rows = await repositoryConnection`
329
+ SELECT id, url, secret
330
+ FROM webhook
331
+ WHERE id = ${payload.webhookId} AND active = TRUE
332
+ LIMIT 1
333
+ `;
334
+ const webhook = rows[0];
335
+ if (!webhook) {
336
+ return;
337
+ }
338
+ const body = JSON.stringify({ event: payload.event, payload: payload.payload });
339
+ const signature = createHmac("sha256", webhook.secret).update(body).digest("hex");
340
+ assertSafeOutboundUrl(webhook.url, { allowHttp: appConfig.env !== "production" });
341
+ let responseStatus = null;
342
+ let errorMessage = null;
343
+ try {
344
+ const response = await safeFetch(webhook.url, {
345
+ method: "POST",
346
+ headers: {
347
+ "content-type": "application/json",
348
+ "x-workhub-signature": signature
349
+ },
350
+ body
351
+ }, { allowHttp: appConfig.env !== "production" });
352
+ responseStatus = response.status;
353
+ if (!response.ok) {
354
+ throw new Error(`Webhook delivery failed with status ${response.status}.`);
355
+ }
356
+ } catch (error) {
357
+ errorMessage = error instanceof Error ? error.message : String(error);
358
+ await repositoryConnection`
359
+ INSERT INTO webhook_delivery (webhook_id, event, payload, response_status, error)
360
+ VALUES (
361
+ ${webhook.id},
362
+ ${payload.event},
363
+ ${JSON.stringify(payload.payload)}::jsonb,
364
+ ${responseStatus},
365
+ ${errorMessage}
366
+ )
367
+ `;
368
+ throw error instanceof Error ? error : new Error(errorMessage);
369
+ }
370
+ await repositoryConnection`
371
+ INSERT INTO webhook_delivery (webhook_id, event, payload, response_status)
372
+ VALUES (
373
+ ${webhook.id},
374
+ ${payload.event},
375
+ ${JSON.stringify(payload.payload)}::jsonb,
376
+ ${responseStatus}
377
+ )
378
+ `;
379
+ }
380
+ }
381
+ export {
382
+ DispatchWebhookJob
383
+ };
@@ -24,3 +24,18 @@ class AsyncQueue {
24
24
  function createQueue(driver) {
25
25
  return driver === "async" ? new AsyncQueue : new SyncQueue;
26
26
  }
27
+
28
+ // ../../src/core/jobs/invalidateCacheTagsJob.ts
29
+ class InvalidateCacheTagsJob extends Job {
30
+ cache;
31
+ constructor(cache) {
32
+ super();
33
+ this.cache = cache;
34
+ }
35
+ async handle(payload) {
36
+ await this.cache.tags(...payload.tags).flush();
37
+ }
38
+ }
39
+ export {
40
+ InvalidateCacheTagsJob
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/core",
3
- "version": "0.5.37",
3
+ "version": "0.5.39",
4
4
  "description": "Strata — Laravel-inspired Bun framework public API",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -80,6 +80,11 @@
80
80
  "import": "./dist/entries/auth/sessionCookie.js",
81
81
  "default": "./dist/entries/auth/sessionCookie.js"
82
82
  },
83
+ "./auth/sessionGuard": {
84
+ "types": "./dist/core/auth/sessionGuard.d.ts",
85
+ "import": "./dist/entries/auth/sessionGuard.js",
86
+ "default": "./dist/entries/auth/sessionGuard.js"
87
+ },
83
88
  "./auth/tokenHash": {
84
89
  "types": "./dist/core/auth/tokenHash.d.ts",
85
90
  "import": "./dist/entries/auth/tokenHash.js",
@@ -100,6 +105,11 @@
100
105
  "import": "./dist/entries/cache/createCacheStore.js",
101
106
  "default": "./dist/entries/cache/createCacheStore.js"
102
107
  },
108
+ "./cache/repository": {
109
+ "types": "./dist/core/cache/repository.d.ts",
110
+ "import": "./dist/entries/cache/repository.js",
111
+ "default": "./dist/entries/cache/repository.js"
112
+ },
103
113
  "./config/envSchema": {
104
114
  "types": "./dist/core/config/envSchema.d.ts",
105
115
  "import": "./dist/entries/config/envSchema.js",
@@ -397,7 +407,7 @@
397
407
  "build:bundle": "bun build index.ts --outdir dist --target bun --external bun --external eta",
398
408
  "build:types": "tsc -p tsconfig.types.json",
399
409
  "prepublishOnly": "bun run build && bun ../../scripts/prepare-core-package-publish.ts",
400
- "build:subpaths": "bun build entries/auth/oauth/oidcProvider.ts entries/auth/oauth/providers.ts entries/auth/oauth/samlProvider.ts entries/auth/oauth/types.ts entries/auth/password.ts entries/auth/sessionCookie.ts entries/auth/tokenHash.ts entries/audit/exportAuditLogs.ts entries/cache/tags.ts entries/cache/createCacheStore.ts entries/config/envSchema.ts entries/contracts/serviceTokens.ts entries/contracts/container.ts entries/contracts/di.ts entries/crypto/fieldEncryption.ts entries/crypto/mfaSecret.ts entries/database/factory.ts entries/database/seeders.ts entries/database/types.ts entries/errors/http.ts entries/http/bodySizeLimitMiddleware.ts entries/http/cookies.ts entries/http/csrfProtection.ts entries/http/contentNegotiation.ts entries/http/csrfToken.ts entries/http/etag.ts entries/http/flashSession.ts entries/http/parseFormBody.ts entries/http/resources.ts entries/http/securedRouteModelBinding.ts entries/http/webErrorResponse.ts entries/http/webFormRequest.ts entries/jobs/dispatchWebhookJob.ts entries/jobs/invalidateCacheTagsJob.ts entries/lifecycle/gracefulShutdown.ts entries/logging/logger.ts entries/metrics/prometheus.ts entries/openapi/registeredRoute.ts entries/pagination.ts entries/queue.ts entries/queue/createAppQueue.ts entries/queue/failedJobService.ts entries/queue/jobRunner.ts entries/queue/queueMetrics.ts entries/queue/publicQueue.ts entries/queue/types.ts entries/scheduler/schedule.ts entries/security/oauthState.ts entries/security/publicReads.ts entries/security/safeUrl.ts entries/security/stripeWebhook.ts entries/security/tokenExpiry.ts entries/security/totp.ts entries/storage/storage.ts entries/validation/rules.ts entries/view.ts --outdir dist --root . --target bun --external bun --external eta",
410
+ "build:subpaths": "bun build entries/auth/oauth/oidcProvider.ts entries/auth/oauth/providers.ts entries/auth/oauth/samlProvider.ts entries/auth/oauth/types.ts entries/auth/password.ts entries/auth/sessionCookie.ts entries/auth/sessionGuard.ts entries/auth/tokenHash.ts entries/audit/exportAuditLogs.ts entries/cache/tags.ts entries/cache/createCacheStore.ts entries/cache/repository.ts entries/config/envSchema.ts entries/contracts/serviceTokens.ts entries/contracts/container.ts entries/contracts/di.ts entries/crypto/fieldEncryption.ts entries/crypto/mfaSecret.ts entries/database/factory.ts entries/database/seeders.ts entries/database/types.ts entries/errors/http.ts entries/http/bodySizeLimitMiddleware.ts entries/http/cookies.ts entries/http/csrfProtection.ts entries/http/contentNegotiation.ts entries/http/csrfToken.ts entries/http/etag.ts entries/http/flashSession.ts entries/http/parseFormBody.ts entries/http/resources.ts entries/http/securedRouteModelBinding.ts entries/http/webErrorResponse.ts entries/http/webFormRequest.ts entries/jobs/dispatchWebhookJob.ts entries/jobs/invalidateCacheTagsJob.ts entries/lifecycle/gracefulShutdown.ts entries/logging/logger.ts entries/metrics/prometheus.ts entries/openapi/registeredRoute.ts entries/pagination.ts entries/queue.ts entries/queue/createAppQueue.ts entries/queue/failedJobService.ts entries/queue/jobRunner.ts entries/queue/queueMetrics.ts entries/queue/publicQueue.ts entries/queue/types.ts entries/scheduler/schedule.ts entries/security/oauthState.ts entries/security/publicReads.ts entries/security/safeUrl.ts entries/security/stripeWebhook.ts entries/security/tokenExpiry.ts entries/security/totp.ts entries/storage/storage.ts entries/validation/rules.ts entries/view.ts --outdir dist --root . --target bun --external bun --external eta",
401
411
  "build:shims": "bun ../../scripts/write-core-shared-shims.ts"
402
412
  },
403
413
  "publishConfig": {