@prisme.ai/sdk 0.0.2 → 1.0.0

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.
@@ -7,6 +7,8 @@ var QueryString = require('qs');
7
7
  var fetcher = require('./fetcher.js');
8
8
  var events = require('./events.js');
9
9
  var utils = require('./utils.js');
10
+ var workspaces = require('./endpoints/workspaces.js');
11
+ var ApiError = require('./ApiError.js');
10
12
 
11
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
14
 
@@ -17,30 +19,60 @@ var Api = /** @class */ (function (_super) {
17
19
  function Api() {
18
20
  return _super !== null && _super.apply(this, arguments) || this;
19
21
  }
22
+ Object.defineProperty(Api.prototype, "user", {
23
+ get: function () {
24
+ return this._user;
25
+ },
26
+ enumerable: false,
27
+ configurable: true
28
+ });
20
29
  Api.prototype.me = function () {
21
30
  return _tslib.__awaiter(this, void 0, void 0, function () {
31
+ var me;
22
32
  return _tslib.__generator(this, function (_a) {
23
33
  switch (_a.label) {
24
34
  case 0: return [4 /*yield*/, this.get('/me')];
25
- case 1: return [2 /*return*/, _a.sent()];
35
+ case 1:
36
+ me = _a.sent();
37
+ this.sessionId = me.sessionId;
38
+ this._user = me;
39
+ return [2 /*return*/, me];
26
40
  }
27
41
  });
28
42
  });
29
43
  };
30
44
  Api.prototype.signin = function (email, password) {
31
45
  return _tslib.__awaiter(this, void 0, void 0, function () {
46
+ var user;
32
47
  return _tslib.__generator(this, function (_a) {
33
48
  switch (_a.label) {
34
49
  case 0: return [4 /*yield*/, this.post('/login', {
35
50
  email: email,
36
51
  password: password,
37
52
  })];
38
- case 1: return [2 /*return*/, _a.sent()];
53
+ case 1:
54
+ user = _a.sent();
55
+ this._user = user;
56
+ return [2 /*return*/, user];
39
57
  }
40
58
  });
41
59
  });
42
60
  };
43
- Api.prototype.signup = function (email, password, firstName, lastName) {
61
+ Api.prototype.createAnonymousSession = function () {
62
+ return _tslib.__awaiter(this, void 0, void 0, function () {
63
+ var user;
64
+ return _tslib.__generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0: return [4 /*yield*/, this.post('/login/anonymous')];
67
+ case 1:
68
+ user = _a.sent();
69
+ this._user = user;
70
+ return [2 /*return*/, user];
71
+ }
72
+ });
73
+ });
74
+ };
75
+ Api.prototype.signup = function (email, password, firstName, lastName, language) {
44
76
  return _tslib.__awaiter(this, void 0, void 0, function () {
45
77
  return _tslib.__generator(this, function (_a) {
46
78
  switch (_a.label) {
@@ -49,6 +81,7 @@ var Api = /** @class */ (function (_super) {
49
81
  password: password,
50
82
  firstName: firstName,
51
83
  lastName: lastName,
84
+ language: language,
52
85
  })];
53
86
  case 1: return [2 /*return*/, _a.sent()];
54
87
  }
@@ -68,12 +101,54 @@ var Api = /** @class */ (function (_super) {
68
101
  });
69
102
  });
70
103
  };
104
+ // Mail validation
105
+ Api.prototype.sendValidationMail = function (email, language) {
106
+ return _tslib.__awaiter(this, void 0, void 0, function () {
107
+ return _tslib.__generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0: return [4 /*yield*/, this.post('/user/validate', { email: email, language: language })];
110
+ case 1: return [2 /*return*/, _a.sent()];
111
+ }
112
+ });
113
+ });
114
+ };
115
+ Api.prototype.validateMail = function (token) {
116
+ return _tslib.__awaiter(this, void 0, void 0, function () {
117
+ return _tslib.__generator(this, function (_a) {
118
+ switch (_a.label) {
119
+ case 0: return [4 /*yield*/, this.post('/user/validate', { token: token })];
120
+ case 1: return [2 /*return*/, _a.sent()];
121
+ }
122
+ });
123
+ });
124
+ };
125
+ // Password reset
126
+ Api.prototype.sendPasswordResetMail = function (email, language) {
127
+ return _tslib.__awaiter(this, void 0, void 0, function () {
128
+ return _tslib.__generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0: return [4 /*yield*/, this.post('/user/password', { email: email, language: language })];
131
+ case 1: return [2 /*return*/, _a.sent()];
132
+ }
133
+ });
134
+ });
135
+ };
136
+ Api.prototype.passwordReset = function (token, password) {
137
+ return _tslib.__awaiter(this, void 0, void 0, function () {
138
+ return _tslib.__generator(this, function (_a) {
139
+ switch (_a.label) {
140
+ case 0: return [4 /*yield*/, this.post('/user/password', { token: token, password: password })];
141
+ case 1: return [2 /*return*/, _a.sent()];
142
+ }
143
+ });
144
+ });
145
+ };
71
146
  // Workspaces
