@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
@@ -0,0 +1,233 @@
1
+ /**
2
+ * @venturekit/billing — Zazu adapter
3
+ *
4
+ * Implements the core {@link PaymentProvider} contract plus all four
5
+ * optional capabilities (invoicing, transfers, accounts, webhook
6
+ * endpoints) by orchestrating the HTTP client (`./client.ts`) and the
7
+ * mappers (`./maps.ts`), and delegating inbound webhook handling to
8
+ * `./webhooks.ts`.
9
+ *
10
+ * Config resolves from the `ZAZU_*` environment variables by default
11
+ * (see `./config.ts`), so `createZazuAdapter()` works with no arguments.
12
+ * The adapter is stateless beyond holding the resolved config; create
13
+ * one per provider config and reuse it.
14
+ *
15
+ * Note on feature flags: Zazu gates invoicing (`release_invoicing`),
16
+ * payment links (`release_payment_links`), API transfers
17
+ * (`release_api_transfers`), and webhook endpoints (`release_webhooks`)
18
+ * per entity. The adapter exposes all of them; calls fail with a
19
+ * non-transient {@link ProviderError} (403) when a flag is off.
20
+ */
21
+ import { MissingConfigError } from '../../errors.js';
22
+ import { createZazuHttpClient } from './client.js';
23
+ import { resolveZazuConfig } from './config.js';
24
+ import { mapAccount, mapAccountTransaction, mapCheckoutSession, mapCreateCheckoutSessionBody, mapCreateCustomerBody, mapCreateInvoiceBody, mapCreatePaymentLinkBody, mapCreateTransferBody, mapCreateWebhookEndpointBody, mapCustomer, mapInvoice, mapPaymentLink, mapTransfer, mapUpdateWebhookEndpointBody, mapWebhookEndpoint, mapWebhookEndpointWithSecret, } from './maps.js';
25
+ import { attachPaymentLinkCorrelation, zazuCorrelationSupport, } from './correlation.js';
26
+ import { handleZazuWebhook } from './webhooks.js';
27
+ /**
28
+ * Zazu requires an account on every money-movement call. Resolution
29
+ * order: the per-call override, then the adapter's configured default
30
+ * (`ZAZU_ACCOUNT_ID`).
31
+ *
32
+ * The per-call argument exists for multi-account tenants; the config
33
+ * default exists so single-account applications don't thread an id
34
+ * through every call site. One of the two must be present.
35
+ */
36
+ function requireAccountId(perCall, configured) {
37
+ const accountId = perCall ?? configured;
38
+ if (!accountId) {
39
+ throw new MissingConfigError('accountId', 'Zazu requires an account. Set ZAZU_ACCOUNT_ID (or pass { accountId } to ' +
40
+ 'createZazuAdapter) for the default, or supply accountId on the call. ' +
41
+ 'Discover valid ids with listAccounts().');
42
+ }
43
+ return accountId;
44
+ }
45
+ /** Map a domain cursor page from a raw Zazu page. */
46
+ function page(raw, map) {
47
+ return {
48
+ data: raw.data.map(map),
49
+ hasMore: raw.has_more,
50
+ nextCursor: raw.next_cursor ?? undefined,
51
+ };
52
+ }
53
+ /**
54
+ * Create a Zazu provider adapter.
55
+ *
56
+ * @param config - Partial Zazu config; missing values resolve from the
57
+ * `ZAZU_API_KEY` / `ZAZU_BASE_URL` / `ZAZU_WEBHOOK_SECRET` env vars.
58
+ * @param deps - Optional dependency injection (used by tests to pass a
59
+ * mocked HTTP client without touching `fetch`).
60
+ */
61
+ export function createZazuAdapter(config, deps) {
62
+ const resolved = resolveZazuConfig(config);
63
+ const http = deps?.httpClient ?? createZazuHttpClient(resolved);
64
+ return {
65
+ name: 'zazu',
66
+ correlationSupport(flow) {
67
+ return zazuCorrelationSupport(flow);
68
+ },
69
+ // -- Checkout sessions ------------------------------------------------
70
+ async createCheckoutSession(input) {
71
+ const accountId = requireAccountId(input.accountId, resolved.accountId);
72
+ const raw = await http.createCheckoutSession(mapCreateCheckoutSessionBody({ ...input, accountId }));
73
+ return mapCheckoutSession(raw);
74
+ },
75
+ async getCheckoutSession(id) {
76
+ return mapCheckoutSession(await http.getCheckoutSession(id));
77
+ },
78
+ // -- Payment links ----------------------------------------------------
79
+ async createPaymentLink(input) {
80
+ const accountId = requireAccountId(input.accountId, resolved.accountId);
81
+ const raw = await http.createPaymentLink(mapCreatePaymentLinkBody({ ...input, accountId }));
82
+ const link = mapPaymentLink(raw);
83
+ // Zazu carries payment-link correlation as a URL query parameter, so
84
+ // the reference is attached to the hosted URL rather than the body.
85
+ // The caller must share THIS url for the reference to come back.
86
+ return {
87
+ ...link,
88
+ url: attachPaymentLinkCorrelation(link.url, input.correlation),
89
+ };
90
+ },
91
+ async getPaymentLink(id) {
92
+ return mapPaymentLink(await http.getPaymentLink(id));
93
+ },
94
+ async listPaymentLinks(params) {
95
+ const raw = await http.listPaymentLinks({
96
+ status: params?.status,
97
+ link_type: params?.linkType,
98
+ cursor: params?.cursor,
99
+ limit: params?.limit,
100
+ });
101
+ return page(raw, mapPaymentLink);
102
+ },
103
+ async cancelPaymentLink(id) {
104
+ return mapPaymentLink(await http.cancelPaymentLink(id));
105
+ },
106
+ // -- Invoicing capability ---------------------------------------------
107
+ async createInvoice(input) {
108
+ return mapInvoice(await http.createInvoice(mapCreateInvoiceBody(input)));
109
+ },
110
+ async getInvoice(id) {
111
+ return mapInvoice(await http.getInvoice(id));
112
+ },
113
+ async listInvoices(params) {
114
+ const raw = await http.listInvoices({
115
+ status: params?.status,
116
+ customer_id: params?.customerId,
117
+ cursor: params?.cursor,
118
+ limit: params?.limit,
119
+ });
120
+ return page(raw, mapInvoice);
121
+ },
122
+ async sendInvoice(id) {
123
+ return mapInvoice(await http.sendInvoice(id));
124
+ },
125
+ async markInvoicePaid(id) {
126
+ return mapInvoice(await http.markInvoicePaid(id));
127
+ },
128
+ async cancelInvoice(id) {
129
+ return mapInvoice(await http.cancelInvoice(id));
130
+ },
131
+ async createCustomer(input) {
132
+ return mapCustomer(await http.createCustomer(mapCreateCustomerBody(input)));
133
+ },
134
+ async getCustomer(id) {
135
+ return mapCustomer(await http.getCustomer(id));
136
+ },
137
+ async listCustomers(params) {
138
+ const raw = await http.listCustomers({
139
+ q: params?.query,
140
+ cursor: params?.cursor,
141
+ limit: params?.limit,
142
+ });
143
+ return page(raw, mapCustomer);
144
+ },
145
+ async updateCustomer(id, input) {
146
+ return mapCustomer(await http.updateCustomer(id, mapCreateCustomerBody(input)));
147
+ },
148
+ async deleteCustomer(id) {
149
+ await http.deleteCustomer(id);
150
+ },
151
+ // -- Transfer capability ----------------------------------------------
152
+ async createTransfer(input) {
153
+ const accountId = requireAccountId(input.accountId, resolved.accountId);
154
+ return mapTransfer(await http.createTransfer(mapCreateTransferBody({ ...input, accountId })));
155
+ },
156
+ async getTransfer(id) {
157
+ return mapTransfer(await http.getTransfer(id));
158
+ },
159
+ async listTransfers(params) {
160
+ const raw = await http.listTransfers({
161
+ status: params?.status,
162
+ cursor: params?.cursor,
163
+ limit: params?.limit,
164
+ });
165
+ return page(raw, mapTransfer);
166
+ },
167
+ // -- Account capability -----------------------------------------------
168
+ async listAccounts(params) {
169
+ const raw = await http.listAccounts({
170
+ status: params?.status,
171
+ currency_code: params?.currency,
172
+ cursor: params?.cursor,
173
+ limit: params?.limit,
174
+ });
175
+ return page(raw, mapAccount);
176
+ },
177
+ async getAccount(id) {
178
+ return mapAccount(await http.getAccount(id));
179
+ },
180
+ async listAccountTransactions(accountId, params) {
181
+ const raw = await http.listAccountTransactions(accountId, {
182
+ cursor: params?.cursor,
183
+ limit: params?.limit,
184
+ });
185
+ return page(raw, mapAccountTransaction);
186
+ },
187
+ async getAccountTransaction(accountId, id) {
188
+ return mapAccountTransaction(await http.getAccountTransaction(accountId, id));
189
+ },
190
+ // -- Webhook endpoint capability --------------------------------------
191
+ async listWebhookEndpoints(params) {
192
+ const raw = await http.listWebhookEndpoints({
193
+ cursor: params?.cursor,
194
+ limit: params?.limit,
195
+ });
196
+ return page(raw, mapWebhookEndpoint);
197
+ },
198
+ async createWebhookEndpoint(input) {
199
+ const raw = await http.createWebhookEndpoint(mapCreateWebhookEndpointBody(input));
200
+ return mapWebhookEndpointWithSecret(raw);
201
+ },
202
+ async getWebhookEndpoint(id) {
203
+ return mapWebhookEndpoint(await http.getWebhookEndpoint(id));
204
+ },
205
+ async updateWebhookEndpoint(id, input) {
206
+ const raw = await http.updateWebhookEndpoint(id, mapUpdateWebhookEndpointBody(input));
207
+ return mapWebhookEndpoint(raw);
208
+ },
209
+ async deleteWebhookEndpoint(id) {
210
+ await http.deleteWebhookEndpoint(id);
211
+ },
212
+ async enableWebhookEndpoint(id) {
213
+ return mapWebhookEndpoint(await http.enableWebhookEndpoint(id));
214
+ },
215
+ async disableWebhookEndpoint(id) {
216
+ return mapWebhookEndpoint(await http.disableWebhookEndpoint(id));
217
+ },
218
+ async testWebhookEndpoint(id) {
219
+ const raw = await http.testWebhookEndpoint(id);
220
+ return { deliveryId: raw.delivery_id, status: raw.status };
221
+ },
222
+ async regenerateWebhookEndpointSecret(id) {
223
+ return mapWebhookEndpointWithSecret(await http.regenerateWebhookEndpointSecret(id));
224
+ },
225
+ // -- Inbound webhooks -------------------------------------------------
226
+ async handleWebhookEvent(request) {
227
+ return handleZazuWebhook(resolved.webhookSecret, request, {
228
+ toleranceSeconds: resolved.webhookToleranceSeconds,
229
+ });
230
+ },
231
+ };
232
+ }
233
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/providers/zazu/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAiCrD,OAAO,EAAE,oBAAoB,EAAuB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAmB,MAAM,aAAa,CAAC;AACjE,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,4BAA4B,EAC5B,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,4BAA4B,EAC5B,WAAW,EACX,UAAU,EACV,cAAc,EACd,WAAW,EACX,4BAA4B,EAC5B,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOlD;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CACvB,OAA2B,EAC3B,UAA8B;IAE9B,MAAM,SAAS,GAAG,OAAO,IAAI,UAAU,CAAC;IACxC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,kBAAkB,CAC1B,WAAW,EACX,0EAA0E;YACxE,uEAAuE;YACvE,yCAAyC,CAC5C,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,qDAAqD;AACrD,SAAS,IAAI,CACX,GAAkE,EAClE,GAAgB;IAEhB,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QACvB,OAAO,EAAE,GAAG,CAAC,QAAQ;QACrB,UAAU,EAAE,GAAG,CAAC,WAAW,IAAI,SAAS;KACzC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG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EAAU;YACpC,MAAM,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC;QACvC,CAAC;QAED,KAAK,CAAC,qBAAqB,CAAC,EAAU;YACpC,OAAO,kBAAkB,CAAC,MAAM,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAAC;QAClE,CAAC;QAED,KAAK,CAAC,sBAAsB,CAAC,EAAU;YACrC,OAAO,kBAAkB,CAAC,MAAM,IAAI,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC;QACnE,CAAC;QAED,KAAK,CAAC,mBAAmB,CAAC,EAAU;YAClC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;YAC/C,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;QAC7D,CAAC;QAED,KAAK,CAAC,+BAA+B,CAAC,EAAU;YAC9C,OAAO,4BAA4B,CAAC,MAAM,IAAI,CAAC,+BAA+B,CAAC,EAAE,CAAC,CAAC,CAAC;QACtF,CAAC;QAED,wEAAwE;QAExE,KAAK,CAAC,kBAAkB,CAAC,OAAuB;YAC9C,OAAO,iBAAiB,CAAC,QAAQ,CAAC,aAAa,EAAE,OAAO,EAAE;gBACxD,gBAAgB,EAAE,QAAQ,CAAC,uBAAuB;aACnD,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @venturekit/billing — Zazu HTTP client
3
+ *
4
+ * Thin wrapper over `@venturekit/integrations` `apiClient` that injects
5
+ * Zazu's Bearer auth and base URL. Returns the raw Zazu shapes from
6
+ * `./types.ts`; mapping to domain objects is the adapter's job
7
+ * (`./adapter.ts`), not the client's.
8
+ *
9
+ * ## Retries are read-only
10
+ *
11
+ * `apiClient` retries on timeouts, network errors, and 408/429/5xx. That
12
+ * is safe for GETs and wrong for POSTs: a request the provider accepted
13
+ * but whose response was lost gets sent again, creating a second
14
+ * resource. Zazu exposes no idempotency-key header (see
15
+ * https://staging.zazu.ma/docs/overview), so the only safe policy is to
16
+ * retry reads and never retry mutations — two clients, one policy each.
17
+ *
18
+ * Concretely: `POST /api/payments` creates a transfer *draft* awaiting
19
+ * human approval, so a duplicate lands in the approval queue rather than
20
+ * settling twice — but an approver can authorize both. `POST
21
+ * /api/invoices` is worse, since duplicates reach the customer.
22
+ *
23
+ * Errors from `apiClient` (`ApiError`) are converted to
24
+ * {@link ProviderError}. The `transient` flag marks what is worth
25
+ * retrying: 5xx, 429, timeouts, and network failures; everything else is
26
+ * hard. Callers that own an application-level idempotency key can safely
27
+ * retry a `transient` mutation themselves. Zazu's error envelope
28
+ * (`{ error: { message, param } }`) is surfaced in the message, since
29
+ * `apiClient` only synthesises a generic status line.
30
+ */
31
+ import type { ZazuConfig } from './config.js';
32
+ import type { ZazuAccount, ZazuAccountTransaction, ZazuCheckoutSession, ZazuCreateCheckoutSessionBody, ZazuCreateCustomerBody, ZazuCreateInvoiceBody, ZazuCreatePaymentLinkBody, ZazuCreateTransferBody, ZazuCreateWebhookEndpointBody, ZazuCursorPage, ZazuCustomer, ZazuInvoice, ZazuPaymentLink, ZazuTestWebhookEndpointResponse, ZazuTransfer, ZazuUpdateWebhookEndpointBody, ZazuWebhookEndpoint, ZazuWebhookEndpointWithSecret } from './types.js';
33
+ /** Query params accepted by `apiClient`. */
34
+ type Params = Record<string, string | number | boolean | undefined> | undefined;
35
+ export interface ZazuHttpClient {
36
+ createCheckoutSession(body: ZazuCreateCheckoutSessionBody): Promise<ZazuCheckoutSession>;
37
+ getCheckoutSession(id: string): Promise<ZazuCheckoutSession>;
38
+ createPaymentLink(body: ZazuCreatePaymentLinkBody): Promise<ZazuPaymentLink>;
39
+ getPaymentLink(id: string): Promise<ZazuPaymentLink>;
40
+ listPaymentLinks(params?: Params): Promise<ZazuCursorPage<ZazuPaymentLink>>;
41
+ cancelPaymentLink(id: string): Promise<ZazuPaymentLink>;
42
+ createInvoice(body: ZazuCreateInvoiceBody): Promise<ZazuInvoice>;
43
+ getInvoice(id: string): Promise<ZazuInvoice>;
44
+ listInvoices(params?: Params): Promise<ZazuCursorPage<ZazuInvoice>>;
45
+ sendInvoice(id: string): Promise<ZazuInvoice>;
46
+ markInvoicePaid(id: string): Promise<ZazuInvoice>;
47
+ cancelInvoice(id: string): Promise<ZazuInvoice>;
48
+ createCustomer(body: ZazuCreateCustomerBody): Promise<ZazuCustomer>;
49
+ getCustomer(id: string): Promise<ZazuCustomer>;
50
+ listCustomers(params?: Params): Promise<ZazuCursorPage<ZazuCustomer>>;
51
+ updateCustomer(id: string, body: ZazuCreateCustomerBody): Promise<ZazuCustomer>;
52
+ deleteCustomer(id: string): Promise<void>;
53
+ createTransfer(body: ZazuCreateTransferBody): Promise<ZazuTransfer>;
54
+ getTransfer(id: string): Promise<ZazuTransfer>;
55
+ listTransfers(params?: Params): Promise<ZazuCursorPage<ZazuTransfer>>;
56
+ listAccounts(params?: Params): Promise<ZazuCursorPage<ZazuAccount>>;
57
+ getAccount(id: string): Promise<ZazuAccount>;
58
+ listAccountTransactions(accountId: string, params?: Params): Promise<ZazuCursorPage<ZazuAccountTransaction>>;
59
+ getAccountTransaction(accountId: string, id: string): Promise<ZazuAccountTransaction>;
60
+ listWebhookEndpoints(params?: Params): Promise<ZazuCursorPage<ZazuWebhookEndpoint>>;
61
+ createWebhookEndpoint(body: ZazuCreateWebhookEndpointBody): Promise<ZazuWebhookEndpointWithSecret>;
62
+ getWebhookEndpoint(id: string): Promise<ZazuWebhookEndpoint>;
63
+ updateWebhookEndpoint(id: string, body: ZazuUpdateWebhookEndpointBody): Promise<ZazuWebhookEndpoint>;
64
+ deleteWebhookEndpoint(id: string): Promise<void>;
65
+ enableWebhookEndpoint(id: string): Promise<ZazuWebhookEndpoint>;
66
+ disableWebhookEndpoint(id: string): Promise<ZazuWebhookEndpoint>;
67
+ testWebhookEndpoint(id: string): Promise<ZazuTestWebhookEndpointResponse>;
68
+ regenerateWebhookEndpointSecret(id: string): Promise<ZazuWebhookEndpointWithSecret>;
69
+ }
70
+ /**
71
+ * Create a Zazu HTTP client. `config.maxRetries` applies to reads only —
72
+ * see the retry note at the top of this file.
73
+ */
74
+ export declare function createZazuHttpClient(config: ZazuConfig): ZazuHttpClient;
75
+ export {};
76
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/providers/zazu/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EACV,WAAW,EACX,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,6BAA6B,EAC7B,cAAc,EACd,YAAY,EACZ,WAAW,EACX,eAAe,EACf,+BAA+B,EAC/B,YAAY,EACZ,6BAA6B,EAC7B,mBAAmB,EACnB,6BAA6B,EAC9B,MAAM,YAAY,CAAC;AAoDpB,4CAA4C;AAC5C,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;AAMhF,MAAM,WAAW,cAAc;IAE7B,qBAAqB,CAAC,IAAI,EAAE,6BAA6B,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACzF,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAG7D,iBAAiB,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7E,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACrD,gBAAgB,CAAC,MAAM,CAAC,EAA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,UAAU,GAAG,cAAc,CAqHvE"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * @venturekit/billing — Zazu HTTP client
3
+ *
4
+ * Thin wrapper over `@venturekit/integrations` `apiClient` that injects
5
+ * Zazu's Bearer auth and base URL. Returns the raw Zazu shapes from
6
+ * `./types.ts`; mapping to domain objects is the adapter's job
7
+ * (`./adapter.ts`), not the client's.
8
+ *
9
+ * ## Retries are read-only
10
+ *
11
+ * `apiClient` retries on timeouts, network errors, and 408/429/5xx. That
12
+ * is safe for GETs and wrong for POSTs: a request the provider accepted
13
+ * but whose response was lost gets sent again, creating a second
14
+ * resource. Zazu exposes no idempotency-key header (see
15
+ * https://staging.zazu.ma/docs/overview), so the only safe policy is to
16
+ * retry reads and never retry mutations — two clients, one policy each.
17
+ *
18
+ * Concretely: `POST /api/payments` creates a transfer *draft* awaiting
19
+ * human approval, so a duplicate lands in the approval queue rather than
20
+ * settling twice — but an approver can authorize both. `POST
21
+ * /api/invoices` is worse, since duplicates reach the customer.
22
+ *
23
+ * Errors from `apiClient` (`ApiError`) are converted to
24
+ * {@link ProviderError}. The `transient` flag marks what is worth
25
+ * retrying: 5xx, 429, timeouts, and network failures; everything else is
26
+ * hard. Callers that own an application-level idempotency key can safely
27
+ * retry a `transient` mutation themselves. Zazu's error envelope
28
+ * (`{ error: { message, param } }`) is surfaced in the message, since
29
+ * `apiClient` only synthesises a generic status line.
30
+ */
31
+ import { apiClient, ApiError } from '@venturekit/integrations';
32
+ import { ProviderError } from '../../errors.js';
33
+ // ---------------------------------------------------------------------------
34
+ // Error classification
35
+ // ---------------------------------------------------------------------------
36
+ const TRANSIENT_STATUSES = new Set([408, 425, 429, 500, 502, 503, 504]);
37
+ /**
38
+ * Pull the human-readable reason out of Zazu's error envelope,
39
+ * `{ "error": { "type", "message", "param" } }`. `apiClient` only
40
+ * synthesises `"<METHOD> <url> failed with status <n>"`, so without this
41
+ * the actual cause ("Customer not found", param `customer_id`) is
42
+ * invisible unless the caller digs into `providerData`.
43
+ * See https://staging.zazu.ma/docs/overview.
44
+ */
45
+ function zazuErrorMessage(data) {
46
+ if (typeof data !== 'object' || data === null)
47
+ return undefined;
48
+ const envelope = data.error;
49
+ if (typeof envelope !== 'object' || envelope === null)
50
+ return undefined;
51
+ const { message, param } = envelope;
52
+ if (typeof message !== 'string' || message === '')
53
+ return undefined;
54
+ return typeof param === 'string' && param !== '' ? `${message} (param: ${param})` : message;
55
+ }
56
+ function toProviderError(err) {
57
+ if (err instanceof ApiError) {
58
+ // `apiClient` reports network failures AND timeouts as an ApiError
59
+ // with status 0, so status alone can't classify them — checking only
60
+ // TRANSIENT_STATUSES would mark every socket blip as permanent. A
61
+ // caller-initiated abort is the one status-0 case that is final.
62
+ const aborted = err.aborted === true;
63
+ const transient = err.status === 0 ? !aborted : TRANSIENT_STATUSES.has(err.status);
64
+ const reason = zazuErrorMessage(err.data);
65
+ return new ProviderError({
66
+ message: reason ? `${reason} [${err.message}]` : err.message,
67
+ status: err.status,
68
+ transient,
69
+ providerData: err.data,
70
+ cause: err,
71
+ });
72
+ }
73
+ // Anything that never reached `apiClient`'s own error mapping.
74
+ const message = err instanceof Error ? err.message : String(err);
75
+ return new ProviderError({
76
+ message,
77
+ status: 0,
78
+ transient: true,
79
+ cause: err,
80
+ });
81
+ }
82
+ /**
83
+ * Create a Zazu HTTP client. `config.maxRetries` applies to reads only —
84
+ * see the retry note at the top of this file.
85
+ */
86
+ export function createZazuHttpClient(config) {
87
+ const shared = {
88
+ baseUrl: config.baseUrl,
89
+ headers: {
90
+ Authorization: `Bearer ${config.apiKey}`,
91
+ 'Content-Type': 'application/json',
92
+ },
93
+ timeout: config.timeoutMs ?? 30_000,
94
+ };
95
+ /** Idempotent reads — retried with exponential backoff. */
96
+ const read = apiClient({
97
+ ...shared,
98
+ retry: {
99
+ maxRetries: config.maxRetries ?? 3,
100
+ initialDelayMs: 500,
101
+ backoffMultiplier: 2,
102
+ },
103
+ });
104
+ /** Mutations — never retried, at any status. */
105
+ const write = apiClient({ ...shared, retry: { maxRetries: 0 } });
106
+ async function unwrap(p) {
107
+ try {
108
+ const res = await p;
109
+ return res.data;
110
+ }
111
+ catch (err) {
112
+ throw toProviderError(err);
113
+ }
114
+ }
115
+ const id = (v) => encodeURIComponent(v);
116
+ return {
117
+ // Checkout sessions ---------------------------------------------------
118
+ createCheckoutSession: (body) => unwrap(write.post('/api/checkout_sessions', { body })),
119
+ getCheckoutSession: (i) => unwrap(read.get(`/api/checkout_sessions/${id(i)}`)),
120
+ // Payment links -------------------------------------------------------
121
+ createPaymentLink: (body) => unwrap(write.post('/api/payment_links', { body })),
122
+ getPaymentLink: (i) => unwrap(read.get(`/api/payment_links/${id(i)}`)),
123
+ listPaymentLinks: (params) => unwrap(read.get('/api/payment_links', { params })),
124
+ cancelPaymentLink: (i) => unwrap(write.post(`/api/payment_links/${id(i)}/cancel`)),
125
+ // Invoices ------------------------------------------------------------
126
+ createInvoice: (body) => unwrap(write.post('/api/invoices', { body })),
127
+ getInvoice: (i) => unwrap(read.get(`/api/invoices/${id(i)}`)),
128
+ listInvoices: (params) => unwrap(read.get('/api/invoices', { params })),
129
+ sendInvoice: (i) => unwrap(write.post(`/api/invoices/${id(i)}/send`)),
130
+ markInvoicePaid: (i) => unwrap(write.post(`/api/invoices/${id(i)}/mark_as_paid`)),
131
+ cancelInvoice: (i) => unwrap(write.post(`/api/invoices/${id(i)}/cancel`)),
132
+ // Customers -----------------------------------------------------------
133
+ createCustomer: (body) => unwrap(write.post('/api/customers', { body })),
134
+ getCustomer: (i) => unwrap(read.get(`/api/customers/${id(i)}`)),
135
+ listCustomers: (params) => unwrap(read.get('/api/customers', { params })),
136
+ updateCustomer: (i, body) => unwrap(write.patch(`/api/customers/${id(i)}`, { body })),
137
+ deleteCustomer: async (i) => {
138
+ await unwrap(write.delete(`/api/customers/${id(i)}`));
139
+ },
140
+ // Transfers -----------------------------------------------------------
141
+ createTransfer: (body) => unwrap(write.post('/api/payments', { body })),
142
+ getTransfer: (i) => unwrap(read.get(`/api/payments/${id(i)}`)),
143
+ listTransfers: (params) => unwrap(read.get('/api/payments', { params })),
144
+ // Accounts ------------------------------------------------------------
145
+ listAccounts: (params) => unwrap(read.get('/api/accounts', { params })),
146
+ getAccount: (i) => unwrap(read.get(`/api/accounts/${id(i)}`)),
147
+ listAccountTransactions: (accountId, params) => unwrap(read.get(`/api/accounts/${id(accountId)}/transactions`, { params })),
148
+ getAccountTransaction: (accountId, i) => unwrap(read.get(`/api/accounts/${id(accountId)}/transactions/${id(i)}`)),
149
+ // Webhook endpoints ---------------------------------------------------
150
+ listWebhookEndpoints: (params) => unwrap(read.get('/api/webhook_endpoints', { params })),
151
+ createWebhookEndpoint: (body) => unwrap(write.post('/api/webhook_endpoints', { body })),
152
+ getWebhookEndpoint: (i) => unwrap(read.get(`/api/webhook_endpoints/${id(i)}`)),
153
+ updateWebhookEndpoint: (i, body) => unwrap(write.patch(`/api/webhook_endpoints/${id(i)}`, { body })),
154
+ deleteWebhookEndpoint: async (i) => {
155
+ await unwrap(write.delete(`/api/webhook_endpoints/${id(i)}`));
156
+ },
157
+ enableWebhookEndpoint: (i) => unwrap(write.post(`/api/webhook_endpoints/${id(i)}/enable`)),
158
+ disableWebhookEndpoint: (i) => unwrap(write.post(`/api/webhook_endpoints/${id(i)}/disable`)),
159
+ testWebhookEndpoint: (i) => unwrap(write.post(`/api/webhook_endpoints/${id(i)}/test`)),
160
+ regenerateWebhookEndpointSecret: (i) => unwrap(write.post(`/api/webhook_endpoints/${id(i)}/regenerate_secret`)),
161
+ };
162
+ }
163
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/providers/zazu/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,0BAA0B,CAAC;AAE/E,OAAO,EAAE,aAAa,EAAE,MAAM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CACrC,MAAM,CACJ,KAAK,CAAC,IAAI,CACR,0BAA0B,EAAE,CAAC,CAAC,CAAC,oBAAoB,CACpD,CACF;KACJ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @venturekit/billing — Zazu configuration
3
+ *
4
+ * Zazu config is self-contained in the provider module (mirrors how
5
+ * `@venturekit/notify` keeps `SesEmailProviderConfig` inside its
6
+ * provider file). Values resolve from the `ZAZU_*` environment variables
7
+ * by default, with explicit overrides accepted — secrets never live in
8
+ * source code.
9
+ */
10
+ export interface ZazuConfig {
11
+ /** Zazu API key (Bearer token). Required. */
12
+ apiKey: string;
13
+ /** Base URL — sandbox or production. Required. */
14
+ baseUrl: string;
15
+ /**
16
+ * Default funding/destination account id, from `ZAZU_ACCOUNT_ID`.
17
+ *
18
+ * Zazu requires `account_id` to create a checkout session, a payment
19
+ * link, or a transfer, but for most applications it is a deployment
20
+ * property rather than a per-payment one — so it lives here instead of
21
+ * on every call. Individual calls may still override it, which is what
22
+ * a multi-account tenant needs. Discover valid ids with
23
+ * `listAccounts()`.
24
+ */
25
+ accountId?: string;
26
+ /** Webhook endpoint signing secret (for signature verification). */
27
+ webhookSecret?: string;
28
+ /** Optional request timeout override (ms). */
29
+ timeoutMs?: number;
30
+ /**
31
+ * Optional retry override. Applies to idempotent reads only — see the
32
+ * retry note in `./client.ts`.
33
+ */
34
+ maxRetries?: number;
35
+ /**
36
+ * Maximum accepted age of a webhook signature, in seconds. Defaults to
37
+ * 300. Set to `0` to disable replay protection (not recommended).
38
+ */
39
+ webhookToleranceSeconds?: number;
40
+ }
41
+ /**
42
+ * Resolve Zazu config from explicit values, falling back to the
43
+ * `ZAZU_API_KEY` / `ZAZU_BASE_URL` / `ZAZU_ACCOUNT_ID` /
44
+ * `ZAZU_WEBHOOK_SECRET` / `ZAZU_WEBHOOK_TOLERANCE_SECONDS` environment
45
+ * variables. Throws {@link MissingConfigError} if the API key cannot be
46
+ * determined.
47
+ *
48
+ * `accountId` is deliberately NOT required here: an application that
49
+ * always passes an explicit account per call is valid, so the check
50
+ * happens at the call site (see `requireAccountId` in `./adapter.ts`)
51
+ * where a useful hint can name both remedies.
52
+ */
53
+ export declare function resolveZazuConfig(input?: Partial<ZazuConfig>): ZazuConfig;
54
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/providers/zazu/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAeD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAyBzE"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @venturekit/billing — Zazu configuration
3
+ *
4
+ * Zazu config is self-contained in the provider module (mirrors how
5
+ * `@venturekit/notify` keeps `SesEmailProviderConfig` inside its
6
+ * provider file). Values resolve from the `ZAZU_*` environment variables
7
+ * by default, with explicit overrides accepted — secrets never live in
8
+ * source code.
9
+ */
10
+ import { MissingConfigError } from '../../errors.js';
11
+ const DEFAULT_BASE_URL = 'https://staging.zazu.ma';
12
+ /**
13
+ * Parse a positive-integer env var, ignoring blank and non-numeric
14
+ * values so a typo falls back to the documented default rather than
15
+ * silently disabling a check.
16
+ */
17
+ function numberFromEnv(raw) {
18
+ if (raw === undefined || raw.trim() === '')
19
+ return undefined;
20
+ const value = Number(raw);
21
+ return Number.isFinite(value) && value >= 0 ? value : undefined;
22
+ }
23
+ /**
24
+ * Resolve Zazu config from explicit values, falling back to the
25
+ * `ZAZU_API_KEY` / `ZAZU_BASE_URL` / `ZAZU_ACCOUNT_ID` /
26
+ * `ZAZU_WEBHOOK_SECRET` / `ZAZU_WEBHOOK_TOLERANCE_SECONDS` environment
27
+ * variables. Throws {@link MissingConfigError} if the API key cannot be
28
+ * determined.
29
+ *
30
+ * `accountId` is deliberately NOT required here: an application that
31
+ * always passes an explicit account per call is valid, so the check
32
+ * happens at the call site (see `requireAccountId` in `./adapter.ts`)
33
+ * where a useful hint can name both remedies.
34
+ */
35
+ export function resolveZazuConfig(input) {
36
+ const apiKey = input?.apiKey ?? process.env.ZAZU_API_KEY;
37
+ const baseUrl = input?.baseUrl ?? process.env.ZAZU_BASE_URL ?? DEFAULT_BASE_URL;
38
+ const accountId = input?.accountId ?? process.env.ZAZU_ACCOUNT_ID;
39
+ const webhookSecret = input?.webhookSecret ?? process.env.ZAZU_WEBHOOK_SECRET;
40
+ const webhookToleranceSeconds = input?.webhookToleranceSeconds ??
41
+ numberFromEnv(process.env.ZAZU_WEBHOOK_TOLERANCE_SECONDS);
42
+ if (!apiKey) {
43
+ throw new MissingConfigError('apiKey', 'Set ZAZU_API_KEY or pass { apiKey } to createZazuAdapter.');
44
+ }
45
+ return {
46
+ apiKey,
47
+ baseUrl,
48
+ accountId,
49
+ webhookSecret,
50
+ timeoutMs: input?.timeoutMs,
51
+ maxRetries: input?.maxRetries,
52
+ webhookToleranceSeconds,
53
+ };
54
+ }
55
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/providers/zazu/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAkCrD,MAAM,gBAAgB,GAAG,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