@hot-updater/aws 1.2.0-rc.2 → 1.2.0-rc.21
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 +82 -163
- package/dist/index.d.cts +25 -8
- package/dist/index.d.mts +25 -8
- package/dist/index.mjs +83 -164
- package/dist/init/index.cjs +66 -22
- package/dist/init/index.d.cts +3 -2
- package/dist/init/index.d.mts +3 -2
- package/dist/init/index.mjs +67 -23
- package/dist/lambda/index.cjs +292 -202
- package/package.json +8 -7
package/dist/init/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import { finished } from "node:stream/promises";
|
|
|
18
18
|
import { Duplex, PassThrough, Readable, Transform, Writable, getDefaultHighWaterMark } from "node:stream";
|
|
19
19
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
20
20
|
import { CreateTableCommand, DescribeTableCommand, DescribeTimeToLiveCommand, DynamoDB, DynamoDBClient, UpdateTimeToLiveCommand, waitUntilTableExists } from "@aws-sdk/client-dynamodb";
|
|
21
|
-
import { SETTINGS_TABLE, aggregateBatchingTables, createEngineDatabase, createKvAdapter, encodeKvKey, migrateCoreSchema, toolingTargetOf } from "@hot-updater/plugin-core";
|
|
21
|
+
import { SETTINGS_TABLE, aggregateBatchingTables, createEngineDatabase, createKvAdapter, encodeKvKey, migrateCoreSchema, resolveLazy, toolingTargetOf } from "@hot-updater/plugin-core";
|
|
22
22
|
import { CloudFront, CloudFrontClient, CreateInvalidationCommand, GetInvalidationCommand } from "@aws-sdk/client-cloudfront";
|
|
23
23
|
import { BatchGetCommand, BatchWriteCommand, DynamoDBDocumentClient, QueryCommand, TransactWriteCommand } from "@aws-sdk/lib-dynamodb";
|
|
24
24
|
import { fromIni, fromNodeProviderChain, fromSSO } from "@aws-sdk/credential-providers";
|
|
@@ -6574,10 +6574,30 @@ async apply() {
|
|
|
6574
6574
|
};
|
|
6575
6575
|
};
|
|
6576
6576
|
//#endregion
|
|
6577
|
+
//#region src/lazyCredentials.ts
|
|
6578
|
+
/**
|
|
6579
|
+
* `credentials` as the AWS SDK takes them: access keys with a lazy field
|
|
6580
|
+
* become a provider, which the SDK calls once, on its first request.
|
|
6581
|
+
*/
|
|
6582
|
+
const toSdkCredentials = (credentials) => {
|
|
6583
|
+
if (credentials === void 0 || typeof credentials === "function") return credentials;
|
|
6584
|
+
const { accessKeyId, secretAccessKey, sessionToken, ...rest } = credentials;
|
|
6585
|
+
if (typeof accessKeyId !== "function" && typeof secretAccessKey !== "function" && typeof sessionToken !== "function") return credentials;
|
|
6586
|
+
return async () => ({
|
|
6587
|
+
...rest,
|
|
6588
|
+
accessKeyId: await resolveLazy(accessKeyId),
|
|
6589
|
+
secretAccessKey: await resolveLazy(secretAccessKey),
|
|
6590
|
+
...sessionToken === void 0 ? {} : { sessionToken: await resolveLazy(sessionToken) }
|
|
6591
|
+
});
|
|
6592
|
+
};
|
|
6593
|
+
//#endregion
|
|
6577
6594
|
//#region src/dynamoDB.ts
|
|
6578
6595
|
/** The DynamoDB client ignores the CloudFront and batching settings. */
|
|
6579
|
-
const adapterOf = ({ tableName, ...clientConfig }) => {
|
|
6580
|
-
const client = new DynamoDBClient(
|
|
6596
|
+
const adapterOf = ({ tableName, credentials, ...clientConfig }) => {
|
|
6597
|
+
const client = new DynamoDBClient({
|
|
6598
|
+
...clientConfig,
|
|
6599
|
+
credentials: toSdkCredentials(credentials)
|
|
6600
|
+
});
|
|
6581
6601
|
const store = createDynamoDBStore({
|
|
6582
6602
|
client,
|
|
6583
6603
|
tableName
|
|
@@ -6612,7 +6632,10 @@ const marked = (target) => ({ [DATABASE_TARGET]: target });
|
|
|
6612
6632
|
*/
|
|
6613
6633
|
const dynamoDB = (config) => {
|
|
6614
6634
|
const { client, adapter } = adapterOf(config);
|
|
6615
|
-
const cloudFront = createUpdateRouteInvalidation(
|
|
6635
|
+
const cloudFront = createUpdateRouteInvalidation({
|
|
6636
|
+
...config,
|
|
6637
|
+
credentials: toSdkCredentials(config.credentials)
|
|
6638
|
+
});
|
|
6616
6639
|
return {
|
|
6617
6640
|
...createEngineDatabase({
|
|
6618
6641
|
name: "dynamoDB",
|
|
@@ -6769,7 +6792,8 @@ const initProvider = {
|
|
|
6769
6792
|
help: "Existing CloudFront distribution ID",
|
|
6770
6793
|
optional: true
|
|
6771
6794
|
}
|
|
6772
|
-
}
|
|
6795
|
+
},
|
|
6796
|
+
secrets: ["HOT_UPDATER_S3_ACCESS_KEY_ID", "HOT_UPDATER_S3_SECRET_ACCESS_KEY"]
|
|
6773
6797
|
};
|
|
6774
6798
|
//#endregion
|
|
6775
6799
|
//#region iac/regionLocationMap.ts
|
|
@@ -8411,7 +8435,17 @@ var SSMKeyPairManager = class {
|
|
|
8411
8435
|
};
|
|
8412
8436
|
//#endregion
|
|
8413
8437
|
//#region iac/templates.ts
|
|
8414
|
-
|
|
8438
|
+
/**
|
|
8439
|
+
* The config init writes. With the `resources` init set up, it names them,
|
|
8440
|
+
* and an account's access keys are read with `secret()`, from the
|
|
8441
|
+
* environment and `.env.hotupdater`, then the config's `secrets` adapter.
|
|
8442
|
+
* Without them, as the agent scaffold writes it before the agent creates the
|
|
8443
|
+
* resources, it reads their names from the environment, where the agent
|
|
8444
|
+
* records them. A profile or SSO sign-in is each person's own.
|
|
8445
|
+
*/
|
|
8446
|
+
const getConfigScaffold = (build, authMode, resources) => {
|
|
8447
|
+
const value = (envKey, resolved) => resolved === void 0 ? `process.env.${envKey}!` : JSON.stringify(resolved);
|
|
8448
|
+
const region = value("HOT_UPDATER_S3_REGION", resources?.region);
|
|
8415
8449
|
const storageConfig = {
|
|
8416
8450
|
imports: [{
|
|
8417
8451
|
pkg: "@hot-updater/aws",
|
|
@@ -8419,7 +8453,7 @@ const getConfigScaffold = (build, authMode) => {
|
|
|
8419
8453
|
}],
|
|
8420
8454
|
configString: `s3Storage({
|
|
8421
8455
|
...awsOptions,
|
|
8422
|
-
bucketName:
|
|
8456
|
+
bucketName: ${value("HOT_UPDATER_S3_BUCKET_NAME", resources?.bucketName)},
|
|
8423
8457
|
})`
|
|
8424
8458
|
};
|
|
8425
8459
|
const databaseConfig = {
|
|
@@ -8429,8 +8463,8 @@ const getConfigScaffold = (build, authMode) => {
|
|
|
8429
8463
|
}],
|
|
8430
8464
|
configString: `dynamoDB({
|
|
8431
8465
|
...awsOptions,
|
|
8432
|
-
tableName:
|
|
8433
|
-
cloudfrontDistributionId:
|
|
8466
|
+
tableName: ${value("HOT_UPDATER_DYNAMODB_TABLE_NAME", resources?.tableName)},
|
|
8467
|
+
cloudfrontDistributionId: ${value("HOT_UPDATER_CLOUDFRONT_DISTRIBUTION_ID", resources?.cloudfrontDistributionId)},
|
|
8434
8468
|
})`
|
|
8435
8469
|
};
|
|
8436
8470
|
let helperStatements;
|
|
@@ -8442,7 +8476,7 @@ const getConfigScaffold = (build, authMode) => {
|
|
|
8442
8476
|
replaceIncompatibleProperties: ["credentials"],
|
|
8443
8477
|
code: `
|
|
8444
8478
|
const awsOptions = {
|
|
8445
|
-
region:
|
|
8479
|
+
region: ${region},
|
|
8446
8480
|
credentials: fromSSO({ profile: process.env.HOT_UPDATER_AWS_PROFILE! }),
|
|
8447
8481
|
};`.trim()
|
|
8448
8482
|
}];
|
|
@@ -8454,11 +8488,11 @@ const awsOptions = {
|
|
|
8454
8488
|
replaceIncompatibleProperties: ["credentials"],
|
|
8455
8489
|
code: authMode.profile ? `
|
|
8456
8490
|
const awsOptions = {
|
|
8457
|
-
region:
|
|
8491
|
+
region: ${region},
|
|
8458
8492
|
credentials: fromIni({ profile: process.env.HOT_UPDATER_AWS_PROFILE! }),
|
|
8459
8493
|
};`.trim() : `
|
|
8460
8494
|
const awsOptions = {
|
|
8461
|
-
region:
|
|
8495
|
+
region: ${region},
|
|
8462
8496
|
credentials: fromNodeProviderChain(),
|
|
8463
8497
|
};`.trim()
|
|
8464
8498
|
}];
|
|
@@ -8469,10 +8503,10 @@ const awsOptions = {
|
|
|
8469
8503
|
replaceIncompatibleProperties: ["credentials"],
|
|
8470
8504
|
code: `
|
|
8471
8505
|
const awsOptions = {
|
|
8472
|
-
region:
|
|
8506
|
+
region: ${region},
|
|
8473
8507
|
credentials: {
|
|
8474
|
-
accessKeyId:
|
|
8475
|
-
secretAccessKey:
|
|
8508
|
+
accessKeyId: secret("HOT_UPDATER_S3_ACCESS_KEY_ID"),
|
|
8509
|
+
secretAccessKey: secret("HOT_UPDATER_S3_SECRET_ACCESS_KEY"),
|
|
8476
8510
|
},
|
|
8477
8511
|
};`.trim()
|
|
8478
8512
|
}];
|
|
@@ -8495,9 +8529,15 @@ const awsOptions = {
|
|
|
8495
8529
|
named: ["fromSSO"]
|
|
8496
8530
|
});
|
|
8497
8531
|
break;
|
|
8498
|
-
case "local":
|
|
8499
|
-
|
|
8500
|
-
|
|
8532
|
+
case "local":
|
|
8533
|
+
builder.addImport({
|
|
8534
|
+
pkg: "@aws-sdk/credential-providers",
|
|
8535
|
+
named: [authMode.profile ? "fromIni" : "fromNodeProviderChain"]
|
|
8536
|
+
});
|
|
8537
|
+
break;
|
|
8538
|
+
case "account": builder.addImport({
|
|
8539
|
+
pkg: "hot-updater",
|
|
8540
|
+
named: ["secret"]
|
|
8501
8541
|
});
|
|
8502
8542
|
}
|
|
8503
8543
|
return createHotUpdaterConfigScaffoldFromBuilder(builder, { helperStatements });
|
|
@@ -8523,9 +8563,9 @@ const prepareDynamoDBDeployment = async (input) => {
|
|
|
8523
8563
|
remoteConfig()
|
|
8524
8564
|
]);
|
|
8525
8565
|
};
|
|
8526
|
-
const runInit = async ({ build, envFile }) => {
|
|
8566
|
+
const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
8527
8567
|
const nonInteractive = envFile !== void 0;
|
|
8528
|
-
const initEnvSources = await readHotUpdaterInitEnv(process.cwd(), envFile);
|
|
8568
|
+
const initEnvSources = await readHotUpdaterInitEnv(process.cwd(), envFile, secretsEnv);
|
|
8529
8569
|
const { managedEnv } = initEnvSources;
|
|
8530
8570
|
const providerEnv = getHotUpdaterInitInputEnv(initEnvSources, nonInteractive);
|
|
8531
8571
|
const savedInputs = resolveAwsInitInputs(providerEnv);
|
|
@@ -8734,7 +8774,12 @@ const runInit = async ({ build, envFile }) => {
|
|
|
8734
8774
|
if (mode === "sso") await ensureInstallPackages({ devDependencies: ["@aws-sdk/credential-provider-sso"] });
|
|
8735
8775
|
else if (mode === "local-session" || mode === "shared-profile") await ensureInstallPackages({ devDependencies: ["@aws-sdk/credential-providers"] });
|
|
8736
8776
|
p.log.success("Generated '.env.hotupdater' file with AWS settings.");
|
|
8737
|
-
await writeHotUpdaterFiles(getConfigScaffold(build, configAuthMode
|
|
8777
|
+
await writeHotUpdaterFiles(getConfigScaffold(build, configAuthMode, {
|
|
8778
|
+
region: bucketRegion,
|
|
8779
|
+
bucketName,
|
|
8780
|
+
tableName: resolvedDynamoDBTableName,
|
|
8781
|
+
cloudfrontDistributionId: distributionId
|
|
8782
|
+
}), {
|
|
8738
8783
|
cwd: process.cwd(),
|
|
8739
8784
|
settings: "AWS"
|
|
8740
8785
|
});
|
|
@@ -8743,8 +8788,7 @@ const runInit = async ({ build, envFile }) => {
|
|
|
8743
8788
|
...credential === void 0 ? {} : { credential },
|
|
8744
8789
|
clientPlugins: server.clientPlugins
|
|
8745
8790
|
});
|
|
8746
|
-
|
|
8747
|
-
p.log.success("Done! 🎉");
|
|
8791
|
+
return { nextSteps: [link("https://hot-updater.dev/docs/managed/aws#step-3-add-hotupdater-to-your-project")] };
|
|
8748
8792
|
};
|
|
8749
8793
|
//#endregion
|
|
8750
8794
|
export { LAMBDA_EDGE_TRUST_POLICY, buildDynamoDBBackupInput, buildDynamoDBCreateTableInput, buildDynamoDBPolicy, buildDynamoDBSchemaSettingsInput, buildDynamoDBTimeToLiveInput, buildS3Policy, buildSsmPolicy, initProvider, prepareDynamoDBDeployment, runInit };
|