@bagelink/sdk 0.0.360 → 0.0.368

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
@@ -291,7 +291,10 @@ var __publicField = (obj, key, value) => {
291
291
  };
292
292
  const axios = axios__default.create({
293
293
  // withCredentials to true to send cookies with requests
294
- withCredentials: true
294
+ headers: {
295
+ "Allow-Control-Allow-Origin": "*",
296
+ withCredentials: true
297
+ }
295
298
  });
296
299
  class DataRequest {
297
300
  constructor(table, bagel) {
@@ -307,7 +310,7 @@ class DataRequest {
307
310
  if (!this.data_table)
308
311
  throw new Error("Data table not set");
309
312
  const { data } = await axios.post(
310
- `${this.bagel.host}/data/${this.data_table}`,
313
+ `/data/${this.data_table}`,
311
314
  item
312
315
  );
313
316
  return data;
@@ -320,7 +323,7 @@ class DataRequest {
320
323
  if (!this.data_table)
321
324
  throw new Error("Data table not set");
322
325
  const filterStr = Object.keys(this._filter).length ? `?filter={${Object.entries(this._filter).map(([k, v]) => `${k}:${v}`).join(",")}}` : "";
323
- const url = `${this.bagel.host}/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ""}${filterStr}`;
326
+ const url = `/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ""}${filterStr}`;
324
327
  try {
325
328
  const { data } = await axios.get(url);
326
329
  return data;
@@ -338,18 +341,18 @@ class DataRequest {
338
341
  if (!this.data_table)
339
342
  throw new Error("Data table not set");
340
343
  const { data } = await axios.delete(
341
- `${this.bagel.host}/data/${this.data_table}/${this.itemID}`
344
+ `/data/${this.data_table}/${this.itemID}`
342
345
  );
343
346
  return data;
344
347
  }
345
348
  async put(updatedItem) {
346
- const { data_table, itemID, bagel } = this;
349
+ const { data_table, itemID } = this;
347
350
  if (!data_table)
348
351
  throw new Error("Data table not set");
349
352
  if (!itemID)
350
353
  throw new Error("Item ID not set");
351
354
  const { data } = await axios.put(
352
- `${bagel.host}/data/${data_table}/${itemID}`,
355
+ `/data/${data_table}/${itemID}`,
353
356
  updatedItem
354
357
  );
355
358
  return data;
@@ -395,7 +398,7 @@ class BagelAuth {
395
398
  formData.append("username", user?.email || "");
396
399
  formData.append("password", user?.password || "");
397
400
  try {
398
- await axios.post(`${this.bagel.host}/auth/cookie/login`, formData, {
401
+ await axios.post("/auth/cookie/login", formData, {
399
402
  headers: {
400
403
  "Content-Type": "multipart/form-data",
401
404
  withCredentials: true
@@ -408,7 +411,7 @@ class BagelAuth {
408
411
  }
409
412
  async logout() {
410
413
  try {
411
- await axios.post(`${this.bagel.host}/auth/cookie/logout`);
414
+ await axios.post("/auth/cookie/logout");
412
415
  } catch (err) {
413
416
  this.bagel.onError?.(err);
414
417
  console.log(err);
@@ -416,12 +419,12 @@ class BagelAuth {
416
419
  this.user = null;
417
420
  }
418
421
  async acceptInvite(token, user) {
419
- await axios.post(`${this.bagel.host}/auth/accept-invite/${token}`, user);
422
+ await axios.post(`/auth/accept-invite/${token}`, user);
420
423
  await this.login(user);
421
424
  }
422
425
  async register(user, errors) {
423
426
  try {
424
- await axios.post(`${this.bagel.host}/auth/register`, user);
427
+ await axios.post("/auth/register", user);
425
428
  return this.login(user);
426
429
  } catch (err) {
427
430
  console.error(err);
@@ -438,7 +441,8 @@ class Bagel {
438
441
  __publicField(this, "onError");
439
442
  __publicField(this, "read_table", null);
440
443
  __publicField(this, "auth", new BagelAuth(this));
441
- this.host = host;
444
+ this.host = host.replace(/\/$/, "");
445
+ axios.defaults.baseURL = this.host;
442
446
  this.onError = onError;
443
447
  }
444
448
  data(table) {
@@ -453,7 +457,7 @@ class Bagel {
453
457
  const queryParams = Object.entries(query).map(([key, value]) => `${key}=${value}`).join("&");
454
458
  endpoint = `${endpoint}?${queryParams}`;
455
459
  }
456
- return axios.get(`${this.host}/api/${endpoint}`).then(({ data }) => data);
460
+ return axios.get(`/api/${endpoint}`).then(({ data }) => data);
457
461
  }
458
462
  async get(endpoint, query) {
459
463
  endpoint = this._endpointCleaner(endpoint);
@@ -464,7 +468,7 @@ class Bagel {
464
468
  if (queryParams)
465
469
  endpoint = `${endpoint}?${queryParams}`;
466
470
  }
467
- const url = `${this.host}/${endpoint}`;
471
+ const url = `/${endpoint}`;
468
472
  return axios.get(url).then(({ data }) => data).catch((err) => {
469
473
  this.onError?.(err);
470
474
  throw err;
@@ -472,28 +476,28 @@ class Bagel {
472
476
  }
473
477
  async delete(endpoint) {
474
478
  endpoint = this._endpointCleaner(endpoint);
475
- return axios.delete(`${this.host}/${endpoint}`).then(({ data }) => data).catch((err) => {
479
+ return axios.delete(`/${endpoint}`).then(({ data }) => data).catch((err) => {
476
480
  this.onError?.(err);
477
481
  throw err;
478
482
  });
479
483
  }
480
484
  async put(endpoint, payload) {
481
485
  endpoint = this._endpointCleaner(endpoint);
482
- return axios.put(`${this.host}/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
486
+ return axios.put(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
483
487
  this.onError?.(err);
484
488
  throw err;
485
489
  });
486
490
  }
487
491
  async patch(endpoint, payload = {}) {
488
492
  endpoint = this._endpointCleaner(endpoint);
489
- return axios.patch(`${this.host}/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
493
+ return axios.patch(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
490
494
  this.onError?.(err);
491
495
  throw err;
492
496
  });
493
497
  }
494
498
  async post(endpoint, payload = {}) {
495
499
  endpoint = this._endpointCleaner(endpoint);
496
- return axios.post(`${this.host}/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
500
+ return axios.post(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
497
501
  this.onError?.(err);
498
502
  throw err;
499
503
  });
@@ -501,7 +505,7 @@ class Bagel {
501
505
  async uploadFile(file, options) {
502
506
  const formData = new FormData();
503
507
  formData.append("file", file);
504
- const { data } = await axios.post(`${this.host}/files/upload`, formData, {
508
+ const { data } = await axios.post("/files/upload", formData, {
505
509
  headers: {
506
510
  "Content-Type": "multipart/form-data"
507
511
  },
package/dist/index.mjs CHANGED
@@ -285,7 +285,10 @@ var __publicField = (obj, key, value) => {
285
285
  };
286
286
  const axios = axios$1.create({
287
287
  // withCredentials to true to send cookies with requests
288
- withCredentials: true
288
+ headers: {
289
+ "Allow-Control-Allow-Origin": "*",
290
+ withCredentials: true
291
+ }
289
292
  });
290
293
  class DataRequest {
291
294
  constructor(table, bagel) {
@@ -301,7 +304,7 @@ class DataRequest {
301
304
  if (!this.data_table)
302
305
  throw new Error("Data table not set");
303
306
  const { data } = await axios.post(
304
- `${this.bagel.host}/data/${this.data_table}`,
307
+ `/data/${this.data_table}`,
305
308
  item
306
309
  );
307
310
  return data;
@@ -314,7 +317,7 @@ class DataRequest {
314
317
  if (!this.data_table)
315
318
  throw new Error("Data table not set");
316
319
  const filterStr = Object.keys(this._filter).length ? `?filter={${Object.entries(this._filter).map(([k, v]) => `${k}:${v}`).join(",")}}` : "";
317
- const url = `${this.bagel.host}/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ""}${filterStr}`;
320
+ const url = `/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ""}${filterStr}`;
318
321
  try {
319
322
  const { data } = await axios.get(url);
320
323
  return data;
@@ -332,18 +335,18 @@ class DataRequest {
332
335
  if (!this.data_table)
333
336
  throw new Error("Data table not set");
334
337
  const { data } = await axios.delete(
335
- `${this.bagel.host}/data/${this.data_table}/${this.itemID}`
338
+ `/data/${this.data_table}/${this.itemID}`
336
339
  );
337
340
  return data;
338
341
  }
339
342
  async put(updatedItem) {
340
- const { data_table, itemID, bagel } = this;
343
+ const { data_table, itemID } = this;
341
344
  if (!data_table)
342
345
  throw new Error("Data table not set");
343
346
  if (!itemID)
344
347
  throw new Error("Item ID not set");
345
348
  const { data } = await axios.put(
346
- `${bagel.host}/data/${data_table}/${itemID}`,
349
+ `/data/${data_table}/${itemID}`,
347
350
  updatedItem
348
351
  );
349
352
  return data;
@@ -389,7 +392,7 @@ class BagelAuth {
389
392
  formData.append("username", user?.email || "");
390
393
  formData.append("password", user?.password || "");
391
394
  try {
392
- await axios.post(`${this.bagel.host}/auth/cookie/login`, formData, {
395
+ await axios.post("/auth/cookie/login", formData, {
393
396
  headers: {
394
397
  "Content-Type": "multipart/form-data",
395
398
  withCredentials: true
@@ -402,7 +405,7 @@ class BagelAuth {
402
405
  }
403
406
  async logout() {
404
407
  try {
405
- await axios.post(`${this.bagel.host}/auth/cookie/logout`);
408
+ await axios.post("/auth/cookie/logout");
406
409
  } catch (err) {
407
410
  this.bagel.onError?.(err);
408
411
  console.log(err);
@@ -410,12 +413,12 @@ class BagelAuth {
410
413
  this.user = null;
411
414
  }
412
415
  async acceptInvite(token, user) {
413
- await axios.post(`${this.bagel.host}/auth/accept-invite/${token}`, user);
416
+ await axios.post(`/auth/accept-invite/${token}`, user);
414
417
  await this.login(user);
415
418
  }
416
419
  async register(user, errors) {
417
420
  try {
418
- await axios.post(`${this.bagel.host}/auth/register`, user);
421
+ await axios.post("/auth/register", user);
419
422
  return this.login(user);
420
423
  } catch (err) {
421
424
  console.error(err);
@@ -432,7 +435,8 @@ class Bagel {
432
435
  __publicField(this, "onError");
433
436
  __publicField(this, "read_table", null);
434
437
  __publicField(this, "auth", new BagelAuth(this));
435
- this.host = host;
438
+ this.host = host.replace(/\/$/, "");
439
+ axios.defaults.baseURL = this.host;
436
440
  this.onError = onError;
437
441
  }
438
442
  data(table) {
@@ -447,7 +451,7 @@ class Bagel {
447
451
  const queryParams = Object.entries(query).map(([key, value]) => `${key}=${value}`).join("&");
448
452
  endpoint = `${endpoint}?${queryParams}`;
449
453
  }
450
- return axios.get(`${this.host}/api/${endpoint}`).then(({ data }) => data);
454
+ return axios.get(`/api/${endpoint}`).then(({ data }) => data);
451
455
  }
452
456
  async get(endpoint, query) {
453
457
  endpoint = this._endpointCleaner(endpoint);
@@ -458,7 +462,7 @@ class Bagel {
458
462
  if (queryParams)
459
463
  endpoint = `${endpoint}?${queryParams}`;
460
464
  }
461
- const url = `${this.host}/${endpoint}`;
465
+ const url = `/${endpoint}`;
462
466
  return axios.get(url).then(({ data }) => data).catch((err) => {
463
467
  this.onError?.(err);
464
468
  throw err;
@@ -466,28 +470,28 @@ class Bagel {
466
470
  }
467
471
  async delete(endpoint) {
468
472
  endpoint = this._endpointCleaner(endpoint);
469
- return axios.delete(`${this.host}/${endpoint}`).then(({ data }) => data).catch((err) => {
473
+ return axios.delete(`/${endpoint}`).then(({ data }) => data).catch((err) => {
470
474
  this.onError?.(err);
471
475
  throw err;
472
476
  });
473
477
  }
474
478
  async put(endpoint, payload) {
475
479
  endpoint = this._endpointCleaner(endpoint);
476
- return axios.put(`${this.host}/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
480
+ return axios.put(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
477
481
  this.onError?.(err);
478
482
  throw err;
479
483
  });
480
484
  }
481
485
  async patch(endpoint, payload = {}) {
482
486
  endpoint = this._endpointCleaner(endpoint);
483
- return axios.patch(`${this.host}/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
487
+ return axios.patch(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
484
488
  this.onError?.(err);
485
489
  throw err;
486
490
  });
487
491
  }
488
492
  async post(endpoint, payload = {}) {
489
493
  endpoint = this._endpointCleaner(endpoint);
490
- return axios.post(`${this.host}/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
494
+ return axios.post(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
491
495
  this.onError?.(err);
492
496
  throw err;
493
497
  });
@@ -495,7 +499,7 @@ class Bagel {
495
499
  async uploadFile(file, options) {
496
500
  const formData = new FormData();
497
501
  formData.append("file", file);
498
- const { data } = await axios.post(`${this.host}/files/upload`, formData, {
502
+ const { data } = await axios.post("/files/upload", formData, {
499
503
  headers: {
500
504
  "Content-Type": "multipart/form-data"
501
505
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.360",
4
+ "version": "0.0.368",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
package/src/index.ts CHANGED
@@ -24,7 +24,10 @@ interface UploadOptions {
24
24
 
25
25
  const axios = ax.create({
26
26
  // withCredentials to true to send cookies with requests
27
- withCredentials: true,
27
+ headers: {
28
+ 'Allow-Control-Allow-Origin': '*',
29
+ withCredentials: true,
30
+ },
28
31
  });
29
32
 
30
33
  class DataRequest<T extends Tables = Tables> {
@@ -45,7 +48,7 @@ class DataRequest<T extends Tables = Tables> {
45
48
  async post(item: Record<string, any>): Promise<Record<string, any>> {
46
49
  if (!this.data_table) throw new Error('Data table not set');
47
50
  const { data } = await axios.post(
48
- `${this.bagel.host}/data/${this.data_table}`,
51
+ `/data/${this.data_table}`,
49
52
  item,
50
53
  );
51
54
  return data;
@@ -65,7 +68,7 @@ class DataRequest<T extends Tables = Tables> {
65
68
  .map(([k, v]) => `${k}:${v}`)
66
69
  .join(',')}}`
67
70
  : '';
68
- const url = `${this.bagel.host}/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ''
71
+ const url = `/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ''
69
72
  }${filterStr}`;
70
73
  try {
71
74
  const { data } = await axios.get(url);
@@ -85,17 +88,17 @@ class DataRequest<T extends Tables = Tables> {
85
88
  async delete(): Promise<TableToTypeMapping[T][]> {
86
89
  if (!this.data_table) throw new Error('Data table not set');
87
90
  const { data } = await axios.delete(
88
- `${this.bagel.host}/data/${this.data_table}/${this.itemID}`,
91
+ `/data/${this.data_table}/${this.itemID}`,
89
92
  );
90
93
  return data;
91
94
  }
92
95
 
93
96
  async put(updatedItem: Record<string, any>): Promise<Record<string, any>> {
94
- const { data_table, itemID, bagel } = this;
97
+ const { data_table, itemID } = this;
95
98
  if (!data_table) throw new Error('Data table not set');
96
99
  if (!itemID) throw new Error('Item ID not set');
97
100
  const { data } = await axios.put(
98
- `${bagel.host}/data/${data_table}/${itemID}`,
101
+ `/data/${data_table}/${itemID}`,
99
102
  updatedItem,
100
103
  );
101
104
  return data;
@@ -148,7 +151,7 @@ class BagelAuth {
148
151
  formData.append('username', user?.email || '');
149
152
  formData.append('password', user?.password || '');
150
153
  try {
151
- await axios.post(`${this.bagel.host}/auth/cookie/login`, formData, {
154
+ await axios.post('/auth/cookie/login', formData, {
152
155
  headers: {
153
156
  'Content-Type': 'multipart/form-data',
154
157
  withCredentials: true,
@@ -162,7 +165,7 @@ class BagelAuth {
162
165
 
163
166
  async logout() {
164
167
  try {
165
- await axios.post(`${this.bagel.host}/auth/cookie/logout`);
168
+ await axios.post('/auth/cookie/logout');
166
169
  } catch (err) {
167
170
  this.bagel.onError?.(err);
168
171
  console.log(err);
@@ -171,7 +174,7 @@ class BagelAuth {
171
174
  }
172
175
 
173
176
  async acceptInvite(token: string, user: Record<string, any>) {
174
- await axios.post(`${this.bagel.host}/auth/accept-invite/${token}`, user);
177
+ await axios.post(`/auth/accept-invite/${token}`, user);
175
178
  await this.login(user as User);
176
179
  }
177
180
 
@@ -180,7 +183,7 @@ class BagelAuth {
180
183
  errors: Record<string, any>,
181
184
  ) {
182
185
  try {
183
- await axios.post<User>(`${this.bagel.host}/auth/register`, user);
186
+ await axios.post<User>('/auth/register', user);
184
187
  return this.login(user as User);
185
188
  } catch (err: any) {
186
189
  console.error(err);
@@ -200,7 +203,8 @@ export class Bagel {
200
203
  onError?: (err: any) => void;
201
204
 
202
205
  constructor({ host, onError }: Record<string, any>) {
203
- this.host = host;
206
+ this.host = host.replace(/\/$/, '');
207
+ axios.defaults.baseURL = this.host;
204
208
  this.onError = onError;
205
209
  }
206
210
 
@@ -227,7 +231,7 @@ export class Bagel {
227
231
  .join('&');
228
232
  endpoint = `${endpoint}?${queryParams}`;
229
233
  }
230
- return axios.get(`${this.host}/api/${endpoint}`).then(({ data }: { data: any }) => data);
234
+ return axios.get(`/api/${endpoint}`).then(({ data }: { data: any }) => data);
231
235
  }
232
236
 
233
237
  async get<T = Record<string, any>>(
@@ -244,7 +248,7 @@ export class Bagel {
244
248
  .join('&');
245
249
  if (queryParams) endpoint = `${endpoint}?${queryParams}`;
246
250
  }
247
- const url = `${this.host}/${endpoint}`;
251
+ const url = `/${endpoint}`;
248
252
  return axios
249
253
  .get(url)
250
254
  .then(({ data }: { data: any }) => data)
@@ -257,7 +261,7 @@ export class Bagel {
257
261
  async delete(endpoint: string): Promise<Record<string, any>> {
258
262
  endpoint = this._endpointCleaner(endpoint);
259
263
  return axios
260
- .delete(`${this.host}/${endpoint}`)
264
+ .delete(`/${endpoint}`)
261
265
  .then(({ data }: { data: any }) => data)
262
266
  .catch((err: any) => {
263
267
  this.onError?.(err);
@@ -268,7 +272,7 @@ export class Bagel {
268
272
  async put(endpoint: string, payload: any): Promise<Record<string, any>> {
269
273
  endpoint = this._endpointCleaner(endpoint);
270
274
  return axios
271
- .put(`${this.host}/${endpoint}`, payload)
275
+ .put(`/${endpoint}`, payload)
272
276
  .then(({ data }: { data: any }) => data)
273
277
  .catch((err: any) => {
274
278
  this.onError?.(err);
@@ -282,7 +286,7 @@ export class Bagel {
282
286
  ): Promise<Record<string, any>> {
283
287
  endpoint = this._endpointCleaner(endpoint);
284
288
  return axios
285
- .patch(`${this.host}/${endpoint}`, payload)
289
+ .patch(`/${endpoint}`, payload)
286
290
  .then(({ data }: { data: any }) => data)
287
291
  .catch((err: any) => {
288
292
  this.onError?.(err);
@@ -296,7 +300,7 @@ export class Bagel {
296
300
  ): Promise<Record<string, any>> {
297
301
  endpoint = this._endpointCleaner(endpoint);
298
302
  return axios
299
- .post(`${this.host}/${endpoint}`, payload)
303
+ .post(`/${endpoint}`, payload)
300
304
  .then(({ data }: { data: any }) => data)
301
305
  .catch((err: any) => {
302
306
  this.onError?.(err);
@@ -309,7 +313,7 @@ export class Bagel {
309
313
  formData.append('file', file);
310
314
  // get an indication of the progress
311
315
 
312
- const { data } = await axios.post<T>(`${this.host}/files/upload`, formData, {
316
+ const { data } = await axios.post<T>('/files/upload', formData, {
313
317
  headers: {
314
318
  'Content-Type': 'multipart/form-data',
315
319
  },