@paklo/core 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/azure/index.d.mts +1605 -289
- package/dist/azure/index.mjs +951 -478
- package/dist/azure/index.mjs.map +1 -1
- package/dist/dependabot/index.d.mts +3 -3
- package/dist/dependabot/index.mjs +3 -4
- package/dist/{dependabot-E0nM5Xbb.mjs → dependabot-DVf7lAEG.mjs} +82 -20
- package/dist/dependabot-DVf7lAEG.mjs.map +1 -0
- package/dist/github/index.d.mts +1 -1
- package/dist/github/index.mjs +1 -1
- package/dist/{index-BWftXTYB.d.mts → index-BfwWezjJ.d.mts} +1 -1
- package/dist/{index-bwD11mTZ.d.mts → index-CFWMNvXg.d.mts} +105 -46
- package/dist/{job-DanO84YW.mjs → job-COuliaYg.mjs} +13 -16
- package/dist/{job-DanO84YW.mjs.map → job-COuliaYg.mjs.map} +1 -1
- package/dist/{logger-BqvUa-Ue.mjs → logger-3Qfh9NUj.mjs} +11 -4
- package/dist/logger-3Qfh9NUj.mjs.map +1 -0
- package/dist/logger.mjs +1 -1
- package/dist/usage.d.mts +1 -1
- package/dist/usage.mjs +1 -1
- package/package.json +5 -8
- package/dist/dependabot-E0nM5Xbb.mjs.map +0 -1
- package/dist/http/index.d.mts +0 -121
- package/dist/http/index.mjs +0 -3
- package/dist/http-D2wwAKQ-.mjs +0 -241
- package/dist/http-D2wwAKQ-.mjs.map +0 -1
- package/dist/logger-BqvUa-Ue.mjs.map +0 -1
package/dist/http-D2wwAKQ-.mjs
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
//#region src/http/headers.ts
|
|
2
|
-
const HEADER_NAME_CONTENT_DISPOSITION = "Content-Disposition";
|
|
3
|
-
const HEADER_NAME_CONTENT_TYPE = "Content-Type";
|
|
4
|
-
const HEADER_NAME_ACCEPT = "Accept";
|
|
5
|
-
const HEADER_NAME_USER_AGENT = "User-Agent";
|
|
6
|
-
const HEADER_NAME_AUTHORIZATION = "Authorization";
|
|
7
|
-
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/http/multipart.ts
|
|
10
|
-
var MultipartFormDataBody = class {
|
|
11
|
-
type = "multipart/form-data";
|
|
12
|
-
boundary = `${Math.random().toString(36).substring(2)}`;
|
|
13
|
-
parts = [];
|
|
14
|
-
async encode() {
|
|
15
|
-
if (this.parts.length === 0) throw new Error("MultipartFormDataBody must have at least one part");
|
|
16
|
-
const data = [];
|
|
17
|
-
for (const part of this.parts) {
|
|
18
|
-
data.push(`--${this.boundary}\r\n`);
|
|
19
|
-
for (const [key, value] of Object.entries(part.headers)) data.push(`${key}: ${value}\r\n`);
|
|
20
|
-
data.push("\r\n");
|
|
21
|
-
data.push(part.body);
|
|
22
|
-
data.push("\r\n");
|
|
23
|
-
}
|
|
24
|
-
data.push(`--${this.boundary}--\r\n`);
|
|
25
|
-
const list = [];
|
|
26
|
-
for (const item of data) if (item instanceof File) list.push(Buffer.from(await item.arrayBuffer()));
|
|
27
|
-
else if (typeof item === "string") list.push(Buffer.from(item, "utf8"));
|
|
28
|
-
else list.push(item);
|
|
29
|
-
return Buffer.concat(list);
|
|
30
|
-
}
|
|
31
|
-
getBoundary() {
|
|
32
|
-
return this.boundary;
|
|
33
|
-
}
|
|
34
|
-
getContentType() {
|
|
35
|
-
return `${this.type}; boundary=${this.boundary}`;
|
|
36
|
-
}
|
|
37
|
-
add(name, value) {
|
|
38
|
-
const part = createPart(name, value);
|
|
39
|
-
this.parts.push(part);
|
|
40
|
-
}
|
|
41
|
-
addFile(name, file) {
|
|
42
|
-
const part = createPart(name, file, file.name, file.type);
|
|
43
|
-
this.parts.push(part);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
function createPart(name, body, filename, contentType) {
|
|
47
|
-
const headers = {};
|
|
48
|
-
headers[HEADER_NAME_CONTENT_DISPOSITION] = `form-data; name="${name}"${filename ? `; filename="${filename}"` : ""}`;
|
|
49
|
-
if (contentType) headers[HEADER_NAME_CONTENT_TYPE] = contentType;
|
|
50
|
-
return {
|
|
51
|
-
name,
|
|
52
|
-
headers,
|
|
53
|
-
body
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/http/inner.ts
|
|
59
|
-
var InnerApiClient = class {
|
|
60
|
-
baseUrl;
|
|
61
|
-
headers;
|
|
62
|
-
token;
|
|
63
|
-
/**
|
|
64
|
-
* Create a new API client.
|
|
65
|
-
* @param options The options to use for the client.
|
|
66
|
-
*/
|
|
67
|
-
constructor({ baseUrl, token }) {
|
|
68
|
-
this.baseUrl = baseUrl;
|
|
69
|
-
this.headers = new Headers({ [HEADER_NAME_ACCEPT]: "application/json" });
|
|
70
|
-
this.token = token;
|
|
71
|
-
}
|
|
72
|
-
async get(url, options) {
|
|
73
|
-
return this.request({
|
|
74
|
-
url: this.makeUrl(url, options),
|
|
75
|
-
method: "GET",
|
|
76
|
-
...options
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async post(url, options) {
|
|
80
|
-
return this.request({
|
|
81
|
-
method: "POST",
|
|
82
|
-
url: this.makeUrl(url, options),
|
|
83
|
-
...options
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async put(url, options) {
|
|
87
|
-
return this.request({
|
|
88
|
-
method: "PUT",
|
|
89
|
-
url: this.makeUrl(url, options),
|
|
90
|
-
...options
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
async patch(url, options) {
|
|
94
|
-
return this.request({
|
|
95
|
-
method: "PATCH",
|
|
96
|
-
url: this.makeUrl(url, options),
|
|
97
|
-
...options
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
async delete(url, options) {
|
|
101
|
-
return this.request({
|
|
102
|
-
method: "DELETE",
|
|
103
|
-
url: this.makeUrl(url, options),
|
|
104
|
-
...options
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
async request(options) {
|
|
108
|
-
const { method, url, payload, userAgent, headers: additionalHeaders, schema } = options;
|
|
109
|
-
const headers = new Headers(this.headers);
|
|
110
|
-
if (userAgent) headers.set(HEADER_NAME_USER_AGENT, userAgent);
|
|
111
|
-
if (this.token) headers.set(HEADER_NAME_AUTHORIZATION, `Bearer ${this.token}`);
|
|
112
|
-
if (additionalHeaders) if (additionalHeaders instanceof Headers) additionalHeaders.forEach((value, key) => headers.set(key, value));
|
|
113
|
-
else if (Array.isArray(additionalHeaders)) additionalHeaders.forEach(([key, value]) => headers.set(key, value));
|
|
114
|
-
else Object.entries(additionalHeaders).forEach(([key, value]) => headers.set(key, value));
|
|
115
|
-
let body;
|
|
116
|
-
if (skipSerialization(payload)) body = payload;
|
|
117
|
-
else if (payload instanceof MultipartFormDataBody) {
|
|
118
|
-
body = new Uint8Array(await payload.encode());
|
|
119
|
-
headers.set(HEADER_NAME_CONTENT_TYPE, payload.getContentType());
|
|
120
|
-
} else {
|
|
121
|
-
body = JSON.stringify(payload);
|
|
122
|
-
headers.set(HEADER_NAME_CONTENT_TYPE, "application/json");
|
|
123
|
-
}
|
|
124
|
-
try {
|
|
125
|
-
const response = await fetch(url, {
|
|
126
|
-
method,
|
|
127
|
-
headers,
|
|
128
|
-
body
|
|
129
|
-
});
|
|
130
|
-
const { ok: successful, status, statusText } = response;
|
|
131
|
-
if (!successful) try {
|
|
132
|
-
const rawError = await response.text();
|
|
133
|
-
return {
|
|
134
|
-
headers: response.headers,
|
|
135
|
-
successful,
|
|
136
|
-
status,
|
|
137
|
-
statusText,
|
|
138
|
-
error: JSON.parse(rawError)
|
|
139
|
-
};
|
|
140
|
-
} catch (err) {
|
|
141
|
-
if (err instanceof SyntaxError) return {
|
|
142
|
-
headers: response.headers,
|
|
143
|
-
successful,
|
|
144
|
-
status,
|
|
145
|
-
statusText,
|
|
146
|
-
error: {
|
|
147
|
-
title: "Unknown error",
|
|
148
|
-
status,
|
|
149
|
-
statusText: response.statusText
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const error = {
|
|
153
|
-
title: (err instanceof Error ? err.message : void 0) ?? "Unknown error",
|
|
154
|
-
status: response.status,
|
|
155
|
-
statusText: response.statusText
|
|
156
|
-
};
|
|
157
|
-
return {
|
|
158
|
-
headers: response.headers,
|
|
159
|
-
successful,
|
|
160
|
-
status,
|
|
161
|
-
statusText,
|
|
162
|
-
error
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
const contentLength = response.headers.get("content-length");
|
|
166
|
-
let data = contentLength && contentLength !== "0" ? await response.json() : void 0;
|
|
167
|
-
if (data && schema) {
|
|
168
|
-
const result = await schema.safeParseAsync(data);
|
|
169
|
-
if (!result.success) return {
|
|
170
|
-
headers: response.headers,
|
|
171
|
-
successful: false,
|
|
172
|
-
status,
|
|
173
|
-
statusText,
|
|
174
|
-
data,
|
|
175
|
-
error: {
|
|
176
|
-
title: "application_error",
|
|
177
|
-
detail: "Schema validation error",
|
|
178
|
-
errors: result.error.flatten().fieldErrors,
|
|
179
|
-
status: response.status,
|
|
180
|
-
statusText: response.statusText
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
data = result.data;
|
|
184
|
-
}
|
|
185
|
-
return {
|
|
186
|
-
headers: response.headers,
|
|
187
|
-
data,
|
|
188
|
-
successful,
|
|
189
|
-
status,
|
|
190
|
-
statusText
|
|
191
|
-
};
|
|
192
|
-
} catch (err) {
|
|
193
|
-
return {
|
|
194
|
-
headers: new Headers(),
|
|
195
|
-
successful: false,
|
|
196
|
-
status: -1,
|
|
197
|
-
statusText: "Application Error",
|
|
198
|
-
error: {
|
|
199
|
-
title: "application_error",
|
|
200
|
-
detail: `Unable to fetch data. The request could not be resolved. ${err}`
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
makeUrl(url, options) {
|
|
206
|
-
if (url.startsWith("http://") || url.startsWith("https://")) return url;
|
|
207
|
-
return `${options?.baseUrl ?? this.baseUrl}${url}`;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
/**
|
|
211
|
-
* Whether to skip serialization of the payload.
|
|
212
|
-
* @param payload The payload to check.
|
|
213
|
-
* @returns true if the payload should not be serialized; otherwise, false.
|
|
214
|
-
*/
|
|
215
|
-
function skipSerialization(payload) {
|
|
216
|
-
return payload instanceof FormData || payload instanceof URLSearchParams || payload instanceof ReadableStream || payload instanceof Blob || payload instanceof ArrayBuffer || payload instanceof Buffer || typeof payload === "string" || !payload;
|
|
217
|
-
}
|
|
218
|
-
/** Http request error */
|
|
219
|
-
var HttpRequestError = class extends Error {
|
|
220
|
-
constructor(message, code) {
|
|
221
|
-
super(message);
|
|
222
|
-
this.code = code;
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
function isErrorTemporaryFailure(e) {
|
|
226
|
-
if (e instanceof HttpRequestError) switch (e.code) {
|
|
227
|
-
case 502: return true;
|
|
228
|
-
case 503: return true;
|
|
229
|
-
case 504: return true;
|
|
230
|
-
default: return false;
|
|
231
|
-
}
|
|
232
|
-
else if (e?.code) switch (e.code) {
|
|
233
|
-
case "ETIMEDOUT": return true;
|
|
234
|
-
default: return false;
|
|
235
|
-
}
|
|
236
|
-
else return false;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
//#endregion
|
|
240
|
-
export { HEADER_NAME_AUTHORIZATION as a, HEADER_NAME_USER_AGENT as c, HEADER_NAME_ACCEPT as i, InnerApiClient as n, HEADER_NAME_CONTENT_DISPOSITION as o, isErrorTemporaryFailure as r, HEADER_NAME_CONTENT_TYPE as s, HttpRequestError as t };
|
|
241
|
-
//# sourceMappingURL=http-D2wwAKQ-.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-D2wwAKQ-.mjs","names":["data: Array<MultipartFormDataBodyPart['body']>","list: Buffer[]","headers: Record<string, string>","body: BodyInit | undefined","error: ProblemDetails","code: number"],"sources":["../src/http/headers.ts","../src/http/multipart.ts","../src/http/inner.ts"],"sourcesContent":["export const HEADER_NAME_CONTENT_DISPOSITION = 'Content-Disposition';\nexport const HEADER_NAME_CONTENT_TYPE = 'Content-Type';\nexport const HEADER_NAME_ACCEPT = 'Accept';\nexport const HEADER_NAME_USER_AGENT = 'User-Agent';\nexport const HEADER_NAME_AUTHORIZATION = 'Authorization';\n","import { HEADER_NAME_CONTENT_DISPOSITION, HEADER_NAME_CONTENT_TYPE } from './headers';\n\nexport class MultipartFormDataBody {\n private type = 'multipart/form-data';\n private boundary: string = `${Math.random().toString(36).substring(2)}`;\n private parts: Array<MultipartFormDataBodyPart> = [];\n\n public async encode(): Promise<Buffer> {\n if (this.parts.length === 0) {\n throw new Error('MultipartFormDataBody must have at least one part');\n }\n\n const data: Array<MultipartFormDataBodyPart['body']> = [];\n\n for (const part of this.parts) {\n // write boundary\n data.push(`--${this.boundary}\\r\\n`);\n\n // write headers\n for (const [key, value] of Object.entries(part.headers)) {\n data.push(`${key}: ${value}\\r\\n`);\n }\n data.push('\\r\\n');\n\n // write body\n data.push(part.body);\n data.push('\\r\\n');\n }\n\n data.push(`--${this.boundary}--\\r\\n`);\n\n const list: Buffer[] = [];\n for (const item of data) {\n if (item instanceof File) list.push(Buffer.from(await item.arrayBuffer()));\n else if (typeof item === 'string') list.push(Buffer.from(item, 'utf8'));\n else list.push(item);\n }\n return Buffer.concat(list);\n }\n\n public getBoundary(): string {\n return this.boundary;\n }\n\n public getContentType(): string {\n return `${this.type}; boundary=${this.boundary}`;\n }\n\n public add(name: string, value: string) {\n const part = createPart(name, value);\n this.parts.push(part);\n }\n\n public addFile(name: string, file: File) {\n const part = createPart(name, file, file.name, file.type);\n this.parts.push(part);\n }\n}\n\ntype MultipartFormDataBodyPart = {\n name: string;\n headers: Record<string, string>;\n body: Buffer | File | string;\n};\n\nfunction createPart(\n name: string,\n body: MultipartFormDataBodyPart['body'],\n filename?: string,\n contentType?: string,\n): MultipartFormDataBodyPart {\n const headers: Record<string, string> = {};\n headers[HEADER_NAME_CONTENT_DISPOSITION] = `form-data; name=\"${name}\"${filename ? `; filename=\"${filename}\"` : ''}`;\n if (contentType) headers[HEADER_NAME_CONTENT_TYPE] = contentType;\n return { name, headers, body };\n}\n","import type { ZodType } from 'zod';\n\nimport {\n HEADER_NAME_ACCEPT,\n HEADER_NAME_AUTHORIZATION,\n HEADER_NAME_CONTENT_TYPE,\n HEADER_NAME_USER_AGENT,\n} from './headers';\nimport { MultipartFormDataBody } from './multipart';\nimport type { ProblemDetails } from './problem';\n\nexport type CreateInnerApiClientOptions = {\n /**\n * The base URL to use for the API.\n * @example 'https://www.paklo.app/api'\n */\n baseUrl: string;\n\n /** The token to use for authentication. This can be a JWT or specialized key. */\n token?: string;\n};\n\nexport type RequestOptions = {\n /**\n * Value for the `User-Agent` header.\n * This prepends the default value (e.g. `paklo/ab26320`)\n * which is important when we need to propagate the browser information to the server.\n */\n userAgent?: string;\n};\n\nexport type ResourceResponse<T = Record<string, unknown>> = {\n /** The headers of the response. */\n headers: Headers;\n\n /** Whether the request was successful. */\n successful: boolean;\n\n /** The status code of the response. */\n status: number;\n\n /** The status text of the response. */\n statusText: string;\n\n /** The data of the response. */\n data?: T;\n\n /** The error of the response. */\n error?: ProblemDetails;\n};\n\nexport type InnerRequestOptions<T> = RequestOptions & {\n /**\n * The base URL to use for the request.\n * This overrides the default base URL.\n * @example 'https://www.paklo.app/api'\n */\n baseUrl?: string;\n\n /** Additional headers to use for the request. */\n headers?: HeadersInit;\n\n /** The payload to use for the request. */\n payload?: Record<string, unknown> | MultipartFormDataBody | ReadableStream | XMLHttpRequestBodyInit;\n\n /** The schema to use when parsing the response. */\n schema?: ZodType<T>;\n};\n\ntype InnerRequestOptionsComplete<T> = InnerRequestOptions<T> & {\n /** The method to use for the request. */\n method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n /** The URL to use for the request. */\n url: string;\n};\n\nexport class InnerApiClient {\n private readonly baseUrl: string;\n private readonly headers: Headers;\n private readonly token?: string;\n\n /**\n * Create a new API client.\n * @param options The options to use for the client.\n */\n constructor({ baseUrl, token }: CreateInnerApiClientOptions) {\n this.baseUrl = baseUrl;\n\n this.headers = new Headers({\n [HEADER_NAME_ACCEPT]: 'application/json',\n });\n\n this.token = token;\n }\n\n async get<T>(url: string, options?: InnerRequestOptions<T>) {\n return this.request<T>({\n url: this.makeUrl(url, options),\n method: 'GET',\n ...options,\n });\n }\n\n async post<T>(url: string, options?: InnerRequestOptions<T>) {\n return this.request<T>({\n method: 'POST',\n url: this.makeUrl(url, options),\n ...options,\n });\n }\n\n async put<T>(url: string, options?: InnerRequestOptions<T>) {\n return this.request<T>({\n method: 'PUT',\n url: this.makeUrl(url, options),\n ...options,\n });\n }\n\n async patch<T>(url: string, options?: InnerRequestOptions<T>) {\n return this.request<T>({\n method: 'PATCH',\n url: this.makeUrl(url, options),\n ...options,\n });\n }\n\n async delete<T>(url: string, options?: InnerRequestOptions<T>) {\n return this.request<T>({\n method: 'DELETE',\n url: this.makeUrl(url, options),\n ...options,\n });\n }\n\n async request<T>(options: InnerRequestOptionsComplete<T>): Promise<ResourceResponse<T>> {\n const { method, url, payload, userAgent, headers: additionalHeaders, schema } = options;\n\n // create headers for the request\n const headers = new Headers(this.headers);\n if (userAgent) {\n headers.set(HEADER_NAME_USER_AGENT, userAgent);\n }\n\n // populate authorization header\n if (this.token) {\n headers.set(HEADER_NAME_AUTHORIZATION, `Bearer ${this.token}`);\n }\n\n // populate additional headers\n // biome-ignore-start lint/suspicious/useIterableCallbackReturn: not used\n if (additionalHeaders) {\n if (additionalHeaders instanceof Headers) {\n additionalHeaders.forEach((value, key) => headers.set(key, value as string));\n } else if (Array.isArray(additionalHeaders)) {\n additionalHeaders.forEach(([key, value]) => headers.set(key, value));\n } else {\n Object.entries(additionalHeaders).forEach(([key, value]) => headers.set(key, value as string));\n }\n }\n // biome-ignore-end lint/suspicious/useIterableCallbackReturn: not used\n\n // prepare body\n let body: BodyInit | undefined;\n if (skipSerialization(payload)) body = payload;\n else if (payload instanceof MultipartFormDataBody) {\n body = new Uint8Array(await payload.encode());\n headers.set(HEADER_NAME_CONTENT_TYPE, payload.getContentType());\n } else {\n body = JSON.stringify(payload);\n headers.set(HEADER_NAME_CONTENT_TYPE, 'application/json');\n }\n\n // make request\n try {\n const response = await fetch(url, { method, headers, body });\n const { ok: successful, status, statusText } = response;\n\n if (!successful) {\n try {\n const rawError = await response.text();\n return { headers: response.headers, successful, status, statusText, error: JSON.parse(rawError) };\n } catch (err) {\n if (err instanceof SyntaxError) {\n return {\n headers: response.headers,\n successful,\n status,\n statusText,\n error: {\n title: 'Unknown error',\n status,\n statusText: response.statusText,\n },\n };\n }\n\n const error: ProblemDetails = {\n title: (err instanceof Error ? err.message : undefined) ?? 'Unknown error',\n status: response.status,\n statusText: response.statusText,\n };\n\n return { headers: response.headers, successful, status, statusText, error };\n }\n }\n\n const contentLength = response.headers.get('content-length');\n let data = contentLength && contentLength !== '0' ? ((await response.json()) as T) : undefined;\n if (data && schema) {\n const result = await schema.safeParseAsync(data);\n if (!result.success) {\n return {\n headers: response.headers,\n successful: false,\n status,\n statusText,\n data,\n error: {\n title: 'application_error',\n detail: 'Schema validation error',\n errors: result.error.flatten().fieldErrors,\n status: response.status,\n statusText: response.statusText,\n },\n };\n }\n data = result.data;\n }\n\n return { headers: response.headers, data, successful, status, statusText };\n } catch (err) {\n return {\n headers: new Headers(),\n successful: false,\n status: -1,\n statusText: 'Application Error',\n error: {\n title: 'application_error',\n detail: `Unable to fetch data. The request could not be resolved. ${err}`,\n },\n };\n }\n }\n\n private makeUrl<T>(url: string, options?: InnerRequestOptions<T>): string {\n if (url.startsWith('http://') || url.startsWith('https://')) return url;\n const baseUrl = options?.baseUrl ?? this.baseUrl;\n return `${baseUrl}${url}`;\n }\n}\n\n/**\n * Whether to skip serialization of the payload.\n * @param payload The payload to check.\n * @returns true if the payload should not be serialized; otherwise, false.\n */\nfunction skipSerialization(\n payload: InnerRequestOptions<never>['payload'],\n): payload is FormData | URLSearchParams | ReadableStream | Blob | ArrayBuffer | string | undefined {\n return (\n payload instanceof FormData ||\n payload instanceof URLSearchParams ||\n payload instanceof ReadableStream ||\n payload instanceof Blob ||\n payload instanceof ArrayBuffer ||\n payload instanceof Buffer ||\n typeof payload === 'string' ||\n !payload\n );\n}\n\n/** Http request error */\nexport class HttpRequestError extends Error {\n constructor(\n message: string,\n public code: number,\n ) {\n super(message);\n }\n}\n\nexport function isErrorTemporaryFailure(e?: { code?: string | number; message?: string } | null): boolean {\n if (e instanceof HttpRequestError) {\n // Check for common HTTP status codes that indicate a temporary failure\n // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status\n switch (e.code) {\n case 502:\n return true; // 502 Bad Gateway\n case 503:\n return true; // 503 Service Unavailable\n case 504:\n return true; // 504 Gateway Timeout\n default:\n return false;\n }\n } else if (e?.code) {\n // Check for Node.js system errors that indicate a temporary failure\n // See: https://nodejs.org/api/errors.html#errors_common_system_errors\n switch (e.code) {\n case 'ETIMEDOUT':\n return true; // Operation timed out\n default:\n return false;\n }\n } else {\n return false;\n }\n}\n"],"mappings":";AAAA,MAAa,kCAAkC;AAC/C,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAClC,MAAa,yBAAyB;AACtC,MAAa,4BAA4B;;;;ACFzC,IAAa,wBAAb,MAAmC;CACjC,AAAQ,OAAO;CACf,AAAQ,WAAmB,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,UAAU,EAAE;CACrE,AAAQ,QAA0C,EAAE;CAEpD,MAAa,SAA0B;AACrC,MAAI,KAAK,MAAM,WAAW,EACxB,OAAM,IAAI,MAAM,oDAAoD;EAGtE,MAAMA,OAAiD,EAAE;AAEzD,OAAK,MAAM,QAAQ,KAAK,OAAO;AAE7B,QAAK,KAAK,KAAK,KAAK,SAAS,MAAM;AAGnC,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,QAAQ,CACrD,MAAK,KAAK,GAAG,IAAI,IAAI,MAAM,MAAM;AAEnC,QAAK,KAAK,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IACZ,OAAO;KACL,OAAO;KACP,QAAQ,4DAA4D;KACrE;IACF;;;CAIL,AAAQ,QAAW,KAAa,SAA0C;AACxE,MAAI,IAAI,WAAW,UAAU,IAAI,IAAI,WAAW,WAAW,CAAE,QAAO;AAEpE,SAAO,GADS,SAAS,WAAW,KAAK,UACrB;;;;;;;;AASxB,SAAS,kBACP,SACkG;AAClG,QACE,mBAAmB,YACnB,mBAAmB,mBACnB,mBAAmB,kBACnB,mBAAmB,QACnB,mBAAmB,eACnB,mBAAmB,UACnB,OAAO,YAAY,YACnB,CAAC;;;AAKL,IAAa,mBAAb,cAAsC,MAAM;CAC1C,YACE,SACA,AAAOC,MACP;AACA,QAAM,QAAQ;EAFP;;;AAMX,SAAgB,wBAAwB,GAAkE;AACxG,KAAI,aAAa,iBAGf,SAAQ,EAAE,MAAV;EACE,KAAK,IACH,QAAO;EACT,KAAK,IACH,QAAO;EACT,KAAK,IACH,QAAO;EACT,QACE,QAAO;;UAEF,GAAG,KAGZ,SAAQ,EAAE,MAAV;EACE,KAAK,YACH,QAAO;EACT,QACE,QAAO;;KAGX,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger-BqvUa-Ue.mjs","names":[],"sources":["../src/logger.ts"],"sourcesContent":["import pino, { type DestinationStream, type Level } from 'pino';\nimport pretty from 'pino-pretty';\n\nexport type LoggerCreateOptions = {\n /**\n * Log level\n * Only set this if you must override the default log level logic from env variables\n */\n level?: Level;\n\n /**\n * Whether to include time stamps in log entries\n * @default false\n */\n timestamp?: boolean;\n\n /** Options for pretty printing */\n pretty?: {\n /**\n * Whether to enable pretty printing\n * @default true\n */\n enable?: boolean;\n\n /**\n * Whether to colorize the pretty printed output\n * @default true\n */\n colorize?: boolean;\n\n /**\n * Whether to include the log level in pretty printed output\n * @default false\n */\n includeLevel?: boolean;\n };\n\n /**\n * Additional streams, if any, to write logs to.\n * This is in addition to any pretty printing stream configured.\n * Useful for adding things like OpenTelemetry streams.\n */\n streams?: DestinationStream[];\n};\n\n/**\n * Creates a new logger with the given options.\n * @param options - Logger creation options\n * @returns A logger instance\n */\nexport function create(options: LoggerCreateOptions = {}) {\n const {\n level,\n timestamp = false,\n pretty: {\n // options for pretty printing\n enable: prettyEnable = true,\n colorize: prettyColorize = true,\n includeLevel: prettyIncludeLevel = false,\n } = {},\n streams = [],\n } = options;\n\n // configure pretty printing stream, if enabled\n const prettyStream = prettyEnable\n ? pretty({\n colorize: prettyColorize,\n ignore: 'pid,hostname',\n customPrettifiers: prettyIncludeLevel ? undefined : { level: () => '' },\n // these colors only apply to the log level which we may be hiding above\n // support for custom colors in the message itself is not yet supported\n // https://github.com/pinojs/pino-pretty/issues/430\n // https://github.com/pinojs/pino-pretty/issues/524\n // https://github.com/pinojs/pino-pretty/pull/611\n customColors: {\n trace: 'grey',\n debug: 'grey',\n info: 'white',\n warn: 'yellow',\n error: 'red',\n fatal: 'magenta',\n } satisfies Record<Level, string>,\n })\n : undefined;\n\n // create and return the logger\n return pino(\n {\n level: level || process.env.LOG_LEVEL || (process.env.NODE_ENV === 'production' ? 'warn' : 'debug'),\n timestamp,\n },\n pino.multistream([\n // add streams conditionally\n ...(prettyStream ? [prettyStream] : []),\n ...streams,\n ]),\n );\n}\n\n/** Default logger instance */\nexport const logger = create();\n"],"mappings":";;;;;;;;;AAkDA,SAAgB,OAAO,UAA+B,EAAE,EAAE;CACxD,MAAM,EACJ,OACA,YAAY,OACZ,QAAQ,EAEN,QAAQ,eAAe,MACvB,UAAU,iBAAiB,MAC3B,cAAc,qBAAqB,UACjC,EAAE,EACN,UAAU,EAAE,KACV;CAGJ,MAAM,eAAe,eACjB,OAAO;EACL,UAAU;EACV,QAAQ;EACR,mBAAmB,qBAAqB,SAAY,EAAE,aAAa,IAAI;EAMvE,cAAc;GACZ,OAAO;GACP,OAAO;GACP,MAAM;GACN,MAAM;GACN,OAAO;GACP,OAAO;GACR;EACF,CAAC,GACF;AAGJ,QAAO,KACL;EACE,OAAO,SAAS,QAAQ,IAAI,cAAc,QAAQ,IAAI,aAAa,eAAe,SAAS;EAC3F;EACD,EACD,KAAK,YAAY,CAEf,GAAI,eAAe,CAAC,aAAa,GAAG,EAAE,EACtC,GAAG,QACJ,CAAC,CACH;;;AAIH,MAAa,SAAS,QAAQ"}
|