@grovemotorco/manifold 0.0.0-stage → 0.0.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/LICENSE +201 -0
- package/README.md +50 -2
- package/dist/api.d.ts +6515 -0
- package/dist/api.js +643 -0
- package/dist/client.d.ts +2603 -0
- package/dist/client.js +42 -0
- package/dist/domain-Dye3ZdC_.js +922 -0
- package/dist/filter-DQnhobby.js +240 -0
- package/dist/ids-Ced7gYBp.d.ts +1704 -0
- package/dist/index.d.ts +640 -0
- package/dist/index.js +1339 -0
- package/dist/listen.d.ts +530 -0
- package/dist/listen.js +566 -0
- package/package.json +49 -3
package/dist/api.js
ADDED
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
import { B as LIMITS, Ct as RouteConfig, Et as RouteView, G as ListenerSessionId, H as ListenTokenInfo, It as SourceKey, Jt as sourceConfigFields, K as ListenersSetting, Kt as relayConfigFields, Lt as SourceStats, M as HeaderName, O as Fingerprint, Q as Millis, Rt as SourceView, St as Revision, T as Extractor, U as ListenerInfo, V as ListenTokenId, W as ListenerName, Wt as VerifyOverride, X as MaxBodyBytes, _t as RequestRecord, at as PresetResponse, b as DeliveryStatus, bt as RetentionDays, c as AutoPauseThreshold, d as ConfigDocument, dt as RelayConfig, et as Page, ft as RelayId, g as DedupeWindowSeconds, gt as RequestId, h as Count, ht as RequestDetail, it as PresetId, jt as SecretValue, k as HandshakeSpec, kt as SecretHeaders, mt as RelayView, n as ApplyResult, o as AuditAction, pt as RelayTimeoutMs, rt as Preset, s as AuditRecord, ut as Rejections, v as DeliveryId, vt as RequestStatus, w as EventTypeGlob, wt as RouteId, xt as RetryPolicy, y as DeliveryRecord } from "./domain-Dye3ZdC_.js";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as SchemaGetter from "effect/SchemaGetter";
|
|
6
|
+
import * as HttpApi from "effect/http-api/HttpApi";
|
|
7
|
+
import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
|
|
8
|
+
import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
|
|
9
|
+
import * as HttpApiMiddleware from "effect/http-api/HttpApiMiddleware";
|
|
10
|
+
import * as HttpApiSchema from "effect/http-api/HttpApiSchema";
|
|
11
|
+
import * as HttpApiSecurity from "effect/http-api/HttpApiSecurity";
|
|
12
|
+
import * as OpenApi from "effect/http-api/OpenApi";
|
|
13
|
+
// src/api/Api.ts
|
|
14
|
+
/**
|
|
15
|
+
* The admin API (§9.1) as an Effect `HttpApi`: every endpoint with its
|
|
16
|
+
* request and response schemas, errors and security. No handlers; those live
|
|
17
|
+
* in the runtime. Served under `/api/v1`.
|
|
18
|
+
*
|
|
19
|
+
* Errors are `{ error: { code, message } }` on the wire and tagged error
|
|
20
|
+
* classes in Effect code (`NotFound`, `Conflict`, …); see `ApiErrors`.
|
|
21
|
+
*/
|
|
22
|
+
var BadRequest = class extends Schema.TaggedError()("BadRequest", { message: Schema.String }) {};
|
|
23
|
+
var Unauthorized = class extends Schema.TaggedError()("Unauthorized", { message: Schema.String }) {};
|
|
24
|
+
var NotFound = class extends Schema.TaggedError()("NotFound", { message: Schema.String }) {};
|
|
25
|
+
var Conflict = class extends Schema.TaggedError()("Conflict", { message: Schema.String }) {};
|
|
26
|
+
var PayloadTooLarge = class extends Schema.TaggedError()("PayloadTooLarge", { message: Schema.String }) {};
|
|
27
|
+
var Unavailable = class extends Schema.TaggedError()("Unavailable", { message: Schema.String }) {};
|
|
28
|
+
/**
|
|
29
|
+
* Encodes a tagged error class as `{ error: { code, message } }` with a status.
|
|
30
|
+
* The client decodes the body back into the class.
|
|
31
|
+
*/
|
|
32
|
+
const wire = (errorClass, tag, code, status) => Schema.Struct({ error: Schema.Struct({
|
|
33
|
+
code: Schema.Literal(code),
|
|
34
|
+
message: Schema.String
|
|
35
|
+
}) }).pipe(Schema.decodeTo(errorClass, {
|
|
36
|
+
decode: SchemaGetter.transform((body) => ({
|
|
37
|
+
_tag: tag,
|
|
38
|
+
message: body.error.message
|
|
39
|
+
})),
|
|
40
|
+
encode: SchemaGetter.transform((error) => ({ error: {
|
|
41
|
+
code,
|
|
42
|
+
message: error.message
|
|
43
|
+
} }))
|
|
44
|
+
}), HttpApiSchema.status(status), (schema) => schema.annotate({ identifier: `${tag}Error` }));
|
|
45
|
+
/** The wire schemas for each error, for `error:` lists in endpoints. */
|
|
46
|
+
const ApiErrors = {
|
|
47
|
+
BadRequest: wire(BadRequest, "BadRequest", "bad_request", 400),
|
|
48
|
+
Unauthorized: wire(Unauthorized, "Unauthorized", "unauthorized", 401),
|
|
49
|
+
NotFound: wire(NotFound, "NotFound", "not_found", 404),
|
|
50
|
+
Conflict: wire(Conflict, "Conflict", "conflict", 409),
|
|
51
|
+
PayloadTooLarge: wire(PayloadTooLarge, "PayloadTooLarge", "payload_too_large", 413),
|
|
52
|
+
Unavailable: wire(Unavailable, "Unavailable", "unavailable", 503)
|
|
53
|
+
};
|
|
54
|
+
var AdminActor = class extends Context.Service()("manifold/api/AdminActor") {};
|
|
55
|
+
/** The audit `actor` string for an `AdminActor`: `token`, `access:<email>` or `listen:<tokenId>`. */
|
|
56
|
+
const actorLabel = (actor) => {
|
|
57
|
+
switch (actor.kind) {
|
|
58
|
+
case "token": return "token";
|
|
59
|
+
case "access": return `access:${actor.id}`;
|
|
60
|
+
case "listen": return `listen:${actor.tokenId}`;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Admin authentication (§7.1). Tried in order: `bearer` (the admin token),
|
|
65
|
+
* then `access` (a Cloudflare Access JWT in `cf-access-jwt-assertion`).
|
|
66
|
+
* Fails `Unauthorized`, or `Unavailable` when neither is configured.
|
|
67
|
+
*/
|
|
68
|
+
var AdminAuth = class extends HttpApiMiddleware.Service()("manifold/api/AdminAuth", {
|
|
69
|
+
security: {
|
|
70
|
+
bearer: HttpApiSecurity.bearer,
|
|
71
|
+
access: HttpApiSecurity.apiKey({
|
|
72
|
+
key: "cf-access-jwt-assertion",
|
|
73
|
+
in: "header"
|
|
74
|
+
})
|
|
75
|
+
},
|
|
76
|
+
error: [ApiErrors.Unauthorized, ApiErrors.Unavailable]
|
|
77
|
+
}) {};
|
|
78
|
+
/**
|
|
79
|
+
* Declares the errors any endpoint can answer with. Provide it with
|
|
80
|
+
* `HttpApiMiddleware.layerSchemaErrorTransform(ApiErrorHandling, …)` to turn
|
|
81
|
+
* request decoding failures into `BadRequest`.
|
|
82
|
+
*/
|
|
83
|
+
var ApiErrorHandling = class extends HttpApiMiddleware.Service()("manifold/api/ApiErrorHandling", { error: [ApiErrors.BadRequest, ApiErrors.Unavailable] }) {};
|
|
84
|
+
const Limit = Schema.Int.check(Schema.isBetween({
|
|
85
|
+
minimum: 1,
|
|
86
|
+
maximum: LIMITS.pageMax
|
|
87
|
+
}));
|
|
88
|
+
/** `limit` (default `LIMITS.pageDefault`, max `LIMITS.pageMax`) and an opaque `cursor`. */
|
|
89
|
+
const PageQuery = {
|
|
90
|
+
limit: Schema.optionalKey(Limit),
|
|
91
|
+
cursor: Schema.optionalKey(Schema.String)
|
|
92
|
+
};
|
|
93
|
+
const ExpectedRevision = { expectedRevision: Revision };
|
|
94
|
+
const Description = Schema.String.check(Schema.isMaxLength(500));
|
|
95
|
+
/**
|
|
96
|
+
* Create payloads come in two forms. `XCreate` is the wire and client shape:
|
|
97
|
+
* defaulted fields are optional (a client sends only what it sets).
|
|
98
|
+
* `XCreateWithDefaults` decodes that shape into the full config; the server
|
|
99
|
+
* runs `Schema.decodeUnknownSync(XCreateWithDefaults)(payload)` to fill defaults.
|
|
100
|
+
*/
|
|
101
|
+
const SourceCreateWithDefaults = Schema.Struct({
|
|
102
|
+
...sourceConfigFields,
|
|
103
|
+
secrets: Schema.Array(SecretValue).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])))
|
|
104
|
+
}).annotate({ identifier: "SourceCreateWithDefaults" });
|
|
105
|
+
const SourceCreate = Schema.toEncoded(SourceCreateWithDefaults).annotate({ identifier: "SourceCreate" });
|
|
106
|
+
/** Absent keys are unchanged; `null` clears an optional field. */
|
|
107
|
+
const SourcePatch = Schema.Struct({
|
|
108
|
+
...ExpectedRevision,
|
|
109
|
+
description: Schema.optionalKey(Schema.NullOr(Description)),
|
|
110
|
+
preset: Schema.optionalKey(PresetId),
|
|
111
|
+
enabled: Schema.optionalKey(Schema.Boolean),
|
|
112
|
+
allowUnverified: Schema.optionalKey(Schema.Boolean),
|
|
113
|
+
verify: Schema.optionalKey(Schema.NullOr(VerifyOverride)),
|
|
114
|
+
eventType: Schema.optionalKey(Schema.NullOr(Extractor)),
|
|
115
|
+
idempotencyKey: Schema.optionalKey(Schema.NullOr(Extractor)),
|
|
116
|
+
handshake: Schema.optionalKey(Schema.NullOr(HandshakeSpec)),
|
|
117
|
+
response: Schema.optionalKey(Schema.NullOr(PresetResponse)),
|
|
118
|
+
redactHeaders: Schema.optionalKey(Schema.Array(HeaderName)),
|
|
119
|
+
dedupeWindowSeconds: Schema.optionalKey(DedupeWindowSeconds),
|
|
120
|
+
maxBodyBytes: Schema.optionalKey(MaxBodyBytes),
|
|
121
|
+
retentionDays: Schema.optionalKey(RetentionDays),
|
|
122
|
+
listeners: Schema.optionalKey(ListenersSetting)
|
|
123
|
+
}).annotate({ identifier: "SourcePatch" });
|
|
124
|
+
const SecretAdd = Schema.Struct({ secret: SecretValue }).annotate({ identifier: "SecretAdd" });
|
|
125
|
+
const SecretChanged = Schema.Struct({
|
|
126
|
+
source: SourceView,
|
|
127
|
+
fingerprint: Fingerprint
|
|
128
|
+
}).annotate({ identifier: "SecretChanged" });
|
|
129
|
+
const RelayCreateWithDefaults = Schema.Struct({
|
|
130
|
+
...relayConfigFields,
|
|
131
|
+
secretHeaders: SecretHeaders.pipe(Schema.withDecodingDefaultKey(Effect.succeed({})))
|
|
132
|
+
}).annotate({ identifier: "RelayCreateWithDefaults" });
|
|
133
|
+
const RelayCreate = Schema.toEncoded(RelayCreateWithDefaults).annotate({ identifier: "RelayCreate" });
|
|
134
|
+
/** Absent keys are unchanged. `secretHeaders` merges by name; `null` removes one. `retry` replaces the policy. */
|
|
135
|
+
const RelayPatch = Schema.Struct({
|
|
136
|
+
...ExpectedRevision,
|
|
137
|
+
name: Schema.optionalKey(RelayConfig.fields.name),
|
|
138
|
+
description: Schema.optionalKey(Schema.NullOr(Description)),
|
|
139
|
+
url: Schema.optionalKey(RelayConfig.fields.url),
|
|
140
|
+
headers: Schema.optionalKey(Schema.Record(HeaderName, Schema.String.check(Schema.isMaxLength(4096)))),
|
|
141
|
+
secretHeaders: Schema.optionalKey(Schema.Record(HeaderName, Schema.NullOr(SecretValue))),
|
|
142
|
+
timeoutMs: Schema.optionalKey(RelayTimeoutMs),
|
|
143
|
+
/** Replaces the policy; omitted fields take their defaults. */
|
|
144
|
+
retry: Schema.optionalKey(Schema.toEncoded(RetryPolicy)),
|
|
145
|
+
signing: Schema.optionalKey(Schema.Boolean)
|
|
146
|
+
}).annotate({ identifier: "RelayPatch" });
|
|
147
|
+
const RelayCreated = Schema.Struct({
|
|
148
|
+
relay: RelayView,
|
|
149
|
+
/** The `whsec_…` signing secret, shown once; `null` when `signing` is off. */
|
|
150
|
+
signingSecret: Schema.NullOr(Schema.String)
|
|
151
|
+
}).annotate({ identifier: "RelayCreated" });
|
|
152
|
+
const RelaySecretRotated = Schema.Struct({
|
|
153
|
+
relay: RelayView,
|
|
154
|
+
/** The new `whsec_…` signing secret, shown once. */
|
|
155
|
+
signingSecret: Schema.String,
|
|
156
|
+
/** When the previous secret stops signing (24 h). `null` when there was none. */
|
|
157
|
+
previousExpiresAt: Schema.NullOr(Millis)
|
|
158
|
+
}).annotate({ identifier: "RelaySecretRotated" });
|
|
159
|
+
/** Decode with `RouteConfig` to fill defaults. */
|
|
160
|
+
const RouteCreate = Schema.toEncoded(RouteConfig).annotate({ identifier: "RouteCreate" });
|
|
161
|
+
/** `PUT /config` payload: a `ConfigDocument` before defaults. Decode with `ConfigDocument` to fill them. */
|
|
162
|
+
const ConfigApply = Schema.toEncoded(ConfigDocument).annotate({ identifier: "ConfigApply" });
|
|
163
|
+
const RoutePatch = Schema.Struct({
|
|
164
|
+
...ExpectedRevision,
|
|
165
|
+
relay: Schema.optionalKey(RelayId),
|
|
166
|
+
description: Schema.optionalKey(Schema.NullOr(Description)),
|
|
167
|
+
eventTypes: Schema.optionalKey(Schema.NonEmptyArray(EventTypeGlob)),
|
|
168
|
+
enabled: Schema.optionalKey(Schema.Boolean),
|
|
169
|
+
autoPauseThreshold: Schema.optionalKey(AutoPauseThreshold)
|
|
170
|
+
}).annotate({ identifier: "RoutePatch" });
|
|
171
|
+
const ReplayRequest = Schema.Struct({
|
|
172
|
+
/** Defaults to every currently matching route. */
|
|
173
|
+
routeIds: Schema.optionalKey(Schema.NonEmptyArray(RouteId)) }).annotate({ identifier: "ReplayRequest" });
|
|
174
|
+
const ReplayResult = Schema.Struct({ deliveries: Schema.Array(DeliveryRecord) }).annotate({ identifier: "ReplayResult" });
|
|
175
|
+
/** Replays stored requests matching a filter (§6.7), at most `LIMITS.replayRangeMax` per call. */
|
|
176
|
+
const ReplayRange = Schema.Struct({
|
|
177
|
+
since: Schema.optionalKey(Millis),
|
|
178
|
+
until: Schema.optionalKey(Millis),
|
|
179
|
+
/** An event-type glob. */
|
|
180
|
+
eventType: Schema.optionalKey(EventTypeGlob),
|
|
181
|
+
status: Schema.optionalKey(RequestStatus),
|
|
182
|
+
routeIds: Schema.optionalKey(Schema.NonEmptyArray(RouteId)),
|
|
183
|
+
limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
|
|
184
|
+
minimum: 1,
|
|
185
|
+
maximum: LIMITS.replayRangeMax
|
|
186
|
+
}))),
|
|
187
|
+
/** `nextCursor` of the previous call. */
|
|
188
|
+
cursor: Schema.optionalKey(Schema.String)
|
|
189
|
+
}).annotate({ identifier: "ReplayRange" });
|
|
190
|
+
const ReplayRangeResult = Schema.Struct({
|
|
191
|
+
requests: Count,
|
|
192
|
+
deliveries: Count,
|
|
193
|
+
nextCursor: Schema.NullOr(Schema.String)
|
|
194
|
+
}).annotate({ identifier: "ReplayRangeResult" });
|
|
195
|
+
const ReencryptResult = Schema.Struct({
|
|
196
|
+
sources: Count,
|
|
197
|
+
relays: Count,
|
|
198
|
+
/** Ciphertexts rewritten with the current key. */
|
|
199
|
+
resealed: Count
|
|
200
|
+
}).annotate({ identifier: "ReencryptResult" });
|
|
201
|
+
/**
|
|
202
|
+
* Names a connected listener: its session id (`lsn_…`), or its name. A name
|
|
203
|
+
* shared by two connected listeners is ambiguous (`409`).
|
|
204
|
+
*/
|
|
205
|
+
const ListenerRef = Schema.String.check(Schema.isBetweenLength(1, 100)).annotate({ identifier: "ListenerRef" });
|
|
206
|
+
/** `POST /sources/{key}/requests/{id}/send-local`. */
|
|
207
|
+
const SendLocal = Schema.Struct({ listener: ListenerRef }).annotate({ identifier: "SendLocal" });
|
|
208
|
+
const sendLocalRangeFields = {
|
|
209
|
+
since: Schema.optionalKey(Millis),
|
|
210
|
+
until: Schema.optionalKey(Millis),
|
|
211
|
+
/** An event-type glob. */
|
|
212
|
+
eventType: Schema.optionalKey(EventTypeGlob),
|
|
213
|
+
/** Without it, `duplicate` requests are left out. */
|
|
214
|
+
status: Schema.optionalKey(RequestStatus),
|
|
215
|
+
/** Newest matching requests first, at most this many (default and max `LIMITS.replayRangeMax`); sent oldest first. */
|
|
216
|
+
limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
|
|
217
|
+
minimum: 1,
|
|
218
|
+
maximum: LIMITS.replayRangeMax
|
|
219
|
+
}))),
|
|
220
|
+
/** `nextCursor` of the previous call. */
|
|
221
|
+
cursor: Schema.optionalKey(Schema.String)
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* `POST /sources/{key}/send-local`: stored requests pushed to one listener,
|
|
225
|
+
* by id (`requestIds`, at most `LIMITS.replayRangeMax`) or by a range filter;
|
|
226
|
+
* not both. The listener's own filter does not apply: what is asked for is
|
|
227
|
+
* sent. Creates no deliveries.
|
|
228
|
+
*/
|
|
229
|
+
const SendLocalRange = Schema.Struct({
|
|
230
|
+
listener: ListenerRef,
|
|
231
|
+
requestIds: Schema.optionalKey(Schema.NonEmptyArray(RequestId).check(Schema.isMaxLength(LIMITS.replayRangeMax))),
|
|
232
|
+
...sendLocalRangeFields
|
|
233
|
+
}).check(Schema.makeFilter((input) => {
|
|
234
|
+
if (input.requestIds === void 0) return void 0;
|
|
235
|
+
const range = Object.entries(input).filter(([key, value]) => Object.hasOwn(sendLocalRangeFields, key) && value !== void 0).map(([key]) => key);
|
|
236
|
+
return range.length === 0 || `requestIds cannot be combined with ${range.join(", ")}`;
|
|
237
|
+
})).annotate({ identifier: "SendLocalRange" });
|
|
238
|
+
const SendLocalResult = Schema.Struct({
|
|
239
|
+
sessionId: ListenerSessionId,
|
|
240
|
+
listener: ListenerName,
|
|
241
|
+
/** `request` frames sent (kind `replay`). */
|
|
242
|
+
sent: Count,
|
|
243
|
+
/** Selected but not sent: too large for one frame even without its body (the socket also gets a `limit` notice). */
|
|
244
|
+
skipped: Count,
|
|
245
|
+
/** Set when the range had more than `limit`; pass it back as `cursor`. Always `null` for ids. */
|
|
246
|
+
nextCursor: Schema.NullOr(Schema.String)
|
|
247
|
+
}).annotate({ identifier: "SendLocalResult" });
|
|
248
|
+
/** Default lifetime of a listen token (§7 of LOCAL-RELAY.md). */
|
|
249
|
+
const LISTEN_TOKEN_DEFAULT_DAYS = 30;
|
|
250
|
+
const LISTEN_TOKEN_MAX_DAYS = 365;
|
|
251
|
+
/** `POST /sources/{key}/listen-tokens`. */
|
|
252
|
+
const ListenTokenCreate = Schema.Struct({
|
|
253
|
+
/** Shown in listings, e.g. the developer's name. */
|
|
254
|
+
name: Schema.String.check(Schema.isBetweenLength(1, 100)),
|
|
255
|
+
/** Default `LISTEN_TOKEN_DEFAULT_DAYS`. */
|
|
256
|
+
expiresInDays: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
|
|
257
|
+
minimum: 1,
|
|
258
|
+
maximum: 365
|
|
259
|
+
})))
|
|
260
|
+
}).annotate({ identifier: "ListenTokenCreate" });
|
|
261
|
+
const ListenTokenCreated = Schema.Struct({
|
|
262
|
+
/** The `mfl_…` token, shown once. Never logged. */
|
|
263
|
+
token: Schema.String,
|
|
264
|
+
tokenInfo: ListenTokenInfo,
|
|
265
|
+
/**
|
|
266
|
+
* The source's SourceDO acknowledged the snapshot carrying the token, so it
|
|
267
|
+
* works now. When `false` it starts working once the cron sweep's retry
|
|
268
|
+
* lands (within about 5 minutes).
|
|
269
|
+
*/
|
|
270
|
+
active: Schema.Boolean
|
|
271
|
+
}).annotate({ identifier: "ListenTokenCreated" });
|
|
272
|
+
const ListenerPage = Page(ListenerInfo).annotate({ identifier: "ListenerPage" });
|
|
273
|
+
const ListenTokenPage = Page(ListenTokenInfo).annotate({ identifier: "ListenTokenPage" });
|
|
274
|
+
const PresetPage = Page(Preset).annotate({ identifier: "PresetPage" });
|
|
275
|
+
const SourcePage = Page(SourceView).annotate({ identifier: "SourcePage" });
|
|
276
|
+
const RelayPage = Page(RelayView).annotate({ identifier: "RelayPage" });
|
|
277
|
+
const RoutePage = Page(RouteView).annotate({ identifier: "RoutePage" });
|
|
278
|
+
const RequestPage = Page(RequestRecord).annotate({ identifier: "RequestPage" });
|
|
279
|
+
const DeliveryPage = Page(DeliveryRecord).annotate({ identifier: "DeliveryPage" });
|
|
280
|
+
const AuditPage = Page(AuditRecord).annotate({ identifier: "AuditPage" });
|
|
281
|
+
const Created = (schema) => schema.pipe(HttpApiSchema.status(201));
|
|
282
|
+
const KeyParam = { key: SourceKey };
|
|
283
|
+
const { BadRequest: E400, NotFound: E404, Conflict: E409, PayloadTooLarge: E413, Unavailable: E503 } = ApiErrors;
|
|
284
|
+
var PresetsGroup = class extends HttpApiGroup.make("presets").add(HttpApiEndpoint.get("list", "/presets", { success: PresetPage })).annotateMerge(OpenApi.annotations({ title: "Presets" })) {};
|
|
285
|
+
var SourcesGroup = class extends HttpApiGroup.make("sources").add(HttpApiEndpoint.get("list", "/sources", {
|
|
286
|
+
query: PageQuery,
|
|
287
|
+
success: SourcePage
|
|
288
|
+
}), HttpApiEndpoint.post("create", "/sources", {
|
|
289
|
+
payload: SourceCreate,
|
|
290
|
+
success: Created(SourceView),
|
|
291
|
+
error: [
|
|
292
|
+
E400,
|
|
293
|
+
E409,
|
|
294
|
+
E503
|
|
295
|
+
]
|
|
296
|
+
}), HttpApiEndpoint.get("get", "/sources/:key", {
|
|
297
|
+
params: KeyParam,
|
|
298
|
+
success: SourceView,
|
|
299
|
+
error: E404
|
|
300
|
+
}), HttpApiEndpoint.patch("update", "/sources/:key", {
|
|
301
|
+
params: KeyParam,
|
|
302
|
+
payload: SourcePatch,
|
|
303
|
+
success: SourceView,
|
|
304
|
+
error: [
|
|
305
|
+
E400,
|
|
306
|
+
E404,
|
|
307
|
+
E409,
|
|
308
|
+
E503
|
|
309
|
+
]
|
|
310
|
+
}), HttpApiEndpoint.delete("delete", "/sources/:key", {
|
|
311
|
+
params: KeyParam,
|
|
312
|
+
query: { expectedRevision: Schema.optionalKey(Revision) },
|
|
313
|
+
success: HttpApiSchema.NoContent,
|
|
314
|
+
error: [E404, E409]
|
|
315
|
+
}), HttpApiEndpoint.post("addSecret", "/sources/:key/secrets", {
|
|
316
|
+
params: KeyParam,
|
|
317
|
+
payload: SecretAdd,
|
|
318
|
+
success: Created(SecretChanged),
|
|
319
|
+
error: [
|
|
320
|
+
E400,
|
|
321
|
+
E404,
|
|
322
|
+
E409,
|
|
323
|
+
E503
|
|
324
|
+
]
|
|
325
|
+
}), HttpApiEndpoint.delete("removeSecret", "/sources/:key/secrets/:fingerprint", {
|
|
326
|
+
params: {
|
|
327
|
+
key: SourceKey,
|
|
328
|
+
fingerprint: Fingerprint
|
|
329
|
+
},
|
|
330
|
+
success: SecretChanged,
|
|
331
|
+
error: [E404, E503]
|
|
332
|
+
}), HttpApiEndpoint.get("rejections", "/sources/:key/rejections", {
|
|
333
|
+
params: KeyParam,
|
|
334
|
+
success: Rejections,
|
|
335
|
+
error: [E404, E503]
|
|
336
|
+
}), HttpApiEndpoint.get("stats", "/sources/:key/stats", {
|
|
337
|
+
params: KeyParam,
|
|
338
|
+
success: SourceStats,
|
|
339
|
+
error: [E404, E503]
|
|
340
|
+
})).annotateMerge(OpenApi.annotations({ title: "Sources" })) {};
|
|
341
|
+
var RelaysGroup = class extends HttpApiGroup.make("relays").add(HttpApiEndpoint.get("list", "/relays", {
|
|
342
|
+
query: PageQuery,
|
|
343
|
+
success: RelayPage
|
|
344
|
+
}), HttpApiEndpoint.post("create", "/relays", {
|
|
345
|
+
payload: RelayCreate,
|
|
346
|
+
success: Created(RelayCreated),
|
|
347
|
+
error: [E400, E409]
|
|
348
|
+
}), HttpApiEndpoint.get("get", "/relays/:id", {
|
|
349
|
+
params: { id: RelayId },
|
|
350
|
+
success: RelayView,
|
|
351
|
+
error: E404
|
|
352
|
+
}), HttpApiEndpoint.patch("update", "/relays/:id", {
|
|
353
|
+
params: { id: RelayId },
|
|
354
|
+
payload: RelayPatch,
|
|
355
|
+
success: RelayView,
|
|
356
|
+
error: [
|
|
357
|
+
E400,
|
|
358
|
+
E404,
|
|
359
|
+
E409
|
|
360
|
+
]
|
|
361
|
+
}), HttpApiEndpoint.delete("delete", "/relays/:id", {
|
|
362
|
+
params: { id: RelayId },
|
|
363
|
+
query: { expectedRevision: Schema.optionalKey(Revision) },
|
|
364
|
+
success: HttpApiSchema.NoContent,
|
|
365
|
+
error: [E404, E409]
|
|
366
|
+
}), HttpApiEndpoint.post("rotateSecret", "/relays/:id/rotate-secret", {
|
|
367
|
+
params: { id: RelayId },
|
|
368
|
+
success: RelaySecretRotated,
|
|
369
|
+
error: [E404, E409]
|
|
370
|
+
})).annotateMerge(OpenApi.annotations({ title: "Relays" })) {};
|
|
371
|
+
var RoutesGroup = class extends HttpApiGroup.make("routes").add(HttpApiEndpoint.get("list", "/routes", {
|
|
372
|
+
query: {
|
|
373
|
+
...PageQuery,
|
|
374
|
+
source: Schema.optionalKey(SourceKey),
|
|
375
|
+
relay: Schema.optionalKey(RelayId)
|
|
376
|
+
},
|
|
377
|
+
success: RoutePage
|
|
378
|
+
}), HttpApiEndpoint.post("create", "/routes", {
|
|
379
|
+
payload: RouteCreate,
|
|
380
|
+
success: Created(RouteView),
|
|
381
|
+
error: [
|
|
382
|
+
E400,
|
|
383
|
+
E404,
|
|
384
|
+
E409
|
|
385
|
+
]
|
|
386
|
+
}), HttpApiEndpoint.get("get", "/routes/:id", {
|
|
387
|
+
params: { id: RouteId },
|
|
388
|
+
success: RouteView,
|
|
389
|
+
error: E404
|
|
390
|
+
}), HttpApiEndpoint.patch("update", "/routes/:id", {
|
|
391
|
+
params: { id: RouteId },
|
|
392
|
+
payload: RoutePatch,
|
|
393
|
+
success: RouteView,
|
|
394
|
+
error: [
|
|
395
|
+
E400,
|
|
396
|
+
E404,
|
|
397
|
+
E409
|
|
398
|
+
]
|
|
399
|
+
}), HttpApiEndpoint.delete("delete", "/routes/:id", {
|
|
400
|
+
params: { id: RouteId },
|
|
401
|
+
query: { expectedRevision: Schema.optionalKey(Revision) },
|
|
402
|
+
success: HttpApiSchema.NoContent,
|
|
403
|
+
error: [E404, E409]
|
|
404
|
+
}), HttpApiEndpoint.post("pause", "/routes/:id/pause", {
|
|
405
|
+
params: { id: RouteId },
|
|
406
|
+
success: RouteView,
|
|
407
|
+
error: E404
|
|
408
|
+
}), HttpApiEndpoint.post("resume", "/routes/:id/resume", {
|
|
409
|
+
params: { id: RouteId },
|
|
410
|
+
success: RouteView,
|
|
411
|
+
error: E404
|
|
412
|
+
})).annotateMerge(OpenApi.annotations({ title: "Routes" })) {};
|
|
413
|
+
var RequestsGroup = class extends HttpApiGroup.make("requests").add(
|
|
414
|
+
HttpApiEndpoint.get("list", "/sources/:key/requests", {
|
|
415
|
+
params: KeyParam,
|
|
416
|
+
query: {
|
|
417
|
+
...PageQuery,
|
|
418
|
+
status: Schema.optionalKey(RequestStatus),
|
|
419
|
+
eventType: Schema.optionalKey(Schema.String),
|
|
420
|
+
since: Schema.optionalKey(Millis),
|
|
421
|
+
until: Schema.optionalKey(Millis),
|
|
422
|
+
idempotencyKey: Schema.optionalKey(Schema.String)
|
|
423
|
+
},
|
|
424
|
+
success: RequestPage,
|
|
425
|
+
error: E404
|
|
426
|
+
}),
|
|
427
|
+
HttpApiEndpoint.get("get", "/sources/:key/requests/:id", {
|
|
428
|
+
params: {
|
|
429
|
+
key: SourceKey,
|
|
430
|
+
id: RequestId
|
|
431
|
+
},
|
|
432
|
+
success: RequestDetail,
|
|
433
|
+
error: E404
|
|
434
|
+
}),
|
|
435
|
+
/** The raw body, byte for byte (audited). The request's `contentType` says how to show it. */
|
|
436
|
+
HttpApiEndpoint.get("body", "/sources/:key/requests/:id/body", {
|
|
437
|
+
params: {
|
|
438
|
+
key: SourceKey,
|
|
439
|
+
id: RequestId
|
|
440
|
+
},
|
|
441
|
+
success: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array({ contentType: "application/octet-stream" })),
|
|
442
|
+
error: E404
|
|
443
|
+
}),
|
|
444
|
+
HttpApiEndpoint.post("replay", "/sources/:key/requests/:id/replay", {
|
|
445
|
+
params: {
|
|
446
|
+
key: SourceKey,
|
|
447
|
+
id: RequestId
|
|
448
|
+
},
|
|
449
|
+
payload: ReplayRequest,
|
|
450
|
+
success: ReplayResult,
|
|
451
|
+
error: [E400, E404]
|
|
452
|
+
}),
|
|
453
|
+
HttpApiEndpoint.post("replayRange", "/sources/:key/replay", {
|
|
454
|
+
params: KeyParam,
|
|
455
|
+
payload: ReplayRange,
|
|
456
|
+
success: ReplayRangeResult,
|
|
457
|
+
error: [E400, E404]
|
|
458
|
+
})
|
|
459
|
+
).annotateMerge(OpenApi.annotations({ title: "Requests" })) {};
|
|
460
|
+
var DeliveriesGroup = class extends HttpApiGroup.make("deliveries").add(HttpApiEndpoint.get("list", "/sources/:key/deliveries", {
|
|
461
|
+
params: KeyParam,
|
|
462
|
+
query: {
|
|
463
|
+
...PageQuery,
|
|
464
|
+
status: Schema.optionalKey(DeliveryStatus),
|
|
465
|
+
routeId: Schema.optionalKey(RouteId),
|
|
466
|
+
held: Schema.optionalKey(Schema.Boolean)
|
|
467
|
+
},
|
|
468
|
+
success: DeliveryPage,
|
|
469
|
+
error: E404
|
|
470
|
+
}), HttpApiEndpoint.post("retry", "/sources/:key/deliveries/:id/retry", {
|
|
471
|
+
params: {
|
|
472
|
+
key: SourceKey,
|
|
473
|
+
id: DeliveryId
|
|
474
|
+
},
|
|
475
|
+
success: DeliveryRecord,
|
|
476
|
+
error: [E404, E409]
|
|
477
|
+
}), HttpApiEndpoint.post("cancel", "/sources/:key/deliveries/:id/cancel", {
|
|
478
|
+
params: {
|
|
479
|
+
key: SourceKey,
|
|
480
|
+
id: DeliveryId
|
|
481
|
+
},
|
|
482
|
+
success: DeliveryRecord,
|
|
483
|
+
error: [E404, E409]
|
|
484
|
+
})).annotateMerge(OpenApi.annotations({ title: "Deliveries" })) {};
|
|
485
|
+
/**
|
|
486
|
+
* Listeners, sends to listeners, and listen tokens (docs/LOCAL-RELAY.md §5.2).
|
|
487
|
+
* `GET /sources/{key}/listen` (the WebSocket) is not here: see src/api/listen.ts.
|
|
488
|
+
*/
|
|
489
|
+
var ListenGroup = class extends HttpApiGroup.make("listen").add(
|
|
490
|
+
/** Connected listeners (at most 10), oldest first. `nextCursor` is always `null`. */
|
|
491
|
+
HttpApiEndpoint.get("listListeners", "/sources/:key/listeners", {
|
|
492
|
+
params: KeyParam,
|
|
493
|
+
success: ListenerPage,
|
|
494
|
+
error: [E404, E503]
|
|
495
|
+
}),
|
|
496
|
+
/** Closes the session with `bye: disconnected`. Audited (`listener.disconnect`). */
|
|
497
|
+
HttpApiEndpoint.delete("disconnectListener", "/sources/:key/listeners/:sessionId", {
|
|
498
|
+
params: {
|
|
499
|
+
key: SourceKey,
|
|
500
|
+
sessionId: ListenerSessionId
|
|
501
|
+
},
|
|
502
|
+
success: HttpApiSchema.NoContent,
|
|
503
|
+
error: [E404, E503]
|
|
504
|
+
}),
|
|
505
|
+
/** Pushes one stored request to a connected listener (kind `replay`). `404` when it is not connected. Audited (`listener.send`). */
|
|
506
|
+
HttpApiEndpoint.post("sendLocal", "/sources/:key/requests/:id/send-local", {
|
|
507
|
+
params: {
|
|
508
|
+
key: SourceKey,
|
|
509
|
+
id: RequestId
|
|
510
|
+
},
|
|
511
|
+
payload: SendLocal,
|
|
512
|
+
success: SendLocalResult,
|
|
513
|
+
error: [
|
|
514
|
+
E400,
|
|
515
|
+
E404,
|
|
516
|
+
E409,
|
|
517
|
+
E503
|
|
518
|
+
]
|
|
519
|
+
}),
|
|
520
|
+
/** The same for ids or a range, at most `LIMITS.replayRangeMax` per call. Audited (`listener.send`). */
|
|
521
|
+
HttpApiEndpoint.post("sendLocalRange", "/sources/:key/send-local", {
|
|
522
|
+
params: KeyParam,
|
|
523
|
+
payload: SendLocalRange,
|
|
524
|
+
success: SendLocalResult,
|
|
525
|
+
error: [
|
|
526
|
+
E400,
|
|
527
|
+
E404,
|
|
528
|
+
E409,
|
|
529
|
+
E503
|
|
530
|
+
]
|
|
531
|
+
}),
|
|
532
|
+
/** Creates a listen token for this source; the token is in the response once. Audited (`listen_token.create`). */
|
|
533
|
+
HttpApiEndpoint.post("createToken", "/sources/:key/listen-tokens", {
|
|
534
|
+
params: KeyParam,
|
|
535
|
+
payload: ListenTokenCreate,
|
|
536
|
+
success: Created(ListenTokenCreated),
|
|
537
|
+
error: [
|
|
538
|
+
E400,
|
|
539
|
+
E404,
|
|
540
|
+
E503
|
|
541
|
+
]
|
|
542
|
+
}),
|
|
543
|
+
/** The source's listen tokens, including expired ones until revoked. Never the tokens themselves. */
|
|
544
|
+
HttpApiEndpoint.get("listTokens", "/sources/:key/listen-tokens", {
|
|
545
|
+
params: KeyParam,
|
|
546
|
+
query: PageQuery,
|
|
547
|
+
success: ListenTokenPage,
|
|
548
|
+
error: [E404, E503]
|
|
549
|
+
}),
|
|
550
|
+
/** Deletes a listen token and closes its open sessions (`bye: revoked`). Audited (`listen_token.revoke`). */
|
|
551
|
+
HttpApiEndpoint.delete("revokeToken", "/sources/:key/listen-tokens/:id", {
|
|
552
|
+
params: {
|
|
553
|
+
key: SourceKey,
|
|
554
|
+
id: ListenTokenId
|
|
555
|
+
},
|
|
556
|
+
success: HttpApiSchema.NoContent,
|
|
557
|
+
error: [E404, E503]
|
|
558
|
+
})
|
|
559
|
+
).annotateMerge(OpenApi.annotations({ title: "Listeners" })) {};
|
|
560
|
+
var ConfigGroup = class extends HttpApiGroup.make("config").add(HttpApiEndpoint.put("apply", "/config", {
|
|
561
|
+
payload: ConfigApply,
|
|
562
|
+
success: ApplyResult,
|
|
563
|
+
error: [
|
|
564
|
+
E400,
|
|
565
|
+
E409,
|
|
566
|
+
E413
|
|
567
|
+
]
|
|
568
|
+
})).annotateMerge(OpenApi.annotations({ title: "Declarative config" })) {};
|
|
569
|
+
var MaintenanceGroup = class extends HttpApiGroup.make("maintenance").add(HttpApiEndpoint.post("reencrypt", "/maintenance/reencrypt", { success: ReencryptResult })).annotateMerge(OpenApi.annotations({ title: "Maintenance" })) {};
|
|
570
|
+
var AuditGroup = class extends HttpApiGroup.make("audit").add(HttpApiEndpoint.get("list", "/audit", {
|
|
571
|
+
query: {
|
|
572
|
+
...PageQuery,
|
|
573
|
+
action: Schema.optionalKey(AuditAction),
|
|
574
|
+
target: Schema.optionalKey(Schema.String)
|
|
575
|
+
},
|
|
576
|
+
success: AuditPage
|
|
577
|
+
})).annotateMerge(OpenApi.annotations({ title: "Audit" })) {};
|
|
578
|
+
/** Where the API is mounted. OpenAPI is served at `${API_PREFIX}/openapi.json`. */
|
|
579
|
+
const API_PREFIX = "/api/v1";
|
|
580
|
+
var ManifoldApi = class extends HttpApi.make("manifold").add(PresetsGroup).add(SourcesGroup).add(RelaysGroup).add(RoutesGroup).add(RequestsGroup).add(DeliveriesGroup).add(ListenGroup).add(ConfigGroup).add(MaintenanceGroup).add(AuditGroup).middleware(ApiErrorHandling).middleware(AdminAuth).prefix(API_PREFIX).annotateMerge(OpenApi.annotations({
|
|
581
|
+
title: "manifold admin API",
|
|
582
|
+
version: "1"
|
|
583
|
+
})) {};
|
|
584
|
+
/**
|
|
585
|
+
* The only `HttpApi` endpoints a listen token (`mfl_…`) may call, besides
|
|
586
|
+
* opening a listener (the WebSocket at `GET /api/v1/sources/{key}/listen`,
|
|
587
|
+
* outside the HttpApi). Every one of them is under `/sources/{key}/…`, and the
|
|
588
|
+
* token is valid only for that `key`:
|
|
589
|
+
*
|
|
590
|
+
* - read the source's request list, request detail and raw body;
|
|
591
|
+
* - push stored requests to a connected listener of that source.
|
|
592
|
+
*
|
|
593
|
+
* Everything else (config, secrets, production replay, retries, other
|
|
594
|
+
* sources, listeners list, tokens, audit) answers `401` to a listen token.
|
|
595
|
+
* `AdminAuth`'s `bearer` handler enforces this:
|
|
596
|
+
* `isListenTokenEndpoint(group.identifier, endpoint.identifier)` with the
|
|
597
|
+
* `group` and `endpoint` the security handler is given.
|
|
598
|
+
*/
|
|
599
|
+
const LISTEN_TOKEN_ENDPOINTS = [
|
|
600
|
+
{
|
|
601
|
+
group: "requests",
|
|
602
|
+
endpoint: "list"
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
group: "requests",
|
|
606
|
+
endpoint: "get"
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
group: "requests",
|
|
610
|
+
endpoint: "body"
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
group: "listen",
|
|
614
|
+
endpoint: "sendLocal"
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
group: "listen",
|
|
618
|
+
endpoint: "sendLocalRange"
|
|
619
|
+
}
|
|
620
|
+
];
|
|
621
|
+
const listenTokenEndpoints = new Set(LISTEN_TOKEN_ENDPOINTS.map((ref) => `${ref.group}.${ref.endpoint}`));
|
|
622
|
+
/** True when a listen token may call this endpoint (group identifier, endpoint name). */
|
|
623
|
+
const isListenTokenEndpoint = (group, endpoint) => listenTokenEndpoints.has(`${group}.${endpoint}`);
|
|
624
|
+
/**
|
|
625
|
+
* The source key of an admin API path under `/sources/{key}/…`, or
|
|
626
|
+
* `undefined`. A listen token is authorized against the SourceDO of this key
|
|
627
|
+
* (see `authorizeListenToken` in src/runtime/rpc.ts). `pathname` is the URL
|
|
628
|
+
* path, `API_PREFIX` included.
|
|
629
|
+
*/
|
|
630
|
+
const sourceKeyOfApiPath = (pathname) => {
|
|
631
|
+
const prefix = `${API_PREFIX}/sources/`;
|
|
632
|
+
if (!pathname.startsWith(prefix)) return void 0;
|
|
633
|
+
const key = pathname.slice(prefix.length).split("/")[0];
|
|
634
|
+
if (key === void 0 || key === "") return void 0;
|
|
635
|
+
let decoded;
|
|
636
|
+
try {
|
|
637
|
+
decoded = decodeURIComponent(key);
|
|
638
|
+
} catch {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
return Schema.is(SourceKey)(decoded) ? decoded : void 0;
|
|
642
|
+
};
|
|
643
|
+
export { API_PREFIX, AdminActor, AdminAuth, ApiErrorHandling, ApiErrors, AuditGroup, AuditPage, BadRequest, ConfigApply, ConfigGroup, Conflict, DeliveriesGroup, DeliveryPage, LISTEN_TOKEN_DEFAULT_DAYS, LISTEN_TOKEN_ENDPOINTS, LISTEN_TOKEN_MAX_DAYS, ListenGroup, ListenTokenCreate, ListenTokenCreated, ListenTokenPage, ListenerPage, ListenerRef, MaintenanceGroup, ManifoldApi, NotFound, PageQuery, PayloadTooLarge, PresetPage, PresetsGroup, ReencryptResult, RelayCreate, RelayCreateWithDefaults, RelayCreated, RelayPage, RelayPatch, RelaySecretRotated, RelaysGroup, ReplayRange, ReplayRangeResult, ReplayRequest, ReplayResult, RequestPage, RequestsGroup, RouteCreate, RoutePage, RoutePatch, RoutesGroup, SecretAdd, SecretChanged, SendLocal, SendLocalRange, SendLocalResult, SourceCreate, SourceCreateWithDefaults, SourcePage, SourcePatch, SourcesGroup, Unauthorized, Unavailable, actorLabel, isListenTokenEndpoint, sourceKeyOfApiPath };
|