mezon-js 2.7.78 → 2.7.79

Sign up to get free protection for your applications and to get access to all the features.
package/api.gen.ts CHANGED
@@ -24,6 +24,9 @@ export interface ClanUserListClanUser {
24
24
  user?: ApiUser;
25
25
  }
26
26
 
27
+ /** */
28
+
29
+
27
30
  /** Update fields in a given channel. */
28
31
  export interface MezonUpdateChannelDescBody {
29
32
  //
@@ -124,6 +127,12 @@ export interface MezonUpdateUserProfileByClanBody {
124
127
  nick_name?: string;
125
128
  }
126
129
 
130
+ /** */
131
+ export interface MezonUpdateWebhookByIdBody {
132
+ //
133
+ webhook_name?: string;
134
+ }
135
+
127
136
  /** A single user-role pair. */
128
137
  export interface RoleUserListRoleUser {
129
138
  //A URL for an avatar image.
@@ -1429,6 +1438,50 @@ export interface ApiVoiceChannelUserList {
1429
1438
  voice_channel_users?: Array<ApiVoiceChannelUser>;
1430
1439
  }
1431
1440
 
1441
+ /** */
1442
+ export interface ApiWebhook {
1443
+ //
1444
+ active?: number;
1445
+ //
1446
+ channel_id?: string;
1447
+ //
1448
+ create_time?: string;
1449
+ //
1450
+ creator_id?: string;
1451
+ //
1452
+ id?: string;
1453
+ //
1454
+ update_time?: string;
1455
+ //
1456
+ url?: string;
1457
+ //
1458
+ webhook_name?: string;
1459
+ }
1460
+
1461
+ /** */
1462
+ export interface ApiWebhookCreateRequest {
1463
+ //
1464
+ channel_id?: string;
1465
+ //
1466
+ webhook_name?: string;
1467
+ }
1468
+
1469
+ /** */
1470
+ export interface ApiWebhookGenerateResponse {
1471
+ //
1472
+ channel_id?: string;
1473
+ //
1474
+ hook_name?: string;
1475
+ //
1476
+ url?: string;
1477
+ }
1478
+
1479
+ /** */
1480
+ export interface ApiWebhookListResponse {
1481
+ //
1482
+ webhooks?: Array<ApiWebhook>;
1483
+ }
1484
+
1432
1485
  /** */
1433
1486
  export interface ApiWebhookResponse {
1434
1487
  //
@@ -5894,7 +5947,7 @@ export class MezonApi {
5894
5947
  /** */
5895
5948
  updateUserProfileByClan(bearerToken: string,
5896
5949
  clanId:string,
5897
- body:{},
5950
+ body:MezonUpdateUserProfileByClanBody,
5898
5951
  options: any = {}): Promise<any> {
5899
5952
 
5900
5953
  if (clanId === null || clanId === undefined) {
@@ -6077,6 +6130,156 @@ export class MezonApi {
6077
6130
  ]);
6078
6131
  }
6079
6132
 
6133
+ /** create webhook */
6134
+ generateWebhook(bearerToken: string,
6135
+ body:ApiWebhookCreateRequest,
6136
+ options: any = {}): Promise<any> {
6137
+
6138
+ if (body === null || body === undefined) {
6139
+ throw new Error("'body' is a required parameter but is null or undefined.");
6140
+ }
6141
+ const urlPath = "/v2/webhooks/generate";
6142
+ const queryParams = new Map<string, any>();
6143
+
6144
+ let bodyJson : string = "";
6145
+ bodyJson = JSON.stringify(body || {});
6146
+
6147
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
6148
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
6149
+ if (bearerToken) {
6150
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
6151
+ }
6152
+
6153
+ return Promise.race([
6154
+ fetch(fullUrl, fetchOptions).then((response) => {
6155
+ if (response.status == 204) {
6156
+ return response;
6157
+ } else if (response.status >= 200 && response.status < 300) {
6158
+ return response.json();
6159
+ } else {
6160
+ throw response;
6161
+ }
6162
+ }),
6163
+ new Promise((_, reject) =>
6164
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
6165
+ ),
6166
+ ]);
6167
+ }
6168
+
6169
+ /** update webhook name by id */
6170
+ updateWebhookById(bearerToken: string,
6171
+ id:string,
6172
+ body:MezonUpdateWebhookByIdBody,
6173
+ options: any = {}): Promise<any> {
6174
+
6175
+ if (id === null || id === undefined) {
6176
+ throw new Error("'id' is a required parameter but is null or undefined.");
6177
+ }
6178
+ if (body === null || body === undefined) {
6179
+ throw new Error("'body' is a required parameter but is null or undefined.");
6180
+ }
6181
+ const urlPath = "/v2/webhooks/update/{id}"
6182
+ .replace("{id}", encodeURIComponent(String(id)));
6183
+ const queryParams = new Map<string, any>();
6184
+
6185
+ let bodyJson : string = "";
6186
+ bodyJson = JSON.stringify(body || {});
6187
+
6188
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
6189
+ const fetchOptions = buildFetchOptions("PATCH", options, bodyJson);
6190
+ if (bearerToken) {
6191
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
6192
+ }
6193
+
6194
+ return Promise.race([
6195
+ fetch(fullUrl, fetchOptions).then((response) => {
6196
+ if (response.status == 204) {
6197
+ return response;
6198
+ } else if (response.status >= 200 && response.status < 300) {
6199
+ return response.json();
6200
+ } else {
6201
+ throw response;
6202
+ }
6203
+ }),
6204
+ new Promise((_, reject) =>
6205
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
6206
+ ),
6207
+ ]);
6208
+ }
6209
+
6210
+ /** list webhook belong to the channel */
6211
+ listWebhookByChannelId(bearerToken: string,
6212
+ channelId:string,
6213
+ options: any = {}): Promise<ApiWebhookListResponse> {
6214
+
6215
+ if (channelId === null || channelId === undefined) {
6216
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
6217
+ }
6218
+ const urlPath = "/v2/webhooks/{channelId}"
6219
+ .replace("{channelId}", encodeURIComponent(String(channelId)));
6220
+ const queryParams = new Map<string, any>();
6221
+
6222
+ let bodyJson : string = "";
6223
+
6224
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
6225
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
6226
+ if (bearerToken) {
6227
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
6228
+ }
6229
+
6230
+ return Promise.race([
6231
+ fetch(fullUrl, fetchOptions).then((response) => {
6232
+ if (response.status == 204) {
6233
+ return response;
6234
+ } else if (response.status >= 200 && response.status < 300) {
6235
+ return response.json();
6236
+ } else {
6237
+ throw response;
6238
+ }
6239
+ }),
6240
+ new Promise((_, reject) =>
6241
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
6242
+ ),
6243
+ ]);
6244
+ }
6245
+
6246
+ /** disabled webhook */
6247
+ deleteWebhookById(bearerToken: string,
6248
+ id:string,
6249
+ options: any = {}): Promise<any> {
6250
+
6251
+ if (id === null || id === undefined) {
6252
+ throw new Error("'id' is a required parameter but is null or undefined.");
6253
+ }
6254
+
6255
+ const urlPath = "/v2/webhooks/{id}"
6256
+ .replace("{id}", encodeURIComponent(String(id)));
6257
+ const queryParams = new Map<string, any>();
6258
+
6259
+ let bodyJson : string = "";
6260
+
6261
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
6262
+ const fetchOptions = buildFetchOptions("PATCH", options, bodyJson);
6263
+ if (bearerToken) {
6264
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
6265
+ }
6266
+
6267
+ return Promise.race([
6268
+ fetch(fullUrl, fetchOptions).then((response) => {
6269
+ if (response.status == 204) {
6270
+ return response;
6271
+ } else if (response.status >= 200 && response.status < 300) {
6272
+ return response.json();
6273
+ } else {
6274
+ throw response;
6275
+ }
6276
+ }),
6277
+ new Promise((_, reject) =>
6278
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
6279
+ ),
6280
+ ]);
6281
+ }
6282
+
6080
6283
  buildFullUrl(basePath: string, fragment: string, queryParams: Map<string, any>) {
6081
6284
  let fullPath = basePath + fragment + "?";
6082
6285
 
package/client.ts CHANGED
@@ -97,7 +97,11 @@ import {
97
97
  ApiClanEmojiList,
98
98
  ApiClanEmojiCreateRequest,
99
99
  ApiChannelVoiceList,
100
- MezonUpdateClanEmojiByIdBody
100
+ MezonUpdateClanEmojiByIdBody,
101
+ ApiWebhookCreateRequest,
102
+ ApiWebhookListResponse,
103
+ MezonUpdateWebhookByIdBody,
104
+ ApiWebhookGenerateResponse,
101
105
  } from "./api.gen";
102
106
 
103
107
  import { Session } from "./session";
@@ -2260,27 +2264,75 @@ async createClanEmoji(session: Session, request: ApiClanEmojiCreateRequest) {
2260
2264
  }
2261
2265
 
2262
2266
  //**update clan emoji by id */
2263
- async updateClanEmojiById(session :Session,id:string,request: MezonUpdateClanEmojiByIdBody) {
2267
+ async updateClanEmojiById(session: Session, id: string, request: MezonUpdateClanEmojiByIdBody) {
2264
2268
  if (this.autoRefreshSession && session.refresh_token &&
2265
2269
  session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
2266
2270
  await this.sessionRefresh(session);
2267
2271
  }
2268
2272
 
2269
- return this.apiClient.updateClanEmojiById(session.token,id,request).then((response: any) => {
2273
+ return this.apiClient.updateClanEmojiById(session.token, id, request).then((response: any) => {
2270
2274
  return response !== undefined;
2271
2275
  });
2272
2276
  }
2273
2277
 
2274
2278
  //**delete clan emoji by id */
2275
- async deleteByIdClanEmoji(session:Session,id:string) {
2279
+ async deleteByIdClanEmoji(session: Session, id: string) {
2276
2280
  if (this.autoRefreshSession && session.refresh_token &&
2277
2281
  session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
2278
2282
  await this.sessionRefresh(session);
2279
2283
  }
2280
2284
 
2281
- return this.apiClient.deleteByIdClanEmoji(session.token,id).then((response: any) => {
2285
+ return this.apiClient.deleteByIdClanEmoji(session.token, id).then((response: any) => {
2282
2286
  return response !== undefined;
2283
2287
  });
2284
2288
  }
2285
2289
 
2290
+ //**create webhook for chaneel */
2291
+ async generateWebhookLink(session: Session, request: ApiWebhookCreateRequest): Promise<ApiWebhookGenerateResponse> {
2292
+ if (this.autoRefreshSession && session.refresh_token &&
2293
+ session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
2294
+ await this.sessionRefresh(session);
2295
+ }
2296
+
2297
+ return this.apiClient.generateWebhook(session.token, request).then((response: any) => {
2298
+ return Promise.resolve(response);
2299
+ })
2300
+ }
2301
+
2302
+ //**list webhook belong to the channel */
2303
+ async listWebhookByChannelId(session: Session, channel_id: string): Promise<ApiWebhookListResponse> {
2304
+ if (this.autoRefreshSession && session.refresh_token &&
2305
+ session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
2306
+ await this.sessionRefresh(session);
2307
+ }
2308
+
2309
+ return this.apiClient.listWebhookByChannelId(session.token, channel_id).then((response: ApiWebhookListResponse) => {
2310
+ return Promise.resolve(response);
2311
+ })
2312
+ }
2313
+
2314
+ //**update webhook name by id */
2315
+ async updateWebhookById(session: Session, id: string, request: MezonUpdateWebhookByIdBody) {
2316
+ if (this.autoRefreshSession && session.refresh_token &&
2317
+ session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
2318
+ await this.sessionRefresh(session);
2319
+ }
2320
+
2321
+ return this.apiClient.updateWebhookById(session.token, id, request).then((response: any) => {
2322
+ return response !== undefined;
2323
+ })
2324
+ }
2325
+
2326
+ //**disabled webhook by id */
2327
+ async deleteWebhookById(session: Session, id: string) {
2328
+ if (this.autoRefreshSession && session.refresh_token &&
2329
+ session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
2330
+ await this.sessionRefresh(session);
2331
+ }
2332
+
2333
+ return this.apiClient.deleteWebhookById(session.token, id).then((response: any) => {
2334
+ return response !== undefined;
2335
+ })
2336
+ }
2337
+
2286
2338
  };
package/dist/api.gen.d.ts CHANGED
@@ -10,6 +10,7 @@ export interface ClanUserListClanUser {
10
10
  role_id?: string;
11
11
  user?: ApiUser;
12
12
  }
13
+ /** */
13
14
  /** Update fields in a given channel. */
14
15
  export interface MezonUpdateChannelDescBody {
15
16
  category_id?: string;
@@ -68,6 +69,10 @@ export interface MezonUpdateUserProfileByClanBody {
68
69
  avatar?: string;
69
70
  nick_name?: string;
70
71
  }
72
+ /** */
73
+ export interface MezonUpdateWebhookByIdBody {
74
+ webhook_name?: string;
75
+ }
71
76
  /** A single user-role pair. */
72
77
  export interface RoleUserListRoleUser {
73
78
  avatar_url?: string;
@@ -826,6 +831,32 @@ export interface ApiVoiceChannelUserList {
826
831
  voice_channel_users?: Array<ApiVoiceChannelUser>;
827
832
  }
828
833
  /** */
834
+ export interface ApiWebhook {
835
+ active?: number;
836
+ channel_id?: string;
837
+ create_time?: string;
838
+ creator_id?: string;
839
+ id?: string;
840
+ update_time?: string;
841
+ url?: string;
842
+ webhook_name?: string;
843
+ }
844
+ /** */
845
+ export interface ApiWebhookCreateRequest {
846
+ channel_id?: string;
847
+ webhook_name?: string;
848
+ }
849
+ /** */
850
+ export interface ApiWebhookGenerateResponse {
851
+ channel_id?: string;
852
+ hook_name?: string;
853
+ url?: string;
854
+ }
855
+ /** */
856
+ export interface ApiWebhookListResponse {
857
+ webhooks?: Array<ApiWebhook>;
858
+ }
859
+ /** */
829
860
  export interface ApiWebhookResponse {
830
861
  channel_id?: string;
831
862
  hook_name?: string;
@@ -1099,7 +1130,7 @@ export declare class MezonApi {
1099
1130
  /** Update channel private. */
1100
1131
  updateChannelPrivate(bearerToken: string, body: ApiChangeChannelPrivateRequest, options?: any): Promise<any>;
1101
1132
  /** */
1102
- updateUserProfileByClan(bearerToken: string, clanId: string, body: {}, options?: any): Promise<any>;
1133
+ updateUserProfileByClan(bearerToken: string, clanId: string, body: MezonUpdateUserProfileByClanBody, options?: any): Promise<any>;
1103
1134
  /** Upload attachment */
1104
1135
  uploadAttachmentFile(bearerToken: string, body: ApiUploadAttachmentRequest, options?: any): Promise<ApiUploadAttachment>;
1105
1136
  /** Fetch zero or more users by ID and/or username. */
@@ -1108,5 +1139,13 @@ export declare class MezonApi {
1108
1139
  updateUser(bearerToken: string, body: ApiUpdateUsersRequest, options?: any): Promise<any>;
1109
1140
  /** Create webhook */
1110
1141
  createWebhookLink(bearerToken: string, body: ApiCreateWebhookRequest, options?: any): Promise<ApiWebhookResponse>;
1142
+ /** create webhook */
1143
+ generateWebhook(bearerToken: string, body: ApiWebhookCreateRequest, options?: any): Promise<any>;
1144
+ /** update webhook name by id */
1145
+ updateWebhookById(bearerToken: string, id: string, body: MezonUpdateWebhookByIdBody, options?: any): Promise<any>;
1146
+ /** list webhook belong to the channel */
1147
+ listWebhookByChannelId(bearerToken: string, channelId: string, options?: any): Promise<ApiWebhookListResponse>;
1148
+ /** disabled webhook */
1149
+ deleteWebhookById(bearerToken: string, id: string, options?: any): Promise<any>;
1111
1150
  buildFullUrl(basePath: string, fragment: string, queryParams: Map<string, any>): string;
1112
1151
  }
package/dist/client.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ApiAccount, ApiAccountCustom, ApiAccountDevice, ApiAccountEmail, ApiAccountFacebook, ApiAccountFacebookInstantGame, ApiAccountGoogle, ApiAccountGameCenter, ApiAccountSteam, ApiChannelDescList, ApiChannelDescription, ApiCreateChannelDescRequest, ApiDeleteRoleRequest, ApiClanDescList, ApiCreateClanDescRequest, ApiClanDesc, ApiCategoryDesc, ApiCategoryDescList, ApiRoleList, ApiPermissionList, ApiRoleUserList, ApiRole, ApiCreateRoleRequest, ApiAddRoleChannelDescRequest, ApiCreateCategoryDescRequest, ApiUpdateCategoryDescRequest, ApiDeleteStorageObjectsRequest, ApiEvent, ApiReadStorageObjectsRequest, ApiStorageObjectAcks, ApiUpdateAccountRequest, ApiAccountApple, ApiLinkSteamRequest, ApiClanDescProfile, ApiClanProfile, ApiChannelUserList, ApiClanUserList, ApiLinkInviteUserRequest, ApiUpdateEventRequest, ApiLinkInviteUser, ApiInviteUserRes, ApiUploadAttachmentRequest, ApiUploadAttachment, ApiMessageReaction, ApiMessageMention, ApiMessageAttachment, ApiMessageRef, ApiChannelMessageHeader, ApiVoiceChannelUserList, ApiChannelAttachmentList, ApiCreateEventRequest, ApiEventManagement, ApiEventList, ApiDeleteEventRequest, ApiNotificationChannelCategoySettingsList, ApiNotificationSetting, ApiSetDefaultNotificationRequest, ApiNotificationUserChannel, ApiSetNotificationRequest, ApiNotifiReactMessage, ApiSetMuteNotificationRequest, ApiSearchMessageRequest, ApiSearchMessageResponse, ApiPinMessageRequest, ApiPinMessagesList, ApiCreateWebhookRequest, ApiWebhookResponse, ApiDeleteChannelDescRequest, ApiChangeChannelPrivateRequest, ApiClanEmojiList, ApiClanEmojiCreateRequest, ApiChannelVoiceList, MezonUpdateClanEmojiByIdBody } from "./api.gen";
16
+ import { ApiAccount, ApiAccountCustom, ApiAccountDevice, ApiAccountEmail, ApiAccountFacebook, ApiAccountFacebookInstantGame, ApiAccountGoogle, ApiAccountGameCenter, ApiAccountSteam, ApiChannelDescList, ApiChannelDescription, ApiCreateChannelDescRequest, ApiDeleteRoleRequest, ApiClanDescList, ApiCreateClanDescRequest, ApiClanDesc, ApiCategoryDesc, ApiCategoryDescList, ApiRoleList, ApiPermissionList, ApiRoleUserList, ApiRole, ApiCreateRoleRequest, ApiAddRoleChannelDescRequest, ApiCreateCategoryDescRequest, ApiUpdateCategoryDescRequest, ApiDeleteStorageObjectsRequest, ApiEvent, ApiReadStorageObjectsRequest, ApiStorageObjectAcks, ApiUpdateAccountRequest, ApiAccountApple, ApiLinkSteamRequest, ApiClanDescProfile, ApiClanProfile, ApiChannelUserList, ApiClanUserList, ApiLinkInviteUserRequest, ApiUpdateEventRequest, ApiLinkInviteUser, ApiInviteUserRes, ApiUploadAttachmentRequest, ApiUploadAttachment, ApiMessageReaction, ApiMessageMention, ApiMessageAttachment, ApiMessageRef, ApiChannelMessageHeader, ApiVoiceChannelUserList, ApiChannelAttachmentList, ApiCreateEventRequest, ApiEventManagement, ApiEventList, ApiDeleteEventRequest, ApiNotificationChannelCategoySettingsList, ApiNotificationSetting, ApiSetDefaultNotificationRequest, ApiNotificationUserChannel, ApiSetNotificationRequest, ApiNotifiReactMessage, ApiSetMuteNotificationRequest, ApiSearchMessageRequest, ApiSearchMessageResponse, ApiPinMessageRequest, ApiPinMessagesList, ApiCreateWebhookRequest, ApiWebhookResponse, ApiDeleteChannelDescRequest, ApiChangeChannelPrivateRequest, ApiClanEmojiList, ApiClanEmojiCreateRequest, ApiChannelVoiceList, MezonUpdateClanEmojiByIdBody, ApiWebhookCreateRequest, ApiWebhookListResponse, MezonUpdateWebhookByIdBody, ApiWebhookGenerateResponse } from "./api.gen";
17
17
  import { Session } from "./session";
18
18
  import { Socket } from "./socket";
19
19
  import { WebSocketAdapter } from "./web_socket_adapter";
@@ -584,4 +584,8 @@ export declare class Client {
584
584
  createClanEmoji(session: Session, request: ApiClanEmojiCreateRequest): Promise<boolean>;
585
585
  updateClanEmojiById(session: Session, id: string, request: MezonUpdateClanEmojiByIdBody): Promise<boolean>;
586
586
  deleteByIdClanEmoji(session: Session, id: string): Promise<boolean>;
587
+ generateWebhookLink(session: Session, request: ApiWebhookCreateRequest): Promise<ApiWebhookGenerateResponse>;
588
+ listWebhookByChannelId(session: Session, channel_id: string): Promise<ApiWebhookListResponse>;
589
+ updateWebhookById(session: Session, id: string, request: MezonUpdateWebhookByIdBody): Promise<boolean>;
590
+ deleteWebhookById(session: Session, id: string): Promise<boolean>;
587
591
  }
@@ -4249,6 +4249,123 @@ var MezonApi = class {
4249
4249
  )
4250
4250
  ]);
4251
4251
  }
4252
+ /** create webhook */
4253
+ generateWebhook(bearerToken, body, options = {}) {
4254
+ if (body === null || body === void 0) {
4255
+ throw new Error("'body' is a required parameter but is null or undefined.");
4256
+ }
4257
+ const urlPath = "/v2/webhooks/generate";
4258
+ const queryParams = /* @__PURE__ */ new Map();
4259
+ let bodyJson = "";
4260
+ bodyJson = JSON.stringify(body || {});
4261
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
4262
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
4263
+ if (bearerToken) {
4264
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
4265
+ }
4266
+ return Promise.race([
4267
+ fetch(fullUrl, fetchOptions).then((response) => {
4268
+ if (response.status == 204) {
4269
+ return response;
4270
+ } else if (response.status >= 200 && response.status < 300) {
4271
+ return response.json();
4272
+ } else {
4273
+ throw response;
4274
+ }
4275
+ }),
4276
+ new Promise(
4277
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
4278
+ )
4279
+ ]);
4280
+ }
4281
+ /** update webhook name by id */
4282
+ updateWebhookById(bearerToken, id, body, options = {}) {
4283
+ if (id === null || id === void 0) {
4284
+ throw new Error("'id' is a required parameter but is null or undefined.");
4285
+ }
4286
+ if (body === null || body === void 0) {
4287
+ throw new Error("'body' is a required parameter but is null or undefined.");
4288
+ }
4289
+ const urlPath = "/v2/webhooks/update/{id}".replace("{id}", encodeURIComponent(String(id)));
4290
+ const queryParams = /* @__PURE__ */ new Map();
4291
+ let bodyJson = "";
4292
+ bodyJson = JSON.stringify(body || {});
4293
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
4294
+ const fetchOptions = buildFetchOptions("PATCH", options, bodyJson);
4295
+ if (bearerToken) {
4296
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
4297
+ }
4298
+ return Promise.race([
4299
+ fetch(fullUrl, fetchOptions).then((response) => {
4300
+ if (response.status == 204) {
4301
+ return response;
4302
+ } else if (response.status >= 200 && response.status < 300) {
4303
+ return response.json();
4304
+ } else {
4305
+ throw response;
4306
+ }
4307
+ }),
4308
+ new Promise(
4309
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
4310
+ )
4311
+ ]);
4312
+ }
4313
+ /** list webhook belong to the channel */
4314
+ listWebhookByChannelId(bearerToken, channelId, options = {}) {
4315
+ if (channelId === null || channelId === void 0) {
4316
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
4317
+ }
4318
+ const urlPath = "/v2/webhooks/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
4319
+ const queryParams = /* @__PURE__ */ new Map();
4320
+ let bodyJson = "";
4321
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
4322
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
4323
+ if (bearerToken) {
4324
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
4325
+ }
4326
+ return Promise.race([
4327
+ fetch(fullUrl, fetchOptions).then((response) => {
4328
+ if (response.status == 204) {
4329
+ return response;
4330
+ } else if (response.status >= 200 && response.status < 300) {
4331
+ return response.json();
4332
+ } else {
4333
+ throw response;
4334
+ }
4335
+ }),
4336
+ new Promise(
4337
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
4338
+ )
4339
+ ]);
4340
+ }
4341
+ /** disabled webhook */
4342
+ deleteWebhookById(bearerToken, id, options = {}) {
4343
+ if (id === null || id === void 0) {
4344
+ throw new Error("'id' is a required parameter but is null or undefined.");
4345
+ }
4346
+ const urlPath = "/v2/webhooks/{id}".replace("{id}", encodeURIComponent(String(id)));
4347
+ const queryParams = /* @__PURE__ */ new Map();
4348
+ let bodyJson = "";
4349
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
4350
+ const fetchOptions = buildFetchOptions("PATCH", options, bodyJson);
4351
+ if (bearerToken) {
4352
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
4353
+ }
4354
+ return Promise.race([
4355
+ fetch(fullUrl, fetchOptions).then((response) => {
4356
+ if (response.status == 204) {
4357
+ return response;
4358
+ } else if (response.status >= 200 && response.status < 300) {
4359
+ return response.json();
4360
+ } else {
4361
+ throw response;
4362
+ }
4363
+ }),
4364
+ new Promise(
4365
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
4366
+ )
4367
+ ]);
4368
+ }
4252
4369
  buildFullUrl(basePath, fragment, queryParams) {
4253
4370
  let fullPath = basePath + fragment + "?";
4254
4371
  for (let [k, v] of queryParams) {
@@ -6504,4 +6621,48 @@ var Client = class {
6504
6621
  });
6505
6622
  });
6506
6623
  }
6624
+ //**create webhook for chaneel */
6625
+ generateWebhookLink(session, request) {
6626
+ return __async(this, null, function* () {
6627
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
6628
+ yield this.sessionRefresh(session);
6629
+ }
6630
+ return this.apiClient.generateWebhook(session.token, request).then((response) => {
6631
+ return Promise.resolve(response);
6632
+ });
6633
+ });
6634
+ }
6635
+ //**list webhook belong to the channel */
6636
+ listWebhookByChannelId(session, channel_id) {
6637
+ return __async(this, null, function* () {
6638
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
6639
+ yield this.sessionRefresh(session);
6640
+ }
6641
+ return this.apiClient.listWebhookByChannelId(session.token, channel_id).then((response) => {
6642
+ return Promise.resolve(response);
6643
+ });
6644
+ });
6645
+ }
6646
+ //**update webhook name by id */
6647
+ updateWebhookById(session, id, request) {
6648
+ return __async(this, null, function* () {
6649
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
6650
+ yield this.sessionRefresh(session);
6651
+ }
6652
+ return this.apiClient.updateWebhookById(session.token, id, request).then((response) => {
6653
+ return response !== void 0;
6654
+ });
6655
+ });
6656
+ }
6657
+ //**disabled webhook by id */
6658
+ deleteWebhookById(session, id) {
6659
+ return __async(this, null, function* () {
6660
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
6661
+ yield this.sessionRefresh(session);
6662
+ }
6663
+ return this.apiClient.deleteWebhookById(session.token, id).then((response) => {
6664
+ return response !== void 0;
6665
+ });
6666
+ });
6667
+ }
6507
6668
  };
@@ -4220,6 +4220,123 @@ var MezonApi = class {
4220
4220
  )
4221
4221
  ]);
4222
4222
  }
