@1money/protocol-ts-sdk 1.1.2 → 2.0.1
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/.claude/settings.local.json +18 -1
- package/README.md +216 -134
- package/es/__integration__/helpers.d.ts +0 -7
- package/es/api/checkpoints/types.d.ts +0 -1
- package/es/api/index.js +49 -10
- package/es/api/tokens/index.d.ts +7 -1
- package/es/api/tokens/types.d.ts +21 -6
- package/es/api/transactions/index.d.ts +4 -3
- package/es/api/transactions/types.d.ts +14 -5
- package/es/client/core.d.ts +2 -4
- package/es/client/index.js +36 -4
- package/es/index.d.ts +1 -0
- package/es/index.js +513 -22
- package/es/signing/builders/index.d.ts +11 -0
- package/es/signing/builders/payment.d.ts +3 -0
- package/es/signing/builders/tokenAuthority.d.ts +3 -0
- package/es/signing/builders/tokenBridgeAndMint.d.ts +3 -0
- package/es/signing/builders/tokenBurn.d.ts +3 -0
- package/es/signing/builders/tokenBurnAndBridge.d.ts +3 -0
- package/es/signing/builders/tokenClawback.d.ts +3 -0
- package/es/signing/builders/tokenIssue.d.ts +3 -0
- package/es/signing/builders/tokenManageList.d.ts +3 -0
- package/es/signing/builders/tokenMetadata.d.ts +3 -0
- package/es/signing/builders/tokenMint.d.ts +3 -0
- package/es/signing/builders/tokenPause.d.ts +3 -0
- package/es/signing/builders/validate.d.ts +18 -0
- package/es/signing/core.d.ts +27 -0
- package/es/signing/index.d.ts +18 -0
- package/es/signing/signer.d.ts +3 -0
- package/es/utils/encode.d.ts +11 -0
- package/es/utils/index.d.ts +2 -1
- package/es/utils/index.js +90 -10
- package/es/utils/interface.d.ts +27 -0
- package/es/utils/sign.d.ts +6 -1
- package/eslint.config.mjs +101 -0
- package/lib/__integration__/helpers.d.ts +0 -7
- package/lib/api/checkpoints/types.d.ts +0 -1
- package/lib/api/index.js +59 -10
- package/lib/api/tokens/index.d.ts +7 -1
- package/lib/api/tokens/types.d.ts +21 -6
- package/lib/api/transactions/index.d.ts +4 -3
- package/lib/api/transactions/types.d.ts +14 -5
- package/lib/client/core.d.ts +2 -4
- package/lib/client/index.js +46 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +511 -21
- package/lib/signing/builders/index.d.ts +11 -0
- package/lib/signing/builders/payment.d.ts +3 -0
- package/lib/signing/builders/tokenAuthority.d.ts +3 -0
- package/lib/signing/builders/tokenBridgeAndMint.d.ts +3 -0
- package/lib/signing/builders/tokenBurn.d.ts +3 -0
- package/lib/signing/builders/tokenBurnAndBridge.d.ts +3 -0
- package/lib/signing/builders/tokenClawback.d.ts +3 -0
- package/lib/signing/builders/tokenIssue.d.ts +3 -0
- package/lib/signing/builders/tokenManageList.d.ts +3 -0
- package/lib/signing/builders/tokenMetadata.d.ts +3 -0
- package/lib/signing/builders/tokenMint.d.ts +3 -0
- package/lib/signing/builders/tokenPause.d.ts +3 -0
- package/lib/signing/builders/validate.d.ts +18 -0
- package/lib/signing/core.d.ts +27 -0
- package/lib/signing/index.d.ts +18 -0
- package/lib/signing/signer.d.ts +3 -0
- package/lib/utils/encode.d.ts +11 -0
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +90 -10
- package/lib/utils/interface.d.ts +27 -0
- package/lib/utils/sign.d.ts +6 -1
- package/package.json +26 -15
- package/umd/1money-protocol-ts-sdk.min.js +4 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddressSchema, U256Schema } from '../types';
|
|
1
|
+
import type { AddressSchema, BytesSchema, U256Schema } from '../types';
|
|
2
2
|
import type { Signature } from '../../utils/index.js';
|
|
3
3
|
export interface MetaDataKeyValuePair {
|
|
4
4
|
key: string;
|
|
@@ -28,6 +28,7 @@ export interface MintInfo {
|
|
|
28
28
|
decimals: number;
|
|
29
29
|
is_paused: boolean;
|
|
30
30
|
is_private: boolean;
|
|
31
|
+
clawback_enabled: boolean;
|
|
31
32
|
meta: TokenMetadata;
|
|
32
33
|
}
|
|
33
34
|
export interface KeyValuePair {
|
|
@@ -40,7 +41,8 @@ export declare enum AuthorityType {
|
|
|
40
41
|
Pause = "Pause",
|
|
41
42
|
ManageList = "ManageList",
|
|
42
43
|
UpdateMetadata = "UpdateMetadata",
|
|
43
|
-
Bridge = "Bridge"
|
|
44
|
+
Bridge = "Bridge",
|
|
45
|
+
Clawback = "Clawback"
|
|
44
46
|
}
|
|
45
47
|
export declare enum AuthorityAction {
|
|
46
48
|
Grant = "Grant",
|
|
@@ -67,7 +69,6 @@ export interface TokenManageListPayload {
|
|
|
67
69
|
export interface TokenBurnPayload {
|
|
68
70
|
chain_id: number;
|
|
69
71
|
nonce: number;
|
|
70
|
-
recipient: string;
|
|
71
72
|
value: string;
|
|
72
73
|
token: string;
|
|
73
74
|
signature: RestSignature;
|
|
@@ -90,6 +91,10 @@ export interface TokenIssuePayload {
|
|
|
90
91
|
decimals: number;
|
|
91
92
|
master_authority: string;
|
|
92
93
|
is_private: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
clawback_enabled?: boolean;
|
|
93
98
|
signature: RestSignature;
|
|
94
99
|
}
|
|
95
100
|
export interface TokenMintPayload {
|
|
@@ -128,14 +133,24 @@ export interface TokenBridgeAndMintPayload {
|
|
|
128
133
|
signature: RestSignature;
|
|
129
134
|
}
|
|
130
135
|
export interface TokenBurnAndBridgePayload {
|
|
131
|
-
bridge_metadata: string;
|
|
132
136
|
chain_id: number;
|
|
133
|
-
|
|
137
|
+
nonce: number;
|
|
138
|
+
sender: string;
|
|
139
|
+
value: string;
|
|
140
|
+
token: string;
|
|
134
141
|
destination_chain_id: number;
|
|
142
|
+
destination_address: string;
|
|
135
143
|
escrow_fee: string;
|
|
144
|
+
bridge_metadata: string;
|
|
145
|
+
bridge_param: BytesSchema;
|
|
146
|
+
signature: RestSignature;
|
|
147
|
+
}
|
|
148
|
+
export interface TokenClawbackPayload {
|
|
149
|
+
chain_id: number;
|
|
136
150
|
nonce: number;
|
|
137
|
-
sender: string;
|
|
138
151
|
token: string;
|
|
152
|
+
from: string;
|
|
153
|
+
recipient: string;
|
|
139
154
|
value: string;
|
|
140
155
|
signature: RestSignature;
|
|
141
156
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hash } from '../../api/types';
|
|
2
|
-
import type { EstimateFee, PaymentPayload, Transaction, TransactionReceipt
|
|
2
|
+
import type { EstimateFee, FinalizedTransactionReceipt, PaymentPayload, Transaction, TransactionReceipt } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Transactions API methods
|
|
5
5
|
*/
|
|
@@ -25,11 +25,12 @@ export declare const transactionsApi: {
|
|
|
25
25
|
/**
|
|
26
26
|
* Estimate transaction fee
|
|
27
27
|
* @param from Address of the transaction author
|
|
28
|
+
* @param to Address of the transaction recipient
|
|
28
29
|
* @param value Value of the transaction
|
|
29
|
-
* @param token
|
|
30
|
+
* @param token Token address
|
|
30
31
|
* @returns Promise with fee estimate response
|
|
31
32
|
*/
|
|
32
|
-
estimateFee: (from: string, value: string, token
|
|
33
|
+
estimateFee: (from: string, to: string, value: string, token: string) => import("../../client/index.js").PromiseWrapper<"custom", EstimateFee, EstimateFee, EstimateFee, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | EstimateFee, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<EstimateFee>;
|
|
33
34
|
/**
|
|
34
35
|
* Submit payment transaction
|
|
35
36
|
* @param payload Payment transaction payload
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthorityType, RestSignature } from '../tokens/types';
|
|
2
|
-
import { AddressSchema, B256Schema } from '../types';
|
|
2
|
+
import type { AddressSchema, B256Schema, BytesSchema } from '../types';
|
|
3
3
|
export interface TransactionReceipt {
|
|
4
4
|
success: boolean;
|
|
5
5
|
transaction_hash: B256Schema;
|
|
@@ -71,18 +71,24 @@ export interface TokenBridgeAndMintData {
|
|
|
71
71
|
value: string;
|
|
72
72
|
}
|
|
73
73
|
export interface TokenBurnData {
|
|
74
|
-
recipient: AddressSchema;
|
|
75
74
|
token: AddressSchema;
|
|
76
75
|
value: string;
|
|
77
76
|
}
|
|
78
77
|
export interface TokenBurnAndBridgeData {
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
value: string;
|
|
79
|
+
sender: AddressSchema;
|
|
81
80
|
destination_chain_id: number;
|
|
81
|
+
destination_address: AddressSchema;
|
|
82
82
|
escrow_fee: string;
|
|
83
|
-
|
|
83
|
+
bridge_metadata: string | null;
|
|
84
|
+
bridge_param: BytesSchema;
|
|
84
85
|
token: AddressSchema;
|
|
86
|
+
}
|
|
87
|
+
export interface TokenClawbackData {
|
|
88
|
+
from: AddressSchema;
|
|
89
|
+
recipient: AddressSchema;
|
|
85
90
|
value: string;
|
|
91
|
+
token: AddressSchema;
|
|
86
92
|
}
|
|
87
93
|
export interface TokenCloseAccountData {
|
|
88
94
|
token: AddressSchema;
|
|
@@ -152,6 +158,9 @@ export type Transaction = (BaseTransaction & {
|
|
|
152
158
|
}) | (BaseTransaction & {
|
|
153
159
|
transaction_type: 'TokenBurnAndBridge';
|
|
154
160
|
data: TokenBurnAndBridgeData;
|
|
161
|
+
}) | (BaseTransaction & {
|
|
162
|
+
transaction_type: 'TokenClawback';
|
|
163
|
+
data: TokenClawbackData;
|
|
155
164
|
}) | (BaseTransaction & {
|
|
156
165
|
transaction_type: 'TokenCloseAccount';
|
|
157
166
|
data: TokenCloseAccountData;
|
package/lib/client/core.d.ts
CHANGED
|
@@ -87,22 +87,20 @@ export type ErrorRes = {
|
|
|
87
87
|
};
|
|
88
88
|
export type RestScopeName = ChainName['all'];
|
|
89
89
|
export type RestScope = Readonly<[RestScopeName, RestScopeName?, RestScopeName?, RestScopeName?, RestScopeName?]>;
|
|
90
|
-
type Tuple2Record<T extends readonly any[]> = {
|
|
91
|
-
[Value in T[number]]: Value;
|
|
92
|
-
};
|
|
93
90
|
export interface PromiseWrapper<T, U, TSuc = ChainReturn<T, U>['success'], TFail = ChainReturn<T, U>['failure'], TErr = ChainReturn<T, U>['error'], TLogin = ChainReturn<T, U>['login'], TTime = ChainReturn<T, U>['timeout'], HadCall extends string = ''> {
|
|
94
91
|
success<TRes = TSuc, Delete extends string = HadCall | 'success'>(onSuccess?: (res: ChainReturn<T, U>['success'], headers: AxiosResHeaders) => TRes): Omit<PromiseWrapper<T, U, TRes, TFail, TErr, TLogin, TTime, Delete>, ChainName['withoutS'] extends HadCall ? Delete | 'rest' : Delete> & Promise<TRes | TFail | TErr | TLogin | TTime>;
|
|
95
92
|
failure<TRes = TFail, Delete extends string = HadCall | 'failure'>(onFailure?: (res: ChainReturn<T, U>['failure'], headers: AxiosResHeaders) => TRes): Omit<PromiseWrapper<T, U, TSuc, TRes, TErr, TLogin, TTime, Delete>, ChainName['withoutF'] extends HadCall ? Delete | 'rest' : Delete> & Promise<TSuc | TRes | TErr | TLogin | TTime>;
|
|
96
93
|
error<TRes = TErr, Delete extends string = HadCall | 'error'>(onError?: (err: ChainReturn<T, U>['error'], headers: AxiosReqHeaders | AxiosResHeaders) => TRes): Omit<PromiseWrapper<T, U, TSuc, TFail, TRes, TLogin, TTime, Delete>, ChainName['withoutE'] extends HadCall ? Delete | 'rest' : Delete> & Promise<TSuc | TFail | TRes | TLogin | TTime>;
|
|
97
94
|
login<TRes = TLogin, Delete extends string = HadCall | 'login'>(onLogin?: (res: ChainReturn<T, U>['login'], headers: AxiosResHeaders) => TRes): Omit<PromiseWrapper<T, U, TSuc, TFail, TErr, TRes, TTime, Delete>, ChainName['withoutL'] extends HadCall ? Delete | 'rest' : Delete> & Promise<TSuc | TFail | TErr | TRes | TTime>;
|
|
98
95
|
timeout<TRes = TTime, Delete extends string = HadCall | 'timeout'>(onTimeout?: (err: ChainReturn<T, U>['timeout'], headers: AxiosReqHeaders) => TRes): Omit<PromiseWrapper<T, U, TSuc, TFail, TErr, TLogin, TRes, Delete>, ChainName['withoutT'] extends HadCall ? Delete | 'rest' : Delete> & Promise<TSuc | TFail | TErr | TLogin | TRes>;
|
|
99
|
-
rest<TRes = TSuc | TFail | TErr | TLogin | TTime,
|
|
96
|
+
rest<TRes = TSuc | TFail | TErr | TLogin | TTime, S1 extends Exclude<RestScopeName, HadCall> = Exclude<RestScopeName, HadCall>, S2 extends Exclude<RestScopeName, HadCall | S1> | undefined = undefined, S3 extends Exclude<RestScopeName, HadCall | S1 | Extract<S2, string>> | undefined = undefined, S4 extends Exclude<RestScopeName, HadCall | S1 | Extract<S2, string> | Extract<S3, string>> | undefined = undefined, S5 extends Exclude<RestScopeName, HadCall | S1 | Extract<S2, string> | Extract<S3, string> | Extract<S4, string>> | undefined = undefined, TRestScopeName extends RestScopeName = Extract<S1 | S2 | S3 | S4 | S5, RestScopeName>, THadCallWithNotInScope extends string = HadCall | Exclude<RestScopeName, TRestScopeName>, Delete extends string = HadCall | TRestScopeName | 'rest'>(onRest?: (val: ChainName['all'] extends THadCallWithNotInScope ? unknown : ChainName['withoutS'] extends THadCallWithNotInScope ? ChainReturn<T, U>['success'] : ChainName['withoutF'] extends THadCallWithNotInScope ? ChainReturn<T, U>['failure'] : ChainName['withoutE'] extends THadCallWithNotInScope ? ChainReturn<T, U>['error'] : ChainName['withoutL'] extends THadCallWithNotInScope ? ChainReturn<T, U>['login'] : ChainName['withoutT'] extends THadCallWithNotInScope ? ChainReturn<T, U>['timeout'] : ChainName['withoutSF'] extends THadCallWithNotInScope ? ChainReturn<T, U>['successOrFailure'] : ChainName['withoutSE'] extends THadCallWithNotInScope ? ChainReturn<T, U>['success' | 'error'] : ChainName['withoutSL'] extends THadCallWithNotInScope ? ChainReturn<T, U>['success' | 'login'] : ChainName['withoutST'] extends THadCallWithNotInScope ? ChainReturn<T, U>['success' | 'timeout'] : ChainName['withoutFE'] extends THadCallWithNotInScope ? ChainReturn<T, U>['failure' | 'error'] : ChainName['withoutFL'] extends THadCallWithNotInScope ? ChainReturn<T, U>['failure' | 'login'] : ChainName['withoutFT'] extends THadCallWithNotInScope ? ChainReturn<T, U>['failure' | 'timeout'] : ChainName['withoutEL'] extends THadCallWithNotInScope ? ChainReturn<T, U>['error' | 'login'] : ChainName['withoutET'] extends THadCallWithNotInScope ? ChainReturn<T, U>['error' | 'timeout'] : ChainName['withoutLT'] extends THadCallWithNotInScope ? ChainReturn<T, U>['login' | 'timeout'] : ChainName['withSF'] extends THadCallWithNotInScope ? ChainReturn<T, U>['error' | 'login' | 'timeout'] : ChainName['withSE'] extends THadCallWithNotInScope ? ChainReturn<T, U>['failure' | 'login' | 'timeout'] : ChainName['withSL'] extends THadCallWithNotInScope ? ChainReturn<T, U>['failure' | 'error' | 'timeout'] : ChainName['withST'] extends THadCallWithNotInScope ? ChainReturn<T, U>['failure' | 'error' | 'login'] : ChainName['withFE'] extends THadCallWithNotInScope ? ChainReturn<T, U>['success' | 'login' | 'timeout'] : ChainName['withFL'] extends THadCallWithNotInScope ? ChainReturn<T, U>['success' | 'error' | 'timeout'] : ChainName['withFT'] extends THadCallWithNotInScope ? ChainReturn<T, U>['success' | 'error' | 'login'] : ChainName['withEL'] extends THadCallWithNotInScope ? ChainReturn<T, U>['successOrFailure' | 'timeout'] : ChainName['withET'] extends THadCallWithNotInScope ? ChainReturn<T, U>['successOrFailure' | 'login'] : ChainName['withLT'] extends THadCallWithNotInScope ? ChainReturn<T, U>['successOrFailure' | 'error'] : ChainName['success'] extends THadCallWithNotInScope ? ChainReturn<T, U>['failure' | 'error' | 'login' | 'timeout'] : ChainName['failure'] extends THadCallWithNotInScope ? ChainReturn<T, U>['success' | 'error' | 'login' | 'timeout'] : ChainName['error'] extends THadCallWithNotInScope ? ChainReturn<T, U>['successOrFailure' | 'login' | 'timeout'] : ChainName['login'] extends THadCallWithNotInScope ? ChainReturn<T, U>['successOrFailure' | 'error' | 'timeout'] : ChainName['timeout'] extends THadCallWithNotInScope ? ChainReturn<T, U>['successOrFailure' | 'error' | 'login'] : ChainReturn<T, U>['all'], headers: AxiosReqHeaders | AxiosResHeaders) => TRes, scope?: Readonly<[S1, S2?, S3?, S4?, S5?]>): Omit<PromiseWrapper<T, U, TSuc, TFail, TErr, TLogin, TTime, Delete>, Delete> & Promise<ChainName['all'] extends THadCallWithNotInScope ? TSuc | TFail | TErr | TLogin | TTime : ChainName['withoutS'] extends THadCallWithNotInScope ? TRes | TFail | TErr | TLogin | TTime : ChainName['withoutF'] extends THadCallWithNotInScope ? TSuc | TRes | TErr | TLogin | TTime : ChainName['withoutE'] extends THadCallWithNotInScope ? TSuc | TFail | TRes | TLogin | TTime : ChainName['withoutL'] extends THadCallWithNotInScope ? TSuc | TFail | TErr | TRes | TTime : ChainName['withoutT'] extends THadCallWithNotInScope ? TSuc | TFail | TErr | TLogin | TRes : ChainName['withoutSF'] extends THadCallWithNotInScope ? TRes | TErr | TLogin | TTime : ChainName['withoutSE'] extends THadCallWithNotInScope ? TRes | TFail | TLogin | TTime : ChainName['withoutSL'] extends THadCallWithNotInScope ? TRes | TFail | TErr | TTime : ChainName['withoutST'] extends THadCallWithNotInScope ? TRes | TFail | TErr | TLogin : ChainName['withoutFE'] extends THadCallWithNotInScope ? TSuc | TRes | TLogin | TTime : ChainName['withoutFL'] extends THadCallWithNotInScope ? TSuc | TRes | TErr | TTime : ChainName['withoutFT'] extends THadCallWithNotInScope ? TSuc | TRes | TErr | TLogin : ChainName['withoutEL'] extends THadCallWithNotInScope ? TSuc | TFail | TRes | TTime : ChainName['withoutET'] extends THadCallWithNotInScope ? TSuc | TFail | TRes | TLogin : ChainName['withoutLT'] extends THadCallWithNotInScope ? TSuc | TFail | TErr | TRes : ChainName['withSF'] extends THadCallWithNotInScope ? TSuc | TFail | TRes : ChainName['withSE'] extends THadCallWithNotInScope ? TSuc | TErr | TRes : ChainName['withSL'] extends THadCallWithNotInScope ? TSuc | TLogin | TRes : ChainName['withST'] extends THadCallWithNotInScope ? TSuc | TTime | TRes : ChainName['withFE'] extends THadCallWithNotInScope ? TFail | TErr | TRes : ChainName['withFL'] extends THadCallWithNotInScope ? TFail | TLogin | TRes : ChainName['withFT'] extends THadCallWithNotInScope ? TFail | TTime | TRes : ChainName['withEL'] extends THadCallWithNotInScope ? TErr | TLogin | TRes : ChainName['withET'] extends THadCallWithNotInScope ? TErr | TTime | TRes : ChainName['withLT'] extends THadCallWithNotInScope ? TLogin | TTime | TRes : ChainName['success'] extends THadCallWithNotInScope ? TSuc | TRes : ChainName['failure'] extends THadCallWithNotInScope ? TFail | TRes : ChainName['error'] extends THadCallWithNotInScope ? TErr | TRes : ChainName['login'] extends THadCallWithNotInScope ? TLogin | TRes : ChainName['timeout'] extends THadCallWithNotInScope ? TTime | TRes : TRes>;
|
|
100
97
|
}
|
|
101
98
|
export declare class Request {
|
|
102
99
|
private _config;
|
|
103
100
|
axios: AxiosStatic;
|
|
104
101
|
constructor(config?: InitConfig);
|
|
105
102
|
private parseError;
|
|
103
|
+
private mergeSignals;
|
|
106
104
|
setting(config: InitConfig): void;
|
|
107
105
|
request<T, U = unknown>(options: Options<T, U>): PromiseWrapper<T, U> & Promise<CustomResponseData<T, U, WithFailureData<T>>>;
|
|
108
106
|
}
|
package/lib/client/index.js
CHANGED
|
@@ -122,7 +122,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
122
122
|
_this._restScope = scope || _this._restScope;
|
|
123
123
|
// @ts-ignore
|
|
124
124
|
if (_this._restScope.length === 0) {
|
|
125
|
-
console.warn('[1Money
|
|
125
|
+
console.warn('[1Money SDK]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
128
|
var deletedCounter_1 = 0;
|
|
@@ -137,7 +137,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
if (deletedCounter_1 === _this._restScope.length) {
|
|
140
|
-
console.warn("[1Money
|
|
140
|
+
console.warn("[1Money SDK]: The \"".concat(_this._restScope.join(', '), "\" had been called and the \"rest\" will never be triggered!"));
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
return wrapper;
|
|
@@ -184,9 +184,36 @@ var Request = /** @class */ (function () {
|
|
|
184
184
|
data: data
|
|
185
185
|
};
|
|
186
186
|
};
|
|
187
|
+
Request.prototype.mergeSignals = function () {
|
|
188
|
+
var signals = [];
|
|
189
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
190
|
+
signals[_i] = arguments[_i];
|
|
191
|
+
}
|
|
192
|
+
var controller = new AbortController();
|
|
193
|
+
var onAbort = function () { return controller.abort(); };
|
|
194
|
+
var cleanups = [];
|
|
195
|
+
var _loop_2 = function (signal) {
|
|
196
|
+
if (signal.aborted) {
|
|
197
|
+
controller.abort();
|
|
198
|
+
return "break";
|
|
199
|
+
}
|
|
200
|
+
signal.addEventListener('abort', onAbort);
|
|
201
|
+
cleanups.push(function () { return signal.removeEventListener('abort', onAbort); });
|
|
202
|
+
};
|
|
203
|
+
for (var _a = 0, signals_1 = signals; _a < signals_1.length; _a++) {
|
|
204
|
+
var signal = signals_1[_a];
|
|
205
|
+
var state_1 = _loop_2(signal);
|
|
206
|
+
if (state_1 === "break")
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
signal: controller.signal,
|
|
211
|
+
cleanup: function () { return cleanups.forEach(function (fn) { return fn(); }); },
|
|
212
|
+
};
|
|
213
|
+
};
|
|
187
214
|
Request.prototype.setting = function (config) {
|
|
188
215
|
if (!config)
|
|
189
|
-
return console.warn('[1Money
|
|
216
|
+
return console.warn('[1Money SDK]: setting method required correct parameters!');
|
|
190
217
|
this._config = __assign(__assign({}, this._config), config);
|
|
191
218
|
};
|
|
192
219
|
Request.prototype.request = function (options) {
|
|
@@ -272,12 +299,26 @@ var Request = /** @class */ (function () {
|
|
|
272
299
|
var timer = null;
|
|
273
300
|
var isTimeout = false;
|
|
274
301
|
var _timeout = timeout !== null && timeout !== void 0 ? timeout : initTimeout;
|
|
302
|
+
var controller = new AbortController();
|
|
303
|
+
var signalCleanup = null;
|
|
304
|
+
if (options.signal) {
|
|
305
|
+
var merged = _this.mergeSignals(options.signal, controller.signal);
|
|
306
|
+
options.signal = merged.signal;
|
|
307
|
+
signalCleanup = merged.cleanup;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
options.signal = controller.signal;
|
|
311
|
+
}
|
|
275
312
|
// Cleanup function for timeout
|
|
276
313
|
var cleanup = function () {
|
|
277
314
|
if (timer !== null) {
|
|
278
315
|
clearTimeout(timer);
|
|
279
316
|
timer = null;
|
|
280
317
|
}
|
|
318
|
+
if (signalCleanup) {
|
|
319
|
+
signalCleanup();
|
|
320
|
+
signalCleanup = null;
|
|
321
|
+
}
|
|
281
322
|
};
|
|
282
323
|
if (_timeout) {
|
|
283
324
|
timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -289,6 +330,7 @@ var Request = /** @class */ (function () {
|
|
|
289
330
|
_c.trys.push([0, 2, , 3]);
|
|
290
331
|
isTimeout = true;
|
|
291
332
|
cleanup();
|
|
333
|
+
controller.abort();
|
|
292
334
|
err = this.parseError('timeout');
|
|
293
335
|
return [4 /*yield*/, Promise.resolve(callbacks.timeout(err, (_a = options.headers) !== null && _a !== void 0 ? _a : {}))];
|
|
294
336
|
case 1:
|
|
@@ -363,7 +405,7 @@ var Request = /** @class */ (function () {
|
|
|
363
405
|
return [2 /*return*/];
|
|
364
406
|
cleanup();
|
|
365
407
|
data = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
366
|
-
console.error("[1Money
|
|
408
|
+
console.error("[1Money SDK]: Error(".concat((_c = err.status) !== null && _c !== void 0 ? _c : 500, ", ").concat((_d = err.code) !== null && _d !== void 0 ? _d : 'UNKNOWN', "), Message: ").concat(err.message, ", Config: ").concat((_f = err.config) === null || _f === void 0 ? void 0 : _f.method, ", ").concat((_h = (_g = err.config) === null || _g === void 0 ? void 0 : _g.baseURL) !== null && _h !== void 0 ? _h : '', ", ").concat((_k = (_j = err.config) === null || _j === void 0 ? void 0 : _j.url) !== null && _k !== void 0 ? _k : '', ", ").concat(JSON.stringify((_o = (_l = err.config) === null || _l === void 0 ? void 0 : _l.headers) !== null && _o !== void 0 ? _o : {}), ", Request: ").concat(JSON.stringify((_q = (_p = err.config) === null || _p === void 0 ? void 0 : _p.data) !== null && _q !== void 0 ? _q : {}), ", Response: ").concat(JSON.stringify(data), ";"));
|
|
367
409
|
status = (_s = (_r = err.response) === null || _r === void 0 ? void 0 : _r.status) !== null && _s !== void 0 ? _s : 500;
|
|
368
410
|
headers = (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.headers) !== null && _u !== void 0 ? _u : {};
|
|
369
411
|
_w.label = 1;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { api } from './api/index.js';
|
|
2
2
|
export { api } from './api/index.js';
|
|
3
3
|
export { default as client } from './client/index.js';
|
|
4
|
+
export * from './signing';
|
|
4
5
|
export * from './utils/index.js';
|
|
5
6
|
export type { AxiosStatic } from 'axios';
|
|
6
7
|
export type { InitConfig, Options, ParsedError, PromiseWrapper } from './client/core';
|