@strimz/sdk 0.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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/browser-client-DlZg0Aae.d.cts +223 -0
- package/dist/browser-client-DlZg0Aae.d.ts +223 -0
- package/dist/browser-client.cjs +443 -0
- package/dist/browser-client.cjs.map +1 -0
- package/dist/browser-client.d.cts +4 -0
- package/dist/browser-client.d.ts +4 -0
- package/dist/browser-client.js +439 -0
- package/dist/browser-client.js.map +1 -0
- package/dist/eip712.cjs +70 -0
- package/dist/eip712.cjs.map +1 -0
- package/dist/eip712.d.cts +181 -0
- package/dist/eip712.d.ts +181 -0
- package/dist/eip712.js +65 -0
- package/dist/eip712.js.map +1 -0
- package/dist/errors.cjs +102 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +56 -0
- package/dist/errors.d.ts +56 -0
- package/dist/errors.js +90 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +831 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +193 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +806 -0
- package/dist/index.js.map +1 -0
- package/dist/webhooks.cjs +54 -0
- package/dist/webhooks.cjs.map +1 -0
- package/dist/webhooks.d.cts +19 -0
- package/dist/webhooks.d.ts +19 -0
- package/dist/webhooks.js +13 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +94 -0
- package/src/browser-client.ts +97 -0
- package/src/client.ts +122 -0
- package/src/eip712/index.ts +25 -0
- package/src/eip712/permit.ts +74 -0
- package/src/eip712/receive-with-authorization.ts +88 -0
- package/src/eip712/types.ts +46 -0
- package/src/errors.ts +138 -0
- package/src/http/fetcher.ts +226 -0
- package/src/http/headers.ts +32 -0
- package/src/idempotency.ts +20 -0
- package/src/index.ts +77 -0
- package/src/pagination.ts +48 -0
- package/src/resources/agents.ts +64 -0
- package/src/resources/api-keys.ts +29 -0
- package/src/resources/base-resource.ts +116 -0
- package/src/resources/checkout.ts +32 -0
- package/src/resources/customers.ts +25 -0
- package/src/resources/invoices.ts +31 -0
- package/src/resources/merchants.ts +26 -0
- package/src/resources/payment-sessions.ts +41 -0
- package/src/resources/refunds.ts +36 -0
- package/src/resources/storefronts.ts +62 -0
- package/src/resources/subscription-plans.ts +32 -0
- package/src/resources/subscriptions.ts +37 -0
- package/src/resources/tokens.ts +70 -0
- package/src/resources/transactions.ts +20 -0
- package/src/resources/webhook-deliveries.ts +29 -0
- package/src/resources/webhook-endpoints.ts +56 -0
- package/src/webhooks.ts +64 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical EIP-712 typed-data shape.
|
|
3
|
+
*
|
|
4
|
+
* Matches the structure every major wallet library accepts —
|
|
5
|
+
* viem's `signTypedData`
|
|
6
|
+
* ethers' `signer._signTypedData`
|
|
7
|
+
* Privy's `signTypedData`
|
|
8
|
+
* Reown AppKit's typed-data RPC
|
|
9
|
+
* — so the SDK can produce typed-data without binding to a specific
|
|
10
|
+
* wallet client. Consumers pipe the result into whichever signer they
|
|
11
|
+
* already use.
|
|
12
|
+
*
|
|
13
|
+
* No viem/ethers dependency on purpose: the SDK stays minimal, and
|
|
14
|
+
* apps can choose their own signing stack.
|
|
15
|
+
*/
|
|
16
|
+
interface Eip712Domain {
|
|
17
|
+
name?: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
chainId?: number;
|
|
20
|
+
verifyingContract?: `0x${string}`;
|
|
21
|
+
salt?: `0x${string}`;
|
|
22
|
+
}
|
|
23
|
+
interface Eip712Field {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
}
|
|
27
|
+
type Eip712Types = Record<string, readonly Eip712Field[]>;
|
|
28
|
+
/**
|
|
29
|
+
* EIP-712 typed-data definition. `primaryType` names the struct that
|
|
30
|
+
* gets hashed at the top level (the `types` object usually contains
|
|
31
|
+
* additional referenced sub-structs).
|
|
32
|
+
*
|
|
33
|
+
* `bigint` is used for uint values; wallet libs handle the conversion
|
|
34
|
+
* to hex/decimal at signing time. If a consumer needs to JSON-serialise
|
|
35
|
+
* this object, convert bigints to strings at that boundary.
|
|
36
|
+
*/
|
|
37
|
+
interface Eip712TypedData<TPrimary extends string = string> {
|
|
38
|
+
domain: Eip712Domain;
|
|
39
|
+
types: Eip712Types;
|
|
40
|
+
primaryType: TPrimary;
|
|
41
|
+
message: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Inputs for the EIP-3009 ReceiveWithAuthorization typed-data.
|
|
46
|
+
*
|
|
47
|
+
* - `chainId` is the EVM chain id (Arc Testnet = 5042002).
|
|
48
|
+
* - `token` is the ERC-20 contract whose `receiveWithAuthorization` is
|
|
49
|
+
* being invoked — usually USDC at `0x36...` on Arc.
|
|
50
|
+
* - `tokenName` and `tokenVersion` form the EIP-712 domain. Real USDC
|
|
51
|
+
* on most chains uses `name="USD Coin"` and `version="2"`; tests
|
|
52
|
+
* use whatever the mock token reports. Always read these from the
|
|
53
|
+
* token contract at runtime to avoid drift.
|
|
54
|
+
* - `from` is the payer; the wallet that produces the signature must
|
|
55
|
+
* match this address.
|
|
56
|
+
* - `to` is the recipient of the funds — for Strimz this is the
|
|
57
|
+
* StrimzPayments contract address (the contract pulls funds into
|
|
58
|
+
* itself, then forwards the fee + net split).
|
|
59
|
+
* - `value` is the gross amount in token base units.
|
|
60
|
+
* - `validAfter` / `validBefore` are unix-second timestamps bounding
|
|
61
|
+
* the signature's validity. Strimz's default checkout window is
|
|
62
|
+
* 5 minutes; integrators may widen this for usage-based billing.
|
|
63
|
+
* - `nonce` is a single-use 32-byte value. Generate with crypto.randomBytes
|
|
64
|
+
* (server) or crypto.getRandomValues (browser). The token contract
|
|
65
|
+
* tracks `(authorizer, nonce) -> used` and rejects replays.
|
|
66
|
+
*/
|
|
67
|
+
interface ReceiveWithAuthorizationParams {
|
|
68
|
+
chainId: number;
|
|
69
|
+
token: `0x${string}`;
|
|
70
|
+
tokenName: string;
|
|
71
|
+
tokenVersion: string;
|
|
72
|
+
from: `0x${string}`;
|
|
73
|
+
to: `0x${string}`;
|
|
74
|
+
value: bigint;
|
|
75
|
+
validAfter: bigint;
|
|
76
|
+
validBefore: bigint;
|
|
77
|
+
nonce: `0x${string}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* EIP-712 type definition for `ReceiveWithAuthorization`. Stable —
|
|
81
|
+
* shared by every EIP-3009 implementation (USDC, EURC, etc.).
|
|
82
|
+
*
|
|
83
|
+
* Exported so consumers can introspect or extend with sibling
|
|
84
|
+
* primitive types (e.g. for x402 batched signing schemes that wrap
|
|
85
|
+
* multiple authorizations in one signature).
|
|
86
|
+
*/
|
|
87
|
+
declare const RECEIVE_WITH_AUTHORIZATION_TYPES: {
|
|
88
|
+
readonly ReceiveWithAuthorization: readonly [{
|
|
89
|
+
readonly name: "from";
|
|
90
|
+
readonly type: "address";
|
|
91
|
+
}, {
|
|
92
|
+
readonly name: "to";
|
|
93
|
+
readonly type: "address";
|
|
94
|
+
}, {
|
|
95
|
+
readonly name: "value";
|
|
96
|
+
readonly type: "uint256";
|
|
97
|
+
}, {
|
|
98
|
+
readonly name: "validAfter";
|
|
99
|
+
readonly type: "uint256";
|
|
100
|
+
}, {
|
|
101
|
+
readonly name: "validBefore";
|
|
102
|
+
readonly type: "uint256";
|
|
103
|
+
}, {
|
|
104
|
+
readonly name: "nonce";
|
|
105
|
+
readonly type: "bytes32";
|
|
106
|
+
}];
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Build the typed-data structure for an EIP-3009
|
|
110
|
+
* `ReceiveWithAuthorization` signature. Returns the canonical shape
|
|
111
|
+
* compatible with viem, ethers, Privy, and Reown.
|
|
112
|
+
*
|
|
113
|
+
* Pass the result to `walletClient.signTypedData(typedData)` (viem)
|
|
114
|
+
* or `signer._signTypedData(domain, types, message)` (ethers) — the
|
|
115
|
+
* SDK does not bind to a specific signer.
|
|
116
|
+
*/
|
|
117
|
+
declare function buildReceiveWithAuthorizationTypedData(params: ReceiveWithAuthorizationParams): Eip712TypedData<'ReceiveWithAuthorization'>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Inputs for the EIP-2612 Permit typed-data.
|
|
121
|
+
*
|
|
122
|
+
* - `chainId`, `token`, `tokenName`, `tokenVersion` form the EIP-712
|
|
123
|
+
* domain (same shape as the EIP-3009 builder).
|
|
124
|
+
* - `owner` is the token holder authorising the allowance — must match
|
|
125
|
+
* the signing wallet.
|
|
126
|
+
* - `spender` is the contract that will pull funds — for Strimz
|
|
127
|
+
* subscriptions this is the StrimzSubscriptions contract.
|
|
128
|
+
* - `value` is the allowance to grant in token base units.
|
|
129
|
+
* `type(uint256).max` produces an unlimited allowance and is the
|
|
130
|
+
* common case for subscription enrolment.
|
|
131
|
+
* - `nonce` is the owner's *current* `nonces(owner)` reading from the
|
|
132
|
+
* token contract. The SDK does not fetch this — the caller is
|
|
133
|
+
* expected to have just queried it. Race-free: the token rejects
|
|
134
|
+
* stale nonces, so a concurrent permit on the same owner just
|
|
135
|
+
* causes one to fail predictably.
|
|
136
|
+
* - `deadline` is the unix-second timestamp after which the permit
|
|
137
|
+
* expires. Strimz default for subscription enrolment is 24h —
|
|
138
|
+
* enough headroom for a slow merchant submit pipeline without
|
|
139
|
+
* leaving an indefinite signature window.
|
|
140
|
+
*/
|
|
141
|
+
interface PermitParams {
|
|
142
|
+
chainId: number;
|
|
143
|
+
token: `0x${string}`;
|
|
144
|
+
tokenName: string;
|
|
145
|
+
tokenVersion: string;
|
|
146
|
+
owner: `0x${string}`;
|
|
147
|
+
spender: `0x${string}`;
|
|
148
|
+
value: bigint;
|
|
149
|
+
nonce: bigint;
|
|
150
|
+
deadline: bigint;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* EIP-712 type definition for `Permit`. Stable across every EIP-2612
|
|
154
|
+
* implementation (USDC, EURC, DAI v2, etc.).
|
|
155
|
+
*/
|
|
156
|
+
declare const PERMIT_TYPES: {
|
|
157
|
+
readonly Permit: readonly [{
|
|
158
|
+
readonly name: "owner";
|
|
159
|
+
readonly type: "address";
|
|
160
|
+
}, {
|
|
161
|
+
readonly name: "spender";
|
|
162
|
+
readonly type: "address";
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "value";
|
|
165
|
+
readonly type: "uint256";
|
|
166
|
+
}, {
|
|
167
|
+
readonly name: "nonce";
|
|
168
|
+
readonly type: "uint256";
|
|
169
|
+
}, {
|
|
170
|
+
readonly name: "deadline";
|
|
171
|
+
readonly type: "uint256";
|
|
172
|
+
}];
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Build the typed-data structure for an EIP-2612 `Permit` signature.
|
|
176
|
+
* Returns the canonical shape compatible with viem, ethers, Privy,
|
|
177
|
+
* and Reown.
|
|
178
|
+
*/
|
|
179
|
+
declare function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'>;
|
|
180
|
+
|
|
181
|
+
export { type Eip712Domain, type Eip712Field, type Eip712TypedData, type Eip712Types, PERMIT_TYPES, type PermitParams, RECEIVE_WITH_AUTHORIZATION_TYPES, type ReceiveWithAuthorizationParams, buildPermitTypedData, buildReceiveWithAuthorizationTypedData };
|
package/dist/eip712.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical EIP-712 typed-data shape.
|
|
3
|
+
*
|
|
4
|
+
* Matches the structure every major wallet library accepts —
|
|
5
|
+
* viem's `signTypedData`
|
|
6
|
+
* ethers' `signer._signTypedData`
|
|
7
|
+
* Privy's `signTypedData`
|
|
8
|
+
* Reown AppKit's typed-data RPC
|
|
9
|
+
* — so the SDK can produce typed-data without binding to a specific
|
|
10
|
+
* wallet client. Consumers pipe the result into whichever signer they
|
|
11
|
+
* already use.
|
|
12
|
+
*
|
|
13
|
+
* No viem/ethers dependency on purpose: the SDK stays minimal, and
|
|
14
|
+
* apps can choose their own signing stack.
|
|
15
|
+
*/
|
|
16
|
+
interface Eip712Domain {
|
|
17
|
+
name?: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
chainId?: number;
|
|
20
|
+
verifyingContract?: `0x${string}`;
|
|
21
|
+
salt?: `0x${string}`;
|
|
22
|
+
}
|
|
23
|
+
interface Eip712Field {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
}
|
|
27
|
+
type Eip712Types = Record<string, readonly Eip712Field[]>;
|
|
28
|
+
/**
|
|
29
|
+
* EIP-712 typed-data definition. `primaryType` names the struct that
|
|
30
|
+
* gets hashed at the top level (the `types` object usually contains
|
|
31
|
+
* additional referenced sub-structs).
|
|
32
|
+
*
|
|
33
|
+
* `bigint` is used for uint values; wallet libs handle the conversion
|
|
34
|
+
* to hex/decimal at signing time. If a consumer needs to JSON-serialise
|
|
35
|
+
* this object, convert bigints to strings at that boundary.
|
|
36
|
+
*/
|
|
37
|
+
interface Eip712TypedData<TPrimary extends string = string> {
|
|
38
|
+
domain: Eip712Domain;
|
|
39
|
+
types: Eip712Types;
|
|
40
|
+
primaryType: TPrimary;
|
|
41
|
+
message: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Inputs for the EIP-3009 ReceiveWithAuthorization typed-data.
|
|
46
|
+
*
|
|
47
|
+
* - `chainId` is the EVM chain id (Arc Testnet = 5042002).
|
|
48
|
+
* - `token` is the ERC-20 contract whose `receiveWithAuthorization` is
|
|
49
|
+
* being invoked — usually USDC at `0x36...` on Arc.
|
|
50
|
+
* - `tokenName` and `tokenVersion` form the EIP-712 domain. Real USDC
|
|
51
|
+
* on most chains uses `name="USD Coin"` and `version="2"`; tests
|
|
52
|
+
* use whatever the mock token reports. Always read these from the
|
|
53
|
+
* token contract at runtime to avoid drift.
|
|
54
|
+
* - `from` is the payer; the wallet that produces the signature must
|
|
55
|
+
* match this address.
|
|
56
|
+
* - `to` is the recipient of the funds — for Strimz this is the
|
|
57
|
+
* StrimzPayments contract address (the contract pulls funds into
|
|
58
|
+
* itself, then forwards the fee + net split).
|
|
59
|
+
* - `value` is the gross amount in token base units.
|
|
60
|
+
* - `validAfter` / `validBefore` are unix-second timestamps bounding
|
|
61
|
+
* the signature's validity. Strimz's default checkout window is
|
|
62
|
+
* 5 minutes; integrators may widen this for usage-based billing.
|
|
63
|
+
* - `nonce` is a single-use 32-byte value. Generate with crypto.randomBytes
|
|
64
|
+
* (server) or crypto.getRandomValues (browser). The token contract
|
|
65
|
+
* tracks `(authorizer, nonce) -> used` and rejects replays.
|
|
66
|
+
*/
|
|
67
|
+
interface ReceiveWithAuthorizationParams {
|
|
68
|
+
chainId: number;
|
|
69
|
+
token: `0x${string}`;
|
|
70
|
+
tokenName: string;
|
|
71
|
+
tokenVersion: string;
|
|
72
|
+
from: `0x${string}`;
|
|
73
|
+
to: `0x${string}`;
|
|
74
|
+
value: bigint;
|
|
75
|
+
validAfter: bigint;
|
|
76
|
+
validBefore: bigint;
|
|
77
|
+
nonce: `0x${string}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* EIP-712 type definition for `ReceiveWithAuthorization`. Stable —
|
|
81
|
+
* shared by every EIP-3009 implementation (USDC, EURC, etc.).
|
|
82
|
+
*
|
|
83
|
+
* Exported so consumers can introspect or extend with sibling
|
|
84
|
+
* primitive types (e.g. for x402 batched signing schemes that wrap
|
|
85
|
+
* multiple authorizations in one signature).
|
|
86
|
+
*/
|
|
87
|
+
declare const RECEIVE_WITH_AUTHORIZATION_TYPES: {
|
|
88
|
+
readonly ReceiveWithAuthorization: readonly [{
|
|
89
|
+
readonly name: "from";
|
|
90
|
+
readonly type: "address";
|
|
91
|
+
}, {
|
|
92
|
+
readonly name: "to";
|
|
93
|
+
readonly type: "address";
|
|
94
|
+
}, {
|
|
95
|
+
readonly name: "value";
|
|
96
|
+
readonly type: "uint256";
|
|
97
|
+
}, {
|
|
98
|
+
readonly name: "validAfter";
|
|
99
|
+
readonly type: "uint256";
|
|
100
|
+
}, {
|
|
101
|
+
readonly name: "validBefore";
|
|
102
|
+
readonly type: "uint256";
|
|
103
|
+
}, {
|
|
104
|
+
readonly name: "nonce";
|
|
105
|
+
readonly type: "bytes32";
|
|
106
|
+
}];
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Build the typed-data structure for an EIP-3009
|
|
110
|
+
* `ReceiveWithAuthorization` signature. Returns the canonical shape
|
|
111
|
+
* compatible with viem, ethers, Privy, and Reown.
|
|
112
|
+
*
|
|
113
|
+
* Pass the result to `walletClient.signTypedData(typedData)` (viem)
|
|
114
|
+
* or `signer._signTypedData(domain, types, message)` (ethers) — the
|
|
115
|
+
* SDK does not bind to a specific signer.
|
|
116
|
+
*/
|
|
117
|
+
declare function buildReceiveWithAuthorizationTypedData(params: ReceiveWithAuthorizationParams): Eip712TypedData<'ReceiveWithAuthorization'>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Inputs for the EIP-2612 Permit typed-data.
|
|
121
|
+
*
|
|
122
|
+
* - `chainId`, `token`, `tokenName`, `tokenVersion` form the EIP-712
|
|
123
|
+
* domain (same shape as the EIP-3009 builder).
|
|
124
|
+
* - `owner` is the token holder authorising the allowance — must match
|
|
125
|
+
* the signing wallet.
|
|
126
|
+
* - `spender` is the contract that will pull funds — for Strimz
|
|
127
|
+
* subscriptions this is the StrimzSubscriptions contract.
|
|
128
|
+
* - `value` is the allowance to grant in token base units.
|
|
129
|
+
* `type(uint256).max` produces an unlimited allowance and is the
|
|
130
|
+
* common case for subscription enrolment.
|
|
131
|
+
* - `nonce` is the owner's *current* `nonces(owner)` reading from the
|
|
132
|
+
* token contract. The SDK does not fetch this — the caller is
|
|
133
|
+
* expected to have just queried it. Race-free: the token rejects
|
|
134
|
+
* stale nonces, so a concurrent permit on the same owner just
|
|
135
|
+
* causes one to fail predictably.
|
|
136
|
+
* - `deadline` is the unix-second timestamp after which the permit
|
|
137
|
+
* expires. Strimz default for subscription enrolment is 24h —
|
|
138
|
+
* enough headroom for a slow merchant submit pipeline without
|
|
139
|
+
* leaving an indefinite signature window.
|
|
140
|
+
*/
|
|
141
|
+
interface PermitParams {
|
|
142
|
+
chainId: number;
|
|
143
|
+
token: `0x${string}`;
|
|
144
|
+
tokenName: string;
|
|
145
|
+
tokenVersion: string;
|
|
146
|
+
owner: `0x${string}`;
|
|
147
|
+
spender: `0x${string}`;
|
|
148
|
+
value: bigint;
|
|
149
|
+
nonce: bigint;
|
|
150
|
+
deadline: bigint;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* EIP-712 type definition for `Permit`. Stable across every EIP-2612
|
|
154
|
+
* implementation (USDC, EURC, DAI v2, etc.).
|
|
155
|
+
*/
|
|
156
|
+
declare const PERMIT_TYPES: {
|
|
157
|
+
readonly Permit: readonly [{
|
|
158
|
+
readonly name: "owner";
|
|
159
|
+
readonly type: "address";
|
|
160
|
+
}, {
|
|
161
|
+
readonly name: "spender";
|
|
162
|
+
readonly type: "address";
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "value";
|
|
165
|
+
readonly type: "uint256";
|
|
166
|
+
}, {
|
|
167
|
+
readonly name: "nonce";
|
|
168
|
+
readonly type: "uint256";
|
|
169
|
+
}, {
|
|
170
|
+
readonly name: "deadline";
|
|
171
|
+
readonly type: "uint256";
|
|
172
|
+
}];
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Build the typed-data structure for an EIP-2612 `Permit` signature.
|
|
176
|
+
* Returns the canonical shape compatible with viem, ethers, Privy,
|
|
177
|
+
* and Reown.
|
|
178
|
+
*/
|
|
179
|
+
declare function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'>;
|
|
180
|
+
|
|
181
|
+
export { type Eip712Domain, type Eip712Field, type Eip712TypedData, type Eip712Types, PERMIT_TYPES, type PermitParams, RECEIVE_WITH_AUTHORIZATION_TYPES, type ReceiveWithAuthorizationParams, buildPermitTypedData, buildReceiveWithAuthorizationTypedData };
|
package/dist/eip712.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/eip712/receive-with-authorization.ts
|
|
2
|
+
var RECEIVE_WITH_AUTHORIZATION_TYPES = {
|
|
3
|
+
ReceiveWithAuthorization: [
|
|
4
|
+
{ name: "from", type: "address" },
|
|
5
|
+
{ name: "to", type: "address" },
|
|
6
|
+
{ name: "value", type: "uint256" },
|
|
7
|
+
{ name: "validAfter", type: "uint256" },
|
|
8
|
+
{ name: "validBefore", type: "uint256" },
|
|
9
|
+
{ name: "nonce", type: "bytes32" }
|
|
10
|
+
]
|
|
11
|
+
};
|
|
12
|
+
function buildReceiveWithAuthorizationTypedData(params) {
|
|
13
|
+
return {
|
|
14
|
+
domain: {
|
|
15
|
+
name: params.tokenName,
|
|
16
|
+
version: params.tokenVersion,
|
|
17
|
+
chainId: params.chainId,
|
|
18
|
+
verifyingContract: params.token
|
|
19
|
+
},
|
|
20
|
+
types: RECEIVE_WITH_AUTHORIZATION_TYPES,
|
|
21
|
+
primaryType: "ReceiveWithAuthorization",
|
|
22
|
+
message: {
|
|
23
|
+
from: params.from,
|
|
24
|
+
to: params.to,
|
|
25
|
+
value: params.value,
|
|
26
|
+
validAfter: params.validAfter,
|
|
27
|
+
validBefore: params.validBefore,
|
|
28
|
+
nonce: params.nonce
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/eip712/permit.ts
|
|
34
|
+
var PERMIT_TYPES = {
|
|
35
|
+
Permit: [
|
|
36
|
+
{ name: "owner", type: "address" },
|
|
37
|
+
{ name: "spender", type: "address" },
|
|
38
|
+
{ name: "value", type: "uint256" },
|
|
39
|
+
{ name: "nonce", type: "uint256" },
|
|
40
|
+
{ name: "deadline", type: "uint256" }
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
function buildPermitTypedData(params) {
|
|
44
|
+
return {
|
|
45
|
+
domain: {
|
|
46
|
+
name: params.tokenName,
|
|
47
|
+
version: params.tokenVersion,
|
|
48
|
+
chainId: params.chainId,
|
|
49
|
+
verifyingContract: params.token
|
|
50
|
+
},
|
|
51
|
+
types: PERMIT_TYPES,
|
|
52
|
+
primaryType: "Permit",
|
|
53
|
+
message: {
|
|
54
|
+
owner: params.owner,
|
|
55
|
+
spender: params.spender,
|
|
56
|
+
value: params.value,
|
|
57
|
+
nonce: params.nonce,
|
|
58
|
+
deadline: params.deadline
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { PERMIT_TYPES, RECEIVE_WITH_AUTHORIZATION_TYPES, buildPermitTypedData, buildReceiveWithAuthorizationTypedData };
|
|
64
|
+
//# sourceMappingURL=eip712.js.map
|
|
65
|
+
//# sourceMappingURL=eip712.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eip712/receive-with-authorization.ts","../src/eip712/permit.ts"],"names":[],"mappings":";AA8CO,IAAM,gCAAA,GAAmC;AAAA,EAC9C,wBAAA,EAA0B;AAAA,IACxB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,SAAA,EAAU;AAAA,IAC9B,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,SAAA,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,SAAA,EAAU;AAAA,IACvC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA;AAAU;AAErC;AAWO,SAAS,uCACd,MAAA,EAC6C;AAC7C,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ;AAAA,MACN,MAAM,MAAA,CAAO,SAAA;AAAA,MACb,SAAS,MAAA,CAAO,YAAA;AAAA,MAChB,SAAS,MAAA,C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O;AAAA;AACnB,GACF;AACF","file":"eip712.js","sourcesContent":["import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-3009 ReceiveWithAuthorization typed-data.\n *\n * - `chainId` is the EVM chain id (Arc Testnet = 5042002).\n * - `token` is the ERC-20 contract whose `receiveWithAuthorization` is\n * being invoked — usually USDC at `0x36...` on Arc.\n * - `tokenName` and `tokenVersion` form the EIP-712 domain. Real USDC\n * on most chains uses `name=\"USD Coin\"` and `version=\"2\"`; tests\n * use whatever the mock token reports. Always read these from the\n * token contract at runtime to avoid drift.\n * - `from` is the payer; the wallet that produces the signature must\n * match this address.\n * - `to` is the recipient of the funds — for Strimz this is the\n * StrimzPayments contract address (the contract pulls funds into\n * itself, then forwards the fee + net split).\n * - `value` is the gross amount in token base units.\n * - `validAfter` / `validBefore` are unix-second timestamps bounding\n * the signature's validity. Strimz's default checkout window is\n * 5 minutes; integrators may widen this for usage-based billing.\n * - `nonce` is a single-use 32-byte value. Generate with crypto.randomBytes\n * (server) or crypto.getRandomValues (browser). The token contract\n * tracks `(authorizer, nonce) -> used` and rejects replays.\n */\nexport interface ReceiveWithAuthorizationParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n from: `0x${string}`\n to: `0x${string}`\n value: bigint\n validAfter: bigint\n validBefore: bigint\n nonce: `0x${string}`\n}\n\n/**\n * EIP-712 type definition for `ReceiveWithAuthorization`. Stable —\n * shared by every EIP-3009 implementation (USDC, EURC, etc.).\n *\n * Exported so consumers can introspect or extend with sibling\n * primitive types (e.g. for x402 batched signing schemes that wrap\n * multiple authorizations in one signature).\n */\nexport const RECEIVE_WITH_AUTHORIZATION_TYPES = {\n ReceiveWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-3009\n * `ReceiveWithAuthorization` signature. Returns the canonical shape\n * compatible with viem, ethers, Privy, and Reown.\n *\n * Pass the result to `walletClient.signTypedData(typedData)` (viem)\n * or `signer._signTypedData(domain, types, message)` (ethers) — the\n * SDK does not bind to a specific signer.\n */\nexport function buildReceiveWithAuthorizationTypedData(\n params: ReceiveWithAuthorizationParams,\n): Eip712TypedData<'ReceiveWithAuthorization'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: RECEIVE_WITH_AUTHORIZATION_TYPES,\n primaryType: 'ReceiveWithAuthorization',\n message: {\n from: params.from,\n to: params.to,\n value: params.value,\n validAfter: params.validAfter,\n validBefore: params.validBefore,\n nonce: params.nonce,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-2612 Permit typed-data.\n *\n * - `chainId`, `token`, `tokenName`, `tokenVersion` form the EIP-712\n * domain (same shape as the EIP-3009 builder).\n * - `owner` is the token holder authorising the allowance — must match\n * the signing wallet.\n * - `spender` is the contract that will pull funds — for Strimz\n * subscriptions this is the StrimzSubscriptions contract.\n * - `value` is the allowance to grant in token base units.\n * `type(uint256).max` produces an unlimited allowance and is the\n * common case for subscription enrolment.\n * - `nonce` is the owner's *current* `nonces(owner)` reading from the\n * token contract. The SDK does not fetch this — the caller is\n * expected to have just queried it. Race-free: the token rejects\n * stale nonces, so a concurrent permit on the same owner just\n * causes one to fail predictably.\n * - `deadline` is the unix-second timestamp after which the permit\n * expires. Strimz default for subscription enrolment is 24h —\n * enough headroom for a slow merchant submit pipeline without\n * leaving an indefinite signature window.\n */\nexport interface PermitParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n owner: `0x${string}`\n spender: `0x${string}`\n value: bigint\n nonce: bigint\n deadline: bigint\n}\n\n/**\n * EIP-712 type definition for `Permit`. Stable across every EIP-2612\n * implementation (USDC, EURC, DAI v2, etc.).\n */\nexport const PERMIT_TYPES = {\n Permit: [\n { name: 'owner', type: 'address' },\n { name: 'spender', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-2612 `Permit` signature.\n * Returns the canonical shape compatible with viem, ethers, Privy,\n * and Reown.\n */\nexport function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: PERMIT_TYPES,\n primaryType: 'Permit',\n message: {\n owner: params.owner,\n spender: params.spender,\n value: params.value,\n nonce: params.nonce,\n deadline: params.deadline,\n },\n }\n}\n"]}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/errors.ts
|
|
4
|
+
var StrimzError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
httpStatus;
|
|
7
|
+
requestId;
|
|
8
|
+
param;
|
|
9
|
+
details;
|
|
10
|
+
constructor(body, httpStatus) {
|
|
11
|
+
super(body.message);
|
|
12
|
+
this.name = "StrimzError";
|
|
13
|
+
this.code = body.code;
|
|
14
|
+
this.httpStatus = httpStatus;
|
|
15
|
+
this.requestId = body.requestId;
|
|
16
|
+
this.param = body.param;
|
|
17
|
+
this.details = body.details;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var StrimzAuthenticationError = class extends StrimzError {
|
|
21
|
+
constructor(body, httpStatus) {
|
|
22
|
+
super(body, httpStatus);
|
|
23
|
+
this.name = "StrimzAuthenticationError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var StrimzPermissionError = class extends StrimzError {
|
|
27
|
+
constructor(body, httpStatus) {
|
|
28
|
+
super(body, httpStatus);
|
|
29
|
+
this.name = "StrimzPermissionError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var StrimzValidationError = class extends StrimzError {
|
|
33
|
+
constructor(body, httpStatus) {
|
|
34
|
+
super(body, httpStatus);
|
|
35
|
+
this.name = "StrimzValidationError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var StrimzNotFoundError = class extends StrimzError {
|
|
39
|
+
constructor(body, httpStatus) {
|
|
40
|
+
super(body, httpStatus);
|
|
41
|
+
this.name = "StrimzNotFoundError";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var StrimzIdempotencyError = class extends StrimzError {
|
|
45
|
+
constructor(body, httpStatus) {
|
|
46
|
+
super(body, httpStatus);
|
|
47
|
+
this.name = "StrimzIdempotencyError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var StrimzRateLimitError = class extends StrimzError {
|
|
51
|
+
retryAfterMs;
|
|
52
|
+
constructor(body, httpStatus, retryAfterMs) {
|
|
53
|
+
super(body, httpStatus);
|
|
54
|
+
this.name = "StrimzRateLimitError";
|
|
55
|
+
this.retryAfterMs = retryAfterMs;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var StrimzNetworkError = class extends StrimzError {
|
|
59
|
+
cause;
|
|
60
|
+
constructor(message, cause) {
|
|
61
|
+
super({ code: "network_error", message });
|
|
62
|
+
this.name = "StrimzNetworkError";
|
|
63
|
+
this.cause = cause;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var StrimzTimeoutError = class extends StrimzError {
|
|
67
|
+
constructor(message) {
|
|
68
|
+
super({ code: "timeout", message });
|
|
69
|
+
this.name = "StrimzTimeoutError";
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var StrimzModeMismatchError = class extends StrimzError {
|
|
73
|
+
constructor(message) {
|
|
74
|
+
super({ code: "mode_mismatch", message });
|
|
75
|
+
this.name = "StrimzModeMismatchError";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function classifyError(httpStatus, body, retryAfterMs) {
|
|
79
|
+
if (httpStatus === 401) return new StrimzAuthenticationError(body, httpStatus);
|
|
80
|
+
if (httpStatus === 403) return new StrimzPermissionError(body, httpStatus);
|
|
81
|
+
if (httpStatus === 404) return new StrimzNotFoundError(body, httpStatus);
|
|
82
|
+
if (httpStatus === 409 && body.code === "idempotency_error") {
|
|
83
|
+
return new StrimzIdempotencyError(body, httpStatus);
|
|
84
|
+
}
|
|
85
|
+
if (httpStatus === 422) return new StrimzValidationError(body, httpStatus);
|
|
86
|
+
if (httpStatus === 429) return new StrimzRateLimitError(body, httpStatus, retryAfterMs);
|
|
87
|
+
return new StrimzError(body, httpStatus);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.StrimzAuthenticationError = StrimzAuthenticationError;
|
|
91
|
+
exports.StrimzError = StrimzError;
|
|
92
|
+
exports.StrimzIdempotencyError = StrimzIdempotencyError;
|
|
93
|
+
exports.StrimzModeMismatchError = StrimzModeMismatchError;
|
|
94
|
+
exports.StrimzNetworkError = StrimzNetworkError;
|
|
95
|
+
exports.StrimzNotFoundError = StrimzNotFoundError;
|
|
96
|
+
exports.StrimzPermissionError = StrimzPermissionError;
|
|
97
|
+
exports.StrimzRateLimitError = StrimzRateLimitError;
|
|
98
|
+
exports.StrimzTimeoutError = StrimzTimeoutError;
|
|
99
|
+
exports.StrimzValidationError = StrimzValidationError;
|
|
100
|
+
exports.classifyError = classifyError;
|
|
101
|
+
//# sourceMappingURL=errors.cjs.map
|
|
102
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";;;AAqCO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EACrB,IAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EAEhB,WAAA,CAAY,MAAuB,UAAA,EAAqB;AACtD,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CA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BAAA,CAAoB,MAAM,UAAU,CAAA;AACvE,EAAA,IAAI,UAAA,KAAe,GAAA,IAAO,IAAA,CAAK,IAAA,KAAS,mBAAA,EAAqB;AAC3D,IAAA,OAAO,IAAI,sBAAA,CAAuB,IAAA,EAAM,UAAU,CAAA;AAAA,EACpD;AACA,EAAA,IAAI,eAAe,GAAA,EAAK,OAAO,IAAI,qBAAA,CAAsB,MAAM,UAAU,CAAA;AACzE,EAAA,IAAI,eAAe,GAAA,EAAK,OAAO,IAAI,oBAAA,CAAqB,IAAA,EAAM,YAAY,YAAY,CAAA;AACtF,EAAA,OAAO,IAAI,WAAA,CAAY,IAAA,EAAM,UAAU,CAAA;AACzC","file":"errors.cjs","sourcesContent":["/**\n * Error hierarchy for the Strimz SDK.\n *\n * Every error thrown by the SDK extends `StrimzError`. The SDK never\n * resolves to `{ ok: false }` — it throws. This matches the Stripe / GitHub\n * SDK convention and keeps call sites linear.\n */\n\nexport type StrimzErrorCode =\n | 'authentication_error'\n | 'permission_denied'\n | 'invalid_request'\n | 'not_found'\n | 'idempotency_error'\n | 'rate_limited'\n | 'mode_mismatch'\n | 'merchant_not_found'\n | 'merchant_inactive'\n | 'token_not_whitelisted'\n | 'compliance_blocked'\n | 'session_expired'\n | 'session_invalid_state'\n | 'webhook_signature_invalid'\n | 'api_error'\n | 'network_error'\n | 'timeout'\n | 'parse_error'\n | 'unknown'\n\nexport interface StrimzErrorBody {\n code: StrimzErrorCode\n message: string\n param?: string\n requestId?: string\n details?: Record<string, unknown>\n}\n\nexport class StrimzError extends Error {\n public readonly code: StrimzErrorCode\n public readonly httpStatus: number | undefined\n public readonly requestId: string | undefined\n public readonly param: string | undefined\n public readonly details: Record<string, unknown> | undefined\n\n constructor(body: StrimzErrorBody, httpStatus?: number) {\n super(body.message)\n this.name = 'StrimzError'\n this.code = body.code\n this.httpStatus = httpStatus\n this.requestId = body.requestId\n this.param = body.param\n this.details = body.details\n }\n}\n\nexport class StrimzAuthenticationError extends StrimzError {\n constructor(body: StrimzErrorBody, httpStatus?: number) {\n super(body, httpStatus)\n this.name = 'StrimzAuthenticationError'\n }\n}\n\nexport class StrimzPermissionError extends StrimzError {\n constructor(body: StrimzErrorBody, httpStatus?: number) {\n super(body, httpStatus)\n this.name = 'StrimzPermissionError'\n }\n}\n\nexport class StrimzValidationError extends StrimzError {\n constructor(body: StrimzErrorBody, httpStatus?: number) {\n super(body, httpStatus)\n this.name = 'StrimzValidationError'\n }\n}\n\nexport class StrimzNotFoundError extends StrimzError {\n constructor(body: StrimzErrorBody, httpStatus?: number) {\n super(body, httpStatus)\n this.name = 'StrimzNotFoundError'\n }\n}\n\nexport class StrimzIdempotencyError extends StrimzError {\n constructor(body: StrimzErrorBody, httpStatus?: number) {\n super(body, httpStatus)\n this.name = 'StrimzIdempotencyError'\n }\n}\n\nexport class StrimzRateLimitError extends StrimzError {\n public readonly retryAfterMs: number | undefined\n constructor(body: StrimzErrorBody, httpStatus?: number, retryAfterMs?: number) {\n super(body, httpStatus)\n this.name = 'StrimzRateLimitError'\n this.retryAfterMs = retryAfterMs\n }\n}\n\nexport class StrimzNetworkError extends StrimzError {\n public override readonly cause: unknown\n constructor(message: string, cause: unknown) {\n super({ code: 'network_error', message })\n this.name = 'StrimzNetworkError'\n this.cause = cause\n }\n}\n\nexport class StrimzTimeoutError extends StrimzError {\n constructor(message: string) {\n super({ code: 'timeout', message })\n this.name = 'StrimzTimeoutError'\n }\n}\n\nexport class StrimzModeMismatchError extends StrimzError {\n constructor(message: string) {\n super({ code: 'mode_mismatch', message })\n this.name = 'StrimzModeMismatchError'\n }\n}\n\n/** Map an HTTP status + body to the right StrimzError subclass. */\nexport function classifyError(\n httpStatus: number,\n body: StrimzErrorBody,\n retryAfterMs?: number,\n): StrimzError {\n if (httpStatus === 401) return new StrimzAuthenticationError(body, httpStatus)\n if (httpStatus === 403) return new StrimzPermissionError(body, httpStatus)\n if (httpStatus === 404) return new StrimzNotFoundError(body, httpStatus)\n if (httpStatus === 409 && body.code === 'idempotency_error') {\n return new StrimzIdempotencyError(body, httpStatus)\n }\n if (httpStatus === 422) return new StrimzValidationError(body, httpStatus)\n if (httpStatus === 429) return new StrimzRateLimitError(body, httpStatus, retryAfterMs)\n return new StrimzError(body, httpStatus)\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error hierarchy for the Strimz SDK.
|
|
3
|
+
*
|
|
4
|
+
* Every error thrown by the SDK extends `StrimzError`. The SDK never
|
|
5
|
+
* resolves to `{ ok: false }` — it throws. This matches the Stripe / GitHub
|
|
6
|
+
* SDK convention and keeps call sites linear.
|
|
7
|
+
*/
|
|
8
|
+
type StrimzErrorCode = 'authentication_error' | 'permission_denied' | 'invalid_request' | 'not_found' | 'idempotency_error' | 'rate_limited' | 'mode_mismatch' | 'merchant_not_found' | 'merchant_inactive' | 'token_not_whitelisted' | 'compliance_blocked' | 'session_expired' | 'session_invalid_state' | 'webhook_signature_invalid' | 'api_error' | 'network_error' | 'timeout' | 'parse_error' | 'unknown';
|
|
9
|
+
interface StrimzErrorBody {
|
|
10
|
+
code: StrimzErrorCode;
|
|
11
|
+
message: string;
|
|
12
|
+
param?: string;
|
|
13
|
+
requestId?: string;
|
|
14
|
+
details?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
declare class StrimzError extends Error {
|
|
17
|
+
readonly code: StrimzErrorCode;
|
|
18
|
+
readonly httpStatus: number | undefined;
|
|
19
|
+
readonly requestId: string | undefined;
|
|
20
|
+
readonly param: string | undefined;
|
|
21
|
+
readonly details: Record<string, unknown> | undefined;
|
|
22
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
23
|
+
}
|
|
24
|
+
declare class StrimzAuthenticationError extends StrimzError {
|
|
25
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
26
|
+
}
|
|
27
|
+
declare class StrimzPermissionError extends StrimzError {
|
|
28
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
29
|
+
}
|
|
30
|
+
declare class StrimzValidationError extends StrimzError {
|
|
31
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
32
|
+
}
|
|
33
|
+
declare class StrimzNotFoundError extends StrimzError {
|
|
34
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
35
|
+
}
|
|
36
|
+
declare class StrimzIdempotencyError extends StrimzError {
|
|
37
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
38
|
+
}
|
|
39
|
+
declare class StrimzRateLimitError extends StrimzError {
|
|
40
|
+
readonly retryAfterMs: number | undefined;
|
|
41
|
+
constructor(body: StrimzErrorBody, httpStatus?: number, retryAfterMs?: number);
|
|
42
|
+
}
|
|
43
|
+
declare class StrimzNetworkError extends StrimzError {
|
|
44
|
+
readonly cause: unknown;
|
|
45
|
+
constructor(message: string, cause: unknown);
|
|
46
|
+
}
|
|
47
|
+
declare class StrimzTimeoutError extends StrimzError {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
declare class StrimzModeMismatchError extends StrimzError {
|
|
51
|
+
constructor(message: string);
|
|
52
|
+
}
|
|
53
|
+
/** Map an HTTP status + body to the right StrimzError subclass. */
|
|
54
|
+
declare function classifyError(httpStatus: number, body: StrimzErrorBody, retryAfterMs?: number): StrimzError;
|
|
55
|
+
|
|
56
|
+
export { StrimzAuthenticationError, StrimzError, type StrimzErrorBody, type StrimzErrorCode, StrimzIdempotencyError, StrimzModeMismatchError, StrimzNetworkError, StrimzNotFoundError, StrimzPermissionError, StrimzRateLimitError, StrimzTimeoutError, StrimzValidationError, classifyError };
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error hierarchy for the Strimz SDK.
|
|
3
|
+
*
|
|
4
|
+
* Every error thrown by the SDK extends `StrimzError`. The SDK never
|
|
5
|
+
* resolves to `{ ok: false }` — it throws. This matches the Stripe / GitHub
|
|
6
|
+
* SDK convention and keeps call sites linear.
|
|
7
|
+
*/
|
|
8
|
+
type StrimzErrorCode = 'authentication_error' | 'permission_denied' | 'invalid_request' | 'not_found' | 'idempotency_error' | 'rate_limited' | 'mode_mismatch' | 'merchant_not_found' | 'merchant_inactive' | 'token_not_whitelisted' | 'compliance_blocked' | 'session_expired' | 'session_invalid_state' | 'webhook_signature_invalid' | 'api_error' | 'network_error' | 'timeout' | 'parse_error' | 'unknown';
|
|
9
|
+
interface StrimzErrorBody {
|
|
10
|
+
code: StrimzErrorCode;
|
|
11
|
+
message: string;
|
|
12
|
+
param?: string;
|
|
13
|
+
requestId?: string;
|
|
14
|
+
details?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
declare class StrimzError extends Error {
|
|
17
|
+
readonly code: StrimzErrorCode;
|
|
18
|
+
readonly httpStatus: number | undefined;
|
|
19
|
+
readonly requestId: string | undefined;
|
|
20
|
+
readonly param: string | undefined;
|
|
21
|
+
readonly details: Record<string, unknown> | undefined;
|
|
22
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
23
|
+
}
|
|
24
|
+
declare class StrimzAuthenticationError extends StrimzError {
|
|
25
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
26
|
+
}
|
|
27
|
+
declare class StrimzPermissionError extends StrimzError {
|
|
28
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
29
|
+
}
|
|
30
|
+
declare class StrimzValidationError extends StrimzError {
|
|
31
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
32
|
+
}
|
|
33
|
+
declare class StrimzNotFoundError extends StrimzError {
|
|
34
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
35
|
+
}
|
|
36
|
+
declare class StrimzIdempotencyError extends StrimzError {
|
|
37
|
+
constructor(body: StrimzErrorBody, httpStatus?: number);
|
|
38
|
+
}
|
|
39
|
+
declare class StrimzRateLimitError extends StrimzError {
|
|
40
|
+
readonly retryAfterMs: number | undefined;
|
|
41
|
+
constructor(body: StrimzErrorBody, httpStatus?: number, retryAfterMs?: number);
|
|
42
|
+
}
|
|
43
|
+
declare class StrimzNetworkError extends StrimzError {
|
|
44
|
+
readonly cause: unknown;
|
|
45
|
+
constructor(message: string, cause: unknown);
|
|
46
|
+
}
|
|
47
|
+
declare class StrimzTimeoutError extends StrimzError {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
declare class StrimzModeMismatchError extends StrimzError {
|
|
51
|
+
constructor(message: string);
|
|
52
|
+
}
|
|
53
|
+
/** Map an HTTP status + body to the right StrimzError subclass. */
|
|
54
|
+
declare function classifyError(httpStatus: number, body: StrimzErrorBody, retryAfterMs?: number): StrimzError;
|
|
55
|
+
|
|
56
|
+
export { StrimzAuthenticationError, StrimzError, type StrimzErrorBody, type StrimzErrorCode, StrimzIdempotencyError, StrimzModeMismatchError, StrimzNetworkError, StrimzNotFoundError, StrimzPermissionError, StrimzRateLimitError, StrimzTimeoutError, StrimzValidationError, classifyError };
|