@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
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var require$$1 = require('util');
6
4
  var stream = require('stream');
7
5
  var require$$1$1 = require('path');
@@ -19003,27 +19001,32 @@ const isBrowser = typeof window !== "undefined" &&
19003
19001
  */
19004
19002
  class PlatformBaseClient extends BaseClient {
19005
19003
  constructor(options) {
19006
- var _a, _b, _c;
19004
+ var _a, _b, _c, _d, _e, _f, _g;
19007
19005
  let { env = null, token = null, host = null, } = options !== null && options !== void 0 ? options : {};
19008
19006
  let headers = {};
19009
19007
  var project_uuid = null;
19010
19008
  if (isBrowser) {
19011
- console.log("PlatformBaseClient: running in browser context");
19012
19009
  if (sessionStorage.getItem('protokol_context') == "forge") {
19013
19010
  headers['X-Project-Env'] = (_a = sessionStorage.getItem('forge_app_env')) !== null && _a !== void 0 ? _a : "dev";
19014
19011
  }
19015
19012
  else {
19016
19013
  headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
19017
19014
  }
19015
+ if (typeof window !== "undefined") {
19016
+ // @ts-ignore
19017
+ const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
19018
+ host = (_c = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.API_HOST) !== null && _c !== void 0 ? _c : host;
19019
+ // @ts-ignore
19020
+ env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
19021
+ token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
19022
+ project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
19023
+ }
19018
19024
  }
19019
- if (typeof window !== "undefined") {
19020
- // @ts-ignore
19021
- const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
19022
- host = (_c = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.API_HOST) !== null && _c !== void 0 ? _c : host;
19023
- // @ts-ignore
19024
- env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
19025
- token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
19026
- project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
19025
+ else if (process && process.env) {
19026
+ host = (_d = host !== null && host !== void 0 ? host : process.env.API_HOST) !== null && _d !== void 0 ? _d : null;
19027
+ env = (_e = env !== null && env !== void 0 ? env : process.env.PROJECT_ENV) !== null && _e !== void 0 ? _e : null;
19028
+ token = (_f = token !== null && token !== void 0 ? token : process.env.PROJECT_API_TOKEN) !== null && _f !== void 0 ? _f : null;
19029
+ project_uuid = (_g = process.env.PROJECT_UUID) !== null && _g !== void 0 ? _g : null;
19027
19030
  }
19028
19031
  if (token) {
19029
19032
  headers['Authorization'] = `Bearer ${token}`;
@@ -19050,198 +19053,22 @@ class PlatformBaseClient extends BaseClient {
19050
19053
  }
19051
19054
  }
19052
19055
 
19053
- class Functions extends PlatformBaseClient {
19054
- async list() {
19055
- return await this.client.get("/v1/system/function");
19056
- }
19057
- async get(ref) {
19058
- return await this.client.get(`/v1/system/function/${ref}`);
19059
- }
19060
- async update(uuid, update) {
19061
- return await this.client.patch(`/v1/system/function/${uuid}`, update);
19062
- }
19063
- /**
19064
- * Run platform function
19065
- *
19066
- * @param id - Function ID
19067
- * @param input - Input data
19068
- * @param query - Query parameters
19069
- * @returns - Function result
19070
- *
19071
- * @example
19072
- * const result = await platform.function().run("myFunction", {input: { foo: "bar" }})
19073
- */
19074
- async run(id, d) {
19075
- const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
19076
- params: d.query,
19077
- headers: d.headers
19078
- });
19079
- return data;
19080
- }
19081
- async generateSignature(ref, env) {
19082
- return await this.client.get(`/v1/system/function/signature/${env}/${ref}`);
19083
- }
19084
- }
19085
-
19086
- class APIUser extends PlatformBaseClient {
19087
- async auth(username, password, project) {
19088
- return this.client.post("/v1/user/api/auth", {
19089
- username,
19090
- password
19091
- }, {
19092
- headers: {
19093
- "X-Project-Uuid": project
19094
- }
19095
- });
19096
- }
19097
- async newSecret(uuid) {
19098
- return await this.client.post(`/v1/user/api-user/secret/${uuid}`, {});
19099
- }
19100
- async revokeSecret(uuid) {
19101
- return await this.client.delete(`/v1/user/api-user/secret/${uuid}`);
19102
- }
19103
- async edit(uuid, roles) {
19104
- return await this.client.patch(`/v1/user/api-user/${uuid}`, { roles });
19105
- }
19106
- async list() {
19107
- return await this.client.get(`/v1/user/api-user`);
19108
- }
19109
- async get(uuid) {
19110
- return await this.client.get(`/v1/user/api-user/${uuid}`);
19111
- }
19112
- }
19113
-
19114
- class Users extends PlatformBaseClient {
19115
- async auth(username, password, project) {
19116
- return await this.client.post("/v1/user/login", {
19117
- username,
19118
- password,
19119
- response_type: 'token',
19120
- }, {
19121
- headers: {
19122
- 'X-Project-Uuid': project
19123
- }
19124
- });
19125
- }
19126
- /**
19127
- * Resend confirmation email
19128
- * @param email User email
19129
- */
19130
- async resendConfirmationEmail(email) {
19131
- return await this.client.post("/v1/user/send/confirmation/email", {
19132
- email,
19133
- });
19134
- }
19135
- // Password Reset (Request Only)
19136
- // Note: Only the REQUEST is exposed, not the password reset completion
19137
- // The actual password reset should be done through the official web interface
19138
- /**
19139
- * Request password reset email
19140
- * This only sends an email with a reset link, does not expose or change passwords
19141
- * @param email User email
19142
- */
19143
- async requestPasswordReset(email) {
19144
- return await this.client.post("/v1/user/resetpassword", { email });
19145
- }
19146
- // User Profile & Management
19147
- /**
19148
- * Get current user's model
19149
- */
19150
- async getUser() {
19151
- return await this.client.get("/v1/user/model");
19152
- }
19153
- /**
19154
- * Get current user's claims
19155
- */
19156
- async getClaims() {
19157
- return await this.client.get("/v1/user/claims");
19158
- }
19159
- /**
19160
- * Edit user profile
19161
- * @param data Profile update data
19162
- */
19163
- async editProfile(data) {
19164
- return await this.client.post("/v1/user/profile/edit", data);
19165
- }
19166
- // Permissions & Roles
19167
- /**
19168
- * Get user permissions
19169
- */
19170
- async getPermissions() {
19171
- return await this.client.get("/v1/user/role/permissions");
19172
- }
19173
- /**
19174
- * Get list of available permissions
19175
- */
19176
- async listPermissions() {
19177
- return await this.client.get("/v1/user/permissions/list");
19178
- }
19179
- /**
19180
- * Create a new role
19181
- * @param role Role data including name, permissions, workspaces, and level
19182
- */
19183
- async createRole(role) {
19184
- return await this.client.post("/v1/user/role/create", role);
19185
- }
19186
- /**
19187
- * Delete a role
19188
- * @param uuid Role UUID
19189
- */
19190
- async deleteRole(uuid) {
19191
- return await this.client.delete(`/v1/user/role/delete/${uuid}`);
19192
- }
19193
- /**
19194
- * List all roles
19195
- */
19196
- async listRoles() {
19197
- return await this.client.get(`/v1/user/role/list`);
19198
- }
19199
- /**
19200
- * Get role details by UUID
19201
- * @param uuid Role UUID
19202
- */
19203
- async getRoleModel(uuid) {
19204
- return await this.client.get(`/v1/user/role/edit/${uuid}`);
19205
- }
19206
- /**
19207
- * Edit a role
19208
- * @param uuid Role UUID
19209
- * @param data Role update data including permissions, workspaces, and level
19210
- */
19211
- async editRole(uuid, data) {
19212
- return await this.client.post(`/v1/user/role/edit/${uuid}`, data);
19213
- }
19214
- /**
19215
- * @deprecated Use getPermissions() instead
19216
- */
19217
- async permissions() {
19218
- return await this.client.get(`/v1/user/role/permissions`);
19219
- }
19220
- }
19221
-
19222
- class Apps extends PlatformBaseClient {
19223
- constructor(appType) {
19224
- super();
19225
- this.appType = appType;
19226
- }
19227
- async updateSettings(updateValues, ref) {
19228
- const payload = { ...updateValues };
19229
- return await this.client.put(`/v3/system/gateway/app-service/${this.appType}/${ref}/settings`, payload);
19230
- }
19231
- async download(ref, version) {
19232
- return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
19233
- }
19234
- async upload(formData) {
19235
- return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
19236
- timeout: 60000
19237
- });
19238
- }
19239
- }
19240
-
19241
19056
  class Component extends PlatformBaseClient {
19242
- constructor(ref = null) {
19057
+ constructor(ref = null, options) {
19058
+ var _a;
19243
19059
  super();
19244
19060
  this.ref = ref;
19061
+ this.version = (_a = options === null || options === void 0 ? void 0 : options.version) !== null && _a !== void 0 ? _a : null;
19062
+ }
19063
+ /**
19064
+ * Get the base path for component API calls
19065
+ * @private
19066
+ */
19067
+ getComponentPath() {
19068
+ if (this.version) {
19069
+ return `/v3/system/component/${this.ref}/v/${this.version}`;
19070
+ }
19071
+ return `/v3/system/component/${this.ref}`;
19245
19072
  }
19246
19073
  /**
19247
19074
  * Find method to search for models
@@ -19311,7 +19138,7 @@ class Component extends PlatformBaseClient {
19311
19138
  params[`_opt_${k}`] = opts ? opts[k] : null;
19312
19139
  });
19313
19140
  }
19314
- return await this.client.get(`/v3/system/component/${this.ref}/models`, {
19141
+ return await this.client.get(`${this.getComponentPath()}/models`, {
19315
19142
  params: params,
19316
19143
  headers: {
19317
19144
  'X-Cache': cache,
@@ -19350,7 +19177,7 @@ class Component extends PlatformBaseClient {
19350
19177
  * @returns (Promise<Model>)
19351
19178
  */
19352
19179
  async get(uuid) {
19353
- return await this.client.get(`/v3/system/component/${this.ref}/model/${uuid}`);
19180
+ return await this.client.get(`${this.getComponentPath()}/model/${uuid}`);
19354
19181
  }
19355
19182
  /**
19356
19183
  * Update model by uuid
@@ -19360,7 +19187,7 @@ class Component extends PlatformBaseClient {
19360
19187
  * @returns
19361
19188
  */
19362
19189
  async update(uuid, data, options) {
19363
- return await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
19190
+ return await this.client.post(`${this.getComponentPath()}/model/${uuid}`, {
19364
19191
  data,
19365
19192
  options,
19366
19193
  });
@@ -19373,9 +19200,9 @@ class Component extends PlatformBaseClient {
19373
19200
  * @returns
19374
19201
  */
19375
19202
  async updateMany(data, options) {
19376
- return await this.client.post(`/v3/system/component/${this.ref}/models/bulk`, {
19203
+ return await this.client.patch(`${this.getComponentPath()}/models/bulk`, {
19377
19204
  data,
19378
- options,
19205
+ options
19379
19206
  });
19380
19207
  }
19381
19208
  /**
@@ -19386,7 +19213,7 @@ class Component extends PlatformBaseClient {
19386
19213
  * @returns
19387
19214
  */
19388
19215
  async modify(filters, data, options) {
19389
- return await this.client.patch(`/v3/system/component/${this.ref}/modify/model`, {
19216
+ return await this.client.patch(`${this.getComponentPath()}/modify/model`, {
19390
19217
  filters,
19391
19218
  data,
19392
19219
  options,
@@ -19401,20 +19228,84 @@ class Component extends PlatformBaseClient {
19401
19228
  * @returns
19402
19229
  */
19403
19230
  async concurrentUpdate(uuid, version, data, options) {
19404
- return await this.client.post(`/v3/system/component/${this.ref}/model/${uuid}`, {
19231
+ return await this.client.post(`${this.getComponentPath()}/model/${uuid}`, {
19405
19232
  version: version,
19406
19233
  data,
19407
19234
  options,
19408
19235
  });
19409
19236
  }
19410
19237
  async create(model) {
19411
- return await this.client.post(`/v3/system/component/${this.ref}/model`, model);
19238
+ return await this.client.post(`${this.getComponentPath()}/model`, model);
19412
19239
  }
19413
19240
  async delete(uuid) {
19414
- return await this.client.delete(`/v3/system/component/${this.ref}/model/${uuid}`);
19241
+ return await this.client.delete(`${this.getComponentPath()}/model/${uuid}`);
19415
19242
  }
19416
- async aggregate(pipeline) {
19417
- return await this.client.post(`/v3/system/component/${this.ref}/aggregate`, pipeline);
19243
+ /**
19244
+ * Execute aggregate pipeline with optional streaming support
19245
+ *
19246
+ * Returns a chainable object that allows both buffered and streaming modes.
19247
+ * Call .onData() to enable streaming mode, or await directly for buffered mode.
19248
+ *
19249
+ * @param {FindAggregateParams} pipeline - MongoDB aggregation pipeline
19250
+ *
19251
+ * @returns {AggregateChainable} Chainable object with streaming methods and Promise interface
19252
+ *
19253
+ * @example
19254
+ * ```typescript
19255
+ * // Buffered response (default, up to 5K documents)
19256
+ * const result = await component.aggregate([{ $match: { status: 'active' } }]);
19257
+ * console.log(result.data); // All results at once
19258
+ *
19259
+ * // Streaming response (up to 25K documents)
19260
+ * await component.aggregate([{ $match: { status: 'active' } }])
19261
+ * .onData((doc) => console.log('Received:', doc))
19262
+ * .onError((err) => console.error('Error:', err))
19263
+ * .onEnd(() => console.log('Stream complete'));
19264
+ * ```
19265
+ */
19266
+ aggregate(pipeline) {
19267
+ let onDataCallback = () => { };
19268
+ let onErrorCallback;
19269
+ let onEndCallback;
19270
+ let isStreaming = false;
19271
+ let streamPromise = null;
19272
+ const chainable = {
19273
+ onData: (callback) => {
19274
+ onDataCallback = callback;
19275
+ isStreaming = true;
19276
+ return chainable;
19277
+ },
19278
+ onError: (callback) => {
19279
+ onErrorCallback = callback;
19280
+ return chainable;
19281
+ },
19282
+ onEnd: (callback) => {
19283
+ onEndCallback = callback;
19284
+ return chainable;
19285
+ },
19286
+ then: (resolve, reject) => {
19287
+ if (isStreaming) {
19288
+ if (!streamPromise) {
19289
+ const handler = {
19290
+ onData: onDataCallback,
19291
+ onError: onErrorCallback,
19292
+ onEnd: onEndCallback
19293
+ };
19294
+ streamPromise = this._streamNDJSON(`${this.getComponentPath()}/aggregate`, {
19295
+ 'Accept': 'application/x-ndjson',
19296
+ 'Content-Type': 'application/json'
19297
+ }, handler, pipeline);
19298
+ }
19299
+ return streamPromise.then(resolve, reject);
19300
+ }
19301
+ return this.client.post(`${this.getComponentPath()}/aggregate`, pipeline)
19302
+ .then(resolve, reject);
19303
+ },
19304
+ catch: (reject) => {
19305
+ return chainable.then(undefined, reject);
19306
+ }
19307
+ };
19308
+ return chainable;
19418
19309
  }
19419
19310
  async settings() {
19420
19311
  return await this.client.get(`/v3/system/component/settings/${this.ref}`);
@@ -19432,18 +19323,281 @@ class Component extends PlatformBaseClient {
19432
19323
  });
19433
19324
  }
19434
19325
  async workflow(event, input) {
19435
- return await this.client.post(`/v3/system/component/${this.ref}/workflow/event`, {
19326
+ return await this.client.post(`${this.getComponentPath()}/workflow/event`, {
19436
19327
  event,
19437
19328
  input
19438
19329
  });
19439
19330
  }
19440
19331
  async function(name, input) {
19441
- return await this.client.post(`/v3/system/component/${this.ref}/function/${name}`, {
19332
+ return await this.client.post(`${this.getComponentPath()}/function/${name}`, {
19442
19333
  data: input
19443
19334
  });
19444
19335
  }
19445
19336
  async revisions(uuid) {
19446
- return await this.client.get(`/v3/system/component/${this.ref}/model/${uuid}/revisions`);
19337
+ return await this.client.get(`${this.getComponentPath()}/model/${uuid}/revisions`);
19338
+ }
19339
+ /**
19340
+ * Internal method to handle NDJSON streaming responses
19341
+ *
19342
+ * @private
19343
+ */
19344
+ async _streamNDJSON(url, headers, handler, body) {
19345
+ try {
19346
+ const config = {
19347
+ headers,
19348
+ responseType: 'stream'
19349
+ };
19350
+ const response = await this.client.post(url, body, config);
19351
+ const stream = response.data;
19352
+ let buffer = '';
19353
+ return new Promise((resolve, reject) => {
19354
+ stream.on('data', (chunk) => {
19355
+ buffer += chunk.toString();
19356
+ // Process complete lines (separated by newlines)
19357
+ const lines = buffer.split('\n');
19358
+ buffer = lines.pop() || ''; // Keep incomplete line in buffer
19359
+ for (const line of lines) {
19360
+ if (line.trim()) {
19361
+ try {
19362
+ const document = JSON.parse(line);
19363
+ const result = handler.onData(document);
19364
+ // Support async callbacks
19365
+ if (result instanceof Promise) {
19366
+ result.catch((err) => {
19367
+ if (handler.onError) {
19368
+ handler.onError(err);
19369
+ }
19370
+ });
19371
+ }
19372
+ }
19373
+ catch (err) {
19374
+ if (handler.onError) {
19375
+ handler.onError(err);
19376
+ }
19377
+ }
19378
+ }
19379
+ }
19380
+ });
19381
+ stream.on('end', () => {
19382
+ // Process any remaining data in buffer
19383
+ if (buffer.trim()) {
19384
+ try {
19385
+ const document = JSON.parse(buffer);
19386
+ handler.onData(document);
19387
+ }
19388
+ catch (err) {
19389
+ if (handler.onError) {
19390
+ handler.onError(err);
19391
+ }
19392
+ }
19393
+ }
19394
+ if (handler.onEnd) {
19395
+ handler.onEnd();
19396
+ }
19397
+ resolve();
19398
+ });
19399
+ stream.on('error', (err) => {
19400
+ if (handler.onError) {
19401
+ handler.onError(err);
19402
+ }
19403
+ reject(err);
19404
+ });
19405
+ });
19406
+ }
19407
+ catch (err) {
19408
+ if (handler.onError) {
19409
+ handler.onError(err);
19410
+ }
19411
+ throw err;
19412
+ }
19413
+ }
19414
+ }
19415
+
19416
+ class Functions extends PlatformBaseClient {
19417
+ async list() {
19418
+ return await this.client.get("/v1/system/function");
19419
+ }
19420
+ async get(ref) {
19421
+ return await this.client.get(`/v1/system/function/${ref}`);
19422
+ }
19423
+ async update(uuid, update) {
19424
+ return await this.client.patch(`/v1/system/function/${uuid}`, update);
19425
+ }
19426
+ /**
19427
+ * Run platform function
19428
+ *
19429
+ * @param id - Function ID
19430
+ * @param input - Input data
19431
+ * @param query - Query parameters
19432
+ * @returns - Function result
19433
+ *
19434
+ * @example
19435
+ * const result = await platform.function().run("myFunction", {input: { foo: "bar" }})
19436
+ */
19437
+ async run(id, d) {
19438
+ const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
19439
+ params: d.query,
19440
+ headers: d.headers
19441
+ });
19442
+ return data;
19443
+ }
19444
+ async generateSignature(ref, env) {
19445
+ return await this.client.get(`/v1/system/function/signature/${env}/${ref}`);
19446
+ }
19447
+ }
19448
+
19449
+ class APIUser extends PlatformBaseClient {
19450
+ async auth(username, password, project) {
19451
+ return this.client.post("/v1/user/api/auth", {
19452
+ username,
19453
+ password
19454
+ }, {
19455
+ headers: {
19456
+ "X-Project-Uuid": project
19457
+ }
19458
+ });
19459
+ }
19460
+ async newSecret(uuid) {
19461
+ return await this.client.post(`/v1/user/api-user/secret/${uuid}`, {});
19462
+ }
19463
+ async revokeSecret(uuid) {
19464
+ return await this.client.delete(`/v1/user/api-user/secret/${uuid}`);
19465
+ }
19466
+ async edit(uuid, roles) {
19467
+ return await this.client.patch(`/v1/user/api-user/${uuid}`, { roles });
19468
+ }
19469
+ async list() {
19470
+ return await this.client.get(`/v1/user/api-user`);
19471
+ }
19472
+ async get(uuid) {
19473
+ return await this.client.get(`/v1/user/api-user/${uuid}`);
19474
+ }
19475
+ }
19476
+
19477
+ class Users extends PlatformBaseClient {
19478
+ async auth(username, password, project) {
19479
+ return await this.client.post("/v1/user/login", {
19480
+ username,
19481
+ password,
19482
+ response_type: 'token',
19483
+ }, {
19484
+ headers: {
19485
+ 'X-Project-Uuid': project
19486
+ }
19487
+ });
19488
+ }
19489
+ /**
19490
+ * Resend confirmation email
19491
+ * @param email User email
19492
+ */
19493
+ async resendConfirmationEmail(email) {
19494
+ return await this.client.post("/v1/user/send/confirmation/email", {
19495
+ email,
19496
+ });
19497
+ }
19498
+ // Password Reset (Request Only)
19499
+ // Note: Only the REQUEST is exposed, not the password reset completion
19500
+ // The actual password reset should be done through the official web interface
19501
+ /**
19502
+ * Request password reset email
19503
+ * This only sends an email with a reset link, does not expose or change passwords
19504
+ * @param email User email
19505
+ */
19506
+ async requestPasswordReset(email) {
19507
+ return await this.client.post("/v1/user/resetpassword", { email });
19508
+ }
19509
+ // User Profile & Management
19510
+ /**
19511
+ * Get current user's model
19512
+ */
19513
+ async getUser() {
19514
+ return await this.client.get("/v1/user/model");
19515
+ }
19516
+ /**
19517
+ * Get current user's claims
19518
+ */
19519
+ async getClaims() {
19520
+ return await this.client.get("/v1/user/claims");
19521
+ }
19522
+ /**
19523
+ * Edit user profile
19524
+ * @param data Profile update data
19525
+ */
19526
+ async editProfile(data) {
19527
+ return await this.client.post("/v1/user/profile/edit", data);
19528
+ }
19529
+ // Permissions & Roles
19530
+ /**
19531
+ * Get user permissions
19532
+ */
19533
+ async getPermissions() {
19534
+ return await this.client.get("/v1/user/role/permissions");
19535
+ }
19536
+ /**
19537
+ * Get list of available permissions
19538
+ */
19539
+ async listPermissions() {
19540
+ return await this.client.get("/v1/user/permissions/list");
19541
+ }
19542
+ /**
19543
+ * Create a new role
19544
+ * @param role Role data including name, permissions, workspaces, and level
19545
+ */
19546
+ async createRole(role) {
19547
+ return await this.client.post("/v1/user/role/create", role);
19548
+ }
19549
+ /**
19550
+ * Delete a role
19551
+ * @param uuid Role UUID
19552
+ */
19553
+ async deleteRole(uuid) {
19554
+ return await this.client.delete(`/v1/user/role/delete/${uuid}`);
19555
+ }
19556
+ /**
19557
+ * List all roles
19558
+ */
19559
+ async listRoles() {
19560
+ return await this.client.get(`/v1/user/role/list`);
19561
+ }
19562
+ /**
19563
+ * Get role details by UUID
19564
+ * @param uuid Role UUID
19565
+ */
19566
+ async getRoleModel(uuid) {
19567
+ return await this.client.get(`/v1/user/role/edit/${uuid}`);
19568
+ }
19569
+ /**
19570
+ * Edit a role
19571
+ * @param uuid Role UUID
19572
+ * @param data Role update data including permissions, workspaces, and level
19573
+ */
19574
+ async editRole(uuid, data) {
19575
+ return await this.client.post(`/v1/user/role/edit/${uuid}`, data);
19576
+ }
19577
+ /**
19578
+ * @deprecated Use getPermissions() instead
19579
+ */
19580
+ async permissions() {
19581
+ return await this.client.get(`/v1/user/role/permissions`);
19582
+ }
19583
+ }
19584
+
19585
+ class Apps extends PlatformBaseClient {
19586
+ constructor(appType) {
19587
+ super();
19588
+ this.appType = appType;
19589
+ }
19590
+ async updateSettings(updateValues, ref) {
19591
+ const payload = { ...updateValues };
19592
+ return await this.client.put(`/v3/system/gateway/app-service/${this.appType}/${ref}/settings`, payload);
19593
+ }
19594
+ async download(ref, version) {
19595
+ return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/download`, { version, uuid: ref }, { responseType: "arraybuffer" });
19596
+ }
19597
+ async upload(formData) {
19598
+ return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
19599
+ timeout: 60000
19600
+ });
19447
19601
  }
19448
19602
  }
19449
19603
 
@@ -19978,8 +20132,8 @@ class Platform extends PlatformBaseClient {
19978
20132
  forge() {
19979
20133
  return (new Forge()).setClient(this.client);
19980
20134
  }
19981
- component(ref) {
19982
- return (new Component(ref)).setClient(this.client);
20135
+ component(ref, options) {
20136
+ return (new Component(ref, options)).setClient(this.client);
19983
20137
  }
19984
20138
  componentUtils() {
19985
20139
  return (new ComponentUtils()).setClient(this.client);
@@ -20034,8 +20188,8 @@ class Invoicing extends PlatformBaseClient {
20034
20188
 
20035
20189
  class IntegrationsBaseClient extends BaseClient {
20036
20190
  constructor(options) {
20037
- var _a, _b, _c;
20038
- let { env = null, token, host, } = options !== null && options !== void 0 ? options : {};
20191
+ var _a, _b, _c, _d, _e, _f, _g;
20192
+ let { env = null, token = null, host = null, } = options !== null && options !== void 0 ? options : {};
20039
20193
  let headers = {};
20040
20194
  var project_uuid = null;
20041
20195
  if (isBrowser) {
@@ -20045,16 +20199,22 @@ class IntegrationsBaseClient extends BaseClient {
20045
20199
  else {
20046
20200
  headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
20047
20201
  }
20202
+ if (typeof window !== "undefined") {
20203
+ // @ts-ignore
20204
+ const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
20205
+ host = (_c = __global_env__.INTEGRATION_API) !== null && _c !== void 0 ? _c : host;
20206
+ // @ts-ignore
20207
+ token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
20208
+ // @ts-ignore
20209
+ env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
20210
+ project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
20211
+ }
20048
20212
  }
20049
- if (typeof window !== "undefined") {
20050
- // @ts-ignore
20051
- const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
20052
- host = (_c = __global_env__.INTEGRATION_API) !== null && _c !== void 0 ? _c : host;
20053
- // @ts-ignore
20054
- token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
20055
- // @ts-ignore
20056
- env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
20057
- project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
20213
+ else if (process && process.env) {
20214
+ host = (_d = host !== null && host !== void 0 ? host : process.env.API_HOST) !== null && _d !== void 0 ? _d : null;
20215
+ env = (_e = env !== null && env !== void 0 ? env : process.env.PROJECT_ENV) !== null && _e !== void 0 ? _e : null;
20216
+ token = (_f = token !== null && token !== void 0 ? token : process.env.PROJECT_API_TOKEN) !== null && _f !== void 0 ? _f : null;
20217
+ project_uuid = (_g = process.env.PROJECT_UUID) !== null && _g !== void 0 ? _g : null;
20058
20218
  }
20059
20219
  if (token) {
20060
20220
  headers['Authorization'] = `Bearer ${token}`;
@@ -20074,6 +20234,9 @@ class IntegrationsBaseClient extends BaseClient {
20074
20234
  withCredentials: true,
20075
20235
  });
20076
20236
  super(client);
20237
+ this.env = null;
20238
+ this.token = null;
20239
+ this.host = null;
20077
20240
  }
20078
20241
  }
20079
20242
 
@@ -21718,13 +21881,13 @@ exports.Integration = Integrations;
21718
21881
  exports.Integrations = Integrations;
21719
21882
  exports.Invoicing = Invoicing;
21720
21883
  exports.Payments = Payments;
21884
+ exports.Platform = Platform;
21721
21885
  exports.Project = Project;
21722
21886
  exports.Ratchet = Ratchet;
21723
21887
  exports.Sandbox = Sandbox;
21724
21888
  exports.SerbiaUtil = SerbiaUtil;
21725
21889
  exports.System = System;
21726
21890
  exports.Thunder = Thunder;
21727
- exports.User = Users;
21891
+ exports.Users = Users;
21728
21892
  exports.VPFR = VPFR;
21729
21893
  exports.Workflow = Workflow;
21730
- exports.default = Platform;