applesauce-actions 0.0.0-next-20250723224513 → 0.0.0-next-20250725170333

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 (36) hide show
  1. package/dist/action-hub.d.ts +1 -4
  2. package/dist/actions/blocked-relays.js +1 -1
  3. package/dist/actions/blossom.js +1 -1
  4. package/dist/actions/bookmarks.js +2 -2
  5. package/dist/actions/calendar.d.ts +1 -1
  6. package/dist/actions/calendar.js +4 -4
  7. package/dist/actions/contacts.js +1 -1
  8. package/dist/actions/dm-relays.js +1 -1
  9. package/dist/actions/favorite-relays.js +1 -1
  10. package/dist/actions/follow-sets.js +3 -3
  11. package/dist/actions/lists.js +2 -2
  12. package/dist/actions/mailboxes.js +1 -1
  13. package/dist/actions/pins.js +1 -1
  14. package/dist/actions/profile.js +3 -3
  15. package/dist/actions/relay-sets.js +3 -3
  16. package/dist/actions/search-relays.js +1 -1
  17. package/dist/actions/wrapped-messages.d.ts +1 -1
  18. package/package.json +4 -4
  19. package/dist/__tests__/action-hub.test.d.ts +0 -1
  20. package/dist/__tests__/action-hub.test.js +0 -67
  21. package/dist/__tests__/exports.test.d.ts +0 -1
  22. package/dist/__tests__/exports.test.js +0 -12
  23. package/dist/__tests__/fake-user.d.ts +0 -10
  24. package/dist/__tests__/fake-user.js +0 -32
  25. package/dist/actions/__tests__/blossom.test.d.ts +0 -1
  26. package/dist/actions/__tests__/blossom.test.js +0 -93
  27. package/dist/actions/__tests__/bookmarks.test.d.ts +0 -1
  28. package/dist/actions/__tests__/bookmarks.test.js +0 -24
  29. package/dist/actions/__tests__/contacts.test.d.ts +0 -1
  30. package/dist/actions/__tests__/contacts.test.js +0 -53
  31. package/dist/actions/__tests__/exports.test.d.ts +0 -1
  32. package/dist/actions/__tests__/exports.test.js +0 -62
  33. package/dist/actions/__tests__/follow-sets.test.d.ts +0 -1
  34. package/dist/actions/__tests__/follow-sets.test.js +0 -80
  35. package/dist/actions/__tests__/mute.test.d.ts +0 -1
  36. package/dist/actions/__tests__/mute.test.js +0 -67
@@ -2,10 +2,7 @@ import { Observable } from "rxjs";
2
2
  import { NostrEvent } from "nostr-tools";
3
3
  import { EventFactory } from "applesauce-factory";
4
4
  import { IEventStoreActions, IEventStoreRead } from "applesauce-core";
5
- /**
6
- * A callback used to tell the upstream app to publish an event
7
- * @param label a label describing what
8
- */
5
+ /** A callback used to tell the upstream app to publish an event */
9
6
  export type PublishMethod = (event: NostrEvent) => void | Promise<void>;
10
7
  /** The context that is passed to actions for them to use to preform actions */
