@bagelink/sdk 0.0.392 → 0.0.398

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
@@ -290,11 +290,7 @@ var __publicField = (obj, key, value) => {
290
290
  return value;
291
291
  };
292
292
  const axios = axios__default.create({
293
- // withCredentials to true to send cookies with requests
294
- headers: {
295
- "Allow-Control-Allow-Origin": "*",
296
- withCredentials: true
297
- }
293
+ withCredentials: true
298
294
  });
299
295
  class DataRequest {
300
296
  constructor(table, bagel) {
@@ -373,11 +369,10 @@ class BagelAuth {
373
369
  }
374
370
  async validateUser() {
375
371
  try {
376
- const usr = await this.bagel.get("/users/me");
372
+ const { data: usr } = await axios.get("/users/me", { withCredentials: true });
377
373
  this.user = usr;
378
374
  return usr;
379
375
  } catch (err) {
380
- console.log(err);
381
376
  return null;
382
377
  }
383
378
  }
@@ -397,13 +392,15 @@ class BagelAuth {
397
392
  const formData = new FormData();
398
393
  formData.append("username", user?.email || "");
399
394
  formData.append("password", user?.password || "");
395
+ console.log("Logging in");
400
396
  try {
401
397
  await axios.post("/auth/cookie/login", formData, {
402
398
  headers: {
403
- "Content-Type": "multipart/form-data",
404
- withCredentials: true
399
+ withCredentials: true,
400
+ "Content-Type": "multipart/form-data"
405
401
  }
406
402
  });
403
+ axios.defaults.withCredentials = true;
407
404
  return this.validateUser();
408
405
  } catch (err) {
409
406
  throw responses(err.response?.data?.detail || "LOGIN_BAD_CREDENTIALS");
@@ -436,7 +433,6 @@ class BagelAuth {
436
433
  class Bagel {
437
434
  constructor({ host, onError }) {
438
435
  __publicField(this, "host");
439
- __publicField(this, "axiosInstance", axios);
440
436
  // eslint-disable-next-line no-unused-vars
441
437
  __publicField(this, "onError");
442
438
  __publicField(this, "read_table", null);
package/dist/index.d.cts CHANGED
@@ -1,5 +1,3 @@
1
- import { AxiosInstance } from 'axios';
2
-
3
1
  type OpenAPIResponse = {
4
2
  types: string;
5
3
  code: string;
@@ -52,7 +50,6 @@ declare class BagelAuth {
52
50
  }
53
51
  declare class Bagel {
54
52
  host: string;
55
- axiosInstance: AxiosInstance;
56
53
  onError?: (err: any) => void;
57
54
  constructor({ host, onError }: Record<string, any>);
58
55
  read_table: Tables | null;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,3 @@
1
- import { AxiosInstance } from 'axios';
2
-
3
1
  type OpenAPIResponse = {
4
2
  types: string;
5
3
  code: string;
@@ -52,7 +50,6 @@ declare class BagelAuth {
52
50
  }
53
51
  declare class Bagel {
54
52
  host: string;
55
- axiosInstance: AxiosInstance;
56
53
  onError?: (err: any) => void;
57
54
  constructor({ host, onError }: Record<string, any>);
58
55
  read_table: Tables | null;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { AxiosInstance } from 'axios';
2
-
3
1
  type OpenAPIResponse = {
4
2
  types: string;
5
3
  code: string;
@@ -52,7 +50,6 @@ declare class BagelAuth {
52
50
  }
53
51
  declare class Bagel {
54
52
  host: string;
55
- axiosInstance: AxiosInstance;
56
53
  onError?: (err: any) => void;
57
54
  constructor({ host, onError }: Record<string, any>);
58
55
  read_table: Tables | null;
package/dist/index.mjs CHANGED
@@ -284,11 +284,7 @@ var __publicField = (obj, key, value) => {
284
284
  return value;
285
285
  };
286
286
  const axios = axios$1.create({
287
- // withCredentials to true to send cookies with requests
288
- headers: {
289
- "Allow-Control-Allow-Origin": "*",
290
- withCredentials: true
291
- }
287
+ withCredentials: true
292
288
  });
293
289
  class DataRequest {
294
290
  constructor(table, bagel) {
@@ -367,11 +363,10 @@ class BagelAuth {
367
363
  }
368
364
  async validateUser() {
369
365
  try {
370
- const usr = await this.bagel.get("/users/me");
366
+ const { data: usr } = await axios.get("/users/me", { withCredentials: true });
371
367
  this.user = usr;
372
368
  return usr;
373
369
  } catch (err) {
374
- console.log(err);
375
370
  return null;
376
371
  }
377
372
  }
@@ -391,13 +386,15 @@ class BagelAuth {
391
386
  const formData = new FormData();
392
387
  formData.append("username", user?.email || "");
393
388
  formData.append("password", user?.password || "");
389
+ console.log("Logging in");
394
390
  try {
395
391
  await axios.post("/auth/cookie/login", formData, {
396
392
  headers: {
397
- "Content-Type": "multipart/form-data",
398
- withCredentials: true
393
+ withCredentials: true,
394
+ "Content-Type": "multipart/form-data"
399
395
  }
400
396
  });
397
+ axios.defaults.withCredentials = true;
401
398
  return this.validateUser();
402
399
  } catch (err) {
403
400
  throw responses(err.response?.data?.detail || "LOGIN_BAD_CREDENTIALS");
@@ -430,7 +427,6 @@ class BagelAuth {
430
427
  class Bagel {
431
428
  constructor({ host, onError }) {
432
429
  __publicField(this, "host");
433
- __publicField(this, "axiosInstance", axios);
434
430
  // eslint-disable-next-line no-unused-vars
435
431
  __publicField(this, "onError");
436
432
  __publicField(this, "read_table", null);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.392",
4
+ "version": "0.0.398",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import ax, { type AxiosInstance } from 'axios';
1
+ import ax from 'axios';
2
2
 
3
3
  import openAPI from './openAPITools';
4
4
 
@@ -23,11 +23,7 @@ interface UploadOptions {
23
23
  }
24
24
 
25
25
  const axios = ax.create({
26
- // withCredentials to true to send cookies with requests
27
- headers: {
28
- 'Allow-Control-Allow-Origin': '*',
29
- withCredentials: true,
30
- },
26
+ withCredentials: true,
31
27
  });
32
28
 
33
29
  class DataRequest<T extends Tables = Tables> {
@@ -122,12 +118,10 @@ class BagelAuth {
122
118
 
123
119
  async validateUser(): Promise<User | null> {
124
120
  try {
125
- const usr = (await this.bagel.get<User>('/users/me'));
121
+ const { data: usr } = await axios.get('/users/me', { withCredentials: true });
126
122
  this.user = usr;
127
123
  return usr;
128
124
  } catch (err) {
129
- // this.bagel.onError?.(err);
130
- console.log(err);
131
125
  return null;
132
126
  }
133
127
  }
@@ -150,13 +144,15 @@ class BagelAuth {
150
144
  const formData = new FormData();
151
145
  formData.append('username', user?.email || '');
152
146
  formData.append('password', user?.password || '');
147
+ console.log('Logging in');
153
148
  try {
154
149
  await axios.post('/auth/cookie/login', formData, {
155
150
  headers: {
156
- 'Content-Type': 'multipart/form-data',
157
151
  withCredentials: true,
152
+ 'Content-Type': 'multipart/form-data',
158
153
  },
159
154
  });
155
+ axios.defaults.withCredentials = true;
160
156
  return this.validateUser();
161
157
  } catch (err: any) {
162
158
  throw responses(err.response?.data?.detail || 'LOGIN_BAD_CREDENTIALS');
@@ -197,8 +193,6 @@ class BagelAuth {
197
193
  export class Bagel {
198
194
  host: string;
199
195
 
200
- axiosInstance: AxiosInstance = axios;
201
-
202
196
  // eslint-disable-next-line no-unused-vars
203
197
  onError?: (err: any) => void;
204
198