@prisme.ai/sdk 1.0.2 → 2.0.1

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 (66) hide show
  1. package/README.md +250 -0
  2. package/dist/index.d.mts +1129 -0
  3. package/dist/index.d.ts +1129 -7
  4. package/dist/index.js +1326 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +1287 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +50 -12
  9. package/Readme.md +0 -28
  10. package/dist/_virtual/_tslib.js +0 -116
  11. package/dist/lib/ApiError.d.ts +0 -8
  12. package/dist/lib/ApiError.test.d.ts +0 -1
  13. package/dist/lib/HTTPError.d.ts +0 -6
  14. package/dist/lib/HTTPError.test.d.ts +0 -1
  15. package/dist/lib/ImportProcessing.d.ts +0 -19
  16. package/dist/lib/WorkspacesEndpoint.d.ts +0 -10
  17. package/dist/lib/api.d.ts +0 -155
  18. package/dist/lib/api.test.d.ts +0 -1
  19. package/dist/lib/endpoints/users.d.ts +0 -13
  20. package/dist/lib/endpoints/workspaces.d.ts +0 -25
  21. package/dist/lib/endpoints/workspacesVersions.d.ts +0 -10
  22. package/dist/lib/events.d.ts +0 -40
  23. package/dist/lib/events.test.d.ts +0 -1
  24. package/dist/lib/fetch.d.ts +0 -2
  25. package/dist/lib/fetcher.d.ts +0 -24
  26. package/dist/lib/fetcher.test.d.ts +0 -1
  27. package/dist/lib/interpolate.d.ts +0 -2
  28. package/dist/lib/interpolate.test.d.ts +0 -1
  29. package/dist/lib/interpolateVars.d.ts +0 -2
  30. package/dist/lib/types.d.ts +0 -17
  31. package/dist/lib/utils.d.ts +0 -4
  32. package/dist/lib/utils.test.d.ts +0 -1
  33. package/dist/sdk/index.js +0 -19
  34. package/dist/sdk/lib/ApiError.js +0 -24
  35. package/dist/sdk/lib/HTTPError.js +0 -21
  36. package/dist/sdk/lib/ImportProcessing.js +0 -17
  37. package/dist/sdk/lib/WorkspacesEndpoint.js +0 -19
  38. package/dist/sdk/lib/api.js +0 -1018
  39. package/dist/sdk/lib/endpoints/users.js +0 -94
  40. package/dist/sdk/lib/endpoints/workspaces.js +0 -144
  41. package/dist/sdk/lib/endpoints/workspacesVersions.js +0 -40
  42. package/dist/sdk/lib/events.js +0 -169
  43. package/dist/sdk/lib/fetch.js +0 -12
  44. package/dist/sdk/lib/fetcher.js +0 -213
  45. package/dist/sdk/lib/interpolate.js +0 -26
  46. package/dist/sdk/lib/interpolateVars.js +0 -26
  47. package/dist/sdk/lib/utils.js +0 -65
  48. package/index.ts +0 -7
  49. package/lib/ApiError.test.ts +0 -13
  50. package/lib/ApiError.ts +0 -21
  51. package/lib/HTTPError.test.ts +0 -8
  52. package/lib/HTTPError.ts +0 -13
  53. package/lib/ImportProcessing.ts +0 -22
  54. package/lib/api.test.ts +0 -787
  55. package/lib/api.ts +0 -949
  56. package/lib/endpoints/users.ts +0 -58
  57. package/lib/endpoints/workspaces.ts +0 -121
  58. package/lib/endpoints/workspacesVersions.ts +0 -38
  59. package/lib/events.test.ts +0 -89
  60. package/lib/events.ts +0 -222
  61. package/lib/fetcher.test.ts +0 -246
  62. package/lib/fetcher.ts +0 -198
  63. package/lib/types.ts +0 -21
  64. package/lib/utils.test.ts +0 -38
  65. package/lib/utils.ts +0 -51
  66. package/tsconfig.json +0 -21
