pim-import 5.0.0 → 5.0.2

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 (249) hide show
  1. package/dist/algolia/clean.js +0 -1
  2. package/dist/algolia/config.js +0 -1
  3. package/dist/algolia/downloads.js +0 -1
  4. package/dist/algolia/families.js +0 -1
  5. package/dist/algolia/inspirations.js +0 -1
  6. package/dist/algolia/models.js +0 -1
  7. package/dist/algolia/news.js +0 -1
  8. package/dist/algolia/pressRelease.js +0 -1
  9. package/dist/algolia/pressReview.js +0 -1
  10. package/dist/algolia/products.js +0 -1
  11. package/dist/algolia/projects.js +0 -1
  12. package/dist/algolia/stories.js +0 -1
  13. package/dist/algolia/subFamilies.js +0 -1
  14. package/dist/algolia/subModels.js +0 -1
  15. package/dist/browser.js +0 -1
  16. package/dist/downloads/classes/manageEntry.js +0 -1
  17. package/dist/downloads/import.js +0 -1
  18. package/dist/index.js +0 -1
  19. package/dist/libs/contentful-cda.js +0 -1
  20. package/dist/libs/contentful.js +0 -1
  21. package/dist/libs/imgix.js +0 -1
  22. package/dist/libs/logs.js +0 -1
  23. package/dist/libs/netlify.js +0 -1
  24. package/dist/libs/notifications.js +0 -1
  25. package/dist/libs/pdf.js +0 -1
  26. package/dist/libs/s3.js +0 -1
  27. package/dist/libs/sentry.js +0 -1
  28. package/dist/pim/config.js +0 -1
  29. package/dist/pim/endpoints.js +0 -1
  30. package/dist/pim/methods/bulkPublish.js +0 -1
  31. package/dist/pim/methods/catalogs.js +0 -1
  32. package/dist/pim/methods/checkTopicDraftAndPagePublished.js +0 -1
  33. package/dist/pim/methods/designers.js +0 -1
  34. package/dist/pim/methods/dictionary.js +0 -1
  35. package/dist/pim/methods/families.js +0 -1
  36. package/dist/pim/methods/latestProducts.js +0 -1
  37. package/dist/pim/methods/migrateEntryFields.js +0 -1
  38. package/dist/pim/methods/models.js +0 -1
  39. package/dist/pim/methods/pages/catalogs.js +0 -1
  40. package/dist/pim/methods/pages/families.js +0 -1
  41. package/dist/pim/methods/pages/subfamilies.js +0 -1
  42. package/dist/pim/methods/products.js +0 -1
  43. package/dist/pim/methods/subfamilies.js +0 -1
  44. package/dist/pim/methods/submodels.js +0 -1
  45. package/dist/pim/request.js +0 -1
  46. package/dist/resources/AllProducts.js +0 -1
  47. package/dist/resources/Audit.js +0 -1
  48. package/dist/resources/CatalogDetails.js +0 -1
  49. package/dist/resources/CollectionModels.js +0 -1
  50. package/dist/resources/CollectionSubFamilies.js +0 -1
  51. package/dist/resources/CollectionSubModels.js +0 -1
  52. package/dist/resources/DProductSubLine.js +0 -1
  53. package/dist/resources/FamilyDetails.js +0 -1
  54. package/dist/resources/ProductDetails.js +0 -1
  55. package/dist/resources/ProductRelation.js +0 -1
  56. package/dist/resources/cfFields.js +0 -1
  57. package/dist/types.js +0 -1
  58. package/dist/utils.js +0 -1
  59. package/package.json +7 -2
  60. package/.env.example +0 -46
  61. package/.nvmrc +0 -1
  62. package/.vscode/settings.json +0 -21
  63. package/dist/algolia/clean.js.map +0 -1
  64. package/dist/algolia/config.js.map +0 -1
  65. package/dist/algolia/downloads.js.map +0 -1
  66. package/dist/algolia/families.js.map +0 -1
  67. package/dist/algolia/inspirations.js.map +0 -1
  68. package/dist/algolia/models.js.map +0 -1
  69. package/dist/algolia/news.js.map +0 -1
  70. package/dist/algolia/pressRelease.js.map +0 -1
  71. package/dist/algolia/pressReview.js.map +0 -1
  72. package/dist/algolia/products.js.map +0 -1
  73. package/dist/algolia/projects.js.map +0 -1
  74. package/dist/algolia/stories.js.map +0 -1
  75. package/dist/algolia/subFamilies.js.map +0 -1
  76. package/dist/algolia/subModels.js.map +0 -1
  77. package/dist/browser.js.map +0 -1
  78. package/dist/downloads/classes/manageEntry.js.map +0 -1
  79. package/dist/downloads/import.js.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/libs/contentful-cda.js.map +0 -1
  82. package/dist/libs/contentful.js.map +0 -1
  83. package/dist/libs/imgix.js.map +0 -1
  84. package/dist/libs/logs.js.map +0 -1
  85. package/dist/libs/netlify.js.map +0 -1
  86. package/dist/libs/notifications.js.map +0 -1
  87. package/dist/libs/pdf.js.map +0 -1
  88. package/dist/libs/s3.js.map +0 -1
  89. package/dist/libs/sentry.js.map +0 -1
  90. package/dist/pim/config.js.map +0 -1
  91. package/dist/pim/endpoints.js.map +0 -1
  92. package/dist/pim/methods/bulkPublish.js.map +0 -1
  93. package/dist/pim/methods/catalogs.js.map +0 -1
  94. package/dist/pim/methods/checkTopicDraftAndPagePublished.js.map +0 -1
  95. package/dist/pim/methods/designers.js.map +0 -1
  96. package/dist/pim/methods/dictionary.js.map +0 -1
  97. package/dist/pim/methods/families.js.map +0 -1
  98. package/dist/pim/methods/latestProducts.js.map +0 -1
  99. package/dist/pim/methods/migrateEntryFields.js.map +0 -1
  100. package/dist/pim/methods/models.js.map +0 -1
  101. package/dist/pim/methods/pages/catalogs.js.map +0 -1
  102. package/dist/pim/methods/pages/families.js.map +0 -1
  103. package/dist/pim/methods/pages/subfamilies.js.map +0 -1
  104. package/dist/pim/methods/products.js.map +0 -1
  105. package/dist/pim/methods/subfamilies.js.map +0 -1
  106. package/dist/pim/methods/submodels.js.map +0 -1
  107. package/dist/pim/request.js.map +0 -1
  108. package/dist/resources/AllProducts.js.map +0 -1
  109. package/dist/resources/Audit.js.map +0 -1
  110. package/dist/resources/CatalogDetails.js.map +0 -1
  111. package/dist/resources/CollectionModels.js.map +0 -1
  112. package/dist/resources/CollectionSubFamilies.js.map +0 -1
  113. package/dist/resources/CollectionSubModels.js.map +0 -1
  114. package/dist/resources/DProductSubLine.js.map +0 -1
  115. package/dist/resources/FamilyDetails.js.map +0 -1
  116. package/dist/resources/ProductDetails.js.map +0 -1
  117. package/dist/resources/ProductRelation.js.map +0 -1
  118. package/dist/resources/cfFields.js.map +0 -1
  119. package/dist/types.js.map +0 -1
  120. package/dist/utils.js.map +0 -1
  121. package/docs/import-data-from-the-dictionary.md +0 -83
  122. package/docs/import-products.md +0 -61
  123. package/docs/import-taxonomies-from-the-catalog.md +0 -60
  124. package/docs/settings.md +0 -47
  125. package/jest.config.js +0 -16
  126. package/local-fn/reindex.js +0 -182
  127. package/src/algolia/clean.ts +0 -164
  128. package/src/algolia/config.ts +0 -390
  129. package/src/algolia/downloads.ts +0 -346
  130. package/src/algolia/families.ts +0 -652
  131. package/src/algolia/inspirations.ts +0 -315
  132. package/src/algolia/models.ts +0 -589
  133. package/src/algolia/news.ts +0 -258
  134. package/src/algolia/pressRelease.ts +0 -255
  135. package/src/algolia/pressReview.ts +0 -247
  136. package/src/algolia/products.ts +0 -731
  137. package/src/algolia/projects.ts +0 -339
  138. package/src/algolia/stories.ts +0 -347
  139. package/src/algolia/subFamilies.ts +0 -709
  140. package/src/algolia/subModels.ts +0 -359
  141. package/src/browser.ts +0 -122
  142. package/src/downloads/classes/manageEntry.ts +0 -99
  143. package/src/downloads/csv/legal.csv +0 -5
  144. package/src/downloads/csv/products.csv +0 -373
  145. package/src/downloads/import.ts +0 -381
  146. package/src/index.ts +0 -140
  147. package/src/libs/contentful-cda.ts +0 -543
  148. package/src/libs/contentful.ts +0 -1453
  149. package/src/libs/imgix.ts +0 -297
  150. package/src/libs/logs.ts +0 -121
  151. package/src/libs/netlify.ts +0 -37
  152. package/src/libs/notifications.ts +0 -104
  153. package/src/libs/pdf.ts +0 -107
  154. package/src/libs/s3.ts +0 -305
  155. package/src/libs/sentry.ts +0 -33
  156. package/src/pim/config.ts +0 -84
  157. package/src/pim/data/productFields.json +0 -1178
  158. package/src/pim/endpoints.ts +0 -364
  159. package/src/pim/methods/bulkPublish.ts +0 -266
  160. package/src/pim/methods/catalogs.ts +0 -586
  161. package/src/pim/methods/checkTopicDraftAndPagePublished.ts +0 -70
  162. package/src/pim/methods/designers.ts +0 -128
  163. package/src/pim/methods/dictionary.ts +0 -611
  164. package/src/pim/methods/families.ts +0 -345
  165. package/src/pim/methods/latestProducts.ts +0 -70
  166. package/src/pim/methods/migrateEntryFields.ts +0 -99
  167. package/src/pim/methods/models.ts +0 -349
  168. package/src/pim/methods/pages/catalogs.ts +0 -28
  169. package/src/pim/methods/pages/families.ts +0 -50
  170. package/src/pim/methods/pages/subfamilies.ts +0 -98
  171. package/src/pim/methods/products.ts +0 -3297
  172. package/src/pim/methods/subfamilies.ts +0 -706
  173. package/src/pim/methods/submodels.ts +0 -262
  174. package/src/pim/request.ts +0 -61
  175. package/src/resources/AllProducts.ts +0 -41
  176. package/src/resources/Audit.ts +0 -24
  177. package/src/resources/CatalogDetails.ts +0 -51
  178. package/src/resources/CollectionModels.ts +0 -42
  179. package/src/resources/CollectionSubFamilies.ts +0 -45
  180. package/src/resources/CollectionSubModels.ts +0 -36
  181. package/src/resources/DProductSubLine.ts +0 -34
  182. package/src/resources/FamilyDetails.ts +0 -31
  183. package/src/resources/ProductDetails.ts +0 -352
  184. package/src/resources/ProductRelation.ts +0 -24
  185. package/src/resources/cfFields.ts +0 -8
  186. package/src/types.ts +0 -268
  187. package/src/utils.ts +0 -553
  188. package/tsconfig.json +0 -93
  189. package/tslint.json +0 -22
  190. package/types/libs/puppeteer.d.ts +0 -17
  191. package/types/pim/methods/checkIp.d.ts +0 -1
  192. /package/{types → dist}/algolia/clean.d.ts +0 -0
  193. /package/{types → dist}/algolia/config.d.ts +0 -0
  194. /package/{types → dist}/algolia/downloads.d.ts +0 -0
  195. /package/{types → dist}/algolia/families.d.ts +0 -0
  196. /package/{types → dist}/algolia/inspirations.d.ts +0 -0
  197. /package/{types → dist}/algolia/models.d.ts +0 -0
  198. /package/{types → dist}/algolia/news.d.ts +0 -0
  199. /package/{types → dist}/algolia/pressRelease.d.ts +0 -0
  200. /package/{types → dist}/algolia/pressReview.d.ts +0 -0
  201. /package/{types → dist}/algolia/products.d.ts +0 -0
  202. /package/{types → dist}/algolia/projects.d.ts +0 -0
  203. /package/{types → dist}/algolia/stories.d.ts +0 -0
  204. /package/{types → dist}/algolia/subFamilies.d.ts +0 -0
  205. /package/{types → dist}/algolia/subModels.d.ts +0 -0
  206. /package/{types → dist}/browser.d.ts +0 -0
  207. /package/{types → dist}/downloads/classes/manageEntry.d.ts +0 -0
  208. /package/{types → dist}/downloads/import.d.ts +0 -0
  209. /package/{types → dist}/index.d.ts +0 -0
  210. /package/{types → dist}/libs/contentful-cda.d.ts +0 -0
  211. /package/{types → dist}/libs/contentful.d.ts +0 -0
  212. /package/{types → dist}/libs/imgix.d.ts +0 -0
  213. /package/{types → dist}/libs/logs.d.ts +0 -0
  214. /package/{types → dist}/libs/netlify.d.ts +0 -0
  215. /package/{types → dist}/libs/notifications.d.ts +0 -0
  216. /package/{types → dist}/libs/pdf.d.ts +0 -0
  217. /package/{types → dist}/libs/s3.d.ts +0 -0
  218. /package/{types → dist}/libs/sentry.d.ts +0 -0
  219. /package/{types → dist}/pim/config.d.ts +0 -0
  220. /package/{types → dist}/pim/endpoints.d.ts +0 -0
  221. /package/{types → dist}/pim/methods/bulkPublish.d.ts +0 -0
  222. /package/{types → dist}/pim/methods/catalogs.d.ts +0 -0
  223. /package/{types → dist}/pim/methods/checkTopicDraftAndPagePublished.d.ts +0 -0
  224. /package/{types → dist}/pim/methods/designers.d.ts +0 -0
  225. /package/{types → dist}/pim/methods/dictionary.d.ts +0 -0
  226. /package/{types → dist}/pim/methods/families.d.ts +0 -0
  227. /package/{types → dist}/pim/methods/latestProducts.d.ts +0 -0
  228. /package/{types → dist}/pim/methods/migrateEntryFields.d.ts +0 -0
  229. /package/{types → dist}/pim/methods/models.d.ts +0 -0
  230. /package/{types → dist}/pim/methods/pages/catalogs.d.ts +0 -0
  231. /package/{types → dist}/pim/methods/pages/families.d.ts +0 -0
  232. /package/{types → dist}/pim/methods/pages/subfamilies.d.ts +0 -0
  233. /package/{types → dist}/pim/methods/products.d.ts +0 -0
  234. /package/{types → dist}/pim/methods/subfamilies.d.ts +0 -0
  235. /package/{types → dist}/pim/methods/submodels.d.ts +0 -0
  236. /package/{types → dist}/pim/request.d.ts +0 -0
  237. /package/{types → dist}/resources/AllProducts.d.ts +0 -0
  238. /package/{types → dist}/resources/Audit.d.ts +0 -0
  239. /package/{types → dist}/resources/CatalogDetails.d.ts +0 -0
  240. /package/{types → dist}/resources/CollectionModels.d.ts +0 -0
  241. /package/{types → dist}/resources/CollectionSubFamilies.d.ts +0 -0
  242. /package/{types → dist}/resources/CollectionSubModels.d.ts +0 -0
  243. /package/{types → dist}/resources/DProductSubLine.d.ts +0 -0
  244. /package/{types → dist}/resources/FamilyDetails.d.ts +0 -0
  245. /package/{types → dist}/resources/ProductDetails.d.ts +0 -0
  246. /package/{types → dist}/resources/ProductRelation.d.ts +0 -0
  247. /package/{types → dist}/resources/cfFields.d.ts +0 -0
  248. /package/{types → dist}/types.d.ts +0 -0
  249. /package/{types → dist}/utils.d.ts +0 -0
