@prisme.ai/sdk 1.0.1 → 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.
- package/README.md +250 -0
- package/dist/index.d.mts +1129 -0
- package/dist/index.d.ts +1129 -7
- package/dist/index.js +1326 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1287 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -11
- package/Readme.md +0 -28
- package/dist/_virtual/_tslib.js +0 -107
- package/dist/lib/ApiError.d.ts +0 -8
- package/dist/lib/ApiError.test.d.ts +0 -1
- package/dist/lib/HTTPError.d.ts +0 -6
- package/dist/lib/HTTPError.test.d.ts +0 -1
- package/dist/lib/api.d.ts +0 -140
- package/dist/lib/api.test.d.ts +0 -1
- package/dist/lib/endpoints/users.d.ts +0 -9
- package/dist/lib/endpoints/workspaces.d.ts +0 -9
- package/dist/lib/endpoints/workspacesVersions.d.ts +0 -10
- package/dist/lib/events.d.ts +0 -38
- package/dist/lib/events.test.d.ts +0 -1
- package/dist/lib/fetcher.d.ts +0 -23
- package/dist/lib/fetcher.test.d.ts +0 -1
- package/dist/lib/types.d.ts +0 -17
- package/dist/lib/utils.d.ts +0 -1
- package/dist/lib/utils.test.d.ts +0 -1
- package/dist/sdk/index.js +0 -19
- package/dist/sdk/lib/ApiError.js +0 -24
- package/dist/sdk/lib/HTTPError.js +0 -21
- package/dist/sdk/lib/api.js +0 -956
- package/dist/sdk/lib/endpoints/users.js +0 -43
- package/dist/sdk/lib/endpoints/workspaces.js +0 -23
- package/dist/sdk/lib/endpoints/workspacesVersions.js +0 -40
- package/dist/sdk/lib/events.js +0 -142
- package/dist/sdk/lib/fetcher.js +0 -175
- package/dist/sdk/lib/utils.js +0 -18
- package/index.ts +0 -7
- package/lib/ApiError.test.ts +0 -13
- package/lib/ApiError.ts +0 -21
- package/lib/HTTPError.test.ts +0 -8
- package/lib/HTTPError.ts +0 -13
- package/lib/api.test.ts +0 -772
- package/lib/api.ts +0 -871
- package/lib/endpoints/users.ts +0 -22
- package/lib/endpoints/workspaces.ts +0 -18
- package/lib/endpoints/workspacesVersions.ts +0 -34
- package/lib/events.test.ts +0 -89
- package/lib/events.ts +0 -180
- package/lib/fetcher.test.ts +0 -246
- package/lib/fetcher.ts +0 -163
- package/lib/types.ts +0 -21
- package/lib/utils.test.ts +0 -38
- package/lib/utils.ts +0 -12
- package/tsconfig.json +0 -21
package/lib/fetcher.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import ApiError from './ApiError';
|
|
2
|
-
import HTTPError from './HTTPError';
|
|
3
|
-
|
|
4
|
-
const headersAsObject = (headers: Headers) =>
|
|
5
|
-
Array.from(headers).reduce(
|
|
6
|
-
(prev, [k, v]) => ({
|
|
7
|
-
...prev,
|
|
8
|
-
[k]: v,
|
|
9
|
-
}),
|
|
10
|
-
{}
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
export type Fetched<T> = T & {
|
|
14
|
-
headers?: Record<string, any>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export class Fetcher {
|
|
18
|
-
public host: string;
|
|
19
|
-
public token: string | null = null;
|
|
20
|
-
public legacyToken: string | null = null;
|
|
21
|
-
public overwriteClientId?: string;
|
|
22
|
-
private clientIdHeader?: string;
|
|
23
|
-
protected _apiKey: string | null = null;
|
|
24
|
-
public language: string | undefined;
|
|
25
|
-
public lastReceivedHeaders?: Record<string, any>;
|
|
26
|
-
|
|
27
|
-
constructor(host: string, clientIdHeader?: string) {
|
|
28
|
-
this.host = host;
|
|
29
|
-
this.clientIdHeader = clientIdHeader;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
set apiKey(apiKey: string) {
|
|
33
|
-
this._apiKey = apiKey;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
prepareRequest(url: string, options: RequestInit = {}) {
|
|
37
|
-
const headers = new Headers(options.headers || {});
|
|
38
|
-
|
|
39
|
-
if (this.token && !headers.has('Authorization')) {
|
|
40
|
-
headers.append('Authorization', `Bearer ${this.token}`);
|
|
41
|
-
} else if (this.legacyToken && !headers.has('Authorization')) {
|
|
42
|
-
headers.append('x-prismeai-token', this.legacyToken);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (this._apiKey && !headers.has('x-prismeai-apikey')) {
|
|
46
|
-
headers.append('x-prismeai-api-key', this._apiKey);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (this.language) {
|
|
50
|
-
headers.append('accept-language', this.language);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (options.body instanceof URLSearchParams) {
|
|
54
|
-
headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
(!options.body || !(options.body instanceof FormData)) &&
|
|
59
|
-
!headers.has('Content-Type')
|
|
60
|
-
) {
|
|
61
|
-
headers.append('Content-Type', 'application/json');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const fullUrl =
|
|
65
|
-
url.startsWith('http://') || url.startsWith('https://')
|
|
66
|
-
? url
|
|
67
|
-
: `${this.host}${url}`;
|
|
68
|
-
return global.fetch(fullUrl, {
|
|
69
|
-
credentials: 'include',
|
|
70
|
-
...options,
|
|
71
|
-
headers,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
protected async _fetch<T>(
|
|
76
|
-
url: string,
|
|
77
|
-
options: RequestInit = {}
|
|
78
|
-
): Promise<T> {
|
|
79
|
-
const res = await this.prepareRequest(url, options);
|
|
80
|
-
if (options.redirect === 'manual' && res.status === 0) {
|
|
81
|
-
return { redirected: true } as T;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
this.lastReceivedHeaders = headersAsObject(res.headers);
|
|
85
|
-
if (this.clientIdHeader && this.lastReceivedHeaders[this.clientIdHeader]) {
|
|
86
|
-
this.overwriteClientId = this.lastReceivedHeaders[this.clientIdHeader];
|
|
87
|
-
}
|
|
88
|
-
if (!res.ok) {
|
|
89
|
-
let error;
|
|
90
|
-
try {
|
|
91
|
-
error = new ApiError(await res.json(), res.status);
|
|
92
|
-
} catch (e) {
|
|
93
|
-
error = new HTTPError(res.statusText, res.status);
|
|
94
|
-
}
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const contentType = res.headers.get('content-type');
|
|
99
|
-
if (contentType && contentType.includes('application/json')) {
|
|
100
|
-
try {
|
|
101
|
-
const response = (await res.json()) || {};
|
|
102
|
-
Object.defineProperty(response, 'headers', {
|
|
103
|
-
value: headersAsObject(res.headers),
|
|
104
|
-
configurable: false,
|
|
105
|
-
enumerable: false,
|
|
106
|
-
writable: false,
|
|
107
|
-
});
|
|
108
|
-
return response as T;
|
|
109
|
-
} catch (e) {
|
|
110
|
-
return {} as T;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const text = await res.text();
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
return JSON.parse(text) as T;
|
|
118
|
-
} catch {
|
|
119
|
-
return text as T;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async get<T = any>(url: string) {
|
|
124
|
-
return this._fetch<T>(url, {
|
|
125
|
-
method: 'GET',
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async post<T>(url: string, body?: Record<string, any>, opts?: RequestInit) {
|
|
130
|
-
return this._fetch<T>(url, {
|
|
131
|
-
method: 'POST',
|
|
132
|
-
body:
|
|
133
|
-
body &&
|
|
134
|
-
!(body instanceof FormData) &&
|
|
135
|
-
!(body instanceof URLSearchParams)
|
|
136
|
-
? JSON.stringify(body)
|
|
137
|
-
: body,
|
|
138
|
-
...opts,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async put<T>(url: string, body: Record<string, any>) {
|
|
143
|
-
return this._fetch<T>(url, {
|
|
144
|
-
method: 'PUT',
|
|
145
|
-
body: JSON.stringify(body),
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async patch<T>(url: string, body: Record<string, any>) {
|
|
150
|
-
return this._fetch<T>(url, {
|
|
151
|
-
method: 'PATCH',
|
|
152
|
-
body: JSON.stringify(body),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async delete<T>(url: string) {
|
|
157
|
-
return this._fetch<T>(url, {
|
|
158
|
-
method: 'DELETE',
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export default Fetcher;
|
package/lib/types.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import '@prisme.ai/types';
|
|
2
|
-
|
|
3
|
-
export interface Workspace extends Prismeai.Workspace {
|
|
4
|
-
id: string;
|
|
5
|
-
updatedAt: Date;
|
|
6
|
-
updatedBy: string;
|
|
7
|
-
createdAt: Date;
|
|
8
|
-
createdBy: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface Event<DateType extends Date | string>
|
|
12
|
-
extends Omit<Prismeai.PrismeEvent, 'createdAt'> {
|
|
13
|
-
createdAt: DateType;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type EventsFilters = Record<string, string> & {
|
|
17
|
-
afterDate?: PrismeaiAPI.EventsLongpolling.Parameters.AfterDate;
|
|
18
|
-
beforeDate?: PrismeaiAPI.EventsLongpolling.Parameters.BeforeDate;
|
|
19
|
-
text?: PrismeaiAPI.EventsLongpolling.Parameters.Text;
|
|
20
|
-
query?: PrismeaiAPI.EventsLongpolling.Parameters.Query;
|
|
21
|
-
};
|
package/lib/utils.test.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { removedUndefinedProperties } from './utils';
|
|
2
|
-
|
|
3
|
-
it('should remove undefined keys', () => {
|
|
4
|
-
const myObject = {
|
|
5
|
-
first: 'one',
|
|
6
|
-
second: 'second',
|
|
7
|
-
third: '',
|
|
8
|
-
fourth: undefined,
|
|
9
|
-
fifth: 5,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const newObject = removedUndefinedProperties(myObject);
|
|
13
|
-
|
|
14
|
-
expect(newObject).toStrictEqual({
|
|
15
|
-
first: 'one',
|
|
16
|
-
second: 'second',
|
|
17
|
-
third: '',
|
|
18
|
-
fifth: 5,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should remove empty strings if specified', () => {
|
|
23
|
-
const myObject = {
|
|
24
|
-
first: 'one',
|
|
25
|
-
second: 'second',
|
|
26
|
-
third: '',
|
|
27
|
-
fourth: undefined,
|
|
28
|
-
fifth: 5,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const newObject = removedUndefinedProperties(myObject, true);
|
|
32
|
-
|
|
33
|
-
expect(newObject).toStrictEqual({
|
|
34
|
-
first: 'one',
|
|
35
|
-
second: 'second',
|
|
36
|
-
fifth: 5,
|
|
37
|
-
});
|
|
38
|
-
});
|
package/lib/utils.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const removedUndefinedProperties = (
|
|
2
|
-
obj: any,
|
|
3
|
-
removeEmptyStrings: boolean = false
|
|
4
|
-
) =>
|
|
5
|
-
Object.entries(obj).reduce((newObject: any, [key, value]) => {
|
|
6
|
-
if (value !== undefined) {
|
|
7
|
-
if (!(removeEmptyStrings && value === '')) {
|
|
8
|
-
newObject[key] = value;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return newObject;
|
|
12
|
-
}, {});
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es5",
|
|
4
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"noFallthroughCasesInSwitch": true,
|
|
12
|
-
"module": "ESNext",
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"isolatedModules": false,
|
|
16
|
-
"noEmit": true,
|
|
17
|
-
"declaration": true
|
|
18
|
-
},
|
|
19
|
-
"include": ["./index.ts", "lib/**/*", "openapi/*"],
|
|
20
|
-
"exclude": ["node_modules", "dist"]
|
|
21
|
-
}
|