@bagelink/sdk 0.0.1276 → 0.0.1286

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.
Files changed (40) hide show
  1. package/bin/utils.ts +1 -1
  2. package/dist/chunks/acorn.cjs +20 -0
  3. package/dist/chunks/acorn.mjs +17 -0
  4. package/dist/chunks/angular.cjs +6 -0
  5. package/dist/chunks/angular.mjs +3 -0
  6. package/dist/chunks/babel.cjs +20 -0
  7. package/dist/chunks/babel.mjs +17 -0
  8. package/dist/chunks/estree.cjs +43 -0
  9. package/dist/chunks/estree.mjs +38 -0
  10. package/dist/chunks/flow.cjs +24 -0
  11. package/dist/chunks/flow.mjs +21 -0
  12. package/dist/chunks/glimmer.cjs +37 -0
  13. package/dist/chunks/glimmer.mjs +32 -0
  14. package/dist/chunks/graphql.cjs +37 -0
  15. package/dist/chunks/graphql.mjs +31 -0
  16. package/dist/chunks/html.cjs +30 -0
  17. package/dist/chunks/html.mjs +24 -0
  18. package/dist/chunks/index.cjs +1451 -0
  19. package/dist/chunks/index.mjs +1441 -0
  20. package/dist/chunks/jiti.cjs +371 -0
  21. package/dist/chunks/jiti.mjs +342 -0
  22. package/dist/chunks/markdown.cjs +71 -0
  23. package/dist/chunks/markdown.mjs +65 -0
  24. package/dist/chunks/meriyah.cjs +9 -0
  25. package/dist/chunks/meriyah.mjs +6 -0
  26. package/dist/chunks/postcss.cjs +62 -0
  27. package/dist/chunks/postcss.mjs +56 -0
  28. package/dist/chunks/typescript.cjs +25 -0
  29. package/dist/chunks/typescript.mjs +22 -0
  30. package/dist/chunks/yaml.cjs +169 -0
  31. package/dist/chunks/yaml.mjs +163 -0
  32. package/dist/index.cjs +52 -626
  33. package/dist/index.d.cts +3 -1
  34. package/dist/index.d.mts +3 -1
  35. package/dist/index.d.ts +3 -1
  36. package/dist/index.mjs +46 -621
  37. package/dist/shared/sdk.BJ23wlaP.mjs +182492 -0
  38. package/dist/shared/sdk.UmZR6apR.cjs +182547 -0
  39. package/package.json +2 -2
  40. package/src/index.ts +2 -0
package/dist/index.cjs CHANGED
@@ -1,628 +1,54 @@
1
1
  'use strict';
2
2
 
