@ductape/sdk 0.1.11 → 0.1.12

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 (47) hide show
  1. package/dist/api/services/cloudApi.service.d.ts +8 -8
  2. package/dist/api/services/cloudApi.service.js +28 -12
  3. package/dist/api/services/cloudApi.service.js.map +1 -1
  4. package/dist/api/urls.d.ts +2 -0
  5. package/dist/api/urls.js +3 -1
  6. package/dist/api/urls.js.map +1 -1
  7. package/dist/cloud/cloud-api.util.d.ts +4 -0
  8. package/dist/cloud/cloud-api.util.js +9 -0
  9. package/dist/cloud/cloud-api.util.js.map +1 -0
  10. package/dist/cloud/cloud-broker-link.util.d.ts +9 -0
  11. package/dist/cloud/cloud-broker-link.util.js +62 -0
  12. package/dist/cloud/cloud-broker-link.util.js.map +1 -0
  13. package/dist/cloud/cloud-database-link.util.d.ts +12 -0
  14. package/dist/cloud/cloud-database-link.util.js +65 -0
  15. package/dist/cloud/cloud-database-link.util.js.map +1 -0
  16. package/dist/cloud/cloud-runtime.util.js +13 -8
  17. package/dist/cloud/cloud-runtime.util.js.map +1 -1
  18. package/dist/cloud/cloud.service.d.ts +11 -16
  19. package/dist/cloud/cloud.service.js +10 -14
  20. package/dist/cloud/cloud.service.js.map +1 -1
  21. package/dist/cloud/index.d.ts +3 -0
  22. package/dist/cloud/index.js +7 -1
  23. package/dist/cloud/index.js.map +1 -1
  24. package/dist/cloud/types/cloud.types.d.ts +14 -4
  25. package/dist/database/databases.service.js +2 -0
  26. package/dist/database/databases.service.js.map +1 -1
  27. package/dist/database/types/connection.interface.d.ts +4 -0
  28. package/dist/index.d.ts +6 -5
  29. package/dist/index.js +10 -9
  30. package/dist/index.js.map +1 -1
  31. package/dist/products/services/products.service.d.ts +1 -0
  32. package/dist/products/services/products.service.js +95 -14
  33. package/dist/products/services/products.service.js.map +1 -1
  34. package/dist/products/validators/joi-validators/create.productDatabase.validator.js +22 -17
  35. package/dist/products/validators/joi-validators/create.productDatabase.validator.js.map +1 -1
  36. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +23 -4
  37. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
  38. package/dist/products/validators/joi-validators/create.productStorage.validator.js +39 -26
  39. package/dist/products/validators/joi-validators/create.productStorage.validator.js.map +1 -1
  40. package/dist/products/validators/joi-validators/update.productDatabase.validator.js +4 -0
  41. package/dist/products/validators/joi-validators/update.productDatabase.validator.js.map +1 -1
  42. package/dist/storage/storage-cloud-link.util.d.ts +13 -0
  43. package/dist/storage/storage-cloud-link.util.js +92 -0
  44. package/dist/storage/storage-cloud-link.util.js.map +1 -0
  45. package/dist/types/productsBuilder.types.d.ts +9 -0
  46. package/dist/types/productsBuilder.types.js.map +1 -1
  47. package/package.json +1 -1
