applesauce-actions 2.1.0 → 3.0.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.
- package/dist/action-hub.d.ts +1 -4
- package/dist/actions/blocked-relays.js +1 -1
- package/dist/actions/blossom.js +16 -16
- package/dist/actions/bookmarks.d.ts +4 -4
- package/dist/actions/bookmarks.js +44 -20
- package/dist/actions/calendar.d.ts +6 -0
- package/dist/actions/calendar.js +25 -0
- package/dist/actions/contacts.d.ts +3 -2
- package/dist/actions/contacts.js +14 -9
- package/dist/actions/dm-relays.js +1 -1
- package/dist/actions/favorite-relays.js +7 -7
- package/dist/actions/follow-sets.js +3 -3
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.js +1 -0
- package/dist/actions/lists.js +2 -2
- package/dist/actions/mailboxes.js +9 -9
- package/dist/actions/pins.d.ts +1 -0
- package/dist/actions/pins.js +15 -7
- package/dist/actions/profile.js +3 -3
- package/dist/actions/relay-sets.js +3 -3
- package/dist/actions/search-relays.js +1 -1
- package/dist/actions/wrapped-messages.d.ts +1 -1
- package/dist/actions/wrapped-messages.js +4 -3
- package/package.json +4 -4
package/dist/action-hub.d.ts
CHANGED
|
@@ -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
|
|
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) {
|
package/dist/actions/blossom.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { BLOSSOM_SERVER_LIST_KIND } from "applesauce-core/helpers/blossom";
|
|
2
|
-
import { modifyPublicTags } from "applesauce-factory/operations
|
|
2
|
+
import { modifyPublicTags, modifyTags } from "applesauce-factory/operations";
|
|
3
3
|
import { addBlossomServerTag, removeBlossomServerTag } from "applesauce-factory/operations/tag/blossom";
|
|
4
|
-
function getBlossomServersEvent(events, self) {
|
|
5
|
-
const event = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
|
|
6
|
-
if (!event)
|
|
7
|
-
throw new Error("Can't find Blossom servers event");
|
|
8
|
-
return event;
|
|
9
|
-
}
|
|
10
4
|
/** An action that adds a server to the Blossom servers event */
|
|
11
5
|
export function AddBlossomServer(server) {
|
|
12
6
|
return async function* ({ events, factory, self }) {
|
|
13
|
-
const servers =
|
|
7
|
+
const servers = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
|
|
14
8
|
const operation = Array.isArray(server) ? server.map((s) => addBlossomServerTag(s)) : addBlossomServerTag(server);
|
|
15
|
-
|
|
9
|
+
// Modify or build new event
|
|
10
|
+
const draft = servers
|
|
11
|
+
? await factory.modifyTags(servers, operation)
|
|
12
|
+
: await factory.build({ kind: BLOSSOM_SERVER_LIST_KIND }, modifyTags(operation));
|
|
16
13
|
yield await factory.sign(draft);
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
16
|
/** An action that removes a server from the Blossom servers event */
|
|
20
17
|
export function RemoveBlossomServer(server) {
|
|
21
18
|
return async function* ({ events, factory, self }) {
|
|
22
|
-
const servers =
|
|
19
|
+
const servers = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
|
|
23
20
|
const operation = Array.isArray(server)
|
|
24
21
|
? server.map((s) => removeBlossomServerTag(s))
|
|
25
22
|
: removeBlossomServerTag(server);
|
|
26
|
-
|
|
23
|
+
// Modify or build new event
|
|
24
|
+
const draft = servers
|
|
25
|
+
? await factory.modifyTags(servers, operation)
|
|
26
|
+
: await factory.build({ kind: BLOSSOM_SERVER_LIST_KIND }, modifyTags(operation));
|
|
27
27
|
yield await factory.sign(draft);
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
/** Makes a specific Blossom server the default server (move it to the top of the list) */
|
|
31
31
|
export function SetDefaultBlossomServer(server) {
|
|
32
32
|
return async function* ({ events, factory, self }) {
|
|
33
|
-
const servers =
|
|
33
|
+
const servers = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
|
|
34
34
|
const prependTag = (tag) => (tags) => [tag, ...tags];
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const operations = [removeBlossomServerTag(server), prependTag(["server", String(server)])];
|
|
36
|
+
const draft = servers
|
|
37
|
+
? await factory.modifyTags(servers, operations)
|
|
38
|
+
: await factory.build({ kind: BLOSSOM_SERVER_LIST_KIND }, modifyTags(...operations));
|
|
39
39
|
yield await factory.sign(draft);
|
|
40
40
|
};
|
|
41
41
|
}
|
|
@@ -3,17 +3,17 @@ import { Action } from "../action-hub.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* An action that adds a note or article to the bookmark list or a bookmark set
|
|
5
5
|
* @param event the event to bookmark
|
|
6
|
-
* @param identifier the "d" tag of the bookmark set
|
|
6
|
+
* @param identifier the "d" tag of the bookmark set or `undefined` for the default bookmark list
|
|
7
7
|
* @param hidden set to true to add to hidden bookmarks
|
|
8
8
|
*/
|
|
9
|
-
export declare function BookmarkEvent(event: NostrEvent, identifier?: string, hidden?: boolean): Action;
|
|
9
|
+
export declare function BookmarkEvent(event: NostrEvent, identifier?: string | NostrEvent, hidden?: boolean): Action;
|
|
10
10
|
/**
|
|
11
11
|
* An action that removes a note or article from the bookmark list or bookmark set
|
|
12
12
|
* @param event the event to remove from bookmarks
|
|
13
|
-
* @param identifier the "d" tag of the bookmark set
|
|
13
|
+
* @param identifier the "d" tag of the bookmark set or `undefined` for the default bookmark list
|
|
14
14
|
* @param hidden set to true to remove from hidden bookmarks
|
|
15
15
|
*/
|
|
16
|
-
export declare function UnbookmarkEvent(event: NostrEvent, identifier?: string, hidden?: boolean): Action;
|
|
16
|
+
export declare function UnbookmarkEvent(event: NostrEvent, identifier?: string | NostrEvent, hidden?: boolean): Action;
|
|
17
17
|
/** An action that creates a new bookmark list for a user */
|
|
18
18
|
export declare function CreateBookmarkList(bookmarks?: NostrEvent[]): Action;
|
|
19
19
|
/** An action that creates a new bookmark set for a user */
|
|
@@ -1,45 +1,72 @@
|
|
|
1
|
-
import { modifyHiddenTags, modifyPublicTags,
|
|
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
|
-
function getBookmarkEvent(events, self, identifier) {
|
|
5
|
-
return events.getReplaceable(identifier ? kinds.Bookmarksets : kinds.BookmarkList, self, identifier);
|
|
6
|
-
}
|
|
7
4
|
/**
|
|
8
5
|
* An action that adds a note or article to the bookmark list or a bookmark set
|
|
9
6
|
* @param event the event to bookmark
|
|
10
|
-
* @param identifier the "d" tag of the bookmark set
|
|
7
|
+
* @param identifier the "d" tag of the bookmark set or `undefined` for the default bookmark list
|
|
11
8
|
* @param hidden set to true to add to hidden bookmarks
|
|
12
9
|
*/
|
|
13
10
|
export function BookmarkEvent(event, identifier, hidden = false) {
|
|
14
11
|
return async function* ({ events, factory, self }) {
|
|
15
|
-
|
|
16
|
-
if (!bookmarks)
|
|
17
|
-
throw new Error("Cant find bookmarks");
|
|
12
|
+
let draft;
|
|
18
13
|
const operation = addEventBookmarkTag(event);
|
|
19
|
-
|
|
14
|
+
if (typeof identifier === "string" || identifier?.kind === kinds.Bookmarksets) {
|
|
15
|
+
const list = typeof identifier === "string" ? events.getReplaceable(kinds.Bookmarksets, self, identifier) : identifier;
|
|
16
|
+
if (list && list.kind !== kinds.Bookmarksets)
|
|
17
|
+
throw new Error("Event is not a bookmark set");
|
|
18
|
+
// Modify or build new event bookmark set
|
|
19
|
+
draft = list
|
|
20
|
+
? await factory.modifyTags(list, hidden ? { hidden: operation } : operation)
|
|
21
|
+
: await factory.build({ kind: kinds.Bookmarksets }, hidden ? modifyHiddenTags(operation) : modifyPublicTags(operation));
|
|
22
|
+
}
|
|
23
|
+
else if (identifier === undefined || identifier?.kind === kinds.BookmarkList) {
|
|
24
|
+
const list = identifier ? identifier : events.getReplaceable(kinds.BookmarkList, self);
|
|
25
|
+
if (list && list.kind !== kinds.BookmarkList)
|
|
26
|
+
throw new Error("Event is not a bookmark list");
|
|
27
|
+
// Modify or build new event bookmark list
|
|
28
|
+
draft = list
|
|
29
|
+
? await factory.modifyTags(list, hidden ? { hidden: operation } : operation)
|
|
30
|
+
: await factory.build({ kind: kinds.BookmarkList }, hidden ? modifyHiddenTags(operation) : modifyPublicTags(operation));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error(`Event kind ${identifier.kind} is not a bookmark list or bookmark set`);
|
|
34
|
+
}
|
|
20
35
|
yield await factory.sign(draft);
|
|
21
36
|
};
|
|
22
37
|
}
|
|
23
38
|
/**
|
|
24
39
|
* An action that removes a note or article from the bookmark list or bookmark set
|
|
25
40
|
* @param event the event to remove from bookmarks
|
|
26
|
-
* @param identifier the "d" tag of the bookmark set
|
|
41
|
+
* @param identifier the "d" tag of the bookmark set or `undefined` for the default bookmark list
|
|
27
42
|
* @param hidden set to true to remove from hidden bookmarks
|
|
28
43
|
*/
|
|
29
44
|
export function UnbookmarkEvent(event, identifier, hidden = false) {
|
|
30
45
|
return async function* ({ events, factory, self }) {
|
|
31
|
-
|
|
32
|
-
if (!bookmarks)
|
|
33
|
-
throw new Error("Cant find bookmarks");
|
|
46
|
+
let list;
|
|
34
47
|
const operation = removeEventBookmarkTag(event);
|
|
35
|
-
|
|
48
|
+
if (typeof identifier === "string" || identifier?.kind === kinds.Bookmarksets) {
|
|
49
|
+
list = typeof identifier === "string" ? events.getReplaceable(kinds.Bookmarksets, self, identifier) : identifier;
|
|
50
|
+
}
|
|
51
|
+
else if (identifier === undefined || identifier?.kind === kinds.BookmarkList) {
|
|
52
|
+
list = identifier ? identifier : events.getReplaceable(kinds.BookmarkList, self);
|
|
53
|
+
if (!list)
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new Error(`Event kind ${identifier.kind} is not a bookmark list or bookmark set`);
|
|
58
|
+
}
|
|
59
|
+
// If no list is found, return
|
|
60
|
+
if (!list)
|
|
61
|
+
return;
|
|
62
|
+
const draft = await factory.modifyTags(list, hidden ? { hidden: operation } : operation);
|
|
36
63
|
yield await factory.sign(draft);
|
|
37
64
|
};
|
|
38
65
|
}
|
|
39
66
|
/** An action that creates a new bookmark list for a user */
|
|
40
67
|
export function CreateBookmarkList(bookmarks) {
|
|
41
68
|
return async function* ({ events, factory, self }) {
|
|
42
|
-
const existing =
|
|
69
|
+
const existing = events.getReplaceable(kinds.BookmarkList, self);
|
|
43
70
|
if (existing)
|
|
44
71
|
throw new Error("Bookmark list already exists");
|
|
45
72
|
const draft = await factory.build({ kind: kinds.BookmarkList }, bookmarks ? modifyPublicTags(...bookmarks.map(addEventBookmarkTag)) : undefined);
|
|
@@ -48,11 +75,8 @@ export function CreateBookmarkList(bookmarks) {
|
|
|
48
75
|
}
|
|
49
76
|
/** An action that creates a new bookmark set for a user */
|
|
50
77
|
export function CreateBookmarkSet(title, description, additional) {
|
|
51
|
-
return async function* ({
|
|
52
|
-
const
|
|
53
|
-
if (existing)
|
|
54
|
-
throw new Error("Bookmark list already exists");
|
|
55
|
-
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);
|
|
78
|
+
return async function* ({ factory }) {
|
|
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);
|
|
56
80
|
yield await factory.sign(draft);
|
|
57
81
|
};
|
|
58
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,7 +1,8 @@
|
|
|
1
|
+
import { ProfilePointer } from "nostr-tools/nip19";
|
|
1
2
|
import { Action } from "../action-hub.js";
|
|
2
3
|
/** An action that adds a pubkey to a users contacts event */
|
|
3
4
|
export declare function FollowUser(pubkey: string, relay?: string, hidden?: boolean): Action;
|
|
4
5
|
/** An action that removes a pubkey from a users contacts event */
|
|
5
|
-
export declare function UnfollowUser(
|
|
6
|
+
export declare function UnfollowUser(user: string | ProfilePointer, hidden?: boolean): Action;
|
|
6
7
|
/** An action that creates a new kind 3 contacts lists, throws if a contact list already exists */
|
|
7
|
-
export declare function NewContacts(pubkeys?: string[]): Action;
|
|
8
|
+
export declare function NewContacts(pubkeys?: (string | ProfilePointer)[]): Action;
|
package/dist/actions/contacts.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations";
|
|
2
2
|
import { addPubkeyTag, removePubkeyTag } from "applesauce-factory/operations/tag";
|
|
3
|
+
import { kinds } from "nostr-tools";
|
|
3
4
|
/** An action that adds a pubkey to a users contacts event */
|
|
4
5
|
export function FollowUser(pubkey, relay, hidden = false) {
|
|
5
6
|
return async function* ({ events, factory, self }) {
|
|
6
|
-
|
|
7
|
-
if (!contacts)
|
|
8
|
-
throw new Error("Missing contacts event");
|
|
7
|
+
let contacts = events.getReplaceable(kinds.Contacts, self);
|
|
9
8
|
const pointer = { pubkey, relays: relay ? [relay] : undefined };
|
|
10
9
|
const operation = addPubkeyTag(pointer);
|
|
11
|
-
|
|
10
|
+
let draft;
|
|
11
|
+
// No contact list, create one
|
|
12
|
+
if (!contacts)
|
|
13
|
+
draft = await factory.build({ kind: kinds.Contacts }, hidden ? modifyHiddenTags(operation) : modifyPublicTags(operation));
|
|
14
|
+
else
|
|
15
|
+
draft = await factory.modifyTags(contacts, hidden ? { hidden: operation } : operation);
|
|
12
16
|
yield await factory.sign(draft);
|
|
13
17
|
};
|
|
14
18
|
}
|
|
15
19
|
/** An action that removes a pubkey from a users contacts event */
|
|
16
|
-
export function UnfollowUser(
|
|
20
|
+
export function UnfollowUser(user, hidden = false) {
|
|
17
21
|
return async function* ({ events, factory, self }) {
|
|
18
22
|
const contacts = events.getReplaceable(kinds.Contacts, self);
|
|
23
|
+
// Unable to find a contacts event, so we can't unfollow
|
|
19
24
|
if (!contacts)
|
|
20
|
-
|
|
21
|
-
const operation = removePubkeyTag(
|
|
25
|
+
return;
|
|
26
|
+
const operation = removePubkeyTag(user);
|
|
22
27
|
const draft = await factory.modifyTags(contacts, hidden ? { hidden: operation } : operation);
|
|
23
28
|
yield await factory.sign(draft);
|
|
24
29
|
};
|
|
@@ -29,7 +34,7 @@ export function NewContacts(pubkeys) {
|
|
|
29
34
|
const contacts = events.getReplaceable(kinds.Contacts, self);
|
|
30
35
|
if (contacts)
|
|
31
36
|
throw new Error("Contact list already exists");
|
|
32
|
-
const draft = await factory.build({ kind: kinds.Contacts,
|
|
37
|
+
const draft = await factory.build({ kind: kinds.Contacts }, pubkeys ? modifyPublicTags(...pubkeys.map((p) => addPubkeyTag(p))) : undefined);
|
|
33
38
|
yield await factory.sign(draft);
|
|
34
39
|
};
|
|
35
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { modifyPublicTags } from "applesauce-factory/operations
|
|
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
|
|
3
|
-
import {
|
|
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) =>
|
|
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) =>
|
|
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) =>
|
|
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) =>
|
|
68
|
+
publicOperations.push(...(sets?.public ?? []).map((s) => addAddressTag(s)));
|
|
69
69
|
if (sets?.hidden)
|
|
70
|
-
hiddenOperations.push(...(sets?.hidden ?? []).map((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,
|
|
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
|
-
|
|
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 ?
|
|
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
|
}
|
package/dist/actions/index.d.ts
CHANGED
package/dist/actions/index.js
CHANGED
package/dist/actions/lists.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAddressPointer } from "applesauce-core/helpers";
|
|
2
|
-
import {
|
|
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,
|
|
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
|
|
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 }) {
|
|
@@ -18,9 +18,9 @@ export function AddInboxRelay(relay) {
|
|
|
18
18
|
if (typeof relay === "string")
|
|
19
19
|
relay = [relay];
|
|
20
20
|
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const draft = mailboxes
|
|
22
|
+
? await factory.modifyTags(mailboxes, ...relay.map(addInboxRelay))
|
|
23
|
+
: await factory.build({ kind: kinds.RelayList }, modifyPublicTags(...relay.map(addInboxRelay)));
|
|
24
24
|
const signed = await factory.sign(draft);
|
|
25
25
|
yield signed;
|
|
26
26
|
};
|
|
@@ -32,7 +32,7 @@ export function RemoveInboxRelay(relay) {
|
|
|
32
32
|
relay = [relay];
|
|
33
33
|
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
34
34
|
if (!mailboxes)
|
|
35
|
-
|
|
35
|
+
return;
|
|
36
36
|
const draft = await factory.modifyTags(mailboxes, ...relay.map(removeInboxRelay));
|
|
37
37
|
const signed = await factory.sign(draft);
|
|
38
38
|
yield signed;
|
|
@@ -44,9 +44,9 @@ export function AddOutboxRelay(relay) {
|
|
|
44
44
|
if (typeof relay === "string")
|
|
45
45
|
relay = [relay];
|
|
46
46
|
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const draft = mailboxes
|
|
48
|
+
? await factory.modifyTags(mailboxes, ...relay.map(addOutboxRelay))
|
|
49
|
+
: await factory.build({ kind: kinds.RelayList }, modifyPublicTags(...relay.map(addOutboxRelay)));
|
|
50
50
|
const signed = await factory.sign(draft);
|
|
51
51
|
yield signed;
|
|
52
52
|
};
|
|
@@ -58,7 +58,7 @@ export function RemoveOutboxRelay(relay) {
|
|
|
58
58
|
relay = [relay];
|
|
59
59
|
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
60
60
|
if (!mailboxes)
|
|
61
|
-
|
|
61
|
+
return;
|
|
62
62
|
const draft = await factory.modifyTags(mailboxes, ...relay.map(removeOutboxRelay));
|
|
63
63
|
const signed = await factory.sign(draft);
|
|
64
64
|
yield signed;
|
package/dist/actions/pins.d.ts
CHANGED
|
@@ -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 */
|
package/dist/actions/pins.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
20
|
-
const
|
|
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
|
}
|
package/dist/actions/profile.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { kinds } from "nostr-tools";
|
|
2
|
-
import {
|
|
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 },
|
|
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,
|
|
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,
|
|
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 },
|
|
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 ?
|
|
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
|
|
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/
|
|
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
|
|
@@ -8,10 +8,11 @@ import { GiftWrapBlueprint, WrappedMessageBlueprint, WrappedMessageReplyBlueprin
|
|
|
8
8
|
* @returns Signed gift wrapped messages to send
|
|
9
9
|
*/
|
|
10
10
|
export function SendWrappedMessage(participants, message, opts) {
|
|
11
|
-
return async function* ({ factory }) {
|
|
11
|
+
return async function* ({ factory, self }) {
|
|
12
12
|
const rumor = await factory.create(WrappedMessageBlueprint, participants, message, opts);
|
|
13
|
-
// Get the pubkeys to send this message to
|
|
14
|
-
const pubkeys = getConversationParticipants(rumor);
|
|
13
|
+
// Get the pubkeys to send this message to and ensure the sender is included
|
|
14
|
+
const pubkeys = new Set(getConversationParticipants(rumor));
|
|
15
|
+
pubkeys.add(self);
|
|
15
16
|
for (const pubkey of pubkeys) {
|
|
16
17
|
yield await factory.create(GiftWrapBlueprint, pubkey, rumor, opts);
|
|
17
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-actions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.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": "^
|
|
36
|
-
"applesauce-factory": "^
|
|
35
|
+
"applesauce-core": "^3.0.0",
|
|
36
|
+
"applesauce-factory": "^3.0.0",
|
|
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": "^
|
|
43
|
+
"applesauce-signers": "^3.0.0",
|
|
44
44
|
"nanoid": "^5.1.5",
|
|
45
45
|
"typescript": "^5.8.3",
|
|
46
46
|
"vitest": "^3.2.3"
|