applesauce-actions 2.3.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
  }
@@ -0,0 +1,6 @@
1
+ import { NostrEvent } from "nostr-tools";
2
+ import { Action } from "../action-hub.js";
3
+ /** Adds a calendar event to a calendar */
4
+ export declare function AddEventToCalendar(calendar: NostrEvent, event: NostrEvent): Action;
5
+ /** Removes a calendar event from a calendar */
6
+ export declare function RemoveEventFromCalendar(calendar: NostrEvent, event: NostrEvent): Action;
@@ -0,0 +1,25 @@
1
+ import { DATE_BASED_CALENDAR_EVENT_KIND, TIME_BASED_CALENDAR_EVENT_KIND } from "applesauce-core/helpers/calendar-event";
2
+ import { Calendar } from "applesauce-factory/operations";
3
+ import { kinds } from "nostr-tools";
4
+ /** Adds a calendar event to a calendar */
5
+ export function AddEventToCalendar(calendar, event) {
6
+ if (calendar.kind !== kinds.Calendar)
7
+ throw new Error("Calendar is not a calendar event");
8
+ if (event.kind !== DATE_BASED_CALENDAR_EVENT_KIND && event.kind !== TIME_BASED_CALENDAR_EVENT_KIND)
9
+ throw new Error("Event is not a calendar event");
10
+ return async function* ({ factory }) {
11
+ const draft = await factory.modify(calendar, Calendar.addEvent(event));
12
+ return await factory.sign(draft);
13
+ };
14
+ }
15
+ /** Removes a calendar event from a calendar */
16
+ export function RemoveEventFromCalendar(calendar, event) {
17
+ if (calendar.kind !== kinds.Calendar)
18
+ throw new Error("Calendar is not a calendar event");
19
+ if (event.kind !== DATE_BASED_CALENDAR_EVENT_KIND && event.kind !== TIME_BASED_CALENDAR_EVENT_KIND)
20
+ throw new Error("Event is not a calendar event");
21
+ return async function* ({ factory }) {
22
+ const draft = await factory.modify(calendar, Calendar.removeEvent(event));
23
+ return await factory.sign(draft);
24
+ };
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,6 +1,6 @@
1
1
  import { FAVORITE_RELAYS_KIND } from "applesauce-core/helpers/lists";
2
- import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations/event";
3
- import { addCoordinateTag, addRelayTag, removeCoordinateTag, removeRelayTag } from "applesauce-factory/operations/tag";
2
+ import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations";
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);
6
6
  if (!event)
