@pontive/server 0.0.0-stage → 1.23.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 +146 -2
- package/dist/auth.d.cts +34 -0
- package/dist/auth.d.ts +34 -0
- package/dist/authorization.cjs +2 -0
- package/dist/authorization.cjs.map +1 -0
- package/dist/authorization.d.cts +222 -0
- package/dist/authorization.d.ts +222 -0
- package/dist/authorization.js +153 -0
- package/dist/authorization.js.map +1 -0
- package/dist/browser-mode.d.cts +23 -0
- package/dist/browser-mode.d.ts +23 -0
- package/dist/config.d.cts +131 -0
- package/dist/config.d.ts +131 -0
- package/dist/cookies.d.cts +50 -0
- package/dist/cookies.d.ts +50 -0
- package/dist/env.d.cts +44 -0
- package/dist/env.d.ts +44 -0
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +700 -0
- package/dist/index.js.map +1 -0
- package/dist/keyless.cjs +16 -0
- package/dist/keyless.cjs.map +1 -0
- package/dist/keyless.d.cts +244 -0
- package/dist/keyless.d.ts +244 -0
- package/dist/keyless.js +355 -0
- package/dist/keyless.js.map +1 -0
- package/dist/management-credential-BNyhHagG.cjs +2 -0
- package/dist/management-credential-BNyhHagG.cjs.map +1 -0
- package/dist/management-credential-VhmMzGDl.js +39 -0
- package/dist/management-credential-VhmMzGDl.js.map +1 -0
- package/dist/management-credential.d.cts +40 -0
- package/dist/management-credential.d.ts +40 -0
- package/dist/mcp-auth-info-BGyWua_9.js +19 -0
- package/dist/mcp-auth-info-BGyWua_9.js.map +1 -0
- package/dist/mcp-auth-info-jblMsSJo.cjs +2 -0
- package/dist/mcp-auth-info-jblMsSJo.cjs.map +1 -0
- package/dist/mcp-auth-info.d.cts +17 -0
- package/dist/mcp-auth-info.d.ts +17 -0
- package/dist/oidc--We55Nrh.cjs +2 -0
- package/dist/oidc--We55Nrh.cjs.map +1 -0
- package/dist/oidc-CB0FqjFz.js +131 -0
- package/dist/oidc-CB0FqjFz.js.map +1 -0
- package/dist/oidc.d.cts +80 -0
- package/dist/oidc.d.ts +80 -0
- package/dist/organization.d.cts +35 -0
- package/dist/organization.d.ts +35 -0
- package/dist/preview-hosts.d.cts +33 -0
- package/dist/preview-hosts.d.ts +33 -0
- package/dist/refresh.d.cts +28 -0
- package/dist/refresh.d.ts +28 -0
- package/dist/resource-server-express.cjs +2 -0
- package/dist/resource-server-express.cjs.map +1 -0
- package/dist/resource-server-express.d.cts +73 -0
- package/dist/resource-server-express.d.ts +73 -0
- package/dist/resource-server-express.js +57 -0
- package/dist/resource-server-express.js.map +1 -0
- package/dist/resource-server-mcp.cjs +2 -0
- package/dist/resource-server-mcp.cjs.map +1 -0
- package/dist/resource-server-mcp.d.cts +70 -0
- package/dist/resource-server-mcp.d.ts +70 -0
- package/dist/resource-server-mcp.js +59 -0
- package/dist/resource-server-mcp.js.map +1 -0
- package/dist/resource-server.cjs +2 -0
- package/dist/resource-server.cjs.map +1 -0
- package/dist/resource-server.d.cts +290 -0
- package/dist/resource-server.d.ts +290 -0
- package/dist/resource-server.js +301 -0
- package/dist/resource-server.js.map +1 -0
- package/dist/seal.d.cts +3 -0
- package/dist/seal.d.ts +3 -0
- package/dist/server-auth.d.cts +100 -0
- package/dist/server-auth.d.ts +100 -0
- package/package.json +96 -4
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyless mode's building blocks (pontive-spec 47 §5.1, §6.2, §7.2): creating
|
|
3
|
+
* an unclaimed development instance with no Pontive account, keeping what the
|
|
4
|
+
* app needs on the developer's machine, and minting claim links.
|
|
5
|
+
*
|
|
6
|
+
* `createServerAuth` uses them when it runs in development with no issuer, and
|
|
7
|
+
* the `pontive` CLI imports them from `@pontive/server/keyless`, so the
|
|
8
|
+
* dev server and the CLI write the same files the same way:
|
|
9
|
+
*
|
|
10
|
+
* - `.env.local`: the §6.1 variables, **appended**; a `PONTIVE_*` line already
|
|
11
|
+
* there is never overwritten.
|
|
12
|
+
* - `.pontive/keyless.json`: `{ instance_id, issuer, app_id, claim_token,
|
|
13
|
+
* expires_at, region }`, the claim token being the instance's ownership.
|
|
14
|
+
* - `.pontive/keyless.lock`: held while provisioning, so two dev workers never
|
|
15
|
+
* create two instances.
|
|
16
|
+
* - `.gitignore`: lists `.env.local` and `.pontive/`.
|
|
17
|
+
*
|
|
18
|
+
* Secrets are never logged: the console message names the instance, its region
|
|
19
|
+
* and its deletion date, nothing else.
|
|
20
|
+
*
|
|
21
|
+
* The Node built-ins are reached through `process.getBuiltinModule` (Node
|
|
22
|
+
* 20.16+, 22.3+), not imported: this module is part of the server entry, which
|
|
23
|
+
* edge runtimes load too, and there it must load without a file system.
|
|
24
|
+
*/
|
|
25
|
+
/** Where the provisioning routes live when `PONTIVE_API_URL` does not say. */
|
|
26
|
+
export declare const DEFAULT_API_URL = "https://api.pontive.com";
|
|
27
|
+
/** The directory keyless mode keeps its files in, under the project root. */
|
|
28
|
+
export declare const KEYLESS_DIR = ".pontive";
|
|
29
|
+
/** The instance's record, under the project root. */
|
|
30
|
+
export declare const KEYLESS_FILE = ".pontive/keyless.json";
|
|
31
|
+
/** The provisioning lock, under the project root. */
|
|
32
|
+
export declare const KEYLESS_LOCK = ".pontive/keyless.lock";
|
|
33
|
+
/** The env file keyless mode appends to, under the project root. */
|
|
34
|
+
export declare const ENV_FILE = ".env.local";
|
|
35
|
+
/** What `.gitignore` must list. */
|
|
36
|
+
export declare const GITIGNORE_ENTRIES: readonly [".env.local", ".pontive/"];
|
|
37
|
+
/** The docs page on unclaimed instances. */
|
|
38
|
+
export declare const UNCLAIMED_DOCS_URL = "https://www.pontive.com/docs/unclaimed-instances";
|
|
39
|
+
/** `POST /v1/unclaimed-instances`'s body. Every field is optional. */
|
|
40
|
+
export interface CreateUnclaimedInstanceRequest {
|
|
41
|
+
name?: string;
|
|
42
|
+
/** `us`, `eu`, `au`; default: the region nearest the caller. */
|
|
43
|
+
region?: string;
|
|
44
|
+
tenancy_mode?: "b2c" | "b2b";
|
|
45
|
+
app?: {
|
|
46
|
+
type?: "web" | "spa" | "native";
|
|
47
|
+
/** Loopback only. Without a port, any port matches on a non-production instance. */
|
|
48
|
+
redirect_uris?: string[];
|
|
49
|
+
};
|
|
50
|
+
/** A public JWK (`EC` P-256 or `OKP` X25519): the secrets come back as a JWE in `encrypted_secrets`. */
|
|
51
|
+
encryption_key?: Record<string, unknown>;
|
|
52
|
+
/** The tool, its version and, when detected, the agent: metrics and abuse signals only. */
|
|
53
|
+
client?: {
|
|
54
|
+
name: string;
|
|
55
|
+
version: string;
|
|
56
|
+
agent?: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** `POST /v1/unclaimed-instances`'s `201`. */
|
|
60
|
+
export interface UnclaimedInstance {
|
|
61
|
+
object: "unclaimed_instance";
|
|
62
|
+
instance_id: string;
|
|
63
|
+
project_id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
region: string;
|
|
66
|
+
environment: string;
|
|
67
|
+
tenancy_mode: string;
|
|
68
|
+
issuer: string;
|
|
69
|
+
app_id: string;
|
|
70
|
+
/** A `web` app's client secret; absent with `encryption_key`. */
|
|
71
|
+
client_secret?: string;
|
|
72
|
+
/** The `keyless` developer secret key; absent with `encryption_key`. */
|
|
73
|
+
secret_key?: string;
|
|
74
|
+
secret_key_id: string;
|
|
75
|
+
/** Returned once; absent with `encryption_key`. */
|
|
76
|
+
claim_token?: string;
|
|
77
|
+
/** With `encryption_key`: a compact JWE of `{ client_secret, secret_key, claim_token }`. */
|
|
78
|
+
encrypted_secrets?: string;
|
|
79
|
+
expires_at: string;
|
|
80
|
+
limits_url?: string;
|
|
81
|
+
}
|
|
82
|
+
/** `GET /v1/unclaimed-instances/{instance_id}` with the claim token. */
|
|
83
|
+
export interface UnclaimedInstanceStatus {
|
|
84
|
+
object: "unclaimed_instance";
|
|
85
|
+
instance_id: string;
|
|
86
|
+
status: "unclaimed" | "claimed";
|
|
87
|
+
claimed_at: string | null;
|
|
88
|
+
expires_at?: string;
|
|
89
|
+
[field: string]: unknown;
|
|
90
|
+
}
|
|
91
|
+
/** `POST /v1/unclaimed-instances/{instance_id}/claim-links`'s `201`. */
|
|
92
|
+
export interface ClaimLink {
|
|
93
|
+
object: "claim_link";
|
|
94
|
+
/** `https://app.pontive.com/claim/{instance_id}#code=…`: single use, one hour. */
|
|
95
|
+
url: string;
|
|
96
|
+
expires_at: string;
|
|
97
|
+
}
|
|
98
|
+
/** A refusal from the Pontive API, in its standard envelope. */
|
|
99
|
+
export declare class PontiveApiError extends Error {
|
|
100
|
+
readonly status: number;
|
|
101
|
+
/** The envelope's `code` (`unclaimed_instance_limit`, `instance_claimed` …), when it had one. */
|
|
102
|
+
readonly code: string | undefined;
|
|
103
|
+
/** Seconds, from `Retry-After`, when the API sent one. */
|
|
104
|
+
readonly retryAfter: number | undefined;
|
|
105
|
+
constructor(status: number, code: string | undefined, message: string, retryAfter?: number);
|
|
106
|
+
}
|
|
107
|
+
export interface ApiOptions {
|
|
108
|
+
/** Default `PONTIVE_API_URL`, else `https://api.pontive.com`. */
|
|
109
|
+
apiUrl?: string;
|
|
110
|
+
/** Default the global `fetch`. */
|
|
111
|
+
fetch?: typeof fetch;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* `POST /v1/unclaimed-instances` (unauthenticated). Sends `X-Idempotency-Key`
|
|
115
|
+
* (generated when not given) and retries once, with the same key, on a
|
|
116
|
+
* network failure or a 500, 502 or 504: a retry within 24 hours returns the
|
|
117
|
+
* same instance and counts once against the caller's limit.
|
|
118
|
+
*/
|
|
119
|
+
export declare function createUnclaimedInstance(body: CreateUnclaimedInstanceRequest, options?: ApiOptions & {
|
|
120
|
+
idempotencyKey?: string;
|
|
121
|
+
}): Promise<UnclaimedInstance>;
|
|
122
|
+
/** `POST /v1/unclaimed-instances/{instance_id}/claim-links`, with the claim token in `X-Pontive-Claim-Token`. */
|
|
123
|
+
export declare function createClaimLink(instanceId: string, claimToken: string, options?: ApiOptions): Promise<ClaimLink>;
|
|
124
|
+
/** `GET /v1/unclaimed-instances/{instance_id}` with the claim token: its status, for polling. */
|
|
125
|
+
export declare function getUnclaimedInstance(instanceId: string, claimToken: string, options?: ApiOptions): Promise<UnclaimedInstanceStatus>;
|
|
126
|
+
/** `.pontive/keyless.json`. `claim_token` is gone once the instance is claimed (`pontive claim` removes it). */
|
|
127
|
+
export interface KeylessRecord {
|
|
128
|
+
instance_id: string;
|
|
129
|
+
issuer: string;
|
|
130
|
+
app_id: string;
|
|
131
|
+
claim_token?: string;
|
|
132
|
+
expires_at: string;
|
|
133
|
+
region: string;
|
|
134
|
+
}
|
|
135
|
+
/** Keyless mode needs a file system: thrown in a runtime without one (an edge runtime). */
|
|
136
|
+
export declare class KeylessUnavailableError extends Error {
|
|
137
|
+
constructor(message?: string);
|
|
138
|
+
}
|
|
139
|
+
/** The unclaimed instance this project uses has expired (Pontive deleted it) or was claimed away. */
|
|
140
|
+
export declare class KeylessInstanceGoneError extends Error {
|
|
141
|
+
readonly record: KeylessRecord;
|
|
142
|
+
constructor(record: KeylessRecord, message: string);
|
|
143
|
+
}
|
|
144
|
+
type Fs = typeof import("node:fs/promises");
|
|
145
|
+
type Path = typeof import("node:path");
|
|
146
|
+
interface NodeApis {
|
|
147
|
+
fs: Fs;
|
|
148
|
+
path: Path;
|
|
149
|
+
}
|
|
150
|
+
/** `fs/promises` and `path`, or KeylessUnavailableError. */
|
|
151
|
+
export declare function nodeApis(): NodeApis;
|
|
152
|
+
/** The project's `.pontive/keyless.json`, or null when there is none. Throws on a file that is not a record. */
|
|
153
|
+
export declare function readKeylessRecord(dir: string): Promise<KeylessRecord | null>;
|
|
154
|
+
/** Writes `.pontive/keyless.json` (owner-only: it holds the claim token). */
|
|
155
|
+
export declare function writeKeylessRecord(dir: string, record: KeylessRecord): Promise<void>;
|
|
156
|
+
/** Whether the record's instance is past its deletion date. */
|
|
157
|
+
export declare function keylessExpired(record: KeylessRecord, now?: number): boolean;
|
|
158
|
+
/** The `KEY=value` lines of an env file (`export `, quotes and comments handled), or an empty map. */
|
|
159
|
+
export declare function parseEnvFile(text: string): Map<string, string>;
|
|
160
|
+
/** The project's `.env.local`, parsed; empty when there is none. */
|
|
161
|
+
export declare function readEnvLocal(dir: string): Promise<Map<string, string>>;
|
|
162
|
+
/**
|
|
163
|
+
* Appends variables to `.env.local`, creating it when missing. A variable the
|
|
164
|
+
* file already sets is never overwritten: it is reported in `skipped`.
|
|
165
|
+
*/
|
|
166
|
+
export declare function appendEnvLocal(dir: string, vars: Readonly<Record<string, string | undefined>>, options?: {
|
|
167
|
+
comment?: string;
|
|
168
|
+
}): Promise<{
|
|
169
|
+
written: string[];
|
|
170
|
+
skipped: string[];
|
|
171
|
+
}>;
|
|
172
|
+
/** Makes sure `.gitignore` lists `.env.local` and `.pontive/`, creating it when missing. Returns what it added. */
|
|
173
|
+
export declare function ensureGitignore(dir: string, entries?: readonly string[]): Promise<string[]>;
|
|
174
|
+
/** 32 random bytes, base64url: a `PONTIVE_SESSION_SECRET` (43 characters), generated locally, never by Pontive. */
|
|
175
|
+
export declare function generateSessionSecret(): string;
|
|
176
|
+
export interface LockOptions {
|
|
177
|
+
/** Give up waiting for another holder after this long. Default 60 s. */
|
|
178
|
+
timeoutMs?: number;
|
|
179
|
+
/** A lock older than this is a crashed holder's, and is taken over. Default 2 minutes. */
|
|
180
|
+
staleMs?: number;
|
|
181
|
+
/** How often to look again while another process holds it. Default 200 ms. */
|
|
182
|
+
pollMs?: number;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Runs `fn` holding `.pontive/keyless.lock`, created exclusively (`wx`), so
|
|
186
|
+
* two processes (two dev workers, the dev server and the CLI) never provision
|
|
187
|
+
* at once. A waiter re-reads `keyless.json` inside `fn` and finds the other's
|
|
188
|
+
* instance. A lock left by a crashed process is taken over after `staleMs`.
|
|
189
|
+
*/
|
|
190
|
+
export declare function withKeylessLock<T>(dir: string, fn: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
191
|
+
/** The §6.1 variables for a provisioned instance (only those it has). */
|
|
192
|
+
export declare function envVarsFor(instance: UnclaimedInstance, sessionSecret: string): Record<string, string | undefined>;
|
|
193
|
+
/** The default redirect URIs for a dev server's callback route: port-less loopback, which matches any port (decision E5). */
|
|
194
|
+
export declare function loopbackCallbacks(basePath?: string): string[];
|
|
195
|
+
export interface ProvisionOptions extends ApiOptions {
|
|
196
|
+
/** The project root. */
|
|
197
|
+
dir: string;
|
|
198
|
+
/** Sent as `app.redirect_uris` (loopback only). */
|
|
199
|
+
redirectUris: string[];
|
|
200
|
+
/** Sent as `client`. */
|
|
201
|
+
client: {
|
|
202
|
+
name: string;
|
|
203
|
+
version: string;
|
|
204
|
+
agent?: string;
|
|
205
|
+
};
|
|
206
|
+
/** Default `PONTIVE_REGION`, else the API picks the region nearest the caller. */
|
|
207
|
+
region?: string;
|
|
208
|
+
/** The project's name. */
|
|
209
|
+
name?: string;
|
|
210
|
+
app?: CreateUnclaimedInstanceRequest["app"];
|
|
211
|
+
tenancyMode?: "b2c" | "b2b";
|
|
212
|
+
lock?: LockOptions;
|
|
213
|
+
}
|
|
214
|
+
export interface KeylessInstance {
|
|
215
|
+
record: KeylessRecord;
|
|
216
|
+
/** The §6.1 values: what was just written, or what `.env.local` and the environment hold for a reused instance. */
|
|
217
|
+
env: Record<string, string | undefined>;
|
|
218
|
+
/** Created by this call (false: an existing `keyless.json` was reused). */
|
|
219
|
+
created: boolean;
|
|
220
|
+
}
|
|
221
|
+
/** The message for an instance that is no longer there, and what to do. */
|
|
222
|
+
export declare function goneMessage(record: KeylessRecord, why: "expired" | "refused"): string;
|
|
223
|
+
/**
|
|
224
|
+
* The project's unclaimed instance: `keyless.json`'s when it is there and not
|
|
225
|
+
* expired; otherwise created now, under the lock, and written to `.env.local`
|
|
226
|
+
* (appended), `keyless.json` and `.gitignore`.
|
|
227
|
+
*
|
|
228
|
+
* An expired `keyless.json` throws `KeylessInstanceGoneError`: never a second
|
|
229
|
+
* instance silently over the first. Pass `reset: true` (`pontive init
|
|
230
|
+
* --reset`) to replace it.
|
|
231
|
+
*/
|
|
232
|
+
export declare function ensureKeylessInstance(options: ProvisionOptions & {
|
|
233
|
+
reset?: boolean;
|
|
234
|
+
}): Promise<KeylessInstance>;
|
|
235
|
+
/**
|
|
236
|
+
* Mints a claim link for the project's unclaimed instance with the claim
|
|
237
|
+
* token in `keyless.json`. The token itself never leaves the machine.
|
|
238
|
+
*/
|
|
239
|
+
export declare function claimLinkFor(record: KeylessRecord, options?: ApiOptions): Promise<ClaimLink>;
|
|
240
|
+
/** The one boxed console message (no secrets): the instance is unclaimed, when it is deleted, and how to claim it. */
|
|
241
|
+
export declare function keylessMessage(record: KeylessRecord, options?: {
|
|
242
|
+
created?: boolean;
|
|
243
|
+
}): string;
|
|
244
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyless mode's building blocks (pontive-spec 47 §5.1, §6.2, §7.2): creating
|
|
3
|
+
* an unclaimed development instance with no Pontive account, keeping what the
|
|
4
|
+
* app needs on the developer's machine, and minting claim links.
|
|
5
|
+
*
|
|
6
|
+
* `createServerAuth` uses them when it runs in development with no issuer, and
|
|
7
|
+
* the `pontive` CLI imports them from `@pontive/server/keyless`, so the
|
|
8
|
+
* dev server and the CLI write the same files the same way:
|
|
9
|
+
*
|
|
10
|
+
* - `.env.local`: the §6.1 variables, **appended**; a `PONTIVE_*` line already
|
|
11
|
+
* there is never overwritten.
|
|
12
|
+
* - `.pontive/keyless.json`: `{ instance_id, issuer, app_id, claim_token,
|
|
13
|
+
* expires_at, region }`, the claim token being the instance's ownership.
|
|
14
|
+
* - `.pontive/keyless.lock`: held while provisioning, so two dev workers never
|
|
15
|
+
* create two instances.
|
|
16
|
+
* - `.gitignore`: lists `.env.local` and `.pontive/`.
|
|
17
|
+
*
|
|
18
|
+
* Secrets are never logged: the console message names the instance, its region
|
|
19
|
+
* and its deletion date, nothing else.
|
|
20
|
+
*
|
|
21
|
+
* The Node built-ins are reached through `process.getBuiltinModule` (Node
|
|
22
|
+
* 20.16+, 22.3+), not imported: this module is part of the server entry, which
|
|
23
|
+
* edge runtimes load too, and there it must load without a file system.
|
|
24
|
+
*/
|
|
25
|
+
/** Where the provisioning routes live when `PONTIVE_API_URL` does not say. */
|
|
26
|
+
export declare const DEFAULT_API_URL = "https://api.pontive.com";
|
|
27
|
+
/** The directory keyless mode keeps its files in, under the project root. */
|
|
28
|
+
export declare const KEYLESS_DIR = ".pontive";
|
|
29
|
+
/** The instance's record, under the project root. */
|
|
30
|
+
export declare const KEYLESS_FILE = ".pontive/keyless.json";
|
|
31
|
+
/** The provisioning lock, under the project root. */
|
|
32
|
+
export declare const KEYLESS_LOCK = ".pontive/keyless.lock";
|
|
33
|
+
/** The env file keyless mode appends to, under the project root. */
|
|
34
|
+
export declare const ENV_FILE = ".env.local";
|
|
35
|
+
/** What `.gitignore` must list. */
|
|
36
|
+
export declare const GITIGNORE_ENTRIES: readonly [".env.local", ".pontive/"];
|
|
37
|
+
/** The docs page on unclaimed instances. */
|
|
38
|
+
export declare const UNCLAIMED_DOCS_URL = "https://www.pontive.com/docs/unclaimed-instances";
|
|
39
|
+
/** `POST /v1/unclaimed-instances`'s body. Every field is optional. */
|
|
40
|
+
export interface CreateUnclaimedInstanceRequest {
|
|
41
|
+
name?: string;
|
|
42
|
+
/** `us`, `eu`, `au`; default: the region nearest the caller. */
|
|
43
|
+
region?: string;
|
|
44
|
+
tenancy_mode?: "b2c" | "b2b";
|
|
45
|
+
app?: {
|
|
46
|
+
type?: "web" | "spa" | "native";
|
|
47
|
+
/** Loopback only. Without a port, any port matches on a non-production instance. */
|
|
48
|
+
redirect_uris?: string[];
|
|
49
|
+
};
|
|
50
|
+
/** A public JWK (`EC` P-256 or `OKP` X25519): the secrets come back as a JWE in `encrypted_secrets`. */
|
|
51
|
+
encryption_key?: Record<string, unknown>;
|
|
52
|
+
/** The tool, its version and, when detected, the agent: metrics and abuse signals only. */
|
|
53
|
+
client?: {
|
|
54
|
+
name: string;
|
|
55
|
+
version: string;
|
|
56
|
+
agent?: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** `POST /v1/unclaimed-instances`'s `201`. */
|
|
60
|
+
export interface UnclaimedInstance {
|
|
61
|
+
object: "unclaimed_instance";
|
|
62
|
+
instance_id: string;
|
|
63
|
+
project_id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
region: string;
|
|
66
|
+
environment: string;
|
|
67
|
+
tenancy_mode: string;
|
|
68
|
+
issuer: string;
|
|
69
|
+
app_id: string;
|
|
70
|
+
/** A `web` app's client secret; absent with `encryption_key`. */
|
|
71
|
+
client_secret?: string;
|
|
72
|
+
/** The `keyless` developer secret key; absent with `encryption_key`. */
|
|
73
|
+
secret_key?: string;
|
|
74
|
+
secret_key_id: string;
|
|
75
|
+
/** Returned once; absent with `encryption_key`. */
|
|
76
|
+
claim_token?: string;
|
|
77
|
+
/** With `encryption_key`: a compact JWE of `{ client_secret, secret_key, claim_token }`. */
|
|
78
|
+
encrypted_secrets?: string;
|
|
79
|
+
expires_at: string;
|
|
80
|
+
limits_url?: string;
|
|
81
|
+
}
|
|
82
|
+
/** `GET /v1/unclaimed-instances/{instance_id}` with the claim token. */
|
|
83
|
+
export interface UnclaimedInstanceStatus {
|
|
84
|
+
object: "unclaimed_instance";
|
|
85
|
+
instance_id: string;
|
|
86
|
+
status: "unclaimed" | "claimed";
|
|
87
|
+
claimed_at: string | null;
|
|
88
|
+
expires_at?: string;
|
|
89
|
+
[field: string]: unknown;
|
|
90
|
+
}
|
|
91
|
+
/** `POST /v1/unclaimed-instances/{instance_id}/claim-links`'s `201`. */
|
|
92
|
+
export interface ClaimLink {
|
|
93
|
+
object: "claim_link";
|
|
94
|
+
/** `https://app.pontive.com/claim/{instance_id}#code=…`: single use, one hour. */
|
|
95
|
+
url: string;
|
|
96
|
+
expires_at: string;
|
|
97
|
+
}
|
|
98
|
+
/** A refusal from the Pontive API, in its standard envelope. */
|
|
99
|
+
export declare class PontiveApiError extends Error {
|
|
100
|
+
readonly status: number;
|
|
101
|
+
/** The envelope's `code` (`unclaimed_instance_limit`, `instance_claimed` …), when it had one. */
|
|
102
|
+
readonly code: string | undefined;
|
|
103
|
+
/** Seconds, from `Retry-After`, when the API sent one. */
|
|
104
|
+
readonly retryAfter: number | undefined;
|
|
105
|
+
constructor(status: number, code: string | undefined, message: string, retryAfter?: number);
|
|
106
|
+
}
|
|
107
|
+
export interface ApiOptions {
|
|
108
|
+
/** Default `PONTIVE_API_URL`, else `https://api.pontive.com`. */
|
|
109
|
+
apiUrl?: string;
|
|
110
|
+
/** Default the global `fetch`. */
|
|
111
|
+
fetch?: typeof fetch;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* `POST /v1/unclaimed-instances` (unauthenticated). Sends `X-Idempotency-Key`
|
|
115
|
+
* (generated when not given) and retries once, with the same key, on a
|
|
116
|
+
* network failure or a 500, 502 or 504: a retry within 24 hours returns the
|
|
117
|
+
* same instance and counts once against the caller's limit.
|
|
118
|
+
*/
|
|
119
|
+
export declare function createUnclaimedInstance(body: CreateUnclaimedInstanceRequest, options?: ApiOptions & {
|
|
120
|
+
idempotencyKey?: string;
|
|
121
|
+
}): Promise<UnclaimedInstance>;
|
|
122
|
+
/** `POST /v1/unclaimed-instances/{instance_id}/claim-links`, with the claim token in `X-Pontive-Claim-Token`. */
|
|
123
|
+
export declare function createClaimLink(instanceId: string, claimToken: string, options?: ApiOptions): Promise<ClaimLink>;
|
|
124
|
+
/** `GET /v1/unclaimed-instances/{instance_id}` with the claim token: its status, for polling. */
|
|
125
|
+
export declare function getUnclaimedInstance(instanceId: string, claimToken: string, options?: ApiOptions): Promise<UnclaimedInstanceStatus>;
|
|
126
|
+
/** `.pontive/keyless.json`. `claim_token` is gone once the instance is claimed (`pontive claim` removes it). */
|
|
127
|
+
export interface KeylessRecord {
|
|
128
|
+
instance_id: string;
|
|
129
|
+
issuer: string;
|
|
130
|
+
app_id: string;
|
|
131
|
+
claim_token?: string;
|
|
132
|
+
expires_at: string;
|
|
133
|
+
region: string;
|
|
134
|
+
}
|
|
135
|
+
/** Keyless mode needs a file system: thrown in a runtime without one (an edge runtime). */
|
|
136
|
+
export declare class KeylessUnavailableError extends Error {
|
|
137
|
+
constructor(message?: string);
|
|
138
|
+
}
|
|
139
|
+
/** The unclaimed instance this project uses has expired (Pontive deleted it) or was claimed away. */
|
|
140
|
+
export declare class KeylessInstanceGoneError extends Error {
|
|
141
|
+
readonly record: KeylessRecord;
|
|
142
|
+
constructor(record: KeylessRecord, message: string);
|
|
143
|
+
}
|
|
144
|
+
type Fs = typeof import("node:fs/promises");
|
|
145
|
+
type Path = typeof import("node:path");
|
|
146
|
+
interface NodeApis {
|
|
147
|
+
fs: Fs;
|
|
148
|
+
path: Path;
|
|
149
|
+
}
|
|
150
|
+
/** `fs/promises` and `path`, or KeylessUnavailableError. */
|
|
151
|
+
export declare function nodeApis(): NodeApis;
|
|
152
|
+
/** The project's `.pontive/keyless.json`, or null when there is none. Throws on a file that is not a record. */
|
|
153
|
+
export declare function readKeylessRecord(dir: string): Promise<KeylessRecord | null>;
|
|
154
|
+
/** Writes `.pontive/keyless.json` (owner-only: it holds the claim token). */
|
|
155
|
+
export declare function writeKeylessRecord(dir: string, record: KeylessRecord): Promise<void>;
|
|
156
|
+
/** Whether the record's instance is past its deletion date. */
|
|
157
|
+
export declare function keylessExpired(record: KeylessRecord, now?: number): boolean;
|
|
158
|
+
/** The `KEY=value` lines of an env file (`export `, quotes and comments handled), or an empty map. */
|
|
159
|
+
export declare function parseEnvFile(text: string): Map<string, string>;
|
|
160
|
+
/** The project's `.env.local`, parsed; empty when there is none. */
|
|
161
|
+
export declare function readEnvLocal(dir: string): Promise<Map<string, string>>;
|
|
162
|
+
/**
|
|
163
|
+
* Appends variables to `.env.local`, creating it when missing. A variable the
|
|
164
|
+
* file already sets is never overwritten: it is reported in `skipped`.
|
|
165
|
+
*/
|
|
166
|
+
export declare function appendEnvLocal(dir: string, vars: Readonly<Record<string, string | undefined>>, options?: {
|
|
167
|
+
comment?: string;
|
|
168
|
+
}): Promise<{
|
|
169
|
+
written: string[];
|
|
170
|
+
skipped: string[];
|
|
171
|
+
}>;
|
|
172
|
+
/** Makes sure `.gitignore` lists `.env.local` and `.pontive/`, creating it when missing. Returns what it added. */
|
|
173
|
+
export declare function ensureGitignore(dir: string, entries?: readonly string[]): Promise<string[]>;
|
|
174
|
+
/** 32 random bytes, base64url: a `PONTIVE_SESSION_SECRET` (43 characters), generated locally, never by Pontive. */
|
|
175
|
+
export declare function generateSessionSecret(): string;
|
|
176
|
+
export interface LockOptions {
|
|
177
|
+
/** Give up waiting for another holder after this long. Default 60 s. */
|
|
178
|
+
timeoutMs?: number;
|
|
179
|
+
/** A lock older than this is a crashed holder's, and is taken over. Default 2 minutes. */
|
|
180
|
+
staleMs?: number;
|
|
181
|
+
/** How often to look again while another process holds it. Default 200 ms. */
|
|
182
|
+
pollMs?: number;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Runs `fn` holding `.pontive/keyless.lock`, created exclusively (`wx`), so
|
|
186
|
+
* two processes (two dev workers, the dev server and the CLI) never provision
|
|
187
|
+
* at once. A waiter re-reads `keyless.json` inside `fn` and finds the other's
|
|
188
|
+
* instance. A lock left by a crashed process is taken over after `staleMs`.
|
|
189
|
+
*/
|
|
190
|
+
export declare function withKeylessLock<T>(dir: string, fn: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
191
|
+
/** The §6.1 variables for a provisioned instance (only those it has). */
|
|
192
|
+
export declare function envVarsFor(instance: UnclaimedInstance, sessionSecret: string): Record<string, string | undefined>;
|
|
193
|
+
/** The default redirect URIs for a dev server's callback route: port-less loopback, which matches any port (decision E5). */
|
|
194
|
+
export declare function loopbackCallbacks(basePath?: string): string[];
|
|
195
|
+
export interface ProvisionOptions extends ApiOptions {
|
|
196
|
+
/** The project root. */
|
|
197
|
+
dir: string;
|
|
198
|
+
/** Sent as `app.redirect_uris` (loopback only). */
|
|
199
|
+
redirectUris: string[];
|
|
200
|
+
/** Sent as `client`. */
|
|
201
|
+
client: {
|
|
202
|
+
name: string;
|
|
203
|
+
version: string;
|
|
204
|
+
agent?: string;
|
|
205
|
+
};
|
|
206
|
+
/** Default `PONTIVE_REGION`, else the API picks the region nearest the caller. */
|
|
207
|
+
region?: string;
|
|
208
|
+
/** The project's name. */
|
|
209
|
+
name?: string;
|
|
210
|
+
app?: CreateUnclaimedInstanceRequest["app"];
|
|
211
|
+
tenancyMode?: "b2c" | "b2b";
|
|
212
|
+
lock?: LockOptions;
|
|
213
|
+
}
|
|
214
|
+
export interface KeylessInstance {
|
|
215
|
+
record: KeylessRecord;
|
|
216
|
+
/** The §6.1 values: what was just written, or what `.env.local` and the environment hold for a reused instance. */
|
|
217
|
+
env: Record<string, string | undefined>;
|
|
218
|
+
/** Created by this call (false: an existing `keyless.json` was reused). */
|
|
219
|
+
created: boolean;
|
|
220
|
+
}
|
|
221
|
+
/** The message for an instance that is no longer there, and what to do. */
|
|
222
|
+
export declare function goneMessage(record: KeylessRecord, why: "expired" | "refused"): string;
|
|
223
|
+
/**
|
|
224
|
+
* The project's unclaimed instance: `keyless.json`'s when it is there and not
|
|
225
|
+
* expired; otherwise created now, under the lock, and written to `.env.local`
|
|
226
|
+
* (appended), `keyless.json` and `.gitignore`.
|
|
227
|
+
*
|
|
228
|
+
* An expired `keyless.json` throws `KeylessInstanceGoneError`: never a second
|
|
229
|
+
* instance silently over the first. Pass `reset: true` (`pontive init
|
|
230
|
+
* --reset`) to replace it.
|
|
231
|
+
*/
|
|
232
|
+
export declare function ensureKeylessInstance(options: ProvisionOptions & {
|
|
233
|
+
reset?: boolean;
|
|
234
|
+
}): Promise<KeylessInstance>;
|
|
235
|
+
/**
|
|
236
|
+
* Mints a claim link for the project's unclaimed instance with the claim
|
|
237
|
+
* token in `keyless.json`. The token itself never leaves the machine.
|
|
238
|
+
*/
|
|
239
|
+
export declare function claimLinkFor(record: KeylessRecord, options?: ApiOptions): Promise<ClaimLink>;
|
|
240
|
+
/** The one boxed console message (no secrets): the instance is unclaimed, when it is deleted, and how to claim it. */
|
|
241
|
+
export declare function keylessMessage(record: KeylessRecord, options?: {
|
|
242
|
+
created?: boolean;
|
|
243
|
+
}): string;
|
|
244
|
+
export {};
|