@fedify/fedify 1.8.1-pr.331.1178 → 1.8.1-pr.332.1180

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.
Files changed (86) hide show
  1. package/dist/{actor-3n3a3mn9.js → actor-CHLBVvcc.js} +179 -179
  2. package/dist/{actor-FNzWBOLP.js → actor-DY2jOBlC.js} +1 -1
  3. package/dist/{authdocloader-GfBzg16C.js → authdocloader-CnPexSez.js} +3 -3
  4. package/dist/{authdocloader-Ca5hhhev.js → authdocloader-Mr-8Pvno.js} +3 -3
  5. package/dist/{builder-Clm8gcd0.js → builder-AQzzgVb7.js} +43 -4
  6. package/dist/{client-Cn1v4IjU.js → client-DrErxHbD.js} +1 -1
  7. package/dist/compat/mod.d.ts +2 -2
  8. package/dist/compat/transformers.test.js +16 -16
  9. package/dist/{context-B6mUZhs_.d.ts → context-72aRESIE.d.ts} +214 -1
  10. package/dist/{docloader-EkABD3kd.js → docloader-BMNjmXei.js} +1 -1
  11. package/dist/{esm-DYas5DHL.js → esm-CkeX4Z_e.js} +1 -1
  12. package/dist/federation/builder.test.js +5 -5
  13. package/dist/federation/collection.test.js +3 -3
  14. package/dist/federation/handler.test.js +327 -17
  15. package/dist/federation/inbox.test.js +4 -4
  16. package/dist/federation/keycache.test.js +4 -4
  17. package/dist/federation/kv.test.js +3 -3
  18. package/dist/federation/middleware.test.js +19 -18
  19. package/dist/federation/mod.d.ts +2 -2
  20. package/dist/federation/mod.js +10 -10
  21. package/dist/federation/mq.test.js +3 -3
  22. package/dist/federation/retry.test.js +3 -3
  23. package/dist/federation/router.test.js +3 -3
  24. package/dist/federation/send.test.js +10 -10
  25. package/dist/{http-BjAxnWIu.js → http-B9bZVfoW.js} +3 -3
  26. package/dist/{http-BMoRES3C.js → http-BEKI5Hou.js} +2 -2
  27. package/dist/{inbox-CSCse5JS.js → inbox-DdH5OssY.js} +1 -1
  28. package/dist/{key-DA72_KFf.js → key-BkDKGtUZ.js} +4 -4
  29. package/dist/{key-DzT1bGXW.js → key-CF4gUN_w.js} +3 -3
  30. package/dist/{key-CcIJJoyp.js → key-ClRK_LNW.js} +2 -2
  31. package/dist/{key-B8Ddhi4l.js → key-_t2XvsRR.js} +2 -2
  32. package/dist/{keycache-B4X8zg2j.js → keycache-C1F4HMt-.js} +1 -1
  33. package/dist/{keys-Db8BUZdO.js → keys-3zMMlZii.js} +1 -1
  34. package/dist/{ld-BwliTJit.js → ld-DQJTs3PX.js} +2 -2
  35. package/dist/{lookup-DSIbu5DQ.js → lookup-BbrpqrfQ.js} +1 -1
  36. package/dist/{lookup-DYSWakdP.js → lookup-DmrIfsZE.js} +1 -1
  37. package/dist/middleware-CHIEcZ7h.js +17 -0
  38. package/dist/{middleware-B5NWowV0.js → middleware-CTkxtnv3.js} +590 -10
  39. package/dist/middleware-DPT6Ob5T.js +26 -0
  40. package/dist/{middleware-CGmmWG7J.js → middleware-DlG0C99f.js} +555 -14
  41. package/dist/{mod-D9qE4iHP.d.ts → mod-OU0GgfW6.d.ts} +1 -1
  42. package/dist/mod.d.ts +3 -3
  43. package/dist/mod.js +10 -10
  44. package/dist/nodeinfo/client.test.js +5 -5
  45. package/dist/nodeinfo/handler.test.js +16 -16
  46. package/dist/nodeinfo/mod.js +2 -2
  47. package/dist/nodeinfo/semver.test.js +3 -3
  48. package/dist/nodeinfo/types.test.js +3 -3
  49. package/dist/{owner-CTaAKlYE.js → owner-DKd1nYEb.js} +2 -2
  50. package/dist/{proof-CqInNpez.js → proof-Dk0reBe7.js} +2 -2
  51. package/dist/{proof-CaMDg5Wf.js → proof-NSkkFrOi.js} +3 -3
  52. package/dist/runtime/authdocloader.test.js +9 -9
  53. package/dist/runtime/docloader.test.js +4 -4
  54. package/dist/runtime/key.test.js +5 -5
  55. package/dist/runtime/langstr.test.js +3 -3
  56. package/dist/runtime/mod.js +6 -6
  57. package/dist/runtime/multibase/multibase.test.js +3 -3
  58. package/dist/runtime/url.test.js +3 -3
  59. package/dist/{send-CylRphpj.js → send-D1L-K83i.js} +2 -2
  60. package/dist/sig/http.test.js +8 -8
  61. package/dist/sig/key.test.js +6 -6
  62. package/dist/sig/ld.test.js +7 -7
  63. package/dist/sig/mod.js +6 -6
  64. package/dist/sig/owner.test.js +7 -7
  65. package/dist/sig/proof.test.js +7 -7
  66. package/dist/testing/docloader.test.js +3 -3
  67. package/dist/testing/mod.d.ts +212 -0
  68. package/dist/testing/mod.js +3 -3
  69. package/dist/{testing-BYK226ka.js → testing-3xSoXkQB.js} +4 -3
  70. package/dist/{type-6aat8vwp.js → type-Dx19jzWd.js} +179 -179
  71. package/dist/{types-BaOxz8EG.js → types-Yo_BljxV.js} +1 -1
  72. package/dist/vocab/actor.test.js +5 -5
  73. package/dist/vocab/lookup.test.js +4 -4
  74. package/dist/vocab/mod.js +4 -4
  75. package/dist/vocab/type.test.js +3 -3
  76. package/dist/vocab/vocab.test.js +4 -4
  77. package/dist/{vocab-3WdS2ySQ.js → vocab-CgUKDr2G.js} +3 -3
  78. package/dist/webfinger/handler.test.js +16 -16
  79. package/dist/webfinger/lookup.test.js +4 -4
  80. package/dist/webfinger/mod.js +2 -2
  81. package/dist/x/cfworkers.test.js +3 -3
  82. package/dist/x/hono.d.ts +1 -1
  83. package/dist/x/sveltekit.d.ts +1 -1
  84. package/package.json +1 -1
  85. package/dist/middleware-7JYs-9eD.js +0 -26
  86. package/dist/middleware-CcZg36yb.js +0 -17
