@amityco/ts-sdk 7.26.1-e618fbd1.0 → 7.26.1-edc0783.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/@types/core/events.d.ts +0 -2
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/permissions.d.ts +0 -1
  4. package/dist/@types/core/permissions.d.ts.map +1 -1
  5. package/dist/@types/domains/channel.d.ts +0 -5
  6. package/dist/@types/domains/channel.d.ts.map +1 -1
  7. package/dist/@types/domains/client.d.ts +0 -7
  8. package/dist/@types/domains/client.d.ts.map +1 -1
  9. package/dist/@types/index.d.ts +0 -1
  10. package/dist/@types/index.d.ts.map +1 -1
  11. package/dist/channelRepository/events/index.d.ts +0 -2
  12. package/dist/channelRepository/events/index.d.ts.map +1 -1
  13. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  14. package/dist/channelRepository/utils/index.d.ts +0 -1
  15. package/dist/channelRepository/utils/index.d.ts.map +1 -1
  16. package/dist/client/api/loginWithAccessToken.d.ts.map +1 -1
  17. package/dist/client/api/resumeSession.d.ts.map +1 -1
  18. package/dist/client/api/validateAccessToken.d.ts +1 -1
  19. package/dist/client/api/validateAccessToken.d.ts.map +1 -1
  20. package/dist/core/events.d.ts +3 -3
  21. package/dist/core/events.d.ts.map +1 -1
  22. package/dist/index.cjs.js +107 -396
  23. package/dist/index.esm.js +107 -396
  24. package/dist/index.umd.js +2 -2
  25. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +0 -1
  26. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
  27. package/dist/messageRepository/api/index.d.ts +0 -2
  28. package/dist/messageRepository/api/index.d.ts.map +1 -1
  29. package/dist/utils/tests/dummy/index.d.ts +0 -1
  30. package/dist/utils/tests/dummy/index.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/dist/@types/domains/pinnedMessage.d.ts +0 -43
  33. package/dist/@types/domains/pinnedMessage.d.ts.map +0 -1
  34. package/dist/channelRepository/events/onChannelMessagePinned.d.ts +0 -24
  35. package/dist/channelRepository/events/onChannelMessagePinned.d.ts.map +0 -1
  36. package/dist/channelRepository/events/onChannelMessageUnpinned.d.ts +0 -21
  37. package/dist/channelRepository/events/onChannelMessageUnpinned.d.ts.map +0 -1
  38. package/dist/channelRepository/events/onChannelPinnedMessageDeleted.d.ts +0 -12
  39. package/dist/channelRepository/events/onChannelPinnedMessageDeleted.d.ts.map +0 -1
  40. package/dist/channelRepository/events/tests/onChannelMessagePinned.test.d.ts +0 -2
  41. package/dist/channelRepository/events/tests/onChannelMessagePinned.test.d.ts.map +0 -1
  42. package/dist/channelRepository/utils/tests/pinnedMessage.test.d.ts +0 -2
  43. package/dist/channelRepository/utils/tests/pinnedMessage.test.d.ts.map +0 -1
  44. package/dist/channelRepository/utils/updatePinnedMessageCache.d.ts +0 -24
  45. package/dist/channelRepository/utils/updatePinnedMessageCache.d.ts.map +0 -1
  46. package/dist/client/api/tests/validateAccessToken.test.d.ts +0 -2
  47. package/dist/client/api/tests/validateAccessToken.test.d.ts.map +0 -1
  48. package/dist/messageRepository/api/pinMessage.d.ts +0 -29
  49. package/dist/messageRepository/api/pinMessage.d.ts.map +0 -1
  50. package/dist/messageRepository/api/tests/pinMessage.test.d.ts +0 -2
  51. package/dist/messageRepository/api/tests/pinMessage.test.d.ts.map +0 -1
  52. package/dist/messageRepository/api/tests/unpinMessage.test.d.ts +0 -2
  53. package/dist/messageRepository/api/tests/unpinMessage.test.d.ts.map +0 -1
  54. package/dist/messageRepository/api/unpinMessage.d.ts +0 -28
  55. package/dist/messageRepository/api/unpinMessage.d.ts.map +0 -1
  56. package/dist/messageRepository/utils/refreshChannelPermissionsForMessage.d.ts +0 -13
  57. package/dist/messageRepository/utils/refreshChannelPermissionsForMessage.d.ts.map +0 -1
  58. package/dist/utils/tests/dummy/pinnedMessage.d.ts +0 -2
  59. package/dist/utils/tests/dummy/pinnedMessage.d.ts.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -3842,53 +3842,6 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
3842
3842
  channelUsers });
3843
3843
  };
3844
3844
 
