axispay-sdk 0.1.1 → 0.1.4

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.
@@ -0,0 +1,23 @@
1
+ declare function createRequestClient(options: {
2
+ baseURL: string;
3
+ token: string;
4
+ }): {
5
+ getAddress: (params: {
6
+ userId: string | number;
7
+ chain: string;
8
+ }) => any;
9
+ checkRecharge: (params: {
10
+ chain: string;
11
+ token: string;
12
+ address: string;
13
+ }) => any;
14
+ withdraw: (params: {
15
+ chain: string;
16
+ token: string;
17
+ address: string;
18
+ amount: number;
19
+ user_id: string | number;
20
+ }) => any;
21
+ };
22
+
23
+ export { createRequestClient as default };
@@ -0,0 +1,23 @@
1
+ declare function createRequestClient(options: {
2
+ baseURL: string;
3
+ token: string;
4
+ }): {
5
+ getAddress: (params: {
6
+ userId: string | number;
7
+ chain: string;
8
+ }) => any;
9
+ checkRecharge: (params: {
10
+ chain: string;
11
+ token: string;
12
+ address: string;
13
+ }) => any;
14
+ withdraw: (params: {
15
+ chain: string;
16
+ token: string;
17
+ address: string;
18
+ amount: number;
19
+ user_id: string | number;
20
+ }) => any;
21
+ };
22
+
23
+ export { createRequestClient as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,694 @@
1
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
2
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
3
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
4
+ function jsonParseTransform(key, value) {
5
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
6
+ warnKeyDropped(key);
7
+ return;
8
+ }
9
+ return value;
10
+ }
11
+ function warnKeyDropped(key) {
12
+ console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
13
+ }
14
+ function destr(value, options = {}) {
15
+ if (typeof value !== "string") {
16
+ return value;
17
+ }
18
+ if (value[0] === '"' && value[value.length - 1] === '"' && value.indexOf("\\") === -1) {
19
+ return value.slice(1, -1);
20
+ }
21
+ const _value = value.trim();
22
+ if (_value.length <= 9) {
23
+ switch (_value.toLowerCase()) {
24
+ case "true": {
25
+ return true;
26
+ }
27
+ case "false": {
28
+ return false;
29
+ }
30
+ case "undefined": {
31
+ return void 0;
32
+ }
33
+ case "null": {
34
+ return null;
35
+ }
36
+ case "nan": {
37
+ return Number.NaN;
38
+ }
39
+ case "infinity": {
40
+ return Number.POSITIVE_INFINITY;
41
+ }
42
+ case "-infinity": {
43
+ return Number.NEGATIVE_INFINITY;
44
+ }
45
+ }
46
+ }
47
+ if (!JsonSigRx.test(value)) {
48
+ if (options.strict) {
49
+ throw new SyntaxError("[destr] Invalid JSON");
50
+ }
51
+ return value;
52
+ }
53
+ try {
54
+ if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
55
+ if (options.strict) {
56
+ throw new Error("[destr] Possible prototype pollution");
57
+ }
58
+ return JSON.parse(value, jsonParseTransform);
59
+ }
60
+ return JSON.parse(value);
61
+ } catch (error) {
62
+ if (options.strict) {
63
+ throw error;
64
+ }
65
+ return value;
66
+ }
67
+ }
68
+
69
+ const HASH_RE = /#/g;
70
+ const AMPERSAND_RE = /&/g;
71
+ const SLASH_RE = /\//g;
72
+ const EQUAL_RE = /=/g;
73
+ const PLUS_RE = /\+/g;
74
+ const ENC_CARET_RE = /%5e/gi;
75
+ const ENC_BACKTICK_RE = /%60/gi;
76
+ const ENC_PIPE_RE = /%7c/gi;
77
+ const ENC_SPACE_RE = /%20/gi;
78
+ function encode(text) {
79
+ return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
80
+ }
81
+ function encodeQueryValue(input) {
82
+ return encode(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
83
+ }
84
+ function encodeQueryKey(text) {
85
+ return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
86
+ }
87
+ function decode(text = "") {
88
+ try {
89
+ return decodeURIComponent("" + text);
90
+ } catch {
91
+ return "" + text;
92
+ }
93
+ }
94
+ function decodeQueryKey(text) {
95
+ return decode(text.replace(PLUS_RE, " "));
96
+ }
97
+ function decodeQueryValue(text) {
98
+ return decode(text.replace(PLUS_RE, " "));
99
+ }
100
+
101
+ function parseQuery(parametersString = "") {
102
+ const object = /* @__PURE__ */ Object.create(null);
103
+ if (parametersString[0] === "?") {
104
+ parametersString = parametersString.slice(1);
105
+ }
106
+ for (const parameter of parametersString.split("&")) {
107
+ const s = parameter.match(/([^=]+)=?(.*)/) || [];
108
+ if (s.length < 2) {
109
+ continue;
110
+ }
111
+ const key = decodeQueryKey(s[1]);
112
+ if (key === "__proto__" || key === "constructor") {
113
+ continue;
114
+ }
115
+ const value = decodeQueryValue(s[2] || "");
116
+ if (object[key] === void 0) {
117
+ object[key] = value;
118
+ } else if (Array.isArray(object[key])) {
119
+ object[key].push(value);
120
+ } else {
121
+ object[key] = [object[key], value];
122
+ }
123
+ }
124
+ return object;
125
+ }
126
+ function encodeQueryItem(key, value) {
127
+ if (typeof value === "number" || typeof value === "boolean") {
128
+ value = String(value);
129
+ }
130
+ if (!value) {
131
+ return encodeQueryKey(key);
132
+ }
133
+ if (Array.isArray(value)) {
134
+ return value.map(
135
+ (_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`
136
+ ).join("&");
137
+ }
138
+ return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
139
+ }
140
+ function stringifyQuery(query) {
141
+ return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
142
+ }
143
+
144
+ const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
145
+ const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
146
+ const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
147
+ const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
148
+ const JOIN_LEADING_SLASH_RE = /^\.?\//;
149
+ function hasProtocol(inputString, opts = {}) {
150
+ if (typeof opts === "boolean") {
151
+ opts = { acceptRelative: opts };
152
+ }
153
+ if (opts.strict) {
154
+ return PROTOCOL_STRICT_REGEX.test(inputString);
155
+ }
156
+ return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
157
+ }
158
+ function hasTrailingSlash(input = "", respectQueryAndFragment) {
159
+ if (!respectQueryAndFragment) {
160
+ return input.endsWith("/");
161
+ }
162
+ return TRAILING_SLASH_RE.test(input);
163
+ }
164
+ function withoutTrailingSlash(input = "", respectQueryAndFragment) {
165
+ if (!respectQueryAndFragment) {
166
+ return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
167
+ }
168
+ if (!hasTrailingSlash(input, true)) {
169
+ return input || "/";
170
+ }
171
+ let path = input;
172
+ let fragment = "";
173
+ const fragmentIndex = input.indexOf("#");
174
+ if (fragmentIndex !== -1) {
175
+ path = input.slice(0, fragmentIndex);
176
+ fragment = input.slice(fragmentIndex);
177
+ }
178
+ const [s0, ...s] = path.split("?");
179
+ const cleanPath = s0.endsWith("/") ? s0.slice(0, -1) : s0;
180
+ return (cleanPath || "/") + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
181
+ }
182
+ function withTrailingSlash(input = "", respectQueryAndFragment) {
183
+ if (!respectQueryAndFragment) {
184
+ return input.endsWith("/") ? input : input + "/";
185
+ }
186
+ if (hasTrailingSlash(input, true)) {
187
+ return input || "/";
188
+ }
189
+ let path = input;
190
+ let fragment = "";
191
+ const fragmentIndex = input.indexOf("#");
192
+ if (fragmentIndex !== -1) {
193
+ path = input.slice(0, fragmentIndex);
194
+ fragment = input.slice(fragmentIndex);
195
+ if (!path) {
196
+ return fragment;
197
+ }
198
+ }
199
+ const [s0, ...s] = path.split("?");
200
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
201
+ }
202
+ function withBase(input, base) {
203
+ if (isEmptyURL(base) || hasProtocol(input)) {
204
+ return input;
205
+ }
206
+ const _base = withoutTrailingSlash(base);
207
+ if (input.startsWith(_base)) {
208
+ const nextChar = input[_base.length];
209
+ if (!nextChar || nextChar === "/" || nextChar === "?") {
210
+ return input;
211
+ }
212
+ }
213
+ return joinURL(_base, input);
214
+ }
215
+ function withQuery(input, query) {
216
+ const parsed = parseURL(input);
217
+ const mergedQuery = { ...parseQuery(parsed.search), ...query };
218
+ parsed.search = stringifyQuery(mergedQuery);
219
+ return stringifyParsedURL(parsed);
220
+ }
221
+ function isEmptyURL(url) {
222
+ return !url || url === "/";
223
+ }
224
+ function isNonEmptyURL(url) {
225
+ return url && url !== "/";
226
+ }
227
+ function joinURL(base, ...input) {
228
+ let url = base || "";
229
+ for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
230
+ if (url) {
231
+ const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
232
+ url = withTrailingSlash(url) + _segment;
233
+ } else {
234
+ url = segment;
235
+ }
236
+ }
237
+ return url;
238
+ }
239
+
240
+ const protocolRelative = Symbol.for("ufo:protocolRelative");
241
+ function parseURL(input = "", defaultProto) {
242
+ const _specialProtoMatch = input.match(
243
+ /^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i
244
+ );
245
+ if (_specialProtoMatch) {
246
+ const [, _proto, _pathname = ""] = _specialProtoMatch;
247
+ return {
248
+ protocol: _proto.toLowerCase(),
249
+ pathname: _pathname,
250
+ href: _proto + _pathname,
251
+ auth: "",
252
+ host: "",
253
+ search: "",
254
+ hash: ""
255
+ };
256
+ }
257
+ if (!hasProtocol(input, { acceptRelative: true })) {
258
+ return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
259
+ }
260
+ const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
261
+ let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
262
+ if (protocol === "file:") {
263
+ path = path.replace(/\/(?=[A-Za-z]:)/, "");
264
+ }
265
+ const { pathname, search, hash } = parsePath(path);
266
+ return {
267
+ protocol: protocol.toLowerCase(),
268
+ auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
269
+ host,
270
+ pathname,
271
+ search,
272
+ hash,
273
+ [protocolRelative]: !protocol
274
+ };
275
+ }
276
+ function parsePath(input = "") {
277
+ const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
278
+ return {
279
+ pathname,
280
+ search,
281
+ hash
282
+ };
283
+ }
284
+ function stringifyParsedURL(parsed) {
285
+ const pathname = parsed.pathname || "";
286
+ const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
287
+ const hash = parsed.hash || "";
288
+ const auth = parsed.auth ? parsed.auth + "@" : "";
289
+ const host = parsed.host || "";
290
+ const proto = parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "";
291
+ return proto + auth + host + pathname + search + hash;
292
+ }
293
+
294
+ class FetchError extends Error {
295
+ constructor(message, opts) {
296
+ super(message, opts);
297
+ this.name = "FetchError";
298
+ if (opts?.cause && !this.cause) {
299
+ this.cause = opts.cause;
300
+ }
301
+ }
302
+ }
303
+ function createFetchError(ctx) {
304
+ const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
305
+ const method = ctx.request?.method || ctx.options?.method || "GET";
306
+ const url = ctx.request?.url || String(ctx.request) || "/";
307
+ const requestStr = `[${method}] ${JSON.stringify(url)}`;
308
+ const statusStr = ctx.response ? `${ctx.response.status} ${ctx.response.statusText}` : "<no response>";
309
+ const message = `${requestStr}: ${statusStr}${errorMessage ? ` ${errorMessage}` : ""}`;
310
+ const fetchError = new FetchError(
311
+ message,
312
+ ctx.error ? { cause: ctx.error } : void 0
313
+ );
314
+ for (const key of ["request", "options", "response"]) {
315
+ Object.defineProperty(fetchError, key, {
316
+ get() {
317
+ return ctx[key];
318
+ }
319
+ });
320
+ }
321
+ for (const [key, refKey] of [
322
+ ["data", "_data"],
323
+ ["status", "status"],
324
+ ["statusCode", "status"],
325
+ ["statusText", "statusText"],
326
+ ["statusMessage", "statusText"]
327
+ ]) {
328
+ Object.defineProperty(fetchError, key, {
329
+ get() {
330
+ return ctx.response && ctx.response[refKey];
331
+ }
332
+ });
333
+ }
334
+ return fetchError;
335
+ }
336
+
337
+ const payloadMethods = new Set(
338
+ Object.freeze(["PATCH", "POST", "PUT", "DELETE"])
339
+ );
340
+ function isPayloadMethod(method = "GET") {
341
+ return payloadMethods.has(method.toUpperCase());
342
+ }
343
+ function isJSONSerializable(value) {
344
+ if (value === void 0) {
345
+ return false;
346
+ }
347
+ const t = typeof value;
348
+ if (t === "string" || t === "number" || t === "boolean" || t === null) {
349
+ return true;
350
+ }
351
+ if (t !== "object") {
352
+ return false;
353
+ }
354
+ if (Array.isArray(value)) {
355
+ return true;
356
+ }
357
+ if (value.buffer) {
358
+ return false;
359
+ }
360
+ if (value instanceof FormData || value instanceof URLSearchParams) {
361
+ return false;
362
+ }
363
+ return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
364
+ }
365
+ const textTypes = /* @__PURE__ */ new Set([
366
+ "image/svg",
367
+ "application/xml",
368
+ "application/xhtml",
369
+ "application/html"
370
+ ]);
371
+ const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
372
+ function detectResponseType(_contentType = "") {
373
+ if (!_contentType) {
374
+ return "json";
375
+ }
376
+ const contentType = _contentType.split(";").shift() || "";
377
+ if (JSON_RE.test(contentType)) {
378
+ return "json";
379
+ }
380
+ if (contentType === "text/event-stream") {
381
+ return "stream";
382
+ }
383
+ if (textTypes.has(contentType) || contentType.startsWith("text/")) {
384
+ return "text";
385
+ }
386
+ return "blob";
387
+ }
388
+ function resolveFetchOptions(request, input, defaults, Headers) {
389
+ const headers = mergeHeaders(
390
+ input?.headers ?? request?.headers,
391
+ defaults?.headers,
392
+ Headers
393
+ );
394
+ let query;
395
+ if (defaults?.query || defaults?.params || input?.params || input?.query) {
396
+ query = {
397
+ ...defaults?.params,
398
+ ...defaults?.query,
399
+ ...input?.params,
400
+ ...input?.query
401
+ };
402
+ }
403
+ return {
404
+ ...defaults,
405
+ ...input,
406
+ query,
407
+ params: query,
408
+ headers
409
+ };
410
+ }
411
+ function mergeHeaders(input, defaults, Headers) {
412
+ if (!defaults) {
413
+ return new Headers(input);
414
+ }
415
+ const headers = new Headers(defaults);
416
+ if (input) {
417
+ for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) {
418
+ headers.set(key, value);
419
+ }
420
+ }
421
+ return headers;
422
+ }
423
+ async function callHooks(context, hooks) {
424
+ if (hooks) {
425
+ if (Array.isArray(hooks)) {
426
+ for (const hook of hooks) {
427
+ await hook(context);
428
+ }
429
+ } else {
430
+ await hooks(context);
431
+ }
432
+ }
433
+ }
434
+
435
+ const retryStatusCodes = /* @__PURE__ */ new Set([
436
+ 408,
437
+ // Request Timeout
438
+ 409,
439
+ // Conflict
440
+ 425,
441
+ // Too Early (Experimental)
442
+ 429,
443
+ // Too Many Requests
444
+ 500,
445
+ // Internal Server Error
446
+ 502,
447
+ // Bad Gateway
448
+ 503,
449
+ // Service Unavailable
450
+ 504
451
+ // Gateway Timeout
452
+ ]);
453
+ const nullBodyResponses = /* @__PURE__ */ new Set([101, 204, 205, 304]);
454
+ function createFetch(globalOptions = {}) {
455
+ const {
456
+ fetch = globalThis.fetch,
457
+ Headers = globalThis.Headers,
458
+ AbortController = globalThis.AbortController
459
+ } = globalOptions;
460
+ async function onError(context) {
461
+ const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
462
+ if (context.options.retry !== false && !isAbort) {
463
+ let retries;
464
+ if (typeof context.options.retry === "number") {
465
+ retries = context.options.retry;
466
+ } else {
467
+ retries = isPayloadMethod(context.options.method) ? 0 : 1;
468
+ }
469
+ const responseCode = context.response && context.response.status || 500;
470
+ if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
471
+ const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
472
+ if (retryDelay > 0) {
473
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
474
+ }
475
+ return $fetchRaw(context.request, {
476
+ ...context.options,
477
+ retry: retries - 1
478
+ });
479
+ }
480
+ }
481
+ const error = createFetchError(context);
482
+ if (Error.captureStackTrace) {
483
+ Error.captureStackTrace(error, $fetchRaw);
484
+ }
485
+ throw error;
486
+ }
487
+ const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
488
+ const context = {
489
+ request: _request,
490
+ options: resolveFetchOptions(
491
+ _request,
492
+ _options,
493
+ globalOptions.defaults,
494
+ Headers
495
+ ),
496
+ response: void 0,
497
+ error: void 0
498
+ };
499
+ if (context.options.method) {
500
+ context.options.method = context.options.method.toUpperCase();
501
+ }
502
+ if (context.options.onRequest) {
503
+ await callHooks(context, context.options.onRequest);
504
+ if (!(context.options.headers instanceof Headers)) {
505
+ context.options.headers = new Headers(
506
+ context.options.headers || {}
507
+ /* compat */
508
+ );
509
+ }
510
+ }
511
+ if (typeof context.request === "string") {
512
+ if (context.options.baseURL) {
513
+ context.request = withBase(context.request, context.options.baseURL);
514
+ }
515
+ if (context.options.query) {
516
+ context.request = withQuery(context.request, context.options.query);
517
+ delete context.options.query;
518
+ }
519
+ if ("query" in context.options) {
520
+ delete context.options.query;
521
+ }
522
+ if ("params" in context.options) {
523
+ delete context.options.params;
524
+ }
525
+ }
526
+ if (context.options.body && isPayloadMethod(context.options.method)) {
527
+ if (isJSONSerializable(context.options.body)) {
528
+ const contentType = context.options.headers.get("content-type");
529
+ if (typeof context.options.body !== "string") {
530
+ context.options.body = contentType === "application/x-www-form-urlencoded" ? new URLSearchParams(
531
+ context.options.body
532
+ ).toString() : JSON.stringify(context.options.body);
533
+ }
534
+ if (!contentType) {
535
+ context.options.headers.set("content-type", "application/json");
536
+ }
537
+ if (!context.options.headers.has("accept")) {
538
+ context.options.headers.set("accept", "application/json");
539
+ }
540
+ } else if (
541
+ // ReadableStream Body
542
+ "pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || // Node.js Stream Body
543
+ typeof context.options.body.pipe === "function"
544
+ ) {
545
+ if (!("duplex" in context.options)) {
546
+ context.options.duplex = "half";
547
+ }
548
+ }
549
+ }
550
+ let abortTimeout;
551
+ if (!context.options.signal && context.options.timeout) {
552
+ const controller = new AbortController();
553
+ abortTimeout = setTimeout(() => {
554
+ const error = new Error(
555
+ "[TimeoutError]: The operation was aborted due to timeout"
556
+ );
557
+ error.name = "TimeoutError";
558
+ error.code = 23;
559
+ controller.abort(error);
560
+ }, context.options.timeout);
561
+ context.options.signal = controller.signal;
562
+ }
563
+ try {
564
+ context.response = await fetch(
565
+ context.request,
566
+ context.options
567
+ );
568
+ } catch (error) {
569
+ context.error = error;
570
+ if (context.options.onRequestError) {
571
+ await callHooks(
572
+ context,
573
+ context.options.onRequestError
574
+ );
575
+ }
576
+ return await onError(context);
577
+ } finally {
578
+ if (abortTimeout) {
579
+ clearTimeout(abortTimeout);
580
+ }
581
+ }
582
+ const hasBody = (context.response.body || // https://github.com/unjs/ofetch/issues/324
583
+ // https://github.com/unjs/ofetch/issues/294
584
+ // https://github.com/JakeChampion/fetch/issues/1454
585
+ context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD";
586
+ if (hasBody) {
587
+ const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
588
+ switch (responseType) {
589
+ case "json": {
590
+ const data = await context.response.text();
591
+ const parseFunction = context.options.parseResponse || destr;
592
+ context.response._data = parseFunction(data);
593
+ break;
594
+ }
595
+ case "stream": {
596
+ context.response._data = context.response.body || context.response._bodyInit;
597
+ break;
598
+ }
599
+ default: {
600
+ context.response._data = await context.response[responseType]();
601
+ }
602
+ }
603
+ }
604
+ if (context.options.onResponse) {
605
+ await callHooks(
606
+ context,
607
+ context.options.onResponse
608
+ );
609
+ }
610
+ if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
611
+ if (context.options.onResponseError) {
612
+ await callHooks(
613
+ context,
614
+ context.options.onResponseError
615
+ );
616
+ }
617
+ return await onError(context);
618
+ }
619
+ return context.response;
620
+ };
621
+ const $fetch = async function $fetch2(request, options) {
622
+ const r = await $fetchRaw(request, options);
623
+ return r._data;
624
+ };
625
+ $fetch.raw = $fetchRaw;
626
+ $fetch.native = (...args) => fetch(...args);
627
+ $fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
628
+ ...globalOptions,
629
+ ...customGlobalOptions,
630
+ defaults: {
631
+ ...globalOptions.defaults,
632
+ ...customGlobalOptions.defaults,
633
+ ...defaultOptions
634
+ }
635
+ });
636
+ return $fetch;
637
+ }
638
+
639
+ const _globalThis = (function() {
640
+ if (typeof globalThis !== "undefined") {
641
+ return globalThis;
642
+ }
643
+ if (typeof self !== "undefined") {
644
+ return self;
645
+ }
646
+ if (typeof window !== "undefined") {
647
+ return window;
648
+ }
649
+ if (typeof global !== "undefined") {
650
+ return global;
651
+ }
652
+ throw new Error("unable to locate global object");
653
+ })();
654
+ const fetch = _globalThis.fetch ? (...args) => _globalThis.fetch(...args) : () => Promise.reject(new Error("[ofetch] global.fetch is not supported!"));
655
+ const Headers = _globalThis.Headers;
656
+ const AbortController = _globalThis.AbortController;
657
+ const ofetch = createFetch({ fetch, Headers, AbortController });
658
+
659
+ function createRequestClient(options) {
660
+ let req = ofetch.create({
661
+ baseURL: options.baseURL,
662
+ headers: {
663
+ token: options.token
664
+ },
665
+ async onResponse({ response }) {
666
+ if (response.status != 200) {
667
+ throw response._data;
668
+ }
669
+ return response._data;
670
+ }
671
+ });
672
+ return {
673
+ getAddress: (params) => {
674
+ return req("/api/platform/wallet/address", {
675
+ method: "GET",
676
+ query: params
677
+ });
678
+ },
679
+ checkRecharge: (params) => {
680
+ return req("/api/platform/wallet/checkRecharge", {
681
+ method: "GET",
682
+ query: params
683
+ });
684
+ },
685
+ withdraw: (params) => {
686
+ return req("/api/platform/wallet/withdraw", {
687
+ method: "POST",
688
+ body: params
689
+ });
690
+ }
691
+ };
692
+ }
693
+
694
+ export { createRequestClient as default };
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
- "name": "axispay-sdk",
3
- "version": "0.1.1",
2
+ "name": "axispay-sdk",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
- "main":"./src/index.ts",
5
+ "main": "./dist/index.ts",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./src/index.d.ts",
9
9
  "import": "./src/index.ts"
10
10
  }
11
11
  },
12
- "files": ["src"],
12
+ "files": [
13
+ "src",
14
+ "dist"
15
+ ],
13
16
  "scripts": {
14
- "build": "unbuild"
17
+ "build": "unbuild",
18
+ "publish": "npm version patch && sudo npm publish"
15
19
  },
16
20
  "devDependencies": {
17
21
  "ofetch": "^1.5.1"