@ericminassian/platform-core 0.4.1 → 0.5.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/dist/api.d.ts +89 -231
- package/dist/api.js +49 -92
- package/dist/api.js.map +1 -1
- package/dist/config.d.ts +0 -2
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +0 -17
- package/dist/constants.js +0 -17
- package/dist/constants.js.map +1 -1
- package/dist/explore.d.ts +35 -33
- package/dist/explore.js +32 -32
- package/dist/explore.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +1 -1
- package/dist/jobs.js +1 -1
- package/dist/manifest.d.ts +10 -47
- package/dist/manifest.js +7 -15
- package/dist/manifest.js.map +1 -1
- package/dist/naming.d.ts +7 -23
- package/dist/naming.js +7 -23
- package/dist/naming.js.map +1 -1
- package/dist/platform-api.d.ts +3996 -4466
- package/dist/platform-api.js +19 -36
- package/dist/platform-api.js.map +1 -1
- package/dist/runtime-config.d.ts +0 -20
- package/dist/runtime-config.js.map +1 -1
- package/dist/telemetry.d.ts +40 -25
- package/dist/telemetry.js +55 -17
- package/dist/telemetry.js.map +1 -1
- package/dist/web-compute.js +2 -1
- package/dist/web-compute.js.map +1 -1
- package/package.json +1 -1
- package/src/api.ts +57 -110
- package/src/config.ts +0 -2
- package/src/constants.ts +0 -19
- package/src/explore.ts +31 -31
- package/src/index.ts +0 -1
- package/src/jobs.ts +1 -1
- package/src/manifest.ts +15 -48
- package/src/naming.ts +7 -25
- package/src/platform-api.ts +25 -38
- package/src/runtime-config.ts +0 -21
- package/src/telemetry.ts +57 -17
- package/src/web-compute.ts +3 -1
- package/dist/compute.d.ts +0 -52
- package/dist/compute.js +0 -65
- package/dist/compute.js.map +0 -1
- package/src/compute.ts +0 -86
package/src/naming.ts
CHANGED
|
@@ -141,21 +141,6 @@ export const names = {
|
|
|
141
141
|
fit(`${app}--${stage}--${eventType.replace(/[^A-Za-z0-9._-]/g, '_')}`, 64),
|
|
142
142
|
scheduleGroup: (app: string, stage: string) => `${app}--${stage}`,
|
|
143
143
|
schedule: (cronKey: string) => cronKey,
|
|
144
|
-
/**
|
|
145
|
-
* A long-running service's ECS service and task definition family (ECS
|
|
146
|
-
* names are their own namespace, so `worker` can't clash with the Lambda).
|
|
147
|
-
*/
|
|
148
|
-
service: (app: string, stage: string, key: string) => `${app}--${stage}--${key}`,
|
|
149
|
-
serviceLogGroup: (app: string, stage: string, key: string) =>
|
|
150
|
-
`/platform/apps/${app}/${stage}/services/${key}`,
|
|
151
|
-
/** Tag of a service's image for one deployment in the container repository (≤ 103 of ECR's 128 chars). */
|
|
152
|
-
serviceImageTag: (app: string, stage: string, key: string, deploymentId: string) =>
|
|
153
|
-
`${app}--${stage}--${key}--${deploymentId}`,
|
|
154
|
-
/**
|
|
155
|
-
* One-shot schedule, in the stage's schedule group, that stops a preview's
|
|
156
|
-
* service. Cron keys can't contain `--`, so it never clashes with a cron.
|
|
157
|
-
*/
|
|
158
|
-
serviceStopSchedule: (key: string) => `${key}--stop`,
|
|
159
144
|
userPoolClient: (app: string, stage: string) => `${app}--${stage}`,
|
|
160
145
|
/** SES tenant and its configuration set (≤ 64 chars each; the base is ≤ 52). */
|
|
161
146
|
emailTenant: (app: string, stage: string) => `${app}--${stage}`,
|
|
@@ -203,16 +188,6 @@ export const platformNames = {
|
|
|
203
188
|
realtimeApi: 'platform-realtime',
|
|
204
189
|
/** Its Lambda authorizer (signed-in subscribe tokens). */
|
|
205
190
|
realtimeAuthorizer: 'platform-realtime-authorizer',
|
|
206
|
-
/** ECS cluster every stage's containers run in (long-running services). */
|
|
207
|
-
containerCluster: 'platform',
|
|
208
|
-
/** VPC and security group containers run in: public subnets, no NAT, egress only. */
|
|
209
|
-
containerNetwork: 'platform-containers',
|
|
210
|
-
/** ECR repository of every container image the platform builds; tags name app, stage and deployment. */
|
|
211
|
-
containerRepository: 'platform-containers',
|
|
212
|
-
/** Role ECS uses to pull images and ship container logs (the app's code runs as its stage role). */
|
|
213
|
-
containerExecutionRole: 'platform-container-execution',
|
|
214
|
-
/** Role EventBridge Scheduler uses to scale containers (a preview's stop schedule). */
|
|
215
|
-
containerSchedulerRole: 'platform-container-scheduler',
|
|
216
191
|
/** Description of the API's subscribe-only key for `public` stages (how the control plane finds it). */
|
|
217
192
|
realtimePublicKey: 'platform-public-subscribe',
|
|
218
193
|
/** The control plane's own app name (services/control-plane/plat.config.ts), stage prod. */
|
|
@@ -234,6 +209,13 @@ export const platformNames = {
|
|
|
234
209
|
* floor on, and the EventBridge rule that tells the control plane when it goes off.
|
|
235
210
|
*/
|
|
236
211
|
edgeFloorAlarm: 'platform-edge-floor',
|
|
212
|
+
/**
|
|
213
|
+
* The router's access log (CloudFront standard logging, `EDGE_LOG_FIELDS`): its log group, and
|
|
214
|
+
* the name of the delivery source, destination, resource policy and subscription filter that
|
|
215
|
+
* feed it to the telemetry processor.
|
|
216
|
+
*/
|
|
217
|
+
edgeLogGroup: '/platform/edge',
|
|
218
|
+
edgeLogDelivery: 'platform-edge',
|
|
237
219
|
runtimeConfigParameter: '/platform/config/runtime',
|
|
238
220
|
sessionKeyParameter: '/platform/config/session-key',
|
|
239
221
|
githubAppParameterPrefix: '/platform/config/github-app/',
|
package/src/platform-api.ts
CHANGED
|
@@ -52,20 +52,19 @@ import {
|
|
|
52
52
|
LogStatsResponse,
|
|
53
53
|
MeResponse,
|
|
54
54
|
MetricsResponse,
|
|
55
|
+
PublicAppsResponse,
|
|
55
56
|
PutSecretRequest,
|
|
56
57
|
QueueStats,
|
|
57
58
|
RealtimeStatsResponse,
|
|
59
|
+
type RepoVisibility,
|
|
58
60
|
RollbackRequest,
|
|
59
61
|
RollbackResponse,
|
|
60
62
|
RouteStats,
|
|
61
63
|
SecretsResponse,
|
|
62
64
|
SeriesResponse,
|
|
63
|
-
ServiceActionResponse,
|
|
64
|
-
ServicesResponse,
|
|
65
65
|
StageDestroyed,
|
|
66
66
|
StageDestroying,
|
|
67
67
|
StageRecord,
|
|
68
|
-
StartServiceRequest,
|
|
69
68
|
StorageResponse,
|
|
70
69
|
SuppressedResponse,
|
|
71
70
|
TraceResponse,
|
|
@@ -141,7 +140,7 @@ export class NotFound extends Schema.TaggedError<NotFound, { readonly brand: uni
|
|
|
141
140
|
|
|
142
141
|
/**
|
|
143
142
|
* 409: `exists`, `dns_conflict`, `has_stages`, `already_started`, `rollback_failed`,
|
|
144
|
-
* `redrive_failed`, `discard_failed`, `paused_by_aws
|
|
143
|
+
* `redrive_failed`, `discard_failed`, `paused_by_aws`.
|
|
145
144
|
*/
|
|
146
145
|
export class Conflict extends Schema.TaggedError<Conflict, { readonly brand: unique symbol }>()(
|
|
147
146
|
'Conflict',
|
|
@@ -213,6 +212,8 @@ export interface CiPrincipal {
|
|
|
213
212
|
readonly sha?: string | undefined;
|
|
214
213
|
readonly actor?: string | undefined;
|
|
215
214
|
readonly runId?: string | undefined;
|
|
215
|
+
/** The repository's visibility when the token was minted. */
|
|
216
|
+
readonly repositoryVisibility?: RepoVisibility | undefined;
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
export type Principal = MemberPrincipal | CiPrincipal;
|
|
@@ -273,6 +274,23 @@ export class SessionApi extends HttpApiGroup.make('session').add(
|
|
|
273
274
|
HttpApiEndpoint.get('me', '/me', { success: MeResponse, error: errors }).middleware(Authenticated),
|
|
274
275
|
) {}
|
|
275
276
|
|
|
277
|
+
/**
|
|
278
|
+
* What anyone may read, without signing in: the public directory. Pages on
|
|
279
|
+
* any site may fetch it from the browser (`Access-Control-Allow-Origin: *`;
|
|
280
|
+
* it carries no credentials), and the router caches it
|
|
281
|
+
* (`PUBLIC_CACHE_CONTROL`), so readers rarely wake the control plane.
|
|
282
|
+
*/
|
|
283
|
+
export class PublicApi extends HttpApiGroup.make('public').add(
|
|
284
|
+
HttpApiEndpoint.get('apps', '/public/apps', { success: PublicAppsResponse, error: errors }),
|
|
285
|
+
) {}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* How long browsers and the router keep the public directory: a page that
|
|
289
|
+
* fetches it live is a few minutes behind at most, and the control plane
|
|
290
|
+
* answers each edge location at most every five minutes.
|
|
291
|
+
*/
|
|
292
|
+
export const PUBLIC_CACHE_CONTROL = 'public, max-age=60, s-maxage=300';
|
|
293
|
+
|
|
276
294
|
export class AppsApi extends HttpApiGroup.make('apps')
|
|
277
295
|
.add(
|
|
278
296
|
HttpApiEndpoint.get('list', '/apps', { success: Schema.Array(AppSummary), error: errors }),
|
|
@@ -420,13 +438,6 @@ export class ObserveApi extends HttpApiGroup.make('observe')
|
|
|
420
438
|
success: LimitsResponse,
|
|
421
439
|
error: errors,
|
|
422
440
|
}),
|
|
423
|
-
/** The stage's long-running services: ECS state, CPU and memory, starts and failed runs. */
|
|
424
|
-
HttpApiEndpoint.get('services', '/apps/:app/services', {
|
|
425
|
-
params: app,
|
|
426
|
-
query: rangeQuery,
|
|
427
|
-
success: ServicesResponse,
|
|
428
|
-
error: errors,
|
|
429
|
-
}),
|
|
430
441
|
HttpApiEndpoint.get('errors', '/apps/:app/errors', {
|
|
431
442
|
params: app,
|
|
432
443
|
query: { ...stageQuery, status: Schema.optional(ErrorStatus) },
|
|
@@ -458,7 +469,7 @@ export class ObserveApi extends HttpApiGroup.make('observe')
|
|
|
458
469
|
query: {
|
|
459
470
|
...rangeQuery,
|
|
460
471
|
q: Schema.optional(Schema.String),
|
|
461
|
-
/** `web
|
|
472
|
+
/** `web` or `worker`. */
|
|
462
473
|
stream: Schema.optional(Schema.String),
|
|
463
474
|
/** Structured filters as JSON (`LogFilters`); any of them runs the search on Logs Insights. */
|
|
464
475
|
f: Schema.optional(Schema.fromJsonString(LogFilters)),
|
|
@@ -478,7 +489,7 @@ export class ObserveApi extends HttpApiGroup.make('observe')
|
|
|
478
489
|
query: {
|
|
479
490
|
...stageQuery,
|
|
480
491
|
q: Schema.optional(Schema.String),
|
|
481
|
-
/** `web
|
|
492
|
+
/** `web` or `worker`. */
|
|
482
493
|
stream: Schema.optional(Schema.String),
|
|
483
494
|
/** Structured filters as JSON (`LogFilters`), applied to the live lines. */
|
|
484
495
|
f: Schema.optional(Schema.fromJsonString(LogFilters)),
|
|
@@ -676,31 +687,6 @@ export class ManageApi extends HttpApiGroup.make('manage')
|
|
|
676
687
|
success: EmailSending,
|
|
677
688
|
error: errors,
|
|
678
689
|
}),
|
|
679
|
-
/** Replaces the service's task with a fresh one on the same build. */
|
|
680
|
-
HttpApiEndpoint.post('restartService', '/apps/:app/services/:name/restart', {
|
|
681
|
-
params: { ...app, name: Schema.String },
|
|
682
|
-
query: stageQuery,
|
|
683
|
-
success: ServiceActionResponse.pipe(HttpApiSchema.status(202)),
|
|
684
|
-
error: errors,
|
|
685
|
-
}),
|
|
686
|
-
/**
|
|
687
|
-
* Runs it (desired 1). It stops again after `minutes` when given; on
|
|
688
|
-
* previews always, by default after its `previewMinutes` (30 when that is 0).
|
|
689
|
-
*/
|
|
690
|
-
HttpApiEndpoint.post('startService', '/apps/:app/services/:name/start', {
|
|
691
|
-
params: { ...app, name: Schema.String },
|
|
692
|
-
query: stageQuery,
|
|
693
|
-
payload: StartServiceRequest,
|
|
694
|
-
success: ServiceActionResponse.pipe(HttpApiSchema.status(202)),
|
|
695
|
-
error: errors,
|
|
696
|
-
}),
|
|
697
|
-
/** Scales it to zero until it is started again or the stage is redeployed. */
|
|
698
|
-
HttpApiEndpoint.post('stopService', '/apps/:app/services/:name/stop', {
|
|
699
|
-
params: { ...app, name: Schema.String },
|
|
700
|
-
query: stageQuery,
|
|
701
|
-
success: ServiceActionResponse.pipe(HttpApiSchema.status(202)),
|
|
702
|
-
error: errors,
|
|
703
|
-
}),
|
|
704
690
|
/** Runs dead letters again from their first attempt, on the function their handler runs in now. */
|
|
705
691
|
HttpApiEndpoint.post('redrive', '/apps/:app/dead-letters/redrive', {
|
|
706
692
|
params: app,
|
|
@@ -733,6 +719,7 @@ export class AdminApi extends HttpApiGroup.make('admin')
|
|
|
733
719
|
|
|
734
720
|
export class PlatformApi extends HttpApi.make('platform')
|
|
735
721
|
.add(SessionApi)
|
|
722
|
+
.add(PublicApi)
|
|
736
723
|
.add(AppsApi)
|
|
737
724
|
.add(StagesApi)
|
|
738
725
|
.add(DeploymentsApi)
|
package/src/runtime-config.ts
CHANGED
|
@@ -44,27 +44,6 @@ export interface PlatformRuntimeConfig {
|
|
|
44
44
|
realtime?: RealtimeRuntimeConfig;
|
|
45
45
|
/** The SES domain every stage sends from (absent on platforms that predate email). */
|
|
46
46
|
email?: EmailRuntimeConfig;
|
|
47
|
-
/** Container compute, ECS on Fargate (absent on platforms that predate it). */
|
|
48
|
-
containers?: ContainersRuntimeConfig;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Where containers run. Tasks get a public IPv4 address in a public subnet
|
|
53
|
-
* (there is no NAT gateway) and accept no inbound traffic.
|
|
54
|
-
*/
|
|
55
|
-
export interface ContainersRuntimeConfig {
|
|
56
|
-
/** ECS cluster name. */
|
|
57
|
-
cluster: string;
|
|
58
|
-
subnets: string[];
|
|
59
|
-
securityGroups: string[];
|
|
60
|
-
/** ECR repository name. */
|
|
61
|
-
repository: string;
|
|
62
|
-
/** `<account>.dkr.ecr.<region>.amazonaws.com/<repository>`. */
|
|
63
|
-
repositoryUri: string;
|
|
64
|
-
/** Pulls images and writes container logs. */
|
|
65
|
-
executionRoleArn: string;
|
|
66
|
-
/** Assumed by EventBridge Scheduler to scale a stage's services (preview stop schedules). */
|
|
67
|
-
schedulerRoleArn: string;
|
|
68
47
|
}
|
|
69
48
|
|
|
70
49
|
/**
|
package/src/telemetry.ts
CHANGED
|
@@ -62,8 +62,7 @@ export type RequestEvent = typeof RequestEvent.Type;
|
|
|
62
62
|
export const ErrorEvent = Schema.Struct({
|
|
63
63
|
...base,
|
|
64
64
|
t: Schema.Literal('err'),
|
|
65
|
-
|
|
66
|
-
source: Schema.Literals(['http', 'job', 'unhandled', 'log', 'service']),
|
|
65
|
+
source: Schema.Literals(['http', 'job', 'unhandled', 'log']),
|
|
67
66
|
name: Schema.String,
|
|
68
67
|
message: Schema.String,
|
|
69
68
|
stack: Schema.optional(Schema.String),
|
|
@@ -73,15 +72,11 @@ export const ErrorEvent = Schema.Struct({
|
|
|
73
72
|
});
|
|
74
73
|
export type ErrorEvent = typeof ErrorEvent.Type;
|
|
75
74
|
|
|
76
|
-
/**
|
|
77
|
-
* One unit of work. `service` jobs come from long-running services: `<service>`
|
|
78
|
-
* is a run of the service that ended (it is rerun; `dur` is how long it ran),
|
|
79
|
-
* `<service>/<unit>` a unit of work it marked with `traced`.
|
|
80
|
-
*/
|
|
75
|
+
/** One unit of work. */
|
|
81
76
|
export const JobEvent = Schema.Struct({
|
|
82
77
|
...base,
|
|
83
78
|
t: Schema.Literal('job'),
|
|
84
|
-
kind: Schema.Literals(['queue', 'event', 'cron', 'invoke'
|
|
79
|
+
kind: Schema.Literals(['queue', 'event', 'cron', 'invoke']),
|
|
85
80
|
name: Schema.String,
|
|
86
81
|
status: Schema.Literals(['ok', 'error']),
|
|
87
82
|
dur: Schema.Finite,
|
|
@@ -141,21 +136,17 @@ export const LimitEvent = Schema.Struct({
|
|
|
141
136
|
});
|
|
142
137
|
export type LimitEvent = typeof LimitEvent.Type;
|
|
143
138
|
|
|
144
|
-
/** A runtime process starting or stopping
|
|
139
|
+
/** A runtime process starting or stopping. */
|
|
145
140
|
export const EnvEvent = Schema.Struct({
|
|
146
141
|
...base,
|
|
147
142
|
t: Schema.Literal('env'),
|
|
148
143
|
event: Schema.Literals(['start', 'stop']),
|
|
149
|
-
runtime: Schema.Literals(['web', 'worker'
|
|
144
|
+
runtime: Schema.Literals(['web', 'worker']),
|
|
150
145
|
/**
|
|
151
146
|
* How a deployed server runs (`runtime: 'web'`): `request`, a function per
|
|
152
147
|
* request, or `instance`, a Web Function environment. Absent under `plat dev`.
|
|
153
148
|
*/
|
|
154
149
|
compute: Schema.optional(Schema.Literals(['request', 'instance'])),
|
|
155
|
-
/** The service's name (`runtime: 'service'`). */
|
|
156
|
-
name: Schema.optional(Schema.String),
|
|
157
|
-
/** Why it stopped, e.g. `SIGTERM`. */
|
|
158
|
-
reason: Schema.optional(Schema.String),
|
|
159
150
|
initMs: Schema.optional(Schema.Finite),
|
|
160
151
|
});
|
|
161
152
|
export type EnvEvent = typeof EnvEvent.Type;
|
|
@@ -266,15 +257,19 @@ export function bucketStart(ts: number, res: Resolution): number {
|
|
|
266
257
|
* - `m#<app>#<stage>#<res>` sk `<iso>` whole-stage HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[], cold,
|
|
267
258
|
* dur (ms handling them, summed), and process starts:
|
|
268
259
|
* webStarts (webInits of them reported webInitMs, summed),
|
|
269
|
-
* workerStarts
|
|
260
|
+
* workerStarts
|
|
270
261
|
* - `r#<app>#<stage>#<res>` sk `<iso>#<METHOD> <route>` per-route HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[],
|
|
271
262
|
* cold, method, route. Rows from before November 2026 have no
|
|
272
263
|
* s2xx, s3xx or cold: their req − s4xx − s5xx were 2xx
|
|
273
|
-
* - `j#<app>#<stage>#<res>` sk `<iso>#<kind>:<name>` jobs: ok, error, lat[]
|
|
274
|
-
* count `starts` (containers of that service starting)
|
|
264
|
+
* - `j#<app>#<stage>#<res>` sk `<iso>#<kind>:<name>` jobs: ok, error, lat[]
|
|
275
265
|
* - `c#<app>#<stage>#<res>` sk `<iso>#<metric>` custom metrics: count, sum, max (and the unit); rows from
|
|
276
266
|
* before November 2026 have no max
|
|
277
267
|
* - `l#<app>#<stage>#<res>` sk `<iso>#<limit>` rate limit checks: allowed, denied
|
|
268
|
+
* - `v#<app>#<stage>#<res>` sk `<iso>` edge traffic from the router's access log, every
|
|
269
|
+
* request to the stage's host (files, server,
|
|
270
|
+
* stores) but health checks: req, s2xx, s3xx,
|
|
271
|
+
* s4xx, s5xx, and pages (`isPageView`). Since
|
|
272
|
+
* November 2026; written up to an hour late
|
|
278
273
|
* - `e#<app>#<stage>` sk `<fingerprint>` error groups: count, firstSeen, lastSeen, sample, status
|
|
279
274
|
* - `u#<app>#<stage>` sk `<iso>` uptime: ok, source (`traffic`: req, s5xx; `check`, or none on
|
|
280
275
|
* rows before traffic counted: status, ms)
|
|
@@ -287,6 +282,7 @@ export const telemetryKeys = {
|
|
|
287
282
|
job: (app: string, stage: string, res: Resolution) => `j#${app}#${stage}#${res}`,
|
|
288
283
|
metric: (app: string, stage: string, res: Resolution) => `c#${app}#${stage}#${res}`,
|
|
289
284
|
limit: (app: string, stage: string, res: Resolution) => `l#${app}#${stage}#${res}`,
|
|
285
|
+
edge: (app: string, stage: string, res: Resolution) => `v#${app}#${stage}#${res}`,
|
|
290
286
|
errors: (app: string, stage: string) => `e#${app}#${stage}`,
|
|
291
287
|
uptime: (app: string, stage: string) => `u#${app}#${stage}`,
|
|
292
288
|
alerts: (app: string, stage: string) => `a#${app}#${stage}`,
|
|
@@ -298,6 +294,50 @@ export const telemetryKeys = {
|
|
|
298
294
|
time: (ts: number) => new Date(ts).toISOString(),
|
|
299
295
|
} as const;
|
|
300
296
|
|
|
297
|
+
// ---------------------------------------------------------------------------
|
|
298
|
+
// Edge traffic (the router's access log)
|
|
299
|
+
// ---------------------------------------------------------------------------
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* The fields the router's access log carries (CloudFront standard logging,
|
|
303
|
+
* delivered to `platformNames.edgeLogGroup` as one JSON object per request,
|
|
304
|
+
* every value a string). Enough to count requests and page views per host;
|
|
305
|
+
* never the client's address. Each field costs bytes ingested, but CloudFront
|
|
306
|
+
* includes 750 bytes of log delivery per request, which these stay well under.
|
|
307
|
+
*/
|
|
308
|
+
export const EDGE_LOG_FIELDS = [
|
|
309
|
+
'timestamp(ms)',
|
|
310
|
+
'x-host-header',
|
|
311
|
+
'cs-method',
|
|
312
|
+
'cs-uri-stem',
|
|
313
|
+
'sc-status',
|
|
314
|
+
'sc-content-type',
|
|
315
|
+
] as const;
|
|
316
|
+
|
|
317
|
+
/** One access log record, as `EDGE_LOG_FIELDS` deliver it. */
|
|
318
|
+
export const EdgeLogRecord = Schema.Struct({
|
|
319
|
+
'timestamp(ms)': Schema.String,
|
|
320
|
+
'x-host-header': Schema.String,
|
|
321
|
+
'cs-method': Schema.String,
|
|
322
|
+
'cs-uri-stem': Schema.String,
|
|
323
|
+
'sc-status': Schema.String,
|
|
324
|
+
'sc-content-type': Schema.optional(Schema.String),
|
|
325
|
+
});
|
|
326
|
+
export type EdgeLogRecord = typeof EdgeLogRecord.Type;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Whether a request loaded a page: a GET answered with an HTML document, or
|
|
330
|
+
* a 304 for a path that names no file (a page the browser had cached, whose
|
|
331
|
+
* revalidation carries no content type). Assets, API calls and errors aren't.
|
|
332
|
+
*/
|
|
333
|
+
export function isPageView(method: string, uri: string, status: number, contentType: string | undefined) {
|
|
334
|
+
if (method !== 'GET') return false;
|
|
335
|
+
if (status >= 200 && status < 300) return (contentType ?? '').toLowerCase().startsWith('text/html');
|
|
336
|
+
if (status !== 304) return false;
|
|
337
|
+
const last = uri.slice(uri.lastIndexOf('/') + 1);
|
|
338
|
+
return !last.includes('.') || last.endsWith('.html');
|
|
339
|
+
}
|
|
340
|
+
|
|
301
341
|
// ---------------------------------------------------------------------------
|
|
302
342
|
// Error fingerprinting (Sentry-style grouping)
|
|
303
343
|
// ---------------------------------------------------------------------------
|
package/src/web-compute.ts
CHANGED
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
* mode (and back) by `simulateWebCompute`.
|
|
17
17
|
*/
|
|
18
18
|
import { base64url, fromBase64url } from './base64url.ts';
|
|
19
|
-
import { HOURS_PER_MONTH } from './compute.ts';
|
|
20
19
|
import { PROD_STAGE } from './constants.ts';
|
|
21
20
|
|
|
21
|
+
/** Hours AWS bills a month of always-on capacity for. */
|
|
22
|
+
const HOURS_PER_MONTH = 730;
|
|
23
|
+
|
|
22
24
|
export const WEB_COMPUTE = ['request', 'instance'] as const;
|
|
23
25
|
export type WebCompute = (typeof WEB_COMPUTE)[number];
|
|
24
26
|
|
package/dist/compute.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Container compute (ECS on Fargate): the sizes a container may have and
|
|
3
|
-
* what one costs while it runs. Shared by the manifest schema, the engine,
|
|
4
|
-
* the console's cost page and `plat deploy`.
|
|
5
|
-
*/
|
|
6
|
-
/** vCPUs a Fargate task may have (the platform caps it at 4). */
|
|
7
|
-
export declare const FARGATE_CPUS: readonly [0.25, 0.5, 1, 2, 4];
|
|
8
|
-
export type FargateCpu = (typeof FARGATE_CPUS)[number];
|
|
9
|
-
/** Memory (MB) Fargate allows for each vCPU size. */
|
|
10
|
-
export declare function fargateMemoryOptions(cpu: FargateCpu): number[];
|
|
11
|
-
/** Why `cpu`/`memoryMb` isn't a size Fargate runs, or null when it is. */
|
|
12
|
-
export declare function fargateSizeIssue(cpu: number, memoryMb: number): string | null;
|
|
13
|
-
/** ECS task-definition units: 1024 per vCPU. */
|
|
14
|
-
export declare function fargateCpuUnits(cpu: number): number;
|
|
15
|
-
/**
|
|
16
|
-
* Prices behind the estimates: us-east-1, Linux on ARM (Graviton), checked
|
|
17
|
-
* 2026-11-15. Spot prices move with supply and demand, so Spot estimates are
|
|
18
|
-
* approximate. Every task gets a public IPv4 address (there is no NAT), which
|
|
19
|
-
* AWS bills by the hour whatever the capacity.
|
|
20
|
-
*/
|
|
21
|
-
export declare const CONTAINER_PRICES_USD: {
|
|
22
|
-
readonly onDemand: {
|
|
23
|
-
readonly vcpuHour: 0.03238;
|
|
24
|
-
readonly gbHour: 0.00356;
|
|
25
|
-
};
|
|
26
|
-
readonly spot: {
|
|
27
|
-
readonly vcpuHour: 0.00995;
|
|
28
|
-
readonly gbHour: 0.00109;
|
|
29
|
-
};
|
|
30
|
-
readonly publicIpv4Hour: 0.005;
|
|
31
|
-
};
|
|
32
|
-
/** Hours AWS bills a month of always-on capacity for. */
|
|
33
|
-
export declare const HOURS_PER_MONTH = 730;
|
|
34
|
-
export interface ContainerCostEstimate {
|
|
35
|
-
/** vCPU and memory, per month. */
|
|
36
|
-
computeUsd: number;
|
|
37
|
-
/** The task's public IPv4 address, per month. */
|
|
38
|
-
publicIpv4Usd: number;
|
|
39
|
-
totalUsd: number;
|
|
40
|
-
}
|
|
41
|
-
/** What one container of this size costs a month if it runs all the time. */
|
|
42
|
-
export declare function estimateContainerCost(size: {
|
|
43
|
-
cpu: number;
|
|
44
|
-
memoryMb: number;
|
|
45
|
-
spot: boolean;
|
|
46
|
-
}): ContainerCostEstimate;
|
|
47
|
-
/** `0.25 vCPU · 512 MB · Spot`. */
|
|
48
|
-
export declare function describeContainerSize(size: {
|
|
49
|
-
cpu: number;
|
|
50
|
-
memoryMb: number;
|
|
51
|
-
spot: boolean;
|
|
52
|
-
}): string;
|
package/dist/compute.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Container compute (ECS on Fargate): the sizes a container may have and
|
|
3
|
-
* what one costs while it runs. Shared by the manifest schema, the engine,
|
|
4
|
-
* the console's cost page and `plat deploy`.
|
|
5
|
-
*/
|
|
6
|
-
/** vCPUs a Fargate task may have (the platform caps it at 4). */
|
|
7
|
-
export const FARGATE_CPUS = [0.25, 0.5, 1, 2, 4];
|
|
8
|
-
/** Memory (MB) Fargate allows for each vCPU size. */
|
|
9
|
-
export function fargateMemoryOptions(cpu) {
|
|
10
|
-
if (cpu === 0.25)
|
|
11
|
-
return [512, 1024, 2048];
|
|
12
|
-
const [from, to] = MEMORY_RANGES[cpu];
|
|
13
|
-
return Array.from({ length: (to - from) / 1024 + 1 }, (_, i) => from + i * 1024);
|
|
14
|
-
}
|
|
15
|
-
/** Above 0.25 vCPU, memory goes from..to in steps of 1024 MB. */
|
|
16
|
-
const MEMORY_RANGES = {
|
|
17
|
-
0.5: [1024, 4096],
|
|
18
|
-
1: [2048, 8192],
|
|
19
|
-
2: [4096, 16384],
|
|
20
|
-
4: [8192, 30720],
|
|
21
|
-
};
|
|
22
|
-
/** Why `cpu`/`memoryMb` isn't a size Fargate runs, or null when it is. */
|
|
23
|
-
export function fargateSizeIssue(cpu, memoryMb) {
|
|
24
|
-
if (!FARGATE_CPUS.includes(cpu)) {
|
|
25
|
-
return `cpu must be one of ${FARGATE_CPUS.join(', ')}`;
|
|
26
|
-
}
|
|
27
|
-
const options = fargateMemoryOptions(cpu);
|
|
28
|
-
if (options.includes(memoryMb))
|
|
29
|
-
return null;
|
|
30
|
-
const allowed = cpu === 0.25 ? options.join(', ') : `${options[0]}-${options[options.length - 1]} in steps of 1024`;
|
|
31
|
-
return `memoryMb ${memoryMb} doesn't fit ${cpu} vCPU: use ${allowed}`;
|
|
32
|
-
}
|
|
33
|
-
/** ECS task-definition units: 1024 per vCPU. */
|
|
34
|
-
export function fargateCpuUnits(cpu) {
|
|
35
|
-
return Math.round(cpu * 1024);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Prices behind the estimates: us-east-1, Linux on ARM (Graviton), checked
|
|
39
|
-
* 2026-11-15. Spot prices move with supply and demand, so Spot estimates are
|
|
40
|
-
* approximate. Every task gets a public IPv4 address (there is no NAT), which
|
|
41
|
-
* AWS bills by the hour whatever the capacity.
|
|
42
|
-
*/
|
|
43
|
-
export const CONTAINER_PRICES_USD = {
|
|
44
|
-
onDemand: { vcpuHour: 0.03238, gbHour: 0.00356 },
|
|
45
|
-
spot: { vcpuHour: 0.00995, gbHour: 0.00109 },
|
|
46
|
-
publicIpv4Hour: 0.005,
|
|
47
|
-
};
|
|
48
|
-
/** Hours AWS bills a month of always-on capacity for. */
|
|
49
|
-
export const HOURS_PER_MONTH = 730;
|
|
50
|
-
/** What one container of this size costs a month if it runs all the time. */
|
|
51
|
-
export function estimateContainerCost(size) {
|
|
52
|
-
const price = size.spot ? CONTAINER_PRICES_USD.spot : CONTAINER_PRICES_USD.onDemand;
|
|
53
|
-
const hourly = size.cpu * price.vcpuHour + (size.memoryMb / 1024) * price.gbHour;
|
|
54
|
-
const computeUsd = round2(hourly * HOURS_PER_MONTH);
|
|
55
|
-
const publicIpv4Usd = round2(CONTAINER_PRICES_USD.publicIpv4Hour * HOURS_PER_MONTH);
|
|
56
|
-
return { computeUsd, publicIpv4Usd, totalUsd: round2(computeUsd + publicIpv4Usd) };
|
|
57
|
-
}
|
|
58
|
-
/** `0.25 vCPU · 512 MB · Spot`. */
|
|
59
|
-
export function describeContainerSize(size) {
|
|
60
|
-
return `${size.cpu} vCPU · ${size.memoryMb} MB · ${size.spot ? 'Spot' : 'on-demand'}`;
|
|
61
|
-
}
|
|
62
|
-
function round2(n) {
|
|
63
|
-
return Math.round(n * 100) / 100;
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=compute.js.map
|
package/dist/compute.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute.js","sourceRoot":"","sources":["../src/compute.ts"],"names":[],"mappings":"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"}
|
package/src/compute.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Container compute (ECS on Fargate): the sizes a container may have and
|
|
3
|
-
* what one costs while it runs. Shared by the manifest schema, the engine,
|
|
4
|
-
* the console's cost page and `plat deploy`.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/** vCPUs a Fargate task may have (the platform caps it at 4). */
|
|
8
|
-
export const FARGATE_CPUS = [0.25, 0.5, 1, 2, 4] as const;
|
|
9
|
-
export type FargateCpu = (typeof FARGATE_CPUS)[number];
|
|
10
|
-
|
|
11
|
-
/** Memory (MB) Fargate allows for each vCPU size. */
|
|
12
|
-
export function fargateMemoryOptions(cpu: FargateCpu): number[] {
|
|
13
|
-
if (cpu === 0.25) return [512, 1024, 2048];
|
|
14
|
-
const [from, to] = MEMORY_RANGES[cpu];
|
|
15
|
-
return Array.from({ length: (to - from) / 1024 + 1 }, (_, i) => from + i * 1024);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Above 0.25 vCPU, memory goes from..to in steps of 1024 MB. */
|
|
19
|
-
const MEMORY_RANGES: Record<Exclude<FargateCpu, 0.25>, readonly [number, number]> = {
|
|
20
|
-
0.5: [1024, 4096],
|
|
21
|
-
1: [2048, 8192],
|
|
22
|
-
2: [4096, 16384],
|
|
23
|
-
4: [8192, 30720],
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/** Why `cpu`/`memoryMb` isn't a size Fargate runs, or null when it is. */
|
|
27
|
-
export function fargateSizeIssue(cpu: number, memoryMb: number): string | null {
|
|
28
|
-
if (!(FARGATE_CPUS as readonly number[]).includes(cpu)) {
|
|
29
|
-
return `cpu must be one of ${FARGATE_CPUS.join(', ')}`;
|
|
30
|
-
}
|
|
31
|
-
const options = fargateMemoryOptions(cpu as FargateCpu);
|
|
32
|
-
if (options.includes(memoryMb)) return null;
|
|
33
|
-
const allowed =
|
|
34
|
-
cpu === 0.25 ? options.join(', ') : `${options[0]}-${options[options.length - 1]} in steps of 1024`;
|
|
35
|
-
return `memoryMb ${memoryMb} doesn't fit ${cpu} vCPU: use ${allowed}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** ECS task-definition units: 1024 per vCPU. */
|
|
39
|
-
export function fargateCpuUnits(cpu: number): number {
|
|
40
|
-
return Math.round(cpu * 1024);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Prices behind the estimates: us-east-1, Linux on ARM (Graviton), checked
|
|
45
|
-
* 2026-11-15. Spot prices move with supply and demand, so Spot estimates are
|
|
46
|
-
* approximate. Every task gets a public IPv4 address (there is no NAT), which
|
|
47
|
-
* AWS bills by the hour whatever the capacity.
|
|
48
|
-
*/
|
|
49
|
-
export const CONTAINER_PRICES_USD = {
|
|
50
|
-
onDemand: { vcpuHour: 0.03238, gbHour: 0.00356 },
|
|
51
|
-
spot: { vcpuHour: 0.00995, gbHour: 0.00109 },
|
|
52
|
-
publicIpv4Hour: 0.005,
|
|
53
|
-
} as const;
|
|
54
|
-
|
|
55
|
-
/** Hours AWS bills a month of always-on capacity for. */
|
|
56
|
-
export const HOURS_PER_MONTH = 730;
|
|
57
|
-
|
|
58
|
-
export interface ContainerCostEstimate {
|
|
59
|
-
/** vCPU and memory, per month. */
|
|
60
|
-
computeUsd: number;
|
|
61
|
-
/** The task's public IPv4 address, per month. */
|
|
62
|
-
publicIpv4Usd: number;
|
|
63
|
-
totalUsd: number;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** What one container of this size costs a month if it runs all the time. */
|
|
67
|
-
export function estimateContainerCost(size: {
|
|
68
|
-
cpu: number;
|
|
69
|
-
memoryMb: number;
|
|
70
|
-
spot: boolean;
|
|
71
|
-
}): ContainerCostEstimate {
|
|
72
|
-
const price = size.spot ? CONTAINER_PRICES_USD.spot : CONTAINER_PRICES_USD.onDemand;
|
|
73
|
-
const hourly = size.cpu * price.vcpuHour + (size.memoryMb / 1024) * price.gbHour;
|
|
74
|
-
const computeUsd = round2(hourly * HOURS_PER_MONTH);
|
|
75
|
-
const publicIpv4Usd = round2(CONTAINER_PRICES_USD.publicIpv4Hour * HOURS_PER_MONTH);
|
|
76
|
-
return { computeUsd, publicIpv4Usd, totalUsd: round2(computeUsd + publicIpv4Usd) };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** `0.25 vCPU · 512 MB · Spot`. */
|
|
80
|
-
export function describeContainerSize(size: { cpu: number; memoryMb: number; spot: boolean }): string {
|
|
81
|
-
return `${size.cpu} vCPU · ${size.memoryMb} MB · ${size.spot ? 'Spot' : 'on-demand'}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function round2(n: number): number {
|
|
85
|
-
return Math.round(n * 100) / 100;
|
|
86
|
-
}
|