@ptkl/sdk 0.10.2 → 1.0.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.
Files changed (132) hide show
  1. package/dist/{index.iife.js → index.0.10.js} +417 -230
  2. package/dist/index.0.9.js +2849 -0
  3. package/dist/package.json +12 -7
  4. package/dist/v0.10/api/component.d.ts +136 -0
  5. package/dist/v0.10/api/componentUtils.d.ts +16 -0
  6. package/dist/v0.10/api/index.d.ts +22 -0
  7. package/dist/{types → v0.10}/api/integrationsBaseClient.d.ts +3 -0
  8. package/dist/{types → v0.10}/api/platform.d.ts +2 -2
  9. package/dist/v0.10/apiUser.d.ts +9 -0
  10. package/dist/v0.10/apps.d.ts +8 -0
  11. package/dist/v0.10/baseClient.d.ts +6 -0
  12. package/dist/{types/api → v0.10}/component.d.ts +39 -4
  13. package/dist/v0.10/componentUtils.d.ts +7 -0
  14. package/dist/v0.10/config.d.ts +14 -0
  15. package/dist/v0.10/forge.d.ts +7 -0
  16. package/dist/v0.10/functions.d.ts +23 -0
  17. package/dist/{index.cjs.js → v0.10/index.cjs.js} +417 -230
  18. package/dist/v0.10/index.d.ts +21 -0
  19. package/dist/{index.esm.js → v0.10/index.esm.js} +416 -227
  20. package/dist/v0.10/integrations/dms.d.ts +469 -0
  21. package/dist/v0.10/integrations/invoicing.d.ts +6 -0
  22. package/dist/v0.10/integrations/minimax.d.ts +289 -0
  23. package/dist/v0.10/integrations/payments.d.ts +40 -0
  24. package/dist/v0.10/integrations/serbiaUtil.d.ts +10 -0
  25. package/dist/v0.10/integrations/vpfr.d.ts +4 -0
  26. package/dist/v0.10/integrations.d.ts +22 -0
  27. package/dist/v0.10/integrationsBaseClient.d.ts +11 -0
  28. package/dist/v0.10/platform.d.ts +34 -0
  29. package/dist/v0.10/platformBaseClient.d.ts +27 -0
  30. package/dist/v0.10/project.d.ts +146 -0
  31. package/dist/v0.10/ratchet.d.ts +196 -0
  32. package/dist/v0.10/sandbox.d.ts +14 -0
  33. package/dist/v0.10/system.d.ts +4 -0
  34. package/dist/v0.10/thunder.d.ts +13 -0
  35. package/dist/v0.10/types/component.d.ts +298 -0
  36. package/dist/v0.10/users.d.ts +69 -0
  37. package/dist/v0.10/workflow.d.ts +5 -0
  38. package/dist/v0.9/api/apiUser.d.ts +9 -0
  39. package/dist/v0.9/api/apps.d.ts +8 -0
  40. package/dist/v0.9/api/baseClient.d.ts +6 -0
  41. package/dist/v0.9/api/component.d.ts +136 -0
  42. package/dist/v0.9/api/config.d.ts +14 -0
  43. package/dist/v0.9/api/forge.d.ts +7 -0
  44. package/dist/v0.9/api/functions.d.ts +23 -0
  45. package/dist/v0.9/api/index.d.ts +24 -0
  46. package/dist/v0.9/api/integrations/dms.d.ts +419 -0
  47. package/dist/v0.9/api/integrations/invoicing.d.ts +6 -0
  48. package/dist/v0.9/api/integrations/minimax.d.ts +289 -0
  49. package/dist/v0.9/api/integrations/payments.d.ts +40 -0
  50. package/dist/v0.9/api/integrations/serbiaUtil.d.ts +10 -0
  51. package/dist/v0.9/api/integrations/vpfr.d.ts +4 -0
  52. package/dist/v0.9/api/integrations.d.ts +22 -0
  53. package/dist/v0.9/api/integrationsBaseClient.d.ts +11 -0
  54. package/dist/v0.9/api/platform.d.ts +34 -0
  55. package/dist/v0.9/api/platformBaseClient.d.ts +27 -0
  56. package/dist/v0.9/api/project.d.ts +146 -0
  57. package/dist/v0.9/api/ratchet.d.ts +196 -0
  58. package/dist/v0.9/api/sandbox.d.ts +14 -0
  59. package/dist/v0.9/api/system.d.ts +4 -0
  60. package/dist/v0.9/api/thunder.d.ts +13 -0
  61. package/dist/v0.9/api/users.d.ts +69 -0
  62. package/dist/v0.9/api/workflow.d.ts +5 -0
  63. package/dist/v0.9/apiUser.d.ts +9 -0
  64. package/dist/v0.9/apps.d.ts +8 -0
  65. package/dist/v0.9/baseClient.d.ts +6 -0
  66. package/dist/v0.9/component.d.ts +128 -0
  67. package/dist/v0.9/componentUtils.d.ts +7 -0
  68. package/dist/v0.9/config.d.ts +14 -0
  69. package/dist/v0.9/forge.d.ts +7 -0
  70. package/dist/v0.9/functions.d.ts +23 -0
  71. package/dist/v0.9/index.cjs.js +21811 -0
  72. package/dist/v0.9/index.d.ts +21 -0
  73. package/dist/v0.9/index.esm.js +2820 -0
  74. package/dist/v0.9/integrations/dms.d.ts +469 -0
  75. package/dist/v0.9/integrations/invoicing.d.ts +6 -0
  76. package/dist/v0.9/integrations/minimax.d.ts +289 -0
  77. package/dist/v0.9/integrations/payments.d.ts +40 -0
  78. package/dist/v0.9/integrations/serbiaUtil.d.ts +10 -0
  79. package/dist/v0.9/integrations/vpfr.d.ts +4 -0
  80. package/dist/v0.9/integrations.d.ts +22 -0
  81. package/dist/v0.9/integrationsBaseClient.d.ts +11 -0
  82. package/dist/v0.9/platform.d.ts +34 -0
  83. package/dist/v0.9/platformBaseClient.d.ts +27 -0
  84. package/dist/v0.9/project.d.ts +146 -0
  85. package/dist/v0.9/ratchet.d.ts +196 -0
  86. package/dist/v0.9/sandbox.d.ts +14 -0
  87. package/dist/v0.9/system.d.ts +4 -0
  88. package/dist/v0.9/thunder.d.ts +13 -0
  89. package/dist/{types → v0.9}/types/component.d.ts +34 -2
  90. package/dist/v0.9/types/config.d.ts +11 -0
  91. package/dist/v0.9/types/integrations.d.ts +321 -0
  92. package/dist/v0.9/types/project.d.ts +64 -0
  93. package/dist/v0.9/types/ratchet.d.ts +38 -0
  94. package/dist/v0.9/types/users.d.ts +66 -0
  95. package/dist/v0.9/users.d.ts +69 -0
  96. package/dist/v0.9/util/detectEnv.d.ts +4 -0
  97. package/dist/v0.9/workflow.d.ts +5 -0
  98. package/package.json +12 -7
  99. package/dist/monaco.d.ts +0 -887
  100. package/dist/types/api/index.d.ts +0 -13
  101. package/dist/types/api/integrations/media.d.ts +0 -17
  102. package/dist/types/api/roles.d.ts +0 -9
  103. package/dist/types/index.d.ts +0 -29
  104. package/dist/types/types/media.d.ts +0 -103
  105. /package/dist/{types → v0.10}/api/apiUser.d.ts +0 -0
  106. /package/dist/{types → v0.10}/api/apps.d.ts +0 -0
  107. /package/dist/{types → v0.10}/api/baseClient.d.ts +0 -0
  108. /package/dist/{types → v0.10}/api/config.d.ts +0 -0
  109. /package/dist/{types → v0.10}/api/forge.d.ts +0 -0
  110. /package/dist/{types → v0.10}/api/functions.d.ts +0 -0
  111. /package/dist/{types → v0.10}/api/integrations/dms.d.ts +0 -0
  112. /package/dist/{types → v0.10}/api/integrations/invoicing.d.ts +0 -0
  113. /package/dist/{types → v0.10}/api/integrations/minimax.d.ts +0 -0
  114. /package/dist/{types → v0.10}/api/integrations/payments.d.ts +0 -0
  115. /package/dist/{types → v0.10}/api/integrations/serbiaUtil.d.ts +0 -0
  116. /package/dist/{types → v0.10}/api/integrations/vpfr.d.ts +0 -0
  117. /package/dist/{types → v0.10}/api/integrations.d.ts +0 -0
  118. /package/dist/{types → v0.10}/api/platformBaseClient.d.ts +0 -0
  119. /package/dist/{types → v0.10}/api/project.d.ts +0 -0
  120. /package/dist/{types → v0.10}/api/ratchet.d.ts +0 -0
  121. /package/dist/{types → v0.10}/api/sandbox.d.ts +0 -0
  122. /package/dist/{types → v0.10}/api/system.d.ts +0 -0
  123. /package/dist/{types → v0.10}/api/thunder.d.ts +0 -0
  124. /package/dist/{types → v0.10}/api/users.d.ts +0 -0
  125. /package/dist/{types → v0.10}/api/workflow.d.ts +0 -0
  126. /package/dist/{types → v0.10}/types/config.d.ts +0 -0
  127. /package/dist/{types → v0.10}/types/integrations.d.ts +0 -0
  128. /package/dist/{types → v0.10}/types/project.d.ts +0 -0
  129. /package/dist/{types → v0.10}/types/ratchet.d.ts +0 -0
  130. /package/dist/{types → v0.10}/types/users.d.ts +0 -0
  131. /package/dist/{types → v0.10}/util/detectEnv.d.ts +0 -0
  132. /package/dist/{types → v0.9}/api/componentUtils.d.ts +0 -0
