applesauce-actions 0.11.0 → 1.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/README.md +42 -0
- package/dist/__tests__/action-hub.test.d.ts +1 -0
- package/dist/__tests__/action-hub.test.js +67 -0
- package/dist/__tests__/fake-user.d.ts +10 -0
- package/dist/__tests__/fake-user.js +32 -0
- package/dist/action-hub.d.ts +36 -0
- package/dist/action-hub.js +49 -0
- package/dist/actions/__tests__/blossom.test.d.ts +1 -0
- package/dist/actions/__tests__/blossom.test.js +93 -0
- package/dist/actions/__tests__/bookmarks.test.d.ts +1 -0
- package/dist/actions/__tests__/bookmarks.test.js +24 -0
- package/dist/actions/__tests__/contacts.test.d.ts +1 -0
- package/dist/actions/__tests__/contacts.test.js +53 -0
- package/dist/actions/__tests__/follow-sets.test.d.ts +1 -0
- package/dist/actions/__tests__/follow-sets.test.js +80 -0
- package/dist/actions/__tests__/mute.test.d.ts +1 -0
- package/dist/actions/__tests__/mute.test.js +67 -0
- package/dist/actions/blocked-relays.d.ts +10 -0
- package/dist/actions/blocked-relays.js +48 -0
- package/dist/actions/blossom.d.ts +9 -0
- package/dist/actions/blossom.js +52 -0
- package/dist/actions/bookmarks.d.ts +24 -0
- package/dist/actions/bookmarks.js +58 -0
- package/dist/actions/contacts.d.ts +7 -0
- package/dist/actions/contacts.js +35 -0
- package/dist/actions/dm-relays.d.ts +7 -0
- package/dist/actions/dm-relays.js +38 -0
- package/dist/actions/favorite-relays.d.ts +18 -0
- package/dist/actions/favorite-relays.js +75 -0
- package/dist/actions/follow-sets.d.ts +43 -0
- package/dist/actions/follow-sets.js +71 -0
- package/dist/actions/index.d.ts +13 -0
- package/dist/actions/index.js +13 -0
- package/dist/actions/mailboxes.d.ts +11 -0
- package/dist/actions/mailboxes.js +66 -0
- package/dist/actions/mute.d.ts +19 -0
- package/dist/actions/mute.js +79 -0
- package/dist/actions/pins.d.ts +8 -0
- package/dist/actions/pins.js +33 -0
- package/dist/actions/profile.d.ts +6 -0
- package/dist/actions/profile.js +22 -0
- package/dist/actions/relay-sets.d.ts +19 -0
- package/dist/actions/relay-sets.js +44 -0
- package/dist/actions/search-relays.d.ts +10 -0
- package/dist/actions/search-relays.js +48 -0
- package/dist/helpers/observable.d.ts +3 -0
- package/dist/helpers/observable.js +20 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +18 -6
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BLOSSOM_SERVER_LIST_KIND } from "applesauce-core/helpers/blossom";
|
|
2
|
+
import { modifyPublicTags } from "applesauce-factory/operations/event";
|
|
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
|
+
/** An action that adds a server to the Blossom servers event */
|
|
11
|
+
export function AddBlossomServer(server) {
|
|
12
|
+
return async function* ({ events, factory, self }) {
|
|
13
|
+
const servers = getBlossomServersEvent(events, self);
|
|
14
|
+
const operation = Array.isArray(server) ? server.map((s) => addBlossomServerTag(s)) : addBlossomServerTag(server);
|
|
15
|
+
const draft = await factory.modifyTags(servers, operation);
|
|
16
|
+
yield await factory.sign(draft);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** An action that removes a server from the Blossom servers event */
|
|
20
|
+
export function RemoveBlossomServer(server) {
|
|
21
|
+
return async function* ({ events, factory, self }) {
|
|
22
|
+
const servers = getBlossomServersEvent(events, self);
|
|
23
|
+
const operation = Array.isArray(server)
|
|
24
|
+
? server.map((s) => removeBlossomServerTag(s))
|
|
25
|
+
: removeBlossomServerTag(server);
|
|
26
|
+
const draft = await factory.modifyTags(servers, operation);
|
|
27
|
+
yield await factory.sign(draft);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Makes a specific Blossom server the default server (move it to the top of the list) */
|
|
31
|
+
export function SetDefaultBlossomServer(server) {
|
|
32
|
+
return async function* ({ events, factory, self }) {
|
|
33
|
+
const servers = getBlossomServersEvent(events, self);
|
|
34
|
+
const prependTag = (tag) => (tags) => [tag, ...tags];
|
|
35
|
+
const draft = await factory.modifyTags(servers, [
|
|
36
|
+
removeBlossomServerTag(server),
|
|
37
|
+
prependTag(["server", String(server)]),
|
|
38
|
+
]);
|
|
39
|
+
yield await factory.sign(draft);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Creates a new Blossom servers event */
|
|
43
|
+
export function NewBlossomServers(servers) {
|
|
44
|
+
return async function* ({ events, factory, self }) {
|
|
45
|
+
const existing = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
|
|
46
|
+
if (existing)
|
|
47
|
+
throw new Error("Blossom servers event already exists");
|
|
48
|
+
const operations = servers ? servers.map((s) => addBlossomServerTag(s)) : [];
|
|
49
|
+
const draft = await factory.build({ kind: BLOSSOM_SERVER_LIST_KIND }, modifyPublicTags(...operations));
|
|
50
|
+
yield await factory.sign(draft);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NostrEvent } from "nostr-tools";
|
|
2
|
+
import { Action } from "../action-hub.js";
|
|
3
|
+
/**
|
|
4
|
+
* An action that adds a note or article to the bookmark list or a bookmark set
|
|
5
|
+
* @param event the event to bookmark
|
|
6
|
+
* @param identifier the "d" tag of the bookmark set
|
|
7
|
+
* @param hidden set to true to add to hidden bookmarks
|
|
8
|
+
*/
|
|
9
|
+
export declare function BookmarkEvent(event: NostrEvent, identifier?: string, hidden?: boolean): Action;
|
|
10
|
+
/**
|
|
11
|
+
* An action that removes a note or article from the bookmark list or bookmark set
|
|
12
|
+
* @param event the event to remove from bookmarks
|
|
13
|
+
* @param identifier the "d" tag of the bookmark set
|
|
14
|
+
* @param hidden set to true to remove from hidden bookmarks
|
|
15
|
+
*/
|
|
16
|
+
export declare function UnbookmarkEvent(event: NostrEvent, identifier: string, hidden?: boolean): Action;
|
|
17
|
+
/** An action that creates a new bookmark list for a user */
|
|
18
|
+
export declare function CreateBookmarkList(bookmarks?: NostrEvent[]): Action;
|
|
19
|
+
/** An action that creates a new bookmark set for a user */
|
|
20
|
+
export declare function CreateBookmarkSet(title: string, description: string, additional: {
|
|
21
|
+
image?: string;
|
|
22
|
+
hidden?: NostrEvent[];
|
|
23
|
+
public?: NostrEvent[];
|
|
24
|
+
}): Action;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { kinds } from "nostr-tools";
|
|
2
|
+
import { addEventBookmarkTag, removeEventBookmarkTag } from "applesauce-factory/operations/tag";
|
|
3
|
+
import { modifyHiddenTags, modifyPublicTags, setListDescription, setListImage, setListTitle, } from "applesauce-factory/operations/event";
|
|
4
|
+
function getBookmarkEvent(events, self, identifier) {
|
|
5
|
+
return events.getReplaceable(identifier ? kinds.Bookmarksets : kinds.BookmarkList, self, identifier);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* An action that adds a note or article to the bookmark list or a bookmark set
|
|
9
|
+
* @param event the event to bookmark
|
|
10
|
+
* @param identifier the "d" tag of the bookmark set
|
|
11
|
+
* @param hidden set to true to add to hidden bookmarks
|
|
12
|
+
*/
|
|
13
|
+
export function BookmarkEvent(event, identifier, hidden = false) {
|
|
14
|
+
return async function* ({ events, factory, self }) {
|
|
15
|
+
const bookmarks = getBookmarkEvent(events, self, identifier);
|
|
16
|
+
if (!bookmarks)
|
|
17
|
+
throw new Error("Cant find bookmarks");
|
|
18
|
+
const operation = addEventBookmarkTag(event);
|
|
19
|
+
const draft = await factory.modifyTags(bookmarks, hidden ? { hidden: operation } : operation);
|
|
20
|
+
yield await factory.sign(draft);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* An action that removes a note or article from the bookmark list or bookmark set
|
|
25
|
+
* @param event the event to remove from bookmarks
|
|
26
|
+
* @param identifier the "d" tag of the bookmark set
|
|
27
|
+
* @param hidden set to true to remove from hidden bookmarks
|
|
28
|
+
*/
|
|
29
|
+
export function UnbookmarkEvent(event, identifier, hidden = false) {
|
|
30
|
+
return async function* ({ events, factory, self }) {
|
|
31
|
+
const bookmarks = getBookmarkEvent(events, self, identifier);
|
|
32
|
+
if (!bookmarks)
|
|
33
|
+
throw new Error("Cant find bookmarks");
|
|
34
|
+
const operation = removeEventBookmarkTag(event);
|
|
35
|
+
const draft = await factory.modifyTags(bookmarks, hidden ? { hidden: operation } : operation);
|
|
36
|
+
yield await factory.sign(draft);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** An action that creates a new bookmark list for a user */
|
|
40
|
+
export function CreateBookmarkList(bookmarks) {
|
|
41
|
+
return async function* ({ events, factory, self }) {
|
|
42
|
+
const existing = getBookmarkEvent(events, self);
|
|
43
|
+
if (existing)
|
|
44
|
+
throw new Error("Bookmark list already exists");
|
|
45
|
+
const draft = await factory.build({ kind: kinds.BookmarkList }, bookmarks ? modifyPublicTags(...bookmarks.map(addEventBookmarkTag)) : undefined);
|
|
46
|
+
yield await factory.sign(draft);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** An action that creates a new bookmark set for a user */
|
|
50
|
+
export function CreateBookmarkSet(title, description, additional) {
|
|
51
|
+
return async function* ({ events, factory, self }) {
|
|
52
|
+
const existing = getBookmarkEvent(events, self);
|
|
53
|
+
if (existing)
|
|
54
|
+
throw new Error("Bookmark list already exists");
|
|
55
|
+
const draft = await factory.process({ 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);
|
|
56
|
+
yield await factory.sign(draft);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Action } from "../action-hub.js";
|
|
2
|
+
/** An action that adds a pubkey to a users contacts event */
|
|
3
|
+
export declare function FollowUser(pubkey: string, relay?: string, hidden?: boolean): Action;
|
|
4
|
+
/** An action that removes a pubkey from a users contacts event */
|
|
5
|
+
export declare function UnfollowUser(pubkey: string, hidden?: boolean): Action;
|
|
6
|
+
/** 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;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { kinds } from "nostr-tools";
|
|
2
|
+
import { addPubkeyTag, removePubkeyTag } from "applesauce-factory/operations/tag";
|
|
3
|
+
/** An action that adds a pubkey to a users contacts event */
|
|
4
|
+
export function FollowUser(pubkey, relay, hidden = false) {
|
|
5
|
+
return async function* ({ events, factory, self }) {
|
|
6
|
+
const contacts = events.getReplaceable(kinds.Contacts, self);
|
|
7
|
+
if (!contacts)
|
|
8
|
+
throw new Error("Missing contacts event");
|
|
9
|
+
const pointer = { pubkey, relays: relay ? [relay] : undefined };
|
|
10
|
+
const operation = addPubkeyTag(pointer);
|
|
11
|
+
const draft = await factory.modifyTags(contacts, hidden ? { hidden: operation } : operation);
|
|
12
|
+
yield await factory.sign(draft);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** An action that removes a pubkey from a users contacts event */
|
|
16
|
+
export function UnfollowUser(pubkey, hidden = false) {
|
|
17
|
+
return async function* ({ events, factory, self }) {
|
|
18
|
+
const contacts = events.getReplaceable(kinds.Contacts, self);
|
|
19
|
+
if (!contacts)
|
|
20
|
+
throw new Error("Missing contacts event");
|
|
21
|
+
const operation = removePubkeyTag(pubkey);
|
|
22
|
+
const draft = await factory.modifyTags(contacts, hidden ? { hidden: operation } : operation);
|
|
23
|
+
yield await factory.sign(draft);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** An action that creates a new kind 3 contacts lists, throws if a contact list already exists */
|
|
27
|
+
export function NewContacts(pubkeys) {
|
|
28
|
+
return async function* ({ events, factory, self }) {
|
|
29
|
+
const contacts = events.getReplaceable(kinds.Contacts, self);
|
|
30
|
+
if (contacts)
|
|
31
|
+
throw new Error("Contact list already exists");
|
|
32
|
+
const draft = await factory.process({ kind: kinds.Contacts, tags: pubkeys?.map((p) => ["p", p]) });
|
|
33
|
+
yield await factory.sign(draft);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Action } from "../action-hub.js";
|
|
2
|
+
/** An action that adds a relay to the 10050 DM relays event */
|
|
3
|
+
export declare function AddDMRelay(relay: string | string[]): Action;
|
|
4
|
+
/** An action that removes a relay from the 10050 DM relays event */
|
|
5
|
+
export declare function RemoveDMRelay(relay: string | string[]): Action;
|
|
6
|
+
/** Creates a new DM relays event */
|
|
7
|
+
export declare function NewDMRelays(relays?: string[]): Action;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { modifyPublicTags } from "applesauce-factory/operations/event";
|
|
2
|
+
import { addRelayTag, removeRelayTag } from "applesauce-factory/operations/tag/relay";
|
|
3
|
+
import { kinds } from "nostr-tools";
|
|
4
|
+
function getDMRelaysEvent(events, self) {
|
|
5
|
+
const event = events.getReplaceable(kinds.DirectMessageRelaysList, self);
|
|
6
|
+
if (!event)
|
|
7
|
+
throw new Error("Can't find DM relays event");
|
|
8
|
+
return event;
|
|
9
|
+
}
|
|
10
|
+
/** An action that adds a relay to the 10050 DM relays event */
|
|
11
|
+
export function AddDMRelay(relay) {
|
|
12
|
+
return async function* ({ events, factory, self }) {
|
|
13
|
+
const dmRelays = getDMRelaysEvent(events, self);
|
|
14
|
+
const operation = Array.isArray(relay) ? relay.map((r) => addRelayTag(r)) : addRelayTag(relay);
|
|
15
|
+
const draft = await factory.modifyTags(dmRelays, operation);
|
|
16
|
+
yield await factory.sign(draft);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** An action that removes a relay from the 10050 DM relays event */
|
|
20
|
+
export function RemoveDMRelay(relay) {
|
|
21
|
+
return async function* ({ events, factory, self }) {
|
|
22
|
+
const dmRelays = getDMRelaysEvent(events, self);
|
|
23
|
+
const operation = Array.isArray(relay) ? relay.map((r) => removeRelayTag(r)) : removeRelayTag(relay);
|
|
24
|
+
const draft = await factory.modifyTags(dmRelays, operation);
|
|
25
|
+
yield await factory.sign(draft);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Creates a new DM relays event */
|
|
29
|
+
export function NewDMRelays(relays) {
|
|
30
|
+
return async function* ({ events, factory, self }) {
|
|
31
|
+
const dmRelays = events.getReplaceable(kinds.DirectMessageRelaysList, self);
|
|
32
|
+
if (dmRelays)
|
|
33
|
+
throw new Error("DM relays event already exists");
|
|
34
|
+
const operations = relays?.map((r) => addRelayTag(r)) ?? [];
|
|
35
|
+
const draft = await factory.build({ kind: kinds.DirectMessageRelaysList }, modifyPublicTags(...operations));
|
|
36
|
+
yield await factory.sign(draft);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AddressPointer } from "nostr-tools/nip19";
|
|
2
|
+
import { Action } from "../action-hub.js";
|
|
3
|
+
/** An action that adds a relay to the 10012 favorite relays event */
|
|
4
|
+
export declare function AddFavoriteRelay(relay: string | string[], hidden?: boolean): Action;
|
|
5
|
+
/** An action that removes a relay from the 10012 favorite relays event */
|
|
6
|
+
export declare function RemoveFavoriteRelay(relay: string | string[], hidden?: boolean): Action;
|
|
7
|
+
/** An action that adds a relay set to the 10012 favorite relays event */
|
|
8
|
+
export declare function AddFavoriteRelaySet(addr: AddressPointer[] | AddressPointer, hidden?: boolean): Action;
|
|
9
|
+
/** An action that removes a relay set from the 10012 favorite relays event */
|
|
10
|
+
export declare function RemoveFavoriteRelaySet(addr: AddressPointer[] | AddressPointer, hidden?: boolean): Action;
|
|
11
|
+
/** Creates a new favorite relays event */
|
|
12
|
+
export declare function NewFavoriteRelays(relays?: string[] | {
|
|
13
|
+
public?: string[];
|
|
14
|
+
hidden?: string[];
|
|
15
|
+
}, sets?: AddressPointer[] | {
|
|
16
|
+
public?: AddressPointer[];
|
|
17
|
+
hidden?: AddressPointer[];
|
|
18
|
+
}): Action;
|
|
@@ -0,0 +1,75 @@
|
|
|
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";
|
|
4
|
+
function getFavoriteRelaysEvent(events, self) {
|
|
5
|
+
const event = events.getReplaceable(FAVORITE_RELAYS_KIND, self);
|
|
6
|
+
if (!event)
|
|
7
|
+
throw new Error("Can't find favorite relays event");
|
|
8
|
+
return event;
|
|
9
|
+
}
|
|
10
|
+
/** An action that adds a relay to the 10012 favorite relays event */
|
|
11
|
+
export function AddFavoriteRelay(relay, hidden = false) {
|
|
12
|
+
return async function* ({ events, factory, self }) {
|
|
13
|
+
const favorites = getFavoriteRelaysEvent(events, self);
|
|
14
|
+
const operation = Array.isArray(relay) ? relay.map((r) => addRelayTag(r)) : addRelayTag(relay);
|
|
15
|
+
const draft = await factory.modifyTags(favorites, hidden ? { hidden: operation } : operation);
|
|
16
|
+
yield await factory.sign(draft);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** An action that removes a relay from the 10012 favorite relays event */
|
|
20
|
+
export function RemoveFavoriteRelay(relay, hidden = false) {
|
|
21
|
+
return async function* ({ events, factory, self }) {
|
|
22
|
+
const favorites = getFavoriteRelaysEvent(events, self);
|
|
23
|
+
const operation = Array.isArray(relay) ? relay.map((r) => removeRelayTag(r)) : removeRelayTag(relay);
|
|
24
|
+
const draft = await factory.modifyTags(favorites, hidden ? { hidden: operation } : operation);
|
|
25
|
+
yield await factory.sign(draft);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** An action that adds a relay set to the 10012 favorite relays event */
|
|
29
|
+
export function AddFavoriteRelaySet(addr, hidden = false) {
|
|
30
|
+
return async function* ({ events, factory, self }) {
|
|
31
|
+
const favorites = getFavoriteRelaysEvent(events, self);
|
|
32
|
+
const operation = Array.isArray(addr) ? addr.map((a) => addCoordinateTag(a)) : addCoordinateTag(addr);
|
|
33
|
+
const draft = await factory.modifyTags(favorites, hidden ? { hidden: operation } : operation);
|
|
34
|
+
yield await factory.sign(draft);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** An action that removes a relay set from the 10012 favorite relays event */
|
|
38
|
+
export function RemoveFavoriteRelaySet(addr, hidden = false) {
|
|
39
|
+
return async function* ({ events, factory, self }) {
|
|
40
|
+
const favorites = getFavoriteRelaysEvent(events, self);
|
|
41
|
+
const operation = Array.isArray(addr) ? addr.map((a) => removeCoordinateTag(a)) : removeCoordinateTag(addr);
|
|
42
|
+
const draft = await factory.modifyTags(favorites, hidden ? { hidden: operation } : operation);
|
|
43
|
+
yield await factory.sign(draft);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Creates a new favorite relays event */
|
|
47
|
+
export function NewFavoriteRelays(relays, sets) {
|
|
48
|
+
return async function* ({ events, factory, self }) {
|
|
49
|
+
const favorites = events.getReplaceable(FAVORITE_RELAYS_KIND, self);
|
|
50
|
+
if (favorites)
|
|
51
|
+
throw new Error("Favorite relays event already exists");
|
|
52
|
+
let publicOperations = [];
|
|
53
|
+
let hiddenOperations = [];
|
|
54
|
+
if (Array.isArray(relays)) {
|
|
55
|
+
publicOperations.push(...relays.map((r) => addRelayTag(r)));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (relays?.public)
|
|
59
|
+
publicOperations.push(...(relays?.public ?? []).map((r) => addRelayTag(r)));
|
|
60
|
+
if (relays?.hidden)
|
|
61
|
+
hiddenOperations.push(...(relays?.hidden ?? []).map((r) => addRelayTag(r)));
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(sets)) {
|
|
64
|
+
publicOperations.push(...sets.map((s) => addCoordinateTag(s)));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (sets?.public)
|
|
68
|
+
publicOperations.push(...(sets?.public ?? []).map((s) => addCoordinateTag(s)));
|
|
69
|
+
if (sets?.hidden)
|
|
70
|
+
hiddenOperations.push(...(sets?.hidden ?? []).map((s) => addCoordinateTag(s)));
|
|
71
|
+
}
|
|
72
|
+
const draft = await factory.build({ kind: FAVORITE_RELAYS_KIND }, publicOperations.length ? modifyPublicTags(...publicOperations) : undefined, hiddenOperations.length ? modifyHiddenTags(...hiddenOperations) : undefined);
|
|
73
|
+
yield await factory.sign(draft);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NostrEvent } from "nostr-tools";
|
|
2
|
+
import { Action } from "../action-hub.js";
|
|
3
|
+
import { ProfilePointer } from "nostr-tools/nip19";
|
|
4
|
+
/**
|
|
5
|
+
* An action that creates a new follow set
|
|
6
|
+
* @param identifier the "d" tag of the follow set
|
|
7
|
+
* @param pubkeys the pubkeys to add to the follow set
|
|
8
|
+
* @param hidden set to true to create a hidden follow set
|
|
9
|
+
* @throws if a follow set already exists
|
|
10
|
+
*/
|
|
11
|
+
export declare function CreateFollowSet(title: string, options?: {
|
|
12
|
+
description?: string;
|
|
13
|
+
image?: string;
|
|
14
|
+
public?: (string | ProfilePointer)[];
|
|
15
|
+
hidden?: (string | ProfilePointer)[];
|
|
16
|
+
}): Action;
|
|
17
|
+
/**
|
|
18
|
+
* An action that adds a pubkey to a follow set
|
|
19
|
+
* @param pubkey the pubkey to add to the set
|
|
20
|
+
* @param identifier the "d" tag of the follow set
|
|
21
|
+
* @param hidden set to true to add to hidden follows
|
|
22
|
+
* @throws if the follow set does not exist
|
|
23
|
+
*/
|
|
24
|
+
export declare function AddUserToFollowSet(pubkey: (string | ProfilePointer)[] | string | ProfilePointer, identifier: NostrEvent | string, hidden?: boolean): Action;
|
|
25
|
+
/**
|
|
26
|
+
* An action that removes a pubkey from a follow set
|
|
27
|
+
* @param pubkey the pubkey to remove from the set
|
|
28
|
+
* @param identifier the "d" tag of the follow set
|
|
29
|
+
* @param hidden set to true to remove from hidden follows
|
|
30
|
+
* @throws if the follow set does not exist
|
|
31
|
+
*/
|
|
32
|
+
export declare function RemoveUserFromFollowSet(pubkey: (string | ProfilePointer)[] | string | ProfilePointer, identifier: NostrEvent | string, hidden?: boolean): Action;
|
|
33
|
+
/**
|
|
34
|
+
* An action that updates the title, description, or image of a follow set
|
|
35
|
+
* @param identifier the "d" tag of the follow set
|
|
36
|
+
* @param info the new information for the follow set
|
|
37
|
+
* @throws if the follow set does not exist
|
|
38
|
+
*/
|
|
39
|
+
export declare function UpdateFollowSetInformation(identifier: string, info: {
|
|
40
|
+
title?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
image?: string;
|
|
43
|
+
}): Action;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { kinds } from "nostr-tools";
|
|
2
|
+
import { addPubkeyTag, removePubkeyTag } from "applesauce-factory/operations/tag";
|
|
3
|
+
import { modifyHiddenTags, modifyPublicTags, setListDescription, setListImage, setListTitle, } from "applesauce-factory/operations/event";
|
|
4
|
+
function getFollowSetEvent(events, self, identifier) {
|
|
5
|
+
const set = typeof identifier === "string" ? events.getReplaceable(kinds.Followsets, self, identifier) : identifier;
|
|
6
|
+
if (!set)
|
|
7
|
+
throw new Error("Can't find follow set");
|
|
8
|
+
if (set.kind !== kinds.Followsets)
|
|
9
|
+
throw new Error("Event is not a follow set");
|
|
10
|
+
return set;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An action that creates a new follow set
|
|
14
|
+
* @param identifier the "d" tag of the follow set
|
|
15
|
+
* @param pubkeys the pubkeys to add to the follow set
|
|
16
|
+
* @param hidden set to true to create a hidden follow set
|
|
17
|
+
* @throws if a follow set already exists
|
|
18
|
+
*/
|
|
19
|
+
export function CreateFollowSet(title, options) {
|
|
20
|
+
return async function* ({ factory }) {
|
|
21
|
+
const draft = await factory.build({ kind: kinds.Followsets },
|
|
22
|
+
// set list information
|
|
23
|
+
setListTitle(title), options?.description ? setListDescription(options.description) : undefined, options?.image ? setListImage(options.image) : undefined,
|
|
24
|
+
// add pubkey tags
|
|
25
|
+
options?.public ? modifyPublicTags(...options.public.map((p) => addPubkeyTag(p))) : undefined, options?.hidden ? modifyHiddenTags(...options.hidden.map((p) => addPubkeyTag(p))) : undefined);
|
|
26
|
+
yield await factory.sign(draft);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An action that adds a pubkey to a follow set
|
|
31
|
+
* @param pubkey the pubkey to add to the set
|
|
32
|
+
* @param identifier the "d" tag of the follow set
|
|
33
|
+
* @param hidden set to true to add to hidden follows
|
|
34
|
+
* @throws if the follow set does not exist
|
|
35
|
+
*/
|
|
36
|
+
export function AddUserToFollowSet(pubkey, identifier, hidden = false) {
|
|
37
|
+
return async function* ({ events, factory, self }) {
|
|
38
|
+
const follows = getFollowSetEvent(events, self, identifier);
|
|
39
|
+
const operations = Array.isArray(pubkey) ? pubkey.map((p) => addPubkeyTag(p)) : addPubkeyTag(pubkey);
|
|
40
|
+
const draft = await factory.modifyTags(follows, hidden ? { hidden: operations } : operations);
|
|
41
|
+
yield await factory.sign(draft);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* An action that removes a pubkey from a follow set
|
|
46
|
+
* @param pubkey the pubkey to remove from the set
|
|
47
|
+
* @param identifier the "d" tag of the follow set
|
|
48
|
+
* @param hidden set to true to remove from hidden follows
|
|
49
|
+
* @throws if the follow set does not exist
|
|
50
|
+
*/
|
|
51
|
+
export function RemoveUserFromFollowSet(pubkey, identifier, hidden = false) {
|
|
52
|
+
return async function* ({ events, factory, self }) {
|
|
53
|
+
const follows = getFollowSetEvent(events, self, identifier);
|
|
54
|
+
const operations = Array.isArray(pubkey) ? pubkey.map((p) => removePubkeyTag(p)) : removePubkeyTag(pubkey);
|
|
55
|
+
const draft = await factory.modifyTags(follows, hidden ? { hidden: operations } : operations);
|
|
56
|
+
yield await factory.sign(draft);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* An action that updates the title, description, or image of a follow set
|
|
61
|
+
* @param identifier the "d" tag of the follow set
|
|
62
|
+
* @param info the new information for the follow set
|
|
63
|
+
* @throws if the follow set does not exist
|
|
64
|
+
*/
|
|
65
|
+
export function UpdateFollowSetInformation(identifier, info) {
|
|
66
|
+
return async function* ({ events, factory, self }) {
|
|
67
|
+
const follows = getFollowSetEvent(events, self, identifier);
|
|
68
|
+
const draft = await factory.modify(follows, info?.title ? setListTitle(info.title) : undefined, info?.description ? setListDescription(info.description) : undefined, info?.image ? setListImage(info.image) : undefined);
|
|
69
|
+
yield await factory.sign(draft);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./blocked-relays.js";
|
|
2
|
+
export * from "./blossom.js";
|
|
3
|
+
export * from "./bookmarks.js";
|
|
4
|
+
export * from "./contacts.js";
|
|
5
|
+
export * from "./dm-relays.js";
|
|
6
|
+
export * from "./favorite-relays.js";
|
|
7
|
+
export * from "./follow-sets.js";
|
|
8
|
+
export * from "./mailboxes.js";
|
|
9
|
+
export * from "./mute.js";
|
|
10
|
+
export * from "./pins.js";
|
|
11
|
+
export * from "./profile.js";
|
|
12
|
+
export * from "./relay-sets.js";
|
|
13
|
+
export * from "./search-relays.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./blocked-relays.js";
|
|
2
|
+
export * from "./blossom.js";
|
|
3
|
+
export * from "./bookmarks.js";
|
|
4
|
+
export * from "./contacts.js";
|
|
5
|
+
export * from "./dm-relays.js";
|
|
6
|
+
export * from "./favorite-relays.js";
|
|
7
|
+
export * from "./follow-sets.js";
|
|
8
|
+
export * from "./mailboxes.js";
|
|
9
|
+
export * from "./mute.js";
|
|
10
|
+
export * from "./pins.js";
|
|
11
|
+
export * from "./profile.js";
|
|
12
|
+
export * from "./relay-sets.js";
|
|
13
|
+
export * from "./search-relays.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Action } from "../action-hub.js";
|
|
2
|
+
/** An action to create a new kind 10002 relay list event */
|
|
3
|
+
export declare function CreateMailboxes(inboxes: string[], outboxes: string[]): Action;
|
|
4
|
+
/** An action to add an inbox relay to the kind 10002 relay list */
|
|
5
|
+
export declare function AddInboxRelay(relay: string | string[]): Action;
|
|
6
|
+
/** An action to remove an inbox relay from the kind 10002 relay list */
|
|
7
|
+
export declare function RemoveInboxRelay(relay: string | string[]): Action;
|
|
8
|
+
/** An action to add an outbox relay to the kind 10002 relay list */
|
|
9
|
+
export declare function AddOutboxRelay(relay: string | string[]): Action;
|
|
10
|
+
/** An action to remove an outbox relay from the kind 10002 relay list */
|
|
11
|
+
export declare function RemoveOutboxRelay(relay: string | string[]): Action;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { kinds } from "nostr-tools";
|
|
2
|
+
import { addInboxRelay, addOutboxRelay, removeInboxRelay, removeOutboxRelay } from "applesauce-factory/operations/tag";
|
|
3
|
+
import { modifyPublicTags } from "applesauce-factory/operations/event";
|
|
4
|
+
/** An action to create a new kind 10002 relay list event */
|
|
5
|
+
export function CreateMailboxes(inboxes, outboxes) {
|
|
6
|
+
return async function* ({ events, factory, self }) {
|
|
7
|
+
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
8
|
+
if (mailboxes)
|
|
9
|
+
throw new Error("Mailbox event already exists");
|
|
10
|
+
const draft = await factory.build({ kind: kinds.RelayList }, modifyPublicTags(...inboxes.map(addInboxRelay), ...outboxes.map(addOutboxRelay)));
|
|
11
|
+
const signed = await factory.sign(draft);
|
|
12
|
+
yield signed;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** An action to add an inbox relay to the kind 10002 relay list */
|
|
16
|
+
export function AddInboxRelay(relay) {
|
|
17
|
+
return async function* ({ events, factory, self }) {
|
|
18
|
+
if (typeof relay === "string")
|
|
19
|
+
relay = [relay];
|
|
20
|
+
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
21
|
+
if (!mailboxes)
|
|
22
|
+
throw new Error("Missing mailboxes event");
|
|
23
|
+
const draft = await factory.modifyTags(mailboxes, ...relay.map(addInboxRelay));
|
|
24
|
+
const signed = await factory.sign(draft);
|
|
25
|
+
yield signed;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** An action to remove an inbox relay from the kind 10002 relay list */
|
|
29
|
+
export function RemoveInboxRelay(relay) {
|
|
30
|
+
return async function* ({ events, factory, self }) {
|
|
31
|
+
if (typeof relay === "string")
|
|
32
|
+
relay = [relay];
|
|
33
|
+
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
34
|
+
if (!mailboxes)
|
|
35
|
+
throw new Error("Missing mailboxes event");
|
|
36
|
+
const draft = await factory.modifyTags(mailboxes, ...relay.map(removeInboxRelay));
|
|
37
|
+
const signed = await factory.sign(draft);
|
|
38
|
+
yield signed;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** An action to add an outbox relay to the kind 10002 relay list */
|
|
42
|
+
export function AddOutboxRelay(relay) {
|
|
43
|
+
return async function* ({ events, factory, self }) {
|
|
44
|
+
if (typeof relay === "string")
|
|
45
|
+
relay = [relay];
|
|
46
|
+
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
47
|
+
if (!mailboxes)
|
|
48
|
+
throw new Error("Missing mailboxes event");
|
|
49
|
+
const draft = await factory.modifyTags(mailboxes, ...relay.map(addOutboxRelay));
|
|
50
|
+
const signed = await factory.sign(draft);
|
|
51
|
+
yield signed;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** An action to remove an outbox relay from the kind 10002 relay list */
|
|
55
|
+
export function RemoveOutboxRelay(relay) {
|
|
56
|
+
return async function* ({ events, factory, self }) {
|
|
57
|
+
if (typeof relay === "string")
|
|
58
|
+
relay = [relay];
|
|
59
|
+
const mailboxes = events.getReplaceable(kinds.RelayList, self);
|
|
60
|
+
if (!mailboxes)
|
|
61
|
+
throw new Error("Missing mailboxes event");
|
|
62
|
+
const draft = await factory.modifyTags(mailboxes, ...relay.map(removeOutboxRelay));
|
|
63
|
+
const signed = await factory.sign(draft);
|
|
64
|
+
yield signed;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NostrEvent } from "nostr-tools";
|
|
2
|
+
import { EventPointer } from "nostr-tools/nip19";
|
|
3
|
+
import { Action } from "../action-hub.js";
|
|
4
|
+
/** An action that adds a pubkey to the mute list */
|
|
5
|
+
export declare function MuteUser(pubkey: string, hidden?: boolean): Action;
|
|
6
|
+
/** Removes a pubkey from the mute list */
|
|
7
|
+
export declare function UnmuteUser(pubkey: string, hidden?: boolean): Action;
|
|
8
|
+
/** Add a thread to the mute list */
|
|
9
|
+
export declare function MuteThread(thread: string | NostrEvent | EventPointer, hidden?: boolean): Action;
|
|
10
|
+
/** Removes a thread from the mute list */
|
|
11
|
+
export declare function UnmuteThread(thread: string | NostrEvent | EventPointer, hidden?: boolean): Action;
|
|
12
|
+
/** Add a word to the mute list */
|
|
13
|
+
export declare function MuteWord(word: string, hidden?: boolean): Action;
|
|
14
|
+
/** Removes a word from the mute list */
|
|
15
|
+
export declare function UnmuteWord(word: string, hidden?: boolean): Action;
|
|
16
|
+
/** Add a hashtag to the mute list */
|
|
17
|
+
export declare function MuteHashtag(hashtag: string, hidden?: boolean): Action;
|
|
18
|
+
/** Removes a hashtag from the mute list */
|
|
19
|
+
export declare function UnmuteHashtag(hashtag: string, hidden?: boolean): Action;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { addEventTag, addNameValueTag, addPubkeyTag, removeEventTag, removeNameValueTag, removePubkeyTag, } from "applesauce-factory/operations/tag";
|
|
2
|
+
import { kinds } from "nostr-tools";
|
|
3
|
+
function ensureMuteList(events, self) {
|
|
4
|
+
const mute = events.getReplaceable(kinds.Mutelist, self);
|
|
5
|
+
if (!mute)
|
|
6
|
+
throw new Error("No mute list found");
|
|
7
|
+
return mute;
|
|
8
|
+
}
|
|
9
|
+
/** An action that adds a pubkey to the mute list */
|
|
10
|
+
export function MuteUser(pubkey, hidden = false) {
|
|
11
|
+
return async function* ({ events, factory, self }) {
|
|
12
|
+
const mute = ensureMuteList(events, self);
|
|
13
|
+
const operation = addPubkeyTag(pubkey);
|
|
14
|
+
const draft = await factory.modifyTags(mute, hidden ? { hidden: operation } : operation);
|
|
15
|
+
yield await factory.sign(draft);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Removes a pubkey from the mute list */
|
|
19
|
+
export function UnmuteUser(pubkey, hidden = false) {
|
|
20
|
+
return async function* ({ events, factory, self }) {
|
|
21
|
+
const mute = ensureMuteList(events, self);
|
|
22
|
+
const draft = await factory.modifyTags(mute, hidden ? { hidden: removePubkeyTag(pubkey) } : removePubkeyTag(pubkey));
|
|
23
|
+
yield await factory.sign(draft);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Add a thread to the mute list */
|
|
27
|
+
export function MuteThread(thread, hidden = false) {
|
|
28
|
+
return async function* ({ events, factory, self }) {
|
|
29
|
+
const mute = ensureMuteList(events, self);
|
|
30
|
+
const operation = addEventTag(thread);
|
|
31
|
+
const draft = await factory.modifyTags(mute, hidden ? { hidden: operation } : operation);
|
|
32
|
+
yield await factory.sign(draft);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Removes a thread from the mute list */
|
|
36
|
+
export function UnmuteThread(thread, hidden = false) {
|
|
37
|
+
return async function* ({ events, factory, self }) {
|
|
38
|
+
const mute = ensureMuteList(events, self);
|
|
39
|
+
const operation = removeEventTag(thread);
|
|
40
|
+
const draft = await factory.modifyTags(mute, hidden ? { hidden: operation } : operation);
|
|
41
|
+
yield await factory.sign(draft);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Add a word to the mute list */
|
|
45
|
+
export function MuteWord(word, hidden = false) {
|
|
46
|
+
return async function* ({ events, factory, self }) {
|
|
47
|
+
const mute = ensureMuteList(events, self);
|
|
48
|
+
const operation = addNameValueTag(["word", word.toLocaleLowerCase()], true);
|
|
49
|
+
const draft = await factory.modifyTags(mute, hidden ? { hidden: operation } : operation);
|
|
50
|
+
yield await factory.sign(draft);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Removes a word from the mute list */
|
|
54
|
+
export function UnmuteWord(word, hidden = false) {
|
|
55
|
+
return async function* ({ events, factory, self }) {
|
|
56
|
+
const mute = ensureMuteList(events, self);
|
|
57
|
+
const operation = removeNameValueTag(["word", word.toLocaleLowerCase()]);
|
|
58
|
+
const draft = await factory.modifyTags(mute, hidden ? { hidden: operation } : operation);
|
|
59
|
+
yield await factory.sign(draft);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Add a hashtag to the mute list */
|
|
63
|
+
export function MuteHashtag(hashtag, hidden = false) {
|
|
64
|
+
return async function* ({ events, factory, self }) {
|
|
65
|
+
const mute = ensureMuteList(events, self);
|
|
66
|
+
const operation = addNameValueTag(["t", hashtag.toLocaleLowerCase()], true);
|
|
67
|
+
const draft = await factory.modifyTags(mute, hidden ? { hidden: operation } : operation);
|
|
68
|
+
yield await factory.sign(draft);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Removes a hashtag from the mute list */
|
|
72
|
+
export function UnmuteHashtag(hashtag, hidden = false) {
|
|
73
|
+
return async function* ({ events, factory, self }) {
|
|
74
|
+
const mute = ensureMuteList(events, self);
|
|
75
|
+
const operation = removeNameValueTag(["t", hashtag.toLocaleLowerCase()]);
|
|
76
|
+
const draft = await factory.modifyTags(mute, hidden ? { hidden: operation } : operation);
|
|
77
|
+
yield await factory.sign(draft);
|
|
78
|
+
};
|
|
79
|
+
}
|