@openupstream/sdk 0.0.0-stage → 0.1.1

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/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @openupstream/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Typed TypeScript client for the openupstream API. The CLI and the dashboard are
4
+ built on it; customers can use it to script their own account.
5
+
6
+ API types are defined here first and implemented in `control-plane/`, so this
7
+ package doubles as the contract between client and server.
8
+
9
+ ```ts
10
+ import { OpenUpstreamClient } from '@openupstream/sdk';
11
+
12
+ const client = new OpenUpstreamClient({ token: process.env.OPENUPSTREAM_TOKEN! });
13
+ const project = await client.createProject({ accountId, name: 'shop-prod' });
14
+ if (project.ok) {
15
+ const db = await client.createDatabase(project.value.id, { name: 'orders', memoryMb: 512, storageGb: 10 });
16
+ }
17
+ ```
18
+
19
+ Every call returns `{ ok: true, value }` or `{ ok: false, error: { status, message } }`
20
+ (status 0: the API was not reached); nothing throws. `src/internal.ts` holds
21
+ the contract between the control plane and its internal callers (the
22
+ operators and the billing service), not for customers.
23
+
24
+ ## Releasing
25
+
26
+ Raise `version` in `package.json` (and `SDK_VERSION` in `src/index.ts`),
27
+ merge, then tag that commit `sdk-v<version>` and push the tag; only admins
28
+ may. The workflow `.github/workflows/sdk-release.yml` waits in the
29
+ Environment `npm-release` until a maintainer approves the run on GitHub,
30
+ then checks that the tag names the version, builds, tests and publishes
31
+ with npm trusted publishing and provenance: no npm token exists anywhere
32
+ (ARCHITECTURE.md, decision 80).
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @openupstream/sdk
3
+ *
4
+ * Typed client for the openupstream control plane API. Used by the CLI and
5
+ * the dashboard; published to npm for customers who want to automate their
6
+ * own account.
7
+ *
8
+ * The API surface is defined here first and implemented in control-plane/.
9
+ */
10
+ export declare const SDK_VERSION = "0.1.1";
11
+ export * from './model.js';
12
+ export * from './internal.js';
13
+ import type { Account, AccountInput, DatabaseDetails, DatabaseInput, Id, Project, ProjectInput } from './model.js';
14
+ export interface ClientOptions {
15
+ baseUrl?: string;
16
+ /** A madAuth session token, or one of the user's madAuth API keys (`madauth_…`). */
17
+ token: string;
18
+ }
19
+ /** What went wrong, as the API said it: the HTTP status and its message. 0: the API was not reached. */
20
+ export interface ApiError {
21
+ readonly status: number;
22
+ readonly message: string;
23
+ }
24
+ export type ApiResult<T> = {
25
+ readonly ok: true;
26
+ readonly value: T;
27
+ } | {
28
+ readonly ok: false;
29
+ readonly error: ApiError;
30
+ };
31
+ export declare class OpenUpstreamClient {
32
+ #private;
33
+ readonly baseUrl: string;
34
+ constructor(options: ClientOptions);
35
+ health(): Promise<{
36
+ ok: boolean;
37
+ }>;
38
+ /** The Accounts the caller is a Member of. */
39
+ listAccounts(): Promise<ApiResult<Account[]>>;
40
+ /** A new Account, with the caller as its first Member. */
41
+ createAccount(input: AccountInput): Promise<ApiResult<Account>>;
42
+ listProjects(): Promise<ApiResult<Project[]>>;
43
+ createProject(input: ProjectInput): Promise<ApiResult<Project>>;
44
+ getProject(projectId: Id): Promise<ApiResult<Project>>;
45
+ /** Deletes the Project and everything in it; backups are kept for the retention window. */
46
+ deleteProject(projectId: Id): Promise<ApiResult<void>>;
47
+ listDatabases(projectId: Id): Promise<ApiResult<DatabaseDetails[]>>;
48
+ createDatabase(projectId: Id, input: DatabaseInput): Promise<ApiResult<DatabaseDetails>>;
49
+ getDatabase(projectId: Id, databaseId: Id): Promise<ApiResult<DatabaseDetails>>;
50
+ /** Deletes the Database at once; its backups are kept for the retention window. */
51
+ deleteDatabase(projectId: Id, databaseId: Id): Promise<ApiResult<void>>;
52
+ }
package/dist/index.js ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @openupstream/sdk
3
+ *
4
+ * Typed client for the openupstream control plane API. Used by the CLI and
5
+ * the dashboard; published to npm for customers who want to automate their
6
+ * own account.
7
+ *
8
+ * The API surface is defined here first and implemented in control-plane/.
9
+ */
10
+ export const SDK_VERSION = '0.1.1';
11
+ export * from './model.js';
12
+ export * from './internal.js';
13
+ export class OpenUpstreamClient {
14
+ baseUrl;
15
+ #token;
16
+ constructor(options) {
17
+ this.baseUrl = options.baseUrl ?? 'https://api.openupstream.com';
18
+ this.#token = options.token;
19
+ }
20
+ async health() {
21
+ const res = await fetch(`${this.baseUrl}/v1/health`);
22
+ return { ok: res.ok };
23
+ }
24
+ /** The Accounts the caller is a Member of. */
25
+ listAccounts() {
26
+ return this.#call('GET', '/v1/accounts');
27
+ }
28
+ /** A new Account, with the caller as its first Member. */
29
+ createAccount(input) {
30
+ return this.#call('POST', '/v1/accounts', input);
31
+ }
32
+ listProjects() {
33
+ return this.#call('GET', '/v1/projects');
34
+ }
35
+ createProject(input) {
36
+ return this.#call('POST', '/v1/projects', input);
37
+ }
38
+ getProject(projectId) {
39
+ return this.#call('GET', `/v1/projects/${encodeURIComponent(projectId)}`);
40
+ }
41
+ /** Deletes the Project and everything in it; backups are kept for the retention window. */
42
+ deleteProject(projectId) {
43
+ return this.#call('DELETE', `/v1/projects/${encodeURIComponent(projectId)}`);
44
+ }
45
+ listDatabases(projectId) {
46
+ return this.#call('GET', `/v1/projects/${encodeURIComponent(projectId)}/databases`);
47
+ }
48
+ createDatabase(projectId, input) {
49
+ return this.#call('POST', `/v1/projects/${encodeURIComponent(projectId)}/databases`, input);
50
+ }
51
+ getDatabase(projectId, databaseId) {
52
+ return this.#call('GET', `/v1/projects/${encodeURIComponent(projectId)}/databases/${encodeURIComponent(databaseId)}`);
53
+ }
54
+ /** Deletes the Database at once; its backups are kept for the retention window. */
55
+ deleteDatabase(projectId, databaseId) {
56
+ return this.#call('DELETE', `/v1/projects/${encodeURIComponent(projectId)}/databases/${encodeURIComponent(databaseId)}`);
57
+ }
58
+ async #call(method, path, body) {
59
+ const response = await fetch(`${this.baseUrl}${path}`, {
60
+ method,
61
+ headers: {
62
+ authorization: `Bearer ${this.#token}`,
63
+ ...(body === undefined ? {} : { 'content-type': 'application/json' }),
64
+ },
65
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
66
+ }).then((value) => ({ ok: true, value }), (error) => ({ ok: false, error: { status: 0, message: error instanceof Error ? error.message : String(error) } }));
67
+ if (!response.ok) {
68
+ return response;
69
+ }
70
+ // A proxy in front may answer with HTML; only the API's own answers are JSON.
71
+ const isJson = response.value.headers.get('content-type')?.includes('application/json') ?? false;
72
+ const parsed = isJson ? await response.value.json().catch(() => undefined) : undefined;
73
+ if (response.value.ok) {
74
+ return { ok: true, value: parsed };
75
+ }
76
+ const message = typeof parsed === 'object' && parsed !== null && 'error' in parsed && typeof parsed.error === 'string'
77
+ ? parsed.error
78
+ : response.value.statusText;
79
+ return { ok: false, error: { status: response.value.status, message } };
80
+ }
81
+ }
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAiB9B,MAAM,OAAO,kBAAkB;IAClB,OAAO,CAAS;IAChB,MAAM,CAAS;IAExB,YAAY,OAAsB;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,8BAA8B,CAAC;QACjE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,MAAM;QACR,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,YAAY,CAAC,CAAC;QACrD,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;IAC1B,CAAC;IAED,8CAA8C;IAC9C,YAAY;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;I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,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAChG,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;YACpB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAW,EAAE,CAAC;QAC5C,CAAC;QACD,MAAM,OAAO,GACT,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;YAClG,CAAC,CAAC,MAAM,CAAC,KAAK;YACd,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC;QACpC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC;IAC5E,CAAC;CACJ"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The control plane's internal API, which the operators and the billing
3
+ * service call (ARCHITECTURE.md, "Operators" and "Billing"). Not part of the
4
+ * public API: it is served on its own port, never routed by ingress, and
5
+ * callers authenticate with their Kubernetes ServiceAccount token.
6
+ */
7
+ import type { Account, Database, Id, Member, Project } from './model.js';
8
+ /**
9
+ * Kubernetes names, by id (ARCHITECTURE.md, decision 42): the operators
10
+ * create these objects, the control plane reads and deletes them.
11
+ */
12
+ export declare const projectNamespace: (projectId: Id) => string;
13
+ /** The Database's CloudNativePG Cluster; also its ObjectStore, ScheduledBackup and backup folder. */
14
+ export declare const clusterName: (database: Pick<Database, "id">) => string;
15
+ /** Cannot share the Cluster's name, nor `<cluster>-rw`, which the Cluster's own Service takes. */
16
+ export declare const poolerName: (database: Pick<Database, "id">) => string;
17
+ /** The folder under the backup bucket that holds one Database's base backups and WAL. */
18
+ export declare const backupPrefix: (projectId: Id, databaseId: Id) => string;
19
+ /** Ids are lowercase UUIDs, as Postgres prints them; usable in DNS names. */
20
+ export declare const UUID: RegExp;
21
+ /** Project and Database names, and label values: a DNS label (the schema checks the same). */
22
+ export declare const DNS_LABEL: RegExp;
23
+ /** Audience of the ServiceAccount tokens the operators send. */
24
+ export declare const INTERNAL_API_AUDIENCE = "openupstream-control-plane";
25
+ /** `GET` lists every Database with its Project. */
26
+ export declare const INTERNAL_DATABASES_PATH = "/internal/v1/databases";
27
+ /**
28
+ * `GET <path>/<account id>`: the Account with its Holds and Members.
29
+ * `PUT` and `DELETE <path>/<account id>/holds/<reason>`: place or lift a
30
+ * Hold; both answer 204 whether or not the Hold was there. A reason is a
31
+ * DNS label.
32
+ */
33
+ export declare const INTERNAL_ACCOUNTS_PATH = "/internal/v1/accounts";
34
+ export interface AccountRecord extends Account {
35
+ readonly members: readonly Pick<Member, 'authSubject' | 'email'>[];
36
+ }
37
+ export interface DatabaseRow {
38
+ readonly project: Project;
39
+ readonly database: Database;
40
+ }
41
+ /**
42
+ * The platform's own Account, Project and Databases: the control plane's
43
+ * state (`database`) and madAuth's users (`authDatabase`). The bootstrap
44
+ * creates these Databases once; the control plane seeds these rows at
45
+ * startup, and from then on the operator reconciles them like any
46
+ * customer's. Fixed ids, so bootstrap and control plane agree.
47
+ */
48
+ export declare const PLATFORM: {
49
+ readonly account: {
50
+ readonly id: "00000000-0000-4000-8000-000000000001";
51
+ readonly name: "openupstream";
52
+ readonly createdAt: "2026-10-17T00:00:00Z";
53
+ };
54
+ readonly project: {
55
+ readonly id: "00000000-0000-4000-8000-000000000002";
56
+ readonly accountId: "00000000-0000-4000-8000-000000000001";
57
+ readonly name: "platform";
58
+ readonly createdAt: "2026-10-17T00:00:00Z";
59
+ };
60
+ readonly database: {
61
+ readonly id: "00000000-0000-4000-8000-000000000003";
62
+ readonly projectId: "00000000-0000-4000-8000-000000000002";
63
+ readonly name: "control-plane";
64
+ readonly homeSite: "hetzner-fsn1";
65
+ readonly memoryMb: 512;
66
+ readonly storageGb: 5;
67
+ readonly createdAt: "2026-10-17T00:00:00Z";
68
+ };
69
+ readonly authDatabase: {
70
+ readonly id: "00000000-0000-4000-8000-000000000004";
71
+ readonly projectId: "00000000-0000-4000-8000-000000000002";
72
+ readonly name: "auth";
73
+ readonly homeSite: "hetzner-fsn1";
74
+ readonly memoryMb: 512;
75
+ readonly storageGb: 2;
76
+ readonly createdAt: "2026-10-17T00:00:00Z";
77
+ };
78
+ /** The billing service's state; seeded only where a billing service runs (BILLING_CALLERS). */
79
+ readonly billingDatabase: {
80
+ readonly id: "00000000-0000-4000-8000-000000000005";
81
+ readonly projectId: "00000000-0000-4000-8000-000000000002";
82
+ readonly name: "billing";
83
+ readonly homeSite: "hetzner-fsn1";
84
+ readonly memoryMb: 512;
85
+ readonly storageGb: 2;
86
+ readonly createdAt: "2026-10-20T00:00:00Z";
87
+ };
88
+ };
89
+ /** The platform's Database rows, as the operator gets them. */
90
+ export declare const PLATFORM_ROWS: readonly DatabaseRow[];
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Kubernetes names, by id (ARCHITECTURE.md, decision 42): the operators
3
+ * create these objects, the control plane reads and deletes them.
4
+ */
5
+ export const projectNamespace = (projectId) => `project-${projectId}`;
6
+ /** The Database's CloudNativePG Cluster; also its ObjectStore, ScheduledBackup and backup folder. */
7
+ export const clusterName = (database) => `db-${database.id}`;
8
+ /** Cannot share the Cluster's name, nor `<cluster>-rw`, which the Cluster's own Service takes. */
9
+ export const poolerName = (database) => `${clusterName(database)}-pooler`;
10
+ /** The folder under the backup bucket that holds one Database's base backups and WAL. */
11
+ export const backupPrefix = (projectId, databaseId) => `${projectNamespace(projectId)}/${clusterName({ id: databaseId })}/`;
12
+ /** Ids are lowercase UUIDs, as Postgres prints them; usable in DNS names. */
13
+ export const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
14
+ /** Project and Database names, and label values: a DNS label (the schema checks the same). */
15
+ export const DNS_LABEL = /^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$/;
16
+ /** Audience of the ServiceAccount tokens the operators send. */
17
+ export const INTERNAL_API_AUDIENCE = 'openupstream-control-plane';
18
+ /** `GET` lists every Database with its Project. */
19
+ export const INTERNAL_DATABASES_PATH = '/internal/v1/databases';
20
+ /**
21
+ * `GET <path>/<account id>`: the Account with its Holds and Members.
22
+ * `PUT` and `DELETE <path>/<account id>/holds/<reason>`: place or lift a
23
+ * Hold; both answer 204 whether or not the Hold was there. A reason is a
24
+ * DNS label.
25
+ */
26
+ export const INTERNAL_ACCOUNTS_PATH = '/internal/v1/accounts';
27
+ /**
28
+ * The platform's own Account, Project and Databases: the control plane's
29
+ * state (`database`) and madAuth's users (`authDatabase`). The bootstrap
30
+ * creates these Databases once; the control plane seeds these rows at
31
+ * startup, and from then on the operator reconciles them like any
32
+ * customer's. Fixed ids, so bootstrap and control plane agree.
33
+ */
34
+ export const PLATFORM = {
35
+ account: {
36
+ id: '00000000-0000-4000-8000-000000000001',
37
+ name: 'openupstream',
38
+ createdAt: '2026-10-17T00:00:00Z',
39
+ },
40
+ project: {
41
+ id: '00000000-0000-4000-8000-000000000002',
42
+ accountId: '00000000-0000-4000-8000-000000000001',
43
+ name: 'platform',
44
+ createdAt: '2026-10-17T00:00:00Z',
45
+ },
46
+ database: {
47
+ id: '00000000-0000-4000-8000-000000000003',
48
+ projectId: '00000000-0000-4000-8000-000000000002',
49
+ name: 'control-plane',
50
+ homeSite: 'hetzner-fsn1',
51
+ memoryMb: 512,
52
+ storageGb: 5,
53
+ createdAt: '2026-10-17T00:00:00Z',
54
+ },
55
+ authDatabase: {
56
+ id: '00000000-0000-4000-8000-000000000004',
57
+ projectId: '00000000-0000-4000-8000-000000000002',
58
+ name: 'auth',
59
+ homeSite: 'hetzner-fsn1',
60
+ memoryMb: 512,
61
+ storageGb: 2,
62
+ createdAt: '2026-10-17T00:00:00Z',
63
+ },
64
+ /** The billing service's state; seeded only where a billing service runs (BILLING_CALLERS). */
65
+ billingDatabase: {
66
+ id: '00000000-0000-4000-8000-000000000005',
67
+ projectId: '00000000-0000-4000-8000-000000000002',
68
+ name: 'billing',
69
+ homeSite: 'hetzner-fsn1',
70
+ memoryMb: 512,
71
+ storageGb: 2,
72
+ createdAt: '2026-10-20T00:00:00Z',
73
+ },
74
+ };
75
+ /** The platform's Database rows, as the operator gets them. */
76
+ export const PLATFORM_ROWS = [
77
+ { project: PLATFORM.project, database: PLATFORM.database },
78
+ { project: PLATFORM.project, database: PLATFORM.authDatabase },
79
+ ];
80
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +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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E,QAAQ,CAAC,YAAY,EAAE;CACjE,CAAC"}
@@ -0,0 +1,214 @@
1
+ /**
2
+ * The objects of the openupstream API. Terms follow GLOSSARY.md; the control
3
+ * plane's schema (control-plane/migrations) stores exactly these.
4
+ *
5
+ * Ids are UUIDs, timestamps RFC 3339 strings.
6
+ */
7
+ export type Id = string;
8
+ export type Timestamp = string;
9
+ /** Compute Sites, where Databases and Services run. Both are in Germany. */
10
+ export declare const COMPUTE_SITES: readonly ["hetzner-fsn1", "ovh-lim"];
11
+ export type Site = (typeof COMPUTE_SITES)[number];
12
+ /** The customer: pays, receives one invoice, owns Projects. */
13
+ export interface Account {
14
+ id: Id;
15
+ name: string;
16
+ createdAt: Timestamp;
17
+ /**
18
+ * Why the Account may not create Resources now, e.g. `payment-method`;
19
+ * empty when it may. Existing Resources keep running.
20
+ */
21
+ holds: string[];
22
+ }
23
+ /** A person who can sign in to an Account. Sign-in is madAuth's. */
24
+ export interface Member {
25
+ id: Id;
26
+ accountId: Id;
27
+ /** The madAuth subject this Member signs in as. */
28
+ authSubject: string;
29
+ email: string;
30
+ createdAt: Timestamp;
31
+ }
32
+ /** The unit of isolation and lifecycle; deleting it deletes everything in it. */
33
+ export interface Project {
34
+ id: Id;
35
+ accountId: Id;
36
+ /** DNS label, unique within the Account. */
37
+ name: string;
38
+ createdAt: Timestamp;
39
+ }
40
+ /** Postgres always runs with at least this much memory. */
41
+ export declare const DATABASE_MIN_MEMORY_MB = 256;
42
+ export interface Database {
43
+ id: Id;
44
+ projectId: Id;
45
+ /** DNS label, unique within the Project. */
46
+ name: string;
47
+ /** Where the primary runs when nothing has failed. */
48
+ homeSite: Site;
49
+ memoryMb: number;
50
+ storageGb: number;
51
+ createdAt: Timestamp;
52
+ }
53
+ /** Creates an Account; the caller becomes its first Member. */
54
+ export interface AccountInput {
55
+ name: string;
56
+ }
57
+ /**
58
+ * What an API key may do (madAuth API keys, created by the Member): `read`
59
+ * allows every GET, `write` everything. A Member's own session may do
60
+ * everything.
61
+ */
62
+ export declare const API_KEY_SCOPES: {
63
+ readonly read: "openupstream:read";
64
+ readonly write: "openupstream:write";
65
+ };
66
+ /** Creates a Project in one of the caller's Accounts. */
67
+ export interface ProjectInput {
68
+ accountId: Id;
69
+ name: string;
70
+ }
71
+ /** Creates a Database; homeSite defaults to `hetzner-fsn1`. */
72
+ export interface DatabaseInput {
73
+ name: string;
74
+ homeSite?: Site;
75
+ memoryMb: number;
76
+ storageGb: number;
77
+ }
78
+ /**
79
+ * - `provisioning`: being created, or not yet seen by the operator
80
+ * - `ready`: both instances healthy
81
+ * - `degraded`: running, but not every instance is healthy (e.g. during a
82
+ * failover)
83
+ * - `unknown`: the platform could not check just now
84
+ */
85
+ export type DatabaseState = 'provisioning' | 'ready' | 'degraded' | 'unknown';
86
+ /**
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.
90
+ */
91
+ export interface DatabaseConnection {
92
+ host: string;
93
+ port: number;
94
+ database: string;
95
+ user: string;
96
+ }
97
+ /** A Database as the API returns it. */
98
+ export interface DatabaseDetails extends Database {
99
+ state: DatabaseState;
100
+ connection: DatabaseConnection;
101
+ }
102
+ export interface Bucket {
103
+ id: Id;
104
+ projectId: Id;
105
+ /** Globally unique: it is the hostname `<name>.s3.<customer domain>`. */
106
+ name: string;
107
+ createdAt: Timestamp;
108
+ }
109
+ export interface Service {
110
+ id: Id;
111
+ projectId: Id;
112
+ /** DNS label, unique within the Project. */
113
+ name: string;
114
+ /** The image reference as given, from any registry. */
115
+ image: string;
116
+ /** `sha256:…`, pinned when the image is deployed; null before the first deploy. */
117
+ imageDigest: string | null;
118
+ replicas: number;
119
+ memoryMb: number;
120
+ cpuMillicores: number;
121
+ /** The HTTP port the container listens on. */
122
+ port: number;
123
+ createdAt: Timestamp;
124
+ }
125
+ /**
126
+ * A Secret's value is write-only: the API accepts it and hands it to the
127
+ * Project's Services and jobs as an environment variable, but never returns it.
128
+ */
129
+ export interface Secret {
130
+ id: Id;
131
+ projectId: Id;
132
+ /** Environment variable name, unique within the Project. */
133
+ name: string;
134
+ createdAt: Timestamp;
135
+ updatedAt: Timestamp;
136
+ }
137
+ export interface SecretInput {
138
+ name: string;
139
+ value: string;
140
+ }
141
+ /** The TXT record that proves an Account owns a custom domain. */
142
+ export interface TxtRecord {
143
+ name: string;
144
+ value: string;
145
+ }
146
+ export type DomainVerification = {
147
+ state: 'pending';
148
+ txtRecord: TxtRecord;
149
+ } | {
150
+ state: 'verified';
151
+ verifiedAt: Timestamp;
152
+ };
153
+ interface DomainBase {
154
+ id: Id;
155
+ projectId: Id;
156
+ /** Lowercase hostname. Only one verified Domain per hostname exists. */
157
+ hostname: string;
158
+ createdAt: Timestamp;
159
+ }
160
+ /** The Project's hostname under the platform's customer domain; always routed. */
161
+ export interface DefaultDomain extends DomainBase {
162
+ kind: 'default';
163
+ }
164
+ /**
165
+ * A hostname the Account claims. Routed only once verified; any number of
166
+ * Projects can hold a pending claim, the first proof wins.
167
+ */
168
+ export interface CustomDomain extends DomainBase {
169
+ kind: 'custom';
170
+ verification: DomainVerification;
171
+ }
172
+ export type Domain = DefaultDomain | CustomDomain;
173
+ /** Where the TXT ownership proof for `hostname` has to be published. */
174
+ export declare function txtRecordName(hostname: string): string;
175
+ export type RouteTarget = {
176
+ kind: 'bucket';
177
+ bucketId: Id;
178
+ spaFallback: boolean;
179
+ } | {
180
+ kind: 'service';
181
+ serviceId: Id;
182
+ };
183
+ /**
184
+ * One entry under a Domain: everything below `pathPrefix` goes to a Bucket or
185
+ * a Service of the Domain's Project.
186
+ */
187
+ export interface Route {
188
+ id: Id;
189
+ domainId: Id;
190
+ /** `/` or `/segment[/segment…]`, no trailing slash. Unique per Domain. */
191
+ pathPrefix: string;
192
+ target: RouteTarget;
193
+ createdAt: Timestamp;
194
+ }
195
+ export declare const RESOURCE_KINDS: readonly ["database", "bucket", "service"];
196
+ export type ResourceKind = (typeof RESOURCE_KINDS)[number];
197
+ export declare const USAGE_UNITS: readonly ["cpu_seconds", "memory_gb_hours", "storage_gb_hours", "egress_gb"];
198
+ export type UsageUnit = (typeof USAGE_UNITS)[number];
199
+ /** A Resource consumed `quantity` of `unit` between `intervalStart` and `intervalEnd`. */
200
+ export interface UsageEvent {
201
+ id: string;
202
+ accountId: Id;
203
+ projectId: Id;
204
+ resource: {
205
+ kind: ResourceKind;
206
+ id: Id;
207
+ };
208
+ unit: UsageUnit;
209
+ quantity: number;
210
+ intervalStart: Timestamp;
211
+ intervalEnd: Timestamp;
212
+ recordedAt: Timestamp;
213
+ }
214
+ export {};
package/dist/model.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The objects of the openupstream API. Terms follow GLOSSARY.md; the control
3
+ * plane's schema (control-plane/migrations) stores exactly these.
4
+ *
5
+ * Ids are UUIDs, timestamps RFC 3339 strings.
6
+ */
7
+ /** Compute Sites, where Databases and Services run. Both are in Germany. */
8
+ export const COMPUTE_SITES = ['hetzner-fsn1', 'ovh-lim'];
9
+ /** Postgres always runs with at least this much memory. */
10
+ export const DATABASE_MIN_MEMORY_MB = 256;
11
+ /**
12
+ * What an API key may do (madAuth API keys, created by the Member): `read`
13
+ * allows every GET, `write` everything. A Member's own session may do
14
+ * everything.
15
+ */
16
+ export const API_KEY_SCOPES = {
17
+ read: 'openupstream:read',
18
+ write: 'openupstream:write',
19
+ };
20
+ /** Where the TXT ownership proof for `hostname` has to be published. */
21
+ export function txtRecordName(hostname) {
22
+ return `_openupstream.${hostname}`;
23
+ }
24
+ export const RESOURCE_KINDS = ['database', 'bucket', 'service'];
25
+ export const USAGE_UNITS = ['cpu_seconds', 'memory_gb_hours', 'storage_gb_hours', 'egress_gb'];
26
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,cAAc,EAAE,SAAS,CAAU,CAAC;AAkClE,2DAA2D;AAC3D,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAmB1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,IAAI,EAAE,mBAAmB;IACzB,KAAK,EAAE,oBAAoB;CACrB,CAAC;AAwHX,wEAAwE;AACxE,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC1C,OAAO,iBAAiB,QAAQ,EAAE,CAAC;AACvC,CAAC;AAmBD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC;AAGzE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,CAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@openupstream/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "TypeScript client for the openupstream API",
5
+ "license": "AGPL-3.0-only",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/openupstream/openupstream.git",
9
+ "directory": "sdk"
10
+ },
11
+ "homepage": "https://github.com/openupstream/openupstream/tree/main/sdk",
12
+ "private": false,
13
+ "type": "module",
14
+ "main": "dist/index.js",
15
+ "types": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "tsc -p tsconfig.json",
30
+ "typecheck": "tsc -p tsconfig.json --noEmit",
31
+ "test": "node --test --import tsx 'src/**/*.test.ts'"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^22.10.0",
35
+ "tsx": "^4.19.0",
36
+ "typescript": "^5.7.0"
37
+ }
38
+ }