@amityco/ts-sdk 7.34.1-aaca0bfd.0 → 7.34.1-efbe98b.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 (38) hide show
  1. package/dist/@types/core/errors.d.ts +1 -7
  2. package/dist/@types/core/errors.d.ts.map +1 -1
  3. package/dist/@types/index.d.ts +0 -1
  4. package/dist/@types/index.d.ts.map +1 -1
  5. package/dist/core/errors.d.ts +0 -18
  6. package/dist/core/errors.d.ts.map +1 -1
  7. package/dist/index.cjs.js +60 -462
  8. package/dist/index.d.ts +1 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.esm.js +36 -436
  11. package/dist/index.umd.js +2 -2
  12. package/package.json +1 -1
  13. package/dist/@types/domains/widget.d.ts +0 -33
  14. package/dist/@types/domains/widget.d.ts.map +0 -1
  15. package/dist/widgetRepository/api/act.d.ts +0 -19
  16. package/dist/widgetRepository/api/act.d.ts.map +0 -1
  17. package/dist/widgetRepository/api/getSetup.d.ts +0 -17
  18. package/dist/widgetRepository/api/getSetup.d.ts.map +0 -1
  19. package/dist/widgetRepository/api/getWidget.d.ts +0 -18
  20. package/dist/widgetRepository/api/getWidget.d.ts.map +0 -1
  21. package/dist/widgetRepository/api/index.d.ts +0 -5
  22. package/dist/widgetRepository/api/index.d.ts.map +0 -1
  23. package/dist/widgetRepository/api/tests/widgetHeaders.test.d.ts +0 -2
  24. package/dist/widgetRepository/api/tests/widgetHeaders.test.d.ts.map +0 -1
  25. package/dist/widgetRepository/api/tests/widgetRepository.test.d.ts +0 -2
  26. package/dist/widgetRepository/api/tests/widgetRepository.test.d.ts.map +0 -1
  27. package/dist/widgetRepository/api/upload.d.ts +0 -19
  28. package/dist/widgetRepository/api/upload.d.ts.map +0 -1
  29. package/dist/widgetRepository/index.d.ts +0 -2
  30. package/dist/widgetRepository/index.d.ts.map +0 -1
  31. package/dist/widgetRepository/utils/settleWidgetResponse.d.ts +0 -29
  32. package/dist/widgetRepository/utils/settleWidgetResponse.d.ts.map +0 -1
  33. package/dist/widgetRepository/utils/tests/settleWidgetResponse.test.d.ts +0 -2
  34. package/dist/widgetRepository/utils/tests/settleWidgetResponse.test.d.ts.map +0 -1
  35. package/dist/widgetRepository/utils/tests/widgetTarget.test.d.ts +0 -2
  36. package/dist/widgetRepository/utils/tests/widgetTarget.test.d.ts.map +0 -1
  37. package/dist/widgetRepository/utils/widgetRequest.d.ts +0 -73
  38. package/dist/widgetRepository/utils/widgetRequest.d.ts.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -875,26 +875,6 @@ class AmityModuleNotEntitledError extends ASCApiError {
875
875
  this.type = 'AmityModuleNotEntitledError';
876
876
  }
877
877
  }
