@ptkl/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +18451 -0
- package/dist/index.esm.js +643 -0
- package/dist/index.umd.js +649 -0
- package/dist/package.json +43 -0
- package/dist/types/api/apiUser.d.ts +9 -0
- package/dist/types/api/apps.d.ts +8 -0
- package/dist/types/api/baseClient.d.ts +5 -0
- package/dist/types/api/component.d.ts +22 -0
- package/dist/types/api/forge.d.ts +6 -0
- package/dist/types/api/functions.d.ts +8 -0
- package/dist/types/api/index.d.ts +13 -0
- package/dist/types/api/integrations/invoicing.d.ts +6 -0
- package/dist/types/api/integrations/media.d.ts +17 -0
- package/dist/types/api/integrations/serbiaUtil.d.ts +8 -0
- package/dist/types/api/integrations/vpfr.d.ts +4 -0
- package/dist/types/api/integrations.d.ts +12 -0
- package/dist/types/api/platform.d.ts +39 -0
- package/dist/types/api/ratchet.d.ts +4 -0
- package/dist/types/api/roles.d.ts +8 -0
- package/dist/types/api/sandbox.d.ts +4 -0
- package/dist/types/api/system.d.ts +4 -0
- package/dist/types/api/thunder.d.ts +13 -0
- package/dist/types/api/users.d.ts +5 -0
- package/dist/types/api/workflow.d.ts +4 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/util/detectEnv.d.ts +3 -0
- package/package.json +43 -0
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('axios')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['axios'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ProtokolSDK = factory(global.axios));
|
|
5
|
+
})(this, (function (axios) { 'use strict';
|
|
6
|
+
|
|
7
|
+
class BaseClient {
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class Functions extends BaseClient {
|
|
14
|
+
async list() {
|
|
15
|
+
return await this.client.get("/v1/system/function");
|
|
16
|
+
}
|
|
17
|
+
async get(ref) {
|
|
18
|
+
return await this.client.get(`/v1/system/function/${ref}`);
|
|
19
|
+
}
|
|
20
|
+
async update(uuid, update) {
|
|
21
|
+
return await this.client.patch(`/v1/system/function/${uuid}`, update);
|
|
22
|
+
}
|
|
23
|
+
async run(id, input, query) {
|
|
24
|
+
const { data } = await this.client.post(`/v1/system/function/run/${id}`, input, {
|
|
25
|
+
params: query || {},
|
|
26
|
+
});
|
|
27
|
+
return data.data;
|
|
28
|
+
}
|
|
29
|
+
async generateSignature(ref, env) {
|
|
30
|
+
return await this.client.get(`/v1/system/function/signature/${env}/${ref}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class Roles extends BaseClient {
|
|
35
|
+
async create(role) {
|
|
36
|
+
const res = await this.client.post("/v1/user/role/create", role);
|
|
37
|
+
// writeFileSync(`.role.create.json`,JSON.stringify(res))
|
|
38
|
+
return res.data;
|
|
39
|
+
}
|
|
40
|
+
async delete(uuid) {
|
|
41
|
+
const { data } = await this.client.delete(`/v1/user/role/delete/${uuid}`);
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
async list() {
|
|
45
|
+
const { data } = await this.client.get(`/v1/user/role/list`);
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
async listPermissions() {
|
|
49
|
+
const { data } = await this.client.get(`/v1/user/permissions/list`);
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
async edit(permissions, workspaces, level, uuid) {
|
|
53
|
+
const { data } = await this.client.post(`/v1/user/role/edit/${uuid}`, { permissions, workspaces, level });
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class APIUser extends BaseClient {
|
|
59
|
+
async apiAuth(username, password) {
|
|
60
|
+
return this.client.post("/v1/user/api/auth", {
|
|
61
|
+
username,
|
|
62
|
+
password
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async newSecret(uuid) {
|
|
66
|
+
return await this.client.post(`/v1/user/api-user/secret/${uuid}`, {});
|
|
67
|
+
}
|
|
68
|
+
async revokeSecret(uuid) {
|
|
69
|
+
return await this.client.delete(`/v1/user/api-user/secret/${uuid}`);
|
|
70
|
+
}
|
|
71
|
+
async edit(uuid, roles) {
|
|
72
|
+
return await this.client.patch(`/v1/user/api-user/${uuid}`, { roles });
|
|
73
|
+
}
|
|
74
|
+
async list() {
|
|
75
|
+
return await this.client.get(`/v1/user/api-user`);
|
|
76
|
+
}
|
|
77
|
+
async get(uuid) {
|
|
78
|
+
return await this.client.get(`/v1/user/api-user/${uuid}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
class Users extends BaseClient {
|
|
83
|
+
async invite(email, roles) {
|
|
84
|
+
return await this.client.post("/v1/project/invite", {
|
|
85
|
+
email,
|
|
86
|
+
roles,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async delete(uuid) {
|
|
90
|
+
return await this.client.delete(`/v1/project/user/${uuid}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
class Apps extends BaseClient {
|
|
95
|
+
constructor(client, appType) {
|
|
96
|
+
super(client);
|
|
97
|
+
this.appType = appType;
|
|
98
|
+
}
|
|
99
|
+
async updateSettings(updateValues, ref) {
|
|
100
|
+
const payload = { ...updateValues };
|
|
101
|
+
return await this.client.put(`/v3/system/gateway/app-service/${this.appType}/${ref}/settings`, payload);
|
|
102
|
+
}
|
|
103
|
+
async download(ref, version) {
|
|
104
|
+
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
|
|
105
|
+
}
|
|
106
|
+
async upload(formData) {
|
|
107
|
+
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class Component extends BaseClient {
|
|
112
|
+
constructor(adapter, ref) {
|
|
113
|
+
super(adapter);
|
|
114
|
+
this.ref = ref;
|
|
115
|
+
}
|
|
116
|
+
new(ref) {
|
|
117
|
+
this.ref = ref;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
find(filters, opts) {
|
|
121
|
+
const { cache = false, buildttl = -1, locale = "en_US" } = opts !== null && opts !== undefined ? opts : {};
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
let payload = {
|
|
124
|
+
context: filters,
|
|
125
|
+
ref: this.ref,
|
|
126
|
+
};
|
|
127
|
+
let ctx = payload.context;
|
|
128
|
+
let offset = ctx.currentPage;
|
|
129
|
+
if (offset == undefined) {
|
|
130
|
+
offset = 0;
|
|
131
|
+
}
|
|
132
|
+
let limit = ctx.perPage;
|
|
133
|
+
if (limit == undefined || limit == -1) {
|
|
134
|
+
limit = 10;
|
|
135
|
+
}
|
|
136
|
+
let sortDesc = 1;
|
|
137
|
+
if (ctx.sortDesc) {
|
|
138
|
+
sortDesc = -1;
|
|
139
|
+
}
|
|
140
|
+
if (ctx.filterOn === undefined) {
|
|
141
|
+
ctx.filterOn = [];
|
|
142
|
+
}
|
|
143
|
+
let params = {
|
|
144
|
+
offset: offset,
|
|
145
|
+
sortBy: ctx.sortBy,
|
|
146
|
+
sortDesc: sortDesc,
|
|
147
|
+
filter: ctx.filter,
|
|
148
|
+
filterOn: ctx.filterOn.join(","),
|
|
149
|
+
disabled: ctx.disabled,
|
|
150
|
+
limit: limit,
|
|
151
|
+
dateFrom: ctx.dateFrom,
|
|
152
|
+
dateTo: ctx.dateTo,
|
|
153
|
+
dateField: ctx.dateField,
|
|
154
|
+
};
|
|
155
|
+
if (Object.keys(ctx.$adv || []).length > 0) {
|
|
156
|
+
params.$adv = JSON.stringify([ctx.$adv]);
|
|
157
|
+
}
|
|
158
|
+
if (ctx.$aggregate && ctx.$aggregate.length > 0) {
|
|
159
|
+
params.$aggregate = JSON.stringify(ctx.$aggregate);
|
|
160
|
+
}
|
|
161
|
+
Object.keys(opts || {}).forEach(k => {
|
|
162
|
+
params[`_opt_${k}`] = opts[k];
|
|
163
|
+
});
|
|
164
|
+
this.client.get(`/v3/system/component/${this.ref}/models`, {
|
|
165
|
+
params: params,
|
|
166
|
+
headers: {
|
|
167
|
+
'X-Cache': cache,
|
|
168
|
+
'X-Build-Ttl': buildttl,
|
|
169
|
+
'Accept-Language': locale
|
|
170
|
+
}
|
|
171
|
+
}).then((resp) => {
|
|
172
|
+
let { data = [] } = resp || {};
|
|
173
|
+
resolve(data);
|
|
174
|
+
}).catch((err) => {
|
|
175
|
+
reject(err);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async findOne(filter, opts) {
|
|
180
|
+
const { items } = await this.find({
|
|
181
|
+
$adv: filter
|
|
182
|
+
}, opts);
|
|
183
|
+
if (items && items.length > 0) {
|
|
184
|
+
return items[0];
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
get(uuid) {
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`).then((resp) => {
|
|
191
|
+
resolve(resp.data);
|
|
192
|
+
}).catch((error) => {
|
|
193
|
+
reject(error);
|
|
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
|
+
});
|
|
207
|
+
}
|
|
208
|
+
concurrentUpdate(uuid, version, model) {
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
211
|
+
version: version,
|
|
212
|
+
data: model
|
|
213
|
+
}).then((resp) => {
|
|
214
|
+
resolve(resp.data);
|
|
215
|
+
}).catch((error) => {
|
|
216
|
+
reject(error);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
create(model) {
|
|
221
|
+
return new Promise((resolve, reject) => {
|
|
222
|
+
this.client.post(`/v3/system/component/${this.ref}/model`, model).then((resp) => {
|
|
223
|
+
resolve(resp.data);
|
|
224
|
+
}).catch((error) => {
|
|
225
|
+
reject(error);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
delete(uuid) {
|
|
230
|
+
return new Promise((resolve, reject) => {
|
|
231
|
+
this.client.delete(`/v3/system/component/${this.ref}/model/${uuid}`).then((resp) => {
|
|
232
|
+
resolve(resp.data);
|
|
233
|
+
}).catch((error) => {
|
|
234
|
+
reject(error);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
aggregate(payload) {
|
|
239
|
+
return new Promise((resolve, reject) => {
|
|
240
|
+
this.client.post(`/v3/system/component/${this.ref}/aggregate`, payload).then((resp) => {
|
|
241
|
+
resolve(resp.data);
|
|
242
|
+
}).catch((error) => {
|
|
243
|
+
reject(error);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
settings() {
|
|
248
|
+
return new Promise((resolve, reject) => {
|
|
249
|
+
this.client.get(`/v3/system/component/settings/${this.ref}`).then((resp) => {
|
|
250
|
+
resolve(resp.data);
|
|
251
|
+
}).catch(err => {
|
|
252
|
+
reject(err);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
saveSettings(settings) {
|
|
257
|
+
return new Promise((resolve, reject) => {
|
|
258
|
+
this.client.post("/v3/system/component/settings/" + settings.general.uuid + "/" + settings.settings.version, settings).then((resp) => {
|
|
259
|
+
resolve(resp.data);
|
|
260
|
+
}).catch(err => {
|
|
261
|
+
reject(err);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
async saveTemplatesDist(version, sdkVersion, engine, dist) {
|
|
266
|
+
const { data } = await this.client.post(`/v3/system/component/templates/${this.ref}/${version}`, {
|
|
267
|
+
templates_dist: {
|
|
268
|
+
sdk_version: sdkVersion,
|
|
269
|
+
sdk_engine: engine,
|
|
270
|
+
dist,
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
return data;
|
|
274
|
+
}
|
|
275
|
+
async workflow(event, input) {
|
|
276
|
+
return await this.client.post("/v1/system/component/" + this.ref + "/workflow/event", {
|
|
277
|
+
event,
|
|
278
|
+
input
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
async function(name, input) {
|
|
282
|
+
return await this.client.post(`/v3/system/component/${this.ref}/function/${name}`, input);
|
|
283
|
+
}
|
|
284
|
+
async all() {
|
|
285
|
+
const { data } = await this.client.get("/v1/system/components");
|
|
286
|
+
return data;
|
|
287
|
+
}
|
|
288
|
+
async setup(data) {
|
|
289
|
+
return await this.client.post("/v3/system/component/create", data);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
class Invoicing extends BaseClient {
|
|
294
|
+
async getSalesInvoices(provider, page) {
|
|
295
|
+
return await this.request("GET", `/invoices/${provider}/sales`, {
|
|
296
|
+
params: {
|
|
297
|
+
page: page || 1
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async acceptPurchaseInvoice(provider, id, comment) {
|
|
302
|
+
return await this.request('POST', `/invoices/${provider}/purchase/acceptReject/${id}`, {
|
|
303
|
+
data: {
|
|
304
|
+
accepted: true,
|
|
305
|
+
comment: comment
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async request(method, endpoint, params) {
|
|
310
|
+
return await this.client.request({
|
|
311
|
+
method: method,
|
|
312
|
+
url: `/v1/karadjordje/${endpoint}`,
|
|
313
|
+
...params
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
class Media extends BaseClient {
|
|
319
|
+
async list(data) {
|
|
320
|
+
return this.request('POST', 'list', { data });
|
|
321
|
+
}
|
|
322
|
+
async libraries() {
|
|
323
|
+
return await this.requestv1("GET", "library/list");
|
|
324
|
+
}
|
|
325
|
+
async upload(payload) {
|
|
326
|
+
let files = payload.files;
|
|
327
|
+
let formData = new FormData();
|
|
328
|
+
let count = 0;
|
|
329
|
+
files.forEach((file, index) => {
|
|
330
|
+
let rename = file.rename || file.name;
|
|
331
|
+
let orgExt = file.name.split('.');
|
|
332
|
+
rename = `${rename}.${orgExt[orgExt.length - 1]}`;
|
|
333
|
+
formData.append('file', file, rename);
|
|
334
|
+
count++;
|
|
335
|
+
});
|
|
336
|
+
if (count == files.length) {
|
|
337
|
+
formData.append('path', payload.uploadDir);
|
|
338
|
+
formData.append('ref', payload.uuid);
|
|
339
|
+
if (payload.public) {
|
|
340
|
+
formData.append('is_public', "true");
|
|
341
|
+
}
|
|
342
|
+
if (payload.expiresAt)
|
|
343
|
+
formData.append('expiresAt', new Date(payload.expiresAt).toISOString());
|
|
344
|
+
if (Object.keys(payload.metadata).length > 0)
|
|
345
|
+
formData.append('metadata', JSON.stringify(payload.metadata));
|
|
346
|
+
return await this.request("POST", "", {
|
|
347
|
+
data: formData,
|
|
348
|
+
headers: {
|
|
349
|
+
'Content-Type': 'multipart/form-data'
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
async delete(data) {
|
|
355
|
+
return this.request('POST', 'delete', data);
|
|
356
|
+
}
|
|
357
|
+
async uploadBase64(data) {
|
|
358
|
+
return this.request('POST', ``, {
|
|
359
|
+
data,
|
|
360
|
+
headers: {
|
|
361
|
+
'Content-Type': 'application/json'
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
async getMedia(lib, key, encoding) {
|
|
366
|
+
return this.request('GET', `library/${lib}/get/${key}`, {
|
|
367
|
+
params: {
|
|
368
|
+
encoding
|
|
369
|
+
},
|
|
370
|
+
responseType: (!encoding) ? 'blob' : null
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
async download(lib, key) {
|
|
374
|
+
return this.request('POST', `library/${lib}/download`, {
|
|
375
|
+
data: {
|
|
376
|
+
key
|
|
377
|
+
},
|
|
378
|
+
responseType: 'blob'
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
async getExifData(lib, key) {
|
|
382
|
+
return this.request('GET', `library/${lib}/exif/${key}`);
|
|
383
|
+
}
|
|
384
|
+
async html2pdf(lib, data) {
|
|
385
|
+
const { output_pdf = false, input_path, input_html, output_path, output_file_name, data: templateData } = data;
|
|
386
|
+
const type = output_pdf ? 'arraybuffer' : 'json';
|
|
387
|
+
const contentType = output_pdf ? 'application/pdf' : 'application/json';
|
|
388
|
+
return this.request('POST', `library/${lib}/html2pdf`, {
|
|
389
|
+
data: {
|
|
390
|
+
output_pdf,
|
|
391
|
+
input_path,
|
|
392
|
+
output_path,
|
|
393
|
+
input_html,
|
|
394
|
+
output_file_name,
|
|
395
|
+
data: templateData
|
|
396
|
+
},
|
|
397
|
+
headers: {
|
|
398
|
+
'Content-Type': contentType
|
|
399
|
+
},
|
|
400
|
+
responseType: type
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
async createDir(lib, path) {
|
|
404
|
+
return this.request('POST', `library/${lib}/dir`, { data: { path } });
|
|
405
|
+
}
|
|
406
|
+
async deleteDir(lib, path) {
|
|
407
|
+
return this.request('POST', `library/${lib}/delete/dir`, { data: { path } });
|
|
408
|
+
}
|
|
409
|
+
async dirs(lib, data) {
|
|
410
|
+
return await this.request("POST", `library/${lib}/dirs`, { data });
|
|
411
|
+
}
|
|
412
|
+
async request(method, endpoint, params) {
|
|
413
|
+
return await this.client.request({
|
|
414
|
+
method: method,
|
|
415
|
+
url: `/v2/media/${endpoint}`,
|
|
416
|
+
...params
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
async requestv1(method, endpoint, params) {
|
|
420
|
+
return await this.client.request({
|
|
421
|
+
method: method,
|
|
422
|
+
url: `/v1/media/${endpoint}`,
|
|
423
|
+
...params
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
class SerbiaUtil extends BaseClient {
|
|
429
|
+
async nsbSearch(params) {
|
|
430
|
+
return await this.services("GET", "nbs/search", { params });
|
|
431
|
+
}
|
|
432
|
+
async getReceiptFromUrl(url, source) {
|
|
433
|
+
return await this.services("POST", "receipt/crawl", {
|
|
434
|
+
data: {
|
|
435
|
+
url,
|
|
436
|
+
source
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
async getContoList() {
|
|
441
|
+
return await this.services("GET", "conto");
|
|
442
|
+
}
|
|
443
|
+
async services(method, endpoint, params) {
|
|
444
|
+
return this.request(method, `services/${endpoint}`, params);
|
|
445
|
+
}
|
|
446
|
+
async request(method, endpoint, params) {
|
|
447
|
+
return await this.client.request({
|
|
448
|
+
method: method,
|
|
449
|
+
url: `/v1/karadjordje/${endpoint}`,
|
|
450
|
+
...params
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
class VPFR extends BaseClient {
|
|
456
|
+
async request(method, endpoint, params) {
|
|
457
|
+
return await this.client.request({
|
|
458
|
+
method: method,
|
|
459
|
+
url: `/v1/karadjordje/vpfr/${endpoint}`,
|
|
460
|
+
...params
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
class Integrations extends BaseClient {
|
|
466
|
+
constructor(adapter) {
|
|
467
|
+
super(adapter);
|
|
468
|
+
this.integrations = {
|
|
469
|
+
'protokol-invoicing': new Invoicing(adapter),
|
|
470
|
+
'protokol-vpfr': new VPFR(adapter),
|
|
471
|
+
'protokol-media': new Media(adapter),
|
|
472
|
+
'serbia-utilities': new SerbiaUtil(adapter)
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
getSerbiaUtilities() {
|
|
476
|
+
return this.getInterfaceOf('serbia-utilities');
|
|
477
|
+
}
|
|
478
|
+
getMedia() {
|
|
479
|
+
return this.getInterfaceOf('protokol-media');
|
|
480
|
+
}
|
|
481
|
+
getVPFR() {
|
|
482
|
+
return this.getInterfaceOf('protokol-vpfr');
|
|
483
|
+
}
|
|
484
|
+
getInvoicing() {
|
|
485
|
+
return this.getInterfaceOf('protokol-invoicing');
|
|
486
|
+
}
|
|
487
|
+
async isInstalled(id) {
|
|
488
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
489
|
+
return data.find((i) => i.id == id) !== undefined;
|
|
490
|
+
}
|
|
491
|
+
getInterfaceOf(id) {
|
|
492
|
+
try {
|
|
493
|
+
return this.integrations[id];
|
|
494
|
+
}
|
|
495
|
+
catch {
|
|
496
|
+
throw new Error(`Interface ${id} not provided`);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
class Ratchet extends BaseClient {
|
|
502
|
+
async query(name, params) {
|
|
503
|
+
let res = await this.client.post('/v1/ratchet/query', {
|
|
504
|
+
name: name,
|
|
505
|
+
params: params
|
|
506
|
+
});
|
|
507
|
+
return res.data;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
class Sandbox extends BaseClient {
|
|
512
|
+
async spark(name, data) {
|
|
513
|
+
return await this.client.post(`/v1/project/sandbox/spark/exec/${name}`, data);
|
|
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
|
+
}
|
|
646
|
+
|
|
647
|
+
return Platform;
|
|
648
|
+
|
|
649
|
+
}));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "protokol-sdk",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "rollup -c"
|
|
6
|
+
},
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.esm.js",
|
|
13
|
+
"require": "./dist/index.cjs.js",
|
|
14
|
+
"types": "./dist/types/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"main": "./dist/index.cjs.js",
|
|
18
|
+
"module": "./dist/index.esm.js",
|
|
19
|
+
"types": "./dist/types/index.d.ts",
|
|
20
|
+
"author": "protokol.io",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"description": "",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
26
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
27
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
28
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
29
|
+
"@types/babel__standalone": "^7.1.9",
|
|
30
|
+
"@types/lodash": "^4.17.13",
|
|
31
|
+
"@types/node": "^22.9.0",
|
|
32
|
+
"rollup": "^4.30.1",
|
|
33
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
34
|
+
"typescript": "^5.6.3",
|
|
35
|
+
"rollup-plugin-copy": "^3.5.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
39
|
+
"axios": "^1.7.7",
|
|
40
|
+
"dom-parser": "^1.1.5",
|
|
41
|
+
"lodash": "^4.17.21"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import BaseClient from "./baseClient";
|
|
2
|
+
export default class APIUser extends BaseClient {
|
|
3
|
+
apiAuth(username: string, password: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
4
|
+
newSecret(uuid: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
5
|
+
revokeSecret(uuid: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
6
|
+
edit(uuid: string, roles: string[]): Promise<import("axios").AxiosResponse<any, any>>;
|
|
7
|
+
list(): Promise<any>;
|
|
8
|
+
get(uuid: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
9
|
+
}
|