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.
- package/dist/algolia/clean.js +0 -1
- package/dist/algolia/config.js +0 -1
- package/dist/algolia/downloads.js +0 -1
- package/dist/algolia/families.js +0 -1
- package/dist/algolia/inspirations.js +0 -1
- package/dist/algolia/models.js +0 -1
- package/dist/algolia/news.js +0 -1
- package/dist/algolia/pressRelease.js +0 -1
- package/dist/algolia/pressReview.js +0 -1
- package/dist/algolia/products.js +0 -1
- package/dist/algolia/projects.js +0 -1
- package/dist/algolia/stories.js +0 -1
- package/dist/algolia/subFamilies.js +0 -1
- package/dist/algolia/subModels.js +0 -1
- package/dist/browser.js +0 -1
- package/dist/downloads/classes/manageEntry.js +0 -1
- package/dist/downloads/import.js +0 -1
- package/dist/index.js +0 -1
- package/dist/libs/contentful-cda.js +0 -1
- package/dist/libs/contentful.js +0 -1
- package/dist/libs/imgix.js +0 -1
- package/dist/libs/logs.js +0 -1
- package/dist/libs/netlify.js +0 -1
- package/dist/libs/notifications.js +0 -1
- package/dist/libs/pdf.js +0 -1
- package/dist/libs/s3.js +0 -1
- package/dist/libs/sentry.js +0 -1
- package/dist/pim/config.js +0 -1
- package/dist/pim/endpoints.js +0 -1
- package/dist/pim/methods/bulkPublish.js +0 -1
- package/dist/pim/methods/catalogs.js +0 -1
- package/dist/pim/methods/checkTopicDraftAndPagePublished.js +0 -1
- package/dist/pim/methods/designers.js +0 -1
- package/dist/pim/methods/dictionary.js +0 -1
- package/dist/pim/methods/families.js +0 -1
- package/dist/pim/methods/latestProducts.js +0 -1
- package/dist/pim/methods/migrateEntryFields.js +0 -1
- package/dist/pim/methods/models.js +0 -1
- package/dist/pim/methods/pages/catalogs.js +0 -1
- package/dist/pim/methods/pages/families.js +0 -1
- package/dist/pim/methods/pages/subfamilies.js +0 -1
- package/dist/pim/methods/products.js +0 -1
- package/dist/pim/methods/subfamilies.js +0 -1
- package/dist/pim/methods/submodels.js +0 -1
- package/dist/pim/request.js +0 -1
- package/dist/resources/AllProducts.js +0 -1
- package/dist/resources/Audit.js +0 -1
- package/dist/resources/CatalogDetails.js +0 -1
- package/dist/resources/CollectionModels.js +0 -1
- package/dist/resources/CollectionSubFamilies.js +0 -1
- package/dist/resources/CollectionSubModels.js +0 -1
- package/dist/resources/DProductSubLine.js +0 -1
- package/dist/resources/FamilyDetails.js +0 -1
- package/dist/resources/ProductDetails.js +0 -1
- package/dist/resources/ProductRelation.js +0 -1
- package/dist/resources/cfFields.js +0 -1
- package/dist/types.js +0 -1
- package/dist/utils.js +0 -1
- package/package.json +7 -2
- package/.env.example +0 -46
- package/.nvmrc +0 -1
- package/.vscode/settings.json +0 -21
- package/dist/algolia/clean.js.map +0 -1
- package/dist/algolia/config.js.map +0 -1
- package/dist/algolia/downloads.js.map +0 -1
- package/dist/algolia/families.js.map +0 -1
- package/dist/algolia/inspirations.js.map +0 -1
- package/dist/algolia/models.js.map +0 -1
- package/dist/algolia/news.js.map +0 -1
- package/dist/algolia/pressRelease.js.map +0 -1
- package/dist/algolia/pressReview.js.map +0 -1
- package/dist/algolia/products.js.map +0 -1
- package/dist/algolia/projects.js.map +0 -1
- package/dist/algolia/stories.js.map +0 -1
- package/dist/algolia/subFamilies.js.map +0 -1
- package/dist/algolia/subModels.js.map +0 -1
- package/dist/browser.js.map +0 -1
- package/dist/downloads/classes/manageEntry.js.map +0 -1
- package/dist/downloads/import.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/libs/contentful-cda.js.map +0 -1
- package/dist/libs/contentful.js.map +0 -1
- package/dist/libs/imgix.js.map +0 -1
- package/dist/libs/logs.js.map +0 -1
- package/dist/libs/netlify.js.map +0 -1
- package/dist/libs/notifications.js.map +0 -1
- package/dist/libs/pdf.js.map +0 -1
- package/dist/libs/s3.js.map +0 -1
- package/dist/libs/sentry.js.map +0 -1
- package/dist/pim/config.js.map +0 -1
- package/dist/pim/endpoints.js.map +0 -1
- package/dist/pim/methods/bulkPublish.js.map +0 -1
- package/dist/pim/methods/catalogs.js.map +0 -1
- package/dist/pim/methods/checkTopicDraftAndPagePublished.js.map +0 -1
- package/dist/pim/methods/designers.js.map +0 -1
- package/dist/pim/methods/dictionary.js.map +0 -1
- package/dist/pim/methods/families.js.map +0 -1
- package/dist/pim/methods/latestProducts.js.map +0 -1
- package/dist/pim/methods/migrateEntryFields.js.map +0 -1
- package/dist/pim/methods/models.js.map +0 -1
- package/dist/pim/methods/pages/catalogs.js.map +0 -1
- package/dist/pim/methods/pages/families.js.map +0 -1
- package/dist/pim/methods/pages/subfamilies.js.map +0 -1
- package/dist/pim/methods/products.js.map +0 -1
- package/dist/pim/methods/subfamilies.js.map +0 -1
- package/dist/pim/methods/submodels.js.map +0 -1
- package/dist/pim/request.js.map +0 -1
- package/dist/resources/AllProducts.js.map +0 -1
- package/dist/resources/Audit.js.map +0 -1
- package/dist/resources/CatalogDetails.js.map +0 -1
- package/dist/resources/CollectionModels.js.map +0 -1
- package/dist/resources/CollectionSubFamilies.js.map +0 -1
- package/dist/resources/CollectionSubModels.js.map +0 -1
- package/dist/resources/DProductSubLine.js.map +0 -1
- package/dist/resources/FamilyDetails.js.map +0 -1
- package/dist/resources/ProductDetails.js.map +0 -1
- package/dist/resources/ProductRelation.js.map +0 -1
- package/dist/resources/cfFields.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/docs/import-data-from-the-dictionary.md +0 -83
- package/docs/import-products.md +0 -61
- package/docs/import-taxonomies-from-the-catalog.md +0 -60
- package/docs/settings.md +0 -47
- package/jest.config.js +0 -16
- package/local-fn/reindex.js +0 -182
- package/src/algolia/clean.ts +0 -164
- package/src/algolia/config.ts +0 -390
- package/src/algolia/downloads.ts +0 -346
- package/src/algolia/families.ts +0 -652
- package/src/algolia/inspirations.ts +0 -315
- package/src/algolia/models.ts +0 -589
- package/src/algolia/news.ts +0 -258
- package/src/algolia/pressRelease.ts +0 -255
- package/src/algolia/pressReview.ts +0 -247
- package/src/algolia/products.ts +0 -731
- package/src/algolia/projects.ts +0 -339
- package/src/algolia/stories.ts +0 -347
- package/src/algolia/subFamilies.ts +0 -709
- package/src/algolia/subModels.ts +0 -359
- package/src/browser.ts +0 -122
- package/src/downloads/classes/manageEntry.ts +0 -99
- package/src/downloads/csv/legal.csv +0 -5
- package/src/downloads/csv/products.csv +0 -373
- package/src/downloads/import.ts +0 -381
- package/src/index.ts +0 -140
- package/src/libs/contentful-cda.ts +0 -543
- package/src/libs/contentful.ts +0 -1453
- package/src/libs/imgix.ts +0 -297
- package/src/libs/logs.ts +0 -121
- package/src/libs/netlify.ts +0 -37
- package/src/libs/notifications.ts +0 -104
- package/src/libs/pdf.ts +0 -107
- package/src/libs/s3.ts +0 -305
- package/src/libs/sentry.ts +0 -33
- package/src/pim/config.ts +0 -84
- package/src/pim/data/productFields.json +0 -1178
- package/src/pim/endpoints.ts +0 -364
- package/src/pim/methods/bulkPublish.ts +0 -266
- package/src/pim/methods/catalogs.ts +0 -586
- package/src/pim/methods/checkTopicDraftAndPagePublished.ts +0 -70
- package/src/pim/methods/designers.ts +0 -128
- package/src/pim/methods/dictionary.ts +0 -611
- package/src/pim/methods/families.ts +0 -345
- package/src/pim/methods/latestProducts.ts +0 -70
- package/src/pim/methods/migrateEntryFields.ts +0 -99
- package/src/pim/methods/models.ts +0 -349
- package/src/pim/methods/pages/catalogs.ts +0 -28
- package/src/pim/methods/pages/families.ts +0 -50
- package/src/pim/methods/pages/subfamilies.ts +0 -98
- package/src/pim/methods/products.ts +0 -3297
- package/src/pim/methods/subfamilies.ts +0 -706
- package/src/pim/methods/submodels.ts +0 -262
- package/src/pim/request.ts +0 -61
- package/src/resources/AllProducts.ts +0 -41
- package/src/resources/Audit.ts +0 -24
- package/src/resources/CatalogDetails.ts +0 -51
- package/src/resources/CollectionModels.ts +0 -42
- package/src/resources/CollectionSubFamilies.ts +0 -45
- package/src/resources/CollectionSubModels.ts +0 -36
- package/src/resources/DProductSubLine.ts +0 -34
- package/src/resources/FamilyDetails.ts +0 -31
- package/src/resources/ProductDetails.ts +0 -352
- package/src/resources/ProductRelation.ts +0 -24
- package/src/resources/cfFields.ts +0 -8
- package/src/types.ts +0 -268
- package/src/utils.ts +0 -553
- package/tsconfig.json +0 -93
- package/tslint.json +0 -22
- package/types/libs/puppeteer.d.ts +0 -17
- package/types/pim/methods/checkIp.d.ts +0 -1
- /package/{types → dist}/algolia/clean.d.ts +0 -0
- /package/{types → dist}/algolia/config.d.ts +0 -0
- /package/{types → dist}/algolia/downloads.d.ts +0 -0
- /package/{types → dist}/algolia/families.d.ts +0 -0
- /package/{types → dist}/algolia/inspirations.d.ts +0 -0
- /package/{types → dist}/algolia/models.d.ts +0 -0
- /package/{types → dist}/algolia/news.d.ts +0 -0
- /package/{types → dist}/algolia/pressRelease.d.ts +0 -0
- /package/{types → dist}/algolia/pressReview.d.ts +0 -0
- /package/{types → dist}/algolia/products.d.ts +0 -0
- /package/{types → dist}/algolia/projects.d.ts +0 -0
- /package/{types → dist}/algolia/stories.d.ts +0 -0
- /package/{types → dist}/algolia/subFamilies.d.ts +0 -0
- /package/{types → dist}/algolia/subModels.d.ts +0 -0
- /package/{types → dist}/browser.d.ts +0 -0
- /package/{types → dist}/downloads/classes/manageEntry.d.ts +0 -0
- /package/{types → dist}/downloads/import.d.ts +0 -0
- /package/{types → dist}/index.d.ts +0 -0
- /package/{types → dist}/libs/contentful-cda.d.ts +0 -0
- /package/{types → dist}/libs/contentful.d.ts +0 -0
- /package/{types → dist}/libs/imgix.d.ts +0 -0
- /package/{types → dist}/libs/logs.d.ts +0 -0
- /package/{types → dist}/libs/netlify.d.ts +0 -0
- /package/{types → dist}/libs/notifications.d.ts +0 -0
- /package/{types → dist}/libs/pdf.d.ts +0 -0
- /package/{types → dist}/libs/s3.d.ts +0 -0
- /package/{types → dist}/libs/sentry.d.ts +0 -0
- /package/{types → dist}/pim/config.d.ts +0 -0
- /package/{types → dist}/pim/endpoints.d.ts +0 -0
- /package/{types → dist}/pim/methods/bulkPublish.d.ts +0 -0
- /package/{types → dist}/pim/methods/catalogs.d.ts +0 -0
- /package/{types → dist}/pim/methods/checkTopicDraftAndPagePublished.d.ts +0 -0
- /package/{types → dist}/pim/methods/designers.d.ts +0 -0
- /package/{types → dist}/pim/methods/dictionary.d.ts +0 -0
- /package/{types → dist}/pim/methods/families.d.ts +0 -0
- /package/{types → dist}/pim/methods/latestProducts.d.ts +0 -0
- /package/{types → dist}/pim/methods/migrateEntryFields.d.ts +0 -0
- /package/{types → dist}/pim/methods/models.d.ts +0 -0
- /package/{types → dist}/pim/methods/pages/catalogs.d.ts +0 -0
- /package/{types → dist}/pim/methods/pages/families.d.ts +0 -0
- /package/{types → dist}/pim/methods/pages/subfamilies.d.ts +0 -0
- /package/{types → dist}/pim/methods/products.d.ts +0 -0
- /package/{types → dist}/pim/methods/subfamilies.d.ts +0 -0
- /package/{types → dist}/pim/methods/submodels.d.ts +0 -0
- /package/{types → dist}/pim/request.d.ts +0 -0
- /package/{types → dist}/resources/AllProducts.d.ts +0 -0
- /package/{types → dist}/resources/Audit.d.ts +0 -0
- /package/{types → dist}/resources/CatalogDetails.d.ts +0 -0
- /package/{types → dist}/resources/CollectionModels.d.ts +0 -0
- /package/{types → dist}/resources/CollectionSubFamilies.d.ts +0 -0
- /package/{types → dist}/resources/CollectionSubModels.d.ts +0 -0
- /package/{types → dist}/resources/DProductSubLine.d.ts +0 -0
- /package/{types → dist}/resources/FamilyDetails.d.ts +0 -0
- /package/{types → dist}/resources/ProductDetails.d.ts +0 -0
- /package/{types → dist}/resources/ProductRelation.d.ts +0 -0
- /package/{types → dist}/resources/cfFields.d.ts +0 -0
- /package/{types → dist}/types.d.ts +0 -0
- /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
|
-
};
|