@emuanalytics/flow-engine-client 1.3.84 → 1.3.94

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/index.js CHANGED
@@ -21,4 +21,5 @@ __exportStar(require("./lib/client"), exports);
21
21
  __exportStar(require("./lib/api-interfaces"), exports);
22
22
  __exportStar(require("./lib/base.endpoints"), exports);
23
23
  __exportStar(require("./lib/errors"), exports);
24
+ __exportStar(require("./lib/web-socket-gateway"), exports);
24
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,+CAA6B;AAC7B,uDAAqC;AACrC,uDAAqC;AACrC,+CAA6B","sourcesContent":["/**\n * Copyright © 2022 Emu Analytics\n */\n\nexport * from './lib/client';\nexport * from './lib/api-interfaces';\nexport * from './lib/base.endpoints';\nexport * from './lib/errors';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,+CAA6B;AAC7B,uDAAqC;AACrC,uDAAqC;AACrC,+CAA6B;AAC7B,2DAAyC","sourcesContent":["/**\n * Copyright © 2022 Emu Analytics\n */\n\nexport * from './lib/client';\nexport * from './lib/api-interfaces';\nexport * from './lib/base.endpoints';\nexport * from './lib/errors';\nexport * from './lib/web-socket-gateway';\n"]}
@@ -59,6 +59,12 @@ var Client = /** @class */ (function () {
59
59
  });
60
60
  this.webSocketGateway = new web_socket_gateway_1.WebSocketGateway(this, options);
61
61
  }
62
+ Client.prototype.connect = function () {
63
+ return this.webSocketGateway.connect();
64
+ };
65
+ Client.prototype.disconnect = function () {
66
+ return this.webSocketGateway.disconnect();
67
+ };
62
68
  Client.prototype.config = function () {
63
69
  return this._get('/api/v1/config');
64
70
  };
