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