@venturekit/billing 0.0.0-dev.20260825184900

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 (66) hide show
  1. package/README.md +218 -0
  2. package/dist/client.d.ts +109 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +139 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/errors.d.ts +102 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +133 -0
  9. package/dist/errors.js.map +1 -0
  10. package/dist/events.d.ts +170 -0
  11. package/dist/events.d.ts.map +1 -0
  12. package/dist/events.js +47 -0
  13. package/dist/events.js.map +1 -0
  14. package/dist/index.d.ts +48 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +52 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/provider.d.ts +178 -0
  19. package/dist/provider.d.ts.map +1 -0
  20. package/dist/provider.js +93 -0
  21. package/dist/provider.js.map +1 -0
  22. package/dist/providers/index.d.ts +15 -0
  23. package/dist/providers/index.d.ts.map +1 -0
  24. package/dist/providers/index.js +15 -0
  25. package/dist/providers/index.js.map +1 -0
  26. package/dist/providers/mock.d.ts +79 -0
  27. package/dist/providers/mock.d.ts.map +1 -0
  28. package/dist/providers/mock.js +536 -0
  29. package/dist/providers/mock.js.map +1 -0
  30. package/dist/providers/zazu/adapter.d.ts +39 -0
  31. package/dist/providers/zazu/adapter.d.ts.map +1 -0
  32. package/dist/providers/zazu/adapter.js +233 -0
  33. package/dist/providers/zazu/adapter.js.map +1 -0
  34. package/dist/providers/zazu/client.d.ts +76 -0
  35. package/dist/providers/zazu/client.d.ts.map +1 -0
  36. package/dist/providers/zazu/client.js +163 -0
  37. package/dist/providers/zazu/client.js.map +1 -0
  38. package/dist/providers/zazu/config.d.ts +54 -0
  39. package/dist/providers/zazu/config.d.ts.map +1 -0
  40. package/dist/providers/zazu/config.js +55 -0
  41. package/dist/providers/zazu/config.js.map +1 -0
  42. package/dist/providers/zazu/correlation.d.ts +65 -0
  43. package/dist/providers/zazu/correlation.d.ts.map +1 -0
  44. package/dist/providers/zazu/correlation.js +178 -0
  45. package/dist/providers/zazu/correlation.js.map +1 -0
  46. package/dist/providers/zazu/index.d.ts +18 -0
  47. package/dist/providers/zazu/index.d.ts.map +1 -0
  48. package/dist/providers/zazu/index.js +21 -0
  49. package/dist/providers/zazu/index.js.map +1 -0
  50. package/dist/providers/zazu/maps.d.ts +36 -0
  51. package/dist/providers/zazu/maps.d.ts.map +1 -0
  52. package/dist/providers/zazu/maps.js +450 -0
  53. package/dist/providers/zazu/maps.js.map +1 -0
  54. package/dist/providers/zazu/types.d.ts +365 -0
  55. package/dist/providers/zazu/types.d.ts.map +1 -0
  56. package/dist/providers/zazu/types.js +13 -0
  57. package/dist/providers/zazu/types.js.map +1 -0
  58. package/dist/providers/zazu/webhooks.d.ts +73 -0
  59. package/dist/providers/zazu/webhooks.d.ts.map +1 -0
  60. package/dist/providers/zazu/webhooks.js +259 -0
  61. package/dist/providers/zazu/webhooks.js.map +1 -0
  62. package/dist/types.d.ts +512 -0
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/types.js +16 -0
  65. package/dist/types.js.map +1 -0
  66. package/package.json +66 -0
