@ptkl/sdk 0.1.0 → 0.2.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 +16 -0
- package/dist/index.cjs.js +158 -22
- package/dist/index.esm.js +145 -22
- package/dist/index.umd.js +162 -26
- package/dist/package.json +7 -5
- package/dist/types/api/component.d.ts +55 -6
- package/dist/types/api/functions.d.ts +16 -1
- package/dist/types/api/platform.d.ts +0 -1
- package/dist/types/api/sandbox.d.ts +10 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/types/component.d.ts +44 -0
- package/package.json +6 -4
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
To use the SDK, you’ll first need to generate an access token.
|
|
2
|
+
|
|
3
|
+
If you haven’t created any users or roles yet, head to the **IAM** section in the dashboard. Start by creating a [role](https://platform.protokol.io/admin/users/roles), then create a [user](https://platform.protokol.io/admin/users) and assign the appropriate role(s) to them.
|
|
4
|
+
|
|
5
|
+
Once your user is set up, go to their **API user edit page**. From there, you can generate a new secret or create a token for an existing secret by clicking the **"Generate secret"** button.
|
|
6
|
+
|
|
7
|
+
### Usage
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
const platform = new Platform({
|
|
11
|
+
token: // your generated token
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
// now you can
|
|
15
|
+
const results = await platform.function().run("hello_world", {text: "Hi!"})
|
|
16
|
+
```
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
3
5
|
var require$$1 = require('util');
|
|
4
6
|
var stream = require('stream');
|
|
5
7
|
var require$$1$1 = require('path');
|
|
@@ -17824,9 +17826,21 @@ class Functions extends BaseClient {
|
|
|
17824
17826
|
async update(uuid, update) {
|
|
17825
17827
|
return await this.client.patch(`/v1/system/function/${uuid}`, update);
|
|
17826
17828
|
}
|
|
17827
|
-
|
|
17828
|
-
|
|
17829
|
-
|
|
17829
|
+
/**
|
|
17830
|
+
* Run platform function
|
|
17831
|
+
*
|
|
17832
|
+
* @param id - Function ID
|
|
17833
|
+
* @param input - Input data
|
|
17834
|
+
* @param query - Query parameters
|
|
17835
|
+
* @returns - Function result
|
|
17836
|
+
*
|
|
17837
|
+
* @example
|
|
17838
|
+
* const result = await platform.function().run("myFunction", { foo: "bar" }, { queryParam: "value" })
|
|
17839
|
+
*/
|
|
17840
|
+
async run(id, d) {
|
|
17841
|
+
const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
|
|
17842
|
+
params: d.query,
|
|
17843
|
+
headers: d.headers
|
|
17830
17844
|
});
|
|
17831
17845
|
return data.data;
|
|
17832
17846
|
}
|
|
@@ -17835,6 +17849,11 @@ class Functions extends BaseClient {
|
|
|
17835
17849
|
}
|
|
17836
17850
|
}
|
|
17837
17851
|
|
|
17852
|
+
var functions = /*#__PURE__*/Object.freeze({
|
|
17853
|
+
__proto__: null,
|
|
17854
|
+
default: Functions
|
|
17855
|
+
});
|
|
17856
|
+
|
|
17838
17857
|
class Roles extends BaseClient {
|
|
17839
17858
|
async create(role) {
|
|
17840
17859
|
const res = await this.client.post("/v1/user/role/create", role);
|
|
@@ -17859,6 +17878,11 @@ class Roles extends BaseClient {
|
|
|
17859
17878
|
}
|
|
17860
17879
|
}
|
|
17861
17880
|
|
|
17881
|
+
var roles = /*#__PURE__*/Object.freeze({
|
|
17882
|
+
__proto__: null,
|
|
17883
|
+
default: Roles
|
|
17884
|
+
});
|
|
17885
|
+
|
|
17862
17886
|
class APIUser extends BaseClient {
|
|
17863
17887
|
async apiAuth(username, password) {
|
|
17864
17888
|
return this.client.post("/v1/user/api/auth", {
|
|
@@ -17883,6 +17907,11 @@ class APIUser extends BaseClient {
|
|
|
17883
17907
|
}
|
|
17884
17908
|
}
|
|
17885
17909
|
|
|
17910
|
+
var apiUser = /*#__PURE__*/Object.freeze({
|
|
17911
|
+
__proto__: null,
|
|
17912
|
+
default: APIUser
|
|
17913
|
+
});
|
|
17914
|
+
|
|
17886
17915
|
class Users extends BaseClient {
|
|
17887
17916
|
async invite(email, roles) {
|
|
17888
17917
|
return await this.client.post("/v1/project/invite", {
|
|
@@ -17895,6 +17924,11 @@ class Users extends BaseClient {
|
|
|
17895
17924
|
}
|
|
17896
17925
|
}
|
|
17897
17926
|
|
|
17927
|
+
var users = /*#__PURE__*/Object.freeze({
|
|
17928
|
+
__proto__: null,
|
|
17929
|
+
default: Users
|
|
17930
|
+
});
|
|
17931
|
+
|
|
17898
17932
|
class Apps extends BaseClient {
|
|
17899
17933
|
constructor(client, appType) {
|
|
17900
17934
|
super(client);
|
|
@@ -17908,10 +17942,17 @@ class Apps extends BaseClient {
|
|
|
17908
17942
|
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
|
|
17909
17943
|
}
|
|
17910
17944
|
async upload(formData) {
|
|
17911
|
-
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData
|
|
17945
|
+
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
|
|
17946
|
+
timeout: 60000
|
|
17947
|
+
});
|
|
17912
17948
|
}
|
|
17913
17949
|
}
|
|
17914
17950
|
|
|
17951
|
+
var apps = /*#__PURE__*/Object.freeze({
|
|
17952
|
+
__proto__: null,
|
|
17953
|
+
default: Apps
|
|
17954
|
+
});
|
|
17955
|
+
|
|
17915
17956
|
class Component extends BaseClient {
|
|
17916
17957
|
constructor(adapter, ref) {
|
|
17917
17958
|
super(adapter);
|
|
@@ -17921,8 +17962,29 @@ class Component extends BaseClient {
|
|
|
17921
17962
|
this.ref = ref;
|
|
17922
17963
|
return this;
|
|
17923
17964
|
}
|
|
17965
|
+
/**
|
|
17966
|
+
* Find method to search for models
|
|
17967
|
+
*
|
|
17968
|
+
* @param {FindParams} filters - The filters to apply to the search
|
|
17969
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
17970
|
+
*
|
|
17971
|
+
* @returns {Promise<FindResponse>} - The result of the search
|
|
17972
|
+
*
|
|
17973
|
+
* @example
|
|
17974
|
+
* platform.component(name).find({
|
|
17975
|
+
* currentPage: 1,
|
|
17976
|
+
* perPage: 10,
|
|
17977
|
+
* })
|
|
17978
|
+
*
|
|
17979
|
+
* // advanced search
|
|
17980
|
+
* platform.component(name).find({
|
|
17981
|
+
* $adv: {
|
|
17982
|
+
* name: "John Doe",
|
|
17983
|
+
* }
|
|
17984
|
+
* )
|
|
17985
|
+
**/
|
|
17924
17986
|
find(filters, opts) {
|
|
17925
|
-
const { cache = false, buildttl = -1, locale = "en_US" } = opts !== null && opts !== undefined ? opts : {};
|
|
17987
|
+
const { cache = false, buildttl = -1, locale = "en_US", } = opts !== null && opts !== undefined ? opts : {};
|
|
17926
17988
|
return new Promise((resolve, reject) => {
|
|
17927
17989
|
let payload = {
|
|
17928
17990
|
context: filters,
|
|
@@ -17950,7 +18012,6 @@ class Component extends BaseClient {
|
|
|
17950
18012
|
sortDesc: sortDesc,
|
|
17951
18013
|
filter: ctx.filter,
|
|
17952
18014
|
filterOn: ctx.filterOn.join(","),
|
|
17953
|
-
disabled: ctx.disabled,
|
|
17954
18015
|
limit: limit,
|
|
17955
18016
|
dateFrom: ctx.dateFrom,
|
|
17956
18017
|
dateTo: ctx.dateTo,
|
|
@@ -17962,9 +18023,11 @@ class Component extends BaseClient {
|
|
|
17962
18023
|
if (ctx.$aggregate && ctx.$aggregate.length > 0) {
|
|
17963
18024
|
params.$aggregate = JSON.stringify(ctx.$aggregate);
|
|
17964
18025
|
}
|
|
17965
|
-
|
|
17966
|
-
|
|
17967
|
-
|
|
18026
|
+
if (opts) {
|
|
18027
|
+
Object.keys(opts).forEach(k => {
|
|
18028
|
+
params[`_opt_${k}`] = opts ? opts[k] : null;
|
|
18029
|
+
});
|
|
18030
|
+
}
|
|
17968
18031
|
this.client.get(`/v3/system/component/${this.ref}/models`, {
|
|
17969
18032
|
params: params,
|
|
17970
18033
|
headers: {
|
|
@@ -17980,6 +18043,19 @@ class Component extends BaseClient {
|
|
|
17980
18043
|
});
|
|
17981
18044
|
});
|
|
17982
18045
|
}
|
|
18046
|
+
/**
|
|
18047
|
+
* FindOne method to search for a single model
|
|
18048
|
+
*
|
|
18049
|
+
* @param {FindAdvancedParams} filter - The filters to apply to the search
|
|
18050
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
18051
|
+
*
|
|
18052
|
+
* @returns {Promise<?Model>} - The result of the search
|
|
18053
|
+
*
|
|
18054
|
+
* @example
|
|
18055
|
+
* platform.component(name).findOne({
|
|
18056
|
+
* name: "John Doe",
|
|
18057
|
+
* })
|
|
18058
|
+
**/
|
|
17983
18059
|
async findOne(filter, opts) {
|
|
17984
18060
|
const { items } = await this.find({
|
|
17985
18061
|
$adv: filter
|
|
@@ -17989,6 +18065,12 @@ class Component extends BaseClient {
|
|
|
17989
18065
|
}
|
|
17990
18066
|
return null;
|
|
17991
18067
|
}
|
|
18068
|
+
/**
|
|
18069
|
+
* Get model by uuid
|
|
18070
|
+
*
|
|
18071
|
+
* @param uuid string - The uuid of the model
|
|
18072
|
+
* @returns (Promise<Model>)
|
|
18073
|
+
*/
|
|
17992
18074
|
get(uuid) {
|
|
17993
18075
|
return new Promise((resolve, reject) => {
|
|
17994
18076
|
this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`).then((resp) => {
|
|
@@ -17998,10 +18080,17 @@ class Component extends BaseClient {
|
|
|
17998
18080
|
});
|
|
17999
18081
|
});
|
|
18000
18082
|
}
|
|
18001
|
-
|
|
18083
|
+
/**
|
|
18084
|
+
* Update model by uuid
|
|
18085
|
+
*
|
|
18086
|
+
* @param uuid string - The uuid of the model
|
|
18087
|
+
* @param data
|
|
18088
|
+
* @returns
|
|
18089
|
+
*/
|
|
18090
|
+
update(uuid, data) {
|
|
18002
18091
|
return new Promise((resolve, reject) => {
|
|
18003
18092
|
this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
18004
|
-
data
|
|
18093
|
+
data,
|
|
18005
18094
|
}).then((resp) => {
|
|
18006
18095
|
resolve(resp.data);
|
|
18007
18096
|
}).catch((error) => {
|
|
@@ -18009,11 +18098,11 @@ class Component extends BaseClient {
|
|
|
18009
18098
|
});
|
|
18010
18099
|
});
|
|
18011
18100
|
}
|
|
18012
|
-
concurrentUpdate(uuid, version,
|
|
18101
|
+
concurrentUpdate(uuid, version, data) {
|
|
18013
18102
|
return new Promise((resolve, reject) => {
|
|
18014
18103
|
this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
18015
18104
|
version: version,
|
|
18016
|
-
data
|
|
18105
|
+
data,
|
|
18017
18106
|
}).then((resp) => {
|
|
18018
18107
|
resolve(resp.data);
|
|
18019
18108
|
}).catch((error) => {
|
|
@@ -18039,9 +18128,9 @@ class Component extends BaseClient {
|
|
|
18039
18128
|
});
|
|
18040
18129
|
});
|
|
18041
18130
|
}
|
|
18042
|
-
aggregate(
|
|
18131
|
+
aggregate(pipeline) {
|
|
18043
18132
|
return new Promise((resolve, reject) => {
|
|
18044
|
-
this.client.post(`/v3/system/component/${this.ref}/aggregate`,
|
|
18133
|
+
this.client.post(`/v3/system/component/${this.ref}/aggregate`, pipeline).then((resp) => {
|
|
18045
18134
|
resolve(resp.data);
|
|
18046
18135
|
}).catch((error) => {
|
|
18047
18136
|
reject(error);
|
|
@@ -18077,7 +18166,7 @@ class Component extends BaseClient {
|
|
|
18077
18166
|
return data;
|
|
18078
18167
|
}
|
|
18079
18168
|
async workflow(event, input) {
|
|
18080
|
-
return await this.client.post(
|
|
18169
|
+
return await this.client.post(`/v1/system/component/${this.ref}/workflow/event`, {
|
|
18081
18170
|
event,
|
|
18082
18171
|
input
|
|
18083
18172
|
});
|
|
@@ -18094,6 +18183,11 @@ class Component extends BaseClient {
|
|
|
18094
18183
|
}
|
|
18095
18184
|
}
|
|
18096
18185
|
|
|
18186
|
+
var component = /*#__PURE__*/Object.freeze({
|
|
18187
|
+
__proto__: null,
|
|
18188
|
+
default: Component
|
|
18189
|
+
});
|
|
18190
|
+
|
|
18097
18191
|
class Invoicing extends BaseClient {
|
|
18098
18192
|
async getSalesInvoices(provider, page) {
|
|
18099
18193
|
return await this.request("GET", `/invoices/${provider}/sales`, {
|
|
@@ -18302,6 +18396,11 @@ class Integrations extends BaseClient {
|
|
|
18302
18396
|
}
|
|
18303
18397
|
}
|
|
18304
18398
|
|
|
18399
|
+
var integrations = /*#__PURE__*/Object.freeze({
|
|
18400
|
+
__proto__: null,
|
|
18401
|
+
default: Integrations
|
|
18402
|
+
});
|
|
18403
|
+
|
|
18305
18404
|
class Ratchet extends BaseClient {
|
|
18306
18405
|
async query(name, params) {
|
|
18307
18406
|
let res = await this.client.post('/v1/ratchet/query', {
|
|
@@ -18312,12 +18411,32 @@ class Ratchet extends BaseClient {
|
|
|
18312
18411
|
}
|
|
18313
18412
|
}
|
|
18314
18413
|
|
|
18414
|
+
var ratchet = /*#__PURE__*/Object.freeze({
|
|
18415
|
+
__proto__: null,
|
|
18416
|
+
default: Ratchet
|
|
18417
|
+
});
|
|
18418
|
+
|
|
18315
18419
|
class Sandbox extends BaseClient {
|
|
18420
|
+
/**
|
|
18421
|
+
* Call the sandbox service to execute a serverless function
|
|
18422
|
+
*
|
|
18423
|
+
* @param name
|
|
18424
|
+
* @param data
|
|
18425
|
+
* @returns
|
|
18426
|
+
*
|
|
18427
|
+
* @example
|
|
18428
|
+
* const result = await platform.sandbox().spark("myFunction", { foo: "bar" })
|
|
18429
|
+
*/
|
|
18316
18430
|
async spark(name, data) {
|
|
18317
18431
|
return await this.client.post(`/v1/project/sandbox/spark/exec/${name}`, data);
|
|
18318
18432
|
}
|
|
18319
18433
|
}
|
|
18320
18434
|
|
|
18435
|
+
var sandbox = /*#__PURE__*/Object.freeze({
|
|
18436
|
+
__proto__: null,
|
|
18437
|
+
default: Sandbox
|
|
18438
|
+
});
|
|
18439
|
+
|
|
18321
18440
|
class System extends BaseClient {
|
|
18322
18441
|
async resourceResolver(ref, resourceName, format) {
|
|
18323
18442
|
const { data } = await this.client.post("/v3/system/resource-resolver", {
|
|
@@ -18331,12 +18450,22 @@ class System extends BaseClient {
|
|
|
18331
18450
|
}
|
|
18332
18451
|
}
|
|
18333
18452
|
|
|
18453
|
+
var system = /*#__PURE__*/Object.freeze({
|
|
18454
|
+
__proto__: null,
|
|
18455
|
+
default: System
|
|
18456
|
+
});
|
|
18457
|
+
|
|
18334
18458
|
class Workflow extends BaseClient {
|
|
18335
18459
|
async trigger(id, event, data) {
|
|
18336
18460
|
return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
|
|
18337
18461
|
}
|
|
18338
18462
|
}
|
|
18339
18463
|
|
|
18464
|
+
var workflow = /*#__PURE__*/Object.freeze({
|
|
18465
|
+
__proto__: null,
|
|
18466
|
+
default: Workflow
|
|
18467
|
+
});
|
|
18468
|
+
|
|
18340
18469
|
class Forge extends BaseClient {
|
|
18341
18470
|
constructor(client) {
|
|
18342
18471
|
super(client);
|
|
@@ -18363,7 +18492,7 @@ const isBrowser = typeof window !== "undefined" &&
|
|
|
18363
18492
|
class Platform {
|
|
18364
18493
|
constructor(options) {
|
|
18365
18494
|
var _a;
|
|
18366
|
-
let {
|
|
18495
|
+
let { env = null, token, host, integrationHost } = options !== null && options !== undefined ? options : {};
|
|
18367
18496
|
let headers = {};
|
|
18368
18497
|
if (isBrowser) {
|
|
18369
18498
|
if (localStorage.getItem('protokol_context') == "forge") {
|
|
@@ -18372,7 +18501,6 @@ class Platform {
|
|
|
18372
18501
|
else {
|
|
18373
18502
|
// this potentially means that it is running as dev server in local
|
|
18374
18503
|
headers['X-Project-Env'] = "dev";
|
|
18375
|
-
// here we don't know actual project so we need a way to determine it
|
|
18376
18504
|
}
|
|
18377
18505
|
}
|
|
18378
18506
|
if (token) {
|
|
@@ -18381,9 +18509,6 @@ class Platform {
|
|
|
18381
18509
|
if (env) {
|
|
18382
18510
|
headers['X-Project-Env'] = env;
|
|
18383
18511
|
}
|
|
18384
|
-
if (project) {
|
|
18385
|
-
headers['X-Project-Uuid'] = project;
|
|
18386
|
-
}
|
|
18387
18512
|
this.platformClient = axios.create({
|
|
18388
18513
|
baseURL: host !== null && host !== undefined ? host : "https://lemon.protokol.io",
|
|
18389
18514
|
timeout: 15000,
|
|
@@ -18448,4 +18573,15 @@ class Platform {
|
|
|
18448
18573
|
}
|
|
18449
18574
|
}
|
|
18450
18575
|
|
|
18451
|
-
|
|
18576
|
+
exports.APIUser = apiUser;
|
|
18577
|
+
exports.Apps = apps;
|
|
18578
|
+
exports.Component = component;
|
|
18579
|
+
exports.Functions = functions;
|
|
18580
|
+
exports.Integration = integrations;
|
|
18581
|
+
exports.Ratchet = ratchet;
|
|
18582
|
+
exports.Roles = roles;
|
|
18583
|
+
exports.Sandbox = sandbox;
|
|
18584
|
+
exports.System = system;
|
|
18585
|
+
exports.Users = users;
|
|
18586
|
+
exports.Workflow = workflow;
|
|
18587
|
+
exports.default = Platform;
|
package/dist/index.esm.js
CHANGED
|
@@ -16,9 +16,21 @@ class Functions extends BaseClient {
|
|
|
16
16
|
async update(uuid, update) {
|
|
17
17
|
return await this.client.patch(`/v1/system/function/${uuid}`, update);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Run platform function
|
|
21
|
+
*
|
|
22
|
+
* @param id - Function ID
|
|
23
|
+
* @param input - Input data
|
|
24
|
+
* @param query - Query parameters
|
|
25
|
+
* @returns - Function result
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const result = await platform.function().run("myFunction", { foo: "bar" }, { queryParam: "value" })
|
|
29
|
+
*/
|
|
30
|
+
async run(id, d) {
|
|
31
|
+
const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
|
|
32
|
+
params: d.query,
|
|
33
|
+
headers: d.headers
|
|
22
34
|
});
|
|
23
35
|
return data.data;
|
|
24
36
|
}
|
|
@@ -27,6 +39,11 @@ class Functions extends BaseClient {
|
|
|
27
39
|
}
|
|
28
40
|
}
|
|
29
41
|
|
|
42
|
+
var functions = /*#__PURE__*/Object.freeze({
|
|
43
|
+
__proto__: null,
|
|
44
|
+
default: Functions
|
|
45
|
+
});
|
|
46
|
+
|
|
30
47
|
class Roles extends BaseClient {
|
|
31
48
|
async create(role) {
|
|
32
49
|
const res = await this.client.post("/v1/user/role/create", role);
|
|
@@ -51,6 +68,11 @@ class Roles extends BaseClient {
|
|
|
51
68
|
}
|
|
52
69
|
}
|
|
53
70
|
|
|
71
|
+
var roles = /*#__PURE__*/Object.freeze({
|
|
72
|
+
__proto__: null,
|
|
73
|
+
default: Roles
|
|
74
|
+
});
|
|
75
|
+
|
|
54
76
|
class APIUser extends BaseClient {
|
|
55
77
|
async apiAuth(username, password) {
|
|
56
78
|
return this.client.post("/v1/user/api/auth", {
|
|
@@ -75,6 +97,11 @@ class APIUser extends BaseClient {
|
|
|
75
97
|
}
|
|
76
98
|
}
|
|
77
99
|
|
|
100
|
+
var apiUser = /*#__PURE__*/Object.freeze({
|
|
101
|
+
__proto__: null,
|
|
102
|
+
default: APIUser
|
|
103
|
+
});
|
|
104
|
+
|
|
78
105
|
class Users extends BaseClient {
|
|
79
106
|
async invite(email, roles) {
|
|
80
107
|
return await this.client.post("/v1/project/invite", {
|
|
@@ -87,6 +114,11 @@ class Users extends BaseClient {
|
|
|
87
114
|
}
|
|
88
115
|
}
|
|
89
116
|
|
|
117
|
+
var users = /*#__PURE__*/Object.freeze({
|
|
118
|
+
__proto__: null,
|
|
119
|
+
default: Users
|
|
120
|
+
});
|
|
121
|
+
|
|
90
122
|
class Apps extends BaseClient {
|
|
91
123
|
constructor(client, appType) {
|
|
92
124
|
super(client);
|
|
@@ -100,10 +132,17 @@ class Apps extends BaseClient {
|
|
|
100
132
|
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
|
|
101
133
|
}
|
|
102
134
|
async upload(formData) {
|
|
103
|
-
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData
|
|
135
|
+
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
|
|
136
|
+
timeout: 60000
|
|
137
|
+
});
|
|
104
138
|
}
|
|
105
139
|
}
|
|
106
140
|
|
|
141
|
+
var apps = /*#__PURE__*/Object.freeze({
|
|
142
|
+
__proto__: null,
|
|
143
|
+
default: Apps
|
|
144
|
+
});
|
|
145
|
+
|
|
107
146
|
class Component extends BaseClient {
|
|
108
147
|
constructor(adapter, ref) {
|
|
109
148
|
super(adapter);
|
|
@@ -113,8 +152,29 @@ class Component extends BaseClient {
|
|
|
113
152
|
this.ref = ref;
|
|
114
153
|
return this;
|
|
115
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Find method to search for models
|
|
157
|
+
*
|
|
158
|
+
* @param {FindParams} filters - The filters to apply to the search
|
|
159
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
160
|
+
*
|
|
161
|
+
* @returns {Promise<FindResponse>} - The result of the search
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* platform.component(name).find({
|
|
165
|
+
* currentPage: 1,
|
|
166
|
+
* perPage: 10,
|
|
167
|
+
* })
|
|
168
|
+
*
|
|
169
|
+
* // advanced search
|
|
170
|
+
* platform.component(name).find({
|
|
171
|
+
* $adv: {
|
|
172
|
+
* name: "John Doe",
|
|
173
|
+
* }
|
|
174
|
+
* )
|
|
175
|
+
**/
|
|
116
176
|
find(filters, opts) {
|
|
117
|
-
const { cache = false, buildttl = -1, locale = "en_US" } = opts !== null && opts !== undefined ? opts : {};
|
|
177
|
+
const { cache = false, buildttl = -1, locale = "en_US", } = opts !== null && opts !== undefined ? opts : {};
|
|
118
178
|
return new Promise((resolve, reject) => {
|
|
119
179
|
let payload = {
|
|
120
180
|
context: filters,
|
|
@@ -142,7 +202,6 @@ class Component extends BaseClient {
|
|
|
142
202
|
sortDesc: sortDesc,
|
|
143
203
|
filter: ctx.filter,
|
|
144
204
|
filterOn: ctx.filterOn.join(","),
|
|
145
|
-
disabled: ctx.disabled,
|
|
146
205
|
limit: limit,
|
|
147
206
|
dateFrom: ctx.dateFrom,
|
|
148
207
|
dateTo: ctx.dateTo,
|
|
@@ -154,9 +213,11 @@ class Component extends BaseClient {
|
|
|
154
213
|
if (ctx.$aggregate && ctx.$aggregate.length > 0) {
|
|
155
214
|
params.$aggregate = JSON.stringify(ctx.$aggregate);
|
|
156
215
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
216
|
+
if (opts) {
|
|
217
|
+
Object.keys(opts).forEach(k => {
|
|
218
|
+
params[`_opt_${k}`] = opts ? opts[k] : null;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
160
221
|
this.client.get(`/v3/system/component/${this.ref}/models`, {
|
|
161
222
|
params: params,
|
|
162
223
|
headers: {
|
|
@@ -172,6 +233,19 @@ class Component extends BaseClient {
|
|
|
172
233
|
});
|
|
173
234
|
});
|
|
174
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* FindOne method to search for a single model
|
|
238
|
+
*
|
|
239
|
+
* @param {FindAdvancedParams} filter - The filters to apply to the search
|
|
240
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
241
|
+
*
|
|
242
|
+
* @returns {Promise<?Model>} - The result of the search
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* platform.component(name).findOne({
|
|
246
|
+
* name: "John Doe",
|
|
247
|
+
* })
|
|
248
|
+
**/
|
|
175
249
|
async findOne(filter, opts) {
|
|
176
250
|
const { items } = await this.find({
|
|
177
251
|
$adv: filter
|
|
@@ -181,6 +255,12 @@ class Component extends BaseClient {
|
|
|
181
255
|
}
|
|
182
256
|
return null;
|
|
183
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Get model by uuid
|
|
260
|
+
*
|
|
261
|
+
* @param uuid string - The uuid of the model
|
|
262
|
+
* @returns (Promise<Model>)
|
|
263
|
+
*/
|
|
184
264
|
get(uuid) {
|
|
185
265
|
return new Promise((resolve, reject) => {
|
|
186
266
|
this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`).then((resp) => {
|
|
@@ -190,10 +270,17 @@ class Component extends BaseClient {
|
|
|
190
270
|
});
|
|
191
271
|
});
|
|
192
272
|
}
|
|
193
|
-
|
|
273
|
+
/**
|
|
274
|
+
* Update model by uuid
|
|
275
|
+
*
|
|
276
|
+
* @param uuid string - The uuid of the model
|
|
277
|
+
* @param data
|
|
278
|
+
* @returns
|
|
279
|
+
*/
|
|
280
|
+
update(uuid, data) {
|
|
194
281
|
return new Promise((resolve, reject) => {
|
|
195
282
|
this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
196
|
-
data
|
|
283
|
+
data,
|
|
197
284
|
}).then((resp) => {
|
|
198
285
|
resolve(resp.data);
|
|
199
286
|
}).catch((error) => {
|
|
@@ -201,11 +288,11 @@ class Component extends BaseClient {
|
|
|
201
288
|
});
|
|
202
289
|
});
|
|
203
290
|
}
|
|
204
|
-
concurrentUpdate(uuid, version,
|
|
291
|
+
concurrentUpdate(uuid, version, data) {
|
|
205
292
|
return new Promise((resolve, reject) => {
|
|
206
293
|
this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
207
294
|
version: version,
|
|
208
|
-
data
|
|
295
|
+
data,
|
|
209
296
|
}).then((resp) => {
|
|
210
297
|
resolve(resp.data);
|
|
211
298
|
}).catch((error) => {
|
|
@@ -231,9 +318,9 @@ class Component extends BaseClient {
|
|
|
231
318
|
});
|
|
232
319
|
});
|
|
233
320
|
}
|
|
234
|
-
aggregate(
|
|
321
|
+
aggregate(pipeline) {
|
|
235
322
|
return new Promise((resolve, reject) => {
|
|
236
|
-
this.client.post(`/v3/system/component/${this.ref}/aggregate`,
|
|
323
|
+
this.client.post(`/v3/system/component/${this.ref}/aggregate`, pipeline).then((resp) => {
|
|
237
324
|
resolve(resp.data);
|
|
238
325
|
}).catch((error) => {
|
|
239
326
|
reject(error);
|
|
@@ -269,7 +356,7 @@ class Component extends BaseClient {
|
|
|
269
356
|
return data;
|
|
270
357
|
}
|
|
271
358
|
async workflow(event, input) {
|
|
272
|
-
return await this.client.post(
|
|
359
|
+
return await this.client.post(`/v1/system/component/${this.ref}/workflow/event`, {
|
|
273
360
|
event,
|
|
274
361
|
input
|
|
275
362
|
});
|
|
@@ -286,6 +373,11 @@ class Component extends BaseClient {
|
|
|
286
373
|
}
|
|
287
374
|
}
|
|
288
375
|
|
|
376
|
+
var component = /*#__PURE__*/Object.freeze({
|
|
377
|
+
__proto__: null,
|
|
378
|
+
default: Component
|
|
379
|
+
});
|
|
380
|
+
|
|
289
381
|
class Invoicing extends BaseClient {
|
|
290
382
|
async getSalesInvoices(provider, page) {
|
|
291
383
|
return await this.request("GET", `/invoices/${provider}/sales`, {
|
|
@@ -494,6 +586,11 @@ class Integrations extends BaseClient {
|
|
|
494
586
|
}
|
|
495
587
|
}
|
|
496
588
|
|
|
589
|
+
var integrations = /*#__PURE__*/Object.freeze({
|
|
590
|
+
__proto__: null,
|
|
591
|
+
default: Integrations
|
|
592
|
+
});
|
|
593
|
+
|
|
497
594
|
class Ratchet extends BaseClient {
|
|
498
595
|
async query(name, params) {
|
|
499
596
|
let res = await this.client.post('/v1/ratchet/query', {
|
|
@@ -504,12 +601,32 @@ class Ratchet extends BaseClient {
|
|
|
504
601
|
}
|
|
505
602
|
}
|
|
506
603
|
|
|
604
|
+
var ratchet = /*#__PURE__*/Object.freeze({
|
|
605
|
+
__proto__: null,
|
|
606
|
+
default: Ratchet
|
|
607
|
+
});
|
|
608
|
+
|
|
507
609
|
class Sandbox extends BaseClient {
|
|
610
|
+
/**
|
|
611
|
+
* Call the sandbox service to execute a serverless function
|
|
612
|
+
*
|
|
613
|
+
* @param name
|
|
614
|
+
* @param data
|
|
615
|
+
* @returns
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* const result = await platform.sandbox().spark("myFunction", { foo: "bar" })
|
|
619
|
+
*/
|
|
508
620
|
async spark(name, data) {
|
|
509
621
|
return await this.client.post(`/v1/project/sandbox/spark/exec/${name}`, data);
|
|
510
622
|
}
|
|
511
623
|
}
|
|
512
624
|
|
|
625
|
+
var sandbox = /*#__PURE__*/Object.freeze({
|
|
626
|
+
__proto__: null,
|
|
627
|
+
default: Sandbox
|
|
628
|
+
});
|
|
629
|
+
|
|
513
630
|
class System extends BaseClient {
|
|
514
631
|
async resourceResolver(ref, resourceName, format) {
|
|
515
632
|
const { data } = await this.client.post("/v3/system/resource-resolver", {
|
|
@@ -523,12 +640,22 @@ class System extends BaseClient {
|
|
|
523
640
|
}
|
|
524
641
|
}
|
|
525
642
|
|
|
643
|
+
var system = /*#__PURE__*/Object.freeze({
|
|
644
|
+
__proto__: null,
|
|
645
|
+
default: System
|
|
646
|
+
});
|
|
647
|
+
|
|
526
648
|
class Workflow extends BaseClient {
|
|
527
649
|
async trigger(id, event, data) {
|
|
528
650
|
return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
|
|
529
651
|
}
|
|
530
652
|
}
|
|
531
653
|
|
|
654
|
+
var workflow = /*#__PURE__*/Object.freeze({
|
|
655
|
+
__proto__: null,
|
|
656
|
+
default: Workflow
|
|
657
|
+
});
|
|
658
|
+
|
|
532
659
|
class Forge extends BaseClient {
|
|
533
660
|
constructor(client) {
|
|
534
661
|
super(client);
|
|
@@ -555,7 +682,7 @@ const isBrowser = typeof window !== "undefined" &&
|
|
|
555
682
|
class Platform {
|
|
556
683
|
constructor(options) {
|
|
557
684
|
var _a;
|
|
558
|
-
let {
|
|
685
|
+
let { env = null, token, host, integrationHost } = options !== null && options !== undefined ? options : {};
|
|
559
686
|
let headers = {};
|
|
560
687
|
if (isBrowser) {
|
|
561
688
|
if (localStorage.getItem('protokol_context') == "forge") {
|
|
@@ -564,7 +691,6 @@ class Platform {
|
|
|
564
691
|
else {
|
|
565
692
|
// this potentially means that it is running as dev server in local
|
|
566
693
|
headers['X-Project-Env'] = "dev";
|
|
567
|
-
// here we don't know actual project so we need a way to determine it
|
|
568
694
|
}
|
|
569
695
|
}
|
|
570
696
|
if (token) {
|
|
@@ -573,9 +699,6 @@ class Platform {
|
|
|
573
699
|
if (env) {
|
|
574
700
|
headers['X-Project-Env'] = env;
|
|
575
701
|
}
|
|
576
|
-
if (project) {
|
|
577
|
-
headers['X-Project-Uuid'] = project;
|
|
578
|
-
}
|
|
579
702
|
this.platformClient = axios.create({
|
|
580
703
|
baseURL: host !== null && host !== undefined ? host : "https://lemon.protokol.io",
|
|
581
704
|
timeout: 15000,
|
|
@@ -640,4 +763,4 @@ class Platform {
|
|
|
640
763
|
}
|
|
641
764
|
}
|
|
642
765
|
|
|
643
|
-
export { Platform as default };
|
|
766
|
+
export { apiUser as APIUser, apps as Apps, component as Component, functions as Functions, integrations as Integration, ratchet as Ratchet, roles as Roles, sandbox as Sandbox, system as System, users as Users, workflow as Workflow, Platform as default };
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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) {
|
|
@@ -20,9 +20,21 @@
|
|
|
20
20
|
async update(uuid, update) {
|
|
21
21
|
return await this.client.patch(`/v1/system/function/${uuid}`, update);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Run platform function
|
|
25
|
+
*
|
|
26
|
+
* @param id - Function ID
|
|
27
|
+
* @param input - Input data
|
|
28
|
+
* @param query - Query parameters
|
|
29
|
+
* @returns - Function result
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const result = await platform.function().run("myFunction", { foo: "bar" }, { queryParam: "value" })
|
|
33
|
+
*/
|
|
34
|
+
async run(id, d) {
|
|
35
|
+
const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
|
|
36
|
+
params: d.query,
|
|
37
|
+
headers: d.headers
|
|
26
38
|
});
|
|
27
39
|
return data.data;
|
|
28
40
|
}
|
|
@@ -31,6 +43,11 @@
|
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
45
|
|
|
46
|
+
var functions = /*#__PURE__*/Object.freeze({
|
|
47
|
+
__proto__: null,
|
|
48
|
+
default: Functions
|
|
49
|
+
});
|
|
50
|
+
|
|
34
51
|
class Roles extends BaseClient {
|
|
35
52
|
async create(role) {
|
|
36
53
|
const res = await this.client.post("/v1/user/role/create", role);
|
|
@@ -55,6 +72,11 @@
|
|
|
55
72
|
}
|
|
56
73
|
}
|
|
57
74
|
|
|
75
|
+
var roles = /*#__PURE__*/Object.freeze({
|
|
76
|
+
__proto__: null,
|
|
77
|
+
default: Roles
|
|
78
|
+
});
|
|
79
|
+
|
|
58
80
|
class APIUser extends BaseClient {
|
|
59
81
|
async apiAuth(username, password) {
|
|
60
82
|
return this.client.post("/v1/user/api/auth", {
|
|
@@ -79,6 +101,11 @@
|
|
|
79
101
|
}
|
|
80
102
|
}
|
|
81
103
|
|
|
104
|
+
var apiUser = /*#__PURE__*/Object.freeze({
|
|
105
|
+
__proto__: null,
|
|
106
|
+
default: APIUser
|
|
107
|
+
});
|
|
108
|
+
|
|
82
109
|
class Users extends BaseClient {
|
|
83
110
|
async invite(email, roles) {
|
|
84
111
|
return await this.client.post("/v1/project/invite", {
|
|
@@ -91,6 +118,11 @@
|
|
|
91
118
|
}
|
|
92
119
|
}
|
|
93
120
|
|
|
121
|
+
var users = /*#__PURE__*/Object.freeze({
|
|
122
|
+
__proto__: null,
|
|
123
|
+
default: Users
|
|
124
|
+
});
|
|
125
|
+
|
|
94
126
|
class Apps extends BaseClient {
|
|
95
127
|
constructor(client, appType) {
|
|
96
128
|
super(client);
|
|
@@ -104,10 +136,17 @@
|
|
|
104
136
|
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
|
|
105
137
|
}
|
|
106
138
|
async upload(formData) {
|
|
107
|
-
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData
|
|
139
|
+
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
|
|
140
|
+
timeout: 60000
|
|
141
|
+
});
|
|
108
142
|
}
|
|
109
143
|
}
|
|
110
144
|
|
|
145
|
+
var apps = /*#__PURE__*/Object.freeze({
|
|
146
|
+
__proto__: null,
|
|
147
|
+
default: Apps
|
|
148
|
+
});
|
|
149
|
+
|
|
111
150
|
class Component extends BaseClient {
|
|
112
151
|
constructor(adapter, ref) {
|
|
113
152
|
super(adapter);
|
|
@@ -117,8 +156,29 @@
|
|
|
117
156
|
this.ref = ref;
|
|
118
157
|
return this;
|
|
119
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Find method to search for models
|
|
161
|
+
*
|
|
162
|
+
* @param {FindParams} filters - The filters to apply to the search
|
|
163
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
164
|
+
*
|
|
165
|
+
* @returns {Promise<FindResponse>} - The result of the search
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* platform.component(name).find({
|
|
169
|
+
* currentPage: 1,
|
|
170
|
+
* perPage: 10,
|
|
171
|
+
* })
|
|
172
|
+
*
|
|
173
|
+
* // advanced search
|
|
174
|
+
* platform.component(name).find({
|
|
175
|
+
* $adv: {
|
|
176
|
+
* name: "John Doe",
|
|
177
|
+
* }
|
|
178
|
+
* )
|
|
179
|
+
**/
|
|
120
180
|
find(filters, opts) {
|
|
121
|
-
const { cache = false, buildttl = -1, locale = "en_US" } = opts !== null && opts !== undefined ? opts : {};
|
|
181
|
+
const { cache = false, buildttl = -1, locale = "en_US", } = opts !== null && opts !== undefined ? opts : {};
|
|
122
182
|
return new Promise((resolve, reject) => {
|
|
123
183
|
let payload = {
|
|
124
184
|
context: filters,
|
|
@@ -146,7 +206,6 @@
|
|
|
146
206
|
sortDesc: sortDesc,
|
|
147
207
|
filter: ctx.filter,
|
|
148
208
|
filterOn: ctx.filterOn.join(","),
|
|
149
|
-
disabled: ctx.disabled,
|
|
150
209
|
limit: limit,
|
|
151
210
|
dateFrom: ctx.dateFrom,
|
|
152
211
|
dateTo: ctx.dateTo,
|
|
@@ -158,9 +217,11 @@
|
|
|
158
217
|
if (ctx.$aggregate && ctx.$aggregate.length > 0) {
|
|
159
218
|
params.$aggregate = JSON.stringify(ctx.$aggregate);
|
|
160
219
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
220
|
+
if (opts) {
|
|
221
|
+
Object.keys(opts).forEach(k => {
|
|
222
|
+
params[`_opt_${k}`] = opts ? opts[k] : null;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
164
225
|
this.client.get(`/v3/system/component/${this.ref}/models`, {
|
|
165
226
|
params: params,
|
|
166
227
|
headers: {
|
|
@@ -176,6 +237,19 @@
|
|
|
176
237
|
});
|
|
177
238
|
});
|
|
178
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* FindOne method to search for a single model
|
|
242
|
+
*
|
|
243
|
+
* @param {FindAdvancedParams} filter - The filters to apply to the search
|
|
244
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
245
|
+
*
|
|
246
|
+
* @returns {Promise<?Model>} - The result of the search
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* platform.component(name).findOne({
|
|
250
|
+
* name: "John Doe",
|
|
251
|
+
* })
|
|
252
|
+
**/
|
|
179
253
|
async findOne(filter, opts) {
|
|
180
254
|
const { items } = await this.find({
|
|
181
255
|
$adv: filter
|
|
@@ -185,6 +259,12 @@
|
|
|
185
259
|
}
|
|
186
260
|
return null;
|
|
187
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Get model by uuid
|
|
264
|
+
*
|
|
265
|
+
* @param uuid string - The uuid of the model
|
|
266
|
+
* @returns (Promise<Model>)
|
|
267
|
+
*/
|
|
188
268
|
get(uuid) {
|
|
189
269
|
return new Promise((resolve, reject) => {
|
|
190
270
|
this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`).then((resp) => {
|
|
@@ -194,10 +274,17 @@
|
|
|
194
274
|
});
|
|
195
275
|
});
|
|
196
276
|
}
|
|
197
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Update model by uuid
|
|
279
|
+
*
|
|
280
|
+
* @param uuid string - The uuid of the model
|
|
281
|
+
* @param data
|
|
282
|
+
* @returns
|
|
283
|
+
*/
|
|
284
|
+
update(uuid, data) {
|
|
198
285
|
return new Promise((resolve, reject) => {
|
|
199
286
|
this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
200
|
-
data
|
|
287
|
+
data,
|
|
201
288
|
}).then((resp) => {
|
|
202
289
|
resolve(resp.data);
|
|
203
290
|
}).catch((error) => {
|
|
@@ -205,11 +292,11 @@
|
|
|
205
292
|
});
|
|
206
293
|
});
|
|
207
294
|
}
|
|
208
|
-
concurrentUpdate(uuid, version,
|
|
295
|
+
concurrentUpdate(uuid, version, data) {
|
|
209
296
|
return new Promise((resolve, reject) => {
|
|
210
297
|
this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
|
|
211
298
|
version: version,
|
|
212
|
-
data
|
|
299
|
+
data,
|
|
213
300
|
}).then((resp) => {
|
|
214
301
|
resolve(resp.data);
|
|
215
302
|
}).catch((error) => {
|
|
@@ -235,9 +322,9 @@
|
|
|
235
322
|
});
|
|
236
323
|
});
|
|
237
324
|
}
|
|
238
|
-
aggregate(
|
|
325
|
+
aggregate(pipeline) {
|
|
239
326
|
return new Promise((resolve, reject) => {
|
|
240
|
-
this.client.post(`/v3/system/component/${this.ref}/aggregate`,
|
|
327
|
+
this.client.post(`/v3/system/component/${this.ref}/aggregate`, pipeline).then((resp) => {
|
|
241
328
|
resolve(resp.data);
|
|
242
329
|
}).catch((error) => {
|
|
243
330
|
reject(error);
|
|
@@ -273,7 +360,7 @@
|
|
|
273
360
|
return data;
|
|
274
361
|
}
|
|
275
362
|
async workflow(event, input) {
|
|
276
|
-
return await this.client.post(
|
|
363
|
+
return await this.client.post(`/v1/system/component/${this.ref}/workflow/event`, {
|
|
277
364
|
event,
|
|
278
365
|
input
|
|
279
366
|
});
|
|
@@ -290,6 +377,11 @@
|
|
|
290
377
|
}
|
|
291
378
|
}
|
|
292
379
|
|
|
380
|
+
var component = /*#__PURE__*/Object.freeze({
|
|
381
|
+
__proto__: null,
|
|
382
|
+
default: Component
|
|
383
|
+
});
|
|
384
|
+
|
|
293
385
|
class Invoicing extends BaseClient {
|
|
294
386
|
async getSalesInvoices(provider, page) {
|
|
295
387
|
return await this.request("GET", `/invoices/${provider}/sales`, {
|
|
@@ -498,6 +590,11 @@
|
|
|
498
590
|
}
|
|
499
591
|
}
|
|
500
592
|
|
|
593
|
+
var integrations = /*#__PURE__*/Object.freeze({
|
|
594
|
+
__proto__: null,
|
|
595
|
+
default: Integrations
|
|
596
|
+
});
|
|
597
|
+
|
|
501
598
|
class Ratchet extends BaseClient {
|
|
502
599
|
async query(name, params) {
|
|
503
600
|
let res = await this.client.post('/v1/ratchet/query', {
|
|
@@ -508,12 +605,32 @@
|
|
|
508
605
|
}
|
|
509
606
|
}
|
|
510
607
|
|
|
608
|
+
var ratchet = /*#__PURE__*/Object.freeze({
|
|
609
|
+
__proto__: null,
|
|
610
|
+
default: Ratchet
|
|
611
|
+
});
|
|
612
|
+
|
|
511
613
|
class Sandbox extends BaseClient {
|
|
614
|
+
/**
|
|
615
|
+
* Call the sandbox service to execute a serverless function
|
|
616
|
+
*
|
|
617
|
+
* @param name
|
|
618
|
+
* @param data
|
|
619
|
+
* @returns
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* const result = await platform.sandbox().spark("myFunction", { foo: "bar" })
|
|
623
|
+
*/
|
|
512
624
|
async spark(name, data) {
|
|
513
625
|
return await this.client.post(`/v1/project/sandbox/spark/exec/${name}`, data);
|
|
514
626
|
}
|
|
515
627
|
}
|
|
516
628
|
|
|
629
|
+
var sandbox = /*#__PURE__*/Object.freeze({
|
|
630
|
+
__proto__: null,
|
|
631
|
+
default: Sandbox
|
|
632
|
+
});
|
|
633
|
+
|
|
517
634
|
class System extends BaseClient {
|
|
518
635
|
async resourceResolver(ref, resourceName, format) {
|
|
519
636
|
const { data } = await this.client.post("/v3/system/resource-resolver", {
|
|
@@ -527,12 +644,22 @@
|
|
|
527
644
|
}
|
|
528
645
|
}
|
|
529
646
|
|
|
647
|
+
var system = /*#__PURE__*/Object.freeze({
|
|
648
|
+
__proto__: null,
|
|
649
|
+
default: System
|
|
650
|
+
});
|
|
651
|
+
|
|
530
652
|
class Workflow extends BaseClient {
|
|
531
653
|
async trigger(id, event, data) {
|
|
532
654
|
return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
|
|
533
655
|
}
|
|
534
656
|
}
|
|
535
657
|
|
|
658
|
+
var workflow = /*#__PURE__*/Object.freeze({
|
|
659
|
+
__proto__: null,
|
|
660
|
+
default: Workflow
|
|
661
|
+
});
|
|
662
|
+
|
|
536
663
|
class Forge extends BaseClient {
|
|
537
664
|
constructor(client) {
|
|
538
665
|
super(client);
|
|
@@ -559,7 +686,7 @@
|
|
|
559
686
|
class Platform {
|
|
560
687
|
constructor(options) {
|
|
561
688
|
var _a;
|
|
562
|
-
let {
|
|
689
|
+
let { env = null, token, host, integrationHost } = options !== null && options !== undefined ? options : {};
|
|
563
690
|
let headers = {};
|
|
564
691
|
if (isBrowser) {
|
|
565
692
|
if (localStorage.getItem('protokol_context') == "forge") {
|
|
@@ -568,7 +695,6 @@
|
|
|
568
695
|
else {
|
|
569
696
|
// this potentially means that it is running as dev server in local
|
|
570
697
|
headers['X-Project-Env'] = "dev";
|
|
571
|
-
// here we don't know actual project so we need a way to determine it
|
|
572
698
|
}
|
|
573
699
|
}
|
|
574
700
|
if (token) {
|
|
@@ -577,9 +703,6 @@
|
|
|
577
703
|
if (env) {
|
|
578
704
|
headers['X-Project-Env'] = env;
|
|
579
705
|
}
|
|
580
|
-
if (project) {
|
|
581
|
-
headers['X-Project-Uuid'] = project;
|
|
582
|
-
}
|
|
583
706
|
this.platformClient = axios.create({
|
|
584
707
|
baseURL: host !== null && host !== undefined ? host : "https://lemon.protokol.io",
|
|
585
708
|
timeout: 15000,
|
|
@@ -644,6 +767,19 @@
|
|
|
644
767
|
}
|
|
645
768
|
}
|
|
646
769
|
|
|
647
|
-
|
|
770
|
+
exports.APIUser = apiUser;
|
|
771
|
+
exports.Apps = apps;
|
|
772
|
+
exports.Component = component;
|
|
773
|
+
exports.Functions = functions;
|
|
774
|
+
exports.Integration = integrations;
|
|
775
|
+
exports.Ratchet = ratchet;
|
|
776
|
+
exports.Roles = roles;
|
|
777
|
+
exports.Sandbox = sandbox;
|
|
778
|
+
exports.System = system;
|
|
779
|
+
exports.Users = users;
|
|
780
|
+
exports.Workflow = workflow;
|
|
781
|
+
exports.default = Platform;
|
|
782
|
+
|
|
783
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
648
784
|
|
|
649
785
|
}));
|
package/dist/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
3
|
-
"version": "0.
|
|
2
|
+
"name": "@ptkl/sdk",
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"build": "rollup -c"
|
|
5
|
+
"build": "rollup -c",
|
|
6
|
+
"docs": "typedoc"
|
|
6
7
|
},
|
|
7
8
|
"files": [
|
|
8
9
|
"dist"
|
|
@@ -30,9 +31,10 @@
|
|
|
30
31
|
"@types/lodash": "^4.17.13",
|
|
31
32
|
"@types/node": "^22.9.0",
|
|
32
33
|
"rollup": "^4.30.1",
|
|
34
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
33
35
|
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
+
"typedoc": "^0.28.4",
|
|
37
|
+
"typescript": "^5.6.3"
|
|
36
38
|
},
|
|
37
39
|
"dependencies": {
|
|
38
40
|
"@rollup/plugin-replace": "^6.0.2",
|
|
@@ -1,17 +1,65 @@
|
|
|
1
|
+
import { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model } from "src/types/component";
|
|
1
2
|
import BaseClient from "./baseClient";
|
|
2
3
|
import { AxiosInstance } from "axios";
|
|
3
4
|
export default class Component extends BaseClient {
|
|
4
5
|
private ref;
|
|
5
6
|
constructor(adapter: AxiosInstance, ref: string);
|
|
6
7
|
new(ref: string): this;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Find method to search for models
|
|
10
|
+
*
|
|
11
|
+
* @param {FindParams} filters - The filters to apply to the search
|
|
12
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
13
|
+
*
|
|
14
|
+
* @returns {Promise<FindResponse>} - The result of the search
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* platform.component(name).find({
|
|
18
|
+
* currentPage: 1,
|
|
19
|
+
* perPage: 10,
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* // advanced search
|
|
23
|
+
* platform.component(name).find({
|
|
24
|
+
* $adv: {
|
|
25
|
+
* name: "John Doe",
|
|
26
|
+
* }
|
|
27
|
+
* )
|
|
28
|
+
**/
|
|
29
|
+
find(filters: FindParams, opts?: FindOptions): Promise<FindResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* FindOne method to search for a single model
|
|
32
|
+
*
|
|
33
|
+
* @param {FindAdvancedParams} filter - The filters to apply to the search
|
|
34
|
+
* @param {FindOptions} opts - The options to apply to the search
|
|
35
|
+
*
|
|
36
|
+
* @returns {Promise<?Model>} - The result of the search
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* platform.component(name).findOne({
|
|
40
|
+
* name: "John Doe",
|
|
41
|
+
* })
|
|
42
|
+
**/
|
|
43
|
+
findOne(filter: FindAdvancedParams, opts: FindOptions): Promise<Model | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Get model by uuid
|
|
46
|
+
*
|
|
47
|
+
* @param uuid string - The uuid of the model
|
|
48
|
+
* @returns (Promise<Model>)
|
|
49
|
+
*/
|
|
50
|
+
get(uuid: string): Promise<Model>;
|
|
51
|
+
/**
|
|
52
|
+
* Update model by uuid
|
|
53
|
+
*
|
|
54
|
+
* @param uuid string - The uuid of the model
|
|
55
|
+
* @param data
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
update(uuid: string, data: Record<string, any>): Promise<unknown>;
|
|
59
|
+
concurrentUpdate(uuid: string, version: number, data: Record<string, any>): Promise<unknown>;
|
|
12
60
|
create(model: Record<string, any>): Promise<unknown>;
|
|
13
61
|
delete(uuid: string): Promise<unknown>;
|
|
14
|
-
aggregate(
|
|
62
|
+
aggregate(pipeline: FindAggregateParams): Promise<unknown>;
|
|
15
63
|
settings(): Promise<unknown>;
|
|
16
64
|
saveSettings(settings: any): Promise<unknown>;
|
|
17
65
|
saveTemplatesDist(version: string, sdkVersion: string, engine: string, dist: Record<string, string>): Promise<any>;
|
|
@@ -20,3 +68,4 @@ export default class Component extends BaseClient {
|
|
|
20
68
|
all(): Promise<any>;
|
|
21
69
|
setup(data: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
22
70
|
}
|
|
71
|
+
export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model };
|
|
@@ -3,6 +3,21 @@ export default class Functions extends BaseClient {
|
|
|
3
3
|
list(): Promise<any>;
|
|
4
4
|
get(ref: string): Promise<any>;
|
|
5
5
|
update(uuid: string, update: any): Promise<any>;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Run platform function
|
|
8
|
+
*
|
|
9
|
+
* @param id - Function ID
|
|
10
|
+
* @param input - Input data
|
|
11
|
+
* @param query - Query parameters
|
|
12
|
+
* @returns - Function result
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const result = await platform.function().run("myFunction", { foo: "bar" }, { queryParam: "value" })
|
|
16
|
+
*/
|
|
17
|
+
run(id: string, d: {
|
|
18
|
+
input?: any;
|
|
19
|
+
query: any;
|
|
20
|
+
headers: any;
|
|
21
|
+
}): Promise<any>;
|
|
7
22
|
generateSignature(ref: string, env: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
8
23
|
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import BaseClient from "./baseClient";
|
|
2
2
|
export default class Sandbox extends BaseClient {
|
|
3
|
+
/**
|
|
4
|
+
* Call the sandbox service to execute a serverless function
|
|
5
|
+
*
|
|
6
|
+
* @param name
|
|
7
|
+
* @param data
|
|
8
|
+
* @returns
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const result = await platform.sandbox().spark("myFunction", { foo: "bar" })
|
|
12
|
+
*/
|
|
3
13
|
spark(name: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
4
14
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
import Platform from './api/platform';
|
|
2
|
+
export * as Component from './api/component';
|
|
3
|
+
export * as Integration from './api/integrations';
|
|
4
|
+
export * as Ratchet from './api/ratchet';
|
|
5
|
+
export * as Sandbox from './api/sandbox';
|
|
6
|
+
export * as System from './api/system';
|
|
7
|
+
export * as Users from './api/users';
|
|
8
|
+
export * as Functions from './api/functions';
|
|
9
|
+
export * as APIUser from './api/apiUser';
|
|
10
|
+
export * as Roles from './api/roles';
|
|
11
|
+
export * as Apps from './api/apps';
|
|
12
|
+
export * as Workflow from './api/workflow';
|
|
2
13
|
export default Platform;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type FindParams = {
|
|
2
|
+
currentPage?: number;
|
|
3
|
+
perPage?: number;
|
|
4
|
+
sortBy?: string;
|
|
5
|
+
sortDesc?: boolean;
|
|
6
|
+
filterOn?: string[];
|
|
7
|
+
filter?: any;
|
|
8
|
+
disabled?: any;
|
|
9
|
+
dateFrom?: string;
|
|
10
|
+
dateTo?: string;
|
|
11
|
+
dateField?: string;
|
|
12
|
+
$adv?: FindAdvancedParams;
|
|
13
|
+
$aggregate?: FindAggregateParams[];
|
|
14
|
+
};
|
|
15
|
+
type FindOptions = {
|
|
16
|
+
cache?: boolean;
|
|
17
|
+
buildttl?: number;
|
|
18
|
+
locale?: string;
|
|
19
|
+
unmaskPasswords?: boolean;
|
|
20
|
+
};
|
|
21
|
+
type FindResponse = {
|
|
22
|
+
items: Model[];
|
|
23
|
+
total: number;
|
|
24
|
+
page: number;
|
|
25
|
+
pages: number;
|
|
26
|
+
};
|
|
27
|
+
type FindAdvancedParams = {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
};
|
|
30
|
+
type FindAggregateParams = {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
33
|
+
type Model = {
|
|
34
|
+
uuid: string;
|
|
35
|
+
__version__: number;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
created_by: string;
|
|
39
|
+
updated_by: string;
|
|
40
|
+
deleted_at: string;
|
|
41
|
+
deleted_by: string;
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
};
|
|
44
|
+
export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, };
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ptkl/sdk",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"build": "rollup -c"
|
|
5
|
+
"build": "rollup -c",
|
|
6
|
+
"docs": "typedoc"
|
|
6
7
|
},
|
|
7
8
|
"files": [
|
|
8
9
|
"dist"
|
|
@@ -30,9 +31,10 @@
|
|
|
30
31
|
"@types/lodash": "^4.17.13",
|
|
31
32
|
"@types/node": "^22.9.0",
|
|
32
33
|
"rollup": "^4.30.1",
|
|
34
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
33
35
|
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
+
"typedoc": "^0.28.4",
|
|
37
|
+
"typescript": "^5.6.3"
|
|
36
38
|
},
|
|
37
39
|
"dependencies": {
|
|
38
40
|
"@rollup/plugin-replace": "^6.0.2",
|