mezon-js 2.7.7 → 2.7.9

Sign up to get free protection for your applications and to get access to all the features.
package/api.gen.ts CHANGED
@@ -172,6 +172,28 @@ export interface ApiCategoryDescList {
172
172
  categorydesc?: Array<ApiCategoryDesc>;
173
173
  }
174
174
 
175
+ /** */
176
+ export interface ApiChannelAttachment {
177
+ //
178
+ filename?: string;
179
+ //
180
+ filesize?: string;
181
+ //
182
+ filetype?: string;
183
+ //
184
+ id?: string;
185
+ //
186
+ uploader?: string;
187
+ //
188
+ url?: string;
189
+ }
190
+
191
+ /** */
192
+ export interface ApiChannelAttachmentList {
193
+ //
194
+ attachments?: Array<ApiChannelAttachment>;
195
+ }
196
+
175
197
  /** A list of channel description, usually a result of a list operation. */
176
198
  export interface ApiChannelDescList {
177
199
  //Cacheable cursor to list newer channel description. Durable and designed to be stored, unlike next/prev cursors.
@@ -2222,161 +2244,6 @@ export class MezonApi {
2222
2244
  ]);
2223
2245
  }
2224
2246
 
2225
- /** List user channels */
2226
- listChannelDescs(bearerToken: string,
2227
- limit?:number,
2228
- state?:number,
2229
- cursor?:string,
2230
- clanId?:string,
2231
- channelType?:number,
2232
- options: any = {}): Promise<ApiChannelDescList> {
2233
-
2234
- const urlPath = "/v2/channeldesc";
2235
- const queryParams = new Map<string, any>();
2236
- queryParams.set("limit", limit);
2237
- queryParams.set("state", state);
2238
- queryParams.set("cursor", cursor);
2239
- queryParams.set("clan_id", clanId);
2240
- queryParams.set("channel_type", channelType);
2241
-
2242
- let bodyJson : string = "";
2243
-
2244
- const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2245
- const fetchOptions = buildFetchOptions("GET", options, bodyJson);
2246
- if (bearerToken) {
2247
- fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2248
- }
2249
-
2250
- return Promise.race([
2251
- fetch(fullUrl, fetchOptions).then((response) => {
2252
- if (response.status == 204) {
2253
- return response;
2254
- } else if (response.status >= 200 && response.status < 300) {
2255
- return response.json();
2256
- } else {
2257
- throw response;
2258
- }
2259
- }),
2260
- new Promise((_, reject) =>
2261
- setTimeout(reject, this.timeoutMs, "Request timed out.")
2262
- ),
2263
- ]);
2264
- }
2265
-
2266
- /** Create a new channel with the current user as the owner. */
2267
- createChannelDesc(bearerToken: string,
2268
- body:ApiCreateChannelDescRequest,
2269
- options: any = {}): Promise<ApiChannelDescription> {
2270
-
2271
- if (body === null || body === undefined) {
2272
- throw new Error("'body' is a required parameter but is null or undefined.");
2273
- }
2274
- const urlPath = "/v2/channeldesc";
2275
- const queryParams = new Map<string, any>();
2276
-
2277
- let bodyJson : string = "";
2278
- bodyJson = JSON.stringify(body || {});
2279
-
2280
- const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2281
- const fetchOptions = buildFetchOptions("POST", options, bodyJson);
2282
- if (bearerToken) {
2283
- fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2284
- }
2285
-
2286
- return Promise.race([
2287
- fetch(fullUrl, fetchOptions).then((response) => {
2288
- if (response.status == 204) {
2289
- return response;
2290
- } else if (response.status >= 200 && response.status < 300) {
2291
- return response.json();
2292
- } else {
2293
- throw response;
2294
- }
2295
- }),
2296
- new Promise((_, reject) =>
2297
- setTimeout(reject, this.timeoutMs, "Request timed out.")
2298
- ),
2299
- ]);
2300
- }
2301
-
2302
-
2303
- /** Delete a channel by ID. */
2304
- deleteChannelDesc(bearerToken: string,
2305
- channelId:string,
2306
- options: any = {}): Promise<any> {
2307
-
2308
- if (channelId === null || channelId === undefined) {
2309
- throw new Error("'channelId' is a required parameter but is null or undefined.");
2310
- }
2311
- const urlPath = "/v2/channeldesc/{channelId}"
2312
- .replace("{channelId}", encodeURIComponent(String(channelId)));
2313
- const queryParams = new Map<string, any>();
2314
-
2315
- let bodyJson : string = "";
2316
-
2317
- const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2318
- const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
2319
- if (bearerToken) {
2320
- fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2321
- }
2322
-
2323
- return Promise.race([
2324
- fetch(fullUrl, fetchOptions).then((response) => {
2325
- if (response.status == 204) {
2326
- return response;
2327
- } else if (response.status >= 200 && response.status < 300) {
2328
- return response.json();
2329
- } else {
2330
- throw response;
2331
- }
2332
- }),
2333
- new Promise((_, reject) =>
2334
- setTimeout(reject, this.timeoutMs, "Request timed out.")
2335
- ),
2336
- ]);
2337
- }
2338
-
2339
- /** Update fields in a given channel. */
2340
- updateChannelDesc(bearerToken: string,
2341
- channelId:string,
2342
- body:{},
2343
- options: any = {}): Promise<any> {
2344
-
2345
- if (channelId === null || channelId === undefined) {
2346
- throw new Error("'channelId' is a required parameter but is null or undefined.");
2347
- }
2348
- if (body === null || body === undefined) {
2349
- throw new Error("'body' is a required parameter but is null or undefined.");
2350
- }
2351
- const urlPath = "/v2/channeldesc/{channelId}"
2352
- .replace("{channelId}", encodeURIComponent(String(channelId)));
2353
- const queryParams = new Map<string, any>();
2354
-
2355
- let bodyJson : string = "";
2356
- bodyJson = JSON.stringify(body || {});
2357
-
2358
- const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2359
- const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
2360
- if (bearerToken) {
2361
- fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2362
- }
2363
-
2364
- return Promise.race([
2365
- fetch(fullUrl, fetchOptions).then((response) => {
2366
- if (response.status == 204) {
2367
- return response;
2368
- } else if (response.status >= 200 && response.status < 300) {
2369
- return response.json();
2370
- } else {
2371
- throw response;
2372
- }
2373
- }),
2374
- new Promise((_, reject) =>
2375
- setTimeout(reject, this.timeoutMs, "Request timed out.")
2376
- ),
2377
- ]);
2378
- }
2379
-
2380
2247
  /** Add users to a channel. */
2381
2248
  addChannelUsers(bearerToken: string,
2382
2249
  channelId:string,
@@ -2386,7 +2253,7 @@ export class MezonApi {
2386
2253
  if (channelId === null || channelId === undefined) {
2387
2254
  throw new Error("'channelId' is a required parameter but is null or undefined.");
2388
2255
  }
2389
- const urlPath = "/v2/channeldesc/{channelId}/add"
2256
+ const urlPath = "/v2/channel/{channelId}/add"
2390
2257
  .replace("{channelId}", encodeURIComponent(String(channelId)));
2391
2258
  const queryParams = new Map<string, any>();
2392
2259
  queryParams.set("user_ids", userIds);
@@ -2415,6 +2282,52 @@ export class MezonApi {
2415
2282
  ]);
2416
2283
  }
