@amplifyup/sdk 0.1.62 → 0.1.64

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
@@ -1,8 +1,8 @@
1
- import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as PageDataSnapshot, b as CDPAdapter, c as AmplifyUpConfig, d as EventProperties, e as AmplifyPageContextInput, f as AttachedPageEventContext, I as IdentifyInput, g as IdentifyTraits, h as ProfileFieldsInput, i as AmplifyUpTarget } from './types-Db_eLrfU.mjs';
2
- export { Z as ZoneConfig, k as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, j as resolveAmplifyUpUrls } from './types-Db_eLrfU.mjs';
1
+ import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as PageDataSnapshot, b as CDPAdapter, c as AmplifyUpConfig, d as EventProperties, e as AmplifyPageContextInput, f as AttachedPageEventContext, I as IdentifyInput, g as IdentifyTraits, h as ProfileFieldsInput, i as AmplifyUpTarget } from './types-C32MgOiv.mjs';
2
+ export { Z as ZoneConfig, k as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, j as resolveAmplifyUpUrls } from './types-C32MgOiv.mjs';
3
3
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.mjs';
4
4
  export { A as AMPLIFYUP_EDITOR_ROUTE, i as isAmplifyUpEditorRoute } from './reservedRoutes-aGgViBDM.mjs';
5
- export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-DIZjc7st.mjs';
5
+ export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-DuRilU_n.mjs';
6
6
 
7
7
  /**
8
8
  * Storage utilities for instance ID and user ID
@@ -53,6 +53,11 @@ interface EdgeResolvedComponent {
53
53
  instanceId: string;
54
54
  componentId: string;
55
55
  props: Record<string, unknown>;
56
+ /** Connection map from the snapshot — used to stamp list-row `ref`. */
57
+ resources?: Record<string, unknown>;
58
+ reads?: Record<string, {
59
+ resource: string;
60
+ }>;
56
61
  children?: Record<string, EdgeResolvedComponent[]>;
57
62
  appliedRules?: string[];
58
63
  degraded?: boolean;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as PageDataSnapshot, b as CDPAdapter, c as AmplifyUpConfig, d as EventProperties, e as AmplifyPageContextInput, f as AttachedPageEventContext, I as IdentifyInput, g as IdentifyTraits, h as ProfileFieldsInput, i as AmplifyUpTarget } from './types-Db_eLrfU.js';
2
- export { Z as ZoneConfig, k as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, j as resolveAmplifyUpUrls } from './types-Db_eLrfU.js';
1
+ import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as PageDataSnapshot, b as CDPAdapter, c as AmplifyUpConfig, d as EventProperties, e as AmplifyPageContextInput, f as AttachedPageEventContext, I as IdentifyInput, g as IdentifyTraits, h as ProfileFieldsInput, i as AmplifyUpTarget } from './types-C32MgOiv.js';
2
+ export { Z as ZoneConfig, k as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, j as resolveAmplifyUpUrls } from './types-C32MgOiv.js';
3
3
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.js';
4
4
  export { A as AMPLIFYUP_EDITOR_ROUTE, i as isAmplifyUpEditorRoute } from './reservedRoutes-aGgViBDM.js';
5
- export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-3AXnQgzO.js';
5
+ export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-BLjZYjHJ.js';
6
6
 
7
7
  /**
8
8
  * Storage utilities for instance ID and user ID
@@ -53,6 +53,11 @@ interface EdgeResolvedComponent {
53
53
  instanceId: string;
54
54
  componentId: string;
55
55
  props: Record<string, unknown>;
56
+ /** Connection map from the snapshot — used to stamp list-row `ref`. */
57
+ resources?: Record<string, unknown>;
58
+ reads?: Record<string, {
59
+ resource: string;
60
+ }>;
56
61
  children?: Record<string, EdgeResolvedComponent[]>;
57
62
  appliedRules?: string[];
58
63
  degraded?: boolean;
