@getmanza/sdk 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +21 -0
  3. package/README.md +154 -2
  4. package/dist/client.d.ts +43 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/errors.d.ts +46 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/index.cjs +655 -0
  9. package/dist/index.d.ts +17 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +613 -0
  12. package/dist/page.d.ts +19 -0
  13. package/dist/page.d.ts.map +1 -0
  14. package/dist/resources/accounts.d.ts +19 -0
  15. package/dist/resources/accounts.d.ts.map +1 -0
  16. package/dist/resources/base.d.ts +19 -0
  17. package/dist/resources/base.d.ts.map +1 -0
  18. package/dist/resources/beneficiaries.d.ts +12 -0
  19. package/dist/resources/beneficiaries.d.ts.map +1 -0
  20. package/dist/resources/checkout_sessions.d.ts +7 -0
  21. package/dist/resources/checkout_sessions.d.ts.map +1 -0
  22. package/dist/resources/customers.d.ts +14 -0
  23. package/dist/resources/customers.d.ts.map +1 -0
  24. package/dist/resources/entity.d.ts +6 -0
  25. package/dist/resources/entity.d.ts.map +1 -0
  26. package/dist/resources/invoices.d.ts +20 -0
  27. package/dist/resources/invoices.d.ts.map +1 -0
  28. package/dist/resources/payee_trust_requests.d.ts +9 -0
  29. package/dist/resources/payee_trust_requests.d.ts.map +1 -0
  30. package/dist/resources/payment_links.d.ts +10 -0
  31. package/dist/resources/payment_links.d.ts.map +1 -0
  32. package/dist/resources/transfer_drafts.d.ts +15 -0
  33. package/dist/resources/transfer_drafts.d.ts.map +1 -0
  34. package/dist/resources/webhook_endpoints.d.ts +20 -0
  35. package/dist/resources/webhook_endpoints.d.ts.map +1 -0
  36. package/dist/response.d.ts +10 -0
  37. package/dist/response.d.ts.map +1 -0
  38. package/dist/transfer_authorization.d.ts +27 -0
  39. package/dist/transfer_authorization.d.ts.map +1 -0
  40. package/dist/version.d.ts +2 -0
  41. package/dist/version.d.ts.map +1 -0
  42. package/package.json +70 -4
