@emuanalytics/flow-engine-client 1.3.66 → 1.3.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"appconfig.endpoints.js","sourceRoot":"","sources":["../../../src/lib/appconfig.endpoints.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;IACE,4BAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,sBAAY,gDAAgB;aAA5B;YACE,OAAO,mBAAmB,CAAC;QAC7B,CAAC;;;OAAA;IAED,gCAAG,GAAH,UAAI,IAAa,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACzG,CAAC;IAED,gCAAG,GAAH,UAAI,IAAY,EAAE,KAAU,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QAC5D,kCAAkC;QAClC,IACE,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,SAAS;YAC1B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACpB;YACA,KAAK,GAAG,EAAE,KAAK,OAAA,EAAE,CAAC;SACnB;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,EAAE,KAAK,EAAE;YACjE,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,MAAM,QAAA;SACP,CAAC,CAAC;IACL,CAAC;IAED,mCAAM,GAAN,UAAO,IAAY,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,sCAAS,GAAT,UAAU,EAA8B;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IACH,yBAAC;AAAD,CAAC,AArCD,IAqCC;AArCY,gDAAkB","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport { Client, WebSocketSubscribeCallback, WebSocketUnsubscriber } from './client';\n\nexport class AppConfigEndpoints {\n constructor(private readonly client: Client) {}\n\n private get resourceEndpoint(): string {\n return `/api/v1/appconfig`;\n }\n\n get(path?: string, params: Record<string, any> = {}): Promise<any> {\n return this.client._get(path ? `${this.resourceEndpoint}/${path}` : this.resourceEndpoint, { params });\n }\n\n set(path: string, value: any, params: Record<string, any> = {}): Promise<any> {\n // Wrap primitives in value object\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n Array.isArray(value)\n ) {\n value = { value };\n }\n\n return this.client._put(`${this.resourceEndpoint}/${path}`, value, {\n headers: {\n 'Content-Type': 'application/json'\n },\n params\n });\n }\n\n delete(path: string, params: Record<string, any> = {}): Promise<any> {\n return this.client._delete(`${this.resourceEndpoint}/${path}`, { params });\n }\n\n subscribe(cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n return this.client._subscribe('appconfig', cb);\n }\n}\n"]}
1
+ {"version":3,"file":"appconfig.endpoints.js","sourceRoot":"","sources":["../../../src/lib/appconfig.endpoints.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAKH;IACE,4BAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,sBAAY,gDAAgB;aAA5B;YACE,OAAO,mBAAmB,CAAC;QAC7B,CAAC;;;OAAA;IAED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{ WebSocketSubscribeCallback, WebSocketUnsubscriber } from './web-socket-gateway';\n\nexport class AppConfigEndpoints {\n constructor(private readonly client: Client) {}\n\n private get resourceEndpoint(): string {\n return `/api/v1/appconfig`;\n }\n\n get(path?: string, params: Record<string, any> = {}): Promise<any> {\n return this.client._get(path ? `${this.resourceEndpoint}/${path}` : this.resourceEndpoint, { params });\n }\n\n set(path: string, value: any, params: Record<string, any> = {}): Promise<any> {\n // Wrap primitives in value object\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n Array.isArray(value)\n ) {\n value = { value };\n }\n\n return this.client._put(`${this.resourceEndpoint}/${path}`, value, {\n headers: {\n 'Content-Type': 'application/json'\n },\n params\n });\n }\n\n delete(path: string, params: Record<string, any> = {}): Promise<any> {\n return this.client._delete(`${this.resourceEndpoint}/${path}`, { params });\n }\n\n subscribe(cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n return this.client._subscribe('appconfig', cb);\n }\n}\n"]}
@@ -35,7 +35,7 @@ var tile_endpoints_1 = require("./tile.endpoints");
35
35
  var upload_endpoints_1 = require("./upload.endpoints");
36
36
  var web_socket_gateway_1 = require("./web-socket-gateway");
