qiscus-sdk-core 2.16.1 → 2.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -39,6 +39,7 @@ var __async = (__this, __arguments, generator) => {
39
39
  step((generator = generator.apply(__this, __arguments)).next());
40
40
  });
41
41
  };
42
+ const nanoid = require("nanoid");
42
43
  const request = require("superagent");
43
44
  const mitt = require("mitt");
44
45
  const is = require("./lib/is.js");
@@ -275,8 +276,16 @@ const _QiscusSDK = class _QiscusSDK {
275
276
  );
276
277
  this.extras = setterHelper(null, cfg.extras, configExtras);
277
278
  this.enableSync = setterHelper(null, cfg.enable_sync, this.enableSync);
278
- this.enableSyncEvent = setterHelper(null, cfg.enable_sync_event, this.enableSyncEvent);
279
- this._autoRefreshToken = setterHelper(null, cfg.auto_refresh_token, false);
279
+ this.enableSyncEvent = setterHelper(
280
+ null,
281
+ cfg.enable_sync_event,
282
+ this.enableSyncEvent
283
+ );
284
+ this._autoRefreshToken = setterHelper(
285
+ null,
286
+ cfg.auto_refresh_token,
287
+ false
288
+ );
280
289
  }).catch((err) => {
281
290
  this.logger("got error when trying to get app config", err);
282
291
  this.isConfigLoaded = true;
@@ -357,7 +366,7 @@ const _QiscusSDK = class _QiscusSDK {
357
366
  });
358
367
  this.syncAdapter = sync(() => this.HTTPAdapter, {
359
368
  syncInterval: () => this.syncInterval,
360
- getShouldSync: () => this._forceEnableSync && (this.isLogin && !this.realtimeAdapter.connected),
369
+ getShouldSync: () => this._forceEnableSync && this.isLogin && !this.realtimeAdapter.connected,
361
370
  syncOnConnect: () => this.syncOnConnect,
362
371
  lastCommentId: () => this.last_received_comment_id,
363
372
  statusLogin: () => this.isLogin,
@@ -573,7 +582,12 @@ const _QiscusSDK = class _QiscusSDK {
573
582
  this.userData.token = token;
574
583
  this.userData.refresh_token = refreshToken;
575
584
  this.userData.token_expires_at = expiredAt == null ? void 0 : expiredAt.toJSON();
576
- this.events.emit("token-refreshed", { token, refreshToken, expiredAt, oldToken });
585
+ this.events.emit("token-refreshed", {
586
+ token,
587
+ refreshToken,
588
+ expiredAt,
589
+ oldToken
590
+ });
577
591
  this.realtimeAdapter.unsusbcribeUserChannelByToken(oldToken);
578
592
  this.realtimeAdapter.subscribeUserChannelByToken(token);
579
593
  this._delayedSync();
@@ -1200,10 +1214,7 @@ const _QiscusSDK = class _QiscusSDK {
1200
1214
  );
1201
1215
  try {
1202
1216
  let res = yield sendComment();
1203
- res = yield this._hookAdapter.trigger(
1204
- hook.Hooks.MESSAGE_BEFORE_RECEIVED,
1205
- res
1206
- );
1217
+ res = yield this._hookAdapter.trigger(hook.Hooks.MESSAGE_BEFORE_RECEIVED, res);
1207
1218
  Object.assign(messageData, res);
1208
1219
  if (!self.selected) return Promise.resolve(messageData);
1209
1220
  messageData.markAsSent();
@@ -1213,14 +1224,28 @@ const _QiscusSDK = class _QiscusSDK {
1213
1224
  (_b = (_a = this.options).commentSentCallback) == null ? void 0 : _b.call(_a, { comment: messageData });
1214
1225
  self.events.emit("comment-sent", messageData);
1215
1226
  self.sortComments();
1216
- const commentIndex = self._pendingComments.findIndex((c) => c.unique_id === messageData.unique_id);
1227
+ const commentIndex = self._pendingComments.findIndex(
1228
+ (c) => c.unique_id === messageData.unique_id
1229
+ );
1217
1230
  if (commentIndex > -1) {
1218
1231
  self._pendingComments.splice(commentIndex, 1);
1219
1232
  }
1220
1233
  return messageData;
1221
1234
  } catch (error) {
1222
1235
  messageData.markAsFailed();
1223
- const whitelistedErrorStatus = [void 0, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524];
1236
+ const whitelistedErrorStatus = [
1237
+ void 0,
1238
+ 408,
1239
+ 413,
1240
+ 429,
1241
+ 500,
1242
+ 502,
1243
+ 503,
1244
+ 504,
1245
+ 521,
1246
+ 522,
1247
+ 524
1248
+ ];
1224
1249
  const message = (_d = (_c = error.message) == null ? void 0 : _c.toLowerCase()) != null ? _d : "";
1225
1250
  const isOffline = message.includes("offline");
1226
1251
  if (whitelistedErrorStatus.includes(error.status) || isOffline) {
@@ -1241,7 +1266,9 @@ const _QiscusSDK = class _QiscusSDK {
1241
1266
  `Exceeding maximum retry count for comment ${comment.unique_id}, not retrying anymore`
1242
1267
  );
1243
1268
  (_c = (_b = this.options).commentRetryExceedCallback) == null ? void 0 : _c.call(_b, comment);
1244
- const index = this._pendingComments.findIndex((c) => c.unique_id === comment.unique_id);
1269
+ const index = this._pendingComments.findIndex(
1270
+ (c) => c.unique_id === comment.unique_id
1271
+ );
1245
1272
  if (index > -1) {
1246
1273
  this._pendingComments.splice(index, 1);
1247
1274
  }
@@ -1275,7 +1302,9 @@ const _QiscusSDK = class _QiscusSDK {
1275
1302
  this.sortComments();
1276
1303
  (_d = (_c2 = this.options).commentSentCallback) == null ? void 0 : _d.call(_c2, { comment });
1277
1304
  this.events.emit("comment-sent", comment);
1278
- const commentIndex = this._pendingComments.findIndex((c) => c.unique_id === comment.unique_id);
1305
+ const commentIndex = this._pendingComments.findIndex(
1306
+ (c) => c.unique_id === comment.unique_id
1307
+ );
1279
1308
  if (commentIndex > -1) {
1280
1309
  this._pendingComments.splice(commentIndex, 1);
1281
1310
  }
@@ -1343,9 +1372,8 @@ const _QiscusSDK = class _QiscusSDK {
1343
1372
  );
1344
1373
  }
1345
1374
  prepareCommentToBeSubmitted(comment) {
1346
- var commentToBeSubmitted, uniqueId;
1347
- commentToBeSubmitted = new Comment(comment);
1348
- uniqueId = "bq" + Date.now();
1375
+ let commentToBeSubmitted = new Comment(comment);
1376
+ let uniqueId = `javascript-${nanoid.nanoid()}`;
1349
1377
  if (comment.unique_id) uniqueId = comment.unique_id;
1350
1378
  commentToBeSubmitted.attachUniqueId(uniqueId);
1351
1379
  commentToBeSubmitted.markAsPending();
@@ -1849,7 +1877,7 @@ const _QiscusSDK = class _QiscusSDK {
1849
1877
  });
1850
1878
  }
1851
1879
  _generateUniqueId() {
1852
- return `javascript-${Date.now()}`;
1880
+ return `javascript-${nanoid.nanoid()}`;
1853
1881
  }
1854
1882
  generateMessage({ roomId, text, extras }) {
1855
1883
  const id = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qiscus-sdk-core",
3
- "version": "2.16.1",
3
+ "version": "2.16.2",
4
4
  "description": "Qiscus Web SDK Core",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -10,6 +10,22 @@
10
10
  "lib",
11
11
  "dist"
12
12
  ],
13
+ "scripts": {
14
+ "build": "npm-run-all clean --parallel build:lib build:dist",
15
+ "build:lib": "cross-env BUILD=lib vite build",
16
+ "build:dist": "npm-run-all build:dist:dev build:dist:min",
17
+ "build:dist:dev": "cross-env BUILD=dist MINIFY=false vite build",
18
+ "build:dist:min": "cross-env BUILD=dist MINIFY=true vite build",
19
+ "build:matrix": "bash scripts/build-matrix.sh",
20
+ "dev": "cross-env BUILD=dist MINIFY=false vite build --watch",
21
+ "test": "mocha --require esbuild-register --colors 'test/**/*test.js'",
22
+ "test:watch": "npm run test -- -w",
23
+ "clean": "rimraf dist lib",
24
+ "preversion": "npm-run-all clean build",
25
+ "prepublishOnly": "npm-run-all clean build",
26
+ "serve": "http-server -p 1234 -c-1 dist",
27
+ "release:patch": "np patch --any-branch --yolo"
28
+ },
13
29
  "devDependencies": {
14
30
  "@commitlint/cli": "^8.3.5",
15
31
  "@commitlint/config-conventional": "^8.3.4",
@@ -39,6 +55,7 @@
39
55
  "lodash.throttle": "^4.1.1",
40
56
  "mitt": "^1.2.0",
41
57
  "mqtt": "~4.2.6",
58
+ "nanoid": "^5.1.16",
42
59
  "superagent": "^3.8.3"
43
60
  },
44
61
  "prettier": {
@@ -46,19 +63,8 @@
46
63
  "singleQuote": true,
47
64
  "trailingComma": "es5"
48
65
  },
49
- "scripts": {
50
- "build": "npm-run-all clean --parallel build:lib build:dist",
51
- "build:lib": "cross-env BUILD=lib vite build",
52
- "build:dist": "npm-run-all build:dist:dev build:dist:min",
53
- "build:dist:dev": "cross-env BUILD=dist MINIFY=false vite build",
54
- "build:dist:min": "cross-env BUILD=dist MINIFY=true vite build",
55
- "build:matrix": "bash scripts/build-matrix.sh",
56
- "dev": "cross-env BUILD=dist MINIFY=false vite build --watch",
57
- "test": "mocha --require esbuild-register --colors 'test/**/*test.js'",
58
- "test:watch": "npm run test -- -w",
59
- "clean": "rimraf dist lib",
60
- "preversion": "npm-run-all clean build",
61
- "serve": "http-server -p 1234 -c-1 dist",
62
- "release:patch": "np patch --any-branch --yolo"
66
+ "packageManager": "pnpm@11.8.0",
67
+ "engines": {
68
+ "node": ">=20.0.0"
63
69
  }
64
- }
70
+ }