@ts-cloud/core 0.16.15 → 0.16.17
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.js +136 -136
- package/dist/modules/cdn-failover.d.ts +97 -0
- package/dist/modules/cdn.d.ts +36 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/types.d.ts +120 -0
- package/package.json +2 -2
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CloudFront origin failover (origin groups).
|
|
3
|
+
*
|
|
4
|
+
* An origin group pairs a primary origin with a secondary one. On a cache miss
|
|
5
|
+
* CloudFront asks the primary; when the primary returns one of the configured
|
|
6
|
+
* status codes, or cannot be reached (503) or times out (504), CloudFront
|
|
7
|
+
* retries the same request against the secondary.
|
|
8
|
+
*
|
|
9
|
+
* These are pure builders: they produce the `OriginGroups` block and check the
|
|
10
|
+
* constraints CloudFront enforces, so every distribution builder in ts-cloud
|
|
11
|
+
* emits the same shape. The block is identical in a CloudFormation
|
|
12
|
+
* `AWS::CloudFront::Distribution` and in the CloudFront API's
|
|
13
|
+
* `DistributionConfig`:
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* OriginGroups: {
|
|
17
|
+
* Quantity: 1,
|
|
18
|
+
* Items: [{
|
|
19
|
+
* Id,
|
|
20
|
+
* FailoverCriteria: { StatusCodes: { Quantity, Items: [500, 502, ...] } },
|
|
21
|
+
* Members: { Quantity: 2, Items: [{ OriginId: primary }, { OriginId: secondary }] },
|
|
22
|
+
* }],
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html
|
|
27
|
+
* @experimental Built against the AWS documentation; not yet exercised against a live distribution.
|
|
28
|
+
*/
|
|
29
|
+
/** Every status code CloudFront accepts as a failover criterion. */
|
|
30
|
+
export declare const CLOUDFRONT_FAILOVER_STATUS_CODES: readonly number[];
|
|
31
|
+
/** Server-side failures: what ts-cloud fails over on when no codes are given. */
|
|
32
|
+
export declare const DEFAULT_FAILOVER_STATUS_CODES: readonly number[];
|
|
33
|
+
/**
|
|
34
|
+
* The only methods a cache behavior may allow when it targets an origin group.
|
|
35
|
+
* CloudFront never fails over a write, so a behavior that accepts writes cannot
|
|
36
|
+
* point at a group.
|
|
37
|
+
*/
|
|
38
|
+
export declare const ORIGIN_GROUP_ALLOWED_METHODS: readonly string[];
|
|
39
|
+
/** Suffix appended to the primary origin id to name its origin group. */
|
|
40
|
+
export declare const ORIGIN_GROUP_ID_SUFFIX = "-failover-group";
|
|
41
|
+
export interface OriginGroupOptions {
|
|
42
|
+
/** Id of the origin CloudFront asks first. */
|
|
43
|
+
primaryOriginId: string;
|
|
44
|
+
/** Id of the origin CloudFront retries against when the primary fails. */
|
|
45
|
+
secondaryOriginId: string;
|
|
46
|
+
/** Status codes from the primary that trigger failover. @default [500, 502, 503, 504] */
|
|
47
|
+
statusCodes?: readonly number[];
|
|
48
|
+
/** Origin group id, which cache behaviors use as their `TargetOriginId`. @default `<primaryOriginId>-failover-group` */
|
|
49
|
+
groupId?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface CloudFrontOriginGroup {
|
|
52
|
+
Id: string;
|
|
53
|
+
FailoverCriteria: {
|
|
54
|
+
StatusCodes: {
|
|
55
|
+
Quantity: number;
|
|
56
|
+
Items: number[];
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
Members: {
|
|
60
|
+
Quantity: number;
|
|
61
|
+
Items: Array<{
|
|
62
|
+
OriginId: string;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export interface CloudFrontOriginGroups {
|
|
67
|
+
Quantity: number;
|
|
68
|
+
Items: CloudFrontOriginGroup[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validate failover status codes and return them deduplicated and sorted.
|
|
72
|
+
* With no codes, returns {@link DEFAULT_FAILOVER_STATUS_CODES}.
|
|
73
|
+
*
|
|
74
|
+
* @throws when the list is empty or holds a code CloudFront does not accept.
|
|
75
|
+
*/
|
|
76
|
+
export declare function resolveFailoverStatusCodes(statusCodes?: readonly number[]): number[];
|
|
77
|
+
/** Build one origin group (primary first, secondary second). */
|
|
78
|
+
export declare function buildOriginGroup(options: OriginGroupOptions): CloudFrontOriginGroup;
|
|
79
|
+
/** Build a distribution's `OriginGroups` block holding a single failover group. */
|
|
80
|
+
export declare function buildOriginGroups(options: OriginGroupOptions): CloudFrontOriginGroups;
|
|
81
|
+
/**
|
|
82
|
+
* Throw unless a cache behavior that targets an origin group allows only
|
|
83
|
+
* GET, HEAD and OPTIONS.
|
|
84
|
+
*
|
|
85
|
+
* Accepts either the CloudFormation form (`['GET', 'HEAD']`) or the CloudFront
|
|
86
|
+
* API form (`{ Quantity, Items: [...] }`) of `AllowedMethods`.
|
|
87
|
+
*
|
|
88
|
+
* @param where Names the behavior in the error, e.g. `the default cache behavior`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function assertOriginGroupMethods(allowedMethods: readonly string[] | {
|
|
91
|
+
Items?: readonly string[];
|
|
92
|
+
} | undefined, where?: string): void;
|
|
93
|
+
/**
|
|
94
|
+
* Whether a domain is an S3 REST endpoint (and so takes an `S3OriginConfig`).
|
|
95
|
+
* S3 *website* endpoints only speak HTTP and are custom origins.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isS3RestEndpoint(domainName: string): boolean;
|
package/dist/modules/cdn.d.ts
CHANGED
|
@@ -11,6 +11,30 @@ export interface DistributionOptions {
|
|
|
11
11
|
edgeFunctions?: EdgeFunctionConfig[];
|
|
12
12
|
http3?: boolean;
|
|
13
13
|
comment?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Secondary origin CloudFront fails over to when the primary errors.
|
|
16
|
+
* Adds an origin group and points the default cache behavior at it.
|
|
17
|
+
* @experimental See {@link CDN.addOriginFailover}.
|
|
18
|
+
*/
|
|
19
|
+
failoverOrigin?: FailoverOriginConfig;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Secondary origin for CloudFront origin failover.
|
|
23
|
+
* @experimental Built against the AWS documentation; not yet exercised against a live distribution.
|
|
24
|
+
*/
|
|
25
|
+
export interface FailoverOriginConfig {
|
|
26
|
+
/** Domain of the secondary origin, e.g. a replica bucket in another region. */
|
|
27
|
+
domainName: string;
|
|
28
|
+
/** Origin kind. @default 's3' for an S3 REST endpoint, otherwise 'custom' */
|
|
29
|
+
type?: 's3' | 'alb' | 'custom';
|
|
30
|
+
/** Origin id for the secondary. @default 'FailoverOrigin' */
|
|
31
|
+
id?: string;
|
|
32
|
+
originPath?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Primary-origin status codes that trigger failover. Allowed: 400, 403, 404,
|
|
35
|
+
* 416, 429, 500, 502, 503, 504. @default [500, 502, 503, 504]
|
|
36
|
+
*/
|
|
37
|
+
statusCodes?: number[];
|
|
14
38
|
}
|
|
15
39
|
export interface OriginConfig {
|
|
16
40
|
type?: 's3' | 'alb' | 'custom';
|
|
@@ -48,6 +72,18 @@ export declare class CDN {
|
|
|
48
72
|
originAccessControl?: CloudFrontOriginAccessControl;
|
|
49
73
|
logicalId: string;
|
|
50
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Add CloudFront origin failover to a distribution: append the secondary
|
|
77
|
+
* origin, group it with the default cache behavior's current origin, and
|
|
78
|
+
* point that behavior at the group.
|
|
79
|
+
*
|
|
80
|
+
* CloudFront only fails over GET, HEAD and OPTIONS, and rejects an origin
|
|
81
|
+
* group behind a cache behavior that allows writes, so this throws if the
|
|
82
|
+
* default cache behavior allows any other method.
|
|
83
|
+
*
|
|
84
|
+
* @experimental Built against the AWS documentation; not yet exercised against a live distribution.
|
|
85
|
+
*/
|
|
86
|
+
static addOriginFailover(distribution: CloudFrontDistribution, failover: FailoverOriginConfig): CloudFrontDistribution;
|
|
51
87
|
/**
|
|
52
88
|
* Set custom domain on a distribution
|
|
53
89
|
*/
|
package/dist/modules/index.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -3145,6 +3145,107 @@ export interface ComputeConfig {
|
|
|
3145
3145
|
* simple as adding an entry here and redeploying.
|
|
3146
3146
|
*/
|
|
3147
3147
|
sshKeys?: SshKeyConfig[];
|
|
3148
|
+
/**
|
|
3149
|
+
* Bounded disk retention on box hosts (Hetzner and ssh providers, and AWS
|
|
3150
|
+
* EC2 boxes deployed over SSM).
|
|
3151
|
+
*
|
|
3152
|
+
* ts-cloud prunes what it leaves behind on a box: abandoned upload staging,
|
|
3153
|
+
* the release artifact cache, the Bun download cache, journald, unused
|
|
3154
|
+
* container images and the apt cache. Current and rollback releases are never
|
|
3155
|
+
* touched; `keepReleases` governs those. The cleanup runs after every deploy,
|
|
3156
|
+
* after a failed one, and on a systemd timer, so a box that stops deploying
|
|
3157
|
+
* still cleans. It reads root-filesystem usage first: below
|
|
3158
|
+
* `pressure.lowWaterPercent` it skips the expensive rules, and at or above
|
|
3159
|
+
* `pressure.highWaterPercent` it prunes on shorter windows and warns.
|
|
3160
|
+
*
|
|
3161
|
+
* Omit for the defaults. `false` turns the whole mechanism off, including a
|
|
3162
|
+
* timer an earlier deploy installed.
|
|
3163
|
+
*/
|
|
3164
|
+
hostCleanup?: boolean | ComputeHostCleanupConfig;
|
|
3165
|
+
}
|
|
3166
|
+
/**
|
|
3167
|
+
* Retention windows for {@link ComputeConfig.hostCleanup}. Each field is an age
|
|
3168
|
+
* past which the matching files are deleted; omit one to keep its default.
|
|
3169
|
+
*/
|
|
3170
|
+
export interface HostCleanupRetention {
|
|
3171
|
+
/**
|
|
3172
|
+
* Abandoned upload staging (`/var/ts-cloud/staging`, `/tmp/*-release.tar.gz`).
|
|
3173
|
+
* Doubles as the in-flight bound for a concurrent deploy, so it cannot go
|
|
3174
|
+
* below 15. @default 60
|
|
3175
|
+
*/
|
|
3176
|
+
stagingMaxAgeMinutes?: number;
|
|
3177
|
+
/** Completed `*.tar.gz` in the release artifact cache, `-mtime` days. @default 2 */
|
|
3178
|
+
artifactMaxAgeDays?: number;
|
|
3179
|
+
/**
|
|
3180
|
+
* `.tmp` uploads to the artifact cache stranded by a dropped transfer. An
|
|
3181
|
+
* upload in flight is younger than this, so it cannot go below 15. @default 60
|
|
3182
|
+
*/
|
|
3183
|
+
artifactUploadMaxAgeMinutes?: number;
|
|
3184
|
+
/** Bun's install (download) cache, `-mtime` days. @default 7 */
|
|
3185
|
+
bunCacheMaxAgeDays?: number;
|
|
3186
|
+
/** journald retention by age. @default 14 */
|
|
3187
|
+
journalMaxAgeDays?: number;
|
|
3188
|
+
/** journald retention by size. @default 512 */
|
|
3189
|
+
journalMaxSizeMb?: number;
|
|
3190
|
+
/** Unused docker/podman images, by age. @default 168 */
|
|
3191
|
+
containerImageMaxAgeHours?: number;
|
|
3192
|
+
}
|
|
3193
|
+
/** How host cleanup reacts to a filling disk. See {@link ComputeHostCleanupConfig.pressure}. */
|
|
3194
|
+
export interface HostCleanupPressureConfig {
|
|
3195
|
+
/**
|
|
3196
|
+
* Below this root-filesystem usage the cleanup runs only the cheap rules
|
|
3197
|
+
* (staging, artifacts, journald, registered paths) and skips the Bun cache
|
|
3198
|
+
* walk, image prunes and `apt-get clean`. `0` always runs everything.
|
|
3199
|
+
* @default 50
|
|
3200
|
+
*/
|
|
3201
|
+
lowWaterPercent?: number;
|
|
3202
|
+
/**
|
|
3203
|
+
* At or above this usage the cleanup prunes with {@link escalated} windows,
|
|
3204
|
+
* prints a warning, and notifies the on-box notifier if it is still above
|
|
3205
|
+
* after cleaning. @default 85
|
|
3206
|
+
*/
|
|
3207
|
+
highWaterPercent?: number;
|
|
3208
|
+
/**
|
|
3209
|
+
* Windows used at or above the high-water mark. Never looser than the normal
|
|
3210
|
+
* ones: each field is the smaller of the two.
|
|
3211
|
+
* @default { artifactMaxAgeDays: 0, bunCacheMaxAgeDays: 1, journalMaxAgeDays: 3, journalMaxSizeMb: 256, containerImageMaxAgeHours: 24 }
|
|
3212
|
+
*/
|
|
3213
|
+
escalated?: HostCleanupRetention;
|
|
3214
|
+
}
|
|
3215
|
+
/**
|
|
3216
|
+
* A directory another component writes timestamped files into, pruned by the
|
|
3217
|
+
* same cleanup on the same schedule. Only direct children of `path` whose name
|
|
3218
|
+
* matches `pattern` are candidates, and only on the same filesystem.
|
|
3219
|
+
*/
|
|
3220
|
+
export interface HostCleanupPathRule {
|
|
3221
|
+
/** Absolute directory, e.g. `/root/rpx-backups`. Not `/`, and not under `/var/www`. */
|
|
3222
|
+
path: string;
|
|
3223
|
+
/** `find -name` glob for the entries to prune, e.g. `cert-backup-*`. */
|
|
3224
|
+
pattern: string;
|
|
3225
|
+
/** Delete entries older than this many days (`-mtime`). */
|
|
3226
|
+
maxAgeDays: number;
|
|
3227
|
+
/** Prune matching files, or matching directories with their contents. @default 'file' */
|
|
3228
|
+
type?: 'file' | 'directory';
|
|
3229
|
+
}
|
|
3230
|
+
/** Host cleanup settings. See {@link ComputeConfig.hostCleanup}. */
|
|
3231
|
+
export interface ComputeHostCleanupConfig {
|
|
3232
|
+
/**
|
|
3233
|
+
* Install the `ts-cloud-host-cleanup.timer` systemd timer, so cleanup runs on
|
|
3234
|
+
* a schedule rather than only when something deploys. `false` removes a timer
|
|
3235
|
+
* an earlier deploy installed and keeps the deploy-time run. @default true
|
|
3236
|
+
*/
|
|
3237
|
+
timer?: boolean;
|
|
3238
|
+
/** systemd `OnCalendar=` expression for the timer. @default 'daily' */
|
|
3239
|
+
schedule?: string;
|
|
3240
|
+
/** Retention windows; omit a field to keep its default. */
|
|
3241
|
+
retention?: HostCleanupRetention;
|
|
3242
|
+
/**
|
|
3243
|
+
* Disk-pressure thresholds. `false` runs every rule with the normal windows
|
|
3244
|
+
* regardless of usage, as ts-cloud did before the thresholds existed.
|
|
3245
|
+
*/
|
|
3246
|
+
pressure?: boolean | HostCleanupPressureConfig;
|
|
3247
|
+
/** Extra directories to prune, e.g. a proxy's own backups. */
|
|
3248
|
+
paths?: HostCleanupPathRule[];
|
|
3148
3249
|
}
|
|
3149
3250
|
/** An operator SSH key authorized on the box. See {@link ComputeConfig.sshKeys}. */
|
|
3150
3251
|
export interface SshKeyConfig {
|
|
@@ -4129,6 +4230,25 @@ export interface CdnItemConfig {
|
|
|
4129
4230
|
originShield?: boolean;
|
|
4130
4231
|
/** AWS region used by Origin Shield. Defaults to the deployment region. */
|
|
4131
4232
|
originShieldRegion?: string;
|
|
4233
|
+
/**
|
|
4234
|
+
* Secondary origin CloudFront fails over to when {@link origin} errors,
|
|
4235
|
+
* e.g. a replica bucket in another region. Adds a CloudFront origin group
|
|
4236
|
+
* (primary + this origin) and serves the default cache behavior from it.
|
|
4237
|
+
* CloudFront only fails over GET, HEAD and OPTIONS requests. An S3 REST
|
|
4238
|
+
* endpoint becomes an S3 origin; any other host an HTTPS-only custom origin.
|
|
4239
|
+
*
|
|
4240
|
+
* @experimental Generated from the AWS documentation; not yet verified
|
|
4241
|
+
* against a live distribution.
|
|
4242
|
+
*/
|
|
4243
|
+
failoverOrigin?: string;
|
|
4244
|
+
/**
|
|
4245
|
+
* Status codes from {@link origin} that trigger failover to
|
|
4246
|
+
* {@link failoverOrigin}. CloudFront accepts 400, 403, 404, 416, 429, 500,
|
|
4247
|
+
* 502, 503 and 504; anything else throws at template generation.
|
|
4248
|
+
* @default [500, 502, 503, 504]
|
|
4249
|
+
* @experimental
|
|
4250
|
+
*/
|
|
4251
|
+
failoverStatusCodes?: number[];
|
|
4132
4252
|
/**
|
|
4133
4253
|
* Cache policy configuration
|
|
4134
4254
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-cloud/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.17",
|
|
5
5
|
"description": "Core CloudFormation generation library for ts-cloud",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typecheck": "tsc --noEmit"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ts-cloud/aws-types": "0.16.
|
|
34
|
+
"@ts-cloud/aws-types": "0.16.17"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^7.0.2"
|