better-ship 0.24.0 → 0.26.0

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.
Files changed (85) hide show
  1. package/dist/application-C_xN_1pa.js.map +1 -1
  2. package/dist/application.d.ts +2 -2
  3. package/dist/auth-secondary-storage-b9ptwPSB.d.ts +37 -0
  4. package/dist/auth-secondary-storage-b9ptwPSB.d.ts.map +1 -0
  5. package/dist/better-auth/secondary-storage.d.ts +1 -1
  6. package/dist/bin/notify-ci.d.ts +1 -0
  7. package/dist/bin/notify-ci.js +24 -0
  8. package/dist/bin/notify-ci.js.map +1 -0
  9. package/dist/client-Dv1Ch7yY.js +20 -0
  10. package/dist/client-Dv1Ch7yY.js.map +1 -0
  11. package/dist/cloudflare/auth-secondary-storage.d.ts +2 -36
  12. package/dist/cloudflare/durable-object-client.js +1 -1
  13. package/dist/cloudflare/durable-object-errors.js +2 -47
  14. package/dist/cloudflare/kv-client.js +1 -1
  15. package/dist/cloudflare/kv-errors.js +2 -143
  16. package/dist/cloudflare/queue.d.ts +1 -1
  17. package/dist/cloudflare/r2-client.js +1 -1
  18. package/dist/cloudflare/r2-errors.js +2 -89
  19. package/dist/cloudflare.d.ts +2 -2
  20. package/dist/durable-object-errors-DkMFXQnK.js +48 -0
  21. package/dist/durable-object-errors-DkMFXQnK.js.map +1 -0
  22. package/dist/{index-tNZHSCpJ.d.ts → index-lS_g1olK.d.ts} +17 -2
  23. package/dist/index-lS_g1olK.d.ts.map +1 -0
  24. package/dist/kv-errors-BUTpFy0t.js +144 -0
  25. package/dist/kv-errors-BUTpFy0t.js.map +1 -0
  26. package/dist/metrics-CWv37yf9.js +30 -0
  27. package/dist/metrics-CWv37yf9.js.map +1 -0
  28. package/dist/metrics-cv9P5nvk.d.ts +19 -0
  29. package/dist/metrics-cv9P5nvk.d.ts.map +1 -0
  30. package/dist/{outbox-repository-options-_B8l8l6l.d.ts → outbox-repository-options-15Sv9WnG.d.ts} +2 -2
  31. package/dist/{outbox-repository-options-_B8l8l6l.d.ts.map → outbox-repository-options-15Sv9WnG.d.ts.map} +1 -1
  32. package/dist/payment-service-DUYd3Itt.d.ts +52 -0
  33. package/dist/payment-service-DUYd3Itt.d.ts.map +1 -0
  34. package/dist/payment-service.error-CqF7GkNp.js +30 -0
  35. package/dist/payment-service.error-CqF7GkNp.js.map +1 -0
  36. package/dist/postgres.d.ts +2 -2
  37. package/dist/posthog/metrics.d.ts +2 -18
  38. package/dist/posthog/metrics.js +2 -29
  39. package/dist/posthog/server.d.ts +2 -2
  40. package/dist/posthog/server.js +1 -1
  41. package/dist/r2-errors-rk7n7rvk.js +90 -0
  42. package/dist/r2-errors-rk7n7rvk.js.map +1 -0
  43. package/dist/request-4vJEWxyZ.js +21 -0
  44. package/dist/request-4vJEWxyZ.js.map +1 -0
  45. package/dist/resend.d.ts +6 -1
  46. package/dist/resend.d.ts.map +1 -1
  47. package/dist/resend.js +35 -0
  48. package/dist/resend.js.map +1 -1
  49. package/dist/sentry/server.d.ts +1 -1
  50. package/dist/slack-webhook-j1FCPeu8.js +270 -0
  51. package/dist/slack-webhook-j1FCPeu8.js.map +1 -0
  52. package/dist/slack.d.ts +102 -0
  53. package/dist/slack.d.ts.map +1 -0
  54. package/dist/slack.js +3 -0
  55. package/dist/stripe/client.js +2 -19
  56. package/dist/stripe/payment-service.d.ts +2 -51
  57. package/dist/stripe/payment-service.error.js +2 -29
  58. package/dist/stripe/payment-service.js +1 -1
  59. package/dist/stripe/request.js +2 -20
  60. package/dist/stripe-fixture-yFUknTJO.js +33 -0
  61. package/dist/stripe-fixture-yFUknTJO.js.map +1 -0
  62. package/dist/testing/outbox-repository.d.ts +1 -1
  63. package/dist/testing/payment-service.d.ts +1 -1
  64. package/dist/testing/payment-service.js +2 -2
  65. package/dist/testing/stripe.js +2 -32
  66. package/package.json +6 -1
  67. package/src/application/email-service.ts +17 -0
  68. package/src/application/index.ts +2 -0
  69. package/src/infrastructure/resend/resend-email-service.ts +39 -0
  70. package/src/infrastructure/slack/ci-message.ts +276 -0
  71. package/src/infrastructure/slack/index.ts +10 -0
  72. package/src/infrastructure/slack/notify-ci.ts +22 -0
  73. package/src/infrastructure/slack/slack-webhook.ts +36 -0
  74. package/dist/cloudflare/auth-secondary-storage.d.ts.map +0 -1
  75. package/dist/cloudflare/durable-object-errors.js.map +0 -1
  76. package/dist/cloudflare/kv-errors.js.map +0 -1
  77. package/dist/cloudflare/r2-errors.js.map +0 -1
  78. package/dist/index-tNZHSCpJ.d.ts.map +0 -1
  79. package/dist/posthog/metrics.d.ts.map +0 -1
  80. package/dist/posthog/metrics.js.map +0 -1
  81. package/dist/stripe/client.js.map +0 -1
  82. package/dist/stripe/payment-service.d.ts.map +0 -1
  83. package/dist/stripe/payment-service.error.js.map +0 -1
  84. package/dist/stripe/request.js.map +0 -1
  85. package/dist/testing/stripe.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { W as DomainEvent, et as D1ConstraintKind, nt as DatabaseFailure, q as MessageId, tt as DatabaseError } from "./index-DUFS0SJ_.js";
2
- import { A as IOutboxRepository, M as OutboxClaim, N as OutboxMessage, P as IMessageStore, k as DeadLetterReason, w as ITransaction } from "./index-tNZHSCpJ.js";
3
- import { n as eventCollector, r as DrizzleSchema, t as OutboxRepositoryOptions } from "./outbox-repository-options-_B8l8l6l.js";
2
+ import { A as IOutboxRepository, M as OutboxClaim, N as OutboxMessage, P as IMessageStore, k as DeadLetterReason, w as ITransaction } from "./index-lS_g1olK.js";
3
+ import { n as eventCollector, r as DrizzleSchema, t as OutboxRepositoryOptions } from "./outbox-repository-options-15Sv9WnG.js";
4
4
  import { BatchItem } from "drizzle-orm/batch";
5
5
  import { AnyD1Database, DrizzleD1Database } from "drizzle-orm/d1";
6
6
  //#region src/infrastructure/cloudflare/d1-database-types.d.ts
