@fedify/interaction-controls 2.4.0-dev.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/dist/mod.d.ts ADDED
@@ -0,0 +1,321 @@
1
+ /// <reference lib="esnext.temporal" />
2
+ import { Accept, Activity, Actor, Announce, AnnounceAuthorization, AnnounceRequest, Article, ChatMessage, Create, Delete, FeatureAuthorization, FeatureRequest, FeaturedCollection, Like, LikeAuthorization, LikeRequest, Note, Object as Object$1, Question, QuoteAuthorization, QuoteRequest, Reject, ReplyAuthorization, ReplyRequest } from "@fedify/vocab";
3
+ import { DocumentLoader } from "@fedify/vocab-runtime";
4
+ import { Context } from "@fedify/fedify";
5
+ import { Temporal } from "temporal-polyfill";
6
+
7
+ //#region src/types.d.ts
8
+ type InteractionName = "like" | "reply" | "announce" | "quote" | "feature";
9
+ type InteractionPolicyProperty = "canLike" | "canReply" | "canAnnounce" | "canQuote" | "canFeature";
10
+ interface InteractionControl<TRequest extends Activity, TAuthorization extends Object$1, TInteracting extends Object$1, TTarget extends Object$1, TImpoliteSource extends Object$1> {
11
+ readonly name: InteractionName;
12
+ readonly policyProperty: InteractionPolicyProperty;
13
+ readonly requestTypeId: URL;
14
+ readonly authorizationTypeId: URL;
15
+ readonly verifyRequest: <TContextData>(context: Context<TContextData>, options: InteractionRequestVerificationOptions<TRequest>) => Promise<InteractionRequestVerification<TRequest, TInteracting, TTarget>>;
16
+ readonly evaluatePolicy: <TContextData>(context: Context<TContextData>, options: InteractionPolicyEvaluationOptions<TContextData, TTarget>) => Promise<InteractionPolicyDecision>;
17
+ readonly createRequest: (options: InteractionRequestCreationOptions<TInteracting, TTarget>) => TRequest;
18
+ readonly createAuthorization: (options: InteractionAuthorizationCreationOptions<TInteracting, TTarget>) => TAuthorization;
19
+ readonly verifyAuthorization: <TContextData>(context: Context<TContextData>, options: InteractionAuthorizationVerificationOptions<TContextData, TAuthorization, TInteracting, TTarget>) => Promise<InteractionAuthorizationVerification<TAuthorization>>;
20
+ readonly createAccept: (options: InteractionAcceptOptions<TRequest, TAuthorization, TInteracting, TTarget>) => Accept;
21
+ readonly createReject: (options: InteractionRejectOptions<TRequest, TInteracting, TTarget>) => Reject;
22
+ readonly createRevocation: (options: InteractionRevocationCreationOptions<TAuthorization>) => Delete;
23
+ readonly recognizeImpolite: (source: TImpoliteSource) => RecognizedImpoliteInteraction<TInteracting, TTarget, TImpoliteSource> | null;
24
+ readonly getInteractionKey: (input: InteractionKeyInput<TInteracting, TTarget>) => InteractionKey;
25
+ readonly getAuthorizationKey: (input: InteractionAuthorizationKeyInput<TAuthorization>) => InteractionAuthorizationKey;
26
+ }
27
+ interface InteractionRequestVerificationOptions<TRequest extends Activity> {
28
+ readonly request: TRequest | URL;
29
+ readonly documentLoader?: DocumentLoader;
30
+ }
31
+ type InteractionRequestVerification<TRequest extends Activity, TInteracting extends Object$1, TTarget extends Object$1> = {
32
+ readonly verified: true;
33
+ readonly request: TRequest;
34
+ readonly requestId: URL;
35
+ readonly requester: URL;
36
+ readonly interactingObject: TInteracting;
37
+ readonly interactingObjectId: URL;
38
+ readonly interactionTarget: TTarget;
39
+ readonly interactionTargetId: URL;
40
+ } | {
41
+ readonly verified: false;
42
+ readonly failure: InteractionRequestVerificationFailure;
43
+ readonly request?: TRequest;
44
+ readonly requestId?: URL;
45
+ };
46
+ type InteractionRequestVerificationFailure = {
47
+ readonly category: "unverifiable";
48
+ readonly type: "notDereferenceable";
49
+ readonly url: URL;
50
+ readonly cause?: unknown;
51
+ } | {
52
+ readonly category: "unverifiable";
53
+ readonly type: "unauthorizedFetchRequired";
54
+ readonly url: URL;
55
+ } | {
56
+ readonly category: "unverifiable";
57
+ readonly type: "invalidJsonLd";
58
+ readonly cause?: unknown;
59
+ } | {
60
+ readonly category: "invalid";
61
+ readonly type: "wrongType";
62
+ readonly expectedType: URL;
63
+ readonly actualTypes: readonly URL[];
64
+ } | {
65
+ readonly category: "invalid";
66
+ readonly type: "wrongInstrumentType";
67
+ readonly expectedTypes: readonly URL[];
68
+ readonly actualTypes: readonly URL[];
69
+ } | {
70
+ readonly category: "invalid";
71
+ readonly type: "wrongObjectType";
72
+ readonly expectedTypes: readonly URL[];
73
+ readonly actualTypes: readonly URL[];
74
+ } | {
75
+ readonly category: "invalid";
76
+ readonly type: "missingId" | "missingActor" | "missingObject" | "missingObjectId" | "missingInstrument" | "missingInstrumentId";
77
+ } | {
78
+ readonly category: "invalid";
79
+ readonly type: "idMismatch" | "objectMismatch" | "instrumentMismatch";
80
+ readonly expected: URL;
81
+ readonly actual?: URL;
82
+ } | {
83
+ readonly category: "unauthorized";
84
+ readonly type: "requesterMismatch";
85
+ readonly expected: URL;
86
+ readonly actual?: URL;
87
+ };
88
+ interface InteractionPolicyEvaluationOptions<TContextData, TTarget extends Object$1> {
89
+ readonly subject: TTarget;
90
+ readonly requester: URL;
91
+ readonly documentLoader?: DocumentLoader;
92
+ readonly matchesApprovalCollection?: MatchesApprovalCollection<TContextData>;
93
+ }
94
+ type MatchesApprovalCollection<TContextData> = (collection: URL, actor: URL, context: Context<TContextData>) => boolean | Promise<boolean>;
95
+ type InteractionPolicyDecision = {
96
+ readonly result: "automatic";
97
+ readonly reason: InteractionPolicyMatchReason;
98
+ } | {
99
+ readonly result: "manual";
100
+ readonly reason: InteractionPolicyMatchReason;
101
+ } | {
102
+ readonly result: "denied";
103
+ readonly reason: InteractionPolicyDenialReason;
104
+ };
105
+ type InteractionPolicyMatchReason = {
106
+ readonly type: "self";
107
+ } | {
108
+ readonly type: "default";
109
+ readonly default: "publicAutomatic";
110
+ } | {
111
+ readonly type: "public";
112
+ } | {
113
+ readonly type: "actor";
114
+ readonly actor: URL;
115
+ } | {
116
+ readonly type: "collection";
117
+ readonly collection: URL;
118
+ };
119
+ type InteractionPolicyDenialReason = {
120
+ readonly type: "missingPolicy";
121
+ } | {
122
+ readonly type: "missingRule";
123
+ } | {
124
+ readonly type: "noMatch";
125
+ } | {
126
+ readonly type: "unverifiableCollection";
127
+ readonly collection: URL;
128
+ };
129
+ interface InteractionRequestCreationOptions<TInteracting extends Object$1, TTarget extends Object$1> {
130
+ readonly id: URL;
131
+ readonly actor: URL;
132
+ readonly object: TTarget | URL;
133
+ readonly instrument: TInteracting | URL;
134
+ readonly to?: URL | readonly URL[];
135
+ readonly cc?: URL | readonly URL[];
136
+ }
137
+ interface InteractionAuthorizationCreationOptions<TInteracting extends Object$1, TTarget extends Object$1> {
138
+ readonly id: URL;
139
+ readonly attributedTo?: URL;
140
+ readonly interactingObject: TInteracting | URL;
141
+ readonly interactionTarget: TTarget | URL;
142
+ }
143
+ interface InteractionAuthorizationVerificationOptions<TContextData, TAuthorization extends Object$1, TInteracting extends Object$1, TTarget extends Object$1> {
144
+ readonly authorization: TAuthorization | URL;
145
+ readonly interactingObject: TInteracting | URL;
146
+ readonly interactionTarget: TTarget | URL;
147
+ readonly attributedTo?: URL;
148
+ readonly documentLoader?: DocumentLoader;
149
+ readonly getRevocation?: GetInteractionAuthorizationRevocation<TContextData>;
150
+ readonly verifyAuthenticity?: (authorization: TAuthorization, context: Context<TContextData>) => boolean | Promise<boolean>;
151
+ }
152
+ type InteractionAuthorizationVerification<TAuthorization extends Object$1> = {
153
+ readonly verified: true;
154
+ readonly authorization: TAuthorization;
155
+ readonly authorizationId: URL;
156
+ } | {
157
+ readonly verified: false;
158
+ readonly failure: InteractionAuthorizationVerificationFailure;
159
+ readonly authorization?: TAuthorization;
160
+ readonly authorizationId?: URL;
161
+ };
162
+ type InteractionAuthorizationVerificationFailure = {
163
+ readonly category: "unverifiable";
164
+ readonly type: "notDereferenceable";
165
+ readonly url: URL;
166
+ readonly cause?: unknown;
167
+ } | {
168
+ readonly category: "unverifiable";
169
+ readonly type: "unauthorizedFetchRequired";
170
+ readonly url: URL;
171
+ } | {
172
+ readonly category: "unverifiable";
173
+ readonly type: "invalidJsonLd";
174
+ readonly cause?: unknown;
175
+ } | {
176
+ readonly category: "unauthorized";
177
+ readonly type: "wrongType";
178
+ readonly expectedType: URL;
179
+ readonly actualTypes: readonly URL[];
180
+ } | {
181
+ readonly category: "unauthorized";
182
+ readonly type: "missingId" | "missingObjectId" | "missingTargetId";
183
+ } | {
184
+ readonly category: "unauthorized";
185
+ readonly type: "missingAttribution";
186
+ } | {
187
+ readonly category: "unauthorized";
188
+ readonly type: "idMismatch" | "objectMismatch" | "targetMismatch";
189
+ readonly expected: URL;
190
+ readonly actual?: URL;
191
+ } | {
192
+ readonly category: "unauthorized";
193
+ readonly type: "attributionMismatch";
194
+ readonly expected: URL;
195
+ readonly actual?: URL;
196
+ } | {
197
+ readonly category: "unauthorized";
198
+ readonly type: "originMismatch";
199
+ readonly expectedOrigin: string;
200
+ readonly actualOrigin: string;
201
+ } | {
202
+ readonly category: "unauthorized";
203
+ readonly type: "notAuthentic";
204
+ readonly detail?: string;
205
+ readonly cause?: unknown;
206
+ } | {
207
+ readonly category: "revoked";
208
+ readonly type: "deleted";
209
+ readonly revoker?: URL;
210
+ readonly revoked?: Temporal.Instant;
211
+ readonly activity?: Delete;
212
+ };
213
+ type GetInteractionAuthorizationRevocation<TContextData> = (authorizationId: URL, context: Context<TContextData>) => InteractionAuthorizationRevocation | null | Promise<InteractionAuthorizationRevocation | null>;
214
+ interface InteractionAuthorizationRevocation {
215
+ readonly revoker?: URL;
216
+ readonly revoked?: Temporal.Instant;
217
+ readonly activity?: Delete;
218
+ }
219
+ type InteractionAcceptOptions<TRequest extends Activity, TAuthorization extends Object$1, TInteracting extends Object$1, TTarget extends Object$1> = {
220
+ readonly mode: "polite";
221
+ readonly id: URL;
222
+ readonly actor: URL;
223
+ readonly request: TRequest | URL;
224
+ readonly authorization: TAuthorization | URL;
225
+ readonly to: URL | readonly URL[];
226
+ readonly cc?: URL | readonly URL[];
227
+ } | {
228
+ readonly mode: "impolite";
229
+ readonly id: URL;
230
+ readonly actor: URL;
231
+ readonly interactingObject: TInteracting | URL;
232
+ readonly interactionTarget: TTarget | URL;
233
+ readonly authorization: TAuthorization | URL;
234
+ readonly to: URL | readonly URL[];
235
+ readonly cc?: URL | readonly URL[];
236
+ };
237
+ type InteractionRejectOptions<TRequest extends Activity, TInteracting extends Object$1, TTarget extends Object$1> = {
238
+ readonly mode: "polite";
239
+ readonly id: URL;
240
+ readonly actor: URL;
241
+ readonly request: TRequest | URL;
242
+ readonly to: URL | readonly URL[];
243
+ readonly cc?: URL | readonly URL[];
244
+ } | {
245
+ readonly mode: "impolite";
246
+ readonly id: URL;
247
+ readonly actor: URL;
248
+ readonly interactingObject: TInteracting | URL;
249
+ readonly interactionTarget: TTarget | URL;
250
+ readonly to: URL | readonly URL[];
251
+ readonly cc?: URL | readonly URL[];
252
+ };
253
+ interface InteractionRevocationCreationOptions<TAuthorization extends Object$1> {
254
+ readonly id: URL;
255
+ readonly actor: URL;
256
+ readonly authorization: TAuthorization | URL;
257
+ readonly to: URL | readonly URL[];
258
+ readonly cc?: URL | readonly URL[];
259
+ }
260
+ interface RecognizedImpoliteInteraction<TInteracting extends Object$1, TTarget extends Object$1, TImpoliteSource extends Object$1> {
261
+ readonly requester: URL;
262
+ readonly interactingObject: TInteracting;
263
+ readonly interactingObjectId: URL;
264
+ readonly interactionTarget?: TTarget;
265
+ readonly interactionTargetId: URL;
266
+ readonly source: TImpoliteSource;
267
+ readonly evidence: ImpoliteInteractionEvidence;
268
+ }
269
+ type ImpoliteInteractionEvidence = {
270
+ readonly type: "activity";
271
+ readonly activityType: URL;
272
+ } | {
273
+ readonly type: "property";
274
+ readonly property: URL;
275
+ } | {
276
+ readonly type: "linkRel";
277
+ readonly rel: URL;
278
+ };
279
+ interface InteractionKeyInput<TInteracting extends Object$1, TTarget extends Object$1> {
280
+ readonly requester: URL;
281
+ readonly interactingObject: TInteracting | URL;
282
+ readonly interactionTarget: TTarget | URL;
283
+ }
284
+ interface InteractionKey {
285
+ readonly interaction: string;
286
+ readonly requester: URL;
287
+ readonly interactingObjectId: URL;
288
+ readonly interactionTargetId: URL;
289
+ }
290
+ interface InteractionAuthorizationKeyInput<TAuthorization extends Object$1> {
291
+ readonly authorization: TAuthorization | URL;
292
+ }
293
+ interface InteractionAuthorizationKey {
294
+ readonly interaction: string;
295
+ readonly authorizationId: URL;
296
+ }
297
+ //#endregion
298
+ //#region src/announce.d.ts
299
+ declare const announceInteraction: InteractionControl<AnnounceRequest, AnnounceAuthorization, Announce, Object$1, Announce>;
300
+ //#endregion
301
+ //#region src/feature.d.ts
302
+ declare const featureInteraction: InteractionControl<FeatureRequest, FeatureAuthorization, FeaturedCollection, Actor, Object$1>;
303
+ //#endregion
304
+ //#region src/key.d.ts
305
+ declare function formatInteractionKey(key: InteractionKey): string;
306
+ declare function formatAuthorizationKey(key: InteractionAuthorizationKey): string;
307
+ //#endregion
308
+ //#region src/like.d.ts
309
+ declare const likeInteraction: InteractionControl<LikeRequest, LikeAuthorization, Like, Object$1, Like>;
310
+ //#endregion
311
+ //#region src/quote.d.ts
312
+ type QuotePost = Note | Article | Question | ChatMessage;
313
+ type QuoteImpoliteSource = Create | QuotePost;
314
+ declare const quoteInteraction: InteractionControl<QuoteRequest, QuoteAuthorization, QuotePost, Object$1, QuoteImpoliteSource>;
315
+ //#endregion
316
+ //#region src/reply.d.ts
317
+ type ReplyPost = Note | Article | Question | ChatMessage;
318
+ type ReplyImpoliteSource = Create | ReplyPost;
319
+ declare const replyInteraction: InteractionControl<ReplyRequest, ReplyAuthorization, ReplyPost, Object$1, ReplyImpoliteSource>;
320
+ //#endregion
321
+ export { GetInteractionAuthorizationRevocation, ImpoliteInteractionEvidence, InteractionAcceptOptions, InteractionAuthorizationCreationOptions, InteractionAuthorizationKey, InteractionAuthorizationKeyInput, InteractionAuthorizationRevocation, InteractionAuthorizationVerification, InteractionAuthorizationVerificationFailure, InteractionAuthorizationVerificationOptions, InteractionControl, InteractionKey, InteractionKeyInput, InteractionName, InteractionPolicyDecision, InteractionPolicyDenialReason, InteractionPolicyEvaluationOptions, InteractionPolicyMatchReason, InteractionPolicyProperty, InteractionRejectOptions, InteractionRequestCreationOptions, InteractionRequestVerification, InteractionRequestVerificationFailure, InteractionRequestVerificationOptions, InteractionRevocationCreationOptions, MatchesApprovalCollection, type QuoteImpoliteSource, type QuotePost, RecognizedImpoliteInteraction, type ReplyImpoliteSource, type ReplyPost, announceInteraction, featureInteraction, formatAuthorizationKey, formatInteractionKey, likeInteraction, quoteInteraction, replyInteraction };