@@ -35,27 +35,32 @@ var ProtokolSDK010 = (function (exports, axios) {
35
35
  */
36
36
  class PlatformBaseClient extends BaseClient {
37
37
  constructor(options) {
38
- var _a, _b, _c;
38
+ var _a, _b, _c, _d, _e, _f, _g;
39
39
  let { env = null, token = null, host = null, } = options !== null && options !== void 0 ? options : {};
40
40
  let headers = {};
41
41
  var project_uuid = null;
42
42
  if (isBrowser) {
43
- console.log("PlatformBaseClient: running in browser context");
44
43
  if (sessionStorage.getItem('protokol_context') == "forge") {
45
44
  headers['X-Project-Env'] = (_a = sessionStorage.getItem('forge_app_env')) !== null && _a !== void 0 ? _a : "dev";
46
45
  }
47
46
  else {
48
47
  headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
49
48
  }
49
+ if (typeof window !== "undefined") {
50
+ // @ts-ignore
51
+ const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
52
+ host = (_c = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.API_HOST) !== null && _c !== void 0 ? _c : host;
53
+ // @ts-ignore
54
+ env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
55
+ token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
56
+ project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
57
+ }
50
58
  }
51
- if (typeof window !== "undefined") {
52
- // @ts-ignore
53
- const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
54
- host = (_c = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.API_HOST) !== null && _c !== void 0 ? _c : host;
55
- // @ts-ignore
56
- env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
57
- token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
58
- project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
59
+ else if (process && process.env) {
60
+ host = (_d = host !== null && host !== void 0 ? host : process.env.API_HOST) !== null && _d !== void 0 ? _d : null;
61
+ env = (_e = env !== null && env !== void 0 ? env : process.env.PROJECT_ENV) !== null && _e !== void 0 ? _e : null;
62
+ token = (_f = token !== null && token !== void 0 ? token : process.env.PROJECT_API_TOKEN) !== null && _f !== void 0 ? _f : null;
63
+ project_uuid = (_g = process.env.PROJECT_UUID) !== null && _g !== void 0 ? _g : null;
59
64
  }
60
65
  if (token) {
61
66
  headers['Authorization'] = `Bearer ${token}`;
@@ -82,198 +87,22 @@ var ProtokolSDK010 = (function (exports, axios) {
82
87
  }
83
88
  }
84
89
 
85
- class Functions extends PlatformBaseClient {
86
- async list() {
87
- return await this.client.get("/v1/system/function");
88
- }
89
- async get(ref) {
90
- return await this.client.get(`/v1/system/function/${ref}`);
91
- }
92
- async update(uuid, update) {
93
- return await this.client.patch(`/v1/system/function/${uuid}`, update);
94
- }
95
- /**
96
- * Run platform function
97
- *
98
- * @param id - Function ID
99
- * @param input - Input data
100
- * @param query - Query parameters
101
- * @returns - Function result
102
- *
103
- * @example
104
- * const result = await platform.function().run("myFunction", {input: { foo: "bar" }})
105
- */
106
- async run(id, d) {
107
- const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
108
- params: d.query,
109
- headers: d.headers
110
- });
111
- return data;
112
- }
113
- async generateSignature(ref, env) {
114
- return await this.client.get(`/v1/system/function/signature/${env}/${ref}`);
115
- }
116
- }
117
-
118
- class APIUser extends PlatformBaseClient {
119
- async auth(username, password, project) {
120
- return this.client.post("/v1/user/api/auth", {
121
- username,
122
- password
123
- }, {
124
- headers: {
125
- "X-Project-Uuid": project
126
- }
127
- });
128
- }
129
- async newSecret(uuid) {
130
- return await this.client.post(`/v1/user/api-user/secret/${uuid}`, {});
131
- }
132
- async revokeSecret(uuid) {
133
- return await this.client.delete(`/v1/user/api-user/secret/${uuid}`);
134
- }
135
- async edit(uuid, roles) {
136
- return await this.client.patch(`/v1/user/api-user/${uuid}`, { roles });
137
- }
138
- async list() {
139
- return await this.client.get(`/v1/user/api-user`);
140
- }
141
- async get(uuid) {
142
- return await this.client.get(`/v1/user/api-user/${uuid}`);
143
- }
144
- }
145
-
146
- class Users extends PlatformBaseClient {
147
- async auth(username, password, project) {
148
- return await this.client.post("/v1/user/login", {
149
- username,
150
- password,
151
- response_type: 'token',
152
- }, {
153
- headers: {
154
- 'X-Project-Uuid': project
155
- }
156
- });
157
- }
158
- /**
159
- * Resend confirmation email
160
- * @param email User email
161
- */
162
- async resendConfirmationEmail(email) {
163
- return await this.client.post("/v1/user/send/confirmation/email", {
164
- email,
165
- });
166
- }
167
- // Password Reset (Request Only)
168
- // Note: Only the REQUEST is exposed, not the password reset completion
169
- // The actual password reset should be done through the official web interface
170
- /**
171
- * Request password reset email
172
- * This only sends an email with a reset link, does not expose or change passwords
173
- * @param email User email
174
- */
175
- async requestPasswordReset(email) {
176
- return await this.client.post("/v1/user/resetpassword", { email });
177
- }
178
- // User Profile & Management
179
- /**
180
- * Get current user's model
181
- */
182
- async getUser() {
183
- return await this.client.get("/v1/user/model");
184
- }
185
- /**
186
- * Get current user's claims
187
- */
188
- async getClaims() {
189
- return await this.client.get("/v1/user/claims");
190
- }
191
- /**
192
- * Edit user profile
193
- * @param data Profile update data
194
- */
195
- async editProfile(data) {
196
- return await this.client.post("/v1/user/profile/edit", data);
197
- }
198
- // Permissions & Roles
199
- /**
200
- * Get user permissions
201
- */
202
- async getPermissions() {
203
- return await this.client.get("/v1/user/role/permissions");
204
- }
205
- /**
206
- * Get list of available permissions
207
- */
208
- async listPermissions() {
209
- return await this.client.get("/v1/user/permissions/list");
210
- }
211
- /**
212
- * Create a new role
213
- * @param role Role data including name, permissions, workspaces, and level
214
- */
215
- async createRole(role) {
216
- return await this.client.post("/v1/user/role/create", role);
217
- }
218
- /**
219
- * Delete a role
220
- * @param uuid Role UUID
221
- */
222
- async deleteRole(uuid) {
223
- return await this.client.delete(`/v1/user/role/delete/${uuid}`);
224
- }
225
- /**
226
- * List all roles
227
- */
228
- async listRoles() {
229
- return await this.client.get(`/v1/user/role/list`);
230
- }
231
- /**
232
- * Get role details by UUID
233
- * @param uuid Role UUID
234
- */
235
- async getRoleModel(uuid) {
236
- return await this.client.get(`/v1/user/role/edit/${uuid}`);
237
- }
238
- /**
239
- * Edit a role
240
- * @param uuid Role UUID
241
- * @param data Role update data including permissions, workspaces, and level
242
- */
243
- async editRole(uuid, data) {
244
- return await this.client.post(`/v1/user/role/edit/${uuid}`, data);
245
- }
246
- /**
247
- * @deprecated Use getPermissions() instead
248
- */
249
- async permissions() {
250
- return await this.client.get(`/v1/user/role/permissions`);
251
- }
252
- }
253
-
254
- class Apps extends PlatformBaseClient {
255
- constructor(appType) {
256
- super();
257
- this.appType = appType;
258
- }
259
- async updateSettings(updateValues, ref) {
260
- const payload = { ...updateValues };
261
- return await this.client.put(`/v3/system/gateway/app-service/${this.appType}/${ref}/settings`, payload);
262
- }
263
- async download(ref, version) {
264
- return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
265
- }
266
- async upload(formData) {
267
- return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
268
- timeout: 60000
269
- });
270
- }
271
- }
272
-
273
90
  class Component extends PlatformBaseClient {
274
- constructor(ref = null) {
91
+ constructor(ref = null, options) {
92
+ var _a;
275
93
  super();
276
94
  this.ref = ref;
95
+ this.version = (_a = options === null || options === void 0 ? void 0 : options.version) !== null && _a !== void 0 ? _a : null;
96
+ }
97
+ /**
98
+ * Get the base path for component API calls
99
+ * @private
100
+ */
101
+ getComponentPath() {
102
+ if (this.version) {
103
+ return `/v3/system/component/${this.ref}/v/${this.version}`;
104
+ }
105
+ return `/v3/system/component/${this.ref}`;
277
106
  }
278
107
  /**
279
108
  * Find method to search for models
@@ -343,7 +172,7 @@ var ProtokolSDK010 = (function (exports, axios) {
343
172
  params[`_opt_${k}`] = opts ? opts[k] : null;
344
173
  });
345
174
  }
346
- return await this.client.get(`/v3/system/component/${this.ref}/models`, {
175
+ return await this.client.get(`${this.getComponentPath()}/models`, {
347
176
  params: params,
348
177
  headers: {
349
178
  'X-Cache': cache,
@@ -382,7 +211,7 @@ var ProtokolSDK010 = (function (exports, axios) {
382
211
  * @returns (Promise<Model>)
383
212
  */
384
213
  async get(uuid) {
385
- return await this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`);
214
+ return await this.client.get(`${this.getComponentPath()}/model/${uuid}`);
386
215
  }
387
216
  /**
388
217
  * Update model by uuid
@@ -392,7 +221,7 @@ var ProtokolSDK010 = (function (exports, axios) {
392
221
  * @returns
393
222
  */
394
223
  async update(uuid, data, options) {
395
- return await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
224
+ return await this.client.post(`${this.getComponentPath()}/model/${uuid}`, {
396
225
  data,
397
226
  options,
398
227
  });
@@ -405,9 +234,22 @@ var ProtokolSDK010 = (function (exports, axios) {
405
234
  * @returns
406
235
  */
407
236
  async updateMany(data, options) {
408
- return await this.client.post(`/v3/system/component/${this.ref}/models/bulk`, {
237
+ return await this.client.patch(`${this.getComponentPath()}/models/bulk`, {
409
238
  data,
410
- options,
239
+ options
240
+ });
241
+ }
242
+ /**
243
+ * Create many models
244
+ *
245
+ * @param data
246
+ * @param options
247
+ * @returns
248
+ */
249
+ async createMany(data, options) {
250
+ return await this.client.post(`${this.getComponentPath()}/models/bulk`, {
251
+ data,
252
+ options
411
253
  });
412
254
  }
413
255
  /**
@@ -418,7 +260,7 @@ var ProtokolSDK010 = (function (exports, axios) {
418
260
  * @returns
419
261
  */
420
262
  async modify(filters, data, options) {
421
- return await this.client.patch(`/v3/system/component/${this.ref}/modify/model`, {
263
+ return await this.client.patch(`${this.getComponentPath()}/modify/model`, {
422
264
  filters,
423
265
  data,
424
266
  options,
@@ -433,20 +275,84 @@ var ProtokolSDK010 = (function (exports, axios) {
433
275
  * @returns
434
276
  */
435
277
  async concurrentUpdate(uuid, version, data, options) {
436
- return await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
278
+ return await this.client.post(`${this.getComponentPath()}/model/${uuid}`, {
437
279
  version: version,
438
280
  data,
439
281
  options,
440
282
  });
441
283
  }
442
284
  async create(model) {
443
- return await this.client.post(`/v3/system/component/${this.ref}/model`, model);
285
+ return await this.client.post(`${this.getComponentPath()}/model`, model);
444
286
  }
445
287
  async delete(uuid) {
446
- return await this.client.delete(`/v3/system/component/${this.ref}/model/${uuid}`);
288
+ return await this.client.delete(`${this.getComponentPath()}/model/${uuid}`);
447
289
  }
448
- async aggregate(pipeline) {
449
- return await this.client.post(`/v3/system/component/${this.ref}/aggregate`, pipeline);
290
+ /**
291
+ * Execute aggregate pipeline with optional streaming support
292
+ *
293
+ * Returns a chainable object that allows both buffered and streaming modes.
294
+ * Call .onData() to enable streaming mode, or await directly for buffered mode.
295
+ *
296
+ * @param {FindAggregateParams} pipeline - MongoDB aggregation pipeline
297
+ *
298
+ * @returns {AggregateChainable} Chainable object with streaming methods and Promise interface
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * // Buffered response (default, up to 5K documents)
303
+ * const result = await component.aggregate([{ $match: { status: 'active' } }]);
304
+ * console.log(result.data); // All results at once
305
+ *
306
+ * // Streaming response (up to 25K documents)
307
+ * await component.aggregate([{ $match: { status: 'active' } }])
308
+ * .onData((doc) => console.log('Received:', doc))
309
+ * .onError((err) => console.error('Error:', err))
310
+ * .onEnd(() => console.log('Stream complete'));
311
+ * ```
312
+ */
313
+ aggregate(pipeline) {
314
+ let onDataCallback = () => { };
315
+ let onErrorCallback;
316
+ let onEndCallback;
317
+ let isStreaming = false;
318
+ let streamPromise = null;
319
+ const chainable = {
320
+ onData: (callback) => {
321
+ onDataCallback = callback;
322
+ isStreaming = true;
323
+ return chainable;
324
+ },
325
+ onError: (callback) => {
326
+ onErrorCallback = callback;
327
+ return chainable;
328
+ },
329
+ onEnd: (callback) => {
330
+ onEndCallback = callback;
331
+ return chainable;
332
+ },
333
+ then: (resolve, reject) => {
334
+ if (isStreaming) {
335
+ if (!streamPromise) {
336
+ const handler = {
337
+ onData: onDataCallback,
338
+ onError: onErrorCallback,
339
+ onEnd: onEndCallback
340
+ };
341
+ streamPromise = this._streamNDJSON(`${this.getComponentPath()}/aggregate`, {
342
+ 'Accept': 'application/x-ndjson',
343
+ 'Content-Type': 'application/json'
344
+ }, handler, pipeline);
345
+ }
346
+ return streamPromise.then(resolve, reject);
347
+ }
348
+ return this.client.post(`${this.getComponentPath()}/aggregate`, pipeline)
349
+ .then(resolve, reject);
350
+ },
351
+ catch: (reject) => {
352
+ return chainable.then(undefined, reject);
353
+ }
354
+ };
355
+ return chainable;
450
356
  }
451
357
  async settings() {
452
358
  return await this.client.get(`/v3/system/component/settings/${this.ref}`);
@@ -464,18 +370,281 @@ var ProtokolSDK010 = (function (exports, axios) {
464
370
  });
465
371
  }
466
372
  async workflow(event, input) {
467
- return await this.client.post(`/v3/system/component/${this.ref}/workflow/event`, {
373
+ return await this.client.post(`${this.getComponentPath()}/workflow/event`, {
468
374
  event,
469
375
  input
470
376
  });
471
377
  }
472
378
  async function(name, input) {
473
- return await this.client.post(`/v3/system/component/${this.ref}/function/${name}`, {
379
+ return await this.client.post(`${this.getComponentPath()}/function/${name}`, {
474
380
  data: input
475
381
  });
476
382
  }
477
383
  async revisions(uuid) {
478
- return await this.client.get(`/v3/system/component/${this.ref}/model/${uuid}/revisions`);
384
+ return await this.client.get(`${this.getComponentPath()}/model/${uuid}/revisions`);
385
+ }
386
+ /**
387
+ * Internal method to handle NDJSON streaming responses
388
+ *
389
+ * @private
390
+ */
391
+ async _streamNDJSON(url, headers, handler, body) {
392
+ try {
393
+ const config = {
394
+ headers,
395
+ responseType: 'stream'
396
+ };
397
+ const response = await this.client.post(url, body, config);
398
+ const stream = response.data;
399
+ let buffer = '';
400
+ return new Promise((resolve, reject) => {
401
+ stream.on('data', (chunk) => {
402
+ buffer += chunk.toString();
403
+ // Process complete lines (separated by newlines)
404
+ const lines = buffer.split('\n');
405
+ buffer = lines.pop() || ''; // Keep incomplete line in buffer
406
+ for (const line of lines) {
407
+ if (line.trim()) {
408
+ try {
409
+ const document = JSON.parse(line);
410
+ const result = handler.onData(document);
411
+ // Support async callbacks
412
+ if (result instanceof Promise) {
413
+ result.catch((err) => {
414
+ if (handler.onError) {
415
+ handler.onError(err);
416
+ }
417
+ });
418
+ }
419
+ }
420
+ catch (err) {
421
+ if (handler.onError) {
422
+ handler.onError(err);
423
+ }
424
+ }
425
+ }
426
+ }
427
+ });
428
+ stream.on('end', () => {
429
+ // Process any remaining data in buffer
430
+ if (buffer.trim()) {
431
+ try {
432
+ const document = JSON.parse(buffer);
433
+ handler.onData(document);
434
+ }
435
+ catch (err) {
436
+ if (handler.onError) {
437
+ handler.onError(err);
438
+ }
439
+ }
440
+ }
441
+ if (handler.onEnd) {
442
+ handler.onEnd();
443
+ }
444
+ resolve();
445
+ });
446
+ stream.on('error', (err) => {
447
+ if (handler.onError) {
448
+ handler.onError(err);
449
+ }
450
+ reject(err);
451
+ });
452
+ });
453
+ }
454
+ catch (err) {
455
+ if (handler.onError) {
456
+ handler.onError(err);
457
+ }
458
+ throw err;
459
+ }
460
+ }
461
+ }
462
+
463
+ class Functions extends PlatformBaseClient {
464
+ async list() {
465
+ return await this.client.get("/v1/system/function");
466
+ }
467
+ async get(ref) {
468
+ return await this.client.get(`/v1/system/function/${ref}`);
469
+ }
470
+ async update(uuid, update) {
471
+ return await this.client.patch(`/v1/system/function/${uuid}`, update);
472
+ }
473
+ /**
474
+ * Run platform function
475
+ *
476
+ * @param id - Function ID
477
+ * @param input - Input data
478
+ * @param query - Query parameters
479
+ * @returns - Function result
480
+ *
481
+ * @example
482
+ * const result = await platform.function().run("myFunction", {input: { foo: "bar" }})
483
+ */
484
+ async run(id, d) {
485
+ const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
486
+ params: d.query,
487
+ headers: d.headers
488
+ });
489
+ return data;
490
+ }
491
+ async generateSignature(ref, env) {
492
+ return await this.client.get(`/v1/system/function/signature/${env}/${ref}`);
493
+ }
494
+ }
495
+
496
+ class APIUser extends PlatformBaseClient {
497
+ async auth(username, password, project) {
498
+ return this.client.post("/v1/user/api/auth", {
499
+ username,
500
+ password
501
+ }, {
502
+ headers: {
503
+ "X-Project-Uuid": project
504
+ }
505
+ });
506
+ }
507
+ async newSecret(uuid) {
508
+ return await this.client.post(`/v1/user/api-user/secret/${uuid}`, {});
509
+ }
510
+ async revokeSecret(uuid) {
511
+ return await this.client.delete(`/v1/user/api-user/secret/${uuid}`);
512
+ }
513
+ async edit(uuid, roles) {
514
+ return await this.client.patch(`/v1/user/api-user/${uuid}`, { roles });
515
+ }
516
+ async list() {
517
+ return await this.client.get(`/v1/user/api-user`);
518
+ }
519
+ async get(uuid) {
520
+ return await this.client.get(`/v1/user/api-user/${uuid}`);
521
+ }
522
+ }
523
+
524
+ class Users extends PlatformBaseClient {
525
+ async auth(username, password, project) {
526
+ return await this.client.post("/v1/user/login", {
527
+ username,
528
+ password,
529
+ response_type: 'token',
530
+ }, {
531
+ headers: {
532
+ 'X-Project-Uuid': project
533
+ }
534
+ });
535
+ }
536
+ /**
537
+ * Resend confirmation email
538
+ * @param email User email
539
+ */
540
+ async resendConfirmationEmail(email) {
541
+ return await this.client.post("/v1/user/send/confirmation/email", {
542
+ email,
543
+ });
544
+ }
545
+ // Password Reset (Request Only)
546
+ // Note: Only the REQUEST is exposed, not the password reset completion
547
+ // The actual password reset should be done through the official web interface
548
+ /**
549
+ * Request password reset email
550
+ * This only sends an email with a reset link, does not expose or change passwords
551
+ * @param email User email
552
+ */
553
+ async requestPasswordReset(email) {
554
+ return await this.client.post("/v1/user/resetpassword", { email });
555
+ }
556
+ // User Profile & Management
557
+ /**
558
+ * Get current user's model
559
+ */
560
+ async getUser() {
561
+ return await this.client.get("/v1/user/model");
562
+ }
563
+ /**
564
+ * Get current user's claims
565
+ */
566
+ async getClaims() {
567
+ return await this.client.get("/v1/user/claims");
568
+ }
569
+ /**
570
+ * Edit user profile
571
+ * @param data Profile update data
572
+ */
573
+ async editProfile(data) {
574
+ return await this.client.post("/v1/user/profile/edit", data);
575
+ }
576
+ // Permissions & Roles
577
+ /**
578
+ * Get user permissions
579
+ */
580
+ async getPermissions() {
581
+ return await this.client.get("/v1/user/role/permissions");
582
+ }
583
+ /**
584
+ * Get list of available permissions
585
+ */
586
+ async listPermissions() {
587
+ return await this.client.get("/v1/user/permissions/list");
588
+ }
589
+ /**
590
+ * Create a new role
591
+ * @param role Role data including name, permissions, workspaces, and level
592
+ */
593
+ async createRole(role) {
594
+ return await this.client.post("/v1/user/role/create", role);
595
+ }
596
+ /**
597
+ * Delete a role
598
+ * @param uuid Role UUID
599
+ */
600
+ async deleteRole(uuid) {
601
+ return await this.client.delete(`/v1/user/role/delete/${uuid}`);
602
+ }
603
+ /**
604
+ * List all roles
605
+ */
606
+ async listRoles() {
607
+ return await this.client.get(`/v1/user/role/list`);
608
+ }
609
+ /**
610
+ * Get role details by UUID
611
+ * @param uuid Role UUID
612
+ */
613
+ async getRoleModel(uuid) {
614
+ return await this.client.get(`/v1/user/role/edit/${uuid}`);
615
+ }
616
+ /**
617
+ * Edit a role
618
+ * @param uuid Role UUID
619
+ * @param data Role update data including permissions, workspaces, and level
620
+ */
621
+ async editRole(uuid, data) {
622
+ return await this.client.post(`/v1/user/role/edit/${uuid}`, data);
623
+ }
624
+ /**
625
+ * @deprecated Use getPermissions() instead
626
+ */
627
+ async permissions() {
628
+ return await this.client.get(`/v1/user/role/permissions`);
629
+ }
630
+ }
631
+
632
+ class Apps extends PlatformBaseClient {
633
+ constructor(appType) {
634
+ super();
635
+ this.appType = appType;
636
+ }
637
+ async updateSettings(updateValues, ref) {
638
+ const payload = { ...updateValues };
639
+ return await this.client.put(`/v3/system/gateway/app-service/${this.appType}/${ref}/settings`, payload);
640
+ }
641
+ async download(ref, version) {
642
+ return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
643
+ }
644
+ async upload(formData) {
645
+ return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
646
+ timeout: 60000
647
+ });
479
648
  }
480
649
  }
481
650
 
@@ -486,6 +655,17 @@ var ProtokolSDK010 = (function (exports, axios) {
486
655
  async create(data) {
487
656
  return await this.client.post("/v3/system/component/create", data);
488
657
  }
658
+ /**
659
+ * Setup a component with settings in a single atomic operation.
660
+ * This is more comprehensive than create as it handles component creation
661
+ * and settings initialization together.
662
+ *
663
+ * @param data - Component setup data including name, settings, versions, etc.
664
+ * @returns Promise resolving to the created/updated component
665
+ */
666
+ async setup(data) {
667
+ return await this.client.post("/v3/system/component/setup", data);
668
+ }
489
669
  }
490
670
 
491
671
  class Thunder extends PlatformBaseClient {
@@ -1010,8 +1190,8 @@ var ProtokolSDK010 = (function (exports, axios) {
1010
1190
  forge() {
1011
1191
  return (new Forge()).setClient(this.client);
1012
1192
  }
1013
- component(ref) {
1014
- return (new Component(ref)).setClient(this.client);
1193
+ component(ref, options) {
1194
+ return (new Component(ref, options)).setClient(this.client);
1015
1195
  }
1016
1196
  componentUtils() {
1017
1197
  return (new ComponentUtils()).setClient(this.client);
@@ -1066,8 +1246,8 @@ var ProtokolSDK010 = (function (exports, axios) {
1066
1246
 
1067
1247
  class IntegrationsBaseClient extends BaseClient {
1068
1248
  constructor(options) {
1069
- var _a, _b, _c;
1070
- let { env = null, token, host, } = options !== null && options !== void 0 ? options : {};
1249
+ var _a, _b, _c, _d, _e, _f, _g;
1250
+ let { env = null, token = null, host = null, } = options !== null && options !== void 0 ? options : {};
1071
1251
  let headers = {};
1072
1252
  var project_uuid = null;
1073
1253
  if (isBrowser) {
@@ -1077,16 +1257,22 @@ var ProtokolSDK010 = (function (exports, axios) {
1077
1257
  else {
1078
1258
  headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
1079
1259
  }
1260
+ if (typeof window !== "undefined") {
1261
+ // @ts-ignore
1262
+ const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
1263
+ host = (_c = __global_env__.INTEGRATION_API) !== null && _c !== void 0 ? _c : host;
1264
+ // @ts-ignore
1265
+ token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
1266
+ // @ts-ignore
1267
+ env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
1268
+ project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
1269
+ }
1080
1270
  }
1081
- if (typeof window !== "undefined") {
1082
- // @ts-ignore
1083
- const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
1084
- host = (_c = __global_env__.INTEGRATION_API) !== null && _c !== void 0 ? _c : host;
1085
- // @ts-ignore
1086
- token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
1087
- // @ts-ignore
1088
- env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
1089
- project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
1271
+ else if (process && process.env) {
1272
+ host = (_d = host !== null && host !== void 0 ? host : process.env.API_HOST) !== null && _d !== void 0 ? _d : null;
1273
+ env = (_e = env !== null && env !== void 0 ? env : process.env.PROJECT_ENV) !== null && _e !== void 0 ? _e : null;
1274
+ token = (_f = token !== null && token !== void 0 ? token : process.env.PROJECT_API_TOKEN) !== null && _f !== void 0 ? _f : null;
1275
+ project_uuid = (_g = process.env.PROJECT_UUID) !== null && _g !== void 0 ? _g : null;
1090
1276
  }
1091
1277
  if (token) {
1092
1278
  headers['Authorization'] = `Bearer ${token}`;
@@ -1106,6 +1292,9 @@ var ProtokolSDK010 = (function (exports, axios) {
1106
1292
  withCredentials: true,
1107
1293
  });
1108
1294
  super(client);
1295
+ this.env = null;
1296
+ this.token = null;
1297
+ this.host = null;
1109
1298
  }
1110
1299
  }
1111
1300
 
@@ -2750,18 +2939,16 @@ var ProtokolSDK010 = (function (exports, axios) {
2750
2939
  exports.Integrations = Integrations;
2751
2940
  exports.Invoicing = Invoicing;
2752
2941
  exports.Payments = Payments;
2942
+ exports.Platform = Platform;
2753
2943
  exports.Project = Project;
2754
2944
  exports.Ratchet = Ratchet;
2755
2945
  exports.Sandbox = Sandbox;
2756
2946
  exports.SerbiaUtil = SerbiaUtil;
2757
2947
  exports.System = System;
2758
2948
  exports.Thunder = Thunder;
2759
- exports.User = Users;
2949
+ exports.Users = Users;
2760
2950
  exports.VPFR = VPFR;
2761
2951
  exports.Workflow = Workflow;
2762
- exports.default = Platform;
2763
-
2764
- Object.defineProperty(exports, '__esModule', { value: true });
2765
2952
 
2766
2953
  return exports;
2767
2954