@amityco/ts-sdk 6.5.7-d7d687d.0 → 6.5.7-e5b9646.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.
@@ -1 +1 @@
1
- {"version":3,"file":"markerSyncEngine.d.ts","sourceRoot":"","sources":["../../../src/client/utils/markerSyncEngine.ts"],"names":[],"mappings":"AAmDA;;;GAGG;AACH,eAAO,MAAM,mBAAmB,+BAAe,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,cAAe,MAAM,eAAe,EAAE,SAErE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,UAAW,MAAM,eAAe,WAAuB,CAAC;AAExF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,qBA4B7B,CAAC;AA2DF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qBAiB3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAK1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAI7B,CAAC"}
1
+ {"version":3,"file":"markerSyncEngine.d.ts","sourceRoot":"","sources":["../../../src/client/utils/markerSyncEngine.ts"],"names":[],"mappings":"AAoDA;;;GAGG;AACH,eAAO,MAAM,mBAAmB,+BAAe,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,cAAe,MAAM,eAAe,EAAE,SAErE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,UAAW,MAAM,eAAe,WAAuB,CAAC;AAExF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,qBA4B7B,CAAC;AAkDF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qBAiB3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAK1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAI7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const onOnline: (callback: () => void) => any;
2
+ //# sourceMappingURL=onOnline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onOnline.d.ts","sourceRoot":"","sources":["../../../src/client/utils/onOnline.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,aAAc,MAAM,IAAI,QAyB5C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"paging.d.ts","sourceRoot":"","sources":["../../../src/core/query/paging.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,SAAU,OAAO,MAAM,EAAE,OAAO,CAAC,sCACf,CAAC;AAEtC;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,SAAU,OAAO,MAAM,EAAE,OAAO,CAAC,wCACe,CAAC;AAE3E;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,SACrB,OAAO,MAAM,EAAE,OAAO,CAAC,0BAC6B,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,+BAAgC,GAAG,mCAMtD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,WACV,MAAM,IAAI,GAAG,MAAM,OAAO,GAAG,SAAS,SACvC,MAAM,gBAAgB,KAC5B,MAAM,KAAK,GAAG,SA0ChB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,WAAY,MAAM,KAAK,KAAG,MAAM,IAAI,GAAG,SA6BzD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,WAAY,MAAM,KAAK,KAAG,MAAM,OAAO,GAAG,SAW/D,CAAC"}
1
+ {"version":3,"file":"paging.d.ts","sourceRoot":"","sources":["../../../src/core/query/paging.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,SAAU,OAAO,MAAM,EAAE,OAAO,CAAC,sCACf,CAAC;AAEtC;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,SAAU,OAAO,MAAM,EAAE,OAAO,CAAC,wCACe,CAAC;AAE3E;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,SACrB,OAAO,MAAM,EAAE,OAAO,CAAC,0BAC6B,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,+BAAgC,GAAG,mCAMtD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,WACV,MAAM,IAAI,GAAG,MAAM,OAAO,GAAG,SAAS,SACvC,MAAM,gBAAgB,KAC5B,MAAM,KAAK,GAAG,SA6ChB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,WAAY,MAAM,KAAK,KAAG,MAAM,IAAI,GAAG,SA6BzD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,WAAY,MAAM,KAAK,KAAG,MAAM,OAAO,GAAG,SAW/D,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -256,22 +256,14 @@ const toToken = (paging, style) => {
256
256
  "before" or "after" value. if that would change,
257
257
  we'd need to move toward a more simple: `!paging.before`
258
258
  */
259
- if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.before))) {
260
- payload = {
261
- before: paging.before,
262
- last: paging.limit,
263
- };
259
+ if (paging === null || paging === void 0 ? void 0 : paging.before) {
260
+ payload = Object.assign(Object.assign({}, payload), { before: paging.before });
264
261
  }
265
- else if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.after))) {
266
- payload = {
267
- after: paging.after,
268
- first: paging.limit,
269
- };
262
+ if (paging === null || paging === void 0 ? void 0 : paging.after) {
263
+ payload = Object.assign(Object.assign({}, payload), { after: paging.after });
270
264
  }
271
- else if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.limit))) {
272
- payload = {
273
- last: paging.limit,
274
- };
265
+ if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.limit))) {
266
+ payload = Object.assign(Object.assign({}, payload), { limit: paging.limit });
275
267
  }
