@hot-updater/aws 0.21.11 → 0.21.13

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/index.cjs CHANGED
@@ -1457,97 +1457,97 @@ async function invalidateCloudFront(client, distributionId, paths) {
1457
1457
  }
1458
1458
  }));
1459
1459
  }
1460
- const s3Database = (config, hooks) => {
1461
- const { bucketName, cloudfrontDistributionId, apiBasePath = "/api/check-update",...s3Config } = config;
1462
- return (0, __hot_updater_plugin_core.createBlobDatabasePlugin)({
1463
- name: "s3Database",
1464
- apiBasePath,
1465
- getContext: () => ({
1466
- client: new __aws_sdk_client_s3.S3Client(s3Config),
1467
- cloudfrontClient: cloudfrontDistributionId ? new __aws_sdk_client_cloudfront.CloudFrontClient({
1468
- credentials: s3Config.credentials,
1469
- region: s3Config.region
1470
- }) : void 0
1471
- }),
1472
- listObjects: (context, prefix) => listObjectsInS3(context.client, bucketName, prefix),
1473
- loadObject: (context, key) => loadJsonFromS3(context.client, bucketName, key),
1474
- uploadObject: (context, key, data) => uploadJsonToS3(context.client, bucketName, key, data),
1475
- deleteObject: (context, key) => deleteObjectInS3(context.client, bucketName, key),
1476
- invalidatePaths: (context, pathsToInvalidate) => {
1477
- if (context.cloudfrontClient && cloudfrontDistributionId && pathsToInvalidate.length > 0) return invalidateCloudFront(context.cloudfrontClient, cloudfrontDistributionId, pathsToInvalidate);
1478
- return Promise.resolve();
1479
- },
1480
- hooks
1481
- });
1482
- };
1460
+ const s3Database = (0, __hot_updater_plugin_core.createBlobDatabasePlugin)({
1461
+ name: "s3Database",
1462
+ factory: (config) => {
1463
+ const { bucketName, cloudfrontDistributionId, apiBasePath = "/api/check-update",...s3Config } = config;
1464
+ const client = new __aws_sdk_client_s3.S3Client(s3Config);
1465
+ const cloudfrontClient = cloudfrontDistributionId ? new __aws_sdk_client_cloudfront.CloudFrontClient({
1466
+ credentials: s3Config.credentials,
1467
+ region: s3Config.region
1468
+ }) : void 0;
1469
+ return {
1470
+ apiBasePath,
1471
+ listObjects: (prefix) => listObjectsInS3(client, bucketName, prefix),
1472
+ loadObject: (key) => loadJsonFromS3(client, bucketName, key),
1473
+ uploadObject: (key, data) => uploadJsonToS3(client, bucketName, key, data),
1474
+ deleteObject: (key) => deleteObjectInS3(client, bucketName, key),
1475
+ invalidatePaths: (pathsToInvalidate) => {
1476
+ if (cloudfrontClient && cloudfrontDistributionId && pathsToInvalidate.length > 0) return invalidateCloudFront(cloudfrontClient, cloudfrontDistributionId, pathsToInvalidate);
1477
+ return Promise.resolve();
1478
+ }
1479
+ };
1480
+ }
1481
+ });
1483
1482
 
1484
1483
  //#endregion
1485
1484
  //#region src/s3Storage.ts
1486
- const s3Storage = (config, hooks) => () => {
1487
- const { bucketName,...s3Config } = config;
1488
- const client = new __aws_sdk_client_s3.S3Client(s3Config);
1489
- const getStorageKey = (0, __hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
1490
- return {
1491
- name: "s3Storage",
1492
- supportedProtocol: "s3",
1493
- async delete(storageUri) {
1494
- const { bucket, key } = (0, __hot_updater_plugin_core.parseStorageUri)(storageUri, "s3");
1495
- if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
1496
- const listCommand = new __aws_sdk_client_s3.ListObjectsV2Command({
1497
- Bucket: bucketName,
1498
- Prefix: key
1499
- });
1500
- const listResponse = await client.send(listCommand);
1501
- if (listResponse.Contents && listResponse.Contents.length > 0) {
1502
- const deleteCommand = new __aws_sdk_client_s3.DeleteObjectsCommand({
1485
+ const s3Storage = (0, __hot_updater_plugin_core.createStoragePlugin)({
1486
+ name: "s3Storage",
1487
+ supportedProtocol: "s3",
1488
+ factory: (config) => {
1489
+ const { bucketName,...s3Config } = config;
1490
+ const client = new __aws_sdk_client_s3.S3Client(s3Config);
1491
+ const getStorageKey = (0, __hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
1492
+ return {
1493
+ async delete(storageUri) {
1494
+ const { bucket, key } = (0, __hot_updater_plugin_core.parseStorageUri)(storageUri, "s3");
1495
+ if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
1496
+ const listCommand = new __aws_sdk_client_s3.ListObjectsV2Command({
1503
1497
  Bucket: bucketName,
1504
- Delete: {
1505
- Objects: listResponse.Contents.map((obj) => ({ Key: obj.Key })),
1506
- Quiet: true
1507
- }
1498
+ Prefix: key
1508
1499
  });
1509
- await client.send(deleteCommand);
1510
- return;
1511
- }
1512
- throw new Error("Bundle Not Found");
1513
- },
1514
- async upload(key, filePath) {
1515
- const Body = await fs_promises.default.readFile(filePath);
1516
- const ContentType = (0, __hot_updater_plugin_core.getContentType)(filePath);
1517
- const Key = getStorageKey(key, path.default.basename(filePath));
1518
- const response = await new __aws_sdk_lib_storage.Upload({
1519
- client,
1520
- params: {
1521
- ContentType,
1522
- Bucket: bucketName,
1523
- Key,
1524
- Body,
1525
- CacheControl: "max-age=31536000"
1500
+ const listResponse = await client.send(listCommand);
1501
+ if (listResponse.Contents && listResponse.Contents.length > 0) {
1502
+ const deleteCommand = new __aws_sdk_client_s3.DeleteObjectsCommand({
1503
+ Bucket: bucketName,
1504
+ Delete: {
1505
+ Objects: listResponse.Contents.map((obj) => ({ Key: obj.Key })),
1506
+ Quiet: true
1507
+ }
1508
+ });
1509
+ await client.send(deleteCommand);
1510
+ return;
1511
+ }
1512
+ throw new Error("Bundle Not Found");
1513
+ },
1514
+ async upload(key, filePath) {
1515
+ const Body = await fs_promises.default.readFile(filePath);
1516
+ const ContentType = (0, __hot_updater_plugin_core.getContentType)(filePath);
1517
+ const Key = getStorageKey(key, path.default.basename(filePath));
1518
+ const response = await new __aws_sdk_lib_storage.Upload({
1519
+ client,
1520
+ params: {
1521
+ ContentType,
1522
+ Bucket: bucketName,
1523
+ Key,
1524
+ Body,
1525
+ CacheControl: "max-age=31536000"
1526
+ }
1527
+ }).done();
1528
+ if (!response.Bucket || !response.Key) throw new Error("Upload Failed");
1529
+ return { storageUri: `s3://${bucketName}/${Key}` };
1530
+ },
1531
+ async getDownloadUrl(storageUri) {
1532
+ const u = new URL(storageUri);
1533
+ if (u.protocol.replace(":", "") !== "s3") throw new Error("Invalid S3 storage URI protocol");
1534
+ const bucket = u.host;
1535
+ const key = u.pathname.slice(1);
1536
+ if (!bucket || !key) throw new Error("Invalid S3 storage URI: missing bucket or key");
1537
+ try {
1538
+ const signedUrl = await (0, __aws_sdk_s3_request_presigner.getSignedUrl)(client, new __aws_sdk_client_s3.GetObjectCommand({
1539
+ Bucket: bucket,
1540
+ Key: key
1541
+ }), { expiresIn: 3600 });
1542
+ if (!signedUrl) throw new Error("Failed to presign S3 URL");
1543
+ return { fileUrl: signedUrl };
1544
+ } catch (e) {
1545
+ throw new Error(e instanceof Error ? `Failed to presign S3 URL: ${e.message}` : "Failed to presign S3 URL");
1526
1546
  }
1527
- }).done();
1528
- if (!response.Bucket || !response.Key) throw new Error("Upload Failed");
1529
- hooks?.onStorageUploaded?.();
1530
- return { storageUri: `s3://${bucketName}/${Key}` };
1531
- },
1532
- async getDownloadUrl(storageUri) {
1533
- const u = new URL(storageUri);
1534
- if (u.protocol.replace(":", "") !== "s3") throw new Error("Invalid S3 storage URI protocol");
1535
- const bucket = u.host;
1536
- const key = u.pathname.slice(1);
1537
- if (!bucket || !key) throw new Error("Invalid S3 storage URI: missing bucket or key");
1538
- try {
1539
- const signedUrl = await (0, __aws_sdk_s3_request_presigner.getSignedUrl)(client, new __aws_sdk_client_s3.GetObjectCommand({
1540
- Bucket: bucket,
1541
- Key: key
1542
- }), { expiresIn: 3600 });
1543
- if (!signedUrl) throw new Error("Failed to presign S3 URL");
1544
- return { fileUrl: signedUrl };
1545
- } catch (e) {
1546
- throw new Error(e instanceof Error ? `Failed to presign S3 URL: ${e.message}` : "Failed to presign S3 URL");
1547
1547
  }
1548
- }
1549
- };
1550
- };
1548
+ };
1549
+ }
1550
+ });
1551
1551
 
1552
1552
  //#endregion
1553
1553
  exports.s3Database = s3Database;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
2
- import { DatabasePluginHooks, StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
3
2
  import { S3ClientConfig } from "@aws-sdk/client-s3";
4
3
 
5
4
  //#region src/s3Database.d.ts
@@ -15,7 +14,7 @@ interface S3DatabaseConfig extends S3ClientConfig {
15
14
  cloudfrontDistributionId?: string;
16
15
  apiBasePath?: string;
17
16
  }
18
- declare const s3Database: (config: S3DatabaseConfig, hooks?: DatabasePluginHooks) => () => _hot_updater_plugin_core0.DatabasePlugin;
17
+ declare const s3Database: (config: S3DatabaseConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => _hot_updater_plugin_core0.DatabasePlugin;
19
18
  //#endregion
20
19
  //#region src/s3Storage.d.ts
21
20
  interface S3StorageConfig extends S3ClientConfig {
@@ -25,6 +24,6 @@ interface S3StorageConfig extends S3ClientConfig {
25
24
  */
26
25
  basePath?: string;
27
26
  }
28
- declare const s3Storage: (config: S3StorageConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
27
+ declare const s3Storage: (config: S3StorageConfig, hooks?: _hot_updater_plugin_core0.StoragePluginHooks) => () => _hot_updater_plugin_core0.StoragePlugin;
29
28
  //#endregion
30
29
  export { S3DatabaseConfig, S3StorageConfig, s3Database, s3Storage };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { S3ClientConfig } from "@aws-sdk/client-s3";
2
- import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
3
- import { DatabasePluginHooks, StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
2
+ import * as _hot_updater_plugin_core1 from "@hot-updater/plugin-core";
4
3
 
5
4
  //#region src/s3Database.d.ts
6
5
  interface S3DatabaseConfig extends S3ClientConfig {
@@ -15,7 +14,7 @@ interface S3DatabaseConfig extends S3ClientConfig {
15
14
  cloudfrontDistributionId?: string;
16
15
  apiBasePath?: string;
17
16
  }
18
- declare const s3Database: (config: S3DatabaseConfig, hooks?: DatabasePluginHooks) => () => _hot_updater_plugin_core0.DatabasePlugin;
17
+ declare const s3Database: (config: S3DatabaseConfig, hooks?: _hot_updater_plugin_core1.DatabasePluginHooks) => _hot_updater_plugin_core1.DatabasePlugin;
19
18
  //#endregion
20
19
  //#region src/s3Storage.d.ts
21
20
  interface S3StorageConfig extends S3ClientConfig {
@@ -25,6 +24,6 @@ interface S3StorageConfig extends S3ClientConfig {
25
24
  */
26
25
  basePath?: string;
27
26
  }
28
- declare const s3Storage: (config: S3StorageConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
27
+ declare const s3Storage: (config: S3StorageConfig, hooks?: _hot_updater_plugin_core1.StoragePluginHooks) => () => _hot_updater_plugin_core1.StoragePlugin;
29
28
  //#endregion
30
29
  export { S3DatabaseConfig, S3StorageConfig, s3Database, s3Storage };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CloudFrontClient, CreateInvalidationCommand } from "@aws-sdk/client-cloudfront";
2
2
  import { DeleteObjectCommand, DeleteObjectsCommand, GetObjectCommand, ListObjectsV2Command, NoSuchKey, S3Client } from "@aws-sdk/client-s3";
3
3
  import { Upload } from "@aws-sdk/lib-storage";
4
- import { createBlobDatabasePlugin, createStorageKeyBuilder, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
4
+ import { createBlobDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
5
5
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
6
6
  import fs from "fs/promises";
7
7
  import path from "path";
@@ -1427,97 +1427,97 @@ async function invalidateCloudFront(client, distributionId, paths) {
1427
1427
  }
1428
1428
  }));
1429
1429
  }
1430
- const s3Database = (config, hooks) => {
1431
- const { bucketName, cloudfrontDistributionId, apiBasePath = "/api/check-update",...s3Config } = config;
1432
- return createBlobDatabasePlugin({
1433
- name: "s3Database",
1434
- apiBasePath,
1435
- getContext: () => ({
1436
- client: new S3Client(s3Config),
1437
- cloudfrontClient: cloudfrontDistributionId ? new CloudFrontClient({
1438
- credentials: s3Config.credentials,
1439
- region: s3Config.region
1440
- }) : void 0
1441
- }),
1442
- listObjects: (context, prefix) => listObjectsInS3(context.client, bucketName, prefix),
1443
- loadObject: (context, key) => loadJsonFromS3(context.client, bucketName, key),
1444
- uploadObject: (context, key, data) => uploadJsonToS3(context.client, bucketName, key, data),
1445
- deleteObject: (context, key) => deleteObjectInS3(context.client, bucketName, key),
1446
- invalidatePaths: (context, pathsToInvalidate) => {
1447
- if (context.cloudfrontClient && cloudfrontDistributionId && pathsToInvalidate.length > 0) return invalidateCloudFront(context.cloudfrontClient, cloudfrontDistributionId, pathsToInvalidate);
1448
- return Promise.resolve();
1449
- },
1450
- hooks
1451
- });
1452
- };
1430
+ const s3Database = createBlobDatabasePlugin({
1431
+ name: "s3Database",
1432
+ factory: (config) => {
1433
+ const { bucketName, cloudfrontDistributionId, apiBasePath = "/api/check-update",...s3Config } = config;
1434
+ const client = new S3Client(s3Config);
1435
+ const cloudfrontClient = cloudfrontDistributionId ? new CloudFrontClient({
1436
+ credentials: s3Config.credentials,
1437
+ region: s3Config.region
1438
+ }) : void 0;
1439
+ return {
1440
+ apiBasePath,
1441
+ listObjects: (prefix) => listObjectsInS3(client, bucketName, prefix),
1442
+ loadObject: (key) => loadJsonFromS3(client, bucketName, key),
1443
+ uploadObject: (key, data) => uploadJsonToS3(client, bucketName, key, data),
1444
+ deleteObject: (key) => deleteObjectInS3(client, bucketName, key),
1445
+ invalidatePaths: (pathsToInvalidate) => {
1446
+ if (cloudfrontClient && cloudfrontDistributionId && pathsToInvalidate.length > 0) return invalidateCloudFront(cloudfrontClient, cloudfrontDistributionId, pathsToInvalidate);
1447
+ return Promise.resolve();
1448
+ }
1449
+ };
1450
+ }
1451
+ });
1453
1452
 
1454
1453
  //#endregion
1455
1454
  //#region src/s3Storage.ts
1456
- const s3Storage = (config, hooks) => () => {
1457
- const { bucketName,...s3Config } = config;
1458
- const client = new S3Client(s3Config);
1459
- const getStorageKey = createStorageKeyBuilder(config.basePath);
1460
- return {
1461
- name: "s3Storage",
1462
- supportedProtocol: "s3",
1463
- async delete(storageUri) {
1464
- const { bucket, key } = parseStorageUri(storageUri, "s3");
1465
- if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
1466
- const listCommand = new ListObjectsV2Command({
1467
- Bucket: bucketName,
1468
- Prefix: key
1469
- });
1470
- const listResponse = await client.send(listCommand);
1471
- if (listResponse.Contents && listResponse.Contents.length > 0) {
1472
- const deleteCommand = new DeleteObjectsCommand({
1455
+ const s3Storage = createStoragePlugin({
1456
+ name: "s3Storage",
1457
+ supportedProtocol: "s3",
1458
+ factory: (config) => {
1459
+ const { bucketName,...s3Config } = config;
1460
+ const client = new S3Client(s3Config);
1461
+ const getStorageKey = createStorageKeyBuilder(config.basePath);
1462
+ return {
1463
+ async delete(storageUri) {
1464
+ const { bucket, key } = parseStorageUri(storageUri, "s3");
1465
+ if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
1466
+ const listCommand = new ListObjectsV2Command({
1473
1467
  Bucket: bucketName,
1474
- Delete: {
1475
- Objects: listResponse.Contents.map((obj) => ({ Key: obj.Key })),
1476
- Quiet: true
1477
- }
1468
+ Prefix: key
1478
1469
  });
1479
- await client.send(deleteCommand);
1480
- return;
1481
- }
1482
- throw new Error("Bundle Not Found");
1483
- },
1484
- async upload(key, filePath) {
1485
- const Body = await fs.readFile(filePath);
1486
- const ContentType = getContentType(filePath);
1487
- const Key = getStorageKey(key, path.basename(filePath));
1488
- const response = await new Upload({
1489
- client,
1490
- params: {
1491
- ContentType,
1492
- Bucket: bucketName,
1493
- Key,
1494
- Body,
1495
- CacheControl: "max-age=31536000"
1470
+ const listResponse = await client.send(listCommand);
1471
+ if (listResponse.Contents && listResponse.Contents.length > 0) {
1472
+ const deleteCommand = new DeleteObjectsCommand({
1473
+ Bucket: bucketName,
1474
+ Delete: {
1475
+ Objects: listResponse.Contents.map((obj) => ({ Key: obj.Key })),
1476
+ Quiet: true
1477
+ }
1478
+ });
1479
+ await client.send(deleteCommand);
1480
+ return;
1481
+ }
1482
+ throw new Error("Bundle Not Found");
1483
+ },
1484
+ async upload(key, filePath) {
1485
+ const Body = await fs.readFile(filePath);
1486
+ const ContentType = getContentType(filePath);
1487
+ const Key = getStorageKey(key, path.basename(filePath));
1488
+ const response = await new Upload({
1489
+ client,
1490
+ params: {
1491
+ ContentType,
1492
+ Bucket: bucketName,
1493
+ Key,
1494
+ Body,
1495
+ CacheControl: "max-age=31536000"
1496
+ }
1497
+ }).done();
1498
+ if (!response.Bucket || !response.Key) throw new Error("Upload Failed");
1499
+ return { storageUri: `s3://${bucketName}/${Key}` };
1500
+ },
1501
+ async getDownloadUrl(storageUri) {
1502
+ const u = new URL(storageUri);
1503
+ if (u.protocol.replace(":", "") !== "s3") throw new Error("Invalid S3 storage URI protocol");
1504
+ const bucket = u.host;
1505
+ const key = u.pathname.slice(1);
1506
+ if (!bucket || !key) throw new Error("Invalid S3 storage URI: missing bucket or key");
1507
+ try {
1508
+ const signedUrl = await getSignedUrl(client, new GetObjectCommand({
1509
+ Bucket: bucket,
1510
+ Key: key
1511
+ }), { expiresIn: 3600 });
1512
+ if (!signedUrl) throw new Error("Failed to presign S3 URL");
1513
+ return { fileUrl: signedUrl };
1514
+ } catch (e) {
1515
+ throw new Error(e instanceof Error ? `Failed to presign S3 URL: ${e.message}` : "Failed to presign S3 URL");
1496
1516
  }
1497
- }).done();
1498
- if (!response.Bucket || !response.Key) throw new Error("Upload Failed");
1499
- hooks?.onStorageUploaded?.();
1500
- return { storageUri: `s3://${bucketName}/${Key}` };
1501
- },
1502
- async getDownloadUrl(storageUri) {
1503
- const u = new URL(storageUri);
1504
- if (u.protocol.replace(":", "") !== "s3") throw new Error("Invalid S3 storage URI protocol");
1505
- const bucket = u.host;
1506
- const key = u.pathname.slice(1);
1507
- if (!bucket || !key) throw new Error("Invalid S3 storage URI: missing bucket or key");
1508
- try {
1509
- const signedUrl = await getSignedUrl(client, new GetObjectCommand({
1510
- Bucket: bucket,
1511
- Key: key
1512
- }), { expiresIn: 3600 });
1513
- if (!signedUrl) throw new Error("Failed to presign S3 URL");
1514
- return { fileUrl: signedUrl };
1515
- } catch (e) {
1516
- throw new Error(e instanceof Error ? `Failed to presign S3 URL: ${e.message}` : "Failed to presign S3 URL");
1517
1517
  }
1518
- }
1519
- };
1520
- };
1518
+ };
1519
+ }
1520
+ });
1521
1521
 
1522
1522
  //#endregion
1523
1523
  export { s3Database, s3Storage };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/aws",
3
3
  "type": "module",
4
- "version": "0.21.11",
4
+ "version": "0.21.13",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -44,9 +44,9 @@
44
44
  "execa": "9.5.2",
45
45
  "hono": "^4.6.3",
46
46
  "mime": "^4.0.4",
47
- "@hot-updater/core": "0.21.11",
48
- "@hot-updater/js": "0.21.11",
49
- "@hot-updater/test-utils": "0.21.11"
47
+ "@hot-updater/js": "0.21.13",
48
+ "@hot-updater/test-utils": "0.21.13",
49
+ "@hot-updater/core": "0.21.13"
50
50
  },
51
51
  "dependencies": {
52
52
  "@aws-sdk/client-cloudfront": "3.772.0",
@@ -59,8 +59,8 @@
59
59
  "@aws-sdk/credential-providers": "3.772.0",
60
60
  "@aws-sdk/lib-storage": "3.772.0",
61
61
  "aws-lambda": "1.0.7",
62
- "@hot-updater/cli-tools": "0.21.11",
63
- "@hot-updater/plugin-core": "0.21.11"
62
+ "@hot-updater/cli-tools": "0.21.13",
63
+ "@hot-updater/plugin-core": "0.21.13"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "tsdown",