@openupstream/sdk 0.1.1 → 0.3.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/internal.js CHANGED
@@ -7,6 +7,37 @@ export const projectNamespace = (projectId) => `project-${projectId}`;
7
7
  export const clusterName = (database) => `db-${database.id}`;
8
8
  /** Cannot share the Cluster's name, nor `<cluster>-rw`, which the Cluster's own Service takes. */
9
9
  export const poolerName = (database) => `${clusterName(database)}-pooler`;
10
+ /** The Secret CloudNativePG keeps the Database's `app` user in, with its generated `password`. */
11
+ export const databaseAppSecret = (database) => `${clusterName(database)}-app`;
12
+ /** Where the Project's Services and Jobs reach the Database: its Pooler, inside the cluster. */
13
+ export const databaseConnection = (database) => ({
14
+ host: `${poolerName(database)}.${projectNamespace(database.projectId)}.svc.cluster.local`,
15
+ port: 5432,
16
+ database: 'app',
17
+ user: 'app',
18
+ });
19
+ /**
20
+ * The Kubernetes Secret in a Project's namespace that holds all its Secrets'
21
+ * values; the control plane writes it, Services and Jobs read it with `envFrom`.
22
+ */
23
+ export const PROJECT_SECRETS = 'project-secrets';
24
+ /**
25
+ * The `kubernetes.io/dockerconfigjson` Secret in a Project's namespace with
26
+ * the registry credentials of all its Services and Jobs, each under its
27
+ * image's repository; the control plane writes it, every Service and Job
28
+ * names it in `imagePullSecrets`.
29
+ */
30
+ export const PROJECT_REGISTRY_AUTH = 'project-registry-auth';
31
+ /** The Service's Deployment and Kubernetes Service, in its Project's namespace. */
32
+ export const serviceObjectName = (service) => `svc-${service.id}`;
33
+ /** The Job's CronJob, in its Project's namespace; its runs are Kubernetes Jobs named after it. */
34
+ export const jobObjectName = (job) => `job-${job.id}`;
35
+ /** On a Service's Deployment and its pods: the Service's id, by which the control plane finds the pods for its logs. */
36
+ export const SERVICE_ID_LABEL = 'openupstream.io/service-id';
37
+ /** On a Job's CronJob and its runs: the Job's id, by which the control plane lists the runs. */
38
+ export const JOB_ID_LABEL = 'openupstream.io/job-id';
39
+ /** On a run the control plane started (a One-off job): `api`. Scheduled runs do not have it. */
40
+ export const RUN_TRIGGER_LABEL = 'openupstream.io/trigger';
10
41
  /** The folder under the backup bucket that holds one Database's base backups and WAL. */
11
42
  export const backupPrefix = (projectId, databaseId) => `${projectNamespace(projectId)}/${clusterName({ id: databaseId })}/`;
12
43
  /** Ids are lowercase UUIDs, as Postgres prints them; usable in DNS names. */
@@ -24,6 +55,58 @@ export const INTERNAL_DATABASES_PATH = '/internal/v1/databases';
24
55
  * DNS label.
25
56
  */
26
57
  export const INTERNAL_ACCOUNTS_PATH = '/internal/v1/accounts';
