@giaeulate/baas-sdk 1.1.0 → 1.2.0
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 +29 -7
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +29 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -79,6 +79,10 @@ var HttpClient = class {
|
|
|
79
79
|
if (this.environment && this.environment !== "prod") {
|
|
80
80
|
headers["X-Environment"] = this.environment;
|
|
81
81
|
}
|
|
82
|
+
const csrfToken = this.getCSRFToken();
|
|
83
|
+
if (csrfToken) {
|
|
84
|
+
headers["X-CSRF-Token"] = csrfToken;
|
|
85
|
+
}
|
|
82
86
|
return headers;
|
|
83
87
|
}
|
|
84
88
|
getDynamicToken() {
|
|
@@ -92,7 +96,8 @@ var HttpClient = class {
|
|
|
92
96
|
const headers = { ...this.getHeaders(), ...customHeaders };
|
|
93
97
|
const fetchOptions = {
|
|
94
98
|
method,
|
|
95
|
-
headers
|
|
99
|
+
headers,
|
|
100
|
+
credentials: "include"
|
|
96
101
|
};
|
|
97
102
|
if (body !== void 0) {
|
|
98
103
|
fetchOptions.body = JSON.stringify(body);
|
|
@@ -128,6 +133,11 @@ var HttpClient = class {
|
|
|
128
133
|
delete(endpoint) {
|
|
129
134
|
return this.request(endpoint, { method: "DELETE" });
|
|
130
135
|
}
|
|
136
|
+
getCSRFToken() {
|
|
137
|
+
if (typeof document === "undefined") return null;
|
|
138
|
+
const match = document.cookie.match(/(?:^|;\s*)csrf_token=([^;]*)/);
|
|
139
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
140
|
+
}
|
|
131
141
|
setEnvironment(env) {
|
|
132
142
|
this.environment = env;
|
|
133
143
|
}
|
|
@@ -239,7 +249,8 @@ var QueryBuilder = class {
|
|
|
239
249
|
}
|
|
240
250
|
async get() {
|
|
241
251
|
const res = await fetch(`${this.url}/api/v1/data/${this.table}?${this.queryParams.toString()}`, {
|
|
242
|
-
headers: this.getHeaders()
|
|
252
|
+
headers: { ...this.getHeaders(), "Cache-Control": "no-cache" },
|
|
253
|
+
cache: "no-store"
|
|
243
254
|
});
|
|
244
255
|
return await this.handleResponse(res);
|
|
245
256
|
}
|
|
@@ -1009,11 +1020,22 @@ var RealtimeService = class {
|
|
|
1009
1020
|
resolve();
|
|
1010
1021
|
};
|
|
1011
1022
|
socket.onmessage = (event) => {
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1023
|
+
const raw = event.data;
|
|
1024
|
+
const parts = raw.split("\n").filter((s) => s.trim());
|
|
1025
|
+
for (const part of parts) {
|
|
1026
|
+
try {
|
|
1027
|
+
const payload = JSON.parse(part);
|
|
1028
|
+
this.handleEvent(payload);
|
|
1029
|
+
} catch {
|
|
1030
|
+
const chunks = part.replace(/\}\s*\{/g, "}\n{").split("\n");
|
|
1031
|
+
for (const chunk of chunks) {
|
|
1032
|
+
try {
|
|
1033
|
+
const payload = JSON.parse(chunk);
|
|
1034
|
+
this.handleEvent(payload);
|
|
1035
|
+
} catch {
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1017
1039
|
}
|
|
1018
1040
|
};
|
|
1019
1041
|
socket.onerror = (error) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -77,6 +77,7 @@ declare class HttpClient {
|
|
|
77
77
|
protected put<T = any>(endpoint: string, body?: unknown): Promise<T>;
|
|
78
78
|
protected patch<T = any>(endpoint: string, body?: unknown): Promise<T>;
|
|
79
79
|
protected delete<T = any>(endpoint: string): Promise<T>;
|
|
80
|
+
private getCSRFToken;
|
|
80
81
|
setEnvironment(env: string): void;
|
|
81
82
|
getEnvironment(): string;
|
|
82
83
|
logout(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,7 @@ declare class HttpClient {
|
|
|
77
77
|
protected put<T = any>(endpoint: string, body?: unknown): Promise<T>;
|
|
78
78
|
protected patch<T = any>(endpoint: string, body?: unknown): Promise<T>;
|
|
79
79
|
protected delete<T = any>(endpoint: string): Promise<T>;
|
|
80
|
+
private getCSRFToken;
|
|
80
81
|
setEnvironment(env: string): void;
|
|
81
82
|
getEnvironment(): string;
|
|
82
83
|
logout(): void;
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,10 @@ var HttpClient = class {
|
|
|
51
51
|
if (this.environment && this.environment !== "prod") {
|
|
52
52
|
headers["X-Environment"] = this.environment;
|
|
53
53
|
}
|
|
54
|
+
const csrfToken = this.getCSRFToken();
|
|
55
|
+
if (csrfToken) {
|
|
56
|
+
headers["X-CSRF-Token"] = csrfToken;
|
|
57
|
+
}
|
|
54
58
|
return headers;
|
|
55
59
|
}
|
|
56
60
|
getDynamicToken() {
|
|
@@ -64,7 +68,8 @@ var HttpClient = class {
|
|
|
64
68
|
const headers = { ...this.getHeaders(), ...customHeaders };
|
|
65
69
|
const fetchOptions = {
|
|
66
70
|
method,
|
|
67
|
-
headers
|
|
71
|
+
headers,
|
|
72
|
+
credentials: "include"
|
|
68
73
|
};
|
|
69
74
|
if (body !== void 0) {
|
|
70
75
|
fetchOptions.body = JSON.stringify(body);
|
|
@@ -100,6 +105,11 @@ var HttpClient = class {
|
|
|
100
105
|
delete(endpoint) {
|
|
101
106
|
return this.request(endpoint, { method: "DELETE" });
|
|
102
107
|
}
|
|
108
|
+
getCSRFToken() {
|
|
109
|
+
if (typeof document === "undefined") return null;
|
|
110
|
+
const match = document.cookie.match(/(?:^|;\s*)csrf_token=([^;]*)/);
|
|
111
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
112
|
+
}
|
|
103
113
|
setEnvironment(env) {
|
|
104
114
|
this.environment = env;
|
|
105
115
|
}
|
|
@@ -211,7 +221,8 @@ var QueryBuilder = class {
|
|
|
211
221
|
}
|
|
212
222
|
async get() {
|
|
213
223
|
const res = await fetch(`${this.url}/api/v1/data/${this.table}?${this.queryParams.toString()}`, {
|
|
214
|
-
headers: this.getHeaders()
|
|
224
|
+
headers: { ...this.getHeaders(), "Cache-Control": "no-cache" },
|
|
225
|
+
cache: "no-store"
|
|
215
226
|
});
|
|
216
227
|
return await this.handleResponse(res);
|
|
217
228
|
}
|
|
@@ -981,11 +992,22 @@ var RealtimeService = class {
|
|
|
981
992
|
resolve();
|
|
982
993
|
};
|
|
983
994
|
socket.onmessage = (event) => {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
995
|
+
const raw = event.data;
|
|
996
|
+
const parts = raw.split("\n").filter((s) => s.trim());
|
|
997
|
+
for (const part of parts) {
|
|
998
|
+
try {
|
|
999
|
+
const payload = JSON.parse(part);
|
|
1000
|
+
this.handleEvent(payload);
|
|
1001
|
+
} catch {
|
|
1002
|
+
const chunks = part.replace(/\}\s*\{/g, "}\n{").split("\n");
|
|
1003
|
+
for (const chunk of chunks) {
|
|
1004
|
+
try {
|
|
1005
|
+
const payload = JSON.parse(chunk);
|
|
1006
|
+
this.handleEvent(payload);
|
|
1007
|
+
} catch {
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
989
1011
|
}
|
|
990
1012
|
};
|
|
991
1013
|
socket.onerror = (error) => {
|