package/dist/index.js CHANGED
@@ -400,6 +400,16 @@ function isComposerPreview() {
400
400
 
401
401
  // src/field-envelope.ts
402
402
  var FIELDS_BRAND = Symbol("amplifyup.fields");
403
+ var IDENTIFIER_KEYS = /* @__PURE__ */ new Set([
404
+ "id",
405
+ "_id",
406
+ "slug",
407
+ "key",
408
+ "_key",
409
+ "docId",
410
+ "_type",
411
+ "type"
412
+ ]);
403
413
  function isBrandedFields(value) {
404
414
  return !!value && typeof value === "object" && FIELDS_BRAND in value;
405
415
  }
@@ -421,6 +431,70 @@ function isPortableImageShape(value) {
421
431
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
422
432
  return "url" in value;
423
433
  }
434
+ function isIdentifierKey(key) {
435
+ return IDENTIFIER_KEYS.has(key);
436
+ }
437
+ function isRecordList(value) {
438
+ if (!Array.isArray(value) || value.length === 0) return false;
439
+ const sample = value.find((item) => item != null);
440
+ if (sample === void 0) return false;
441
+ if (typeof sample !== "object" || Array.isArray(sample)) return false;
442
+ if (isPortableImageShape(sample)) return false;
443
+ if (sample.$$typeof) return false;
444
+ return true;
445
+ }
446
+ function isFieldRef(value) {
447
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
448
+ const rec = value;
449
+ return typeof rec.providerId === "string" && !!rec.providerId && typeof rec.entity === "string" && !!rec.entity && typeof rec.id === "string" && !!rec.id;
450
+ }
451
+ function isListOwner(value) {
452
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
453
+ const rec = value;
454
+ return typeof rec.providerId === "string" && !!rec.providerId && typeof rec.entity === "string" && !!rec.entity;
455
+ }
456
+ function listOwnerFromConnection(conn) {
457
+ if (!conn || typeof conn !== "object") return void 0;
458
+ if (conn.mode === "query") {
459
+ const providerId = String(conn.spec?.providerId || "").trim();
460
+ const entity = String(conn.spec?.entity || "").trim();
461
+ return providerId && entity ? { providerId, entity } : void 0;
462
+ }
463
+ if (conn.mode === "item" || conn.mode === "items") {
464
+ const providerId = String(conn.providerId || "").trim();
465
+ const entity = String(conn.entity || "").trim();
466
+ return providerId && entity ? { providerId, entity } : void 0;
467
+ }
468
+ return void 0;
469
+ }
470
+ function listOwnerFromSpec(spec) {
471
+ const providerId = String(spec?.providerId || "").trim();
472
+ const entity = String(spec?.entity || "").trim();
473
+ return providerId && entity ? { providerId, entity } : void 0;
474
+ }
475
+ function isEnvelopeSources(value) {
476
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
477
+ const rec = value;
478
+ return rec.connections != null || rec.reads != null;
479
+ }
480
+ function normalizeEnvelopeSources(sources) {
481
+ if (!sources) return {};
482
+ if (isEnvelopeSources(sources) && !("mode" in sources)) {
483
+ return sources;
484
+ }
485
+ return { connections: sources };
486
+ }
487
+ function listOwnerForField(fieldName, props, sources) {
488
+ const { connections, reads } = normalizeEnvelopeSources(sources);
489
+ const resourceName = reads?.[fieldName]?.resource || fieldName;
490
+ const fromConn = listOwnerFromConnection(connections?.[resourceName]);
491
+ if (fromConn) return fromConn;
492
+ const paging = props?.[`${fieldName}Pagination`];
493
+ if (paging && typeof paging === "object" && !Array.isArray(paging)) {
494
+ return listOwnerFromSpec(paging.spec);
495
+ }
496
+ return void 0;
497
+ }
424
498
  function joinPath(prefix, key) {
425
499
  return prefix ? `${prefix}.${key}` : key;
426
500
  }
@@ -428,39 +502,101 @@ function emptyValue(raw) {
428
502
  if (raw === void 0) return null;
429
503
  return raw;
430
504
  }
431
- function toFieldEnvelopes(source, prefix = "") {
505
+ function rowId(raw) {
506
+ const candidates = [raw.id, raw._id, raw.docId, raw.key, raw._key];
507
+ for (const c of candidates) {
508
+ if (typeof c === "string" && c.trim()) return c;
509
+ }
510
+ return "";
511
+ }
512
+ function withLeaf(envelope, scope) {
513
+ if (isFieldRef(scope?.ref)) envelope.ref = scope.ref;
514
+ else if (scope?.readOnly) envelope.readOnly = true;
515
+ return envelope;
516
+ }
517
+ function toFieldEnvelopes(source, prefix = "", scope) {
518
+ const ctx = isFieldRef(scope) ? { ref: scope } : scope || {};
432
519
  const input = source && typeof source === "object" && !Array.isArray(source) ? source : {};
433
520
  if (isBrandedFields(input)) {
434
521
  return input;
435
522
  }
436
523
  const out = {};
437
524
  for (const [key, raw] of Object.entries(input)) {
525
+ if (isIdentifierKey(key) && (typeof raw === "string" || raw == null)) {
526
+ out[key] = raw ?? "";
527
+ continue;
528
+ }
438
529
  const path = joinPath(prefix, key);
439
530
  if (isFieldEnvelope(raw)) {
440
- out[key] = { value: raw.value ?? null, name: raw.name || path };
531
+ const inner = raw.value;
532
+ if (isRecordList(inner)) {
533
+ const owner = ctx.owners?.(key);
534
+ out[key] = {
535
+ value: envelopeListRows(inner, owner),
536
+ name: raw.name || path
537
+ };
538
+ continue;
539
+ }
540
+ out[key] = withLeaf(
541
+ { value: raw.value ?? null, name: raw.name || path },
542
+ raw.ref ? { ref: raw.ref } : ctx
543
+ );
544
+ continue;
545
+ }
546
+ if (isRecordList(raw)) {
547
+ const owner = ctx.owners?.(key);
548
+ out[key] = { value: envelopeListRows(raw, owner), name: path };
441
549
  continue;
442
550
  }
443
551
  if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
444
- out[key] = toFieldEnvelopes(raw, path);
552
+ out[key] = toFieldEnvelopes(raw, path, ctx);
445
553
  continue;
446
554
  }
447
- out[key] = { value: emptyValue(raw), name: path };
555
+ out[key] = withLeaf({ value: emptyValue(raw), name: path }, ctx);
448
556
  }
449
557
  return brandFields(out);
450
558
  }
451
- function attachFieldEnvelopes(props) {
559
+ function envelopeListRows(items, owner) {
560
+ return items.map((item) => envelopeListRow(item, owner));
561
+ }
562
+ function envelopeListRow(item, owner) {
563
+ if (isBrandedFields(item) && typeof item.id === "string") {
564
+ return item;
565
+ }
566
+ const raw = item && typeof item === "object" && !Array.isArray(item) ? item : {};
567
+ const id = rowId(raw);
568
+ const ref = isListOwner(owner) && id ? { providerId: owner.providerId, entity: owner.entity, id } : void 0;
569
+ const fields = toFieldEnvelopes(raw, "", {
570
+ ref,
571
+ readOnly: !ref
572
+ });
573
+ const row = fields;
574
+ if (typeof row.id !== "string") {
575
+ row.id = id;
576
+ }
577
+ return row;
578
+ }
579
+ function attachFieldEnvelopes(props, sources) {
452
580
  const raw = props && typeof props === "object" ? { ...props } : {};
453
581
  if (isBrandedFields(raw.fields)) return raw;
454
582
  const { fields: existing, ...content } = raw;
455
583
  const source = existing && typeof existing === "object" && !isFieldEnvelope(existing) ? existing : content;
456
- return { ...raw, fields: toFieldEnvelopes(source) };
584
+ return {
585
+ ...raw,
586
+ fields: toFieldEnvelopes(source, "", {
587
+ owners: (fieldName) => listOwnerForField(fieldName, source, sources)
588
+ })
589
+ };
457
590
  }
458
591
  function walkLayoutNodes(nodes) {
459
592
  if (!Array.isArray(nodes)) return;
460
593
  for (const node of nodes) {
461
594
  if (!node || typeof node !== "object") continue;
462
595
  const rec = node;
463
- rec.props = attachFieldEnvelopes(rec.props);
596
+ rec.props = attachFieldEnvelopes(rec.props, {
597
+ connections: rec.resources,
598
+ reads: rec.reads
599
+ });
464
600
  for (const slot of rec.slots || []) {
465
601
  walkLayoutNodes(slot.children);
466
602
  }
@@ -727,7 +863,10 @@ async function fetchEdgeResolve(options) {
727
863
  return envelopeResolvedPayload(body);
728
864
  }
729
865
  function envelopeResolvedComponent(node) {
730
- node.props = attachFieldEnvelopes(node.props);
866
+ node.props = attachFieldEnvelopes(node.props, {
867
+ connections: node.resources,
868
+ reads: node.reads
869
+ });
731
870
  if (!node.children) return;
732
871
  for (const kids of Object.values(node.children)) {
733
872
  for (const child of kids || []) envelopeResolvedComponent(child);
@@ -986,7 +1125,7 @@ async function fetchEdgeQuery(options) {
986
1125
  async function queryContent(options) {
987
1126
  const target = resolveAmplifyUpTarget({ configTarget: options.target });
988
1127
  const { edgeUrl } = resolveAmplifyUpUrls(target);
989
- return fetchEdgeQuery({
1128
+ const raw = await fetchEdgeQuery({
990
1129
  edgeUrl,
991
1130
  trackingId: options.trackingId,
992
1131
  route: options.route,
@@ -995,6 +1134,13 @@ async function queryContent(options) {
995
1134
  fetch: options.fetch,
996
1135
  signal: options.signal
997
1136
  });
1137
+ return {
1138
+ ...raw,
1139
+ results: envelopeListRows(
1140
+ raw.results,
1141
+ listOwnerFromSpec(options.spec)
1142
+ )
1143
+ };
998
1144
  }
999
1145
  function nextPageSpec(pagination) {
1000
1146
  return { ...pagination.spec, offset: pagination.nextOffset };