58
+ /** `GET` lists every Domain that has Routes, with its Routes, for the Routes operator. */
59
+ export const INTERNAL_ROUTES_PATH = '/internal/v1/routes';
60
+ /** `GET` lists every Service with its Project, for the Services operator. */
61
+ export const INTERNAL_SERVICES_PATH = '/internal/v1/services';
62
+ /** `GET` lists every Job with its Project, for the Jobs operator. */
63
+ export const INTERNAL_JOBS_PATH = '/internal/v1/jobs';
64
+ /** An Account's usage of one month: `${INTERNAL_ACCOUNTS_PATH}/{id}/usage?month=YYYY-MM`, for the billing service. */
65
+ export const internalUsagePath = (accountId, month) => `${INTERNAL_ACCOUNTS_PATH}/${accountId}/usage?month=${month}`;
66
+ /**
67
+ * The Traefik IngressRoute that serves one Resource under one Domain, in its
68
+ * Project's namespace (decision 114): `domain-<id>-bucket-<id>` or
69
+ * `domain-<id>-svc-<id>`. Traefik names each rule's metrics after it, so
70
+ * metering reads the Resource from them.
71
+ */
72
+ export const ingressRouteName = (domainId, resource) => `domain-${domainId}-${resource.kind === 'bucket' ? 'bucket' : 'svc'}-${resource.id}`;
73
+ /** On a Service's Deployment and a Job's CronJob: the spec version it was applied from (serviceSpecVersion, jobSpecVersion). */
74
+ export const SPEC_VERSION_ANNOTATION = 'openupstream.io/spec-version';
75
+ /**
76
+ * Everything of a Service's row that its Deployment is rendered from. The
77
+ * Services operator writes it on the Deployment; the control plane reports
78
+ * `deploying` until the Deployment carries the version its row asks for,
79
+ * so a change is not `running` before it has been applied and rolled out.
80
+ */
81
+ export const serviceSpecVersion = (row) => [
82
+ row.pinnedImage,
83
+ row.service.replicas,
84
+ row.service.memoryMb,
85
+ row.service.cpuMillicores,
86
+ row.service.port,
87
+ row.site,
88
+ row.secretsVersion,
89
+ ...row.databases.map((database) => `${database.id}=${database.name}`),
90
+ ].join('|');
91
+ /**
92
+ * Everything of a Job's row that its CronJob is rendered from. The Jobs
93
+ * operator writes it on the CronJob; until the CronJob carries the version
94
+ * the row asks for, the Job is `deploying` and no run starts from the old
95
+ * template. The Secrets are not part of it: a run's pod reads them when it
96
+ * starts, so nothing needs to change when they do.
97
+ */
98
+ export const jobSpecVersion = (row) => JSON.stringify([
99
+ row.pinnedImage,
100
+ row.job.command,
101
+ row.job.args,
102
+ row.job.memoryMb,
103
+ row.job.cpuMillicores,
104
+ row.job.timeoutSeconds,
105
+ row.job.schedule,
106
+ row.job.timeZone,
107
+ row.site,
108
+ row.databases,
109
+ ]);
27
110
  /**
28
111
  * The platform's own Account, Project and Databases: the control plane's
29
112
  * state (`database`) and madAuth's users (`authDatabase`). The bootstrap
@@ -50,6 +133,8 @@ export const PLATFORM = {
50
133
  homeSite: 'hetzner-fsn1',
51
134
  memoryMb: 512,
52
135
  storageGb: 5,
136
+ autoGrow: true,
137
+ maxStorageGb: null,
53
138
  createdAt: '2026-10-17T00:00:00Z',
54
139
  },
55
140
  authDatabase: {
@@ -59,6 +144,8 @@ export const PLATFORM = {
59
144
  homeSite: 'hetzner-fsn1',
60
145
  memoryMb: 512,
61
146
  storageGb: 2,
147
+ autoGrow: true,
148
+ maxStorageGb: null,
62
149
  createdAt: '2026-10-17T00:00:00Z',
63
150
  },
64
151
  /** The billing service's state; seeded only where a billing service runs (BILLING_CALLERS). */
@@ -69,6 +156,8 @@ export const PLATFORM = {
69
156
  homeSite: 'hetzner-fsn1',
70
157
  memoryMb: 512,
71
158
  storageGb: 2,
159
+ autoGrow: true,
160
+ maxStorageGb: null,
72
161
  createdAt: '2026-10-20T00:00:00Z',
73
162
  },
74
163
  };
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,SAAa,EAAU,EAAE,CAAC,WAAW,SAAS,EAAE,CAAC;AAElF,qGAAqG;AACrG,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAA8B,EAAU,EAAE,CAAC,MAAM,QAAQ,CAAC,EAAE,EAAE,CAAC;AAE3F,kGAAkG;AAClG,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAA8B,EAAU,EAAE,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC;AAExG,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAa,EAAE,UAAc,EAAU,EAAE,CAClE,GAAG,gBAAgB,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC;AAEzE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,IAAI,GAAG,gEAAgE,CAAC;AAErF,8FAA8F;AAC9F,MAAM,CAAC,MAAM,SAAS,GAAG,mCAAmC,CAAC;AAE7D,gEAAgE;AAChE,MAAM,CAAC,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAElE,mDAAmD;AACnD,MAAM,CAAC,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAW9D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,OAAO,EAAE;QACL,EAAE,EAAE,sCAAsC;QAC1C,IAAI,EAAE,cAAc;QACpB,SAAS,EAAE,sBAAsB;KACpC;IACD,OAAO,EAAE;QACL,EAAE,EAAE,sCAAsC;QAC1C,SAAS,EAAE,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ACZ,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,sBAAsB;KACpC;IACD,YAAY,EAAE;QACV,EAAE,EAAE,sCAAsC;QAC1C,SAAS,EAAE,sCAAsC;QACjD,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,cAAc;QACxB,QAAQ,EAAE,GAAG;QACb,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,sBAAsB;KACpC;IACD,+FAA+F;IAC/F,eAAe,EAAE;QACb,EAAE,EAAE,sCAAsC;QAC1C,SAAS,EAAE,sCAAsC;QACjD,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,cAAc;QACxB,QAAQ,EAAE,GAAG;QACb,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,sBAAsB;KACpC;CAOJ,CAAC;AAEF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,aAAa,GAA2B;IACjD,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;IAC1D,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,YAAY,EAAE;CACjE,CAAC"}
package/dist/model.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  export type Id = string;
8
8
  export type Timestamp = string;
