@amityco/ts-sdk 7.31.1-e63a36d.0 → 7.32.1-0c1c3831.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.
Files changed (47) hide show
  1. package/dist/@types/domains/client.d.ts +2 -1
  2. package/dist/@types/domains/client.d.ts.map +1 -1
  3. package/dist/@types/domains/comment.d.ts +2 -2
  4. package/dist/@types/domains/comment.d.ts.map +1 -1
  5. package/dist/@types/domains/content.d.ts +23 -3
  6. package/dist/@types/domains/content.d.ts.map +1 -1
  7. package/dist/@types/domains/feed.d.ts +4 -1
  8. package/dist/@types/domains/feed.d.ts.map +1 -1
  9. package/dist/@types/domains/post.d.ts +11 -0
  10. package/dist/@types/domains/post.d.ts.map +1 -1
  11. package/dist/client/utils/autoSubscriptionManager.d.ts.map +1 -1
  12. package/dist/commentRepository/api/createComment.d.ts +1 -1
  13. package/dist/commentRepository/api/createComment.d.ts.map +1 -1
  14. package/dist/commentRepository/api/tests/createComment.gif.test.d.ts +2 -0
  15. package/dist/commentRepository/api/tests/createComment.gif.test.d.ts.map +1 -0
  16. package/dist/commentRepository/api/tests/deleteComment.gif.test.d.ts +2 -0
  17. package/dist/commentRepository/api/tests/deleteComment.gif.test.d.ts.map +1 -0
  18. package/dist/commentRepository/api/tests/updateComment.gif.test.d.ts +2 -0
  19. package/dist/commentRepository/api/tests/updateComment.gif.test.d.ts.map +1 -0
  20. package/dist/commentRepository/api/updateComment.d.ts +9 -2
  21. package/dist/commentRepository/api/updateComment.d.ts.map +1 -1
  22. package/dist/commentRepository/observers/tests/getComments.gif.test.d.ts +2 -0
  23. package/dist/commentRepository/observers/tests/getComments.gif.test.d.ts.map +1 -0
  24. package/dist/commentRepository/utils/dataTypes.d.ts +2 -0
  25. package/dist/commentRepository/utils/dataTypes.d.ts.map +1 -0
  26. package/dist/index.cjs.js +84 -41
  27. package/dist/index.esm.js +84 -41
  28. package/dist/index.umd.js +2 -2
  29. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  30. package/dist/postRepository/api/createMixedMediaPost.d.ts +6 -6
  31. package/dist/postRepository/api/createMixedMediaPost.d.ts.map +1 -1
  32. package/dist/postRepository/api/createPost.d.ts +1 -4
  33. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  34. package/dist/postRepository/api/editPost.d.ts +4 -5
  35. package/dist/postRepository/api/editPost.d.ts.map +1 -1
  36. package/dist/postRepository/api/tests/gifPost.test.d.ts +2 -0
  37. package/dist/postRepository/api/tests/gifPost.test.d.ts.map +1 -0
  38. package/dist/postRepository/observers/getPosts.d.ts +4 -0
  39. package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
  40. package/dist/postRepository/utils/attachments.d.ts +8 -0
  41. package/dist/postRepository/utils/attachments.d.ts.map +1 -0
  42. package/dist/utils/gifAttachment.d.ts +5 -0
  43. package/dist/utils/gifAttachment.d.ts.map +1 -0
  44. package/dist/utils/postTypePredicate.d.ts +1 -0
  45. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  46. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  47. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -21,6 +21,7 @@ var AmityAutoSubscription;
21
21
  AmityAutoSubscription["NETWORK"] = "network";
22
22
  AmityAutoSubscription["LIVESTREAM"] = "livestream";
23
23
  AmityAutoSubscription["BLOCK"] = "block";
24
+ AmityAutoSubscription["USER"] = "user";
24
25
  })(AmityAutoSubscription || (AmityAutoSubscription = {}));
25
26
 
26
27
  var UserTypeEnum;
@@ -176,6 +177,7 @@ const PostContentType = Object.freeze({
176
177
  AUDIO: 'audio',
177
178
  ROOM: 'room',
178
179
  EVENT: 'event',
180
+ GIF: 'gif',
179
181
  });
