@pithy-sh/payments 0.1.5 → 0.2.1

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 (50) hide show
  1. package/dist/capability.d.ts.map +1 -1
  2. package/dist/capability.js +14 -0
  3. package/dist/config/config.d.ts.map +1 -1
  4. package/dist/config/config.js +2 -1
  5. package/dist/entitlement/unimplementedSubject.d.ts +25 -0
  6. package/dist/entitlement/unimplementedSubject.d.ts.map +1 -0
  7. package/dist/entitlement/unimplementedSubject.js +78 -0
  8. package/dist/http/webhookGuard.d.ts +9 -6
  9. package/dist/http/webhookGuard.d.ts.map +1 -1
  10. package/dist/http/webhookGuard.js +44 -8
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -1
  14. package/dist/rails/apple/x509.d.ts.map +1 -1
  15. package/dist/rails/apple/x509.js +6 -0
  16. package/dist/rails/google/oidc.d.ts +5 -1
  17. package/dist/rails/google/oidc.d.ts.map +1 -1
  18. package/dist/rails/google/oidc.js +12 -0
  19. package/dist/rails/paddle/rail.d.ts +10 -1
  20. package/dist/rails/paddle/rail.d.ts.map +1 -1
  21. package/dist/rails/paddle/signature.d.ts +8 -2
  22. package/dist/rails/paddle/signature.d.ts.map +1 -1
  23. package/dist/rails/paddle/signature.js +17 -2
  24. package/dist/rails/stripe/rail.d.ts +11 -1
  25. package/dist/rails/stripe/rail.d.ts.map +1 -1
  26. package/dist/rails/stripe/signature.d.ts +8 -1
  27. package/dist/rails/stripe/signature.d.ts.map +1 -1
  28. package/dist/secret/branches.d.ts +23 -0
  29. package/dist/secret/branches.d.ts.map +1 -0
  30. package/dist/secret/branches.js +27 -0
  31. package/dist/secret/registry.d.ts.map +1 -1
  32. package/dist/secret/registry.js +15 -15
  33. package/dist/version.generated.d.ts +1 -1
  34. package/dist/version.generated.js +1 -1
  35. package/package.json +4 -4
  36. package/pithy.manifest.json +2 -2
  37. package/src/capability.ts +20 -0
  38. package/src/config/config.ts +10 -1
  39. package/src/entitlement/unimplementedSubject.ts +89 -0
  40. package/src/http/webhookGuard.ts +40 -7
  41. package/src/index.ts +8 -0
  42. package/src/rails/apple/x509.ts +18 -0
  43. package/src/rails/google/oidc.ts +28 -1
  44. package/src/rails/paddle/rail.ts +10 -1
  45. package/src/rails/paddle/signature.ts +39 -3
  46. package/src/rails/stripe/rail.ts +11 -1
  47. package/src/rails/stripe/signature.ts +8 -1
  48. package/src/secret/branches.ts +28 -0
  49. package/src/secret/registry.ts +24 -2
  50. package/src/version.generated.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAI3E,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,uBAAuB,EAAuB,MAAM,2BAA2B,CAAC;AAQ9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAK7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG;IAClD;;;;OAIG;IACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C,CAAC;AA4LF,6FAA6F;AAC7F,MAAM,WAAW,kBACf,SAAQ,UAAU,CAAC,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,iBAAiB,CAAC;IAC7F,4BAA4B;IAC5B,cAAc,EAAE,cAAc,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,CAwFrE;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,kBAAkB,CAE7F"}
