@fedify/botkit 0.5.0-dev.210 → 0.5.0-dev.225

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/bot-group.test.d.ts +2 -0
  2. package/dist/bot-group.test.js +220 -0
  3. package/dist/bot-group.test.js.map +1 -0
  4. package/dist/bot-impl.d.ts +132 -13
  5. package/dist/bot-impl.d.ts.map +1 -1
  6. package/dist/bot-impl.js +400 -178
  7. package/dist/bot-impl.js.map +1 -1
  8. package/dist/bot-impl.test.js +214 -76
  9. package/dist/bot-impl.test.js.map +1 -1
  10. package/dist/bot.d.ts +94 -48
  11. package/dist/bot.d.ts.map +1 -1
  12. package/dist/bot.js +2 -104
  13. package/dist/bot.js.map +1 -1
  14. package/dist/bot.test.js +59 -0
  15. package/dist/bot.test.js.map +1 -1
  16. package/dist/components/FollowButton.d.ts +5 -3
  17. package/dist/components/FollowButton.d.ts.map +1 -1
  18. package/dist/components/FollowButton.js +2 -2
  19. package/dist/components/FollowButton.js.map +1 -1
  20. package/dist/components/Follower.d.ts +2 -2
  21. package/dist/components/Layout.js +1 -1
  22. package/dist/components/Layout.js.map +1 -1
  23. package/dist/components/Message.d.ts +2 -2
  24. package/dist/deno.js +2 -1
  25. package/dist/deno.js.map +1 -1
  26. package/dist/follow-impl.test.js +3 -3
  27. package/dist/follow-impl.test.js.map +1 -1
  28. package/dist/instance-impl.d.ts +158 -0
  29. package/dist/instance-impl.d.ts.map +1 -0
  30. package/dist/instance-impl.js +603 -0
  31. package/dist/instance-impl.js.map +1 -0
  32. package/dist/instance-impl.test.d.ts +2 -0
  33. package/dist/instance-impl.test.js +103 -0
  34. package/dist/instance-impl.test.js.map +1 -0
  35. package/dist/instance-multi.test.d.ts +2 -0
  36. package/dist/instance-multi.test.js +151 -0
  37. package/dist/instance-multi.test.js.map +1 -0
  38. package/dist/instance-routing.test.d.ts +2 -0
  39. package/dist/instance-routing.test.js +367 -0
  40. package/dist/instance-routing.test.js.map +1 -0
  41. package/dist/instance.d.ts +318 -0
  42. package/dist/instance.d.ts.map +1 -0
  43. package/dist/instance.js +51 -0
  44. package/dist/instance.js.map +1 -0
  45. package/dist/message-impl.d.ts.map +1 -1
  46. package/dist/message-impl.js +17 -10
  47. package/dist/message-impl.js.map +1 -1
  48. package/dist/message-impl.test.js +43 -9
  49. package/dist/message-impl.test.js.map +1 -1
  50. package/dist/mod.d.ts +5 -3
  51. package/dist/mod.js +4 -2
  52. package/dist/pages.d.ts +12 -3
  53. package/dist/pages.d.ts.map +1 -1
  54. package/dist/pages.js +112 -41
  55. package/dist/pages.js.map +1 -1
  56. package/dist/pages.test.d.ts +2 -0
  57. package/dist/pages.test.js +170 -0
  58. package/dist/pages.test.js.map +1 -0
  59. package/dist/repository.d.ts +385 -138
  60. package/dist/repository.d.ts.map +1 -1
  61. package/dist/repository.js +595 -223
  62. package/dist/repository.js.map +1 -1
  63. package/dist/repository.test.js +564 -136
  64. package/dist/repository.test.js.map +1 -1
  65. package/dist/session-impl.d.ts.map +1 -1
  66. package/dist/session-impl.js +13 -4
  67. package/dist/session-impl.js.map +1 -1
  68. package/dist/session-impl.test.d.ts.map +1 -1
  69. package/dist/session-impl.test.js +9 -9
  70. package/dist/session-impl.test.js.map +1 -1
  71. package/dist/session.d.ts +8 -3
  72. package/dist/session.d.ts.map +1 -1
  73. package/dist/text.d.ts.map +1 -1
  74. package/dist/text.js +27 -10
  75. package/dist/text.js.map +1 -1
  76. package/dist/text.test.js +37 -2
  77. package/dist/text.test.js.map +1 -1
  78. package/dist/uri.d.ts +46 -0
  79. package/dist/uri.d.ts.map +1 -0
  80. package/dist/uri.js +64 -0
  81. package/dist/uri.js.map +1 -0
  82. package/dist/uri.test.d.ts +2 -0
  83. package/dist/uri.test.js +93 -0
  84. package/dist/uri.test.js.map +1 -0
  85. package/package.json +5 -1