2417
2284
 
2285
+ /** List all attachment that are part of a channel. */
2286
+ listChannelAttachment(bearerToken: string,
2287
+ channelId:string,
2288
+ clanId?:string,
2289
+ fileType?:string,
2290
+ limit?:number,
2291
+ state?:number,
2292
+ cursor?:string,
2293
+ options: any = {}): Promise<ApiChannelAttachmentList> {
2294
+
2295
+ if (channelId === null || channelId === undefined) {
2296
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
2297
+ }
2298
+ const urlPath = "/v2/channel/{channelId}/attachment"
2299
+ .replace("{channelId}", encodeURIComponent(String(channelId)));
2300
+ const queryParams = new Map<string, any>();
2301
+ queryParams.set("clan_id", clanId);
2302
+ queryParams.set("file_type", fileType);
2303
+ queryParams.set("limit", limit);
2304
+ queryParams.set("state", state);
2305
+ queryParams.set("cursor", cursor);
2306
+
2307
+ let bodyJson : string = "";
2308
+
2309
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2310
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
2311
+ if (bearerToken) {
2312
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2313
+ }
2314
+
2315
+ return Promise.race([
2316
+ fetch(fullUrl, fetchOptions).then((response) => {
2317
+ if (response.status == 204) {
2318
+ return response;
2319
+ } else if (response.status >= 200 && response.status < 300) {
2320
+ return response.json();
2321
+ } else {
2322
+ throw response;
2323
+ }
2324
+ }),
2325
+ new Promise((_, reject) =>
2326
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
2327
+ ),
2328
+ ]);
2329
+ }
2330
+
2418
2331
  /** Leave a channel the user is a member of. */
