@amplifyup/sdk 0.1.61 → 0.1.63

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,118 @@ 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 isEntryRefItem(value) {
421
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
422
+ const rec = value;
423
+ return typeof rec.id === "string" && rec.id.trim().length > 0 || typeof rec._id === "string" && rec._id.trim().length > 0 || typeof rec.docId === "string" && rec.docId.trim().length > 0;
424
+ }
425
+ function isRepeaterArray(value) {
426
+ if (!Array.isArray(value) || value.length === 0) return false;
427
+ const sample = value.find((item) => item != null);
428
+ if (sample === void 0) return false;
429
+ if (typeof sample !== "object" || Array.isArray(sample)) return false;
430
+ if (isPortableImageShape(sample)) return false;
431
+ if (isEntryRefItem(sample)) return false;
432
+ if (sample.$$typeof) return false;
433
+ return true;
434
+ }
435
+ function joinPath(prefix, key) {
436
+ return prefix ? `${prefix}.${key}` : key;
437
+ }
438
+ function emptyValue(raw) {
439
+ if (raw === void 0) return null;
440
+ return raw;
441
+ }
442
+ function toFieldEnvelopes(source, prefix = "") {
443
+ const input = source && typeof source === "object" && !Array.isArray(source) ? source : {};
444
+ if (isBrandedFields(input)) {
445
+ return input;
446
+ }
447
+ const out = {};
448
+ for (const [key, raw] of Object.entries(input)) {
449
+ const path = joinPath(prefix, key);
450
+ if (isFieldEnvelope(raw)) {
451
+ const inner = raw.value;
452
+ if (isRepeaterArray(inner)) {
453
+ out[key] = {
454
+ value: envelopeRepeaterItems(inner, raw.name || path),
455
+ name: raw.name || path
456
+ };
457
+ continue;
458
+ }
459
+ out[key] = { value: raw.value ?? null, name: raw.name || path };
460
+ continue;
461
+ }
462
+ if (isRepeaterArray(raw)) {
463
+ out[key] = { value: envelopeRepeaterItems(raw, path), name: path };
464
+ continue;
465
+ }
466
+ if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
467
+ out[key] = toFieldEnvelopes(raw, path);
468
+ continue;
469
+ }
470
+ out[key] = { value: emptyValue(raw), name: path };
471
+ }
472
+ return brandFields(out);
473
+ }
474
+ function envelopeRepeaterItems(items, prefix) {
475
+ return items.map((item, i) => {
476
+ const path = joinPath(prefix, String(i));
477
+ if (isBrandedFields(item)) return item;
478
+ if (item && typeof item === "object" && !Array.isArray(item)) {
479
+ return toFieldEnvelopes(item, path);
480
+ }
481
+ return toFieldEnvelopes({}, path);
482
+ });
483
+ }
484
+ function attachFieldEnvelopes(props) {
485
+ const raw = props && typeof props === "object" ? { ...props } : {};
486
+ if (isBrandedFields(raw.fields)) return raw;
487
+ const { fields: existing, ...content } = raw;
488
+ const source = existing && typeof existing === "object" && !isFieldEnvelope(existing) ? existing : content;
489
+ return { ...raw, fields: toFieldEnvelopes(source) };
490
+ }
491
+ function walkLayoutNodes(nodes) {
492
+ if (!Array.isArray(nodes)) return;
493
+ for (const node of nodes) {
494
+ if (!node || typeof node !== "object") continue;
495
+ const rec = node;
496
+ rec.props = attachFieldEnvelopes(rec.props);
497
+ for (const slot of rec.slots || []) {
498
+ walkLayoutNodes(slot.children);
499
+ }
500
+ }
501
+ }
502
+ function envelopePageConfig(page2) {
503
+ if (!page2 || typeof page2 !== "object") return page2 ?? null;
504
+ const tree = page2.layoutTree;
505
+ if (Array.isArray(tree)) walkLayoutNodes(tree);
506
+ return page2;
507
+ }
508
+
397
509
  // src/page-context.ts
398
510
  var defaultLog = {
399
511
  warn: (...args) => {
@@ -645,7 +757,25 @@ async function fetchEdgeResolve(options) {
645
757
  body
646
758
  );
647
759
  }
648
- return body;
760
+ return envelopeResolvedPayload(body);
761
+ }
762
+ function envelopeResolvedComponent(node) {
763
+ node.props = attachFieldEnvelopes(node.props);
764
+ if (!node.children) return;
765
+ for (const kids of Object.values(node.children)) {
766
+ for (const child of kids || []) envelopeResolvedComponent(child);
767
+ }
768
+ }
769
+ function envelopeResolvedPayload(payload) {
770
+ if (payload.tree) {
771
+ for (const node of payload.tree) envelopeResolvedComponent(node);
772
+ }
773
+ if (payload.zones) {
774
+ for (const roots of Object.values(payload.zones)) {
775
+ for (const node of roots || []) envelopeResolvedComponent(node);
776
+ }
777
+ }
778
+ return payload;
649
779
  }
650
780
 
651
781
  // src/edge/mapResolvedToPageConfig.ts
@@ -705,7 +835,9 @@ async function fetchContent(options) {
705
835
  const preview = options.preview ?? (typeof window !== "undefined" ? isComposerPreview() : false);
706
836
  if (preview) {
707
837
  try {
708
- const page2 = await options.fetchOrchestratorPage(options.route, true);
838
+ const page2 = envelopePageConfig(
839
+ await options.fetchOrchestratorPage(options.route, true)
840
+ );
709
841
  return {
710
842
  pageConfig: page2,
711
843
  source: "orchestrator",
@@ -1975,7 +2107,7 @@ Available Console Commands:
1975
2107
  this.refreshEventTracking();
1976
2108
  }, 800);
1977
2109
  }
1978
- return pageConfig;
2110
+ return envelopePageConfig(pageConfig);
1979
2111
  }
1980
2112
  /**
1981
2113
  * Set up view-level event tracking based on configuration