@coin-voyage/shared 0.0.7 → 0.0.9
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/dist/api/pay-order.d.ts +1 -1
- package/dist/api/pay-order.js +1 -1
- package/dist/api/pay-order.js.map +1 -1
- package/dist/common/address.d.ts +5 -0
- package/dist/common/address.js +7 -0
- package/dist/common/address.js.map +1 -0
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.js +1 -1
- package/dist/common/index.js.map +1 -1
- package/dist/common/pay.d.ts +94 -39
- package/dist/common/pay.js +46 -28
- package/dist/common/pay.js.map +1 -1
- package/package.json +3 -3
- package/dist/common/retryBackoff.d.ts +0 -1
- package/dist/common/retryBackoff.js +0 -22
- package/dist/common/retryBackoff.js.map +0 -1
package/dist/api/pay-order.d.ts
CHANGED
package/dist/api/pay-order.js
CHANGED
|
@@ -47,7 +47,7 @@ export async function getPayOrder(payOrderId, apiKey) {
|
|
|
47
47
|
*/
|
|
48
48
|
export async function createDepositPayOrder(createOrderParams, apiKey, throwOnFailure) {
|
|
49
49
|
const result = zDepositPayOrder.safeParse(createOrderParams);
|
|
50
|
-
if (
|
|
50
|
+
if (result.error) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
return fetchApi({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pay-order.js","sourceRoot":"","sources":["../../src/api/pay-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAyH,YAAY,EAAkB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3N,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,UAAkB,EAAE,MAAc;IAClE,OAAO,QAAQ,CAAW;QACxB,IAAI,EAAE,cAAc,UAAU,EAAE;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S,CAAC;gBACnB,GAAG,WAAW;aACf,CAAC;YACF,OAAO,EAAE;gBACP,WAAW,EAAE,MAAM;aACpB;SACF;KACF,CAAC,CAAA;AACJ,CAAC;AA0BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,UAAU,EACV,eAAe,EACf,UAAU,EACV,aAAa,EACb,MAAM,EACe;IACrB,OAAO,QAAQ,CAAiB;QAC9B,IAAI,EAAE,cAAc,UAAU,kBAAkB,EAAE,OAAO,EAAE;YACzD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,eAAe,EAAE;oBACf,OAAO,EAAE,eAAe;oBACxB,QAAQ,EAAE,UAAU;iBACrB;gBACD,cAAc,EAAE,aAAa;aAC9B,CAAC;YACF,OAAO,EAAE;gBACP,WAAW,EAAE,MAAM;aACpB;SACF;KACF,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EACpC,UAAU,EACV,qBAAqB,EACrB,MAAM,EAKP;IACC,OAAO,QAAQ,CAAO;QACpB,IAAI,EAAE,cAAc,UAAU,oBAAoB,qBAAqB,EAAE,EAAE,OAAO,EAAE;YAClF,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,WAAW,EAAE,MAAM;aACpB;SACF;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const isBitcoinAddress: (addr: string) => boolean;
|
|
2
|
+
export declare const isEthereumAddress: (addr: string) => boolean;
|
|
3
|
+
export declare const isSolanaAddress: (addr: string) => boolean;
|
|
4
|
+
export declare const isSuiAddress: (addr: string) => boolean;
|
|
5
|
+
export declare const isTronAddress: (addr: string) => boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Address validators
|
|
2
|
+
export const isBitcoinAddress = (addr) => /^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/.test(addr) || /^bc1[a-z0-9]{25,39}$/.test(addr);
|
|
3
|
+
export const isEthereumAddress = (addr) => /^0x[a-fA-F0-9]{40}$/.test(addr);
|
|
4
|
+
export const isSolanaAddress = (addr) => /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(addr);
|
|
5
|
+
export const isSuiAddress = (addr) => /^0x[a-fA-F0-9]{64}$/.test(addr);
|
|
6
|
+
export const isTronAddress = (addr) => /^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(addr);
|
|
7
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/common/address.ts"],"names":[],"mappings":"AACA,qBAAqB;AACrB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAE,CAC/C,mCAAmC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./address";
|
|
1
2
|
export * from "./assert";
|
|
2
3
|
export * from "./chainExplorer";
|
|
3
4
|
export * from "./chains";
|
|
@@ -7,6 +8,5 @@ export * from "./pay";
|
|
|
7
8
|
export * from "./debug";
|
|
8
9
|
export * from "./format";
|
|
9
10
|
export * from "./model";
|
|
10
|
-
export * from "./retryBackoff";
|
|
11
11
|
export * from "./time";
|
|
12
12
|
export * from "./i18n";
|
package/dist/common/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./address";
|
|
1
2
|
export * from "./assert";
|
|
2
3
|
export * from "./chainExplorer";
|
|
3
4
|
export * from "./chains";
|
|
@@ -7,7 +8,6 @@ export * from "./pay";
|
|
|
7
8
|
export * from "./debug";
|
|
8
9
|
export * from "./format";
|
|
9
10
|
export * from "./model";
|
|
10
|
-
export * from "./retryBackoff";
|
|
11
11
|
export * from "./time";
|
|
12
12
|
export * from "./i18n";
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
package/dist/common/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,OAAO,CAAA;AACrB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,OAAO,CAAA;AACrB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA"}
|
package/dist/common/pay.d.ts
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { Currency } from "./model";
|
|
3
2
|
import { Address, Hex } from "../types/crypto";
|
|
3
|
+
import { ChainId } from "./chains";
|
|
4
|
+
import { Currency } from "./model";
|
|
4
5
|
export declare enum PayOrderMode {
|
|
5
6
|
SALE = "SALE",// product or item sale, value out can only be adjusted by the merchant
|
|
6
7
|
DEPOSIT = "DEPOSIT"
|
|
7
8
|
}
|
|
8
|
-
export declare const zBridgeTokenOutOptions: z.ZodArray<z.ZodObject<{
|
|
9
|
-
token: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
10
|
-
amount: z.ZodEffects<z.ZodEffects<z.ZodString, `${bigint}`, string>, bigint, string>;
|
|
11
|
-
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
token: `0x${string}`;
|
|
13
|
-
amount: bigint;
|
|
14
|
-
}, {
|
|
15
|
-
token: string;
|
|
16
|
-
amount: string;
|
|
17
|
-
}>, "many">;
|
|
18
|
-
export type BridgeTokenOutOptions = z.infer<typeof zBridgeTokenOutOptions>;
|
|
19
9
|
export declare const zPayOrderMetadata: z.ZodObject<{
|
|
20
10
|
items: z.ZodArray<z.ZodObject<{
|
|
21
11
|
name: z.ZodString;
|
|
@@ -58,7 +48,7 @@ export declare const zPayOrderMetadata: z.ZodObject<{
|
|
|
58
48
|
unit_price?: number | undefined;
|
|
59
49
|
}[];
|
|
60
50
|
}>;
|
|
61
|
-
export declare const zDepositPayOrder: z.ZodEffects<z.ZodObject<{
|
|
51
|
+
export declare const zDepositPayOrder: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
62
52
|
metadata: z.ZodOptional<z.ZodObject<{
|
|
63
53
|
items: z.ZodArray<z.ZodObject<{
|
|
64
54
|
name: z.ZodString;
|
|
@@ -186,6 +176,42 @@ export declare const zDepositPayOrder: z.ZodEffects<z.ZodObject<{
|
|
|
186
176
|
} | undefined;
|
|
187
177
|
destination_value_usd?: number | undefined;
|
|
188
178
|
destination_amount?: string | undefined;
|
|
179
|
+
}>, {
|
|
180
|
+
destination_currency: {
|
|
181
|
+
chain_id: number;
|
|
182
|
+
address: string | null;
|
|
183
|
+
};
|
|
184
|
+
receiving_address: string;
|
|
185
|
+
metadata?: {
|
|
186
|
+
items: {
|
|
187
|
+
name: string;
|
|
188
|
+
currency?: string | undefined;
|
|
189
|
+
description?: string | undefined;
|
|
190
|
+
image?: string | undefined;
|
|
191
|
+
quantity?: number | undefined;
|
|
192
|
+
unit_price?: number | undefined;
|
|
193
|
+
}[];
|
|
194
|
+
} | undefined;
|
|
195
|
+
destination_value_usd?: number | undefined;
|
|
196
|
+
destination_amount?: string | undefined;
|
|
197
|
+
}, {
|
|
198
|
+
destination_currency: {
|
|
199
|
+
chain_id: number;
|
|
200
|
+
address: string | null;
|
|
201
|
+
};
|
|
202
|
+
receiving_address: string;
|
|
203
|
+
metadata?: {
|
|
204
|
+
items: {
|
|
205
|
+
name: string;
|
|
206
|
+
currency?: string | undefined;
|
|
207
|
+
description?: string | undefined;
|
|
208
|
+
image?: string | undefined;
|
|
209
|
+
quantity?: number | undefined;
|
|
210
|
+
unit_price?: number | undefined;
|
|
211
|
+
}[];
|
|
212
|
+
} | undefined;
|
|
213
|
+
destination_value_usd?: number | undefined;
|
|
214
|
+
destination_amount?: string | undefined;
|
|
189
215
|
}>;
|
|
190
216
|
export type PayOrderMetadata = z.infer<typeof zPayOrderMetadata>;
|
|
191
217
|
export declare enum PayOrderStatus {
|
|
@@ -233,41 +259,61 @@ export type OnChainCall = {
|
|
|
233
259
|
value: bigint;
|
|
234
260
|
};
|
|
235
261
|
export declare const emptyOnChainCall: OnChainCall;
|
|
236
|
-
export
|
|
237
|
-
|
|
238
|
-
export type PaymentCreationErrorEvent = {
|
|
239
|
-
type: "payment_creation_error";
|
|
262
|
+
export type PayOrderCreationErrorEvent = {
|
|
263
|
+
type: "payorder_creation_error";
|
|
240
264
|
errorMessage: string;
|
|
241
265
|
};
|
|
242
|
-
export type
|
|
243
|
-
type: "
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
266
|
+
export type PayOrderCreatedEvent = {
|
|
267
|
+
type: "payorder_created";
|
|
268
|
+
payorder_id: string;
|
|
269
|
+
};
|
|
270
|
+
export type PayOrderStartedEvent = {
|
|
271
|
+
type: "payorder_started";
|
|
272
|
+
payorder_id: string;
|
|
273
|
+
chain_id: ChainId;
|
|
274
|
+
chain: string;
|
|
275
|
+
};
|
|
276
|
+
export type PayOrderConfirmingEvent = {
|
|
277
|
+
type: "payorder_confirming";
|
|
278
|
+
payorder_id: string;
|
|
279
|
+
chain_id: ChainId;
|
|
280
|
+
chain: string;
|
|
281
|
+
source_transaction_hash: Hex | string;
|
|
282
|
+
};
|
|
283
|
+
export type PayOrderExecutingEvent = {
|
|
284
|
+
type: "payorder_executing";
|
|
285
|
+
payorder_id: string;
|
|
247
286
|
};
|
|
248
|
-
export type
|
|
249
|
-
type: "
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
287
|
+
export type PayOrderCompletedEvent = {
|
|
288
|
+
type: "payorder_completed";
|
|
289
|
+
payorder_id: string;
|
|
290
|
+
chain_id: ChainId;
|
|
291
|
+
chain: string;
|
|
292
|
+
destination_tx_hash: Hex | string;
|
|
253
293
|
};
|
|
254
|
-
export type
|
|
255
|
-
type: "
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
294
|
+
export type PayOrderErrorEvent = {
|
|
295
|
+
type: "payorder_error";
|
|
296
|
+
payorder_id: string;
|
|
297
|
+
message: string;
|
|
298
|
+
status: string;
|
|
259
299
|
};
|
|
260
|
-
export type
|
|
300
|
+
export type PayOrderRefundedEvent = {
|
|
301
|
+
type: "payorder_refunded";
|
|
302
|
+
payorder_id: string;
|
|
303
|
+
refund_tx_hash: Hex | string;
|
|
304
|
+
refund_address: string;
|
|
305
|
+
};
|
|
306
|
+
export type PayOrderEvent = PayOrderCreationErrorEvent | PayOrderCreatedEvent | PayOrderStartedEvent | PayOrderConfirmingEvent | PayOrderExecutingEvent | PayOrderCompletedEvent | PayOrderErrorEvent;
|
|
261
307
|
export interface WebhookEndpoint {
|
|
262
308
|
id: string;
|
|
263
309
|
organization_id: string;
|
|
264
310
|
active: boolean;
|
|
265
311
|
url: string;
|
|
266
312
|
webhook_secret: string;
|
|
267
|
-
subscription_events:
|
|
313
|
+
subscription_events: WebhookEventType[];
|
|
268
314
|
created_at: Date;
|
|
269
315
|
}
|
|
270
|
-
export declare enum
|
|
316
|
+
export declare enum WebhookEventType {
|
|
271
317
|
ORDER_CREATED = "ORDER_CREATED",
|
|
272
318
|
ORDER_AWAITING_PAYMENT = "ORDER_AWAITING_PAYMENT",
|
|
273
319
|
ORDER_CONFIRMING = "ORDER_CONFIRMING",
|
|
@@ -277,9 +323,18 @@ export declare enum WebhookEventStatus {
|
|
|
277
323
|
ORDER_REFUNDED = "ORDER_REFUNDED"
|
|
278
324
|
}
|
|
279
325
|
export interface WebhookEvent {
|
|
280
|
-
id:
|
|
326
|
+
id: string;
|
|
281
327
|
endpoint: WebhookEndpoint;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
328
|
+
payload: PayOrderEvent;
|
|
329
|
+
webhook_id: string;
|
|
330
|
+
status: WebhookEventType;
|
|
331
|
+
deliveries: WebhookDelivery[];
|
|
332
|
+
created_at: Date;
|
|
333
|
+
}
|
|
334
|
+
export interface WebhookDelivery {
|
|
335
|
+
id: string;
|
|
336
|
+
event_id: string;
|
|
337
|
+
http_status: string;
|
|
338
|
+
body: string | null;
|
|
339
|
+
created_at: Date;
|
|
285
340
|
}
|
package/dist/common/pay.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { zAddress, zBigIntStr } from "./model";
|
|
3
2
|
import { zeroAddress } from "../types/crypto";
|
|
3
|
+
import { isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSuiAddress, isTronAddress } from "./address";
|
|
4
|
+
import { ChainId } from "./chains";
|
|
4
5
|
export var PayOrderMode;
|
|
5
6
|
(function (PayOrderMode) {
|
|
6
7
|
PayOrderMode["SALE"] = "SALE";
|
|
7
8
|
PayOrderMode["DEPOSIT"] = "DEPOSIT";
|
|
8
9
|
})(PayOrderMode || (PayOrderMode = {}));
|
|
9
|
-
export const zBridgeTokenOutOptions = z.array(z.object({
|
|
10
|
-
token: zAddress,
|
|
11
|
-
amount: zBigIntStr.transform((a) => BigInt(a)),
|
|
12
|
-
}));
|
|
13
10
|
// NOTE: be careful to modify this type only in backward-compatible ways.
|
|
14
|
-
//
|
|
11
|
+
// Add OPTIONAL fields, etc. Anything else requires a migration.
|
|
15
12
|
export const zPayOrderMetadata = z.object({
|
|
16
13
|
items: z
|
|
17
14
|
.array(z.object({
|
|
@@ -40,10 +37,39 @@ export const zDepositPayOrder = z.object({
|
|
|
40
37
|
message: "destination_amount must be greater than zero if defined",
|
|
41
38
|
}),
|
|
42
39
|
receiving_address: z.string().min(1),
|
|
43
|
-
}).
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
}).superRefine((data, ctx) => {
|
|
41
|
+
const hasUsd = data.destination_value_usd !== undefined;
|
|
42
|
+
const hasAmount = data.destination_amount !== undefined;
|
|
43
|
+
if (hasUsd && hasAmount) {
|
|
44
|
+
ctx.addIssue({
|
|
45
|
+
path: ["destination_value_usd"],
|
|
46
|
+
code: z.ZodIssueCode.custom,
|
|
47
|
+
message: "Only one of destination_value_usd or destination_amount should be present.",
|
|
48
|
+
});
|
|
49
|
+
ctx.addIssue({
|
|
50
|
+
path: ["destination_amount"],
|
|
51
|
+
code: z.ZodIssueCode.custom,
|
|
52
|
+
message: "Only one of destination_value_usd or destination_amount should be present.",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}).superRefine((data, ctx) => {
|
|
56
|
+
const { receiving_address } = data;
|
|
57
|
+
const chainId = data.destination_currency.chain_id;
|
|
58
|
+
const validators = {
|
|
59
|
+
[ChainId.SOL]: isSolanaAddress,
|
|
60
|
+
[ChainId.BTC]: isBitcoinAddress,
|
|
61
|
+
[ChainId.SUI]: isSuiAddress,
|
|
62
|
+
[ChainId.TRX]: isTronAddress,
|
|
63
|
+
};
|
|
64
|
+
// All Chains before ChainId.BTC use Ethereum address validation
|
|
65
|
+
const validator = chainId < ChainId.BTC ? isEthereumAddress : validators[chainId];
|
|
66
|
+
if (validator && !validator(receiving_address)) {
|
|
67
|
+
ctx.addIssue({
|
|
68
|
+
message: `Invalid receiving address for chain_id ${chainId}`,
|
|
69
|
+
path: ["receiving_address"],
|
|
70
|
+
code: z.ZodIssueCode.custom,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
47
73
|
});
|
|
48
74
|
export var PayOrderStatus;
|
|
49
75
|
(function (PayOrderStatus) {
|
|
@@ -62,22 +88,14 @@ export const emptyOnChainCall = {
|
|
|
62
88
|
data: "0x",
|
|
63
89
|
value: BigInt(0),
|
|
64
90
|
};
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
})(WebhookEventStatus || (WebhookEventStatus = {}));
|
|
76
|
-
// export interface WebhookDelivery {
|
|
77
|
-
// id: UUID
|
|
78
|
-
// eventId: UUID
|
|
79
|
-
// httpStatus: number | null
|
|
80
|
-
// body: string | null
|
|
81
|
-
// createdAt: Date
|
|
82
|
-
// }
|
|
91
|
+
export var WebhookEventType;
|
|
92
|
+
(function (WebhookEventType) {
|
|
93
|
+
WebhookEventType["ORDER_CREATED"] = "ORDER_CREATED";
|
|
94
|
+
WebhookEventType["ORDER_AWAITING_PAYMENT"] = "ORDER_AWAITING_PAYMENT";
|
|
95
|
+
WebhookEventType["ORDER_CONFIRMING"] = "ORDER_CONFIRMING";
|
|
96
|
+
WebhookEventType["ORDER_EXECUTING"] = "ORDER_EXECUTING";
|
|
97
|
+
WebhookEventType["ORDER_COMPLETED"] = "ORDER_COMPLETED";
|
|
98
|
+
WebhookEventType["ORDER_ERROR"] = "ORDER_ERROR";
|
|
99
|
+
WebhookEventType["ORDER_REFUNDED"] = "ORDER_REFUNDED";
|
|
100
|
+
})(WebhookEventType || (WebhookEventType = {}));
|
|
83
101
|
//# sourceMappingURL=pay.js.map
|
package/dist/common/pay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pay.js","sourceRoot":"","sources":["../../src/common/pay.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,
|
|
1
|
+
{"version":3,"file":"pay.js","sourceRoot":"","sources":["../../src/common/pay.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAgB,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC7G,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAIlC,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,mCAAmB,CAAA;AACrB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAED,yEAAyE;AACzE,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC;SACL,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAClC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC5B,Q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AC,CAAC,CAAA;AAIF,MAAM,CAAN,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,mCAAiB,CAAA;IACjB,uDAAqC,CAAA;IACrC,iEAA+C,CAAA;IAC/C,+DAA6C,CAAA;IAC7C,qDAAmC,CAAA;IACnC,yCAAuB,CAAA;IACvB,qCAAmB,CAAA;IACnB,uCAAqB,CAAA;AACvB,CAAC,EAVW,cAAc,KAAd,cAAc,QAUzB;AA6CD,MAAM,CAAC,MAAM,gBAAgB,GAAgB;IAC3C,EAAE,EAAE,WAAW;IACf,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;CACjB,CAAA;AA0ED,MAAM,CAAN,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,mDAA+B,CAAA;IAC/B,qEAAiD,CAAA;IACjD,yDAAqC,CAAA;IACrC,uDAAmC,CAAA;IACnC,uDAAmC,CAAA;IACnC,+CAA2B,CAAA;IAC3B,qDAAiC,CAAA;AACnC,CAAC,EARW,gBAAgB,KAAhB,gBAAgB,QAQ3B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coin-voyage/shared",
|
|
3
3
|
"description": "Shared utilities for Coin Voyage",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.9",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"watch": "tsc -w -p ./tsconfig.json",
|
|
30
30
|
"build": "tsc --build --force",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
32
|
+
"release:build": "pnpm clean && pnpm build",
|
|
33
33
|
"type-check": "tsc --noEmit",
|
|
34
34
|
"test": "vitest run"
|
|
35
35
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function retryBackoff<T>(name: string, fn: () => Promise<T>, maxRetries?: number, backoffFn?: (i: number) => number): Promise<T>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Retries a function up to a maximum number of times, with exponential backoff.
|
|
2
|
-
// Current settings, max total wait time is ~10 seconds.
|
|
3
|
-
export async function retryBackoff(name, fn, maxRetries = 5, backoffFn = (i) => Math.min(2000, 250 * 2 ** i)) {
|
|
4
|
-
for (let i = 1;; i++) {
|
|
5
|
-
try {
|
|
6
|
-
return await fn();
|
|
7
|
-
}
|
|
8
|
-
catch (e) {
|
|
9
|
-
if (i <= maxRetries) {
|
|
10
|
-
const sleepMs = backoffFn(i);
|
|
11
|
-
await new Promise((r) => setTimeout(r, sleepMs));
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
console.warn(`[RETRY] ${name} QUITTING after try ${i}, error: ${e}`);
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
// TODO: add performance logging
|
|
20
|
-
throw new Error(`too many retries: ${name}`);
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=retryBackoff.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retryBackoff.js","sourceRoot":"","sources":["../../src/common/retryBackoff.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,wDAAwD;AACxD,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,EAAoB,EACpB,UAAU,GAAG,CAAC,EACd,YAAmC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IAEtE,KAAK,IAAI,CAAC,GAAG,CAAC,GAAI,CAAC,EAAE,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAA;QACnB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC;gBACpB,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;gBAC5B,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAA;YAClD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,WAAW,IAAI,uBAAuB,CAAC,YAAY,CAAC,EAAE,CAAC,CAAA;gBACpE,MAAK;YACP,CAAC;QACH,CAAC;IACH,CAAC;IACD,gCAAgC;IAChC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAA;AAC9C,CAAC"}
|