@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 CHANGED
@@ -1,6 +1,7 @@
1
1
  interface GoralysClientConfig {
2
2
  apiDomain: string;
3
3
  schoolToken: string;
4
+ isNative: boolean;
4
5
  }
5
6
  declare function configureGoralysClient(cfg: GoralysClientConfig): void;
6
7
  declare function getGoralysClientConfig(): GoralysClientConfig;
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: method === "BREW" ? { "X-HTTP-Method-Override": method } : {},
429
- body: finalPayload ? finalPayload instanceof FormData ? finalPayload : JSON.stringify(finalPayload) : void 0,
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: { "Content-Type": "application/json" },
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, "high-school-token": schoolToken })
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, schoolToken } = getGoralysClientConfig();
474
+ const { apiDomain } = getGoralysClientConfig();
474
475
  const queryString = buildQueryString(params);
475
- return `${domain ? apiDomain + "/" : ""}${endpoint + "?high-school-token=" + encodeURIComponent(schoolToken)}
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goralys/core",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "license": "LGPL-2.1-or-later",
5
5
  "description": "Shared business logic for the Goralys web application",
6
6
  "repository": {