1
+ {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAI3E,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,uBAAuB,EAAuB,MAAM,2BAA2B,CAAC;AAU9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAK7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG;IAClD;;;;OAIG;IACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C,CAAC;AAsMF,6FAA6F;AAC7F,MAAM,WAAW,kBACf,SAAQ,UAAU,CAAC,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,iBAAiB,CAAC;IAC7F,4BAA4B;IAC5B,cAAc,EAAE,cAAc,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,CAgGrE;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,kBAAkB,CAE7F"}
@@ -3,12 +3,14 @@
3
3
  import { PaymentsConfig } from "./config/config.js";
4
4
  import { paymentsTables } from "./data/tables.js";
5
5
  import { installEntitlementResolver } from "./entitlement/resolver.js";
6
+ import { requireImplementedSubject } from "./entitlement/unimplementedSubject.js";
6
7
  import { paymentsManifestConfig } from "./http/manifestConfig.js";
7
8
  import { paymentsSecretsRegistry } from "./secret/registry.js";
8
9
  import { paymentsWorkflows } from "./workflows/specs.js";
9
10
  import { paymentsAdminRoutes } from "./http/scopes.js";
10
11
  import { registerPaymentsRoutes } from "./http/routes.js";
11
12
  import { payments_0001_purchases } from "./migrations/0001_purchases.js";
13
+ import { paymentsSecretBranches } from "./secret/branches.js";
12
14
  import { paymentsExampleSeed } from "./seeds/example.js";
13
15
  import { PACKAGE_VERSION } from "./version.generated.js";
14
16
  import { defineCapability } from "@pithy-sh/core/src/capability/capability";
@@ -83,6 +85,16 @@ function checkLedgerGrants({ capabilities }, config) {
83
85
  * request that ever works, so there is nothing to lose by refusing to boot, and a Worker that boots into
84
86
  * that state is one whose first symptom is a support ticket from a paying company.
85
87
  */
88
+ /**
89
+ * **An unimplemented resolver is not an absent one, and this check is deliberately blind to the
90
+ * difference.** `pithy add payments --set billingSubject=organization` scaffolds
91
+ * `src/billing/subject.ts` exporting a placeholder branded unimplemented, and passes it here. It is a
92
+ * resolver, so this returns — which it must, because `payments()` runs every time a Worker's
93
+ * `pithy.config.ts` is evaluated and the CLI evaluates it on nearly every command. Refusing the
94
+ * placeholder here would leave the adopter with no `pithy` at all in the project the scaffold just landed
95
+ * in. `requireImplementedSubject`, on the capability's `boot` hook, is where the placeholder is refused —
96
+ * `createEntrypoint` runs it and nothing else does, so the Worker still will not serve (#500).
97
+ */
86
98
  function requireResolvableSubject(config, resolveSubject) {
87
99
  if (config.billingSubject !== "organization" || resolveSubject !== void 0) return;
88
100
  throw new ValidationError({
@@ -200,8 +212,10 @@ function payments(options) {
200
212
  dependsOn: ["secrets"],
201
213
  providesEntitlements: true,
202
214
  secretRegistry: paymentsSecretsRegistry,
215
+ secretBranches: paymentsSecretBranches(resolved.rails),
203
216
  workflows: paymentsWorkflows,
204
217
  compose: (context) => checkLedgerGrants(context, resolved),
218
+ boot: () => requireImplementedSubject(resolveSubject),
205
219
  client: ({ environment }) => clientProjection(resolved, environment),
206
220
  requiredBindings,
207
221
  config: PaymentsConfig,
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAoCjE,eAAO,MAAM,mBAAmB;;;;;;iBA6B+E,CAAC;AAChH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEtE,eAAO,MAAM,mBAAmB;;;;EAI7B,CAAC;AACJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEtE,eAAO,MAAM,oBAAoB;;iBAQyE,CAAC;AAC3G,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,eAAO,MAAM,qBAAqB;;iBAQuE,CAAC;AAC1G,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E,eAAO,MAAM,qBAAqB;;iBAUkE,CAAC;AACrG,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E,eAAO,MAAM,2BAA2B;;iBAUgE,CAAC;AACzG,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEtF,eAAO,MAAM,4BAA4B;;;iBAetC,CAAC;AACJ,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAExF,eAAO,MAA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AAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAalG;AAED,wGAAwG;AACxG,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAGnG;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,MAAM,GACV,oBAAoB,GAAG,SAAS,CAKlC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC,CAIjF;AAED,8GAA8G;AAC9G,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAE5F;AAED,sGAAsG;AACtG,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAE/E"}
@@ -3,6 +3,7 @@
3
3
  import { PAYMENTS_RAILS } from "../data/rail.js";
4
4
  import { PaymentsSubjectType } from "../data/subject.js";
5
5
  import { EntitlementKey } from "@pithy-sh/core/src/entitlement/entitlement";
6
+ import { SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS } from "@pithy-sh/core/src/http/webhookWindow";
6
7
  import { z } from "zod";
7
8
  //#region src/config/config.ts
8
9
  /**
@@ -61,7 +62,7 @@ const PaymentsPaddleSettings = z.strictObject({
61
62
  environment: z.enum(["sandbox", "production"]).describe("Which Paddle account this project sells through. Paddle Billing partitions sandbox from live by account — separate host, separate key, separate notification destinations — so this decides both the API host and every purchase's recorded environment. There is no `mode` field on a Paddle payload that could contradict it."),
62
63
  successUrl: ReturnUrl.describe("Where a buyer lands after paying. Used as `settings.successUrl` for Paddle.js and as the redirect target in `hosted` mode. Build it on `PUBLIC_ORIGIN`, never on a literal."),
63
64
  cancelUrl: ReturnUrl.optional().describe("Where a buyer who backs out lands, in `hosted` mode. Optional, because an overlay a buyer closes leaves them exactly where they were."),
64
- webhookFreshnessSeconds: z.number().int().positive().optional().describe("How many seconds either side of now a delivery's `ts` may be dated. Omitted uses 300, deliberately not the 5 Paddle's own SDKs use: replay protection here is the webhook table's `UNIQUE (rail, providerEventId)`, which is absolute, and a five-second window adds nothing to that while turning ordinary clock skew into a dropped renewal."),
65
+ webhookFreshnessSeconds: z.number().int().positive().optional().describe(`How many seconds either side of now a delivery's \`ts\` may be dated. Omitted uses 300, deliberately not the 5 Paddle's own SDKs use: replay protection here is the webhook table's \`UNIQUE (rail, providerEventId)\`, which is absolute, and a five-second window adds nothing to that while turning ordinary clock skew into a dropped renewal. Bounded at ${SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS} because a freshness window is a replay window: every second of it is a second longer a captured delivery keeps working. That bound is enforced by the verifier rather than by this schema, so a number past it refuses the Paddle webhook route with \`core/internal\` naming this key, instead of refusing to boot the Worker.`),
65
66
  storeCurrency: z.string().regex(CURRENCY_CODE_PATTERN, "A currency code is lowercase, digits, and dashes.").optional().describe("The currency this Paddle catalog prices in, lowercase ISO 4217 — `usd`. Optional, and the only thing it does is let a fixed-amount discount in another currency be refused when it is created rather than when a customer redeems it. Paddle accepts the mismatched object and fails at redemption, so without this the error arrives at the buyer instead of at you.")
66
67
  }).describe("How this project sells through Paddle. `strictObject`, and that is what refuses `portalReturnUrl`: Paddle's customer portal takes no return parameter, so accepting one and dropping it would leave a URL an adopter wrote and believed in that nothing ever reads — a lie in a file they trust.");
67
68
  const PaymentsStripeSettings = z.object({
@@ -0,0 +1,25 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { PaymentsSubjectResolver } from "./subjectSeam";
4
+ /**
5
+ * The scaffolded resolver: branded unimplemented, and a throw if anything ever calls it.
6
+ *
7
+ * A throw rather than `undefined`, and it is belt and braces rather than the mechanism — {@link
8
+ * requireImplementedSubject} means a deployed Worker never gets here. What it covers is every other way
9
+ * this function could be reached: a test composing the capability directly, a tool that assembles a
10
+ * backend without an entrypoint (`pithy ui` reads the composed route tree that way), an adopter who
11
+ * imported the placeholder somewhere of their own. In all of them a loud failure is the right answer and a
12
+ * quiet `undefined` is the failure mode of the stub this replaces.
13
+ */
14
+ export declare const unimplementedSubject: PaymentsSubjectResolver;
15
+ /** Whether this resolver is the scaffolded placeholder rather than something the adopter wrote. */
16
+ export declare function isUnimplementedSubject(resolver: PaymentsSubjectResolver | undefined): boolean;
17
+ /**
18
+ * Refuse a Worker whose subject resolver is still the scaffolded placeholder.
19
+ *
20
+ * Called from the capability's `boot` hook, which `createEntrypoint` runs and nothing else does. The
21
+ * message is the adopter's next action and nothing else: the file is named, the question it has to answer
22
+ * is stated, and the alternative is the other billing mode.
23
+ */
24
+ export declare function requireImplementedSubject(resolver: PaymentsSubjectResolver | undefined): void;
25
+ //# sourceMappingURL=unimplementedSubject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unimplementedSubject.d.ts","sourceRoot":"","sources":["../../src/entitlement/unimplementedSubject.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAwC7D;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,EAAE,uBAWP,CAAC;AAE7B,mGAAmG;AACnG,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,SAAS,GAAG,OAAO,CAE7F;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,SAAS,GAAG,IAAI,CAS7F"}
@@ -0,0 +1,78 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { InternalError, ValidationError } from "@pithy-sh/core/src/error/pithyError";
4
+ //#region src/entitlement/unimplementedSubject.ts
5
+ /**
6
+ * The placeholder `pithy add payments --set billingSubject=organization` scaffolds, and the brand that
7
+ * makes it recognizably unfinished.
8
+ *
9
+ * ## Why a placeholder is safe here and a stub never is
10
+ *
11
+ * A stub is a resolver that *answers*. Returning `undefined` composes cleanly, satisfies every check the
12
+ * capability can make, and then denies every entitlement gate and raises `payments/subject_unresolved` on
13
+ * every write — which is indistinguishable from a customer who has not paid, and whose first symptom is a
14
+ * support ticket from a paying company. That is strictly worse than refusing to write the config at all,
15
+ * and it is why `pithy add` refused `organization` outright for as long as a stub was the only thing it
16
+ * could have written (#483).
17
+ *
18
+ * This answers nothing. It is a **marked absence**: a function carrying {@link UNIMPLEMENTED_SUBJECT},
19
+ * which `payments()` reads at the Worker's entrypoint and refuses to boot on. So the two facts that used
20
+ * to be in tension both hold — the adopter states `organization`, which is what they mean, and the Worker
21
+ * still will not serve a request until somebody has written the resolver (#500).
22
+ *
23
+ * ## Why the check is at the entrypoint and not at composition
24
+ *
25
+ * `payments()` runs whenever a Worker's `pithy.config.ts` is *evaluated*, and the CLI evaluates that
26
+ * module on nearly every command — `loadWorkerConfig` is how `migrate`, `deploy`, `doctor`, `upgrade` and
27
+ * `add` itself learn what a Worker composes. A refusal at composition would therefore brick the whole CLI
28
+ * in the adopter's project the moment the scaffold landed, which is exactly the #483 regression turned
29
+ * inside out. `createEntrypoint` is the one seam the CLI never crosses: only the Worker's own
30
+ * `src/index.ts` calls it. So the composition check stays what it was — an **absent** resolver is refused,
31
+ * unchanged — and the unimplemented one is refused one seam later, where the audience is a request.
32
+ */
33
+ /**
34
+ * The brand. `Symbol.for` rather than a module-local symbol or function identity: a project that ends up
35
+ * with two copies of `@pithy-sh/payments` resolved (a transitive range that did not dedupe) would compare
36
+ * a placeholder from one copy against the marker from the other, and identity would answer no — booting a
37
+ * Worker that denies every gate, which is the one outcome this file exists to prevent. A registered symbol
38
+ * is the same symbol in both copies.
39
+ */
40
+ const UNIMPLEMENTED_SUBJECT = Symbol.for("@pithy-sh/payments/unimplemented-subject");
41
+ /**
42
+ * The scaffolded resolver: branded unimplemented, and a throw if anything ever calls it.
43
+ *
44
+ * A throw rather than `undefined`, and it is belt and braces rather than the mechanism — {@link
45
+ * requireImplementedSubject} means a deployed Worker never gets here. What it covers is every other way
46
+ * this function could be reached: a test composing the capability directly, a tool that assembles a
47
+ * backend without an entrypoint (`pithy ui` reads the composed route tree that way), an adopter who
48
+ * imported the placeholder somewhere of their own. In all of them a loud failure is the right answer and a
49
+ * quiet `undefined` is the failure mode of the stub this replaces.
50
+ */
51
+ const unimplementedSubject = Object.defineProperty(async () => {
52
+ throw new InternalError({
53
+ message: "The subject resolver for this project has not been written.",
54
+ action: "Implement resolveSubject in this Worker's src/billing/subject.ts.",
55
+ detail: "pithy add scaffolded an unimplemented resolveSubject and it is still the one composed. Under billingSubject: \"organization\" only the application can say which organization a caller is acting for."
56
+ });
57
+ }, UNIMPLEMENTED_SUBJECT, { value: true });
58
+ /** Whether this resolver is the scaffolded placeholder rather than something the adopter wrote. */
59
+ function isUnimplementedSubject(resolver) {
60
+ return resolver !== void 0 && resolver[UNIMPLEMENTED_SUBJECT] === true;
61
+ }
62
+ /**
63
+ * Refuse a Worker whose subject resolver is still the scaffolded placeholder.
64
+ *
65
+ * Called from the capability's `boot` hook, which `createEntrypoint` runs and nothing else does. The
66
+ * message is the adopter's next action and nothing else: the file is named, the question it has to answer
67
+ * is stated, and the alternative is the other billing mode.
68
+ */
69
+ function requireImplementedSubject(resolver) {
70
+ if (!isUnimplementedSubject(resolver)) return;
71
+ throw new ValidationError({
72
+ message: "This project bills organizations, and its subject resolver is still the scaffolded placeholder.",
73
+ action: "Implement resolveSubject in this Worker's src/billing/subject.ts, or set `billingSubject: \"user\"` in pithy.config.ts.",
74
+ detail: "pithy add wrote src/billing/subject.ts exporting an unimplemented resolveSubject, and it is unchanged. Payments has no members table and never guesses a holder, so booting on it would deny every entitlement gate and raise payments/subject_unresolved on every write, for every caller, forever."
75
+ });
76
+ }
77
+ //#endregion
78
+ export { isUnimplementedSubject, requireImplementedSubject, unimplementedSubject };
@@ -38,12 +38,15 @@ export interface WebhookGuardOptions {
38
38
  * distinction helps a developer; on a webhook it would only tell a forger how close it got. The original code
39
39
  * rides in `detail`, which the HTTP codec strips.
40
40
  *
41
- * **Two codes pass through unchanged, because they are not the caller's failure.** A rail that cannot reach its
42
- * store (`payments/provider_unavailable`) or cannot use its own credentials (`payments/rail_not_configured`) has
43
- * not judged the delivery at all — Google's rail must call the Play Developer API to resolve a notification, and
44
- * an outage there is ours, not the sender's. Reporting either as a failed signature would send an operator
45
- * hunting for a rotated key while the real answer is in a status page, and would tell the audit trail a forgery
46
- * arrived when none did. Both remain non-2xx, so the provider still redelivers.
41
+ * **{@link PASS_THROUGH_CODES} pass through unchanged, because they are not the caller's failure.** A rail that
42
+ * cannot reach its store (`payments/provider_unavailable`) or cannot use its own credentials
43
+ * (`payments/rail_not_configured`) has not judged the delivery at all — Google's rail must call the Play
44
+ * Developer API to resolve a notification, and an outage there is ours, not the sender's. A rail handed a
45
+ * freshness window that is not a number (`core/internal`) has not judged it either, and that one is our
46
+ * configuration rather than our dependency's weather. Reporting any of them as a failed signature would send an
47
+ * operator hunting for a rotated key while the real answer is in a status page or in one line of
48
+ * `wrangler.jsonc`, and would tell the audit trail a forgery arrived when none did. All remain non-2xx, so the
49
+ * provider still redelivers.
47
50
  */
48
51
  export declare function requireSignedWebhook(rail: PaymentsRail, options: WebhookGuardOptions): MiddlewareHandler<PithyHonoEnv>;
49
52
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"webhookGuard.d.ts","sourceRoot":"","sources":["../../src/http/webhookGuard.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAM7E,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,c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;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAenH"}
@@ -68,8 +68,41 @@ import { sharedSecretsStore } from "@pithy-sh/secrets/src/sharedSecretsStore";
68
68
  function failingStep(cause) {
69
69
  return cause instanceof PithyError ? cause.payload.code : "unknown";
70
70
  }
71
- /** The codes a rail may raise that describe our side rather than the sender's, and so keep their own status. */
72
- const PASS_THROUGH_CODES = /* @__PURE__ */ new Set(["payments/provider_unavailable", "payments/rail_not_configured"]);
71
+ /**
72
+ * The codes a rail may raise that describe our side rather than the sender's, and so keep their own status.
73
+ *
74
+ * **Membership is decided by whose fault the code names, not by its status.** `payments/rail_not_configured`
75
+ * is a 404 and `core/internal` is a 500; what they share is that neither is a statement about the caller, so
76
+ * re-coding either as `payments/webhook_unverified` would be a lie in the one direction that costs the most —
77
+ * it names a culprit, and the culprit is us.
78
+ *
79
+ * The three `core/*` members are what #521 added, and they are the reason this set exists as a set. The
80
+ * signed-webhook verifiers now refuse a freshness window that is not a window — a `NaN` from
81
+ * `Number(env.STRIPE_WEBHOOK_TOLERANCE)` on a variable nobody set — as `core/internal`, because a comparison
82
+ * against `NaN` deletes the replay window rather than widening it. Caught here and re-rendered as a 401, that
83
+ * refusal arrived at the operator as *"check the webhook signing secret"*: it blamed the sender for our
84
+ * configuration, sent whoever was debugging to the one place the answer is not, and wrote an audit row saying
85
+ * a forgery had arrived when none had. CLAUDE.md §Errors gives a 500-class code exactly one job — *read **our**
86
+ * logs* — and laundering it into a 401 destroys that job entirely.
87
+ *
88
+ * `core/upstream_failed` and `core/upstream_timeout` ride along for the same reason `payments/provider_unavailable`
89
+ * already does: they are the shared-client spelling of a hop into something we do not control, and
90
+ * `workflows/retryPolicy.ts` already classifies the three together. Nothing on the verification path raises
91
+ * them today; the set is the place that would have to be edited if one ever did, and forgetting is what this
92
+ * comment exists to prevent.
93
+ *
94
+ * **The client boundary is untouched by any of this.** Every one of these still leaves through `clientError`,
95
+ * which strips `action` and `detail` — so the sender learns a status and a bland `message`, and the knob's
96
+ * name reaches the terminal, the `--json` line and the log alone. What changed is that the operator's surface
97
+ * and the status code stop saying *bad signature* when the truth is *this endpoint is misconfigured*.
98
+ */
99
+ const PASS_THROUGH_CODES = /* @__PURE__ */ new Set([
100
+ "payments/provider_unavailable",
101
+ "payments/rail_not_configured",
102
+ "core/internal",
103
+ "core/upstream_failed",
104
+ "core/upstream_timeout"
105
+ ]);
73
106
  /**
74
107
  * Request-scoped, keyed on the `Request` object so an entry cannot outlive its request and cannot be reached
75
108
  * from another one. Weak, so a dropped request drops its entry with no bookkeeping.
@@ -102,12 +135,15 @@ function database(c) {
102
135
  * distinction helps a developer; on a webhook it would only tell a forger how close it got. The original code
103
136
  * rides in `detail`, which the HTTP codec strips.
104
137
  *
105
- * **Two codes pass through unchanged, because they are not the caller's failure.** A rail that cannot reach its
106
- * store (`payments/provider_unavailable`) or cannot use its own credentials (`payments/rail_not_configured`) has
107
- * not judged the delivery at all — Google's rail must call the Play Developer API to resolve a notification, and
108
- * an outage there is ours, not the sender's. Reporting either as a failed signature would send an operator
109
- * hunting for a rotated key while the real answer is in a status page, and would tell the audit trail a forgery
110
- * arrived when none did. Both remain non-2xx, so the provider still redelivers.
138
+ * **{@link PASS_THROUGH_CODES} pass through unchanged, because they are not the caller's failure.** A rail that
139
+ * cannot reach its store (`payments/provider_unavailable`) or cannot use its own credentials
140
+ * (`payments/rail_not_configured`) has not judged the delivery at all — Google's rail must call the Play
141
+ * Developer API to resolve a notification, and an outage there is ours, not the sender's. A rail handed a
142
+ * freshness window that is not a number (`core/internal`) has not judged it either, and that one is our
143
+ * configuration rather than our dependency's weather. Reporting any of them as a failed signature would send an
144
+ * operator hunting for a rotated key while the real answer is in a status page or in one line of
145
+ * `wrangler.jsonc`, and would tell the audit trail a forgery arrived when none did. All remain non-2xx, so the
146
+ * provider still redelivers.
111
147
  */
112
148
  function requireSignedWebhook(rail, options) {
113
149
  return async (c, next) => {
package/dist/index.d.ts CHANGED
@@ -35,6 +35,7 @@ export { PaymentsWebhookEvent, WEBHOOK_EVENT_ORPHANED, webhookEventAwaitsOwner }
35
35
  export { grantEntitlement, type ManualEntitlementInput, type ManualEntitlementOptions, revokeEntitlement, } from "./entitlement/manual";
36
36
  export { createPaymentsEntitlementResolver, installEntitlementResolver, PAYMENTS_ENTITLEMENT_PROVIDER, } from "./entitlement/resolver";
37
37
  export { authenticatedUserSubject, type PaymentsSubjectResolver, type PaymentsSubjectSeam, requirePaymentsSubject, resolvePaymentsSubject, } from "./entitlement/subjectSeam";
38
+ export { isUnimplementedSubject, requireImplementedSubject, unimplementedSubject, } from "./entitlement/unimplementedSubject";
38
39
  export { type AppliedGrant, applyGrants, type FulfillmentReport, type FulfillPurchaseOptions, fulfillPurchase, type GrantOptions, grantRef, ledgerGrantFor, purchaseIsPaid, } from "./grants/apply";
39
40
  export { type ClawbackOutcome, clawbackGrants, clawbackRef } from "./grants/clawback";
40
41
  export { type OpenPaymentsLedgerOptions, openPaymentsLedger, type PaymentsLedger, type PaymentsLedgerLoader, } from "./grants/ledgerSeam";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,KA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BAAqB,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,EACL,kBAAkB,EAClB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iCAAiC,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,uBAAuB,EACvB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EACL,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,EAC3B,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ import { PAYMENTS_ENTITLEMENTS_TABLE, PAYMENTS_PROVIDER_ACCOUNTS_TABLE, PAYMENTS
13
13
  import { resolveEntitlements } from "./projection/resolve.js";
14
14
  import { authenticatedUserSubject, requirePaymentsSubject, resolvePaymentsSubject } from "./entitlement/subjectSeam.js";
15
15
  import { PAYMENTS_ENTITLEMENT_PROVIDER, createPaymentsEntitlementResolver, installEntitlementResolver } from "./entitlement/resolver.js";
16
+ import { isUnimplementedSubject, requireImplementedSubject, unimplementedSubject } from "./entitlement/unimplementedSubject.js";
16
17
  import { PaymentsAuditActions } from "./audit/actions.js";
17
18
  import { grantEntitlement, revokeEntitlement } from "./entitlement/manual.js";
18
19
  import { openPaymentsLedger } from "./grants/ledgerSeam.js";
@@ -42,4 +43,4 @@ import { PAYMENTS_RECONCILE_KEY, triggerPaymentsReconcile } from "./http/dispatc
42
43
  import { paymentsWorkerName, resolvePaymentsConfig } from "./provision/resolvePaymentsConfig.js";
43
44
  import { batchedRailAccess } from "./workflows/railAccess.js";
44
45
  import { reconcilePayments } from "./workflows/reconcile.js";
45
- export { ACCESS_GRANTING_STATUSES, APPLE_API_AUDIENCE, APPLE_API_BASES, APPLE_ROOT_CERTIFICATES, AppleSubscriptionStatuses, AppleWebhookNotification, CheckoutRequest, DEFAULT_EXPIRING_WITHIN_SECONDS, DEFAULT_STALE_AFTER_SECONDS, EntitlementGrantRequest, EntitlementRevokeRequest, GOOGLE_JWKS_URL, GOOGLE_OIDC_ISSUERS, GoogleJwk, GoogleJwks, GoogleWebhookNotification, ORPHAN_REPAIR_LIMIT, PAYMENTS_CAPABILITY, PAYMENTS_CATALOG_READ_SCOPE, PAYMENTS_CONTROL_PLANE_SCOPES, PAYMENTS_ENTITLEMENTS_TABLE, PAYMENTS_ENTITLEMENT_GRANT_SCOPE, PAYMENTS_ENTITLEMENT_PROVIDER, PAYMENTS_ENTITLEMENT_REVOKE_SCOPE, PAYMENTS_MIGRATION_ORDER, PAYMENTS_PROVIDER_ACCOUNTS_TABLE, PAYMENTS_PROVIDER_SECRET, PAYMENTS_PURCHASES_TABLE, PAYMENTS_RAILS, PAYMENTS_RECONCILE_KEY, PAYMENTS_RECONCILE_RUNS_TABLE, PAYMENTS_WEBHOOK_EVENTS_TABLE, PaymentsAppleCredentials, PaymentsAppleProduct, PaymentsAuditActions, PaymentsConfig, PaymentsEntitlement, PaymentsGoogleCredentials, PaymentsGoogleProduct, PaymentsGrants, PaymentsLedgerGrant, PaymentsLemonSqueezyProduct, PaymentsLemonSqueezySettings, PaymentsPaddleProduct, PaymentsPaddleSettings, PaymentsProduct, PaymentsProductType, PaymentsProviderAccount, PaymentsProviderCredentials, PaymentsPurchase, PaymentsRail, PaymentsRailToggles, PaymentsReconcileParams, PaymentsReconcileRun, PaymentsStripeCredentials, PaymentsStripeProduct, PaymentsStripeSettings, PaymentsSubject, PaymentsSubjectType, PaymentsWebhookEvent, ProviderEvent, PurchaseEnvironment, PurchaseStatus, PurchaseSubmission, RECONCILE_RUN_RETENTION_DAYS, RestoreRequest, STRIPE_API_VERSION, STRIPE_METADATA_ACCOUNT_REFERENCE, STRIPE_METADATA_PRICE, StripeWebhookNotification, WEBHOOK_EVENT_ORPHANED, appleSubscriptionStatus, applyGrants, authenticatedUserSubject, batchedRailAccess, clawbackGrants, clawbackRef, createPaymentsEntitlementResolver, decodeSubjectReference, encodeSubjectReference, entitlementsForProduct, fulfillPurchase, grantEntitlement, grantRef, grantableEntitlements, grantingStatuses, implementedRails, installEntitlementResolver, isCheckoutRail, isPaymentsCapability, ledgerGrantFor, linkProviderAccount, minorUnitDigits, minorUnitsFromScaled, mintAppleApiToken, noteIsRepairable, noteText, openPaymentsLedger, payments, paymentsDatabase, paymentsExampleSeed, paymentsSecretsRegistry, paymentsTables, paymentsWorkerName, paymentsWorkflowRegistry, paymentsWorkflows, productForProviderSku, projectPurchase, providerAccountForSubject, providerProductId, purchaseIsPaid, railCredentials, railEnabled, reconcilePayments, recordReconcileRun, registerPaymentsRoutes, repairOrphanedEvents, requireAuth, requirePaymentsSubject, resolveEntitlements, resolveNotificationOwner, resolvePaymentsConfig, resolvePaymentsSubject, resolveProduct, resolveRailProvider, revokeEntitlement, sameSubject, statusGrantsAccess, triggerPaymentsReconcile, webhookEventAwaitsOwner };
46
+ export { ACCESS_GRANTING_STATUSES, APPLE_API_AUDIENCE, APPLE_API_BASES, APPLE_ROOT_CERTIFICATES, AppleSubscriptionStatuses, AppleWebhookNotification, CheckoutRequest, DEFAULT_EXPIRING_WITHIN_SECONDS, DEFAULT_STALE_AFTER_SECONDS, EntitlementGrantRequest, EntitlementRevokeRequest, GOOGLE_JWKS_URL, GOOGLE_OIDC_ISSUERS, GoogleJwk, GoogleJwks, GoogleWebhookNotification, ORPHAN_REPAIR_LIMIT, PAYMENTS_CAPABILITY, PAYMENTS_CATALOG_READ_SCOPE, PAYMENTS_CONTROL_PLANE_SCOPES, PAYMENTS_ENTITLEMENTS_TABLE, PAYMENTS_ENTITLEMENT_GRANT_SCOPE, PAYMENTS_ENTITLEMENT_PROVIDER, PAYMENTS_ENTITLEMENT_REVOKE_SCOPE, PAYMENTS_MIGRATION_ORDER, PAYMENTS_PROVIDER_ACCOUNTS_TABLE, PAYMENTS_PROVIDER_SECRET, PAYMENTS_PURCHASES_TABLE, PAYMENTS_RAILS, PAYMENTS_RECONCILE_KEY, PAYMENTS_RECONCILE_RUNS_TABLE, PAYMENTS_WEBHOOK_EVENTS_TABLE, PaymentsAppleCredentials, PaymentsAppleProduct, PaymentsAuditActions, PaymentsConfig, PaymentsEntitlement, PaymentsGoogleCredentials, PaymentsGoogleProduct, PaymentsGrants, PaymentsLedgerGrant, PaymentsLemonSqueezyProduct, PaymentsLemonSqueezySettings, PaymentsPaddleProduct, PaymentsPaddleSettings, PaymentsProduct, PaymentsProductType, PaymentsProviderAccount, PaymentsProviderCredentials, PaymentsPurchase, PaymentsRail, PaymentsRailToggles, PaymentsReconcileParams, PaymentsReconcileRun, PaymentsStripeCredentials, PaymentsStripeProduct, PaymentsStripeSettings, PaymentsSubject, PaymentsSubjectType, PaymentsWebhookEvent, ProviderEvent, PurchaseEnvironment, PurchaseStatus, PurchaseSubmission, RECONCILE_RUN_RETENTION_DAYS, RestoreRequest, STRIPE_API_VERSION, STRIPE_METADATA_ACCOUNT_REFERENCE, STRIPE_METADATA_PRICE, StripeWebhookNotification, WEBHOOK_EVENT_ORPHANED, appleSubscriptionStatus, applyGrants, authenticatedUserSubject, batchedRailAccess, clawbackGrants, clawbackRef, createPaymentsEntitlementResolver, decodeSubjectReference, encodeSubjectReference, entitlementsForProduct, fulfillPurchase, grantEntitlement, grantRef, grantableEntitlements, grantingStatuses, implementedRails, installEntitlementResolver, isCheckoutRail, isPaymentsCapability, isUnimplementedSubject, ledgerGrantFor, linkProviderAccount, minorUnitDigits, minorUnitsFromScaled, mintAppleApiToken, noteIsRepairable, noteText, openPaymentsLedger, payments, paymentsDatabase, paymentsExampleSeed, paymentsSecretsRegistry, paymentsTables, paymentsWorkerName, paymentsWorkflowRegistry, paymentsWorkflows, productForProviderSku, projectPurchase, providerAccountForSubject, providerProductId, purchaseIsPaid, railCredentials, railEnabled, reconcilePayments, recordReconcileRun, registerPaymentsRoutes, repairOrphanedEvents, requireAuth, requireImplementedSubject, requirePaymentsSubject, resolveEntitlements, resolveNotificationOwner, resolvePaymentsConfig, resolvePaymentsSubject, resolveProduct, resolveRailProvider, revokeEntitlement, sameSubject, statusGrantsAccess, triggerPaymentsReconcile, unimplementedSubject, webhookEventAwaitsOwner };
@@ -1 +1 @@
1
- {"version":3,"file":"x509.d.ts","sourceRoot":"","sources":["../../../src/rails/apple/x509.ts"],"names":[],"mappings":"AAqFA;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,2BAA2B,6BAA6B,CAAC;AAStE,kFAAkF;AAClF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,4GAA4G;AAC5G,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sFAAsF;AACtF,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,GAAG,EAAE,UAAU,CAAC;IAChB,sGAAsG;IACtG,GAAG,EAAE,UAAU,CAAC;IAChB,gGAAgG;IAChG,MAAM,EAAE,UAAU,CAAC;IACnB,8BAA8B;IAC9B,OAAO,EAAE,UAAU,CAAC;IACpB,0CAA0C;IAC1C,SAAS,EAAE,IAAI,CAAC;IAChB,iCAAiC;IACjC,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sG;IACtG,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC;AA6FD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,iBAAiB,CAuCnE;AAiCD;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA8FvB"}
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  import { PaymentsInvalidReceiptError, PaymentsVerificationFailedError } from "../../error/errors.js";
4
4
  import { asn1Children, bytesEqual, decodeBase64, derSignatureToRaw, readAsn1, readBits, readBoolean, readInteger, readOid } from "./der.js";
5
+ import { InternalError } from "@pithy-sh/core/src/error/pithyError";
5
6
  //#region src/rails/apple/x509.ts
6
7
  /**
7
8
  * X.509 certificates, and the chain check that makes an Apple signature mean something.
@@ -234,6 +235,11 @@ async function verifyCertificateChain(chain, options) {
234
235
  if (chain.length > MAX_CHAIN_LENGTH) throw rejected(`X.509: a chain of ${chain.length} is longer than the ${MAX_CHAIN_LENGTH} accepted.`);
235
236
  const certificates = chain.map((der) => parseCertificate(der));
236
237
  const at = options.now.getTime();
238
+ if (!Number.isFinite(at)) throw new InternalError({
239
+ message: "That purchase could not be verified.",
240
+ action: "Give the Apple rail a valid clock.",
241
+ detail: "X.509: chain verification was handed a clock that is not a valid Date, so no certificate's validity window can be judged."
242
+ });
237
243
  for (const [index, certificate] of certificates.entries()) if (at < certificate.notBefore.getTime() || at > certificate.notAfter.getTime()) throw rejected(`X.509: certificate ${index} is valid ${certificate.notBefore.toISOString()}–${certificate.notAfter.toISOString()}.`);
238
244
  const root = certificates[certificates.length - 1];
239
245
  if (!options.roots.some((encoded) => bytesEqual(decodeBase64(encoded), root.der))) throw rejected("X.509: the chain's root is not one of the pinned roots.");
@@ -97,7 +97,11 @@ export interface VerifyGoogleOidcOptions {
97
97
  * is exercised for real, and a local Pub/Sub emulator, whose tokens are signed by a key Google never saw.
98
98
  */
99
99
  trustedKeys?: readonly GoogleJwk[];
100
- /** Tolerance on `exp` and `iat`, in seconds. Defaults to a minute. */
100
+ /**
101
+ * Tolerance on `exp` and `iat`, in seconds. Defaults to a minute, and must be a finite number from 0 to
102
+ * {@link OIDC_MAX_CLOCK_SKEW_SECONDS}; anything else is `core/internal`, because this is the second operand
103
+ * of both freshness comparisons and one `NaN` turns the pair into no-ops together.
104
+ */
101
105
  clockSkewSeconds?: number;
102
106
  }
103
107
  /** Drop the cached key set. For tests, which must not inherit another suite's keys. */
@@ -1 +1 @@
1
- {"version":3,"file":"oidc.d.ts","sourceRoot":"","sources":["../../../src/rails/google/oidc.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,eAAe,EAA+B,MAAM,QAAQ,CAAC;AAG3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,gHAAgH;AAChH,eAAO,MAAM,eAAe,+CAA+C,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAA2D,CAAC;AA+B7G;;;GAGG;AACH,eAAO,MAAM,SAAS;;;;;;;iBAU0C,CAAC;AACjE,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAElD,gHAAgH;AAChH,eAAO,MAAM,UAAU;;;;;;;;;iBAKmC,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;iBAuBwE,CAAC;AACtG,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,6GAA6G;AAC7G,MAAM,WAAW,uBAAuB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BAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,6GAA6G;AAC7G,MAAM,WAAW,uBAAuB;IACtC,0GAA0G;IAC1G,QAAQ,EAAE,MAAM,CAAC;IACjB,qGAAqG;IACrG,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iEAAiE;IACjE,GAAG,EAAE,IAAI,CAAC;IACV,iGAAiG;IACjG,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACnC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAWD,uFAAuF;AACvF,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AA6DD;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CA8E3B"}
@@ -3,7 +3,9 @@
3
3
  import { PaymentsInvalidReceiptError, PaymentsVerificationFailedError } from "../../error/errors.js";
4
4
  import { googleHttpFetch, googleJson } from "./http.js";
5
5
  import { base64UrlDecode, decodeJwtJson, splitJwt } from "./jwt.js";
6
+ import { InternalError } from "@pithy-sh/core/src/error/pithyError";
6
7
  import { z } from "zod";
8
+ import { OIDC_MAX_CLOCK_SKEW_SECONDS } from "@pithy-sh/core/src/http/oidcWebhook";
7
9
  //#region src/rails/google/oidc.ts
8
10
  /**
9
11
  * The authenticity boundary on Google's webhook: the OIDC token a Pub/Sub push carries.
@@ -160,7 +162,17 @@ async function verifyGoogleOidcToken(token, options) {
160
162
  if (!parsed.success) throw new PaymentsVerificationFailedError({ detail: `Google: the token claims are not those of a Pub/Sub push token — ${issues(parsed.error)}.` });
161
163
  const claims = parsed.data;
162
164
  const skew = options.clockSkewSeconds ?? DEFAULT_CLOCK_SKEW_SECONDS;
165
+ if (!Number.isFinite(skew) || skew < 0 || skew > OIDC_MAX_CLOCK_SKEW_SECONDS) throw new InternalError({
166
+ message: "This webhook endpoint is not configured.",
167
+ action: `Give the Google Pub/Sub webhook a clock skew between 0 and ${OIDC_MAX_CLOCK_SKEW_SECONDS} seconds.`,
168
+ detail: `Google: the push-token check was given a clock skew of ${String(skew)} seconds, and a tolerance must be a number from 0 to ${OIDC_MAX_CLOCK_SKEW_SECONDS}.`
169
+ });
163
170
  const seconds = Math.floor(options.now.getTime() / 1e3);
171
+ if (!Number.isFinite(seconds)) throw new InternalError({
172
+ message: "This webhook endpoint is not configured.",
173
+ action: "Give the Google Pub/Sub webhook a valid clock.",
174
+ detail: "Google: the push-token check was handed a clock that is not a valid Date, so no token's freshness can be judged."
175
+ });
164
176
  if (!GOOGLE_OIDC_ISSUERS.includes(claims.iss)) throw failed(`the token issuer is "${claims.iss}", not one of Google's.`);
165
177
  if (claims.aud !== options.audience) throw failed(`the token audience is "${claims.aud}", and this endpoint expects "${options.audience}".`);
166
178
  if (claims.exp + skew < seconds) throw failed(`the token expired at ${(/* @__PURE__ */ new Date(claims.exp * 1e3)).toISOString()}.`);
@@ -40,7 +40,16 @@ export interface PaddleRailOptions {
40
40
  clientToken: string;
41
41
  /** Whether checkout opens as an overlay, inline, or on Paddle's own hosted page. */
42
42
  checkout: "overlay" | "inline" | "hosted";
43
- /** How many seconds either side of now a delivery may be dated. Undefined uses the rail's 300. */
43
+ /**
44
+ * How many seconds either side of now a delivery may be dated. Undefined uses the rail's 300.
45
+ *
46
+ * Threaded down unchanged through `webhook.ts` and validated in one place, `signature.ts`, where the
47
+ * comparison is — a non-finite, negative, or over-wide window is `core/internal` there, refused before any
48
+ * delivery is judged. The layers between only apply defaults with `??`, which catches `undefined` and never
49
+ * `NaN`; one place that refuses beats three that each half-check. `paddle.webhookFreshnessSeconds` reaches
50
+ * this field and is deliberately **not** bounded again in `PaymentsPaddleSettings`: that schema parses at
51
+ * module scope, so a bound there refuses the whole Worker for one webhook route's knob.
52
+ */
44
53
  freshnessSeconds?: number;
45
54
  /**
46
55
  * The currency this project's Paddle catalog prices in, when the project declared one.
@@ -1 +1 @@
1
- {"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/rail.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAEX,UAAU,EAIV,gBAAgB,EAKjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAmB,MAAM,OAAO,CAAC;AAkBtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,WAAW,EAAE,iBAAiB,CAAC;IAC/B,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C,kGAAkG;IAClG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,uBAAuB;AACvB,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,EAAE,iBAAiB,GACzB,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,gBAAgB,GAAG,UAAU,CAqHlG"}
1
+ {"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/rail.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAEX,UAAU,EAIV,gBAAgB,EAKjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAmB,MAAM,OAAO,CAAC;AAkBtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,WAAW,EAAE,iBAAiB,CAAC;IAC/B,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C;;;;;;;;;OASG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,uBAAuB;AACvB,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,EAAE,iBAAiB,GACzB,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,gBAAgB,GAAG,UAAU,CAqHlG"}
@@ -38,7 +38,9 @@
38
38
  * The window still earns its place, in both directions. It bounds how long a captured-but-never-delivered
39
39
  * signature stays usable, and it refuses a far-future timestamp — either a broken clock or somebody trying
40
40
  * to mint a delivery that never goes stale. Configurable, so an adopter who wants Paddle's number can set
41
- * it.
41
+ * it — bounded, and checked before it is used, because a window is only a boundary while it is a number. A
42
+ * non-finite tolerance makes `drift > tolerance` false for every delivery ever signed, which is not a wider
43
+ * window but no window at all.
42
44
  *
43
45
  * Paddle re-signs each retry attempt with a fresh `ts`, which is the only way a three-day retry window and
44
46
  * a five-second SDK tolerance could both be coherent — so the window does not silently reject retries.
@@ -60,7 +62,11 @@ export interface VerifyPaddleSignatureOptions {
60
62
  secret: string;
61
63
  /** The clock, for the freshness window. Injected so verification is deterministic. */
62
64
  now: Date;
63
- /** How many seconds either side of `now` a delivery may be dated. Undefined uses the default. */
65
+ /**
66
+ * How many seconds either side of `now` a delivery may be dated. Undefined uses the default, and anything
67
+ * present must be a finite number from 0 to {@link SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS} — anything else is
68
+ * `core/internal`, because a `NaN` here does not widen the window, it removes it.
69
+ */
64
70
  toleranceSeconds?: number;
65
71
  }
66
72
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/signature.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,wGAAwG;AACxG,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D,2GAA2G;AAC3G,eAAO,MAAM,gCAAgC,MAAM,CAAC;AAkBpD,uFAAuF;AACvF,MAAM,WAAW,4BAA4B;IAC3C,oFAAoF;IACpF,MAAM,EAAE,MAAM,CAAC;IACf,sFAAsF;IACtF,GAAG,EAAE,IAAI,CAAC;IACV,iGAAiG;IACjG,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AA+BD;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASrG;AA2CD;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CAgBf"}
1
+ {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/signature.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,wGAAwG;AACxG,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D,2GAA2G;AAC3G,eAAO,MAAM,gCAAgC,MAAM,CAAC;AAkBpD,uFAAuF;AACvF,MAAM,WAAW,4BAA4B;IAC3C,oFAAoF;IACpF,MAAM,EAAE,MAAM,CAAC;IACf,sFAAsF;IACtF,GAAG,EAAE,IAAI,CAAC;IACV;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AA+BD;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASrG;AA2CD;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CA4Cf"}
@@ -1,6 +1,8 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
  import { PaymentsVerificationFailedError } from "../../error/errors.js";
4
+ import { InternalError } from "@pithy-sh/core/src/error/pithyError";
5
+ import { SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS } from "@pithy-sh/core/src/http/webhookWindow";
4
6
  //#region src/rails/paddle/signature.ts
5
7
  /**
6
8
  * Paddle's authenticity proof: a timestamp and one or more HMACs, in one header.
@@ -40,7 +42,9 @@ import { PaymentsVerificationFailedError } from "../../error/errors.js";
40
42
  * The window still earns its place, in both directions. It bounds how long a captured-but-never-delivered
41
43
  * signature stays usable, and it refuses a far-future timestamp — either a broken clock or somebody trying
42
44
  * to mint a delivery that never goes stale. Configurable, so an adopter who wants Paddle's number can set
43
- * it.
45
+ * it — bounded, and checked before it is used, because a window is only a boundary while it is a number. A
46
+ * non-finite tolerance makes `drift > tolerance` false for every delivery ever signed, which is not a wider
47
+ * window but no window at all.
44
48
  *
45
49
  * Paddle re-signs each retry attempt with a fresh `ts`, which is the only way a three-day retry window and
46
50
  * a five-second SDK tolerance could both be coherent — so the window does not silently reject retries.
@@ -141,7 +145,18 @@ async function verifyPaddleSignature(body, header, options) {
141
145
  const parsed = header === null ? void 0 : parse(header.trim());
142
146
  if (parsed === void 0) throw new PaymentsVerificationFailedError({ detail: refusal("unreadable") });
143
147
  const tolerance = options.toleranceSeconds ?? 300;
144
- if (Math.abs(Math.floor(options.now.getTime() / 1e3) - parsed.timestamp) > tolerance) throw new PaymentsVerificationFailedError({ detail: refusal("stale") });
148
+ if (!Number.isFinite(tolerance) || tolerance < 0 || tolerance > SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS) throw new InternalError({
149
+ message: "This webhook endpoint is not configured.",
150
+ action: `Give the Paddle webhook a freshness window between 0 and ${SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS} seconds.`,
151
+ detail: `Paddle: the signature check was given a freshness window of ${String(tolerance)} seconds, and a window must be a number from 0 to ${SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS}.`
152
+ });
153
+ const nowSeconds = Math.floor(options.now.getTime() / 1e3);
154
+ if (!Number.isFinite(nowSeconds)) throw new InternalError({
155
+ message: "This webhook endpoint is not configured.",
156
+ action: "Give the Paddle webhook a valid clock.",
157
+ detail: "Paddle: the signature check was handed a clock that is not a valid Date, so no delivery's freshness can be judged."
158
+ });
159
+ if (Math.abs(nowSeconds - parsed.timestamp) > tolerance) throw new PaymentsVerificationFailedError({ detail: refusal("stale") });
145
160
  const key = await signingKey(options.secret, "verify");
146
161
  const message = new TextEncoder().encode(`${parsed.timestamp}:${body}`);
147
162
  for (const candidate of parsed.candidates) if (await crypto.subtle.verify("HMAC", key, candidate, message)) return;
@@ -22,7 +22,17 @@ import type { StripeHttpFetch } from "./api";
22
22
  export interface StripeRailOptions {
23
23
  /** The HTTP seam Stripe's API is reached through. Defaults to the runtime's `fetch`. */
24
24
  transport?: StripeHttpFetch;
25
- /** The signature freshness window, in seconds. Defaults to Stripe's own five minutes. */
25
+ /**
26
+ * The signature freshness window, in seconds. Defaults to Stripe's own five minutes.
27
+ *
28
+ * Threaded down unchanged and validated in exactly one place: `@pithy-sh/core`'s `checkSignedWebhook`, which
29
+ * refuses a non-finite, negative, or over-wide window as `core/internal` before it compares anything. This
30
+ * layer, `webhook.ts` and `signature.ts` each re-apply a default with `??` — which catches `undefined` and
31
+ * never `NaN` — and none of them re-checks the number. That is deliberate: one place that refuses is better
32
+ * than three that each half-check, and nothing on this path can reach the comparison without going through
33
+ * the primitive, so there is no bypass for a second check to cover. Three copies of the bound would only be
34
+ * three chances for one of them to drift.
35
+ */
26
36
  toleranceSeconds?: number;
27
37
  }
28
38
  /** The Stripe rail. Verifies a returning Checkout Session, verifies webhooks, and creates hosted sessions. */
@@ -1 +1 @@
1
- {"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/rail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAMZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAU7C;;;;;;;;;;;;;;GAcG;AAEH,iGAAiG;AACjG,MAAM,WAAW,iBAAiB;IAChC,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,yFAAyF;IACzF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,8GAA8G;AAC9G,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,GAAE,iBAAsB,GAC9B,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CA8ElE"}
1
+ {"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/rail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAMZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAU7C;;;;;;;;;;;;;;GAcG;AAEH,iGAAiG;AACjG,MAAM,WAAW,iBAAiB;IAChC,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,8GAA8G;AAC9G,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,GAAE,iBAAsB,GAC9B,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CA8ElE"}
@@ -50,7 +50,14 @@ export type StripeSignatureHeader = SignedWebhookHeader;
50
50
  export interface VerifyStripeSignatureOptions {
51
51
  /** The clock. Injected so the replay window is deterministic in tests rather than wall-clock dependent. */
52
52
  now: Date;
53
- /** The freshness window, in seconds. Defaults to {@link STRIPE_SIGNATURE_TOLERANCE_SECONDS}. */
53
+ /**
54
+ * The freshness window, in seconds. Defaults to {@link STRIPE_SIGNATURE_TOLERANCE_SECONDS}.
55
+ *
56
+ * The `??` below applies that default and nothing more — a `NaN` passes it untouched, on purpose. The
57
+ * primitive owns the bound (`core/internal` for anything non-finite, negative, or over-wide) because it owns
58
+ * the comparison, and every caller on this path reaches it. See {@link ./rail.StripeRailOptions} for why the
59
+ * check is not repeated at each layer.
60
+ */
54
61
  toleranceSeconds?: number;
55
62
  }
56
63
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/signature.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,mBAAmB,EAEzB,MAAM,uCAAuC,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,wGAAwG;AACxG,eAAO,MAAM,uBA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