@1money/protocol-ts-sdk 2.0.0 → 2.0.2

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.
@@ -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, TRestScope extends RestScope = ['success', 'failure', 'login', 'error', 'timeout'], TRestScopeName extends RestScopeName = Exclude<keyof Tuple2Record<TRestScope>, undefined>, 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?: TRestScope): 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>;
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
  }
@@ -184,6 +184,33 @@ 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
216
  return console.warn('[1Money SDK]: setting method required correct parameters!');
@@ -196,7 +223,6 @@ var Request = /** @class */ (function () {
196
223
  options.headers = __assign(__assign(__assign({}, this.axios.defaults.headers.common), (options.method ? this.axios.defaults.headers[options.method] : {})), options.headers);
197
224
  options.headers['Accept'] = options.headers['Accept'] || '*/*';
198
225
  options.headers['X-Requested-With'] = options.headers['X-Requested-With'] || 'XMLHttpRequest';
199
- options.headers['X-Content-Type-Options'] = options.headers['X-Content-Type-Options'] || 'nosniff';
200
226
  var _a = this._config, initOnSuccess = _a.onSuccess, initOnFailure = _a.onFailure, initOnLogin = _a.onLogin, initOnError = _a.onError, initOnTimeout = _a.onTimeout, initIsSuccess = _a.isSuccess, initIsLogin = _a.isLogin, initTimeout = _a.timeout;
201
227
  var onSuccess = options.onSuccess, onFailure = options.onFailure, onLogin = options.onLogin, onError = options.onError, onTimeout = options.onTimeout, isSuccess = options.isSuccess, isLogin = options.isLogin, timeout = options.timeout;
202
228
  var rules = {
@@ -272,12 +298,26 @@ var Request = /** @class */ (function () {
272
298
  var timer = null;
273
299
  var isTimeout = false;
274
300
  var _timeout = timeout !== null && timeout !== void 0 ? timeout : initTimeout;
301
+ var controller = new AbortController();
302
+ var signalCleanup = null;
303
+ if (options.signal) {
304
+ var merged = _this.mergeSignals(options.signal, controller.signal);
305
+ options.signal = merged.signal;
306
+ signalCleanup = merged.cleanup;
307
+ }
308
+ else {
309
+ options.signal = controller.signal;
310
+ }
275
311
  // Cleanup function for timeout
276
312
  var cleanup = function () {
277
313
  if (timer !== null) {
278
314
  clearTimeout(timer);
279
315
  timer = null;
280
316
  }
317
+ if (signalCleanup) {
318
+ signalCleanup();
319
+ signalCleanup = null;
320
+ }
281
321
  };
282
322
  if (_timeout) {
283
323
  timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -289,6 +329,7 @@ var Request = /** @class */ (function () {
289
329
  _c.trys.push([0, 2, , 3]);
290
330
  isTimeout = true;
291
331
  cleanup();
332
+ controller.abort();
292
333
  err = this.parseError('timeout');
293
334
  return [4 /*yield*/, Promise.resolve(callbacks.timeout(err, (_a = options.headers) !== null && _a !== void 0 ? _a : {}))];
294
335
  case 1:
@@ -355,34 +396,34 @@ var Request = /** @class */ (function () {
355
396
  });
356
397
  }); }).catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
357
398
  var data, status, headers, res, doLogin, e_3;
358
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _o, _p, _q, _r, _s, _t, _u, _v;
359
- return __generator(this, function (_w) {
360
- switch (_w.label) {
399
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _o, _p, _q, _r;
400
+ return __generator(this, function (_s) {
401
+ switch (_s.label) {
361
402
  case 0:
362
403
  if (isTimeout)
363
404
  return [2 /*return*/];
364
405
  cleanup();
365
406
  data = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
366
- 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
- status = (_s = (_r = err.response) === null || _r === void 0 ? void 0 : _r.status) !== null && _s !== void 0 ? _s : 500;
368
- headers = (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.headers) !== null && _u !== void 0 ? _u : {};
369
- _w.label = 1;
407
+ 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 : '', ";"));
408
+ status = (_o = (_l = err.response) === null || _l === void 0 ? void 0 : _l.status) !== null && _o !== void 0 ? _o : 500;
409
+ headers = (_q = (_p = err.response) === null || _p === void 0 ? void 0 : _p.headers) !== null && _q !== void 0 ? _q : {};
410
+ _s.label = 1;
370
411
  case 1:
371
- _w.trys.push([1, 5, , 6]);
412
+ _s.trys.push([1, 5, , 6]);
372
413
  res = data;
373
- doLogin = (_v = rules.login) === null || _v === void 0 ? void 0 : _v.call(rules, data, status, headers);
414
+ doLogin = (_r = rules.login) === null || _r === void 0 ? void 0 : _r.call(rules, data, status, headers);
374
415
  if (!doLogin) return [3 /*break*/, 3];
375
416
  return [4 /*yield*/, Promise.resolve(callbacks.login(res, headers))];
376
417
  case 2:
377
- res = _w.sent();
418
+ res = _s.sent();
378
419
  ResPromise._resolve(res);
379
420
  return [3 /*break*/, 4];
380
421
  case 3:
381
422
  errorHandler(err, headers);
382
- _w.label = 4;
423
+ _s.label = 4;
383
424
  case 4: return [3 /*break*/, 6];
384
425
  case 5:
385
- e_3 = _w.sent();
426
+ e_3 = _s.sent();
386
427
  errorHandler(e_3, headers);
387
428
  return [3 /*break*/, 6];
388
429
  case 6: return [2 /*return*/];
package/lib/index.js CHANGED
@@ -1008,8 +1008,7 @@ function toHex(value) {
1008
1008
  }
1009
1009
  }
1010
1010
  catch (e) {
1011
- console.error('[1Money SDK]: toHex error:', e);
1012
- return '0x';
1011
+ throw new Error("[1Money SDK]: toHex conversion failed: ".concat(e instanceof Error ? e.message : String(e)));
1013
1012
  }
1014
1013
  }function encodeRlpListHeader(length) {
1015
1014
  if (length < 56) {
@@ -1146,6 +1145,33 @@ var Request = /** @class */ (function () {
1146
1145
  data: data
1147
1146
  };
1148
1147
  };
1148
+ Request.prototype.mergeSignals = function () {
1149
+ var signals = [];
1150
+ for (var _i = 0; _i < arguments.length; _i++) {
1151
+ signals[_i] = arguments[_i];
1152
+ }
1153
+ var controller = new AbortController();
1154
+ var onAbort = function () { return controller.abort(); };
1155
+ var cleanups = [];
1156
+ var _loop_2 = function (signal) {
1157
+ if (signal.aborted) {
1158
+ controller.abort();
1159
+ return "break";
1160
+ }
1161
+ signal.addEventListener('abort', onAbort);
1162
+ cleanups.push(function () { return signal.removeEventListener('abort', onAbort); });
1163
+ };
1164
+ for (var _a = 0, signals_1 = signals; _a < signals_1.length; _a++) {
1165
+ var signal = signals_1[_a];
1166
+ var state_1 = _loop_2(signal);
1167
+ if (state_1 === "break")
1168
+ break;
1169
+ }
1170
+ return {
1171
+ signal: controller.signal,
1172
+ cleanup: function () { return cleanups.forEach(function (fn) { return fn(); }); },
1173
+ };
1174
+ };
1149
1175
  Request.prototype.setting = function (config) {
1150
1176
  if (!config)
1151
1177
  return console.warn('[1Money SDK]: setting method required correct parameters!');
@@ -1158,7 +1184,6 @@ var Request = /** @class */ (function () {
1158
1184
  options.headers = __assign(__assign(__assign({}, this.axios.defaults.headers.common), (options.method ? this.axios.defaults.headers[options.method] : {})), options.headers);
1159
1185
  options.headers['Accept'] = options.headers['Accept'] || '*/*';
1160
1186
  options.headers['X-Requested-With'] = options.headers['X-Requested-With'] || 'XMLHttpRequest';
1161
- options.headers['X-Content-Type-Options'] = options.headers['X-Content-Type-Options'] || 'nosniff';
1162
1187
  var _a = this._config, initOnSuccess = _a.onSuccess, initOnFailure = _a.onFailure, initOnLogin = _a.onLogin, initOnError = _a.onError, initOnTimeout = _a.onTimeout, initIsSuccess = _a.isSuccess, initIsLogin = _a.isLogin, initTimeout = _a.timeout;
1163
1188
  var onSuccess = options.onSuccess, onFailure = options.onFailure, onLogin = options.onLogin, onError = options.onError, onTimeout = options.onTimeout, isSuccess = options.isSuccess, isLogin = options.isLogin, timeout = options.timeout;
1164
1189
  var rules = {
@@ -1234,12 +1259,26 @@ var Request = /** @class */ (function () {
1234
1259
  var timer = null;
1235
1260
  var isTimeout = false;
1236
1261
  var _timeout = timeout !== null && timeout !== void 0 ? timeout : initTimeout;
1262
+ var controller = new AbortController();
1263
+ var signalCleanup = null;
1264
+ if (options.signal) {
1265
+ var merged = _this.mergeSignals(options.signal, controller.signal);
1266
+ options.signal = merged.signal;
1267
+ signalCleanup = merged.cleanup;
1268
+ }
1269
+ else {
1270
+ options.signal = controller.signal;
1271
+ }
1237
1272
  // Cleanup function for timeout
1238
1273
  var cleanup = function () {
1239
1274
  if (timer !== null) {
1240
1275
  clearTimeout(timer);
1241
1276
  timer = null;
1242
1277
  }
1278
+ if (signalCleanup) {
1279
+ signalCleanup();
1280
+ signalCleanup = null;
1281
+ }
1243
1282
  };
1244
1283
  if (_timeout) {
1245
1284
  timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -1251,6 +1290,7 @@ var Request = /** @class */ (function () {
1251
1290
  _c.trys.push([0, 2, , 3]);
1252
1291
  isTimeout = true;
1253
1292
  cleanup();
1293
+ controller.abort();
1254
1294
  err = this.parseError('timeout');
1255
1295
  return [4 /*yield*/, Promise.resolve(callbacks.timeout(err, (_a = options.headers) !== null && _a !== void 0 ? _a : {}))];
1256
1296
  case 1:
@@ -1317,34 +1357,34 @@ var Request = /** @class */ (function () {
1317
1357
  });
1318
1358
  }); }).catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
1319
1359
  var data, status, headers, res, doLogin, e_3;
1320
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _o, _p, _q, _r, _s, _t, _u, _v;
1321
- return __generator(this, function (_w) {
1322
- switch (_w.label) {
1360
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _o, _p, _q, _r;
1361
+ return __generator(this, function (_s) {
1362
+ switch (_s.label) {
1323
1363
  case 0:
1324
1364
  if (isTimeout)
1325
1365
  return [2 /*return*/];
1326
1366
  cleanup();
1327
1367
  data = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
1328
- 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), ";"));
1329
- status = (_s = (_r = err.response) === null || _r === void 0 ? void 0 : _r.status) !== null && _s !== void 0 ? _s : 500;
1330
- headers = (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.headers) !== null && _u !== void 0 ? _u : {};
1331
- _w.label = 1;
1368
+ 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 : '', ";"));
1369
+ status = (_o = (_l = err.response) === null || _l === void 0 ? void 0 : _l.status) !== null && _o !== void 0 ? _o : 500;
1370
+ headers = (_q = (_p = err.response) === null || _p === void 0 ? void 0 : _p.headers) !== null && _q !== void 0 ? _q : {};
1371
+ _s.label = 1;
1332
1372
  case 1:
1333
- _w.trys.push([1, 5, , 6]);
1373
+ _s.trys.push([1, 5, , 6]);
1334
1374
  res = data;
1335
- doLogin = (_v = rules.login) === null || _v === void 0 ? void 0 : _v.call(rules, data, status, headers);
1375
+ doLogin = (_r = rules.login) === null || _r === void 0 ? void 0 : _r.call(rules, data, status, headers);
1336
1376
  if (!doLogin) return [3 /*break*/, 3];
1337
1377
  return [4 /*yield*/, Promise.resolve(callbacks.login(res, headers))];
1338
1378
  case 2:
1339
- res = _w.sent();
1379
+ res = _s.sent();
1340
1380
  ResPromise._resolve(res);
1341
1381
  return [3 /*break*/, 4];
1342
1382
  case 3:
1343
1383
  errorHandler(err, headers);
1344
- _w.label = 4;
1384
+ _s.label = 4;
1345
1385
  case 4: return [3 /*break*/, 6];
1346
1386
  case 5:
1347
- e_3 = _w.sent();
1387
+ e_3 = _s.sent();
1348
1388
  errorHandler(e_3, headers);
1349
1389
  return [3 /*break*/, 6];
1350
1390
  case 6: return [2 /*return*/];
@@ -985,8 +985,7 @@ function toHex(value) {
985
985
  }
986
986
  }
987
987
  catch (e) {
988
- console.error('[1Money SDK]: toHex error:', e);
989
- return '0x';
988
+ throw new Error("[1Money SDK]: toHex conversion failed: ".concat(e instanceof Error ? e.message : String(e)));
990
989
  }
991
990
  }function encodeRlpListHeader(length) {
992
991
  if (length < 56) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1money/protocol-ts-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "ts sdk for 1Money protocol network",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -37,11 +37,11 @@
37
37
  "test:all": "npm run test && npm run test:integration",
38
38
  "lint": "npm run lint:prettier && npm run lint:es",
39
39
  "lint:fix": "npm run lint:prettier_fix && npm run lint:es_fix",
40
- "lint:es": "eslint src/ --ext .ts --ext .tsx",
41
- "lint:es_fix": "eslint src/ --ext .ts --ext .tsx --fix",
40
+ "lint:es": "eslint src/",
41
+ "lint:es_fix": "eslint src/ --fix",
42
42
  "lint:prettier": "prettier --check src/",
43
43
  "lint:prettier_fix": "prettier --write src/",
44
- "lint:commit": "commitlint -e $HUSKY_GIT_PARAMS",
44
+ "lint:commit": "commitlint --edit",
45
45
  "new": "omni new",
46
46
  "build": "omni build",
47
47
  "build:remote": "cross-env RUN_ENV=remote omni build",
@@ -72,7 +72,8 @@
72
72
  "@babel/preset-env": "~7.26.9",
73
73
  "@babel/preset-typescript": "~7.26.0",
74
74
  "@babel/runtime-corejs3": "~7.26.10",
75
- "@commitlint/cli": "8.3.5",
75
+ "@commitlint/cli": "~20.5.0",
76
+ "@commitlint/config-conventional": "~20.5.0",
76
77
  "@ethereumjs/rlp": "^10.0.0",
77
78
  "@noble/secp256k1": "2.3.0",
78
79
  "@omni-door/cli": "~3.2.2",
@@ -81,31 +82,31 @@
81
82
  "@rollup/plugin-commonjs": "~28.0.3",
82
83
  "@rollup/plugin-json": "~6.1.0",
83
84
  "@rollup/plugin-node-resolve": "~16.0.1",
84
- "@rollup/plugin-terser": "^0.4.4",
85
+ "@rollup/plugin-terser": "^1.0.0",
85
86
  "@rollup/plugin-typescript": "^12.1.2",
86
87
  "@types/chai": "4.3.17",
87
88
  "@types/mocha": "10.0.7",
88
89
  "@types/node": "~18.19.39",
89
- "@typescript-eslint/eslint-plugin": "~8.30.0",
90
- "@typescript-eslint/parser": "~8.30.0",
90
+ "typescript-eslint": "~8.57.1",
91
91
  "axios": "~1.12.0",
92
92
  "chai": "4.5.0",
93
93
  "cross-env": "^7.0.3",
94
94
  "del": "5.1.0",
95
95
  "detect-port": "1.3.0",
96
96
  "dotenv": "^16.5.0",
97
- "eslint": "~8.57.1",
98
- "eslint-config-prettier": "~10.0.1",
99
- "eslint-plugin-prettier": "~5.2.3",
97
+ "@eslint/js": "~9.23.0",
98
+ "eslint": "~9.23.0",
99
+ "eslint-config-prettier": "~10.1.8",
100
+ "eslint-plugin-prettier": "~5.5.5",
100
101
  "husky": "9.1.7",
101
102
  "ip": "1.1.5",
102
103
  "lint-staged": "15.4.3",
103
- "mocha": "10.7.0",
104
+ "mocha": "11.7.5",
104
105
  "nyc": "17.0.0",
105
106
  "prettier": "~3.5.0",
106
107
  "prettier-eslint": "^16.3.0",
107
- "puppeteer": "^24.9.0",
108
- "rollup": "~4.40.0",
108
+ "puppeteer": "^24.40.0",
109
+ "rollup": "~4.60.0",
109
110
  "rollup-plugin-polyfill-node": "^0.13.0",
110
111
  "ts-loader": "9.5.1",
111
112
  "ts-patch": "~3.2.1",
@@ -116,5 +117,15 @@
116
117
  "typescript": "~5.8.3",
117
118
  "typescript-transform-paths": "~3.5.5",
118
119
  "viem": "^2.30.0"
120
+ },
121
+ "pnpm": {
122
+ "overrides": {
123
+ "minimatch@<3.1.4": "3.1.4",
124
+ "minimatch@>=5.0.0 <5.1.8": "5.1.8",
125
+ "minimatch@>=9.0.0 <9.0.7": "9.0.7",
126
+ "flatted@<=3.4.1": "3.4.2",
127
+ "serialize-javascript@<=7.0.2": "7.0.4",
128
+ "basic-ftp@<5.2.0": "5.2.0"
129
+ }
119
130
  }
120
131
  }