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