@@ -156,6 +156,7 @@ export default class ProductsBuilderService implements IProductsBuilderService {
156
156
  private isQuotaFallbackInput;
157
157
  private redisClient?;
158
158
  private queues;
159
+ private env_type;
159
160
  /** In-memory cache for the current product run (cleared on init) to avoid repeated API calls in workflows */
160
161
  private brokerCache;
161
162
  private envCache;
@@ -21,6 +21,10 @@ const userApi_service_1 = require("../../api/services/userApi.service");
21
21
  const inputs_service_1 = __importDefault(require("../../inputs/inputs.service"));
22
22
  const inputs_utils_create_1 = require("../../inputs/utils/inputs.utils.create");
23
23
  const enums_1 = require("../../types/enums");
24
+ const cloudApi_service_1 = require("../../api/services/cloudApi.service");
25
+ const storage_cloud_link_util_1 = require("../../storage/storage-cloud-link.util");
26
+ const cloud_broker_link_util_1 = require("../../cloud/cloud-broker-link.util");
27
+ const cloud_database_link_util_1 = require("../../cloud/cloud-database-link.util");
24
28
  const productsBuilder_types_1 = require("../../types/productsBuilder.types");
25
29
  const validators_1 = require("../validators");
26
30
  const objects_utils_1 = require("../utils/objects.utils");
@@ -59,6 +63,7 @@ class ProductsBuilderService {
59
63
  this.token = token;
60
64
  this.access_key = access_key || null;
61
65
  this.workspace_private_key = workspace_private_key !== null && workspace_private_key !== void 0 ? workspace_private_key : null;
66
+ this.env_type = env_type;
62
67
  this.userApi = new userApi_service_1.UserApiService(env_type, redis_client);
63
68
  this.productApi = new productsApi_service_1.ProductsApiService(env_type, redis_client);
64
69
  this.workspaceApi = new workspaceApi_service_1.WorkspaceApiService(env_type, redis_client);
@@ -1347,6 +1352,19 @@ class ProductsBuilderService {
1347
1352
  const existingBroker = await this.fetchMessageBroker(data.tag);
1348
1353
  if (!existingBroker) {
1349
1354
  console.log(`${logPrefix} Broker ${data.tag} does not exist, proceeding with creation`);
1355
+ const auth = this.getUserAccess();
1356
+ const cloudApi = new cloudApi_service_1.CloudApiService(this.env_type);
1357
+ const productTag = this.product.tag;
1358
+ const materializedEnvs = [];
1359
+ for (const env of data.envs || []) {
1360
+ materializedEnvs.push(await (0, cloud_broker_link_util_1.materializeCloudLinkedBrokerEnv)(env, {
1361
+ cloudApi,
1362
+ auth,
1363
+ productTag,
1364
+ brokerTag: data.tag,
1365
+ }));
1366
+ }
1367
+ data.envs = materializedEnvs;
1350
1368
  console.log(`${logPrefix} Validating schema...`);
1351
1369
  await validators_1.CreateMessageBrokerSchema.validateAsync(data);
1352
1370
  console.log(`${logPrefix} Schema validation passed`);
@@ -1407,6 +1425,17 @@ class ProductsBuilderService {
1407
1425
  console.log(`${logPrefix} Existing broker found with ${((_b = messageBroker.envs) === null || _b === void 0 ? void 0 : _b.length) || 0} environments`);
1408
1426
  const { _id, envs } = messageBroker;
1409
1427
  console.log(`${logPrefix} Broker ID: ${_id}`);
1428
+ if (data.envs && data.envs.length > 0) {
1429
+ const auth = this.getUserAccess();
1430
+ const cloudApi = new cloudApi_service_1.CloudApiService(this.env_type);
1431
+ const productTag = this.product.tag;
1432
+ data.envs = await Promise.all(data.envs.map(async (env) => (0, cloud_broker_link_util_1.materializeCloudLinkedBrokerEnv)(env, {
1433
+ cloudApi,
1434
+ auth,
1435
+ productTag,
1436
+ brokerTag: data.tag || tag,
1437
+ })));
1438
+ }
1410
1439
  console.log(`${logPrefix} Validating update schema...`);
1411
1440
  await validators_1.UpdateMessageBrokerSchema.validateAsync(data);
1412
1441
  console.log(`${logPrefix} Schema validation passed`);
@@ -1415,7 +1444,7 @@ class ProductsBuilderService {
1415
1444
  throw new Error(`tag ${tag} is in use`);
1416
1445
  }
1417
1446
  const processedEnvs = [];
1418
- for (const env of data.envs) {
1447
+ for (const env of data.envs || []) {
1419
1448
  console.log(`${logPrefix} Processing env: ${env.slug} (type: ${env.type})`);
1420
1449
  const exists = await this.fetchEnv(env.slug);
1421
1450
  if (!exists) {
@@ -1570,6 +1599,19 @@ class ProductsBuilderService {
1570
1599
  }
1571
1600
  async createStorage(data, throwErrorIfExists = false) {
1572
1601
  if (!(await this.fetchStorage(data.tag))) {
1602
+ const auth = this.getUserAccess();
1603
+ const cloudApi = new cloudApi_service_1.CloudApiService(this.env_type);
1604
+ const productTag = this.product.tag;
1605
+ const materializedEnvs = [];
1606
+ for (const env of data.envs || []) {
1607
+ materializedEnvs.push(await (0, storage_cloud_link_util_1.materializeCloudLinkedStorageEnv)(env, {
1608
+ cloudApi,
1609
+ auth,
1610
+ productTag,
1611
+ storageTag: data.tag,
1612
+ }));
1613
+ }
1614
+ data.envs = materializedEnvs;
1573
1615
  await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
1574
1616
  const processedEnvs = [];
1575
1617
  for (const env of data.envs) {
@@ -1608,11 +1650,22 @@ class ProductsBuilderService {
1608
1650
  throw new Error(`Storage ${tag} not found`);
1609
1651
  }
1610
1652
  const { _id, envs } = storage;
1611
- await create_productStorage_validator_1.UpdateProductStorageSchema.validateAsync(data); // Change to update;
1612
1653
  if (data.tag && await this.fetchStorage(data.tag)) {
1613
1654
  throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
1614
1655
  }
1615
1656
  // Only process envs if they are provided in the update
1657
+ if (data.envs && data.envs.length > 0) {
1658
+ const auth = this.getUserAccess();
1659
+ const cloudApi = new cloudApi_service_1.CloudApiService(this.env_type);
1660
+ const productTag = this.product.tag;
1661
+ data.envs = await Promise.all(data.envs.map(async (env) => (0, storage_cloud_link_util_1.materializeCloudLinkedStorageEnv)(env, {
1662
+ cloudApi,
1663
+ auth,
1664
+ productTag,
1665
+ storageTag: data.tag || tag,
1666
+ })));
1667
+ }
1668
+ await create_productStorage_validator_1.UpdateProductStorageSchema.validateAsync(data);
1616
1669
  if (data.envs && data.envs.length > 0) {
1617
1670
  data.envs = await Promise.all(data.envs.map(async (env) => {
1618
1671
  const exists = await this.fetchEnv(env.slug);
@@ -4107,8 +4160,20 @@ class ProductsBuilderService {
4107
4160
  }
4108
4161
  async createDatabase(data, throwErrorIfExists = false) {
4109
4162
  try {
4110
- // TODO: figure out a way to check if this has run before, halt if it has
4111
4163
  if (!(await this.fetchDatabase(data.tag))) {
4164
+ const auth = this.getUserAccess();
4165
+ const cloudApi = new cloudApi_service_1.CloudApiService(this.env_type);
4166
+ const productTag = this.product.tag;
4167
+ const materializedEnvs = [];
4168
+ for (const env of data.envs || []) {
4169
+ materializedEnvs.push(await (0, cloud_database_link_util_1.materializeCloudLinkedDatabaseEnv)(env, {
4170
+ cloudApi,
4171
+ auth,
4172
+ productTag,
4173
+ databaseTag: data.tag,
4174
+ }));
4175
+ }
4176
+ data.envs = materializedEnvs;
4112
4177
  await validators_1.CreateProductDatabaseSchema.validateAsync(data);
4113
4178
  const processedEnvs = [];
4114
4179
  for (const env of data.envs) {
@@ -4145,20 +4210,36 @@ class ProductsBuilderService {
4145
4210
  throw new Error(`Database ${tag} not found`);
4146
4211
  }
4147
4212
  const { _id, envs } = db;
4148
- await validators_1.UpdateProductDatabaseSchema.validateAsync(data); // Change to update;
4149
4213
  if (data.tag && this.fetchDatabase(data.tag)) {
4150
4214
  throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
4151
4215
  }
4152
- data.envs = await Promise.all(data.envs.map(async (env) => {
4153
- const exists = await this.fetchEnv(env.slug);
4154
- if (!exists) {
4155
- throw new Error(`Env ${env.slug} does not exist`);
4156
- }
4157
- if (env.connection_url) {
4158
- env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
4159
- }
4160
- return env;
4161
- }));
4216
+ if (data.envs && data.envs.length > 0) {
4217
+ const auth = this.getUserAccess();
4218
+ const cloudApi = new cloudApi_service_1.CloudApiService(this.env_type);
4219
+ const productTag = this.product.tag;
4220
+ data.envs = await Promise.all(data.envs.map(async (env) => (0, cloud_database_link_util_1.materializeCloudLinkedDatabaseEnv)(env, {
4221
+ cloudApi,
4222
+ auth,
4223
+ productTag,
4224
+ databaseTag: data.tag || tag,
4225
+ })));
4226
+ }
4227
+ await validators_1.UpdateProductDatabaseSchema.validateAsync(data);
4228
+ if (data.envs && data.envs.length > 0) {
4229
+ data.envs = await Promise.all(data.envs.map(async (env) => {
4230
+ const exists = await this.fetchEnv(env.slug);
4231
+ if (!exists) {
4232
+ throw new Error(`Env ${env.slug} does not exist`);
4233
+ }
4234
+ if (env.connection_url) {
4235
+ env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
4236
+ }
4237
+ return env;
4238
+ }));
4239
+ }
4240
+ if (!data.envs) {
4241
+ data.envs = [];
4242
+ }
4162
4243
  const overwrite = [];
4163
4244
  const newEnvs = [];
4164
4245
  data.envs.map((dataEnv) => {