@@ -1,1018 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('../../_virtual/_tslib.js');
6
- var QueryString = require('qs');
7
- var pkceChallenge = require('pkce-challenge');
8
- var fetcher = require('./fetcher.js');
9
- var events = require('./events.js');
10
- var utils = require('./utils.js');
11
- var workspaces = require('./endpoints/workspaces.js');
12
- var ApiError = require('./ApiError.js');
13
- var users = require('./endpoints/users.js');
14
- var ImportProcessing = require('./ImportProcessing.js');
15
-
16
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
-
18
- var QueryString__default = /*#__PURE__*/_interopDefaultLegacy(QueryString);
19
- var pkceChallenge__default = /*#__PURE__*/_interopDefaultLegacy(pkceChallenge);
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
- }
49
- var Api = /** @class */ (function (_super) {
50
- _tslib.__extends(Api, _super);
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;
57
- }
58
- Object.defineProperty(Api.prototype, "user", {
59
- get: function () {
60
- return this._user;
61
- },
62
- enumerable: false,
63
- configurable: true
64
- });
65
- Api.prototype.me = function () {
66
- return _tslib.__awaiter(this, void 0, void 0, function () {
67
- var me;
68
- return _tslib.__generator(this, function (_a) {
69
- switch (_a.label) {
70
- case 0: return [4 /*yield*/, this.get('/me')];
71
- case 1:
72
- me = _a.sent();
73
- this.sessionId = me.sessionId;
74
- this._user = me;
75
- return [2 /*return*/, me];
76
- }
77
- });
78
- });
79
- };
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; }
89
- return _tslib.__awaiter(this, void 0, void 0, function () {
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;
125
- return _tslib.__generator(this, function (_a) {
126
- switch (_a.label) {
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
- })];
133
- case 1:
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];
160
- }
161
- });
162
- });
163
- };
164
- Api.prototype.createAnonymousSession = function () {
165
- return _tslib.__awaiter(this, void 0, void 0, function () {
166
- var user;
167
- return _tslib.__generator(this, function (_a) {
168
- switch (_a.label) {
169
- case 0: return [4 /*yield*/, this.post('/login/anonymous')];
170
- case 1:
171
- user = _a.sent();
172
- this._user = user;
173
- return [2 /*return*/, user];
174
- }
175
- });
176
- });
177
- };
178
- Api.prototype.signup = function (email, password, firstName, lastName, language) {
179
- return _tslib.__awaiter(this, void 0, void 0, function () {
180
- return _tslib.__generator(this, function (_a) {
181
- switch (_a.label) {
182
- case 0: return [4 /*yield*/, this.post('/signup', {
183
- email: email,
184
- password: password,
185
- firstName: firstName,
186
- lastName: lastName,
187
- language: language,
188
- }, {
189
- credentials: 'omit',
190
- })];
191
- case 1: return [2 /*return*/, _a.sent()];
192
- }
193
- });
194
- });
195
- };
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();
204
- };
205
- // Mail validation
206
- Api.prototype.sendValidationMail = function (email, language) {
207
- return _tslib.__awaiter(this, void 0, void 0, function () {
208
- return _tslib.__generator(this, function (_a) {
209
- switch (_a.label) {
210
- case 0: return [4 /*yield*/, this.post('/user/validate', { email: email, language: language })];
211
- case 1: return [2 /*return*/, _a.sent()];
212
- }
213
- });
214
- });
215
- };
216
- Api.prototype.validateMail = function (token) {
217
- return _tslib.__awaiter(this, void 0, void 0, function () {
218
- return _tslib.__generator(this, function (_a) {
219
- switch (_a.label) {
220
- case 0: return [4 /*yield*/, this.post('/user/validate', { token: token })];
221
- case 1: return [2 /*return*/, _a.sent()];
222
- }
223
- });
224
- });
225
- };
226
- // Password reset
227
- Api.prototype.sendPasswordResetMail = function (email, language) {
228
- return _tslib.__awaiter(this, void 0, void 0, function () {
229
- return _tslib.__generator(this, function (_a) {
230
- switch (_a.label) {
231
- case 0: return [4 /*yield*/, this.post('/user/password', { email: email, language: language })];
232
- case 1: return [2 /*return*/, _a.sent()];
233
- }
234
- });
235
- });
236
- };
237
- Api.prototype.passwordReset = function (token, password) {
238
- return _tslib.__awaiter(this, void 0, void 0, function () {
239
- return _tslib.__generator(this, function (_a) {
240
- switch (_a.label) {
241
- case 0: return [4 /*yield*/, this.post('/user/password', { token: token, password: password })];
242
- case 1: return [2 /*return*/, _a.sent()];
243
- }
244
- });
245
- });
246
- };
247
- // Workspaces
248
- Api.prototype.getWorkspaces = function () {
249
- return _tslib.__awaiter(this, void 0, void 0, function () {
250
- return _tslib.__generator(this, function (_a) {
251
- switch (_a.label) {
252
- case 0: return [4 /*yield*/, this.get('/workspaces?limit=2000')];
253
- case 1: return [2 /*return*/, _a.sent()];
254
- }
255
- });
256
- });
257
- };
258
- Api.prototype.getWorkspace = function (id) {
259
- return _tslib.__awaiter(this, void 0, void 0, function () {
260
- return _tslib.__generator(this, function (_a) {
261
- switch (_a.label) {
262
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(id))];
263
- case 1: return [2 /*return*/, _a.sent()];
264
- }
265
- });
266
- });
267
- };
268
- Api.prototype.getWorkspaceSecurity = function (id) {
269
- return _tslib.__awaiter(this, void 0, void 0, function () {
270
- return _tslib.__generator(this, function (_a) {
271
- switch (_a.label) {
272
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(id, "/security"))];
273
- case 1: return [2 /*return*/, _a.sent()];
274
- }
275
- });
276
- });
277
- };
278
- Api.prototype.updateWorkspaceSecurity = function (workspaceId, security) {
279
- return _tslib.__awaiter(this, void 0, void 0, function () {
280
- return _tslib.__generator(this, function (_a) {
281
- switch (_a.label) {
282
- case 0: return [4 /*yield*/, this.put("/workspaces/".concat(workspaceId, "/security"), security)];
283
- case 1: return [2 /*return*/, _a.sent()];
284
- }
285
- });
286
- });
287
- };
288
- Api.prototype.getWorkspaceRoles = function (id) {
289
- return _tslib.__awaiter(this, void 0, void 0, function () {
290
- return _tslib.__generator(this, function (_a) {
291
- switch (_a.label) {
292
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(id, "/security/roles"))];
293
- case 1: return [2 /*return*/, _a.sent()];
294
- }
295
- });
296
- });
297
- };
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) {
329
- return _tslib.__awaiter(this, void 0, void 0, function () {
330
- return _tslib.__generator(this, function (_a) {
331
- switch (_a.label) {
332
- case 0: return [4 /*yield*/, this.post('/workspaces', newWorkspace)];
333
- case 1: return [2 /*return*/, _a.sent()];
334
- }
335
- });
336
- });
337
- };
338
- Api.prototype.duplicateWorkspace = function (_a) {
339
- var id = _a.id;
340
- return _tslib.__awaiter(this, void 0, void 0, function () {
341
- return _tslib.__generator(this, function (_b) {
342
- switch (_b.label) {
343
- case 0: return [4 /*yield*/, this.post("/workspaces/".concat(id, "/versions/current/duplicate"), {})];
344
- case 1: return [2 /*return*/, _b.sent()];
345
- }
346
- });
347
- });
348
- };
349
- // @deprecated. Use api.workspaces(id).update() instead
350
- Api.prototype.updateWorkspace = function (workspace) {
351
- return _tslib.__awaiter(this, void 0, void 0, function () {
352
- var _a, _b;
353
- return _tslib.__generator(this, function (_c) {
354
- switch (_c.label) {
355
- case 0:
356
- if (!workspace.id)
357
- return [2 /*return*/, null];
358
- _a = this.patch;
359
- _b = ["/workspaces/".concat(workspace.id)];
360
- return [4 /*yield*/, this.replaceAllImagesData(workspace, workspace.id)];
361
- case 1: return [4 /*yield*/, _a.apply(this, _b.concat([_c.sent()]))];
362
- case 2: return [2 /*return*/, _c.sent()];
363
- }
364
- });
365
- });
366
- };
367
- // @deprecated. Use api.workspaces(id).delete() instead
368
- Api.prototype.deleteWorkspace = function (workspaceId) {
369
- return _tslib.__awaiter(this, void 0, void 0, function () {
370
- return _tslib.__generator(this, function (_a) {
371
- switch (_a.label) {
372
- case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId))];
373
- case 1: return [2 /*return*/, _a.sent()];
374
- }
375
- });
376
- });
377
- };
378
- Api.prototype.generateApiKey = function (workspaceId, events, uploads) {
379
- return _tslib.__awaiter(this, void 0, void 0, function () {
380
- var apiKey;
381
- return _tslib.__generator(this, function (_a) {
382
- switch (_a.label) {
383
- case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/apiKeys"), {
384
- rules: {
385
- events: {
386
- types: events,
387
- filters: {
388
- 'source.sessionId': '${user.sessionId}',
389
- },
390
- },
391
- uploads: uploads
392
- ? {
393
- mimetypes: uploads,
394
- }
395
- : undefined,
396
- },
397
- })];
398
- case 1:
399
- apiKey = (_a.sent()).apiKey;
400
- return [2 /*return*/, apiKey];
401
- }
402
- });
403
- });
404
- };
405
- Api.prototype.updateApiKey = function (workspaceId, apiKey, events, uploads) {
406
- return _tslib.__awaiter(this, void 0, void 0, function () {
407
- return _tslib.__generator(this, function (_a) {
408
- switch (_a.label) {
409
- case 0: return [4 /*yield*/, this.put("/workspaces/".concat(workspaceId, "/apiKeys/").concat(apiKey), {
410
- rules: {
411
- events: {
412
- types: events,
413
- filters: {
414
- 'source.sessionId': '${user.sessionId}',
415
- },
416
- },
417
- uploads: uploads
418
- ? {
419
- mimetypes: uploads,
420
- }
421
- : undefined,
422
- },
423
- })];
424
- case 1:
425
- _a.sent();
426
- return [2 /*return*/, apiKey];
427
- }
428
- });
429
- });
430
- };
431
- // Automations
432
- Api.prototype.getAutomation = function (workspaceId, automationSlug) {
433
- return _tslib.__awaiter(this, void 0, void 0, function () {
434
- return _tslib.__generator(this, function (_a) {
435
- switch (_a.label) {
436
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/automations/").concat(encodeURIComponent(automationSlug)))];
437
- case 1: return [2 /*return*/, _a.sent()];
438
- }
439
- });
440
- });
441
- };
442
- Api.prototype.createAutomation = function (workspaceId, automation) {
443
- return _tslib.__awaiter(this, void 0, void 0, function () {
444
- return _tslib.__generator(this, function (_a) {
445
- switch (_a.label) {
446
- case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/automations"), _tslib.__assign({}, automation))];
447
- case 1: return [2 /*return*/, _a.sent()];
448
- }
449
- });
450
- });
451
- };
452
- Api.prototype.updateAutomation = function (workspaceId, slug, automation) {
453
- return _tslib.__awaiter(this, void 0, void 0, function () {
454
- var _a, _b;
455
- return _tslib.__generator(this, function (_c) {
456
- switch (_c.label) {
457
- case 0:
458
- _a = this.patch;
459
- _b = ["/workspaces/".concat(workspaceId, "/automations/").concat(encodeURIComponent(slug))];
460
- return [4 /*yield*/, this.replaceAllImagesData(automation, workspaceId)];
461
- case 1: return [4 /*yield*/, _a.apply(this, _b.concat([_c.sent()]))];
462
- case 2: return [2 /*return*/, _c.sent()];
463
- }
464
- });
465
- });
466
- };
467
- Api.prototype.deleteAutomation = function (workspaceId, slug) {
468
- return _tslib.__awaiter(this, void 0, void 0, function () {
469
- return _tslib.__generator(this, function (_a) {
470
- switch (_a.label) {
471
- case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/automations/").concat(encodeURIComponent(slug)))];
472
- case 1: return [2 /*return*/, _a.sent()];
473
- }
474
- });
475
- });
476
- };
477
- // Pages
478
- Api.prototype.getPages = function (workspaceId) {
479
- return _tslib.__awaiter(this, void 0, void 0, function () {
480
- var pages;
481
- return _tslib.__generator(this, function (_a) {
482
- switch (_a.label) {
483
- case 0:
484
- _a.trys.push([0, 2, , 3]);
485
- return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/pages"))];
486
- case 1:
487
- pages = _a.sent();
488
- return [2 /*return*/, pages.map(function (_a) {
489
- _a.createdAt; _a.createdBy; _a.updatedAt; _a.updatedBy; var page = _tslib.__rest(_a, ["createdAt", "createdBy", "updatedAt", "updatedBy"]);
490
- return page;
491
- })];
492
- case 2:
493
- _a.sent();
494
- return [2 /*return*/, []];
495
- case 3: return [2 /*return*/];
496
- }
497
- });
498
- });
499
- };
500
- Api.prototype.getPage = function (workspaceId, pageSlug) {
501
- return _tslib.__awaiter(this, void 0, void 0, function () {
502
- return _tslib.__generator(this, function (_a) {
503
- switch (_a.label) {
504
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/pages/").concat(encodeURIComponent(pageSlug)))];
505
- case 1: return [2 /*return*/, _a.sent()];
506
- }
507
- });
508
- });
509
- };
510
- Api.prototype.getPageBySlug = function (workspaceSlug, pageSlug) {
511
- return _tslib.__awaiter(this, void 0, void 0, function () {
512
- return _tslib.__generator(this, function (_a) {
513
- switch (_a.label) {
514
- case 0: return [4 /*yield*/, this.get("/pages/".concat(workspaceSlug, "/").concat(encodeURIComponent(pageSlug)))];
515
- case 1: return [2 /*return*/, _a.sent()];
516
- }
517
- });
518
- });
519
- };
520
- Api.prototype.createPage = function (workspaceId, page) {
521
- return _tslib.__awaiter(this, void 0, void 0, function () {
522
- var _a, newPage;
523
- return _tslib.__generator(this, function (_b) {
524
- switch (_b.label) {
525
- case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/pages"), page)];
526
- case 1:
527
- _a = _b.sent(), newPage = _tslib.__rest(_a, ["createdAt", "createdBy", "updatedAt", "updatedBy"]);
528
- return [2 /*return*/, newPage];
529
- }
530
- });
531
- });
532
- };
533
- Api.prototype.updatePage = function (workspaceId, page, prevSlug) {
534
- if (prevSlug === void 0) { prevSlug = page.slug || ''; }
535
- return _tslib.__awaiter(this, void 0, void 0, function () {
536
- var _a, updatedPage, _b, _c;
537
- return _tslib.__generator(this, function (_d) {
538
- switch (_d.label) {
539
- case 0:
540
- _b = this.patch;
541
- _c = ["/workspaces/".concat(workspaceId, "/pages/").concat(encodeURIComponent(prevSlug))];
542
- // Replace images as dataurl to uploaded url in any type of data
543
- return [4 /*yield*/, this.replaceAllImagesData(page, workspaceId)];
544
- case 1: return [4 /*yield*/, _b.apply(this, _c.concat([
545
- // Replace images as dataurl to uploaded url in any type of data
546
- _d.sent()]))];
547
- case 2:
548
- _a = _d.sent(), updatedPage = _tslib.__rest(_a, ["createdAt", "createdBy", "updatedAt", "updatedBy"]);
549
- return [2 /*return*/, updatedPage];
550
- }
551
- });
552
- });
553
- };
554
- Api.prototype.deletePage = function (workspaceId, pageSlug) {
555
- return _tslib.__awaiter(this, void 0, void 0, function () {
556
- return _tslib.__generator(this, function (_a) {
557
- switch (_a.label) {
558
- case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/pages/").concat(encodeURIComponent(pageSlug)))];
559
- case 1: return [2 /*return*/, _a.sent()];
560
- }
561
- });
562
- });
563
- };
564
- // Events
565
- Api.prototype.streamEvents = function (workspaceId, filters) {
566
- var _a, _b;
567
- if (filters && filters['source.sessionId'] === true) {
568
- if (this.sessionId) {
569
- filters['source.sessionId'] = this.sessionId;
570
- filters['target.userTopic'] = ''; // We do not want to receive userTopics emitted by ourself for this session listener
571
- }
572
- else {
573
- delete filters['source.sessionId'];
574
- }
575
- }
576
- var events$1 = new events.Events({
577
- workspaceId: workspaceId,
578
- token: this.token || '',
579
- legacyToken: this.legacyToken || '',
580
- apiKey: this._apiKey ? this._apiKey : undefined,
581
- apiHost: this.host,
582
- filters: filters,
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,
585
- });
586
- return new Promise(function (resolve, reject) {
587
- var off = events$1.once('connect_error', function () {
588
- reject();
589
- events$1.close();
590
- });
591
- events$1.once('connect', function () {
592
- off();
593
- resolve(events$1);
594
- });
595
- });
596
- };
597
- Api.prototype.getEvents = function (workspaceId, options) {
598
- if (options === void 0) { options = {}; }
599
- return _tslib.__awaiter(this, void 0, void 0, function () {
600
- var query, events;
601
- return _tslib.__generator(this, function (_a) {
602
- switch (_a.label) {
603
- case 0:
604
- _a.trys.push([0, 2, , 3]);
605
- query = QueryString__default["default"].stringify(options);
606
- return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/events").concat(query && "?".concat(query)))];
607
- case 1:
608
- events = (_a.sent()).result.events;
609
- return [2 /*return*/, events.map(function (_a) {
610
- var createdAt = _a.createdAt, event = _tslib.__rest(_a, ["createdAt"]);
611
- return (_tslib.__assign(_tslib.__assign({}, event), { createdAt: new Date(createdAt) }));
612
- })];
613
- case 2:
614
- _a.sent();
615
- return [2 /*return*/, []];
616
- case 3: return [2 /*return*/];
617
- }
618
- });
619
- });
620
- };
621
- Api.prototype.postEvents = function (workspaceId, events) {
622
- return _tslib.__awaiter(this, void 0, void 0, function () {
623
- return _tslib.__generator(this, function (_a) {
624
- switch (_a.label) {
625
- case 0:
626
- _a.trys.push([0, 2, , 3]);
627
- return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/events"), {
628
- events: events,
629
- })];
630
- case 1:
631
- _a.sent();
632
- return [2 /*return*/, true];
633
- case 2:
634
- _a.sent();
635
- return [2 /*return*/, false];
636
- case 3: return [2 /*return*/];
637
- }
638
- });
639
- });
640
- };
641
- Api.prototype.findContacts = function (query) {
642
- return _tslib.__awaiter(this, void 0, void 0, function () {
643
- return _tslib.__generator(this, function (_a) {
644
- switch (_a.label) {
645
- case 0: return [4 /*yield*/, this.post("/contacts", query)];
646
- case 1: return [2 /*return*/, _a.sent()];
647
- }
648
- });
649
- });
650
- };
651
- Api.prototype.getPermissions = function (subjectType, subjectId) {
652
- return _tslib.__awaiter(this, void 0, void 0, function () {
653
- var permissions, contacts;
654
- return _tslib.__generator(this, function (_a) {
655
- switch (_a.label) {
656
- case 0: return [4 /*yield*/, this.get("/".concat(subjectType, "/").concat(subjectId, "/permissions"))];
657
- case 1:
658
- permissions = _a.sent();
659
- return [4 /*yield*/, this.findContacts({
660
- ids: permissions.result
661
- .filter(function (cur) { return cur.target.id && !cur.target.displayName; })
662
- .map(function (cur) { return cur.target.id; }),
663
- })];
664
- case 2:
665
- contacts = _a.sent();
666
- return [2 /*return*/, {
667
- result: permissions.result.map(function (perm) {
668
- var user = perm.target.id && !perm.target.displayName
669
- ? contacts.contacts.find(function (cur) { return cur.id === perm.target.id; })
670
- : undefined;
671
- 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);
672
- return _tslib.__assign(_tslib.__assign({}, perm), { target: _tslib.__assign(_tslib.__assign({}, perm.target), { id: perm.target.id, displayName: displayName }) });
673
- }),
674
- }];
675
- }
676
- });
677
- });
678
- };
679
- Api.prototype.addPermissions = function (subjectType, subjectId, permissions) {
680
- return _tslib.__awaiter(this, void 0, void 0, function () {
681
- var body, email, contacts, result;
682
- return _tslib.__generator(this, function (_a) {
683
- switch (_a.label) {
684
- case 0:
685
- body = _tslib.__assign({}, permissions);
686
- email = permissions.target.email;
687
- if (!email) return [3 /*break*/, 2];
688
- return [4 /*yield*/, this.findContacts({
689
- email: email,
690
- })];
691
- case 1:
692
- contacts = _a.sent();
693
- if (!contacts.contacts.length) {
694
- throw new ApiError.ApiError({
695
- error: 'CollaboratorNotFound',
696
- message: 'This user does not exist',
697
- }, 404);
698
- }
699
- body.target = { id: contacts.contacts[0].id };
700
- _a.label = 2;
701
- case 2: return [4 /*yield*/, this.post("/".concat(subjectType, "/").concat(subjectId, "/permissions"), body)];
702
- case 3:
703
- result = _a.sent();
704
- return [2 /*return*/, _tslib.__assign(_tslib.__assign({}, result), { target: _tslib.__assign(_tslib.__assign({}, result.target), { id: result.target.id, email: email }) })];
705
- }
706
- });
707
- });
708
- };
709
- Api.prototype.deletePermissions = function (subjectType, subjectId, id) {
710
- return _tslib.__awaiter(this, void 0, void 0, function () {
711
- return _tslib.__generator(this, function (_a) {
712
- switch (_a.label) {
713
- case 0: return [4 /*yield*/, this.delete("/".concat(subjectType, "/").concat(subjectId, "/permissions/").concat(id))];
714
- case 1: return [2 /*return*/, _a.sent()];
715
- }
716
- });
717
- });
718
- };
719
- Api.prototype.getApps = function (_a) {
720
- var query = _a.query, page = _a.page, limit = _a.limit, workspaceId = _a.workspaceId;
721
- return _tslib.__awaiter(this, void 0, void 0, function () {
722
- var params;
723
- return _tslib.__generator(this, function (_b) {
724
- switch (_b.label) {
725
- case 0:
726
- params = new URLSearchParams(utils.removedUndefinedProperties({
727
- text: "".concat(encodeURIComponent(query || '')),
728
- page: "".concat(page || ''),
729
- limit: "".concat(limit || ''),
730
- workspaceId: "".concat(workspaceId || ''),
731
- }, true));
732
- return [4 /*yield*/, this.get("/apps?".concat(params.toString()))];
733
- case 1: return [2 /*return*/, _b.sent()];
734
- }
735
- });
736
- });
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
- };
749
- Api.prototype.installApp = function (workspaceId, body) {
750
- return _tslib.__awaiter(this, void 0, void 0, function () {
751
- return _tslib.__generator(this, function (_a) {
752
- switch (_a.label) {
753
- case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/apps"), body)];
754
- case 1: return [2 /*return*/, _a.sent()];
755
- }
756
- });
757
- });
758
- };
759
- Api.prototype.updateApp = function (workspaceId, slug, body) {
760
- return _tslib.__awaiter(this, void 0, void 0, function () {
761
- return _tslib.__generator(this, function (_a) {
762
- switch (_a.label) {
763
- case 0: return [4 /*yield*/, this.patch("/workspaces/".concat(workspaceId, "/apps/").concat(slug), body)];
764
- case 1: return [2 /*return*/, _a.sent()];
765
- }
766
- });
767
- });
768
- };
769
- Api.prototype.uninstallApp = function (workspaceId, slug) {
770
- return _tslib.__awaiter(this, void 0, void 0, function () {
771
- return _tslib.__generator(this, function (_a) {
772
- switch (_a.label) {
773
- case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/apps/").concat(slug))];
774
- case 1: return [2 /*return*/, _a.sent()];
775
- }
776
- });
777
- });
778
- };
779
- Api.prototype.publishApp = function (body) {
780
- return _tslib.__awaiter(this, void 0, void 0, function () {
781
- return _tslib.__generator(this, function (_a) {
782
- switch (_a.label) {
783
- case 0: return [4 /*yield*/, this.post("/apps", body)];
784
- case 1: return [2 /*return*/, _a.sent()];
785
- }
786
- });
787
- });
788
- };
789
- // @deprecated. Use api.workspaces(id).listAppInstances())
790
- Api.prototype.listAppInstances = function (workspaceId) {
791
- return _tslib.__awaiter(this, void 0, void 0, function () {
792
- return _tslib.__generator(this, function (_a) {
793
- switch (_a.label) {
794
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/apps"))];
795
- case 1: return [2 /*return*/, _a.sent()];
796
- }
797
- });
798
- });
799
- };
800
- Api.prototype.getAppConfig = function (workspaceId, slug) {
801
- return _tslib.__awaiter(this, void 0, void 0, function () {
802
- var config;
803
- return _tslib.__generator(this, function (_a) {
804
- switch (_a.label) {
805
- case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/apps/").concat(slug, "/config"))];
806
- case 1:
807
- config = _a.sent();
808
- return [2 /*return*/, config];
809
- }
810
- });
811
- });
812
- };
813
- Api.prototype.updateAppConfig = function (workspaceId, slug, config) {
814
- return _tslib.__awaiter(this, void 0, void 0, function () {
815
- return _tslib.__generator(this, function (_a) {
816
- switch (_a.label) {
817
- case 0: return [4 /*yield*/, this.patch("/workspaces/".concat(workspaceId, "/apps/").concat(slug, "/config"), _tslib.__assign({}, config))];
818
- case 1:
819
- _a.sent();
820
- return [2 /*return*/, config];
821
- }
822
- });
823
- });
824
- };
825
- Api.prototype.getAppInstance = function (workspaceId, slug) {
826
- return _tslib.__awaiter(this, void 0, void 0, function () {
827
- return _tslib.__generator(this, function (_a) {
828
- return [2 /*return*/, this.get("/workspaces/".concat(workspaceId, "/apps/").concat(slug))];
829
- });
830
- });
831
- };
832
- Api.prototype.saveAppInstance = function (workspaceId, slug, appInstance) {
833
- return _tslib.__awaiter(this, void 0, void 0, function () {
834
- var response;
835
- return _tslib.__generator(this, function (_a) {
836
- switch (_a.label) {
837
- case 0: return [4 /*yield*/, this.patch("/workspaces/".concat(workspaceId, "/apps/").concat(slug), _tslib.__assign({}, appInstance))];
838
- case 1:
839
- response = _a.sent();
840
- return [2 /*return*/, response];
841
- }
842
- });
843
- });
844
- };
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 () {
848
- var formData;
849
- return _tslib.__generator(this, function (_a) {
850
- switch (_a.label) {
851
- case 0:
852
- formData = new FormData();
853
- (Array.isArray(files) ? files : [files]).forEach(function (file) {
854
- try {
855
- formData.append.apply(formData, _tslib.__spreadArray(['file'], dataURItoBlob(file), false));
856
- }
857
- catch (_a) { }
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
- }
868
- _a.label = 1;
869
- case 1:
870
- _a.trys.push([1, 3, , 4]);
871
- return [4 /*yield*/, this._fetch("/workspaces/".concat(workspaceId, "/files"), {
872
- method: 'POST',
873
- body: formData,
874
- })];
875
- case 2: return [2 /*return*/, _a.sent()];
876
- case 3:
877
- _a.sent();
878
- return [3 /*break*/, 4];
879
- case 4: return [2 /*return*/, []];
880
- }
881
- });
882
- });
883
- };
884
- Api.prototype.replaceAllImagesData = function (original, workspaceId) {
885
- return _tslib.__awaiter(this, void 0, void 0, function () {
886
- var key, toUpload, searchImages, searching, uploaded, replaced;
887
- return _tslib.__generator(this, function (_a) {
888
- switch (_a.label) {
889
- case 0:
890
- key = '…uploading-';
891
- toUpload = [];
892
- searchImages = function (mayHaveImage, uploaded) {
893
- switch (typeof mayHaveImage) {
894
- case 'string':
895
- if (uploaded && mayHaveImage.match(key)) {
896
- // Replace with url
897
- var _a = mayHaveImage.split(key), index = _a[1];
898
- return uploaded[+index];
899
- }
900
- if (mayHaveImage.match(/^data:/)) {
901
- toUpload.push(mayHaveImage);
902
- return "".concat(key).concat(toUpload.length - 1);
903
- }
904
- return mayHaveImage;
905
- case 'object':
906
- var isArray = Array.isArray(mayHaveImage);
907
- var withImagesUrl = isArray
908
- ? _tslib.__spreadArray([], mayHaveImage, true) : _tslib.__assign({}, mayHaveImage);
909
- for (var _i = 0, _b = Object.keys(withImagesUrl); _i < _b.length; _i++) {
910
- var key_1 = _b[_i];
911
- withImagesUrl[key_1] = searchImages(withImagesUrl[key_1], uploaded);
912
- }
913
- return withImagesUrl;
914
- default:
915
- return mayHaveImage;
916
- }
917
- };
918
- searching = searchImages(original);
919
- if (toUpload.length === 0)
920
- return [2 /*return*/, original];
921
- return [4 /*yield*/, this.uploadFiles(toUpload, workspaceId)];
922
- case 1:
923
- uploaded = _a.sent();
924
- replaced = searchImages(searching, uploaded.map(function (_a) {
925
- var url = _a.url;
926
- return url;
927
- }));
928
- return [2 /*return*/, replaced];
929
- }
930
- });
931
- });
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
- };
937
- Api.prototype.callAutomation = function (workspaceId, automation, params) {
938
- return _tslib.__awaiter(this, void 0, void 0, function () {
939
- return _tslib.__generator(this, function (_a) {
940
- return [2 /*return*/, this.post("/workspaces/".concat(workspaceId, "/webhooks/").concat(automation), params)];
941
- });
942
- });
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())
955
- Api.prototype.getWorkspaceUsage = function (workspaceId, _a) {
956
- var _b = _a === void 0 ? {} : _a, afterDate = _b.afterDate, beforeDate = _b.beforeDate, details = _b.details;
957
- return _tslib.__awaiter(this, void 0, void 0, function () {
958
- var params;
959
- return _tslib.__generator(this, function (_c) {
960
- params = new URLSearchParams(utils.removedUndefinedProperties({
961
- afterDate: "".concat(afterDate || ''),
962
- beforeDate: "".concat(beforeDate || ''),
963
- details: "".concat(details || ''),
964
- }, true));
965
- return [2 /*return*/, this.get("/workspaces/".concat(workspaceId, "/usage?").concat(params.toString()))];
966
- });
967
- });
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
- };
1010
- Api.prototype.workspaces = function (id) {
1011
- return new workspaces.WorkspacesEndpoint(id, this);
1012
- };
1013
- return Api;
1014
- }(fetcher.Fetcher));
1015
- var api = new Api({ host: 'https://api.eda.prisme.ai' });
1016
-
1017
- exports.Api = Api;
1018
- exports["default"] = api;