pim-import 6.7.0 → 6.9.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.
@@ -12,7 +12,7 @@ export declare const getDictionary: () => Promise<any>;
12
12
  export declare const getAllProducts: (lastModified?: string | null, catalogCode?: AvailableCatalogs | null) => Promise<any>;
13
13
  export declare const getLatestProducts: (catalogCode: AvailableCatalogs, lastModified: string, offset?: number, limit?: number, lastModifiedTo?: string) => Promise<any>;
14
14
  export declare const getProductDetails: (code: string) => Promise<any>;
15
- export declare const getAudit: (lastModified?: string) => Promise<Audit[]>;
15
+ export declare const getAudit: (lastModified?: string) => Promise<Audit>;
16
16
  export declare const getStaticDailyProducts: (catalogCode: AvailableCatalogs, day: string, saveToS3?: boolean) => Promise<any>;
17
17
  type AvailableOtherCatalogCollection = CollectionModels | CollectionSubModels | CollectionSubFamilies;
18
18
  export declare const getOtherCatalogData: <T extends AvailableOtherCatalogCollection>(endpoint: AvailableOtherCatalogDataEndpoint, offset?: number, limit?: number, newEndpoint?: boolean) => Promise<T>;
@@ -54,7 +54,7 @@ const getTopicModelData = async (model, topicModel) => {
54
54
  };
55
55
  data.fields.name = (0, utils_1.getPimTranslations)(model.data);
56
56
  data.fields = await (0, contentful_1.addFieldValue)(data, "code", model.code);
57
- data.fields = await (0, contentful_1.addFieldValue)(data, "priority", model.priority);
57
+ data.fields = await (0, contentful_1.addFieldValue)(data, "priority", model?.priority || 0);
58
58
  data.fields.description = (0, utils_1.getPimTranslations)(model, "description1");
59
59
  if (model.subFamilyCode) {
60
60
  const subFamilyEntry = await (0, contentful_1.getEntryByCode)(model.subFamilyCode, "topicSubFamily", "sys,fields.code,fields.catalog");
@@ -1363,7 +1363,9 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
1363
1363
  };
1364
1364
  }
1365
1365
  const filename = `${lastModified}-all-audit.json`;
1366
- const path = `audit`;
1366
+ const path = `audit${process.env.FPI_CTF_ENVIRONMENT
1367
+ ? "/" + process.env.FPI_CTF_ENVIRONMENT
1368
+ : ""}`;
1367
1369
  await (0, s3_1.saveJsonToS3)(allAudit, filename, path);
1368
1370
  const s3Path = `${path}/${filename}`;
1369
1371
  if (logs_1.serverUtils) {
@@ -1405,6 +1407,7 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
1405
1407
  otherFilters.push({ key: "fields.catalogs.sys.id[in]", value: catalog });
1406
1408
  }
1407
1409
  (0, logs_1.log)(`Get ${productCodes.length} product entry from Contentful`);
1410
+ console.log("productCodes", productCodes);
1408
1411
  const productEntries = await (0, contentful_1.getAllEntriesByCodes)(productCodes, "topicProduct", "sys,fields", "fields.code", otherFilters);
1409
1412
  (0, logs_1.log)(`Founded ${productEntries.length} topicProduct`);
1410
1413
  let familyEntries = [];
@@ -1,2 +1,2 @@
1
1
  import { PaginationResults } from "../../types";
2
- export declare const importSubModels: (offset?: number, limit?: number) => Promise<PaginationResults>;
2
+ export declare const importSubModels: (page?: number, size?: number) => Promise<PaginationResults>;
@@ -12,7 +12,7 @@ const getTopicSubModelData = async (subModel, topicSubModel) => {
12
12
  };
13
13
  data.fields.name = (0, utils_1.getPimTranslations)(subModel.data);
14
14
  data.fields = await (0, contentful_1.addFieldValue)(data, "code", subModel.code);
