@emuanalytics/flow-engine-client 1.3.48 → 1.3.64
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/bundle.js +2 -2
- package/dist/bundle.js.map +4 -4
- package/dist/cjs/lib/appconfig.endpoints.js +7 -1
- package/dist/cjs/lib/appconfig.endpoints.js.map +1 -1
- package/dist/cjs/lib/client.js +61 -7
- package/dist/cjs/lib/client.js.map +1 -1
- package/dist/cjs/lib/dataset.endpoints.js +3 -0
- package/dist/cjs/lib/dataset.endpoints.js.map +1 -1
- package/dist/cjs/lib/web-socket-gateway.js +34 -0
- package/dist/cjs/lib/web-socket-gateway.js.map +1 -0
- package/dist/esm/lib/appconfig.endpoints.js +7 -1
- package/dist/esm/lib/appconfig.endpoints.js.map +1 -1
- package/dist/esm/lib/client.js +61 -7
- package/dist/esm/lib/client.js.map +1 -1
- package/dist/esm/lib/dataset.endpoints.js +3 -0
- package/dist/esm/lib/dataset.endpoints.js.map +1 -1
- package/dist/esm/lib/web-socket-gateway.js +30 -0
- package/dist/esm/lib/web-socket-gateway.js.map +1 -0
- package/dist/types/lib/appconfig.endpoints.d.ts +2 -1
- package/dist/types/lib/appconfig.endpoints.d.ts.map +1 -1
- package/dist/types/lib/client.d.ts +15 -6
- package/dist/types/lib/client.d.ts.map +1 -1
- package/dist/types/lib/dataset.endpoints.d.ts +2 -1
- package/dist/types/lib/dataset.endpoints.d.ts.map +1 -1
- package/dist/types/lib/web-socket-gateway.d.ts +26 -0
- package/dist/types/lib/web-socket-gateway.d.ts.map +1 -0
- package/package.json +7 -4
|
@@ -22,7 +22,10 @@ var AppConfigEndpoints = /** @class */ (function () {
|
|
|
22
22
|
AppConfigEndpoints.prototype.set = function (path, value, params) {
|
|
23
23
|
if (params === void 0) { params = {}; }
|
|
24
24
|
// Wrap primitives in value object
|
|
25
|
-
if (typeof value === 'string' ||
|
|
25
|
+
if (typeof value === 'string' ||
|
|
26
|
+
typeof value === 'number' ||
|
|
27
|
+
typeof value === 'boolean' ||
|
|
28
|
+
Array.isArray(value)) {
|
|
26
29
|
value = { value: value };
|
|
27
30
|
}
|
|
28
31
|
return this.client._put("".concat(this.resourceEndpoint, "/").concat(path), value, {
|
|
@@ -36,6 +39,9 @@ var AppConfigEndpoints = /** @class */ (function () {
|
|
|
36
39
|
if (params === void 0) { params = {}; }
|
|
37
40
|
return this.client._delete("".concat(this.resourceEndpoint, "/").concat(path), { params: params });
|
|
38
41
|
};
|
|
42
|
+
AppConfigEndpoints.prototype.subscribe = function (cb) {
|
|
43
|
+
return this.client._subscribe('appconfig', cb);
|
|
44
|
+
};
|
|
39
45
|
return AppConfigEndpoints;
|
|
40
46
|
}());
|
|
41
47
|
exports.AppConfigEndpoints = AppConfigEndpoints;
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"appconfig.endpoints.js","sourceRoot":"","sources":["../../../src/lib/appconfig.endpoints.ts"],"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AAM,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"]}
|
package/dist/cjs/lib/client.js
CHANGED
|
@@ -19,24 +19,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.Client = void 0;
|
|
21
21
|
var axios_1 = __importDefault(require("axios"));
|
|
22
|
-
var
|
|
23
|
-
var auth_edpoints_1 = require("./auth.edpoints");
|
|
24
|
-
var tile_endpoints_1 = require("./tile.endpoints");
|
|
25
|
-
var style_endpoint_1 = require("./style.endpoint");
|
|
26
|
-
var map_endoints_1 = require("./map.endoints");
|
|
22
|
+
var debug_1 = require("debug");
|
|
27
23
|
var apikey_endpoints_1 = require("./apikey.endpoints");
|
|
24
|
+
var appconfig_endpoints_1 = require("./appconfig.endpoints");
|
|
28
25
|
var application_endpoints_1 = require("./application.endpoints");
|
|
26
|
+
var auth_edpoints_1 = require("./auth.edpoints");
|
|
29
27
|
var database_endpoints_1 = require("./database.endpoints");
|
|
30
28
|
var dataset_endpoints_1 = require("./dataset.endpoints");
|
|
29
|
+
var errors_1 = require("./errors");
|
|
30
|
+
var job_endpoints_1 = require("./job.endpoints");
|
|
31
|
+
var map_endoints_1 = require("./map.endoints");
|
|
32
|
+
var style_endpoint_1 = require("./style.endpoint");
|
|
31
33
|
var tile_source_endpoints_1 = require("./tile-source.endpoints");
|
|
34
|
+
var tile_endpoints_1 = require("./tile.endpoints");
|
|
32
35
|
var upload_endpoints_1 = require("./upload.endpoints");
|
|
33
|
-
var
|
|
34
|
-
var job_endpoints_1 = require("./job.endpoints");
|
|
36
|
+
var web_socket_gateway_1 = require("./web-socket-gateway");
|
|
35
37
|
var Client = /** @class */ (function () {
|
|
36
38
|
function Client(baseUrl, apiKey) {
|
|
37
39
|
if (apiKey === void 0) { apiKey = null; }
|
|
38
40
|
this.baseUrl = baseUrl;
|
|
39
41
|
this.apiKey = apiKey;
|
|
42
|
+
this.debug = (0, debug_1.debug)('flow-engine-client');
|
|
40
43
|
this.accessToken = null;
|
|
41
44
|
this.auth = new auth_edpoints_1.AuthEndpoints(this);
|
|
42
45
|
this.tiles = new tile_endpoints_1.TileEndpoints(this);
|
|
@@ -106,6 +109,57 @@ var Client = /** @class */ (function () {
|
|
|
106
109
|
.then(function (res) { return res.data; })
|
|
107
110
|
.catch(this.handleError);
|
|
108
111
|
};
|
|
112
|
+
// Subscribe to named channel - errors and messages are delivered via the callback
|
|
113
|
+
Client.prototype._subscribe = function (channel, cb) {
|
|
114
|
+
var _this = this;
|
|
115
|
+
if (!this.webSocketGateway) {
|
|
116
|
+
this.webSocketGateway = (0, web_socket_gateway_1.initializewebSocketGateway)(this);
|
|
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;
|
|
140
|
+
};
|
|
141
|
+
// Unsubscribe from named channel - optional callback is called on completion
|
|
142
|
+
Client.prototype._unsubscribe = function (channel, cb) {
|
|
143
|
+
var _this = this;
|
|
144
|
+
if (!this.webSocketGateway) {
|
|
145
|
+
this.webSocketGateway = (0, web_socket_gateway_1.initializewebSocketGateway)(this);
|
|
146
|
+
}
|
|
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
|
+
});
|
|
162
|
+
};
|
|
109
163
|
/**
|
|
110
164
|
* Normalize errors
|
|
111
165
|
* Throws a new error based on type of input error
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,gDAAyD;AACzD,mCAA2C;AAC3C,iDAAgD;AAEhD,mDAAiD;AACjD,mDAAkD;AAClD,+CAA8C;AAC9C,uDAAqD;AACrD,iEAA+D;AAC/D,2DAAyD;AACzD,yDAAuD;AACvD,iEAA8D;AAC9D,uDAAqD;AACrD,6DAA2D;AAC3D,iDAA+C;AAE/C;IAkBE,gBAAmB,OAAe,EAAkB,MAA4B;QAA5B,uBAAA,EAAA,aAA4B;QAA7D,YAAO,GAAP,OAAO,CAAQ;QAAkB,WAAM,GAAN,MAAM,CAAsB;QAfhF,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,YAAO,GAAG,IAAI,kCAAe,CAAC,IAAI,CAAC,CAAC;QACpC,iBAAY,GAAG,IAAI,4CAAoB,CAAC,IAAI,CAAC,CAAC;QAC9C,cAAS,GAAG,IAAI,wCAAkB,CAAC,IAAI,CAAC,CAAC;QACzC,cAAS,GAAG,IAAI,sCAAiB,CAAC,IAAI,CAAC,CAAC;QACxC,aAAQ,GAAG,IAAI,oCAAgB,CAAC,IAAI,CAAC,CAAC;QACtC,WAAM,GAAG,IAAI,+BAAc,CAAC,IAAI,CAAC,CAAC;QAClC,gBAAW,GAAG,IAAI,2CAAmB,CAAC,IAAI,CAAC,CAAC;QAC5C,YAAO,GAAG,IAAI,kCAAe,CAAC,IAAI,CAAC,CAAC;QACpC,SAAI,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,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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,AA/ID,IA+IC;AA/IY,wBAAM","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport Axios, { AxiosError, AxiosInstance } from 'axios';\nimport { FlowEngineError } from './errors';\nimport { AuthEndpoints } from './auth.edpoints';\nimport { IConfig } from './api-interfaces';\nimport { TileEndpoints } from './tile.endpoints';\nimport { StyleEndpoints } from './style.endpoint';\nimport { MapEndpoints } from './map.endoints';\nimport { ApiKeyEndpoints } from './apikey.endpoints';\nimport { ApplicationEndpoints } from './application.endpoints';\nimport { DatabaseEndpoints } from './database.endpoints';\nimport { DatasetEndpoints } from './dataset.endpoints';\nimport { TileSourceEndpoints } from './tile-source.endpoints';\nimport { UploadEndpoints } from './upload.endpoints';\nimport { AppConfigEndpoints } from './appconfig.endpoints';\nimport { JobEndpoints } from './job.endpoints';\n\nexport class Client {\n private readonly axios: AxiosInstance;\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 /**\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;AAGvC,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,2DAA8G;AAM9G;IAoBE,gBAAmB,OAAe,EAAkB,MAA4B;QAA5B,uBAAA,EAAA,aAA4B;QAA7D,YAAO,GAAP,OAAO,CAAQ;QAAkB,WAAM,GAAN,MAAM,CAAsB;QAjBvE,UAAK,GAAG,IAAA,aAAK,EAAC,oBAAoB,CAAC,CAAC;QAE7C,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,YAAO,GAAG,IAAI,kCAAe,CAAC,IAAI,CAAC,CAAC;QACpC,iBAAY,GAAG,IAAI,4CAAoB,CAAC,IAAI,CAAC,CAAC;QAC9C,cAAS,GAAG,IAAI,wCAAkB,CAAC,IAAI,CAAC,CAAC;QACzC,cAAS,GAAG,IAAI,sCAAiB,CAAC,IAAI,CAAC,CAAC;QACxC,aAAQ,GAAG,IAAI,oCAAgB,CAAC,IAAI,CAAC,CAAC;QACtC,WAAM,GAAG,IAAI,+BAAc,CAAC,IAAI,CAAC,CAAC;QAClC,gBAAW,GAAG,IAAI,2CAAmB,CAAC,IAAI,CAAC,CAAC;QAC5C,YAAO,GAAG,IAAI,kCAAe,CAAC,IAAI,C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aACtF;iBAAM,IAAI,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;gBAC9C,MAAM,IAAI,wBAAe,CAAC,CAAC,CAAC,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"]}
|
|
@@ -69,6 +69,9 @@ var DatasetEndpoints = /** @class */ (function (_super) {
|
|
|
69
69
|
: "apikey=".concat(this.client.apiKey);
|
|
70
70
|
return "".concat(this.client.baseUrl, "/api/v1/datasets/").concat(datasetId, "/export?format=").concat(format, "&").concat(credentials);
|
|
71
71
|
};
|
|
72
|
+
DatasetEndpoints.prototype.subscribe = function (datasetId, cb) {
|
|
73
|
+
return this.client._subscribe("dataset-".concat(datasetId), cb);
|
|
74
|
+
};
|
|
72
75
|
return DatasetEndpoints;
|
|
73
76
|
}(base_endpoints_1.BaseEndpoints));
|
|
74
77
|
exports.DatasetEndpoints = DatasetEndpoints;
|
|
@@ -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,MAAM,EAAE,SAAS,CAAC,MAAM,IAAI,MAAM,GAAE,CAAC;YACrE,KAAK,GAAG,SAAS,CAAC;YAClB,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;YAC5B,OAAO,KAAK,CAAC,SAAS,CAAC;YACvB,OAAO,KAAK,CAAC,MAAM,CAAC;SACrB;QAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,MAAM,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;SAC7B;QAED,OAAO,IAAI,CAAC,MAAM;aACf,KAAK,CAAC,2BAAoB,SAAS,WAAQ,EAAE,KAAK,EAAE;YACnD,MAAM,wBACD,MAAM,KACT,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM,EAC/B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,GACjC;SACF,CAAC;aACD,KAAK,CAAC,UAAA,CAAC;YACN,IAAI,CAAC,CAAC,OAAO,KAAK,eAAe,EAAE;gBACjC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;aACpC;iBAAM;gBACL,MAAM,CAAC,CAAC;aACT;QACH,CAAC,CAAC,CAAC;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AAE;YACnD,MAAM,wBACD,MAAM,KACT,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM,EAC/B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,GACjC;SACF,CAAC;aACD,KAAK,CAAC,UAAA,CAAC;YACN,IAAI,CAAC,CAAC,OAAO,KAAK,eAAe,EAAE;gBACjC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;aACpC;iBAAM;gBACL,MAAM,CAAC,CAAC;aACT;QACH,CAAC,CAAC,CAAC;IACP,CAAC;IAED,uCAAY,GAAZ,UAAa,SAAiB,EAAE,MAAwB;QACtD,IAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW;YACzC,CAAC,CAAC,sBAAe,IAAI,CAAC,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, 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"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializewebSocketGateway = exports.WebSocketChannel = void 0;
|
|
4
|
+
var debug_1 = require("debug");
|
|
5
|
+
var socket_io_client_1 = require("socket.io-client");
|
|
6
|
+
var debug = (0, debug_1.debug)('flow-engine-client');
|
|
7
|
+
var WebSocketChannel;
|
|
8
|
+
(function (WebSocketChannel) {
|
|
9
|
+
WebSocketChannel["System"] = "system";
|
|
10
|
+
WebSocketChannel["AppConfig"] = "appconfig";
|
|
11
|
+
WebSocketChannel["Dataset"] = "dataset/";
|
|
12
|
+
})(WebSocketChannel = exports.WebSocketChannel || (exports.WebSocketChannel = {}));
|
|
13
|
+
function initializewebSocketGateway(client, options) {
|
|
14
|
+
var websocketHeaders = {};
|
|
15
|
+
if (client.apiKey) {
|
|
16
|
+
websocketHeaders['x-api-key'] = client.apiKey;
|
|
17
|
+
}
|
|
18
|
+
if (client.accessToken) {
|
|
19
|
+
websocketHeaders.Authorization = "Bearer ".concat(client.accessToken);
|
|
20
|
+
}
|
|
21
|
+
var socket = (0, socket_io_client_1.io)(client.baseUrl, {
|
|
22
|
+
withCredentials: true,
|
|
23
|
+
extraHeaders: websocketHeaders
|
|
24
|
+
});
|
|
25
|
+
socket.on('connect', function () {
|
|
26
|
+
debug("Socket connected: ".concat(socket.id)); // x8WIv7-mJelg7on_ALbx
|
|
27
|
+
});
|
|
28
|
+
socket.on('disconnect', function () {
|
|
29
|
+
debug("Socket disconnected: ".concat(socket.id)); // undefined
|
|
30
|
+
});
|
|
31
|
+
return socket;
|
|
32
|
+
}
|
|
33
|
+
exports.initializewebSocketGateway = initializewebSocketGateway;
|
|
34
|
+
//# sourceMappingURL=web-socket-gateway.js.map
|
|
@@ -0,0 +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,aAAa,GAAG,iBAAU,MAAM,CAAC,WAAW,CAAE,CAAC;KACjE;IAED,IAAM,MAAM,GAAG,IAAA,qBAAE,EAAC,MAAM,CAAC,OAAO,EAAE;QAChC,eAAe,EAAE,IAAI;QACrB,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;AA5BD,gEA4BC","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.Authorization = `Bearer ${client.accessToken}`;\n }\n\n const socket = io(client.baseUrl, {\n withCredentials: true,\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"]}
|
|
@@ -19,7 +19,10 @@ var AppConfigEndpoints = /** @class */ (function () {
|
|
|
19
19
|
AppConfigEndpoints.prototype.set = function (path, value, params) {
|
|
20
20
|
if (params === void 0) { params = {}; }
|
|
21
21
|
// Wrap primitives in value object
|
|
22
|
-
if (typeof value === 'string' ||
|
|
22
|
+
if (typeof value === 'string' ||
|
|
23
|
+
typeof value === 'number' ||
|
|
24
|
+
typeof value === 'boolean' ||
|
|
25
|
+
Array.isArray(value)) {
|
|
23
26
|
value = { value: value };
|
|
24
27
|
}
|
|
25
28
|
return this.client._put("".concat(this.resourceEndpoint, "/").concat(path), value, {
|
|
@@ -33,6 +36,9 @@ var AppConfigEndpoints = /** @class */ (function () {
|
|
|
33
36
|
if (params === void 0) { params = {}; }
|
|
34
37
|
return this.client._delete("".concat(this.resourceEndpoint, "/").concat(path), { params: params });
|
|
35
38
|
};
|
|
39
|
+
AppConfigEndpoints.prototype.subscribe = function (cb) {
|
|
40
|
+
return this.client._subscribe('appconfig', cb);
|
|
41
|
+
};
|
|
36
42
|
return AppConfigEndpoints;
|
|
37
43
|
}());
|
|
38
44
|
export { AppConfigEndpoints };
|
|
@@ -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,C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BACP,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"]}
|
package/dist/esm/lib/client.js
CHANGED
|
@@ -13,24 +13,27 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
return __assign.apply(this, arguments);
|
|
14
14
|
};
|
|
15
15
|
import Axios from 'axios';
|
|
16
|
-
import {
|
|
17
|
-
import { AuthEndpoints } from './auth.edpoints';
|
|
18
|
-
import { TileEndpoints } from './tile.endpoints';
|
|
19
|
-
import { StyleEndpoints } from './style.endpoint';
|
|
20
|
-
import { MapEndpoints } from './map.endoints';
|
|
16
|
+
import { debug as Debug } from 'debug';
|
|
21
17
|
import { ApiKeyEndpoints } from './apikey.endpoints';
|
|
18
|
+
import { AppConfigEndpoints } from './appconfig.endpoints';
|
|
22
19
|
import { ApplicationEndpoints } from './application.endpoints';
|
|
20
|
+
import { AuthEndpoints } from './auth.edpoints';
|
|
23
21
|
import { DatabaseEndpoints } from './database.endpoints';
|
|
24
22
|
import { DatasetEndpoints } from './dataset.endpoints';
|
|
23
|
+
import { FlowEngineError } from './errors';
|
|
24
|
+
import { JobEndpoints } from './job.endpoints';
|
|
25
|
+
import { MapEndpoints } from './map.endoints';
|
|
26
|
+
import { StyleEndpoints } from './style.endpoint';
|
|
25
27
|
import { TileSourceEndpoints } from './tile-source.endpoints';
|
|
28
|
+
import { TileEndpoints } from './tile.endpoints';
|
|
26
29
|
import { UploadEndpoints } from './upload.endpoints';
|
|
27
|
-
import {
|
|
28
|
-
import { JobEndpoints } from './job.endpoints';
|
|
30
|
+
import { initializewebSocketGateway } from './web-socket-gateway';
|
|
29
31
|
var Client = /** @class */ (function () {
|
|
30
32
|
function Client(baseUrl, apiKey) {
|
|
31
33
|
if (apiKey === void 0) { apiKey = null; }
|
|
32
34
|
this.baseUrl = baseUrl;
|
|
33
35
|
this.apiKey = apiKey;
|
|
36
|
+
this.debug = Debug('flow-engine-client');
|
|
34
37
|
this.accessToken = null;
|
|
35
38
|
this.auth = new AuthEndpoints(this);
|
|
36
39
|
this.tiles = new TileEndpoints(this);
|
|
@@ -100,6 +103,57 @@ var Client = /** @class */ (function () {
|
|
|
100
103
|
.then(function (res) { return res.data; })
|
|
101
104
|
.catch(this.handleError);
|
|
102
105
|
};
|
|
106
|
+
// Subscribe to named channel - errors and messages are delivered via the callback
|
|
107
|
+
Client.prototype._subscribe = function (channel, cb) {
|
|
108
|
+
var _this = this;
|
|
109
|
+
if (!this.webSocketGateway) {
|
|
110
|
+
this.webSocketGateway = initializewebSocketGateway(this);
|
|
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;
|
|
134
|
+
};
|
|
135
|
+
// Unsubscribe from named channel - optional callback is called on completion
|
|
136
|
+
Client.prototype._unsubscribe = function (channel, cb) {
|
|
137
|
+
var _this = this;
|
|
138
|
+
if (!this.webSocketGateway) {
|
|
139
|
+
this.webSocketGateway = initializewebSocketGateway(this);
|
|
140
|
+
}
|
|
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
|
+
});
|
|
156
|
+
};
|
|
103
157
|
/**
|
|
104
158
|
* Normalize errors
|
|
105
159
|
* Throws a new error based on type of input error
|
|
@@ -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,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;IAkBE,gBAAmB,OAAe,EAAkB,MAA4B;QAA5B,uBAAA,EAAA,aAA4B;QAA7D,YAAO,GAAP,OAAO,CAAQ;QAAkB,WAAM,GAAN,MAAM,CAAsB;QAfhF,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AAM,IAAI,eAAe,CAAC,CAAC,CAAC,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,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,AA/ID,IA+IC","sourcesContent":["/**\n * Copyright © 2018 Emu Analytics\n */\n\nimport Axios, { AxiosError, AxiosInstance } from 'axios';\nimport { FlowEngineError } from './errors';\nimport { AuthEndpoints } from './auth.edpoints';\nimport { IConfig } from './api-interfaces';\nimport { TileEndpoints } from './tile.endpoints';\nimport { StyleEndpoints } from './style.endpoint';\nimport { MapEndpoints } from './map.endoints';\nimport { ApiKeyEndpoints } from './apikey.endpoints';\nimport { ApplicationEndpoints } from './application.endpoints';\nimport { DatabaseEndpoints } from './database.endpoints';\nimport { DatasetEndpoints } from './dataset.endpoints';\nimport { TileSourceEndpoints } from './tile-source.endpoints';\nimport { UploadEndpoints } from './upload.endpoints';\nimport { AppConfigEndpoints } from './appconfig.endpoints';\nimport { JobEndpoints } from './job.endpoints';\n\nexport class Client {\n private readonly axios: AxiosInstance;\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 /**\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;AAGvC,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;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iBAAM,IAAI,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;gBAC9C,MAAM,IAAI,eAAe,CAAC,CAAC,CAAC,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,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,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"]}
|
|
@@ -66,6 +66,9 @@ var DatasetEndpoints = /** @class */ (function (_super) {
|
|
|
66
66
|
: "apikey=".concat(this.client.apiKey);
|
|
67
67
|
return "".concat(this.client.baseUrl, "/api/v1/datasets/").concat(datasetId, "/export?format=").concat(format, "&").concat(credentials);
|
|
68
68
|
};
|
|
69
|
+
DatasetEndpoints.prototype.subscribe = function (datasetId, cb) {
|
|
70
|
+
return this.client._subscribe("dataset-".concat(datasetId), cb);
|
|
71
|
+
};
|
|
69
72
|
return DatasetEndpoints;
|
|
70
73
|
}(BaseEndpoints));
|
|
71
74
|
export { DatasetEndpoints };
|
|
@@ -1 +1 @@
|
|
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WAAQ,EAAE,KAAK,EAAE;YACnD,MAAM,wBACD,MAAM,KACT,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM,EAC/B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,GACjC;SACF,CAAC;aACD,KAAK,CAAC,UAAA,CAAC;YACN,IAAI,CAAC,CAAC,OAAO,KAAK,eAAe,EAAE;gBACjC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;aACpC;iBAAM;gBACL,MAAM,CAAC,CAAC;aACT;QACH,CAAC,CAAC,CAAC;IACP,CAAC;IAED,uCAAY,GAAZ,UAAa,SAAiB,EAAE,MAAwB;QACtD,IAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW;YACzC,CAAC,CAAC,sBAAe,IAAI,CAAC,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,aAAa,GAkDlD","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"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { debug as Debug } from 'debug';
|
|
2
|
+
import { io } from 'socket.io-client';
|
|
3
|
+
var debug = Debug('flow-engine-client');
|
|
4
|
+
export var WebSocketChannel;
|
|
5
|
+
(function (WebSocketChannel) {
|
|
6
|
+
WebSocketChannel["System"] = "system";
|
|
7
|
+
WebSocketChannel["AppConfig"] = "appconfig";
|
|
8
|
+
WebSocketChannel["Dataset"] = "dataset/";
|
|
9
|
+
})(WebSocketChannel || (WebSocketChannel = {}));
|
|
10
|
+
export function initializewebSocketGateway(client, options) {
|
|
11
|
+
var websocketHeaders = {};
|
|
12
|
+
if (client.apiKey) {
|
|
13
|
+
websocketHeaders['x-api-key'] = client.apiKey;
|
|
14
|
+
}
|
|
15
|
+
if (client.accessToken) {
|
|
16
|
+
websocketHeaders.Authorization = "Bearer ".concat(client.accessToken);
|
|
17
|
+
}
|
|
18
|
+
var socket = io(client.baseUrl, {
|
|
19
|
+
withCredentials: true,
|
|
20
|
+
extraHeaders: websocketHeaders
|
|
21
|
+
});
|
|
22
|
+
socket.on('connect', function () {
|
|
23
|
+
debug("Socket connected: ".concat(socket.id)); // x8WIv7-mJelg7on_ALbx
|
|
24
|
+
});
|
|
25
|
+
socket.on('disconnect', function () {
|
|
26
|
+
debug("Socket disconnected: ".concat(socket.id)); // undefined
|
|
27
|
+
});
|
|
28
|
+
return socket;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=web-socket-gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-socket-gateway.js","sourceRoot":"","sources":["../../../src/lib/web-socket-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,EAAE,EAAiC,MAAM,kBAAkB,CAAC;AAErE,IAAM,KAAK,GAAG,KAAK,CAAC,oBAAoB,CAAC,CAAC;AAE1C,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,qCAAiB,CAAA;IACjB,2CAAuB,CAAA;IACvB,wCAAoB,CAAA;AACtB,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B;AAwBD,MAAM,UAAU,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,aAAa,GAAG,iBAAU,MAAM,CAAC,WAAW,CAAE,CAAC;KACjE;IAED,IAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE;QAChC,eAAe,EAAE,IAAI;QACrB,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","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.Authorization = `Bearer ${client.accessToken}`;\n }\n\n const socket = io(client.baseUrl, {\n withCredentials: true,\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,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright © 2018 Emu Analytics
|
|
3
3
|
*/
|
|
4
|
-
import { Client } from './client';
|
|
4
|
+
import { Client, WebSocketSubscribeCallback, WebSocketUnsubscriber } from './client';
|
|
5
5
|
export declare class AppConfigEndpoints {
|
|
6
6
|
private readonly client;
|
|
7
7
|
constructor(client: Client);
|
|
@@ -9,5 +9,6 @@ export declare class AppConfigEndpoints {
|
|
|
9
9
|
get(path?: string, params?: Record<string, any>): Promise<any>;
|
|
10
10
|
set(path: string, value: any, params?: Record<string, any>): Promise<any>;
|
|
11
11
|
delete(path: string, params?: Record<string, any>): Promise<any>;
|
|
12
|
+
subscribe(cb: WebSocketSubscribeCallback): WebSocketUnsubscriber;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=appconfig.endpoints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appconfig.endpoints.d.ts","sourceRoot":"","sources":["../../../src/lib/appconfig.endpoints.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"appconfig.endpoints.d.ts","sourceRoot":"","sources":["../../../src/lib/appconfig.endpoints.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAErF,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C,OAAO,KAAK,gBAAgB,GAE3B;IAED,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIlE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAmB7E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIpE,SAAS,CAAC,EAAE,EAAE,0BAA0B,GAAG,qBAAqB;CAGjE"}
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright © 2018 Emu Analytics
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
/// <reference types="debug" />
|
|
5
5
|
import { IConfig } from './api-interfaces';
|
|
6
|
-
import { TileEndpoints } from './tile.endpoints';
|
|
7
|
-
import { StyleEndpoints } from './style.endpoint';
|
|
8
|
-
import { MapEndpoints } from './map.endoints';
|
|
9
6
|
import { ApiKeyEndpoints } from './apikey.endpoints';
|
|
7
|
+
import { AppConfigEndpoints } from './appconfig.endpoints';
|
|
10
8
|
import { ApplicationEndpoints } from './application.endpoints';
|
|
9
|
+
import { AuthEndpoints } from './auth.edpoints';
|
|
11
10
|
import { DatabaseEndpoints } from './database.endpoints';
|
|
12
11
|
import { DatasetEndpoints } from './dataset.endpoints';
|
|
12
|
+
import { JobEndpoints } from './job.endpoints';
|
|
13
|
+
import { MapEndpoints } from './map.endoints';
|
|
14
|
+
import { StyleEndpoints } from './style.endpoint';
|
|
13
15
|
import { TileSourceEndpoints } from './tile-source.endpoints';
|
|
16
|
+
import { TileEndpoints } from './tile.endpoints';
|
|
14
17
|
import { UploadEndpoints } from './upload.endpoints';
|
|
15
|
-
import {
|
|
16
|
-
|
|
18
|
+
import { WebSocketPublishMessage } from './web-socket-gateway';
|
|
19
|
+
export declare type WebSocketSubscribeCallback = (err: Error | null, msg?: WebSocketPublishMessage) => void;
|
|
20
|
+
export declare type WebSocketUnsubscribeCallback = (err: Error | null) => void;
|
|
21
|
+
export declare type WebSocketUnsubscriber = (cb?: WebSocketUnsubscribeCallback) => void;
|
|
17
22
|
export declare class Client {
|
|
18
23
|
baseUrl: string;
|
|
19
24
|
readonly apiKey: string | null;
|
|
20
25
|
private readonly axios;
|
|
26
|
+
private webSocketGateway?;
|
|
27
|
+
readonly debug: import("debug").Debugger;
|
|
21
28
|
accessToken: string | null;
|
|
22
29
|
auth: AuthEndpoints;
|
|
23
30
|
tiles: TileEndpoints;
|
|
@@ -37,6 +44,8 @@ export declare class Client {
|
|
|
37
44
|
_post(path: string, data: object, options?: any): Promise<any>;
|
|
38
45
|
_put(path: string, data: object, options?: any): Promise<any>;
|
|
39
46
|
_delete(path: string, options?: any): Promise<any>;
|
|
47
|
+
_subscribe(channel: string, cb: WebSocketSubscribeCallback): WebSocketUnsubscriber;
|
|
48
|
+
_unsubscribe(channel: string, cb?: WebSocketUnsubscribeCallback): void;
|
|
40
49
|
/**
|
|
41
50
|
* Normalize errors
|
|
42
51
|
* Throws a new error based on type of input error
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":"AAAA;;GAEG
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAKH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,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;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YA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