@@ -0,0 +1,48 @@
1
+ import { _ as isTransientCloudflareRuntimeError, g as isCloudflareRetryableError, h as isCloudflareOverloadedError, nt as AppError, v as isAbortError, y as isTransientTransportError } from "./core-BiN6S_cm.js";
2
+ import { z } from "zod";
3
+
4
+ //#region src/infrastructure/cloudflare/durable-object-errors.ts
5
+ /** Stable tag for a failed Durable Object call. */
6
+ const DURABLE_OBJECT_CALL_ERROR = "DurableObjectCallError";
7
+ const RemoteClassifiedErrorSchema = z.object({
8
+ _tag: z.string(),
9
+ classification: z.enum([
10
+ "transient",
11
+ "terminal",
12
+ "unknown"
13
+ ]),
14
+ remote: z.literal(true)
15
+ });
16
+ const RemoteCallErrorSchema = RemoteClassifiedErrorSchema.extend({
17
+ _tag: z.literal(DURABLE_OBJECT_CALL_ERROR),
18
+ cause: z.unknown()
19
+ });
20
+ /** Recognize a judged local or remote error without admitting its tag to the public error table. */
21
+ function isClassifiedDurableObjectError(cause) {
22
+ return cause instanceof AppError || cause instanceof Error && RemoteClassifiedErrorSchema.safeParse(cause).success;
23
+ }
24
+ /** Classify the error itself. Its cause remains diagnostic evidence, not a second retry decision. */
25
+ function classifyDurableObjectError(cause) {
26
+ if (isAbortError(cause)) return "terminal";
27
+ if (isClassifiedDurableObjectError(cause)) return cause.classification;
28
+ if (isCloudflareOverloadedError(cause)) return "terminal";
29
+ if (isCloudflareRetryableError(cause) || isTransientCloudflareRuntimeError(cause) || isTransientTransportError(cause)) return "transient";
30
+ return "unknown";
31
+ }
32
+ /** Identify a local call error or its validated Workers RPC representation. */
33
+ function isDurableObjectCallError(cause) {
34
+ return cause instanceof DurableObjectCallError || cause instanceof Error && RemoteCallErrorSchema.safeParse(cause).success;
35
+ }
36
+ /** A call failed after retries stopped. Classification does not establish repeat safety. */
37
+ var DurableObjectCallError = class extends AppError {
38
+ _tag = DURABLE_OBJECT_CALL_ERROR;
39
+ classification;
40
+ constructor(args) {
41
+ super("Durable Object call failed", { cause: args.cause });
42
+ this.classification = classifyDurableObjectError(args.cause);
43
+ }
44
+ };
45
+
46
+ //#endregion
47
+ export { isDurableObjectCallError as a, isClassifiedDurableObjectError as i, DurableObjectCallError as n, classifyDurableObjectError as r, DURABLE_OBJECT_CALL_ERROR as t };
48
+ //# sourceMappingURL=durable-object-errors-DkMFXQnK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-object-errors-DkMFXQnK.js","names":[],"sources":["../src/infrastructure/cloudflare/durable-object-errors.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport {\n AppError,\n isAbortError,\n isCloudflareOverloadedError,\n isCloudflareRetryableError,\n isTransientCloudflareRuntimeError,\n isTransientTransportError,\n type FailureClassification,\n} from '@/core'\n\n/** Stable tag for a failed Durable Object call. */\nexport const DURABLE_OBJECT_CALL_ERROR = 'DurableObjectCallError'\n\nconst RemoteClassifiedErrorSchema = z.object({\n _tag: z.string(),\n classification: z.enum(['transient', 'terminal', 'unknown']),\n remote: z.literal(true),\n})\n\nconst RemoteCallErrorSchema = RemoteClassifiedErrorSchema.extend({\n _tag: z.literal(DURABLE_OBJECT_CALL_ERROR),\n cause: z.unknown(),\n})\n\n/** Recognize a judged local or remote error without admitting its tag to the public error table. */\nexport function isClassifiedDurableObjectError(\n cause: unknown,\n): cause is AppError | (Error & z.output<typeof RemoteClassifiedErrorSchema>) {\n return (\n cause instanceof AppError ||\n (cause instanceof Error && RemoteClassifiedErrorSchema.safeParse(cause).success)\n )\n}\n\n/** Classify the error itself. Its cause remains diagnostic evidence, not a second retry decision. */\nexport function classifyDurableObjectError(cause: unknown): FailureClassification {\n if (isAbortError(cause)) return 'terminal'\n if (isClassifiedDurableObjectError(cause)) return cause.classification\n if (isCloudflareOverloadedError(cause)) return 'terminal'\n if (\n isCloudflareRetryableError(cause) ||\n isTransientCloudflareRuntimeError(cause) ||\n isTransientTransportError(cause)\n )\n return 'transient'\n return 'unknown'\n}\n\n/** Identify a local call error or its validated Workers RPC representation. */\nexport function isDurableObjectCallError(\n cause: unknown,\n): cause is DurableObjectCallError | (Error & z.output<typeof RemoteCallErrorSchema>) {\n return (\n cause instanceof DurableObjectCallError ||\n (cause instanceof Error && RemoteCallErrorSchema.safeParse(cause).success)\n )\n}\n\n/** A call failed after retries stopped. Classification does not establish repeat safety. */\nexport class DurableObjectCallError extends AppError {\n readonly _tag = DURABLE_OBJECT_CALL_ERROR\n readonly classification: FailureClassification\n\n constructor(args: { readonly cause: unknown }) {\n super('Durable Object call failed', { cause: args.cause })\n this.classification = classifyDurableObjectError(args.cause)\n }\n}\n"],"mappings":";;;;;AAaA,MAAa,4BAA4B;AAEzC,MAAM,8BAA8B,EAAE,OAAO;CAC3C,MAAM,EAAE,OAAO;CACf,gBAAgB,EAAE,KAAK;EAAC;EAAa;EAAY;CAAS,CAAC;CAC3D,QAAQ,EAAE,QAAQ,IAAI;AACxB,CAAC;AAED,MAAM,wBAAwB,4BAA4B,OAAO;CAC/D,MAAM,EAAE,QAAQ,yBAAyB;CACzC,OAAO,EAAE,QAAQ;AACnB,CAAC;;AAGD,SAAgB,+BACd,OAC4E;CAC5E,OACE,iBAAiB,YAChB,iBAAiB,SAAS,4BAA4B,UAAU,KAAK,CAAC,CAAC;AAE5E;;AAGA,SAAgB,2BAA2B,OAAuC;CAChF,IAAI,aAAa,KAAK,GAAG,OAAO;CAChC,IAAI,+BAA+B,KAAK,GAAG,OAAO,MAAM;CACxD,IAAI,4BAA4B,KAAK,GAAG,OAAO;CAC/C,IACE,2BAA2B,KAAK,KAChC,kCAAkC,KAAK,KACvC,0BAA0B,KAAK,GAE/B,OAAO;CACT,OAAO;AACT;;AAGA,SAAgB,yBACd,OACoF;CACpF,OACE,iBAAiB,0BAChB,iBAAiB,SAAS,sBAAsB,UAAU,KAAK,CAAC,CAAC;AAEtE;;AAGA,IAAa,yBAAb,cAA4C,SAAS;CACnD,AAAS,OAAO;CAChB,AAAS;CAET,YAAY,MAAmC;EAC7C,MAAM,8BAA8B,EAAE,OAAO,KAAK,MAAM,CAAC;EACzD,KAAK,iBAAiB,2BAA2B,KAAK,KAAK;CAC7D;AACF"}
@@ -100,6 +100,21 @@ type OutboundEmail = {
100
100
  type ReceivedEmail = {
101
101
  readonly headers: Readonly<Record<string, string>>;
102
102
  };
103
+ /** One attachment of a received email. `downloadUrl` is a signed link that stops working at `expiresAt`. */
104
+ type ReceivedAttachment = {
105
+ readonly filename: string | null;
106
+ readonly contentType: string;
107
+ readonly size: number;
108
+ readonly downloadUrl: string;
109
+ readonly expiresAt: string;
110
+ };
111
+ /** A received email's sender, plain text body, and attachments, for an application that reads mail it receives. */
112
+ type ReceivedContent = {
113
+ /** The sender as the email states it, for example "Display Name <address@domain.com>". */
114
+ readonly from: string;
115
+ readonly text: string | null;
116
+ readonly attachments: readonly ReceivedAttachment[];
117
+ };
103
118
  /** The provider accepted the email and assigned its id. */
104
119
  type EmailAccepted = {
105
120
  readonly providerId: string;
@@ -395,5 +410,5 @@ declare class UnitOfWorkAlreadyActiveError extends AppError {
395
410
  constructor();
396
411
  }
397
412
  //#endregion
398
- export { CommandHandler as $, IOutboxRepository as A, OutboundEmail as B, UnitOfWorkDeps as C, OutboxRelay as D, IOutboxRelay as E, IEventCollector as F, ObservabilityUser as G, RecordingEmailService as H, EmailAccepted as I, MetricOptions as J, MetricAttributeValue as K, EmailAttachment as L, OutboxClaim as M, OutboxMessage as N, OutboxRelayOptions as O, IMessageStore as P, NULL_ANALYTICS as Q, IEmailService as R, UnitOfWork as S, IOutboxPublisher as T, ObservabilityScope as U, ReceivedEmail as V, ObservabilityService as W, NULL_METRICS_SERVICE as X, MetricsService as Y, AnalyticsService as Z, RecordEmailEventCommand as _, OutboxRetentionResult as a, recordEmailEvent as b, CommandRegistry as c, MessageRegistry as d, EventHandler as et, MessageResult as f, IEmailDeliverabilityStore as g, EmailBounceRecord as h, OutboxRetentionOptions as i, IOutboxRetentionRepository as j, DeadLetterReason as k, EventRegistry as l, RegistryMessage as m, MessageAlreadyProcessedError as n, IMessageBus as o, QueryRegistry as p, MetricAttributes as q, OutboxRetention as r, MessageBus as s, UnitOfWorkAlreadyActiveError as t, QueryHandler as tt, Handlers as u, RecordEmailEventDeps as v, ITransaction as w, IUnitOfWork as x, RecordEmailEventRepos as y, MimeType as z };
399
- //# sourceMappingURL=index-tNZHSCpJ.d.ts.map
413
+ export { AnalyticsService as $, IOutboxRepository as A, OutboundEmail as B, UnitOfWorkDeps as C, OutboxRelay as D, IOutboxRelay as E, IEventCollector as F, ObservabilityScope as G, ReceivedContent as H, EmailAccepted as I, MetricAttributeValue as J, ObservabilityService as K, EmailAttachment as L, OutboxClaim as M, OutboxMessage as N, OutboxRelayOptions as O, IMessageStore as P, NULL_METRICS_SERVICE as Q, IEmailService as R, UnitOfWork as S, IOutboxPublisher as T, ReceivedEmail as U, ReceivedAttachment as V, RecordingEmailService as W, MetricOptions as X, MetricAttributes as Y, MetricsService as Z, RecordEmailEventCommand as _, OutboxRetentionResult as a, recordEmailEvent as b, CommandRegistry as c, MessageRegistry as d, NULL_ANALYTICS as et, MessageResult as f, IEmailDeliverabilityStore as g, EmailBounceRecord as h, OutboxRetentionOptions as i, IOutboxRetentionRepository as j, DeadLetterReason as k, EventRegistry as l, RegistryMessage as m, MessageAlreadyProcessedError as n, EventHandler as nt, IMessageBus as o, QueryRegistry as p, ObservabilityUser as q, OutboxRetention as r, QueryHandler as rt, MessageBus as s, UnitOfWorkAlreadyActiveError as t, CommandHandler as tt, Handlers as u, RecordEmailEventDeps as v, ITransaction as w, IUnitOfWork as x, RecordEmailEventRepos as y, MimeType as z };
414
+ //# sourceMappingURL=index-lS_g1olK.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-lS_g1olK.d.ts","names":[],"sources":["../src/application/handlers.ts","../src/application/analytics-service.ts","../src/application/metrics-service.ts","../src/application/observability-service.ts","../src/application/email-service.ts","../src/application/event-collector.ts","../src/application/message-store.ts","../src/application/outbox-repository.ts","../src/application/outbox-relay.ts","../src/application/transaction.ts","../src/application/unit-of-work.ts","../src/application/record-email-event.ts","../src/application/registry.ts","../src/application/message-bus.ts","../src/application/outbox-retention.ts","../src/application/message-already-processed.error.ts","../src/application/unit-of-work.errors.ts"],"mappings":";;;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vB,OAAO,iBAAiB,gBAAgB,gBAAgB,YAC5D,SAAS,WACR,QAAQ,cAAc,UAAU;UAM3B;UASA;UASA;;;;;;UAWM;;;;;KCpEJ;WACD;WACA;WACA;WACA;WACA;;;KAIC;WACD;WACA;WACA;;;cAIE;mBAIQ;mBAHF;EAEjB,YACmB,YAAY,4BAC7B,UAAS;;EAYL,MAAM,IAAI,OAAO,QAAQ;UAcjB;;;;;cC/CH,qCAAqC;WAKrC,WAAW;WAJb;WACA;EAET,YACW,WAAW,WACpB;aAAqB;;;SAMhB,KAAK,gBAAgB,WAAW,YAAY;;;;;cCZxC,qCAAqC;WACvC;WACA;EAET"}
@@ -0,0 +1,144 @@
1
+ import { g as isCloudflareRetryableError, h as isCloudflareOverloadedError, nt as AppError, y as isTransientTransportError } from "./core-BiN6S_cm.js";
2
+
3
+ //#region src/infrastructure/cloudflare/kv-errors.ts
4
+ /** Extract Typist's verified KV message formats, including nested causes. */
5
+ function extractKVMeta(cause) {
6
+ const message = getDeepErrorMessage(cause);
7
+ if (!message) return void 0;
8
+ const statusMatch = message.match(/\bKV\s+(GET|PUT|DELETE|LIST)\s+failed:\s+(\d{3})\b/);
9
+ const operation = statusMatch?.[1];
10
+ const status = statusMatch ? Number(statusMatch[2]) : void 0;
11
+ if (/Key name cannot be empty/i.test(message)) return {
12
+ kind: "invalid_key",
13
+ message,
14
+ status,
15
+ operation
16
+ };
17
+ if (/exceeds key length limit/i.test(message)) return {
18
+ kind: "key_too_large",
19
+ message,
20
+ status,
21
+ operation
22
+ };
23
+ if (/Invalid expiration_ttl/i.test(message)) return {
24
+ kind: "invalid_expiration_ttl",
25
+ message,
26
+ status,
27
+ operation
28
+ };
29
+ if (/Invalid expiration of/i.test(message)) return {
30
+ kind: "invalid_expiration",
31
+ message,
32
+ status,
33
+ operation
34
+ };
35
+ if (/Invalid cache_ttl/i.test(message)) return {
36
+ kind: "invalid_cache_ttl",
37
+ message,
38
+ status,
39
+ operation
40
+ };
41
+ if (/Invalid key_count_limit/i.test(message)) return {
42
+ kind: "invalid_list_limit",
43
+ message,
44
+ status,
45
+ operation
46
+ };
47
+ if (/value.*(too large|exceeds)|exceeds.*value/i.test(message)) return {
48
+ kind: "value_too_large",
49
+ message,
50
+ status,
51
+ operation
52
+ };
53
+ if (status === 429) return {
54
+ kind: "rate_limited",
55
+ message,
56
+ status,
57
+ operation
58
+ };
59
+ if (status !== void 0 && status >= 500) return {
60
+ kind: "server_error",
61
+ message,
62
+ status,
63
+ operation
64
+ };
65
+ if (status !== void 0 && status >= 400) return {
66
+ kind: "client_error",
67
+ message,
68
+ status,
69
+ operation
70
+ };
71
+ }
72
+ /** Identify recognized KV failures that another attempt cannot resolve. */
73
+ function isTerminalKVError(cause) {
74
+ const meta = extractKVMeta(cause);
75
+ if (!meta) return false;
76
+ if (meta.kind === "rate_limited" || meta.kind === "server_error") return false;
77
+ if (meta.status === 408) return false;
78
+ return true;
79
+ }
80
+ /** Identify a PUT rate limit that requires at least one second before retrying. */
81
+ function isKVPutRateLimitError(cause) {
82
+ const meta = extractKVMeta(cause);
83
+ return meta?.operation === "PUT" && meta.kind === "rate_limited";
84
+ }
85
+ /** Identify PUT rate limits, server failures, and request timeouts. */
86
+ function isTransientKVError(cause) {
87
+ const meta = extractKVMeta(cause);
88
+ if (!meta) return false;
89
+ return isKVPutRateLimitError(cause) || meta.kind === "server_error" || meta.status === 408;
90
+ }
91
+ /** Apply Typist's KV, overload, platform, and transport checks in their original order. */
92
+ function isRetryableKVError(cause) {
93
+ if (isTerminalKVError(cause)) return false;
94
+ if (isTransientKVError(cause)) return true;
95
+ if (isCloudflareOverloadedError(cause)) return false;
96
+ return isCloudflareRetryableError(cause) || isTransientTransportError(cause);
97
+ }
98
+ /** Return the existing retry decision and minimum delay in milliseconds. */
99
+ function decideKVRetry(cause) {
100
+ if (!isRetryableKVError(cause)) return { retry: false };
101
+ return {
102
+ retry: true,
103
+ retryAfterMs: isKVPutRateLimitError(cause) ? 1e3 : 0
104
+ };
105
+ }
106
+ /** A final KV failure with Typist's diagnostics and Better Ship's error classification. */
107
+ var KVError = class extends AppError {
108
+ _tag = "KVError";
109
+ classification;
110
+ retryable;
111
+ operation;
112
+ key;
113
+ cause;
114
+ kv;
115
+ context;
116
+ constructor(args) {
117
+ const kv = extractKVMeta(args.cause);
118
+ const causeMessage = getDeepErrorMessage(args.cause) || String(args.cause);
119
+ const keyContext = args.key === void 0 ? "" : ` for key "${args.key}"`;
120
+ super(`KV ${args.operation} failed${keyContext}: ${causeMessage}`, { cause: args.cause });
121
+ this.operation = args.operation;
122
+ this.key = args.key;
123
+ this.cause = args.cause;
124
+ this.kv = kv;
125
+ this.context = {
126
+ operation: args.operation,
127
+ key: args.key,
128
+ kv
129
+ };
130
+ this.retryable = isRetryableKVError(args.cause);
131
+ this.classification = isTerminalKVError(args.cause) ? "terminal" : this.retryable ? "transient" : "unknown";
132
+ }
133
+ };
134
+ function getDeepErrorMessage(cause) {
135
+ if (typeof cause === "string") return cause;
136
+ if (cause === null || cause === void 0) return "";
137
+ if (typeof cause === "number" || typeof cause === "boolean" || typeof cause === "bigint") return String(cause);
138
+ if (typeof cause !== "object") return "";
139
+ return `${"message" in cause && typeof cause.message === "string" ? cause.message : ""} ${"cause" in cause ? getDeepErrorMessage(cause.cause) : ""}`.trim();
140
+ }
141
+
142
+ //#endregion
143
+ export { isRetryableKVError as a, isKVPutRateLimitError as i, decideKVRetry as n, isTerminalKVError as o, extractKVMeta as r, isTransientKVError as s, KVError as t };
144
+ //# sourceMappingURL=kv-errors-BUTpFy0t.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kv-errors-BUTpFy0t.js","names":[],"sources":["../src/infrastructure/cloudflare/kv-errors.ts"],"sourcesContent":["import {\n AppError,\n isCloudflareOverloadedError,\n isCloudflareRetryableError,\n isTransientTransportError,\n type FailureClassification,\n} from '@/core'\n\n/** KV operations recognized in binding error messages. */\nexport type KVOperation = 'get' | 'put' | 'delete' | 'list'\n\n/** KV failure kinds retained from Typist's binding tests. */\nexport type KVErrorKind =\n | 'invalid_key'\n | 'key_too_large'\n | 'invalid_expiration_ttl'\n | 'invalid_expiration'\n | 'invalid_cache_ttl'\n | 'invalid_list_limit'\n | 'value_too_large'\n | 'client_error'\n | 'rate_limited'\n | 'server_error'\n\n/** Evidence extracted from a KV error and its causes. */\nexport interface KVErrorMeta {\n kind: KVErrorKind\n message: string\n status?: number | undefined\n operation?: Uppercase<KVOperation> | undefined\n}\n\n/** Extract Typist's verified KV message formats, including nested causes. */\nexport function extractKVMeta(cause: unknown): KVErrorMeta | undefined {\n const message = getDeepErrorMessage(cause)\n if (!message) return undefined\n const statusMatch = message.match(/\\bKV\\s+(GET|PUT|DELETE|LIST)\\s+failed:\\s+(\\d{3})\\b/)\n // SAFETY: The regular expression permits only uppercase KV operation names in this capture.\n const operation = statusMatch?.[1] as Uppercase<KVOperation> | undefined\n const status = statusMatch ? Number(statusMatch[2]) : undefined\n\n if (/Key name cannot be empty/i.test(message)) {\n return { kind: 'invalid_key', message, status, operation }\n }\n if (/exceeds key length limit/i.test(message)) {\n return { kind: 'key_too_large', message, status, operation }\n }\n if (/Invalid expiration_ttl/i.test(message)) {\n return { kind: 'invalid_expiration_ttl', message, status, operation }\n }\n if (/Invalid expiration of/i.test(message)) {\n return { kind: 'invalid_expiration', message, status, operation }\n }\n if (/Invalid cache_ttl/i.test(message)) {\n return { kind: 'invalid_cache_ttl', message, status, operation }\n }\n if (/Invalid key_count_limit/i.test(message)) {\n return { kind: 'invalid_list_limit', message, status, operation }\n }\n if (/value.*(too large|exceeds)|exceeds.*value/i.test(message)) {\n return { kind: 'value_too_large', message, status, operation }\n }\n if (status === 429) return { kind: 'rate_limited', message, status, operation }\n if (status !== undefined && status >= 500) {\n return { kind: 'server_error', message, status, operation }\n }\n if (status !== undefined && status >= 400) {\n return { kind: 'client_error', message, status, operation }\n }\n return undefined\n}\n\n/** Identify recognized KV failures that another attempt cannot resolve. */\nexport function isTerminalKVError(cause: unknown): boolean {\n const meta = extractKVMeta(cause)\n if (!meta) return false\n if (meta.kind === 'rate_limited' || meta.kind === 'server_error') return false\n if (meta.status === 408) return false\n return true\n}\n\n/** Identify a PUT rate limit that requires at least one second before retrying. */\nexport function isKVPutRateLimitError(cause: unknown): boolean {\n const meta = extractKVMeta(cause)\n return meta?.operation === 'PUT' && meta.kind === 'rate_limited'\n}\n\n/** Identify PUT rate limits, server failures, and request timeouts. */\nexport function isTransientKVError(cause: unknown): boolean {\n const meta = extractKVMeta(cause)\n if (!meta) return false\n return isKVPutRateLimitError(cause) || meta.kind === 'server_error' || meta.status === 408\n}\n\n/** Apply Typist's KV, overload, platform, and transport checks in their original order. */\nexport function isRetryableKVError(cause: unknown): boolean {\n if (isTerminalKVError(cause)) return false\n if (isTransientKVError(cause)) return true\n if (isCloudflareOverloadedError(cause)) return false\n return isCloudflareRetryableError(cause) || isTransientTransportError(cause)\n}\n\n/** Return the existing retry decision and minimum delay in milliseconds. */\nexport function decideKVRetry(\n cause: unknown,\n): { retry: false } | { retry: true; retryAfterMs: number } {\n if (!isRetryableKVError(cause)) return { retry: false }\n return { retry: true, retryAfterMs: isKVPutRateLimitError(cause) ? 1_000 : 0 }\n}\n\n/** A final KV failure with Typist's diagnostics and Better Ship's error classification. */\nexport class KVError extends AppError {\n readonly _tag = 'KVError'\n readonly classification: FailureClassification\n retryable: boolean\n readonly operation: KVOperation\n readonly key?: string | undefined\n override readonly cause: unknown\n readonly kv?: KVErrorMeta | undefined\n readonly context: {\n operation: KVOperation\n key?: string | undefined\n kv?: KVErrorMeta | undefined\n }\n\n constructor(args: { operation: KVOperation; key?: string | undefined; cause: unknown }) {\n const kv = extractKVMeta(args.cause)\n const causeMessage = getDeepErrorMessage(args.cause) || String(args.cause)\n const keyContext = args.key === undefined ? '' : ` for key \"${args.key}\"`\n super(`KV ${args.operation} failed${keyContext}: ${causeMessage}`, { cause: args.cause })\n this.operation = args.operation\n this.key = args.key\n this.cause = args.cause\n this.kv = kv\n this.context = { operation: args.operation, key: args.key, kv }\n this.retryable = isRetryableKVError(args.cause)\n this.classification = isTerminalKVError(args.cause)\n ? 'terminal'\n : this.retryable\n ? 'transient'\n : 'unknown'\n }\n}\n\n// oxlint-disable anti-slop/no-runtime-typeof -- Preserve Typist's primitive messages and nested causes at the raw binding boundary.\nfunction getDeepErrorMessage(cause: unknown): string {\n if (typeof cause === 'string') return cause\n if (cause === null || cause === undefined) return ''\n if (typeof cause === 'number' || typeof cause === 'boolean' || typeof cause === 'bigint') {\n return String(cause)\n }\n if (typeof cause !== 'object') return ''\n const message = 'message' in cause && typeof cause.message === 'string' ? cause.message : ''\n const causeMessage = 'cause' in cause ? getDeepErrorMessage(cause.cause) : ''\n return `${message} ${causeMessage}`.trim()\n}\n// oxlint-enable anti-slop/no-runtime-typeof\n"],"mappings":";;;;AAiCA,SAAgB,cAAc,OAAyC;CACrE,MAAM,UAAU,oBAAoB,KAAK;CACzC,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,cAAc,QAAQ,MAAM,oDAAoD;CAEtF,MAAM,YAAY,cAAc;CAChC,MAAM,SAAS,cAAc,OAAO,YAAY,EAAE,IAAI;CAEtD,IAAI,4BAA4B,KAAK,OAAO,GAC1C,OAAO;EAAE,MAAM;EAAe;EAAS;EAAQ;CAAU;CAE3D,IAAI,4BAA4B,KAAK,OAAO,GAC1C,OAAO;EAAE,MAAM;EAAiB;EAAS;EAAQ;CAAU;CAE7D,IAAI,0BAA0B,KAAK,OAAO,GACxC,OAAO;EAAE,MAAM;EAA0B;EAAS;EAAQ;CAAU;CAEtE,IAAI,yBAAyB,KAAK,OAAO,GACvC,OAAO;EAAE,MAAM;EAAsB;EAAS;EAAQ;CAAU;CAElE,IAAI,qBAAqB,KAAK,OAAO,GACnC,OAAO;EAAE,MAAM;EAAqB;EAAS;EAAQ;CAAU;CAEjE,IAAI,2BAA2B,KAAK,OAAO,GACzC,OAAO;EAAE,MAAM;EAAsB;EAAS;EAAQ;CAAU;CAElE,IAAI,6CAA6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,AAAS;CACT,AAAkB;CAClB,AAAS;CACT,AAAS;CAMT,YAAY,MAA4E;EACtF,MAAM,KAAK,cAAc,KAAK,KAAK;EACnC,MAAM,eAAe,oBAAoB,KAAK,KAAK,KAAK,OAAO,KAAK,KAAK;EACzE,MAAM,aAAa,KAAK,QAAQ,SAAY,KAAK,aAAa,KAAK,IAAI;EACvE,MAAM,MAAM,KAAK,UAAU,SAAS,WAAW,IAAI,gBAAgB,EAAE,OAAO,KAAK,MAAM,CAAC;EACxF,KAAK,YAAY,KAAK;EACtB,KAAK,MAAM,KAAK;EAChB,KAAK,QAAQ,KAAK;EAClB,KAAK,KAAK;EACV,KAAK,UAAU;GAAE,WAAW,KAAK;GAAW,KAAK,KAAK;GAAK;EAAG;EAC9D,KAAK,YAAY,mBAAmB,KAAK,KAAK;EAC9C,KAAK,iBAAiB,kBAAkB,KAAK,KAAK,IAC9C,aACA,KAAK,YACH,cACA;CACR;AACF;AAGA,SAAS,oBAAoB,OAAwB;CACnD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,UAAU,QAAQ,UAAU,QAAW,OAAO;CAClD,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa,OAAO,UAAU,UAC9E,OAAO,OAAO,KAAK;CAErB,IAAI,OAAO,UAAU,UAAU,OAAO;CAGtC,OAAO,GAFS,aAAa,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,GAExE,GADG,WAAW,QAAQ,oBAAoB,MAAM,KAAK,IAAI,KACvC,KAAK;AAC3C"}
@@ -0,0 +1,30 @@
1
+ //#region src/infrastructure/posthog/metrics.ts
2
+ /** PostHog Metrics with Worker lifetime management, ported from Typist's metrics-service.ts. */
3
+ var PostHogMetricsService = class {
4
+ client;
5
+ waitUntil;
6
+ /** Use the analytics client's metrics; the runtime owns each flush promise. */
7
+ constructor(client, waitUntil) {
8
+ this.client = client;
9
+ this.waitUntil = waitUntil;
10
+ }
11
+ /** Record a total and schedule its flush. */
12
+ count(name, value = 1, options) {
13
+ this.client.metrics.count(name, value, options);
14
+ this.waitUntil(this.client.metrics.flush());
15
+ }
16
+ /** Record a current value and schedule its flush. */
17
+ gauge(name, value, options) {
18
+ this.client.metrics.gauge(name, value, options);
19
+ this.waitUntil(this.client.metrics.flush());
20
+ }
21
+ /** Record an observation and schedule its flush. */
22
+ histogram(name, value, options) {
23
+ this.client.metrics.histogram(name, value, options);
24
+ this.waitUntil(this.client.metrics.flush());
25
+ }
26
+ };
27
+
28
+ //#endregion
29
+ export { PostHogMetricsService as t };
30
+ //# sourceMappingURL=metrics-CWv37yf9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics-CWv37yf9.js","names":[],"sources":["../src/infrastructure/posthog/metrics.ts"],"sourcesContent":["import type { PostHog } from 'posthog-node'\n\nimport type { MetricOptions, MetricsService } from '@/application'\n\n/** PostHog Metrics with Worker lifetime management, ported from Typist's metrics-service.ts. */\nexport class PostHogMetricsService implements MetricsService {\n /** Use the analytics client's metrics; the runtime owns each flush promise. */\n constructor(\n private readonly client: Pick<PostHog, 'metrics'>,\n private readonly waitUntil: (promise: Promise<unknown>) => void,\n ) {}\n\n /** Record a total and schedule its flush. */\n count(name: string, value = 1, options?: MetricOptions): void {\n this.client.metrics.count(name, value, options)\n this.waitUntil(this.client.metrics.flush())\n }\n\n /** Record a current value and schedule its flush. */\n gauge(name: string, value: number, options?: MetricOptions): void {\n this.client.metrics.gauge(name, value, options)\n this.waitUntil(this.client.metrics.flush())\n }\n\n /** Record an observation and schedule its flush. */\n histogram(name: string, value: number, options?: MetricOptions): void {\n this.client.metrics.histogram(name, value, options)\n this.waitUntil(this.client.metrics.flush())\n }\n}\n"],"mappings":";;AAKA,IAAa,wBAAb,MAA6D;CAGxC;CACA;;CAFnB,YACE,AAAiB,QACjB,AAAiB,WACjB;EAFiB;EACA;CAChB;;CAGH,MAAM,MAAc,QAAQ,GAAG,SAA+B;EAC5D,KAAK,OAAO,QAAQ,MAAM,MAAM,OAAO,OAAO;EAC9C,KAAK,UAAU,KAAK,OAAO,QAAQ,MAAM,CAAC;CAC5C;;CAGA,MAAM,MAAc,OAAe,SAA+B;EAChE,KAAK,OAAO,QAAQ,MAAM,MAAM,OAAO,OAAO;EAC9C,KAAK,UAAU,KAAK,OAAO,QAAQ,MAAM,CAAC;CAC5C;;CAGA,UAAU,MAAc,OAAe,SAA+B;EACpE,KAAK,OAAO,QAAQ,UAAU,MAAM,OAAO,OAAO;EAClD,KAAK,UAAU,KAAK,OAAO,QAAQ,MAAM,CAAC;CAC5C;AACF"}
@@ -0,0 +1,19 @@
1
+ import { X as MetricOptions, Z as MetricsService } from "./index-lS_g1olK.js";
2
+ import { PostHog } from "posthog-node";
3
+ //#region src/infrastructure/posthog/metrics.d.ts
4
+ /** PostHog Metrics with Worker lifetime management, ported from Typist's metrics-service.ts. */
5
+ declare class PostHogMetricsService implements MetricsService {
6
+ private readonly client;
7
+ private readonly waitUntil;
8
+ /** Use the analytics client's metrics; the runtime owns each flush promise. */
9
+ constructor(client: Pick<PostHog, 'metrics'>, waitUntil: (promise: Promise<unknown>) => void);
10
+ /** Record a total and schedule its flush. */
11
+ count(name: string, value?: number, options?: MetricOptions): void;
12
+ /** Record a current value and schedule its flush. */
13
+ gauge(name: string, value: number, options?: MetricOptions): void;
14
+ /** Record an observation and schedule its flush. */
15
+ histogram(name: string, value: number, options?: MetricOptions): void;
16
+ }
17
+ //#endregion
18
+ export { PostHogMetricsService as t };
19
+ //# sourceMappingURL=metrics-cv9P5nvk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics-cv9P5nvk.d.ts","names":[],"sources":["../src/infrastructure/posthog/metrics.ts"],"mappings":";;;;cAKa,iCAAiC;mBAGzB;mBACA;;EAFnB,YACmB,QAAQ,KAAK,qBACb,YAAY,SAAS;;EAIxC,MAAM,cAAc,gBAAW,UAAU;;EAMzC,MAAM,cAAc,eAAe,UAAU;;EAM7C,UAAU,cAAc,eAAe,UAAU"}
@@ -1,5 +1,5 @@
1
1
  import "./index-DUFS0SJ_.js";
2
- import { F as IEventCollector } from "./index-tNZHSCpJ.js";
2
+ import { F as IEventCollector } from "./index-lS_g1olK.js";
3
3
  import { BatchItem } from "drizzle-orm/batch";
4
4
  //#region src/infrastructure/drizzle-schema.d.ts
5
5
  /**
@@ -23,4 +23,4 @@ declare const OUTBOX_REPOSITORY_DEFAULTS: {
23
23
  type OutboxRepositoryOptions = Readonly<Partial<typeof OUTBOX_REPOSITORY_DEFAULTS>>;
24
24
  //#endregion
25
25
  export { eventCollector as n, DrizzleSchema as r, OutboxRepositoryOptions as t };
26
- //# sourceMappingURL=outbox-repository-options-_B8l8l6l.d.ts.map
26
+ //# sourceMappingURL=outbox-repository-options-15Sv9WnG.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"outbox-repository-options-_B8l8l6l.d.ts","names":[],"sources":["../src/infrastructure/drizzle-schema.ts","../src/infrastructure/unit-of-work-context.ts","../src/infrastructure/outbox-repository-options.ts"],"mappings":";;;;;;;;KAKY,gBAAgB;;;;cCuBf,gBAAgB;;;;cC3BhB;EACX;EACA;EACA;;;KAIU,0BAA0B,SAAS,eAAe"}
1
+ {"version":3,"file":"outbox-repository-options-15Sv9WnG.d.ts","names":[],"sources":["../src/infrastructure/drizzle-schema.ts","../src/infrastructure/unit-of-work-context.ts","../src/infrastructure/outbox-repository-options.ts"],"mappings":";;;;;;;;KAKY,gBAAgB;;;;cCuBf,gBAAgB;;;;cC3BhB;EACX;EACA;EACA;;;KAIU,0BAA0B,SAAS,eAAe"}
@@ -0,0 +1,52 @@
1
+ import Stripe from "stripe";
2
+ //#region src/infrastructure/stripe/payment-service.d.ts
3
+ /** Supply the same key and parameters when repeating one durable payment attempt. */
4
+ type PaymentRequestOptions = Stripe.RequestOptions & Required<Pick<Stripe.RequestOptions, 'idempotencyKey'>>;
5
+ /** Native Checkout parameters; the service selects payment or setup mode. */
6
+ type CheckoutInput = Omit<Stripe.Checkout.SessionCreateParams, 'mode'>;
7
+ /** A saved customer method; the service confirms the payment off-session. */
8
+ type SavedMethodCharge = Omit<Stripe.PaymentIntentCreateParams, 'confirm' | 'off_session'> & Required<Pick<Stripe.PaymentIntentCreateParams, 'customer' | 'payment_method'>>;
9
+ /** Native customer response, including Stripe request metadata. */
10
+ type CustomerResult = Awaited<ReturnType<Stripe['customers']['create']>>;
11
+ /** Native Checkout response. Its URL can be null; this does not confirm payment. */
12
+ type CheckoutResult = Awaited<ReturnType<Stripe['checkout']['sessions']['create']>>;
13
+ /** Native PaymentIntent response. Applications decide what each status permits. */
14
+ type PaymentResult = Awaited<ReturnType<Stripe['paymentIntents']['create']>>;
15
+ /**
16
+ * Stripe payment operations, with native types and stable keys for mutations.
17
+ * Rejects with PaymentServiceError for Stripe failures; non-Stripe failures propagate unchanged.
18
+ */
19
+ interface IPaymentService {
20
+ /** Create a customer; the application owns persistence and reuse of the customer link. */
21
+ createCustomer(input: Stripe.CustomerCreateParams, options: PaymentRequestOptions): Promise<CustomerResult>;
22
+ /** Create one-time payment checkout; application fulfillment requires verified payment confirmation. */
23
+ createCheckout(input: CheckoutInput, options: PaymentRequestOptions): Promise<CheckoutResult>;
24
+ /** Create checkout in setup mode. The application records consent and verifies the saved method's owner. */
25
+ setupPaymentMethod(input: CheckoutInput, options: PaymentRequestOptions): Promise<CheckoutResult>;
26
+ /** Confirm a saved method off-session. PaymentServiceError retains card errors in cause. */
27
+ chargeSavedMethod(input: SavedMethodCharge, options: PaymentRequestOptions): Promise<PaymentResult>;
28
+ /** Retrieve an existing payment without starting another payment attempt. */
29
+ getPayment(paymentId: string, params?: Stripe.PaymentIntentRetrieveParams, options?: Stripe.RequestOptions): Promise<PaymentResult>;
30
+ }
31
+ /**
32
+ * Ported from Typist's StripeClient request boundary; the native SDK now owns retries.
33
+ * The injected client owns retry and timeout defaults. Native request options can override them.
34
+ */
35
+ declare class StripePaymentService implements IPaymentService {
36
+ private readonly stripe;
37
+ /** Inject a native SDK instance; its transport, credentials, and API version remain caller-owned. */
38
+ constructor(stripe: Stripe);
39
+ /** Create a customer with a stable application key and preserve the native response. */
40
+ createCustomer(input: Stripe.CustomerCreateParams, options: PaymentRequestOptions): Promise<CustomerResult>;
41
+ /** Force payment mode after caller parameters; return the native Checkout Session. */
42
+ createCheckout(input: CheckoutInput, options: PaymentRequestOptions): Promise<CheckoutResult>;
43
+ /** Force setup mode after caller parameters; this operation does not charge the customer. */
44
+ setupPaymentMethod(input: CheckoutInput, options: PaymentRequestOptions): Promise<CheckoutResult>;
45
+ /** Force confirmation and off-session use; retain native card failures in PaymentServiceError.cause. */
46
+ chargeSavedMethod(input: SavedMethodCharge, options: PaymentRequestOptions): Promise<PaymentResult>;
47
+ /** Preserve every native status and response field when reconciling an existing payment. */
48
+ getPayment(paymentId: string, params?: Stripe.PaymentIntentRetrieveParams, options?: Stripe.RequestOptions): Promise<PaymentResult>;
49
+ }
50
+ //#endregion
51
+ export { PaymentRequestOptions as a, StripePaymentService as c, IPaymentService as i, CheckoutResult as n, PaymentResult as o, CustomerResult as r, SavedMethodCharge as s, CheckoutInput as t };
52
+ //# sourceMappingURL=payment-service-DUYd3Itt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-service-DUYd3Itt.d.ts","names":[],"sources":["../src/infrastructure/stripe/payment-service.ts"],"mappings":";;;KAKY,wBAAwB,OAAO,iBACzC,SAAS,KAAK,OAAO;;KAGX,gBAAgB,KAAK,OAAO,SAAS;;KAGrC,oBAAoB,KAAK,OAAO,wDAC1C,SAAS,KAAK,OAAO;;KAGX,iBAAiB,QAAQ,WAAW;;KAGpC,iBAAiB,QAAQ,WAAW;;KAGpC,gBAAgB,QAAQ,WAAW;;;;;UAM9B;;EAEf,eACE,OAAO,OAAO,sBACd,SAAS,wBACR,QAAQ;;EAEX,eAAe,OAAO,eAAe,SAAS,wBAAwB,QAAQ;;EAE9E,mBAAmB,OAAO,eAAe,SAAS,wBAAwB,QAAQ;;EAElF,kBACE,OAAO,mBACP,SAAS,wBACR,QAAQ;;EAEX,WACE,mBACA,SAAS,OAAO,6BAChB,UAAU,OAAO,iBAChB,QAAQ;;;;;;cAOA,gCAAgC;mBAEd;;EAA7B,YAA6B,QAAQ;;EAGrC,eACE,OAAO,OAAO,sBACd,SAAS,wBACR,QAAQ;;EAKX,eAAe,OAAO,eAAe,SAAS,wBAAwB,QAAQ;;EAO9E,mBACE,OAAO,eACP,SAAS,wBACR,QAAQ;;EAOX,kBACE,OAAO,mBACP,SAAS,wBACR,QAAQ;;EAOX,WACE,mBACA,SAAS,OAAO,6BAChB,UAAU,OAAO,iBAChB,QAAQ"}
@@ -0,0 +1,30 @@
1
+ import { nt as AppError } from "./core-BiN6S_cm.js";
2
+ import Stripe from "stripe";
3
+
4
+ //#region src/infrastructure/stripe/payment-service.error.ts
5
+ /** A final Stripe request failure. The caller logs once; native details remain in cause. */
6
+ var PaymentServiceError = class extends AppError {
7
+ operation;
8
+ _tag = "PaymentServiceError";
9
+ classification;
10
+ /** Classify the final SDK error without scheduling another payment attempt. */
11
+ constructor(operation, cause) {
12
+ super(`Stripe request failed: ${operation}`, { cause });
13
+ this.operation = operation;
14
+ this.classification = classifyStripeError(cause);
15
+ }
16
+ };
17
+ function classifyStripeError(error) {
18
+ if (error.headers?.["stripe-should-retry"] === "false") return "terminal";
19
+ const status = error.statusCode;
20
+ if (status !== void 0 && status >= 400 && status < 500 && status !== 409 && status !== 429) return "terminal";
21
+ if (error instanceof Stripe.errors.StripeAuthenticationError || error instanceof Stripe.errors.StripePermissionError || error instanceof Stripe.errors.StripeInvalidRequestError || error instanceof Stripe.errors.StripeIdempotencyError || error instanceof Stripe.errors.StripeCardError) return "terminal";
22
+ if (error.headers?.["stripe-should-retry"] === "true") return "transient";
23
+ if (status === 409 || status === 429 || status !== void 0 && status >= 500) return "transient";
24
+ if (error instanceof Stripe.errors.StripeConnectionError || error instanceof Stripe.errors.StripeAPIError || error instanceof Stripe.errors.StripeRateLimitError) return "transient";
25
+ return "unknown";
26
+ }
27
+
28
+ //#endregion
29
+ export { PaymentServiceError as t };
30
+ //# sourceMappingURL=payment-service.error-CqF7GkNp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-service.error-CqF7GkNp.js","names":[],"sources":["../src/infrastructure/stripe/payment-service.error.ts"],"sourcesContent":["import Stripe from 'stripe'\n\nimport { AppError, type FailureClassification } from '@/core'\n\n/** A final Stripe request failure. The caller logs once; native details remain in cause. */\nexport class PaymentServiceError extends AppError {\n readonly _tag = 'PaymentServiceError'\n readonly classification: FailureClassification\n\n /** Classify the final SDK error without scheduling another payment attempt. */\n constructor(\n readonly operation: string,\n cause: Stripe.errors.StripeError,\n ) {\n super(`Stripe request failed: ${operation}`, { cause })\n this.classification = classifyStripeError(cause)\n }\n}\n\nfunction classifyStripeError(error: Stripe.errors.StripeError): FailureClassification {\n if (error.headers?.['stripe-should-retry'] === 'false') return 'terminal'\n const status = error.statusCode\n if (status !== undefined && status >= 400 && status < 500 && status !== 409 && status !== 429)\n return 'terminal'\n if (\n error instanceof Stripe.errors.StripeAuthenticationError ||\n error instanceof Stripe.errors.StripePermissionError ||\n error instanceof Stripe.errors.StripeInvalidRequestError ||\n error instanceof Stripe.errors.StripeIdempotencyError ||\n error instanceof Stripe.errors.StripeCardError\n )\n return 'terminal'\n if (error.headers?.['stripe-should-retry'] === 'true') return 'transient'\n if (status === 409 || status === 429 || (status !== undefined && status >= 500))\n return 'transient'\n if (\n error instanceof Stripe.errors.StripeConnectionError ||\n error instanceof Stripe.errors.StripeAPIError ||\n error instanceof Stripe.errors.StripeRateLimitError\n )\n return 'transient'\n return 'unknown'\n}\n"],"mappings":";;;;;AAKA,IAAa,sBAAb,cAAyC,SAAS;CAMrC;CALX,AAAS,OAAO;CAChB,AAAS;;CAGT,YACE,AAAS,WACT,OACA;EACA,MAAM,0BAA0B,aAAa,EAAE,MAAM,CAAC;EAH7C;EAIT,KAAK,iBAAiB,oBAAoB,KAAK;CACjD;AACF;AAEA,SAAS,oBAAoB,OAAyD;CACpF,IAAI,MAAM,UAAU,2BAA2B,SAAS,OAAO;CAC/D,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,UAAa,UAAU,OAAO,SAAS,OAAO,WAAW,OAAO,WAAW,KACxF,OAAO;CACT,IACE,iBAAiB,OAAO,OAAO,6BAC/B,iBAAiB,OAAO,OAAO,yBAC/B,iBAAiB,OAAO,OAAO,6BAC/B,iBAAiB,OAAO,OAAO,0BAC/B,iBAAiB,OAAO,OAAO,iBAE/B,OAAO;CACT,IAAI,MAAM,UAAU,2BAA2B,QAAQ,OAAO;CAC9D,IAAI,WAAW,OAAO,WAAW,OAAQ,WAAW,UAAa,UAAU,KACzE,OAAO;CACT,IACE,iBAAiB,OAAO,OAAO,yBAC/B,iBAAiB,OAAO,OAAO,kBAC/B,iBAAiB,OAAO,OAAO,sBAE/B,OAAO;CACT,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
1
  import { W as DomainEvent, nt as DatabaseFailure, q as MessageId, tt as DatabaseError } from "./index-DUFS0SJ_.js";
2
- import { A as IOutboxRepository, M as OutboxClaim, N as OutboxMessage, P as IMessageStore, k as DeadLetterReason, w as ITransaction } from "./index-tNZHSCpJ.js";
3
- import { n as eventCollector, r as DrizzleSchema, t as OutboxRepositoryOptions } from "./outbox-repository-options-_B8l8l6l.js";
2
+ import { A as IOutboxRepository, M as OutboxClaim, N as OutboxMessage, P as IMessageStore, k as DeadLetterReason, w as ITransaction } from "./index-lS_g1olK.js";
3
+ import { n as eventCollector, r as DrizzleSchema, t as OutboxRepositoryOptions } from "./outbox-repository-options-15Sv9WnG.js";
4
4
  import { ExtractTablesWithRelations } from "drizzle-orm";
5
5
  import { PostgresJsDatabase, PostgresJsTransaction, drizzle } from "drizzle-orm/postgres-js";
6
6
  //#region src/infrastructure/postgres/postgres-database-types.d.ts
@@ -1,18 +1,2 @@
1
- import { J as MetricOptions, Y as MetricsService } from "../index-tNZHSCpJ.js";
2
- import { PostHog } from "posthog-node";
3
- //#region src/infrastructure/posthog/metrics.d.ts
4
- /** PostHog Metrics with Worker lifetime management, ported from Typist's metrics-service.ts. */
5
- export declare class PostHogMetricsService implements MetricsService {
6
- private readonly client;
7
- private readonly waitUntil;
8
- /** Use the analytics client's metrics; the runtime owns each flush promise. */
9
- constructor(client: Pick<PostHog, 'metrics'>, waitUntil: (promise: Promise<unknown>) => void);
10
- /** Record a total and schedule its flush. */
11
- count(name: string, value?: number, options?: MetricOptions): void;
12
- /** Record a current value and schedule its flush. */
13
- gauge(name: string, value: number, options?: MetricOptions): void;
14
- /** Record an observation and schedule its flush. */
15
- histogram(name: string, value: number, options?: MetricOptions): void;
16
- }
17
- //#endregion
18
- //# sourceMappingURL=metrics.d.ts.map
1
+ import { t as PostHogMetricsService } from "../metrics-cv9P5nvk.js";
2
+ export { PostHogMetricsService };
@@ -1,30 +1,3 @@
1
- //#region src/infrastructure/posthog/metrics.ts
2
- /** PostHog Metrics with Worker lifetime management, ported from Typist's metrics-service.ts. */
3
- var PostHogMetricsService = class {
4
- client;
5
- waitUntil;
6
- /** Use the analytics client's metrics; the runtime owns each flush promise. */
7
- constructor(client, waitUntil) {
8
- this.client = client;
9
- this.waitUntil = waitUntil;
10
- }
11
- /** Record a total and schedule its flush. */
12
- count(name, value = 1, options) {
13
- this.client.metrics.count(name, value, options);
14
- this.waitUntil(this.client.metrics.flush());
15
- }
16
- /** Record a current value and schedule its flush. */
17
- gauge(name, value, options) {
18
- this.client.metrics.gauge(name, value, options);
19
- this.waitUntil(this.client.metrics.flush());
20
- }
21
- /** Record an observation and schedule its flush. */
22
- histogram(name, value, options) {
23
- this.client.metrics.histogram(name, value, options);
24
- this.waitUntil(this.client.metrics.flush());
25
- }
26
- };
1
+ import { t as PostHogMetricsService } from "../metrics-CWv37yf9.js";
27
2
 
28
- //#endregion
29
- export { PostHogMetricsService };
30
- //# sourceMappingURL=metrics.js.map
3
+ export { PostHogMetricsService };
@@ -1,6 +1,6 @@
1
1
  import { Gt as AnalyticsEventIdentity, Kt as AnalyticsEventInput, qt as AnalyticsProperties } from "../index-DUFS0SJ_.js";
2
- import { Z as AnalyticsService } from "../index-tNZHSCpJ.js";
3
- import { PostHogMetricsService } from "./metrics.js";
2
+ import { $ as AnalyticsService } from "../index-lS_g1olK.js";
3
+ import { t as PostHogMetricsService } from "../metrics-cv9P5nvk.js";
4
4
  import { PostHog, PostHogOptions } from "posthog-node";
5
5
  //#region src/infrastructure/posthog/server.d.ts
6
6
  /** Deployment values and SDK options; the runtime owns delivery promises. */
@@ -1,5 +1,5 @@
1
1
  import { tt as MissingConfigurationError } from "../core-BiN6S_cm.js";
2
- import { PostHogMetricsService } from "./metrics.js";
2
+ import { t as PostHogMetricsService } from "../metrics-CWv37yf9.js";
3
3
  import { PostHog } from "posthog-node";
4
4
 
5
5
  //#region src/infrastructure/posthog/server.ts
@@ -0,0 +1,90 @@
1
+ import { nt as AppError, u as classifyBoundaryError, v as isAbortError } from "./core-BiN6S_cm.js";
2
+ import { z } from "zod";
3
+
4
+ //#region src/infrastructure/cloudflare/r2-errors.ts
5
+ const R2FailureSchema = z.object({
6
+ code: z.number().int().positive(),
7
+ action: z.string().optional()
8
+ });
9
+ const classifications = /* @__PURE__ */ new Map([
10
+ [10001, "transient"],
11
+ [10043, "transient"],
12
+ [10054, "transient"],
13
+ [10058, "transient"],
14
+ [10013, "transient"],
15
+ [10002, "terminal"],
16
+ [10003, "terminal"],
17
+ [10018, "terminal"],
18
+ [10035, "terminal"],
19
+ [10042, "terminal"],
20
+ [10005, "terminal"],
21
+ [10006, "terminal"],
22
+ [10008, "terminal"],
23
+ [10009, "terminal"],
24
+ [10073, "terminal"],
25
+ [10007, "terminal"],
26
+ [10020, "terminal"],
27
+ [100100, "terminal"],
28
+ [10012, "terminal"],
29
+ [10069, "terminal"],
30
+ [10033, "terminal"],
31
+ [10014, "terminal"],
32
+ [10037, "terminal"],
33
+ [10039, "terminal"],
34
+ [10031, "terminal"],
35
+ [10011, "terminal"],
36
+ [10024, "terminal"],
37
+ [10025, "terminal"],
38
+ [10048, "terminal"]
39
+ ]);
40
+ function extractR2Failure(cause) {
41
+ if (!(cause instanceof Error)) return void 0;
42
+ const parsed = R2FailureSchema.safeParse(cause);
43
+ if (parsed.success) return parsed.data;
44
+ const match = /\((\d{5,6})\)\s*$/.exec(cause.message);
45
+ return match?.[1] === void 0 ? void 0 : { code: Number(match[1]) };
46
+ }
47
+ function classifyR2Code(cause) {
48
+ const failure = extractR2Failure(cause);
49
+ return failure === void 0 ? void 0 : classifications.get(failure.code) ?? "unknown";
50
+ }
51
+ function classifyR2Error(cause) {
52
+ if (isAbortError(cause)) return "terminal";
53
+ if (cause instanceof AppError) return cause.classification;
54
+ return classifyBoundaryError({
55
+ cause,
56
+ classifyBoundary: classifyR2Code,
57
+ includeCloudflare: true
58
+ });
59
+ }
60
+ /** A raw binding failure after one attempt. Classification does not establish whether a mutation committed. */
61
+ var R2Error = class extends AppError {
62
+ _tag = "R2Error";
63
+ classification;
64
+ operation;
65
+ r2;
66
+ cause;
67
+ constructor(input) {
68
+ super(`R2 ${input.operation} failed`, { cause: input.cause });
69
+ this.operation = input.operation;
70
+ this.cause = input.cause;
71
+ this.r2 = extractR2Failure(input.cause);
72
+ this.classification = classifyR2Error(input.cause);
73
+ }
74
+ };
75
+ /** JSON serialization or syntax failed. Binding and body-read failures use R2Error. */
76
+ var R2JsonError = class extends AppError {
77
+ _tag = "R2JsonError";
78
+ classification = "terminal";
79
+ operation;
80
+ cause;
81
+ constructor(input) {
82
+ super(`R2 JSON ${input.operation} failed`, { cause: input.cause });
83
+ this.operation = input.operation;
84
+ this.cause = input.cause;
85
+ }
86
+ };
87
+
88
+ //#endregion
89
+ export { R2JsonError as n, R2Error as t };
90
+ //# sourceMappingURL=r2-errors-rk7n7rvk.js.map