@@ -0,0 +1,26 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import "./type-Dx19jzWd.js";
7
+ import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-DlG0C99f.js";
8
+ import "./semver-DCqorrj5.js";
9
+ import "./client-DrErxHbD.js";
10
+ import "./lookup-DmrIfsZE.js";
11
+ import "./types-n7HI7VFr.js";
12
+ import "./actor-DY2jOBlC.js";
13
+ import "./key-_t2XvsRR.js";
14
+ import "./http-BEKI5Hou.js";
15
+ import "./authdocloader-Mr-8Pvno.js";
16
+ import "./ld-DQJTs3PX.js";
17
+ import "./owner-DKd1nYEb.js";
18
+ import "./proof-Dk0reBe7.js";
19
+ import "./inbox-DdH5OssY.js";
20
+ import "./builder-AQzzgVb7.js";
21
+ import "./collection-D5V3UzU3.js";
22
+ import "./keycache-C1F4HMt-.js";
23
+ import "./retry-BnpVRGFC.js";
24
+ import "./send-D1L-K83i.js";
25
+
26
+ export { FederationImpl };
@@ -3,22 +3,22 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, deno_default, getDocumentLoader, getTypeId, kvCache, lookupWebFinger } from "./type-6aat8vwp.js";
7
- import { getNodeInfo } from "./client-Cn1v4IjU.js";
8
- import { RouterError, lookupObject, traverseCollection } from "./lookup-DYSWakdP.js";
6
+ import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, deno_default, getDocumentLoader, getTypeId, kvCache, lookupWebFinger } from "./type-Dx19jzWd.js";
7
+ import { getNodeInfo } from "./client-DrErxHbD.js";
8
+ import { RouterError, lookupObject, traverseCollection } from "./lookup-DmrIfsZE.js";
9
9
  import { nodeInfoToJson } from "./types-n7HI7VFr.js";
10
- import { exportJwk, importJwk, validateCryptoKey } from "./key-B8Ddhi4l.js";
11
- import { verifyRequest } from "./http-BMoRES3C.js";
12
- import { getAuthenticatedDocumentLoader } from "./authdocloader-Ca5hhhev.js";
13
- import { detachSignature, hasSignature, signJsonLd, verifyJsonLd } from "./ld-BwliTJit.js";
14
- import { doesActorOwnKey, getKeyOwner } from "./owner-CTaAKlYE.js";
15
- import { signObject, verifyObject } from "./proof-CqInNpez.js";
16
- import { routeActivity } from "./inbox-CSCse5JS.js";
17
- import { FederationBuilderImpl } from "./builder-Clm8gcd0.js";
10
+ import { exportJwk, importJwk, validateCryptoKey } from "./key-_t2XvsRR.js";
11
+ import { verifyRequest } from "./http-BEKI5Hou.js";
12
+ import { getAuthenticatedDocumentLoader } from "./authdocloader-Mr-8Pvno.js";
13
+ import { detachSignature, hasSignature, signJsonLd, verifyJsonLd } from "./ld-DQJTs3PX.js";
14
+ import { doesActorOwnKey, getKeyOwner } from "./owner-DKd1nYEb.js";
15
+ import { signObject, verifyObject } from "./proof-Dk0reBe7.js";
16
+ import { routeActivity } from "./inbox-DdH5OssY.js";
17
+ import { FederationBuilderImpl } from "./builder-AQzzgVb7.js";
18
18
  import { buildCollectionSynchronizationHeader } from "./collection-D5V3UzU3.js";
