@ptkl/sdk 0.10.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/{index.iife.js → index.0.10.js} +393 -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 +128 -0
  5. package/dist/v0.10/api/index.d.ts +22 -0
  6. package/dist/{types → v0.10}/api/integrationsBaseClient.d.ts +3 -0
  7. package/dist/{types → v0.10}/api/platform.d.ts +2 -2
  8. package/dist/v0.10/apiUser.d.ts +9 -0
  9. package/dist/v0.10/apps.d.ts +8 -0
  10. package/dist/v0.10/baseClient.d.ts +6 -0
  11. package/dist/{types/api → v0.10}/component.d.ts +39 -4
  12. package/dist/v0.10/componentUtils.d.ts +7 -0
  13. package/dist/v0.10/config.d.ts +14 -0
  14. package/dist/v0.10/forge.d.ts +7 -0
  15. package/dist/v0.10/functions.d.ts +23 -0
  16. package/dist/{index.cjs.js → v0.10/index.cjs.js} +393 -230
  17. package/dist/v0.10/index.d.ts +21 -0
  18. package/dist/{index.esm.js → v0.10/index.esm.js} +392 -227
  19. package/dist/v0.10/integrations/dms.d.ts +469 -0
  20. package/dist/v0.10/integrations/invoicing.d.ts +6 -0
  21. package/dist/v0.10/integrations/minimax.d.ts +289 -0
  22. package/dist/v0.10/integrations/payments.d.ts +40 -0
  23. package/dist/v0.10/integrations/serbiaUtil.d.ts +10 -0
  24. package/dist/v0.10/integrations/vpfr.d.ts +4 -0
  25. package/dist/v0.10/integrations.d.ts +22 -0
  26. package/dist/v0.10/integrationsBaseClient.d.ts +11 -0
  27. package/dist/v0.10/platform.d.ts +34 -0
  28. package/dist/v0.10/platformBaseClient.d.ts +27 -0
  29. package/dist/v0.10/project.d.ts +146 -0
  30. package/dist/v0.10/ratchet.d.ts +196 -0
  31. package/dist/v0.10/sandbox.d.ts +14 -0
  32. package/dist/v0.10/system.d.ts +4 -0
  33. package/dist/v0.10/thunder.d.ts +13 -0
  34. package/dist/{types → v0.10}/types/component.d.ts +27 -1
  35. package/dist/v0.10/users.d.ts +69 -0
  36. package/dist/v0.10/workflow.d.ts +5 -0
  37. package/dist/v0.9/api/apiUser.d.ts +9 -0
  38. package/dist/v0.9/api/apps.d.ts +8 -0
  39. package/dist/v0.9/api/baseClient.d.ts +6 -0
  40. package/dist/v0.9/api/component.d.ts +136 -0
  41. package/dist/v0.9/api/componentUtils.d.ts +7 -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/v0.9/types/component.d.ts +116 -0
  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/componentUtils.d.ts +0 -0
  109. /package/dist/{types → v0.10}/api/config.d.ts +0 -0
  110. /package/dist/{types → v0.10}/api/forge.d.ts +0 -0
  111. /package/dist/{types → v0.10}/api/functions.d.ts +0 -0
  112. /package/dist/{types → v0.10}/api/integrations/dms.d.ts +0 -0
  113. /package/dist/{types → v0.10}/api/integrations/invoicing.d.ts +0 -0
  114. /package/dist/{types → v0.10}/api/integrations/minimax.d.ts +0 -0
  115. /package/dist/{types → v0.10}/api/integrations/payments.d.ts +0 -0
  116. /package/dist/{types → v0.10}/api/integrations/serbiaUtil.d.ts +0 -0
  117. /package/dist/{types → v0.10}/api/integrations/vpfr.d.ts +0 -0
  118. /package/dist/{types → v0.10}/api/integrations.d.ts +0 -0
  119. /package/dist/{types → v0.10}/api/platformBaseClient.d.ts +0 -0
  120. /package/dist/{types → v0.10}/api/project.d.ts +0 -0
  121. /package/dist/{types → v0.10}/api/ratchet.d.ts +0 -0
  122. /package/dist/{types → v0.10}/api/sandbox.d.ts +0 -0
  123. /package/dist/{types → v0.10}/api/system.d.ts +0 -0
  124. /package/dist/{types → v0.10}/api/thunder.d.ts +0 -0
  125. /package/dist/{types → v0.10}/api/users.d.ts +0 -0
  126. /package/dist/{types → v0.10}/api/workflow.d.ts +0 -0
  127. /package/dist/{types → v0.10}/types/config.d.ts +0 -0
  128. /package/dist/{types → v0.10}/types/integrations.d.ts +0 -0
  129. /package/dist/{types → v0.10}/types/project.d.ts +0 -0
  130. /package/dist/{types → v0.10}/types/ratchet.d.ts +0 -0
  131. /package/dist/{types → v0.10}/types/users.d.ts +0 -0
  132. /package/dist/{types → v0.10}/util/detectEnv.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,9 @@ 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
