@giaeulate/baas-sdk 1.0.9 → 1.0.10

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
@@ -32,12 +32,32 @@ var HttpClient = class {
32
32
  apiKey = "";
33
33
  token = null;
34
34
  environment = "prod";
35
+ _onForceLogout = null;
35
36
  constructor(url, apiKey) {
36
37
  let baseUrl = url || (typeof window !== "undefined" ? window.location.origin : "http://localhost:8080");
37
38
  this.url = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
38
39
  if (apiKey) this.apiKey = apiKey;
39
40
  this.token = this.cleanValue(localStorage.getItem("baas_token"));
40
41
  }
42
+ /**
43
+ * Set the auth token manually (e.g. restoring from SecureStore in React Native).
44
+ * Persists to both the in-memory property and localStorage so getDynamicToken() works.
45
+ */
46
+ setToken(token) {
47
+ this.token = token;
48
+ if (token) {
49
+ localStorage.setItem("baas_token", token);
50
+ } else {
51
+ localStorage.removeItem("baas_token");
52
+ }
53
+ }
54
+ /**
55
+ * Register a callback invoked on forced logout (401).
56
+ * Use this in React Native instead of the default window.location redirect.
57
+ */
58
+ onForceLogout(callback) {
59
+ this._onForceLogout = callback;
60
+ }
41
61
  cleanValue(val) {
42
62
  if (!val || val === "null" || val === "undefined") return null;
43
63
  return val.trim();
@@ -120,9 +140,13 @@ var HttpClient = class {
120
140
  }
121
141
  forceLogout() {
122
142
  this.logout();
123
- if (typeof window !== "undefined") {
143
+ if (this._onForceLogout) {
144
+ this._onForceLogout();
145
+ return;
146
+ }
147
+ if (typeof window !== "undefined" && window.location && window.location.search !== void 0) {
124
148
  if (!window.location.search.includes("expired")) {
125
- window.location.href = "/auth/login?reason=expired";
149
+ window.location.href = "/authentication/login?reason=expired";
126
150
  }
127
151
  }
128
152
  }
package/dist/index.d.cts CHANGED
@@ -50,7 +50,18 @@ declare class HttpClient {
50
50
  apiKey: string;
51
51
  token: string | null;
52
52
  private environment;
53
+ private _onForceLogout;
53
54
  constructor(url?: string, apiKey?: string);
55
+ /**
56
+ * Set the auth token manually (e.g. restoring from SecureStore in React Native).
57
+ * Persists to both the in-memory property and localStorage so getDynamicToken() works.
58
+ */
59
+ setToken(token: string | null): void;
60
+ /**
61
+ * Register a callback invoked on forced logout (401).
62
+ * Use this in React Native instead of the default window.location redirect.
63
+ */
64
+ onForceLogout(callback: () => void): void;
54
65
  protected cleanValue(val: string | null): string | null;
55
66
  /**
56
67
  * Public header generator for adapters
package/dist/index.d.ts CHANGED
@@ -50,7 +50,18 @@ declare class HttpClient {
50
50
  apiKey: string;
51
51
  token: string | null;
52
52
  private environment;
53
+ private _onForceLogout;
53
54
  constructor(url?: string, apiKey?: string);
55
+ /**
56
+ * Set the auth token manually (e.g. restoring from SecureStore in React Native).
57
+ * Persists to both the in-memory property and localStorage so getDynamicToken() works.
58
+ */
59
+ setToken(token: string | null): void;
60
+ /**
61
+ * Register a callback invoked on forced logout (401).
62
+ * Use this in React Native instead of the default window.location redirect.
63
+ */
64
+ onForceLogout(callback: () => void): void;
54
65
  protected cleanValue(val: string | null): string | null;
55
66
  /**
56
67
  * Public header generator for adapters
package/dist/index.js CHANGED
@@ -4,12 +4,32 @@ var HttpClient = class {
4
4
  apiKey = "";
5
5
  token = null;
6
6
  environment = "prod";
7
+ _onForceLogout = null;
7
8
  constructor(url, apiKey) {
8
9
  let baseUrl = url || (typeof window !== "undefined" ? window.location.origin : "http://localhost:8080");
9
10
  this.url = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
10
11
  if (apiKey) this.apiKey = apiKey;
11
12
  this.token = this.cleanValue(localStorage.getItem("baas_token"));
12
13
  }
14
+ /**
15
+ * Set the auth token manually (e.g. restoring from SecureStore in React Native).
16
+ * Persists to both the in-memory property and localStorage so getDynamicToken() works.
17
+ */
18
+ setToken(token) {
19
+ this.token = token;
20
+ if (token) {
21
+ localStorage.setItem("baas_token", token);
22
+ } else {
23
+ localStorage.removeItem("baas_token");
24
+ }
25
+ }
26
+ /**
27
+ * Register a callback invoked on forced logout (401).
28
+ * Use this in React Native instead of the default window.location redirect.
29
+ */
30
+ onForceLogout(callback) {
31
+ this._onForceLogout = callback;
32
+ }
13
33
  cleanValue(val) {
14
34
  if (!val || val === "null" || val === "undefined") return null;
15
35
  return val.trim();
@@ -92,9 +112,13 @@ var HttpClient = class {
92
112
  }
93
113
  forceLogout() {
94
114
  this.logout();
95
- if (typeof window !== "undefined") {
115
+ if (this._onForceLogout) {
116
+ this._onForceLogout();
117
+ return;
118
+ }
119
+ if (typeof window !== "undefined" && window.location && window.location.search !== void 0) {
96
120
  if (!window.location.search.includes("expired")) {
97
- window.location.href = "/auth/login?reason=expired";
121
+ window.location.href = "/authentication/login?reason=expired";
98
122
  }
99
123
  }
100
124
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giaeulate/baas-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Standalone SDK for BaaS Golang",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",