@prisme.ai/sdk 1.0.0 → 1.0.2

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.
Files changed (38) hide show
  1. package/Readme.md +3 -1
  2. package/dist/_virtual/_tslib.js +17 -8
  3. package/dist/lib/ImportProcessing.d.ts +19 -0
  4. package/dist/lib/WorkspacesEndpoint.d.ts +10 -0
  5. package/dist/lib/api.d.ts +88 -29
  6. package/dist/lib/endpoints/users.d.ts +13 -0
  7. package/dist/lib/endpoints/workspaces.d.ts +16 -0
  8. package/dist/lib/endpoints/workspacesVersions.d.ts +2 -2
  9. package/dist/lib/events.d.ts +5 -1
  10. package/dist/lib/fetch.d.ts +2 -0
  11. package/dist/lib/fetcher.d.ts +11 -3
  12. package/dist/lib/interpolate.d.ts +2 -0
  13. package/dist/lib/interpolate.test.d.ts +1 -0
  14. package/dist/lib/interpolateVars.d.ts +2 -0
  15. package/dist/lib/utils.d.ts +3 -0
  16. package/dist/sdk/lib/ImportProcessing.js +17 -0
  17. package/dist/sdk/lib/WorkspacesEndpoint.js +19 -0
  18. package/dist/sdk/lib/api.js +248 -62
  19. package/dist/sdk/lib/endpoints/users.js +94 -0
  20. package/dist/sdk/lib/endpoints/workspaces.js +121 -0
  21. package/dist/sdk/lib/endpoints/workspacesVersions.js +4 -4
  22. package/dist/sdk/lib/events.js +51 -13
  23. package/dist/sdk/lib/fetch.js +12 -0
  24. package/dist/sdk/lib/fetcher.js +98 -42
  25. package/dist/sdk/lib/interpolate.js +26 -0
  26. package/dist/sdk/lib/interpolateVars.js +26 -0
  27. package/dist/sdk/lib/utils.js +48 -1
  28. package/lib/ImportProcessing.ts +22 -0
  29. package/lib/api.test.ts +90 -60
  30. package/lib/api.ts +318 -79
  31. package/lib/endpoints/users.ts +58 -0
  32. package/lib/endpoints/workspaces.ts +103 -0
  33. package/lib/endpoints/workspacesVersions.ts +13 -9
  34. package/lib/events.test.ts +2 -2
  35. package/lib/events.ts +60 -14
  36. package/lib/fetcher.ts +77 -12
  37. package/lib/utils.ts +39 -0
  38. package/package.json +3 -1
@@ -2,6 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _tslib = require('../../../_virtual/_tslib.js');
6
+ var ImportProcessing = require('../ImportProcessing.js');
7
+ var utils = require('../utils.js');
5
8
  var workspacesVersions = require('./workspacesVersions.js');
6
9
 