37
37
  var Client = /** @class */ (function () {
38
- function Client(baseUrl, apiKey) {
38
+ function Client(baseUrl, apiKey, options) {
39
39
  if (apiKey === void 0) { apiKey = null; }
40
40
  this.baseUrl = baseUrl;
41
41
  this.apiKey = apiKey;
@@ -57,6 +57,7 @@ var Client = /** @class */ (function () {
57
57
  baseURL: baseUrl,
58
58
  maxContentLength: 524288000
59
59
  });
60
+ this.webSocketGateway = new web_socket_gateway_1.WebSocketGateway(this, options);
60
61
  }
61
62
  Client.prototype.config = function () {
62
63
  return this._get('/api/v1/config');
@@ -111,54 +112,17 @@ var Client = /** @class */ (function () {
111
112
  };
112
113
  // Subscribe to named channel - errors and messages are delivered via the callback
113
114
  Client.prototype._subscribe = function (channel, cb) {
114
- var _this = this;
115
- if (!this.webSocketGateway) {
116
- this.webSocketGateway = (0, web_socket_gateway_1.initializewebSocketGateway)(this);
115
+ if (!this.webSocketGateway.isInitialized) {
116
+ this.webSocketGateway.initialize();
117
117
  }
118
- this.debug("Subscribing to channel '".concat(channel));
119
- // Discriminating 'message' event listener that only responds to messages sent to 'channel'
120
- var listener = function (msg) {
121
- if (msg.channel === channel) {
122
- cb(null, msg);
123
- }
124
- };
125
- // Unsubscriber
126
- var unsubscribe = function (unsubscribeCb) {
127
- _this.webSocketGateway.off('message', listener);
128
- _this._unsubscribe(channel, unsubscribeCb);
129
- };
130
- // Subscribe and bind listener
131
- this.webSocketGateway.emit('subscribe', { channel: 'appconfig' }, function (resp) {
132
- if (resp.status === 'error') {
133
- _this.debug("Error subscribed to channel '".concat(channel), resp);
134
- return cb(new Error(resp.message));
135
- }
136
- _this.debug("Subscribed to channel '".concat(channel));
137
- _this.webSocketGateway.on('message', listener);
138
- });
139
- return unsubscribe;
118
+ return this.webSocketGateway.subscribe(channel, cb);
140
119
  };
141
120
  // Unsubscribe from named channel - optional callback is called on completion
142
121
  Client.prototype._unsubscribe = function (channel, cb) {
143
- var _this = this;
144
- if (!this.webSocketGateway) {
145
- this.webSocketGateway = (0, web_socket_gateway_1.initializewebSocketGateway)(this);
122
+ if (!this.webSocketGateway.isInitialized) {
123
+ this.webSocketGateway.initialize();
146
124
  }
147
- this.debug("Unsubscribing from channel '".concat(channel));
148
- this.webSocketGateway.emit('unsubscribe', { channel: channel }, function (resp) {
149
- if (resp.status === 'error') {
150
- _this.debug("Error unsubscribing from channel '".concat(channel), resp);
151
- if (cb) {
152
- cb(new Error(resp.message));
153
- }
154
- }
155
- else {
156
- _this.debug("Unsubscribed from channel '".concat(channel));
157
- if (cb) {
158
- cb(null);
159
- }
160
- }
161
- });
125
+ this.webSocketGateway.unsubscribe(channel, cb);
162
126
  };
163
127
  /**
164
128
  * Normalize errors
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings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AAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;aACrE;SACF;QAED,gBAAgB;QAEhB,kCAAkC;QAClC,IAAM,UAAU,GAAQ,CAAC,CAAC;QAC1B,OAAO,UAAU,CAAC,MAAM,CAAC;QACzB,OAAO,UAAU,CAAC,OAAO,CAAC;QAC1B,OAAO,UAAU,CAAC,QAAQ,CAAC;QAE3B,MAAM,IAAI,wBAAe,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,AA1MD,IA0MC;AA1MY,wBAAM","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport Axios, { AxiosError, AxiosInstance } from 'axios';\nimport { debug as Debug } from 'debug';\nimport { Socket } from 'socket.io-client';\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 { initializewebSocketGateway, WebSocketPublishMessage, WebSocketResponse } from './web-socket-gateway';\n\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 Client {\n private readonly axios: AxiosInstance;\n private webSocketGateway?: Socket;\n readonly debug = Debug('flow-engine-client');\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) {\n this.axios = Axios.create({\n baseURL: baseUrl,\n maxContentLength: 524288000\n });\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) {\n this.webSocketGateway = initializewebSocketGateway(this);\n }\n\n this.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.webSocketGateway!.off('message', listener);\n this._unsubscribe(channel, unsubscribeCb);\n };\n\n // Subscribe and bind listener\n this.webSocketGateway.emit('subscribe', { channel: 'appconfig' }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.debug(`Error subscribed to channel '${channel}`, resp);\n return cb(new Error(resp.message));\n }\n\n this.debug(`Subscribed to channel '${channel}`);\n this.webSocketGateway!.on('message', listener);\n });\n\n return unsubscribe;\n }\n\n // Unsubscribe from named channel - optional callback is called on completion\n _unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback) {\n if (!this.webSocketGateway) {\n this.webSocketGateway = initializewebSocketGateway(this);\n }\n\n this.debug(`Unsubscribing from channel '${channel}`);\n this.webSocketGateway.emit('unsubscribe', { channel }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.debug(`Error unsubscribing from channel '${channel}`, resp);\n if (cb) {\n cb(new Error(resp.message));\n }\n } else {\n this.debug(`Unsubscribed from channel '${channel}`);\n if (cb) {\n cb(null);\n }\n }\n });\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,U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O,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;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 +1 @@
1
- {"version":3,"file":"dataset.endpoints.js","sourceRoot":"","sources":["../../../src/lib/dataset.endpoints.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,mDAAiD;AAgBjD;IAAsC,oCAAuB;IAC3D,0BAAY,MAAc;eACxB,kBAAM,MAAM,EAAE,UAAU,CAAC;IAC3B,CAAC;IAED,gCAAK,GAAL,UACE,SAAgC,EAChC,KAAwB,EACxB,MAAoD;QADpD,sBAAA,EAAA,UAAwB;QACxB,uBAAA,EAAA,WAAoD;QAEpD,2CAA2C;QAC3C,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,MAAM,yBAAQ,SAAS,CAAC,MAAM,KAAE,MAA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AAC;AAAD,CAAC,AAlDD,CAAsC,8BAAa,GAkDlD;AAlDY,4CAAgB","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport { Client, WebSocketSubscribeCallback, WebSocketUnsubscriber } from './client';\nimport { BaseEndpoints } from './base.endpoints';\nimport { IDataset, FileExportFormat } from './api-interfaces';\nimport { type } from 'os';\n\nexport interface DatasetQuery {\n [key: string]: any;\n}\n\ntype QueryOutputFormat = 'plain' | 'json' | 'csv' | 'geojson';\n\nexport interface DatasetQueryOptions {\n [param: string]: any;\n format?: QueryOutputFormat;\n explain?: boolean | string;\n}\n\nexport class DatasetEndpoints extends BaseEndpoints<IDataset> {\n constructor(client: Client) {\n super(client, 'datasets');\n }\n\n query(\n datasetId: string | DatasetQuery,\n query: DatasetQuery = {},\n params: DatasetQueryOptions | QueryOutputFormat = {}\n ): Promise<any> {\n // Support Flo.w RDF-style query definition\n if (typeof datasetId === 'object') {\n params = { ...datasetId.params, format: datasetId.format || 'json' };\n query = datasetId;\n datasetId = query.datasetId;\n delete query.datasetId;\n delete query.format;\n }\n\n if (typeof params === 'string') {\n params = { format: params };\n }\n\n return this.client\n ._post(`/api/v1/datasets/${datasetId}/query`, query, {\n params: {\n ...params,\n format: params.format || 'json',\n explain: params.explain || false\n }\n })\n .catch(e => {\n if (e.message === 'Network Error') {\n throw new Error('Query timed out');\n } else {\n throw e;\n }\n });\n }\n\n getExportUrl(datasetId: string, format: FileExportFormat): string {\n const credentials = this.client.accessToken\n ? `accesstoken=${this.client.accessToken}`\n : `apikey=${this.client.apiKey}`;\n return `${this.client.baseUrl}/api/v1/datasets/${datasetId}/export?format=${format}&${credentials}`;\n }\n\n subscribe(datasetId: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n return this.client._subscribe(`dataset-${datasetId}`, cb);\n }\n}\n"]}
1
+ {"version":3,"file":"dataset.endpoints.js","sourceRoot":"","sources":["../../../src/lib/dataset.endpoints.ts"],"names":[],"mappings":";AAAA;;GAE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,MAAM,CAAC,WAAW,CAAE;YAC1C,CAAC,CAAC,iBAAU,IAAI,CAAC,MAAM,CAAC,MAAM,CAAE,CAAC;QACnC,OAAO,UAAG,IAAI,CAAC,MAAM,CAAC,OAAO,8BAAoB,SAAS,4BAAkB,MAAM,cAAI,WAAW,CAAE,CAAC;IACtG,CAAC;IAED,oCAAS,GAAT,UAAU,SAAiB,EAAE,EAA8B;QACzD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,kBAAW,SAAS,CAAE,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IACH,uBAAC;AAAD,CAAC,AAlDD,CAAsC,8BAAa,GAkDlD;AAlDY,4CAAgB","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport { Client } from './client';\nimport { BaseEndpoints } from './base.endpoints';\nimport { IDataset, FileExportFormat } from './api-interfaces';\nimport { type } from 'os';\nimport { WebSocketSubscribeCallback, WebSocketUnsubscriber } from './web-socket-gateway';\n\nexport interface DatasetQuery {\n [key: string]: any;\n}\n\ntype QueryOutputFormat = 'plain' | 'json' | 'csv' | 'geojson';\n\nexport interface DatasetQueryOptions {\n [param: string]: any;\n format?: QueryOutputFormat;\n explain?: boolean | string;\n}\n\nexport class DatasetEndpoints extends BaseEndpoints<IDataset> {\n constructor(client: Client) {\n super(client, 'datasets');\n }\n\n query(\n datasetId: string | DatasetQuery,\n query: DatasetQuery = {},\n params: DatasetQueryOptions | QueryOutputFormat = {}\n ): Promise<any> {\n // Support Flo.w RDF-style query definition\n if (typeof datasetId === 'object') {\n params = { ...datasetId.params, format: datasetId.format || 'json' };\n query = datasetId;\n datasetId = query.datasetId;\n delete query.datasetId;\n delete query.format;\n }\n\n if (typeof params === 'string') {\n params = { format: params };\n }\n\n return this.client\n ._post(`/api/v1/datasets/${datasetId}/query`, query, {\n params: {\n ...params,\n format: params.format || 'json',\n explain: params.explain || false\n }\n })\n .catch(e => {\n if (e.message === 'Network Error') {\n throw new Error('Query timed out');\n } else {\n throw e;\n }\n });\n }\n\n getExportUrl(datasetId: string, format: FileExportFormat): string {\n const credentials = this.client.accessToken\n ? `accesstoken=${this.client.accessToken}`\n : `apikey=${this.client.apiKey}`;\n return `${this.client.baseUrl}/api/v1/datasets/${datasetId}/export?format=${format}&${credentials}`;\n }\n\n subscribe(datasetId: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n return this.client._subscribe(`dataset-${datasetId}`, cb);\n }\n}\n"]}
@@ -1,33 +1,122 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initializewebSocketGateway = exports.WebSocketChannel = void 0;
4
- var debug_1 = require("debug");
3
+ exports.WebSocketGateway = exports.WebSocketChannel = void 0;
5
4
  var socket_io_client_1 = require("socket.io-client");
6
- var debug = (0, debug_1.debug)('flow-engine-client');
7
5
  var WebSocketChannel;
8
6
  (function (WebSocketChannel) {
9
7
  WebSocketChannel["System"] = "system";
10
8
  WebSocketChannel["AppConfig"] = "appconfig";
11
9
  WebSocketChannel["Dataset"] = "dataset/";
12
10
  })(WebSocketChannel = exports.WebSocketChannel || (exports.WebSocketChannel = {}));
13
- function initializewebSocketGateway(client, options) {
14
- var websocketHeaders = {};
15
- if (client.apiKey) {
16
- websocketHeaders['x-api-key'] = client.apiKey;
11
+ var WebSocketGateway = /** @class */ (function () {
12
+ function WebSocketGateway(client, options) {
13
+ this.client = client;
14
+ this.options = options;
15
+ this.initialized = false;
16
+ this.subscribedChannels = new Set();
17
17
  }
18
- if (client.accessToken) {
19
- websocketHeaders['x-socket-token'] = "Bearer ".concat(client.accessToken);
20
- }
21
- var socket = (0, socket_io_client_1.io)(client.baseUrl, {
22
- extraHeaders: websocketHeaders
23
- });
24
- socket.on('connect', function () {
25
- debug("Socket connected: ".concat(socket.id)); // x8WIv7-mJelg7on_ALbx
26
- });
27
- socket.on('disconnect', function () {
28
- debug("Socket disconnected: ".concat(socket.id)); // undefined
18
+ Object.defineProperty(WebSocketGateway.prototype, "isInitialized", {
19
+ get: function () {
20
+ return this.initialized;
21
+ },
22
+ enumerable: false,
23
+ configurable: true
29
24
  });
30
- return socket;
31
- }
32
- exports.initializewebSocketGateway = initializewebSocketGateway;
25
+ WebSocketGateway.prototype.initialize = function () {
26
+ var _this = this;
27
+ var websocketHeaders = {};
28
+ if (this.client.apiKey) {
29
+ websocketHeaders['x-api-key'] = this.client.apiKey;
30
+ }
31
+ if (this.client.accessToken) {
32
+ websocketHeaders['x-socket-token'] = "Bearer ".concat(this.client.accessToken);
33
+ }
34
+ var socket = (0, socket_io_client_1.io)(this.client.baseUrl, {
35
+ extraHeaders: websocketHeaders
36
+ });
37
+ socket.on('connect', function () {
38
+ _this.client.debug("Socket connected: ".concat(socket.id));
39
+ if (_this.subscribedChannels.size) {
40
+ _this.subscribedChannels.forEach(function (channel) {
41
+ socket.emit('subscribe', { channel: 'appconfig' }, function (resp) {
42
+ if (resp.status === 'error') {
43
+ _this.client.debug("Error re-subscribeingto channel '".concat(channel), resp);
44
+ }
45
+ _this.client.debug("Resubscribed to channel '".concat(channel));
46
+ });
47
+ });
48
+ }
49
+ });
50
+ socket.io.on('reconnect_attempt', function (attempt) {
51
+ _this.client.debug("Socket reconnect attempt: ".concat(attempt));
52
+ });
53
+ socket.io.on('reconnect_error', function (error) {
54
+ _this.client.debug("Socket reconnect error: ".concat(error.message));
55
+ });
56
+ socket.io.on('reconnect_failed', function () {
57
+ _this.client.debug("Socket reconnect failed");
58
+ });
59
+ socket.io.on('reconnect', function () {
60
+ _this.client.debug("Socket reconnected");
61
+ });
62
+ socket.on('disconnect', function (reason) {
63
+ _this.client.debug("Socket disconnected: ".concat(reason));
64
+ });
65
+ this.socket = socket;
66
+ this.initialized = true;
67
+ };
68
+ WebSocketGateway.prototype.subscribe = function (channel, cb) {
69
+ var _this = this;
70
+ if (!this.isInitialized) {
71
+ throw new Error('WebSocketGateway is not initialized');
72
+ }
73
+ this.client.debug("Subscribing to channel '".concat(channel));
74
+ // Discriminating 'message' event listener that only responds to messages sent to 'channel'
75
+ var listener = function (msg) {
76
+ if (msg.channel === channel) {
77
+ cb(null, msg);
78
+ }
79
+ };
80
+ // Unsubscriber
81
+ var unsubscribe = function (unsubscribeCb) {
82
+ _this.socket.on('message', listener);
83
+ _this.unsubscribe(channel, unsubscribeCb);
84
+ };
85
+ // Subscribe and bind listener
86
+ this.socket.emit('subscribe', { channel: 'appconfig' }, function (resp) {
87
+ if (resp.status === 'error') {
88
+ _this.client.debug("Error subscribed to channel '".concat(channel), resp);
89
+ return cb(new Error(resp.message));
90
+ }
91
+ _this.subscribedChannels.add(channel);
92
+ _this.client.debug("Subscribed to channel '".concat(channel));
93
+ _this.socket.on('message', listener);
94
+ });
95
+ return unsubscribe;
96
+ };
97
+ WebSocketGateway.prototype.unsubscribe = function (channel, cb) {
98
+ var _this = this;
99
+ if (!this.isInitialized) {
100
+ throw new Error('WebSocketGateway is not initialized');
101
+ }
102
+ this.client.debug("Unsubscribing from channel '".concat(channel));
103
+ this.socket.emit('unsubscribe', { channel: channel }, function (resp) {
104
+ if (resp.status === 'error') {
105
+ _this.client.debug("Error unsubscribing from channel '".concat(channel), resp);
106
+ if (cb) {
107
+ cb(new Error(resp.message));
108
+ }
109
+ }
110
+ else {
111
+ _this.subscribedChannels.delete(channel);
112
+ _this.client.debug("Unsubscribed from channel '".concat(channel));
113
+ if (cb) {
114
+ cb(null);
115
+ }
116
+ }
117
+ });
118
+ };
119
+ return WebSocketGateway;
120
+ }());
121
+ exports.WebSocketGateway = WebSocketGateway;
33
122
  //# sourceMappingURL=web-socket-gateway.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-socket-gateway.js","sourceRoot":"","sources":["../../../src/lib/web-socket-gateway.ts"],"names":[],"mappings":";;;AAAA,+BAAuC;AACvC,qDAAqE;AAErE,IAAM,KAAK,GAAG,IAAA,aAAK,EAAC,oBAAoB,CAAC,CAAC;AAE1C,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,qCAAiB,CAAA;IACjB,2CAAuB,CAAA;IACvB,wCAAoB,CAAA;AACtB,CAAC,EAJW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAI3B;AAwBD,SAAgB,0BAA0B,CACxC,MAAc,EACd,OAAiD;IAEjD,IAAM,gBAAgB,GAA2B,EAAE,CAAC;IAEpD,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,gBAAgB,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;KAC/C;IAED,IAAI,MAAM,CAAC,WAAW,EAAE;QACtB,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,iBAAU,MAAM,CAAC,WAAW,CAAE,CAAC;KACrE;IAED,IAAM,MAAM,GAAG,IAAA,qBAAE,EAAC,MAAM,CAAC,OAAO,EAAE;QAChC,YAAY,EAAE,gBAAgB;KAC/B,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE;QACnB,KAAK,CAAC,4BAAqB,MAAM,CAAC,EAAE,CAAE,CAAC,CAAC,CAAC,uBAAuB;IAClE,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE;QACtB,KAAK,CAAC,+BAAwB,MAAM,CAAC,EAAE,CAAE,CAAC,CAAC,CAAC,YAAY;IAC1D,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AA3BD,gEA2BC","sourcesContent":["import { debug as Debug } from 'debug';\nimport { io, ManagerOptions, SocketOptions } from 'socket.io-client';\nimport { Client } from './client';\nconst debug = Debug('flow-engine-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;\n\nexport function initializewebSocketGateway(\n client: Client,\n options?: Partial<ManagerOptions & SocketOptions>\n) {\n const websocketHeaders: Record<string, string> = {};\n\n if (client.apiKey) {\n websocketHeaders['x-api-key'] = client.apiKey;\n }\n\n if (client.accessToken) {\n websocketHeaders['x-socket-token'] = `Bearer ${client.accessToken}`;\n }\n\n const socket = io(client.baseUrl, {\n extraHeaders: websocketHeaders\n });\n\n socket.on('connect', () => {\n debug(`Socket connected: ${socket.id}`); // x8WIv7-mJelg7on_ALbx\n });\n\n socket.on('disconnect', () => {\n debug(`Socket disconnected: ${socket.id}`); // undefined\n });\n\n return socket;\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,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,iBAsDC;QArDC,IAAM,gBAAgB,GAA2B,EAAE,CAAC;QAEpD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YACtB,gBAAgB,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;SACpD;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,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AC3D,IAAI,EAAE,EAAE;oBACN,EAAE,CAAC,IAAI,CAAC,CAAC;iBACV;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACH,uBAAC;AAAD,CAAC,AA5HD,IA4HC;AA5HY,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 websocketHeaders: Record<string, string> = {};\n\n if (this.client.apiKey) {\n websocketHeaders['x-api-key'] = this.client.apiKey;\n }\n\n if (this.client.accessToken) {\n websocketHeaders['x-socket-token'] = `Bearer ${this.client.accessToken}`;\n }\n\n const socket = io(this.client.baseUrl, {\n extraHeaders: websocketHeaders\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: 'appconfig' }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.client.debug(`Error re-subscribeingto channel '${channel}`, resp);\n }\n\n this.client.debug(`Resubscribed to channel '${channel}`);\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 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.on('message', listener);\n this.unsubscribe(channel, unsubscribeCb);\n };\n\n // Subscribe and bind listener\n this.socket.emit('subscribe', { channel: 'appconfig' }, (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 +1 @@
1
- {"version":3,"file":"appconfig.endpoints.js","sourceRoot":"","sources":["../../../src/lib/appconfig.endpoints.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;IACE,4BAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,sBAAY,gDAAgB;aAA5B;YACE,OAAO,mBAAmB,CAAC;QAC7B,CAAC;;;OAAA;IAED,gCAAG,GAAH,UAAI,IAAa,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACzG,CAAC;IAED,gCAAG,GAAH,UAAI,IAAY,EAAE,KAAU,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QAC5D,kCAAkC;QAClC,IACE,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,SAAS;YAC1B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACpB;YACA,KAAK,GAAG,EAAE,KAAK,OAAA,EAAE,CAAC;SACnB;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,EAAE,KAAK,EAAE;YACjE,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,MAAM,QAAA;SACP,CAAC,CAAC;IACL,CAAC;IAED,mCAAM,GAAN,UAAO,IAAY,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,sCAAS,GAAT,UAAU,EAA8B;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IACH,yBAAC;AAAD,CAAC,AArCD,IAqCC","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport { Client, WebSocketSubscribeCallback, WebSocketUnsubscriber } from './client';\n\nexport class AppConfigEndpoints {\n constructor(private readonly client: Client) {}\n\n private get resourceEndpoint(): string {\n return `/api/v1/appconfig`;\n }\n\n get(path?: string, params: Record<string, any> = {}): Promise<any> {\n return this.client._get(path ? `${this.resourceEndpoint}/${path}` : this.resourceEndpoint, { params });\n }\n\n set(path: string, value: any, params: Record<string, any> = {}): Promise<any> {\n // Wrap primitives in value object\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n Array.isArray(value)\n ) {\n value = { value };\n }\n\n return this.client._put(`${this.resourceEndpoint}/${path}`, value, {\n headers: {\n 'Content-Type': 'application/json'\n },\n params\n });\n }\n\n delete(path: string, params: Record<string, any> = {}): Promise<any> {\n return this.client._delete(`${this.resourceEndpoint}/${path}`, { params });\n }\n\n subscribe(cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n return this.client._subscribe('appconfig', cb);\n }\n}\n"]}
1
+ {"version":3,"file":"appconfig.endpoints.js","sourceRoot":"","sources":["../../../src/lib/appconfig.endpoints.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;IACE,4BAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,sBAAY,gDAAgB;aAA5B;YACE,OAAO,mBAAmB,CAAC;QAC7B,CAAC;;;OAAA;IAED,gCAAG,GAAH,UAAI,IAAa,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACzG,CAAC;IAED,gCAAG,GAAH,UAAI,IAAY,EAAE,KAAU,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QAC5D,kCAAkC;QAClC,IACE,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,SAAS;YAC1B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACpB;YACA,KAAK,GAAG,EAAE,KAAK,OAAA,EAAE,CAAC;SACnB;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,EAAE,KAAK,EAAE;YACjE,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,MAAM,QAAA;SACP,CAAC,CAAC;IACL,CAAC;IAED,mCAAM,GAAN,UAAO,IAAY,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAG,IAAI,CAAC,gBAAgB,cAAI,IAAI,CAAE,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,sCAAS,GAAT,UAAU,EAA8B;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IACH,yBAAC;AAAD,CAAC,AArCD,IAqCC","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport { Client } from './client';\nimport { WebSocketSubscribeCallback, WebSocketUnsubscriber } from './web-socket-gateway';\n\nexport class AppConfigEndpoints {\n constructor(private readonly client: Client) {}\n\n private get resourceEndpoint(): string {\n return `/api/v1/appconfig`;\n }\n\n get(path?: string, params: Record<string, any> = {}): Promise<any> {\n return this.client._get(path ? `${this.resourceEndpoint}/${path}` : this.resourceEndpoint, { params });\n }\n\n set(path: string, value: any, params: Record<string, any> = {}): Promise<any> {\n // Wrap primitives in value object\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n Array.isArray(value)\n ) {\n value = { value };\n }\n\n return this.client._put(`${this.resourceEndpoint}/${path}`, value, {\n headers: {\n 'Content-Type': 'application/json'\n },\n params\n });\n }\n\n delete(path: string, params: Record<string, any> = {}): Promise<any> {\n return this.client._delete(`${this.resourceEndpoint}/${path}`, { params });\n }\n\n subscribe(cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n return this.client._subscribe('appconfig', cb);\n }\n}\n"]}
@@ -27,9 +27,9 @@ import { StyleEndpoints } from './style.endpoint';
27
27
  import { TileSourceEndpoints } from './tile-source.endpoints';
28
28
  import { TileEndpoints } from './tile.endpoints';
29
29
  import { UploadEndpoints } from './upload.endpoints';
30
- import { initializewebSocketGateway } from './web-socket-gateway';
30
+ import { WebSocketGateway } from './web-socket-gateway';
31
31
  var Client = /** @class */ (function () {
32
- function Client(baseUrl, apiKey) {
32
+ function Client(baseUrl, apiKey, options) {
33
33
  if (apiKey === void 0) { apiKey = null; }
34
34
  this.baseUrl = baseUrl;
35
35
  this.apiKey = apiKey;
@@ -51,6 +51,7 @@ var Client = /** @class */ (function () {
51
51
  baseURL: baseUrl,
52
52
  maxContentLength: 524288000
53
53
  });
54
+ this.webSocketGateway = new WebSocketGateway(this, options);
54
55
  }
55
56
  Client.prototype.config = function () {
56
57
  return this._get('/api/v1/config');
@@ -105,54 +106,17 @@ var Client = /** @class */ (function () {
105
106
  };
106
107
  // Subscribe to named channel - errors and messages are delivered via the callback
107
108
  Client.prototype._subscribe = function (channel, cb) {
108
- var _this = this;
109
- if (!this.webSocketGateway) {
110
- this.webSocketGateway = initializewebSocketGateway(this);
109
+ if (!this.webSocketGateway.isInitialized) {
110
+ this.webSocketGateway.initialize();
111
111
  }
112
- this.debug("Subscribing to channel '".concat(channel));
113
- // Discriminating 'message' event listener that only responds to messages sent to 'channel'
114
- var listener = function (msg) {
115
- if (msg.channel === channel) {
116
- cb(null, msg);
117
- }
118
- };
119
- // Unsubscriber
120
- var unsubscribe = function (unsubscribeCb) {
121
- _this.webSocketGateway.off('message', listener);
122
- _this._unsubscribe(channel, unsubscribeCb);
123
- };
124
- // Subscribe and bind listener
125
- this.webSocketGateway.emit('subscribe', { channel: 'appconfig' }, function (resp) {
126
- if (resp.status === 'error') {
127
- _this.debug("Error subscribed to channel '".concat(channel), resp);
128
- return cb(new Error(resp.message));
129
- }
130
- _this.debug("Subscribed to channel '".concat(channel));
131
- _this.webSocketGateway.on('message', listener);
132
- });
133
- return unsubscribe;
112
+ return this.webSocketGateway.subscribe(channel, cb);
134
113
  };
135
114
  // Unsubscribe from named channel - optional callback is called on completion
136
115
  Client.prototype._unsubscribe = function (channel, cb) {
137
- var _this = this;
138
- if (!this.webSocketGateway) {
139
- this.webSocketGateway = initializewebSocketGateway(this);
116
+ if (!this.webSocketGateway.isInitialized) {
117
+ this.webSocketGateway.initialize();
140
118
  }
141
- this.debug("Unsubscribing from channel '".concat(channel));
142
- this.webSocketGateway.emit('unsubscribe', { channel: channel }, function (resp) {
143
- if (resp.status === 'error') {
144
- _this.debug("Error unsubscribing from channel '".concat(channel), resp);
145
- if (cb) {
146
- cb(new Error(resp.message));
147
- }
148
- }
149
- else {
150
- _this.debug("Unsubscribed from channel '".concat(channel));
151
- if (cb) {
152
- cb(null);
153
- }
154
- }
155
- });
119
+ this.webSocketGateway.unsubscribe(channel, cb);
156
120
  };
157
121
  /**
158
122
  * Normalize errors
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/client.ts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O,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,AA1MD,IA0MC","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport Axios, { AxiosError, AxiosInstance } from 'axios';\nimport { debug as Debug } from 'debug';\nimport { Socket } from 'socket.io-client';\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 { initializewebSocketGateway, WebSocketPublishMessage, WebSocketResponse } from './web-socket-gateway';\n\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 Client {\n private readonly axios: AxiosInstance;\n private webSocketGateway?: Socket;\n readonly debug = Debug('flow-engine-client');\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) {\n this.axios = Axios.create({\n baseURL: baseUrl,\n maxContentLength: 524288000\n });\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) {\n this.webSocketGateway = initializewebSocketGateway(this);\n }\n\n this.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.webSocketGateway!.off('message', listener);\n this._unsubscribe(channel, unsubscribeCb);\n };\n\n // Subscribe and bind listener\n this.webSocketGateway.emit('subscribe', { channel: 'appconfig' }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.debug(`Error subscribed to channel '${channel}`, resp);\n return cb(new Error(resp.message));\n }\n\n this.debug(`Subscribed to channel '${channel}`);\n this.webSocketGateway!.on('message', listener);\n });\n\n return unsubscribe;\n }\n\n // Unsubscribe from named channel - optional callback is called on completion\n _unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback) {\n if (!this.webSocketGateway) {\n this.webSocketGateway = initializewebSocketGateway(this);\n }\n\n this.debug(`Unsubscribing from channel '${channel}`);\n this.webSocketGateway.emit('unsubscribe', { channel }, (resp: WebSocketResponse) => {\n if (resp.status === 'error') {\n this.debug(`Error unsubscribing from channel '${channel}`, resp);\n if (cb) {\n cb(new Error(resp.message));\n }\n } else {\n this.debug(`Unsubscribed from channel '${channel}`);\n if (cb) {\n cb(null);\n }\n }\n });\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,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,yBAAyB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,gBAAgB,EAKjB,MAAM,sBAAsB,CAAC;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,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAI7C,gBAAW,GAAkB,IAAI,CAAC;QAElC,SAAI,GAAG,IAAI,a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AAW,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 +1 @@
1
- {"version":3,"file":"dataset.endpoints.js","sourceRoot":"","sources":["../../../src/lib/dataset.endpoints.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAgBjD;IAAsC,oCAAuB;IAC3D,0BAAY,MAAc;eACxB,kBAAM,MAAM,EAAE,UAAU,CAAC;IAC3B,CAAC;IAED,gCAAK,GAAL,UACE,SAAgC,EAChC,KAAwB,EACxB,MAAoD;QADpD,sBAAA,EAAA,UAAwB;QACxB,uBAAA,EAAA,WAAoD;QAEpD,2CAA2C;QAC3C,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,MAAM,yBAAQ,SAAS,CAAC,MAAM,KAAE,MAAM,EAAE,SAAS,CAAC,MAAM,IAAI,MAAM,GAAE,CAAC;YACrE,KAAK,GAAG,SAAS,CAAC;YAClB,SAAS,GAAG,K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ocketSubscribeCallback, WebSocketUnsubscriber } from './client';\nimport { BaseEndpoints } from './base.endpoints';\nimport { IDataset, FileExportFormat } from './api-interfaces';\nimport { type } from 'os';\n\nexport interface DatasetQuery {\n [key: string]: any;\n}\n\ntype QueryOutputFormat = 'plain' | 'json' | 'csv' | 'geojson';\n\nexport interface DatasetQueryOptions {\n [param: string]: any;\n format?: QueryOutputFormat;\n explain?: boolean | string;\n}\n\nexport class DatasetEndpoints extends BaseEndpoints<IDataset> {\n constructor(client: Client) {\n super(client, 'datasets');\n }\n\n query(\n datasetId: string | DatasetQuery,\n query: DatasetQuery = {},\n params: DatasetQueryOptions | QueryOutputFormat = {}\n ): Promise<any> {\n // Support Flo.w RDF-style query definition\n if (typeof datasetId === 'object') {\n params = { ...datasetId.params, format: datasetId.format || 'json' };\n query = datasetId;\n datasetId = query.datasetId;\n delete query.datasetId;\n delete query.format;\n }\n\n if (typeof params === 'string') {\n params = { format: params };\n }\n\n return this.client\n ._post(`/api/v1/datasets/${datasetId}/query`, query, {\n params: {\n ...params,\n format: params.format || 'json',\n explain: params.explain || false\n }\n })\n .catch(e => {\n if (e.message === 'Network Error') {\n throw new Error('Query timed out');\n } else {\n throw e;\n }\n });\n }\n\n getExportUrl(datasetId: string, format: FileExportFormat): string {\n const credentials = this.client.accessToken\n ? `accesstoken=${this.client.accessToken}`\n : `apikey=${this.client.apiKey}`;\n return `${this.client.baseUrl}/api/v1/datasets/${datasetId}/export?format=${format}&${credentials}`;\n }\n\n subscribe(datasetId: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n return this.client._subscribe(`dataset-${datasetId}`, cb);\n }\n}\n"]}
1
+ {"version":3,"file":"dataset.endpoints.js","sourceRoot":"","sources":["../../../src/lib/dataset.endpoints.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAiBjD;IAAsC,oCAAuB;IAC3D,0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AAE,CAAC;QACnC,OAAO,UAAG,IAAI,CAAC,MAAM,CAAC,OAAO,8BAAoB,SAAS,4BAAkB,MAAM,cAAI,WAAW,CAAE,CAAC;IACtG,CAAC;IAED,oCAAS,GAAT,UAAU,SAAiB,EAAE,EAA8B;QACzD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,kBAAW,SAAS,CAAE,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IACH,uBAAC;AAAD,CAAC,AAlDD,CAAsC,aAAa,GAkDlD","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport { Client } from './client';\nimport { BaseEndpoints } from './base.endpoints';\nimport { IDataset, FileExportFormat } from './api-interfaces';\nimport { type } from 'os';\nimport { WebSocketSubscribeCallback, WebSocketUnsubscriber } from './web-socket-gateway';\n\nexport interface DatasetQuery {\n [key: string]: any;\n}\n\ntype QueryOutputFormat = 'plain' | 'json' | 'csv' | 'geojson';\n\nexport interface DatasetQueryOptions {\n [param: string]: any;\n format?: QueryOutputFormat;\n explain?: boolean | string;\n}\n\nexport class DatasetEndpoints extends BaseEndpoints<IDataset> {\n constructor(client: Client) {\n super(client, 'datasets');\n }\n\n query(\n datasetId: string | DatasetQuery,\n query: DatasetQuery = {},\n params: DatasetQueryOptions | QueryOutputFormat = {}\n ): Promise<any> {\n // Support Flo.w RDF-style query definition\n if (typeof datasetId === 'object') {\n params = { ...datasetId.params, format: datasetId.format || 'json' };\n query = datasetId;\n datasetId = query.datasetId;\n delete query.datasetId;\n delete query.format;\n }\n\n if (typeof params === 'string') {\n params = { format: params };\n }\n\n return this.client\n ._post(`/api/v1/datasets/${datasetId}/query`, query, {\n params: {\n ...params,\n format: params.format || 'json',\n explain: params.explain || false\n }\n })\n .catch(e => {\n if (e.message === 'Network Error') {\n throw new Error('Query timed out');\n } else {\n throw e;\n }\n });\n }\n\n getExportUrl(datasetId: string, format: FileExportFormat): string {\n const credentials = this.client.accessToken\n ? `accesstoken=${this.client.accessToken}`\n : `apikey=${this.client.apiKey}`;\n return `${this.client.baseUrl}/api/v1/datasets/${datasetId}/export?format=${format}&${credentials}`;\n }\n\n subscribe(datasetId: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber {\n return this.client._subscribe(`dataset-${datasetId}`, cb);\n }\n}\n"]}