pim-import 5.12.1 → 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 +1 -0
- package/dist/libs/s3.js +29 -10
- package/package.json +1 -1
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,22 +112,41 @@ const upload = async (url, fileName = "", path = "", metaData = {}) => {
|
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
exports.upload = upload;
|
|
115
|
-
const
|
|
115
|
+
const fileExistsOnS3 = async (path) => {
|
|
116
116
|
(0, exports.checkConfig)();
|
|
117
|
-
const
|
|
117
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
118
|
+
Bucket: exports.config.bucket,
|
|
119
|
+
Key: path,
|
|
120
|
+
});
|
|
118
121
|
try {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
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;
|
|
125
128
|
}
|
|
129
|
+
throw error;
|
|
126
130
|
}
|
|
127
|
-
|
|
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) {
|
|
128
138
|
(0, logs_1.log)(`S3 file not found. ${url}`);
|
|
129
139
|
return false;
|
|
130
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
|
+
}
|
|
131
150
|
};
|
|
132
151
|
exports.getFileFromS3 = getFileFromS3;
|
|
133
152
|
const saveCatalogToS3 = async (catalog) => {
|