7
10
  var WorkspacesEndpoint = /** @class */ (function () {
@@ -16,6 +19,124 @@ var WorkspacesEndpoint = /** @class */ (function () {
16
19
  enumerable: false,
17
20
  configurable: true
18
21
  });
22
+ WorkspacesEndpoint.prototype.update = function (workspace) {
23
+ return _tslib.__awaiter(this, void 0, void 0, function () {
24
+ var _a, _b, _c;
25
+ return _tslib.__generator(this, function (_d) {
26
+ switch (_d.label) {
27
+ case 0:
28
+ _b = (_a = this.api).patch;
29
+ _c = ["/workspaces/".concat(this.id)];
30
+ return [4 /*yield*/, this.api.replaceAllImagesData(workspace, this.id)];
31
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent()]))];
32
+ case 2: return [2 /*return*/, _d.sent()];
33
+ }
34
+ });
35
+ });
36
+ };
37
+ WorkspacesEndpoint.prototype.delete = function () {
38
+ return _tslib.__awaiter(this, void 0, void 0, function () {
39
+ return _tslib.__generator(this, function (_a) {
40
+ switch (_a.label) {
41
+ case 0: return [4 /*yield*/, this.api.delete("/workspaces/".concat(this.id))];
42
+ case 1: return [2 /*return*/, _a.sent()];
43
+ }
44
+ });
45
+ });
46
+ };
47
+ WorkspacesEndpoint.prototype.uploadFiles = function (files, opts) {
48
+ return _tslib.__awaiter(this, void 0, void 0, function () {
49
+ var formData, e_1;
50
+ return _tslib.__generator(this, function (_a) {
51
+ switch (_a.label) {
52
+ case 0:
53
+ formData = new FormData();
54
+ (Array.isArray(files) ? files : [files]).forEach(function (file) {
55
+ try {
56
+ formData.append.apply(formData, _tslib.__spreadArray(['file'], utils.dataURItoBlob(file), false));
57
+ }
58
+ catch (_a) { }
59
+ });
60
+ if (opts === null || opts === void 0 ? void 0 : opts.expiresAfter) {
61
+ formData.append('expiresAfter', "".concat(opts === null || opts === void 0 ? void 0 : opts.expiresAfter));
62
+ }
63
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.public) === 'boolean') {
64
+ formData.append('public', "".concat(opts === null || opts === void 0 ? void 0 : opts.public));
65
+ }
66
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.shareToken) === 'boolean') {
67
+ formData.append('shareToken', "".concat(opts === null || opts === void 0 ? void 0 : opts.shareToken));
68
+ }
69
+ _a.label = 1;
70
+ case 1:
71
+ _a.trys.push([1, 3, , 4]);
72
+ return [4 /*yield*/, this.api.post("/workspaces/".concat(this.id, "/files"), formData)];
73
+ case 2: return [2 /*return*/, _a.sent()];
74
+ case 3:
75
+ e_1 = _a.sent();
76
+ console.error(e_1);
77
+ return [3 /*break*/, 4];
78
+ case 4: return [2 /*return*/, []];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ WorkspacesEndpoint.prototype.listAppInstances = function () {
84
+ return _tslib.__awaiter(this, void 0, void 0, function () {
85
+ return _tslib.__generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0: return [4 /*yield*/, this.api.get("/workspaces/".concat(this.id, "/apps"))];
88
+ case 1: return [2 /*return*/, _a.sent()];
89
+ }
90
+ });
91
+ });
92
+ };
93
+ WorkspacesEndpoint.prototype.getUsage = function (_a) {
94
+ var _b = _a === void 0 ? {} : _a, afterDate = _b.afterDate, beforeDate = _b.beforeDate, details = _b.details;
95
+ return _tslib.__awaiter(this, void 0, void 0, function () {
96
+ var params;
97
+ return _tslib.__generator(this, function (_c) {
98
+ params = new URLSearchParams(utils.removedUndefinedProperties({
99
+ afterDate: "".concat(afterDate || ''),
100
+ beforeDate: "".concat(beforeDate || ''),
101
+ details: "".concat(details || ''),
102
+ }, true));
103
+ return [2 /*return*/, this.api.get("/workspaces/".concat(this.id, "/usage?").concat(params.toString()))];
104
+ });
105
+ });
106
+ };
107
+ WorkspacesEndpoint.prototype.importArchive = function (archive) {
108
+ return _tslib.__awaiter(this, void 0, void 0, function () {
109
+ var _this = this;
110
+ return _tslib.__generator(this, function (_a) {
111
+ return [2 /*return*/, new Promise(function (resolve) {
112
+ var fileReader = new FileReader();
113
+ fileReader.addEventListener('load', function (_a) {
114
+ var target = _a.target;
115
+ return _tslib.__awaiter(_this, void 0, void 0, function () {
116
+ var file, formData, result;
117
+ return _tslib.__generator(this, function (_b) {
118
+ switch (_b.label) {
119
+ case 0:
120
+ file = target === null || target === void 0 ? void 0 : target.result;
121
+ formData = new FormData();
122
+ formData.append.apply(formData, _tslib.__spreadArray(['archive'], utils.dataURItoBlob(file), false));
123
+ return [4 /*yield*/, this.api.post("/workspaces/".concat(this.id, "/import"), formData)];
124
+ case 1:
125
+ result = _b.sent();
126
+ if (result.processing) {
127
+ throw new ImportProcessing.ImportProcessingError(result);
128
+ }
129
+ resolve(result);
130
+ return [2 /*return*/];
131
+ }
132
+ });
133
+ });
134
+ });
135
+ fileReader.readAsDataURL(archive);
136
+ })];
137
+ });
138
+ });
139
+ };
19
140
  return WorkspacesEndpoint;