180
182
  const PostStructureType = Object.freeze({
181
183
  TEXT: 'text',
@@ -185,6 +187,8 @@ const PostStructureType = Object.freeze({
185
187
  AUDIO: 'audio',
186
188
  MIXED: 'mixed',
187
189
  EVENT: 'event',
190
+ /** A post that holds only GIFs. GIFs beside other media make the post `mixed`. */
191
+ GIF: 'gif',
188
192
  });
189
193
 
190
194
  var InvitationTypeEnum;
@@ -344,8 +348,8 @@ var AmityLiveViewerCountMode;
344
348
 
345
349
  function getVersion() {
346
350
  try {
347
- // the string ''v7.31.0-esm'' should be replaced by actual value by @rollup/plugin-replace
348
- return 'v7.31.0-esm';
351
+ // the string ''v7.32.0-esm'' should be replaced by actual value by @rollup/plugin-replace
352
+ return 'v7.32.0-esm';
349
353
  }
350
354
  catch (error) {
351
355
  return '__dev__';
@@ -2730,6 +2734,7 @@ const TOPICS = {
2730
2734
  ],
2731
2735
  [AmityAutoSubscription.LIVESTREAM]: [getLiveStreamTopic],
2732
2736
  [AmityAutoSubscription.BLOCK]: [getMyFollowersTopic, getMyFollowingsTopic],
2737
+ [AmityAutoSubscription.USER]: [() => getUserTopic(getActiveUser())], // global ban
2733
2738
  };
2734
2739
  const DEFAULT_TOPICS = [
2735
2740
  AmityAutoSubscription.CHAT,
@@ -27741,8 +27746,40 @@ getCommentByIds.locally = (commentIds) => {
27741
27746
  };
27742
27747
  };
27743
27748
 
27749
+ const GIF_OPTIONAL_KEYS = ['width', 'height'];
27750
+ /*
27751
+ * The server refuses a GIF attachment that carries `null` or any key it does not know, so the
27752
+ * request keeps `type`, `url` and only the optional fields that have a value. The SDK does not
27753
+ * check the values themselves: the server answers 400 for a bad one.
27754
+ */
27755
+ const toGifAttachmentPayload = (gif) => {
27756
+ const payload = { type: 'gif', url: gif.url };
27757
+ GIF_OPTIONAL_KEYS.forEach(key => {
27758
+ const value = gif[key];
27759
+ if (value !== undefined && value !== null)
27760
+ Object.assign(payload, { [key]: value });
27761
+ });
27762
+ return payload;
27763
+ };
27764
+ /* Builds each GIF from its known keys; every other attachment is sent as the caller gave it. */
27765
+ const toAttachmentsPayload = (attachments) => attachments.map(attachment => attachment.type === 'gif'
27766
+ ? toGifAttachmentPayload(attachment)
27767
+ : attachment);
27768
+
27769
+ /*
27770
+ * The data types the server lists for a comment, known before it answers: one per attachment
27771
+ * type, plus `text` when there is text. Sorted, as the server sorts them.
27772
+ */
27773
+ const commentDataTypesOf = (text, attachments) => {
27774
+ const types = new Set((attachments !== null && attachments !== void 0 ? attachments : []).map(attachment => attachment.type));
27775
+ if (text)
27776
+ types.add('text');
27777
+ return [...types].sort();
27778
+ };
27779
+
27744
27780
  const getLocalCommentId = () => uuid();
27745
27781
  const createCommentOptimistic = (bundle) => {
27782
+ var _a;
27746
27783
  const client = getActiveClient();
27747
27784
  if (!client.cache)
27748
27785
  return;
@@ -27777,6 +27814,7 @@ const createCommentOptimistic = (bundle) => {
27777
27814
  targetId: '',
27778
27815
  targetType: 'community',
27779
27816
  dataType: 'text',
27817
+ dataTypes: commentDataTypesOf((_a = bundle.data) === null || _a === void 0 ? void 0 : _a.text, bundle.attachments),
27780
27818
  syncState: "syncing" /* Amity.SyncState.Syncing */,
27781
27819
  // In a gated community the optimistic object stays out of public collections until the
27782
27820
  // response settles the status; the author's own view still updates through the local event
@@ -27823,12 +27861,15 @@ const createCommentOptimistic = (bundle) => {
27823
27861
  const createComment = async (bundle, isOptimistic = true) => {
27824
27862
  const client = getActiveClient();
27825
27863
  client.log('comment/createComment', Object.assign(Object.assign({}, bundle), { isOptimistic }));
27864
+ // A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
27865
+ const request = bundle.attachments
27866
+ ? Object.assign(Object.assign({}, bundle), { attachments: toAttachmentsPayload(bundle.attachments) }) : bundle;
27826
27867
  // Without a local comment the server assigns the id; with one, the same id travels through the
27827
27868
  // optimistic object, the response and every realtime event so each step recognises it.
27828
- const optimisticData = isOptimistic ? createCommentOptimistic(bundle) : undefined;
27869
+ const optimisticData = isOptimistic ? createCommentOptimistic(request) : undefined;
27829
27870
  const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
27830
27871
  try {
27831
- const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
27872
+ const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, request), { commentId }));
27832
27873
  // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
27833
27874
  if (payload.comments.length === 0)
27834
27875
  throw new Error('Comment not created');
@@ -27921,9 +27962,16 @@ const createComment = async (bundle, isOptimistic = true) => {
27921
27962
  * const updated = await CommentRepository.updateComment(commentId, {
27922
27963
  * data: { text: 'hello world' }
27923
27964
  * })
27965
+ *
27966
+ * // Replace the GIF, or remove it and keep the text
27967
+ * await CommentRepository.updateComment(commentId, {
27968
+ * attachments: [{ type: 'gif', url: 'https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif' }],
27969
+ * })
27970
+ * await CommentRepository.updateComment(commentId, { attachments: [] })
27924
27971
  * ```
27925
27972
  *
27926
- * Updates an {@link Amity.Comment}
27973
+ * Updates an {@link Amity.Comment}. `attachments` replaces the current ones, `[]` removes them,
27974
+ * and leaving `attachments` out keeps them as they are.
27927
27975
  *
27928
27976
  * @param commentId The ID of the {@link Amity.Comment} to edit
27929
27977
  * @param patch The patch data to apply
@@ -27937,7 +27985,10 @@ const updateComment = async (commentId, patch) => {
27937
27985
  const client = getActiveClient();
27938
27986
  client.log('user/updateComment', patch);
27939
27987
  const previous = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
27940
- const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
27988
+ // A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
27989
+ const body = patch.attachments
27990
+ ? Object.assign(Object.assign({}, patch), { attachments: toAttachmentsPayload(patch.attachments) }) : patch;
27991
+ const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, body);
27941
27992
  const data = prepareCommentPayload(payload);
27942
27993
  const updated = data.comments.find(comment => comment.commentId === commentId);
27943
27994
  const cachedAt = client.cache && Date.now();
@@ -30404,6 +30455,19 @@ getPostByIds.locally = (postIds) => {
30404
30455
  };
30405
30456
  };
30406
30457
 
30458
+ /*
30459
+ * The `attachments` a post create or edit sends. A GIF goes with its known keys only and never
30460
+ * with product tags (both a 400). A file takes its product tags from the map, as before.
30461
+ */
30462
+ const preparePostAttachments = (attachments, attachmentProductTags) => attachments === null || attachments === void 0 ? void 0 : attachments.map(attachment => {
30463
+ if (attachment.type === 'gif') {
30464
+ return toGifAttachmentPayload(attachment);
30465
+ }
30466
+ if (!attachmentProductTags || !attachment.fileId)
30467
+ return attachment;
30468
+ return Object.assign(Object.assign({}, attachment), { productTags: attachmentProductTags.get(attachment.fileId) });
30469
+ });
30470
+
30407
30471
  /* begin_public_function
30408
30472
  id: post.create.text_post, post.create.image_post, post.create.file_post, post.create.video_post, post.create.poll_post, post.create.livestream_post, post.create.custom_post
30409
30473
  */
@@ -30433,17 +30497,7 @@ const createPost = async (bundle) => {
30433
30497
  delete bundle.dataType;
30434
30498
  }
30435
30499
  const { attachments, attachmentProductTags } = bundle, rest = __rest(bundle, ["attachments", "attachmentProductTags"]);
30436
- const processedAttachments = attachments && attachments.length > 0 && bundle.attachmentProductTags
30437
- ? attachments.map(attachment => {
30438
- var _a;
30439
- /* c8 ignore next */
30440
- const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
30441
- if (productTags)
30442
- return Object.assign(Object.assign({}, attachment), { productTags });
30443
- /* c8 ignore next */
30444
- return attachment;
30445
- })
30446
- : attachments;
30500
+ const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
30447
30501
  const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
30448
30502
  fireEvent('post.created', payload);
30449
30503
  const data = preparePostPayload(payload);
@@ -30469,7 +30523,9 @@ const createPost = async (bundle) => {
30469
30523
  * })
30470
30524
  * ```
30471
30525
  *
30472
- * Updates an {@link Amity.Post}
30526
+ * Updates an {@link Amity.Post}. `attachments` is the full list to keep: a GIF is matched by its
30527
+ * `url`, so send each kept GIF back with its link and size as read from `childrenPosts`; an
30528
+ * attachment left out is deleted, `[]` removes them all, and leaving `attachments` out keeps them.
30473
30529
  *
30474
30530
  * @param postId The ID of the {@link Amity.Post} to edit
30475
30531
  * @param patch The patch data to apply
@@ -30482,17 +30538,7 @@ const editPost = async (postId, patch) => {
30482
30538
  const client = getActiveClient();
30483
30539
  client.log('user/editPost', patch);
30484
30540
  const { attachments } = patch;
30485
- const processedAttachments = attachments && attachments.length > 0 && patch.attachmentProductTags
30486
- ? attachments.map(attachment => {
30487
- var _a;
30488
- /* c8 ignore next */
30489
- const productTags = (_a = patch.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
30490
- if (productTags)
30491
- return Object.assign(Object.assign({}, attachment), { productTags });
30492
- /* c8 ignore next */
30493
- return attachment;
30494
- })
30495
- : attachments;
30541
+ const processedAttachments = preparePostAttachments(attachments, patch.attachmentProductTags);
30496
30542
  const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
30497
30543
  const data = prepareMembershipPayload(payload, 'communityUsers');
30498
30544
  const cachedAt = client.cache && Date.now();
@@ -30976,11 +31022,14 @@ const createAudioPost = async (bundle) => {
30976
31022
  * { fileId: "file1", type: "image" },
30977
31023
  * { fileId: "file2", type: "video" },
30978
31024
  * { fileId: "file3", type: "audio" },
30979
- * { fileId: "file4", type: "file" }
31025
+ * { fileId: "file4", type: "file" },
31026
+ * { type: "gif", url: "https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif", width: 480, height: 270 }
30980
31027
  * ],
30981
31028
  * })
30982
31029
  * ```
30983
31030
  *
31031
+ * A post holds 1 to 10 attachments. A GIF is a link, not a file, and takes no product tags.
31032
+ *
30984
31033
  * Creates an {@link Amity.Post}
30985
31034
  *
30986
31035
  * @param bundle The data necessary to create a new {@link Amity.Post}
@@ -30994,17 +31043,7 @@ const createMixedMediaPost = async (bundle) => {
30994
31043
  const client = getActiveClient();
30995
31044
  client.log('post/createMixedMediaPost', bundle);
30996
31045
  const { attachments, attachmentProductTags } = bundle, rest = __rest(bundle, ["attachments", "attachmentProductTags"]);
30997
- const processedAttachments = attachments && attachments.length > 0 && bundle.attachmentProductTags
30998
- ? attachments.map(attachment => {
30999
- var _a;
31000
- /* c8 ignore next */
31001
- const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
31002
- if (productTags)
31003
- return Object.assign(Object.assign({}, attachment), { productTags });
31004
- /* c8 ignore next */
31005
- return attachment;
31006
- })
31007
- : /* c8 ignore next */ attachments;
31046
+ const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
31008
31047
  const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
31009
31048
  fireEvent('post.created', payload);
31010
31049
  const data = preparePostPayload(payload);
@@ -31521,6 +31560,10 @@ class PostLiveCollectionController extends LiveCollectionController {
31521
31560
  *
31522
31561
  * Observe all mutations on a list of {@link Amity.Post} for a given target object
31523
31562
  *
31563
+ * GIF posts come back on every API version. This query is on v5, so `dataTypes: ['gif']` filters
31564
+ * them; a post with GIFs beside other media is `mixed` and is hidden unless
31565
+ * `includeMixedStructure` is `true`.
31566
+ *
31524
31567
  * @param params.targetType the type of the target
31525
31568
  * @param params.targetId the ID of the target
31526
31569
  * @param callback the function to call when new data are available