9
- /** Compute Sites, where Databases and Services run. Both are in Germany. */
9
+ /** Compute Sites, where Databases, Services and Jobs run. Both are in Germany. */
10
10
  export declare const COMPUTE_SITES: readonly ["hetzner-fsn1", "ovh-lim"];
11
11
  export type Site = (typeof COMPUTE_SITES)[number];
12
12
  /** The customer: pays, receives one invoice, owns Projects. */
@@ -48,7 +48,25 @@ export interface Database {
48
48
  homeSite: Site;
49
49
  memoryMb: number;
50
50
  storageGb: number;
51
+ /**
52
+ * Whether storage grows by itself (decision 111): by half once a volume
53
+ * is 90% used, up to maxStorageGb. False: only resizing grows it.
54
+ */
55
+ autoGrow: boolean;
56
+ /** How far auto-grow may take storageGb; null: no limit but the nodes' free space. */
57
+ maxStorageGb: number | null;
51
58
  createdAt: Timestamp;
59
+ /** Set when the Database started as a copy of another one. */
60
+ restoredFrom?: DatabaseRestore;
61
+ }
62
+ /**
63
+ * Where a restored Database's data comes from (decision 108): another
64
+ * Database of the same Project, live or deleted within the backup retention
65
+ * window, at `targetTime`; without it, the latest point its backups reach.
66
+ */
67
+ export interface DatabaseRestore {
68
+ databaseId: Id;
69
+ targetTime?: Timestamp;
52
70
  }
53
71
  /** Creates an Account; the caller becomes its first Member. */
54
72
  export interface AccountInput {
@@ -68,25 +86,48 @@ export interface ProjectInput {
68
86
  accountId: Id;
69
87
  name: string;
70
88
  }
71
- /** Creates a Database; homeSite defaults to `hetzner-fsn1`. */
89
+ /**
90
+ * Creates a Database; homeSite defaults to `hetzner-fsn1`. With
91
+ * `restoreFrom`, it starts as a copy of that Database instead of empty.
92
+ */
72
93
  export interface DatabaseInput {
73
94
  name: string;
74
95
  homeSite?: Site;
75
96
  memoryMb: number;
76
97
  storageGb: number;
98
+ /** Default true. */
99
+ autoGrow?: boolean;
100
+ /** Default null: no limit. At least storageGb. */
101
+ maxStorageGb?: number | null;
102
+ restoreFrom?: DatabaseRestore;
103
+ }
104
+ /**
105
+ * Resizes a Database (decision 110). Storage only grows: a volume cannot
106
+ * shrink. A new memory size restarts the instances one after the other,
107
+ * the standby first, then a switchover (writes pause for seconds).
108
+ */
109
+ export interface DatabasePatch {
110
+ memoryMb?: number;
111
+ storageGb?: number;
112
+ autoGrow?: boolean;
113
+ /** null removes the limit. */
114
+ maxStorageGb?: number | null;
77
115
  }
78
116
  /**
79
117
  * - `provisioning`: being created, or not yet seen by the operator
118
+ * - `resizing`: its Cluster does not have the size the Database asks for yet
80
119
  * - `ready`: both instances healthy
81
120
  * - `degraded`: running, but not every instance is healthy (e.g. during a
82
121
  * failover)
83
122
  * - `unknown`: the platform could not check just now
84
123
  */
85
- export type DatabaseState = 'provisioning' | 'ready' | 'degraded' | 'unknown';
124
+ export type DatabaseState = 'provisioning' | 'resizing' | 'ready' | 'degraded' | 'unknown';
86
125
  /**
87
- * Where the Project's Services reach the Database: through its PgBouncer
88
- * (transaction pooling), inside the cluster only. The password is never
89
- * returned; it is given to Services as DATABASE_URL.
126
+ * Where the Project's Services and Jobs reach the Database: through its
127
+ * PgBouncer (transaction pooling), inside the cluster only. The password is
128
+ * never returned; every Service and Job of the Project gets the whole URL as
129
+ * `DATABASE_URL_<NAME>` (the name upper-cased, `-` as `_`), and the oldest
130
+ * Database's also as `DATABASE_URL` (decision 97).
90
131
  */
91
132
  export interface DatabaseConnection {
92
133
  host: string;
@@ -99,6 +140,11 @@ export interface DatabaseDetails extends Database {
99
140
  state: DatabaseState;
100
141
  connection: DatabaseConnection;
101
142
  }
143
+ /**
144
+ * A Bucket's name: a hostname label of 3 to 63 lowercase letters, digits
145
+ * and hyphens, neither starting nor ending with a hyphen.
146
+ */
147
+ export declare const BUCKET_NAME: RegExp;
102
148
  export interface Bucket {
103
149
  id: Id;
104
150
  projectId: Id;
@@ -106,6 +152,55 @@ export interface Bucket {
106
152
  name: string;
107
153
  createdAt: Timestamp;
108
154
  }
155
+ /** Creates a Bucket; the name must not be taken in any Project. */
156
+ export interface BucketInput {
157
+ name: string;
158
+ }
159
+ /**
160
+ * How to reach a Bucket with any S3 client: virtual-hosted style only, at
161
+ * `endpoint` (the Bucket's own hostname), with the Bucket's key. The key
162
+ * reads and writes this Bucket and no other.
163
+ */
164
+ export interface BucketAccess {
165
+ /** `https://<name>.s3.<customer domain>`. */
166
+ endpoint: string;
167
+ /** What S3 clients sign requests with; Garage accepts only this one. */
168
+ region: string;
169
+ accessKeyId: string;
170
+ /** Left out for an API key with only `openupstream:read`: the key itself may write. */
171
+ secretAccessKey?: string;
172
+ }
173
+ /** A Bucket as the API returns it. The list leaves out `access`. */
174
+ export interface BucketDetails extends Bucket {
175
+ access: BucketAccess;
176
+ }
177
+ /**
178
+ * A container image from any registry, as given: `nginx:1.27`,
179
+ * `ghcr.io/acme/api:v3`, `registry.example.com:5000/team/app@sha256:…`.
180
+ * A reference without a tag means `latest`.
181
+ */
182
+ export declare const IMAGE_REFERENCE_MAX_LENGTH = 512;
183
+ /**
184
+ * Credentials for a private registry: write-only, stored encrypted with the
185
+ * Project's Secrets and never returned. The registry is the image's.
186
+ */
187
+ export interface RegistryAuth {
188
+ username: string;
189
+ password: string;
190
+ }
191
+ /** Limits of a Service, checked by the API. */
192
+ export declare const SERVICE_LIMITS: {
193
+ readonly maxReplicas: 10;
194
+ readonly minMemoryMb: 64;
195
+ readonly maxMemoryMb: 16384;
196
+ readonly minCpuMillicores: 50;
197
+ readonly maxCpuMillicores: 8000;
198
+ };
199
+ /**
200
+ * A container, always on, 1..N replicas (ARCHITECTURE.md, "Containers"):
201
+ * an HTTP server, or a worker without a port. Its image is pinned to a
202
+ * digest whenever it is deployed.
203
+ */
109
204
  export interface Service {
110
205
  id: Id;
111
206
  projectId: Id;
@@ -113,15 +208,244 @@ export interface Service {
113
208
  name: string;
114
209
  /** The image reference as given, from any registry. */
115
210
  image: string;
116
- /** `sha256:…`, pinned when the image is deployed; null before the first deploy. */
117
- imageDigest: string | null;
211
+ /** `sha256:…`, the digest the tag resolved to when the Service was last deployed. */
212
+ imageDigest: string;
213
+ /** When the tag was last resolved: at creation, on a change of image, and on every deploy. */
214
+ deployedAt: Timestamp;
118
215
  replicas: number;
119
216
  memoryMb: number;
120
217
  cpuMillicores: number;
121
- /** The HTTP port the container listens on. */
122
- port: number;
218
+ /**
219
+ * The HTTP port the container listens on; null: a worker, which no Route
220
+ * can serve, gets no in-cluster address and counts as ready once it runs
221
+ * (decision 98).
222
+ */
223
+ port: number | null;
224
+ /**
225
+ * Where a single replica runs; null: the Home site of the Project's oldest
226
+ * Database, or `hetzner-fsn1`. Two or more replicas run in both Sites.
227
+ */
228
+ homeSite: Site | null;
229
+ /** Whether the image is pulled with registry credentials. */
230
+ registryAuth: boolean;
231
+ createdAt: Timestamp;
232
+ }
233
+ /** Creates a Service; the tag is resolved to a digest while the request waits. */
234
+ export interface ServiceInput {
235
+ name: string;
236
+ image: string;
237
+ /** Left out: a worker without a port. */
238
+ port?: number;
239
+ /** Default 1. */
240
+ replicas?: number;
241
+ memoryMb: number;
242
+ cpuMillicores: number;
243
+ homeSite?: Site;
244
+ registryAuth?: RegistryAuth;
245
+ }
246
+ /**
247
+ * Changes a Service. A new `image` or `registryAuth` resolves the tag again;
248
+ * `registryAuth: null` removes the credentials, `homeSite: null` the choice,
249
+ * `port: null` the port (refused while a Route serves the Service).
250
+ */
251
+ export interface ServicePatch {
252
+ image?: string;
253
+ port?: number | null;
254
+ replicas?: number;
255
+ memoryMb?: number;
256
+ cpuMillicores?: number;
257
+ homeSite?: Site | null;
258
+ registryAuth?: RegistryAuth | null;
259
+ }
260
+ /**
261
+ * Read live from its Deployment: `deploying` until the first replica is
262
+ * up and while a new version rolls out, `running` with every replica
263
+ * available, `degraded` with some, `unknown` when Kubernetes cannot be asked.
264
+ */
265
+ export type ServiceState = 'deploying' | 'running' | 'degraded' | 'unknown';
266
+ /** A Service as the API returns it. */
267
+ export interface ServiceDetails extends Service {
268
+ state: ServiceState;
269
+ }
270
+ /** Limits of a Job, checked by the API; memory and CPU as for a Service. */
271
+ export declare const JOB_LIMITS: {
272
+ readonly minMemoryMb: 64;
273
+ readonly maxMemoryMb: 16384;
274
+ readonly minCpuMillicores: 50;
275
+ readonly maxCpuMillicores: 8000;
276
+ readonly defaultTimeoutSeconds: 3600;
277
+ readonly maxTimeoutSeconds: 86400;
278
+ /** Entries of `command` and of `args`, and their bytes (UTF-8) together, which go into a Kubernetes annotation. */
279
+ readonly maxArgs: 256;
280
+ readonly maxArgsTotalBytes: number;
281
+ };
282
+ /**
283
+ * A container image run to completion (ARCHITECTURE.md, "Containers"): a
284
+ * Cron job when it has a `schedule`, and started as a One-off job through
285
+ * the API whether or not it has one. Its image is pinned to a digest
286
+ * whenever it is deployed; every run starts that digest.
287
+ */
288
+ export interface Job {
289
+ id: Id;
290
+ projectId: Id;
291
+ /** DNS label, unique within the Project. */
292
+ name: string;
293
+ /** The image reference as given, from any registry. */
294
+ image: string;
295
+ /** `sha256:…`, the digest the tag resolved to when the Job was last deployed. */
296
+ imageDigest: string;
297
+ /** When the tag was last resolved: at creation, on a change of image, and on every deploy. */
298
+ deployedAt: Timestamp;
299
+ /** Replaces the image's entrypoint; null: the image's. */
300
+ command: string[] | null;
301
+ /** Replaces the image's command (its CMD); null: the image's. A run may replace it again. */
302
+ args: string[] | null;
303
+ memoryMb: number;
304
+ cpuMillicores: number;
305
+ /** A run still going after this long is stopped and failed. */
306
+ timeoutSeconds: number;
307
+ /**
308
+ * Five-field cron expression (`*\/15 * * * *`) or `@hourly`, `@daily`,
309
+ * `@weekly`, `@monthly`, `@yearly`; null: started only through the API.
310
+ * A run that is due while the previous one still runs is skipped.
311
+ */
312
+ schedule: string | null;
313
+ /** IANA time zone the schedule is read in, e.g. `Europe/Berlin`; null: UTC. */
314
+ timeZone: string | null;
315
+ /** Where its runs go; null: the Home site of the Project's oldest Database, or `hetzner-fsn1`. */
316
+ homeSite: Site | null;
317
+ /** Whether the image is pulled with registry credentials. */
318
+ registryAuth: boolean;
123
319
  createdAt: Timestamp;
124
320
  }
321
+ /** Creates a Job; the tag is resolved to a digest while the request waits. */
322
+ export interface JobInput {
323
+ name: string;
324
+ image: string;
325
+ command?: string[];
326
+ args?: string[];
327
+ memoryMb: number;
328
+ cpuMillicores: number;
329
+ /** Default JOB_LIMITS.defaultTimeoutSeconds. */
330
+ timeoutSeconds?: number;
331
+ schedule?: string;
332
+ timeZone?: string;
333
+ homeSite?: Site;
334
+ registryAuth?: RegistryAuth;
335
+ }
336
+ /**
337
+ * Changes a Job. A new `image` or `registryAuth` resolves the tag again;
338
+ * null removes a `command`, `args`, `schedule`, `timeZone`, `homeSite` or
339
+ * the registry credentials.
340
+ */
341
+ export interface JobPatch {
342
+ image?: string;
343
+ command?: string[] | null;
344
+ args?: string[] | null;
345
+ memoryMb?: number;
346
+ cpuMillicores?: number;
347
+ timeoutSeconds?: number;
348
+ schedule?: string | null;
349
+ timeZone?: string | null;
350
+ homeSite?: Site | null;
351
+ registryAuth?: RegistryAuth | null;
352
+ }
353
+ /**
354
+ * Read live from its CronJob: `deploying` until the Jobs operator has
355
+ * applied the Job as it is now, `ready` once it has (runs can start),
356
+ * `unknown` when Kubernetes cannot be asked.
357
+ */
358
+ export type JobState = 'deploying' | 'ready' | 'unknown';
359
+ /** A Job as the API returns it. */
360
+ export interface JobDetails extends Job {
361
+ state: JobState;
362
+ }
363
+ /**
364
+ * Read live from its Kubernetes Job: `pending` until its container runs
365
+ * (e.g. while the image is pulled), `running`, then `succeeded` (exit 0) or
366
+ * `failed` (another exit code, or stopped at the timeout).
367
+ */
368
+ export type JobRunState = 'pending' | 'running' | 'succeeded' | 'failed';
369
+ /**
370
+ * One run of a Job, scheduled or started through the API. Kept for 24 hours
371
+ * after it finished; a Cron job keeps at most its last 3 successful and 3
372
+ * failed scheduled runs.
373
+ */
374
+ export interface JobRun {
375
+ /** Unique within the Project; the name of its Kubernetes Job. */
376
+ id: string;
377
+ jobId: Id;
378
+ /** `schedule` for a Cron job's run, `api` for a One-off job. */
379
+ trigger: 'schedule' | 'api';
380
+ state: JobRunState;
381
+ /**
382
+ * Why it failed, as Kubernetes says: `BackoffLimitExceeded` (it exited
383
+ * with an error), `DeadlineExceeded` (stopped at the timeout); null
384
+ * otherwise.
385
+ */
386
+ reason: string | null;
387
+ createdAt: Timestamp;
388
+ startedAt: Timestamp | null;
389
+ finishedAt: Timestamp | null;
390
+ }
391
+ /**
392
+ * Starts a One-off job. `args` replaces the Job's args for this run; `env`
393
+ * adds variables to it, over Secrets of the same name. Together with the
394
+ * Job's command and args at most JOB_LIMITS.maxArgsTotalBytes.
395
+ */
396
+ export interface JobRunInput {
397
+ args?: string[];
398
+ env?: Record<string, string>;
399
+ }
400
+ /**
401
+ * One line of a Service's or a run's output, as the log stream sends it
402
+ * (ARCHITECTURE.md, "Observability and customer logs"): a live tail only,
403
+ * nothing is retained (decision 21).
404
+ */
405
+ export interface LogEntry {
406
+ /** The pod (replica or run) it came from. */
407
+ pod: string;
408
+ /** The Site the pod runs in; null when Kubernetes does not say. */
409
+ site: Site | null;
410
+ /** When the container wrote it, as Kubernetes recorded it (RFC 3339, nanoseconds). */
411
+ time: string;
412
+ /** The line, without its line break. */
413
+ line: string;
414
+ /** From the container before its last restart (a crash): what it wrote before it died. */
415
+ previous: boolean;
416
+ }
417
+ /** Limits of the log stream, checked by the API. */
418
+ export declare const LOG_LIMITS: {
419
+ /** Lines per container sent first, when `tail` is not given. */
420
+ readonly defaultTailLines: 100;
421
+ readonly maxTailLines: 10000;
422
+ /** A followed stream ends after this long; the client asks again to go on. */
423
+ readonly maxFollowSeconds: 3600;
424
+ /** Followed streams open at once per Account, on one control-plane replica; more answer 429. */
425
+ readonly maxFollowsPerAccount: 10;
426
+ /** A followed stream sends an empty line this often, so a client and the proxies between see it is alive. */
427
+ readonly heartbeatSeconds: 30;
428
+ };
429
+ /**
430
+ * What to read: `tail` lines per container first; with `follow`, then new
431
+ * lines as they are written, also from replicas that start while it runs,
432
+ * until LOG_LIMITS.maxFollowSeconds have passed or every pod is gone.
433
+ * `tail` 0 sends only what is written from now on. Empty lines in the
434
+ * stream are heartbeats, not entries.
435
+ */
436
+ export interface LogQuery {
437
+ tail?: number;
438
+ follow?: boolean;
439
+ }
440
+ /** A Secret's name is an environment variable name (the schema checks the same). */
441
+ export declare const SECRET_NAME: RegExp;
442
+ /**
443
+ * At most this many bytes (UTF-8) per value, and all of a Project's values
444
+ * together at most SECRETS_MAX_TOTAL_BYTES: they go into one Kubernetes
445
+ * Secret (1 MiB at most) and into every container's environment.
446
+ */
447
+ export declare const SECRET_VALUE_MAX_BYTES: number;
448
+ export declare const SECRETS_MAX_TOTAL_BYTES: number;
125
449
  /**
126
450
  * A Secret's value is write-only: the API accepts it and hands it to the
127
451
  * Project's Services and jobs as an environment variable, but never returns it.
@@ -138,6 +462,14 @@ export interface SecretInput {
138
462
  name: string;
139
463
  value: string;
140
464
  }
465
+ /**
466
+ * Where `oup login` signs in (`GET /v1/login`, no token needed): madAuth's
467
+ * issuer and the CLI's client ID there, for the device authorization grant.
468
+ */
469
+ export interface CliLogin {
470
+ issuer: string;
471
+ clientId: string;
472
+ }
141
473
  /** The TXT record that proves an Account owns a custom domain. */
142
474
  export interface TxtRecord {
143
475
  name: string;
@@ -172,6 +504,24 @@ export interface CustomDomain extends DomainBase {
172
504
  export type Domain = DefaultDomain | CustomDomain;
173
505
  /** Where the TXT ownership proof for `hostname` has to be published. */
174
506
  export declare function txtRecordName(hostname: string): string;
507
+ /**
508
+ * A custom domain's hostname: lowercase labels of letters, digits and
509
+ * hyphens, at least two of them, at most 253 characters (the schema checks
510
+ * the same).
511
+ */
512
+ export declare const HOSTNAME: RegExp;
513
+ /**
514
+ * Claims a custom domain for a Project. It is routed once its TXT record
515
+ * (`verification.txtRecord`) is published and verified; point the hostname
516
+ * at `ingress.<customer domain>` with a CNAME for traffic and its
517
+ * certificate, before adding the first Route: its certificate is requested
518
+ * then, and a failed attempt is retried only after an hour.
519
+ */
520
+ export interface CustomDomainInput {
521
+ hostname: string;
522
+ }
523
+ /** A Route's path prefix: `/` or `/segment[/segment…]`, no trailing slash (the schema checks the same). */
524
+ export declare const PATH_PREFIX: RegExp;
175
525
  export type RouteTarget = {
176
526
  kind: 'bucket';
177
527
  bucketId: Id;
@@ -192,7 +542,23 @@ export interface Route {
192
542
  target: RouteTarget;
193
543
  createdAt: Timestamp;
194
544
  }
195
- export declare const RESOURCE_KINDS: readonly ["database", "bucket", "service"];
545
+ /**
546
+ * Creates a Route to a Bucket or a Service of the same Project. For a
547
+ * Bucket the prefix is stripped: `/docs/a.html` on the Route `/docs` serves
548
+ * the object `a.html`. With `spaFallback`, a path with no object serves
549
+ * `index.html` with status 200; every Route to one Bucket has the same
550
+ * `spaFallback`. A Service gets the path unchanged.
551
+ */
552
+ export type RouteInput = {
553
+ pathPrefix: string;
554
+ bucketId: Id;
555
+ spaFallback?: boolean;
556
+ } | {
557
+ pathPrefix: string;
558
+ /** The Service gets the request with its path as it came, prefix included. */
559
+ serviceId: Id;
560
+ };
561
+ export declare const RESOURCE_KINDS: readonly ["database", "bucket", "service", "job"];
196
562
  export type ResourceKind = (typeof RESOURCE_KINDS)[number];
197
563
  export declare const USAGE_UNITS: readonly ["cpu_seconds", "memory_gb_hours", "storage_gb_hours", "egress_gb"];
198
564
  export type UsageUnit = (typeof USAGE_UNITS)[number];
package/dist/model.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Ids are UUIDs, timestamps RFC 3339 strings.
6
6
  */
7
- /** Compute Sites, where Databases and Services run. Both are in Germany. */
7
+ /** Compute Sites, where Databases, Services and Jobs run. Both are in Germany. */
8
8
  export const COMPUTE_SITES = ['hetzner-fsn1', 'ovh-lim'];
9
9
  /** Postgres always runs with at least this much memory. */
10
10
  export const DATABASE_MIN_MEMORY_MB = 256;
@@ -17,10 +17,70 @@ export const API_KEY_SCOPES = {
17
17
  read: 'openupstream:read',
18
18
  write: 'openupstream:write',
19
19
  };
20
+ /**
21
+ * A Bucket's name: a hostname label of 3 to 63 lowercase letters, digits
22
+ * and hyphens, neither starting nor ending with a hyphen.
23
+ */
24
+ export const BUCKET_NAME = /^[a-z0-9]([a-z0-9-]{1,61}[a-z0-9])$/;
25
+ /**
26
+ * A container image from any registry, as given: `nginx:1.27`,
27
+ * `ghcr.io/acme/api:v3`, `registry.example.com:5000/team/app@sha256:…`.
28
+ * A reference without a tag means `latest`.
29
+ */
30
+ export const IMAGE_REFERENCE_MAX_LENGTH = 512;
31
+ /** Limits of a Service, checked by the API. */
32
+ export const SERVICE_LIMITS = {
33
+ maxReplicas: 10,
34
+ minMemoryMb: 64,
35
+ maxMemoryMb: 16384,
36
+ minCpuMillicores: 50,
37
+ maxCpuMillicores: 8000,
38
+ };
39
+ /** Limits of a Job, checked by the API; memory and CPU as for a Service. */
40
+ export const JOB_LIMITS = {
41
+ minMemoryMb: SERVICE_LIMITS.minMemoryMb,
42
+ maxMemoryMb: SERVICE_LIMITS.maxMemoryMb,
43
+ minCpuMillicores: SERVICE_LIMITS.minCpuMillicores,
44
+ maxCpuMillicores: SERVICE_LIMITS.maxCpuMillicores,
45
+ defaultTimeoutSeconds: 3600,
46
+ maxTimeoutSeconds: 86400,
47
+ /** Entries of `command` and of `args`, and their bytes (UTF-8) together, which go into a Kubernetes annotation. */
48
+ maxArgs: 256,
49
+ maxArgsTotalBytes: 16 * 1024,
50
+ };
51
+ /** Limits of the log stream, checked by the API. */
52
+ export const LOG_LIMITS = {
53
+ /** Lines per container sent first, when `tail` is not given. */
54
+ defaultTailLines: 100,
55
+ maxTailLines: 10_000,
56
+ /** A followed stream ends after this long; the client asks again to go on. */
57
+ maxFollowSeconds: 3600,
58
+ /** Followed streams open at once per Account, on one control-plane replica; more answer 429. */
59
+ maxFollowsPerAccount: 10,
60
+ /** A followed stream sends an empty line this often, so a client and the proxies between see it is alive. */
61
+ heartbeatSeconds: 30,
62
+ };
63
+ /** A Secret's name is an environment variable name (the schema checks the same). */
64
+ export const SECRET_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,254}$/;
65
+ /**
66
+ * At most this many bytes (UTF-8) per value, and all of a Project's values
67
+ * together at most SECRETS_MAX_TOTAL_BYTES: they go into one Kubernetes
68
+ * Secret (1 MiB at most) and into every container's environment.
69
+ */
70
+ export const SECRET_VALUE_MAX_BYTES = 64 * 1024;
71
+ export const SECRETS_MAX_TOTAL_BYTES = 512 * 1024;
20
72
  /** Where the TXT ownership proof for `hostname` has to be published. */
21
73
  export function txtRecordName(hostname) {
22
74
  return `_openupstream.${hostname}`;
23
75
  }
24
- export const RESOURCE_KINDS = ['database', 'bucket', 'service'];
76
+ /**
77
+ * A custom domain's hostname: lowercase labels of letters, digits and
78
+ * hyphens, at least two of them, at most 253 characters (the schema checks
79
+ * the same).
80
+ */
81
+ export const HOSTNAME = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]([a-z0-9-]{0,61}[a-z0-9])?$/;
82
+ /** A Route's path prefix: `/` or `/segment[/segment…]`, no trailing slash (the schema checks the same). */
83
+ export const PATH_PREFIX = /^(\/|(\/[A-Za-z0-9._~-]+)+)$/;
84
+ export const RESOURCE_KINDS = ['database', 'bucket', 'service', 'job'];
25
85
  export const USAGE_UNITS = ['cpu_seconds', 'memory_gb_hours', 'storage_gb_hours', 'egress_gb'];
26
86
  //# sourceMappingURL=model.js.map