pim-import 5.12.4 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,10 @@ import { AvailableCatalogs, AvailableEntryStatus } from "../types";
2
2
  import { AvailableIndicesKey } from "./config";
3
3
  export declare const removeRecordsByStatus: (indexKey: AvailableIndicesKey, offset?: number, limit?: number, status?: AvailableEntryStatus, catalogCode?: AvailableCatalogs) => Promise<false | {
4
4
  objectIds: string[];
5
- offset: number;
5
+ offset?: number | undefined;
6
6
  limit: number;
7
7
  completed: boolean;
8
8
  s3FilePath?: string | undefined;
9
9
  total?: number | undefined;
10
+ nextPage?: number | null | undefined;
10
11
  }>;
@@ -33,10 +33,11 @@ export declare const reindexDownloads: (offset?: number, limit?: number, filterK
33
33
  savedObjectIDs: string[];
34
34
  deletedObjectIDs: string[];
35
35
  objects: Readonly<Record<string, any>>[];
36
- offset: number;
36
+ offset?: number | undefined;
37
37
  limit: number;
38
38
  completed: boolean;
39
39
  s3FilePath?: string | undefined;
40
40
  total?: number | undefined;
41
+ nextPage?: number | null | undefined;
41
42
  }>;
42
43
  export declare const removeDownloadObject: (objectId: string) => Promise<void>;
@@ -30,11 +30,12 @@ export declare const reindexFamilies: (offset?: number, limit?: number, catalogC
30
30
  savedObjectIDs: string[];
31
31
  deletedObjectIDs: string[];
32
32
  objects: Readonly<Record<string, any>>[];
33
- offset: number;
33
+ offset?: number | undefined;
34
34
  limit: number;
35
35
  completed: boolean;
36
36
  s3FilePath?: string | undefined;
37
37
  total?: number | undefined;
38
+ nextPage?: number | null | undefined;
38
39
  }>;