4223
+ /** create webhook */
4224
+ generateWebhook(bearerToken, body, options = {}) {
4225
+ if (body === null || body === void 0) {
4226
+ throw new Error("'body' is a required parameter but is null or undefined.");
4227
+ }
4228
+ const urlPath = "/v2/webhooks/generate";
4229
+ const queryParams = /* @__PURE__ */ new Map();
4230
+ let bodyJson = "";
4231
+ bodyJson = JSON.stringify(body || {});
4232
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
4233
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
4234
+ if (bearerToken) {
4235
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
4236
+ }
4237
+ return Promise.race([
4238
+ fetch(fullUrl, fetchOptions).then((response) => {
4239
+ if (response.status == 204) {
4240
+ return response;
4241
+ } else if (response.status >= 200 && response.status < 300) {
4242
+ return response.json();
4243
+ } else {
4244
+ throw response;
4245
+ }
4246
+ }),
4247
+ new Promise(
4248
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
4249
+ )
4250
+ ]);
4251
+ }
4252
+ /** update webhook name by id */
4253
+ updateWebhookById(bearerToken, id, body, options = {}) {
4254
+ if (id === null || id === void 0) {
4255
+ throw new Error("'id' is a required parameter but is null or undefined.");
4256
+ }
4257
+ if (body === null || body === void 0) {
4258
+ throw new Error("'body' is a required parameter but is null or undefined.");
4259
+ }
4260
+ const urlPath = "/v2/webhooks/update/{id}".replace("{id}", encodeURIComponent(String(id)));
4261
+ const queryParams = /* @__PURE__ */ new Map();
4262
+ let bodyJson = "";
4263
+ bodyJson = JSON.stringify(body || {});
4264
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
4265
+ const fetchOptions = buildFetchOptions("PATCH", options, bodyJson);
4266
+ if (bearerToken) {
4267
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
4268
+ }
4269
+ return Promise.race([
4270
+ fetch(fullUrl, fetchOptions).then((response) => {
4271
+ if (response.status == 204) {
4272
+ return response;
4273
+ } else if (response.status >= 200 && response.status < 300) {
4274
+ return response.json();
4275
+ } else {
4276
+ throw response;
4277
+ }
4278
+ }),
4279
+ new Promise(
4280
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
4281
+ )
4282
+ ]);
4283
+ }
4284
+ /** list webhook belong to the channel */
4285
+ listWebhookByChannelId(bearerToken, channelId, options = {}) {
4286
+ if (channelId === null || channelId === void 0) {
4287
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
4288
+ }
4289
+ const urlPath = "/v2/webhooks/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
4290
+ const queryParams = /* @__PURE__ */ new Map();
4291
+ let bodyJson = "";
4292
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
4293
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
4294
+ if (bearerToken) {
4295
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
4296
+ }
4297
+ return Promise.race([
4298
+ fetch(fullUrl, fetchOptions).then((response) => {
4299
+ if (response.status == 204) {
4300
+ return response;
4301
+ } else if (response.status >= 200 && response.status < 300) {
4302
+ return response.json();
4303
+ } else {
4304
+ throw response;
4305
+ }
4306
+ }),
4307
+ new Promise(
4308
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
4309
+ )
4310
+ ]);
4311
+ }
4312
+ /** disabled webhook */
4313
+ deleteWebhookById(bearerToken, id, options = {}) {
4314
+ if (id === null || id === void 0) {
4315
+ throw new Error("'id' is a required parameter but is null or undefined.");
4316
+ }
4317
+ const urlPath = "/v2/webhooks/{id}".replace("{id}", encodeURIComponent(String(id)));
4318
+ const queryParams = /* @__PURE__ */ new Map();
4319
+ let bodyJson = "";
4320
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
4321
+ const fetchOptions = buildFetchOptions("PATCH", options, bodyJson);
4322
+ if (bearerToken) {
4323
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
4324
+ }
4325
+ return Promise.race([
4326
+ fetch(fullUrl, fetchOptions).then((response) => {
4327
+ if (response.status == 204) {
4328
+ return response;
4329
+ } else if (response.status >= 200 && response.status < 300) {
4330
+ return response.json();
4331
+ } else {
4332
+ throw response;
4333
+ }
4334
+ }),
4335
+ new Promise(
4336
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
4337
+ )
4338
+ ]);
4339
+ }
4223
4340
  buildFullUrl(basePath, fragment, queryParams) {
4224
4341
  let fullPath = basePath + fragment + "?";
4225
4342
  for (let [k, v] of queryParams) {
@@ -6475,6 +6592,50 @@ var Client = class {
6475
6592
  });
6476
6593
  });
