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,8 @@
|
|
|
1
|
+
import { NostrEvent } from "nostr-tools";
|
|
2
|
+
import { Action } from "../action-hub.js";
|
|
3
|
+
/** An action that pins a note to the users pin list */
|
|
4
|
+
export declare function PinNote(note: NostrEvent): Action;
|
|
5
|
+
/** An action that removes an event from the users pin list */
|
|
6
|
+
export declare function UnpinNote(note: NostrEvent): Action;
|
|
7
|
+
/** An action that creates a new pin list for a user */
|
|
8
|
+
export declare function CreatePinList(pins?: NostrEvent[]): Action;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { kinds } from "nostr-tools";
|
|
2
|
+
import { addEventTag, removeEventTag } from "applesauce-factory/operations/tag";
|
|
3
|
+
import { modifyPublicTags } from "applesauce-factory/operations/event";
|
|
4
|
+
/** An action that pins a note to the users pin list */
|
|
5
|
+
export function PinNote(note) {
|
|
6
|
+
return async function* ({ events, factory, self }) {
|
|
7
|
+
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));
|
|
11
|
+
yield await factory.sign(draft);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** An action that removes an event from the users pin list */
|
|
15
|
+
export function UnpinNote(note) {
|
|
16
|
+
return async function* ({ events, factory, self }) {
|
|
17
|
+
const pins = events.getReplaceable(kinds.Pinlist, self);
|
|
18
|
+
if (!pins)
|
|
19
|
+
throw new Error("Missing pin list");
|
|
20
|
+
const draft = await factory.modifyTags(pins, removeEventTag(note.id));
|
|
21
|
+
yield await factory.sign(draft);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** An action that creates a new pin list for a user */
|
|
25
|
+
export function CreatePinList(pins = []) {
|
|
26
|
+
return async function* ({ events, factory, self }) {
|
|
27
|
+
const existing = events.getReplaceable(kinds.Pinlist, self);
|
|
28
|
+
if (existing)
|
|
29
|
+
throw new Error("Pin list already exists");
|
|
30
|
+
const draft = await factory.process({ kind: kinds.Pinlist }, modifyPublicTags(...pins.map((event) => addEventTag(event.id))));
|
|
31
|
+
yield await factory.sign(draft);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProfileContent } from "applesauce-core/helpers";
|
|
2
|
+
import { Action } from "../action-hub.js";
|
|
3
|
+
/** An action that creates a new kind 0 profile event for a user */
|
|
4
|
+
export declare function CreateProfile(content: ProfileContent): Action;
|
|
5
|
+
/** An action that updates a kind 0 profile evnet for a user */
|
|
6
|
+
export declare function UpdateProfile(content: Partial<ProfileContent>): Action;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { kinds } from "nostr-tools";
|
|
2
|
+
import { setProfileContent, updateProfileContent } from "applesauce-factory/operations/event";
|
|
3
|
+
/** An action that creates a new kind 0 profile event for a user */
|
|
4
|
+
export function CreateProfile(content) {
|
|
5
|
+
return async function* ({ events, factory, self }) {
|
|
6
|
+
const metadata = events.getReplaceable(kinds.Metadata, self);
|
|
7
|
+
if (metadata)
|
|
8
|
+
throw new Error("Profile already exists");
|
|
9
|
+
const draft = await factory.build({ kind: kinds.Metadata }, setProfileContent(content));
|
|
10
|
+
yield await factory.sign(draft);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** An action that updates a kind 0 profile evnet for a user */
|
|
14
|
+
export function UpdateProfile(content) {
|
|
15
|
+
return async function* ({ events, factory, self }) {
|
|
16
|
+
const metadata = events.getReplaceable(kinds.Metadata, self);
|
|
17
|
+
if (!metadata)
|
|
18
|
+
throw new Error("Profile does not exists");
|
|
19
|
+
const draft = await factory.modify(metadata, updateProfileContent(content));
|
|
20
|
+
yield await factory.sign(draft);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NostrEvent } from "nostr-tools";
|
|
2
|
+
import { Action } from "../action-hub.js";
|
|
3
|
+
/** An action that adds a relay to a relay set*/
|
|
4
|
+
export declare function AddRelayToRelaySet(relay: string | string[], identifier: NostrEvent | string, hidden?: boolean): Action;
|
|
5
|
+
/** An action that removes a relay from a relay set */
|
|
6
|
+
export declare function RemoveRelayFromRelaySet(relay: string | string[], identifier: NostrEvent | string, hidden?: boolean): Action;
|
|
7
|
+
/** An action that creates a new relay set */
|
|
8
|
+
export declare function CreateRelaySet(title: string, options?: {
|
|
9
|
+
description?: string;
|
|
10
|
+
image?: string;
|
|
11
|
+
public?: string[];
|
|
12
|
+
hidden?: string[];
|
|
13
|
+
}): Action;
|
|
14
|
+
/** An action that updates the title, description, or image of a relay set */
|
|
15
|
+
export declare function UpdateRelaySetInformation(identifier: string, info: {
|
|
16
|
+
title?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
image?: string;
|
|
19
|
+
}): Action;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { modifyHiddenTags, modifyPublicTags, setListDescription, setListImage, setListTitle, } from "applesauce-factory/operations/event";
|
|
2
|
+
import { addRelayTag, removeRelayTag } from "applesauce-factory/operations/tag";
|
|
3
|
+
import { kinds } from "nostr-tools";
|
|
4
|
+
function getRelaySetEvent(events, self, identifier) {
|
|
5
|
+
const set = typeof identifier === "string" ? events.getReplaceable(kinds.Relaysets, self, identifier) : identifier;
|
|
6
|
+
if (!set)
|
|
7
|
+
throw new Error("Can't find relay set");
|
|
8
|
+
if (set.kind !== kinds.Relaysets)
|
|
9
|
+
throw new Error("Event is not a relay set");
|
|
10
|
+
return set;
|
|
11
|
+
}
|
|
12
|
+
/** An action that adds a relay to a relay set*/
|
|
13
|
+
export function AddRelayToRelaySet(relay, identifier, hidden = false) {
|
|
14
|
+
return async function* ({ events, factory, self }) {
|
|
15
|
+
const relays = getRelaySetEvent(events, self, identifier);
|
|
16
|
+
const operations = Array.isArray(relay) ? relay.map((r) => addRelayTag(r)) : addRelayTag(relay);
|
|
17
|
+
const draft = await factory.modifyTags(relays, hidden ? { hidden: operations } : operations);
|
|
18
|
+
yield await factory.sign(draft);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** An action that removes a relay from a relay set */
|
|
22
|
+
export function RemoveRelayFromRelaySet(relay, identifier, hidden = false) {
|
|
23
|
+
return async function* ({ events, factory, self }) {
|
|
24
|
+
const relays = getRelaySetEvent(events, self, identifier);
|
|
25
|
+
const operations = Array.isArray(relay) ? relay.map((r) => removeRelayTag(r)) : removeRelayTag(relay);
|
|
26
|
+
const draft = await factory.modifyTags(relays, hidden ? { hidden: operations } : operations);
|
|
27
|
+
yield await factory.sign(draft);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** An action that creates a new relay set */
|
|
31
|
+
export function CreateRelaySet(title, options) {
|
|
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);
|
|
34
|
+
yield await factory.sign(draft);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** An action that updates the title, description, or image of a relay set */
|
|
38
|
+
export function UpdateRelaySetInformation(identifier, info) {
|
|
39
|
+
return async function* ({ events, factory, self }) {
|
|
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);
|
|
42
|
+
yield await factory.sign(draft);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Action } from "../action-hub.js";
|
|
2
|
+
/** An action that adds a relay to the 10007 search relays event */
|
|
3
|
+
export declare function AddSearchRelay(relay: string | string[], hidden?: boolean): Action;
|
|
4
|
+
/** An action that removes a relay from the 10007 search relays event */
|
|
5
|
+
export declare function RemoveSearchRelay(relay: string | string[], hidden?: boolean): Action;
|
|
6
|
+
/** Creates a new search relays event */
|
|
7
|
+
export declare function NewSearchRelays(relays?: string[] | {
|
|
8
|
+
public?: string[];
|
|
9
|
+
hidden?: string[];
|
|
10
|
+
}): Action;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations/event";
|
|
2
|
+
import { addRelayTag, removeRelayTag } from "applesauce-factory/operations/tag/relay";
|
|
3
|
+
import { kinds } from "nostr-tools";
|
|
4
|
+
function getSearchRelaysEvent(events, self) {
|
|
5
|
+
const event = events.getReplaceable(kinds.SearchRelaysList, self);
|
|
6
|
+
if (!event)
|
|
7
|
+
throw new Error("Can't find search relays event");
|
|
8
|
+
return event;
|
|
9
|
+
}
|
|
10
|
+
/** An action that adds a relay to the 10007 search relays event */
|
|
11
|
+
export function AddSearchRelay(relay, hidden = false) {
|
|
12
|
+
return async function* ({ events, factory, self }) {
|
|
13
|
+
const search = getSearchRelaysEvent(events, self);
|
|
14
|
+
const operation = Array.isArray(relay) ? relay.map((r) => addRelayTag(r)) : addRelayTag(relay);
|
|
15
|
+
const draft = await factory.modifyTags(search, hidden ? { hidden: operation } : operation);
|
|
16
|
+
yield await factory.sign(draft);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** An action that removes a relay from the 10007 search relays event */
|
|
20
|
+
export function RemoveSearchRelay(relay, hidden = false) {
|
|
21
|
+
return async function* ({ events, factory, self }) {
|
|
22
|
+
const search = getSearchRelaysEvent(events, self);
|
|
23
|
+
const operation = Array.isArray(relay) ? relay.map((r) => removeRelayTag(r)) : removeRelayTag(relay);
|
|
24
|
+
const draft = await factory.modifyTags(search, hidden ? { hidden: operation } : operation);
|
|
25
|
+
yield await factory.sign(draft);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Creates a new search relays event */
|
|
29
|
+
export function NewSearchRelays(relays) {
|
|
30
|
+
return async function* ({ events, factory, self }) {
|
|
31
|
+
const search = events.getReplaceable(kinds.SearchRelaysList, self);
|
|
32
|
+
if (search)
|
|
33
|
+
throw new Error("Search relays event already exists");
|
|
34
|
+
let publicOperations = [];
|
|
35
|
+
let hiddenOperations = [];
|
|
36
|
+
if (Array.isArray(relays)) {
|
|
37
|
+
publicOperations.push(...relays.map((r) => addRelayTag(r)));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (relays?.public)
|
|
41
|
+
publicOperations.push(...(relays?.public ?? []).map((r) => addRelayTag(r)));
|
|
42
|
+
if (relays?.hidden)
|
|
43
|
+
hiddenOperations.push(...(relays?.hidden ?? []).map((r) => addRelayTag(r)));
|
|
44
|
+
}
|
|
45
|
+
const draft = await factory.build({ kind: kinds.SearchRelaysList }, publicOperations.length ? modifyPublicTags(...publicOperations) : undefined, hiddenOperations.length ? modifyHiddenTags(...hiddenOperations) : undefined);
|
|
46
|
+
yield await factory.sign(draft);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Subscribes to an observable, send all the values to a method and unsubscribes when complete */
|
|
2
|
+
export function play(stream, method) {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
const sub = stream.subscribe({
|
|
5
|
+
next: (v) => {
|
|
6
|
+
try {
|
|
7
|
+
method(v);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
reject(error);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
error: (error) => reject(error),
|
|
14
|
+
complete: () => {
|
|
15
|
+
sub.unsubscribe();
|
|
16
|
+
resolve();
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./action-hub.js";
|
|
2
|
+
export * as Actions from "./actions/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./action-hub.js";
|
|
2
|
+
export * as Actions from "./actions/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-actions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A package for performing common nostr actions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,19 +19,31 @@
|
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"require": "./dist/index.js",
|
|
21
21
|
"types": "./dist/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./actions": {
|
|
24
|
+
"import": "./dist/actions/index.js",
|
|
25
|
+
"require": "./dist/actions/index.js",
|
|
26
|
+
"types": "./dist/actions/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./actions/*": {
|
|
29
|
+
"import": "./dist/actions/*.js",
|
|
30
|
+
"require": "./dist/actions/*.js",
|
|
31
|
+
"types": "./dist/actions/*.d.ts"
|
|
22
32
|
}
|
|
23
33
|
},
|
|
24
34
|
"dependencies": {
|
|
25
|
-
"applesauce-core": "^0.
|
|
26
|
-
"applesauce-factory": "^0.
|
|
27
|
-
"debug": "^4.4.0",
|
|
35
|
+
"applesauce-core": "^1.0.0",
|
|
36
|
+
"applesauce-factory": "^1.0.0",
|
|
28
37
|
"nostr-tools": "^2.10.4",
|
|
29
38
|
"rxjs": "^7.8.1"
|
|
30
39
|
},
|
|
31
40
|
"devDependencies": {
|
|
41
|
+
"@hirez_io/observer-spy": "^2.2.0",
|
|
32
42
|
"@types/debug": "^4.1.12",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
43
|
+
"applesauce-signers": "^1.0.0",
|
|
44
|
+
"nanoid": "^5.1.5",
|
|
45
|
+
"typescript": "^5.8.3",
|
|
46
|
+
"vitest": "^3.1.1"
|
|
35
47
|
},
|
|
36
48
|
"funding": {
|
|
37
49
|
"type": "lightning",
|