72
147
  Api.prototype.getWorkspaces = function () {
73
148
  return _tslib.__awaiter(this, void 0, void 0, function () {
74
149
  return _tslib.__generator(this, function (_a) {
75
150
  switch (_a.label) {
76
- case 0: return [4 /*yield*/, this.get('/workspaces?limit=300')];
151
+ case 0: return [4 /*yield*/, this.get('/workspaces?limit=600')];
77
152
  case 1: return [2 /*return*/, _a.sent()];
78
153
  }
79
154
  });
@@ -89,6 +164,36 @@ var Api = /** @class */ (function (_super) {
89
164
  });
90
165
  });
91
166
  };
167
+ Api.prototype.getWorkspaceSecurity = function (id) {
168
+ return _tslib.__awaiter(this, void 0, void 0, function () {
169
+ return _tslib.__generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0: return [4 /*yield*/, this.get("/workspaces/".concat(id, "/security"))];
172
+ case 1: return [2 /*return*/, _a.sent()];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ Api.prototype.updateWorkspaceSecurity = function (workspaceId, security) {
178
+ return _tslib.__awaiter(this, void 0, void 0, function () {
179
+ return _tslib.__generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0: return [4 /*yield*/, this.put("/workspaces/".concat(workspaceId, "/security"), security)];
182
+ case 1: return [2 /*return*/, _a.sent()];
183
+ }
184
+ });
185
+ });
186
+ };
187
+ Api.prototype.getWorkspaceRoles = function (id) {
188
+ return _tslib.__awaiter(this, void 0, void 0, function () {
189
+ return _tslib.__generator(this, function (_a) {
190
+ switch (_a.label) {
191
+ case 0: return [4 /*yield*/, this.get("/workspaces/".concat(id, "/security/roles"))];
192
+ case 1: return [2 /*return*/, _a.sent()];
193
+ }
194
+ });
195
+ });
196
+ };
92
197
  Api.prototype.createWorkspace = function (name) {
93
198
  return _tslib.__awaiter(this, void 0, void 0, function () {
94
199
  return _tslib.__generator(this, function (_a) {
@@ -99,12 +204,25 @@ var Api = /** @class */ (function (_super) {
99
204
  });
100
205
  });
101
206
  };
207
+ Api.prototype.duplicateWorkspace = function (_a) {
208
+ var id = _a.id;
209
+ return _tslib.__awaiter(this, void 0, void 0, function () {
210
+ return _tslib.__generator(this, function (_b) {
211
+ switch (_b.label) {
212
+ case 0: return [4 /*yield*/, this.post("/workspaces/".concat(id, "/versions/current/duplicate"), {})];
213
+ case 1: return [2 /*return*/, _b.sent()];
214
+ }
215
+ });
216
+ });
217
+ };
102
218
  Api.prototype.updateWorkspace = function (workspace) {
103
219
  return _tslib.__awaiter(this, void 0, void 0, function () {
104
220
  var _a, _b;
105
221
  return _tslib.__generator(this, function (_c) {
106
222
  switch (_c.label) {
107
223
  case 0:
224
+ if (!workspace.id)
225
+ return [2 /*return*/, null];
108
226
  _a = this.patch;
109
227
  _b = ["/workspaces/".concat(workspace.id)];
110
228
  return [4 /*yield*/, this.replaceAllImagesData(workspace, workspace.id)];
@@ -124,37 +242,100 @@ var Api = /** @class */ (function (_super) {
124
242
  });
125
243
  });
126
244
  };
245
+ Api.prototype.generateApiKey = function (workspaceId, events, uploads) {
246
+ return _tslib.__awaiter(this, void 0, void 0, function () {
247
+ var apiKey;
248
+ return _tslib.__generator(this, function (_a) {
249
+ switch (_a.label) {
250
+ case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/apiKeys"), {
251
+ rules: {
252
+ events: {
253
+ types: events,
254
+ filters: {
255
+ 'source.sessionId': '${user.sessionId}',
256
+ },
257
+ },
258
+ uploads: uploads
259
+ ? {
260
+ mimetypes: uploads,
261
+ }
262
+ : undefined,
263
+ },
264
+ })];
265
+ case 1:
266
+ apiKey = (_a.sent()).apiKey;
267
+ return [2 /*return*/, apiKey];
268
+ }
269
+ });
270
+ });
271
+ };
272
+ Api.prototype.updateApiKey = function (workspaceId, apiKey, events, uploads) {
273
+ return _tslib.__awaiter(this, void 0, void 0, function () {
274
+ return _tslib.__generator(this, function (_a) {
275
+ switch (_a.label) {
276
+ case 0: return [4 /*yield*/, this.put("/workspaces/".concat(workspaceId, "/apiKeys/").concat(apiKey), {
277
+ rules: {
278
+ events: {
279
+ types: events,
280
+ filters: {
281
+ 'source.sessionId': '${user.sessionId}',
282
+ },
283
+ },
284
+ uploads: uploads
285
+ ? {
286
+ mimetypes: uploads,
287
+ }
288
+ : undefined,
289
+ },
290
+ })];
291
+ case 1:
292
+ _a.sent();
293
+ return [2 /*return*/, apiKey];
294
+ }
295
+ });
296
+ });
297
+ };
127
298
  // Automations
128
- Api.prototype.createAutomation = function (workspace, automation) {
299
+ Api.prototype.getAutomation = function (workspaceId, automationSlug) {
300
+ return _tslib.__awaiter(this, void 0, void 0, function () {
301
+ return _tslib.__generator(this, function (_a) {
302
+ switch (_a.label) {
303
+ case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/automations/").concat(automationSlug))];
304
+ case 1: return [2 /*return*/, _a.sent()];
305
+ }
306
+ });
307
+ });
308
+ };
309
+ Api.prototype.createAutomation = function (workspaceId, automation) {
129
310
  return _tslib.__awaiter(this, void 0, void 0, function () {
130
311
  return _tslib.__generator(this, function (_a) {
131
312
  switch (_a.label) {
132
- case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspace.id, "/automations"), _tslib.__assign({}, automation))];
313
+ case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/automations"), _tslib.__assign({}, automation))];
133
314
  case 1: return [2 /*return*/, _a.sent()];
134
315
  }
135
316
  });
136
317
  });
137
318
  };
