@ericminassian/platform-core 0.2.0 → 0.4.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.
Files changed (89) hide show
  1. package/dist/api.d.ts +1847 -212
  2. package/dist/api.js +694 -1
  3. package/dist/api.js.map +1 -1
  4. package/dist/auth.d.ts +19 -0
  5. package/dist/auth.js +32 -0
  6. package/dist/auth.js.map +1 -1
  7. package/dist/base64url.d.ts +3 -0
  8. package/dist/base64url.js +15 -0
  9. package/dist/base64url.js.map +1 -0
  10. package/dist/bindings.d.ts +69 -13
  11. package/dist/bindings.js +1 -1
  12. package/dist/bindings.js.map +1 -1
  13. package/dist/cloudfront-function.d.ts +5 -1
  14. package/dist/cloudfront-function.js +70 -2
  15. package/dist/cloudfront-function.js.map +1 -1
  16. package/dist/compute.d.ts +52 -0
  17. package/dist/compute.js +65 -0
  18. package/dist/compute.js.map +1 -0
  19. package/dist/config.d.ts +21 -1
  20. package/dist/config.js +16 -0
  21. package/dist/config.js.map +1 -1
  22. package/dist/constants.d.ts +67 -1
  23. package/dist/constants.js +56 -1
  24. package/dist/constants.js.map +1 -1
  25. package/dist/email.d.ts +84 -0
  26. package/dist/email.js +111 -0
  27. package/dist/email.js.map +1 -0
  28. package/dist/fingerprint.d.ts +9 -0
  29. package/dist/fingerprint.js +19 -0
  30. package/dist/fingerprint.js.map +1 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +6 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/jobs.d.ts +111 -0
  35. package/dist/jobs.js +214 -0
  36. package/dist/jobs.js.map +1 -0
  37. package/dist/manifest.d.ts +357 -112
  38. package/dist/manifest.js +270 -72
  39. package/dist/manifest.js.map +1 -1
  40. package/dist/naming.d.ts +93 -6
  41. package/dist/naming.js +98 -6
  42. package/dist/naming.js.map +1 -1
  43. package/dist/platform-api.d.ts +7792 -0
  44. package/dist/platform-api.js +455 -0
  45. package/dist/platform-api.js.map +1 -0
  46. package/dist/realtime.d.ts +139 -0
  47. package/dist/realtime.js +201 -0
  48. package/dist/realtime.js.map +1 -0
  49. package/dist/router/decide.d.ts +7 -1
  50. package/dist/router/decide.js +42 -5
  51. package/dist/router.d.ts +35 -13
  52. package/dist/router.js +36 -0
  53. package/dist/router.js.map +1 -1
  54. package/dist/runtime-config.d.ts +57 -0
  55. package/dist/runtime-config.js +12 -0
  56. package/dist/runtime-config.js.map +1 -1
  57. package/dist/storage.d.ts +55 -0
  58. package/dist/storage.js +112 -0
  59. package/dist/storage.js.map +1 -0
  60. package/dist/telemetry.d.ts +350 -83
  61. package/dist/telemetry.js +188 -15
  62. package/dist/telemetry.js.map +1 -1
  63. package/dist/web-compute.d.ts +191 -0
  64. package/dist/web-compute.js +257 -0
  65. package/dist/web-compute.js.map +1 -0
  66. package/package.json +28 -8
  67. package/src/api.ts +864 -238
  68. package/src/auth.ts +37 -0
  69. package/src/base64url.ts +13 -0
  70. package/src/bindings.ts +74 -7
  71. package/src/cloudfront-function.ts +70 -2
  72. package/src/compute.ts +86 -0
  73. package/src/config.ts +34 -2
  74. package/src/constants.ts +76 -1
  75. package/src/email.ts +168 -0
  76. package/src/fingerprint.ts +20 -0
  77. package/src/index.ts +6 -0
  78. package/src/jobs.ts +281 -0
  79. package/src/manifest.ts +542 -114
  80. package/src/naming.ts +103 -8
  81. package/src/platform-api.ts +630 -0
  82. package/src/realtime.ts +298 -0
  83. package/src/router/decide.d.ts +7 -1
  84. package/src/router/decide.js +42 -5
  85. package/src/router.ts +33 -13
  86. package/src/runtime-config.ts +70 -0
  87. package/src/storage.ts +120 -0
  88. package/src/telemetry.ts +198 -93
  89. package/src/web-compute.ts +342 -0
