@ts-cloud/core 0.16.14 → 0.16.16

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.
@@ -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;
@@ -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
  */
@@ -5,6 +5,7 @@
5
5
  export * from './storage';
6
6
  export * from './registry';
7
7
  export * from './cdn';
8
+ export * from './cdn-failover';
8
9
  export * from './dns';
9
10
  export * from './security';
10
11
  export * from './compute';
package/dist/types.d.ts CHANGED
@@ -977,6 +977,39 @@ export interface SharedPathSpec {
977
977
  }
978
978
  /** A shared path: a release-relative path, or {@link SharedPathSpec}. */
979
979
  export type SharedPathEntry = string | SharedPathSpec;
980
+ /**
981
+ * The recurring liveness probe for a ported server-app site: a systemd timer
982
+ * that asks the service for an HTTP response on `127.0.0.1:<port>` and
983
+ * restarts it when it has stopped answering. Every field is optional.
984
+ */
985
+ export interface SiteLivenessConfig {
986
+ /** Path to request. @default the health check path, else '/' */
987
+ path?: string;
988
+ /** Seconds between checks. @default 60 */
989
+ intervalSeconds?: number;
990
+ /** Consecutive failed checks, after the startup grace, before a restart. @default 3 */
991
+ failuresBeforeRestart?: number;
992
+ /**
993
+ * Seconds one check waits for an HTTP response. A slow answer inside this
994
+ * budget is an answer, and counts as alive. @default 10
995
+ */
996
+ timeoutSeconds?: number;
997
+ /**
998
+ * Seconds after a unit (re)starts during which a failed check is not held
999
+ * against it - the equivalent of a Kubernetes startupProbe. Must be longer
1000
+ * than the slowest honest boot: a server that binds its port and then warms
1001
+ * up for minutes is starting, not wedged. `0` disables the grace.
1002
+ * @default 600
1003
+ */
1004
+ startupGraceSeconds?: number;
1005
+ /**
1006
+ * Ceiling on the back-off between consecutive liveness restarts. The second
1007
+ * restart in a row waits at least 5 minutes after the first, and each one
1008
+ * after that doubles, up to this. `0` disables the back-off.
1009
+ * @default 3600
1010
+ */
1011
+ maxBackoffSeconds?: number;
1012
+ }
980
1013
  export interface SiteConfig {
981
1014
  /**
982
1015
  * Directory to deploy.
@@ -1184,6 +1217,19 @@ export interface SiteConfig {
1184
1217
  * exactly that. Leave unset for anything that stops immediately.
1185
1218
  */
1186
1219
  stopTimeout?: string;
1220
+ /**
1221
+ * Recurring liveness probe for a ported server-app site. `Restart=always`
1222
+ * only covers a process that exits; this covers one that is alive and no
1223
+ * longer answering. A unit is never restarted inside its startup grace, and
1224
+ * consecutive restarts back off, so a slow boot cannot turn into a restart
1225
+ * loop.
1226
+ *
1227
+ * Set `false` to opt out, for a service that answers nothing on its port or
1228
+ * one where a restart is more dangerous than an outage.
1229
+ * @default enabled: `healthCheck.path` or '/', every 60s, 10s timeout,
1230
+ * restart after 3 consecutive failures once the unit is 10 minutes old
1231
+ */
1232
+ liveness?: false | SiteLivenessConfig;
1187
1233
  /**
1188
1234
  * SSR only. tar `--exclude` patterns applied when packaging the release
1189
1235
  * tarball. Keep host-specific / heavy paths out of the artifact — most
@@ -4083,6 +4129,25 @@ export interface CdnItemConfig {
4083
4129
  originShield?: boolean;
4084
4130
  /** AWS region used by Origin Shield. Defaults to the deployment region. */
4085
4131
  originShieldRegion?: string;
4132
+ /**
4133
+ * Secondary origin CloudFront fails over to when {@link origin} errors,
4134
+ * e.g. a replica bucket in another region. Adds a CloudFront origin group
4135
+ * (primary + this origin) and serves the default cache behavior from it.
4136
+ * CloudFront only fails over GET, HEAD and OPTIONS requests. An S3 REST
4137
+ * endpoint becomes an S3 origin; any other host an HTTPS-only custom origin.
4138
+ *
4139
+ * @experimental Generated from the AWS documentation; not yet verified
4140
+ * against a live distribution.
4141
+ */
4142
+ failoverOrigin?: string;
4143
+ /**
4144
+ * Status codes from {@link origin} that trigger failover to
4145
+ * {@link failoverOrigin}. CloudFront accepts 400, 403, 404, 416, 429, 500,
4146
+ * 502, 503 and 504; anything else throws at template generation.
4147
+ * @default [500, 502, 503, 504]
4148
+ * @experimental
4149
+ */
4150
+ failoverStatusCodes?: number[];
4086
4151
  /**
4087
4152
  * Cache policy configuration
4088
4153
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ts-cloud/core",
3
3
  "type": "module",
4
- "version": "0.16.14",
4
+ "version": "0.16.16",
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.14"
34
+ "@ts-cloud/aws-types": "0.16.16"
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "^7.0.2"