@prenta/import 0.5.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.
Files changed (144) hide show
  1. package/CHANGELOG.md +686 -0
  2. package/LICENSE +21 -0
  3. package/README.md +24 -0
  4. package/dist/adapter.d.ts +47 -0
  5. package/dist/adapter.d.ts.map +1 -0
  6. package/dist/adapter.js +60 -0
  7. package/dist/adapter.js.map +1 -0
  8. package/dist/adapters/contentful/asset.d.ts +47 -0
  9. package/dist/adapters/contentful/asset.d.ts.map +1 -0
  10. package/dist/adapters/contentful/asset.js +88 -0
  11. package/dist/adapters/contentful/asset.js.map +1 -0
  12. package/dist/adapters/contentful/index.d.ts +24 -0
  13. package/dist/adapters/contentful/index.d.ts.map +1 -0
  14. package/dist/adapters/contentful/index.js +242 -0
  15. package/dist/adapters/contentful/index.js.map +1 -0
  16. package/dist/adapters/contentful/locale.d.ts +66 -0
  17. package/dist/adapters/contentful/locale.d.ts.map +1 -0
  18. package/dist/adapters/contentful/locale.js +125 -0
  19. package/dist/adapters/contentful/locale.js.map +1 -0
  20. package/dist/adapters/contentful/map.d.ts +69 -0
  21. package/dist/adapters/contentful/map.d.ts.map +1 -0
  22. package/dist/adapters/contentful/map.js +174 -0
  23. package/dist/adapters/contentful/map.js.map +1 -0
  24. package/dist/adapters/contentful/rich-text.d.ts +52 -0
  25. package/dist/adapters/contentful/rich-text.d.ts.map +1 -0
  26. package/dist/adapters/contentful/rich-text.js +95 -0
  27. package/dist/adapters/contentful/rich-text.js.map +1 -0
  28. package/dist/adapters/contentful/types.d.ts +189 -0
  29. package/dist/adapters/contentful/types.d.ts.map +1 -0
  30. package/dist/adapters/contentful/types.js +26 -0
  31. package/dist/adapters/contentful/types.js.map +1 -0
  32. package/dist/adapters/identity.d.ts +27 -0
  33. package/dist/adapters/identity.d.ts.map +1 -0
  34. package/dist/adapters/identity.js +116 -0
  35. package/dist/adapters/identity.js.map +1 -0
  36. package/dist/adapters/sanity/asset.d.ts +45 -0
  37. package/dist/adapters/sanity/asset.d.ts.map +1 -0
  38. package/dist/adapters/sanity/asset.js +79 -0
  39. package/dist/adapters/sanity/asset.js.map +1 -0
  40. package/dist/adapters/sanity/index.d.ts +19 -0
  41. package/dist/adapters/sanity/index.d.ts.map +1 -0
  42. package/dist/adapters/sanity/index.js +165 -0
  43. package/dist/adapters/sanity/index.js.map +1 -0
  44. package/dist/adapters/sanity/map.d.ts +75 -0
  45. package/dist/adapters/sanity/map.d.ts.map +1 -0
  46. package/dist/adapters/sanity/map.js +245 -0
  47. package/dist/adapters/sanity/map.js.map +1 -0
  48. package/dist/adapters/sanity/parse.d.ts +64 -0
  49. package/dist/adapters/sanity/parse.d.ts.map +1 -0
  50. package/dist/adapters/sanity/parse.js +71 -0
  51. package/dist/adapters/sanity/parse.js.map +1 -0
  52. package/dist/adapters/sanity/portable-text.d.ts +64 -0
  53. package/dist/adapters/sanity/portable-text.d.ts.map +1 -0
  54. package/dist/adapters/sanity/portable-text.js +112 -0
  55. package/dist/adapters/sanity/portable-text.js.map +1 -0
  56. package/dist/adapters/sanity/types.d.ts +182 -0
  57. package/dist/adapters/sanity/types.d.ts.map +1 -0
  58. package/dist/adapters/sanity/types.js +17 -0
  59. package/dist/adapters/sanity/types.js.map +1 -0
  60. package/dist/adapters/strapi/asset.d.ts +56 -0
  61. package/dist/adapters/strapi/asset.d.ts.map +1 -0
  62. package/dist/adapters/strapi/asset.js +94 -0
  63. package/dist/adapters/strapi/asset.js.map +1 -0
  64. package/dist/adapters/strapi/index.d.ts +20 -0
  65. package/dist/adapters/strapi/index.d.ts.map +1 -0
  66. package/dist/adapters/strapi/index.js +205 -0
  67. package/dist/adapters/strapi/index.js.map +1 -0
  68. package/dist/adapters/strapi/links.d.ts +79 -0
  69. package/dist/adapters/strapi/links.d.ts.map +1 -0
  70. package/dist/adapters/strapi/links.js +98 -0
  71. package/dist/adapters/strapi/links.js.map +1 -0
  72. package/dist/adapters/strapi/loader.d.ts +68 -0
  73. package/dist/adapters/strapi/loader.d.ts.map +1 -0
  74. package/dist/adapters/strapi/loader.js +177 -0
  75. package/dist/adapters/strapi/loader.js.map +1 -0
  76. package/dist/adapters/strapi/map.d.ts +53 -0
  77. package/dist/adapters/strapi/map.d.ts.map +1 -0
  78. package/dist/adapters/strapi/map.js +193 -0
  79. package/dist/adapters/strapi/map.js.map +1 -0
  80. package/dist/adapters/strapi/types.d.ts +174 -0
  81. package/dist/adapters/strapi/types.d.ts.map +1 -0
  82. package/dist/adapters/strapi/types.js +31 -0
  83. package/dist/adapters/strapi/types.js.map +1 -0
  84. package/dist/adapters/strapi/uid.d.ts +44 -0
  85. package/dist/adapters/strapi/uid.d.ts.map +1 -0
  86. package/dist/adapters/strapi/uid.js +58 -0
  87. package/dist/adapters/strapi/uid.js.map +1 -0
  88. package/dist/adapters/wordpress/attachments.d.ts +37 -0
  89. package/dist/adapters/wordpress/attachments.d.ts.map +1 -0
  90. package/dist/adapters/wordpress/attachments.js +134 -0
  91. package/dist/adapters/wordpress/attachments.js.map +1 -0
  92. package/dist/adapters/wordpress/authors.d.ts +24 -0
  93. package/dist/adapters/wordpress/authors.d.ts.map +1 -0
  94. package/dist/adapters/wordpress/authors.js +40 -0
  95. package/dist/adapters/wordpress/authors.js.map +1 -0
  96. package/dist/adapters/wordpress/index.d.ts +19 -0
  97. package/dist/adapters/wordpress/index.d.ts.map +1 -0
  98. package/dist/adapters/wordpress/index.js +281 -0
  99. package/dist/adapters/wordpress/index.js.map +1 -0
  100. package/dist/adapters/wordpress/map.d.ts +61 -0
  101. package/dist/adapters/wordpress/map.d.ts.map +1 -0
  102. package/dist/adapters/wordpress/map.js +265 -0
  103. package/dist/adapters/wordpress/map.js.map +1 -0
  104. package/dist/adapters/wordpress/parse.d.ts +50 -0
  105. package/dist/adapters/wordpress/parse.d.ts.map +1 -0
  106. package/dist/adapters/wordpress/parse.js +141 -0
  107. package/dist/adapters/wordpress/parse.js.map +1 -0
  108. package/dist/adapters/wordpress/terms.d.ts +46 -0
  109. package/dist/adapters/wordpress/terms.d.ts.map +1 -0
  110. package/dist/adapters/wordpress/terms.js +87 -0
  111. package/dist/adapters/wordpress/terms.js.map +1 -0
  112. package/dist/adapters/wordpress/types.d.ts +201 -0
  113. package/dist/adapters/wordpress/types.d.ts.map +1 -0
  114. package/dist/adapters/wordpress/types.js +24 -0
  115. package/dist/adapters/wordpress/types.js.map +1 -0
  116. package/dist/cli.d.ts +16 -0
  117. package/dist/cli.d.ts.map +1 -0
  118. package/dist/cli.js +266 -0
  119. package/dist/cli.js.map +1 -0
  120. package/dist/formatter.d.ts +12 -0
  121. package/dist/formatter.d.ts.map +1 -0
  122. package/dist/formatter.js +48 -0
  123. package/dist/formatter.js.map +1 -0
  124. package/dist/index.d.ts +31 -0
  125. package/dist/index.d.ts.map +1 -0
  126. package/dist/index.js +25 -0
  127. package/dist/index.js.map +1 -0
  128. package/dist/migrate.d.ts +151 -0
  129. package/dist/migrate.d.ts.map +1 -0
  130. package/dist/migrate.js +255 -0
  131. package/dist/migrate.js.map +1 -0
  132. package/dist/registry.d.ts +39 -0
  133. package/dist/registry.d.ts.map +1 -0
  134. package/dist/registry.js +62 -0
  135. package/dist/registry.js.map +1 -0
  136. package/dist/runner.d.ts +33 -0
  137. package/dist/runner.d.ts.map +1 -0
  138. package/dist/runner.js +61 -0
  139. package/dist/runner.js.map +1 -0
  140. package/dist/types.d.ts +173 -0
  141. package/dist/types.d.ts.map +1 -0
  142. package/dist/types.js +17 -0
  143. package/dist/types.js.map +1 -0
  144. package/package.json +59 -0
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Locale handling for the Contentful adapter.
3
+ *
4
+ * Contentful is locale-first: every field is `{ [locale]: value }`.
5
+ * Prenta's import contract is single-locale-per-document, so the
6
+ * adapter has to flatten — either by picking a primary locale or
7
+ * by preserving the locale map verbatim for downstream tooling that
8
+ * can handle it.
9
+ *
10
+ * The strategy lives in its own module so the field mapper can stay
11
+ * focused on per-value rewriting and the per-import config can be
12
+ * validated in one place.
13
+ */
14
+ import type { ContentfulAdapterConfig, ContentfulLocale } from './types.js';
15
+ /**
16
+ * Resolve which locale wins the "primary" slot.
17
+ *
18
+ * 1. Explicit `config.primaryLocale` always wins.
19
+ * 2. Otherwise, the locale flagged `default: true` in the export.
20
+ * 3. Otherwise, the first locale in the export.
21
+ * 4. Otherwise, `'en-US'` as a last-ditch sensible default.
22
+ */
23
+ export declare function resolvePrimaryLocale(exportLocales: readonly ContentfulLocale[] | undefined, config: ContentfulAdapterConfig): string;
24
+ /**
25
+ * Build a per-locale fallback chain — for each locale, the list of
26
+ * codes to try in order. Honors the `fallbackCode` declared on each
27
+ * locale in the export. Used by the `primary-with-fallback`
28
+ * strategy.
29
+ *
30
+ * Self-cycles and infinite loops are clipped by tracking visited
31
+ * codes so a malformed export can't lock the adapter up.
32
+ */
33
+ export declare function buildFallbackChains(locales: readonly ContentfulLocale[] | undefined): Map<string, string[]>;
34
+ /**
35
+ * Detect whether a value looks like a Contentful locale-wrapped
36
+ * field. The adapter is defensive: a field that's *not*
37
+ * locale-wrapped (single-locale projects sometimes have hand-edited
38
+ * exports that skip the wrapper) is passed through unchanged.
39
+ *
40
+ * Rule: object whose every top-level key is a known locale code
41
+ * from the export. We pass the locale set in rather than guessing
42
+ * with regex — `'es-419'` and `'en'` are both valid Contentful
43
+ * codes and there's no clean shape-only test that catches the
44
+ * boundary cleanly.
45
+ */
46
+ export declare function isLocaleWrapped(value: unknown, knownLocales: ReadonlySet<string>): value is Record<string, unknown>;
47
+ /**
48
+ * Pick the value for a single field according to the configured
49
+ * locale strategy. The result is the value the adapter should put
50
+ * on `data[fieldName]`.
51
+ *
52
+ * `'primary-only'`: returns the primary locale value (or `undefined`).
53
+ * `'primary-with-fallback'`: walks the fallback chain until a value
54
+ * is found; returns the first hit.
55
+ * `'all'`: returns the whole locale map untouched.
56
+ *
57
+ * When the value isn't locale-wrapped at all, every strategy
58
+ * returns it as-is.
59
+ */
60
+ export declare function pickLocaleValue(value: unknown, ctx: {
61
+ primaryLocale: string;
62
+ strategy: 'primary-only' | 'all' | 'primary-with-fallback';
63
+ fallbackChains: Map<string, string[]>;
64
+ knownLocales: ReadonlySet<string>;
65
+ }): unknown;
66
+ //# sourceMappingURL=locale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../../../src/adapters/contentful/locale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAS3E;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,SAAS,gBAAgB,EAAE,GAAG,SAAS,EACtD,MAAM,EAAE,uBAAuB,GAC9B,MAAM,CAQR;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,SAAS,GAC/C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAmBvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQlC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE;IACH,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,cAAc,GAAG,KAAK,GAAG,uBAAuB,CAAA;IAC1D,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACrC,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAClC,GACA,OAAO,CAmBT"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Locale handling for the Contentful adapter.
3
+ *
4
+ * Contentful is locale-first: every field is `{ [locale]: value }`.
5
+ * Prenta's import contract is single-locale-per-document, so the
6
+ * adapter has to flatten — either by picking a primary locale or
7
+ * by preserving the locale map verbatim for downstream tooling that
8
+ * can handle it.
9
+ *
10
+ * The strategy lives in its own module so the field mapper can stay
11
+ * focused on per-value rewriting and the per-import config can be
12
+ * validated in one place.
13
+ */
14
+ /**
15
+ * Default locale used when the export doesn't declare locales and
16
+ * the operator didn't configure one. Matches Contentful's own
17
+ * "first project" default.
18
+ */
19
+ const DEFAULT_LOCALE = 'en-US';
20
+ /**
21
+ * Resolve which locale wins the "primary" slot.
22
+ *
23
+ * 1. Explicit `config.primaryLocale` always wins.
24
+ * 2. Otherwise, the locale flagged `default: true` in the export.
25
+ * 3. Otherwise, the first locale in the export.
26
+ * 4. Otherwise, `'en-US'` as a last-ditch sensible default.
27
+ */
28
+ export function resolvePrimaryLocale(exportLocales, config) {
29
+ if (config.primaryLocale)
30
+ return config.primaryLocale;
31
+ if (exportLocales && exportLocales.length > 0) {
32
+ const flagged = exportLocales.find((l) => l.default === true);
33
+ if (flagged)
34
+ return flagged.code;
35
+ return exportLocales[0].code;
36
+ }
37
+ return DEFAULT_LOCALE;
38
+ }
39
+ /**
40
+ * Build a per-locale fallback chain — for each locale, the list of
41
+ * codes to try in order. Honors the `fallbackCode` declared on each
42
+ * locale in the export. Used by the `primary-with-fallback`
43
+ * strategy.
44
+ *
45
+ * Self-cycles and infinite loops are clipped by tracking visited
46
+ * codes so a malformed export can't lock the adapter up.
47
+ */
48
+ export function buildFallbackChains(locales) {
49
+ const out = new Map();
50
+ if (!locales)
51
+ return out;
52
+ const byCode = new Map();
53
+ for (const l of locales)
54
+ byCode.set(l.code, l);
55
+ for (const start of locales) {
56
+ const chain = [];
57
+ const seen = new Set();
58
+ let cursor = start.code;
59
+ while (cursor && !seen.has(cursor)) {
60
+ seen.add(cursor);
61
+ chain.push(cursor);
62
+ cursor = byCode.get(cursor)?.fallbackCode ?? null;
63
+ }
64
+ out.set(start.code, chain);
65
+ }
66
+ return out;
67
+ }
68
+ /**
69
+ * Detect whether a value looks like a Contentful locale-wrapped
70
+ * field. The adapter is defensive: a field that's *not*
71
+ * locale-wrapped (single-locale projects sometimes have hand-edited
72
+ * exports that skip the wrapper) is passed through unchanged.
73
+ *
74
+ * Rule: object whose every top-level key is a known locale code
75
+ * from the export. We pass the locale set in rather than guessing
76
+ * with regex — `'es-419'` and `'en'` are both valid Contentful
77
+ * codes and there's no clean shape-only test that catches the
78
+ * boundary cleanly.
79
+ */
80
+ export function isLocaleWrapped(value, knownLocales) {
81
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
82
+ return false;
83
+ const keys = Object.keys(value);
84
+ if (keys.length === 0)
85
+ return false;
86
+ for (const k of keys) {
87
+ if (!knownLocales.has(k))
88
+ return false;
89
+ }
90
+ return true;
91
+ }
92
+ /**
93
+ * Pick the value for a single field according to the configured
94
+ * locale strategy. The result is the value the adapter should put
95
+ * on `data[fieldName]`.
96
+ *
97
+ * `'primary-only'`: returns the primary locale value (or `undefined`).
98
+ * `'primary-with-fallback'`: walks the fallback chain until a value
99
+ * is found; returns the first hit.
100
+ * `'all'`: returns the whole locale map untouched.
101
+ *
102
+ * When the value isn't locale-wrapped at all, every strategy
103
+ * returns it as-is.
104
+ */
105
+ export function pickLocaleValue(value, ctx) {
106
+ if (!isLocaleWrapped(value, ctx.knownLocales))
107
+ return value;
108
+ if (ctx.strategy === 'all')
109
+ return value;
110
+ const map = value;
111
+ if (ctx.strategy === 'primary-only') {
112
+ return map[ctx.primaryLocale];
113
+ }
114
+ // primary-with-fallback
115
+ const chain = ctx.fallbackChains.get(ctx.primaryLocale) ?? [ctx.primaryLocale];
116
+ for (const code of chain) {
117
+ if (Object.prototype.hasOwnProperty.call(map, code)) {
118
+ const v = map[code];
119
+ if (v !== undefined && v !== null)
120
+ return v;
121
+ }
122
+ }
123
+ return undefined;
124
+ }
125
+ //# sourceMappingURL=locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.js","sourceRoot":"","s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AAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAC9E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAA;YACnB,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI;gBAAE,OAAO,CAAC,CAAA;QAC7C,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Map a single Contentful entry into an Prenta-shaped payload.
3
+ *
4
+ * Walks every field after locale unwrapping, applying these rules
5
+ * in order:
6
+ *
7
+ * 1. **System fields** (`sys.id`, `sys.contentType.sys.id`,
8
+ * timestamps) are stripped from `data` and lifted into
9
+ * `sourceId` / `sourceType`. Set `includeSystemFields: true`
10
+ * in config to keep them on `data`.
11
+ * 2. **Locale-wrapped values** are unwrapped according to the
12
+ * configured strategy (see `locale.ts`). The mapper does this
13
+ * once per field; nested locale wrappers (rare) are passed
14
+ * through unchanged because Contentful itself doesn't produce
15
+ * them.
16
+ * 3. **Link objects** (`{ sys: { type: 'Link', linkType, id } }`)
17
+ * resolve to `{ collection, sourceId }` (Entry links) or
18
+ * `{ url, fileName, contentType, width, height }` (Asset links).
19
+ * Broken links → unresolved field.
20
+ * 4. **Rich Text documents** are passed through unchanged. The
21
+ * mapper walks them once to surface broken embedded refs as
22
+ * warnings.
23
+ * 5. **Slug fields** — if a field's value is a string and the
24
+ * field key is `slug`, that string is also lifted to the
25
+ * top-level `slug`. Contentful's `slug` field type is just a
26
+ * string in the export, so no structural detection needed.
27
+ * 6. Everything else recurses (objects/arrays) or is preserved as-is.
28
+ */
29
+ import type { ImportWarning, UnresolvedField } from '../../types.js';
30
+ import type { AssetEntry } from './asset.js';
31
+ import type { ContentfulAdapterConfig, ContentfulEntry } from './types.js';
32
+ export interface MappingContext {
33
+ /** Entry id → resolved Prenta collection. */
34
+ collectionByEntryId: Map<string, string>;
35
+ /** Asset id → resolved asset payload. */
36
+ assetsById: Map<string, AssetEntry>;
37
+ /** Primary locale to lift values to. */
38
+ primaryLocale: string;
39
+ /** Locale strategy. */
40
+ strategy: 'primary-only' | 'all' | 'primary-with-fallback';
41
+ /** Per-locale fallback chain (precomputed from the export). */
42
+ fallbackChains: Map<string, string[]>;
43
+ /** Locale codes the export knows about. */
44
+ knownLocales: ReadonlySet<string>;
45
+ }
46
+ export interface MapResult {
47
+ collection: string;
48
+ slug?: string;
49
+ data: Record<string, unknown>;
50
+ sourceId: string;
51
+ sourceType: string;
52
+ warnings: ImportWarning[];
53
+ unresolved: UnresolvedField[];
54
+ }
55
+ /**
56
+ * Resolve the target Prenta collection for a Contentful
57
+ * contentType id. Same semantics as the Sanity adapter:
58
+ *
59
+ * - `typeMap` set + entry exists → use mapped slug.
60
+ * - `typeMap` set + entry missing → fall back to contentType id +
61
+ * `warned: true` so the adapter emits an `unmapped-type` warning.
62
+ * - `typeMap` not set → silent fall-through to contentType id.
63
+ */
64
+ export declare function resolveCollection(contentTypeId: string, config: ContentfulAdapterConfig): {
65
+ collection: string;
66
+ warned: boolean;
67
+ };
68
+ export declare function mapEntry(entry: ContentfulEntry, context: MappingContext, config: ContentfulAdapterConfig): MapResult;
69
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/adapters/contentful/map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE1E,MAAM,WAAW,cAAc;IAC7B,6CAA6C;IAC7C,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,yCAAyC;IACzC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACnC,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAA;IACrB,uBAAuB;IACvB,QAAQ,EAAE,cAAc,GAAG,KAAK,GAAG,uBAAuB,CAAA;IAC1D,+DAA+D;IAC/D,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACrC,2CAA2C;IAC3C,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAClC;AAED,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,aAAa,EAAE,CAAA;IACzB,UAAU,EAAE,eAAe,EAAE,CAAA;CAC9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,uBAAuB,GAC9B;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAKzC;AAED,wBAAgB,QAAQ,CACtB,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,uBAAuB,GAC9B,SAAS,CA+CX"}
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Map a single Contentful entry into an Prenta-shaped payload.
3
+ *
4
+ * Walks every field after locale unwrapping, applying these rules
5
+ * in order:
6
+ *
7
+ * 1. **System fields** (`sys.id`, `sys.contentType.sys.id`,
8
+ * timestamps) are stripped from `data` and lifted into
9
+ * `sourceId` / `sourceType`. Set `includeSystemFields: true`
10
+ * in config to keep them on `data`.
11
+ * 2. **Locale-wrapped values** are unwrapped according to the
12
+ * configured strategy (see `locale.ts`). The mapper does this
13
+ * once per field; nested locale wrappers (rare) are passed
14
+ * through unchanged because Contentful itself doesn't produce
15
+ * them.
16
+ * 3. **Link objects** (`{ sys: { type: 'Link', linkType, id } }`)
17
+ * resolve to `{ collection, sourceId }` (Entry links) or
18
+ * `{ url, fileName, contentType, width, height }` (Asset links).
19
+ * Broken links → unresolved field.
20
+ * 4. **Rich Text documents** are passed through unchanged. The
21
+ * mapper walks them once to surface broken embedded refs as
22
+ * warnings.
23
+ * 5. **Slug fields** — if a field's value is a string and the
24
+ * field key is `slug`, that string is also lifted to the
25
+ * top-level `slug`. Contentful's `slug` field type is just a
26
+ * string in the export, so no structural detection needed.
27
+ * 6. Everything else recurses (objects/arrays) or is preserved as-is.
28
+ */
29
+ import { pickLocaleValue } from './locale.js';
30
+ import { collectRichTextReferences, isRichTextDocument, readLink } from './rich-text.js';
31
+ /**
32
+ * Resolve the target Prenta collection for a Contentful
33
+ * contentType id. Same semantics as the Sanity adapter:
34
+ *
35
+ * - `typeMap` set + entry exists → use mapped slug.
36
+ * - `typeMap` set + entry missing → fall back to contentType id +
37
+ * `warned: true` so the adapter emits an `unmapped-type` warning.
38
+ * - `typeMap` not set → silent fall-through to contentType id.
39
+ */
40
+ export function resolveCollection(contentTypeId, config) {
41
+ if (!config.typeMap)
42
+ return { collection: contentTypeId, warned: false };
43
+ const mapped = config.typeMap[contentTypeId];
44
+ if (mapped)
45
+ return { collection: mapped, warned: false };
46
+ return { collection: contentTypeId, warned: true };
47
+ }
48
+ export function mapEntry(entry, context, config) {
49
+ const contentTypeId = entry.sys.contentType?.sys?.id ?? 'unknown';
50
+ const { collection, warned: usedFallbackCollection } = resolveCollection(contentTypeId, config);
51
+ const warnings = [];
52
+ const unresolved = [];
53
+ const data = {};
54
+ const source = { type: contentTypeId, id: entry.sys.id };
55
+ let slug;
56
+ if (usedFallbackCollection) {
57
+ warnings.push({
58
+ source,
59
+ code: 'unmapped-type',
60
+ message: `No typeMap entry for '${contentTypeId}' — using as-is as the collection slug.`,
61
+ });
62
+ }
63
+ if (config.includeSystemFields) {
64
+ data.sys = entry.sys;
65
+ }
66
+ for (const [key, rawValue] of Object.entries(entry.fields ?? {})) {
67
+ const unwrapped = pickLocaleValue(rawValue, context);
68
+ const mapped = visit(unwrapped, {
69
+ context,
70
+ config,
71
+ source,
72
+ path: key,
73
+ warnings,
74
+ unresolved,
75
+ });
76
+ if (slug === undefined && key === 'slug' && typeof mapped === 'string') {
77
+ slug = mapped;
78
+ }
79
+ data[key] = mapped;
80
+ }
81
+ return {
82
+ collection,
83
+ ...(slug !== undefined ? { slug } : {}),
84
+ data,
85
+ sourceId: entry.sys.id,
86
+ sourceType: contentTypeId,
87
+ warnings,
88
+ unresolved,
89
+ };
90
+ }
91
+ function visit(value, ctx) {
92
+ if (value === null || value === undefined)
93
+ return value;
94
+ if (typeof value !== 'object')
95
+ return value;
96
+ if (Array.isArray(value)) {
97
+ return value.map((item, i) => visit(item, { ...ctx, path: `${ctx.path}[${i}]` }));
98
+ }
99
+ // Rich Text documents pass through; we just walk for broken refs.
100
+ if (isRichTextDocument(value)) {
101
+ const hits = collectRichTextReferences(value, ctx.path);
102
+ for (const hit of hits) {
103
+ const resolved = hit.linkType === 'Entry'
104
+ ? ctx.context.collectionByEntryId.has(hit.id)
105
+ : ctx.context.assetsById.has(hit.id);
106
+ if (!resolved) {
107
+ ctx.warnings.push({
108
+ source: { ...ctx.source },
109
+ code: hit.linkType === 'Entry'
110
+ ? 'unresolved-rich-text-entry-ref'
111
+ : 'unresolved-rich-text-asset-ref',
112
+ message: `Rich Text ${hit.linkType.toLowerCase()} reference at ${hit.path} (nodeType=${hit.nodeType}) → '${hit.id}' not present in this export.`,
113
+ });
114
+ }
115
+ }
116
+ return value;
117
+ }
118
+ const link = readLink(value);
119
+ if (link) {
120
+ return resolveLink(link, ctx);
121
+ }
122
+ // Plain object — recurse.
123
+ const tagged = value;
124
+ const out = {};
125
+ for (const [k, v] of Object.entries(tagged)) {
126
+ out[k] = visit(v, { ...ctx, path: `${ctx.path}.${k}` });
127
+ }
128
+ return out;
129
+ }
130
+ function resolveLink(link, ctx) {
131
+ if (link.linkType === 'Entry') {
132
+ const targetCollection = ctx.context.collectionByEntryId.get(link.id);
133
+ if (targetCollection) {
134
+ return { collection: targetCollection, sourceId: link.id };
135
+ }
136
+ ctx.unresolved.push({
137
+ source: { ...ctx.source, field: ctx.path },
138
+ code: 'unresolved-entry-link',
139
+ reason: `Entry link → '${link.id}' not present in this export.`,
140
+ rawValue: { sys: { type: 'Link', linkType: 'Entry', id: link.id } },
141
+ hint: 'Include the target entry in the export, or pre-filter the consuming entry.',
142
+ });
143
+ return { sys: { type: 'Link', linkType: 'Entry', id: link.id } };
144
+ }
145
+ // Asset link
146
+ const asset = ctx.context.assetsById.get(link.id);
147
+ if (asset && asset.url) {
148
+ const out = { url: asset.url, sourceId: link.id };
149
+ if (asset.fileName)
150
+ out.fileName = asset.fileName;
151
+ if (asset.contentType)
152
+ out.contentType = asset.contentType;
153
+ if (asset.size !== undefined)
154
+ out.size = asset.size;
155
+ if (asset.width !== undefined)
156
+ out.width = asset.width;
157
+ if (asset.height !== undefined)
158
+ out.height = asset.height;
159
+ if (asset.title)
160
+ out.title = asset.title;
161
+ if (asset.description)
162
+ out.description = asset.description;
163
+ return out;
164
+ }
165
+ ctx.unresolved.push({
166
+ source: { ...ctx.source, field: ctx.path },
167
+ code: 'unresolved-asset-link',
168
+ reason: `Asset link → '${link.id}' not present in this export${asset ? ' (asset has no file URL)' : ''}.`,
169
+ rawValue: { sys: { type: 'Link', linkType: 'Asset', id: link.id } },
170
+ hint: 'Re-run contentful-export with --include-drafts or ensure the asset has been published.',
171
+ });
172
+ return { sys: { type: 'Link', linkType: 'Asset', id: link.id } };
173
+ }
174
+ //# sourceMappingURL=map.js.map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1C,IAAI,EAAE,uBAAuB;QAC7B,MAAM,EAAE,iBAAiB,IAAI,CAAC,EAAE,+BAA+B,KAAK,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,GAAG;QACzG,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE;QACnE,IAAI,EAAE,wFAAwF;KAC/F,CAAC,CAAA;IACF,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAA;AAClE,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Rich Text helpers for the Contentful adapter.
3
+ *
4
+ * Contentful's Rich Text format is a tree: a root `nodeType:
5
+ * 'document'` with `content[]` children, each of which is a node
6
+ * with its own `content[]` (until you reach `nodeType: 'text'`
7
+ * leaves with `value` + `marks`). Embedded entries and inline
8
+ * links live in their own node types (`embedded-entry-block`,
9
+ * `embedded-asset-block`, `entry-hyperlink`, `asset-hyperlink`).
10
+ *
11
+ * Same strategy as Sanity Portable Text: detect the shape, pass
12
+ * the document through unchanged, walk it once to surface broken
13
+ * references.
14
+ */
15
+ export interface RichTextRefHit {
16
+ /** Path-ish location string for diagnostics. */
17
+ path: string;
18
+ /** Reference target id. */
19
+ id: string;
20
+ /** Whether the target is an entry or asset. */
21
+ linkType: 'Entry' | 'Asset';
22
+ /** The node type that produced the reference (for the warning code). */
23
+ nodeType: string;
24
+ }
25
+ /**
26
+ * True when `value` looks like a Rich Text document — a plain
27
+ * object whose `nodeType === 'document'` and `content` is an array.
28
+ */
29
+ export declare function isRichTextDocument(value: unknown): boolean;
30
+ /**
31
+ * Walk a Rich Text document and collect every entry / asset
32
+ * reference. Recursive — the format nests arbitrarily.
33
+ *
34
+ * Recognized reference-carrying node types:
35
+ *
36
+ * - `embedded-entry-block`, `embedded-entry-inline`
37
+ * - `embedded-asset-block`
38
+ * - `entry-hyperlink`, `asset-hyperlink`
39
+ *
40
+ * Other node types pass through; their `content` arrays are still
41
+ * walked so references nested inside (e.g.) a list item are caught.
42
+ */
43
+ export declare function collectRichTextReferences(doc: unknown, basePath: string): RichTextRefHit[];
44
+ /**
45
+ * Pull `{ linkType, id }` out of a Contentful Link object, if the
46
+ * value matches. Returns `null` for non-links.
47
+ */
48
+ export declare function readLink(value: unknown): {
49
+ id: string;
50
+ linkType: 'Entry' | 'Asset';
51
+ } | null;
52
+ //# sourceMappingURL=rich-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-text.d.ts","sourceRoot":"","sources":["../../../src/adapters/contentful/rich-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,+CAA+C;IAC/C,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAA;IAC3B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAI1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CAI1F;AAoCD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAA;CAAE,GAAG,IAAI,CAY3F"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Rich Text helpers for the Contentful adapter.
3
+ *
4
+ * Contentful's Rich Text format is a tree: a root `nodeType:
5
+ * 'document'` with `content[]` children, each of which is a node
6
+ * with its own `content[]` (until you reach `nodeType: 'text'`
7
+ * leaves with `value` + `marks`). Embedded entries and inline
8
+ * links live in their own node types (`embedded-entry-block`,
9
+ * `embedded-asset-block`, `entry-hyperlink`, `asset-hyperlink`).
10
+ *
11
+ * Same strategy as Sanity Portable Text: detect the shape, pass
12
+ * the document through unchanged, walk it once to surface broken
13
+ * references.
14
+ */
15
+ /**
16
+ * True when `value` looks like a Rich Text document — a plain
17
+ * object whose `nodeType === 'document'` and `content` is an array.
18
+ */
19
+ export function isRichTextDocument(value) {
20
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
21
+ return false;
22
+ const v = value;
23
+ return v.nodeType === 'document' && Array.isArray(v.content);
24
+ }
25
+ /**
26
+ * Walk a Rich Text document and collect every entry / asset
27
+ * reference. Recursive — the format nests arbitrarily.
28
+ *
29
+ * Recognized reference-carrying node types:
30
+ *
31
+ * - `embedded-entry-block`, `embedded-entry-inline`
32
+ * - `embedded-asset-block`
33
+ * - `entry-hyperlink`, `asset-hyperlink`
34
+ *
35
+ * Other node types pass through; their `content` arrays are still
36
+ * walked so references nested inside (e.g.) a list item are caught.
37
+ */
38
+ export function collectRichTextReferences(doc, basePath) {
39
+ const hits = [];
40
+ walk(doc, basePath, hits);
41
+ return hits;
42
+ }
43
+ function walk(node, path, hits) {
44
+ if (node === null || typeof node !== 'object' || Array.isArray(node))
45
+ return;
46
+ const n = node;
47
+ const nodeType = typeof n.nodeType === 'string' ? n.nodeType : '';
48
+ if (isReferenceCarryingNode(nodeType)) {
49
+ const target = n.data?.target;
50
+ const link = readLink(target);
51
+ if (link) {
52
+ hits.push({ path, id: link.id, linkType: link.linkType, nodeType });
53
+ }
54
+ }
55
+ const content = n.content;
56
+ if (Array.isArray(content)) {
57
+ for (let i = 0; i < content.length; i++) {
58
+ walk(content[i], `${path}.content[${i}]`, hits);
59
+ }
60
+ }
61
+ }
62
+ const REFERENCE_NODES = new Set([
63
+ 'embedded-entry-block',
64
+ 'embedded-entry-inline',
65
+ 'embedded-asset-block',
66
+ 'embedded-asset-inline',
67
+ 'entry-hyperlink',
68
+ 'asset-hyperlink',
69
+ ]);
70
+ function isReferenceCarryingNode(nodeType) {
71
+ return REFERENCE_NODES.has(nodeType);
72
+ }
73
+ /**
74
+ * Pull `{ linkType, id }` out of a Contentful Link object, if the
75
+ * value matches. Returns `null` for non-links.
76
+ */
77
+ export function readLink(value) {
78
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
79
+ return null;
80
+ const v = value;
81
+ const sys = v.sys;
82
+ if (sys === null || typeof sys !== 'object' || Array.isArray(sys))
83
+ return null;
84
+ const s = sys;
85
+ if (s.type !== 'Link')
86
+ return null;
87
+ const linkType = s.linkType;
88
+ const id = s.id;
89
+ if (typeof id !== 'string')
90
+ return null;
91
+ if (linkType !== 'Entry' && linkType !== 'Asset')
92
+ return null;
93
+ return { id, linkType };
94
+ }
95
+ //# sourceMappingURL=rich-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-text.js","sourceRoot":"","sources":["../../../src/adapters/contentful/rich-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrF,MAAM,CAAC,GAAG,KAAgC,CAAA;IAC1C,OAAO,CAAC,CAAC,QAAQ,KAAK,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;AAC9D,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,yBAAyB,CAAC,GAAY,EAAE,QAAgB;IACtE,MAAM,IAAI,GAAqB,EAAE,CAAA;IACjC,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA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