@getmanza/sdk 1.0.1 → 2.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,170 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0] - 2026-11-14
11
+
12
+ Mirrors manza-ruby 2.0.0 and replays `cassettes-v2.0.0`: synced to the
13
+ Manza API at getmanza/app `906ec486e5` (API version `2026-11-13`). A major
14
+ release: see Migrating from 1.x below.
15
+
16
+ ### Removed
17
+
18
+ - **Breaking:** `manza.invoices.createPaymentLink` (`POST
19
+ /api/invoices/:id/payment_link`). The API retired the endpoint: ask for
20
+ the link with `generate_payment_link: true` on `invoices.create` or
21
+ `invoices.update` instead.
22
+ - **Breaking:** the v1 transfer-authorization signer.
23
+ `TransferAuthorization` builds only the v2 input (below).
24
+
25
+ ### Changed
26
+
27
+ - **Breaking:** `TransferAuthorization.SIGNATURE_VERSION` is
28
+ `manza.transfer-authorization.v2`, and `signatureInput` takes a required
29
+ `transfer_method` (`string | null`), appended after `client_reference`
30
+ (`""` when `null`):
31
+ `manza.transfer-authorization.v2|payment_id|nonce|amount|currency_code|account_id|payee|client_reference|transfer_method`.
32
+ Leaving it out fails to compile, and throws `ManzaArgumentError` from
33
+ plain JavaScript, before anything is sent. The API verifies v2 for
34
+ every request that is unpinned or sends `Manza-Version: 2026-11-13` or
35
+ later; only `2026-03-27` still verifies v1. Pass the payment's
36
+ `transfer_method` as the API returned it.
37
+ - The example authorizer (`examples/transfer_authorizer`) records the
38
+ create response's `transfer_method` in its ledger, checks it against the
39
+ webhook's `payment.transfer_method`, signs v2, and compares its input
40
+ with the webhook's `signature_input_v2`. `LedgerEntry` has a required
41
+ `transfer_method`; an entry without one reads as `null`.
42
+ - Invoice docs: `account_id` is required on `invoices.create` (without
43
+ one the API answers 422 `state_error`; an account that is not the
44
+ entity's, 422 with `param` `account_id`), and `invoices.update` takes it
45
+ too. An invoice's `status` may be `declined`, and `invoices.delete` also
46
+ takes a `declined` invoice that has no number.
47
+
48
+ ### Added
49
+
50
+ - `ManzaPlanLimitReachedError`, a `ManzaValidationError` thrown for a 422
51
+ whose `type` is `plan_limit_reached` (a plan cap, which the API used to
52
+ answer with a 500). `kind`, `current` and `max` read the cap from the
53
+ error body.
54
+ - `generate_payment_link` on `invoices.create` and `invoices.update`
55
+ (needs the `payment_links:write` scope; taken only while payment links
56
+ are enabled for the entity). Invoice responses carry
57
+ `generate_payment_link` and the embedded `account`.
58
+ - `transfer_method` on `payments.create`: `eft` or `rtc` in South Africa,
59
+ `standard` or `instant` in Morocco; one the market does not offer
60
+ rejects with `ManzaValidationError` with `param` `transfer_method`.
61
+ Payment responses carry `transfer_method` (the rail sent, the provider's
62
+ default when left out, `null` where the market offers no choice).
63
+ - Documented: the authorization `refusal_reason` `rail_limit_exceeded`
64
+ (status `superseded`): an authorized transfer over its rail's limit at
65
+ execution, sent to the approvers; the authorize call rejects with a 422
66
+ `ManzaValidationError` (`state_error`). A non-boolean
67
+ `generate_payment_link` rejects with `ManzaValidationError` (400).
68
+ - Documented: the `payment.authorization_requested` webhook's
69
+ `signature_input_v2` and `payment.transfer_method`, and
70
+ `transferAuthorizer.get()`'s `trust_new_payees` and `new_payee_limit`.
71
+
72
+ ### Fixed (API side, no wire change)
73
+
74
+ - `accounts.listTransactions` and `accounts.getTransaction` return posted
75
+ movements only (getmanza/app 818432457a); the SDK is unchanged.
76
+
77
+ ### Changed (cassettes)
78
+
79
+ - The replay tests pin `cassettes-v2.0.0` (was `v1.3.0`). Every cassette
80
+ was re-recorded against staging; the changed or new requests are
81
+ `invoices/create` (with `account_id`, `generate_payment_link: true` and
82
+ new dates), `invoices/create_invalid_generate_payment_link` (new, 400),
83
+ `invoices/create_without_account` (new, 422 `state_error`),
84
+ `invoices/update` (with `account_id` and `generate_payment_link: true`),
85
+ `payments/create` (with `transfer_method: "standard"`) and
86
+ `payments/create_invalid_transfer_method` (new, 422 on
87
+ `transfer_method`). See manza-ruby's CHANGELOG at 2.0.0.
88
+
89
+ ### Migrating from 1.x
90
+
91
+ - **`createPaymentLink` is gone.** Replace
92
+ `manza.invoices.createPaymentLink(id, { account_id })` with
93
+ `manza.invoices.update(id, { account_id, generate_payment_link: true })`,
94
+ or pass `generate_payment_link: true` on create. `update` resolves to
95
+ the invoice, not a link: the link is made from the invoice's account
96
+ when the invoice is approved, and appears in the invoice's
97
+ `payment_link`. `update` takes only an invoice that is still `draft`,
98
+ `pending_approval` or `declined` (any other rejects with
99
+ `ManzaValidationError`, `state_error`); for an invoice already approved
100
+ or sent, there is no API path to attach a link to it:
101
+ `manza.paymentLinks.create({ account_id, amount, ... })` makes a
102
+ standalone link instead.
103
+ - **`account_id` is required on invoice create.** Pass the account the
104
+ invoice is paid into (`manza.accounts.list()`); 1.x calls without it now
105
+ reject with `ManzaValidationError`.
106
+ - **v2 signatures only.** Add `transfer_method: payment.transfer_method`
107
+ to every `TransferAuthorization.signatureInput` call, and compare with
108
+ the webhook's `signature_input_v2` instead of `signature_input`. A
109
+ client pinned to `Manza-Version: 2026-03-27` (`apiVersion` or
110
+ `MANZA_API_VERSION`) is verified v1 and must stay on `@getmanza/sdk`
111
+ 1.x; unpin it, or pin `2026-11-13`, to move to 2.0.
112
+ - **Plan caps.** A `catch` that tests `instanceof ManzaServerError` around
113
+ creates that may hit a plan cap no longer catches it: test
114
+ `instanceof ManzaPlanLimitReachedError` (or its parent
115
+ `ManzaValidationError`), and do not retry it.
116
+
117
+ ## [1.1.0]
118
+
119
+ Mirrors manza-ruby 1.3.0 (with 1.2.0) and replays `cassettes-v1.3.0`.
120
+
121
+ ### Added
122
+
123
+ - `Webhook` verifies incoming webhook deliveries: `Webhook.verify` (resolves
124
+ to a boolean), `Webhook.constructEvent` (resolves to the parsed event,
125
+ rejects with `ManzaArgumentError`) and `Webhook.sign`. Reads
126
+ `X-Manza-Signature` / `X-Manza-Timestamp` in any case from a Fetch
127
+ `Headers` or a plain object (Node's `req.headers`), with the legacy
128
+ `X-Zazu-*` names as a fallback; compares in constant time and checks the
129
+ timestamp within 5 minutes (`tolerance: null` skips it, for local replay
130
+ only). Async, on Web Crypto. Passes the shared fixed vector every SDK
131
+ reuses. No new error class.
132
+ - `manza.payments` (`Payments`): `create`, `get`, `authorize` and
133
+ `decline` on the API's canonical paths, `POST /api/payments`,
134
+ `GET /api/payments/:id`, `POST /api/payments/:id/authorize` and
135
+ `POST /api/payments/:id/decline`. The API renamed transfer drafts to
136
+ payments; request and response bodies are unchanged, and so is the
137
+ `TransferAuthorization` signature input.
138
+ - `manza.transferAuthorizer.get()` (`GET /api/transfer_authorizer`): the
139
+ enrolled authorizer's `status`, `suspension_reason`, limits,
140
+ `daily_authorized_total`, `secret_expires_at` and `webhook_endpoint_id`.
141
+ Rejects with `ManzaNotFoundError` when none is enrolled.
142
+ - Documented the new pass-through fields: a draft's `authorization` carries
143
+ `refusal_reason` (status `refused` when it went to the approvers at
144
+ create time), bank accounts carry `trusted`, and the challenge webhook's
145
+ `payment.payee_trusted` says whether the payee was trusted already.
146
+ - `examples/transfer_authorizer/`: a runnable two-key transfer authorizer
147
+ on `node:http` (Bun, or Node through `tsx`): `server.ts` verifies the
148
+ webhook, checks a JSON ledger, signs and authorizes (or declines, also
149
+ for a new payee with `ALLOW_NEW_PAYEES=false`) and retries 409
150
+ `authorization_busy`; `create_transfer.ts` prints where the draft was
151
+ routed and why; `preflight.ts` checks what the API shows of each setup
152
+ step, prints the fix for each that fails and warns about what it cannot
153
+ see (key B's scope and IP allowlist, the new-payee option). Not shipped
154
+ in the npm package.
155
+ - README: "Machine-authorized transfers" with "Setup, step by step", the
156
+ webhook verifier and the signing snippet.
157
+
158
+ ### Deprecated
159
+
160
+ - `manza.transferDrafts` and `TransferDrafts`. Both keep working for all of
161
+ 1.x: the accessor is `manza.payments` itself and the export names the
162
+ same class, so the old name now calls `/api/payments` too. The server
163
+ keeps `/api/transfer_drafts` as a permanent alias.
164
+
165
+ ### Changed (cassettes)
166
+
167
+ - The replay tests pin `cassettes-v1.3.0` (was `v1.0.0`). The payment
168
+ cassettes moved from `transfer_drafts/` to `payments/`; the
169
+ `payments/create` and `beneficiaries/create` request bodies changed
170
+ (see manza-ruby's CHANGELOG at 1.2.0 and 1.3.0).
171
+
172
+ ## [1.0.0]
173
+
10
174
  Renamed from Zazu to Manza; the first release under the new name is 1.0.0.
11
175
 
12
176
  ### Changed (breaking)
package/README.md CHANGED
@@ -44,7 +44,15 @@ manza.customers.update(id, { ... });
44
44
  manza.customers.delete(id);
45
45
 
46
46
  manza.invoices.list();
47
- manza.invoices.create({ ... });
47
+ manza.invoices.create({
48
+ customer_id,
49
+ account_id, // required: the account the invoice is paid into
50
+ issue_date: "2026-11-14",
51
+ due_date: "2026-12-14",
52
+ generate_payment_link: true, // a card payment link, made when approved (payment_links:write; payment links enabled for the entity)
53
+ items: [{ description: "Consulting", quantity: 10, unit_price: "150.00" }],
54
+ });
55
+ manza.invoices.update(id, { account_id, generate_payment_link: false });
48
56
  // state-transition methods exist but the underlying public API is
49
57
  // not yet wired up — see getmanza/app issue #2174.
50
58
 
@@ -66,33 +74,84 @@ manza.beneficiaries.list();
66
74
  manza.beneficiaries.get(id);
67
75
  manza.beneficiaries.create({ beneficiary_type: "individual", person_name: "Jane Doe" });
68
76
  manza.beneficiaries.listExternalAccounts(beneficiaryId);
69
- manza.beneficiaries.getExternalAccount(beneficiaryId, id);
77
+ manza.beneficiaries.getExternalAccount(beneficiaryId, id); // "trusted": true once a trusted payee
70
78
  manza.beneficiaries.createExternalAccount(beneficiaryId, { account_number });
71
79
 
72
- manza.transferDrafts.create({ account_id, beneficiary_id, amount: "150.00", client_reference });
73
- manza.transferDrafts.get(id);
74
- manza.transferDrafts.authorize(id, { authorization_id, signature });
75
- manza.transferDrafts.decline(id, { authorization_id, reason });
76
-
77
80
  manza.payeeTrustRequests.create({ external_account_ids: [id] });
78
81
  manza.payeeTrustRequests.get(id);
82
+
83
+ manza.payments.create({ account_id, beneficiary_id, amount: "2500.00", client_reference, transfer_method: "standard" });
84
+ // client_reference is unique per entity; a duplicate raises ManzaConflictError
85
+ // transfer_method is the optional rail: eft/rtc (ZA), standard/instant (MA); omitted → the default
86
+ manza.payments.get(id); // authorization: status, refusal_reason
87
+ manza.payments.authorize(id, { authorization_id, signature });
88
+ manza.payments.decline(id, { authorization_id, reason });
89
+ // manza.transferDrafts is a deprecated alias of manza.payments (same object, /api/payments)
90
+
91
+ manza.transferAuthorizer.get(); // status, suspension_reason, limits, daily_authorized_total, trust_new_payees,
92
+ // new_payee_limit; ManzaNotFoundError: none enrolled
79
93
  ```
80
94
 
81
- ## Transfer authorization
95
+ ## Machine-authorized transfers
96
+
97
+ A draft inside your entity's authorization envelope (trusted payee, or a new one when you allow it, within limits) is sent to your enrolled authorizer endpoint as a `payment.authorization_requested` webhook carrying an `authorization.id` and a one-time `nonce`. Your system checks it against its own ledger, signs it and authorizes it with a **different API key** from the one that created it. [`examples/transfer_authorizer/`](examples/transfer_authorizer/) runs the whole flow. The [transfer authorization docs](https://ma.manza.finance/docs/api/transfer-authorization) have the full reference.
98
+
99
+ ### Setup, step by step
100
+
101
+ 1. **Feature flags.** Ask support to enable API transfers and transfer authorization (`release_api_webhook_authorization`) on your workspace.
102
+ 2. **Two API keys.** Key A creates drafts (`transfers:write`; `beneficiaries:request_trust` for step 6; `entity:read`, `accounts:read`, `webhook_endpoints:read` and `beneficiaries:read` for the preflight in step 7). Key B answers the challenges (`transfers:authorize`). The creating key is always refused with 403 `same_key_forbidden`, so keep key B and the signing secret on the system that holds your ledger. Bind key B to an IP allowlist: authorizing from a key without one is refused with 403 `unrestricted_api_key`. Bind key A to one too if you allow new payees (step 6): a draft to a new payee from a key without an allowlist goes to your approvers (`unrestricted_api_key`).
103
+ 3. **A stable public URL.** Your authorizer needs an HTTPS URL that never changes: an enrolled endpoint's URL is locked. Use a reserved ngrok domain (`ngrok http --url=your-name.ngrok.app 4599`) or a named Cloudflare tunnel (`cloudflared tunnel create`, then `cloudflared tunnel route dns`). Never a free ngrok URL: it changes on every restart.
104
+ 4. **Create the webhook endpoint** at that URL:
105
+
106
+ ```ts
107
+ await manza.webhookEndpoints.create({ url: "https://your-name.ngrok.app/", events: ["transfer.executed"] });
108
+ ```
109
+
110
+ 5. **Enrol it in the app**: Settings → Developer → Transfer approval. Pick the endpoint, the currency and both limits, confirm with your two-factor code, and copy the signing secret: it is shown once. Enrolment is what routes the challenges: `payment.authorization_requested` goes only to the enrolled endpoint and cannot be subscribed to through `events`.
111
+ 6. **Allow new payees, or trust each payee.** Turn on *Approve transfers to new payees* at enrolment (or later, same page, with your two-factor code) and set the *Limit per transfer to a new payee*. Your authorizer may then approve a transfer to bank details your workspace never trusted, up to that limit, and its signature trusts them: the webhook's `payment.payee_trusted` is `false` for such a transfer. Bank details whose trust was revoked, or that were edited after trusting, still go to your approvers. Without the option, an approver marks the beneficiary's bank account as trusted from the Beneficiaries list, or you ask them to:
112
+
113
+ ```ts
114
+ await manza.payeeTrustRequests.create({ external_account_ids: ["01a1..."] });
115
+ ```
116
+
117
+ `trusted` on `manza.beneficiaries.getExternalAccount` says which it is. `trust_new_payees` on `manza.transferAuthorizer.get()` says whether the option is on, and `new_payee_limit` its limit.
118
+ 7. **Run the preflight, then the example** (from `examples/transfer_authorizer/`, after `bun install` at the repository root and filling in `.env`): `bun preflight.ts` checks what the API shows of steps 1–6 and prints a fix for each that fails. What it cannot see, check by hand: that key B is bound to an IP allowlist, and, for a payee not trusted yet, that *Approve transfers to new payees* is on and key A is bound to an IP allowlist too (it warns, it does not fail). Then `bun server.ts` in one terminal, `bun create_transfer.ts` in another (on Node, `npx tsx` in place of `bun`).
119
+ 8. **Troubleshooting**: a draft that goes to your approvers instead has an `authorization` with a `refusal_reason`: status `refused` when it did not qualify (`create_transfer.ts` prints the reason in words), or `expired` (`expired`), `superseded` (`stale`; or an approver finalized the draft while its challenge was open, and it executes) or `failed` (`signature_failed`, five invalid signatures) when a challenge was sent and closed without an authorize, and `superseded` (`rail_limit_exceeded`) when an authorized transfer was over its rail's limit at execution, so nothing moved; `manza.transferAuthorizer.get()` shows a suspension and its `suspension_reason`. An authorize answered 409 `authorization_busy` (a bank-detail edit, trust or trust revocation on the same payee was in flight) is safe to retry. The reasons, and an API error's `type`, are in the [transfer authorization docs](https://ma.manza.finance/docs/api/transfer-authorization).
120
+
121
+ ### Verifying the webhook
82
122
 
83
- The `payment.authorization_requested` webhook delivers an `authorization_id` and a one-time `nonce`. Build the signature input from your own record of the draft (not the webhook's `signature_input`, which is there only to compare against), sign it with the authorizer endpoint's signing secret, and pass the result to `transferDrafts.authorize`.
123
+ Pass the **raw request body**, never re-serialized JSON. `Webhook.constructEvent` reads `X-Manza-Signature` and `X-Manza-Timestamp` (any case, from a Fetch `Headers` or a plain object such as Node's `req.headers`, or the legacy `X-Zazu-*` names), checks the signature in constant time and the timestamp within 5 minutes, and resolves to the parsed event. It rejects with `ManzaArgumentError` otherwise:
124
+
125
+ ```ts
126
+ import { ManzaArgumentError, Webhook } from "@getmanza/sdk";
127
+
128
+ let event: Record<string, unknown>;
129
+ try {
130
+ event = await Webhook.constructEvent({ payload: rawBody, headers: req.headers, secret: signingSecret });
131
+ } catch (err) {
132
+ if (err instanceof ManzaArgumentError) return reply(401, err.message);
133
+ throw err;
134
+ }
135
+ ```
136
+
137
+ `Webhook.verify({ payload, signature, timestamp, secret })` resolves to a boolean instead. Both accept `tolerance: null` to skip the timestamp check. Use it only to replay a captured delivery in a local tool or test, never on a live endpoint: without the check, anyone holding a captured delivery can replay it. `Webhook.sign({ payload, timestamp, secret })` signs a delivery for your tests. All three are async: they use the Web Crypto API, so they run on Node, Bun, Deno, browsers and Workers.
138
+
139
+ ### Signing the challenge
140
+
141
+ Sign the draft from **your own record** of it with the endpoint's signing secret. The SDK builds the v2 input (`manza.transfer-authorization.v2`), which ends with the payment's `transfer_method` (an empty segment when it is `null`); compare it with the webhook's `signature_input_v2`, which is there only to compare against. The webhook's `signature_input` is the v1 string, verified only for clients pinned to `Manza-Version: 2026-03-27`: those stay on `@getmanza/sdk` 1.x. Unpinned, or pinned to `2026-11-13` or later, the API verifies v2.
84
142
 
85
143
  ```ts
86
144
  import { Manza, TransferAuthorization } from "@getmanza/sdk";
87
145
 
88
146
  const input = TransferAuthorization.signatureInput({
89
147
  payment_id: draft.id,
90
- nonce,
148
+ nonce: webhook.data.authorization.nonce,
91
149
  amount: draft.amount, // The API's decimal string verbatim ("2500.0"), not a number.
92
150
  currency_code: draft.currency_code,
93
151
  account_id: draft.account_id,
94
152
  payee: TransferAuthorization.payeeFor({ external_account_id: draft.external_account_id }),
95
153
  client_reference: draft.client_reference,
154
+ transfer_method: draft.transfer_method, // required; null signs as ""
96
155
  });
97
156
 
98
157
  const signature = await TransferAuthorization.sign({
@@ -100,19 +159,18 @@ const signature = await TransferAuthorization.sign({
100
159
  signature_input: input,
101
160
  });
102
161
 
103
- await manza.transferDrafts.authorize(draft.id, {
104
- authorization_id: authorizationId,
162
+ const authorizer = new Manza({ apiKey: process.env.MANZA_AUTHORIZER_API_KEY });
163
+ await authorizer.payments.authorize(draft.id, {
164
+ authorization_id: webhook.data.authorization.id,
105
165
  signature,
106
166
  });
107
167
  ```
108
168
 
109
- `TransferAuthorization.sign` is async — it uses the Web Crypto API so it works on Node, Bun, Deno, browsers, and Workers without a `node:crypto` import.
110
-
111
- Use a key other than the one that created the draft — otherwise 403 `same_key_forbidden`. A blank signature raises `ManzaArgumentError` locally; the server counts a missing one as a failed attempt, and five fail the challenge.
169
+ `TransferAuthorization.sign` is async for the same Web Crypto reason. A blank signature raises `ManzaArgumentError` locally and is never sent. A wrong one raises `ManzaValidationError` (`type` `invalid_signature`). Five on one challenge send the draft to your in-app approvers; five in a row suspend the authorizer.
112
170
 
113
171
  ## Errors
114
172
 
115
- Ten concrete subclasses; discriminate with `instanceof`.
173
+ Eleven concrete subclasses; discriminate with `instanceof`. A 422 is a `ManzaValidationError`; one whose `type` is `plan_limit_reached` is its subclass `ManzaPlanLimitReachedError`, carrying `kind`, `current` and `max` (a plan cap: retrying does not help).
116
174
 
117
175
  ```ts
118
176
  import { ManzaValidationError, ManzaRateLimitError, ManzaNotFoundError } from "@getmanza/sdk";
@@ -145,10 +203,19 @@ bun run fetch:cassettes
145
203
  bun test
146
204
  ```
147
205
 
148
- ## Sibling SDKs
149
-
150
- - [manza-ruby](https://github.com/getmanza/manza-ruby) — reference implementation (records the cassettes)
151
- - manza-python, manza-php, manza-go, manza-crystal, manza-elixir — coming up
206
+ ## The SDK family
207
+
208
+ | SDK | Repository | Install |
209
+ |---|---|---|
210
+ | Ruby (reference implementation, records the cassettes) | [getmanza/manza-ruby](https://github.com/getmanza/manza-ruby) | `gem "manza"` |
211
+ | TypeScript / JavaScript | [getmanza/manza-ts](https://github.com/getmanza/manza-ts) (this repo) | `npm install @getmanza/sdk` |
212
+ | Python | [getmanza/manza-python](https://github.com/getmanza/manza-python) | `pip install manza` |
213
+ | Go | [getmanza/manza-go](https://github.com/getmanza/manza-go) | `go get github.com/getmanza/manza-go` |
214
+ | PHP | [getmanza/manza-php](https://github.com/getmanza/manza-php) | `composer require manza/manza-php` |
215
+ | Rust | [getmanza/manza-rust](https://github.com/getmanza/manza-rust) | `cargo add manza` |
216
+ | Crystal | [getmanza/manza-crystal](https://github.com/getmanza/manza-crystal) | shard `manza` (`github: getmanza/manza-crystal`) |
217
+ | Elixir | [getmanza/manza-elixir](https://github.com/getmanza/manza-elixir) | `{:manza, "~> 1.0"}` |
218
+ | CLI | [getmanza/cli](https://github.com/getmanza/cli) | `npm install -g @getzazu/cli` or `brew install getmanza/tap/zazu` |
152
219
 
153
220
  ## License
154
221
 
package/dist/client.d.ts CHANGED
@@ -6,7 +6,9 @@ import { Entity } from "./resources/entity.js";
6
6
  import { Invoices } from "./resources/invoices.js";
7
7
  import { PayeeTrustRequests } from "./resources/payee_trust_requests.js";
8
8
  import { PaymentLinks } from "./resources/payment_links.js";
9
- import { TransferDrafts } from "./resources/transfer_drafts.js";
9
+ import { Payments } from "./resources/payments.js";
10
+ import { TransferAuthorizer } from "./resources/transfer_authorizer.js";
11
+ import type { TransferDrafts } from "./resources/transfer_drafts.js";
10
12
  import { WebhookEndpoints } from "./resources/webhook_endpoints.js";
11
13
  import { ManzaResponse } from "./response.js";
12
14
  export interface ManzaClientOptions {
@@ -35,6 +37,12 @@ export declare class Manza {
35
37
  readonly invoices: Invoices;
36
38
  readonly payeeTrustRequests: PayeeTrustRequests;
37
39
  readonly paymentLinks: PaymentLinks;
40
+ readonly payments: Payments;
41
+ readonly transferAuthorizer: TransferAuthorizer;
42
+ /**
43
+ * @deprecated Use {@link Manza.payments}. Kept for all of 1.x: it is the
44
+ * same resource, which calls `/api/payments`.
45
+ */
38
46
  readonly transferDrafts: TransferDrafts;
39
47
  readonly webhookEndpoints: WebhookEndpoints;
40
48
  constructor(options?: ManzaClientOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAiBA,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,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,e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O,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CAC9C;AAOD,qBAAa,KAAK;;IAChB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAG3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAChD,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAChD;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;gBAEhC,OAAO,GAAE,kBAAuB;IAyBtC,OAAO,CAAC,CAAC,GAAG,OAAO,EACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;CAqD7B"}
package/dist/errors.d.ts CHANGED
@@ -27,6 +27,16 @@ export declare class ManzaNotFoundError extends ManzaError {
27
27
  }
28
28
  export declare class ManzaValidationError extends ManzaError {
29
29
  }
30
+ export declare class ManzaPlanLimitReachedError extends ManzaValidationError {
31
+ readonly kind: string | null;
32
+ readonly current: number | null;
33
+ readonly max: number | null;
34
+ constructor(message: string, options?: ManzaErrorOptions & {
35
+ kind?: string | null;
36
+ current?: number | null;
37
+ max?: number | null;
38
+ });
39
+ }
30
40
  export declare class ManzaRateLimitError extends ManzaError {
31
41
  readonly retryAfter: number | null;
32
42
  constructor(message: string, options?: ManzaErrorOptions & {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC;IAIf,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1B;AAED,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;gBAErB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;CAU7D;AAED,qBAAa,uBAAwB,SAAQ,UAAU;CAAG;AAC1D,qBAAa,oBAAqB,SAAQ,UAAU;CAAG;AACvD,qBAAa,wBAAyB,SAAQ,UAAU;CAAG;AAC3D,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AACtD,qBAAa,kBAAmB,SAAQ,UAAU;CAAG;AACrD,q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AAI,CAAA;KAAO;CAI7F"}
package/dist/index.cjs CHANGED
@@ -55,6 +55,7 @@ __export(exports_src, {
55
55
  ManzaError: () => ManzaError,
56
56
  ManzaForbiddenError: () => ManzaForbiddenError,
57
57
  ManzaNotFoundError: () => ManzaNotFoundError,
58
+ ManzaPlanLimitReachedError: () => ManzaPlanLimitReachedError,
58
59
  ManzaRateLimitError: () => ManzaRateLimitError,
59
60
  ManzaResponse: () => ManzaResponse,
60
61
  ManzaServerError: () => ManzaServerError,
@@ -62,9 +63,12 @@ __export(exports_src, {
62
63
  Page: () => Page,
63
64
  PayeeTrustRequests: () => PayeeTrustRequests,
64
65
  PaymentLinks: () => PaymentLinks,
66
+ Payments: () => Payments,
65
67
  TransferAuthorization: () => TransferAuthorization,
68
+ TransferAuthorizer: () => TransferAuthorizer,
66
69
  TransferDrafts: () => TransferDrafts,
67
70
  VERSION: () => VERSION,
71
+ Webhook: () => Webhook,
68
72
  WebhookEndpoints: () => WebhookEndpoints
69
73
  });
70
74
  module.exports = __toCommonJS(exports_src);
@@ -130,6 +134,18 @@ class ManzaNotFoundError extends ManzaError {
130
134
  class ManzaValidationError extends ManzaError {
131
135
  }
132
136
 
137
+ class ManzaPlanLimitReachedError extends ManzaValidationError {
138
+ kind;
139
+ current;
140
+ max;
141
+ constructor(message, options = {}) {
142
+ super(message, options);
143
+ this.kind = options.kind ?? null;
144
+ this.current = options.current ?? null;
145
+ this.max = options.max ?? null;
146
+ }
147
+ }
148
+
133
149
  class ManzaRateLimitError extends ManzaError {
134
150
  retryAfter;
135
151
  constructor(message, options = {}) {
@@ -366,9 +382,6 @@ class Invoices extends ResourceBase {
366
382
  creditNote(id, attributes = {}) {
367
383
  return this.httpPost(this.encodePath("api/invoices", id, "credit_note"), attributes);
368
384
  }
369
- createPaymentLink(id, attributes = {}) {
370
- return this.httpPost(this.encodePath("api/invoices", id, "payment_link"), attributes);
371
- }
372
385
  }
373
386
 
374
387
  // src/resources/payee_trust_requests.ts
@@ -400,19 +413,19 @@ class PaymentLinks extends ResourceBase {
400
413
  }
401
414
  }
402
415
 
403
- // src/resources/transfer_drafts.ts
404
- class TransferDrafts extends ResourceBase {
416
+ // src/resources/payments.ts
417
+ class Payments extends ResourceBase {
405
418
  create(attributes) {
406
- return this.httpPost("api/transfer_drafts", attributes);
419
+ return this.httpPost("api/payments", attributes);
407
420
  }
408
421
  get(id) {
409
- return this.httpGet(this.encodePath("api/transfer_drafts", id));
422
+ return this.httpGet(this.encodePath("api/payments", id));
410
423
  }
411
424
  authorize(id, params) {
412
425
  if (!params.signature || params.signature.trim() === "") {
413
426
  throw new ManzaArgumentError("signature cannot be blank");
414
427
  }
415
- return this.httpPost(this.encodePath("api/transfer_drafts", id, "authorize"), {
428
+ return this.httpPost(this.encodePath("api/payments", id, "authorize"), {
416
429
  authorization_id: params.authorization_id,
417
430
  signature: params.signature
418
431
  });
@@ -421,7 +434,14 @@ class TransferDrafts extends ResourceBase {
421
434
  const body = { authorization_id: params.authorization_id };
422
435
  if (params.reason !== undefined && params.reason !== null)
423
436
  body.reason = params.reason;
424
- return this.httpPost(this.encodePath("api/transfer_drafts", id, "decline"), body);
437
+ return this.httpPost(this.encodePath("api/payments", id, "decline"), body);
438
+ }
439
+ }
440
+
441
+ // src/resources/transfer_authorizer.ts
442
+ class TransferAuthorizer extends ResourceBase {
443
+ get() {
444
+ return this.httpGet("api/transfer_authorizer");
425
445
  }
426
446
  }
427
447
 
@@ -478,7 +498,7 @@ class ManzaResponse {
478
498
  }
479
499
 
480
500
  // src/version.ts
481
- var VERSION = "1.0.1";
501
+ var VERSION = "2.0.0";
482
502
 
483
503
  // src/client.ts
484
504
  var DEFAULT_BASE_URL = "https://ma.manza.finance";
@@ -499,6 +519,8 @@ class Manza {
499
519
  invoices;
500
520
  payeeTrustRequests;
501
521
  paymentLinks;
522
+ payments;
523
+ transferAuthorizer;
502
524
  transferDrafts;
503
525
  webhookEndpoints;
504
526
  constructor(options = {}) {
@@ -519,7 +541,9 @@ class Manza {
519
541
  this.invoices = new Invoices(this);
520
542
  this.payeeTrustRequests = new PayeeTrustRequests(this);
521
543
  this.paymentLinks = new PaymentLinks(this);
522
- this.transferDrafts = new TransferDrafts(this);
544
+ this.payments = new Payments(this);
545
+ this.transferAuthorizer = new TransferAuthorizer(this);
546
+ this.transferDrafts = this.payments;
523
547
  this.webhookEndpoints = new WebhookEndpoints(this);
524
548
  }
525
549
  async request(method, path, options = {}) {
@@ -605,6 +629,14 @@ function buildError(response) {
605
629
  body: response.body,
606
630
  headers: response.headers
607
631
  };
632
+ if (response.status === 422 && payload.type === "plan_limit_reached") {
633
+ return new ManzaPlanLimitReachedError(message ?? "Plan limit reached", {
634
+ ...opts,
635
+ kind: payload.kind ?? null,
636
+ current: payload.current ?? null,
637
+ max: payload.max ?? null
638
+ });
639
+ }
608
640
  switch (response.status) {
609
641
  case 400:
610
642
  return new ManzaValidationError(message ?? "Bad request", opts);
@@ -634,12 +666,17 @@ function buildError(response) {
634
666
  }
635
667
  return new ManzaError(message ?? `Unexpected status ${response.status}`, opts);
636
668
  }
669
+ // src/resources/transfer_drafts.ts
670
+ var TransferDrafts = Payments;
637
671
  // src/transfer_authorization.ts
638
- var SIGNATURE_VERSION = "manza.transfer-authorization.v1";
672
+ var SIGNATURE_VERSION = "manza.transfer-authorization.v2";
639
673
  function signatureInput(fields) {
640
674
  if (typeof fields.amount !== "string") {
641
675
  throw new ManzaArgumentError(`amount must be the API's decimal string (got ${JSON.stringify(fields.amount)})`);
642
676
  }
677
+ if (fields.transfer_method === undefined) {
678
+ throw new ManzaArgumentError("transfer_method is required (null where the market offers no choice)");
679
+ }
643
680
  return [
644
681
  SIGNATURE_VERSION,
645
682
  fields.payment_id,
@@ -648,7 +685,8 @@ function signatureInput(fields) {
648
685
  fields.currency_code,
649
686
  fields.account_id,
650
687
  fields.payee,
651
- fields.client_reference ?? ""
688
+ fields.client_reference ?? "",
689
+ fields.transfer_method ?? ""
652
690
  ].join("|");
653
691
  }
654
692
  async function sign(params) {
@@ -671,3 +709,106 @@ var TransferAuthorization = {
671
709
  sign,
672
710
  payeeFor
673
711
  };
712
+ // src/webhook.ts
713
+ var DEFAULT_TOLERANCE = 300;
714
+ function sign2(params) {
715
+ if (params.secret === "") {
716
+ return Promise.reject(new ManzaArgumentError("secret cannot be empty"));
717
+ }
718
+ return sign({
719
+ secret: params.secret,
720
+ signature_input: `${params.timestamp}.${params.payload}`
721
+ });
722
+ }
723
+ async function verify(params) {
724
+ return await signatureMatches(params.payload, params.signature, params.timestamp, params.secret) && timestampFresh(params.timestamp, params.tolerance, params.now);
725
+ }
726
+ async function constructEvent(params) {
727
+ const normalized = normalizeHeaders(params.headers);
728
+ const signature = header(normalized, "signature");
729
+ const timestamp = header(normalized, "timestamp");
730
+ if (!await signatureMatches(params.payload, signature, timestamp, params.secret)) {
731
+ throw new ManzaArgumentError("invalid webhook signature");
732
+ }
733
+ if (!timestampFresh(timestamp, params.tolerance, params.now)) {
734
+ throw new ManzaArgumentError("webhook timestamp outside tolerance");
735
+ }
736
+ let event;
737
+ try {
738
+ event = JSON.parse(params.payload);
739
+ } catch {
740
+ throw new ManzaArgumentError("webhook payload is not JSON");
741
+ }
742
+ if (event === null || typeof event !== "object" || Array.isArray(event)) {
743
+ throw new ManzaArgumentError("webhook payload is not a JSON object");
744
+ }
745
+ return event;
746
+ }
747
+ async function signatureMatches(payload, signature, timestamp, secret) {
748
+ if (typeof payload !== "string" || typeof secret !== "string" || secret === "")
749
+ return false;
750
+ if (typeof signature !== "string")
751
+ return false;
752
+ if (typeof timestamp !== "string" && typeof timestamp !== "number")
753
+ return false;
754
+ if (parseTimestamp(timestamp) === null)
755
+ return false;
756
+ const expected = await sign2({ payload, timestamp, secret });
757
+ return constantTimeEqual(expected, signature);
758
+ }
759
+ function constantTimeEqual(a, b) {
760
+ if (a.length !== b.length)
761
+ return false;
762
+ let diff = 0;
763
+ for (let i = 0;i < a.length; i++)
764
+ diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
765
+ return diff === 0;
766
+ }
767
+ function timestampFresh(timestamp, tolerance, now) {
768
+ if (tolerance === null)
769
+ return true;
770
+ const seconds = parseTimestamp(timestamp);
771
+ if (seconds === null)
772
+ return false;
773
+ const nowSeconds = Math.floor((now ?? new Date).getTime() / 1000);
774
+ return Math.abs(nowSeconds - seconds) <= (tolerance ?? DEFAULT_TOLERANCE);
775
+ }
776
+ function parseTimestamp(timestamp) {
777
+ if (typeof timestamp === "number")
778
+ return Number.isInteger(timestamp) ? timestamp : null;
779
+ if (typeof timestamp !== "string" || !/^[+-]?\d+$/.test(timestamp.trim()))
780
+ return null;
781
+ return Number.parseInt(timestamp, 10);
782
+ }
783
+ function normalizeHeaders(headers) {
784
+ const entries = [];
785
+ if (headers instanceof Headers) {
786
+ headers.forEach((value, name) => {
787
+ entries.push([name, value]);
788
+ });
789
+ } else {
790
+ entries.push(...Object.entries(headers ?? {}));
791
+ }
792
+ const normalized = new Map;
793
+ for (const [name, raw] of entries) {
794
+ const value = Array.isArray(raw) ? raw[0] : raw;
795
+ if (value === undefined || value === null)
796
+ continue;
797
+ normalized.set(name.replace(/^HTTP_/i, "").replace(/_/g, "-").toLowerCase(), String(value));
798
+ }
799
+ return normalized;
800
+ }
801
+ function header(normalized, suffix) {
802
+ const manza = `x-manza-${suffix}`;
803
+ const value = normalized.has(manza) ? normalized.get(manza) : normalized.get(`x-zazu-${suffix}`);
804
+ if (value)
805
+ return value;
806
+ const name = suffix.charAt(0).toUpperCase() + suffix.slice(1);
807
+ throw new ManzaArgumentError(`missing X-Manza-${name} header`);
808
+ }
809
+ var Webhook = {
810
+ DEFAULT_TOLERANCE,
811
+ sign: sign2,
812
+ verify,
813
+ constructEvent
814
+ };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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";
2
+ export { ManzaArgumentError, ManzaAuthenticationError, ManzaConfigurationError, ManzaConflictError, ManzaConnectionError, ManzaError, type ManzaErrorOptions, ManzaForbiddenError, ManzaNotFoundError, ManzaPlanLimitReachedError, 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
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
@@ -1 +1 @@
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,E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O,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"}
package/dist/index.js CHANGED
@@ -59,6 +59,18 @@ class ManzaNotFoundError extends ManzaError {
59
59
  class ManzaValidationError extends ManzaError {
60
60
  }
61
61
 
62
+ class ManzaPlanLimitReachedError extends ManzaValidationError {
63
+ kind;
64
+ current;
65
+ max;
66
+ constructor(message, options = {}) {
67
+ super(message, options);
68
+ this.kind = options.kind ?? null;
69
+ this.current = options.current ?? null;
70
+ this.max = options.max ?? null;
71
+ }
72
+ }
73
+
62
74
  class ManzaRateLimitError extends ManzaError {
63
75
  retryAfter;
64
76
  constructor(message, options = {}) {
@@ -295,9 +307,6 @@ class Invoices extends ResourceBase {
295
307
  creditNote(id, attributes = {}) {
296
308
  return this.httpPost(this.encodePath("api/invoices", id, "credit_note"), attributes);
297
309
  }
298
- createPaymentLink(id, attributes = {}) {
299
- return this.httpPost(this.encodePath("api/invoices", id, "payment_link"), attributes);
300
- }
301
310
  }
302
311
 
303
312
  // src/resources/payee_trust_requests.ts
@@ -329,19 +338,19 @@ class PaymentLinks extends ResourceBase {
329
338
  }
330
339
  }
331
340
 
332
- // src/resources/transfer_drafts.ts
333
- class TransferDrafts extends ResourceBase {
341
+ // src/resources/payments.ts
342
+ class Payments extends ResourceBase {
334
343
  create(attributes) {
335
- return this.httpPost("api/transfer_drafts", attributes);
344
+ return this.httpPost("api/payments", attributes);
336
345
  }
337
346
  get(id) {
338
- return this.httpGet(this.encodePath("api/transfer_drafts", id));
347
+ return this.httpGet(this.encodePath("api/payments", id));
339
348
  }
340
349
  authorize(id, params) {
341
350
  if (!params.signature || params.signature.trim() === "") {
342
351
  throw new ManzaArgumentError("signature cannot be blank");
343
352
  }
344
- return this.httpPost(this.encodePath("api/transfer_drafts", id, "authorize"), {
353
+ return this.httpPost(this.encodePath("api/payments", id, "authorize"), {
345
354
  authorization_id: params.authorization_id,
346
355
  signature: params.signature
347
356
  });
@@ -350,7 +359,14 @@ class TransferDrafts extends ResourceBase {
350
359
  const body = { authorization_id: params.authorization_id };
351
360
  if (params.reason !== undefined && params.reason !== null)
352
361
  body.reason = params.reason;
353
- return this.httpPost(this.encodePath("api/transfer_drafts", id, "decline"), body);
362
+ return this.httpPost(this.encodePath("api/payments", id, "decline"), body);
363
+ }
364
+ }
365
+
366
+ // src/resources/transfer_authorizer.ts
367
+ class TransferAuthorizer extends ResourceBase {
368
+ get() {
369
+ return this.httpGet("api/transfer_authorizer");
354
370
  }
355
371
  }
356
372
 
@@ -407,7 +423,7 @@ class ManzaResponse {
407
423
  }
408
424
 
409
425
  // src/version.ts
410
- var VERSION = "1.0.1";
426
+ var VERSION = "2.0.0";
411
427
 
412
428
  // src/client.ts
413
429
  var DEFAULT_BASE_URL = "https://ma.manza.finance";
@@ -428,6 +444,8 @@ class Manza {
428
444
  invoices;
429
445
  payeeTrustRequests;
430
446
  paymentLinks;
447
+ payments;
448
+ transferAuthorizer;
431
449
  transferDrafts;
432
450
  webhookEndpoints;
433
451
  constructor(options = {}) {
@@ -448,7 +466,9 @@ class Manza {
448
466
  this.invoices = new Invoices(this);
449
467
  this.payeeTrustRequests = new PayeeTrustRequests(this);
450
468
  this.paymentLinks = new PaymentLinks(this);
451
- this.transferDrafts = new TransferDrafts(this);
469
+ this.payments = new Payments(this);
470
+ this.transferAuthorizer = new TransferAuthorizer(this);
471
+ this.transferDrafts = this.payments;
452
472
  this.webhookEndpoints = new WebhookEndpoints(this);
453
473
  }
454
474
  async request(method, path, options = {}) {
@@ -534,6 +554,14 @@ function buildError(response) {
534
554
  body: response.body,
535
555
  headers: response.headers
536
556
  };
557
+ if (response.status === 422 && payload.type === "plan_limit_reached") {
558
+ return new ManzaPlanLimitReachedError(message ?? "Plan limit reached", {
559
+ ...opts,
560
+ kind: payload.kind ?? null,
561
+ current: payload.current ?? null,
562
+ max: payload.max ?? null
563
+ });
564
+ }
537
565
  switch (response.status) {
538
566
  case 400:
539
567
  return new ManzaValidationError(message ?? "Bad request", opts);
@@ -563,12 +591,17 @@ function buildError(response) {
563
591
  }
564
592
  return new ManzaError(message ?? `Unexpected status ${response.status}`, opts);
565
593
  }
594
+ // src/resources/transfer_drafts.ts
595
+ var TransferDrafts = Payments;
566
596
  // src/transfer_authorization.ts
567
- var SIGNATURE_VERSION = "manza.transfer-authorization.v1";
597
+ var SIGNATURE_VERSION = "manza.transfer-authorization.v2";
568
598
  function signatureInput(fields) {
569
599
  if (typeof fields.amount !== "string") {
570
600
  throw new ManzaArgumentError(`amount must be the API's decimal string (got ${JSON.stringify(fields.amount)})`);
571
601
  }
602
+ if (fields.transfer_method === undefined) {
603
+ throw new ManzaArgumentError("transfer_method is required (null where the market offers no choice)");
604
+ }
572
605
  return [
573
606
  SIGNATURE_VERSION,
574
607
  fields.payment_id,
@@ -577,7 +610,8 @@ function signatureInput(fields) {
577
610
  fields.currency_code,
578
611
  fields.account_id,
579
612
  fields.payee,
580
- fields.client_reference ?? ""
613
+ fields.client_reference ?? "",
614
+ fields.transfer_method ?? ""
581
615
  ].join("|");
582
616
  }
583
617
  async function sign(params) {
@@ -600,6 +634,109 @@ var TransferAuthorization = {
600
634
  sign,
601
635
  payeeFor
602
636
  };
637
+ // src/webhook.ts
638
+ var DEFAULT_TOLERANCE = 300;
639
+ function sign2(params) {
640
+ if (params.secret === "") {
641
+ return Promise.reject(new ManzaArgumentError("secret cannot be empty"));
642
+ }
643
+ return sign({
644
+ secret: params.secret,
645
+ signature_input: `${params.timestamp}.${params.payload}`
646
+ });
647
+ }
648
+ async function verify(params) {
649
+ return await signatureMatches(params.payload, params.signature, params.timestamp, params.secret) && timestampFresh(params.timestamp, params.tolerance, params.now);
650
+ }
651
+ async function constructEvent(params) {
652
+ const normalized = normalizeHeaders(params.headers);
653
+ const signature = header(normalized, "signature");
654
+ const timestamp = header(normalized, "timestamp");
655
+ if (!await signatureMatches(params.payload, signature, timestamp, params.secret)) {
656
+ throw new ManzaArgumentError("invalid webhook signature");
657
+ }
658
+ if (!timestampFresh(timestamp, params.tolerance, params.now)) {
659
+ throw new ManzaArgumentError("webhook timestamp outside tolerance");
660
+ }
661
+ let event;
662
+ try {
663
+ event = JSON.parse(params.payload);
664
+ } catch {
665
+ throw new ManzaArgumentError("webhook payload is not JSON");
666
+ }
667
+ if (event === null || typeof event !== "object" || Array.isArray(event)) {
668
+ throw new ManzaArgumentError("webhook payload is not a JSON object");
669
+ }
670
+ return event;
671
+ }
672
+ async function signatureMatches(payload, signature, timestamp, secret) {
673
+ if (typeof payload !== "string" || typeof secret !== "string" || secret === "")
674
+ return false;
675
+ if (typeof signature !== "string")
676
+ return false;
677
+ if (typeof timestamp !== "string" && typeof timestamp !== "number")
678
+ return false;
679
+ if (parseTimestamp(timestamp) === null)
680
+ return false;
681
+ const expected = await sign2({ payload, timestamp, secret });
682
+ return constantTimeEqual(expected, signature);
683
+ }
684
+ function constantTimeEqual(a, b) {
685
+ if (a.length !== b.length)
686
+ return false;
687
+ let diff = 0;
688
+ for (let i = 0;i < a.length; i++)
689
+ diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
690
+ return diff === 0;
691
+ }
692
+ function timestampFresh(timestamp, tolerance, now) {
693
+ if (tolerance === null)
694
+ return true;
695
+ const seconds = parseTimestamp(timestamp);
696
+ if (seconds === null)
697
+ return false;
698
+ const nowSeconds = Math.floor((now ?? new Date).getTime() / 1000);
699
+ return Math.abs(nowSeconds - seconds) <= (tolerance ?? DEFAULT_TOLERANCE);
700
+ }
701
+ function parseTimestamp(timestamp) {
702
+ if (typeof timestamp === "number")
703
+ return Number.isInteger(timestamp) ? timestamp : null;
704
+ if (typeof timestamp !== "string" || !/^[+-]?\d+$/.test(timestamp.trim()))
705
+ return null;
706
+ return Number.parseInt(timestamp, 10);
707
+ }
708
+ function normalizeHeaders(headers) {
709
+ const entries = [];
710
+ if (headers instanceof Headers) {
711
+ headers.forEach((value, name) => {
712
+ entries.push([name, value]);
713
+ });
714
+ } else {
715
+ entries.push(...Object.entries(headers ?? {}));
716
+ }
717
+ const normalized = new Map;
718
+ for (const [name, raw] of entries) {
719
+ const value = Array.isArray(raw) ? raw[0] : raw;
720
+ if (value === undefined || value === null)
721
+ continue;
722
+ normalized.set(name.replace(/^HTTP_/i, "").replace(/_/g, "-").toLowerCase(), String(value));
723
+ }
724
+ return normalized;
725
+ }
726
+ function header(normalized, suffix) {
727
+ const manza = `x-manza-${suffix}`;
728
+ const value = normalized.has(manza) ? normalized.get(manza) : normalized.get(`x-zazu-${suffix}`);
729
+ if (value)
730
+ return value;
731
+ const name = suffix.charAt(0).toUpperCase() + suffix.slice(1);
732
+ throw new ManzaArgumentError(`missing X-Manza-${name} header`);
733
+ }
734
+ var Webhook = {
735
+ DEFAULT_TOLERANCE,
736
+ sign: sign2,
737
+ verify,
738
+ constructEvent
739
+ };
603
740
  export {
604
741
  Accounts,
605
742
  Beneficiaries,
@@ -617,6 +754,7 @@ export {
617
754
  ManzaError,
618
755
  ManzaForbiddenError,
619
756
  ManzaNotFoundError,
757
+ ManzaPlanLimitReachedError,
620
758
  ManzaRateLimitError,
621
759
  ManzaResponse,
622
760
  ManzaServerError,
@@ -624,8 +762,11 @@ export {
624
762
  Page,
625
763
  PayeeTrustRequests,
626
764
  PaymentLinks,
765
+ Payments,
627
766
  TransferAuthorization,
767
+ TransferAuthorizer,
628
768
  TransferDrafts,
629
769
  VERSION,
770
+ Webhook,
630
771
  WebhookEndpoints
631
772
  };
@@ -15,6 +15,5 @@ export declare class Invoices extends ResourceBase {
15
15
  markAsPaid(id: string, attributes?: Record<string, unknown>): Promise<ManzaResponse>;
16
16
  cancel(id: string): Promise<ManzaResponse>;
17
17
  creditNote(id: string, attributes?: Record<string, unknown>): Promise<ManzaResponse>;
18
- createPaymentLink(id: string, attributes?: Record<string, unknown>): Promise<ManzaResponse>;
19
18
  }
20
19
  //# sourceMappingURL=invoices.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoices.d.ts","sourceRoot":"","sources":["../../src/resources/invoices.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,KAAK,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE1D,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,C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YAAY,EAAE,MAAM,WAAW,CAAC;AAE1D,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IAGnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;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,aAAa,CAAC;IA0BvC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IASnE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAS/E,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAO1C,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAIxC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAIxF,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAI1C,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAGzF"}
@@ -0,0 +1,15 @@
1
+ import type { ManzaResponse } from "../response.js";
2
+ import { ResourceBase } from "./base.js";
3
+ export declare class Payments extends ResourceBase {
4
+ create(attributes: Record<string, unknown>): Promise<ManzaResponse>;
5
+ get(id: string): Promise<ManzaResponse>;
6
+ authorize(id: string, params: {
7
+ authorization_id: string;
8
+ signature: string;
9
+ }): Promise<ManzaResponse>;
10
+ decline(id: string, params: {
11
+ authorization_id: string;
12
+ reason?: string | null | undefined;
13
+ }): Promise<ManzaResponse>;
14
+ }
15
+ //# sourceMappingURL=payments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../src/resources/payments.ts"],"names":[],"mappings":"AA2CA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,qBAAa,QAAS,SAAQ,YAAY;IAiBxC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAKnE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAsBvC,SAAS,CACP,EAAE,EAAE,MAAM,EACV,MAAM,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GACtD,OAAO,CAAC,aAAa,CAAC;IAezB,OAAO,CACL,EAAE,EAAE,MAAM,EACV,MAAM,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,GACvE,OAAO,CAAC,aAAa,CAAC;CAK1B"}
@@ -0,0 +1,6 @@
1
+ import type { ManzaResponse } from "../response.js";
2
+ import { ResourceBase } from "./base.js";
3
+ export declare class TransferAuthorizer extends ResourceBase {
4
+ get(): Promise<ManzaResponse>;
5
+ }
6
+ //# sourceMappingURL=transfer_authorizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer_authorizer.d.ts","sourceRoot":"","sources":["../../src/resources/transfer_authorizer.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,qBAAa,kBAAmB,SAAQ,YAAY;IAalD,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC;CAG9B"}
@@ -1,15 +1,9 @@
1
- import type { ManzaResponse } from "../response.js";
2
- import { ResourceBase } from "./base.js";
3
- export declare class TransferDrafts extends ResourceBase {
4
- create(attributes: Record<string, unknown>): Promise<ManzaResponse>;
5
- get(id: string): Promise<ManzaResponse>;
6
- authorize(id: string, params: {
7
- authorization_id: string;
8
- signature: string;
9
- }): Promise<ManzaResponse>;
10
- decline(id: string, params: {
11
- authorization_id: string;
12
- reason?: string | null | undefined;
13
- }): Promise<ManzaResponse>;
14
- }
1
+ import { Payments } from "./payments.js";
2
+ /**
3
+ * @deprecated Use {@link Payments} (`manza.payments`). Kept for all of 1.x:
4
+ * it is the same class, and it calls `/api/payments`.
5
+ */
6
+ export declare const TransferDrafts: typeof Payments;
7
+ /** @deprecated Use {@link Payments}. */
8
+ export type TransferDrafts = Payments;
15
9
  //# sourceMappingURL=transfer_drafts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transfer_drafts.d.ts","sourceRoot":"","sources":["../../src/resources/transfer_drafts.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,qBAAa,cAAe,SAAQ,YAAY;IAO9C,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAInE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAUvC,SAAS,CACP,EAAE,EAAE,MAAM,EACV,MAAM,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GACtD,OAAO,CAAC,aAAa,CAAC;IAYzB,OAAO,CACL,EAAE,EAAE,MAAM,EACV,MAAM,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,GACvE,OAAO,CAAC,aAAa,CAAC;CAK1B"}
1
+ {"version":3,"file":"transfer_drafts.d.ts","sourceRoot":"","sources":["../../src/resources/transfer_drafts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,cAAc,iBAAW,CAAC;AACvC,wCAAwC;AACxC,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC"}
@@ -1,4 +1,4 @@
1
- export declare const SIGNATURE_VERSION = "manza.transfer-authorization.v1";
1
+ export declare const SIGNATURE_VERSION = "manza.transfer-authorization.v2";
2
2
  export interface SignatureInputFields {
3
3
  payment_id: string;
4
4
  nonce: string;
@@ -7,6 +7,7 @@ export interface SignatureInputFields {
7
7
  account_id: string;
8
8
  payee: string;
9
9
  client_reference?: string | null | undefined;
10
+ transfer_method: string | null;
10
11
  }
11
12
  export interface PayeeForParams {
12
13
  external_account_id?: string | null | undefined;
@@ -19,7 +20,7 @@ export declare function sign(params: {
19
20
  }): Promise<string>;
20
21
  export declare function payeeFor(params: PayeeForParams): string;
21
22
  export declare const TransferAuthorization: {
22
- readonly SIGNATURE_VERSION: "manza.transfer-authorization.v1";
23
+ readonly SIGNATURE_VERSION: "manza.transfer-authorization.v2";
23
24
  readonly signatureInput: typeof signatureInput;
24
25
  readonly sign: typeof sign;
25
26
  readonly payeeFor: typeof payeeFor;
@@ -1 +1 @@
1
- {"version":3,"file":"transfer_authorization.d.ts","sourceRoot":"","sources":["../src/transfer_authorization.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,iBAAiB,oCAAoC,CAAC;AAEnE,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IAGd,MAAM,E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C;CACpD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAwBnE;AAKD,wBAAsB,IAAI,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAW/F;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CASvD;AAED,eAAO,MAAM,qBAAqB;;;;;CAKxB,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.0.1";
1
+ export declare const VERSION = "2.0.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1,32 @@
1
+ export declare const DEFAULT_TOLERANCE = 300;
2
+ export type WebhookHeaders = Headers | Record<string, string | number | readonly string[] | null | undefined>;
3
+ export interface WebhookSignParams {
4
+ payload: string;
5
+ timestamp: string | number;
6
+ secret: string;
7
+ }
8
+ export interface WebhookVerifyParams {
9
+ payload: string;
10
+ signature: string;
11
+ timestamp: string | number;
12
+ secret: string;
13
+ tolerance?: number | null | undefined;
14
+ now?: Date | undefined;
15
+ }
16
+ export interface WebhookConstructEventParams {
17
+ payload: string;
18
+ headers: WebhookHeaders;
19
+ secret: string;
20
+ tolerance?: number | null | undefined;
21
+ now?: Date | undefined;
22
+ }
23
+ export declare function sign(params: WebhookSignParams): Promise<string>;
24
+ export declare function verify(params: WebhookVerifyParams): Promise<boolean>;
25
+ export declare function constructEvent(params: WebhookConstructEventParams): Promise<Record<string, unknown>>;
26
+ export declare const Webhook: {
27
+ readonly DEFAULT_TOLERANCE: 300;
28
+ readonly sign: typeof sign;
29
+ readonly verify: typeof verify;
30
+ readonly constructEvent: typeof constructEvent;
31
+ };
32
+ //# sourceMappingURL=webhook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../src/webhook.ts"],"names":[],"mappings":"AA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
3
+ "version": "2.0.0",
4
4
  "description": "TypeScript SDK for the Manza API. Runtime-agnostic (Node, Bun, Deno, browsers, Cloudflare Workers).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "devDependencies": {
64
64
  "@biomejs/biome": "^2.4.14",
65
- "@types/bun": "latest",
65
+ "@types/bun": "^1.4.2",
66
66
  "@types/js-yaml": "^4.0.9",
67
67
  "js-yaml": "^4.1.0",
68
68
  "msw": "^2.6.0",