@fabriktor/fx 0.0.160 → 0.0.162

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.
@@ -2,6 +2,7 @@ import { type ChatOperator, type UsersOperator, type WSCloseHandler, type WSConn
2
2
  import { type Chat, type ChatRoom, type ChatRoomMember, type User } from "@fabriktor/schema";
3
3
  import { type RequiredSearchOptions, type SearchOptions, type SearchPage, type SearchPaginationOptions } from "../core/search.js";
4
4
  import { ChatSendQueue, type ChatSendQueueOptions } from "./send-queue.js";
5
+ export declare function isChatRecipientUnavailable(error: unknown): boolean;
5
6
  export declare function isChatPublicConversationDisabled(error: unknown): boolean;
6
7
  type ChatInsertOptions = Parameters<ChatOperator["insertOneChat"]>[0];
7
8
  type ChatReplaceOptions = Parameters<ChatOperator["replaceOneChat"]>[0];
@@ -5,7 +5,7 @@
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  import { isHTTPClientErr, queryParam, queryParams, } from "@fabriktor/client";
7
7
  import { ErrCodeChatPublicConversationDisabled, IDKey, OwnerIDKey, } from "@fabriktor/schema";
8
- import { errRequired, errResolveFailed, errValidation } from "../core/err.js";
8
+ import { errRequired, errResolveFailed, errValidation, FXErrKind, isFXErr, } from "../core/err.js";
9
9
  import { requiredOperationID, normalizeIDs } from "../core/id.js";
10
10
  import { normalizeSearchPage, normalizeSearchPerPage, normalizeSearchQuery, runSearch, } from "../core/search.js";
11
11
  import { isFabriktorUser } from "../users/users.js";
@@ -20,8 +20,13 @@ const msgEnsuredChatRoomIDMissing = "Ensured chat room response did not contain
20
20
  const msgChatMissing = "Chat could not be resolved after the mutation.";
21
21
  const msgSearchQueryRequired = "Search query is required.";
22
22
  const msgChatObjectsUploading = "Cannot react to a chat while objects are still uploading.";
23
- const msgChatRecipients = "Chat recipients must have a Fabriktor account. External contacts cannot receive messages or forms.";
23
+ const msgChatRecipients = "One or more selected accounts are unavailable for chat.";
24
24
  const msgParticipantMissing = "Chat room participant could not be resolved.";
25
+ export function isChatRecipientUnavailable(error) {
26
+ return (isFXErr(error) &&
27
+ error.kind === FXErrKind.Validation &&
28
+ error.field === "members");
29
+ }
25
30
  export function isChatPublicConversationDisabled(error) {
26
31
  return (isHTTPClientErr(error) &&
27
32
  error.status === 403 &&
@@ -55,6 +60,7 @@ export class ChatFX {
55
60
  }));
56
61
  if (users.some((user) => !isFabriktorUser(user))) {
57
62
  throw errValidation({
63
+ field: "members",
58
64
  msg: msgChatRecipients,
59
65
  });
60
66
  }
@@ -84,6 +84,7 @@ export type StartFeedSessionOptions = FeedPullContext & {
84
84
  export type AddFeedReactionOptions = {
85
85
  post: FeedPost;
86
86
  reaction_type: FeedReactionType;
87
+ replace_existing?: boolean;
87
88
  };
88
89
  export type RemoveFeedReactionOptions = {
89
90
  post: FeedPost;
@@ -372,7 +372,8 @@ export class FeedFX {
372
372
  const post_id = feedPostID(opts.post);
373
373
  return await this.runAction(post_id, FeedAction.Reaction, async (signal) => {
374
374
  const fresh = await this.requireFeedPost(post_id, signal);
375
- if (resolvedID(fresh.self.reaction_id))
375
+ const id = resolvedID(fresh.self.reaction_id);
376
+ if (id && !opts.replace_existing)
376
377
  throw errValidation({
377
378
  msg: "An action already exists for this post.",
378
379
  });
@@ -381,6 +382,11 @@ export class FeedFX {
381
382
  field: "reaction_type",
382
383
  msg: "Unsupported reaction.",
383
384
  });
385
+ if (id) {
386
+ await this.feed.deleteOneFeedReaction({ signal, id });
387
+ signal.throwIfAborted();
388
+ this.markActionRemoved(post_id, FeedAction.Reaction);
389
+ }
384
390
  const out = await this.feed.insertOneFeedReaction({
385
391
  signal,
386
392
  in: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.160",
3
+ "version": "0.0.162",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "@fabriktor/client": "0.0.101",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.72",
22
+ "@fabriktor/schema": "0.0.73",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }