@hot-updater/storage-s3 1.1.4 → 1.2.0-rc.10

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
@@ -3,6 +3,23 @@ let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
3
3
  let _aws_sdk_lib_storage = require("@aws-sdk/lib-storage");
4
4
  let _aws_sdk_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
5
5
  let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
6
+ //#region src/lazyCredentials.ts
7
+ /**
8
+ * `credentials` as the AWS SDK takes them: access keys with a lazy field
9
+ * become a provider, which the SDK calls once, on its first request.
10
+ */
11
+ const toSdkCredentials = (credentials) => {
12
+ if (credentials === void 0 || typeof credentials === "function") return credentials;
13
+ const { accessKeyId, secretAccessKey, sessionToken, ...rest } = credentials;
14
+ if (typeof accessKeyId !== "function" && typeof secretAccessKey !== "function" && typeof sessionToken !== "function") return credentials;
15
+ return async () => ({
16
+ ...rest,
17
+ accessKeyId: await (0, _hot_updater_plugin_core.resolveLazy)(accessKeyId),
18
+ secretAccessKey: await (0, _hot_updater_plugin_core.resolveLazy)(secretAccessKey),
19
+ ...sessionToken === void 0 ? {} : { sessionToken: await (0, _hot_updater_plugin_core.resolveLazy)(sessionToken) }
20
+ });
21
+ };
22
+ //#endregion
6
23
  //#region src/createS3Storage.ts
7
24
  /** Devices download right after the update check that returns the URL. */
8
25
  const DEFAULT_SIGNED_LIFETIME_SECONDS = 3600;
@@ -21,9 +38,12 @@ const trimSlashes = (value) => value.replace(/^\/+|\/+$/g, "");
21
38
  * URI protocol, and client defaults.
22
39
  */
23
40
  const createS3Storage = ({ name, protocol }, config) => {
24
- const { bucketName, basePath, getDownloadUrl, signedUrlExpiresIn = DEFAULT_SIGNED_LIFETIME_SECONDS, ...clientConfig } = config;
41
+ const { bucketName, basePath, getDownloadUrl, signedUrlExpiresIn = DEFAULT_SIGNED_LIFETIME_SECONDS, credentials, ...clientConfig } = config;
25
42
  if (!Number.isFinite(signedUrlExpiresIn) || signedUrlExpiresIn <= 0 || signedUrlExpiresIn > MAX_SIGNED_LIFETIME_SECONDS) throw new Error(`${name} signedUrlExpiresIn must be between 1 and ${MAX_SIGNED_LIFETIME_SECONDS} seconds (seven days).`);
26
- const client = new _aws_sdk_client_s3.S3Client(clientConfig);
43
+ const client = new _aws_sdk_client_s3.S3Client({
44
+ ...clientConfig,
45
+ credentials: toSdkCredentials(credentials)
46
+ });
27
47
  const normalizedBasePath = trimSlashes(basePath ?? "");
28
48
  const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(normalizedBasePath);
29
49
  const getListPrefix = (prefix = "") => {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,19 @@
1
- import { S3ClientConfig } from "@aws-sdk/client-s3";
2
- import { StorageAdapter, StorageAdapterWith } from "@hot-updater/plugin-core";
1
+ import { S3ClientConfig, S3ClientConfig as S3ClientConfig$1 } from "@aws-sdk/client-s3";
2
+ import { Lazy, StorageAdapter, StorageAdapterWith } from "@hot-updater/plugin-core";
3
+ //#region src/lazyCredentials.d.ts
4
+ type SdkCredentials = S3ClientConfig$1["credentials"];
5
+ /**
6
+ * Access keys whose fields may each be a function that returns them, such
7
+ * as `secret("<name>")` in `hot-updater.config.ts`, called on first use.
8
+ */
9
+ interface LazyS3Credentials {
10
+ readonly accessKeyId: Lazy<string>;
11
+ readonly secretAccessKey: Lazy<string>;
12
+ readonly sessionToken?: Lazy<string>;
13
+ }
14
+ /** The credentials the AWS SDK takes, or access keys with lazy fields. */
15
+ type S3CredentialsOption = SdkCredentials | LazyS3Credentials;
16
+ //#endregion
3
17
  //#region src/createS3Storage.d.ts
4
18
  /** Who the adapter is: its name and the scheme of the URIs it writes. */
5
19
  interface S3StorageIdentity {
@@ -8,7 +22,12 @@ interface S3StorageIdentity {
8
22
  /** The scheme of the storage URIs it writes, such as `s3`. */
9
23
  protocol: string;
10
24
  }
11
- interface S3StorageConfig extends S3ClientConfig {
25
+ interface S3StorageConfig extends Omit<S3ClientConfig, "credentials"> {
26
+ /**
27
+ * The SDK's credentials, or access keys whose fields are lazy, such as
28
+ * `secret("<name>")`, read once, on the first request.
29
+ */
30
+ credentials?: S3CredentialsOption;
12
31
  bucketName: string;
13
32
  /** Base path where bundles will be stored in the bucket. */
14
33
  basePath?: string;
@@ -31,4 +50,4 @@ type S3StorageOperations = "put" | "get" | "getDownloadUrl" | "exists" | "delete
31
50
  */
32
51
  declare const createS3Storage: ({ name, protocol }: S3StorageIdentity, config: S3StorageConfig) => StorageAdapterWith<S3StorageOperations>;
33
52
  //#endregion
34
- export { type S3ClientConfig, S3StorageConfig, S3StorageIdentity, S3StorageOperations, createS3Storage };
53
+ export { type LazyS3Credentials, type S3ClientConfig, type S3CredentialsOption, S3StorageConfig, S3StorageIdentity, S3StorageOperations, createS3Storage };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,19 @@
1
- import { S3ClientConfig } from "@aws-sdk/client-s3";
2
- import { StorageAdapter, StorageAdapterWith } from "@hot-updater/plugin-core";
1
+ import { S3ClientConfig, S3ClientConfig as S3ClientConfig$1 } from "@aws-sdk/client-s3";
2
+ import { Lazy, StorageAdapter, StorageAdapterWith } from "@hot-updater/plugin-core";
3
+ //#region src/lazyCredentials.d.ts
4
+ type SdkCredentials = S3ClientConfig$1["credentials"];
5
+ /**
6
+ * Access keys whose fields may each be a function that returns them, such
7
+ * as `secret("<name>")` in `hot-updater.config.ts`, called on first use.
8
+ */
9
+ interface LazyS3Credentials {
10
+ readonly accessKeyId: Lazy<string>;
11
+ readonly secretAccessKey: Lazy<string>;
12
+ readonly sessionToken?: Lazy<string>;
13
+ }
14
+ /** The credentials the AWS SDK takes, or access keys with lazy fields. */
15
+ type S3CredentialsOption = SdkCredentials | LazyS3Credentials;
16
+ //#endregion
3
17
  //#region src/createS3Storage.d.ts
4
18
  /** Who the adapter is: its name and the scheme of the URIs it writes. */
5
19
  interface S3StorageIdentity {
@@ -8,7 +22,12 @@ interface S3StorageIdentity {
8
22
  /** The scheme of the storage URIs it writes, such as `s3`. */
9
23
  protocol: string;
10
24
  }
11
- interface S3StorageConfig extends S3ClientConfig {
25
+ interface S3StorageConfig extends Omit<S3ClientConfig, "credentials"> {
26
+ /**
27
+ * The SDK's credentials, or access keys whose fields are lazy, such as
28
+ * `secret("<name>")`, read once, on the first request.
29
+ */
30
+ credentials?: S3CredentialsOption;
12
31
  bucketName: string;
13
32
  /** Base path where bundles will be stored in the bucket. */
14
33
  basePath?: string;
@@ -31,4 +50,4 @@ type S3StorageOperations = "put" | "get" | "getDownloadUrl" | "exists" | "delete
31
50
  */
32
51
  declare const createS3Storage: ({ name, protocol }: S3StorageIdentity, config: S3StorageConfig) => StorageAdapterWith<S3StorageOperations>;
33
52
  //#endregion
34
- export { type S3ClientConfig, S3StorageConfig, S3StorageIdentity, S3StorageOperations, createS3Storage };
53
+ export { type LazyS3Credentials, type S3ClientConfig, type S3CredentialsOption, S3StorageConfig, S3StorageIdentity, S3StorageOperations, createS3Storage };
package/dist/index.mjs CHANGED
@@ -1,7 +1,24 @@
1
1
  import { DeleteObjectCommand, DeleteObjectsCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, S3Client } from "@aws-sdk/client-s3";
2
2
  import { Upload } from "@aws-sdk/lib-storage";
3
3
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
4
- import { createStorageAdapter, createStorageKeyBuilder, createStorageUri, parseStorageUri } from "@hot-updater/plugin-core";
4
+ import { createStorageAdapter, createStorageKeyBuilder, createStorageUri, parseStorageUri, resolveLazy } from "@hot-updater/plugin-core";
5
+ //#region src/lazyCredentials.ts
6
+ /**
7
+ * `credentials` as the AWS SDK takes them: access keys with a lazy field
8
+ * become a provider, which the SDK calls once, on its first request.
9
+ */
10
+ const toSdkCredentials = (credentials) => {
11
+ if (credentials === void 0 || typeof credentials === "function") return credentials;
12
+ const { accessKeyId, secretAccessKey, sessionToken, ...rest } = credentials;
13
+ if (typeof accessKeyId !== "function" && typeof secretAccessKey !== "function" && typeof sessionToken !== "function") return credentials;
14
+ return async () => ({
15
+ ...rest,
16
+ accessKeyId: await resolveLazy(accessKeyId),
17
+ secretAccessKey: await resolveLazy(secretAccessKey),
18
+ ...sessionToken === void 0 ? {} : { sessionToken: await resolveLazy(sessionToken) }
19
+ });
20
+ };
21
+ //#endregion
5
22
  //#region src/createS3Storage.ts
6
23
  /** Devices download right after the update check that returns the URL. */
7
24
  const DEFAULT_SIGNED_LIFETIME_SECONDS = 3600;
@@ -20,9 +37,12 @@ const trimSlashes = (value) => value.replace(/^\/+|\/+$/g, "");
20
37
  * URI protocol, and client defaults.
21
38
  */
22
39
  const createS3Storage = ({ name, protocol }, config) => {
23
- const { bucketName, basePath, getDownloadUrl, signedUrlExpiresIn = DEFAULT_SIGNED_LIFETIME_SECONDS, ...clientConfig } = config;
40
+ const { bucketName, basePath, getDownloadUrl, signedUrlExpiresIn = DEFAULT_SIGNED_LIFETIME_SECONDS, credentials, ...clientConfig } = config;
24
41
  if (!Number.isFinite(signedUrlExpiresIn) || signedUrlExpiresIn <= 0 || signedUrlExpiresIn > MAX_SIGNED_LIFETIME_SECONDS) throw new Error(`${name} signedUrlExpiresIn must be between 1 and ${MAX_SIGNED_LIFETIME_SECONDS} seconds (seven days).`);
25
- const client = new S3Client(clientConfig);
42
+ const client = new S3Client({
43
+ ...clientConfig,
44
+ credentials: toSdkCredentials(credentials)
45
+ });
26
46
  const normalizedBasePath = trimSlashes(basePath ?? "");
27
47
  const getStorageKey = createStorageKeyBuilder(normalizedBasePath);
28
48
  const getListPrefix = (prefix = "") => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/storage-s3",
3
3
  "type": "module",
4
- "version": "1.1.4",
4
+ "version": "1.2.0-rc.10",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
@@ -35,12 +35,12 @@
35
35
  "@aws-sdk/client-s3": "3.1066.0",
36
36
  "@aws-sdk/lib-storage": "3.1066.0",
37
37
  "@aws-sdk/s3-request-presigner": "3.1066.0",
38
- "@hot-updater/plugin-core": "1.1.4"
38
+ "@hot-updater/plugin-core": "1.2.0-rc.10"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^20",
42
42
  "vitest": "4.1.4",
43
- "@hot-updater/test-utils": "1.1.4"
43
+ "@hot-updater/test-utils": "1.2.0-rc.10"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsdown",