mppx 0.17.6 → 0.18.1
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 +43 -0
- package/dist/Currency.d.ts +59 -0
- package/dist/Currency.js +60 -0
- package/dist/Errors.d.ts +13 -0
- package/dist/Errors.js +15 -6
- package/dist/cli/cli.js +138 -138
- package/dist/cli/plugins/index.js +12 -12
- package/dist/cli/plugins/tempo.js +13 -1
- package/dist/client/Mppx.js +13 -4
- package/dist/client/internal/Fetch.d.ts +5 -0
- package/dist/client/internal/Fetch.js +16 -5
- package/dist/cloudflare/ChannelStore.d.ts +1 -2
- package/dist/cloudflare/ChannelStore.js +14 -20
- package/dist/cloudflare/Channels.d.ts +20 -2
- package/dist/cloudflare/Channels.js +47 -4
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/discovery/Discovery.d.ts +116 -9
- package/dist/discovery/Discovery.js +169 -0
- package/dist/evm/server/Charge.js +2 -3
- package/dist/evm/server/Methods.d.ts +1 -1
- package/dist/evm/server/Methods.js +3 -2
- package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.d.ts +4 -1
- package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.js +4 -1
- package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.d.ts +5 -5
- package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.js +1 -1
- package/dist/extensions/identity/{email-otp/internal/Attestation.d.ts → attestation/Token.d.ts} +40 -26
- package/dist/extensions/identity/{email-otp/internal/Attestation.js → attestation/Token.js} +18 -3
- package/dist/extensions/identity/{email-otp/internal → attestation}/Types.d.ts +14 -14
- package/dist/extensions/identity/attestation/client/index.d.ts +66 -0
- package/dist/extensions/identity/attestation/client/index.js +273 -0
- package/dist/extensions/identity/attestation/index.d.ts +20 -0
- package/dist/extensions/identity/attestation/index.js +18 -0
- package/dist/extensions/identity/attestation/internal/Cache.d.ts +120 -0
- package/dist/extensions/identity/attestation/internal/Cache.js +90 -0
- package/dist/extensions/identity/attestation/server/index.d.ts +66 -0
- package/dist/extensions/identity/attestation/server/index.js +119 -0
- package/dist/extensions/identity/email-otp/Constants.d.ts +5 -5
- package/dist/extensions/identity/email-otp/Constants.js +6 -5
- package/dist/extensions/identity/email-otp/Types.d.ts +4 -4
- package/dist/extensions/identity/email-otp/client/index.d.ts +22 -15
- package/dist/extensions/identity/email-otp/client/index.js +21 -9
- package/dist/extensions/identity/email-otp/index.d.ts +3 -8
- package/dist/extensions/identity/email-otp/index.js +3 -8
- package/dist/extensions/identity/email-otp/server/index.d.ts +16 -16
- package/dist/extensions/identity/email-otp/server/index.js +17 -14
- package/dist/extensions/identity/index.d.ts +6 -0
- package/dist/extensions/identity/index.js +6 -0
- package/dist/extensions/identity/internal/Verification.js +9 -5
- package/dist/extensions/identity/link/Constants.d.ts +102 -0
- package/dist/extensions/identity/link/Constants.js +16 -0
- package/dist/extensions/identity/link/client/index.d.ts +80 -0
- package/dist/extensions/identity/link/client/index.js +211 -0
- package/dist/extensions/identity/link/index.d.ts +12 -0
- package/dist/extensions/identity/link/index.js +12 -0
- package/dist/extensions/identity/link/server/index.d.ts +124 -0
- package/dist/extensions/identity/link/server/index.js +518 -0
- package/dist/extensions/identity/persona/Constants.d.ts +24 -0
- package/dist/extensions/identity/persona/Constants.js +24 -0
- package/dist/extensions/identity/persona/Did.d.ts +24 -0
- package/dist/extensions/identity/persona/Did.js +24 -0
- package/dist/extensions/identity/persona/Types.d.ts +21 -0
- package/dist/extensions/identity/persona/Types.js +2 -0
- package/dist/extensions/identity/persona/index.d.ts +10 -0
- package/dist/extensions/identity/persona/index.js +9 -0
- package/dist/extensions/identity/persona/server/index.d.ts +152 -0
- package/dist/extensions/identity/persona/server/index.js +263 -0
- package/dist/identity/Callback.d.ts +24 -5
- package/dist/identity/Callback.js +35 -11
- package/dist/identity/Client.d.ts +78 -5
- package/dist/identity/Client.js +165 -48
- package/dist/identity/Headers.d.ts +21 -0
- package/dist/identity/Headers.js +24 -0
- package/dist/identity/Server.d.ts +159 -37
- package/dist/identity/Server.js +309 -138
- package/dist/identity/Status.d.ts +14 -0
- package/dist/identity/Status.js +19 -0
- package/dist/identity/Types.d.ts +166 -65
- package/dist/identity/index.d.ts +2 -0
- package/dist/identity/index.js +2 -0
- package/dist/identity/internal/Requirements.d.ts +28 -0
- package/dist/identity/internal/Requirements.js +78 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/integrations/x402/Evm.d.ts +1 -0
- package/dist/internal/env.d.ts +14 -0
- package/dist/internal/env.js +38 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/proxy/internal/Headers.d.ts +1 -1
- package/dist/proxy/internal/Headers.js +11 -7
- package/dist/server/Mppx.d.ts +14 -6
- package/dist/server/Mppx.js +256 -149
- package/dist/server/internal/challengeMeta.d.ts +0 -6
- package/dist/server/internal/challengeMeta.js +3 -17
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/client/Charge.d.ts +11 -8
- package/dist/tempo/client/Charge.js +53 -6
- package/dist/tempo/index.d.ts +4 -0
- package/dist/tempo/index.js +4 -0
- package/dist/tempo/internal/auto-swap.d.ts +6 -5
- package/dist/tempo/internal/auto-swap.js +17 -2
- package/dist/tempo/internal/currencies.d.ts +5 -4
- package/dist/tempo/internal/currencies.js +13 -9
- package/dist/tempo/internal/defaults.d.ts +7 -0
- package/dist/tempo/internal/defaults.js +7 -0
- package/dist/tempo/internal/fee-payer.js +8 -2
- package/dist/tempo/internal/machine-token-charge.d.ts +52 -0
- package/dist/tempo/internal/machine-token-charge.js +82 -1
- package/dist/tempo/server/Charge.d.ts +14 -9
- package/dist/tempo/server/Charge.js +64 -3
- package/dist/tempo/server/Methods.d.ts +1 -1
- package/dist/tempo/server/Methods.js +4 -1
- package/dist/tempo/server/Subscription.d.ts +8 -0
- package/dist/tempo/server/internal/fallback-store.d.ts +7 -2
- package/dist/tempo/server/internal/fallback-store.js +12 -3
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/transport.d.ts +1 -1
- package/dist/tempo/server/internal/transport.js +9 -16
- package/dist/tempo/session/client/CredentialState.js +31 -0
- package/dist/tempo/session/client/Session.d.ts +12 -6
- package/dist/tempo/session/client/Session.js +64 -18
- package/dist/tempo/session/server/ChannelStore.d.ts +22 -1
- package/dist/tempo/session/server/ChannelStore.js +58 -8
- package/dist/tempo/session/server/CloseSupervisor.d.ts +5 -1
- package/dist/tempo/session/server/CloseSupervisor.js +110 -12
- package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
- package/dist/tempo/session/server/CredentialVerification.js +6 -32
- package/dist/tempo/session/server/Session.d.ts +5 -1
- package/dist/tempo/session/server/Session.js +6 -3
- package/dist/tempo/session/server/Settlement.d.ts +7 -0
- package/dist/tempo/session/server/Settlement.js +36 -6
- package/dist/tempo/session/server/Sse.d.ts +2 -0
- package/dist/tempo/session/server/Sse.js +12 -12
- package/dist/tempo/subscription/KeyAuthorization.d.ts +1 -1
- package/dist/tempo/subscription/KeyAuthorization.js +1 -1
- package/dist/x402/Assets.d.ts +14 -5
- package/dist/x402/Assets.js +11 -16
- package/package.json +19 -3
- package/dist/extensions/identity/email-otp/internal/Prover.d.ts +0 -46
- package/dist/extensions/identity/email-otp/internal/Prover.js +0 -168
- package/dist/extensions/identity/email-otp/internal/Verifier.d.ts +0 -56
- package/dist/extensions/identity/email-otp/internal/Verifier.js +0 -116
- /package/dist/extensions/identity/{email-otp/internal → attestation}/Types.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# mppx
|
|
2
2
|
|
|
3
|
+
## 0.18.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7663d93: Fixed Cloudflare settlement recovery for vouchers larger than recorded usage, capturing only the amount owed. Added a settlement backfill for channels left unscheduled before upgrading.
|
|
8
|
+
- 2a00add: Fixed automatic session settlement retries and preserved prepaid stream delivery during channel closure. Fixed mixed-case channel IDs in settlement backfills.
|
|
9
|
+
- e86c670: Added `listOperations` to `mppx/discovery`, which lists a discovery document's operations with typed offers and JSON request schemas. Typed the offers `PaymentInfo` returns.
|
|
10
|
+
- 066a75b: Added `mppx/extensions/identity/link`: server verifiers and client provers for Link agent identity attestations and Link-signed claims, such as a verified email. Added `Identity.Verifier.authorization`, which makes a route refuse a server without `requiresAuth: true`, and stopped proxies from forwarding `Identity-Presentation` headers and upstream identity challenges.
|
|
11
|
+
- 4071a6c: Added MACH onramp links to insufficient-balance errors. `Tempo.machineTokenFundingUrl` builds the Tempo Wallet link that buys MACH, and `PaymentError` gained an optional `fundingUrl`, serialized as a Problem Details extension member. On Tempo mainnet, the `tempo.charge` client now throws `InsufficientBalanceError` with the link when a MACH-enabled charge can't be paid from MACH or the charge currency, the session client does the same for a MACH channel deposit, servers link MACH payments rejected for a low MACH balance, and the `mppx` CLI treats a MACH-enabled charge as payable from a MACH balance.
|
|
12
|
+
- ee48ef6: Removed the package size limits from the package check; it still reports the sizes.
|
|
13
|
+
- 40b9535: Prevented automatic payments during email OTP requests through identity-wrapped fetch clients. Added `Fetch.withoutPayment` to explicitly disable payments for a request.
|
|
14
|
+
- dd571b3: Added `mppx/extensions/identity/persona`: `Persona.Server.create` starts Persona inquiries and returns a payment check and a request-stage verifier that require an approved inquiry, with an onboarding link on rejection and an optional approval cache. `Persona.Server.verifyWallet` links a wallet to a person before KYC, and `Persona.did` builds a wallet's reference ID.
|
|
15
|
+
- 6e32317: Fixed composed subscription routes retaining request-derived dispatch state and accepting overlapping identity policies.
|
|
16
|
+
- 75aee4b: Added the `Currency` module and accepted `viem/tokens` tokens, chain-indexed (`ousd`) or resolved to one chain (`ousd(4217)`), everywhere a currency is configured: Tempo charge and session client `currencies`, `autoSwap.tokenIn`, Tempo server `currencies`, and EVM and x402 `currencies`, with token decimals used for `maxAmount`, `maxDeposit` and `topUpAmount`.
|
|
17
|
+
|
|
18
|
+
## 0.18.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- de802b9: Reworked identity verification around explicit statuses and data.
|
|
23
|
+
|
|
24
|
+
- Changed `Identity.Verification` to fixed statuses: `valid`, `missing` (401), `invalid` (401), `forbidden` (403) and `unavailable` (503), exported as `Identity.Status.codes` with the precedence list `Identity.Status.precedence`. When several verifiers (or every `anyOf` member) reject, the status with the highest precedence decides, and the headers of every rejection are merged. **Breaking:** `missing` now answers 401 instead of 403.
|
|
25
|
+
- Added `status` to `Identity.Rejection` (`invalid`, `forbidden` or `unavailable`).
|
|
26
|
+
- Marked identity rejections with a `rejection` field (`{ stage, status, reason }`) on the route result's non-200 branch, which `compose` now reads.
|
|
27
|
+
- Replaced payment-stage verifiers with an experimental payment check, `identity: { request, payment }`: `payment.requires` is listed in every 402's new `Identity-Required` header (merged across composed offers), and `payment.verify` runs once on the paid retry with the Credential. **Breaking:** `stage: 'payment'` verifiers now throw, the identity nonce is no longer added to Challenges, and request verifiers' `verify` receives only the request.
|
|
28
|
+
- Routes with a payment check reject x402 Credentials and do not offer x402. `compose` requires every payment check in a route to be the same one, and refuses a checked and an unchecked offer with the same payment terms, since a Credential could reach either.
|
|
29
|
+
- Changed `Prover.prepare` to receive the selected Challenge and the parsed `Identity-Required` requirements, and `Prover.retry` to return headers to resend with.
|
|
30
|
+
- Deprecated `Verifier.stage`, `Verifier.challenge`, the `code` of `missing` and `invalid` outcomes and `Identity.Rejection`'s `code`, and a `retry` result of `true`. They keep working.
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 802a27a: **Behavior change in production:** Changed `tempo.charge()`, `tempo.session()`, `tempo.subscription()` and `tempo()` to throw at construction when no `store` is passed and `NODE_ENV` is `production`, the server runs on a multi-instance platform (Vercel, AWS Lambda, Netlify, Fly.io, Cloud Run, Render, Railway, Heroku, Deno Deploy) or on Cloudflare Workers, instead of silently keeping replay protection and sponsor budgets in per-instance memory. Pass a shared store, or `store: Store.memory()` to keep instance-local state; local development and tests still fall back to memory with a warning. Charges served through `relay` need no store, since the relay enforces single use.
|
|
35
|
+
- 454b9e0: Added `mppx/extensions/identity/attestation` and rebuilt the identity extensions on fixed statuses.
|
|
36
|
+
|
|
37
|
+
- Added the attestation module (`Attestation` from `mppx/extensions/identity`): `Attestation.Server.verifier` for any attestation type, `Attestation.Client.prover`, `Attestation.sign`, `decode` and `verify` for issuers, `Attestation.Jwks.resolver` and `Attestation.Constants`. The attestation wire format and the `Identity-Attestation` header are unchanged.
|
|
38
|
+
- Grouped alternatives in `Identity-Attestation-Required`: `Identity.anyOf` lists its members' requirements as one inner list, and the prover meets each group with one attestation, the first that succeeds in listed order, so a route accepting any of several issuers costs one code. `Attestation.Client.requirements` returns these groups.
|
|
39
|
+
- Rebuilt `EmailOtp` on it, with the same public API. Deprecated `EmailOtp.Constants.header` and `requiredHeader` in favor of `Attestation.Constants`.
|
|
40
|
+
- Added `Identity.Headers`, the identity request headers that never cross origins or reach upstream and the identity response headers a proxy drops, and `Prover.headers` for a prover's own sensitive request headers. The client's cross-origin redirect stripping and the proxy now read them instead of hardcoded names.
|
|
41
|
+
- Added a second `Prover.retry` parameter, `{ request }`: the request that got the rejected response.
|
|
42
|
+
- Simplified the attestation prover: it caches one attestation per audience, issuer and type, sends every unexpired one on a paid attempt and only those outside the refresh margin (`min(300s, half the lifetime)`) on an unpaid one, and its `retry` returns the attestations to resend with. Fixed a paid retry dropping an attestation close to expiry, and a late 401 on a concurrent request discarding a just-obtained attestation and asking for another code.
|
|
43
|
+
- Moved the identity extensions to fixed statuses: an untrusted or unresolvable signature key and an attestation the route's policy rejects are `forbidden` (403), an unreachable issuer key set is `unavailable` (503). `Attestation.verify` returns `unavailable` instead of `invalid` with `unavailable: true`.
|
|
44
|
+
- Deprecated the function form of `audience` in `Attestation.Server.verifier` and `EmailOtp.Server.verifier`: it is only safe where the platform guarantees the request's host.
|
|
45
|
+
|
|
3
46
|
## 0.17.6
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Address, ResolvedToken } from 'viem';
|
|
2
|
+
import type { Token } from 'viem/tokens';
|
|
3
|
+
/**
|
|
4
|
+
* A currency accepted anywhere mppx takes one: a token address, a chain-indexed token from
|
|
5
|
+
* `viem/tokens` (such as `ousd`), or a token resolved to one chain (such as `ousd(4217)`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { ousd, usdc } from 'viem/tokens'
|
|
10
|
+
*
|
|
11
|
+
* const currencies = [ousd, usdc(8453), '0x20c0000000000000000000000000000000000000']
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type Currency = Address | Token | ResolvedToken;
|
|
15
|
+
/** A currency resolved to one chain. `decimals` is `undefined` for an address configured without decimals. */
|
|
16
|
+
export type Resolved = Omit<ResolvedToken, 'decimals'> & {
|
|
17
|
+
decimals: number | undefined;
|
|
18
|
+
};
|
|
19
|
+
/** Returns true when a value is a chain-indexed token from `viem/tokens`. */
|
|
20
|
+
export declare function isToken(value: unknown): value is Token;
|
|
21
|
+
/** Returns true when a value is a token resolved to one chain, such as `ousd(4217)`. */
|
|
22
|
+
export declare function isResolvedToken(value: unknown): value is ResolvedToken;
|
|
23
|
+
/** Returns the chain a currency is bound to: a resolved token's `chainId`, otherwise `undefined`. */
|
|
24
|
+
export declare function chainIdOf(currency: Currency): number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves a currency for `chainId`: a token by its addresses, a resolved token only on its own
|
|
27
|
+
* chain, and an address on any chain with `decimals`. Returns `undefined` when the currency has no
|
|
28
|
+
* address on `chainId`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolve(currency: Currency, options: resolve.Options): Resolved | undefined;
|
|
31
|
+
export declare namespace resolve {
|
|
32
|
+
type Options = {
|
|
33
|
+
/** Chain to resolve the currency for. */
|
|
34
|
+
chainId: number;
|
|
35
|
+
/** Decimals of an address currency. Tokens carry their own. */
|
|
36
|
+
decimals?: number | undefined;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the first currency in `currencies` that is `address`, compared case-insensitively, with
|
|
41
|
+
* its decimals: an address as is, and a token on `chainId`, or on any chain it lists when
|
|
42
|
+
* `chainId` is omitted.
|
|
43
|
+
*/
|
|
44
|
+
export declare function find(currencies: readonly Currency[], address: string, options?: find.Options): find.ReturnType | undefined;
|
|
45
|
+
export declare namespace find {
|
|
46
|
+
type Options = {
|
|
47
|
+
/** Chain the address is on. When omitted, tokens match on any chain they list. */
|
|
48
|
+
chainId?: number | undefined;
|
|
49
|
+
/** Decimals of an address currency. Tokens carry their own. */
|
|
50
|
+
decimals?: number | undefined;
|
|
51
|
+
};
|
|
52
|
+
type ReturnType = {
|
|
53
|
+
/** The matching currency. */
|
|
54
|
+
currency: Currency;
|
|
55
|
+
/** Its decimals: the token's, or the configured `decimals` for an address. */
|
|
56
|
+
decimals: number | undefined;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=Currency.d.ts.map
|
package/dist/Currency.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Returns true when a value is a chain-indexed token from `viem/tokens`. */
|
|
2
|
+
export function isToken(value) {
|
|
3
|
+
return (typeof value === 'function' &&
|
|
4
|
+
typeof value.addresses === 'object' &&
|
|
5
|
+
typeof value.decimals === 'number');
|
|
6
|
+
}
|
|
7
|
+
/** Returns true when a value is a token resolved to one chain, such as `ousd(4217)`. */
|
|
8
|
+
export function isResolvedToken(value) {
|
|
9
|
+
if (typeof value !== 'object' || value === null)
|
|
10
|
+
return false;
|
|
11
|
+
const { address, chainId, decimals } = value;
|
|
12
|
+
return typeof address === 'string' && typeof chainId === 'number' && typeof decimals === 'number';
|
|
13
|
+
}
|
|
14
|
+
/** Returns the chain a currency is bound to: a resolved token's `chainId`, otherwise `undefined`. */
|
|
15
|
+
export function chainIdOf(currency) {
|
|
16
|
+
return isResolvedToken(currency) ? currency.chainId : undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a currency for `chainId`: a token by its addresses, a resolved token only on its own
|
|
20
|
+
* chain, and an address on any chain with `decimals`. Returns `undefined` when the currency has no
|
|
21
|
+
* address on `chainId`.
|
|
22
|
+
*/
|
|
23
|
+
export function resolve(currency, options) {
|
|
24
|
+
const { chainId, decimals } = options;
|
|
25
|
+
if (typeof currency === 'string')
|
|
26
|
+
return { address: currency, chainId, decimals };
|
|
27
|
+
if (isToken(currency)) {
|
|
28
|
+
if (!currency.addresses[chainId])
|
|
29
|
+
return undefined;
|
|
30
|
+
return currency(chainId);
|
|
31
|
+
}
|
|
32
|
+
if (currency.chainId !== chainId)
|
|
33
|
+
return undefined;
|
|
34
|
+
return currency;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the first currency in `currencies` that is `address`, compared case-insensitively, with
|
|
38
|
+
* its decimals: an address as is, and a token on `chainId`, or on any chain it lists when
|
|
39
|
+
* `chainId` is omitted.
|
|
40
|
+
*/
|
|
41
|
+
export function find(currencies, address, options = {}) {
|
|
42
|
+
const { chainId, decimals } = options;
|
|
43
|
+
const matches = (value) => value.toLowerCase() === address.toLowerCase();
|
|
44
|
+
for (const currency of currencies) {
|
|
45
|
+
if (typeof currency === 'string') {
|
|
46
|
+
if (matches(currency))
|
|
47
|
+
return { currency, decimals };
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const candidates = chainId !== undefined
|
|
51
|
+
? [resolve(currency, { chainId })]
|
|
52
|
+
: isToken(currency)
|
|
53
|
+
? Object.keys(currency.addresses).map((id) => resolve(currency, { chainId: Number(id) }))
|
|
54
|
+
: [currency];
|
|
55
|
+
if (candidates.some((candidate) => candidate && matches(candidate.address)))
|
|
56
|
+
return { currency, decimals: currency.decimals };
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=Currency.js.map
|
package/dist/Errors.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export declare abstract class PaymentError extends Error {
|
|
|
19
19
|
readonly status: number;
|
|
20
20
|
/** Actionable hint for resolving the error (RFC 9457 extension member). */
|
|
21
21
|
readonly hint: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Page where the payer can get the funds this payment needs, such as the MACH onramp
|
|
24
|
+
* (RFC 9457 extension member).
|
|
25
|
+
*/
|
|
26
|
+
readonly fundingUrl: string | undefined;
|
|
22
27
|
protected constructor(message: string, options?: PaymentError.Options);
|
|
23
28
|
/** Converts the error to RFC 9457 Problem Details format. */
|
|
24
29
|
toProblemDetails(challengeId?: string): PaymentError.ProblemDetails;
|
|
@@ -28,6 +33,8 @@ export declare namespace PaymentError {
|
|
|
28
33
|
/** Underlying error. Never serialized into Problem Details. */
|
|
29
34
|
cause?: unknown;
|
|
30
35
|
details?: Record<string, unknown> | undefined;
|
|
36
|
+
/** Page where the payer can get the funds this payment needs. */
|
|
37
|
+
fundingUrl?: string | undefined;
|
|
31
38
|
};
|
|
32
39
|
type ProblemDetails = {
|
|
33
40
|
/** RFC 9457 Problem Details type URI. */
|
|
@@ -42,6 +49,8 @@ export declare namespace PaymentError {
|
|
|
42
49
|
details?: Readonly<Record<string, unknown>>;
|
|
43
50
|
/** Actionable hint for resolving the error (RFC 9457 extension member). */
|
|
44
51
|
hint?: string;
|
|
52
|
+
/** Page where the payer can get the funds this payment needs (RFC 9457 extension member). */
|
|
53
|
+
fundingUrl?: string;
|
|
45
54
|
/** Associated challenge ID, if applicable. */
|
|
46
55
|
challengeId?: string;
|
|
47
56
|
};
|
|
@@ -94,6 +103,8 @@ export declare namespace VerificationFailedError {
|
|
|
94
103
|
type Options = {
|
|
95
104
|
/** Safe method-specific diagnostic context. */
|
|
96
105
|
details?: Record<string, unknown> | undefined;
|
|
106
|
+
/** Page where the payer can get the funds the payment lacked. */
|
|
107
|
+
fundingUrl?: string | undefined;
|
|
97
108
|
/** Reason verification failed (e.g., "invalid signature", "insufficient amount"). */
|
|
98
109
|
reason?: string;
|
|
99
110
|
};
|
|
@@ -381,6 +392,8 @@ export declare class InsufficientBalanceError extends PaymentError {
|
|
|
381
392
|
}
|
|
382
393
|
export declare namespace InsufficientBalanceError {
|
|
383
394
|
type Options = {
|
|
395
|
+
/** Page where the payer can get the funds, such as the MACH onramp. */
|
|
396
|
+
fundingUrl?: string | undefined;
|
|
384
397
|
/** Reason for insufficient balance. */
|
|
385
398
|
reason?: string;
|
|
386
399
|
};
|
package/dist/Errors.js
CHANGED
|
@@ -4,6 +4,10 @@ export const Hints = {
|
|
|
4
4
|
malformedCredential: 'Use a supported wallet to construct valid credentials for one of the supported payment methods returned in the WWW-Authenticate header. See https://mpp.dev/tools/wallet.md',
|
|
5
5
|
methodUnsupported: 'Use a supported wallet to pay for this resource using one of the supported payment methods returned in the WWW-Authenticate header. See https://mpp.dev/tools/wallet.md',
|
|
6
6
|
};
|
|
7
|
+
/** Appends where to get funds to an error message. */
|
|
8
|
+
function withFundingUrl(message, fundingUrl) {
|
|
9
|
+
return fundingUrl ? `${message} Add funds at ${fundingUrl}` : message;
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
12
|
* Base class for all payment-related errors.
|
|
9
13
|
*/
|
|
@@ -14,9 +18,15 @@ export class PaymentError extends Error {
|
|
|
14
18
|
status = 402;
|
|
15
19
|
/** Actionable hint for resolving the error (RFC 9457 extension member). */
|
|
16
20
|
hint;
|
|
21
|
+
/**
|
|
22
|
+
* Page where the payer can get the funds this payment needs, such as the MACH onramp
|
|
23
|
+
* (RFC 9457 extension member).
|
|
24
|
+
*/
|
|
25
|
+
fundingUrl;
|
|
17
26
|
constructor(message, options = {}) {
|
|
18
27
|
super(message);
|
|
19
28
|
this.details = options.details;
|
|
29
|
+
this.fundingUrl = options.fundingUrl;
|
|
20
30
|
// Defined manually (non-enumerable, like native `cause`) so consumers on pre-ES2022 libs still typecheck.
|
|
21
31
|
if (options.cause !== undefined)
|
|
22
32
|
Object.defineProperty(this, 'cause', {
|
|
@@ -34,6 +44,7 @@ export class PaymentError extends Error {
|
|
|
34
44
|
detail: this.message,
|
|
35
45
|
...(this.details && Object.keys(this.details).length > 0 && { details: this.details }),
|
|
36
46
|
...(this.hint && { hint: this.hint }),
|
|
47
|
+
...(this.fundingUrl && { fundingUrl: this.fundingUrl }),
|
|
37
48
|
...(challengeId && { challengeId }),
|
|
38
49
|
};
|
|
39
50
|
}
|
|
@@ -75,10 +86,8 @@ export class VerificationFailedError extends PaymentError {
|
|
|
75
86
|
title = 'Verification Failed';
|
|
76
87
|
type = 'https://paymentauth.org/problems/verification-failed';
|
|
77
88
|
constructor(options = {}) {
|
|
78
|
-
const { details, reason } = options;
|
|
79
|
-
super(reason ? `Payment verification failed: ${reason}.` : 'Payment verification failed.', {
|
|
80
|
-
details,
|
|
81
|
-
});
|
|
89
|
+
const { details, fundingUrl, reason } = options;
|
|
90
|
+
super(withFundingUrl(reason ? `Payment verification failed: ${reason}.` : 'Payment verification failed.', fundingUrl), { details, fundingUrl });
|
|
82
91
|
}
|
|
83
92
|
}
|
|
84
93
|
/**
|
|
@@ -319,8 +328,8 @@ export class InsufficientBalanceError extends PaymentError {
|
|
|
319
328
|
status = 402;
|
|
320
329
|
type = 'https://paymentauth.org/problems/session/insufficient-balance';
|
|
321
330
|
constructor(options = {}) {
|
|
322
|
-
const { reason } = options;
|
|
323
|
-
super(reason ? `Insufficient balance: ${reason}.` : 'Insufficient balance.');
|
|
331
|
+
const { fundingUrl, reason } = options;
|
|
332
|
+
super(withFundingUrl(reason ? `Insufficient balance: ${reason}.` : 'Insufficient balance.', fundingUrl), { fundingUrl });
|
|
324
333
|
}
|
|
325
334
|
}
|
|
326
335
|
/**
|