forked from GetStream/stream-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeed.ts
653 lines (579 loc) · 23 KB
/
feed.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
/// <reference path="../types/modules.d.ts" />
import * as Faye from 'faye';
import { StreamClient, APIResponse, UR, RealTimeMessage, DefaultGenerics } from './client';
import { StreamUser, EnrichedUser } from './user';
import { FeedError, SiteError } from './errors';
import utils from './utils';
import { EnrichedReaction } from './reaction';
import { CollectionResponse } from './collections';
export type FollowStatsOptions = {
followerSlugs?: string[];
followingSlugs?: string[];
};
export type EnrichOptions = {
enrich?: boolean;
ownReactions?: boolean; // best not to use it, will be removed by client.replaceReactionOptions()
reactionKindsFilter?: string[]; // TODO: add support for array sample: kind,kind,kind
recentReactionsLimit?: number;
withOwnChildren?: boolean;
withOwnReactions?: boolean;
withReactionCounts?: boolean;
withRecentReactions?: boolean;
withUserId?: string;
};
export type FeedPaginationOptions = {
id_gt?: string;
id_gte?: string;
id_lt?: string;
id_lte?: string;
limit?: number;
refresh?: boolean;
};
export type RankedFeedOptions = {
offset?: number;
ranking?: string;
rankingVars?: Record<string, string | number>;
session?: string;
withScoreVars?: boolean;
};
export type NotificationFeedOptions = {
mark_read?: boolean | 'current' | string[];
mark_seen?: boolean | 'current' | string[];
};
export type FeedContextOptions = {
user_id?: string;
};
export type GetFeedOptions = FeedPaginationOptions &
EnrichOptions &
RankedFeedOptions &
NotificationFeedOptions &
FeedContextOptions;
export type GetFollowOptions = {
filter?: string[];
limit?: number;
offset?: number;
};
export type GetFollowAPIResponse = APIResponse & {
results: { created_at: string; feed_id: string; target_id: string; updated_at: string }[];
};
export type FollowStatsAPIResponse = APIResponse & {
results: {
followers: { count: number; feed: string };
following: { count: number; feed: string };
};
};
type BaseActivity = {
verb: string;
target?: string;
to?: string[];
};
export type NewActivity<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
StreamFeedGenerics['activityType'] &
BaseActivity & {
actor: string | StreamUser;
object: string | unknown;
foreign_id?: string;
time?: string;
};
export type UpdateActivity<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
StreamFeedGenerics['activityType'] &
BaseActivity & {
actor: string;
foreign_id: string;
object: string | unknown;
time: string;
};
export type Activity<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
StreamFeedGenerics['activityType'] &
BaseActivity & {
actor: string;
foreign_id: string;
id: string;
object: string | unknown;
time: string;
analytics?: Record<string, number>; // ranked feeds only
extra_context?: UR;
origin?: string;
score?: number; // ranked feeds only
// ** Add new fields to EnrichedActivity as well **
};
export type ReactionsRecords<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> = Record<
string,
EnrichedReaction<StreamFeedGenerics>[]
>;
export type EnrichedActivity<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
StreamFeedGenerics['activityType'] &
BaseActivity &
Pick<Activity, 'foreign_id' | 'id' | 'time' | 'analytics' | 'extra_context' | 'origin' | 'score'> & {
actor: EnrichedUser<StreamFeedGenerics> | string;
// Object should be casted based on the verb
object:
| string
| unknown
| EnrichedActivity<StreamFeedGenerics>
| EnrichedReaction<StreamFeedGenerics>
| CollectionResponse<StreamFeedGenerics>;
latest_reactions?: ReactionsRecords<StreamFeedGenerics>;
latest_reactions_extra?: Record<string, { next?: string }>;
own_reactions?: ReactionsRecords<StreamFeedGenerics>;
own_reactions_extra?: Record<string, { next?: string }>;
// Reaction posted to feed
reaction?: EnrichedReaction<StreamFeedGenerics>;
// enriched reactions
reaction_counts?: Record<string, number>;
};
export type FlatActivity<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> = Activity<StreamFeedGenerics>;
export type FlatActivityEnriched<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
EnrichedActivity<StreamFeedGenerics>;
type BaseAggregatedActivity = {
activity_count: number;
actor_count: number;
created_at: string;
group: string;
id: string;
updated_at: string;
verb: string;
score?: number;
};
export type AggregatedActivity<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
BaseAggregatedActivity & {
activities: Activity<StreamFeedGenerics>[];
};
export type AggregatedActivityEnriched<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
BaseAggregatedActivity & {
activities: EnrichedActivity<StreamFeedGenerics>[];
};
type BaseNotificationActivity = { is_read: boolean; is_seen: boolean };
export type NotificationActivity<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
AggregatedActivity<StreamFeedGenerics> & BaseNotificationActivity;
export type NotificationActivityEnriched<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
BaseNotificationActivity & AggregatedActivityEnriched<StreamFeedGenerics>;
export type FeedAPIResponse<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> = APIResponse & {
next: string;
results:
| FlatActivity<StreamFeedGenerics>[]
| FlatActivityEnriched<StreamFeedGenerics>[]
| AggregatedActivity<StreamFeedGenerics>[]
| AggregatedActivityEnriched<StreamFeedGenerics>[]
| NotificationActivity<StreamFeedGenerics>[]
| NotificationActivityEnriched<StreamFeedGenerics>[];
// Notification Feed only
unread?: number;
unseen?: number;
};
export type PersonalizationFeedAPIResponse<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> =
APIResponse & {
limit: number;
next: string;
offset: number;
results: FlatActivityEnriched<StreamFeedGenerics>[];
version: string;
};
export type GetActivitiesAPIResponse<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> = APIResponse & {
results: FlatActivity<StreamFeedGenerics>[] | FlatActivityEnriched<StreamFeedGenerics>[];
};
export type ToTargetUpdate = {
foreignId: string;
time: string;
addedTargets?: string[];
newTargets?: string[];
removedTargets?: string[];
};
type ToTargetUpdateInternal = {
foreign_id: string;
time: string;
added_targets?: string[];
new_targets?: string[];
removed_targets?: string[];
};
/**
* Manage api calls for specific feeds
* The feed object contains convenience functions such add activity, remove activity etc
* @class StreamFeed
*/
export class StreamFeed<StreamFeedGenerics extends DefaultGenerics = DefaultGenerics> {
client: StreamClient<StreamFeedGenerics>;
token: string;
id: string;
slug: string;
userId: string;
feedUrl: string;
feedTogether: string;
notificationChannel: string;
/**
* Initialize a feed object
* @link https://getstream.io/activity-feeds/docs/node/adding_activities/?language=js
* @method constructor
* @memberof StreamFeed.prototype
* @param {StreamClient} client - The stream client this feed is constructed from
* @param {string} feedSlug - The feed slug
* @param {string} userId - The user id
* @param {string} [token] - The authentication token
*/
constructor(client: StreamClient<StreamFeedGenerics>, feedSlug: string, userId: string, token: string) {
if (!feedSlug || !userId) {
throw new FeedError('Please provide a feed slug and user id, ie client.feed("user", "1")');
}
if (feedSlug.indexOf(':') !== -1) {
throw new FeedError('Please initialize the feed using client.feed("user", "1") not client.feed("user:1")');
}
utils.validateFeedSlug(feedSlug);
utils.validateUserId(userId);
// raise an error if there is no token
if (!token) {
throw new FeedError('Missing token, in client side mode please provide a feed secret');
}
this.client = client;
this.slug = feedSlug;
this.userId = userId;
this.id = `${this.slug}:${this.userId}`;
this.token = token;
this.feedUrl = this.id.replace(':', '/');
this.feedTogether = this.id.replace(':', '');
// faye setup
this.notificationChannel = `site-${this.client.appId}-feed-${this.feedTogether}`;
}
/**
* Adds the given activity to the feed
* @link https://getstream.io/activity-feeds/docs/node/adding_activities/?language=js#adding-activities-basic
* @method addActivity
* @memberof StreamFeed.prototype
* @param {NewActivity<StreamFeedGenerics>} activity - The activity to add
* @return {Promise<Activity<StreamFeedGenerics>>}
*/
addActivity(activity: NewActivity<StreamFeedGenerics>) {
activity = utils.replaceStreamObjects(activity);
if (!activity.actor && this.client.currentUser) {
activity.actor = this.client.currentUser.ref();
}
return this.client.post<Activity<StreamFeedGenerics>>({
url: `feed/${this.feedUrl}/`,
body: activity,
token: this.token,
});
}
/**
* Removes the activity by activityId or foreignId
* @link https://getstream.io/activity-feeds/docs/node/adding_activities/?language=js#removing-activities
* @method removeActivity
* @memberof StreamFeed.prototype
* @param {string} activityOrActivityId Identifier of activity to remove
* @return {Promise<APIResponse & { removed: string }>}
* @example feed.removeActivity(activityId);
* @example feed.removeActivity({'foreign_id': foreignId});
*/
removeActivity(activityOrActivityId: string | { foreignId: string } | { foreign_id: string }) {
const foreign_id =
(activityOrActivityId as { foreignId?: string }).foreignId ||
(activityOrActivityId as { foreign_id?: string }).foreign_id;
return this.client.delete<APIResponse & { removed: string }>({
url: `feed/${this.feedUrl}/${foreign_id || activityOrActivityId}/`,
qs: foreign_id ? { foreign_id: '1' } : {},
token: this.token,
});
}
/**
* Adds the given activities to the feed
* @link https://getstream.io/activity-feeds/docs/node/add_many_activities/?language=js#batch-add-activities
* @method addActivities
* @memberof StreamFeed.prototype
* @param {NewActivity<StreamFeedGenerics>[]} activities Array of activities to add
* @return {Promise<Activity<StreamFeedGenerics>[]>}
*/
addActivities(activities: NewActivity<StreamFeedGenerics>[]) {
return this.client.post<Activity<StreamFeedGenerics>[]>({
url: `feed/${this.feedUrl}/`,
body: { activities: utils.replaceStreamObjects(activities) },
token: this.token,
});
}
/**
* Follows the given target feed
* @link https://getstream.io/activity-feeds/docs/node/following/?language=js
* @method follow
* @memberof StreamFeed.prototype
* @param {string} targetSlug Slug of the target feed
* @param {string} targetUserId User identifier of the target feed
* @param {object} [options] Additional options
* @param {number} [options.limit] Limit the amount of activities copied over on follow
* @return {Promise<APIResponse>}
* @example feed.follow('user', '1');
* @example feed.follow('user', '1');
* @example feed.follow('user', '1', options);
*/
follow(targetSlug: string, targetUserId: string | { id: string }, options: { limit?: number } = {}) {
if (targetUserId instanceof StreamUser) {
targetUserId = targetUserId.id;
}
utils.validateFeedSlug(targetSlug);
utils.validateUserId(targetUserId as string);
const body: { target: string; activity_copy_limit?: number } = { target: `${targetSlug}:${targetUserId}` };
if (typeof options.limit === 'number') body.activity_copy_limit = options.limit;
return this.client.post<APIResponse>({
url: `feed/${this.feedUrl}/following/`,
body,
token: this.token,
});
}
/**
* Unfollow the given feed
* @link https://getstream.io/activity-feeds/docs/node/following/?language=js#unfollowing-feeds
* @method unfollow
* @memberof StreamFeed.prototype
* @param {string} targetSlug Slug of the target feed
* @param {string} targetUserId User identifier of the target feed
* @param {object} [options]
* @param {boolean} [options.keepHistory] when provided the activities from target
* feed will not be kept in the feed
* @return {Promise<APIResponse>}
* @example feed.unfollow('user', '2');
*/
unfollow(targetSlug: string, targetUserId: string, options: { keepHistory?: boolean } = {}) {
const qs: { keep_history?: string } = {};
if (typeof options.keepHistory === 'boolean' && options.keepHistory) qs.keep_history = '1';
utils.validateFeedSlug(targetSlug);
utils.validateUserId(targetUserId);
const targetFeedId = `${targetSlug}:${targetUserId}`;
return this.client.delete<APIResponse>({
url: `feed/${this.feedUrl}/following/${targetFeedId}/`,
qs,
token: this.token,
});
}
/**
* List which feeds this feed is following
* @link https://getstream.io/activity-feeds/docs/node/following/?language=js#reading-followed-feeds
* @method following
* @memberof StreamFeed.prototype
* @param {GetFollowOptions} [options] Additional options
* @param {string[]} options.filter array of feed id to filter on
* @param {number} options.limit pagination
* @param {number} options.offset pagination
* @return {Promise<GetFollowAPIResponse>}
* @example feed.following({limit:10, filter: ['user:1', 'user:2']});
*/
following(options: GetFollowOptions = {}) {
const extraOptions: { filter?: string } = {};
if (options.filter) extraOptions.filter = options.filter.join(',');
return this.client.get<GetFollowAPIResponse>({
url: `feed/${this.feedUrl}/following/`,
qs: { ...options, ...extraOptions },
token: this.token,
});
}
/**
* List the followers of this feed
* @link https://getstream.io/activity-feeds/docs/node/following/?language=js#reading-feed-followers
* @method followers
* @memberof StreamFeed.prototype
* @param {GetFollowOptions} [options] Additional options
* @param {string[]} options.filter array of feed id to filter on
* @param {number} options.limit pagination
* @param {number} options.offset pagination
* @return {Promise<GetFollowAPIResponse>}
* @example feed.followers({limit:10, filter: ['user:1', 'user:2']});
*/
followers(options: GetFollowOptions = {}) {
const extraOptions: { filter?: string } = {};
if (options.filter) extraOptions.filter = options.filter.join(',');
return this.client.get<GetFollowAPIResponse>({
url: `feed/${this.feedUrl}/followers/`,
qs: { ...options, ...extraOptions },
token: this.token,
});
}
/**
* Retrieve the number of follower and following feed stats of the current feed.
* For each count, feed slugs can be provided to filter counts accordingly.
* @link https://getstream.io/activity-feeds/docs/node/following/?language=js#reading-follow-stats
* @method followStats
* @param {object} [options]
* @param {string[]} [options.followerSlugs] find counts only on these slugs
* @param {string[]} [options.followingSlugs] find counts only on these slugs
* @return {Promise<FollowStatsAPIResponse>}
* @example feed.followStats();
* @example feed.followStats({ followerSlugs:['user', 'news'], followingSlugs:['timeline'] });
*/
followStats(options: FollowStatsOptions = {}) {
const qs: { followers: string; following: string; followers_slugs?: string; following_slugs?: string } = {
followers: this.id,
following: this.id,
};
if (options.followerSlugs && options.followerSlugs.length) qs.followers_slugs = options.followerSlugs.join(',');
if (options.followingSlugs && options.followingSlugs.length) qs.following_slugs = options.followingSlugs.join(',');
return this.client.get<FollowStatsAPIResponse>({
url: 'stats/follow/',
qs,
token: this.client.getOrCreateToken() || this.token,
});
}
/**
* Reads the feed
* @link https://getstream.io/activity-feeds/docs/node/adding_activities/?language=js#retrieving-activities
* @method get
* @memberof StreamFeed.prototype
* @param {GetFeedOptions} options Additional options
* @return {Promise<FeedAPIResponse>}
* @example feed.get({limit: 10, id_lte: 'activity-id'})
* @example feed.get({limit: 10, mark_seen: true})
*/
get(options: GetFeedOptions = {}) {
const extraOptions: { mark_read?: boolean | string; mark_seen?: boolean | string } = {};
if (options.mark_read && (options.mark_read as string[]).join) {
extraOptions.mark_read = (options.mark_read as string[]).join(',');
}
if (options.mark_seen && (options.mark_seen as string[]).join) {
extraOptions.mark_seen = (options.mark_seen as string[]).join(',');
}
this.client.replaceReactionOptions(options);
const path = this.client.shouldUseEnrichEndpoint(options) ? 'enrich/feed/' : 'feed/';
return this.client.get<FeedAPIResponse<StreamFeedGenerics>>({
url: `${path}${this.feedUrl}/`,
qs: { ...options, ...extraOptions },
token: this.token,
});
}
/**
* Retrieves one activity from a feed and adds enrichment
* @link https://getstream.io/activity-feeds/docs/node/adding_activities/?language=js#retrieving-activities
* @method getActivityDetail
* @memberof StreamFeed.prototype
* @param {string} activityId Identifier of activity to retrieve
* @param {EnrichOptions} options Additional options
* @return {Promise<FeedAPIResponse>}
* @example feed.getActivityDetail(activityId)
* @example feed.getActivityDetail(activityId, {withRecentReactions: true})
* @example feed.getActivityDetail(activityId, {withReactionCounts: true})
* @example feed.getActivityDetail(activityId, {withScoreVars: true})
* @example feed.getActivityDetail(activityId, {withOwnReactions: true, withReactionCounts: true})
*/
getActivityDetail(activityId: string, options: EnrichOptions) {
return this.get({
id_lte: activityId,
id_gte: activityId,
limit: 1,
...(options || {}),
});
}
/**
* Returns the current faye client object
* @method getFayeClient
* @memberof StreamFeed.prototype
* @access private
* @return {Faye.Client} Faye client
*/
getFayeClient() {
return this.client.getFayeClient();
}
/**
* Subscribes to any changes in the feed, return a promise
* @link https://getstream.io/activity-feeds/docs/node/web_and_mobile/?language=js#subscribe-to-realtime-updates-via-api-client
* @method subscribe
* @memberof StreamFeed.prototype
* @param {function} Faye.Callback<RealTimeMessage<StreamFeedGenerics>> Callback to call on completion
* @return {Promise<Faye.Subscription>}
* @example
* feed.subscribe(callback).then(function(){
* console.log('we are now listening to changes');
* });
*/
subscribe(callback: Faye.SubscribeCallback<RealTimeMessage<StreamFeedGenerics>>) {
if (!this.client.appId) {
throw new SiteError(
'Missing app id, which is needed to subscribe, use var client = stream.connect(key, secret, appId);',
);
}
const subscription = this.getFayeClient().subscribe(`/${this.notificationChannel}`, callback);
this.client.subscriptions[`/${this.notificationChannel}`] = {
token: this.token,
userId: this.notificationChannel,
fayeSubscription: subscription,
};
return subscription;
}
/**
* Cancel updates created via feed.subscribe()
* @link https://getstream.io/activity-feeds/docs/node/web_and_mobile/?language=js#subscribe-to-realtime-updates-via-api-client
* @return void
*/
unsubscribe() {
const streamSubscription = this.client.subscriptions[`/${this.notificationChannel}`];
if (streamSubscription) {
delete this.client.subscriptions[`/${this.notificationChannel}`];
(streamSubscription.fayeSubscription as Faye.Subscription).cancel();
}
}
_validateToTargetInput(
foreignId: string,
time: string,
newTargets?: string[],
addedTargets?: string[],
removedTargets?: string[],
) {
if (!foreignId) throw new Error('Missing `foreign_id` parameter!');
if (!time) throw new Error('Missing `time` parameter!');
if (!newTargets && !addedTargets && !removedTargets) {
throw new Error(
'Requires you to provide at least one parameter for `newTargets`, `addedTargets`, or `removedTargets` - example: `updateActivityToTargets("foreignID:1234", new Date(), [newTargets...], [addedTargets...], [removedTargets...])`',
);
}
if (newTargets) {
if (addedTargets || removedTargets) {
throw new Error("Can't include add_targets or removedTargets if you're also including newTargets");
}
}
if (addedTargets && removedTargets) {
// brute force - iterate through added, check to see if removed contains that element
addedTargets.forEach((addedTarget) => {
if (removedTargets.includes(addedTarget)) {
throw new Error("Can't have the same feed ID in addedTargets and removedTargets.");
}
});
}
}
/**
* Updates an activity's "to" fields
* @link https://getstream.io/activity-feeds/docs/node/targeting/?language=js
* @param {string} foreignId The foreign_id of the activity to update
* @param {string} time The time of the activity to update
* @param {string[]} newTargets Set the new "to" targets for the activity - will remove old targets
* @param {string[]} addedTargets Add these new targets to the activity
* @param {string[]} removedTargets Remove these targets from the activity
*/
updateActivityToTargets(
foreignId: string,
time: string,
newTargets?: string[],
addedTargets?: string[],
removedTargets?: string[],
) {
return this._updateActivityToTargetsMany([{ foreignId, time, newTargets, addedTargets, removedTargets }]);
}
// NOTE: it can change without notice
_updateActivityToTargetsMany(inputs: ToTargetUpdate[]) {
if (!inputs || inputs.length === 0) {
throw new Error('At least one input is required');
}
const body: ToTargetUpdateInternal[] = [];
for (let i = 0; i < inputs.length; i++) {
const input = inputs[i];
this._validateToTargetInput(
input.foreignId,
input.time,
input.newTargets,
input.addedTargets,
input.removedTargets,
);
const item: ToTargetUpdateInternal = { foreign_id: input.foreignId, time: input.time };
if (input.newTargets) item.new_targets = input.newTargets;
if (input.addedTargets) item.added_targets = input.addedTargets;
if (input.removedTargets) item.removed_targets = input.removedTargets;
body.push(item);
}
return this.client.post<APIResponse & Activity<StreamFeedGenerics> & { added?: string[]; removed?: string[] }>({
url: `feed_targets/${this.feedUrl}/activity_to_targets/`,
token: this.token,
body: body.length > 1 ? body : body[0],
});
}
}