138
- Api.prototype.updateAutomation = function (workspace, slug, automation) {
319
+ Api.prototype.updateAutomation = function (workspaceId, slug, automation) {
139
320
  return _tslib.__awaiter(this, void 0, void 0, function () {
140
321
  var _a, _b;
141
322
  return _tslib.__generator(this, function (_c) {
142
323
  switch (_c.label) {
143
324
  case 0:
144
325
  _a = this.patch;
145
- _b = ["/workspaces/".concat(workspace.id, "/automations/").concat(slug)];
146
- return [4 /*yield*/, this.replaceAllImagesData(automation, workspace.id)];
326
+ _b = ["/workspaces/".concat(workspaceId, "/automations/").concat(slug)];
327
+ return [4 /*yield*/, this.replaceAllImagesData(automation, workspaceId)];
147
328
  case 1: return [4 /*yield*/, _a.apply(this, _b.concat([_c.sent()]))];
148
329
  case 2: return [2 /*return*/, _c.sent()];
149
330
  }
150
331
  });
151
332
  });
152
333
  };
153
- Api.prototype.deleteAutomation = function (workspace, slug) {
334
+ Api.prototype.deleteAutomation = function (workspaceId, slug) {
154
335
  return _tslib.__awaiter(this, void 0, void 0, function () {
155
336
  return _tslib.__generator(this, function (_a) {
156
337
  switch (_a.label) {
157
- case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspace.id, "/automations/").concat(slug))];
338
+ case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/automations/").concat(slug))];
158
339
  case 1: return [2 /*return*/, _a.sent()];
159
340
  }
160
341
  });
@@ -183,21 +364,21 @@ var Api = /** @class */ (function (_super) {
183
364
  });
184
365
  });