20
141
  }());
21
142
 
@@ -10,10 +10,10 @@ var WorkspacesVersionsEndpoint = /** @class */ (function () {
10
10
  this.api = api;
11
11
  }
12
12
  WorkspacesVersionsEndpoint.prototype.create = function (version) {
13
- this.api.post("/workspaces/".concat(this.workspaceId, "/versions"), version);
13
+ return this.api.post("/workspaces/".concat(this.workspaceId, "/versions"), version);
14
14
  };
15
- WorkspacesVersionsEndpoint.prototype.rollback = function (versionId) {
16
- this.api.post("/workspaces/".concat(this.workspaceId, "/versions/").concat(versionId, "/rollback"));
15
+ WorkspacesVersionsEndpoint.prototype.rollback = function (versionId, opts) {
16
+ return this.api.post("/workspaces/".concat(this.workspaceId, "/versions/").concat(versionId, "/pull"), opts);
17
17
  };
18
18
  WorkspacesVersionsEndpoint.prototype.export = function (version) {
19
19
  if (version === void 0) { version = 'current'; }
@@ -22,7 +22,7 @@ var WorkspacesVersionsEndpoint = /** @class */ (function () {
22
22
  return _tslib.__generator(this, function (_b) {
23
23
  switch (_b.label) {
24
24
  case 0: return [4 /*yield*/, this.api.prepareRequest("/workspaces/".concat(this.workspaceId, "/versions/").concat(version, "/export"), {
25
- method: 'post'
25
+ method: 'post',
26
26
  })];
27
27
  case 1:
28
28
  res = _b.sent();
@@ -11,30 +11,59 @@ var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
11
11
 
12
12
  var Events = /** @class */ (function () {
13
13
  function Events(_a) {
14
- var workspaceId = _a.workspaceId, token = _a.token, apiKey = _a.apiKey, _b = _a.apiHost, apiHost = _b === void 0 ? 'https://api.eda.prisme.ai' : _b, filters = _a.filters, api = _a.api;
14
+ var workspaceId = _a.workspaceId, token = _a.token, legacyToken = _a.legacyToken, apiKey = _a.apiKey, _b = _a.apiHost, apiHost = _b === void 0 ? 'https://api.eda.prisme.ai' : _b, filters = _a.filters, api = _a.api, transports = _a.transports;
15
15
  var _this = this;
16
16
  this.listeners = new Map();
17
17
  this.workspaceId = workspaceId;
18
18
  var queryString = new URLSearchParams(filters || {}).toString();
19
19
  var fullQueryString = queryString ? "?".concat(queryString) : '';
20
- var extraHeaders = {
21
- 'x-prismeai-token': token,
22
- };
20
+ var extraHeaders = token
21
+ ? {
22
+ authorization: "Bearer ".concat(token),
23
+ }
24
+ : { 'x-prismeai-token': legacyToken };
25
+ this.lastReceivedEventDate = new Date();
23
26
  if (apiKey) {
24
27
  extraHeaders['x-prismeai-api-key'] = apiKey;
25
28
  }
29
+ this.filters = [filters || {}];
30
+ this.listenedUserTopics = new Map();
26
31
  this.client = io__default["default"]("".concat(apiHost, "/workspaces/").concat(workspaceId, "/events").concat(fullQueryString), {
27
32
  extraHeaders: extraHeaders,
28
- withCredentials: true,
33
+ withCredentials: !extraHeaders.authorization,
34
+ transports: transports || ['polling', 'websocket'],
35
+ auth: function (cb) {
36
+ cb({
37
+ // Browser websockets cannot send extraHeaders, so we use socketio-client auth instead
38
+ extraHeaders: transports && transports[0] === 'websocket' ? extraHeaders : {},
39
+ filters: {
40
+ payloadQuery: _this.filters,
41
+ },
42
+ reuseSocketId: _this.socketId,
43
+ });
44
+ },
45
+ });
46
+ this.client.on('connect_error', function (err) {
47
+ console.error("Failed websocket connection : ", err);
48
+ // revert to classic upgrade
49
+ _this.client.io.opts.transports = ['polling', 'websocket'];
50
+ });
51
+ this.client.on('error', function (err) {
52
+ _this.client.io.opts.transports = ['polling', 'websocket'];
29
53
  });
30
- var lastConnectionTime = new Date();
31
54
  var onConnect = function () {
55
+ // First connection
56
+ if (!_this.socketId) {
57
+ _this.socketId = _this.client.id;
58
+ return;
59
+ }
60
+ // Retrieve lost history on reconnection
32
61
  setTimeout(function () { return _tslib.__awaiter(_this, void 0, void 0, function () {
33
62
  var events;
34
63
  var _this = this;
35
64
  return _tslib.__generator(this, function (_a) {
36
65
  switch (_a.label) {
37
- case 0: return [4 /*yield*/, api.getEvents(workspaceId, _tslib.__assign(_tslib.__assign({}, this.filters[this.filters.length - 1]), { afterDate: lastConnectionTime.toISOString() }))];
66
+ case 0: return [4 /*yield*/, api.getEvents(workspaceId, _tslib.__assign(_tslib.__assign({}, this.filters[this.filters.length - 1]), { afterDate: this.lastReceivedEventDate.toISOString() }))];
38
67
  case 1:
39
68
  events = _a.sent();
40
69
  events.reverse().forEach(function (event) {
@@ -47,13 +76,18 @@ var Events = /** @class */ (function () {
47
76
  });
48
77
  }); }, 2000);
49
78
  };
79
+ this.client.on('connect', onConnect);
50
80
  this.client.on('disconnect', function () {
51
- lastConnectionTime = new Date();
81
+ if (!_this.lastReceivedEventDate) {
82
+ _this.lastReceivedEventDate = new Date();
83
+ }
84
+ // Make sure we reconnect with current filters & socketId
85
+ _this.client.auth = _tslib.__assign(_tslib.__assign({}, _this.client.auth), { filters: {
86
+ payloadQuery: _this.filters,
87
+ }, reuseSocketId: _this.socketId });
52
88
  _this.client.off('connect', onConnect);
53
89
  _this.client.on('connect', onConnect);
54
90
  });
55
- this.filters = [filters || {}];
56
- this.listenedUserTopics = new Map();
57
91
  }
58
92
  Object.defineProperty(Events.prototype, "socket", {
59
93
  get: function () {
@@ -75,12 +109,16 @@ var Events = /** @class */ (function () {
75
109
  };
76
110
  Events.prototype.all = function (listener) {
77
111
  var _this = this;
78
- this.client.onAny(listener);
79
- return function () { return _this.client.offAny(listener); };
112
+ var anyListener = function (eventName, eventData) {
113
+ _this.lastReceivedEventDate = new Date(eventData === null || eventData === void 0 ? void 0 : eventData.createdAt);
114
+ return listener(eventName, eventData);
115
+ };
116
+ this.client.onAny(anyListener);
117
+ return function () { return _this.client.offAny(anyListener); };
80
118
  };
81
119
  Events.prototype.on = function (ev, listener) {
82
120
  var _this = this;
83
- this.listeners.set(ev, _tslib.__spreadArray(_tslib.__spreadArray([], (this.listeners.get(ev) || []), true), [listener]));
121
+ this.listeners.set(ev, _tslib.__spreadArray(_tslib.__spreadArray([], (this.listeners.get(ev) || []), true), [listener], false));
84
122
  this.client.on(ev, listener);
85
123
  return function () {
86
124
  _this.listeners.set(ev, (_this.listeners.get(ev) || []).filter(function (l) { return l !== listener; }));
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fetch = global.fetch;
6
+ console.log(fetch);
7
+ // @ts-ignore
8
+ delete global.fetch;
9
+ // @ts-ignore
10
+ delete global.XMLHttpRequest;
11
+
12
+ exports["default"] = fetch;
@@ -3,8 +3,14 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../../_virtual/_tslib.js');
6
+ var FormData = require('form-data');
6
7
  var ApiError = require('./ApiError.js');
7
8
  var HTTPError = require('./HTTPError.js');
9
+ var utils = require('./utils.js');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData);
8
14
 
9
15
  var headersAsObject = function (headers) {
10
16
  return Array.from(headers).reduce(function (prev, _a) {
@@ -13,11 +19,18 @@ var headersAsObject = function (headers) {
13
19
  return (_tslib.__assign(_tslib.__assign({}, prev), (_b = {}, _b[k] = v, _b)));
14
20
  }, {});
15
21
  };
22
+ function isFormData(data) {
23
+ return !!(data.append && typeof data.append === 'function');
24
+ }
25
+ var CSRF_TOKEN_HEADER = 'x-prismeai-csrf-token';
16
26
  var Fetcher = /** @class */ (function () {
17
- function Fetcher(host) {
27
+ function Fetcher(host, clientIdHeader) {
18
28
  this.token = null;
29
+ this.legacyToken = null;
19
30
  this._apiKey = null;
31
+ this._csrfToken = null;
20
32
  this.host = host;
33
+ this.clientIdHeader = clientIdHeader;
21
34
  }
22
35
  Object.defineProperty(Fetcher.prototype, "apiKey", {
23
36
  set: function (apiKey) {
@@ -29,55 +42,99 @@ var Fetcher = /** @class */ (function () {
29
42
  Fetcher.prototype.prepareRequest = function (url, options) {
30
43
  if (options === void 0) { options = {}; }
31
44
  var headers = new Headers(options.headers || {});
32
- if (this.token && !headers.has('x-prismeai-token')) {
33
- headers.append('x-prismeai-token', this.token);
45
+ if (this.token && !headers.has('Authorization')) {
46
+ headers.append('Authorization', "Bearer ".concat(this.token));
47
+ }
48
+ else if (this.legacyToken && !headers.has('Authorization')) {
49
+ headers.append('x-prismeai-token', this.legacyToken);
34
50
  }
35
51
  if (this._apiKey && !headers.has('x-prismeai-apikey')) {
36
52
  headers.append('x-prismeai-api-key', this._apiKey);
37
53
  }
54
+ if (this._csrfToken && options.method && options.method !== 'GET') {
55
+ headers.append(CSRF_TOKEN_HEADER, this._csrfToken);
56
+ }
38
57
  if (this.language) {
39
58
  headers.append('accept-language', this.language);
40
59
  }
41
- if ((!options.body || !(options.body instanceof FormData)) &&
60
+ if (options.body instanceof URLSearchParams) {
61
+ headers.set('Content-Type', 'application/x-www-form-urlencoded');
62
+ }
63
+ if ((!options.body || !(options.body instanceof FormData__default["default"])) &&
42
64
  !headers.has('Content-Type')) {
43
65
  headers.append('Content-Type', 'application/json');
44
66
  }
45
- headers.append('Access-Control-Allow-Origin', '*');
46
- return global.fetch("".concat(this.host).concat(url), _tslib.__assign(_tslib.__assign({}, options), { headers: headers }));
67
+ var fullUrl = url.startsWith('http://') || url.startsWith('https://')
68
+ ? url
69
+ : "".concat(this.host).concat(url);
70
+ return global.fetch(fullUrl, _tslib.__assign(_tslib.__assign({ credentials: headers.has('Authorization') ? 'omit' : 'include' }, options), { headers: headers }));
47
71
  };
48
- Fetcher.prototype._fetch = function (url, options) {
72
+ Fetcher.prototype._fetch = function (url, options, maxRetries) {
73
+ var _a;
49
74
  if (options === void 0) { options = {}; }
75
+ if (maxRetries === void 0) { maxRetries = 3; }
50
76
  return _tslib.__awaiter(this, void 0, void 0, function () {
51
- var res, error, _a, contentType, response, text;
52
- return _tslib.__generator(this, function (_b) {
53
- switch (_b.label) {
54
- case 0: return [4 /*yield*/, this.prepareRequest(url, options)];
77
+ var res, e_1, error, _b, contentType, response, text;
78
+ return _tslib.__generator(this, function (_c) {
79
+ switch (_c.label) {
80
+ case 0:
81
+ _c.trys.push([0, 2, , 5]);
82
+ return [4 /*yield*/, this.prepareRequest(url, options)];
55
83
  case 1:
56
- res = _b.sent();
57
- if (!!res.ok) return [3 /*break*/, 6];
58
- error = void 0;
59
- _b.label = 2;
84
+ res = _c.sent();
85
+ return [3 /*break*/, 5];
60
86
  case 2:
61
- _b.trys.push([2, 4, , 5]);
62
- _a = ApiError.ApiError.bind;
63
- return [4 /*yield*/, res.json()];
87
+ e_1 = _c.sent();
88
+ if (!(maxRetries > 0 && e_1.message === 'Load failed')) return [3 /*break*/, 4];
89
+ return [4 /*yield*/, utils.wait(20)];
64
90
  case 3:
65
- error = new (_a.apply(ApiError.ApiError, [void 0, _b.sent(), res.status]))();
66
- return [3 /*break*/, 5];
67
- case 4:
68
- _b.sent();
69
- error = new HTTPError.HTTPError(res.statusText, res.status);
70
- return [3 /*break*/, 5];
71
- case 5: throw error;
91
+ _c.sent();
92
+ return [2 /*return*/, this._fetch(url, options, --maxRetries)];
93
+ case 4: throw e_1;
94
+ case 5:
95
+ if (options.redirect === 'manual' && res.status === 0) {
96
+ return [2 /*return*/, { redirected: true }];
97
+ }
98
+ this.lastReceivedHeaders = headersAsObject(res.headers);
99
+ if (this.clientIdHeader && this.lastReceivedHeaders[this.clientIdHeader]) {
100
+ this.overwriteClientId = this.lastReceivedHeaders[this.clientIdHeader];
101
+ }
102
+ if (this.lastReceivedHeaders[CSRF_TOKEN_HEADER]) {
103
+ this._csrfToken = this.lastReceivedHeaders[CSRF_TOKEN_HEADER];
104
+ }
105
+ if (!!res.ok) return [3 /*break*/, 12];
106
+ if (!(((_a = res.statusText) === null || _a === void 0 ? void 0 : _a.length) &&
107
+ res.statusText.includes('ECONNRESET') &&
108
+ maxRetries > 0)) return [3 /*break*/, 7];
109
+ console.log("Retrying request towards ".concat(url, " as we received ECONNRESET error : ").concat(res.statusText));
110
+ return [4 /*yield*/, utils.wait(20)];
72
111
  case 6:
73
- contentType = res.headers.get('content-type');
74
- if (!(contentType && contentType.includes('application/json'))) return [3 /*break*/, 10];
75
- _b.label = 7;
112
+ _c.sent();
113
+ return [2 /*return*/, this._fetch(url, options, --maxRetries)];
76
114
  case 7:
77
- _b.trys.push([7, 9, , 10]);
78
- return [4 /*yield*/, res.json()];
115
+ error = void 0;
116
+ _c.label = 8;
79
117
  case 8:
80
- response = (_b.sent()) || {};
118
+ _c.trys.push([8, 10, , 11]);
119
+ _b = ApiError.ApiError.bind;
120
+ return [4 /*yield*/, res.json()];
121
+ case 9:
122
+ error = new (_b.apply(ApiError.ApiError, [void 0, _c.sent(), res.status]))();
123
+ return [3 /*break*/, 11];
124
+ case 10:
125
+ _c.sent();
126
+ error = new HTTPError.HTTPError(res.statusText, res.status);
127
+ return [3 /*break*/, 11];
128
+ case 11: throw error;
129
+ case 12:
130
+ contentType = res.headers.get('content-type');
131
+ if (!(contentType && contentType.includes('application/json'))) return [3 /*break*/, 16];
132
+ _c.label = 13;
133
+ case 13:
134
+ _c.trys.push([13, 15, , 16]);
135
+ return [4 /*yield*/, res.json()];
136
+ case 14:
137
+ response = (_c.sent()) || {};
81
138
  Object.defineProperty(response, 'headers', {
82
139
  value: headersAsObject(res.headers),
83
140
  configurable: false,
@@ -85,16 +142,16 @@ var Fetcher = /** @class */ (function () {
85
142
  writable: false,
86
143
  });
87
144
  return [2 /*return*/, response];
88
- case 9:
89
- _b.sent();
145
+ case 15:
146
+ _c.sent();
90
147
  return [2 /*return*/, {}];
91
- case 10: return [4 /*yield*/, res.text()];
92
- case 11:
93
- text = _b.sent();
148
+ case 16: return [4 /*yield*/, res.text()];
149
+ case 17:
150
+ text = _c.sent();
94
151
  try {
95
152
  return [2 /*return*/, JSON.parse(text)];
96
153
  }
97
- catch (_c) {
154
+ catch (_d) {
98
155
  return [2 /*return*/, text];
99
156
  }
100
157
  return [2 /*return*/];
@@ -111,13 +168,12 @@ var Fetcher = /** @class */ (function () {
111
168
  });
112
169
  });
113
170
  };
114
- Fetcher.prototype.post = function (url, body) {
171
+ Fetcher.prototype.post = function (url, body, opts) {
115
172
  return _tslib.__awaiter(this, void 0, void 0, function () {
116
173
  return _tslib.__generator(this, function (_a) {
117
- return [2 /*return*/, this._fetch(url, {
118
- method: 'POST',
119
- body: body && !(body instanceof FormData) ? JSON.stringify(body) : body,
120
- })];
174
+ return [2 /*return*/, this._fetch(url, _tslib.__assign({ method: 'POST', body: body && !isFormData(body) && !(body instanceof URLSearchParams)
175
+ ? JSON.stringify(body)
176
+ : body }, opts))];
121
177
  });
122
178
  });
123
179
  };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../_virtual/_tslib.js');
6
+
7
+ function interpolateString(str, values) {
8
+ if (values === void 0) { values = {}; }
9
+ return str.replace(/\$\{([^}]+)\}/g, function (_, m) { return values[m] || ''; });
10
+ }
11
+ function interpolate(into, values) {
12
+ if (typeof into === 'string') {
13
+ return interpolateString(into, values);
14
+ }
15
+ var isArray = Array.isArray(into);
16
+ var newObject = isArray ? _tslib.__spreadArray([], into) : _tslib.__assign({}, into);
17
+ for (var _i = 0, _a = Object.keys(newObject); _i < _a.length; _i++) {
18
+ var key = _a[_i];
19
+ var value = newObject[key];
20
+ newObject[key] = interpolate(value, values);
21
+ }
22
+ return newObject;
23
+ }
24
+
25
+ exports.interpolate = interpolate;
26
+ exports.interpolateString = interpolateString;
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../_virtual/_tslib.js');
6
+
7
+ function interpolateString(str, values) {
8
+ if (values === void 0) { values = {}; }
9
+ return str.replace(/\$\{([^}]+)\}/g, function (_, m) { return values[m] || ''; });
10
+ }
11
+ function interpolate(into, values) {
12
+ if (typeof into === 'string') {
13
+ return interpolateString(into, values);
14
+ }
15
+ var isArray = Array.isArray(into);
16
+ var newObject = isArray ? _tslib.__spreadArray([], into) : _tslib.__assign({}, into);
17
+ for (var _i = 0, _a = Object.keys(newObject); _i < _a.length; _i++) {
18
+ var key = _a[_i];
19
+ var value = newObject[key];
20
+ newObject[key] = interpolate(value, values);
21
+ }
22
+ return newObject;
23
+ }
24
+
25
+ exports.interpolate = interpolate;
26
+ exports.interpolateString = interpolateString;
@@ -2,6 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _tslib = require('../../_virtual/_tslib.js');
6
+
5
7
  var removedUndefinedProperties = function (obj, removeEmptyStrings) {
6
8
  if (removeEmptyStrings === void 0) { removeEmptyStrings = false; }
7
9
  return Object.entries(obj).reduce(function (newObject, _a) {
@@ -13,6 +15,51 @@ var removedUndefinedProperties = function (obj, removeEmptyStrings) {
13
15
  }
14
16
  return newObject;
15
17
  }, {});
16
- };
18
+ };
19
+ function dataURItoBlob(dataURI) {
20
+ // convert base64/URLEncoded data component to raw binary data held in a string
21
+ var byteString;
22
+ if (dataURI.split(',')[0].indexOf('base64') >= 0)
23
+ byteString = atob(dataURI.split(',')[1].split(';')[0]);
24
+ else
25
+ byteString = unescape(dataURI.split(',')[1]);
26
+ // separate out the mime component
27
+ var metadata = dataURI
28
+ .split(';')
29
+ .map(function (v) { return v.split(/:/); })
30
+ .filter(function (pair) { return pair.length === 2; });
31
+ var _a = metadata.find(function (_a) {
32
+ var k = _a[0]; _a[1];
33
+ return k === 'data';
34
+ }) || [], _b = _a[1], mimeString = _b === void 0 ? '' : _b;
35
+ var _c = mimeString.split(/\//), ext = _c[1];
36
+ var _d = metadata.find(function (_a) {
37
+ var k = _a[0]; _a[1];
38
+ return k === 'filename';
39
+ }) || [], _e = _d[1], fileName = _e === void 0 ? "file.".concat(ext) : _e;
40
+ var sanitizedFileName = encodeURIComponent(decodeURIComponent(fileName).replace(/[;,\s]/g, '-'));
41
+ // write the bytes of the string to a typed array
42
+ var ia = new Uint8Array(byteString.length);
43
+ for (var i = 0; i < byteString.length; i++) {
44
+ ia[i] = byteString.charCodeAt(i);
45
+ }
46
+ return [new Blob([ia], { type: mimeString }), sanitizedFileName];
47
+ }
48
+ function isDataURL(file) {
49
+ return !!(typeof file === 'string' && file.match(/^data\:/));
50
+ }
51
+ function wait(delay) {
52
+ if (delay === void 0) { delay = 0; }
53
+ return _tslib.__awaiter(this, void 0, void 0, function () {
54
+ return _tslib.__generator(this, function (_a) {
55
+ return [2 /*return*/, new Promise(function (resolve) {
56
+ setTimeout(resolve, delay);
57
+ })];
58
+ });
59
+ });
60
+ }
17
61
 
62
+ exports.dataURItoBlob = dataURItoBlob;
63
+ exports.isDataURL = isDataURL;
18
64
  exports.removedUndefinedProperties = removedUndefinedProperties;
65
+ exports.wait = wait;
@@ -0,0 +1,22 @@
1
+ export type ImportProcessing = {
2
+ processing?: boolean;
3
+ message?: string;
4
+ };
5
+ export class ImportProcessingError extends Error {
6
+ error: ImportProcessing;
7
+ constructor(error: ImportProcessing) {
8
+ super();
9
+ this.error = error;
10
+ }
11
+ }
12
+ export type ImportSuccess = {
13
+ createdWorkspaceIds?: string[];
14
+ updatedWorkspaceIds?: string[];
15
+ imported: string[];
16
+ errors?: {
17
+ [name: string]: any;
18
+ }[];
19
+ workspace?: Prismeai.DSULReadOnly;
20
+ publishedApps?: Prismeai.App[];
21
+ deleted?: string[];
22
+ };