6477
6594
  }
6595
+ //**create webhook for chaneel */
6596
+ generateWebhookLink(session, request) {
6597
+ return __async(this, null, function* () {
6598
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
6599
+ yield this.sessionRefresh(session);
6600
+ }
6601
+ return this.apiClient.generateWebhook(session.token, request).then((response) => {
6602
+ return Promise.resolve(response);
6603
+ });
6604
+ });
6605
+ }
6606
+ //**list webhook belong to the channel */
6607
+ listWebhookByChannelId(session, channel_id) {
6608
+ return __async(this, null, function* () {
6609
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
6610
+ yield this.sessionRefresh(session);
6611
+ }
6612
+ return this.apiClient.listWebhookByChannelId(session.token, channel_id).then((response) => {
6613
+ return Promise.resolve(response);
6614
+ });
6615
+ });
6616
+ }
6617
+ //**update webhook name by id */
6618
+ updateWebhookById(session, id, request) {
6619
+ return __async(this, null, function* () {
6620
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
6621
+ yield this.sessionRefresh(session);
6622
+ }
6623
+ return this.apiClient.updateWebhookById(session.token, id, request).then((response) => {
6624
+ return response !== void 0;
6625
+ });
6626
+ });
6627
+ }
6628
+ //**disabled webhook by id */
6629
+ deleteWebhookById(session, id) {
6630
+ return __async(this, null, function* () {
6631
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
6632
+ yield this.sessionRefresh(session);
6633
+ }
6634
+ return this.apiClient.deleteWebhookById(session.token, id).then((response) => {
6635
+ return response !== void 0;
6636
+ });
6637
+ });
6638
+ }
6478
6639
  };
6479
6640
  export {
6480
6641
  ChannelStreamMode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mezon-js",
3
- "version": "2.7.78",
3
+ "version": "2.7.79",
4
4
  "scripts": {
5
5
  "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs"
6
6
  },