@getmanza/sdk 1.0.0 → 1.1.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.
- package/CHANGELOG.md +57 -0
- package/README.md +74 -18
- package/dist/client.d.ts +14 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/env.d.ts +3 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/errors.d.ts +15 -15
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.cjs +203 -66
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +203 -66
- package/dist/page.d.ts +3 -3
- package/dist/page.d.ts.map +1 -1
- package/dist/resources/accounts.d.ts +3 -3
- package/dist/resources/accounts.d.ts.map +1 -1
- package/dist/resources/base.d.ts +8 -8
- package/dist/resources/base.d.ts.map +1 -1
- package/dist/resources/beneficiaries.d.ts +5 -5
- package/dist/resources/beneficiaries.d.ts.map +1 -1
- package/dist/resources/checkout_sessions.d.ts +3 -3
- package/dist/resources/checkout_sessions.d.ts.map +1 -1
- package/dist/resources/customers.d.ts +5 -5
- package/dist/resources/customers.d.ts.map +1 -1
- package/dist/resources/entity.d.ts +2 -2
- package/dist/resources/entity.d.ts.map +1 -1
- package/dist/resources/invoices.d.ts +10 -10
- package/dist/resources/invoices.d.ts.map +1 -1
- package/dist/resources/payee_trust_requests.d.ts +3 -3
- package/dist/resources/payee_trust_requests.d.ts.map +1 -1
- package/dist/resources/payment_links.d.ts +4 -4
- package/dist/resources/payment_links.d.ts.map +1 -1
- package/dist/resources/payments.d.ts +15 -0
- package/dist/resources/payments.d.ts.map +1 -0
- package/dist/resources/transfer_authorizer.d.ts +6 -0
- package/dist/resources/transfer_authorizer.d.ts.map +1 -0
- package/dist/resources/transfer_drafts.d.ts +8 -14
- package/dist/resources/transfer_drafts.d.ts.map +1 -1
- package/dist/resources/webhook_endpoints.d.ts +9 -9
- package/dist/resources/webhook_endpoints.d.ts.map +1 -1
- package/dist/response.d.ts +1 -1
- package/dist/response.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/webhook.d.ts +32 -0
- package/dist/webhook.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -46,31 +46,57 @@ __export(exports_src, {
|
|
|
46
46
|
Entity: () => Entity,
|
|
47
47
|
Invoices: () => Invoices,
|
|
48
48
|
MAX_PER_PAGE: () => MAX_PER_PAGE,
|
|
49
|
+
Manza: () => Manza,
|
|
50
|
+
ManzaArgumentError: () => ManzaArgumentError,
|
|
51
|
+
ManzaAuthenticationError: () => ManzaAuthenticationError,
|
|
52
|
+
ManzaConfigurationError: () => ManzaConfigurationError,
|
|
53
|
+
ManzaConflictError: () => ManzaConflictError,
|
|
54
|
+
ManzaConnectionError: () => ManzaConnectionError,
|
|
55
|
+
ManzaError: () => ManzaError,
|
|
56
|
+
ManzaForbiddenError: () => ManzaForbiddenError,
|
|
57
|
+
ManzaNotFoundError: () => ManzaNotFoundError,
|
|
58
|
+
ManzaRateLimitError: () => ManzaRateLimitError,
|
|
59
|
+
ManzaResponse: () => ManzaResponse,
|
|
60
|
+
ManzaServerError: () => ManzaServerError,
|
|
61
|
+
ManzaValidationError: () => ManzaValidationError,
|
|
49
62
|
Page: () => Page,
|
|
50
63
|
PayeeTrustRequests: () => PayeeTrustRequests,
|
|
51
64
|
PaymentLinks: () => PaymentLinks,
|
|
65
|
+
Payments: () => Payments,
|
|
52
66
|
TransferAuthorization: () => TransferAuthorization,
|
|
67
|
+
TransferAuthorizer: () => TransferAuthorizer,
|
|
53
68
|
TransferDrafts: () => TransferDrafts,
|
|
54
69
|
VERSION: () => VERSION,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
ZazuArgumentError: () => ZazuArgumentError,
|
|
58
|
-
ZazuAuthenticationError: () => ZazuAuthenticationError,
|
|
59
|
-
ZazuConfigurationError: () => ZazuConfigurationError,
|
|
60
|
-
ZazuConflictError: () => ZazuConflictError,
|
|
61
|
-
ZazuConnectionError: () => ZazuConnectionError,
|
|
62
|
-
ZazuError: () => ZazuError,
|
|
63
|
-
ZazuForbiddenError: () => ZazuForbiddenError,
|
|
64
|
-
ZazuNotFoundError: () => ZazuNotFoundError,
|
|
65
|
-
ZazuRateLimitError: () => ZazuRateLimitError,
|
|
66
|
-
ZazuResponse: () => ZazuResponse,
|
|
67
|
-
ZazuServerError: () => ZazuServerError,
|
|
68
|
-
ZazuValidationError: () => ZazuValidationError
|
|
70
|
+
Webhook: () => Webhook,
|
|
71
|
+
WebhookEndpoints: () => WebhookEndpoints
|
|
69
72
|
});
|
|
70
73
|
module.exports = __toCommonJS(exports_src);
|
|
71
74
|
|
|
75
|
+
// src/env.ts
|
|
76
|
+
var WARNED = Symbol.for("@getmanza/sdk.warnedLegacyEnv");
|
|
77
|
+
var store = globalThis;
|
|
78
|
+
store[WARNED] ??= new Set;
|
|
79
|
+
var warned = store[WARNED];
|
|
80
|
+
function rawEnv(name) {
|
|
81
|
+
if (typeof process !== "undefined" && process.env)
|
|
82
|
+
return process.env[name];
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
function readEnv(name) {
|
|
86
|
+
const value = rawEnv(`MANZA_${name}`);
|
|
87
|
+
if (value !== undefined)
|
|
88
|
+
return value;
|
|
89
|
+
const legacy = `ZAZU_${name}`;
|
|
90
|
+
const legacyValue = rawEnv(legacy);
|
|
91
|
+
if (legacyValue !== undefined && !warned.has(legacy)) {
|
|
92
|
+
warned.add(legacy);
|
|
93
|
+
console.warn(`[manza] ${legacy} is deprecated and will be removed in 2.0. Use MANZA_${name} instead.`);
|
|
94
|
+
}
|
|
95
|
+
return legacyValue;
|
|
96
|
+
}
|
|
97
|
+
|
|
72
98
|
// src/errors.ts
|
|
73
|
-
class
|
|
99
|
+
class ManzaError extends Error {
|
|
74
100
|
status;
|
|
75
101
|
requestId;
|
|
76
102
|
type;
|
|
@@ -89,25 +115,25 @@ class ZazuError extends Error {
|
|
|
89
115
|
}
|
|
90
116
|
}
|
|
91
117
|
|
|
92
|
-
class
|
|
118
|
+
class ManzaConfigurationError extends ManzaError {
|
|
93
119
|
}
|
|
94
120
|
|
|
95
|
-
class
|
|
121
|
+
class ManzaConnectionError extends ManzaError {
|
|
96
122
|
}
|
|
97
123
|
|
|
98
|
-
class
|
|
124
|
+
class ManzaAuthenticationError extends ManzaError {
|
|
99
125
|
}
|
|
100
126
|
|
|
101
|
-
class
|
|
127
|
+
class ManzaForbiddenError extends ManzaError {
|
|
102
128
|
}
|
|
103
129
|
|
|
104
|
-
class
|
|
130
|
+
class ManzaNotFoundError extends ManzaError {
|
|
105
131
|
}
|
|
106
132
|
|
|
107
|
-
class
|
|
133
|
+
class ManzaValidationError extends ManzaError {
|
|
108
134
|
}
|
|
109
135
|
|
|
110
|
-
class
|
|
136
|
+
class ManzaRateLimitError extends ManzaError {
|
|
111
137
|
retryAfter;
|
|
112
138
|
constructor(message, options = {}) {
|
|
113
139
|
super(message, options);
|
|
@@ -115,13 +141,13 @@ class ZazuRateLimitError extends ZazuError {
|
|
|
115
141
|
}
|
|
116
142
|
}
|
|
117
143
|
|
|
118
|
-
class
|
|
144
|
+
class ManzaServerError extends ManzaError {
|
|
119
145
|
}
|
|
120
146
|
|
|
121
|
-
class
|
|
147
|
+
class ManzaArgumentError extends ManzaError {
|
|
122
148
|
}
|
|
123
149
|
|
|
124
|
-
class
|
|
150
|
+
class ManzaConflictError extends ManzaError {
|
|
125
151
|
paymentId;
|
|
126
152
|
constructor(message, options = {}) {
|
|
127
153
|
super(message, options);
|
|
@@ -141,7 +167,7 @@ class Page {
|
|
|
141
167
|
constructor(response, fetcher) {
|
|
142
168
|
const body = response.body;
|
|
143
169
|
if (!body || !Array.isArray(body.data)) {
|
|
144
|
-
throw new
|
|
170
|
+
throw new ManzaArgumentError("Page response body has no `data` array — was this a list endpoint?", { body });
|
|
145
171
|
}
|
|
146
172
|
this.response = response;
|
|
147
173
|
this.data = body.data;
|
|
@@ -195,10 +221,10 @@ class ResourceBase {
|
|
|
195
221
|
if (limit === undefined || limit === null)
|
|
196
222
|
return MAX_PER_PAGE;
|
|
197
223
|
if (!Number.isInteger(limit) || limit <= 0) {
|
|
198
|
-
throw new
|
|
224
|
+
throw new ManzaArgumentError(`limit must be a positive integer (got ${JSON.stringify(limit)})`);
|
|
199
225
|
}
|
|
200
226
|
if (limit > MAX_PER_PAGE) {
|
|
201
|
-
throw new
|
|
227
|
+
throw new ManzaArgumentError(`limit cannot exceed ${MAX_PER_PAGE} (got ${limit})`);
|
|
202
228
|
}
|
|
203
229
|
return limit;
|
|
204
230
|
}
|
|
@@ -206,7 +232,7 @@ class ResourceBase {
|
|
|
206
232
|
const encoded = segments.map((s) => {
|
|
207
233
|
const str = String(s);
|
|
208
234
|
if (str.length === 0) {
|
|
209
|
-
throw new
|
|
235
|
+
throw new ManzaArgumentError("path segment cannot be blank");
|
|
210
236
|
}
|
|
211
237
|
return str.replace(/[^A-Za-z0-9._~-]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`);
|
|
212
238
|
});
|
|
@@ -377,19 +403,19 @@ class PaymentLinks extends ResourceBase {
|
|
|
377
403
|
}
|
|
378
404
|
}
|
|
379
405
|
|
|
380
|
-
// src/resources/
|
|
381
|
-
class
|
|
406
|
+
// src/resources/payments.ts
|
|
407
|
+
class Payments extends ResourceBase {
|
|
382
408
|
create(attributes) {
|
|
383
|
-
return this.httpPost("api/
|
|
409
|
+
return this.httpPost("api/payments", attributes);
|
|
384
410
|
}
|
|
385
411
|
get(id) {
|
|
386
|
-
return this.httpGet(this.encodePath("api/
|
|
412
|
+
return this.httpGet(this.encodePath("api/payments", id));
|
|
387
413
|
}
|
|
388
414
|
authorize(id, params) {
|
|
389
415
|
if (!params.signature || params.signature.trim() === "") {
|
|
390
|
-
throw new
|
|
416
|
+
throw new ManzaArgumentError("signature cannot be blank");
|
|
391
417
|
}
|
|
392
|
-
return this.httpPost(this.encodePath("api/
|
|
418
|
+
return this.httpPost(this.encodePath("api/payments", id, "authorize"), {
|
|
393
419
|
authorization_id: params.authorization_id,
|
|
394
420
|
signature: params.signature
|
|
395
421
|
});
|
|
@@ -398,7 +424,14 @@ class TransferDrafts extends ResourceBase {
|
|
|
398
424
|
const body = { authorization_id: params.authorization_id };
|
|
399
425
|
if (params.reason !== undefined && params.reason !== null)
|
|
400
426
|
body.reason = params.reason;
|
|
401
|
-
return this.httpPost(this.encodePath("api/
|
|
427
|
+
return this.httpPost(this.encodePath("api/payments", id, "decline"), body);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/resources/transfer_authorizer.ts
|
|
432
|
+
class TransferAuthorizer extends ResourceBase {
|
|
433
|
+
get() {
|
|
434
|
+
return this.httpGet("api/transfer_authorizer");
|
|
402
435
|
}
|
|
403
436
|
}
|
|
404
437
|
|
|
@@ -435,7 +468,7 @@ class WebhookEndpoints extends ResourceBase {
|
|
|
435
468
|
}
|
|
436
469
|
|
|
437
470
|
// src/response.ts
|
|
438
|
-
class
|
|
471
|
+
class ManzaResponse {
|
|
439
472
|
status;
|
|
440
473
|
headers;
|
|
441
474
|
body;
|
|
@@ -455,14 +488,14 @@ class ZazuResponse {
|
|
|
455
488
|
}
|
|
456
489
|
|
|
457
490
|
// src/version.ts
|
|
458
|
-
var VERSION = "
|
|
491
|
+
var VERSION = "1.1.0";
|
|
459
492
|
|
|
460
493
|
// src/client.ts
|
|
461
494
|
var DEFAULT_BASE_URL = "https://ma.manza.finance";
|
|
462
495
|
var DEFAULT_TIMEOUT_MS = 30000;
|
|
463
|
-
var USER_AGENT = `
|
|
496
|
+
var USER_AGENT = `manza-ts/${VERSION}`;
|
|
464
497
|
|
|
465
|
-
class
|
|
498
|
+
class Manza {
|
|
466
499
|
apiKey;
|
|
467
500
|
baseUrl;
|
|
468
501
|
apiVersion;
|
|
@@ -476,17 +509,19 @@ class Zazu {
|
|
|
476
509
|
invoices;
|
|
477
510
|
payeeTrustRequests;
|
|
478
511
|
paymentLinks;
|
|
512
|
+
payments;
|
|
513
|
+
transferAuthorizer;
|
|
479
514
|
transferDrafts;
|
|
480
515
|
webhookEndpoints;
|
|
481
516
|
constructor(options = {}) {
|
|
482
|
-
const apiKey = options.apiKey ?? readEnv("
|
|
517
|
+
const apiKey = options.apiKey ?? readEnv("API_KEY");
|
|
483
518
|
if (!apiKey) {
|
|
484
|
-
throw new
|
|
519
|
+
throw new ManzaConfigurationError("Missing apiKey. Pass apiKey or set MANZA_API_KEY.");
|
|
485
520
|
}
|
|
486
521
|
this.apiKey = apiKey;
|
|
487
|
-
this.baseUrl = (options.baseUrl ?? readEnv("
|
|
488
|
-
this.apiVersion = options.apiVersion ?? readEnv("
|
|
489
|
-
this.timeoutMs = options.timeoutMs ?? (Number(readEnv("
|
|
522
|
+
this.baseUrl = (options.baseUrl ?? readEnv("BASE_URL") ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
523
|
+
this.apiVersion = options.apiVersion ?? readEnv("API_VERSION") ?? null;
|
|
524
|
+
this.timeoutMs = options.timeoutMs ?? (Number(readEnv("TIMEOUT_MS")) || DEFAULT_TIMEOUT_MS);
|
|
490
525
|
this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
491
526
|
this.accounts = new Accounts(this);
|
|
492
527
|
this.beneficiaries = new Beneficiaries(this);
|
|
@@ -496,7 +531,9 @@ class Zazu {
|
|
|
496
531
|
this.invoices = new Invoices(this);
|
|
497
532
|
this.payeeTrustRequests = new PayeeTrustRequests(this);
|
|
498
533
|
this.paymentLinks = new PaymentLinks(this);
|
|
499
|
-
this.
|
|
534
|
+
this.payments = new Payments(this);
|
|
535
|
+
this.transferAuthorizer = new TransferAuthorizer(this);
|
|
536
|
+
this.transferDrafts = this.payments;
|
|
500
537
|
this.webhookEndpoints = new WebhookEndpoints(this);
|
|
501
538
|
}
|
|
502
539
|
async request(method, path, options = {}) {
|
|
@@ -507,7 +544,7 @@ class Zazu {
|
|
|
507
544
|
Accept: "application/json"
|
|
508
545
|
});
|
|
509
546
|
if (this.apiVersion)
|
|
510
|
-
headers.set("
|
|
547
|
+
headers.set("Manza-Version", this.apiVersion);
|
|
511
548
|
if (options.headers) {
|
|
512
549
|
for (const [k, v] of Object.entries(options.headers))
|
|
513
550
|
headers.set(k, v);
|
|
@@ -525,14 +562,14 @@ class Zazu {
|
|
|
525
562
|
raw = await this.#fetch(url, init);
|
|
526
563
|
} catch (err) {
|
|
527
564
|
if (err instanceof Error && err.name === "AbortError") {
|
|
528
|
-
throw new
|
|
565
|
+
throw new ManzaConnectionError(`Request timed out after ${this.timeoutMs}ms`);
|
|
529
566
|
}
|
|
530
|
-
throw new
|
|
567
|
+
throw new ManzaConnectionError(`Connection failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
531
568
|
} finally {
|
|
532
569
|
clearTimeout(timeout);
|
|
533
570
|
}
|
|
534
571
|
const body = await parseBody(raw);
|
|
535
|
-
const response = new
|
|
572
|
+
const response = new ManzaResponse(raw, body);
|
|
536
573
|
if (response.success)
|
|
537
574
|
return response;
|
|
538
575
|
throw buildError(response);
|
|
@@ -584,43 +621,40 @@ function buildError(response) {
|
|
|
584
621
|
};
|
|
585
622
|
switch (response.status) {
|
|
586
623
|
case 400:
|
|
587
|
-
return new
|
|
624
|
+
return new ManzaValidationError(message ?? "Bad request", opts);
|
|
588
625
|
case 401:
|
|
589
|
-
return new
|
|
626
|
+
return new ManzaAuthenticationError(message ?? "Authentication failed", opts);
|
|
590
627
|
case 403:
|
|
591
|
-
return new
|
|
628
|
+
return new ManzaForbiddenError(message ?? "Forbidden", opts);
|
|
592
629
|
case 404:
|
|
593
|
-
return new
|
|
630
|
+
return new ManzaNotFoundError(message ?? "Not found", opts);
|
|
594
631
|
case 409:
|
|
595
|
-
return new
|
|
632
|
+
return new ManzaConflictError(message ?? "Conflict", {
|
|
596
633
|
...opts,
|
|
597
634
|
paymentId: payload.payment_id ?? null
|
|
598
635
|
});
|
|
599
636
|
case 422:
|
|
600
|
-
return new
|
|
637
|
+
return new ManzaValidationError(message ?? "Validation failed", opts);
|
|
601
638
|
case 429: {
|
|
602
639
|
const retryAfter = Number(response.headers.get("retry-after"));
|
|
603
|
-
return new
|
|
640
|
+
return new ManzaRateLimitError(message ?? "Rate limited", {
|
|
604
641
|
...opts,
|
|
605
642
|
retryAfter: Number.isFinite(retryAfter) ? retryAfter : null
|
|
606
643
|
});
|
|
607
644
|
}
|
|
608
645
|
}
|
|
609
646
|
if (response.status >= 500 && response.status < 600) {
|
|
610
|
-
return new
|
|
647
|
+
return new ManzaServerError(message ?? `Server error (${response.status})`, opts);
|
|
611
648
|
}
|
|
612
|
-
return new
|
|
613
|
-
}
|
|
614
|
-
function readEnv(name) {
|
|
615
|
-
if (typeof process !== "undefined" && process.env)
|
|
616
|
-
return process.env[name];
|
|
617
|
-
return;
|
|
649
|
+
return new ManzaError(message ?? `Unexpected status ${response.status}`, opts);
|
|
618
650
|
}
|
|
651
|
+
// src/resources/transfer_drafts.ts
|
|
652
|
+
var TransferDrafts = Payments;
|
|
619
653
|
// src/transfer_authorization.ts
|
|
620
654
|
var SIGNATURE_VERSION = "manza.transfer-authorization.v1";
|
|
621
655
|
function signatureInput(fields) {
|
|
622
656
|
if (typeof fields.amount !== "string") {
|
|
623
|
-
throw new
|
|
657
|
+
throw new ManzaArgumentError(`amount must be the API's decimal string (got ${JSON.stringify(fields.amount)})`);
|
|
624
658
|
}
|
|
625
659
|
return [
|
|
626
660
|
SIGNATURE_VERSION,
|
|
@@ -643,7 +677,7 @@ function payeeFor(params) {
|
|
|
643
677
|
const ext = params.external_account_id ?? null;
|
|
644
678
|
const own = params.destination_account_id ?? null;
|
|
645
679
|
if (ext === null === (own === null)) {
|
|
646
|
-
throw new
|
|
680
|
+
throw new ManzaArgumentError("pass exactly one of external_account_id or destination_account_id");
|
|
647
681
|
}
|
|
648
682
|
return own !== null ? `own:${own}` : `ext:${ext}`;
|
|
649
683
|
}
|
|
@@ -653,3 +687,106 @@ var TransferAuthorization = {
|
|
|
653
687
|
sign,
|
|
654
688
|
payeeFor
|
|
655
689
|
};
|
|
690
|
+
// src/webhook.ts
|
|
691
|
+
var DEFAULT_TOLERANCE = 300;
|
|
692
|
+
function sign2(params) {
|
|
693
|
+
if (params.secret === "") {
|
|
694
|
+
return Promise.reject(new ManzaArgumentError("secret cannot be empty"));
|
|
695
|
+
}
|
|
696
|
+
return sign({
|
|
697
|
+
secret: params.secret,
|
|
698
|
+
signature_input: `${params.timestamp}.${params.payload}`
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
async function verify(params) {
|
|
702
|
+
return await signatureMatches(params.payload, params.signature, params.timestamp, params.secret) && timestampFresh(params.timestamp, params.tolerance, params.now);
|
|
703
|
+
}
|
|
704
|
+
async function constructEvent(params) {
|
|
705
|
+
const normalized = normalizeHeaders(params.headers);
|
|
706
|
+
const signature = header(normalized, "signature");
|
|
707
|
+
const timestamp = header(normalized, "timestamp");
|
|
708
|
+
if (!await signatureMatches(params.payload, signature, timestamp, params.secret)) {
|
|
709
|
+
throw new ManzaArgumentError("invalid webhook signature");
|
|
710
|
+
}
|
|
711
|
+
if (!timestampFresh(timestamp, params.tolerance, params.now)) {
|
|
712
|
+
throw new ManzaArgumentError("webhook timestamp outside tolerance");
|
|
713
|
+
}
|
|
714
|
+
let event;
|
|
715
|
+
try {
|
|
716
|
+
event = JSON.parse(params.payload);
|
|
717
|
+
} catch {
|
|
718
|
+
throw new ManzaArgumentError("webhook payload is not JSON");
|
|
719
|
+
}
|
|
720
|
+
if (event === null || typeof event !== "object" || Array.isArray(event)) {
|
|
721
|
+
throw new ManzaArgumentError("webhook payload is not a JSON object");
|
|
722
|
+
}
|
|
723
|
+
return event;
|
|
724
|
+
}
|
|
725
|
+
async function signatureMatches(payload, signature, timestamp, secret) {
|
|
726
|
+
if (typeof payload !== "string" || typeof secret !== "string" || secret === "")
|
|
727
|
+
return false;
|
|
728
|
+
if (typeof signature !== "string")
|
|
729
|
+
return false;
|
|
730
|
+
if (typeof timestamp !== "string" && typeof timestamp !== "number")
|
|
731
|
+
return false;
|
|
732
|
+
if (parseTimestamp(timestamp) === null)
|
|
733
|
+
return false;
|
|
734
|
+
const expected = await sign2({ payload, timestamp, secret });
|
|
735
|
+
return constantTimeEqual(expected, signature);
|
|
736
|
+
}
|
|
737
|
+
function constantTimeEqual(a, b) {
|
|
738
|
+
if (a.length !== b.length)
|
|
739
|
+
return false;
|
|
740
|
+
let diff = 0;
|
|
741
|
+
for (let i = 0;i < a.length; i++)
|
|
742
|
+
diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
743
|
+
return diff === 0;
|
|
744
|
+
}
|
|
745
|
+
function timestampFresh(timestamp, tolerance, now) {
|
|
746
|
+
if (tolerance === null)
|
|
747
|
+
return true;
|
|
748
|
+
const seconds = parseTimestamp(timestamp);
|
|
749
|
+
if (seconds === null)
|
|
750
|
+
return false;
|
|
751
|
+
const nowSeconds = Math.floor((now ?? new Date).getTime() / 1000);
|
|
752
|
+
return Math.abs(nowSeconds - seconds) <= (tolerance ?? DEFAULT_TOLERANCE);
|
|
753
|
+
}
|
|
754
|
+
function parseTimestamp(timestamp) {
|
|
755
|
+
if (typeof timestamp === "number")
|
|
756
|
+
return Number.isInteger(timestamp) ? timestamp : null;
|
|
757
|
+
if (typeof timestamp !== "string" || !/^[+-]?\d+$/.test(timestamp.trim()))
|
|
758
|
+
return null;
|
|
759
|
+
return Number.parseInt(timestamp, 10);
|
|
760
|
+
}
|
|
761
|
+
function normalizeHeaders(headers) {
|
|
762
|
+
const entries = [];
|
|
763
|
+
if (headers instanceof Headers) {
|
|
764
|
+
headers.forEach((value, name) => {
|
|
765
|
+
entries.push([name, value]);
|
|
766
|
+
});
|
|
767
|
+
} else {
|
|
768
|
+
entries.push(...Object.entries(headers ?? {}));
|
|
769
|
+
}
|
|
770
|
+
const normalized = new Map;
|
|
771
|
+
for (const [name, raw] of entries) {
|
|
772
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
773
|
+
if (value === undefined || value === null)
|
|
774
|
+
continue;
|
|
775
|
+
normalized.set(name.replace(/^HTTP_/i, "").replace(/_/g, "-").toLowerCase(), String(value));
|
|
776
|
+
}
|
|
777
|
+
return normalized;
|
|
778
|
+
}
|
|
779
|
+
function header(normalized, suffix) {
|
|
780
|
+
const manza = `x-manza-${suffix}`;
|
|
781
|
+
const value = normalized.has(manza) ? normalized.get(manza) : normalized.get(`x-zazu-${suffix}`);
|
|
782
|
+
if (value)
|
|
783
|
+
return value;
|
|
784
|
+
const name = suffix.charAt(0).toUpperCase() + suffix.slice(1);
|
|
785
|
+
throw new ManzaArgumentError(`missing X-Manza-${name} header`);
|
|
786
|
+
}
|
|
787
|
+
var Webhook = {
|
|
788
|
+
DEFAULT_TOLERANCE,
|
|
789
|
+
sign: sign2,
|
|
790
|
+
verify,
|
|
791
|
+
constructEvent
|
|
792
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { type
|
|
2
|
-
export {
|
|
1
|
+
export { Manza, type ManzaClientOptions, type RequestOptions } from "./client.js";
|
|
2
|
+
export { ManzaArgumentError, ManzaAuthenticationError, ManzaConfigurationError, ManzaConflictError, ManzaConnectionError, ManzaError, type ManzaErrorOptions, ManzaForbiddenError, ManzaNotFoundError, ManzaRateLimitError, ManzaServerError, ManzaValidationError, } from "./errors.js";
|
|
3
3
|
export { MAX_PER_PAGE, Page, type PageBody, type PageFetcher } from "./page.js";
|
|
4
4
|
export { Accounts } from "./resources/accounts.js";
|
|
5
5
|
export { Beneficiaries } from "./resources/beneficiaries.js";
|
|
@@ -9,9 +9,12 @@ export { Entity } from "./resources/entity.js";
|
|
|
9
9
|
export { Invoices } from "./resources/invoices.js";
|
|
10
10
|
export { PayeeTrustRequests } from "./resources/payee_trust_requests.js";
|
|
11
11
|
export { PaymentLinks } from "./resources/payment_links.js";
|
|
12
|
+
export { Payments } from "./resources/payments.js";
|
|
13
|
+
export { TransferAuthorizer } from "./resources/transfer_authorizer.js";
|
|
12
14
|
export { TransferDrafts } from "./resources/transfer_drafts.js";
|
|
13
15
|
export { WebhookEndpoints } from "./resources/webhook_endpoints.js";
|
|
14
|
-
export {
|
|
16
|
+
export { ManzaResponse } from "./response.js";
|
|
15
17
|
export { type PayeeForParams, type SignatureInputFields, TransferAuthorization, } from "./transfer_authorization.js";
|
|
16
18
|
export { VERSION } from "./version.js";
|
|
19
|
+
export { Webhook, type WebhookConstructEventParams, type WebhookHeaders, type WebhookSignParams, type WebhookVerifyParams, } from "./webhook.js";
|
|
17
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,KAAK,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,KAAK,iBAAiB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAGhF,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,OAAO,EACP,KAAK,2BAA2B,EAChC,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAC"}
|