@fabriktor/fx 0.0.165 → 0.0.166

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.
@@ -1,9 +1,4 @@
1
1
  import type { CallsOperator, NotificationsOperator } from "@fabriktor/client";
2
- import type { Event } from "@fabriktor/schema";
3
- type EventInsertOptions = Parameters<CallsOperator["insertOneEvent"]>[0];
4
- type EventReplaceOptions = Parameters<CallsOperator["replaceOneEvent"]>[0];
5
- export type CreateEventOptions = EventInsertOptions;
6
- export type ReplaceEventOptions = EventReplaceOptions;
7
2
  export type MintVideoTokenOptions = Parameters<CallsOperator["mintVideoToken"]>[0];
8
3
  export type RelayNotificationOptions = Parameters<NotificationsOperator["relayNotification"]>[0];
9
4
  export type StartCallOptions = {
@@ -22,8 +17,6 @@ export type CallsFXOptions = {
22
17
  notifications: NotificationsOperator;
23
18
  };
24
19
  export interface CallsFXOperator {
25
- createEvent(opts: CreateEventOptions): Promise<Event>;
26
- replaceEvent(opts: ReplaceEventOptions): Promise<Event>;
27
20
  startCall(opts: StartCallOptions): Promise<string>;
28
21
  answerCall(opts: AnswerCallOptions): Promise<string>;
29
22
  cancelCall(opts: CancelCallOptions): Promise<void>;
@@ -32,13 +25,9 @@ export declare class CallsFX implements CallsFXOperator {
32
25
  private calls;
33
26
  private notifications;
34
27
  constructor(opts: CallsFXOptions);
35
- createEvent(opts: CreateEventOptions): Promise<Event>;
36
- replaceEvent(opts: ReplaceEventOptions): Promise<Event>;
37
28
  startCall(opts: StartCallOptions): Promise<string>;
38
29
  answerCall(opts: AnswerCallOptions): Promise<string>;
39
30
  cancelCall(opts: CancelCallOptions): Promise<void>;
40
- private findEvent;
41
31
  private requireVideoToken;
42
32
  }
43
33
  export declare function newCallsFX(opts: CallsFXOptions): CallsFX;
44
- export {};
@@ -4,11 +4,7 @@
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  import { errResolveFailed } from "../core/err.js";
7
- import { requiredOperationID } from "../core/id.js";
8
- const resourceEvent = "event";
9
7
  const resourceVideoToken = "video_token";
10
- const msgCreatedEventIDMissing = "Created event response did not contain an ID.";
11
- const msgEventMissing = "Event could not be resolved after the mutation.";
12
8
  const msgUnableToMintVideoToken = "Unable to mint video token.";
13
9
  export class CallsFX {
14
10
  calls;
@@ -17,15 +13,6 @@ export class CallsFX {
17
13
  this.calls = opts.calls;
18
14
  this.notifications = opts.notifications;
19
15
  }
20
- async createEvent(opts) {
21
- const out = await this.calls.insertOneEvent(opts);
22
- const id = requiredOperationID(out, msgCreatedEventIDMissing);
23
- return await this.findEvent(id);
24
- }
25
- async replaceEvent(opts) {
26
- await this.calls.replaceOneEvent(opts);
27
- return await this.findEvent(opts.id);
28
- }
29
16
  async startCall(opts) {
30
17
  const token = await this.requireVideoToken(opts.mint);
31
18
  await this.notifications.relayNotification(opts.notification);
@@ -39,19 +26,6 @@ export class CallsFX {
39
26
  async cancelCall(opts) {
40
27
  await this.notifications.relayNotification(opts.notification);
41
28
  }
42
- async findEvent(id) {
43
- const out = await this.calls.findOneEvent({
44
- id,
45
- });
46
- const event = out.value;
47
- if (event === undefined) {
48
- throw errResolveFailed({
49
- resource: resourceEvent,
50
- msg: msgEventMissing,
51
- });
52
- }
53
- return event;
54
- }
55
29
  async requireVideoToken(opts) {
56
30
  const out = await this.calls.mintVideoToken(opts);
57
31
  const token = out.value?.trim();
@@ -11,6 +11,7 @@ import { type SaveFeedPostOptions, type FeedPostSaveResult, type FeedPostSaveSta
11
11
  export declare const FeedEvents: {
12
12
  Changed: import("../index.js").EventKey<{
13
13
  post_id: string;
14
+ deleted?: boolean;
14
15
  }>;
15
16
  };
16
17
  export type FeedReadOptions = {
@@ -16,7 +16,9 @@ import { prepareFeedTextPost, validateFeedVisibility, feedPostInput, checkFeedPo
16
16
  export * from "./validation.js";
17
17
  export * from "./media.js";
18
18
  import { saveFeedPost, newFeedPostSaveState, } from "./media.js";
19
- export const FeedEvents = { Changed: createEvent() };
19
+ export const FeedEvents = {
20
+ Changed: createEvent(),
21
+ };
20
22
  const newFeedSessionToken = "";
21
23
  const resourceFeedSessionToken = "feed_session_token";
22
24
  const resourceFeedPost = "feed_post";
@@ -252,7 +254,7 @@ export class FeedFX {
252
254
  });
253
255
  await this.feed.deleteOneFeedPost({ id: current.id, signal });
254
256
  signal.throwIfAborted();
255
- this.changed(current.id);
257
+ this.changed(current.id, true);
256
258
  if (resolvedID(current.reply_to_post_id))
257
259
  this.changed(current.reply_to_post_id);
258
260
  if (resolvedID(current.referenced_post_id))
@@ -276,8 +278,8 @@ export class FeedFX {
276
278
  });
277
279
  return post;
278
280
  }
279
- changed(post_id) {
280
- this.events.publish(FeedEvents.Changed, { post_id });
281
+ changed(post_id, deleted = false) {
282
+ this.events.publish(FeedEvents.Changed, { post_id, deleted });
281
283
  }
282
284
  async mutate(fn, parent) {
283
285
  const signal = this.sessions.signal(parent);
@@ -519,6 +521,7 @@ export class FeedFX {
519
521
  id,
520
522
  });
521
523
  signal.throwIfAborted();
524
+ this.changed(id, true);
522
525
  this.markActionRemoved(post_id, FeedAction.Reply);
523
526
  return out;
524
527
  });
@@ -560,6 +563,7 @@ export class FeedFX {
560
563
  id,
561
564
  });
562
565
  signal.throwIfAborted();
566
+ this.changed(id, true);
563
567
  this.markActionRemoved(post_id, FeedAction.Reference);
564
568
  return out;
565
569
  });
@@ -6,15 +6,21 @@ export type NotificationsFXOptions = {
6
6
  };
7
7
  export type SyncDeviceTokenOptions = {
8
8
  owner_id: string;
9
+ previous_id?: string;
10
+ };
11
+ export type UnregisterDeviceTokenOptions = {
12
+ id: string;
9
13
  };
10
14
  export type SyncDeviceTokenResult = Awaited<ReturnType<NotificationsOperator["upsertOneDTok"]>>;
11
15
  export interface NotificationsFXOperator {
12
16
  syncDeviceToken(opts: SyncDeviceTokenOptions): Promise<SyncDeviceTokenResult>;
17
+ unregisterDeviceToken(opts: UnregisterDeviceTokenOptions): Promise<void>;
13
18
  }
14
19
  export declare class NotificationsFX implements NotificationsFXOperator {
15
20
  private notifications;
16
21
  private getDeviceToken;
17
22
  constructor(opts: NotificationsFXOptions);
18
23
  syncDeviceToken(opts: SyncDeviceTokenOptions): Promise<SyncDeviceTokenResult>;
24
+ unregisterDeviceToken(opts: UnregisterDeviceTokenOptions): Promise<void>;
19
25
  }
20
26
  export declare function newNotificationsFX(opts: NotificationsFXOptions): NotificationsFX;
@@ -5,8 +5,11 @@
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  import { ZeroID } from "@fabriktor/schema";
7
7
  import { errRequired } from "../core/err.js";
8
+ import { requiredOperationID, resolvedID } from "../core/id.js";
8
9
  const msgOwnerIDRequired = "Owner ID is required.";
9
10
  const msgDeviceTokenRequired = "Device token is required.";
11
+ const msgDeviceRegistrationRequired = "Device registration is required.";
12
+ const msgDeviceRegistrationMissing = "Device registration response did not contain an ID.";
10
13
  export class NotificationsFX {
11
14
  notifications;
12
15
  getDeviceToken;
@@ -37,7 +40,23 @@ export class NotificationsFX {
37
40
  owner_id,
38
41
  },
39
42
  };
40
- return await this.notifications.upsertOneDTok(input);
43
+ const out = await this.notifications.upsertOneDTok(input);
44
+ const id = requiredOperationID(out, msgDeviceRegistrationMissing);
45
+ const previousID = resolvedID(opts.previous_id);
46
+ if (previousID !== undefined && previousID !== id) {
47
+ await this.notifications.deleteOneDTok({ id: previousID });
48
+ }
49
+ return out;
50
+ }
51
+ async unregisterDeviceToken(opts) {
52
+ const id = resolvedID(opts.id);
53
+ if (id === undefined) {
54
+ throw errRequired({
55
+ field: "id",
56
+ msg: msgDeviceRegistrationRequired,
57
+ });
58
+ }
59
+ await this.notifications.deleteOneDTok({ id });
41
60
  }
42
61
  }
43
62
  export function newNotificationsFX(opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.165",
3
+ "version": "0.0.166",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,9 +17,9 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/client": "0.0.101",
20
+ "@fabriktor/client": "0.0.102",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.73",
22
+ "@fabriktor/schema": "0.0.74",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }