@heliofi/withdraw-core 0.3.4-alpha.1782910080 → 0.5.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/dist/index.d.ts +1 -1
- package/dist/sdk/WithdrawalSDK.d.ts +6 -4
- package/dist/types/enums.d.ts +1 -49
- package/dist/types/index.d.ts +2 -2
- package/dist/types/prepared.d.ts +19 -1
- package/dist/types/requests.d.ts +2 -2
- package/dist/withdraw-core.cjs +1 -1
- package/dist/withdraw-core.js +59 -44
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export type { WithdrawalJwtPayload } from './jwt';
|
|
|
3
3
|
export { decodeJwt, isQuoteExpired } from './jwt';
|
|
4
4
|
export type { ApiClientConfig } from './sdk';
|
|
5
5
|
export { WithdrawalSDK } from './sdk';
|
|
6
|
-
export type { BalanceResponse, BaseBlockchain, PolymarketWalletPreparedTransaction, PreparedTransaction,
|
|
6
|
+
export type { BalanceResponse, BaseBlockchain, CreateWithdrawalDetailParams, HypercorePreparedTransaction, PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, SubmitWithdrawalParams, UpdateWithdrawalDetailParams, UserOpPreparedTransaction, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './types';
|
|
7
7
|
export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalFeature, WithdrawalState, } from './types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { QuoteResponse } from '../types/prepared';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CreateWithdrawalDetailParams, SubmitWithdrawalParams, UpdateWithdrawalDetailParams } from '../types/requests';
|
|
3
3
|
import type { BalanceResponse, RoutesResponse, StatusResponse, SubmitResponse, WithdrawalConfig } from '../types/responses';
|
|
4
4
|
import { ApiClient, type ApiClientConfig } from './ApiClient';
|
|
5
5
|
export declare class WithdrawalSDK {
|
|
@@ -10,19 +10,21 @@ export declare class WithdrawalSDK {
|
|
|
10
10
|
getRoutes(withdrawalConfigId: string, signal?: AbortSignal): Promise<RoutesResponse>;
|
|
11
11
|
getBalance(withdrawalConfigId: string, walletAddress: string, signal?: AbortSignal): Promise<BalanceResponse>;
|
|
12
12
|
/**
|
|
13
|
+
* Create a withdrawal detail (a priced quote) for a config.
|
|
14
|
+
*
|
|
13
15
|
* Calls `POST /withdraw/:withdrawalConfigId/prepare`.
|
|
14
16
|
* `withdrawalConfigId` goes in the path; the remaining fields are the
|
|
15
17
|
* request body matching the backend `PreparedWithdrawalDto`.
|
|
16
18
|
*/
|
|
17
|
-
|
|
19
|
+
createWithdrawalDetail(params: CreateWithdrawalDetailParams, signal?: AbortSignal): Promise<QuoteResponse>;
|
|
18
20
|
/**
|
|
19
|
-
* Update an existing quote.
|
|
21
|
+
* Update an existing withdrawal detail, returning a fresh quote.
|
|
20
22
|
*
|
|
21
23
|
* NOTE: The backend does not yet expose a PATCH endpoint for prepare.
|
|
22
24
|
* This stub is kept for forward compatibility. It will throw until
|
|
23
25
|
* the backend ships the handler.
|
|
24
26
|
*/
|
|
25
|
-
|
|
27
|
+
updateWithdrawalDetail(_withdrawalDetailId: string, _params: UpdateWithdrawalDetailParams, _signal?: AbortSignal): Promise<QuoteResponse>;
|
|
26
28
|
/**
|
|
27
29
|
* Body matches the backend `SubmitWithdrawalDto`:
|
|
28
30
|
* `{ token, signedTx }`, where `signedTx` is the bare signed payload string.
|
package/dist/types/enums.d.ts
CHANGED
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
EVM = "EVM",
|
|
3
|
-
SOL = "SOL",
|
|
4
|
-
BTC = "BTC",
|
|
5
|
-
TRON = "TRON",
|
|
6
|
-
HYPERCORE = "HYPERCORE",
|
|
7
|
-
DOGE = "DOGE"
|
|
8
|
-
}
|
|
9
|
-
declare enum BlockchainSymbol {
|
|
10
|
-
SOL = "SOL",
|
|
11
|
-
ETH = "ETH",
|
|
12
|
-
POLYGON = "POLYGON",
|
|
13
|
-
BASE = "BASE",
|
|
14
|
-
BITCOIN = "BITCOIN",
|
|
15
|
-
ARBITRUM = "ARBITRUM",
|
|
16
|
-
BSC = "BSC",
|
|
17
|
-
TRON = "TRON",
|
|
18
|
-
DOGE = "DOGE"
|
|
19
|
-
}
|
|
20
|
-
declare enum BroadcastAck {
|
|
21
|
-
ACKNOWLEDGED = "acknowledged",
|
|
22
|
-
UNACKNOWLEDGED = "unacknowledged",
|
|
23
|
-
REJECTED = "rejected"
|
|
24
|
-
}
|
|
25
|
-
declare enum SignedTransactionKind {
|
|
26
|
-
RAW = "raw",
|
|
27
|
-
USER_OP = "userop",
|
|
28
|
-
POLYMARKET_WALLET = "polymarket_wallet",
|
|
29
|
-
HYPERCORE = "hypercore"
|
|
30
|
-
}
|
|
31
|
-
declare enum WithdrawalFeature {
|
|
32
|
-
IRON = "iron",
|
|
33
|
-
MP_SELL = "mp_sell"
|
|
34
|
-
}
|
|
35
|
-
declare enum Platform {
|
|
36
|
-
HELIO = "HELIO",
|
|
37
|
-
MAGIC_EDEN = "MAGIC_EDEN"
|
|
38
|
-
}
|
|
39
|
-
declare enum WithdrawalState {
|
|
40
|
-
QUOTED = "QUOTED",
|
|
41
|
-
SUBMITTING = "SUBMITTING",
|
|
42
|
-
SUBMITTED = "SUBMITTED",
|
|
43
|
-
BRIDGING = "BRIDGING",
|
|
44
|
-
COMPLETED = "COMPLETED",
|
|
45
|
-
FAILED = "FAILED",
|
|
46
|
-
FAILED_EXPIRED = "FAILED_EXPIRED",
|
|
47
|
-
EXPIRED = "EXPIRED",
|
|
48
|
-
REFUNDED_BY_PROVIDER = "REFUNDED_BY_PROVIDER"
|
|
49
|
-
}
|
|
1
|
+
import { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, WithdrawalFeature, WithdrawalState } from '@heliofi/common-fe';
|
|
50
2
|
export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, WithdrawalFeature, WithdrawalState, };
|
|
51
3
|
export declare const TERMINAL_STATES: ReadonlySet<WithdrawalState>;
|
|
52
4
|
export declare enum WithdrawalErrorCode {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalFeature, WithdrawalState, } from './enums';
|
|
2
|
-
export type { PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, UserOpPreparedTransaction, } from './prepared';
|
|
3
|
-
export type {
|
|
2
|
+
export type { HypercorePreparedTransaction, PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, UserOpPreparedTransaction, } from './prepared';
|
|
3
|
+
export type { CreateWithdrawalDetailParams, SubmitWithdrawalParams, UpdateWithdrawalDetailParams, } from './requests';
|
|
4
4
|
export type { BalanceResponse, BaseBlockchain, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './responses';
|
package/dist/types/prepared.d.ts
CHANGED
|
@@ -13,8 +13,26 @@ export interface UserOpPreparedTransaction {
|
|
|
13
13
|
chain: string;
|
|
14
14
|
userOp: Record<string, unknown>;
|
|
15
15
|
entryPoint: string;
|
|
16
|
+
/**
|
|
17
|
+
* EIP-7702 authorization tuple. Optional — present only when the userOp
|
|
18
|
+
* carries one. Mirrors the backend `UserOpPreparedTransaction.authorization?`.
|
|
19
|
+
*/
|
|
20
|
+
authorization?: {
|
|
21
|
+
chainId: string;
|
|
22
|
+
address: string;
|
|
23
|
+
nonce: string;
|
|
24
|
+
};
|
|
16
25
|
}
|
|
17
|
-
|
|
26
|
+
/**
|
|
27
|
+
* HyperCore lane: the merchant signs the EIP-712 typed data of the HyperCore
|
|
28
|
+
* action (same modality as Polymarket); submit carries back the signature.
|
|
29
|
+
*/
|
|
30
|
+
export interface HypercorePreparedTransaction {
|
|
31
|
+
kind: SignedTransactionKind.HYPERCORE;
|
|
32
|
+
chain: string;
|
|
33
|
+
typedData: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
export type PreparedTransaction = PolymarketWalletPreparedTransaction | RawPreparedTransaction | UserOpPreparedTransaction | HypercorePreparedTransaction;
|
|
18
36
|
export interface QuoteSummary {
|
|
19
37
|
sourceToken: string;
|
|
20
38
|
sourceAmount: string;
|
package/dist/types/requests.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Field names mirror the backend `PreparedWithdrawalDto` exactly.
|
|
5
5
|
* `withdrawalConfigId` is sent as a URL path segment (not in the body).
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface CreateWithdrawalDetailParams {
|
|
8
8
|
/** Merchant withdrawal config ID — used in the URL path. */
|
|
9
9
|
withdrawalConfigId: string;
|
|
10
10
|
/** Owner address of the source wallet (lane-specific format). */
|
|
@@ -24,7 +24,7 @@ export interface PrepareWithdrawalParams {
|
|
|
24
24
|
* is kept as a forward-compatible stub and will throw at runtime until
|
|
25
25
|
* the backend ships the PATCH handler.
|
|
26
26
|
*/
|
|
27
|
-
export interface
|
|
27
|
+
export interface UpdateWithdrawalDetailParams {
|
|
28
28
|
amount: string;
|
|
29
29
|
recipient?: string;
|
|
30
30
|
toCurrencyId?: string;
|
package/dist/withdraw-core.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var N=Object.defineProperty;var i=(e,t,E)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:E}):e[t]=E;var r=(e,t,E)=>i(e,typeof t!="symbol"?t+"":t,E);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let u=(function(e){return e.SOL="SOL",e.ETH="ETH",e.POLYGON="POLYGON",e.BASE="BASE",e.BITCOIN="BITCOIN",e.ARBITRUM="ARBITRUM",e.BSC="BSC",e.TRON="TRON",e.DOGE="DOGE",e})({}),W=(function(e){return e.EVM="EVM",e.SOL="SOL",e.BTC="BTC",e.TRON="TRON",e.HYPERCORE="HYPERCORE",e.DOGE="DOGE",e})({}),o=(function(e){return e.HELIO="HELIO",e.MAGIC_EDEN="MAGIC_EDEN",e})({}),L=(function(e){return e.IRON="iron",e.MP_SELL="mp_sell",e})({}),T=(function(e){return e.QUOTED="QUOTED",e.SUBMITTING="SUBMITTING",e.SUBMITTED="SUBMITTED",e.BRIDGING="BRIDGING",e.COMPLETED="COMPLETED",e.FAILED="FAILED",e.FAILED_EXPIRED="FAILED_EXPIRED",e.EXPIRED="EXPIRED",e.REFUNDED_BY_PROVIDER="REFUNDED_BY_PROVIDER",e})({}),c=(function(e){return e.ACKNOWLEDGED="acknowledged",e.UNACKNOWLEDGED="unacknowledged",e.REJECTED="rejected",e})({}),U=(function(e){return e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e.HYPERCORE="hypercore",e})({});const H=new Set([T.COMPLETED,T.FAILED,T.FAILED_EXPIRED,T.EXPIRED,T.REFUNDED_BY_PROVIDER]);var I=(e=>(e.WITHDRAW_TX_INVALID_SIGNATURE="WITHDRAW_TX_INVALID_SIGNATURE",e.WITHDRAW_TX_BLOCKHASH_EXPIRED="WITHDRAW_TX_BLOCKHASH_EXPIRED",e.WITHDRAW_TX_NONCE_TOO_LOW="WITHDRAW_TX_NONCE_TOO_LOW",e.WITHDRAW_TX_USEROP_EXPIRED="WITHDRAW_TX_USEROP_EXPIRED",e.WITHDRAW_TX_UNDERPRICED="WITHDRAW_TX_UNDERPRICED",e.WITHDRAW_BUNDLER_REJECTED="WITHDRAW_BUNDLER_REJECTED",e.WITHDRAW_TX_BROADCAST_TIMEOUT="WITHDRAW_TX_BROADCAST_TIMEOUT",e.WITHDRAW_TX_ALREADY_KNOWN="WITHDRAW_TX_ALREADY_KNOWN",e.WITHDRAW_QUOTE_EXPIRED="WITHDRAW_QUOTE_EXPIRED",e.WITHDRAW_SANCTIONS_BLOCKED="WITHDRAW_SANCTIONS_BLOCKED",e.WITHDRAW_NO_ROUTE="WITHDRAW_NO_ROUTE",e.WITHDRAW_NOT_FOUND="WITHDRAW_NOT_FOUND",e.WITHDRAW_INSUFFICIENT_BALANCE="WITHDRAW_INSUFFICIENT_BALANCE",e.WITHDRAW_DETAILS_NOT_UPDATABLE="WITHDRAW_DETAILS_NOT_UPDATABLE",e.INVALID_WALLET_ADDRESS="INVALID_WALLET_ADDRESS",e.BALANCE_FETCH_FAILED="BALANCE_FETCH_FAILED",e.UNKNOWN="UNKNOWN",e))(I||{});const C=new Set(Object.values(I));class A extends Error{constructor(E,s,D){super(D??s);r(this,"name","WithdrawalApiError");this.status=E,this.code=s,this.detail=D}}const n=e=>e&&C.has(e)?e:I.UNKNOWN,O=e=>{const t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected 3 parts");const E=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(E)},l=(e,t=5e3)=>{const{exp:E}=O(e);return E===void 0?!1:Date.now()>=E*1e3-t},p="0.5.0";class P{constructor(t){r(this,"baseUrl");r(this,"headers");r(this,"fetch");var E,s;this.baseUrl=t.baseUrl.endsWith("/")?t.baseUrl.slice(0,-1):t.baseUrl,this.headers={"Content-Type":"application/json","X-MoonPay-Commerce-SDK-Version":p,...(E=t.consumer)!=null&&E.name?{"X-MoonPay-Commerce-Consumer":t.consumer.name}:{},...(s=t.consumer)!=null&&s.version?{"X-MoonPay-Commerce-Consumer-Version":t.consumer.version}:{},...t.headers},this.fetch=t.fetch??globalThis.fetch.bind(globalThis)}async get(t,E){return this.request("GET",t,void 0,E)}async post(t,E,s){return this.request("POST",t,E,s)}async patch(t,E,s){return this.request("PATCH",t,E,s)}async request(t,E,s,D){const a=`${this.baseUrl}${E}`,_=await this.fetch(a,{method:t,headers:this.headers,body:s!==void 0?JSON.stringify(s):void 0,signal:D});if(!_.ok)throw await this.buildError(_);return await _.json()}async buildError(t){let E,s;try{const D=await t.json();E=D.message??void 0,s=D.errorCode??D.errorType??void 0}catch{E=t.statusText||void 0}return new A(t.status,n(s),E)}}class R{constructor(t){this.api=t}static create(t){return new R(new P(t))}async getWithdrawalConfig(t,E){return this.api.get(`/withdrawal-configs/${t}/public`,E)}async getRoutes(t,E){return this.api.get(`/withdraw/${t}/routes`,E)}async getBalance(t,E,s){return this.api.get(`/withdraw/${t}/balances?walletAddress=${encodeURIComponent(E)}`,s)}async createWithdrawalDetail(t,E){const{withdrawalConfigId:s,...D}=t;return this.api.post(`/withdraw/${s}/prepare`,D,E)}async updateWithdrawalDetail(t,E,s){throw new Error("updateWithdrawalDetail is not yet supported by the backend. Create a new withdrawal detail via createWithdrawalDetail() instead.")}async submitWithdrawal(t,E){const{withdrawalDetailId:s,...D}=t;return this.api.post(`/withdraw/${s}/submit`,D,E)}async getWithdrawalDetail(t,E){return this.api.get(`/withdraw-details/${t}`,E)}}exports.BlockchainEngineType=W;exports.BlockchainSymbol=u;exports.BroadcastAck=c;exports.Platform=o;exports.SignedTransactionKind=U;exports.TERMINAL_STATES=H;exports.WithdrawalApiError=A;exports.WithdrawalErrorCode=I;exports.WithdrawalFeature=L;exports.WithdrawalSDK=R;exports.WithdrawalState=T;exports.decodeJwt=O;exports.isQuoteExpired=l;exports.toWithdrawalErrorCode=n;
|
package/dist/withdraw-core.js
CHANGED
|
@@ -1,35 +1,48 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var T = (e, t, E) =>
|
|
4
|
-
|
|
1
|
+
var O = Object.defineProperty;
|
|
2
|
+
var n = (e, t, E) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: E }) : e[t] = E;
|
|
3
|
+
var T = (e, t, E) => n(e, typeof t != "symbol" ? t + "" : t, E);
|
|
4
|
+
let H = /* @__PURE__ */ (function(e) {
|
|
5
|
+
return e.SOL = "SOL", e.ETH = "ETH", e.POLYGON = "POLYGON", e.BASE = "BASE", e.BITCOIN = "BITCOIN", e.ARBITRUM = "ARBITRUM", e.BSC = "BSC", e.TRON = "TRON", e.DOGE = "DOGE", e;
|
|
6
|
+
})({}), C = /* @__PURE__ */ (function(e) {
|
|
7
|
+
return e.EVM = "EVM", e.SOL = "SOL", e.BTC = "BTC", e.TRON = "TRON", e.HYPERCORE = "HYPERCORE", e.DOGE = "DOGE", e;
|
|
8
|
+
})({}), c = /* @__PURE__ */ (function(e) {
|
|
9
|
+
return e.HELIO = "HELIO", e.MAGIC_EDEN = "MAGIC_EDEN", e;
|
|
10
|
+
})({}), o = /* @__PURE__ */ (function(e) {
|
|
11
|
+
return e.IRON = "iron", e.MP_SELL = "mp_sell", e;
|
|
12
|
+
})({}), I = /* @__PURE__ */ (function(e) {
|
|
13
|
+
return e.QUOTED = "QUOTED", e.SUBMITTING = "SUBMITTING", e.SUBMITTED = "SUBMITTED", e.BRIDGING = "BRIDGING", e.COMPLETED = "COMPLETED", e.FAILED = "FAILED", e.FAILED_EXPIRED = "FAILED_EXPIRED", e.EXPIRED = "EXPIRED", e.REFUNDED_BY_PROVIDER = "REFUNDED_BY_PROVIDER", e;
|
|
14
|
+
})({}), p = /* @__PURE__ */ (function(e) {
|
|
15
|
+
return e.ACKNOWLEDGED = "acknowledged", e.UNACKNOWLEDGED = "unacknowledged", e.REJECTED = "rejected", e;
|
|
16
|
+
})({}), P = /* @__PURE__ */ (function(e) {
|
|
17
|
+
return e.RAW = "raw", e.USER_OP = "userop", e.POLYMARKET_WALLET = "polymarket_wallet", e.HYPERCORE = "hypercore", e;
|
|
18
|
+
})({});
|
|
5
19
|
const X = /* @__PURE__ */ new Set([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/* REFUNDED_BY_PROVIDER */
|
|
20
|
+
I.COMPLETED,
|
|
21
|
+
I.FAILED,
|
|
22
|
+
I.FAILED_EXPIRED,
|
|
23
|
+
I.EXPIRED,
|
|
24
|
+
I.REFUNDED_BY_PROVIDER
|
|
12
25
|
]);
|
|
13
|
-
var
|
|
14
|
-
const
|
|
15
|
-
class
|
|
26
|
+
var R = /* @__PURE__ */ ((e) => (e.WITHDRAW_TX_INVALID_SIGNATURE = "WITHDRAW_TX_INVALID_SIGNATURE", e.WITHDRAW_TX_BLOCKHASH_EXPIRED = "WITHDRAW_TX_BLOCKHASH_EXPIRED", e.WITHDRAW_TX_NONCE_TOO_LOW = "WITHDRAW_TX_NONCE_TOO_LOW", e.WITHDRAW_TX_USEROP_EXPIRED = "WITHDRAW_TX_USEROP_EXPIRED", e.WITHDRAW_TX_UNDERPRICED = "WITHDRAW_TX_UNDERPRICED", e.WITHDRAW_BUNDLER_REJECTED = "WITHDRAW_BUNDLER_REJECTED", e.WITHDRAW_TX_BROADCAST_TIMEOUT = "WITHDRAW_TX_BROADCAST_TIMEOUT", e.WITHDRAW_TX_ALREADY_KNOWN = "WITHDRAW_TX_ALREADY_KNOWN", e.WITHDRAW_QUOTE_EXPIRED = "WITHDRAW_QUOTE_EXPIRED", e.WITHDRAW_SANCTIONS_BLOCKED = "WITHDRAW_SANCTIONS_BLOCKED", e.WITHDRAW_NO_ROUTE = "WITHDRAW_NO_ROUTE", e.WITHDRAW_NOT_FOUND = "WITHDRAW_NOT_FOUND", e.WITHDRAW_INSUFFICIENT_BALANCE = "WITHDRAW_INSUFFICIENT_BALANCE", e.WITHDRAW_DETAILS_NOT_UPDATABLE = "WITHDRAW_DETAILS_NOT_UPDATABLE", e.INVALID_WALLET_ADDRESS = "INVALID_WALLET_ADDRESS", e.BALANCE_FETCH_FAILED = "BALANCE_FETCH_FAILED", e.UNKNOWN = "UNKNOWN", e))(R || {});
|
|
27
|
+
const N = new Set(Object.values(R));
|
|
28
|
+
class u extends Error {
|
|
16
29
|
constructor(E, s, D) {
|
|
17
30
|
super(D ?? s);
|
|
18
31
|
T(this, "name", "WithdrawalApiError");
|
|
19
32
|
this.status = E, this.code = s, this.detail = D;
|
|
20
33
|
}
|
|
21
34
|
}
|
|
22
|
-
const
|
|
35
|
+
const W = (e) => e && N.has(e) ? e : R.UNKNOWN, a = (e) => {
|
|
23
36
|
const t = e.split(".");
|
|
24
37
|
if (t.length !== 3)
|
|
25
38
|
throw new Error("Invalid JWT: expected 3 parts");
|
|
26
39
|
const E = atob(t[1].replace(/-/g, "+").replace(/_/g, "/"));
|
|
27
40
|
return JSON.parse(E);
|
|
28
|
-
},
|
|
29
|
-
const { exp: E } =
|
|
41
|
+
}, l = (e, t = 5e3) => {
|
|
42
|
+
const { exp: E } = a(e);
|
|
30
43
|
return E === void 0 ? !1 : Date.now() >= E * 1e3 - t;
|
|
31
|
-
},
|
|
32
|
-
class
|
|
44
|
+
}, i = "0.5.0";
|
|
45
|
+
class L {
|
|
33
46
|
constructor(t) {
|
|
34
47
|
T(this, "baseUrl");
|
|
35
48
|
T(this, "headers");
|
|
@@ -38,7 +51,7 @@ class o {
|
|
|
38
51
|
this.baseUrl = t.baseUrl.endsWith("/") ? t.baseUrl.slice(0, -1) : t.baseUrl, this.headers = {
|
|
39
52
|
"Content-Type": "application/json",
|
|
40
53
|
// Every request self-identifies with the client version (always sent).
|
|
41
|
-
"X-MoonPay-Commerce-SDK-Version":
|
|
54
|
+
"X-MoonPay-Commerce-SDK-Version": i,
|
|
42
55
|
...(E = t.consumer) != null && E.name ? { "X-MoonPay-Commerce-Consumer": t.consumer.name } : {},
|
|
43
56
|
...(s = t.consumer) != null && s.version ? { "X-MoonPay-Commerce-Consumer-Version": t.consumer.version } : {},
|
|
44
57
|
...t.headers
|
|
@@ -54,15 +67,15 @@ class o {
|
|
|
54
67
|
return this.request("PATCH", t, E, s);
|
|
55
68
|
}
|
|
56
69
|
async request(t, E, s, D) {
|
|
57
|
-
const r = `${this.baseUrl}${E}`,
|
|
70
|
+
const r = `${this.baseUrl}${E}`, _ = await this.fetch(r, {
|
|
58
71
|
method: t,
|
|
59
72
|
headers: this.headers,
|
|
60
73
|
body: s !== void 0 ? JSON.stringify(s) : void 0,
|
|
61
74
|
signal: D
|
|
62
75
|
});
|
|
63
|
-
if (!
|
|
64
|
-
throw await this.buildError(
|
|
65
|
-
return await
|
|
76
|
+
if (!_.ok)
|
|
77
|
+
throw await this.buildError(_);
|
|
78
|
+
return await _.json();
|
|
66
79
|
}
|
|
67
80
|
async buildError(t) {
|
|
68
81
|
let E, s;
|
|
@@ -72,21 +85,21 @@ class o {
|
|
|
72
85
|
} catch {
|
|
73
86
|
E = t.statusText || void 0;
|
|
74
87
|
}
|
|
75
|
-
return new
|
|
88
|
+
return new u(
|
|
76
89
|
t.status,
|
|
77
|
-
|
|
90
|
+
W(s),
|
|
78
91
|
E
|
|
79
92
|
);
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
|
-
class
|
|
95
|
+
class A {
|
|
83
96
|
// Takes a prebuilt ApiClient (DI). Use `WithdrawalSDK.create()` for the
|
|
84
97
|
// common case where you just have config.
|
|
85
98
|
constructor(t) {
|
|
86
99
|
this.api = t;
|
|
87
100
|
}
|
|
88
101
|
static create(t) {
|
|
89
|
-
return new
|
|
102
|
+
return new A(new L(t));
|
|
90
103
|
}
|
|
91
104
|
async getWithdrawalConfig(t, E) {
|
|
92
105
|
return this.api.get(
|
|
@@ -106,11 +119,13 @@ class R {
|
|
|
106
119
|
);
|
|
107
120
|
}
|
|
108
121
|
/**
|
|
122
|
+
* Create a withdrawal detail (a priced quote) for a config.
|
|
123
|
+
*
|
|
109
124
|
* Calls `POST /withdraw/:withdrawalConfigId/prepare`.
|
|
110
125
|
* `withdrawalConfigId` goes in the path; the remaining fields are the
|
|
111
126
|
* request body matching the backend `PreparedWithdrawalDto`.
|
|
112
127
|
*/
|
|
113
|
-
async
|
|
128
|
+
async createWithdrawalDetail(t, E) {
|
|
114
129
|
const { withdrawalConfigId: s, ...D } = t;
|
|
115
130
|
return this.api.post(
|
|
116
131
|
`/withdraw/${s}/prepare`,
|
|
@@ -119,15 +134,15 @@ class R {
|
|
|
119
134
|
);
|
|
120
135
|
}
|
|
121
136
|
/**
|
|
122
|
-
* Update an existing quote.
|
|
137
|
+
* Update an existing withdrawal detail, returning a fresh quote.
|
|
123
138
|
*
|
|
124
139
|
* NOTE: The backend does not yet expose a PATCH endpoint for prepare.
|
|
125
140
|
* This stub is kept for forward compatibility. It will throw until
|
|
126
141
|
* the backend ships the handler.
|
|
127
142
|
*/
|
|
128
|
-
async
|
|
143
|
+
async updateWithdrawalDetail(t, E, s) {
|
|
129
144
|
throw new Error(
|
|
130
|
-
"
|
|
145
|
+
"updateWithdrawalDetail is not yet supported by the backend. Create a new withdrawal detail via createWithdrawalDetail() instead."
|
|
131
146
|
);
|
|
132
147
|
}
|
|
133
148
|
/**
|
|
@@ -147,18 +162,18 @@ class R {
|
|
|
147
162
|
}
|
|
148
163
|
}
|
|
149
164
|
export {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
165
|
+
C as BlockchainEngineType,
|
|
166
|
+
H as BlockchainSymbol,
|
|
167
|
+
p as BroadcastAck,
|
|
168
|
+
c as Platform,
|
|
169
|
+
P as SignedTransactionKind,
|
|
155
170
|
X as TERMINAL_STATES,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
171
|
+
u as WithdrawalApiError,
|
|
172
|
+
R as WithdrawalErrorCode,
|
|
173
|
+
o as WithdrawalFeature,
|
|
174
|
+
A as WithdrawalSDK,
|
|
175
|
+
I as WithdrawalState,
|
|
176
|
+
a as decodeJwt,
|
|
177
|
+
l as isQuoteExpired,
|
|
178
|
+
W as toWithdrawalErrorCode
|
|
164
179
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heliofi/withdraw-core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"vitest": "3.2.4"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@heliofi/common": "0.2.
|
|
44
|
+
"@heliofi/common-fe": "0.2.278-alpha.1782920922"
|
|
45
45
|
}
|
|
46
46
|
}
|