@getmanza/sdk 1.0.1 → 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 +9 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +127 -8
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +127 -8
- 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/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/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,63 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.1.0]
|
|
11
|
+
|
|
12
|
+
Mirrors manza-ruby 1.3.0 (with 1.2.0) and replays `cassettes-v1.3.0`.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- `Webhook` verifies incoming webhook deliveries: `Webhook.verify` (resolves
|
|
17
|
+
to a boolean), `Webhook.constructEvent` (resolves to the parsed event,
|
|
18
|
+
rejects with `ManzaArgumentError`) and `Webhook.sign`. Reads
|
|
19
|
+
`X-Manza-Signature` / `X-Manza-Timestamp` in any case from a Fetch
|
|
20
|
+
`Headers` or a plain object (Node's `req.headers`), with the legacy
|
|
21
|
+
`X-Zazu-*` names as a fallback; compares in constant time and checks the
|
|
22
|
+
timestamp within 5 minutes (`tolerance: null` skips it, for local replay
|
|
23
|
+
only). Async, on Web Crypto. Passes the shared fixed vector every SDK
|
|
24
|
+
reuses. No new error class.
|
|
25
|
+
- `manza.payments` (`Payments`): `create`, `get`, `authorize` and
|
|
26
|
+
`decline` on the API's canonical paths, `POST /api/payments`,
|
|
27
|
+
`GET /api/payments/:id`, `POST /api/payments/:id/authorize` and
|
|
28
|
+
`POST /api/payments/:id/decline`. The API renamed transfer drafts to
|
|
29
|
+
payments; request and response bodies are unchanged, and so is the
|
|
30
|
+
`TransferAuthorization` signature input.
|
|
31
|
+
- `manza.transferAuthorizer.get()` (`GET /api/transfer_authorizer`): the
|
|
32
|
+
enrolled authorizer's `status`, `suspension_reason`, limits,
|
|
33
|
+
`daily_authorized_total`, `secret_expires_at` and `webhook_endpoint_id`.
|
|
34
|
+
Rejects with `ManzaNotFoundError` when none is enrolled.
|
|
35
|
+
- Documented the new pass-through fields: a draft's `authorization` carries
|
|
36
|
+
`refusal_reason` (status `refused` when it went to the approvers at
|
|
37
|
+
create time), bank accounts carry `trusted`, and the challenge webhook's
|
|
38
|
+
`payment.payee_trusted` says whether the payee was trusted already.
|
|
39
|
+
- `examples/transfer_authorizer/`: a runnable two-key transfer authorizer
|
|
40
|
+
on `node:http` (Bun, or Node through `tsx`): `server.ts` verifies the
|
|
41
|
+
webhook, checks a JSON ledger, signs and authorizes (or declines, also
|
|
42
|
+
for a new payee with `ALLOW_NEW_PAYEES=false`) and retries 409
|
|
43
|
+
`authorization_busy`; `create_transfer.ts` prints where the draft was
|
|
44
|
+
routed and why; `preflight.ts` checks what the API shows of each setup
|
|
45
|
+
step, prints the fix for each that fails and warns about what it cannot
|
|
46
|
+
see (key B's scope and IP allowlist, the new-payee option). Not shipped
|
|
47
|
+
in the npm package.
|
|
48
|
+
- README: "Machine-authorized transfers" with "Setup, step by step", the
|
|
49
|
+
webhook verifier and the signing snippet.
|
|
50
|
+
|
|
51
|
+
### Deprecated
|
|
52
|
+
|
|
53
|
+
- `manza.transferDrafts` and `TransferDrafts`. Both keep working for all of
|
|
54
|
+
1.x: the accessor is `manza.payments` itself and the export names the
|
|
55
|
+
same class, so the old name now calls `/api/payments` too. The server
|
|
56
|
+
keeps `/api/transfer_drafts` as a permanent alias.
|
|
57
|
+
|
|
58
|
+
### Changed (cassettes)
|
|
59
|
+
|
|
60
|
+
- The replay tests pin `cassettes-v1.3.0` (was `v1.0.0`). The payment
|
|
61
|
+
cassettes moved from `transfer_drafts/` to `payments/`; the
|
|
62
|
+
`payments/create` and `beneficiaries/create` request bodies changed
|
|
63
|
+
(see manza-ruby's CHANGELOG at 1.2.0 and 1.3.0).
|
|
64
|
+
|
|
65
|
+
## [1.0.0]
|
|
66
|
+
|
|
10
67
|
Renamed from Zazu to Manza; the first release under the new name is 1.0.0.
|
|
11
68
|
|
|
12
69
|
### Changed (breaking)
|
package/README.md
CHANGED
|
@@ -66,28 +66,76 @@ manza.beneficiaries.list();
|
|
|
66
66
|
manza.beneficiaries.get(id);
|
|
67
67
|
manza.beneficiaries.create({ beneficiary_type: "individual", person_name: "Jane Doe" });
|
|
68
68
|
manza.beneficiaries.listExternalAccounts(beneficiaryId);
|
|
69
|
-
manza.beneficiaries.getExternalAccount(beneficiaryId, id);
|
|
69
|
+
manza.beneficiaries.getExternalAccount(beneficiaryId, id); // "trusted": true once a trusted payee
|
|
70
70
|
manza.beneficiaries.createExternalAccount(beneficiaryId, { account_number });
|
|
71
71
|
|
|
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
72
|
manza.payeeTrustRequests.create({ external_account_ids: [id] });
|
|
78
73
|
manza.payeeTrustRequests.get(id);
|
|
74
|
+
|
|
75
|
+
manza.payments.create({ account_id, beneficiary_id, amount: "2500.00", client_reference });
|
|
76
|
+
// client_reference is unique per entity; a duplicate raises ManzaConflictError
|
|
77
|
+
manza.payments.get(id); // authorization: status, refusal_reason
|
|
78
|
+
manza.payments.authorize(id, { authorization_id, signature });
|
|
79
|
+
manza.payments.decline(id, { authorization_id, reason });
|
|
80
|
+
// manza.transferDrafts is a deprecated alias of manza.payments (same object, /api/payments)
|
|
81
|
+
|
|
82
|
+
manza.transferAuthorizer.get(); // status, suspension_reason, limits, daily_authorized_total; ManzaNotFoundError: none enrolled
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Machine-authorized transfers
|
|
86
|
+
|
|
87
|
+
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.
|
|
88
|
+
|
|
89
|
+
### Setup, step by step
|
|
90
|
+
|
|
91
|
+
1. **Feature flags.** Ask support to enable API transfers and transfer authorization (`release_api_webhook_authorization`) on your workspace.
|
|
92
|
+
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`).
|
|
93
|
+
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.
|
|
94
|
+
4. **Create the webhook endpoint** at that URL:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
await manza.webhookEndpoints.create({ url: "https://your-name.ngrok.app/", events: ["transfer.executed"] });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
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`.
|
|
101
|
+
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:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
await manza.payeeTrustRequests.create({ external_account_ids: ["01a1..."] });
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`trusted` on `manza.beneficiaries.getExternalAccount` says which it is. The API does not show whether the option is on.
|
|
108
|
+
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`).
|
|
109
|
+
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; `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).
|
|
110
|
+
|
|
111
|
+
### Verifying the webhook
|
|
112
|
+
|
|
113
|
+
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:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { ManzaArgumentError, Webhook } from "@getmanza/sdk";
|
|
117
|
+
|
|
118
|
+
let event: Record<string, unknown>;
|
|
119
|
+
try {
|
|
120
|
+
event = await Webhook.constructEvent({ payload: rawBody, headers: req.headers, secret: signingSecret });
|
|
121
|
+
} catch (err) {
|
|
122
|
+
if (err instanceof ManzaArgumentError) return reply(401, err.message);
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
79
125
|
```
|
|
80
126
|
|
|
81
|
-
|
|
127
|
+
`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.
|
|
128
|
+
|
|
129
|
+
### Signing the challenge
|
|
82
130
|
|
|
83
|
-
|
|
131
|
+
Sign the draft from **your own record** of it (not the webhook's `signature_input`, which is there only to compare against) with the endpoint's signing secret:
|
|
84
132
|
|
|
85
133
|
```ts
|
|
86
134
|
import { Manza, TransferAuthorization } from "@getmanza/sdk";
|
|
87
135
|
|
|
88
136
|
const input = TransferAuthorization.signatureInput({
|
|
89
137
|
payment_id: draft.id,
|
|
90
|
-
nonce,
|
|
138
|
+
nonce: webhook.data.authorization.nonce,
|
|
91
139
|
amount: draft.amount, // The API's decimal string verbatim ("2500.0"), not a number.
|
|
92
140
|
currency_code: draft.currency_code,
|
|
93
141
|
account_id: draft.account_id,
|
|
@@ -100,15 +148,14 @@ const signature = await TransferAuthorization.sign({
|
|
|
100
148
|
signature_input: input,
|
|
101
149
|
});
|
|
102
150
|
|
|
103
|
-
|
|
104
|
-
|
|
151
|
+
const authorizer = new Manza({ apiKey: process.env.MANZA_AUTHORIZER_API_KEY });
|
|
152
|
+
await authorizer.payments.authorize(draft.id, {
|
|
153
|
+
authorization_id: webhook.data.authorization.id,
|
|
105
154
|
signature,
|
|
106
155
|
});
|
|
107
156
|
```
|
|
108
157
|
|
|
109
|
-
`TransferAuthorization.sign` is async
|
|
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.
|
|
158
|
+
`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
159
|
|
|
113
160
|
## Errors
|
|
114
161
|
|
|
@@ -145,10 +192,19 @@ bun run fetch:cassettes
|
|
|
145
192
|
bun test
|
|
146
193
|
```
|
|
147
194
|
|
|
148
|
-
##
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
195
|
+
## The SDK family
|
|
196
|
+
|
|
197
|
+
| SDK | Repository | Install |
|
|
198
|
+
|---|---|---|
|
|
199
|
+
| Ruby (reference implementation, records the cassettes) | [getmanza/manza-ruby](https://github.com/getmanza/manza-ruby) | `gem "manza"` |
|
|
200
|
+
| TypeScript / JavaScript | [getmanza/manza-ts](https://github.com/getmanza/manza-ts) (this repo) | `npm install @getmanza/sdk` |
|
|
201
|
+
| Python | [getmanza/manza-python](https://github.com/getmanza/manza-python) | `pip install manza` |
|
|
202
|
+
| Go | [getmanza/manza-go](https://github.com/getmanza/manza-go) | `go get github.com/getmanza/manza-go` |
|
|
203
|
+
| PHP | [getmanza/manza-php](https://github.com/getmanza/manza-php) | `composer require manza/manza-php` |
|
|
204
|
+
| Rust | [getmanza/manza-rust](https://github.com/getmanza/manza-rust) | `cargo add manza` |
|
|
205
|
+
| Crystal | [getmanza/manza-crystal](https://github.com/getmanza/manza-crystal) | shard `manza` (`github: getmanza/manza-crystal`) |
|
|
206
|
+
| Elixir | [getmanza/manza-elixir](https://github.com/getmanza/manza-elixir) | `{:manza, "~> 1.0"}` |
|
|
207
|
+
| CLI | [getmanza/cli](https://github.com/getmanza/cli) | `npm install -g @getzazu/cli` or `brew install getmanza/tap/zazu` |
|
|
152
208
|
|
|
153
209
|
## License
|
|
154
210
|
|
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 {
|
|
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);
|
package/dist/client.d.ts.map
CHANGED
|
@@ -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;
|
|
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,YAA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Q,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/index.cjs
CHANGED
|
@@ -62,9 +62,12 @@ __export(exports_src, {
|
|
|
62
62
|
Page: () => Page,
|
|
63
63
|
PayeeTrustRequests: () => PayeeTrustRequests,
|
|
64
64
|
PaymentLinks: () => PaymentLinks,
|
|
65
|
+
Payments: () => Payments,
|
|
65
66
|
TransferAuthorization: () => TransferAuthorization,
|
|
67
|
+
TransferAuthorizer: () => TransferAuthorizer,
|
|
66
68
|
TransferDrafts: () => TransferDrafts,
|
|
67
69
|
VERSION: () => VERSION,
|
|
70
|
+
Webhook: () => Webhook,
|
|
68
71
|
WebhookEndpoints: () => WebhookEndpoints
|
|
69
72
|
});
|
|
70
73
|
module.exports = __toCommonJS(exports_src);
|
|
@@ -400,19 +403,19 @@ class PaymentLinks extends ResourceBase {
|
|
|
400
403
|
}
|
|
401
404
|
}
|
|
402
405
|
|
|
403
|
-
// src/resources/
|
|
404
|
-
class
|
|
406
|
+
// src/resources/payments.ts
|
|
407
|
+
class Payments extends ResourceBase {
|
|
405
408
|
create(attributes) {
|
|
406
|
-
return this.httpPost("api/
|
|
409
|
+
return this.httpPost("api/payments", attributes);
|
|
407
410
|
}
|
|
408
411
|
get(id) {
|
|
409
|
-
return this.httpGet(this.encodePath("api/
|
|
412
|
+
return this.httpGet(this.encodePath("api/payments", id));
|
|
410
413
|
}
|
|
411
414
|
authorize(id, params) {
|
|
412
415
|
if (!params.signature || params.signature.trim() === "") {
|
|
413
416
|
throw new ManzaArgumentError("signature cannot be blank");
|
|
414
417
|
}
|
|
415
|
-
return this.httpPost(this.encodePath("api/
|
|
418
|
+
return this.httpPost(this.encodePath("api/payments", id, "authorize"), {
|
|
416
419
|
authorization_id: params.authorization_id,
|
|
417
420
|
signature: params.signature
|
|
418
421
|
});
|
|
@@ -421,7 +424,14 @@ class TransferDrafts extends ResourceBase {
|
|
|
421
424
|
const body = { authorization_id: params.authorization_id };
|
|
422
425
|
if (params.reason !== undefined && params.reason !== null)
|
|
423
426
|
body.reason = params.reason;
|
|
424
|
-
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");
|
|
425
435
|
}
|
|
426
436
|
}
|
|
427
437
|
|
|
@@ -478,7 +488,7 @@ class ManzaResponse {
|
|
|
478
488
|
}
|
|
479
489
|
|
|
480
490
|
// src/version.ts
|
|
481
|
-
var VERSION = "1.0
|
|
491
|
+
var VERSION = "1.1.0";
|
|
482
492
|
|
|
483
493
|
// src/client.ts
|
|
484
494
|
var DEFAULT_BASE_URL = "https://ma.manza.finance";
|
|
@@ -499,6 +509,8 @@ class Manza {
|
|
|
499
509
|
invoices;
|
|
500
510
|
payeeTrustRequests;
|
|
501
511
|
paymentLinks;
|
|
512
|
+
payments;
|
|
513
|
+
transferAuthorizer;
|
|
502
514
|
transferDrafts;
|
|
503
515
|
webhookEndpoints;
|
|
504
516
|
constructor(options = {}) {
|
|
@@ -519,7 +531,9 @@ class Manza {
|
|
|
519
531
|
this.invoices = new Invoices(this);
|
|
520
532
|
this.payeeTrustRequests = new PayeeTrustRequests(this);
|
|
521
533
|
this.paymentLinks = new PaymentLinks(this);
|
|
522
|
-
this.
|
|
534
|
+
this.payments = new Payments(this);
|
|
535
|
+
this.transferAuthorizer = new TransferAuthorizer(this);
|
|
536
|
+
this.transferDrafts = this.payments;
|
|
523
537
|
this.webhookEndpoints = new WebhookEndpoints(this);
|
|
524
538
|
}
|
|
525
539
|
async request(method, path, options = {}) {
|
|
@@ -634,6 +648,8 @@ function buildError(response) {
|
|
|
634
648
|
}
|
|
635
649
|
return new ManzaError(message ?? `Unexpected status ${response.status}`, opts);
|
|
636
650
|
}
|
|
651
|
+
// src/resources/transfer_drafts.ts
|
|
652
|
+
var TransferDrafts = Payments;
|
|
637
653
|
// src/transfer_authorization.ts
|
|
638
654
|
var SIGNATURE_VERSION = "manza.transfer-authorization.v1";
|
|
639
655
|
function signatureInput(fields) {
|
|
@@ -671,3 +687,106 @@ var TransferAuthorization = {
|
|
|
671
687
|
sign,
|
|
672
688
|
payeeFor
|
|
673
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
|
@@ -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
|
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,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,gBAA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AAE,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
|
@@ -329,19 +329,19 @@ class PaymentLinks extends ResourceBase {
|
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
// src/resources/
|
|
333
|
-
class
|
|
332
|
+
// src/resources/payments.ts
|
|
333
|
+
class Payments extends ResourceBase {
|
|
334
334
|
create(attributes) {
|
|
335
|
-
return this.httpPost("api/
|
|
335
|
+
return this.httpPost("api/payments", attributes);
|
|
336
336
|
}
|
|
337
337
|
get(id) {
|
|
338
|
-
return this.httpGet(this.encodePath("api/
|
|
338
|
+
return this.httpGet(this.encodePath("api/payments", id));
|
|
339
339
|
}
|
|
340
340
|
authorize(id, params) {
|
|
341
341
|
if (!params.signature || params.signature.trim() === "") {
|
|
342
342
|
throw new ManzaArgumentError("signature cannot be blank");
|
|
343
343
|
}
|
|
344
|
-
return this.httpPost(this.encodePath("api/
|
|
344
|
+
return this.httpPost(this.encodePath("api/payments", id, "authorize"), {
|
|
345
345
|
authorization_id: params.authorization_id,
|
|
346
346
|
signature: params.signature
|
|
347
347
|
});
|
|
@@ -350,7 +350,14 @@ class TransferDrafts extends ResourceBase {
|
|
|
350
350
|
const body = { authorization_id: params.authorization_id };
|
|
351
351
|
if (params.reason !== undefined && params.reason !== null)
|
|
352
352
|
body.reason = params.reason;
|
|
353
|
-
return this.httpPost(this.encodePath("api/
|
|
353
|
+
return this.httpPost(this.encodePath("api/payments", id, "decline"), body);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// src/resources/transfer_authorizer.ts
|
|
358
|
+
class TransferAuthorizer extends ResourceBase {
|
|
359
|
+
get() {
|
|
360
|
+
return this.httpGet("api/transfer_authorizer");
|
|
354
361
|
}
|
|
355
362
|
}
|
|
356
363
|
|
|
@@ -407,7 +414,7 @@ class ManzaResponse {
|
|
|
407
414
|
}
|
|
408
415
|
|
|
409
416
|
// src/version.ts
|
|
410
|
-
var VERSION = "1.0
|
|
417
|
+
var VERSION = "1.1.0";
|
|
411
418
|
|
|
412
419
|
// src/client.ts
|
|
413
420
|
var DEFAULT_BASE_URL = "https://ma.manza.finance";
|
|
@@ -428,6 +435,8 @@ class Manza {
|
|
|
428
435
|
invoices;
|
|
429
436
|
payeeTrustRequests;
|
|
430
437
|
paymentLinks;
|
|
438
|
+
payments;
|
|
439
|
+
transferAuthorizer;
|
|
431
440
|
transferDrafts;
|
|
432
441
|
webhookEndpoints;
|
|
433
442
|
constructor(options = {}) {
|
|
@@ -448,7 +457,9 @@ class Manza {
|
|
|
448
457
|
this.invoices = new Invoices(this);
|
|
449
458
|
this.payeeTrustRequests = new PayeeTrustRequests(this);
|
|
450
459
|
this.paymentLinks = new PaymentLinks(this);
|
|
451
|
-
this.
|
|
460
|
+
this.payments = new Payments(this);
|
|
461
|
+
this.transferAuthorizer = new TransferAuthorizer(this);
|
|
462
|
+
this.transferDrafts = this.payments;
|
|
452
463
|
this.webhookEndpoints = new WebhookEndpoints(this);
|
|
453
464
|
}
|
|
454
465
|
async request(method, path, options = {}) {
|
|
@@ -563,6 +574,8 @@ function buildError(response) {
|
|
|
563
574
|
}
|
|
564
575
|
return new ManzaError(message ?? `Unexpected status ${response.status}`, opts);
|
|
565
576
|
}
|
|
577
|
+
// src/resources/transfer_drafts.ts
|
|
578
|
+
var TransferDrafts = Payments;
|
|
566
579
|
// src/transfer_authorization.ts
|
|
567
580
|
var SIGNATURE_VERSION = "manza.transfer-authorization.v1";
|
|
568
581
|
function signatureInput(fields) {
|
|
@@ -600,6 +613,109 @@ var TransferAuthorization = {
|
|
|
600
613
|
sign,
|
|
601
614
|
payeeFor
|
|
602
615
|
};
|
|
616
|
+
// src/webhook.ts
|
|
617
|
+
var DEFAULT_TOLERANCE = 300;
|
|
618
|
+
function sign2(params) {
|
|
619
|
+
if (params.secret === "") {
|
|
620
|
+
return Promise.reject(new ManzaArgumentError("secret cannot be empty"));
|
|
621
|
+
}
|
|
622
|
+
return sign({
|
|
623
|
+
secret: params.secret,
|
|
624
|
+
signature_input: `${params.timestamp}.${params.payload}`
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
async function verify(params) {
|
|
628
|
+
return await signatureMatches(params.payload, params.signature, params.timestamp, params.secret) && timestampFresh(params.timestamp, params.tolerance, params.now);
|
|
629
|
+
}
|
|
630
|
+
async function constructEvent(params) {
|
|
631
|
+
const normalized = normalizeHeaders(params.headers);
|
|
632
|
+
const signature = header(normalized, "signature");
|
|
633
|
+
const timestamp = header(normalized, "timestamp");
|
|
634
|
+
if (!await signatureMatches(params.payload, signature, timestamp, params.secret)) {
|
|
635
|
+
throw new ManzaArgumentError("invalid webhook signature");
|
|
636
|
+
}
|
|
637
|
+
if (!timestampFresh(timestamp, params.tolerance, params.now)) {
|
|
638
|
+
throw new ManzaArgumentError("webhook timestamp outside tolerance");
|
|
639
|
+
}
|
|
640
|
+
let event;
|
|
641
|
+
try {
|
|
642
|
+
event = JSON.parse(params.payload);
|
|
643
|
+
} catch {
|
|
644
|
+
throw new ManzaArgumentError("webhook payload is not JSON");
|
|
645
|
+
}
|
|
646
|
+
if (event === null || typeof event !== "object" || Array.isArray(event)) {
|
|
647
|
+
throw new ManzaArgumentError("webhook payload is not a JSON object");
|
|
648
|
+
}
|
|
649
|
+
return event;
|
|
650
|
+
}
|
|
651
|
+
async function signatureMatches(payload, signature, timestamp, secret) {
|
|
652
|
+
if (typeof payload !== "string" || typeof secret !== "string" || secret === "")
|
|
653
|
+
return false;
|
|
654
|
+
if (typeof signature !== "string")
|
|
655
|
+
return false;
|
|
656
|
+
if (typeof timestamp !== "string" && typeof timestamp !== "number")
|
|
657
|
+
return false;
|
|
658
|
+
if (parseTimestamp(timestamp) === null)
|
|
659
|
+
return false;
|
|
660
|
+
const expected = await sign2({ payload, timestamp, secret });
|
|
661
|
+
return constantTimeEqual(expected, signature);
|
|
662
|
+
}
|
|
663
|
+
function constantTimeEqual(a, b) {
|
|
664
|
+
if (a.length !== b.length)
|
|
665
|
+
return false;
|
|
666
|
+
let diff = 0;
|
|
667
|
+
for (let i = 0;i < a.length; i++)
|
|
668
|
+
diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
669
|
+
return diff === 0;
|
|
670
|
+
}
|
|
671
|
+
function timestampFresh(timestamp, tolerance, now) {
|
|
672
|
+
if (tolerance === null)
|
|
673
|
+
return true;
|
|
674
|
+
const seconds = parseTimestamp(timestamp);
|
|
675
|
+
if (seconds === null)
|
|
676
|
+
return false;
|
|
677
|
+
const nowSeconds = Math.floor((now ?? new Date).getTime() / 1000);
|
|
678
|
+
return Math.abs(nowSeconds - seconds) <= (tolerance ?? DEFAULT_TOLERANCE);
|
|
679
|
+
}
|
|
680
|
+
function parseTimestamp(timestamp) {
|
|
681
|
+
if (typeof timestamp === "number")
|
|
682
|
+
return Number.isInteger(timestamp) ? timestamp : null;
|
|
683
|
+
if (typeof timestamp !== "string" || !/^[+-]?\d+$/.test(timestamp.trim()))
|
|
684
|
+
return null;
|
|
685
|
+
return Number.parseInt(timestamp, 10);
|
|
686
|
+
}
|
|
687
|
+
function normalizeHeaders(headers) {
|
|
688
|
+
const entries = [];
|
|
689
|
+
if (headers instanceof Headers) {
|
|
690
|
+
headers.forEach((value, name) => {
|
|
691
|
+
entries.push([name, value]);
|
|
692
|
+
});
|
|
693
|
+
} else {
|
|
694
|
+
entries.push(...Object.entries(headers ?? {}));
|
|
695
|
+
}
|
|
696
|
+
const normalized = new Map;
|
|
697
|
+
for (const [name, raw] of entries) {
|
|
698
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
699
|
+
if (value === undefined || value === null)
|
|
700
|
+
continue;
|
|
701
|
+
normalized.set(name.replace(/^HTTP_/i, "").replace(/_/g, "-").toLowerCase(), String(value));
|
|
702
|
+
}
|
|
703
|
+
return normalized;
|
|
704
|
+
}
|
|
705
|
+
function header(normalized, suffix) {
|
|
706
|
+
const manza = `x-manza-${suffix}`;
|
|
707
|
+
const value = normalized.has(manza) ? normalized.get(manza) : normalized.get(`x-zazu-${suffix}`);
|
|
708
|
+
if (value)
|
|
709
|
+
return value;
|
|
710
|
+
const name = suffix.charAt(0).toUpperCase() + suffix.slice(1);
|
|
711
|
+
throw new ManzaArgumentError(`missing X-Manza-${name} header`);
|
|
712
|
+
}
|
|
713
|
+
var Webhook = {
|
|
714
|
+
DEFAULT_TOLERANCE,
|
|
715
|
+
sign: sign2,
|
|
716
|
+
verify,
|
|
717
|
+
constructEvent
|
|
718
|
+
};
|
|
603
719
|
export {
|
|
604
720
|
Accounts,
|
|
605
721
|
Beneficiaries,
|
|
@@ -624,8 +740,11 @@ export {
|
|
|
624
740
|
Page,
|
|
625
741
|
PayeeTrustRequests,
|
|
626
742
|
PaymentLinks,
|
|
743
|
+
Payments,
|
|
627
744
|
TransferAuthorization,
|
|
745
|
+
TransferAuthorizer,
|
|
628
746
|
TransferDrafts,
|
|
629
747
|
VERSION,
|
|
748
|
+
Webhook,
|
|
630
749
|
WebhookEndpoints
|
|
631
750
|
};
|
|
@@ -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":"AAwCA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,qBAAa,QAAS,SAAQ,YAAY;IASxC,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;IAgBvC,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 @@
|
|
|
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;IAWlD,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC;CAG9B"}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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":"
|
|
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"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.0
|
|
1
|
+
export declare const VERSION = "1.1.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 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C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getmanza/sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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": "
|
|
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",
|