@binopartner/pay-sdk 0.1.1 → 0.3.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 +145 -2
- package/dist/core/api-base.d.ts +49 -0
- package/dist/core/api-base.js +196 -0
- package/dist/core/appearance.d.ts +17 -0
- package/dist/core/appearance.js +122 -0
- package/dist/core/auth.d.ts +32 -0
- package/dist/core/auth.js +233 -0
- package/dist/core/client.d.ts +71 -0
- package/dist/core/client.js +307 -0
- package/dist/core/clock.d.ts +7 -0
- package/dist/core/clock.js +17 -0
- package/dist/core/errors.d.ts +29 -0
- package/dist/core/errors.js +87 -0
- package/dist/core/events.d.ts +50 -0
- package/dist/core/events.js +1 -0
- package/dist/core/flows/deposit.d.ts +63 -0
- package/dist/core/flows/deposit.js +502 -0
- package/dist/core/flows/withdraw.d.ts +51 -0
- package/dist/core/flows/withdraw.js +413 -0
- package/dist/core/i18n/ar.d.ts +2 -0
- package/dist/core/i18n/ar.js +314 -0
- package/dist/core/i18n/base.d.ts +14 -0
- package/dist/core/i18n/base.js +86 -0
- package/dist/core/i18n/cs.d.ts +2 -0
- package/dist/core/i18n/cs.js +314 -0
- package/dist/core/i18n/de.d.ts +2 -0
- package/dist/core/i18n/de.js +314 -0
- package/dist/core/i18n/en-ui.d.ts +39 -0
- package/dist/core/i18n/en-ui.js +39 -0
- package/dist/core/i18n/en.d.ts +316 -0
- package/dist/core/i18n/en.js +280 -0
- package/dist/core/i18n/es.d.ts +2 -0
- package/dist/core/i18n/es.js +314 -0
- package/dist/core/i18n/fr.d.ts +2 -0
- package/dist/core/i18n/fr.js +314 -0
- package/dist/core/i18n/hi.d.ts +2 -0
- package/dist/core/i18n/hi.js +314 -0
- package/dist/core/i18n/index.d.ts +16 -0
- package/dist/core/i18n/index.js +39 -0
- package/dist/core/i18n/it.d.ts +2 -0
- package/dist/core/i18n/it.js +314 -0
- package/dist/core/i18n/ru.d.ts +2 -0
- package/dist/core/i18n/ru.js +314 -0
- package/dist/core/i18n/tr.d.ts +2 -0
- package/dist/core/i18n/tr.js +314 -0
- package/dist/core/i18n/ua.d.ts +2 -0
- package/dist/core/i18n/ua.js +314 -0
- package/dist/core/index.d.ts +37 -0
- package/dist/core/index.js +19 -0
- package/dist/core/intent.d.ts +13 -0
- package/dist/core/intent.js +45 -0
- package/dist/core/money.d.ts +22 -0
- package/dist/core/money.js +178 -0
- package/dist/core/poll.d.ts +16 -0
- package/dist/core/poll.js +100 -0
- package/dist/core/requisites-frame.d.ts +32 -0
- package/dist/core/requisites-frame.js +202 -0
- package/dist/core/rules/address.d.ts +3 -0
- package/dist/core/rules/address.js +29 -0
- package/dist/core/rules/limits.d.ts +17 -0
- package/dist/core/rules/limits.js +19 -0
- package/dist/core/rules/paying.d.ts +10 -0
- package/dist/core/rules/paying.js +32 -0
- package/dist/core/rules/receipt.d.ts +6 -0
- package/dist/core/rules/receipt.js +33 -0
- package/dist/core/rules/requisites.d.ts +42 -0
- package/dist/core/rules/requisites.js +68 -0
- package/dist/core/rules/slippage.d.ts +1 -0
- package/dist/core/rules/slippage.js +7 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +53 -0
- package/dist/core/types.d.ts +244 -0
- package/dist/core/types.js +1 -0
- package/dist/core/wire.d.ts +178 -0
- package/dist/core/wire.js +602 -0
- package/dist/elements/Root.d.ts +37 -0
- package/dist/elements/Root.js +143 -0
- package/dist/elements/chains.d.ts +1 -0
- package/dist/elements/chains.js +1 -0
- package/dist/elements/components/Qr.d.ts +17 -0
- package/dist/elements/components/Qr.js +28 -0
- package/dist/elements/components/basic.d.ts +42 -0
- package/dist/elements/components/basic.js +129 -0
- package/dist/elements/components/deposit.d.ts +61 -0
- package/dist/elements/components/deposit.js +272 -0
- package/dist/elements/components/inputs.d.ts +24 -0
- package/dist/elements/components/inputs.js +92 -0
- package/dist/elements/components/pickers.d.ts +32 -0
- package/dist/elements/components/pickers.js +267 -0
- package/dist/elements/components/status.d.ts +25 -0
- package/dist/elements/components/status.js +221 -0
- package/dist/elements/context.d.ts +47 -0
- package/dist/elements/context.js +33 -0
- package/dist/elements/hooks/deposit.d.ts +52 -0
- package/dist/elements/hooks/deposit.js +215 -0
- package/dist/elements/hooks/root.d.ts +70 -0
- package/dist/elements/hooks/root.js +125 -0
- package/dist/elements/hooks/withdraw.d.ts +30 -0
- package/dist/elements/hooks/withdraw.js +145 -0
- package/dist/elements/index.d.ts +28 -0
- package/dist/elements/index.js +14 -0
- package/dist/elements/part.d.ts +2 -0
- package/dist/elements/part.js +1 -0
- package/dist/elements/presets/DepositForm.d.ts +32 -0
- package/dist/elements/presets/DepositForm.js +97 -0
- package/dist/elements/presets/WithdrawForm.d.ts +25 -0
- package/dist/elements/presets/WithdrawForm.js +44 -0
- package/dist/elements/presets/focus.d.ts +2 -0
- package/dist/elements/presets/focus.js +26 -0
- package/dist/elements.css +2777 -0
- package/dist/fonts.css +31 -0
- package/dist/frame.d.ts +1 -0
- package/dist/frame.js +37 -6
- package/dist/types.d.ts +1 -0
- package/dist/ui/chains.d.ts +3 -0
- package/dist/ui/chains.js +42 -0
- package/dist/ui/context.d.ts +51 -0
- package/dist/ui/context.js +63 -0
- package/dist/ui/crypto.d.ts +67 -0
- package/dist/ui/crypto.js +68 -0
- package/dist/ui/entry.d.ts +25 -0
- package/dist/ui/entry.js +26 -0
- package/dist/ui/fiat.d.ts +94 -0
- package/dist/ui/fiat.js +149 -0
- package/dist/ui/fields.d.ts +76 -0
- package/dist/ui/fields.js +71 -0
- package/dist/ui/fonts.d.ts +4 -0
- package/dist/ui/fonts.js +31 -0
- package/dist/ui/icons.d.ts +39 -0
- package/dist/ui/icons.js +116 -0
- package/dist/ui/index.d.ts +31 -0
- package/dist/ui/index.js +17 -0
- package/dist/ui/layout.d.ts +36 -0
- package/dist/ui/layout.js +44 -0
- package/dist/ui/logos.d.ts +14 -0
- package/dist/ui/logos.js +61 -0
- package/dist/ui/part.d.ts +32 -0
- package/dist/ui/part.js +33 -0
- package/dist/ui/pickers.d.ts +71 -0
- package/dist/ui/pickers.js +167 -0
- package/dist/ui/qr-encode.d.ts +30 -0
- package/dist/ui/qr-encode.js +340 -0
- package/dist/ui/summary.d.ts +31 -0
- package/dist/ui/summary.js +36 -0
- package/dist/ui/types.d.ts +67 -0
- package/dist/ui/types.js +1 -0
- package/dist/ui/urls.d.ts +4 -0
- package/dist/ui/urls.js +41 -0
- package/dist/ui/withdraw.d.ts +38 -0
- package/dist/ui/withdraw.js +30 -0
- package/dist/ui.css +2699 -0
- package/dist/widget-url.d.ts +1 -0
- package/dist/widget-url.js +16 -0
- package/package.json +46 -5
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export const SERVER_ERROR_CODES = [
|
|
2
|
+
"UNAUTHENTICATED",
|
|
3
|
+
"ORIGIN_MISMATCH",
|
|
4
|
+
"MODE_NOT_ALLOWED",
|
|
5
|
+
"PAY_API_DISABLED",
|
|
6
|
+
"NOT_FOUND",
|
|
7
|
+
"VALIDATION_FAILED",
|
|
8
|
+
"METHOD_UNAVAILABLE",
|
|
9
|
+
"AMOUNT_TOO_SMALL",
|
|
10
|
+
"AMOUNT_TOO_LARGE",
|
|
11
|
+
"INVALID_ADDRESS",
|
|
12
|
+
"UNSUPPORTED_ROUTE",
|
|
13
|
+
"SELF_WALLET",
|
|
14
|
+
"RECIPIENT_BLOCKED",
|
|
15
|
+
"INSUFFICIENT_BALANCE",
|
|
16
|
+
"WITHDRAWALS_RESTRICTED",
|
|
17
|
+
"ACCOUNT_FROZEN",
|
|
18
|
+
"WITHDRAWAL_IN_PROGRESS",
|
|
19
|
+
"TWO_FA_REQUIRED",
|
|
20
|
+
"TWO_FA_INVALID",
|
|
21
|
+
"TWO_FA_REUSED",
|
|
22
|
+
"TWO_FA_LOCKED",
|
|
23
|
+
"DAILY_CAP",
|
|
24
|
+
"RATE_LIMITED",
|
|
25
|
+
"IDEMPOTENCY_CONFLICT",
|
|
26
|
+
"IDEMPOTENCY_IN_PROGRESS",
|
|
27
|
+
"PROVIDER_UNAVAILABLE",
|
|
28
|
+
"INTERNAL_ERROR",
|
|
29
|
+
];
|
|
30
|
+
export const CLIENT_ERROR_CODES = [
|
|
31
|
+
"SESSION_FAILED",
|
|
32
|
+
"PAY_API_UNAVAILABLE",
|
|
33
|
+
"INVALID_API_BASE",
|
|
34
|
+
"HOST_UNREACHABLE",
|
|
35
|
+
"NETWORK_ERROR",
|
|
36
|
+
"INVALID_RESPONSE",
|
|
37
|
+
"REQUISITES_FRAME_UNAVAILABLE",
|
|
38
|
+
"UNKNOWN",
|
|
39
|
+
];
|
|
40
|
+
const SERVER_CODES = new Set(SERVER_ERROR_CODES);
|
|
41
|
+
export const isServerErrorCode = (value) => typeof value === "string" && SERVER_CODES.has(value);
|
|
42
|
+
export class PayError extends Error {
|
|
43
|
+
constructor(code, message = code, options = {}) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = "PayError";
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.status = options.status ?? null;
|
|
48
|
+
this.details = options.details ?? {};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export const isPayError = (value) => value instanceof PayError;
|
|
52
|
+
export const isAbortError = (value) => typeof value === "object" &&
|
|
53
|
+
value !== null &&
|
|
54
|
+
value.name === "AbortError";
|
|
55
|
+
export const toPayError = (value) => {
|
|
56
|
+
if (value instanceof PayError)
|
|
57
|
+
return value;
|
|
58
|
+
return new PayError("UNKNOWN", value instanceof Error && value.message ? value.message : "Unknown error");
|
|
59
|
+
};
|
|
60
|
+
const FALLBACK_BY_STATUS = {
|
|
61
|
+
400: "VALIDATION_FAILED",
|
|
62
|
+
401: "UNAUTHENTICATED",
|
|
63
|
+
403: "MODE_NOT_ALLOWED",
|
|
64
|
+
404: "NOT_FOUND",
|
|
65
|
+
409: "IDEMPOTENCY_IN_PROGRESS",
|
|
66
|
+
413: "VALIDATION_FAILED",
|
|
67
|
+
429: "RATE_LIMITED",
|
|
68
|
+
};
|
|
69
|
+
export const codeForStatus = (status) => FALLBACK_BY_STATUS[status] ??
|
|
70
|
+
(status === 502 || status === 503 || status === 504
|
|
71
|
+
? "PROVIDER_UNAVAILABLE"
|
|
72
|
+
: status >= 500
|
|
73
|
+
? "INTERNAL_ERROR"
|
|
74
|
+
: "UNKNOWN");
|
|
75
|
+
const RETRYABLE = new Set([
|
|
76
|
+
"NETWORK_ERROR",
|
|
77
|
+
"PROVIDER_UNAVAILABLE",
|
|
78
|
+
"INTERNAL_ERROR",
|
|
79
|
+
"RATE_LIMITED",
|
|
80
|
+
"IDEMPOTENCY_IN_PROGRESS",
|
|
81
|
+
"HOST_UNREACHABLE",
|
|
82
|
+
"SESSION_FAILED",
|
|
83
|
+
"REQUISITES_FRAME_UNAVAILABLE",
|
|
84
|
+
"UNKNOWN",
|
|
85
|
+
]);
|
|
86
|
+
export const isRetryable = (error) => RETRYABLE.has(error.code);
|
|
87
|
+
export const FALLBACK_CODES = new Set(["PAY_API_UNAVAILABLE", "PAY_API_DISABLED"]);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { PayErrorCode } from "./errors.js";
|
|
2
|
+
import type { CryptoDepositStatus, DepositSource, DisplayStatus, FiatDepositStatus, WithdrawalStatus } from "./types.js";
|
|
3
|
+
interface EventBase {
|
|
4
|
+
at: number;
|
|
5
|
+
source: "client";
|
|
6
|
+
}
|
|
7
|
+
export type PayEvent = EventBase & ({
|
|
8
|
+
type: "session.ready";
|
|
9
|
+
renewed: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
type: "session.expired";
|
|
12
|
+
} | {
|
|
13
|
+
type: "method.selected";
|
|
14
|
+
methodId: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: "deposit.created";
|
|
17
|
+
depositId: string;
|
|
18
|
+
kind: "crypto" | "fiat";
|
|
19
|
+
methodId: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "deposit.status";
|
|
22
|
+
depositId: string;
|
|
23
|
+
status: CryptoDepositStatus | FiatDepositStatus;
|
|
24
|
+
} | {
|
|
25
|
+
type: "deposit.credited";
|
|
26
|
+
paymentId: number;
|
|
27
|
+
amountUsd: string | null;
|
|
28
|
+
depositSource: DepositSource;
|
|
29
|
+
creditedAt: number;
|
|
30
|
+
} | {
|
|
31
|
+
type: "withdrawal.created";
|
|
32
|
+
withdrawalId: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: "withdrawal.status";
|
|
35
|
+
withdrawalId: string;
|
|
36
|
+
status: WithdrawalStatus;
|
|
37
|
+
displayStatus: DisplayStatus;
|
|
38
|
+
paymentId?: number;
|
|
39
|
+
} | {
|
|
40
|
+
type: "close.requested";
|
|
41
|
+
} | {
|
|
42
|
+
type: "error";
|
|
43
|
+
code: PayErrorCode;
|
|
44
|
+
scope: string;
|
|
45
|
+
});
|
|
46
|
+
export type PayEventType = PayEvent["type"];
|
|
47
|
+
type DistributiveOmit<T, K extends keyof never> = T extends unknown ? Omit<T, K> : never;
|
|
48
|
+
export type PayEventInput = DistributiveOmit<PayEvent, "at" | "source">;
|
|
49
|
+
export declare const createEvent: (input: PayEventInput, at?: number) => PayEvent;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const createEvent = (input, at = Date.now()) => ({ ...input, at, source: "client" });
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Timers } from "../api-base.js";
|
|
2
|
+
import type { PayClient } from "../client.js";
|
|
3
|
+
import { PayError } from "../errors.js";
|
|
4
|
+
import { type PayView, type RequisitesView } from "../rules/requisites.js";
|
|
5
|
+
import { type ReadableStore } from "../store.js";
|
|
6
|
+
import type { CreditedDeposit, Deposit, DepositQuote, FiatDepositStatus, FiatMethod, PayContext, PayMethod, PayMethods, PayTheme } from "../types.js";
|
|
7
|
+
export type DepositStep = "loading" | "pick-method" | "enter-amount" | "creating" | "crypto-address" | "requisites" | "redirect" | "onramp" | "done" | "error";
|
|
8
|
+
export type DepositOutcome = "credited" | "completed" | "failed" | "expired";
|
|
9
|
+
export interface DepositFlowState {
|
|
10
|
+
step: DepositStep;
|
|
11
|
+
context: PayContext | null;
|
|
12
|
+
methods: PayMethods | null;
|
|
13
|
+
method: PayMethod | null;
|
|
14
|
+
amount: string;
|
|
15
|
+
customerPhone: string;
|
|
16
|
+
amountError: PayError | null;
|
|
17
|
+
quote: DepositQuote | null;
|
|
18
|
+
quoteLoading: boolean;
|
|
19
|
+
quoteError: PayError | null;
|
|
20
|
+
deposit: Deposit | null;
|
|
21
|
+
view: PayView | null;
|
|
22
|
+
shownStatus: FiatDepositStatus | null;
|
|
23
|
+
knownRequisites: RequisitesView | null;
|
|
24
|
+
onrampUrl: string | null;
|
|
25
|
+
onrampLoading: boolean;
|
|
26
|
+
onrampError: PayError | null;
|
|
27
|
+
credited: CreditedDeposit[];
|
|
28
|
+
receiptPending: boolean;
|
|
29
|
+
receiptError: PayError | null;
|
|
30
|
+
outcome: DepositOutcome | null;
|
|
31
|
+
submitError: PayError | null;
|
|
32
|
+
error: PayError | null;
|
|
33
|
+
}
|
|
34
|
+
export interface DepositFlowActions {
|
|
35
|
+
start: () => void;
|
|
36
|
+
selectMethod: (methodId: string) => void;
|
|
37
|
+
setAmount: (raw: string) => void;
|
|
38
|
+
setCustomerPhone: (value: string) => void;
|
|
39
|
+
submit: () => Promise<void>;
|
|
40
|
+
attachReceipt: (file: Blob) => Promise<void>;
|
|
41
|
+
loadOnramp: () => Promise<string | null>;
|
|
42
|
+
retryOnramp: () => Promise<string | null>;
|
|
43
|
+
refreshContext: () => Promise<void>;
|
|
44
|
+
back: () => void;
|
|
45
|
+
retry: () => void;
|
|
46
|
+
reset: () => void;
|
|
47
|
+
destroy: () => void;
|
|
48
|
+
}
|
|
49
|
+
export interface FlowStore<S, A> extends ReadableStore<S> {
|
|
50
|
+
actions: A;
|
|
51
|
+
}
|
|
52
|
+
export type DepositFlow = FlowStore<DepositFlowState, DepositFlowActions>;
|
|
53
|
+
export interface DepositFlowOptions {
|
|
54
|
+
quoteDebounceMs?: number;
|
|
55
|
+
depositPollMs?: number;
|
|
56
|
+
activityPollMs?: number;
|
|
57
|
+
maxPollMs?: number;
|
|
58
|
+
returnUrl?: string;
|
|
59
|
+
onrampTheme?: PayTheme;
|
|
60
|
+
timers?: Timers;
|
|
61
|
+
}
|
|
62
|
+
export declare const fiatAmountHint: (method: FiatMethod, amount: string) => PayError | null;
|
|
63
|
+
export declare const createDepositFlow: (client: PayClient, options?: DepositFlowOptions) => DepositFlow;
|