@hot-updater/aws 1.2.0-rc.6 → 1.2.0-rc.61
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 +97 -31
- package/dist/init/index.d.cts +2 -2
- package/dist/init/index.d.mts +2 -2
- package/dist/init/index.mjs +99 -33
- package/dist/lambda/index.cjs +3476 -1062
- package/package.json +9 -8
package/dist/init/index.cjs
CHANGED
|
@@ -6579,10 +6579,30 @@ async apply() {
|
|
|
6579
6579
|
};
|
|
6580
6580
|
};
|
|
6581
6581
|
//#endregion
|
|
6582
|
+
//#region src/lazyCredentials.ts
|
|
6583
|
+
/**
|
|
6584
|
+
* `credentials` as the AWS SDK takes them: access keys with a lazy field
|
|
6585
|
+
* become a provider, which the SDK calls once, on its first request.
|
|
6586
|
+
*/
|
|
6587
|
+
const toSdkCredentials = (credentials) => {
|
|
6588
|
+
if (credentials === void 0 || typeof credentials === "function") return credentials;
|
|
6589
|
+
const { accessKeyId, secretAccessKey, sessionToken, ...rest } = credentials;
|
|
6590
|
+
if (typeof accessKeyId !== "function" && typeof secretAccessKey !== "function" && typeof sessionToken !== "function") return credentials;
|
|
6591
|
+
return async () => ({
|
|
6592
|
+
...rest,
|
|
6593
|
+
accessKeyId: await (0, _hot_updater_plugin_core.resolveLazy)(accessKeyId),
|
|
6594
|
+
secretAccessKey: await (0, _hot_updater_plugin_core.resolveLazy)(secretAccessKey),
|
|
6595
|
+
...sessionToken === void 0 ? {} : { sessionToken: await (0, _hot_updater_plugin_core.resolveLazy)(sessionToken) }
|
|
6596
|
+
});
|
|
6597
|
+
};
|
|
6598
|
+
//#endregion
|
|
6582
6599
|
//#region src/dynamoDB.ts
|
|
6583
6600
|
/** The DynamoDB client ignores the CloudFront and batching settings. */
|
|
6584
|
-
const adapterOf = ({ tableName, ...clientConfig }) => {
|
|
6585
|
-
const client = new _aws_sdk_client_dynamodb.DynamoDBClient(
|
|
6601
|
+
const adapterOf = ({ tableName, credentials, ...clientConfig }) => {
|
|
6602
|
+
const client = new _aws_sdk_client_dynamodb.DynamoDBClient({
|
|
6603
|
+
...clientConfig,
|
|
6604
|
+
credentials: toSdkCredentials(credentials)
|
|
6605
|
+
});
|
|
6586
6606
|
const store = createDynamoDBStore({
|
|
6587
6607
|
client,
|
|
6588
6608
|
tableName
|
|
@@ -6617,7 +6637,10 @@ const marked = (target) => ({ [DATABASE_TARGET]: target });
|
|
|
6617
6637
|
*/
|
|
6618
6638
|
const dynamoDB = (config) => {
|
|
6619
6639
|
const { client, adapter } = adapterOf(config);
|
|
6620
|
-
const cloudFront = createUpdateRouteInvalidation(
|
|
6640
|
+
const cloudFront = createUpdateRouteInvalidation({
|
|
6641
|
+
...config,
|
|
6642
|
+
credentials: toSdkCredentials(config.credentials)
|
|
6643
|
+
});
|
|
6621
6644
|
return {
|
|
6622
6645
|
...(0, _hot_updater_plugin_core.createEngineDatabase)({
|
|
6623
6646
|
name: "dynamoDB",
|
|
@@ -7255,6 +7278,33 @@ const buildOriginRequestPolicyConfig = (clientHeaders) => ({
|
|
|
7255
7278
|
CookiesConfig: { CookieBehavior: "none" },
|
|
7256
7279
|
QueryStringsConfig: { QueryStringBehavior: "all" }
|
|
7257
7280
|
});
|
|
7281
|
+
/**
|
|
7282
|
+
* Server errors CloudFront never caches: by default it keeps a 5xx for ten
|
|
7283
|
+
* seconds, so one 503 of a retryable read would reach every device behind
|
|
7284
|
+
* that edge. No response page replaces the server's own answer.
|
|
7285
|
+
*/
|
|
7286
|
+
const HOT_UPDATER_UNCACHED_ERROR_CODES = [
|
|
7287
|
+
500,
|
|
7288
|
+
502,
|
|
7289
|
+
503,
|
|
7290
|
+
504
|
|
7291
|
+
];
|
|
7292
|
+
/**
|
|
7293
|
+
* The API reference lists `ResponsePagePath` and `ResponseCode` as optional,
|
|
7294
|
+
* but CloudFront rejects an error response without both elements
|
|
7295
|
+
* (IllegalUpdate: "The specified list of custom error responses does not
|
|
7296
|
+
* exist or is not valid"). Empty elements mean no page replaces the origin's
|
|
7297
|
+
* answer.
|
|
7298
|
+
*/
|
|
7299
|
+
const withResponseElements = (response) => ({
|
|
7300
|
+
...response,
|
|
7301
|
+
ResponsePagePath: response.ResponsePagePath ?? "",
|
|
7302
|
+
ResponseCode: response.ResponseCode ?? ""
|
|
7303
|
+
});
|
|
7304
|
+
const uncachedErrorResponses = () => HOT_UPDATER_UNCACHED_ERROR_CODES.map((ErrorCode) => withResponseElements({
|
|
7305
|
+
ErrorCode,
|
|
7306
|
+
ErrorCachingMinTTL: 0
|
|
7307
|
+
}));
|
|
7258
7308
|
const READ_ONLY_METHODS = {
|
|
7259
7309
|
Quantity: 2,
|
|
7260
7310
|
Items: ["HEAD", "GET"],
|
|
@@ -7314,7 +7364,11 @@ const sanitizeDistributionConfig = (distributionConfig) => ({
|
|
|
7314
7364
|
CacheBehaviors: distributionConfig.CacheBehaviors ? {
|
|
7315
7365
|
Quantity: distributionConfig.CacheBehaviors.Quantity,
|
|
7316
7366
|
Items: (distributionConfig.CacheBehaviors.Items ?? []).map((behavior) => sanitizeCacheBehavior(behavior))
|
|
7317
|
-
} : distributionConfig.CacheBehaviors
|
|
7367
|
+
} : distributionConfig.CacheBehaviors,
|
|
7368
|
+
CustomErrorResponses: distributionConfig.CustomErrorResponses ? {
|
|
7369
|
+
Quantity: distributionConfig.CustomErrorResponses.Quantity,
|
|
7370
|
+
Items: distributionConfig.CustomErrorResponses.Items?.map(withResponseElements)
|
|
7371
|
+
} : distributionConfig.CustomErrorResponses
|
|
7318
7372
|
});
|
|
7319
7373
|
const buildOriginRequestLambdaAssociations = (functionArn) => ({
|
|
7320
7374
|
Quantity: 1,
|
|
@@ -7431,6 +7485,10 @@ const buildDistributionConfigOverrides = (options) => ({
|
|
|
7431
7485
|
sharedCachePolicyId: options.sharedCachePolicyId
|
|
7432
7486
|
}))
|
|
7433
7487
|
]
|
|
7488
|
+
},
|
|
7489
|
+
CustomErrorResponses: {
|
|
7490
|
+
Quantity: HOT_UPDATER_UNCACHED_ERROR_CODES.length,
|
|
7491
|
+
Items: uncachedErrorResponses()
|
|
7434
7492
|
}
|
|
7435
7493
|
});
|
|
7436
7494
|
const applyDistributionConfigOverrides = (distributionConfig, overrides) => {
|
|
@@ -7446,6 +7504,8 @@ const applyDistributionConfigOverrides = (distributionConfig, overrides) => {
|
|
|
7446
7504
|
} : behavior);
|
|
7447
7505
|
const origins = mergeOrigins(distributionConfig.Origins?.Items ?? [], overrides.Origins.Items ?? []);
|
|
7448
7506
|
const cacheBehaviors = mergeCacheBehaviors(distributionConfig.CacheBehaviors?.Items ?? [], cacheBehaviorOverrides);
|
|
7507
|
+
const managedCodes = new Set((overrides.CustomErrorResponses.Items ?? []).map(({ ErrorCode }) => ErrorCode));
|
|
7508
|
+
const errorResponses = [...(distributionConfig.CustomErrorResponses?.Items ?? []).filter(({ ErrorCode }) => !managedCodes.has(ErrorCode)), ...overrides.CustomErrorResponses.Items ?? []];
|
|
7449
7509
|
return sanitizeDistributionConfig({
|
|
7450
7510
|
...distributionConfig,
|
|
7451
7511
|
Origins: {
|
|
@@ -7456,6 +7516,10 @@ const applyDistributionConfigOverrides = (distributionConfig, overrides) => {
|
|
|
7456
7516
|
CacheBehaviors: {
|
|
7457
7517
|
Quantity: cacheBehaviors.length,
|
|
7458
7518
|
Items: cacheBehaviors
|
|
7519
|
+
},
|
|
7520
|
+
CustomErrorResponses: {
|
|
7521
|
+
Quantity: errorResponses.length,
|
|
7522
|
+
Items: errorResponses
|
|
7459
7523
|
}
|
|
7460
7524
|
});
|
|
7461
7525
|
};
|
|
@@ -8419,10 +8483,11 @@ var SSMKeyPairManager = class {
|
|
|
8419
8483
|
//#region iac/templates.ts
|
|
8420
8484
|
/**
|
|
8421
8485
|
* The config init writes. With the `resources` init set up, it names them,
|
|
8422
|
-
* and an account's access keys are read with `
|
|
8486
|
+
* and an account's access keys are read with `secret()`, from the
|
|
8423
8487
|
* environment and `.env.hotupdater`, then the config's `secrets` adapter.
|
|
8424
|
-
* Without them, as the agent scaffold writes it
|
|
8425
|
-
*
|
|
8488
|
+
* Without them, as the agent scaffold writes it before the agent creates the
|
|
8489
|
+
* resources, it reads their names from the environment, where the agent
|
|
8490
|
+
* records them. A profile or SSO sign-in is each person's own.
|
|
8426
8491
|
*/
|
|
8427
8492
|
const getConfigScaffold = (build, authMode, resources) => {
|
|
8428
8493
|
const value = (envKey, resolved) => resolved === void 0 ? `process.env.${envKey}!` : JSON.stringify(resolved);
|
|
@@ -8478,31 +8543,19 @@ const awsOptions = {
|
|
|
8478
8543
|
};`.trim()
|
|
8479
8544
|
}];
|
|
8480
8545
|
break;
|
|
8481
|
-
case "account":
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
code: resources === void 0 ? `
|
|
8546
|
+
case "account": helperStatements = [{
|
|
8547
|
+
name: "awsOptions",
|
|
8548
|
+
strategy: "merge-object",
|
|
8549
|
+
replaceIncompatibleProperties: ["credentials"],
|
|
8550
|
+
code: `
|
|
8487
8551
|
const awsOptions = {
|
|
8488
8552
|
region: ${region},
|
|
8489
8553
|
credentials: {
|
|
8490
|
-
accessKeyId:
|
|
8491
|
-
secretAccessKey:
|
|
8492
|
-
},
|
|
8493
|
-
};`.trim() : `
|
|
8494
|
-
const awsOptions = {
|
|
8495
|
-
region: ${region},
|
|
8496
|
-
credentials: async () => {
|
|
8497
|
-
const env = await deploySecrets();
|
|
8498
|
-
return {
|
|
8499
|
-
accessKeyId: env.HOT_UPDATER_S3_ACCESS_KEY_ID,
|
|
8500
|
-
secretAccessKey: env.HOT_UPDATER_S3_SECRET_ACCESS_KEY,
|
|
8501
|
-
};
|
|
8554
|
+
accessKeyId: secret("HOT_UPDATER_S3_ACCESS_KEY_ID"),
|
|
8555
|
+
secretAccessKey: secret("HOT_UPDATER_S3_SECRET_ACCESS_KEY"),
|
|
8502
8556
|
},
|
|
8503
8557
|
};`.trim()
|
|
8504
|
-
|
|
8505
|
-
if (resources !== void 0) helperStatements.unshift((0, _hot_updater_cli_tools.secretEnvHelper)("deploySecrets", ["HOT_UPDATER_S3_ACCESS_KEY_ID", "HOT_UPDATER_S3_SECRET_ACCESS_KEY"]));
|
|
8558
|
+
}];
|
|
8506
8559
|
}
|
|
8507
8560
|
const builder = new _hot_updater_cli_tools.ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
|
|
8508
8561
|
imports: [{
|
|
@@ -8528,9 +8581,9 @@ const awsOptions = {
|
|
|
8528
8581
|
named: [authMode.profile ? "fromIni" : "fromNodeProviderChain"]
|
|
8529
8582
|
});
|
|
8530
8583
|
break;
|
|
8531
|
-
case "account":
|
|
8584
|
+
case "account": builder.addImport({
|
|
8532
8585
|
pkg: "hot-updater",
|
|
8533
|
-
named: ["
|
|
8586
|
+
named: ["secret"]
|
|
8534
8587
|
});
|
|
8535
8588
|
}
|
|
8536
8589
|
return (0, _hot_updater_cli_tools.createHotUpdaterConfigScaffoldFromBuilder)(builder, { helperStatements });
|
|
@@ -8722,6 +8775,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8722
8775
|
});
|
|
8723
8776
|
let credential;
|
|
8724
8777
|
try {
|
|
8778
|
+
await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
|
|
8725
8779
|
credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
|
|
8726
8780
|
env: providerEnv,
|
|
8727
8781
|
name: "AWS init"
|
|
@@ -8776,13 +8830,25 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8776
8830
|
cwd: process.cwd(),
|
|
8777
8831
|
settings: "AWS"
|
|
8778
8832
|
});
|
|
8833
|
+
const backfillDatabase = dynamoDB({
|
|
8834
|
+
credentials,
|
|
8835
|
+
region: bucketRegion,
|
|
8836
|
+
tableName: resolvedDynamoDBTableName
|
|
8837
|
+
});
|
|
8838
|
+
try {
|
|
8839
|
+
await (0, _hot_updater_cli_tools.backfillInsightsReleaseRefs)((0, _hot_updater_cli_tools.assembleServer)({
|
|
8840
|
+
database: backfillDatabase,
|
|
8841
|
+
plugins: server.plugins
|
|
8842
|
+
}));
|
|
8843
|
+
} finally {
|
|
8844
|
+
await backfillDatabase.dispose?.();
|
|
8845
|
+
}
|
|
8779
8846
|
(0, _hot_updater_cli_tools.printAppSetup)({
|
|
8780
8847
|
baseURL: `https://${distributionDomain}`,
|
|
8781
8848
|
...credential === void 0 ? {} : { credential },
|
|
8782
8849
|
clientPlugins: server.clientPlugins
|
|
8783
8850
|
});
|
|
8784
|
-
|
|
8785
|
-
_hot_updater_cli_tools.p.log.success("Done! 🎉");
|
|
8851
|
+
return { nextSteps: [(0, _hot_updater_cli_tools.link)("https://hot-updater.dev/docs/managed/aws#step-3-add-hotupdater-to-your-project")] };
|
|
8786
8852
|
};
|
|
8787
8853
|
//#endregion
|
|
8788
8854
|
exports.LAMBDA_EDGE_TRUST_POLICY = LAMBDA_EDGE_TRUST_POLICY;
|
package/dist/init/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunInitOptions } from "@hot-updater/cli-tools";
|
|
1
|
+
import { 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.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, backfillInsightsReleaseRefs, colors, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, createZip, ensureInstallPackages, fillReleaseLabels, 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 });
|
|
@@ -8717,6 +8770,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8717
8770
|
});
|
|
8718
8771
|
let credential;
|
|
8719
8772
|
try {
|
|
8773
|
+
await fillReleaseLabels(server);
|
|
8720
8774
|
credential = await provisionClientCredential(server, {
|
|
8721
8775
|
env: providerEnv,
|
|
8722
8776
|
name: "AWS init"
|
|
@@ -8771,13 +8825,25 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8771
8825
|
cwd: process.cwd(),
|
|
8772
8826
|
settings: "AWS"
|
|
8773
8827
|
});
|
|
8828
|
+
const backfillDatabase = dynamoDB({
|
|
8829
|
+
credentials,
|
|
8830
|
+
region: bucketRegion,
|
|
8831
|
+
tableName: resolvedDynamoDBTableName
|
|
8832
|
+
});
|
|
8833
|
+
try {
|
|
8834
|
+
await backfillInsightsReleaseRefs(assembleServer({
|
|
8835
|
+
database: backfillDatabase,
|
|
8836
|
+
plugins: server.plugins
|
|
8837
|
+
}));
|
|
8838
|
+
} finally {
|
|
8839
|
+
await backfillDatabase.dispose?.();
|
|
8840
|
+
}
|
|
8774
8841
|
printAppSetup({
|
|
8775
8842
|
baseURL: `https://${distributionDomain}`,
|
|
8776
8843
|
...credential === void 0 ? {} : { credential },
|
|
8777
8844
|
clientPlugins: server.clientPlugins
|
|
8778
8845
|
});
|
|
8779
|
-
|
|
8780
|
-
p.log.success("Done! 🎉");
|
|
8846
|
+
return { nextSteps: [link("https://hot-updater.dev/docs/managed/aws#step-3-add-hotupdater-to-your-project")] };
|
|
8781
8847
|
};
|
|
8782
8848
|
//#endregion
|
|
8783
8849
|
export { LAMBDA_EDGE_TRUST_POLICY, buildDynamoDBBackupInput, buildDynamoDBCreateTableInput, buildDynamoDBPolicy, buildDynamoDBSchemaSettingsInput, buildDynamoDBTimeToLiveInput, buildS3Policy, buildSsmPolicy, initProvider, prepareDynamoDBDeployment, runInit };
|