@@ -29,7 +29,7 @@ export function RemoveFavoriteRelay(relay, hidden = false) {
29
29
  export function AddFavoriteRelaySet(addr, hidden = false) {
30
30
  return async function* ({ events, factory, self }) {
31
31
  const favorites = getFavoriteRelaysEvent(events, self);
32
- const operation = Array.isArray(addr) ? addr.map((a) => addCoordinateTag(a)) : addCoordinateTag(addr);
32
+ const operation = Array.isArray(addr) ? addr.map((a) => addAddressTag(a)) : addAddressTag(addr);
33
33
  const draft = await factory.modifyTags(favorites, hidden ? { hidden: operation } : operation);
34
34
  yield await factory.sign(draft);
35
35
  };
@@ -38,7 +38,7 @@ export function AddFavoriteRelaySet(addr, hidden = false) {
38
38
  export function RemoveFavoriteRelaySet(addr, hidden = false) {
39
39
  return async function* ({ events, factory, self }) {
40
40
  const favorites = getFavoriteRelaysEvent(events, self);
41
- const operation = Array.isArray(addr) ? addr.map((a) => removeCoordinateTag(a)) : removeCoordinateTag(addr);
41
+ const operation = Array.isArray(addr) ? addr.map((a) => removeAddressTag(a)) : removeAddressTag(addr);
42
42
  const draft = await factory.modifyTags(favorites, hidden ? { hidden: operation } : operation);
43
43
  yield await factory.sign(draft);
44
44
  };
@@ -61,13 +61,13 @@ export function NewFavoriteRelays(relays, sets) {
61
61
  hiddenOperations.push(...(relays?.hidden ?? []).map((r) => addRelayTag(r)));
62
62
  }
63
63
  if (Array.isArray(sets)) {
64
- publicOperations.push(...sets.map((s) => addCoordinateTag(s)));
64
+ publicOperations.push(...sets.map((s) => addAddressTag(s)));
65
65
  }
66
66
  else {
67
67
  if (sets?.public)
68
- publicOperations.push(...(sets?.public ?? []).map((s) => addCoordinateTag(s)));
68
+ publicOperations.push(...(sets?.public ?? []).map((s) => addAddressTag(s)));
69
69
  if (sets?.hidden)
70
- hiddenOperations.push(...(sets?.hidden ?? []).map((s) => addCoordinateTag(s)));
70
+ hiddenOperations.push(...(sets?.hidden ?? []).map((s) => addAddressTag(s)));
71
71
  }
72
72
  const draft = await factory.build({ kind: FAVORITE_RELAYS_KIND }, publicOperations.length ? modifyPublicTags(...publicOperations) : undefined, hiddenOperations.length ? modifyHiddenTags(...hiddenOperations) : undefined);
73
73
  yield await factory.sign(draft);
@@ -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,6 +1,7 @@
1
1
  export * from "./blocked-relays.js";
2
2
  export * from "./blossom.js";
3
3
  export * from "./bookmarks.js";
4
+ export * from "./calendar.js";
4
5
  export * from "./contacts.js";
5
6
  export * from "./dm-relays.js";
6
7
  export * from "./favorite-relays.js";
@@ -1,6 +1,7 @@
1
1
  export * from "./blocked-relays.js";
2
2
  export * from "./blossom.js";
3
3
  export * from "./bookmarks.js";
4
+ export * from "./calendar.js";
4
5
  export * from "./contacts.js";
5
6
  export * from "./dm-relays.js";
6
7
  export * from "./favorite-relays.js";
@@ -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,6 @@
1
1
  import { NostrEvent } from "nostr-tools";
2
2
  import { Action } from "../action-hub.js";
3
+ export declare const ALLOWED_PIN_KINDS: number[];
3
4
  /** An action that pins a note to the users pin list */
4
5
  export declare function PinNote(note: NostrEvent): Action;
5
6
  /** An action that removes an event from the users pin list */
@@ -1,13 +1,18 @@
1
+ import { getReplaceableAddress, isReplaceable } from "applesauce-core/helpers";
2
+ import { modifyPublicTags } from "applesauce-factory/operations";
3
+ import { addAddressTag, addEventTag, removeAddressTag, removeEventTag } from "applesauce-factory/operations/tag";
1
4
  import { kinds } from "nostr-tools";
2
- import { addEventTag, removeEventTag } from "applesauce-factory/operations/tag";
3
- import { modifyPublicTags } from "applesauce-factory/operations/event";
5
+ export const ALLOWED_PIN_KINDS = [kinds.ShortTextNote, kinds.LongFormArticle];
4
6
  /** An action that pins a note to the users pin list */
5
7
  export function PinNote(note) {
8
+ if (!ALLOWED_PIN_KINDS.includes(note.kind))
9
+ throw new Error(`Event kind ${note.kind} can not be pinned`);
6
10
  return async function* ({ events, factory, self }) {
7
11
  const pins = events.getReplaceable(kinds.Pinlist, self);
8
- if (!pins)
9
- throw new Error("Missing pin list");
10
- const draft = await factory.modifyTags(pins, addEventTag(note.id));
12
+ const operation = isReplaceable(note.kind) ? addAddressTag(getReplaceableAddress(note)) : addEventTag(note.id);
13
+ const draft = pins
14
+ ? await factory.modifyTags(pins, operation)
15
+ : await factory.build({ kind: kinds.Pinlist }, modifyPublicTags(operation));
11
16
  yield await factory.sign(draft);
12
17
  };
13
18
  }
@@ -16,8 +21,11 @@ export function UnpinNote(note) {
16
21
  return async function* ({ events, factory, self }) {
17
22
  const pins = events.getReplaceable(kinds.Pinlist, self);
18
23
  if (!pins)
19
- throw new Error("Missing pin list");
20
- const draft = await factory.modifyTags(pins, removeEventTag(note.id));
24
+ return;
25
+ const operation = isReplaceable(note.kind)
26
+ ? removeAddressTag(getReplaceableAddress(note))
27
+ : removeEventTag(note.id);
28
+ const draft = await factory.modifyTags(pins, operation);
21
29
  yield await factory.sign(draft);
22
30
  };
23
31
  }
@@ -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": "2.3.0",
3
+ "version": "3.1.0",
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": "^2.3.0",
36
- "applesauce-factory": "^2.3.0",
37
- "nostr-tools": "^2.13",
35
+ "applesauce-core": "^3.1.0",
36
+ "applesauce-factory": "^3.1.0",
37
+ "nostr-tools": "~2.15",
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": "^2.0.0",
43
+ "applesauce-signers": "^3.1.0",
44
44
  "nanoid": "^5.1.5",
45
45
  "typescript": "^5.8.3",
46
46
  "vitest": "^3.2.3"