canopycms-cdk 0.5.0 → 0.7.0

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/README.md CHANGED
@@ -22,7 +22,7 @@ What changed in each release, for all five CanopyCMS packages, is in `node_modul
22
22
  **`CanopyCmsDistribution`** — CloudFront + DNS (optional):
23
23
 
24
24
  - ACM certificate with DNS validation
25
- - CloudFront distribution with Lambda Function URL origin
25
+ - CloudFront distribution with Lambda Function URL origin; its read timeout follows the Lambda's (60 s by default, at most 120 s, CloudFront's default quota)
26
26
  - Route53 A/AAAA alias records
27
27
  - Cache policies: no-cache for API/editor, long-cache for static assets
28
28
  - Response headers: framing protection (`frame-ancestors 'self'`), `nosniff`, HSTS, `X-Robots-Tag: noindex`
@@ -26,7 +26,7 @@ export interface CanopyCmsDistributionProps {
26
26
  * First-touch branch provisioning does a full `git clone` onto EFS inside the
27
27
  * request, so this is a real path.
28
28
  *
29
- * Capped at 60s: CloudFront rejects more without a service-quota increase.
29
+ * Capped at 120s (`MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT`), CloudFront's default quota.
30
30
  */
31
31
  originReadTimeout?: Duration;
32
32
  /**
@@ -25,10 +25,10 @@ export declare function withoutShellComments(...lines: string[]): string[];
25
25
  * One constant rather than two matching literals, so the pair cannot drift;
26
26
  * `cms-deploy.test.ts` asserts the emitted template keeps them equal.
27
27
  *
28
- * NOTE: CloudFront accepts an origin read timeout up to 60s without a quota
29
- * increase. A longer Lambda timeout needs an AWS quota increase before the
30
- * distribution can match it — `CanopyCmsDistribution` fails at synth rather
31
- * than deploying a configuration that would 504.
28
+ * NOTE: the Lambda timeout may not exceed `MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT`
29
+ * (120s, CloudFront's default origin response timeout quota):
30
+ * `CanopyCmsDistribution` and `attachTo` fail at synth rather than deploying a
31
+ * configuration that would 504.
32
32
  */
33
33
  export declare const DEFAULT_CMS_LAMBDA_TIMEOUT: Duration;
34
34
  /**
@@ -47,7 +47,7 @@ export interface CanopyCmsServiceProps {
47
47
  vpc?: ec2.IVpc;
48
48
  /** Lambda memory in MB (default: 2048) */
49
49
  memorySize?: number;
50
- /** Lambda timeout (default: 60 seconds) */
50
+ /** Lambda timeout (default: 60 seconds; at most 120 seconds, see {@link DEFAULT_CMS_LAMBDA_TIMEOUT}) */
51
51
  timeout?: Duration;
52
52
  /**
53
53
  * Cap on the CMS Lambda's concurrent invocations (default: 50).
@@ -268,6 +268,19 @@ export interface CanopyCmsServiceProps {
268
268
  * not relieve you of supplying those two separately.
269
269
  */
270
270
  clerkSecretKeySecretJsonField?: string;
271
+ /**
272
+ * Whether the worker maps Clerk Organizations onto Canopy groups (default
273
+ * true). Stamped into the GitHub gateway's
274
+ * `CANOPYCMS_CLERK_ORGANIZATIONS_AS_GROUPS` only when set.
275
+ *
276
+ * In a deployment this, not `createClerkAuthPlugin`'s
277
+ * `useOrganizationsAsGroups`, decides what groups the editor sees: the
278
+ * Lambda serves auth from the cache the worker writes. Set it to match the
279
+ * plugin option. Set it `false` when Organizations is disabled on the Clerk
280
+ * instance; otherwise every refresh logs a warning and writes no groups. A
281
+ * worker bundle from before this prop existed ignores it.
282
+ */
283
+ clerkOrganizationsAsGroups?: boolean;
271
284
  /**
272
285
  * The branch editing branches fork from (default: unset, so the worker
273
286
  * detects it: the branch remote.git's HEAD names, or before remote.git exists
@@ -577,10 +577,10 @@ function assertGitHubAuthProps(props) {
577
577
  * One constant rather than two matching literals, so the pair cannot drift;
578
578
  * `cms-deploy.test.ts` asserts the emitted template keeps them equal.
579
579
  *
580
- * NOTE: CloudFront accepts an origin read timeout up to 60s without a quota
581
- * increase. A longer Lambda timeout needs an AWS quota increase before the
582
- * distribution can match it — `CanopyCmsDistribution` fails at synth rather
583
- * than deploying a configuration that would 504.
580
+ * NOTE: the Lambda timeout may not exceed `MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT`
581
+ * (120s, CloudFront's default origin response timeout quota):
582
+ * `CanopyCmsDistribution` and `attachTo` fail at synth rather than deploying a
583
+ * configuration that would 504.
584
584
  */
585
585
  export const DEFAULT_CMS_LAMBDA_TIMEOUT = Duration.seconds(60);
586
586
  /**
@@ -1198,6 +1198,13 @@ export class CanopyCmsService extends Construct {
1198
1198
  'gateway',
1199
1199
  ]);
1200
1200
  }
1201
+ if (props.clerkOrganizationsAsGroups !== undefined) {
1202
+ envEntries.push([
1203
+ 'CANOPYCMS_CLERK_ORGANIZATIONS_AS_GROUPS',
1204
+ String(props.clerkOrganizationsAsGroups),
1205
+ 'gateway',
1206
+ ]);
1207
+ }
1201
1208
  if (workerCapacity.type === 'spot') {
1202
1209
  // The termination watch is the gateway's.
1203
1210
  envEntries.push([WORKER_CAPACITY_ENV, 'spot', 'gateway']);
@@ -1,6 +1,16 @@
1
1
  import { Construct } from 'constructs';
2
2
  import { Duration, aws_cloudfront as cloudfront, aws_lambda as lambda } from 'aws-cdk-lib';
3
- /** CloudFront's maximum origin read timeout without a service-quota increase. */
3
+ /**
4
+ * The longest origin read timeout these constructs accept: CloudFront's default
5
+ * quota for "Response timeout per origin" (1-120 s; 30 s unset; CloudFront Developer Guide,
6
+ * Quotas > General quotas on distributions).
7
+ *
8
+ * A cap rather than a pass-through of a raised quota because the editor's client
9
+ * deadline sits just above it (`REQUEST_TIMEOUT_MS` in canopycms
10
+ * `api/request-deadline.ts`, pinned by `request-deadline-pin.test.ts`) and cannot
11
+ * see the account's quota: a longer origin would be given up on by the browser
12
+ * before CloudFront answers.
13
+ */
4
14
  export declare const MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT: Duration;
5
15
  /**
6
16
  * The routes the editor needs from the CMS Lambda on a distribution it shares
@@ -21,9 +31,8 @@ export declare const EDITOR_PATH_PATTERNS: readonly ["/edit", "/edit/*", "/api/c
21
31
  */
22
32
  export declare function cloudFrontPathPatternMatches(pattern: string, path: string): boolean;
23
33
  /**
24
- * Throws when the origin read timeout exceeds the 60s CloudFront accepts
25
- * without a quota increase, which it would reject at deploy. Neither construct
26
- * takes a higher, quota-raised value.
34
+ * Throws when the origin read timeout exceeds {@link MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT},
35
+ * so a configuration the editor's deadline cannot cover fails at synth, not mid-deploy.
27
36
  */
28
37
  export declare function assertOriginReadTimeout(readTimeout: Duration, owner: string): void;
29
38
  /**
@@ -1,8 +1,18 @@
1
1
  import { Construct } from 'constructs';
2
2
  import { Annotations, Duration, Stack, aws_cloudfront as cloudfront, aws_cloudfront_origins as origins, } from 'aws-cdk-lib';
3
3
  import { ASSETS_PATH_PATTERN, ASSETS_TRANSFORM_PATH_PATTERN } from './asset-support.js';
4
- /** CloudFront's maximum origin read timeout without a service-quota increase. */
5
- export const MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT = Duration.seconds(60);
4
+ /**
5
+ * The longest origin read timeout these constructs accept: CloudFront's default
6
+ * quota for "Response timeout per origin" (1-120 s; 30 s unset; CloudFront Developer Guide,
7
+ * Quotas > General quotas on distributions).
8
+ *
9
+ * A cap rather than a pass-through of a raised quota because the editor's client
10
+ * deadline sits just above it (`REQUEST_TIMEOUT_MS` in canopycms
11
+ * `api/request-deadline.ts`, pinned by `request-deadline-pin.test.ts`) and cannot
12
+ * see the account's quota: a longer origin would be given up on by the browser
13
+ * before CloudFront answers.
14
+ */
15
+ export const MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT = Duration.seconds(120);
6
16
  /**
7
17
  * The routes the editor needs from the CMS Lambda on a distribution it shares
8
18
  * with a site: the editor page and the catch-all API route `canopycms init`
@@ -72,17 +82,18 @@ export function cloudFrontPathPatternMatches(pattern, path) {
72
82
  return g === glob.length;
73
83
  }
74
84
  /**
75
- * Throws when the origin read timeout exceeds the 60s CloudFront accepts
76
- * without a quota increase, which it would reject at deploy. Neither construct
77
- * takes a higher, quota-raised value.
85
+ * Throws when the origin read timeout exceeds {@link MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT},
86
+ * so a configuration the editor's deadline cannot cover fails at synth, not mid-deploy.
78
87
  */
79
88
  export function assertOriginReadTimeout(readTimeout, owner) {
80
- if (readTimeout.toSeconds() > MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT.toSeconds()) {
81
- throw new Error(`${owner}: originReadTimeout is ${readTimeout.toSeconds()}s, but CloudFront ` +
82
- `allows at most ${MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT.toSeconds()}s without a service-quota ` +
83
- `increase, and these constructs do not take a higher value. Lower the CMS Lambda's ` +
84
- `timeout to ${MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT.toSeconds()}s or less. A shorter origin ` +
85
- `timeout than the Lambda's would 504 at the edge on requests that actually succeed.`);
89
+ const max = MAX_CLOUDFRONT_ORIGIN_READ_TIMEOUT.toSeconds();
90
+ if (readTimeout.toSeconds() > max) {
91
+ throw new Error(`${owner}: originReadTimeout is ${readTimeout.toSeconds()}s, but these constructs ` +
92
+ `support at most ${max}s, CloudFront's default quota for "Response timeout per ` +
93
+ `origin" (Service Quotas > CloudFront). Raising that quota does not lift this ` +
94
+ `limit: the editor's request deadline is set just above ${max}s. Lower the CMS ` +
95
+ `Lambda's timeout to ${max}s or less. A shorter origin timeout than the Lambda's ` +
96
+ `would 504 at the edge on requests that actually succeed.`);
86
97
  }
87
98
  }
88
99
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canopycms-cdk",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "AWS CDK constructs and EC2 worker for CanopyCMS deployment",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "peerDependencies": {
35
35
  "aws-cdk-lib": "^2.260.0",
36
36
  "constructs": "^10.0.0",
37
- "canopycms": "0.5.0"
37
+ "canopycms": "0.7.0"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "aws-cdk-lib": {
@@ -60,8 +60,8 @@
60
60
  "tsx": "^4.19.0",
61
61
  "typescript": "^5.6.3",
62
62
  "vitest": "^4.1.0",
63
- "canopycms": "0.5.0",
64
- "canopycms-auth-clerk": "0.5.0"
63
+ "canopycms": "0.7.0",
64
+ "canopycms-auth-clerk": "0.7.0"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "rm -rf dist && tsc && node ../../scripts/add-js-extensions.mjs dist",