@0to1pay/fulfillment-sdk 1.0.1 → 2.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/README.md +5 -5
- package/dist/contracts/openapi.yaml +710 -706
- package/dist/packages/domain/contract.d.ts +0 -1
- package/dist/packages/domain/contract.js +0 -3
- package/dist/packages/domain/shared.js +0 -37
- package/dist/packages/server-sdk/index.d.ts +33 -19
- package/dist/packages/server-sdk/schema.d.ts +717 -511
- package/package.json +1 -1
|
@@ -14,6 +14,3 @@ export function validateSchema(name, data) {
|
|
|
14
14
|
throw new Error('Unknown OpenAPI schema ' + name);
|
|
15
15
|
return schema(data) ? undefined : ajv.errorsText(schema.errors);
|
|
16
16
|
}
|
|
17
|
-
export function check(ref, data) {
|
|
18
|
-
return ref?.$ref ? validateSchema(ref.$ref.split('/').at(-1), data) : undefined;
|
|
19
|
-
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
1
|
import canonicalizeModule from 'canonicalize';
|
|
3
|
-
export const id = randomUUID;
|
|
4
|
-
export const iso = (value) => new Date(value).toISOString();
|
|
5
|
-
export const now = () => new Date().toISOString();
|
|
6
2
|
export const canonical = (value) => {
|
|
7
3
|
const stringify = canonicalizeModule;
|
|
8
4
|
const result = stringify(value);
|
|
@@ -10,36 +6,3 @@ export const canonical = (value) => {
|
|
|
10
6
|
throw new Error('Unable to canonicalize JSON');
|
|
11
7
|
return result;
|
|
12
8
|
};
|
|
13
|
-
export const sha = (bytes) => createHash('sha256').update(bytes).digest();
|
|
14
|
-
export const digest = (value) => sha(canonical(value));
|
|
15
|
-
export const scope = (value) => ({
|
|
16
|
-
merchant_id: value.merchant_id, project_id: value.project_id, environment: value.environment,
|
|
17
|
-
});
|
|
18
|
-
export const params = (value) => [value.merchant_id, value.project_id, value.environment];
|
|
19
|
-
export const SCOPE = 'merchant_id=$1 AND project_id=$2 AND environment=$3';
|
|
20
|
-
export const money = (asset, amount, scale) => ({ asset, amount_atomic: amount, scale });
|
|
21
|
-
export class ApiError extends Error {
|
|
22
|
-
status;
|
|
23
|
-
code;
|
|
24
|
-
constructor(status, code, message = code) {
|
|
25
|
-
super(message);
|
|
26
|
-
this.status = status;
|
|
27
|
-
this.code = code;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export function requireValue(value, code = 'NOT_FOUND') {
|
|
31
|
-
if (value === undefined || value === null)
|
|
32
|
-
throw new ApiError(404, code, 'Resource not found');
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
export function requireCondition(condition, status, code, message) {
|
|
36
|
-
if (!condition)
|
|
37
|
-
throw new ApiError(status, code, message);
|
|
38
|
-
}
|
|
39
|
-
export const conflict = (condition, code = 'RESOURCE_CONFLICT') => requireCondition(condition, 409, code);
|
|
40
|
-
export const invalid = (condition, code = 'INVALID_REQUEST') => requireCondition(condition, 400, code);
|
|
41
|
-
export const ASSETS = new Map([['fiat:USD', 2], ['fiat:EUR', 2], ['fiat:GBP', 2], ['fiat:CAD', 2], ['fiat:AUD', 2], ['fiat:JPY', 0]]);
|
|
42
|
-
export const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
43
|
-
export function isChainProvider(provider) {
|
|
44
|
-
return provider === 'evm' || provider === 'solana' || provider === 'tron';
|
|
45
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { components, operations } from './schema.js';
|
|
2
2
|
export type { components, operations, paths } from './schema.js';
|
|
3
3
|
export type Schema<K extends keyof components['schemas']> = components['schemas'][K];
|
|
4
|
-
type PrivateOperation = '
|
|
4
|
+
type PrivateOperation = 'receiveStablePayEvent';
|
|
5
5
|
type OperationName = Exclude<keyof operations, PrivateOperation>;
|
|
6
6
|
type JsonContent<T> = T extends {
|
|
7
7
|
content: {
|
|
@@ -37,6 +37,8 @@ type OperationInput<K extends OperationName> = RequiredPath<K> & Body<K> & Idemp
|
|
|
37
37
|
query?: ParametersOf<K>['query'];
|
|
38
38
|
signal?: AbortSignal;
|
|
39
39
|
};
|
|
40
|
+
/** Return the exact UTF-8 message the approved payer signs after broadcasting. */
|
|
41
|
+
export declare function chainIntentClaimMessage(intent: Pick<Schema<'ChainIntent'>, 'family' | 'signing_message'>, transactionId: string): string;
|
|
40
42
|
export declare class ZeroToOnePayError extends Error {
|
|
41
43
|
readonly status: number;
|
|
42
44
|
readonly code: string;
|
|
@@ -121,28 +123,40 @@ export declare class ZeroToOnePayClient {
|
|
|
121
123
|
expires_at: string;
|
|
122
124
|
created_at: string;
|
|
123
125
|
}>;
|
|
126
|
+
createChainIntent(quote_id: string, body: Schema<'CreateChainIntent'>, idempotencyKey: string): Promise<{
|
|
127
|
+
intent_id: string;
|
|
128
|
+
quote_id: string;
|
|
129
|
+
family: components["schemas"]["ChainFamily"];
|
|
130
|
+
payer_address: components["schemas"]["ChainAddress"];
|
|
131
|
+
expires_at: string;
|
|
132
|
+
signing_message: string;
|
|
133
|
+
status: "pending" | "authorized" | "submitted";
|
|
134
|
+
transaction_id: components["schemas"]["ChainIntentTransactionId"] | null;
|
|
135
|
+
}>;
|
|
136
|
+
authorizeChainIntent(quote_id: string, intent_id: string, body: Schema<'AuthorizeChainIntent'>, idempotencyKey: string): Promise<{
|
|
137
|
+
intent_id: string;
|
|
138
|
+
quote_id: string;
|
|
139
|
+
family: components["schemas"]["ChainFamily"];
|
|
140
|
+
payer_address: components["schemas"]["ChainAddress"];
|
|
141
|
+
expires_at: string;
|
|
142
|
+
signing_message: string;
|
|
143
|
+
status: "pending" | "authorized" | "submitted";
|
|
144
|
+
transaction_id: components["schemas"]["ChainIntentTransactionId"] | null;
|
|
145
|
+
}>;
|
|
146
|
+
submitChainIntent(quote_id: string, intent_id: string, body: Schema<'SubmitChainIntent'>, idempotencyKey: string): Promise<{
|
|
147
|
+
intent_id: string;
|
|
148
|
+
quote_id: string;
|
|
149
|
+
family: components["schemas"]["ChainFamily"];
|
|
150
|
+
payer_address: components["schemas"]["ChainAddress"];
|
|
151
|
+
expires_at: string;
|
|
152
|
+
signing_message: string;
|
|
153
|
+
status: "pending" | "authorized" | "submitted";
|
|
154
|
+
transaction_id: components["schemas"]["ChainIntentTransactionId"] | null;
|
|
155
|
+
}>;
|
|
124
156
|
createAttempt(payment_id: string, body: Schema<'CreateAttempt'>, idempotencyKey: string): Promise<{
|
|
125
157
|
attempt: components["schemas"]["Attempt"];
|
|
126
158
|
operation: components["schemas"]["Operation"] | null;
|
|
127
159
|
}>;
|
|
128
|
-
attachExternalAttempt(payment_id: string, body: Schema<'AttachExternalAttempt'>, idempotencyKey: string): Promise<{
|
|
129
|
-
merchant_id: string;
|
|
130
|
-
project_id: string;
|
|
131
|
-
environment: components["schemas"]["Environment"];
|
|
132
|
-
attempt_id: string;
|
|
133
|
-
payment_id: string;
|
|
134
|
-
quote_id: string;
|
|
135
|
-
connection_id: string;
|
|
136
|
-
mode: "managed" | "external";
|
|
137
|
-
execution_status: "created" | "requires_action" | "processing" | "unknown" | "succeeded" | "failed" | "canceled";
|
|
138
|
-
operation_id: string | null;
|
|
139
|
-
external_resources: components["schemas"]["ExternalResource"][];
|
|
140
|
-
binding: components["schemas"]["Binding"];
|
|
141
|
-
next_action: components["schemas"]["NextAction"];
|
|
142
|
-
created_at: string;
|
|
143
|
-
updated_at: string;
|
|
144
|
-
resource_version: number;
|
|
145
|
-
}>;
|
|
146
160
|
claimFulfillment(command_id: string, body: Schema<'ClaimRequest'>, idempotencyKey: string): Promise<{
|
|
147
161
|
claim_id: string;
|
|
148
162
|
command_id: string;
|