2419
2332
  leaveChannel(bearerToken: string,
2420
2333
  channelId:string,
@@ -2423,7 +2336,7 @@ export class MezonApi {
2423
2336
  if (channelId === null || channelId === undefined) {
2424
2337
  throw new Error("'channelId' is a required parameter but is null or undefined.");
2425
2338
  }
2426
- const urlPath = "/v2/channeldesc/{channelId}/leave"
2339
+ const urlPath = "/v2/channel/{channelId}/leave"
2427
2340
  .replace("{channelId}", encodeURIComponent(String(channelId)));
2428
2341
  const queryParams = new Map<string, any>();
2429
2342
 
@@ -2460,7 +2373,7 @@ export class MezonApi {
2460
2373
  if (channelId === null || channelId === undefined) {
2461
2374
  throw new Error("'channelId' is a required parameter but is null or undefined.");
2462
2375
  }
2463
- const urlPath = "/v2/channeldesc/{channelId}/remove"
2376
+ const urlPath = "/v2/channel/{channelId}/remove"
2464
2377
  .replace("{channelId}", encodeURIComponent(String(channelId)));
2465
2378
  const queryParams = new Map<string, any>();
2466
2379
  queryParams.set("user_ids", userIds);
@@ -2502,7 +2415,7 @@ export class MezonApi {
2502
2415
  if (channelId === null || channelId === undefined) {
2503
2416
  throw new Error("'channelId' is a required parameter but is null or undefined.");
2504
2417
  }
2505
- const urlPath = "/v2/channeldesc/{channelId}/user"
2418
+ const urlPath = "/v2/channel/{channelId}/user"
2506
2419
  .replace("{channelId}", encodeURIComponent(String(channelId)));
2507
2420
  const queryParams = new Map<string, any>();
2508
2421
  queryParams.set("clan_id", clanId);
@@ -2535,6 +2448,161 @@ export class MezonApi {
2535
2448
  ]);
2536
2449
  }
2537
2450
 
2451
+ /** List user channels */
2452
+ listChannelDescs(bearerToken: string,
2453
+ limit?:number,
2454
+ state?:number,
2455
+ cursor?:string,
2456
+ clanId?:string,
2457
+ channelType?:number,
2458
+ options: any = {}): Promise<ApiChannelDescList> {
2459
+
2460
+ const urlPath = "/v2/channeldesc";
2461
+ const queryParams = new Map<string, any>();
2462
+ queryParams.set("limit", limit);
2463
+ queryParams.set("state", state);
2464
+ queryParams.set("cursor", cursor);
2465
+ queryParams.set("clan_id", clanId);
2466
+ queryParams.set("channel_type", channelType);
2467
+
2468
+ let bodyJson : string = "";
2469
+
2470
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2471
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
2472
+ if (bearerToken) {
2473
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2474
+ }
2475
+
2476
+ return Promise.race([
2477
+ fetch(fullUrl, fetchOptions).then((response) => {
2478
+ if (response.status == 204) {
2479
+ return response;
2480
+ } else if (response.status >= 200 && response.status < 300) {
2481
+ return response.json();
2482
+ } else {
2483
+ throw response;
2484
+ }
2485
+ }),
2486
+ new Promise((_, reject) =>
2487
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
2488
+ ),
2489
+ ]);
2490
+ }
2491
+
2492
+ /** Create a new channel with the current user as the owner. */
2493
+ createChannelDesc(bearerToken: string,
2494
+ body:ApiCreateChannelDescRequest,
2495
+ options: any = {}): Promise<ApiChannelDescription> {
2496
+
2497
+ if (body === null || body === undefined) {
2498
+ throw new Error("'body' is a required parameter but is null or undefined.");
2499
+ }
2500
+ const urlPath = "/v2/channeldesc";
2501
+ const queryParams = new Map<string, any>();
2502
+
2503
+ let bodyJson : string = "";
2504
+ bodyJson = JSON.stringify(body || {});
2505
+
2506
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2507
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
2508
+ if (bearerToken) {
2509
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2510
+ }
2511
+
2512
+ return Promise.race([
2513
+ fetch(fullUrl, fetchOptions).then((response) => {
2514
+ if (response.status == 204) {
2515
+ return response;
2516
+ } else if (response.status >= 200 && response.status < 300) {
2517
+ return response.json();
2518
+ } else {
2519
+ throw response;
2520
+ }
2521
+ }),
2522
+ new Promise((_, reject) =>
2523
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
2524
+ ),
2525
+ ]);
2526
+ }
2527
+
2528
+
2529
+ /** Delete a channel by ID. */
2530
+ deleteChannelDesc(bearerToken: string,
2531
+ channelId:string,
2532
+ options: any = {}): Promise<any> {
2533
+
2534
+ if (channelId === null || channelId === undefined) {
2535
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
2536
+ }
2537
+ const urlPath = "/v2/channeldesc/{channelId}"
2538
+ .replace("{channelId}", encodeURIComponent(String(channelId)));
2539
+ const queryParams = new Map<string, any>();
2540
+
2541
+ let bodyJson : string = "";
2542
+
2543
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2544
+ const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
2545
+ if (bearerToken) {
2546
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2547
+ }
2548
+
2549
+ return Promise.race([
2550
+ fetch(fullUrl, fetchOptions).then((response) => {
2551
+ if (response.status == 204) {
2552
+ return response;
2553
+ } else if (response.status >= 200 && response.status < 300) {
2554
+ return response.json();
2555
+ } else {
2556
+ throw response;
2557
+ }
2558
+ }),
2559
+ new Promise((_, reject) =>
2560
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
2561
+ ),
2562
+ ]);
2563
+ }
2564
+
2565
+ /** Update fields in a given channel. */
2566
+ updateChannelDesc(bearerToken: string,
2567
+ channelId:string,
2568
+ body:{},
2569
+ options: any = {}): Promise<any> {
2570
+
2571
+ if (channelId === null || channelId === undefined) {
2572
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
2573
+ }
2574
+ if (body === null || body === undefined) {
2575
+ throw new Error("'body' is a required parameter but is null or undefined.");
2576
+ }
2577
+ const urlPath = "/v2/channeldesc/{channelId}"
2578
+ .replace("{channelId}", encodeURIComponent(String(channelId)));
2579
+ const queryParams = new Map<string, any>();
2580
+
2581
+ let bodyJson : string = "";
2582
+ bodyJson = JSON.stringify(body || {});
2583
+
2584
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
2585
+ const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
2586
+ if (bearerToken) {
2587
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
2588
+ }
2589
+
2590
+ return Promise.race([
2591
+ fetch(fullUrl, fetchOptions).then((response) => {
2592
+ if (response.status == 204) {
2593
+ return response;
2594
+ } else if (response.status >= 200 && response.status < 300) {
2595
+ return response.json();
2596
+ } else {
2597
+ throw response;
2598
+ }
2599
+ }),
2600
+ new Promise((_, reject) =>
2601
+ setTimeout(reject, this.timeoutMs, "Request timed out.")
2602
+ ),
2603
+ ]);
2604
+ }
2605
+
2538
2606
  /** List all users that are part of a channel. */
2539
2607
  listChannelVoiceUsers(bearerToken: string,
2540
2608
  clanId?:string,
@@ -4225,7 +4293,7 @@ export class MezonApi {
4225
4293
  /** Create a new group with the current user as the owner. */
4226
4294
  uploadAttachmentFile(bearerToken: string,
4227
4295
  body:ApiUploadAttachmentRequest,
4228
- options: any = {}): Promise<any> {
4296
+ options: any = {}): Promise<ApiUploadAttachment> {
4229
4297
 
4230
4298
  if (body === null || body === undefined) {
4231
4299
  throw new Error("'body' is a required parameter but is null or undefined.");
package/client.ts CHANGED
@@ -73,6 +73,7 @@ import {
73
73
  ApiMessageRef,
74
74
  ApiChannelMessageHeader,
75
75
  ApiVoiceChannelUserList,
76
+ ApiChannelAttachmentList,
76
77
  } from "./api.gen";
77
78
 
78
79
  import { Session } from "./session";
@@ -1062,6 +1063,36 @@ export class Client {
1062
1063
  });
1063
1064
  }
1064
1065
 
1066
+ /** List a channel's attachment. */
1067
+ async listChannelAttachments(session: Session, clanId: string, channelId: string, fileType: string, state?: number, limit?: number, cursor?: string): Promise<ApiChannelAttachmentList> {
1068
+ if (this.autoRefreshSession && session.refresh_token &&
1069
+ session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
1070
+ await this.sessionRefresh(session);
1071
+ }
1072
+
1073
+ return this.apiClient.listChannelAttachment(session.token, clanId, channelId, fileType, limit, state, cursor).then((response: ApiChannelAttachmentList) => {
1074
+ var result: ApiChannelAttachmentList = {
1075
+ attachments: [],
1076
+ };
1077
+
1078
+ if (response.attachments == null) {
1079
+ return Promise.resolve(result);
1080
+ }
1081
+
1082
+ response.attachments!.forEach(at => {
1083
+ result.attachments!.push({
1084
+ filename: at.filename,
1085
+ filesize: at.filetype,
1086
+ filetype: at.filetype,
1087
+ id: at.id,
1088
+ uploader: at.uploader,
1089
+ url: at.uploader
1090
+ })
1091
+ });
1092
+ return Promise.resolve(result);
1093
+ });
1094
+ }
1095
+
1065
1096
  /** List a channel's users. */
1066
1097
  async listClanUsers(session: Session, clanId: string): Promise<ApiClanUserList> {
1067
1098
  if (this.autoRefreshSession && session.refresh_token &&
package/dist/api.gen.d.ts CHANGED
@@ -99,6 +99,19 @@ export interface ApiCategoryDesc {
99
99
  export interface ApiCategoryDescList {
100
100
  categorydesc?: Array<ApiCategoryDesc>;
101
101
  }
102
+ /** */
103
+ export interface ApiChannelAttachment {
104
+ filename?: string;
105
+ filesize?: string;
106
+ filetype?: string;
107
+ id?: string;
108
+ uploader?: string;
109
+ url?: string;
110
+ }
111
+ /** */
112
+ export interface ApiChannelAttachmentList {
113
+ attachments?: Array<ApiChannelAttachment>;
114
+ }
102
115
  /** A list of channel description, usually a result of a list operation. */
103
116
  export interface ApiChannelDescList {
104
117
  cacheable_cursor?: string;
@@ -619,22 +632,24 @@ export declare class MezonApi {
619
632
  listCategoryDescs(bearerToken: string, clanId: string, creatorId?: string, categoryName?: string, categoryId?: string, options?: any): Promise<ApiCategoryDescList>;
620
633
  /** List a channel's message history. */
621
634
  listChannelMessages(bearerToken: string, channelId: string, messageId?: string, direction?: number, limit?: number, options?: any): Promise<ApiChannelMessageList>;
622
- /** List user channels */
623
- listChannelDescs(bearerToken: string, limit?: number, state?: number, cursor?: string, clanId?: string, channelType?: number, options?: any): Promise<ApiChannelDescList>;
624
- /** Create a new channel with the current user as the owner. */
625
- createChannelDesc(bearerToken: string, body: ApiCreateChannelDescRequest, options?: any): Promise<ApiChannelDescription>;
626
- /** Delete a channel by ID. */
627
- deleteChannelDesc(bearerToken: string, channelId: string, options?: any): Promise<any>;
628
- /** Update fields in a given channel. */
629
- updateChannelDesc(bearerToken: string, channelId: string, body: {}, options?: any): Promise<any>;
630
635
  /** Add users to a channel. */
631
636
  addChannelUsers(bearerToken: string, channelId: string, userIds?: Array<string>, options?: any): Promise<any>;
637
+ /** List all attachment that are part of a channel. */
638
+ listChannelAttachment(bearerToken: string, channelId: string, clanId?: string, fileType?: string, limit?: number, state?: number, cursor?: string, options?: any): Promise<ApiChannelAttachmentList>;
632
639
  /** Leave a channel the user is a member of. */
633
640
  leaveChannel(bearerToken: string, channelId: string, options?: any): Promise<any>;
634
641
  /** Kick a set of users from a channel. */
635
642
  removeChannelUsers(bearerToken: string, channelId: string, userIds?: Array<string>, options?: any): Promise<any>;
636
643
  /** List all users that are part of a channel. */
637
644
  listChannelUsers(bearerToken: string, clanId: string, channelId: string, channelType?: number, limit?: number, state?: number, cursor?: string, options?: any): Promise<ApiChannelUserList>;
645
+ /** List user channels */
646
+ listChannelDescs(bearerToken: string, limit?: number, state?: number, cursor?: string, clanId?: string, channelType?: number, options?: any): Promise<ApiChannelDescList>;
647
+ /** Create a new channel with the current user as the owner. */
648
+ createChannelDesc(bearerToken: string, body: ApiCreateChannelDescRequest, options?: any): Promise<ApiChannelDescription>;
649
+ /** Delete a channel by ID. */
650
+ deleteChannelDesc(bearerToken: string, channelId: string, options?: any): Promise<any>;
651
+ /** Update fields in a given channel. */
652
+ updateChannelDesc(bearerToken: string, channelId: string, body: {}, options?: any): Promise<any>;
638
653
  /** List all users that are part of a channel. */
639
654
  listChannelVoiceUsers(bearerToken: string, clanId?: string, channelId?: string, channelType?: number, limit?: number, state?: number, cursor?: string, options?: any): Promise<ApiVoiceChannelUserList>;
640
655
  /** List clans */
@@ -726,7 +741,7 @@ export declare class MezonApi {
726
741
  /** */
727
742
  updateUserProfileByClan(bearerToken: string, clanId: string, body: {}, options?: any): Promise<any>;
728
743
  /** Create a new group with the current user as the owner. */
729
- uploadAttachmentFile(bearerToken: string, body: ApiUploadAttachmentRequest, options?: any): Promise<any>;
744
+ uploadAttachmentFile(bearerToken: string, body: ApiUploadAttachmentRequest, options?: any): Promise<ApiUploadAttachment>;
730
745
  /** Fetch zero or more users by ID and/or username. */
731
746
  getUsers(bearerToken: string, ids?: Array<string>, usernames?: Array<string>, facebookIds?: Array<string>, options?: any): Promise<ApiUsers>;
732
747
  /** */
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, ApiLinkInviteUser, ApiInviteUserRes, ApiUploadAttachmentRequest, ApiUploadAttachment, ApiMessageReaction, ApiMessageMention, ApiMessageAttachment, ApiMessageRef, ApiChannelMessageHeader, ApiVoiceChannelUserList } 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, ApiLinkInviteUser, ApiInviteUserRes, ApiUploadAttachmentRequest, ApiUploadAttachment, ApiMessageReaction, ApiMessageMention, ApiMessageAttachment, ApiMessageRef, ApiChannelMessageHeader, ApiVoiceChannelUserList, ApiChannelAttachmentList } from "./api.gen";
17
17
  import { Session } from "./session";
18
18
  import { Socket } from "./socket";
19
19
  import { WebSocketAdapter } from "./web_socket_adapter";
@@ -427,6 +427,8 @@ export declare class Client {
427
427
  listChannelVoiceUsers(session: Session, clanId: string, channelId: string, channelType: number, state?: number, limit?: number, cursor?: string): Promise<ApiVoiceChannelUserList>;
428
428
  /** List a channel's users. */
429
429
  listChannelUsers(session: Session, clanId: string, channelId: string, channelType: number, state?: number, limit?: number, cursor?: string): Promise<ApiChannelUserList>;
430
+ /** List a channel's attachment. */
431
+ listChannelAttachments(session: Session, clanId: string, channelId: string, fileType: string, state?: number, limit?: number, cursor?: string): Promise<ApiChannelAttachmentList>;
430
432
  /** List a channel's users. */
431
433
  listClanUsers(session: Session, clanId: string): Promise<ApiClanUserList>;
432
434
  /** List channels. */
@@ -1669,15 +1669,47 @@ var MezonApi = class {
1669
1669
  )
1670
1670
  ]);
1671
1671
  }
1672
- /** List user channels */
1673
- listChannelDescs(bearerToken, limit, state, cursor, clanId, channelType, options = {}) {
1674
- const urlPath = "/v2/channeldesc";
1672
+ /** Add users to a channel. */
1673
+ addChannelUsers(bearerToken, channelId, userIds, options = {}) {
1674
+ if (channelId === null || channelId === void 0) {
1675
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
1676
+ }
1677
+ const urlPath = "/v2/channel/{channelId}/add".replace("{channelId}", encodeURIComponent(String(channelId)));
1678
+ const queryParams = /* @__PURE__ */ new Map();
1679
+ queryParams.set("user_ids", userIds);
1680
+ let bodyJson = "";
1681
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1682
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1683
+ if (bearerToken) {
1684
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1685
+ }
1686
+ return Promise.race([
1687
+ fetch(fullUrl, fetchOptions).then((response) => {
1688
+ if (response.status == 204) {
1689
+ return response;
1690
+ } else if (response.status >= 200 && response.status < 300) {
1691
+ return response.json();
1692
+ } else {
1693
+ throw response;
1694
+ }
1695
+ }),
1696
+ new Promise(
1697
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
1698
+ )
1699
+ ]);
1700
+ }
1701
+ /** List all attachment that are part of a channel. */
1702
+ listChannelAttachment(bearerToken, channelId, clanId, fileType, limit, state, cursor, options = {}) {
1703
+ if (channelId === null || channelId === void 0) {
1704
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
1705
+ }
1706
+ const urlPath = "/v2/channel/{channelId}/attachment".replace("{channelId}", encodeURIComponent(String(channelId)));
1675
1707
  const queryParams = /* @__PURE__ */ new Map();
1708
+ queryParams.set("clan_id", clanId);
1709
+ queryParams.set("file_type", fileType);
1676
1710
  queryParams.set("limit", limit);
1677
1711
  queryParams.set("state", state);
1678
1712
  queryParams.set("cursor", cursor);
1679
- queryParams.set("clan_id", clanId);
1680
- queryParams.set("channel_type", channelType);
1681
1713
  let bodyJson = "";
1682
1714
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1683
1715
  const fetchOptions = buildFetchOptions("GET", options, bodyJson);
@@ -1699,15 +1731,14 @@ var MezonApi = class {
1699
1731
  )
1700
1732
  ]);
1701
1733
  }
1702
- /** Create a new channel with the current user as the owner. */
1703
- createChannelDesc(bearerToken, body, options = {}) {
1704
- if (body === null || body === void 0) {
1705
- throw new Error("'body' is a required parameter but is null or undefined.");
1734
+ /** Leave a channel the user is a member of. */
1735
+ leaveChannel(bearerToken, channelId, options = {}) {
1736
+ if (channelId === null || channelId === void 0) {
1737
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
1706
1738
  }
1707
- const urlPath = "/v2/channeldesc";
1739
+ const urlPath = "/v2/channel/{channelId}/leave".replace("{channelId}", encodeURIComponent(String(channelId)));
1708
1740
  const queryParams = /* @__PURE__ */ new Map();
1709
1741
  let bodyJson = "";
1710
- bodyJson = JSON.stringify(body || {});
1711
1742
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1712
1743
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1713
1744
  if (bearerToken) {
@@ -1728,16 +1759,17 @@ var MezonApi = class {
1728
1759
  )
1729
1760
  ]);
1730
1761
  }
1731
- /** Delete a channel by ID. */
1732
- deleteChannelDesc(bearerToken, channelId, options = {}) {
1762
+ /** Kick a set of users from a channel. */
1763
+ removeChannelUsers(bearerToken, channelId, userIds, options = {}) {
1733
1764
  if (channelId === null || channelId === void 0) {
1734
1765
  throw new Error("'channelId' is a required parameter but is null or undefined.");
1735
1766
  }
1736
- const urlPath = "/v2/channeldesc/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
1767
+ const urlPath = "/v2/channel/{channelId}/remove".replace("{channelId}", encodeURIComponent(String(channelId)));
1737
1768
  const queryParams = /* @__PURE__ */ new Map();
1769
+ queryParams.set("user_ids", userIds);
1738
1770
  let bodyJson = "";
1739
1771
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1740
- const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
1772
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1741
1773
  if (bearerToken) {
1742
1774
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1743
1775
  }
@@ -1756,20 +1788,21 @@ var MezonApi = class {
1756
1788
  )
1757
1789
  ]);
1758
1790
  }
1759
- /** Update fields in a given channel. */
1760
- updateChannelDesc(bearerToken, channelId, body, options = {}) {
1791
+ /** List all users that are part of a channel. */
1792
+ listChannelUsers(bearerToken, clanId, channelId, channelType, limit, state, cursor, options = {}) {
1761
1793
  if (channelId === null || channelId === void 0) {
1762
1794
  throw new Error("'channelId' is a required parameter but is null or undefined.");
1763
1795
  }
1764
- if (body === null || body === void 0) {
1765
- throw new Error("'body' is a required parameter but is null or undefined.");
1766
- }
1767
- const urlPath = "/v2/channeldesc/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
1796
+ const urlPath = "/v2/channel/{channelId}/user".replace("{channelId}", encodeURIComponent(String(channelId)));
1768
1797
  const queryParams = /* @__PURE__ */ new Map();
1798
+ queryParams.set("clan_id", clanId);
1799
+ queryParams.set("channel_type", channelType);
1800
+ queryParams.set("limit", limit);
1801
+ queryParams.set("state", state);
1802
+ queryParams.set("cursor", cursor);
1769
1803
  let bodyJson = "";
1770
- bodyJson = JSON.stringify(body || {});
1771
1804
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1772
- const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
1805
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
1773
1806
  if (bearerToken) {
1774
1807
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1775
1808
  }
@@ -1788,17 +1821,18 @@ var MezonApi = class {
1788
1821
  )
1789
1822
  ]);
1790
1823
  }
1791
- /** Add users to a channel. */
1792
- addChannelUsers(bearerToken, channelId, userIds, options = {}) {
1793
- if (channelId === null || channelId === void 0) {
1794
- throw new Error("'channelId' is a required parameter but is null or undefined.");
1795
- }
1796
- const urlPath = "/v2/channeldesc/{channelId}/add".replace("{channelId}", encodeURIComponent(String(channelId)));
1824
+ /** List user channels */
1825
+ listChannelDescs(bearerToken, limit, state, cursor, clanId, channelType, options = {}) {
1826
+ const urlPath = "/v2/channeldesc";
1797
1827
  const queryParams = /* @__PURE__ */ new Map();
1798
- queryParams.set("user_ids", userIds);
1828
+ queryParams.set("limit", limit);
1829
+ queryParams.set("state", state);
1830
+ queryParams.set("cursor", cursor);
1831
+ queryParams.set("clan_id", clanId);
1832
+ queryParams.set("channel_type", channelType);
1799
1833
  let bodyJson = "";
1800
1834
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1801
- const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1835
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
1802
1836
  if (bearerToken) {
1803
1837
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1804
1838
  }
@@ -1817,14 +1851,15 @@ var MezonApi = class {
1817
1851
  )
1818
1852
  ]);
1819
1853
  }
1820
- /** Leave a channel the user is a member of. */
1821
- leaveChannel(bearerToken, channelId, options = {}) {
1822
- if (channelId === null || channelId === void 0) {
1823
- throw new Error("'channelId' is a required parameter but is null or undefined.");
1854
+ /** Create a new channel with the current user as the owner. */
1855
+ createChannelDesc(bearerToken, body, options = {}) {
1856
+ if (body === null || body === void 0) {
1857
+ throw new Error("'body' is a required parameter but is null or undefined.");
1824
1858
  }
1825
- const urlPath = "/v2/channeldesc/{channelId}/leave".replace("{channelId}", encodeURIComponent(String(channelId)));
1859
+ const urlPath = "/v2/channeldesc";
1826
1860
  const queryParams = /* @__PURE__ */ new Map();
1827
1861
  let bodyJson = "";
1862
+ bodyJson = JSON.stringify(body || {});
1828
1863
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1829
1864
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1830
1865
  if (bearerToken) {
@@ -1845,17 +1880,16 @@ var MezonApi = class {
1845
1880
  )
1846
1881
  ]);
1847
1882
  }
1848
- /** Kick a set of users from a channel. */
1849
- removeChannelUsers(bearerToken, channelId, userIds, options = {}) {
1883
+ /** Delete a channel by ID. */
1884
+ deleteChannelDesc(bearerToken, channelId, options = {}) {
1850
1885
  if (channelId === null || channelId === void 0) {
1851
1886
  throw new Error("'channelId' is a required parameter but is null or undefined.");
1852
1887
  }
1853
- const urlPath = "/v2/channeldesc/{channelId}/remove".replace("{channelId}", encodeURIComponent(String(channelId)));
1888
+ const urlPath = "/v2/channeldesc/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
1854
1889
  const queryParams = /* @__PURE__ */ new Map();
1855
- queryParams.set("user_ids", userIds);
1856
1890
  let bodyJson = "";
1857
1891
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1858
- const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1892
+ const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
1859
1893
  if (bearerToken) {
1860
1894
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1861
1895
  }
@@ -1874,21 +1908,20 @@ var MezonApi = class {
1874
1908
  )
1875
1909
  ]);
1876
1910
  }
1877
- /** List all users that are part of a channel. */
1878
- listChannelUsers(bearerToken, clanId, channelId, channelType, limit, state, cursor, options = {}) {
1911
+ /** Update fields in a given channel. */
1912
+ updateChannelDesc(bearerToken, channelId, body, options = {}) {
1879
1913
  if (channelId === null || channelId === void 0) {
1880
1914
  throw new Error("'channelId' is a required parameter but is null or undefined.");
1881
1915
  }
1882
- const urlPath = "/v2/channeldesc/{channelId}/user".replace("{channelId}", encodeURIComponent(String(channelId)));
1916
+ if (body === null || body === void 0) {
1917
+ throw new Error("'body' is a required parameter but is null or undefined.");
1918
+ }
1919
+ const urlPath = "/v2/channeldesc/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
1883
1920
  const queryParams = /* @__PURE__ */ new Map();
1884
- queryParams.set("clan_id", clanId);
1885
- queryParams.set("channel_type", channelType);
1886
- queryParams.set("limit", limit);
1887
- queryParams.set("state", state);
1888
- queryParams.set("cursor", cursor);
1889
1921
  let bodyJson = "";
1922
+ bodyJson = JSON.stringify(body || {});
1890
1923
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1891
- const fetchOptions = buildFetchOptions("GET", options, bodyJson);
1924
+ const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
1892
1925
  if (bearerToken) {
1893
1926
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1894
1927
  }
@@ -3525,30 +3558,36 @@ var _DefaultSocket = class _DefaultSocket {
3525
3558
  } else if (message.stream_data) {
3526
3559
  this.onstreamdata(message.stream_data);
3527
3560
  } else if (message.channel_message) {
3561
+ var content, reactions, mentions, attachments, references;
3528
3562
  try {
3529
- var e = {
3530
- avatar: message.channel_message.avatar,
3531
- channel_id: message.channel_message.channel_id,
3532
- mode: message.channel_message.mode,
3533
- channel_label: message.channel_message.channel_label,
3534
- clan_id: message.channel_message.clan_id,
3535
- code: message.channel_message.code,
3536
- content: JSON.parse(message.channel_message.content),
3537
- create_time: message.channel_message.create_time,
3538
- id: message.channel_message.message_id,
3539
- sender_id: message.channel_message.sender_id,
3540
- update_time: message.channel_message.update_time,
3541
- user_id_one: message.channel_message.user_id_one,
3542
- user_id_two: message.channel_message.user_id_two,
3543
- username: message.channel_message.username,
3544
- reactions: JSON.parse(message.channel_message.reactions),
3545
- mentions: JSON.parse(message.channel_message.mentions),
3546
- attachments: JSON.parse(message.channel_message.attachments),
3547
- references: JSON.parse(message.channel_message.references)
3548
- };
3549
- this.onchannelmessage(e);
3563
+ content = JSON.parse(message.channel_message.content);
3564
+ reactions = JSON.parse(message.channel_message.reactions);
3565
+ mentions = JSON.parse(message.channel_message.mentions);
3566
+ attachments = JSON.parse(message.channel_message.attachments);
3567
+ references = JSON.parse(message.channel_message.references);
3550
3568
  } catch (e2) {
3551
3569
  }
3570
+ var e = {
3571
+ avatar: message.channel_message.avatar,
3572
+ channel_id: message.channel_message.channel_id,
3573
+ mode: message.channel_message.mode,
3574
+ channel_label: message.channel_message.channel_label,
3575
+ clan_id: message.channel_message.clan_id,
3576
+ code: message.channel_message.code,
3577
+ create_time: message.channel_message.create_time,
3578
+ id: message.channel_message.message_id,
3579
+ sender_id: message.channel_message.sender_id,
3580
+ update_time: message.channel_message.update_time,
3581
+ user_id_one: message.channel_message.user_id_one,
3582
+ user_id_two: message.channel_message.user_id_two,
3583
+ username: message.channel_message.username,
3584
+ content,
3585
+ reactions,
3586
+ mentions,
3587
+ attachments,
3588
+ references
3589
+ };
3590
+ this.onchannelmessage(e);
3552
3591
  } else if (message.message_typing_event) {
3553
3592
  this.onmessagetyping(message.message_typing_event);
3554
3593
  } else if (message.message_reaction_event) {
@@ -4507,6 +4546,33 @@ var Client = class {
4507
4546
  });
4508
4547
  });
4509
4548
  }
4549
+ /** List a channel's attachment. */
4550
+ listChannelAttachments(session, clanId, channelId, fileType, state, limit, cursor) {
4551
+ return __async(this, null, function* () {
4552
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
4553
+ yield this.sessionRefresh(session);
4554
+ }
4555
+ return this.apiClient.listChannelAttachment(session.token, clanId, channelId, fileType, limit, state, cursor).then((response) => {
4556
+ var result = {
4557
+ attachments: []
4558
+ };
4559
+ if (response.attachments == null) {
4560
+ return Promise.resolve(result);
4561
+ }
4562
+ response.attachments.forEach((at) => {
4563
+ result.attachments.push({
4564
+ filename: at.filename,
4565
+ filesize: at.filetype,
4566
+ filetype: at.filetype,
4567
+ id: at.id,
4568
+ uploader: at.uploader,
4569
+ url: at.uploader
4570
+ });
4571
+ });
4572
+ return Promise.resolve(result);
4573
+ });
4574
+ });
4575
+ }
4510
4576
  /** List a channel's users. */
4511
4577
  listClanUsers(session, clanId) {
4512
4578
  return __async(this, null, function* () {
@@ -1641,15 +1641,47 @@ var MezonApi = class {
1641
1641
  )
1642
1642
  ]);
1643
1643
  }
1644
- /** List user channels */
1645
- listChannelDescs(bearerToken, limit, state, cursor, clanId, channelType, options = {}) {
1646
- const urlPath = "/v2/channeldesc";
1644
+ /** Add users to a channel. */
1645
+ addChannelUsers(bearerToken, channelId, userIds, options = {}) {
1646
+ if (channelId === null || channelId === void 0) {
1647
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
1648
+ }
1649
+ const urlPath = "/v2/channel/{channelId}/add".replace("{channelId}", encodeURIComponent(String(channelId)));
1650
+ const queryParams = /* @__PURE__ */ new Map();
1651
+ queryParams.set("user_ids", userIds);
1652
+ let bodyJson = "";
1653
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1654
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1655
+ if (bearerToken) {
1656
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1657
+ }
1658
+ return Promise.race([
1659
+ fetch(fullUrl, fetchOptions).then((response) => {
1660
+ if (response.status == 204) {
1661
+ return response;
1662
+ } else if (response.status >= 200 && response.status < 300) {
1663
+ return response.json();
1664
+ } else {
1665
+ throw response;
1666
+ }
1667
+ }),
1668
+ new Promise(
1669
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
1670
+ )
1671
+ ]);
1672
+ }
1673
+ /** List all attachment that are part of a channel. */
1674
+ listChannelAttachment(bearerToken, channelId, clanId, fileType, limit, state, cursor, options = {}) {
1675
+ if (channelId === null || channelId === void 0) {
1676
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
1677
+ }
1678
+ const urlPath = "/v2/channel/{channelId}/attachment".replace("{channelId}", encodeURIComponent(String(channelId)));
1647
1679
  const queryParams = /* @__PURE__ */ new Map();
1680
+ queryParams.set("clan_id", clanId);
1681
+ queryParams.set("file_type", fileType);
1648
1682
  queryParams.set("limit", limit);
1649
1683
  queryParams.set("state", state);
1650
1684
  queryParams.set("cursor", cursor);
1651
- queryParams.set("clan_id", clanId);
1652
- queryParams.set("channel_type", channelType);
1653
1685
  let bodyJson = "";
1654
1686
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1655
1687
  const fetchOptions = buildFetchOptions("GET", options, bodyJson);
@@ -1671,15 +1703,14 @@ var MezonApi = class {
1671
1703
  )
1672
1704
  ]);
1673
1705
  }
1674
- /** Create a new channel with the current user as the owner. */
1675
- createChannelDesc(bearerToken, body, options = {}) {
1676
- if (body === null || body === void 0) {
1677
- throw new Error("'body' is a required parameter but is null or undefined.");
1706
+ /** Leave a channel the user is a member of. */
1707
+ leaveChannel(bearerToken, channelId, options = {}) {
1708
+ if (channelId === null || channelId === void 0) {
1709
+ throw new Error("'channelId' is a required parameter but is null or undefined.");
1678
1710
  }
1679
- const urlPath = "/v2/channeldesc";
1711
+ const urlPath = "/v2/channel/{channelId}/leave".replace("{channelId}", encodeURIComponent(String(channelId)));
1680
1712
  const queryParams = /* @__PURE__ */ new Map();
1681
1713
  let bodyJson = "";
1682
- bodyJson = JSON.stringify(body || {});
1683
1714
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1684
1715
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1685
1716
  if (bearerToken) {
@@ -1700,16 +1731,17 @@ var MezonApi = class {
1700
1731
  )
1701
1732
  ]);
1702
1733
  }
1703
- /** Delete a channel by ID. */
1704
- deleteChannelDesc(bearerToken, channelId, options = {}) {
1734
+ /** Kick a set of users from a channel. */
1735
+ removeChannelUsers(bearerToken, channelId, userIds, options = {}) {
1705
1736
  if (channelId === null || channelId === void 0) {
1706
1737
  throw new Error("'channelId' is a required parameter but is null or undefined.");
1707
1738
  }
1708
- const urlPath = "/v2/channeldesc/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
1739
+ const urlPath = "/v2/channel/{channelId}/remove".replace("{channelId}", encodeURIComponent(String(channelId)));
1709
1740
  const queryParams = /* @__PURE__ */ new Map();
1741
+ queryParams.set("user_ids", userIds);
1710
1742
  let bodyJson = "";
1711
1743
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1712
- const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
1744
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1713
1745
  if (bearerToken) {
1714
1746
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1715
1747
  }
@@ -1728,20 +1760,21 @@ var MezonApi = class {
1728
1760
  )
1729
1761
  ]);
1730
1762
  }
