pim-import 6.13.1 → 6.15.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.
@@ -1,14 +1,10 @@
1
- import { CfLocalizedEntryField, TopicDetailsResponse, TopicProductFieldsResponse, WrapperImageFields, AvailableCatalogs } from "../types";
1
+ import { CfLocalizedEntryField, TopicDetailsResponse, TopicProductFieldsResponse, WrapperImageFields, AvailableCatalogs, SubFamiliyDownloadButtons } from "../types";
2
2
  export type pageResponse = {
3
3
  slugs: {};
4
4
  type: string;
5
5
  details?: {};
6
+ downloadButtons?: SubFamiliyDownloadButtons;
6
7
  } | null;
7
- type downloadButton = {
8
- key: string;
9
- to: string;
10
- downloadType: string;
11
- };
12
8
  export type AlgoliaFamilyRecord = {
13
9
  objectID: string;
14
10
  names: CfLocalizedEntryField;
@@ -28,7 +24,7 @@ export type AlgoliaFamilyRecord = {
28
24
  productFieldsCn: TopicProductFieldsResponse[];
29
25
  isNew: boolean;
30
26
  priority: number;
31
- downloadButtons?: downloadButton[];
27
+ downloadButtons?: SubFamiliyDownloadButtons;
32
28
  destinations?: string[];
33
29
  lastSyncDate: string;
34
30
  };
@@ -67,10 +63,9 @@ export declare const reindexFamily: (topicFamilyEntryId: string) => Promise<{
67
63
  productFieldsCn: TopicProductFieldsResponse[];
68
64
  isNew: boolean;
69
65
  priority: number;
70
- downloadButtons?: downloadButton[] | undefined;
66
+ downloadButtons?: SubFamiliyDownloadButtons | undefined;
71
67
  destinations?: string[] | undefined;
72
68
  lastSyncDate: string;
73
69
  taskID: number;
74
70
  }>;
75
71
  export declare const removeFamilyObject: (objectId: string) => Promise<void>;
76
- export {};
@@ -6,6 +6,7 @@ const logs_1 = require("../libs/logs");
6
6
  const config_1 = require("./config");
7
7
  const utils_1 = require("../utils");
8
8
  const subfamilies_1 = require("../pim/methods/subfamilies");
9
+ const subFamilies_1 = require("./subFamilies");
9
10
  const imgix_1 = require("../libs/imgix");
10
11
  const indexKey = "families";
11
12
  const getFamilyPage = async (topicFamily) => {
@@ -45,11 +46,14 @@ const getFamilyPage = async (topicFamily) => {
45
46
  (0, logs_1.log)(`The modelPage with id "${modelPageId}" not found`, "WARN");
46
47
  }
47
48
  }
48
- const subFamilyEntry = await (0, contentful_cda_1.getEntryByID)(subFamilyPageId.replace("_PAGE", ""), "topicSubFamily", "sys,fields.catalog,fields.category,fields.parentFamily");
49
+ const subFamilyEntry = await (0, contentful_cda_1.getEntryByID)(subFamilyPageId.replace("_PAGE", ""), "topicSubFamily", "sys,fields.catalog,fields.category,fields.parentFamily,fields.leaflet,fields.datasheet,fields.specsheet_us");
49
50
  if (subFamilyEntry) {
50
51
  const subFamilyPageSlugWithDetails = await (0, subfamilies_1.getSubFamilyPageSlugWithDetails)(subFamilyEntry);
51
52
  if (subFamilyPageSlugWithDetails) {
52
- return subFamilyPageSlugWithDetails;
53
+ return {
54
+ ...subFamilyPageSlugWithDetails,
55
+ downloadButtons: (0, subFamilies_1.getDownloadButtons)(subFamilyEntry, defaultEnvironmentLocaleCode),
56
+ };
53
57
  }
54
58
  }
55
59
  else {
@@ -196,6 +200,7 @@ const getObject = async (topicFamily) => {
196
200
  productFieldsCn,
197
201
  priority,
198
202
  isNew,
203
+ downloadButtons: page?.downloadButtons || {},
199
204
  destinations: topicFamilyWithFields?.fields?.destinations?.[defaultEnvironmentLocaleCode] || [],
200
205
  lastSyncDate: (0, utils_1.getLocalISOTime)(),
201
206
  };
@@ -1,4 +1,6 @@
1
- import { AvailableCatalogs } from "../types";
1
+ import { AvailableCatalogs, SubFamiliyDownloadButtons } from "../types";
2
+ import type { Entry } from "contentful-management/dist/typings/entities/entry";
3
+ export declare const getDownloadButtons: (topicSubFamily: Entry, defaultEnvironmentLocaleCode: string) => SubFamiliyDownloadButtons;
2
4
  export declare const reindexSubFamilies: (offset?: number, limit?: number, catalogCode?: AvailableCatalogs) => Promise<{
3
5
  savedObjectIDs: string[];
4
6
  deletedObjectIDs: string[];
@@ -34,11 +36,7 @@ export declare const reindexSubFamily: (topicSubFamilyEntryId: string) => Promis
34
36
  productFieldsCn: import("../types").TopicProductFieldsResponse[];
35
37
  isNew: boolean;
36
38
  priority: number;
37
- downloadButtons?: {
38
- key: string;
39
- to: string;
40
- downloadType: string;
41
- }[] | undefined;
39
+ downloadButtons?: SubFamiliyDownloadButtons | undefined;
42
40
  destinations?: string[] | undefined;
43
41
  lastSyncDate: string;
44
42
  taskID: number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeSubFamilyObject = exports.reindexSubFamily = exports.reindexSubFamilies = void 0;
3
+ exports.removeSubFamilyObject = exports.reindexSubFamily = exports.reindexSubFamilies = exports.getDownloadButtons = void 0;
4
4
  const contentful_cda_1 = require("../libs/contentful-cda");
5
5
  const logs_1 = require("../libs/logs");
6
6
  const config_1 = require("./config");
@@ -144,37 +144,35 @@ const isObjectToDelete = (object, defaultEnvironmentLocaleCode) => {
144
144
  return (!object?.productFields || !object?.slugs?.[defaultEnvironmentLocaleCode]);
145
145
  };
146
146
  const getDownloadButtons = (topicSubFamily, defaultEnvironmentLocaleCode) => {
147
- const downloadButtons = [];
147
+ const downloadButtons = {};
148
148
  const topicSubFamilyFields = topicSubFamily?.fields;
149
149
  if (topicSubFamilyFields?.leaflet?.[defaultEnvironmentLocaleCode]?.fields
150
150
  ?.file?.[defaultEnvironmentLocaleCode]?.url) {
151
- downloadButtons.push({
152
- key: "leaflet",
151
+ downloadButtons.leaflet = {
153
152
  to: topicSubFamilyFields.leaflet?.[defaultEnvironmentLocaleCode]?.fields
154
153
  ?.file?.[defaultEnvironmentLocaleCode]?.url,
155
154
  downloadType: "pdf",
156
- });
155
+ };
157
156
  }
158
157
  if (topicSubFamilyFields?.datasheet?.[defaultEnvironmentLocaleCode]?.fields
159
158
  ?.file?.[defaultEnvironmentLocaleCode]?.url) {
160
- downloadButtons.push({
161
- key: "datasheet",
159
+ downloadButtons.datasheet = {
162
160
  to: topicSubFamilyFields.datasheet?.[defaultEnvironmentLocaleCode]?.fields
163
161
  ?.file?.[defaultEnvironmentLocaleCode]?.url,
164
162
  downloadType: "pdf",
165
- });
163
+ };
166
164
  }
167
165
  if (topicSubFamilyFields?.specsheet_us?.[defaultEnvironmentLocaleCode]?.fields
168
166
  ?.file?.[defaultEnvironmentLocaleCode]?.url) {
169
- downloadButtons.push({
170
- key: "specsheet_us",
167
+ downloadButtons.specsheet_us = {
171
168
  to: topicSubFamilyFields.specsheet_us?.[defaultEnvironmentLocaleCode]
172
169
  ?.fields?.file?.[defaultEnvironmentLocaleCode]?.url,
173
170
  downloadType: "pdf",
174
- });
171
+ };
175
172
  }
176
173
  return downloadButtons;
177
174
  };
175
+ exports.getDownloadButtons = getDownloadButtons;
178
176
  const getObject = async (topicSubFamily) => {
179
177
  const defaultEnvironmentLocaleCode = await (0, contentful_cda_1.getEnvironmentDefaultLocaleCode)();
180
178
  (0, logs_1.log)(`Get details of the ${topicSubFamily.sys.id} topicSubFamily`);
@@ -248,7 +246,7 @@ const getObject = async (topicSubFamily) => {
248
246
  (0, logs_1.log)(`Get priority details...`);
249
247
  const priority = topicSubFamilyWithFields?.fields?.priority?.[defaultEnvironmentLocaleCode] || 0;
250
248
  (0, logs_1.log)(`Get download buttons details...`);
251
- const downloadButtons = getDownloadButtons(topicSubFamilyWithFields, defaultEnvironmentLocaleCode);
249
+ const downloadButtons = (0, exports.getDownloadButtons)(topicSubFamilyWithFields, defaultEnvironmentLocaleCode);
252
250
  const record = {
253
251
  objectID: topicSubFamilyWithFields.sys.id,
254
252
  names: await (0, utils_1.getAllTranslations)(topicSubFamilyWithFields?.fields?.name || {}),
package/dist/libs/s3.d.ts CHANGED
@@ -17,7 +17,6 @@ export declare const upload: (url: string, fileName?: string, path?: string, met
17
17
  export declare const fileExistsOnS3: (path: string) => Promise<boolean>;
18
18
  export declare const getFileFromS3: (path: string, returnUrl?: boolean) => Promise<any>;
19
19
  export declare const saveCatalogToS3: (catalog: AvailableCatalogs) => Promise<string>;
20
- export declare const saveAllProductsToS3: (catalog: AvailableCatalogs, lastModified: string) => Promise<string>;
21
20
  export declare const saveJsonToS3: (obj: any, fileName?: string, path?: string) => Promise<import("@aws-sdk/client-s3").CompleteMultipartUploadCommandOutput>;
22
21
  export declare const savePDFToS3: (pdf: any, fileName: string, path?: string) => Promise<string | undefined>;
23
22
  export {};
package/dist/libs/s3.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.savePDFToS3 = exports.saveJsonToS3 = exports.saveAllProductsToS3 = exports.saveCatalogToS3 = exports.getFileFromS3 = exports.fileExistsOnS3 = exports.upload = exports.listObjects = exports.init = exports.checkConfig = exports.s3Client = exports.config = void 0;
6
+ exports.savePDFToS3 = exports.saveJsonToS3 = exports.saveCatalogToS3 = exports.getFileFromS3 = exports.fileExistsOnS3 = exports.upload = exports.listObjects = exports.init = exports.checkConfig = exports.s3Client = exports.config = void 0;
7
7
  const dotenv_1 = __importDefault(require("dotenv"));
8
8
  const axios_1 = __importDefault(require("@atoms-studio/axios"));
9
9
  const client_s3_1 = require("@aws-sdk/client-s3");
@@ -165,24 +165,6 @@ const saveCatalogToS3 = async (catalog) => {
165
165
  return `${path}${fileName}`;
166
166
  };
167
167
  exports.saveCatalogToS3 = saveCatalogToS3;
168
- const saveAllProductsToS3 = async (catalog, lastModified) => {
169
- (0, config_1.checkConfig)();
170
- (0, exports.checkConfig)();
171
- const timeStart = new Date();
172
- const dateNow = new Date();
173
- const dateDirName = dateNow.toISOString().split("T")[0];
174
- const path = `pim/${dateDirName}/all-products/`;
175
- const fileName = `all-products-${catalog}-${lastModified}.json`;
176
- const fileUrl = `${config_1.config.baseURL}products/?onlyweb=true&catalog=${catalog}&lastModified=${lastModified}`;
177
- (0, logs_1.log)(`Uploading "${fileName}" to S3 path "${path}"`, "INFO");
178
- await (0, exports.upload)(fileUrl, fileName, path);
179
- (0, logs_1.log)(`"${fileName}" saved to S3`);
180
- const timeEnd = new Date();
181
- const seconds = (0, utils_1.secondBetweenTwoDate)(timeStart, timeEnd);
182
- (0, logs_1.log)(`Request time: ${seconds} seconds - saveAllProductsToS3`);
183
- return `${path}${fileName}`;
184
- };
185
- exports.saveAllProductsToS3 = saveAllProductsToS3;
186
168
  const saveJsonToS3 = async (obj, fileName = "", path = "") => {
187
169
  (0, exports.checkConfig)();
188
170
  const timeStart = new Date();
@@ -11,18 +11,12 @@ export declare const getProductPageIdByCode: (productCode: string) => string;
11
11
  export declare const importProduct: (productDetails: ProductDetails, catalog: AvailableCatalogs, familyCodeIn?: string[], subFamilyCodeIn?: string[]) => Promise<boolean>;
12
12
  export declare const pimKeyRenamedCheck: (key: string) => string;
13
13
  export declare const setProductRelationships: (code: string, fieldKey?: AvailableRelationFieldKeys | null) => Promise<void>;
14
- export declare const setProductsRelationships: (catalog: AvailableCatalogs, lastModified: string, fieldKey: AvailableRelationFieldKeys | null, offset?: number, limit?: number, s3FilePath?: string) => Promise<{
15
- offset: number;
16
- limit: number;
17
- completed: boolean;
18
- s3FilePath: string;
19
- total?: undefined;
20
- } | {
21
- offset: number;
22
- limit: number;
14
+ export declare const setProductsRelationships: (catalog: AvailableCatalogs, lastModified: string, fieldKey: AvailableRelationFieldKeys | null, page: number | undefined, size: number | undefined, lastModifiedTo: string) => Promise<{
15
+ page: number;
16
+ size: number;
23
17
  completed: boolean;
24
- s3FilePath: string;
25
- total: number;
18
+ totalElements: number;
19
+ totalPages: any;
26
20
  }>;
27
21
  export declare const getAllProductEntriesByCatalog: (catalog: AvailableCatalogs, limit?: number, select?: string) => Promise<Entry[]>;
28
22
  export declare const audit: (lastModified: string, catalog: AvailableCatalogs, offset?: number, limit?: number, s3FilePath?: string) => Promise<{
@@ -928,46 +928,26 @@ const setProductRelationships = async (code, fieldKey = null) => {
928
928
  }
929
929
  };
930
930
  exports.setProductRelationships = setProductRelationships;
931
- const setProductsRelationships = async (catalog, lastModified, fieldKey, offset = 0, limit = 150, s3FilePath = "") => {
931
+ const setProductsRelationships = async (catalog, lastModified, fieldKey, page = 0, size = 150, lastModifiedTo) => {
932
932
  const timeStart = new Date();
933
- (0, logs_1.log)(`setProductsRelationships - catalog: ${catalog} lastModified: ${lastModified} fieldKey: ${fieldKey} offset: ${offset} limit: ${limit} s3FilePath: ${s3FilePath}`, "INFO");
934
- if (!s3FilePath) {
935
- const s3Path = await (0, s3_1.saveAllProductsToS3)(catalog, lastModified);
936
- const tEnd = new Date();
937
- const secs = (0, utils_1.secondBetweenTwoDate)(timeStart, tEnd);
938
- (0, logs_1.log)(`Request time: ${secs} seconds`);
939
- return {
940
- offset: Number(offset),
941
- limit: Number(limit),
942
- completed: false,
943
- s3FilePath: s3Path,
944
- };
945
- }
946
- const JSONData = await (0, s3_1.getFileFromS3)(s3FilePath);
947
- const total = JSONData.length;
948
- (0, logs_1.log)(`${total} products founded`);
949
- let count = 0;
933
+ (0, logs_1.log)(`setProductsRelationships - catalog: ${catalog} lastModified: ${lastModified} fieldKey: ${fieldKey} page: ${page} size: ${size}`, "INFO");
934
+ const data = await (0, endpoints_1.getLatestProducts)(catalog, lastModified, page, size, lastModifiedTo);
935
+ const totalElements = data.totalElements;
936
+ (0, logs_1.log)(`${totalElements} products founded`);
950
937
  let updated = 0;
951
938
  let current = 0;
952
- for (const product of JSONData) {
953
- if (offset <= count || limit === -1) {
954
- (0, logs_1.log)(`${count + 1} of ${JSONData.length}`);
955
- await (0, exports.setProductRelationships)(product.code, fieldKey);
956
- updated++;
957
- if (logs_1.serverUtils) {
958
- logs_1.serverUtils.log(product.code);
959
- const currentTotal = JSONData.length > limit && limit !== -1 ? limit : JSONData.length;
960
- const progress = Math.floor((++current / currentTotal) * 100);
961
- logs_1.serverUtils.updateProgress(progress);
962
- }
963
- if (updated % 7 === 0) {
964
- await (0, utils_1.sleep)(500);
965
- }
966
- if (limit !== -1 && count + 1 - offset >= limit) {
967
- break;
968
- }
939
+ for (const product of data.content) {
940
+ (0, logs_1.log)(`${++current + page * size} of ${totalElements} - Set relationships for product ${product.code}`);
941
+ await (0, exports.setProductRelationships)(product.code, fieldKey);
942
+ updated++;
943
+ if (logs_1.serverUtils) {
944
+ logs_1.serverUtils.log(product.code);
945
+ const progress = Math.floor((current / data.content.length) * 100);
946
+ logs_1.serverUtils.updateProgress(progress);
947
+ }
948
+ if (updated % 7 === 0) {
949
+ await (0, utils_1.sleep)(500);
969
950
  }
970
- count++;
971
951
  }
972
952
  const timeEnd = new Date();
973
953
  const seconds = (0, utils_1.secondBetweenTwoDate)(timeStart, timeEnd);
@@ -975,12 +955,13 @@ const setProductsRelationships = async (catalog, lastModified, fieldKey, offset
975
955
  if (logs_1.serverUtils) {
976
956
  logs_1.serverUtils.updateProgress(100);
977
957
  }
958
+ const nextPage = Number(page) + 1;
978
959
  return {
979
- offset: Number(offset) + Number(limit),
980
- limit: Number(limit),
981
- completed: limit === -1 || limit > updated,
982
- s3FilePath,
983
- total: JSONData.length,
960
+ page: nextPage,
961
+ size,
962
+ completed: nextPage >= data.totalPages,
963
+ totalElements,
964
+ totalPages: data.totalPages,
984
965
  };
985
966
  };
986
967
  exports.setProductsRelationships = setProductsRelationships;
package/dist/types.d.ts CHANGED
@@ -196,3 +196,17 @@ export type AlgoliaObjectFilter = {
196
196
  key: string;
197
197
  value: string;
198
198
  };
199
+ export type SubFamiliyDownloadButtons = {
200
+ leaflet?: {
201
+ to: string;
202
+ downloadType: string;
203
+ };
204
+ datasheet?: {
205
+ to: string;
206
+ downloadType: string;
207
+ };
208
+ specsheet_us?: {
209
+ to: string;
210
+ downloadType: string;
211
+ };
212
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pim-import",
3
- "version": "6.13.1",
3
+ "version": "6.15.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",