@@ -0,0 +1,112 @@
1
+ /**
2
+ * File stores (`storage` in `plat.config.ts`). Every stage's stores share the
3
+ * platform's storage bucket:
4
+ *
5
+ * - a private store is `<app>/<stage>/<store>/` (`names.storagePrefix`);
6
+ * browsers reach its files only through presigned URLs;
7
+ * - a public store is `_public/<app>/<stage>/<store>/`, which the edge serves
8
+ * at `/__platform/storage/<store>/<key>` on the app's own host. The router
9
+ * distribution may read `_public/*` and nothing else, so a routing mistake
10
+ * can't expose a private store. `_` can't start an app name, so no app's
11
+ * prefix collides with it.
12
+ *
13
+ * Isomorphic: the SDK, its browser client, the CLI and the engine share it.
14
+ */
15
+ /** Where the edge serves public stores on every app host: `/__platform/storage/<store>/<key>`. */
16
+ export const STORAGE_PATH = '/__platform/storage/';
17
+ /** Top-level prefix of public stores in the storage bucket. */
18
+ export const PUBLIC_STORAGE_ROOT = '_public/';
19
+ /**
20
+ * Headers the edge adds to every public-store response (the router
21
+ * distribution's response headers policy; `plat dev` sends the same).
22
+ * `script-src 'none'` keeps an uploaded HTML or SVG file from running script
23
+ * on the app's origin, where its session cookie lives (`sandbox` would also
24
+ * stop PDFs from opening in Chrome).
25
+ */
26
+ export const STORAGE_RESPONSE_HEADERS = {
27
+ 'x-content-type-options': 'nosniff',
28
+ 'content-security-policy': "script-src 'none'",
29
+ };
30
+ /**
31
+ * The router's `x-platform-host` for a public store's file, in place of the
32
+ * host. CloudFront's cache key is the rewritten URI plus that header, not the
33
+ * behavior or origin, and an app's server could be asked for the same path
34
+ * (`/<app>/<stage>/<store>/<key>`) on the app's host: with the host in both,
35
+ * its response would be served for the file, and the file for that path. No
36
+ * routed host has this value.
37
+ */
38
+ export const STORAGE_CACHE_HOST = '__storage';
39
+ /** `Cache-Control` the edge adds to a public file that carries none: browsers revalidate it. */
40
+ export const STORAGE_DEFAULT_CACHE_CONTROL = 'no-cache';
41
+ /**
42
+ * Whether the edge serves `key` (as it appears in a URL path, so still
43
+ * percent-encoded): not empty, and without `.` or `..` segments. S3 decodes
44
+ * the key once, so `%2e` counts as a dot and `%2f` as a slash. The router
45
+ * inlines the same check (`router/decide.js`).
46
+ */
47
+ export function isServableKey(key) {
48
+ if (!key)
49
+ return false;
50
+ return key
51
+ .replace(/%2e/gi, '.')
52
+ .replace(/%2f/gi, '/')
53
+ .split('/')
54
+ .every((part) => part !== '.' && part !== '..');
55
+ }
56
+ /**
57
+ * The path the edge serves a public store's file at, with each key segment
58
+ * percent-encoded: `storagePath('snapshots', 'fires/today 1.json')` →
59
+ * `/__platform/storage/snapshots/fires/today%201.json`.
60
+ */
61
+ export function storagePath(store, key) {
62
+ const k = key.replace(/^\/+/, '');
63
+ const path = k.split('/').map(encodeURIComponent).join('/');
64
+ if (!isServableKey(path))
65
+ throw new Error(`Storage key "${key}" can't be served from the edge`);
66
+ return `${STORAGE_PATH}${store}/${path}`;
67
+ }
68
+ /** Content types by file extension: static files, and store files put without one. */
69
+ const CONTENT_TYPES = {
70
+ html: 'text/html; charset=utf-8',
71
+ htm: 'text/html; charset=utf-8',
72
+ css: 'text/css; charset=utf-8',
73
+ js: 'text/javascript; charset=utf-8',
74
+ mjs: 'text/javascript; charset=utf-8',
75
+ cjs: 'text/javascript; charset=utf-8',
76
+ map: 'application/json; charset=utf-8',
77
+ json: 'application/json; charset=utf-8',
78
+ geojson: 'application/geo+json',
79
+ ndjson: 'application/x-ndjson',
80
+ webmanifest: 'application/manifest+json',
81
+ txt: 'text/plain; charset=utf-8',
82
+ csv: 'text/csv; charset=utf-8',
83
+ md: 'text/markdown; charset=utf-8',
84
+ xml: 'application/xml; charset=utf-8',
85
+ svg: 'image/svg+xml',
86
+ png: 'image/png',
87
+ jpg: 'image/jpeg',
88
+ jpeg: 'image/jpeg',
89
+ gif: 'image/gif',
90
+ webp: 'image/webp',
91
+ avif: 'image/avif',
92
+ ico: 'image/x-icon',
93
+ woff: 'font/woff',
94
+ woff2: 'font/woff2',
95
+ ttf: 'font/ttf',
96
+ otf: 'font/otf',
97
+ wasm: 'application/wasm',
98
+ pdf: 'application/pdf',
99
+ zip: 'application/zip',
100
+ gz: 'application/gzip',
101
+ mp4: 'video/mp4',
102
+ webm: 'video/webm',
103
+ mp3: 'audio/mpeg',
104
+ wav: 'audio/wav',
105
+ };
106
+ /** The content type for a file name (or key), `application/octet-stream` when the extension is unknown. */
107
+ export function contentTypeFor(path) {
108
+ const file = path.slice(path.lastIndexOf('/') + 1);
109
+ const dot = file.lastIndexOf('.');
110
+ return ((dot === -1 ? undefined : CONTENT_TYPES[file.slice(dot + 1).toLowerCase()]) ?? 'application/octet-stream');
111
+ }
112
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"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"}
@@ -4,93 +4,350 @@
4
4
  * filter forwards the interesting kinds to the telemetry processor, which
