@hot-updater/aws 1.2.0-rc.5 → 1.2.0-rc.50
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 +144 -188
- package/dist/index.d.cts +30 -12
- package/dist/index.d.mts +30 -12
- package/dist/index.mjs +145 -189
- package/dist/init/index.cjs +83 -31
- package/dist/init/index.d.cts +2 -2
- package/dist/init/index.d.mts +2 -2
- package/dist/init/index.mjs +85 -33
- package/dist/lambda/index.cjs +1789 -411
- package/package.json +8 -7
package/dist/init/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitError, RunInitOptions } from "@hot-updater/cli-tools";
|
|
1
|
+
import { InitError, RunInitOptions, RunInitResult } from "@hot-updater/cli-tools";
|
|
2
2
|
//#region iac/dynamodb.d.ts
|
|
3
3
|
declare const buildDynamoDBCreateTableInput: (tableName: string) => {
|
|
4
4
|
AttributeDefinitions: {
|
|
@@ -219,6 +219,6 @@ declare const prepareDynamoDBDeployment: (input: {
|
|
|
219
219
|
readonly region: string;
|
|
220
220
|
readonly tableName: string;
|
|
221
221
|
}) => Promise<void>;
|
|
222
|
-
declare const runInit: ({ build, envFile, secretsEnv }: RunInitOptions) => Promise<
|
|
222
|
+
declare const runInit: ({ build, envFile, secretsEnv }: RunInitOptions) => Promise<RunInitResult>;
|
|
223
223
|
//#endregion
|
|
224
224
|
export { LAMBDA_EDGE_TRUST_POLICY, buildDynamoDBBackupInput, buildDynamoDBCreateTableInput, buildDynamoDBPolicy, buildDynamoDBSchemaSettingsInput, buildDynamoDBTimeToLiveInput, buildS3Policy, buildSsmPolicy, initProvider, prepareDynamoDBDeployment, runInit };
|
package/dist/init/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInfrastructureGenerationPayload, assertInitProviderInputs, colors, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, createZip, ensureInstallPackages, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput,
|
|
2
|
+
import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInfrastructureGenerationPayload, assertInitProviderInputs, colors, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, createZip, ensureInstallPackages, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, transformEnv, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
3
3
|
import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
@@ -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",
|
|
@@ -7250,6 +7273,33 @@ const buildOriginRequestPolicyConfig = (clientHeaders) => ({
|
|
|
7250
7273
|
CookiesConfig: { CookieBehavior: "none" },
|
|
7251
7274
|
QueryStringsConfig: { QueryStringBehavior: "all" }
|
|
7252
7275
|
});
|
|
7276
|
+
/**
|
|
7277
|
+
* Server errors CloudFront never caches: by default it keeps a 5xx for ten
|
|
7278
|
+
* seconds, so one 503 of a retryable read would reach every device behind
|
|
7279
|
+
* that edge. No response page replaces the server's own answer.
|
|
7280
|
+
*/
|
|
7281
|
+
const HOT_UPDATER_UNCACHED_ERROR_CODES = [
|
|
7282
|
+
500,
|
|
7283
|
+
502,
|
|
7284
|
+
503,
|
|
7285
|
+
504
|
|
7286
|
+
];
|
|
7287
|
+
/**
|
|
7288
|
+
* The API reference lists `ResponsePagePath` and `ResponseCode` as optional,
|
|
7289
|
+
* but CloudFront rejects an error response without both elements
|
|
7290
|
+
* (IllegalUpdate: "The specified list of custom error responses does not
|
|
7291
|
+
* exist or is not valid"). Empty elements mean no page replaces the origin's
|
|
7292
|
+
* answer.
|
|
7293
|
+
*/
|
|
7294
|
+
const withResponseElements = (response) => ({
|
|
7295
|
+
...response,
|
|
7296
|
+
ResponsePagePath: response.ResponsePagePath ?? "",
|
|
7297
|
+
ResponseCode: response.ResponseCode ?? ""
|
|
7298
|
+
});
|
|
7299
|
+
const uncachedErrorResponses = () => HOT_UPDATER_UNCACHED_ERROR_CODES.map((ErrorCode) => withResponseElements({
|
|
7300
|
+
ErrorCode,
|
|
7301
|
+
ErrorCachingMinTTL: 0
|
|
7302
|
+
}));
|
|
7253
7303
|
const READ_ONLY_METHODS = {
|
|
7254
7304
|
Quantity: 2,
|
|
7255
7305
|
Items: ["HEAD", "GET"],
|
|
@@ -7309,7 +7359,11 @@ const sanitizeDistributionConfig = (distributionConfig) => ({
|
|
|
7309
7359
|
CacheBehaviors: distributionConfig.CacheBehaviors ? {
|
|
7310
7360
|
Quantity: distributionConfig.CacheBehaviors.Quantity,
|
|
7311
7361
|
Items: (distributionConfig.CacheBehaviors.Items ?? []).map((behavior) => sanitizeCacheBehavior(behavior))
|
|
7312
|
-
} : distributionConfig.CacheBehaviors
|
|
7362
|
+
} : distributionConfig.CacheBehaviors,
|
|
7363
|
+
CustomErrorResponses: distributionConfig.CustomErrorResponses ? {
|
|
7364
|
+
Quantity: distributionConfig.CustomErrorResponses.Quantity,
|
|
7365
|
+
Items: distributionConfig.CustomErrorResponses.Items?.map(withResponseElements)
|
|
7366
|
+
} : distributionConfig.CustomErrorResponses
|
|
7313
7367
|
});
|
|
7314
7368
|
const buildOriginRequestLambdaAssociations = (functionArn) => ({
|
|
7315
7369
|
Quantity: 1,
|
|
@@ -7426,6 +7480,10 @@ const buildDistributionConfigOverrides = (options) => ({
|
|
|
7426
7480
|
sharedCachePolicyId: options.sharedCachePolicyId
|
|
7427
7481
|
}))
|
|
7428
7482
|
]
|
|
7483
|
+
},
|
|
7484
|
+
CustomErrorResponses: {
|
|
7485
|
+
Quantity: HOT_UPDATER_UNCACHED_ERROR_CODES.length,
|
|
7486
|
+
Items: uncachedErrorResponses()
|
|
7429
7487
|
}
|
|
7430
7488
|
});
|
|
7431
7489
|
const applyDistributionConfigOverrides = (distributionConfig, overrides) => {
|
|
@@ -7441,6 +7499,8 @@ const applyDistributionConfigOverrides = (distributionConfig, overrides) => {
|
|
|
7441
7499
|
} : behavior);
|
|
7442
7500
|
const origins = mergeOrigins(distributionConfig.Origins?.Items ?? [], overrides.Origins.Items ?? []);
|
|
7443
7501
|
const cacheBehaviors = mergeCacheBehaviors(distributionConfig.CacheBehaviors?.Items ?? [], cacheBehaviorOverrides);
|
|
7502
|
+
const managedCodes = new Set((overrides.CustomErrorResponses.Items ?? []).map(({ ErrorCode }) => ErrorCode));
|
|
7503
|
+
const errorResponses = [...(distributionConfig.CustomErrorResponses?.Items ?? []).filter(({ ErrorCode }) => !managedCodes.has(ErrorCode)), ...overrides.CustomErrorResponses.Items ?? []];
|
|
7444
7504
|
return sanitizeDistributionConfig({
|
|
7445
7505
|
...distributionConfig,
|
|
7446
7506
|
Origins: {
|
|
@@ -7451,6 +7511,10 @@ const applyDistributionConfigOverrides = (distributionConfig, overrides) => {
|
|
|
7451
7511
|
CacheBehaviors: {
|
|
7452
7512
|
Quantity: cacheBehaviors.length,
|
|
7453
7513
|
Items: cacheBehaviors
|
|
7514
|
+
},
|
|
7515
|
+
CustomErrorResponses: {
|
|
7516
|
+
Quantity: errorResponses.length,
|
|
7517
|
+
Items: errorResponses
|
|
7454
7518
|
}
|
|
7455
7519
|
});
|
|
7456
7520
|
};
|
|
@@ -8414,10 +8478,11 @@ var SSMKeyPairManager = class {
|
|
|
8414
8478
|
//#region iac/templates.ts
|
|
8415
8479
|
/**
|
|
8416
8480
|
* The config init writes. With the `resources` init set up, it names them,
|
|
8417
|
-
* and an account's access keys are read with `
|
|
8481
|
+
* and an account's access keys are read with `secret()`, from the
|
|
8418
8482
|
* environment and `.env.hotupdater`, then the config's `secrets` adapter.
|
|
8419
|
-
* Without them, as the agent scaffold writes it
|
|
8420
|
-
*
|
|
8483
|
+
* Without them, as the agent scaffold writes it before the agent creates the
|
|
8484
|
+
* resources, it reads their names from the environment, where the agent
|
|
8485
|
+
* records them. A profile or SSO sign-in is each person's own.
|
|
8421
8486
|
*/
|
|
8422
8487
|
const getConfigScaffold = (build, authMode, resources) => {
|
|
8423
8488
|
const value = (envKey, resolved) => resolved === void 0 ? `process.env.${envKey}!` : JSON.stringify(resolved);
|
|
@@ -8473,31 +8538,19 @@ const awsOptions = {
|
|
|
8473
8538
|
};`.trim()
|
|
8474
8539
|
}];
|
|
8475
8540
|
break;
|
|
8476
|
-
case "account":
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
code: resources === void 0 ? `
|
|
8541
|
+
case "account": helperStatements = [{
|
|
8542
|
+
name: "awsOptions",
|
|
8543
|
+
strategy: "merge-object",
|
|
8544
|
+
replaceIncompatibleProperties: ["credentials"],
|
|
8545
|
+
code: `
|
|
8482
8546
|
const awsOptions = {
|
|
8483
8547
|
region: ${region},
|
|
8484
8548
|
credentials: {
|
|
8485
|
-
accessKeyId:
|
|
8486
|
-
secretAccessKey:
|
|
8487
|
-
},
|
|
8488
|
-
};`.trim() : `
|
|
8489
|
-
const awsOptions = {
|
|
8490
|
-
region: ${region},
|
|
8491
|
-
credentials: async () => {
|
|
8492
|
-
const env = await deploySecrets();
|
|
8493
|
-
return {
|
|
8494
|
-
accessKeyId: env.HOT_UPDATER_S3_ACCESS_KEY_ID,
|
|
8495
|
-
secretAccessKey: env.HOT_UPDATER_S3_SECRET_ACCESS_KEY,
|
|
8496
|
-
};
|
|
8549
|
+
accessKeyId: secret("HOT_UPDATER_S3_ACCESS_KEY_ID"),
|
|
8550
|
+
secretAccessKey: secret("HOT_UPDATER_S3_SECRET_ACCESS_KEY"),
|
|
8497
8551
|
},
|
|
8498
8552
|
};`.trim()
|
|
8499
|
-
|
|
8500
|
-
if (resources !== void 0) helperStatements.unshift(secretEnvHelper("deploySecrets", ["HOT_UPDATER_S3_ACCESS_KEY_ID", "HOT_UPDATER_S3_SECRET_ACCESS_KEY"]));
|
|
8553
|
+
}];
|
|
8501
8554
|
}
|
|
8502
8555
|
const builder = new ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
|
|
8503
8556
|
imports: [{
|
|
@@ -8523,9 +8576,9 @@ const awsOptions = {
|
|
|
8523
8576
|
named: [authMode.profile ? "fromIni" : "fromNodeProviderChain"]
|
|
8524
8577
|
});
|
|
8525
8578
|
break;
|
|
8526
|
-
case "account":
|
|
8579
|
+
case "account": builder.addImport({
|
|
8527
8580
|
pkg: "hot-updater",
|
|
8528
|
-
named: ["
|
|
8581
|
+
named: ["secret"]
|
|
8529
8582
|
});
|
|
8530
8583
|
}
|
|
8531
8584
|
return createHotUpdaterConfigScaffoldFromBuilder(builder, { helperStatements });
|
|
@@ -8776,8 +8829,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8776
8829
|
...credential === void 0 ? {} : { credential },
|
|
8777
8830
|
clientPlugins: server.clientPlugins
|
|
8778
8831
|
});
|
|
8779
|
-
|
|
8780
|
-
p.log.success("Done! 🎉");
|
|
8832
|
+
return { nextSteps: [link("https://hot-updater.dev/docs/managed/aws#step-3-add-hotupdater-to-your-project")] };
|
|
8781
8833
|
};
|
|
8782
8834
|
//#endregion
|
|
8783
8835
|
export { LAMBDA_EDGE_TRUST_POLICY, buildDynamoDBBackupInput, buildDynamoDBCreateTableInput, buildDynamoDBPolicy, buildDynamoDBSchemaSettingsInput, buildDynamoDBTimeToLiveInput, buildS3Policy, buildSsmPolicy, initProvider, prepareDynamoDBDeployment, runInit };
|