stream-chat 8.17.0 → 8.18.1
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/dist/browser.es.js +902 -395
- package/dist/browser.es.js.map +1 -1
- package/dist/browser.full-bundle.min.js +1 -1
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/browser.js +903 -394
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +902 -395
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +903 -394
- package/dist/index.js.map +1 -1
- package/dist/types/campaign.d.ts +35 -0
- package/dist/types/campaign.d.ts.map +1 -0
- package/dist/types/client.d.ts +46 -50
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/segment.d.ts +35 -0
- package/dist/types/segment.d.ts.map +1 -0
- package/dist/types/thread.d.ts +5 -0
- package/dist/types/thread.d.ts.map +1 -1
- package/dist/types/types.d.ts +52 -30
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/campaign.ts +97 -0
- package/src/client.ts +119 -92
- package/src/index.ts +2 -0
- package/src/segment.ts +89 -0
- package/src/thread.ts +18 -6
- package/src/types.ts +53 -34
- package/src/utils.ts +1 -0
package/src/client.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { StableWSConnection } from './connection';
|
|
|
11
11
|
import { CheckSignature, DevToken, JWTUserToken } from './signing';
|
|
12
12
|
import { TokenManager } from './token_manager';
|
|
13
13
|
import { WSConnectionFallback } from './connection_fallback';
|
|
14
|
+
import { Campaign } from './campaign';
|
|
15
|
+
import { Segment } from './segment';
|
|
14
16
|
import { isErrorResponse, isWSFailure } from './errors';
|
|
15
17
|
import {
|
|
16
18
|
addFileToFormData,
|
|
@@ -38,7 +40,7 @@ import {
|
|
|
38
40
|
BaseDeviceFields,
|
|
39
41
|
BlockList,
|
|
40
42
|
BlockListResponse,
|
|
41
|
-
|
|
43
|
+
CampaignResponse,
|
|
42
44
|
CampaignData,
|
|
43
45
|
CampaignFilters,
|
|
44
46
|
CampaignQueryOptions,
|
|
@@ -65,7 +67,6 @@ import {
|
|
|
65
67
|
CustomPermissionOptions,
|
|
66
68
|
DeactivateUsersOptions,
|
|
67
69
|
DefaultGenerics,
|
|
68
|
-
DeleteCampaignOptions,
|
|
69
70
|
DeleteChannelsResponse,
|
|
70
71
|
DeleteCommandResponse,
|
|
71
72
|
DeleteUserOptions,
|
|
@@ -136,7 +137,7 @@ import {
|
|
|
136
137
|
SearchMessageSortBase,
|
|
137
138
|
SearchOptions,
|
|
138
139
|
SearchPayload,
|
|
139
|
-
|
|
140
|
+
SegmentResponse,
|
|
140
141
|
SegmentData,
|
|
141
142
|
SegmentType,
|
|
142
143
|
SendFileAPIResponse,
|
|
@@ -145,7 +146,6 @@ import {
|
|
|
145
146
|
SyncResponse,
|
|
146
147
|
TaskResponse,
|
|
147
148
|
TaskStatus,
|
|
148
|
-
TestCampaignResponse,
|
|
149
149
|
TestPushDataInput,
|
|
150
150
|
TestSNSDataInput,
|
|
151
151
|
TestSQSDataInput,
|
|
@@ -168,6 +168,10 @@ import {
|
|
|
168
168
|
PartialThreadUpdate,
|
|
169
169
|
QueryThreadsOptions,
|
|
170
170
|
GetThreadOptions,
|
|
171
|
+
CampaignSort,
|
|
172
|
+
SegmentTargetsResponse,
|
|
173
|
+
QuerySegmentTargetsFilter,
|
|
174
|
+
SortParam,
|
|
171
175
|
} from './types';
|
|
172
176
|
import { InsightMetrics, postInsights } from './insights';
|
|
173
177
|
import { Thread } from './thread';
|
|
@@ -2943,6 +2947,30 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
2943
2947
|
return this.get<APIResponse & ExportChannelStatusResponse>(`${this.baseURL}/export_channels/${id}`);
|
|
2944
2948
|
}
|
|
2945
2949
|
|
|
2950
|
+
campaign(idOrData: string | CampaignData, data?: CampaignData) {
|
|
2951
|
+
if (typeof idOrData === 'string') {
|
|
2952
|
+
return new Campaign(this, idOrData, data);
|
|
2953
|
+
}
|
|
2954
|
+
|
|
2955
|
+
return new Campaign(this, null, idOrData);
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
segment(type: SegmentType, idOrData: string | SegmentData, data?: SegmentData) {
|
|
2959
|
+
if (typeof idOrData === 'string') {
|
|
2960
|
+
return new Segment(this, type, idOrData, data);
|
|
2961
|
+
}
|
|
2962
|
+
|
|
2963
|
+
return new Segment(this, type, null, idOrData);
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
validateServerSideAuth() {
|
|
2967
|
+
if (!this.secret) {
|
|
2968
|
+
throw new Error(
|
|
2969
|
+
'Campaigns is a server-side only feature. Please initialize the client with a secret to use this feature.',
|
|
2970
|
+
);
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2946
2974
|
/**
|
|
2947
2975
|
* createSegment - Creates a segment
|
|
2948
2976
|
*
|
|
@@ -2952,17 +2980,17 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
2952
2980
|
* @param {string} name Segment name (valid UUID)
|
|
2953
2981
|
* @param {SegmentData} params Segment data
|
|
2954
2982
|
*
|
|
2955
|
-
* @return {
|
|
2983
|
+
* @return {{segment: SegmentResponse} & APIResponse} The created Segment
|
|
2956
2984
|
*/
|
|
2957
|
-
private async createSegment(type: SegmentType, id: string, name: string, data?: SegmentData)
|
|
2985
|
+
private async createSegment(type: SegmentType, id: string, name: string, data?: SegmentData) {
|
|
2986
|
+
this.validateServerSideAuth();
|
|
2958
2987
|
const body = {
|
|
2959
2988
|
id,
|
|
2960
2989
|
type,
|
|
2961
2990
|
name,
|
|
2962
2991
|
data,
|
|
2963
2992
|
};
|
|
2964
|
-
|
|
2965
|
-
return segment;
|
|
2993
|
+
return this.post<{ segment: SegmentResponse }>(this.baseURL + `/segments`, body);
|
|
2966
2994
|
}
|
|
2967
2995
|
|
|
2968
2996
|
/**
|
|
@@ -2974,8 +3002,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
2974
3002
|
*
|
|
2975
3003
|
* @return {Segment} The created Segment
|
|
2976
3004
|
*/
|
|
2977
|
-
async createUserSegment(id: string, name: string, data?: SegmentData)
|
|
2978
|
-
|
|
3005
|
+
async createUserSegment(id: string, name: string, data?: SegmentData) {
|
|
3006
|
+
this.validateServerSideAuth();
|
|
3007
|
+
return this.createSegment('user', id, name, data);
|
|
2979
3008
|
}
|
|
2980
3009
|
|
|
2981
3010
|
/**
|
|
@@ -2987,8 +3016,14 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
2987
3016
|
*
|
|
2988
3017
|
* @return {Segment} The created Segment
|
|
2989
3018
|
*/
|
|
2990
|
-
async createChannelSegment(id: string, name: string, data?: SegmentData)
|
|
2991
|
-
|
|
3019
|
+
async createChannelSegment(id: string, name: string, data?: SegmentData) {
|
|
3020
|
+
this.validateServerSideAuth();
|
|
3021
|
+
return this.createSegment('channel', id, name, data);
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
async getSegment(id: string) {
|
|
3025
|
+
this.validateServerSideAuth();
|
|
3026
|
+
return this.get<{ segment: SegmentResponse } & APIResponse>(this.baseURL + `/segments/${id}`);
|
|
2992
3027
|
}
|
|
2993
3028
|
|
|
2994
3029
|
/**
|
|
@@ -3000,8 +3035,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3000
3035
|
* @return {Segment} Updated Segment
|
|
3001
3036
|
*/
|
|
3002
3037
|
async updateSegment(id: string, data: Partial<UpdateSegmentData>) {
|
|
3003
|
-
|
|
3004
|
-
return segment;
|
|
3038
|
+
this.validateServerSideAuth();
|
|
3039
|
+
return this.put<{ segment: SegmentResponse }>(this.baseURL + `/segments/${id}`, data);
|
|
3005
3040
|
}
|
|
3006
3041
|
|
|
3007
3042
|
/**
|
|
@@ -3013,21 +3048,39 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3013
3048
|
* @return {APIResponse} API response
|
|
3014
3049
|
*/
|
|
3015
3050
|
async addSegmentTargets(id: string, targets: string[]) {
|
|
3016
|
-
|
|
3017
|
-
|
|
3051
|
+
this.validateServerSideAuth();
|
|
3052
|
+
const body = { target_ids: targets };
|
|
3053
|
+
return this.post<APIResponse>(this.baseURL + `/segments/${id}/addtargets`, body);
|
|
3018
3054
|
}
|
|
3019
3055
|
|
|
3056
|
+
async querySegmentTargets(
|
|
3057
|
+
id: string,
|
|
3058
|
+
filter: QuerySegmentTargetsFilter | null = {},
|
|
3059
|
+
sort: SortParam[] | null | [] = [],
|
|
3060
|
+
options = {},
|
|
3061
|
+
) {
|
|
3062
|
+
this.validateServerSideAuth();
|
|
3063
|
+
return this.post<{ targets: SegmentTargetsResponse[]; next?: string } & APIResponse>(
|
|
3064
|
+
this.baseURL + `/segments/${id}/targets/query`,
|
|
3065
|
+
{
|
|
3066
|
+
filter: filter || {},
|
|
3067
|
+
sort: sort || [],
|
|
3068
|
+
...options,
|
|
3069
|
+
},
|
|
3070
|
+
);
|
|
3071
|
+
}
|
|
3020
3072
|
/**
|
|
3021
|
-
*
|
|
3073
|
+
* removeSegmentTargets - Remove targets from a segment
|
|
3022
3074
|
*
|
|
3023
3075
|
* @param {string} id Segment ID
|
|
3024
3076
|
* @param {string[]} targets Targets to add to the segment
|
|
3025
3077
|
*
|
|
3026
3078
|
* @return {APIResponse} API response
|
|
3027
3079
|
*/
|
|
3028
|
-
async
|
|
3029
|
-
|
|
3030
|
-
|
|
3080
|
+
async removeSegmentTargets(id: string, targets: string[]) {
|
|
3081
|
+
this.validateServerSideAuth();
|
|
3082
|
+
const body = { target_ids: targets };
|
|
3083
|
+
return this.post<APIResponse>(this.baseURL + `/segments/${id}/deletetargets`, body);
|
|
3031
3084
|
}
|
|
3032
3085
|
|
|
3033
3086
|
/**
|
|
@@ -3038,15 +3091,17 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3038
3091
|
*
|
|
3039
3092
|
* @return {Segment[]} Segments
|
|
3040
3093
|
*/
|
|
3041
|
-
async querySegments(filter: {}, options: QuerySegmentsOptions = {}) {
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3094
|
+
async querySegments(filter: {}, sort?: SortParam[], options: QuerySegmentsOptions = {}) {
|
|
3095
|
+
this.validateServerSideAuth();
|
|
3096
|
+
return this.post<
|
|
3097
|
+
{
|
|
3098
|
+
segments: SegmentResponse[];
|
|
3099
|
+
next?: string;
|
|
3100
|
+
} & APIResponse
|
|
3101
|
+
>(this.baseURL + `/segments/query`, {
|
|
3102
|
+
filter,
|
|
3103
|
+
sort,
|
|
3104
|
+
...options,
|
|
3050
3105
|
});
|
|
3051
3106
|
}
|
|
3052
3107
|
|
|
@@ -3058,7 +3113,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3058
3113
|
* @return {Promise<APIResponse>} The Server Response
|
|
3059
3114
|
*/
|
|
3060
3115
|
async deleteSegment(id: string) {
|
|
3061
|
-
|
|
3116
|
+
this.validateServerSideAuth();
|
|
3117
|
+
return this.delete<APIResponse>(this.baseURL + `/segments/${id}`);
|
|
3062
3118
|
}
|
|
3063
3119
|
|
|
3064
3120
|
/**
|
|
@@ -3070,7 +3126,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3070
3126
|
* @return {Promise<APIResponse>} The Server Response
|
|
3071
3127
|
*/
|
|
3072
3128
|
async segmentTargetExists(segmentId: string, targetId: string) {
|
|
3073
|
-
|
|
3129
|
+
this.validateServerSideAuth();
|
|
3130
|
+
return this.get<APIResponse>(this.baseURL + `/segments/${segmentId}/target/${targetId}`);
|
|
3074
3131
|
}
|
|
3075
3132
|
|
|
3076
3133
|
/**
|
|
@@ -3081,27 +3138,38 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3081
3138
|
* @return {Campaign} The Created Campaign
|
|
3082
3139
|
*/
|
|
3083
3140
|
async createCampaign(params: CampaignData) {
|
|
3084
|
-
|
|
3085
|
-
return campaign;
|
|
3141
|
+
this.validateServerSideAuth();
|
|
3142
|
+
return this.post<{ campaign: CampaignResponse } & APIResponse>(this.baseURL + `/campaigns`, { ...params });
|
|
3086
3143
|
}
|
|
3087
3144
|
|
|
3145
|
+
async getCampaign(id: string) {
|
|
3146
|
+
this.validateServerSideAuth();
|
|
3147
|
+
return this.get<{ campaign: CampaignResponse } & APIResponse>(this.baseURL + `/campaigns/${id}`);
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
async startCampaign(id: string, scheduledFor?: string) {
|
|
3151
|
+
this.validateServerSideAuth();
|
|
3152
|
+
return this.post<{ campaign: CampaignResponse } & APIResponse>(this.baseURL + `/campaigns/${id}/start`, {
|
|
3153
|
+
scheduled_for: scheduledFor,
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
3088
3156
|
/**
|
|
3089
3157
|
* queryCampaigns - Query Campaigns
|
|
3090
3158
|
*
|
|
3091
3159
|
*
|
|
3092
3160
|
* @return {Campaign[]} Campaigns
|
|
3093
3161
|
*/
|
|
3094
|
-
async queryCampaigns(
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
},
|
|
3162
|
+
async queryCampaigns(filter: CampaignFilters, sort?: CampaignSort, options?: CampaignQueryOptions) {
|
|
3163
|
+
this.validateServerSideAuth();
|
|
3164
|
+
return await this.post<
|
|
3165
|
+
{
|
|
3166
|
+
campaigns: CampaignResponse[];
|
|
3167
|
+
next?: string;
|
|
3168
|
+
} & APIResponse
|
|
3169
|
+
>(this.baseURL + `/campaigns/query`, {
|
|
3170
|
+
filter,
|
|
3171
|
+
sort,
|
|
3172
|
+
...(options || {}),
|
|
3105
3173
|
});
|
|
3106
3174
|
}
|
|
3107
3175
|
|
|
@@ -3114,10 +3182,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3114
3182
|
* @return {Campaign} Updated Campaign
|
|
3115
3183
|
*/
|
|
3116
3184
|
async updateCampaign(id: string, params: Partial<CampaignData>) {
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
});
|
|
3120
|
-
return campaign;
|
|
3185
|
+
this.validateServerSideAuth();
|
|
3186
|
+
return this.put<{ campaign: CampaignResponse }>(this.baseURL + `/campaigns/${id}`, params);
|
|
3121
3187
|
}
|
|
3122
3188
|
|
|
3123
3189
|
/**
|
|
@@ -3127,24 +3193,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3127
3193
|
*
|
|
3128
3194
|
* @return {Promise<APIResponse>} The Server Response
|
|
3129
3195
|
*/
|
|
3130
|
-
async deleteCampaign(id: string
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
/**
|
|
3135
|
-
* scheduleCampaign - Schedule a Campaign
|
|
3136
|
-
*
|
|
3137
|
-
* @param {string} id Campaign ID
|
|
3138
|
-
* @param {{scheduledFor: number}} params Schedule params
|
|
3139
|
-
*
|
|
3140
|
-
* @return {Campaign} Scheduled Campaign
|
|
3141
|
-
*/
|
|
3142
|
-
async scheduleCampaign(id: string, params: { scheduledFor: number }) {
|
|
3143
|
-
const { scheduledFor } = params;
|
|
3144
|
-
const { campaign } = await this.patch<{ campaign: Campaign }>(this.baseURL + `/campaigns/${id}/schedule`, {
|
|
3145
|
-
scheduled_for: scheduledFor,
|
|
3146
|
-
});
|
|
3147
|
-
return campaign;
|
|
3196
|
+
async deleteCampaign(id: string) {
|
|
3197
|
+
this.validateServerSideAuth();
|
|
3198
|
+
return this.delete<APIResponse>(this.baseURL + `/campaigns/${id}`);
|
|
3148
3199
|
}
|
|
3149
3200
|
|
|
3150
3201
|
/**
|
|
@@ -3155,35 +3206,11 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3155
3206
|
* @return {Campaign} Stopped Campaign
|
|
3156
3207
|
*/
|
|
3157
3208
|
async stopCampaign(id: string) {
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
}
|
|
3161
|
-
|
|
3162
|
-
/**
|
|
3163
|
-
* resumeCampaign - Resume a Campaign
|
|
3164
|
-
*
|
|
3165
|
-
* @param {string} id Campaign ID
|
|
3166
|
-
*
|
|
3167
|
-
* @return {Campaign} Resumed Campaign
|
|
3168
|
-
*/
|
|
3169
|
-
async resumeCampaign(id: string) {
|
|
3170
|
-
const { campaign } = await this.patch<{ campaign: Campaign }>(this.baseURL + `/campaigns/${id}/resume`);
|
|
3209
|
+
this.validateServerSideAuth();
|
|
3210
|
+
const { campaign } = await this.patch<{ campaign: CampaignResponse }>(this.baseURL + `/campaigns/${id}/stop`);
|
|
3171
3211
|
return campaign;
|
|
3172
3212
|
}
|
|
3173
3213
|
|
|
3174
|
-
/**
|
|
3175
|
-
* testCampaign - Test a Campaign
|
|
3176
|
-
*
|
|
3177
|
-
* @param {string} id Campaign ID
|
|
3178
|
-
* @param {{users: string[]}} params Test params
|
|
3179
|
-
*
|
|
3180
|
-
* @return {TestCampaignResponse} Test campaign response
|
|
3181
|
-
*/
|
|
3182
|
-
async testCampaign(id: string, params: { users: string[] }) {
|
|
3183
|
-
const { users } = params;
|
|
3184
|
-
return await this.post<APIResponse & TestCampaignResponse>(this.baseURL + `/campaigns/${id}/test`, { users });
|
|
3185
|
-
}
|
|
3186
|
-
|
|
3187
3214
|
/**
|
|
3188
3215
|
* enrichURL - Get OpenGraph data of the given link
|
|
3189
3216
|
*
|
package/src/index.ts
CHANGED
|
@@ -11,4 +11,6 @@ export * from './signing';
|
|
|
11
11
|
export * from './token_manager';
|
|
12
12
|
export * from './insights';
|
|
13
13
|
export * from './types';
|
|
14
|
+
export * from './segment';
|
|
15
|
+
export * from './campaign';
|
|
14
16
|
export { isOwnUser, chatCodes, logChatPromiseExecution, formatMessage } from './utils';
|
package/src/segment.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { StreamChat } from './client';
|
|
2
|
+
import {
|
|
3
|
+
DefaultGenerics,
|
|
4
|
+
ExtendableGenerics,
|
|
5
|
+
QuerySegmentTargetsFilter,
|
|
6
|
+
SegmentData,
|
|
7
|
+
SegmentResponse,
|
|
8
|
+
SortParam,
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
type SegmentType = 'user' | 'channel';
|
|
12
|
+
|
|
13
|
+
type SegmentUpdatableFields = {
|
|
14
|
+
description?: string;
|
|
15
|
+
filter?: {};
|
|
16
|
+
name?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export class Segment<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> {
|
|
20
|
+
type: SegmentType;
|
|
21
|
+
id?: string | null;
|
|
22
|
+
client: StreamChat<StreamChatGenerics>;
|
|
23
|
+
data?: SegmentData | SegmentResponse;
|
|
24
|
+
|
|
25
|
+
constructor(client: StreamChat<StreamChatGenerics>, type: SegmentType, id: string | null, data?: SegmentData) {
|
|
26
|
+
this.client = client;
|
|
27
|
+
this.type = type;
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.data = data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async create() {
|
|
33
|
+
const body = {
|
|
34
|
+
id: this.id,
|
|
35
|
+
type: this.type,
|
|
36
|
+
name: this.data?.name,
|
|
37
|
+
filter: this.data?.filter,
|
|
38
|
+
description: this.data?.description,
|
|
39
|
+
all_users: this.data?.all_users,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return this.client.post<{ segment: SegmentResponse }>(this.client.baseURL + `/segments`, body);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
verifySegmentId() {
|
|
46
|
+
if (!this.id) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
'Segment id is missing. Either create the segment using segment.create() or set the id during instantiation - const segment = client.segment(id)',
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async get() {
|
|
54
|
+
this.verifySegmentId();
|
|
55
|
+
return this.client.getSegment(this.id as string);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async update(data: Partial<SegmentUpdatableFields>) {
|
|
59
|
+
this.verifySegmentId();
|
|
60
|
+
|
|
61
|
+
return this.client.updateSegment(this.id as string, data);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async addTargets(targets: string[]) {
|
|
65
|
+
this.verifySegmentId();
|
|
66
|
+
return this.client.addSegmentTargets(this.id as string, targets);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async removeTargets(targets: string[]) {
|
|
70
|
+
this.verifySegmentId();
|
|
71
|
+
return this.client.removeSegmentTargets(this.id as string, targets);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async delete() {
|
|
75
|
+
this.verifySegmentId();
|
|
76
|
+
return this.client.deleteSegment(this.id as string);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async targetExists(targetId: string) {
|
|
80
|
+
this.verifySegmentId();
|
|
81
|
+
return this.client.segmentTargetExists(this.id as string, targetId);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async queryTargets(filter: QuerySegmentTargetsFilter | null = {}, sort: SortParam[] | null | [] = [], options = {}) {
|
|
85
|
+
this.verifySegmentId();
|
|
86
|
+
|
|
87
|
+
return this.client.querySegmentTargets(this.id as string, filter, sort, options);
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/thread.ts
CHANGED
|
@@ -41,11 +41,13 @@ export class Thread<StreamChatGenerics extends ExtendableGenerics = DefaultGener
|
|
|
41
41
|
this.channel = t.channel;
|
|
42
42
|
this._channel = client.channel(t.channel.type, t.channel.id);
|
|
43
43
|
this._client = client;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (t.read) {
|
|
45
|
+
for (const r of t.read) {
|
|
46
|
+
this.read[r.user.id] = {
|
|
47
|
+
...r,
|
|
48
|
+
last_read: new Date(r.last_read),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -53,8 +55,17 @@ export class Thread<StreamChatGenerics extends ExtendableGenerics = DefaultGener
|
|
|
53
55
|
return this._client;
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
/**
|
|
59
|
+
* addReply - Adds or updates a latestReplies to the thread
|
|
60
|
+
*
|
|
61
|
+
* @param {MessageResponse<StreamChatGenerics>} message reply message to be added.
|
|
62
|
+
*/
|
|
56
63
|
addReply(message: MessageResponse<StreamChatGenerics>) {
|
|
57
|
-
|
|
64
|
+
if (message.parent_id !== this.message.id) {
|
|
65
|
+
throw new Error('Message does not belong to this thread');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.latestReplies = addToMessageList(this.latestReplies, formatMessage(message), true);
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
updateReply(message: MessageResponse<StreamChatGenerics>) {
|
|
@@ -77,6 +88,7 @@ export class Thread<StreamChatGenerics extends ExtendableGenerics = DefaultGener
|
|
|
77
88
|
|
|
78
89
|
if (message.parent_id && message.parent_id === this.message.id) {
|
|
79
90
|
this.updateReply(message);
|
|
91
|
+
return;
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
if (!message.parent_id && message.id === this.message.id) {
|
package/src/types.ts
CHANGED
|
@@ -673,6 +673,7 @@ export type OwnUserBase<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
673
673
|
total_unread_count: number;
|
|
674
674
|
unread_channels: number;
|
|
675
675
|
unread_count: number;
|
|
676
|
+
unread_threads: number;
|
|
676
677
|
invisible?: boolean;
|
|
677
678
|
roles?: string[];
|
|
678
679
|
};
|
|
@@ -2487,17 +2488,19 @@ export type DeleteUserOptions = {
|
|
|
2487
2488
|
export type SegmentType = 'channel' | 'user';
|
|
2488
2489
|
|
|
2489
2490
|
export type SegmentData = {
|
|
2491
|
+
all_users?: boolean;
|
|
2490
2492
|
description?: string;
|
|
2491
2493
|
filter?: {};
|
|
2494
|
+
name?: string;
|
|
2492
2495
|
};
|
|
2493
2496
|
|
|
2494
|
-
export type
|
|
2497
|
+
export type SegmentResponse = {
|
|
2495
2498
|
created_at: string;
|
|
2496
2499
|
deleted_at: string;
|
|
2497
2500
|
id: string;
|
|
2498
2501
|
locked: boolean;
|
|
2499
|
-
name: string;
|
|
2500
2502
|
size: number;
|
|
2503
|
+
task_id: string;
|
|
2501
2504
|
type: SegmentType;
|
|
2502
2505
|
updated_at: string;
|
|
2503
2506
|
} & SegmentData;
|
|
@@ -2506,6 +2509,12 @@ export type UpdateSegmentData = {
|
|
|
2506
2509
|
name: string;
|
|
2507
2510
|
} & SegmentData;
|
|
2508
2511
|
|
|
2512
|
+
export type SegmentTargetsResponse = {
|
|
2513
|
+
created_at: string;
|
|
2514
|
+
segment_id: string;
|
|
2515
|
+
target_id: string;
|
|
2516
|
+
};
|
|
2517
|
+
|
|
2509
2518
|
export type SortParam = {
|
|
2510
2519
|
field: string;
|
|
2511
2520
|
direction?: AscDesc;
|
|
@@ -2517,10 +2526,18 @@ export type Pager = {
|
|
|
2517
2526
|
prev?: string;
|
|
2518
2527
|
};
|
|
2519
2528
|
|
|
2520
|
-
export type QuerySegmentsOptions =
|
|
2521
|
-
sort?: SortParam[];
|
|
2522
|
-
} & Pager;
|
|
2529
|
+
export type QuerySegmentsOptions = Pager;
|
|
2523
2530
|
|
|
2531
|
+
export type QuerySegmentTargetsFilter = {
|
|
2532
|
+
target_id?: {
|
|
2533
|
+
$eq?: string;
|
|
2534
|
+
$gte?: string;
|
|
2535
|
+
$in?: string[];
|
|
2536
|
+
$lte?: string;
|
|
2537
|
+
};
|
|
2538
|
+
};
|
|
2539
|
+
export type QuerySegmentTargetsSort = {};
|
|
2540
|
+
export type QuerySegmentTargetsOptions = Pick<Pager, 'next' | 'limit'>;
|
|
2524
2541
|
export type CampaignSortField = {
|
|
2525
2542
|
field: string;
|
|
2526
2543
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -2534,6 +2551,8 @@ export type CampaignSort = {
|
|
|
2534
2551
|
|
|
2535
2552
|
export type CampaignQueryOptions = {
|
|
2536
2553
|
limit?: number;
|
|
2554
|
+
next?: string;
|
|
2555
|
+
prev?: string;
|
|
2537
2556
|
sort?: CampaignSort;
|
|
2538
2557
|
};
|
|
2539
2558
|
|
|
@@ -2543,43 +2562,43 @@ export type SegmentQueryOptions = CampaignQueryOptions;
|
|
|
2543
2562
|
export type CampaignFilters = {};
|
|
2544
2563
|
|
|
2545
2564
|
export type CampaignData = {
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2565
|
+
channel_template?: {
|
|
2566
|
+
type: string;
|
|
2567
|
+
custom?: {};
|
|
2568
|
+
id?: string;
|
|
2569
|
+
members?: string[];
|
|
2570
|
+
};
|
|
2571
|
+
create_channels?: boolean;
|
|
2572
|
+
deleted_at?: string;
|
|
2552
2573
|
description?: string;
|
|
2574
|
+
id?: string | null;
|
|
2575
|
+
message_template?: {
|
|
2576
|
+
text: string;
|
|
2577
|
+
attachments?: Attachment[];
|
|
2578
|
+
custom?: {};
|
|
2579
|
+
};
|
|
2580
|
+
name?: string;
|
|
2581
|
+
segment_ids?: string[];
|
|
2553
2582
|
sender_id?: string;
|
|
2583
|
+
skip_push?: boolean;
|
|
2584
|
+
skip_webhook?: boolean;
|
|
2585
|
+
user_ids?: string[];
|
|
2554
2586
|
};
|
|
2555
2587
|
|
|
2556
|
-
export type
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
failed_at?: string;
|
|
2563
|
-
resumed_at?: string;
|
|
2564
|
-
scheduled_at?: string;
|
|
2565
|
-
scheduled_for?: string;
|
|
2566
|
-
sent_messages?: number;
|
|
2567
|
-
stopped_at?: string;
|
|
2568
|
-
task_id?: string;
|
|
2588
|
+
export type CampaignStats = {
|
|
2589
|
+
progress?: number;
|
|
2590
|
+
stats_channels_created?: number;
|
|
2591
|
+
stats_completed_at?: string;
|
|
2592
|
+
stats_messages_sent?: number;
|
|
2593
|
+
stats_started_at?: string;
|
|
2569
2594
|
};
|
|
2570
|
-
|
|
2571
|
-
export type Campaign = {
|
|
2595
|
+
export type CampaignResponse = {
|
|
2572
2596
|
created_at: string;
|
|
2573
2597
|
id: string;
|
|
2598
|
+
stats: CampaignStats;
|
|
2574
2599
|
updated_at: string;
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
export type TestCampaignResponse = {
|
|
2579
|
-
status: CampaignStatusName;
|
|
2580
|
-
details?: string;
|
|
2581
|
-
results?: Record<string, string>;
|
|
2582
|
-
};
|
|
2600
|
+
scheduled_for?: string;
|
|
2601
|
+
} & CampaignData;
|
|
2583
2602
|
|
|
2584
2603
|
export type DeleteCampaignOptions = {};
|
|
2585
2604
|
|