stream-chat 8.16.0 → 8.18.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.
- package/dist/browser.es.js +979 -474
- 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 +980 -473
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +979 -474
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +980 -473
- 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/channel.d.ts.map +1 -1
- package/dist/types/client.d.ts +45 -46
- 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/types.d.ts +43 -14
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +3 -7
- package/src/campaign.ts +97 -0
- package/src/channel.ts +14 -2
- package/src/client.ts +116 -88
- package/src/index.ts +2 -0
- package/src/segment.ts +89 -0
- package/src/types.ts +44 -14
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,14 +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
|
-
|
|
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,
|
|
3049
3105
|
});
|
|
3050
3106
|
}
|
|
3051
3107
|
|
|
@@ -3057,7 +3113,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3057
3113
|
* @return {Promise<APIResponse>} The Server Response
|
|
3058
3114
|
*/
|
|
3059
3115
|
async deleteSegment(id: string) {
|
|
3060
|
-
|
|
3116
|
+
this.validateServerSideAuth();
|
|
3117
|
+
return this.delete<APIResponse>(this.baseURL + `/segments/${id}`);
|
|
3061
3118
|
}
|
|
3062
3119
|
|
|
3063
3120
|
/**
|
|
@@ -3069,7 +3126,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3069
3126
|
* @return {Promise<APIResponse>} The Server Response
|
|
3070
3127
|
*/
|
|
3071
3128
|
async segmentTargetExists(segmentId: string, targetId: string) {
|
|
3072
|
-
|
|
3129
|
+
this.validateServerSideAuth();
|
|
3130
|
+
return this.get<APIResponse>(this.baseURL + `/segments/${segmentId}/target/${targetId}`);
|
|
3073
3131
|
}
|
|
3074
3132
|
|
|
3075
3133
|
/**
|
|
@@ -3080,27 +3138,38 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3080
3138
|
* @return {Campaign} The Created Campaign
|
|
3081
3139
|
*/
|
|
3082
3140
|
async createCampaign(params: CampaignData) {
|
|
3083
|
-
|
|
3084
|
-
return campaign;
|
|
3141
|
+
this.validateServerSideAuth();
|
|
3142
|
+
return this.post<{ campaign: CampaignResponse } & APIResponse>(this.baseURL + `/campaigns`, { ...params });
|
|
3143
|
+
}
|
|
3144
|
+
|
|
3145
|
+
async getCampaign(id: string) {
|
|
3146
|
+
this.validateServerSideAuth();
|
|
3147
|
+
return this.get<{ campaign: CampaignResponse } & APIResponse>(this.baseURL + `/campaigns/${id}`);
|
|
3085
3148
|
}
|
|
3086
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
|
+
}
|
|
3087
3156
|
/**
|
|
3088
3157
|
* queryCampaigns - Query Campaigns
|
|
3089
3158
|
*
|
|
3090
3159
|
*
|
|
3091
3160
|
* @return {Campaign[]} Campaigns
|
|
3092
3161
|
*/
|
|
3093
|
-
async queryCampaigns(
|
|
3094
|
-
|
|
3095
|
-
|
|
3162
|
+
async queryCampaigns(filter: CampaignFilters, sort?: CampaignSort, options?: CampaignQueryOptions) {
|
|
3163
|
+
this.validateServerSideAuth();
|
|
3164
|
+
return await this.post<{
|
|
3165
|
+
campaigns: CampaignResponse[];
|
|
3096
3166
|
segments: Record<string, Segment>;
|
|
3097
3167
|
channels?: Record<string, ChannelResponse<StreamChatGenerics>>;
|
|
3098
3168
|
users?: Record<string, UserResponse<StreamChatGenerics>>;
|
|
3099
|
-
}>(this.baseURL + `/campaigns`, {
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
},
|
|
3169
|
+
}>(this.baseURL + `/campaigns/query`, {
|
|
3170
|
+
filter,
|
|
3171
|
+
sort,
|
|
3172
|
+
...(options || {}),
|
|
3104
3173
|
});
|
|
3105
3174
|
}
|
|
3106
3175
|
|
|
@@ -3113,10 +3182,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3113
3182
|
* @return {Campaign} Updated Campaign
|
|
3114
3183
|
*/
|
|
3115
3184
|
async updateCampaign(id: string, params: Partial<CampaignData>) {
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
});
|
|
3119
|
-
return campaign;
|
|
3185
|
+
this.validateServerSideAuth();
|
|
3186
|
+
return this.put<{ campaign: CampaignResponse }>(this.baseURL + `/campaigns/${id}`, params);
|
|
3120
3187
|
}
|
|
3121
3188
|
|
|
3122
3189
|
/**
|
|
@@ -3126,24 +3193,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3126
3193
|
*
|
|
3127
3194
|
* @return {Promise<APIResponse>} The Server Response
|
|
3128
3195
|
*/
|
|
3129
|
-
async deleteCampaign(id: string
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
/**
|
|
3134
|
-
* scheduleCampaign - Schedule a Campaign
|
|
3135
|
-
*
|
|
3136
|
-
* @param {string} id Campaign ID
|
|
3137
|
-
* @param {{scheduledFor: number}} params Schedule params
|
|
3138
|
-
*
|
|
3139
|
-
* @return {Campaign} Scheduled Campaign
|
|
3140
|
-
*/
|
|
3141
|
-
async scheduleCampaign(id: string, params: { scheduledFor: number }) {
|
|
3142
|
-
const { scheduledFor } = params;
|
|
3143
|
-
const { campaign } = await this.patch<{ campaign: Campaign }>(this.baseURL + `/campaigns/${id}/schedule`, {
|
|
3144
|
-
scheduled_for: scheduledFor,
|
|
3145
|
-
});
|
|
3146
|
-
return campaign;
|
|
3196
|
+
async deleteCampaign(id: string) {
|
|
3197
|
+
this.validateServerSideAuth();
|
|
3198
|
+
return this.delete<APIResponse>(this.baseURL + `/campaigns/${id}`);
|
|
3147
3199
|
}
|
|
3148
3200
|
|
|
3149
3201
|
/**
|
|
@@ -3154,35 +3206,11 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3154
3206
|
* @return {Campaign} Stopped Campaign
|
|
3155
3207
|
*/
|
|
3156
3208
|
async stopCampaign(id: string) {
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
}
|
|
3160
|
-
|
|
3161
|
-
/**
|
|
3162
|
-
* resumeCampaign - Resume a Campaign
|
|
3163
|
-
*
|
|
3164
|
-
* @param {string} id Campaign ID
|
|
3165
|
-
*
|
|
3166
|
-
* @return {Campaign} Resumed Campaign
|
|
3167
|
-
*/
|
|
3168
|
-
async resumeCampaign(id: string) {
|
|
3169
|
-
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`);
|
|
3170
3211
|
return campaign;
|
|
3171
3212
|
}
|
|
3172
3213
|
|
|
3173
|
-
/**
|
|
3174
|
-
* testCampaign - Test a Campaign
|
|
3175
|
-
*
|
|
3176
|
-
* @param {string} id Campaign ID
|
|
3177
|
-
* @param {{users: string[]}} params Test params
|
|
3178
|
-
*
|
|
3179
|
-
* @return {TestCampaignResponse} Test campaign response
|
|
3180
|
-
*/
|
|
3181
|
-
async testCampaign(id: string, params: { users: string[] }) {
|
|
3182
|
-
const { users } = params;
|
|
3183
|
-
return await this.post<APIResponse & TestCampaignResponse>(this.baseURL + `/campaigns/${id}/test`, { users });
|
|
3184
|
-
}
|
|
3185
|
-
|
|
3186
3214
|
/**
|
|
3187
3215
|
* enrichURL - Get OpenGraph data of the given link
|
|
3188
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/types.ts
CHANGED
|
@@ -1507,6 +1507,7 @@ export type UserFilters<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
1507
1507
|
| RequireOnlyOne<{
|
|
1508
1508
|
$contains?: PrimitiveFilter<string>;
|
|
1509
1509
|
$eq?: PrimitiveFilter<UserResponse<StreamChatGenerics>['teams']>;
|
|
1510
|
+
$in?: PrimitiveFilter<UserResponse<StreamChatGenerics>['teams']>;
|
|
1510
1511
|
}>
|
|
1511
1512
|
| PrimitiveFilter<UserResponse<StreamChatGenerics>['teams']>;
|
|
1512
1513
|
username?:
|
|
@@ -2486,17 +2487,19 @@ export type DeleteUserOptions = {
|
|
|
2486
2487
|
export type SegmentType = 'channel' | 'user';
|
|
2487
2488
|
|
|
2488
2489
|
export type SegmentData = {
|
|
2489
|
-
|
|
2490
|
-
|
|
2490
|
+
all_users?: boolean;
|
|
2491
|
+
description?: string;
|
|
2492
|
+
filter?: {};
|
|
2493
|
+
name?: string;
|
|
2491
2494
|
};
|
|
2492
2495
|
|
|
2493
|
-
export type
|
|
2496
|
+
export type SegmentResponse = {
|
|
2494
2497
|
created_at: string;
|
|
2495
2498
|
deleted_at: string;
|
|
2496
2499
|
id: string;
|
|
2497
2500
|
locked: boolean;
|
|
2498
|
-
name: string;
|
|
2499
2501
|
size: number;
|
|
2502
|
+
task_id: string;
|
|
2500
2503
|
type: SegmentType;
|
|
2501
2504
|
updated_at: string;
|
|
2502
2505
|
} & SegmentData;
|
|
@@ -2505,6 +2508,12 @@ export type UpdateSegmentData = {
|
|
|
2505
2508
|
name: string;
|
|
2506
2509
|
} & SegmentData;
|
|
2507
2510
|
|
|
2511
|
+
export type SegmentTargetsResponse = {
|
|
2512
|
+
created_at: string;
|
|
2513
|
+
segment_id: string;
|
|
2514
|
+
target_id: string;
|
|
2515
|
+
};
|
|
2516
|
+
|
|
2508
2517
|
export type SortParam = {
|
|
2509
2518
|
field: string;
|
|
2510
2519
|
direction?: AscDesc;
|
|
@@ -2516,10 +2525,18 @@ export type Pager = {
|
|
|
2516
2525
|
prev?: string;
|
|
2517
2526
|
};
|
|
2518
2527
|
|
|
2519
|
-
export type QuerySegmentsOptions =
|
|
2520
|
-
sort?: SortParam[];
|
|
2521
|
-
} & Pager;
|
|
2528
|
+
export type QuerySegmentsOptions = Pager;
|
|
2522
2529
|
|
|
2530
|
+
export type QuerySegmentTargetsFilter = {
|
|
2531
|
+
target_id?: {
|
|
2532
|
+
$eq?: string;
|
|
2533
|
+
$gte?: string;
|
|
2534
|
+
$in?: string[];
|
|
2535
|
+
$lte?: string;
|
|
2536
|
+
};
|
|
2537
|
+
};
|
|
2538
|
+
export type QuerySegmentTargetsSort = {};
|
|
2539
|
+
export type QuerySegmentTargetsOptions = Pick<Pager, 'next' | 'limit'>;
|
|
2523
2540
|
export type CampaignSortField = {
|
|
2524
2541
|
field: string;
|
|
2525
2542
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -2533,6 +2550,8 @@ export type CampaignSort = {
|
|
|
2533
2550
|
|
|
2534
2551
|
export type CampaignQueryOptions = {
|
|
2535
2552
|
limit?: number;
|
|
2553
|
+
next?: string;
|
|
2554
|
+
prev?: string;
|
|
2536
2555
|
sort?: CampaignSort;
|
|
2537
2556
|
};
|
|
2538
2557
|
|
|
@@ -2542,14 +2561,25 @@ export type SegmentQueryOptions = CampaignQueryOptions;
|
|
|
2542
2561
|
export type CampaignFilters = {};
|
|
2543
2562
|
|
|
2544
2563
|
export type CampaignData = {
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2564
|
+
channel_template?: {
|
|
2565
|
+
type: string;
|
|
2566
|
+
custom?: {};
|
|
2567
|
+
id?: string;
|
|
2568
|
+
members?: string[];
|
|
2569
|
+
};
|
|
2570
|
+
create_channels?: boolean;
|
|
2571
|
+
deleted_at?: string;
|
|
2551
2572
|
description?: string;
|
|
2573
|
+
id?: string | null;
|
|
2574
|
+
message_template?: {
|
|
2575
|
+
text: string;
|
|
2576
|
+
attachments?: Attachment[];
|
|
2577
|
+
custom?: {};
|
|
2578
|
+
};
|
|
2579
|
+
name?: string;
|
|
2580
|
+
segment_ids?: string[];
|
|
2552
2581
|
sender_id?: string;
|
|
2582
|
+
user_ids?: string[];
|
|
2553
2583
|
};
|
|
2554
2584
|
|
|
2555
2585
|
export type CampaignStatusName = 'draft' | 'stopped' | 'scheduled' | 'completed' | 'failed' | 'in_progress';
|
|
@@ -2567,7 +2597,7 @@ export type CampaignStatus = {
|
|
|
2567
2597
|
task_id?: string;
|
|
2568
2598
|
};
|
|
2569
2599
|
|
|
2570
|
-
export type
|
|
2600
|
+
export type CampaignResponse = {
|
|
2571
2601
|
created_at: string;
|
|
2572
2602
|
id: string;
|
|
2573
2603
|
updated_at: string;
|