@amplifyup/sdk 0.1.61 → 0.1.62

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.mjs CHANGED
@@ -394,6 +394,81 @@ function isComposerPreview() {
394
394
  return false;
395
395
  }
396
396
 
397
+ // src/field-envelope.ts
398
+ var FIELDS_BRAND = Symbol("amplifyup.fields");
399
+ function isBrandedFields(value) {
400
+ return !!value && typeof value === "object" && FIELDS_BRAND in value;
401
+ }
402
+ function brandFields(bag) {
403
+ if (isBrandedFields(bag)) return bag;
404
+ Object.defineProperty(bag, FIELDS_BRAND, {
405
+ value: true,
406
+ enumerable: false,
407
+ configurable: false
408
+ });
409
+ return bag;
410
+ }
411
+ function isFieldEnvelope(value) {
412
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
413
+ const rec = value;
414
+ return typeof rec.name === "string" && "value" in rec && !("url" in rec);
415
+ }
416
+ function isPortableImageShape(value) {
417
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
418
+ return "url" in value;
419
+ }
420
+ function joinPath(prefix, key) {
421
+ return prefix ? `${prefix}.${key}` : key;
422
+ }
423
+ function emptyValue(raw) {
424
+ if (raw === void 0) return null;
425
+ return raw;
426
+ }
427
+ function toFieldEnvelopes(source, prefix = "") {
428
+ const input = source && typeof source === "object" && !Array.isArray(source) ? source : {};
429
+ if (isBrandedFields(input)) {
430
+ return input;
431
+ }
432
+ const out = {};
433
+ for (const [key, raw] of Object.entries(input)) {
434
+ const path = joinPath(prefix, key);
435
+ if (isFieldEnvelope(raw)) {
436
+ out[key] = { value: raw.value ?? null, name: raw.name || path };
437
+ continue;
438
+ }
439
+ if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
440
+ out[key] = toFieldEnvelopes(raw, path);
441
+ continue;
442
+ }
443
+ out[key] = { value: emptyValue(raw), name: path };
444
+ }
445
+ return brandFields(out);
446
+ }
447
+ function attachFieldEnvelopes(props) {
448
+ const raw = props && typeof props === "object" ? { ...props } : {};
449
+ if (isBrandedFields(raw.fields)) return raw;
450
+ const { fields: existing, ...content } = raw;
451
+ const source = existing && typeof existing === "object" && !isFieldEnvelope(existing) ? existing : content;
452
+ return { ...raw, fields: toFieldEnvelopes(source) };
453
+ }
454
+ function walkLayoutNodes(nodes) {
455
+ if (!Array.isArray(nodes)) return;
456
+ for (const node of nodes) {
457
+ if (!node || typeof node !== "object") continue;
458
+ const rec = node;
459
+ rec.props = attachFieldEnvelopes(rec.props);
460
+ for (const slot of rec.slots || []) {
461
+ walkLayoutNodes(slot.children);
462
+ }
463
+ }
464
+ }
465
+ function envelopePageConfig(page2) {
466
+ if (!page2 || typeof page2 !== "object") return page2 ?? null;
467
+ const tree = page2.layoutTree;
468
+ if (Array.isArray(tree)) walkLayoutNodes(tree);
469
+ return page2;
470
+ }
471
+
397
472
  // src/page-context.ts
398
473
  var defaultLog = {
399
474
  warn: (...args) => {
@@ -645,7 +720,25 @@ async function fetchEdgeResolve(options) {
645
720
  body
646
721
  );
647
722
  }
648
- return body;
723
+ return envelopeResolvedPayload(body);
724
+ }
725
+ function envelopeResolvedComponent(node) {
726
+ node.props = attachFieldEnvelopes(node.props);
727
+ if (!node.children) return;
728
+ for (const kids of Object.values(node.children)) {
729
+ for (const child of kids || []) envelopeResolvedComponent(child);
730
+ }
731
+ }
732
+ function envelopeResolvedPayload(payload) {
733
+ if (payload.tree) {
734
+ for (const node of payload.tree) envelopeResolvedComponent(node);
735
+ }
736
+ if (payload.zones) {
737
+ for (const roots of Object.values(payload.zones)) {
738
+ for (const node of roots || []) envelopeResolvedComponent(node);
739
+ }
740
+ }
741
+ return payload;
649
742
  }
650
743
 
651
744
  // src/edge/mapResolvedToPageConfig.ts
@@ -705,7 +798,9 @@ async function fetchContent(options) {
705
798
  const preview = options.preview ?? (typeof window !== "undefined" ? isComposerPreview() : false);
706
799
  if (preview) {
707
800
  try {
708
- const page2 = await options.fetchOrchestratorPage(options.route, true);
801
+ const page2 = envelopePageConfig(
802
+ await options.fetchOrchestratorPage(options.route, true)
803
+ );
709
804
  return {
710
805
  pageConfig: page2,
711
806
  source: "orchestrator",
@@ -1975,7 +2070,7 @@ Available Console Commands:
1975
2070
  this.refreshEventTracking();
1976
2071
  }, 800);
1977
2072
  }
1978
- return pageConfig;
2073
+ return envelopePageConfig(pageConfig);
1979
2074
  }
1980
2075
  /**
1981
2076
  * Set up view-level event tracking based on configuration