@fedify/fedify 1.6.1-dev.856 → 1.6.1-dev.871
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/actor-CM3gfkH6.js +36173 -0
- package/dist/{vocab/actor.js → actor-D7NMuy45.js} +5 -4
- package/dist/{vocab/actor.d.ts → actor-lFlm8FYo.d.ts} +2 -2
- package/dist/{node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert.js → assert-Dv75vaGI.js} +2 -1
- package/dist/assert_equals-ClvzlhZu.js +1020 -0
- package/dist/{node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_instance_of.js → assert_instance_of--9UCVKsi.js} +2 -1
- package/dist/{node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_is_error.js → assert_is_error-D162gXcM.js} +2 -2
- package/dist/{node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_not_equals.js → assert_not_equals-Cyf5m9Ke.js} +2 -2
- package/dist/{node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_rejects.js → assert_rejects-FOHCtlD2.js} +23 -3
- package/dist/{node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_throws.js → assert_throws-CRfQJvVx.js} +3 -2
- package/dist/{runtime/authdocloader.js → authdocloader-BKZDAq91.js} +5 -4
- package/dist/authdocloader-OfYZlI31.js +51 -0
- package/dist/{federation/builder.js → builder-DSTiU6ue.js} +18 -17
- package/dist/{_virtual/rolldown_runtime.js → chunk-HsBuZ-b2.js} +1 -0
- package/dist/client-Dw1pCSIt.d.ts +299 -0
- package/dist/{nodeinfo/client.js → client-RN5A1Qgw.js} +3 -2
- package/dist/{federation/collection.js → collection-QaGK9TVn.js} +1 -0
- package/dist/compat/mod.d.ts +12 -2
- package/dist/compat/mod.js +2 -1
- package/dist/compat/transformers.test.d.ts +2 -1
- package/dist/compat/transformers.test.js +32 -8
- package/dist/context-CzJXjNR8.d.ts +2034 -0
- package/dist/{testing/context.js → context-DZKXS0DV.js} +5 -4
- package/dist/{x/denokv.js → denokv-iB_ggPGm.js} +3 -1
- package/dist/{testing/docloader.js → docloader-09nVWLAZ.js} +1 -0
- package/dist/{runtime/contexts.js → docloader-BcMxZ9JH.js} +420 -1
- package/dist/docloader-DDFam5Xn.js +4594 -0
- package/dist/{runtime/docloader.d.ts → docloader-DTRsVZPo.d.ts} +1 -1
- package/dist/esm-BxIKwi-M.js +1221 -0
- package/dist/federation/builder.test.d.ts +2 -1
- package/dist/federation/builder.test.js +22 -7
- package/dist/federation/collection.test.d.ts +2 -1
- package/dist/federation/collection.test.js +11 -3
- package/dist/federation/handler.test.d.ts +2 -1
- package/dist/federation/handler.test.js +40 -12
- package/dist/federation/inbox.test.d.ts +2 -1
- package/dist/federation/inbox.test.js +12 -5
- package/dist/federation/keycache.test.d.ts +2 -1
- package/dist/federation/keycache.test.js +12 -7
- package/dist/federation/kv.test.d.ts +2 -1
- package/dist/federation/kv.test.js +11 -3
- package/dist/federation/middleware.test.d.ts +2 -1
- package/dist/federation/middleware.test.js +107 -26
- package/dist/federation/mod.d.ts +13 -13
- package/dist/federation/mod.js +12 -8
- package/dist/federation/mq.test.d.ts +2 -1
- package/dist/federation/mq.test.js +153 -6
- package/dist/federation/retry.test.d.ts +2 -1
- package/dist/federation/retry.test.js +5 -5
- package/dist/federation/router.test.d.ts +2 -1
- package/dist/federation/router.test.js +24 -4
- package/dist/federation/send.test.d.ts +2 -1
- package/dist/federation/send.test.js +25 -13
- package/dist/{federation/mq.js → federation-Bmj7soSg.js} +47 -1
- package/dist/{node_modules/.pnpm/@jsr_hongminhee__deno-mock-fetch@0.3.2/node_modules/@jsr/hongminhee__deno-mock-fetch/router.js → hongminhee__deno-mock-fetch-DJKLj_H-.js} +96 -1
- package/dist/{sig/http.js → http-BFvv3ZId.js} +5 -4
- package/dist/http-BImJcLfv.d.ts +258 -0
- package/dist/http-v1TqJ9Qa.js +720 -0
- package/dist/{federation/inbox.js → inbox-XV_W1qfB.js} +10 -4
- package/dist/key-BNM-ickE.js +16 -0
- package/dist/key-CVIQ7iUB.js +262 -0
- package/dist/{sig/key.js → key-DIk4Rloj.js} +2 -4
- package/dist/key-DiVhk5ik.js +10 -0
- package/dist/{federation/keycache.js → keycache-uTxsh7dt.js} +2 -1
- package/dist/{testing/keys.js → keys-D7lJqunm.js} +2 -2
- package/dist/{federation/kv.js → kv-DohFOP2C.js} +1 -0
- package/dist/{runtime/langstr.js → langstr-DbWheeIS.js} +1 -0
- package/dist/{sig/ld.js → ld-bOhcKpmk.js} +6 -6
- package/dist/{webfinger/lookup.js → lookup-B5KVF6HM.js} +1 -3
- package/dist/lookup-D3xTID-6.js +131 -0
- package/dist/{webfinger/jrd.d.ts → lookup-DAfStZtI.d.ts} +41 -1
- package/dist/{vocab/lookup.js → lookup-D_v0FFGL.js} +5 -5
- package/dist/middleware-BFedQWFA.js +33 -0
- package/dist/middleware-BiYIqI0b.js +3525 -0
- package/dist/{federation/middleware.js → middleware-CPAfRtS5.js} +957 -105
- package/dist/middleware-pAGwVkRf.js +17 -0
- package/dist/mod-1pDWKvUL.d.ts +2 -0
- package/dist/{runtime/key.d.ts → mod-BxwG4X3V.d.ts} +52 -7
- package/dist/{compat/transformers.d.ts → mod-CeLnlsqE.d.ts} +3 -4
- package/dist/{vocab/lookup.d.ts → mod-DysVoXOu.d.ts} +98 -3
- package/dist/mod-GIh5OYxW.d.ts +2 -0
- package/dist/{sig/ld.d.ts → mod-XT0mRthe.d.ts} +126 -4
- package/dist/mod-g0xFzAP9.d.ts +2 -0
- package/dist/mod.d.ts +18 -34
- package/dist/mod.js +17 -27
- package/dist/multibase-DeCHcK8L.js +316 -0
- package/dist/nodeinfo/client.test.d.ts +2 -1
- package/dist/nodeinfo/client.test.js +15 -4
- package/dist/nodeinfo/handler.test.d.ts +2 -1
- package/dist/nodeinfo/handler.test.js +39 -7
- package/dist/nodeinfo/mod.d.ts +4 -3
- package/dist/nodeinfo/mod.js +3 -3
- package/dist/nodeinfo/semver.test.d.ts +2 -1
- package/dist/nodeinfo/semver.test.js +11 -4
- package/dist/nodeinfo/types.test.d.ts +2 -1
- package/dist/nodeinfo/types.test.js +12 -4
- package/dist/{sig/owner.d.ts → owner-BjpObx-L.d.ts} +4 -6
- package/dist/{sig/owner.js → owner-tYPzPLFs.js} +4 -4
- package/dist/proof-D0cf4R25.js +595 -0
- package/dist/{sig/proof.js → proof-DIsZ1VTb.js} +5 -4
- package/dist/{federation/retry.js → retry-BiIhZWgD.js} +1 -0
- package/dist/{federation/router.js → router-D_aVZZUc.js} +20 -1
- package/dist/runtime/authdocloader.test.d.ts +2 -1
- package/dist/runtime/authdocloader.test.js +24 -9
- package/dist/runtime/docloader.test.d.ts +2 -1
- package/dist/runtime/docloader.test.js +15 -11
- package/dist/runtime/key.test.d.ts +2 -1
- package/dist/runtime/key.test.js +19 -4
- package/dist/runtime/langstr.test.d.ts +2 -1
- package/dist/runtime/langstr.test.js +11 -3
- package/dist/runtime/mod.d.ts +5 -4
- package/dist/runtime/mod.js +7 -4
- package/dist/runtime/multibase/multibase.test.d.ts +2 -1
- package/dist/runtime/multibase/multibase.test.js +11 -5
- package/dist/runtime/url.test.d.ts +2 -1
- package/dist/runtime/url.test.js +7 -6
- package/dist/{nodeinfo/semver.js → semver-CbbIgUsa.js} +1 -0
- package/dist/{federation/send.js → send-CFBOnY61.js} +3 -2
- package/dist/sig/http.test.d.ts +2 -1
- package/dist/sig/http.test.js +23 -12
- package/dist/sig/key.test.d.ts +2 -1
- package/dist/sig/key.test.js +21 -8
- package/dist/sig/ld.test.d.ts +2 -1
- package/dist/sig/ld.test.js +19 -11
- package/dist/sig/mod.d.ts +7 -5
- package/dist/sig/mod.js +7 -5
- package/dist/sig/owner.test.d.ts +2 -1
- package/dist/sig/owner.test.js +23 -9
- package/dist/sig/proof.test.d.ts +2 -1
- package/dist/sig/proof.test.js +22 -10
- package/dist/std__assert-CaBUULmX.js +151 -0
- package/dist/testing/docloader.test.d.ts +2 -1
- package/dist/testing/docloader.test.js +11 -3
- package/dist/testing/mod.d.ts +1 -0
- package/dist/testing/mod.js +2 -136
- package/dist/testing-jcGLO9Lp.js +143 -0
- package/dist/{compat/transformers.js → transformers-jxj-4o2K.js} +1 -1
- package/dist/{vocab/type.js → type-D2s5lmbZ.js} +1 -0
- package/dist/{nodeinfo/types.js → types-CqoqWDkp.js} +2 -1
- package/dist/types-D4p7qK8A.js +457 -0
- package/dist/{runtime/url.js → url-kTAI6_KP.js} +1 -0
- package/dist/vocab/actor.test.d.ts +2 -1
- package/dist/vocab/actor.test.js +5853 -14
- package/dist/vocab/lookup.test.d.ts +2 -1
- package/dist/vocab/lookup.test.js +20 -7
- package/dist/vocab/mod.d.ts +5 -5
- package/dist/vocab/mod.js +4 -5
- package/dist/vocab/type.test.d.ts +2 -1
- package/dist/vocab/type.test.js +9 -4
- package/dist/vocab/vocab.test.d.ts +2 -1
- package/dist/vocab/vocab.test.js +2440 -15
- package/dist/vocab-BSNlVPPE.js +172 -0
- package/dist/{vocab/vocab.js → vocab-BxrrllKY.js} +331 -182
- package/dist/{vocab/vocab.d.ts → vocab-CLWdoo7y.d.ts} +21 -9
- package/dist/webfinger/handler.test.d.ts +2 -1
- package/dist/webfinger/handler.test.js +39 -7
- package/dist/webfinger/lookup.test.d.ts +2 -1
- package/dist/webfinger/lookup.test.js +14 -4
- package/dist/webfinger/mod.d.ts +4 -2
- package/dist/webfinger/mod.js +3 -1
- package/dist/x/cfworkers.d.ts +49 -0
- package/dist/x/cfworkers.js +73 -0
- package/dist/x/cfworkers.test.d.ts +3 -0
- package/dist/x/cfworkers.test.js +153 -0
- package/dist/x/hono.d.ts +11 -2
- package/dist/x/sveltekit.d.ts +11 -2
- package/package.json +6 -1
- package/dist/codegen/fs.js +0 -23
- package/dist/codegen/schema.js +0 -88
- package/dist/codegen/type.js +0 -392
- package/dist/compat/types.d.ts +0 -18
- package/dist/deno.js +0 -137
- package/dist/federation/builder.d.ts +0 -19
- package/dist/federation/callback.d.ts +0 -211
- package/dist/federation/collection.d.ts +0 -36
- package/dist/federation/context.d.ts +0 -757
- package/dist/federation/federation.d.ts +0 -689
- package/dist/federation/handler.d.ts +0 -44
- package/dist/federation/handler.js +0 -543
- package/dist/federation/middleware.d.ts +0 -101
- package/dist/federation/negotiation.js +0 -63
- package/dist/federation/retry.d.ts +0 -71
- package/dist/federation/router.d.ts +0 -91
- package/dist/federation/send.d.ts +0 -29
- package/dist/node_modules/.pnpm/@jsr_hongminhee__deno-mock-fetch@0.3.2/node_modules/@jsr/hongminhee__deno-mock-fetch/mod.js +0 -101
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_equals.js +0 -49
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_exists.js +0 -32
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_false.js +0 -26
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_greater.js +0 -34
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_greater_or_equal.js +0 -34
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_strict_equals.js +0 -53
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_string_includes.js +0 -32
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assertion_error.js +0 -33
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/equal.js +0 -79
- package/dist/node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/mod.js +0 -19
- package/dist/node_modules/.pnpm/@jsr_std__internal@1.0.7/node_modules/@jsr/std__internal/assertion_state.js +0 -177
- package/dist/node_modules/.pnpm/@jsr_std__internal@1.0.7/node_modules/@jsr/std__internal/build_message.js +0 -101
- package/dist/node_modules/.pnpm/@jsr_std__internal@1.0.7/node_modules/@jsr/std__internal/diff.js +0 -274
- package/dist/node_modules/.pnpm/@jsr_std__internal@1.0.7/node_modules/@jsr/std__internal/diff_str.js +0 -148
- package/dist/node_modules/.pnpm/@jsr_std__internal@1.0.7/node_modules/@jsr/std__internal/format.js +0 -37
- package/dist/node_modules/.pnpm/@jsr_std__internal@1.0.7/node_modules/@jsr/std__internal/mod.js +0 -10
- package/dist/node_modules/.pnpm/@jsr_std__internal@1.0.7/node_modules/@jsr/std__internal/styles.js +0 -172
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/assert_path.js +0 -11
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/constants.js +0 -10
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/dirname.js +0 -14
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/from_file_url.js +0 -13
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/normalize.js +0 -14
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/normalize_string.js +0 -60
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/strip_trailing_separators.js +0 -15
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_os.js +0 -9
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/extname.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/format.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/from_file_url.js +0 -34
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/glob_to_regexp.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/is_absolute.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/join.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/join_globs.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/mod.js +0 -5
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/normalize.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/normalize_glob.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/parse.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/_util.js +0 -13
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/dirname.js +0 -54
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/from_file_url.js +0 -27
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/join.js +0 -47
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/normalize.js +0 -59
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/relative.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/resolve.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/to_file_url.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/to_namespaced_path.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/windows/from_file_url.js +0 -31
- package/dist/node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/_strip.js +0 -17
- package/dist/node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/dirname.js +0 -38
- package/dist/node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/join.js +0 -36
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_chars.js +0 -47
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_dumper_state.js +0 -4
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_loader_state.js +0 -884
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_schema.js +0 -120
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/binary.js +0 -92
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/bool.js +0 -41
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/float.js +0 -58
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/int.js +0 -118
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/map.js +0 -18
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/merge.js +0 -14
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/nil.js +0 -23
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/omap.js +0 -31
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/pairs.js +0 -22
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/regexp.js +0 -29
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/seq.js +0 -14
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/set.js +0 -17
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/str.js +0 -14
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/timestamp.js +0 -57
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_type/undefined.js +0 -24
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/_utils.js +0 -17
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/mod.js +0 -5
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/parse.js +0 -54
- package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/stringify.js +0 -4
- package/dist/node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.js +0 -68
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/AlwaysShrinkableArbitrary.js +0 -30
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/ArrayArbitrary.js +0 -203
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/ArrayInt64Arbitrary.js +0 -122
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/BigIntArbitrary.js +0 -63
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/ConstantArbitrary.js +0 -58
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/FrequencyArbitrary.js +0 -136
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/IntegerArbitrary.js +0 -64
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/LazyArbitrary.js +0 -29
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/StringUnitArbitrary.js +0 -45
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/TupleArbitrary.js +0 -74
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/WithShrinkFromOtherArbitrary.js +0 -40
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/builders/AnyArbitraryBuilder.js +0 -97
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/builders/BoxedArbitraryBuilder.js +0 -13
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/builders/CharacterArbitraryBuilder.js +0 -17
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/builders/RestrictedIntegerArbitraryBuilder.js +0 -23
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder.js +0 -32
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/data/GraphemeRanges.js +0 -990
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/ArrayInt64.js +0 -98
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BiasNumericRange.js +0 -53
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BuildSlicedGenerator.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/CustomEqualSet.js +0 -27
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/DepthContext.js +0 -24
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/DoubleHelpers.js +0 -96
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/DoubleOnlyHelpers.js +0 -25
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/FloatHelpers.js +0 -57
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/FloatOnlyHelpers.js +0 -26
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/FloatingOnlyHelpers.js +0 -26
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/GraphemeRangesHelpers.js +0 -58
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/MaxLengthFromMinLength.js +0 -72
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/NoUndefinedAsContext.js +0 -16
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/QualifiedObjectConstraints.js +0 -58
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/SameValueSet.js +0 -41
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/SameValueZeroSet.js +0 -33
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/ShrinkBigInt.js +0 -37
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/ShrinkInteger.js +0 -41
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/SlicesForStringBuilder.js +0 -74
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/StrictlyEqualSet.js +0 -38
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/TokenizeString.js +0 -47
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/NoopSlicedGenerator.js +0 -21
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/SlicedBasedGenerator.js +0 -53
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/ArrayToMap.js +0 -16
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/ArrayToSet.js +0 -16
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/CodePointsToString.js +0 -17
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/IndexToCharString.js +0 -20
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/IndexToMappedConstant.js +0 -69
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/IndexToPrintableIndex.js +0 -18
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/KeyValuePairsToObject.js +0 -42
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/PatternsToString.js +0 -32
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/TimeToDate.js +0 -30
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/_internals/mappers/UnboxedToBoxed.js +0 -22
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/anything.js +0 -14
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/array.js +0 -22
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/bigInt.js +0 -38
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/boolean.js +0 -24
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/constant.js +0 -13
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/constantFrom.js +0 -14
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/date.js +0 -30
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/dictionary.js +0 -27
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/double.js +0 -54
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/float.js +0 -60
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/float32Array.js +0 -22
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/float64Array.js +0 -22
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/fullUnicode.js +0 -24
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/fullUnicodeString.js +0 -20
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/int16Array.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/int32Array.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/int8Array.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/integer.js +0 -26
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/letrec.js +0 -28
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/mapToConstant.js +0 -26
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/maxSafeInteger.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/nat.js +0 -17
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/noBias.js +0 -11
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/oneof.js +0 -31
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/sparseArray.js +0 -68
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/string.js +0 -32
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/tuple.js +0 -13
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/uint16Array.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/uint32Array.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/uint8Array.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/uint8ClampedArray.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/arbitrary/uniqueArray.js +0 -47
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/arbitrary/definition/Arbitrary.js +0 -184
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/arbitrary/definition/Value.js +0 -31
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/precondition/PreconditionFailure.js +0 -19
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/property/IRawProperty.js +0 -12
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/property/IgnoreEqualValuesProperty.js +0 -52
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/property/Property.generic.js +0 -77
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/property/Property.js +0 -22
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/property/SkipAfterProperty.js +0 -61
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/property/TimeoutProperty.js +0 -52
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/property/UnbiasedProperty.js +0 -29
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/DecorateProperty.js +0 -26
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/Runner.js +0 -61
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/RunnerIterator.js +0 -47
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/SourceValuesIterator.js +0 -35
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/Tosser.js +0 -33
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/configuration/GlobalParameters.js +0 -12
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/configuration/QualifiedParameters.js +0 -121
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/configuration/VerbosityLevel.js +0 -14
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/reporter/ExecutionStatus.js +0 -14
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/reporter/RunExecution.js +0 -116
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/utils/PathWalker.js +0 -24
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/runner/utils/RunDetailsFormatter.js +0 -135
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/check/symbols.js +0 -15
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/random/generator/Random.js +0 -48
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/stream/LazyIterableIterator.js +0 -24
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/stream/Stream.js +0 -84
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/stream/StreamHelpers.js +0 -50
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/utils/apply.js +0 -28
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/utils/globals.js +0 -309
- package/dist/node_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/esm/utils/stringify.js +0 -217
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/CallHistory.js +0 -94
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/FetchMock.js +0 -143
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/IsSubsetOf.js +0 -103
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/Matchers.js +0 -195
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/RequestUtils.js +0 -83
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/Route.js +0 -137
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/Router.js +0 -181
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/StatusTextMap.js +0 -73
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/TypeDescriptor.js +0 -97
- package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/index.js +0 -11
- package/dist/node_modules/.pnpm/glob-to-regexp@0.4.1/node_modules/glob-to-regexp/index.js +0 -87
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/UniformArrayIntDistribution.js +0 -20
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/UniformBigIntDistribution.js +0 -20
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/UniformIntDistribution.js +0 -20
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/UnsafeUniformArrayIntDistribution.js +0 -20
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/UnsafeUniformBigIntDistribution.js +0 -32
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/UnsafeUniformIntDistribution.js +0 -43
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/internals/ArrayInt.js +0 -139
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/internals/UnsafeUniformArrayIntDistributionInternal.js +0 -26
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/distribution/internals/UnsafeUniformIntDistributionInternal.js +0 -14
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/generator/LinearCongruential.js +0 -53
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/generator/MersenneTwister.js +0 -114
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/generator/RandomGenerator.js +0 -26
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/generator/XorShift.js +0 -83
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/generator/XoroShiro.js +0 -83
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/pure-rand-default.js +0 -44
- package/dist/node_modules/.pnpm/pure-rand@6.1.0/node_modules/pure-rand/lib/esm/pure-rand.js +0 -22
- package/dist/node_modules/.pnpm/regexparam@3.0.0/node_modules/regexparam/dist/index.js +0 -37
- package/dist/nodeinfo/client.d.ts +0 -96
- package/dist/nodeinfo/handler.js +0 -46
- package/dist/nodeinfo/semver.d.ts +0 -78
- package/dist/nodeinfo/types.d.ts +0 -140
- package/dist/runtime/authdocloader.d.ts +0 -56
- package/dist/runtime/docloader.js +0 -291
- package/dist/runtime/key.js +0 -156
- package/dist/runtime/langstr.d.ts +0 -24
- package/dist/runtime/multibase/base.js +0 -32
- package/dist/runtime/multibase/constants.js +0 -172
- package/dist/runtime/multibase/index.js +0 -57
- package/dist/runtime/multibase/rfc4648.js +0 -61
- package/dist/runtime/multibase/util.js +0 -21
- package/dist/sig/http.d.ts +0 -143
- package/dist/sig/key.d.ts +0 -125
- package/dist/sig/proof.d.ts +0 -134
- package/dist/testing/fixtures/example.com/person.js +0 -29
- package/dist/testing/fixtures/example.com/person2.js +0 -48
- package/dist/vocab/constants.d.ts +0 -24
- package/dist/vocab/constants.js +0 -17
- package/dist/vocab/type.d.ts +0 -107
- package/dist/webfinger/handler.js +0 -140
- package/dist/webfinger/lookup.d.ts +0 -47
- /package/dist/{node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_object_match.js → compat-Bb5myD13.js} +0 -0
- /package/dist/{testing/fixtures → fixtures}/activitypub.academy/users/brauca_darradiul.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/announce.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/collection.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/create.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/cross-origin-actor.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/hong-gildong.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/invite.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/key.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/key2.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/object.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/orderedcollectionpage.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/paged/a.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/paged/b.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/paged-collection.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/person.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/person2.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/test.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/users/handle.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/example.com/wrong-type.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/remote.domain/users/bob.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/server.example/users/alice.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/w3id.org/identity/v1.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/w3id.org/security/data-integrity/v1.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/w3id.org/security/multikey/v1.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/w3id.org/security/v1.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/wizard.casa/users/hongminhee.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/www.w3.org/ns/activitystreams.json +0 -0
- /package/dist/{testing/fixtures → fixtures}/www.w3.org/ns/did/v1.json +0 -0
- /package/dist/{federation/kv.d.ts → kv-BmsWxOQ2.d.ts} +0 -0
- /package/dist/{federation/mq.d.ts → mq-Bue016Tz.d.ts} +0 -0
- /package/dist/{node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/basename.js → nodeinfo-CyEbLjHs.js} +0 -0
- /package/dist/{node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/common.js → runtime-BSkOVUWM.js} +0 -0
- /package/dist/{node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/constants.js → sig-BXJO--F9.js} +0 -0
- /package/dist/{codegen → vocab}/schema.yaml +0 -0
- /package/dist/{node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/dirname.js → webfinger-C3GIyXIg.js} +0 -0
@@ -0,0 +1,3525 @@
|
|
1
|
+
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
3
|
+
import { URLPattern } from "urlpattern-polyfill";
|
4
|
+
|
5
|
+
import { getDefaultActivityTransformers$1 as getDefaultActivityTransformers } from "./transformers-jxj-4o2K.js";
|
6
|
+
import { deno_default, getDocumentLoader, kvCache } from "./docloader-DDFam5Xn.js";
|
7
|
+
import { Activity, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId$1 as getTypeId } from "./actor-CM3gfkH6.js";
|
8
|
+
import { lookupWebFinger } from "./lookup-B5KVF6HM.js";
|
9
|
+
import { exportJwk, importJwk, validateCryptoKey } from "./key-DIk4Rloj.js";
|
10
|
+
import { doubleKnock, verifyRequest } from "./http-v1TqJ9Qa.js";
|
11
|
+
import { detachSignature$1 as detachSignature, doesActorOwnKey, getKeyOwner, hasSignature, signJsonLd$1 as signJsonLd, signObject$1 as signObject, verifyJsonLd$1 as verifyJsonLd, verifyObject$1 as verifyObject } from "./proof-D0cf4R25.js";
|
12
|
+
import { getNodeInfo, nodeInfoToJson } from "./types-D4p7qK8A.js";
|
13
|
+
import { getAuthenticatedDocumentLoader$1 as getAuthenticatedDocumentLoader } from "./authdocloader-OfYZlI31.js";
|
14
|
+
import { lookupObject, traverseCollection } from "./vocab-BSNlVPPE.js";
|
15
|
+
import { getLogger, withContext } from "@logtape/logtape";
|
16
|
+
import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
|
17
|
+
import { encodeHex } from "byte-encodings/hex";
|
18
|
+
import { cloneDeep } from "@es-toolkit/es-toolkit";
|
19
|
+
import { Router } from "uri-template-router";
|
20
|
+
import { parseTemplate } from "url-template";
|
21
|
+
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";
|
22
|
+
import { domainToASCII } from "node:url";
|
23
|
+
|
24
|
+
//#region federation/inbox.ts
|
25
|
+
var InboxListenerSet = class InboxListenerSet {
|
26
|
+
#listeners;
|
27
|
+
constructor() {
|
28
|
+
this.#listeners = new Map();
|
29
|
+
}
|
30
|
+
clone() {
|
31
|
+
const clone = new InboxListenerSet();
|
32
|
+
clone.#listeners = new Map(this.#listeners);
|
33
|
+
return clone;
|
34
|
+
}
|
35
|
+
add(type, listener) {
|
36
|
+
if (this.#listeners.has(type)) throw new TypeError("Listener already set for this type.");
|
37
|
+
this.#listeners.set(type, listener);
|
38
|
+
}
|
39
|
+
dispatchWithClass(activity) {
|
40
|
+
let cls = activity.constructor;
|
41
|
+
const inboxListeners = this.#listeners;
|
42
|
+
if (inboxListeners == null) return null;
|
43
|
+
while (true) {
|
44
|
+
if (inboxListeners.has(cls)) break;
|
45
|
+
if (cls === Activity) return null;
|
46
|
+
cls = globalThis.Object.getPrototypeOf(cls);
|
47
|
+
}
|
48
|
+
const listener = inboxListeners.get(cls);
|
49
|
+
return {
|
50
|
+
class: cls,
|
51
|
+
listener
|
52
|
+
};
|
53
|
+
}
|
54
|
+
dispatch(activity) {
|
55
|
+
return this.dispatchWithClass(activity)?.listener ?? null;
|
56
|
+
}
|
57
|
+
};
|
58
|
+
async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider }) {
|
59
|
+
const logger$1 = getLogger([
|
60
|
+
"fedify",
|
61
|
+
"federation",
|
62
|
+
"inbox"
|
63
|
+
]);
|
64
|
+
const cacheKey = activity.id == null ? null : [
|
65
|
+
...kvPrefixes.activityIdempotence,
|
66
|
+
ctx.origin,
|
67
|
+
activity.id.href
|
68
|
+
];
|
69
|
+
if (cacheKey != null) {
|
70
|
+
const cached = await kv.get(cacheKey);
|
71
|
+
if (cached === true) {
|
72
|
+
logger$1.debug("Activity {activityId} has already been processed.", {
|
73
|
+
activityId: activity.id?.href,
|
74
|
+
activity: json,
|
75
|
+
recipient
|
76
|
+
});
|
77
|
+
span.setStatus({
|
78
|
+
code: SpanStatusCode.UNSET,
|
79
|
+
message: `Activity ${activity.id?.href} has already been processed.`
|
80
|
+
});
|
81
|
+
return "alreadyProcessed";
|
82
|
+
}
|
83
|
+
}
|
84
|
+
if (activity.actorId == null) {
|
85
|
+
logger$1.error("Missing actor.", { activity: json });
|
86
|
+
span.setStatus({
|
87
|
+
code: SpanStatusCode.ERROR,
|
88
|
+
message: "Missing actor."
|
89
|
+
});
|
90
|
+
return "missingActor";
|
91
|
+
}
|
92
|
+
span.setAttribute("activitypub.actor.id", activity.actorId.href);
|
93
|
+
if (queue != null) {
|
94
|
+
const carrier = {};
|
95
|
+
propagation.inject(context.active(), carrier);
|
96
|
+
try {
|
97
|
+
await queue.enqueue({
|
98
|
+
type: "inbox",
|
99
|
+
id: crypto.randomUUID(),
|
100
|
+
baseUrl: ctx.origin,
|
101
|
+
activity: json,
|
102
|
+
identifier: recipient,
|
103
|
+
attempt: 0,
|
104
|
+
started: new Date().toISOString(),
|
105
|
+
traceContext: carrier
|
106
|
+
});
|
107
|
+
} catch (error) {
|
108
|
+
logger$1.error("Failed to enqueue the incoming activity {activityId}:\n{error}", {
|
109
|
+
error,
|
110
|
+
activityId: activity.id?.href,
|
111
|
+
activity: json,
|
112
|
+
recipient
|
113
|
+
});
|
114
|
+
span.setStatus({
|
115
|
+
code: SpanStatusCode.ERROR,
|
116
|
+
message: `Failed to enqueue the incoming activity ${activity.id?.href}.`
|
117
|
+
});
|
118
|
+
throw error;
|
119
|
+
}
|
120
|
+
logger$1.info("Activity {activityId} is enqueued.", {
|
121
|
+
activityId: activity.id?.href,
|
122
|
+
activity: json,
|
123
|
+
recipient
|
124
|
+
});
|
125
|
+
return "enqueued";
|
126
|
+
}
|
127
|
+
tracerProvider = tracerProvider ?? trace.getTracerProvider();
|
128
|
+
const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
|
129
|
+
return await tracer.startActiveSpan("activitypub.dispatch_inbox_listener", { kind: SpanKind.INTERNAL }, async (span$1) => {
|
130
|
+
const dispatched = inboxListeners?.dispatchWithClass(activity);
|
131
|
+
if (dispatched == null) {
|
132
|
+
logger$1.error("Unsupported activity type:\n{activity}", {
|
133
|
+
activity: json,
|
134
|
+
recipient
|
135
|
+
});
|
136
|
+
span$1.setStatus({
|
137
|
+
code: SpanStatusCode.UNSET,
|
138
|
+
message: `Unsupported activity type: ${getTypeId(activity).href}`
|
139
|
+
});
|
140
|
+
span$1.end();
|
141
|
+
return "unsupportedActivity";
|
142
|
+
}
|
143
|
+
const { class: cls, listener } = dispatched;
|
144
|
+
span$1.updateName(`activitypub.dispatch_inbox_listener ${cls.name}`);
|
145
|
+
try {
|
146
|
+
await listener(inboxContextFactory(recipient, json, activity?.id?.href, getTypeId(activity).href), activity);
|
147
|
+
} catch (error) {
|
148
|
+
try {
|
149
|
+
await inboxErrorHandler?.(ctx, error);
|
150
|
+
} catch (error$1) {
|
151
|
+
logger$1.error("An unexpected error occurred in inbox error handler:\n{error}", {
|
152
|
+
error: error$1,
|
153
|
+
activityId: activity.id?.href,
|
154
|
+
activity: json,
|
155
|
+
recipient
|
156
|
+
});
|
157
|
+
}
|
158
|
+
logger$1.error("Failed to process the incoming activity {activityId}:\n{error}", {
|
159
|
+
error,
|
160
|
+
activityId: activity.id?.href,
|
161
|
+
activity: json,
|
162
|
+
recipient
|
163
|
+
});
|
164
|
+
span$1.setStatus({
|
165
|
+
code: SpanStatusCode.ERROR,
|
166
|
+
message: String(error)
|
167
|
+
});
|
168
|
+
span$1.end();
|
169
|
+
return "error";
|
170
|
+
}
|
171
|
+
if (cacheKey != null) await kv.set(cacheKey, true, { ttl: Temporal.Duration.from({ days: 1 }) });
|
172
|
+
logger$1.info("Activity {activityId} has been processed.", {
|
173
|
+
activityId: activity.id?.href,
|
174
|
+
activity: json,
|
175
|
+
recipient
|
176
|
+
});
|
177
|
+
span$1.end();
|
178
|
+
return "success";
|
179
|
+
});
|
180
|
+
}
|
181
|
+
|
182
|
+
//#endregion
|
183
|
+
//#region federation/router.ts
|
184
|
+
function cloneInnerRouter(router) {
|
185
|
+
const clone = new Router();
|
186
|
+
clone.nid = router.nid;
|
187
|
+
clone.fsm = cloneDeep(router.fsm);
|
188
|
+
clone.routeSet = new Set(router.routeSet);
|
189
|
+
clone.templateRouteMap = new Map(router.templateRouteMap);
|
190
|
+
clone.valueRouteMap = new Map(router.valueRouteMap);
|
191
|
+
clone.hierarchy = cloneDeep(router.hierarchy);
|
192
|
+
return clone;
|
193
|
+
}
|
194
|
+
/**
|
195
|
+
* URL router and constructor based on URI Template
|
196
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
197
|
+
*/
|
198
|
+
var Router$1 = class Router$1 {
|
199
|
+
#router;
|
200
|
+
#templates;
|
201
|
+
#templateStrings;
|
202
|
+
/**
|
203
|
+
* Whether to ignore trailing slashes when matching paths.
|
204
|
+
* @since 1.6.0
|
205
|
+
*/
|
206
|
+
trailingSlashInsensitive;
|
207
|
+
/**
|
208
|
+
* Create a new {@link Router}.
|
209
|
+
* @param options Options for the router.
|
210
|
+
*/
|
211
|
+
constructor(options = {}) {
|
212
|
+
this.#router = new Router();
|
213
|
+
this.#templates = {};
|
214
|
+
this.#templateStrings = {};
|
215
|
+
this.trailingSlashInsensitive = options.trailingSlashInsensitive ?? false;
|
216
|
+
}
|
217
|
+
clone() {
|
218
|
+
const clone = new Router$1({ trailingSlashInsensitive: this.trailingSlashInsensitive });
|
219
|
+
clone.#router = cloneInnerRouter(this.#router);
|
220
|
+
clone.#templates = { ...this.#templates };
|
221
|
+
clone.#templateStrings = { ...this.#templateStrings };
|
222
|
+
return clone;
|
223
|
+
}
|
224
|
+
/**
|
225
|
+
* Checks if a path name exists in the router.
|
226
|
+
* @param name The name of the path.
|
227
|
+
* @returns `true` if the path name exists, otherwise `false`.
|
228
|
+
*/
|
229
|
+
has(name) {
|
230
|
+
return name in this.#templates;
|
231
|
+
}
|
232
|
+
/**
|
233
|
+
* Adds a new path rule to the router.
|
234
|
+
* @param template The path pattern.
|
235
|
+
* @param name The name of the path.
|
236
|
+
* @returns The names of the variables in the path pattern.
|
237
|
+
*/
|
238
|
+
add(template, name) {
|
239
|
+
if (!template.startsWith("/")) throw new RouterError("Path must start with a slash.");
|
240
|
+
const rule = this.#router.addTemplate(template, {}, name);
|
241
|
+
this.#templates[name] = parseTemplate(template);
|
242
|
+
this.#templateStrings[name] = template;
|
243
|
+
return new Set(rule.variables.map((v) => v.varname));
|
244
|
+
}
|
245
|
+
/**
|
246
|
+
* Resolves a path name and values from a URL, if any match.
|
247
|
+
* @param url The URL to resolve.
|
248
|
+
* @returns The name of the path and its values, if any match. Otherwise,
|
249
|
+
* `null`.
|
250
|
+
*/
|
251
|
+
route(url) {
|
252
|
+
let match = this.#router.resolveURI(url);
|
253
|
+
if (match == null) {
|
254
|
+
if (!this.trailingSlashInsensitive) return null;
|
255
|
+
url = url.endsWith("/") ? url.replace(/\/+$/, "") : `${url}/`;
|
256
|
+
match = this.#router.resolveURI(url);
|
257
|
+
if (match == null) return null;
|
258
|
+
}
|
259
|
+
return {
|
260
|
+
name: match.matchValue,
|
261
|
+
template: this.#templateStrings[match.matchValue],
|
262
|
+
values: match.params
|
263
|
+
};
|
264
|
+
}
|
265
|
+
/**
|
266
|
+
* Constructs a URL/path from a path name and values.
|
267
|
+
* @param name The name of the path.
|
268
|
+
* @param values The values to expand the path with.
|
269
|
+
* @returns The URL/path, if the name exists. Otherwise, `null`.
|
270
|
+
*/
|
271
|
+
build(name, values) {
|
272
|
+
if (name in this.#templates) return this.#templates[name].expand(values);
|
273
|
+
return null;
|
274
|
+
}
|
275
|
+
};
|
276
|
+
/**
|
277
|
+
* An error thrown by the {@link Router}.
|
278
|
+
*/
|
279
|
+
var RouterError = class extends Error {
|
280
|
+
/**
|
281
|
+
* Create a new {@link RouterError}.
|
282
|
+
* @param message The error message.
|
283
|
+
*/
|
284
|
+
constructor(message) {
|
285
|
+
super(message);
|
286
|
+
this.name = "RouterError";
|
287
|
+
}
|
288
|
+
};
|
289
|
+
|
290
|
+
//#endregion
|
291
|
+
//#region federation/builder.ts
|
292
|
+
var FederationBuilderImpl = class {
|
293
|
+
router;
|
294
|
+
actorCallbacks;
|
295
|
+
nodeInfoDispatcher;
|
296
|
+
objectCallbacks;
|
297
|
+
objectTypeIds;
|
298
|
+
inboxPath;
|
299
|
+
inboxCallbacks;
|
300
|
+
outboxCallbacks;
|
301
|
+
followingCallbacks;
|
302
|
+
followersCallbacks;
|
303
|
+
likedCallbacks;
|
304
|
+
featuredCallbacks;
|
305
|
+
featuredTagsCallbacks;
|
306
|
+
inboxListeners;
|
307
|
+
inboxErrorHandler;
|
308
|
+
sharedInboxKeyDispatcher;
|
309
|
+
constructor() {
|
310
|
+
this.router = new Router$1();
|
311
|
+
this.objectCallbacks = {};
|
312
|
+
this.objectTypeIds = {};
|
313
|
+
}
|
314
|
+
async build(options) {
|
315
|
+
const { FederationImpl: FederationImpl$1 } = await import("./middleware-pAGwVkRf.js");
|
316
|
+
const f = new FederationImpl$1(options);
|
317
|
+
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
318
|
+
f.router = this.router.clone();
|
319
|
+
f.router.trailingSlashInsensitive = trailingSlashInsensitiveValue;
|
320
|
+
f._initializeRouter();
|
321
|
+
f.actorCallbacks = this.actorCallbacks == null ? void 0 : { ...this.actorCallbacks };
|
322
|
+
f.nodeInfoDispatcher = this.nodeInfoDispatcher;
|
323
|
+
f.objectCallbacks = { ...this.objectCallbacks };
|
324
|
+
f.objectTypeIds = { ...this.objectTypeIds };
|
325
|
+
f.inboxPath = this.inboxPath;
|
326
|
+
f.inboxCallbacks = this.inboxCallbacks == null ? void 0 : { ...this.inboxCallbacks };
|
327
|
+
f.outboxCallbacks = this.outboxCallbacks == null ? void 0 : { ...this.outboxCallbacks };
|
328
|
+
f.followingCallbacks = this.followingCallbacks == null ? void 0 : { ...this.followingCallbacks };
|
329
|
+
f.followersCallbacks = this.followersCallbacks == null ? void 0 : { ...this.followersCallbacks };
|
330
|
+
f.likedCallbacks = this.likedCallbacks == null ? void 0 : { ...this.likedCallbacks };
|
331
|
+
f.featuredCallbacks = this.featuredCallbacks == null ? void 0 : { ...this.featuredCallbacks };
|
332
|
+
f.featuredTagsCallbacks = this.featuredTagsCallbacks == null ? void 0 : { ...this.featuredTagsCallbacks };
|
333
|
+
f.inboxListeners = this.inboxListeners?.clone();
|
334
|
+
f.inboxErrorHandler = this.inboxErrorHandler;
|
335
|
+
f.sharedInboxKeyDispatcher = this.sharedInboxKeyDispatcher;
|
336
|
+
return f;
|
337
|
+
}
|
338
|
+
_getTracer() {
|
339
|
+
return trace.getTracer(deno_default.name, deno_default.version);
|
340
|
+
}
|
341
|
+
setActorDispatcher(path, dispatcher) {
|
342
|
+
if (this.router.has("actor")) throw new RouterError("Actor dispatcher already set.");
|
343
|
+
const variables = this.router.add(path, "actor");
|
344
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for actor dispatcher must have one variable: {identifier}");
|
345
|
+
if (variables.has("handle")) getLogger([
|
346
|
+
"fedify",
|
347
|
+
"federation",
|
348
|
+
"actor"
|
349
|
+
]).warn("The {{handle}} variable in the actor dispatcher path is deprecated. Use {{identifier}} instead.");
|
350
|
+
const callbacks = { dispatcher: async (context$1, identifier) => {
|
351
|
+
const actor = await this._getTracer().startActiveSpan("activitypub.dispatch_actor", {
|
352
|
+
kind: SpanKind.SERVER,
|
353
|
+
attributes: { "fedify.actor.identifier": identifier }
|
354
|
+
}, async (span) => {
|
355
|
+
try {
|
356
|
+
const actor$1 = await dispatcher(context$1, identifier);
|
357
|
+
span.setAttribute("activitypub.actor.id", (actor$1?.id ?? context$1.getActorUri(identifier)).href);
|
358
|
+
if (actor$1 == null) span.setStatus({ code: SpanStatusCode.ERROR });
|
359
|
+
else span.setAttribute("activitypub.actor.type", getTypeId(actor$1).href);
|
360
|
+
return actor$1;
|
361
|
+
} catch (error) {
|
362
|
+
span.setStatus({
|
363
|
+
code: SpanStatusCode.ERROR,
|
364
|
+
message: String(error)
|
365
|
+
});
|
366
|
+
throw error;
|
367
|
+
} finally {
|
368
|
+
span.end();
|
369
|
+
}
|
370
|
+
});
|
371
|
+
if (actor == null) return null;
|
372
|
+
const logger$1 = getLogger([
|
373
|
+
"fedify",
|
374
|
+
"federation",
|
375
|
+
"actor"
|
376
|
+
]);
|
377
|
+
if (actor.id == null) logger$1.warn("Actor dispatcher returned an actor without an id property. Set the property with Context.getActorUri(identifier).");
|
378
|
+
else if (actor.id.href != context$1.getActorUri(identifier).href) logger$1.warn("Actor dispatcher returned an actor with an id property that does not match the actor URI. Set the property with Context.getActorUri(identifier).");
|
379
|
+
if (this.followingCallbacks != null && this.followingCallbacks.dispatcher != null) {
|
380
|
+
if (actor.followingId == null) logger$1.warn("You configured a following collection dispatcher, but the actor does not have a following property. Set the property with Context.getFollowingUri(identifier).");
|
381
|
+
else if (actor.followingId.href != context$1.getFollowingUri(identifier).href) logger$1.warn("You configured a following collection dispatcher, but the actor's following property does not match the following collection URI. Set the property with Context.getFollowingUri(identifier).");
|
382
|
+
}
|
383
|
+
if (this.followersCallbacks != null && this.followersCallbacks.dispatcher != null) {
|
384
|
+
if (actor.followersId == null) logger$1.warn("You configured a followers collection dispatcher, but the actor does not have a followers property. Set the property with Context.getFollowersUri(identifier).");
|
385
|
+
else if (actor.followersId.href != context$1.getFollowersUri(identifier).href) logger$1.warn("You configured a followers collection dispatcher, but the actor's followers property does not match the followers collection URI. Set the property with Context.getFollowersUri(identifier).");
|
386
|
+
}
|
387
|
+
if (this.outboxCallbacks != null && this.outboxCallbacks.dispatcher != null) {
|
388
|
+
if (actor?.outboxId == null) logger$1.warn("You configured an outbox collection dispatcher, but the actor does not have an outbox property. Set the property with Context.getOutboxUri(identifier).");
|
389
|
+
else if (actor.outboxId.href != context$1.getOutboxUri(identifier).href) logger$1.warn("You configured an outbox collection dispatcher, but the actor's outbox property does not match the outbox collection URI. Set the property with Context.getOutboxUri(identifier).");
|
390
|
+
}
|
391
|
+
if (this.likedCallbacks != null && this.likedCallbacks.dispatcher != null) {
|
392
|
+
if (actor?.likedId == null) logger$1.warn("You configured a liked collection dispatcher, but the actor does not have a liked property. Set the property with Context.getLikedUri(identifier).");
|
393
|
+
else if (actor.likedId.href != context$1.getLikedUri(identifier).href) logger$1.warn("You configured a liked collection dispatcher, but the actor's liked property does not match the liked collection URI. Set the property with Context.getLikedUri(identifier).");
|
394
|
+
}
|
395
|
+
if (this.featuredCallbacks != null && this.featuredCallbacks.dispatcher != null) {
|
396
|
+
if (actor?.featuredId == null) logger$1.warn("You configured a featured collection dispatcher, but the actor does not have a featured property. Set the property with Context.getFeaturedUri(identifier).");
|
397
|
+
else if (actor.featuredId.href != context$1.getFeaturedUri(identifier).href) logger$1.warn("You configured a featured collection dispatcher, but the actor's featured property does not match the featured collection URI. Set the property with Context.getFeaturedUri(identifier).");
|
398
|
+
}
|
399
|
+
if (this.featuredTagsCallbacks != null && this.featuredTagsCallbacks.dispatcher != null) {
|
400
|
+
if (actor?.featuredTagsId == null) logger$1.warn("You configured a featured tags collection dispatcher, but the actor does not have a featuredTags property. Set the property with Context.getFeaturedTagsUri(identifier).");
|
401
|
+
else if (actor.featuredTagsId.href != context$1.getFeaturedTagsUri(identifier).href) logger$1.warn("You configured a featured tags collection dispatcher, but the actor's featuredTags property does not match the featured tags collection URI. Set the property with Context.getFeaturedTagsUri(identifier).");
|
402
|
+
}
|
403
|
+
if (this.router.has("inbox")) {
|
404
|
+
if (actor.inboxId == null) logger$1.warn("You configured inbox listeners, but the actor does not have an inbox property. Set the property with Context.getInboxUri(identifier).");
|
405
|
+
else if (actor.inboxId.href != context$1.getInboxUri(identifier).href) logger$1.warn("You configured inbox listeners, but the actor's inbox property does not match the inbox URI. Set the property with Context.getInboxUri(identifier).");
|
406
|
+
if (actor.endpoints == null || actor.endpoints.sharedInbox == null) logger$1.warn("You configured inbox listeners, but the actor does not have a endpoints.sharedInbox property. Set the property with Context.getInboxUri().");
|
407
|
+
else if (actor.endpoints.sharedInbox.href != context$1.getInboxUri().href) logger$1.warn("You configured inbox listeners, but the actor's endpoints.sharedInbox property does not match the shared inbox URI. Set the property with Context.getInboxUri().");
|
408
|
+
}
|
409
|
+
if (callbacks.keyPairsDispatcher != null) {
|
410
|
+
if (actor.publicKeyId == null) logger$1.warn("You configured a key pairs dispatcher, but the actor does not have a publicKey property. Set the property with Context.getActorKeyPairs(identifier).");
|
411
|
+
if (actor.assertionMethodId == null) logger$1.warn("You configured a key pairs dispatcher, but the actor does not have an assertionMethod property. Set the property with Context.getActorKeyPairs(identifier).");
|
412
|
+
}
|
413
|
+
return actor;
|
414
|
+
} };
|
415
|
+
this.actorCallbacks = callbacks;
|
416
|
+
const setters = {
|
417
|
+
setKeyPairsDispatcher: (dispatcher$1) => {
|
418
|
+
callbacks.keyPairsDispatcher = (ctx, identifier) => this._getTracer().startActiveSpan("activitypub.dispatch_actor_key_pairs", {
|
419
|
+
kind: SpanKind.SERVER,
|
420
|
+
attributes: {
|
421
|
+
"activitypub.actor.id": ctx.getActorUri(identifier).href,
|
422
|
+
"fedify.actor.identifier": identifier
|
423
|
+
}
|
424
|
+
}, async (span) => {
|
425
|
+
try {
|
426
|
+
return await dispatcher$1(ctx, identifier);
|
427
|
+
} catch (e) {
|
428
|
+
span.setStatus({
|
429
|
+
code: SpanStatusCode.ERROR,
|
430
|
+
message: String(e)
|
431
|
+
});
|
432
|
+
throw e;
|
433
|
+
} finally {
|
434
|
+
span.end();
|
435
|
+
}
|
436
|
+
});
|
437
|
+
return setters;
|
438
|
+
},
|
439
|
+
mapHandle(mapper) {
|
440
|
+
callbacks.handleMapper = mapper;
|
441
|
+
return setters;
|
442
|
+
},
|
443
|
+
mapAlias(mapper) {
|
444
|
+
callbacks.aliasMapper = mapper;
|
445
|
+
return setters;
|
446
|
+
},
|
447
|
+
authorize(predicate) {
|
448
|
+
callbacks.authorizePredicate = predicate;
|
449
|
+
return setters;
|
450
|
+
}
|
451
|
+
};
|
452
|
+
return setters;
|
453
|
+
}
|
454
|
+
setNodeInfoDispatcher(path, dispatcher) {
|
455
|
+
if (this.router.has("nodeInfo")) throw new RouterError("NodeInfo dispatcher already set.");
|
456
|
+
const variables = this.router.add(path, "nodeInfo");
|
457
|
+
if (variables.size !== 0) throw new RouterError("Path for NodeInfo dispatcher must have no variables.");
|
458
|
+
this.nodeInfoDispatcher = dispatcher;
|
459
|
+
}
|
460
|
+
setObjectDispatcher(cls, path, dispatcher) {
|
461
|
+
const routeName = `object:${cls.typeId.href}`;
|
462
|
+
if (this.router.has(routeName)) throw new RouterError(`Object dispatcher for ${cls.name} already set.`);
|
463
|
+
const variables = this.router.add(path, routeName);
|
464
|
+
if (variables.size < 1) throw new RouterError("Path for object dispatcher must have at least one variable.");
|
465
|
+
const callbacks = {
|
466
|
+
dispatcher: (ctx, values) => {
|
467
|
+
const tracer = this._getTracer();
|
468
|
+
return tracer.startActiveSpan("activitypub.dispatch_object", {
|
469
|
+
kind: SpanKind.SERVER,
|
470
|
+
attributes: {
|
471
|
+
"fedify.object.type": cls.typeId.href,
|
472
|
+
...globalThis.Object.fromEntries(globalThis.Object.entries(values).map(([k, v]) => [`fedify.object.values.${k}`, v]))
|
473
|
+
}
|
474
|
+
}, async (span) => {
|
475
|
+
try {
|
476
|
+
const object = await dispatcher(ctx, values);
|
477
|
+
span.setAttribute("activitypub.object.id", (object?.id ?? ctx.getObjectUri(cls, values)).href);
|
478
|
+
if (object == null) span.setStatus({ code: SpanStatusCode.ERROR });
|
479
|
+
else span.setAttribute("activitypub.object.type", getTypeId(object).href);
|
480
|
+
return object;
|
481
|
+
} catch (e) {
|
482
|
+
span.setStatus({
|
483
|
+
code: SpanStatusCode.ERROR,
|
484
|
+
message: String(e)
|
485
|
+
});
|
486
|
+
throw e;
|
487
|
+
} finally {
|
488
|
+
span.end();
|
489
|
+
}
|
490
|
+
});
|
491
|
+
},
|
492
|
+
parameters: variables
|
493
|
+
};
|
494
|
+
this.objectCallbacks[cls.typeId.href] = callbacks;
|
495
|
+
this.objectTypeIds[cls.typeId.href] = cls;
|
496
|
+
const setters = { authorize(predicate) {
|
497
|
+
callbacks.authorizePredicate = predicate;
|
498
|
+
return setters;
|
499
|
+
} };
|
500
|
+
return setters;
|
501
|
+
}
|
502
|
+
setInboxDispatcher(path, dispatcher) {
|
503
|
+
if (this.inboxCallbacks != null) throw new RouterError("Inbox dispatcher already set.");
|
504
|
+
if (this.router.has("inbox")) {
|
505
|
+
if (this.inboxPath !== path) throw new RouterError("Inbox dispatcher path must match inbox listener path.");
|
506
|
+
} else {
|
507
|
+
const variables = this.router.add(path, "inbox");
|
508
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for inbox dispatcher must have one variable: {identifier}");
|
509
|
+
if (variables.has("handle")) getLogger([
|
510
|
+
"fedify",
|
511
|
+
"federation",
|
512
|
+
"inbox"
|
513
|
+
]).warn("The {{handle}} variable in the inbox dispatcher path is deprecated. Use {{identifier}} instead.");
|
514
|
+
this.inboxPath = path;
|
515
|
+
}
|
516
|
+
const callbacks = { dispatcher };
|
517
|
+
this.inboxCallbacks = callbacks;
|
518
|
+
const setters = {
|
519
|
+
setCounter(counter) {
|
520
|
+
callbacks.counter = counter;
|
521
|
+
return setters;
|
522
|
+
},
|
523
|
+
setFirstCursor(cursor) {
|
524
|
+
callbacks.firstCursor = cursor;
|
525
|
+
return setters;
|
526
|
+
},
|
527
|
+
setLastCursor(cursor) {
|
528
|
+
callbacks.lastCursor = cursor;
|
529
|
+
return setters;
|
530
|
+
},
|
531
|
+
authorize(predicate) {
|
532
|
+
callbacks.authorizePredicate = predicate;
|
533
|
+
return setters;
|
534
|
+
}
|
535
|
+
};
|
536
|
+
return setters;
|
537
|
+
}
|
538
|
+
setOutboxDispatcher(path, dispatcher) {
|
539
|
+
if (this.router.has("outbox")) throw new RouterError("Outbox dispatcher already set.");
|
540
|
+
const variables = this.router.add(path, "outbox");
|
541
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for outbox dispatcher must have one variable: {identifier}");
|
542
|
+
if (variables.has("handle")) getLogger([
|
543
|
+
"fedify",
|
544
|
+
"federation",
|
545
|
+
"outbox"
|
546
|
+
]).warn("The {{handle}} variable in the outbox dispatcher path is deprecated. Use {{identifier}} instead.");
|
547
|
+
const callbacks = { dispatcher };
|
548
|
+
this.outboxCallbacks = callbacks;
|
549
|
+
const setters = {
|
550
|
+
setCounter(counter) {
|
551
|
+
callbacks.counter = counter;
|
552
|
+
return setters;
|
553
|
+
},
|
554
|
+
setFirstCursor(cursor) {
|
555
|
+
callbacks.firstCursor = cursor;
|
556
|
+
return setters;
|
557
|
+
},
|
558
|
+
setLastCursor(cursor) {
|
559
|
+
callbacks.lastCursor = cursor;
|
560
|
+
return setters;
|
561
|
+
},
|
562
|
+
authorize(predicate) {
|
563
|
+
callbacks.authorizePredicate = predicate;
|
564
|
+
return setters;
|
565
|
+
}
|
566
|
+
};
|
567
|
+
return setters;
|
568
|
+
}
|
569
|
+
setFollowingDispatcher(path, dispatcher) {
|
570
|
+
if (this.router.has("following")) throw new RouterError("Following collection dispatcher already set.");
|
571
|
+
const variables = this.router.add(path, "following");
|
572
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for following collection dispatcher must have one variable: {identifier}");
|
573
|
+
if (variables.has("handle")) getLogger([
|
574
|
+
"fedify",
|
575
|
+
"federation",
|
576
|
+
"collection"
|
577
|
+
]).warn("The {{handle}} variable in the following collection dispatcher path is deprecated. Use {{identifier}} instead.");
|
578
|
+
const callbacks = { dispatcher };
|
579
|
+
this.followingCallbacks = callbacks;
|
580
|
+
const setters = {
|
581
|
+
setCounter(counter) {
|
582
|
+
callbacks.counter = counter;
|
583
|
+
return setters;
|
584
|
+
},
|
585
|
+
setFirstCursor(cursor) {
|
586
|
+
callbacks.firstCursor = cursor;
|
587
|
+
return setters;
|
588
|
+
},
|
589
|
+
setLastCursor(cursor) {
|
590
|
+
callbacks.lastCursor = cursor;
|
591
|
+
return setters;
|
592
|
+
},
|
593
|
+
authorize(predicate) {
|
594
|
+
callbacks.authorizePredicate = predicate;
|
595
|
+
return setters;
|
596
|
+
}
|
597
|
+
};
|
598
|
+
return setters;
|
599
|
+
}
|
600
|
+
setFollowersDispatcher(path, dispatcher) {
|
601
|
+
if (this.router.has("followers")) throw new RouterError("Followers collection dispatcher already set.");
|
602
|
+
const variables = this.router.add(path, "followers");
|
603
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for followers collection dispatcher must have one variable: {identifier}");
|
604
|
+
if (variables.has("handle")) getLogger([
|
605
|
+
"fedify",
|
606
|
+
"federation",
|
607
|
+
"collection"
|
608
|
+
]).warn("The {{handle}} variable in the followers collection dispatcher path is deprecated. Use {{identifier}} instead.");
|
609
|
+
const callbacks = { dispatcher };
|
610
|
+
this.followersCallbacks = callbacks;
|
611
|
+
const setters = {
|
612
|
+
setCounter(counter) {
|
613
|
+
callbacks.counter = counter;
|
614
|
+
return setters;
|
615
|
+
},
|
616
|
+
setFirstCursor(cursor) {
|
617
|
+
callbacks.firstCursor = cursor;
|
618
|
+
return setters;
|
619
|
+
},
|
620
|
+
setLastCursor(cursor) {
|
621
|
+
callbacks.lastCursor = cursor;
|
622
|
+
return setters;
|
623
|
+
},
|
624
|
+
authorize(predicate) {
|
625
|
+
callbacks.authorizePredicate = predicate;
|
626
|
+
return setters;
|
627
|
+
}
|
628
|
+
};
|
629
|
+
return setters;
|
630
|
+
}
|
631
|
+
setLikedDispatcher(path, dispatcher) {
|
632
|
+
if (this.router.has("liked")) throw new RouterError("Liked collection dispatcher already set.");
|
633
|
+
const variables = this.router.add(path, "liked");
|
634
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for liked collection dispatcher must have one variable: {identifier}");
|
635
|
+
if (variables.has("handle")) getLogger([
|
636
|
+
"fedify",
|
637
|
+
"federation",
|
638
|
+
"collection"
|
639
|
+
]).warn("The {{handle}} variable in the liked collection dispatcher path is deprecated. Use {{identifier}} instead.");
|
640
|
+
const callbacks = { dispatcher };
|
641
|
+
this.likedCallbacks = callbacks;
|
642
|
+
const setters = {
|
643
|
+
setCounter(counter) {
|
644
|
+
callbacks.counter = counter;
|
645
|
+
return setters;
|
646
|
+
},
|
647
|
+
setFirstCursor(cursor) {
|
648
|
+
callbacks.firstCursor = cursor;
|
649
|
+
return setters;
|
650
|
+
},
|
651
|
+
setLastCursor(cursor) {
|
652
|
+
callbacks.lastCursor = cursor;
|
653
|
+
return setters;
|
654
|
+
},
|
655
|
+
authorize(predicate) {
|
656
|
+
callbacks.authorizePredicate = predicate;
|
657
|
+
return setters;
|
658
|
+
}
|
659
|
+
};
|
660
|
+
return setters;
|
661
|
+
}
|
662
|
+
setFeaturedDispatcher(path, dispatcher) {
|
663
|
+
if (this.router.has("featured")) throw new RouterError("Featured collection dispatcher already set.");
|
664
|
+
const variables = this.router.add(path, "featured");
|
665
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for featured collection dispatcher must have one variable: {identifier}");
|
666
|
+
if (variables.has("handle")) getLogger([
|
667
|
+
"fedify",
|
668
|
+
"federation",
|
669
|
+
"collection"
|
670
|
+
]).warn("The {{handle}} variable in the featured collection dispatcher path is deprecated. Use {{identifier}} instead.");
|
671
|
+
const callbacks = { dispatcher };
|
672
|
+
this.featuredCallbacks = callbacks;
|
673
|
+
const setters = {
|
674
|
+
setCounter(counter) {
|
675
|
+
callbacks.counter = counter;
|
676
|
+
return setters;
|
677
|
+
},
|
678
|
+
setFirstCursor(cursor) {
|
679
|
+
callbacks.firstCursor = cursor;
|
680
|
+
return setters;
|
681
|
+
},
|
682
|
+
setLastCursor(cursor) {
|
683
|
+
callbacks.lastCursor = cursor;
|
684
|
+
return setters;
|
685
|
+
},
|
686
|
+
authorize(predicate) {
|
687
|
+
callbacks.authorizePredicate = predicate;
|
688
|
+
return setters;
|
689
|
+
}
|
690
|
+
};
|
691
|
+
return setters;
|
692
|
+
}
|
693
|
+
setFeaturedTagsDispatcher(path, dispatcher) {
|
694
|
+
if (this.router.has("featuredTags")) throw new RouterError("Featured tags collection dispatcher already set.");
|
695
|
+
const variables = this.router.add(path, "featuredTags");
|
696
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for featured tags collection dispatcher must have one variable: {identifier}");
|
697
|
+
if (variables.has("handle")) getLogger([
|
698
|
+
"fedify",
|
699
|
+
"federation",
|
700
|
+
"collection"
|
701
|
+
]).warn("The {{handle}} variable in the featured tags collection dispatcher path is deprecated. Use {{identifier}} instead.");
|
702
|
+
const callbacks = { dispatcher };
|
703
|
+
this.featuredTagsCallbacks = callbacks;
|
704
|
+
const setters = {
|
705
|
+
setCounter(counter) {
|
706
|
+
callbacks.counter = counter;
|
707
|
+
return setters;
|
708
|
+
},
|
709
|
+
setFirstCursor(cursor) {
|
710
|
+
callbacks.firstCursor = cursor;
|
711
|
+
return setters;
|
712
|
+
},
|
713
|
+
setLastCursor(cursor) {
|
714
|
+
callbacks.lastCursor = cursor;
|
715
|
+
return setters;
|
716
|
+
},
|
717
|
+
authorize(predicate) {
|
718
|
+
callbacks.authorizePredicate = predicate;
|
719
|
+
return setters;
|
720
|
+
}
|
721
|
+
};
|
722
|
+
return setters;
|
723
|
+
}
|
724
|
+
setInboxListeners(inboxPath, sharedInboxPath) {
|
725
|
+
if (this.inboxListeners != null) throw new RouterError("Inbox listeners already set.");
|
726
|
+
if (this.router.has("inbox")) {
|
727
|
+
if (this.inboxPath !== inboxPath) throw new RouterError("Inbox listener path must match inbox dispatcher path.");
|
728
|
+
} else {
|
729
|
+
const variables = this.router.add(inboxPath, "inbox");
|
730
|
+
if (variables.size !== 1 || !(variables.has("identifier") || variables.has("handle"))) throw new RouterError("Path for inbox must have one variable: {identifier}");
|
731
|
+
this.inboxPath = inboxPath;
|
732
|
+
if (variables.has("handle")) getLogger([
|
733
|
+
"fedify",
|
734
|
+
"federation",
|
735
|
+
"inbox"
|
736
|
+
]).warn("The {{handle}} variable in the inbox path is deprecated. Use {{identifier}} instead.");
|
737
|
+
}
|
738
|
+
if (sharedInboxPath != null) {
|
739
|
+
const siVars = this.router.add(sharedInboxPath, "sharedInbox");
|
740
|
+
if (siVars.size !== 0) throw new RouterError("Path for shared inbox must have no variables.");
|
741
|
+
}
|
742
|
+
const listeners = this.inboxListeners = new InboxListenerSet();
|
743
|
+
const setters = {
|
744
|
+
on(type, listener) {
|
745
|
+
listeners.add(type, listener);
|
746
|
+
return setters;
|
747
|
+
},
|
748
|
+
onError: (handler) => {
|
749
|
+
this.inboxErrorHandler = handler;
|
750
|
+
return setters;
|
751
|
+
},
|
752
|
+
setSharedKeyDispatcher: (dispatcher) => {
|
753
|
+
this.sharedInboxKeyDispatcher = dispatcher;
|
754
|
+
return setters;
|
755
|
+
}
|
756
|
+
};
|
757
|
+
return setters;
|
758
|
+
}
|
759
|
+
};
|
760
|
+
/**
|
761
|
+
* Creates a new {@link FederationBuilder} instance.
|
762
|
+
* @returns A new {@link FederationBuilder} instance.
|
763
|
+
* @since 1.6.0
|
764
|
+
*/
|
765
|
+
function createFederationBuilder() {
|
766
|
+
return new FederationBuilderImpl();
|
767
|
+
}
|
768
|
+
|
769
|
+
//#endregion
|
770
|
+
//#region federation/collection.ts
|
771
|
+
/**
|
772
|
+
* Calculates the [partial follower collection digest][1].
|
773
|
+
*
|
774
|
+
* [1]: https://w3id.org/fep/8fcf#partial-follower-collection-digest
|
775
|
+
* @param uris The URIs to calculate the digest. Duplicate URIs are ignored.
|
776
|
+
* @returns The digest.
|
777
|
+
*/
|
778
|
+
async function digest(uris) {
|
779
|
+
const processed = new Set();
|
780
|
+
const encoder = new TextEncoder();
|
781
|
+
const result = new Uint8Array(32);
|
782
|
+
for (const uri of uris) {
|
783
|
+
const u = uri instanceof URL ? uri.href : uri;
|
784
|
+
if (processed.has(u)) continue;
|
785
|
+
processed.add(u);
|
786
|
+
const encoded = encoder.encode(u);
|
787
|
+
const digest$1 = new Uint8Array(await crypto.subtle.digest("SHA-256", encoded));
|
788
|
+
for (let i = 0; i < 32; i++) result[i] ^= digest$1[i];
|
789
|
+
}
|
790
|
+
return result;
|
791
|
+
}
|
792
|
+
/**
|
793
|
+
* Builds [`Collection-Synchronization`][1] header content.
|
794
|
+
*
|
795
|
+
* [1]: https://w3id.org/fep/8fcf#the-collection-synchronization-http-header
|
796
|
+
*
|
797
|
+
* @param collectionId The sender's followers collection URI.
|
798
|
+
* @param actorIds The actor URIs to digest.
|
799
|
+
* @returns The header content.
|
800
|
+
*/
|
801
|
+
async function buildCollectionSynchronizationHeader(collectionId, actorIds) {
|
802
|
+
const [anyActorId] = actorIds;
|
803
|
+
const baseUrl = new URL(anyActorId);
|
804
|
+
const url = new URL(collectionId);
|
805
|
+
url.searchParams.set("base-url", `${baseUrl.origin}/`);
|
806
|
+
const hash = encodeHex(await digest(actorIds));
|
807
|
+
return `collectionId="${collectionId}", url="${url}", digest="${hash}"`;
|
808
|
+
}
|
809
|
+
|
810
|
+
//#endregion
|
811
|
+
//#region federation/keycache.ts
|
812
|
+
var KvKeyCache = class {
|
813
|
+
kv;
|
814
|
+
prefix;
|
815
|
+
options;
|
816
|
+
nullKeys;
|
817
|
+
constructor(kv, prefix, options = {}) {
|
818
|
+
this.kv = kv;
|
819
|
+
this.prefix = prefix;
|
820
|
+
this.nullKeys = new Set();
|
821
|
+
this.options = options;
|
822
|
+
}
|
823
|
+
async get(keyId) {
|
824
|
+
if (this.nullKeys.has(keyId.href)) return null;
|
825
|
+
const serialized = await this.kv.get([...this.prefix, keyId.href]);
|
826
|
+
if (serialized == null) return void 0;
|
827
|
+
try {
|
828
|
+
return await CryptographicKey.fromJsonLd(serialized, this.options);
|
829
|
+
} catch {
|
830
|
+
try {
|
831
|
+
return await Multikey.fromJsonLd(serialized, this.options);
|
832
|
+
} catch {
|
833
|
+
await this.kv.delete([...this.prefix, keyId.href]);
|
834
|
+
return void 0;
|
835
|
+
}
|
836
|
+
}
|
837
|
+
}
|
838
|
+
async set(keyId, key) {
|
839
|
+
if (key == null) {
|
840
|
+
this.nullKeys.add(keyId.href);
|
841
|
+
await this.kv.delete([...this.prefix, keyId.href]);
|
842
|
+
return;
|
843
|
+
}
|
844
|
+
this.nullKeys.delete(keyId.href);
|
845
|
+
const serialized = await key.toJsonLd(this.options);
|
846
|
+
await this.kv.set([...this.prefix, keyId.href], serialized);
|
847
|
+
}
|
848
|
+
};
|
849
|
+
|
850
|
+
//#endregion
|
851
|
+
//#region federation/negotiation.ts
|
852
|
+
function compareSpecs(a, b) {
|
853
|
+
return b.q - a.q || (b.s ?? 0) - (a.s ?? 0) || (a.o ?? 0) - (b.o ?? 0) || a.i - b.i || 0;
|
854
|
+
}
|
855
|
+
function isQuality(spec) {
|
856
|
+
return spec.q > 0;
|
857
|
+
}
|
858
|
+
const simpleMediaTypeRegExp = /^\s*([^\s\/;]+)\/([^;\s]+)\s*(?:;(.*))?$/;
|
859
|
+
function splitKeyValuePair(str) {
|
860
|
+
const [key, value] = str.split("=");
|
861
|
+
return [key.toLowerCase(), value];
|
862
|
+
}
|
863
|
+
function parseMediaType(str, i) {
|
864
|
+
const match = simpleMediaTypeRegExp.exec(str);
|
865
|
+
if (!match) return;
|
866
|
+
const [, type, subtype, parameters] = match;
|
867
|
+
if (!type || !subtype) return;
|
868
|
+
const params = Object.create(null);
|
869
|
+
let q = 1;
|
870
|
+
if (parameters) {
|
871
|
+
const kvps = parameters.split(";").map((p) => p.trim()).map(splitKeyValuePair);
|
872
|
+
for (const [key, val] of kvps) {
|
873
|
+
const value = val && val[0] === `"` && val[val.length - 1] === `"` ? val.slice(1, val.length - 1) : val;
|
874
|
+
if (key === "q" && value) {
|
875
|
+
q = parseFloat(value);
|
876
|
+
break;
|
877
|
+
}
|
878
|
+
params[key] = value;
|
879
|
+
}
|
880
|
+
}
|
881
|
+
return {
|
882
|
+
type,
|
883
|
+
subtype,
|
884
|
+
params,
|
885
|
+
i,
|
886
|
+
o: void 0,
|
887
|
+
q,
|
888
|
+
s: void 0
|
889
|
+
};
|
890
|
+
}
|
891
|
+
function parseAccept(accept) {
|
892
|
+
const accepts = accept.split(",").map((p) => p.trim());
|
893
|
+
const mediaTypes = [];
|
894
|
+
for (const [index, accept$1] of accepts.entries()) {
|
895
|
+
const mediaType = parseMediaType(accept$1.trim(), index);
|
896
|
+
if (mediaType) mediaTypes.push(mediaType);
|
897
|
+
}
|
898
|
+
return mediaTypes;
|
899
|
+
}
|
900
|
+
function getFullType(spec) {
|
901
|
+
return `${spec.type}/${spec.subtype}`;
|
902
|
+
}
|
903
|
+
function preferredMediaTypes(accept) {
|
904
|
+
const accepts = parseAccept(accept === void 0 ? "*/*" : accept ?? "");
|
905
|
+
return accepts.filter(isQuality).sort(compareSpecs).map(getFullType);
|
906
|
+
}
|
907
|
+
|
908
|
+
//#endregion
|
909
|
+
//#region federation/handler.ts
|
910
|
+
function acceptsJsonLd(request) {
|
911
|
+
const accept = request.headers.get("Accept");
|
912
|
+
const types = accept ? preferredMediaTypes(accept) : ["*/*"];
|
913
|
+
if (types == null) return true;
|
914
|
+
if (types[0] === "text/html" || types[0] === "application/xhtml+xml") return false;
|
915
|
+
return types.includes("application/activity+json") || types.includes("application/ld+json") || types.includes("application/json");
|
916
|
+
}
|
917
|
+
async function handleActor(request, { identifier, context: context$1, actorDispatcher, authorizePredicate, onNotFound, onNotAcceptable, onUnauthorized }) {
|
918
|
+
const logger$1 = getLogger([
|
919
|
+
"fedify",
|
920
|
+
"federation",
|
921
|
+
"actor"
|
922
|
+
]);
|
923
|
+
if (actorDispatcher == null) {
|
924
|
+
logger$1.debug("Actor dispatcher is not set.", { identifier });
|
925
|
+
return await onNotFound(request);
|
926
|
+
}
|
927
|
+
const actor = await actorDispatcher(context$1, identifier);
|
928
|
+
if (actor == null) {
|
929
|
+
logger$1.debug("Actor {identifier} not found.", { identifier });
|
930
|
+
return await onNotFound(request);
|
931
|
+
}
|
932
|
+
if (!acceptsJsonLd(request)) return await onNotAcceptable(request);
|
933
|
+
if (authorizePredicate != null) {
|
934
|
+
let key = await context$1.getSignedKey();
|
935
|
+
key = key?.clone({}, { $warning: {
|
936
|
+
category: [
|
937
|
+
"fedify",
|
938
|
+
"federation",
|
939
|
+
"actor"
|
940
|
+
],
|
941
|
+
message: "The third parameter of AuthorizePredicate is deprecated in favor of RequestContext.getSignedKey() method. The third parameter will be removed in a future release."
|
942
|
+
} }) ?? null;
|
943
|
+
let keyOwner = await context$1.getSignedKeyOwner();
|
944
|
+
keyOwner = keyOwner?.clone({}, { $warning: {
|
945
|
+
category: [
|
946
|
+
"fedify",
|
947
|
+
"federation",
|
948
|
+
"actor"
|
949
|
+
],
|
950
|
+
message: "The fourth parameter of AuthorizePredicate is deprecated in favor of RequestContext.getSignedKeyOwner() method. The fourth parameter will be removed in a future release."
|
951
|
+
} }) ?? null;
|
952
|
+
if (!await authorizePredicate(context$1, identifier, key, keyOwner)) return await onUnauthorized(request);
|
953
|
+
}
|
954
|
+
const jsonLd = await actor.toJsonLd(context$1);
|
955
|
+
return new Response(JSON.stringify(jsonLd), { headers: {
|
956
|
+
"Content-Type": "application/activity+json",
|
957
|
+
Vary: "Accept"
|
958
|
+
} });
|
959
|
+
}
|
960
|
+
async function handleObject(request, { values, context: context$1, objectDispatcher, authorizePredicate, onNotFound, onNotAcceptable, onUnauthorized }) {
|
961
|
+
if (objectDispatcher == null) return await onNotFound(request);
|
962
|
+
const object = await objectDispatcher(context$1, values);
|
963
|
+
if (object == null) return await onNotFound(request);
|
964
|
+
if (!acceptsJsonLd(request)) return await onNotAcceptable(request);
|
965
|
+
if (authorizePredicate != null) {
|
966
|
+
let key = await context$1.getSignedKey();
|
967
|
+
key = key?.clone({}, { $warning: {
|
968
|
+
category: [
|
969
|
+
"fedify",
|
970
|
+
"federation",
|
971
|
+
"object"
|
972
|
+
],
|
973
|
+
message: "The third parameter of ObjectAuthorizePredicate is deprecated in favor of RequestContext.getSignedKey() method. The third parameter will be removed in a future release."
|
974
|
+
} }) ?? null;
|
975
|
+
let keyOwner = await context$1.getSignedKeyOwner();
|
976
|
+
keyOwner = keyOwner?.clone({}, { $warning: {
|
977
|
+
category: [
|
978
|
+
"fedify",
|
979
|
+
"federation",
|
980
|
+
"object"
|
981
|
+
],
|
982
|
+
message: "The fourth parameter of ObjectAuthorizePredicate is deprecated in favor of RequestContext.getSignedKeyOwner() method. The fourth parameter will be removed in a future release."
|
983
|
+
} }) ?? null;
|
984
|
+
if (!await authorizePredicate(context$1, values, key, keyOwner)) return await onUnauthorized(request);
|
985
|
+
}
|
986
|
+
const jsonLd = await object.toJsonLd(context$1);
|
987
|
+
return new Response(JSON.stringify(jsonLd), { headers: {
|
988
|
+
"Content-Type": "application/activity+json",
|
989
|
+
Vary: "Accept"
|
990
|
+
} });
|
991
|
+
}
|
992
|
+
async function handleCollection(request, { name, identifier, uriGetter, filter, filterPredicate, context: context$1, collectionCallbacks, tracerProvider, onUnauthorized, onNotFound, onNotAcceptable }) {
|
993
|
+
const spanName = name.trim().replace(/\s+/g, "_");
|
994
|
+
tracerProvider = tracerProvider ?? trace.getTracerProvider();
|
995
|
+
const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
|
996
|
+
const url = new URL(request.url);
|
997
|
+
const cursor = url.searchParams.get("cursor");
|
998
|
+
if (collectionCallbacks == null) return await onNotFound(request);
|
999
|
+
let collection;
|
1000
|
+
const baseUri = uriGetter(identifier);
|
1001
|
+
if (cursor == null) {
|
1002
|
+
const firstCursor = await collectionCallbacks.firstCursor?.(context$1, identifier);
|
1003
|
+
const totalItems = filter == null ? await collectionCallbacks.counter?.(context$1, identifier) : void 0;
|
1004
|
+
if (firstCursor == null) {
|
1005
|
+
const itemsOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection ${spanName}`, {
|
1006
|
+
kind: SpanKind.SERVER,
|
1007
|
+
attributes: {
|
1008
|
+
"activitypub.collection.id": baseUri.href,
|
1009
|
+
"activitypub.collection.type": OrderedCollection.typeId.href
|
1010
|
+
}
|
1011
|
+
}, async (span) => {
|
1012
|
+
if (totalItems != null) span.setAttribute("activitypub.collection.total_items", Number(totalItems));
|
1013
|
+
try {
|
1014
|
+
const page = await collectionCallbacks.dispatcher(context$1, identifier, null, filter);
|
1015
|
+
if (page == null) {
|
1016
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
1017
|
+
return await onNotFound(request);
|
1018
|
+
}
|
1019
|
+
const { items } = page;
|
1020
|
+
span.setAttribute("fedify.collection.items", items.length);
|
1021
|
+
return items;
|
1022
|
+
} catch (e) {
|
1023
|
+
span.setStatus({
|
1024
|
+
code: SpanStatusCode.ERROR,
|
1025
|
+
message: String(e)
|
1026
|
+
});
|
1027
|
+
throw e;
|
1028
|
+
} finally {
|
1029
|
+
span.end();
|
1030
|
+
}
|
1031
|
+
});
|
1032
|
+
if (itemsOrResponse instanceof Response) return itemsOrResponse;
|
1033
|
+
collection = new OrderedCollection({
|
1034
|
+
id: baseUri,
|
1035
|
+
totalItems: totalItems == null ? null : Number(totalItems),
|
1036
|
+
items: filterCollectionItems(itemsOrResponse, name, filterPredicate)
|
1037
|
+
});
|
1038
|
+
} else {
|
1039
|
+
const lastCursor = await collectionCallbacks.lastCursor?.(context$1, identifier);
|
1040
|
+
const first = new URL(context$1.url);
|
1041
|
+
first.searchParams.set("cursor", firstCursor);
|
1042
|
+
let last = null;
|
1043
|
+
if (lastCursor != null) {
|
1044
|
+
last = new URL(context$1.url);
|
1045
|
+
last.searchParams.set("cursor", lastCursor);
|
1046
|
+
}
|
1047
|
+
collection = new OrderedCollection({
|
1048
|
+
id: baseUri,
|
1049
|
+
totalItems: totalItems == null ? null : Number(totalItems),
|
1050
|
+
first,
|
1051
|
+
last
|
1052
|
+
});
|
1053
|
+
}
|
1054
|
+
} else {
|
1055
|
+
const uri = new URL(baseUri);
|
1056
|
+
uri.searchParams.set("cursor", cursor);
|
1057
|
+
const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name}`, {
|
1058
|
+
kind: SpanKind.SERVER,
|
1059
|
+
attributes: {
|
1060
|
+
"activitypub.collection.id": uri.href,
|
1061
|
+
"activitypub.collection.type": OrderedCollectionPage.typeId.href,
|
1062
|
+
"fedify.collection.cursor": cursor
|
1063
|
+
}
|
1064
|
+
}, async (span) => {
|
1065
|
+
try {
|
1066
|
+
const page = await collectionCallbacks.dispatcher(context$1, identifier, cursor, filter);
|
1067
|
+
if (page == null) {
|
1068
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
1069
|
+
return await onNotFound(request);
|
1070
|
+
}
|
1071
|
+
span.setAttribute("fedify.collection.items", page.items.length);
|
1072
|
+
return page;
|
1073
|
+
} catch (e) {
|
1074
|
+
span.setStatus({
|
1075
|
+
code: SpanStatusCode.ERROR,
|
1076
|
+
message: String(e)
|
1077
|
+
});
|
1078
|
+
throw e;
|
1079
|
+
} finally {
|
1080
|
+
span.end();
|
1081
|
+
}
|
1082
|
+
});
|
1083
|
+
if (pageOrResponse instanceof Response) return pageOrResponse;
|
1084
|
+
const { items, prevCursor, nextCursor } = pageOrResponse;
|
1085
|
+
let prev = null;
|
1086
|
+
if (prevCursor != null) {
|
1087
|
+
prev = new URL(context$1.url);
|
1088
|
+
prev.searchParams.set("cursor", prevCursor);
|
1089
|
+
}
|
1090
|
+
let next = null;
|
1091
|
+
if (nextCursor != null) {
|
1092
|
+
next = new URL(context$1.url);
|
1093
|
+
next.searchParams.set("cursor", nextCursor);
|
1094
|
+
}
|
1095
|
+
const partOf = new URL(context$1.url);
|
1096
|
+
partOf.searchParams.delete("cursor");
|
1097
|
+
collection = new OrderedCollectionPage({
|
1098
|
+
id: uri,
|
1099
|
+
prev,
|
1100
|
+
next,
|
1101
|
+
items: filterCollectionItems(items, name, filterPredicate),
|
1102
|
+
partOf
|
1103
|
+
});
|
1104
|
+
}
|
1105
|
+
if (!acceptsJsonLd(request)) return await onNotAcceptable(request);
|
1106
|
+
if (collectionCallbacks.authorizePredicate != null) {
|
1107
|
+
let key = await context$1.getSignedKey();
|
1108
|
+
key = key?.clone({}, { $warning: {
|
1109
|
+
category: [
|
1110
|
+
"fedify",
|
1111
|
+
"federation",
|
1112
|
+
"collection"
|
1113
|
+
],
|
1114
|
+
message: "The third parameter of AuthorizePredicate is deprecated in favor of RequestContext.getSignedKey() method. The third parameter will be removed in a future release."
|
1115
|
+
} }) ?? null;
|
1116
|
+
let keyOwner = await context$1.getSignedKeyOwner();
|
1117
|
+
keyOwner = keyOwner?.clone({}, { $warning: {
|
1118
|
+
category: [
|
1119
|
+
"fedify",
|
1120
|
+
"federation",
|
1121
|
+
"collection"
|
1122
|
+
],
|
1123
|
+
message: "The fourth parameter of AuthorizePredicate is deprecated in favor of RequestContext.getSignedKeyOwner() method. The fourth parameter will be removed in a future release."
|
1124
|
+
} }) ?? null;
|
1125
|
+
if (!await collectionCallbacks.authorizePredicate(context$1, identifier, key, keyOwner)) return await onUnauthorized(request);
|
1126
|
+
}
|
1127
|
+
const jsonLd = await collection.toJsonLd(context$1);
|
1128
|
+
return new Response(JSON.stringify(jsonLd), { headers: {
|
1129
|
+
"Content-Type": "application/activity+json",
|
1130
|
+
Vary: "Accept"
|
1131
|
+
} });
|
1132
|
+
}
|
1133
|
+
function filterCollectionItems(items, collectionName, filterPredicate) {
|
1134
|
+
const result = [];
|
1135
|
+
let logged = false;
|
1136
|
+
for (const item of items) {
|
1137
|
+
let mappedItem;
|
1138
|
+
if (item instanceof Object$1 || item instanceof Link || item instanceof URL) mappedItem = item;
|
1139
|
+
else if (item.id == null) continue;
|
1140
|
+
else mappedItem = item.id;
|
1141
|
+
if (filterPredicate != null && !filterPredicate(item)) {
|
1142
|
+
if (!logged) {
|
1143
|
+
getLogger([
|
1144
|
+
"fedify",
|
1145
|
+
"federation",
|
1146
|
+
"collection"
|
1147
|
+
]).warn(`The ${collectionName} collection apparently does not implement filtering. This may result in a large response payload. Please consider implementing filtering for the collection. See also: https://fedify.dev/manual/collections#filtering-by-server`);
|
1148
|
+
logged = true;
|
1149
|
+
}
|
1150
|
+
continue;
|
1151
|
+
}
|
1152
|
+
result.push(mappedItem);
|
1153
|
+
}
|
1154
|
+
return result;
|
1155
|
+
}
|
1156
|
+
async function handleInbox(request, options) {
|
1157
|
+
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
1158
|
+
const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
|
1159
|
+
return await tracer.startActiveSpan("activitypub.inbox", {
|
1160
|
+
kind: options.queue == null ? SpanKind.SERVER : SpanKind.PRODUCER,
|
1161
|
+
attributes: { "activitypub.shared_inbox": options.recipient == null }
|
1162
|
+
}, async (span) => {
|
1163
|
+
if (options.recipient != null) span.setAttribute("fedify.inbox.recipient", options.recipient);
|
1164
|
+
try {
|
1165
|
+
return await handleInboxInternal(request, options, span);
|
1166
|
+
} catch (e) {
|
1167
|
+
span.setStatus({
|
1168
|
+
code: SpanStatusCode.ERROR,
|
1169
|
+
message: String(e)
|
1170
|
+
});
|
1171
|
+
throw e;
|
1172
|
+
} finally {
|
1173
|
+
span.end();
|
1174
|
+
}
|
1175
|
+
});
|
1176
|
+
}
|
1177
|
+
async function handleInboxInternal(request, { recipient, context: ctx, inboxContextFactory, kv, kvPrefixes, queue, actorDispatcher, inboxListeners, inboxErrorHandler, onNotFound, signatureTimeWindow, skipSignatureVerification, tracerProvider }, span) {
|
1178
|
+
const logger$1 = getLogger([
|
1179
|
+
"fedify",
|
1180
|
+
"federation",
|
1181
|
+
"inbox"
|
1182
|
+
]);
|
1183
|
+
if (actorDispatcher == null) {
|
1184
|
+
logger$1.error("Actor dispatcher is not set.", { recipient });
|
1185
|
+
span.setStatus({
|
1186
|
+
code: SpanStatusCode.ERROR,
|
1187
|
+
message: "Actor dispatcher is not set."
|
1188
|
+
});
|
1189
|
+
return await onNotFound(request);
|
1190
|
+
} else if (recipient != null) {
|
1191
|
+
const actor = await actorDispatcher(ctx, recipient);
|
1192
|
+
if (actor == null) {
|
1193
|
+
logger$1.error("Actor {recipient} not found.", { recipient });
|
1194
|
+
span.setStatus({
|
1195
|
+
code: SpanStatusCode.ERROR,
|
1196
|
+
message: `Actor ${recipient} not found.`
|
1197
|
+
});
|
1198
|
+
return await onNotFound(request);
|
1199
|
+
}
|
1200
|
+
}
|
1201
|
+
if (request.bodyUsed) {
|
1202
|
+
logger$1.error("Request body has already been read.", { recipient });
|
1203
|
+
span.setStatus({
|
1204
|
+
code: SpanStatusCode.ERROR,
|
1205
|
+
message: "Request body has already been read."
|
1206
|
+
});
|
1207
|
+
return new Response("Internal server error.", {
|
1208
|
+
status: 500,
|
1209
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1210
|
+
});
|
1211
|
+
} else if (request.body?.locked) {
|
1212
|
+
logger$1.error("Request body is locked.", { recipient });
|
1213
|
+
span.setStatus({
|
1214
|
+
code: SpanStatusCode.ERROR,
|
1215
|
+
message: "Request body is locked."
|
1216
|
+
});
|
1217
|
+
return new Response("Internal server error.", {
|
1218
|
+
status: 500,
|
1219
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1220
|
+
});
|
1221
|
+
}
|
1222
|
+
let json;
|
1223
|
+
try {
|
1224
|
+
json = await request.clone().json();
|
1225
|
+
} catch (error) {
|
1226
|
+
logger$1.error("Failed to parse JSON:\n{error}", {
|
1227
|
+
recipient,
|
1228
|
+
error
|
1229
|
+
});
|
1230
|
+
try {
|
1231
|
+
await inboxErrorHandler?.(ctx, error);
|
1232
|
+
} catch (error$1) {
|
1233
|
+
logger$1.error("An unexpected error occurred in inbox error handler:\n{error}", {
|
1234
|
+
error: error$1,
|
1235
|
+
activity: json,
|
1236
|
+
recipient
|
1237
|
+
});
|
1238
|
+
}
|
1239
|
+
span.setStatus({
|
1240
|
+
code: SpanStatusCode.ERROR,
|
1241
|
+
message: `Failed to parse JSON:\n${error}`
|
1242
|
+
});
|
1243
|
+
return new Response("Invalid JSON.", {
|
1244
|
+
status: 400,
|
1245
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1246
|
+
});
|
1247
|
+
}
|
1248
|
+
const keyCache = new KvKeyCache(kv, kvPrefixes.publicKey, ctx);
|
1249
|
+
let ldSigVerified;
|
1250
|
+
try {
|
1251
|
+
ldSigVerified = await verifyJsonLd(json, {
|
1252
|
+
contextLoader: ctx.contextLoader,
|
1253
|
+
documentLoader: ctx.documentLoader,
|
1254
|
+
keyCache,
|
1255
|
+
tracerProvider
|
1256
|
+
});
|
1257
|
+
} catch (error) {
|
1258
|
+
if (error instanceof Error && error.name === "jsonld.SyntaxError") {
|
1259
|
+
logger$1.error("Failed to parse JSON-LD:\n{error}", {
|
1260
|
+
recipient,
|
1261
|
+
error
|
1262
|
+
});
|
1263
|
+
return new Response("Invalid JSON-LD.", {
|
1264
|
+
status: 400,
|
1265
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1266
|
+
});
|
1267
|
+
}
|
1268
|
+
ldSigVerified = false;
|
1269
|
+
}
|
1270
|
+
const jsonWithoutSig = detachSignature(json);
|
1271
|
+
let activity = null;
|
1272
|
+
if (ldSigVerified) {
|
1273
|
+
logger$1.debug("Linked Data Signatures are verified.", {
|
1274
|
+
recipient,
|
1275
|
+
json
|
1276
|
+
});
|
1277
|
+
activity = await Activity.fromJsonLd(jsonWithoutSig, ctx);
|
1278
|
+
} else {
|
1279
|
+
logger$1.debug("Linked Data Signatures are not verified.", {
|
1280
|
+
recipient,
|
1281
|
+
json
|
1282
|
+
});
|
1283
|
+
try {
|
1284
|
+
activity = await verifyObject(Activity, jsonWithoutSig, {
|
1285
|
+
contextLoader: ctx.contextLoader,
|
1286
|
+
documentLoader: ctx.documentLoader,
|
1287
|
+
keyCache,
|
1288
|
+
tracerProvider
|
1289
|
+
});
|
1290
|
+
} catch (error) {
|
1291
|
+
logger$1.error("Failed to parse activity:\n{error}", {
|
1292
|
+
recipient,
|
1293
|
+
activity: json,
|
1294
|
+
error
|
1295
|
+
});
|
1296
|
+
try {
|
1297
|
+
await inboxErrorHandler?.(ctx, error);
|
1298
|
+
} catch (error$1) {
|
1299
|
+
logger$1.error("An unexpected error occurred in inbox error handler:\n{error}", {
|
1300
|
+
error: error$1,
|
1301
|
+
activity: json,
|
1302
|
+
recipient
|
1303
|
+
});
|
1304
|
+
}
|
1305
|
+
span.setStatus({
|
1306
|
+
code: SpanStatusCode.ERROR,
|
1307
|
+
message: `Failed to parse activity:\n${error}`
|
1308
|
+
});
|
1309
|
+
return new Response("Invalid activity.", {
|
1310
|
+
status: 400,
|
1311
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1312
|
+
});
|
1313
|
+
}
|
1314
|
+
if (activity == null) logger$1.debug("Object Integrity Proofs are not verified.", {
|
1315
|
+
recipient,
|
1316
|
+
activity: json
|
1317
|
+
});
|
1318
|
+
else logger$1.debug("Object Integrity Proofs are verified.", {
|
1319
|
+
recipient,
|
1320
|
+
activity: json
|
1321
|
+
});
|
1322
|
+
}
|
1323
|
+
let httpSigKey = null;
|
1324
|
+
if (activity == null) {
|
1325
|
+
if (!skipSignatureVerification) {
|
1326
|
+
const key = await verifyRequest(request, {
|
1327
|
+
contextLoader: ctx.contextLoader,
|
1328
|
+
documentLoader: ctx.documentLoader,
|
1329
|
+
timeWindow: signatureTimeWindow,
|
1330
|
+
keyCache,
|
1331
|
+
tracerProvider
|
1332
|
+
});
|
1333
|
+
if (key == null) {
|
1334
|
+
logger$1.error("Failed to verify the request's HTTP Signatures.", { recipient });
|
1335
|
+
span.setStatus({
|
1336
|
+
code: SpanStatusCode.ERROR,
|
1337
|
+
message: `Failed to verify the request's HTTP Signatures.`
|
1338
|
+
});
|
1339
|
+
const response = new Response("Failed to verify the request signature.", {
|
1340
|
+
status: 401,
|
1341
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1342
|
+
});
|
1343
|
+
return response;
|
1344
|
+
} else logger$1.debug("HTTP Signatures are verified.", { recipient });
|
1345
|
+
httpSigKey = key;
|
1346
|
+
}
|
1347
|
+
activity = await Activity.fromJsonLd(jsonWithoutSig, ctx);
|
1348
|
+
}
|
1349
|
+
if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
|
1350
|
+
span.setAttribute("activitypub.activity.type", getTypeId(activity).href);
|
1351
|
+
const routeResult = await routeActivity({
|
1352
|
+
context: ctx,
|
1353
|
+
json,
|
1354
|
+
activity,
|
1355
|
+
recipient,
|
1356
|
+
inboxListeners,
|
1357
|
+
inboxContextFactory,
|
1358
|
+
inboxErrorHandler,
|
1359
|
+
kv,
|
1360
|
+
kvPrefixes,
|
1361
|
+
queue,
|
1362
|
+
span,
|
1363
|
+
tracerProvider
|
1364
|
+
});
|
1365
|
+
if (httpSigKey != null && !await doesActorOwnKey(activity, httpSigKey, ctx)) {
|
1366
|
+
logger$1.error("The signer ({keyId}) and the actor ({actorId}) do not match.", {
|
1367
|
+
activity: json,
|
1368
|
+
recipient,
|
1369
|
+
keyId: httpSigKey.id?.href,
|
1370
|
+
actorId: activity.actorId?.href
|
1371
|
+
});
|
1372
|
+
span.setStatus({
|
1373
|
+
code: SpanStatusCode.ERROR,
|
1374
|
+
message: `The signer (${httpSigKey.id?.href}) and the actor (${activity.actorId?.href}) do not match.`
|
1375
|
+
});
|
1376
|
+
return new Response("The signer and the actor do not match.", {
|
1377
|
+
status: 401,
|
1378
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1379
|
+
});
|
1380
|
+
}
|
1381
|
+
if (routeResult === "alreadyProcessed") return new Response(`Activity <${activity.id}> has already been processed.`, {
|
1382
|
+
status: 202,
|
1383
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1384
|
+
});
|
1385
|
+
else if (routeResult === "missingActor") return new Response("Missing actor.", {
|
1386
|
+
status: 400,
|
1387
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1388
|
+
});
|
1389
|
+
else if (routeResult === "enqueued") return new Response("Activity is enqueued.", {
|
1390
|
+
status: 202,
|
1391
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1392
|
+
});
|
1393
|
+
else if (routeResult === "unsupportedActivity") return new Response("", {
|
1394
|
+
status: 202,
|
1395
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1396
|
+
});
|
1397
|
+
else if (routeResult === "error") return new Response("Internal server error.", {
|
1398
|
+
status: 500,
|
1399
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1400
|
+
});
|
1401
|
+
else return new Response("", {
|
1402
|
+
status: 202,
|
1403
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
1404
|
+
});
|
1405
|
+
}
|
1406
|
+
/**
|
1407
|
+
* Responds with the given object in JSON-LD format.
|
1408
|
+
*
|
1409
|
+
* @param object The object to respond with.
|
1410
|
+
* @param options Options.
|
1411
|
+
* @since 0.3.0
|
1412
|
+
*/
|
1413
|
+
async function respondWithObject(object, options) {
|
1414
|
+
const jsonLd = await object.toJsonLd(options);
|
1415
|
+
return new Response(JSON.stringify(jsonLd), { headers: { "Content-Type": "application/activity+json" } });
|
1416
|
+
}
|
1417
|
+
/**
|
1418
|
+
* Responds with the given object in JSON-LD format if the request accepts
|
1419
|
+
* JSON-LD.
|
1420
|
+
*
|
1421
|
+
* @param object The object to respond with.
|
1422
|
+
* @param request The request to check for JSON-LD acceptability.
|
1423
|
+
* @param options Options.
|
1424
|
+
* @since 0.3.0
|
1425
|
+
*/
|
1426
|
+
async function respondWithObjectIfAcceptable(object, request, options) {
|
1427
|
+
if (!acceptsJsonLd(request)) return null;
|
1428
|
+
const response = await respondWithObject(object, options);
|
1429
|
+
response.headers.set("Vary", "Accept");
|
1430
|
+
return response;
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
//#endregion
|
1434
|
+
//#region nodeinfo/handler.ts
|
1435
|
+
/**
|
1436
|
+
* Handles a NodeInfo request. You would not typically call this function
|
1437
|
+
* directly, but instead use {@link Federation.handle} method.
|
1438
|
+
* @param request The NodeInfo request to handle.
|
1439
|
+
* @param parameters The parameters for handling the request.
|
1440
|
+
* @returns The response to the request.
|
1441
|
+
*/
|
1442
|
+
async function handleNodeInfo(_request, { context: context$1, nodeInfoDispatcher }) {
|
1443
|
+
const promise = nodeInfoDispatcher(context$1);
|
1444
|
+
const nodeInfo = promise instanceof Promise ? await promise : promise;
|
1445
|
+
const json = nodeInfoToJson(nodeInfo);
|
1446
|
+
return new Response(JSON.stringify(json), { headers: { "Content-Type": "application/json; profile=\"http://nodeinfo.diaspora.software/ns/schema/2.1#\"" } });
|
1447
|
+
}
|
1448
|
+
/**
|
1449
|
+
* Handles a request to `/.well-known/nodeinfo`. You would not typically call
|
1450
|
+
* this function directly, but instead use {@link Federation.handle} method.
|
1451
|
+
* @param request The request to handle.
|
1452
|
+
* @param context The request context.
|
1453
|
+
* @returns The response to the request.
|
1454
|
+
*/
|
1455
|
+
function handleNodeInfoJrd(_request, context$1) {
|
1456
|
+
const links = [];
|
1457
|
+
try {
|
1458
|
+
links.push({
|
1459
|
+
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
|
1460
|
+
href: context$1.getNodeInfoUri().href,
|
1461
|
+
type: "application/json; profile=\"http://nodeinfo.diaspora.software/ns/schema/2.1#\""
|
1462
|
+
});
|
1463
|
+
} catch (e) {
|
1464
|
+
if (!(e instanceof RouterError)) throw e;
|
1465
|
+
}
|
1466
|
+
const jrd = { links };
|
1467
|
+
const response = new Response(JSON.stringify(jrd), { headers: { "Content-Type": "application/jrd+json" } });
|
1468
|
+
return Promise.resolve(response);
|
1469
|
+
}
|
1470
|
+
|
1471
|
+
//#endregion
|
1472
|
+
//#region webfinger/handler.ts
|
1473
|
+
const logger = getLogger([
|
1474
|
+
"fedify",
|
1475
|
+
"webfinger",
|
1476
|
+
"server"
|
1477
|
+
]);
|
1478
|
+
/**
|
1479
|
+
* Handles a WebFinger request. You would not typically call this function
|
1480
|
+
* directly, but instead use {@link Federation.fetch} method.
|
1481
|
+
* @param request The WebFinger request to handle.
|
1482
|
+
* @param parameters The parameters for handling the request.
|
1483
|
+
* @returns The response to the request.
|
1484
|
+
*/
|
1485
|
+
async function handleWebFinger(request, options) {
|
1486
|
+
if (options.tracer == null) return await handleWebFingerInternal(request, options);
|
1487
|
+
return await options.tracer.startActiveSpan("webfinger.handle", { kind: SpanKind.SERVER }, async (span) => {
|
1488
|
+
try {
|
1489
|
+
const response = await handleWebFingerInternal(request, options);
|
1490
|
+
span.setStatus({ code: response.ok ? SpanStatusCode.UNSET : SpanStatusCode.ERROR });
|
1491
|
+
return response;
|
1492
|
+
} catch (error) {
|
1493
|
+
span.setStatus({
|
1494
|
+
code: SpanStatusCode.ERROR,
|
1495
|
+
message: String(error)
|
1496
|
+
});
|
1497
|
+
throw error;
|
1498
|
+
} finally {
|
1499
|
+
span.end();
|
1500
|
+
}
|
1501
|
+
});
|
1502
|
+
}
|
1503
|
+
async function handleWebFingerInternal(request, { context: context$1, host, actorDispatcher, actorHandleMapper, actorAliasMapper, onNotFound, span }) {
|
1504
|
+
if (actorDispatcher == null) return await onNotFound(request);
|
1505
|
+
const resource = context$1.url.searchParams.get("resource");
|
1506
|
+
if (resource == null) return new Response("Missing resource parameter.", { status: 400 });
|
1507
|
+
span?.setAttribute("webfinger.resource", resource);
|
1508
|
+
let resourceUrl;
|
1509
|
+
try {
|
1510
|
+
resourceUrl = new URL(resource);
|
1511
|
+
} catch (e) {
|
1512
|
+
if (e instanceof TypeError) return new Response("Invalid resource URL.", { status: 400 });
|
1513
|
+
throw e;
|
1514
|
+
}
|
1515
|
+
span?.setAttribute("webfinger.resource.scheme", resourceUrl.protocol.replace(/:$/, ""));
|
1516
|
+
if (actorDispatcher == null) {
|
1517
|
+
logger.error("Actor dispatcher is not set.");
|
1518
|
+
return await onNotFound(request);
|
1519
|
+
}
|
1520
|
+
async function mapUsernameToIdentifier(username) {
|
1521
|
+
if (actorHandleMapper == null) {
|
1522
|
+
logger.error("No actor handle mapper is set; use the WebFinger username {username} as the actor's internal identifier.", { username });
|
1523
|
+
return username;
|
1524
|
+
}
|
1525
|
+
const identifier$1 = await actorHandleMapper(context$1, username);
|
1526
|
+
if (identifier$1 == null) {
|
1527
|
+
logger.error("Actor {username} not found.", { username });
|
1528
|
+
return null;
|
1529
|
+
}
|
1530
|
+
return identifier$1;
|
1531
|
+
}
|
1532
|
+
let identifier = null;
|
1533
|
+
const uriParsed = context$1.parseUri(resourceUrl);
|
1534
|
+
if (uriParsed?.type != "actor") {
|
1535
|
+
const match = /^acct:([^@]+)@([^@]+)$/.exec(resource);
|
1536
|
+
if (match == null) {
|
1537
|
+
const result = await actorAliasMapper?.(context$1, resourceUrl);
|
1538
|
+
if (result == null) return await onNotFound(request);
|
1539
|
+
if ("identifier" in result) identifier = result.identifier;
|
1540
|
+
else identifier = await mapUsernameToIdentifier(result.username);
|
1541
|
+
} else {
|
1542
|
+
const portMatch = /:\d+$/.exec(match[2]);
|
1543
|
+
const normalizedHost = portMatch == null ? domainToASCII(match[2].toLowerCase()) : domainToASCII(match[2].substring(0, portMatch.index).toLowerCase()) + portMatch[0];
|
1544
|
+
if (normalizedHost != context$1.url.host && normalizedHost != host) return await onNotFound(request);
|
1545
|
+
else {
|
1546
|
+
identifier = await mapUsernameToIdentifier(match[1]);
|
1547
|
+
resourceUrl = new URL(`acct:${match[1]}@${normalizedHost}`);
|
1548
|
+
}
|
1549
|
+
}
|
1550
|
+
} else identifier = uriParsed.identifier;
|
1551
|
+
if (identifier == null) return await onNotFound(request);
|
1552
|
+
const actor = await actorDispatcher(context$1, identifier);
|
1553
|
+
if (actor == null) {
|
1554
|
+
logger.error("Actor {identifier} not found.", { identifier });
|
1555
|
+
return await onNotFound(request);
|
1556
|
+
}
|
1557
|
+
const links = [{
|
1558
|
+
rel: "self",
|
1559
|
+
href: context$1.getActorUri(identifier).href,
|
1560
|
+
type: "application/activity+json"
|
1561
|
+
}];
|
1562
|
+
for (const url of actor.urls) if (url instanceof Link && url.href != null) links.push({
|
1563
|
+
rel: url.rel ?? "http://webfinger.net/rel/profile-page",
|
1564
|
+
href: url.href.href,
|
1565
|
+
type: url.mediaType == null ? void 0 : url.mediaType
|
1566
|
+
});
|
1567
|
+
else if (url instanceof URL) links.push({
|
1568
|
+
rel: "http://webfinger.net/rel/profile-page",
|
1569
|
+
href: url.href
|
1570
|
+
});
|
1571
|
+
for await (const image of actor.getIcons()) {
|
1572
|
+
if (image.url?.href == null) continue;
|
1573
|
+
const link = {
|
1574
|
+
rel: "http://webfinger.net/rel/avatar",
|
1575
|
+
href: image.url.href.toString()
|
1576
|
+
};
|
1577
|
+
if (image.mediaType != null) link.type = image.mediaType;
|
1578
|
+
links.push(link);
|
1579
|
+
}
|
1580
|
+
const aliases = [];
|
1581
|
+
if (resourceUrl.protocol != "acct:" && actor.preferredUsername != null) {
|
1582
|
+
aliases.push(`acct:${actor.preferredUsername}@${host ?? context$1.url.host}`);
|
1583
|
+
if (host != null && host !== context$1.url.host) aliases.push(`acct:${actor.preferredUsername}@${context$1.url.host}`);
|
1584
|
+
}
|
1585
|
+
if (resourceUrl.href !== context$1.getActorUri(identifier).href) aliases.push(context$1.getActorUri(identifier).href);
|
1586
|
+
if (resourceUrl.protocol === "acct:" && host != null && host !== context$1.url.host && !resourceUrl.href.endsWith(`@${host}`)) {
|
1587
|
+
const username = resourceUrl.href.replace(/^acct:/, "").replace(/@.*$/, "");
|
1588
|
+
aliases.push(`acct:${username}@${host}`);
|
1589
|
+
}
|
1590
|
+
const jrd = {
|
1591
|
+
subject: resourceUrl.href,
|
1592
|
+
aliases,
|
1593
|
+
links
|
1594
|
+
};
|
1595
|
+
return new Response(JSON.stringify(jrd), { headers: {
|
1596
|
+
"Content-Type": "application/jrd+json",
|
1597
|
+
"Access-Control-Allow-Origin": "*"
|
1598
|
+
} });
|
1599
|
+
}
|
1600
|
+
|
1601
|
+
//#endregion
|
1602
|
+
//#region federation/retry.ts
|
1603
|
+
/**
|
1604
|
+
* Creates an exponential backoff retry policy. The delay between retries
|
1605
|
+
* starts at the `initialDelay` and is multiplied by the `factor` for each
|
1606
|
+
* subsequent retry, up to the `maxDelay`. The policy will give up after
|
1607
|
+
* `maxAttempts` attempts. The actual delay is randomized to avoid
|
1608
|
+
* synchronization (jitter).
|
1609
|
+
* @param options The options for the policy.
|
1610
|
+
* @returns The retry policy.
|
1611
|
+
* @since 0.12.0
|
1612
|
+
*/
|
1613
|
+
function createExponentialBackoffPolicy(options = {}) {
|
1614
|
+
const initialDelay = Temporal.Duration.from(options.initialDelay ?? { seconds: 1 });
|
1615
|
+
const maxDelay = Temporal.Duration.from(options.maxDelay ?? { hours: 12 });
|
1616
|
+
const maxAttempts = options.maxAttempts ?? 10;
|
1617
|
+
const factor = options.factor ?? 2;
|
1618
|
+
const jitter = options.jitter ?? true;
|
1619
|
+
return ({ attempts }) => {
|
1620
|
+
if (attempts >= maxAttempts) return null;
|
1621
|
+
let milliseconds = initialDelay.total("millisecond");
|
1622
|
+
milliseconds *= factor ** attempts;
|
1623
|
+
if (jitter) {
|
1624
|
+
milliseconds *= 1 + Math.random();
|
1625
|
+
milliseconds = Math.round(milliseconds);
|
1626
|
+
}
|
1627
|
+
const delay$1 = Temporal.Duration.from({ milliseconds });
|
1628
|
+
return Temporal.Duration.compare(delay$1, maxDelay) > 0 ? maxDelay : delay$1;
|
1629
|
+
};
|
1630
|
+
}
|
1631
|
+
|
1632
|
+
//#endregion
|
1633
|
+
//#region federation/send.ts
|
1634
|
+
/**
|
1635
|
+
* Extracts the inbox URLs from recipients.
|
1636
|
+
* @param parameters The parameters to extract the inboxes.
|
1637
|
+
* See also {@link ExtractInboxesParameters}.
|
1638
|
+
* @returns The inboxes as a map of inbox URL to actor URIs.
|
1639
|
+
*/
|
1640
|
+
function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
|
1641
|
+
const inboxes = {};
|
1642
|
+
for (const recipient of recipients) {
|
1643
|
+
let inbox;
|
1644
|
+
let sharedInbox = false;
|
1645
|
+
if (preferSharedInbox && recipient.endpoints?.sharedInbox != null) {
|
1646
|
+
inbox = recipient.endpoints.sharedInbox;
|
1647
|
+
sharedInbox = true;
|
1648
|
+
} else inbox = recipient.inboxId;
|
1649
|
+
if (inbox != null && recipient.id != null) {
|
1650
|
+
if (excludeBaseUris != null && excludeBaseUris.some((u) => u.origin === inbox?.origin)) continue;
|
1651
|
+
inboxes[inbox.href] ??= {
|
1652
|
+
actorIds: new Set(),
|
1653
|
+
sharedInbox
|
1654
|
+
};
|
1655
|
+
inboxes[inbox.href].actorIds.add(recipient.id.href);
|
1656
|
+
}
|
1657
|
+
}
|
1658
|
+
return inboxes;
|
1659
|
+
}
|
1660
|
+
/**
|
1661
|
+
* Sends an {@link Activity} to an inbox.
|
1662
|
+
*
|
1663
|
+
* @param parameters The parameters for sending the activity.
|
1664
|
+
* See also {@link SendActivityParameters}.
|
1665
|
+
* @throws {Error} If the activity fails to send.
|
1666
|
+
*/
|
1667
|
+
function sendActivity(options) {
|
1668
|
+
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
1669
|
+
const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
|
1670
|
+
return tracer.startActiveSpan("activitypub.send_activity", {
|
1671
|
+
kind: SpanKind.CLIENT,
|
1672
|
+
attributes: { "activitypub.shared_inbox": options.sharedInbox ?? false }
|
1673
|
+
}, async (span) => {
|
1674
|
+
if (options.activityId != null) span.setAttribute("activitypub.activity.id", options.activityId);
|
1675
|
+
if (options.activityType != null) span.setAttribute("activitypub.activity.type", options.activityType);
|
1676
|
+
try {
|
1677
|
+
await sendActivityInternal({
|
1678
|
+
...options,
|
1679
|
+
tracerProvider
|
1680
|
+
});
|
1681
|
+
} catch (e) {
|
1682
|
+
span.setStatus({
|
1683
|
+
code: SpanStatusCode.ERROR,
|
1684
|
+
message: String(e)
|
1685
|
+
});
|
1686
|
+
throw e;
|
1687
|
+
} finally {
|
1688
|
+
span.end();
|
1689
|
+
}
|
1690
|
+
});
|
1691
|
+
}
|
1692
|
+
async function sendActivityInternal({ activity, activityId, keys, inbox, headers, specDeterminer, tracerProvider }) {
|
1693
|
+
const logger$1 = getLogger([
|
1694
|
+
"fedify",
|
1695
|
+
"federation",
|
1696
|
+
"outbox"
|
1697
|
+
]);
|
1698
|
+
headers = new Headers(headers);
|
1699
|
+
headers.set("Content-Type", "application/activity+json");
|
1700
|
+
const request = new Request(inbox, {
|
1701
|
+
method: "POST",
|
1702
|
+
headers,
|
1703
|
+
body: JSON.stringify(activity)
|
1704
|
+
});
|
1705
|
+
let rsaKey = null;
|
1706
|
+
for (const key of keys) if (key.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
1707
|
+
rsaKey = key;
|
1708
|
+
break;
|
1709
|
+
}
|
1710
|
+
if (rsaKey == null) logger$1.warn("No supported key found to sign the request to {inbox}. The request will be sent without a signature. In order to sign the request, at least one RSASSA-PKCS1-v1_5 key must be provided.", {
|
1711
|
+
inbox: inbox.href,
|
1712
|
+
keys: keys.map((pair) => ({
|
1713
|
+
keyId: pair.keyId.href,
|
1714
|
+
privateKey: pair.privateKey
|
1715
|
+
}))
|
1716
|
+
});
|
1717
|
+
let response;
|
1718
|
+
try {
|
1719
|
+
response = rsaKey == null ? await fetch(request) : await doubleKnock(request, rsaKey, {
|
1720
|
+
tracerProvider,
|
1721
|
+
specDeterminer
|
1722
|
+
});
|
1723
|
+
} catch (error) {
|
1724
|
+
logger$1.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
1725
|
+
activityId,
|
1726
|
+
inbox: inbox.href,
|
1727
|
+
error
|
1728
|
+
});
|
1729
|
+
throw error;
|
1730
|
+
}
|
1731
|
+
if (!response.ok) {
|
1732
|
+
let error;
|
1733
|
+
try {
|
1734
|
+
error = await response.text();
|
1735
|
+
} catch (_) {
|
1736
|
+
error = "";
|
1737
|
+
}
|
1738
|
+
logger$1.error("Failed to send activity {activityId} to {inbox} ({status} {statusText}):\n{error}", {
|
1739
|
+
activityId,
|
1740
|
+
inbox: inbox.href,
|
1741
|
+
status: response.status,
|
1742
|
+
statusText: response.statusText,
|
1743
|
+
error
|
1744
|
+
});
|
1745
|
+
throw new Error(`Failed to send activity ${activityId} to ${inbox.href} (${response.status} ${response.statusText}):\n${error}`);
|
1746
|
+
}
|
1747
|
+
}
|
1748
|
+
|
1749
|
+
//#endregion
|
1750
|
+
//#region federation/middleware.ts
|
1751
|
+
/**
|
1752
|
+
* Create a new {@link Federation} instance.
|
1753
|
+
* @param parameters Parameters for initializing the instance.
|
1754
|
+
* @returns A new {@link Federation} instance.
|
1755
|
+
* @since 0.10.0
|
1756
|
+
*/
|
1757
|
+
function createFederation(options) {
|
1758
|
+
return new FederationImpl(options);
|
1759
|
+
}
|
1760
|
+
var FederationImpl = class extends FederationBuilderImpl {
|
1761
|
+
kv;
|
1762
|
+
kvPrefixes;
|
1763
|
+
inboxQueue;
|
1764
|
+
outboxQueue;
|
1765
|
+
fanoutQueue;
|
1766
|
+
inboxQueueStarted;
|
1767
|
+
outboxQueueStarted;
|
1768
|
+
fanoutQueueStarted;
|
1769
|
+
manuallyStartQueue;
|
1770
|
+
origin;
|
1771
|
+
documentLoaderFactory;
|
1772
|
+
contextLoaderFactory;
|
1773
|
+
authenticatedDocumentLoaderFactory;
|
1774
|
+
allowPrivateAddress;
|
1775
|
+
userAgent;
|
1776
|
+
onOutboxError;
|
1777
|
+
signatureTimeWindow;
|
1778
|
+
skipSignatureVerification;
|
1779
|
+
outboxRetryPolicy;
|
1780
|
+
inboxRetryPolicy;
|
1781
|
+
activityTransformers;
|
1782
|
+
tracerProvider;
|
1783
|
+
constructor(options) {
|
1784
|
+
super();
|
1785
|
+
const logger$1 = getLogger(["fedify", "federation"]);
|
1786
|
+
this.kv = options.kv;
|
1787
|
+
this.kvPrefixes = {
|
1788
|
+
activityIdempotence: ["_fedify", "activityIdempotence"],
|
1789
|
+
remoteDocument: ["_fedify", "remoteDocument"],
|
1790
|
+
publicKey: ["_fedify", "publicKey"],
|
1791
|
+
httpMessageSignaturesSpec: ["_fedify", "httpMessageSignaturesSpec"],
|
1792
|
+
...options.kvPrefixes ?? {}
|
1793
|
+
};
|
1794
|
+
if (options.queue == null) {
|
1795
|
+
this.inboxQueue = void 0;
|
1796
|
+
this.outboxQueue = void 0;
|
1797
|
+
this.fanoutQueue = void 0;
|
1798
|
+
} else if ("enqueue" in options.queue && "listen" in options.queue) {
|
1799
|
+
this.inboxQueue = options.queue;
|
1800
|
+
this.outboxQueue = options.queue;
|
1801
|
+
this.fanoutQueue = options.queue;
|
1802
|
+
} else {
|
1803
|
+
this.inboxQueue = options.queue.inbox;
|
1804
|
+
this.outboxQueue = options.queue.outbox;
|
1805
|
+
this.fanoutQueue = options.queue.fanout;
|
1806
|
+
}
|
1807
|
+
this.inboxQueueStarted = false;
|
1808
|
+
this.outboxQueueStarted = false;
|
1809
|
+
this.fanoutQueueStarted = false;
|
1810
|
+
this.manuallyStartQueue = options.manuallyStartQueue ?? false;
|
1811
|
+
if (options.origin != null) if (typeof options.origin === "string") {
|
1812
|
+
if (!URL.canParse(options.origin) || !options.origin.match(/^https?:\/\//)) throw new TypeError(`Invalid origin: ${JSON.stringify(options.origin)}`);
|
1813
|
+
const origin = new URL(options.origin);
|
1814
|
+
if (!origin.pathname.match(/^\/*$/) || origin.search !== "" || origin.hash !== "") throw new TypeError(`Invalid origin: ${JSON.stringify(options.origin)}`);
|
1815
|
+
this.origin = {
|
1816
|
+
handleHost: origin.host,
|
1817
|
+
webOrigin: origin.origin
|
1818
|
+
};
|
1819
|
+
} else {
|
1820
|
+
const { handleHost, webOrigin } = options.origin;
|
1821
|
+
if (!URL.canParse(`https://${handleHost}/`) || handleHost.includes("/")) throw new TypeError(`Invalid origin.handleHost: ${JSON.stringify(handleHost)}`);
|
1822
|
+
if (!URL.canParse(webOrigin) || !webOrigin.match(/^https?:\/\//)) throw new TypeError(`Invalid origin.webOrigin: ${JSON.stringify(webOrigin)}`);
|
1823
|
+
const webOriginUrl = new URL(webOrigin);
|
1824
|
+
if (!webOriginUrl.pathname.match(/^\/*$/) || webOriginUrl.search !== "" || webOriginUrl.hash !== "") throw new TypeError(`Invalid origin.webOrigin: ${JSON.stringify(webOrigin)}`);
|
1825
|
+
this.origin = {
|
1826
|
+
handleHost: new URL(`https://${handleHost}/`).host,
|
1827
|
+
webOrigin: webOriginUrl.origin
|
1828
|
+
};
|
1829
|
+
}
|
1830
|
+
this.router.trailingSlashInsensitive = options.trailingSlashInsensitive ?? false;
|
1831
|
+
this._initializeRouter();
|
1832
|
+
if (options.allowPrivateAddress || options.userAgent != null) {
|
1833
|
+
if (options.documentLoader != null) throw new TypeError("Cannot set documentLoader with allowPrivateAddress or userAgent options.");
|
1834
|
+
else if (options.contextLoader != null) throw new TypeError("Cannot set contextLoader with allowPrivateAddress or userAgent options.");
|
1835
|
+
else if (options.authenticatedDocumentLoaderFactory != null) throw new TypeError("Cannot set authenticatedDocumentLoaderFactory with allowPrivateAddress or userAgent options.");
|
1836
|
+
}
|
1837
|
+
const { allowPrivateAddress, userAgent } = options;
|
1838
|
+
this.allowPrivateAddress = allowPrivateAddress ?? false;
|
1839
|
+
if (options.documentLoader != null) {
|
1840
|
+
if (options.documentLoaderFactory != null) throw new TypeError("Cannot set both documentLoader and documentLoaderFactory options at a time; use documentLoaderFactory only.");
|
1841
|
+
this.documentLoaderFactory = () => options.documentLoader;
|
1842
|
+
logger$1.warn("The documentLoader option is deprecated; use documentLoaderFactory option instead.");
|
1843
|
+
} else this.documentLoaderFactory = options.documentLoaderFactory ?? ((opts) => {
|
1844
|
+
return kvCache({
|
1845
|
+
loader: getDocumentLoader({
|
1846
|
+
allowPrivateAddress: opts?.allowPrivateAddress ?? allowPrivateAddress,
|
1847
|
+
userAgent: opts?.userAgent ?? userAgent
|
1848
|
+
}),
|
1849
|
+
kv: options.kv,
|
1850
|
+
prefix: this.kvPrefixes.remoteDocument
|
1851
|
+
});
|
1852
|
+
});
|
1853
|
+
if (options.contextLoader != null) {
|
1854
|
+
if (options.contextLoaderFactory != null) throw new TypeError("Cannot set both contextLoader and contextLoaderFactory options at a time; use contextLoaderFactory only.");
|
1855
|
+
this.contextLoaderFactory = () => options.contextLoader;
|
1856
|
+
logger$1.warn("The contextLoader option is deprecated; use contextLoaderFactory option instead.");
|
1857
|
+
} else this.contextLoaderFactory = options.contextLoaderFactory ?? this.documentLoaderFactory;
|
1858
|
+
this.authenticatedDocumentLoaderFactory = options.authenticatedDocumentLoaderFactory ?? ((identity) => getAuthenticatedDocumentLoader(identity, {
|
1859
|
+
allowPrivateAddress,
|
1860
|
+
userAgent,
|
1861
|
+
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec),
|
1862
|
+
tracerProvider: this.tracerProvider
|
1863
|
+
}));
|
1864
|
+
this.userAgent = userAgent;
|
1865
|
+
this.onOutboxError = options.onOutboxError;
|
1866
|
+
this.signatureTimeWindow = options.signatureTimeWindow ?? { hours: 1 };
|
1867
|
+
this.skipSignatureVerification = options.skipSignatureVerification ?? false;
|
1868
|
+
this.outboxRetryPolicy = options.outboxRetryPolicy ?? createExponentialBackoffPolicy();
|
1869
|
+
this.inboxRetryPolicy = options.inboxRetryPolicy ?? createExponentialBackoffPolicy();
|
1870
|
+
this.activityTransformers = options.activityTransformers ?? getDefaultActivityTransformers();
|
1871
|
+
this.tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
1872
|
+
}
|
1873
|
+
_initializeRouter() {
|
1874
|
+
this.router.add("/.well-known/webfinger", "webfinger");
|
1875
|
+
this.router.add("/.well-known/nodeinfo", "nodeInfoJrd");
|
1876
|
+
}
|
1877
|
+
_getTracer() {
|
1878
|
+
return this.tracerProvider.getTracer(deno_default.name, deno_default.version);
|
1879
|
+
}
|
1880
|
+
async _startQueueInternal(ctxData, signal, queue) {
|
1881
|
+
if (this.inboxQueue == null && this.outboxQueue == null) return;
|
1882
|
+
const logger$1 = getLogger([
|
1883
|
+
"fedify",
|
1884
|
+
"federation",
|
1885
|
+
"queue"
|
1886
|
+
]);
|
1887
|
+
const promises = [];
|
1888
|
+
if (this.inboxQueue != null && (queue == null || queue === "inbox") && !this.inboxQueueStarted) {
|
1889
|
+
logger$1.debug("Starting an inbox task worker.");
|
1890
|
+
this.inboxQueueStarted = true;
|
1891
|
+
promises.push(this.inboxQueue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal }));
|
1892
|
+
}
|
1893
|
+
if (this.outboxQueue != null && this.outboxQueue !== this.inboxQueue && (queue == null || queue === "outbox") && !this.outboxQueueStarted) {
|
1894
|
+
logger$1.debug("Starting an outbox task worker.");
|
1895
|
+
this.outboxQueueStarted = true;
|
1896
|
+
promises.push(this.outboxQueue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal }));
|
1897
|
+
}
|
1898
|
+
if (this.fanoutQueue != null && this.fanoutQueue !== this.inboxQueue && this.fanoutQueue !== this.outboxQueue && (queue == null || queue === "fanout") && !this.fanoutQueueStarted) {
|
1899
|
+
logger$1.debug("Starting a fanout task worker.");
|
1900
|
+
this.fanoutQueueStarted = true;
|
1901
|
+
promises.push(this.fanoutQueue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal }));
|
1902
|
+
}
|
1903
|
+
await Promise.all(promises);
|
1904
|
+
}
|
1905
|
+
processQueuedTask(contextData, message) {
|
1906
|
+
const tracer = this._getTracer();
|
1907
|
+
const extractedContext = propagation.extract(context.active(), message.traceContext);
|
1908
|
+
return withContext({ messageId: message.id }, async () => {
|
1909
|
+
if (message.type === "fanout") await tracer.startActiveSpan("activitypub.fanout", {
|
1910
|
+
kind: SpanKind.CONSUMER,
|
1911
|
+
attributes: { "activitypub.activity.type": message.activityType }
|
1912
|
+
}, extractedContext, async (span) => {
|
1913
|
+
if (message.activityId != null) span.setAttribute("activitypub.activity.id", message.activityId);
|
1914
|
+
try {
|
1915
|
+
await this.#listenFanoutMessage(contextData, message);
|
1916
|
+
} catch (e) {
|
1917
|
+
span.setStatus({
|
1918
|
+
code: SpanStatusCode.ERROR,
|
1919
|
+
message: String(e)
|
1920
|
+
});
|
1921
|
+
throw e;
|
1922
|
+
} finally {
|
1923
|
+
span.end();
|
1924
|
+
}
|
1925
|
+
});
|
1926
|
+
else if (message.type === "outbox") await tracer.startActiveSpan("activitypub.outbox", {
|
1927
|
+
kind: SpanKind.CONSUMER,
|
1928
|
+
attributes: {
|
1929
|
+
"activitypub.activity.type": message.activityType,
|
1930
|
+
"activitypub.activity.retries": message.attempt
|
1931
|
+
}
|
1932
|
+
}, extractedContext, async (span) => {
|
1933
|
+
if (message.activityId != null) span.setAttribute("activitypub.activity.id", message.activityId);
|
1934
|
+
try {
|
1935
|
+
await this.#listenOutboxMessage(contextData, message, span);
|
1936
|
+
} catch (e) {
|
1937
|
+
span.setStatus({
|
1938
|
+
code: SpanStatusCode.ERROR,
|
1939
|
+
message: String(e)
|
1940
|
+
});
|
1941
|
+
throw e;
|
1942
|
+
} finally {
|
1943
|
+
span.end();
|
1944
|
+
}
|
1945
|
+
});
|
1946
|
+
else if (message.type === "inbox") await tracer.startActiveSpan("activitypub.inbox", {
|
1947
|
+
kind: SpanKind.CONSUMER,
|
1948
|
+
attributes: { "activitypub.shared_inbox": message.identifier == null }
|
1949
|
+
}, extractedContext, async (span) => {
|
1950
|
+
try {
|
1951
|
+
await this.#listenInboxMessage(contextData, message, span);
|
1952
|
+
} catch (e) {
|
1953
|
+
span.setStatus({
|
1954
|
+
code: SpanStatusCode.ERROR,
|
1955
|
+
message: String(e)
|
1956
|
+
});
|
1957
|
+
throw e;
|
1958
|
+
} finally {
|
1959
|
+
span.end();
|
1960
|
+
}
|
1961
|
+
});
|
1962
|
+
});
|
1963
|
+
}
|
1964
|
+
async #listenFanoutMessage(data, message) {
|
1965
|
+
const logger$1 = getLogger([
|
1966
|
+
"fedify",
|
1967
|
+
"federation",
|
1968
|
+
"fanout"
|
1969
|
+
]);
|
1970
|
+
logger$1.debug("Fanning out activity {activityId} to {inboxes} inbox(es)...", {
|
1971
|
+
activityId: message.activityId,
|
1972
|
+
inboxes: globalThis.Object.keys(message.inboxes).length
|
1973
|
+
});
|
1974
|
+
const keys = await Promise.all(message.keys.map(async ({ keyId, privateKey }) => ({
|
1975
|
+
keyId: new URL(keyId),
|
1976
|
+
privateKey: await importJwk(privateKey, "private")
|
1977
|
+
})));
|
1978
|
+
const activity = await Activity.fromJsonLd(message.activity, {
|
1979
|
+
contextLoader: this.contextLoaderFactory({
|
1980
|
+
allowPrivateAddress: this.allowPrivateAddress,
|
1981
|
+
userAgent: this.userAgent
|
1982
|
+
}),
|
1983
|
+
documentLoader: this.documentLoaderFactory({
|
1984
|
+
allowPrivateAddress: this.allowPrivateAddress,
|
1985
|
+
userAgent: this.userAgent
|
1986
|
+
}),
|
1987
|
+
tracerProvider: this.tracerProvider
|
1988
|
+
});
|
1989
|
+
const context$1 = this.#createContext(new URL(message.baseUrl), data, { documentLoader: this.documentLoaderFactory({
|
1990
|
+
allowPrivateAddress: this.allowPrivateAddress,
|
1991
|
+
userAgent: this.userAgent
|
1992
|
+
}) });
|
1993
|
+
await this.sendActivity(keys, message.inboxes, activity, {
|
1994
|
+
collectionSync: message.collectionSync,
|
1995
|
+
context: context$1
|
1996
|
+
});
|
1997
|
+
}
|
1998
|
+
async #listenOutboxMessage(_, message, span) {
|
1999
|
+
const logger$1 = getLogger([
|
2000
|
+
"fedify",
|
2001
|
+
"federation",
|
2002
|
+
"outbox"
|
2003
|
+
]);
|
2004
|
+
const logData = {
|
2005
|
+
keyIds: message.keys.map((pair) => pair.keyId),
|
2006
|
+
inbox: message.inbox,
|
2007
|
+
activity: message.activity,
|
2008
|
+
activityId: message.activityId,
|
2009
|
+
attempt: message.attempt,
|
2010
|
+
headers: message.headers
|
2011
|
+
};
|
2012
|
+
const keys = [];
|
2013
|
+
let rsaKeyPair = null;
|
2014
|
+
for (const { keyId, privateKey } of message.keys) {
|
2015
|
+
const pair = {
|
2016
|
+
keyId: new URL(keyId),
|
2017
|
+
privateKey: await importJwk(privateKey, "private")
|
2018
|
+
};
|
2019
|
+
if (rsaKeyPair == null && pair.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") rsaKeyPair = pair;
|
2020
|
+
keys.push(pair);
|
2021
|
+
}
|
2022
|
+
try {
|
2023
|
+
await sendActivity({
|
2024
|
+
keys,
|
2025
|
+
activity: message.activity,
|
2026
|
+
activityId: message.activityId,
|
2027
|
+
activityType: message.activityType,
|
2028
|
+
inbox: new URL(message.inbox),
|
2029
|
+
sharedInbox: message.sharedInbox,
|
2030
|
+
headers: new Headers(message.headers),
|
2031
|
+
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec),
|
2032
|
+
tracerProvider: this.tracerProvider
|
2033
|
+
});
|
2034
|
+
} catch (error) {
|
2035
|
+
span.setStatus({
|
2036
|
+
code: SpanStatusCode.ERROR,
|
2037
|
+
message: String(error)
|
2038
|
+
});
|
2039
|
+
const loaderOptions = this.#getLoaderOptions(message.baseUrl);
|
2040
|
+
const activity = await Activity.fromJsonLd(message.activity, {
|
2041
|
+
contextLoader: this.contextLoaderFactory(loaderOptions),
|
2042
|
+
documentLoader: rsaKeyPair == null ? this.documentLoaderFactory(loaderOptions) : this.authenticatedDocumentLoaderFactory(rsaKeyPair, loaderOptions),
|
2043
|
+
tracerProvider: this.tracerProvider
|
2044
|
+
});
|
2045
|
+
try {
|
2046
|
+
this.onOutboxError?.(error, activity);
|
2047
|
+
} catch (error$1) {
|
2048
|
+
logger$1.error("An unexpected error occurred in onError handler:\n{error}", {
|
2049
|
+
...logData,
|
2050
|
+
error: error$1
|
2051
|
+
});
|
2052
|
+
}
|
2053
|
+
const delay$1 = this.outboxRetryPolicy({
|
2054
|
+
elapsedTime: Temporal.Instant.from(message.started).until(Temporal.Now.instant()),
|
2055
|
+
attempts: message.attempt
|
2056
|
+
});
|
2057
|
+
if (delay$1 != null) {
|
2058
|
+
logger$1.error("Failed to send activity {activityId} to {inbox} (attempt #{attempt}); retry...:\n{error}", {
|
2059
|
+
...logData,
|
2060
|
+
error
|
2061
|
+
});
|
2062
|
+
await this.outboxQueue?.enqueue({
|
2063
|
+
...message,
|
2064
|
+
attempt: message.attempt + 1
|
2065
|
+
}, { delay: Temporal.Duration.compare(delay$1, { seconds: 0 }) < 0 ? Temporal.Duration.from({ seconds: 0 }) : delay$1 });
|
2066
|
+
} else logger$1.error("Failed to send activity {activityId} to {inbox} after {attempt} attempts; giving up:\n{error}", {
|
2067
|
+
...logData,
|
2068
|
+
error
|
2069
|
+
});
|
2070
|
+
return;
|
2071
|
+
}
|
2072
|
+
logger$1.info("Successfully sent activity {activityId} to {inbox}.", { ...logData });
|
2073
|
+
}
|
2074
|
+
async #listenInboxMessage(ctxData, message, span) {
|
2075
|
+
const logger$1 = getLogger([
|
2076
|
+
"fedify",
|
2077
|
+
"federation",
|
2078
|
+
"inbox"
|
2079
|
+
]);
|
2080
|
+
const baseUrl = new URL(message.baseUrl);
|
2081
|
+
let context$1 = this.#createContext(baseUrl, ctxData);
|
2082
|
+
if (message.identifier != null) context$1 = this.#createContext(baseUrl, ctxData, { documentLoader: await context$1.getDocumentLoader({ identifier: message.identifier }) });
|
2083
|
+
else if (this.sharedInboxKeyDispatcher != null) {
|
2084
|
+
const identity = await this.sharedInboxKeyDispatcher(context$1);
|
2085
|
+
if (identity != null) context$1 = this.#createContext(baseUrl, ctxData, { documentLoader: "identifier" in identity || "username" in identity || "handle" in identity ? await context$1.getDocumentLoader(identity) : context$1.getDocumentLoader(identity) });
|
2086
|
+
}
|
2087
|
+
const activity = await Activity.fromJsonLd(message.activity, context$1);
|
2088
|
+
span.setAttribute("activitypub.activity.type", getTypeId(activity).href);
|
2089
|
+
if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
|
2090
|
+
const cacheKey = activity.id == null ? null : [
|
2091
|
+
...this.kvPrefixes.activityIdempotence,
|
2092
|
+
context$1.origin,
|
2093
|
+
activity.id.href
|
2094
|
+
];
|
2095
|
+
if (cacheKey != null) {
|
2096
|
+
const cached = await this.kv.get(cacheKey);
|
2097
|
+
if (cached === true) {
|
2098
|
+
logger$1.debug("Activity {activityId} has already been processed.", {
|
2099
|
+
activityId: activity.id?.href,
|
2100
|
+
activity: message.activity,
|
2101
|
+
recipient: message.identifier
|
2102
|
+
});
|
2103
|
+
return;
|
2104
|
+
}
|
2105
|
+
}
|
2106
|
+
await this._getTracer().startActiveSpan("activitypub.dispatch_inbox_listener", { kind: SpanKind.INTERNAL }, async (span$1) => {
|
2107
|
+
const dispatched = this.inboxListeners?.dispatchWithClass(activity);
|
2108
|
+
if (dispatched == null) {
|
2109
|
+
logger$1.error("Unsupported activity type:\n{activity}", {
|
2110
|
+
activityId: activity.id?.href,
|
2111
|
+
activity: message.activity,
|
2112
|
+
recipient: message.identifier,
|
2113
|
+
trial: message.attempt
|
2114
|
+
});
|
2115
|
+
span$1.setStatus({
|
2116
|
+
code: SpanStatusCode.ERROR,
|
2117
|
+
message: `Unsupported activity type: ${getTypeId(activity).href}`
|
2118
|
+
});
|
2119
|
+
span$1.end();
|
2120
|
+
return;
|
2121
|
+
}
|
2122
|
+
const { class: cls, listener } = dispatched;
|
2123
|
+
span$1.updateName(`activitypub.dispatch_inbox_listener ${cls.name}`);
|
2124
|
+
try {
|
2125
|
+
await listener(context$1.toInboxContext(message.identifier, message.activity, activity.id?.href, getTypeId(activity).href), activity);
|
2126
|
+
} catch (error) {
|
2127
|
+
try {
|
2128
|
+
await this.inboxErrorHandler?.(context$1, error);
|
2129
|
+
} catch (error$1) {
|
2130
|
+
logger$1.error("An unexpected error occurred in inbox error handler:\n{error}", {
|
2131
|
+
error: error$1,
|
2132
|
+
trial: message.attempt,
|
2133
|
+
activityId: activity.id?.href,
|
2134
|
+
activity: message.activity,
|
2135
|
+
recipient: message.identifier
|
2136
|
+
});
|
2137
|
+
}
|
2138
|
+
const delay$1 = this.inboxRetryPolicy({
|
2139
|
+
elapsedTime: Temporal.Instant.from(message.started).until(Temporal.Now.instant()),
|
2140
|
+
attempts: message.attempt
|
2141
|
+
});
|
2142
|
+
if (delay$1 != null) {
|
2143
|
+
logger$1.error("Failed to process the incoming activity {activityId} (attempt #{attempt}); retry...:\n{error}", {
|
2144
|
+
error,
|
2145
|
+
attempt: message.attempt,
|
2146
|
+
activityId: activity.id?.href,
|
2147
|
+
activity: message.activity,
|
2148
|
+
recipient: message.identifier
|
2149
|
+
});
|
2150
|
+
await this.inboxQueue?.enqueue({
|
2151
|
+
...message,
|
2152
|
+
attempt: message.attempt + 1
|
2153
|
+
}, { delay: Temporal.Duration.compare(delay$1, { seconds: 0 }) < 0 ? Temporal.Duration.from({ seconds: 0 }) : delay$1 });
|
2154
|
+
} else logger$1.error("Failed to process the incoming activity {activityId} after {trial} attempts; giving up:\n{error}", {
|
2155
|
+
error,
|
2156
|
+
activityId: activity.id?.href,
|
2157
|
+
activity: message.activity,
|
2158
|
+
recipient: message.identifier
|
2159
|
+
});
|
2160
|
+
span$1.setStatus({
|
2161
|
+
code: SpanStatusCode.ERROR,
|
2162
|
+
message: String(error)
|
2163
|
+
});
|
2164
|
+
span$1.end();
|
2165
|
+
return;
|
2166
|
+
}
|
2167
|
+
if (cacheKey != null) await this.kv.set(cacheKey, true, { ttl: Temporal.Duration.from({ days: 1 }) });
|
2168
|
+
logger$1.info("Activity {activityId} has been processed.", {
|
2169
|
+
activityId: activity.id?.href,
|
2170
|
+
activity: message.activity,
|
2171
|
+
recipient: message.identifier
|
2172
|
+
});
|
2173
|
+
span$1.end();
|
2174
|
+
});
|
2175
|
+
}
|
2176
|
+
startQueue(contextData, options = {}) {
|
2177
|
+
return this._startQueueInternal(contextData, options.signal, options.queue);
|
2178
|
+
}
|
2179
|
+
createContext(urlOrRequest, contextData) {
|
2180
|
+
return urlOrRequest instanceof Request ? this.#createContext(urlOrRequest, contextData) : this.#createContext(urlOrRequest, contextData);
|
2181
|
+
}
|
2182
|
+
#createContext(urlOrRequest, contextData, opts = {}) {
|
2183
|
+
const request = urlOrRequest instanceof Request ? urlOrRequest : null;
|
2184
|
+
const url = urlOrRequest instanceof URL ? new URL(urlOrRequest) : new URL(urlOrRequest.url);
|
2185
|
+
if (request == null) {
|
2186
|
+
url.pathname = "/";
|
2187
|
+
url.hash = "";
|
2188
|
+
url.search = "";
|
2189
|
+
}
|
2190
|
+
const loaderOptions = this.#getLoaderOptions(url.origin);
|
2191
|
+
const ctxOptions = {
|
2192
|
+
url,
|
2193
|
+
federation: this,
|
2194
|
+
data: contextData,
|
2195
|
+
documentLoader: opts.documentLoader ?? this.documentLoaderFactory(loaderOptions),
|
2196
|
+
contextLoader: this.contextLoaderFactory(loaderOptions)
|
2197
|
+
};
|
2198
|
+
if (request == null) return new ContextImpl(ctxOptions);
|
2199
|
+
return new RequestContextImpl({
|
2200
|
+
...ctxOptions,
|
2201
|
+
request,
|
2202
|
+
invokedFromActorDispatcher: opts.invokedFromActorDispatcher,
|
2203
|
+
invokedFromObjectDispatcher: opts.invokedFromObjectDispatcher
|
2204
|
+
});
|
2205
|
+
}
|
2206
|
+
#getLoaderOptions(origin) {
|
2207
|
+
origin = typeof origin === "string" ? new URL(origin).origin : origin.origin;
|
2208
|
+
return {
|
2209
|
+
allowPrivateAddress: this.allowPrivateAddress,
|
2210
|
+
userAgent: typeof this.userAgent === "string" ? this.userAgent : {
|
2211
|
+
url: origin,
|
2212
|
+
...this.userAgent
|
2213
|
+
}
|
2214
|
+
};
|
2215
|
+
}
|
2216
|
+
async sendActivity(keys, inboxes, activity, options) {
|
2217
|
+
const logger$1 = getLogger([
|
2218
|
+
"fedify",
|
2219
|
+
"federation",
|
2220
|
+
"outbox"
|
2221
|
+
]);
|
2222
|
+
const { immediate, collectionSync, context: ctx } = options;
|
2223
|
+
if (activity.id == null) throw new TypeError("The activity to send must have an id.");
|
2224
|
+
if (activity.actorId == null) throw new TypeError("The activity to send must have at least one actor property.");
|
2225
|
+
else if (keys.length < 1) throw new TypeError("The keys must not be empty.");
|
2226
|
+
const contextLoader = this.contextLoaderFactory(this.#getLoaderOptions(ctx.origin));
|
2227
|
+
const activityId = activity.id.href;
|
2228
|
+
let proofCreated = false;
|
2229
|
+
let rsaKey = null;
|
2230
|
+
for (const { keyId, privateKey } of keys) {
|
2231
|
+
validateCryptoKey(privateKey, "private");
|
2232
|
+
if (rsaKey == null && privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
2233
|
+
rsaKey = {
|
2234
|
+
keyId,
|
2235
|
+
privateKey
|
2236
|
+
};
|
2237
|
+
continue;
|
2238
|
+
}
|
2239
|
+
if (privateKey.algorithm.name === "Ed25519") {
|
2240
|
+
activity = await signObject(activity, privateKey, keyId, {
|
2241
|
+
contextLoader,
|
2242
|
+
tracerProvider: this.tracerProvider
|
2243
|
+
});
|
2244
|
+
proofCreated = true;
|
2245
|
+
}
|
2246
|
+
}
|
2247
|
+
let jsonLd = await activity.toJsonLd({
|
2248
|
+
format: "compact",
|
2249
|
+
contextLoader
|
2250
|
+
});
|
2251
|
+
if (rsaKey == null) logger$1.warn("No supported key found to create a Linked Data signature for the activity {activityId}. The activity will be sent without a Linked Data signature. In order to create a Linked Data signature, at least one RSASSA-PKCS1-v1_5 key must be provided.", {
|
2252
|
+
activityId,
|
2253
|
+
keys: keys.map((pair) => ({
|
2254
|
+
keyId: pair.keyId.href,
|
2255
|
+
privateKey: pair.privateKey
|
2256
|
+
}))
|
2257
|
+
});
|
2258
|
+
else jsonLd = await signJsonLd(jsonLd, rsaKey.privateKey, rsaKey.keyId, {
|
2259
|
+
contextLoader,
|
2260
|
+
tracerProvider: this.tracerProvider
|
2261
|
+
});
|
2262
|
+
if (!proofCreated) logger$1.warn("No supported key found to create a proof for the activity {activityId}. The activity will be sent without a proof. In order to create a proof, at least one Ed25519 key must be provided.", {
|
2263
|
+
activityId,
|
2264
|
+
keys: keys.map((pair) => ({
|
2265
|
+
keyId: pair.keyId.href,
|
2266
|
+
privateKey: pair.privateKey
|
2267
|
+
}))
|
2268
|
+
});
|
2269
|
+
if (immediate || this.outboxQueue == null) {
|
2270
|
+
if (immediate) logger$1.debug("Sending activity immediately without queue since immediate option is set.", {
|
2271
|
+
activityId: activity.id.href,
|
2272
|
+
activity: jsonLd
|
2273
|
+
});
|
2274
|
+
else logger$1.debug("Sending activity immediately without queue since queue is not set.", {
|
2275
|
+
activityId: activity.id.href,
|
2276
|
+
activity: jsonLd
|
2277
|
+
});
|
2278
|
+
const promises = [];
|
2279
|
+
for (const inbox in inboxes) promises.push(sendActivity({
|
2280
|
+
keys,
|
2281
|
+
activity: jsonLd,
|
2282
|
+
activityId: activity.id?.href,
|
2283
|
+
activityType: getTypeId(activity).href,
|
2284
|
+
inbox: new URL(inbox),
|
2285
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
2286
|
+
headers: collectionSync == null ? void 0 : new Headers({ "Collection-Synchronization": await buildCollectionSynchronizationHeader(collectionSync, inboxes[inbox].actorIds) }),
|
2287
|
+
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec),
|
2288
|
+
tracerProvider: this.tracerProvider
|
2289
|
+
}));
|
2290
|
+
await Promise.all(promises);
|
2291
|
+
return;
|
2292
|
+
}
|
2293
|
+
logger$1.debug("Enqueuing activity {activityId} to send later.", {
|
2294
|
+
activityId: activity.id.href,
|
2295
|
+
activity: jsonLd
|
2296
|
+
});
|
2297
|
+
const keyJwkPairs = [];
|
2298
|
+
for (const { keyId, privateKey } of keys) {
|
2299
|
+
const privateKeyJwk = await exportJwk(privateKey);
|
2300
|
+
keyJwkPairs.push({
|
2301
|
+
keyId: keyId.href,
|
2302
|
+
privateKey: privateKeyJwk
|
2303
|
+
});
|
2304
|
+
}
|
2305
|
+
if (!this.manuallyStartQueue) this._startQueueInternal(ctx.data);
|
2306
|
+
const carrier = {};
|
2307
|
+
propagation.inject(context.active(), carrier);
|
2308
|
+
const messages = [];
|
2309
|
+
for (const inbox in inboxes) {
|
2310
|
+
const message = {
|
2311
|
+
type: "outbox",
|
2312
|
+
id: crypto.randomUUID(),
|
2313
|
+
baseUrl: ctx.origin,
|
2314
|
+
keys: keyJwkPairs,
|
2315
|
+
activity: jsonLd,
|
2316
|
+
activityId: activity.id?.href,
|
2317
|
+
activityType: getTypeId(activity).href,
|
2318
|
+
inbox,
|
2319
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
2320
|
+
started: new Date().toISOString(),
|
2321
|
+
attempt: 0,
|
2322
|
+
headers: collectionSync == null ? {} : { "Collection-Synchronization": await buildCollectionSynchronizationHeader(collectionSync, inboxes[inbox].actorIds) },
|
2323
|
+
traceContext: carrier
|
2324
|
+
};
|
2325
|
+
messages.push(message);
|
2326
|
+
}
|
2327
|
+
const { outboxQueue } = this;
|
2328
|
+
if (outboxQueue.enqueueMany == null) {
|
2329
|
+
const promises = messages.map((m) => outboxQueue.enqueue(m));
|
2330
|
+
const results = await Promise.allSettled(promises);
|
2331
|
+
const errors = results.filter((r) => r.status === "rejected").map((r) => r.reason);
|
2332
|
+
if (errors.length > 0) {
|
2333
|
+
logger$1.error("Failed to enqueue activity {activityId} to send later: {errors}", {
|
2334
|
+
activityId: activity.id.href,
|
2335
|
+
errors
|
2336
|
+
});
|
2337
|
+
if (errors.length > 1) throw new AggregateError(errors, `Failed to enqueue activity ${activityId} to send later.`);
|
2338
|
+
throw errors[0];
|
2339
|
+
}
|
2340
|
+
} else try {
|
2341
|
+
await outboxQueue.enqueueMany(messages);
|
2342
|
+
} catch (error) {
|
2343
|
+
logger$1.error("Failed to enqueue activity {activityId} to send later: {error}", {
|
2344
|
+
activityId: activity.id.href,
|
2345
|
+
error
|
2346
|
+
});
|
2347
|
+
throw error;
|
2348
|
+
}
|
2349
|
+
}
|
2350
|
+
fetch(request, options) {
|
2351
|
+
const requestId = getRequestId(request);
|
2352
|
+
return withContext({ requestId }, async () => {
|
2353
|
+
const tracer = this._getTracer();
|
2354
|
+
return await tracer.startActiveSpan(request.method, {
|
2355
|
+
kind: SpanKind.SERVER,
|
2356
|
+
attributes: {
|
2357
|
+
[ATTR_HTTP_REQUEST_METHOD]: request.method,
|
2358
|
+
[ATTR_URL_FULL]: request.url
|
2359
|
+
}
|
2360
|
+
}, async (span) => {
|
2361
|
+
const logger$1 = getLogger([
|
2362
|
+
"fedify",
|
2363
|
+
"federation",
|
2364
|
+
"http"
|
2365
|
+
]);
|
2366
|
+
if (span.isRecording()) for (const [k, v] of request.headers) span.setAttribute(ATTR_HTTP_REQUEST_HEADER(k), [v]);
|
2367
|
+
let response;
|
2368
|
+
try {
|
2369
|
+
response = await this.#fetch(request, {
|
2370
|
+
...options,
|
2371
|
+
span,
|
2372
|
+
tracer
|
2373
|
+
});
|
2374
|
+
} catch (error) {
|
2375
|
+
span.setStatus({
|
2376
|
+
code: SpanStatusCode.ERROR,
|
2377
|
+
message: `${error}`
|
2378
|
+
});
|
2379
|
+
span.end();
|
2380
|
+
logger$1.error("An error occurred while serving request {method} {url}: {error}", {
|
2381
|
+
method: request.method,
|
2382
|
+
url: request.url,
|
2383
|
+
error
|
2384
|
+
});
|
2385
|
+
throw error;
|
2386
|
+
}
|
2387
|
+
if (span.isRecording()) {
|
2388
|
+
span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, response.status);
|
2389
|
+
for (const [k, v] of response.headers) span.setAttribute(ATTR_HTTP_RESPONSE_HEADER(k), [v]);
|
2390
|
+
span.setStatus({
|
2391
|
+
code: response.status >= 500 ? SpanStatusCode.ERROR : SpanStatusCode.UNSET,
|
2392
|
+
message: response.statusText
|
2393
|
+
});
|
2394
|
+
}
|
2395
|
+
span.end();
|
2396
|
+
const url = new URL(request.url);
|
2397
|
+
const logTpl = "{method} {path}: {status}";
|
2398
|
+
const values = {
|
2399
|
+
method: request.method,
|
2400
|
+
path: `${url.pathname}${url.search}`,
|
2401
|
+
url: request.url,
|
2402
|
+
status: response.status
|
2403
|
+
};
|
2404
|
+
if (response.status >= 500) logger$1.error(logTpl, values);
|
2405
|
+
else if (response.status >= 400) logger$1.warn(logTpl, values);
|
2406
|
+
else logger$1.info(logTpl, values);
|
2407
|
+
return response;
|
2408
|
+
});
|
2409
|
+
});
|
2410
|
+
}
|
2411
|
+
async #fetch(request, { onNotFound, onNotAcceptable, onUnauthorized, contextData, span, tracer }) {
|
2412
|
+
onNotFound ??= notFound;
|
2413
|
+
onNotAcceptable ??= notAcceptable;
|
2414
|
+
onUnauthorized ??= unauthorized;
|
2415
|
+
const url = new URL(request.url);
|
2416
|
+
const route = this.router.route(url.pathname);
|
2417
|
+
if (route == null) return await onNotFound(request);
|
2418
|
+
span.updateName(`${request.method} ${route.template}`);
|
2419
|
+
let context$1 = this.#createContext(request, contextData);
|
2420
|
+
const routeName = route.name.replace(/:.*$/, "");
|
2421
|
+
switch (routeName) {
|
2422
|
+
case "webfinger": return await handleWebFinger(request, {
|
2423
|
+
context: context$1,
|
2424
|
+
host: this.origin?.handleHost,
|
2425
|
+
actorDispatcher: this.actorCallbacks?.dispatcher,
|
2426
|
+
actorHandleMapper: this.actorCallbacks?.handleMapper,
|
2427
|
+
actorAliasMapper: this.actorCallbacks?.aliasMapper,
|
2428
|
+
onNotFound,
|
2429
|
+
tracer
|
2430
|
+
});
|
2431
|
+
case "nodeInfoJrd": return await handleNodeInfoJrd(request, context$1);
|
2432
|
+
case "nodeInfo": return await handleNodeInfo(request, {
|
2433
|
+
context: context$1,
|
2434
|
+
nodeInfoDispatcher: this.nodeInfoDispatcher
|
2435
|
+
});
|
2436
|
+
case "actor":
|
2437
|
+
context$1 = this.#createContext(request, contextData, { invokedFromActorDispatcher: { identifier: route.values.identifier ?? route.values.handle } });
|
2438
|
+
return await handleActor(request, {
|
2439
|
+
identifier: route.values.identifier ?? route.values.handle,
|
2440
|
+
context: context$1,
|
2441
|
+
actorDispatcher: this.actorCallbacks?.dispatcher,
|
2442
|
+
authorizePredicate: this.actorCallbacks?.authorizePredicate,
|
2443
|
+
onUnauthorized,
|
2444
|
+
onNotFound,
|
2445
|
+
onNotAcceptable
|
2446
|
+
});
|
2447
|
+
case "object": {
|
2448
|
+
const typeId = route.name.replace(/^object:/, "");
|
2449
|
+
const callbacks = this.objectCallbacks[typeId];
|
2450
|
+
const cls = this.objectTypeIds[typeId];
|
2451
|
+
context$1 = this.#createContext(request, contextData, { invokedFromObjectDispatcher: {
|
2452
|
+
cls,
|
2453
|
+
values: route.values
|
2454
|
+
} });
|
2455
|
+
return await handleObject(request, {
|
2456
|
+
values: route.values,
|
2457
|
+
context: context$1,
|
2458
|
+
objectDispatcher: callbacks?.dispatcher,
|
2459
|
+
authorizePredicate: callbacks?.authorizePredicate,
|
2460
|
+
onUnauthorized,
|
2461
|
+
onNotFound,
|
2462
|
+
onNotAcceptable
|
2463
|
+
});
|
2464
|
+
}
|
2465
|
+
case "outbox": return await handleCollection(request, {
|
2466
|
+
name: "outbox",
|
2467
|
+
identifier: route.values.identifier ?? route.values.handle,
|
2468
|
+
uriGetter: context$1.getOutboxUri.bind(context$1),
|
2469
|
+
context: context$1,
|
2470
|
+
collectionCallbacks: this.outboxCallbacks,
|
2471
|
+
tracerProvider: this.tracerProvider,
|
2472
|
+
onUnauthorized,
|
2473
|
+
onNotFound,
|
2474
|
+
onNotAcceptable
|
2475
|
+
});
|
2476
|
+
case "inbox":
|
2477
|
+
if (request.method !== "POST") return await handleCollection(request, {
|
2478
|
+
name: "inbox",
|
2479
|
+
identifier: route.values.identifier ?? route.values.handle,
|
2480
|
+
uriGetter: context$1.getInboxUri.bind(context$1),
|
2481
|
+
context: context$1,
|
2482
|
+
collectionCallbacks: this.inboxCallbacks,
|
2483
|
+
tracerProvider: this.tracerProvider,
|
2484
|
+
onUnauthorized,
|
2485
|
+
onNotFound,
|
2486
|
+
onNotAcceptable
|
2487
|
+
});
|
2488
|
+
context$1 = this.#createContext(request, contextData, { documentLoader: await context$1.getDocumentLoader({ identifier: route.values.identifier ?? route.values.handle }) });
|
2489
|
+
case "sharedInbox":
|
2490
|
+
if (routeName !== "inbox" && this.sharedInboxKeyDispatcher != null) {
|
2491
|
+
const identity = await this.sharedInboxKeyDispatcher(context$1);
|
2492
|
+
if (identity != null) context$1 = this.#createContext(request, contextData, { documentLoader: "identifier" in identity || "username" in identity || "handle" in identity ? await context$1.getDocumentLoader(identity) : context$1.getDocumentLoader(identity) });
|
2493
|
+
}
|
2494
|
+
if (!this.manuallyStartQueue) this._startQueueInternal(contextData);
|
2495
|
+
return await handleInbox(request, {
|
2496
|
+
recipient: route.values.identifier ?? route.values.handle ?? null,
|
2497
|
+
context: context$1,
|
2498
|
+
inboxContextFactory: context$1.toInboxContext.bind(context$1),
|
2499
|
+
kv: this.kv,
|
2500
|
+
kvPrefixes: this.kvPrefixes,
|
2501
|
+
queue: this.inboxQueue,
|
2502
|
+
actorDispatcher: this.actorCallbacks?.dispatcher,
|
2503
|
+
inboxListeners: this.inboxListeners,
|
2504
|
+
inboxErrorHandler: this.inboxErrorHandler,
|
2505
|
+
onNotFound,
|
2506
|
+
signatureTimeWindow: this.signatureTimeWindow,
|
2507
|
+
skipSignatureVerification: this.skipSignatureVerification,
|
2508
|
+
tracerProvider: this.tracerProvider
|
2509
|
+
});
|
2510
|
+
case "following": return await handleCollection(request, {
|
2511
|
+
name: "following",
|
2512
|
+
identifier: route.values.identifier ?? route.values.handle,
|
2513
|
+
uriGetter: context$1.getFollowingUri.bind(context$1),
|
2514
|
+
context: context$1,
|
2515
|
+
collectionCallbacks: this.followingCallbacks,
|
2516
|
+
tracerProvider: this.tracerProvider,
|
2517
|
+
onUnauthorized,
|
2518
|
+
onNotFound,
|
2519
|
+
onNotAcceptable
|
2520
|
+
});
|
2521
|
+
case "followers": {
|
2522
|
+
let baseUrl = url.searchParams.get("base-url");
|
2523
|
+
if (baseUrl != null) try {
|
2524
|
+
baseUrl = `${new URL(baseUrl).origin}/`;
|
2525
|
+
} catch {
|
2526
|
+
baseUrl = null;
|
2527
|
+
}
|
2528
|
+
return await handleCollection(request, {
|
2529
|
+
name: "followers",
|
2530
|
+
identifier: route.values.identifier ?? route.values.handle,
|
2531
|
+
uriGetter: baseUrl == null ? context$1.getFollowersUri.bind(context$1) : (identifier) => {
|
2532
|
+
const uri = context$1.getFollowersUri(identifier);
|
2533
|
+
uri.searchParams.set("base-url", baseUrl);
|
2534
|
+
return uri;
|
2535
|
+
},
|
2536
|
+
context: context$1,
|
2537
|
+
filter: baseUrl != null ? new URL(baseUrl) : void 0,
|
2538
|
+
filterPredicate: baseUrl != null ? (i) => (i instanceof URL ? i.href : i.id?.href ?? "").startsWith(baseUrl) : void 0,
|
2539
|
+
collectionCallbacks: this.followersCallbacks,
|
2540
|
+
tracerProvider: this.tracerProvider,
|
2541
|
+
onUnauthorized,
|
2542
|
+
onNotFound,
|
2543
|
+
onNotAcceptable
|
2544
|
+
});
|
2545
|
+
}
|
2546
|
+
case "liked": return await handleCollection(request, {
|
2547
|
+
name: "liked",
|
2548
|
+
identifier: route.values.identifier ?? route.values.handle,
|
2549
|
+
uriGetter: context$1.getLikedUri.bind(context$1),
|
2550
|
+
context: context$1,
|
2551
|
+
collectionCallbacks: this.likedCallbacks,
|
2552
|
+
tracerProvider: this.tracerProvider,
|
2553
|
+
onUnauthorized,
|
2554
|
+
onNotFound,
|
2555
|
+
onNotAcceptable
|
2556
|
+
});
|
2557
|
+
case "featured": return await handleCollection(request, {
|
2558
|
+
name: "featured",
|
2559
|
+
identifier: route.values.identifier ?? route.values.handle,
|
2560
|
+
uriGetter: context$1.getFeaturedUri.bind(context$1),
|
2561
|
+
context: context$1,
|
2562
|
+
collectionCallbacks: this.featuredCallbacks,
|
2563
|
+
tracerProvider: this.tracerProvider,
|
2564
|
+
onUnauthorized,
|
2565
|
+
onNotFound,
|
2566
|
+
onNotAcceptable
|
2567
|
+
});
|
2568
|
+
case "featuredTags": return await handleCollection(request, {
|
2569
|
+
name: "featured tags",
|
2570
|
+
identifier: route.values.identifier ?? route.values.handle,
|
2571
|
+
uriGetter: context$1.getFeaturedTagsUri.bind(context$1),
|
2572
|
+
context: context$1,
|
2573
|
+
collectionCallbacks: this.featuredTagsCallbacks,
|
2574
|
+
tracerProvider: this.tracerProvider,
|
2575
|
+
onUnauthorized,
|
2576
|
+
onNotFound,
|
2577
|
+
onNotAcceptable
|
2578
|
+
});
|
2579
|
+
default: {
|
2580
|
+
const response = onNotFound(request);
|
2581
|
+
return response instanceof Promise ? await response : response;
|
2582
|
+
}
|
2583
|
+
}
|
2584
|
+
}
|
2585
|
+
};
|
2586
|
+
const FANOUT_THRESHOLD = 5;
|
2587
|
+
var ContextImpl = class ContextImpl {
|
2588
|
+
url;
|
2589
|
+
federation;
|
2590
|
+
data;
|
2591
|
+
documentLoader;
|
2592
|
+
contextLoader;
|
2593
|
+
invokedFromActorKeyPairsDispatcher;
|
2594
|
+
constructor({ url, federation, data, documentLoader, contextLoader, invokedFromActorKeyPairsDispatcher }) {
|
2595
|
+
this.url = url;
|
2596
|
+
this.federation = federation;
|
2597
|
+
this.data = data;
|
2598
|
+
this.documentLoader = documentLoader;
|
2599
|
+
this.contextLoader = contextLoader;
|
2600
|
+
this.invokedFromActorKeyPairsDispatcher = invokedFromActorKeyPairsDispatcher;
|
2601
|
+
}
|
2602
|
+
clone(data) {
|
2603
|
+
return new ContextImpl({
|
2604
|
+
url: this.url,
|
2605
|
+
federation: this.federation,
|
2606
|
+
data,
|
2607
|
+
documentLoader: this.documentLoader,
|
2608
|
+
contextLoader: this.contextLoader,
|
2609
|
+
invokedFromActorKeyPairsDispatcher: this.invokedFromActorKeyPairsDispatcher
|
2610
|
+
});
|
2611
|
+
}
|
2612
|
+
toInboxContext(recipient, activity, activityId, activityType) {
|
2613
|
+
return new InboxContextImpl(recipient, activity, activityId, activityType, {
|
2614
|
+
url: this.url,
|
2615
|
+
federation: this.federation,
|
2616
|
+
data: this.data,
|
2617
|
+
documentLoader: this.documentLoader,
|
2618
|
+
contextLoader: this.contextLoader,
|
2619
|
+
invokedFromActorKeyPairsDispatcher: this.invokedFromActorKeyPairsDispatcher
|
2620
|
+
});
|
2621
|
+
}
|
2622
|
+
get hostname() {
|
2623
|
+
return this.url.hostname;
|
2624
|
+
}
|
2625
|
+
get host() {
|
2626
|
+
return this.url.host;
|
2627
|
+
}
|
2628
|
+
get origin() {
|
2629
|
+
return this.url.origin;
|
2630
|
+
}
|
2631
|
+
get canonicalOrigin() {
|
2632
|
+
return this.federation.origin?.webOrigin ?? this.origin;
|
2633
|
+
}
|
2634
|
+
get tracerProvider() {
|
2635
|
+
return this.federation.tracerProvider;
|
2636
|
+
}
|
2637
|
+
getNodeInfoUri() {
|
2638
|
+
const path = this.federation.router.build("nodeInfo", {});
|
2639
|
+
if (path == null) throw new RouterError("No NodeInfo dispatcher registered.");
|
2640
|
+
return new URL(path, this.canonicalOrigin);
|
2641
|
+
}
|
2642
|
+
getActorUri(identifier) {
|
2643
|
+
const path = this.federation.router.build("actor", {
|
2644
|
+
identifier,
|
2645
|
+
handle: identifier
|
2646
|
+
});
|
2647
|
+
if (path == null) throw new RouterError("No actor dispatcher registered.");
|
2648
|
+
return new URL(path, this.canonicalOrigin);
|
2649
|
+
}
|
2650
|
+
getObjectUri(cls, values) {
|
2651
|
+
const callbacks = this.federation.objectCallbacks[cls.typeId.href];
|
2652
|
+
if (callbacks == null) throw new RouterError("No object dispatcher registered.");
|
2653
|
+
for (const param of callbacks.parameters) if (!(param in values)) throw new TypeError(`Missing parameter: ${param}`);
|
2654
|
+
const path = this.federation.router.build(`object:${cls.typeId.href}`, values);
|
2655
|
+
if (path == null) throw new RouterError("No object dispatcher registered.");
|
2656
|
+
return new URL(path, this.canonicalOrigin);
|
2657
|
+
}
|
2658
|
+
getOutboxUri(identifier) {
|
2659
|
+
const path = this.federation.router.build("outbox", {
|
2660
|
+
identifier,
|
2661
|
+
handle: identifier
|
2662
|
+
});
|
2663
|
+
if (path == null) throw new RouterError("No outbox dispatcher registered.");
|
2664
|
+
return new URL(path, this.canonicalOrigin);
|
2665
|
+
}
|
2666
|
+
getInboxUri(identifier) {
|
2667
|
+
if (identifier == null) {
|
2668
|
+
const path$1 = this.federation.router.build("sharedInbox", {});
|
2669
|
+
if (path$1 == null) throw new RouterError("No shared inbox path registered.");
|
2670
|
+
return new URL(path$1, this.canonicalOrigin);
|
2671
|
+
}
|
2672
|
+
const path = this.federation.router.build("inbox", {
|
2673
|
+
identifier,
|
2674
|
+
handle: identifier
|
2675
|
+
});
|
2676
|
+
if (path == null) throw new RouterError("No inbox path registered.");
|
2677
|
+
return new URL(path, this.canonicalOrigin);
|
2678
|
+
}
|
2679
|
+
getFollowingUri(identifier) {
|
2680
|
+
const path = this.federation.router.build("following", {
|
2681
|
+
identifier,
|
2682
|
+
handle: identifier
|
2683
|
+
});
|
2684
|
+
if (path == null) throw new RouterError("No following collection path registered.");
|
2685
|
+
return new URL(path, this.canonicalOrigin);
|
2686
|
+
}
|
2687
|
+
getFollowersUri(identifier) {
|
2688
|
+
const path = this.federation.router.build("followers", {
|
2689
|
+
identifier,
|
2690
|
+
handle: identifier
|
2691
|
+
});
|
2692
|
+
if (path == null) throw new RouterError("No followers collection path registered.");
|
2693
|
+
return new URL(path, this.canonicalOrigin);
|
2694
|
+
}
|
2695
|
+
getLikedUri(identifier) {
|
2696
|
+
const path = this.federation.router.build("liked", {
|
2697
|
+
identifier,
|
2698
|
+
handle: identifier
|
2699
|
+
});
|
2700
|
+
if (path == null) throw new RouterError("No liked collection path registered.");
|
2701
|
+
return new URL(path, this.canonicalOrigin);
|
2702
|
+
}
|
2703
|
+
getFeaturedUri(identifier) {
|
2704
|
+
const path = this.federation.router.build("featured", {
|
2705
|
+
identifier,
|
2706
|
+
handle: identifier
|
2707
|
+
});
|
2708
|
+
if (path == null) throw new RouterError("No featured collection path registered.");
|
2709
|
+
return new URL(path, this.canonicalOrigin);
|
2710
|
+
}
|
2711
|
+
getFeaturedTagsUri(identifier) {
|
2712
|
+
const path = this.federation.router.build("featuredTags", {
|
2713
|
+
identifier,
|
2714
|
+
handle: identifier
|
2715
|
+
});
|
2716
|
+
if (path == null) throw new RouterError("No featured tags collection path registered.");
|
2717
|
+
return new URL(path, this.canonicalOrigin);
|
2718
|
+
}
|
2719
|
+
parseUri(uri) {
|
2720
|
+
if (uri == null) return null;
|
2721
|
+
if (uri.origin !== this.origin && uri.origin !== this.canonicalOrigin) return null;
|
2722
|
+
const route = this.federation.router.route(uri.pathname);
|
2723
|
+
const logger$1 = getLogger(["fedify", "federation"]);
|
2724
|
+
if (route == null) return null;
|
2725
|
+
else if (route.name === "sharedInbox") return {
|
2726
|
+
type: "inbox",
|
2727
|
+
identifier: void 0,
|
2728
|
+
get handle() {
|
2729
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2730
|
+
return void 0;
|
2731
|
+
}
|
2732
|
+
};
|
2733
|
+
const identifier = "identifier" in route.values ? route.values.identifier : route.values.handle;
|
2734
|
+
if (route.name === "actor") return {
|
2735
|
+
type: "actor",
|
2736
|
+
identifier,
|
2737
|
+
get handle() {
|
2738
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2739
|
+
return identifier;
|
2740
|
+
}
|
2741
|
+
};
|
2742
|
+
else if (route.name.startsWith("object:")) {
|
2743
|
+
const typeId = route.name.replace(/^object:/, "");
|
2744
|
+
return {
|
2745
|
+
type: "object",
|
2746
|
+
class: this.federation.objectTypeIds[typeId],
|
2747
|
+
typeId: new URL(typeId),
|
2748
|
+
values: route.values
|
2749
|
+
};
|
2750
|
+
} else if (route.name === "inbox") return {
|
2751
|
+
type: "inbox",
|
2752
|
+
identifier,
|
2753
|
+
get handle() {
|
2754
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2755
|
+
return identifier;
|
2756
|
+
}
|
2757
|
+
};
|
2758
|
+
else if (route.name === "outbox") return {
|
2759
|
+
type: "outbox",
|
2760
|
+
identifier,
|
2761
|
+
get handle() {
|
2762
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2763
|
+
return identifier;
|
2764
|
+
}
|
2765
|
+
};
|
2766
|
+
else if (route.name === "following") return {
|
2767
|
+
type: "following",
|
2768
|
+
identifier,
|
2769
|
+
get handle() {
|
2770
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2771
|
+
return identifier;
|
2772
|
+
}
|
2773
|
+
};
|
2774
|
+
else if (route.name === "followers") return {
|
2775
|
+
type: "followers",
|
2776
|
+
identifier,
|
2777
|
+
get handle() {
|
2778
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2779
|
+
return identifier;
|
2780
|
+
}
|
2781
|
+
};
|
2782
|
+
else if (route.name === "liked") return {
|
2783
|
+
type: "liked",
|
2784
|
+
identifier,
|
2785
|
+
get handle() {
|
2786
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2787
|
+
return identifier;
|
2788
|
+
}
|
2789
|
+
};
|
2790
|
+
else if (route.name === "featured") return {
|
2791
|
+
type: "featured",
|
2792
|
+
identifier,
|
2793
|
+
get handle() {
|
2794
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2795
|
+
return identifier;
|
2796
|
+
}
|
2797
|
+
};
|
2798
|
+
else if (route.name === "featuredTags") return {
|
2799
|
+
type: "featuredTags",
|
2800
|
+
identifier,
|
2801
|
+
get handle() {
|
2802
|
+
logger$1.warn("The ParseUriResult.handle property is deprecated; use ParseUriResult.identifier instead.");
|
2803
|
+
return identifier;
|
2804
|
+
}
|
2805
|
+
};
|
2806
|
+
return null;
|
2807
|
+
}
|
2808
|
+
async getActorKeyPairs(identifier) {
|
2809
|
+
const logger$1 = getLogger([
|
2810
|
+
"fedify",
|
2811
|
+
"federation",
|
2812
|
+
"actor"
|
2813
|
+
]);
|
2814
|
+
if (this.invokedFromActorKeyPairsDispatcher != null) logger$1.warn("Context.getActorKeyPairs({getActorKeyPairsIdentifier}) method is invoked from the actor key pairs dispatcher ({actorKeyPairsDispatcherIdentifier}); this may cause an infinite loop.", {
|
2815
|
+
getActorKeyPairsIdentifier: identifier,
|
2816
|
+
actorKeyPairsDispatcherIdentifier: this.invokedFromActorKeyPairsDispatcher.identifier
|
2817
|
+
});
|
2818
|
+
let keyPairs;
|
2819
|
+
try {
|
2820
|
+
keyPairs = await this.getKeyPairsFromIdentifier(identifier);
|
2821
|
+
} catch (_) {
|
2822
|
+
logger$1.warn("No actor key pairs dispatcher registered.");
|
2823
|
+
return [];
|
2824
|
+
}
|
2825
|
+
const owner = this.getActorUri(identifier);
|
2826
|
+
const result = [];
|
2827
|
+
for (const keyPair of keyPairs) {
|
2828
|
+
const newPair = {
|
2829
|
+
...keyPair,
|
2830
|
+
cryptographicKey: new CryptographicKey({
|
2831
|
+
id: keyPair.keyId,
|
2832
|
+
owner,
|
2833
|
+
publicKey: keyPair.publicKey
|
2834
|
+
}),
|
2835
|
+
multikey: new Multikey({
|
2836
|
+
id: keyPair.keyId,
|
2837
|
+
controller: owner,
|
2838
|
+
publicKey: keyPair.publicKey
|
2839
|
+
})
|
2840
|
+
};
|
2841
|
+
result.push(newPair);
|
2842
|
+
}
|
2843
|
+
return result;
|
2844
|
+
}
|
2845
|
+
async getKeyPairsFromIdentifier(identifier) {
|
2846
|
+
const logger$1 = getLogger([
|
2847
|
+
"fedify",
|
2848
|
+
"federation",
|
2849
|
+
"actor"
|
2850
|
+
]);
|
2851
|
+
if (this.federation.actorCallbacks?.keyPairsDispatcher == null) throw new Error("No actor key pairs dispatcher registered.");
|
2852
|
+
const path = this.federation.router.build("actor", {
|
2853
|
+
identifier,
|
2854
|
+
handle: identifier
|
2855
|
+
});
|
2856
|
+
if (path == null) {
|
2857
|
+
logger$1.warn("No actor dispatcher registered.");
|
2858
|
+
return [];
|
2859
|
+
}
|
2860
|
+
const actorUri = new URL(path, this.canonicalOrigin);
|
2861
|
+
const keyPairs = await this.federation.actorCallbacks?.keyPairsDispatcher(new ContextImpl({
|
2862
|
+
...this,
|
2863
|
+
invokedFromActorKeyPairsDispatcher: { identifier }
|
2864
|
+
}), identifier);
|
2865
|
+
if (keyPairs.length < 1) logger$1.warn("No key pairs found for actor {identifier}.", { identifier });
|
2866
|
+
let i = 0;
|
2867
|
+
const result = [];
|
2868
|
+
for (const keyPair of keyPairs) {
|
2869
|
+
result.push({
|
2870
|
+
...keyPair,
|
2871
|
+
keyId: new URL(i == 0 ? `#main-key` : `#key-${i + 1}`, actorUri)
|
2872
|
+
});
|
2873
|
+
i++;
|
2874
|
+
}
|
2875
|
+
return result;
|
2876
|
+
}
|
2877
|
+
async getRsaKeyPairFromIdentifier(identifier) {
|
2878
|
+
const keyPairs = await this.getKeyPairsFromIdentifier(identifier);
|
2879
|
+
for (const keyPair of keyPairs) {
|
2880
|
+
const { privateKey } = keyPair;
|
2881
|
+
if (privateKey.algorithm.name === "RSASSA-PKCS1-v1_5" && privateKey.algorithm.hash.name === "SHA-256") return keyPair;
|
2882
|
+
}
|
2883
|
+
getLogger([
|
2884
|
+
"fedify",
|
2885
|
+
"federation",
|
2886
|
+
"actor"
|
2887
|
+
]).warn("No RSA-PKCS#1-v1.5 SHA-256 key found for actor {identifier}.", { identifier });
|
2888
|
+
return null;
|
2889
|
+
}
|
2890
|
+
getDocumentLoader(identity) {
|
2891
|
+
if ("identifier" in identity || "username" in identity || "handle" in identity) {
|
2892
|
+
let identifierPromise;
|
2893
|
+
if ("username" in identity || "handle" in identity) {
|
2894
|
+
let username;
|
2895
|
+
if ("username" in identity) username = identity.username;
|
2896
|
+
else {
|
2897
|
+
username = identity.handle;
|
2898
|
+
getLogger([
|
2899
|
+
"fedify",
|
2900
|
+
"runtime",
|
2901
|
+
"docloader"
|
2902
|
+
]).warn("The \"handle\" property is deprecated; use \"identifier\" or \"username\" instead.", { identity });
|
2903
|
+
}
|
2904
|
+
const mapper = this.federation.actorCallbacks?.handleMapper;
|
2905
|
+
if (mapper == null) identifierPromise = Promise.resolve(username);
|
2906
|
+
else {
|
2907
|
+
const identifier = mapper(this, username);
|
2908
|
+
identifierPromise = identifier instanceof Promise ? identifier : Promise.resolve(identifier);
|
2909
|
+
}
|
2910
|
+
} else identifierPromise = Promise.resolve(identity.identifier);
|
2911
|
+
return identifierPromise.then((identifier) => {
|
2912
|
+
if (identifier == null) return this.documentLoader;
|
2913
|
+
const keyPair = this.getRsaKeyPairFromIdentifier(identifier);
|
2914
|
+
return keyPair.then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory(pair));
|
2915
|
+
});
|
2916
|
+
}
|
2917
|
+
return this.federation.authenticatedDocumentLoaderFactory(identity);
|
2918
|
+
}
|
2919
|
+
lookupObject(identifier, options = {}) {
|
2920
|
+
return lookupObject(identifier, {
|
2921
|
+
...options,
|
2922
|
+
documentLoader: options.documentLoader ?? this.documentLoader,
|
2923
|
+
contextLoader: options.contextLoader ?? this.contextLoader,
|
2924
|
+
userAgent: options.userAgent ?? this.federation.userAgent,
|
2925
|
+
tracerProvider: options.tracerProvider ?? this.tracerProvider,
|
2926
|
+
allowPrivateAddress: this.federation.allowPrivateAddress
|
2927
|
+
});
|
2928
|
+
}
|
2929
|
+
traverseCollection(collection, options = {}) {
|
2930
|
+
return traverseCollection(collection, {
|
2931
|
+
...options,
|
2932
|
+
documentLoader: options.documentLoader ?? this.documentLoader,
|
2933
|
+
contextLoader: options.contextLoader ?? this.contextLoader
|
2934
|
+
});
|
2935
|
+
}
|
2936
|
+
lookupNodeInfo(url, options = {}) {
|
2937
|
+
return options.parse === "none" ? getNodeInfo(url, {
|
2938
|
+
parse: "none",
|
2939
|
+
direct: options.direct,
|
2940
|
+
userAgent: options?.userAgent ?? this.federation.userAgent
|
2941
|
+
}) : getNodeInfo(url, {
|
2942
|
+
parse: options.parse,
|
2943
|
+
direct: options.direct,
|
2944
|
+
userAgent: options?.userAgent ?? this.federation.userAgent
|
2945
|
+
});
|
2946
|
+
}
|
2947
|
+
lookupWebFinger(resource, options = {}) {
|
2948
|
+
return lookupWebFinger(resource, {
|
2949
|
+
...options,
|
2950
|
+
userAgent: options.userAgent ?? this.federation.userAgent,
|
2951
|
+
tracerProvider: options.tracerProvider ?? this.tracerProvider,
|
2952
|
+
allowPrivateAddress: this.federation.allowPrivateAddress
|
2953
|
+
});
|
2954
|
+
}
|
2955
|
+
sendActivity(sender, recipients, activity, options = {}) {
|
2956
|
+
const tracer = this.tracerProvider.getTracer(deno_default.name, deno_default.version);
|
2957
|
+
return tracer.startActiveSpan(this.federation.outboxQueue == null || options.immediate ? "activitypub.outbox" : "activitypub.fanout", {
|
2958
|
+
kind: this.federation.outboxQueue == null || options.immediate ? SpanKind.CLIENT : SpanKind.PRODUCER,
|
2959
|
+
attributes: {
|
2960
|
+
"activitypub.activity.type": getTypeId(activity).href,
|
2961
|
+
"activitypub.activity.to": activity.toIds.map((to) => to.href),
|
2962
|
+
"activitypub.activity.cc": activity.toIds.map((cc) => cc.href),
|
2963
|
+
"activitypub.activity.bto": activity.btoIds.map((bto) => bto.href),
|
2964
|
+
"activitypub.activity.bcc": activity.toIds.map((bcc) => bcc.href)
|
2965
|
+
}
|
2966
|
+
}, async (span) => {
|
2967
|
+
try {
|
2968
|
+
if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
|
2969
|
+
await this.sendActivityInternal(sender, recipients, activity, options, span);
|
2970
|
+
} catch (e) {
|
2971
|
+
span.setStatus({
|
2972
|
+
code: SpanStatusCode.ERROR,
|
2973
|
+
message: String(e)
|
2974
|
+
});
|
2975
|
+
throw e;
|
2976
|
+
} finally {
|
2977
|
+
span.end();
|
2978
|
+
}
|
2979
|
+
});
|
2980
|
+
}
|
2981
|
+
async sendActivityInternal(sender, recipients, activity, options, span) {
|
2982
|
+
const logger$1 = getLogger([
|
2983
|
+
"fedify",
|
2984
|
+
"federation",
|
2985
|
+
"outbox"
|
2986
|
+
]);
|
2987
|
+
let keys;
|
2988
|
+
let identifier = null;
|
2989
|
+
if ("identifier" in sender || "username" in sender || "handle" in sender) {
|
2990
|
+
if ("identifier" in sender) identifier = sender.identifier;
|
2991
|
+
else {
|
2992
|
+
let username;
|
2993
|
+
if ("username" in sender) username = sender.username;
|
2994
|
+
else {
|
2995
|
+
username = sender.handle;
|
2996
|
+
logger$1.warn("The \"handle\" property for the sender parameter is deprecated; use \"identifier\" or \"username\" instead.", { sender });
|
2997
|
+
}
|
2998
|
+
if (this.federation.actorCallbacks?.handleMapper == null) identifier = username;
|
2999
|
+
else {
|
3000
|
+
const mapped = await this.federation.actorCallbacks.handleMapper(this, username);
|
3001
|
+
if (mapped == null) throw new Error(`No actor found for the given username ${JSON.stringify(username)}.`);
|
3002
|
+
identifier = mapped;
|
3003
|
+
}
|
3004
|
+
}
|
3005
|
+
span.setAttribute("fedify.actor.identifier", identifier);
|
3006
|
+
keys = await this.getKeyPairsFromIdentifier(identifier);
|
3007
|
+
if (keys.length < 1) throw new Error(`No key pair found for actor ${JSON.stringify(identifier)}.`);
|
3008
|
+
} else if (Array.isArray(sender)) {
|
3009
|
+
if (sender.length < 1) throw new Error("The sender's key pairs are empty.");
|
3010
|
+
keys = sender;
|
3011
|
+
} else keys = [sender];
|
3012
|
+
if (keys.length < 1) throw new TypeError("The sender's keys must not be empty.");
|
3013
|
+
for (const { privateKey } of keys) validateCryptoKey(privateKey, "private");
|
3014
|
+
const opts = { context: this };
|
3015
|
+
let expandedRecipients;
|
3016
|
+
if (Array.isArray(recipients)) expandedRecipients = recipients;
|
3017
|
+
else if (recipients === "followers") {
|
3018
|
+
if (identifier == null) throw new Error("If recipients is \"followers\", sender must be an actor identifier or username.");
|
3019
|
+
expandedRecipients = [];
|
3020
|
+
for await (const recipient of this.getFollowers(identifier)) expandedRecipients.push(recipient);
|
3021
|
+
if (options.syncCollection) {
|
3022
|
+
const collectionId = this.federation.router.build("followers", {
|
3023
|
+
identifier,
|
3024
|
+
handle: identifier
|
3025
|
+
});
|
3026
|
+
opts.collectionSync = collectionId == null ? void 0 : new URL(collectionId, this.canonicalOrigin).href;
|
3027
|
+
}
|
3028
|
+
} else expandedRecipients = [recipients];
|
3029
|
+
span.setAttribute("activitypub.inboxes", expandedRecipients.length);
|
3030
|
+
for (const activityTransformer of this.federation.activityTransformers) activity = activityTransformer(activity, this);
|
3031
|
+
span?.setAttribute("activitypub.activity.id", activity?.id?.href ?? "");
|
3032
|
+
if (activity.actorId == null) {
|
3033
|
+
logger$1.error("Activity {activityId} to send does not have an actor.", {
|
3034
|
+
activity,
|
3035
|
+
activityId: activity?.id?.href
|
3036
|
+
});
|
3037
|
+
throw new TypeError("The activity to send must have at least one actor property.");
|
3038
|
+
}
|
3039
|
+
const inboxes = extractInboxes({
|
3040
|
+
recipients: expandedRecipients,
|
3041
|
+
preferSharedInbox: options.preferSharedInbox,
|
3042
|
+
excludeBaseUris: options.excludeBaseUris
|
3043
|
+
});
|
3044
|
+
logger$1.debug("Sending activity {activityId} to inboxes:\n{inboxes}", {
|
3045
|
+
inboxes: globalThis.Object.keys(inboxes),
|
3046
|
+
activityId: activity.id?.href,
|
3047
|
+
activity
|
3048
|
+
});
|
3049
|
+
if (this.federation.fanoutQueue == null || options.immediate || options.fanout === "skip" || (options.fanout ?? "auto") === "auto" && globalThis.Object.keys(inboxes).length < FANOUT_THRESHOLD) {
|
3050
|
+
await this.federation.sendActivity(keys, inboxes, activity, opts);
|
3051
|
+
return;
|
3052
|
+
}
|
3053
|
+
const keyJwkPairs = await Promise.all(keys.map(async ({ keyId, privateKey }) => ({
|
3054
|
+
keyId: keyId.href,
|
3055
|
+
privateKey: await exportJwk(privateKey)
|
3056
|
+
})));
|
3057
|
+
const carrier = {};
|
3058
|
+
propagation.inject(context.active(), carrier);
|
3059
|
+
const message = {
|
3060
|
+
type: "fanout",
|
3061
|
+
id: crypto.randomUUID(),
|
3062
|
+
baseUrl: this.origin,
|
3063
|
+
keys: keyJwkPairs,
|
3064
|
+
inboxes: globalThis.Object.fromEntries(globalThis.Object.entries(inboxes).map(([k, { actorIds, sharedInbox }]) => [k, {
|
3065
|
+
actorIds: [...actorIds],
|
3066
|
+
sharedInbox
|
3067
|
+
}])),
|
3068
|
+
activity: await activity.toJsonLd({
|
3069
|
+
format: "compact",
|
3070
|
+
contextLoader: this.contextLoader
|
3071
|
+
}),
|
3072
|
+
activityId: activity.id?.href,
|
3073
|
+
activityType: getTypeId(activity).href,
|
3074
|
+
collectionSync: opts.collectionSync,
|
3075
|
+
traceContext: carrier
|
3076
|
+
};
|
3077
|
+
if (!this.federation.manuallyStartQueue) this.federation._startQueueInternal(this.data);
|
3078
|
+
this.federation.fanoutQueue.enqueue(message);
|
3079
|
+
}
|
3080
|
+
async *getFollowers(identifier) {
|
3081
|
+
if (this.federation.followersCallbacks == null) throw new Error("No followers collection dispatcher registered.");
|
3082
|
+
const result = await this.federation.followersCallbacks.dispatcher(this, identifier, null);
|
3083
|
+
if (result != null) {
|
3084
|
+
for (const recipient of result.items) yield recipient;
|
3085
|
+
return;
|
3086
|
+
}
|
3087
|
+
if (this.federation.followersCallbacks.firstCursor == null) throw new Error("No first cursor dispatcher registered for followers collection.");
|
3088
|
+
let cursor = await this.federation.followersCallbacks.firstCursor(this, identifier);
|
3089
|
+
if (cursor != null) getLogger([
|
3090
|
+
"fedify",
|
3091
|
+
"federation",
|
3092
|
+
"outbox"
|
3093
|
+
]).warn("Since the followers collection dispatcher returned null for no cursor (i.e., one-shot dispatcher), the pagination is used to fetch \"followers\". However, it is recommended to implement the one-shot dispatcher for better performance.", { identifier });
|
3094
|
+
while (cursor != null) {
|
3095
|
+
const result$1 = await this.federation.followersCallbacks.dispatcher(this, identifier, cursor);
|
3096
|
+
if (result$1 == null) break;
|
3097
|
+
for (const recipient of result$1.items) yield recipient;
|
3098
|
+
cursor = result$1.nextCursor ?? null;
|
3099
|
+
}
|
3100
|
+
}
|
3101
|
+
routeActivity(recipient, activity, options = {}) {
|
3102
|
+
const tracerProvider = this.tracerProvider ?? this.tracerProvider;
|
3103
|
+
const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
|
3104
|
+
return tracer.startActiveSpan("activitypub.inbox", {
|
3105
|
+
kind: this.federation.inboxQueue == null || options.immediate ? SpanKind.INTERNAL : SpanKind.PRODUCER,
|
3106
|
+
attributes: { "activitypub.activity.type": getTypeId(activity).href }
|
3107
|
+
}, async (span) => {
|
3108
|
+
if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
|
3109
|
+
if (activity.toIds.length > 0) span.setAttribute("activitypub.activity.to", activity.toIds.map((to) => to.href));
|
3110
|
+
if (activity.ccIds.length > 0) span.setAttribute("activitypub.activity.cc", activity.ccIds.map((cc) => cc.href));
|
3111
|
+
if (activity.btoIds.length > 0) span.setAttribute("activitypub.activity.bto", activity.btoIds.map((bto) => bto.href));
|
3112
|
+
if (activity.bccIds.length > 0) span.setAttribute("activitypub.activity.bcc", activity.bccIds.map((bcc) => bcc.href));
|
3113
|
+
try {
|
3114
|
+
const ok = await this.routeActivityInternal(recipient, activity, options, span);
|
3115
|
+
if (ok) {
|
3116
|
+
span.setAttribute("activitypub.shared_inbox", recipient == null);
|
3117
|
+
if (recipient != null) span.setAttribute("fedify.inbox.recipient", recipient);
|
3118
|
+
} else span.setStatus({ code: SpanStatusCode.ERROR });
|
3119
|
+
return ok;
|
3120
|
+
} catch (e) {
|
3121
|
+
span.setStatus({
|
3122
|
+
code: SpanStatusCode.ERROR,
|
3123
|
+
message: String(e)
|
3124
|
+
});
|
3125
|
+
throw e;
|
3126
|
+
} finally {
|
3127
|
+
span.end();
|
3128
|
+
}
|
3129
|
+
});
|
3130
|
+
}
|
3131
|
+
async routeActivityInternal(recipient, activity, options = {}, span) {
|
3132
|
+
const logger$1 = getLogger([
|
3133
|
+
"fedify",
|
3134
|
+
"federation",
|
3135
|
+
"inbox"
|
3136
|
+
]);
|
3137
|
+
const contextLoader = options.contextLoader ?? this.contextLoader;
|
3138
|
+
const json = await activity.toJsonLd({ contextLoader });
|
3139
|
+
const keyCache = new KvKeyCache(this.federation.kv, this.federation.kvPrefixes.publicKey, this);
|
3140
|
+
const verified = await verifyObject(Activity, json, {
|
3141
|
+
contextLoader,
|
3142
|
+
documentLoader: options.documentLoader ?? this.documentLoader,
|
3143
|
+
tracerProvider: options.tracerProvider ?? this.tracerProvider,
|
3144
|
+
keyCache
|
3145
|
+
});
|
3146
|
+
if (verified == null) {
|
3147
|
+
logger$1.debug("Object Integrity Proofs are not verified.", {
|
3148
|
+
recipient,
|
3149
|
+
activity: json
|
3150
|
+
});
|
3151
|
+
if (activity.id == null) {
|
3152
|
+
logger$1.debug("Activity is missing an ID; unable to fetch.", {
|
3153
|
+
recipient,
|
3154
|
+
activity: json
|
3155
|
+
});
|
3156
|
+
return false;
|
3157
|
+
}
|
3158
|
+
const fetched = await this.lookupObject(activity.id, options);
|
3159
|
+
if (fetched == null) {
|
3160
|
+
logger$1.debug("Failed to fetch the remote activity object {activityId}.", {
|
3161
|
+
recipient,
|
3162
|
+
activity: json,
|
3163
|
+
activityId: activity.id.href
|
3164
|
+
});
|
3165
|
+
return false;
|
3166
|
+
} else if (!(fetched instanceof Activity)) {
|
3167
|
+
logger$1.debug("Fetched object is not an Activity.", {
|
3168
|
+
recipient,
|
3169
|
+
activity: await fetched.toJsonLd({ contextLoader })
|
3170
|
+
});
|
3171
|
+
return false;
|
3172
|
+
} else if (fetched.id?.href !== activity.id.href) {
|
3173
|
+
logger$1.debug("Fetched activity object has a different ID; failed to verify.", {
|
3174
|
+
recipient,
|
3175
|
+
activity: await fetched.toJsonLd({ contextLoader })
|
3176
|
+
});
|
3177
|
+
return false;
|
3178
|
+
} else if (fetched.actorIds.length < 1) {
|
3179
|
+
logger$1.debug("Fetched activity object is missing an actor; unable to verify.", {
|
3180
|
+
recipient,
|
3181
|
+
activity: await fetched.toJsonLd({ contextLoader })
|
3182
|
+
});
|
3183
|
+
return false;
|
3184
|
+
}
|
3185
|
+
const activityId = fetched.id;
|
3186
|
+
if (!fetched.actorIds.every((actor) => actor.origin === activityId.origin)) {
|
3187
|
+
logger$1.debug("Fetched activity object has actors from different origins; unable to verify.", {
|
3188
|
+
recipient,
|
3189
|
+
activity: await fetched.toJsonLd({ contextLoader })
|
3190
|
+
});
|
3191
|
+
return false;
|
3192
|
+
}
|
3193
|
+
logger$1.debug("Successfully fetched the remote activity object {activityId}; ignore the original activity and use the fetched one, which is trustworthy.");
|
3194
|
+
activity = fetched;
|
3195
|
+
} else logger$1.debug("Object Integrity Proofs are verified.", {
|
3196
|
+
recipient,
|
3197
|
+
activity: json
|
3198
|
+
});
|
3199
|
+
const routeResult = await routeActivity({
|
3200
|
+
context: this,
|
3201
|
+
json,
|
3202
|
+
activity,
|
3203
|
+
recipient,
|
3204
|
+
inboxListeners: this.federation.inboxListeners,
|
3205
|
+
inboxContextFactory: this.toInboxContext.bind(this),
|
3206
|
+
inboxErrorHandler: this.federation.inboxErrorHandler,
|
3207
|
+
kv: this.federation.kv,
|
3208
|
+
kvPrefixes: this.federation.kvPrefixes,
|
3209
|
+
queue: this.federation.inboxQueue,
|
3210
|
+
span,
|
3211
|
+
tracerProvider: options.tracerProvider ?? this.tracerProvider
|
3212
|
+
});
|
3213
|
+
return routeResult === "alreadyProcessed" || routeResult === "enqueued" || routeResult === "unsupportedActivity" || routeResult === "success";
|
3214
|
+
}
|
3215
|
+
};
|
3216
|
+
var RequestContextImpl = class RequestContextImpl extends ContextImpl {
|
3217
|
+
#invokedFromActorDispatcher;
|
3218
|
+
#invokedFromObjectDispatcher;
|
3219
|
+
request;
|
3220
|
+
url;
|
3221
|
+
constructor(options) {
|
3222
|
+
super(options);
|
3223
|
+
this.#invokedFromActorDispatcher = options.invokedFromActorDispatcher;
|
3224
|
+
this.#invokedFromObjectDispatcher = options.invokedFromObjectDispatcher;
|
3225
|
+
this.request = options.request;
|
3226
|
+
this.url = options.url;
|
3227
|
+
}
|
3228
|
+
clone(data) {
|
3229
|
+
return new RequestContextImpl({
|
3230
|
+
url: this.url,
|
3231
|
+
federation: this.federation,
|
3232
|
+
data,
|
3233
|
+
documentLoader: this.documentLoader,
|
3234
|
+
contextLoader: this.contextLoader,
|
3235
|
+
invokedFromActorKeyPairsDispatcher: this.invokedFromActorKeyPairsDispatcher,
|
3236
|
+
invokedFromActorDispatcher: this.#invokedFromActorDispatcher,
|
3237
|
+
invokedFromObjectDispatcher: this.#invokedFromObjectDispatcher,
|
3238
|
+
request: this.request
|
3239
|
+
});
|
3240
|
+
}
|
3241
|
+
async getActor(identifier) {
|
3242
|
+
if (this.federation.actorCallbacks == null || this.federation.actorCallbacks.dispatcher == null) throw new Error("No actor dispatcher registered.");
|
3243
|
+
if (this.#invokedFromActorDispatcher != null) getLogger([
|
3244
|
+
"fedify",
|
3245
|
+
"federation",
|
3246
|
+
"actor"
|
3247
|
+
]).warn("RequestContext.getActor({getActorIdentifier}) is invoked from the actor dispatcher ({actorDispatcherIdentifier}); this may cause an infinite loop.", {
|
3248
|
+
getActorIdentifier: identifier,
|
3249
|
+
actorDispatcherIdentifier: this.#invokedFromActorDispatcher.identifier
|
3250
|
+
});
|
3251
|
+
return await this.federation.actorCallbacks.dispatcher(new RequestContextImpl({
|
3252
|
+
...this,
|
3253
|
+
invokedFromActorDispatcher: { identifier }
|
3254
|
+
}), identifier);
|
3255
|
+
}
|
3256
|
+
async getObject(cls, values) {
|
3257
|
+
const callbacks = this.federation.objectCallbacks[cls.typeId.href];
|
3258
|
+
if (callbacks == null) throw new Error("No object dispatcher registered.");
|
3259
|
+
for (const param of callbacks.parameters) if (!(param in values)) throw new TypeError(`Missing parameter: ${param}`);
|
3260
|
+
if (this.#invokedFromObjectDispatcher != null) getLogger(["fedify", "federation"]).warn("RequestContext.getObject({getObjectClass}, {getObjectValues}) is invoked from the object dispatcher ({actorDispatcherClass}, {actorDispatcherValues}); this may cause an infinite loop.", {
|
3261
|
+
getObjectClass: cls.name,
|
3262
|
+
getObjectValues: values,
|
3263
|
+
actorDispatcherClass: this.#invokedFromObjectDispatcher.cls.name,
|
3264
|
+
actorDispatcherValues: this.#invokedFromObjectDispatcher.values
|
3265
|
+
});
|
3266
|
+
return await callbacks.dispatcher(new RequestContextImpl({
|
3267
|
+
...this,
|
3268
|
+
invokedFromObjectDispatcher: {
|
3269
|
+
cls,
|
3270
|
+
values
|
3271
|
+
}
|
3272
|
+
}), values);
|
3273
|
+
}
|
3274
|
+
#signedKey = void 0;
|
3275
|
+
async getSignedKey(options = {}) {
|
3276
|
+
if (this.#signedKey != null) return this.#signedKey;
|
3277
|
+
return this.#signedKey = await verifyRequest(this.request, {
|
3278
|
+
...this,
|
3279
|
+
contextLoader: options.contextLoader ?? this.contextLoader,
|
3280
|
+
documentLoader: options.documentLoader ?? this.documentLoader,
|
3281
|
+
timeWindow: this.federation.signatureTimeWindow,
|
3282
|
+
tracerProvider: options.tracerProvider ?? this.tracerProvider
|
3283
|
+
});
|
3284
|
+
}
|
3285
|
+
#signedKeyOwner = void 0;
|
3286
|
+
async getSignedKeyOwner(options = {}) {
|
3287
|
+
if (this.#signedKeyOwner != null) return this.#signedKeyOwner;
|
3288
|
+
const key = await this.getSignedKey(options);
|
3289
|
+
if (key == null) return this.#signedKeyOwner = null;
|
3290
|
+
return this.#signedKeyOwner = await getKeyOwner(key, {
|
3291
|
+
contextLoader: options.contextLoader ?? this.contextLoader,
|
3292
|
+
documentLoader: options.documentLoader ?? this.documentLoader,
|
3293
|
+
tracerProvider: options.tracerProvider ?? this.tracerProvider
|
3294
|
+
});
|
3295
|
+
}
|
3296
|
+
};
|
3297
|
+
var InboxContextImpl = class InboxContextImpl extends ContextImpl {
|
3298
|
+
recipient;
|
3299
|
+
activity;
|
3300
|
+
activityId;
|
3301
|
+
activityType;
|
3302
|
+
constructor(recipient, activity, activityId, activityType, options) {
|
3303
|
+
super(options);
|
3304
|
+
this.recipient = recipient;
|
3305
|
+
this.activity = activity;
|
3306
|
+
this.activityId = activityId;
|
3307
|
+
this.activityType = activityType;
|
3308
|
+
}
|
3309
|
+
clone(data) {
|
3310
|
+
return new InboxContextImpl(this.recipient, this.activity, this.activityId, this.activityType, {
|
3311
|
+
url: this.url,
|
3312
|
+
federation: this.federation,
|
3313
|
+
data,
|
3314
|
+
documentLoader: this.documentLoader,
|
3315
|
+
contextLoader: this.contextLoader,
|
3316
|
+
invokedFromActorKeyPairsDispatcher: this.invokedFromActorKeyPairsDispatcher
|
3317
|
+
});
|
3318
|
+
}
|
3319
|
+
forwardActivity(forwarder, recipients, options) {
|
3320
|
+
const tracer = this.tracerProvider.getTracer(deno_default.name, deno_default.version);
|
3321
|
+
return tracer.startActiveSpan("activitypub.outbox", {
|
3322
|
+
kind: this.federation.outboxQueue == null || options?.immediate ? SpanKind.CLIENT : SpanKind.PRODUCER,
|
3323
|
+
attributes: { "activitypub.activity.type": this.activityType }
|
3324
|
+
}, async (span) => {
|
3325
|
+
try {
|
3326
|
+
if (this.activityId != null) span.setAttribute("activitypub.activity.id", this.activityId);
|
3327
|
+
await this.forwardActivityInternal(forwarder, recipients, options);
|
3328
|
+
} catch (e) {
|
3329
|
+
span.setStatus({
|
3330
|
+
code: SpanStatusCode.ERROR,
|
3331
|
+
message: String(e)
|
3332
|
+
});
|
3333
|
+
throw e;
|
3334
|
+
} finally {
|
3335
|
+
span.end();
|
3336
|
+
}
|
3337
|
+
});
|
3338
|
+
}
|
3339
|
+
async forwardActivityInternal(forwarder, recipients, options) {
|
3340
|
+
const logger$1 = getLogger([
|
3341
|
+
"fedify",
|
3342
|
+
"federation",
|
3343
|
+
"inbox"
|
3344
|
+
]);
|
3345
|
+
let keys;
|
3346
|
+
let identifier = null;
|
3347
|
+
if ("identifier" in forwarder || "username" in forwarder || "handle" in forwarder) {
|
3348
|
+
if ("identifier" in forwarder) identifier = forwarder.identifier;
|
3349
|
+
else {
|
3350
|
+
let username;
|
3351
|
+
if ("username" in forwarder) username = forwarder.username;
|
3352
|
+
else {
|
3353
|
+
username = forwarder.handle;
|
3354
|
+
logger$1.warn("The \"handle\" property for the forwarder parameter is deprecated; use \"identifier\" or \"username\" instead.", { forwarder });
|
3355
|
+
}
|
3356
|
+
if (this.federation.actorCallbacks?.handleMapper == null) identifier = username;
|
3357
|
+
else {
|
3358
|
+
const mapped = await this.federation.actorCallbacks.handleMapper(this, username);
|
3359
|
+
if (mapped == null) throw new Error(`No actor found for the given username ${JSON.stringify(username)}.`);
|
3360
|
+
identifier = mapped;
|
3361
|
+
}
|
3362
|
+
}
|
3363
|
+
keys = await this.getKeyPairsFromIdentifier(identifier);
|
3364
|
+
if (keys.length < 1) throw new Error(`No key pair found for actor ${JSON.stringify(identifier)}.`);
|
3365
|
+
} else if (Array.isArray(forwarder)) {
|
3366
|
+
if (forwarder.length < 1) throw new Error("The forwarder's key pairs are empty.");
|
3367
|
+
keys = forwarder;
|
3368
|
+
} else keys = [forwarder];
|
3369
|
+
if (!hasSignature(this.activity)) {
|
3370
|
+
let hasProof;
|
3371
|
+
try {
|
3372
|
+
const activity = await Activity.fromJsonLd(this.activity, this);
|
3373
|
+
hasProof = await activity.getProof() != null;
|
3374
|
+
} catch {
|
3375
|
+
hasProof = false;
|
3376
|
+
}
|
3377
|
+
if (!hasProof) {
|
3378
|
+
if (options?.skipIfUnsigned) return;
|
3379
|
+
logger$1.warn("The received activity {activityId} is not signed; even if it is forwarded to other servers as is, it may not be accepted by them due to the lack of a signature/proof.");
|
3380
|
+
}
|
3381
|
+
}
|
3382
|
+
if (recipients === "followers") {
|
3383
|
+
if (identifier == null) throw new Error("If recipients is \"followers\", forwarder must be an actor identifier or username.");
|
3384
|
+
const followers = [];
|
3385
|
+
for await (const recipient of this.getFollowers(identifier)) followers.push(recipient);
|
3386
|
+
recipients = followers;
|
3387
|
+
}
|
3388
|
+
const inboxes = extractInboxes({
|
3389
|
+
recipients: Array.isArray(recipients) ? recipients : [recipients],
|
3390
|
+
preferSharedInbox: options?.preferSharedInbox,
|
3391
|
+
excludeBaseUris: options?.excludeBaseUris
|
3392
|
+
});
|
3393
|
+
logger$1.debug("Forwarding activity {activityId} to inboxes:\n{inboxes}", {
|
3394
|
+
inboxes: globalThis.Object.keys(inboxes),
|
3395
|
+
activityId: this.activityId,
|
3396
|
+
activity: this.activity
|
3397
|
+
});
|
3398
|
+
if (options?.immediate || this.federation.outboxQueue == null) {
|
3399
|
+
if (options?.immediate) logger$1.debug("Forwarding activity immediately without queue since immediate option is set.");
|
3400
|
+
else logger$1.debug("Forwarding activity immediately without queue since queue is not set.");
|
3401
|
+
const promises = [];
|
3402
|
+
for (const inbox in inboxes) promises.push(sendActivity({
|
3403
|
+
keys,
|
3404
|
+
activity: this.activity,
|
3405
|
+
activityId: this.activityId,
|
3406
|
+
activityType: this.activityType,
|
3407
|
+
inbox: new URL(inbox),
|
3408
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
3409
|
+
tracerProvider: this.tracerProvider,
|
3410
|
+
specDeterminer: new KvSpecDeterminer(this.federation.kv, this.federation.kvPrefixes.httpMessageSignaturesSpec)
|
3411
|
+
}));
|
3412
|
+
await Promise.all(promises);
|
3413
|
+
return;
|
3414
|
+
}
|
3415
|
+
logger$1.debug("Enqueuing activity {activityId} to forward later.", {
|
3416
|
+
activityId: this.activityId,
|
3417
|
+
activity: this.activity
|
3418
|
+
});
|
3419
|
+
const keyJwkPairs = [];
|
3420
|
+
for (const { keyId, privateKey } of keys) {
|
3421
|
+
const privateKeyJwk = await exportJwk(privateKey);
|
3422
|
+
keyJwkPairs.push({
|
3423
|
+
keyId: keyId.href,
|
3424
|
+
privateKey: privateKeyJwk
|
3425
|
+
});
|
3426
|
+
}
|
3427
|
+
const carrier = {};
|
3428
|
+
propagation.inject(context.active(), carrier);
|
3429
|
+
const messages = [];
|
3430
|
+
for (const inbox in inboxes) {
|
3431
|
+
const message = {
|
3432
|
+
type: "outbox",
|
3433
|
+
id: crypto.randomUUID(),
|
3434
|
+
baseUrl: this.origin,
|
3435
|
+
keys: keyJwkPairs,
|
3436
|
+
activity: this.activity,
|
3437
|
+
activityId: this.activityId,
|
3438
|
+
activityType: this.activityType,
|
3439
|
+
inbox,
|
3440
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
3441
|
+
started: new Date().toISOString(),
|
3442
|
+
attempt: 0,
|
3443
|
+
headers: {},
|
3444
|
+
traceContext: carrier
|
3445
|
+
};
|
3446
|
+
messages.push(message);
|
3447
|
+
}
|
3448
|
+
const { outboxQueue } = this.federation;
|
3449
|
+
if (outboxQueue.enqueueMany == null) {
|
3450
|
+
const promises = messages.map((m) => outboxQueue.enqueue(m));
|
3451
|
+
const results = await Promise.allSettled(promises);
|
3452
|
+
const errors = results.filter((r) => r.status === "rejected").map((r) => r.reason);
|
3453
|
+
if (errors.length > 0) {
|
3454
|
+
logger$1.error("Failed to enqueue activity {activityId} to forward later:\n{errors}", {
|
3455
|
+
activityId: this.activityId,
|
3456
|
+
errors
|
3457
|
+
});
|
3458
|
+
if (errors.length > 1) throw new AggregateError(errors, `Failed to enqueue activity ${this.activityId} to forward later.`);
|
3459
|
+
throw errors[0];
|
3460
|
+
}
|
3461
|
+
} else try {
|
3462
|
+
await outboxQueue.enqueueMany(messages);
|
3463
|
+
} catch (error) {
|
3464
|
+
logger$1.error("Failed to enqueue activity {activityId} to forward later:\n{error}", {
|
3465
|
+
activityId: this.activityId,
|
3466
|
+
error
|
3467
|
+
});
|
3468
|
+
throw error;
|
3469
|
+
}
|
3470
|
+
}
|
3471
|
+
};
|
3472
|
+
var KvSpecDeterminer = class {
|
3473
|
+
kv;
|
3474
|
+
prefix;
|
3475
|
+
defaultSpec;
|
3476
|
+
constructor(kv, prefix, defaultSpec = "rfc9421") {
|
3477
|
+
this.kv = kv;
|
3478
|
+
this.prefix = prefix;
|
3479
|
+
this.defaultSpec = defaultSpec;
|
3480
|
+
}
|
3481
|
+
async determineSpec(origin) {
|
3482
|
+
return await this.kv.get([...this.prefix, origin]) ?? this.defaultSpec;
|
3483
|
+
}
|
3484
|
+
async rememberSpec(origin, spec) {
|
3485
|
+
await this.kv.set([...this.prefix, origin], spec);
|
3486
|
+
}
|
3487
|
+
};
|
3488
|
+
function notFound(_request) {
|
3489
|
+
return new Response("Not Found", { status: 404 });
|
3490
|
+
}
|
3491
|
+
function notAcceptable(_request) {
|
3492
|
+
return new Response("Not Acceptable", {
|
3493
|
+
status: 406,
|
3494
|
+
headers: { Vary: "Accept, Signature" }
|
3495
|
+
});
|
3496
|
+
}
|
3497
|
+
function unauthorized(_request) {
|
3498
|
+
return new Response("Unauthorized", {
|
3499
|
+
status: 401,
|
3500
|
+
headers: { Vary: "Accept, Signature" }
|
3501
|
+
});
|
3502
|
+
}
|
3503
|
+
/**
|
3504
|
+
* Generates or extracts a unique identifier for a request.
|
3505
|
+
*
|
3506
|
+
* This function first attempts to extract an existing request ID from standard
|
3507
|
+
* tracing headers. If none exists, it generates a new one. The ID format is:
|
3508
|
+
*
|
3509
|
+
* - If from headers, uses the existing ID.
|
3510
|
+
* - If generated, uses format `req_` followed by a base36 timestamp and
|
3511
|
+
* 6 random chars.
|
3512
|
+
*
|
3513
|
+
* @param request The incoming HTTP request.
|
3514
|
+
* @returns A string identifier unique to this request.
|
3515
|
+
*/
|
3516
|
+
function getRequestId(request) {
|
3517
|
+
const traceId = request.headers.get("X-Request-Id") || request.headers.get("X-Correlation-Id") || request.headers.get("Traceparent")?.split("-")[1];
|
3518
|
+
if (traceId != null) return traceId;
|
3519
|
+
const timestamp = Date.now().toString(36);
|
3520
|
+
const random = Math.random().toString(36).slice(2, 8);
|
3521
|
+
return `req_${timestamp}${random}`;
|
3522
|
+
}
|
3523
|
+
|
3524
|
+
//#endregion
|
3525
|
+
export { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, Router$1 as Router, RouterError, buildCollectionSynchronizationHeader, createExponentialBackoffPolicy, createFederation, createFederationBuilder, digest, respondWithObject, respondWithObjectIfAcceptable };
|