qiscus-sdk-core 2.16.0 → 2.16.1

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/lib/match.js CHANGED
@@ -1,63 +1,45 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.match = match;
8
- exports.when = when;
9
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
- // Taken from https://github.com/FGRibreau/match-when/blob/master/match.js
11
-
12
- var _catchAllSymbol = String('match.pattern.catchAll');
13
- var _patternOR = String('match.pattern.OR');
14
- var _patternORStr = _patternOR.toString(); // dirty hack
15
- var _patternAND = String('match.pattern.AND');
16
- var _patternANDStr = _patternAND.toString(); // dirty hack
17
- var _patternRANGE = String('match.pattern.RANGE');
18
- var _patternRANGEStr = _patternRANGE.toString(); // dirty hack
19
-
20
- var _patternREGEXP = String('match.pattern.REGEXP');
21
- var _patternREGEXPStr = _patternREGEXP.toString(); // dirty hack
22
- var EXTRACT_PATTERN_AND_FLAGS = /\/(.*)\/(.*)/;
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const _catchAllSymbol = String("match.pattern.catchAll");
4
+ const _patternOR = String("match.pattern.OR");
5
+ const _patternORStr = _patternOR.toString();
6
+ const _patternAND = String("match.pattern.AND");
7
+ const _patternANDStr = _patternAND.toString();
8
+ const _patternRANGE = String("match.pattern.RANGE");
9
+ const _patternRANGEStr = _patternRANGE.toString();
10
+ const _patternREGEXP = String("match.pattern.REGEXP");
11
+ const _patternREGEXPStr = _patternREGEXP.toString();
12
+ const EXTRACT_PATTERN_AND_FLAGS = /\/(.*)\/(.*)/;
23
13
  function MissingCatchAllPattern() {
24
- Error.call(this, 'Missing when() catch-all pattern as last match argument, add [when()]: void 0');
25
- if (!('stack' in this)) {
14
+ Error.call(this, "Missing when() catch-all pattern as last match argument, add [when()]: void 0");
15
+ if (!("stack" in this)) {
26
16
  this.stack = new Error().stack;
27
17
  }
28
18
  }
29
19
  MissingCatchAllPattern.prototype = Object.create(Error.prototype);
30
- function match() {
31
- var _ref;
32
- var obj = (_ref = arguments.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
33
-
34
- // pre-compute matchers
35
- var matchers = [];
36
- for (var key in obj) {
20
+ function match(...args) {
21
+ const obj = args[args.length - 1];
22
+ let matchers = [];
23
+ for (let key in obj) {
37
24
  matchers.push(when.unserialize(key, obj[key]));
38
25
  }
39
-
40
- // since JS objects are unordered we need to reorder what for..in give us even if the order was already right
41
- // because it depends on the JS engine implementation. See #2
42
- matchers.sort(function (a, b) {
26
+ matchers.sort(function(a, b) {
43
27
  return a.position < b.position ? -1 : 1;
44
28
  });
45
29
  if (Object.getOwnPropertySymbols(obj).indexOf(_catchAllSymbol) !== -1) {
46
30
  matchers.push(when.unserialize(_catchAllSymbol, obj[_catchAllSymbol]));
47
31
  }
48
- var calculateResult = function calculateResult(input) {
49
- var matched = matchers.find(function (matcher) {
50
- return matcher.match(input);
51
- });
32
+ const calculateResult = function(input) {
33
+ const matched = matchers.find((matcher) => matcher.match(input));
52
34
  if (!matched) {
53
35
  throw new MissingCatchAllPattern();
54
36
  }
55
- return typeof matched.result === 'function' ? matched.result(input) : matched.result;
37
+ return typeof matched.result === "function" ? matched.result(input) : matched.result;
56
38
  };
57
- return arguments.length === 2 ? calculateResult(arguments.length <= 0 ? undefined : arguments[0]) : calculateResult;
39
+ return args.length === 2 ? calculateResult(args[0]) : calculateResult;
58
40
  }
59
41
  function when(props) {
60
- if (props === undefined) {
42
+ if (props === void 0) {
61
43
  return _catchAllSymbol;
62
44
  }
63
45
  if (props instanceof RegExp) {
@@ -66,94 +48,69 @@ function when(props) {
66
48
  return _serialize(props);
67
49
  }
68
50
  when.__uid = 0;
69
-
70
- // Any -> String
71
51
  function _serialize(mixed) {
72
52
  return JSON.stringify([when.__uid++, mixed]);
73
53
  }
74
-
75
- // String -> [Number, Any]
76
54
  function _unserialize(str) {
77
55
  return JSON.parse(str);
78
56
  }
79
57
  function _true() {
80
58
  return true;
81
59
  }
82
-
83
- // Any -> String
84
60
  function _match(props) {
85
61
  if (Array.isArray(props)) {
86
62
  if (props[0] === _patternORStr) {
87
63
  props.shift();
88
- return function (input) {
89
- return props[0].some(function (prop) {
90
- return _matching(prop, input);
91
- });
64
+ return function(input) {
65
+ return props[0].some((prop) => _matching(prop, input));
92
66
  };
93
67
  }
94
68
  if (props[0] === _patternANDStr) {
95
69
  props.shift();
96
- return function (input) {
97
- return props[0].every(function (prop) {
98
- return _matching(prop, input);
99
- });
70
+ return function(input) {
71
+ return props[0].every((prop) => _matching(prop, input));
100
72
  };
101
73
  }
102
74
  if (props[0] === _patternRANGEStr) {
103
75
  props.shift();
104
- return function (input) {
76
+ return function(input) {
105
77
  return props[0] <= input && input <= props[1];
106
78
  };
107
79
  }
108
80
  if (props[0] === _patternREGEXPStr) {
109
- var res = EXTRACT_PATTERN_AND_FLAGS.exec(props[1]);
81
+ const res = EXTRACT_PATTERN_AND_FLAGS.exec(props[1]);
110
82
  return _matching.bind(null, new RegExp(res[1], res[2]));
111
83
  }
112
84
  }
113
- function _matching(props, input) {
114
- // implement array matching
85
+ function _matching(props2, input) {
115
86
  if (Array.isArray(input)) {
116
- // @todo yes this is a quick and dirty way, optimize this
117
- return JSON.stringify(props) === JSON.stringify(input);
87
+ return JSON.stringify(props2) === JSON.stringify(input);
118
88
  }
119
- if (props instanceof RegExp) {
120
- return props.test(input);
89
+ if (props2 instanceof RegExp) {
90
+ return props2.test(input);
121
91
  }
122
- if ((0, _typeof2["default"])(input) === 'object') {
123
- for (var prop in props) {
124
- if (input[prop] !== props[prop]) {
92
+ if (typeof input === "object") {
93
+ for (let prop in props2) {
94
+ if (input[prop] !== props2[prop]) {
125
95
  return false;
126
96
  }
127
97
  }
128
98
  return true;
129
99
  }
130
- return props === input;
100
+ return props2 === input;
131
101
  }
132
- return function (input) {
133
- return _matching(props, input);
134
- };
102
+ return (input) => _matching(props, input);
135
103
  }
136
-
137
- // mixed -> String
138
- when.or = function () {
139
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
140
- args[_key] = arguments[_key];
141
- }
104
+ when.or = function(...args) {
142
105
  return _serialize([_patternOR.toString(), args]);
143
106
  };
144
-
145
- // mixed -> String
146
- // upcoming...
147
- when.and = function () {
148
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
149
- args[_key2] = arguments[_key2];
150
- }
107
+ when.and = function(...args) {
151
108
  return _serialize([_patternAND.toString(), args]);
152
109
  };
153
- when.range = function (start, end) {
110
+ when.range = function(start, end) {
154
111
  return _serialize([_patternRANGE.toString(), start, end]);
155
112
  };
156
- when.unserialize = function (serializedKey, value) {
113
+ when.unserialize = function(serializedKey, value) {
157
114
  if (serializedKey === _catchAllSymbol) {
158
115
  return {
159
116
  match: _true,
@@ -161,14 +118,14 @@ when.unserialize = function (serializedKey, value) {
161
118
  position: Infinity
162
119
  };
163
120
  }
164
-
165
- // const {position, matcherConfiguration} = _unserialize(serializedKey);
166
- var deserialized = _unserialize(serializedKey);
167
- var matcherConfiguration = deserialized[1];
168
- var position = deserialized[0];
121
+ const deserialized = _unserialize(serializedKey);
122
+ const matcherConfiguration = deserialized[1];
123
+ const position = deserialized[0];
169
124
  return {
170
125
  match: _match(matcherConfiguration),
171
126
  result: value,
172
- position: position
127
+ position
173
128
  };
174
- };
129
+ };
130
+ exports.match = match;
131
+ exports.when = when;
@@ -1,27 +1,16 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = UrlBuilder;
7
2
  function UrlBuilder(basePath) {
8
- var params = {};
9
- var getQuery = function getQuery(key, value) {
10
- return "".concat(key, "=").concat(value);
11
- };
3
+ const params = {};
4
+ const getQuery = (key, value) => `${key}=${value}`;
12
5
  return {
13
- param: function param(key, value) {
6
+ param(key, value) {
14
7
  params[key] = value;
15
8
  return this;
16
9
  },
17
- build: function build() {
18
- var query = Object.keys(params).filter(function (key) {
19
- return params[key] != null;
20
- }).map(function (key) {
10
+ build() {
11
+ const query = Object.keys(params).filter((key) => params[key] != null).map((key) => {
21
12
  if (Array.isArray(params[key])) {
22
- return params[key].map(function (value) {
23
- return getQuery("".concat(key, "[]"), value);
24
- }).join("&");
13
+ return params[key].map((value) => getQuery(`${key}[]`, value)).join("&");
25
14
  }
26
15
  return getQuery(key, params[key]);
27
16
  }).join("&");
@@ -29,4 +18,4 @@ function UrlBuilder(basePath) {
29
18
  }
30
19
  };
31
20
  }
32
- module.exports = exports.default;
21
+ module.exports = UrlBuilder;
package/lib/lib/util.js CHANGED
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.wrapP = exports.tryCatch = exports.sleep = void 0;
7
- var tryCatch = exports.tryCatch = function tryCatch(fn, default_, onError, onSuccess) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tryCatch = (fn, default_, onError, onSuccess) => {
8
4
  try {
9
- var resp = fn();
5
+ const resp = fn();
10
6
  if (onSuccess != null) onSuccess(resp);
11
7
  return resp;
12
8
  } catch (error) {
@@ -14,16 +10,6 @@ var tryCatch = exports.tryCatch = function tryCatch(fn, default_, onError, onSuc
14
10
  return default_;
15
11
  }
16
12
  };
17
- var wrapP = exports.wrapP = function wrapP(promise) {
18
- return promise.then(function (res) {
19
- return [res, null];
20
- })["catch"](function (err) {
21
- return [null, err];
22
- });
23
- };
24
- var sleep = exports.sleep = function sleep() {
25
- var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
26
- return new Promise(function (r) {
27
- return setTimeout(r, time);
28
- });
29
- };
13
+ const wrapP = (promise) => promise.then((res) => [res, null]).catch((err) => [null, err]);
14
+ exports.tryCatch = tryCatch;
15
+ exports.wrapP = wrapP;
package/lib/lib/utils.js CHANGED
@@ -1,123 +1,78 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.GroupChatBuilder = void 0;
8
- exports.delayed = delayed;
9
- exports.escapeHTML = escapeHTML;
10
- exports.scrollToBottom = scrollToBottom;
11
- exports.searchAndReplace = searchAndReplace;
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
- function searchAndReplace(str, find, replace) {
15
- return str.split(find).join(replace);
16
- }
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
17
3
  function escapeHTML(str) {
18
- return str.replace(/<[^>]*\/?>([\s\S]*)?<\/.*?>/gi, function (match) {
19
- return match.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
4
+ return str.replace(/<[^>]*\/?>([\s\S]*)?<\/.*?>/gi, function(match) {
5
+ return match.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
20
6
  });
21
7
  }
22
- var GroupChatBuilder = exports.GroupChatBuilder = /*#__PURE__*/function () {
8
+ class GroupChatBuilder {
23
9
  /**
24
10
  * Create a group chat room builder.
25
11
  * @constructs
26
12
  * @param {RoomAdapter} roomAdapter - Room adapter to be used to call backend
27
13
  * API.
28
14
  */
29
- function GroupChatBuilder(roomAdapter) {
30
- (0, _classCallCheck2["default"])(this, GroupChatBuilder);
15
+ constructor(roomAdapter) {
31
16
  this.roomAdapter = roomAdapter;
32
17
  this.name = null;
33
18
  this.emails = [];
34
19
  this.options = {};
35
20
  }
36
-
37
21
  /**
38
22
  * Set the room name
39
23
  * @param {string} name - Room name
40
24
  * @returns {GroupChatBuilder}
41
25
  */
42
- return (0, _createClass2["default"])(GroupChatBuilder, [{
43
- key: "withName",
44
- value: function withName(name) {
45
- this.name = name;
46
- return this;
47
- }
48
-
49
- /**
50
- * Add an options to this room.
51
- * @param {object} options - Any data that is `JSON.stringify` able
52
- * @returns {GroupChatBuilder}
53
- */
54
- }, {
55
- key: "withOptions",
56
- value: function withOptions(options) {
57
- this.options = options;
58
- return this;
59
- }
60
-
61
- /**
62
- * Add more participants to the room.
63
- * This method use javascript rest operator, which mean you can add as many as
64
- * you want.
65
- * eg: addParticipants('email1@gg.com', 'email2@gg.com')
66
- * @param {string} emails - Email of participant to be added.
67
- */
68
- }, {
69
- key: "addParticipants",
70
- value: function addParticipants() {
71
- var _this$emails$filter;
72
- for (var _len = arguments.length, emails = new Array(_len), _key = 0; _key < _len; _key++) {
73
- emails[_key] = arguments[_key];
74
- }
75
- this.emails = (_this$emails$filter = this.emails.filter(function (email) {
76
- return emails.indexOf(email) === -1;
77
- })).concat.apply(_this$emails$filter, emails);
78
- return this;
79
- }
80
-
81
- /**
82
- * Real create group chat room by calling the backend API.
83
- * @returns {Promise.<Room, Error>}
84
- */
85
- }, {
86
- key: "create",
87
- value: function create() {
88
- var name = this.name;
89
- var emails = this.emails;
90
- var options = this.options;
91
- return this.roomAdapter.createRoom(name, emails, {
92
- avatarURL: options.avatarURL
93
- }, options);
94
- }
95
- }]);
96
- }();
97
- function scrollToBottom(latestCommentId) {
98
- requestAnimationFrame(function () {
99
- if (latestCommentId > 0) {
100
- var elementToScroll = document.getElementById(latestCommentId);
101
- if (!elementToScroll) return false;
102
- elementToScroll.scrollIntoView({
103
- block: 'end',
104
- behavior: 'smooth'
105
- });
106
- }
107
- // on entering the room, wait for data processed then focus on comment form
108
- document.getElementsByClassName('qcw-comment-form').item(0).getElementsByTagName('textarea').item(0).focus();
109
- });
26
+ withName(name) {
27
+ this.name = name;
28
+ return this;
29
+ }
30
+ /**
31
+ * Add an options to this room.
32
+ * @param {object} options - Any data that is `JSON.stringify` able
33
+ * @returns {GroupChatBuilder}
34
+ */
35
+ withOptions(options) {
36
+ this.options = options;
37
+ return this;
38
+ }
39
+ /**
40
+ * Add more participants to the room.
41
+ * This method use javascript rest operator, which mean you can add as many as
42
+ * you want.
43
+ * eg: addParticipants('email1@gg.com', 'email2@gg.com')
44
+ * @param {string} emails - Email of participant to be added.
45
+ */
46
+ addParticipants(...emails) {
47
+ this.emails = this.emails.filter((email) => emails.indexOf(email) === -1).concat(...emails);
48
+ return this;
49
+ }
50
+ /**
51
+ * Real create group chat room by calling the backend API.
52
+ * @returns {Promise.<Room, Error>}
53
+ */
54
+ create() {
55
+ const name = this.name;
56
+ const emails = this.emails;
57
+ const options = this.options;
58
+ return this.roomAdapter.createRoom(
59
+ name,
60
+ emails,
61
+ { avatarURL: options.avatarURL },
62
+ options
63
+ );
64
+ }
110
65
  }
111
66
  function delayed(cb, timeout) {
112
- var timer = null;
113
- return function () {
114
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
115
- args[_key2] = arguments[_key2];
116
- }
67
+ let timer = null;
68
+ return function(...args) {
117
69
  if (timer != null) clearTimeout(timer);
118
- timer = setTimeout(function () {
119
- cb.apply(void 0, args);
70
+ timer = setTimeout(() => {
71
+ cb(...args);
120
72
  timer = null;
121
73
  }, timeout);
122
74
  };
123
- }
75
+ }
76
+ exports.GroupChatBuilder = GroupChatBuilder;
77
+ exports.delayed = delayed;
78
+ exports.escapeHTML = escapeHTML;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qiscus-sdk-core",
3
- "version": "2.16.0",
3
+ "version": "2.16.1",
4
4
  "description": "Qiscus Web SDK Core",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -10,45 +10,16 @@
10
10
  "lib",
11
11
  "dist"
12
12
  ],
13
- "scripts": {
14
- "build": "npm-run-all --parallel build:node build:web build:web:dev",
15
- "build:dev": "npm-run-all --parallel build:node build:web:dev",
16
- "build:dev:watch": "npm-run-all --parallel build:web:watch serve",
17
- "build:node": "babel -d lib src",
18
- "build:node:watch": "babel -w -d lib src",
19
- "build:web": "webpack --env.production --env.target=web",
20
- "build:web:dev": "webpack --env.development --env.target=web",
21
- "build:web:watch": "webpack --env.development --env.target=web --watch",
22
- "dev": "webpack --env.development --progress --colors --watch",
23
- "watch": "npm-run-all build:web:watch build:node:watch",
24
- "test": "mocha --require @babel/register --colors 'test/**/*test.js'",
25
- "test:watch": "npm run test -- -w",
26
- "clean": "rimraf dist lib",
27
- "preversion": "npm-run-all clean build",
28
- "prepublishOnly": "npm-run-all clean build",
29
- "serve": "http-server -p 1234 -c-1 dist",
30
- "dev:serve": "run-p serve watch",
31
- "release:patch": "np patch --any-branch --yolo"
32
- },
33
13
  "devDependencies": {
34
- "@babel/cli": "^7.10.5",
35
- "@babel/core": "^7.11.4",
36
- "@babel/plugin-proposal-class-properties": "^7.10.4",
37
- "@babel/plugin-transform-runtime": "^7.11.0",
38
- "@babel/polyfill": "^7.10.4",
39
- "@babel/preset-env": "^7.11.0",
40
- "@babel/register": "^7.10.5",
41
14
  "@commitlint/cli": "^8.3.5",
42
15
  "@commitlint/config-conventional": "^8.3.4",
43
16
  "babel-eslint": "^8.2.6",
44
- "babel-loader": "^8.0.6",
45
- "babel-plugin-add-module-exports": "^1.0.2",
46
- "babel-plugin-date-fns": "^0.1.0",
47
17
  "chai": "^4.2.0",
48
18
  "chai-spies": "^1.0.0",
19
+ "cross-env": "^7.0.3",
20
+ "esbuild-register": "^3.6.0",
49
21
  "eslint": "5.0.0",
50
22
  "eslint-config-standard": "^12.0.0",
51
- "eslint-loader": "^2.2.1",
52
23
  "eslint-plugin-import": "^2.22.0",
53
24
  "eslint-plugin-node": "^8.0.1",
54
25
  "eslint-plugin-promise": "^4.2.1",
@@ -59,11 +30,10 @@
59
30
  "npm-run-all": "^4.1.5",
60
31
  "rimraf": "^2.7.1",
61
32
  "serve": "^12.0.0",
62
- "webpack": "^4.44.1",
63
- "webpack-cli": "^3.3.12"
33
+ "vite": "^6.0.0",
34
+ "vite-plugin-node-polyfills": "~0.22.0"
64
35
  },
65
36
  "dependencies": {
66
- "@babel/runtime": "^7.11.2",
67
37
  "date-fns": "^1.30.1",
68
38
  "lodash.debounce": "^4.0.8",
69
39
  "lodash.throttle": "^4.1.1",
@@ -71,28 +41,24 @@
71
41
  "mqtt": "~4.2.6",
72
42
  "superagent": "^3.8.3"
73
43
  },
74
- "babel": {
75
- "presets": [
76
- [
77
- "@babel/preset-env",
78
- {
79
- "modules": "auto"
80
- }
81
- ]
82
- ],
83
- "plugins": [
84
- "@babel/plugin-transform-runtime",
85
- "@babel/plugin-proposal-class-properties",
86
- "babel-plugin-add-module-exports"
87
- ]
88
- },
89
44
  "prettier": {
90
45
  "semi": false,
91
46
  "singleQuote": true,
92
47
  "trailingComma": "es5"
93
48
  },
94
- "engines": {
95
- "node": "16.15.1"
96
- },
97
- "packageManager": "pnpm@8.15.9"
98
- }
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"
63
+ }
64
+ }