5
5
  * aggregates rollups into the telemetry table. Logs Insights covers the rest
6
6
  * (search, traces) on demand. No CloudWatch custom metrics are ever created.
7
+ *
8
+ * CloudWatch Logs bills every byte ingested, so lines leave out what a reader
9
+ * can tell without it (a `path` equal to its `route`, a first `attempt`), and
10
+ * most requests and jobs fold their spans into a count (`traceSampled`).
7
11
  */
8
- export type TelemetryKind = 'req' | 'err' | 'job' | 'span' | 'log' | 'metric' | 'env';
9
- interface Base {
10
- /** Marker so the subscription filter only matches platform lines. */
11
- _p: 1;
12
- t: TelemetryKind;
13
- /** Epoch milliseconds. */
14
- ts: number;
15
- app: string;
16
- stage: string;
17
- /** Deployment id. */
18
- rev: string;
19
- trace?: string;
20
- span?: string;
21
- parent?: string;
22
- }
23
- export interface RequestEvent extends Base {
24
- t: 'req';
25
- method: string;
26
- /** Route pattern when known (`/api/todos/:id`), else the raw path. */
27
- route: string;
28
- path: string;
29
- status: number;
12
+ import { Schema } from 'effect';
13
+ export declare const TelemetryKind: Schema.Literals<readonly ["req", "err", "job", "span", "log", "metric", "limit", "env"]>;
14
+ export type TelemetryKind = typeof TelemetryKind.Type;
15
+ export declare const RequestEvent: Schema.Struct<{
16
+ readonly _p: Schema.Literal<1>;
17
+ readonly ts: Schema.Finite;
18
+ readonly app: Schema.String;
19
+ readonly stage: Schema.String;
20
+ readonly rev: Schema.String;
21
+ readonly trace: Schema.optional<Schema.String>;
22
+ readonly span: Schema.optional<Schema.String>;
23
+ readonly parent: Schema.optional<Schema.String>;
24
+ readonly calls: Schema.optional<Schema.Finite>;
25
+ readonly callMs: Schema.optional<Schema.Finite>;
26
+ readonly t: Schema.Literal<"req">;
27
+ readonly method: Schema.String;
28
+ /** Route pattern when known (`/api/todos/:id`), else the raw path with ids as `:id`. */
29
+ readonly route: Schema.String;
30
+ /** The raw path, when it isn't `route`. */
31
+ readonly path: Schema.optional<Schema.String>;
32
+ readonly status: Schema.Finite;
30
33
  /** Duration in ms. */
31
- dur: number;
32
- bytes?: number;
33
- country?: string;
34
+ readonly dur: Schema.Finite;
35
+ readonly bytes: Schema.optional<Schema.Finite>;
36
+ readonly country: Schema.optional<Schema.String>;
34
37
  /** Hashed user id when signed in. */
35
- user?: string;
36
- cold?: boolean;
37
- }
38
- export interface ErrorEvent extends Base {
39
- t: 'err';
40
- source: 'http' | 'job' | 'unhandled' | 'log';
41
- name: string;
42
- message: string;
43
- stack?: string;
44
- route?: string;
45
- job?: string;
46
- fingerprint: string;
47
- }
48
- export interface JobEvent extends Base {
49
- t: 'job';
50
- kind: 'queue' | 'event' | 'cron' | 'invoke';
51
- name: string;
52
- status: 'ok' | 'error';
53
- dur: number;
54
- attempt?: number;
55
- }
56
- export interface SpanEvent extends Base {
57
- t: 'span';
38
+ readonly user: Schema.optional<Schema.String>;
39
+ readonly cold: Schema.optional<Schema.Boolean>;
40
+ }>;
41
+ export type RequestEvent = typeof RequestEvent.Type;
42
+ export declare const ErrorEvent: Schema.Struct<{
43
+ readonly _p: Schema.Literal<1>;
44
+ readonly ts: Schema.Finite;
45
+ readonly app: Schema.String;
46
+ readonly stage: Schema.String;
47
+ readonly rev: Schema.String;
48
+ readonly trace: Schema.optional<Schema.String>;
49
+ readonly span: Schema.optional<Schema.String>;
50
+ readonly parent: Schema.optional<Schema.String>;
51
+ readonly t: Schema.Literal<"err">;
52
+ /** `service`: a long-running service's `run` failed (it is rerun after a backoff). */
53
+ readonly source: Schema.Literals<readonly ["http", "job", "unhandled", "log", "service"]>;
54
+ readonly name: Schema.String;
55
+ readonly message: Schema.String;
56
+ readonly stack: Schema.optional<Schema.String>;
57
+ readonly route: Schema.optional<Schema.String>;
58
+ readonly job: Schema.optional<Schema.String>;
59
+ readonly fingerprint: Schema.String;
60
+ }>;
61
+ export type ErrorEvent = typeof ErrorEvent.Type;
62
+ /**
63
+ * One unit of work. `service` jobs come from long-running services: `<service>`
64
+ * is a run of the service that ended (it is rerun; `dur` is how long it ran),
65
+ * `<service>/<unit>` a unit of work it marked with `traced`.
66
+ */
67
+ export declare const JobEvent: Schema.Struct<{
68
+ readonly _p: Schema.Literal<1>;
69
+ readonly ts: Schema.Finite;
70
+ readonly app: Schema.String;
71
+ readonly stage: Schema.String;
72
+ readonly rev: Schema.String;
73
+ readonly trace: Schema.optional<Schema.String>;
74
+ readonly span: Schema.optional<Schema.String>;
75
+ readonly parent: Schema.optional<Schema.String>;
76
+ readonly calls: Schema.optional<Schema.Finite>;
77
+ readonly callMs: Schema.optional<Schema.Finite>;
78
+ readonly t: Schema.Literal<"job">;
79
+ readonly kind: Schema.Literals<readonly ["queue", "event", "cron", "invoke", "service"]>;
80
+ readonly name: Schema.String;
81
+ readonly status: Schema.Literals<readonly ["ok", "error"]>;
82
+ readonly dur: Schema.Finite;
83
+ /** A queue message's, event's or cron run's attempt, when it isn't the first. */
84
+ readonly attempt: Schema.optional<Schema.Finite>;
85
+ /** What happens after a failed run: tried again later, or moved to the dead-letter queue. */
86
+ readonly next: Schema.optional<Schema.Literals<readonly ["retry", "dead"]>>;
87
+ }>;
88
+ export type JobEvent = typeof JobEvent.Type;
89
+ /**
90
+ * A call a request or job made, written only when its request or job keeps its
91
+ * spans (`TRACE_SAMPLE_RATE`); `parent` is that request's or job's `span`.
92
+ */
93
+ export declare const SpanEvent: Schema.Struct<{
94
+ readonly _p: Schema.Literal<1>;
95
+ readonly ts: Schema.Finite;
96
+ readonly app: Schema.String;
97
+ readonly stage: Schema.String;
98
+ readonly rev: Schema.String;
99
+ readonly trace: Schema.optional<Schema.String>;
100
+ readonly span: Schema.optional<Schema.String>;
101
+ readonly parent: Schema.optional<Schema.String>;
102
+ readonly t: Schema.Literal<"span">;
58
103
  /** `db.get`, `db.query`, `queue.send`, `events.publish`, `storage.put`, `fetch`, ... */
59
- op: string;
60
- name?: string;
61
- dur: number;
62
- status: 'ok' | 'error';
104
+ readonly op: Schema.String;
105
+ readonly name: Schema.optional<Schema.String>;
106
+ readonly dur: Schema.Finite;
107
+ readonly status: Schema.Literals<readonly ["ok", "error"]>;
63
108
  /** Start offset relative to the trace root, ms. */
64
- start?: number;
65
- }
66
- export interface LogEvent extends Base {
67
- t: 'log';
68
- level: 'debug' | 'info' | 'warn' | 'error';
69
- msg: string;
70
- [field: string]: unknown;
71
- }
72
- export interface MetricEvent extends Base {
73
- t: 'metric';
74
- name: string;
75
- value: number;
76
- unit?: string;
77
- }
78
- export interface EnvEvent extends Base {
79
- t: 'env';
80
- event: 'start' | 'stop';
81
- runtime: 'web' | 'worker';
82
- initMs?: number;
83
- }
84
- export type TelemetryEvent = RequestEvent | ErrorEvent | JobEvent | SpanEvent | LogEvent | MetricEvent | EnvEvent;
109
+ readonly start: Schema.optional<Schema.Finite>;
110
+ }>;
111
+ export type SpanEvent = typeof SpanEvent.Type;
112
+ /** A log line; any other fields are the structured fields it was logged with. */
113
+ export declare const LogEvent: Schema.StructWithRest<Schema.Struct<{
114
+ readonly _p: Schema.Literal<1>;
115
+ readonly ts: Schema.Finite;
116
+ readonly app: Schema.String;
117
+ readonly stage: Schema.String;
118
+ readonly rev: Schema.String;
119
+ readonly trace: Schema.optional<Schema.String>;
120
+ readonly span: Schema.optional<Schema.String>;
121
+ readonly parent: Schema.optional<Schema.String>;
122
+ readonly t: Schema.Literal<"log">;
123
+ readonly level: Schema.Literals<readonly ["debug", "info", "warn", "error"]>;
124
+ readonly msg: Schema.String;
125
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
126
+ export type LogEvent = typeof LogEvent.Type;
127
+ export declare const MetricEvent: Schema.Struct<{
128
+ readonly _p: Schema.Literal<1>;
129
+ readonly ts: Schema.Finite;
130
+ readonly app: Schema.String;
131
+ readonly stage: Schema.String;
132
+ readonly rev: Schema.String;
133
+ readonly trace: Schema.optional<Schema.String>;
134
+ readonly span: Schema.optional<Schema.String>;
135
+ readonly parent: Schema.optional<Schema.String>;
136
+ readonly t: Schema.Literal<"metric">;
137
+ readonly name: Schema.String;
138
+ readonly value: Schema.Finite;
139
+ readonly unit: Schema.optional<Schema.String>;
140
+ }>;
141
+ export type MetricEvent = typeof MetricEvent.Type;
142
+ /** One `RateLimits` check, and whether the limit let it through. */
143
+ export declare const LimitEvent: Schema.Struct<{
144
+ readonly _p: Schema.Literal<1>;
145
+ readonly ts: Schema.Finite;
146
+ readonly app: Schema.String;
147
+ readonly stage: Schema.String;
148
+ readonly rev: Schema.String;
149
+ readonly trace: Schema.optional<Schema.String>;
150
+ readonly span: Schema.optional<Schema.String>;
151
+ readonly parent: Schema.optional<Schema.String>;
152
+ readonly t: Schema.Literal<"limit">;
153
+ /** The limit's name (`signups`). Its key (whom it counts) is never sent: it can be a client address. */
154
+ readonly name: Schema.String;
155
+ readonly ok: Schema.Boolean;
156
+ }>;
157
+ export type LimitEvent = typeof LimitEvent.Type;
158
+ /** A runtime process starting or stopping (`service`: a container of a long-running service). */
159
+ export declare const EnvEvent: Schema.Struct<{
160
+ readonly _p: Schema.Literal<1>;
161
+ readonly ts: Schema.Finite;
162
+ readonly app: Schema.String;
163
+ readonly stage: Schema.String;
164
+ readonly rev: Schema.String;
165
+ readonly trace: Schema.optional<Schema.String>;
166
+ readonly span: Schema.optional<Schema.String>;
167
+ readonly parent: Schema.optional<Schema.String>;
168
+ readonly t: Schema.Literal<"env">;
169
+ readonly event: Schema.Literals<readonly ["start", "stop"]>;
170
+ readonly runtime: Schema.Literals<readonly ["web", "worker", "service"]>;
171
+ /**
172
+ * How a deployed server runs (`runtime: 'web'`): `request`, a function per
173
+ * request, or `instance`, a Web Function environment. Absent under `plat dev`.
174
+ */
175
+ readonly compute: Schema.optional<Schema.Literals<readonly ["request", "instance"]>>;
176
+ /** The service's name (`runtime: 'service'`). */
177
+ readonly name: Schema.optional<Schema.String>;
178
+ /** Why it stopped, e.g. `SIGTERM`. */
179
+ readonly reason: Schema.optional<Schema.String>;
180
+ readonly initMs: Schema.optional<Schema.Finite>;
181
+ }>;
182
+ export type EnvEvent = typeof EnvEvent.Type;
183
+ /** One telemetry line, as the SDK writes it and the telemetry processor reads it. */
184
+ export declare const TelemetryEvent: Schema.Union<readonly [Schema.Struct<{
185
+ readonly _p: Schema.Literal<1>;
186
+ readonly ts: Schema.Finite;
187
+ readonly app: Schema.String;
188
+ readonly stage: Schema.String;
189
+ readonly rev: Schema.String;
190
+ readonly trace: Schema.optional<Schema.String>;
191
+ readonly span: Schema.optional<Schema.String>;
192
+ readonly parent: Schema.optional<Schema.String>;
193
+ readonly calls: Schema.optional<Schema.Finite>;
194
+ readonly callMs: Schema.optional<Schema.Finite>;
195
+ readonly t: Schema.Literal<"req">;
196
+ readonly method: Schema.String;
197
+ /** Route pattern when known (`/api/todos/:id`), else the raw path with ids as `:id`. */
198
+ readonly route: Schema.String;
199
+ /** The raw path, when it isn't `route`. */
200
+ readonly path: Schema.optional<Schema.String>;
201
+ readonly status: Schema.Finite;
202
+ /** Duration in ms. */
203
+ readonly dur: Schema.Finite;
204
+ readonly bytes: Schema.optional<Schema.Finite>;
205
+ readonly country: Schema.optional<Schema.String>;
206
+ /** Hashed user id when signed in. */
207
+ readonly user: Schema.optional<Schema.String>;
208
+ readonly cold: Schema.optional<Schema.Boolean>;
209
+ }>, Schema.Struct<{
210
+ readonly _p: Schema.Literal<1>;
211
+ readonly ts: Schema.Finite;
212
+ readonly app: Schema.String;
213
+ readonly stage: Schema.String;
214
+ readonly rev: Schema.String;
215
+ readonly trace: Schema.optional<Schema.String>;
216
+ readonly span: Schema.optional<Schema.String>;
217
+ readonly parent: Schema.optional<Schema.String>;
218
+ readonly t: Schema.Literal<"err">;
219
+ /** `service`: a long-running service's `run` failed (it is rerun after a backoff). */
220
+ readonly source: Schema.Literals<readonly ["http", "job", "unhandled", "log", "service"]>;
221
+ readonly name: Schema.String;
222
+ readonly message: Schema.String;
223
+ readonly stack: Schema.optional<Schema.String>;
224
+ readonly route: Schema.optional<Schema.String>;
225
+ readonly job: Schema.optional<Schema.String>;
226
+ readonly fingerprint: Schema.String;
227
+ }>, Schema.Struct<{
228
+ readonly _p: Schema.Literal<1>;
229
+ readonly ts: Schema.Finite;
230
+ readonly app: Schema.String;
231
+ readonly stage: Schema.String;
232
+ readonly rev: Schema.String;
233
+ readonly trace: Schema.optional<Schema.String>;
234
+ readonly span: Schema.optional<Schema.String>;
235
+ readonly parent: Schema.optional<Schema.String>;
236
+ readonly calls: Schema.optional<Schema.Finite>;
237
+ readonly callMs: Schema.optional<Schema.Finite>;
238
+ readonly t: Schema.Literal<"job">;
239
+ readonly kind: Schema.Literals<readonly ["queue", "event", "cron", "invoke", "service"]>;
240
+ readonly name: Schema.String;
241
+ readonly status: Schema.Literals<readonly ["ok", "error"]>;
242
+ readonly dur: Schema.Finite;
243
+ /** A queue message's, event's or cron run's attempt, when it isn't the first. */
244
+ readonly attempt: Schema.optional<Schema.Finite>;
245
+ /** What happens after a failed run: tried again later, or moved to the dead-letter queue. */
246
+ readonly next: Schema.optional<Schema.Literals<readonly ["retry", "dead"]>>;
247
+ }>, Schema.Struct<{
248
+ readonly _p: Schema.Literal<1>;
249
+ readonly ts: Schema.Finite;
250
+ readonly app: Schema.String;
251
+ readonly stage: Schema.String;
252
+ readonly rev: Schema.String;
253
+ readonly trace: Schema.optional<Schema.String>;
254
+ readonly span: Schema.optional<Schema.String>;
255
+ readonly parent: Schema.optional<Schema.String>;
256
+ readonly t: Schema.Literal<"span">;
257
+ /** `db.get`, `db.query`, `queue.send`, `events.publish`, `storage.put`, `fetch`, ... */
258
+ readonly op: Schema.String;
259
+ readonly name: Schema.optional<Schema.String>;
260
+ readonly dur: Schema.Finite;
261
+ readonly status: Schema.Literals<readonly ["ok", "error"]>;
262
+ /** Start offset relative to the trace root, ms. */
263
+ readonly start: Schema.optional<Schema.Finite>;
264
+ }>, Schema.StructWithRest<Schema.Struct<{
265
+ readonly _p: Schema.Literal<1>;
266
+ readonly ts: Schema.Finite;
267
+ readonly app: Schema.String;
268
+ readonly stage: Schema.String;
269
+ readonly rev: Schema.String;
270
+ readonly trace: Schema.optional<Schema.String>;
271
+ readonly span: Schema.optional<Schema.String>;
272
+ readonly parent: Schema.optional<Schema.String>;
273
+ readonly t: Schema.Literal<"log">;
274
+ readonly level: Schema.Literals<readonly ["debug", "info", "warn", "error"]>;
275
+ readonly msg: Schema.String;
276
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
277
+ readonly _p: Schema.Literal<1>;
278
+ readonly ts: Schema.Finite;
279
+ readonly app: Schema.String;
280
+ readonly stage: Schema.String;
281
+ readonly rev: Schema.String;
282
+ readonly trace: Schema.optional<Schema.String>;
283
+ readonly span: Schema.optional<Schema.String>;
284
+ readonly parent: Schema.optional<Schema.String>;
285
+ readonly t: Schema.Literal<"metric">;
286
+ readonly name: Schema.String;
287
+ readonly value: Schema.Finite;
288
+ readonly unit: Schema.optional<Schema.String>;
289
+ }>, Schema.Struct<{
290
+ readonly _p: Schema.Literal<1>;
291
+ readonly ts: Schema.Finite;
292
+ readonly app: Schema.String;
293
+ readonly stage: Schema.String;
294
+ readonly rev: Schema.String;
295
+ readonly trace: Schema.optional<Schema.String>;
296
+ readonly span: Schema.optional<Schema.String>;
297
+ readonly parent: Schema.optional<Schema.String>;
298
+ readonly t: Schema.Literal<"limit">;
299
+ /** The limit's name (`signups`). Its key (whom it counts) is never sent: it can be a client address. */
300
+ readonly name: Schema.String;
301
+ readonly ok: Schema.Boolean;
302
+ }>, Schema.Struct<{
303
+ readonly _p: Schema.Literal<1>;
304
+ readonly ts: Schema.Finite;
305
+ readonly app: Schema.String;
306
+ readonly stage: Schema.String;
307
+ readonly rev: Schema.String;
308
+ readonly trace: Schema.optional<Schema.String>;
309
+ readonly span: Schema.optional<Schema.String>;
310
+ readonly parent: Schema.optional<Schema.String>;
311
+ readonly t: Schema.Literal<"env">;
312
+ readonly event: Schema.Literals<readonly ["start", "stop"]>;
313
+ readonly runtime: Schema.Literals<readonly ["web", "worker", "service"]>;
314
+ /**
315
+ * How a deployed server runs (`runtime: 'web'`): `request`, a function per
316
+ * request, or `instance`, a Web Function environment. Absent under `plat dev`.
317
+ */
318
+ readonly compute: Schema.optional<Schema.Literals<readonly ["request", "instance"]>>;
319
+ /** The service's name (`runtime: 'service'`). */
320
+ readonly name: Schema.optional<Schema.String>;
321
+ /** Why it stopped, e.g. `SIGTERM`. */
322
+ readonly reason: Schema.optional<Schema.String>;
323
+ readonly initMs: Schema.optional<Schema.Finite>;
324
+ }>]>;
325
+ export type TelemetryEvent = typeof TelemetryEvent.Type;
85
326
  /** Account-level subscription filter: only aggregate-worthy kinds reach the processor. */
86
- export declare const TELEMETRY_FILTER_PATTERN = "{ ($._p = 1) && (($.t = \"req\") || ($.t = \"err\") || ($.t = \"job\") || ($.t = \"metric\") || ($.t = \"env\")) }";
327
+ export declare const TELEMETRY_FILTER_PATTERN = "{ ($._p = 1) && (($.t = \"req\") || ($.t = \"err\") || ($.t = \"job\") || ($.t = \"metric\") || ($.t = \"limit\") || ($.t = \"env\")) }";
328
+ /**
329
+ * A request or job writes its spans when it fails (a 5xx, a failed job, or an
330
+ * `err` line while it runs), takes `SLOW_TRACE_MS` or longer, or its trace is
331
+ * in this share of traces (`traceSampled`). The rest write only their own
332
+ * line, with the spans counted on it (`calls`, `callMs`).
333
+ */
334
+ export declare const TRACE_SAMPLE_RATE: number;
335
+ /** A request or job that takes this long (ms) or longer writes its spans. */
336
+ export declare const SLOW_TRACE_MS = 1000;
337
+ /**
338
+ * Whether `trace` is one of the sampled traces. It depends on the trace id
339
+ * alone, so every hop of a trace (server → queue → worker) makes the same
340
+ * choice. Any string works: a client can send its own `x-platform-trace`.
341
+ */
342
+ export declare function traceSampled(trace: string): boolean;
87
343
  export declare function isTelemetryEvent(v: unknown): v is TelemetryEvent;
88
344
  /** Upper bounds in ms; the last bucket is open-ended. */
89
345
  export declare const LATENCY_BUCKETS_MS: readonly [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 30000];
90
346
  export declare function latencyBucket(ms: number): number;
91
347
  /** Approximate percentile (upper bound of the bucket containing it). `hist[i]` = count in bucket i. */
92
348
  export declare function percentile(hist: readonly number[], p: number): number | null;
93
- export type Resolution = '1m' | '1h' | '1d';
349
+ export declare const Resolution: Schema.Literals<readonly ["1m", "1h", "1d"]>;
350
+ export type Resolution = typeof Resolution.Type;
94
351
  export declare const RESOLUTION_MS: Record<Resolution, number>;
95
352
  /** How long each resolution is kept (DynamoDB TTL). */
96
353
  export declare const RESOLUTION_TTL_DAYS: Record<Resolution, number>;
@@ -100,27 +357,37 @@ export declare function bucketStart(ts: number, res: Resolution): number;
100
357
  * resolution; `sk` starts with the bucket time so a Query with `BETWEEN`
101
358
  * returns a time range.
102
359
  *
103
- * - `m#<app>#<stage>#<res>` sk `<iso>` whole-stage HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[], cold
360
+ * - `m#<app>#<stage>#<res>` sk `<iso>` whole-stage HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[], cold,
361
+ * dur (ms handling them, summed), and process starts:
362
+ * webStarts (webInits of them reported webInitMs, summed),
363
+ * workerStarts, serviceStarts
104
364
  * - `r#<app>#<stage>#<res>` sk `<iso>#<route>` per-route HTTP (same fields, plus method)
105
- * - `j#<app>#<stage>#<res>` sk `<iso>#<kind>:<name>` jobs: ok, error, lat[]
106
- * - `c#<app>#<stage>#<res>` sk `<iso>#<metric>` custom metrics: count, sum, min, max
365
+ * - `j#<app>#<stage>#<res>` sk `<iso>#<kind>:<name>` jobs: ok, error, lat[]; `service:<name>` rows also
366
+ * count `starts` (containers of that service starting)
367
+ * - `c#<app>#<stage>#<res>` sk `<iso>#<metric>` custom metrics: count, sum (and the unit)
368
+ * - `l#<app>#<stage>#<res>` sk `<iso>#<limit>` rate limit checks: allowed, denied
107
369
  * - `e#<app>#<stage>` sk `<fingerprint>` error groups: count, firstSeen, lastSeen, sample, status
108
- * - `u#<app>#<stage>` sk `<iso>` uptime checks: ok, status, ms
370
+ * - `u#<app>#<stage>` sk `<iso>` uptime: ok, source (`traffic`: req, s5xx; `check`, or none on
371
+ * rows before traffic counted: status, ms)
109
372
  */
110
373
  export declare const telemetryKeys: {
111
374
  readonly stage: (app: string, stage: string, res: Resolution) => string;
112
375
  readonly route: (app: string, stage: string, res: Resolution) => string;
113
376
  readonly job: (app: string, stage: string, res: Resolution) => string;
114
377
  readonly metric: (app: string, stage: string, res: Resolution) => string;
378
+ readonly limit: (app: string, stage: string, res: Resolution) => string;
115
379
  readonly errors: (app: string, stage: string) => string;
116
380
  readonly uptime: (app: string, stage: string) => string;
381
+ /**
382
+ * Email usage: sk `YYYY-MM-DD` (UTC), `n` recipients sent. The SDK writes it
383
+ * with the stage role, whose IAM grant covers only this partition.
384
+ */
385
+ readonly email: (app: string, stage: string) => string;
117
386
  readonly time: (ts: number) => string;
118
387
  };
119
- /** Normalize volatile parts (ids, numbers, quoted values) so similar errors group together. */
388
+ /** Normalize volatile parts (ARNs, ids, numbers, quoted values) so similar errors group together. */
120
389
  export declare function normalizeErrorMessage(message: string): string;
121
390
  /** First stack frame that is app code (not node internals or node_modules). */
122
391
  export declare function topFrame(stack: string | undefined): string;
123
- /** Stable short hash (FNV-1a 32-bit, hex) — no crypto dependency so the SDK stays tiny. */
124
- export declare function fingerprint(parts: readonly string[]): string;
392
+ export { fingerprint } from './fingerprint.ts';
125
393
  export declare function errorFingerprint(name: string, message: string, stack?: string): string;
126
- export {};