@fedify/fedify 2.5.0-dev.2822 → 2.5.0-dev.2825

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.
@@ -0,0 +1,350 @@
1
+ /// <reference lib="esnext.temporal" />
2
+ import { DocumentLoader } from "@fedify/vocab-runtime";
3
+
4
+ //#region src/delivery-suspension/types.d.ts
5
+ /** A shape diagnostic, not an authentication or authorization verdict. @since 2.5.0 */
6
+ interface ShapeIssue {
7
+ /** Stable machine-readable diagnostic code. */
8
+ readonly code: string;
9
+ /**
10
+ * JSON pointer identifying a field in the original expansion. Required fields
11
+ * may be absent.
12
+ * Dropped occurrences identify a surviving container and include `rawPath`.
13
+ * Before expansion succeeds, pointers may identify input or context data.
14
+ */
15
+ readonly path: string;
16
+ /** Human-readable explanation. */
17
+ readonly message: string;
18
+ /** Original input pointer supplied by a diagnostic null or empty marker. */
19
+ readonly rawPath?: string;
20
+ }
21
+ /** A shape result with immutable diagnostics. @since 2.5.0 */
22
+ type ParseResult<T> = {
23
+ readonly ok: true;
24
+ readonly value: T;
25
+ readonly warnings: readonly ShapeIssue[];
26
+ } | {
27
+ readonly ok: false;
28
+ readonly issues: readonly ShapeIssue[];
29
+ };
30
+ /** A strict ASCII HTTPS origin and its original spelling. @since 2.5.0 */
31
+ interface DeliverySuspensionOrigin {
32
+ /** Original input, without rewriting. */
33
+ readonly raw: string;
34
+ /** ASCII origin with default port omitted and IPv6 brackets retained. */
35
+ readonly normalized: string;
36
+ /** Canonical hostname; IPv6 addresses have no enclosing brackets. */
37
+ readonly hostname: string;
38
+ /** Effective numeric port, including the default 443. */
39
+ readonly port: number;
40
+ }
41
+ /** Detached, deeply immutable JSON evidence. @since 2.5.0 */
42
+ type ShapeJson = null | boolean | number | string | readonly ShapeJson[] | {
43
+ readonly [key: string]: ShapeJson;
44
+ };
45
+ /** Options for the conservative raw JSON-LD shape profile. @since 2.5.0 */
46
+ interface ParseOptions {
47
+ /**
48
+ * Explicit opt-in to caller-owned context loading. Only contexts are loaded;
49
+ * the caller must bound its I/O. The default resolves preloaded contexts only.
50
+ * Loaded responses are snapshotted and memoized within each parse call.
51
+ * Context preflight uses a conservative profile and may reject valid JSON-LD
52
+ * outside that profile before expansion. See the parser documentation.
53
+ */
54
+ readonly contextLoader?: DocumentLoader;
55
+ }
56
+ /**
57
+ * Options for inspecting control claims on one exact resource. Both expectedId
58
+ * and contextLoader are captured synchronously when a metadata parse starts.
59
+ * @since 2.5.0
60
+ */
61
+ interface ControlParseOptions extends ParseOptions {
62
+ /** Required exact expanded representation ID, without URL normalization. */
63
+ readonly expectedId?: string;
64
+ }
65
+ /** A reusable claimed target description; neither variant establishes control. @since 2.5.0 */
66
+ type DeliverySuspensionTarget = {
67
+ readonly kind: "inbox";
68
+ readonly inbox: string;
69
+ } | {
70
+ readonly kind: "origin";
71
+ readonly origin: string;
72
+ };
73
+ /** Detached input and original-pass JSON-LD expansion. @since 2.5.0 */
74
+ interface ShapeEvidence {
75
+ /** Original compact spelling, copied before asynchronous work. */
76
+ readonly raw: ShapeJson;
77
+ /** Original expanded evidence, preserving extra types and properties. */
78
+ readonly expanded: ShapeJson;
79
+ }
80
+ /**
81
+ * Structurally consistent notice claims, without authentication, authority,
82
+ * freshness, history, signature verification, or complete signed-state equality.
83
+ * Literal timestamp strings and expanded IRI spellings are preserved exactly.
84
+ * @since 2.5.0
85
+ */
86
+ interface DeliverySuspensionFacts extends ShapeEvidence {
87
+ readonly id: string;
88
+ readonly controller: string;
89
+ readonly published: string;
90
+ readonly suspensionStatus: "active" | "cancelled";
91
+ readonly target: DeliverySuspensionTarget;
92
+ /** Derived strict normalization evidence, populated only for an origin target. */
93
+ readonly normalizedTargetOrigin?: DeliverySuspensionOrigin;
94
+ readonly revision: number;
95
+ readonly announcement?: string;
96
+ readonly startTime?: string;
97
+ readonly endTime: string;
98
+ readonly types: readonly string[];
99
+ }
100
+ /** Common claimed activity identity. @since 2.5.0 */
101
+ interface DeliverySuspensionActivityIdentity extends ShapeEvidence {
102
+ readonly id: string;
103
+ readonly actor: string;
104
+ readonly published: string;
105
+ readonly types: readonly string[];
106
+ }
107
+ /**
108
+ * Shape claims from a control activity. A successful Undo only identifies an
109
+ * unverified reference; it does not establish an FEP-f799 delivery exemption.
110
+ * @since 2.5.0
111
+ */
112
+ type DeliverySuspensionActivityFacts = (DeliverySuspensionActivityIdentity & {
113
+ readonly kind: "create" | "update";
114
+ readonly suspension: DeliverySuspensionFacts;
115
+ }) | (DeliverySuspensionActivityIdentity & {
116
+ readonly kind: "undo";
117
+ readonly undoneActivity: string;
118
+ readonly embeddedCreate?: {
119
+ readonly id: string;
120
+ readonly actor: string;
121
+ readonly types: readonly string[];
122
+ };
123
+ });
124
+ /** One occurrence of a link claim, including its malformed evidence. @since 2.5.0 */
125
+ interface ControlLinkValue {
126
+ readonly raw: ShapeJson;
127
+ readonly path: string;
128
+ readonly rawPath?: string;
129
+ readonly valid: boolean;
130
+ readonly value?: string;
131
+ readonly issues: readonly ShapeIssue[];
132
+ }
133
+ /**
134
+ * Multiplicity takes precedence: two or more values are multiple even if some
135
+ * are invalid. No occurrence is absent; a lone malformed occurrence is invalid.
136
+ * @since 2.5.0
137
+ */
138
+ interface ControlLinkState {
139
+ readonly state: "absent" | "single" | "multiple" | "invalid";
140
+ readonly values: readonly ControlLinkValue[];
141
+ }
142
+ /**
143
+ * One `endpoints` occurrence; reference-only nodes remain unresolved, including
144
+ * those with an `@index` annotation.
145
+ * @since 2.5.0
146
+ */
147
+ interface ActorEndpointsMetadata {
148
+ readonly raw: ShapeJson;
149
+ readonly path: string;
150
+ readonly rawPath?: string;
151
+ readonly kind: "embedded" | "unresolved" | "invalid";
152
+ readonly reference?: string;
153
+ readonly sharedInbox: ControlLinkState;
154
+ readonly issues: readonly ShapeIssue[];
155
+ }
156
+ /** One controlled-origin occurrence with an independent normalization result. @since 2.5.0 */
157
+ interface ControlledOriginValue {
158
+ readonly raw: ShapeJson;
159
+ readonly path: string;
160
+ readonly rawPath?: string;
161
+ readonly value?: string;
162
+ readonly normalization: ParseResult<DeliverySuspensionOrigin>;
163
+ }
164
+ /** Diagnostic actor claims, never independently fetched authority evidence. @since 2.5.0 */
165
+ interface ActorControlMetadata extends ShapeEvidence {
166
+ readonly id: string;
167
+ readonly types: readonly string[];
168
+ readonly inbox: ControlLinkState;
169
+ readonly endpoints: readonly ActorEndpointsMetadata[];
170
+ /** True when several endpoints parents prevent choosing a unique parent. */
171
+ readonly endpointsAmbiguous: boolean;
172
+ /** All embedded parents' sharedInbox values, retaining parent ambiguity above. */
173
+ readonly sharedInbox: ControlLinkState;
174
+ readonly controlledOrigins: readonly ControlledOriginValue[];
175
+ }
176
+ /** Diagnostic inbox claims; neither reverse link grants authority. @since 2.5.0 */
177
+ interface InboxControlMetadata extends ShapeEvidence {
178
+ readonly id: string;
179
+ readonly types: readonly string[];
180
+ readonly inboxOf: ControlLinkState;
181
+ readonly deliveryController: ControlLinkState;
182
+ }
183
+ //#endregion
184
+ //#region src/delivery-suspension/parse.d.ts
185
+ /**
186
+ * Create an offline context-only loader that returns detached copies of the
187
+ * preloaded JSON-LD contexts. Unknown URLs reject; no network fallback is used.
188
+ * The parser catches loader rejections and returns shape diagnostics.
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * import { getDeliverySuspensionContextLoader } from "@fedify/fedify/delivery-suspension";
193
+ * const contextLoader = getDeliverySuspensionContextLoader();
194
+ * const context = await contextLoader("https://w3id.org/fep/f799");
195
+ * ```
196
+ * @since 2.5.0
197
+ */
198
+ declare function getDeliverySuspensionContextLoader(): DocumentLoader;
199
+ /**
200
+ * Inspect an untrusted raw DeliverySuspension using JSON-LD semantics. Exact
201
+ * expanded IRI claims (including compact-IRI/@vocab expansion), lexical times,
202
+ * detached input, and original expansion are retained without RDF deduplication.
203
+ * Embedded activity notices retain the containing source document as raw evidence.
204
+ * Origin normalization evidence is separate in normalizedTargetOrigin; the target
205
+ * itself remains a reusable description containing its original string claim.
206
+ * Success checks shape and claimed identity consistency only, never authority,
207
+ * authenticity, currentness, history, or complete signed-state equality.
208
+ *
209
+ * This conservative profile rejects non-null @base, lossy expansion events and
210
+ * null/empty occurrences that cannot survive diagnostic expansion exactly once,
211
+ * even on unrelated properties. Such failures precede metadata diagnostics.
212
+ * JSON input is bounded to depth 64, 10000 value nodes, and 1048576 aggregate
213
+ * string code units. Contexts have a separate shared budget with the same
214
+ * bounds, and at most 32 distinct context URLs are allowed.
215
+ * Before either expansion, the complete context closure is checked and both
216
+ * passes reserve a shared conservative work budget. Context strings and term
217
+ * names are at most 2048 code units. Prefix and `@vocab` anchors must be fixed
218
+ * hierarchical absolute IRIs or `_:`; context URLs must be absolute and
219
+ * hierarchical.
220
+ * Chained prefixes, IRI-shaped context term names, nested context wrappers,
221
+ * relative context URLs, and objects containing `@context` in positions that
222
+ * may hold opaque JSON payloads are outside this profile. Each context graph is limited to depth 64 and 4096 unfolded
223
+ * objects or definitions. Marker selection allows at most eight collision attempts.
224
+ * The work budget is an admission estimate, not an exact heap or time limit.
225
+ * Expanded `@included` outside `@value` literals is rejected. Repeated
226
+ * descriptions of an inspected `@id` are also rejected across the document,
227
+ * including named graphs. Properties asserted through `@reverse` for inspected
228
+ * IDs are rejected too. Inspected IDs belong to the root node and, depending
229
+ * on the parser, the nodes directly under an activity's `object` or an actor's
230
+ * `endpoints`. Descriptions of other IDs may repeat, as may references with
231
+ * only `@id` and an optional `@index`. `@value` payloads are opaque to this
232
+ * check; other profile limits still apply.
233
+ * Timestamp lexemes are bounded to 4096 code units, with arbitrary fractional
234
+ * precision within that bound. Only plain JSON data properties are accepted;
235
+ * own __proto__ keys, accessors, cycles, sparse arrays and nonfinite numbers fail.
236
+ * Copying precedes asynchronous loading. Unknown default contexts never fetch;
237
+ * an explicit contextLoader opts into caller-owned, bounded context I/O.
238
+ *
239
+ * An already parsed unknown value cannot reveal duplicate JSON member names or
240
+ * distinguish numeric lexemes such as 1, 1.0 and 1e0. Integrity verification must
241
+ * retain its original signing input. Malformed input and loader failures return
242
+ * ok:false rather than rejecting this promise. Returned evidence is deep frozen.
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * import { parseDeliverySuspensionDocument } from "@fedify/fedify/delivery-suspension";
247
+ * async function inspectNotice(rawJson: unknown) {
248
+ * const result = await parseDeliverySuspensionDocument(rawJson);
249
+ * if (result.ok) console.log(result.value.target); // An unverified claim.
250
+ * }
251
+ * ```
252
+ * @since 2.5.0
253
+ */
254
+ declare function parseDeliverySuspensionDocument(raw: unknown, options?: ParseOptions): Promise<ParseResult<DeliverySuspensionFacts>>;
255
+ /**
256
+ * Inspect Create/Update with an embedded complete notice, or an Undo's unverified
257
+ * original-Create reference. No resource is fetched. Matching extra RDF types
258
+ * are retained; Create(Note) returns not-applicable. Success is not authenticity,
259
+ * authority, prior publication, replay admission or a delivery-hold exemption.
260
+ * In particular an Undo reference does not prove its target was an FEP-f799
261
+ * Create. Uses the same bounded conservative JSON-LD profile as
262
+ * {@link parseDeliverySuspensionDocument}.
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * import { parseDeliverySuspensionActivityDocument } from "@fedify/fedify/delivery-suspension";
267
+ * async function inspectActivity(rawActivity: unknown) {
268
+ * const result = await parseDeliverySuspensionActivityDocument(rawActivity);
269
+ * if (result.ok && result.value.kind === "undo") console.log(result.value.undoneActivity);
270
+ * }
271
+ * ```
272
+ * @since 2.5.0
273
+ */
274
+ declare function parseDeliverySuspensionActivityDocument(raw: unknown, options?: ParseOptions): Promise<ParseResult<DeliverySuspensionActivityFacts>>;
275
+ /**
276
+ * Inspect actor inbox, endpoints/sharedInbox and controlled-origin claims without
277
+ * fetching linked representations or inferring control from actor type. Every
278
+ * link occurrence remains visible: multiplicity takes precedence over invalid
279
+ * members. Referenced `endpoints` values, including those with an `@index`
280
+ * annotation, remain unresolved; multiple embedded parents retain parent
281
+ * ambiguity and all `sharedInbox` occurrences. controlledOrigins
282
+ * preserves each literal and its independent strict normalization result.
283
+ * Malformed extension claims are diagnostic facts; malformed document IDs,
284
+ * expectedId mismatch and conservative-profile failures return ok:false.
285
+ * Uses {@link parseDeliverySuspensionDocument}'s limits and JSON-LD semantics.
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * import { parseActorControlMetadata } from "@fedify/fedify/delivery-suspension";
290
+ * async function inspectActor(rawActor: unknown, actorId: string) {
291
+ * const actor = await parseActorControlMetadata(rawActor, { expectedId: actorId });
292
+ * if (actor.ok) console.log(actor.value.inbox.state);
293
+ * }
294
+ * ```
295
+ * @since 2.5.0
296
+ */
297
+ declare function parseActorControlMetadata(raw: unknown, options?: ControlParseOptions): Promise<ParseResult<ActorControlMetadata>>;
298
+ /**
299
+ * Inspect inboxOf and deliveryController reverse-link claims without fetching or
300
+ * deciding authority. Absence, a single valid link, a single invalid occurrence,
301
+ * and multiple occurrences (including invalid members) remain distinct.
302
+ * Uses {@link parseDeliverySuspensionDocument}'s bounded conservative profile;
303
+ * malformed IDs and expectedId mismatches fail instead of becoming metadata.
304
+ *
305
+ * @example
306
+ * ```typescript
307
+ * import { parseInboxControlMetadata } from "@fedify/fedify/delivery-suspension";
308
+ * async function inspectInbox(rawInbox: unknown, inboxId: string) {
309
+ * const inbox = await parseInboxControlMetadata(rawInbox, { expectedId: inboxId });
310
+ * if (inbox.ok) console.log(inbox.value.deliveryController.state);
311
+ * }
312
+ * ```
313
+ * @since 2.5.0
314
+ */
315
+ declare function parseInboxControlMetadata(raw: unknown, options?: ControlParseOptions): Promise<ParseResult<InboxControlMetadata>>;
316
+ //#endregion
317
+ //#region src/delivery-suspension/origin.d.ts
318
+ /**
319
+ * Parse an FEP-f799 HTTPS origin claim without fetching or granting authority.
320
+ *
321
+ * Accepts equivalent root spellings, preserves a DNS terminal dot, and validates
322
+ * IDNA2008 A-labels against Unicode 12.0.0. Unicode wire hosts are rejected.
323
+ * Pass the original string: an already normalized `URL.href` can conceal invalid
324
+ * input such as legacy IPv4, backslashes, dot segments, or compatibility mappings.
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * import { parseDeliverySuspensionOrigin } from "@fedify/fedify/delivery-suspension";
329
+ * const origin = parseDeliverySuspensionOrigin("https://EXAMPLE.org:443/");
330
+ * ```
331
+ * @since 2.5.0
332
+ */
333
+ declare function parseDeliverySuspensionOrigin(raw: string): ParseResult<DeliverySuspensionOrigin>;
334
+ /**
335
+ * Compute the strict HTTPS origin of a lexically valid endpoint or identifier.
336
+ * Valid path, query, and fragment components are permitted and remain in `raw`.
337
+ * This only reports a claimed origin; it does not verify control or authority.
338
+ * IDNA2008 validation uses Unicode 12.0.0. Supply the original string rather
339
+ * than an already normalized `URL.href`, which can erase invalid wire spellings.
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * import { getDeliverySuspensionUrlOrigin } from "@fedify/fedify/delivery-suspension";
344
+ * const origin = getDeliverySuspensionUrlOrigin("https://example.org/inbox?key=1");
345
+ * ```
346
+ * @since 2.5.0
347
+ */
348
+ declare function getDeliverySuspensionUrlOrigin(raw: string): ParseResult<DeliverySuspensionOrigin>;
349
+ //#endregion
350
+ export { type ActorControlMetadata, type ActorEndpointsMetadata, type ControlLinkState, type ControlLinkValue, type ControlParseOptions, type ControlledOriginValue, type DeliverySuspensionActivityFacts, type DeliverySuspensionActivityIdentity, type DeliverySuspensionFacts, type DeliverySuspensionOrigin, type DeliverySuspensionTarget, type InboxControlMetadata, type ParseOptions, type ParseResult, type ShapeEvidence, type ShapeIssue, type ShapeJson, getDeliverySuspensionContextLoader, getDeliverySuspensionUrlOrigin, parseActorControlMetadata, parseDeliverySuspensionActivityDocument, parseDeliverySuspensionDocument, parseDeliverySuspensionOrigin, parseInboxControlMetadata };