@bagelink/sdk 0.0.1133 → 0.0.1135

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/index.cjs CHANGED
@@ -18,20 +18,24 @@ function formatType(typeName) {
18
18
  }
19
19
  function resolveReference(ref) {
20
20
  const t = ref.split("/").pop();
21
- if (!t) return "any";
21
+ if (!t)
22
+ return "any";
22
23
  return formatType(t);
23
24
  }
24
25
  function schemaToType(schema) {
25
- if (!schema) return "any";
26
+ if (!schema)
27
+ return "any";
26
28
  if (schema.anyOf) {
27
29
  let _t = schema.anyOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
28
- if (_t === "" || _t === "null") _t = "any";
30
+ if (_t === "" || _t === "null")
31
+ _t = "any";
29
32
  return _t;
30
33
  }
31
34
  if (schema.allOf) {
32
35
  return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
33
36
  }
34
- if (schema.$ref) return resolveReference(schema.$ref);
37
+ if (schema.$ref)
38
+ return resolveReference(schema.$ref);
35
39
  switch (schema.type) {
36
40
  case "object":
37
41
  return "{ [key: string]: any }";
@@ -49,7 +53,7 @@ function schemaToType(schema) {
49
53
  return "undefined";
50
54
  case "null":
51
55
  return "null";
52
- case undefined:
56
+ case void 0:
53
57
  return "any";
54
58
  default:
55
59
  console.log("Unknown type", schema.type);
@@ -61,7 +65,7 @@ function isOptional(schema) {
61
65
  const splitType = type.split(/\s+\|\s+/);
62
66
  const includesNull = splitType.includes("null");
63
67
  const includesUndefined = splitType.includes("undefined");
64
- return includesNull || includesUndefined || schema.default !== undefined;
68
+ return includesNull || includesUndefined || schema.default !== void 0;
65
69
  }
66
70
  function cleanOptionals(str) {
67
71
  return str.split(" | ").filter((t) => t !== "null" && t !== "undefined").join(" | ");
@@ -83,7 +87,8 @@ function formatVarType({
83
87
  }
84
88
  }
85
89
  let optionalStr = !required && isOptional(schema) ? "?" : "";
86
- if (defaultStr) optionalStr = "";
90
+ if (defaultStr)
91
+ optionalStr = "";
87
92
  return `${varName}${optionalStr}: ${type}${defaultStr}`;
88
93
  }
89
94
  function cleanPath(path) {
@@ -112,8 +117,10 @@ function collectTypeForImportStatement(typeName) {
112
117
  }
113
118
  const isPrimitive = primitiveTypes.includes(typeName);
114
119
  typeName = formatType(typeName);
115
- if (!typeName || isPrimitive) return;
116
- if (!allTypes.includes(typeName)) allTypes.push(typeName);
120
+ if (!typeName || isPrimitive)
121
+ return;
122
+ if (!allTypes.includes(typeName))
123
+ allTypes.push(typeName);
117
124
  }
118
125
  function schemaToTypeWithCollection(schema) {
119
126
  const type = schemaToType(schema);
@@ -122,12 +129,14 @@ function schemaToTypeWithCollection(schema) {
122
129
  }
123
130
  function getResponseType(response) {
124
131
  const mediaTypeObject = response.content?.["application/json"];
125
- if (!mediaTypeObject || !mediaTypeObject.schema) return;
132
+ if (!mediaTypeObject || !mediaTypeObject.schema)
133
+ return;
126
134
  const responseType = schemaToTypeWithCollection(mediaTypeObject.schema);
127
135
  return responseType;
128
136
  }
129
137
  function generateResponseType(responses) {
130
- if (!responses) return "";
138
+ if (!responses)
139
+ return "";
131
140
  const types = [];
132
141
  for (const [statusCode, response] of Object.entries(responses)) {
133
142
  if (statusCode.startsWith("2")) {
@@ -140,7 +149,8 @@ function generateResponseType(responses) {
140
149
  return types.join(" | ");
141
150
  }
142
151
  function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload) {
143
- if (allParams === "undefined") allParams = "";
152
+ if (allParams === "undefined")
153
+ allParams = "";
144
154
  let axiosFunction = `async (${allParams})${responseTypeStr} => {`;
145
155
  if (requestBodyPayload === "formData") {
146
156
  const paramStr = parameters?.config?.params ? `params: {${parameters.config.params}}` : "";
@@ -200,12 +210,14 @@ function combineAllParams(parameters, requestBodyParam) {
200
210
  let allParamsArray = [];
201
211
  if (parameters && parameters.params)
202
212
  allParamsArray = parameters.params.split(",").map((p) => p.trim());
203
- if (requestBodyParam) allParamsArray.push(requestBodyParam.trim());
213
+ if (requestBodyParam)
214
+ allParamsArray.push(requestBodyParam.trim());
204
215
  allParamsArray = allParamsArray.filter((p) => p).sort((a, b) => (a.includes("?") ? 1 : -1) - (b.includes("?") ? 1 : -1));
205
216
  return allParamsArray.join(", ");
206
217
  }
207
218
  function generateFunctionParameters(params, isFileUpload = false) {
208
- if (!params?.length) return {};
219
+ if (!params?.length)
220
+ return {};
209
221
  if (isFileUpload) {
210
222
  return {
211
223
  config: {
@@ -244,7 +256,8 @@ function generateFunctionParameters(params, isFileUpload = false) {
244
256
  };
245
257
  }
246
258
  function generateFunctionForOperation(method, path, operation) {
247
- if (!operation) return "";
259
+ if (!operation)
260
+ return "";
248
261
  const isFileUpload = operation.requestBody?.content["multipart/form-data"]?.schema?.$ref?.includes("Body_upload_files");
249
262
  const parameters = generateFunctionParameters(
250
263
  operation.parameters,
@@ -326,7 +339,8 @@ function generateFunctions(paths, baseUrl) {
326
339
  const splitPath = path.split("/").filter((p) => p && !/\{|\}/.test(p));
327
340
  splitPath.reduce((acc, key, index, array) => {
328
341
  const objFuncKey = toCamelCase(key);
329
- if (!objFuncKey) return acc;
342
+ if (!objFuncKey)
343
+ return acc;
330
344
  const methods = Object.keys(operation);
331
345
  if (index === array.length - 1 && methods.length === 1 && allPathsClean.filter((p) => p === cleanPath(path)).length === 1) {
332
346
  const method = methods[0];
@@ -341,7 +355,7 @@ function generateFunctions(paths, baseUrl) {
341
355
  }, body);
342
356
  }
343
357
  for (const [parent, object] of Object.entries(body)) {
344
- tsString += `export const ${parent} = ${JSON.stringify(object, undefined, 2)};
358
+ tsString += `export const ${parent} = ${JSON.stringify(object, void 0, 2)};
345
359
  `;
346
360
  }
347
361
  Object.entries(functionsInventory).forEach(([key, value]) => {
@@ -381,10 +395,12 @@ const index = async (openApiUrl, baseUrl) => {
381
395
  try {
382
396
  const { data: openApi } = await axios__default.get(openApiUrl, { headers: basicAuthHeader });
383
397
  const schemas = openApi.components?.schemas;
384
- if (!schemas) throw new Error("No schemas found in OpenAPI document");
398
+ if (!schemas)
399
+ throw new Error("No schemas found in OpenAPI document");
385
400
  const types = generateTypes(schemas);
386
401
  const { paths } = openApi;
387
- if (!paths) throw new Error("No paths found in OpenAPI document");
402
+ if (!paths)
403
+ throw new Error("No paths found in OpenAPI document");
388
404
  const code = generateFunctions(paths, baseUrl);
389
405
  return { types, code };
390
406
  } catch (error) {
@@ -392,21 +408,28 @@ const index = async (openApiUrl, baseUrl) => {
392
408
  }
393
409
  };
394
410
 
411
+ var __defProp = Object.defineProperty;
412
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
413
+ var __publicField = (obj, key, value) => {
414
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
415
+ return value;
416
+ };
395
417
  const axios = axios__default.create({
396
418
  withCredentials: true
397
419
  });
398
420
  class DataRequest {
399
- data_table;
400
- bagel;
401
- itemID;
402
- _filter = {};
403
421
  constructor(table, bagel) {
422
+ __publicField(this, "data_table");
423
+ __publicField(this, "bagel");
424
+ __publicField(this, "itemID");
425
+ __publicField(this, "_filter", {});
404
426
  this.data_table = table;
405
427
  this.bagel = bagel;
406
428
  this.itemID = "";
407
429
  }
408
430
  async post(item) {
409
- if (!this.data_table) throw new Error("Data table not set");
431
+ if (!this.data_table)
432
+ throw new Error("Data table not set");
410
433
  const { data } = await axios.post(`/data/${this.data_table}`, item);
411
434
  return data;
412
435
  }
@@ -415,7 +438,8 @@ class DataRequest {
415
438
  return this;
416
439
  }
417
440
  async get() {
418
- if (!this.data_table) throw new Error("Data table not set");
441
+ if (!this.data_table)
442
+ throw new Error("Data table not set");
419
443
  const filterStr = Object.keys(this._filter).length > 0 ? `?filter={${Object.entries(this._filter).map(([k, v]) => `${k}:${v}`).join(",")}}` : "";
420
444
  const url = `/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ""}${filterStr}`;
421
445
  try {
@@ -424,7 +448,7 @@ class DataRequest {
424
448
  } catch (err) {
425
449
  console.log(err);
426
450
  this.bagel.onError?.(err);
427
- return undefined;
451
+ return void 0;
428
452
  }
429
453
  }
430
454
  item(id) {
@@ -432,7 +456,8 @@ class DataRequest {
432
456
  return this;
433
457
  }
434
458
  async delete() {
435
- if (!this.data_table) throw new Error("Data table not set");
459
+ if (!this.data_table)
460
+ throw new Error("Data table not set");
436
461
  const { data } = await axios.delete(
437
462
  `/data/${this.data_table}/${this.itemID}`
438
463
  );
@@ -440,8 +465,10 @@ class DataRequest {
440
465
  }
441
466
  async put(updatedItem) {
442
467
  const { data_table, itemID } = this;
443
- if (!data_table) throw new Error("Data table not set");
444
- if (!itemID) throw new Error("Item ID not set");
468
+ if (!data_table)
469
+ throw new Error("Data table not set");
470
+ if (!itemID)
471
+ throw new Error("Item ID not set");
445
472
  const { data } = await axios.put(
446
473
  `/data/${data_table}/${itemID}`,
447
474
  updatedItem
@@ -459,9 +486,9 @@ function responses(key) {
459
486
  class BagelAuth {
460
487
  constructor(bagel) {
461
488
  this.bagel = bagel;
489
+ __publicField(this, "user");
462
490
  this.bagel = bagel;
463
491
  }
464
- user = undefined;
465
492
  async validateUser() {
466
493
  try {
467
494
  const { data: usr } = await axios.get("/users/me", {
@@ -509,7 +536,7 @@ class BagelAuth {
509
536
  this.bagel.onError?.(err);
510
537
  console.log(err);
511
538
  }
512
- this.user = undefined;
539
+ this.user = void 0;
513
540
  }
514
541
  async acceptInvite(token, user) {
515
542
  await axios.post(`/auth/accept-invite/${token}`, user);
@@ -527,10 +554,12 @@ class BagelAuth {
527
554
  }
528
555
  }
529
556
  class Bagel {
530
- host;
531
- fileBaseUrl;
532
- onError;
533
557
  constructor({ host, fileBaseUrl, onError }) {
558
+ __publicField(this, "host");
559
+ __publicField(this, "fileBaseUrl");
560
+ __publicField(this, "onError");
561
+ __publicField(this, "read_table");
562
+ __publicField(this, "auth", new BagelAuth(this));
534
563
  this.host = host?.replace(/\/$/, "");
535
564
  this.fileBaseUrl = fileBaseUrl?.replace(/\/$/, "");
536
565
  if (!this.host) {
@@ -539,11 +568,9 @@ class Bagel {
539
568
  axios.defaults.baseURL = this.host;
540
569
  this.onError = onError;
541
570
  }
542
- read_table = undefined;
543
571
  data(table) {
544
572
  return new DataRequest(table, this);
545
573
  }
546
- auth = new BagelAuth(this);
547
574
  _endpointCleaner(endpoint) {
548
575
  const url = `${endpoint.replace(/^\//, "").replaceAll(/\/$/g, "")}`;
549
576
  return url;
@@ -558,10 +585,12 @@ class Bagel {
558
585
  async get(endpoint, query) {
559
586
  this._setAuthorization();
560
587
  endpoint = this._endpointCleaner(endpoint);
561
- if (/undefined|null/.test(endpoint)) throw new Error(`Invalid endpoint: ${endpoint}`);
588
+ if (/undefined|null/.test(endpoint))
589
+ throw new Error(`Invalid endpoint: ${endpoint}`);
562
590
  if (query) {
563
591
  const queryParams = Object.entries(query).filter(([_, value]) => !!value).map(([key, value]) => `${key}=${value}`).join("&");
564
- if (queryParams) endpoint = `${endpoint}?${queryParams}`;
592
+ if (queryParams)
593
+ endpoint = `${endpoint}?${queryParams}`;
565
594
  }
566
595
  const url = `/${endpoint}`;
567
596
  return axios.get(url).then(({ data }) => data).catch((err) => {
@@ -611,7 +640,8 @@ class Bagel {
611
640
  const formData = new FormData();
612
641
  formData.append("file", file);
613
642
  let url = "/static_files/upload";
614
- if (options?.topic) url = `/static_files/upload?topic=${options.topic}`;
643
+ if (options?.topic)
644
+ url = `/static_files/upload?topic=${options.topic}`;
615
645
  const { data } = await axios.post(url, formData, {
616
646
  headers: {
617
647
  "Content-Type": "multipart/form-data"
package/dist/index.mjs CHANGED
@@ -12,20 +12,24 @@ function formatType(typeName) {
12
12
  }
13
13
  function resolveReference(ref) {
14
14
  const t = ref.split("/").pop();
15
- if (!t) return "any";
15
+ if (!t)
16
+ return "any";
16
17
  return formatType(t);
17
18
  }
18
19
  function schemaToType(schema) {
19
- if (!schema) return "any";
20
+ if (!schema)
21
+ return "any";
20
22
  if (schema.anyOf) {
21
23
  let _t = schema.anyOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
22
- if (_t === "" || _t === "null") _t = "any";
24
+ if (_t === "" || _t === "null")
25
+ _t = "any";
23
26
  return _t;
24
27
  }
25
28
  if (schema.allOf) {
26
29
  return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
27
30
  }
28
- if (schema.$ref) return resolveReference(schema.$ref);
31
+ if (schema.$ref)
32
+ return resolveReference(schema.$ref);
29
33
  switch (schema.type) {
30
34
  case "object":
31
35
  return "{ [key: string]: any }";
@@ -43,7 +47,7 @@ function schemaToType(schema) {
43
47
  return "undefined";
44
48
  case "null":
45
49
  return "null";
46
- case undefined:
50
+ case void 0:
47
51
  return "any";
48
52
  default:
49
53
  console.log("Unknown type", schema.type);
@@ -55,7 +59,7 @@ function isOptional(schema) {
55
59
  const splitType = type.split(/\s+\|\s+/);
56
60
  const includesNull = splitType.includes("null");
57
61
  const includesUndefined = splitType.includes("undefined");
58
- return includesNull || includesUndefined || schema.default !== undefined;
62
+ return includesNull || includesUndefined || schema.default !== void 0;
59
63
  }
60
64
  function cleanOptionals(str) {
61
65
  return str.split(" | ").filter((t) => t !== "null" && t !== "undefined").join(" | ");
@@ -77,7 +81,8 @@ function formatVarType({
77
81
  }
78
82
  }
79
83
  let optionalStr = !required && isOptional(schema) ? "?" : "";
80
- if (defaultStr) optionalStr = "";
84
+ if (defaultStr)
85
+ optionalStr = "";
81
86
  return `${varName}${optionalStr}: ${type}${defaultStr}`;
82
87
  }
83
88
  function cleanPath(path) {
@@ -106,8 +111,10 @@ function collectTypeForImportStatement(typeName) {
106
111
  }
107
112
  const isPrimitive = primitiveTypes.includes(typeName);
108
113
  typeName = formatType(typeName);
109
- if (!typeName || isPrimitive) return;
110
- if (!allTypes.includes(typeName)) allTypes.push(typeName);
114
+ if (!typeName || isPrimitive)
115
+ return;
116
+ if (!allTypes.includes(typeName))
117
+ allTypes.push(typeName);
111
118
  }
112
119
  function schemaToTypeWithCollection(schema) {
113
120
  const type = schemaToType(schema);
@@ -116,12 +123,14 @@ function schemaToTypeWithCollection(schema) {
116
123
  }
117
124
  function getResponseType(response) {
118
125
  const mediaTypeObject = response.content?.["application/json"];
119
- if (!mediaTypeObject || !mediaTypeObject.schema) return;
126
+ if (!mediaTypeObject || !mediaTypeObject.schema)
127
+ return;
120
128
  const responseType = schemaToTypeWithCollection(mediaTypeObject.schema);
121
129
  return responseType;
122
130
  }
123
131
  function generateResponseType(responses) {
124
- if (!responses) return "";
132
+ if (!responses)
133
+ return "";
125
134
  const types = [];
126
135
  for (const [statusCode, response] of Object.entries(responses)) {
127
136
  if (statusCode.startsWith("2")) {
@@ -134,7 +143,8 @@ function generateResponseType(responses) {
134
143
  return types.join(" | ");
135
144
  }
136
145
  function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload) {
137
- if (allParams === "undefined") allParams = "";
146
+ if (allParams === "undefined")
147
+ allParams = "";
138
148
  let axiosFunction = `async (${allParams})${responseTypeStr} => {`;
139
149
  if (requestBodyPayload === "formData") {
140
150
  const paramStr = parameters?.config?.params ? `params: {${parameters.config.params}}` : "";
@@ -194,12 +204,14 @@ function combineAllParams(parameters, requestBodyParam) {
194
204
  let allParamsArray = [];
195
205
  if (parameters && parameters.params)
196
206
  allParamsArray = parameters.params.split(",").map((p) => p.trim());
197
- if (requestBodyParam) allParamsArray.push(requestBodyParam.trim());
207
+ if (requestBodyParam)
208
+ allParamsArray.push(requestBodyParam.trim());
198
209
  allParamsArray = allParamsArray.filter((p) => p).sort((a, b) => (a.includes("?") ? 1 : -1) - (b.includes("?") ? 1 : -1));
199
210
  return allParamsArray.join(", ");
200
211
  }
201
212
  function generateFunctionParameters(params, isFileUpload = false) {
202
- if (!params?.length) return {};
213
+ if (!params?.length)
214
+ return {};
203
215
  if (isFileUpload) {
204
216
  return {
205
217
  config: {
@@ -238,7 +250,8 @@ function generateFunctionParameters(params, isFileUpload = false) {
238
250
  };
239
251
  }
240
252
  function generateFunctionForOperation(method, path, operation) {
241
- if (!operation) return "";
253
+ if (!operation)
254
+ return "";
242
255
  const isFileUpload = operation.requestBody?.content["multipart/form-data"]?.schema?.$ref?.includes("Body_upload_files");
243
256
  const parameters = generateFunctionParameters(
244
257
  operation.parameters,
@@ -320,7 +333,8 @@ function generateFunctions(paths, baseUrl) {
320
333
  const splitPath = path.split("/").filter((p) => p && !/\{|\}/.test(p));
321
334
  splitPath.reduce((acc, key, index, array) => {
322
335
  const objFuncKey = toCamelCase(key);
323
- if (!objFuncKey) return acc;
336
+ if (!objFuncKey)
337
+ return acc;
324
338
  const methods = Object.keys(operation);
325
339
  if (index === array.length - 1 && methods.length === 1 && allPathsClean.filter((p) => p === cleanPath(path)).length === 1) {
326
340
  const method = methods[0];
@@ -335,7 +349,7 @@ function generateFunctions(paths, baseUrl) {
335
349
  }, body);
336
350
  }
337
351
  for (const [parent, object] of Object.entries(body)) {
338
- tsString += `export const ${parent} = ${JSON.stringify(object, undefined, 2)};
352
+ tsString += `export const ${parent} = ${JSON.stringify(object, void 0, 2)};
339
353
  `;
340
354
  }
341
355
  Object.entries(functionsInventory).forEach(([key, value]) => {
@@ -375,10 +389,12 @@ const index = async (openApiUrl, baseUrl) => {
375
389
  try {
376
390
  const { data: openApi } = await axios$1.get(openApiUrl, { headers: basicAuthHeader });
377
391
  const schemas = openApi.components?.schemas;
378
- if (!schemas) throw new Error("No schemas found in OpenAPI document");
392
+ if (!schemas)
393
+ throw new Error("No schemas found in OpenAPI document");
379
394
  const types = generateTypes(schemas);
380
395
  const { paths } = openApi;
381
- if (!paths) throw new Error("No paths found in OpenAPI document");
396
+ if (!paths)
397
+ throw new Error("No paths found in OpenAPI document");
382
398
  const code = generateFunctions(paths, baseUrl);
383
399
  return { types, code };
384
400
  } catch (error) {
@@ -386,21 +402,28 @@ const index = async (openApiUrl, baseUrl) => {
386
402
  }
387
403
  };
388
404
 
405
+ var __defProp = Object.defineProperty;
406
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
407
+ var __publicField = (obj, key, value) => {
408
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
409
+ return value;
410
+ };
389
411
  const axios = axios$1.create({
390
412
  withCredentials: true
391
413
  });
392
414
  class DataRequest {
393
- data_table;
394
- bagel;
395
- itemID;
396
- _filter = {};
397
415
  constructor(table, bagel) {
416
+ __publicField(this, "data_table");
417
+ __publicField(this, "bagel");
418
+ __publicField(this, "itemID");
419
+ __publicField(this, "_filter", {});
398
420
  this.data_table = table;
399
421
  this.bagel = bagel;
400
422
  this.itemID = "";
401
423
  }
402
424
  async post(item) {
403
- if (!this.data_table) throw new Error("Data table not set");
425
+ if (!this.data_table)
426
+ throw new Error("Data table not set");
404
427
  const { data } = await axios.post(`/data/${this.data_table}`, item);
405
428
  return data;
406
429
  }
@@ -409,7 +432,8 @@ class DataRequest {
409
432
  return this;
410
433
  }
411
434
  async get() {
412
- if (!this.data_table) throw new Error("Data table not set");
435
+ if (!this.data_table)
436
+ throw new Error("Data table not set");
413
437
  const filterStr = Object.keys(this._filter).length > 0 ? `?filter={${Object.entries(this._filter).map(([k, v]) => `${k}:${v}`).join(",")}}` : "";
414
438
  const url = `/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ""}${filterStr}`;
415
439
  try {
@@ -418,7 +442,7 @@ class DataRequest {
418
442
  } catch (err) {
419
443
  console.log(err);
420
444
  this.bagel.onError?.(err);
421
- return undefined;
445
+ return void 0;
422
446
  }
423
447
  }
424
448
  item(id) {
@@ -426,7 +450,8 @@ class DataRequest {
426
450
  return this;
427
451
  }
428
452
  async delete() {
429
- if (!this.data_table) throw new Error("Data table not set");
453
+ if (!this.data_table)
454
+ throw new Error("Data table not set");
430
455
  const { data } = await axios.delete(
431
456
  `/data/${this.data_table}/${this.itemID}`
432
457
  );
@@ -434,8 +459,10 @@ class DataRequest {
434
459
  }
435
460
  async put(updatedItem) {
436
461
  const { data_table, itemID } = this;
437
- if (!data_table) throw new Error("Data table not set");
438
- if (!itemID) throw new Error("Item ID not set");
462
+ if (!data_table)
463
+ throw new Error("Data table not set");
464
+ if (!itemID)
465
+ throw new Error("Item ID not set");
439
466
  const { data } = await axios.put(
440
467
  `/data/${data_table}/${itemID}`,
441
468
  updatedItem
@@ -453,9 +480,9 @@ function responses(key) {
453
480
  class BagelAuth {
454
481
  constructor(bagel) {
455
482
  this.bagel = bagel;
483
+ __publicField(this, "user");
456
484
  this.bagel = bagel;
457
485
  }
458
- user = undefined;
459
486
  async validateUser() {
460
487
  try {
461
488
  const { data: usr } = await axios.get("/users/me", {
@@ -503,7 +530,7 @@ class BagelAuth {
503
530
  this.bagel.onError?.(err);
504
531
  console.log(err);
505
532
  }
506
- this.user = undefined;
533
+ this.user = void 0;
507
534
  }
508
535
  async acceptInvite(token, user) {
509
536
  await axios.post(`/auth/accept-invite/${token}`, user);
@@ -521,10 +548,12 @@ class BagelAuth {
521
548
  }
522
549
  }
523
550
  class Bagel {
524
- host;
525
- fileBaseUrl;
526
- onError;
527
551
  constructor({ host, fileBaseUrl, onError }) {
552
+ __publicField(this, "host");
553
+ __publicField(this, "fileBaseUrl");
554
+ __publicField(this, "onError");
555
+ __publicField(this, "read_table");
556
+ __publicField(this, "auth", new BagelAuth(this));
528
557
  this.host = host?.replace(/\/$/, "");
529
558
  this.fileBaseUrl = fileBaseUrl?.replace(/\/$/, "");
530
559
  if (!this.host) {
@@ -533,11 +562,9 @@ class Bagel {
533
562
  axios.defaults.baseURL = this.host;
534
563
  this.onError = onError;
535
564
  }
536
- read_table = undefined;
537
565
  data(table) {
538
566
  return new DataRequest(table, this);
539
567
  }
540
- auth = new BagelAuth(this);
541
568
  _endpointCleaner(endpoint) {
542
569
  const url = `${endpoint.replace(/^\//, "").replaceAll(/\/$/g, "")}`;
543
570
  return url;
@@ -552,10 +579,12 @@ class Bagel {
552
579
  async get(endpoint, query) {
553
580
  this._setAuthorization();
554
581
  endpoint = this._endpointCleaner(endpoint);
555
- if (/undefined|null/.test(endpoint)) throw new Error(`Invalid endpoint: ${endpoint}`);
582
+ if (/undefined|null/.test(endpoint))
583
+ throw new Error(`Invalid endpoint: ${endpoint}`);
556
584
  if (query) {
557
585
  const queryParams = Object.entries(query).filter(([_, value]) => !!value).map(([key, value]) => `${key}=${value}`).join("&");
558
- if (queryParams) endpoint = `${endpoint}?${queryParams}`;
586
+ if (queryParams)
587
+ endpoint = `${endpoint}?${queryParams}`;
559
588
  }
560
589
  const url = `/${endpoint}`;
561
590
  return axios.get(url).then(({ data }) => data).catch((err) => {
@@ -605,7 +634,8 @@ class Bagel {
605
634
  const formData = new FormData();
606
635
  formData.append("file", file);
607
636
  let url = "/static_files/upload";
608
- if (options?.topic) url = `/static_files/upload?topic=${options.topic}`;
637
+ if (options?.topic)
638
+ url = `/static_files/upload?topic=${options.topic}`;
609
639
  const { data } = await axios.post(url, formData, {
610
640
  headers: {
611
641
  "Content-Type": "multipart/form-data"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.1133",
4
+ "version": "0.0.1135",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",