package/dist/index.js ADDED
@@ -0,0 +1,613 @@
1
+ // src/errors.ts
2
+ class ZazuError extends Error {
3
+ status;
4
+ requestId;
5
+ type;
6
+ param;
7
+ body;
8
+ headers;
9
+ constructor(message, options = {}) {
10
+ super(message);
11
+ this.name = new.target.name;
12
+ this.status = options.status;
13
+ this.requestId = options.requestId ?? null;
14
+ this.type = options.type ?? null;
15
+ this.param = options.param ?? null;
16
+ this.body = options.body;
17
+ this.headers = options.headers ?? null;
18
+ }
19
+ }
20
+
21
+ class ZazuConfigurationError extends ZazuError {
22
+ }
23
+
24
+ class ZazuConnectionError extends ZazuError {
25
+ }
26
+
27
+ class ZazuAuthenticationError extends ZazuError {
28
+ }
29
+
30
+ class ZazuForbiddenError extends ZazuError {
31
+ }
32
+
33
+ class ZazuNotFoundError extends ZazuError {
34
+ }
35
+
36
+ class ZazuValidationError extends ZazuError {
37
+ }
38
+
39
+ class ZazuRateLimitError extends ZazuError {
40
+ retryAfter;
41
+ constructor(message, options = {}) {
42
+ super(message, options);
43
+ this.retryAfter = options.retryAfter ?? null;
44
+ }
45
+ }
46
+
47
+ class ZazuServerError extends ZazuError {
48
+ }
49
+
50
+ class ZazuArgumentError extends ZazuError {
51
+ }
52
+
53
+ class ZazuConflictError extends ZazuError {
54
+ paymentId;
55
+ constructor(message, options = {}) {
56
+ super(message, options);
57
+ this.paymentId = options.paymentId ?? null;
58
+ }
59
+ }
60
+
61
+ // src/page.ts
62
+ var MAX_PER_PAGE = 100;
63
+
64
+ class Page {
65
+ data;
66
+ hasMore;
67
+ nextCursor;
68
+ response;
69
+ #fetcher;
70
+ constructor(response, fetcher) {
71
+ const body = response.body;
72
+ if (!body || !Array.isArray(body.data)) {
73
+ throw new ZazuArgumentError("Page response body has no `data` array — was this a list endpoint?", { body });
74
+ }
75
+ this.response = response;
76
+ this.data = body.data;
77
+ this.hasMore = Boolean(body.has_more);
78
+ this.nextCursor = body.next_cursor ?? null;
79
+ this.#fetcher = fetcher;
80
+ }
81
+ async next() {
82
+ if (!this.hasMore || !this.nextCursor)
83
+ return null;
84
+ return this.#fetcher(this.nextCursor);
85
+ }
86
+ async* records() {
87
+ let page = this;
88
+ while (page) {
89
+ for (const item of page.data)
90
+ yield item;
91
+ page = await page.next();
92
+ }
93
+ }
94
+ }
95
+
96
+ // src/resources/base.ts
97
+ class ResourceBase {
98
+ client;
99
+ constructor(client) {
100
+ this.client = client;
101
+ }
102
+ httpGet(path, params) {
103
+ return this.client.request("GET", path, { params });
104
+ }
105
+ httpPost(path, body) {
106
+ return this.client.request("POST", path, { body });
107
+ }
108
+ httpPatch(path, body) {
109
+ return this.client.request("PATCH", path, { body });
110
+ }
111
+ httpDelete(path) {
112
+ return this.client.request("DELETE", path);
113
+ }
114
+ async listPage(path, params = {}, listOpts = {}) {
115
+ const limit = this.validateLimit(listOpts.limit);
116
+ const fetcher = async (cursor) => {
117
+ const query = compactObject({ ...params, limit, cursor });
118
+ const response = await this.httpGet(path, query);
119
+ return new Page(response, fetcher);
120
+ };
121
+ return fetcher(listOpts.cursor ?? null);
122
+ }
123
+ validateLimit(limit) {
124
+ if (limit === undefined || limit === null)
125
+ return MAX_PER_PAGE;
126
+ if (!Number.isInteger(limit) || limit <= 0) {
127
+ throw new ZazuArgumentError(`limit must be a positive integer (got ${JSON.stringify(limit)})`);
128
+ }
129
+ if (limit > MAX_PER_PAGE) {
130
+ throw new ZazuArgumentError(`limit cannot exceed ${MAX_PER_PAGE} (got ${limit})`);
131
+ }
132
+ return limit;
133
+ }
134
+ encodePath(base, ...segments) {
135
+ const encoded = segments.map((s) => {
136
+ const str = String(s);
137
+ if (str.length === 0) {
138
+ throw new ZazuArgumentError("path segment cannot be blank");
139
+ }
140
+ return str.replace(/[^A-Za-z0-9._~-]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`);
141
+ });
142
+ return [base, ...encoded].join("/");
143
+ }
144
+ }
145
+ function compactObject(obj) {
146
+ const out = {};
147
+ for (const [k, v] of Object.entries(obj)) {
148
+ if (v === undefined || v === null)
149
+ continue;
150
+ out[k] = v;
151
+ }
152
+ return out;
153
+ }
154
+
155
+ // src/resources/accounts.ts
156
+ class Accounts extends ResourceBase {
157
+ list(params = {}) {
158
+ const { limit, cursor, ...rest } = params;
159
+ return this.listPage("api/accounts", rest, { limit, cursor });
160
+ }
161
+ get(id) {
162
+ return this.httpGet(this.encodePath("api/accounts", id));
163
+ }
164
+ listTransactions(accountId, params = {}) {
165
+ const { limit, cursor, posted_after, posted_before, ...rest } = params;
166
+ return this.listPage(this.encodePath("api/accounts", accountId, "transactions"), {
167
+ ...rest,
168
+ posted_after: serializeTime(posted_after),
169
+ posted_before: serializeTime(posted_before)
170
+ }, { limit, cursor });
171
+ }
172
+ getTransaction(accountId, transactionId) {
173
+ return this.httpGet(this.encodePath("api/accounts", accountId, "transactions", transactionId));
174
+ }
175
+ }
176
+ function serializeTime(value) {
177
+ if (value === undefined)
178
+ return;
179
+ if (typeof value === "string")
180
+ return value;
181
+ return value.toISOString();
182
+ }
183
+
184
+ // src/resources/beneficiaries.ts
185
+ class Beneficiaries extends ResourceBase {
186
+ list(params = {}) {
187
+ const { limit, cursor } = params;
188
+ return this.listPage("api/beneficiaries", {}, { limit, cursor });
189
+ }
190
+ get(id) {
191
+ return this.httpGet(this.encodePath("api/beneficiaries", id));
192
+ }
193
+ create(attributes) {
194
+ return this.httpPost("api/beneficiaries", attributes);
195
+ }
196
+ listExternalAccounts(beneficiaryId, params = {}) {
197
+ const { limit, cursor } = params;
198
+ return this.listPage(this.encodePath("api/beneficiaries", beneficiaryId, "external_accounts"), {}, { limit, cursor });
199
+ }
200
+ getExternalAccount(beneficiaryId, id) {
201
+ return this.httpGet(this.encodePath("api/beneficiaries", beneficiaryId, "external_accounts", id));
202
+ }
203
+ createExternalAccount(beneficiaryId, attributes) {
204
+ return this.httpPost(this.encodePath("api/beneficiaries", beneficiaryId, "external_accounts"), attributes);
205
+ }
206
+ }
207
+
208
+ // src/resources/checkout_sessions.ts
209
+ class CheckoutSessions extends ResourceBase {
210
+ get(id) {
211
+ return this.httpGet(this.encodePath("api/checkout_sessions", id));
212
+ }
213
+ create(attributes) {
214
+ return this.httpPost("api/checkout_sessions", attributes);
215
+ }
216
+ }
217
+
218
+ // src/resources/customers.ts
219
+ class Customers extends ResourceBase {
220
+ list(params = {}) {
221
+ const { limit, cursor, ...rest } = params;
222
+ return this.listPage("api/customers", rest, { limit, cursor });
223
+ }
224
+ get(id) {
225
+ return this.httpGet(this.encodePath("api/customers", id));
226
+ }
227
+ create(attributes) {
228
+ return this.httpPost("api/customers", attributes);
229
+ }
230
+ update(id, attributes) {
231
+ return this.httpPatch(this.encodePath("api/customers", id), attributes);
232
+ }
233
+ delete(id) {
234
+ return this.httpDelete(this.encodePath("api/customers", id));
235
+ }
236
+ }
237
+
238
+ // src/resources/entity.ts
239
+ class Entity extends ResourceBase {
240
+ get() {
241
+ return this.httpGet("api/entity");
242
+ }
243
+ }
244
+
245
+ // src/resources/invoices.ts
246
+ class Invoices extends ResourceBase {
247
+ list(params = {}) {
248
+ const { limit, cursor, ...rest } = params;
249
+ return this.listPage("api/invoices", rest, { limit, cursor });
250
+ }
251
+ get(id) {
252
+ return this.httpGet(this.encodePath("api/invoices", id));
253
+ }
254
+ create(attributes) {
255
+ return this.httpPost("api/invoices", attributes);
256
+ }
257
+ update(id, attributes) {
258
+ return this.httpPatch(this.encodePath("api/invoices", id), attributes);
259
+ }
260
+ delete(id) {
261
+ return this.httpDelete(this.encodePath("api/invoices", id));
262
+ }
263
+ send(id) {
264
+ return this.httpPost(this.encodePath("api/invoices", id, "send"));
265
+ }
266
+ markAsPaid(id, attributes = {}) {
267
+ return this.httpPost(this.encodePath("api/invoices", id, "mark_as_paid"), attributes);
268
+ }
269
+ cancel(id) {
270
+ return this.httpPost(this.encodePath("api/invoices", id, "cancel"));
271
+ }
272
+ creditNote(id, attributes = {}) {
273
+ return this.httpPost(this.encodePath("api/invoices", id, "credit_note"), attributes);
274
+ }
275
+ createPaymentLink(id, attributes = {}) {
276
+ return this.httpPost(this.encodePath("api/invoices", id, "payment_link"), attributes);
277
+ }
278
+ }
279
+
280
+ // src/resources/payee_trust_requests.ts
281
+ class PayeeTrustRequests extends ResourceBase {
282
+ create(params) {
283
+ return this.httpPost("api/payee_trust_requests", {
284
+ external_account_ids: params.external_account_ids
285
+ });
286
+ }
287
+ get(id) {
288
+ return this.httpGet(this.encodePath("api/payee_trust_requests", id));
289
+ }
290
+ }
291
+
292
+ // src/resources/payment_links.ts
293
+ class PaymentLinks extends ResourceBase {
294
+ list(params = {}) {
295
+ const { limit, cursor } = params;
296
+ return this.listPage("api/payment_links", {}, { limit, cursor });
297
+ }
298
+ get(id) {
299
+ return this.httpGet(this.encodePath("api/payment_links", id));
300
+ }
301
+ create(attributes) {
302
+ return this.httpPost("api/payment_links", attributes);
303
+ }
304
+ cancel(id) {
305
+ return this.httpPost(this.encodePath("api/payment_links", id, "cancel"));
306
+ }
307
+ }
308
+
309
+ // src/resources/transfer_drafts.ts
310
+ class TransferDrafts extends ResourceBase {
311
+ create(attributes) {
312
+ return this.httpPost("api/transfer_drafts", attributes);
313
+ }
314
+ get(id) {
315
+ return this.httpGet(this.encodePath("api/transfer_drafts", id));
316
+ }
317
+ authorize(id, params) {
318
+ if (!params.signature || params.signature.trim() === "") {
319
+ throw new ZazuArgumentError("signature cannot be blank");
320
+ }
321
+ return this.httpPost(this.encodePath("api/transfer_drafts", id, "authorize"), {
322
+ authorization_id: params.authorization_id,
323
+ signature: params.signature
324
+ });
325
+ }
326
+ decline(id, params) {
327
+ const body = { authorization_id: params.authorization_id };
328
+ if (params.reason !== undefined && params.reason !== null)
329
+ body.reason = params.reason;
330
+ return this.httpPost(this.encodePath("api/transfer_drafts", id, "decline"), body);
331
+ }
332
+ }
333
+
334
+ // src/resources/webhook_endpoints.ts
335
+ class WebhookEndpoints extends ResourceBase {
336
+ list(params = {}) {
337
+ const { limit, cursor } = params;
338
+ return this.listPage("api/webhook_endpoints", {}, { limit, cursor });
339
+ }
340
+ get(id) {
341
+ return this.httpGet(this.encodePath("api/webhook_endpoints", id));
342
+ }
343
+ create(params) {
344
+ return this.httpPost("api/webhook_endpoints", params);
345
+ }
346
+ update(id, attributes) {
347
+ return this.httpPatch(this.encodePath("api/webhook_endpoints", id), attributes);
348
+ }
349
+ delete(id) {
350
+ return this.httpDelete(this.encodePath("api/webhook_endpoints", id));
351
+ }
352
+ test(id) {
353
+ return this.httpPost(this.encodePath("api/webhook_endpoints", id, "test"));
354
+ }
355
+ regenerateSecret(id) {
356
+ return this.httpPost(this.encodePath("api/webhook_endpoints", id, "regenerate_secret"));
357
+ }
358
+ enable(id) {
359
+ return this.httpPost(this.encodePath("api/webhook_endpoints", id, "enable"));
360
+ }
361
+ disable(id) {
362
+ return this.httpPost(this.encodePath("api/webhook_endpoints", id, "disable"));
363
+ }
364
+ }
365
+
366
+ // src/response.ts
367
+ class ZazuResponse {
368
+ status;
369
+ headers;
370
+ body;
371
+ raw;
372
+ constructor(raw, body) {
373
+ this.raw = raw;
374
+ this.status = raw.status;
375
+ this.headers = raw.headers;
376
+ this.body = body;
377
+ }
378
+ get success() {
379
+ return this.status >= 200 && this.status < 300;
380
+ }
381
+ get requestId() {
382
+ return this.headers.get("x-request-id");
383
+ }
384
+ }
385
+
386
+ // src/version.ts
387
+ var VERSION = "0.3.0";
388
+
389
+ // src/client.ts
390
+ var DEFAULT_BASE_URL = "https://ma.manza.finance";
391
+ var DEFAULT_TIMEOUT_MS = 30000;
392
+ var USER_AGENT = `zazu-ts/${VERSION}`;
393
+
394
+ class Zazu {
395
+ apiKey;
396
+ baseUrl;
397
+ apiVersion;
398
+ timeoutMs;
399
+ #fetch;
400
+ accounts;
401
+ beneficiaries;
402
+ checkoutSessions;
403
+ customers;
404
+ entity;
405
+ invoices;
406
+ payeeTrustRequests;
407
+ paymentLinks;
408
+ transferDrafts;
409
+ webhookEndpoints;
410
+ constructor(options = {}) {
411
+ const apiKey = options.apiKey ?? readEnv("ZAZU_API_KEY");
412
+ if (!apiKey) {
413
+ throw new ZazuConfigurationError("Missing apiKey. Pass apiKey or set ZAZU_API_KEY.");
414
+ }
415
+ this.apiKey = apiKey;
416
+ this.baseUrl = (options.baseUrl ?? readEnv("ZAZU_BASE_URL") ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
417
+ this.apiVersion = options.apiVersion ?? readEnv("ZAZU_API_VERSION") ?? null;
418
+ this.timeoutMs = options.timeoutMs ?? (Number(readEnv("ZAZU_TIMEOUT_MS")) || DEFAULT_TIMEOUT_MS);
419
+ this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
420
+ this.accounts = new Accounts(this);
421
+ this.beneficiaries = new Beneficiaries(this);
422
+ this.checkoutSessions = new CheckoutSessions(this);
423
+ this.customers = new Customers(this);
424
+ this.entity = new Entity(this);
425
+ this.invoices = new Invoices(this);
426
+ this.payeeTrustRequests = new PayeeTrustRequests(this);
427
+ this.paymentLinks = new PaymentLinks(this);
428
+ this.transferDrafts = new TransferDrafts(this);
429
+ this.webhookEndpoints = new WebhookEndpoints(this);
430
+ }
431
+ async request(method, path, options = {}) {
432
+ const url = this.#buildUrl(path, options.params);
433
+ const headers = new Headers({
434
+ Authorization: `Bearer ${this.apiKey}`,
435
+ "User-Agent": USER_AGENT,
436
+ Accept: "application/json"
437
+ });
438
+ if (this.apiVersion)
439
+ headers.set("Zazu-Version", this.apiVersion);
440
+ if (options.headers) {
441
+ for (const [k, v] of Object.entries(options.headers))
442
+ headers.set(k, v);
443
+ }
444
+ const init = { method: method.toUpperCase(), headers };
445
+ if (options.body !== undefined && options.body !== null) {
446
+ headers.set("Content-Type", "application/json");
447
+ init.body = JSON.stringify(options.body);
448
+ }
449
+ const controller = new AbortController;
450
+ const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
451
+ init.signal = controller.signal;
452
+ let raw;
453
+ try {
454
+ raw = await this.#fetch(url, init);
455
+ } catch (err) {
456
+ if (err instanceof Error && err.name === "AbortError") {
457
+ throw new ZazuConnectionError(`Request timed out after ${this.timeoutMs}ms`);
458
+ }
459
+ throw new ZazuConnectionError(`Connection failed: ${err instanceof Error ? err.message : String(err)}`);
460
+ } finally {
461
+ clearTimeout(timeout);
462
+ }
463
+ const body = await parseBody(raw);
464
+ const response = new ZazuResponse(raw, body);
465
+ if (response.success)
466
+ return response;
467
+ throw buildError(response);
468
+ }
469
+ #buildUrl(path, params) {
470
+ const trimmed = path.replace(/^\/+/, "");
471
+ const url = new URL(`${this.baseUrl}/${trimmed}`);
472
+ if (params) {
473
+ for (const [k, v] of Object.entries(params)) {
474
+ if (v === undefined || v === null)
475
+ continue;
476
+ url.searchParams.set(k, String(v));
477
+ }
478
+ }
479
+ return url.toString();
480
+ }
481
+ }
482
+ async function parseBody(raw) {
483
+ const ct = raw.headers.get("content-type") ?? "";
484
+ if (!ct.includes("json"))
485
+ return;
486
+ const text = await raw.text();
487
+ if (!text)
488
+ return;
489
+ try {
490
+ return JSON.parse(text);
491
+ } catch {
492
+ return text;
493
+ }
494
+ }
495
+ function errorPayload(body) {
496
+ if (!body || typeof body !== "object")
497
+ return {};
498
+ const e = body.error;
499
+ if (!e || typeof e !== "object")
500
+ return {};
501
+ return e;
502
+ }
503
+ function buildError(response) {
504
+ const payload = errorPayload(response.body);
505
+ const message = payload.message;
506
+ const opts = {
507
+ status: response.status,
508
+ requestId: response.requestId,
509
+ type: payload.type ?? null,
510
+ param: payload.param ?? null,
511
+ body: response.body,
512
+ headers: response.headers
513
+ };
514
+ switch (response.status) {
515
+ case 400:
516
+ return new ZazuValidationError(message ?? "Bad request", opts);
517
+ case 401:
518
+ return new ZazuAuthenticationError(message ?? "Authentication failed", opts);
519
+ case 403:
520
+ return new ZazuForbiddenError(message ?? "Forbidden", opts);
521
+ case 404:
522
+ return new ZazuNotFoundError(message ?? "Not found", opts);
523
+ case 409:
524
+ return new ZazuConflictError(message ?? "Conflict", {
525
+ ...opts,
526
+ paymentId: payload.payment_id ?? null
527
+ });
528
+ case 422:
529
+ return new ZazuValidationError(message ?? "Validation failed", opts);
530
+ case 429: {
531
+ const retryAfter = Number(response.headers.get("retry-after"));
532
+ return new ZazuRateLimitError(message ?? "Rate limited", {
533
+ ...opts,
534
+ retryAfter: Number.isFinite(retryAfter) ? retryAfter : null
535
+ });
536
+ }
537
+ }
538
+ if (response.status >= 500 && response.status < 600) {
539
+ return new ZazuServerError(message ?? `Server error (${response.status})`, opts);
540
+ }
541
+ return new ZazuError(message ?? `Unexpected status ${response.status}`, opts);
542
+ }
543
+ function readEnv(name) {
544
+ if (typeof process !== "undefined" && process.env)
545
+ return process.env[name];
546
+ return;
547
+ }
548
+ // src/transfer_authorization.ts
549
+ var SIGNATURE_VERSION = "manza.transfer-authorization.v1";
550
+ function signatureInput(fields) {
551
+ if (typeof fields.amount !== "string") {
552
+ throw new ZazuArgumentError(`amount must be the API's decimal string (got ${JSON.stringify(fields.amount)})`);
553
+ }
554
+ return [
555
+ SIGNATURE_VERSION,
556
+ fields.payment_id,
557
+ fields.nonce,
558
+ fields.amount,
559
+ fields.currency_code,
560
+ fields.account_id,
561
+ fields.payee,
562
+ fields.client_reference ?? ""
563
+ ].join("|");
564
+ }
565
+ async function sign(params) {
566
+ const encoder = new TextEncoder;
567
+ const key = await crypto.subtle.importKey("raw", encoder.encode(params.secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
568
+ const sig = await crypto.subtle.sign("HMAC", key, encoder.encode(params.signature_input));
569
+ return [...new Uint8Array(sig)].map((b) => b.toString(16).padStart(2, "0")).join("");
570
+ }
571
+ function payeeFor(params) {
572
+ const ext = params.external_account_id ?? null;
573
+ const own = params.destination_account_id ?? null;
574
+ if (ext === null === (own === null)) {
575
+ throw new ZazuArgumentError("pass exactly one of external_account_id or destination_account_id");
576
+ }
577
+ return own !== null ? `own:${own}` : `ext:${ext}`;
578
+ }
579
+ var TransferAuthorization = {
580
+ SIGNATURE_VERSION,
581
+ signatureInput,
582
+ sign,
583
+ payeeFor
584
+ };
585
+ export {
586
+ Accounts,
587
+ Beneficiaries,
588
+ CheckoutSessions,
589
+ Customers,
590
+ Entity,
591
+ Invoices,
592
+ MAX_PER_PAGE,
593
+ Page,
594
+ PayeeTrustRequests,
595
+ PaymentLinks,
596
+ TransferAuthorization,
597
+ TransferDrafts,
598
+ VERSION,
599
+ WebhookEndpoints,
600
+ Zazu,
601
+ ZazuArgumentError,
602
+ ZazuAuthenticationError,
603
+ ZazuConfigurationError,
604
+ ZazuConflictError,
605
+ ZazuConnectionError,
606
+ ZazuError,
607
+ ZazuForbiddenError,
608
+ ZazuNotFoundError,
609
+ ZazuRateLimitError,
610
+ ZazuResponse,
611
+ ZazuServerError,
612
+ ZazuValidationError
613
+ };
package/dist/page.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { ZazuResponse } from "./response.js";
2
+ export declare const MAX_PER_PAGE = 100;
3
+ export interface PageBody<T> {
4
+ data: T[];
5
+ has_more: boolean;
6
+ next_cursor: string | null;
7
+ }
8
+ export type PageFetcher<T> = (cursor: string | null) => Promise<Page<T>>;
9
+ export declare class Page<T> {
10
+ #private;
11
+ readonly data: T[];
12
+ readonly hasMore: boolean;
13
+ readonly nextCursor: string | null;
14
+ readonly response: ZazuResponse<PageBody<T>>;
15
+ constructor(response: ZazuResponse<PageBody<T>>, fetcher: PageFetcher<T>);
16
+ next(): Promise<Page<T> | null>;
17
+ records(): AsyncIterableIterator<T>;
18
+ }
19
+ //# sourceMappingURL=page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzE,qBAAa,IAAI,CAAC,CAAC;;IACjB,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;IACnB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;gBAGjC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IAelE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAM9B,OAAO,IAAI,qBAAqB,CAAC,CAAC,CAAC;CAQ3C"}
@@ -0,0 +1,19 @@
1
+ import type { Page } from "../page.js";
2
+ import type { ZazuResponse } from "../response.js";
3
+ import { type ListParams, ResourceBase } from "./base.js";
4
+ export interface AccountListParams extends ListParams {
5
+ status?: string;
6
+ currency_code?: string;
7
+ }
8
+ export interface TransactionListParams extends ListParams {
9
+ operation?: string;
10
+ posted_after?: string | Date;
11
+ posted_before?: string | Date;
12
+ }
13
+ export declare class Accounts extends ResourceBase {
14
+ list(params?: AccountListParams): Promise<Page<unknown>>;
15
+ get(id: string): Promise<ZazuResponse>;
16
+ listTransactions(accountId: string, params?: TransactionListParams): Promise<Page<unknown>>;
17
+ getTransaction(accountId: string, transactionId: string): Promise<ZazuResponse>;
18
+ }
19
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/resources/accounts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,KAAK,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE1D,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,qBAAsB,SAAQ,UAAU;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,qBAAa,QAAS,SAAQ,YAAY;IACxC,IAAI,CAAC,MAAM,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAK5D,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAItC,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,qBAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAa/F,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAGhF"}
@@ -0,0 +1,19 @@
1
+ import type { Zazu } from "../client.js";
2
+ import { Page } from "../page.js";
3
+ import type { ZazuResponse } from "../response.js";
4
+ export interface ListParams {
5
+ limit?: number | undefined;
6
+ cursor?: string | null | undefined;
7
+ }
8
+ export declare abstract class ResourceBase {
9
+ protected readonly client: Zazu;
10
+ constructor(client: Zazu);
11
+ protected httpGet<T>(path: string, params?: Record<string, unknown>): Promise<ZazuResponse<T>>;
12
+ protected httpPost<T>(path: string, body?: unknown): Promise<ZazuResponse<T>>;
13
+ protected httpPatch<T>(path: string, body?: unknown): Promise<ZazuResponse<T>>;
14
+ protected httpDelete<T>(path: string): Promise<ZazuResponse<T>>;
15
+ protected listPage<T>(path: string, params?: Record<string, unknown>, listOpts?: ListParams): Promise<Page<T>>;
16
+ protected validateLimit(limit: number | undefined): number;
17
+ protected encodePath(base: string, ...segments: string[]): string;
18
+ }
19
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/resources/base.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAgB,IAAI,EAAiB,MAAM,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACpC;AAED,8BAAsB,YAAY;IAChC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;gBAEpB,MAAM,EAAE,IAAI;IAIxB,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAI9F,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAI7E,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAI9E,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;cAI/C,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,QAAQ,GAAE,UAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAYnB,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM;IAiB1D,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM;CAalE"}
@@ -0,0 +1,12 @@
1
+ import type { Page } from "../page.js";
2
+ import type { ZazuResponse } from "../response.js";
3
+ import { type ListParams, ResourceBase } from "./base.js";
4
+ export declare class Beneficiaries extends ResourceBase {
5
+ list(params?: ListParams): Promise<Page<unknown>>;
6
+ get(id: string): Promise<ZazuResponse>;
7
+ create(attributes: Record<string, unknown>): Promise<ZazuResponse>;
8
+ listExternalAccounts(beneficiaryId: string, params?: ListParams): Promise<Page<unknown>>;
9
+ getExternalAccount(beneficiaryId: string, id: string): Promise<ZazuResponse>;
10
+ createExternalAccount(beneficiaryId: string, attributes: Record<string, unknown>): Promise<ZazuResponse>;
11
+ }
12
+ //# sourceMappingURL=beneficiaries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beneficiaries.d.ts","sourceRoot":"","sources":["../../src/resources/beneficiaries.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,KAAK,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE1D,qBAAa,aAAc,SAAQ,YAAY;IAC7C,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAKrD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAQtC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IAIlE,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAS5F,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAS5E,qBAAqB,CACnB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,YAAY,CAAC;CAMzB"}