@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
@@ -4,20 +4,56 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../../_virtual/_tslib.js');
6
6
  var QueryString = require('qs');
7
+ var pkceChallenge = require('pkce-challenge');
7
8
  var fetcher = require('./fetcher.js');
8
9
  var events = require('./events.js');
9
10
  var utils = require('./utils.js');
10
11
  var workspaces = require('./endpoints/workspaces.js');
11
12
  var ApiError = require('./ApiError.js');
13
+ var users = require('./endpoints/users.js');
14
+ var ImportProcessing = require('./ImportProcessing.js');
12
15
 
13
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
17
 
15
18
  var QueryString__default = /*#__PURE__*/_interopDefaultLegacy(QueryString);
19
+ var pkceChallenge__default = /*#__PURE__*/_interopDefaultLegacy(pkceChallenge);
16
20
 
21
+ function dataURItoBlob(dataURI) {
22
+ // convert base64/URLEncoded data component to raw binary data held in a string
23
+ var byteString;
24
+ if (dataURI.split(',')[0].indexOf('base64') >= 0)
25
+ byteString = atob(dataURI.split(',')[1]);
26
+ else
27
+ byteString = unescape(dataURI.split(',')[1]);
28
+ // separate out the mime component
29
+ var metadata = dataURI
30
+ .split(';')
31
+ .filter(function (v, k, all) { return k < all.length - 1; })
32
+ .map(function (v) { return v.split(/:/); });
33
+ var _a = metadata.find(function (_a) {
34
+ var k = _a[0]; _a[1];
35
+ return k === 'data';
36
+ }) || [], _b = _a[1], mimeString = _b === void 0 ? '' : _b;
37
+ var _c = mimeString.split(/\//), ext = _c[1];
38
+ var _d = metadata.find(function (_a) {
39
+ var k = _a[0]; _a[1];
40
+ return k === 'filename';
41
+ }) || [], _e = _d[1], fileName = _e === void 0 ? "file.".concat(ext) : _e;
42
+ // write the bytes of the string to a typed array
43
+ var ia = new Uint8Array(byteString.length);
44
+ for (var i = 0; i < byteString.length; i++) {
45
+ ia[i] = byteString.charCodeAt(i);
46
+ }
47
+ return [new Blob([ia], { type: mimeString }), fileName];
48
+ }
17
49
  var Api = /** @class */ (function (_super) {
18
50
  _tslib.__extends(Api, _super);
19
- function Api() {
20
- return _super !== null && _super.apply(this, arguments) || this;
51
+ function Api(opts) {
52
+ var _this = this;
53
+ var _a, _b;
54
+ _this = _super.call(this, opts.host, (_a = opts === null || opts === void 0 ? void 0 : opts.oidc) === null || _a === void 0 ? void 0 : _a.clientIdHeader) || this;
55
+ _this.opts = _tslib.__assign(_tslib.__assign({}, opts), { oidc: _tslib.__assign({ url: 'http://studio.local.prisme.ai:3001', clientId: 'local-client-id', redirectUri: 'http://studio.local.prisme.ai:3000/signin' }, opts.oidc), websockets: _tslib.__assign(_tslib.__assign({}, opts.websockets), { transports: ((_b = opts.websockets) === null || _b === void 0 ? void 0 : _b.transports) || ['polling', 'websocket'] }) });
56
+ return _this;
21
57
  }
22
58
  Object.defineProperty(Api.prototype, "user", {
23
59
  get: function () {
@@ -41,19 +77,86 @@ var Api = /** @class */ (function (_super) {
41
77
  });
42
78
  });
43
79
  };
44
- Api.prototype.signin = function (email, password) {
80
+ Api.prototype.clientId = function () {
81
+ var _a, _b;
82
+ return this.overwriteClientId || ((_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.oidc) === null || _b === void 0 ? void 0 : _b.clientId);
83
+ };
84
+ Api.prototype.getAuthorizationURL = function (overrideRedirectUri, authParams, locale) {
85
+ var _a, _b;
86
+ if (locale === void 0) { locale = ((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.language)
87
+ ? window.navigator.language.substring(0, 2)
88
+ : undefined; }
45
89
  return _tslib.__awaiter(this, void 0, void 0, function () {
46
- var user;
90
+ var url, clientId, _c, codeVerifier, codeChallenge;
91
+ return _tslib.__generator(this, function (_d) {
92
+ switch (_d.label) {
93
+ case 0:
94
+ url = new URL('/oidc/auth', this.opts.oidc.url);
95
+ url.searchParams.set('response_type', 'code');
96
+ url.searchParams.set('response_mode', 'query'); // Send the final authorization code as a query param to the redirect uri
97
+ url.searchParams.set('redirect_uri', overrideRedirectUri || ((_b = this.opts.oidc) === null || _b === void 0 ? void 0 : _b.redirectUri) || '');
98
+ url.searchParams.set('scope', 'openid profile email settings offline_access events:write events:read webhooks pages:read files:write files:read');
99
+ clientId = this.clientId();
100
+ url.searchParams.set('client_id', clientId);
101
+ url.searchParams.set('code_challenge_method', 'S256');
102
+ return [4 /*yield*/, pkceChallenge__default["default"](64)];
103
+ case 1:
104
+ _c = _d.sent(), codeVerifier = _c.code_verifier, codeChallenge = _c.code_challenge;
105
+ url.searchParams.set('code_challenge', codeChallenge);
106
+ if (locale) {
107
+ url.searchParams.set('locale', locale);
108
+ }
109
+ Object.entries(authParams || {}).forEach(function (_a) {
110
+ var k = _a[0], v = _a[1];
111
+ url.searchParams.set(k, v);
112
+ });
113
+ return [2 /*return*/, {
114
+ url: url.toString(),
115
+ codeVerifier: codeVerifier,
116
+ clientId: clientId,
117
+ }];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ Api.prototype.signin = function (body) {
123
+ return _tslib.__awaiter(this, void 0, void 0, function () {
124
+ var url, redirectTo;
47
125
  return _tslib.__generator(this, function (_a) {
48
126
  switch (_a.label) {
49
- case 0: return [4 /*yield*/, this.post('/login', {
50
- email: email,
51
- password: password,
52
- })];
127
+ case 0:
128
+ url = new URL("/oidc/interaction/".concat(body.interaction, "/login"), this.opts.oidc.url);
129
+ // Do not follow redirects as we need to get redirected from browser itself to save final token in local storage
130
+ return [4 /*yield*/, this.post(url.toString(), new URLSearchParams(body), {
131
+ redirect: 'manual',
132
+ })];
53
133
  case 1:
54
- user = _a.sent();
55
- this._user = user;
56
- return [2 /*return*/, user];
134
+ // Do not follow redirects as we need to get redirected from browser itself to save final token in local storage
135
+ _a.sent();
136
+ redirectTo = new URL("/oidc/auth/".concat(body.interaction), this.opts.oidc.url);
137
+ return [2 /*return*/, { redirectTo: redirectTo.toString() }];
138
+ }
139
+ });
140
+ });
141
+ };
142
+ Api.prototype.getToken = function (authorizationCode, codeVerifier, overrideRedirectUri) {
143
+ return _tslib.__awaiter(this, void 0, void 0, function () {
144
+ var url, token;
145
+ return _tslib.__generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0:
148
+ this.token = null;
149
+ url = new URL('/oidc/token', this.opts.oidc.url);
150
+ return [4 /*yield*/, this.post(url.toString(), new URLSearchParams({
151
+ grant_type: 'authorization_code',
152
+ code: authorizationCode,
153
+ code_verifier: codeVerifier,
154
+ client_id: this.clientId(),
155
+ redirect_uri: overrideRedirectUri || this.opts.oidc.redirectUri,
156
+ }))];
157
+ case 1:
158
+ token = _a.sent();
159
+ return [2 /*return*/, token];
57
160
  }
58
161
  });
59
162
  });
@@ -82,24 +185,22 @@ var Api = /** @class */ (function (_super) {
82
185
  firstName: firstName,
83
186
  lastName: lastName,
84
187
  language: language,
188
+ }, {
189
+ credentials: 'omit',
85
190
  })];
86
191
  case 1: return [2 /*return*/, _a.sent()];
87
192
  }
88
193
  });
89
194
  });
90
195
  };
91
- Api.prototype.signout = function () {
92
- return _tslib.__awaiter(this, void 0, void 0, function () {
93
- return _tslib.__generator(this, function (_a) {
94
- switch (_a.label) {
95
- case 0: return [4 /*yield*/, this.post('/logout')];
96
- case 1:
97
- _a.sent();
98
- this.token = null;
99
- return [2 /*return*/];
100
- }
101
- });
102
- });
196
+ Api.prototype.getSignoutURL = function (redirectUri) {
197
+ var params = new URLSearchParams();
198
+ params.set('client_id', this.clientId());
199
+ if (redirectUri) {
200
+ params.set('post_logout_redirect_uri', redirectUri);
201
+ }
202
+ var url = new URL("/oidc/session/end?".concat(params.toString()), this.opts.oidc.url);
203
+ return url.toString();
103
204
  };
104
205
  // Mail validation
105
206
  Api.prototype.sendValidationMail = function (email, language) {
@@ -148,7 +249,7 @@ var Api = /** @class */ (function (_super) {
148
249
  return _tslib.__awaiter(this, void 0, void 0, function () {
149
250
  return _tslib.__generator(this, function (_a) {
150
251
  switch (_a.label) {
151
- case 0: return [4 /*yield*/, this.get('/workspaces?limit=600')];
252
+ case 0: return [4 /*yield*/, this.get('/workspaces?limit=2000')];
152
253
  case 1: return [2 /*return*/, _a.sent()];
153
254
  }
154
255
  });
@@ -194,11 +295,41 @@ var Api = /** @class */ (function (_super) {
194
295
  });
195
296
  });
196
297
  };
197
- Api.prototype.createWorkspace = function (name) {
298
+ Api.prototype.getWorkspaceSecrets = function (id) {
299
+ return _tslib.__awaiter(this, void 0, void 0, function () {
300
+ return _tslib.__generator(this, function (_a) {
301
+ switch (_a.label) {
302
+ case 0: return [4 /*yield*/, this.get("/workspaces/".concat(id, "/security/secrets"))];
303
+ case 1: return [2 /*return*/, _a.sent()];
304
+ }
305
+ });
306
+ });
307
+ };
308
+ Api.prototype.updateWorkspaceSecrets = function (id, newSecrets) {
309
+ return _tslib.__awaiter(this, void 0, void 0, function () {
310
+ return _tslib.__generator(this, function (_a) {
311
+ switch (_a.label) {
312
+ case 0: return [4 /*yield*/, this.patch("/workspaces/".concat(id, "/security/secrets"), _tslib.__assign({}, newSecrets))];
313
+ case 1: return [2 /*return*/, _a.sent()];
314
+ }
315
+ });
316
+ });
317
+ };
318
+ Api.prototype.deleteWorkspaceSecrets = function (id, secretName) {
319
+ return _tslib.__awaiter(this, void 0, void 0, function () {
320
+ return _tslib.__generator(this, function (_a) {
321
+ switch (_a.label) {
322
+ case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(id, "/security/secrets/").concat(secretName))];
323
+ case 1: return [2 /*return*/, _a.sent()];
324
+ }
325
+ });
326
+ });
327
+ };
328
+ Api.prototype.createWorkspace = function (newWorkspace) {
198
329
  return _tslib.__awaiter(this, void 0, void 0, function () {
199
330
  return _tslib.__generator(this, function (_a) {
200
331
  switch (_a.label) {
201
- case 0: return [4 /*yield*/, this.post('/workspaces', { name: name })];
332
+ case 0: return [4 /*yield*/, this.post('/workspaces', newWorkspace)];
202
333
  case 1: return [2 /*return*/, _a.sent()];
203
334
  }
204
335
  });
@@ -215,6 +346,7 @@ var Api = /** @class */ (function (_super) {
215
346
  });
216
347
  });
217
348
  };
349
+ // @deprecated. Use api.workspaces(id).update() instead
218
350
  Api.prototype.updateWorkspace = function (workspace) {
219
351
  return _tslib.__awaiter(this, void 0, void 0, function () {
220
352
  var _a, _b;
@@ -232,6 +364,7 @@ var Api = /** @class */ (function (_super) {
232
364
  });
233
365
  });
234
366
  };
367
+ // @deprecated. Use api.workspaces(id).delete() instead
235
368
  Api.prototype.deleteWorkspace = function (workspaceId) {
236
369
  return _tslib.__awaiter(this, void 0, void 0, function () {
237
370
  return _tslib.__generator(this, function (_a) {
@@ -300,7 +433,7 @@ var Api = /** @class */ (function (_super) {
300
433
  return _tslib.__awaiter(this, void 0, void 0, function () {
301
434
  return _tslib.__generator(this, function (_a) {
302
435
  switch (_a.label) {
303
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/automations/").concat(automationSlug))];
436
+ case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/automations/").concat(encodeURIComponent(automationSlug)))];
304
437
  case 1: return [2 /*return*/, _a.sent()];
305
438
  }
306
439
  });
@@ -323,7 +456,7 @@ var Api = /** @class */ (function (_super) {
323
456
  switch (_c.label) {
324
457
  case 0:
325
458
  _a = this.patch;
326
- _b = ["/workspaces/".concat(workspaceId, "/automations/").concat(slug)];
459
+ _b = ["/workspaces/".concat(workspaceId, "/automations/").concat(encodeURIComponent(slug))];
327
460
  return [4 /*yield*/, this.replaceAllImagesData(automation, workspaceId)];
328
461
  case 1: return [4 /*yield*/, _a.apply(this, _b.concat([_c.sent()]))];
329
462
  case 2: return [2 /*return*/, _c.sent()];
@@ -335,7 +468,7 @@ var Api = /** @class */ (function (_super) {
335
468
  return _tslib.__awaiter(this, void 0, void 0, function () {
336
469
  return _tslib.__generator(this, function (_a) {
337
470
  switch (_a.label) {
338
- case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/automations/").concat(slug))];
471
+ case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/automations/").concat(encodeURIComponent(slug)))];
339
472
  case 1: return [2 /*return*/, _a.sent()];
340
473
  }
341
474
  });
@@ -430,9 +563,11 @@ var Api = /** @class */ (function (_super) {
430
563
  };
431
564
  // Events
432
565
  Api.prototype.streamEvents = function (workspaceId, filters) {
566
+ var _a, _b;
433
567
  if (filters && filters['source.sessionId'] === true) {
434
568
  if (this.sessionId) {
435
569
  filters['source.sessionId'] = this.sessionId;
570
+ filters['target.userTopic'] = ''; // We do not want to receive userTopics emitted by ourself for this session listener
436
571
  }
437
572
  else {
438
573
  delete filters['source.sessionId'];
@@ -441,10 +576,12 @@ var Api = /** @class */ (function (_super) {
441
576
  var events$1 = new events.Events({
442
577
  workspaceId: workspaceId,
443
578
  token: this.token || '',
579
+ legacyToken: this.legacyToken || '',
444
580
  apiKey: this._apiKey ? this._apiKey : undefined,
445
581
  apiHost: this.host,
446
582
  filters: filters,
447
583
  api: this,
584
+ transports: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.websockets) === null || _b === void 0 ? void 0 : _b.transports,
448
585
  });
449
586
  return new Promise(function (resolve, reject) {
450
587
  var off = events$1.once('connect_error', function () {
@@ -557,7 +694,6 @@ var Api = /** @class */ (function (_super) {
557
694
  throw new ApiError.ApiError({
558
695
  error: 'CollaboratorNotFound',
559
696
  message: 'This user does not exist',
560
- details: { email: email },
561
697
  }, 404);
562
698
  }
563
699
  body.target = { id: contacts.contacts[0].id };
@@ -599,6 +735,17 @@ var Api = /** @class */ (function (_super) {
599
735
  });
600
736
  });
601
737
  };
738
+ Api.prototype.getApp = function (_a) {
739
+ var _b = _a.slug, slug = _b === void 0 ? '' : _b;
740
+ return _tslib.__awaiter(this, void 0, void 0, function () {
741
+ return _tslib.__generator(this, function (_c) {
742
+ switch (_c.label) {
743
+ case 0: return [4 /*yield*/, this.get("/apps/".concat(encodeURIComponent(slug)))];
744
+ case 1: return [2 /*return*/, _c.sent()];
745
+ }
746
+ });
747
+ });
748
+ };
602
749
  Api.prototype.installApp = function (workspaceId, body) {
603
750
  return _tslib.__awaiter(this, void 0, void 0, function () {
604
751
  return _tslib.__generator(this, function (_a) {
@@ -639,6 +786,7 @@ var Api = /** @class */ (function (_super) {
639
786
  });
640
787
  });
641
788
  };
789
+ // @deprecated. Use api.workspaces(id).listAppInstances())
642
790
  Api.prototype.listAppInstances = function (workspaceId) {
643
791
  return _tslib.__awaiter(this, void 0, void 0, function () {
644
792
  return _tslib.__generator(this, function (_a) {
@@ -694,36 +842,9 @@ var Api = /** @class */ (function (_super) {
694
842
  });
695
843
  });
696
844
  };
697
- Api.prototype.uploadFiles = function (files, workspaceId) {
698
- return _tslib.__awaiter(this, void 0, void 0, function () {
699
- function dataURItoBlob(dataURI) {
700
- // convert base64/URLEncoded data component to raw binary data held in a string
701
- var byteString;
702
- if (dataURI.split(',')[0].indexOf('base64') >= 0)
703
- byteString = atob(dataURI.split(',')[1]);
704
- else
705
- byteString = unescape(dataURI.split(',')[1]);
706
- // separate out the mime component
707
- var metadata = dataURI
708
- .split(';')
709
- .filter(function (v, k, all) { return k < all.length - 1; })
710
- .map(function (v) { return v.split(/:/); });
711
- var _a = metadata.find(function (_a) {
712
- var k = _a[0]; _a[1];
713
- return k === 'data';
714
- }) || [], _b = _a[1], mimeString = _b === void 0 ? '' : _b;
715
- var _c = mimeString.split(/\//), ext = _c[1];
716
- var _d = metadata.find(function (_a) {
717
- var k = _a[0]; _a[1];
718
- return k === 'filename';
719
- }) || [], _e = _d[1], fileName = _e === void 0 ? "file.".concat(ext) : _e;
720
- // write the bytes of the string to a typed array
721
- var ia = new Uint8Array(byteString.length);
722
- for (var i = 0; i < byteString.length; i++) {
723
- ia[i] = byteString.charCodeAt(i);
724
- }
725
- return [new Blob([ia], { type: mimeString }), fileName];
726
- }
845
+ // @deprecated. Use api.workspaces(id).uploadFiles()
846
+ Api.prototype.uploadFiles = function (files, workspaceId, opts) {
847
+ return _tslib.__awaiter(this, void 0, void 0, function () {
727
848
  var formData;
728
849
  return _tslib.__generator(this, function (_a) {
729
850
  switch (_a.label) {
@@ -735,6 +856,15 @@ var Api = /** @class */ (function (_super) {
735
856
  }
736
857
  catch (_a) { }
737
858
  });
859
+ if (opts === null || opts === void 0 ? void 0 : opts.expiresAfter) {
860
+ formData.append('expiresAfter', "".concat(opts === null || opts === void 0 ? void 0 : opts.expiresAfter));
861
+ }
862
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.public) === 'boolean') {
863
+ formData.append('public', "".concat(opts === null || opts === void 0 ? void 0 : opts.public));
864
+ }
865
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.shareToken) === 'boolean') {
866
+ formData.append('shareToken', "".concat(opts === null || opts === void 0 ? void 0 : opts.shareToken));
867
+ }
738
868
  _a.label = 1;
739
869
  case 1:
740
870
  _a.trys.push([1, 3, , 4]);
@@ -775,7 +905,7 @@ var Api = /** @class */ (function (_super) {
775
905
  case 'object':
776
906
  var isArray = Array.isArray(mayHaveImage);
777
907
  var withImagesUrl = isArray
778
- ? _tslib.__spreadArray([], mayHaveImage) : _tslib.__assign({}, mayHaveImage);
908
+ ? _tslib.__spreadArray([], mayHaveImage, true) : _tslib.__assign({}, mayHaveImage);
779
909
  for (var _i = 0, _b = Object.keys(withImagesUrl); _i < _b.length; _i++) {
780
910
  var key_1 = _b[_i];
781
911
  withImagesUrl[key_1] = searchImages(withImagesUrl[key_1], uploaded);
@@ -800,6 +930,10 @@ var Api = /** @class */ (function (_super) {
800
930
  });
801
931
  });
802
932
  };
933
+ Api.prototype.getAutomationFromUrl = function (workspaceId, url) {
934
+ var match = url.match("".concat(this.host, "/workspaces/").concat(workspaceId, "/webhooks/(.*$)"));
935
+ return match ? match[1] : false;
936
+ };
803
937
  Api.prototype.callAutomation = function (workspaceId, automation, params) {
804
938
  return _tslib.__awaiter(this, void 0, void 0, function () {
805
939
  return _tslib.__generator(this, function (_a) {
@@ -807,6 +941,17 @@ var Api = /** @class */ (function (_super) {
807
941
  });
808
942
  });
809
943
  };
944
+ Api.prototype.testAutomation = function (_a) {
945
+ var workspaceId = _a.workspaceId, automation = _a.automation, payload = _a.payload;
946
+ return _tslib.__awaiter(this, void 0, void 0, function () {
947
+ return _tslib.__generator(this, function (_b) {
948
+ return [2 /*return*/, this.post("/workspaces/".concat(workspaceId, "/test/").concat(automation), {
949
+ payload: payload,
950
+ })];
951
+ });
952
+ });
953
+ };
954
+ // @deprecated. Use api.workspaces(id).getUsage())
810
955
  Api.prototype.getWorkspaceUsage = function (workspaceId, _a) {
811
956
  var _b = _a === void 0 ? {} : _a, afterDate = _b.afterDate, beforeDate = _b.beforeDate, details = _b.details;
812
957
  return _tslib.__awaiter(this, void 0, void 0, function () {
@@ -821,12 +966,53 @@ var Api = /** @class */ (function (_super) {
821
966
  });
822
967
  });
823
968
  };
969
+ Api.prototype.importArchive = function (archive) {
970
+ return _tslib.__awaiter(this, void 0, void 0, function () {
971
+ var _this = this;
972
+ return _tslib.__generator(this, function (_a) {
973
+ return [2 /*return*/, new Promise(function (resolve) {
974
+ var fileReader = new FileReader();
975
+ fileReader.addEventListener('load', function (_a) {
976
+ var target = _a.target;
977
+ return _tslib.__awaiter(_this, void 0, void 0, function () {
978
+ var file, formData, result;
979
+ return _tslib.__generator(this, function (_b) {
980
+ switch (_b.label) {
981
+ case 0:
982
+ file = target === null || target === void 0 ? void 0 : target.result;
983
+ formData = new FormData();
984
+ formData.append.apply(formData, _tslib.__spreadArray(['archive'], dataURItoBlob(file), false));
985
+ return [4 /*yield*/, this.post("/workspaces/import", formData)];
986
+ case 1:
987
+ result = _b.sent();
988
+ if (result.processing) {
989
+ throw new ImportProcessing.ImportProcessingError(result);
990
+ }
991
+ resolve(result);
992
+ return [2 /*return*/];
993
+ }
994
+ });
995
+ });
996
+ });
997
+ fileReader.readAsDataURL(archive);
998
+ })];
999
+ });
1000
+ });
1001
+ };
1002
+ Api.prototype.users = function (id) {
1003
+ var _a;
1004
+ if (id === void 0) { id = ((_a = this.user) === null || _a === void 0 ? void 0 : _a.id) || ''; }
1005
+ if (!id) {
1006
+ throw new Error();
1007
+ }
1008
+ return new users.UsersEndpoint(id, this);
1009
+ };
824
1010
  Api.prototype.workspaces = function (id) {
825
1011
  return new workspaces.WorkspacesEndpoint(id, this);
826
1012
  };
827
1013
  return Api;
828
1014
  }(fetcher.Fetcher));
829
- var api = new Api('https://api.eda.prisme.ai');
1015
+ var api = new Api({ host: 'https://api.eda.prisme.ai' });
830
1016
 
831
1017
  exports.Api = Api;
832
1018
  exports["default"] = api;
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../../_virtual/_tslib.js');
6
+ var utils = require('../utils.js');
7
+
8
+ var UsersEndpoint = /** @class */ (function () {
9
+ function UsersEndpoint(id, api) {
10
+ this.id = id;
11
+ this.api = api;
12
+ }
13
+ UsersEndpoint.prototype.update = function (data) {
14
+ return _tslib.__awaiter(this, void 0, void 0, function () {
15
+ return _tslib.__generator(this, function (_a) {
16
+ switch (_a.label) {
17
+ case 0:
18
+ if (!utils.isDataURL(data.photo)) return [3 /*break*/, 2];
19
+ return [4 /*yield*/, this.updatePhoto(data.photo)];
20
+ case 1:
21
+ _a.sent();
22
+ delete data.photo;
23
+ _a.label = 2;
24
+ case 2: return [4 /*yield*/, this.api.patch('/user', data)];
25
+ case 3: return [2 /*return*/, _a.sent()];
26
+ }
27
+ });
28
+ });
29
+ };
30
+ UsersEndpoint.prototype.updatePhoto = function (photo) {
31
+ return _tslib.__awaiter(this, void 0, void 0, function () {
32
+ var formData;
33
+ return _tslib.__generator(this, function (_a) {
34
+ switch (_a.label) {
35
+ case 0:
36
+ if (!utils.isDataURL(photo)) {
37
+ throw new Error('Photo must be a dataurl file');
38
+ }
39
+ formData = new FormData();
40
+ formData.append.apply(formData, _tslib.__spreadArray(['photo'], utils.dataURItoBlob(photo), false));
41
+ return [4 /*yield*/, this.api.post("/user/photo", formData)];
42
+ case 1: return [2 /*return*/, _a.sent()];
43
+ }
44
+ });
45
+ });
46
+ };
47
+ UsersEndpoint.prototype.setMeta = function (k, v) {
48
+ return _tslib.__awaiter(this, void 0, void 0, function () {
49
+ var _a;
50
+ return _tslib.__generator(this, function (_b) {
51
+ switch (_b.label) {
52
+ case 0: return [4 /*yield*/, this.api.post("/user/meta", (_a = {},
53
+ _a[k] = v,
54
+ _a))];
55
+ case 1: return [2 /*return*/, _b.sent()];
56
+ }
57
+ });
58
+ });
59
+ };
60
+ UsersEndpoint.prototype.deleteMeta = function (k) {
61
+ return _tslib.__awaiter(this, void 0, void 0, function () {
62
+ return _tslib.__generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0: return [4 /*yield*/, this.api.delete("/user/meta/".concat(k))];
65
+ case 1: return [2 /*return*/, _a.sent()];
66
+ }
67
+ });
68
+ });
69
+ };
70
+ UsersEndpoint.prototype.sendDeleteValidation = function () {
71
+ return _tslib.__awaiter(this, void 0, void 0, function () {
72
+ return _tslib.__generator(this, function (_a) {
73
+ switch (_a.label) {
74
+ case 0: return [4 /*yield*/, this.api.delete("/user")];
75
+ case 1: return [2 /*return*/, _a.sent()];
76
+ }
77
+ });
78
+ });
79
+ };
80
+ UsersEndpoint.prototype.delete = function (token) {
81
+ return _tslib.__awaiter(this, void 0, void 0, function () {
82
+ return _tslib.__generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0: return [4 /*yield*/, this.api.delete("/users/".concat(this.id, "?token=").concat(token))];
85
+ case 1: return [2 /*return*/, _a.sent()];
86
+ }
87
+ });
88
+ });
89
+ };
90
+ return UsersEndpoint;
91
+ }());
92
+
93
+ exports.UsersEndpoint = UsersEndpoint;
94
+ exports["default"] = UsersEndpoint;