@hot-updater/aws 0.20.11 → 0.20.12
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/iac/index.cjs +206 -345
- package/dist/iac/index.js +204 -343
- package/dist/index.cjs +14 -22
- package/dist/index.js +13 -21
- package/dist/lambda/index.cjs +125 -207
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -29,10 +29,10 @@ let __aws_sdk_lib_storage = require("@aws-sdk/lib-storage");
|
|
|
29
29
|
__aws_sdk_lib_storage = __toESM(__aws_sdk_lib_storage);
|
|
30
30
|
let __hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
31
31
|
__hot_updater_plugin_core = __toESM(__hot_updater_plugin_core);
|
|
32
|
-
let path = require("path");
|
|
33
|
-
path = __toESM(path);
|
|
34
32
|
let fs_promises = require("fs/promises");
|
|
35
33
|
fs_promises = __toESM(fs_promises);
|
|
34
|
+
let path = require("path");
|
|
35
|
+
path = __toESM(path);
|
|
36
36
|
|
|
37
37
|
//#region ../../node_modules/.pnpm/mime@4.0.4/node_modules/mime/dist/types/other.js
|
|
38
38
|
const types$1 = {
|
|
@@ -1337,8 +1337,7 @@ var Mime = class {
|
|
|
1337
1337
|
const last = path$2.replace(/^.*[/\\]/, "").toLowerCase();
|
|
1338
1338
|
const ext = last.replace(/^.*\./, "").toLowerCase();
|
|
1339
1339
|
const hasPath = last.length < path$2.length;
|
|
1340
|
-
|
|
1341
|
-
if (!hasDot && hasPath) return null;
|
|
1340
|
+
if (!(ext.length < last.length - 1) && hasPath) return null;
|
|
1342
1341
|
return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
|
|
1343
1342
|
}
|
|
1344
1343
|
getExtension(type) {
|
|
@@ -1407,19 +1406,16 @@ async function loadJsonFromS3(client, bucket, key) {
|
|
|
1407
1406
|
* Converts data to JSON string and uploads to S3.
|
|
1408
1407
|
*/
|
|
1409
1408
|
async function uploadJsonToS3(client, bucket, key, data) {
|
|
1410
|
-
|
|
1411
|
-
const ContentType = src_default.getType(key) ?? "application/json";
|
|
1412
|
-
const upload = new __aws_sdk_lib_storage.Upload({
|
|
1409
|
+
await new __aws_sdk_lib_storage.Upload({
|
|
1413
1410
|
client,
|
|
1414
1411
|
params: {
|
|
1415
1412
|
Bucket: bucket,
|
|
1416
1413
|
Key: key,
|
|
1417
|
-
Body,
|
|
1418
|
-
ContentType,
|
|
1414
|
+
Body: JSON.stringify(data),
|
|
1415
|
+
ContentType: src_default.getType(key) ?? "application/json",
|
|
1419
1416
|
CacheControl: "max-age=31536000"
|
|
1420
1417
|
}
|
|
1421
|
-
});
|
|
1422
|
-
await upload.done();
|
|
1418
|
+
}).done();
|
|
1423
1419
|
}
|
|
1424
1420
|
async function listObjectsInS3(client, bucketName, prefix) {
|
|
1425
1421
|
let continuationToken;
|
|
@@ -1447,7 +1443,7 @@ async function deleteObjectInS3(client, bucketName, key) {
|
|
|
1447
1443
|
*/
|
|
1448
1444
|
async function invalidateCloudFront(client, distributionId, paths) {
|
|
1449
1445
|
if (paths.length === 0) return;
|
|
1450
|
-
const timestamp =
|
|
1446
|
+
const timestamp = Date.now();
|
|
1451
1447
|
await client.send(new __aws_sdk_client_cloudfront.CreateInvalidationCommand({
|
|
1452
1448
|
DistributionId: distributionId,
|
|
1453
1449
|
InvalidationBatch: {
|
|
@@ -1500,15 +1496,13 @@ const s3Storage = (config, hooks) => (_) => {
|
|
|
1500
1496
|
});
|
|
1501
1497
|
const listResponse = await client.send(listCommand);
|
|
1502
1498
|
if (listResponse.Contents && listResponse.Contents.length > 0) {
|
|
1503
|
-
const
|
|
1504
|
-
const deleteParams = {
|
|
1499
|
+
const deleteCommand = new __aws_sdk_client_s3.DeleteObjectsCommand({
|
|
1505
1500
|
Bucket: bucketName,
|
|
1506
1501
|
Delete: {
|
|
1507
|
-
Objects:
|
|
1502
|
+
Objects: listResponse.Contents.map((obj) => ({ Key: obj.Key })),
|
|
1508
1503
|
Quiet: true
|
|
1509
1504
|
}
|
|
1510
|
-
};
|
|
1511
|
-
const deleteCommand = new __aws_sdk_client_s3.DeleteObjectsCommand(deleteParams);
|
|
1505
|
+
});
|
|
1512
1506
|
await client.send(deleteCommand);
|
|
1513
1507
|
return { storageUri: `s3://${bucketName}/${Key}` };
|
|
1514
1508
|
}
|
|
@@ -1517,9 +1511,8 @@ const s3Storage = (config, hooks) => (_) => {
|
|
|
1517
1511
|
async uploadBundle(bundleId, bundlePath) {
|
|
1518
1512
|
const Body = await fs_promises.default.readFile(bundlePath);
|
|
1519
1513
|
const ContentType = src_default.getType(bundlePath) ?? void 0;
|
|
1520
|
-
const
|
|
1521
|
-
const
|
|
1522
|
-
const upload = new __aws_sdk_lib_storage.Upload({
|
|
1514
|
+
const Key = getStorageKey(bundleId, path.default.basename(bundlePath));
|
|
1515
|
+
const response = await new __aws_sdk_lib_storage.Upload({
|
|
1523
1516
|
client,
|
|
1524
1517
|
params: {
|
|
1525
1518
|
ContentType,
|
|
@@ -1528,8 +1521,7 @@ const s3Storage = (config, hooks) => (_) => {
|
|
|
1528
1521
|
Body,
|
|
1529
1522
|
CacheControl: "max-age=31536000"
|
|
1530
1523
|
}
|
|
1531
|
-
});
|
|
1532
|
-
const response = await upload.done();
|
|
1524
|
+
}).done();
|
|
1533
1525
|
if (!response.Bucket || !response.Key) throw new Error("Upload Failed");
|
|
1534
1526
|
hooks?.onStorageUploaded?.();
|
|
1535
1527
|
return { storageUri: `s3://${bucketName}/${Key}` };
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { CloudFrontClient, CreateInvalidationCommand } from "@aws-sdk/client-clo
|
|
|
2
2
|
import { DeleteObjectCommand, DeleteObjectsCommand, GetObjectCommand, ListObjectsV2Command, NoSuchKey, S3Client } from "@aws-sdk/client-s3";
|
|
3
3
|
import { Upload } from "@aws-sdk/lib-storage";
|
|
4
4
|
import { createBlobDatabasePlugin, createStorageKeyBuilder } from "@hot-updater/plugin-core";
|
|
5
|
-
import path from "path";
|
|
6
5
|
import fs from "fs/promises";
|
|
6
|
+
import path from "path";
|
|
7
7
|
|
|
8
8
|
//#region ../../node_modules/.pnpm/mime@4.0.4/node_modules/mime/dist/types/other.js
|
|
9
9
|
const types$1 = {
|
|
@@ -1308,8 +1308,7 @@ var Mime = class {
|
|
|
1308
1308
|
const last = path$1.replace(/^.*[/\\]/, "").toLowerCase();
|
|
1309
1309
|
const ext = last.replace(/^.*\./, "").toLowerCase();
|
|
1310
1310
|
const hasPath = last.length < path$1.length;
|
|
1311
|
-
|
|
1312
|
-
if (!hasDot && hasPath) return null;
|
|
1311
|
+
if (!(ext.length < last.length - 1) && hasPath) return null;
|
|
1313
1312
|
return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
|
|
1314
1313
|
}
|
|
1315
1314
|
getExtension(type) {
|
|
@@ -1378,19 +1377,16 @@ async function loadJsonFromS3(client, bucket, key) {
|
|
|
1378
1377
|
* Converts data to JSON string and uploads to S3.
|
|
1379
1378
|
*/
|
|
1380
1379
|
async function uploadJsonToS3(client, bucket, key, data) {
|
|
1381
|
-
|
|
1382
|
-
const ContentType = src_default.getType(key) ?? "application/json";
|
|
1383
|
-
const upload = new Upload({
|
|
1380
|
+
await new Upload({
|
|
1384
1381
|
client,
|
|
1385
1382
|
params: {
|
|
1386
1383
|
Bucket: bucket,
|
|
1387
1384
|
Key: key,
|
|
1388
|
-
Body,
|
|
1389
|
-
ContentType,
|
|
1385
|
+
Body: JSON.stringify(data),
|
|
1386
|
+
ContentType: src_default.getType(key) ?? "application/json",
|
|
1390
1387
|
CacheControl: "max-age=31536000"
|
|
1391
1388
|
}
|
|
1392
|
-
});
|
|
1393
|
-
await upload.done();
|
|
1389
|
+
}).done();
|
|
1394
1390
|
}
|
|
1395
1391
|
async function listObjectsInS3(client, bucketName, prefix) {
|
|
1396
1392
|
let continuationToken;
|
|
@@ -1418,7 +1414,7 @@ async function deleteObjectInS3(client, bucketName, key) {
|
|
|
1418
1414
|
*/
|
|
1419
1415
|
async function invalidateCloudFront(client, distributionId, paths) {
|
|
1420
1416
|
if (paths.length === 0) return;
|
|
1421
|
-
const timestamp =
|
|
1417
|
+
const timestamp = Date.now();
|
|
1422
1418
|
await client.send(new CreateInvalidationCommand({
|
|
1423
1419
|
DistributionId: distributionId,
|
|
1424
1420
|
InvalidationBatch: {
|
|
@@ -1471,15 +1467,13 @@ const s3Storage = (config, hooks) => (_) => {
|
|
|
1471
1467
|
});
|
|
1472
1468
|
const listResponse = await client.send(listCommand);
|
|
1473
1469
|
if (listResponse.Contents && listResponse.Contents.length > 0) {
|
|
1474
|
-
const
|
|
1475
|
-
const deleteParams = {
|
|
1470
|
+
const deleteCommand = new DeleteObjectsCommand({
|
|
1476
1471
|
Bucket: bucketName,
|
|
1477
1472
|
Delete: {
|
|
1478
|
-
Objects:
|
|
1473
|
+
Objects: listResponse.Contents.map((obj) => ({ Key: obj.Key })),
|
|
1479
1474
|
Quiet: true
|
|
1480
1475
|
}
|
|
1481
|
-
};
|
|
1482
|
-
const deleteCommand = new DeleteObjectsCommand(deleteParams);
|
|
1476
|
+
});
|
|
1483
1477
|
await client.send(deleteCommand);
|
|
1484
1478
|
return { storageUri: `s3://${bucketName}/${Key}` };
|
|
1485
1479
|
}
|
|
@@ -1488,9 +1482,8 @@ const s3Storage = (config, hooks) => (_) => {
|
|
|
1488
1482
|
async uploadBundle(bundleId, bundlePath) {
|
|
1489
1483
|
const Body = await fs.readFile(bundlePath);
|
|
1490
1484
|
const ContentType = src_default.getType(bundlePath) ?? void 0;
|
|
1491
|
-
const
|
|
1492
|
-
const
|
|
1493
|
-
const upload = new Upload({
|
|
1485
|
+
const Key = getStorageKey(bundleId, path.basename(bundlePath));
|
|
1486
|
+
const response = await new Upload({
|
|
1494
1487
|
client,
|
|
1495
1488
|
params: {
|
|
1496
1489
|
ContentType,
|
|
@@ -1499,8 +1492,7 @@ const s3Storage = (config, hooks) => (_) => {
|
|
|
1499
1492
|
Body,
|
|
1500
1493
|
CacheControl: "max-age=31536000"
|
|
1501
1494
|
}
|
|
1502
|
-
});
|
|
1503
|
-
const response = await upload.done();
|
|
1495
|
+
}).done();
|
|
1504
1496
|
if (!response.Bucket || !response.Key) throw new Error("Upload Failed");
|
|
1505
1497
|
hooks?.onStorageUploaded?.();
|
|
1506
1498
|
return { storageUri: `s3://${bucketName}/${Key}` };
|