1731
- /** Update fields in a given channel. */
1732
- updateChannelDesc(bearerToken, channelId, body, options = {}) {
1763
+ /** List all users that are part of a channel. */
1764
+ listChannelUsers(bearerToken, clanId, channelId, channelType, limit, state, cursor, options = {}) {
1733
1765
  if (channelId === null || channelId === void 0) {
1734
1766
  throw new Error("'channelId' is a required parameter but is null or undefined.");
1735
1767
  }
1736
- if (body === null || body === void 0) {
1737
- throw new Error("'body' is a required parameter but is null or undefined.");
1738
- }
1739
- const urlPath = "/v2/channeldesc/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
1768
+ const urlPath = "/v2/channel/{channelId}/user".replace("{channelId}", encodeURIComponent(String(channelId)));
1740
1769
  const queryParams = /* @__PURE__ */ new Map();
1770
+ queryParams.set("clan_id", clanId);
1771
+ queryParams.set("channel_type", channelType);
1772
+ queryParams.set("limit", limit);
1773
+ queryParams.set("state", state);
1774
+ queryParams.set("cursor", cursor);
1741
1775
  let bodyJson = "";
1742
- bodyJson = JSON.stringify(body || {});
1743
1776
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1744
- const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
1777
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
1745
1778
  if (bearerToken) {
1746
1779
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1747
1780
  }
@@ -1760,17 +1793,18 @@ var MezonApi = class {
1760
1793
  )
1761
1794
  ]);
