@goralys/core 1.3.0 → 1.4.1
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.d.ts +1 -0
- package/dist/index.js +16 -16
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -414,19 +414,16 @@ var GoralysActionHandler = class {
|
|
|
414
414
|
// src/lib/fetch/fetch.client.ts
|
|
415
415
|
var actionHandler = new GoralysActionHandler();
|
|
416
416
|
async function goralysFetchClient(method, input, payload, requestOptions) {
|
|
417
|
-
const { apiDomain, schoolToken } = getGoralysClientConfig();
|
|
418
|
-
let finalPayload = payload;
|
|
419
|
-
if (payload instanceof FormData) {
|
|
420
|
-
payload.append("high-school-token", schoolToken ?? "");
|
|
421
|
-
finalPayload = payload;
|
|
422
|
-
} else if (payload !== void 0) {
|
|
423
|
-
finalPayload = { ...payload, "high-school-token": schoolToken };
|
|
424
|
-
}
|
|
417
|
+
const { apiDomain, schoolToken, isNative } = getGoralysClientConfig();
|
|
425
418
|
const res = await fetch(`${apiDomain}/${input}`, {
|
|
426
419
|
credentials: "include",
|
|
427
420
|
method: method === "BREW" ? "POST" : method,
|
|
428
|
-
headers:
|
|
429
|
-
|
|
421
|
+
headers: {
|
|
422
|
+
...method === "BREW" ? { "X-HTTP-Method-Override": method } : {},
|
|
423
|
+
"X-High-School-Token": schoolToken,
|
|
424
|
+
"X-Goralys-Client": isNative ? "mobile" : "desktop"
|
|
425
|
+
},
|
|
426
|
+
body: payload ? payload instanceof FormData ? payload : JSON.stringify(payload) : void 0,
|
|
430
427
|
...requestOptions
|
|
431
428
|
});
|
|
432
429
|
const clone = res.clone();
|
|
@@ -454,12 +451,16 @@ async function goralysFetchClient(method, input, payload, requestOptions) {
|
|
|
454
451
|
return res;
|
|
455
452
|
}
|
|
456
453
|
async function fetchCsrfClient(formId) {
|
|
457
|
-
const { apiDomain, schoolToken } = getGoralysClientConfig();
|
|
454
|
+
const { apiDomain, schoolToken, isNative } = getGoralysClientConfig();
|
|
458
455
|
const res = await fetch(`${apiDomain}/csrf`, {
|
|
459
456
|
method: "POST",
|
|
460
|
-
headers: {
|
|
457
|
+
headers: {
|
|
458
|
+
"Content-Type": "application/json",
|
|
459
|
+
"X-High-School-Token": schoolToken,
|
|
460
|
+
"X-Goralys-Client": isNative ? "mobile" : "desktop"
|
|
461
|
+
},
|
|
461
462
|
credentials: "include",
|
|
462
|
-
body: JSON.stringify({ form: formId
|
|
463
|
+
body: JSON.stringify({ form: formId })
|
|
463
464
|
});
|
|
464
465
|
if (!res.ok)
|
|
465
466
|
return null;
|
|
@@ -470,10 +471,9 @@ function buildQueryString(params) {
|
|
|
470
471
|
return Object.entries(params).filter(([, value]) => value !== null && value !== void 0).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&");
|
|
471
472
|
}
|
|
472
473
|
function buildApiUrl(endpoint, params, domain = false) {
|
|
473
|
-
const { apiDomain
|
|
474
|
+
const { apiDomain } = getGoralysClientConfig();
|
|
474
475
|
const queryString = buildQueryString(params);
|
|
475
|
-
return `${domain ? apiDomain + "/" : ""}${endpoint
|
|
476
|
-
${queryString ? `&${queryString}` : ""}`;
|
|
476
|
+
return `${domain ? apiDomain + "/" : ""}${endpoint}${queryString ? `?${queryString}` : ""}`;
|
|
477
477
|
}
|
|
478
478
|
async function handleToastRequest(r, showToast, redirect = true, duration) {
|
|
479
479
|
const res = r.clone();
|