@meltwater/conversations-api-services 1.0.46 → 1.0.47
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.
|
@@ -130,13 +130,42 @@ async function getProfile(token, business_id) {
|
|
|
130
130
|
const profile = (await sendRequest(token, `get/?business_id=${business_id}&fields=${fields}`, logger)) || {};
|
|
131
131
|
return profile;
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Processes an array in chunks of a specified size.
|
|
136
|
+
* @param {Array} array - The array to process.
|
|
137
|
+
* @param {number} chunkSize - The size of each chunk.
|
|
138
|
+
* @param {Function} callback - The function to call for each chunk.
|
|
139
|
+
*/
|
|
140
|
+
async function processInChunks(array, chunkSize, callback) {
|
|
141
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
142
|
+
const chunk = array.slice(i, i + chunkSize);
|
|
143
|
+
await callback(chunk);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
133
146
|
async function getStats(token, business_id, externalIds) {
|
|
134
147
|
let paramString = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'video/list/';
|
|
135
148
|
let logger = arguments.length > 4 ? arguments[4] : undefined;
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
const results = [];
|
|
150
|
+
|
|
151
|
+
// process externalIds in chunks of 20 (tiktok limit)
|
|
152
|
+
await processInChunks(externalIds, 20, async chunk => {
|
|
153
|
+
const profile = (await sendRequest(token, `${paramString}?business_id=${business_id}&fields=["item_id","create_time","thumbnail_url","share_url","embed_url","caption","video_views","likes","comments","shares"]&filters=${JSON.stringify({
|
|
154
|
+
video_ids: chunk
|
|
155
|
+
})}`, logger)) || {};
|
|
156
|
+
results.push(profile);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// merge results if multiple calls were made
|
|
160
|
+
if (results.length > 1) {
|
|
161
|
+
results[0].data.videos = results.reduce((acc, _ref2) => {
|
|
162
|
+
let {
|
|
163
|
+
data
|
|
164
|
+
} = _ref2;
|
|
165
|
+
return acc.concat(data.videos);
|
|
166
|
+
}, []);
|
|
167
|
+
}
|
|
168
|
+
return results[0];
|
|
140
169
|
}
|
|
141
170
|
|
|
142
171
|
// This doesn't appear to be used in Conversations either
|
|
@@ -113,13 +113,42 @@ export async function getProfile(token, business_id) {
|
|
|
113
113
|
const profile = (await sendRequest(token, `get/?business_id=${business_id}&fields=${fields}`, logger)) || {};
|
|
114
114
|
return profile;
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Processes an array in chunks of a specified size.
|
|
119
|
+
* @param {Array} array - The array to process.
|
|
120
|
+
* @param {number} chunkSize - The size of each chunk.
|
|
121
|
+
* @param {Function} callback - The function to call for each chunk.
|
|
122
|
+
*/
|
|
123
|
+
async function processInChunks(array, chunkSize, callback) {
|
|
124
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
125
|
+
const chunk = array.slice(i, i + chunkSize);
|
|
126
|
+
await callback(chunk);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
116
129
|
export async function getStats(token, business_id, externalIds) {
|
|
117
130
|
let paramString = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'video/list/';
|
|
118
131
|
let logger = arguments.length > 4 ? arguments[4] : undefined;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
const results = [];
|
|
133
|
+
|
|
134
|
+
// process externalIds in chunks of 20 (tiktok limit)
|
|
135
|
+
await processInChunks(externalIds, 20, async chunk => {
|
|
136
|
+
const profile = (await sendRequest(token, `${paramString}?business_id=${business_id}&fields=["item_id","create_time","thumbnail_url","share_url","embed_url","caption","video_views","likes","comments","shares"]&filters=${JSON.stringify({
|
|
137
|
+
video_ids: chunk
|
|
138
|
+
})}`, logger)) || {};
|
|
139
|
+
results.push(profile);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// merge results if multiple calls were made
|
|
143
|
+
if (results.length > 1) {
|
|
144
|
+
results[0].data.videos = results.reduce((acc, _ref2) => {
|
|
145
|
+
let {
|
|
146
|
+
data
|
|
147
|
+
} = _ref2;
|
|
148
|
+
return acc.concat(data.videos);
|
|
149
|
+
}, []);
|
|
150
|
+
}
|
|
151
|
+
return results[0];
|
|
123
152
|
}
|
|
124
153
|
|
|
125
154
|
// This doesn't appear to be used in Conversations either
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltwater/conversations-api-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"description": "Repository to contain all conversations api services shared across our services",
|
|
5
5
|
"main": "dist/cjs/data-access/index.js",
|
|
6
6
|
"module": "dist/esm/data-access/index.js",
|
|
@@ -169,6 +169,19 @@ export async function getProfile(
|
|
|
169
169
|
return profile;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Processes an array in chunks of a specified size.
|
|
174
|
+
* @param {Array} array - The array to process.
|
|
175
|
+
* @param {number} chunkSize - The size of each chunk.
|
|
176
|
+
* @param {Function} callback - The function to call for each chunk.
|
|
177
|
+
*/
|
|
178
|
+
async function processInChunks(array, chunkSize, callback) {
|
|
179
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
180
|
+
const chunk = array.slice(i, i + chunkSize);
|
|
181
|
+
await callback(chunk);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
172
185
|
export async function getStats(
|
|
173
186
|
token,
|
|
174
187
|
business_id,
|
|
@@ -176,17 +189,30 @@ export async function getStats(
|
|
|
176
189
|
paramString = 'video/list/',
|
|
177
190
|
logger
|
|
178
191
|
) {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
const results = [];
|
|
193
|
+
|
|
194
|
+
// process externalIds in chunks of 20 (tiktok limit)
|
|
195
|
+
await processInChunks(externalIds, 20, async (chunk) => {
|
|
196
|
+
const profile =
|
|
197
|
+
(await sendRequest(
|
|
198
|
+
token,
|
|
199
|
+
`${paramString}?business_id=${business_id}&fields=["item_id","create_time","thumbnail_url","share_url","embed_url","caption","video_views","likes","comments","shares"]&filters=${JSON.stringify(
|
|
200
|
+
{
|
|
201
|
+
video_ids: chunk,
|
|
202
|
+
}
|
|
203
|
+
)}`,
|
|
204
|
+
logger
|
|
205
|
+
)) || {};
|
|
206
|
+
results.push(profile);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// merge results if multiple calls were made
|
|
210
|
+
if(results.length > 1) {
|
|
211
|
+
results[0].data.videos = results.reduce((acc, {data}) => {
|
|
212
|
+
return acc.concat(data.videos);
|
|
213
|
+
}, []);
|
|
214
|
+
}
|
|
215
|
+
return results[0];
|
|
190
216
|
}
|
|
191
217
|
|
|
192
218
|
// This doesn't appear to be used in Conversations either
|