1762
1795
  }
1763
- /** Add users to a channel. */
1764
- addChannelUsers(bearerToken, channelId, userIds, options = {}) {
1765
- if (channelId === null || channelId === void 0) {
1766
- throw new Error("'channelId' is a required parameter but is null or undefined.");
1767
- }
1768
- const urlPath = "/v2/channeldesc/{channelId}/add".replace("{channelId}", encodeURIComponent(String(channelId)));
1796
+ /** List user channels */
1797
+ listChannelDescs(bearerToken, limit, state, cursor, clanId, channelType, options = {}) {
1798
+ const urlPath = "/v2/channeldesc";
1769
1799
  const queryParams = /* @__PURE__ */ new Map();
1770
- queryParams.set("user_ids", userIds);
1800
+ queryParams.set("limit", limit);
1801
+ queryParams.set("state", state);
1802
+ queryParams.set("cursor", cursor);
1803
+ queryParams.set("clan_id", clanId);
1804
+ queryParams.set("channel_type", channelType);
1771
1805
  let bodyJson = "";
1772
1806
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1773
- const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1807
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
1774
1808
  if (bearerToken) {
1775
1809
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1776
1810
  }
@@ -1789,14 +1823,15 @@ var MezonApi = class {
1789
1823
  )
1790
1824
  ]);