@@ -112,15 +118,15 @@ var Client = /** @class */ (function () {
112
118
  };
113
119
  // Subscribe to named channel - errors and messages are delivered via the callback
114
120
  Client.prototype._subscribe = function (channel, cb) {
115
- if (!this.webSocketGateway.isInitialized) {
116
- this.webSocketGateway.initialize();
121
+ if (!this.webSocketGateway.isConnected) {
122
+ this.webSocketGateway.connect();
117
123
  }
118
124
  return this.webSocketGateway.subscribe(channel, cb);
119
125
  };
120
126
  // Unsubscribe from named channel - optional callback is called on completion
121
127
  Client.prototype._unsubscribe = function (channel, cb) {
122
- if (!this.webSocketGateway.isInitialized) {
123
- this.webSocketGateway.initialize();
128
+ if (!this.webSocketGateway.isConnected) {
129
+ this.webSocketGateway.connect();
124
130
  }
125
131
  this.webSocketGateway.unsubscribe(channel, cb);
126
132
  };
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,gDAAyD;AACzD,+BAAuC;AAEvC,uDAAqD;AACrD,6DAA2D;AAC3D,iEAA+D;AAC/D,iDAAgD;AAChD,2DAAyD;AACzD,yDAAuD;AACvD,mCAA2C;AAC3C,iDAA+C;AAC/C,+CAA8C;AAC9C,mDAAkD;AAClD,iEAA8D;AAC9D,mDAAiD;AACjD,uDAAqD;AACrD,2DAM8B;AAI9B;IAqBE,gBAAmB,OAAe,EAAkB,MAA4B,EAAE,OAAuB;QAArD,uBAAA,EAAA,aAA4B;QAA7D,YAAO,GAAP,OAAO,CAAQ;QAAkB,WAAM,GAAN,MAAM,CAAsB;QAnBvE,UAAK,GAAG,IAAA,aAAK,EAAC,oBAAoB,CAAC,CAAC;QAI7C,gBAAW,GAAkB,IAAI,CAAC;QAElC,SAAI,GAAG,IAAI,6BAAa,CAAC,IAAI,CAAC,CAAC;QAC/B,UAAK,GAAG,IAAI,8BAAa,CAAC,IAAI,CAAC,CAAC;QAChC,SAAI,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,CAAC;QAC9B,YAA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AE,CAAC;IACrB,CAAC;IACH,aAAC;AAAD,CAAC,AArKD,IAqKC;AArKY,wBAAM","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport Axios, { AxiosError, AxiosInstance } from 'axios';\nimport { debug as Debug } from 'debug';\nimport { IConfig } from './api-interfaces';\nimport { ApiKeyEndpoints } from './apikey.endpoints';\nimport { AppConfigEndpoints } from './appconfig.endpoints';\nimport { ApplicationEndpoints } from './application.endpoints';\nimport { AuthEndpoints } from './auth.edpoints';\nimport { DatabaseEndpoints } from './database.endpoints';\nimport { DatasetEndpoints } from './dataset.endpoints';\nimport { FlowEngineError } from './errors';\nimport { JobEndpoints } from './job.endpoints';\nimport { MapEndpoints } from './map.endoints';\nimport { StyleEndpoints } from './style.endpoint';\nimport { TileSourceEndpoints } from './tile-source.endpoints';\nimport { TileEndpoints } from './tile.endpoints';\nimport { UploadEndpoints } from './upload.endpoints';\nimport {\n WebSocketGateway,\n WebSocketManagerOptions,\n WebSocketSubscribeCallback,\n WebSocketUnsubscribeCallback,\n WebSocketUnsubscriber\n} from './web-socket-gateway';\n\nexport type ClientOptions = WebSocketManagerOptions;\n\nexport class Client {\n private readonly axios: AxiosInstance;\n readonly debug = Debug('flow-engine-client');\n\n public webSocketGateway: WebSocketGateway;\n\n accessToken: string | null = null;\n\n auth = new AuthEndpoints(this);\n tiles = new TileEndpoints(this);\n maps = new MapEndpoints(this);\n apiKeys = new ApiKeyEndpoints(this);\n applications = new ApplicationEndpoints(this);\n appconfig = new AppConfigEndpoints(this);\n databases = new DatabaseEndpoints(this);\n datasets = new DatasetEndpoints(this);\n styles = new StyleEndpoints(this);\n tileSources = new TileSourceEndpoints(this);\n uploads = new UploadEndpoints(this);\n jobs = new JobEndpoints(this);\n\n constructor(public baseUrl: string, public readonly apiKey: string | null = null, options?: ClientOptions) {\n this.axios = Axios.create({\n baseURL: baseUrl,\n maxContentLength: 524288000\n });\n\n this.webSocketGateway = new WebSocketGateway(this, options);\n }\n\n config(): Promise<IConfig> {\n return this._get('/api/v1/config');\n }\n\n _get(path: string, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'get',\n url: path,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _post(path: string, data: object, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'post',\n url: path,\n data,\n maxContentLength: Infinity,\n maxBodyLength: Infinity,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _put(path: string, data: object, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'put',\n url: path,\n data,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _delete(path: string, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'delete',\n url: path,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n // Subscribe to named channel - errors and messages are delivered via the callback\n _subscribe(channel: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n if (!this.webSocketGateway.isInitialized) {\n this.webSocketGateway.initialize();\n }\n\n return this.webSocketGateway.subscribe(channel, cb);\n }\n\n // Unsubscribe from named channel - optional callback is called on completion\n _unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback) {\n if (!this.webSocketGateway.isInitialized) {\n this.webSocketGateway.initialize();\n }\n this.webSocketGateway.unsubscribe(channel, cb);\n }\n\n /**\n * Normalize errors\n * Throws a new error based on type of input error\n *\n * @param {AxiosError} e\n */\n private handleError(e: AxiosError) {\n // Flow API error\n if (e.response && e.response.data) {\n if (typeof e.response.data === 'object') {\n const data: any = e.response.data;\n throw new FlowEngineError(data.message || data.error, data.error, e.response.status);\n } else if (typeof e.response.data === 'string') {\n throw new FlowEngineError(e.response.data, null, e.response.status);\n }\n }\n\n // Generic error\n\n // Don't leak information in error\n const cleanError: any = e;\n delete cleanError.config;\n delete cleanError.request;\n delete cleanError.response;\n\n throw new FlowEngineError(cleanError.message, cleanError);\n }\n\n private headers(options: any) {\n const headers = options.headers || {};\n\n if (options.apiKey || this.apiKey) {\n headers['X-Api-Key'] = options.apiKey || this.apiKey;\n }\n\n // Add default auth header if token supplied and not already set in options\n if (this.accessToken) {\n headers.Authorization = headers.Authorization || `Bearer ${this.accessToken}`;\n }\n\n return { headers };\n }\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,gDAAyD;AACzD,+BAAuC;AAEvC,uDAAqD;AACrD,6DAA2D;AAC3D,iEAA+D;AAC/D,iDAAgD;AAChD,2DAAyD;AACzD,yDAAuD;AACvD,mCAA2C;AAC3C,iDAA+C;AAC/C,+CAA8C;AAC9C,mDAAkD;AAClD,iEAA8D;AAC9D,mDAAiD;AACjD,uDAAqD;AACrD,2DAM8B;AAI9B;IAqBE,gBAAmB,OAAe,EAAkB,MAA4B,EAAE,OAAuB;QAArD,uBAAA,EAAA,aAA4B;QAA7D,YAAO,GAAP,OAAO,CAAQ;QAAkB,WAAM,GAAN,MAAM,CAAsB;QAnBvE,UAAK,GAAG,IAAA,aAAK,EAAC,oBAAoB,CAAC,CAAC;QAI7C,gBAAW,GAAkB,IAAI,CAAC;QAElC,SAAI,GAAG,IAAI,6BAAa,CAAC,IAAI,CAAC,CAAC;QAC/B,UAAK,GAAG,IAAI,8BAAa,CAAC,IAAI,CAAC,CAAC;QAChC,SAAI,GAAG,IAAI,2BAAY,CAAC,IAA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AAM,CAAC;SACtD;QAED,2EAA2E;QAC3E,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,iBAAU,IAAI,CAAC,WAAW,CAAE,CAAC;SAC/E;QAED,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC;IACrB,CAAC;IACH,aAAC;AAAD,CAAC,AA7KD,IA6KC;AA7KY,wBAAM","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport Axios, { AxiosError, AxiosInstance } from 'axios';\nimport { debug as Debug } from 'debug';\nimport { IConfig } from './api-interfaces';\nimport { ApiKeyEndpoints } from './apikey.endpoints';\nimport { AppConfigEndpoints } from './appconfig.endpoints';\nimport { ApplicationEndpoints } from './application.endpoints';\nimport { AuthEndpoints } from './auth.edpoints';\nimport { DatabaseEndpoints } from './database.endpoints';\nimport { DatasetEndpoints } from './dataset.endpoints';\nimport { FlowEngineError } from './errors';\nimport { JobEndpoints } from './job.endpoints';\nimport { MapEndpoints } from './map.endoints';\nimport { StyleEndpoints } from './style.endpoint';\nimport { TileSourceEndpoints } from './tile-source.endpoints';\nimport { TileEndpoints } from './tile.endpoints';\nimport { UploadEndpoints } from './upload.endpoints';\nimport {\n WebSocketGateway,\n WebSocketManagerOptions,\n WebSocketSubscribeCallback,\n WebSocketUnsubscribeCallback,\n WebSocketUnsubscriber\n} from './web-socket-gateway';\n\nexport type ClientOptions = WebSocketManagerOptions;\n\nexport class Client {\n private readonly axios: AxiosInstance;\n readonly debug = Debug('flow-engine-client');\n\n public webSocketGateway: WebSocketGateway;\n\n accessToken: string | null = null;\n\n auth = new AuthEndpoints(this);\n tiles = new TileEndpoints(this);\n maps = new MapEndpoints(this);\n apiKeys = new ApiKeyEndpoints(this);\n applications = new ApplicationEndpoints(this);\n appconfig = new AppConfigEndpoints(this);\n databases = new DatabaseEndpoints(this);\n datasets = new DatasetEndpoints(this);\n styles = new StyleEndpoints(this);\n tileSources = new TileSourceEndpoints(this);\n uploads = new UploadEndpoints(this);\n jobs = new JobEndpoints(this);\n\n constructor(public baseUrl: string, public readonly apiKey: string | null = null, options?: ClientOptions) {\n this.axios = Axios.create({\n baseURL: baseUrl,\n maxContentLength: 524288000\n });\n\n this.webSocketGateway = new WebSocketGateway(this, options);\n }\n\n connect(): Promise<void> {\n return this.webSocketGateway.connect();\n }\n\n disconnect(): Promise<void> {\n return this.webSocketGateway.disconnect();\n }\n\n config(): Promise<IConfig> {\n return this._get('/api/v1/config');\n }\n\n _get(path: string, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'get',\n url: path,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _post(path: string, data: object, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'post',\n url: path,\n data,\n maxContentLength: Infinity,\n maxBodyLength: Infinity,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _put(path: string, data: object, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'put',\n url: path,\n data,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _delete(path: string, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'delete',\n url: path,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n // Subscribe to named channel - errors and messages are delivered via the callback\n _subscribe(channel: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n if (!this.webSocketGateway.isConnected) {\n this.webSocketGateway.connect();\n }\n\n return this.webSocketGateway.subscribe(channel, cb);\n }\n\n // Unsubscribe from named channel - optional callback is called on completion\n _unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback) {\n if (!this.webSocketGateway.isConnected) {\n this.webSocketGateway.connect();\n }\n this.webSocketGateway.unsubscribe(channel, cb);\n }\n\n /**\n * Normalize errors\n * Throws a new error based on type of input error\n *\n * @param {AxiosError} e\n */\n private handleError(e: AxiosError) {\n // Flow API error\n if (e.response && e.response.data) {\n if (typeof e.response.data === 'object') {\n const data: any = e.response.data;\n throw new FlowEngineError(data.message || data.error, data.error, e.response.status);\n } else if (typeof e.response.data === 'string') {\n throw new FlowEngineError(e.response.data, null, e.response.status);\n }\n }\n\n // Generic error\n\n // Don't leak information in error\n const cleanError: any = e;\n delete cleanError.config;\n delete cleanError.request;\n delete cleanError.response;\n\n throw new FlowEngineError(cleanError.message, cleanError);\n }\n\n private headers(options: any) {\n const headers = options.headers || {};\n\n if (options.apiKey || this.apiKey) {\n headers['X-Api-Key'] = options.apiKey || this.apiKey;\n }\n\n // Add default auth header if token supplied and not already set in options\n if (this.accessToken) {\n headers.Authorization = headers.Authorization || `Bearer ${this.accessToken}`;\n }\n\n return { headers };\n }\n}\n"]}
@@ -29,7 +29,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
29
29
  function verb(n) { return function (v) { return step([n, v]); }; }
30
30
  function step(op) {
31
31
  if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
33
  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;
34
34
  if (y = 0, t) op = [op[0] & 2, t.value];
35
35
  switch (op[0]) {
@@ -23,67 +23,89 @@ var WebSocketGateway = /** @class */ (function () {
23
23
  function WebSocketGateway(client, options) {
24
24
  this.client = client;
25
25
  this.options = options;
26
- this.initialized = false;
26
+ this.connected = false;
27
27
  this.subscribedChannels = new Set();
28
28
  }
29
- Object.defineProperty(WebSocketGateway.prototype, "isInitialized", {
29
+ Object.defineProperty(WebSocketGateway.prototype, "isConnected", {
30
30
  get: function () {
31
- return this.initialized;
31
+ return this.connected;
32
32
  },
33
33
  enumerable: false,
34
34
  configurable: true
35
35
  });
36
- WebSocketGateway.prototype.initialize = function () {
36
+ WebSocketGateway.prototype.connect = function () {
37
37
  var _this = this;
38
- var socket = (0, socket_io_client_1.io)(this.client.baseUrl, __assign(__assign({}, this.options), { auth: function (cb) {
39
- var authHeaders = {};
40
- if (_this.client.apiKey) {
41
- authHeaders['x-api-key'] = _this.client.apiKey;
42
- }
43
- if (_this.client.accessToken) {
44
- authHeaders['x-socket-token'] = "Bearer ".concat(_this.client.accessToken);
45
- }
46
- cb(authHeaders);
47
- } }));
48
- socket.on('connect', function () {
49
- _this.client.debug("Socket connected: ".concat(socket.id));
50
- if (_this.subscribedChannels.size) {
51
- _this.subscribedChannels.forEach(function (channel) {
52
- socket.emit('subscribe', { channel: channel }, function (resp) {
53
- if (resp.status === 'error') {
54
- console.error("Error re-subscribing to channel '".concat(channel), resp);
55
- }
56
- else {
57
- _this.client.debug("Re-subscribed to channel '".concat(channel));
58
- }
38
+ if (this.isConnected) {
39
+ return Promise.resolve();
40
+ }
41
+ return new Promise(function (resolve, reject) {
42
+ var socket = (0, socket_io_client_1.io)(_this.client.baseUrl, __assign(__assign({}, _this.options), { autoConnect: false, auth: function (cb) {
43
+ var authHeaders = {};
44
+ if (_this.client.apiKey) {
45
+ authHeaders['x-api-key'] = _this.client.apiKey;
46
+ }
47
+ if (_this.client.accessToken) {
48
+ authHeaders['x-socket-token'] = "Bearer ".concat(_this.client.accessToken);
49
+ }
50
+ cb(authHeaders);
51
+ } }));
52
+ socket.on('connect', function () {
53
+ _this.client.debug("Socket connected: ".concat(socket.id));
54
+ if (_this.subscribedChannels.size) {
55
+ _this.subscribedChannels.forEach(function (channel) {
56
+ socket.emit('subscribe', { channel: channel }, function (resp) {
57
+ if (resp.status === 'error') {
58
+ console.error("Error re-subscribing to channel '".concat(channel), resp);
59
+ }
60
+ else {
61
+ _this.client.debug("Re-subscribed to channel '".concat(channel));
62
+ }
63
+ });
59
64
  });
60
- });
61
- }
62
- });
63
- socket.io.on('reconnect_attempt', function (attempt) {
64
- _this.client.debug("Socket reconnect attempt: ".concat(attempt));
65
- });
66
- socket.io.on('reconnect_error', function (error) {
67
- _this.client.debug("Socket reconnect error: ".concat(error.message));
68
- });
69
- socket.io.on('reconnect_failed', function () {
70
- _this.client.debug("Socket reconnect failed");
71
- });
72
- socket.io.on('reconnect', function () {
73
- _this.client.debug("Socket reconnected");
74
- });
75
- socket.on('disconnect', function (reason) {
76
- _this.client.debug("Socket disconnected: ".concat(reason));
65
+ }
66
+ });
67
+ socket.io.on('reconnect_attempt', function (attempt) {
68
+ _this.client.debug("Socket reconnect attempt: ".concat(attempt));
69
+ });
70
+ socket.io.on('reconnect_error', function (error) {
71
+ _this.client.debug("Socket reconnect error: ".concat(error.message));
72
+ });
73
+ socket.io.on('reconnect_failed', function () {
74
+ _this.client.debug("Socket reconnect failed");
75
+ });
76
+ socket.io.on('reconnect', function () {
77
+ _this.client.debug("Socket reconnected");
78
+ });
79
+ socket.on('disconnect', function (reason) {
80
+ _this.client.debug("Socket disconnected: ".concat(reason));
81
+ });
82
+ socket.on('error', function (e) {
83
+ _this.client.debug("Socket error: ".concat(e.messaage));
84
+ });
85
+ _this.socket = socket;
86
+ _this.connected = true;
87
+ socket.on('connect', function () {
88
+ resolve();
89
+ });
90
+ socket.connect();
77
91
  });
78
- socket.on('error', function (e) {
79
- _this.client.debug("Socket error: ".concat(e.messaage));
92
+ };
93
+ WebSocketGateway.prototype.disconnect = function () {
94
+ var _this = this;
95
+ if (!this.isConnected) {
96
+ return Promise.resolve();
97
+ }
98
+ return new Promise(function (resolve) {
99
+ _this.socket.once('disconnect', function () {
100
+ _this.connected = false;
101
+ resolve();
102
+ });
103
+ _this.socket.disconnect();
80
104
  });
81
- this.socket = socket;
82
- this.initialized = true;
83
105
  };
84
106
  WebSocketGateway.prototype.subscribe = function (channel, cb) {
85
107
  var _this = this;
86
- if (!this.isInitialized) {
108
+ if (!this.isConnected) {
87
109
  throw new Error('WebSocketGateway is not initialized');
88
110
  }
89
111
  this.client.debug("Subscribing to channel '".concat(channel));
@@ -112,7 +134,7 @@ var WebSocketGateway = /** @class */ (function () {
112
134
  };
113
135
  WebSocketGateway.prototype.unsubscribe = function (channel, cb) {
114
136
  var _this = this;
115
- if (!this.isInitialized) {
137
+ if (!this.isConnected) {
116
138
  throw new Error('WebSocketGateway is not initialized');
117
139
  }
118
140
  this.client.debug("Unsubscribing from channel '".concat(channel));
@@ -1 +1 @@
1
- {"version":3,"file":"web-socket-gateway.js","sourceRoot":"","sources":["../../../src/lib/web-socket-gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qDAA6E;AAG7E,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,qCAAiB,CAAA;IACjB,2CAAuB,CAAA;IACvB,wCAAoB,CAAA;AACtB,CAAC,EAJW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAI3B;AA4BD;IAUE,0BAA4B,MAAc,EAAmB,OAAiC;QAAlE,WAAM,GAAN,MAAM,CAAQ;QAAmB,YAAO,GAAP,OAAO,CAA0B;QATtF,gBAAW,GAAG,KAAK,CAAC;QACpB,uBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;IAQkD,CAAC;IAJlG,sBAAI,2CAAa;aAAjB;YACE,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;;;OAAA;IAID,qCAAU,GAAV;QAAA,iBA6DC;QA5DC,IAAM,MAAM,GAAG,IAAA,qBAAE,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,wBAChC,IAAI,CAAC,OAAO,KACf,IAAI,EAAE,UAAA,EAAE;gBACN,IAAM,WAAW,GAA2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,IAAI,CAAC,CAAC;gBACxE,IAAI,EAAE,EAAE;oBACN,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;iBAC7B;aACF;iBAAM;gBACL,KAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACxC,KAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qCAA8B,OAAO,CAAE,CAAC,CAAC;gBAC3D,IAAI,EAAE,EAAE;oBACN,EAAE,CAAC,IAAI,CAAC,CAAC;iBACV;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACH,uBAAC;AAAD,CAAC,AAnID,IAmIC;AAnIY,4CAAgB","sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from 'socket.io-client';\nimport { Client } from './client';\n\nexport enum WebSocketChannel {\n System = 'system',\n AppConfig = 'appconfig',\n Dataset = 'dataset/'\n}\n\nexport interface WebSocketPublishMessage {\n channel: string;\n messageType?: string;\n payload: unknown;\n}\n\nexport interface WebSocketSubscribeMessage {\n channel: string;\n}\n\nexport interface WebSocketErrorResponse {\n status: 'error';\n code: string;\n message: string;\n}\n\nexport interface WebSocketOkResponse {\n status: 'ok';\n}\n\nexport type WebSocketResponse = WebSocketOkResponse | WebSocketErrorResponse;\nexport type WebSocketManagerOptions = Partial<ManagerOptions & SocketOptions>;\nexport type WebSocketSubscribeCallback = (err: Error | null, msg?: WebSocketPublishMessage) => void;\nexport type WebSocketUnsubscribeCallback = (err: Error | null) => void;\nexport type WebSocketUnsubscriber = (cb?: WebSocketUnsubscribeCallback) => void;\n\nexport class WebSocketGateway {\n private initialized = false;\n private subscribedChannels = new Set<string>();\n\n socket!: Socket;\n\n get isInitialized(): boolean {\n return this.initialized;\n }\n\n constructor(public readonly client: Client, private readonly options?: WebSocketManagerOptions) {}\n\n initialize() {\n const socket = io(this.client.baseUrl, {\n ...this.options,\n auth: cb => {\n const authHeaders: Record<string, string> = {};\n\n if (this.client.apiKey) {\n authHeaders['x-api-key'] = this.client.apiKey;\n }\n\n if (this.client.accessToken) {\n authHeaders['x-socket-token'] = `Bearer ${this.client.accessToken}`;\n }\n\n cb(authHeaders);\n }\n });\n\n socket.on('connect', () => {\n this.client.debug(`Socket connected: ${socket.id}`);\n\n if (this.subscribedChannels.size) {\n this.subscribedChannels.forEach(channel => {\n socket.emit('subscribe', { channel }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n console.error(`Error re-subscribing to channel '${channel}`, resp);\n } else {\n this.client.debug(`Re-subscribed to channel '${channel}`);\n }\n });\n });\n }\n });\n\n socket.io.on('reconnect_attempt', (attempt: number) => {\n this.client.debug(`Socket reconnect attempt: ${attempt}`);\n });\n\n socket.io.on('reconnect_error', (error: Error) => {\n this.client.debug(`Socket reconnect error: ${error.message}`);\n });\n\n socket.io.on('reconnect_failed', () => {\n this.client.debug(`Socket reconnect failed`);\n });\n\n socket.io.on('reconnect', () => {\n this.client.debug(`Socket reconnected`);\n });\n\n socket.on('disconnect', reason => {\n this.client.debug(`Socket disconnected: ${reason}`);\n });\n\n socket.on('error', e => {\n this.client.debug(`Socket error: ${e.messaage}`);\n });\n\n this.socket = socket;\n\n this.initialized = true;\n }\n\n subscribe(channel: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n if (!this.isInitialized) {\n throw new Error('WebSocketGateway is not initialized');\n }\n\n this.client.debug(`Subscribing to channel '${channel}`);\n\n // Discriminating 'message' event listener that only responds to messages sent to 'channel'\n const listener = (msg: WebSocketPublishMessage) => {\n if (msg.channel === channel) {\n cb(null, msg);\n }\n };\n\n // Unsubscriber\n const unsubscribe = (unsubscribeCb?: WebSocketUnsubscribeCallback) => {\n this.socket.off('message', listener);\n this.unsubscribe(channel, unsubscribeCb);\n };\n\n // Subscribe and bind listener\n this.socket.emit('subscribe', { channel }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.client.debug(`Error subscribed to channel '${channel}`, resp);\n return cb(new Error(resp.message));\n }\n\n this.subscribedChannels.add(channel);\n this.client.debug(`Subscribed to channel '${channel}`);\n this.socket.on('message', listener);\n });\n\n return unsubscribe;\n }\n\n unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback) {\n if (!this.isInitialized) {\n throw new Error('WebSocketGateway is not initialized');\n }\n\n this.client.debug(`Unsubscribing from channel '${channel}`);\n this.socket.emit('unsubscribe', { channel }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.client.debug(`Error unsubscribing from channel '${channel}`, resp);\n if (cb) {\n cb(new Error(resp.message));\n }\n } else {\n this.subscribedChannels.delete(channel);\n this.client.debug(`Unsubscribed from channel '${channel}`);\n if (cb) {\n cb(null);\n }\n }\n });\n }\n}\n"]}
1
+ {"version":3,"file":"web-socket-gateway.js","sourceRoot":"","sources":["../../../src/lib/web-socket-gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qDAA6E;AAG7E,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,qCAAiB,CAAA;IACjB,2CAAuB,CAAA;IACvB,wCAAoB,CAAA;AACtB,CAAC,EAJW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAI3B;AA4BD;IAUE,0BAA4B,MAAc,EAAmB,OAAiC;QAAlE,WAAM,GAAN,MAAM,CAAQ;QAAmB,YAAO,GAAP,OAAO,CAA0B;QATtF,cAAS,GAAG,KAAK,CAAC;QAClB,uBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;IAQkD,CAAC;IAJlG,sBAAI,yCAAW;aAAf;YACE,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;;;OAAA;IAID,kCAAO,GAAP;QAAA,iBA0EC;QAzEC,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC1B;QAED,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YACjC,IAAM,MAAM,GAAG,IAAA,qBAAE,EAAC,KAAI,CAAC,M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OAAO,CAAC,CAAC;YACrC,KAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAA0B,OAAO,CAAE,CAAC,CAAC;YACvD,KAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,sCAAW,GAAX,UAAY,OAAe,EAAE,EAAiC;QAA9D,iBAoBC;QAnBC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;SACxD;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sCAA+B,OAAO,CAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,OAAO,SAAA,EAAE,EAAE,UAAC,IAAuB;YACnE,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,EAAE;gBAC3B,KAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4CAAqC,OAAO,CAAE,EAAE,IAAI,CAAC,CAAC;gBACxE,IAAI,EAAE,EAAE;oBACN,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;iBAC7B;aACF;iBAAM;gBACL,KAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACxC,KAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qCAA8B,OAAO,CAAE,CAAC,CAAC;gBAC3D,IAAI,EAAE,EAAE;oBACN,EAAE,CAAC,IAAI,CAAC,CAAC;iBACV;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACH,uBAAC;AAAD,CAAC,AA9JD,IA8JC;AA9JY,4CAAgB","sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from 'socket.io-client';\nimport { Client } from './client';\n\nexport enum WebSocketChannel {\n System = 'system',\n AppConfig = 'appconfig',\n Dataset = 'dataset/'\n}\n\nexport interface WebSocketPublishMessage {\n channel: string;\n messageType?: string;\n payload: unknown;\n}\n\nexport interface WebSocketSubscribeMessage {\n channel: string;\n}\n\nexport interface WebSocketErrorResponse {\n status: 'error';\n code: string;\n message: string;\n}\n\nexport interface WebSocketOkResponse {\n status: 'ok';\n}\n\nexport type WebSocketResponse = WebSocketOkResponse | WebSocketErrorResponse;\nexport type WebSocketManagerOptions = Partial<ManagerOptions & SocketOptions>;\nexport type WebSocketSubscribeCallback = (err: Error | null, msg?: WebSocketPublishMessage) => void;\nexport type WebSocketUnsubscribeCallback = (err: Error | null) => void;\nexport type WebSocketUnsubscriber = (cb?: WebSocketUnsubscribeCallback) => void;\n\nexport class WebSocketGateway {\n private connected = false;\n private subscribedChannels = new Set<string>();\n\n socket!: Socket;\n\n get isConnected(): boolean {\n return this.connected;\n }\n\n constructor(public readonly client: Client, private readonly options?: WebSocketManagerOptions) {}\n\n connect(): Promise<void> {\n if (this.isConnected) {\n return Promise.resolve();\n }\n\n return new Promise((resolve, reject) => {\n const socket = io(this.client.baseUrl, {\n ...this.options,\n autoConnect: false,\n auth: cb => {\n const authHeaders: Record<string, string> = {};\n\n if (this.client.apiKey) {\n authHeaders['x-api-key'] = this.client.apiKey;\n }\n\n if (this.client.accessToken) {\n authHeaders['x-socket-token'] = `Bearer ${this.client.accessToken}`;\n }\n\n cb(authHeaders);\n }\n });\n\n socket.on('connect', () => {\n this.client.debug(`Socket connected: ${socket.id}`);\n\n if (this.subscribedChannels.size) {\n this.subscribedChannels.forEach(channel => {\n socket.emit('subscribe', { channel }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n console.error(`Error re-subscribing to channel '${channel}`, resp);\n } else {\n this.client.debug(`Re-subscribed to channel '${channel}`);\n }\n });\n });\n }\n });\n\n socket.io.on('reconnect_attempt', (attempt: number) => {\n this.client.debug(`Socket reconnect attempt: ${attempt}`);\n });\n\n socket.io.on('reconnect_error', (error: Error) => {\n this.client.debug(`Socket reconnect error: ${error.message}`);\n });\n\n socket.io.on('reconnect_failed', () => {\n this.client.debug(`Socket reconnect failed`);\n });\n\n socket.io.on('reconnect', () => {\n this.client.debug(`Socket reconnected`);\n });\n\n socket.on('disconnect', reason => {\n this.client.debug(`Socket disconnected: ${reason}`);\n });\n\n socket.on('error', e => {\n this.client.debug(`Socket error: ${e.messaage}`);\n });\n\n this.socket = socket;\n\n this.connected = true;\n\n socket.on('connect', () => {\n resolve();\n });\n\n socket.connect();\n });\n }\n\n disconnect(): Promise<void> {\n if (!this.isConnected) {\n return Promise.resolve();\n }\n\n return new Promise(resolve => {\n this.socket.once('disconnect', () => {\n this.connected = false;\n resolve();\n });\n this.socket.disconnect();\n });\n }\n\n subscribe(channel: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n if (!this.isConnected) {\n throw new Error('WebSocketGateway is not initialized');\n }\n\n this.client.debug(`Subscribing to channel '${channel}`);\n\n // Discriminating 'message' event listener that only responds to messages sent to 'channel'\n const listener = (msg: WebSocketPublishMessage) => {\n if (msg.channel === channel) {\n cb(null, msg);\n }\n };\n\n // Unsubscriber\n const unsubscribe = (unsubscribeCb?: WebSocketUnsubscribeCallback) => {\n this.socket.off('message', listener);\n this.unsubscribe(channel, unsubscribeCb);\n };\n\n // Subscribe and bind listener\n this.socket.emit('subscribe', { channel }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.client.debug(`Error subscribed to channel '${channel}`, resp);\n return cb(new Error(resp.message));\n }\n\n this.subscribedChannels.add(channel);\n this.client.debug(`Subscribed to channel '${channel}`);\n this.socket.on('message', listener);\n });\n\n return unsubscribe;\n }\n\n unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback) {\n if (!this.isConnected) {\n throw new Error('WebSocketGateway is not initialized');\n }\n\n this.client.debug(`Unsubscribing from channel '${channel}`);\n this.socket.emit('unsubscribe', { channel }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.client.debug(`Error unsubscribing from channel '${channel}`, resp);\n if (cb) {\n cb(new Error(resp.message));\n }\n } else {\n this.subscribedChannels.delete(channel);\n this.client.debug(`Unsubscribed from channel '${channel}`);\n if (cb) {\n cb(null);\n }\n }\n });\n }\n}\n"]}
package/dist/esm/index.js CHANGED
@@ -5,4 +5,5 @@ export * from './lib/client';
5
5
  export * from './lib/api-interfaces';
6
6
  export * from './lib/base.endpoints';
7
7
  export * from './lib/errors';
8
+ export * from './lib/web-socket-gateway';
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC","sourcesContent":["/**\n * Copyright © 2022 Emu Analytics\n */\n\nexport * from './lib/client';\nexport * from './lib/api-interfaces';\nexport * from './lib/base.endpoints';\nexport * from './lib/errors';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC","sourcesContent":["/**\n * Copyright © 2022 Emu Analytics\n */\n\nexport * from './lib/client';\nexport * from './lib/api-interfaces';\nexport * from './lib/base.endpoints';\nexport * from './lib/errors';\nexport * from './lib/web-socket-gateway';\n"]}
@@ -53,6 +53,12 @@ var Client = /** @class */ (function () {
53
53
  });
54
54
  this.webSocketGateway = new WebSocketGateway(this, options);
55
55
  }
56
+ Client.prototype.connect = function () {
57
+ return this.webSocketGateway.connect();
58
+ };
59
+ Client.prototype.disconnect = function () {
60
+ return this.webSocketGateway.disconnect();
61
+ };
56
62
  Client.prototype.config = function () {
57
63
  return this._get('/api/v1/config');
58
64
  };
@@ -106,15 +112,15 @@ var Client = /** @class */ (function () {
106
112
  };
107
113
  // Subscribe to named channel - errors and messages are delivered via the callback
108
114
  Client.prototype._subscribe = function (channel, cb) {
109
- if (!this.webSocketGateway.isInitialized) {
110
- this.webSocketGateway.initialize();
115
+ if (!this.webSocketGateway.isConnected) {
116
+ this.webSocketGateway.connect();
111
117
  }
112
118
  return this.webSocketGateway.subscribe(channel, cb);
113
119
  };
114
120
  // Unsubscribe from named channel - optional callback is called on completion
115
121
  Client.prototype._unsubscribe = function (channel, cb) {
116
- if (!this.webSocketGateway.isInitialized) {
117
- this.webSocketGateway.initialize();
122
+ if (!this.webSocketGateway.isConnected) {
123
+ this.webSocketGateway.connect();
118
124
  }
119
125
  this.webSocketGateway.unsubscribe(channel, cb);
120
126
  };
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;;;AAEH,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,y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CAAC,OAAO,CAAC;QAC1B,OAAO,UAAU,CAAC,QAAQ,CAAC;QAE3B,MAAM,IAAI,eAAe,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC5D,CAAC;IAEO,wBAAO,GAAf,UAAgB,OAAY;QAC1B,IAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAEtC,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE;YACjC,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;SACtD;QAED,2EAA2E;QAC3E,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,iBAAU,IAAI,CAAC,WAAW,CAAE,CAAC;SAC/E;QAED,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC;IACrB,CAAC;IACH,aAAC;AAAD,CAAC,AArKD,IAqKC","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport Axios, { AxiosError, AxiosInstance } from 'axios';\nimport { debug as Debug } from 'debug';\nimport { IConfig } from './api-interfaces';\nimport { ApiKeyEndpoints } from './apikey.endpoints';\nimport { AppConfigEndpoints } from './appconfig.endpoints';\nimport { ApplicationEndpoints } from './application.endpoints';\nimport { AuthEndpoints } from './auth.edpoints';\nimport { DatabaseEndpoints } from './database.endpoints';\nimport { DatasetEndpoints } from './dataset.endpoints';\nimport { FlowEngineError } from './errors';\nimport { JobEndpoints } from './job.endpoints';\nimport { MapEndpoints } from './map.endoints';\nimport { StyleEndpoints } from './style.endpoint';\nimport { TileSourceEndpoints } from './tile-source.endpoints';\nimport { TileEndpoints } from './tile.endpoints';\nimport { UploadEndpoints } from './upload.endpoints';\nimport {\n WebSocketGateway,\n WebSocketManagerOptions,\n WebSocketSubscribeCallback,\n WebSocketUnsubscribeCallback,\n WebSocketUnsubscriber\n} from './web-socket-gateway';\n\nexport type ClientOptions = WebSocketManagerOptions;\n\nexport class Client {\n private readonly axios: AxiosInstance;\n readonly debug = Debug('flow-engine-client');\n\n public webSocketGateway: WebSocketGateway;\n\n accessToken: string | null = null;\n\n auth = new AuthEndpoints(this);\n tiles = new TileEndpoints(this);\n maps = new MapEndpoints(this);\n apiKeys = new ApiKeyEndpoints(this);\n applications = new ApplicationEndpoints(this);\n appconfig = new AppConfigEndpoints(this);\n databases = new DatabaseEndpoints(this);\n datasets = new DatasetEndpoints(this);\n styles = new StyleEndpoints(this);\n tileSources = new TileSourceEndpoints(this);\n uploads = new UploadEndpoints(this);\n jobs = new JobEndpoints(this);\n\n constructor(public baseUrl: string, public readonly apiKey: string | null = null, options?: ClientOptions) {\n this.axios = Axios.create({\n baseURL: baseUrl,\n maxContentLength: 524288000\n });\n\n this.webSocketGateway = new WebSocketGateway(this, options);\n }\n\n config(): Promise<IConfig> {\n return this._get('/api/v1/config');\n }\n\n _get(path: string, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'get',\n url: path,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _post(path: string, data: object, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'post',\n url: path,\n data,\n maxContentLength: Infinity,\n maxBodyLength: Infinity,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _put(path: string, data: object, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'put',\n url: path,\n data,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _delete(path: string, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'delete',\n url: path,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n // Subscribe to named channel - errors and messages are delivered via the callback\n _subscribe(channel: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n if (!this.webSocketGateway.isInitialized) {\n this.webSocketGateway.initialize();\n }\n\n return this.webSocketGateway.subscribe(channel, cb);\n }\n\n // Unsubscribe from named channel - optional callback is called on completion\n _unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback) {\n if (!this.webSocketGateway.isInitialized) {\n this.webSocketGateway.initialize();\n }\n this.webSocketGateway.unsubscribe(channel, cb);\n }\n\n /**\n * Normalize errors\n * Throws a new error based on type of input error\n *\n * @param {AxiosError} e\n */\n private handleError(e: AxiosError) {\n // Flow API error\n if (e.response && e.response.data) {\n if (typeof e.response.data === 'object') {\n const data: any = e.response.data;\n throw new FlowEngineError(data.message || data.error, data.error, e.response.status);\n } else if (typeof e.response.data === 'string') {\n throw new FlowEngineError(e.response.data, null, e.response.status);\n }\n }\n\n // Generic error\n\n // Don't leak information in error\n const cleanError: any = e;\n delete cleanError.config;\n delete cleanError.request;\n delete cleanError.response;\n\n throw new FlowEngineError(cleanError.message, cleanError);\n }\n\n private headers(options: any) {\n const headers = options.headers || {};\n\n if (options.apiKey || this.apiKey) {\n headers['X-Api-Key'] = options.apiKey || this.apiKey;\n }\n\n // Add default auth header if token supplied and not already set in options\n if (this.accessToken) {\n headers.Authorization = headers.Authorization || `Bearer ${this.accessToken}`;\n }\n\n return { headers };\n }\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;;;AAEH,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAA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,IAAI,iBAAU,IAAI,CAAC,WAAW,CAAE,CAAC;SAC/E;QAED,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC;IACrB,CAAC;IACH,aAAC;AAAD,CAAC,AA7KD,IA6KC","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport Axios, { AxiosError, AxiosInstance } from 'axios';\nimport { debug as Debug } from 'debug';\nimport { IConfig } from './api-interfaces';\nimport { ApiKeyEndpoints } from './apikey.endpoints';\nimport { AppConfigEndpoints } from './appconfig.endpoints';\nimport { ApplicationEndpoints } from './application.endpoints';\nimport { AuthEndpoints } from './auth.edpoints';\nimport { DatabaseEndpoints } from './database.endpoints';\nimport { DatasetEndpoints } from './dataset.endpoints';\nimport { FlowEngineError } from './errors';\nimport { JobEndpoints } from './job.endpoints';\nimport { MapEndpoints } from './map.endoints';\nimport { StyleEndpoints } from './style.endpoint';\nimport { TileSourceEndpoints } from './tile-source.endpoints';\nimport { TileEndpoints } from './tile.endpoints';\nimport { UploadEndpoints } from './upload.endpoints';\nimport {\n WebSocketGateway,\n WebSocketManagerOptions,\n WebSocketSubscribeCallback,\n WebSocketUnsubscribeCallback,\n WebSocketUnsubscriber\n} from './web-socket-gateway';\n\nexport type ClientOptions = WebSocketManagerOptions;\n\nexport class Client {\n private readonly axios: AxiosInstance;\n readonly debug = Debug('flow-engine-client');\n\n public webSocketGateway: WebSocketGateway;\n\n accessToken: string | null = null;\n\n auth = new AuthEndpoints(this);\n tiles = new TileEndpoints(this);\n maps = new MapEndpoints(this);\n apiKeys = new ApiKeyEndpoints(this);\n applications = new ApplicationEndpoints(this);\n appconfig = new AppConfigEndpoints(this);\n databases = new DatabaseEndpoints(this);\n datasets = new DatasetEndpoints(this);\n styles = new StyleEndpoints(this);\n tileSources = new TileSourceEndpoints(this);\n uploads = new UploadEndpoints(this);\n jobs = new JobEndpoints(this);\n\n constructor(public baseUrl: string, public readonly apiKey: string | null = null, options?: ClientOptions) {\n this.axios = Axios.create({\n baseURL: baseUrl,\n maxContentLength: 524288000\n });\n\n this.webSocketGateway = new WebSocketGateway(this, options);\n }\n\n connect(): Promise<void> {\n return this.webSocketGateway.connect();\n }\n\n disconnect(): Promise<void> {\n return this.webSocketGateway.disconnect();\n }\n\n config(): Promise<IConfig> {\n return this._get('/api/v1/config');\n }\n\n _get(path: string, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'get',\n url: path,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _post(path: string, data: object, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'post',\n url: path,\n data,\n maxContentLength: Infinity,\n maxBodyLength: Infinity,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _put(path: string, data: object, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'put',\n url: path,\n data,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n _delete(path: string, options: any = {}): Promise<any> {\n // Move apiKey from params\n if (options.params?.apiKey) {\n options.apiKey = options.params.apiKey;\n delete options.params.apiKey;\n }\n\n return this.axios({\n method: 'delete',\n url: path,\n ...options,\n ...this.headers(options)\n })\n .then(res => res.data)\n .catch(this.handleError);\n }\n\n // Subscribe to named channel - errors and messages are delivered via the callback\n _subscribe(channel: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n if (!this.webSocketGateway.isConnected) {\n this.webSocketGateway.connect();\n }\n\n return this.webSocketGateway.subscribe(channel, cb);\n }\n\n // Unsubscribe from named channel - optional callback is called on completion\n _unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback) {\n if (!this.webSocketGateway.isConnected) {\n this.webSocketGateway.connect();\n }\n this.webSocketGateway.unsubscribe(channel, cb);\n }\n\n /**\n * Normalize errors\n * Throws a new error based on type of input error\n *\n * @param {AxiosError} e\n */\n private handleError(e: AxiosError) {\n // Flow API error\n if (e.response && e.response.data) {\n if (typeof e.response.data === 'object') {\n const data: any = e.response.data;\n throw new FlowEngineError(data.message || data.error, data.error, e.response.status);\n } else if (typeof e.response.data === 'string') {\n throw new FlowEngineError(e.response.data, null, e.response.status);\n }\n }\n\n // Generic error\n\n // Don't leak information in error\n const cleanError: any = e;\n delete cleanError.config;\n delete cleanError.request;\n delete cleanError.response;\n\n throw new FlowEngineError(cleanError.message, cleanError);\n }\n\n private headers(options: any) {\n const headers = options.headers || {};\n\n if (options.apiKey || this.apiKey) {\n headers['X-Api-Key'] = options.apiKey || this.apiKey;\n }\n\n // Add default auth header if token supplied and not already set in options\n if (this.accessToken) {\n headers.Authorization = headers.Authorization || `Bearer ${this.accessToken}`;\n }\n\n return { headers };\n }\n}\n"]}
@@ -28,7 +28,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
28
28
  function verb(n) { return function (v) { return step([n, v]); }; }
29
29
  function step(op) {
30
30
  if (f) throw new TypeError("Generator is already executing.");
31
- while (_) try {
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
32
  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;
33
33
  if (y = 0, t) op = [op[0] & 2, t.value];
34
34
  switch (op[0]) {
@@ -20,67 +20,89 @@ var WebSocketGateway = /** @class */ (function () {
20
20
  function WebSocketGateway(client, options) {
21
21
  this.client = client;
22
22
  this.options = options;
23
- this.initialized = false;
23
+ this.connected = false;
24
24
  this.subscribedChannels = new Set();
25
25
  }
26
- Object.defineProperty(WebSocketGateway.prototype, "isInitialized", {
26
+ Object.defineProperty(WebSocketGateway.prototype, "isConnected", {
27
27
  get: function () {
28
- return this.initialized;
28
+ return this.connected;
29
29
  },
30
30
  enumerable: false,
31
31
  configurable: true
32
32
  });
33
- WebSocketGateway.prototype.initialize = function () {
33
+ WebSocketGateway.prototype.connect = function () {
34
34
  var _this = this;
35
- var socket = io(this.client.baseUrl, __assign(__assign({}, this.options), { auth: function (cb) {
36
- var authHeaders = {};
37
- if (_this.client.apiKey) {
38
- authHeaders['x-api-key'] = _this.client.apiKey;
39
- }
40
- if (_this.client.accessToken) {
41
- authHeaders['x-socket-token'] = "Bearer ".concat(_this.client.accessToken);
42
- }
43
- cb(authHeaders);
44
- } }));
45
- socket.on('connect', function () {
46
- _this.client.debug("Socket connected: ".concat(socket.id));
47
- if (_this.subscribedChannels.size) {
48
- _this.subscribedChannels.forEach(function (channel) {
49
- socket.emit('subscribe', { channel: channel }, function (resp) {
50
- if (resp.status === 'error') {
51
- console.error("Error re-subscribing to channel '".concat(channel), resp);
52
- }
53
- else {
54
- _this.client.debug("Re-subscribed to channel '".concat(channel));
55
- }
35
+ if (this.isConnected) {
36
+ return Promise.resolve();
37
+ }
38
+ return new Promise(function (resolve, reject) {
39
+ var socket = io(_this.client.baseUrl, __assign(__assign({}, _this.options), { autoConnect: false, auth: function (cb) {
40
+ var authHeaders = {};
41
+ if (_this.client.apiKey) {
42
+ authHeaders['x-api-key'] = _this.client.apiKey;
43
+ }
44
+ if (_this.client.accessToken) {
45
+ authHeaders['x-socket-token'] = "Bearer ".concat(_this.client.accessToken);
46
+ }
47
+ cb(authHeaders);
48
+ } }));
49
+ socket.on('connect', function () {
50
+ _this.client.debug("Socket connected: ".concat(socket.id));
51
+ if (_this.subscribedChannels.size) {
52
+ _this.subscribedChannels.forEach(function (channel) {
53
+ socket.emit('subscribe', { channel: channel }, function (resp) {
54
+ if (resp.status === 'error') {
55
+ console.error("Error re-subscribing to channel '".concat(channel), resp);
56
+ }
57
+ else {
58
+ _this.client.debug("Re-subscribed to channel '".concat(channel));
59
+ }
60
+ });
56
61
  });
57
- });
58
- }
59
- });
60
- socket.io.on('reconnect_attempt', function (attempt) {
61
- _this.client.debug("Socket reconnect attempt: ".concat(attempt));
62
- });
63
- socket.io.on('reconnect_error', function (error) {
64
- _this.client.debug("Socket reconnect error: ".concat(error.message));
65
- });
66
- socket.io.on('reconnect_failed', function () {
67
- _this.client.debug("Socket reconnect failed");
68
- });
69
- socket.io.on('reconnect', function () {
70
- _this.client.debug("Socket reconnected");
71
- });
72
- socket.on('disconnect', function (reason) {
73
- _this.client.debug("Socket disconnected: ".concat(reason));
62
+ }
63
+ });
64
+ socket.io.on('reconnect_attempt', function (attempt) {
65
+ _this.client.debug("Socket reconnect attempt: ".concat(attempt));
66
+ });
67
+ socket.io.on('reconnect_error', function (error) {
68
+ _this.client.debug("Socket reconnect error: ".concat(error.message));
69
+ });
70
+ socket.io.on('reconnect_failed', function () {
71
+ _this.client.debug("Socket reconnect failed");
72
+ });
73
+ socket.io.on('reconnect', function () {
74
+ _this.client.debug("Socket reconnected");
75
+ });
76
+ socket.on('disconnect', function (reason) {
77
+ _this.client.debug("Socket disconnected: ".concat(reason));
78
+ });
79
+ socket.on('error', function (e) {
80
+ _this.client.debug("Socket error: ".concat(e.messaage));
81
+ });
82
+ _this.socket = socket;
83
+ _this.connected = true;
84
+ socket.on('connect', function () {
85
+ resolve();
86
+ });
87
+ socket.connect();
74
88
  });
75
- socket.on('error', function (e) {
76
- _this.client.debug("Socket error: ".concat(e.messaage));
89
+ };
90
+ WebSocketGateway.prototype.disconnect = function () {
91
+ var _this = this;
92
+ if (!this.isConnected) {
93
+ return Promise.resolve();
94
+ }
95
+ return new Promise(function (resolve) {
96
+ _this.socket.once('disconnect', function () {
97
+ _this.connected = false;
98
+ resolve();
99
+ });
100
+ _this.socket.disconnect();
77
101
  });
78
- this.socket = socket;
79
- this.initialized = true;
80
102
  };
81
103
  WebSocketGateway.prototype.subscribe = function (channel, cb) {
82
104
  var _this = this;
83
- if (!this.isInitialized) {
105
+ if (!this.isConnected) {
84
106
  throw new Error('WebSocketGateway is not initialized');
85
107
  }
86
108
  this.client.debug("Subscribing to channel '".concat(channel));
@@ -109,7 +131,7 @@ var WebSocketGateway = /** @class */ (function () {
109
131
  };
110
132
  WebSocketGateway.prototype.unsubscribe = function (channel, cb) {
111
133
  var _this = this;
112
- if (!this.isInitialized) {
134
+ if (!this.isConnected) {
113
135
  throw new Error('WebSocketGateway is not initialized');
114
136
  }
115
137
  this.client.debug("Unsubscribing from channel '".concat(channel));