@prisme.ai/sdk 1.0.0 → 1.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.
- package/Readme.md +3 -1
- package/dist/lib/api.d.ts +71 -27
- package/dist/lib/endpoints/users.d.ts +9 -0
- package/dist/lib/events.d.ts +3 -1
- package/dist/lib/fetcher.d.ts +9 -2
- package/dist/sdk/lib/api.js +177 -53
- package/dist/sdk/lib/endpoints/users.js +43 -0
- package/dist/sdk/lib/events.js +19 -8
- package/dist/sdk/lib/fetcher.js +28 -10
- package/lib/api.test.ts +76 -61
- package/lib/api.ts +227 -66
- package/lib/endpoints/users.ts +22 -0
- package/lib/events.test.ts +2 -2
- package/lib/events.ts +7 -3
- package/lib/fetcher.ts +40 -10
- package/package.json +2 -1
package/Readme.md
CHANGED
|
@@ -16,7 +16,9 @@ You can set a different host by instantiating the Api class:
|
|
|
16
16
|
|
|
17
17
|
```
|
|
18
18
|
import { Api } from '@prisme.ai/sdk';
|
|
19
|
-
const api = new Api(
|
|
19
|
+
const api = new Api({
|
|
20
|
+
host: 'https://my.custom.host'
|
|
21
|
+
})
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
You are able to call un authentified methods like signin or signup, but you'll need a valid token to call the other. Just set its property:
|
package/dist/lib/api.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import Fetcher from './fetcher';
|
|
1
|
+
import Fetcher, { Fetched } from './fetcher';
|
|
2
2
|
import { Event, Workspace } from './types';
|
|
3
3
|
import { Events } from './events';
|
|
4
4
|
import WorkspacesEndpoint from './endpoints/workspaces';
|
|
5
|
+
import UsersEndpoint from './endpoints/users';
|
|
5
6
|
export type UserPermissions = {
|
|
6
7
|
permissions: Prismeai.UserPermissions['permissions'];
|
|
7
8
|
target: {
|
|
@@ -12,21 +13,57 @@ export type UserPermissions = {
|
|
|
12
13
|
displayName?: string;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
16
|
+
export interface ApiOptions {
|
|
17
|
+
host: string;
|
|
18
|
+
oidc?: {
|
|
19
|
+
url: string;
|
|
20
|
+
clientId: string;
|
|
21
|
+
clientIdHeader?: string;
|
|
22
|
+
redirectUri: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface AccessToken {
|
|
26
|
+
access_token: string;
|
|
27
|
+
id_token: string;
|
|
28
|
+
scope: string;
|
|
29
|
+
expiresIn: number;
|
|
30
|
+
token_type: 'Bearer';
|
|
31
|
+
}
|
|
32
|
+
export interface InteractiveSignin {
|
|
33
|
+
interaction: string;
|
|
34
|
+
login: string;
|
|
35
|
+
password: string;
|
|
36
|
+
remember?: boolean;
|
|
37
|
+
}
|
|
15
38
|
export declare class Api extends Fetcher {
|
|
39
|
+
opts: Required<ApiOptions>;
|
|
16
40
|
private sessionId?;
|
|
17
41
|
private _user?;
|
|
18
|
-
|
|
42
|
+
constructor(opts: ApiOptions);
|
|
43
|
+
get user(): (Prismeai.User & {
|
|
44
|
+
sessionId?: string | undefined;
|
|
45
|
+
}) | undefined;
|
|
19
46
|
me(): Promise<any>;
|
|
20
|
-
|
|
21
|
-
|
|
47
|
+
clientId(): string;
|
|
48
|
+
getAuthorizationURL(overrideRedirectUri?: string, authParams?: {
|
|
49
|
+
max_age?: string;
|
|
50
|
+
acr_values?: string;
|
|
51
|
+
}, locale?: string | undefined): Promise<{
|
|
52
|
+
url: string;
|
|
53
|
+
codeVerifier: string;
|
|
54
|
+
clientId: string;
|
|
55
|
+
}>;
|
|
56
|
+
signin(body: InteractiveSignin): Promise<{
|
|
57
|
+
redirectTo: string;
|
|
22
58
|
}>;
|
|
59
|
+
getToken(authorizationCode: string, codeVerifier: string, overrideRedirectUri?: string): Promise<AccessToken>;
|
|
23
60
|
createAnonymousSession(): Promise<Prismeai.User & {
|
|
24
61
|
token: string;
|
|
25
62
|
}>;
|
|
26
63
|
signup(email: string, password: string, firstName: string, lastName: string, language: string): Promise<Prismeai.User & {
|
|
27
64
|
token: string;
|
|
28
65
|
}>;
|
|
29
|
-
|
|
66
|
+
getSignoutURL(redirectUri?: string): string;
|
|
30
67
|
sendValidationMail(email: string, language: string): Promise<unknown>;
|
|
31
68
|
validateMail(token: string): Promise<unknown>;
|
|
32
69
|
sendPasswordResetMail(email: string, language: string): Promise<unknown>;
|
|
@@ -34,30 +71,30 @@ export declare class Api extends Fetcher {
|
|
|
34
71
|
getWorkspaces(): Promise<Workspace[]>;
|
|
35
72
|
getWorkspace(id: string): Promise<PrismeaiAPI.GetWorkspace.Responses.$200>;
|
|
36
73
|
getWorkspaceSecurity(id: string): Promise<PrismeaiAPI.GetSecurity.Responses.$200>;
|
|
37
|
-
updateWorkspaceSecurity(workspaceId: string, security: Prismeai.WorkspaceSecurity): Promise<PrismeaiAPI.UpdateSecurity.Responses.$200
|
|
38
|
-
getWorkspaceRoles(id: string): Promise<PrismeaiAPI.GetRoles.Responses.$200
|
|
74
|
+
updateWorkspaceSecurity(workspaceId: string, security: Prismeai.WorkspaceSecurity): Promise<Fetched<PrismeaiAPI.UpdateSecurity.Responses.$200>>;
|
|
75
|
+
getWorkspaceRoles(id: string): Promise<Fetched<PrismeaiAPI.GetRoles.Responses.$200>>;
|
|
39
76
|
createWorkspace(name: string): Promise<Workspace>;
|
|
40
77
|
duplicateWorkspace({ id }: {
|
|
41
78
|
id: string;
|
|
42
79
|
}): Promise<Workspace | null>;
|
|
43
|
-
updateWorkspace(workspace: Prismeai.DSULPatch): Promise<PrismeaiAPI.UpdateWorkspace.Responses.$200 | null>;
|
|
80
|
+
updateWorkspace(workspace: Prismeai.DSULPatch): Promise<Fetched<PrismeaiAPI.UpdateWorkspace.Responses.$200> | null>;
|
|
44
81
|
deleteWorkspace(workspaceId: Workspace['id']): Promise<Workspace>;
|
|
45
82
|
generateApiKey(workspaceId: Workspace['id'], events: string[], uploads?: string[]): Promise<string>;
|
|
46
83
|
updateApiKey(workspaceId: Workspace['id'], apiKey: string, events: string[], uploads?: string[]): Promise<string>;
|
|
47
|
-
getAutomation(workspaceId: string, automationSlug: string): Promise<PrismeaiAPI.GetAutomation.Responses.$200
|
|
48
|
-
createAutomation(workspaceId: Workspace['id'], automation: Prismeai.Automation): Promise<Prismeai.Automation & {
|
|
84
|
+
getAutomation(workspaceId: string, automationSlug: string): Promise<Fetched<PrismeaiAPI.GetAutomation.Responses.$200>>;
|
|
85
|
+
createAutomation(workspaceId: Workspace['id'], automation: Prismeai.Automation): Promise<Fetched<Prismeai.Automation & {
|
|
49
86
|
slug: string;
|
|
50
|
-
}
|
|
51
|
-
updateAutomation(workspaceId: string, slug: string, automation: Prismeai.Automation): Promise<Prismeai.Automation & {
|
|
87
|
+
}>>;
|
|
88
|
+
updateAutomation(workspaceId: string, slug: string, automation: Prismeai.Automation): Promise<Fetched<Prismeai.Automation & {
|
|
52
89
|
slug: string;
|
|
53
|
-
}
|
|
90
|
+
}>>;
|
|
54
91
|
deleteAutomation(workspaceId: string, slug: string): Promise<string>;
|
|
55
92
|
getPages(workspaceId: NonNullable<Workspace['id']>): Promise<Prismeai.Page[]>;
|
|
56
|
-
getPage(workspaceId: PrismeaiAPI.GetPage.Parameters.WorkspaceId, pageSlug: PrismeaiAPI.GetPage.Parameters.Slug): Promise<Prismeai.DetailedPage
|
|
57
|
-
getPageBySlug(workspaceSlug: PrismeaiAPI.GetPageBySlug.Parameters.WorkspaceSlug, pageSlug: PrismeaiAPI.GetPageBySlug.Parameters.PageSlug): Promise<Prismeai.DetailedPage
|
|
93
|
+
getPage(workspaceId: PrismeaiAPI.GetPage.Parameters.WorkspaceId, pageSlug: PrismeaiAPI.GetPage.Parameters.Slug): Promise<Fetched<Prismeai.DetailedPage>>;
|
|
94
|
+
getPageBySlug(workspaceSlug: PrismeaiAPI.GetPageBySlug.Parameters.WorkspaceSlug, pageSlug: PrismeaiAPI.GetPageBySlug.Parameters.PageSlug): Promise<Fetched<Prismeai.DetailedPage>>;
|
|
58
95
|
createPage(workspaceId: PrismeaiAPI.CreatePage.Parameters.WorkspaceId, page: PrismeaiAPI.CreatePage.RequestBody): Promise<Prismeai.Page>;
|
|
59
96
|
updatePage(workspaceId: PrismeaiAPI.UpdatePage.Parameters.WorkspaceId, page: PrismeaiAPI.UpdatePage.RequestBody, prevSlug?: PrismeaiAPI.DeletePage.Parameters.Slug): Promise<Prismeai.Page>;
|
|
60
|
-
deletePage(workspaceId: PrismeaiAPI.DeletePage.Parameters.WorkspaceId, pageSlug: PrismeaiAPI.DeletePage.Parameters.Slug): Promise<PrismeaiAPI.DeletePage.Responses.$200
|
|
97
|
+
deletePage(workspaceId: PrismeaiAPI.DeletePage.Parameters.WorkspaceId, pageSlug: PrismeaiAPI.DeletePage.Parameters.Slug): Promise<Fetched<PrismeaiAPI.DeletePage.Responses.$200>>;
|
|
61
98
|
streamEvents(workspaceId: string, filters?: Record<string, any>): Promise<Events>;
|
|
62
99
|
getEvents(workspaceId: string, options?: Record<string, any>): Promise<Event<Date>[]>;
|
|
63
100
|
postEvents(workspaceId: PrismeaiAPI.SendWorkspaceEvent.Parameters.WorkspaceId, events: PrismeaiAPI.SendWorkspaceEvent.RequestBody['events']): Promise<boolean>;
|
|
@@ -66,30 +103,37 @@ export declare class Api extends Fetcher {
|
|
|
66
103
|
result: UserPermissions[];
|
|
67
104
|
}>;
|
|
68
105
|
addPermissions(subjectType: PrismeaiAPI.GetPermissions.Parameters.SubjectType, subjectId: string, permissions: UserPermissions): Promise<UserPermissions>;
|
|
69
|
-
deletePermissions(subjectType: PrismeaiAPI.GetPermissions.Parameters.SubjectType, subjectId: string, id: string): Promise<PrismeaiAPI.RevokePermissions.Responses.$200
|
|
106
|
+
deletePermissions(subjectType: PrismeaiAPI.GetPermissions.Parameters.SubjectType, subjectId: string, id: string): Promise<Fetched<PrismeaiAPI.RevokePermissions.Responses.$200>>;
|
|
70
107
|
getApps({ query, page, limit, workspaceId, }: {
|
|
71
108
|
query?: PrismeaiAPI.SearchApps.QueryParameters['text'];
|
|
72
109
|
page?: PrismeaiAPI.SearchApps.QueryParameters['page'];
|
|
73
110
|
limit?: PrismeaiAPI.SearchApps.QueryParameters['limit'];
|
|
74
111
|
workspaceId?: PrismeaiAPI.SearchApps.QueryParameters['workspaceId'];
|
|
75
|
-
}): Promise<PrismeaiAPI.SearchApps.Responses.$200
|
|
76
|
-
installApp(workspaceId: PrismeaiAPI.InstallAppInstance.PathParameters['workspaceId'], body: PrismeaiAPI.InstallAppInstance.RequestBody): Promise<PrismeaiAPI.InstallAppInstance.Responses.$200
|
|
77
|
-
updateApp(workspaceId: PrismeaiAPI.ConfigureAppInstance.PathParameters['workspaceId'], slug: PrismeaiAPI.ConfigureAppInstance.PathParameters['slug'], body: PrismeaiAPI.ConfigureAppInstance.RequestBody): Promise<PrismeaiAPI.ConfigureAppInstance.Responses.$200
|
|
78
|
-
uninstallApp(workspaceId: PrismeaiAPI.UninstallAppInstance.PathParameters['workspaceId'], slug: PrismeaiAPI.ConfigureAppInstance.PathParameters['slug']): Promise<PrismeaiAPI.UninstallAppInstance.Responses.$200
|
|
79
|
-
publishApp(body: PrismeaiAPI.PublishApp.RequestBody): Promise<PrismeaiAPI.PublishApp.Responses.$200
|
|
80
|
-
listAppInstances(workspaceId: PrismeaiAPI.ListAppInstances.PathParameters['workspaceId']): Promise<PrismeaiAPI.ListAppInstances.Responses.$200
|
|
112
|
+
}): Promise<Fetched<PrismeaiAPI.SearchApps.Responses.$200>>;
|
|
113
|
+
installApp(workspaceId: PrismeaiAPI.InstallAppInstance.PathParameters['workspaceId'], body: PrismeaiAPI.InstallAppInstance.RequestBody): Promise<Fetched<PrismeaiAPI.InstallAppInstance.Responses.$200>>;
|
|
114
|
+
updateApp(workspaceId: PrismeaiAPI.ConfigureAppInstance.PathParameters['workspaceId'], slug: PrismeaiAPI.ConfigureAppInstance.PathParameters['slug'], body: PrismeaiAPI.ConfigureAppInstance.RequestBody): Promise<Fetched<PrismeaiAPI.ConfigureAppInstance.Responses.$200>>;
|
|
115
|
+
uninstallApp(workspaceId: PrismeaiAPI.UninstallAppInstance.PathParameters['workspaceId'], slug: PrismeaiAPI.ConfigureAppInstance.PathParameters['slug']): Promise<Fetched<PrismeaiAPI.UninstallAppInstance.Responses.$200>>;
|
|
116
|
+
publishApp(body: PrismeaiAPI.PublishApp.RequestBody): Promise<Fetched<PrismeaiAPI.PublishApp.Responses.$200>>;
|
|
117
|
+
listAppInstances(workspaceId: PrismeaiAPI.ListAppInstances.PathParameters['workspaceId']): Promise<Fetched<PrismeaiAPI.ListAppInstances.Responses.$200>>;
|
|
81
118
|
getAppConfig<T>(workspaceId: PrismeaiAPI.GetAppInstanceConfig.Parameters.WorkspaceId, slug: PrismeaiAPI.GetAppInstanceConfig.Parameters.Slug): Promise<T>;
|
|
82
119
|
updateAppConfig(workspaceId: PrismeaiAPI.UpdateAppInstanceConfig.Parameters.WorkspaceId, slug: PrismeaiAPI.UpdateAppInstanceConfig.Parameters.Slug, config: any): Promise<PrismeaiAPI.UpdateAppInstanceConfig.Responses.$200['config']>;
|
|
83
|
-
getAppInstance(workspaceId: string, slug: string): Promise<PrismeaiAPI.GetAppInstance.Responses.$200
|
|
84
|
-
saveAppInstance(workspaceId: PrismeaiAPI.ConfigureAppInstance.Parameters.WorkspaceId, slug: PrismeaiAPI.ConfigureAppInstance.Parameters.Slug, appInstance: PrismeaiAPI.ConfigureAppInstance.RequestBody): Promise<PrismeaiAPI.ConfigureAppInstance.Responses.$200
|
|
120
|
+
getAppInstance(workspaceId: string, slug: string): Promise<Fetched<PrismeaiAPI.GetAppInstance.Responses.$200>>;
|
|
121
|
+
saveAppInstance(workspaceId: PrismeaiAPI.ConfigureAppInstance.Parameters.WorkspaceId, slug: PrismeaiAPI.ConfigureAppInstance.Parameters.Slug, appInstance: PrismeaiAPI.ConfigureAppInstance.RequestBody): Promise<Fetched<PrismeaiAPI.ConfigureAppInstance.Responses.$200>>;
|
|
85
122
|
uploadFiles(files: string | string[], workspaceId: string): Promise<PrismeaiAPI.UploadFile.Responses.$200>;
|
|
86
123
|
replaceAllImagesData(original: any, workspaceId: string): Promise<any>;
|
|
87
|
-
callAutomation(workspaceId: string, automation: string, params?: any): Promise<any
|
|
124
|
+
callAutomation(workspaceId: string, automation: string, params?: any): Promise<Fetched<any>>;
|
|
125
|
+
testAutomation({ workspaceId, automation, payload, }: {
|
|
126
|
+
workspaceId: string;
|
|
127
|
+
automation: string;
|
|
128
|
+
payload?: Record<string, any>;
|
|
129
|
+
}): Promise<Fetched<any>>;
|
|
88
130
|
getWorkspaceUsage(workspaceId: PrismeaiAPI.WorkspaceUsage.Parameters.WorkspaceId, { afterDate, beforeDate, details, }?: {
|
|
89
131
|
afterDate?: PrismeaiAPI.WorkspaceUsage.Parameters.AfterDate;
|
|
90
132
|
beforeDate?: PrismeaiAPI.WorkspaceUsage.Parameters.BeforeDate;
|
|
91
133
|
details?: PrismeaiAPI.WorkspaceUsage.Parameters.Details;
|
|
92
|
-
}): Promise<PrismeaiAPI.WorkspaceUsage.Responses.$200
|
|
134
|
+
}): Promise<Fetched<PrismeaiAPI.WorkspaceUsage.Responses.$200>>;
|
|
135
|
+
importArchive(archive: File): Promise<PrismeaiAPI.ImportNewWorkspace.Responses.$200>;
|
|
136
|
+
users(id?: string): UsersEndpoint;
|
|
93
137
|
workspaces(id: string): WorkspacesEndpoint;
|
|
94
138
|
}
|
|
95
139
|
declare const _default: Api;
|
package/dist/lib/events.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ export declare class Events {
|
|
|
12
12
|
private filters;
|
|
13
13
|
private listenedUserTopics;
|
|
14
14
|
private listeners;
|
|
15
|
-
|
|
15
|
+
private lastReceivedEventDate;
|
|
16
|
+
constructor({ workspaceId, token, legacyToken, apiKey, apiHost, filters, api, }: {
|
|
16
17
|
workspaceId: string;
|
|
17
18
|
token: string;
|
|
19
|
+
legacyToken?: string;
|
|
18
20
|
apiKey?: string;
|
|
19
21
|
apiHost?: string;
|
|
20
22
|
filters?: Record<string, any>;
|
package/dist/lib/fetcher.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
export type Fetched<T> = T & {
|
|
2
|
+
headers?: Record<string, any>;
|
|
3
|
+
};
|
|
1
4
|
export declare class Fetcher {
|
|
2
5
|
host: string;
|
|
3
6
|
token: string | null;
|
|
7
|
+
legacyToken: string | null;
|
|
8
|
+
overwriteClientId?: string;
|
|
9
|
+
private clientIdHeader?;
|
|
4
10
|
protected _apiKey: string | null;
|
|
5
11
|
language: string | undefined;
|
|
6
|
-
|
|
12
|
+
lastReceivedHeaders?: Record<string, any>;
|
|
13
|
+
constructor(host: string, clientIdHeader?: string);
|
|
7
14
|
set apiKey(apiKey: string);
|
|
8
15
|
prepareRequest(url: string, options?: RequestInit): Promise<Response>;
|
|
9
16
|
protected _fetch<T>(url: string, options?: RequestInit): Promise<T>;
|
|
10
17
|
get<T = any>(url: string): Promise<T>;
|
|
11
|
-
post<T>(url: string, body?: Record<string, any
|
|
18
|
+
post<T>(url: string, body?: Record<string, any>, opts?: RequestInit): Promise<T>;
|
|
12
19
|
put<T>(url: string, body: Record<string, any>): Promise<T>;
|
|
13
20
|
patch<T>(url: string, body: Record<string, any>): Promise<T>;
|
|
14
21
|
delete<T>(url: string): Promise<T>;
|
package/dist/sdk/lib/api.js
CHANGED
|
@@ -4,20 +4,55 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _tslib = require('../../_virtual/_tslib.js');
|
|
6
6
|
var QueryString = require('qs');
|
|
7
|
+
var pkceChallenge = require('pkce-challenge');
|
|
7
8
|
var fetcher = require('./fetcher.js');
|
|
8
9
|
var events = require('./events.js');
|
|
9
10
|
var utils = require('./utils.js');
|
|
10
11
|
var workspaces = require('./endpoints/workspaces.js');
|
|
11
12
|
var ApiError = require('./ApiError.js');
|
|
13
|
+
var users = require('./endpoints/users.js');
|
|
12
14
|
|
|
13
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
16
|
|
|
15
17
|
var QueryString__default = /*#__PURE__*/_interopDefaultLegacy(QueryString);
|
|
18
|
+
var pkceChallenge__default = /*#__PURE__*/_interopDefaultLegacy(pkceChallenge);
|
|
16
19
|
|
|
20
|
+
function dataURItoBlob(dataURI) {
|
|
21
|
+
// convert base64/URLEncoded data component to raw binary data held in a string
|
|
22
|
+
var byteString;
|
|
23
|
+
if (dataURI.split(',')[0].indexOf('base64') >= 0)
|
|
24
|
+
byteString = atob(dataURI.split(',')[1]);
|
|
25
|
+
else
|
|
26
|
+
byteString = unescape(dataURI.split(',')[1]);
|
|
27
|
+
// separate out the mime component
|
|
28
|
+
var metadata = dataURI
|
|
29
|
+
.split(';')
|
|
30
|
+
.filter(function (v, k, all) { return k < all.length - 1; })
|
|
31
|
+
.map(function (v) { return v.split(/:/); });
|
|
32
|
+
var _a = metadata.find(function (_a) {
|
|
33
|
+
var k = _a[0]; _a[1];
|
|
34
|
+
return k === 'data';
|
|
35
|
+
}) || [], _b = _a[1], mimeString = _b === void 0 ? '' : _b;
|
|
36
|
+
var _c = mimeString.split(/\//), ext = _c[1];
|
|
37
|
+
var _d = metadata.find(function (_a) {
|
|
38
|
+
var k = _a[0]; _a[1];
|
|
39
|
+
return k === 'filename';
|
|
40
|
+
}) || [], _e = _d[1], fileName = _e === void 0 ? "file.".concat(ext) : _e;
|
|
41
|
+
// write the bytes of the string to a typed array
|
|
42
|
+
var ia = new Uint8Array(byteString.length);
|
|
43
|
+
for (var i = 0; i < byteString.length; i++) {
|
|
44
|
+
ia[i] = byteString.charCodeAt(i);
|
|
45
|
+
}
|
|
46
|
+
return [new Blob([ia], { type: mimeString }), fileName];
|
|
47
|
+
}
|
|
17
48
|
var Api = /** @class */ (function (_super) {
|
|
18
49
|
_tslib.__extends(Api, _super);
|
|
19
|
-
function Api() {
|
|
20
|
-
|
|
50
|
+
function Api(opts) {
|
|
51
|
+
var _this = this;
|
|
52
|
+
var _a;
|
|
53
|
+
_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;
|
|
54
|
+
_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) });
|
|
55
|
+
return _this;
|
|
21
56
|
}
|
|
22
57
|
Object.defineProperty(Api.prototype, "user", {
|
|
23
58
|
get: function () {
|
|
@@ -41,19 +76,86 @@ var Api = /** @class */ (function (_super) {
|
|
|
41
76
|
});
|
|
42
77
|
});
|
|
43
78
|
};
|
|
44
|
-
Api.prototype.
|
|
79
|
+
Api.prototype.clientId = function () {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
return this.overwriteClientId || ((_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.oidc) === null || _b === void 0 ? void 0 : _b.clientId);
|
|
82
|
+
};
|
|
83
|
+
Api.prototype.getAuthorizationURL = function (overrideRedirectUri, authParams, locale) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
if (locale === void 0) { locale = ((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.language)
|
|
86
|
+
? window.navigator.language.substring(0, 2)
|
|
87
|
+
: undefined; }
|
|
45
88
|
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
46
|
-
var
|
|
89
|
+
var url, clientId, _c, codeVerifier, codeChallenge;
|
|
90
|
+
return _tslib.__generator(this, function (_d) {
|
|
91
|
+
switch (_d.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
url = new URL('/oidc/auth', this.opts.oidc.url);
|
|
94
|
+
url.searchParams.set('response_type', 'code');
|
|
95
|
+
url.searchParams.set('response_mode', 'query'); // Send the final authorization code as a query param to the redirect uri
|
|
96
|
+
url.searchParams.set('redirect_uri', overrideRedirectUri || ((_b = this.opts.oidc) === null || _b === void 0 ? void 0 : _b.redirectUri) || '');
|
|
97
|
+
url.searchParams.set('scope', 'openid profile email settings offline_access events:write events:read webhooks pages:read files:write files:read');
|
|
98
|
+
clientId = this.clientId();
|
|
99
|
+
url.searchParams.set('client_id', clientId);
|
|
100
|
+
url.searchParams.set('code_challenge_method', 'S256');
|
|
101
|
+
return [4 /*yield*/, pkceChallenge__default["default"](64)];
|
|
102
|
+
case 1:
|
|
103
|
+
_c = _d.sent(), codeVerifier = _c.code_verifier, codeChallenge = _c.code_challenge;
|
|
104
|
+
url.searchParams.set('code_challenge', codeChallenge);
|
|
105
|
+
if (locale) {
|
|
106
|
+
url.searchParams.set('locale', locale);
|
|
107
|
+
}
|
|
108
|
+
Object.entries(authParams || {}).forEach(function (_a) {
|
|
109
|
+
var k = _a[0], v = _a[1];
|
|
110
|
+
url.searchParams.set(k, v);
|
|
111
|
+
});
|
|
112
|
+
return [2 /*return*/, {
|
|
113
|
+
url: url.toString(),
|
|
114
|
+
codeVerifier: codeVerifier,
|
|
115
|
+
clientId: clientId,
|
|
116
|
+
}];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
Api.prototype.signin = function (body) {
|
|
122
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
123
|
+
var url, redirectTo;
|
|
47
124
|
return _tslib.__generator(this, function (_a) {
|
|
48
125
|
switch (_a.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
126
|
+
case 0:
|
|
127
|
+
url = new URL("/oidc/interaction/".concat(body.interaction, "/login"), this.opts.oidc.url);
|
|
128
|
+
// Do not follow redirects as we need to get redirected from browser itself to save final token in local storage
|
|
129
|
+
return [4 /*yield*/, this.post(url.toString(), new URLSearchParams(body), {
|
|
130
|
+
redirect: 'manual',
|
|
131
|
+
})];
|
|
53
132
|
case 1:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
133
|
+
// Do not follow redirects as we need to get redirected from browser itself to save final token in local storage
|
|
134
|
+
_a.sent();
|
|
135
|
+
redirectTo = new URL("/oidc/auth/".concat(body.interaction), this.opts.oidc.url);
|
|
136
|
+
return [2 /*return*/, { redirectTo: redirectTo.toString() }];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
Api.prototype.getToken = function (authorizationCode, codeVerifier, overrideRedirectUri) {
|
|
142
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
143
|
+
var url, token;
|
|
144
|
+
return _tslib.__generator(this, function (_a) {
|
|
145
|
+
switch (_a.label) {
|
|
146
|
+
case 0:
|
|
147
|
+
this.token = null;
|
|
148
|
+
url = new URL('/oidc/token', this.opts.oidc.url);
|
|
149
|
+
return [4 /*yield*/, this.post(url.toString(), new URLSearchParams({
|
|
150
|
+
grant_type: 'authorization_code',
|
|
151
|
+
code: authorizationCode,
|
|
152
|
+
code_verifier: codeVerifier,
|
|
153
|
+
client_id: this.clientId(),
|
|
154
|
+
redirect_uri: overrideRedirectUri || this.opts.oidc.redirectUri,
|
|
155
|
+
}))];
|
|
156
|
+
case 1:
|
|
157
|
+
token = _a.sent();
|
|
158
|
+
return [2 /*return*/, token];
|
|
57
159
|
}
|
|
58
160
|
});
|
|
59
161
|
});
|
|
@@ -63,7 +165,9 @@ var Api = /** @class */ (function (_super) {
|
|
|
63
165
|
var user;
|
|
64
166
|
return _tslib.__generator(this, function (_a) {
|
|
65
167
|
switch (_a.label) {
|
|
66
|
-
case 0: return [4 /*yield*/, this.post('/login/anonymous'
|
|
168
|
+
case 0: return [4 /*yield*/, this.post('/login/anonymous', {}, {
|
|
169
|
+
credentials: 'omit',
|
|
170
|
+
})];
|
|
67
171
|
case 1:
|
|
68
172
|
user = _a.sent();
|
|
69
173
|
this._user = user;
|
|
@@ -88,18 +192,14 @@ var Api = /** @class */ (function (_super) {
|
|
|
88
192
|
});
|
|
89
193
|
});
|
|
90
194
|
};
|
|
91
|
-
Api.prototype.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return [2 /*return*/];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
195
|
+
Api.prototype.getSignoutURL = function (redirectUri) {
|
|
196
|
+
var params = new URLSearchParams();
|
|
197
|
+
params.set('client_id', this.clientId());
|
|
198
|
+
if (redirectUri) {
|
|
199
|
+
params.set('post_logout_redirect_uri', redirectUri);
|
|
200
|
+
}
|
|
201
|
+
var url = new URL("/oidc/session/end?".concat(params.toString()), this.opts.oidc.url);
|
|
202
|
+
return url.toString();
|
|
103
203
|
};
|
|
104
204
|
// Mail validation
|
|
105
205
|
Api.prototype.sendValidationMail = function (email, language) {
|
|
@@ -441,6 +541,7 @@ var Api = /** @class */ (function (_super) {
|
|
|
441
541
|
var events$1 = new events.Events({
|
|
442
542
|
workspaceId: workspaceId,
|
|
443
543
|
token: this.token || '',
|
|
544
|
+
legacyToken: this.legacyToken || '',
|
|
444
545
|
apiKey: this._apiKey ? this._apiKey : undefined,
|
|
445
546
|
apiHost: this.host,
|
|
446
547
|
filters: filters,
|
|
@@ -696,34 +797,6 @@ var Api = /** @class */ (function (_super) {
|
|
|
696
797
|
};
|
|
697
798
|
Api.prototype.uploadFiles = function (files, workspaceId) {
|
|
698
799
|
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
699
|
-
function dataURItoBlob(dataURI) {
|
|
700
|
-
// convert base64/URLEncoded data component to raw binary data held in a string
|
|
701
|
-
var byteString;
|
|
702
|
-
if (dataURI.split(',')[0].indexOf('base64') >= 0)
|
|
703
|
-
byteString = atob(dataURI.split(',')[1]);
|
|
704
|
-
else
|
|
705
|
-
byteString = unescape(dataURI.split(',')[1]);
|
|
706
|
-
// separate out the mime component
|
|
707
|
-
var metadata = dataURI
|
|
708
|
-
.split(';')
|
|
709
|
-
.filter(function (v, k, all) { return k < all.length - 1; })
|
|
710
|
-
.map(function (v) { return v.split(/:/); });
|
|
711
|
-
var _a = metadata.find(function (_a) {
|
|
712
|
-
var k = _a[0]; _a[1];
|
|
713
|
-
return k === 'data';
|
|
714
|
-
}) || [], _b = _a[1], mimeString = _b === void 0 ? '' : _b;
|
|
715
|
-
var _c = mimeString.split(/\//), ext = _c[1];
|
|
716
|
-
var _d = metadata.find(function (_a) {
|
|
717
|
-
var k = _a[0]; _a[1];
|
|
718
|
-
return k === 'filename';
|
|
719
|
-
}) || [], _e = _d[1], fileName = _e === void 0 ? "file.".concat(ext) : _e;
|
|
720
|
-
// write the bytes of the string to a typed array
|
|
721
|
-
var ia = new Uint8Array(byteString.length);
|
|
722
|
-
for (var i = 0; i < byteString.length; i++) {
|
|
723
|
-
ia[i] = byteString.charCodeAt(i);
|
|
724
|
-
}
|
|
725
|
-
return [new Blob([ia], { type: mimeString }), fileName];
|
|
726
|
-
}
|
|
727
800
|
var formData;
|
|
728
801
|
return _tslib.__generator(this, function (_a) {
|
|
729
802
|
switch (_a.label) {
|
|
@@ -807,6 +880,16 @@ var Api = /** @class */ (function (_super) {
|
|
|
807
880
|
});
|
|
808
881
|
});
|
|
809
882
|
};
|
|
883
|
+
Api.prototype.testAutomation = function (_a) {
|
|
884
|
+
var workspaceId = _a.workspaceId, automation = _a.automation, payload = _a.payload;
|
|
885
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
886
|
+
return _tslib.__generator(this, function (_b) {
|
|
887
|
+
return [2 /*return*/, this.post("/workspaces/".concat(workspaceId, "/test/").concat(automation), {
|
|
888
|
+
payload: payload,
|
|
889
|
+
})];
|
|
890
|
+
});
|
|
891
|
+
});
|
|
892
|
+
};
|
|
810
893
|
Api.prototype.getWorkspaceUsage = function (workspaceId, _a) {
|
|
811
894
|
var _b = _a === void 0 ? {} : _a, afterDate = _b.afterDate, beforeDate = _b.beforeDate, details = _b.details;
|
|
812
895
|
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
@@ -821,12 +904,53 @@ var Api = /** @class */ (function (_super) {
|
|
|
821
904
|
});
|
|
822
905
|
});
|
|
823
906
|
};
|
|
907
|
+
Api.prototype.importArchive = function (archive) {
|
|
908
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
909
|
+
var _this = this;
|
|
910
|
+
return _tslib.__generator(this, function (_a) {
|
|
911
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
912
|
+
var fileReader = new FileReader();
|
|
913
|
+
fileReader.addEventListener('load', function (_a) {
|
|
914
|
+
var target = _a.target;
|
|
915
|
+
return _tslib.__awaiter(_this, void 0, void 0, function () {
|
|
916
|
+
var file, formData, _b;
|
|
917
|
+
return _tslib.__generator(this, function (_c) {
|
|
918
|
+
switch (_c.label) {
|
|
919
|
+
case 0:
|
|
920
|
+
file = target === null || target === void 0 ? void 0 : target.result;
|
|
921
|
+
formData = new FormData();
|
|
922
|
+
formData.append.apply(formData, _tslib.__spreadArray(['archive'], dataURItoBlob(file)));
|
|
923
|
+
_b = resolve;
|
|
924
|
+
return [4 /*yield*/, this._fetch("/workspaces/import", {
|
|
925
|
+
method: 'POST',
|
|
926
|
+
body: formData,
|
|
927
|
+
})];
|
|
928
|
+
case 1:
|
|
929
|
+
_b.apply(void 0, [_c.sent()]);
|
|
930
|
+
return [2 /*return*/];
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
fileReader.readAsDataURL(archive);
|
|
936
|
+
})];
|
|
937
|
+
});
|
|
938
|
+
});
|
|
939
|
+
};
|
|
940
|
+
Api.prototype.users = function (id) {
|
|
941
|
+
var _a;
|
|
942
|
+
if (id === void 0) { id = ((_a = this.user) === null || _a === void 0 ? void 0 : _a.id) || ''; }
|
|
943
|
+
if (!id) {
|
|
944
|
+
throw new Error();
|
|
945
|
+
}
|
|
946
|
+
return new users.UsersEndpoint(id, this);
|
|
947
|
+
};
|
|
824
948
|
Api.prototype.workspaces = function (id) {
|
|
825
949
|
return new workspaces.WorkspacesEndpoint(id, this);
|
|
826
950
|
};
|
|
827
951
|
return Api;
|
|
828
952
|
}(fetcher.Fetcher));
|
|
829
|
-
var api = new Api('https://api.eda.prisme.ai');
|
|
953
|
+
var api = new Api({ host: 'https://api.eda.prisme.ai' });
|
|
830
954
|
|
|
831
955
|
exports.Api = Api;
|
|
832
956
|
exports["default"] = api;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../_virtual/_tslib.js');
|
|
6
|
+
|
|
7
|
+
var UsersEndpoint = /** @class */ (function () {
|
|
8
|
+
function UsersEndpoint(id, api) {
|
|
9
|
+
this.id = id;
|
|
10
|
+
this.api = api;
|
|
11
|
+
}
|
|
12
|
+
UsersEndpoint.prototype.setMeta = function (k, v) {
|
|
13
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
14
|
+
var _a;
|
|
15
|
+
return _tslib.__generator(this, function (_b) {
|
|
16
|
+
switch (_b.label) {
|
|
17
|
+
case 0: return [4 /*yield*/, this.api.post("/user/meta", (_a = {},
|
|
18
|
+
_a[k] = v,
|
|
19
|
+
_a))];
|
|
20
|
+
case 1:
|
|
21
|
+
_b.sent();
|
|
22
|
+
return [2 /*return*/];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
UsersEndpoint.prototype.deleteMeta = function (k) {
|
|
28
|
+
return _tslib.__awaiter(this, void 0, void 0, function () {
|
|
29
|
+
return _tslib.__generator(this, function (_a) {
|
|
30
|
+
switch (_a.label) {
|
|
31
|
+
case 0: return [4 /*yield*/, this.api.delete("/user/meta/".concat(k))];
|
|
32
|
+
case 1:
|
|
33
|
+
_a.sent();
|
|
34
|
+
return [2 /*return*/];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return UsersEndpoint;
|
|
40
|
+
}());
|
|
41
|
+
|
|
42
|
+
exports.UsersEndpoint = UsersEndpoint;
|
|
43
|
+
exports["default"] = UsersEndpoint;
|
package/dist/sdk/lib/events.js
CHANGED
|
@@ -11,15 +11,18 @@ var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
|
|
|
11
11
|
|
|
12
12
|
var Events = /** @class */ (function () {
|
|
13
13
|
function Events(_a) {
|
|
14
|
-
var workspaceId = _a.workspaceId, token = _a.token, apiKey = _a.apiKey, _b = _a.apiHost, apiHost = _b === void 0 ? 'https://api.eda.prisme.ai' : _b, filters = _a.filters, api = _a.api;
|
|
14
|
+
var workspaceId = _a.workspaceId, token = _a.token, legacyToken = _a.legacyToken, apiKey = _a.apiKey, _b = _a.apiHost, apiHost = _b === void 0 ? 'https://api.eda.prisme.ai' : _b, filters = _a.filters, api = _a.api;
|
|
15
15
|
var _this = this;
|
|
16
16
|
this.listeners = new Map();
|
|
17
17
|
this.workspaceId = workspaceId;
|
|
18
18
|
var queryString = new URLSearchParams(filters || {}).toString();
|
|
19
19
|
var fullQueryString = queryString ? "?".concat(queryString) : '';
|
|
20
|
-
var extraHeaders =
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
var extraHeaders = token
|
|
21
|
+
? {
|
|
22
|
+
Authorization: "Bearer ".concat(token),
|
|
23
|
+
}
|
|
24
|
+
: { 'x-prismeai-token': legacyToken };
|
|
25
|
+
this.lastReceivedEventDate = new Date();
|
|
23
26
|
if (apiKey) {
|
|
24
27
|
extraHeaders['x-prismeai-api-key'] = apiKey;
|
|
25
28
|
}
|
|
@@ -27,14 +30,17 @@ var Events = /** @class */ (function () {
|
|
|
27
30
|
extraHeaders: extraHeaders,
|
|
28
31
|
withCredentials: true,
|
|
29
32
|
});
|
|
30
|
-
var lastConnectionTime = new Date();
|
|
31
33
|
var onConnect = function () {
|
|
34
|
+
// Reset last filters
|
|
35
|
+
_this.updateFilters({
|
|
36
|
+
payloadQuery: _this.filters,
|
|
37
|
+
});
|
|
32
38
|
setTimeout(function () { return _tslib.__awaiter(_this, void 0, void 0, function () {
|
|
33
39
|
var events;
|
|
34
40
|
var _this = this;
|
|
35
41
|
return _tslib.__generator(this, function (_a) {
|
|
36
42
|
switch (_a.label) {
|
|
37
|
-
case 0: return [4 /*yield*/, api.getEvents(workspaceId, _tslib.__assign(_tslib.__assign({}, this.filters[this.filters.length - 1]), { afterDate:
|
|
43
|
+
case 0: return [4 /*yield*/, api.getEvents(workspaceId, _tslib.__assign(_tslib.__assign({}, this.filters[this.filters.length - 1]), { afterDate: this.lastReceivedEventDate.toISOString() }))];
|
|
38
44
|
case 1:
|
|
39
45
|
events = _a.sent();
|
|
40
46
|
events.reverse().forEach(function (event) {
|
|
@@ -48,7 +54,9 @@ var Events = /** @class */ (function () {
|
|
|
48
54
|
}); }, 2000);
|
|
49
55
|
};
|
|
50
56
|
this.client.on('disconnect', function () {
|
|
51
|
-
|
|
57
|
+
if (!_this.lastReceivedEventDate) {
|
|
58
|
+
_this.lastReceivedEventDate = new Date();
|
|
59
|
+
}
|
|
52
60
|
_this.client.off('connect', onConnect);
|
|
53
61
|
_this.client.on('connect', onConnect);
|
|
54
62
|
});
|
|
@@ -75,7 +83,10 @@ var Events = /** @class */ (function () {
|
|
|
75
83
|
};
|
|
76
84
|
Events.prototype.all = function (listener) {
|
|
77
85
|
var _this = this;
|
|
78
|
-
this.client.onAny(
|
|
86
|
+
this.client.onAny(function (eventName, eventData) {
|
|
87
|
+
_this.lastReceivedEventDate = new Date(eventData === null || eventData === void 0 ? void 0 : eventData.createdAt);
|
|
88
|
+
return listener(eventName, eventData);
|
|
89
|
+
});
|
|
79
90
|
return function () { return _this.client.offAny(listener); };
|
|
80
91
|
};
|
|
81
92
|
Events.prototype.on = function (ev, listener) {
|