@heypointerhq/contracts 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +53 -2
- package/dist/index.d.ts +1418 -0
- package/dist/index.js +799 -0
- package/package.json +42 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Contract version. Bump on any breaking schema change and note it in packages/contracts/README.md. */
|
|
3
|
+
export const CONTRACT_VERSION = "1.11.0";
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Knowledge base: sources, provenance, workflow graph
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
/**
|
|
8
|
+
* `code` (added in 1.3.0) marks flows a model inferred from application source in
|
|
9
|
+
* `heypointer scan --llm`. Every such step still cites a real file, lines and excerpt.
|
|
10
|
+
*/
|
|
11
|
+
export const SourceTypeSchema = z.enum(["prd", "e2e", "mermaid", "code"]);
|
|
12
|
+
/** Where a fact came from. Line numbers are 1-based and inclusive. */
|
|
13
|
+
export const ProvenanceSchema = z.object({
|
|
14
|
+
sourceType: SourceTypeSchema,
|
|
15
|
+
path: z.string().min(1),
|
|
16
|
+
lineStart: z.number().int().positive(),
|
|
17
|
+
lineEnd: z.number().int().positive(),
|
|
18
|
+
excerpt: z.string(),
|
|
19
|
+
/** sha256 (hex, 16 chars) of the whole source file at scan time. */
|
|
20
|
+
sourceHash: z.string().min(1),
|
|
21
|
+
});
|
|
22
|
+
export const StepActionSchema = z.enum(["click", "type", "select", "navigate", "observe"]);
|
|
23
|
+
/**
|
|
24
|
+
* How to find a live DOM element. Every field is copied from evidence; the
|
|
25
|
+
* server never invents selectors. SDK resolution order: selectors, then
|
|
26
|
+
* role+text, then label, then text.
|
|
27
|
+
*/
|
|
28
|
+
export const TargetSchema = z.object({
|
|
29
|
+
selectors: z.array(z.string().min(1)).default([]),
|
|
30
|
+
role: z.string().min(1).optional(),
|
|
31
|
+
/** Accessible name or visible text. */
|
|
32
|
+
text: z.string().min(1).optional(),
|
|
33
|
+
/** Associated <label> text, for form controls. */
|
|
34
|
+
label: z.string().min(1).optional(),
|
|
35
|
+
});
|
|
36
|
+
export const NodeKindSchema = z.enum(["screen", "action", "outcome", "requirement"]);
|
|
37
|
+
export const WorkflowNodeSchema = z.object({
|
|
38
|
+
id: z.string().min(1),
|
|
39
|
+
workflowId: z.string().min(1),
|
|
40
|
+
kind: NodeKindSchema,
|
|
41
|
+
label: z.string().min(1),
|
|
42
|
+
/** Ordinal of this node in its source sequence (0-based). */
|
|
43
|
+
order: z.number().int().nonnegative(),
|
|
44
|
+
action: StepActionSchema.optional(),
|
|
45
|
+
target: TargetSchema.optional(),
|
|
46
|
+
value: z.string().optional(),
|
|
47
|
+
consequential: z.boolean().default(false),
|
|
48
|
+
provenance: z.array(ProvenanceSchema).min(1),
|
|
49
|
+
});
|
|
50
|
+
export const EdgeKindSchema = z.enum([
|
|
51
|
+
/** Sequence within one source. */
|
|
52
|
+
"next",
|
|
53
|
+
/** Two nodes from different sources describe the same step. */
|
|
54
|
+
"same_as",
|
|
55
|
+
]);
|
|
56
|
+
export const WorkflowEdgeSchema = z.object({
|
|
57
|
+
from: z.string().min(1),
|
|
58
|
+
to: z.string().min(1),
|
|
59
|
+
kind: EdgeKindSchema,
|
|
60
|
+
/** Match strength for same_as (0..1); 1 for next. */
|
|
61
|
+
weight: z.number().min(0).max(1),
|
|
62
|
+
label: z.string().optional(),
|
|
63
|
+
});
|
|
64
|
+
export const WorkflowSchema = z.object({
|
|
65
|
+
id: z.string().min(1),
|
|
66
|
+
title: z.string().min(1),
|
|
67
|
+
sources: z.array(z.string()),
|
|
68
|
+
});
|
|
69
|
+
export const VectorEntrySchema = z.object({
|
|
70
|
+
nodeId: z.string().min(1),
|
|
71
|
+
text: z.string(),
|
|
72
|
+
vector: z.array(z.number()),
|
|
73
|
+
});
|
|
74
|
+
export const KnowledgeBaseSnapshotSchema = z.object({
|
|
75
|
+
/** Content-addressed: same sources + scanner version => same version. */
|
|
76
|
+
version: z.string().min(1),
|
|
77
|
+
createdAt: z.string(),
|
|
78
|
+
scannerVersion: z.string(),
|
|
79
|
+
embedder: z.string(),
|
|
80
|
+
workflows: z.array(WorkflowSchema),
|
|
81
|
+
nodes: z.array(WorkflowNodeSchema),
|
|
82
|
+
edges: z.array(WorkflowEdgeSchema),
|
|
83
|
+
vectors: z.array(VectorEntrySchema),
|
|
84
|
+
});
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// Walkthrough (what the SDK renders)
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
export const EvidenceSchema = z.object({
|
|
89
|
+
nodeId: z.string().min(1),
|
|
90
|
+
sourceType: SourceTypeSchema,
|
|
91
|
+
path: z.string().min(1),
|
|
92
|
+
lineStart: z.number().int().positive(),
|
|
93
|
+
lineEnd: z.number().int().positive(),
|
|
94
|
+
excerpt: z.string(),
|
|
95
|
+
});
|
|
96
|
+
export const WalkthroughStepSchema = z.object({
|
|
97
|
+
id: z.string().min(1),
|
|
98
|
+
title: z.string().min(1),
|
|
99
|
+
instruction: z.string().min(1),
|
|
100
|
+
target: TargetSchema,
|
|
101
|
+
action: StepActionSchema,
|
|
102
|
+
/** Text to type or option to select, when evidence supplies it. Suggestion only. */
|
|
103
|
+
value: z.string().optional(),
|
|
104
|
+
/** True for consequential actions (send, delete, pay...). SDK must confirm first. */
|
|
105
|
+
requiresConfirmation: z.boolean(),
|
|
106
|
+
/** Never empty: a step without evidence is rejected by validation. */
|
|
107
|
+
evidence: z.array(EvidenceSchema).min(1),
|
|
108
|
+
});
|
|
109
|
+
export const WalkthroughStatusSchema = z.enum(["ok", "insufficient_evidence"]);
|
|
110
|
+
export const PlannerKindSchema = z.enum(["llm", "deterministic", "fallback"]);
|
|
111
|
+
/** A guide the server can give, offered when it cannot cover the goal. The title works as a goal: ask for it to get the steps. Added in 1.5.0. */
|
|
112
|
+
export const FlowSuggestionSchema = z.object({
|
|
113
|
+
workflowId: z.string().min(1),
|
|
114
|
+
title: z.string().min(1).max(200),
|
|
115
|
+
});
|
|
116
|
+
export const WalkthroughSchema = z
|
|
117
|
+
.object({
|
|
118
|
+
id: z.string().min(1),
|
|
119
|
+
goal: z.string().min(1),
|
|
120
|
+
status: WalkthroughStatusSchema,
|
|
121
|
+
workflowId: z.string().optional(),
|
|
122
|
+
steps: z.array(WalkthroughStepSchema),
|
|
123
|
+
kbVersion: z.string(),
|
|
124
|
+
/** Retrieval confidence 0..1. */
|
|
125
|
+
confidence: z.number().min(0).max(1),
|
|
126
|
+
planner: PlannerKindSchema,
|
|
127
|
+
/** Human-readable note, required for insufficient_evidence. */
|
|
128
|
+
message: z.string().optional(),
|
|
129
|
+
/** What evidence would be needed, for insufficient_evidence. */
|
|
130
|
+
missingEvidence: z.array(z.string()).optional(),
|
|
131
|
+
/** Nearest guides, for insufficient_evidence only. Added in 1.5.0. */
|
|
132
|
+
suggestions: z.array(FlowSuggestionSchema).max(5).optional(),
|
|
133
|
+
})
|
|
134
|
+
.superRefine((w, ctx) => {
|
|
135
|
+
if (w.status === "ok" && w.steps.length === 0) {
|
|
136
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "status ok requires at least one step", path: ["steps"] });
|
|
137
|
+
}
|
|
138
|
+
if (w.status === "ok" && w.suggestions?.length) {
|
|
139
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "suggestions are only for insufficient_evidence", path: ["suggestions"] });
|
|
140
|
+
}
|
|
141
|
+
if (w.status === "insufficient_evidence") {
|
|
142
|
+
if (w.steps.length > 0) {
|
|
143
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "insufficient_evidence must not include steps", path: ["steps"] });
|
|
144
|
+
}
|
|
145
|
+
if (!w.message) {
|
|
146
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "insufficient_evidence requires a message", path: ["message"] });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
// HTTP API
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
export const API_ROUTES = {
|
|
154
|
+
health: "GET /api/health",
|
|
155
|
+
ingest: "POST /api/ingest",
|
|
156
|
+
knowledgeBase: "GET /api/kb",
|
|
157
|
+
/** Replace the base knowledge base with a scanned one (CI publish). Added in 1.7.0. */
|
|
158
|
+
publishKnowledgeBase: "PUT /api/kb",
|
|
159
|
+
/** Requires the `X-HeyPointer-Client` header unless the server runs with HEYPOINTER_CLIENT_AUTH=off. Added in 1.8.0. */
|
|
160
|
+
walkthrough: "POST /api/walkthrough",
|
|
161
|
+
transcribe: "POST /api/transcribe",
|
|
162
|
+
/** Key-protected inference metrics. Added in 1.2.0. */
|
|
163
|
+
metrics: "GET /api/metrics",
|
|
164
|
+
};
|
|
165
|
+
export const IngestRequestSchema = z.object({
|
|
166
|
+
/** Files or directories, relative to the server source root. Default: ["fixtures"]. */
|
|
167
|
+
paths: z.array(z.string().min(1)).min(1).optional(),
|
|
168
|
+
});
|
|
169
|
+
export const IngestResponseSchema = z.object({
|
|
170
|
+
version: z.string(),
|
|
171
|
+
nodes: z.number().int().nonnegative(),
|
|
172
|
+
edges: z.number().int().nonnegative(),
|
|
173
|
+
workflows: z.array(z.string()),
|
|
174
|
+
sources: z.array(z.object({ path: z.string(), sourceType: SourceTypeSchema, sourceHash: z.string() })),
|
|
175
|
+
warnings: z.array(z.string()),
|
|
176
|
+
});
|
|
177
|
+
/** Largest knowledge base the server accepts on `PUT /api/kb`, and the CLI refuses to send more. Added in 1.7.0. */
|
|
178
|
+
export const MAX_KB_PUBLISH_BYTES = 32 * 1024 * 1024;
|
|
179
|
+
/**
|
|
180
|
+
* Body of `PUT /api/kb`: a scanned knowledge base (the `kb.json` the CLI writes), exactly as written.
|
|
181
|
+
* Unknown top-level fields are refused, and the graph must be internally consistent, so a corrupt or
|
|
182
|
+
* hand-edited file fails here instead of half-loading. Added in 1.7.0.
|
|
183
|
+
*/
|
|
184
|
+
export const PublishKbRequestSchema = KnowledgeBaseSnapshotSchema.strict().superRefine((kb, ctx) => {
|
|
185
|
+
const problem = (message, path = []) => ctx.addIssue({ code: "custom", message, path });
|
|
186
|
+
if (kb.nodes.length > 20_000)
|
|
187
|
+
return problem("too many nodes (limit 20000)", ["nodes"]);
|
|
188
|
+
if (kb.edges.length > 100_000)
|
|
189
|
+
return problem("too many edges (limit 100000)", ["edges"]);
|
|
190
|
+
if (kb.vectors.length > 20_000)
|
|
191
|
+
return problem("too many vectors (limit 20000)", ["vectors"]);
|
|
192
|
+
const workflows = new Set(kb.workflows.map((w) => w.id));
|
|
193
|
+
if (workflows.size !== kb.workflows.length)
|
|
194
|
+
problem("duplicate workflow id", ["workflows"]);
|
|
195
|
+
const nodes = new Set();
|
|
196
|
+
kb.nodes.forEach((n, i) => {
|
|
197
|
+
if (nodes.has(n.id))
|
|
198
|
+
problem(`duplicate node id ${n.id}`, ["nodes", i, "id"]);
|
|
199
|
+
nodes.add(n.id);
|
|
200
|
+
if (!workflows.has(n.workflowId))
|
|
201
|
+
problem(`node ${n.id} names an unknown workflow ${n.workflowId}`, ["nodes", i, "workflowId"]);
|
|
202
|
+
});
|
|
203
|
+
kb.edges.forEach((e, i) => {
|
|
204
|
+
if (!nodes.has(e.from) || !nodes.has(e.to))
|
|
205
|
+
problem(`edge ${e.from} -> ${e.to} names an unknown node`, ["edges", i]);
|
|
206
|
+
});
|
|
207
|
+
const dims = new Set(kb.vectors.map((v) => v.vector.length));
|
|
208
|
+
if (dims.size > 1)
|
|
209
|
+
problem("vectors have different lengths", ["vectors"]);
|
|
210
|
+
kb.vectors.forEach((v, i) => {
|
|
211
|
+
if (!nodes.has(v.nodeId))
|
|
212
|
+
problem(`vector for unknown node ${v.nodeId}`, ["vectors", i, "nodeId"]);
|
|
213
|
+
if (v.vector.some((x) => !Number.isFinite(x)))
|
|
214
|
+
problem("vector has a value that is not a finite number", ["vectors", i, "vector"]);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
export const PublishKbResponseSchema = z.object({
|
|
218
|
+
/** `unchanged`: the server already serves exactly this knowledge base and nothing was written. */
|
|
219
|
+
status: z.enum(["published", "unchanged"]),
|
|
220
|
+
kbId: z.string().min(1),
|
|
221
|
+
nodes: z.number().int().nonnegative(),
|
|
222
|
+
edges: z.number().int().nonnegative(),
|
|
223
|
+
workflows: z.array(z.string()),
|
|
224
|
+
replaced: z.object({ prevKbId: z.string().nullable() }),
|
|
225
|
+
});
|
|
226
|
+
export const WalkthroughRequestSchema = z.object({
|
|
227
|
+
goal: z.string().trim().min(1).max(500),
|
|
228
|
+
context: z.object({ url: z.string().max(2048).optional() }).optional(),
|
|
229
|
+
});
|
|
230
|
+
/** Request body: raw audio bytes with Content-Type audio/* (e.g. audio/webm). */
|
|
231
|
+
export const TranscribeResponseSchema = z.object({
|
|
232
|
+
text: z.string(),
|
|
233
|
+
provider: z.string(),
|
|
234
|
+
});
|
|
235
|
+
export const HealthResponseSchema = z.object({
|
|
236
|
+
ok: z.boolean(),
|
|
237
|
+
contractVersion: z.string(),
|
|
238
|
+
kbVersion: z.string().nullable(),
|
|
239
|
+
mode: z.enum(["offline", "openrouter"]),
|
|
240
|
+
transcription: z.boolean(),
|
|
241
|
+
/** True once a knowledge base is loaded and walkthroughs can be served. Added in 1.1.0. */
|
|
242
|
+
ready: z.boolean().optional(),
|
|
243
|
+
});
|
|
244
|
+
export const ErrorCodeSchema = z.enum([
|
|
245
|
+
"bad_request",
|
|
246
|
+
/** Missing or wrong API key (HTTP 401). Added in 1.1.0. */
|
|
247
|
+
"unauthorized",
|
|
248
|
+
"not_found",
|
|
249
|
+
"payload_too_large",
|
|
250
|
+
"unsupported_media_type",
|
|
251
|
+
"transcription_unavailable",
|
|
252
|
+
/** Model spend cap reached (HTTP 429). Added in 1.2.0. */
|
|
253
|
+
"spend_cap_exceeded",
|
|
254
|
+
/** Metrics store not readable (HTTP 503). Added in 1.2.0. */
|
|
255
|
+
"metrics_unavailable",
|
|
256
|
+
/** Authenticated but not allowed: disabled client or a model outside the allowlist (HTTP 403). Added in 1.4.0. */
|
|
257
|
+
"forbidden",
|
|
258
|
+
/** Too many requests from one client or address (HTTP 429). Added in 1.4.0. */
|
|
259
|
+
"rate_limited",
|
|
260
|
+
"kb_empty",
|
|
261
|
+
/** A published knowledge base was built with a different embedder than the server's (HTTP 409). Added in 1.7.0. */
|
|
262
|
+
"embedder_mismatch",
|
|
263
|
+
/** A published knowledge base was built by an older scanner than the server accepts (HTTP 422). Added in 1.7.0. */
|
|
264
|
+
"scanner_too_old",
|
|
265
|
+
/** The request is valid but clashes with current state, e.g. a scanned workflow id equal to a published flow (HTTP 409). Added in 1.7.0. */
|
|
266
|
+
"conflict",
|
|
267
|
+
/** `X-HeyPointer-Client` is missing or not a client id (HTTP 401). Added in 1.8.0. */
|
|
268
|
+
"client_required",
|
|
269
|
+
/** The client id is unknown or revoked; the two are not told apart (HTTP 401). Added in 1.8.0. */
|
|
270
|
+
"client_invalid",
|
|
271
|
+
/** The request's Origin is not in the client's allowed origins (HTTP 403). Added in 1.8.0. */
|
|
272
|
+
"client_origin_not_allowed",
|
|
273
|
+
/** The tenant's plan does not allow another client id, key or flow (HTTP 403). The body also carries `limit` and `used`. Added in 1.9.0. */
|
|
274
|
+
"plan_limit_reached",
|
|
275
|
+
/** Wrong email or password, or a disabled account; the three are not told apart (HTTP 401). Added in 1.10.0. */
|
|
276
|
+
"invalid_credentials",
|
|
277
|
+
/** The invite is for an email that already has an account: log in first, then accept it (HTTP 409). Added in 1.10.0. */
|
|
278
|
+
"account_exists_login_first",
|
|
279
|
+
/** User accounts are not enabled on this server (HTTP 404). Added in 1.10.0. */
|
|
280
|
+
"accounts_disabled",
|
|
281
|
+
/** A cookie-authenticated request lacked a valid CSRF token or came from another origin (HTTP 403). Added in 1.10.0. */
|
|
282
|
+
"csrf_failed",
|
|
283
|
+
/** A HeyPointer staff account must turn on two-factor sign-in before it may use the operator routes (HTTP 403). Added in 1.11.0. */
|
|
284
|
+
"operator_2fa_required",
|
|
285
|
+
"internal",
|
|
286
|
+
]);
|
|
287
|
+
/** Every non-2xx response has this body. transcription_unavailable uses HTTP 501. */
|
|
288
|
+
export const ErrorResponseSchema = z.object({
|
|
289
|
+
error: z.string(),
|
|
290
|
+
code: ErrorCodeSchema,
|
|
291
|
+
/** Human-readable text. Sent with the client_* codes, whose `error` is the code itself. Added in 1.8.0. */
|
|
292
|
+
message: z.string().optional(),
|
|
293
|
+
/** With `plan_limit_reached`: what the plan allows and how much the tenant already uses. Added in 1.9.0. */
|
|
294
|
+
limit: z.number().int().nonnegative().optional(),
|
|
295
|
+
used: z.number().int().nonnegative().optional(),
|
|
296
|
+
});
|
|
297
|
+
// ---------------------------------------------------------------------------
|
|
298
|
+
// Inference metrics (added in 1.2.0)
|
|
299
|
+
// ---------------------------------------------------------------------------
|
|
300
|
+
/**
|
|
301
|
+
* Aggregate inference metrics. Key-protected. Never includes prompts, keys or
|
|
302
|
+
* response content. All numeric fields are finite and nonnegative.
|
|
303
|
+
*/
|
|
304
|
+
export const MetricsResponseSchema = z.object({
|
|
305
|
+
calls: z.number().int().nonnegative(),
|
|
306
|
+
errors: z.number().int().nonnegative(),
|
|
307
|
+
p50Ms: z.number().nonnegative().finite(),
|
|
308
|
+
p95Ms: z.number().nonnegative().finite(),
|
|
309
|
+
estCostUsd: z.number().nonnegative().finite(),
|
|
310
|
+
/** Models seen with no price on record, so estCostUsd may understate. */
|
|
311
|
+
unpricedModels: z.array(z.string()),
|
|
312
|
+
spendCapUsd: z.number().nonnegative().finite().nullable(),
|
|
313
|
+
remainingUsd: z.number().nonnegative().finite().nullable(),
|
|
314
|
+
});
|
|
315
|
+
// ---------------------------------------------------------------------------
|
|
316
|
+
// Hosted inference ("llm-cloud", added in 1.4.0)
|
|
317
|
+
// ---------------------------------------------------------------------------
|
|
318
|
+
/** Routes under /api/cloud use `Authorization: Bearer <client token>`. Admin routes use the server API key. */
|
|
319
|
+
export const CLOUD_ROUTES = {
|
|
320
|
+
enroll: "POST /api/cloud/enroll",
|
|
321
|
+
me: "GET /api/cloud/me",
|
|
322
|
+
logout: "POST /api/cloud/logout",
|
|
323
|
+
createBatch: "POST /api/cloud/v1/batches",
|
|
324
|
+
getBatch: "GET /api/cloud/v1/batches/{id}",
|
|
325
|
+
decisions: "POST /api/cloud/alpha/decisions",
|
|
326
|
+
adminCreateClient: "POST /api/admin/clients",
|
|
327
|
+
adminListClients: "GET /api/admin/clients",
|
|
328
|
+
adminNewCode: "POST /api/admin/clients/{id}/enrollment-codes",
|
|
329
|
+
adminDisable: "POST /api/admin/clients/{id}/disable",
|
|
330
|
+
};
|
|
331
|
+
export const CloudModelsSchema = z.object({ scan: z.string(), decision: z.string() });
|
|
332
|
+
/** One-time enrollment code in, long-lived client token out. The token is shown once. */
|
|
333
|
+
export const CloudEnrollRequestSchema = z.object({
|
|
334
|
+
code: z.string().trim().min(8).max(40),
|
|
335
|
+
deviceName: z.string().trim().max(80).optional(),
|
|
336
|
+
});
|
|
337
|
+
export const CloudEnrollResponseSchema = z.object({
|
|
338
|
+
clientId: z.string(),
|
|
339
|
+
name: z.string(),
|
|
340
|
+
token: z.string(),
|
|
341
|
+
budgetUsd: z.number().nonnegative().finite(),
|
|
342
|
+
models: CloudModelsSchema,
|
|
343
|
+
});
|
|
344
|
+
export const CloudMeResponseSchema = z.object({
|
|
345
|
+
clientId: z.string(),
|
|
346
|
+
name: z.string(),
|
|
347
|
+
budgetUsd: z.number().nonnegative().finite(),
|
|
348
|
+
spentUsd: z.number().nonnegative().finite(),
|
|
349
|
+
reservedUsd: z.number().nonnegative().finite(),
|
|
350
|
+
remainingUsd: z.number().nonnegative().finite(),
|
|
351
|
+
models: CloudModelsSchema,
|
|
352
|
+
});
|
|
353
|
+
export const AdminCreateClientRequestSchema = z.object({
|
|
354
|
+
name: z.string().trim().min(1).max(80),
|
|
355
|
+
budgetUsd: z.number().positive().max(100_000).finite(),
|
|
356
|
+
});
|
|
357
|
+
export const AdminClientSchema = z.object({
|
|
358
|
+
id: z.string(),
|
|
359
|
+
name: z.string(),
|
|
360
|
+
budgetUsd: z.number().nonnegative().finite(),
|
|
361
|
+
spentUsd: z.number().nonnegative().finite(),
|
|
362
|
+
reservedUsd: z.number().nonnegative().finite(),
|
|
363
|
+
disabled: z.boolean(),
|
|
364
|
+
createdAt: z.string(),
|
|
365
|
+
});
|
|
366
|
+
export const AdminCodeResponseSchema = z.object({
|
|
367
|
+
client: AdminClientSchema,
|
|
368
|
+
/** Shown once. Valid for a short time and a single use. */
|
|
369
|
+
enrollmentCode: z.string(),
|
|
370
|
+
expiresAt: z.string(),
|
|
371
|
+
});
|
|
372
|
+
// ---------------------------------------------------------------------------
|
|
373
|
+
// Flows API (added in 1.6.0): add, edit and publish flows on a running server
|
|
374
|
+
// ---------------------------------------------------------------------------
|
|
375
|
+
/** Routes use `Authorization: Bearer <server API key>` when the server has one. */
|
|
376
|
+
export const FLOW_ROUTES = {
|
|
377
|
+
list: "GET /api/flows",
|
|
378
|
+
create: "POST /api/flows",
|
|
379
|
+
get: "GET /api/flows/{id}",
|
|
380
|
+
update: "PUT /api/flows/{id}",
|
|
381
|
+
delete: "DELETE /api/flows/{id}",
|
|
382
|
+
publish: "POST /api/flows/{id}/publish",
|
|
383
|
+
unpublish: "POST /api/flows/{id}/unpublish",
|
|
384
|
+
rollback: "POST /api/flows/{id}/rollback",
|
|
385
|
+
validate: "POST /api/flows/validate",
|
|
386
|
+
};
|
|
387
|
+
/** One step is a sentence in PRD style that quotes the control: `Click "Change plan"`. */
|
|
388
|
+
export const FlowInputSchema = z.object({
|
|
389
|
+
title: z.string().trim().min(1).max(120),
|
|
390
|
+
steps: z.array(z.string().trim().min(1).max(240)).min(1).max(40),
|
|
391
|
+
/** Why this version was saved. Shown in the history. */
|
|
392
|
+
note: z.string().trim().max(200).optional(),
|
|
393
|
+
});
|
|
394
|
+
export const FlowVersionSchema = z.object({
|
|
395
|
+
version: z.number().int().positive(),
|
|
396
|
+
title: z.string(),
|
|
397
|
+
steps: z.array(z.string()),
|
|
398
|
+
note: z.string().optional(),
|
|
399
|
+
savedAt: z.string(),
|
|
400
|
+
});
|
|
401
|
+
/**
|
|
402
|
+
* A flow as the API shows it. `version` is the latest saved one. Users are served only the
|
|
403
|
+
* published version: saving more edits never changes what they see until the flow is published again.
|
|
404
|
+
*/
|
|
405
|
+
export const FlowSchema = z.object({
|
|
406
|
+
id: z.string().regex(/^fl_[0-9a-f]{12}$/),
|
|
407
|
+
title: z.string(),
|
|
408
|
+
steps: z.array(z.string()),
|
|
409
|
+
version: z.number().int().positive(),
|
|
410
|
+
published: z.boolean(),
|
|
411
|
+
publishedVersion: z.number().int().positive().optional(),
|
|
412
|
+
hasUnpublishedChanges: z.boolean(),
|
|
413
|
+
/** Why the latest saved version cannot be published yet. Empty when it can. */
|
|
414
|
+
problems: z.array(z.string()),
|
|
415
|
+
createdAt: z.string(),
|
|
416
|
+
updatedAt: z.string(),
|
|
417
|
+
});
|
|
418
|
+
export const FlowDetailSchema = FlowSchema.extend({
|
|
419
|
+
/** Newest first. */
|
|
420
|
+
versions: z.array(FlowVersionSchema),
|
|
421
|
+
});
|
|
422
|
+
export const FlowListResponseSchema = z.object({ flows: z.array(FlowSchema) });
|
|
423
|
+
export const FlowRollbackRequestSchema = z.object({ version: z.number().int().positive() });
|
|
424
|
+
/** Dry run: how the server reads these steps, without saving anything. */
|
|
425
|
+
export const FlowValidateResponseSchema = z.object({
|
|
426
|
+
ok: z.boolean(),
|
|
427
|
+
problems: z.array(z.string()),
|
|
428
|
+
steps: z.array(z.object({
|
|
429
|
+
text: z.string(),
|
|
430
|
+
action: StepActionSchema.optional(),
|
|
431
|
+
target: z.string().optional(),
|
|
432
|
+
/** The user is asked to confirm before this step. */
|
|
433
|
+
gated: z.boolean(),
|
|
434
|
+
})),
|
|
435
|
+
});
|
|
436
|
+
// ---------------------------------------------------------------------------
|
|
437
|
+
// App clients (added in 1.8.0): who may ask for walkthroughs
|
|
438
|
+
// ---------------------------------------------------------------------------
|
|
439
|
+
/**
|
|
440
|
+
* The header every walkthrough request carries. The value is a client id, which is a PUBLISHABLE
|
|
441
|
+
* identifier: it ships in web pages and app packages, so it is not a secret and must not be
|
|
442
|
+
* treated as one. It names who is asking (for revocation, origin limits, rate limits and
|
|
443
|
+
* usage counts); it does not prove who is asking.
|
|
444
|
+
*/
|
|
445
|
+
export const CLIENT_ID_HEADER = "X-HeyPointer-Client";
|
|
446
|
+
/** `gfc_` and 24 lowercase hex characters (96 random bits). */
|
|
447
|
+
export const CLIENT_ID_PATTERN = /^gfc_[0-9a-f]{24}$/;
|
|
448
|
+
export const ClientIdSchema = z.string().regex(CLIENT_ID_PATTERN);
|
|
449
|
+
/** Routes use `Authorization: Bearer <server API key>`. */
|
|
450
|
+
export const CLIENT_ROUTES = {
|
|
451
|
+
create: "POST /api/clients",
|
|
452
|
+
list: "GET /api/clients",
|
|
453
|
+
/** Revokes: the row stays, the id stops working. Repeating it is fine. */
|
|
454
|
+
revoke: "DELETE /api/clients/{id}",
|
|
455
|
+
};
|
|
456
|
+
export const MAX_CLIENT_ORIGINS = 20;
|
|
457
|
+
/** `scheme://host[:port]` with no path, query or fragment, exactly as a browser sends `Origin`. No wildcard. */
|
|
458
|
+
export const ClientOriginSchema = z.string().max(300).refine((v) => {
|
|
459
|
+
try {
|
|
460
|
+
const u = new URL(v);
|
|
461
|
+
return (u.protocol === "http:" || u.protocol === "https:") && u.origin === v;
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
}, "an origin is scheme://host[:port] with no path (no wildcard)");
|
|
467
|
+
export const CreateClientRequestSchema = z.object({
|
|
468
|
+
name: z.string().trim().min(1).max(80).refine((v) => !/[\u0000-\u001f\u007f-\u009f]/.test(v), "name must not contain control characters"),
|
|
469
|
+
/** Browser origins allowed to use this client. Empty or absent means any origin (native apps send none). */
|
|
470
|
+
origins: z.array(ClientOriginSchema).max(MAX_CLIENT_ORIGINS).optional(),
|
|
471
|
+
});
|
|
472
|
+
export const CreateClientResponseSchema = z.object({
|
|
473
|
+
clientId: ClientIdSchema,
|
|
474
|
+
name: z.string(),
|
|
475
|
+
origins: z.array(z.string()),
|
|
476
|
+
createdAt: z.string(),
|
|
477
|
+
revoked: z.literal(false),
|
|
478
|
+
});
|
|
479
|
+
export const AppClientSchema = z.object({
|
|
480
|
+
clientId: ClientIdSchema,
|
|
481
|
+
name: z.string(),
|
|
482
|
+
origins: z.array(z.string()),
|
|
483
|
+
createdAt: z.string(),
|
|
484
|
+
revoked: z.boolean(),
|
|
485
|
+
revokedAt: z.string().optional(),
|
|
486
|
+
/** Last time a walkthrough request passed the gate. Updated about every 5 seconds, not per request. */
|
|
487
|
+
lastUsedAt: z.string().nullable(),
|
|
488
|
+
/** Walkthrough requests that passed the gate. */
|
|
489
|
+
requests: z.number().int().nonnegative(),
|
|
490
|
+
});
|
|
491
|
+
export const ClientListResponseSchema = z.object({ clients: z.array(AppClientSchema) });
|
|
492
|
+
// ---------------------------------------------------------------------------
|
|
493
|
+
// Tenants and keys (added in 1.9.0): isolation between customers of one server
|
|
494
|
+
// ---------------------------------------------------------------------------
|
|
495
|
+
/**
|
|
496
|
+
* A tenant owns its keys, app clients, flows and knowledge base. Nothing is shared between tenants.
|
|
497
|
+
* The server operator (the server API key) creates tenants; a tenant's owner exchanges a one-time
|
|
498
|
+
* enrollment code for a secret admin key and manages the tenant with it.
|
|
499
|
+
*/
|
|
500
|
+
export const TENANT_ID_PATTERN = /^tn_[0-9a-f]{12}$/;
|
|
501
|
+
export const TenantIdSchema = z.string().regex(TENANT_ID_PATTERN);
|
|
502
|
+
/** The tenant every pre-1.9.0 install is migrated into. Requests that name no tenant act on it. */
|
|
503
|
+
export const DEFAULT_TENANT_ID = "tn_000000000000";
|
|
504
|
+
/** A secret key: `gfk_a_` (admin) or `gfk_g_` (guide) and 48 lowercase hex characters (192 random bits). Shown once. */
|
|
505
|
+
export const KEY_SECRET_PATTERN = /^gfk_[ag]_[0-9a-f]{48}$/;
|
|
506
|
+
export const ADMIN_KEY_PATTERN = /^gfk_a_[0-9a-f]{48}$/;
|
|
507
|
+
export const GUIDE_KEY_PATTERN = /^gfk_g_[0-9a-f]{48}$/;
|
|
508
|
+
/** A key handle (not a secret): used to list and revoke keys. */
|
|
509
|
+
export const KEY_ID_PATTERN = /^kid_[0-9a-f]{12}$/;
|
|
510
|
+
export const KeyIdSchema = z.string().regex(KEY_ID_PATTERN);
|
|
511
|
+
/** A one-time enrollment code: `gfe_` and 32 lowercase hex characters. Valid for 15 minutes. */
|
|
512
|
+
export const ENROLL_CODE_PATTERN = /^gfe_[0-9a-f]{32}$/;
|
|
513
|
+
export const ENROLLMENT_TTL_MS = 15 * 60 * 1000;
|
|
514
|
+
export const KeyScopeSchema = z.enum(["admin", "guide"]);
|
|
515
|
+
/**
|
|
516
|
+
* Tenant routes use a tenant admin key (`Authorization: Bearer gfk_a_...`). A guide key (`gfk_g_...`) may only fetch walkthroughs.
|
|
517
|
+
*/
|
|
518
|
+
export const TENANT_ROUTES = {
|
|
519
|
+
/** No authentication: the code is the credential. Rate limited like failed key checks. */
|
|
520
|
+
enroll: "POST /api/tenant/enroll",
|
|
521
|
+
self: "GET /api/tenant",
|
|
522
|
+
createKey: "POST /api/keys",
|
|
523
|
+
listKeys: "GET /api/keys",
|
|
524
|
+
/** Revokes. A tenant cannot revoke its last active admin key. Repeating it is fine. */
|
|
525
|
+
revokeKey: "DELETE /api/keys/{id}",
|
|
526
|
+
};
|
|
527
|
+
const NameSchema = z.string().trim().min(1).max(80).refine((v) => !/[\u0000-\u001f\u007f-\u009f]/.test(v), "name must not contain control characters");
|
|
528
|
+
/**
|
|
529
|
+
* A plan names a set of limits. Plans are data on the server (`HEYPOINTER_PLAN_LIMITS_JSON` adds or changes
|
|
530
|
+
* them), so a new tier needs no code. New tenants start on `free`; the migrated default tenant is `internal`.
|
|
531
|
+
*/
|
|
532
|
+
export const PlanNameSchema = z.string().regex(/^[a-z][a-z0-9_-]{0,29}$/, "a plan name is lowercase letters, digits, - or _ (30 characters at most)");
|
|
533
|
+
export const DEFAULT_PLAN = "free";
|
|
534
|
+
const Count = z.number().int().nonnegative();
|
|
535
|
+
/** What a tenant may hold at once. Revoked clients and keys do not count; they stay on record. */
|
|
536
|
+
export const PlanLimitsSchema = z.object({
|
|
537
|
+
clients: z.number().int().positive(),
|
|
538
|
+
keys: z.number().int().positive(),
|
|
539
|
+
flows: z.number().int().positive(),
|
|
540
|
+
/** Team members plus pending invites. Added in 1.10.0; a plan that omits it gets the server default (free 3, internal 100). */
|
|
541
|
+
members: z.number().int().positive().optional(),
|
|
542
|
+
});
|
|
543
|
+
export const PlanUsageSchema = z.object({ clients: Count, keys: Count, flows: Count, /** Members plus pending invites. Added in 1.10.0. */ members: Count.optional() });
|
|
544
|
+
/** A tenant's plan, what it allows, and what the tenant uses now. */
|
|
545
|
+
export const TenantPlanSchema = z.object({ plan: PlanNameSchema, limits: PlanLimitsSchema, usage: PlanUsageSchema });
|
|
546
|
+
export const EnrollTenantRequestSchema = z.object({ code: z.string().max(100) });
|
|
547
|
+
export const CreatedKeySchema = z.object({
|
|
548
|
+
keyId: KeyIdSchema,
|
|
549
|
+
scope: KeyScopeSchema,
|
|
550
|
+
/** Shown once; only its hash is stored. */
|
|
551
|
+
secret: z.string().regex(KEY_SECRET_PATTERN),
|
|
552
|
+
});
|
|
553
|
+
export const EnrollTenantResponseSchema = z.object({
|
|
554
|
+
tenantId: TenantIdSchema,
|
|
555
|
+
name: z.string(),
|
|
556
|
+
key: CreatedKeySchema.extend({ scope: z.literal("admin") }),
|
|
557
|
+
});
|
|
558
|
+
export const CreateKeyRequestSchema = z.object({ name: NameSchema, scope: KeyScopeSchema });
|
|
559
|
+
export const CreateKeyResponseSchema = CreatedKeySchema.extend({ name: z.string(), createdAt: z.string() });
|
|
560
|
+
export const KeySummarySchema = z.object({
|
|
561
|
+
keyId: KeyIdSchema,
|
|
562
|
+
scope: KeyScopeSchema,
|
|
563
|
+
name: z.string(),
|
|
564
|
+
/** The first characters of the secret (e.g. `gfk_a_1a2b3c4d`), enough to recognise it. Not usable as a key. */
|
|
565
|
+
prefix: z.string(),
|
|
566
|
+
createdAt: z.string(),
|
|
567
|
+
lastUsedAt: z.string().nullable(),
|
|
568
|
+
revoked: z.boolean(),
|
|
569
|
+
});
|
|
570
|
+
export const KeyListResponseSchema = z.object({ keys: z.array(KeySummarySchema) });
|
|
571
|
+
export const TenantSelfResponseSchema = z.object({
|
|
572
|
+
tenantId: TenantIdSchema,
|
|
573
|
+
name: z.string(),
|
|
574
|
+
createdAt: z.string(),
|
|
575
|
+
/** Same as `usage`. */
|
|
576
|
+
counts: PlanUsageSchema,
|
|
577
|
+
/** `plan`, `limits` and `usage`. */
|
|
578
|
+
...TenantPlanSchema.shape,
|
|
579
|
+
});
|
|
580
|
+
// ---------------------------------------------------------------------------
|
|
581
|
+
// Accounts and login (added in 1.10.0): people, sessions, invites, device login, audit
|
|
582
|
+
// ---------------------------------------------------------------------------
|
|
583
|
+
/**
|
|
584
|
+
* People sign in to the web console with an email and password (OIDC providers come later) and get a session
|
|
585
|
+
* cookie instead of pasting a key. Signup is invite-only. A user belongs to one or more tenants with a role.
|
|
586
|
+
* Accounts exist only when the operator sets `HEYPOINTER_PUBLIC_URL` and `HEYPOINTER_AUTH_SECRET`; otherwise every
|
|
587
|
+
* account route answers 404 `accounts_disabled` and keys keep working as before.
|
|
588
|
+
*/
|
|
589
|
+
export const USER_ID_PATTERN = /^usr_[0-9a-f]{12}$/;
|
|
590
|
+
export const UserIdSchema = z.string().regex(USER_ID_PATTERN);
|
|
591
|
+
export const SESSION_ID_PATTERN = /^ses_[0-9a-f]{12}$/;
|
|
592
|
+
export const INVITE_ID_PATTERN = /^inv_[0-9a-f]{12}$/;
|
|
593
|
+
/** An invite link token: shown once to the inviter inside the link. */
|
|
594
|
+
export const INVITE_TOKEN_PATTERN = /^gfi_[0-9a-f]{32}$/;
|
|
595
|
+
/** A password reset token: shown once inside the reset link; valid one hour. */
|
|
596
|
+
export const RESET_TOKEN_PATTERN = /^gfr_[0-9a-f]{32}$/;
|
|
597
|
+
/** The device code the CLI polls with. A secret: only its hash is stored. */
|
|
598
|
+
export const DEVICE_CODE_PATTERN = /^gfd_[0-9a-f]{40}$/;
|
|
599
|
+
/** What the person types in the browser: `ABCD-EFGH`, no vowels and no look-alike characters. */
|
|
600
|
+
export const USER_CODE_PATTERN = /^[BCDFGHJKLMNPQRSTVWXZ2-9]{4}-[BCDFGHJKLMNPQRSTVWXZ2-9]{4}$/;
|
|
601
|
+
export const RECOVERY_CODE_PATTERN = /^[0-9a-f]{5}-[0-9a-f]{5}$/;
|
|
602
|
+
/** The session cookie. With an https public URL the server sends it as `__Host-hp_session` (Secure). */
|
|
603
|
+
export const SESSION_COOKIE = "hp_session";
|
|
604
|
+
/** Every state-changing request authenticated by the session cookie must send the session's CSRF token here. */
|
|
605
|
+
export const CSRF_HEADER = "X-HeyPointer-CSRF";
|
|
606
|
+
export const SESSION_IDLE_MS = 12 * 60 * 60 * 1000;
|
|
607
|
+
export const SESSION_ABSOLUTE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
608
|
+
export const INVITE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
609
|
+
export const RESET_TTL_MS = 60 * 60 * 1000;
|
|
610
|
+
export const DEVICE_TTL_SECONDS = 600;
|
|
611
|
+
export const DEVICE_POLL_INTERVAL_SECONDS = 5;
|
|
612
|
+
export const MemberRoleSchema = z.enum(["owner", "admin", "member"]);
|
|
613
|
+
export const EmailSchema = z.string().trim().toLowerCase().max(254).email();
|
|
614
|
+
/** The routes added in 1.10.0. Session routes need the cookie and, when they change anything, the CSRF header and a same-origin `Origin`. */
|
|
615
|
+
export const ACCOUNT_ROUTES = {
|
|
616
|
+
config: "GET /api/auth/config",
|
|
617
|
+
login: "POST /api/auth/login",
|
|
618
|
+
logout: "POST /api/auth/logout",
|
|
619
|
+
session: "GET /api/auth/session",
|
|
620
|
+
switchTenant: "POST /api/auth/tenant",
|
|
621
|
+
inviteInfo: "GET /api/auth/invite/{token}",
|
|
622
|
+
acceptInvite: "POST /api/auth/accept-invite",
|
|
623
|
+
changePassword: "POST /api/auth/password",
|
|
624
|
+
reset: "POST /api/auth/reset",
|
|
625
|
+
totpEnroll: "POST /api/auth/totp/enroll",
|
|
626
|
+
totpVerify: "POST /api/auth/totp/verify",
|
|
627
|
+
totpDisable: "DELETE /api/auth/totp",
|
|
628
|
+
listSessions: "GET /api/auth/sessions",
|
|
629
|
+
revokeSession: "DELETE /api/auth/sessions/{id}",
|
|
630
|
+
deviceStart: "POST /api/auth/device",
|
|
631
|
+
deviceLookup: "GET /api/auth/device/lookup?userCode=",
|
|
632
|
+
deviceApprove: "POST /api/auth/device/approve",
|
|
633
|
+
deviceDeny: "POST /api/auth/device/deny",
|
|
634
|
+
deviceToken: "POST /api/auth/device/token",
|
|
635
|
+
cliLogin: "POST /api/auth/cli-login",
|
|
636
|
+
listMembers: "GET /api/members",
|
|
637
|
+
updateMember: "PATCH /api/members/{userId}",
|
|
638
|
+
removeMember: "DELETE /api/members/{userId}",
|
|
639
|
+
resetMember: "POST /api/members/{userId}/reset",
|
|
640
|
+
listInvites: "GET /api/invites",
|
|
641
|
+
createInvite: "POST /api/invites",
|
|
642
|
+
revokeInvite: "DELETE /api/invites/{id}",
|
|
643
|
+
audit: "GET /api/audit",
|
|
644
|
+
};
|
|
645
|
+
/** A server without accounts answers `GET /api/auth/config` with 200 `{accounts:false}` (every other account route is a 404). */
|
|
646
|
+
export const AuthConfigDisabledSchema = z.object({ accounts: z.literal(false) });
|
|
647
|
+
export const AuthConfigResponseSchema = z.object({
|
|
648
|
+
accounts: z.literal(true),
|
|
649
|
+
passwordLogin: z.boolean(),
|
|
650
|
+
/** OIDC providers the operator configured. Empty until OIDC login ships. */
|
|
651
|
+
providers: z.array(z.object({ id: z.string(), name: z.string() })),
|
|
652
|
+
publicUrl: z.string(),
|
|
653
|
+
});
|
|
654
|
+
export const AccountUserSchema = z.object({ userId: UserIdSchema, email: z.string(), totpEnabled: z.boolean().optional(), /** Present and true for a HeyPointer staff account. Added in 1.11.0. */ operator: z.boolean().optional() });
|
|
655
|
+
export const MembershipSchema = z.object({ tenantId: TenantIdSchema, name: z.string(), role: MemberRoleSchema });
|
|
656
|
+
export const LoginRequestSchema = z.object({
|
|
657
|
+
email: z.string().max(254),
|
|
658
|
+
password: z.string().max(200),
|
|
659
|
+
/** A 6-digit code from the authenticator app, or a recovery code (`xxxxx-xxxxx`). */
|
|
660
|
+
totp: z.string().max(32).optional(),
|
|
661
|
+
});
|
|
662
|
+
export const LoginResponseSchema = z.discriminatedUnion("status", [
|
|
663
|
+
z.object({
|
|
664
|
+
status: z.literal("ok"),
|
|
665
|
+
user: AccountUserSchema,
|
|
666
|
+
tenants: z.array(MembershipSchema),
|
|
667
|
+
/** The tenant the session acts on; null when the user belongs to several (choose one with `POST /api/auth/tenant`). */
|
|
668
|
+
activeTenantId: TenantIdSchema.nullable(),
|
|
669
|
+
csrfToken: z.string(),
|
|
670
|
+
}),
|
|
671
|
+
/** The password was right and the account has 2FA: repeat the request with `totp`. No cookie was set. */
|
|
672
|
+
z.object({ status: z.literal("totp_required") }),
|
|
673
|
+
]);
|
|
674
|
+
export const SessionResponseSchema = z.object({
|
|
675
|
+
user: AccountUserSchema,
|
|
676
|
+
tenants: z.array(MembershipSchema),
|
|
677
|
+
activeTenantId: TenantIdSchema.nullable(),
|
|
678
|
+
/** The user's role in the active tenant. */
|
|
679
|
+
role: MemberRoleSchema.nullable(),
|
|
680
|
+
csrfToken: z.string(),
|
|
681
|
+
/** True for a HeyPointer staff account (it may use the staff tools once two-factor sign-in is on). Added in 1.11.0. */
|
|
682
|
+
operator: z.boolean().optional(),
|
|
683
|
+
/** Of the active tenant. */
|
|
684
|
+
plan: PlanNameSchema.optional(),
|
|
685
|
+
limits: PlanLimitsSchema.optional(),
|
|
686
|
+
usage: PlanUsageSchema.optional(),
|
|
687
|
+
});
|
|
688
|
+
export const SwitchTenantRequestSchema = z.object({ tenantId: TenantIdSchema });
|
|
689
|
+
export const InviteInfoResponseSchema = z.object({
|
|
690
|
+
email: z.string(),
|
|
691
|
+
tenantName: z.string(),
|
|
692
|
+
role: MemberRoleSchema,
|
|
693
|
+
/** `operator` for a HeyPointer staff invite (then `tenantName` is "HeyPointer staff" and `role` is only a placeholder). Absent for a tenant invite. Added in 1.11.0. */
|
|
694
|
+
kind: z.literal("operator").optional(),
|
|
695
|
+
});
|
|
696
|
+
export const AcceptInviteRequestSchema = z.object({
|
|
697
|
+
token: z.string().max(100),
|
|
698
|
+
/** Required for a new account. An existing account logs in first and sends no password. */
|
|
699
|
+
password: z.string().max(200).optional(),
|
|
700
|
+
});
|
|
701
|
+
export const ChangePasswordRequestSchema = z.object({ current: z.string().max(200), next: z.string().max(200) });
|
|
702
|
+
export const ResetPasswordRequestSchema = z.object({ token: z.string().max(100), password: z.string().max(200) });
|
|
703
|
+
export const TotpEnrollResponseSchema = z.object({ secretBase32: z.string(), otpauthUri: z.string() });
|
|
704
|
+
export const TotpVerifyRequestSchema = z.object({ code: z.string().max(16) });
|
|
705
|
+
/** Shown once. Each works once in place of an authenticator code. */
|
|
706
|
+
export const TotpVerifyResponseSchema = z.object({ recoveryCodes: z.array(z.string().regex(RECOVERY_CODE_PATTERN)).length(10) });
|
|
707
|
+
export const TotpDisableRequestSchema = z.object({ password: z.string().max(200) });
|
|
708
|
+
export const SessionSummarySchema = z.object({
|
|
709
|
+
sessionId: z.string().regex(SESSION_ID_PATTERN),
|
|
710
|
+
current: z.boolean(),
|
|
711
|
+
createdAt: z.string(),
|
|
712
|
+
lastSeenAt: z.string(),
|
|
713
|
+
expiresAt: z.string(),
|
|
714
|
+
/** Coarse: the address with its last part removed, and the first 120 characters of the user agent. */
|
|
715
|
+
ip: z.string(),
|
|
716
|
+
userAgent: z.string(),
|
|
717
|
+
tenantId: TenantIdSchema.nullable(),
|
|
718
|
+
});
|
|
719
|
+
export const SessionListResponseSchema = z.object({ sessions: z.array(SessionSummarySchema) });
|
|
720
|
+
export const MemberSchema = z.object({
|
|
721
|
+
userId: UserIdSchema,
|
|
722
|
+
email: z.string(),
|
|
723
|
+
role: MemberRoleSchema,
|
|
724
|
+
createdAt: z.string(),
|
|
725
|
+
lastLoginAt: z.string().nullable(),
|
|
726
|
+
totpEnabled: z.boolean(),
|
|
727
|
+
});
|
|
728
|
+
export const MemberListResponseSchema = z.object({ members: z.array(MemberSchema) });
|
|
729
|
+
export const UpdateMemberRequestSchema = z.object({ role: MemberRoleSchema });
|
|
730
|
+
export const CreateInviteRequestSchema = z.object({ email: EmailSchema, role: MemberRoleSchema });
|
|
731
|
+
/** The link is shown once: the server sends no email, so the inviter passes it on. */
|
|
732
|
+
export const CreateInviteResponseSchema = z.object({
|
|
733
|
+
inviteId: z.string().regex(INVITE_ID_PATTERN),
|
|
734
|
+
email: z.string(),
|
|
735
|
+
role: MemberRoleSchema,
|
|
736
|
+
inviteLink: z.string(),
|
|
737
|
+
expiresAt: z.string(),
|
|
738
|
+
});
|
|
739
|
+
export const InviteSummarySchema = z.object({
|
|
740
|
+
inviteId: z.string().regex(INVITE_ID_PATTERN),
|
|
741
|
+
email: z.string(),
|
|
742
|
+
role: MemberRoleSchema,
|
|
743
|
+
invitedBy: z.string(),
|
|
744
|
+
createdAt: z.string(),
|
|
745
|
+
expiresAt: z.string(),
|
|
746
|
+
status: z.enum(["pending", "expired"]),
|
|
747
|
+
});
|
|
748
|
+
export const InviteListResponseSchema = z.object({ invites: z.array(InviteSummarySchema) });
|
|
749
|
+
export const ResetLinkResponseSchema = z.object({ resetLink: z.string(), expiresAt: z.string() });
|
|
750
|
+
const DeviceNameSchema = z.string().trim().min(1).max(60).refine((v) => !/[\u0000-\u001f\u007f-\u009f]/.test(v), "name must not contain control characters");
|
|
751
|
+
export const DeviceStartRequestSchema = z.object({ deviceName: DeviceNameSchema });
|
|
752
|
+
export const DeviceStartResponseSchema = z.object({
|
|
753
|
+
deviceCode: z.string().regex(DEVICE_CODE_PATTERN),
|
|
754
|
+
userCode: z.string().regex(USER_CODE_PATTERN),
|
|
755
|
+
verificationUri: z.string(),
|
|
756
|
+
verificationUriComplete: z.string(),
|
|
757
|
+
expiresIn: z.number().int().positive(),
|
|
758
|
+
interval: z.number().int().positive(),
|
|
759
|
+
});
|
|
760
|
+
export const DeviceLookupResponseSchema = z.object({ deviceName: z.string(), requestedAt: z.string() });
|
|
761
|
+
export const DeviceDecisionRequestSchema = z.object({ userCode: z.string().max(20), tenantId: TenantIdSchema.optional() });
|
|
762
|
+
export const DeviceTokenRequestSchema = z.object({ deviceCode: z.string().max(100) });
|
|
763
|
+
export const DeviceTokenResponseSchema = z.discriminatedUnion("status", [
|
|
764
|
+
z.object({ status: z.literal("pending"), interval: z.number().int().positive() }),
|
|
765
|
+
z.object({ status: z.literal("slow_down"), interval: z.number().int().positive() }),
|
|
766
|
+
z.object({ status: z.literal("denied") }),
|
|
767
|
+
z.object({ status: z.literal("expired") }),
|
|
768
|
+
/** Delivered once; the server forgets the key after this reply. */
|
|
769
|
+
z.object({ status: z.literal("approved"), tenantId: TenantIdSchema, tenantName: z.string(), key: CreatedKeySchema.extend({ scope: z.literal("admin") }) }),
|
|
770
|
+
]);
|
|
771
|
+
export const CliLoginRequestSchema = z.object({
|
|
772
|
+
email: z.string().max(254),
|
|
773
|
+
password: z.string().max(200),
|
|
774
|
+
totp: z.string().max(32).optional(),
|
|
775
|
+
tenantId: TenantIdSchema.optional(),
|
|
776
|
+
deviceName: DeviceNameSchema,
|
|
777
|
+
});
|
|
778
|
+
export const CliLoginResponseSchema = z.discriminatedUnion("status", [
|
|
779
|
+
z.object({ status: z.literal("ok"), tenantId: TenantIdSchema, tenantName: z.string(), key: CreatedKeySchema.extend({ scope: z.literal("admin") }) }),
|
|
780
|
+
z.object({ status: z.literal("totp_required") }),
|
|
781
|
+
/** The user belongs to several tenants where they may mint keys: repeat with `tenantId`. */
|
|
782
|
+
z.object({ status: z.literal("tenant_required"), tenants: z.array(MembershipSchema) }),
|
|
783
|
+
]);
|
|
784
|
+
export const AuditActorSchema = z.object({ type: z.enum(["user", "key", "operator", "anonymous"]), id: z.string() });
|
|
785
|
+
export const AuditEntrySchema = z.object({
|
|
786
|
+
id: z.number().int().positive(),
|
|
787
|
+
ts: z.string(),
|
|
788
|
+
tenantId: TenantIdSchema.nullable(),
|
|
789
|
+
actor: AuditActorSchema,
|
|
790
|
+
action: z.string(),
|
|
791
|
+
target: z.string().nullable(),
|
|
792
|
+
result: z.enum(["ok", "denied", "failed"]),
|
|
793
|
+
/** In a tenant's own audit log: true when HeyPointer staff (the operator) did it. The staff member's identity is never shown to the tenant. Added in 1.11.0. */
|
|
794
|
+
byStaff: z.boolean().optional(),
|
|
795
|
+
/** A plain sentence for entries staff made on the tenant, e.g. "HeyPointer staff viewed your flow list". Added in 1.11.0. */
|
|
796
|
+
description: z.string().optional(),
|
|
797
|
+
});
|
|
798
|
+
/** Newest first. Pass `next` back as `before` for the following page; null when there is none. */
|
|
799
|
+
export const AuditListResponseSchema = z.object({ entries: z.array(AuditEntrySchema), next: z.number().int().positive().nullable() });
|