@@ -1,543 +0,0 @@
1
- import type { Entry } from "contentful-management/dist/typings/entities/entry";
2
- import { Locale } from "contentful-management/types";
3
- import {
4
- CfSys,
5
- TopicDetailsResponse,
6
- AssetPropFieldsWithoutLocaleKey,
7
- OtherFilters,
8
- } from "../types";
9
- import {
10
- getPimTranslations,
11
- keysToLowerCase,
12
- getAllTranslations,
13
- } from "../utils";
14
- import { log } from "./logs";
15
- import { getFileFromS3 } from "../libs/s3";
16
- const contentful = require("contentful");
17
- import { getWrapperImgixFields } from "../libs/imgix";
18
-
19
- let client: any;
20
- let defaultEnvironmentLocale: Locale;
21
- let defaultEnvironmentLocaleCode: string;
22
-
23
- const config = {
24
- spaceId: process.env.FPI_CTF_SPACE_ID,
25
- previewAccessToken: process.env.FPI_CTF_PREVIEW_ACCESS_TOKEN,
26
- accessToken: process.env.FPI_CTF_CDA_ACCESS_TOKEN,
27
- environment: process.env.FPI_CTF_ENVIRONMENT,
28
- // removeUnresolved: process.env.FPI_CTF_REMOVE_UNRESOLVED === "1",
29
- // resolveLinks: process.env.FPI_CTF_RESOLVE_LINKS === "1",
30
- previewEnabled: process.env.FPI_CTF_PREVIEW_ENABLED === "1",
31
- host:
32
- process.env.FPI_CTF_PREVIEW_ENABLED === "1"
33
- ? "preview.contentful.com"
34
- : "cdn.contentful.com",
35
- };
36
-
37
- const initClient = async () => {
38
- client = await contentful.createClient({
39
- space: config.spaceId,
40
- accessToken: config.previewEnabled
41
- ? config.previewAccessToken || ""
42
- : config.accessToken,
43
- environment: config.environment || "master",
44
- // removeUnresolved: config.removeUnresolved,
45
- // resolveLinks: config.resolveLinks,
46
- host: config.previewEnabled
47
- ? "preview.contentful.com"
48
- : "cdn.contentful.com",
49
- });
50
-
51
- log(`host: ${config.host}`);
52
-
53
- return client;
54
- };
55
-
56
- export const getClient = async () => {
57
- if (!client) {
58
- return await initClient();
59
- } else {
60
- return client;
61
- }
62
- };
63
-
64
- /**
65
- * Get environment default locale
66
- *
67
- * @returns
68
- */
69
- export const getEnvironmentDefaultLocale = async (): Promise<Locale> => {
70
- if (defaultEnvironmentLocale) {
71
- return new Promise((resolve) => resolve(defaultEnvironmentLocale));
72
- }
73
-
74
- const client = await getClient();
75
- const environmentLocales = await client.getLocales();
76
- if (!environmentLocales) {
77
- throw new Error("Environment locales not found");
78
- }
79
-
80
- const findDefaultEnvironmentLocale: Locale | undefined =
81
- environmentLocales.items.find((locale: Locale) => locale.default);
82
-
83
- if (findDefaultEnvironmentLocale) {
84
- defaultEnvironmentLocale = findDefaultEnvironmentLocale;
85
- } else {
86
- throw new Error("Default environment locales not found");
87
- }
88
-
89
- return new Promise((resolve) => resolve(defaultEnvironmentLocale));
90
- };
91
-
92
- /**
93
- * Get environment default locale code
94
- *
95
- * @returns
96
- */
97
- export const getEnvironmentDefaultLocaleCode = async (): Promise<string> => {
98
- if (defaultEnvironmentLocaleCode) {
99
- return new Promise((resolve) => resolve(defaultEnvironmentLocaleCode));
100
- }
101
-
102
- const defEnvironmentLocale = await getEnvironmentDefaultLocale();
103
- defaultEnvironmentLocaleCode = defEnvironmentLocale.code;
104
- return new Promise((resolve) => resolve(defaultEnvironmentLocaleCode));
105
- };
106
-
107
- /**
108
- * Get entry by id
109
- *
110
- * @param entryID
111
- * @param contentTypeId
112
- * @returns
113
- */
114
- export const getEntryByID = async (
115
- entryID: string,
116
- contentTypeId: string,
117
- select?: string
118
- ): Promise<Entry> => {
119
- const client = await getClient();
120
-
121
- const opts = {
122
- content_type: contentTypeId,
123
- "sys.id": entryID,
124
- limit: 1,
125
- select,
126
- include: 1,
127
- };
128
-
129
- const entries = await client.withAllLocales.getEntries(opts);
130
-
131
- return entries.items[0];
132
- };
133
-
134
- /**
135
- * Get all entries
136
- *
137
- * @param {string} contentType
138
- * @param {string} select
139
- * @param {string} filterKey Ex: `fields.catalog[in]`
140
- * @param {string} filterValue Ex: `ARCHITECTURAL`
141
- * @param {number} limit Default: 50
142
- * @param {array} otherFilters Example: [{ key: "fields.catalogs.sys.id[in]", value: 'ARCHITECTURAL' }]
143
- * @returns
144
- */
145
- export const getAllEntries = async (
146
- contentType: string,
147
- select?: string,
148
- filterKey?: string,
149
- filterValue?: string,
150
- limit: number = 50,
151
- otherFilters?: OtherFilters[],
152
- include: number = 10
153
- ): Promise<Entry[]> => {
154
- // log(
155
- // `getAllEntries contentType: ${contentType} select: ${select} filterKey: ${filterKey} filterValue: ${filterValue}`,
156
- // "INFO"
157
- // );
158
-
159
- const client = await getClient();
160
- let allItems: Entry[] = [];
161
- let othersPagesToFetch = false;
162
- let skip = 0;
163
- // let count = 0;
164
- do {
165
- const opts: any = {
166
- content_type: contentType,
167
- limit,
168
- skip,
169
- select,
170
- include,
171
- };
172
- if (filterKey) {
173
- opts[filterKey] = filterValue;
174
- }
175
- if (otherFilters?.length) {
176
- for (const otherFilter of otherFilters) {
177
- opts[otherFilter.key] = otherFilter.value;
178
- }
179
- }
180
-
181
- const { items, total } = await client.withAllLocales.getEntries(opts);
182
-
183
- allItems = [...allItems, ...(items || [])];
184
-
185
- if (total && allItems.length < total) {
186
- othersPagesToFetch = true;
187
- skip += limit;
188
-
189
- // if (++count % 7 === 0) {
190
- // await sleep(200);
191
- // }
192
- } else {
193
- othersPagesToFetch = false;
194
- }
195
- } while (othersPagesToFetch);
196
-
197
- return allItems;
198
- };
199
-
200
- /**
201
- * Get asset details
202
- *
203
- * @param assetId
204
- * @returns
205
- *
206
- * // TODO: modificare quanto verrà integrato imagix
207
- */
208
- export const getAssetDetails = async (
209
- assetId: string
210
- ): Promise<AssetPropFieldsWithoutLocaleKey> => {
211
- const client = await getClient();
212
- const thumbnailEntry = await client.getAsset(assetId);
213
- return thumbnailEntry?.fields
214
- ? keysToLowerCase(thumbnailEntry.fields, true)
215
- : {};
216
- };
217
-
218
- /**
219
- * Get entry image details
220
- *
221
- * @example
222
- * await getEntryImageDetails(topicSubModule, 'thumbnail');
223
- *
224
- * @param entry The Contentful entry
225
- * @param fieldKey The image field key of the entry
226
- * @returns
227
- *
228
- * // TODO: modificare quanto verrà integrato imagix
229
- */
230
- export const getEntryImageDetails = async (entry: Entry, fieldKey: string) => {
231
- const assetId =
232
- entry?.fields?.[fieldKey]?.[defaultEnvironmentLocaleCode]?.sys?.id;
233
- if (assetId) {
234
- const assetEntry = await getAssetDetails(assetId);
235
- return assetEntry?.file?.url || "";
236
- }
237
-
238
- return "";
239
- };
240
-
241
- /**
242
- * Get topic details
243
- *
244
- * @example const catalogs = await getTopicDetails(topicFamily,"catalogs", "topicCatalog");
245
- * @returns {
246
- * names: {
247
- * de: 'Architectural Lighting',
248
- * 'en-US': 'Architectural Lighting',
249
- * ...
250
- * },
251
- * code: { 'en': 'ARCHITECTURAL' },
252
- * slugs: {
253
- * de: 'architectural lighting',
254
- * 'en-US': 'architectural lighting'
255
- * ...
256
- * }
257
- * }
258
- *
259
- * @param topicEntry
260
- * @param fieldKey
261
- * @param contentType
262
- * @param showRelatedEntities Default false
263
- * @param isCatalogEntry Default true
264
- * @param skipPageSlugs Default false
265
- * @param skipThumbnail Default true
266
- * @returns
267
- */
268
- export const getTopicDetails = async (
269
- topicEntry: Entry,
270
- fieldKey: string,
271
- contentType: string,
272
- showRelatedEntities: boolean = false,
273
- isCatalogEntry: boolean = true,
274
- skipPageSlugs: boolean = false,
275
- thumbnailFieldName: string = ""
276
- ): Promise<TopicDetailsResponse[]> => {
277
- const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
278
- const isHasToManyField = Array.isArray(
279
- topicEntry?.fields?.[fieldKey]?.[defEnvLocaleCode]
280
- );
281
-
282
- const items: TopicDetailsResponse[] = [];
283
- let entryIds = [];
284
- if (isHasToManyField) {
285
- entryIds = topicEntry?.fields?.[fieldKey]?.[defEnvLocaleCode].map(
286
- (item: CfSys) => item.sys.id
287
- );
288
- } else {
289
- entryIds = [topicEntry?.fields?.[fieldKey]?.[defEnvLocaleCode]?.sys?.id];
290
- }
291
-
292
- if (entryIds) {
293
- let select = isCatalogEntry
294
- ? "sys,fields.name,fields.code"
295
- : "sys,fields.name";
296
- if (contentType === "topicSubFamily" && showRelatedEntities) {
297
- select += ",fields.catalog,fields.category,fields.parentFamily";
298
- }
299
- if (thumbnailFieldName) {
300
- select += `,fields.${thumbnailFieldName}`;
301
- }
302
- if (contentType === "topicProductLine") {
303
- select += ",fields.priority";
304
- }
305
-
306
- const entries = await getAllEntries(
307
- contentType,
308
- select,
309
- "sys.id[in]",
310
- entryIds.join(",")
311
- );
312
-
313
- if (entries) {
314
- for (const entry of entries) {
315
- const data: TopicDetailsResponse = {
316
- names: await getAllTranslations(entry?.fields?.name || {}),
317
- code: entry?.fields?.code?.[defEnvLocaleCode],
318
- };
319
- if (!skipPageSlugs) {
320
- let entryPage: any = {};
321
- if (isCatalogEntry) {
322
- const entryPageId = `${entry.sys.id}_PAGE`;
323
- entryPage = await getEntryByID(entryPageId, "page", "fields.slug");
324
- } else {
325
- entryPage = await getTopicPage(entry.sys.id);
326
- }
327
- data.slugs = await getAllTranslations(entryPage?.fields?.slug || {});
328
- }
329
-
330
- if (thumbnailFieldName) {
331
- let thumbnailImgix = {};
332
- const thumbnailImgixWrapperImgixID =
333
- entry?.fields?.[thumbnailFieldName]?.[defEnvLocaleCode]?.sys.id;
334
- if (thumbnailImgixWrapperImgixID) {
335
- thumbnailImgix = await getWrapperImgixFields(
336
- thumbnailImgixWrapperImgixID
337
- );
338
- }
339
- data.thumbnail = thumbnailImgix;
340
- }
341
-
342
- if (contentType === "topicSubFamily" && showRelatedEntities) {
343
- data.details = await getSubFamilyRelatedDetails(entry);
344
- }
345
-
346
- if (contentType === "topicProductLine") {
347
- data.priority = entry?.fields?.priority?.[defEnvLocaleCode];
348
- }
349
-
350
- items.push(data);
351
- }
352
- }
353
- } else {
354
- log(
355
- `No ${fieldKey} found in the ${contentType} ${topicEntry.sys.id}`,
356
- "WARN"
357
- );
358
- }
359
-
360
- return items;
361
- };
362
-
363
- export const getSubFamilyRelatedDetails = async (topicSubFamily: Entry) => {
364
- const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
365
- // const catalogEntry = topicSubFamily?.fields?.catalog?.[defaultEnvironmentLocaleCode]
366
- // const catalogEntryId =
367
- // catalogEntry?.sys?.id;
368
- // if (!catalogEntryId) {
369
- // log(
370
- // `catalogEntryId not found to ${topicSubFamily.sys.id} subFamilyEntry`,
371
- // "WARN"
372
- // );
373
- // }
374
- const parentFamilyEntry =
375
- topicSubFamily?.fields?.parentFamily?.[defaultEnvironmentLocaleCode];
376
- const parentFamilyEntryId = parentFamilyEntry?.sys?.id;
377
- if (!parentFamilyEntryId) {
378
- log(
379
- `parentFamilyEntryId not found to ${topicSubFamily.sys.id} subFamilyEntry`,
380
- "WARN"
381
- );
382
- }
383
- const categoryEntry =
384
- topicSubFamily?.fields?.category?.[defaultEnvironmentLocaleCode];
385
- const categoryEntryId = categoryEntry?.sys?.id;
386
- if (!categoryEntryId) {
387
- log(
388
- `categoryEntryId not found to ${topicSubFamily.sys.id} subFamilyEntry`,
389
- "WARN"
390
- );
391
- }
392
- // const subFamilyCatalogPage: any = catalogEntryId
393
- // ? await getEntryByID(
394
- // `${catalogEntryId}_PAGE`,
395
- // "page",
396
- // "fields.title,fields.slug,fields.topic"
397
- // )
398
- // : {};
399
- const subFamilyFamilyPage: any = parentFamilyEntryId
400
- ? await getEntryByID(
401
- `${parentFamilyEntryId}_PAGE`,
402
- "page",
403
- "fields.title,fields.slug"
404
- )
405
- : {};
406
- const subFamilyCategoryPage: any = categoryEntryId
407
- ? await getEntryByID(
408
- `${categoryEntryId}_PAGE`,
409
- "page",
410
- "fields.title,fields.slug,fields.topic"
411
- )
412
- : {};
413
-
414
- return {
415
- // catalog: {
416
- // code: catalogEntry?.code,
417
- // names: subFamilyCatalogPage?.fields?.title,
418
- // slugs: await getAllTranslations(subFamilyCatalogPage?.fields?.slug || {}),
419
- // },
420
- family: {
421
- code: parentFamilyEntry?.fields?.code[defaultEnvironmentLocaleCode],
422
- names: subFamilyFamilyPage?.fields?.title,
423
- slugs: await getAllTranslations(subFamilyFamilyPage?.fields?.slug || {}),
424
- thumbnail: await getWrapperImgixFields(
425
- parentFamilyEntry?.fields?.["thumbnailImgix"]?.[
426
- defaultEnvironmentLocaleCode
427
- ]?.sys.id
428
- ),
429
- },
430
- category: {
431
- code: categoryEntry?.fields?.code[defaultEnvironmentLocaleCode],
432
- names: subFamilyCategoryPage?.fields?.title,
433
- slugs: await getAllTranslations(
434
- subFamilyCategoryPage?.fields?.slug || {}
435
- ),
436
- thumbnail: await getWrapperImgixFields(
437
- categoryEntry?.fields?.["thumbnailImgix"]?.[
438
- defaultEnvironmentLocaleCode
439
- ]?.sys.id
440
- ),
441
- },
442
- };
443
- };
444
-
445
- export const getDictionaryJson = async () => {
446
- const data = await getFileFromS3(`dictionary.json`);
447
- if (!data) {
448
- throw new Error("Dictionary JSON file not found on S3.");
449
- }
450
-
451
- return data;
452
- };
453
-
454
- export const getDictionaryValue = async (
455
- fieldKey: string,
456
- fieldValue: string,
457
- fieldParent: string = "",
458
- dictionaryJsonFile: any = {}
459
- ) => {
460
- const dictionaryJson = Object.entries(dictionaryJsonFile)
461
- ? dictionaryJsonFile
462
- : await getDictionaryJson();
463
- let field = null;
464
-
465
- if (fieldParent && dictionaryJson?.[fieldParent]?.[fieldKey]) {
466
- field = dictionaryJson[fieldParent][fieldKey];
467
- } else if (dictionaryJson?.[fieldKey]) {
468
- field = dictionaryJson[fieldKey];
469
- }
470
-
471
- if (field) {
472
- if (Array.isArray(field)) {
473
- return getPimTranslations(
474
- field.find((item: any) => item.code === fieldValue)
475
- );
476
- } else if (typeof field === "object" && field?.code) {
477
- return getPimTranslations(field);
478
- } else {
479
- return field;
480
- }
481
- } else {
482
- log(
483
- `No field found with fieldKey: ${fieldKey} fieldValue: ${fieldValue} fieldParent: ${fieldParent}`
484
- );
485
- }
486
- };
487
-
488
- /**
489
- *
490
- * @example
491
- * const lampCategoriesLocalizedValue = await getDictionaryLocaleValue(locale, "lampCategories", productFileds.electrical.lampCategories.code, "electrical");
492
- *
493
- * @param locale
494
- * @param fieldKey
495
- * @param fieldValue
496
- * @param fieldParent
497
- * @param dictionaryJsonFile
498
- * @returns
499
- */
500
- export const getDictionaryLocaleValue = async (
501
- locale: string,
502
- fieldKey: string,
503
- fieldValue: string,
504
- fieldParent: string = "",
505
- dictionaryJsonFile: any = {}
506
- ) => {
507
- const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
508
- const values = await getDictionaryValue(
509
- fieldKey,
510
- fieldValue,
511
- fieldParent,
512
- dictionaryJsonFile
513
- );
514
- if (typeof values === "object") {
515
- return values?.[locale] || values?.[defEnvLocaleCode];
516
- } else {
517
- return values;
518
- }
519
- };
520
-
521
- /**
522
- * Get topic page
523
- *
524
- * @param topicId
525
- * @param select Default: "sys,fields"
526
- * @returns
527
- */
528
- export const getTopicPage = async (
529
- topicId: string,
530
- select: string = "sys,fields"
531
- ) => {
532
- const client = await getClient();
533
-
534
- const { items } = await client.withAllLocales.getEntries({
535
- links_to_entry: topicId,
536
- content_type: "page",
537
- include: 2,
538
- select,
539
- limit: 1,
540
- });
541
-
542
- return items?.[0];
543
- };