3
- const axios$1 = require('axios');
4
-
5
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
6
-
7
- const axios__default = /*#__PURE__*/_interopDefaultCompat(axios$1);
8
-
9
- function toCamelCase(str) {
10
- return str?.replaceAll(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toLowerCase()) || str || "";
11
- }
12
- function toPascalCase(str) {
13
- return str?.replaceAll(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toUpperCase()) || str || "";
14
- }
15
- function formatType(typeName) {
16
- typeName = typeName.replaceAll("-", "").replaceAll(/post|put$/gi, "").replaceAll(/^body_/gi, "");
17
- return toPascalCase(typeName);
18
- }
19
- function resolveReference(ref) {
20
- const t = ref.split("/").pop();
21
- if (!t) return "any";
22
- return formatType(t);
23
- }
24
- function schemaToType(schema) {
25
- if (!schema) return "any";
26
- if (schema.anyOf) {
27
- let _t = schema.anyOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
28
- if (_t === "" || _t === "null") _t = "any";
29
- return _t;
30
- }
31
- if (schema.allOf) {
32
- return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
33
- }
34
- if (schema.$ref) return resolveReference(schema.$ref);
35
- switch (schema.type) {
36
- case "object":
37
- return "{ [key: string]: any }";
38
- case "string":
39
- return "string";
40
- case "integer":
41
- return "number";
42
- case "number":
43
- return "number";
44
- case "boolean":
45
- return "boolean";
46
- case "array":
47
- return `${schemaToType(schema.items)}[]`;
48
- case "undefined":
49
- return "undefined";
50
- case "null":
51
- return "null";
52
- case undefined:
53
- return "any";
54
- default:
55
- console.log("Unknown type", schema.type);
56
- return "any";
57
- }
58
- }
59
- function isOptional(schema) {
60
- const type = schemaToType(schema);
61
- const splitType = type.split(/\s+\|\s+/);
62
- const includesNull = splitType.includes("null");
63
- const includesUndefined = splitType.includes("undefined");
64
- return includesNull || includesUndefined || schema.default !== undefined;
65
- }
66
- function cleanOptionals(str) {
67
- return str.split(" | ").filter((t) => t !== "null" && t !== "undefined").join(" | ");
68
- }
69
- function formatVarType({
70
- varName,
71
- schema,
72
- required = false,
73
- defaultValue
74
- }) {
75
- let type = schemaToType(schema);
76
- type = cleanOptionals(type);
77
- let defaultStr = "";
78
- if (defaultValue) {
79
- if (typeof defaultValue === "string") {
80
- defaultStr = ` = '${defaultValue}'`;
81
- } else if (typeof defaultValue === "object") {
82
- defaultStr = ` = ${JSON.stringify(defaultValue)}`;
83
- } else {
84
- defaultStr = ` = ${defaultValue}`;
85
- }
86
- }
87
- let optionalStr = !required && isOptional(schema) ? "?" : "";
88
- if (defaultStr) optionalStr = "";
89
- return `${varName}${optionalStr}: ${type}${defaultStr}`;
90
- }
91
- function cleanPath(path) {
92
- return path.split("/").filter((p) => p && !/\{|\}/.test(p)).join("/");
93
- }
94
-
95
- const allTypes = [];
96
- const primitiveTypes = [
97
- "string",
98
- "number",
99
- "boolean",
100
- "null",
101
- "void",
102
- "any",
103
- "Record<string, any>",
104
- "undefined",
105
- "{ [key: string]: any }"
106
- ];
107
- function collectTypeForImportStatement(typeName) {
108
- typeName = typeName.trim().replace("[]", "");
109
- if (typeName.includes("|")) {
110
- typeName.split("|").forEach((singleType) => {
111
- collectTypeForImportStatement(singleType);
112
- });
113
- return;
114
- }
115
- const isPrimitive = primitiveTypes.includes(typeName);
116
- typeName = formatType(typeName);
117
- if (!typeName || isPrimitive) return;
118
- if (!allTypes.includes(typeName)) allTypes.push(typeName);
119
- }
120
- function schemaToTypeWithCollection(schema) {
121
- const type = schemaToType(schema);
122
- collectTypeForImportStatement(type);
123
- return type;
124
- }
125
- function getResponseType(response) {
126
- const mediaTypeObject = response.content?.["application/json"];
127
- if (!mediaTypeObject || !mediaTypeObject.schema) return;
128
- const responseType = schemaToTypeWithCollection(mediaTypeObject.schema);
129
- return responseType;
130
- }
131
- function generateResponseType(responses) {
132
- if (!responses) return "";
133
- const types = [];
134
- for (const [statusCode, response] of Object.entries(responses)) {
135
- if (statusCode.startsWith("2")) {
136
- const responseType = getResponseType(response);
137
- if (responseType && responseType !== "any") {
138
- types.push(responseType);
139
- }
140
- }
141
- }
142
- return types.join(" | ");
143
- }
144
- function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload) {
145
- if (allParams === "undefined") allParams = "";
146
- let axiosFunction = `async (${allParams})${responseTypeStr} => {`;
147
- if (requestBodyPayload === "formData") {
148
- const paramStr = parameters?.config?.params ? `params: {${parameters.config.params}}` : "";
149
- axiosFunction += `
150
- const formData = new FormData()
151
- formData.append('upload', file)
152
- return axios.${method}(${formattedPath}, formData, {
153
- headers: { 'Content-Type': 'multipart/form-data' },
154
- onUploadProgress: options?.onUploadProgress${paramStr ? `,
155
- ${paramStr}` : ""}
156
- })`;
157
- } else {
158
- const paramStr = parameters?.config?.params ? `, { params: {${parameters.config.params}} }` : "";
159
- const bodyVar = requestBodyPayload ? `${requestBodyPayload}` : "{}";
160
- axiosFunction += `return axios.${method}(${formattedPath}${["get", "delete"].includes(method) ? paramStr : `, ${bodyVar}${paramStr}`})`;
161
- }
162
- axiosFunction += "}";
163
- return axiosFunction;
164
- }
165
- const pathParamRegex = /\{([^}]+)\}/g;
166
- function getParamsFromPath(path) {
167
- const params = path.match(pathParamRegex)?.map((p) => p.slice(1, -1));
168
- return params;
169
- }
170
- function formatPathWithParams(path) {
171
- const params = getParamsFromPath(path);
172
- const formattedPath = params ? `\`${path.replace(pathParamRegex, (v) => `$${toCamelCase(v)}`)}\`` : `'${path}'`;
173
- return formattedPath;
174
- }
175
- function generateRequestBody(requestBody) {
176
- if (!requestBody?.content)
177
- return { requestBodyParam: "", requestBodyPayload: "" };
178
- const { content } = requestBody;
179
- const multipartFormData = content["multipart/form-data"] || {};
180
- if (multipartFormData.schema?.$ref?.includes("Body_upload_files")) {
181
- return {
182
- requestBodyParam: "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }",
183
- requestBodyPayload: "formData"
184
- };
185
- }
186
- const jsonContent = requestBody.content["application/json"];
187
- if (!jsonContent || !jsonContent.schema) {
188
- return { requestBodyParam: "", requestBodyPayload: "" };
189
- }
190
- const bodySchema = jsonContent.schema;
191
- const requestBodyType = schemaToType(bodySchema);
192
- collectTypeForImportStatement(requestBodyType);
193
- const requestBodyPayload = toCamelCase(bodySchema.title) || toCamelCase(requestBodyType) || "requestBody";
194
- const requestBodyParam = formatVarType({
195
- varName: requestBodyPayload,
196
- schema: bodySchema,
197
- defaultValue: bodySchema.default
198
- });
199
- return { requestBodyParam, requestBodyPayload };
200
- }
201
- function combineAllParams(parameters, requestBodyParam) {
202
- let allParamsArray = [];
203
- if (parameters && parameters.params)
204
- allParamsArray = parameters.params.split(",").map((p) => p.trim());
205
- if (requestBodyParam) allParamsArray.push(requestBodyParam.trim());
206
- allParamsArray = allParamsArray.filter((p) => p).sort((a, b) => (a.includes("?") ? 1 : -1) - (b.includes("?") ? 1 : -1));
207
- return allParamsArray.join(", ");
208
- }
209
- function generateFunctionParameters(params, isFileUpload = false) {
210
- if (!params?.length) return {};
211
- if (isFileUpload) {
212
- return {
213
- config: {
214
- params: "dir_path: options?.dirPath, tags: options?.tags"
215
- },
216
- params: ""
217
- // Empty string to ensure file is the first parameter
218
- };
219
- }
220
- const functionParams = [];
221
- const paramList = [];
222
- for (const param of params) {
223
- const paramType = schemaToType(param.schema);
224
- collectTypeForImportStatement(paramType);
225
- const paramName = param.name;
226
- const varName = toCamelCase(param.name);
227
- if (param.in === "path" || param.in === "query" || param.in === "header") {
228
- functionParams.push(
229
- formatVarType({
230
- varName,
231
- schema: param.schema,
232
- required: param.required,
233
- defaultValue: param.schema.default
234
- })
235
- );
236
- }
237
- if (param.in === "query" || param.in === "header") {
238
- paramList.push(
239
- paramName === varName ? paramName : `'${paramName}': ${varName}`
240
- );
241
- }
242
- }
243
- return {
244
- params: functionParams.join(", "),
245
- config: paramList.length ? { params: paramList.join(", ") } : {}
246
- };
247
- }
248
- function generateFunctionForOperation(method, path, operation) {
249
- if (!operation) return "";
250
- const isFileUpload = operation.requestBody?.content["multipart/form-data"]?.schema?.$ref?.includes("Body_upload_files");
251
- const parameters = generateFunctionParameters(
252
- operation.parameters,
253
- isFileUpload
254
- );
255
- const { requestBodyParam, requestBodyPayload } = generateRequestBody(
256
- operation.requestBody
257
- );
258
- const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
259
- const responseType = generateResponseType(operation.responses);
260
- const responseTypeStr = responseType ? `: Promise<AxiosResponse<${responseType}>>` : "";
261
- return generateAxiosFunction(
262
- method,
263
- formatPathWithParams(path),
264
- allParams,
265
- responseTypeStr,
266
- parameters,
267
- requestBodyPayload
268
- );
269
- }
270
- const generateRandomString = () => Math.random().toString(36).slice(7);
271
- const DOUBLE_QUOTE_REGEX = /"([^"]+)":/g;
272
- function fileTemplate(tsString, typeForImport, baseURL) {
273
- const templateCode = `import ax from 'axios';
274
- import type { AxiosResponse } from 'axios';
275
- import type {${typeForImport.join(", ")}} from './types.d';
276
-
277
- interface UploadOptions {
278
- onUploadProgress?: (progressEvent: any) => void
279
- dirPath?: string
280
- tags?: string[]
281
- }
282
-
283
- export const axios = ax.create({baseURL:${baseURL}});
284
- ${tsString}`;
285
- return templateCode.replace(DOUBLE_QUOTE_REGEX, "$1:");
286
- }
287
- const functionsInventory = {};
288
- const pathOperations = [];
289
- function hasConflict(path, method) {
290
- const cleanPathName = path.split("/").filter((p) => p && !/\{|\}/.test(p)).join("/");
291
- const matchingPaths = pathOperations.filter(
292
- (p) => p.path === cleanPathName && p.method === method
293
- );
294
- pathOperations.push({ path: cleanPathName, method });
295
- return matchingPaths.length > 0;
296
- }
297
- function createFunctionPlaceholder(path, method, operation) {
298
- const funcID = generateRandomString();
299
- functionsInventory[funcID] = generateFunctionForOperation(
300
- method,
301
- path,
302
- operation
303
- );
304
- return funcID;
305
- }
306
- function handlePathSegment(path, operation, existingObj = {}) {
307
- const methods = Object.keys(operation);
308
- const obj = {};
309
- for (const method of methods) {
310
- let functionName = method.toLowerCase();
311
- if (hasConflict(path, method)) {
312
- const params = getParamsFromPath(path);
313
- functionName += params ? `By${toPascalCase(params.pop() || "")}` : "All";
314
- }
315
- obj[functionName] = createFunctionPlaceholder(
316
- path,
317
- method,
318
- operation[method]
319
- );
320
- }
321
- return { ...obj, ...existingObj };
322
- }
323
- function generateFunctions(paths, baseUrl) {
324
- let tsString = "";
325
- const body = {};
326
- const allPathsClean = Object.keys(paths).map(cleanPath);
327
- for (const [path, operation] of Object.entries(paths)) {
328
- const splitPath = path.split("/").filter((p) => p && !/\{|\}/.test(p));
329
- splitPath.reduce((acc, key, index, array) => {
330
- const objFuncKey = toCamelCase(key);
331
- if (!objFuncKey) return acc;
332
- const methods = Object.keys(operation);
333
- if (index === array.length - 1 && methods.length === 1 && allPathsClean.filter((p) => p === cleanPath(path)).length === 1) {
334
- const method = methods[0];
335
- const opp = { ...operation }[method];
336
- acc[objFuncKey] = createFunctionPlaceholder(path, methods[0], opp);
337
- } else if (index === array.length - 1) {
338
- acc[objFuncKey] = handlePathSegment(path, operation, acc[objFuncKey]);
339
- } else if (!acc[objFuncKey] || typeof acc[objFuncKey] !== "object") {
340
- acc[objFuncKey] = {};
341
- }
342
- return acc[objFuncKey];
343
- }, body);
344
- }
345
- for (const [parent, object] of Object.entries(body)) {
346
- tsString += `export const ${parent} = ${JSON.stringify(object, undefined, 2)};
347
- `;
348
- }
349
- Object.entries(functionsInventory).forEach(([key, value]) => {
350
- tsString = tsString.replace(`"${key}"`, value);
351
- });
352
- tsString = fileTemplate(tsString, allTypes, baseUrl);
353
- return tsString;
354
- }
355
-
356
- function generateTypes(schemas) {
357
- return Object.entries(schemas).map(([typeName, schema]) => {
358
- typeName = formatType(typeName);
359
- if (schema.enum) {
360
- return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
361
- `;
362
- }
363
- if (schema.type === "array" && schema.items) {
364
- return `export type ${typeName} = ${schemaToType(schema.items)}[];
365
- `;
366
- }
367
- if (!schema.properties) {
368
- return "";
369
- }
370
- const properties = Object.entries(schema.properties).map(([key, value]) => {
371
- const varType = formatVarType({ varName: key, schema: value });
372
- return ` ${varType}`;
373
- }).join(";\n ");
374
- return `export type ${typeName} = {
375
- ${properties};
376
- };
377
- `;
378
- }).join("\n");
379
- }
380
-
381
- const basicAuthHeader = { Authorization: "Basic YmFnZWxfdXNlcm5hbWU6Tm90U2VjdXJlQGJhZ2Vs" };
382
- const index = async (openApiUrl, baseUrl) => {
383
- try {
384
- const { data: openApi } = await axios__default.get(openApiUrl, { headers: basicAuthHeader });
385
- const schemas = openApi.components?.schemas;
386
- if (!schemas) throw new Error("No schemas found in OpenAPI document");
387
- const types = generateTypes(schemas);
388
- const { paths } = openApi;
389
- if (!paths) throw new Error("No paths found in OpenAPI document");
390
- const code = generateFunctions(paths, baseUrl);
391
- return { types, code };
392
- } catch (error) {
393
- throw new Error(error);
394
- }
395
- };
396
-
397
- const axios = axios__default.create({
398
- withCredentials: true
399
- });
400
- class DataRequest {
401
- data_table;
402
- bagel;
403
- itemID;
404
- _filter = {};
405
- constructor(table, bagel) {
406
- this.data_table = table;
407
- this.bagel = bagel;
408
- this.itemID = "";
409
- }
410
- async post(item) {
411
- if (!this.data_table) throw new Error("Data table not set");
412
- const { data } = await axios.post(`/data/${this.data_table}`, item);
413
- return data;
414
- }
415
- filter(filter) {
416
- this._filter = filter;
417
- return this;
418
- }
419
- async get() {
420
- if (!this.data_table) throw new Error("Data table not set");
421
- const filterStr = Object.keys(this._filter).length > 0 ? `?filter={${Object.entries(this._filter).map(([k, v]) => `${k}:${v}`).join(",")}}` : "";
422
- const url = `/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ""}${filterStr}`;
423
- try {
424
- const { data } = await axios.get(url);
425
- return data;
426
- } catch (err) {
427
- console.log(err);
428
- this.bagel.onError?.(err);
429
- return undefined;
430
- }
431
- }
432
- item(id) {
433
- this.itemID = id;
434
- return this;
435
- }
436
- async delete() {
437
- if (!this.data_table) throw new Error("Data table not set");
438
- const { data } = await axios.delete(
439
- `/data/${this.data_table}/${this.itemID}`
440
- );
441
- return data;
442
- }
443
- async put(updatedItem) {
444
- const { data_table, itemID } = this;
445
- if (!data_table) throw new Error("Data table not set");
446
- if (!itemID) throw new Error("Item ID not set");
447
- const { data } = await axios.put(
448
- `/data/${data_table}/${itemID}`,
449
- updatedItem
450
- );
451
- return data;
452
- }
453
- }
454
- function responses(key) {
455
- const res = {
456
- LOGIN_BAD_CREDENTIALS: "Invalid username or password",
457
- RESET_PASSWORD_BAD_TOKEN: "This reset password link is invalid or expired."
458
- };
459
- return res[key] || key;
460
- }
461
- class BagelAuth {
462
- constructor(bagel) {
463
- this.bagel = bagel;
464
- this.bagel = bagel;
465
- }
466
- user = undefined;
467
- async validateUser() {
468
- try {
469
- const { data: usr } = await axios.get("/users/me", {
470
- withCredentials: true
471
- });
472
- this.user = usr;
473
- return usr;
474
- } catch {
475
- }
476
- }
477
- async resetPassword(ctx) {
478
- return this.bagel.post("auth/reset-password", ctx).catch((err) => {
479
- throw responses(err.response?.data?.detail);
480
- });
481
- }
482
- async forgotPassword(email) {
483
- try {
484
- await this.bagel.post("auth/forgot-password", { email });
485
- } catch (err) {
486
- throw responses(err?.response?.data?.detail);
487
- }
488
- }
489
- async login(user) {
490
- const formData = new FormData();
491
- formData.append("username", user.email || "");
492
- formData.append("password", user.password || "");
493
- console.log("Logging in");
494
- try {
495
- await axios.post("/auth/cookie/login", formData, {
496
- headers: {
497
- "withCredentials": true,
498
- "Content-Type": "multipart/form-data"
499
- }
500
- });
501
- axios.defaults.withCredentials = true;
502
- return this.validateUser();
503
- } catch (err) {
504
- throw responses(err.response?.data?.detail || "LOGIN_BAD_CREDENTIALS");
505
- }
506
- }
507
- async logout() {
508
- try {
509
- await axios.post("/auth/cookie/logout");
510
- } catch (err) {
511
- this.bagel.onError?.(err);
512
- console.log(err);
513
- }
514
- this.user = undefined;
515
- }
516
- async acceptInvite(token, user) {
517
- await axios.post(`/auth/accept-invite/${token}`, user);
518
- await this.login(user);
519
- }
520
- async register(user, errors) {
521
- try {
522
- await axios.post("/auth/register", user);
523
- return this.login(user);
524
- } catch (err) {
525
- console.error(err);
526
- errors.email = err.response.data.detail;
527
- throw err;
528
- }
529
- }
530
- }
531
- class Bagel {
532
- host;
533
- fileBaseUrl;
534
- onError;
535
- constructor({ host, fileBaseUrl, onError }) {
536
- this.host = host?.replace(/\/$/, "");
537
- this.fileBaseUrl = fileBaseUrl?.replace(/\/$/, "");
538
- if (!this.host) {
539
- return this;
540
- }
541
- axios.defaults.baseURL = this.host;
542
- this.onError = onError;
543
- }
544
- read_table = undefined;
545
- data(table) {
546
- return new DataRequest(table, this);
547
- }
548
- auth = new BagelAuth(this);
549
- _endpointCleaner(endpoint) {
550
- const url = `${endpoint.replace(/^\//, "").replaceAll(/\/$/g, "")}`;
551
- return url;
552
- }
553
- async api(endpoint, query) {
554
- if (query) {
555
- const queryParams = Object.entries(query).map(([key, value]) => `${key}=${value}`).join("&");
556
- endpoint = `${endpoint}?${queryParams}`;
557
- }
558
- return axios.get(`/api/${endpoint}`).then(({ data }) => data);
559
- }
560
- async get(endpoint, query) {
561
- this._setAuthorization();
562
- endpoint = this._endpointCleaner(endpoint);
563
- if (/undefined|null/.test(endpoint)) throw new Error(`Invalid endpoint: ${endpoint}`);
564
- if (query) {
565
- const queryParams = Object.entries(query).filter(([_, value]) => !!value).map(([key, value]) => `${key}=${value}`).join("&");
566
- if (queryParams) endpoint = `${endpoint}?${queryParams}`;
567
- }
568
- const url = `/${endpoint}`;
569
- return axios.get(url).then(({ data }) => data).catch((err) => {
570
- this.onError?.(err);
571
- throw err;
572
- });
573
- }
574
- async delete(endpoint) {
575
- this._setAuthorization();
576
- endpoint = this._endpointCleaner(endpoint);
577
- return axios.delete(`/${endpoint}`).then(({ data }) => data).catch((err) => {
578
- this.onError?.(err);
579
- throw err;
580
- });
581
- }
582
- async put(endpoint, payload) {
583
- endpoint = this._endpointCleaner(endpoint);
584
- this._setAuthorization();
585
- return axios.put(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
586
- this.onError?.(err);
587
- throw err;
588
- });
589
- }
590
- async patch(endpoint, payload = {}) {
591
- endpoint = this._endpointCleaner(endpoint);
592
- return axios.patch(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
593
- this.onError?.(err);
594
- throw err;
595
- });
596
- }
597
- _setAuthorization() {
598
- const Authorization = localStorage.getItem("access_token");
599
- if (Authorization) {
600
- axios.defaults.headers.common.Authorization = `Bearer ${Authorization}`;
601
- }
602
- }
603
- async post(endpoint, payload = {}) {
604
- this._setAuthorization();
605
- endpoint = this._endpointCleaner(endpoint);
606
- return axios.post(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
607
- this.onError?.(err);
608
- throw err;
609
- });
610
- }
611
- async uploadFile(file, options) {
612
- this._setAuthorization();
613
- const formData = new FormData();
614
- formData.append("file", file);
615
- let url = "/static_files/upload";
616
- if (options?.topic) url = `/static_files/upload?topic=${options.topic}`;
617
- const { data } = await axios.post(url, formData, {
618
- headers: {
619
- "Content-Type": "multipart/form-data"
620
- },
621
- onUploadProgress: options?.onUploadProgress
622
- });
623
- return data;
624
- }
625
- }
626
-
627
- exports.Bagel = Bagel;
628
- exports.openAPI = index;
3
+ require('axios');
4
+ const index = require('./shared/sdk.UmZR6apR.cjs');
5
+ require('node:fs');
6
+ require('node:path');
7
+ require('node:process');
8
+ require('node:fs/promises');
9
+ require('util');
10
+ require('path');
11
+ require('tty');
12
+ require('os');
13
+ require('fs');
14
+ require('module');
15
+ require('assert');
16
+ require('url');
17
+ require('node:url');
18
+ require('crypto');
19
+ require('events');
20
+ require('node:util');
21
+ require('node:assert');
22
+ require('process');
23
+ require('fs/promises');
24
+ require('v8');
25
+ require('node:perf_hooks');
26
+ require('node:module');
27
+ require('node:crypto');
28
+ require('child_process');
29
+ require('node:child_process');
30
+ require('node:http');
31
+ require('node:https');
32
+ require('net');
33
+ require('http');
34
+ require('stream');
35
+ require('node:os');
36
+ require('node:net');
37
+ require('node:dns');
38
+ require('node:readline');
39
+ require('node:buffer');
40
+ require('node:events');
41
+ require('node:v8');
42
+ require('node:worker_threads');
43
+ require('zlib');
44
+ require('buffer');
45
+ require('https');
46
+ require('tls');
47
+ require('node:querystring');
48
+ require('node:zlib');
49
+
50
+
51
+
52
+ exports.Bagel = index.Bagel;
53
+ exports.formatAPIErrorMessage = index.formatAPIErrorMessage;
54
+ exports.openAPI = index.index;
package/dist/index.d.cts CHANGED
@@ -4,6 +4,8 @@ interface OpenAPIResponse {
4
4
  }
5
5
  declare const _default: (openApiUrl: string, baseUrl: string) => Promise<OpenAPIResponse>;
6
6
 
7
+ declare function formatAPIErrorMessage(error: any): any;
8
+
7
9
  type Tables = '';
8
10
  type TableToTypeMapping = Record<Tables, any>;
9
11
 
@@ -106,4 +108,4 @@ declare class Bagel {
106
108
  uploadFile<T = any>(file: File, options?: UploadOptions): Promise<T>;
107
109
  }
108
110
 
109
- export { Bagel, type TableToTypeMapping, type Tables, type User, _default as openAPI };
111
+ export { Bagel, type TableToTypeMapping, type Tables, type User, formatAPIErrorMessage, _default as openAPI };