@streamline-pulse/formkrafter-core 0.16.0 → 0.17.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.js CHANGED
@@ -7125,6 +7125,7 @@ var en = {
7125
7125
  "panel.content": "Content",
7126
7126
  "panel.dataKey": "Data key",
7127
7127
  "panel.url": "URL",
7128
+ "panel.responsePath": "Response path (optional)",
7128
7129
  "panel.headers": "Headers ({token} reads form data)",
7129
7130
  "panel.searchParam": "Server search param",
7130
7131
  "panel.labelKey": "Label key",
@@ -7259,6 +7260,7 @@ var frFkTranslations = {
7259
7260
  "panel.content": "Contenu",
7260
7261
  "panel.dataKey": "Clé de données",
7261
7262
  "panel.url": "URL",
7263
+ "panel.responsePath": "Chemin dans la réponse (optionnel)",
7262
7264
  "panel.headers": "En-têtes ({token} lit les données du formulaire)",
7263
7265
  "panel.searchParam": "Paramètre de recherche serveur",
7264
7266
  "panel.labelKey": "Clé du libellé",
@@ -7710,7 +7712,68 @@ class SandboxJsRunnerService {
7710
7712
  }
7711
7713
  }
7712
7714
 
7715
+ // lib/utils/remote.ts
7716
+ function resolvePath(source, path) {
7717
+ if (Object.prototype.hasOwnProperty.call(source, path))
7718
+ return source[path];
7719
+ let current = source;
7720
+ for (const segment of path.split(".")) {
7721
+ if (current === null || typeof current !== "object")
7722
+ return;
7723
+ if (!Object.prototype.hasOwnProperty.call(current, segment))
7724
+ return;
7725
+ current = current[segment];
7726
+ }
7727
+ return current;
7728
+ }
7729
+ function interpolateTemplate(template, dataMap) {
7730
+ return template.replace(/\{([\w.]+)\}/g, (_, token) => {
7731
+ const value = dataMap && resolvePath(dataMap, token);
7732
+ return value === undefined || value === null ? "" : String(value);
7733
+ });
7734
+ }
7735
+ function parseHeaderLines(raw, dataMap) {
7736
+ if (typeof raw !== "string" || !raw.trim())
7737
+ return;
7738
+ const headers = {};
7739
+ for (const line of raw.split(`
7740
+ `)) {
7741
+ const separator = line.indexOf(":");
7742
+ if (separator <= 0)
7743
+ continue;
7744
+ const name = line.slice(0, separator).trim();
7745
+ const value = interpolateTemplate(line.slice(separator + 1).trim(), dataMap);
7746
+ if (name)
7747
+ headers[name] = value;
7748
+ }
7749
+ return Object.keys(headers).length ? headers : undefined;
7750
+ }
7751
+ function appendSearchParam(url, param, term) {
7752
+ if (!term)
7753
+ return url;
7754
+ const separator = url.includes("?") ? "&" : "?";
7755
+ return `${url}${separator}${encodeURIComponent(param)}=${encodeURIComponent(term)}`;
7756
+ }
7757
+
7713
7758
  // lib/services/data_source_service.ts
7759
+ function optionsFromPayload(json, url, path) {
7760
+ if (path) {
7761
+ const picked = json !== null && typeof json === "object" ? resolvePath(json, path) : undefined;
7762
+ if (!Array.isArray(picked)) {
7763
+ throw new Error(`Data source has no array at "${path}": ${url}`);
7764
+ }
7765
+ return picked;
7766
+ }
7767
+ if (Array.isArray(json))
7768
+ return json;
7769
+ if (json !== null && typeof json === "object") {
7770
+ const envelope = json.data;
7771
+ if (Array.isArray(envelope))
7772
+ return envelope;
7773
+ }
7774
+ throw new Error(`Data source did not return an array: ${url}`);
7775
+ }
7776
+
7714
7777
  class FetchDataSourceService {
7715
7778
  defaults;
7716
7779
  cache = new Map;
@@ -7724,7 +7787,7 @@ class FetchDataSourceService {
7724
7787
  init.headers = headers;
7725
7788
  if (this.defaults.credentials)
7726
7789
  init.credentials = this.defaults.credentials;
7727
- const key = `${url}|${JSON.stringify(init)}`;
7790
+ const key = `${url}|${JSON.stringify(init)}|${options?.path ?? ""}`;
7728
7791
  let pending = this.cache.get(key);
7729
7792
  if (!pending) {
7730
7793
  pending = fetch(url, Object.keys(init).length ? init : undefined).then((response) => {
@@ -7732,12 +7795,7 @@ class FetchDataSourceService {
7732
7795
  throw new Error(`Data source request failed (${response.status}): ${url}`);
7733
7796
  }
7734
7797
  return response.json();
7735
- }).then((json) => {
7736
- if (!Array.isArray(json)) {
7737
- throw new Error(`Data source did not return an array: ${url}`);
7738
- }
7739
- return json;
7740
- }).catch((error) => {
7798
+ }).then((json) => optionsFromPayload(json, url, options?.path)).catch((error) => {
7741
7799
  this.cache.delete(key);
7742
7800
  throw error;
7743
7801
  });
@@ -8148,35 +8206,6 @@ function stripUidsFromPatches(patches) {
8148
8206
  value: stripPatchValue(patch.value, patch.path)
8149
8207
  } : patch);
8150
8208
  }
8151
- // lib/utils/remote.ts
8152
- function interpolateTemplate(template, dataMap) {
8153
- return template.replace(/\{(\w+)\}/g, (_, token) => {
8154
- const value = dataMap?.[token];
8155
- return value === undefined || value === null ? "" : String(value);
8156
- });
8157
- }
8158
- function parseHeaderLines(raw, dataMap) {
8159
- if (typeof raw !== "string" || !raw.trim())
8160
- return;
8161
- const headers = {};
8162
- for (const line of raw.split(`
8163
- `)) {
8164
- const separator = line.indexOf(":");
8165
- if (separator <= 0)
8166
- continue;
8167
- const name = line.slice(0, separator).trim();
8168
- const value = interpolateTemplate(line.slice(separator + 1).trim(), dataMap);
8169
- if (name)
8170
- headers[name] = value;
8171
- }
8172
- return Object.keys(headers).length ? headers : undefined;
8173
- }
8174
- function appendSearchParam(url, param, term) {
8175
- if (!term)
8176
- return url;
8177
- const separator = url.includes("?") ? "&" : "?";
8178
- return `${url}${separator}${encodeURIComponent(param)}=${encodeURIComponent(term)}`;
8179
- }
8180
8209
  // lib/brick/brick.ts
8181
8210
  class Brick {
8182
8211
  type;
@@ -9207,5 +9236,5 @@ export {
9207
9236
  Base64FileUploadService
9208
9237
  };
9209
9238
 
9210
- //# debugId=BE1DBCBD4AB9F2FF64756E2164756E21
9239
+ //# debugId=7CC5CCE3A23FDF4A64756E2164756E21
9211
9240
  //# sourceMappingURL=index.js.map