11
8
  export type ActionContext = {
@@ -1,4 +1,4 @@
1
- import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations/event";
1
+ import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations";
2
2
  import { addRelayTag, removeRelayTag } from "applesauce-factory/operations/tag/relay";
3
3
  import { kinds } from "nostr-tools";
4
4
  function getBlockedRelaysEvent(events, self) {
@@ -1,5 +1,5 @@
1
1
  import { BLOSSOM_SERVER_LIST_KIND } from "applesauce-core/helpers/blossom";
2
- import { modifyPublicTags, modifyTags } from "applesauce-factory/operations/event";
2
+ import { modifyPublicTags, modifyTags } from "applesauce-factory/operations";
3
3
  import { addBlossomServerTag, removeBlossomServerTag } from "applesauce-factory/operations/tag/blossom";
4
4
  /** An action that adds a server to the Blossom servers event */
5
5
  export function AddBlossomServer(server) {
@@ -1,4 +1,4 @@
1
- import { modifyHiddenTags, modifyPublicTags, setListDescription, setListImage, setListTitle, } from "applesauce-factory/operations/event";
1
+ import { modifyHiddenTags, modifyPublicTags, List } from "applesauce-factory/operations";
2
2
  import { addEventBookmarkTag, removeEventBookmarkTag } from "applesauce-factory/operations/tag";
3
3
  import { kinds } from "nostr-tools";
4
4
  /**
@@ -76,7 +76,7 @@ export function CreateBookmarkList(bookmarks) {
76
76
  /** An action that creates a new bookmark set for a user */
77
77
  export function CreateBookmarkSet(title, description, additional) {
78
78
  return async function* ({ factory }) {
79
- const draft = await factory.build({ kind: kinds.BookmarkList }, setListTitle(title), setListDescription(description), additional.image ? setListImage(additional.image) : undefined, additional.public ? modifyPublicTags(...additional.public.map(addEventBookmarkTag)) : undefined, additional.hidden ? modifyHiddenTags(...additional.hidden.map(addEventBookmarkTag)) : undefined);
79
+ const draft = await factory.build({ kind: kinds.BookmarkList }, List.setTitle(title), List.setDescription(description), additional.image ? List.setImage(additional.image) : undefined, additional.public ? modifyPublicTags(...additional.public.map(addEventBookmarkTag)) : undefined, additional.hidden ? modifyHiddenTags(...additional.hidden.map(addEventBookmarkTag)) : undefined);
80
80
  yield await factory.sign(draft);
81
81
  };
82
82
  }
@@ -3,4 +3,4 @@ import { Action } from "../action-hub.js";
3
3
  /** Adds a calendar event to a calendar */
4
4
  export declare function AddEventToCalendar(calendar: NostrEvent, event: NostrEvent): Action;
5
5
  /** Removes a calendar event from a calendar */
6
- export declare function RemoveEventToCalendar(calendar: NostrEvent, event: NostrEvent): Action;
6
+ export declare function RemoveEventFromCalendar(calendar: NostrEvent, event: NostrEvent): Action;
@@ -1,5 +1,5 @@
1
1
  import { DATE_BASED_CALENDAR_EVENT_KIND, TIME_BASED_CALENDAR_EVENT_KIND } from "applesauce-core/helpers/calendar-event";
2
- import { calendarAddEvent, calendarRemoveEvent } from "applesauce-factory/operations/event";
2
+ import { Calendar } from "applesauce-factory/operations";
3
3
  import { kinds } from "nostr-tools";
4
4
  /** Adds a calendar event to a calendar */
5
5
  export function AddEventToCalendar(calendar, event) {
@@ -8,18 +8,18 @@ export function AddEventToCalendar(calendar, event) {
8
8
  if (event.kind !== DATE_BASED_CALENDAR_EVENT_KIND && event.kind !== TIME_BASED_CALENDAR_EVENT_KIND)
9
9
  throw new Error("Event is not a calendar event");
10
10
  return async function* ({ factory }) {
11
- const draft = await factory.modify(calendar, calendarAddEvent(event));
11
+ const draft = await factory.modify(calendar, Calendar.addEvent(event));
12
12
  return await factory.sign(draft);
13
13
  };
14
14
  }
15
15
  /** Removes a calendar event from a calendar */
16
- export function RemoveEventToCalendar(calendar, event) {
16
+ export function RemoveEventFromCalendar(calendar, event) {
17
17
  if (calendar.kind !== kinds.Calendar)
18
18
  throw new Error("Calendar is not a calendar event");
19
19
  if (event.kind !== DATE_BASED_CALENDAR_EVENT_KIND && event.kind !== TIME_BASED_CALENDAR_EVENT_KIND)
20
20
  throw new Error("Event is not a calendar event");
21
21
  return async function* ({ factory }) {
22
- const draft = await factory.modify(calendar, calendarRemoveEvent(event));
22
+ const draft = await factory.modify(calendar, Calendar.removeEvent(event));
23
23
  return await factory.sign(draft);
24
24
  };
25
25
  }
@@ -1,4 +1,4 @@
1
- import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations/event";
1
+ import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations";
2
2
  import { addPubkeyTag, removePubkeyTag } from "applesauce-factory/operations/tag";
3
3
  import { kinds } from "nostr-tools";
4
4
  /** An action that adds a pubkey to a users contacts event */
@@ -1,4 +1,4 @@
1
- import { modifyPublicTags } from "applesauce-factory/operations/event";
1
+ import { modifyPublicTags } from "applesauce-factory/operations";
2
2
  import { addRelayTag, removeRelayTag } from "applesauce-factory/operations/tag/relay";
3
3
  import { kinds } from "nostr-tools";
4
4
  function getDMRelaysEvent(events, self) {
@@ -1,5 +1,5 @@
1
1
  import { FAVORITE_RELAYS_KIND } from "applesauce-core/helpers/lists";
2
- import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations/event";
2
+ import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations";
3
3
  import { addAddressTag, addRelayTag, removeAddressTag, removeRelayTag } from "applesauce-factory/operations/tag";
4
4
  function getFavoriteRelaysEvent(events, self) {
5
5
  const event = events.getReplaceable(FAVORITE_RELAYS_KIND, self);
@@ -1,4 +1,4 @@
1
- import { modifyHiddenTags, modifyPublicTags, setListDescription, setListImage, setListTitle, } from "applesauce-factory/operations/event";
1
+ import { modifyHiddenTags, modifyPublicTags, List } from "applesauce-factory/operations";
2
2
  import { addPubkeyTag, removePubkeyTag } from "applesauce-factory/operations/tag";
3
3
  import { kinds } from "nostr-tools";
4
4
  function getFollowSetEvent(events, self, identifier) {
@@ -17,7 +17,7 @@ export function CreateFollowSet(title, options) {
17
17
  return async function* ({ factory }) {
18
18
  const draft = await factory.build({ kind: kinds.Followsets },
19
19
  // set list information
20
- setListTitle(title), options?.description ? setListDescription(options.description) : undefined, options?.image ? setListImage(options.image) : undefined,
20
+ List.setTitle(title), options?.description ? List.setDescription(options.description) : undefined, options?.image ? List.setImage(options.image) : undefined,
21
21
  // add pubkey tags
22
22
  options?.public ? modifyPublicTags(...options.public.map((p) => addPubkeyTag(p))) : undefined, options?.hidden ? modifyHiddenTags(...options.hidden.map((p) => addPubkeyTag(p))) : undefined);
23
23
  yield await factory.sign(draft);
@@ -62,7 +62,7 @@ export function RemoveUserFromFollowSet(pubkey, identifier, hidden = false) {
62
62
  export function UpdateFollowSetInformation(identifier, info) {
63
63
  return async function* ({ events, factory, self }) {
64
64
  const follows = getFollowSetEvent(events, self, identifier);
65
- const draft = await factory.modify(follows, info?.title ? setListTitle(info.title) : undefined, info?.description ? setListDescription(info.description) : undefined, info?.image ? setListImage(info.image) : undefined);
65
+ const draft = await factory.modify(follows, info?.title ? List.setTitle(info.title) : undefined, info?.description ? List.setDescription(info.description) : undefined, info?.image ? List.setImage(info.image) : undefined);
66
66
  yield await factory.sign(draft);
67
67
  };
68
68
  }
@@ -1,5 +1,5 @@
1
1
  import { isAddressPointer } from "applesauce-core/helpers";
2
- import { setListDescription, setListImage, setListTitle } from "applesauce-factory/operations/event";
2
+ import { List } from "applesauce-factory/operations";
3
3
  function getList(events, address) {
4
4
  const list = isAddressPointer(address)
5
5
  ? events.getReplaceable(address.kind, address.pubkey, address.identifier)
@@ -12,7 +12,7 @@ function getList(events, address) {
12
12
  export function SetListMetadata(list, info) {
13
13
  return async function* ({ events, factory }) {
14
14
  list = getList(events, list);
15
- const draft = await factory.modify(list, setListTitle(info.title ?? null), setListDescription(info.description ?? null), setListImage(info.image ?? null));
15
+ const draft = await factory.modify(list, List.setTitle(info.title ?? null), List.setDescription(info.description ?? null), List.setImage(info.image ?? null));
16
16
  yield await factory.sign(draft);
17
17
  };
18
18
  }
@@ -1,6 +1,6 @@
1
1
  import { kinds } from "nostr-tools";
2
2
  import { addInboxRelay, addOutboxRelay, removeInboxRelay, removeOutboxRelay } from "applesauce-factory/operations/tag";
3
- import { modifyPublicTags } from "applesauce-factory/operations/event";
3
+ import { modifyPublicTags } from "applesauce-factory/operations";
4
4
  /** An action to create a new kind 10002 relay list event */
5
5
  export function CreateMailboxes(inboxes, outboxes) {
6
6
  return async function* ({ events, factory, self }) {
@@ -1,5 +1,5 @@
1
1
  import { getReplaceableAddress, isReplaceable } from "applesauce-core/helpers";
2
- import { modifyPublicTags } from "applesauce-factory/operations/event";
2
+ import { modifyPublicTags } from "applesauce-factory/operations";
3
3
  import { addAddressTag, addEventTag, removeAddressTag, removeEventTag } from "applesauce-factory/operations/tag";
4
4
  import { kinds } from "nostr-tools";
5
5
  export const ALLOWED_PIN_KINDS = [kinds.ShortTextNote, kinds.LongFormArticle];
@@ -1,12 +1,12 @@
1
1
  import { kinds } from "nostr-tools";
2
- import { setProfileContent, updateProfileContent } from "applesauce-factory/operations/event";
2
+ import { Profile } from "applesauce-factory/operations";
3
3
  /** An action that creates a new kind 0 profile event for a user */
4
4
  export function CreateProfile(content) {
5
5
  return async function* ({ events, factory, self }) {
6
6
  const metadata = events.getReplaceable(kinds.Metadata, self);
7
7
  if (metadata)
8
8
  throw new Error("Profile already exists");
9
- const draft = await factory.build({ kind: kinds.Metadata }, setProfileContent(content));
9
+ const draft = await factory.build({ kind: kinds.Metadata }, Profile.setProfile(content));
10
10
  yield await factory.sign(draft);
11
11
  };
12
12
  }
@@ -16,7 +16,7 @@ export function UpdateProfile(content) {
16
16
  const metadata = events.getReplaceable(kinds.Metadata, self);
17
17
  if (!metadata)
18
18
  throw new Error("Profile does not exists");
19
- const draft = await factory.modify(metadata, updateProfileContent(content));
19
+ const draft = await factory.modify(metadata, Profile.updateProfile(content));
20
20
  yield await factory.sign(draft);
21
21
  };
22
22
  }
@@ -1,4 +1,4 @@
1
- import { modifyHiddenTags, modifyPublicTags, setListDescription, setListImage, setListTitle, } from "applesauce-factory/operations/event";
1
+ import { modifyHiddenTags, modifyPublicTags, List } from "applesauce-factory/operations";
2
2
  import { addRelayTag, removeRelayTag } from "applesauce-factory/operations/tag";
3
3
  import { kinds } from "nostr-tools";
4
4
  function getRelaySetEvent(events, self, identifier) {
@@ -30,7 +30,7 @@ export function RemoveRelayFromRelaySet(relay, identifier, hidden = false) {
30
30
  /** An action that creates a new relay set */
31
31
  export function CreateRelaySet(title, options) {
32
32
  return async function* ({ factory }) {
33
- const draft = await factory.build({ kind: kinds.Relaysets }, setListTitle(title), options?.description ? setListDescription(options.description) : undefined, options?.image ? setListImage(options.image) : undefined, options?.public ? modifyPublicTags(...options.public.map((r) => addRelayTag(r))) : undefined, options?.hidden ? modifyHiddenTags(...options.hidden.map((r) => addRelayTag(r))) : undefined);
33
+ const draft = await factory.build({ kind: kinds.Relaysets }, List.setTitle(title), options?.description ? List.setDescription(options.description) : undefined, options?.image ? List.setImage(options.image) : undefined, options?.public ? modifyPublicTags(...options.public.map((r) => addRelayTag(r))) : undefined, options?.hidden ? modifyHiddenTags(...options.hidden.map((r) => addRelayTag(r))) : undefined);
34
34
  yield await factory.sign(draft);
35
35
  };
36
36
  }
@@ -38,7 +38,7 @@ export function CreateRelaySet(title, options) {
38
38
  export function UpdateRelaySetInformation(identifier, info) {
39
39
  return async function* ({ events, factory, self }) {
40
40
  const relays = getRelaySetEvent(events, self, identifier);
41
- const draft = await factory.modify(relays, info?.title ? setListTitle(info.title) : undefined, info?.description ? setListDescription(info.description) : undefined, info?.image ? setListImage(info.image) : undefined);
41
+ const draft = await factory.modify(relays, info?.title ? List.setTitle(info.title) : undefined, info?.description ? List.setDescription(info.description) : undefined, info?.image ? List.setImage(info.image) : undefined);
42
42
  yield await factory.sign(draft);
43
43
  };
44
44
  }
@@ -1,4 +1,4 @@
1
- import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations/event";
1
+ import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations";
2
2
  import { addRelayTag, removeRelayTag } from "applesauce-factory/operations/tag/relay";
3
3
  import { kinds } from "nostr-tools";
4
4
  function getSearchRelaysEvent(events, self) {
@@ -1,6 +1,6 @@
1
1
  import { Rumor } from "applesauce-core/helpers";
2
2
  import { WrappedMessageBlueprintOptions } from "applesauce-factory/blueprints";
3
- import { GiftWrapOptions } from "applesauce-factory/operations/event";
3
+ import { GiftWrapOptions } from "applesauce-factory/operations/gift-wrap";
4
4
  import { Action } from "../action-hub.js";
5
5
  /**
6
6
  * Sends a NIP-17 wrapped message to a conversation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-actions",
3
- "version": "0.0.0-next-20250723224513",
3
+ "version": "0.0.0-next-20250725170333",
4
4
  "description": "A package for performing common nostr actions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,15 +32,15 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "applesauce-core": "0.0.0-next-20250723224513",
36
- "applesauce-factory": "0.0.0-next-20250723224513",
35
+ "applesauce-core": "0.0.0-next-20250725170333",
36
+ "applesauce-factory": "0.0.0-next-20250725170333",
37
37
  "nostr-tools": "^2.13",
38
38
  "rxjs": "^7.8.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@hirez_io/observer-spy": "^2.2.0",
42
42
  "@types/debug": "^4.1.12",
43
- "applesauce-signers": "0.0.0-next-20250723224513",
43
+ "applesauce-signers": "0.0.0-next-20250725170333",
44
44
  "nanoid": "^5.1.5",
45
45
  "typescript": "^5.8.3",
46
46
  "vitest": "^3.2.3"
@@ -1 +0,0 @@
1
- export {};
@@ -1,67 +0,0 @@
1
- import { from, Subject } from "rxjs";
2
- import { describe, expect, it, vi } from "vitest";
3
- import { subscribeSpyTo } from "@hirez_io/observer-spy";
4
- import { EventFactory } from "applesauce-factory";
5
- import { EventStore } from "applesauce-core";
6
- import { FakeUser } from "./fake-user.js";
7
- import { ActionHub } from "../action-hub.js";
8
- import { CreateProfile } from "../actions/profile.js";
9
- const user = new FakeUser();
10
- const events = new EventStore();
11
- const factory = new EventFactory({ signer: user });
12
- describe("runAction", () => {
13
- it("should handle action that return observables", async () => {
14
- const e = [user.note(), user.profile({ name: "testing" })];
15
- const action = () => from(e);
16
- const spy = subscribeSpyTo(ActionHub.runAction({ events, factory, self: await user.getPublicKey() }, action));
17
- await spy.onComplete();
18
- expect(spy.getValues()).toEqual(e);
19
- });
20
- it("should handle action that return AsyncIterable", async () => {
21
- const e = [user.note(), user.profile({ name: "testing" })];
22
- async function* action() {
23
- for (const event of e)
24
- yield event;
25
- }
26
- const spy = subscribeSpyTo(ActionHub.runAction({ events, factory, self: await user.getPublicKey() }, action));
27
- await spy.onComplete();
28
- expect(spy.getValues()).toEqual(e);
29
- });
30
- it("should handle action that return Iterable", async () => {
31
- const e = [user.note(), user.profile({ name: "testing" })];
32
- function* action() {
33
- for (const event of e)
34
- yield event;
35
- }
36
- const spy = subscribeSpyTo(ActionHub.runAction({ events, factory, self: await user.getPublicKey() }, action));
37
- await spy.onComplete();
38
- expect(spy.getValues()).toEqual(e);
39
- });
40
- });
41
- describe("run", () => {
42
- it("should throw if publish is not set", async () => {
43
- const hub = new ActionHub(events, factory);
44
- await expect(async () => hub.run(CreateProfile, { name: "fiatjaf" })).rejects.toThrow();
45
- });
46
- it("should call publish with all events", async () => {
47
- const publish = vi.fn().mockResolvedValue(undefined);
48
- const hub = new ActionHub(events, factory, publish);
49
- await hub.run(CreateProfile, { name: "fiatjaf" });
50
- expect(publish).toHaveBeenCalledWith(expect.objectContaining({ content: JSON.stringify({ name: "fiatjaf" }) }));
51
- });
52
- });
53
- describe("exec", () => {
54
- it("should support forEach to stream to publish", async () => {
55
- const publish = vi.fn().mockResolvedValue(undefined);
56
- const hub = new ActionHub(events, factory);
57
- await hub.exec(CreateProfile, { name: "fiatjaf" }).forEach(publish);
58
- expect(publish).toHaveBeenCalledWith(expect.objectContaining({ content: JSON.stringify({ name: "fiatjaf" }) }));
59
- });
60
- it("should support streaming to a publish subject", async () => {
61
- const publish = new Subject();
62
- const spy = subscribeSpyTo(publish);
63
- const hub = new ActionHub(events, factory);
64
- await hub.exec(CreateProfile, { name: "fiatjaf" }).forEach((v) => publish.next(v));
65
- expect(spy.getValues()).toEqual([expect.objectContaining({ content: JSON.stringify({ name: "fiatjaf" }) })]);
66
- });
67
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import * as exports from "../index.js";
3
- describe("exports", () => {
4
- it("should export the expected functions", () => {
5
- expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
6
- [
7
- "ActionHub",
8
- "Actions",
9
- ]
10
- `);
11
- });
12
- });
@@ -1,10 +0,0 @@
1
- import { SimpleSigner } from "applesauce-signers/signers/simple-signer";
2
- import type { NostrEvent } from "nostr-tools";
3
- export declare class FakeUser extends SimpleSigner {
4
- pubkey: string;
5
- event(data?: Partial<NostrEvent>): NostrEvent;
6
- note(content?: string, extra?: Partial<NostrEvent>): import("nostr-tools").Event;
7
- profile(profile: any, extra?: Partial<NostrEvent>): import("nostr-tools").Event;
8
- contacts(pubkeys?: string[]): import("nostr-tools").Event;
9
- list(tags?: string[][], extra?: Partial<NostrEvent>): import("nostr-tools").Event;
10
- }
@@ -1,32 +0,0 @@
1
- import { unixNow } from "applesauce-core/helpers";
2
- import { SimpleSigner } from "applesauce-signers/signers/simple-signer";
3
- import { nanoid } from "nanoid";
4
- import { finalizeEvent, getPublicKey, kinds } from "nostr-tools";
5
- export class FakeUser extends SimpleSigner {
6
- pubkey = getPublicKey(this.key);
7
- event(data) {
8
- return finalizeEvent({
9
- kind: data?.kind ?? kinds.ShortTextNote,
10
- content: data?.content || "",
11
- created_at: data?.created_at ?? unixNow(),
12
- tags: data?.tags || [],
13
- }, this.key);
14
- }
15
- note(content = "Hello World", extra) {
16
- return this.event({ kind: kinds.ShortTextNote, content, ...extra });
17
- }
18
- profile(profile, extra) {
19
- return this.event({ kind: kinds.Metadata, content: JSON.stringify({ ...profile }), ...extra });
20
- }
21
- contacts(pubkeys = []) {
22
- return this.event({ kind: kinds.Contacts, tags: pubkeys.map((p) => ["p", p]) });
23
- }
24
- list(tags = [], extra) {
25
- return this.event({
26
- kind: kinds.Bookmarksets,
27
- content: "",
28
- tags: [["d", nanoid()], ...tags],
29
- ...extra,
30
- });
31
- }
32
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,93 +0,0 @@
1
- import { EventStore } from "applesauce-core";
2
- import { BLOSSOM_SERVER_LIST_KIND } from "applesauce-core/helpers/blossom";
3
- import { EventFactory } from "applesauce-factory";
4
- import { firstValueFrom, lastValueFrom } from "rxjs";
5
- import { toArray } from "rxjs/operators";
6
- import { beforeEach, describe, expect, it } from "vitest";
7
- import { FakeUser } from "../../__tests__/fake-user.js";
8
- import { ActionHub } from "../../action-hub.js";
9
- import { AddBlossomServer, NewBlossomServers, RemoveBlossomServer, SetDefaultBlossomServer } from "../blossom.js";
10
- const user = new FakeUser();
11
- let events;
12
- let factory;
13
- let hub;
14
- beforeEach(() => {
15
- events = new EventStore();
16
- factory = new EventFactory({ signer: user });
17
- hub = new ActionHub(events, factory);
18
- });
19
- describe("NewBlossomServers", () => {
20
- it("should publish a kind 10063 blossom server list", async () => {
21
- const result = await lastValueFrom(hub.exec(NewBlossomServers, ["https://cdn.example.com/"]).pipe(toArray()));
22
- expect(result[0]).toMatchObject({ kind: BLOSSOM_SERVER_LIST_KIND, tags: [["server", "https://cdn.example.com/"]] });
23
- });
24
- it("should throw if a blossom servers event already exists", async () => {
25
- // Create the initial event
26
- await hub.exec(NewBlossomServers, ["https://cdn.example.com/"]).forEach((e) => events.add(e));
27
- // Attempt to create another one
28
- await expect(lastValueFrom(hub.exec(NewBlossomServers, ["https://other.example.com/"]).pipe(toArray()))).rejects.toThrow("Blossom servers event already exists");
29
- });
30
- });
31
- describe("AddBlossomServer", () => {
32
- beforeEach(async () => {
33
- // Create an initial empty server list
34
- await hub.exec(NewBlossomServers, ["https://cdn.example.com/"]).forEach((e) => events.add(e));
35
- });
36
- it("should add a single server to the list", async () => {
37
- const result = await firstValueFrom(hub.exec(AddBlossomServer, "https://other.example.com/"));
38
- expect(result).toMatchObject({
39
- kind: BLOSSOM_SERVER_LIST_KIND,
40
- tags: expect.arrayContaining([["server", expect.stringContaining("other.example.com")]]),
41
- });
42
- });
43
- it("should add multiple servers to the list", async () => {
44
- const result = await firstValueFrom(hub.exec(AddBlossomServer, ["https://other.example.com/", "https://other2.example.com/"]));
45
- expect(result).toMatchObject({
46
- kind: BLOSSOM_SERVER_LIST_KIND,
47
- tags: expect.arrayContaining([
48
- ["server", expect.stringContaining("other.example.com")],
49
- ["server", expect.stringContaining("other2.example.com")],
50
- ]),
51
- });
52
- });
53
- });
54
- describe("RemoveBlossomServer", () => {
55
- beforeEach(async () => {
56
- // Create an initial server list with two servers
57
- await hub
58
- .exec(NewBlossomServers, ["https://cdn.example.com/", "https://other.example.com/"])
59
- .forEach((e) => events.add(e));
60
- });
61
- it("should remove a server from the list", async () => {
62
- const result = await firstValueFrom(hub.exec(RemoveBlossomServer, "https://cdn.example.com/"));
63
- expect(result).toMatchObject({
64
- kind: BLOSSOM_SERVER_LIST_KIND,
65
- tags: expect.arrayContaining([["server", expect.stringContaining("other.example.com")]]),
66
- });
67
- });
68
- it("should remove multiple servers from the list", async () => {
69
- const result = await firstValueFrom(hub.exec(RemoveBlossomServer, ["https://cdn.example.com/", "https://other.example.com/"]));
70
- expect(result).toMatchObject({
71
- kind: BLOSSOM_SERVER_LIST_KIND,
72
- tags: [],
73
- });
74
- });
75
- });
76
- describe("SetDefaultBlossomServer", () => {
77
- beforeEach(async () => {
78
- // Create an initial server list with two servers
79
- await hub
80
- .exec(NewBlossomServers, ["https://cdn.example.com/", "https://other.example.com/"])
81
- .forEach((e) => events.add(e));
82
- });
83
- it("should move the specified server to the top of the list", async () => {
84
- const result = await firstValueFrom(hub.exec(SetDefaultBlossomServer, "https://other.example.com/"));
85
- expect(result).toMatchObject({
86
- kind: BLOSSOM_SERVER_LIST_KIND,
87
- tags: expect.arrayContaining([
88
- ["server", expect.stringContaining("other.example.com")],
89
- ["server", expect.stringContaining("cdn.example.com")],
90
- ]),
91
- });
92
- });
93
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
1
- import { beforeEach, describe, expect, it, vitest } from "vitest";
2
- import { EventStore } from "applesauce-core";
3
- import { EventFactory } from "applesauce-factory";
4
- import { kinds } from "nostr-tools";
5
- import { FakeUser } from "../../__tests__/fake-user.js";
6
- import { ActionHub } from "../../action-hub.js";
7
- import { CreateBookmarkList } from "../bookmarks.js";
8
- const user = new FakeUser();
9
- let events;
10
- let factory;
11
- let publish;
12
- let hub;
13
- beforeEach(() => {
14
- events = new EventStore();
15
- factory = new EventFactory({ signer: user });
16
- publish = vitest.fn().mockResolvedValue(undefined);
17
- hub = new ActionHub(events, factory, publish);
18
- });
19
- describe("CreateBookmarkList", () => {
20
- it("should publish a kind 10003 bookmark list", async () => {
21
- await hub.run(CreateBookmarkList);
22
- expect(publish).toBeCalledWith(expect.objectContaining({ kind: kinds.BookmarkList }));
23
- });
24
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,53 +0,0 @@
1
- import { describe, it, expect, beforeEach, vitest } from "vitest";
2
- import { FakeUser } from "../../__tests__/fake-user.js";
3
- import { EventFactory } from "applesauce-factory";
4
- import { EventStore } from "applesauce-core";
5
- import { ActionHub } from "../../action-hub.js";
6
- import { FollowUser, NewContacts, UnfollowUser } from "../contacts.js";
7
- const user = new FakeUser();
8
- let events;
9
- let factory;
10
- let publish;
11
- let hub;
12
- beforeEach(() => {
13
- events = new EventStore();
14
- factory = new EventFactory({ signer: user });
15
- publish = vitest.fn().mockResolvedValue(undefined);
16
- hub = new ActionHub(events, factory, publish);
17
- });
18
- describe("FollowUser", () => {
19
- it("should throw an error if contacts does not exist", async () => {
20
- // don't add any events to the store
21
- await expect(hub.run(FollowUser, user.pubkey)).rejects.toThrow();
22
- expect(publish).not.toHaveBeenCalled();
23
- });
24
- it('should publish an event with a new "p" tag', async () => {
25
- events.add(user.contacts());
26
- await hub.run(FollowUser, user.pubkey);
27
- expect(publish).toHaveBeenCalledWith(expect.objectContaining({ tags: expect.arrayContaining([["p", user.pubkey]]) }));
28
- });
29
- });
30
- describe("UnfollowUser", () => {
31
- it("should throw an error if contacts does not exist", async () => {
32
- // don't add any events to the store
33
- await expect(hub.run(UnfollowUser, user.pubkey)).rejects.toThrow();
34
- expect(publish).not.toHaveBeenCalled();
35
- });
36
- it('should publish an event with a new "p" tag', async () => {
37
- events.add(user.contacts([user.pubkey]));
38
- await hub.run(UnfollowUser, user.pubkey);
39
- expect(publish).toHaveBeenCalledWith(expect.objectContaining({ kind: 3, tags: [] }));
40
- });
41
- });
42
- describe("NewContacts", () => {
43
- it("should throw if contact list already exists", async () => {
44
- events.add(user.contacts([user.pubkey]));
45
- await expect(hub.run(NewContacts, [])).rejects.toThrow();
46
- expect(publish).not.toBeCalled();
47
- });
48
- it("should publish a new contact event with pubkeys", async () => {
49
- await hub.run(NewContacts, [user.pubkey]);
50
- expect(publish).toHaveBeenCalled();
51
- expect(publish).toHaveBeenCalledWith(expect.objectContaining({ kind: 3, tags: expect.arrayContaining([["p", user.pubkey]]) }));
52
- });
53
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,62 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import * as exports from "../index.js";
3
- describe("exports", () => {
4
- it("should export the expected functions", () => {
5
- expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
6
- [
7
- "AddBlockedRelay",
8
- "AddBlossomServer",
9
- "AddDMRelay",
10
- "AddFavoriteRelay",
11
- "AddFavoriteRelaySet",
12
- "AddInboxRelay",
13
- "AddOutboxRelay",
14
- "AddRelayToRelaySet",
15
- "AddSearchRelay",
16
- "AddUserToFollowSet",
17
- "BookmarkEvent",
18
- "CreateBookmarkList",
19
- "CreateBookmarkSet",
20
- "CreateFollowSet",
21
- "CreateMailboxes",
22
- "CreatePinList",
23
- "CreateProfile",
24
- "CreateRelaySet",
25
- "FollowUser",
26
- "MuteHashtag",
27
- "MuteThread",
28
- "MuteUser",
29
- "MuteWord",
30
- "NewBlockedRelays",
31
- "NewBlossomServers",
32
- "NewContacts",
33
- "NewDMRelays",
34
- "NewFavoriteRelays",
35
- "NewSearchRelays",
36
- "PinNote",
37
- "RemoveBlockedRelay",
38
- "RemoveBlossomServer",
39
- "RemoveDMRelay",
40
- "RemoveFavoriteRelay",
41
- "RemoveFavoriteRelaySet",
42
- "RemoveInboxRelay",
43
- "RemoveOutboxRelay",
44
- "RemoveRelayFromRelaySet",
45
- "RemoveSearchRelay",
46
- "RemoveUserFromFollowSet",
47
- "SetDefaultBlossomServer",
48
- "SetListMetadata",
49
- "UnbookmarkEvent",
50
- "UnfollowUser",
51
- "UnmuteHashtag",
52
- "UnmuteThread",
53
- "UnmuteUser",
54
- "UnmuteWord",
55
- "UnpinNote",
56
- "UpdateFollowSetInformation",
57
- "UpdateProfile",
58
- "UpdateRelaySetInformation",
59
- ]
60
- `);
61
- });
62
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,80 +0,0 @@
1
- import { beforeEach, describe, expect, it } from "vitest";
2
- import { EventStore } from "applesauce-core";
3
- import { EventFactory } from "applesauce-factory";
4
- import { kinds } from "nostr-tools";
5
- import { unlockHiddenTags } from "applesauce-core/helpers";
6
- import { subscribeSpyTo } from "@hirez_io/observer-spy";
7
- import { FakeUser } from "../../__tests__/fake-user.js";
8
- import { ActionHub } from "../../action-hub.js";
9
- import { AddUserToFollowSet, RemoveUserFromFollowSet } from "../follow-sets.js";
10
- const user = new FakeUser();
11
- const testPubkey = "test-pubkey";
12
- const testIdentifier = "test-list";
13
- let events;
14
- let factory;
15
- let hub;
16
- beforeEach(() => {
17
- events = new EventStore();
18
- factory = new EventFactory({ signer: user });
19
- hub = new ActionHub(events, factory);
20
- // Add a follow set event to work with
21
- const followSet = user.event({
22
- kind: kinds.Followsets,
23
- tags: [["d", testIdentifier]],
24
- content: "",
25
- created_at: Math.floor(Date.now() / 1000),
26
- });
27
- events.add(followSet);
28
- });
29
- describe("AddUserToList", () => {
30
- it("should add a pubkey to public tags in a follow set", async () => {
31
- const spy = subscribeSpyTo(hub.exec(AddUserToFollowSet, testPubkey, testIdentifier), { expectErrors: false });
32
- await spy.onComplete();
33
- const emittedEvent = spy.getLastValue();
34
- expect(emittedEvent).toMatchObject({
35
- kind: kinds.Followsets,
36
- tags: expect.arrayContaining([
37
- ["d", testIdentifier],
38
- ["p", testPubkey],
39
- ]),
40
- });
41
- });
42
- it("should add a pubkey to hidden tags in a follow set", async () => {
43
- const spy = subscribeSpyTo(hub.exec(AddUserToFollowSet, testPubkey, testIdentifier, true), { expectErrors: false });
44
- await spy.onComplete();
45
- const emittedEvent = spy.getLastValue();
46
- expect(await unlockHiddenTags(emittedEvent, user)).toEqual(expect.arrayContaining([["p", testPubkey]]));
47
- });
48
- });
49
- describe("RemoveUserFromList", () => {
50
- beforeEach(async () => {
51
- // Add a follow set with existing tags to remove
52
- const followSetWithTags = user.event({
53
- kind: kinds.Followsets,
54
- tags: [
55
- ["d", testIdentifier],
56
- ["p", testPubkey],
57
- ],
58
- content: await user.nip04.encrypt(user.pubkey, JSON.stringify(["p", testPubkey])),
59
- created_at: Math.floor(Date.now() / 1000),
60
- });
61
- events.add(followSetWithTags);
62
- });
63
- it("should remove a pubkey from public tags in a follow set", async () => {
64
- const spy = subscribeSpyTo(hub.exec(RemoveUserFromFollowSet, testPubkey, testIdentifier), { expectErrors: false });
65
- await spy.onComplete();
66
- const emittedEvent = spy.getLastValue();
67
- expect(emittedEvent).toMatchObject({
68
- kind: kinds.Followsets,
69
- tags: expect.not.arrayContaining([["p", testPubkey]]),
70
- });
71
- });
72
- it("should remove a pubkey from hidden tags in a follow set", async () => {
73
- const spy = subscribeSpyTo(hub.exec(RemoveUserFromFollowSet, testPubkey, testIdentifier, true), {
74
- expectErrors: false,
75
- });
76
- await spy.onComplete();
77
- const emittedEvent = spy.getLastValue();
78
- expect(await unlockHiddenTags(emittedEvent, user)).toEqual(expect.not.arrayContaining([["hidden", "p", testPubkey]]));
79
- });
80
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,67 +0,0 @@
1
- import { beforeEach, describe, expect, it } from "vitest";
2
- import { EventStore } from "applesauce-core";
3
- import { EventFactory } from "applesauce-factory";
4
- import { kinds } from "nostr-tools";
5
- import { getMutedThings, getHiddenMutedThings } from "applesauce-core/helpers";
6
- import { subscribeSpyTo } from "@hirez_io/observer-spy";
7
- import { FakeUser } from "../../__tests__/fake-user.js";
8
- import { ActionHub } from "../../action-hub.js";
9
- import { MuteThread, UnmuteThread } from "../mute.js";
10
- const user = new FakeUser();
11
- const testEventId = "test-event-id";
12
- let events;
13
- let factory;
14
- let hub;
15
- beforeEach(() => {
16
- events = new EventStore();
17
- factory = new EventFactory({ signer: user });
18
- hub = new ActionHub(events, factory);
19
- // Add a mute list event to work with
20
- const muteList = user.event({
21
- kind: kinds.Mutelist,
22
- tags: [],
23
- content: "",
24
- created_at: Math.floor(Date.now() / 1000),
25
- });
26
- events.add(muteList);
27
- });
28
- describe("MuteThread", () => {
29
- it("should add an event to public tags in mute list", async () => {
30
- const spy = subscribeSpyTo(hub.exec(MuteThread, testEventId), { expectErrors: false });
31
- await spy.onComplete();
32
- const emittedEvent = spy.getLastValue();
33
- const mutedThings = getMutedThings(emittedEvent);
34
- expect(mutedThings.threads).toContain(testEventId);
35
- });
36
- it("should add an event to hidden tags in mute list", async () => {
37
- const spy = subscribeSpyTo(hub.exec(MuteThread, testEventId, true), { expectErrors: false });
38
- await spy.onComplete();
39
- const emittedEvent = spy.getLastValue();
40
- const hiddenMutedThings = await getHiddenMutedThings(emittedEvent);
41
- expect(hiddenMutedThings?.threads).toContain(testEventId);
42
- });
43
- });
44
- describe("UnmuteThread", () => {
45
- it("should remove an event from public tags in mute list", async () => {
46
- // First add the thread to mute list
47
- const addSpy = subscribeSpyTo(hub.exec(MuteThread, testEventId), { expectErrors: false });
48
- await addSpy.onComplete();
49
- // Then unmute it
50
- const spy = subscribeSpyTo(hub.exec(UnmuteThread, testEventId), { expectErrors: false });
51
- await spy.onComplete();
52
- const emittedEvent = spy.getLastValue();
53
- const mutedThings = getMutedThings(emittedEvent);
54
- expect(mutedThings.threads).not.toContain(testEventId);
55
- });
56
- it("should remove an event from hidden tags in mute list", async () => {
57
- // First add the thread to hidden mute list
58
- const addSpy = subscribeSpyTo(hub.exec(MuteThread, testEventId, true), { expectErrors: false });
59
- await addSpy.onComplete();
60
- // Then unmute it
61
- const spy = subscribeSpyTo(hub.exec(UnmuteThread, testEventId, true), { expectErrors: false });
62
- await spy.onComplete();
63
- const emittedEvent = spy.getLastValue();
64
- const hiddenMutedThings = await getHiddenMutedThings(emittedEvent);
65
- expect(hiddenMutedThings?.threads).not.toContain(testEventId);
66
- });
67
- });