39
40
  export declare const reindexFamily: (topicFamilyEntryId: string) => Promise<{
40
41
  taskID: number;
@@ -32,10 +32,11 @@ export declare const reindexInspirations: (offset?: number, limit?: number, filt
32
32
  savedObjectIDs: string[];
33
33
  deletedObjectIDs: string[];
34
34
  objects: Readonly<Record<string, any>>[];
35
- offset: number;
35
+ offset?: number | undefined;
36
36
  limit: number;
37
37
  completed: boolean;
38
38
  s3FilePath?: string | undefined;
39
39
  total?: number | undefined;
40
+ nextPage?: number | null | undefined;
40
41
  }>;
41
42
  export declare const removeInspirationObject: (objectId: string) => Promise<void>;
@@ -27,10 +27,11 @@ export declare const reindexModels: (offset?: number, limit?: number, catalogCod
27
27
  savedObjectIDs: string[];
28
28
  deletedObjectIDs: string[];
29
29
  objects: Readonly<Record<string, any>>[];
30
- offset: number;
30
+ offset?: number | undefined;
31
31
  limit: number;
32
32
  completed: boolean;
33
33
  s3FilePath?: string | undefined;
34
34
  total?: number | undefined;
35
+ nextPage?: number | null | undefined;
35
36
  }>;
36
37
  export declare const removeModelObject: (topicModelId: string) => Promise<void>;
@@ -28,10 +28,11 @@ export declare const reindexPosts: (offset?: number, limit?: number, filterKey?:
28
28
  savedObjectIDs: string[];
29
29
  deletedObjectIDs: string[];
30
30
  objects: Readonly<Record<string, any>>[];
31
- offset: number;
31
+ offset?: number | undefined;
32
32
  limit: number;
33
33
  completed: boolean;
34
34
  s3FilePath?: string | undefined;
35
35
  total?: number | undefined;
36
+ nextPage?: number | null | undefined;
36
37
  }>;
37
38
  export declare const removePostObject: (objectId: string) => Promise<void>;
@@ -26,10 +26,11 @@ export declare const reindexPressReleases: (offset?: number, limit?: number, fil
26
26
  savedObjectIDs: string[];
27
27
  deletedObjectIDs: string[];
28
28
  objects: Readonly<Record<string, any>>[];
29
- offset: number;
29
+ offset?: number | undefined;
30
30
  limit: number;
31
31
  completed: boolean;
32
32
  s3FilePath?: string | undefined;
33
33
  total?: number | undefined;
34
+ nextPage?: number | null | undefined;
34
35
  }>;
35
36
  export declare const removePressReleaseObject: (objectId: string) => Promise<void>;
@@ -26,10 +26,11 @@ export declare const reindexPressReviews: (offset?: number, limit?: number, filt
26
26
  savedObjectIDs: string[];
27
27
  deletedObjectIDs: string[];
28
28
  objects: Readonly<Record<string, any>>[];
29
- offset: number;
29
+ offset?: number | undefined;
30
30
  limit: number;
31
31
  completed: boolean;
32
32
  s3FilePath?: string | undefined;
33
33
  total?: number | undefined;
34
+ nextPage?: number | null | undefined;
34
35
  }>;
35
36
  export declare const removePressReviewObject: (objectId: string) => Promise<void>;
@@ -81,10 +81,11 @@ export declare const reindexProducts: (filterKey: string, filterValue: string, o
81
81
  savedObjectIDs: string[];
82
82
  deletedObjectIDs: string[];
83
83
  objects: Readonly<Record<string, any>>[];
84
- offset: number;
84
+ offset?: number | undefined;
85
85
  limit: number;
86
86
  completed: boolean;
87
87
  s3FilePath?: string | undefined;
88
88
  total?: number | undefined;
89
+ nextPage?: number | null | undefined;
89
90
  }>;
90
91
  export declare const removeProductObject: (topicProductId: string) => Promise<void>;
@@ -44,10 +44,11 @@ export declare const reindexProjects: (offset?: number, limit?: number, filterKe
44
44
  savedObjectIDs: string[];
45
45
  deletedObjectIDs: string[];
46
46
  objects: Readonly<Record<string, any>>[];
47
- offset: number;
47
+ offset?: number | undefined;
48
48
  limit: number;
49
49
  completed: boolean;
50
50
  s3FilePath?: string | undefined;
51
51
  total?: number | undefined;
52
+ nextPage?: number | null | undefined;
52
53
  }>;
53
54
  export declare const removeProjectObject: (objectId: string) => Promise<void>;
@@ -40,10 +40,11 @@ export declare const reindexStories: (offset?: number, limit?: number, filterKey
40
40
  savedObjectIDs: string[];
41
41
  deletedObjectIDs: string[];
42
42
  objects: Readonly<Record<string, any>>[];
43
- offset: number;
43
+ offset?: number | undefined;
44
44
  limit: number;
45
45
  completed: boolean;
46
46
  s3FilePath?: string | undefined;
47
47
  total?: number | undefined;
48
+ nextPage?: number | null | undefined;
48
49
  }>;
49
50
  export declare const removeStoryObject: (objectId: string) => Promise<void>;
@@ -3,11 +3,12 @@ export declare const reindexSubFamilies: (offset?: number, limit?: number, catal
3
3
  savedObjectIDs: string[];
4
4
  deletedObjectIDs: string[];
5
5
  objects: Readonly<Record<string, any>>[];
6
- offset: number;
6
+ offset?: number | undefined;
7
7
  limit: number;
8
8
  completed: boolean;
9
9
  s3FilePath?: string | undefined;
10
10
  total?: number | undefined;
11
+ nextPage?: number | null | undefined;
11
12
  }>;
12
13
  export declare const reindexSubFamily: (topicSubFamilyEntryId: string) => Promise<{
13
14
  taskID: number;
@@ -21,10 +21,11 @@ export declare const reindexSubModels: (offset?: number, limit?: number, catalog
21
21
  savedObjectIDs: string[];
22
22
  deletedObjectIDs: string[];
23
23
  objects: Readonly<Record<string, any>>[];
24
- offset: number;
24
+ offset?: number | undefined;
25
25
  limit: number;
26
26
  completed: boolean;
27
27
  s3FilePath?: string | undefined;
28
28
  total?: number | undefined;
29
+ nextPage?: number | null | undefined;
29
30
  }>;
30
31
  export declare const removeSubModelObject: (topicSubModelId: string) => Promise<void>;
@@ -50,7 +50,7 @@ const init = (providedConfig) => {
50
50
  else if (!providedConfig) {
51
51
  throw new Error("Configuration params not found");
52
52
  }
53
- exports.config.baseURL = providedConfig.baseURL;
53
+ exports.config.baseURL = providedConfig.baseURL.replace(/^["']|["']$/g, "");
54
54
  exports.config.username =
55
55
  typeof providedConfig.username !== "undefined"
56
56
  ? providedConfig.username
@@ -706,13 +706,6 @@
706
706
  "dictionary": "",
707
707
  "type": "string"
708
708
  },
709
- {
710
- "key": "dynamicLoad_us",
711
- "parent": "marking",
712
- "icon": false,
713
- "dictionary": "",
714
- "type": "string"
715
- },
716
709
  {
717
710
  "key": "staticLoad",
718
711
  "parent": "marking",
@@ -91,16 +91,16 @@ const getLatestProducts = async (catalogCode, lastModified, offset = 0, limit =
91
91
  onlyweb: true,
92
92
  lastModified,
93
93
  catalog: catalogCode,
94
- offset: offset,
95
- limit: limit,
94
+ page: offset,
95
+ size: limit,
96
96
  lastModifiedTo,
97
97
  };
98
- const { data } = await (0, request_1.getRequest)("latest-products/full", {
98
+ const { data } = await (0, request_1.getRequest)("micro-service/product/paged/search", {
99
99
  params: opts,
100
100
  });
101
101
  const timeEnd = new Date();
102
102
  const seconds = (0, utils_1.secondBetweenTwoDate)(timeStart, timeEnd);
103
- (0, logs_1.log)(`Request time: ${seconds} seconds - endpoint: latest-products/full`);
103
+ (0, logs_1.log)(`Request time: ${seconds} seconds - endpoint: micro-service/product/paged/search`);
104
104
  return data;
105
105
  }
106
106
  catch (err) {
@@ -111,10 +111,10 @@ exports.getLatestProducts = getLatestProducts;
111
111
  const getProductDetails = async (code) => {
112
112
  try {
113
113
  const timeStart = new Date();
114
- const { data } = await (0, request_1.getRequest)(`product/full/${code}`);
114
+ const { data } = await (0, request_1.getRequest)(`micro-service/product/get/${code}`);
115
115
  const timeEnd = new Date();
116
116
  const seconds = (0, utils_1.secondBetweenTwoDate)(timeStart, timeEnd);
117
- (0, logs_1.log)(`Request time: ${seconds} seconds - endpoint: product/full/${code}`);
117
+ (0, logs_1.log)(`Request time: ${seconds} seconds - endpoint: micro-service/product/get/${code}`);
118
118
  return data;
119
119
  }
120
120
  catch (err) {
@@ -1,2 +1,2 @@
1
1
  import { AvailableCatalogs, PaginationResults } from "../../types";
2
- export declare const importLatestProducts: (catalog: AvailableCatalogs, lastModified: string, offset?: number, limit?: number, lastModifiedTo?: string) => Promise<PaginationResults>;
2
+ export declare const importLatestProducts: (catalog: AvailableCatalogs, lastModified: string, page?: number, limit?: number, lastModifiedTo?: string) => Promise<PaginationResults>;
@@ -5,20 +5,20 @@ const endpoints_1 = require("../endpoints");
5
5
  const logs_1 = require("../../libs/logs");
6
6
  const products_1 = require("./products");
7
7
  const utils_1 = require("../../utils");
8
- const importLatestProducts = async (catalog, lastModified, offset = 0, limit = 100, lastModifiedTo = "") => {
8
+ const importLatestProducts = async (catalog, lastModified, page = 0, limit = 100, lastModifiedTo = "") => {
9
9
  const timeStart = new Date();
10
- offset = Number(offset);
10
+ page = Number(page);
11
11
  limit = Number(limit);
12
- (0, logs_1.log)(`importLatestProducts - catalog: ${catalog} lastModified: ${lastModified} offset: ${offset} limit: ${limit} lastModifiedTo: ${lastModifiedTo}`, "INFO");
13
- const data = await (0, endpoints_1.getLatestProducts)(catalog, lastModified, offset, limit, lastModifiedTo);
14
- const total = data.totalCount;
15
- const products = data.pagedCollection;
12
+ (0, logs_1.log)(`importLatestProducts - catalog: ${catalog} lastModified: ${lastModified} page: ${page} limit: ${limit} lastModifiedTo: ${lastModifiedTo}`, "INFO");
13
+ const data = await (0, endpoints_1.getLatestProducts)(catalog, lastModified, page, limit, lastModifiedTo);
14
+ const total = data.totalElements;
15
+ const products = data.content;
16
16
  (0, logs_1.log)(`${total} products founded`);
17
- let count = offset + 1;
17
+ let count = page * limit + 1;
18
18
  let current = 0;
19
19
  for (const product of products) {
20
20
  (0, logs_1.log)(`${count} of ${total}`);
21
- const productDetails = product.content;
21
+ const productDetails = product;
22
22
  await (0, products_1.importProduct)(productDetails, catalog);
23
23
  count++;
24
24
  if (logs_1.serverUtils) {
@@ -30,9 +30,9 @@ const importLatestProducts = async (catalog, lastModified, offset = 0, limit = 1
30
30
  const timeEnd = new Date();
31
31
  const seconds = (0, utils_1.secondBetweenTwoDate)(timeStart, timeEnd);
32
32
  (0, logs_1.log)(`Request time: ${seconds} seconds`);
33
- const completed = limit === -1 || offset >= total;
33
+ const completed = count >= total;
34
34
  return {
35
- offset: completed ? offset : offset + limit,
35
+ nextPage: completed ? null : page + 1,
36
36
  limit,
37
37
  completed,
38
38
  total,
@@ -93,7 +93,7 @@ const isTermsToAdd = async (productDetails, catalog) => {
93
93
  const modelsFieldKey = "models" + (0, utils_1.capitalizeFirstLetter)(catalog);
94
94
  if (productDetails.models) {
95
95
  for (const model of productDetails.models) {
96
- const modelCode = model.data.code;
96
+ const modelCode = model.code;
97
97
  if (modelCode) {
98
98
  (0, logs_1.log)(`Get model entry with id ${modelCode}`);
99
99
  const modelEntry = await (0, contentful_1.getEntryByID)(modelCode, "topicModel", "sys");
@@ -116,7 +116,7 @@ const isTermsToAdd = async (productDetails, catalog) => {
116
116
  const subModelsFieldKey = "subModels" + (0, utils_1.capitalizeFirstLetter)(catalog);
117
117
  if (productDetails.submodels) {
118
118
  for (const submodel of productDetails.submodels) {
119
- const subModelCode = submodel.data.code;
119
+ const subModelCode = submodel.code;
120
120
  if (subModelCode) {
121
121
  (0, logs_1.log)(`Get subModel entry with id ${subModelCode}`);
122
122
  const subModelEntry = await (0, contentful_1.getEntryByID)(subModelCode, "topicSubModel", "sys");
@@ -529,7 +529,7 @@ const getProductData = async (productEntry, productDetails) => {
529
529
  if (productDetails?.models) {
530
530
  (0, logs_1.log)(`Set ${productDetails.models.length} model relations`);
531
531
  const modelCodes = productDetails.models.map((model) => {
532
- return model.data.code;
532
+ return model.code;
533
533
  });
534
534
  const topicModelEntries = await (0, contentful_1.getAllEntriesByCodes)(modelCodes, "topicModel", "sys,fields.catalog");
535
535
  if (topicModelEntries.length) {
@@ -553,7 +553,7 @@ const getProductData = async (productEntry, productDetails) => {
553
553
  if (productDetails?.submodels) {
554
554
  (0, logs_1.log)(`Set ${productDetails.submodels.length} subModels relations`);
555
555
  const subModelsCodes = productDetails.submodels.map((subModel) => {
556
- return subModel.data.code;
556
+ return subModel.code;
557
557
  });
558
558
  const topicSubModelEntries = await (0, contentful_1.getAllEntriesByCodes)(subModelsCodes, "topicSubModel", "sys,fields.catalog");
559
559
  if (topicSubModelEntries.length) {
@@ -682,7 +682,46 @@ const getProductColourVariantsData = async (topicProductColourVariantsCode, prod
682
682
  data.fields.lastPimSyncDate[defaultEnvironmentLocaleCode] = (0, utils_1.getLocalISOTime)();
683
683
  return data;
684
684
  };
685
+ const removeProductColourVariants = async (productEntryId) => {
686
+ (0, logs_1.log)(`Remove product from all topicProductColourVariants`);
687
+ const env = await (0, contentful_1.getEnvironment)();
688
+ const defEnvLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
689
+ const { items: allTopicProductColourVariants } = await env.getEntries({
690
+ content_type: "topicProductColourVariants",
691
+ locale: defEnvLocaleCode,
692
+ include: 1,
693
+ links_to_entry: productEntryId,
694
+ limit: 1000,
695
+ });
696
+ (0, logs_1.log)(`Found ${allTopicProductColourVariants.length} topicProductColourVariants`);
697
+ for (let topicProductColourVariants of allTopicProductColourVariants) {
698
+ topicProductColourVariants.fields = await (0, contentful_1.removeFromRelationFields)(topicProductColourVariants, "products", productEntryId, true);
699
+ try {
700
+ topicProductColourVariants = await topicProductColourVariants.update();
701
+ if (topicProductColourVariants.isPublished()) {
702
+ try {
703
+ topicProductColourVariants =
704
+ await topicProductColourVariants.publish();
705
+ }
706
+ catch (err) {
707
+ const message = `addProductColourVariants - Cannot publish entry. ${topicProductColourVariants.sys.id}`;
708
+ await (0, notifications_1.notify)(message, false);
709
+ (0, logs_1.log)(message);
710
+ (0, logs_1.log)(err);
711
+ }
712
+ }
713
+ }
714
+ catch (err) {
715
+ const message = `addProductColourVariants - Cannot update entry. ${topicProductColourVariants.sys.id}`;
716
+ await (0, notifications_1.notify)(message, false);
717
+ (0, logs_1.log)(message);
718
+ (0, logs_1.log)(err);
719
+ }
720
+ }
721
+ };
685
722
  const addProductColourVariants = async (colourVariants, productEntryId) => {
723
+ await removeProductColourVariants(productEntryId);
724
+ (0, logs_1.log)(`Add product to the topicProductColourVariants of the ${colourVariants.length} colour variants`);
686
725
  for (const colourVariant of colourVariants) {
687
726
  const topicId = `PCV_${colourVariant.code}`;
688
727
  let topicProductColourVariants = await (0, contentful_1.getEntryByID)(topicId, "topicProductColourVariants");
@@ -1509,11 +1548,9 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
1509
1548
  const fileName = (pageSlug.length >= 170
1510
1549
  ? `tech-spec-${topicProductId}`
1511
1550
  : `tech-spec-${pageSlug}`) + `_${country}-${locale}`;
1512
- let baseUrl = country === "cn"
1513
- ? process.env.FPI_TECH_SPEC_BASE_URL_CN ?? ""
1514
- : process.env.FPI_TECH_SPEC_BASE_URL ?? "";
1551
+ let baseUrl = process.env.FPI_TECH_SPEC_BASE_URL ?? "";
1515
1552
  if (!baseUrl) {
1516
- (0, logs_1.log)(`FPI_TECH_SPEC_BASE_URL process env not found for country ${country}`, "ERROR");
1553
+ (0, logs_1.log)(`FPI_TECH_SPEC_BASE_URL process env not found`, "ERROR");
1517
1554
  }
1518
1555
  baseUrl = baseUrl.replace(/\/?(\?|#|$)/, "/$1");
1519
1556
  let footerBaseUrl = country === "cn"
@@ -265,8 +265,7 @@ export interface CatalogsEntity {
265
265
  familyCode?: string | null;
266
266
  childFamilyCode?: null;
267
267
  }
268
- export interface ModelsEntityOrParentModel {
269
- data: GenericData;
268
+ export interface ModelsEntityOrParentModel extends GenericData {
270
269
  priority: number;
271
270
  subFamilyCode: string;
272
271
  productLineCode: string;
@@ -290,23 +289,11 @@ export interface ModelsEntityOrParentModel {
290
289
  description2_da?: null;
291
290
  description2_ru?: null;
292
291
  description2_en_us?: null;
293
- code?: null;
294
292
  image?: null;
295
293
  imageAlternative?: null;
296
- value_en?: null;
297
- value_en_US?: null;
298
- value_it?: null;
299
- value_es?: null;
300
- value_de?: null;
301
- value_fr?: null;
302
- value_sv?: null;
303
- value_no?: null;
304
- value_da?: null;
305
- value_ru?: null;
306
294
  othersData: OthersData;
307
295
  }
308
- export interface SubmodelsEntity {
309
- data: GenericData;
296
+ export interface SubmodelsEntity extends GenericData {
310
297
  priority: number;
311
298
  subFamilyCode?: null;
312
299
  productLineCode?: null;
@@ -331,19 +318,7 @@ export interface SubmodelsEntity {
331
318
  description2_da?: null;
332
319
  description2_ru?: null;
333
320
  description2_en_us?: null;
334
- code?: null;
335
- image?: null;
336
321
  imageAlternative?: null;
337
- value_en?: null;
338
- value_en_US?: null;
339
- value_it?: null;
340
- value_es?: null;
341
- value_de?: null;
342
- value_fr?: null;
343
- value_sv?: null;
344
- value_no?: null;
345
- value_da?: null;
346
- value_ru?: null;
347
322
  othersData: OthersData;
348
323
  }
349
324
  export interface ColourVariant {
package/dist/types.d.ts CHANGED
@@ -61,11 +61,12 @@ export type CfSys = {
61
61
  };
62
62
  };
63
63
  export type PaginationResults = {
64
- offset: number;
64
+ offset?: number;
65
65
  limit: number;
66
66
  completed: boolean;
67
67
  s3FilePath?: string;
68
68
  total?: number;
69
+ nextPage?: number | null;
69
70
  };
70
71
  export type CfLocalizedEntryField = Partial<Record<ContentfulLocale, string | null>>;
71
72
  export type TopicDetailsResponse = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pim-import",
3
- "version": "5.12.4",
3
+ "version": "6.0.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",