19
- import { KvKeyCache } from "./keycache-B4X8zg2j.js";
19
+ import { KvKeyCache } from "./keycache-C1F4HMt-.js";
20
20
  import { createExponentialBackoffPolicy } from "./retry-BnpVRGFC.js";
21
- import { extractInboxes, sendActivity } from "./send-CylRphpj.js";
21
+ import { extractInboxes, sendActivity } from "./send-D1L-K83i.js";
22
22
  import { getLogger, withContext } from "@logtape/logtape";
23
23
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
24
24
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_HEADER, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
@@ -361,6 +361,13 @@ function acceptsJsonLd(request) {
361
361
  if (types[0] === "text/html" || types[0] === "application/xhtml+xml") return false;
362
362
  return types.includes("application/activity+json") || types.includes("application/ld+json") || types.includes("application/json");
363
363
  }
364
+ /**
365
+ * Handles an actor request.
366
+ * @typeParam TContextData The context data to pass to the context.
367
+ * @param request The HTTP request.
368
+ * @param parameters The parameters for handling the actor.
369
+ * @returns A promise that resolves to an HTTP response.
370
+ */
364
371
  async function handleActor(request, { identifier, context: context$1, actorDispatcher, authorizePredicate, onNotFound, onNotAcceptable, onUnauthorized }) {
365
372
  const logger$2 = getLogger([
366
373
  "fedify",
@@ -404,6 +411,13 @@ async function handleActor(request, { identifier, context: context$1, actorDispa
404
411
  Vary: "Accept"
405
412
  } });
406
413
  }
414
+ /**
415
+ * Handles an object request.
416
+ * @typeParam TContextData The context data to pass to the context.
417
+ * @param request The HTTP request.
418
+ * @param parameters The parameters for handling the object.
419
+ * @returns A promise that resolves to an HTTP response.
420
+ */
407
421
  async function handleObject(request, { values, context: context$1, objectDispatcher, authorizePredicate, onNotFound, onNotAcceptable, onUnauthorized }) {
408
422
  if (objectDispatcher == null) return await onNotFound(request);
409
423
  const object = await objectDispatcher(context$1, values);
@@ -436,6 +450,16 @@ async function handleObject(request, { values, context: context$1, objectDispatc
436
450
  Vary: "Accept"
437
451
  } });
438
452
  }
453
+ /**
454
+ * Handles a collection request.
455
+ * @typeParam TItem The type of items in the collection.
456
+ * @typeParam TContext The type of the context, extending {@link RequestContext}.
457
+ * @typeParam TContextData The context data to pass to the `TContext`.
458
+ * @typeParam TFilter The type of the filter.
459
+ * @param request The HTTP request.
460
+ * @param parameters The parameters for handling the collection.
461
+ * @returns A promise that resolves to an HTTP response.
462
+ */
439
463
  async function handleCollection(request, { name, identifier, uriGetter, filter, filterPredicate, context: context$1, collectionCallbacks, tracerProvider, onUnauthorized, onNotFound, onNotAcceptable }) {
440
464
  const spanName = name.trim().replace(/\s+/g, "_");
441
465
  tracerProvider = tracerProvider ?? trace.getTracerProvider();
@@ -577,6 +601,14 @@ async function handleCollection(request, { name, identifier, uriGetter, filter,
577
601
  Vary: "Accept"
578
602
  } });
579
603
  }
604
+ /**
605
+ * Filters collection items based on the provided predicate.
606
+ * @typeParam TItem The type of items to filter.
607
+ * @param items The items to filter.
608
+ * @param collectionName The name of the collection for logging purposes.
609
+ * @param filterPredicate Optional predicate function to filter items.
610
+ * @returns The filtered items as Objects, Links, or URLs.
611
+ */
580
612
  function filterCollectionItems(items, collectionName, filterPredicate) {
581
613
  const result = [];
582
614
  let logged = false;
@@ -600,6 +632,13 @@ function filterCollectionItems(items, collectionName, filterPredicate) {
600
632
  }
601
633
  return result;
602
634
  }
635
+ /**
636
+ * Handles an inbox request for ActivityPub activities.
637
+ * @typeParam TContextData The context data to pass to the context.
638
+ * @param request The HTTP request.
639
+ * @param options The parameters for handling the inbox.
640
+ * @returns A promise that resolves to an HTTP response.
641
+ */
603
642
  async function handleInbox(request, options) {
604
643
  const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
605
644
  const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
@@ -621,6 +660,14 @@ async function handleInbox(request, options) {
621
660
  }
622
661
  });
623
662
  }
