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,611 +0,0 @@
|
|
|
1
|
-
import { getDictionary } from "../endpoints";
|
|
2
|
-
import {
|
|
3
|
-
ObjectPartial,
|
|
4
|
-
CfLocalizedEntryField,
|
|
5
|
-
ProductFieldsRequiredData,
|
|
6
|
-
} from "../../types";
|
|
7
|
-
import {
|
|
8
|
-
createEntryWithId,
|
|
9
|
-
updateEntry,
|
|
10
|
-
getEntryByCode,
|
|
11
|
-
addFieldValue,
|
|
12
|
-
addToRelationFields,
|
|
13
|
-
getDictionaryJson,
|
|
14
|
-
} from "../../libs/contentful";
|
|
15
|
-
import productFieldsRequiredData from "../data/productFields.json";
|
|
16
|
-
import mime from "mime-types";
|
|
17
|
-
import {
|
|
18
|
-
checkConfig as checkS3Config,
|
|
19
|
-
upload as uploadToS3,
|
|
20
|
-
getFileFromS3,
|
|
21
|
-
saveJsonToS3,
|
|
22
|
-
} from "../../libs/s3";
|
|
23
|
-
import type {
|
|
24
|
-
CreateEntryProps,
|
|
25
|
-
Entry,
|
|
26
|
-
} from "contentful-management/dist/typings/entities/entry";
|
|
27
|
-
import { log, serverUtils } from "../../libs/logs";
|
|
28
|
-
import {
|
|
29
|
-
getPimTranslations,
|
|
30
|
-
getLocalISOTime,
|
|
31
|
-
sanitizeValue,
|
|
32
|
-
} from "../../utils";
|
|
33
|
-
import { DProductSubLine } from "../../resources/DProductSubLine";
|
|
34
|
-
import {
|
|
35
|
-
certificationFields,
|
|
36
|
-
excludeCertificationFieldsKeys,
|
|
37
|
-
} from "./products";
|
|
38
|
-
|
|
39
|
-
export const contentTypeId = "globalJsonFile";
|
|
40
|
-
export const entryId = "globalJsonProductFields";
|
|
41
|
-
|
|
42
|
-
type DictionaryRecord = {
|
|
43
|
-
code: string;
|
|
44
|
-
parentName: string | null;
|
|
45
|
-
image: string | null;
|
|
46
|
-
imageAlternative: string | null;
|
|
47
|
-
value_en: string | null;
|
|
48
|
-
value_en_US: string | null;
|
|
49
|
-
value_it: string | null;
|
|
50
|
-
value_es: string | null;
|
|
51
|
-
value_de: string | null;
|
|
52
|
-
value_fr: string | null;
|
|
53
|
-
value_sv: string | null;
|
|
54
|
-
value_no: string | null;
|
|
55
|
-
value_da: string | null;
|
|
56
|
-
value_ru: string | null;
|
|
57
|
-
otherData: ObjectPartial;
|
|
58
|
-
imageS3: string | null;
|
|
59
|
-
imageAlternativeS3: string | null;
|
|
60
|
-
priority: number | null;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const getRequiredDictionaryDataWithIcons = (): ProductFieldsRequiredData[] => {
|
|
64
|
-
return productFieldsRequiredData.filter((field) => field.icon);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const importIcons = async (
|
|
68
|
-
fieldValue: any,
|
|
69
|
-
fieldProductKey: string,
|
|
70
|
-
skipAlreadyExistsCheck: boolean = false
|
|
71
|
-
) => {
|
|
72
|
-
log(`Import icons of field ${fieldProductKey}`);
|
|
73
|
-
const imageFields = ["image", "imageAlternative"];
|
|
74
|
-
|
|
75
|
-
for (const imageField of imageFields) {
|
|
76
|
-
const s3FieldKey = `${imageField}S3`;
|
|
77
|
-
if (fieldValue?.[imageField]) {
|
|
78
|
-
const contentType = mime.lookup(fieldValue[imageField]);
|
|
79
|
-
const imgUrl = fieldValue[imageField];
|
|
80
|
-
const fileName = `${fieldValue.code}.${imgUrl.split(".").pop()}`;
|
|
81
|
-
if (contentType) {
|
|
82
|
-
const path = `icons/${fieldProductKey}/${imageField}`;
|
|
83
|
-
const iconAlreadyExists = await getFileFromS3(
|
|
84
|
-
`${path}/${fileName}`,
|
|
85
|
-
true
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
if (iconAlreadyExists && !skipAlreadyExistsCheck) {
|
|
89
|
-
log(
|
|
90
|
-
`Icon ${imageField} "${fileName}" already exists to"${iconAlreadyExists}"`
|
|
91
|
-
);
|
|
92
|
-
fieldValue[s3FieldKey] = iconAlreadyExists;
|
|
93
|
-
} else {
|
|
94
|
-
log(
|
|
95
|
-
`Uploading icon ${imageField} "${fileName}" to S3 path "${path}"`
|
|
96
|
-
);
|
|
97
|
-
try {
|
|
98
|
-
const res = await uploadToS3(imgUrl, fileName, path);
|
|
99
|
-
fieldValue[s3FieldKey] = res.Location;
|
|
100
|
-
} catch (err: any) {
|
|
101
|
-
log(
|
|
102
|
-
`Uploading icon ${imageField} "${fileName}" to S3 path "${path}" failed. imgUrl: ${imgUrl}`,
|
|
103
|
-
"WARN"
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
log(
|
|
109
|
-
`contentType not found. \nimageField: ${imageField} \nField: ${fieldProductKey} \nCode: ${fieldValue.code}`,
|
|
110
|
-
"ERROR"
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
log(
|
|
115
|
-
`image url not found. \n\nimageField: ${imageField} \nField: ${fieldProductKey} \nCode: ${fieldValue.code}`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return fieldValue;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export const importDictionaryIcons = async (
|
|
123
|
-
skipAlreadyExistsCheck: boolean = false
|
|
124
|
-
): Promise<any> => {
|
|
125
|
-
try {
|
|
126
|
-
checkS3Config();
|
|
127
|
-
|
|
128
|
-
log("importDictionaryIcons - Start", "INFO");
|
|
129
|
-
log("Get S3 JSON dictionary file");
|
|
130
|
-
|
|
131
|
-
const data = await getDictionaryJson();
|
|
132
|
-
|
|
133
|
-
const requiredDictionaryDataWithIcons =
|
|
134
|
-
getRequiredDictionaryDataWithIcons();
|
|
135
|
-
let current: number = 0;
|
|
136
|
-
for (const reqField of requiredDictionaryDataWithIcons) {
|
|
137
|
-
const reqFieldKey = reqField.key;
|
|
138
|
-
if (reqFieldKey && reqField.icon) {
|
|
139
|
-
if (reqField.parent) {
|
|
140
|
-
if (data?.[reqField.parent]?.[reqFieldKey]) {
|
|
141
|
-
await Promise.all(
|
|
142
|
-
data[reqField.parent][reqFieldKey].map(async (field: any) => {
|
|
143
|
-
await importIcons(field, reqFieldKey, skipAlreadyExistsCheck);
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
} else {
|
|
147
|
-
log(`Field ${reqFieldKey} not found into contenful dictionary`);
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
if (data?.[reqFieldKey]) {
|
|
151
|
-
await Promise.all(
|
|
152
|
-
data[reqFieldKey].map(async (field: any) => {
|
|
153
|
-
await importIcons(field, reqFieldKey, skipAlreadyExistsCheck);
|
|
154
|
-
})
|
|
155
|
-
);
|
|
156
|
-
} else {
|
|
157
|
-
log(`Field ${reqFieldKey} not found into contenful dictionary`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (serverUtils) {
|
|
162
|
-
serverUtils.log(reqFieldKey);
|
|
163
|
-
const progress = Math.floor(
|
|
164
|
-
(++current / requiredDictionaryDataWithIcons.length) * 100
|
|
165
|
-
);
|
|
166
|
-
serverUtils.updateProgress(progress);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (data?.certifications) {
|
|
171
|
-
await Promise.all(
|
|
172
|
-
data.certifications.map(async (field: any) => {
|
|
173
|
-
await importIcons(field, "certifications", skipAlreadyExistsCheck);
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
} else {
|
|
177
|
-
log(`No certifications found into contenful dictionary`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Updating S3 dictionary entry data
|
|
181
|
-
log("Updating S3 dictionary entry data");
|
|
182
|
-
await saveJsonToS3(data, "dictionary.json");
|
|
183
|
-
log("importDictionaryIcons - Completed");
|
|
184
|
-
|
|
185
|
-
return { completed: true };
|
|
186
|
-
} catch (err: any) {
|
|
187
|
-
log(err, "ERROR");
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export const importDictionaryFields = async (
|
|
192
|
-
offset: number = 0,
|
|
193
|
-
limit: number = -1
|
|
194
|
-
): Promise<any> => {
|
|
195
|
-
if (limit === 0) {
|
|
196
|
-
log("the limit cannot be 0", "ERROR");
|
|
197
|
-
}
|
|
198
|
-
if (offset === 0) {
|
|
199
|
-
await importDictionaryData();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
log(`importDictionaryFields - offset: ${offset} limit: ${limit}`, "INFO");
|
|
203
|
-
|
|
204
|
-
// Get dictionary data
|
|
205
|
-
log("Get dictionary data");
|
|
206
|
-
const pimDictionaryData: Partial<Record<string, DictionaryRecord[]>> =
|
|
207
|
-
await getDictionary();
|
|
208
|
-
|
|
209
|
-
// Icons Check
|
|
210
|
-
log("Icons Check");
|
|
211
|
-
const iconCodes = ["colour_18k-gold", "colour_alluminio-anodizzato-nero"];
|
|
212
|
-
const iconsCheck = pimDictionaryData?.DWebColour?.filter((c) =>
|
|
213
|
-
iconCodes.includes(c.code)
|
|
214
|
-
);
|
|
215
|
-
let iconEmpty = false;
|
|
216
|
-
if (iconsCheck) {
|
|
217
|
-
for (const icon of iconsCheck) {
|
|
218
|
-
if (!icon?.image) {
|
|
219
|
-
iconEmpty = true;
|
|
220
|
-
console.log(icon);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (iconEmpty) {
|
|
225
|
-
throw new Error(`Icons not found. Codes: ${iconCodes.join(", ")}`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (pimDictionaryData) {
|
|
229
|
-
// Filter required fields
|
|
230
|
-
log("Filter required fields");
|
|
231
|
-
let count: number = 0;
|
|
232
|
-
let current: number = 0;
|
|
233
|
-
const data: ObjectPartial = {};
|
|
234
|
-
productFieldsRequiredData.push({
|
|
235
|
-
key: "designer",
|
|
236
|
-
parent: "",
|
|
237
|
-
icon: false,
|
|
238
|
-
dictionary: "Designer",
|
|
239
|
-
type: "object",
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// productFieldsRequiredData.push({
|
|
243
|
-
// key: "categories",
|
|
244
|
-
// parent: "",
|
|
245
|
-
// icon: false,
|
|
246
|
-
// dictionary: "DCategory",
|
|
247
|
-
// type: "array",
|
|
248
|
-
// });
|
|
249
|
-
// productFieldsRequiredData.push({
|
|
250
|
-
// key: "families",
|
|
251
|
-
// parent: "",
|
|
252
|
-
// icon: false,
|
|
253
|
-
// dictionary: "Family",
|
|
254
|
-
// type: "array",
|
|
255
|
-
// });
|
|
256
|
-
productFieldsRequiredData.push({
|
|
257
|
-
key: "subFamilies",
|
|
258
|
-
parent: "",
|
|
259
|
-
icon: false,
|
|
260
|
-
dictionary: "Subfamily",
|
|
261
|
-
type: "array",
|
|
262
|
-
});
|
|
263
|
-
productFieldsRequiredData.push({
|
|
264
|
-
key: "models",
|
|
265
|
-
parent: "",
|
|
266
|
-
icon: false,
|
|
267
|
-
dictionary: "Model",
|
|
268
|
-
type: "array",
|
|
269
|
-
});
|
|
270
|
-
productFieldsRequiredData.push({
|
|
271
|
-
key: "productLine",
|
|
272
|
-
parent: "",
|
|
273
|
-
icon: false,
|
|
274
|
-
dictionary: "DProductLine",
|
|
275
|
-
type: "array",
|
|
276
|
-
});
|
|
277
|
-
productFieldsRequiredData.push({
|
|
278
|
-
key: "categories",
|
|
279
|
-
parent: "",
|
|
280
|
-
icon: false,
|
|
281
|
-
dictionary: "DCategory",
|
|
282
|
-
type: "array",
|
|
283
|
-
});
|
|
284
|
-
// productFieldsRequiredData.push({
|
|
285
|
-
// key: "subModels",
|
|
286
|
-
// parent: "",
|
|
287
|
-
// icon: false,
|
|
288
|
-
// dictionary: "SubModel",
|
|
289
|
-
// type: "array",
|
|
290
|
-
// });
|
|
291
|
-
for (const productFieldRequiredData of productFieldsRequiredData) {
|
|
292
|
-
if (offset <= count || limit === -1) {
|
|
293
|
-
if (
|
|
294
|
-
productFieldRequiredData.dictionary &&
|
|
295
|
-
pimDictionaryData?.[productFieldRequiredData.dictionary]
|
|
296
|
-
) {
|
|
297
|
-
log(`Import ${productFieldRequiredData.dictionary}`);
|
|
298
|
-
const dictionaryRecord =
|
|
299
|
-
pimDictionaryData?.[productFieldRequiredData.dictionary];
|
|
300
|
-
if (productFieldRequiredData.parent) {
|
|
301
|
-
if (!data[productFieldRequiredData.parent]) {
|
|
302
|
-
data[productFieldRequiredData.parent] = {};
|
|
303
|
-
}
|
|
304
|
-
data[productFieldRequiredData.parent][
|
|
305
|
-
productFieldRequiredData.key
|
|
306
|
-
] = dictionaryRecord;
|
|
307
|
-
} else {
|
|
308
|
-
data[productFieldRequiredData.key] = dictionaryRecord;
|
|
309
|
-
}
|
|
310
|
-
} else if (productFieldRequiredData.dictionary) {
|
|
311
|
-
log(`${productFieldRequiredData.dictionary} not found`, "WARN");
|
|
312
|
-
}
|
|
313
|
-
if (limit !== -1 && count + 1 - offset >= limit) {
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
count++;
|
|
318
|
-
if (serverUtils) {
|
|
319
|
-
serverUtils.log(productFieldRequiredData.key);
|
|
320
|
-
const currentTotal =
|
|
321
|
-
productFieldsRequiredData.length > limit && limit !== -1
|
|
322
|
-
? limit
|
|
323
|
-
: productFieldsRequiredData.length;
|
|
324
|
-
const progress = Math.floor((++current / currentTotal) * 100);
|
|
325
|
-
serverUtils.updateProgress(progress);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const completed = count >= productFieldsRequiredData.length;
|
|
330
|
-
|
|
331
|
-
if (completed) {
|
|
332
|
-
log("Create certifications");
|
|
333
|
-
let certifications: DictionaryRecord[] = [];
|
|
334
|
-
for (const certificationField of certificationFields) {
|
|
335
|
-
const pimCertifications: { string: DictionaryRecord[] } =
|
|
336
|
-
data[certificationField];
|
|
337
|
-
for (const [key, values] of Object.entries(pimCertifications)) {
|
|
338
|
-
if (!excludeCertificationFieldsKeys.includes(key)) {
|
|
339
|
-
log(`Add ${key} values to certifications`);
|
|
340
|
-
certifications = certifications.concat(values);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
log(`Remove unwanted values to certifications`);
|
|
344
|
-
certifications = certifications.filter((value) => {
|
|
345
|
-
return sanitizeValue(value?.code);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
log(`Add certifications to data`);
|
|
349
|
-
data.certifications = certifications;
|
|
350
|
-
|
|
351
|
-
log("Create catalogs");
|
|
352
|
-
data.catalogs = pimDictionaryData.Catalog;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
if (Object.entries(data).length) {
|
|
356
|
-
// Create/Update Contentful entry
|
|
357
|
-
log("Create/Update Contentful entry");
|
|
358
|
-
// await updateContentfulDictionaryData(data, offset === 0);
|
|
359
|
-
|
|
360
|
-
await saveJsonToS3(data, "dictionary.json", "");
|
|
361
|
-
} else {
|
|
362
|
-
log("no matches found", "ERROR");
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
return {
|
|
366
|
-
offset: Number(offset) + Number(limit),
|
|
367
|
-
limit: Number(limit),
|
|
368
|
-
completed, // if is true the import is completed
|
|
369
|
-
total: productFieldsRequiredData.length,
|
|
370
|
-
};
|
|
371
|
-
} else {
|
|
372
|
-
log("no data found in the dictionary", "ERROR");
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
export const importDictionaryData = async (): Promise<any> => {
|
|
377
|
-
log(`importDictionaryData`, "INFO");
|
|
378
|
-
|
|
379
|
-
// Get dictionary data
|
|
380
|
-
log("Get dictionary data");
|
|
381
|
-
const pimDictionaryData: Partial<Record<string, DictionaryRecord[]>> =
|
|
382
|
-
await getDictionary();
|
|
383
|
-
|
|
384
|
-
if (pimDictionaryData && Object.keys(pimDictionaryData).length) {
|
|
385
|
-
const dictionaryData = {} as any;
|
|
386
|
-
|
|
387
|
-
for (const key in pimDictionaryData) {
|
|
388
|
-
if (Array.isArray(pimDictionaryData[key])) {
|
|
389
|
-
//@ts-ignore
|
|
390
|
-
dictionaryData[key] = pimDictionaryData[key].map((item) => ({
|
|
391
|
-
code: item.code,
|
|
392
|
-
parentName: item.parentName,
|
|
393
|
-
image: item.image,
|
|
394
|
-
imageAlternative: item.imageAlternative,
|
|
395
|
-
value_en: item.value_en,
|
|
396
|
-
imageS3: item.imageS3,
|
|
397
|
-
imageAlternativeS3: item.imageAlternativeS3,
|
|
398
|
-
}));
|
|
399
|
-
} else {
|
|
400
|
-
dictionaryData[key] = pimDictionaryData[key];
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (Object.entries(dictionaryData).length) {
|
|
405
|
-
// Create/Update Contentful entry
|
|
406
|
-
log("Create/Update Contentful entry");
|
|
407
|
-
// await updateContentfulDictionaryData(data, offset === 0);
|
|
408
|
-
|
|
409
|
-
await saveJsonToS3(dictionaryData, "dictionary-data.json", "");
|
|
410
|
-
} else {
|
|
411
|
-
log("no matches found", "ERROR");
|
|
412
|
-
}
|
|
413
|
-
} else {
|
|
414
|
-
log("no data found in the dictionary", "ERROR");
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
const getProductLineData = async (
|
|
419
|
-
names: CfLocalizedEntryField,
|
|
420
|
-
code: string,
|
|
421
|
-
productLineEntry: Entry | null
|
|
422
|
-
) => {
|
|
423
|
-
const data: CreateEntryProps = {
|
|
424
|
-
fields: productLineEntry?.fields || {},
|
|
425
|
-
};
|
|
426
|
-
data.fields.name = names;
|
|
427
|
-
data.fields = await addFieldValue(data, "code", code);
|
|
428
|
-
|
|
429
|
-
// lastPimSyncDate
|
|
430
|
-
data.fields = await addFieldValue(data, "lastPimSyncDate", getLocalISOTime());
|
|
431
|
-
|
|
432
|
-
return data;
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Import producLine
|
|
437
|
-
* - name
|
|
438
|
-
* - code
|
|
439
|
-
* - lastPimSyncDate
|
|
440
|
-
*
|
|
441
|
-
* @returns
|
|
442
|
-
*/
|
|
443
|
-
export const importDictionaryProductLine = async (): Promise<any> => {
|
|
444
|
-
log(`importDictionaryProductLine`, "INFO");
|
|
445
|
-
|
|
446
|
-
// Get dictionary data
|
|
447
|
-
log("Get dictionary data");
|
|
448
|
-
const pimDictionaryData = await getDictionary();
|
|
449
|
-
if (pimDictionaryData) {
|
|
450
|
-
let count: number = 0;
|
|
451
|
-
if (pimDictionaryData?.DProductLine.length) {
|
|
452
|
-
for (const item of pimDictionaryData.DProductLine) {
|
|
453
|
-
const names: CfLocalizedEntryField = getPimTranslations(item);
|
|
454
|
-
const productLine: DictionaryRecord = item;
|
|
455
|
-
log(`Import productLine ${productLine.code}`);
|
|
456
|
-
|
|
457
|
-
let productLineEntry = await getEntryByCode(
|
|
458
|
-
productLine.code,
|
|
459
|
-
"topicProductLine"
|
|
460
|
-
);
|
|
461
|
-
|
|
462
|
-
const data: CreateEntryProps = await getProductLineData(
|
|
463
|
-
names,
|
|
464
|
-
productLine.code,
|
|
465
|
-
productLineEntry
|
|
466
|
-
);
|
|
467
|
-
|
|
468
|
-
if (productLineEntry) {
|
|
469
|
-
log(`ProductLine ${productLine.code} already exists. Updating...`);
|
|
470
|
-
productLineEntry = await updateEntry(
|
|
471
|
-
productLineEntry,
|
|
472
|
-
data,
|
|
473
|
-
productLineEntry.isPublished()
|
|
474
|
-
);
|
|
475
|
-
} else {
|
|
476
|
-
log(
|
|
477
|
-
`ProductLine ${productLine.code} not exists. Create new entry with data`
|
|
478
|
-
);
|
|
479
|
-
productLineEntry = await createEntryWithId(
|
|
480
|
-
"topicProductLine",
|
|
481
|
-
productLine.code,
|
|
482
|
-
data,
|
|
483
|
-
true
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
++count;
|
|
488
|
-
if (serverUtils) {
|
|
489
|
-
serverUtils.log(productLine.code);
|
|
490
|
-
const progress = Math.floor(
|
|
491
|
-
(count / pimDictionaryData.DProductLine.length) * 100
|
|
492
|
-
);
|
|
493
|
-
serverUtils.updateProgress(progress);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return count;
|
|
499
|
-
} else {
|
|
500
|
-
log("no data found in the dictionary", "ERROR");
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
const getProductSubLineData = async (
|
|
505
|
-
names: CfLocalizedEntryField,
|
|
506
|
-
code: string,
|
|
507
|
-
productLineEntry: Entry | null,
|
|
508
|
-
productSubLineEntry: Entry | null
|
|
509
|
-
) => {
|
|
510
|
-
const data: CreateEntryProps = {
|
|
511
|
-
fields: productSubLineEntry?.fields || {},
|
|
512
|
-
};
|
|
513
|
-
data.fields.name = names;
|
|
514
|
-
data.fields = await addFieldValue(data, "code", code);
|
|
515
|
-
|
|
516
|
-
// parentProductLine
|
|
517
|
-
if (productLineEntry) {
|
|
518
|
-
data.fields = await addToRelationFields(
|
|
519
|
-
data,
|
|
520
|
-
"parentProductLine",
|
|
521
|
-
productLineEntry.sys.id
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// lastPimSyncDate
|
|
526
|
-
data.fields = await addFieldValue(data, "lastPimSyncDate", getLocalISOTime());
|
|
527
|
-
|
|
528
|
-
return data;
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
export const importDictionaryProductSubLine = async (): Promise<any> => {
|
|
532
|
-
log(`importDictionaryProductSubLine`, "INFO");
|
|
533
|
-
|
|
534
|
-
// Get dictionary data
|
|
535
|
-
log("Get dictionary data");
|
|
536
|
-
const pimDictionaryData = await getDictionary();
|
|
537
|
-
if (pimDictionaryData) {
|
|
538
|
-
let count: number = 0;
|
|
539
|
-
if (pimDictionaryData?.DProductSubLine.length) {
|
|
540
|
-
for (const item of pimDictionaryData.DProductSubLine) {
|
|
541
|
-
const names: CfLocalizedEntryField = getPimTranslations(item);
|
|
542
|
-
const productSubLine: DProductSubLine = item;
|
|
543
|
-
log(`Import productSubLine ${productSubLine.code}`);
|
|
544
|
-
|
|
545
|
-
let productSubLineEntry = await getEntryByCode(
|
|
546
|
-
productSubLine.code,
|
|
547
|
-
"topicProductSubLine"
|
|
548
|
-
);
|
|
549
|
-
|
|
550
|
-
let productLineEntry = null;
|
|
551
|
-
if (productSubLine.othersData.productLine.code) {
|
|
552
|
-
productLineEntry = await getEntryByCode(
|
|
553
|
-
productSubLine.othersData.productLine.code,
|
|
554
|
-
"topicProductLine"
|
|
555
|
-
);
|
|
556
|
-
|
|
557
|
-
if (!productLineEntry) {
|
|
558
|
-
log(
|
|
559
|
-
`No topicProductLine with code ${productSubLine.othersData.productLine.code} found for the productSubLine ${productSubLine.code}`
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
} else {
|
|
563
|
-
log(
|
|
564
|
-
`No parent productLine found for the productSubLine ${productSubLine.code} from PIM`
|
|
565
|
-
);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
const data: CreateEntryProps = await getProductSubLineData(
|
|
569
|
-
names,
|
|
570
|
-
productSubLine.code,
|
|
571
|
-
productLineEntry,
|
|
572
|
-
productSubLineEntry
|
|
573
|
-
);
|
|
574
|
-
|
|
575
|
-
if (productSubLineEntry) {
|
|
576
|
-
log(
|
|
577
|
-
`ProductSubLine ${productSubLine.code} already exists. Updating...`
|
|
578
|
-
);
|
|
579
|
-
productSubLineEntry = await updateEntry(
|
|
580
|
-
productSubLineEntry,
|
|
581
|
-
data,
|
|
582
|
-
productSubLineEntry.isPublished()
|
|
583
|
-
);
|
|
584
|
-
} else {
|
|
585
|
-
log(
|
|
586
|
-
`ProductSubLine ${productSubLine.code} not exists. Create new entry with data`
|
|
587
|
-
);
|
|
588
|
-
productSubLineEntry = await createEntryWithId(
|
|
589
|
-
"topicProductSubLine",
|
|
590
|
-
productSubLine.code,
|
|
591
|
-
data,
|
|
592
|
-
true
|
|
593
|
-
);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
++count;
|
|
597
|
-
if (serverUtils) {
|
|
598
|
-
serverUtils.log(productSubLine.code);
|
|
599
|
-
const progress = Math.floor(
|
|
600
|
-
(count / pimDictionaryData.DProductSubLine.length) * 100
|
|
601
|
-
);
|
|
602
|
-
serverUtils.updateProgress(progress);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
return count;
|
|
608
|
-
} else {
|
|
609
|
-
log("no data found in the dictionary", "ERROR");
|
|
610
|
-
}
|
|
611
|
-
};
|