@reactoo/watchtogether-sdk-js 2.7.7 → 2.7.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.7.7",
3
+ "version": "2.7.8",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -1,21 +1,33 @@
1
1
  'use strict';
2
2
 
3
- import {generateUUID} from "../modules/wt-utils";
3
+ import {generateUUID, chunkArray} from "../modules/wt-utils";
4
4
 
5
5
  let asset = function() {
6
6
  return {
7
7
  getAssetList: ({type = 'instanceType', instanceType, assetType, size = 20, startKey = null, roomId, ids}) => {
8
- let apiParams = {
9
- type,
10
- ...(instanceType && {instanceType: instanceType === true ? this.__instanceType : instanceType }),
11
- ...(assetType && {assetType}),
12
- ...(size && !ids && {size}),
13
- ...(ids && {ids: ids.join(',')}),
14
- ...(roomId && {roomId}),
15
- ...(startKey && {startKey})
16
- };
17
- return this.__privates.auth.__client
18
- .then(client => client.apis.asset.getAssetList(apiParams))
8
+ return chunkArray(ids, 50)
9
+ .reduce((promiseChain, idsChunk) => {
10
+ return promiseChain.then(chainResponse => {
11
+ let apiParams = {
12
+ type,
13
+ ...(instanceType && {instanceType: instanceType === true ? this.__instanceType : instanceType }),
14
+ ...(assetType && {assetType}),
15
+ ...(size && !ids && {size}),
16
+ ...(idsChunk?.length && {ids: idsChunk.join(',')}),
17
+ ...(roomId && {roomId}),
18
+ ...(startKey && {startKey})
19
+ };
20
+ return this.__privates.auth.__client
21
+ .then(client => client.apis.asset.getAssetList(apiParams))
22
+ .then(response => type === 'ids' ? {
23
+ data: {
24
+ items: [...chainResponse.data.items, ...response.data.items],
25
+ size: chainResponse.data.size + response.data.size,
26
+ startKey: null,
27
+ },
28
+ } : response);
29
+ });
30
+ }, Promise.resolve({data: {items: [], size: 0, startKey: null}}));
19
31
  },
20
32
  getAssetById: (id) => {
21
33
  return this.__privates.auth.__client
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import {generateUUID} from "../modules/wt-utils";
3
+ import {generateUUID, chunkArray} from "../modules/wt-utils";
4
4
  import {serializeError} from "serialize-error";
5
5
 
6
6
  let user = function () {
@@ -95,14 +95,26 @@ let user = function () {
95
95
  .then(client => client.apis.user.getUserById({id}))
96
96
  },
97
97
  getUsersByIds: ({ids = [], size = null, startKey = null } = {}) => {
98
- let apiParams = {
99
- type : 'ids',
100
- ...(size && {size}),
101
- ...(ids && {ids:ids.join(',')}),
102
- ...(startKey && {startKey})
103
- };
104
- return this.__privates.auth.__client
105
- .then(client => client.apis.user.getUsers(apiParams))
98
+ return chunkArray(ids, 50)
99
+ .reduce((promiseChain, idsChunk) => {
100
+ return promiseChain.then(chainResponse => {
101
+ let apiParams = {
102
+ type : 'ids',
103
+ ...(size && {size}),
104
+ ...(idsChunk?.length && {ids: idsChunk.join(',')}),
105
+ ...(startKey && {startKey})
106
+ };
107
+ return this.__privates.auth.__client
108
+ .then(client => client.apis.user.getUsers(apiParams))
109
+ .then(response => ({
110
+ data: {
111
+ items: [...chainResponse.data.items, ...response.data.items],
112
+ size: chainResponse.data.size + response.data.size,
113
+ startKey: null,
114
+ },
115
+ }));
116
+ });
117
+ }, Promise.resolve({data: {items: [], size: 0, startKey: null}}));
106
118
  },
107
119
  getUsers: ({type, userId, roomId, size = 20, startKey = null} = {}) => {
108
120
  let apiParams = {
@@ -128,6 +128,14 @@ const maxJitter = (x) => {
128
128
  return a / (1 + Math.exp(-b * (x - c))) + d; // Fixed the typo here
129
129
  }
130
130
 
131
+ const chunkArray = (array, chunkSize) => {
132
+ if (!array?.length) return [[]];
131
133
 
134
+ let results = [];
135
+ while (array.length) {
136
+ results.push(array.splice(0, chunkSize));
137
+ }
138
+ return results;
139
+ }
132
140
 
133
- export {wait, getBrowserFingerprint, generateUUID, decodeJanusDisplay, setExactTimeout, clearExactTimeout, median, maxJitter}
141
+ export {wait, getBrowserFingerprint, generateUUID, decodeJanusDisplay, setExactTimeout, clearExactTimeout, median, maxJitter, chunkArray}