@prisme.ai/sdk 0.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.
- package/Readme.md +26 -0
- package/dist/_virtual/_tslib.js +107 -0
- package/dist/index.d.ts +7 -0
- package/dist/lib/ApiError.d.ts +8 -0
- package/dist/lib/ApiError.test.d.ts +1 -0
- package/dist/lib/HTTPError.d.ts +6 -0
- package/dist/lib/HTTPError.test.d.ts +1 -0
- package/dist/lib/api.d.ts +59 -0
- package/dist/lib/api.test.d.ts +1 -0
- package/dist/lib/events.d.ts +14 -0
- package/dist/lib/events.test.d.ts +1 -0
- package/dist/lib/fetcher.d.ts +11 -0
- package/dist/lib/fetcher.test.d.ts +1 -0
- package/dist/lib/types.d.ts +13 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.test.d.ts +1 -0
- package/dist/sdk/index.js +19 -0
- package/dist/sdk/lib/ApiError.js +24 -0
- package/dist/sdk/lib/HTTPError.js +21 -0
- package/dist/sdk/lib/api.js +553 -0
- package/dist/sdk/lib/events.js +65 -0
- package/dist/sdk/lib/fetcher.js +121 -0
- package/dist/sdk/lib/utils.js +18 -0
- package/index.ts +7 -0
- package/lib/ApiError.test.ts +13 -0
- package/lib/ApiError.ts +21 -0
- package/lib/HTTPError.test.ts +8 -0
- package/lib/HTTPError.ts +13 -0
- package/lib/api.test.ts +231 -0
- package/lib/api.ts +439 -0
- package/lib/events.test.ts +57 -0
- package/lib/events.ts +69 -0
- package/lib/fetcher.test.ts +200 -0
- package/lib/fetcher.ts +97 -0
- package/lib/types.ts +17 -0
- package/lib/utils.test.ts +38 -0
- package/lib/utils.ts +12 -0
- package/package.json +16 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,553 @@
|
|
|
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 fetcher = require('./fetcher.js');
|
|
8
|
+
var events = require('./events.js');
|
|
9
|
+
var utils = require('./utils.js');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var QueryString__default = /*#__PURE__*/_interopDefaultLegacy(QueryString);
|
|
14
|
+
|
|
15
|
+
var Api = /** @class */ (function (_super) {
|
|
16
|
+
_tslib.__extends(Api, _super);
|
|
17
|
+
function Api() {
|
|
18
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
19
|
+
}
|
|
20
|
+
Api.prototype.me = function () {
|
|
21
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
22
|
+
return _tslib.__generator(this, function (_a) {
|
|
23
|
+
switch (_a.label) {
|
|
24
|
+
case 0: return [4 /*yield*/, this.get('/me')];
|
|
25
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Api.prototype.signin = function (email, password) {
|
|
31
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
32
|
+
return _tslib.__generator(this, function (_a) {
|
|
33
|
+
switch (_a.label) {
|
|
34
|
+
case 0: return [4 /*yield*/, this.post('/login', {
|
|
35
|
+
email: email,
|
|
36
|
+
password: password,
|
|
37
|
+
})];
|
|
38
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
Api.prototype.signup = function (email, password, firstName, lastName) {
|
|
44
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
45
|
+
return _tslib.__generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0: return [4 /*yield*/, this.post('/signup', {
|
|
48
|
+
email: email,
|
|
49
|
+
password: password,
|
|
50
|
+
firstName: firstName,
|
|
51
|
+
lastName: lastName,
|
|
52
|
+
})];
|
|
53
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
Api.prototype.signout = function () {
|
|
59
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
60
|
+
return _tslib.__generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0: return [4 /*yield*/, this.post('/logout')];
|
|
63
|
+
case 1:
|
|
64
|
+
_a.sent();
|
|
65
|
+
this.token = null;
|
|
66
|
+
return [2 /*return*/];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
// Workspaces
|
|
72
|
+
Api.prototype.getWorkspaces = function () {
|
|
73
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
74
|
+
return _tslib.__generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, this.get('/workspaces?limit=300')];
|
|
77
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
Api.prototype.getWorkspace = function (id) {
|
|
83
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
84
|
+
return _tslib.__generator(this, function (_a) {
|
|
85
|
+
switch (_a.label) {
|
|
86
|
+
case 0: return [4 /*yield*/, this.get("/workspaces/".concat(id))];
|
|
87
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
Api.prototype.createWorkspace = function (name) {
|
|
93
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
94
|
+
return _tslib.__generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0: return [4 /*yield*/, this.post('/workspaces', { name: name })];
|
|
97
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
Api.prototype.updateWorkspace = function (workspace) {
|
|
103
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
return _tslib.__generator(this, function (_c) {
|
|
106
|
+
switch (_c.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
_a = this.patch;
|
|
109
|
+
_b = ["/workspaces/".concat(workspace.id)];
|
|
110
|
+
return [4 /*yield*/, this.replaceAllImagesData(workspace, workspace.id)];
|
|
111
|
+
case 1: return [4 /*yield*/, _a.apply(this, _b.concat([_c.sent()]))];
|
|
112
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
Api.prototype.deleteWorkspace = function (workspaceId) {
|
|
118
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
119
|
+
return _tslib.__generator(this, function (_a) {
|
|
120
|
+
switch (_a.label) {
|
|
121
|
+
case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId))];
|
|
122
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
// Automations
|
|
128
|
+
Api.prototype.createAutomation = function (workspace, automation) {
|
|
129
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
130
|
+
return _tslib.__generator(this, function (_a) {
|
|
131
|
+
switch (_a.label) {
|
|
132
|
+
case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspace.id, "/automations"), _tslib.__assign({}, automation))];
|
|
133
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
Api.prototype.updateAutomation = function (workspace, slug, automation) {
|
|
139
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
return _tslib.__generator(this, function (_c) {
|
|
142
|
+
switch (_c.label) {
|
|
143
|
+
case 0:
|
|
144
|
+
_a = this.patch;
|
|
145
|
+
_b = ["/workspaces/".concat(workspace.id, "/automations/").concat(slug)];
|
|
146
|
+
return [4 /*yield*/, this.replaceAllImagesData(automation, workspace.id)];
|
|
147
|
+
case 1: return [4 /*yield*/, _a.apply(this, _b.concat([_c.sent()]))];
|
|
148
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
Api.prototype.deleteAutomation = function (workspace, slug) {
|
|
154
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
155
|
+
return _tslib.__generator(this, function (_a) {
|
|
156
|
+
switch (_a.label) {
|
|
157
|
+
case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspace.id, "/automations/").concat(slug))];
|
|
158
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
// Pages
|
|
164
|
+
Api.prototype.getPages = function (workspaceId) {
|
|
165
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
166
|
+
var pages;
|
|
167
|
+
return _tslib.__generator(this, function (_a) {
|
|
168
|
+
switch (_a.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
_a.trys.push([0, 2, , 3]);
|
|
171
|
+
return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/pages"))];
|
|
172
|
+
case 1:
|
|
173
|
+
pages = _a.sent();
|
|
174
|
+
return [2 /*return*/, pages.map(function (_a) {
|
|
175
|
+
_a.createdAt; _a.createdBy; _a.updatedAt; _a.updatedBy; var page = _tslib.__rest(_a, ["createdAt", "createdBy", "updatedAt", "updatedBy"]);
|
|
176
|
+
return page;
|
|
177
|
+
})];
|
|
178
|
+
case 2:
|
|
179
|
+
_a.sent();
|
|
180
|
+
return [2 /*return*/, []];
|
|
181
|
+
case 3: return [2 /*return*/];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
Api.prototype.getPage = function (workspaceId, pageId) {
|
|
187
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
188
|
+
return _tslib.__generator(this, function (_a) {
|
|
189
|
+
switch (_a.label) {
|
|
190
|
+
case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/pages/").concat(pageId))];
|
|
191
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
Api.prototype.getPageBySlug = function (pageSlug) {
|
|
197
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
198
|
+
return _tslib.__generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0: return [4 /*yield*/, this.get("/pages/".concat(pageSlug))];
|
|
201
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
Api.prototype.createPage = function (workspaceId, page) {
|
|
207
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
208
|
+
var _a, newPage;
|
|
209
|
+
return _tslib.__generator(this, function (_b) {
|
|
210
|
+
switch (_b.label) {
|
|
211
|
+
case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/pages"), page)];
|
|
212
|
+
case 1:
|
|
213
|
+
_a = _b.sent(), newPage = _tslib.__rest(_a, ["createdAt", "createdBy", "updatedAt", "updatedBy"]);
|
|
214
|
+
return [2 /*return*/, newPage];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
// Replace images as dataurl to uploaded url in any type of data
|
|
220
|
+
Api.prototype.updatePage = function (workspaceId, page) {
|
|
221
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
222
|
+
var _a, updatedPage, _b, _c;
|
|
223
|
+
return _tslib.__generator(this, function (_d) {
|
|
224
|
+
switch (_d.label) {
|
|
225
|
+
case 0:
|
|
226
|
+
_b = this.patch;
|
|
227
|
+
_c = ["/workspaces/".concat(workspaceId, "/pages/").concat(page.id)];
|
|
228
|
+
return [4 /*yield*/, this.replaceAllImagesData(page, workspaceId)];
|
|
229
|
+
case 1: return [4 /*yield*/, _b.apply(this, _c.concat([_d.sent()]))];
|
|
230
|
+
case 2:
|
|
231
|
+
_a = _d.sent(), updatedPage = _tslib.__rest(_a, ["createdAt", "createdBy", "updatedAt", "updatedBy"]);
|
|
232
|
+
return [2 /*return*/, updatedPage];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
Api.prototype.deletePage = function (workspaceId, pageId) {
|
|
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.delete("/workspaces/".concat(workspaceId, "/pages/").concat(pageId))];
|
|
242
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
// Events
|
|
248
|
+
Api.prototype.streamEvents = function (workspaceId) {
|
|
249
|
+
var events$1 = new events.Events(workspaceId, this.token || '', this.host);
|
|
250
|
+
return new Promise(function (resolve, reject) {
|
|
251
|
+
events$1.once('connect', function () {
|
|
252
|
+
resolve(events$1);
|
|
253
|
+
});
|
|
254
|
+
events$1.once('connect_error', function () {
|
|
255
|
+
reject();
|
|
256
|
+
events$1.close();
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
Api.prototype.getEvents = function (workspaceId, options) {
|
|
261
|
+
if (options === void 0) { options = {}; }
|
|
262
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
263
|
+
var query, events;
|
|
264
|
+
return _tslib.__generator(this, function (_a) {
|
|
265
|
+
switch (_a.label) {
|
|
266
|
+
case 0:
|
|
267
|
+
_a.trys.push([0, 2, , 3]);
|
|
268
|
+
query = QueryString__default["default"].stringify(options);
|
|
269
|
+
return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/events").concat(query && "?".concat(query)))];
|
|
270
|
+
case 1:
|
|
271
|
+
events = (_a.sent()).result.events;
|
|
272
|
+
return [2 /*return*/, events.map(function (_a) {
|
|
273
|
+
var createdAt = _a.createdAt, event = _tslib.__rest(_a, ["createdAt"]);
|
|
274
|
+
return (_tslib.__assign(_tslib.__assign({}, event), { createdAt: new Date(createdAt) }));
|
|
275
|
+
})];
|
|
276
|
+
case 2:
|
|
277
|
+
_a.sent();
|
|
278
|
+
return [2 /*return*/, []];
|
|
279
|
+
case 3: return [2 /*return*/];
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
Api.prototype.postEvents = function (workspaceId, events) {
|
|
285
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
286
|
+
return _tslib.__generator(this, function (_a) {
|
|
287
|
+
switch (_a.label) {
|
|
288
|
+
case 0:
|
|
289
|
+
_a.trys.push([0, 2, , 3]);
|
|
290
|
+
return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/events"), {
|
|
291
|
+
events: events,
|
|
292
|
+
})];
|
|
293
|
+
case 1:
|
|
294
|
+
_a.sent();
|
|
295
|
+
return [2 /*return*/, true];
|
|
296
|
+
case 2:
|
|
297
|
+
_a.sent();
|
|
298
|
+
return [2 /*return*/, false];
|
|
299
|
+
case 3: return [2 /*return*/];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
Api.prototype.getPermissions = function (subjectType, subjectId) {
|
|
305
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
306
|
+
return _tslib.__generator(this, function (_a) {
|
|
307
|
+
switch (_a.label) {
|
|
308
|
+
case 0: return [4 /*yield*/, this.get("/".concat(subjectType, "/").concat(subjectId, "/permissions"))];
|
|
309
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
Api.prototype.addPermissions = function (subjectType, subjectId, permissions) {
|
|
315
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
316
|
+
return _tslib.__generator(this, function (_a) {
|
|
317
|
+
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()];
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
Api.prototype.deletePermissions = function (subjectType, subjectId, userEmail) {
|
|
325
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
326
|
+
return _tslib.__generator(this, function (_a) {
|
|
327
|
+
switch (_a.label) {
|
|
328
|
+
case 0: return [4 /*yield*/, this.delete("/".concat(subjectType, "/").concat(subjectId, "/permissions/").concat(userEmail))];
|
|
329
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
Api.prototype.getApps = function (_a) {
|
|
335
|
+
var query = _a.query, page = _a.page, limit = _a.limit, workspaceId = _a.workspaceId;
|
|
336
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
337
|
+
var params;
|
|
338
|
+
return _tslib.__generator(this, function (_b) {
|
|
339
|
+
switch (_b.label) {
|
|
340
|
+
case 0:
|
|
341
|
+
params = new URLSearchParams(utils.removedUndefinedProperties({
|
|
342
|
+
text: "".concat(query || ''),
|
|
343
|
+
page: "".concat(page || ''),
|
|
344
|
+
limit: "".concat(limit || ''),
|
|
345
|
+
workspaceId: "".concat(workspaceId || ''),
|
|
346
|
+
}, true));
|
|
347
|
+
return [4 /*yield*/, this.get("/apps?".concat(params.toString()))];
|
|
348
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
Api.prototype.installApp = function (workspaceId, body) {
|
|
354
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
355
|
+
return _tslib.__generator(this, function (_a) {
|
|
356
|
+
switch (_a.label) {
|
|
357
|
+
case 0: return [4 /*yield*/, this.post("/workspaces/".concat(workspaceId, "/apps"), body)];
|
|
358
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
Api.prototype.updateApp = function (workspaceId, slug, body) {
|
|
364
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
365
|
+
return _tslib.__generator(this, function (_a) {
|
|
366
|
+
switch (_a.label) {
|
|
367
|
+
case 0: return [4 /*yield*/, this.patch("/workspaces/".concat(workspaceId, "/apps/").concat(slug), body)];
|
|
368
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
Api.prototype.uninstallApp = function (workspaceId, slug) {
|
|
374
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
375
|
+
return _tslib.__generator(this, function (_a) {
|
|
376
|
+
switch (_a.label) {
|
|
377
|
+
case 0: return [4 /*yield*/, this.delete("/workspaces/".concat(workspaceId, "/apps/").concat(slug))];
|
|
378
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
Api.prototype.publishApp = function (body) {
|
|
384
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
385
|
+
return _tslib.__generator(this, function (_a) {
|
|
386
|
+
switch (_a.label) {
|
|
387
|
+
case 0: return [4 /*yield*/, this.post("/apps", body)];
|
|
388
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
Api.prototype.listAppInstances = function (workspaceId) {
|
|
394
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
395
|
+
return _tslib.__generator(this, function (_a) {
|
|
396
|
+
switch (_a.label) {
|
|
397
|
+
case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/apps"))];
|
|
398
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
};
|
|
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
|
+
Api.prototype.getAppConfig = function (workspaceId, slug) {
|
|
414
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
415
|
+
var config;
|
|
416
|
+
return _tslib.__generator(this, function (_a) {
|
|
417
|
+
switch (_a.label) {
|
|
418
|
+
case 0: return [4 /*yield*/, this.get("/workspaces/".concat(workspaceId, "/apps/").concat(slug, "/config"))];
|
|
419
|
+
case 1:
|
|
420
|
+
config = _a.sent();
|
|
421
|
+
return [2 /*return*/, config];
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
Api.prototype.updateAppConfig = function (workspaceId, slug, config) {
|
|
427
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
428
|
+
return _tslib.__generator(this, function (_a) {
|
|
429
|
+
switch (_a.label) {
|
|
430
|
+
case 0: return [4 /*yield*/, this.patch("/workspaces/".concat(workspaceId, "/apps/").concat(slug, "/config"), _tslib.__assign({}, config))];
|
|
431
|
+
case 1:
|
|
432
|
+
_a.sent();
|
|
433
|
+
return [2 /*return*/, config];
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
Api.prototype.uploadFiles = function (files, workspaceId) {
|
|
439
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
440
|
+
function dataURItoBlob(dataURI) {
|
|
441
|
+
// convert base64/URLEncoded data component to raw binary data held in a string
|
|
442
|
+
var byteString;
|
|
443
|
+
if (dataURI.split(',')[0].indexOf('base64') >= 0)
|
|
444
|
+
byteString = atob(dataURI.split(',')[1]);
|
|
445
|
+
else
|
|
446
|
+
byteString = unescape(dataURI.split(',')[1]);
|
|
447
|
+
// separate out the mime component
|
|
448
|
+
var metadata = dataURI
|
|
449
|
+
.split(';')
|
|
450
|
+
.filter(function (v, k, all) { return k < all.length - 1; })
|
|
451
|
+
.map(function (v) { return v.split(/:/); });
|
|
452
|
+
var _a = metadata.find(function (_a) {
|
|
453
|
+
var k = _a[0]; _a[1];
|
|
454
|
+
return k === 'data';
|
|
455
|
+
}) || [], _b = _a[1], mimeString = _b === void 0 ? '' : _b;
|
|
456
|
+
var _c = mimeString.split(/\//), ext = _c[1];
|
|
457
|
+
var _d = metadata.find(function (_a) {
|
|
458
|
+
var k = _a[0]; _a[1];
|
|
459
|
+
return k === 'filename';
|
|
460
|
+
}) || [], _e = _d[1], fileName = _e === void 0 ? "file.".concat(ext) : _e;
|
|
461
|
+
// write the bytes of the string to a typed array
|
|
462
|
+
var ia = new Uint8Array(byteString.length);
|
|
463
|
+
for (var i = 0; i < byteString.length; i++) {
|
|
464
|
+
ia[i] = byteString.charCodeAt(i);
|
|
465
|
+
}
|
|
466
|
+
return [new Blob([ia], { type: mimeString }), fileName];
|
|
467
|
+
}
|
|
468
|
+
var formData;
|
|
469
|
+
return _tslib.__generator(this, function (_a) {
|
|
470
|
+
switch (_a.label) {
|
|
471
|
+
case 0:
|
|
472
|
+
formData = new FormData();
|
|
473
|
+
(Array.isArray(files) ? files : [files]).forEach(function (file) {
|
|
474
|
+
formData.append.apply(formData, _tslib.__spreadArray(['file'], dataURItoBlob(file)));
|
|
475
|
+
});
|
|
476
|
+
_a.label = 1;
|
|
477
|
+
case 1:
|
|
478
|
+
_a.trys.push([1, 3, , 4]);
|
|
479
|
+
return [4 /*yield*/, this._fetch("/workspaces/".concat(workspaceId, "/files"), {
|
|
480
|
+
method: 'POST',
|
|
481
|
+
body: formData,
|
|
482
|
+
})];
|
|
483
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
484
|
+
case 3:
|
|
485
|
+
_a.sent();
|
|
486
|
+
return [3 /*break*/, 4];
|
|
487
|
+
case 4: return [2 /*return*/, []];
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
Api.prototype.replaceAllImagesData = function (original, workspaceId) {
|
|
493
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
494
|
+
var key, toUpload, searchImages, searching, uploaded, replaced;
|
|
495
|
+
return _tslib.__generator(this, function (_a) {
|
|
496
|
+
switch (_a.label) {
|
|
497
|
+
case 0:
|
|
498
|
+
key = '…uploading-';
|
|
499
|
+
toUpload = [];
|
|
500
|
+
searchImages = function (mayHaveImage, uploaded) {
|
|
501
|
+
switch (typeof mayHaveImage) {
|
|
502
|
+
case 'string':
|
|
503
|
+
if (uploaded && mayHaveImage.match(key)) {
|
|
504
|
+
// Replace with url
|
|
505
|
+
var _a = mayHaveImage.split(key), index = _a[1];
|
|
506
|
+
return uploaded[+index];
|
|
507
|
+
}
|
|
508
|
+
if (mayHaveImage.match(/^data:/)) {
|
|
509
|
+
toUpload.push(mayHaveImage);
|
|
510
|
+
return "".concat(key).concat(toUpload.length - 1);
|
|
511
|
+
}
|
|
512
|
+
return mayHaveImage;
|
|
513
|
+
case 'object':
|
|
514
|
+
var isArray = Array.isArray(mayHaveImage);
|
|
515
|
+
var withImagesUrl = isArray
|
|
516
|
+
? _tslib.__spreadArray([], mayHaveImage) : _tslib.__assign({}, mayHaveImage);
|
|
517
|
+
for (var _i = 0, _b = Object.keys(withImagesUrl); _i < _b.length; _i++) {
|
|
518
|
+
var key_1 = _b[_i];
|
|
519
|
+
withImagesUrl[key_1] = searchImages(withImagesUrl[key_1], uploaded);
|
|
520
|
+
}
|
|
521
|
+
return withImagesUrl;
|
|
522
|
+
default:
|
|
523
|
+
return mayHaveImage;
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
searching = searchImages(original);
|
|
527
|
+
if (toUpload.length === 0)
|
|
528
|
+
return [2 /*return*/, original];
|
|
529
|
+
return [4 /*yield*/, this.uploadFiles(toUpload, workspaceId)];
|
|
530
|
+
case 1:
|
|
531
|
+
uploaded = _a.sent();
|
|
532
|
+
replaced = searchImages(searching, uploaded.map(function (_a) {
|
|
533
|
+
var url = _a.url;
|
|
534
|
+
return url;
|
|
535
|
+
}));
|
|
536
|
+
return [2 /*return*/, replaced];
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
Api.prototype.callAutomation = function (workspaceId, automation) {
|
|
542
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
543
|
+
return _tslib.__generator(this, function (_a) {
|
|
544
|
+
return [2 /*return*/, this._fetch("/workspaces/".concat(workspaceId, "/webhooks/").concat(automation))];
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
};
|
|
548
|
+
return Api;
|
|
549
|
+
}(fetcher.Fetcher));
|
|
550
|
+
var api = new Api('https://api.eda.prisme.ai');
|
|
551
|
+
|
|
552
|
+
exports.Api = Api;
|
|
553
|
+
exports["default"] = api;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var io = require('socket.io-client');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
|
|
10
|
+
|
|
11
|
+
var Events = /** @class */ (function () {
|
|
12
|
+
function Events(workspaceId, token, apiHost) {
|
|
13
|
+
if (apiHost === void 0) { apiHost = 'https://api.eda.prisme.ai'; }
|
|
14
|
+
this.workspaceId = workspaceId;
|
|
15
|
+
this.client = io__default["default"]("".concat(apiHost, "/workspaces/").concat(workspaceId, "/events"), {
|
|
16
|
+
extraHeaders: {
|
|
17
|
+
'x-prismeai-session-token': token,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(Events.prototype, "socket", {
|
|
22
|
+
get: function () {
|
|
23
|
+
return this.client;
|
|
24
|
+
},
|
|
25
|
+
enumerable: false,
|
|
26
|
+
configurable: true
|
|
27
|
+
});
|
|
28
|
+
Events.prototype.destroy = function () {
|
|
29
|
+
var _this = this;
|
|
30
|
+
this.workspaceId = '';
|
|
31
|
+
if (this.client.connected) {
|
|
32
|
+
this.client.disconnect();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this.client.once('connect', function () {
|
|
36
|
+
_this.client.disconnect();
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
Events.prototype.all = function (listener) {
|
|
40
|
+
var _this = this;
|
|
41
|
+
this.client.onAny(listener);
|
|
42
|
+
return function () { return _this.client.offAny(listener); };
|
|
43
|
+
};
|
|
44
|
+
Events.prototype.on = function (ev, listener) {
|
|
45
|
+
var _this = this;
|
|
46
|
+
this.client.on(ev, listener);
|
|
47
|
+
return function () { return _this.client.off(ev, listener); };
|
|
48
|
+
};
|
|
49
|
+
Events.prototype.emit = function (event, payload) {
|
|
50
|
+
this.client.emit('event', {
|
|
51
|
+
type: event,
|
|
52
|
+
payload: payload,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
Events.prototype.once = function (ev, listener) {
|
|
56
|
+
this.client.once(ev, listener);
|
|
57
|
+
};
|
|
58
|
+
Events.prototype.close = function () {
|
|
59
|
+
this.client.close();
|
|
60
|
+
};
|
|
61
|
+
return Events;
|
|
62
|
+
}());
|
|
63
|
+
|
|
64
|
+
exports.Events = Events;
|
|
65
|
+
exports["default"] = Events;
|