1791
1825
  }
1792
- /** Leave a channel the user is a member of. */
1793
- leaveChannel(bearerToken, channelId, options = {}) {
1794
- if (channelId === null || channelId === void 0) {
1795
- throw new Error("'channelId' is a required parameter but is null or undefined.");
1826
+ /** Create a new channel with the current user as the owner. */
1827
+ createChannelDesc(bearerToken, body, options = {}) {
1828
+ if (body === null || body === void 0) {
1829
+ throw new Error("'body' is a required parameter but is null or undefined.");
1796
1830
  }
1797
- const urlPath = "/v2/channeldesc/{channelId}/leave".replace("{channelId}", encodeURIComponent(String(channelId)));
1831
+ const urlPath = "/v2/channeldesc";
1798
1832
  const queryParams = /* @__PURE__ */ new Map();
1799
1833
  let bodyJson = "";
1834
+ bodyJson = JSON.stringify(body || {});
1800
1835
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1801
1836
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1802
1837
  if (bearerToken) {
@@ -1817,17 +1852,16 @@ var MezonApi = class {
1817
1852
  )
1818
1853
  ]);
1819
1854
  }
1820
- /** Kick a set of users from a channel. */
1821
- removeChannelUsers(bearerToken, channelId, userIds, options = {}) {
1855
+ /** Delete a channel by ID. */
1856
+ deleteChannelDesc(bearerToken, channelId, options = {}) {
1822
1857
  if (channelId === null || channelId === void 0) {
1823
1858
  throw new Error("'channelId' is a required parameter but is null or undefined.");
1824
1859
  }
1825
- const urlPath = "/v2/channeldesc/{channelId}/remove".replace("{channelId}", encodeURIComponent(String(channelId)));
1860
+ const urlPath = "/v2/channeldesc/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
1826
1861
  const queryParams = /* @__PURE__ */ new Map();
1827
- queryParams.set("user_ids", userIds);
1828
1862
  let bodyJson = "";
1829
1863
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1830
- const fetchOptions = buildFetchOptions("POST", options, bodyJson);
1864
+ const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
1831
1865
  if (bearerToken) {
1832
1866
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1833
1867
  }
@@ -1846,21 +1880,20 @@ var MezonApi = class {
1846
1880
  )
1847
1881
  ]);
1848
1882
  }
