pim-import 6.14.0 → 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.
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pim-import",
3
- "version": "6.14.0",
3
+ "version": "6.15.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",