pim-import 5.12.2 → 5.12.3

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
@@ -14,6 +14,7 @@ export declare const checkConfig: (skipInit?: boolean) => void;
14
14
  export declare const init: (opts?: Config) => void;
15
15
  export declare const listObjects: (prefix?: string) => Promise<import("@aws-sdk/client-s3").ListObjectsV2CommandOutput>;
16
16
  export declare const upload: (url: string, fileName?: string, path?: string, metaData?: any) => Promise<import("@aws-sdk/client-s3").CompleteMultipartUploadCommandOutput>;
17
+ export declare const fileExistsOnS3: (path: string) => Promise<boolean>;
17
18
  export declare const getFileFromS3: (path: string, returnUrl?: boolean) => Promise<any>;
18
19
  export declare const saveCatalogToS3: (catalog: AvailableCatalogs) => Promise<string>;
19
20
  export declare const saveAllProductsToS3: (catalog: AvailableCatalogs, lastModified: string) => Promise<string>;
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.upload = exports.listObjects = exports.init = exports.checkConfig = exports.s3Client = exports.config = void 0;
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;
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");
@@ -112,23 +112,41 @@ const upload = async (url, fileName = "", path = "", metaData = {}) => {
112
112
  }
113
113
  };
114
114
  exports.upload = upload;
115
- const getFileFromS3 = async (path, returnUrl = false) => {
115
+ const fileExistsOnS3 = async (path) => {
116
116
  (0, exports.checkConfig)();
117
- const url = `https://${exports.config.bucket}.s3.${exports.config.region}.amazonaws.com/${path}`;
117
+ const command = new client_s3_1.HeadObjectCommand({
118
+ Bucket: exports.config.bucket,
119
+ Key: path,
120
+ });
118
121
  try {
119
- const opts = !returnUrl ? {} : { responseType: "arraybuffer" };
120
- const res = await axios_1.default.get(url, opts);
121
- if (returnUrl) {
122
- return url;
123
- }
124
- else {
125
- return res.data;
122
+ await exports.s3Client.send(command);
123
+ return true;
124
+ }
125
+ catch (error) {
126
+ if (error.name === "NotFound" || error.$metadata?.httpStatusCode === 404) {
127
+ return false;
126
128
  }
129
+ throw error;
127
130
  }
128
- catch (err) {
131
+ };
132
+ exports.fileExistsOnS3 = fileExistsOnS3;
133
+ const getFileFromS3 = async (path, returnUrl = false) => {
134
+ (0, exports.checkConfig)();
135
+ const url = `https://${exports.config.bucket}.s3.${exports.config.region}.amazonaws.com/${path}`;
136
+ const fileExists = await (0, exports.fileExistsOnS3)(path);
137
+ if (!fileExists) {
129
138
  (0, logs_1.log)(`S3 file not found. ${url}`);
130
139
  return false;
131
140
  }
141
+ else if (returnUrl) {
142
+ return url;
143
+ }
144
+ else {
145
+ const res = await axios_1.default.get(url, {
146
+ responseType: "arraybuffer",
147
+ });
148
+ return res.data;
149
+ }
132
150
  };
133
151
  exports.getFileFromS3 = getFileFromS3;
134
152
  const saveCatalogToS3 = async (catalog) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pim-import",
3
- "version": "5.12.2",
3
+ "version": "5.12.3",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",