15
- data.fields = await (0, contentful_1.addFieldValue)(data, "priority", subModel.priority);
15
+ data.fields = await (0, contentful_1.addFieldValue)(data, "priority", subModel?.priority || 0);
16
16
  if (subModel.subFamilyCode) {
17
17
  const subFamilyEntry = await (0, contentful_1.getEntryByCode)(subModel.subFamilyCode, "topicSubFamily", "sys,fields.code,fields.catalog");
18
18
  if (subFamilyEntry) {
@@ -85,37 +85,38 @@ const addSubModelToModel = async (topicSubModelId, topicModelId) => {
85
85
  data.fields = await (0, contentful_1.addToRelationFields)(topicModel, "subModels", topicSubModelId, true);
86
86
  topicModel = await (0, contentful_1.updateEntry)(topicModel, data, topicModel.isPublished());
87
87
  };
88
- const importSubModels = async (offset = 0, limit = 50) => {
88
+ const importSubModels = async (page = 0, size = 50) => {
89
89
  const timeStart = new Date();
90
- (0, logs_1.log)(`importSubModels - offset: ${offset}, limit: ${limit}`, "INFO");
91
- const subModels = await (0, endpoints_1.getOtherCatalogData)("submodels", offset, limit);
92
- const total = subModels?.pagedCollection?.length || 0;
93
- if (subModels?.pagedCollection?.length) {
90
+ (0, logs_1.log)(`importSubModels - page: ${page}, size: ${size}`, "INFO");
91
+ const subModels = await (0, endpoints_1.getOtherCatalogData)("submodels", page, size, true);
92
+ const total = subModels?.content?.length || 0;
93
+ if (subModels?.content?.length) {
94
94
  (0, logs_1.log)(`Founded ${total} subModels`);
95
- let count = offset;
95
+ let count = page * size;
96
96
  let current = 0;
97
- for (const subModel of subModels.pagedCollection) {
98
- (0, logs_1.log)(`${++count} of ${subModels.totalCount}`);
97
+ for (const subModel of subModels.content) {
98
+ (0, logs_1.log)(`${++count} of ${subModels.totalElements}`);
99
99
  await importSubModel(subModel);
100
100
  if (logs_1.serverUtils) {
101
101
  logs_1.serverUtils.log(subModel.code);
102
- const progress = Math.floor((++current / subModels.pagedCollection.length) * 100);
102
+ const progress = Math.floor((++current / subModels.content.length) * 100);
103
103
  logs_1.serverUtils.updateProgress(progress);
104
104
  }
105
- if (count % 2 === 0 && count < subModels.totalCount) {
105
+ if (count % 2 === 0 && count < subModels.totalElements) {
106
106
  await (0, utils_1.sleep)(1000);
107
107
  }
108
108
  }
109
109
  }
110
- const nextOffset = Number(offset) + Number(limit);
111
110
  const timeEnd = new Date();
112
111
  const seconds = (0, utils_1.secondBetweenTwoDate)(timeStart, timeEnd);
113
112
  (0, logs_1.log)(`Request time: ${seconds} seconds`);
113
+ const nextPage = Number(page) + 1;
114
114
  return {
115
- offset: nextOffset,
116
- limit: Number(limit),
117
- completed: nextOffset >= subModels.totalCount,
118
- total: subModels.totalCount,
115
+ page: nextPage,
116
+ size: Number(size),
117
+ completed: nextPage >= subModels.totalPages,
118
+ total: subModels.totalElements,
119
+ totalPages: subModels.totalPages,
119
120
  };
120
121
  };
121
122
  exports.importSubModels = importSubModels;
@@ -1,25 +1,18 @@
1
- type AuditCatalog = {
2
- where: string;
3
- catalogCode?: string;
4
- categoryCode?: string;
5
- subfamilyCode?: string;
6
- models?: string;
7
- subModels?: string;
8
- codes?: string;
9
- };
10
- export interface Audit {
1
+ export type Audit = AuditEntry[];
2
+ export interface AuditEntry {
11
3
  what: string;
12
- when: When;
4
+ when: string;
13
5
  product: string;
14
- upgradeProduct?: string;
6
+ upgradeProduct?: string | null;
15
7
  catalogs: AuditCatalog[];
16
8
  }
17
- export interface When {
18
- year: number;
19
- month: number;
20
- dayOfMonth: number;
21
- hourOfDay: number;
22
- minute: number;
23
- second: number;
9
+ export interface AuditCatalog {
10
+ where: string;
11
+ catalogCode?: string | null;
12
+ categoryCode?: string | null;
13
+ subfamilyCode?: string | null;
14
+ models?: string | null;
15
+ subModels?: string | null;
16
+ accessoryProducts?: string | null;
17
+ codes?: string | null;
24
18
  }
25
- export {};
@@ -1,19 +1,19 @@
1
1
  export interface CollectionSubModels {
2
- totalCount: number;
3
- pageSize: number;
4
- pageOffset: number;
5
- pagedCollection?: PagedCollectionEntity[] | null;
2
+ content: SubModelEntity[];
3
+ page: number;
4
+ size: number;
5
+ totalElements: number;
6
+ totalPages: number;
6
7
  }
7
- export interface PagedCollectionEntity {
8
- relatedProducts?: string[] | null;
8
+ export interface SubModelEntity {
9
9
  data: Data;
10
- priority: number;
10
+ destinations?: string[] | null;
11
+ relatedProducts?: string[] | null;
12
+ code: string;
13
+ priority?: number | null;
11
14
  subFamilyCode: string;
12
15
  productLineCode: string;
13
16
  parentModel: ParentModel;
14
- code: string;
15
- othersData: OthersData;
16
- destinations?: string[];
17
17
  }
18
18
  export interface Data {
19
19
  code: string;
@@ -27,11 +27,11 @@ export interface Data {
27
27
  value_no: string;
28
28
  value_da: string;
29
29
  value_ru: string;
30
- othersData: OthersData;
31
- }
32
- export interface OthersData {
30
+ value_zh: string;
31
+ value_ja: string;
32
+ value_ko: string;
33
33
  }
34
34
  export interface ParentModel {
35
35
  code: string;
36
- othersData: OthersData;
36
+ designers?: Data[] | null;
37
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pim-import",
3
- "version": "6.7.0",
3
+ "version": "6.9.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",