1849
- /** List all users that are part of a channel. */
1850
- listChannelUsers(bearerToken, clanId, channelId, channelType, limit, state, cursor, options = {}) {
1883
+ /** Update fields in a given channel. */
1884
+ updateChannelDesc(bearerToken, channelId, body, options = {}) {
1851
1885
  if (channelId === null || channelId === void 0) {
1852
1886
  throw new Error("'channelId' is a required parameter but is null or undefined.");
1853
1887
  }
1854
- const urlPath = "/v2/channeldesc/{channelId}/user".replace("{channelId}", encodeURIComponent(String(channelId)));
1888
+ if (body === null || body === void 0) {
1889
+ throw new Error("'body' is a required parameter but is null or undefined.");
1890
+ }
1891
+ const urlPath = "/v2/channeldesc/{channelId}".replace("{channelId}", encodeURIComponent(String(channelId)));
1855
1892
  const queryParams = /* @__PURE__ */ new Map();
1856
- queryParams.set("clan_id", clanId);
1857
- queryParams.set("channel_type", channelType);
1858
- queryParams.set("limit", limit);
1859
- queryParams.set("state", state);
1860
- queryParams.set("cursor", cursor);
1861
1893
  let bodyJson = "";
1894
+ bodyJson = JSON.stringify(body || {});
1862
1895
  const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1863
- const fetchOptions = buildFetchOptions("GET", options, bodyJson);
1896
+ const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
1864
1897
  if (bearerToken) {
1865
1898
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1866
1899
  }
@@ -3497,30 +3530,36 @@ var _DefaultSocket = class _DefaultSocket {
3497
3530
  } else if (message.stream_data) {
3498
3531
  this.onstreamdata(message.stream_data);
3499
3532
  } else if (message.channel_message) {
3533
+ var content, reactions, mentions, attachments, references;
3500
3534
  try {
3501
- var e = {
3502
- avatar: message.channel_message.avatar,
3503
- channel_id: message.channel_message.channel_id,
3504
- mode: message.channel_message.mode,
3505
- channel_label: message.channel_message.channel_label,
3506
- clan_id: message.channel_message.clan_id,
3507
- code: message.channel_message.code,
3508
- content: JSON.parse(message.channel_message.content),
3509
- create_time: message.channel_message.create_time,
3510
- id: message.channel_message.message_id,
3511
- sender_id: message.channel_message.sender_id,
3512
- update_time: message.channel_message.update_time,
3513
- user_id_one: message.channel_message.user_id_one,
3514
- user_id_two: message.channel_message.user_id_two,
3515
- username: message.channel_message.username,
3516
- reactions: JSON.parse(message.channel_message.reactions),
3517
- mentions: JSON.parse(message.channel_message.mentions),
3518
- attachments: JSON.parse(message.channel_message.attachments),
3519
- references: JSON.parse(message.channel_message.references)
3520
- };
3521
- this.onchannelmessage(e);
3535
+ content = JSON.parse(message.channel_message.content);
3536
+ reactions = JSON.parse(message.channel_message.reactions);
3537
+ mentions = JSON.parse(message.channel_message.mentions);
3538
+ attachments = JSON.parse(message.channel_message.attachments);
3539
+ references = JSON.parse(message.channel_message.references);
3522
3540
  } catch (e2) {
3523
3541
  }
3542
+ var e = {
3543
+ avatar: message.channel_message.avatar,
3544
+ channel_id: message.channel_message.channel_id,
3545
+ mode: message.channel_message.mode,
3546
+ channel_label: message.channel_message.channel_label,
3547
+ clan_id: message.channel_message.clan_id,
3548
+ code: message.channel_message.code,
3549
+ create_time: message.channel_message.create_time,
3550
+ id: message.channel_message.message_id,
3551
+ sender_id: message.channel_message.sender_id,
3552
+ update_time: message.channel_message.update_time,
3553
+ user_id_one: message.channel_message.user_id_one,
3554
+ user_id_two: message.channel_message.user_id_two,
3555
+ username: message.channel_message.username,
3556
+ content,
3557
+ reactions,
3558
+ mentions,
3559
+ attachments,
3560
+ references
3561
+ };
3562
+ this.onchannelmessage(e);
3524
3563
  } else if (message.message_typing_event) {
3525
3564
  this.onmessagetyping(message.message_typing_event);
3526
3565
  } else if (message.message_reaction_event) {
@@ -4479,6 +4518,33 @@ var Client = class {
4479
4518
  });
4480
4519
  });
4481
4520
  }
4521
+ /** List a channel's attachment. */
4522
+ listChannelAttachments(session, clanId, channelId, fileType, state, limit, cursor) {
4523
+ return __async(this, null, function* () {
4524
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
4525
+ yield this.sessionRefresh(session);
4526
+ }
4527
+ return this.apiClient.listChannelAttachment(session.token, clanId, channelId, fileType, limit, state, cursor).then((response) => {
4528
+ var result = {
4529
+ attachments: []
4530
+ };
4531
+ if (response.attachments == null) {
4532
+ return Promise.resolve(result);
4533
+ }
4534
+ response.attachments.forEach((at) => {
4535
+ result.attachments.push({
4536
+ filename: at.filename,
4537
+ filesize: at.filetype,
4538
+ filetype: at.filetype,
4539
+ id: at.id,
4540
+ uploader: at.uploader,
4541
+ url: at.uploader
4542
+ });
4543
+ });
4544
+ return Promise.resolve(result);
4545
+ });
4546
+ });
4547
+ }
4482
4548
  /** List a channel's users. */
4483
4549
  listClanUsers(session, clanId) {
4484
4550
  return __async(this, null, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mezon-js",
3
- "version": "2.7.7",
3
+ "version": "2.7.9",
4
4
  "scripts": {
5
5
  "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs"
6
6
  },
package/socket.ts CHANGED
@@ -884,32 +884,38 @@ export class DefaultSocket implements Socket {
884
884
  this.onstreampresence(<StreamPresenceEvent>message.stream_presence_event);
885
885
  } else if (message.stream_data) {
886
886
  this.onstreamdata(<StreamData>message.stream_data);
887
- } else if (message.channel_message) {
888
- try {
889
- var e: ChannelMessageEvent = {
890
- avatar: message.channel_message.avatar,
891
- channel_id: message.channel_message.channel_id,
892
- mode: message.channel_message.mode,
893
- channel_label: message.channel_message.channel_label,
894
- clan_id: message.channel_message.clan_id,
895
- code: message.channel_message.code,
896
- content: JSON.parse(message.channel_message.content),
897
- create_time: message.channel_message.create_time,
898
- id: message.channel_message.message_id,
899
- sender_id: message.channel_message.sender_id,
900
- update_time: message.channel_message.update_time,
901
- user_id_one: message.channel_message.user_id_one,
902
- user_id_two: message.channel_message.user_id_two,
903
- username: message.channel_message.username,
904
- reactions: JSON.parse(message.channel_message.reactions),
905
- mentions: JSON.parse(message.channel_message.mentions),
906
- attachments: JSON.parse(message.channel_message.attachments),
907
- references: JSON.parse(message.channel_message.references)
908
- };
909
- this.onchannelmessage(e);
887
+ } else if (message.channel_message) {
888
+ var content, reactions, mentions, attachments, references;
889
+ try {
890
+ content = JSON.parse(message.channel_message.content);
891
+ reactions = JSON.parse(message.channel_message.reactions);
892
+ mentions = JSON.parse(message.channel_message.mentions);
893
+ attachments = JSON.parse(message.channel_message.attachments);
894
+ references = JSON.parse(message.channel_message.references);
910
895
  } catch(e) {
911
896
  //console.log("error parse data", e);
912
- }
897
+ }
898
+ var e: ChannelMessageEvent = {
899
+ avatar: message.channel_message.avatar,
900
+ channel_id: message.channel_message.channel_id,
901
+ mode: message.channel_message.mode,
902
+ channel_label: message.channel_message.channel_label,
903
+ clan_id: message.channel_message.clan_id,
904
+ code: message.channel_message.code,
905
+ create_time: message.channel_message.create_time,
906
+ id: message.channel_message.message_id,
907
+ sender_id: message.channel_message.sender_id,
908
+ update_time: message.channel_message.update_time,
909
+ user_id_one: message.channel_message.user_id_one,
910
+ user_id_two: message.channel_message.user_id_two,
911
+ username: message.channel_message.username,
912
+ content: content,
913
+ reactions: reactions,
914
+ mentions: mentions,
915
+ attachments: attachments,
916
+ references: references,
917
+ };
918
+ this.onchannelmessage(e);
913
919
  } else if (message.message_typing_event) {
914
920
  this.onmessagetyping(<MessageTypingEvent>message.message_typing_event);
915
921
  } else if (message.message_reaction_event) {