@bagelink/sdk 0.0.431 → 0.0.435

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
@@ -313,10 +313,7 @@ class DataRequest {
313
313
  async post(item) {
314
314
  if (!this.data_table)
315
315
  throw new Error("Data table not set");
316
- const { data } = await axios.post(
317
- `/data/${this.data_table}`,
318
- item
319
- );
316
+ const { data } = await axios.post(`/data/${this.data_table}`, item);
320
317
  return data;
321
318
  }
322
319
  filter(filter) {
@@ -377,7 +374,9 @@ class BagelAuth {
377
374
  }
378
375
  async validateUser() {
379
376
  try {
380
- const { data: usr } = await axios.get("/users/me", { withCredentials: true });
377
+ const { data: usr } = await axios.get("/users/me", {
378
+ withCredentials: true
379
+ });
381
380
  this.user = usr;
382
381
  return usr;
383
382
  } catch (err) {
@@ -446,8 +445,11 @@ class Bagel {
446
445
  __publicField(this, "read_table", null);
447
446
  __publicField(this, "auth", new BagelAuth(this));
448
447
  this.host = host?.replace(/\/$/, "");
449
- if (!this.host)
450
- throw new Error("you probably need to set VITE_BAGEL_BASE_URL in the .env file");
448
+ if (!this.host) {
449
+ throw new Error(
450
+ "you probably need to set VITE_BAGEL_BASE_URL in the .env file"
451
+ );
452
+ }
451
453
  axios.defaults.baseURL = this.host;
452
454
  this.onError = onError;
453
455
  }
@@ -466,6 +468,7 @@ class Bagel {
466
468
  return axios.get(`/api/${endpoint}`).then(({ data }) => data);
467
469
  }
468
470
  async get(endpoint, query) {
471
+ this._setAuthorization();
469
472
  endpoint = this._endpointCleaner(endpoint);
470
473
  if (endpoint.match(/undefined|null/))
471
474
  throw new Error("Invalid endpoint");
@@ -481,6 +484,7 @@ class Bagel {
481
484
  });
482
485
  }
483
486
  async delete(endpoint) {
487
+ this._setAuthorization();
484
488
  endpoint = this._endpointCleaner(endpoint);
485
489
  return axios.delete(`/${endpoint}`).then(({ data }) => data).catch((err) => {
486
490
  this.onError?.(err);
@@ -489,6 +493,7 @@ class Bagel {
489
493
  }
490
494
  async put(endpoint, payload) {
491
495
  endpoint = this._endpointCleaner(endpoint);
496
+ this._setAuthorization();
492
497
  return axios.put(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
493
498
  this.onError?.(err);
494
499
  throw err;
@@ -501,7 +506,14 @@ class Bagel {
501
506
  throw err;
502
507
  });
503
508
  }
509
+ _setAuthorization() {
510
+ const Authorization = localStorage.getItem("access_token");
511
+ if (Authorization) {
512
+ axios.defaults.headers.common.Authorization = `Bearer ${Authorization}`;
513
+ }
514
+ }
504
515
  async post(endpoint, payload = {}) {
516
+ this._setAuthorization();
505
517
  endpoint = this._endpointCleaner(endpoint);
506
518
  return axios.post(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
507
519
  this.onError?.(err);
@@ -509,6 +521,7 @@ class Bagel {
509
521
  });
510
522
  }
511
523
  async uploadFile(file, options) {
524
+ this._setAuthorization();
512
525
  const formData = new FormData();
513
526
  formData.append("file", file);
514
527
  const { data } = await axios.post("/static_files/upload", formData, {
package/dist/index.d.cts CHANGED
@@ -61,6 +61,7 @@ declare class Bagel {
61
61
  delete(endpoint: string): Promise<Record<string, any>>;
62
62
  put(endpoint: string, payload: any): Promise<Record<string, any>>;
63
63
  patch(endpoint: string, payload?: any): Promise<Record<string, any>>;
64
+ _setAuthorization(): void;
64
65
  post(endpoint: string, payload?: any): Promise<Record<string, any>>;
65
66
  uploadFile<T = any>(file: File, options?: UploadOptions): Promise<T>;
66
67
  }
package/dist/index.d.mts CHANGED
@@ -61,6 +61,7 @@ declare class Bagel {
61
61
  delete(endpoint: string): Promise<Record<string, any>>;
62
62
  put(endpoint: string, payload: any): Promise<Record<string, any>>;
63
63
  patch(endpoint: string, payload?: any): Promise<Record<string, any>>;
64
+ _setAuthorization(): void;
64
65
  post(endpoint: string, payload?: any): Promise<Record<string, any>>;
65
66
  uploadFile<T = any>(file: File, options?: UploadOptions): Promise<T>;
66
67
  }
package/dist/index.d.ts CHANGED
@@ -61,6 +61,7 @@ declare class Bagel {
61
61
  delete(endpoint: string): Promise<Record<string, any>>;
62
62
  put(endpoint: string, payload: any): Promise<Record<string, any>>;
63
63
  patch(endpoint: string, payload?: any): Promise<Record<string, any>>;
64
+ _setAuthorization(): void;
64
65
  post(endpoint: string, payload?: any): Promise<Record<string, any>>;
65
66
  uploadFile<T = any>(file: File, options?: UploadOptions): Promise<T>;
66
67
  }
package/dist/index.mjs CHANGED
@@ -307,10 +307,7 @@ class DataRequest {
307
307
  async post(item) {
308
308
  if (!this.data_table)
309
309
  throw new Error("Data table not set");
310
- const { data } = await axios.post(
311
- `/data/${this.data_table}`,
312
- item
313
- );
310
+ const { data } = await axios.post(`/data/${this.data_table}`, item);
314
311
  return data;
315
312
  }
316
313
  filter(filter) {
@@ -371,7 +368,9 @@ class BagelAuth {
371
368
  }
372
369
  async validateUser() {
373
370
  try {
374
- const { data: usr } = await axios.get("/users/me", { withCredentials: true });
371
+ const { data: usr } = await axios.get("/users/me", {
372
+ withCredentials: true
373
+ });
375
374
  this.user = usr;
376
375
  return usr;
377
376
  } catch (err) {
@@ -440,8 +439,11 @@ class Bagel {
440
439
  __publicField(this, "read_table", null);
441
440
  __publicField(this, "auth", new BagelAuth(this));
442
441
  this.host = host?.replace(/\/$/, "");
443
- if (!this.host)
444
- throw new Error("you probably need to set VITE_BAGEL_BASE_URL in the .env file");
442
+ if (!this.host) {
443
+ throw new Error(
444
+ "you probably need to set VITE_BAGEL_BASE_URL in the .env file"
445
+ );
446
+ }
445
447
  axios.defaults.baseURL = this.host;
446
448
  this.onError = onError;
447
449
  }
@@ -460,6 +462,7 @@ class Bagel {
460
462
  return axios.get(`/api/${endpoint}`).then(({ data }) => data);
461
463
  }
462
464
  async get(endpoint, query) {
465
+ this._setAuthorization();
463
466
  endpoint = this._endpointCleaner(endpoint);
464
467
  if (endpoint.match(/undefined|null/))
465
468
  throw new Error("Invalid endpoint");
@@ -475,6 +478,7 @@ class Bagel {
475
478
  });
476
479
  }
477
480
  async delete(endpoint) {
481
+ this._setAuthorization();
478
482
  endpoint = this._endpointCleaner(endpoint);
479
483
  return axios.delete(`/${endpoint}`).then(({ data }) => data).catch((err) => {
480
484
  this.onError?.(err);
@@ -483,6 +487,7 @@ class Bagel {
483
487
  }
484
488
  async put(endpoint, payload) {
485
489
  endpoint = this._endpointCleaner(endpoint);
490
+ this._setAuthorization();
486
491
  return axios.put(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
487
492
  this.onError?.(err);
488
493
  throw err;
@@ -495,7 +500,14 @@ class Bagel {
495
500
  throw err;
496
501
  });
497
502
  }
503
+ _setAuthorization() {
504
+ const Authorization = localStorage.getItem("access_token");
505
+ if (Authorization) {
506
+ axios.defaults.headers.common.Authorization = `Bearer ${Authorization}`;
507
+ }
508
+ }
498
509
  async post(endpoint, payload = {}) {
510
+ this._setAuthorization();
499
511
  endpoint = this._endpointCleaner(endpoint);
500
512
  return axios.post(`/${endpoint}`, payload).then(({ data }) => data).catch((err) => {
501
513
  this.onError?.(err);
@@ -503,6 +515,7 @@ class Bagel {
503
515
  });
504
516
  }
505
517
  async uploadFile(file, options) {
518
+ this._setAuthorization();
506
519
  const formData = new FormData();
507
520
  formData.append("file", file);
508
521
  const { data } = await axios.post("/static_files/upload", formData, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.431",
4
+ "version": "0.0.435",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
package/src/index.ts CHANGED
@@ -7,19 +7,19 @@ export type TableToTypeMapping = Record<Tables, any>;
7
7
 
8
8
  export { openAPI };
9
9
  export interface User {
10
- id: string
11
- first_name?: string
12
- last_name?: string
13
- email?: string
14
- password?: string
15
- is_verified?: boolean
16
- locale: string
17
- type: string
10
+ id: string;
11
+ first_name?: string;
12
+ last_name?: string;
13
+ email?: string;
14
+ password?: string;
15
+ is_verified?: boolean;
16
+ locale: string;
17
+ type: string;
18
18
  }
19
19
 
20
20
  interface UploadOptions {
21
21
  // eslint-disable-next-line no-unused-vars
22
- onUploadProgress?: (progressEvent: any) => void
22
+ onUploadProgress?: (progressEvent: any) => void;
23
23
  }
24
24
 
25
25
  const axios = ax.create({
@@ -43,10 +43,7 @@ class DataRequest<T extends Tables = Tables> {
43
43
 
44
44
  async post(item: Record<string, any>): Promise<Record<string, any>> {
45
45
  if (!this.data_table) throw new Error('Data table not set');
46
- const { data } = await axios.post(
47
- `/data/${this.data_table}`,
48
- item,
49
- );
46
+ const { data } = await axios.post(`/data/${this.data_table}`, item);
50
47
  return data;
51
48
  }
52
49
 
@@ -64,7 +61,8 @@ class DataRequest<T extends Tables = Tables> {
64
61
  .map(([k, v]) => `${k}:${v}`)
65
62
  .join(',')}}`
66
63
  : '';
67
- const url = `/data/${this.data_table}${this.itemID ? `/${this.itemID}` : ''
64
+ const url = `/data/${this.data_table}${
65
+ this.itemID ? `/${this.itemID}` : ''
68
66
  }${filterStr}`;
69
67
  try {
70
68
  const { data } = await axios.get(url);
@@ -118,7 +116,9 @@ class BagelAuth {
118
116
 
119
117
  async validateUser(): Promise<User | null> {
120
118
  try {
121
- const { data: usr } = await axios.get('/users/me', { withCredentials: true });
119
+ const { data: usr } = await axios.get('/users/me', {
120
+ withCredentials: true,
121
+ });
122
122
  this.user = usr;
123
123
  return usr;
124
124
  } catch (err) {
@@ -174,10 +174,7 @@ class BagelAuth {
174
174
  await this.login(user as User);
175
175
  }
176
176
 
177
- async register(
178
- user: Record<string, any>,
179
- errors: Record<string, any>,
180
- ) {
177
+ async register(user: Record<string, any>, errors: Record<string, any>) {
181
178
  try {
182
179
  await axios.post<User>('/auth/register', user);
183
180
  return this.login(user as User);
@@ -198,7 +195,11 @@ export class Bagel {
198
195
 
199
196
  constructor({ host, onError }: Record<string, any>) {
200
197
  this.host = host?.replace(/\/$/, '');
201
- if (!this.host) throw new Error('you probably need to set VITE_BAGEL_BASE_URL in the .env file');
198
+ if (!this.host) {
199
+ throw new Error(
200
+ 'you probably need to set VITE_BAGEL_BASE_URL in the .env file',
201
+ );
202
+ }
202
203
  axios.defaults.baseURL = this.host;
203
204
  this.onError = onError;
204
205
  }
@@ -226,13 +227,16 @@ export class Bagel {
226
227
  .join('&');
227
228
  endpoint = `${endpoint}?${queryParams}`;
228
229
  }
229
- return axios.get(`/api/${endpoint}`).then(({ data }: { data: any }) => data);
230
+ return axios
231
+ .get(`/api/${endpoint}`)
232
+ .then(({ data }: { data: any }) => data);
230
233
  }
231
234
 
232
235
  async get<T = Record<string, any>>(
233
236
  endpoint: string,
234
237
  query?: Record<string, any>,
235
238
  ): Promise<T> {
239
+ this._setAuthorization();
236
240
  endpoint = this._endpointCleaner(endpoint);
237
241
  if (endpoint.match(/undefined|null/)) throw new Error('Invalid endpoint');
238
242
  if (query) {
@@ -254,6 +258,7 @@ export class Bagel {
254
258
  }
255
259
 
256
260
  async delete(endpoint: string): Promise<Record<string, any>> {
261
+ this._setAuthorization();
257
262
  endpoint = this._endpointCleaner(endpoint);
258
263
  return axios
259
264
  .delete(`/${endpoint}`)
@@ -266,6 +271,7 @@ export class Bagel {
266
271
 
267
272
  async put(endpoint: string, payload: any): Promise<Record<string, any>> {
268
273
  endpoint = this._endpointCleaner(endpoint);
274
+ this._setAuthorization();
269
275
  return axios
270
276
  .put(`/${endpoint}`, payload)
271
277
  .then(({ data }: { data: any }) => data)
@@ -289,10 +295,18 @@ export class Bagel {
289
295
  });
290
296
  }
291
297
 
298
+ _setAuthorization() {
299
+ const Authorization = localStorage.getItem('access_token');
300
+ if (Authorization) {
301
+ axios.defaults.headers.common.Authorization = `Bearer ${Authorization}`;
302
+ }
303
+ }
304
+
292
305
  async post(
293
306
  endpoint: string,
294
307
  payload: any = {},
295
308
  ): Promise<Record<string, any>> {
309
+ this._setAuthorization();
296
310
  endpoint = this._endpointCleaner(endpoint);
297
311
  return axios
298
312
  .post(`/${endpoint}`, payload)
@@ -304,6 +318,7 @@ export class Bagel {
304
318
  }
305
319
 
306
320
  async uploadFile<T = any>(file: File, options?: UploadOptions): Promise<T> {
321
+ this._setAuthorization();
307
322
  const formData = new FormData();
308
323
  formData.append('file', file);
309
324
  // get an indication of the progress