applesauce-actions 6.0.0 → 6.2.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.
@@ -43,7 +43,7 @@ export declare class ActionRunner {
43
43
  publish(event: NostrEvent | NostrEvent[], relays?: string[]): Promise<void>;
44
44
  /** Run an action and publish events using the publish method */
45
45
  run<Args extends Array<any>>(builder: ActionBuilder<Args>, ...args: Args): Promise<void>;
46
- /** Run an action without publishing the events */
46
+ /** Run an action without waiting for publishing */
47
47
  exec<Args extends Array<any>>(builder: ActionBuilder<Args>, ...args: Args): Observable<NostrEvent>;
48
48
  }
49
49
  /** @deprecated Use ActionRunner instead */
@@ -38,23 +38,23 @@ export class ActionRunner {
38
38
  await Promise.all(event.map((e) => this.publish(e, relays)));
39
39
  return;
40
40
  }
41
- if (this.publishMethod) {
42
- let result;
43
- if ("publish" in this.publishMethod)
44
- result = this.publishMethod.publish(event, relays);
45
- else if (typeof this.publishMethod === "function")
46
- result = this.publishMethod(event, relays);
47
- else
48
- throw new Error("Invalid publish method");
49
- if (isObservable(result)) {
50
- await lastValueFrom(result);
51
- }
52
- else if (result instanceof Promise) {
53
- await result;
54
- }
55
- // Optionally save the event to the store
56
- if (this.saveToStore)
57
- this.events.add(event);
41
+ // Save the event to the store first so subscribers (and the UI) update immediately, before the
42
+ // potentially slow relay publish resolves. The event is already signed and valid at this point, so
43
+ // there is no reason to gate the local store update on the network round-trip.
44
+ if (this.saveToStore)
45
+ this.events.add(event);
46
+ let result;
47
+ if ("publish" in this.publishMethod)
48
+ result = this.publishMethod.publish(event, relays);
49
+ else if (typeof this.publishMethod === "function")
50
+ result = this.publishMethod(event, relays);
51
+ else
52
+ throw new Error("Invalid publish method");
53
+ if (isObservable(result)) {
54
+ await lastValueFrom(result);
55
+ }
56
+ else if (result instanceof Promise) {
57
+ await result;
58
58
  }
59
59
  }
60
60
  /** Run an action and publish events using the publish method */
@@ -63,7 +63,7 @@ export class ActionRunner {
63
63
  const context = await this.getContext();
64
64
  await builder(...args)(context);
65
65
  }
66
- /** Run an action without publishing the events */
66
+ /** Run an action without waiting for publishing */
67
67
  exec(builder, ...args) {
68
68
  return from(this.getContext()).pipe(
69
69
  // Run the action
@@ -1,4 +1,4 @@
1
- import { CommentBlueprintOptions } from "applesauce-common/factories";
1
+ import { CommentFactoryOptions } from "applesauce-common/factories";
2
2
  import { CommentPointer } from "applesauce-common/helpers/comment";
3
3
  import { NostrEvent } from "applesauce-core/helpers/event";
4
4
  import { Action } from "../action-runner.js";
@@ -7,4 +7,4 @@ import { Action } from "../action-runner.js";
7
7
  * - The parent event's author's inboxes (if the author exists and pubkey is available)
8
8
  * - The current user's outboxes
9
9
  */
10
- export declare function CreateComment(parent: NostrEvent | CommentPointer, content: string, options?: CommentBlueprintOptions): Action;
10
+ export declare function CreateComment(parent: NostrEvent | CommentPointer, content: string, options?: CommentFactoryOptions): Action;
@@ -1,7 +1,10 @@
1
- import { LegacyMessageBlueprintOptions } from "applesauce-common/factories";
2
1
  import { NostrEvent } from "applesauce-core/helpers/event";
3
2
  import { Action } from "../action-runner.js";
4
3
  /** Sends a legacy NIP-04 message to a recipient */
5
- export declare function SendLegacyMessage(recipient: string, message: string, _opts?: LegacyMessageBlueprintOptions): Action;
4
+ export declare function SendLegacyMessage(recipient: string, message: string, options?: {
5
+ expiration?: number;
6
+ }): Action;
6
7
  /** Send a reply to a legacy message */
7
- export declare function ReplyToLegacyMessage(parent: NostrEvent, message: string, _opts?: LegacyMessageBlueprintOptions): Action;
8
+ export declare function ReplyToLegacyMessage(parent: NostrEvent, message: string, options?: {
9
+ expiration?: number;
10
+ }): Action;
@@ -2,11 +2,14 @@ import { LegacyMessageFactory } from "applesauce-common/factories";
2
2
  import { castUser } from "applesauce-common/casts";
3
3
  import { kinds } from "applesauce-core/helpers/event";
4
4
  /** Sends a legacy NIP-04 message to a recipient */
5
- export function SendLegacyMessage(recipient, message, _opts) {
5
+ export function SendLegacyMessage(recipient, message, options) {
6
6
  return async ({ signer, publish, events }) => {
7
7
  if (!signer)
8
8
  throw new Error("Missing signer");
9
- const signed = await LegacyMessageFactory.create(recipient, message).sign(signer);
9
+ let draft = LegacyMessageFactory.create(recipient, message);
10
+ if (options?.expiration)
11
+ draft = draft.expiration(options.expiration);
12
+ const signed = await draft.sign(signer);
10
13
  // Get the recipient's inbox relays
11
14
  const receiver = castUser(recipient, events);
12
15
  const [inboxes, directMessageRelays] = await Promise.all([
@@ -19,7 +22,7 @@ export function SendLegacyMessage(recipient, message, _opts) {
19
22
  };
20
23
  }
21
24
  /** Send a reply to a legacy message */
22
- export function ReplyToLegacyMessage(parent, message, _opts) {
25
+ export function ReplyToLegacyMessage(parent, message, options) {
23
26
  return async ({ signer, publish, events }) => {
24
27
  if (!signer)
25
28
  throw new Error("Missing signer");
@@ -30,7 +33,10 @@ export function ReplyToLegacyMessage(parent, message, _opts) {
30
33
  const recipient = parent.pubkey === self ? parent.tags.find((t) => t[0] === "p")?.[1] : parent.pubkey;
31
34
  if (!recipient)
32
35
  throw new Error("Could not determine reply recipient");
33
- const signed = await LegacyMessageFactory.reply(parent, recipient, message).sign(signer);
36
+ let draft = LegacyMessageFactory.reply(parent, recipient, message);
37
+ if (options?.expiration)
38
+ draft = draft.expiration(options.expiration);
39
+ const signed = await draft.sign(signer);
34
40
  // Get the recipient's inbox relays (the sender of the parent message)
35
41
  const receiver = castUser(parent.pubkey, events);
36
42
  const [inboxes, directMessageRelays] = await Promise.all([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-actions",
3
- "version": "6.0.0",
3
+ "version": "6.2.0",
4
4
  "description": "A package for performing common nostr actions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,14 +32,14 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "applesauce-common": "^6.0.0",
36
- "applesauce-core": "^6.0.0",
35
+ "applesauce-common": "^6.2.0",
36
+ "applesauce-core": "^6.2.0",
37
37
  "rxjs": "^7.8.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@hirez_io/observer-spy": "^2.2.0",
41
41
  "@types/debug": "^4.1.12",
42
- "applesauce-signers": "^6.0.0",
42
+ "applesauce-signers": "^6.2.0",
43
43
  "nanoid": "^5.1.5",
44
44
  "rimraf": "^6.0.1",
45
45
  "typescript": "^5.8.3",