Skip to content

Commit 43be1dd

Browse files
committed
fixup! ability to customize nb of versions and their max age
1 parent 468cd0a commit 43be1dd

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/cloudflare/src/api/config.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,22 @@ interface OpenNextConfig extends AwsOpenNextConfig {
160160
dangerousDisableConfigValidation?: boolean;
161161

162162
/**
163-
* Enable skew protection.
163+
* Skew protection.
164164
*
165165
* Note: Skew Protection is experimental and might break on minor releases.
166166
*
167167
* @default false
168168
*/
169-
skewProtectionEnabled?: boolean;
169+
skewProtection?: {
170+
// Whether to enable skew protection
171+
enabled?: boolean;
172+
// Maximum number of versions to retrieve
173+
// @default 20
174+
maxNumberOfVersions?: number;
175+
// Maximum age of versions to retrieve in days
176+
// @default 7
177+
maxVersionAgeDays?: number;
178+
};
170179
};
171180
}
172181

packages/cloudflare/src/cli/build/open-next/compile-skew-protection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function compileSkewProtection(options: BuildOptions, config: OpenN
1111
const templatesDir = path.join(currentDir, "../../templates");
1212
const initPath = path.join(templatesDir, "skew-protection.js");
1313

14-
const skewProtectionEnabled = config.cloudflare?.skewProtectionEnabled ?? false;
14+
const skewProtectionEnabled = config.cloudflare?.skewProtection?.enabled === true;
1515

1616
await build({
1717
entryPoints: [initPath],

packages/cloudflare/src/cli/commands/skew-protection.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type { WorkerEnvVar } from "./helpers.js";
3838
const MAX_NUMBER_OF_VERSIONS = 20;
3939
/** Maximum age of versions to list */
4040
const MAX_VERSION_AGE_DAYS = 7;
41+
const MS_PER_DAY = 24 * 3600 * 1000;
4142

4243
/**
4344
* Compute the deployment mapping for a deployment.
@@ -52,7 +53,7 @@ export async function getDeploymentMapping(
5253
config: OpenNextConfig,
5354
envVars: WorkerEnvVar
5455
): Promise<Record<string, string> | undefined> {
55-
if (config.cloudflare?.skewProtectionEnabled !== true) {
56+
if (config.cloudflare?.skewProtection?.enabled !== true) {
5657
return undefined;
5758
}
5859

@@ -93,6 +94,10 @@ export async function getDeploymentMapping(
9394
const deployedVersions = await listWorkerVersions(scriptName, {
9495
client,
9596
accountId,
97+
maxNumberOfVersions: config.cloudflare?.skewProtection?.maxNumberOfVersions,
98+
afterTimeMs: config.cloudflare?.skewProtection?.maxVersionAgeDays
99+
? Date.now() - config.cloudflare?.skewProtection?.maxVersionAgeDays * MS_PER_DAY
100+
: undefined,
96101
});
97102

98103
const existingMapping =

0 commit comments

Comments
 (0)