@goralys/core 1.3.0 → 1.4.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.
Files changed (2) hide show
  1. package/dist/index.js +6 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -415,18 +415,11 @@ var GoralysActionHandler = class {
415
415
  var actionHandler = new GoralysActionHandler();
416
416
  async function goralysFetchClient(method, input, payload, requestOptions) {
417
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
- }
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: { ...method === "BREW" ? { "X-HTTP-Method-Override": method } : {}, "X-High-School-Token": schoolToken },
422
+ body: payload ? payload instanceof FormData ? payload : JSON.stringify(payload) : void 0,
430
423
  ...requestOptions
431
424
  });
432
425
  const clone = res.clone();
@@ -457,9 +450,9 @@ async function fetchCsrfClient(formId) {
457
450
  const { apiDomain, schoolToken } = getGoralysClientConfig();
458
451
  const res = await fetch(`${apiDomain}/csrf`, {
459
452
  method: "POST",
460
- headers: { "Content-Type": "application/json" },
453
+ headers: { "Content-Type": "application/json", "X-High-School-Token": schoolToken },
461
454
  credentials: "include",
462
- body: JSON.stringify({ form: formId, "high-school-token": schoolToken })
455
+ body: JSON.stringify({ form: formId })
463
456
  });
464
457
  if (!res.ok)
465
458
  return null;
@@ -470,10 +463,9 @@ function buildQueryString(params) {
470
463
  return Object.entries(params).filter(([, value]) => value !== null && value !== void 0).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&");
471
464
  }
472
465
  function buildApiUrl(endpoint, params, domain = false) {
473
- const { apiDomain, schoolToken } = getGoralysClientConfig();
466
+ const { apiDomain } = getGoralysClientConfig();
474
467
  const queryString = buildQueryString(params);
475
- return `${domain ? apiDomain + "/" : ""}${endpoint + "?high-school-token=" + encodeURIComponent(schoolToken)}
476
- ${queryString ? `&${queryString}` : ""}`;
468
+ return `${domain ? apiDomain + "/" : ""}${endpoint}${queryString ? `?${queryString}` : ""}`;
477
469
  }
478
470
  async function handleToastRequest(r, showToast, redirect = true, duration) {
479
471
  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.0",
4
4
  "license": "LGPL-2.1-or-later",
5
5
  "description": "Shared business logic for the Goralys web application",
6
6
  "repository": {