663
+ /**
664
+ * Internal function for handling inbox requests with detailed processing.
665
+ * @typeParam TContextData The context data to pass to the context.
666
+ * @param request The HTTP request.
667
+ * @param options The parameters for handling the inbox.
668
+ * @param span The OpenTelemetry span for tracing.
669
+ * @returns A promise that resolves to an HTTP response.
670
+ */
624
671
  async function handleInboxInternal(request, { recipient, context: ctx, inboxContextFactory, kv, kvPrefixes, queue, actorDispatcher, inboxListeners, inboxErrorHandler, onNotFound, signatureTimeWindow, skipSignatureVerification, tracerProvider }, span) {
625
672
  const logger$2 = getLogger([
626
673
  "fedify",
@@ -851,6 +898,447 @@ async function handleInboxInternal(request, { recipient, context: ctx, inboxCont
851
898
  });
852
899
  }
853
900
  /**
901
+ * Handles a custom collection request.
902
+ * @typeParam TItem The type of items in the collection.
903
+ * @typeParam TParams The parameter names of the requested URL.
904
+ * @typeParam TContext The type of the context, extending {@link RequestContext}.
905
+ * @typeParam TContextData The context data to pass to the `TContext`.
906
+ * @param request The HTTP request.
907
+ * @param handleParams Parameters for handling the collection.
908
+ * @returns A promise that resolves to an HTTP response.
909
+ * @since 1.8.0
910
+ */
911
+ const handleCustomCollection = exceptWrapper(_handleCustomCollection);
912
+ async function _handleCustomCollection(request, { name, values, context: context$1, tracerProvider, collectionCallbacks: callbacks, filterPredicate }) {
913
+ verifyDefined(callbacks);
914
+ verifyJsonLdRequest(request);
915
+ await authIfNeeded(context$1, values, callbacks);
916
+ const cursor = new URL(request.url).searchParams.get("cursor");
917
+ return await new CustomCollectionHandler(name, values, context$1, callbacks, tracerProvider, Collection, CollectionPage, filterPredicate).fetchCollection(cursor).toJsonLd().then(respondAsActivity);
918
+ }
919
+ /**
920
+ * Handles an ordered collection request.
921
+ * @typeParam TItem The type of items in the collection.
922
+ * @typeParam TParams The parameter names of the requested URL.
923
+ * @typeParam TContext The type of the context, extending {@link RequestContext}.
924
+ * @typeParam TContextData The context data to pass to the `TContext`.
925
+ * @param request The HTTP request.
926
+ * @param handleParams Parameters for handling the collection.
927
+ * @returns A promise that resolves to an HTTP response.
928
+ * @since 1.8.0
929
+ */
930
+ const handleOrderedCollection = exceptWrapper(_handleOrderedCollection);
931
+ async function _handleOrderedCollection(request, { name, values, context: context$1, tracerProvider, collectionCallbacks: callbacks, filterPredicate }) {
932
+ verifyDefined(callbacks);
933
+ verifyJsonLdRequest(request);
934
+ await authIfNeeded(context$1, values, callbacks);
935
+ const cursor = new URL(request.url).searchParams.get("cursor");
936
+ return await new CustomCollectionHandler(name, values, context$1, callbacks, tracerProvider, OrderedCollection, OrderedCollectionPage, filterPredicate).fetchCollection(cursor).toJsonLd().then(respondAsActivity);
937
+ }
938
+ /**
939
+ * Handling custom collections with support for pagination and filtering.
940
+ * The main flow is on `getCollection`, `dispatch`.
941
+ *
942
+ * @typeParam TItem The type of items in the collection.
943
+ * @typeParam TParams The parameter names of the requested URL.
944
+ * @typeParam TContext The type of the context. {@link Context} or {@link RequestContext}.
945
+ * @typeParam TContextData The context data to pass to the `TContext`.
946
+ * @typeParam TCollection The type of the collection, extending {@link Collection}.
947
+ * @typeParam TCollectionPage The type of the collection page, extending {@link CollectionPage}.
948
+ * @since 1.8.0
949
+ */
950
+ var CustomCollectionHandler = class {
951
+ /**
952
+ * The tracer for telemetry.
953
+ * @type {Tracer}
954
+ */
955
+ #tracer;
956
+ /**
957
+ * The ID of the collection.
958
+ * @type {URL}
959
+ */
960
+ #id;
961
+ /**
962
+ * Store total count of items in the collection.
963
+ * Use `this.totalItems` to access the total items count.
964
+ * It is a promise because it may require an asynchronous operation to count items.
965
+ * @type {Promise<number | null> | undefined}
966
+ */
967
+ #totalItems = void 0;
968
+ /**
969
+ * The first cursor for pagination.
970
+ * It is a promise because it may require an asynchronous operation to get the first cursor.
971
+ * @type {Promise<string | null> | undefined}
972
+ */
973
+ #dispatcher;
974
+ #collection = null;
975
+ /**
976
+ * Creates a new CustomCollection instance.
977
+ * @param {string} name The name of the collection.
978
+ * @param {TParams} values The parameter values for the collection.
979
+ * @param {TContext} context The request context.
980
+ * @param {CustomCollectionCallbacks} callbacks The collection callbacks.
981
+ * @param {TracerProvider} tracerProvider The tracer provider for telemetry.
982
+ * @param {ConstructorWithTypeId<TCollection>} Collection The Collection constructor.
983
+ * @param {ConstructorWithTypeId<TCollectionPage>} CollectionPage The CollectionPage constructor.
984
+ * @param {(item: TItem) => boolean} filterPredicate Optional filter predicate for items.
985
+ */
986
+ constructor(name, values, context$1, callbacks, tracerProvider = trace.getTracerProvider(), Collection$1, CollectionPage$1, filterPredicate) {
987
+ this.name = name;
988
+ this.values = values;
989
+ this.context = context$1;
990
+ this.callbacks = callbacks;
991
+ this.tracerProvider = tracerProvider;
992
+ this.Collection = Collection$1;
993
+ this.CollectionPage = CollectionPage$1;
994
+ this.filterPredicate = filterPredicate;
995
+ this.name = this.name.trim().replace(/\s+/g, "_");
996
+ this.#tracer = this.tracerProvider.getTracer(deno_default.name, deno_default.version);
997
+ this.#id = new URL(this.context.url);
998
+ this.#dispatcher = callbacks.dispatcher.bind(callbacks);
999
+ }
1000
+ /**
1001
+ * Converts the collection to JSON-LD format.
1002
+ * @returns A promise that resolves to the JSON-LD representation.
1003
+ */
1004
+ async toJsonLd() {
1005
+ return (await this.collection).toJsonLd(this.context);
1006
+ }
1007
+ /**
1008
+ * Fetches the collection with optional cursor for pagination.
1009
+ * This method is defined for method chaining and to show processing flow properly.
1010
+ * So it is no problem to call `toJsonLd` directly on the instance.
1011
+ * @param cursor The cursor for pagination, or null for the first page.
1012
+ * @returns The CustomCollection instance for method chaining.
1013
+ */
1014
+ fetchCollection(cursor = null) {
1015
+ this.#collection = this.getCollection(cursor);
1016
+ return this;
1017
+ }
1018
+ /**
1019
+ * Gets the collection or collection page based on the cursor.
1020
+ * @param {string | null} cursor The cursor for pagination, or null for the main collection.
1021
+ * @returns {Promise<TCollection | TCollectionPage>} A promise that resolves to a Collection or CollectionPage.
1022
+ */
1023
+ async getCollection(cursor = null) {
1024
+ if (cursor !== null) {
1025
+ const props$1 = await this.getPageProps(cursor);
1026
+ return new this.CollectionPage(props$1);
1027
+ }
1028
+ const firstCursor = await this.firstCursor;
1029
+ const props = typeof firstCursor === "string" ? await this.getProps(firstCursor) : await this.getPropsWithoutCursor();
1030
+ return new this.Collection(props);
1031
+ }
1032
+ /**
1033
+ * Gets the properties for a collection page.
1034
+ * Returns the page properties including items, previous and next cursors.
1035
+ * @param {string} cursor The cursor for the page.
1036
+ * @returns A promise that resolves to the page properties.
1037
+ */
1038
+ async getPageProps(cursor) {
1039
+ const id = this.#id;
1040
+ const pages = await this.getPages({ cursor });
1041
+ const { prevCursor, nextCursor } = pages;
1042
+ const partOf = new URL(id);
1043
+ partOf.searchParams.delete("cursor");
1044
+ return {
1045
+ id,
1046
+ partOf,
1047
+ items: this.filterItems(pages.items),
1048
+ prev: this.appendToUrl(prevCursor),
1049
+ next: this.appendToUrl(nextCursor)
1050
+ };
1051
+ }
1052
+ /**
1053
+ * Gets the properties for a collection with cursors.
1054
+ * Returns the first cursor and last cursor as URL, along with total items count.
1055
+ * @param {string} firstCursor The first cursor for pagination.
1056
+ * @returns A promise that resolves to the collection properties.
1057
+ */
1058
+ async getProps(firstCursor) {
1059
+ const lastCursor = await this.callbacks.lastCursor?.(this.context, this.values);
1060
+ return {
1061
+ id: this.#id,
1062
+ first: this.appendToUrl(firstCursor),
1063
+ last: this.appendToUrl(lastCursor),
1064
+ totalItems: await this.totalItems
1065
+ };
1066
+ }
1067
+ /**
1068
+ * Gets the properties for a collection of all items and the count.
1069
+ * @returns A promise that resolves to the collection properties.
1070
+ */
1071
+ async getPropsWithoutCursor() {
1072
+ const totalItems = await this.totalItems;
1073
+ const pages = await this.getPages({ totalItems });
1074
+ return {
1075
+ id: this.#id,
1076
+ totalItems,
1077
+ items: this.filterItems(pages.items)
1078
+ };
1079
+ }
1080
+ /**
1081
+ * Gets a page of items from the collection.
1082
+ * Wraps the dispatcher in a span for telemetry.
1083
+ * @param options Options for getting the page, including cursor and total items.
1084
+ * @returns A promise that resolves to the page items.
1085
+ */
1086
+ async getPages({ cursor = null, totalItems = null }) {
1087
+ return await this.#tracer.startActiveSpan(`${this.ATTRS.DISPATCH_COLLECTION} ${this.name}`, this.spanOptions(SpanKind.SERVER, cursor), this.spanPages({
1088
+ cursor,
1089
+ totalItems
1090
+ }));
1091
+ }
1092
+ /**
1093
+ * Creates span options for telemetry.
1094
+ * @param {SpanKind} kind The span kind.
1095
+ * @param {string | null} cursor The optional cursor value.
1096
+ * @returns {SpanOptions}The span options.
1097
+ */
1098
+ spanOptions = (kind, cursor) => ({
1099
+ kind,
1100
+ attributes: {
1101
+ [this.ATTRS.ID]: this.#id.href,
1102
+ [this.ATTRS.TYPE]: this.Collection.typeId.href,
1103
+ ...cursor ? { [this.ATTRS.CURSOR]: cursor } : {}
1104
+ }
1105
+ });
1106
+ /**
1107
+ * Creates a function to wrap the dispatcher so tracing can be applied.
1108
+ * @param params Parameters including cursor and total items.
1109
+ * @returns {(span: Span) => Promise<PageItems<TItem>>} A function that handles the span operation.
1110
+ */
1111
+ spanPages = ({ totalItems = null, cursor = null }) => async (span) => {
1112
+ try {
1113
+ if (totalItems !== null) span.setAttribute(this.ATTRS.TOTAL_ITEMS, totalItems);
1114
+ const page = await this.dispatch(cursor);
1115
+ span.setAttribute(this.ATTRS.ITEMS, page.items.length);
1116
+ return page;
1117
+ } catch (e) {
1118
+ const message = e instanceof Error ? e.message : String(e);
1119
+ span.setStatus({
1120
+ code: SpanStatusCode.ERROR,
1121
+ message
1122
+ });
1123
+ throw e;
1124
+ } finally {
1125
+ span.end();
1126
+ }
1127
+ };
1128
+ /**
1129
+ * Dispatches the collection request to get items.
1130
+ * @param {string | null} cursor The cursor for pagination, or null for the first page.
1131
+ * @returns {Promise<PageItems<TItem>>} A promise that resolves to the page items.
1132
+ */
1133
+ async dispatch(cursor = null) {
1134
+ return await this.#dispatcher(this.context, this.values, cursor) ?? new ItemsNotFoundError().throw();
1135
+ }
1136
+ /**
1137
+ * Filters the items in the collection.
1138
+ * @param {TItem[]} items The items to filter.
1139
+ * @returns {(Object | Link | URL)[]} The filtered items.
1140
+ */
1141
+ filterItems(items) {
1142
+ return filterCollectionItems(items, this.name, this.filterPredicate);
1143
+ }
1144
+ /**
1145
+ * Appends a cursor to the URL if it exists.
1146
+ * @param {string | null | undefined} cursor The cursor to append, or null/undefined.
1147
+ * @returns The URL with cursor appended, or null if cursor is null/undefined.
1148
+ */
1149
+ appendToUrl(cursor) {
1150
+ return appendCursorIfExists(this.context.url, cursor);
1151
+ }
1152
+ /**
1153
+ * Gets the stored collection or collection page.
1154
+ * @returns {Promise<TCollection | TCollectionPage>} A promise that resolves to
1155
+ the collection or collection page.
1156
+ */
1157
+ get collection() {
1158
+ if (this.#collection === null) this.#collection = this.getCollection();
1159
+ return this.#collection;
1160
+ }
1161
+ /**
1162
+ * Gets the total number of items in the collection.
1163
+ * @returns {Promise<number | null>} A promise that
1164
+ resolves to the total items count, or null if not available.
1165
+ */
1166
+ get totalItems() {
1167
+ if (this.#totalItems === void 0) this.totalItems = this.callbacks.counter?.(this.context, this.values);
1168
+ return this.#totalItems;
1169
+ }
1170
+ /**
1171
+ * Sets the total number of items in the collection.
1172
+ * @param value The total items count or a promise that resolves to it.
1173
+ */
1174
+ set totalItems(value) {
1175
+ const toNumber = (value$1) => value$1 == null ? null : Number(value$1);
1176
+ this.#totalItems = value instanceof Promise ? value.then(toNumber) : Promise.resolve(toNumber(value));
1177
+ }
1178
+ /**
1179
+ * Gets the first cursor for pagination.
1180
+ * @returns {Promise<string | null>} A promise that resolves to the first cursor,
1181
+ or null if not available.
1182
+ */
1183
+ get firstCursor() {
1184
+ const cursor = this.callbacks.firstCursor?.(this.context, this.values);
1185
+ return Promise.resolve(cursor ?? null);
1186
+ }
1187
+ /**
1188
+ * Attribute constants for telemetry spans.
1189
+ */
1190
+ ATTRS = {
1191
+ DISPATCH_COLLECTION: "activitypub.dispatch_collection",
1192
+ CURSOR: "fedify.collection.cursor",
1193
+ ID: "activitypub.collection.id",
1194
+ ITEMS: "fedify.collection.items",
1195
+ TOTAL_ITEMS: "activitypub.collection.total_items",
1196
+ TYPE: "activitypub.collection.type"
1197
+ };
1198
+ };
1199
+ /**
1200
+ * A wrapper function that catches specific errors and handles them appropriately.
1201
+ * @typeParam TParams The type of parameters that extend ErrorHandlers.
1202
+ * @param handler The handler function to wrap.
1203
+ * @returns A wrapped handler function that catches and handles specific errors.
1204
+ * @since 1.8.0
1205
+ */
1206
+ function exceptWrapper(handler) {
1207
+ return async (request, handlerParams) => {
1208
+ try {
1209
+ return await handler(request, handlerParams);
1210
+ } catch (error) {
1211
+ const { onNotFound, onNotAcceptable, onUnauthorized } = handlerParams;
1212
+ switch (error?.constructor) {
1213
+ case ItemsNotFoundError: return await onNotFound(request);
1214
+ case NotAcceptableError: return await onNotAcceptable(request);
1215
+ case UnauthorizedError: return await onUnauthorized(request);
1216
+ default: throw error;
1217
+ }
1218
+ }
1219
+ };
1220
+ }
1221
+ /**
1222
+ * Verifies that a value is defined (not undefined).
1223
+ * @typeParam T The type of the value, excluding undefined.
1224
+ * @param callbacks The value to verify.
1225
+ * @throws {ItemsNotFoundError} If the value is undefined.
1226
+ * @since 1.8.0
1227
+ */
1228
+ const verifyDefined = (callbacks) => {
1229
+ if (callbacks === void 0) throw new ItemsNotFoundError();
1230
+ };
1231
+ /**
1232
+ * Verifies that a request accepts JSON-LD content type.
1233
+ * @param request The HTTP request to verify.
1234
+ * @throws {NotAcceptableError} If the request doesn't accept JSON-LD.
1235
+ * @since 1.8.0
1236
+ */
1237
+ const verifyJsonLdRequest = (request) => {
1238
+ if (!acceptsJsonLd(request)) throw new NotAcceptableError();
1239
+ };
1240
+ /**
1241
+ * Performs authorization if needed based on the authorization predicate.
1242
+ * @typeParam TContextData The context data type.
1243
+ * @param {RequestContext<TContextData>} context The request context.
1244
+ * @param {Record<string, string>} values The parameter values.
1245
+ * @param options Options containing the authorization predicate.
1246
+ * @throws {UnauthorizedError} If authorization fails.
1247
+ * @since 1.8.0
1248
+ */
1249
+ const authIfNeeded = async (context$1, values, { authorizePredicate: authorize = void 0 }) => {
1250
+ if (authorize === void 0) return;
1251
+ const key = (await context$1.getSignedKey())?.clone({}, warning.key) ?? null;
1252
+ const keyOwner = (await context$1.getSignedKeyOwner())?.clone({}, warning.keyOwner) ?? null;
1253
+ if (!await authorize(context$1, values, key, keyOwner)) throw new UnauthorizedError();
1254
+ };
1255
+ /** Warning messages for `authIfNeeded`. */
1256
+ const warning = {
1257
+ key: { $warning: {
1258
+ category: [
1259
+ "fedify",
1260
+ "federation",
1261
+ "collection"
1262
+ ],
1263
+ message: "The third parameter of AuthorizePredicate is deprecated in favor of RequestContext.getSignedKey() method. The third parameter will be removed in a future release."
1264
+ } },
1265
+ keyOwner: { $warning: {
1266
+ category: [
1267
+ "fedify",
1268
+ "federation",
1269
+ "collection"
1270
+ ],
1271
+ message: "The fourth parameter of AuthorizePredicate is deprecated in favor of RequestContext.getSignedKeyOwner() method. The fourth parameter will be removed in a future release."
1272
+ } }
1273
+ };
1274
+ /**
1275
+ * Appends a cursor parameter to a URL if the cursor exists.
1276
+ * @typeParam Cursor The type of the cursor (string, null, or undefined).
1277
+ * @param {URL} url The base URL to append the cursor to.
1278
+ * @param {string | null | undefined} cursor The cursor value to append.
1279
+ * @returns The URL with cursor appended if cursor is a string, null otherwise.
1280
+ * @since 1.8.0
1281
+ */
1282
+ const appendCursorIfExists = (url, cursor) => {
1283
+ if (cursor === null || cursor === void 0) return null;
1284
+ const copied = new URL(url);
1285
+ copied.searchParams.set("cursor", cursor);
1286
+ return copied;
1287
+ };
1288
+ /**
1289
+ * Creates an HTTP response for ActivityPub data.
1290
+ * @param {unknown} data The data to serialize as JSON-LD.
1291
+ * @returns {Response} An HTTP response with the data as ActivityPub JSON.
1292
+ * @since 1.8.0
1293
+ */
1294
+ const respondAsActivity = (data) => new Response(JSON.stringify(data), { headers: {
1295
+ "Content-Type": "application/activity+json",
1296
+ Vary: "Accept"
1297
+ } });
1298
+ /**
1299
+ * Base class for handler errors.
1300
+ * @since 1.8.0
1301
+ */
1302
+ var HandlerError = class extends Error {
1303
+ constructor(message) {
1304
+ super(message);
1305
+ }
1306
+ /**
1307
+ * Throws this error.
1308
+ * @returns Never returns, always throws.
1309
+ */
1310
+ throw() {
1311
+ throw this;
1312
+ }
1313
+ };
1314
+ /**
1315
+ * Error thrown when items are not found in a collection.
1316
+ * @since 1.8.0
1317
+ */
1318
+ var ItemsNotFoundError = class extends HandlerError {
1319
+ constructor() {
1320
+ super("Items not found in the collection.");
1321
+ }
1322
+ };
1323
+ /**
1324
+ * Error thrown when the request is not acceptable (e.g., wrong content type).
1325
+ * @since 1.8.0
1326
+ */
1327
+ var NotAcceptableError = class extends HandlerError {
1328
+ constructor() {
1329
+ super("Items not found in the collection.");
1330
+ }
1331
+ };
1332
+ /**
1333
+ * Error thrown when access to a collection is unauthorized.
1334
+ * @since 1.8.0
1335
+ */
1336
+ var UnauthorizedError = class extends HandlerError {
1337
+ constructor() {
1338
+ super("Unauthorized access to the collection.");
1339
+ }
1340
+ };
1341
+ /**
854
1342
  * Responds with the given object in JSON-LD format.
855
1343
  *
856
1344
  * @param object The object to respond with.
@@ -1730,6 +2218,34 @@ var FederationImpl = class extends FederationBuilderImpl {
1730
2218
  onNotFound,
1731
2219
  onNotAcceptable
1732
2220
  });
2221
+ case "collection": {
2222
+ const name = route.name.replace(/^collection:/, "");
2223
+ const callbacks = this.collectionCallbacks[name];
2224
+ return await handleOrderedCollection(request, {
2225
+ name,
2226
+ context: context$1,
2227
+ values: route.values,
2228
+ collectionCallbacks: callbacks,
2229
+ tracerProvider: this.tracerProvider,
2230
+ onUnauthorized,
2231
+ onNotFound,
2232
+ onNotAcceptable
2233
+ });
2234
+ }
2235
+ case "orderedCollection": {
2236
+ const name = route.name.replace(/^orderedCollection:/, "");
2237
+ const callbacks = this.collectionCallbacks[name];
2238
+ return await handleOrderedCollection(request, {
2239
+ name,
2240
+ context: context$1,
2241
+ values: route.values,
2242
+ collectionCallbacks: callbacks,
2243
+ tracerProvider: this.tracerProvider,
2244
+ onUnauthorized,
2245
+ onNotFound,
2246
+ onNotAcceptable
2247
+ });
2248
+ }
1733
2249
  default: {
1734
2250
  const response = onNotFound(request);
1735
2251
  return response instanceof Promise ? await response : response;
@@ -1870,6 +2386,18 @@ var ContextImpl = class ContextImpl {
1870
2386
  if (path == null) throw new RouterError("No featured tags collection path registered.");
1871
2387
  return new URL(path, this.canonicalOrigin);
1872
2388
  }
2389
+ getCollectionUri(name, values) {
2390
+ const customCallbacks = this.federation.collectionCallbacks[name];
2391
+ if (customCallbacks != null) {
2392
+ const collectionRouteName = `collection:${String(name)}`;
2393
+ const orderedCollectionRouteName = `orderedCollection:${String(name)}`;
2394
+ let path = this.federation.router.build(collectionRouteName, values);
2395
+ if (path == null) path = this.federation.router.build(orderedCollectionRouteName, values);
2396
+ if (path == null) throw new RouterError(`No collection dispatcher registered for ${String(name)}.`);
2397
+ return new URL(path, this.canonicalOrigin);
2398
+ }
2399
+ throw new RouterError(`No collection dispatcher registered for ${String(name)}.`);
2400
+ }
1873
2401
  parseUri(uri) {
1874
2402
  if (uri == null) return null;
1875
2403
  if (uri.origin !== this.origin && uri.origin !== this.canonicalOrigin) return null;
@@ -1957,6 +2485,19 @@ var ContextImpl = class ContextImpl {
1957
2485
  return identifier;
1958
2486
  }
1959
2487
  };
2488
+ const collectionRegex = /^(orderedC|c)ollection:(.*)$/;
2489
+ const match = route.name.match(collectionRegex);
2490
+ if (match !== null) {
2491
+ const [, type, name] = match;
2492
+ const cls = this.federation.collectionTypeIds[name];
2493
+ return {
2494
+ type,
2495
+ name,
2496
+ class: cls,
2497
+ typeId: cls.typeId,
2498
+ values: route.values
2499
+ };
2500
+ }
1960
2501
  return null;
1961
2502
  }
1962
2503
  async getActorKeyPairs(identifier) {
@@ -2676,4 +3217,4 @@ function getRequestId(request) {
2676
3217
  }
2677
3218
 
2678
3219
  //#endregion
2679
- export { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, acceptsJsonLd, actorDehydrator, autoIdAssigner, createFederation, handleActor, handleCollection, handleInbox, handleNodeInfo, handleNodeInfoJrd, handleObject, handleWebFinger, respondWithObject, respondWithObjectIfAcceptable };
3220
+ export { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, acceptsJsonLd, actorDehydrator, autoIdAssigner, createFederation, handleActor, handleCollection, handleCustomCollection, handleInbox, handleNodeInfo, handleNodeInfoJrd, handleObject, handleWebFinger, respondWithObject, respondWithObjectIfAcceptable };
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
3
  import { Activity } from "./vocab-By6mpzr-.js";
4
- import { ActivityTransformer, Context } from "./context-B6mUZhs_.js";
4
+ import { ActivityTransformer, Context } from "./context-72aRESIE.js";
5
5
 
6
6
  //#region compat/transformers.d.ts
7
7