410
239
  });
411
240
  }
412
241
  /**
@@ -417,7 +246,7 @@ class Component extends PlatformBaseClient {
417
246
  * @returns
418
247
  */
419
248
  async modify(filters, data, options) {
420
- return await this.client.patch(`/v3/system/component/${this.ref}/modify/model`, {
249
+ return await this.client.patch(`${this.getComponentPath()}/modify/model`, {
421
250
  filters,
422
251
  data,
423
252
  options,
@@ -432,20 +261,84 @@ class Component extends PlatformBaseClient {
432
261
  * @returns
433
262
  */
434
263
  async concurrentUpdate(uuid, version, data, options) {
435
- return await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
264
+ return await this.client.post(`${this.getComponentPath()}/model/${uuid}`, {
436
265
  version: version,
437
266
  data,
438
267
  options,
439
268
  });
440
269
  }
441
270
  async create(model) {
442
- return await this.client.post(`/v3/system/component/${this.ref}/model`, model);
271
+ return await this.client.post(`${this.getComponentPath()}/model`, model);
443
272
  }
444
273
  async delete(uuid) {
445
- return await this.client.delete(`/v3/system/component/${this.ref}/model/${uuid}`);
274
+ return await this.client.delete(`${this.getComponentPath()}/model/${uuid}`);
446
275
  }
447
- async aggregate(pipeline) {
448
- return await this.client.post(`/v3/system/component/${this.ref}/aggregate`, pipeline);
276
+ /**
277
+ * Execute aggregate pipeline with optional streaming support
278
+ *
279
+ * Returns a chainable object that allows both buffered and streaming modes.
280
+ * Call .onData() to enable streaming mode, or await directly for buffered mode.
281
+ *
282
+ * @param {FindAggregateParams} pipeline - MongoDB aggregation pipeline
283
+ *
284
+ * @returns {AggregateChainable} Chainable object with streaming methods and Promise interface
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * // Buffered response (default, up to 5K documents)
289
+ * const result = await component.aggregate([{ $match: { status: 'active' } }]);
290
+ * console.log(result.data); // All results at once
291
+ *
292
+ * // Streaming response (up to 25K documents)
293
+ * await component.aggregate([{ $match: { status: 'active' } }])
294
+ * .onData((doc) => console.log('Received:', doc))
295
+ * .onError((err) => console.error('Error:', err))
296
+ * .onEnd(() => console.log('Stream complete'));
297
+ * ```
298
+ */
299
+ aggregate(pipeline) {
300
+ let onDataCallback = () => { };
301
+ let onErrorCallback;
302
+ let onEndCallback;
303
+ let isStreaming = false;
304
+ let streamPromise = null;
305
+ const chainable = {
306
+ onData: (callback) => {
307
+ onDataCallback = callback;
308
+ isStreaming = true;
309
+ return chainable;
310
+ },
311
+ onError: (callback) => {
312
+ onErrorCallback = callback;
313
+ return chainable;
314
+ },
315
+ onEnd: (callback) => {
316
+ onEndCallback = callback;
317
+ return chainable;
318
+ },
319
+ then: (resolve, reject) => {
320
+ if (isStreaming) {
321
+ if (!streamPromise) {
322
+ const handler = {
323
+ onData: onDataCallback,
324
+ onError: onErrorCallback,
325
+ onEnd: onEndCallback
326
+ };
327
+ streamPromise = this._streamNDJSON(`${this.getComponentPath()}/aggregate`, {
328
+ 'Accept': 'application/x-ndjson',
329
+ 'Content-Type': 'application/json'
330
+ }, handler, pipeline);
331
+ }
332
+ return streamPromise.then(resolve, reject);
333
+ }
334
+ return this.client.post(`${this.getComponentPath()}/aggregate`, pipeline)
335
+ .then(resolve, reject);
336
+ },
337
+ catch: (reject) => {
338
+ return chainable.then(undefined, reject);
339
+ }
340
+ };
341
+ return chainable;
449
342
  }
450
343
  async settings() {
451
344
  return await this.client.get(`/v3/system/component/settings/${this.ref}`);
@@ -463,18 +356,281 @@ class Component extends PlatformBaseClient {
463
356
  });
464
357
  }
465
358
  async workflow(event, input) {
466
- return await this.client.post(`/v3/system/component/${this.ref}/workflow/event`, {
359
+ return await this.client.post(`${this.getComponentPath()}/workflow/event`, {
467
360
  event,
468
361
  input
469
362
  });
470
363
  }
471
364
  async function(name, input) {
472
- return await this.client.post(`/v3/system/component/${this.ref}/function/${name}`, {
365
+ return await this.client.post(`${this.getComponentPath()}/function/${name}`, {
473
366
  data: input
474
367
  });
475
368
  }
476
369
  async revisions(uuid) {
477
- return await this.client.get(`/v3/system/component/${this.ref}/model/${uuid}/revisions`);
370
+ return await this.client.get(`${this.getComponentPath()}/model/${uuid}/revisions`);
371
+ }
372
+ /**
373
+ * Internal method to handle NDJSON streaming responses
374
+ *
375
+ * @private
376
+ */
377
+ async _streamNDJSON(url, headers, handler, body) {
378
+ try {
379
+ const config = {
380
+ headers,
381
+ responseType: 'stream'
382
+ };
383
+ const response = await this.client.post(url, body, config);
384
+ const stream = response.data;
385
+ let buffer = '';
386
+ return new Promise((resolve, reject) => {
387
+ stream.on('data', (chunk) => {
388
+ buffer += chunk.toString();
389
+ // Process complete lines (separated by newlines)
390
+ const lines = buffer.split('\n');
391
+ buffer = lines.pop() || ''; // Keep incomplete line in buffer
392
+ for (const line of lines) {
393
+ if (line.trim()) {
394
+ try {
395
+ const document = JSON.parse(line);
396
+ const result = handler.onData(document);
397
+ // Support async callbacks
398
+ if (result instanceof Promise) {
399
+ result.catch((err) => {
400
+ if (handler.onError) {
401
+ handler.onError(err);
402
+ }
403
+ });
404
+ }
405
+ }
406
+ catch (err) {
407
+ if (handler.onError) {
408
+ handler.onError(err);
409
+ }
410
+ }
411
+ }
412
+ }
413
+ });
414
+ stream.on('end', () => {
415
+ // Process any remaining data in buffer
416
+ if (buffer.trim()) {
417
+ try {
418
+ const document = JSON.parse(buffer);
419
+ handler.onData(document);
420
+ }
421
+ catch (err) {
422
+ if (handler.onError) {
423
+ handler.onError(err);
424
+ }
425
+ }
426
+ }
427
+ if (handler.onEnd) {
428
+ handler.onEnd();
429
+ }
430
+ resolve();
431
+ });
432
+ stream.on('error', (err) => {
433
+ if (handler.onError) {
434
+ handler.onError(err);
435
+ }
436
+ reject(err);
437
+ });
438
+ });
439
+ }
440
+ catch (err) {
441
+ if (handler.onError) {
442
+ handler.onError(err);
443
+ }
444
+ throw err;
445
+ }
446
+ }
447
+ }
448
+
449
+ class Functions extends PlatformBaseClient {
450
+ async list() {
451
+ return await this.client.get("/v1/system/function");
452
+ }
453
+ async get(ref) {
454
+ return await this.client.get(`/v1/system/function/${ref}`);
455
+ }
456
+ async update(uuid, update) {
457
+ return await this.client.patch(`/v1/system/function/${uuid}`, update);
458
+ }
459
+ /**
460
+ * Run platform function
461
+ *
462
+ * @param id - Function ID
463
+ * @param input - Input data
464
+ * @param query - Query parameters
465
+ * @returns - Function result
466
+ *
467
+ * @example
468
+ * const result = await platform.function().run("myFunction", {input: { foo: "bar" }})
469
+ */
470
+ async run(id, d) {
471
+ const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
472
+ params: d.query,
473
+ headers: d.headers
474
+ });
475
+ return data;
476
+ }
477
+ async generateSignature(ref, env) {
478
+ return await this.client.get(`/v1/system/function/signature/${env}/${ref}`);
479
+ }
480
+ }
481
+
482
+ class APIUser extends PlatformBaseClient {
483
+ async auth(username, password, project) {
484
+ return this.client.post("/v1/user/api/auth", {
485
+ username,
486
+ password
487
+ }, {
488
+ headers: {
489
+ "X-Project-Uuid": project
490
+ }
491
+ });
492
+ }
493
+ async newSecret(uuid) {
494
+ return await this.client.post(`/v1/user/api-user/secret/${uuid}`, {});
495
+ }
496
+ async revokeSecret(uuid) {
497
+ return await this.client.delete(`/v1/user/api-user/secret/${uuid}`);
498
+ }
499
+ async edit(uuid, roles) {
500
+ return await this.client.patch(`/v1/user/api-user/${uuid}`, { roles });
501
+ }
502
+ async list() {
503
+ return await this.client.get(`/v1/user/api-user`);
504
+ }
505
+ async get(uuid) {
506
+ return await this.client.get(`/v1/user/api-user/${uuid}`);
507
+ }
508
+ }
509
+
510
+ class Users extends PlatformBaseClient {
511
+ async auth(username, password, project) {
512
+ return await this.client.post("/v1/user/login", {
513
+ username,
514
+ password,
515
+ response_type: 'token',
516
+ }, {
517
+ headers: {
518
+ 'X-Project-Uuid': project
519
+ }
520
+ });
521
+ }
522
+ /**
523
+ * Resend confirmation email
524
+ * @param email User email
525
+ */
526
+ async resendConfirmationEmail(email) {
527
+ return await this.client.post("/v1/user/send/confirmation/email", {
528
+ email,
529
+ });
530
+ }
531
+ // Password Reset (Request Only)
532
+ // Note: Only the REQUEST is exposed, not the password reset completion
533
+ // The actual password reset should be done through the official web interface
534
+ /**
535
+ * Request password reset email
536
+ * This only sends an email with a reset link, does not expose or change passwords
537
+ * @param email User email
538
+ */
539
+ async requestPasswordReset(email) {
540
+ return await this.client.post("/v1/user/resetpassword", { email });
541
+ }
542
+ // User Profile & Management
543
+ /**
544
+ * Get current user's model
545
+ */
546
+ async getUser() {
547
+ return await this.client.get("/v1/user/model");
548
+ }
549
+ /**
550
+ * Get current user's claims
551
+ */
552
+ async getClaims() {
553
+ return await this.client.get("/v1/user/claims");
554
+ }
555
+ /**
556
+ * Edit user profile
557
+ * @param data Profile update data
558
+ */
559
+ async editProfile(data) {
560
+ return await this.client.post("/v1/user/profile/edit", data);
561
+ }
562
+ // Permissions & Roles
563
+ /**
564
+ * Get user permissions
565
+ */
566
+ async getPermissions() {
567
+ return await this.client.get("/v1/user/role/permissions");
568
+ }
569
+ /**
570
+ * Get list of available permissions
571
+ */
572
+ async listPermissions() {
573
+ return await this.client.get("/v1/user/permissions/list");
574
+ }
575
+ /**
576
+ * Create a new role
577
+ * @param role Role data including name, permissions, workspaces, and level
578
+ */
579
+ async createRole(role) {
580
+ return await this.client.post("/v1/user/role/create", role);
581
+ }
582
+ /**
583
+ * Delete a role
584
+ * @param uuid Role UUID
585
+ */
586
+ async deleteRole(uuid) {
587
+ return await this.client.delete(`/v1/user/role/delete/${uuid}`);
588
+ }
589
+ /**
590
+ * List all roles
591
+ */
592
+ async listRoles() {
593
+ return await this.client.get(`/v1/user/role/list`);
594
+ }
595
+ /**
596
+ * Get role details by UUID
597
+ * @param uuid Role UUID
598
+ */
599
+ async getRoleModel(uuid) {
600
+ return await this.client.get(`/v1/user/role/edit/${uuid}`);
601
+ }
602
+ /**
603
+ * Edit a role
604
+ * @param uuid Role UUID
605
+ * @param data Role update data including permissions, workspaces, and level
606
+ */
607
+ async editRole(uuid, data) {
608
+ return await this.client.post(`/v1/user/role/edit/${uuid}`, data);
609
+ }
610
+ /**
611
+ * @deprecated Use getPermissions() instead
612
+ */
613
+ async permissions() {
614
+ return await this.client.get(`/v1/user/role/permissions`);
615
+ }
616
+ }
617
+
618
+ class Apps extends PlatformBaseClient {
619
+ constructor(appType) {
620
+ super();
621
+ this.appType = appType;
622
+ }
623
+ async updateSettings(updateValues, ref) {
624
+ const payload = { ...updateValues };
625
+ return await this.client.put(`/v3/system/gateway/app-service/${this.appType}/${ref}/settings`, payload);
626
+ }
627
+ async download(ref, version) {
628
+ return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
629
+ }
630
+ async upload(formData) {
631
+ return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
632
+ timeout: 60000
633
+ });
478
634
  }
479
635
  }
480
636
 
@@ -1009,8 +1165,8 @@ class Platform extends PlatformBaseClient {
1009
1165
  forge() {
1010
1166
  return (new Forge()).setClient(this.client);
1011
1167
  }
1012
- component(ref) {
1013
- return (new Component(ref)).setClient(this.client);
1168
+ component(ref, options) {
1169
+ return (new Component(ref, options)).setClient(this.client);
1014
1170
  }
1015
1171
  componentUtils() {
1016
1172
  return (new ComponentUtils()).setClient(this.client);
@@ -1065,8 +1221,8 @@ class Invoicing extends PlatformBaseClient {
1065
1221
 
1066
1222
  class IntegrationsBaseClient extends BaseClient {
1067
1223
  constructor(options) {
1068
- var _a, _b, _c;
1069
- let { env = null, token, host, } = options !== null && options !== void 0 ? options : {};
1224
+ var _a, _b, _c, _d, _e, _f, _g;
1225
+ let { env = null, token = null, host = null, } = options !== null && options !== void 0 ? options : {};
1070
1226
  let headers = {};
1071
1227
  var project_uuid = null;
1072
1228
  if (isBrowser) {
@@ -1076,16 +1232,22 @@ class IntegrationsBaseClient extends BaseClient {
1076
1232
  else {
1077
1233
  headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
1078
1234
  }
1235
+ if (typeof window !== "undefined") {
1236
+ // @ts-ignore
1237
+ const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
1238
+ host = (_c = __global_env__.INTEGRATION_API) !== null && _c !== void 0 ? _c : host;
1239
+ // @ts-ignore
1240
+ token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
1241
+ // @ts-ignore
1242
+ env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
1243
+ project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
1244
+ }
1079
1245
  }
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;
1246
+ else if (process && process.env) {
1247
+ host = (_d = host !== null && host !== void 0 ? host : process.env.API_HOST) !== null && _d !== void 0 ? _d : null;
1248
+ env = (_e = env !== null && env !== void 0 ? env : process.env.PROJECT_ENV) !== null && _e !== void 0 ? _e : null;
1249
+ token = (_f = token !== null && token !== void 0 ? token : process.env.PROJECT_API_TOKEN) !== null && _f !== void 0 ? _f : null;
1250
+ project_uuid = (_g = process.env.PROJECT_UUID) !== null && _g !== void 0 ? _g : null;
1089
1251
  }
1090
1252
  if (token) {
1091
1253
  headers['Authorization'] = `Bearer ${token}`;
@@ -1105,6 +1267,9 @@ class IntegrationsBaseClient extends BaseClient {
1105
1267
  withCredentials: true,
1106
1268
  });
1107
1269
  super(client);
1270
+ this.env = null;
1271
+ this.token = null;
1272
+ this.host = null;
1108
1273
  }
1109
1274
  }
1110
1275
 
@@ -2737,4 +2902,4 @@ class Integrations extends IntegrationsBaseClient {
2737
2902
  }
2738
2903
  }
2739
2904
 
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 };
2905
+ 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 };