@ptkl/sdk 0.2.0 → 0.2.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/dist/index.cjs.js +380 -254
- package/dist/index.esm.js +369 -257
- package/dist/index.umd.js +386 -260
- package/dist/package.json +7 -5
- package/dist/types/api/apiUser.d.ts +3 -3
- package/dist/types/api/apps.d.ts +3 -3
- package/dist/types/api/baseClient.d.ts +1 -0
- package/dist/types/api/component.d.ts +80 -19
- package/dist/types/api/componentUtils.d.ts +5 -0
- package/dist/types/api/forge.d.ts +2 -3
- package/dist/types/api/functions.d.ts +18 -3
- package/dist/types/api/integrations/invoicing.d.ts +2 -2
- package/dist/types/api/integrations/media.d.ts +2 -2
- package/dist/types/api/integrations/serbiaUtil.d.ts +2 -2
- package/dist/types/api/integrations/vpfr.d.ts +2 -2
- package/dist/types/api/integrations.d.ts +7 -4
- package/dist/types/api/integrationsBaseClient.d.ts +8 -0
- package/dist/types/api/platform.d.ts +4 -13
- package/dist/types/api/platformBaseClient.d.ts +27 -0
- package/dist/types/api/ratchet.d.ts +2 -2
- package/dist/types/api/roles.d.ts +2 -2
- package/dist/types/api/sandbox.d.ts +12 -2
- package/dist/types/api/system.d.ts +2 -2
- package/dist/types/api/thunder.d.ts +2 -2
- package/dist/types/api/users.d.ts +2 -2
- package/dist/types/api/workflow.d.ts +2 -2
- package/dist/types/index.d.ts +12 -0
- package/dist/types/types/component.d.ts +47 -0
- package/package.json +6 -4
package/dist/index.esm.js
CHANGED
|
@@ -4,9 +4,73 @@ class BaseClient {
|
|
|
4
4
|
constructor(client) {
|
|
5
5
|
this.client = client;
|
|
6
6
|
}
|
|
7
|
+
setClient(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
7
11
|
}
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
typeof process !== "undefined" &&
|
|
14
|
+
process.versions != null &&
|
|
15
|
+
process.versions.node != null;
|
|
16
|
+
const isBrowser = typeof window !== "undefined" &&
|
|
17
|
+
typeof document !== "undefined";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Base client for the platform API
|
|
21
|
+
* Classes that extend PlatformBaseClient have intentins of only working in platform context
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* @class PlatformBaseClient
|
|
25
|
+
* @extends BaseClient
|
|
26
|
+
* @constructor
|
|
27
|
+
* @param {AxiosInstance} [client] - The axios instance to use for the client
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // if sdk is used in the forge app that is running in the platform context
|
|
31
|
+
* const utils = new ComponentUtils()
|
|
32
|
+
* // this won't work outside of platform context because client needs authtorization to communicate with the API.
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
class PlatformBaseClient extends BaseClient {
|
|
36
|
+
constructor(options) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
let { env = null, token, host, } = options !== null && options !== undefined ? options : {};
|
|
39
|
+
let headers = {};
|
|
40
|
+
if (isBrowser) {
|
|
41
|
+
if (localStorage.getItem('protokol_context') == "forge") {
|
|
42
|
+
headers['X-Project-Env'] = (_a = localStorage.getItem('forge_app_env')) !== null && _a !== undefined ? _a : "dev";
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// this potentially means that it is running as dev server in local
|
|
46
|
+
headers['X-Project-Env'] = "dev";
|
|
47
|
+
}
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
const __global_env__ = window === null || window === undefined ? undefined : window.__ENV_VARIABLES__;
|
|
50
|
+
host = (_b = __global_env__ === null || __global_env__ === undefined ? undefined : __global_env__.API_HOST) !== null && _b !== undefined ? _b : host;
|
|
51
|
+
}
|
|
52
|
+
if (token) {
|
|
53
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
54
|
+
}
|
|
55
|
+
if (env) {
|
|
56
|
+
headers['X-Project-Env'] = env;
|
|
57
|
+
}
|
|
58
|
+
const client = axios.create({
|
|
59
|
+
baseURL: host !== null && host !== undefined ? host : "https://lemon.protokol.io",
|
|
60
|
+
timeout: 15000,
|
|
61
|
+
headers: {
|
|
62
|
+
...headers,
|
|
63
|
+
},
|
|
64
|
+
withCredentials: true,
|
|
65
|
+
});
|
|
66
|
+
super(client);
|
|
67
|
+
this.env = null;
|
|
68
|
+
this.token = null;
|
|
69
|
+
this.host = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
class Functions extends PlatformBaseClient {
|
|
10
74
|
async list() {
|
|
11
75
|
return await this.client.get("/v1/system/function");
|
|
12
76
|
}
|
|
@@ -16,9 +80,21 @@ class Functions extends BaseClient {
|
|
|
16
80
|
async update(uuid, update) {
|
|
17
81
|
return await this.client.patch(`/v1/system/function/${uuid}`, update);
|
|
18
82
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Run platform function
|
|
85
|
+
*
|
|
86
|
+
* @param id - Function ID
|
|
87
|
+
* @param input - Input data
|
|
88
|
+
* @param query - Query parameters
|
|
89
|
+
* @returns - Function result
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const result = await platform.function().run("myFunction", { foo: "bar" }, { queryParam: "value" })
|
|
93
|
+
*/
|
|
94
|
+
async run(id, d) {
|
|
95
|
+
const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
|
|
96
|
+
params: d.query,
|
|
97
|
+
headers: d.headers
|
|
22
98
|
});
|
|
23
99
|
return data.data;
|
|
24
100
|
}
|
|
@@ -27,7 +103,7 @@ class Functions extends BaseClient {
|
|
|
27
103
|
}
|
|
28
104
|
}
|
|
29
105
|
|
|
30
|
-
class Roles extends
|
|
106
|
+
class Roles extends PlatformBaseClient {
|
|
31
107
|
async create(role) {
|
|
32
108
|
const res = await this.client.post("/v1/user/role/create", role);
|
|
33
109
|
// writeFileSync(`.role.create.json`,JSON.stringify(res))
|
|
@@ -51,11 +127,15 @@ class Roles extends BaseClient {
|
|
|
51
127
|
}
|
|
52
128
|
}
|
|
53
129
|
|
|
54
|
-
class APIUser extends
|
|
55
|
-
async
|
|
130
|
+
class APIUser extends PlatformBaseClient {
|
|
131
|
+
async auth(username, password, project) {
|
|
56
132
|
return this.client.post("/v1/user/api/auth", {
|
|
57
133
|
username,
|
|
58
134
|
password
|
|
135
|
+
}, {
|
|
136
|
+
headers: {
|
|
137
|
+
"X-Project-Uuid": project
|
|
138
|
+
}
|
|
59
139
|
});
|
|
60
140
|
}
|
|
61
141
|
async newSecret(uuid) {
|
|
@@ -75,7 +155,7 @@ class APIUser extends BaseClient {
|
|
|
75
155
|
}
|
|
76
156
|
}
|
|
77
157
|
|
|
78
|
-
class Users extends
|
|
158
|
+
class Users extends PlatformBaseClient {
|
|
79
159
|
async invite(email, roles) {
|
|
80
160
|
return await this.client.post("/v1/project/invite", {
|
|
81
161
|
email,
|
|
@@ -87,9 +167,9 @@ class Users extends BaseClient {
|
|
|
87
167
|
}
|
|
88
168
|
}
|
|
89
169
|
|
|
90
|
-
class Apps extends
|
|
91
|
-
constructor(
|
|
92
|
-
super(
|
|
170
|
+
class Apps extends PlatformBaseClient {
|
|
171
|
+
constructor(appType) {
|
|
172
|
+
super();
|
|
93
173
|
this.appType = appType;
|
|
94
174
|
}
|
|
95
175
|
async updateSettings(updateValues, ref) {
|
|
@@ -100,21 +180,40 @@ class Apps extends BaseClient {
|
|
|
100
180
|
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
|
|
101
181
|
}
|
|
102
182
|
async upload(formData) {
|
|
103
|
-
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData
|
|
183
|
+
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
|
|
184
|
+
timeout: 60000
|
|
185
|
+
});
|
|
104
186
|
}
|
|
105
187
|
}
|
|
106
188
|
|
|
107
|
-
class Component extends
|
|
108
|
-
constructor(
|
|
109
|
-
super(
|
|
189
|
+
class Component extends PlatformBaseClient {
|
|
190
|
+
constructor(ref = null) {
|
|
191
|
+
super();
|
|
110
192
|
this.ref = ref;
|
|
111
193
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Find method to search for models
|
|
196
|
+
*
|
|
197
|
+
* @param {FindParams} filters - The filters to apply to the search
|
|
198
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
199
|
+
*
|
|
200
|
+
* @returns {Promise<FindResponse>} - The result of the search
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* platform.component(name).find({
|
|
204
|
+
* currentPage: 1,
|
|
205
|
+
* perPage: 10,
|
|
206
|
+
* })
|
|
207
|
+
*
|
|
208
|
+
* // advanced search
|
|
209
|
+
* platform.component(name).find({
|
|
210
|
+
* $adv: {
|
|
211
|
+
* name: "John Doe",
|
|
212
|
+
* }
|
|
213
|
+
* )
|
|
214
|
+
**/
|
|
116
215
|
find(filters, opts) {
|
|
117
|
-
const { cache = false, buildttl = -1, locale = "en_US" } = opts !== null && opts !== undefined ? opts : {};
|
|
216
|
+
const { cache = false, buildttl = -1, locale = "en_US", } = opts !== null && opts !== undefined ? opts : {};
|
|
118
217
|
return new Promise((resolve, reject) => {
|
|
119
218
|
let payload = {
|
|
120
219
|
context: filters,
|
|
@@ -142,7 +241,6 @@ class Component extends BaseClient {
|
|
|
142
241
|
sortDesc: sortDesc,
|
|
143
242
|
filter: ctx.filter,
|
|
144
243
|
filterOn: ctx.filterOn.join(","),
|
|
145
|
-
disabled: ctx.disabled,
|
|
146
244
|
limit: limit,
|
|
147
245
|
dateFrom: ctx.dateFrom,
|
|
148
246
|
dateTo: ctx.dateTo,
|
|
@@ -154,9 +252,11 @@ class Component extends BaseClient {
|
|
|
154
252
|
if (ctx.$aggregate && ctx.$aggregate.length > 0) {
|
|
155
253
|
params.$aggregate = JSON.stringify(ctx.$aggregate);
|
|
156
254
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
255
|
+
if (opts) {
|
|
256
|
+
Object.keys(opts).forEach(k => {
|
|
257
|
+
params[`_opt_${k}`] = opts ? opts[k] : null;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
160
260
|
this.client.get(`/v3/system/component/${this.ref}/models`, {
|
|
161
261
|
params: params,
|
|
162
262
|
headers: {
|
|
@@ -172,6 +272,19 @@ class Component extends BaseClient {
|
|
|
172
272
|
});
|
|
173
273
|
});
|
|
174
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* FindOne method to search for a single model
|
|
277
|
+
*
|
|
278
|
+
* @param {FindAdvancedParams} filter - The filters to apply to the search
|
|
279
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
280
|
+
*
|
|
281
|
+
* @returns {Promise<?Model>} - The result of the search
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* platform.component(name).findOne({
|
|
285
|
+
* name: "John Doe",
|
|
286
|
+
* })
|
|
287
|
+
**/
|
|
175
288
|
async findOne(filter, opts) {
|
|
176
289
|
const { items } = await this.find({
|
|
177
290
|
$adv: filter
|
|
@@ -181,82 +294,79 @@ class Component extends BaseClient {
|
|
|
181
294
|
}
|
|
182
295
|
return null;
|
|
183
296
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
update(uuid, model) {
|
|
194
|
-
return new Promise((resolve, reject) => {
|
|
195
|
-
this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
196
|
-
data: model
|
|
197
|
-
}).then((resp) => {
|
|
198
|
-
resolve(resp.data);
|
|
199
|
-
}).catch((error) => {
|
|
200
|
-
reject(error);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
297
|
+
/**
|
|
298
|
+
* Get model by uuid
|
|
299
|
+
*
|
|
300
|
+
* @param uuid string - The uuid of the model
|
|
301
|
+
* @returns (Promise<Model>)
|
|
302
|
+
*/
|
|
303
|
+
async get(uuid) {
|
|
304
|
+
const { data } = await this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`);
|
|
305
|
+
return data;
|
|
203
306
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
307
|
+
/**
|
|
308
|
+
* Update model by uuid
|
|
309
|
+
*
|
|
310
|
+
* @param uuid string - The uuid of the model
|
|
311
|
+
* @param data
|
|
312
|
+
* @returns
|
|
313
|
+
*/
|
|
314
|
+
async update(uuid, data, options) {
|
|
315
|
+
const { data: responseData } = await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
316
|
+
data,
|
|
317
|
+
options,
|
|
318
|
+
});
|
|
319
|
+
return responseData;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Update many models
|
|
323
|
+
*
|
|
324
|
+
* @param data
|
|
325
|
+
* @param options
|
|
326
|
+
* @returns
|
|
327
|
+
*/
|
|
328
|
+
async updateMany(data, options) {
|
|
329
|
+
const { data: responseData } = await this.client.post(`/v3/system/component/${this.ref}/models/bulk`, {
|
|
330
|
+
data,
|
|
331
|
+
options,
|
|
332
|
+
});
|
|
333
|
+
return responseData;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Concurrent update model by uuid
|
|
337
|
+
*
|
|
338
|
+
* @param uuid string - The uuid of the model
|
|
339
|
+
* @param version number - The version of the model
|
|
340
|
+
* @param data
|
|
341
|
+
* @returns
|
|
342
|
+
*/
|
|
343
|
+
async concurrentUpdate(uuid, version, data, options) {
|
|
344
|
+
const { data: responseData } = await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
345
|
+
version: version,
|
|
346
|
+
data,
|
|
347
|
+
options,
|
|
214
348
|
});
|
|
349
|
+
return responseData;
|
|
215
350
|
}
|
|
216
|
-
create(model) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
resolve(resp.data);
|
|
220
|
-
}).catch((error) => {
|
|
221
|
-
reject(error);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
351
|
+
async create(model) {
|
|
352
|
+
const { data } = await this.client.post(`/v3/system/component/${this.ref}/model`, model);
|
|
353
|
+
return data;
|
|
224
354
|
}
|
|
225
|
-
delete(uuid) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
resolve(resp.data);
|
|
229
|
-
}).catch((error) => {
|
|
230
|
-
reject(error);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
355
|
+
async delete(uuid) {
|
|
356
|
+
const { data } = await this.client.delete(`/v3/system/component/${this.ref}/model/${uuid}`);
|
|
357
|
+
return data;
|
|
233
358
|
}
|
|
234
|
-
aggregate(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
resolve(resp.data);
|
|
238
|
-
}).catch((error) => {
|
|
239
|
-
reject(error);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
359
|
+
async aggregate(pipeline) {
|
|
360
|
+
const { data } = await this.client.post(`/v3/system/component/${this.ref}/aggregate`, pipeline);
|
|
361
|
+
return data;
|
|
242
362
|
}
|
|
243
|
-
settings() {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
resolve(resp.data);
|
|
247
|
-
}).catch(err => {
|
|
248
|
-
reject(err);
|
|
249
|
-
});
|
|
250
|
-
});
|
|
363
|
+
async settings() {
|
|
364
|
+
const { data } = await this.client.get(`/v3/system/component/settings/${this.ref}`);
|
|
365
|
+
return data;
|
|
251
366
|
}
|
|
252
|
-
saveSettings(settings) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
resolve(resp.data);
|
|
256
|
-
}).catch(err => {
|
|
257
|
-
reject(err);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
367
|
+
async saveSettings(settings, version) {
|
|
368
|
+
const { data } = await this.client.post(`/v3/system/component/settings/${this.ref}/${version}`, settings);
|
|
369
|
+
return data;
|
|
260
370
|
}
|
|
261
371
|
async saveTemplatesDist(version, sdkVersion, engine, dist) {
|
|
262
372
|
const { data } = await this.client.post(`/v3/system/component/templates/${this.ref}/${version}`, {
|
|
@@ -269,24 +379,136 @@ class Component extends BaseClient {
|
|
|
269
379
|
return data;
|
|
270
380
|
}
|
|
271
381
|
async workflow(event, input) {
|
|
272
|
-
|
|
382
|
+
const { data } = await this.client.post(`/v1/system/component/${this.ref}/workflow/event`, {
|
|
273
383
|
event,
|
|
274
384
|
input
|
|
275
385
|
});
|
|
386
|
+
return data;
|
|
276
387
|
}
|
|
277
388
|
async function(name, input) {
|
|
278
|
-
|
|
389
|
+
const { data } = await this.client.post(`/v3/system/component/${this.ref}/function/${name}`, input);
|
|
390
|
+
return data;
|
|
279
391
|
}
|
|
280
|
-
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
class ComponentUtils extends PlatformBaseClient {
|
|
395
|
+
async list() {
|
|
281
396
|
const { data } = await this.client.get("/v1/system/components");
|
|
282
397
|
return data;
|
|
283
398
|
}
|
|
284
|
-
async
|
|
285
|
-
|
|
399
|
+
async create(data) {
|
|
400
|
+
const { data: responseData } = await this.client.post("/v3/system/component/create", data);
|
|
401
|
+
return responseData;
|
|
286
402
|
}
|
|
287
403
|
}
|
|
288
404
|
|
|
289
|
-
class
|
|
405
|
+
class Ratchet extends PlatformBaseClient {
|
|
406
|
+
async query(name, params) {
|
|
407
|
+
let res = await this.client.post('/v1/ratchet/query', {
|
|
408
|
+
name: name,
|
|
409
|
+
params: params
|
|
410
|
+
});
|
|
411
|
+
return res.data;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
class Sandbox extends PlatformBaseClient {
|
|
416
|
+
/**
|
|
417
|
+
* Call the sandbox service to execute a serverless function
|
|
418
|
+
*
|
|
419
|
+
* @param name
|
|
420
|
+
* @param data
|
|
421
|
+
* @returns
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* const result = await platform.sandbox().spark("myFunction", { foo: "bar" })
|
|
425
|
+
*/
|
|
426
|
+
async spark(name, data) {
|
|
427
|
+
return await this.client.post(`/v1/project/sandbox/spark/exec/${name}`, data);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
class System extends PlatformBaseClient {
|
|
432
|
+
async resourceResolver(ref, resourceName, format) {
|
|
433
|
+
const { data } = await this.client.post("/v3/system/resource-resolver", {
|
|
434
|
+
type: resourceName,
|
|
435
|
+
format,
|
|
436
|
+
});
|
|
437
|
+
if (format) {
|
|
438
|
+
return data.format;
|
|
439
|
+
}
|
|
440
|
+
return data;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
class Workflow extends PlatformBaseClient {
|
|
445
|
+
async trigger(id, event, data) {
|
|
446
|
+
return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
class Forge extends PlatformBaseClient {
|
|
451
|
+
async bundleUpload(buffer) {
|
|
452
|
+
return await this.client.post(`/v3/system/gateway/app-service/forge/upload`, buffer, {
|
|
453
|
+
headers: {
|
|
454
|
+
'Content-Type': 'application/octet-stream',
|
|
455
|
+
'Content-Length': buffer.length
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
async getWorkspaceApps() {
|
|
460
|
+
return await this.client.get(`/v3/system/gateway/app-service/forge/workspace`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// apis
|
|
465
|
+
class Platform extends PlatformBaseClient {
|
|
466
|
+
getPlatformClient() {
|
|
467
|
+
return this.client;
|
|
468
|
+
}
|
|
469
|
+
getPlatformBaseURL() {
|
|
470
|
+
var _a;
|
|
471
|
+
return (_a = this.client.defaults.baseURL) !== null && _a !== undefined ? _a : "";
|
|
472
|
+
}
|
|
473
|
+
apiUser() {
|
|
474
|
+
return (new APIUser()).setClient(this.client);
|
|
475
|
+
}
|
|
476
|
+
function() {
|
|
477
|
+
return (new Functions()).setClient(this.client);
|
|
478
|
+
}
|
|
479
|
+
role() {
|
|
480
|
+
return (new Roles()).setClient(this.client);
|
|
481
|
+
}
|
|
482
|
+
user() {
|
|
483
|
+
return (new Users()).setClient(this.client);
|
|
484
|
+
}
|
|
485
|
+
app(appType) {
|
|
486
|
+
return (new Apps(appType)).setClient(this.client);
|
|
487
|
+
}
|
|
488
|
+
forge() {
|
|
489
|
+
return (new Forge()).setClient(this.client);
|
|
490
|
+
}
|
|
491
|
+
component(ref) {
|
|
492
|
+
return (new Component(ref)).setClient(this.client);
|
|
493
|
+
}
|
|
494
|
+
componentUtils() {
|
|
495
|
+
return (new ComponentUtils()).setClient(this.client);
|
|
496
|
+
}
|
|
497
|
+
ratchet() {
|
|
498
|
+
return (new Ratchet()).setClient(this.client);
|
|
499
|
+
}
|
|
500
|
+
sandbox() {
|
|
501
|
+
return (new Sandbox()).setClient(this.client);
|
|
502
|
+
}
|
|
503
|
+
system() {
|
|
504
|
+
return (new System()).setClient(this.client);
|
|
505
|
+
}
|
|
506
|
+
workflow() {
|
|
507
|
+
return (new Workflow()).setClient(this.client);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
class Invoicing extends PlatformBaseClient {
|
|
290
512
|
async getSalesInvoices(provider, page) {
|
|
291
513
|
return await this.request("GET", `/invoices/${provider}/sales`, {
|
|
292
514
|
params: {
|
|
@@ -305,13 +527,48 @@ class Invoicing extends BaseClient {
|
|
|
305
527
|
async request(method, endpoint, params) {
|
|
306
528
|
return await this.client.request({
|
|
307
529
|
method: method,
|
|
308
|
-
url: `/v1/karadjordje/${endpoint}`,
|
|
530
|
+
url: `/v1/integrations/karadjordje/${endpoint}`,
|
|
309
531
|
...params
|
|
310
532
|
});
|
|
311
533
|
}
|
|
312
534
|
}
|
|
313
535
|
|
|
314
|
-
class
|
|
536
|
+
class IntegrationsBaseClient extends BaseClient {
|
|
537
|
+
constructor(options) {
|
|
538
|
+
var _a, _b;
|
|
539
|
+
let { env = null, token, host, } = options !== null && options !== undefined ? options : {};
|
|
540
|
+
let headers = {};
|
|
541
|
+
if (isBrowser) {
|
|
542
|
+
if (localStorage.getItem('protokol_context') == "forge") {
|
|
543
|
+
headers['X-Project-Env'] = (_a = localStorage.getItem('forge_app_env')) !== null && _a !== undefined ? _a : "dev";
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
// this potentially means that it is running as dev server in local
|
|
547
|
+
headers['X-Project-Env'] = "dev";
|
|
548
|
+
}
|
|
549
|
+
// @ts-ignore
|
|
550
|
+
const __global_env__ = window === null || window === undefined ? undefined : window.__ENV_VARIABLES__;
|
|
551
|
+
host = (_b = __global_env__.INTEGRATION_API) !== null && _b !== undefined ? _b : host;
|
|
552
|
+
}
|
|
553
|
+
if (token) {
|
|
554
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
555
|
+
}
|
|
556
|
+
if (env) {
|
|
557
|
+
headers['X-Project-Env'] = env;
|
|
558
|
+
}
|
|
559
|
+
const client = axios.create({
|
|
560
|
+
baseURL: host !== null && host !== undefined ? host : "https://orange.protokol.io",
|
|
561
|
+
timeout: 15000,
|
|
562
|
+
headers: {
|
|
563
|
+
...headers,
|
|
564
|
+
},
|
|
565
|
+
withCredentials: true,
|
|
566
|
+
});
|
|
567
|
+
super(client);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
class Media extends IntegrationsBaseClient {
|
|
315
572
|
async list(data) {
|
|
316
573
|
return this.request('POST', 'list', { data });
|
|
317
574
|
}
|
|
@@ -421,7 +678,7 @@ class Media extends BaseClient {
|
|
|
421
678
|
}
|
|
422
679
|
}
|
|
423
680
|
|
|
424
|
-
class SerbiaUtil extends
|
|
681
|
+
class SerbiaUtil extends IntegrationsBaseClient {
|
|
425
682
|
async nsbSearch(params) {
|
|
426
683
|
return await this.services("GET", "nbs/search", { params });
|
|
427
684
|
}
|
|
@@ -448,7 +705,7 @@ class SerbiaUtil extends BaseClient {
|
|
|
448
705
|
}
|
|
449
706
|
}
|
|
450
707
|
|
|
451
|
-
class VPFR extends
|
|
708
|
+
class VPFR extends IntegrationsBaseClient {
|
|
452
709
|
async request(method, endpoint, params) {
|
|
453
710
|
return await this.client.request({
|
|
454
711
|
method: method,
|
|
@@ -458,14 +715,15 @@ class VPFR extends BaseClient {
|
|
|
458
715
|
}
|
|
459
716
|
}
|
|
460
717
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
718
|
+
// import integrations
|
|
719
|
+
class Integrations extends IntegrationsBaseClient {
|
|
720
|
+
constructor(options) {
|
|
721
|
+
super(options);
|
|
464
722
|
this.integrations = {
|
|
465
|
-
'protokol-invoicing': new Invoicing(
|
|
466
|
-
'protokol-vpfr': new VPFR(
|
|
467
|
-
'protokol-media': new Media(
|
|
468
|
-
'serbia-utilities': new SerbiaUtil(
|
|
723
|
+
'protokol-invoicing': new Invoicing().setClient(this.client),
|
|
724
|
+
'protokol-vpfr': new VPFR().setClient(this.client),
|
|
725
|
+
'protokol-media': new Media().setClient(this.client),
|
|
726
|
+
'serbia-utilities': new SerbiaUtil().setClient(this.client),
|
|
469
727
|
};
|
|
470
728
|
}
|
|
471
729
|
getSerbiaUtilities() {
|
|
@@ -494,150 +752,4 @@ class Integrations extends BaseClient {
|
|
|
494
752
|
}
|
|
495
753
|
}
|
|
496
754
|
|
|
497
|
-
|
|
498
|
-
async query(name, params) {
|
|
499
|
-
let res = await this.client.post('/v1/ratchet/query', {
|
|
500
|
-
name: name,
|
|
501
|
-
params: params
|
|
502
|
-
});
|
|
503
|
-
return res.data;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
class Sandbox extends BaseClient {
|
|
508
|
-
async spark(name, data) {
|
|
509
|
-
return await this.client.post(`/v1/project/sandbox/spark/exec/${name}`, data);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
class System extends BaseClient {
|
|
514
|
-
async resourceResolver(ref, resourceName, format) {
|
|
515
|
-
const { data } = await this.client.post("/v3/system/resource-resolver", {
|
|
516
|
-
type: resourceName,
|
|
517
|
-
format,
|
|
518
|
-
});
|
|
519
|
-
if (format) {
|
|
520
|
-
return data.format;
|
|
521
|
-
}
|
|
522
|
-
return data;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
class Workflow extends BaseClient {
|
|
527
|
-
async trigger(id, event, data) {
|
|
528
|
-
return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
class Forge extends BaseClient {
|
|
533
|
-
constructor(client) {
|
|
534
|
-
super(client);
|
|
535
|
-
}
|
|
536
|
-
async bundleUpload(buffer) {
|
|
537
|
-
return await this.client.post(`/v3/system/gateway/app-service/forge/upload`, buffer, {
|
|
538
|
-
headers: {
|
|
539
|
-
'Content-Type': 'application/octet-stream',
|
|
540
|
-
'Content-Length': buffer.length
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
async getWorkspaceApps() {
|
|
545
|
-
return await this.client.get(`/v3/system/gateway/app-service/forge/workspace`);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
typeof process !== "undefined" &&
|
|
550
|
-
process.versions != null &&
|
|
551
|
-
process.versions.node != null;
|
|
552
|
-
const isBrowser = typeof window !== "undefined" &&
|
|
553
|
-
typeof document !== "undefined";
|
|
554
|
-
|
|
555
|
-
class Platform {
|
|
556
|
-
constructor(options) {
|
|
557
|
-
var _a;
|
|
558
|
-
let { project = null, env = null, token, host, integrationHost } = options !== null && options !== undefined ? options : {};
|
|
559
|
-
let headers = {};
|
|
560
|
-
if (isBrowser) {
|
|
561
|
-
if (localStorage.getItem('protokol_context') == "forge") {
|
|
562
|
-
headers['X-Project-Env'] = (_a = localStorage.getItem('forge_app_env')) !== null && _a !== undefined ? _a : "dev";
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
// this potentially means that it is running as dev server in local
|
|
566
|
-
headers['X-Project-Env'] = "dev";
|
|
567
|
-
// here we don't know actual project so we need a way to determine it
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
if (token) {
|
|
571
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
572
|
-
}
|
|
573
|
-
if (env) {
|
|
574
|
-
headers['X-Project-Env'] = env;
|
|
575
|
-
}
|
|
576
|
-
if (project) {
|
|
577
|
-
headers['X-Project-Uuid'] = project;
|
|
578
|
-
}
|
|
579
|
-
this.platformClient = axios.create({
|
|
580
|
-
baseURL: host !== null && host !== undefined ? host : "https://lemon.protokol.io",
|
|
581
|
-
timeout: 15000,
|
|
582
|
-
headers: {
|
|
583
|
-
...headers,
|
|
584
|
-
},
|
|
585
|
-
withCredentials: true,
|
|
586
|
-
});
|
|
587
|
-
this.integrationsClient = axios.create({
|
|
588
|
-
baseURL: integrationHost !== null && integrationHost !== undefined ? integrationHost : "https://orange.protokol.io",
|
|
589
|
-
timeout: 15000,
|
|
590
|
-
headers: {
|
|
591
|
-
...headers,
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
setPlatformClient(client) {
|
|
596
|
-
this.platformClient = client;
|
|
597
|
-
}
|
|
598
|
-
getPlatformClient() {
|
|
599
|
-
return this.platformClient;
|
|
600
|
-
}
|
|
601
|
-
getPlatformBaseURL() {
|
|
602
|
-
var _a;
|
|
603
|
-
return (_a = this.platformClient.defaults.baseURL) !== null && _a !== undefined ? _a : "";
|
|
604
|
-
}
|
|
605
|
-
apiUser() {
|
|
606
|
-
return new APIUser(this.platformClient);
|
|
607
|
-
}
|
|
608
|
-
function() {
|
|
609
|
-
return new Functions(this.platformClient);
|
|
610
|
-
}
|
|
611
|
-
role() {
|
|
612
|
-
return new Roles(this.platformClient);
|
|
613
|
-
}
|
|
614
|
-
user() {
|
|
615
|
-
return new Users(this.platformClient);
|
|
616
|
-
}
|
|
617
|
-
app(appType) {
|
|
618
|
-
return new Apps(this.platformClient, appType);
|
|
619
|
-
}
|
|
620
|
-
forge() {
|
|
621
|
-
return new Forge(this.platformClient);
|
|
622
|
-
}
|
|
623
|
-
component(ref) {
|
|
624
|
-
return new Component(this.platformClient, ref);
|
|
625
|
-
}
|
|
626
|
-
integrations() {
|
|
627
|
-
return new Integrations(this.integrationsClient);
|
|
628
|
-
}
|
|
629
|
-
ratchet() {
|
|
630
|
-
return new Ratchet(this.platformClient);
|
|
631
|
-
}
|
|
632
|
-
sandbox() {
|
|
633
|
-
return new Sandbox(this.platformClient);
|
|
634
|
-
}
|
|
635
|
-
system() {
|
|
636
|
-
return new System(this.platformClient);
|
|
637
|
-
}
|
|
638
|
-
workflow() {
|
|
639
|
-
return new Workflow(this.platformClient);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
export { Platform as default };
|
|
755
|
+
export { APIUser, Apps, Component, ComponentUtils, Functions, Integrations as Integration, Ratchet, Roles, Sandbox, System, Users, Workflow, Platform as default };
|