@amplifyup/sdk 0.3.0 → 0.3.1-uat.105.g9d5f4eb

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.mts CHANGED
@@ -165,7 +165,12 @@ interface components {
165
165
  id: string;
166
166
  key: string;
167
167
  version: number;
168
+ title?: string;
169
+ intro?: string;
170
+ /** @description Every field, in order. Renderers that ignore `steps` show these on one page. */
168
171
  fields: components["schemas"]["FormField"][];
172
+ /** @description Headings, paragraphs and fields per step. Absent means one step with `fields` in order. */
173
+ steps?: components["schemas"]["FormStep"][];
169
174
  submit: components["schemas"]["FormSubmitSettings"];
170
175
  onSuccess: components["schemas"]["FormOnSuccess"];
171
176
  honeypot: components["schemas"]["FormHoneypot"];
@@ -177,27 +182,55 @@ interface components {
177
182
  label?: string;
178
183
  required?: boolean;
179
184
  placeholder?: string;
180
- /** @description For `select`. */
185
+ /** @description For `select`, `radio` and `checkboxes`. */
181
186
  options?: components["schemas"]["FormFieldOption"][];
182
187
  /** @description Initial value; the posted value for `hidden`. */
183
188
  defaultValue?: string;
189
+ /** @description Half-width fields sit side by side on wide screens. Defaults to full. */
190
+ width?: components["schemas"]["FormFieldWidth"];
191
+ /** @description For `hidden`: filled from this parameter of the page URL, when present. */
192
+ fromQuery?: components["schemas"]["FormQueryParam"];
184
193
  };
185
194
  FormFieldOption: {
186
195
  label: string;
187
196
  value: string;
188
197
  };
189
198
  /**
190
- * @description Delivery API for published forms, as the form packages see it. GET /v1/forms/{formId}?trackingId= → FormDefinition POST /v1/forms/{formId}/submit?trackingId= → SubmitFormSuccess | 422 SubmitFormValidationError
199
+ * @description Delivery API for published forms, as the form packages see it. GET /v1/forms/{formId}?trackingId= → FormDefinition POST /v1/forms/{formId}/submit?trackingId= → SubmitFormSuccess | 422 SubmitFormValidationError Optional header `x-amplifyup-consent: granted | denied` — what the site's consent banner reported.
191
200
  *
192
201
  * Source of truth for `openapi/delivery.json` (scripts/generate-openapi.mjs). Never carries mapping metadata: what a submission writes to is platform-only.
193
202
  * @enum {string}
194
203
  */
195
- FormFieldType: "text" | "email" | "phone" | "textarea" | "select" | "checkbox" | "hidden";
204
+ FormFieldType: "text" | "email" | "phone" | "number" | "date" | "textarea" | "select" | "radio" | "checkboxes" | "checkbox" | "consent" | "hidden";
205
+ /** @enum {string} */
206
+ FormFieldWidth: "full" | "half";
196
207
  FormHoneypot: {
197
208
  /** @description Field name to post empty; bots that fill it are dropped. */
198
209
  name: string;
199
210
  };
200
211
  FormOnSuccess: components["schemas"]["FormSuccessMessage"] | components["schemas"]["FormSuccessRedirect"];
212
+ /**
213
+ * @description UTM parameters a hidden field can be filled from.
214
+ * @enum {string}
215
+ */
216
+ FormQueryParam: "utm_source" | "utm_medium" | "utm_campaign" | "utm_term" | "utm_content";
217
+ /** @description One page of a multi-step form, in display order. */
218
+ FormStep: {
219
+ title?: string;
220
+ items: components["schemas"]["FormStepItem"][];
221
+ };
222
+ FormStepField: {
223
+ /** @constant */
224
+ kind: "field";
225
+ /** @description A key in `fields`. */
226
+ key: string;
227
+ };
228
+ FormStepItem: components["schemas"]["FormStepField"] | components["schemas"]["FormStepText"];
229
+ FormStepText: {
230
+ /** @enum {string} */
231
+ kind: "heading" | "paragraph";
232
+ text: string;
233
+ };
201
234
  FormSubmitSettings: {
202
235
  label: string;
203
236
  };
@@ -211,12 +244,15 @@ interface components {
211
244
  type: "redirect";
212
245
  url: string;
213
246
  };
214
- FormValue: string | boolean;
247
+ /** @description Text for most fields, true/false for `checkbox` and `consent`, the chosen values for `checkboxes`. */
248
+ FormValue: string | boolean | string[];
215
249
  SubmitFormRequest: {
216
250
  /** @description Field values by key, including the honeypot key. */
217
251
  values: {
218
252
  [key: string]: components["schemas"]["FormValue"];
219
253
  };
254
+ /** @description The page the form was on. Only its path and UTM parameters are kept. */
255
+ page?: string;
220
256
  };
221
257
  SubmitFormSuccess: {
222
258
  onSuccess: components["schemas"]["FormOnSuccess"];
@@ -351,9 +387,23 @@ declare const getFormDefinition: (formId: string, options?: FormRequestOptions)
351
387
  /**
352
388
  * Submit a form. Field errors (422) come back as `{ ok: false, errors }`;
353
389
  * anything else that fails throws. Never submits from a Composer preview.
390
+ * Sends the visitor's consent (see `setConsent`) and the page it was on;
391
+ * only the page's path and UTM parameters are kept.
354
392
  */
355
393
  declare const submitForm: (formId: string, values: FormValues, options?: FormRequestOptions) => Promise<SubmitFormResult>;
356
394
 
395
+ /**
396
+ * What the site's consent banner reported for this visitor. Amplify UP sends
397
+ * it with form submissions; without it, answers are kept only if the site is
398
+ * set to treat visitors who haven't chosen as agreed.
399
+ *
400
+ * Call `setConsent('granted')` or `setConsent('denied')` whenever your banner
401
+ * learns the visitor's choice, and `setConsent(null)` to forget it.
402
+ */
403
+ type ConsentState = 'granted' | 'denied';
404
+ declare function setConsent(state: ConsentState | null): void;
405
+ declare function getConsent(): ConsentState | null;
406
+
357
407
  /**
358
408
  * Map Edge /v1/resolve payload → PageConfig for AmplifyRenderer.
359
409
  * Prefers `tree` (full page skeleton with zones spliced in); falls back to
@@ -829,4 +879,4 @@ declare const verifyAWSConnection: () => {
829
879
 
830
880
  declare const _default: AmplifyUpSDK;
831
881
 
832
- export { ANON_COOKIE_NAME, AmplifyContentMeta, AmplifyPageContextInput, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, ContentSource, DWELL_ACTIVITY_IDLE_MS, DeliveryRequestError, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, type FormDefinition, type FormField, type FormFieldOption, type FormFieldType, type FormOnSuccess, type FormValue, type FormValues, IdentifyInput, IdentifyTraits, PageConfig, PageDataSnapshot, PageTaxonomies, ProfileFieldsInput, SESSION_COOKIE_NAME, SESSION_IDLE_GAP_MS, type SubmitFormResult, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getFormDefinition, getInstanceId, getOrchestratorUrl, getSDK, getSessionId, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, submitForm, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
882
+ export { ANON_COOKIE_NAME, AmplifyContentMeta, AmplifyPageContextInput, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, type ConsentState, ContentSource, DWELL_ACTIVITY_IDLE_MS, DeliveryRequestError, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, type FormDefinition, type FormField, type FormFieldOption, type FormFieldType, type FormOnSuccess, type FormValue, type FormValues, IdentifyInput, IdentifyTraits, PageConfig, PageDataSnapshot, PageTaxonomies, ProfileFieldsInput, SESSION_COOKIE_NAME, SESSION_IDLE_GAP_MS, type SubmitFormResult, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getConsent, getDiagnostics, getFormDefinition, getInstanceId, getOrchestratorUrl, getSDK, getSessionId, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setConsent, setProfileFields, setupComponentViewTracking, setupEventTracking, submitForm, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
package/dist/index.d.ts CHANGED
@@ -165,7 +165,12 @@ interface components {
165
165
  id: string;
166
166
  key: string;
167
167
  version: number;
168
+ title?: string;
169
+ intro?: string;
170
+ /** @description Every field, in order. Renderers that ignore `steps` show these on one page. */
168
171
  fields: components["schemas"]["FormField"][];
172
+ /** @description Headings, paragraphs and fields per step. Absent means one step with `fields` in order. */
173
+ steps?: components["schemas"]["FormStep"][];
169
174
  submit: components["schemas"]["FormSubmitSettings"];
170
175
  onSuccess: components["schemas"]["FormOnSuccess"];
171
176
  honeypot: components["schemas"]["FormHoneypot"];
@@ -177,27 +182,55 @@ interface components {
177
182
  label?: string;
178
183
  required?: boolean;
179
184
  placeholder?: string;
180
- /** @description For `select`. */
185
+ /** @description For `select`, `radio` and `checkboxes`. */
181
186
  options?: components["schemas"]["FormFieldOption"][];
182
187
  /** @description Initial value; the posted value for `hidden`. */
183
188
  defaultValue?: string;
189
+ /** @description Half-width fields sit side by side on wide screens. Defaults to full. */
190
+ width?: components["schemas"]["FormFieldWidth"];
191
+ /** @description For `hidden`: filled from this parameter of the page URL, when present. */
192
+ fromQuery?: components["schemas"]["FormQueryParam"];
184
193
  };
185
194
  FormFieldOption: {
186
195
  label: string;
187
196
  value: string;
188
197
  };
189
198
  /**
190
- * @description Delivery API for published forms, as the form packages see it. GET /v1/forms/{formId}?trackingId= → FormDefinition POST /v1/forms/{formId}/submit?trackingId= → SubmitFormSuccess | 422 SubmitFormValidationError
199
+ * @description Delivery API for published forms, as the form packages see it. GET /v1/forms/{formId}?trackingId= → FormDefinition POST /v1/forms/{formId}/submit?trackingId= → SubmitFormSuccess | 422 SubmitFormValidationError Optional header `x-amplifyup-consent: granted | denied` — what the site's consent banner reported.
191
200
  *
192
201
  * Source of truth for `openapi/delivery.json` (scripts/generate-openapi.mjs). Never carries mapping metadata: what a submission writes to is platform-only.
193
202
  * @enum {string}
194
203
  */
195
- FormFieldType: "text" | "email" | "phone" | "textarea" | "select" | "checkbox" | "hidden";
204
+ FormFieldType: "text" | "email" | "phone" | "number" | "date" | "textarea" | "select" | "radio" | "checkboxes" | "checkbox" | "consent" | "hidden";
205
+ /** @enum {string} */
206
+ FormFieldWidth: "full" | "half";
196
207
  FormHoneypot: {
197
208
  /** @description Field name to post empty; bots that fill it are dropped. */
198
209
  name: string;
199
210
  };
200
211
  FormOnSuccess: components["schemas"]["FormSuccessMessage"] | components["schemas"]["FormSuccessRedirect"];
212
+ /**
213
+ * @description UTM parameters a hidden field can be filled from.
214
+ * @enum {string}
215
+ */
216
+ FormQueryParam: "utm_source" | "utm_medium" | "utm_campaign" | "utm_term" | "utm_content";
217
+ /** @description One page of a multi-step form, in display order. */
218
+ FormStep: {
219
+ title?: string;
220
+ items: components["schemas"]["FormStepItem"][];
221
+ };
222
+ FormStepField: {
223
+ /** @constant */
224
+ kind: "field";
225
+ /** @description A key in `fields`. */
226
+ key: string;
227
+ };
228
+ FormStepItem: components["schemas"]["FormStepField"] | components["schemas"]["FormStepText"];
229
+ FormStepText: {
230
+ /** @enum {string} */
231
+ kind: "heading" | "paragraph";
232
+ text: string;
233
+ };
201
234
  FormSubmitSettings: {
202
235
  label: string;
203
236
  };
@@ -211,12 +244,15 @@ interface components {
211
244
  type: "redirect";
212
245
  url: string;
213
246
  };
214
- FormValue: string | boolean;
247
+ /** @description Text for most fields, true/false for `checkbox` and `consent`, the chosen values for `checkboxes`. */
248
+ FormValue: string | boolean | string[];
215
249
  SubmitFormRequest: {
216
250
  /** @description Field values by key, including the honeypot key. */
217
251
  values: {
218
252
  [key: string]: components["schemas"]["FormValue"];
219
253
  };
254
+ /** @description The page the form was on. Only its path and UTM parameters are kept. */
255
+ page?: string;
220
256
  };
221
257
  SubmitFormSuccess: {
222
258
  onSuccess: components["schemas"]["FormOnSuccess"];
@@ -351,9 +387,23 @@ declare const getFormDefinition: (formId: string, options?: FormRequestOptions)
351
387
  /**
352
388
  * Submit a form. Field errors (422) come back as `{ ok: false, errors }`;
353
389
  * anything else that fails throws. Never submits from a Composer preview.
390
+ * Sends the visitor's consent (see `setConsent`) and the page it was on;
391
+ * only the page's path and UTM parameters are kept.
354
392
  */
355
393
  declare const submitForm: (formId: string, values: FormValues, options?: FormRequestOptions) => Promise<SubmitFormResult>;
356
394
 
395
+ /**
396
+ * What the site's consent banner reported for this visitor. Amplify UP sends
397
+ * it with form submissions; without it, answers are kept only if the site is
398
+ * set to treat visitors who haven't chosen as agreed.
399
+ *
400
+ * Call `setConsent('granted')` or `setConsent('denied')` whenever your banner
401
+ * learns the visitor's choice, and `setConsent(null)` to forget it.
402
+ */
403
+ type ConsentState = 'granted' | 'denied';
404
+ declare function setConsent(state: ConsentState | null): void;
405
+ declare function getConsent(): ConsentState | null;
406
+
357
407
  /**
358
408
  * Map Edge /v1/resolve payload → PageConfig for AmplifyRenderer.
359
409
  * Prefers `tree` (full page skeleton with zones spliced in); falls back to
@@ -829,4 +879,4 @@ declare const verifyAWSConnection: () => {
829
879
 
830
880
  declare const _default: AmplifyUpSDK;
831
881
 
832
- export { ANON_COOKIE_NAME, AmplifyContentMeta, AmplifyPageContextInput, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, ContentSource, DWELL_ACTIVITY_IDLE_MS, DeliveryRequestError, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, type FormDefinition, type FormField, type FormFieldOption, type FormFieldType, type FormOnSuccess, type FormValue, type FormValues, IdentifyInput, IdentifyTraits, PageConfig, PageDataSnapshot, PageTaxonomies, ProfileFieldsInput, SESSION_COOKIE_NAME, SESSION_IDLE_GAP_MS, type SubmitFormResult, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getFormDefinition, getInstanceId, getOrchestratorUrl, getSDK, getSessionId, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, submitForm, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
882
+ export { ANON_COOKIE_NAME, AmplifyContentMeta, AmplifyPageContextInput, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, type ConsentState, ContentSource, DWELL_ACTIVITY_IDLE_MS, DeliveryRequestError, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, type FormDefinition, type FormField, type FormFieldOption, type FormFieldType, type FormOnSuccess, type FormValue, type FormValues, IdentifyInput, IdentifyTraits, PageConfig, PageDataSnapshot, PageTaxonomies, ProfileFieldsInput, SESSION_COOKIE_NAME, SESSION_IDLE_GAP_MS, type SubmitFormResult, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getConsent, getDiagnostics, getFormDefinition, getInstanceId, getOrchestratorUrl, getSDK, getSessionId, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setConsent, setProfileFields, setupComponentViewTracking, setupEventTracking, submitForm, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
package/dist/index.js CHANGED
@@ -1132,6 +1132,39 @@ async function fetchContent(options) {
1132
1132
  }
1133
1133
  }
1134
1134
 
1135
+ // src/consent.ts
1136
+ var STORAGE_KEY = "amplifyup_consent";
1137
+ var current = null;
1138
+ var loaded = false;
1139
+ function readStored() {
1140
+ try {
1141
+ const value = typeof window !== "undefined" ? window.localStorage.getItem(STORAGE_KEY) : null;
1142
+ return value === "granted" || value === "denied" ? value : null;
1143
+ } catch {
1144
+ return null;
1145
+ }
1146
+ }
1147
+ function writeStored(state) {
1148
+ try {
1149
+ if (typeof window === "undefined") return;
1150
+ if (state) window.localStorage.setItem(STORAGE_KEY, state);
1151
+ else window.localStorage.removeItem(STORAGE_KEY);
1152
+ } catch {
1153
+ }
1154
+ }
1155
+ function setConsent(state) {
1156
+ current = state;
1157
+ loaded = true;
1158
+ writeStored(state);
1159
+ }
1160
+ function getConsent() {
1161
+ if (!loaded) {
1162
+ current = readStored();
1163
+ loaded = true;
1164
+ }
1165
+ return current;
1166
+ }
1167
+
1135
1168
  // src/delivery/forms.ts
1136
1169
  var DeliveryRequestError = class extends Error {
1137
1170
  constructor(message, status) {
@@ -1171,10 +1204,16 @@ var submitForm = async (formId, values, options = {}) => {
1171
1204
  throw new DeliveryRequestError("Forms do not submit in preview.", 0);
1172
1205
  }
1173
1206
  const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
1207
+ const consent = getConsent();
1208
+ const page2 = typeof window !== "undefined" ? window.location.href : void 0;
1174
1209
  const response = await fetchFn(formUrl(formId, "/submit"), {
1175
1210
  method: "POST",
1176
- headers: { Accept: "application/json", "Content-Type": "application/json" },
1177
- body: JSON.stringify({ values })
1211
+ headers: {
1212
+ Accept: "application/json",
1213
+ "Content-Type": "application/json",
1214
+ ...consent ? { "x-amplifyup-consent": consent } : {}
1215
+ },
1216
+ body: JSON.stringify({ values, page: page2 })
1178
1217
  });
1179
1218
  if (response.status === 422) {
1180
1219
  const body2 = await response.json();
@@ -3629,16 +3668,16 @@ Available Console Commands:
3629
3668
  }
3630
3669
  buildComponentHierarchy(element) {
3631
3670
  const hierarchy = [];
3632
- let current = element;
3671
+ let current2 = element;
3633
3672
  let sawPageSlot = false;
3634
- while (current) {
3635
- if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id") || current.hasAttribute("data-node-id") || current.hasAttribute("data-amplifyup-node")) {
3636
- hierarchy.push(current);
3637
- if (current.getAttribute("data-slot-source") === "page") {
3673
+ while (current2) {
3674
+ if (current2.hasAttribute("data-amplifyup-component") || current2.hasAttribute("data-component-id") || current2.hasAttribute("data-amplifyup-slot") || current2.hasAttribute("data-slot-id") || current2.hasAttribute("data-node-id") || current2.hasAttribute("data-amplifyup-node")) {
3675
+ hierarchy.push(current2);
3676
+ if (current2.getAttribute("data-slot-source") === "page") {
3638
3677
  sawPageSlot = true;
3639
3678
  }
3640
3679
  }
3641
- current = current.parentElement;
3680
+ current2 = current2.parentElement;
3642
3681
  }
3643
3682
  const ordered = hierarchy.reverse();
3644
3683
  if (!sawPageSlot) {
@@ -3880,6 +3919,7 @@ exports.fetchEdgeQuery = fetchEdgeQuery;
3880
3919
  exports.fetchEdgeResolve = fetchEdgeResolve;
3881
3920
  exports.fetchEdgeSelect = fetchEdgeSelect;
3882
3921
  exports.fetchPageConfig = fetchPageConfig;
3922
+ exports.getConsent = getConsent;
3883
3923
  exports.getDiagnostics = getDiagnostics;
3884
3924
  exports.getFormDefinition = getFormDefinition;
3885
3925
  exports.getInstanceId = getInstanceId2;
@@ -3910,6 +3950,7 @@ exports.resolveAmplifyUpUrls = resolveAmplifyUpUrls;
3910
3950
  exports.routeChange = routeChange;
3911
3951
  exports.searchSpec = searchSpec;
3912
3952
  exports.selectVariants = selectVariants;
3953
+ exports.setConsent = setConsent;
3913
3954
  exports.setProfileFields = setProfileFields;
3914
3955
  exports.setupComponentViewTracking = setupComponentViewTracking;
3915
3956
  exports.setupEventTracking = setupEventTracking;