185
366
  };
186
- Api.prototype.getPage = function (workspaceId, pageId) {
367
+ Api.prototype.getPage = function (workspaceId, pageSlug) {
187
368
  return _tslib.__awaiter(this, void 0, void 0, function () {
188
369
  return _tslib.__generator(this, function (_a) {
189
370
  switch (_a.label) {
190
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/pages/").concat(pageId))];
371
+ case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/pages/").concat(encodeURIComponent(pageSlug)))];
191
372
  case 1: return [2 /*return*/, _a.sent()];
192
373
  }
193
374
  });
194
375
  });
195
376
  };
196
- Api.prototype.getPageBySlug = function (pageSlug) {
377
+ Api.prototype.getPageBySlug = function (workspaceSlug, pageSlug) {
197
378
  return _tslib.__awaiter(this, void 0, void 0, function () {
198
379
  return _tslib.__generator(this, function (_a) {
199
380
  switch (_a.label) {
200
- case 0: return [4 /*yield*/, this.get("/pages/".concat(pageSlug))];
381
+ case 0: return [4 /*yield*/, this.get("/pages/".concat(workspaceSlug, "/").concat(encodeURIComponent(pageSlug)))];
201
382
  case 1: return [2 /*return*/, _a.sent()];
202
383
  }
203
384
  });
@@ -216,17 +397,20 @@ var Api = /** @class */ (function (_super) {
216
397
  });
217
398
  });
218
399
  };
219
- // Replace images as dataurl to uploaded url in any type of data
220
- Api.prototype.updatePage = function (workspaceId, page) {
400
+ Api.prototype.updatePage = function (workspaceId, page, prevSlug) {
401
+ if (prevSlug === void 0) { prevSlug = page.slug || ''; }
221
402
  return _tslib.__awaiter(this, void 0, void 0, function () {
222
403
  var _a, updatedPage, _b, _c;
223
404
  return _tslib.__generator(this, function (_d) {
224
405
  switch (_d.label) {
225
406
  case 0:
226
407
  _b = this.patch;
227
- _c = ["/workspaces/".concat(workspaceId, "/pages/").concat(page.id)];
408
+ _c = ["/workspaces/".concat(workspaceId, "/pages/").concat(encodeURIComponent(prevSlug))];
409
+ // Replace images as dataurl to uploaded url in any type of data
228
410
  return [4 /*yield*/, this.replaceAllImagesData(page, workspaceId)];
229
- case 1: return [4 /*yield*/, _b.apply(this, _c.concat([_d.sent()]))];
411
+ case 1: return [4 /*yield*/, _b.apply(this, _c.concat([
412
+ // Replace images as dataurl to uploaded url in any type of data
413
+ _d.sent()]))];
230
414
  case 2:
231
415
  _a = _d.sent(), updatedPage = _tslib.__rest(_a, ["createdAt", "createdBy", "updatedAt", "updatedBy"]);
232
416
  return [2 /*return*/, updatedPage];
@@ -234,27 +418,43 @@ var Api = /** @class */ (function (_super) {
234
418
  });
235
419
  });
236
420
  };
237
- Api.prototype.deletePage = function (workspaceId, pageId) {
421
+ Api.prototype.deletePage = function (workspaceId, pageSlug) {
238
422
  return _tslib.__awaiter(this, void 0, void 0, function () {
239
423
  return _tslib.__generator(this, function (_a) {
240
424
  switch (_a.label) {
241
- case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/pages/").concat(pageId))];
425
+ case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/pages/").concat(encodeURIComponent(pageSlug)))];
242
426
  case 1: return [2 /*return*/, _a.sent()];
243
427
  }
244
428
  });
245
429
  });
246
430
  };
247
431
  // Events
248
- Api.prototype.streamEvents = function (workspaceId) {
249
- var events$1 = new events.Events(workspaceId, this.token || '', this.host);
432
+ Api.prototype.streamEvents = function (workspaceId, filters) {
433
+ if (filters && filters['source.sessionId'] === true) {
434
+ if (this.sessionId) {
435
+ filters['source.sessionId'] = this.sessionId;
436
+ }
437
+ else {
438
+ delete filters['source.sessionId'];
439
+ }
440
+ }
441
+ var events$1 = new events.Events({
442
+ workspaceId: workspaceId,
443
+ token: this.token || '',
444
+ apiKey: this._apiKey ? this._apiKey : undefined,
445
+ apiHost: this.host,
446
+ filters: filters,
447
+ api: this,
448
+ });
250
449
  return new Promise(function (resolve, reject) {
251
- events$1.once('connect', function () {
252
- resolve(events$1);
253
- });
254
- events$1.once('connect_error', function () {
450
+ var off = events$1.once('connect_error', function () {
255
451
  reject();
256
452
  events$1.close();
257
453
  });
454
+ events$1.once('connect', function () {
455
+ off();
456
+ resolve(events$1);
457
+ });
258
458
  });
259
459
  };
260
460
  Api.prototype.getEvents = function (workspaceId, options) {
@@ -301,31 +501,80 @@ var Api = /** @class */ (function (_super) {
301
501
  });
302
502
  });
303
503
  };
504
+ Api.prototype.findContacts = function (query) {
505
+ return _tslib.__awaiter(this, void 0, void 0, function () {
506
+ return _tslib.__generator(this, function (_a) {
507
+ switch (_a.label) {
508
+ case 0: return [4 /*yield*/, this.post("/contacts", query)];
509
+ case 1: return [2 /*return*/, _a.sent()];
510
+ }
511
+ });
512
+ });
513
+ };
304
514
  Api.prototype.getPermissions = function (subjectType, subjectId) {
305
515
  return _tslib.__awaiter(this, void 0, void 0, function () {
516
+ var permissions, contacts;
306
517
  return _tslib.__generator(this, function (_a) {
307
518
  switch (_a.label) {
308
519
  case 0: return [4 /*yield*/, this.get("/".concat(subjectType, "/").concat(subjectId, "/permissions"))];
309
- case 1: return [2 /*return*/, _a.sent()];
520
+ case 1:
521
+ permissions = _a.sent();
522
+ return [4 /*yield*/, this.findContacts({
523
+ ids: permissions.result
524
+ .filter(function (cur) { return cur.target.id && !cur.target.displayName; })
525
+ .map(function (cur) { return cur.target.id; }),
526
+ })];
527
+ case 2:
528
+ contacts = _a.sent();
529
+ return [2 /*return*/, {
530
+ result: permissions.result.map(function (perm) {
531
+ var user = perm.target.id && !perm.target.displayName
532
+ ? contacts.contacts.find(function (cur) { return cur.id === perm.target.id; })
533
+ : undefined;
534
+ var displayName = perm.target.displayName || "".concat(user === null || user === void 0 ? void 0 : user.firstName, " ").concat(user === null || user === void 0 ? void 0 : user.lastName);
535
+ return _tslib.__assign(_tslib.__assign({}, perm), { target: _tslib.__assign(_tslib.__assign({}, perm.target), { id: perm.target.id, displayName: displayName }) });
536
+ }),
537
+ }];
310
538
  }
311
539
  });
312
540
  });
313
541
  };
314
542
  Api.prototype.addPermissions = function (subjectType, subjectId, permissions) {
315
543
  return _tslib.__awaiter(this, void 0, void 0, function () {
544
+ var body, email, contacts, result;
316
545
  return _tslib.__generator(this, function (_a) {
317
546
  switch (_a.label) {
318
- case 0: return [4 /*yield*/, this.post("/".concat(subjectType, "/").concat(subjectId, "/permissions"), permissions)];
319
- case 1: return [2 /*return*/, _a.sent()];
547
+ case 0:
548
+ body = _tslib.__assign({}, permissions);
549
+ email = permissions.target.email;
550
+ if (!email) return [3 /*break*/, 2];
551
+ return [4 /*yield*/, this.findContacts({
552
+ email: email,
553
+ })];
554
+ case 1:
555
+ contacts = _a.sent();
556
+ if (!contacts.contacts.length) {
557
+ throw new ApiError.ApiError({
558
+ error: 'CollaboratorNotFound',
559
+ message: 'This user does not exist',
560
+ details: { email: email },
561
+ }, 404);
562
+ }
563
+ body.target = { id: contacts.contacts[0].id };
564
+ _a.label = 2;
565
+ case 2: return [4 /*yield*/, this.post("/".concat(subjectType, "/").concat(subjectId, "/permissions"), body)];
566
+ case 3:
567
+ result = _a.sent();
568
+ return [2 /*return*/, _tslib.__assign(_tslib.__assign({}, result), { target: _tslib.__assign(_tslib.__assign({}, result.target), { id: result.target.id, email: email }) })];
320
569
  }
321
570
  });
322
571
  });
323
572
  };
324
- Api.prototype.deletePermissions = function (subjectType, subjectId, userEmail) {
573
+ Api.prototype.deletePermissions = function (subjectType, subjectId, id) {
325
574
  return _tslib.__awaiter(this, void 0, void 0, function () {
326
575
  return _tslib.__generator(this, function (_a) {
327
576
  switch (_a.label) {
328
- case 0: return [4 /*yield*/, this.delete("/".concat(subjectType, "/").concat(subjectId, "/permissions/").concat(userEmail))];
577
+ case 0: return [4 /*yield*/, this.delete("/".concat(subjectType, "/").concat(subjectId, "/permissions/").concat(id))];
329
578
  case 1: return [2 /*return*/, _a.sent()];
330
579
  }
331
580
  });
@@ -339,7 +588,7 @@ var Api = /** @class */ (function (_super) {
339
588
  switch (_b.label) {
340
589
  case 0:
341
590
  params = new URLSearchParams(utils.removedUndefinedProperties({
342
- text: "".concat(query || ''),
591
+ text: "".concat(encodeURIComponent(query || '')),
343
592
  page: "".concat(page || ''),
344
593
  limit: "".concat(limit || ''),
345
594
  workspaceId: "".concat(workspaceId || ''),
@@ -400,16 +649,6 @@ var Api = /** @class */ (function (_super) {
400
649
  });
401
650
  });
402
651
  };
403
- Api.prototype.fetchImports = function (workspaceId) {
404
- return _tslib.__awaiter(this, void 0, void 0, function () {
405
- return _tslib.__generator(this, function (_a) {
406
- switch (_a.label) {
407
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/apps"))];
408
- case 1: return [2 /*return*/, _a.sent()];
409
- }
410
- });
411
- });
412
- };
413
652
  Api.prototype.getAppConfig = function (workspaceId, slug) {
414
653
  return _tslib.__awaiter(this, void 0, void 0, function () {
415
654
  var config;
@@ -435,6 +674,26 @@ var Api = /** @class */ (function (_super) {
435
674
  });
436
675
  });
437
676
  };
677
+ Api.prototype.getAppInstance = function (workspaceId, slug) {
678
+ return _tslib.__awaiter(this, void 0, void 0, function () {
679
+ return _tslib.__generator(this, function (_a) {
680
+ return [2 /*return*/, this.get("/workspaces/".concat(workspaceId, "/apps/").concat(slug))];
681
+ });
682
+ });
683
+ };
684
+ Api.prototype.saveAppInstance = function (workspaceId, slug, appInstance) {
685
+ return _tslib.__awaiter(this, void 0, void 0, function () {
686
+ var response;
687
+ return _tslib.__generator(this, function (_a) {
688
+ switch (_a.label) {
689
+ case 0: return [4 /*yield*/, this.patch("/workspaces/".concat(workspaceId, "/apps/").concat(slug), _tslib.__assign({}, appInstance))];
690
+ case 1:
691
+ response = _a.sent();
692
+ return [2 /*return*/, response];
693
+ }
694
+ });
695
+ });
696
+ };
438
697
  Api.prototype.uploadFiles = function (files, workspaceId) {
439
698
  return _tslib.__awaiter(this, void 0, void 0, function () {
440
699
  function dataURItoBlob(dataURI) {
@@ -471,7 +730,10 @@ var Api = /** @class */ (function (_super) {
471
730
  case 0:
472
731
  formData = new FormData();
473
732
  (Array.isArray(files) ? files : [files]).forEach(function (file) {
474
- formData.append.apply(formData, _tslib.__spreadArray(['file'], dataURItoBlob(file)));
733
+ try {
734
+ formData.append.apply(formData, _tslib.__spreadArray(['file'], dataURItoBlob(file), false));
735
+ }
736
+ catch (_a) { }
475
737
  });
476
738
  _a.label = 1;
477
739
  case 1:
@@ -538,13 +800,30 @@ var Api = /** @class */ (function (_super) {
538
800
  });
539
801
  });
540
802
  };
541
- Api.prototype.callAutomation = function (workspaceId, automation) {
803
+ Api.prototype.callAutomation = function (workspaceId, automation, params) {
542
804
  return _tslib.__awaiter(this, void 0, void 0, function () {
543
805
  return _tslib.__generator(this, function (_a) {
544
- return [2 /*return*/, this._fetch("/workspaces/".concat(workspaceId, "/webhooks/").concat(automation))];
806
+ return [2 /*return*/, this.post("/workspaces/".concat(workspaceId, "/webhooks/").concat(automation), params)];
807
+ });
808
+ });
809
+ };
810
+ Api.prototype.getWorkspaceUsage = function (workspaceId, _a) {
811
+ var _b = _a === void 0 ? {} : _a, afterDate = _b.afterDate, beforeDate = _b.beforeDate, details = _b.details;
812
+ return _tslib.__awaiter(this, void 0, void 0, function () {
813
+ var params;
814
+ return _tslib.__generator(this, function (_c) {
815
+ params = new URLSearchParams(utils.removedUndefinedProperties({
816
+ afterDate: "".concat(afterDate || ''),
817
+ beforeDate: "".concat(beforeDate || ''),
818
+ details: "".concat(details || ''),
819
+ }, true));
820
+ return [2 /*return*/, this.get("/workspaces/".concat(workspaceId, "/usage?").concat(params.toString()))];
545
821
  });
546
822
  });
547
823
  };
824
+ Api.prototype.workspaces = function (id) {
825
+ return new workspaces.WorkspacesEndpoint(id, this);
826
+ };
548
827
  return Api;
549
828
  }(fetcher.Fetcher));
550
829
  var api = new Api('https://api.eda.prisme.ai');
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var workspacesVersions = require('./workspacesVersions.js');
6
+
7
+ var WorkspacesEndpoint = /** @class */ (function () {
8
+ function WorkspacesEndpoint(id, api) {
9
+ this.id = id;
10
+ this.api = api;
11
+ }
12
+ Object.defineProperty(WorkspacesEndpoint.prototype, "versions", {
13
+ get: function () {
14
+ return new workspacesVersions.WorkspacesVersionsEndpoint(this.id, this.api);
15
+ },
16
+ enumerable: false,
17
+ configurable: true
18
+ });
19
+ return WorkspacesEndpoint;
20
+ }());
21
+
22
+ exports.WorkspacesEndpoint = WorkspacesEndpoint;
23
+ exports["default"] = WorkspacesEndpoint;
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../../_virtual/_tslib.js');
6
+
7
+ var WorkspacesVersionsEndpoint = /** @class */ (function () {
8
+ function WorkspacesVersionsEndpoint(workspaceId, api) {
9
+ this.workspaceId = workspaceId;
10
+ this.api = api;
11
+ }
12
+ WorkspacesVersionsEndpoint.prototype.create = function (version) {
13
+ this.api.post("/workspaces/".concat(this.workspaceId, "/versions"), version);
14
+ };
15
+ WorkspacesVersionsEndpoint.prototype.rollback = function (versionId) {
16
+ this.api.post("/workspaces/".concat(this.workspaceId, "/versions/").concat(versionId, "/rollback"));
17
+ };
18
+ WorkspacesVersionsEndpoint.prototype.export = function (version) {
19
+ if (version === void 0) { version = 'current'; }
20
+ return _tslib.__awaiter(this, void 0, void 0, function () {
21
+ var res, _a;
22
+ return _tslib.__generator(this, function (_b) {
23
+ switch (_b.label) {
24
+ case 0: return [4 /*yield*/, this.api.prepareRequest("/workspaces/".concat(this.workspaceId, "/versions/").concat(version, "/export"), {
25
+ method: 'post'
26
+ })];
27
+ case 1:
28
+ res = _b.sent();
29
+ _a = Blob.bind;
30
+ return [4 /*yield*/, res.arrayBuffer()];
31
+ case 2: return [2 /*return*/, new (_a.apply(Blob, [void 0, [_b.sent()], { type: 'application/zip' }]))()];
32
+ }
33
+ });
34
+ });
35
+ };
36
+ return WorkspacesVersionsEndpoint;
37
+ }());
38
+
39
+ exports.WorkspacesVersionsEndpoint = WorkspacesVersionsEndpoint;
40
+ exports["default"] = WorkspacesVersionsEndpoint;