@ripwords/myinvois-client 0.0.1 → 0.0.3
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/cjs/index.cjs +549 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/multipart-parser-Bu3ikqFQ.cjs +182 -0
- package/dist/cjs/multipart-parser-Bu3ikqFQ.cjs.map +1 -0
- package/dist/cjs/node-qs2pnN6F.cjs +4124 -0
- package/dist/cjs/node-qs2pnN6F.cjs.map +1 -0
- package/package.json +1 -1
- package/rolldown.config.ts +18 -6
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_node = require('./node-qs2pnN6F.cjs');
|
|
3
|
+
const node_http = require_node.__toESM(require("node:http"));
|
|
4
|
+
const node_https = require_node.__toESM(require("node:https"));
|
|
5
|
+
const node_zlib = require_node.__toESM(require("node:zlib"));
|
|
6
|
+
const node_stream = require_node.__toESM(require("node:stream"));
|
|
7
|
+
const node_buffer = require_node.__toESM(require("node:buffer"));
|
|
8
|
+
const node_util = require_node.__toESM(require("node:util"));
|
|
9
|
+
const node_url = require_node.__toESM(require("node:url"));
|
|
10
|
+
const node_net = require_node.__toESM(require("node:net"));
|
|
11
|
+
const node_fs = require_node.__toESM(require("node:fs"));
|
|
12
|
+
const node_path = require_node.__toESM(require("node:path"));
|
|
13
|
+
|
|
14
|
+
//#region node_modules/node-fetch-native/dist/index.mjs
|
|
15
|
+
const o = !!globalThis.process?.env?.FORCE_NODE_FETCH, r$1 = !o && globalThis.fetch || require_node.ei, p = !o && globalThis.Blob || require_node.Ze, F = !o && globalThis.File || require_node.Yr, h = !o && globalThis.FormData || require_node.Zt, n = !o && globalThis.Headers || require_node.ae, c = !o && globalThis.Request || require_node.Xe, R = !o && globalThis.Response || require_node.H, T = !o && globalThis.AbortController || require_node.nn;
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region node_modules/destr/dist/index.mjs
|
|
19
|
+
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*:/;
|
|
20
|
+
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*:/;
|
|
21
|
+
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
22
|
+
function jsonParseTransform(key, value) {
|
|
23
|
+
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
24
|
+
warnKeyDropped(key);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function warnKeyDropped(key) {
|
|
30
|
+
console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
|
|
31
|
+
}
|
|
32
|
+
function destr(value, options = {}) {
|
|
33
|
+
if (typeof value !== "string") return value;
|
|
34
|
+
if (value[0] === "\"" && value[value.length - 1] === "\"" && value.indexOf("\\") === -1) return value.slice(1, -1);
|
|
35
|
+
const _value = value.trim();
|
|
36
|
+
if (_value.length <= 9) switch (_value.toLowerCase()) {
|
|
37
|
+
case "true": return true;
|
|
38
|
+
case "false": return false;
|
|
39
|
+
case "undefined": return void 0;
|
|
40
|
+
case "null": return null;
|
|
41
|
+
case "nan": return Number.NaN;
|
|
42
|
+
case "infinity": return Number.POSITIVE_INFINITY;
|
|
43
|
+
case "-infinity": return Number.NEGATIVE_INFINITY;
|
|
44
|
+
}
|
|
45
|
+
if (!JsonSigRx.test(value)) {
|
|
46
|
+
if (options.strict) throw new SyntaxError("[destr] Invalid JSON");
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
|
|
51
|
+
if (options.strict) throw new Error("[destr] Possible prototype pollution");
|
|
52
|
+
return JSON.parse(value, jsonParseTransform);
|
|
53
|
+
}
|
|
54
|
+
return JSON.parse(value);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (options.strict) throw error;
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region node_modules/ufo/dist/index.mjs
|
|
63
|
+
const r = String.fromCharCode;
|
|
64
|
+
const HASH_RE = /#/g;
|
|
65
|
+
const AMPERSAND_RE = /&/g;
|
|
66
|
+
const SLASH_RE = /\//g;
|
|
67
|
+
const EQUAL_RE = /=/g;
|
|
68
|
+
const PLUS_RE = /\+/g;
|
|
69
|
+
const ENC_CARET_RE = /%5e/gi;
|
|
70
|
+
const ENC_BACKTICK_RE = /%60/gi;
|
|
71
|
+
const ENC_PIPE_RE = /%7c/gi;
|
|
72
|
+
const ENC_SPACE_RE = /%20/gi;
|
|
73
|
+
function encode(text) {
|
|
74
|
+
return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
|
|
75
|
+
}
|
|
76
|
+
function encodeQueryValue(input) {
|
|
77
|
+
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");
|
|
78
|
+
}
|
|
79
|
+
function encodeQueryKey(text) {
|
|
80
|
+
return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
|
|
81
|
+
}
|
|
82
|
+
function decode(text = "") {
|
|
83
|
+
try {
|
|
84
|
+
return decodeURIComponent("" + text);
|
|
85
|
+
} catch {
|
|
86
|
+
return "" + text;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function decodeQueryKey(text) {
|
|
90
|
+
return decode(text.replace(PLUS_RE, " "));
|
|
91
|
+
}
|
|
92
|
+
function decodeQueryValue(text) {
|
|
93
|
+
return decode(text.replace(PLUS_RE, " "));
|
|
94
|
+
}
|
|
95
|
+
function parseQuery(parametersString = "") {
|
|
96
|
+
const object = /* @__PURE__ */ Object.create(null);
|
|
97
|
+
if (parametersString[0] === "?") parametersString = parametersString.slice(1);
|
|
98
|
+
for (const parameter of parametersString.split("&")) {
|
|
99
|
+
const s = parameter.match(/([^=]+)=?(.*)/) || [];
|
|
100
|
+
if (s.length < 2) continue;
|
|
101
|
+
const key = decodeQueryKey(s[1]);
|
|
102
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
103
|
+
const value = decodeQueryValue(s[2] || "");
|
|
104
|
+
if (object[key] === void 0) object[key] = value;
|
|
105
|
+
else if (Array.isArray(object[key])) object[key].push(value);
|
|
106
|
+
else object[key] = [object[key], value];
|
|
107
|
+
}
|
|
108
|
+
return object;
|
|
109
|
+
}
|
|
110
|
+
function encodeQueryItem(key, value) {
|
|
111
|
+
if (typeof value === "number" || typeof value === "boolean") value = String(value);
|
|
112
|
+
if (!value) return encodeQueryKey(key);
|
|
113
|
+
if (Array.isArray(value)) return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
|
|
114
|
+
return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
|
|
115
|
+
}
|
|
116
|
+
function stringifyQuery(query) {
|
|
117
|
+
return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
|
|
118
|
+
}
|
|
119
|
+
const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
|
|
120
|
+
const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
|
|
121
|
+
const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
|
|
122
|
+
const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
|
|
123
|
+
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
124
|
+
function hasProtocol(inputString, opts = {}) {
|
|
125
|
+
if (typeof opts === "boolean") opts = { acceptRelative: opts };
|
|
126
|
+
if (opts.strict) return PROTOCOL_STRICT_REGEX.test(inputString);
|
|
127
|
+
return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
|
|
128
|
+
}
|
|
129
|
+
function hasTrailingSlash(input = "", respectQueryAndFragment) {
|
|
130
|
+
if (!respectQueryAndFragment) return input.endsWith("/");
|
|
131
|
+
return TRAILING_SLASH_RE.test(input);
|
|
132
|
+
}
|
|
133
|
+
function withoutTrailingSlash(input = "", respectQueryAndFragment) {
|
|
134
|
+
if (!respectQueryAndFragment) return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
|
135
|
+
if (!hasTrailingSlash(input, true)) return input || "/";
|
|
136
|
+
let path = input;
|
|
137
|
+
let fragment = "";
|
|
138
|
+
const fragmentIndex = input.indexOf("#");
|
|
139
|
+
if (fragmentIndex !== -1) {
|
|
140
|
+
path = input.slice(0, fragmentIndex);
|
|
141
|
+
fragment = input.slice(fragmentIndex);
|
|
142
|
+
}
|
|
143
|
+
const [s0, ...s] = path.split("?");
|
|
144
|
+
const cleanPath = s0.endsWith("/") ? s0.slice(0, -1) : s0;
|
|
145
|
+
return (cleanPath || "/") + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
146
|
+
}
|
|
147
|
+
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
148
|
+
if (!respectQueryAndFragment) return input.endsWith("/") ? input : input + "/";
|
|
149
|
+
if (hasTrailingSlash(input, true)) return input || "/";
|
|
150
|
+
let path = input;
|
|
151
|
+
let fragment = "";
|
|
152
|
+
const fragmentIndex = input.indexOf("#");
|
|
153
|
+
if (fragmentIndex !== -1) {
|
|
154
|
+
path = input.slice(0, fragmentIndex);
|
|
155
|
+
fragment = input.slice(fragmentIndex);
|
|
156
|
+
if (!path) return fragment;
|
|
157
|
+
}
|
|
158
|
+
const [s0, ...s] = path.split("?");
|
|
159
|
+
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
160
|
+
}
|
|
161
|
+
function withBase(input, base) {
|
|
162
|
+
if (isEmptyURL(base) || hasProtocol(input)) return input;
|
|
163
|
+
const _base = withoutTrailingSlash(base);
|
|
164
|
+
if (input.startsWith(_base)) return input;
|
|
165
|
+
return joinURL(_base, input);
|
|
166
|
+
}
|
|
167
|
+
function withQuery(input, query) {
|
|
168
|
+
const parsed = parseURL(input);
|
|
169
|
+
const mergedQuery = {
|
|
170
|
+
...parseQuery(parsed.search),
|
|
171
|
+
...query
|
|
172
|
+
};
|
|
173
|
+
parsed.search = stringifyQuery(mergedQuery);
|
|
174
|
+
return stringifyParsedURL(parsed);
|
|
175
|
+
}
|
|
176
|
+
function isEmptyURL(url) {
|
|
177
|
+
return !url || url === "/";
|
|
178
|
+
}
|
|
179
|
+
function isNonEmptyURL(url) {
|
|
180
|
+
return url && url !== "/";
|
|
181
|
+
}
|
|
182
|
+
function joinURL(base, ...input) {
|
|
183
|
+
let url = base || "";
|
|
184
|
+
for (const segment of input.filter((url2) => isNonEmptyURL(url2))) if (url) {
|
|
185
|
+
const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
|
|
186
|
+
url = withTrailingSlash(url) + _segment;
|
|
187
|
+
} else url = segment;
|
|
188
|
+
return url;
|
|
189
|
+
}
|
|
190
|
+
const protocolRelative = Symbol.for("ufo:protocolRelative");
|
|
191
|
+
function parseURL(input = "", defaultProto) {
|
|
192
|
+
const _specialProtoMatch = input.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);
|
|
193
|
+
if (_specialProtoMatch) {
|
|
194
|
+
const [, _proto, _pathname = ""] = _specialProtoMatch;
|
|
195
|
+
return {
|
|
196
|
+
protocol: _proto.toLowerCase(),
|
|
197
|
+
pathname: _pathname,
|
|
198
|
+
href: _proto + _pathname,
|
|
199
|
+
auth: "",
|
|
200
|
+
host: "",
|
|
201
|
+
search: "",
|
|
202
|
+
hash: ""
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (!hasProtocol(input, { acceptRelative: true })) return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
|
|
206
|
+
const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
|
|
207
|
+
let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
|
|
208
|
+
if (protocol === "file:") path = path.replace(/\/(?=[A-Za-z]:)/, "");
|
|
209
|
+
const { pathname, search, hash } = parsePath(path);
|
|
210
|
+
return {
|
|
211
|
+
protocol: protocol.toLowerCase(),
|
|
212
|
+
auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
|
|
213
|
+
host,
|
|
214
|
+
pathname,
|
|
215
|
+
search,
|
|
216
|
+
hash,
|
|
217
|
+
[protocolRelative]: !protocol
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function parsePath(input = "") {
|
|
221
|
+
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
|
|
222
|
+
return {
|
|
223
|
+
pathname,
|
|
224
|
+
search,
|
|
225
|
+
hash
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function stringifyParsedURL(parsed) {
|
|
229
|
+
const pathname = parsed.pathname || "";
|
|
230
|
+
const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
|
|
231
|
+
const hash = parsed.hash || "";
|
|
232
|
+
const auth = parsed.auth ? parsed.auth + "@" : "";
|
|
233
|
+
const host = parsed.host || "";
|
|
234
|
+
const proto = parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "";
|
|
235
|
+
return proto + auth + host + pathname + search + hash;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs
|
|
240
|
+
var FetchError = class extends Error {
|
|
241
|
+
constructor(message, opts) {
|
|
242
|
+
super(message, opts);
|
|
243
|
+
this.name = "FetchError";
|
|
244
|
+
if (opts?.cause && !this.cause) this.cause = opts.cause;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
function createFetchError(ctx) {
|
|
248
|
+
const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
|
|
249
|
+
const method = ctx.request?.method || ctx.options?.method || "GET";
|
|
250
|
+
const url = ctx.request?.url || String(ctx.request) || "/";
|
|
251
|
+
const requestStr = `[${method}] ${JSON.stringify(url)}`;
|
|
252
|
+
const statusStr = ctx.response ? `${ctx.response.status} ${ctx.response.statusText}` : "<no response>";
|
|
253
|
+
const message = `${requestStr}: ${statusStr}${errorMessage ? ` ${errorMessage}` : ""}`;
|
|
254
|
+
const fetchError = new FetchError(message, ctx.error ? { cause: ctx.error } : void 0);
|
|
255
|
+
for (const key of [
|
|
256
|
+
"request",
|
|
257
|
+
"options",
|
|
258
|
+
"response"
|
|
259
|
+
]) Object.defineProperty(fetchError, key, { get() {
|
|
260
|
+
return ctx[key];
|
|
261
|
+
} });
|
|
262
|
+
for (const [key, refKey] of [
|
|
263
|
+
["data", "_data"],
|
|
264
|
+
["status", "status"],
|
|
265
|
+
["statusCode", "status"],
|
|
266
|
+
["statusText", "statusText"],
|
|
267
|
+
["statusMessage", "statusText"]
|
|
268
|
+
]) Object.defineProperty(fetchError, key, { get() {
|
|
269
|
+
return ctx.response && ctx.response[refKey];
|
|
270
|
+
} });
|
|
271
|
+
return fetchError;
|
|
272
|
+
}
|
|
273
|
+
const payloadMethods = new Set(Object.freeze([
|
|
274
|
+
"PATCH",
|
|
275
|
+
"POST",
|
|
276
|
+
"PUT",
|
|
277
|
+
"DELETE"
|
|
278
|
+
]));
|
|
279
|
+
function isPayloadMethod(method = "GET") {
|
|
280
|
+
return payloadMethods.has(method.toUpperCase());
|
|
281
|
+
}
|
|
282
|
+
function isJSONSerializable(value) {
|
|
283
|
+
if (value === void 0) return false;
|
|
284
|
+
const t = typeof value;
|
|
285
|
+
if (t === "string" || t === "number" || t === "boolean" || t === null) return true;
|
|
286
|
+
if (t !== "object") return false;
|
|
287
|
+
if (Array.isArray(value)) return true;
|
|
288
|
+
if (value.buffer) return false;
|
|
289
|
+
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
290
|
+
}
|
|
291
|
+
const textTypes = /* @__PURE__ */ new Set([
|
|
292
|
+
"image/svg",
|
|
293
|
+
"application/xml",
|
|
294
|
+
"application/xhtml",
|
|
295
|
+
"application/html"
|
|
296
|
+
]);
|
|
297
|
+
const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
|
|
298
|
+
function detectResponseType(_contentType = "") {
|
|
299
|
+
if (!_contentType) return "json";
|
|
300
|
+
const contentType = _contentType.split(";").shift() || "";
|
|
301
|
+
if (JSON_RE.test(contentType)) return "json";
|
|
302
|
+
if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
|
|
303
|
+
return "blob";
|
|
304
|
+
}
|
|
305
|
+
function resolveFetchOptions(request, input, defaults, Headers$1) {
|
|
306
|
+
const headers = mergeHeaders(input?.headers ?? request?.headers, defaults?.headers, Headers$1);
|
|
307
|
+
let query;
|
|
308
|
+
if (defaults?.query || defaults?.params || input?.params || input?.query) query = {
|
|
309
|
+
...defaults?.params,
|
|
310
|
+
...defaults?.query,
|
|
311
|
+
...input?.params,
|
|
312
|
+
...input?.query
|
|
313
|
+
};
|
|
314
|
+
return {
|
|
315
|
+
...defaults,
|
|
316
|
+
...input,
|
|
317
|
+
query,
|
|
318
|
+
params: query,
|
|
319
|
+
headers
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function mergeHeaders(input, defaults, Headers$1) {
|
|
323
|
+
if (!defaults) return new Headers$1(input);
|
|
324
|
+
const headers = new Headers$1(defaults);
|
|
325
|
+
if (input) for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers$1(input)) headers.set(key, value);
|
|
326
|
+
return headers;
|
|
327
|
+
}
|
|
328
|
+
async function callHooks(context, hooks) {
|
|
329
|
+
if (hooks) if (Array.isArray(hooks)) for (const hook of hooks) await hook(context);
|
|
330
|
+
else await hooks(context);
|
|
331
|
+
}
|
|
332
|
+
const retryStatusCodes = /* @__PURE__ */ new Set([
|
|
333
|
+
408,
|
|
334
|
+
409,
|
|
335
|
+
425,
|
|
336
|
+
429,
|
|
337
|
+
500,
|
|
338
|
+
502,
|
|
339
|
+
503,
|
|
340
|
+
504
|
|
341
|
+
]);
|
|
342
|
+
const nullBodyResponses = /* @__PURE__ */ new Set([
|
|
343
|
+
101,
|
|
344
|
+
204,
|
|
345
|
+
205,
|
|
346
|
+
304
|
|
347
|
+
]);
|
|
348
|
+
function createFetch(globalOptions = {}) {
|
|
349
|
+
const { fetch: fetch$1 = globalThis.fetch, Headers: Headers$1 = globalThis.Headers, AbortController: AbortController$1 = globalThis.AbortController } = globalOptions;
|
|
350
|
+
async function onError(context) {
|
|
351
|
+
const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
|
|
352
|
+
if (context.options.retry !== false && !isAbort) {
|
|
353
|
+
let retries;
|
|
354
|
+
if (typeof context.options.retry === "number") retries = context.options.retry;
|
|
355
|
+
else retries = isPayloadMethod(context.options.method) ? 0 : 1;
|
|
356
|
+
const responseCode = context.response && context.response.status || 500;
|
|
357
|
+
if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
|
|
358
|
+
const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
|
|
359
|
+
if (retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
360
|
+
return $fetchRaw(context.request, {
|
|
361
|
+
...context.options,
|
|
362
|
+
retry: retries - 1
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const error = createFetchError(context);
|
|
367
|
+
if (Error.captureStackTrace) Error.captureStackTrace(error, $fetchRaw);
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
|
|
371
|
+
const context = {
|
|
372
|
+
request: _request,
|
|
373
|
+
options: resolveFetchOptions(_request, _options, globalOptions.defaults, Headers$1),
|
|
374
|
+
response: void 0,
|
|
375
|
+
error: void 0
|
|
376
|
+
};
|
|
377
|
+
if (context.options.method) context.options.method = context.options.method.toUpperCase();
|
|
378
|
+
if (context.options.onRequest) await callHooks(context, context.options.onRequest);
|
|
379
|
+
if (typeof context.request === "string") {
|
|
380
|
+
if (context.options.baseURL) context.request = withBase(context.request, context.options.baseURL);
|
|
381
|
+
if (context.options.query) {
|
|
382
|
+
context.request = withQuery(context.request, context.options.query);
|
|
383
|
+
delete context.options.query;
|
|
384
|
+
}
|
|
385
|
+
if ("query" in context.options) delete context.options.query;
|
|
386
|
+
if ("params" in context.options) delete context.options.params;
|
|
387
|
+
}
|
|
388
|
+
if (context.options.body && isPayloadMethod(context.options.method)) {
|
|
389
|
+
if (isJSONSerializable(context.options.body)) {
|
|
390
|
+
context.options.body = typeof context.options.body === "string" ? context.options.body : JSON.stringify(context.options.body);
|
|
391
|
+
context.options.headers = new Headers$1(context.options.headers || {});
|
|
392
|
+
if (!context.options.headers.has("content-type")) context.options.headers.set("content-type", "application/json");
|
|
393
|
+
if (!context.options.headers.has("accept")) context.options.headers.set("accept", "application/json");
|
|
394
|
+
} else if ("pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || typeof context.options.body.pipe === "function") {
|
|
395
|
+
if (!("duplex" in context.options)) context.options.duplex = "half";
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
let abortTimeout;
|
|
399
|
+
if (!context.options.signal && context.options.timeout) {
|
|
400
|
+
const controller = new AbortController$1();
|
|
401
|
+
abortTimeout = setTimeout(() => {
|
|
402
|
+
const error = new Error("[TimeoutError]: The operation was aborted due to timeout");
|
|
403
|
+
error.name = "TimeoutError";
|
|
404
|
+
error.code = 23;
|
|
405
|
+
controller.abort(error);
|
|
406
|
+
}, context.options.timeout);
|
|
407
|
+
context.options.signal = controller.signal;
|
|
408
|
+
}
|
|
409
|
+
try {
|
|
410
|
+
context.response = await fetch$1(context.request, context.options);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
context.error = error;
|
|
413
|
+
if (context.options.onRequestError) await callHooks(context, context.options.onRequestError);
|
|
414
|
+
return await onError(context);
|
|
415
|
+
} finally {
|
|
416
|
+
if (abortTimeout) clearTimeout(abortTimeout);
|
|
417
|
+
}
|
|
418
|
+
const hasBody = (context.response.body || context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD";
|
|
419
|
+
if (hasBody) {
|
|
420
|
+
const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
|
|
421
|
+
switch (responseType) {
|
|
422
|
+
case "json": {
|
|
423
|
+
const data = await context.response.text();
|
|
424
|
+
const parseFunction = context.options.parseResponse || destr;
|
|
425
|
+
context.response._data = parseFunction(data);
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
case "stream": {
|
|
429
|
+
context.response._data = context.response.body || context.response._bodyInit;
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
default: context.response._data = await context.response[responseType]();
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (context.options.onResponse) await callHooks(context, context.options.onResponse);
|
|
436
|
+
if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
|
|
437
|
+
if (context.options.onResponseError) await callHooks(context, context.options.onResponseError);
|
|
438
|
+
return await onError(context);
|
|
439
|
+
}
|
|
440
|
+
return context.response;
|
|
441
|
+
};
|
|
442
|
+
const $fetch = async function $fetch2(request, options) {
|
|
443
|
+
const r$2 = await $fetchRaw(request, options);
|
|
444
|
+
return r$2._data;
|
|
445
|
+
};
|
|
446
|
+
$fetch.raw = $fetchRaw;
|
|
447
|
+
$fetch.native = (...args) => fetch$1(...args);
|
|
448
|
+
$fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
|
|
449
|
+
...globalOptions,
|
|
450
|
+
...customGlobalOptions,
|
|
451
|
+
defaults: {
|
|
452
|
+
...globalOptions.defaults,
|
|
453
|
+
...customGlobalOptions.defaults,
|
|
454
|
+
...defaultOptions
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
return $fetch;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region node_modules/ofetch/dist/node.mjs
|
|
462
|
+
function createNodeFetch() {
|
|
463
|
+
const useKeepAlive = JSON.parse(process.env.FETCH_KEEP_ALIVE || "false");
|
|
464
|
+
if (!useKeepAlive) return r$1;
|
|
465
|
+
const agentOptions = { keepAlive: true };
|
|
466
|
+
const httpAgent = new node_http.default.Agent(agentOptions);
|
|
467
|
+
const httpsAgent = new node_https.default.Agent(agentOptions);
|
|
468
|
+
const nodeFetchOptions = { agent(parsedURL) {
|
|
469
|
+
return parsedURL.protocol === "http:" ? httpAgent : httpsAgent;
|
|
470
|
+
} };
|
|
471
|
+
return function nodeFetchWithKeepAlive(input, init) {
|
|
472
|
+
return r$1(input, {
|
|
473
|
+
...nodeFetchOptions,
|
|
474
|
+
...init
|
|
475
|
+
});
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
const fetch = globalThis.fetch ? (...args) => globalThis.fetch(...args) : createNodeFetch();
|
|
479
|
+
const Headers = globalThis.Headers || n;
|
|
480
|
+
const AbortController = globalThis.AbortController || T;
|
|
481
|
+
const ofetch = createFetch({
|
|
482
|
+
fetch,
|
|
483
|
+
Headers,
|
|
484
|
+
AbortController
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/utils/MyInvoisClient.ts
|
|
489
|
+
var MyInvoisClient = class {
|
|
490
|
+
baseUrl;
|
|
491
|
+
clientId;
|
|
492
|
+
clientSecret;
|
|
493
|
+
token = "";
|
|
494
|
+
tokenExpiration = new Date();
|
|
495
|
+
constructor(clientId, clientSecret, environment) {
|
|
496
|
+
this.clientId = clientId;
|
|
497
|
+
this.clientSecret = clientSecret;
|
|
498
|
+
if (environment === "sandbox") this.baseUrl = "https://preprod-mytax.hasil.gov.my/";
|
|
499
|
+
else this.baseUrl = "https://mytax.hasil.gov.my";
|
|
500
|
+
}
|
|
501
|
+
async refreshToken() {
|
|
502
|
+
const tokenResponse = await ofetch(`${this.baseUrl}/connect/token`, {
|
|
503
|
+
method: "POST",
|
|
504
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
505
|
+
body: {
|
|
506
|
+
grant_type: "client_credentials",
|
|
507
|
+
client_id: this.clientId,
|
|
508
|
+
client_secret: this.clientSecret,
|
|
509
|
+
scope: "InvoicingAPI"
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
this.token = tokenResponse.access_token;
|
|
513
|
+
this.tokenExpiration = new Date(Date.now() + tokenResponse.expires_in * 1e3);
|
|
514
|
+
}
|
|
515
|
+
async getToken() {
|
|
516
|
+
if (this.tokenExpiration < new Date()) await this.refreshToken();
|
|
517
|
+
return this.token;
|
|
518
|
+
}
|
|
519
|
+
async fetch(path, options = {}) {
|
|
520
|
+
const token = await this.getToken();
|
|
521
|
+
return ofetch(`${this.baseUrl}${path}`, {
|
|
522
|
+
...options,
|
|
523
|
+
headers: {
|
|
524
|
+
...options.headers,
|
|
525
|
+
Authorization: `Bearer ${token}`
|
|
526
|
+
},
|
|
527
|
+
responseType: "json"
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Validates a TIN against a NRIC
|
|
532
|
+
*
|
|
533
|
+
* @param tin
|
|
534
|
+
* @param nric
|
|
535
|
+
* @returns
|
|
536
|
+
*/
|
|
537
|
+
async verifyTin(tin, nric) {
|
|
538
|
+
try {
|
|
539
|
+
await this.fetch(`/api/v1.0/taxpayer/validate/${tin}?idType=NRIC&idValue=${nric}`, { method: "GET" });
|
|
540
|
+
return true;
|
|
541
|
+
} catch {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
//#endregion
|
|
548
|
+
exports.MyInvoisClient = MyInvoisClient
|
|
549
|
+
//# sourceMappingURL=index.cjs.map
|