@ductape/sdk 0.0.4-v9 → 0.0.4-v90
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.
- package/dist/agents/agent-context.d.ts +98 -0
- package/dist/agents/agent-context.js +588 -0
- package/dist/agents/agent-context.js.map +1 -0
- package/dist/agents/agent-executor.d.ts +180 -0
- package/dist/agents/agent-executor.js +715 -0
- package/dist/agents/agent-executor.js.map +1 -0
- package/dist/agents/agents.service.d.ts +310 -0
- package/dist/agents/agents.service.js +1249 -0
- package/dist/agents/agents.service.js.map +1 -0
- package/dist/agents/index.d.ts +55 -0
- package/dist/agents/index.js +110 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/memory-manager.d.ts +182 -0
- package/dist/agents/memory-manager.js +383 -0
- package/dist/agents/memory-manager.js.map +1 -0
- package/dist/agents/tool-registry.d.ts +141 -0
- package/dist/agents/tool-registry.js +355 -0
- package/dist/agents/tool-registry.js.map +1 -0
- package/dist/agents/types/agents.types.d.ts +1227 -0
- package/dist/agents/types/agents.types.js +12 -0
- package/dist/agents/types/agents.types.js.map +1 -0
- package/dist/agents/types/index.d.ts +6 -0
- package/dist/agents/types/index.js +23 -0
- package/dist/agents/types/index.js.map +1 -0
- package/dist/agents/vector-store-adapter.d.ts +108 -0
- package/dist/agents/vector-store-adapter.js +213 -0
- package/dist/agents/vector-store-adapter.js.map +1 -0
- package/dist/api/services/appApi.service.d.ts +51 -5
- package/dist/api/services/appApi.service.js +101 -3
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/pricingApi.service.d.ts +10 -0
- package/dist/api/services/pricingApi.service.js +34 -0
- package/dist/api/services/pricingApi.service.js.map +1 -0
- package/dist/api/services/processorApi.service.d.ts +322 -0
- package/dist/api/services/processorApi.service.js +252 -0
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +105 -0
- package/dist/api/services/productsApi.service.js +139 -3
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/resilienceApi.service.d.ts +106 -0
- package/dist/api/services/resilienceApi.service.js +224 -0
- package/dist/api/services/resilienceApi.service.js.map +1 -0
- package/dist/api/services/secretsApi.service.d.ts +50 -0
- package/dist/api/services/secretsApi.service.js +124 -0
- package/dist/api/services/secretsApi.service.js.map +1 -0
- package/dist/api/services/workflowApi.service.d.ts +199 -0
- package/dist/api/services/workflowApi.service.js +183 -0
- package/dist/api/services/workflowApi.service.js.map +1 -0
- package/dist/api/services/workspaceApi.service.d.ts +8 -0
- package/dist/api/services/workspaceApi.service.js +20 -0
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +62 -0
- package/dist/api/urls.js +87 -17
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/auth.utils.d.ts +1 -3
- package/dist/api/utils/auth.utils.js.map +1 -1
- package/dist/api/utils/cache.utils.d.ts +1 -1
- package/dist/api/utils/cache.utils.js +2 -2
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/api/utils/strings.utils.d.ts +2 -0
- package/dist/api/utils/strings.utils.js +14 -0
- package/dist/api/utils/strings.utils.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +41 -33
- package/dist/apps/services/app.service.js +472 -184
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/utils/auth-context-manager.d.ts +137 -0
- package/dist/apps/utils/auth-context-manager.js +248 -0
- package/dist/apps/utils/auth-context-manager.js.map +1 -0
- package/dist/apps/utils/credential-manager.d.ts +128 -0
- package/dist/apps/utils/credential-manager.js +199 -0
- package/dist/apps/utils/credential-manager.js.map +1 -0
- package/dist/apps/utils/index.d.ts +10 -0
- package/dist/apps/utils/index.js +54 -0
- package/dist/apps/utils/index.js.map +1 -0
- package/dist/apps/utils/input-helpers.d.ts +67 -0
- package/dist/apps/utils/input-helpers.js +185 -0
- package/dist/apps/utils/input-helpers.js.map +1 -0
- package/dist/apps/utils/input-resolver.d.ts +165 -0
- package/dist/apps/utils/input-resolver.js +477 -0
- package/dist/apps/utils/input-resolver.js.map +1 -0
- package/dist/apps/utils/oauth-manager.d.ts +196 -0
- package/dist/apps/utils/oauth-manager.js +429 -0
- package/dist/apps/utils/oauth-manager.js.map +1 -0
- package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js +21 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
- package/dist/bin.d.ts +26 -0
- package/dist/bin.js +28 -0
- package/dist/bin.js.map +1 -0
- package/dist/brokers/brokers.service.d.ts +297 -0
- package/dist/brokers/brokers.service.js +797 -0
- package/dist/brokers/brokers.service.js.map +1 -0
- package/dist/brokers/index.d.ts +46 -0
- package/dist/brokers/index.js +83 -0
- package/dist/brokers/index.js.map +1 -0
- package/dist/brokers/types/index.d.ts +316 -0
- package/dist/brokers/types/index.js +8 -0
- package/dist/brokers/types/index.js.map +1 -0
- package/dist/brokers/utils/broker.util.d.ts +33 -0
- package/dist/brokers/utils/broker.util.js +125 -0
- package/dist/brokers/utils/broker.util.js.map +1 -0
- package/dist/brokers/utils/providers/aws-sqs.service.d.ts +16 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js +71 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js.map +1 -0
- package/dist/brokers/utils/providers/google-pubsub.service.d.ts +16 -0
- package/dist/brokers/utils/providers/google-pubsub.service.js +43 -0
- package/dist/brokers/utils/providers/google-pubsub.service.js.map +1 -0
- package/dist/brokers/utils/providers/index.d.ts +6 -0
- package/dist/brokers/utils/providers/index.js +16 -0
- package/dist/brokers/utils/providers/index.js.map +1 -0
- package/dist/brokers/utils/providers/kafka.service.d.ts +23 -0
- package/dist/brokers/utils/providers/kafka.service.js +131 -0
- package/dist/brokers/utils/providers/kafka.service.js.map +1 -0
- package/dist/brokers/utils/providers/nats.service.d.ts +18 -0
- package/dist/brokers/utils/providers/nats.service.js +63 -0
- package/dist/brokers/utils/providers/nats.service.js.map +1 -0
- package/dist/brokers/utils/providers/rabbitmq.service.d.ts +15 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js +151 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js.map +1 -0
- package/dist/brokers/utils/providers/redis.service.d.ts +18 -0
- package/dist/brokers/utils/providers/redis.service.js +93 -0
- package/dist/brokers/utils/providers/redis.service.js.map +1 -0
- package/dist/cache/cache.manager.d.ts +229 -0
- package/dist/cache/cache.manager.js +460 -0
- package/dist/cache/cache.manager.js.map +1 -0
- package/dist/cache/cache.service.d.ts +186 -0
- package/dist/cache/cache.service.js +437 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/cache/index.d.ts +52 -0
- package/dist/cache/index.js +79 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/types/index.d.ts +106 -0
- package/dist/cache/types/index.js +6 -0
- package/dist/cache/types/index.js.map +1 -0
- package/dist/clients/pricing.client.d.ts +3 -0
- package/dist/clients/pricing.client.js +33 -0
- package/dist/clients/pricing.client.js.map +1 -0
- package/dist/database/actions/action-manager.d.ts +170 -0
- package/dist/database/actions/action-manager.js +465 -0
- package/dist/database/actions/action-manager.js.map +1 -0
- package/dist/database/actions/index.d.ts +6 -0
- package/dist/database/actions/index.js +13 -0
- package/dist/database/actions/index.js.map +1 -0
- package/dist/database/adapters/adapter.factory.d.ts +62 -0
- package/dist/database/adapters/adapter.factory.js +97 -0
- package/dist/database/adapters/adapter.factory.js.map +1 -0
- package/dist/database/adapters/base.adapter.d.ts +423 -0
- package/dist/database/adapters/base.adapter.js +260 -0
- package/dist/database/adapters/base.adapter.js.map +1 -0
- package/dist/database/adapters/cassandra.adapter.d.ts +92 -0
- package/dist/database/adapters/cassandra.adapter.js +1091 -0
- package/dist/database/adapters/cassandra.adapter.js.map +1 -0
- package/dist/database/adapters/dynamodb.adapter.d.ts +110 -0
- package/dist/database/adapters/dynamodb.adapter.js +1564 -0
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
- package/dist/database/adapters/index.d.ts +11 -0
- package/dist/database/adapters/index.js +27 -0
- package/dist/database/adapters/index.js.map +1 -0
- package/dist/database/adapters/mariadb.adapter.d.ts +100 -0
- package/dist/database/adapters/mariadb.adapter.js +247 -0
- package/dist/database/adapters/mariadb.adapter.js.map +1 -0
- package/dist/database/adapters/mongodb.adapter.d.ts +121 -0
- package/dist/database/adapters/mongodb.adapter.js +1284 -0
- package/dist/database/adapters/mongodb.adapter.js.map +1 -0
- package/dist/database/adapters/mysql.adapter.d.ts +86 -0
- package/dist/database/adapters/mysql.adapter.js +1371 -0
- package/dist/database/adapters/mysql.adapter.js.map +1 -0
- package/dist/database/adapters/postgresql.adapter.d.ts +90 -0
- package/dist/database/adapters/postgresql.adapter.js +1487 -0
- package/dist/database/adapters/postgresql.adapter.js.map +1 -0
- package/dist/database/databases.service.d.ts +1408 -0
- package/dist/database/databases.service.js +2953 -0
- package/dist/database/databases.service.js.map +1 -0
- package/dist/database/index.d.ts +46 -0
- package/dist/database/index.js +109 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/migrations/index.d.ts +6 -0
- package/dist/database/migrations/index.js +12 -0
- package/dist/database/migrations/index.js.map +1 -0
- package/dist/database/migrations/migration-engine.d.ts +136 -0
- package/dist/database/migrations/migration-engine.js +1421 -0
- package/dist/database/migrations/migration-engine.js.map +1 -0
- package/dist/database/operators/aggregation-builder.d.ts +67 -0
- package/dist/database/operators/aggregation-builder.js +841 -0
- package/dist/database/operators/aggregation-builder.js.map +1 -0
- package/dist/database/operators/index.d.ts +7 -0
- package/dist/database/operators/index.js +15 -0
- package/dist/database/operators/index.js.map +1 -0
- package/dist/database/operators/query-builder.d.ts +69 -0
- package/dist/database/operators/query-builder.js +447 -0
- package/dist/database/operators/query-builder.js.map +1 -0
- package/dist/database/presave/decrypt.d.ts +25 -0
- package/dist/database/presave/decrypt.js +146 -0
- package/dist/database/presave/decrypt.js.map +1 -0
- package/dist/database/presave/index.d.ts +9 -0
- package/dist/database/presave/index.js +18 -0
- package/dist/database/presave/index.js.map +1 -0
- package/dist/database/presave/presave-processor.d.ts +148 -0
- package/dist/database/presave/presave-processor.js +702 -0
- package/dist/database/presave/presave-processor.js.map +1 -0
- package/dist/database/schema/index.d.ts +7 -0
- package/dist/database/schema/index.js +13 -0
- package/dist/database/schema/index.js.map +1 -0
- package/dist/database/schema/schema-manager.d.ts +258 -0
- package/dist/database/schema/schema-manager.js +638 -0
- package/dist/database/schema/schema-manager.js.map +1 -0
- package/dist/database/transactions/index.d.ts +6 -0
- package/dist/database/transactions/index.js +13 -0
- package/dist/database/transactions/index.js.map +1 -0
- package/dist/database/transactions/transaction-manager.d.ts +113 -0
- package/dist/database/transactions/transaction-manager.js +344 -0
- package/dist/database/transactions/transaction-manager.js.map +1 -0
- package/dist/database/triggers/index.d.ts +7 -0
- package/dist/database/triggers/index.js +14 -0
- package/dist/database/triggers/index.js.map +1 -0
- package/dist/database/triggers/trigger-processor.d.ts +239 -0
- package/dist/database/triggers/trigger-processor.js +1034 -0
- package/dist/database/triggers/trigger-processor.js.map +1 -0
- package/dist/database/types/action.interface.d.ts +148 -0
- package/dist/database/types/action.interface.js +6 -0
- package/dist/database/types/action.interface.js.map +1 -0
- package/dist/database/types/aggregation.interface.d.ts +185 -0
- package/dist/database/types/aggregation.interface.js +6 -0
- package/dist/database/types/aggregation.interface.js.map +1 -0
- package/dist/database/types/connection.interface.d.ts +137 -0
- package/dist/database/types/connection.interface.js +6 -0
- package/dist/database/types/connection.interface.js.map +1 -0
- package/dist/database/types/enums.d.ts +195 -0
- package/dist/database/types/enums.js +244 -0
- package/dist/database/types/enums.js.map +1 -0
- package/dist/database/types/index.d.ts +14 -0
- package/dist/database/types/index.js +31 -0
- package/dist/database/types/index.js.map +1 -0
- package/dist/database/types/migration.interface.d.ts +686 -0
- package/dist/database/types/migration.interface.js +9 -0
- package/dist/database/types/migration.interface.js.map +1 -0
- package/dist/database/types/presave.interface.d.ts +292 -0
- package/dist/database/types/presave.interface.js +60 -0
- package/dist/database/types/presave.interface.js.map +1 -0
- package/dist/database/types/query.interface.d.ts +205 -0
- package/dist/database/types/query.interface.js +6 -0
- package/dist/database/types/query.interface.js.map +1 -0
- package/dist/database/types/schema.interface.d.ts +412 -0
- package/dist/database/types/schema.interface.js +6 -0
- package/dist/database/types/schema.interface.js.map +1 -0
- package/dist/database/types/transaction.interface.d.ts +84 -0
- package/dist/database/types/transaction.interface.js +6 -0
- package/dist/database/types/transaction.interface.js.map +1 -0
- package/dist/database/types/trigger.interface.d.ts +612 -0
- package/dist/database/types/trigger.interface.js +121 -0
- package/dist/database/types/trigger.interface.js.map +1 -0
- package/dist/database/types/write.interface.d.ts +216 -0
- package/dist/database/types/write.interface.js +6 -0
- package/dist/database/types/write.interface.js.map +1 -0
- package/dist/database/utils/database-error.d.ts +96 -0
- package/dist/database/utils/database-error.js +221 -0
- package/dist/database/utils/database-error.js.map +1 -0
- package/dist/database/utils/index.d.ts +6 -0
- package/dist/database/utils/index.js +11 -0
- package/dist/database/utils/index.js.map +1 -0
- package/dist/graph/adapters/adapter.factory.d.ts +47 -0
- package/dist/graph/adapters/adapter.factory.js +77 -0
- package/dist/graph/adapters/adapter.factory.js.map +1 -0
- package/dist/graph/adapters/arangodb.adapter.d.ts +86 -0
- package/dist/graph/adapters/arangodb.adapter.js +1588 -0
- package/dist/graph/adapters/arangodb.adapter.js.map +1 -0
- package/dist/graph/adapters/base.adapter.d.ts +264 -0
- package/dist/graph/adapters/base.adapter.js +156 -0
- package/dist/graph/adapters/base.adapter.js.map +1 -0
- package/dist/graph/adapters/index.d.ts +11 -0
- package/dist/graph/adapters/index.js +21 -0
- package/dist/graph/adapters/index.js.map +1 -0
- package/dist/graph/adapters/memgraph.adapter.d.ts +110 -0
- package/dist/graph/adapters/memgraph.adapter.js +1452 -0
- package/dist/graph/adapters/memgraph.adapter.js.map +1 -0
- package/dist/graph/adapters/neo4j.adapter.d.ts +81 -0
- package/dist/graph/adapters/neo4j.adapter.js +1317 -0
- package/dist/graph/adapters/neo4j.adapter.js.map +1 -0
- package/dist/graph/adapters/neptune.adapter.d.ts +82 -0
- package/dist/graph/adapters/neptune.adapter.js +1369 -0
- package/dist/graph/adapters/neptune.adapter.js.map +1 -0
- package/dist/graph/graphs.service.d.ts +568 -0
- package/dist/graph/graphs.service.js +1948 -0
- package/dist/graph/graphs.service.js.map +1 -0
- package/dist/graph/index.d.ts +57 -0
- package/dist/graph/index.js +77 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/transactions/index.d.ts +4 -0
- package/dist/graph/transactions/index.js +9 -0
- package/dist/graph/transactions/index.js.map +1 -0
- package/dist/graph/transactions/transaction-manager.d.ts +61 -0
- package/dist/graph/transactions/transaction-manager.js +126 -0
- package/dist/graph/transactions/transaction-manager.js.map +1 -0
- package/dist/graph/types/connection.interface.d.ts +149 -0
- package/dist/graph/types/connection.interface.js +9 -0
- package/dist/graph/types/connection.interface.js.map +1 -0
- package/dist/graph/types/enums.d.ts +101 -0
- package/dist/graph/types/enums.js +114 -0
- package/dist/graph/types/enums.js.map +1 -0
- package/dist/graph/types/index.d.ts +13 -0
- package/dist/graph/types/index.js +20 -0
- package/dist/graph/types/index.js.map +1 -0
- package/dist/graph/types/node.interface.d.ts +248 -0
- package/dist/graph/types/node.interface.js +9 -0
- package/dist/graph/types/node.interface.js.map +1 -0
- package/dist/graph/types/query.interface.d.ts +175 -0
- package/dist/graph/types/query.interface.js +9 -0
- package/dist/graph/types/query.interface.js.map +1 -0
- package/dist/graph/types/relationship.interface.d.ts +207 -0
- package/dist/graph/types/relationship.interface.js +9 -0
- package/dist/graph/types/relationship.interface.js.map +1 -0
- package/dist/graph/types/schema.interface.d.ts +295 -0
- package/dist/graph/types/schema.interface.js +9 -0
- package/dist/graph/types/schema.interface.js.map +1 -0
- package/dist/graph/types/transaction.interface.d.ts +55 -0
- package/dist/graph/types/transaction.interface.js +9 -0
- package/dist/graph/types/transaction.interface.js.map +1 -0
- package/dist/graph/types/traversal.interface.d.ts +181 -0
- package/dist/graph/types/traversal.interface.js +9 -0
- package/dist/graph/types/traversal.interface.js.map +1 -0
- package/dist/graph/utils/graph-error.d.ts +71 -0
- package/dist/graph/utils/graph-error.js +142 -0
- package/dist/graph/utils/graph-error.js.map +1 -0
- package/dist/graph/utils/index.d.ts +4 -0
- package/dist/graph/utils/index.js +9 -0
- package/dist/graph/utils/index.js.map +1 -0
- package/dist/imports/imports.service.d.ts +3 -3
- package/dist/imports/imports.service.js +8 -7
- package/dist/imports/imports.service.js.map +1 -1
- package/dist/imports/imports.types.d.ts +8 -0
- package/dist/imports/repos/openApi.repo.d.ts +1 -1
- package/dist/imports/repos/openApi.repo.js +414 -47
- package/dist/imports/repos/openApi.repo.js.map +1 -1
- package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
- package/dist/imports/repos/postmanV21.repo.js +126 -83
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +3654 -289
- package/dist/index.js +5066 -669
- package/dist/index.js.map +1 -1
- package/dist/init.interface.d.ts +407 -0
- package/dist/init.interface.js +3 -0
- package/dist/init.interface.js.map +1 -0
- package/dist/inputs/inputs.service.d.ts +1 -1
- package/dist/inputs/utils/inputs.utils.create.js +1 -1
- package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
- package/dist/jobs/index.d.ts +38 -0
- package/dist/jobs/index.js +50 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/jobs.service.d.ts +154 -0
- package/dist/jobs/jobs.service.js +491 -0
- package/dist/jobs/jobs.service.js.map +1 -0
- package/dist/jobs/jobs.state.d.ts +113 -0
- package/dist/jobs/jobs.state.js +447 -0
- package/dist/jobs/jobs.state.js.map +1 -0
- package/dist/jobs/types.d.ts +449 -0
- package/dist/jobs/types.js +74 -0
- package/dist/jobs/types.js.map +1 -0
- package/dist/logs/logs.service.js +6 -2
- package/dist/logs/logs.service.js.map +1 -1
- package/dist/logs/logs.types.d.ts +19 -1
- package/dist/logs/logs.types.js +6 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.js +11 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/models.service.d.ts +137 -0
- package/dist/models/models.service.js +195 -0
- package/dist/models/models.service.js.map +1 -0
- package/dist/notifications/index.d.ts +13 -0
- package/dist/notifications/index.js +26 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/notifications.service.d.ts +265 -0
- package/dist/notifications/notifications.service.js +862 -0
- package/dist/notifications/notifications.service.js.map +1 -0
- package/dist/notifications/types/index.d.ts +4 -0
- package/dist/notifications/types/index.js +21 -0
- package/dist/notifications/types/index.js.map +1 -0
- package/dist/notifications/types/notifications.types.d.ts +402 -0
- package/dist/notifications/types/notifications.types.js +49 -0
- package/dist/notifications/types/notifications.types.js.map +1 -0
- package/dist/parsers/index.d.ts +3 -0
- package/dist/parsers/index.js +27 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
- package/dist/parsers/pipelines/postman.pipelines.js +103 -0
- package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
- package/dist/parsers/types/postman.types.d.ts +200 -0
- package/dist/parsers/types/postman.types.js +3 -0
- package/dist/parsers/types/postman.types.js.map +1 -0
- package/dist/parsers/utils/postman.utils.d.ts +12 -0
- package/dist/parsers/utils/postman.utils.js +116 -0
- package/dist/parsers/utils/postman.utils.js.map +1 -0
- package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
- package/dist/parsers/validators/postman-auth.validators.js +127 -0
- package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
- package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-request.validators.js +139 -0
- package/dist/parsers/validators/postman-request.validators.js.map +1 -0
- package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-response.validators.js +150 -0
- package/dist/parsers/validators/postman-response.validators.js.map +1 -0
- package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
- package/dist/parsers/validators/postman-variable.validators.js +163 -0
- package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
- package/dist/pricing/pricing.repo.js +1 -0
- package/dist/pricing/pricing.repo.js.map +1 -0
- package/dist/pricing/pricing.service.d.ts +24 -0
- package/dist/pricing/pricing.service.js +51 -0
- package/dist/pricing/pricing.service.js.map +1 -0
- package/dist/pricing/pricing.types.d.ts +76 -0
- package/dist/pricing/pricing.types.js +21 -0
- package/dist/pricing/pricing.types.js.map +1 -0
- package/dist/pricing/utils/string.utils.d.ts +1 -0
- package/dist/pricing/utils/string.utils.js +9 -0
- package/dist/pricing/utils/string.utils.js.map +1 -0
- package/dist/processor/services/processor.service.d.ts +117 -73
- package/dist/processor/services/processor.service.js +1557 -1276
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/request.service.d.ts +36 -0
- package/dist/processor/services/request.service.js +304 -0
- package/dist/processor/services/request.service.js.map +1 -0
- package/dist/processor/types/request.types.d.ts +14 -0
- package/dist/processor/types/request.types.js +3 -0
- package/dist/processor/types/request.types.js.map +1 -0
- package/dist/processor/utils/processor.utils.js +32 -20
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/request.utils.d.ts +20 -0
- package/dist/processor/utils/request.utils.js +113 -0
- package/dist/processor/utils/request.utils.js.map +1 -0
- package/dist/products/services/products.service.d.ts +365 -75
- package/dist/products/services/products.service.js +2809 -414
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/utils/string.utils.d.ts +1 -1
- package/dist/products/utils/string.utils.js +14 -2
- package/dist/products/utils/string.utils.js.map +1 -1
- package/dist/products/validators/index.d.ts +7 -1
- package/dist/products/validators/index.js +16 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productAgent.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js +266 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productGraph.validator.js +89 -0
- package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +81 -25
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productModel.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productModel.validator.js +132 -0
- package/dist/products/validators/joi-validators/create.productModel.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productNotification.validator.js +133 -45
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productStorage.validator.js +77 -18
- package/dist/products/validators/joi-validators/create.productStorage.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productVector.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js +135 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/update.productDatabase.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
- package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productGraph.validator.js +88 -0
- package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -0
- package/dist/resilience/fallback.service.d.ts +140 -0
- package/dist/resilience/fallback.service.js +764 -0
- package/dist/resilience/fallback.service.js.map +1 -0
- package/dist/resilience/healthcheck.service.d.ts +159 -0
- package/dist/resilience/healthcheck.service.js +943 -0
- package/dist/resilience/healthcheck.service.js.map +1 -0
- package/dist/resilience/index.d.ts +104 -0
- package/dist/resilience/index.js +140 -0
- package/dist/resilience/index.js.map +1 -0
- package/dist/resilience/quota.service.d.ts +82 -0
- package/dist/resilience/quota.service.js +516 -0
- package/dist/resilience/quota.service.js.map +1 -0
- package/dist/resilience/resilience.service.d.ts +98 -0
- package/dist/resilience/resilience.service.js +560 -0
- package/dist/resilience/resilience.service.js.map +1 -0
- package/dist/resilience/types/index.d.ts +513 -0
- package/dist/resilience/types/index.js +29 -0
- package/dist/resilience/types/index.js.map +1 -0
- package/dist/secrets/index.d.ts +10 -0
- package/dist/secrets/index.js +33 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/secrets/secrets.resolver.d.ts +52 -0
- package/dist/secrets/secrets.resolver.js +233 -0
- package/dist/secrets/secrets.resolver.js.map +1 -0
- package/dist/secrets/secrets.service.d.ts +93 -0
- package/dist/secrets/secrets.service.js +258 -0
- package/dist/secrets/secrets.service.js.map +1 -0
- package/dist/secrets/secrets.types.d.ts +188 -0
- package/dist/secrets/secrets.types.js +87 -0
- package/dist/secrets/secrets.types.js.map +1 -0
- package/dist/sessions/index.d.ts +50 -0
- package/dist/sessions/index.js +93 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/sessions.helper.d.ts +68 -0
- package/dist/sessions/sessions.helper.js +116 -0
- package/dist/sessions/sessions.helper.js.map +1 -0
- package/dist/sessions/sessions.resolver.d.ts +157 -0
- package/dist/sessions/sessions.resolver.js +374 -0
- package/dist/sessions/sessions.resolver.js.map +1 -0
- package/dist/sessions/sessions.service.d.ts +178 -0
- package/dist/sessions/sessions.service.js +923 -0
- package/dist/sessions/sessions.service.js.map +1 -0
- package/dist/sessions/types/index.d.ts +298 -0
- package/dist/sessions/types/index.js +6 -0
- package/dist/sessions/types/index.js.map +1 -0
- package/dist/storage/index.d.ts +66 -0
- package/dist/storage/index.js +99 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/storage.service.d.ts +174 -0
- package/dist/storage/storage.service.js +757 -0
- package/dist/storage/storage.service.js.map +1 -0
- package/dist/storage/types/index.d.ts +267 -0
- package/dist/storage/types/index.js +6 -0
- package/dist/storage/types/index.js.map +1 -0
- package/dist/storage/utils/storage.util.d.ts +62 -0
- package/dist/storage/utils/storage.util.js +593 -0
- package/dist/storage/utils/storage.util.js.map +1 -0
- package/dist/test/index.d.ts +3 -0
- package/dist/test/index.js +11 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/test.appBuilder.d.ts +0 -1
- package/dist/test/test.appBuilder.js +0 -15
- package/dist/test/test.appBuilder.js.map +1 -1
- package/dist/test/test.broker.kafka.js +172 -0
- package/dist/test/test.broker.kafka.js.map +1 -0
- package/dist/test/test.broker.nats.js +193 -0
- package/dist/test/test.broker.nats.js.map +1 -0
- package/dist/test/test.broker.pubsub.js +171 -0
- package/dist/test/test.broker.pubsub.js.map +1 -0
- package/dist/test/test.broker.rabbitmq.js +164 -0
- package/dist/test/test.broker.rabbitmq.js.map +1 -0
- package/dist/test/test.broker.redis.js +168 -0
- package/dist/test/test.broker.redis.js.map +1 -0
- package/dist/test/test.broker.sqs.d.ts +1 -0
- package/dist/test/test.broker.sqs.js +158 -0
- package/dist/test/test.broker.sqs.js.map +1 -0
- package/dist/test/test.caches.d.ts +1 -0
- package/dist/test/test.caches.js +231 -0
- package/dist/test/test.caches.js.map +1 -0
- package/dist/test/test.database.d.ts +1 -0
- package/dist/test/test.database.dynamo.d.ts +1 -0
- package/dist/test/test.database.dynamo.js +265 -0
- package/dist/test/test.database.dynamo.js.map +1 -0
- package/dist/test/test.database.js +140 -0
- package/dist/test/test.database.js.map +1 -0
- package/dist/test/test.database.mongo.d.ts +1 -0
- package/dist/test/test.database.mongo.js +371 -0
- package/dist/test/test.database.mongo.js.map +1 -0
- package/dist/test/test.database.mysql.d.ts +1 -0
- package/dist/test/test.database.mysql.js +415 -0
- package/dist/test/test.database.mysql.js.map +1 -0
- package/dist/test/test.database.postgres.d.ts +1 -0
- package/dist/test/test.database.postgres.js +412 -0
- package/dist/test/test.database.postgres.js.map +1 -0
- package/dist/test/test.email.brevo.d.ts +1 -0
- package/dist/test/test.email.brevo.js +326 -0
- package/dist/test/test.email.brevo.js.map +1 -0
- package/dist/test/test.email.mailgun.d.ts +1 -0
- package/dist/test/test.email.mailgun.js +352 -0
- package/dist/test/test.email.mailgun.js.map +1 -0
- package/dist/test/test.email.postmark.d.ts +1 -0
- package/dist/test/test.email.postmark.js +316 -0
- package/dist/test/test.email.postmark.js.map +1 -0
- package/dist/test/test.email.sendgrid.d.ts +1 -0
- package/dist/test/test.email.sendgrid.js +365 -0
- package/dist/test/test.email.sendgrid.js.map +1 -0
- package/dist/test/test.email.smtp.d.ts +1 -0
- package/dist/test/test.email.smtp.js +323 -0
- package/dist/test/test.email.smtp.js.map +1 -0
- package/dist/test/test.graph.arangodb.d.ts +1 -0
- package/dist/test/test.graph.arangodb.js +358 -0
- package/dist/test/test.graph.arangodb.js.map +1 -0
- package/dist/test/test.graph.memgraph.d.ts +1 -0
- package/dist/test/test.graph.memgraph.js +320 -0
- package/dist/test/test.graph.memgraph.js.map +1 -0
- package/dist/test/test.graph.neo4j.d.ts +1 -0
- package/dist/test/test.graph.neo4j.js +218 -0
- package/dist/test/test.graph.neo4j.js.map +1 -0
- package/dist/test/test.graph.neptune.d.ts +1 -0
- package/dist/test/test.graph.neptune.js +331 -0
- package/dist/test/test.graph.neptune.js.map +1 -0
- package/dist/test/test.health.js +1 -0
- package/dist/test/test.health.js.map +1 -0
- package/dist/test/test.import.d.ts +0 -1
- package/dist/test/test.import.js +0 -1459
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.import.openapi.d.ts +0 -1
- package/dist/test/test.import.openapi.js +0 -75
- package/dist/test/test.import.openapi.js.map +1 -1
- package/dist/test/test.imports.js +14 -55
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.logs.d.ts +0 -1
- package/dist/test/test.logs.js +0 -17
- package/dist/test/test.logs.js.map +1 -1
- package/dist/test/test.notifications.d.ts +1 -0
- package/dist/test/test.notifications.js +198 -0
- package/dist/test/test.notifications.js.map +1 -0
- package/dist/test/test.notifiers.js +1 -0
- package/dist/test/test.notifiers.js.map +1 -0
- package/dist/test/test.processor.d.ts +0 -1
- package/dist/test/test.processor.js +0 -122
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.productBuilder.d.ts +0 -1
- package/dist/test/test.productBuilder.js +0 -660
- package/dist/test/test.productBuilder.js.map +1 -1
- package/dist/test/test.products.js +1 -0
- package/dist/test/test.products.js.map +1 -0
- package/dist/test/test.push.expo.d.ts +1 -0
- package/dist/test/test.push.expo.js +442 -0
- package/dist/test/test.push.expo.js.map +1 -0
- package/dist/test/test.push.firebase.d.ts +1 -0
- package/dist/test/test.push.firebase.js +409 -0
- package/dist/test/test.push.firebase.js.map +1 -0
- package/dist/test/test.session.d.ts +1 -0
- package/dist/test/test.session.js +299 -0
- package/dist/test/test.session.js.map +1 -0
- package/dist/test/test.sms.nexmo.d.ts +1 -0
- package/dist/test/test.sms.nexmo.js +278 -0
- package/dist/test/test.sms.nexmo.js.map +1 -0
- package/dist/test/test.sms.twilio.d.ts +1 -0
- package/dist/test/test.sms.twilio.js +275 -0
- package/dist/test/test.sms.twilio.js.map +1 -0
- package/dist/test/test.storage.d.ts +1 -0
- package/dist/test/test.storage.js +202 -0
- package/dist/test/test.storage.js.map +1 -0
- package/dist/test/test.triggers.d.ts +1 -0
- package/dist/test/test.triggers.js +314 -0
- package/dist/test/test.triggers.js.map +1 -0
- package/dist/test/test.vector.pinecone.d.ts +1 -0
- package/dist/test/test.vector.pinecone.js +238 -0
- package/dist/test/test.vector.pinecone.js.map +1 -0
- package/dist/test/test.vector.qdrant.d.ts +1 -0
- package/dist/test/test.vector.qdrant.js +307 -0
- package/dist/test/test.vector.qdrant.js.map +1 -0
- package/dist/test/test.vector.weaviate.d.ts +1 -0
- package/dist/test/test.vector.weaviate.js +325 -0
- package/dist/test/test.vector.weaviate.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +9 -2
- package/dist/types/enums.d.ts +11 -1
- package/dist/types/enums.js +10 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/index.types.d.ts +4 -7
- package/dist/types/index.types.js +0 -1
- package/dist/types/index.types.js.map +1 -1
- package/dist/types/inputs.types.js +1 -1
- package/dist/types/inputs.types.js.map +1 -1
- package/dist/types/pricing.types.d.ts +4 -0
- package/dist/types/pricing.types.js +3 -0
- package/dist/types/pricing.types.js.map +1 -0
- package/dist/types/processor.types.d.ts +214 -33
- package/dist/types/processor.types.js +9 -1
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +978 -23
- package/dist/types/productsBuilder.types.js +210 -3
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/types/request-tracker.interface.js +1 -0
- package/dist/types/request-tracker.interface.js.map +1 -0
- package/dist/types/requests.types.d.ts +2 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +24 -52
- package/dist/utils/index.js.map +1 -1
- package/dist/vector/actions/action-manager.d.ts +140 -0
- package/dist/vector/actions/action-manager.js +356 -0
- package/dist/vector/actions/action-manager.js.map +1 -0
- package/dist/vector/adapters/base.adapter.d.ts +169 -0
- package/dist/vector/adapters/base.adapter.js +218 -0
- package/dist/vector/adapters/base.adapter.js.map +1 -0
- package/dist/vector/adapters/index.d.ts +10 -0
- package/dist/vector/adapters/index.js +19 -0
- package/dist/vector/adapters/index.js.map +1 -0
- package/dist/vector/adapters/memory.adapter.d.ts +85 -0
- package/dist/vector/adapters/memory.adapter.js +505 -0
- package/dist/vector/adapters/memory.adapter.js.map +1 -0
- package/dist/vector/adapters/pinecone.adapter.d.ts +52 -0
- package/dist/vector/adapters/pinecone.adapter.js +433 -0
- package/dist/vector/adapters/pinecone.adapter.js.map +1 -0
- package/dist/vector/adapters/qdrant.adapter.d.ts +56 -0
- package/dist/vector/adapters/qdrant.adapter.js +442 -0
- package/dist/vector/adapters/qdrant.adapter.js.map +1 -0
- package/dist/vector/adapters/weaviate.adapter.d.ts +68 -0
- package/dist/vector/adapters/weaviate.adapter.js +645 -0
- package/dist/vector/adapters/weaviate.adapter.js.map +1 -0
- package/dist/vector/index.d.ts +36 -0
- package/dist/vector/index.js +70 -0
- package/dist/vector/index.js.map +1 -0
- package/dist/vector/types/action.interface.d.ts +195 -0
- package/dist/vector/types/action.interface.js +100 -0
- package/dist/vector/types/action.interface.js.map +1 -0
- package/dist/vector/types/connection.interface.d.ts +151 -0
- package/dist/vector/types/connection.interface.js +8 -0
- package/dist/vector/types/connection.interface.js.map +1 -0
- package/dist/vector/types/embedding.interface.d.ts +144 -0
- package/dist/vector/types/embedding.interface.js +8 -0
- package/dist/vector/types/embedding.interface.js.map +1 -0
- package/dist/vector/types/enums.d.ts +104 -0
- package/dist/vector/types/enums.js +113 -0
- package/dist/vector/types/enums.js.map +1 -0
- package/dist/vector/types/index.d.ts +11 -0
- package/dist/vector/types/index.js +23 -0
- package/dist/vector/types/index.js.map +1 -0
- package/dist/vector/types/vector.interface.d.ts +315 -0
- package/dist/vector/types/vector.interface.js +8 -0
- package/dist/vector/types/vector.interface.js.map +1 -0
- package/dist/vector/utils/index.d.ts +6 -0
- package/dist/vector/utils/index.js +11 -0
- package/dist/vector/utils/index.js.map +1 -0
- package/dist/vector/utils/vector-error.d.ts +69 -0
- package/dist/vector/utils/vector-error.js +116 -0
- package/dist/vector/utils/vector-error.js.map +1 -0
- package/dist/vector/vector-database.service.d.ts +474 -0
- package/dist/vector/vector-database.service.js +850 -0
- package/dist/vector/vector-database.service.js.map +1 -0
- package/dist/vector/vector.service.d.ts +283 -0
- package/dist/vector/vector.service.js +544 -0
- package/dist/vector/vector.service.js.map +1 -0
- package/dist/warehouse/executor/index.d.ts +5 -0
- package/dist/warehouse/executor/index.js +12 -0
- package/dist/warehouse/executor/index.js.map +1 -0
- package/dist/warehouse/executor/joins/index.d.ts +5 -0
- package/dist/warehouse/executor/joins/index.js +11 -0
- package/dist/warehouse/executor/joins/index.js.map +1 -0
- package/dist/warehouse/executor/joins/join-executor.d.ts +101 -0
- package/dist/warehouse/executor/joins/join-executor.js +493 -0
- package/dist/warehouse/executor/joins/join-executor.js.map +1 -0
- package/dist/warehouse/executor/joins/semantic-join.d.ts +64 -0
- package/dist/warehouse/executor/joins/semantic-join.js +241 -0
- package/dist/warehouse/executor/joins/semantic-join.js.map +1 -0
- package/dist/warehouse/executor/single-source-executor.d.ts +155 -0
- package/dist/warehouse/executor/single-source-executor.js +573 -0
- package/dist/warehouse/executor/single-source-executor.js.map +1 -0
- package/dist/warehouse/index.d.ts +79 -0
- package/dist/warehouse/index.js +111 -0
- package/dist/warehouse/index.js.map +1 -0
- package/dist/warehouse/parser/index.d.ts +4 -0
- package/dist/warehouse/parser/index.js +10 -0
- package/dist/warehouse/parser/index.js.map +1 -0
- package/dist/warehouse/parser/query-parser.d.ts +181 -0
- package/dist/warehouse/parser/query-parser.js +415 -0
- package/dist/warehouse/parser/query-parser.js.map +1 -0
- package/dist/warehouse/registry/data-source-registry.d.ts +207 -0
- package/dist/warehouse/registry/data-source-registry.js +396 -0
- package/dist/warehouse/registry/data-source-registry.js.map +1 -0
- package/dist/warehouse/registry/index.d.ts +4 -0
- package/dist/warehouse/registry/index.js +9 -0
- package/dist/warehouse/registry/index.js.map +1 -0
- package/dist/warehouse/transactions/index.d.ts +4 -0
- package/dist/warehouse/transactions/index.js +9 -0
- package/dist/warehouse/transactions/index.js.map +1 -0
- package/dist/warehouse/transactions/saga-orchestrator.d.ts +92 -0
- package/dist/warehouse/transactions/saga-orchestrator.js +383 -0
- package/dist/warehouse/transactions/saga-orchestrator.js.map +1 -0
- package/dist/warehouse/types/index.d.ts +9 -0
- package/dist/warehouse/types/index.js +33 -0
- package/dist/warehouse/types/index.js.map +1 -0
- package/dist/warehouse/types/join.interface.d.ts +225 -0
- package/dist/warehouse/types/join.interface.js +87 -0
- package/dist/warehouse/types/join.interface.js.map +1 -0
- package/dist/warehouse/types/query.interface.d.ts +232 -0
- package/dist/warehouse/types/query.interface.js +9 -0
- package/dist/warehouse/types/query.interface.js.map +1 -0
- package/dist/warehouse/types/transaction.interface.d.ts +236 -0
- package/dist/warehouse/types/transaction.interface.js +74 -0
- package/dist/warehouse/types/transaction.interface.js.map +1 -0
- package/dist/warehouse/types/where.interface.d.ts +208 -0
- package/dist/warehouse/types/where.interface.js +89 -0
- package/dist/warehouse/types/where.interface.js.map +1 -0
- package/dist/warehouse/warehouse.service.d.ts +200 -0
- package/dist/warehouse/warehouse.service.js +470 -0
- package/dist/warehouse/warehouse.service.js.map +1 -0
- package/dist/workflows/index.d.ts +30 -0
- package/dist/workflows/index.js +64 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/types/index.d.ts +6 -0
- package/dist/workflows/types/index.js +23 -0
- package/dist/workflows/types/index.js.map +1 -0
- package/dist/workflows/types/workflows.types.d.ts +1037 -0
- package/dist/workflows/types/workflows.types.js +13 -0
- package/dist/workflows/types/workflows.types.js.map +1 -0
- package/dist/workflows/workflow-builder.d.ts +70 -0
- package/dist/workflows/workflow-builder.js +338 -0
- package/dist/workflows/workflow-builder.js.map +1 -0
- package/dist/workflows/workflow-executor.d.ts +208 -0
- package/dist/workflows/workflow-executor.js +1194 -0
- package/dist/workflows/workflow-executor.js.map +1 -0
- package/dist/workflows/workflows.service.d.ts +410 -0
- package/dist/workflows/workflows.service.js +1724 -0
- package/dist/workflows/workflows.service.js.map +1 -0
- package/package.json +65 -12
- package/dist/actions/actions.repo.js +0 -13
- package/dist/actions/actions.repo.js.map +0 -1
- package/dist/actions/actions.service.js +0 -24
- package/dist/actions/actions.service.js.map +0 -1
- package/dist/actions/utils/actions.util.read.js +0 -427
- package/dist/actions/utils/actions.util.read.js.map +0 -1
- package/dist/api/services/integrationsApi.service.d.ts +0 -18
- package/dist/api/services/integrationsApi.service.js +0 -80
- package/dist/api/services/integrationsApi.service.js.map +0 -1
- package/dist/appBuilder/services/app.service.d.ts +0 -111
- package/dist/appBuilder/services/app.service.js +0 -737
- package/dist/appBuilder/services/app.service.js.map +0 -1
- package/dist/appBuilder/services/appBuilder.service.d.ts +0 -111
- package/dist/appBuilder/services/appBuilder.service.js +0 -662
- package/dist/appBuilder/services/appBuilder.service.js.map +0 -1
- package/dist/appBuilder/utils/objects.utils.d.ts +0 -3
- package/dist/appBuilder/utils/objects.utils.js +0 -9
- package/dist/appBuilder/utils/objects.utils.js.map +0 -1
- package/dist/appBuilder/utils/string.utils.d.ts +0 -2
- package/dist/appBuilder/utils/string.utils.js +0 -57
- package/dist/appBuilder/utils/string.utils.js.map +0 -1
- package/dist/appBuilder/validators/index.d.ts +0 -19
- package/dist/appBuilder/validators/index.js +0 -40
- package/dist/appBuilder/validators/index.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.app.validator.js +0 -10
- package/dist/appBuilder/validators/joi-validators/create.app.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js +0 -20
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.d.ts +0 -7
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js +0 -44
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js +0 -31
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js +0 -11
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js +0 -12
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js +0 -17
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.d.ts +0 -5
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js +0 -30
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js +0 -14
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/sample.validator.d.ts +0 -5
- package/dist/appBuilder/validators/joi-validators/sample.validator.js +0 -26
- package/dist/appBuilder/validators/joi-validators/sample.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.app.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.app.validator.js +0 -34
- package/dist/appBuilder/validators/joi-validators/update.app.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js +0 -23
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js +0 -21
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js +0 -19
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js +0 -12
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js +0 -17
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js +0 -16
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js +0 -14
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js +0 -27
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js.map +0 -1
- package/dist/apps/validators/joi-validators/create.appEvent.validator.d.ts +0 -5
- package/dist/apps/validators/joi-validators/create.appEvent.validator.js +0 -30
- package/dist/apps/validators/joi-validators/create.appEvent.validator.js.map +0 -1
- package/dist/apps/validators/joi-validators/update.appEvent.validator.d.ts +0 -4
- package/dist/apps/validators/joi-validators/update.appEvent.validator.js +0 -16
- package/dist/apps/validators/joi-validators/update.appEvent.validator.js.map +0 -1
- package/dist/clients/integrations.client.d.ts +0 -2
- package/dist/clients/integrations.client.js +0 -26
- package/dist/clients/integrations.client.js.map +0 -1
- package/dist/integrationsBuilder/services/integration.service.d.ts +0 -138
- package/dist/integrationsBuilder/services/integration.service.js +0 -1148
- package/dist/integrationsBuilder/services/integration.service.js.map +0 -1
- package/dist/integrationsBuilder/services/integrationBuilder.service.d.ts +0 -130
- package/dist/integrationsBuilder/services/integrationBuilder.service.js +0 -1017
- package/dist/integrationsBuilder/services/integrationBuilder.service.js.map +0 -1
- package/dist/integrationsBuilder/utils/objects.utils.d.ts +0 -2
- package/dist/integrationsBuilder/utils/objects.utils.js +0 -48
- package/dist/integrationsBuilder/utils/objects.utils.js.map +0 -1
- package/dist/integrationsBuilder/utils/string.utils.d.ts +0 -1
- package/dist/integrationsBuilder/utils/string.utils.js +0 -9
- package/dist/integrationsBuilder/utils/string.utils.js.map +0 -1
- package/dist/integrationsBuilder/validators/index.d.ts +0 -18
- package/dist/integrationsBuilder/validators/index.js +0 -38
- package/dist/integrationsBuilder/validators/index.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.d.ts +0 -4
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js +0 -26
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js +0 -60
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js +0 -9
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js.map +0 -1
- package/dist/postman.d.ts +0 -1
- package/dist/postman.js +0 -21674
- package/dist/postman.js.map +0 -1
- package/dist/processor/utils/mongo.util.js +0 -152
- package/dist/processor/utils/mongo.util.js.map +0 -1
- package/dist/processor/utils/postgres.util.d.ts +0 -14
- package/dist/processor/utils/postgres.util.js +0 -83
- package/dist/processor/utils/postgres.util.js.map +0 -1
- package/dist/products/validators/joi-validators/create.product.validator.d.ts +0 -3
- package/dist/products/validators/joi-validators/create.product.validator.js +0 -10
- package/dist/products/validators/joi-validators/create.product.validator.js.map +0 -1
- package/dist/test.appBuilder.js +0 -14
- package/dist/test.appBuilder.js.map +0 -1
- package/dist/test.import.js +0 -24
- package/dist/test.import.js.map +0 -1
- package/dist/test.imports.js +0 -28
- package/dist/test.imports.js.map +0 -1
- package/dist/test.integrationBuilder.js +0 -276
- package/dist/test.integrationBuilder.js.map +0 -1
- package/dist/test.processor.js +0 -23
- package/dist/test.processor.js.map +0 -1
- package/dist/test.utils.js +0 -25
- package/dist/test.utils.js.map +0 -1
- package/dist/types/integrationsBuilder.types.d.ts +0 -276
- package/dist/types/integrationsBuilder.types.js +0 -51
- package/dist/types/integrationsBuilder.types.js.map +0 -1
- /package/dist/{actions/actions.repo.d.ts → pricing/pricing.repo.d.ts} +0 -0
- /package/dist/{appBuilder/validators/joi-validators/create.app.validator.d.ts → products/validators/joi-validators/create.productGraph.validator.d.ts} +0 -0
- /package/dist/{appBuilder/validators/joi-validators/update.validation.entityData.validator.d.ts → products/validators/joi-validators/update.productGraph.validator.d.ts} +0 -0
- /package/dist/{test.appBuilder.d.ts → test/test.broker.kafka.d.ts} +0 -0
- /package/dist/{test.imports.d.ts → test/test.broker.nats.d.ts} +0 -0
- /package/dist/{test.integrationBuilder.d.ts → test/test.broker.pubsub.d.ts} +0 -0
- /package/dist/{test.processor.d.ts → test/test.broker.rabbitmq.d.ts} +0 -0
- /package/dist/{test.utils.d.ts → test/test.broker.redis.d.ts} +0 -0
- /package/dist/{actions/actions.service.d.ts → test/test.health.d.ts} +0 -0
- /package/dist/{actions/utils/actions.util.read.d.ts → test/test.notifiers.d.ts} +0 -0
- /package/dist/{processor/utils/mongo.util.d.ts → test/test.products.d.ts} +0 -0
- /package/dist/{test.import.d.ts → types/request-tracker.interface.d.ts} +0 -0
|
@@ -36,17 +36,20 @@ const update_productDatabaseMigration_validator_1 = __importDefault(require("../
|
|
|
36
36
|
const create_productNotificationMessage_validator_1 = __importDefault(require("../validators/joi-validators/create.productNotificationMessage.validator"));
|
|
37
37
|
const create_productMessageBrokerTopic_validator_1 = __importDefault(require("../validators/joi-validators/create.productMessageBrokerTopic.validator"));
|
|
38
38
|
const update_productMessageBrokerTopic_validator_1 = __importDefault(require("../validators/joi-validators/update.productMessageBrokerTopic.validator"));
|
|
39
|
+
const secrets_1 = require("../../secrets");
|
|
39
40
|
const update_productNotificationMessage_validator_1 = __importDefault(require("../validators/joi-validators/update.productNotificationMessage.validator"));
|
|
40
41
|
const create_productNotification_validator_1 = require("../validators/joi-validators/create.productNotification.validator");
|
|
41
42
|
const functions_utils_1 = require("../utils/functions.utils");
|
|
42
43
|
const objects_utils_2 = require("../../apps/utils/objects.utils");
|
|
43
44
|
const webhooksApi_service_1 = require("../../api/services/webhooksApi.service");
|
|
44
45
|
class ProductsBuilderService {
|
|
45
|
-
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
|
|
46
|
+
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client, queues, access_key }) {
|
|
47
|
+
this.workspace_private_key = null;
|
|
46
48
|
this.workspace_id = workspace_id;
|
|
47
49
|
this.public_key = public_key;
|
|
48
50
|
this.user_id = user_id;
|
|
49
51
|
this.token = token;
|
|
52
|
+
this.access_key = access_key || null;
|
|
50
53
|
this.userApi = new userApi_service_1.UserApiService(env_type, redis_client);
|
|
51
54
|
this.productApi = new productsApi_service_1.ProductsApiService(env_type, redis_client);
|
|
52
55
|
this.workspaceApi = new workspaceApi_service_1.WorkspaceApiService(env_type, redis_client);
|
|
@@ -54,6 +57,150 @@ class ProductsBuilderService {
|
|
|
54
57
|
this.appApi = new appApi_service_1.AppApiService(env_type, redis_client);
|
|
55
58
|
this.inputsService = new inputs_service_1.default();
|
|
56
59
|
this.thirdPartyApps = [];
|
|
60
|
+
if (redis_client) {
|
|
61
|
+
this.redisClient = redis_client;
|
|
62
|
+
// Start healthcheck workers automatically
|
|
63
|
+
//this.startHealthcheckWorkers();
|
|
64
|
+
}
|
|
65
|
+
if (queues) {
|
|
66
|
+
this.queues = queues;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
fetchPrivateKey() {
|
|
70
|
+
return this.product.private_key;
|
|
71
|
+
}
|
|
72
|
+
fetchWorkspaceId() {
|
|
73
|
+
return this.product.workspace_id;
|
|
74
|
+
}
|
|
75
|
+
fetchProductId() {
|
|
76
|
+
return this.product._id;
|
|
77
|
+
}
|
|
78
|
+
async createHealthcheck(data) {
|
|
79
|
+
try {
|
|
80
|
+
await validators_1.CreateProductHealthcheckSchema.validateAsync(data);
|
|
81
|
+
if (!data.tag) {
|
|
82
|
+
throw new Error('tag field is required');
|
|
83
|
+
}
|
|
84
|
+
const exists = await this.fetchHealthcheck(data.app, data.tag);
|
|
85
|
+
if (!exists) {
|
|
86
|
+
const { app: access_tag, event: action } = data;
|
|
87
|
+
const app = await this.fetchThirdPartyAppByAccessTag(access_tag);
|
|
88
|
+
const version = app.versions.find((data) => data.tag === app.version);
|
|
89
|
+
if (!version) {
|
|
90
|
+
throw new Error(`Version ${app.version} not found`);
|
|
91
|
+
}
|
|
92
|
+
const event = version.actions.find((act) => act.tag === action);
|
|
93
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
94
|
+
const exists = await this.fetchEnv(env.slug);
|
|
95
|
+
if (!exists) {
|
|
96
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
97
|
+
}
|
|
98
|
+
await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
|
|
99
|
+
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.product.private_key);
|
|
100
|
+
console.log('INPUT', env);
|
|
101
|
+
return env;
|
|
102
|
+
}));
|
|
103
|
+
const envs = await this.fetchEnvs();
|
|
104
|
+
console.log('ENVS ===>>>>', envs);
|
|
105
|
+
console.log('DBENVS ====>>>>', data.envs);
|
|
106
|
+
envs.map((env) => {
|
|
107
|
+
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
108
|
+
if (exists === -1) {
|
|
109
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide details`);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
console.log('UPDATING VALUE', data);
|
|
113
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { action: enums_1.RequestAction.CREATE, component: enums_1.ProductComponents.HEALTHCHECK }), this.getUserAccess());
|
|
114
|
+
data.envs.map(async (env) => {
|
|
115
|
+
const payload = {
|
|
116
|
+
app: data.app,
|
|
117
|
+
action: data.event,
|
|
118
|
+
input: env.input,
|
|
119
|
+
env: env.slug,
|
|
120
|
+
product: this.product.tag,
|
|
121
|
+
retries: data.retries,
|
|
122
|
+
};
|
|
123
|
+
const jobId = `healthcheck-${data.tag}`;
|
|
124
|
+
const job = await this.queues.health.getJob(jobId);
|
|
125
|
+
if (job) {
|
|
126
|
+
await job.remove();
|
|
127
|
+
}
|
|
128
|
+
await this.queues.health.add(jobId, payload, { jobId, repeat: { every: data.interval } });
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
console.log(e);
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async updateHealthcheck(tag, data) {
|
|
138
|
+
try {
|
|
139
|
+
// 1. Fetch the existing healthcheck
|
|
140
|
+
const healthcheck = await this.fetchHealthcheck(data.app, tag);
|
|
141
|
+
if (!healthcheck) {
|
|
142
|
+
throw new Error(`Healthcheck with tag: ${tag} not found`);
|
|
143
|
+
}
|
|
144
|
+
// 2. Validate the incoming data
|
|
145
|
+
await validators_1.CreateProductHealthcheckSchema.validateAsync(data); // No Update schema, use Create
|
|
146
|
+
// 3. Check for tag conflicts
|
|
147
|
+
if (data.tag && data.tag !== tag && (await this.fetchHealthcheck(data.app, data.tag))) {
|
|
148
|
+
throw new Error(`Healthcheck with tag ${data.tag} already exists`);
|
|
149
|
+
}
|
|
150
|
+
// 4. Validate and process envs
|
|
151
|
+
if (data.envs) {
|
|
152
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
153
|
+
const exists = await this.fetchEnv(env.slug);
|
|
154
|
+
if (!exists) {
|
|
155
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
156
|
+
}
|
|
157
|
+
// Validate input if present
|
|
158
|
+
if (env.input) {
|
|
159
|
+
const app = await this.fetchThirdPartyAppByAccessTag(data.app);
|
|
160
|
+
const version = app.versions.find((v) => v.tag === app.version);
|
|
161
|
+
if (!version) {
|
|
162
|
+
throw new Error(`Version ${app.version} not found`);
|
|
163
|
+
}
|
|
164
|
+
const event = version.actions.find((act) => act.tag === data.event);
|
|
165
|
+
await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
|
|
166
|
+
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.product.private_key);
|
|
167
|
+
}
|
|
168
|
+
return env;
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
// 5. Ensure all product envs are covered
|
|
172
|
+
const envs = await this.fetchEnvs();
|
|
173
|
+
envs.map((env) => {
|
|
174
|
+
var _a;
|
|
175
|
+
const exists = (_a = data.envs) === null || _a === void 0 ? void 0 : _a.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
176
|
+
if (exists === -1) {
|
|
177
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide details`);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
// 6. Update the healthcheck
|
|
181
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, healthcheck), data), { tag, component: enums_1.ProductComponents.HEALTHCHECK, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
throw e;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async fetchHealthcheck(access_tag, tag, throwError = false) {
|
|
188
|
+
const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
|
|
189
|
+
const health = healthchecks.find((data) => data.tag === tag && data.app === access_tag);
|
|
190
|
+
if (!health && throwError)
|
|
191
|
+
throw new Error(`Healthcheck ${tag} not found`);
|
|
192
|
+
return health || null;
|
|
193
|
+
}
|
|
194
|
+
async fetchHealthchecks(access_tag, throwError = false) {
|
|
195
|
+
const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
|
|
196
|
+
const health = healthchecks.filter((data) => data.app === access_tag);
|
|
197
|
+
if (!health && throwError)
|
|
198
|
+
throw new Error(`Access tag ${access_tag} not found`);
|
|
199
|
+
return health;
|
|
200
|
+
}
|
|
201
|
+
async fetchProductHealthchecks() {
|
|
202
|
+
const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
|
|
203
|
+
return healthchecks;
|
|
57
204
|
}
|
|
58
205
|
async updateDataValidation(selector, update) {
|
|
59
206
|
if (!selector.startsWith('$Data{') && !selector.startsWith('$Filter')) {
|
|
@@ -68,26 +215,27 @@ class ProductsBuilderService {
|
|
|
68
215
|
if (stages.length < 3) {
|
|
69
216
|
throw new Error(`Invalid selector ${selector}`);
|
|
70
217
|
}
|
|
71
|
-
const tag = stages[0];
|
|
72
|
-
const type = stages[1];
|
|
218
|
+
const tag = String(stages[0]);
|
|
219
|
+
const type = String(stages[1]);
|
|
73
220
|
let size = 2;
|
|
74
221
|
let data;
|
|
75
222
|
switch (type) {
|
|
76
223
|
case productsBuilder_types_1.FeatureEventTypes.DB_ACTION:
|
|
77
|
-
const action = this.fetchDatabaseAction(tag);
|
|
224
|
+
const action = await this.fetchDatabaseAction(tag);
|
|
78
225
|
if (!action)
|
|
79
226
|
throw new Error(`DB Action ${tag} not found`);
|
|
80
227
|
data = useData ? action.data : action.filterData;
|
|
81
228
|
break;
|
|
82
229
|
case productsBuilder_types_1.FeatureEventTypes.NOTIFICATION:
|
|
83
230
|
size = 3;
|
|
84
|
-
|
|
85
|
-
|
|
231
|
+
const stage3Str = String(stages[3]);
|
|
232
|
+
if (!stages[3] || (stage3Str !== 'push' && stage3Str !== 'callback' && stage3Str !== 'email')) {
|
|
233
|
+
throw new Error(`Invalid value ${stage3Str} in ${selector}, expected to be "push", "callback" or "email" in notification`);
|
|
86
234
|
}
|
|
87
|
-
const notification = this.fetchNotificationMessage(tag);
|
|
235
|
+
const notification = await this.fetchNotificationMessage(tag);
|
|
88
236
|
if (!notification)
|
|
89
237
|
throw new Error(`Notification ${tag} not found`);
|
|
90
|
-
if (
|
|
238
|
+
if (stage3Str === 'push') {
|
|
91
239
|
data = notification.push_notification_data;
|
|
92
240
|
}
|
|
93
241
|
if (stages[3] === 'callback') {
|
|
@@ -129,11 +277,11 @@ class ProductsBuilderService {
|
|
|
129
277
|
await validators_1.CreateProductBuilderSchema.validateAsync(data);
|
|
130
278
|
const exists = await this.checkIfProductExists(data.name);
|
|
131
279
|
if (exists && (exists === null || exists === void 0 ? void 0 : exists._id)) {
|
|
132
|
-
await this.initializeProduct(exists
|
|
280
|
+
// await this.initializeProduct(exists?._id);
|
|
133
281
|
}
|
|
134
282
|
else {
|
|
135
283
|
const product = await this.createNewProduct(data);
|
|
136
|
-
await this.initializeProduct(product._id);
|
|
284
|
+
// await this.initializeProduct(product._id);
|
|
137
285
|
}
|
|
138
286
|
}
|
|
139
287
|
catch (e) {
|
|
@@ -144,10 +292,26 @@ class ProductsBuilderService {
|
|
|
144
292
|
if (!this.workspace) {
|
|
145
293
|
this.workspace = await this.workspaceApi.fetchWorkspaceById(this.getUserAccess(), subCheck);
|
|
146
294
|
}
|
|
295
|
+
// Fetch workspace private key using the dedicated endpoint for secrets encryption
|
|
296
|
+
if (!this.workspace_private_key && this.access_key) {
|
|
297
|
+
try {
|
|
298
|
+
this.workspace_private_key = await this.workspaceApi.fetchPrivateKey(this.getUserAccess(), this.access_key);
|
|
299
|
+
}
|
|
300
|
+
catch (e) {
|
|
301
|
+
console.warn('[ProductsBuilderService] Failed to fetch workspace private key:', e);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Get the workspace private key for secrets encryption
|
|
307
|
+
* @returns The workspace private key or null if not available
|
|
308
|
+
*/
|
|
309
|
+
getWorkspacePrivateKey() {
|
|
310
|
+
return this.workspace_private_key;
|
|
147
311
|
}
|
|
148
312
|
async initializeProduct(product_id) {
|
|
149
313
|
try {
|
|
150
|
-
this.product = await this.productApi.
|
|
314
|
+
this.product = (await this.productApi.initProduct(product_id, this.getUserAccess()));
|
|
151
315
|
this.product_id = product_id;
|
|
152
316
|
}
|
|
153
317
|
catch (e) {
|
|
@@ -156,20 +320,64 @@ class ProductsBuilderService {
|
|
|
156
320
|
}
|
|
157
321
|
async initializeProductByTag(tag) {
|
|
158
322
|
try {
|
|
159
|
-
this.product = await this.productApi.
|
|
323
|
+
this.product = (await this.productApi.initProduct(tag, this.getUserAccess()));
|
|
324
|
+
if (!this.product) {
|
|
325
|
+
throw new Error(`Product with tag "${tag}" not found or failed to fetch`);
|
|
326
|
+
}
|
|
160
327
|
this.product_id = this.product._id;
|
|
161
328
|
}
|
|
162
329
|
catch (e) {
|
|
163
330
|
throw e;
|
|
164
331
|
}
|
|
165
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Bootstrap action - ultra-lightweight API call to fetch action data needed for processAction
|
|
335
|
+
* Replaces 5+ separate API calls: initializeProduct, fetchApp, fetchThirdPartyApp, fetchEnv, initializePricing
|
|
336
|
+
* Returns only the minimal action data needed to execute
|
|
337
|
+
*/
|
|
338
|
+
async bootstrapAction(params) {
|
|
339
|
+
try {
|
|
340
|
+
const result = await this.productApi.bootstrapAction(params, this.getUserAccess());
|
|
341
|
+
// Initialize minimal product data
|
|
342
|
+
if (result.product_id) {
|
|
343
|
+
this.product_id = result.product_id;
|
|
344
|
+
}
|
|
345
|
+
return result;
|
|
346
|
+
}
|
|
347
|
+
catch (e) {
|
|
348
|
+
throw e;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async bootstrapNotification(params) {
|
|
352
|
+
try {
|
|
353
|
+
const result = await this.productApi.bootstrapNotification(params, this.getUserAccess());
|
|
354
|
+
if (result.product_id) {
|
|
355
|
+
this.product_id = result.product_id;
|
|
356
|
+
}
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
catch (e) {
|
|
360
|
+
throw e;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async bootstrapStorage(params) {
|
|
364
|
+
try {
|
|
365
|
+
const result = await this.productApi.bootstrapStorage(params, this.getUserAccess());
|
|
366
|
+
if (result.product_id) {
|
|
367
|
+
this.product_id = result.product_id;
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
catch (e) {
|
|
372
|
+
throw e;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
166
375
|
async updateProduct(data) {
|
|
167
376
|
try {
|
|
168
377
|
if (!this.app_id)
|
|
169
378
|
throw new Error('Product not initialized');
|
|
170
379
|
await validators_1.CreateProductBuilderSchema.validateAsync(data);
|
|
171
380
|
await this.productApi.updateProduct(this.product_id, Object.assign({}, data), this.getUserAccess());
|
|
172
|
-
await this.initializeProduct(this.product_id);
|
|
173
381
|
}
|
|
174
382
|
catch (e) {
|
|
175
383
|
throw e;
|
|
@@ -186,11 +394,11 @@ class ProductsBuilderService {
|
|
|
186
394
|
return false;
|
|
187
395
|
}
|
|
188
396
|
}
|
|
189
|
-
fetchProduct() {
|
|
397
|
+
async fetchProduct() {
|
|
190
398
|
if (!this.product) {
|
|
191
399
|
throw new Error('Product not yet initiated');
|
|
192
400
|
}
|
|
193
|
-
return this.product;
|
|
401
|
+
return await this.productApi.fetchProductByTag(this.product.tag, this.getUserAccess());
|
|
194
402
|
}
|
|
195
403
|
async createSession(data, throwErrorIfExists = false) {
|
|
196
404
|
try {
|
|
@@ -198,7 +406,7 @@ class ProductsBuilderService {
|
|
|
198
406
|
if (!data.tag) {
|
|
199
407
|
throw new Error('tag field is required');
|
|
200
408
|
}
|
|
201
|
-
const exists = this.fetchSession(data.tag);
|
|
409
|
+
const exists = await this.fetchSession(data.tag);
|
|
202
410
|
if (!exists) {
|
|
203
411
|
if (!data.selector.startsWith('$Session{')) {
|
|
204
412
|
throw new Error('Selector should be in the format $Session{...}{key}');
|
|
@@ -213,19 +421,16 @@ class ProductsBuilderService {
|
|
|
213
421
|
throw new Error(`${data.selector} not found in event sample`);
|
|
214
422
|
}
|
|
215
423
|
}
|
|
216
|
-
if (current === null ||
|
|
217
|
-
|
|
218
|
-
typeof current === "object") {
|
|
219
|
-
throw new Error("Selector value is not allowed to be an object|array|null|undefined");
|
|
424
|
+
if (current === null || typeof current === 'undefined' || typeof current === 'object') {
|
|
425
|
+
throw new Error('Selector value is not allowed to be an object|array|null|undefined');
|
|
220
426
|
}
|
|
221
|
-
data.schema_data = await this.inputsService.parseJson({
|
|
427
|
+
data.schema_data = (await this.inputsService.parseJson({
|
|
222
428
|
data: data.schema,
|
|
223
|
-
expected: inputs_types_1.ExpectedValues.PARSESAMPLE
|
|
224
|
-
});
|
|
429
|
+
expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
|
|
430
|
+
}));
|
|
225
431
|
data.selectorValue = current;
|
|
226
432
|
const payload = Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE });
|
|
227
433
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
228
|
-
await this.initializeProduct(this.product_id);
|
|
229
434
|
}
|
|
230
435
|
else {
|
|
231
436
|
if (throwErrorIfExists)
|
|
@@ -238,7 +443,7 @@ class ProductsBuilderService {
|
|
|
238
443
|
}
|
|
239
444
|
async updateSession(tag, data) {
|
|
240
445
|
try {
|
|
241
|
-
const session = this.fetchSession(tag);
|
|
446
|
+
const session = await this.fetchSession(tag);
|
|
242
447
|
if (!session) {
|
|
243
448
|
throw new Error(`Session with tag: ${tag} not found`);
|
|
244
449
|
}
|
|
@@ -271,25 +476,39 @@ class ProductsBuilderService {
|
|
|
271
476
|
throw new Error(`${data.selector} not found in event sample`);
|
|
272
477
|
}
|
|
273
478
|
}
|
|
274
|
-
if (current === null ||
|
|
275
|
-
|
|
276
|
-
typeof current === "object") {
|
|
277
|
-
throw new Error("Selector value is not allowed to be an object|array|null|undefined");
|
|
479
|
+
if (current === null || typeof current === 'undefined' || typeof current === 'object') {
|
|
480
|
+
throw new Error('Selector value is not allowed to be an object|array|null|undefined');
|
|
278
481
|
}
|
|
279
482
|
}
|
|
280
483
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, session), data)), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
281
|
-
await this.initializeProduct(this.product_id);
|
|
282
484
|
}
|
|
283
485
|
catch (e) {
|
|
284
486
|
throw e;
|
|
285
487
|
}
|
|
286
488
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return
|
|
489
|
+
async fetchSessions(version) {
|
|
490
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'session', this.getUserAccess());
|
|
491
|
+
return components;
|
|
492
|
+
}
|
|
493
|
+
async fetchSession(tag) {
|
|
494
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'session', tag, this.getUserAccess());
|
|
495
|
+
return component;
|
|
290
496
|
}
|
|
291
|
-
|
|
292
|
-
|
|
497
|
+
async deleteSession(tag) {
|
|
498
|
+
try {
|
|
499
|
+
const session = await this.fetchSession(tag);
|
|
500
|
+
if (!session) {
|
|
501
|
+
throw new Error(`Session with tag: ${tag} not found`);
|
|
502
|
+
}
|
|
503
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
504
|
+
tag,
|
|
505
|
+
component: enums_1.ProductComponents.SESSION,
|
|
506
|
+
action: enums_1.RequestAction.DELETE,
|
|
507
|
+
}, this.getUserAccess());
|
|
508
|
+
}
|
|
509
|
+
catch (e) {
|
|
510
|
+
throw e;
|
|
511
|
+
}
|
|
293
512
|
}
|
|
294
513
|
async createMessageBrokerTopic(data, throwErrorIfExists = false) {
|
|
295
514
|
try {
|
|
@@ -303,16 +522,17 @@ class ProductsBuilderService {
|
|
|
303
522
|
if (data.sample)
|
|
304
523
|
data.sample = JSON.stringify(data.sample);
|
|
305
524
|
await create_productMessageBrokerTopic_validator_1.default.validateAsync(data);
|
|
306
|
-
const exists = this.fetchMessageBrokerTopic(data.tag);
|
|
307
|
-
const broker = this.fetchMessageBroker(messageBrokerTag);
|
|
308
|
-
|
|
525
|
+
const exists = await this.fetchMessageBrokerTopic(data.tag);
|
|
526
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
527
|
+
if (broker) {
|
|
528
|
+
(0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
|
|
529
|
+
}
|
|
309
530
|
data.tag = tag;
|
|
310
531
|
if (!exists) {
|
|
311
532
|
if (data.sample) {
|
|
312
533
|
data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
|
|
313
534
|
}
|
|
314
535
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_TOPIC, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
315
|
-
await this.initializeProduct(this.product_id);
|
|
316
536
|
}
|
|
317
537
|
else {
|
|
318
538
|
if (throwErrorIfExists)
|
|
@@ -335,12 +555,12 @@ class ProductsBuilderService {
|
|
|
335
555
|
if (!messageBrokerTag || !tag) {
|
|
336
556
|
throw new Error(`tag is expected to be defined as "messageBrokr_tag:topic_tag"`);
|
|
337
557
|
}
|
|
338
|
-
const exists = this.fetchMessageBrokerTopic(data.tag);
|
|
558
|
+
const exists = await this.fetchMessageBrokerTopic(data.tag);
|
|
339
559
|
if (!exists) {
|
|
340
560
|
throw new Error(`Topic ${data.tag} not found`);
|
|
341
561
|
}
|
|
342
|
-
const broker = this.fetchMessageBroker(messageBrokerTag);
|
|
343
|
-
if (data.queueUrls) {
|
|
562
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
563
|
+
if (data.queueUrls && broker) {
|
|
344
564
|
(0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
|
|
345
565
|
}
|
|
346
566
|
data.tag = tag;
|
|
@@ -349,7 +569,6 @@ class ProductsBuilderService {
|
|
|
349
569
|
data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
|
|
350
570
|
}
|
|
351
571
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_TOPIC, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
352
|
-
await this.initializeProduct(this.product_id);
|
|
353
572
|
}
|
|
354
573
|
else {
|
|
355
574
|
throw new Error(`Message Broker Topic ${data.tag} not found`);
|
|
@@ -359,7 +578,7 @@ class ProductsBuilderService {
|
|
|
359
578
|
throw e;
|
|
360
579
|
}
|
|
361
580
|
}
|
|
362
|
-
fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
|
|
581
|
+
async fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
|
|
363
582
|
const [messageBrokerTag, topicTag] = tag.split(':');
|
|
364
583
|
if (!messageBrokerTag || !topicTag) {
|
|
365
584
|
throw new Error(`tag is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
@@ -372,12 +591,140 @@ class ProductsBuilderService {
|
|
|
372
591
|
throw new Error(`MessageBroker topic ${tag} not found`);
|
|
373
592
|
return topic;
|
|
374
593
|
}
|
|
375
|
-
fetchMessageBrokerTopics(messageBrokerTag) {
|
|
594
|
+
async fetchMessageBrokerTopics(messageBrokerTag) {
|
|
376
595
|
const messageBroker = this.product.messageBrokers.find((data) => data.tag === messageBrokerTag);
|
|
377
596
|
if (!messageBroker)
|
|
378
597
|
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
379
598
|
return messageBroker.topics;
|
|
380
599
|
}
|
|
600
|
+
// ==================== MESSAGE BROKER PRODUCERS ====================
|
|
601
|
+
async createMessageBrokerProducer(data) {
|
|
602
|
+
var _a, _b;
|
|
603
|
+
try {
|
|
604
|
+
const [messageBrokerTag, topicTag] = data.topic.split(':');
|
|
605
|
+
if (!messageBrokerTag || !topicTag) {
|
|
606
|
+
throw new Error(`topic is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
607
|
+
}
|
|
608
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
609
|
+
if (!broker) {
|
|
610
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
611
|
+
}
|
|
612
|
+
// Check if topic exists
|
|
613
|
+
const topic = (_a = broker.topics) === null || _a === void 0 ? void 0 : _a.find((t) => t.tag === topicTag);
|
|
614
|
+
if (!topic) {
|
|
615
|
+
throw new Error(`Topic ${topicTag} not found in broker ${messageBrokerTag}`);
|
|
616
|
+
}
|
|
617
|
+
// Check if producer already exists
|
|
618
|
+
const existingProducer = (_b = broker.producers) === null || _b === void 0 ? void 0 : _b.find((p) => p.tag === data.tag);
|
|
619
|
+
if (existingProducer) {
|
|
620
|
+
throw new Error(`Producer ${data.tag} already exists in broker ${messageBrokerTag}`);
|
|
621
|
+
}
|
|
622
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_PRODUCER, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
623
|
+
}
|
|
624
|
+
catch (e) {
|
|
625
|
+
throw e;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
async updateMessageBrokerProducer(data) {
|
|
629
|
+
var _a;
|
|
630
|
+
try {
|
|
631
|
+
const [messageBrokerTag, topicTag] = data.topic.split(':');
|
|
632
|
+
if (!messageBrokerTag || !topicTag) {
|
|
633
|
+
throw new Error(`topic is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
634
|
+
}
|
|
635
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
636
|
+
if (!broker) {
|
|
637
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
638
|
+
}
|
|
639
|
+
// Check if producer exists
|
|
640
|
+
const existingProducer = (_a = broker.producers) === null || _a === void 0 ? void 0 : _a.find((p) => p.tag === data.tag);
|
|
641
|
+
if (!existingProducer) {
|
|
642
|
+
throw new Error(`Producer ${data.tag} not found in broker ${messageBrokerTag}`);
|
|
643
|
+
}
|
|
644
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_PRODUCER, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
645
|
+
}
|
|
646
|
+
catch (e) {
|
|
647
|
+
throw e;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
async fetchMessageBrokerProducer(brokerTag, tag) {
|
|
651
|
+
var _a;
|
|
652
|
+
const messageBroker = this.product.messageBrokers.find((data) => data.tag === brokerTag);
|
|
653
|
+
if (!messageBroker)
|
|
654
|
+
throw new Error(`MessageBroker ${brokerTag} not found`);
|
|
655
|
+
const producer = (_a = messageBroker.producers) === null || _a === void 0 ? void 0 : _a.find((p) => p.tag === tag);
|
|
656
|
+
return producer || null;
|
|
657
|
+
}
|
|
658
|
+
async fetchMessageBrokerProducers(messageBrokerTag) {
|
|
659
|
+
const messageBroker = this.product.messageBrokers.find((data) => data.tag === messageBrokerTag);
|
|
660
|
+
if (!messageBroker)
|
|
661
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
662
|
+
return messageBroker.producers || [];
|
|
663
|
+
}
|
|
664
|
+
// ==================== MESSAGE BROKER CONSUMERS ====================
|
|
665
|
+
async createMessageBrokerConsumer(data) {
|
|
666
|
+
var _a, _b;
|
|
667
|
+
try {
|
|
668
|
+
const [messageBrokerTag, topicTag] = data.topic.split(':');
|
|
669
|
+
if (!messageBrokerTag || !topicTag) {
|
|
670
|
+
throw new Error(`topic is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
671
|
+
}
|
|
672
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
673
|
+
if (!broker) {
|
|
674
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
675
|
+
}
|
|
676
|
+
// Check if topic exists
|
|
677
|
+
const topic = (_a = broker.topics) === null || _a === void 0 ? void 0 : _a.find((t) => t.tag === topicTag);
|
|
678
|
+
if (!topic) {
|
|
679
|
+
throw new Error(`Topic ${topicTag} not found in broker ${messageBrokerTag}`);
|
|
680
|
+
}
|
|
681
|
+
// Check if consumer already exists
|
|
682
|
+
const existingConsumer = (_b = broker.consumers) === null || _b === void 0 ? void 0 : _b.find((c) => c.tag === data.tag);
|
|
683
|
+
if (existingConsumer) {
|
|
684
|
+
throw new Error(`Consumer ${data.tag} already exists in broker ${messageBrokerTag}`);
|
|
685
|
+
}
|
|
686
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_CONSUMER, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
687
|
+
}
|
|
688
|
+
catch (e) {
|
|
689
|
+
throw e;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
async updateMessageBrokerConsumer(data) {
|
|
693
|
+
var _a;
|
|
694
|
+
try {
|
|
695
|
+
const [messageBrokerTag, topicTag] = data.topic.split(':');
|
|
696
|
+
if (!messageBrokerTag || !topicTag) {
|
|
697
|
+
throw new Error(`topic is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
698
|
+
}
|
|
699
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
700
|
+
if (!broker) {
|
|
701
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
702
|
+
}
|
|
703
|
+
// Check if consumer exists
|
|
704
|
+
const existingConsumer = (_a = broker.consumers) === null || _a === void 0 ? void 0 : _a.find((c) => c.tag === data.tag);
|
|
705
|
+
if (!existingConsumer) {
|
|
706
|
+
throw new Error(`Consumer ${data.tag} not found in broker ${messageBrokerTag}`);
|
|
707
|
+
}
|
|
708
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_CONSUMER, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
709
|
+
}
|
|
710
|
+
catch (e) {
|
|
711
|
+
throw e;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
async fetchMessageBrokerConsumer(brokerTag, tag) {
|
|
715
|
+
var _a;
|
|
716
|
+
const messageBroker = this.product.messageBrokers.find((data) => data.tag === brokerTag);
|
|
717
|
+
if (!messageBroker)
|
|
718
|
+
throw new Error(`MessageBroker ${brokerTag} not found`);
|
|
719
|
+
const consumer = (_a = messageBroker.consumers) === null || _a === void 0 ? void 0 : _a.find((c) => c.tag === tag);
|
|
720
|
+
return consumer || null;
|
|
721
|
+
}
|
|
722
|
+
async fetchMessageBrokerConsumers(messageBrokerTag) {
|
|
723
|
+
const messageBroker = this.product.messageBrokers.find((data) => data.tag === messageBrokerTag);
|
|
724
|
+
if (!messageBroker)
|
|
725
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
726
|
+
return messageBroker.consumers || [];
|
|
727
|
+
}
|
|
381
728
|
async validateQuotaFallbackInputAndOutput(data, type) {
|
|
382
729
|
const input = data.input;
|
|
383
730
|
await Promise.all(data.options.map(async (d, index) => {
|
|
@@ -410,7 +757,7 @@ class ProductsBuilderService {
|
|
|
410
757
|
this.checkActionQuotaFallbackInput(action.body, option.input.body, input, 'body');
|
|
411
758
|
}
|
|
412
759
|
else {
|
|
413
|
-
const feature = this.fetchFeature(option.event);
|
|
760
|
+
const feature = await this.fetchFeature(option.event);
|
|
414
761
|
if (!feature) {
|
|
415
762
|
throw new Error(`Feature ${option.event} not found`);
|
|
416
763
|
}
|
|
@@ -500,7 +847,7 @@ class ProductsBuilderService {
|
|
|
500
847
|
}
|
|
501
848
|
else {
|
|
502
849
|
// fetch feature
|
|
503
|
-
const feature = this.fetchFeature(option.event);
|
|
850
|
+
const feature = await this.fetchFeature(option.event);
|
|
504
851
|
if (!feature) {
|
|
505
852
|
throw new Error(`Feature ${option.event} not found`);
|
|
506
853
|
}
|
|
@@ -568,7 +915,7 @@ class ProductsBuilderService {
|
|
|
568
915
|
if (!data.tag) {
|
|
569
916
|
throw new Error('tag field is required');
|
|
570
917
|
}
|
|
571
|
-
if (!this.fetchQuota(data.tag)) {
|
|
918
|
+
if (!(await this.fetchQuota(data.tag))) {
|
|
572
919
|
await validators_1.CreateProductQuotaSchema.validateAsync(data);
|
|
573
920
|
await this.validateQuotaFallbackInputAndOutput(data, 'quota');
|
|
574
921
|
data.total_quota = 0;
|
|
@@ -593,7 +940,10 @@ class ProductsBuilderService {
|
|
|
593
940
|
if (!action) {
|
|
594
941
|
throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
|
|
595
942
|
}
|
|
596
|
-
if (action.headers.data.length > 0 ||
|
|
943
|
+
if (action.headers.data.length > 0 ||
|
|
944
|
+
action.body.data.length > 0 ||
|
|
945
|
+
action.params.data.length > 0 ||
|
|
946
|
+
action.query.data.length > 0) {
|
|
597
947
|
throw new Error('Healthcheck action is expected to have no headers, body, params or query');
|
|
598
948
|
}
|
|
599
949
|
}
|
|
@@ -611,7 +961,7 @@ class ProductsBuilderService {
|
|
|
611
961
|
}
|
|
612
962
|
async updateQuota(tag, data) {
|
|
613
963
|
try {
|
|
614
|
-
const quota = this.fetchQuota(tag);
|
|
964
|
+
const quota = await this.fetchQuota(tag);
|
|
615
965
|
if (quota) {
|
|
616
966
|
await validators_1.UpdateProductQuotaSchema.validateAsync(data);
|
|
617
967
|
if (data.options) {
|
|
@@ -639,7 +989,10 @@ class ProductsBuilderService {
|
|
|
639
989
|
if (!action) {
|
|
640
990
|
throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
|
|
641
991
|
}
|
|
642
|
-
if (action.headers.data.length > 0 ||
|
|
992
|
+
if (action.headers.data.length > 0 ||
|
|
993
|
+
action.body.data.length > 0 ||
|
|
994
|
+
action.params.data.length > 0 ||
|
|
995
|
+
action.query.data.length > 0) {
|
|
643
996
|
throw new Error('Healthcheck action is expected to have no headers, body, params or query');
|
|
644
997
|
}
|
|
645
998
|
}
|
|
@@ -659,18 +1012,36 @@ class ProductsBuilderService {
|
|
|
659
1012
|
throw e;
|
|
660
1013
|
}
|
|
661
1014
|
}
|
|
662
|
-
|
|
663
|
-
|
|
1015
|
+
async fetchQuotas(version) {
|
|
1016
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'quota', this.getUserAccess());
|
|
1017
|
+
return components;
|
|
664
1018
|
}
|
|
665
|
-
|
|
666
|
-
|
|
1019
|
+
async fetchQuota(tag, version) {
|
|
1020
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'quota', tag, this.getUserAccess());
|
|
1021
|
+
return component;
|
|
1022
|
+
}
|
|
1023
|
+
async deleteQuota(tag) {
|
|
1024
|
+
try {
|
|
1025
|
+
const quota = await this.fetchQuota(tag);
|
|
1026
|
+
if (!quota) {
|
|
1027
|
+
throw new Error(`Quota with tag: ${tag} not found`);
|
|
1028
|
+
}
|
|
1029
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1030
|
+
tag,
|
|
1031
|
+
component: enums_1.ProductComponents.QUOTA,
|
|
1032
|
+
action: enums_1.RequestAction.DELETE,
|
|
1033
|
+
}, this.getUserAccess());
|
|
1034
|
+
}
|
|
1035
|
+
catch (e) {
|
|
1036
|
+
throw e;
|
|
1037
|
+
}
|
|
667
1038
|
}
|
|
668
1039
|
async createFallback(data) {
|
|
669
1040
|
try {
|
|
670
1041
|
if (!data.tag) {
|
|
671
1042
|
throw new Error('tag field is required');
|
|
672
1043
|
}
|
|
673
|
-
if (!this.fetchFallback(data.tag)) {
|
|
1044
|
+
if (!(await this.fetchFallback(data.tag))) {
|
|
674
1045
|
await validators_1.CreateProductFallbackSchema.validateAsync(data);
|
|
675
1046
|
await this.validateQuotaFallbackInputAndOutput(data, 'fallback');
|
|
676
1047
|
await Promise.all(data.options.map(async (d) => {
|
|
@@ -692,7 +1063,10 @@ class ProductsBuilderService {
|
|
|
692
1063
|
if (!action) {
|
|
693
1064
|
throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
|
|
694
1065
|
}
|
|
695
|
-
if (action.headers.data.length > 0 ||
|
|
1066
|
+
if (action.headers.data.length > 0 ||
|
|
1067
|
+
action.body.data.length > 0 ||
|
|
1068
|
+
action.params.data.length > 0 ||
|
|
1069
|
+
action.query.data.length > 0) {
|
|
696
1070
|
throw new Error('Healthcheck action is expected to have no headers, body, params or query');
|
|
697
1071
|
}
|
|
698
1072
|
}
|
|
@@ -710,7 +1084,7 @@ class ProductsBuilderService {
|
|
|
710
1084
|
}
|
|
711
1085
|
async updateFallback(tag, data) {
|
|
712
1086
|
try {
|
|
713
|
-
const fallback = this.fetchFallback(tag);
|
|
1087
|
+
const fallback = await this.fetchFallback(tag);
|
|
714
1088
|
if (fallback) {
|
|
715
1089
|
await validators_1.UpdateProductFallbackSchema.validateAsync(data);
|
|
716
1090
|
if (data.options) {
|
|
@@ -735,7 +1109,10 @@ class ProductsBuilderService {
|
|
|
735
1109
|
if (!action) {
|
|
736
1110
|
throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
|
|
737
1111
|
}
|
|
738
|
-
if (action.headers.data.length > 0 ||
|
|
1112
|
+
if (action.headers.data.length > 0 ||
|
|
1113
|
+
action.body.data.length > 0 ||
|
|
1114
|
+
action.params.data.length > 0 ||
|
|
1115
|
+
action.query.data.length > 0) {
|
|
739
1116
|
throw new Error('Healthcheck action is expected to have no headers, body, params or query');
|
|
740
1117
|
}
|
|
741
1118
|
}
|
|
@@ -755,19 +1132,36 @@ class ProductsBuilderService {
|
|
|
755
1132
|
throw e;
|
|
756
1133
|
}
|
|
757
1134
|
}
|
|
758
|
-
|
|
759
|
-
|
|
1135
|
+
async fetchFallbacks(version) {
|
|
1136
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'fallback', this.getUserAccess());
|
|
1137
|
+
return components;
|
|
1138
|
+
}
|
|
1139
|
+
async fetchFallback(tag, version) {
|
|
1140
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'fallback', tag, this.getUserAccess());
|
|
1141
|
+
return component;
|
|
760
1142
|
}
|
|
761
|
-
|
|
762
|
-
|
|
1143
|
+
async deleteFallback(tag) {
|
|
1144
|
+
try {
|
|
1145
|
+
const fallback = await this.fetchFallback(tag);
|
|
1146
|
+
if (!fallback) {
|
|
1147
|
+
throw new Error(`Fallback with tag: ${tag} not found`);
|
|
1148
|
+
}
|
|
1149
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1150
|
+
tag,
|
|
1151
|
+
component: enums_1.ProductComponents.FALLBACK,
|
|
1152
|
+
action: enums_1.RequestAction.DELETE,
|
|
1153
|
+
}, this.getUserAccess());
|
|
1154
|
+
}
|
|
1155
|
+
catch (e) {
|
|
1156
|
+
throw e;
|
|
1157
|
+
}
|
|
763
1158
|
}
|
|
764
1159
|
async createEnv(data, throwErrorIfExists = false) {
|
|
765
1160
|
try {
|
|
766
1161
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
767
|
-
if (!this.fetchEnv(data.slug)) {
|
|
1162
|
+
if (!(await this.fetchEnv(data.slug))) {
|
|
768
1163
|
await validators_1.CreateProductEnvSchema.validateAsync(data);
|
|
769
1164
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.ENV, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
770
|
-
await this.initializeProduct(this.product_id);
|
|
771
1165
|
}
|
|
772
1166
|
else {
|
|
773
1167
|
if (throwErrorIfExists)
|
|
@@ -780,137 +1174,227 @@ class ProductsBuilderService {
|
|
|
780
1174
|
}
|
|
781
1175
|
async updateEnv(slug, data) {
|
|
782
1176
|
try {
|
|
783
|
-
const env = this.fetchEnv(slug
|
|
1177
|
+
const env = await this.fetchEnv(slug);
|
|
784
1178
|
if (!env) {
|
|
785
1179
|
throw new Error(`Env ${slug} not found`);
|
|
786
1180
|
}
|
|
787
1181
|
const { _id } = env;
|
|
788
1182
|
await validators_1.UpdateProductEnvSchema.validateAsync(data); // Change to update;
|
|
789
|
-
if (data.slug && this.fetchEnv(data.slug)) {
|
|
1183
|
+
if (data.slug && (await this.fetchEnv(data.slug))) {
|
|
790
1184
|
throw new Error(`slug ${slug} is in use`); // TODO: also check on the backend
|
|
791
1185
|
}
|
|
792
1186
|
if (!data.slug) {
|
|
793
1187
|
data.slug = slug;
|
|
794
1188
|
}
|
|
795
1189
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, env), data)), { component: enums_1.ProductComponents.ENV, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
796
|
-
await this.initializeProduct(this.product_id);
|
|
797
1190
|
}
|
|
798
1191
|
catch (e) {
|
|
799
1192
|
throw e;
|
|
800
1193
|
}
|
|
801
1194
|
}
|
|
802
|
-
fetchEnvs() {
|
|
803
|
-
|
|
1195
|
+
async fetchEnvs(version) {
|
|
1196
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'env', this.getUserAccess());
|
|
1197
|
+
return components;
|
|
804
1198
|
}
|
|
805
|
-
fetchEnv(slug
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
1199
|
+
async fetchEnv(slug) {
|
|
1200
|
+
console.log;
|
|
1201
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'env', slug, this.getUserAccess());
|
|
1202
|
+
return component;
|
|
1203
|
+
}
|
|
1204
|
+
async deleteEnv(slug) {
|
|
1205
|
+
try {
|
|
1206
|
+
const env = await this.fetchEnv(slug);
|
|
1207
|
+
if (!env) {
|
|
1208
|
+
throw new Error(`Environment with slug: ${slug} not found`);
|
|
1209
|
+
}
|
|
1210
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1211
|
+
slug,
|
|
1212
|
+
component: enums_1.ProductComponents.ENV,
|
|
1213
|
+
action: enums_1.RequestAction.DELETE,
|
|
1214
|
+
}, this.getUserAccess());
|
|
1215
|
+
}
|
|
1216
|
+
catch (e) {
|
|
1217
|
+
throw e;
|
|
1218
|
+
}
|
|
810
1219
|
}
|
|
811
1220
|
async createMessageBroker(data, throwErrorIfExists = false) {
|
|
812
|
-
|
|
1221
|
+
var _a;
|
|
1222
|
+
const logPrefix = '[MessageBroker:Create]';
|
|
1223
|
+
console.log(`${logPrefix} Starting creation for broker: ${data.tag}`);
|
|
1224
|
+
console.log(`${logPrefix} Broker name: ${data.name}`);
|
|
1225
|
+
console.log(`${logPrefix} Broker description: ${data.description || 'N/A'}`);
|
|
1226
|
+
console.log(`${logPrefix} Number of environments: ${((_a = data.envs) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
|
|
1227
|
+
const existingBroker = await this.fetchMessageBroker(data.tag);
|
|
1228
|
+
if (!existingBroker) {
|
|
1229
|
+
console.log(`${logPrefix} Broker ${data.tag} does not exist, proceeding with creation`);
|
|
1230
|
+
console.log(`${logPrefix} Validating schema...`);
|
|
813
1231
|
await validators_1.CreateMessageBrokerSchema.validateAsync(data);
|
|
814
|
-
|
|
815
|
-
|
|
1232
|
+
console.log(`${logPrefix} Schema validation passed`);
|
|
1233
|
+
const processedEnvs = [];
|
|
1234
|
+
for (const env of data.envs) {
|
|
1235
|
+
console.log(`${logPrefix} Processing env: ${env.slug} (type: ${env.type})`);
|
|
1236
|
+
const exists = await this.fetchEnv(env.slug);
|
|
816
1237
|
if (!exists) {
|
|
1238
|
+
console.error(`${logPrefix} Env ${env.slug} does not exist`);
|
|
817
1239
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
818
1240
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
1241
|
+
console.log(`${logPrefix} Env ${env.slug} exists, verified`);
|
|
1242
|
+
// Store sensitive credentials as secrets
|
|
1243
|
+
console.log(`${logPrefix} Processing secrets for env: ${env.slug}...`);
|
|
1244
|
+
env.config = await this.processMessageBrokerConfigSecrets(env.config, env.type, data.tag, env.slug);
|
|
1245
|
+
console.log(`${logPrefix} Secrets processed for env: ${env.slug}`);
|
|
1246
|
+
console.log(`${logPrefix} Encrypting config for env: ${env.slug}...`);
|
|
1247
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1248
|
+
console.log(`${logPrefix} Config encrypted for env: ${env.slug}`);
|
|
1249
|
+
processedEnvs.push(env);
|
|
1250
|
+
}
|
|
1251
|
+
data.envs = processedEnvs;
|
|
1252
|
+
console.log(`${logPrefix} All environments processed: ${processedEnvs.length}`);
|
|
1253
|
+
const envs = await this.fetchEnvs();
|
|
1254
|
+
console.log(`${logPrefix} Product has ${envs.length} environments defined`);
|
|
1255
|
+
for (const env of envs) {
|
|
824
1256
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
825
1257
|
if (exists === -1) {
|
|
1258
|
+
console.error(`${logPrefix} Product env ${env.slug} is not defined in broker config`);
|
|
826
1259
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
827
1260
|
}
|
|
828
|
-
}
|
|
1261
|
+
}
|
|
1262
|
+
console.log(`${logPrefix} All product environments have broker configs`);
|
|
1263
|
+
console.log(`${logPrefix} Sending create request to API...`);
|
|
829
1264
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.MESSAGEBROKER, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
830
|
-
|
|
1265
|
+
console.log(`${logPrefix} Message broker ${data.tag} created successfully`);
|
|
831
1266
|
}
|
|
832
1267
|
else {
|
|
1268
|
+
console.log(`${logPrefix} Broker ${data.tag} already exists`);
|
|
833
1269
|
if (throwErrorIfExists)
|
|
834
1270
|
throw new Error(`Message Broker ${data.tag} already exists`);
|
|
835
1271
|
}
|
|
836
1272
|
}
|
|
837
1273
|
async updateMessageBroker(tag, data) {
|
|
1274
|
+
var _a, _b;
|
|
1275
|
+
const logPrefix = '[MessageBroker:Update]';
|
|
1276
|
+
console.log(`${logPrefix} Starting update for broker: ${tag}`);
|
|
1277
|
+
console.log(`${logPrefix} New tag (if changed): ${data.tag || 'unchanged'}`);
|
|
1278
|
+
console.log(`${logPrefix} New name: ${data.name || 'unchanged'}`);
|
|
1279
|
+
console.log(`${logPrefix} Number of environments in update: ${((_a = data.envs) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
|
|
838
1280
|
try {
|
|
839
|
-
|
|
1281
|
+
console.log(`${logPrefix} Fetching existing broker: ${tag}`);
|
|
1282
|
+
const messageBroker = await this.fetchMessageBroker(tag);
|
|
840
1283
|
if (!messageBroker) {
|
|
1284
|
+
console.error(`${logPrefix} Broker ${tag} not found`);
|
|
841
1285
|
throw new Error(`Broker ${tag} not found`);
|
|
842
1286
|
}
|
|
1287
|
+
console.log(`${logPrefix} Existing broker found with ${((_b = messageBroker.envs) === null || _b === void 0 ? void 0 : _b.length) || 0} environments`);
|
|
843
1288
|
const { _id, envs } = messageBroker;
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
1289
|
+
console.log(`${logPrefix} Broker ID: ${_id}`);
|
|
1290
|
+
console.log(`${logPrefix} Validating update schema...`);
|
|
1291
|
+
await validators_1.UpdateMessageBrokerSchema.validateAsync(data);
|
|
1292
|
+
console.log(`${logPrefix} Schema validation passed`);
|
|
1293
|
+
if (data.tag && (await this.fetchMessageBroker(data.tag))) {
|
|
1294
|
+
console.error(`${logPrefix} Tag ${data.tag} is already in use`);
|
|
1295
|
+
throw new Error(`tag ${tag} is in use`);
|
|
1296
|
+
}
|
|
1297
|
+
const processedEnvs = [];
|
|
1298
|
+
for (const env of data.envs) {
|
|
1299
|
+
console.log(`${logPrefix} Processing env: ${env.slug} (type: ${env.type})`);
|
|
1300
|
+
const exists = await this.fetchEnv(env.slug);
|
|
851
1301
|
if (!exists) {
|
|
1302
|
+
console.error(`${logPrefix} Env ${env.slug} does not exist`);
|
|
852
1303
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
853
1304
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1305
|
+
console.log(`${logPrefix} Env ${env.slug} exists, verified`);
|
|
1306
|
+
if (env.config) {
|
|
1307
|
+
// Store sensitive credentials as secrets
|
|
1308
|
+
console.log(`${logPrefix} Processing secrets for env: ${env.slug}...`);
|
|
1309
|
+
env.config = await this.processMessageBrokerConfigSecrets(env.config, env.type, data.tag || tag, env.slug);
|
|
1310
|
+
console.log(`${logPrefix} Secrets processed for env: ${env.slug}`);
|
|
1311
|
+
console.log(`${logPrefix} Encrypting config for env: ${env.slug}...`);
|
|
1312
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1313
|
+
console.log(`${logPrefix} Config encrypted for env: ${env.slug}`);
|
|
1314
|
+
}
|
|
1315
|
+
else {
|
|
1316
|
+
console.log(`${logPrefix} No config provided for env: ${env.slug}, skipping secrets processing`);
|
|
1317
|
+
}
|
|
1318
|
+
processedEnvs.push(env);
|
|
1319
|
+
}
|
|
1320
|
+
data.envs = processedEnvs;
|
|
1321
|
+
console.log(`${logPrefix} All environments processed: ${processedEnvs.length}`);
|
|
858
1322
|
const overwrite = [];
|
|
859
1323
|
const newEnvs = [];
|
|
860
|
-
data.envs
|
|
1324
|
+
for (const dataEnv of data.envs) {
|
|
861
1325
|
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
862
|
-
if (!this.fetchEnv(dataEnv.slug)) {
|
|
1326
|
+
if (!(await this.fetchEnv(dataEnv.slug))) {
|
|
1327
|
+
console.error(`${logPrefix} Product Environment ${dataEnv.slug} doesn't exist`);
|
|
863
1328
|
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
864
1329
|
}
|
|
865
1330
|
if (exists === -1) {
|
|
1331
|
+
console.log(`${logPrefix} Env ${dataEnv.slug} is a NEW environment`);
|
|
866
1332
|
if (!dataEnv.config) {
|
|
1333
|
+
console.error(`${logPrefix} Config is required for new env ${dataEnv.slug}`);
|
|
867
1334
|
throw new Error(`config is required for new env ${data.envs[exists].slug}`);
|
|
868
1335
|
}
|
|
869
1336
|
newEnvs.push(dataEnv);
|
|
870
1337
|
}
|
|
871
1338
|
else {
|
|
1339
|
+
console.log(`${logPrefix} Env ${dataEnv.slug} will OVERWRITE existing config`);
|
|
872
1340
|
if (envs[exists].config) {
|
|
873
|
-
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.
|
|
1341
|
+
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.product.private_key);
|
|
874
1342
|
}
|
|
875
1343
|
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
876
1344
|
}
|
|
877
|
-
}
|
|
1345
|
+
}
|
|
878
1346
|
const unchanged = [];
|
|
879
|
-
|
|
1347
|
+
for (const env of envs) {
|
|
880
1348
|
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
881
1349
|
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
882
1350
|
if (!newEnv && !overwriteEnv) {
|
|
1351
|
+
console.log(`${logPrefix} Env ${env.slug} is UNCHANGED`);
|
|
883
1352
|
if (env.config) {
|
|
884
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.
|
|
1353
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
885
1354
|
}
|
|
886
1355
|
unchanged.push(env);
|
|
887
1356
|
}
|
|
888
|
-
}
|
|
1357
|
+
}
|
|
889
1358
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1359
|
+
console.log(`${logPrefix} Final env breakdown - Unchanged: ${unchanged.length}, Overwrite: ${overwrite.length}, New: ${newEnvs.length}`);
|
|
1360
|
+
console.log(`${logPrefix} Sending update request to API...`);
|
|
890
1361
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, messageBroker), data), { component: enums_1.ProductComponents.MESSAGEBROKER, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
891
|
-
|
|
1362
|
+
console.log(`${logPrefix} Message broker ${tag} updated successfully`);
|
|
892
1363
|
}
|
|
893
1364
|
catch (e) {
|
|
1365
|
+
console.error(`${logPrefix} Update failed:`, e);
|
|
894
1366
|
throw e;
|
|
895
1367
|
}
|
|
896
1368
|
}
|
|
897
|
-
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
1369
|
+
async fetchMessageBrokers(version) {
|
|
1370
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'message_broker', this.getUserAccess());
|
|
1371
|
+
return components;
|
|
1372
|
+
}
|
|
1373
|
+
async fetchMessageBroker(tag, version) {
|
|
1374
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'message_broker', tag, this.getUserAccess());
|
|
1375
|
+
if (component) {
|
|
1376
|
+
const decryptedEnvs = component.envs.map((env) => {
|
|
1377
|
+
return Object.assign(Object.assign({}, env), { config: JSON.parse((0, processor_utils_1.decrypt)(env.config, this.product.private_key)) });
|
|
906
1378
|
});
|
|
1379
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
907
1380
|
}
|
|
908
|
-
return
|
|
1381
|
+
return component;
|
|
909
1382
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1383
|
+
async deleteMessageBroker(tag) {
|
|
1384
|
+
try {
|
|
1385
|
+
const messageBroker = await this.fetchMessageBroker(tag);
|
|
1386
|
+
if (!messageBroker) {
|
|
1387
|
+
throw new Error(`Message broker with tag: ${tag} not found`);
|
|
1388
|
+
}
|
|
1389
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1390
|
+
tag,
|
|
1391
|
+
component: enums_1.ProductComponents.MESSAGEBROKER,
|
|
1392
|
+
action: enums_1.RequestAction.DELETE,
|
|
1393
|
+
}, this.getUserAccess());
|
|
1394
|
+
}
|
|
1395
|
+
catch (e) {
|
|
1396
|
+
throw e;
|
|
1397
|
+
}
|
|
914
1398
|
}
|
|
915
1399
|
async fetchStorageFiles(filter) {
|
|
916
1400
|
try {
|
|
@@ -926,7 +1410,7 @@ class ProductsBuilderService {
|
|
|
926
1410
|
});
|
|
927
1411
|
}
|
|
928
1412
|
catch (e) {
|
|
929
|
-
throw
|
|
1413
|
+
throw e;
|
|
930
1414
|
}
|
|
931
1415
|
}
|
|
932
1416
|
async fetchSessionUsers(filter) {
|
|
@@ -942,14 +1426,15 @@ class ProductsBuilderService {
|
|
|
942
1426
|
});
|
|
943
1427
|
}
|
|
944
1428
|
catch (e) {
|
|
945
|
-
throw
|
|
1429
|
+
throw e;
|
|
946
1430
|
}
|
|
947
1431
|
}
|
|
948
1432
|
async createStorage(data, throwErrorIfExists = false) {
|
|
949
|
-
if (!this.fetchStorage(data.tag
|
|
1433
|
+
if (!(await this.fetchStorage(data.tag))) {
|
|
950
1434
|
await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
|
|
951
|
-
|
|
952
|
-
|
|
1435
|
+
const processedEnvs = [];
|
|
1436
|
+
for (const env of data.envs) {
|
|
1437
|
+
const exists = await this.fetchEnv(env.slug);
|
|
953
1438
|
if (!exists) {
|
|
954
1439
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
955
1440
|
}
|
|
@@ -957,18 +1442,20 @@ class ProductsBuilderService {
|
|
|
957
1442
|
// @ts-ignore
|
|
958
1443
|
//env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
|
|
959
1444
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1445
|
+
// Store sensitive credentials as secrets
|
|
1446
|
+
env.config = await this.processStorageConfigSecrets(env.config, env.type, data.tag, env.slug);
|
|
1447
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1448
|
+
processedEnvs.push(env);
|
|
1449
|
+
}
|
|
1450
|
+
data.envs = processedEnvs;
|
|
1451
|
+
const envs = await this.fetchEnvs();
|
|
1452
|
+
for (const env of envs) {
|
|
965
1453
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
966
1454
|
if (exists === -1) {
|
|
967
1455
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
968
1456
|
}
|
|
969
|
-
}
|
|
1457
|
+
}
|
|
970
1458
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
971
|
-
await this.initializeProduct(this.product_id);
|
|
972
1459
|
}
|
|
973
1460
|
else {
|
|
974
1461
|
if (throwErrorIfExists)
|
|
@@ -977,85 +1464,756 @@ class ProductsBuilderService {
|
|
|
977
1464
|
}
|
|
978
1465
|
async updateStorage(tag, data) {
|
|
979
1466
|
try {
|
|
980
|
-
const storage = this.fetchStorage(tag);
|
|
1467
|
+
const storage = await this.fetchStorage(tag);
|
|
981
1468
|
if (!storage) {
|
|
982
1469
|
throw new Error(`Storage ${tag} not found`);
|
|
983
1470
|
}
|
|
984
1471
|
const { _id, envs } = storage;
|
|
985
1472
|
await create_productStorage_validator_1.UpdateProductStorageSchema.validateAsync(data); // Change to update;
|
|
986
|
-
if (data.tag && this.fetchStorage(data.tag)) {
|
|
1473
|
+
if (data.tag && await this.fetchStorage(data.tag)) {
|
|
987
1474
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
988
1475
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
// @ts-ignore
|
|
996
|
-
//env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
|
|
997
|
-
}
|
|
998
|
-
if (env.config)
|
|
999
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
|
|
1000
|
-
return env;
|
|
1001
|
-
});
|
|
1002
|
-
const overwrite = [];
|
|
1003
|
-
const newEnvs = [];
|
|
1004
|
-
data.envs.map((dataEnv) => {
|
|
1005
|
-
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1006
|
-
if (!this.fetchEnv(dataEnv.slug)) {
|
|
1007
|
-
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
1008
|
-
}
|
|
1009
|
-
if (exists === -1) {
|
|
1010
|
-
if (!dataEnv.config) {
|
|
1011
|
-
throw new Error(`config is required for new env ${data.envs[exists].slug}`);
|
|
1476
|
+
// Only process envs if they are provided in the update
|
|
1477
|
+
if (data.envs && data.envs.length > 0) {
|
|
1478
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
1479
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1480
|
+
if (!exists) {
|
|
1481
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
1012
1482
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
if (envs[exists].config) {
|
|
1017
|
-
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.fetchProduct().private_key);
|
|
1483
|
+
if (env.type === productsBuilder_types_1.StorageProviders.GCP) {
|
|
1484
|
+
// @ts-ignore
|
|
1485
|
+
//env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
|
|
1018
1486
|
}
|
|
1019
|
-
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
const unchanged = [];
|
|
1023
|
-
envs.map((env) => {
|
|
1024
|
-
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1025
|
-
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1026
|
-
if (!newEnv && !overwriteEnv) {
|
|
1027
1487
|
if (env.config) {
|
|
1028
|
-
|
|
1488
|
+
// Store sensitive credentials as secrets
|
|
1489
|
+
env.config = await this.processStorageConfigSecrets(env.config, env.type, data.tag || tag, env.slug);
|
|
1490
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1029
1491
|
}
|
|
1030
|
-
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1492
|
+
return env;
|
|
1493
|
+
}));
|
|
1494
|
+
const overwrite = [];
|
|
1495
|
+
const newEnvs = [];
|
|
1496
|
+
data.envs.map((dataEnv) => {
|
|
1497
|
+
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1498
|
+
if (!this.fetchEnv(dataEnv.slug)) {
|
|
1499
|
+
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
1500
|
+
}
|
|
1501
|
+
if (exists === -1) {
|
|
1502
|
+
if (!dataEnv.config) {
|
|
1503
|
+
throw new Error(`config is required for new env ${data.envs[exists].slug}`);
|
|
1504
|
+
}
|
|
1505
|
+
newEnvs.push(dataEnv);
|
|
1506
|
+
}
|
|
1507
|
+
else {
|
|
1508
|
+
if (envs[exists].config) {
|
|
1509
|
+
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.product.private_key);
|
|
1510
|
+
}
|
|
1511
|
+
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1514
|
+
const unchanged = [];
|
|
1515
|
+
envs.map((env) => {
|
|
1516
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1517
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1518
|
+
if (!newEnv && !overwriteEnv) {
|
|
1519
|
+
if (env.config) {
|
|
1520
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1521
|
+
}
|
|
1522
|
+
unchanged.push(env);
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1526
|
+
}
|
|
1527
|
+
// Build the update payload - only send fields that are being updated
|
|
1528
|
+
// Remove fields that shouldn't be in the update request
|
|
1529
|
+
const { envs: dataEnvs } = data, dataWithoutEnvs = __rest(data, ["envs"]);
|
|
1530
|
+
// Only include envs if they were explicitly provided and processed
|
|
1531
|
+
// Don't spread ...storage - only send the fields being updated
|
|
1532
|
+
const updatePayload = Object.assign(Object.assign(Object.assign({ _id }, storage), { tag }), dataWithoutEnvs);
|
|
1533
|
+
// Add processed envs only if they were provided in the update
|
|
1534
|
+
if (data.envs && data.envs.length > 0) {
|
|
1535
|
+
updatePayload.envs = data.envs;
|
|
1536
|
+
}
|
|
1537
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, updatePayload), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1538
|
+
}
|
|
1539
|
+
catch (e) {
|
|
1540
|
+
throw e;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
async fetchStorages(version) {
|
|
1544
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'storage', this.getUserAccess());
|
|
1545
|
+
return components;
|
|
1546
|
+
}
|
|
1547
|
+
async fetchStorage(tag, version) {
|
|
1548
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'storage', tag, this.getUserAccess());
|
|
1549
|
+
if (component) {
|
|
1550
|
+
const decryptedEnvs = component.envs.map((env) => {
|
|
1551
|
+
return Object.assign(Object.assign({}, env), { config: JSON.parse((0, processor_utils_1.decrypt)(env.config, this.product.private_key)) });
|
|
1552
|
+
});
|
|
1553
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
1554
|
+
}
|
|
1555
|
+
return component;
|
|
1556
|
+
}
|
|
1557
|
+
async deleteStorage(tag) {
|
|
1558
|
+
try {
|
|
1559
|
+
const storage = await this.fetchStorage(tag);
|
|
1560
|
+
if (!storage) {
|
|
1561
|
+
throw new Error(`Storage with tag: ${tag} not found`);
|
|
1562
|
+
}
|
|
1563
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1564
|
+
tag,
|
|
1565
|
+
component: enums_1.ProductComponents.STORAGE,
|
|
1566
|
+
action: enums_1.RequestAction.DELETE,
|
|
1567
|
+
}, this.getUserAccess());
|
|
1568
|
+
}
|
|
1569
|
+
catch (e) {
|
|
1570
|
+
throw e;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
// ==================== VECTOR DATABASE METHODS ====================
|
|
1574
|
+
/**
|
|
1575
|
+
* Create a new vector database configuration
|
|
1576
|
+
* @param data Vector database configuration
|
|
1577
|
+
* @param throwErrorIfExists Whether to throw error if vector config already exists
|
|
1578
|
+
*/
|
|
1579
|
+
async createVector(data, throwErrorIfExists = false) {
|
|
1580
|
+
var _a, _b, _c, _d;
|
|
1581
|
+
console.log('[ProductsService.createVector] Starting vector creation:', {
|
|
1582
|
+
tag: data.tag,
|
|
1583
|
+
name: data.name,
|
|
1584
|
+
type: data.type,
|
|
1585
|
+
envsCount: (_a = data.envs) === null || _a === void 0 ? void 0 : _a.length,
|
|
1586
|
+
productTag: (_b = this.product) === null || _b === void 0 ? void 0 : _b.tag,
|
|
1587
|
+
});
|
|
1588
|
+
if (!(await this.fetchVector(data.tag))) {
|
|
1589
|
+
await validators_1.CreateProductVectorSchema.validateAsync(data);
|
|
1590
|
+
const processedEnvs = [];
|
|
1591
|
+
for (const env of data.envs) {
|
|
1592
|
+
console.log('[ProductsService.createVector] Processing env:', {
|
|
1593
|
+
slug: env.slug,
|
|
1594
|
+
hasApiKey: !!env.apiKey,
|
|
1595
|
+
hasEndpoint: !!env.endpoint,
|
|
1596
|
+
});
|
|
1597
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1598
|
+
if (!exists) {
|
|
1599
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
1600
|
+
}
|
|
1601
|
+
// Store API key as secret and encrypt
|
|
1602
|
+
if (env.apiKey) {
|
|
1603
|
+
console.log('[ProductsService.createVector] Converting API key to secret for env:', env.slug);
|
|
1604
|
+
const originalApiKey = env.apiKey;
|
|
1605
|
+
env.apiKey = await this.storeVectorApiKeyAsSecret(env.apiKey, data.tag, env.slug);
|
|
1606
|
+
console.log('[ProductsService.createVector] API key after secret conversion:', {
|
|
1607
|
+
wasConverted: originalApiKey !== env.apiKey,
|
|
1608
|
+
isSecretRef: (_c = env.apiKey) === null || _c === void 0 ? void 0 : _c.startsWith('$Secret{'),
|
|
1609
|
+
});
|
|
1610
|
+
env.apiKey = (0, processor_utils_1.encrypt)(env.apiKey, this.product.private_key);
|
|
1611
|
+
console.log('[ProductsService.createVector] API key encrypted');
|
|
1612
|
+
}
|
|
1613
|
+
// Store endpoint as secret and encrypt
|
|
1614
|
+
if (env.endpoint) {
|
|
1615
|
+
console.log('[ProductsService.createVector] Converting endpoint to secret for env:', env.slug);
|
|
1616
|
+
const originalEndpoint = env.endpoint;
|
|
1617
|
+
env.endpoint = await this.storeVectorEndpointAsSecret(env.endpoint, data.tag, env.slug);
|
|
1618
|
+
console.log('[ProductsService.createVector] Endpoint after secret conversion:', {
|
|
1619
|
+
wasConverted: originalEndpoint !== env.endpoint,
|
|
1620
|
+
isSecretRef: (_d = env.endpoint) === null || _d === void 0 ? void 0 : _d.startsWith('$Secret{'),
|
|
1621
|
+
});
|
|
1622
|
+
env.endpoint = (0, processor_utils_1.encrypt)(env.endpoint, this.product.private_key);
|
|
1623
|
+
console.log('[ProductsService.createVector] Endpoint encrypted');
|
|
1624
|
+
}
|
|
1625
|
+
processedEnvs.push(env);
|
|
1626
|
+
console.log('[ProductsService.createVector] Env processed successfully:', env.slug);
|
|
1627
|
+
}
|
|
1628
|
+
data.envs = processedEnvs;
|
|
1629
|
+
console.log('[ProductsService.createVector] All envs processed, total:', processedEnvs.length);
|
|
1630
|
+
const envs = await this.fetchEnvs();
|
|
1631
|
+
for (const env of envs) {
|
|
1632
|
+
const exists = data.envs.findIndex((vecEnv) => vecEnv.slug === env.slug);
|
|
1633
|
+
if (exists === -1) {
|
|
1634
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.VECTOR, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1638
|
+
}
|
|
1639
|
+
else {
|
|
1640
|
+
if (throwErrorIfExists)
|
|
1641
|
+
throw new Error(`Vector ${data.tag} already exists`);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Update an existing vector database configuration
|
|
1646
|
+
* @param tag Vector config tag
|
|
1647
|
+
* @param data Updated vector configuration
|
|
1648
|
+
*/
|
|
1649
|
+
async updateVector(tag, data) {
|
|
1650
|
+
var _a, _b;
|
|
1651
|
+
console.log('[ProductsService.updateVector] Starting vector update:', {
|
|
1652
|
+
tag,
|
|
1653
|
+
newTag: data.tag,
|
|
1654
|
+
name: data.name,
|
|
1655
|
+
envsCount: (_a = data.envs) === null || _a === void 0 ? void 0 : _a.length,
|
|
1656
|
+
productTag: (_b = this.product) === null || _b === void 0 ? void 0 : _b.tag,
|
|
1657
|
+
});
|
|
1658
|
+
try {
|
|
1659
|
+
const vector = await this.fetchVector(tag);
|
|
1660
|
+
if (!vector) {
|
|
1661
|
+
throw new Error(`Vector ${tag} not found`);
|
|
1662
|
+
}
|
|
1663
|
+
const { _id, envs } = vector;
|
|
1664
|
+
console.log('[ProductsService.updateVector] Found existing vector:', {
|
|
1665
|
+
_id,
|
|
1666
|
+
existingEnvsCount: envs === null || envs === void 0 ? void 0 : envs.length,
|
|
1667
|
+
});
|
|
1668
|
+
await validators_1.UpdateProductVectorSchema.validateAsync(data);
|
|
1669
|
+
if (data.tag && (await this.fetchVector(data.tag))) {
|
|
1670
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
1671
|
+
}
|
|
1672
|
+
if (data.envs) {
|
|
1673
|
+
console.log('[ProductsService.updateVector] Processing envs update');
|
|
1674
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
1675
|
+
var _a, _b;
|
|
1676
|
+
console.log('[ProductsService.updateVector] Processing env:', {
|
|
1677
|
+
slug: env.slug,
|
|
1678
|
+
hasApiKey: !!env.apiKey,
|
|
1679
|
+
hasEndpoint: !!env.endpoint,
|
|
1680
|
+
});
|
|
1681
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1682
|
+
if (!exists) {
|
|
1683
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
1684
|
+
}
|
|
1685
|
+
// Store API key as secret and encrypt
|
|
1686
|
+
if (env.apiKey) {
|
|
1687
|
+
console.log('[ProductsService.updateVector] Converting API key to secret for env:', env.slug);
|
|
1688
|
+
const originalApiKey = env.apiKey;
|
|
1689
|
+
env.apiKey = await this.storeVectorApiKeyAsSecret(env.apiKey, data.tag || tag, env.slug);
|
|
1690
|
+
console.log('[ProductsService.updateVector] API key after secret conversion:', {
|
|
1691
|
+
wasConverted: originalApiKey !== env.apiKey,
|
|
1692
|
+
isSecretRef: (_a = env.apiKey) === null || _a === void 0 ? void 0 : _a.startsWith('$Secret{'),
|
|
1693
|
+
});
|
|
1694
|
+
env.apiKey = (0, processor_utils_1.encrypt)(env.apiKey, this.product.private_key);
|
|
1695
|
+
console.log('[ProductsService.updateVector] API key encrypted');
|
|
1696
|
+
}
|
|
1697
|
+
// Store endpoint as secret and encrypt
|
|
1698
|
+
if (env.endpoint) {
|
|
1699
|
+
console.log('[ProductsService.updateVector] Converting endpoint to secret for env:', env.slug);
|
|
1700
|
+
const originalEndpoint = env.endpoint;
|
|
1701
|
+
env.endpoint = await this.storeVectorEndpointAsSecret(env.endpoint, data.tag || tag, env.slug);
|
|
1702
|
+
console.log('[ProductsService.updateVector] Endpoint after secret conversion:', {
|
|
1703
|
+
wasConverted: originalEndpoint !== env.endpoint,
|
|
1704
|
+
isSecretRef: (_b = env.endpoint) === null || _b === void 0 ? void 0 : _b.startsWith('$Secret{'),
|
|
1705
|
+
});
|
|
1706
|
+
env.endpoint = (0, processor_utils_1.encrypt)(env.endpoint, this.product.private_key);
|
|
1707
|
+
console.log('[ProductsService.updateVector] Endpoint encrypted');
|
|
1708
|
+
}
|
|
1709
|
+
console.log('[ProductsService.updateVector] Env processed successfully:', env.slug);
|
|
1710
|
+
return env;
|
|
1711
|
+
}));
|
|
1712
|
+
const overwrite = [];
|
|
1713
|
+
const newEnvs = [];
|
|
1714
|
+
data.envs.forEach((dataEnv) => {
|
|
1715
|
+
const existsIdx = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1716
|
+
if (existsIdx === -1) {
|
|
1717
|
+
newEnvs.push(dataEnv);
|
|
1718
|
+
}
|
|
1719
|
+
else {
|
|
1720
|
+
overwrite.push(Object.assign(Object.assign({}, envs[existsIdx]), dataEnv));
|
|
1721
|
+
}
|
|
1722
|
+
});
|
|
1723
|
+
const unchanged = [];
|
|
1724
|
+
envs.forEach((env) => {
|
|
1725
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1726
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1727
|
+
if (!newEnv && !overwriteEnv) {
|
|
1728
|
+
unchanged.push(env);
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1731
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1732
|
+
}
|
|
1733
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, vector), data), { component: enums_1.ProductComponents.VECTOR, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1734
|
+
}
|
|
1735
|
+
catch (e) {
|
|
1736
|
+
throw e;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Fetch all vector database configurations
|
|
1741
|
+
* @param version Optional version
|
|
1742
|
+
*/
|
|
1743
|
+
async fetchVectors(version) {
|
|
1744
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'vector', this.getUserAccess());
|
|
1745
|
+
// Decrypt sensitive fields in vector envs
|
|
1746
|
+
/* const decryptedComponents = components.map((vectorComponent: any) => {
|
|
1747
|
+
const decryptedEnvs = vectorComponent.envs?.map((env: any) => {
|
|
1748
|
+
return {
|
|
1749
|
+
...env,
|
|
1750
|
+
apiKey: env.apiKey ? decrypt(env.apiKey, this.product.private_key) : env.apiKey,
|
|
1751
|
+
endpoint: env.endpoint ? decrypt(env.endpoint, this.product.private_key) : env.endpoint,
|
|
1752
|
+
};
|
|
1753
|
+
});
|
|
1754
|
+
return { ...vectorComponent, envs: decryptedEnvs };
|
|
1755
|
+
}); */
|
|
1756
|
+
//return decryptedComponents as unknown as IProductVector[];
|
|
1757
|
+
return components;
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Fetch a specific vector database configuration by tag
|
|
1761
|
+
* @param tag Vector config tag
|
|
1762
|
+
* @param version Optional version
|
|
1763
|
+
*/
|
|
1764
|
+
async fetchVector(tag, version) {
|
|
1765
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'vector', tag, this.getUserAccess());
|
|
1766
|
+
/*console.log(JSON.stringify(component))
|
|
1767
|
+
if (component) {
|
|
1768
|
+
// Decrypt sensitive fields in vector envs
|
|
1769
|
+
const decryptedEnvs = component.envs?.map((env: any) => {
|
|
1770
|
+
return {
|
|
1771
|
+
...env,
|
|
1772
|
+
apiKey: env.apiKey ? decrypt(env.apiKey, this.product.private_key) : env.apiKey,
|
|
1773
|
+
endpoint: env.endpoint ? decrypt(env.endpoint, this.product.private_key) : env.endpoint,
|
|
1774
|
+
};
|
|
1775
|
+
});
|
|
1776
|
+
return { ...component, envs: decryptedEnvs } as unknown as IProductVector;
|
|
1777
|
+
}*/
|
|
1778
|
+
return component;
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Delete a vector database configuration
|
|
1782
|
+
* @param tag Vector config tag
|
|
1783
|
+
*/
|
|
1784
|
+
async deleteVector(tag) {
|
|
1785
|
+
try {
|
|
1786
|
+
const vector = await this.fetchVector(tag);
|
|
1787
|
+
if (!vector) {
|
|
1788
|
+
throw new Error(`Vector with tag: ${tag} not found`);
|
|
1789
|
+
}
|
|
1790
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1791
|
+
tag,
|
|
1792
|
+
component: enums_1.ProductComponents.VECTOR,
|
|
1793
|
+
action: enums_1.RequestAction.DELETE,
|
|
1794
|
+
}, this.getUserAccess());
|
|
1795
|
+
}
|
|
1796
|
+
catch (e) {
|
|
1797
|
+
throw e;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
// ==================== VECTOR ACTION METHODS ====================
|
|
1801
|
+
/**
|
|
1802
|
+
* Create a new vector action
|
|
1803
|
+
* @param vectorTag Vector database tag
|
|
1804
|
+
* @param data Vector action data
|
|
1805
|
+
* @returns Created vector action
|
|
1806
|
+
*/
|
|
1807
|
+
async createVectorAction(vectorTag, data) {
|
|
1808
|
+
try {
|
|
1809
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1810
|
+
if (!vector) {
|
|
1811
|
+
throw new Error(`Vector with tag: ${vectorTag} not found`);
|
|
1812
|
+
}
|
|
1813
|
+
if (!data.tag) {
|
|
1814
|
+
throw new Error('Action tag is required');
|
|
1815
|
+
}
|
|
1816
|
+
if (!data.name) {
|
|
1817
|
+
throw new Error('Action name is required');
|
|
1818
|
+
}
|
|
1819
|
+
// Parse the tag to get action-only part (format: vector_tag:action_tag)
|
|
1820
|
+
const tagParts = data.tag.split(':');
|
|
1821
|
+
const actionTag = tagParts.length > 1 ? tagParts[tagParts.length - 1] : data.tag;
|
|
1822
|
+
// Check if action already exists
|
|
1823
|
+
const existingActions = vector.actions || [];
|
|
1824
|
+
const exists = existingActions.find(a => a.tag === data.tag || a.tag === `${vectorTag}:${actionTag}`);
|
|
1825
|
+
if (exists) {
|
|
1826
|
+
throw new Error(`Vector action with tag: ${data.tag} already exists`);
|
|
1827
|
+
}
|
|
1828
|
+
// Build the full action tag
|
|
1829
|
+
const fullTag = data.tag.includes(':') ? data.tag : `${vectorTag}:${actionTag}`;
|
|
1830
|
+
const newAction = {
|
|
1831
|
+
name: data.name,
|
|
1832
|
+
tag: fullTag,
|
|
1833
|
+
description: data.description,
|
|
1834
|
+
type: data.type,
|
|
1835
|
+
template: data.template || { options: {} },
|
|
1836
|
+
parameters: data.parameters || [],
|
|
1837
|
+
created_at: new Date(),
|
|
1838
|
+
updated_at: new Date(),
|
|
1839
|
+
};
|
|
1840
|
+
// Add to vector's actions array
|
|
1841
|
+
const updatedActions = [...existingActions, newAction];
|
|
1842
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1843
|
+
tag: vectorTag,
|
|
1844
|
+
actions: updatedActions,
|
|
1845
|
+
component: enums_1.ProductComponents.VECTOR,
|
|
1846
|
+
action: enums_1.RequestAction.UPDATE,
|
|
1847
|
+
}, this.getUserAccess());
|
|
1848
|
+
return newAction;
|
|
1849
|
+
}
|
|
1850
|
+
catch (e) {
|
|
1851
|
+
throw e;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Update an existing vector action
|
|
1856
|
+
* @param vectorTag Vector database tag
|
|
1857
|
+
* @param data Vector action update data (must include tag)
|
|
1858
|
+
* @returns Updated vector action
|
|
1859
|
+
*/
|
|
1860
|
+
async updateVectorAction(vectorTag, data) {
|
|
1861
|
+
try {
|
|
1862
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1863
|
+
if (!vector) {
|
|
1864
|
+
throw new Error(`Vector with tag: ${vectorTag} not found`);
|
|
1865
|
+
}
|
|
1866
|
+
if (!data.tag) {
|
|
1867
|
+
throw new Error('Action tag is required');
|
|
1868
|
+
}
|
|
1869
|
+
const existingActions = vector.actions || [];
|
|
1870
|
+
const actionIndex = existingActions.findIndex(a => a.tag === data.tag);
|
|
1871
|
+
if (actionIndex === -1) {
|
|
1872
|
+
throw new Error(`Vector action with tag: ${data.tag} not found`);
|
|
1873
|
+
}
|
|
1874
|
+
// Merge with existing action
|
|
1875
|
+
const updatedAction = Object.assign(Object.assign(Object.assign({}, existingActions[actionIndex]), data), { updated_at: new Date() });
|
|
1876
|
+
// Update in the array
|
|
1877
|
+
const updatedActions = [...existingActions];
|
|
1878
|
+
updatedActions[actionIndex] = updatedAction;
|
|
1879
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1880
|
+
tag: vectorTag,
|
|
1881
|
+
actions: updatedActions,
|
|
1882
|
+
component: enums_1.ProductComponents.VECTOR,
|
|
1883
|
+
action: enums_1.RequestAction.UPDATE,
|
|
1884
|
+
}, this.getUserAccess());
|
|
1885
|
+
return updatedAction;
|
|
1886
|
+
}
|
|
1887
|
+
catch (e) {
|
|
1888
|
+
throw e;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
* Fetch a specific vector action
|
|
1893
|
+
* @param vectorTag Vector database tag
|
|
1894
|
+
* @param actionTag Action tag
|
|
1895
|
+
* @returns Vector action or null
|
|
1896
|
+
*/
|
|
1897
|
+
async fetchVectorAction(vectorTag, actionTag) {
|
|
1898
|
+
try {
|
|
1899
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1900
|
+
if (!vector) {
|
|
1901
|
+
return null;
|
|
1902
|
+
}
|
|
1903
|
+
const actions = vector.actions || [];
|
|
1904
|
+
const action = actions.find(a => a.tag === actionTag || a.tag === `${vectorTag}:${actionTag}`);
|
|
1905
|
+
return action || null;
|
|
1906
|
+
}
|
|
1907
|
+
catch (e) {
|
|
1908
|
+
throw e;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Fetch all vector actions for a vector database
|
|
1913
|
+
* @param vectorTag Vector database tag
|
|
1914
|
+
* @returns Array of vector actions
|
|
1915
|
+
*/
|
|
1916
|
+
async fetchVectorActions(vectorTag) {
|
|
1917
|
+
try {
|
|
1918
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1919
|
+
if (!vector) {
|
|
1920
|
+
return [];
|
|
1921
|
+
}
|
|
1922
|
+
return vector.actions || [];
|
|
1923
|
+
}
|
|
1924
|
+
catch (e) {
|
|
1925
|
+
throw e;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
/**
|
|
1929
|
+
* Delete a vector action
|
|
1930
|
+
* @param vectorTag Vector database tag
|
|
1931
|
+
* @param actionTag Action tag to delete
|
|
1932
|
+
*/
|
|
1933
|
+
async deleteVectorAction(vectorTag, actionTag) {
|
|
1934
|
+
try {
|
|
1935
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1936
|
+
if (!vector) {
|
|
1937
|
+
throw new Error(`Vector with tag: ${vectorTag} not found`);
|
|
1938
|
+
}
|
|
1939
|
+
const existingActions = vector.actions || [];
|
|
1940
|
+
const actionIndex = existingActions.findIndex(a => a.tag === actionTag || a.tag === `${vectorTag}:${actionTag}`);
|
|
1941
|
+
if (actionIndex === -1) {
|
|
1942
|
+
throw new Error(`Vector action with tag: ${actionTag} not found`);
|
|
1943
|
+
}
|
|
1944
|
+
// Remove from array
|
|
1945
|
+
const updatedActions = existingActions.filter((_, idx) => idx !== actionIndex);
|
|
1946
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1947
|
+
tag: vectorTag,
|
|
1948
|
+
actions: updatedActions,
|
|
1949
|
+
component: enums_1.ProductComponents.VECTOR,
|
|
1950
|
+
action: enums_1.RequestAction.UPDATE,
|
|
1951
|
+
}, this.getUserAccess());
|
|
1952
|
+
}
|
|
1953
|
+
catch (e) {
|
|
1954
|
+
throw e;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
// ==================== AGENT METHODS ====================
|
|
1958
|
+
/**
|
|
1959
|
+
* Create a new agent configuration
|
|
1960
|
+
* @param data Agent configuration data
|
|
1961
|
+
* @param throwErrorIfExists Whether to throw an error if agent already exists
|
|
1962
|
+
*/
|
|
1963
|
+
async createAgent(data, throwErrorIfExists = false) {
|
|
1964
|
+
if (!(await this.fetchAgent(data.tag))) {
|
|
1965
|
+
await validators_1.CreateProductAgentSchema.validateAsync(data);
|
|
1966
|
+
// Validate envs if provided
|
|
1967
|
+
if (data.envs) {
|
|
1968
|
+
for (const env of data.envs) {
|
|
1969
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1970
|
+
if (!exists) {
|
|
1971
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
// Validate that all product envs are configured
|
|
1976
|
+
const envs = await this.fetchEnvs();
|
|
1977
|
+
if (data.envs) {
|
|
1978
|
+
for (const env of envs) {
|
|
1979
|
+
const exists = data.envs.findIndex((agentEnv) => agentEnv.slug === env.slug);
|
|
1980
|
+
if (exists === -1) {
|
|
1981
|
+
// Auto-add missing envs with default config
|
|
1982
|
+
data.envs.push({ slug: env.slug, active: true });
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
else {
|
|
1987
|
+
// Initialize envs with all product envs
|
|
1988
|
+
data.envs = envs.map((env) => ({ slug: env.slug, active: true }));
|
|
1989
|
+
}
|
|
1990
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.AGENT, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1991
|
+
}
|
|
1992
|
+
else {
|
|
1993
|
+
if (throwErrorIfExists)
|
|
1994
|
+
throw new Error(`Agent ${data.tag} already exists`);
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
* Update an existing agent configuration
|
|
1999
|
+
* @param tag Agent tag
|
|
2000
|
+
* @param data Updated agent configuration
|
|
2001
|
+
*/
|
|
2002
|
+
async updateAgent(tag, data) {
|
|
2003
|
+
try {
|
|
2004
|
+
const agent = await this.fetchAgent(tag);
|
|
2005
|
+
if (!agent) {
|
|
2006
|
+
throw new Error(`Agent ${tag} not found`);
|
|
2007
|
+
}
|
|
2008
|
+
const { _id, envs } = agent;
|
|
2009
|
+
await validators_1.UpdateProductAgentSchema.validateAsync(data);
|
|
2010
|
+
if (data.tag && data.tag !== tag && (await this.fetchAgent(data.tag))) {
|
|
2011
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
2012
|
+
}
|
|
2013
|
+
if (data.envs) {
|
|
2014
|
+
// Validate that all provided envs exist
|
|
2015
|
+
for (const env of data.envs) {
|
|
2016
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2017
|
+
if (!exists) {
|
|
2018
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
const overwrite = [];
|
|
2022
|
+
const newEnvs = [];
|
|
2023
|
+
data.envs.forEach((dataEnv) => {
|
|
2024
|
+
var _a;
|
|
2025
|
+
const existsIdx = (_a = envs === null || envs === void 0 ? void 0 : envs.findIndex((env) => env.slug === dataEnv.slug)) !== null && _a !== void 0 ? _a : -1;
|
|
2026
|
+
if (existsIdx === -1) {
|
|
2027
|
+
newEnvs.push(dataEnv);
|
|
2028
|
+
}
|
|
2029
|
+
else {
|
|
2030
|
+
overwrite.push(Object.assign(Object.assign({}, envs[existsIdx]), dataEnv));
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
const unchanged = [];
|
|
2034
|
+
envs === null || envs === void 0 ? void 0 : envs.forEach((env) => {
|
|
2035
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
2036
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
2037
|
+
if (!newEnv && !overwriteEnv) {
|
|
2038
|
+
unchanged.push(env);
|
|
2039
|
+
}
|
|
2040
|
+
});
|
|
2041
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
2042
|
+
}
|
|
2043
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, agent), data), { component: enums_1.ProductComponents.AGENT, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
2044
|
+
}
|
|
2045
|
+
catch (e) {
|
|
2046
|
+
throw e;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Fetch all agent configurations
|
|
2051
|
+
* @param version Optional version
|
|
2052
|
+
*/
|
|
2053
|
+
async fetchAgents(version) {
|
|
2054
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'agent', this.getUserAccess());
|
|
2055
|
+
return components;
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Fetch a specific agent configuration by tag
|
|
2059
|
+
* @param tag Agent tag
|
|
2060
|
+
* @param version Optional version
|
|
2061
|
+
*/
|
|
2062
|
+
async fetchAgent(tag, version) {
|
|
2063
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'agent', tag, this.getUserAccess());
|
|
2064
|
+
return component;
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* Delete an agent configuration
|
|
2068
|
+
* @param tag Agent tag
|
|
2069
|
+
*/
|
|
2070
|
+
async deleteAgent(tag) {
|
|
2071
|
+
try {
|
|
2072
|
+
const agent = await this.fetchAgent(tag);
|
|
2073
|
+
if (!agent) {
|
|
2074
|
+
throw new Error(`Agent with tag: ${tag} not found`);
|
|
2075
|
+
}
|
|
2076
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2077
|
+
tag,
|
|
2078
|
+
component: enums_1.ProductComponents.AGENT,
|
|
2079
|
+
action: enums_1.RequestAction.DELETE,
|
|
2080
|
+
}, this.getUserAccess());
|
|
2081
|
+
}
|
|
2082
|
+
catch (e) {
|
|
2083
|
+
throw e;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
// ==================== LLM MODEL METHODS ====================
|
|
2087
|
+
/**
|
|
2088
|
+
* Create a new LLM model configuration
|
|
2089
|
+
* API keys are automatically encrypted using the product's private key
|
|
2090
|
+
* @param data LLM model configuration
|
|
2091
|
+
* @param throwErrorIfExists Whether to throw error if model already exists
|
|
2092
|
+
*/
|
|
2093
|
+
async createModel(data, throwErrorIfExists = false) {
|
|
2094
|
+
if (!(await this.fetchModel(data.tag))) {
|
|
2095
|
+
await validators_1.CreateProductModelSchema.validateAsync(data);
|
|
2096
|
+
const processedEnvs = [];
|
|
2097
|
+
for (const env of data.envs) {
|
|
2098
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2099
|
+
if (!exists) {
|
|
2100
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
2101
|
+
}
|
|
2102
|
+
// Store API key as secret and encrypt
|
|
2103
|
+
if (env.apiKey) {
|
|
2104
|
+
env.apiKey = await this.storeModelApiKeyAsSecret(env.apiKey, data.tag, env.slug);
|
|
2105
|
+
env.apiKey = (0, processor_utils_1.encrypt)(env.apiKey, this.product.private_key);
|
|
2106
|
+
}
|
|
2107
|
+
processedEnvs.push(env);
|
|
2108
|
+
}
|
|
2109
|
+
data.envs = processedEnvs;
|
|
2110
|
+
const envs = await this.fetchEnvs();
|
|
2111
|
+
for (const env of envs) {
|
|
2112
|
+
const exists = data.envs.findIndex((modelEnv) => modelEnv.slug === env.slug);
|
|
2113
|
+
if (exists === -1) {
|
|
2114
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide API key configuration`);
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.MODEL, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2118
|
+
}
|
|
2119
|
+
else {
|
|
2120
|
+
if (throwErrorIfExists)
|
|
2121
|
+
throw new Error(`Model ${data.tag} already exists`);
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Update an existing LLM model configuration
|
|
2126
|
+
* @param tag Model tag
|
|
2127
|
+
* @param data Updated model configuration
|
|
2128
|
+
*/
|
|
2129
|
+
async updateModel(tag, data) {
|
|
2130
|
+
try {
|
|
2131
|
+
const model = await this.fetchModel(tag);
|
|
2132
|
+
if (!model) {
|
|
2133
|
+
throw new Error(`Model ${tag} not found`);
|
|
2134
|
+
}
|
|
2135
|
+
const { _id, envs } = model;
|
|
2136
|
+
await validators_1.UpdateProductModelSchema.validateAsync(data);
|
|
2137
|
+
if (data.tag && (await this.fetchModel(data.tag))) {
|
|
2138
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
2139
|
+
}
|
|
2140
|
+
if (data.envs) {
|
|
2141
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
2142
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2143
|
+
if (!exists) {
|
|
2144
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
2145
|
+
}
|
|
2146
|
+
// Store API key as secret and encrypt
|
|
2147
|
+
if (env.apiKey) {
|
|
2148
|
+
env.apiKey = await this.storeModelApiKeyAsSecret(env.apiKey, data.tag || tag, env.slug);
|
|
2149
|
+
env.apiKey = (0, processor_utils_1.encrypt)(env.apiKey, this.product.private_key);
|
|
2150
|
+
}
|
|
2151
|
+
return env;
|
|
2152
|
+
}));
|
|
2153
|
+
const overwrite = [];
|
|
2154
|
+
const newEnvs = [];
|
|
2155
|
+
data.envs.forEach((dataEnv) => {
|
|
2156
|
+
const existsIdx = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
2157
|
+
if (existsIdx === -1) {
|
|
2158
|
+
newEnvs.push(dataEnv);
|
|
2159
|
+
}
|
|
2160
|
+
else {
|
|
2161
|
+
overwrite.push(Object.assign(Object.assign({}, envs[existsIdx]), dataEnv));
|
|
2162
|
+
}
|
|
2163
|
+
});
|
|
2164
|
+
const unchanged = [];
|
|
2165
|
+
envs.forEach((env) => {
|
|
2166
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
2167
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
2168
|
+
if (!newEnv && !overwriteEnv) {
|
|
2169
|
+
unchanged.push(env);
|
|
2170
|
+
}
|
|
2171
|
+
});
|
|
2172
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
2173
|
+
}
|
|
2174
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, model), data), { component: enums_1.ProductComponents.MODEL, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
2175
|
+
}
|
|
2176
|
+
catch (e) {
|
|
2177
|
+
throw e;
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
/**
|
|
2181
|
+
* Fetch all LLM model configurations
|
|
2182
|
+
* @param version Optional version
|
|
2183
|
+
*/
|
|
2184
|
+
async fetchModels(version) {
|
|
2185
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'model', this.getUserAccess());
|
|
2186
|
+
return components;
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Fetch a specific LLM model configuration by tag
|
|
2190
|
+
* @param tag Model tag
|
|
2191
|
+
* @param version Optional version
|
|
2192
|
+
*/
|
|
2193
|
+
async fetchModel(tag, version) {
|
|
2194
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'model', tag, this.getUserAccess());
|
|
2195
|
+
return component;
|
|
2196
|
+
}
|
|
2197
|
+
/**
|
|
2198
|
+
* Delete an LLM model configuration
|
|
2199
|
+
* @param tag Model tag
|
|
2200
|
+
*/
|
|
2201
|
+
async deleteModel(tag) {
|
|
2202
|
+
try {
|
|
2203
|
+
const model = await this.fetchModel(tag);
|
|
2204
|
+
if (!model) {
|
|
2205
|
+
throw new Error(`Model with tag: ${tag} not found`);
|
|
2206
|
+
}
|
|
2207
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2208
|
+
tag,
|
|
2209
|
+
component: enums_1.ProductComponents.MODEL,
|
|
2210
|
+
action: enums_1.RequestAction.DELETE,
|
|
2211
|
+
}, this.getUserAccess());
|
|
2212
|
+
}
|
|
2213
|
+
catch (e) {
|
|
2214
|
+
throw e;
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
1059
2217
|
async validateAppData(appData, app) {
|
|
1060
2218
|
// TODO:
|
|
1061
2219
|
const { envs } = app;
|
|
@@ -1077,6 +2235,9 @@ class ProductsBuilderService {
|
|
|
1077
2235
|
}
|
|
1078
2236
|
}
|
|
1079
2237
|
validateVariablesValues(variables, appVariables) {
|
|
2238
|
+
if (!variables) {
|
|
2239
|
+
variables = [];
|
|
2240
|
+
}
|
|
1080
2241
|
if (appVariables && appVariables.length) {
|
|
1081
2242
|
appVariables.map((data) => {
|
|
1082
2243
|
const find = variables.find((value) => value.key === data.key);
|
|
@@ -1093,7 +2254,7 @@ class ProductsBuilderService {
|
|
|
1093
2254
|
const { envs: appEnvs } = version;
|
|
1094
2255
|
return envs.map((env) => {
|
|
1095
2256
|
const { auth } = env;
|
|
1096
|
-
this.fetchEnv(env.product_env_slug
|
|
2257
|
+
this.fetchEnv(env.product_env_slug);
|
|
1097
2258
|
const appEnv = appEnvs.find((appEnv) => appEnv.slug === env.app_env_slug);
|
|
1098
2259
|
if (!appEnv) {
|
|
1099
2260
|
throw new Error(`app_slug ${env.app_env_slug} not found`);
|
|
@@ -1183,10 +2344,10 @@ class ProductsBuilderService {
|
|
|
1183
2344
|
});
|
|
1184
2345
|
(0, inputs_utils_create_1.validateInputSchema)(queryValues, querySchema);
|
|
1185
2346
|
}
|
|
1186
|
-
const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.
|
|
2347
|
+
const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.product.private_key);
|
|
1187
2348
|
let updateValues = null;
|
|
1188
2349
|
if (exists.setup_type === enums_1.AuthTypes.TOKEN) {
|
|
1189
|
-
updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.
|
|
2350
|
+
updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.product.private_key);
|
|
1190
2351
|
}
|
|
1191
2352
|
return { data: updateData, values: updateValues };
|
|
1192
2353
|
}
|
|
@@ -1219,8 +2380,10 @@ class ProductsBuilderService {
|
|
|
1219
2380
|
throw new Error(`App ${app.access_tag} not found`);
|
|
1220
2381
|
}
|
|
1221
2382
|
const cleanedAppData = await this.validateAppData(appData, app);
|
|
1222
|
-
|
|
1223
|
-
|
|
2383
|
+
if (!cleanedAppData.pricing_tag) {
|
|
2384
|
+
cleanedAppData.pricing_tag = `${appData.tag}:${productsBuilder_types_1.PricingTag.FREE}`;
|
|
2385
|
+
}
|
|
2386
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, cleanedAppData), { app_tag: appData.tag, component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1224
2387
|
}
|
|
1225
2388
|
else {
|
|
1226
2389
|
if (throwErrorIfExists)
|
|
@@ -1251,7 +2414,7 @@ class ProductsBuilderService {
|
|
|
1251
2414
|
}
|
|
1252
2415
|
async updateApp(access_tag, data) {
|
|
1253
2416
|
try {
|
|
1254
|
-
const app = this.fetchApp(access_tag);
|
|
2417
|
+
const app = await this.fetchApp(access_tag);
|
|
1255
2418
|
if (!app) {
|
|
1256
2419
|
throw new Error(`App ${access_tag} not found`);
|
|
1257
2420
|
}
|
|
@@ -1267,28 +2430,43 @@ class ProductsBuilderService {
|
|
|
1267
2430
|
throw new Error(`access_tag ${access_tag} is in use`); // TODO: also check on the backend
|
|
1268
2431
|
}*/
|
|
1269
2432
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { access_tag, component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1270
|
-
await this.initializeProduct(this.product_id);
|
|
1271
2433
|
}
|
|
1272
2434
|
catch (e) {
|
|
1273
2435
|
throw e;
|
|
1274
2436
|
}
|
|
1275
2437
|
}
|
|
1276
|
-
fetchApps() {
|
|
2438
|
+
async fetchApps() {
|
|
1277
2439
|
return this.product.apps;
|
|
1278
2440
|
}
|
|
1279
|
-
fetchApp(tag, throwErrorIfExists = false) {
|
|
1280
|
-
const app = this.product.apps.find((data) => data.access_tag === tag);
|
|
2441
|
+
async fetchApp(tag, throwErrorIfExists = false) {
|
|
2442
|
+
const app = this.product.apps.find((data) => data.app_tag === tag || data.access_tag === tag);
|
|
1281
2443
|
if (!app && throwErrorIfExists)
|
|
1282
2444
|
throw new Error(`App ${tag} not found`);
|
|
1283
2445
|
return app;
|
|
1284
2446
|
}
|
|
2447
|
+
async deleteApp(tag) {
|
|
2448
|
+
try {
|
|
2449
|
+
const app = await this.fetchApp(tag, true);
|
|
2450
|
+
if (!app) {
|
|
2451
|
+
throw new Error(`App with tag: ${tag} not found`);
|
|
2452
|
+
}
|
|
2453
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2454
|
+
tag: app.access_tag,
|
|
2455
|
+
component: enums_1.ProductComponents.APP,
|
|
2456
|
+
action: enums_1.RequestAction.DELETE,
|
|
2457
|
+
}, this.getUserAccess());
|
|
2458
|
+
}
|
|
2459
|
+
catch (e) {
|
|
2460
|
+
throw e;
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
1285
2463
|
async createFunction(data, throwErrorIfExists = false) {
|
|
1286
2464
|
try {
|
|
1287
2465
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1288
|
-
if (!this.fetchFunction(data.tag)) {
|
|
2466
|
+
if (!(await this.fetchFunction(data.tag))) {
|
|
1289
2467
|
await validators_1.CreateProductFunctionSchema.validateAsync(data);
|
|
1290
2468
|
data.envs.map((env) => {
|
|
1291
|
-
env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.
|
|
2469
|
+
env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.product.private_key);
|
|
1292
2470
|
});
|
|
1293
2471
|
data.sample_data = (await this.inputsService.parseJson({
|
|
1294
2472
|
data: data.sample,
|
|
@@ -1301,7 +2479,6 @@ class ProductsBuilderService {
|
|
|
1301
2479
|
category: enums_1.Categories.DATA,
|
|
1302
2480
|
}));
|
|
1303
2481
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FUNCTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1304
|
-
await this.initializeProduct(this.product_id);
|
|
1305
2482
|
}
|
|
1306
2483
|
else {
|
|
1307
2484
|
if (throwErrorIfExists)
|
|
@@ -1314,37 +2491,51 @@ class ProductsBuilderService {
|
|
|
1314
2491
|
}
|
|
1315
2492
|
async updateFunction(tag, data) {
|
|
1316
2493
|
try {
|
|
1317
|
-
const func = this.fetchFunction(tag);
|
|
2494
|
+
const func = await this.fetchFunction(tag);
|
|
1318
2495
|
if (!func) {
|
|
1319
2496
|
throw new Error(`Function ${tag} not found`);
|
|
1320
2497
|
}
|
|
1321
2498
|
const { _id } = func;
|
|
1322
2499
|
await validators_1.UpdateProductFunctionSchema.validateAsync(data); // Change to update;
|
|
1323
|
-
if (data.tag && this.fetchFunction(data.tag)) {
|
|
2500
|
+
if (data.tag && (await this.fetchFunction(data.tag))) {
|
|
1324
2501
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1325
2502
|
}
|
|
1326
2503
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, func), data), { component: enums_1.ProductComponents.FUNCTION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1327
|
-
await this.initializeProduct(this.product_id);
|
|
1328
2504
|
}
|
|
1329
2505
|
catch (e) {
|
|
1330
2506
|
throw e;
|
|
1331
2507
|
}
|
|
1332
2508
|
}
|
|
1333
|
-
fetchFunctions() {
|
|
1334
|
-
|
|
2509
|
+
async fetchFunctions(version) {
|
|
2510
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'function', this.getUserAccess());
|
|
2511
|
+
return components;
|
|
1335
2512
|
}
|
|
1336
|
-
fetchFunction(tag) {
|
|
1337
|
-
const
|
|
1338
|
-
|
|
1339
|
-
|
|
2513
|
+
async fetchFunction(tag, version) {
|
|
2514
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'function', tag, this.getUserAccess());
|
|
2515
|
+
return component;
|
|
2516
|
+
}
|
|
2517
|
+
async deleteFunction(tag) {
|
|
2518
|
+
try {
|
|
2519
|
+
const func = await this.fetchFunction(tag);
|
|
2520
|
+
if (!func) {
|
|
2521
|
+
throw new Error(`Function with tag: ${tag} not found`);
|
|
2522
|
+
}
|
|
2523
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2524
|
+
tag,
|
|
2525
|
+
component: enums_1.ProductComponents.FUNCTION,
|
|
2526
|
+
action: enums_1.RequestAction.DELETE,
|
|
2527
|
+
}, this.getUserAccess());
|
|
2528
|
+
}
|
|
2529
|
+
catch (e) {
|
|
2530
|
+
throw e;
|
|
2531
|
+
}
|
|
1340
2532
|
}
|
|
1341
2533
|
async createCache(data, throwErrorIfExists = false) {
|
|
1342
2534
|
try {
|
|
1343
2535
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1344
|
-
if (!this.fetchCache(data.tag)) {
|
|
2536
|
+
if (!(await this.fetchCache(data.tag))) {
|
|
1345
2537
|
await validators_1.CreateProductCacheSchema.validateAsync(data);
|
|
1346
2538
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.CACHE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1347
|
-
await this.initializeProduct(this.product_id);
|
|
1348
2539
|
}
|
|
1349
2540
|
else {
|
|
1350
2541
|
if (throwErrorIfExists)
|
|
@@ -1357,62 +2548,75 @@ class ProductsBuilderService {
|
|
|
1357
2548
|
}
|
|
1358
2549
|
async updateCache(tag, data) {
|
|
1359
2550
|
try {
|
|
1360
|
-
const cache = this.fetchCache(tag);
|
|
2551
|
+
const cache = await this.fetchCache(tag);
|
|
1361
2552
|
if (!cache) {
|
|
1362
2553
|
throw new Error(`Cache ${tag} not found`);
|
|
1363
2554
|
}
|
|
1364
2555
|
const { _id } = cache;
|
|
1365
2556
|
await validators_1.UpdateProductCacheSchema.validateAsync(data); // Change to update;
|
|
1366
|
-
if (data.tag && this.fetchCache(data.tag)) {
|
|
2557
|
+
if (data.tag && (await this.fetchCache(data.tag))) {
|
|
1367
2558
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1368
2559
|
}
|
|
1369
2560
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { component: enums_1.ProductComponents.CACHE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1370
|
-
await this.initializeProduct(this.product_id);
|
|
1371
2561
|
}
|
|
1372
2562
|
catch (e) {
|
|
1373
2563
|
throw e;
|
|
1374
2564
|
}
|
|
1375
2565
|
}
|
|
1376
|
-
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
throw new Error(`Cache ${tag} not found`);
|
|
1380
|
-
return cache;
|
|
2566
|
+
async fetchCaches(version) {
|
|
2567
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'cache', this.getUserAccess());
|
|
2568
|
+
return components;
|
|
1381
2569
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
2570
|
+
async fetchCache(tag, version) {
|
|
2571
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'cache', tag, this.getUserAccess());
|
|
2572
|
+
return component;
|
|
2573
|
+
}
|
|
2574
|
+
async deleteCache(tag) {
|
|
2575
|
+
try {
|
|
2576
|
+
const cache = await this.fetchCache(tag);
|
|
2577
|
+
if (!cache) {
|
|
2578
|
+
throw new Error(`Cache with tag: ${tag} not found`);
|
|
2579
|
+
}
|
|
2580
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2581
|
+
tag,
|
|
2582
|
+
component: enums_1.ProductComponents.CACHE,
|
|
2583
|
+
action: enums_1.RequestAction.DELETE,
|
|
2584
|
+
}, this.getUserAccess());
|
|
2585
|
+
}
|
|
2586
|
+
catch (e) {
|
|
2587
|
+
throw e;
|
|
2588
|
+
}
|
|
1384
2589
|
}
|
|
1385
2590
|
async createNotification(data, throwErrorIfExists = false) {
|
|
1386
2591
|
try {
|
|
1387
2592
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1388
|
-
if (!this.fetchNotification(data.tag)) {
|
|
2593
|
+
if (!(await this.fetchNotification(data.tag))) {
|
|
1389
2594
|
await validators_1.CreateProductNotificationSchema.validateAsync(data);
|
|
1390
|
-
const envs = this.fetchEnvs();
|
|
1391
|
-
|
|
2595
|
+
const envs = await this.fetchEnvs();
|
|
2596
|
+
for (const env of envs) {
|
|
1392
2597
|
const exists = data.envs.findIndex((nEnv) => nEnv.slug === env.slug);
|
|
1393
2598
|
if (exists === -1) {
|
|
1394
2599
|
throw new Error(`Notification for environment ${env.slug} is not defined, please provide the environment details`);
|
|
1395
2600
|
}
|
|
1396
|
-
}
|
|
2601
|
+
}
|
|
1397
2602
|
for (let i = 0; i < data.envs.length; i++) {
|
|
2603
|
+
// Process secrets for each notification handler
|
|
2604
|
+
const processedEnv = await this.processNotificationEnvSecrets(data.envs[i], data.tag, data.envs[i].slug);
|
|
1398
2605
|
const updates = {
|
|
1399
|
-
push_notifications:
|
|
1400
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(
|
|
2606
|
+
push_notifications: processedEnv.push_notifications
|
|
2607
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.push_notifications), this.product.private_key)
|
|
1401
2608
|
: undefined,
|
|
1402
|
-
emails:
|
|
1403
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(
|
|
2609
|
+
emails: processedEnv.emails
|
|
2610
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.emails), this.product.private_key)
|
|
1404
2611
|
: undefined,
|
|
1405
|
-
callbacks:
|
|
1406
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(
|
|
1407
|
-
: undefined,
|
|
1408
|
-
sms: data.envs[i].sms
|
|
1409
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].sms), this.fetchProduct().private_key)
|
|
2612
|
+
callbacks: processedEnv.callbacks
|
|
2613
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.callbacks), this.product.private_key)
|
|
1410
2614
|
: undefined,
|
|
2615
|
+
sms: processedEnv.sms ? (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.sms), this.product.private_key) : undefined,
|
|
1411
2616
|
};
|
|
1412
2617
|
data.envs[i] = Object.assign(Object.assign({}, data.envs[i]), updates);
|
|
1413
2618
|
}
|
|
1414
2619
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1415
|
-
await this.initializeProduct(this.product_id);
|
|
1416
2620
|
}
|
|
1417
2621
|
else {
|
|
1418
2622
|
if (throwErrorIfExists)
|
|
@@ -1433,7 +2637,7 @@ class ProductsBuilderService {
|
|
|
1433
2637
|
if (!notificationTag || !tag) {
|
|
1434
2638
|
throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
|
|
1435
2639
|
}
|
|
1436
|
-
const exists = this.fetchNotificationMessage(data.tag);
|
|
2640
|
+
const exists = await this.fetchNotificationMessage(data.tag);
|
|
1437
2641
|
data.tag = tag;
|
|
1438
2642
|
if (!exists) {
|
|
1439
2643
|
if (!data.email && !data.push_notification && !data.callback) {
|
|
@@ -1470,7 +2674,6 @@ class ProductsBuilderService {
|
|
|
1470
2674
|
data.sms_data = (0, string_utils_1.extractPlaceholders)(data.sms, '');
|
|
1471
2675
|
}
|
|
1472
2676
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { notificationTag, component: enums_1.ProductComponents.NOTIFICATION_MESSAGE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1473
|
-
await this.initializeProduct(this.product_id);
|
|
1474
2677
|
}
|
|
1475
2678
|
else {
|
|
1476
2679
|
if (throwErrorIfExists)
|
|
@@ -1481,12 +2684,12 @@ class ProductsBuilderService {
|
|
|
1481
2684
|
throw e;
|
|
1482
2685
|
}
|
|
1483
2686
|
}
|
|
1484
|
-
fetchNotificationMessage(tag, throwErrorIfExists = false) {
|
|
2687
|
+
async fetchNotificationMessage(tag, throwErrorIfExists = false) {
|
|
1485
2688
|
const [notificationTag, messageTag] = tag.split(':');
|
|
1486
2689
|
if (!notificationTag || !messageTag) {
|
|
1487
2690
|
throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
|
|
1488
2691
|
}
|
|
1489
|
-
const notification = this.fetchNotification(notificationTag);
|
|
2692
|
+
const notification = await this.fetchNotification(notificationTag);
|
|
1490
2693
|
if (!notification)
|
|
1491
2694
|
throw new Error(`Notification ${notificationTag} not found`);
|
|
1492
2695
|
const message = notification.messages.find((data) => data.tag === messageTag);
|
|
@@ -1494,7 +2697,7 @@ class ProductsBuilderService {
|
|
|
1494
2697
|
throw new Error(`Notification message ${tag} not found`);
|
|
1495
2698
|
return message;
|
|
1496
2699
|
}
|
|
1497
|
-
fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
|
|
2700
|
+
async fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
|
|
1498
2701
|
const notification = this.product.notifications.find((data) => data.tag === notificationTag);
|
|
1499
2702
|
if (!notification)
|
|
1500
2703
|
throw new Error(`Notification ${notificationTag} not found`);
|
|
@@ -1502,7 +2705,7 @@ class ProductsBuilderService {
|
|
|
1502
2705
|
}
|
|
1503
2706
|
async updateNotificationMessage(data) {
|
|
1504
2707
|
try {
|
|
1505
|
-
console.log(
|
|
2708
|
+
console.log('NOTIFICATION DATA!!', data);
|
|
1506
2709
|
await update_productNotificationMessage_validator_1.default.validateAsync(data);
|
|
1507
2710
|
if (!data.tag) {
|
|
1508
2711
|
throw new Error('tag field is required');
|
|
@@ -1548,7 +2751,6 @@ class ProductsBuilderService {
|
|
|
1548
2751
|
const payload = Object.assign(Object.assign(Object.assign({}, message), data), { notificationTag, component: enums_1.ProductComponents.NOTIFICATION_MESSAGE, action: enums_1.RequestAction.UPDATE });
|
|
1549
2752
|
// Update product and reinitialize
|
|
1550
2753
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
1551
|
-
await this.initializeProduct(this.product_id);
|
|
1552
2754
|
}
|
|
1553
2755
|
catch (error) {
|
|
1554
2756
|
throw error;
|
|
@@ -1556,21 +2758,25 @@ class ProductsBuilderService {
|
|
|
1556
2758
|
}
|
|
1557
2759
|
async updateNotification(tag, data) {
|
|
1558
2760
|
try {
|
|
1559
|
-
const
|
|
1560
|
-
if (
|
|
2761
|
+
const notificationResult = await this.fetchNotification(tag);
|
|
2762
|
+
if (!notificationResult) {
|
|
2763
|
+
throw new Error(`Notification with tag ${tag} not found`);
|
|
2764
|
+
}
|
|
2765
|
+
const { _id, envs } = notificationResult;
|
|
2766
|
+
if (data.tag && tag !== data.tag && (await this.fetchNotification(data.tag))) {
|
|
1561
2767
|
throw new Error(`Notification of tag ${data.tag} already exists`);
|
|
1562
2768
|
}
|
|
1563
2769
|
await validators_1.UpdateProductNotificationSchema.validateAsync(data); // Change to update;
|
|
1564
|
-
let notification = this.fetchNotification(tag);
|
|
2770
|
+
let notification = await this.fetchNotification(tag);
|
|
1565
2771
|
if (!notification) {
|
|
1566
2772
|
throw new Error(`Notification with tag ${tag} not found`);
|
|
1567
2773
|
}
|
|
1568
2774
|
if (data.envs) {
|
|
1569
2775
|
const overwrite = [];
|
|
1570
2776
|
const newEnvs = [];
|
|
1571
|
-
data.envs
|
|
2777
|
+
for (const dataEnv of data.envs) {
|
|
1572
2778
|
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1573
|
-
if (!this.fetchEnv(dataEnv.slug)) {
|
|
2779
|
+
if (!(await this.fetchEnv(dataEnv.slug))) {
|
|
1574
2780
|
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
1575
2781
|
}
|
|
1576
2782
|
if (exists === -1) {
|
|
@@ -1580,70 +2786,61 @@ class ProductsBuilderService {
|
|
|
1580
2786
|
else {
|
|
1581
2787
|
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1582
2788
|
}
|
|
1583
|
-
}
|
|
2789
|
+
}
|
|
1584
2790
|
const unchanged = [];
|
|
1585
|
-
|
|
2791
|
+
for (const env of envs) {
|
|
1586
2792
|
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1587
2793
|
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1588
2794
|
if (!newEnv && !overwriteEnv) {
|
|
1589
2795
|
unchanged.push(env);
|
|
1590
2796
|
}
|
|
1591
|
-
}
|
|
2797
|
+
}
|
|
1592
2798
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1593
2799
|
}
|
|
1594
2800
|
const update = Object.assign(Object.assign({}, notification), data);
|
|
1595
|
-
update.envs.
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
2801
|
+
for (let i = 0; i < update.envs.length; i++) {
|
|
2802
|
+
const env = update.envs[i];
|
|
2803
|
+
// Process secrets for each notification handler
|
|
2804
|
+
const processedEnv = await this.processNotificationEnvSecrets(env, data.tag || tag, env.slug);
|
|
2805
|
+
if (processedEnv.emails)
|
|
2806
|
+
update.envs[i].emails = (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.emails), this.product.private_key);
|
|
2807
|
+
if (processedEnv.push_notifications)
|
|
2808
|
+
update.envs[i].push_notifications = (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.push_notifications), this.product.private_key);
|
|
2809
|
+
if (processedEnv.callbacks)
|
|
2810
|
+
update.envs[i].callbacks = (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.callbacks), this.product.private_key);
|
|
2811
|
+
if (processedEnv.sms)
|
|
2812
|
+
update.envs[i].sms = (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.sms), this.product.private_key);
|
|
2813
|
+
}
|
|
1606
2814
|
const payload = Object.assign(Object.assign({ _id }, update), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.UPDATE });
|
|
1607
2815
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
1608
|
-
await this.initializeProduct(this.product_id);
|
|
1609
2816
|
}
|
|
1610
2817
|
catch (e) {
|
|
1611
2818
|
throw e;
|
|
1612
2819
|
}
|
|
1613
2820
|
}
|
|
1614
|
-
|
|
1615
|
-
const
|
|
1616
|
-
|
|
1617
|
-
throw new Error(`Notification ${tag} is in use`);
|
|
1618
|
-
/*if (notification_slug) {
|
|
1619
|
-
const { notifications, emails, callbacks } = notification.envs.find(
|
|
1620
|
-
(data: INotificationEnv) => (data.slug = notification_slug),
|
|
1621
|
-
);
|
|
1622
|
-
return { notifications, emails, callbacks };
|
|
1623
|
-
}*/
|
|
1624
|
-
if (notification) {
|
|
1625
|
-
notification.envs.map((data) => {
|
|
1626
|
-
if (data.callbacks && typeof data.callbacks == 'string') {
|
|
1627
|
-
data.callbacks = JSON.parse((0, processor_utils_1.decrypt)(String(data.callbacks), this.fetchProduct().private_key));
|
|
1628
|
-
}
|
|
1629
|
-
if (data.push_notifications && typeof data.push_notifications == 'string') {
|
|
1630
|
-
data.push_notifications = JSON.parse((0, processor_utils_1.decrypt)(String(data.push_notifications), this.fetchProduct().private_key));
|
|
1631
|
-
}
|
|
1632
|
-
if (data.emails && typeof data.emails == 'string') {
|
|
1633
|
-
data.emails = JSON.parse((0, processor_utils_1.decrypt)(String(data.emails), this.fetchProduct().private_key));
|
|
1634
|
-
}
|
|
1635
|
-
if (data.sms && typeof data.sms == 'string') {
|
|
1636
|
-
data.sms = JSON.parse((0, processor_utils_1.decrypt)(String(data.sms), this.fetchProduct().private_key));
|
|
1637
|
-
}
|
|
1638
|
-
return data;
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
return notification;
|
|
2821
|
+
async fetchNotifications(version) {
|
|
2822
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'notification', this.getUserAccess());
|
|
2823
|
+
return components;
|
|
1642
2824
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
2825
|
+
async fetchNotification(tag, version) {
|
|
2826
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'notification', tag, this.getUserAccess());
|
|
2827
|
+
return component;
|
|
2828
|
+
}
|
|
2829
|
+
async deleteNotification(tag) {
|
|
2830
|
+
try {
|
|
2831
|
+
const notification = await this.fetchNotification(tag);
|
|
2832
|
+
if (!notification) {
|
|
2833
|
+
throw new Error(`Notification with tag: ${tag} not found`);
|
|
2834
|
+
}
|
|
2835
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2836
|
+
tag,
|
|
2837
|
+
component: enums_1.ProductComponents.NOTIFICATION,
|
|
2838
|
+
action: enums_1.RequestAction.DELETE,
|
|
2839
|
+
}, this.getUserAccess());
|
|
2840
|
+
}
|
|
2841
|
+
catch (e) {
|
|
2842
|
+
throw e;
|
|
2843
|
+
}
|
|
1647
2844
|
}
|
|
1648
2845
|
validateFeatureSequence(array) {
|
|
1649
2846
|
// Validate uniqueness of sequence_tag
|
|
@@ -1743,24 +2940,27 @@ class ProductsBuilderService {
|
|
|
1743
2940
|
await this.validateActionDataInput(data, action, event.input, event_index, sequence_index);
|
|
1744
2941
|
}
|
|
1745
2942
|
async checkAndValidateFunctionDataInput(data, sequence_index, event, event_index) {
|
|
1746
|
-
const func = this.fetchFunction(event.event);
|
|
2943
|
+
const func = (await this.fetchFunction(event.event));
|
|
1747
2944
|
await this.validateActionDataInput(data, func, event.input, event_index, sequence_index);
|
|
1748
2945
|
}
|
|
1749
2946
|
async checkAndValidateDBActionDataInput(data, sequence_index, event, event_index) {
|
|
1750
2947
|
console.log('EVENTY', event.event);
|
|
1751
|
-
const { filterData, data: dbData, filterTemplate, template } = this.fetchDatabaseAction(event.event);
|
|
2948
|
+
const { filterData, data: dbData, filterTemplate, template } = await this.fetchDatabaseAction(event.event);
|
|
1752
2949
|
await this.validateDBActionDataInput(data, { filterData, data: dbData, template, filter: filterTemplate }, event.input, event_index, sequence_index);
|
|
1753
2950
|
}
|
|
1754
2951
|
async checkAndValidateFeatureDataInput(data, sequence_index, event, event_index) {
|
|
1755
|
-
const
|
|
2952
|
+
const feature = await this.fetchFeature(event.event);
|
|
2953
|
+
if (!feature)
|
|
2954
|
+
throw new Error(`Feature ${event.event} not found`);
|
|
2955
|
+
const { input } = feature;
|
|
1756
2956
|
await this.validateFeatureDataInput(data, input, event.input, event_index, sequence_index);
|
|
1757
2957
|
}
|
|
1758
2958
|
async checkAndValidateNotificationDataInput(data, sequence_index, event, event_index) {
|
|
1759
|
-
const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = this.fetchNotificationMessage(event.event);
|
|
2959
|
+
const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = await this.fetchNotificationMessage(event.event);
|
|
1760
2960
|
await this.validateNotificationDataInput(data, { callback, notification, email, sms }, event.input, event_index, sequence_index);
|
|
1761
2961
|
}
|
|
1762
2962
|
async checkAndValidatePublishDataInput(data, sequence_index, event, event_index) {
|
|
1763
|
-
const topic = this.fetchMessageBrokerTopic(event.event);
|
|
2963
|
+
const topic = await this.fetchMessageBrokerTopic(event.event);
|
|
1764
2964
|
if (!topic) {
|
|
1765
2965
|
throw new Error(`Topic ${event.event} not registered`);
|
|
1766
2966
|
}
|
|
@@ -1768,14 +2968,14 @@ class ProductsBuilderService {
|
|
|
1768
2968
|
//await this.validatePublishTopicDataInput(data, { data: topicData }, event.input, event_index, sequence_index)
|
|
1769
2969
|
}
|
|
1770
2970
|
async checkAndValidateStorageDataInput(data, sequence_index, event, event_index) {
|
|
1771
|
-
const storage = this.fetchStorage(event.event);
|
|
2971
|
+
const storage = await this.fetchStorage(event.event);
|
|
1772
2972
|
if (!storage) {
|
|
1773
2973
|
throw new Error(`Storage ${event.event} does not exist`);
|
|
1774
2974
|
}
|
|
1775
2975
|
//await this.validateStorageDataInput(data, {}, event.input, event_index, sequence_index);
|
|
1776
2976
|
}
|
|
1777
2977
|
async checkAndValidateJobDataInput(data, sequence_index, event, event_index) {
|
|
1778
|
-
const job = this.fetchJob(event.event);
|
|
2978
|
+
const job = await this.fetchJob(event.event);
|
|
1779
2979
|
if (job.type === productsBuilder_types_1.JobEventTypes.ACTION) {
|
|
1780
2980
|
await this.checkAndValidateActionDataInput(data, sequence_index, event, event_index);
|
|
1781
2981
|
}
|
|
@@ -1791,9 +2991,6 @@ class ProductsBuilderService {
|
|
|
1791
2991
|
if (job.type === productsBuilder_types_1.JobEventTypes.PUBLISH) {
|
|
1792
2992
|
await this.checkAndValidatePublishDataInput(data, sequence_index, event, event_index);
|
|
1793
2993
|
}
|
|
1794
|
-
if (job.type === productsBuilder_types_1.JobEventTypes.FUNCTION) {
|
|
1795
|
-
await this.checkAndValidateFunctionDataInput(data, sequence_index, event, event_index);
|
|
1796
|
-
}
|
|
1797
2994
|
}
|
|
1798
2995
|
async checkAndValidateFallbackDataInput(data, sequence_index, event, event_index) { }
|
|
1799
2996
|
async validateEvent(data, sequence_index, event, event_index) {
|
|
@@ -1815,7 +3012,7 @@ class ProductsBuilderService {
|
|
|
1815
3012
|
await this.checkAndValidatePublishDataInput(data, sequence_index, event, event_index);
|
|
1816
3013
|
}
|
|
1817
3014
|
/*if (event.type === FeatureEventTypes.SUBSCRIBE) {
|
|
1818
|
-
const topic = this.fetchMessageBrokerTopic(event.event);
|
|
3015
|
+
const topic = await this.fetchMessageBrokerTopic(event.event);
|
|
1819
3016
|
|
|
1820
3017
|
if(!topic) {
|
|
1821
3018
|
throw new Error(`Topic ${event.event} not registered`);
|
|
@@ -2018,7 +3215,7 @@ class ProductsBuilderService {
|
|
|
2018
3215
|
});
|
|
2019
3216
|
}
|
|
2020
3217
|
async validateActionInputData(data, skipSample = false, option = false, optionIndex = 0) {
|
|
2021
|
-
var _a;
|
|
3218
|
+
var _a, _b;
|
|
2022
3219
|
const { obj } = data, base_data = __rest(data, ["obj"]);
|
|
2023
3220
|
if (!data.sample && Object.keys(obj).length === 0) {
|
|
2024
3221
|
return;
|
|
@@ -2026,8 +3223,8 @@ class ProductsBuilderService {
|
|
|
2026
3223
|
if (!data.sample) {
|
|
2027
3224
|
throw new Error('Something unexpected happened in validating action input');
|
|
2028
3225
|
}
|
|
2029
|
-
const sequence = data.feature.sequence[data.sequence_index];
|
|
2030
|
-
if (obj === undefined || obj === null) {
|
|
3226
|
+
const sequence = data.feature.sequence ? (_a = data.feature) === null || _a === void 0 ? void 0 : _a.sequence[data.sequence_index] : null;
|
|
3227
|
+
if ((obj === undefined || obj === null) && sequence) {
|
|
2031
3228
|
if (!option) {
|
|
2032
3229
|
throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be ${obj}`);
|
|
2033
3230
|
}
|
|
@@ -2035,7 +3232,7 @@ class ProductsBuilderService {
|
|
|
2035
3232
|
throw new Error(`option event index ${optionIndex}, ${data.type} should not be ${obj}`);
|
|
2036
3233
|
}
|
|
2037
3234
|
}
|
|
2038
|
-
if (Object.values(obj).length > 0 && ((
|
|
3235
|
+
if (sequence && Object.values(obj).length > 0 && ((_b = data.sample.data) === null || _b === void 0 ? void 0 : _b.length) === 0) {
|
|
2039
3236
|
if (!option) {
|
|
2040
3237
|
throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should be an empty object`);
|
|
2041
3238
|
}
|
|
@@ -2046,7 +3243,7 @@ class ProductsBuilderService {
|
|
|
2046
3243
|
if (Object.values(obj).length === 0 && data.sample.data.length === 0 /*data.sample?.data?.length === 0*/) {
|
|
2047
3244
|
return;
|
|
2048
3245
|
}
|
|
2049
|
-
if (Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
|
|
3246
|
+
if (sequence && Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
|
|
2050
3247
|
//console.log("validity err: ",obj, data.sample)
|
|
2051
3248
|
if (!option) {
|
|
2052
3249
|
throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be an empty object`);
|
|
@@ -2222,7 +3419,9 @@ class ProductsBuilderService {
|
|
|
2222
3419
|
let current_input = input;
|
|
2223
3420
|
for (let i = 0; i < stages.length; i++) {
|
|
2224
3421
|
let stage = stages[i];
|
|
2225
|
-
|
|
3422
|
+
// Convert to string for .match() call
|
|
3423
|
+
const stageStr = String(stage);
|
|
3424
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2226
3425
|
if (matches && matches.length === 2) {
|
|
2227
3426
|
const number = parseInt(matches[1], 10);
|
|
2228
3427
|
if (!isNaN(number)) {
|
|
@@ -2278,14 +3477,16 @@ class ProductsBuilderService {
|
|
|
2278
3477
|
}
|
|
2279
3478
|
else {
|
|
2280
3479
|
//const envs =
|
|
2281
|
-
const app = this.fetchApp(access_tag);
|
|
3480
|
+
const app = await this.fetchApp(access_tag);
|
|
2282
3481
|
const { envs } = app;
|
|
2283
3482
|
await Promise.all(envs.map((env) => {
|
|
2284
3483
|
if (stages[0] !== env.auth.auth_tag) {
|
|
2285
3484
|
throw new Error(`Auth ${stages[0]} does not exist on env ${env.product_env_slug} on app ${access_tag}`);
|
|
2286
3485
|
}
|
|
2287
|
-
const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.
|
|
2288
|
-
|
|
3486
|
+
const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.product.private_key));
|
|
3487
|
+
// Convert stages to string[] for findFaultyKeys
|
|
3488
|
+
const stringStages = stages.slice(1).map((stage) => String(stage));
|
|
3489
|
+
const check = (0, objects_utils_1.findFaultyKeys)(stringStages, decrypted);
|
|
2289
3490
|
if (check.faultyKeys) {
|
|
2290
3491
|
throw new Error(`Auth Key(s) ${check.faultyKeys.join(', ')} is/are invalid, they do not exist in authorization for ${env.product_env_slug} on app ${access_tag}`);
|
|
2291
3492
|
}
|
|
@@ -2301,7 +3502,9 @@ class ProductsBuilderService {
|
|
|
2301
3502
|
let i = 1;
|
|
2302
3503
|
while (i < stages.length) {
|
|
2303
3504
|
let stage = stages[i];
|
|
2304
|
-
|
|
3505
|
+
// Convert to string for .match() call
|
|
3506
|
+
const stageStr = String(stage);
|
|
3507
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2305
3508
|
if (matches && matches.length === 2) {
|
|
2306
3509
|
const number = parseInt(matches[1], 10);
|
|
2307
3510
|
if (!isNaN(number)) {
|
|
@@ -2375,11 +3578,15 @@ class ProductsBuilderService {
|
|
|
2375
3578
|
// let current_data;
|
|
2376
3579
|
if (i === 0) {
|
|
2377
3580
|
// find sequence by tag, see if it exists and its before current sequence
|
|
2378
|
-
|
|
2379
|
-
|
|
3581
|
+
// Convert stage to string for function calls
|
|
3582
|
+
const stageStr = String(stage);
|
|
3583
|
+
this.validateSequenceInputParents(stageStr, meta.sequence_index, meta.feature.sequence);
|
|
3584
|
+
sequence = this.fetchPriorSequence(meta, stageStr);
|
|
2380
3585
|
}
|
|
2381
3586
|
if (i === 1 && sequence) {
|
|
2382
|
-
|
|
3587
|
+
// Convert stage to string for function calls
|
|
3588
|
+
const stageStr = String(stage);
|
|
3589
|
+
event = this.fetchSequenceEvent(sequence, stageStr);
|
|
2383
3590
|
if (!event) {
|
|
2384
3591
|
throw new Error(`event ${stage} not found in sequence ${sequence.tag}`);
|
|
2385
3592
|
}
|
|
@@ -2408,7 +3615,9 @@ class ProductsBuilderService {
|
|
|
2408
3615
|
if (i > 1 && response) {
|
|
2409
3616
|
let parent_index = 0;
|
|
2410
3617
|
let increment = false;
|
|
2411
|
-
|
|
3618
|
+
// Convert to string for .match() call
|
|
3619
|
+
const stageStr = String(stage);
|
|
3620
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2412
3621
|
if (matches && matches.length === 2) {
|
|
2413
3622
|
const number = parseInt(matches[1], 10);
|
|
2414
3623
|
if (!isNaN(number)) {
|
|
@@ -2466,7 +3675,7 @@ class ProductsBuilderService {
|
|
|
2466
3675
|
if (stages.length > 2) {
|
|
2467
3676
|
throw new Error(`sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}, has invalid varibale definition ${value}, only two keys is required`);
|
|
2468
3677
|
}
|
|
2469
|
-
const app = this.fetchApp(stages[0]);
|
|
3678
|
+
const app = await this.fetchApp(String(stages[0]));
|
|
2470
3679
|
if (!app) {
|
|
2471
3680
|
throw new Error(`App ${stages[0]} not found in sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}, has invalid varibale definition ${value}. `);
|
|
2472
3681
|
}
|
|
@@ -2483,8 +3692,8 @@ class ProductsBuilderService {
|
|
|
2483
3692
|
if (stages.length !== 2) {
|
|
2484
3693
|
throw new Error(`When using constants you need to specify the constant in the format $Constant{app_tag}{key} instead of ${value}`);
|
|
2485
3694
|
}
|
|
2486
|
-
const app_tag = stages[0];
|
|
2487
|
-
const key = stages[1];
|
|
3695
|
+
const app_tag = String(stages[0]);
|
|
3696
|
+
const key = String(stages[1]);
|
|
2488
3697
|
const _c = await this.fetchThirdPartyAppByAccessTag(app_tag), { version } = _c, app = __rest(_c, ["version"]);
|
|
2489
3698
|
if (!app) {
|
|
2490
3699
|
throw new Error(`App ${app_tag} not found in constant ${value}`);
|
|
@@ -2574,9 +3783,10 @@ class ProductsBuilderService {
|
|
|
2574
3783
|
return found;
|
|
2575
3784
|
}
|
|
2576
3785
|
validateActionKeyPlacement(data) {
|
|
3786
|
+
var _a;
|
|
2577
3787
|
const actionData = data.sample.data;
|
|
2578
3788
|
const { indexes } = data;
|
|
2579
|
-
const sequence = data.feature.sequence[data.sequence_index];
|
|
3789
|
+
const sequence = data.feature.sequence ? (_a = data.feature) === null || _a === void 0 ? void 0 : _a.sequence[data.sequence_index] : null;
|
|
2580
3790
|
const datapoint = actionData.find((item) => {
|
|
2581
3791
|
return (item.parent_key === indexes.parent_key && item.key === data.key && item.level === indexes.level //&&
|
|
2582
3792
|
//indexes.index === item.index
|
|
@@ -2584,7 +3794,12 @@ class ProductsBuilderService {
|
|
|
2584
3794
|
});
|
|
2585
3795
|
if (!datapoint) {
|
|
2586
3796
|
console.log('VALIDATE', data.key, data.value, actionData, indexes);
|
|
2587
|
-
|
|
3797
|
+
if (sequence) {
|
|
3798
|
+
throw new Error(`Key ${data.key} not found for ${data.type} for sequence ${sequence.tag} event ${sequence.events[data.event_index].event}`);
|
|
3799
|
+
}
|
|
3800
|
+
else {
|
|
3801
|
+
throw new Error(`Key ${data.key} not found`);
|
|
3802
|
+
}
|
|
2588
3803
|
}
|
|
2589
3804
|
return datapoint;
|
|
2590
3805
|
}
|
|
@@ -2615,12 +3830,11 @@ class ProductsBuilderService {
|
|
|
2615
3830
|
}
|
|
2616
3831
|
async createFeature(data, throwErrorIfExists = false) {
|
|
2617
3832
|
try {
|
|
2618
|
-
if (!this.fetchFeature(data.tag
|
|
3833
|
+
if (!(await this.fetchFeature(data.tag))) {
|
|
2619
3834
|
await validators_1.CreateProductFeatureSchema.validateAsync(data);
|
|
2620
3835
|
try {
|
|
2621
3836
|
await this.validateFeatureData(data);
|
|
2622
3837
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2623
|
-
await this.initializeProduct(this.product_id);
|
|
2624
3838
|
}
|
|
2625
3839
|
catch (e) {
|
|
2626
3840
|
throw e;
|
|
@@ -2637,7 +3851,7 @@ class ProductsBuilderService {
|
|
|
2637
3851
|
}
|
|
2638
3852
|
async updateFeature(tag, data) {
|
|
2639
3853
|
try {
|
|
2640
|
-
const feature = this.fetchFeature(tag);
|
|
3854
|
+
const feature = await this.fetchFeature(tag);
|
|
2641
3855
|
if (!feature) {
|
|
2642
3856
|
throw new Error(`Feature ${tag} not found`);
|
|
2643
3857
|
}
|
|
@@ -2649,43 +3863,58 @@ class ProductsBuilderService {
|
|
|
2649
3863
|
}
|
|
2650
3864
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id,
|
|
2651
3865
|
tag }, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
2652
|
-
await this.initializeProduct(this.product_id);
|
|
2653
3866
|
}
|
|
2654
3867
|
catch (e) {
|
|
2655
3868
|
throw e;
|
|
2656
3869
|
}
|
|
2657
3870
|
}
|
|
2658
|
-
|
|
2659
|
-
const
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
3871
|
+
async fetchFeatures() {
|
|
3872
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'feature', this.getUserAccess());
|
|
3873
|
+
return components;
|
|
3874
|
+
}
|
|
3875
|
+
async fetchFeature(tag) {
|
|
3876
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'feature', tag, this.getUserAccess());
|
|
3877
|
+
return component;
|
|
2663
3878
|
}
|
|
2664
|
-
|
|
2665
|
-
|
|
3879
|
+
async deleteFeature(tag) {
|
|
3880
|
+
try {
|
|
3881
|
+
const feature = await this.fetchFeature(tag);
|
|
3882
|
+
if (!feature) {
|
|
3883
|
+
throw new Error(`Feature with tag: ${tag} not found`);
|
|
3884
|
+
}
|
|
3885
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
3886
|
+
tag,
|
|
3887
|
+
component: enums_1.ProductComponents.FEATURE,
|
|
3888
|
+
action: enums_1.RequestAction.DELETE,
|
|
3889
|
+
}, this.getUserAccess());
|
|
3890
|
+
}
|
|
3891
|
+
catch (e) {
|
|
3892
|
+
throw e;
|
|
3893
|
+
}
|
|
2666
3894
|
}
|
|
2667
3895
|
async createDatabase(data, throwErrorIfExists = false) {
|
|
2668
3896
|
try {
|
|
2669
3897
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
2670
|
-
if (!this.fetchDatabase(data.tag
|
|
3898
|
+
if (!(await this.fetchDatabase(data.tag))) {
|
|
2671
3899
|
await validators_1.CreateProductDatabaseSchema.validateAsync(data);
|
|
2672
|
-
|
|
2673
|
-
|
|
3900
|
+
const processedEnvs = [];
|
|
3901
|
+
for (const env of data.envs) {
|
|
3902
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2674
3903
|
if (!exists) {
|
|
2675
3904
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
2676
3905
|
}
|
|
2677
|
-
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.
|
|
2678
|
-
|
|
2679
|
-
}
|
|
2680
|
-
|
|
2681
|
-
envs.
|
|
3906
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
3907
|
+
processedEnvs.push(env);
|
|
3908
|
+
}
|
|
3909
|
+
data.envs = processedEnvs;
|
|
3910
|
+
const envs = await this.fetchEnvs();
|
|
3911
|
+
for (const env of envs) {
|
|
2682
3912
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
2683
3913
|
if (exists === -1) {
|
|
2684
3914
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
2685
3915
|
}
|
|
2686
|
-
}
|
|
3916
|
+
}
|
|
2687
3917
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.DATABASE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2688
|
-
await this.initializeProduct(this.product_id);
|
|
2689
3918
|
}
|
|
2690
3919
|
else {
|
|
2691
3920
|
if (throwErrorIfExists)
|
|
@@ -2698,7 +3927,7 @@ class ProductsBuilderService {
|
|
|
2698
3927
|
}
|
|
2699
3928
|
async updateDatabase(tag, data) {
|
|
2700
3929
|
try {
|
|
2701
|
-
const db = this.fetchDatabase(tag);
|
|
3930
|
+
const db = await this.fetchDatabase(tag);
|
|
2702
3931
|
if (!db) {
|
|
2703
3932
|
throw new Error(`Database ${tag} not found`);
|
|
2704
3933
|
}
|
|
@@ -2707,15 +3936,16 @@ class ProductsBuilderService {
|
|
|
2707
3936
|
if (data.tag && this.fetchDatabase(data.tag)) {
|
|
2708
3937
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
2709
3938
|
}
|
|
2710
|
-
data.envs = data.envs.map((env) => {
|
|
2711
|
-
const exists = this.fetchEnv(env.slug);
|
|
3939
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
3940
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2712
3941
|
if (!exists) {
|
|
2713
3942
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
2714
3943
|
}
|
|
2715
|
-
if (env.connection_url)
|
|
2716
|
-
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.
|
|
3944
|
+
if (env.connection_url) {
|
|
3945
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
3946
|
+
}
|
|
2717
3947
|
return env;
|
|
2718
|
-
});
|
|
3948
|
+
}));
|
|
2719
3949
|
const overwrite = [];
|
|
2720
3950
|
const newEnvs = [];
|
|
2721
3951
|
data.envs.map((dataEnv) => {
|
|
@@ -2744,23 +3974,348 @@ class ProductsBuilderService {
|
|
|
2744
3974
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
2745
3975
|
//console.log("UPDATED!!!", JSON.stringify(data.envs))
|
|
2746
3976
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { tag, component: enums_1.ProductComponents.DATABASE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
2747
|
-
await this.initializeProduct(this.product_id);
|
|
2748
3977
|
}
|
|
2749
3978
|
catch (e) {
|
|
2750
3979
|
throw e;
|
|
2751
3980
|
}
|
|
2752
3981
|
}
|
|
2753
|
-
|
|
2754
|
-
const
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
3982
|
+
async fetchDatabases() {
|
|
3983
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'database', this.getUserAccess());
|
|
3984
|
+
const decryptedComponents = components.map((component) => {
|
|
3985
|
+
const dbComponent = component;
|
|
3986
|
+
const decryptedEnvs = dbComponent.envs.map((env) => {
|
|
3987
|
+
return Object.assign(Object.assign({}, env), { connection_url: (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key) });
|
|
3988
|
+
});
|
|
3989
|
+
return Object.assign(Object.assign({}, dbComponent), { envs: decryptedEnvs });
|
|
3990
|
+
});
|
|
3991
|
+
return decryptedComponents;
|
|
3992
|
+
}
|
|
3993
|
+
async fetchDatabase(tag) {
|
|
3994
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'database', tag, this.getUserAccess());
|
|
3995
|
+
if (component) {
|
|
3996
|
+
const decryptedEnvs = component.envs.map((env) => {
|
|
3997
|
+
return Object.assign(Object.assign({}, env), { connection_url: (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key) });
|
|
3998
|
+
});
|
|
3999
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
4000
|
+
}
|
|
4001
|
+
return component;
|
|
4002
|
+
}
|
|
4003
|
+
async deleteDatabase(tag) {
|
|
4004
|
+
try {
|
|
4005
|
+
const database = await this.fetchDatabase(tag);
|
|
4006
|
+
if (!database) {
|
|
4007
|
+
throw new Error(`Database with tag: ${tag} not found`);
|
|
4008
|
+
}
|
|
4009
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4010
|
+
tag,
|
|
4011
|
+
component: enums_1.ProductComponents.DATABASE,
|
|
4012
|
+
action: enums_1.RequestAction.DELETE,
|
|
4013
|
+
}, this.getUserAccess());
|
|
4014
|
+
}
|
|
4015
|
+
catch (e) {
|
|
4016
|
+
throw e;
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
// GRAPH CRUD METHODS
|
|
4020
|
+
async createGraph(data, throwErrorIfExists = false) {
|
|
4021
|
+
var _a, _b, _c;
|
|
4022
|
+
console.log('[ProductsService.createGraph] Starting graph creation:', {
|
|
4023
|
+
tag: data.tag,
|
|
4024
|
+
name: data.name,
|
|
4025
|
+
type: data.type,
|
|
4026
|
+
envsCount: (_a = data.envs) === null || _a === void 0 ? void 0 : _a.length,
|
|
4027
|
+
productTag: (_b = this.product) === null || _b === void 0 ? void 0 : _b.tag,
|
|
4028
|
+
});
|
|
4029
|
+
try {
|
|
4030
|
+
if (!(await this.fetchGraph(data.tag))) {
|
|
4031
|
+
await validators_1.CreateProductGraphSchema.validateAsync(data);
|
|
4032
|
+
const processedEnvs = [];
|
|
4033
|
+
for (const env of data.envs) {
|
|
4034
|
+
console.log('[ProductsService.createGraph] Processing env:', {
|
|
4035
|
+
slug: env.slug,
|
|
4036
|
+
hasConnectionUrl: !!env.connection_url,
|
|
4037
|
+
hasUsername: !!env.username,
|
|
4038
|
+
hasPassword: !!env.password,
|
|
4039
|
+
});
|
|
4040
|
+
const exists = await this.fetchEnv(env.slug);
|
|
4041
|
+
if (!exists) {
|
|
4042
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
4043
|
+
}
|
|
4044
|
+
// Store connection URL as secret
|
|
4045
|
+
console.log('[ProductsService.createGraph] Converting connection URL to secret for env:', env.slug);
|
|
4046
|
+
const originalUrl = env.connection_url;
|
|
4047
|
+
env.connection_url = await this.storeGraphConnectionUrlAsSecret(env.connection_url, data.tag, env.slug);
|
|
4048
|
+
console.log('[ProductsService.createGraph] Connection URL after secret conversion:', {
|
|
4049
|
+
wasConverted: originalUrl !== env.connection_url,
|
|
4050
|
+
isSecretRef: (_c = env.connection_url) === null || _c === void 0 ? void 0 : _c.startsWith('$Secret{'),
|
|
4051
|
+
});
|
|
4052
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
4053
|
+
console.log('[ProductsService.createGraph] Connection URL encrypted');
|
|
4054
|
+
// Encrypt username and password if provided
|
|
4055
|
+
if (env.username) {
|
|
4056
|
+
console.log('[ProductsService.createGraph] Encrypting username for env:', env.slug);
|
|
4057
|
+
env.username = (0, processor_utils_1.encrypt)(env.username, this.product.private_key);
|
|
4058
|
+
}
|
|
4059
|
+
if (env.password) {
|
|
4060
|
+
console.log('[ProductsService.createGraph] Encrypting password for env:', env.slug);
|
|
4061
|
+
env.password = (0, processor_utils_1.encrypt)(env.password, this.product.private_key);
|
|
4062
|
+
}
|
|
4063
|
+
processedEnvs.push(env);
|
|
4064
|
+
console.log('[ProductsService.createGraph] Env processed successfully:', env.slug);
|
|
4065
|
+
}
|
|
4066
|
+
data.envs = processedEnvs;
|
|
4067
|
+
console.log('[ProductsService.createGraph] All envs processed, total:', processedEnvs.length);
|
|
4068
|
+
const envs = await this.fetchEnvs();
|
|
4069
|
+
for (const env of envs) {
|
|
4070
|
+
const exists = data.envs.findIndex((graphEnv) => graphEnv.slug === env.slug);
|
|
4071
|
+
if (exists === -1) {
|
|
4072
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.GRAPH, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
4076
|
+
}
|
|
4077
|
+
else {
|
|
4078
|
+
if (throwErrorIfExists)
|
|
4079
|
+
throw new Error(`Graph ${data.tag} already exists`);
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
catch (e) {
|
|
4083
|
+
throw e;
|
|
4084
|
+
}
|
|
4085
|
+
}
|
|
4086
|
+
async updateGraph(tag, data) {
|
|
4087
|
+
var _a, _b;
|
|
4088
|
+
console.log('[ProductsService.updateGraph] Starting graph update:', {
|
|
4089
|
+
tag,
|
|
4090
|
+
newTag: data.tag,
|
|
4091
|
+
name: data.name,
|
|
4092
|
+
type: data.type,
|
|
4093
|
+
envsCount: (_a = data.envs) === null || _a === void 0 ? void 0 : _a.length,
|
|
4094
|
+
productTag: (_b = this.product) === null || _b === void 0 ? void 0 : _b.tag,
|
|
4095
|
+
});
|
|
4096
|
+
try {
|
|
4097
|
+
const graph = await this.fetchGraph(tag);
|
|
4098
|
+
if (!graph) {
|
|
4099
|
+
throw new Error(`Graph ${tag} not found`);
|
|
4100
|
+
}
|
|
4101
|
+
const { _id, envs } = graph;
|
|
4102
|
+
console.log('[ProductsService.updateGraph] Found existing graph:', {
|
|
4103
|
+
_id,
|
|
4104
|
+
existingEnvsCount: envs === null || envs === void 0 ? void 0 : envs.length,
|
|
4105
|
+
});
|
|
4106
|
+
await validators_1.UpdateProductGraphSchema.validateAsync(data);
|
|
4107
|
+
if (data.tag && this.fetchGraph(data.tag)) {
|
|
4108
|
+
throw new Error(`tag ${tag} is in use`);
|
|
4109
|
+
}
|
|
4110
|
+
console.log('[ProductsService.updateGraph] Processing envs update');
|
|
4111
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
4112
|
+
var _a;
|
|
4113
|
+
console.log('[ProductsService.updateGraph] Processing env:', {
|
|
4114
|
+
slug: env.slug,
|
|
4115
|
+
hasConnectionUrl: !!env.connection_url,
|
|
4116
|
+
hasUsername: !!env.username,
|
|
4117
|
+
hasPassword: !!env.password,
|
|
4118
|
+
});
|
|
4119
|
+
const exists = await this.fetchEnv(env.slug);
|
|
4120
|
+
if (!exists) {
|
|
4121
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
4122
|
+
}
|
|
4123
|
+
if (env.connection_url) {
|
|
4124
|
+
// Store connection URL as secret
|
|
4125
|
+
console.log('[ProductsService.updateGraph] Converting connection URL to secret for env:', env.slug);
|
|
4126
|
+
const originalUrl = env.connection_url;
|
|
4127
|
+
env.connection_url = await this.storeGraphConnectionUrlAsSecret(env.connection_url, data.tag || tag, env.slug);
|
|
4128
|
+
console.log('[ProductsService.updateGraph] Connection URL after secret conversion:', {
|
|
4129
|
+
wasConverted: originalUrl !== env.connection_url,
|
|
4130
|
+
isSecretRef: (_a = env.connection_url) === null || _a === void 0 ? void 0 : _a.startsWith('$Secret{'),
|
|
4131
|
+
});
|
|
4132
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
4133
|
+
console.log('[ProductsService.updateGraph] Connection URL encrypted');
|
|
4134
|
+
}
|
|
4135
|
+
// Encrypt username and password if provided
|
|
4136
|
+
if (env.username) {
|
|
4137
|
+
console.log('[ProductsService.updateGraph] Encrypting username for env:', env.slug);
|
|
4138
|
+
env.username = (0, processor_utils_1.encrypt)(env.username, this.product.private_key);
|
|
4139
|
+
}
|
|
4140
|
+
if (env.password) {
|
|
4141
|
+
console.log('[ProductsService.updateGraph] Encrypting password for env:', env.slug);
|
|
4142
|
+
env.password = (0, processor_utils_1.encrypt)(env.password, this.product.private_key);
|
|
4143
|
+
}
|
|
4144
|
+
console.log('[ProductsService.updateGraph] Env processed successfully:', env.slug);
|
|
4145
|
+
return env;
|
|
4146
|
+
}));
|
|
4147
|
+
const overwrite = [];
|
|
4148
|
+
const newEnvs = [];
|
|
4149
|
+
data.envs.map((dataEnv) => {
|
|
4150
|
+
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
4151
|
+
if (!this.fetchEnv(dataEnv.slug)) {
|
|
4152
|
+
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
4153
|
+
}
|
|
4154
|
+
if (exists === -1) {
|
|
4155
|
+
if (!dataEnv.connection_url) {
|
|
4156
|
+
throw new Error(`connection_url is required for new env ${data.envs[exists].slug}`);
|
|
4157
|
+
}
|
|
4158
|
+
newEnvs.push(dataEnv);
|
|
4159
|
+
}
|
|
4160
|
+
else {
|
|
4161
|
+
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
4162
|
+
}
|
|
4163
|
+
});
|
|
4164
|
+
const unchanged = [];
|
|
4165
|
+
envs.map((env) => {
|
|
4166
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
4167
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
4168
|
+
if (!newEnv && !overwriteEnv) {
|
|
4169
|
+
unchanged.push(env);
|
|
4170
|
+
}
|
|
4171
|
+
});
|
|
4172
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
4173
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { tag, component: enums_1.ProductComponents.GRAPH, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
4174
|
+
}
|
|
4175
|
+
catch (e) {
|
|
4176
|
+
throw e;
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
async fetchGraphs() {
|
|
4180
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'graph', this.getUserAccess());
|
|
4181
|
+
// Decrypt sensitive fields in graph envs
|
|
4182
|
+
const decryptedComponents = components.map((component) => {
|
|
4183
|
+
const graphComponent = component;
|
|
4184
|
+
const decryptedEnvs = graphComponent.envs.map((env) => {
|
|
4185
|
+
return Object.assign(Object.assign({}, env), { connection_url: env.connection_url ? (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key) : env.connection_url, username: env.username ? (0, processor_utils_1.decrypt)(env.username, this.product.private_key) : env.username, password: env.password ? (0, processor_utils_1.decrypt)(env.password, this.product.private_key) : env.password, graphName: env.graphName ? (0, processor_utils_1.decrypt)(env.graphName, this.product.private_key) : env.graphName, region: env.region ? (0, processor_utils_1.decrypt)(env.region, this.product.private_key) : env.region });
|
|
4186
|
+
});
|
|
4187
|
+
return Object.assign(Object.assign({}, graphComponent), { envs: decryptedEnvs });
|
|
4188
|
+
});
|
|
4189
|
+
return decryptedComponents;
|
|
4190
|
+
}
|
|
4191
|
+
async fetchGraph(tag) {
|
|
4192
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'graph', tag, this.getUserAccess());
|
|
4193
|
+
if (component) {
|
|
4194
|
+
// Decrypt sensitive fields in graph envs
|
|
4195
|
+
const decryptedEnvs = component.envs.map((env) => {
|
|
4196
|
+
return Object.assign(Object.assign({}, env), { connection_url: env.connection_url ? (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key) : env.connection_url, username: env.username ? (0, processor_utils_1.decrypt)(env.username, this.product.private_key) : env.username, password: env.password ? (0, processor_utils_1.decrypt)(env.password, this.product.private_key) : env.password, graphName: env.graphName ? (0, processor_utils_1.decrypt)(env.graphName, this.product.private_key) : env.graphName, region: env.region ? (0, processor_utils_1.decrypt)(env.region, this.product.private_key) : env.region });
|
|
4197
|
+
});
|
|
4198
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
4199
|
+
}
|
|
4200
|
+
return component;
|
|
4201
|
+
}
|
|
4202
|
+
async deleteGraph(tag) {
|
|
4203
|
+
try {
|
|
4204
|
+
const graph = await this.fetchGraph(tag);
|
|
4205
|
+
if (!graph) {
|
|
4206
|
+
throw new Error(`Graph with tag: ${tag} not found`);
|
|
4207
|
+
}
|
|
4208
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4209
|
+
tag,
|
|
4210
|
+
component: enums_1.ProductComponents.GRAPH,
|
|
4211
|
+
action: enums_1.RequestAction.DELETE,
|
|
4212
|
+
}, this.getUserAccess());
|
|
4213
|
+
}
|
|
4214
|
+
catch (e) {
|
|
4215
|
+
throw e;
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
// ==================== GRAPH ACTIONS ====================
|
|
4219
|
+
async createGraphAction(graphTag, data) {
|
|
4220
|
+
try {
|
|
4221
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4222
|
+
if (!graph) {
|
|
4223
|
+
throw new Error(`Graph with tag: ${graphTag} not found`);
|
|
4224
|
+
}
|
|
4225
|
+
// Initialize actions array if it doesn't exist
|
|
4226
|
+
if (!graph.actions) {
|
|
4227
|
+
graph.actions = [];
|
|
4228
|
+
}
|
|
4229
|
+
// Check if action already exists
|
|
4230
|
+
const existingAction = graph.actions.find((a) => a.tag === data.tag);
|
|
4231
|
+
if (existingAction) {
|
|
4232
|
+
throw new Error(`Action with tag: ${data.tag} already exists`);
|
|
4233
|
+
}
|
|
4234
|
+
graph.actions.push(data);
|
|
4235
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4236
|
+
tag: graphTag,
|
|
4237
|
+
actions: graph.actions,
|
|
4238
|
+
component: enums_1.ProductComponents.GRAPH,
|
|
4239
|
+
action: enums_1.RequestAction.UPDATE,
|
|
4240
|
+
}, this.getUserAccess());
|
|
4241
|
+
}
|
|
4242
|
+
catch (e) {
|
|
4243
|
+
throw e;
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
async updateGraphAction(graphTag, actionTag, data) {
|
|
4247
|
+
try {
|
|
4248
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4249
|
+
if (!graph) {
|
|
4250
|
+
throw new Error(`Graph with tag: ${graphTag} not found`);
|
|
4251
|
+
}
|
|
4252
|
+
if (!graph.actions) {
|
|
4253
|
+
throw new Error(`Action with tag: ${actionTag} not found`);
|
|
4254
|
+
}
|
|
4255
|
+
const actionIndex = graph.actions.findIndex((a) => a.tag === actionTag);
|
|
4256
|
+
if (actionIndex === -1) {
|
|
4257
|
+
throw new Error(`Action with tag: ${actionTag} not found`);
|
|
4258
|
+
}
|
|
4259
|
+
graph.actions[actionIndex] = Object.assign(Object.assign({}, graph.actions[actionIndex]), data);
|
|
4260
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4261
|
+
tag: graphTag,
|
|
4262
|
+
actions: graph.actions,
|
|
4263
|
+
component: enums_1.ProductComponents.GRAPH,
|
|
4264
|
+
action: enums_1.RequestAction.UPDATE,
|
|
4265
|
+
}, this.getUserAccess());
|
|
4266
|
+
}
|
|
4267
|
+
catch (e) {
|
|
4268
|
+
throw e;
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
async fetchGraphAction(graphTag, actionTag) {
|
|
4272
|
+
try {
|
|
4273
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4274
|
+
if (!graph || !graph.actions) {
|
|
4275
|
+
return null;
|
|
4276
|
+
}
|
|
4277
|
+
return graph.actions.find((a) => a.tag === actionTag) || null;
|
|
4278
|
+
}
|
|
4279
|
+
catch (e) {
|
|
4280
|
+
throw e;
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
async fetchGraphActions(graphTag) {
|
|
4284
|
+
try {
|
|
4285
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4286
|
+
if (!graph) {
|
|
4287
|
+
throw new Error(`Graph with tag: ${graphTag} not found`);
|
|
4288
|
+
}
|
|
4289
|
+
return graph.actions || [];
|
|
4290
|
+
}
|
|
4291
|
+
catch (e) {
|
|
4292
|
+
throw e;
|
|
4293
|
+
}
|
|
2761
4294
|
}
|
|
2762
|
-
|
|
2763
|
-
|
|
4295
|
+
async deleteGraphAction(graphTag, actionTag) {
|
|
4296
|
+
try {
|
|
4297
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4298
|
+
if (!graph) {
|
|
4299
|
+
throw new Error(`Graph with tag: ${graphTag} not found`);
|
|
4300
|
+
}
|
|
4301
|
+
if (!graph.actions) {
|
|
4302
|
+
throw new Error(`Action with tag: ${actionTag} not found`);
|
|
4303
|
+
}
|
|
4304
|
+
const actionIndex = graph.actions.findIndex((a) => a.tag === actionTag);
|
|
4305
|
+
if (actionIndex === -1) {
|
|
4306
|
+
throw new Error(`Action with tag: ${actionTag} not found`);
|
|
4307
|
+
}
|
|
4308
|
+
graph.actions.splice(actionIndex, 1);
|
|
4309
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4310
|
+
tag: graphTag,
|
|
4311
|
+
actions: graph.actions,
|
|
4312
|
+
component: enums_1.ProductComponents.GRAPH,
|
|
4313
|
+
action: enums_1.RequestAction.UPDATE,
|
|
4314
|
+
}, this.getUserAccess());
|
|
4315
|
+
}
|
|
4316
|
+
catch (e) {
|
|
4317
|
+
throw e;
|
|
4318
|
+
}
|
|
2764
4319
|
}
|
|
2765
4320
|
async createDatabaseAction(data, throwErrorIfExists = false) {
|
|
2766
4321
|
try {
|
|
@@ -2771,10 +4326,10 @@ class ProductsBuilderService {
|
|
|
2771
4326
|
if (!databaseTag || !tag) {
|
|
2772
4327
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
2773
4328
|
}
|
|
2774
|
-
const exists = this.fetchDatabaseAction(data.tag);
|
|
4329
|
+
const exists = await this.fetchDatabaseAction(data.tag);
|
|
2775
4330
|
data.tag = tag;
|
|
2776
4331
|
if (!exists) {
|
|
2777
|
-
const database = this.fetchDatabase(databaseTag);
|
|
4332
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
2778
4333
|
let values, template;
|
|
2779
4334
|
if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
|
|
2780
4335
|
await create_productDatabaseAction_validator_1.NOSQLDatabaseActionsSchema.validateAsync(data);
|
|
@@ -2798,7 +4353,6 @@ class ProductsBuilderService {
|
|
|
2798
4353
|
}
|
|
2799
4354
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { data: values, template,
|
|
2800
4355
|
databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2801
|
-
await this.initializeProduct(this.product_id);
|
|
2802
4356
|
}
|
|
2803
4357
|
else {
|
|
2804
4358
|
if (throwErrorIfExists)
|
|
@@ -2809,7 +4363,7 @@ class ProductsBuilderService {
|
|
|
2809
4363
|
throw e;
|
|
2810
4364
|
}
|
|
2811
4365
|
}
|
|
2812
|
-
fetchDatabaseAction(tag, throwErrorIfExists = false) {
|
|
4366
|
+
async fetchDatabaseAction(tag, throwErrorIfExists = false) {
|
|
2813
4367
|
const [databaseTag, actionTag] = tag.split(':');
|
|
2814
4368
|
if (!databaseTag || !actionTag) {
|
|
2815
4369
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
@@ -2836,7 +4390,7 @@ class ProductsBuilderService {
|
|
|
2836
4390
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
2837
4391
|
}
|
|
2838
4392
|
// Fetch required data
|
|
2839
|
-
const database = await this.fetchDatabase(databaseTag
|
|
4393
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
2840
4394
|
const action = await this.fetchDatabaseAction(data.tag, true);
|
|
2841
4395
|
// Construct payload
|
|
2842
4396
|
const payload = Object.assign(Object.assign(Object.assign({}, action), data), { databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.UPDATE });
|
|
@@ -2864,13 +4418,12 @@ class ProductsBuilderService {
|
|
|
2864
4418
|
}
|
|
2865
4419
|
// Update product and reinitialize
|
|
2866
4420
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
2867
|
-
await this.initializeProduct(this.product_id);
|
|
2868
4421
|
}
|
|
2869
4422
|
catch (error) {
|
|
2870
4423
|
throw error;
|
|
2871
4424
|
}
|
|
2872
4425
|
}
|
|
2873
|
-
fetchDatabaseActions(databaseTag) {
|
|
4426
|
+
async fetchDatabaseActions(databaseTag) {
|
|
2874
4427
|
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
2875
4428
|
if (!database)
|
|
2876
4429
|
throw new Error(`Database ${databaseTag} not found`);
|
|
@@ -2882,6 +4435,27 @@ class ProductsBuilderService {
|
|
|
2882
4435
|
}
|
|
2883
4436
|
return actions;
|
|
2884
4437
|
}
|
|
4438
|
+
async deleteDatabaseAction(tag) {
|
|
4439
|
+
try {
|
|
4440
|
+
const [databaseTag, actionTag] = tag.split(':');
|
|
4441
|
+
if (!databaseTag || !actionTag) {
|
|
4442
|
+
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
4443
|
+
}
|
|
4444
|
+
const action = await this.fetchDatabaseAction(tag, true);
|
|
4445
|
+
if (!action) {
|
|
4446
|
+
throw new Error(`Database action with tag: ${tag} not found`);
|
|
4447
|
+
}
|
|
4448
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4449
|
+
tag: actionTag,
|
|
4450
|
+
databaseTag,
|
|
4451
|
+
component: enums_1.ProductComponents.DATABASE_ACTION,
|
|
4452
|
+
action: enums_1.RequestAction.DELETE,
|
|
4453
|
+
}, this.getUserAccess());
|
|
4454
|
+
}
|
|
4455
|
+
catch (e) {
|
|
4456
|
+
throw e;
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
2885
4459
|
async createDatabaseMigration(data, throwErrorIfExists) {
|
|
2886
4460
|
if (!data.tag) {
|
|
2887
4461
|
throw new Error('tag field is required');
|
|
@@ -2890,22 +4464,48 @@ class ProductsBuilderService {
|
|
|
2890
4464
|
if (!databaseTag || !tag) {
|
|
2891
4465
|
throw new Error(`tag is expected to be defined as "database_tag:migration_tag"`);
|
|
2892
4466
|
}
|
|
2893
|
-
const exists = this.fetchDatabaseMigration(data.tag);
|
|
4467
|
+
const exists = await this.fetchDatabaseMigration(data.tag);
|
|
2894
4468
|
data.tag = tag;
|
|
2895
|
-
await create_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag }));
|
|
4469
|
+
await create_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag }));
|
|
2896
4470
|
if (!exists) {
|
|
2897
|
-
const database = this.fetchDatabase(databaseTag
|
|
4471
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
2898
4472
|
if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
|
|
2899
4473
|
throw new Error(`${database.type} does not support migrations`);
|
|
2900
4474
|
}
|
|
2901
|
-
|
|
2902
|
-
|
|
4475
|
+
// Process migration value - supports both simple strings and rich operations
|
|
4476
|
+
let processedValue = data.value;
|
|
4477
|
+
if (data.value) {
|
|
4478
|
+
processedValue = {
|
|
4479
|
+
up: this.processMigrationOperations(data.value.up),
|
|
4480
|
+
down: this.processMigrationOperations(data.value.down),
|
|
4481
|
+
};
|
|
4482
|
+
}
|
|
4483
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { value: processedValue, databaseTag, component: enums_1.ProductComponents.DATABASE_MIGRATION }), this.getUserAccess());
|
|
2903
4484
|
}
|
|
2904
4485
|
else {
|
|
2905
4486
|
if (throwErrorIfExists)
|
|
2906
|
-
throw new Error(`Database
|
|
4487
|
+
throw new Error(`Database Migration ${data.tag} already exists`);
|
|
2907
4488
|
}
|
|
2908
4489
|
}
|
|
4490
|
+
/**
|
|
4491
|
+
* Process migration operations - handles both string and object formats
|
|
4492
|
+
* Strings are passed through as-is (raw SQL/CQL)
|
|
4493
|
+
* Objects are serialized for storage and executed by the migration engine
|
|
4494
|
+
*/
|
|
4495
|
+
processMigrationOperations(operations) {
|
|
4496
|
+
if (!operations || !Array.isArray(operations))
|
|
4497
|
+
return [];
|
|
4498
|
+
return operations.map((op) => {
|
|
4499
|
+
if (typeof op === 'string') {
|
|
4500
|
+
return op; // Raw SQL/CQL string
|
|
4501
|
+
}
|
|
4502
|
+
// Rich operation object - validate it has required 'type' field
|
|
4503
|
+
if (typeof op === 'object' && op !== null && 'type' in op) {
|
|
4504
|
+
return op;
|
|
4505
|
+
}
|
|
4506
|
+
throw new Error(`Invalid migration operation format. Expected string or object with 'type' field.`);
|
|
4507
|
+
});
|
|
4508
|
+
}
|
|
2909
4509
|
async updateDatabaseMigration(data) {
|
|
2910
4510
|
if (!data.tag) {
|
|
2911
4511
|
throw new Error('tag field is required');
|
|
@@ -2914,16 +4514,23 @@ class ProductsBuilderService {
|
|
|
2914
4514
|
if (!databaseTag || !tag) {
|
|
2915
4515
|
throw new Error(`tag is expected to be defined as "database_tag:migration_tag"`);
|
|
2916
4516
|
}
|
|
2917
|
-
await update_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag }));
|
|
2918
|
-
const
|
|
2919
|
-
if (!
|
|
4517
|
+
await update_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag }));
|
|
4518
|
+
const existing = await this.fetchDatabaseMigration(data.tag);
|
|
4519
|
+
if (!existing) {
|
|
2920
4520
|
throw new Error(`Migration ${data.tag} not found`);
|
|
2921
4521
|
}
|
|
2922
4522
|
data.tag = tag;
|
|
2923
|
-
|
|
2924
|
-
|
|
4523
|
+
// Process migration value if provided - supports both simple strings and rich operations
|
|
4524
|
+
let processedValue = data.value;
|
|
4525
|
+
if (data.value) {
|
|
4526
|
+
processedValue = {
|
|
4527
|
+
up: this.processMigrationOperations(data.value.up),
|
|
4528
|
+
down: this.processMigrationOperations(data.value.down),
|
|
4529
|
+
};
|
|
4530
|
+
}
|
|
4531
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, existing), data), { value: processedValue || existing.value, databaseTag, component: enums_1.ProductComponents.DATABASE_MIGRATION }), this.getUserAccess());
|
|
2925
4532
|
}
|
|
2926
|
-
fetchDatabaseMigration(tag, throwError = false) {
|
|
4533
|
+
async fetchDatabaseMigration(tag, throwError = false) {
|
|
2927
4534
|
const [databaseTag, migrationTag] = tag.split(':');
|
|
2928
4535
|
if (!databaseTag || !migrationTag) {
|
|
2929
4536
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
@@ -2936,13 +4543,126 @@ class ProductsBuilderService {
|
|
|
2936
4543
|
throw new Error(`Database migration ${tag} not found`);
|
|
2937
4544
|
return migration;
|
|
2938
4545
|
}
|
|
2939
|
-
fetchDatabaseMigrations(databaseTag) {
|
|
4546
|
+
async fetchDatabaseMigrations(databaseTag) {
|
|
2940
4547
|
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
2941
4548
|
if (!database)
|
|
2942
4549
|
throw new Error(`Database ${databaseTag} not found`);
|
|
2943
4550
|
const migrations = database.migrations;
|
|
2944
4551
|
return migrations;
|
|
2945
4552
|
}
|
|
4553
|
+
async deleteDatabaseMigration(tag) {
|
|
4554
|
+
try {
|
|
4555
|
+
const [databaseTag, migrationTag] = tag.split(':');
|
|
4556
|
+
if (!databaseTag || !migrationTag) {
|
|
4557
|
+
throw new Error(`tag is expected to be defined as "database_tag:migration_tag"`);
|
|
4558
|
+
}
|
|
4559
|
+
const migration = await this.fetchDatabaseMigration(tag, true);
|
|
4560
|
+
if (!migration) {
|
|
4561
|
+
throw new Error(`Database migration with tag: ${tag} not found`);
|
|
4562
|
+
}
|
|
4563
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4564
|
+
tag: migrationTag,
|
|
4565
|
+
databaseTag,
|
|
4566
|
+
component: enums_1.ProductComponents.DATABASE_MIGRATION,
|
|
4567
|
+
action: enums_1.RequestAction.DELETE,
|
|
4568
|
+
}, this.getUserAccess());
|
|
4569
|
+
}
|
|
4570
|
+
catch (e) {
|
|
4571
|
+
throw e;
|
|
4572
|
+
}
|
|
4573
|
+
}
|
|
4574
|
+
// ==================== DATABASE TRIGGER CRUD ====================
|
|
4575
|
+
async createDatabaseTrigger(data, throwErrorIfExists = false) {
|
|
4576
|
+
try {
|
|
4577
|
+
if (!data.tag) {
|
|
4578
|
+
throw new Error('tag field is required');
|
|
4579
|
+
}
|
|
4580
|
+
const [databaseTag, triggerTag] = data.tag.split(':');
|
|
4581
|
+
if (!databaseTag || !triggerTag) {
|
|
4582
|
+
throw new Error(`tag is expected to be defined as "database_tag:trigger_tag"`);
|
|
4583
|
+
}
|
|
4584
|
+
const exists = await this.fetchDatabaseTrigger(data.tag);
|
|
4585
|
+
if (exists) {
|
|
4586
|
+
if (throwErrorIfExists) {
|
|
4587
|
+
throw new Error(`Database trigger with tag: ${data.tag} already exists`);
|
|
4588
|
+
}
|
|
4589
|
+
return;
|
|
4590
|
+
}
|
|
4591
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
4592
|
+
if (!database) {
|
|
4593
|
+
throw new Error(`Database ${databaseTag} not found`);
|
|
4594
|
+
}
|
|
4595
|
+
// Initialize triggers array if not present
|
|
4596
|
+
if (!database.triggers) {
|
|
4597
|
+
database.triggers = [];
|
|
4598
|
+
}
|
|
4599
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { tag: triggerTag, databaseTag, component: enums_1.ProductComponents.DATABASE_TRIGGER, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
4600
|
+
}
|
|
4601
|
+
catch (e) {
|
|
4602
|
+
throw e;
|
|
4603
|
+
}
|
|
4604
|
+
}
|
|
4605
|
+
async updateDatabaseTrigger(data) {
|
|
4606
|
+
try {
|
|
4607
|
+
if (!data.tag) {
|
|
4608
|
+
throw new Error('tag field is required');
|
|
4609
|
+
}
|
|
4610
|
+
const [databaseTag, triggerTag] = data.tag.split(':');
|
|
4611
|
+
if (!databaseTag || !triggerTag) {
|
|
4612
|
+
throw new Error(`tag is expected to be defined as "database_tag:trigger_tag"`);
|
|
4613
|
+
}
|
|
4614
|
+
const exists = await this.fetchDatabaseTrigger(data.tag, true);
|
|
4615
|
+
if (!exists) {
|
|
4616
|
+
throw new Error(`Database trigger with tag: ${data.tag} not found`);
|
|
4617
|
+
}
|
|
4618
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { tag: triggerTag, databaseTag, component: enums_1.ProductComponents.DATABASE_TRIGGER, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
4619
|
+
}
|
|
4620
|
+
catch (e) {
|
|
4621
|
+
throw e;
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
async fetchDatabaseTrigger(tag, throwError = false) {
|
|
4625
|
+
const [databaseTag, triggerTag] = tag.split(':');
|
|
4626
|
+
if (!databaseTag || !triggerTag) {
|
|
4627
|
+
throw new Error(`tag is expected to be defined as "database_tag:trigger_tag"`);
|
|
4628
|
+
}
|
|
4629
|
+
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
4630
|
+
if (!database)
|
|
4631
|
+
throw new Error(`Database ${databaseTag} not found`);
|
|
4632
|
+
const triggers = database.triggers || [];
|
|
4633
|
+
const trigger = triggers.find((data) => data.tag === triggerTag);
|
|
4634
|
+
if (!trigger && throwError)
|
|
4635
|
+
throw new Error(`Database trigger ${tag} not found`);
|
|
4636
|
+
return trigger || null;
|
|
4637
|
+
}
|
|
4638
|
+
async fetchDatabaseTriggers(databaseTag) {
|
|
4639
|
+
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
4640
|
+
if (!database)
|
|
4641
|
+
throw new Error(`Database ${databaseTag} not found`);
|
|
4642
|
+
const triggers = database.triggers || [];
|
|
4643
|
+
return triggers;
|
|
4644
|
+
}
|
|
4645
|
+
async deleteDatabaseTrigger(tag) {
|
|
4646
|
+
try {
|
|
4647
|
+
const [databaseTag, triggerTag] = tag.split(':');
|
|
4648
|
+
if (!databaseTag || !triggerTag) {
|
|
4649
|
+
throw new Error(`tag is expected to be defined as "database_tag:trigger_tag"`);
|
|
4650
|
+
}
|
|
4651
|
+
const trigger = await this.fetchDatabaseTrigger(tag, true);
|
|
4652
|
+
if (!trigger) {
|
|
4653
|
+
throw new Error(`Database trigger with tag: ${tag} not found`);
|
|
4654
|
+
}
|
|
4655
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4656
|
+
tag: triggerTag,
|
|
4657
|
+
databaseTag,
|
|
4658
|
+
component: enums_1.ProductComponents.DATABASE_TRIGGER,
|
|
4659
|
+
action: enums_1.RequestAction.DELETE,
|
|
4660
|
+
}, this.getUserAccess());
|
|
4661
|
+
}
|
|
4662
|
+
catch (e) {
|
|
4663
|
+
throw e;
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
2946
4666
|
async validateJobEvent(data) {
|
|
2947
4667
|
const { type, app, event } = data;
|
|
2948
4668
|
if (type === productsBuilder_types_1.JobEventTypes.ACTION) {
|
|
@@ -2957,31 +4677,25 @@ class ProductsBuilderService {
|
|
|
2957
4677
|
}
|
|
2958
4678
|
}
|
|
2959
4679
|
if (type === productsBuilder_types_1.JobEventTypes.DATABASE_ACTION) {
|
|
2960
|
-
const found = this.fetchDatabaseAction(event);
|
|
4680
|
+
const found = await this.fetchDatabaseAction(event);
|
|
2961
4681
|
if (!found) {
|
|
2962
4682
|
throw new Error(`Database action ${event} not found`);
|
|
2963
4683
|
}
|
|
2964
4684
|
}
|
|
2965
|
-
if (type === productsBuilder_types_1.JobEventTypes.FUNCTION) {
|
|
2966
|
-
const found = this.fetchFunction(event);
|
|
2967
|
-
if (!found) {
|
|
2968
|
-
throw new Error(`Cloud function ${event} not found`);
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
4685
|
if (type === productsBuilder_types_1.JobEventTypes.STORAGE) {
|
|
2972
|
-
const found = this.fetchStorage(event);
|
|
4686
|
+
const found = await this.fetchStorage(event);
|
|
2973
4687
|
if (!found) {
|
|
2974
4688
|
throw new Error(`Storage ${event} not found`);
|
|
2975
4689
|
}
|
|
2976
4690
|
}
|
|
2977
4691
|
if (type === productsBuilder_types_1.JobEventTypes.NOTIFICATION) {
|
|
2978
|
-
const found = this.fetchNotification(event);
|
|
4692
|
+
const found = await this.fetchNotification(event);
|
|
2979
4693
|
if (!found) {
|
|
2980
4694
|
throw new Error(`Notification ${event} not found`);
|
|
2981
4695
|
}
|
|
2982
4696
|
}
|
|
2983
4697
|
if (type === productsBuilder_types_1.JobEventTypes.PUBLISH) {
|
|
2984
|
-
const found = this.fetchMessageBroker(event);
|
|
4698
|
+
const found = await this.fetchMessageBroker(event);
|
|
2985
4699
|
if (!found) {
|
|
2986
4700
|
throw new Error(`Message Broker ${event} not found`);
|
|
2987
4701
|
}
|
|
@@ -2990,7 +4704,7 @@ class ProductsBuilderService {
|
|
|
2990
4704
|
async createJob(data, throwErrorIfExists = false) {
|
|
2991
4705
|
try {
|
|
2992
4706
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
2993
|
-
if (!this.fetchJob(data.tag)) {
|
|
4707
|
+
if (!(await this.fetchJob(data.tag))) {
|
|
2994
4708
|
await validators_1.CreateProductJobSchema.validateAsync(data);
|
|
2995
4709
|
await this.validateJobEvent(data);
|
|
2996
4710
|
if (data.type === productsBuilder_types_1.JobEventTypes.ACTION) {
|
|
@@ -3012,7 +4726,6 @@ class ProductsBuilderService {
|
|
|
3012
4726
|
const dbAction = await this.fetchDatabaseAction(data.event);
|
|
3013
4727
|
}
|
|
3014
4728
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.JOB, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
3015
|
-
await this.initializeProduct(this.product_id);
|
|
3016
4729
|
}
|
|
3017
4730
|
else {
|
|
3018
4731
|
if (throwErrorIfExists)
|
|
@@ -3035,20 +4748,111 @@ class ProductsBuilderService {
|
|
|
3035
4748
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
3036
4749
|
}
|
|
3037
4750
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, job), data), { component: enums_1.ProductComponents.JOB, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
3038
|
-
await this.initializeProduct(this.product_id);
|
|
3039
4751
|
}
|
|
3040
4752
|
catch (e) {
|
|
3041
4753
|
throw e;
|
|
3042
4754
|
}
|
|
3043
4755
|
}
|
|
3044
|
-
|
|
3045
|
-
const
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
4756
|
+
async fetchJobs() {
|
|
4757
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'job', this.getUserAccess());
|
|
4758
|
+
return components;
|
|
4759
|
+
}
|
|
4760
|
+
async fetchJob(tag) {
|
|
4761
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'job', tag, this.getUserAccess());
|
|
4762
|
+
return component;
|
|
4763
|
+
}
|
|
4764
|
+
async deleteJob(tag) {
|
|
4765
|
+
try {
|
|
4766
|
+
const job = await this.fetchJob(tag);
|
|
4767
|
+
if (!job) {
|
|
4768
|
+
throw new Error(`Job with tag: ${tag} not found`);
|
|
4769
|
+
}
|
|
4770
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4771
|
+
tag,
|
|
4772
|
+
component: enums_1.ProductComponents.JOB,
|
|
4773
|
+
action: enums_1.RequestAction.DELETE,
|
|
4774
|
+
}, this.getUserAccess());
|
|
4775
|
+
}
|
|
4776
|
+
catch (e) {
|
|
4777
|
+
throw e;
|
|
4778
|
+
}
|
|
4779
|
+
}
|
|
4780
|
+
// ==================== WORKFLOW CRUD METHODS ====================
|
|
4781
|
+
async createWorkflow(data, throwErrorIfExists = false) {
|
|
4782
|
+
try {
|
|
4783
|
+
if (!(await this.fetchWorkflow(data.tag))) {
|
|
4784
|
+
// Validate required fields
|
|
4785
|
+
if (!data.name || !data.tag) {
|
|
4786
|
+
throw new Error('Workflow requires name and tag');
|
|
4787
|
+
}
|
|
4788
|
+
// Validate envs if provided
|
|
4789
|
+
if (data.envs && data.envs.length > 0) {
|
|
4790
|
+
for (const env of data.envs) {
|
|
4791
|
+
const exists = await this.fetchEnv(env.slug);
|
|
4792
|
+
if (!exists) {
|
|
4793
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
4796
|
+
}
|
|
4797
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.WORKFLOW, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
4798
|
+
}
|
|
4799
|
+
else {
|
|
4800
|
+
if (throwErrorIfExists)
|
|
4801
|
+
throw new Error(`Workflow ${data.tag} already exists`);
|
|
4802
|
+
}
|
|
4803
|
+
}
|
|
4804
|
+
catch (e) {
|
|
4805
|
+
throw e;
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
async updateWorkflow(tag, data) {
|
|
4809
|
+
try {
|
|
4810
|
+
const workflow = await this.fetchWorkflow(tag);
|
|
4811
|
+
if (!workflow) {
|
|
4812
|
+
throw new Error(`Workflow ${tag} not found`);
|
|
4813
|
+
}
|
|
4814
|
+
const { _id } = workflow;
|
|
4815
|
+
if (data.tag && data.tag !== tag && (await this.fetchWorkflow(data.tag))) {
|
|
4816
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
4817
|
+
}
|
|
4818
|
+
// Validate envs if provided
|
|
4819
|
+
if (data.envs && data.envs.length > 0) {
|
|
4820
|
+
for (const env of data.envs) {
|
|
4821
|
+
const exists = await this.fetchEnv(env.slug);
|
|
4822
|
+
if (!exists) {
|
|
4823
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
4824
|
+
}
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { tag, component: enums_1.ProductComponents.WORKFLOW, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
4828
|
+
}
|
|
4829
|
+
catch (e) {
|
|
4830
|
+
throw e;
|
|
4831
|
+
}
|
|
4832
|
+
}
|
|
4833
|
+
async fetchWorkflows() {
|
|
4834
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'workflow', this.getUserAccess());
|
|
4835
|
+
return components;
|
|
4836
|
+
}
|
|
4837
|
+
async fetchWorkflow(tag) {
|
|
4838
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'workflow', tag, this.getUserAccess());
|
|
4839
|
+
return component;
|
|
3049
4840
|
}
|
|
3050
|
-
|
|
3051
|
-
|
|
4841
|
+
async deleteWorkflow(tag) {
|
|
4842
|
+
try {
|
|
4843
|
+
const workflow = await this.fetchWorkflow(tag);
|
|
4844
|
+
if (!workflow) {
|
|
4845
|
+
throw new Error(`Workflow with tag: ${tag} not found`);
|
|
4846
|
+
}
|
|
4847
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4848
|
+
tag,
|
|
4849
|
+
component: enums_1.ProductComponents.WORKFLOW,
|
|
4850
|
+
action: enums_1.RequestAction.DELETE,
|
|
4851
|
+
}, this.getUserAccess());
|
|
4852
|
+
}
|
|
4853
|
+
catch (e) {
|
|
4854
|
+
throw e;
|
|
4855
|
+
}
|
|
3052
4856
|
}
|
|
3053
4857
|
getUserAccess() {
|
|
3054
4858
|
return {
|
|
@@ -3056,7 +4860,598 @@ class ProductsBuilderService {
|
|
|
3056
4860
|
workspace_id: this.workspace_id,
|
|
3057
4861
|
token: this.token,
|
|
3058
4862
|
public_key: this.public_key,
|
|
4863
|
+
access_key: this.access_key,
|
|
4864
|
+
};
|
|
4865
|
+
}
|
|
4866
|
+
async fetchSessionUser(ductape_user_id) {
|
|
4867
|
+
return await this.productApi.fetchProductSessionUser(ductape_user_id, this.getUserAccess());
|
|
4868
|
+
}
|
|
4869
|
+
/**
|
|
4870
|
+
* Process storage config to store sensitive credentials as secrets
|
|
4871
|
+
* Format: STORAGE_{PRODUCT}_{STORAGE_TAG}_{ENV}_{KEY}
|
|
4872
|
+
*
|
|
4873
|
+
* Product parsing: split by ":", select first element
|
|
4874
|
+
* Storage tag: replace "-" with "_"
|
|
4875
|
+
*/
|
|
4876
|
+
async processStorageConfigSecrets(config, providerType, storageTag, envSlug) {
|
|
4877
|
+
console.log(`[Storage Secrets] Processing secrets for storage: ${storageTag}, env: ${envSlug}, provider: ${providerType}`);
|
|
4878
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
4879
|
+
if (!secretsService) {
|
|
4880
|
+
console.log(`[Storage Secrets] No secrets service available, skipping secret storage`);
|
|
4881
|
+
return config;
|
|
4882
|
+
}
|
|
4883
|
+
const generateSecretKey = (keyName) => {
|
|
4884
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
4885
|
+
const productParts = this.product.tag.split(':');
|
|
4886
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
4887
|
+
const storageKey = storageTag.replace(/-/g, '_');
|
|
4888
|
+
const key = `STORAGE_${sanitize(productKey)}_${sanitize(storageKey)}_${sanitize(envSlug)}_${sanitize(keyName)}`;
|
|
4889
|
+
console.log(`[Storage Secrets] Generated secret key: ${key}`);
|
|
4890
|
+
return key;
|
|
4891
|
+
};
|
|
4892
|
+
const storeAsSecret = async (value, keyName) => {
|
|
4893
|
+
const secretCheck = (0, secrets_1.isSecretReference)(value);
|
|
4894
|
+
if (secretCheck.isSecret) {
|
|
4895
|
+
console.log(`[Storage Secrets] ${keyName} is already a secret reference, skipping`);
|
|
4896
|
+
return value; // Already a secret reference
|
|
4897
|
+
}
|
|
4898
|
+
const secretKey = generateSecretKey(keyName);
|
|
4899
|
+
try {
|
|
4900
|
+
const exists = await secretsService.exists(secretKey);
|
|
4901
|
+
if (exists) {
|
|
4902
|
+
console.log(`[Storage Secrets] Updating existing secret: ${secretKey}`);
|
|
4903
|
+
await secretsService.update(secretKey, { value });
|
|
4904
|
+
}
|
|
4905
|
+
else {
|
|
4906
|
+
console.log(`[Storage Secrets] Creating new secret: ${secretKey}`);
|
|
4907
|
+
await secretsService.create({
|
|
4908
|
+
key: secretKey,
|
|
4909
|
+
value,
|
|
4910
|
+
description: `Storage ${keyName} for ${storageTag} in ${envSlug}`,
|
|
4911
|
+
scope: [this.product.tag, storageTag],
|
|
4912
|
+
envs: [envSlug],
|
|
4913
|
+
});
|
|
4914
|
+
}
|
|
4915
|
+
console.log(`[Storage Secrets] Successfully stored ${keyName} as secret: $Secret{${secretKey}}`);
|
|
4916
|
+
return `$Secret{${secretKey}}`;
|
|
4917
|
+
}
|
|
4918
|
+
catch (error) {
|
|
4919
|
+
console.warn(`[Storage Secrets] Failed to store storage credential as secret: ${error}`);
|
|
4920
|
+
return value;
|
|
4921
|
+
}
|
|
4922
|
+
};
|
|
4923
|
+
if (providerType === productsBuilder_types_1.StorageProviders.AWS) {
|
|
4924
|
+
console.log(`[Storage Secrets] Processing AWS S3 credentials`);
|
|
4925
|
+
const awsConfig = config;
|
|
4926
|
+
const result = Object.assign(Object.assign({}, awsConfig), { accessKeyId: await storeAsSecret(awsConfig.accessKeyId, 'ACCESS_KEY_ID'), secretAccessKey: await storeAsSecret(awsConfig.secretAccessKey, 'SECRET_ACCESS_KEY') });
|
|
4927
|
+
console.log(`[Storage Secrets] AWS S3 config processed successfully`);
|
|
4928
|
+
return result;
|
|
4929
|
+
}
|
|
4930
|
+
else if (providerType === productsBuilder_types_1.StorageProviders.GCP) {
|
|
4931
|
+
console.log(`[Storage Secrets] Processing GCP credentials`);
|
|
4932
|
+
const gcpConfig = config;
|
|
4933
|
+
if (gcpConfig.config) {
|
|
4934
|
+
const processedConfig = Object.assign({}, gcpConfig.config);
|
|
4935
|
+
// Store private_key_id as secret
|
|
4936
|
+
if (processedConfig.private_key_id) {
|
|
4937
|
+
processedConfig.private_key_id = await storeAsSecret(processedConfig.private_key_id, 'PRIVATE_KEY_ID');
|
|
4938
|
+
}
|
|
4939
|
+
// Store private_key as secret
|
|
4940
|
+
if (processedConfig.private_key) {
|
|
4941
|
+
processedConfig.private_key = await storeAsSecret(processedConfig.private_key, 'PRIVATE_KEY');
|
|
4942
|
+
}
|
|
4943
|
+
// Store client_email as secret
|
|
4944
|
+
if (processedConfig.client_email) {
|
|
4945
|
+
processedConfig.client_email = await storeAsSecret(processedConfig.client_email, 'CLIENT_EMAIL');
|
|
4946
|
+
}
|
|
4947
|
+
// Store client_id as secret
|
|
4948
|
+
if (processedConfig.client_id) {
|
|
4949
|
+
processedConfig.client_id = await storeAsSecret(processedConfig.client_id, 'CLIENT_ID');
|
|
4950
|
+
}
|
|
4951
|
+
const result = Object.assign(Object.assign({}, gcpConfig), { config: processedConfig });
|
|
4952
|
+
console.log(`[Storage Secrets] GCP config processed successfully`);
|
|
4953
|
+
console.log(`[Storage Secrets] Converted GCP config:`, JSON.stringify(result, null, 2));
|
|
4954
|
+
return result;
|
|
4955
|
+
}
|
|
4956
|
+
console.log(`[Storage Secrets] GCP config has no nested config, skipping`);
|
|
4957
|
+
return gcpConfig;
|
|
4958
|
+
}
|
|
4959
|
+
else if (providerType === productsBuilder_types_1.StorageProviders.AZURE) {
|
|
4960
|
+
console.log(`[Storage Secrets] Processing Azure Blob credentials`);
|
|
4961
|
+
const azureConfig = config;
|
|
4962
|
+
const result = Object.assign(Object.assign({}, azureConfig), { connectionString: await storeAsSecret(azureConfig.connectionString, 'CONNECTION_STRING') });
|
|
4963
|
+
console.log(`[Storage Secrets] Azure Blob config processed successfully`);
|
|
4964
|
+
return result;
|
|
4965
|
+
}
|
|
4966
|
+
console.log(`[Storage Secrets] Unknown provider type: ${providerType}, returning config as-is`);
|
|
4967
|
+
return config;
|
|
4968
|
+
}
|
|
4969
|
+
/**
|
|
4970
|
+
* Process message broker config to store sensitive credentials as secrets
|
|
4971
|
+
* Format: BROKER_{PRODUCT}_{BROKER_TAG}_{ENV}_{KEY}
|
|
4972
|
+
*
|
|
4973
|
+
* Product parsing: split by ":", select first element
|
|
4974
|
+
* Broker tag: replace "-" with "_"
|
|
4975
|
+
*/
|
|
4976
|
+
async processMessageBrokerConfigSecrets(config, brokerType, brokerTag, envSlug) {
|
|
4977
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
4978
|
+
const logPrefix = '[MessageBroker:Secrets]';
|
|
4979
|
+
console.log(`${logPrefix} Processing secrets for broker: ${brokerTag}, env: ${envSlug}, type: ${brokerType}`);
|
|
4980
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
4981
|
+
if (!secretsService) {
|
|
4982
|
+
console.log(`${logPrefix} No secrets service available, skipping secret storage`);
|
|
4983
|
+
return config;
|
|
4984
|
+
}
|
|
4985
|
+
console.log(`${logPrefix} Secrets service available`);
|
|
4986
|
+
const generateSecretKey = (keyName) => {
|
|
4987
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
4988
|
+
const productParts = this.product.tag.split(':');
|
|
4989
|
+
const productKey = productParts[1] || productParts[0];
|
|
4990
|
+
const brokerKey = brokerTag.replace(/-/g, '_');
|
|
4991
|
+
const key = `BROKER_${sanitize(productKey)}_${sanitize(brokerKey)}_${sanitize(envSlug)}_${sanitize(keyName)}`;
|
|
4992
|
+
console.log(`${logPrefix} Generated secret key: ${key}`);
|
|
4993
|
+
return key;
|
|
4994
|
+
};
|
|
4995
|
+
const storeAsSecret = async (value, keyName) => {
|
|
4996
|
+
console.log(`${logPrefix} Processing field: ${keyName}`);
|
|
4997
|
+
if (!value) {
|
|
4998
|
+
console.log(`${logPrefix} Field ${keyName} is empty, skipping`);
|
|
4999
|
+
return value;
|
|
5000
|
+
}
|
|
5001
|
+
const secretCheck = (0, secrets_1.isSecretReference)(value);
|
|
5002
|
+
if (secretCheck.isSecret) {
|
|
5003
|
+
console.log(`${logPrefix} Field ${keyName} is already a secret reference: ${value}`);
|
|
5004
|
+
return value;
|
|
5005
|
+
}
|
|
5006
|
+
const secretKey = generateSecretKey(keyName);
|
|
5007
|
+
console.log(`${logPrefix} Storing ${keyName} as secret with key: ${secretKey}`);
|
|
5008
|
+
try {
|
|
5009
|
+
const exists = await secretsService.exists(secretKey);
|
|
5010
|
+
console.log(`${logPrefix} Secret ${secretKey} exists: ${exists}`);
|
|
5011
|
+
if (exists) {
|
|
5012
|
+
console.log(`${logPrefix} Updating existing secret: ${secretKey}`);
|
|
5013
|
+
await secretsService.update(secretKey, { value });
|
|
5014
|
+
console.log(`${logPrefix} Secret ${secretKey} updated successfully`);
|
|
5015
|
+
}
|
|
5016
|
+
else {
|
|
5017
|
+
console.log(`${logPrefix} Creating new secret: ${secretKey}`);
|
|
5018
|
+
await secretsService.create({
|
|
5019
|
+
key: secretKey,
|
|
5020
|
+
value,
|
|
5021
|
+
description: `Message broker ${keyName} for ${brokerTag} in ${envSlug}`,
|
|
5022
|
+
scope: [this.product.tag, brokerTag],
|
|
5023
|
+
envs: [envSlug],
|
|
5024
|
+
});
|
|
5025
|
+
console.log(`${logPrefix} Secret ${secretKey} created successfully`);
|
|
5026
|
+
}
|
|
5027
|
+
const secretRef = `$Secret{${secretKey}}`;
|
|
5028
|
+
console.log(`${logPrefix} Field ${keyName} converted to secret reference: ${secretRef}`);
|
|
5029
|
+
return secretRef;
|
|
5030
|
+
}
|
|
5031
|
+
catch (error) {
|
|
5032
|
+
console.error(`${logPrefix} Failed to store ${keyName} as secret:`, error);
|
|
5033
|
+
console.warn(`${logPrefix} Returning original value for ${keyName}`);
|
|
5034
|
+
return value;
|
|
5035
|
+
}
|
|
5036
|
+
};
|
|
5037
|
+
// Handle different broker types - config is passed directly without wrapper
|
|
5038
|
+
console.log(`${logPrefix} Processing broker type: ${brokerType}`);
|
|
5039
|
+
if (brokerType === productsBuilder_types_1.MessageBrokerTypes.REDIS) {
|
|
5040
|
+
console.log(`${logPrefix} Redis config detected`);
|
|
5041
|
+
console.log(`${logPrefix} Redis fields - host: ${config.host}, port: ${config.port}, password: ${config.password ? '[SET]' : '[NOT SET]'}`);
|
|
5042
|
+
if (config.password) {
|
|
5043
|
+
config.password = await storeAsSecret(config.password, 'PASSWORD');
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.RABBITMQ) {
|
|
5047
|
+
console.log(`${logPrefix} RabbitMQ config detected`);
|
|
5048
|
+
console.log(`${logPrefix} RabbitMQ fields - url: ${config.url ? '[SET]' : '[NOT SET]'}`);
|
|
5049
|
+
if (config.url) {
|
|
5050
|
+
config.url = await storeAsSecret(config.url, 'URL');
|
|
5051
|
+
}
|
|
5052
|
+
}
|
|
5053
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.KAFKA) {
|
|
5054
|
+
console.log(`${logPrefix} Kafka config detected`);
|
|
5055
|
+
console.log(`${logPrefix} Kafka fields - brokers: ${(_a = config.brokers) === null || _a === void 0 ? void 0 : _a.join(', ')}, clientId: ${config.clientId}, ssl: ${config.ssl}`);
|
|
5056
|
+
console.log(`${logPrefix} Kafka SASL - mechanism: ${((_b = config.sasl) === null || _b === void 0 ? void 0 : _b.mechanism) || 'N/A'}, username: ${((_c = config.sasl) === null || _c === void 0 ? void 0 : _c.username) ? '[SET]' : '[NOT SET]'}, password: ${((_d = config.sasl) === null || _d === void 0 ? void 0 : _d.password) ? '[SET]' : '[NOT SET]'}`);
|
|
5057
|
+
if ((_e = config.sasl) === null || _e === void 0 ? void 0 : _e.username) {
|
|
5058
|
+
config.sasl.username = await storeAsSecret(config.sasl.username, 'SASL_USERNAME');
|
|
5059
|
+
}
|
|
5060
|
+
if ((_f = config.sasl) === null || _f === void 0 ? void 0 : _f.password) {
|
|
5061
|
+
config.sasl.password = await storeAsSecret(config.sasl.password, 'SASL_PASSWORD');
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.AWS_SQS) {
|
|
5065
|
+
console.log(`${logPrefix} AWS SQS config detected`);
|
|
5066
|
+
console.log(`${logPrefix} AWS SQS fields - region: ${config.region}, accessKeyId: ${config.accessKeyId ? '[SET]' : '[NOT SET]'}, secretAccessKey: ${config.secretAccessKey ? '[SET]' : '[NOT SET]'}`);
|
|
5067
|
+
if (config.accessKeyId) {
|
|
5068
|
+
config.accessKeyId = await storeAsSecret(config.accessKeyId, 'ACCESS_KEY_ID');
|
|
5069
|
+
}
|
|
5070
|
+
if (config.secretAccessKey) {
|
|
5071
|
+
config.secretAccessKey = await storeAsSecret(config.secretAccessKey, 'SECRET_ACCESS_KEY');
|
|
5072
|
+
}
|
|
5073
|
+
}
|
|
5074
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.NATS) {
|
|
5075
|
+
console.log(`${logPrefix} NATS config detected`);
|
|
5076
|
+
console.log(`${logPrefix} NATS fields - servers: ${(_g = config.servers) === null || _g === void 0 ? void 0 : _g.join(', ')}, token: ${config.token ? '[SET]' : '[NOT SET]'}, user: ${config.user ? '[SET]' : '[NOT SET]'}, pass: ${config.pass ? '[SET]' : '[NOT SET]'}, tls: ${config.tls}`);
|
|
5077
|
+
if (config.token) {
|
|
5078
|
+
config.token = await storeAsSecret(config.token, 'TOKEN');
|
|
5079
|
+
}
|
|
5080
|
+
if (config.user) {
|
|
5081
|
+
config.user = await storeAsSecret(config.user, 'USER');
|
|
5082
|
+
}
|
|
5083
|
+
if (config.pass) {
|
|
5084
|
+
config.pass = await storeAsSecret(config.pass, 'PASSWORD');
|
|
5085
|
+
}
|
|
5086
|
+
}
|
|
5087
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.GOOGLE_PUBSUB) {
|
|
5088
|
+
console.log(`${logPrefix} Google Pub/Sub config detected`);
|
|
5089
|
+
console.log(`${logPrefix} Google Pub/Sub fields - projectId: ${config.projectId}, credentials: ${config.credentials ? '[SET]' : '[NOT SET]'}`);
|
|
5090
|
+
if (config.credentials) {
|
|
5091
|
+
console.log(`${logPrefix} Google Pub/Sub credentials - type: ${config.credentials.type}, project_id: ${config.credentials.project_id}`);
|
|
5092
|
+
console.log(`${logPrefix} Google Pub/Sub credentials - private_key_id: ${config.credentials.private_key_id ? '[SET]' : '[NOT SET]'}, private_key: ${config.credentials.private_key ? '[SET]' : '[NOT SET]'}`);
|
|
5093
|
+
console.log(`${logPrefix} Google Pub/Sub credentials - client_email: ${config.credentials.client_email ? '[SET]' : '[NOT SET]'}, client_id: ${config.credentials.client_id ? '[SET]' : '[NOT SET]'}`);
|
|
5094
|
+
if (config.credentials.private_key_id) {
|
|
5095
|
+
config.credentials.private_key_id = await storeAsSecret(config.credentials.private_key_id, 'PRIVATE_KEY_ID');
|
|
5096
|
+
}
|
|
5097
|
+
if (config.credentials.private_key) {
|
|
5098
|
+
config.credentials.private_key = await storeAsSecret(config.credentials.private_key, 'PRIVATE_KEY');
|
|
5099
|
+
}
|
|
5100
|
+
if (config.credentials.client_email) {
|
|
5101
|
+
config.credentials.client_email = await storeAsSecret(config.credentials.client_email, 'CLIENT_EMAIL');
|
|
5102
|
+
}
|
|
5103
|
+
if (config.credentials.client_id) {
|
|
5104
|
+
config.credentials.client_id = await storeAsSecret(config.credentials.client_id, 'CLIENT_ID');
|
|
5105
|
+
}
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
else {
|
|
5109
|
+
console.log(`${logPrefix} Unknown broker type: ${brokerType}, no secrets processing`);
|
|
5110
|
+
}
|
|
5111
|
+
console.log(`${logPrefix} Secrets processing completed for ${brokerTag}:${envSlug}`);
|
|
5112
|
+
return config;
|
|
5113
|
+
}
|
|
5114
|
+
/**
|
|
5115
|
+
* Process notification environment config to store sensitive credentials as secrets
|
|
5116
|
+
* Format: NOTIFIER_{PRODUCT}_{NOTIFIER_TAG}_{ENV}_{KEY}
|
|
5117
|
+
*
|
|
5118
|
+
* Product parsing: split by ":", select first element
|
|
5119
|
+
* Notifier tag: replace "-" with "_"
|
|
5120
|
+
*/
|
|
5121
|
+
async processNotificationEnvSecrets(env, notifierTag, envSlug) {
|
|
5122
|
+
var _a, _b;
|
|
5123
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5124
|
+
if (!secretsService) {
|
|
5125
|
+
return env;
|
|
5126
|
+
}
|
|
5127
|
+
const generateSecretKey = (keyName) => {
|
|
5128
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5129
|
+
const productParts = this.product.tag.split(':');
|
|
5130
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
5131
|
+
const notifierKey = notifierTag.replace(/-/g, '_');
|
|
5132
|
+
return `NOTIFIER_${sanitize(productKey)}_${sanitize(notifierKey)}_${sanitize(envSlug)}_${sanitize(keyName)}`;
|
|
5133
|
+
};
|
|
5134
|
+
const storeAsSecret = async (value, keyName) => {
|
|
5135
|
+
if (!value)
|
|
5136
|
+
return value;
|
|
5137
|
+
const secretCheck = (0, secrets_1.isSecretReference)(value);
|
|
5138
|
+
if (secretCheck.isSecret) {
|
|
5139
|
+
return value; // Already a secret reference
|
|
5140
|
+
}
|
|
5141
|
+
const secretKey = generateSecretKey(keyName);
|
|
5142
|
+
try {
|
|
5143
|
+
const exists = await secretsService.exists(secretKey);
|
|
5144
|
+
if (exists) {
|
|
5145
|
+
await secretsService.update(secretKey, { value });
|
|
5146
|
+
}
|
|
5147
|
+
else {
|
|
5148
|
+
await secretsService.create({
|
|
5149
|
+
key: secretKey,
|
|
5150
|
+
value,
|
|
5151
|
+
description: `Notification ${keyName} for ${notifierTag} in ${envSlug}`,
|
|
5152
|
+
scope: [this.product.tag, notifierTag],
|
|
5153
|
+
envs: [envSlug],
|
|
5154
|
+
});
|
|
5155
|
+
}
|
|
5156
|
+
return `$Secret{${secretKey}}`;
|
|
5157
|
+
}
|
|
5158
|
+
catch (error) {
|
|
5159
|
+
console.warn(`Failed to store notification credential as secret: ${error}`);
|
|
5160
|
+
return value;
|
|
5161
|
+
}
|
|
3059
5162
|
};
|
|
5163
|
+
const result = Object.assign({}, env);
|
|
5164
|
+
// Process email handler
|
|
5165
|
+
if ((_a = result.emails) === null || _a === void 0 ? void 0 : _a.auth) {
|
|
5166
|
+
result.emails = Object.assign(Object.assign({}, result.emails), { auth: Object.assign(Object.assign({}, result.emails.auth), { pass: await storeAsSecret(result.emails.auth.pass, 'EMAIL_PASSWORD') }) });
|
|
5167
|
+
}
|
|
5168
|
+
// Process SMS handler
|
|
5169
|
+
if (result.sms) {
|
|
5170
|
+
const smsUpdates = {};
|
|
5171
|
+
if (result.sms.authToken) {
|
|
5172
|
+
smsUpdates.authToken = await storeAsSecret(result.sms.authToken, 'SMS_AUTH_TOKEN');
|
|
5173
|
+
}
|
|
5174
|
+
if (result.sms.apiSecret) {
|
|
5175
|
+
smsUpdates.apiSecret = await storeAsSecret(result.sms.apiSecret, 'SMS_API_SECRET');
|
|
5176
|
+
}
|
|
5177
|
+
if (result.sms.apiKey) {
|
|
5178
|
+
smsUpdates.apiKey = await storeAsSecret(result.sms.apiKey, 'SMS_API_KEY');
|
|
5179
|
+
}
|
|
5180
|
+
if (result.sms.accountSid) {
|
|
5181
|
+
smsUpdates.accountSid = await storeAsSecret(result.sms.accountSid, 'SMS_ACCOUNT_SID');
|
|
5182
|
+
}
|
|
5183
|
+
result.sms = Object.assign(Object.assign({}, result.sms), smsUpdates);
|
|
5184
|
+
}
|
|
5185
|
+
// Process push notifications handler (Firebase credentials)
|
|
5186
|
+
if ((_b = result.push_notifications) === null || _b === void 0 ? void 0 : _b.credentials) {
|
|
5187
|
+
const creds = result.push_notifications.credentials;
|
|
5188
|
+
if (creds.private_key) {
|
|
5189
|
+
result.push_notifications = Object.assign(Object.assign({}, result.push_notifications), { credentials: Object.assign(Object.assign({}, creds), { private_key: await storeAsSecret(creds.private_key, 'PUSH_PRIVATE_KEY') }) });
|
|
5190
|
+
}
|
|
5191
|
+
}
|
|
5192
|
+
return result;
|
|
5193
|
+
}
|
|
5194
|
+
/**
|
|
5195
|
+
* Store graph connection URL as a secret
|
|
5196
|
+
* Format: GRAPH_{PRODUCT}_{GRAPH_TAG}_{ENV}_URL
|
|
5197
|
+
*/
|
|
5198
|
+
async storeGraphConnectionUrlAsSecret(connectionUrl, graphTag, envSlug) {
|
|
5199
|
+
var _a;
|
|
5200
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Starting secret conversion:', {
|
|
5201
|
+
graphTag,
|
|
5202
|
+
envSlug,
|
|
5203
|
+
hasConnectionUrl: !!connectionUrl,
|
|
5204
|
+
connectionUrlLength: connectionUrl === null || connectionUrl === void 0 ? void 0 : connectionUrl.length,
|
|
5205
|
+
productTag: (_a = this.product) === null || _a === void 0 ? void 0 : _a.tag,
|
|
5206
|
+
});
|
|
5207
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5208
|
+
if (!secretsService) {
|
|
5209
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] No secrets service available, returning original value');
|
|
5210
|
+
return connectionUrl;
|
|
5211
|
+
}
|
|
5212
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secrets service is available');
|
|
5213
|
+
const secretCheck = (0, secrets_1.isSecretReference)(connectionUrl);
|
|
5214
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secret reference check:', {
|
|
5215
|
+
isSecret: secretCheck.isSecret,
|
|
5216
|
+
secretKey: secretCheck.isSecret ? secretCheck.key : null,
|
|
5217
|
+
});
|
|
5218
|
+
if (secretCheck.isSecret) {
|
|
5219
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Value is already a secret reference, returning as-is');
|
|
5220
|
+
return connectionUrl;
|
|
5221
|
+
}
|
|
5222
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5223
|
+
const productParts = this.product.tag.split(':');
|
|
5224
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
5225
|
+
const graphKey = graphTag.replace(/-/g, '_');
|
|
5226
|
+
const secretKey = `GRAPH_${sanitize(productKey)}_${sanitize(graphKey)}_${sanitize(envSlug)}_URL`;
|
|
5227
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Generated secret key:', {
|
|
5228
|
+
secretKey,
|
|
5229
|
+
productParts,
|
|
5230
|
+
productKey,
|
|
5231
|
+
graphKey,
|
|
5232
|
+
});
|
|
5233
|
+
try {
|
|
5234
|
+
const exists = await secretsService.exists(secretKey);
|
|
5235
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secret exists check:', { secretKey, exists });
|
|
5236
|
+
if (exists) {
|
|
5237
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Updating existing secret:', secretKey);
|
|
5238
|
+
await secretsService.update(secretKey, { value: connectionUrl });
|
|
5239
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secret updated successfully');
|
|
5240
|
+
}
|
|
5241
|
+
else {
|
|
5242
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Creating new secret:', {
|
|
5243
|
+
secretKey,
|
|
5244
|
+
description: `Graph connection URL for ${graphTag} in ${envSlug}`,
|
|
5245
|
+
scope: [this.product.tag, graphTag],
|
|
5246
|
+
envs: [envSlug],
|
|
5247
|
+
});
|
|
5248
|
+
await secretsService.create({
|
|
5249
|
+
key: secretKey,
|
|
5250
|
+
value: connectionUrl,
|
|
5251
|
+
description: `Graph connection URL for ${graphTag} in ${envSlug}`,
|
|
5252
|
+
scope: [this.product.tag, graphTag],
|
|
5253
|
+
envs: [envSlug],
|
|
5254
|
+
});
|
|
5255
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secret created successfully');
|
|
5256
|
+
}
|
|
5257
|
+
const secretRef = `$Secret{${secretKey}}`;
|
|
5258
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Returning secret reference:', secretRef);
|
|
5259
|
+
return secretRef;
|
|
5260
|
+
}
|
|
5261
|
+
catch (error) {
|
|
5262
|
+
console.error('[ProductsService.storeGraphConnectionUrlAsSecret] Failed to store secret:', {
|
|
5263
|
+
secretKey,
|
|
5264
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5265
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
5266
|
+
});
|
|
5267
|
+
return connectionUrl;
|
|
5268
|
+
}
|
|
5269
|
+
}
|
|
5270
|
+
/**
|
|
5271
|
+
* Generate a secret key for vector configuration field
|
|
5272
|
+
* Format: VECTOR_{PRODUCT}_{ASSET_TAG}_{ENV}_{KEY}
|
|
5273
|
+
*
|
|
5274
|
+
* Where:
|
|
5275
|
+
* - PRODUCT = productTag.split('.')[1] (second part after workspace)
|
|
5276
|
+
* - ASSET_TAG = if vectorTag starts with same workspace prefix, use second part; otherwise sanitize full tag
|
|
5277
|
+
* - All parts are automatically capitalized
|
|
5278
|
+
*/
|
|
5279
|
+
generateVectorSecretKey(vectorTag, envSlug, field) {
|
|
5280
|
+
var _a;
|
|
5281
|
+
console.log('[ProductsService.generateVectorSecretKey] Generating secret key:', {
|
|
5282
|
+
vectorTag,
|
|
5283
|
+
envSlug,
|
|
5284
|
+
field,
|
|
5285
|
+
productTag: (_a = this.product) === null || _a === void 0 ? void 0 : _a.tag,
|
|
5286
|
+
});
|
|
5287
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5288
|
+
// Support both ':' and '.' delimiters for product tags (e.g., 'ductape:rematch' or 'ductape.rematch')
|
|
5289
|
+
const productParts = this.product.tag.includes(':')
|
|
5290
|
+
? this.product.tag.split(':')
|
|
5291
|
+
: this.product.tag.split('.');
|
|
5292
|
+
const product = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
5293
|
+
const workspace = productParts[0];
|
|
5294
|
+
console.log('[ProductsService.generateVectorSecretKey] Product parsing:', {
|
|
5295
|
+
productParts,
|
|
5296
|
+
product,
|
|
5297
|
+
workspace,
|
|
5298
|
+
});
|
|
5299
|
+
// Support both ':' and '.' delimiters for vector tags
|
|
5300
|
+
const vectorParts = vectorTag.includes(':') ? vectorTag.split(':') : vectorTag.split('.');
|
|
5301
|
+
let assetTag;
|
|
5302
|
+
if (vectorParts.length > 1 && vectorParts[0] === workspace) {
|
|
5303
|
+
// Same workspace prefix, use second part
|
|
5304
|
+
assetTag = vectorParts[1];
|
|
5305
|
+
console.log('[ProductsService.generateVectorSecretKey] Using second part of vectorTag:', assetTag);
|
|
5306
|
+
}
|
|
5307
|
+
else {
|
|
5308
|
+
// Different or no prefix, use full tag
|
|
5309
|
+
assetTag = vectorTag;
|
|
5310
|
+
console.log('[ProductsService.generateVectorSecretKey] Using full vectorTag:', assetTag);
|
|
5311
|
+
}
|
|
5312
|
+
const secretKey = `VECTOR_${sanitize(product)}_${sanitize(assetTag)}_${sanitize(envSlug)}_${sanitize(field)}`;
|
|
5313
|
+
console.log('[ProductsService.generateVectorSecretKey] Generated secret key:', secretKey);
|
|
5314
|
+
return secretKey;
|
|
5315
|
+
}
|
|
5316
|
+
/**
|
|
5317
|
+
* Store a vector field value as a secret if it exists and is not already a secret reference
|
|
5318
|
+
* @returns The secret reference if stored, or the original value
|
|
5319
|
+
*/
|
|
5320
|
+
async storeVectorFieldAsSecret(value, vectorTag, envSlug, fieldName, description) {
|
|
5321
|
+
var _a;
|
|
5322
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Starting secret conversion:', {
|
|
5323
|
+
vectorTag,
|
|
5324
|
+
envSlug,
|
|
5325
|
+
fieldName,
|
|
5326
|
+
hasValue: !!value,
|
|
5327
|
+
valueLength: value === null || value === void 0 ? void 0 : value.length,
|
|
5328
|
+
productTag: (_a = this.product) === null || _a === void 0 ? void 0 : _a.tag,
|
|
5329
|
+
});
|
|
5330
|
+
if (!value) {
|
|
5331
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] No value provided, returning undefined');
|
|
5332
|
+
return undefined;
|
|
5333
|
+
}
|
|
5334
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5335
|
+
if (!secretsService) {
|
|
5336
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] No secrets service available, returning original value');
|
|
5337
|
+
return value;
|
|
5338
|
+
}
|
|
5339
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secrets service is available');
|
|
5340
|
+
const secretCheck = (0, secrets_1.isSecretReference)(value);
|
|
5341
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secret reference check:', {
|
|
5342
|
+
isSecret: secretCheck.isSecret,
|
|
5343
|
+
secretKey: secretCheck.isSecret ? secretCheck.key : null,
|
|
5344
|
+
});
|
|
5345
|
+
if (secretCheck.isSecret) {
|
|
5346
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Value is already a secret reference, returning as-is');
|
|
5347
|
+
return value;
|
|
5348
|
+
}
|
|
5349
|
+
const secretKey = this.generateVectorSecretKey(vectorTag, envSlug, fieldName);
|
|
5350
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Generated secret key:', secretKey);
|
|
5351
|
+
try {
|
|
5352
|
+
const exists = await secretsService.exists(secretKey);
|
|
5353
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secret exists check:', { secretKey, exists });
|
|
5354
|
+
if (exists) {
|
|
5355
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Updating existing secret:', secretKey);
|
|
5356
|
+
await secretsService.update(secretKey, { value });
|
|
5357
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secret updated successfully');
|
|
5358
|
+
}
|
|
5359
|
+
else {
|
|
5360
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Creating new secret:', {
|
|
5361
|
+
secretKey,
|
|
5362
|
+
description,
|
|
5363
|
+
scope: [this.product.tag, vectorTag],
|
|
5364
|
+
envs: [envSlug],
|
|
5365
|
+
});
|
|
5366
|
+
await secretsService.create({
|
|
5367
|
+
key: secretKey,
|
|
5368
|
+
value,
|
|
5369
|
+
description,
|
|
5370
|
+
scope: [this.product.tag, vectorTag],
|
|
5371
|
+
envs: [envSlug],
|
|
5372
|
+
});
|
|
5373
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secret created successfully');
|
|
5374
|
+
}
|
|
5375
|
+
const secretRef = `$Secret{${secretKey}}`;
|
|
5376
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Returning secret reference:', secretRef);
|
|
5377
|
+
return secretRef;
|
|
5378
|
+
}
|
|
5379
|
+
catch (error) {
|
|
5380
|
+
console.error('[ProductsService.storeVectorFieldAsSecret] Failed to store secret:', {
|
|
5381
|
+
secretKey,
|
|
5382
|
+
fieldName,
|
|
5383
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5384
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
5385
|
+
});
|
|
5386
|
+
return value;
|
|
5387
|
+
}
|
|
5388
|
+
}
|
|
5389
|
+
async storeVectorApiKeyAsSecret(apiKey, vectorTag, envSlug) {
|
|
5390
|
+
console.log('[ProductsService.storeVectorApiKeyAsSecret] Storing API key as secret:', {
|
|
5391
|
+
vectorTag,
|
|
5392
|
+
envSlug,
|
|
5393
|
+
hasApiKey: !!apiKey,
|
|
5394
|
+
apiKeyLength: apiKey === null || apiKey === void 0 ? void 0 : apiKey.length,
|
|
5395
|
+
});
|
|
5396
|
+
const result = await this.storeVectorFieldAsSecret(apiKey, vectorTag, envSlug, 'API_KEY', `Vector API key for ${vectorTag} in ${envSlug}`);
|
|
5397
|
+
console.log('[ProductsService.storeVectorApiKeyAsSecret] Result:', {
|
|
5398
|
+
hasResult: !!result,
|
|
5399
|
+
isSecretRef: result === null || result === void 0 ? void 0 : result.startsWith('$Secret{'),
|
|
5400
|
+
});
|
|
5401
|
+
return result || apiKey;
|
|
5402
|
+
}
|
|
5403
|
+
async storeVectorEndpointAsSecret(endpoint, vectorTag, envSlug) {
|
|
5404
|
+
console.log('[ProductsService.storeVectorEndpointAsSecret] Storing endpoint as secret:', {
|
|
5405
|
+
vectorTag,
|
|
5406
|
+
envSlug,
|
|
5407
|
+
hasEndpoint: !!endpoint,
|
|
5408
|
+
endpointLength: endpoint === null || endpoint === void 0 ? void 0 : endpoint.length,
|
|
5409
|
+
});
|
|
5410
|
+
const result = await this.storeVectorFieldAsSecret(endpoint, vectorTag, envSlug, 'ENDPOINT', `Vector endpoint for ${vectorTag} in ${envSlug}`);
|
|
5411
|
+
console.log('[ProductsService.storeVectorEndpointAsSecret] Result:', {
|
|
5412
|
+
hasResult: !!result,
|
|
5413
|
+
isSecretRef: result === null || result === void 0 ? void 0 : result.startsWith('$Secret{'),
|
|
5414
|
+
});
|
|
5415
|
+
return result || endpoint;
|
|
5416
|
+
}
|
|
5417
|
+
/**
|
|
5418
|
+
* Store LLM model API key as a secret
|
|
5419
|
+
* Format: MODEL_{PRODUCT}_{MODEL_TAG}_{ENV}_API_KEY
|
|
5420
|
+
*/
|
|
5421
|
+
async storeModelApiKeyAsSecret(apiKey, modelTag, envSlug) {
|
|
5422
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5423
|
+
if (!secretsService) {
|
|
5424
|
+
return apiKey;
|
|
5425
|
+
}
|
|
5426
|
+
const secretCheck = (0, secrets_1.isSecretReference)(apiKey);
|
|
5427
|
+
if (secretCheck.isSecret) {
|
|
5428
|
+
return apiKey;
|
|
5429
|
+
}
|
|
5430
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5431
|
+
const productParts = this.product.tag.split(':');
|
|
5432
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
5433
|
+
const modelKey = modelTag.replace(/-/g, '_');
|
|
5434
|
+
const secretKey = `MODEL_${sanitize(productKey)}_${sanitize(modelKey)}_${sanitize(envSlug)}_API_KEY`;
|
|
5435
|
+
try {
|
|
5436
|
+
const exists = await secretsService.exists(secretKey);
|
|
5437
|
+
if (exists) {
|
|
5438
|
+
await secretsService.update(secretKey, { value: apiKey });
|
|
5439
|
+
}
|
|
5440
|
+
else {
|
|
5441
|
+
await secretsService.create({
|
|
5442
|
+
key: secretKey,
|
|
5443
|
+
value: apiKey,
|
|
5444
|
+
description: `LLM model API key for ${modelTag} in ${envSlug}`,
|
|
5445
|
+
scope: [this.product.tag, modelTag],
|
|
5446
|
+
envs: [envSlug],
|
|
5447
|
+
});
|
|
5448
|
+
}
|
|
5449
|
+
return `$Secret{${secretKey}}`;
|
|
5450
|
+
}
|
|
5451
|
+
catch (error) {
|
|
5452
|
+
console.warn(`Failed to store model API key as secret: ${error}`);
|
|
5453
|
+
return apiKey;
|
|
5454
|
+
}
|
|
3060
5455
|
}
|
|
3061
5456
|
}
|
|
3062
5457
|
exports.default = ProductsBuilderService;
|