package/dist/uri.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
2
+ Date.prototype.toTemporalInstant = toTemporalInstant;
3
+ import { Context } from "@fedify/fedify/federation";
4
+
5
+ //#region src/uri.d.ts
6
+
7
+ /**
8
+ * Rewrites a local object URI path in the legacy (pre-0.5) format, which did
9
+ * not carry the owning bot actor identifier, into the canonical format nested
10
+ * under the actor path.
11
+ *
12
+ * For example, `/ap/follow/123` becomes `/ap/actor/bot/follow/123` for the
13
+ * identifier `bot`.
14
+ * @param pathname The URL path to rewrite.
15
+ * @param identifier The identifier of the bot actor that owns the legacy
16
+ * objects.
17
+ * @returns The rewritten path, or `null` if the path is not in the legacy
18
+ * object URI format.
19
+ * @since 0.5.0
20
+ */
21
+ declare function rewriteLegacyObjectPath(pathname: string, identifier: string): string | null;
22
+ /**
23
+ * Parses a URI as a local ActivityPub resource, like
24
+ * {@link Context.parseUri}, but additionally recognizes local object URIs in
25
+ * the legacy (pre-0.5) format when a legacy bot actor identifier is
26
+ * configured.
27
+ *
28
+ * Remote servers may have stored object URIs generated by BotKit 0.4 or
29
+ * earlier and can send them back in later activities (e.g. `Accept`,
30
+ * `Undo`, `Like`, or replies), so failing to parse them would break
31
+ * long-lived interactions after an upgrade. Since legacy URIs carry no
32
+ * identifier, they can only be attributed to the single bot actor that
33
+ * predates the upgrade.
34
+ * @param ctx The Fedify context to parse the URI with.
35
+ * @param uri The URI to parse.
36
+ * @param legacyIdentifier The identifier of the bot actor that owns objects
37
+ * with legacy URIs, or `undefined` if the instance
38
+ * has no legacy objects.
39
+ * @returns The parse result, or `null` if the URI is not a local resource.
40
+ * @since 0.5.0
41
+ */
42
+ declare function parseLocalUri<TContextData>(ctx: Context<TContextData>, uri: URL | null, legacyIdentifier?: string): ReturnType<Context<TContextData>["parseUri"]>;
43
+ //# sourceMappingURL=uri.d.ts.map
44
+ //#endregion
45
+ export { parseLocalUri, rewriteLegacyObjectPath };
46
+ //# sourceMappingURL=uri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uri.d.ts","names":[],"sources":["../src/uri.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;AAsCA;AA6BA;;;;;;;AAIG,iBAjCa,uBAAA,CAiCb,QAAA,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,IAAA;AAAU;;;;;;;;;;;;;;;;;;;;iBAJG,iCACT,QAAQ,oBACR,wCAEJ,WAAW,QAAQ"}
package/dist/uri.js ADDED
@@ -0,0 +1,64 @@
1
+
2
+ import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
3
+ Date.prototype.toTemporalInstant = toTemporalInstant;
4
+
5
+ //#region src/uri.ts
6
+ /**
7
+ * The path pattern of local object URIs generated by BotKit 0.4 and earlier,
8
+ * which did not carry the owning bot actor identifier.
9
+ */
10
+ const legacyObjectPathPattern = /^\/ap\/(follow|create|article|chat-message|note|question|announce)\/([^/]+)$/;
11
+ /**
12
+ * Rewrites a local object URI path in the legacy (pre-0.5) format, which did
13
+ * not carry the owning bot actor identifier, into the canonical format nested
14
+ * under the actor path.
15
+ *
16
+ * For example, `/ap/follow/123` becomes `/ap/actor/bot/follow/123` for the
17
+ * identifier `bot`.
18
+ * @param pathname The URL path to rewrite.
19
+ * @param identifier The identifier of the bot actor that owns the legacy
20
+ * objects.
21
+ * @returns The rewritten path, or `null` if the path is not in the legacy
22
+ * object URI format.
23
+ * @since 0.5.0
24
+ */
25
+ function rewriteLegacyObjectPath(pathname, identifier) {
26
+ const match = legacyObjectPathPattern.exec(pathname);
27
+ if (match == null) return null;
28
+ return `/ap/actor/${encodeURIComponent(identifier)}/${match[1]}/${match[2]}`;
29
+ }
30
+ /**
31
+ * Parses a URI as a local ActivityPub resource, like
32
+ * {@link Context.parseUri}, but additionally recognizes local object URIs in
33
+ * the legacy (pre-0.5) format when a legacy bot actor identifier is
34
+ * configured.
35
+ *
36
+ * Remote servers may have stored object URIs generated by BotKit 0.4 or
37
+ * earlier and can send them back in later activities (e.g. `Accept`,
38
+ * `Undo`, `Like`, or replies), so failing to parse them would break
39
+ * long-lived interactions after an upgrade. Since legacy URIs carry no
40
+ * identifier, they can only be attributed to the single bot actor that
41
+ * predates the upgrade.
42
+ * @param ctx The Fedify context to parse the URI with.
43
+ * @param uri The URI to parse.
44
+ * @param legacyIdentifier The identifier of the bot actor that owns objects
45
+ * with legacy URIs, or `undefined` if the instance
46
+ * has no legacy objects.
47
+ * @returns The parse result, or `null` if the URI is not a local resource.
48
+ * @since 0.5.0
49
+ */
50
+ function parseLocalUri(ctx, uri, legacyIdentifier) {
51
+ if (uri == null) return null;
52
+ const parsed = ctx.parseUri(uri);
53
+ if (parsed != null) return parsed;
54
+ if (legacyIdentifier == null) return null;
55
+ const rewrittenPath = rewriteLegacyObjectPath(uri.pathname, legacyIdentifier);
56
+ if (rewrittenPath == null) return null;
57
+ const rewritten = new URL(uri.href);
58
+ rewritten.pathname = rewrittenPath;
59
+ return ctx.parseUri(rewritten);
60
+ }
61
+
62
+ //#endregion
63
+ export { parseLocalUri, rewriteLegacyObjectPath };
64
+ //# sourceMappingURL=uri.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uri.js","names":["pathname: string","identifier: string","ctx: Context<TContextData>","uri: URL | null","legacyIdentifier?: string"],"sources":["../src/uri.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025–2026 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport type { Context } from \"@fedify/fedify/federation\";\n\n/**\n * The path pattern of local object URIs generated by BotKit 0.4 and earlier,\n * which did not carry the owning bot actor identifier.\n */\nconst legacyObjectPathPattern =\n /^\\/ap\\/(follow|create|article|chat-message|note|question|announce)\\/([^/]+)$/;\n\n/**\n * Rewrites a local object URI path in the legacy (pre-0.5) format, which did\n * not carry the owning bot actor identifier, into the canonical format nested\n * under the actor path.\n *\n * For example, `/ap/follow/123` becomes `/ap/actor/bot/follow/123` for the\n * identifier `bot`.\n * @param pathname The URL path to rewrite.\n * @param identifier The identifier of the bot actor that owns the legacy\n * objects.\n * @returns The rewritten path, or `null` if the path is not in the legacy\n * object URI format.\n * @since 0.5.0\n */\nexport function rewriteLegacyObjectPath(\n pathname: string,\n identifier: string,\n): string | null {\n const match = legacyObjectPathPattern.exec(pathname);\n if (match == null) return null;\n return `/ap/actor/${encodeURIComponent(identifier)}/${match[1]}/${match[2]}`;\n}\n\n/**\n * Parses a URI as a local ActivityPub resource, like\n * {@link Context.parseUri}, but additionally recognizes local object URIs in\n * the legacy (pre-0.5) format when a legacy bot actor identifier is\n * configured.\n *\n * Remote servers may have stored object URIs generated by BotKit 0.4 or\n * earlier and can send them back in later activities (e.g. `Accept`,\n * `Undo`, `Like`, or replies), so failing to parse them would break\n * long-lived interactions after an upgrade. Since legacy URIs carry no\n * identifier, they can only be attributed to the single bot actor that\n * predates the upgrade.\n * @param ctx The Fedify context to parse the URI with.\n * @param uri The URI to parse.\n * @param legacyIdentifier The identifier of the bot actor that owns objects\n * with legacy URIs, or `undefined` if the instance\n * has no legacy objects.\n * @returns The parse result, or `null` if the URI is not a local resource.\n * @since 0.5.0\n */\nexport function parseLocalUri<TContextData>(\n ctx: Context<TContextData>,\n uri: URL | null,\n legacyIdentifier?: string,\n): ReturnType<Context<TContextData>[\"parseUri\"]> {\n if (uri == null) return null;\n const parsed = ctx.parseUri(uri);\n if (parsed != null) return parsed;\n if (legacyIdentifier == null) return null;\n const rewrittenPath = rewriteLegacyObjectPath(uri.pathname, legacyIdentifier);\n if (rewrittenPath == null) return null;\n const rewritten = new URL(uri.href);\n rewritten.pathname = rewrittenPath;\n return ctx.parseUri(rewritten);\n}\n"],"mappings":";;;;;;;;;AAqBA,MAAM,0BACJ;;;;;;;;;;;;;;;AAgBF,SAAgB,wBACdA,UACAC,YACe;CACf,MAAM,QAAQ,wBAAwB,KAAK,SAAS;AACpD,KAAI,SAAS,KAAM,QAAO;AAC1B,SAAQ,YAAY,mBAAmB,WAAW,CAAC,GAAG,MAAM,GAAG,GAAG,MAAM,GAAG;AAC5E;;;;;;;;;;;;;;;;;;;;;AAsBD,SAAgB,cACdC,KACAC,KACAC,kBAC+C;AAC/C,KAAI,OAAO,KAAM,QAAO;CACxB,MAAM,SAAS,IAAI,SAAS,IAAI;AAChC,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,oBAAoB,KAAM,QAAO;CACrC,MAAM,gBAAgB,wBAAwB,IAAI,UAAU,iBAAiB;AAC7E,KAAI,iBAAiB,KAAM,QAAO;CAClC,MAAM,YAAY,IAAI,IAAI,IAAI;AAC9B,WAAU,WAAW;AACrB,QAAO,IAAI,SAAS,UAAU;AAC/B"}
@@ -0,0 +1,2 @@
1
+ import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
2
+ Date.prototype.toTemporalInstant = toTemporalInstant;
@@ -0,0 +1,93 @@
1
+
2
+ import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
3
+ Date.prototype.toTemporalInstant = toTemporalInstant;
4
+
5
+ import { parseLocalUri, rewriteLegacyObjectPath } from "./uri.js";
6
+ import { BotImpl } from "./bot-impl.js";
7
+ import { MemoryKvStore } from "@fedify/fedify/federation";
8
+ import { Announce, Article, ChatMessage, Create, Follow, Note, Question } from "@fedify/vocab";
9
+ import assert from "node:assert";
10
+ import { describe, test } from "node:test";
11
+
12
+ //#region src/uri.test.ts
13
+ describe("rewriteLegacyObjectPath()", () => {
14
+ test("rewrites legacy object paths", () => {
15
+ assert.deepStrictEqual(rewriteLegacyObjectPath("/ap/follow/03a395a2-353a-4894-afdb-2cab31a7b004", "bot"), "/ap/actor/bot/follow/03a395a2-353a-4894-afdb-2cab31a7b004");
16
+ for (const type of [
17
+ "follow",
18
+ "create",
19
+ "article",
20
+ "chat-message",
21
+ "note",
22
+ "question",
23
+ "announce"
24
+ ]) assert.deepStrictEqual(rewriteLegacyObjectPath(`/ap/${type}/123`, "my-bot"), `/ap/actor/my-bot/${type}/123`);
25
+ });
26
+ test("percent-encodes the identifier", () => {
27
+ assert.deepStrictEqual(rewriteLegacyObjectPath("/ap/note/123", "b/t"), "/ap/actor/b%2Ft/note/123");
28
+ });
29
+ test("returns null for non-legacy paths", () => {
30
+ assert.deepStrictEqual(rewriteLegacyObjectPath("/ap/actor/bot", "bot"), null);
31
+ assert.deepStrictEqual(rewriteLegacyObjectPath("/ap/actor/bot/note/123", "bot"), null);
32
+ assert.deepStrictEqual(rewriteLegacyObjectPath("/ap/emoji/wave", "bot"), null);
33
+ assert.deepStrictEqual(rewriteLegacyObjectPath("/ap/inbox", "bot"), null);
34
+ assert.deepStrictEqual(rewriteLegacyObjectPath("/message/123", "bot"), null);
35
+ assert.deepStrictEqual(rewriteLegacyObjectPath("/ap/note/123/extra", "bot"), null);
36
+ });
37
+ });
38
+ describe("parseLocalUri()", () => {
39
+ const bot = new BotImpl({
40
+ kv: new MemoryKvStore(),
41
+ username: "bot"
42
+ });
43
+ const ctx = bot.federation.createContext(new URL("https://example.com/"));
44
+ test("behaves like Context.parseUri() for canonical URIs", () => {
45
+ const actorUri = new URL("https://example.com/ap/actor/bot");
46
+ assert.deepStrictEqual(parseLocalUri(ctx, actorUri, "bot"), ctx.parseUri(actorUri));
47
+ const noteUri = new URL("https://example.com/ap/actor/bot/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0");
48
+ const parsed = parseLocalUri(ctx, noteUri, "bot");
49
+ assert.ok(parsed != null);
50
+ assert.deepStrictEqual(parsed.type, "object");
51
+ assert.ok(parsed.type === "object");
52
+ assert.deepStrictEqual(parsed.class, Note);
53
+ assert.deepStrictEqual(parsed.values, {
54
+ identifier: "bot",
55
+ id: "01941f29-7c00-7fe8-ab0a-7b593990a3c0"
56
+ });
57
+ });
58
+ test("recognizes legacy object URIs when a legacy identifier is given", () => {
59
+ const classes = {
60
+ follow: Follow,
61
+ create: Create,
62
+ article: Article,
63
+ "chat-message": ChatMessage,
64
+ note: Note,
65
+ question: Question,
66
+ announce: Announce
67
+ };
68
+ for (const [type, cls] of Object.entries(classes)) {
69
+ const legacyUri = new URL(`https://example.com/ap/${type}/01941f29-7c00-7fe8-ab0a-7b593990a3c0`);
70
+ const parsed = parseLocalUri(ctx, legacyUri, "bot");
71
+ assert.ok(parsed != null, `legacy ${type} URI should parse`);
72
+ assert.deepStrictEqual(parsed.type, "object");
73
+ assert.ok(parsed.type === "object");
74
+ assert.deepStrictEqual(parsed.class, cls);
75
+ assert.deepStrictEqual(parsed.values, {
76
+ identifier: "bot",
77
+ id: "01941f29-7c00-7fe8-ab0a-7b593990a3c0"
78
+ });
79
+ }
80
+ });
81
+ test("does not recognize legacy URIs without a legacy identifier", () => {
82
+ const legacyUri = new URL("https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0");
83
+ assert.deepStrictEqual(parseLocalUri(ctx, legacyUri), null);
84
+ });
85
+ test("returns null for null and foreign URIs", () => {
86
+ assert.deepStrictEqual(parseLocalUri(ctx, null, "bot"), null);
87
+ assert.deepStrictEqual(parseLocalUri(ctx, new URL("https://other.example/ap/note/123"), "bot"), null);
88
+ assert.deepStrictEqual(parseLocalUri(ctx, new URL("https://example.com/unrelated"), "bot"), null);
89
+ });
90
+ });
91
+
92
+ //#endregion
93
+ //# sourceMappingURL=uri.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uri.test.js","names":[],"sources":["../src/uri.test.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025–2026 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport { MemoryKvStore } from \"@fedify/fedify/federation\";\nimport {\n Announce,\n Article,\n ChatMessage,\n Create,\n Follow,\n Note,\n Question,\n} from \"@fedify/vocab\";\nimport assert from \"node:assert\";\nimport { describe, test } from \"node:test\";\nimport { BotImpl } from \"./bot-impl.ts\";\nimport { parseLocalUri, rewriteLegacyObjectPath } from \"./uri.ts\";\n\ndescribe(\"rewriteLegacyObjectPath()\", () => {\n test(\"rewrites legacy object paths\", () => {\n assert.deepStrictEqual(\n rewriteLegacyObjectPath(\n \"/ap/follow/03a395a2-353a-4894-afdb-2cab31a7b004\",\n \"bot\",\n ),\n \"/ap/actor/bot/follow/03a395a2-353a-4894-afdb-2cab31a7b004\",\n );\n for (\n const type of [\n \"follow\",\n \"create\",\n \"article\",\n \"chat-message\",\n \"note\",\n \"question\",\n \"announce\",\n ]\n ) {\n assert.deepStrictEqual(\n rewriteLegacyObjectPath(`/ap/${type}/123`, \"my-bot\"),\n `/ap/actor/my-bot/${type}/123`,\n );\n }\n });\n\n test(\"percent-encodes the identifier\", () => {\n assert.deepStrictEqual(\n rewriteLegacyObjectPath(\"/ap/note/123\", \"b/t\"),\n \"/ap/actor/b%2Ft/note/123\",\n );\n });\n\n test(\"returns null for non-legacy paths\", () => {\n assert.deepStrictEqual(\n rewriteLegacyObjectPath(\"/ap/actor/bot\", \"bot\"),\n null,\n );\n assert.deepStrictEqual(\n rewriteLegacyObjectPath(\"/ap/actor/bot/note/123\", \"bot\"),\n null,\n );\n assert.deepStrictEqual(\n rewriteLegacyObjectPath(\"/ap/emoji/wave\", \"bot\"),\n null,\n );\n assert.deepStrictEqual(rewriteLegacyObjectPath(\"/ap/inbox\", \"bot\"), null);\n assert.deepStrictEqual(\n rewriteLegacyObjectPath(\"/message/123\", \"bot\"),\n null,\n );\n assert.deepStrictEqual(\n rewriteLegacyObjectPath(\"/ap/note/123/extra\", \"bot\"),\n null,\n );\n });\n});\n\ndescribe(\"parseLocalUri()\", () => {\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n username: \"bot\",\n });\n const ctx = bot.federation.createContext(new URL(\"https://example.com/\"));\n\n test(\"behaves like Context.parseUri() for canonical URIs\", () => {\n const actorUri = new URL(\"https://example.com/ap/actor/bot\");\n assert.deepStrictEqual(\n parseLocalUri(ctx, actorUri, \"bot\"),\n ctx.parseUri(actorUri),\n );\n const noteUri = new URL(\n \"https://example.com/ap/actor/bot/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n );\n const parsed = parseLocalUri(ctx, noteUri, \"bot\");\n assert.ok(parsed != null);\n assert.deepStrictEqual(parsed.type, \"object\");\n assert.ok(parsed.type === \"object\");\n assert.deepStrictEqual(parsed.class, Note);\n assert.deepStrictEqual(parsed.values, {\n identifier: \"bot\",\n id: \"01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n });\n });\n\n test(\"recognizes legacy object URIs when a legacy identifier is given\", () => {\n const classes = {\n follow: Follow,\n create: Create,\n article: Article,\n \"chat-message\": ChatMessage,\n note: Note,\n question: Question,\n announce: Announce,\n } as const;\n for (const [type, cls] of Object.entries(classes)) {\n const legacyUri = new URL(\n `https://example.com/ap/${type}/01941f29-7c00-7fe8-ab0a-7b593990a3c0`,\n );\n const parsed = parseLocalUri(ctx, legacyUri, \"bot\");\n assert.ok(parsed != null, `legacy ${type} URI should parse`);\n assert.deepStrictEqual(parsed.type, \"object\");\n assert.ok(parsed.type === \"object\");\n assert.deepStrictEqual(parsed.class, cls);\n assert.deepStrictEqual(parsed.values, {\n identifier: \"bot\",\n id: \"01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n });\n }\n });\n\n test(\"does not recognize legacy URIs without a legacy identifier\", () => {\n const legacyUri = new URL(\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n );\n assert.deepStrictEqual(parseLocalUri(ctx, legacyUri), null);\n });\n\n test(\"returns null for null and foreign URIs\", () => {\n assert.deepStrictEqual(parseLocalUri(ctx, null, \"bot\"), null);\n assert.deepStrictEqual(\n parseLocalUri(\n ctx,\n new URL(\"https://other.example/ap/note/123\"),\n \"bot\",\n ),\n null,\n );\n assert.deepStrictEqual(\n parseLocalUri(ctx, new URL(\"https://example.com/unrelated\"), \"bot\"),\n null,\n );\n });\n});\n"],"mappings":";;;;;;;;;;;;AA8BA,SAAS,6BAA6B,MAAM;AAC1C,MAAK,gCAAgC,MAAM;AACzC,SAAO,gBACL,wBACE,mDACA,MACD,EACD,4DACD;AACD,OACE,MAAM,QAAQ;GACZ;GACA;GACA;GACA;GACA;GACA;GACA;EACD,EAED,QAAO,gBACL,yBAAyB,MAAM,KAAK,OAAO,SAAS,GACnD,mBAAmB,KAAK,MAC1B;CAEJ,EAAC;AAEF,MAAK,kCAAkC,MAAM;AAC3C,SAAO,gBACL,wBAAwB,gBAAgB,MAAM,EAC9C,2BACD;CACF,EAAC;AAEF,MAAK,qCAAqC,MAAM;AAC9C,SAAO,gBACL,wBAAwB,iBAAiB,MAAM,EAC/C,KACD;AACD,SAAO,gBACL,wBAAwB,0BAA0B,MAAM,EACxD,KACD;AACD,SAAO,gBACL,wBAAwB,kBAAkB,MAAM,EAChD,KACD;AACD,SAAO,gBAAgB,wBAAwB,aAAa,MAAM,EAAE,KAAK;AACzE,SAAO,gBACL,wBAAwB,gBAAgB,MAAM,EAC9C,KACD;AACD,SAAO,gBACL,wBAAwB,sBAAsB,MAAM,EACpD,KACD;CACF,EAAC;AACH,EAAC;AAEF,SAAS,mBAAmB,MAAM;CAChC,MAAM,MAAM,IAAI,QAAc;EAC5B,IAAI,IAAI;EACR,UAAU;CACX;CACD,MAAM,MAAM,IAAI,WAAW,cAAc,IAAI,IAAI,wBAAwB;AAEzE,MAAK,sDAAsD,MAAM;EAC/D,MAAM,WAAW,IAAI,IAAI;AACzB,SAAO,gBACL,cAAc,KAAK,UAAU,MAAM,EACnC,IAAI,SAAS,SAAS,CACvB;EACD,MAAM,UAAU,IAAI,IAClB;EAEF,MAAM,SAAS,cAAc,KAAK,SAAS,MAAM;AACjD,SAAO,GAAG,UAAU,KAAK;AACzB,SAAO,gBAAgB,OAAO,MAAM,SAAS;AAC7C,SAAO,GAAG,OAAO,SAAS,SAAS;AACnC,SAAO,gBAAgB,OAAO,OAAO,KAAK;AAC1C,SAAO,gBAAgB,OAAO,QAAQ;GACpC,YAAY;GACZ,IAAI;EACL,EAAC;CACH,EAAC;AAEF,MAAK,mEAAmE,MAAM;EAC5E,MAAM,UAAU;GACd,QAAQ;GACR,QAAQ;GACR,SAAS;GACT,gBAAgB;GAChB,MAAM;GACN,UAAU;GACV,UAAU;EACX;AACD,OAAK,MAAM,CAAC,MAAM,IAAI,IAAI,OAAO,QAAQ,QAAQ,EAAE;GACjD,MAAM,YAAY,IAAI,KACnB,yBAAyB,KAAK;GAEjC,MAAM,SAAS,cAAc,KAAK,WAAW,MAAM;AACnD,UAAO,GAAG,UAAU,OAAO,SAAS,KAAK,mBAAmB;AAC5D,UAAO,gBAAgB,OAAO,MAAM,SAAS;AAC7C,UAAO,GAAG,OAAO,SAAS,SAAS;AACnC,UAAO,gBAAgB,OAAO,OAAO,IAAI;AACzC,UAAO,gBAAgB,OAAO,QAAQ;IACpC,YAAY;IACZ,IAAI;GACL,EAAC;EACH;CACF,EAAC;AAEF,MAAK,8DAA8D,MAAM;EACvE,MAAM,YAAY,IAAI,IACpB;AAEF,SAAO,gBAAgB,cAAc,KAAK,UAAU,EAAE,KAAK;CAC5D,EAAC;AAEF,MAAK,0CAA0C,MAAM;AACnD,SAAO,gBAAgB,cAAc,KAAK,MAAM,MAAM,EAAE,KAAK;AAC7D,SAAO,gBACL,cACE,KACA,IAAI,IAAI,sCACR,MACD,EACD,KACD;AACD,SAAO,gBACL,cAAc,KAAK,IAAI,IAAI,kCAAkC,MAAM,EACnE,KACD;CACF,EAAC;AACH,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/botkit",
3
- "version": "0.5.0-dev.210",
3
+ "version": "0.5.0-dev.225",
4
4
  "description": "A framework for creating ActivityPub bots",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": {
@@ -50,6 +50,10 @@
50
50
  "types": "./dist/follow.d.ts",
51
51
  "import": "./dist/follow.js"
52
52
  },
53
+ "./instance": {
54
+ "types": "./dist/instance.d.ts",
55
+ "import": "./dist/instance.js"
56
+ },
53
57
  "./message": {
54
58
  "types": "./dist/message.d.ts",
55
59
  "import": "./dist/message.js"