package/dist/errors.js ADDED
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @venturekit/billing — error hierarchy
3
+ *
4
+ * All provider failures surface as a {@link ProviderError} carrying a
5
+ * `transient` flag. Transient errors (5xx, 429, network) are safe to
6
+ * retry; hard errors (4xx, auth, validation) should fail immediately.
7
+ * This mirrors the `ProviderSendError` / `ProviderHardError` split in
8
+ * `@venturekit/notify` but collapses both into one class with a flag so
9
+ * adapters can classify by HTTP status without picking a subclass.
10
+ */
11
+ /** Base class for every error thrown by this package. */
12
+ export class BillingError extends Error {
13
+ cause;
14
+ constructor(message, cause) {
15
+ super(message);
16
+ this.name = 'BillingError';
17
+ this.cause = cause;
18
+ }
19
+ }
20
+ /**
21
+ * Error returned by a payment provider. Use `transient` to decide
22
+ * whether to retry: `true` means the failure is likely temporary
23
+ * (provider 5xx, rate limit, network blip); `false` means the request
24
+ * is structurally wrong and retrying won't help (auth, validation,
25
+ * not found).
26
+ */
27
+ export class ProviderError extends BillingError {
28
+ /** HTTP status from the provider response, or `0` for network errors. */
29
+ status;
30
+ /** Whether retrying the same request could succeed. */
31
+ transient;
32
+ /** Raw provider response body (for diagnostics). */
33
+ providerData;
34
+ constructor(options) {
35
+ super(options.message, options.cause);
36
+ this.name = 'ProviderError';
37
+ this.status = options.status;
38
+ this.transient = options.transient;
39
+ this.providerData = options.providerData;
40
+ }
41
+ }
42
+ /**
43
+ * Webhook signature verification failed — the request is not provably
44
+ * from the provider. Treat as an authentication failure (respond 401)
45
+ * and alert: a burst of these means either a rotated secret or an
46
+ * attacker probing the endpoint.
47
+ */
48
+ export class WebhookSignatureError extends BillingError {
49
+ constructor(message, cause) {
50
+ super(message, cause);
51
+ this.name = 'WebhookSignatureError';
52
+ }
53
+ }
54
+ /**
55
+ * The signature verified but the payload could not be parsed or
56
+ * normalized — malformed JSON, a missing required header, absent event
57
+ * data, or an event type this adapter doesn't map.
58
+ *
59
+ * Deliberately distinct from {@link WebhookSignatureError}: this is an
60
+ * authentic request the adapter can't consume, so it must NOT be
61
+ * reported as an auth failure. Respond 400 (and, for an unknown event
62
+ * type, consider 200 so the provider stops redelivering it).
63
+ */
64
+ export class WebhookPayloadError extends BillingError {
65
+ constructor(message, cause) {
66
+ super(message, cause);
67
+ this.name = 'WebhookPayloadError';
68
+ }
69
+ }
70
+ /** The requested provider is not registered in the factory. */
71
+ export class UnknownProviderError extends BillingError {
72
+ provider;
73
+ constructor(provider) {
74
+ super(`Unknown billing provider: "${provider}". Register it via createBillingClient or createProvider.`);
75
+ this.name = 'UnknownProviderError';
76
+ this.provider = provider;
77
+ }
78
+ }
79
+ /**
80
+ * A {@link CorrelationRef} carried data the target flow cannot
81
+ * round-trip, or a reference collided with a provider-visible field.
82
+ *
83
+ * This exists because the failure is otherwise **silent**: Zazu accepts
84
+ * only four whitelisted query parameters on a payment link and ignores
85
+ * everything else without error, so a dropped metadata map would only
86
+ * surface as missing data at webhook time — long after the request that
87
+ * caused it.
88
+ */
89
+ export class UnsupportedCorrelationError extends BillingError {
90
+ flow;
91
+ constructor(flow, detail) {
92
+ super(`Correlation is not supported for the "${flow}" flow: ${detail}`);
93
+ this.name = 'UnsupportedCorrelationError';
94
+ this.flow = flow;
95
+ }
96
+ }
97
+ /**
98
+ * A {@link CorrelationRef} violated a provider's metadata constraints
99
+ * (key count, key charset, or value length). Raised locally, before the
100
+ * request, so the failure names the offending key instead of surfacing
101
+ * as an opaque provider 422.
102
+ */
103
+ export class InvalidCorrelationError extends BillingError {
104
+ constructor(message) {
105
+ super(message);
106
+ this.name = 'InvalidCorrelationError';
107
+ }
108
+ }
109
+ /**
110
+ * The mock provider was constructed outside a provably local
111
+ * environment. The mock accepts webhooks **without verifying any
112
+ * signature** and fabricates successful payments, so reaching it from a
113
+ * deployed stage would mean trusting forged payment events.
114
+ */
115
+ export class MockProviderNotAllowedError extends BillingError {
116
+ constructor() {
117
+ super('The mock billing provider is refusing to start: it accepts unverified ' +
118
+ 'webhooks and fabricates payments, so it must never run in a deployed ' +
119
+ 'environment. It is enabled only under `vk dev` (VENTURE_LOCAL=true) or ' +
120
+ 'in tests (NODE_ENV=test).');
121
+ this.name = 'MockProviderNotAllowedError';
122
+ }
123
+ }
124
+ /** Required configuration (API key, base URL, …) is missing. */
125
+ export class MissingConfigError extends BillingError {
126
+ key;
127
+ constructor(key, hint) {
128
+ super(`Missing required billing config: "${key}".${hint ? ` ${hint}` : ''}`);
129
+ this.name = 'MissingConfigError';
130
+ this.key = key;
131
+ }
132
+ }
133
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,yDAAyD;AACzD,MAAM,O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AAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,2BAA4B,SAAQ,YAAY;IAClD,IAAI,CAAS;IACtB,YAAY,IAAY,EAAE,MAAc;QACtC,KAAK,CAAC,yCAAyC,IAAI,WAAW,MAAM,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,uBAAwB,SAAQ,YAAY;IACvD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,2BAA4B,SAAQ,YAAY;IAC3D;QACE,KAAK,CACH,wEAAwE;YACtE,uEAAuE;YACvE,yEAAyE;YACzE,2BAA2B,CAC9B,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAED,gEAAgE;AAChE,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IACzC,GAAG,CAAS;IACrB,YAAY,GAAW,EAAE,IAAa;QACpC,KAAK,CAAC,qCAAqC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * @venturekit/billing — normalized webhook events
3
+ *
4
+ * Every provider's `handleWebhookEvent` returns a {@link PaymentEvent}
5
+ * in this canonical shape, regardless of the raw payload structure.
6
+ * The application publishes `PaymentEvent` to its event bus
7
+ * (`publishEvent` from `@venturekit/runtime/patterns`) and subscribers
8
+ * react to `event.type` without knowing which provider fired it.
9
+ *
10
+ * Idempotency: `eventId` (the provider's stable event id, e.g. Zazu's
11
+ * `X-Zazu-Event-Id`) must be deduplicated by the consumer — providers
12
+ * may deliver the same event more than once. Zazu retries up to 8 times
13
+ * over ~28 hours, so this is not optional.
14
+ *
15
+ * ## Correlation, not reconstruction
16
+ *
17
+ * Webhook payloads are **projections** — they carry a strict subset of
18
+ * the fields the REST API returns, and the subset differs per event. So
19
+ * an event deliberately does NOT try to rebuild a full domain object.
20
+ * Instead it hands back:
21
+ *
22
+ * - `correlation` — the identifiers you supplied on create, so you can
23
+ * look up your own record. This is the intended reconciliation path.
24
+ * - `objectId` — the provider's id, for follow-up API calls.
25
+ * - `amount` — what the provider says was paid. **Verify this against
26
+ * your own record before fulfilling**; do not trust the event alone.
27
+ * - `raw` — the untouched provider payload, for anything else.
28
+ *
29
+ * `data` then carries only the fields a given event type is documented
30
+ * to include. Earlier versions projected `CheckoutSession` / `PaymentLink`
31
+ * / `Transfer` domain objects into events, which meant every event type
32
+ * had to fabricate the fields its payload lacked.
33
+ */
34
+ import type { CheckoutTransaction, CorrelationRef, Money } from './types.js';
35
+ import type { ProviderName } from './provider.js';
36
+ /**
37
+ * Canonical event type names. These are the `detail-type` values an
38
+ * application publishes to its event bus.
39
+ */
40
+ export type PaymentEventType = 'checkout_session.completed' | 'payment_link.paid' | 'transfer.executed' | 'test.ping';
41
+ /**
42
+ * Fields the `checkout_session.completed` payload is documented to
43
+ * carry. Everything optional here is genuinely optional in the payload.
44
+ */
45
+ export interface CheckoutSessionCompletedData {
46
+ sessionId: string;
47
+ status: string;
48
+ completedAt?: string;
49
+ customerEmail?: string;
50
+ description?: string;
51
+ /** Card transaction, present once the session completes. */
52
+ transaction?: CheckoutTransaction;
53
+ }
54
+ /**
55
+ * Fields the `payment_link.paid` payload is documented to carry. Note
56
+ * the customer identifiers are "always present, set to null when not
57
+ * supplied" per Zazu's docs, hence optional rather than absent.
58
+ */
59
+ export interface PaymentLinkPaidData {
60
+ paymentLinkId: string;
61
+ slug?: string;
62
+ status: string;
63
+ linkType?: string;
64
+ title?: string;
65
+ description?: string;
66
+ paymentReference?: string;
67
+ paymentsCount?: number;
68
+ paidAt?: string;
69
+ customerEmail?: string;
70
+ customerId?: string;
71
+ customerName?: string;
72
+ }
73
+ /**
74
+ * Fields the `transfer.executed` payload is documented to carry.
75
+ *
76
+ * Deliberately has **no `accountId`**: the payload does not include one,
77
+ * and an earlier version fabricated `''` to satisfy a required field on
78
+ * the shared `Transfer` type. If you need the source account, resolve it
79
+ * from your own record via `correlation`, or fetch the draft with
80
+ * `transfers.getTransfer(objectId)`.
81
+ */
82
+ export interface TransferExecutedData {
83
+ transferId: string;
84
+ /** Raw provider status (e.g. Zazu's `"accepted"`), not remapped. */
85
+ providerStatus: string;
86
+ /** `"debit"` / `"credit"` where the provider reports it. */
87
+ operation?: string;
88
+ paymentReference?: string;
89
+ postedAt?: string;
90
+ }
91
+ /** Empty payload for `test.ping`. */
92
+ export interface TestPingData {
93
+ [key: string]: unknown;
94
+ }
95
+ export type PaymentEventData = (CheckoutSessionCompletedData & {
96
+ type: 'checkout_session.completed';
97
+ }) | (PaymentLinkPaidData & {
98
+ type: 'payment_link.paid';
99
+ }) | (TransferExecutedData & {
100
+ type: 'transfer.executed';
101
+ }) | (TestPingData & {
102
+ type: 'test.ping';
103
+ });
104
+ /**
105
+ * A normalized webhook event ready to publish to the application's
106
+ * event bus. The `data` field is a discriminated union keyed by
107
+ * `data.type` so consumers can narrow with a switch.
108
+ */
109
+ export interface PaymentEvent {
110
+ /** Canonical event type (also available as `data.type`). */
111
+ type: PaymentEventType;
112
+ /** Provider that emitted the event. */
113
+ provider: ProviderName;
114
+ /** Provider's stable event id — deduplicate on this. */
115
+ eventId: string;
116
+ /** Provider's delivery id (distinct from eventId when the provider retries). */
117
+ deliveryId?: string;
118
+ /** ISO 8601 timestamp the event was created by the provider. */
119
+ createdAt: string;
120
+ /**
121
+ * The identifiers you supplied when creating the object, echoed back.
122
+ * `null` when none were supplied, or when the provider dropped them.
123
+ *
124
+ * This is the intended way to tie an event to your own record. Prefer
125
+ * it over `objectId`, which is meaningful only to the provider.
126
+ */
127
+ correlation: CorrelationRef | null;
128
+ /**
129
+ * Provider id of the object this event concerns — the checkout session,
130
+ * payment link, or transfer. Use it for follow-up API calls.
131
+ */
132
+ objectId: string | null;
133
+ /**
134
+ * Amount the provider reports. `null` on events that carry none
135
+ * (`test.ping`).
136
+ *
137
+ * **Check this against your own record before fulfilling.** Correlation
138
+ * tells you *which* order the event is for; it does not tell you the
139
+ * right amount was paid.
140
+ */
141
+ amount: Money | null;
142
+ /**
143
+ * The provider's payload, untouched. An escape hatch for fields this
144
+ * package does not normalize — prefer the typed fields where they exist,
145
+ * since this one is provider-shaped and unstable.
146
+ */
147
+ raw: unknown;
148
+ /** Discriminated payload of documented-present fields. */
149
+ data: PaymentEventData;
150
+ }
151
+ /**
152
+ * Type guard helpers so consumers (and tests) can narrow a
153
+ * {@link PaymentEvent} without repeating the discriminant check.
154
+ */
155
+ export declare function isCheckoutSessionCompleted(e: PaymentEvent): e is PaymentEvent & {
156
+ data: CheckoutSessionCompletedData & {
157
+ type: 'checkout_session.completed';
158
+ };
159
+ };
160
+ export declare function isPaymentLinkPaid(e: PaymentEvent): e is PaymentEvent & {
161
+ data: PaymentLinkPaidData & {
162
+ type: 'payment_link.paid';
163
+ };
164
+ };
165
+ export declare function isTransferExecuted(e: PaymentEvent): e is PaymentEvent & {
166
+ data: TransferExecutedData & {
167
+ type: 'transfer.executed';
168
+ };
169
+ };
170
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE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AE,CAAA;CAAE,CAEnF;AAED,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,YAAY,GACd,CAAC,IAAI,YAAY,GAAG;IAAE,IAAI,EAAE,oBAAoB,GAAG;QAAE,IAAI,EAAE,mBAAmB,CAAA;KAAE,CAAA;CAAE,CAEpF"}
package/dist/events.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @venturekit/billing — normalized webhook events
3
+ *
4
+ * Every provider's `handleWebhookEvent` returns a {@link PaymentEvent}
5
+ * in this canonical shape, regardless of the raw payload structure.
6
+ * The application publishes `PaymentEvent` to its event bus
7
+ * (`publishEvent` from `@venturekit/runtime/patterns`) and subscribers
8
+ * react to `event.type` without knowing which provider fired it.
9
+ *
10
+ * Idempotency: `eventId` (the provider's stable event id, e.g. Zazu's
11
+ * `X-Zazu-Event-Id`) must be deduplicated by the consumer — providers
12
+ * may deliver the same event more than once. Zazu retries up to 8 times
13
+ * over ~28 hours, so this is not optional.
14
+ *
15
+ * ## Correlation, not reconstruction
16
+ *
17
+ * Webhook payloads are **projections** — they carry a strict subset of
18
+ * the fields the REST API returns, and the subset differs per event. So
19
+ * an event deliberately does NOT try to rebuild a full domain object.
20
+ * Instead it hands back:
21
+ *
22
+ * - `correlation` — the identifiers you supplied on create, so you can
23
+ * look up your own record. This is the intended reconciliation path.
24
+ * - `objectId` — the provider's id, for follow-up API calls.
25
+ * - `amount` — what the provider says was paid. **Verify this against
26
+ * your own record before fulfilling**; do not trust the event alone.
27
+ * - `raw` — the untouched provider payload, for anything else.
28
+ *
29
+ * `data` then carries only the fields a given event type is documented
30
+ * to include. Earlier versions projected `CheckoutSession` / `PaymentLink`
31
+ * / `Transfer` domain objects into events, which meant every event type
32
+ * had to fabricate the fields its payload lacked.
33
+ */
34
+ /**
35
+ * Type guard helpers so consumers (and tests) can narrow a
36
+ * {@link PaymentEvent} without repeating the discriminant check.
37
+ */
38
+ export function isCheckoutSessionCompleted(e) {
39
+ return e.type === 'checkout_session.completed';
40
+ }
41
+ export function isPaymentLinkPaid(e) {
42
+ return e.type === 'payment_link.paid';
43
+ }
44
+ export function isTransferExecuted(e) {
45
+ return e.type === 'transfer.executed';
46
+ }
47
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AA2IH;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACxC,CAAe;IAEf,OAAO,CAAC,CAAC,IAAI,KAAK,4BAA4B,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,CAAe;IAEf,OAAO,CAAC,CAAC,IAAI,KAAK,mBAAmB,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,CAAe;IAEf,OAAO,CAAC,CAAC,IAAI,KAAK,mBAAmB,CAAC;AACxC,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @venturekit/billing
3
+ *
4
+ * Multi-provider billing for VentureKit. Provides a provider-agnostic
5
+ * abstraction (`PaymentProvider`) over payment providers (Zazu, Stripe,
6
+ * PayPal) with checkout sessions, payment links, invoices, transfers,
7
+ * and normalized webhook events.
8
+ *
9
+ * ## Quick start
10
+ *
11
+ * ```ts
12
+ * import { createBillingClient, createZazuAdapter } from '@venturekit/billing';
13
+ *
14
+ * // createZazuAdapter() resolves config from ZAZU_* env vars.
15
+ * const billing = createBillingClient({
16
+ * providers: { zazu: createZazuAdapter() },
17
+ * defaultProvider: 'zazu',
18
+ * });
19
+ *
20
+ * // Checkout session (customer-driven, per-order)
21
+ * const session = await billing.createCheckoutSession({
22
+ * accountId: process.env.ZAZU_ACCOUNT_ID!,
23
+ * amount: { amount: '1500.000', currency: 'MAD' },
24
+ * successUrl: 'https://app.example.com/success?session={CHECKOUT_SESSION_ID}',
25
+ * metadata: { order_id: 'ORD-123' },
26
+ * });
27
+ *
28
+ * // Webhook → normalized event ready to publish
29
+ * const event = await billing.handleWebhookEvent({ rawBody, headers });
30
+ * // → publishEvent(event.type, event.data, { source: 'billing' })
31
+ * ```
32
+ *
33
+ * ## Extensibility
34
+ *
35
+ * Providers self-register via `registerProvider(name, factory)`. Add a
36
+ * new provider by implementing `PaymentProvider` and registering it —
37
+ * no edits to core files. See the README for the full checklist.
38
+ */
39
+ export type { Money, Customer, CustomerType, BillingAddress, Order, CheckoutSession, CheckoutSessionStatus, CheckoutTransaction, CreateCheckoutSessionInput, PaymentLink, PaymentLinkType, PaymentLinkStatus, PaymentLinkAccount, CreatePaymentLinkInput, Invoice, InvoiceStatus, InvoiceLineItem, InvoiceDiscount, CreateInvoiceInput, ListInvoicesParams, CreateCustomerInput, UpdateCustomerInput, ListCustomersParams, Transfer, TransferStatus, CreateTransferInput, ListTransfersParams, ListPaymentLinksParams, Account, AccountStatus, ListAccountsParams, AccountTransaction, AccountTransactionOperation, ListAccountTransactionsParams, WebhookEndpoint, WebhookEndpointStatus, WebhookEndpointWithSecret, CreateWebhookEndpointInput, UpdateWebhookEndpointInput, ListWebhookEndpointsParams, TestWebhookEndpointResult, CursorPage, CorrelationRef, CorrelationFlow, CorrelationSupport, } from './types.js';
40
+ export { BillingError, ProviderError, WebhookSignatureError, WebhookPayloadError, UnknownProviderError, UnsupportedCorrelationError, InvalidCorrelationError, MockProviderNotAllowedError, MissingConfigError, } from './errors.js';
41
+ export { isCheckoutSessionCompleted, isPaymentLinkPaid, isTransferExecuted, } from './events.js';
42
+ export type { PaymentEvent, PaymentEventType, PaymentEventData, CheckoutSessionCompletedData, PaymentLinkPaidData, TransferExecutedData, TestPingData, } from './events.js';
43
+ export { registerProvider, createProvider, isProviderRegistered, registeredProviders, supportsInvoicing, supportsTransfers, supportsAccounts, supportsWebhookEndpoints, } from './provider.js';
44
+ export type { PaymentProvider, FullPaymentProvider, InvoicingCapable, TransferCapable, AccountCapable, WebhookEndpointCapable, ProviderFactory, ProviderName, WebhookRequest, } from './provider.js';
45
+ export { createBillingClient, createBillingClientFor, createBillingClientFromEnv, CapabilityNotSupportedError, } from './client.js';
46
+ export type { BillingClient, CreateBillingClientOptions, CreateBillingClientFromEnvOptions, } from './client.js';
47
+ export { createZazuAdapter, type ZazuAdapter, createZazuHttpClient, type ZazuHttpClient, resolveZazuConfig, type ZazuConfig, verifyZazuSignature, parseZazuWebhook, handleZazuWebhook, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, type HandleZazuWebhookOptions, } from './providers/index.js';
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAGH,YAAY,EACV,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,KAAK,EACL,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,0BAA0B,EAC1B,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,OAAO,EACP,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,EAC3B,6BAA6B,EAC7B,eAAe,EACf,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,UAAU,EACV,cAAc,EACd,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,EAC3B,uBAAuB,EACvB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,4BAA4B,EAC5B,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,cAAc,GACf,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,aAAa,EACb,0BAA0B,EAC1B,iCAAiC,GAClC,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,EAChB,oBAAoB,EACpB,KAAK,cAAc,EACnB,iBAAiB,EACjB,KAAK,UAAU,EACf,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,iCAAiC,EACjC,KAAK,wBAAwB,GAC9B,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @venturekit/billing
3
+ *
4
+ * Multi-provider billing for VentureKit. Provides a provider-agnostic
5
+ * abstraction (`PaymentProvider`) over payment providers (Zazu, Stripe,
6
+ * PayPal) with checkout sessions, payment links, invoices, transfers,
7
+ * and normalized webhook events.
8
+ *
9
+ * ## Quick start
10
+ *
11
+ * ```ts
12
+ * import { createBillingClient, createZazuAdapter } from '@venturekit/billing';
13
+ *
14
+ * // createZazuAdapter() resolves config from ZAZU_* env vars.
15
+ * const billing = createBillingClient({
16
+ * providers: { zazu: createZazuAdapter() },
17
+ * defaultProvider: 'zazu',
18
+ * });
19
+ *
20
+ * // Checkout session (customer-driven, per-order)
21
+ * const session = await billing.createCheckoutSession({
22
+ * accountId: process.env.ZAZU_ACCOUNT_ID!,
23
+ * amount: { amount: '1500.000', currency: 'MAD' },
24
+ * successUrl: 'https://app.example.com/success?session={CHECKOUT_SESSION_ID}',
25
+ * metadata: { order_id: 'ORD-123' },
26
+ * });
27
+ *
28
+ * // Webhook → normalized event ready to publish
29
+ * const event = await billing.handleWebhookEvent({ rawBody, headers });
30
+ * // → publishEvent(event.type, event.data, { source: 'billing' })
31
+ * ```
32
+ *
33
+ * ## Extensibility
34
+ *
35
+ * Providers self-register via `registerProvider(name, factory)`. Add a
36
+ * new provider by implementing `PaymentProvider` and registering it —
37
+ * no edits to core files. See the README for the full checklist.
38
+ */
39
+ // Errors ------------------------------------------------------------
40
+ export { BillingError, ProviderError, WebhookSignatureError, WebhookPayloadError, UnknownProviderError, UnsupportedCorrelationError, InvalidCorrelationError, MockProviderNotAllowedError, MissingConfigError, } from './errors.js';
41
+ // Events ------------------------------------------------------------
42
+ export { isCheckoutSessionCompleted, isPaymentLinkPaid, isTransferExecuted, } from './events.js';
43
+ // Provider interface, capabilities & registry ----------------------
44
+ export { registerProvider, createProvider, isProviderRegistered, registeredProviders, supportsInvoicing, supportsTransfers, supportsAccounts, supportsWebhookEndpoints, } from './provider.js';
45
+ // Client facade -----------------------------------------------------
46
+ export { createBillingClient, createBillingClientFor, createBillingClientFromEnv, CapabilityNotSupportedError, } from './client.js';
47
+ // Providers ---------------------------------------------------------
48
+ // The mock is NOT re-exported here on purpose: it skips webhook
49
+ // signature verification, so it must stay out of production bundles.
50
+ // Import it by subpath — `@venturekit/billing/providers/mock`.
51
+ export { createZazuAdapter, createZazuHttpClient, resolveZazuConfig, verifyZazuSignature, parseZazuWebhook, handleZazuWebhook, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, } from './providers/index.js';
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAmDH,sEAAsE;AACtE,OAAO,EACL,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,EAC3B,uBAAuB,EACvB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,sEAAsE;AACtE,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAWrB,qEAAqE;AACrE,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AAavB,sEAAsE;AACtE,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,aAAa,CAAC;AAOrB,sEAAsE;AACtE,gEAAgE;AAChE,qEAAqE;AACrE,+DAA+D;AAC/D,OAAO,EACL,iBAAiB,EAEjB,oBAAoB,EAEpB,iBAAiB,EAEjB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,iCAAiC,GAElC,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @venturekit/billing — payment provider interface, capabilities & registry
3
+ *
4
+ * ## Interface segregation
5
+ *
6
+ * {@link PaymentProvider} holds only what EVERY card-payment provider can
7
+ * do: hosted checkout, shareable payment links, and inbound webhook
8
+ * normalization. Everything else is an **optional capability** — a
9
+ * separate interface an adapter opts into:
10
+ *
11
+ * | Capability | Operations |
12
+ * | ------------------------------ | ------------------------------------------- |
13
+ * | {@link InvoicingCapable} | invoices + customers |
14
+ * | {@link TransferCapable} | outgoing transfers |
15
+ * | {@link AccountCapable} | funding accounts + their ledger entries |
16
+ * | {@link WebhookEndpointCapable} | webhook endpoint provisioning |
17
+ *
18
+ * This keeps a future Stripe or PayPal adapter from stubbing methods it
19
+ * has no equivalent for (e.g. Zazu's bank accounts). Consumers narrow
20
+ * with the `supports*` type guards before calling.
21
+ *
22
+ * ## Extensibility
23
+ *
24
+ * Providers self-register into a {@link registerProvider registry} so
25
+ * adding a provider NEVER requires editing this file — implement the
26
+ * interface(s), call `registerProvider('name', factory)` in the provider's
27
+ * module, and it's usable by name. Applications can also construct
28
+ * adapters directly and pass instances to `createBillingClient`.
29
+ */
30
+ import type { Account, AccountTransaction, CheckoutSession, CreateCheckoutSessionInput, CreateCustomerInput, CreateInvoiceInput, CreatePaymentLinkInput, CreateTransferInput, CreateWebhookEndpointInput, CorrelationFlow, CorrelationSupport, CursorPage, Customer, Invoice, ListAccountTransactionsParams, ListAccountsParams, ListCustomersParams, ListInvoicesParams, ListPaymentLinksParams, ListTransfersParams, ListWebhookEndpointsParams, PaymentLink, TestWebhookEndpointResult, Transfer, UpdateCustomerInput, UpdateWebhookEndpointInput, WebhookEndpoint, WebhookEndpointWithSecret } from './types.js';
31
+ import type { PaymentEvent } from './events.js';
32
+ /**
33
+ * A provider name. `string` (not a closed union) so third-party
34
+ * providers registered at runtime are first-class — the registry is the
35
+ * source of truth, not a compile-time enum.
36
+ */
37
+ export type ProviderName = string;
38
+ /**
39
+ * Raw webhook request handed to `handleWebhookEvent`. `rawBody` is the
40
+ * untouched request body the provider signed — API Gateway delivers it
41
+ * as a string (or base64) and the handler must NOT re-serialize it, or
42
+ * the signature won't match.
43
+ */
44
+ export interface WebhookRequest {
45
+ /** Raw request body exactly as received. */
46
+ rawBody: string;
47
+ /** Lowercased request headers. */
48
+ headers: Record<string, string>;
49
+ }
50
+ /**
51
+ * The universal payment provider contract. Implementations must:
52
+ *
53
+ * - Map domain inputs → provider API bodies and provider responses →
54
+ * domain objects (see `providers/zazu/maps.ts` for an example).
55
+ * - Throw {@link ProviderError} with `transient` set correctly on
56
+ * failures so callers can retry intelligently.
57
+ * - Verify the webhook signature inside `handleWebhookEvent` and throw
58
+ * {@link WebhookSignatureError} on mismatch.
59
+ * - Return a normalized {@link PaymentEvent} from `handleWebhookEvent`
60
+ * so the application can publish it without provider-specific parsing.
61
+ *
62
+ * All method names and domain types are provider-agnostic — nothing here
63
+ * references a specific provider's concepts.
64
+ */
65
+ export interface PaymentProvider {
66
+ /** Provider identifier (`'zazu'`, `'stripe'`, `'paypal'`, `'mock'`, …). */
67
+ readonly name: ProviderName;
68
+ /**
69
+ * What this provider can round-trip for a given flow. Query it before
70
+ * relying on `correlation.metadata`, which is not universally
71
+ * supported — Zazu carries a metadata map on checkout sessions but
72
+ * only a single query parameter on payment links.
73
+ *
74
+ * Passing unsupported correlation to a create call throws
75
+ * {@link UnsupportedCorrelationError} rather than silently dropping it.
76
+ */
77
+ correlationSupport(flow: CorrelationFlow): CorrelationSupport;
78
+ createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
79
+ getCheckoutSession(id: string): Promise<CheckoutSession>;
80
+ createPaymentLink(input: CreatePaymentLinkInput): Promise<PaymentLink>;
81
+ getPaymentLink(id: string): Promise<PaymentLink>;
82
+ listPaymentLinks(params?: ListPaymentLinksParams): Promise<CursorPage<PaymentLink>>;
83
+ cancelPaymentLink(id: string): Promise<PaymentLink>;
84
+ handleWebhookEvent(request: WebhookRequest): Promise<PaymentEvent>;
85
+ }
86
+ /** Invoicing + customer management. */
87
+ export interface InvoicingCapable {
88
+ createInvoice(input: CreateInvoiceInput): Promise<Invoice>;
89
+ getInvoice(id: string): Promise<Invoice>;
90
+ listInvoices(params?: ListInvoicesParams): Promise<CursorPage<Invoice>>;
91
+ /** Send (or re-send) the invoice to the customer. */
92
+ sendInvoice(id: string): Promise<Invoice>;
93
+ markInvoicePaid(id: string): Promise<Invoice>;
94
+ cancelInvoice(id: string): Promise<Invoice>;
95
+ createCustomer(input: CreateCustomerInput): Promise<Customer>;
96
+ getCustomer(id: string): Promise<Customer>;
97
+ listCustomers(params?: ListCustomersParams): Promise<CursorPage<Customer>>;
98
+ updateCustomer(id: string, input: UpdateCustomerInput): Promise<Customer>;
99
+ deleteCustomer(id: string): Promise<void>;
100
+ }
101
+ /** Outgoing transfers / payouts. */
102
+ export interface TransferCapable {
103
+ createTransfer(input: CreateTransferInput): Promise<Transfer>;
104
+ getTransfer(id: string): Promise<Transfer>;
105
+ listTransfers(params?: ListTransfersParams): Promise<CursorPage<Transfer>>;
106
+ }
107
+ /**
108
+ * Provider-held funding / settlement accounts and their ledger entries.
109
+ * Only providers that expose accounts as first-class objects (Zazu)
110
+ * implement this.
111
+ */
112
+ export interface AccountCapable {
113
+ listAccounts(params?: ListAccountsParams): Promise<CursorPage<Account>>;
114
+ getAccount(id: string): Promise<Account>;
115
+ listAccountTransactions(accountId: string, params?: ListAccountTransactionsParams): Promise<CursorPage<AccountTransaction>>;
116
+ getAccountTransaction(accountId: string, id: string): Promise<AccountTransaction>;
117
+ }
118
+ /** Programmatic webhook endpoint provisioning. */
119
+ export interface WebhookEndpointCapable {
120
+ listWebhookEndpoints(params?: ListWebhookEndpointsParams): Promise<CursorPage<WebhookEndpoint>>;
121
+ /** Returns the signing secret — shown only once, store it immediately. */
122
+ createWebhookEndpoint(input: CreateWebhookEndpointInput): Promise<WebhookEndpointWithSecret>;
123
+ getWebhookEndpoint(id: string): Promise<WebhookEndpoint>;
124
+ updateWebhookEndpoint(id: string, input: UpdateWebhookEndpointInput): Promise<WebhookEndpoint>;
125
+ deleteWebhookEndpoint(id: string): Promise<void>;
126
+ enableWebhookEndpoint(id: string): Promise<WebhookEndpoint>;
127
+ disableWebhookEndpoint(id: string): Promise<WebhookEndpoint>;
128
+ /** Ask the provider to deliver a test event to the endpoint. */
129
+ testWebhookEndpoint(id: string): Promise<TestWebhookEndpointResult>;
130
+ /** Rotate the signing secret and return the new value. */
131
+ regenerateWebhookEndpointSecret(id: string): Promise<WebhookEndpointWithSecret>;
132
+ }
133
+ /** Narrow a provider to one that supports invoicing + customers. */
134
+ export declare function supportsInvoicing<T extends object>(p: T): p is T & InvoicingCapable;
135
+ /** Narrow a provider to one that supports outgoing transfers. */
136
+ export declare function supportsTransfers<T extends object>(p: T): p is T & TransferCapable;
137
+ /** Narrow a provider to one that exposes funding accounts. */
138
+ export declare function supportsAccounts<T extends object>(p: T): p is T & AccountCapable;
139
+ /** Narrow a provider to one that supports webhook endpoint provisioning. */
140
+ export declare function supportsWebhookEndpoints<T extends object>(p: T): p is T & WebhookEndpointCapable;
141
+ /**
142
+ * A provider implementing every capability. Convenience alias for
143
+ * adapters (like Zazu) that support the full surface.
144
+ */
145
+ export type FullPaymentProvider = PaymentProvider & InvoicingCapable & TransferCapable & AccountCapable & WebhookEndpointCapable;
146
+ /**
147
+ * A factory that builds a provider adapter from its resolved config.
148
+ * Providers register one of these under their name.
149
+ */
150
+ export type ProviderFactory<C = unknown> = (config?: C) => PaymentProvider;
151
+ /**
152
+ * Register a provider factory under a name. Providers typically call
153
+ * this at the top level of their barrel module so that importing the
154
+ * provider makes it available by name:
155
+ *
156
+ * ```ts
157
+ * // providers/stripe/index.ts
158
+ * registerProvider('stripe', (cfg?: Partial<StripeConfig>) => createStripeAdapter(cfg));
159
+ * ```
160
+ *
161
+ * Registering the same name twice replaces the previous factory
162
+ * (last write wins) — useful for overriding a built-in provider in
163
+ * tests.
164
+ */
165
+ export declare function registerProvider<C>(name: ProviderName, factory: ProviderFactory<C>): void;
166
+ /** True if a provider with this name has been registered. */
167
+ export declare function isProviderRegistered(name: ProviderName): boolean;
168
+ /** Names of all currently registered providers. */
169
+ export declare function registeredProviders(): ProviderName[];
170
+ /**
171
+ * Build a registered provider by name. Throws {@link UnknownProviderError}
172
+ * if the name hasn't been registered (i.e. the provider module was never
173
+ * imported). Prefer constructing adapters directly and passing them to
174
+ * `createBillingClient` for full tree-shaking control; this string-based
175
+ * path exists for config-driven selection.
176
+ */
177
+ export declare function createProvider(name: ProviderName, config?: unknown): PaymentProvider;
178
+ //# sourceMappingURL=provider.d.ts.map