@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 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');
@@ -17812,9 +17814,73 @@ class BaseClient {
17812
17814
  constructor(client) {
17813
17815
  this.client = client;
17814
17816
  }
17817
+ setClient(client) {
17818
+ this.client = client;
17819
+ return this;
17820
+ }
17815
17821
  }
17816
17822
 
17817
- class Functions extends BaseClient {
17823
+ typeof process !== "undefined" &&
17824
+ process.versions != null &&
17825
+ process.versions.node != null;
17826
+ const isBrowser = typeof window !== "undefined" &&
17827
+ typeof document !== "undefined";
17828
+
17829
+ /**
17830
+ * Base client for the platform API
17831
+ * Classes that extend PlatformBaseClient have intentins of only working in platform context
17832
+ *
17833
+ *
17834
+ * @class PlatformBaseClient
17835
+ * @extends BaseClient
17836
+ * @constructor
17837
+ * @param {AxiosInstance} [client] - The axios instance to use for the client
17838
+ *
17839
+ * @example
17840
+ * // if sdk is used in the forge app that is running in the platform context
17841
+ * const utils = new ComponentUtils()
17842
+ * // this won't work outside of platform context because client needs authtorization to communicate with the API.
17843
+ *
17844
+ */
17845
+ class PlatformBaseClient extends BaseClient {
17846
+ constructor(options) {
17847
+ var _a, _b;
17848
+ let { env = null, token, host, } = options !== null && options !== undefined ? options : {};
17849
+ let headers = {};
17850
+ if (isBrowser) {
17851
+ if (localStorage.getItem('protokol_context') == "forge") {
17852
+ headers['X-Project-Env'] = (_a = localStorage.getItem('forge_app_env')) !== null && _a !== undefined ? _a : "dev";
17853
+ }
17854
+ else {
17855
+ // this potentially means that it is running as dev server in local
17856
+ headers['X-Project-Env'] = "dev";
17857
+ }
17858
+ // @ts-ignore
17859
+ const __global_env__ = window === null || window === undefined ? undefined : window.__ENV_VARIABLES__;
17860
+ host = (_b = __global_env__ === null || __global_env__ === undefined ? undefined : __global_env__.API_HOST) !== null && _b !== undefined ? _b : host;
17861
+ }
17862
+ if (token) {
17863
+ headers['Authorization'] = `Bearer ${token}`;
17864
+ }
17865
+ if (env) {
17866
+ headers['X-Project-Env'] = env;
17867
+ }
17868
+ const client = axios.create({
17869
+ baseURL: host !== null && host !== undefined ? host : "https://lemon.protokol.io",
17870
+ timeout: 15000,
17871
+ headers: {
17872
+ ...headers,
17873
+ },
17874
+ withCredentials: true,
17875
+ });
17876
+ super(client);
17877
+ this.env = null;
17878
+ this.token = null;
17879
+ this.host = null;
17880
+ }
17881
+ }
17882
+
17883
+ class Functions extends PlatformBaseClient {
17818
17884
  async list() {
17819
17885
  return await this.client.get("/v1/system/function");
17820
17886
  }
@@ -17824,9 +17890,21 @@ class Functions extends BaseClient {
17824
17890
  async update(uuid, update) {
17825
17891
  return await this.client.patch(`/v1/system/function/${uuid}`, update);
17826
17892
  }
17827
- async run(id, input, query) {
17828
- const { data } = await this.client.post(`/v1/system/function/run/${id}`, input, {
17829
- params: query || {},
17893
+ /**
17894
+ * Run platform function
17895
+ *
17896
+ * @param id - Function ID
17897
+ * @param input - Input data
17898
+ * @param query - Query parameters
17899
+ * @returns - Function result
17900
+ *
17901
+ * @example
17902
+ * const result = await platform.function().run("myFunction", { foo: "bar" }, { queryParam: "value" })
17903
+ */
17904
+ async run(id, d) {
17905
+ const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
17906
+ params: d.query,
17907
+ headers: d.headers
17830
17908
  });
17831
17909
  return data.data;
17832
17910
  }
@@ -17835,7 +17913,7 @@ class Functions extends BaseClient {
17835
17913
  }
17836
17914
  }
17837
17915
 
17838
- class Roles extends BaseClient {
17916
+ class Roles extends PlatformBaseClient {
17839
17917
  async create(role) {
17840
17918
  const res = await this.client.post("/v1/user/role/create", role);
17841
17919
  // writeFileSync(`.role.create.json`,JSON.stringify(res))
@@ -17859,11 +17937,15 @@ class Roles extends BaseClient {
17859
17937
  }
17860
17938
  }
17861
17939
 
17862
- class APIUser extends BaseClient {
17863
- async apiAuth(username, password) {
17940
+ class APIUser extends PlatformBaseClient {
17941
+ async auth(username, password, project) {
17864
17942
  return this.client.post("/v1/user/api/auth", {
17865
17943
  username,
17866
17944
  password
17945
+ }, {
17946
+ headers: {
17947
+ "X-Project-Uuid": project
17948
+ }
17867
17949
  });
17868
17950
  }
17869
17951
  async newSecret(uuid) {
@@ -17883,7 +17965,7 @@ class APIUser extends BaseClient {
17883
17965
  }
17884
17966
  }
17885
17967
 
17886
- class Users extends BaseClient {
17968
+ class Users extends PlatformBaseClient {
17887
17969
  async invite(email, roles) {
17888
17970
  return await this.client.post("/v1/project/invite", {
17889
17971
  email,
@@ -17895,9 +17977,9 @@ class Users extends BaseClient {
17895
17977
  }
17896
17978
  }
17897
17979
 
17898
- class Apps extends BaseClient {
17899
- constructor(client, appType) {
17900
- super(client);
17980
+ class Apps extends PlatformBaseClient {
17981
+ constructor(appType) {
17982
+ super();
17901
17983
  this.appType = appType;
17902
17984
  }
17903
17985
  async updateSettings(updateValues, ref) {
@@ -17908,21 +17990,40 @@ class Apps extends BaseClient {
17908
17990
  return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
17909
17991
  }
17910
17992
  async upload(formData) {
17911
- return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData);
17993
+ return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
17994
+ timeout: 60000
17995
+ });
17912
17996
  }
17913
17997
  }
17914
17998
 
17915
- class Component extends BaseClient {
17916
- constructor(adapter, ref) {
17917
- super(adapter);
17918
- this.ref = ref;
17919
- }
17920
- new(ref) {
17999
+ class Component extends PlatformBaseClient {
18000
+ constructor(ref = null) {
18001
+ super();
17921
18002
  this.ref = ref;
17922
- return this;
17923
18003
  }
18004
+ /**
18005
+ * Find method to search for models
18006
+ *
18007
+ * @param {FindParams} filters - The filters to apply to the search
18008
+ * @param {FindOptions} opts - The options to apply to the search
18009
+ *
18010
+ * @returns {Promise<FindResponse>} - The result of the search
18011
+ *
18012
+ * @example
18013
+ * platform.component(name).find({
18014
+ * currentPage: 1,
18015
+ * perPage: 10,
18016
+ * })
18017
+ *
18018
+ * // advanced search
18019
+ * platform.component(name).find({
18020
+ * $adv: {
18021
+ * name: "John Doe",
18022
+ * }
18023
+ * )
18024
+ **/
17924
18025
  find(filters, opts) {
17925
- const { cache = false, buildttl = -1, locale = "en_US" } = opts !== null && opts !== undefined ? opts : {};
18026
+ const { cache = false, buildttl = -1, locale = "en_US", } = opts !== null && opts !== undefined ? opts : {};
17926
18027
  return new Promise((resolve, reject) => {
17927
18028
  let payload = {
17928
18029
  context: filters,
@@ -17950,7 +18051,6 @@ class Component extends BaseClient {
17950
18051
  sortDesc: sortDesc,
17951
18052
  filter: ctx.filter,
17952
18053
  filterOn: ctx.filterOn.join(","),
17953
- disabled: ctx.disabled,
17954
18054
  limit: limit,
17955
18055
  dateFrom: ctx.dateFrom,
17956
18056
  dateTo: ctx.dateTo,
@@ -17962,9 +18062,11 @@ class Component extends BaseClient {
17962
18062
  if (ctx.$aggregate && ctx.$aggregate.length > 0) {
17963
18063
  params.$aggregate = JSON.stringify(ctx.$aggregate);
17964
18064
  }
17965
- Object.keys(opts || {}).forEach(k => {
17966
- params[`_opt_${k}`] = opts[k];
17967
- });
18065
+ if (opts) {
18066
+ Object.keys(opts).forEach(k => {
18067
+ params[`_opt_${k}`] = opts ? opts[k] : null;
18068
+ });
18069
+ }
17968
18070
  this.client.get(`/v3/system/component/${this.ref}/models`, {
17969
18071
  params: params,
17970
18072
  headers: {
@@ -17980,6 +18082,19 @@ class Component extends BaseClient {
17980
18082
  });
17981
18083
  });
17982
18084
  }
18085
+ /**
18086
+ * FindOne method to search for a single model
18087
+ *
18088
+ * @param {FindAdvancedParams} filter - The filters to apply to the search
18089
+ * @param {FindOptions} opts - The options to apply to the search
18090
+ *
18091
+ * @returns {Promise<?Model>} - The result of the search
18092
+ *
18093
+ * @example
18094
+ * platform.component(name).findOne({
18095
+ * name: "John Doe",
18096
+ * })
18097
+ **/
17983
18098
  async findOne(filter, opts) {
17984
18099
  const { items } = await this.find({
17985
18100
  $adv: filter
@@ -17989,82 +18104,79 @@ class Component extends BaseClient {
17989
18104
  }
17990
18105
  return null;
17991
18106
  }
17992
- get(uuid) {
17993
- return new Promise((resolve, reject) => {
17994
- this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`).then((resp) => {
17995
- resolve(resp.data);
17996
- }).catch((error) => {
17997
- reject(error);
17998
- });
17999
- });
18107
+ /**
18108
+ * Get model by uuid
18109
+ *
18110
+ * @param uuid string - The uuid of the model
18111
+ * @returns (Promise<Model>)
18112
+ */
18113
+ async get(uuid) {
18114
+ const { data } = await this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`);
18115
+ return data;
18000
18116
  }
18001
- update(uuid, model) {
18002
- return new Promise((resolve, reject) => {
18003
- this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
18004
- data: model
18005
- }).then((resp) => {
18006
- resolve(resp.data);
18007
- }).catch((error) => {
18008
- reject(error);
18009
- });
18117
+ /**
18118
+ * Update model by uuid
18119
+ *
18120
+ * @param uuid string - The uuid of the model
18121
+ * @param data
18122
+ * @returns
18123
+ */
18124
+ async update(uuid, data, options) {
18125
+ const { data: responseData } = await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
18126
+ data,
18127
+ options,
18010
18128
  });
18129
+ return responseData;
18011
18130
  }
18012
- concurrentUpdate(uuid, version, model) {
18013
- return new Promise((resolve, reject) => {
18014
- this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
18015
- version: version,
18016
- data: model
18017
- }).then((resp) => {
18018
- resolve(resp.data);
18019
- }).catch((error) => {
18020
- reject(error);
18021
- });
18131
+ /**
18132
+ * Update many models
18133
+ *
18134
+ * @param data
18135
+ * @param options
18136
+ * @returns
18137
+ */
18138
+ async updateMany(data, options) {
18139
+ const { data: responseData } = await this.client.post(`/v3/system/component/${this.ref}/models/bulk`, {
18140
+ data,
18141
+ options,
18022
18142
  });
18143
+ return responseData;
18023
18144
  }
18024
- create(model) {
18025
- return new Promise((resolve, reject) => {
18026
- this.client.post(`/v3/system/component/${this.ref}/model`, model).then((resp) => {
18027
- resolve(resp.data);
18028
- }).catch((error) => {
18029
- reject(error);
18030
- });
18145
+ /**
18146
+ * Concurrent update model by uuid
18147
+ *
18148
+ * @param uuid string - The uuid of the model
18149
+ * @param version number - The version of the model
18150
+ * @param data
18151
+ * @returns
18152
+ */
18153
+ async concurrentUpdate(uuid, version, data, options) {
18154
+ const { data: responseData } = await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
18155
+ version: version,
18156
+ data,
18157
+ options,
18031
18158
  });
18159
+ return responseData;
18032
18160
  }
18033
- delete(uuid) {
18034
- return new Promise((resolve, reject) => {
18035
- this.client.delete(`/v3/system/component/${this.ref}/model/${uuid}`).then((resp) => {
18036
- resolve(resp.data);
18037
- }).catch((error) => {
18038
- reject(error);
18039
- });
18040
- });
18161
+ async create(model) {
18162
+ const { data } = await this.client.post(`/v3/system/component/${this.ref}/model`, model);
18163
+ return data;
18041
18164
  }
18042
- aggregate(payload) {
18043
- return new Promise((resolve, reject) => {
18044
- this.client.post(`/v3/system/component/${this.ref}/aggregate`, payload).then((resp) => {
18045
- resolve(resp.data);
18046
- }).catch((error) => {
18047
- reject(error);
18048
- });
18049
- });
18165
+ async delete(uuid) {
18166
+ const { data } = await this.client.delete(`/v3/system/component/${this.ref}/model/${uuid}`);
18167
+ return data;
18050
18168
  }
18051
- settings() {
18052
- return new Promise((resolve, reject) => {
18053
- this.client.get(`/v3/system/component/settings/${this.ref}`).then((resp) => {
18054
- resolve(resp.data);
18055
- }).catch(err => {
18056
- reject(err);
18057
- });
18058
- });
18169
+ async aggregate(pipeline) {
18170
+ const { data } = await this.client.post(`/v3/system/component/${this.ref}/aggregate`, pipeline);
18171
+ return data;
18059
18172
  }
18060
- saveSettings(settings) {
18061
- return new Promise((resolve, reject) => {
18062
- this.client.post("/v3/system/component/settings/" + settings.general.uuid + "/" + settings.settings.version, settings).then((resp) => {
18063
- resolve(resp.data);
18064
- }).catch(err => {
18065
- reject(err);
18066
- });
18067
- });
18173
+ async settings() {
18174
+ const { data } = await this.client.get(`/v3/system/component/settings/${this.ref}`);
18175
+ return data;
18176
+ }
18177
+ async saveSettings(settings, version) {
18178
+ const { data } = await this.client.post(`/v3/system/component/settings/${this.ref}/${version}`, settings);
18179
+ return data;
18068
18180
  }
18069
18181
  async saveTemplatesDist(version, sdkVersion, engine, dist) {
18070
18182
  const { data } = await this.client.post(`/v3/system/component/templates/${this.ref}/${version}`, {
@@ -18077,24 +18189,136 @@ class Component extends BaseClient {
18077
18189
  return data;
18078
18190
  }
18079
18191
  async workflow(event, input) {
18080
- return await this.client.post("/v1/system/component/" + this.ref + "/workflow/event", {
18192
+ const { data } = await this.client.post(`/v1/system/component/${this.ref}/workflow/event`, {
18081
18193
  event,
18082
18194
  input
18083
18195
  });
18196
+ return data;
18084
18197
  }
18085
18198
  async function(name, input) {
18086
- return await this.client.post(`/v3/system/component/${this.ref}/function/${name}`, input);
18199
+ const { data } = await this.client.post(`/v3/system/component/${this.ref}/function/${name}`, input);
18200
+ return data;
18087
18201
  }
18088
- async all() {
18202
+ }
18203
+
18204
+ class ComponentUtils extends PlatformBaseClient {
18205
+ async list() {
18089
18206
  const { data } = await this.client.get("/v1/system/components");
18090
18207
  return data;
18091
18208
  }
18092
- async setup(data) {
18093
- return await this.client.post("/v3/system/component/create", data);
18209
+ async create(data) {
18210
+ const { data: responseData } = await this.client.post("/v3/system/component/create", data);
18211
+ return responseData;
18212
+ }
18213
+ }
18214
+
18215
+ class Ratchet extends PlatformBaseClient {
18216
+ async query(name, params) {
18217
+ let res = await this.client.post('/v1/ratchet/query', {
18218
+ name: name,
18219
+ params: params
18220
+ });
18221
+ return res.data;
18222
+ }
18223
+ }
18224
+
18225
+ class Sandbox extends PlatformBaseClient {
18226
+ /**
18227
+ * Call the sandbox service to execute a serverless function
18228
+ *
18229
+ * @param name
18230
+ * @param data
18231
+ * @returns
18232
+ *
18233
+ * @example
18234
+ * const result = await platform.sandbox().spark("myFunction", { foo: "bar" })
18235
+ */
18236
+ async spark(name, data) {
18237
+ return await this.client.post(`/v1/project/sandbox/spark/exec/${name}`, data);
18238
+ }
18239
+ }
18240
+
18241
+ class System extends PlatformBaseClient {
18242
+ async resourceResolver(ref, resourceName, format) {
18243
+ const { data } = await this.client.post("/v3/system/resource-resolver", {
18244
+ type: resourceName,
18245
+ format,
18246
+ });
18247
+ if (format) {
18248
+ return data.format;
18249
+ }
18250
+ return data;
18251
+ }
18252
+ }
18253
+
18254
+ class Workflow extends PlatformBaseClient {
18255
+ async trigger(id, event, data) {
18256
+ return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
18257
+ }
18258
+ }
18259
+
18260
+ class Forge extends PlatformBaseClient {
18261
+ async bundleUpload(buffer) {
18262
+ return await this.client.post(`/v3/system/gateway/app-service/forge/upload`, buffer, {
18263
+ headers: {
18264
+ 'Content-Type': 'application/octet-stream',
18265
+ 'Content-Length': buffer.length
18266
+ }
18267
+ });
18268
+ }
18269
+ async getWorkspaceApps() {
18270
+ return await this.client.get(`/v3/system/gateway/app-service/forge/workspace`);
18271
+ }
18272
+ }
18273
+
18274
+ // apis
18275
+ class Platform extends PlatformBaseClient {
18276
+ getPlatformClient() {
18277
+ return this.client;
18278
+ }
18279
+ getPlatformBaseURL() {
18280
+ var _a;
18281
+ return (_a = this.client.defaults.baseURL) !== null && _a !== undefined ? _a : "";
18282
+ }
18283
+ apiUser() {
18284
+ return (new APIUser()).setClient(this.client);
18285
+ }
18286
+ function() {
18287
+ return (new Functions()).setClient(this.client);
18288
+ }
18289
+ role() {
18290
+ return (new Roles()).setClient(this.client);
18291
+ }
18292
+ user() {
18293
+ return (new Users()).setClient(this.client);
18294
+ }
18295
+ app(appType) {
18296
+ return (new Apps(appType)).setClient(this.client);
18297
+ }
18298
+ forge() {
18299
+ return (new Forge()).setClient(this.client);
18300
+ }
18301
+ component(ref) {
18302
+ return (new Component(ref)).setClient(this.client);
18303
+ }
18304
+ componentUtils() {
18305
+ return (new ComponentUtils()).setClient(this.client);
18306
+ }
18307
+ ratchet() {
18308
+ return (new Ratchet()).setClient(this.client);
18309
+ }
18310
+ sandbox() {
18311
+ return (new Sandbox()).setClient(this.client);
18312
+ }
18313
+ system() {
18314
+ return (new System()).setClient(this.client);
18315
+ }
18316
+ workflow() {
18317
+ return (new Workflow()).setClient(this.client);
18094
18318
  }
18095
18319
  }
18096
18320
 
18097
- class Invoicing extends BaseClient {
18321
+ class Invoicing extends PlatformBaseClient {
18098
18322
  async getSalesInvoices(provider, page) {
18099
18323
  return await this.request("GET", `/invoices/${provider}/sales`, {
18100
18324
  params: {
@@ -18113,13 +18337,48 @@ class Invoicing extends BaseClient {
18113
18337
  async request(method, endpoint, params) {
18114
18338
  return await this.client.request({
18115
18339
  method: method,
18116
- url: `/v1/karadjordje/${endpoint}`,
18340
+ url: `/v1/integrations/karadjordje/${endpoint}`,
18117
18341
  ...params
18118
18342
  });
18119
18343
  }
18120
18344
  }
18121
18345
 
18122
- class Media extends BaseClient {
18346
+ class IntegrationsBaseClient extends BaseClient {
18347
+ constructor(options) {
18348
+ var _a, _b;
18349
+ let { env = null, token, host, } = options !== null && options !== undefined ? options : {};
18350
+ let headers = {};
18351
+ if (isBrowser) {
18352
+ if (localStorage.getItem('protokol_context') == "forge") {
18353
+ headers['X-Project-Env'] = (_a = localStorage.getItem('forge_app_env')) !== null && _a !== undefined ? _a : "dev";
18354
+ }
18355
+ else {
18356
+ // this potentially means that it is running as dev server in local
18357
+ headers['X-Project-Env'] = "dev";
18358
+ }
18359
+ // @ts-ignore
18360
+ const __global_env__ = window === null || window === undefined ? undefined : window.__ENV_VARIABLES__;
18361
+ host = (_b = __global_env__.INTEGRATION_API) !== null && _b !== undefined ? _b : host;
18362
+ }
18363
+ if (token) {
18364
+ headers['Authorization'] = `Bearer ${token}`;
18365
+ }
18366
+ if (env) {
18367
+ headers['X-Project-Env'] = env;
18368
+ }
18369
+ const client = axios.create({
18370
+ baseURL: host !== null && host !== undefined ? host : "https://orange.protokol.io",
18371
+ timeout: 15000,
18372
+ headers: {
18373
+ ...headers,
18374
+ },
18375
+ withCredentials: true,
18376
+ });
18377
+ super(client);
18378
+ }
18379
+ }
18380
+
18381
+ class Media extends IntegrationsBaseClient {
18123
18382
  async list(data) {
18124
18383
  return this.request('POST', 'list', { data });
18125
18384
  }
@@ -18229,7 +18488,7 @@ class Media extends BaseClient {
18229
18488
  }
18230
18489
  }
18231
18490
 
18232
- class SerbiaUtil extends BaseClient {
18491
+ class SerbiaUtil extends IntegrationsBaseClient {
18233
18492
  async nsbSearch(params) {
18234
18493
  return await this.services("GET", "nbs/search", { params });
18235
18494
  }
@@ -18256,7 +18515,7 @@ class SerbiaUtil extends BaseClient {
18256
18515
  }
18257
18516
  }
18258
18517
 
18259
- class VPFR extends BaseClient {
18518
+ class VPFR extends IntegrationsBaseClient {
18260
18519
  async request(method, endpoint, params) {
18261
18520
  return await this.client.request({
18262
18521
  method: method,
@@ -18266,14 +18525,15 @@ class VPFR extends BaseClient {
18266
18525
  }
18267
18526
  }
18268
18527
 
18269
- class Integrations extends BaseClient {
18270
- constructor(adapter) {
18271
- super(adapter);
18528
+ // import integrations
18529
+ class Integrations extends IntegrationsBaseClient {
18530
+ constructor(options) {
18531
+ super(options);
18272
18532
  this.integrations = {
18273
- 'protokol-invoicing': new Invoicing(adapter),
18274
- 'protokol-vpfr': new VPFR(adapter),
18275
- 'protokol-media': new Media(adapter),
18276
- 'serbia-utilities': new SerbiaUtil(adapter)
18533
+ 'protokol-invoicing': new Invoicing().setClient(this.client),
18534
+ 'protokol-vpfr': new VPFR().setClient(this.client),
18535
+ 'protokol-media': new Media().setClient(this.client),
18536
+ 'serbia-utilities': new SerbiaUtil().setClient(this.client),
18277
18537
  };
18278
18538
  }
18279
18539
  getSerbiaUtilities() {
@@ -18302,150 +18562,16 @@ class Integrations extends BaseClient {
18302
18562
  }
18303
18563
  }
18304
18564
 
18305
- class Ratchet extends BaseClient {
18306
- async query(name, params) {
18307
- let res = await this.client.post('/v1/ratchet/query', {
18308
- name: name,
18309
- params: params
18310
- });
18311
- return res.data;
18312
- }
18313
- }
18314
-
18315
- class Sandbox extends BaseClient {
18316
- async spark(name, data) {
18317
- return await this.client.post(`/v1/project/sandbox/spark/exec/${name}`, data);
18318
- }
18319
- }
18320
-
18321
- class System extends BaseClient {
18322
- async resourceResolver(ref, resourceName, format) {
18323
- const { data } = await this.client.post("/v3/system/resource-resolver", {
18324
- type: resourceName,
18325
- format,
18326
- });
18327
- if (format) {
18328
- return data.format;
18329
- }
18330
- return data;
18331
- }
18332
- }
18333
-
18334
- class Workflow extends BaseClient {
18335
- async trigger(id, event, data) {
18336
- return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
18337
- }
18338
- }
18339
-
18340
- class Forge extends BaseClient {
18341
- constructor(client) {
18342
- super(client);
18343
- }
18344
- async bundleUpload(buffer) {
18345
- return await this.client.post(`/v3/system/gateway/app-service/forge/upload`, buffer, {
18346
- headers: {
18347
- 'Content-Type': 'application/octet-stream',
18348
- 'Content-Length': buffer.length
18349
- }
18350
- });
18351
- }
18352
- async getWorkspaceApps() {
18353
- return await this.client.get(`/v3/system/gateway/app-service/forge/workspace`);
18354
- }
18355
- }
18356
-
18357
- typeof process !== "undefined" &&
18358
- process.versions != null &&
18359
- process.versions.node != null;
18360
- const isBrowser = typeof window !== "undefined" &&
18361
- typeof document !== "undefined";
18362
-
18363
- class Platform {
18364
- constructor(options) {
18365
- var _a;
18366
- let { project = null, env = null, token, host, integrationHost } = options !== null && options !== undefined ? options : {};
18367
- let headers = {};
18368
- if (isBrowser) {
18369
- if (localStorage.getItem('protokol_context') == "forge") {
18370
- headers['X-Project-Env'] = (_a = localStorage.getItem('forge_app_env')) !== null && _a !== undefined ? _a : "dev";
18371
- }
18372
- else {
18373
- // this potentially means that it is running as dev server in local
18374
- headers['X-Project-Env'] = "dev";
18375
- // here we don't know actual project so we need a way to determine it
18376
- }
18377
- }
18378
- if (token) {
18379
- headers['Authorization'] = `Bearer ${token}`;
18380
- }
18381
- if (env) {
18382
- headers['X-Project-Env'] = env;
18383
- }
18384
- if (project) {
18385
- headers['X-Project-Uuid'] = project;
18386
- }
18387
- this.platformClient = axios.create({
18388
- baseURL: host !== null && host !== undefined ? host : "https://lemon.protokol.io",
18389
- timeout: 15000,
18390
- headers: {
18391
- ...headers,
18392
- },
18393
- withCredentials: true,
18394
- });
18395
- this.integrationsClient = axios.create({
18396
- baseURL: integrationHost !== null && integrationHost !== undefined ? integrationHost : "https://orange.protokol.io",
18397
- timeout: 15000,
18398
- headers: {
18399
- ...headers,
18400
- }
18401
- });
18402
- }
18403
- setPlatformClient(client) {
18404
- this.platformClient = client;
18405
- }
18406
- getPlatformClient() {
18407
- return this.platformClient;
18408
- }
18409
- getPlatformBaseURL() {
18410
- var _a;
18411
- return (_a = this.platformClient.defaults.baseURL) !== null && _a !== undefined ? _a : "";
18412
- }
18413
- apiUser() {
18414
- return new APIUser(this.platformClient);
18415
- }
18416
- function() {
18417
- return new Functions(this.platformClient);
18418
- }
18419
- role() {
18420
- return new Roles(this.platformClient);
18421
- }
18422
- user() {
18423
- return new Users(this.platformClient);
18424
- }
18425
- app(appType) {
18426
- return new Apps(this.platformClient, appType);
18427
- }
18428
- forge() {
18429
- return new Forge(this.platformClient);
18430
- }
18431
- component(ref) {
18432
- return new Component(this.platformClient, ref);
18433
- }
18434
- integrations() {
18435
- return new Integrations(this.integrationsClient);
18436
- }
18437
- ratchet() {
18438
- return new Ratchet(this.platformClient);
18439
- }
18440
- sandbox() {
18441
- return new Sandbox(this.platformClient);
18442
- }
18443
- system() {
18444
- return new System(this.platformClient);
18445
- }
18446
- workflow() {
18447
- return new Workflow(this.platformClient);
18448
- }
18449
- }
18450
-
18451
- module.exports = Platform;
18565
+ exports.APIUser = APIUser;
18566
+ exports.Apps = Apps;
18567
+ exports.Component = Component;
18568
+ exports.ComponentUtils = ComponentUtils;
18569
+ exports.Functions = Functions;
18570
+ exports.Integration = Integrations;
18571
+ exports.Ratchet = Ratchet;
18572
+ exports.Roles = Roles;
18573
+ exports.Sandbox = Sandbox;
18574
+ exports.System = System;
18575
+ exports.Users = Users;
18576
+ exports.Workflow = Workflow;
18577
+ exports.default = Platform;