878
- /**
879
- * Thrown by every {@link WidgetRepository} call that does not succeed. `status`
880
- * and `body` are the widget service's HTTP status and raw body, when one came back.
881
- *
882
- * @category Errors
883
- */
884
- class AmityWidgetError extends ASCError {
885
- /**
886
- * @param message A custom error message
887
- * @param code A normalized error code
888
- * @param status The HTTP status, when an answer came back
889
- * @param body The raw body text, when an answer came back
890
- */
891
- constructor(message, code, status, body) {
892
- super(message, code, "error" /* Amity.ErrorLevel.ERROR */);
893
- this.status = status;
894
- this.body = body;
895
- this.type = 'AmityWidgetError';
896
- }
897
- }
898
878
  /**
899
879
  * Input sanitization related error
900
880
  * @category Errors
@@ -11527,7 +11507,7 @@ const resolveModuleAvailability = (moduleSettings, moduleKey, seen = new Set())
11527
11507
  };
11528
11508
  };
11529
11509
 
11530
- var index$u = /*#__PURE__*/Object.freeze({
11510
+ var index$t = /*#__PURE__*/Object.freeze({
11531
11511
  __proto__: null,
11532
11512
  getActiveClient: getActiveClient,
11533
11513
  getActiveUser: getActiveUser,
@@ -12658,7 +12638,7 @@ const getMyFollowInfo = (callback) => {
12658
12638
  };
12659
12639
  /* end_public_function */
12660
12640
 
12661
- var index$t = /*#__PURE__*/Object.freeze({
12641
+ var index$s = /*#__PURE__*/Object.freeze({
12662
12642
  __proto__: null,
12663
12643
  blockUser: blockUser,
12664
12644
  unBlockUser: unBlockUser,
@@ -17662,9 +17642,9 @@ var AmityUserSearchMatchType;
17662
17642
  AmityUserSearchMatchType["PARTIAL"] = "partial";
17663
17643
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
17664
17644
 
17665
- var index$s = /*#__PURE__*/Object.freeze({
17645
+ var index$r = /*#__PURE__*/Object.freeze({
17666
17646
  __proto__: null,
17667
- Relationship: index$t,
17647
+ Relationship: index$s,
17668
17648
  getUserByIds: getUserByIds,
17669
17649
  updateUser: updateUser,
17670
17650
  flagUser: flagUser,
@@ -18079,7 +18059,7 @@ const uploadAudio = async (formData, onProgress) => {
18079
18059
  };
18080
18060
  /* end_public_function */
18081
18061
 
18082
- var index$r = /*#__PURE__*/Object.freeze({
18062
+ var index$q = /*#__PURE__*/Object.freeze({
18083
18063
  __proto__: null,
18084
18064
  getFile: getFile,
18085
18065
  uploadFile: uploadFile,
@@ -19939,7 +19919,7 @@ const getReactions$1 = (params, callback, config) => {
19939
19919
  };
19940
19920
  /* end_public_function */
19941
19921
 
19942
- var index$q = /*#__PURE__*/Object.freeze({
19922
+ var index$p = /*#__PURE__*/Object.freeze({
19943
19923
  __proto__: null,
19944
19924
  addReaction: addReaction,
19945
19925
  removeReaction: removeReaction,
@@ -22200,7 +22180,7 @@ const searchMessage = (params, callback) => {
22200
22180
  };
22201
22181
  /* end_public_function */
22202
22182
 
22203
- var index$p = /*#__PURE__*/Object.freeze({
22183
+ var index$o = /*#__PURE__*/Object.freeze({
22204
22184
  __proto__: null,
22205
22185
  createMessage: createMessage,
22206
22186
  updateMessage: updateMessage,
@@ -22738,7 +22718,7 @@ const stopMessageReceiptSync = (subChannelId) => {
22738
22718
  };
22739
22719
  /* end_public_function */
22740
22720
 
22741
- var index$o = /*#__PURE__*/Object.freeze({
22721
+ var index$n = /*#__PURE__*/Object.freeze({
22742
22722
  __proto__: null,
22743
22723
  getSubChannelByIds: getSubChannels$1,
22744
22724
  createSubChannel: createSubChannel,
@@ -24706,7 +24686,7 @@ const searchMembers$1 = (params, callback, config) => {
24706
24686
  };
24707
24687
  /* end_public_function */
24708
24688
 
24709
- var index$n = /*#__PURE__*/Object.freeze({
24689
+ var index$m = /*#__PURE__*/Object.freeze({
24710
24690
  __proto__: null,
24711
24691
  addMembers: addMembers$1,
24712
24692
  removeMembers: removeMembers$1,
@@ -24928,7 +24908,7 @@ const unmuteMembers = async (channelId, userIds) => {
24928
24908
  };
24929
24909
  /* end_public_function */
24930
24910
 
24931
- var index$m = /*#__PURE__*/Object.freeze({
24911
+ var index$l = /*#__PURE__*/Object.freeze({
24932
24912
  __proto__: null,
24933
24913
  addRole: addRole,
24934
24914
  removeRole: removeRole,
@@ -24938,10 +24918,10 @@ var index$m = /*#__PURE__*/Object.freeze({
24938
24918
  unmuteMembers: unmuteMembers
24939
24919
  });
24940
24920
 
24941
- var index$l = /*#__PURE__*/Object.freeze({
24921
+ var index$k = /*#__PURE__*/Object.freeze({
24942
24922
  __proto__: null,
24943
- Membership: index$n,
24944
- Moderation: index$m,
24923
+ Membership: index$m,
24924
+ Moderation: index$l,
24945
24925
  getChannelByIds: getChannelByIds$1,
24946
24926
  createChannel: createChannel,
24947
24927
  updateChannel: updateChannel,
@@ -26376,7 +26356,7 @@ const searchMembers = (params, callback, config) => {
26376
26356
  };
26377
26357
  /* end_public_function */
26378
26358
 
26379
- var index$k = /*#__PURE__*/Object.freeze({
26359
+ var index$j = /*#__PURE__*/Object.freeze({
26380
26360
  __proto__: null,
26381
26361
  addMembers: addMembers,
26382
26362
  removeMembers: removeMembers,
@@ -27627,7 +27607,7 @@ const unbanMembers = async (communityId, userIds) => {
27627
27607
  };
27628
27608
  /* end_public_function */
27629
27609
 
27630
- var index$j = /*#__PURE__*/Object.freeze({
27610
+ var index$i = /*#__PURE__*/Object.freeze({
27631
27611
  __proto__: null,
27632
27612
  addRoles: addRoles,
27633
27613
  removeRoles: removeRoles,
@@ -27635,10 +27615,10 @@ var index$j = /*#__PURE__*/Object.freeze({
27635
27615
  unbanMembers: unbanMembers
27636
27616
  });
27637
27617
 
27638
- var index$i = /*#__PURE__*/Object.freeze({
27618
+ var index$h = /*#__PURE__*/Object.freeze({
27639
27619
  __proto__: null,
27640
- Moderation: index$j,
27641
- Membership: index$k,
27620
+ Moderation: index$i,
27621
+ Membership: index$j,
27642
27622
  getCommunityByIds: getCommunities$1,
27643
27623
  createCommunity: createCommunity,
27644
27624
  updateCommunity: updateCommunity,
@@ -27874,7 +27854,7 @@ const getCategories = (params, callback, config) => {
27874
27854
  };
27875
27855
  /* end_public_function */
27876
27856
 
27877
- var index$h = /*#__PURE__*/Object.freeze({
27857
+ var index$g = /*#__PURE__*/Object.freeze({
27878
27858
  __proto__: null,
27879
27859
  getCategory: getCategory,
27880
27860
  getCategories: getCategories
@@ -29480,7 +29460,7 @@ const getCommentReviewQueue = (params, callback) => {
29480
29460
  };
29481
29461
  /* end_public_function */
29482
29462
 
29483
- var index$g = /*#__PURE__*/Object.freeze({
29463
+ var index$f = /*#__PURE__*/Object.freeze({
29484
29464
  __proto__: null,
29485
29465
  getCommentByIds: getCommentByIds,
29486
29466
  createComment: createComment,
@@ -30936,7 +30916,7 @@ const getFollowingFeed = (params, callback, config) => {
30936
30916
  };
30937
30917
  /* end_public_function */
30938
30918
 
30939
- var index$f = /*#__PURE__*/Object.freeze({
30919
+ var index$e = /*#__PURE__*/Object.freeze({
30940
30920
  __proto__: null,
30941
30921
  queryGlobalFeed: queryGlobalFeed,
30942
30922
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
@@ -34134,7 +34114,7 @@ const getRooms = (params, callback, config) => {
34134
34114
  };
34135
34115
  /* end_public_function */
34136
34116
 
34137
- var index$e = /*#__PURE__*/Object.freeze({
34117
+ var index$d = /*#__PURE__*/Object.freeze({
34138
34118
  __proto__: null,
34139
34119
  createRoom: createRoom,
34140
34120
  updateRoom: updateRoom,
@@ -34433,7 +34413,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
34433
34413
  };
34434
34414
  /* end_public_function */
34435
34415
 
34436
- var index$d = /*#__PURE__*/Object.freeze({
34416
+ var index$c = /*#__PURE__*/Object.freeze({
34437
34417
  __proto__: null,
34438
34418
  getPostByIds: getPostByIds,
34439
34419
  createPost: createPost,
@@ -35048,7 +35028,7 @@ const getStreams = (params, callback, config) => {
35048
35028
  };
35049
35029
  };
35050
35030
 
35051
- var index$c = /*#__PURE__*/Object.freeze({
35031
+ var index$b = /*#__PURE__*/Object.freeze({
35052
35032
  __proto__: null,
35053
35033
  createStream: createStream,
35054
35034
  updateStream: updateStream,
@@ -35351,7 +35331,7 @@ const stopHeartbeat = (roomId) => {
35351
35331
  };
35352
35332
  /* end_public_function */
35353
35333
 
35354
- var index$b = /*#__PURE__*/Object.freeze({
35334
+ var index$a = /*#__PURE__*/Object.freeze({
35355
35335
  __proto__: null,
35356
35336
  getRoomOnlineUsers: getRoomOnlineUsers,
35357
35337
  getRoomUserCount: getRoomUserCount,
@@ -35662,7 +35642,7 @@ const getPoll = (pollId, callback) => {
35662
35642
  };
35663
35643
  /* end_public_function */
35664
35644
 
35665
- var index$a = /*#__PURE__*/Object.freeze({
35645
+ var index$9 = /*#__PURE__*/Object.freeze({
35666
35646
  __proto__: null,
35667
35647
  createPoll: createPoll,
35668
35648
  closePoll: closePoll,
@@ -35966,7 +35946,7 @@ const getPlayer = async (parameters) => {
35966
35946
  return video;
35967
35947
  };
35968
35948
 
35969
- var index$9 = /*#__PURE__*/Object.freeze({
35949
+ var index$8 = /*#__PURE__*/Object.freeze({
35970
35950
  __proto__: null,
35971
35951
  getPlayer: getPlayer
35972
35952
  });
@@ -37139,7 +37119,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
37139
37119
  };
37140
37120
  };
37141
37121
 
37142
- var index$8 = /*#__PURE__*/Object.freeze({
37122
+ var index$7 = /*#__PURE__*/Object.freeze({
37143
37123
  __proto__: null,
37144
37124
  createImageStory: createImageStory,
37145
37125
  createVideoStory: createVideoStory,
@@ -37176,7 +37156,7 @@ const getNetworkAds = async () => {
37176
37156
  };
37177
37157
  };
37178
37158
 
37179
- var index$7 = /*#__PURE__*/Object.freeze({
37159
+ var index$6 = /*#__PURE__*/Object.freeze({
37180
37160
  __proto__: null,
37181
37161
  getNetworkAds: getNetworkAds
37182
37162
  });
@@ -37567,7 +37547,7 @@ const markTraySeen = async (lastSeenAt) => {
37567
37547
  };
37568
37548
  /* end_public_function */
37569
37549
 
37570
- var index$6 = /*#__PURE__*/Object.freeze({
37550
+ var index$5 = /*#__PURE__*/Object.freeze({
37571
37551
  __proto__: null,
37572
37552
  getNotificationTraySeen: getNotificationTraySeen,
37573
37553
  getNotificationTrayItems: getNotificationTrayItems,
@@ -37869,7 +37849,7 @@ const getInvitations = (params, callback) => {
37869
37849
  };
37870
37850
  };
37871
37851
 
37872
- var index$5 = /*#__PURE__*/Object.freeze({
37852
+ var index$4 = /*#__PURE__*/Object.freeze({
37873
37853
  __proto__: null,
37874
37854
  cancelInvitation: cancelInvitation,
37875
37855
  onLocalInvitationCreated: onLocalInvitationCreated,
@@ -38018,7 +37998,7 @@ const getReactions = (postId, callback) => {
38018
37998
  };
38019
37999
  };
38020
38000
 
38021
- var index$4 = /*#__PURE__*/Object.freeze({
38001
+ var index$3 = /*#__PURE__*/Object.freeze({
38022
38002
  __proto__: null,
38023
38003
  createReaction: createReaction,
38024
38004
  onLiveReactionCreated: onLiveReactionCreated,
@@ -38501,7 +38481,7 @@ const getMyEvents = (params, callback, config) => {
38501
38481
  };
38502
38482
  };
38503
38483
 
38504
- var index$3 = /*#__PURE__*/Object.freeze({
38484
+ var index$2 = /*#__PURE__*/Object.freeze({
38505
38485
  __proto__: null,
38506
38486
  createEvent: createEvent,
38507
38487
  updateEvent: updateEvent,
@@ -38728,7 +38708,7 @@ const searchProducts = (params, callback, config) => {
38728
38708
  };
38729
38709
  /* end_public_function */
38730
38710
 
38731
- var index$2 = /*#__PURE__*/Object.freeze({
38711
+ var index$1 = /*#__PURE__*/Object.freeze({
38732
38712
  __proto__: null,
38733
38713
  getProduct: getProduct,
38734
38714
  searchProducts: searchProducts
@@ -38753,389 +38733,9 @@ const getPool = async (topicId, limit) => {
38753
38733
  };
38754
38734
  };
38755
38735
 
38756
- var index$1 = /*#__PURE__*/Object.freeze({
38757
- __proto__: null,
38758
- getPool: getPool
38759
- });
38760
-
38761
- /** A 2xx body over this many bytes is `MALFORMED_DATA`; an error body is passed on whatever its size. */
38762
- const WIDGET_MAX_BODY_BYTES = 524288;
38763
- const STATUS_CODES = {
38764
- 401: 400100 /* Amity.ServerError.UNAUTHORIZED */,
38765
- 403: 400300 /* Amity.ServerError.FORBIDDEN */,
38766
- 404: 400400 /* Amity.ServerError.ITEM_NOT_FOUND */,
38767
- 409: 800920 /* Amity.ClientError.WIDGET_CORE_UNSUPPORTED */,
38768
- 410: 800910 /* Amity.ClientError.WIDGET_UNAVAILABLE */,
38769
- 422: 800930 /* Amity.ClientError.WIDGET_INVALID_REQUEST */,
38770
- 429: 400311 /* Amity.ServerError.RPC_RATE_LIMIT_ERROR */,
38771
- };
38772
- const utf8Length = (text) => {
38773
- let bytes = 0;
38774
- for (let i = 0; i < text.length; i += 1) {
38775
- const unit = text.charCodeAt(i);
38776
- if (unit < 0x80)
38777
- bytes += 1;
38778
- else if (unit < 0x800)
38779
- bytes += 2;
38780
- else if (unit >= 0xd800 && unit <= 0xdbff && i + 1 < text.length) {
38781
- bytes += 4;
38782
- i += 1;
38783
- }
38784
- else
38785
- bytes += 3;
38786
- }
38787
- return bytes;
38788
- };
38789
- /**
38790
- * The error for a status that is no success: an error body whose `code` is
38791
- * 400323 first, then the status. Nothing else of the body is read.
38792
- *
38793
- * @hidden
38794
- */
38795
- const widgetErrorOf = (status, body) => {
38796
- var _a;
38797
- let code = (_a = STATUS_CODES[status]) !== null && _a !== void 0 ? _a : 800000 /* Amity.ClientError.UNKNOWN_ERROR */;
38798
- try {
38799
- const parsed = JSON.parse(body);
38800
- if ((parsed === null || parsed === void 0 ? void 0 : parsed.code) === 400323 /* Amity.ServerError.VISITOR_USAGE_LIMIT_EXCEEDED */) {
38801
- code = 400323 /* Amity.ServerError.VISITOR_USAGE_LIMIT_EXCEEDED */;
38802
- }
38803
- }
38804
- catch (_b) {
38805
- // not JSON: the status decides
38806
- }
38807
- return new AmityWidgetError(`the widget service answered ${status}`, code, status, body);
38808
- };
38809
- /**
38810
- * A widget service answer as the call's result: 304 and 204 where the call
38811
- * allows them, any 2xx a body, anything else its {@link AmityWidgetError}.
38812
- *
38813
- * @hidden
38814
- */
38815
- const settleWidgetResponse = ({ status, body, etag }, allowed) => {
38816
- if (status === 304 && allowed.notModified)
38817
- return { kind: 'notModified' };
38818
- if (status === 204 && allowed.noContent)
38819
- return { kind: 'noContent' };
38820
- if (status < 200 || status > 299)
38821
- throw widgetErrorOf(status, body);
38822
- if (utf8Length(body) > WIDGET_MAX_BODY_BYTES) {
38823
- throw new AmityWidgetError('the answer is over 512 KB', 800130 /* Amity.ClientError.MALFORMED_DATA */, status, body);
38824
- }
38825
- return { kind: 'body', text: body, etag };
38826
- };
38827
-
38828
- const WIDGET_PLATFORM = 'WEB';
38829
- const WIDGET_BASE_PATH = '/api/v1/widgets';
38830
- const WIDGET_TIMEOUT_MS = 5000;
38831
- const WIDGET_UPLOAD_TIMEOUT_MS = 30000;
38832
- /** How long a call waits for a session that is being established. */
38833
- const WIDGET_SESSION_WAIT_MS = 15000;
38834
- /**
38835
- * Fetch first, with `cache: 'no-store'`: XHR has no per-request way to keep the
38836
- * browser's HTTP cache from answering, fetch does. XHR and http are fallbacks.
38837
- */
38838
- const WIDGET_ADAPTERS = ['fetch', 'xhr', 'http'];
38839
- const connectionError = (message) => new AmityWidgetError(message, 800210 /* Amity.ClientError.CONNECTION_ERROR */);
38840
- const isReady = (client) => {
38841
- var _a;
38842
- return (client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
38843
- client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) &&
38844
- !!((_a = client.token) === null || _a === void 0 ? void 0 : _a.accessToken);
38845
- };
38846
- /**
38847
- * The active client once its session is ready; `ESTABLISHING_ERROR` when it is
38848
- * not ready within the wait. The session is the caller's to start.
38849
- *
38850
- * @hidden
38851
- */
38852
- const widgetSession = (waitMs = WIDGET_SESSION_WAIT_MS) => new Promise((resolve, reject) => {
38853
- const notReady = () => new AmityWidgetError('the session did not become ready', 800402 /* Amity.ClientError.ESTABLISHING_ERROR */);
38854
- let client;
38855
- try {
38856
- client = getActiveClient();
38857
- }
38858
- catch (_a) {
38859
- reject(notReady());
38860
- return;
38861
- }
38862
- if (isReady(client)) {
38863
- resolve(client);
38864
- return;
38865
- }
38866
- let timer;
38867
- const unsubscribe = onSessionStateChange(() => {
38868
- if (!isReady(client))
38869
- return;
38870
- clearTimeout(timer);
38871
- unsubscribe();
38872
- resolve(client);
38873
- });
38874
- timer = setTimeout(() => {
38875
- unsubscribe();
38876
- reject(notReady());
38877
- }, waitMs);
38878
- });
38879
- const WIDGET_PREFIX = `${WIDGET_BASE_PATH}/`;
38880
- const UPLOAD_PATHS = ['/api/v4/images', '/api/v4/videos'];
38881
- /** The paths a widget call may send the token to: anything under `/api/v1/widgets/`. */
38882
- const isWidgetPath = (path) => path.startsWith(WIDGET_PREFIX) && path.length > WIDGET_PREFIX.length;
38883
- /** The paths an upload may send the token to: exactly the SDK's image and video uploads. */
38884
- const isUploadPath = (path) => UPLOAD_PATHS.includes(path);
38885
- const ABSOLUTE = /^https?:\/\/[^/?#]*/i;
38886
- const ENCODED_SEPARATOR = /%(2f|2e|5c)/i;
38887
- const hasDotSegment = (path) => path.split('/').some(part => part === '.' || part === '..');
38888
- /**
38889
- * Where a widget request goes, refused (`CONNECTION_ERROR`) unless it is a clean,
38890
- * allowed path on the SDK's HTTP origin: the client sends its token to any URL.
38891
- * A path is joined to the SDK's HTTP endpoint; a full URL keeps its own.
38892
- *
38893
- * @hidden
38894
- */
38895
- const widgetTarget = (url, endpoint, allowed) => {
38896
- var _a;
38897
- if (!endpoint)
38898
- throw connectionError('the SDK has no HTTP endpoint');
38899
- const refuse = (why) => connectionError(`refused ${url}: ${why}`);
38900
- const isPath = url.startsWith('/') && !url.startsWith('//');
38901
- const authority = isPath ? '' : (_a = ABSOLUTE.exec(url)) === null || _a === void 0 ? void 0 : _a[0];
38902
- if (authority === undefined)
38903
- throw refuse('not a path or an http(s) URL');
38904
- const path = url.slice(authority.length).split(/[?#]/)[0];
38905
- if (!path)
38906
- throw refuse('empty path');
38907
- if (url.includes('\\') || ENCODED_SEPARATOR.test(path) || hasDotSegment(path)) {
38908
- throw refuse('unsafe path');
38909
- }
38910
- let origin;
38911
- let target;
38912
- try {
38913
- origin = new URL(endpoint).origin;
38914
- target = new URL(isPath ? path : url, origin);
38915
- }
38916
- catch (_b) {
38917
- throw refuse('not a URL');
38918
- }
38919
- if (target.origin !== origin)
38920
- throw refuse("not the SDK's host");
38921
- if (target.pathname !== path)
38922
- throw refuse('path not normalized');
38923
- if (!allowed(path))
38924
- throw refuse('path not allowed');
38925
- return isPath ? { url } : { baseURL: origin, url: `${target.pathname}${target.search}` };
38926
- };
38927
- /**
38928
- * The headers of a widget request, on that request only: never on the client's
38929
- * defaults or an interceptor, so no other SDK request carries them.
38930
- *
38931
- * @hidden
38932
- */
38933
- const widgetHeaders = (apiKey, call, json = false) => (Object.assign(Object.assign(Object.assign(Object.assign({}, (apiKey ? { 'X-API-Key': apiKey } : {})), { 'X-Widget-Platform': WIDGET_PLATFORM, 'X-Widget-Core-Version': call.coreVersion }), (call.etag ? { 'If-None-Match': call.etag } : {})), (json ? { 'Content-Type': 'application/json' } : {})));
38934
- /**
38935
- * The query of a call: `locale`, `tz` and the paging token where they are given, in that order.
38936
- * The token (`cursor`) goes as core's `options[token]`, unread.
38937
- */
38938
- const widgetQuery = (call, keys) => keys.reduce((query, key) => {
38939
- const value = call[key];
38940
- const given = key === 'cursor' ? !!value : value !== undefined && value !== null;
38941
- return given
38942
- ? Object.assign(Object.assign({}, query), { [key === 'cursor' ? 'options[token]' : key]: value }) : query;
38943
- }, {});
38944
- /**
38945
- * Drops `traceparent` from a widget request. The widget service's CORS does not
38946
- * allow it yet, so a browser refuses the request; `x-request-id` still goes.
38947
- * Remove once the service allows `traceparent`.
38948
- *
38949
- * @hidden
38950
- */
38951
- const withoutTraceparent = (data, headers) => {
38952
- headers.delete('traceparent');
38953
- return data;
38954
- };
38955
- const defaultTransforms = () => { var _a; return [(_a = axios__default["default"].defaults.transformRequest) !== null && _a !== void 0 ? _a : []].flat(); };
38956
- const bodyText = (data) => {
38957
- if (typeof data === 'string')
38958
- return data;
38959
- if (data === undefined || data === null)
38960
- return '';
38961
- return JSON.stringify(data);
38962
- };
38963
- /**
38964
- * Sends one widget service request through the SDK's HTTP client, with the
38965
- * session's token, and returns its status, raw body and `ETag`.
38966
- *
38967
- * @hidden
38968
- */
38969
- const sendWidgetRequest = async ({ method, url, call, params, data, json, timeout, allowed, }) => {
38970
- var _a;
38971
- const client = await widgetSession();
38972
- const target = widgetTarget(url, client.http.defaults.baseURL, allowed);
38973
- const config = Object.assign(Object.assign(Object.assign({}, (target.baseURL ? { baseURL: target.baseURL } : {})), (params && Object.keys(params).length ? { params } : {})), { headers: widgetHeaders(client.apiKey, call, json), timeout, adapter: WIDGET_ADAPTERS, fetchOptions: { cache: 'no-store' },
38974
- // transforms run after the client's interceptor has set traceparent
38975
- transformRequest: [withoutTraceparent, ...defaultTransforms()], responseType: 'text',
38976
- // every status is read here, not by the client's error interceptor
38977
- validateStatus: () => true });
38978
- let response;
38979
- try {
38980
- response =
38981
- method === 'get'
38982
- ? await client.http.get(target.url, config)
38983
- : await client.http.post(target.url, data, config);
38984
- }
38985
- catch (error) {
38986
- throw connectionError(`no answer: ${String(error)}`);
38987
- }
38988
- const etag = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.etag;
38989
- return {
38990
- status: response.status,
38991
- body: bodyText(response.data),
38992
- etag: typeof etag === 'string' ? etag : null,
38993
- };
38994
- };
38995
-
38996
- /* begin_public_function
38997
- id: widget.get
38998
- */
38999
- /**
39000
- * ```js
39001
- * import { WidgetRepository } from '@amityco/ts-sdk'
39002
- * const result = await WidgetRepository.getWidget(slotId, { coreVersion, locale, tz })
39003
- * ```
39004
- *
39005
- * Fetches a slot's widget from the widget service. Nothing is cached or parsed.
39006
- *
39007
- * @param slotId The slot to fetch
39008
- * @param call What the call carries: `coreVersion`, and `locale`, `tz`, `cursor` (sent as `options[token]`), `etag`
39009
- * @returns The body, `notModified` (304) or `noContent` (204)
39010
- * @throws {AmityWidgetError}
39011
- *
39012
- * @category Widget API
39013
- * @async
39014
- */
39015
- const getWidget = async (slotId, call) => {
39016
- getActiveClient().log('widget/getWidget', slotId);
39017
- const answer = await sendWidgetRequest({
39018
- method: 'get',
39019
- url: `${WIDGET_BASE_PATH}/${encodeURIComponent(slotId)}`,
39020
- params: widgetQuery(call, ['locale', 'tz', 'cursor']),
39021
- call,
39022
- allowed: isWidgetPath,
39023
- timeout: WIDGET_TIMEOUT_MS,
39024
- });
39025
- return settleWidgetResponse(answer, { notModified: true, noContent: true });
39026
- };
39027
- /* end_public_function */
39028
-
39029
- /* begin_public_function
39030
- id: widget.get.setup
39031
- */
39032
- /**
39033
- * ```js
39034
- * import { WidgetRepository } from '@amityco/ts-sdk'
39035
- * const result = await WidgetRepository.getSetup({ coreVersion, locale })
39036
- * ```
39037
- *
39038
- * Fetches the widget setup bundle from the widget service. Nothing is cached or parsed.
39039
- *
39040
- * @param call What the call carries: `coreVersion`, and `locale`, `etag`
39041
- * @returns The body, or `notModified` (304)
39042
- * @throws {AmityWidgetError}
39043
- *
39044
- * @category Widget API
39045
- * @async
39046
- */
39047
- const getSetup = async (call) => {
39048
- getActiveClient().log('widget/getSetup');
39049
- const answer = await sendWidgetRequest({
39050
- method: 'get',
39051
- url: `${WIDGET_BASE_PATH}/setup`,
39052
- params: widgetQuery(call, ['locale']),
39053
- call,
39054
- allowed: isWidgetPath,
39055
- timeout: WIDGET_TIMEOUT_MS,
39056
- });
39057
- return settleWidgetResponse(answer, { notModified: true });
39058
- };
39059
- /* end_public_function */
39060
-
39061
- /* begin_public_function
39062
- id: widget.act
39063
- */
39064
- /**
39065
- * ```js
39066
- * import { WidgetRepository } from '@amityco/ts-sdk'
39067
- * const result = await WidgetRepository.act(url, { coreVersion, locale, tz }, request)
39068
- * ```
39069
- *
39070
- * Posts a widget action to the widget service, as JSON. Nothing is cached or parsed.
39071
- *
39072
- * @param url The action's path under `/api/v1/widgets/`, or that path as a full URL on the SDK's HTTP origin
39073
- * @param call What the call carries: `coreVersion`, and `locale`, `tz`
39074
- * @param request The action's request, sent as JSON
39075
- * @returns The body
39076
- * @throws {AmityWidgetError}
39077
- *
39078
- * @category Widget API
39079
- * @async
39080
- */
39081
- const act = async (url, call, request) => {
39082
- getActiveClient().log('widget/act', url);
39083
- const answer = await sendWidgetRequest({
39084
- method: 'post',
39085
- url,
39086
- params: widgetQuery(call, ['locale', 'tz']),
39087
- data: JSON.stringify(request),
39088
- json: true,
39089
- call,
39090
- allowed: isWidgetPath,
39091
- timeout: WIDGET_TIMEOUT_MS,
39092
- });
39093
- return settleWidgetResponse(answer, {});
39094
- };
39095
- /* end_public_function */
39096
-
39097
- /* begin_public_function
39098
- id: widget.upload
39099
- */
39100
- /**
39101
- * ```js
39102
- * import { WidgetRepository } from '@amityco/ts-sdk'
39103
- * const result = await WidgetRepository.upload(url, file, { coreVersion })
39104
- * ```
39105
- *
39106
- * Uploads one file to the widget service, as multipart part `file`, with no query.
39107
- *
39108
- * @param url `/api/v4/images` or `/api/v4/videos`, or either as a full URL on the SDK's HTTP origin
39109
- * @param file The file to send; a `File` keeps its name
39110
- * @param call What the call carries: `coreVersion`
39111
- * @returns The body
39112
- * @throws {AmityWidgetError}
39113
- *
39114
- * @category Widget API
39115
- * @async
39116
- */
39117
- const upload = async (url, file, call) => {
39118
- getActiveClient().log('widget/upload', url);
39119
- const form = new FormData();
39120
- form.append('file', file);
39121
- const answer = await sendWidgetRequest({
39122
- method: 'post',
39123
- url,
39124
- data: form,
39125
- call,
39126
- allowed: isUploadPath,
39127
- timeout: WIDGET_UPLOAD_TIMEOUT_MS,
39128
- });
39129
- return settleWidgetResponse(answer, {});
39130
- };
39131
- /* end_public_function */
39132
-
39133
38736
  var index = /*#__PURE__*/Object.freeze({
39134
38737
  __proto__: null,
39135
- getWidget: getWidget,
39136
- getSetup: getSetup,
39137
- act: act,
39138
- upload: upload
38738
+ getPool: getPool
39139
38739
  });
39140
38740
 
39141
38741
  /**
@@ -39244,48 +38844,46 @@ const getContentFlagReasonKey = (reason) => CONTENT_FLAG_REASON_KEYS[reason];
39244
38844
  /* end_public_function */
39245
38845
 
39246
38846
  exports.API_REGIONS = API_REGIONS;
39247
- exports.AdRepository = index$7;
38847
+ exports.AdRepository = index$6;
39248
38848
  exports.AmityAttachmentProductTags = AmityAttachmentProductTags;
39249
38849
  exports.AmityContentFlagReasonType = exports.ContentFlagReasonEnum;
39250
38850
  exports.AmityModuleNotEntitledError = AmityModuleNotEntitledError;
39251
- exports.AmityWidgetError = AmityWidgetError;
39252
- exports.CategoryRepository = index$h;
39253
- exports.ChannelRepository = index$l;
39254
- exports.Client = index$u;
39255
- exports.CommentRepository = index$g;
38851
+ exports.CategoryRepository = index$g;
38852
+ exports.ChannelRepository = index$k;
38853
+ exports.Client = index$t;
38854
+ exports.CommentRepository = index$f;
39256
38855
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
39257
38856
  exports.CommunityPostSettings = CommunityPostSettings;
39258
- exports.CommunityRepository = index$i;
38857
+ exports.CommunityRepository = index$h;
39259
38858
  exports.ContentFeedType = ContentFeedType;
39260
- exports.CuratedContentRepository = index$1;
38859
+ exports.CuratedContentRepository = index;
39261
38860
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
39262
- exports.EventRepository = index$3;
39263
- exports.FeedRepository = index$f;
39264
- exports.FileRepository = index$r;
38861
+ exports.EventRepository = index$2;
38862
+ exports.FeedRepository = index$e;
38863
+ exports.FileRepository = index$q;
39265
38864
  exports.FileType = FileType;
39266
38865
  exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
39267
- exports.InvitationRepository = index$5;
39268
- exports.LiveReactionRepository = index$4;
39269
- exports.LiveStreamPlayer = index$9;
38866
+ exports.InvitationRepository = index$4;
38867
+ exports.LiveReactionRepository = index$3;
38868
+ exports.LiveStreamPlayer = index$8;
39270
38869
  exports.MessageContentType = MessageContentType;
39271
- exports.MessageRepository = index$p;
39272
- exports.PollRepository = index$a;
38870
+ exports.MessageRepository = index$o;
38871
+ exports.PollRepository = index$9;
39273
38872
  exports.PostContentType = PostContentType;
39274
- exports.PostRepository = index$d;
38873
+ exports.PostRepository = index$c;
39275
38874
  exports.PostStructureType = PostStructureType;
39276
- exports.ProductRepository = index$2;
39277
- exports.ReactionRepository = index$q;
39278
- exports.RoomPresenceRepository = index$b;
39279
- exports.RoomRepository = index$e;
39280
- exports.StoryRepository = index$8;
39281
- exports.StreamRepository = index$c;
39282
- exports.SubChannelRepository = index$o;
39283
- exports.UserRepository = index$s;
38875
+ exports.ProductRepository = index$1;
38876
+ exports.ReactionRepository = index$p;
38877
+ exports.RoomPresenceRepository = index$a;
38878
+ exports.RoomRepository = index$d;
38879
+ exports.StoryRepository = index$7;
38880
+ exports.StreamRepository = index$b;
38881
+ exports.SubChannelRepository = index$n;
38882
+ exports.UserRepository = index$r;
39284
38883
  exports.VERSION = VERSION;
39285
38884
  exports.VideoResolution = VideoResolution;
39286
38885
  exports.VideoSize = VideoSize;
39287
38886
  exports.VideoTranscodingStatus = VideoTranscodingStatus;
39288
- exports.WidgetRepository = index;
39289
38887
  exports.backupCache = backupCache;
39290
38888
  exports.createQuery = createQuery;
39291
38889
  exports.createReport = createReport;
@@ -39345,7 +38943,7 @@ exports.isPaged = isPaged;
39345
38943
  exports.isReportedByMe = isReportedByMe;
39346
38944
  exports.isSkip = isSkip;
39347
38945
  exports.mergeInCache = mergeInCache;
39348
- exports.notificationTray = index$6;
38946
+ exports.notificationTray = index$5;
39349
38947
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
39350
38948
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
39351
38949
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;