3845
- const channelCacheKey = (channel) => [
3846
- 'channel',
3847
- 'get',
3848
- getResolver('channel')(channel),
3849
- ];
3850
- /**
3851
- * Find a cached channel by any of its ids (internal, public, or `channelId`).
3852
- *
3853
- * The channel cache is keyed by the channel internal id (see `idResolvers.channel`), but
3854
- * realtime payloads reference channels by different ids: pin events carry the **public**
3855
- * id, messages carry `channelId`. Try the cheap direct lookup first, then scan.
3856
- */
3857
- const findCachedChannelByAnyId = (id) => {
3858
- var _a, _b, _c;
3859
- if (!id)
3860
- return undefined;
3861
- const direct = (_a = pullFromCache(['channel', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
3862
- if (direct)
3863
- return direct;
3864
- return (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => data.channelInternalId === id || data.channelPublicId === id || data.channelId === id)) === null || _c === void 0 ? void 0 : _c.data;
3865
- };
3866
- /**
3867
- * Resolve the cached channel a `channel.messagePinned` / `channel.messageUnpinned` event
3868
- * refers to. `data.channelId` is the channel public id; a pinned message body (present on
3869
- * `messagePinned` only) also carries the internal id, which is the direct cache key.
3870
- */
3871
- const findCachedChannelForPin = (payload) => {
3872
- var _a, _b;
3873
- return (_b = findCachedChannelByAnyId((_a = payload.pinnedMessage) === null || _a === void 0 ? void 0 : _a.channelId)) !== null && _b !== void 0 ? _b : findCachedChannelByAnyId(payload.channelId);
3874
- };
3875
- /**
3876
- * Write a new pin snapshot (or `null` to clear) on a cached channel and ingest any
3877
- * users delivered with it (the pin author and the message author), so the banner can
3878
- * render a byline without a second fetch.
3879
- *
3880
- * Every `messagePinned` payload is a full snapshot — "this is the pin now" — so the last
3881
- * one received always wins; there is no merging with the previous pin.
3882
- */
3883
- const updatePinnedMessageCache = (channel, pinnedMessage, users) => {
3884
- if (users && users.length > 0) {
3885
- ingestInCache({ users: users.map(convertRawUserToInternalUser) });
3886
- }
3887
- const updated = Object.assign(Object.assign({}, channel), { pinnedMessage });
3888
- pushToCache(channelCacheKey(channel), updated);
3889
- return updated;
3890
- };
3891
-
3892
3845
  /**
3893
3846
  * ```js
3894
3847
  * import { getSubChannelMarkers } from '@amityco/ts-sdk'
@@ -4170,55 +4123,55 @@ function isEqual(x, y) {
4170
4123
  }));
4171
4124
  }
4172
4125
 
4173
- const callbacks$e = [];
4174
- let mainDisposer$d = null;
4175
- const dispose$e = (cb) => {
4176
- const index = callbacks$e.indexOf(cb);
4126
+ const callbacks$c = [];
4127
+ let mainDisposer$b = null;
4128
+ const dispose$c = (cb) => {
4129
+ const index = callbacks$c.indexOf(cb);
4177
4130
  if (index > -1) {
4178
- callbacks$e.splice(index, 1);
4131
+ callbacks$c.splice(index, 1);
4179
4132
  }
4180
- if (callbacks$e.length === 0) {
4181
- mainDisposer$d === null || mainDisposer$d === void 0 ? void 0 : mainDisposer$d();
4133
+ if (callbacks$c.length === 0) {
4134
+ mainDisposer$b === null || mainDisposer$b === void 0 ? void 0 : mainDisposer$b();
4182
4135
  }
4183
4136
  };
4184
4137
  const onChannelCreated = (callback) => {
4185
- if (callbacks$e.length === 0) {
4138
+ if (callbacks$c.length === 0) {
4186
4139
  const client = getActiveClient();
4187
4140
  const filter = async (payload) => {
4188
4141
  const data = await prepareChannelPayload(payload);
4189
4142
  ingestInCache(data);
4190
- callbacks$e.forEach(cb => cb(data.channels[0]));
4143
+ callbacks$c.forEach(cb => cb(data.channels[0]));
4191
4144
  };
4192
- mainDisposer$d = createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
4145
+ mainDisposer$b = createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
4193
4146
  }
4194
- callbacks$e.push(callback);
4195
- return () => dispose$e(callback);
4147
+ callbacks$c.push(callback);
4148
+ return () => dispose$c(callback);
4196
4149
  };
4197
4150
 
4198
- const callbacks$d = [];
4151
+ const callbacks$b = [];
4199
4152
  const mainDisposers = [];
4200
- const dispose$d = (cb) => {
4201
- const index = callbacks$d.indexOf(cb);
4153
+ const dispose$b = (cb) => {
4154
+ const index = callbacks$b.indexOf(cb);
4202
4155
  if (index > -1) {
4203
- callbacks$d.splice(index, 1);
4156
+ callbacks$b.splice(index, 1);
4204
4157
  }
4205
- if (callbacks$d.length === 0) {
4158
+ if (callbacks$b.length === 0) {
4206
4159
  mainDisposers.forEach(fn => fn());
4207
4160
  }
4208
4161
  };
4209
4162
  const onChannelUpdated = (callback) => {
4210
4163
  const client = getActiveClient();
4211
- if (callbacks$d.length === 0) {
4164
+ if (callbacks$b.length === 0) {
4212
4165
  const filter = async (payload) => {
4213
4166
  const data = await prepareChannelPayload(payload);
4214
4167
  ingestInCache(data);
4215
- callbacks$d.forEach(cb => cb(data.channels[0]));
4168
+ callbacks$b.forEach(cb => cb(data.channels[0]));
4216
4169
  };
4217
4170
  mainDisposers.push(createEventSubscriber(client, 'onChannelUpdated', 'channel.updated', filter));
4218
- mainDisposers.push(createEventSubscriber(client, 'onChannelUpdated', 'local.channel.updated', payload => callbacks$d.forEach(cb => cb(payload.channels[0]))));
4171
+ mainDisposers.push(createEventSubscriber(client, 'onChannelUpdated', 'local.channel.updated', payload => callbacks$b.forEach(cb => cb(payload.channels[0]))));
4219
4172
  }
4220
- callbacks$d.push(callback);
4221
- return () => dispose$d(callback);
4173
+ callbacks$b.push(callback);
4174
+ return () => dispose$b(callback);
4222
4175
  };
4223
4176
 
4224
4177
  const addFlagIsDeletedSubChannelUnreadByChannelId = (channelId) => {
@@ -4241,19 +4194,19 @@ const deleteChannelUnreadByChannelId = (channelId) => {
4241
4194
  }
4242
4195
  };
4243
4196
 
4244
- const callbacks$c = [];
4245
- let mainDisposer$c = null;
4246
- const dispose$c = (cb) => {
4247
- const index = callbacks$c.indexOf(cb);
4197
+ const callbacks$a = [];
4198
+ let mainDisposer$a = null;
4199
+ const dispose$a = (cb) => {
4200
+ const index = callbacks$a.indexOf(cb);
4248
4201
  if (index > -1) {
4249
- callbacks$c.splice(index, 1);
4202
+ callbacks$a.splice(index, 1);
4250
4203
  }
4251
- if (callbacks$c.length === 0) {
4252
- mainDisposer$c === null || mainDisposer$c === void 0 ? void 0 : mainDisposer$c();
4204
+ if (callbacks$a.length === 0) {
4205
+ mainDisposer$a === null || mainDisposer$a === void 0 ? void 0 : mainDisposer$a();
4253
4206
  }
4254
4207
  };
4255
4208
  const onChannelDeleted = (callback) => {
4256
- if (callbacks$c.length === 0) {
4209
+ if (callbacks$a.length === 0) {
4257
4210
  const client = getActiveClient();
4258
4211
  const filter = async (payload) => {
4259
4212
  const data = await prepareChannelPayload(payload);
@@ -4273,53 +4226,53 @@ const onChannelDeleted = (callback) => {
4273
4226
  }
4274
4227
  });
4275
4228
  ingestInCache(data);
4276
- callbacks$c.forEach(cb => cb(data.channels[0]));
4229
+ callbacks$a.forEach(cb => cb(data.channels[0]));
4277
4230
  };
4278
- mainDisposer$c = createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
4231
+ mainDisposer$a = createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
4279
4232
  }
4280
- callbacks$c.push(callback);
4281
- return () => dispose$c(callback);
4233
+ callbacks$a.push(callback);
4234
+ return () => dispose$a(callback);
4282
4235
  };
4283
4236
 
4284
- const callbacks$b = [];
4285
- let mainDisposer$b = null;
4286
- const dispose$b = (cb) => {
4287
- const index = callbacks$b.indexOf(cb);
4237
+ const callbacks$9 = [];
4238
+ let mainDisposer$9 = null;
4239
+ const dispose$9 = (cb) => {
4240
+ const index = callbacks$9.indexOf(cb);
4288
4241
  if (index > -1) {
4289
- callbacks$b.splice(index, 1);
4242
+ callbacks$9.splice(index, 1);
4290
4243
  }
4291
- if (callbacks$b.length === 0) {
4292
- mainDisposer$b === null || mainDisposer$b === void 0 ? void 0 : mainDisposer$b();
4244
+ if (callbacks$9.length === 0) {
4245
+ mainDisposer$9 === null || mainDisposer$9 === void 0 ? void 0 : mainDisposer$9();
4293
4246
  }
4294
4247
  };
4295
4248
  const onChannelJoined = (callback) => {
4296
- if (callbacks$b.length === 0) {
4249
+ if (callbacks$9.length === 0) {
4297
4250
  const client = getActiveClient();
4298
4251
  const filter = async (payload) => {
4299
4252
  const preparedPayload = await prepareChannelPayload(payload);
4300
4253
  const { channels, channelUsers } = preparedPayload;
4301
4254
  ingestInCache(preparedPayload);
4302
- callbacks$b.forEach(cb => cb(channels[0], channelUsers[0]));
4255
+ callbacks$9.forEach(cb => cb(channels[0], channelUsers[0]));
4303
4256
  };
4304
- mainDisposer$b = createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
4257
+ mainDisposer$9 = createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
4305
4258
  }
4306
- callbacks$b.push(callback);
4307
- return () => dispose$b(callback);
4259
+ callbacks$9.push(callback);
4260
+ return () => dispose$9(callback);
4308
4261
  };
4309
4262
 
4310
- const callbacks$a = [];
4311
- let mainDisposer$a = null;
4312
- const dispose$a = (cb) => {
4313
- const index = callbacks$a.indexOf(cb);
4263
+ const callbacks$8 = [];
4264
+ let mainDisposer$8 = null;
4265
+ const dispose$8 = (cb) => {
4266
+ const index = callbacks$8.indexOf(cb);
4314
4267
  if (index > -1) {
4315
- callbacks$a.splice(index, 1);
4268
+ callbacks$8.splice(index, 1);
4316
4269
  }
4317
- if (callbacks$a.length === 0) {
4318
- mainDisposer$a === null || mainDisposer$a === void 0 ? void 0 : mainDisposer$a();
4270
+ if (callbacks$8.length === 0) {
4271
+ mainDisposer$8 === null || mainDisposer$8 === void 0 ? void 0 : mainDisposer$8();
4319
4272
  }
4320
4273
  };
4321
4274
  const onChannelLeft = (callback) => {
4322
- if (callbacks$a.length === 0) {
4275
+ if (callbacks$8.length === 0) {
4323
4276
  const client = getActiveClient();
4324
4277
  const filter = async (payload) => {
4325
4278
  const { userId } = getActiveClient();
@@ -4343,27 +4296,27 @@ const onChannelLeft = (callback) => {
4343
4296
  }
4344
4297
  const { channels, channelUsers } = preparedPayload;
4345
4298
  ingestInCache(preparedPayload);
4346
- callbacks$a.forEach(cb => cb(channels[0], channelUsers[0]));
4299
+ callbacks$8.forEach(cb => cb(channels[0], channelUsers[0]));
4347
4300
  };
4348
- mainDisposer$a = createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
4301
+ mainDisposer$8 = createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
4349
4302
  }
4350
- callbacks$a.push(callback);
4351
- return () => dispose$a(callback);
4303
+ callbacks$8.push(callback);
4304
+ return () => dispose$8(callback);
4352
4305
  };
4353
4306
 
4354
- const callbacks$9 = [];
4355
- let mainDisposer$9 = null;
4356
- const dispose$9 = (cb) => {
4357
- const index = callbacks$9.indexOf(cb);
4307
+ const callbacks$7 = [];
4308
+ let mainDisposer$7 = null;
4309
+ const dispose$7 = (cb) => {
4310
+ const index = callbacks$7.indexOf(cb);
4358
4311
  if (index > -1) {
4359
- callbacks$9.splice(index, 1);
4312
+ callbacks$7.splice(index, 1);
4360
4313
  }
4361
- if (callbacks$9.length === 0) {
4362
- mainDisposer$9 === null || mainDisposer$9 === void 0 ? void 0 : mainDisposer$9();
4314
+ if (callbacks$7.length === 0) {
4315
+ mainDisposer$7 === null || mainDisposer$7 === void 0 ? void 0 : mainDisposer$7();
4363
4316
  }
4364
4317
  };
4365
4318
  const onChannelSetMuted = (callback) => {
4366
- if (callbacks$9.length === 0) {
4319
+ if (callbacks$7.length === 0) {
4367
4320
  const client = getActiveClient();
4368
4321
  const filter = async (payload) => {
4369
4322
  var _a;
@@ -4378,114 +4331,14 @@ const onChannelSetMuted = (callback) => {
4378
4331
  payload.channelId,
4379
4332
  ])) === null || _a === void 0 ? void 0 : _a.data;
4380
4333
  if (channel) {
4381
- callbacks$9.forEach(cb => cb(channel));
4334
+ callbacks$7.forEach(cb => cb(channel));
4382
4335
  }
4383
4336
  };
4384
- mainDisposer$9 = createEventSubscriber(client, 'onChannelMute', 'channel.setMuted', filter);
4385
- }
4386
- callbacks$9.push(callback);
4387
- return () => dispose$9(callback);
4388
- };
4389
-
4390
- const callbacks$8 = [];
4391
- let mainDisposer$8 = null;
4392
- const dispose$8 = (cb) => {
4393
- const index = callbacks$8.indexOf(cb);
4394
- if (index > -1) {
4395
- callbacks$8.splice(index, 1);
4396
- }
4397
- if (callbacks$8.length === 0) {
4398
- mainDisposer$8 === null || mainDisposer$8 === void 0 ? void 0 : mainDisposer$8();
4399
- }
4400
- };
4401
- /* begin_public_function
4402
- id: channel.event.message_pinned
4403
- */
4404
- /**
4405
- * ```js
4406
- * import { onChannelMessagePinned } from '@amityco/ts-sdk'
4407
- * const dispose = onChannelMessagePinned(channel => {
4408
- * // channel.pinnedMessage is the new pin
4409
- * })
4410
- * ```
4411
- *
4412
- * Fired when a message is pinned in a channel (the `channel.messagePinned` realtime
4413
- * event). Pinning a different message while one is already pinned emits a single
4414
- * `messagePinned` carrying the replacement — treat every payload as a full snapshot.
4415
- *
4416
- * The updated channel is written to cache before the callback runs, so
4417
- * `ChannelRepository.getChannel` observers see `channel.pinnedMessage` change.
4418
- *
4419
- * @param callback The function to call when the event was fired
4420
- * @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
4421
- *
4422
- * @category Channel Events
4423
- */
4424
- const onChannelMessagePinned = (callback) => {
4425
- if (callbacks$8.length === 0) {
4426
- const client = getActiveClient();
4427
- const filter = (payload) => {
4428
- var _a;
4429
- const channel = findCachedChannelForPin(payload);
4430
- if (!channel)
4431
- return;
4432
- const updated = updatePinnedMessageCache(channel, (_a = payload.pinnedMessage) !== null && _a !== void 0 ? _a : null, payload.users);
4433
- callbacks$8.forEach(cb => cb(updated));
4434
- };
4435
- mainDisposer$8 = createEventSubscriber(client, 'onChannelMessagePinned', 'channel.messagePinned', filter);
4436
- }
4437
- callbacks$8.push(callback);
4438
- return () => dispose$8(callback);
4439
- };
4440
- /* end_public_function */
4441
-
4442
- const callbacks$7 = [];
4443
- let mainDisposer$7 = null;
4444
- const dispose$7 = (cb) => {
4445
- const index = callbacks$7.indexOf(cb);
4446
- if (index > -1) {
4447
- callbacks$7.splice(index, 1);
4448
- }
4449
- if (callbacks$7.length === 0) {
4450
- mainDisposer$7 === null || mainDisposer$7 === void 0 ? void 0 : mainDisposer$7();
4451
- }
4452
- };
4453
- /* begin_public_function
4454
- id: channel.event.message_unpinned
4455
- */
4456
- /**
4457
- * ```js
4458
- * import { onChannelMessageUnpinned } from '@amityco/ts-sdk'
4459
- * const dispose = onChannelMessageUnpinned(channel => {
4460
- * // channel.pinnedMessage is now null
4461
- * })
4462
- * ```
4463
- *
4464
- * Fired when a channel's pinned message is removed (the `channel.messageUnpinned`
4465
- * realtime event) — either by an explicit unpin or automatically by the server when the
4466
- * pinned message is deleted or its author is banned from the channel / globally.
4467
- *
4468
- * @param callback The function to call when the event was fired
4469
- * @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
4470
- *
4471
- * @category Channel Events
4472
- */
4473
- const onChannelMessageUnpinned = (callback) => {
4474
- if (callbacks$7.length === 0) {
4475
- const client = getActiveClient();
4476
- const filter = (payload) => {
4477
- const channel = findCachedChannelForPin(payload);
4478
- if (!channel)
4479
- return;
4480
- const updated = updatePinnedMessageCache(channel, null);
4481
- callbacks$7.forEach(cb => cb(updated));
4482
- };
4483
- mainDisposer$7 = createEventSubscriber(client, 'onChannelMessageUnpinned', 'channel.messageUnpinned', filter);
4337
+ mainDisposer$7 = createEventSubscriber(client, 'onChannelMute', 'channel.setMuted', filter);
4484
4338
  }
4485
4339
  callbacks$7.push(callback);
4486
4340
  return () => dispose$7(callback);
4487
4341
  };
4488
- /* end_public_function */
4489
4342
 
4490
4343
  const callbacks$6 = [];
4491
4344
  let mainDisposer$6 = null;
@@ -7881,21 +7734,19 @@ const renewal = () => {
7881
7734
 
7882
7735
  const validateAccessToken = async ({ token, userId }) => {
7883
7736
  const client = getActiveClient();
7884
- // Verify the token and hydrate the caller in a single call.
7885
- const { data } = await client.http.get('/api/v4/sessions', {
7737
+ // Validate token using sessions API
7738
+ await client.http.get('/api/v3/sessions', {
7886
7739
  headers: {
7887
7740
  Authorization: `Bearer ${token.accessToken}`,
7888
7741
  },
7889
7742
  });
7890
- const { users, files, userType } = data;
7891
- const [user] = users;
7892
- if (userId && (user === null || user === void 0 ? void 0 : user.userId) && userId !== user.userId) {
7893
- client.log('client/api/validateAccessToken', {
7894
- message: 'session userId does not match the token userId; using the server value',
7895
- tokenUserId: userId,
7896
- sessionUserId: user.userId,
7897
- });
7898
- }
7743
+ // Get user details
7744
+ const { data: { users }, } = await client.http.get(`/api/v3/users/${userId}`, {
7745
+ headers: {
7746
+ Authorization: `Bearer ${token.accessToken}`,
7747
+ },
7748
+ });
7749
+ const user = users.find((u) => u.userId === userId);
7899
7750
  client.http.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
7900
7751
  client.http.defaults.metadata = {
7901
7752
  tokenExpiry: token.expiresAt,
@@ -7909,8 +7760,6 @@ const validateAccessToken = async ({ token, userId }) => {
7909
7760
  isUserDeleted: false,
7910
7761
  };
7911
7762
  client.token = token;
7912
- ingestInCache(prepareUserPayload({ users, files }));
7913
- setCurrentUserType(userType);
7914
7763
  return user;
7915
7764
  };
7916
7765
 
@@ -7993,6 +7842,14 @@ const loginWithAccessToken = async (accessToken) => {
7993
7842
  setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
7994
7843
  throw new ASCError(`User ${userId} has not been found`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
7995
7844
  }
7845
+ if (user.isDeleted) {
7846
+ setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
7847
+ throw new ASCError(`User ${userId} has been deleted`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
7848
+ }
7849
+ if (user.isGlobalBanned) {
7850
+ setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
7851
+ throw new ASCError(`User ${userId} is globally banned`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
7852
+ }
7996
7853
  // Set userId and login method flag
7997
7854
  client.userId = user.userId;
7998
7855
  // Set login method flag to 'accessToken' in platform-specific login session
@@ -8791,13 +8648,21 @@ const resumeSession = async (params, sessionHandler, config) => {
8791
8648
  if (user == null) {
8792
8649
  throw new ASCError(`${params.userId} has not been found`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
8793
8650
  }
8651
+ if (user.isDeleted) {
8652
+ terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
8653
+ return false;
8654
+ }
8655
+ if (user.isGlobalBanned) {
8656
+ terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
8657
+ return false;
8658
+ }
8794
8659
  client.userId = user.userId;
8795
8660
  client.sessionHandler = sessionHandler;
8796
8661
  /*
8797
8662
  * Cannot push to subscriptions as watcher needs to continue working even if
8798
8663
  * token expires
8799
8664
  */
8800
- unsubWatcher = client.accessTokenExpiryWatcher();
8665
+ unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
8801
8666
  setActiveUser(user);
8802
8667
  }
8803
8668
  catch (error) {
@@ -18391,20 +18256,20 @@ const getArchivedChannelIds = async () => {
18391
18256
 
18392
18257
  /**
18393
18258
  * ```js
18394
- * import { onMessageDeleted } from '@amityco/ts-sdk'
18395
- * const dispose = onMessageDeleted(message => {
18259
+ * import { onMessageUpdated } from '@amityco/ts-sdk'
18260
+ * const dispose = onMessageUpdated(message => {
18396
18261
  * // ...
18397
18262
  * })
18398
18263
  * ```
18399
18264
  *
18400
- * Fired when an {@link Amity.Message} was deleted
18265
+ * Fired when an {@link Amity.Message} has been updated
18401
18266
  *
18402
18267
  * @param callback The function to call when the event was fired
18403
18268
  * @returns an {@link Amity.Unsubscriber} function to stop listening
18404
18269
  *
18405
18270
  * @category Message Events
18406
18271
  */
18407
- const onMessageDeleted = (callback) => {
18272
+ const onMessageUpdated = (callback) => {
18408
18273
  const client = getActiveClient();
18409
18274
  const filter = async (rawPayload) => {
18410
18275
  const payload = await prepareMessagePayload(rawPayload);
@@ -18412,48 +18277,30 @@ const onMessageDeleted = (callback) => {
18412
18277
  callback(payload.messages[0]);
18413
18278
  };
18414
18279
  const disposers = [
18415
- createEventSubscriber(client, 'message/onMessageDeleted', 'message.deleted', filter),
18416
- createEventSubscriber(client, 'message/onMessageDeleted', 'local.message.deleted', payload => callback(payload.messages[0])),
18280
+ createEventSubscriber(client, 'onMessageUpdated', 'message.updated', filter),
18281
+ createEventSubscriber(client, 'onMessageUpdated', 'local.message.updated', payload => callback(payload.messages[0])),
18417
18282
  ];
18418
18283
  return () => {
18419
18284
  disposers.forEach(fn => fn());
18420
18285
  };
18421
18286
  };
18422
18287
 
18423
- /**
18424
- * Defensive clear of `channel.pinnedMessage` when the pinned message itself is deleted.
18425
- *
18426
- * The server also emits `channel.messageUnpinned` in this case, but realtime events are
18427
- * fire-and-forget and their order is not guaranteed. Clearing on `message.deleted`
18428
- * (MQTT or local) makes the banner disappear even if the unpin event is lost; the
18429
- * server's own `messageUnpinned` then becomes a no-op.
18430
- *
18431
- * Internal — wired into the `getChannel` live object; not exported publicly.
18432
- */
18433
- const onChannelPinnedMessageDeleted = (callback) => onMessageDeleted(message => {
18434
- var _a;
18435
- const channel = findCachedChannelByAnyId(message.channelId);
18436
- if (!channel || ((_a = channel.pinnedMessage) === null || _a === void 0 ? void 0 : _a.messageId) !== message.messageId)
18437
- return;
18438
- callback(updatePinnedMessageCache(channel, null));
18439
- });
18440
-
18441
18288
  /**
18442
18289
  * ```js
18443
- * import { onMessageUpdated } from '@amityco/ts-sdk'
18444
- * const dispose = onMessageUpdated(message => {
18290
+ * import { onMessageDeleted } from '@amityco/ts-sdk'
18291
+ * const dispose = onMessageDeleted(message => {
18445
18292
  * // ...
18446
18293
  * })
18447
18294
  * ```
18448
18295
  *
18449
- * Fired when an {@link Amity.Message} has been updated
18296
+ * Fired when an {@link Amity.Message} was deleted
18450
18297
  *
18451
18298
  * @param callback The function to call when the event was fired
18452
18299
  * @returns an {@link Amity.Unsubscriber} function to stop listening
18453
18300
  *
18454
18301
  * @category Message Events
18455
18302
  */
18456
- const onMessageUpdated = (callback) => {
18303
+ const onMessageDeleted = (callback) => {
18457
18304
  const client = getActiveClient();
18458
18305
  const filter = async (rawPayload) => {
18459
18306
  const payload = await prepareMessagePayload(rawPayload);
@@ -18461,8 +18308,8 @@ const onMessageUpdated = (callback) => {
18461
18308
  callback(payload.messages[0]);
18462
18309
  };
18463
18310
  const disposers = [
18464
- createEventSubscriber(client, 'onMessageUpdated', 'message.updated', filter),
18465
- createEventSubscriber(client, 'onMessageUpdated', 'local.message.updated', payload => callback(payload.messages[0])),
18311
+ createEventSubscriber(client, 'message/onMessageDeleted', 'message.deleted', filter),
18312
+ createEventSubscriber(client, 'message/onMessageDeleted', 'local.message.deleted', payload => callback(payload.messages[0])),
18466
18313
  ];
18467
18314
  return () => {
18468
18315
  disposers.forEach(fn => fn());
@@ -19043,132 +18890,6 @@ softDeleteMessage.optimistically = (messageId) => {
19043
18890
  };
19044
18891
  /* end_public_function */
19045
18892
 
19046
- /**
19047
- * Fire-and-forget refresh of `channelUsers[...].permissions` for the channel a
19048
- * message belongs to. Used by `pinMessage` / `unpinMessage` on `403` so the next
19049
- * `hasPermission(PIN_MESSAGE).channel(channelId)` reflects a revoked role
19050
- * ([`pinMessage` REQ-010](../../@types/../..) / [`unpinMessage` REQ-008](../../@types/../..)).
19051
- *
19052
- * The API only receives a `messageId`, so the channel is resolved through the
19053
- * local cache: first the message row, then any cached channel whose current pin
19054
- * is that message. When nothing matches the refresh is skipped — the next
19055
- * channel read picks up the fresh permissions anyway.
19056
- */
19057
- const refreshChannelPermissionsForMessage = (messageId) => {
19058
- var _a, _b, _c;
19059
- const cachedMessage = (_a = getMessage$1.locally(messageId)) === null || _a === void 0 ? void 0 : _a.data;
19060
- let channelId = cachedMessage === null || cachedMessage === void 0 ? void 0 : cachedMessage.channelId;
19061
- if (!channelId) {
19062
- channelId = (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => { var _a; return ((_a = data.pinnedMessage) === null || _a === void 0 ? void 0 : _a.messageId) === messageId; })) === null || _c === void 0 ? void 0 : _c.data.channelId;
19063
- }
19064
- if (!channelId)
19065
- return;
19066
- getChannel$1(channelId).catch(() => {
19067
- /* silent per spec; UIKit renders no error toast */
19068
- });
19069
- };
19070
-
19071
- /* begin_public_function
19072
- id: message.pin
19073
- */
19074
- /**
19075
- * ```js
19076
- * import { MessageRepository } from '@amityco/ts-sdk'
19077
- * const channel = await MessageRepository.pinMessage(messageId)
19078
- * console.log(channel.pinnedMessage)
19079
- * ```
19080
- *
19081
- * Pins a {@link Amity.Message} in its livestream (`live`) channel. A channel holds at
19082
- * most one pinned message: pinning a different message replaces the current pin in a
19083
- * single step — no unpin is needed first. Pinning the message that is already pinned is
19084
- * rejected by the server (400).
19085
- *
19086
- * The caller must hold the `PIN_MESSAGE` permission in the channel (or be an admin with
19087
- * `ModerateChannel`). The server also rejects pinning a deleted message, a message whose
19088
- * author is banned from the channel or globally banned, and pinning in any channel type
19089
- * other than `live`. On any error the pin state is left unchanged.
19090
- *
19091
- * The response is the affected channel; it is ingested into cache and fires
19092
- * `local.channel.updated`, so `ChannelRepository.getChannel` observers update without
19093
- * waiting for the `channel.messagePinned` realtime event.
19094
- *
19095
- * @param messageId the **internal** ID of the {@link Amity.Message} to pin
19096
- * @returns the updated {@link Amity.Channel}, with `pinnedMessage` set
19097
- *
19098
- * @category Message API
19099
- * @async
19100
- */
19101
- const pinMessage = async (messageId) => {
19102
- const client = getActiveClient();
19103
- client.log('message/pinMessage', messageId);
19104
- let payload;
19105
- try {
19106
- ({ data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/pin`));
19107
- }
19108
- catch (error) {
19109
- if ((error === null || error === void 0 ? void 0 : error.code) === 400301 /* Amity.ServerError.PERMISSION_DENIED */) {
19110
- refreshChannelPermissionsForMessage(messageId);
19111
- }
19112
- throw error;
19113
- }
19114
- const data = await prepareChannelPayload(payload);
19115
- if (client.cache)
19116
- ingestInCache(data);
19117
- fireEvent('local.channel.updated', data);
19118
- return constructChannelObject(data.channels[0]);
19119
- };
19120
- /* end_public_function */
19121
-
19122
- /* begin_public_function
19123
- id: message.unpin
19124
- */
19125
- /**
19126
- * ```js
19127
- * import { MessageRepository } from '@amityco/ts-sdk'
19128
- * const channel = await MessageRepository.unpinMessage(messageId)
19129
- * console.log(channel.pinnedMessage) // null
19130
- * ```
19131
- *
19132
- * Removes the pin from a {@link Amity.Message}. `messageId` must be the message that is
19133
- * **currently** pinned in its channel; otherwise the server answers 400 — this is
19134
- * deliberate, so a stale client cannot clear a pin that someone else has since replaced.
19135
- * On that error, re-read the channel (or rely on the `channel.messagePinned` event) to
19136
- * get the current pin.
19137
- *
19138
- * The caller must hold the `PIN_MESSAGE` permission in the channel (or be an admin with
19139
- * `ModerateChannel`). Unpinning is allowed regardless of channel type and stream state.
19140
- *
19141
- * The response is the affected channel; it is ingested into cache and fires
19142
- * `local.channel.updated`, so `ChannelRepository.getChannel` observers update without
19143
- * waiting for the `channel.messageUnpinned` realtime event.
19144
- *
19145
- * @param messageId the **internal** ID of the currently pinned {@link Amity.Message}
19146
- * @returns the updated {@link Amity.Channel}, with `pinnedMessage` cleared
19147
- *
19148
- * @category Message API
19149
- * @async
19150
- */
19151
- const unpinMessage = async (messageId) => {
19152
- const client = getActiveClient();
19153
- client.log('message/unpinMessage', messageId);
19154
- let payload;
19155
- try {
19156
- ({ data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}/pin`));
19157
- }
19158
- catch (error) {
19159
- if ((error === null || error === void 0 ? void 0 : error.code) === 400301 /* Amity.ServerError.PERMISSION_DENIED */) {
19160
- refreshChannelPermissionsForMessage(messageId);
19161
- }
19162
- throw error;
19163
- }
19164
- const data = await prepareChannelPayload(payload);
19165
- if (client.cache)
19166
- ingestInCache(data);
19167
- fireEvent('local.channel.updated', data);
19168
- return constructChannelObject(data.channels[0]);
19169
- };
19170
- /* end_public_function */
19171
-
19172
18893
  /**
19173
18894
  * ```js
19174
18895
  * import { MessageRepository } from '@amityco/ts-sdk'
@@ -20072,8 +19793,6 @@ var index$n = /*#__PURE__*/Object.freeze({
20072
19793
  editMessage: editMessage,
20073
19794
  deleteMessage: deleteMessage,
20074
19795
  softDeleteMessage: softDeleteMessage,
20075
- pinMessage: pinMessage,
20076
- unpinMessage: unpinMessage,
20077
19796
  markAsDelivered: markAsDelivered,
20078
19797
  getReadUsers: getReadUsers,
20079
19798
  getDeliveredUsers: getDeliveredUsers,
@@ -20711,9 +20430,6 @@ const getChannel = (channelId, callback) => {
20711
20430
  onChannelMemberBanned,
20712
20431
  onChannelMemberUnbanned,
20713
20432
  onChannelSetMuted,
20714
- onChannelMessagePinned,
20715
- onChannelMessageUnpinned,
20716
- onChannelPinnedMessageDeleted,
20717
20433
  convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
20718
20434
  convertEventPayload(onChannelMarkerUpdated, 'entityId', 'channel'),
20719
20435
  convertEventPayload((callback) => {
@@ -22810,8 +22526,6 @@ var index$j = /*#__PURE__*/Object.freeze({
22810
22526
  onChannelJoined: onChannelJoined,
22811
22527
  onChannelLeft: onChannelLeft,
22812
22528
  onChannelSetMuted: onChannelSetMuted,
22813
- onChannelMessagePinned: onChannelMessagePinned,
22814
- onChannelMessageUnpinned: onChannelMessageUnpinned,
22815
22529
  onChannelMemberAdded: onChannelMemberAdded,
22816
22530
  onChannelMemberRemoved: onChannelMemberRemoved,
22817
22531
  onChannelMemberBanned: onChannelMemberBanned,
@@ -22829,10 +22543,7 @@ var index$j = /*#__PURE__*/Object.freeze({
22829
22543
  isUnreadCountSupport: isUnreadCountSupport,
22830
22544
  convertFromRaw: convertFromRaw,
22831
22545
  preUpdateChannelCache: preUpdateChannelCache,
22832
- prepareChannelPayload: prepareChannelPayload,
22833
- findCachedChannelByAnyId: findCachedChannelByAnyId,
22834
- findCachedChannelForPin: findCachedChannelForPin,
22835
- updatePinnedMessageCache: updatePinnedMessageCache
22546
+ prepareChannelPayload: prepareChannelPayload
22836
22547
  });
22837
22548
 
22838
22549
  const saveCommunityUsers = (communities, communityUsers) => {