@rc-ex/ws 1.3.13 → 1.3.15

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/dist/cjs/rest.js CHANGED
@@ -1,103 +1,53 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
4
  };
52
5
  Object.defineProperty(exports, "__esModule", { value: true });
53
6
  exports.request = request;
54
- var RestException_1 = __importDefault(require("@rc-ex/core/RestException"));
55
- var hyperid_1 = __importDefault(require("hyperid"));
56
- var http_status_codes_1 = require("http-status-codes");
57
- var utils_js_1 = __importDefault(require("./utils.js"));
58
- var version = "0.16";
59
- var uuid = (0, hyperid_1.default)();
60
- function request(method, endpoint, content, queryParams, config) {
61
- return __awaiter(this, void 0, void 0, function () {
62
- var newConfig, messageId, requestBody, _a, meta, body, response;
63
- var _b;
64
- return __generator(this, function (_c) {
65
- switch (_c.label) {
66
- case 0:
67
- newConfig = __assign({ method: method, baseURL: (_b = this.wsToken) === null || _b === void 0 ? void 0 : _b.uri, url: endpoint, data: content, params: queryParams }, config);
68
- newConfig.headers = __assign(__assign({}, newConfig.headers), { "X-User-Agent": "".concat(this.rc.rest.appName, "/").concat(this.rc.rest.appVersion, " ringcentral-extensible/ws/").concat(version) });
69
- messageId = uuid();
70
- requestBody = [
71
- {
72
- type: "ClientRequest",
73
- messageId: messageId,
74
- method: newConfig.method,
75
- path: newConfig.url,
76
- headers: newConfig.headers,
77
- query: newConfig.params,
78
- },
79
- ];
80
- if (newConfig.data) {
81
- requestBody.push(newConfig.data);
82
- }
83
- return [4 /*yield*/, this.ws.send(JSON.stringify(requestBody))];
84
- case 1:
85
- _c.sent();
86
- return [4 /*yield*/, utils_js_1.default.waitForWebSocketMessage(this.ws, function (_meta) { return _meta.messageId === messageId; })];
87
- case 2:
88
- _a = _c.sent(), meta = _a[0], body = _a[1];
89
- response = {
90
- data: body,
91
- status: meta.status,
92
- statusText: (0, http_status_codes_1.getReasonPhrase)(meta.status),
93
- headers: meta.headers,
94
- config: newConfig,
95
- };
96
- if (meta.type === "ClientRequest" && meta.status >= 200 && meta.status < 300) {
97
- return [2 /*return*/, response];
98
- }
99
- throw new RestException_1.default(response);
100
- }
101
- });
102
- });
7
+ const RestException_1 = __importDefault(require("@rc-ex/core/RestException"));
8
+ const hyperid_1 = __importDefault(require("hyperid"));
9
+ const http_status_codes_1 = require("http-status-codes");
10
+ const utils_js_1 = __importDefault(require("./utils.js"));
11
+ const version = "0.16";
12
+ const uuid = (0, hyperid_1.default)();
13
+ async function request(method, endpoint, content, queryParams, config) {
14
+ const newConfig = {
15
+ method,
16
+ baseURL: this.wsToken?.uri,
17
+ url: endpoint,
18
+ data: content,
19
+ params: queryParams,
20
+ ...config,
21
+ };
22
+ newConfig.headers = {
23
+ ...newConfig.headers,
24
+ "X-User-Agent": `${this.rc.rest.appName}/${this.rc.rest.appVersion} ringcentral-extensible/ws/${version}`,
25
+ };
26
+ const messageId = uuid();
27
+ const requestBody = [
28
+ {
29
+ type: "ClientRequest",
30
+ messageId,
31
+ method: newConfig.method,
32
+ path: newConfig.url,
33
+ headers: newConfig.headers,
34
+ query: newConfig.params,
35
+ },
36
+ ];
37
+ if (newConfig.data) {
38
+ requestBody.push(newConfig.data);
39
+ }
40
+ await this.ws.send(JSON.stringify(requestBody));
41
+ const [meta, body] = await utils_js_1.default.waitForWebSocketMessage(this.ws, (_meta) => _meta.messageId === messageId);
42
+ const response = {
43
+ data: body,
44
+ status: meta.status,
45
+ statusText: (0, http_status_codes_1.getReasonPhrase)(meta.status),
46
+ headers: meta.headers,
47
+ config: newConfig,
48
+ };
49
+ if (meta.type === "ClientRequest" && meta.status >= 200 && meta.status < 300) {
50
+ return response;
51
+ }
52
+ throw new RestException_1.default(response);
103
53
  }
@@ -1,166 +1,85 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var utils_js_1 = __importDefault(require("./utils.js"));
43
- var Subscription = /** @class */ (function () {
44
- function Subscription(wse, eventFilters, callback) {
45
- var _this = this;
46
- this.enabled = true;
6
+ const utils_js_1 = __importDefault(require("./utils.js"));
7
+ class Subscription {
8
+ subscriptionInfo;
9
+ wse;
10
+ eventFilters;
11
+ eventListener;
12
+ timeout;
13
+ enabled = true;
14
+ constructor(wse, eventFilters, callback) {
47
15
  this.wse = wse;
48
16
  this.eventFilters = eventFilters;
49
- this.eventListener = function (mEvent) {
50
- var event = mEvent;
51
- var _a = utils_js_1.default
52
- .splitWsgData(event.data), meta = _a[0], body = _a[1];
53
- if (_this.enabled && meta.type === "ServerNotification" &&
54
- body.subscriptionId === _this.subscriptionInfo.id) {
17
+ this.eventListener = (mEvent) => {
18
+ const event = mEvent;
19
+ const [meta, body] = utils_js_1.default
20
+ .splitWsgData(event.data);
21
+ if (this.enabled && meta.type === "ServerNotification" &&
22
+ body.subscriptionId === this.subscriptionInfo.id) {
55
23
  callback(body);
56
24
  }
57
25
  };
58
26
  this.setupWsEventListener();
59
27
  }
60
- Subscription.prototype.setupWsEventListener = function () {
28
+ setupWsEventListener() {
61
29
  this.wse.ws.addEventListener("message", this.eventListener);
62
- };
63
- Object.defineProperty(Subscription.prototype, "requestBody", {
64
- get: function () {
65
- return {
66
- deliveryMode: { transportType: "WebSocket" }, // because WebSocket is not in spec
67
- eventFilters: this.eventFilters,
68
- };
69
- },
70
- enumerable: false,
71
- configurable: true
72
- });
73
- Subscription.prototype.subscribe = function () {
74
- return __awaiter(this, void 0, void 0, function () {
75
- var _a;
76
- return __generator(this, function (_b) {
77
- switch (_b.label) {
78
- case 0:
79
- _a = this;
80
- return [4 /*yield*/, this.wse.request("POST", "/restapi/v1.0/subscription", this.requestBody)];
81
- case 1:
82
- _a.subscriptionInfo = (_b.sent()).data;
83
- return [2 /*return*/];
84
- }
85
- });
86
- });
87
- };
88
- Subscription.prototype.refresh = function () {
89
- return __awaiter(this, void 0, void 0, function () {
90
- var _a, e_1, re;
91
- return __generator(this, function (_b) {
92
- switch (_b.label) {
93
- case 0:
94
- if (!this.subscriptionInfo) {
95
- return [2 /*return*/];
96
- }
97
- _b.label = 1;
98
- case 1:
99
- _b.trys.push([1, 3, , 6]);
100
- _a = this;
101
- return [4 /*yield*/, this.wse.request("PUT", "/restapi/v1.0/subscription/".concat(this.subscriptionInfo.id), this.requestBody)];
102
- case 2:
103
- _a.subscriptionInfo = (_b.sent()).data;
104
- return [3 /*break*/, 6];
105
- case 3:
106
- e_1 = _b.sent();
107
- re = e_1;
108
- if (!(re.response && re.response.status === 404)) return [3 /*break*/, 5];
109
- // subscription expired
110
- return [4 /*yield*/, this.subscribe()];
111
- case 4:
112
- // subscription expired
113
- _b.sent();
114
- _b.label = 5;
115
- case 5: return [3 /*break*/, 6];
116
- case 6: return [2 /*return*/];
30
+ }
31
+ get requestBody() {
32
+ return {
33
+ deliveryMode: { transportType: "WebSocket" }, // because WebSocket is not in spec
34
+ eventFilters: this.eventFilters,
35
+ };
36
+ }
37
+ async subscribe() {
38
+ this.subscriptionInfo = (await this.wse.request("POST", "/restapi/v1.0/subscription", this.requestBody)).data;
39
+ }
40
+ async refresh() {
41
+ if (!this.subscriptionInfo) {
42
+ return;
43
+ }
44
+ try {
45
+ this.subscriptionInfo = (await this.wse.request("PUT", `/restapi/v1.0/subscription/${this.subscriptionInfo.id}`, this.requestBody)).data;
46
+ }
47
+ catch (e) {
48
+ const re = e;
49
+ if (re.response && re.response.status === 404) {
50
+ // subscription expired
51
+ await this.subscribe();
52
+ }
53
+ }
54
+ }
55
+ async revoke() {
56
+ if (!this.subscriptionInfo) {
57
+ return;
58
+ }
59
+ try {
60
+ await this.wse.request("DELETE", `/restapi/v1.0/subscription/${this.subscriptionInfo.id}`);
61
+ }
62
+ catch (e) {
63
+ const re = e;
64
+ if (re.response && re.response.status === 404) {
65
+ // ignore
66
+ if (this.wse.options.debugMode) {
67
+ console.debug(`Subscription ${this.subscriptionInfo.id} doesn't exist on server side`);
117
68
  }
118
- });
119
- });
120
- };
121
- Subscription.prototype.revoke = function () {
122
- return __awaiter(this, void 0, void 0, function () {
123
- var e_2, re;
124
- return __generator(this, function (_a) {
125
- switch (_a.label) {
126
- case 0:
127
- if (!this.subscriptionInfo) {
128
- return [2 /*return*/];
129
- }
130
- _a.label = 1;
131
- case 1:
132
- _a.trys.push([1, 3, , 4]);
133
- return [4 /*yield*/, this.wse.request("DELETE", "/restapi/v1.0/subscription/".concat(this.subscriptionInfo.id))];
134
- case 2:
135
- _a.sent();
136
- return [3 /*break*/, 4];
137
- case 3:
138
- e_2 = _a.sent();
139
- re = e_2;
140
- if (re.response && re.response.status === 404) {
141
- // ignore
142
- if (this.wse.options.debugMode) {
143
- console.debug("Subscription ".concat(this.subscriptionInfo.id, " doesn't exist on server side"));
144
- }
145
- }
146
- else if (re.response && re.response.status === 401) {
147
- // ignore
148
- if (this.wse.options.debugMode) {
149
- console.debug("Token invalid when trying to revoke subscription");
150
- }
151
- }
152
- else {
153
- throw e_2;
154
- }
155
- return [3 /*break*/, 4];
156
- case 4:
157
- this.remove();
158
- return [2 /*return*/];
69
+ }
70
+ else if (re.response && re.response.status === 401) {
71
+ // ignore
72
+ if (this.wse.options.debugMode) {
73
+ console.debug("Token invalid when trying to revoke subscription");
159
74
  }
160
- });
161
- });
162
- };
163
- Subscription.prototype.remove = function () {
75
+ }
76
+ else {
77
+ throw e;
78
+ }
79
+ }
80
+ this.remove();
81
+ }
82
+ remove() {
164
83
  if (this.timeout) {
165
84
  global.clearTimeout(this.timeout);
166
85
  this.timeout = undefined;
@@ -171,7 +90,6 @@ var Subscription = /** @class */ (function () {
171
90
  this.wse.ws.removeEventListener("message", this.eventListener);
172
91
  }
173
92
  this.wse.subscription = undefined;
174
- };
175
- return Subscription;
176
- }());
93
+ }
94
+ }
177
95
  exports.default = Subscription;
@@ -1,4 +1,4 @@
1
- import type RingCentral from "@rc-ex/core/index";
1
+ import type RingCentral from "@rc-ex/core";
2
2
  import type { RestMethod, RestRequestConfig, RestResponse } from "@rc-ex/core/types";
3
3
  import type WS from "isomorphic-ws";
4
4
  export interface WsToken {
package/dist/cjs/utils.js CHANGED
@@ -1,105 +1,62 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var ClosedException_js_1 = __importDefault(require("./exceptions/ClosedException.js"));
43
- var TimeoutException_js_1 = __importDefault(require("./exceptions/TimeoutException.js"));
44
- var Utils = /** @class */ (function () {
45
- function Utils() {
46
- }
47
- Utils.splitWsgData = function (wsgData) {
6
+ const ClosedException_js_1 = __importDefault(require("./exceptions/ClosedException.js"));
7
+ const TimeoutException_js_1 = __importDefault(require("./exceptions/TimeoutException.js"));
8
+ class Utils {
9
+ static splitWsgData(wsgData) {
48
10
  if (wsgData.includes(",--Boundary")) {
49
- var index = wsgData.indexOf(",--Boundary");
11
+ const index = wsgData.indexOf(",--Boundary");
50
12
  return [
51
13
  JSON.parse(wsgData.substring(1, index)),
52
14
  wsgData.substring(index + 1, wsgData.length - 1),
53
15
  ];
54
16
  }
55
17
  return JSON.parse(wsgData);
56
- };
57
- Utils.debugWebSocket = function (_ws) {
58
- var _this = this;
59
- var ws = _ws;
60
- var send = ws.send.bind(ws);
61
- ws.send = function (str) { return __awaiter(_this, void 0, void 0, function () {
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
64
- case 0: return [4 /*yield*/, send(str)];
65
- case 1:
66
- _a.sent();
67
- console.debug("*** WebSocket outgoing message: ***\n".concat(JSON.stringify(JSON.parse(str), null, 2), "\n******"));
68
- return [2 /*return*/];
69
- }
70
- });
71
- }); };
72
- ws.addEventListener("message", function (mEvent) {
73
- var event = mEvent;
74
- console.debug("*** WebSocket incoming message: ***\n".concat(JSON.stringify(JSON.parse(event.data), null, 2), "\n******"));
18
+ }
19
+ static debugWebSocket(_ws) {
20
+ const ws = _ws;
21
+ const send = ws.send.bind(ws);
22
+ ws.send = async (str) => {
23
+ await send(str);
24
+ console.debug(`*** WebSocket outgoing message: ***
25
+ ${JSON.stringify(JSON.parse(str), null, 2)}
26
+ ******`);
27
+ };
28
+ ws.addEventListener("message", (mEvent) => {
29
+ const event = mEvent;
30
+ console.debug(`*** WebSocket incoming message: ***
31
+ ${JSON.stringify(JSON.parse(event.data), null, 2)}
32
+ ******`);
75
33
  });
76
- ws.addEventListener("open", function (event) {
34
+ ws.addEventListener("open", (event) => {
77
35
  console.debug("WebSocket open event:", event);
78
36
  });
79
- ws.addEventListener("error", function (event) {
37
+ ws.addEventListener("error", (event) => {
80
38
  console.debug("WebSocket error event:", event);
81
39
  });
82
- ws.addEventListener("close", function (event) {
40
+ ws.addEventListener("close", (event) => {
83
41
  console.debug("WebSocket close event:", event);
84
42
  });
85
- };
86
- Utils.waitForWebSocketMessage = function (ws, matchCondition, timeout) {
87
- if (timeout === void 0) { timeout = 60000; }
88
- return new Promise(function (resolve, reject) {
89
- var checkHandle = setInterval(function () {
43
+ }
44
+ static waitForWebSocketMessage(ws, matchCondition, timeout = 60000) {
45
+ return new Promise((resolve, reject) => {
46
+ const checkHandle = setInterval(() => {
90
47
  if (ws.readyState === ws.CLOSED) {
91
48
  clearInterval(checkHandle);
92
49
  reject(new ClosedException_js_1.default());
93
50
  }
94
51
  }, 1000);
95
- var timeoutHandle = setTimeout(function () {
52
+ const timeoutHandle = setTimeout(() => {
96
53
  ws.removeEventListener("message", handler);
97
54
  clearInterval(checkHandle);
98
55
  reject(new TimeoutException_js_1.default());
99
56
  }, timeout);
100
- var handler = function (mEvent) {
101
- var event = mEvent;
102
- var _a = Utils.splitWsgData(event.data), meta = _a[0], body = _a[1];
57
+ const handler = (mEvent) => {
58
+ const event = mEvent;
59
+ const [meta, body] = Utils.splitWsgData(event.data);
103
60
  if (matchCondition(meta)) {
104
61
  ws.removeEventListener("message", handler);
105
62
  clearInterval(checkHandle);
@@ -109,7 +66,6 @@ var Utils = /** @class */ (function () {
109
66
  };
110
67
  ws.addEventListener("message", handler);
111
68
  });
112
- };
113
- return Utils;
114
- }());
69
+ }
70
+ }
115
71
  exports.default = Utils;
@@ -1,4 +1,4 @@
1
- import type RingCentral from "@rc-ex/core/index";
1
+ import type RingCentral from "@rc-ex/core";
2
2
  import SdkExtension from "@rc-ex/core/SdkExtension";
3
3
  import WS from "isomorphic-ws";
4
4
  import { EventEmitter } from "events";
@@ -1,4 +1,4 @@
1
- import type RingCentral from "@rc-ex/core/index";
1
+ import type RingCentral from "@rc-ex/core";
2
2
  import type { RestMethod, RestRequestConfig, RestResponse } from "@rc-ex/core/types";
3
3
  import type WS from "isomorphic-ws";
4
4
  export interface WsToken {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-ex/ws",
3
- "version": "1.3.13",
3
+ "version": "1.3.15",
4
4
  "description": "WebSocket extension for ringcentral-extensible project",
5
5
  "author": "Tyler Liu <tyler.liu@ringcentral.com>",
6
6
  "homepage": "https://github.com/ringcentral/ringcentral-extensible/tree/master/packages/extensions/ws",
@@ -8,9 +8,9 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
- "types": "dist/esm/index.d.ts",
12
- "main": "dist/cjs/index.js",
13
- "module": "dist/esm/index.js",
11
+ "types": "./dist/esm/index.d.ts",
12
+ "main": "./dist/cjs/index.js",
13
+ "module": "./dist/esm/index.js",
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./dist/esm/index.d.ts",
@@ -43,11 +43,11 @@
43
43
  "http-status-codes": "^2.3.0",
44
44
  "hyperid": "^3.3.0",
45
45
  "isomorphic-ws": "^5.0.0",
46
- "wait-for-async": "^0.7.10",
46
+ "wait-for-async": "^0.7.11",
47
47
  "ws": "^8.18.0"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json"
51
51
  },
52
- "gitHead": "7d20cb5dee1f13d16284fdf08835d1c69262712e"
52
+ "gitHead": "ab5ffc28d1b6db97ce54b935f6c63dd0dee19400"
53
53
  }