@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.
- package/dist/lib/api.d.ts +58 -21
- package/dist/lib/endpoints/workspaces.d.ts +9 -0
- package/dist/lib/endpoints/workspacesVersions.d.ts +10 -0
- package/dist/lib/events.d.ts +26 -4
- package/dist/lib/fetcher.d.ts +5 -0
- package/dist/lib/types.d.ts +5 -1
- package/dist/sdk/lib/api.js +325 -46
- package/dist/sdk/lib/endpoints/workspaces.js +23 -0
- package/dist/sdk/lib/endpoints/workspacesVersions.js +40 -0
- package/dist/sdk/lib/events.js +74 -8
- package/dist/sdk/lib/fetcher.js +53 -17
- package/lib/api.test.ts +568 -42
- package/lib/api.ts +348 -77
- package/lib/endpoints/workspaces.ts +18 -0
- package/lib/endpoints/workspacesVersions.ts +34 -0
- package/lib/events.test.ts +39 -7
- package/lib/events.ts +123 -16
- package/lib/fetcher.test.ts +59 -13
- package/lib/fetcher.ts +54 -18
- package/lib/types.ts +5 -1
- package/package.json +1 -1
package/lib/api.ts
CHANGED
|
@@ -3,8 +3,8 @@ import Fetcher from './fetcher';
|
|
|
3
3
|
import { Event, Workspace } from './types';
|
|
4
4
|
import { Events } from './events';
|
|
5
5
|
import { removedUndefinedProperties } from './utils';
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import WorkspacesEndpoint from './endpoints/workspaces';
|
|
7
|
+
import ApiError from './ApiError';
|
|
8
8
|
|
|
9
9
|
interface PageWithMetadata extends Prismeai.Page {
|
|
10
10
|
createdAt: string;
|
|
@@ -13,9 +13,30 @@ interface PageWithMetadata extends Prismeai.Page {
|
|
|
13
13
|
updatedBy: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export type UserPermissions = {
|
|
17
|
+
permissions: Prismeai.UserPermissions['permissions'];
|
|
18
|
+
target: {
|
|
19
|
+
id?: string;
|
|
20
|
+
email?: string;
|
|
21
|
+
public?: boolean;
|
|
22
|
+
role?: string;
|
|
23
|
+
displayName?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
16
27
|
export class Api extends Fetcher {
|
|
28
|
+
private sessionId?: string;
|
|
29
|
+
private _user?: Prismeai.User & { sessionId?: string };
|
|
30
|
+
|
|
31
|
+
get user() {
|
|
32
|
+
return this._user;
|
|
33
|
+
}
|
|
34
|
+
|
|
17
35
|
async me() {
|
|
18
|
-
|
|
36
|
+
const me = await this.get('/me');
|
|
37
|
+
this.sessionId = me.sessionId;
|
|
38
|
+
this._user = me;
|
|
39
|
+
return me;
|
|
19
40
|
}
|
|
20
41
|
|
|
21
42
|
async signin(
|
|
@@ -26,17 +47,38 @@ export class Api extends Fetcher {
|
|
|
26
47
|
token: string;
|
|
27
48
|
}
|
|
28
49
|
> {
|
|
29
|
-
|
|
50
|
+
const user = await this.post<
|
|
51
|
+
Prismeai.User & {
|
|
52
|
+
token: string;
|
|
53
|
+
}
|
|
54
|
+
>('/login', {
|
|
30
55
|
email,
|
|
31
56
|
password,
|
|
32
57
|
});
|
|
58
|
+
this._user = user;
|
|
59
|
+
return user;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async createAnonymousSession(): Promise<
|
|
63
|
+
Prismeai.User & {
|
|
64
|
+
token: string;
|
|
65
|
+
}
|
|
66
|
+
> {
|
|
67
|
+
const user = await this.post<
|
|
68
|
+
Prismeai.User & {
|
|
69
|
+
token: string;
|
|
70
|
+
}
|
|
71
|
+
>('/login/anonymous');
|
|
72
|
+
this._user = user;
|
|
73
|
+
return user;
|
|
33
74
|
}
|
|
34
75
|
|
|
35
76
|
async signup(
|
|
36
77
|
email: string,
|
|
37
78
|
password: string,
|
|
38
79
|
firstName: string,
|
|
39
|
-
lastName: string
|
|
80
|
+
lastName: string,
|
|
81
|
+
language: string
|
|
40
82
|
): Promise<
|
|
41
83
|
Prismeai.User & {
|
|
42
84
|
token: string;
|
|
@@ -47,6 +89,7 @@ export class Api extends Fetcher {
|
|
|
47
89
|
password,
|
|
48
90
|
firstName,
|
|
49
91
|
lastName,
|
|
92
|
+
language,
|
|
50
93
|
});
|
|
51
94
|
}
|
|
52
95
|
|
|
@@ -55,20 +98,66 @@ export class Api extends Fetcher {
|
|
|
55
98
|
this.token = null;
|
|
56
99
|
}
|
|
57
100
|
|
|
101
|
+
// Mail validation
|
|
102
|
+
async sendValidationMail(email: string, language: string) {
|
|
103
|
+
return await this.post('/user/validate', { email, language });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async validateMail(token: string) {
|
|
107
|
+
return await this.post('/user/validate', { token });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Password reset
|
|
111
|
+
async sendPasswordResetMail(email: string, language: string) {
|
|
112
|
+
return await this.post('/user/password', { email, language });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async passwordReset(token: string, password: string) {
|
|
116
|
+
return await this.post('/user/password', { token, password });
|
|
117
|
+
}
|
|
118
|
+
|
|
58
119
|
// Workspaces
|
|
59
120
|
async getWorkspaces(): Promise<Workspace[]> {
|
|
60
|
-
return await this.get('/workspaces?limit=
|
|
121
|
+
return await this.get('/workspaces?limit=600');
|
|
61
122
|
}
|
|
62
123
|
|
|
63
|
-
async getWorkspace(
|
|
124
|
+
async getWorkspace(
|
|
125
|
+
id: string
|
|
126
|
+
): Promise<PrismeaiAPI.GetWorkspace.Responses.$200> {
|
|
64
127
|
return await this.get(`/workspaces/${id}`);
|
|
65
128
|
}
|
|
66
129
|
|
|
130
|
+
async getWorkspaceSecurity(
|
|
131
|
+
id: string
|
|
132
|
+
): Promise<PrismeaiAPI.GetSecurity.Responses.$200> {
|
|
133
|
+
return await this.get(`/workspaces/${id}/security`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async updateWorkspaceSecurity(
|
|
137
|
+
workspaceId: string,
|
|
138
|
+
security: Prismeai.WorkspaceSecurity
|
|
139
|
+
): Promise<PrismeaiAPI.UpdateSecurity.Responses.$200> {
|
|
140
|
+
return await this.put(`/workspaces/${workspaceId}/security`, security);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async getWorkspaceRoles(
|
|
144
|
+
id: string
|
|
145
|
+
): Promise<PrismeaiAPI.GetRoles.Responses.$200> {
|
|
146
|
+
return await this.get(`/workspaces/${id}/security/roles`);
|
|
147
|
+
}
|
|
148
|
+
|
|
67
149
|
async createWorkspace(name: string): Promise<Workspace> {
|
|
68
150
|
return await this.post('/workspaces', { name });
|
|
69
151
|
}
|
|
70
152
|
|
|
71
|
-
async
|
|
153
|
+
async duplicateWorkspace({ id }: { id: string }): Promise<Workspace | null> {
|
|
154
|
+
return await this.post(`/workspaces/${id}/versions/current/duplicate`, {});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async updateWorkspace(
|
|
158
|
+
workspace: Prismeai.DSULPatch
|
|
159
|
+
): Promise<PrismeaiAPI.UpdateWorkspace.Responses.$200 | null> {
|
|
160
|
+
if (!workspace.id) return null;
|
|
72
161
|
return await this.patch(
|
|
73
162
|
`/workspaces/${workspace.id}`,
|
|
74
163
|
await this.replaceAllImagesData(workspace, workspace.id)
|
|
@@ -79,29 +168,89 @@ export class Api extends Fetcher {
|
|
|
79
168
|
return await this.delete(`/workspaces/${workspaceId}`);
|
|
80
169
|
}
|
|
81
170
|
|
|
171
|
+
async generateApiKey(
|
|
172
|
+
workspaceId: Workspace['id'],
|
|
173
|
+
events: string[],
|
|
174
|
+
uploads?: string[]
|
|
175
|
+
) {
|
|
176
|
+
const { apiKey } = await this.post<{ apiKey: string }>(
|
|
177
|
+
`/workspaces/${workspaceId}/apiKeys`,
|
|
178
|
+
{
|
|
179
|
+
rules: {
|
|
180
|
+
events: {
|
|
181
|
+
types: events,
|
|
182
|
+
filters: {
|
|
183
|
+
'source.sessionId': '${user.sessionId}',
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
uploads: uploads
|
|
187
|
+
? {
|
|
188
|
+
mimetypes: uploads,
|
|
189
|
+
}
|
|
190
|
+
: undefined,
|
|
191
|
+
},
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
return apiKey;
|
|
196
|
+
}
|
|
197
|
+
async updateApiKey(
|
|
198
|
+
workspaceId: Workspace['id'],
|
|
199
|
+
apiKey: string,
|
|
200
|
+
events: string[],
|
|
201
|
+
uploads?: string[]
|
|
202
|
+
) {
|
|
203
|
+
await this.put(`/workspaces/${workspaceId}/apiKeys/${apiKey}`, {
|
|
204
|
+
rules: {
|
|
205
|
+
events: {
|
|
206
|
+
types: events,
|
|
207
|
+
filters: {
|
|
208
|
+
'source.sessionId': '${user.sessionId}',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
uploads: uploads
|
|
212
|
+
? {
|
|
213
|
+
mimetypes: uploads,
|
|
214
|
+
}
|
|
215
|
+
: undefined,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
return apiKey;
|
|
220
|
+
}
|
|
221
|
+
|
|
82
222
|
// Automations
|
|
223
|
+
async getAutomation(
|
|
224
|
+
workspaceId: string,
|
|
225
|
+
automationSlug: string
|
|
226
|
+
): Promise<PrismeaiAPI.GetAutomation.Responses.$200> {
|
|
227
|
+
return await this.get(
|
|
228
|
+
`/workspaces/${workspaceId}/automations/${automationSlug}`
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
83
232
|
async createAutomation(
|
|
84
|
-
|
|
233
|
+
workspaceId: Workspace['id'],
|
|
85
234
|
automation: Prismeai.Automation
|
|
86
235
|
): Promise<Prismeai.Automation & { slug: string }> {
|
|
87
|
-
return await this.post(`/workspaces/${
|
|
236
|
+
return await this.post(`/workspaces/${workspaceId}/automations`, {
|
|
88
237
|
...automation,
|
|
89
238
|
});
|
|
90
239
|
}
|
|
91
240
|
|
|
92
241
|
async updateAutomation(
|
|
93
|
-
|
|
242
|
+
workspaceId: string,
|
|
94
243
|
slug: string,
|
|
95
244
|
automation: Prismeai.Automation
|
|
96
245
|
): Promise<Prismeai.Automation & { slug: string }> {
|
|
97
246
|
return await this.patch(
|
|
98
|
-
`/workspaces/${
|
|
99
|
-
await this.replaceAllImagesData(automation,
|
|
247
|
+
`/workspaces/${workspaceId}/automations/${slug}`,
|
|
248
|
+
await this.replaceAllImagesData(automation, workspaceId)
|
|
100
249
|
);
|
|
101
250
|
}
|
|
102
251
|
|
|
103
|
-
async deleteAutomation(
|
|
104
|
-
return await this.delete(`/workspaces/${
|
|
252
|
+
async deleteAutomation(workspaceId: string, slug: string): Promise<string> {
|
|
253
|
+
return await this.delete(`/workspaces/${workspaceId}/automations/${slug}`);
|
|
105
254
|
}
|
|
106
255
|
|
|
107
256
|
// Pages
|
|
@@ -122,77 +271,92 @@ export class Api extends Fetcher {
|
|
|
122
271
|
|
|
123
272
|
async getPage(
|
|
124
273
|
workspaceId: PrismeaiAPI.GetPage.Parameters.WorkspaceId,
|
|
125
|
-
|
|
274
|
+
pageSlug: PrismeaiAPI.GetPage.Parameters.Slug
|
|
126
275
|
): Promise<Prismeai.DetailedPage> {
|
|
127
|
-
return await this.get(
|
|
276
|
+
return await this.get(
|
|
277
|
+
`/workspaces/${workspaceId}/pages/${encodeURIComponent(pageSlug)}`
|
|
278
|
+
);
|
|
128
279
|
}
|
|
129
280
|
|
|
130
281
|
async getPageBySlug(
|
|
131
|
-
|
|
282
|
+
workspaceSlug: PrismeaiAPI.GetPageBySlug.Parameters.WorkspaceSlug,
|
|
283
|
+
pageSlug: PrismeaiAPI.GetPageBySlug.Parameters.PageSlug
|
|
132
284
|
): Promise<Prismeai.DetailedPage> {
|
|
133
|
-
return await this.get(
|
|
285
|
+
return await this.get(
|
|
286
|
+
`/pages/${workspaceSlug}/${encodeURIComponent(pageSlug)}`
|
|
287
|
+
);
|
|
134
288
|
}
|
|
135
289
|
|
|
136
290
|
async createPage(
|
|
137
|
-
workspaceId:
|
|
138
|
-
page:
|
|
291
|
+
workspaceId: PrismeaiAPI.CreatePage.Parameters.WorkspaceId,
|
|
292
|
+
page: PrismeaiAPI.CreatePage.RequestBody
|
|
139
293
|
): Promise<Prismeai.Page> {
|
|
140
|
-
const {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
...newPage
|
|
146
|
-
} = await this.post<PageWithMetadata>(
|
|
147
|
-
`/workspaces/${workspaceId}/pages`,
|
|
148
|
-
page
|
|
149
|
-
);
|
|
294
|
+
const { createdAt, createdBy, updatedAt, updatedBy, ...newPage } =
|
|
295
|
+
await this.post<PageWithMetadata>(
|
|
296
|
+
`/workspaces/${workspaceId}/pages`,
|
|
297
|
+
page
|
|
298
|
+
);
|
|
150
299
|
return newPage;
|
|
151
300
|
}
|
|
152
301
|
|
|
153
|
-
// Replace images as dataurl to uploaded url in any type of data
|
|
154
|
-
|
|
155
302
|
async updatePage(
|
|
156
|
-
workspaceId:
|
|
157
|
-
page:
|
|
303
|
+
workspaceId: PrismeaiAPI.UpdatePage.Parameters.WorkspaceId,
|
|
304
|
+
page: PrismeaiAPI.UpdatePage.RequestBody,
|
|
305
|
+
prevSlug: PrismeaiAPI.DeletePage.Parameters.Slug = page.slug || ''
|
|
158
306
|
): Promise<Prismeai.Page> {
|
|
159
|
-
const {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
} = await this.patch<PageWithMetadata>(
|
|
166
|
-
`/workspaces/${workspaceId}/pages/${page.id}`,
|
|
167
|
-
await this.replaceAllImagesData(page, workspaceId)
|
|
168
|
-
);
|
|
307
|
+
const { createdAt, createdBy, updatedAt, updatedBy, ...updatedPage } =
|
|
308
|
+
await this.patch<PageWithMetadata>(
|
|
309
|
+
`/workspaces/${workspaceId}/pages/${encodeURIComponent(prevSlug)}`,
|
|
310
|
+
// Replace images as dataurl to uploaded url in any type of data
|
|
311
|
+
await this.replaceAllImagesData(page, workspaceId)
|
|
312
|
+
);
|
|
169
313
|
return updatedPage;
|
|
170
314
|
}
|
|
171
315
|
|
|
172
316
|
async deletePage(
|
|
173
|
-
workspaceId:
|
|
174
|
-
|
|
175
|
-
): Promise<
|
|
176
|
-
return await this.delete(
|
|
317
|
+
workspaceId: PrismeaiAPI.DeletePage.Parameters.WorkspaceId,
|
|
318
|
+
pageSlug: PrismeaiAPI.DeletePage.Parameters.Slug
|
|
319
|
+
): Promise<PrismeaiAPI.DeletePage.Responses.$200> {
|
|
320
|
+
return await this.delete(
|
|
321
|
+
`/workspaces/${workspaceId}/pages/${encodeURIComponent(pageSlug)}`
|
|
322
|
+
);
|
|
177
323
|
}
|
|
178
324
|
|
|
179
325
|
// Events
|
|
180
|
-
streamEvents(
|
|
181
|
-
|
|
326
|
+
streamEvents(
|
|
327
|
+
workspaceId: string,
|
|
328
|
+
filters?: Record<string, any>
|
|
329
|
+
): Promise<Events> {
|
|
330
|
+
if (filters && filters['source.sessionId'] === true) {
|
|
331
|
+
if (this.sessionId) {
|
|
332
|
+
filters['source.sessionId'] = this.sessionId;
|
|
333
|
+
} else {
|
|
334
|
+
delete filters['source.sessionId'];
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const events = new Events({
|
|
338
|
+
workspaceId,
|
|
339
|
+
token: this.token || '',
|
|
340
|
+
apiKey: this._apiKey ? this._apiKey : undefined,
|
|
341
|
+
apiHost: this.host,
|
|
342
|
+
filters,
|
|
343
|
+
api: this,
|
|
344
|
+
});
|
|
182
345
|
return new Promise((resolve, reject) => {
|
|
183
|
-
events.once('
|
|
184
|
-
resolve(events);
|
|
185
|
-
});
|
|
186
|
-
events.once('connect_error', () => {
|
|
346
|
+
const off = events.once('connect_error', () => {
|
|
187
347
|
reject();
|
|
188
348
|
events.close();
|
|
189
349
|
});
|
|
350
|
+
events.once('connect', () => {
|
|
351
|
+
off();
|
|
352
|
+
resolve(events);
|
|
353
|
+
});
|
|
190
354
|
});
|
|
191
355
|
}
|
|
192
356
|
|
|
193
357
|
async getEvents(
|
|
194
358
|
workspaceId: string,
|
|
195
|
-
options:
|
|
359
|
+
options: Record<string, any> = {}
|
|
196
360
|
): Promise<Event<Date>[]> {
|
|
197
361
|
try {
|
|
198
362
|
const query = QueryString.stringify(options);
|
|
@@ -229,32 +393,89 @@ export class Api extends Fetcher {
|
|
|
229
393
|
}
|
|
230
394
|
}
|
|
231
395
|
|
|
396
|
+
async findContacts(
|
|
397
|
+
query: PrismeaiAPI.FindContacts.RequestBody
|
|
398
|
+
): Promise<PrismeaiAPI.FindContacts.Responses.$200> {
|
|
399
|
+
return await this.post(`/contacts`, query);
|
|
400
|
+
}
|
|
401
|
+
|
|
232
402
|
async getPermissions(
|
|
233
403
|
subjectType: PrismeaiAPI.GetPermissions.Parameters.SubjectType,
|
|
234
404
|
subjectId: string
|
|
235
|
-
): Promise<
|
|
236
|
-
|
|
405
|
+
): Promise<{ result: UserPermissions[] }> {
|
|
406
|
+
const permissions: PrismeaiAPI.GetPermissions.Responses.$200 =
|
|
407
|
+
await this.get(`/${subjectType}/${subjectId}/permissions`);
|
|
408
|
+
const contacts = await this.findContacts({
|
|
409
|
+
ids: permissions.result
|
|
410
|
+
.filter((cur) => cur.target.id && !cur.target.displayName)
|
|
411
|
+
.map((cur) => cur.target.id!),
|
|
412
|
+
});
|
|
413
|
+
return {
|
|
414
|
+
result: permissions.result.map((perm) => {
|
|
415
|
+
const user =
|
|
416
|
+
perm.target.id && !perm.target.displayName
|
|
417
|
+
? contacts.contacts.find((cur) => cur.id === perm.target.id)
|
|
418
|
+
: undefined;
|
|
419
|
+
const displayName =
|
|
420
|
+
perm.target.displayName || `${user?.firstName} ${user?.lastName}`;
|
|
421
|
+
return {
|
|
422
|
+
...perm,
|
|
423
|
+
target: {
|
|
424
|
+
...perm.target,
|
|
425
|
+
id: perm.target.id!,
|
|
426
|
+
displayName,
|
|
427
|
+
},
|
|
428
|
+
};
|
|
429
|
+
}),
|
|
430
|
+
};
|
|
237
431
|
}
|
|
238
432
|
|
|
239
433
|
async addPermissions(
|
|
240
434
|
subjectType: PrismeaiAPI.GetPermissions.Parameters.SubjectType,
|
|
241
435
|
subjectId: string,
|
|
242
436
|
permissions: UserPermissions
|
|
243
|
-
): Promise<
|
|
244
|
-
|
|
437
|
+
): Promise<UserPermissions> {
|
|
438
|
+
const body = { ...permissions };
|
|
439
|
+
const { email } = permissions.target;
|
|
440
|
+
|
|
441
|
+
if (email) {
|
|
442
|
+
const contacts = await this.findContacts({
|
|
443
|
+
email,
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
if (!contacts.contacts.length) {
|
|
447
|
+
throw new ApiError(
|
|
448
|
+
{
|
|
449
|
+
error: 'CollaboratorNotFound',
|
|
450
|
+
message: 'This user does not exist',
|
|
451
|
+
details: { email },
|
|
452
|
+
},
|
|
453
|
+
404
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
body.target = { id: contacts.contacts[0].id };
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const result: PrismeaiAPI.Share.Responses.$200 = await this.post(
|
|
245
460
|
`/${subjectType}/${subjectId}/permissions`,
|
|
246
|
-
|
|
461
|
+
body
|
|
247
462
|
);
|
|
463
|
+
return {
|
|
464
|
+
...result,
|
|
465
|
+
target: {
|
|
466
|
+
...result.target,
|
|
467
|
+
id: result.target.id!,
|
|
468
|
+
email,
|
|
469
|
+
},
|
|
470
|
+
};
|
|
248
471
|
}
|
|
249
472
|
|
|
250
473
|
async deletePermissions(
|
|
251
474
|
subjectType: PrismeaiAPI.GetPermissions.Parameters.SubjectType,
|
|
252
475
|
subjectId: string,
|
|
253
|
-
|
|
476
|
+
id: string
|
|
254
477
|
): Promise<PrismeaiAPI.RevokePermissions.Responses.$200> {
|
|
255
|
-
return await this.delete(
|
|
256
|
-
`/${subjectType}/${subjectId}/permissions/${userEmail}`
|
|
257
|
-
);
|
|
478
|
+
return await this.delete(`/${subjectType}/${subjectId}/permissions/${id}`);
|
|
258
479
|
}
|
|
259
480
|
|
|
260
481
|
async getApps({
|
|
@@ -271,7 +492,7 @@ export class Api extends Fetcher {
|
|
|
271
492
|
const params = new URLSearchParams(
|
|
272
493
|
removedUndefinedProperties(
|
|
273
494
|
{
|
|
274
|
-
text: `${query || ''}`,
|
|
495
|
+
text: `${encodeURIComponent(query || '')}`,
|
|
275
496
|
page: `${page || ''}`,
|
|
276
497
|
limit: `${limit || ''}`,
|
|
277
498
|
workspaceId: `${workspaceId || ''}`,
|
|
@@ -316,12 +537,6 @@ export class Api extends Fetcher {
|
|
|
316
537
|
return await this.get(`/workspaces/${workspaceId}/apps`);
|
|
317
538
|
}
|
|
318
539
|
|
|
319
|
-
async fetchImports(
|
|
320
|
-
workspaceId: PrismeaiAPI.ListAppInstances.Parameters.WorkspaceId
|
|
321
|
-
): Promise<PrismeaiAPI.ListAppInstances.Responses.$200> {
|
|
322
|
-
return await this.get(`/workspaces/${workspaceId}/apps`);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
540
|
async getAppConfig<T>(
|
|
326
541
|
workspaceId: PrismeaiAPI.GetAppInstanceConfig.Parameters.WorkspaceId,
|
|
327
542
|
slug: PrismeaiAPI.GetAppInstanceConfig.Parameters.Slug
|
|
@@ -344,6 +559,25 @@ export class Api extends Fetcher {
|
|
|
344
559
|
return config;
|
|
345
560
|
}
|
|
346
561
|
|
|
562
|
+
async getAppInstance(
|
|
563
|
+
workspaceId: string,
|
|
564
|
+
slug: string
|
|
565
|
+
): Promise<PrismeaiAPI.GetAppInstance.Responses.$200> {
|
|
566
|
+
return this.get(`/workspaces/${workspaceId}/apps/${slug}`);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
async saveAppInstance(
|
|
570
|
+
workspaceId: PrismeaiAPI.ConfigureAppInstance.Parameters.WorkspaceId,
|
|
571
|
+
slug: PrismeaiAPI.ConfigureAppInstance.Parameters.Slug,
|
|
572
|
+
appInstance: PrismeaiAPI.ConfigureAppInstance.RequestBody
|
|
573
|
+
): Promise<PrismeaiAPI.ConfigureAppInstance.Responses.$200> {
|
|
574
|
+
const response = await this.patch<Prismeai.DetailedAppInstance>(
|
|
575
|
+
`/workspaces/${workspaceId}/apps/${slug}`,
|
|
576
|
+
{ ...appInstance }
|
|
577
|
+
);
|
|
578
|
+
return response;
|
|
579
|
+
}
|
|
580
|
+
|
|
347
581
|
async uploadFiles(files: string | string[], workspaceId: string) {
|
|
348
582
|
function dataURItoBlob(dataURI: string): [Blob, string] {
|
|
349
583
|
// convert base64/URLEncoded data component to raw binary data held in a string
|
|
@@ -351,7 +585,6 @@ export class Api extends Fetcher {
|
|
|
351
585
|
if (dataURI.split(',')[0].indexOf('base64') >= 0)
|
|
352
586
|
byteString = atob(dataURI.split(',')[1]);
|
|
353
587
|
else byteString = unescape(dataURI.split(',')[1]);
|
|
354
|
-
|
|
355
588
|
// separate out the mime component
|
|
356
589
|
const metadata = dataURI
|
|
357
590
|
.split(';')
|
|
@@ -372,9 +605,10 @@ export class Api extends Fetcher {
|
|
|
372
605
|
}
|
|
373
606
|
const formData = new FormData();
|
|
374
607
|
(Array.isArray(files) ? files : [files]).forEach((file) => {
|
|
375
|
-
|
|
608
|
+
try {
|
|
609
|
+
formData.append('file', ...dataURItoBlob(file));
|
|
610
|
+
} catch {}
|
|
376
611
|
});
|
|
377
|
-
|
|
378
612
|
try {
|
|
379
613
|
return await this._fetch<PrismeaiAPI.UploadFile.Responses.$200>(
|
|
380
614
|
`/workspaces/${workspaceId}/files`,
|
|
@@ -431,8 +665,45 @@ export class Api extends Fetcher {
|
|
|
431
665
|
return replaced;
|
|
432
666
|
}
|
|
433
667
|
|
|
434
|
-
async callAutomation(
|
|
435
|
-
|
|
668
|
+
async callAutomation(
|
|
669
|
+
workspaceId: string,
|
|
670
|
+
automation: string,
|
|
671
|
+
params?: any
|
|
672
|
+
): Promise<any> {
|
|
673
|
+
return this.post(
|
|
674
|
+
`/workspaces/${workspaceId}/webhooks/${automation}`,
|
|
675
|
+
params
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
async getWorkspaceUsage(
|
|
680
|
+
workspaceId: PrismeaiAPI.WorkspaceUsage.Parameters.WorkspaceId,
|
|
681
|
+
{
|
|
682
|
+
afterDate,
|
|
683
|
+
beforeDate,
|
|
684
|
+
details,
|
|
685
|
+
}: {
|
|
686
|
+
afterDate?: PrismeaiAPI.WorkspaceUsage.Parameters.AfterDate;
|
|
687
|
+
beforeDate?: PrismeaiAPI.WorkspaceUsage.Parameters.BeforeDate;
|
|
688
|
+
details?: PrismeaiAPI.WorkspaceUsage.Parameters.Details;
|
|
689
|
+
} = {}
|
|
690
|
+
): Promise<PrismeaiAPI.WorkspaceUsage.Responses.$200> {
|
|
691
|
+
const params = new URLSearchParams(
|
|
692
|
+
removedUndefinedProperties(
|
|
693
|
+
{
|
|
694
|
+
afterDate: `${afterDate || ''}`,
|
|
695
|
+
beforeDate: `${beforeDate || ''}`,
|
|
696
|
+
details: `${details || ''}`,
|
|
697
|
+
},
|
|
698
|
+
true
|
|
699
|
+
)
|
|
700
|
+
);
|
|
701
|
+
|
|
702
|
+
return this.get(`/workspaces/${workspaceId}/usage?${params.toString()}`);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
workspaces(id: string) {
|
|
706
|
+
return new WorkspacesEndpoint(id, this);
|
|
436
707
|
}
|
|
437
708
|
}
|
|
438
709
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Api } from '../api';
|
|
2
|
+
import WorkspacesVersionsEndpoint from './workspacesVersions';
|
|
3
|
+
|
|
4
|
+
export class WorkspacesEndpoint {
|
|
5
|
+
private id: string;
|
|
6
|
+
private api: Api;
|
|
7
|
+
|
|
8
|
+
constructor(id: string, api: Api) {
|
|
9
|
+
this.id = id;
|
|
10
|
+
this.api = api;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get versions() {
|
|
14
|
+
return new WorkspacesVersionsEndpoint(this.id, this.api);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default WorkspacesEndpoint;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Api } from '../api';
|
|
2
|
+
|
|
3
|
+
export class WorkspacesVersionsEndpoint {
|
|
4
|
+
private workspaceId: string;
|
|
5
|
+
private api: Api;
|
|
6
|
+
|
|
7
|
+
constructor(workspaceId: string, api: Api) {
|
|
8
|
+
this.workspaceId = workspaceId;
|
|
9
|
+
this.api = api;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
create(version?: PrismeaiAPI.PublishWorkspaceVersion.RequestBody) {
|
|
13
|
+
this.api.post(`/workspaces/${this.workspaceId}/versions`, version);
|
|
14
|
+
}
|
|
15
|
+
rollback(
|
|
16
|
+
versionId: PrismeaiAPI.RollbackWorkspaceVersion.PathParameters['versionId']
|
|
17
|
+
) {
|
|
18
|
+
this.api.post(
|
|
19
|
+
`/workspaces/${this.workspaceId}/versions/${versionId}/rollback`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async export(version: PrismeaiAPI.ExportWorkspaceVersion.Parameters.VersionId = 'current') {
|
|
24
|
+
const res = await this.api.prepareRequest(
|
|
25
|
+
`/workspaces/${this.workspaceId}/versions/${version}/export`, {
|
|
26
|
+
method: 'post'
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
return new Blob([await res.arrayBuffer()], { type: 'application/zip' });
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default WorkspacesVersionsEndpoint;
|