276
268
  }
277
269
  else if (style === 'afterbeforeraw') {
@@ -21009,6 +21001,30 @@ const setIntervalTask = (handler, timeout) => {
21009
21001
  return () => clearInterval(timer);
21010
21002
  };
21011
21003
 
21004
+ const onOnline = (callback) => {
21005
+ if (typeof window !== 'undefined' && window.addEventListener) {
21006
+ window.addEventListener('online', callback);
21007
+ return () => window.removeEventListener('online', callback);
21008
+ }
21009
+ if (typeof document !== 'undefined' && document.addEventListener) {
21010
+ document.addEventListener('online', callback);
21011
+ return () => document.removeEventListener('online', callback);
21012
+ }
21013
+ // @TODO: Please update code below to follow our coding conventions and our TS rules
21014
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
21015
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
21016
+ const NetInfo = require('@react-native-community/netinfo');
21017
+ return NetInfo.addEventListener((state) => {
21018
+ if (!state.isConnected)
21019
+ return;
21020
+ callback();
21021
+ });
21022
+ }
21023
+ // Handle unsupported environment
21024
+ console.error('Unsupported environment');
21025
+ return () => console.error('Unsupported environment');
21026
+ };
21027
+
21012
21028
  /**
21013
21029
  * ```js
21014
21030
  * import { isInTombstone } from '@amityco/ts-sdk'
@@ -21569,17 +21585,6 @@ const markReadEngineOnLoginHandler = () => {
21569
21585
  stopIntervalTask();
21570
21586
  };
21571
21587
  };
21572
- /**
21573
- * the event callback when app is back to online
21574
- */
21575
- const onOnline$1 = () => {
21576
- const callback = () => {
21577
- // Start reading the reading subChannel again when resume from offline state
21578
- startReadingFromReadingList();
21579
- };
21580
- window.addEventListener('online', callback);
21581
- return () => window.removeEventListener('online', callback);
21582
- };
21583
21588
  const getParentChannelId = async (subChannelId) => {
21584
21589
  const cached = getSubChannel$1.locally(subChannelId);
21585
21590
  if (cached) {
@@ -21589,7 +21594,10 @@ const getParentChannelId = async (subChannelId) => {
21589
21594
  return data.channelId;
21590
21595
  };
21591
21596
  const registerEventListeners$1 = () => {
21592
- disposers$1.push(onOnline$1());
21597
+ disposers$1.push(onOnline(() => {
21598
+ // Start reading the reading subChannel again when resume from offline state
21599
+ startReadingFromReadingList();
21600
+ }));
21593
21601
  };
21594
21602
  const registerTopicSubscribers = async (subChannelId) => {
21595
21603
  const channelId = await getParentChannelId(subChannelId);
@@ -24021,13 +24029,7 @@ const onMessageCreated = (callback, local = true) => {
24021
24029
  const filter = async (rawPayload) => {
24022
24030
  const payload = await prepareMessagePayload(rawPayload);
24023
24031
  const message = payload.messages[0];
24024
- // Update in cache
24025
24032
  ingestInCache(payload);
24026
- // Update lastActivity for Channel and SubChannel
24027
- payload.messages.forEach(({ channelId, subChannelId, createdAt }) => {
24028
- upsertInCache(['channel', 'get', channelId], { lastActivityAt: createdAt });
24029
- upsertInCache(['subChannel', 'get', channelId], { lastActivityAt: createdAt });
24030
- });
24031
24033
  callback(message);
24032
24034
  };
24033
24035
  const disposers = [
@@ -24411,22 +24413,16 @@ const markerSyncTrigger = async () => {
24411
24413
  // eslint-disable-next-line require-atomic-updates
24412
24414
  isWaitingForResponse = false;
24413
24415
  };
24414
- /**
24415
- * the event callback when app is back to online
24416
- */
24417
- const onOnline = () => {
24418
- // should add RESUME to the event to trigger marker syncing again
24419
- const callback = () => events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
24420
- window.addEventListener('online', callback);
24421
- return () => window.removeEventListener('online', callback);
24422
- };
24423
24416
  const registerEventListeners = () => {
24424
24417
  // based on the tech spec design, we designed a fetch marker in case of these events
24425
24418
  // - new message
24426
24419
  // - create channel
24427
24420
  // - remove channel
24428
24421
  // - app going to online again after offline
24429
- disposers.push(onOnline(), onMessageCreated(message => {
24422
+ disposers.push(onOnline(() => {
24423
+ // should add RESUME to the event to trigger marker syncing again
24424
+ events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
24425
+ }), onMessageCreated(message => {
24430
24426
  // only conversation, community and broadcast types can sync
24431
24427
  if (isUnreadCountSupport(message))
24432
24428
  events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
@@ -29035,7 +29031,9 @@ const getMessages = (params, callback, config) => {
29035
29031
  const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29036
29032
  if (params.subChannelId !== (message === null || message === void 0 ? void 0 : message.subChannelId) || !collection)
29037
29033
  return;
29038
- collection.data = [...new Set([message.messageId, ...collection.data])];
29034
+ if (!collection.data.includes(message.messageId)) {
29035
+ collection.data = [...new Set([message.messageId, ...collection.data])];
29036
+ }
29039
29037
  pushToCache(cacheKey, collection);
29040
29038
  responder(collection);
29041
29039
  };
@@ -29479,7 +29477,7 @@ const querySubChannels = async (query) => {
29479
29477
  const _a = convertQueryParams(query), { page = { limit: 10 }, channelId, includeDeleted } = _a, params = __rest(_a, ["page", "channelId", "includeDeleted"]);
29480
29478
  const response = await client.http.get(`/api/v5/message-feeds/channel/${channelId}`, {
29481
29479
  params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options: {
29482
- token: toToken(page, 'skiplimit'),
29480
+ token: toToken(page, 'afterbefore'),
29483
29481
  } }),
29484
29482
  });
29485
29483
  const _b = response.data, { paging } = _b, payload = __rest(_b, ["paging"]);
@@ -29603,12 +29601,11 @@ const getSubChannels = (params, callback, config) => {
29603
29601
  responder(snapshot);
29604
29602
  };
29605
29603
  const onFetch = () => {
29606
- var _a;
29607
29604
  const subChannels = snapshot ? snapshot.data : [];
29608
29605
  if (subChannels.length > 0 && !(snapshot === null || snapshot === void 0 ? void 0 : snapshot.params.page)) {
29609
29606
  return;
29610
29607
  }
29611
- const query = createQuery(querySubChannels, Object.assign(Object.assign({}, queryParams), { page: (_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.params.page) !== null && _a !== void 0 ? _a : { limit } }));
29608
+ const query = createQuery(querySubChannels, Object.assign(Object.assign({}, queryParams), { page: (snapshot === null || snapshot === void 0 ? void 0 : snapshot.params.page) ? Object.assign(Object.assign({}, snapshot === null || snapshot === void 0 ? void 0 : snapshot.params.page), { limit }) : { limit } }));
29612
29609
  runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
29613
29610
  snapshot = {
29614
29611
  loading,
package/dist/index.esm.js CHANGED
@@ -242,22 +242,14 @@ const toToken = (paging, style) => {
242
242
  "before" or "after" value. if that would change,
243
243
  we'd need to move toward a more simple: `!paging.before`
244
244
  */
245
- if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.before))) {
246
- payload = {
247
- before: paging.before,
248
- last: paging.limit,
249
- };
245
+ if (paging === null || paging === void 0 ? void 0 : paging.before) {
246
+ payload = Object.assign(Object.assign({}, payload), { before: paging.before });
250
247
  }
251
- else if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.after))) {
252
- payload = {
253
- after: paging.after,
254
- first: paging.limit,
255
- };
248
+ if (paging === null || paging === void 0 ? void 0 : paging.after) {
249
+ payload = Object.assign(Object.assign({}, payload), { after: paging.after });
256
250
  }
257
- else if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.limit))) {
258
- payload = {
259
- last: paging.limit,
260
- };
251
+ if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.limit))) {
252
+ payload = Object.assign(Object.assign({}, payload), { limit: paging.limit });
261
253
  }
262
254
  }
263
255
  else if (style === 'afterbeforeraw') {
@@ -20995,6 +20987,30 @@ const setIntervalTask = (handler, timeout) => {
20995
20987
  return () => clearInterval(timer);
20996
20988
  };
20997
20989
 
20990
+ const onOnline = (callback) => {
20991
+ if (typeof window !== 'undefined' && window.addEventListener) {
20992
+ window.addEventListener('online', callback);
20993
+ return () => window.removeEventListener('online', callback);
20994
+ }
20995
+ if (typeof document !== 'undefined' && document.addEventListener) {
20996
+ document.addEventListener('online', callback);
20997
+ return () => document.removeEventListener('online', callback);
20998
+ }
20999
+ // @TODO: Please update code below to follow our coding conventions and our TS rules
21000
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
21001
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
21002
+ const NetInfo = require('@react-native-community/netinfo');
21003
+ return NetInfo.addEventListener((state) => {
21004
+ if (!state.isConnected)
21005
+ return;
21006
+ callback();
21007
+ });
21008
+ }
21009
+ // Handle unsupported environment
21010
+ console.error('Unsupported environment');
21011
+ return () => console.error('Unsupported environment');
21012
+ };
21013
+
20998
21014
  /**
20999
21015
  * ```js
21000
21016
  * import { isInTombstone } from '@amityco/ts-sdk'
@@ -21555,17 +21571,6 @@ const markReadEngineOnLoginHandler = () => {
21555
21571
  stopIntervalTask();
21556
21572
  };
21557
21573
  };
21558
- /**
21559
- * the event callback when app is back to online
21560
- */
21561
- const onOnline$1 = () => {
21562
- const callback = () => {
21563
- // Start reading the reading subChannel again when resume from offline state
21564
- startReadingFromReadingList();
21565
- };
21566
- window.addEventListener('online', callback);
21567
- return () => window.removeEventListener('online', callback);
21568
- };
21569
21574
  const getParentChannelId = async (subChannelId) => {
21570
21575
  const cached = getSubChannel$1.locally(subChannelId);
21571
21576
  if (cached) {
@@ -21575,7 +21580,10 @@ const getParentChannelId = async (subChannelId) => {
21575
21580
  return data.channelId;
21576
21581
  };
21577
21582
  const registerEventListeners$1 = () => {
21578
- disposers$1.push(onOnline$1());
21583
+ disposers$1.push(onOnline(() => {
21584
+ // Start reading the reading subChannel again when resume from offline state
21585
+ startReadingFromReadingList();
21586
+ }));
21579
21587
  };
21580
21588
  const registerTopicSubscribers = async (subChannelId) => {
21581
21589
  const channelId = await getParentChannelId(subChannelId);
@@ -24007,13 +24015,7 @@ const onMessageCreated = (callback, local = true) => {
24007
24015
  const filter = async (rawPayload) => {
24008
24016
  const payload = await prepareMessagePayload(rawPayload);
24009
24017
  const message = payload.messages[0];
24010
- // Update in cache
24011
24018
  ingestInCache(payload);
24012
- // Update lastActivity for Channel and SubChannel
24013
- payload.messages.forEach(({ channelId, subChannelId, createdAt }) => {
24014
- upsertInCache(['channel', 'get', channelId], { lastActivityAt: createdAt });
24015
- upsertInCache(['subChannel', 'get', channelId], { lastActivityAt: createdAt });
24016
- });
24017
24019
  callback(message);
24018
24020
  };
24019
24021
  const disposers = [
@@ -24397,22 +24399,16 @@ const markerSyncTrigger = async () => {
24397
24399
  // eslint-disable-next-line require-atomic-updates
24398
24400
  isWaitingForResponse = false;
24399
24401
  };
24400
- /**
24401
- * the event callback when app is back to online
24402
- */
24403
- const onOnline = () => {
24404
- // should add RESUME to the event to trigger marker syncing again
24405
- const callback = () => events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
24406
- window.addEventListener('online', callback);
24407
- return () => window.removeEventListener('online', callback);
24408
- };
24409
24402
  const registerEventListeners = () => {
24410
24403
  // based on the tech spec design, we designed a fetch marker in case of these events
24411
24404
  // - new message
24412
24405
  // - create channel
24413
24406
  // - remove channel
24414
24407
  // - app going to online again after offline
24415
- disposers.push(onOnline(), onMessageCreated(message => {
24408
+ disposers.push(onOnline(() => {
24409
+ // should add RESUME to the event to trigger marker syncing again
24410
+ events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
24411
+ }), onMessageCreated(message => {
24416
24412
  // only conversation, community and broadcast types can sync
24417
24413
  if (isUnreadCountSupport(message))
24418
24414
  events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
@@ -29021,7 +29017,9 @@ const getMessages = (params, callback, config) => {
29021
29017
  const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29022
29018
  if (params.subChannelId !== (message === null || message === void 0 ? void 0 : message.subChannelId) || !collection)
29023
29019
  return;
29024
- collection.data = [...new Set([message.messageId, ...collection.data])];
29020
+ if (!collection.data.includes(message.messageId)) {
29021
+ collection.data = [...new Set([message.messageId, ...collection.data])];
29022
+ }
29025
29023
  pushToCache(cacheKey, collection);
29026
29024
  responder(collection);
29027
29025
  };
@@ -29465,7 +29463,7 @@ const querySubChannels = async (query) => {
29465
29463
  const _a = convertQueryParams(query), { page = { limit: 10 }, channelId, includeDeleted } = _a, params = __rest(_a, ["page", "channelId", "includeDeleted"]);
29466
29464
  const response = await client.http.get(`/api/v5/message-feeds/channel/${channelId}`, {
29467
29465
  params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options: {
29468
- token: toToken(page, 'skiplimit'),
29466
+ token: toToken(page, 'afterbefore'),
29469
29467
  } }),
29470
29468
  });
29471
29469
  const _b = response.data, { paging } = _b, payload = __rest(_b, ["paging"]);
@@ -29589,12 +29587,11 @@ const getSubChannels = (params, callback, config) => {
29589
29587
  responder(snapshot);
29590
29588
  };
29591
29589
  const onFetch = () => {
29592
- var _a;
29593
29590
  const subChannels = snapshot ? snapshot.data : [];
29594
29591
  if (subChannels.length > 0 && !(snapshot === null || snapshot === void 0 ? void 0 : snapshot.params.page)) {
29595
29592
  return;
29596
29593
  }
29597
- const query = createQuery(querySubChannels, Object.assign(Object.assign({}, queryParams), { page: (_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.params.page) !== null && _a !== void 0 ? _a : { limit } }));
29594
+ const query = createQuery(querySubChannels, Object.assign(Object.assign({}, queryParams), { page: (snapshot === null || snapshot === void 0 ? void 0 : snapshot.params.page) ? Object.assign(Object.assign({}, snapshot === null || snapshot === void 0 ? void 0 : snapshot.params.page), { limit }) : { limit } }));
29598
29595
  runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
29599
29596
  snapshot = {
29600
29597
  loading,