@ductape/sdk 0.0.4-v12 → 0.0.4-v120
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 +1254 -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/logsApi.service.d.ts +51 -0
- package/dist/api/services/logsApi.service.js +14 -0
- package/dist/api/services/logsApi.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 +745 -0
- package/dist/api/services/processorApi.service.js +536 -2
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +103 -0
- package/dist/api/services/productsApi.service.js +133 -7
- 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 +113 -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 +80 -0
- package/dist/api/urls.js +106 -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 +42 -33
- package/dist/apps/services/app.service.js +574 -223
- 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 +22 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.app.validator.js +2 -0
- package/dist/apps/validators/joi-validators/update.app.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +23 -2
- package/dist/apps/validators/joi-validators/update.appAction.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 +418 -0
- package/dist/brokers/brokers.service.js +1156 -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 +565 -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/{processor/services/messagebrokers → brokers/utils/providers}/aws-sqs.service.d.ts +3 -2
- 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/{processor/services/messagebrokers → brokers/utils/providers}/google-pubsub.service.d.ts +2 -2
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/google-pubsub.service.js +16 -7
- 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/{processor/services/messagebrokers → brokers/utils/providers}/rabbitmq.service.d.ts +4 -3
- package/dist/brokers/utils/providers/rabbitmq.service.js +118 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js.map +1 -0
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/redis.service.d.ts +3 -3
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/redis.service.js +25 -14
- package/dist/brokers/utils/providers/redis.service.js.map +1 -0
- package/dist/cache/cache.manager.d.ts +308 -0
- package/dist/cache/cache.manager.js +900 -0
- package/dist/cache/cache.manager.js.map +1 -0
- package/dist/cache/cache.service.d.ts +191 -0
- package/dist/cache/cache.service.js +594 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/cache/index.d.ts +52 -0
- package/dist/cache/index.js +81 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/types/index.d.ts +110 -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 +1476 -0
- package/dist/database/databases.service.js +3068 -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/dashboard.interface.d.ts +74 -0
- package/dist/database/types/dashboard.interface.js +7 -0
- package/dist/database/types/dashboard.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 +15 -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 +606 -0
- package/dist/graph/graphs.service.js +2434 -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 +3366 -743
- package/dist/index.js +4885 -1107
- package/dist/index.js.map +1 -1
- package/dist/init.interface.d.ts +407 -0
- package/dist/{processor/services/messagebrokers/messagebrokers.type.js → init.interface.js} +1 -1
- 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 +24 -1
- package/dist/logs/logs.types.js +9 -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 +268 -0
- package/dist/notifications/notifications.service.js +905 -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 +404 -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 +101 -72
- package/dist/processor/services/processor.service.js +1573 -1343
- 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 +358 -79
- package/dist/products/services/products.service.js +2918 -434
- 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 +6 -1
- package/dist/products/validators/index.js +14 -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.productApp.validator.js +2 -2
- package/dist/products/validators/joi-validators/create.productApp.validator.js.map +1 -1
- 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.productMessageBrokerTopic.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
- 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 +150 -51
- 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 +136 -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 +236 -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 +246 -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 +96 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/sessions.helper.d.ts +88 -0
- package/dist/sessions/sessions.helper.js +133 -0
- package/dist/sessions/sessions.helper.js.map +1 -0
- package/dist/sessions/sessions.resolver.d.ts +188 -0
- package/dist/sessions/sessions.resolver.js +603 -0
- package/dist/sessions/sessions.resolver.js.map +1 -0
- package/dist/sessions/sessions.service.d.ts +194 -0
- package/dist/sessions/sessions.service.js +987 -0
- package/dist/sessions/sessions.service.js.map +1 -0
- package/dist/sessions/types/index.d.ts +342 -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 +177 -0
- package/dist/storage/storage.service.js +897 -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/types/appBuilder.types.d.ts +12 -3
- package/dist/types/enums.d.ts +10 -1
- package/dist/types/enums.js +9 -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 +265 -38
- package/dist/types/processor.types.js +9 -1
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +954 -29
- 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 +661 -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 +476 -0
- package/dist/vector/vector-database.service.js +892 -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 +412 -0
- package/dist/workflows/workflows.service.js +1746 -0
- package/dist/workflows/workflows.service.js.map +1 -0
- package/package.json +75 -13
- 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.d.ts +0 -0
- 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/services/fallback.service.d.ts +0 -5
- package/dist/processor/services/fallback.service.js +0 -43
- package/dist/processor/services/fallback.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/aws-sqs.service.js +0 -77
- package/dist/processor/services/messagebrokers/aws-sqs.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/google-pubsub.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/index.d.ts +0 -3
- package/dist/processor/services/messagebrokers/index.js +0 -26
- package/dist/processor/services/messagebrokers/index.js.map +0 -1
- package/dist/processor/services/messagebrokers/kafka.service.d.ts +0 -14
- package/dist/processor/services/messagebrokers/kafka.service.js +0 -45
- package/dist/processor/services/messagebrokers/kafka.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/messagebrokers.type.d.ts +0 -6
- package/dist/processor/services/messagebrokers/messagebrokers.type.js.map +0 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.js +0 -67
- package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/redis.service.js.map +0 -1
- package/dist/processor/services/quota.service.d.ts +0 -15
- package/dist/processor/services/quota.service.js +0 -63
- package/dist/processor/services/quota.service.js.map +0 -1
- package/dist/processor/utils/mongo.util.d.ts +0 -0
- 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/test.appBuilder.d.ts +0 -1
- package/dist/test/test.appBuilder.js +0 -16
- package/dist/test/test.appBuilder.js.map +0 -1
- package/dist/test/test.health.d.ts +0 -1
- package/dist/test/test.health.js +0 -49
- package/dist/test/test.health.js.map +0 -1
- package/dist/test/test.import.d.ts +0 -1
- package/dist/test/test.import.js +0 -1460
- package/dist/test/test.import.js.map +0 -1
- package/dist/test/test.import.openapi.d.ts +0 -1
- package/dist/test/test.import.openapi.js +0 -76
- package/dist/test/test.import.openapi.js.map +0 -1
- package/dist/test/test.imports.d.ts +0 -1
- package/dist/test/test.imports.js +0 -62
- package/dist/test/test.imports.js.map +0 -1
- package/dist/test/test.logs.d.ts +0 -1
- package/dist/test/test.logs.js +0 -18
- package/dist/test/test.logs.js.map +0 -1
- package/dist/test/test.processor.d.ts +0 -1
- package/dist/test/test.processor.js +0 -123
- package/dist/test/test.processor.js.map +0 -1
- package/dist/test/test.productBuilder.d.ts +0 -1
- package/dist/test/test.productBuilder.js +0 -661
- package/dist/test/test.productBuilder.js.map +0 -1
- package/dist/test.appBuilder.d.ts +0 -1
- package/dist/test.appBuilder.js +0 -14
- package/dist/test.appBuilder.js.map +0 -1
- package/dist/test.import.d.ts +0 -0
- package/dist/test.import.js +0 -24
- package/dist/test.import.js.map +0 -1
- package/dist/test.imports.d.ts +0 -1
- package/dist/test.imports.js +0 -28
- package/dist/test.imports.js.map +0 -1
- package/dist/test.integrationBuilder.d.ts +0 -1
- package/dist/test.integrationBuilder.js +0 -276
- package/dist/test.integrationBuilder.js.map +0 -1
- package/dist/test.processor.d.ts +0 -1
- package/dist/test.processor.js +0 -23
- package/dist/test.processor.js.map +0 -1
- package/dist/test.utils.d.ts +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/{actions/actions.service.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, queues }) {
|
|
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);
|
|
@@ -63,13 +66,22 @@ class ProductsBuilderService {
|
|
|
63
66
|
this.queues = queues;
|
|
64
67
|
}
|
|
65
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
|
+
}
|
|
66
78
|
async createHealthcheck(data) {
|
|
67
79
|
try {
|
|
68
80
|
await validators_1.CreateProductHealthcheckSchema.validateAsync(data);
|
|
69
81
|
if (!data.tag) {
|
|
70
82
|
throw new Error('tag field is required');
|
|
71
83
|
}
|
|
72
|
-
const exists = this.fetchHealthcheck(data.app, data.tag);
|
|
84
|
+
const exists = await this.fetchHealthcheck(data.app, data.tag);
|
|
73
85
|
if (!exists) {
|
|
74
86
|
const { app: access_tag, event: action } = data;
|
|
75
87
|
const app = await this.fetchThirdPartyAppByAccessTag(access_tag);
|
|
@@ -79,31 +91,30 @@ class ProductsBuilderService {
|
|
|
79
91
|
}
|
|
80
92
|
const event = version.actions.find((act) => act.tag === action);
|
|
81
93
|
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
82
|
-
const exists = this.fetchEnv(env.slug);
|
|
94
|
+
const exists = await this.fetchEnv(env.slug);
|
|
83
95
|
if (!exists) {
|
|
84
96
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
85
97
|
}
|
|
86
98
|
await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
|
|
87
|
-
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.
|
|
88
|
-
console.log(
|
|
99
|
+
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.product.private_key);
|
|
100
|
+
console.log('INPUT', env);
|
|
89
101
|
return env;
|
|
90
102
|
}));
|
|
91
|
-
const envs = this.fetchEnvs();
|
|
92
|
-
console.log(
|
|
93
|
-
console.log(
|
|
103
|
+
const envs = await this.fetchEnvs();
|
|
104
|
+
console.log('ENVS ===>>>>', envs);
|
|
105
|
+
console.log('DBENVS ====>>>>', data.envs);
|
|
94
106
|
envs.map((env) => {
|
|
95
107
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
96
108
|
if (exists === -1) {
|
|
97
109
|
throw new Error(`Product env ${env.slug} is not defined, please provide details`);
|
|
98
110
|
}
|
|
99
111
|
});
|
|
100
|
-
console.log(
|
|
112
|
+
console.log('UPDATING VALUE', data);
|
|
101
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());
|
|
102
|
-
await this.initializeProduct(this.product_id);
|
|
103
114
|
data.envs.map(async (env) => {
|
|
104
115
|
const payload = {
|
|
105
116
|
app: data.app,
|
|
106
|
-
|
|
117
|
+
action: data.event,
|
|
107
118
|
input: env.input,
|
|
108
119
|
env: env.slug,
|
|
109
120
|
product: this.product.tag,
|
|
@@ -126,20 +137,20 @@ class ProductsBuilderService {
|
|
|
126
137
|
async updateHealthcheck(tag, data) {
|
|
127
138
|
try {
|
|
128
139
|
// 1. Fetch the existing healthcheck
|
|
129
|
-
const healthcheck = this.fetchHealthcheck(data.app, tag);
|
|
140
|
+
const healthcheck = await this.fetchHealthcheck(data.app, tag);
|
|
130
141
|
if (!healthcheck) {
|
|
131
142
|
throw new Error(`Healthcheck with tag: ${tag} not found`);
|
|
132
143
|
}
|
|
133
144
|
// 2. Validate the incoming data
|
|
134
145
|
await validators_1.CreateProductHealthcheckSchema.validateAsync(data); // No Update schema, use Create
|
|
135
146
|
// 3. Check for tag conflicts
|
|
136
|
-
if (data.tag && data.tag !== tag && this.fetchHealthcheck(data.app, data.tag)) {
|
|
147
|
+
if (data.tag && data.tag !== tag && (await this.fetchHealthcheck(data.app, data.tag))) {
|
|
137
148
|
throw new Error(`Healthcheck with tag ${data.tag} already exists`);
|
|
138
149
|
}
|
|
139
150
|
// 4. Validate and process envs
|
|
140
151
|
if (data.envs) {
|
|
141
152
|
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
142
|
-
const exists = this.fetchEnv(env.slug);
|
|
153
|
+
const exists = await this.fetchEnv(env.slug);
|
|
143
154
|
if (!exists) {
|
|
144
155
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
145
156
|
}
|
|
@@ -152,13 +163,13 @@ class ProductsBuilderService {
|
|
|
152
163
|
}
|
|
153
164
|
const event = version.actions.find((act) => act.tag === data.event);
|
|
154
165
|
await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
|
|
155
|
-
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.
|
|
166
|
+
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.product.private_key);
|
|
156
167
|
}
|
|
157
168
|
return env;
|
|
158
169
|
}));
|
|
159
170
|
}
|
|
160
171
|
// 5. Ensure all product envs are covered
|
|
161
|
-
const envs = this.fetchEnvs();
|
|
172
|
+
const envs = await this.fetchEnvs();
|
|
162
173
|
envs.map((env) => {
|
|
163
174
|
var _a;
|
|
164
175
|
const exists = (_a = data.envs) === null || _a === void 0 ? void 0 : _a.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
@@ -168,24 +179,29 @@ class ProductsBuilderService {
|
|
|
168
179
|
});
|
|
169
180
|
// 6. Update the healthcheck
|
|
170
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());
|
|
171
|
-
await this.initializeProduct(this.product_id);
|
|
172
182
|
}
|
|
173
183
|
catch (e) {
|
|
174
184
|
throw e;
|
|
175
185
|
}
|
|
176
186
|
}
|
|
177
|
-
fetchHealthcheck(access_tag, tag, throwError = false) {
|
|
178
|
-
const
|
|
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);
|
|
179
190
|
if (!health && throwError)
|
|
180
191
|
throw new Error(`Healthcheck ${tag} not found`);
|
|
181
|
-
return health;
|
|
192
|
+
return health || null;
|
|
182
193
|
}
|
|
183
|
-
fetchHealthchecks(access_tag, throwError = false) {
|
|
184
|
-
const
|
|
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);
|
|
185
197
|
if (!health && throwError)
|
|
186
198
|
throw new Error(`Access tag ${access_tag} not found`);
|
|
187
199
|
return health;
|
|
188
200
|
}
|
|
201
|
+
async fetchProductHealthchecks() {
|
|
202
|
+
const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
|
|
203
|
+
return healthchecks;
|
|
204
|
+
}
|
|
189
205
|
async updateDataValidation(selector, update) {
|
|
190
206
|
if (!selector.startsWith('$Data{') && !selector.startsWith('$Filter')) {
|
|
191
207
|
throw new Error(`selector ${selector} is expected to start with $Data or $Filter`);
|
|
@@ -199,26 +215,27 @@ class ProductsBuilderService {
|
|
|
199
215
|
if (stages.length < 3) {
|
|
200
216
|
throw new Error(`Invalid selector ${selector}`);
|
|
201
217
|
}
|
|
202
|
-
const tag = stages[0];
|
|
203
|
-
const type = stages[1];
|
|
218
|
+
const tag = String(stages[0]);
|
|
219
|
+
const type = String(stages[1]);
|
|
204
220
|
let size = 2;
|
|
205
221
|
let data;
|
|
206
222
|
switch (type) {
|
|
207
223
|
case productsBuilder_types_1.FeatureEventTypes.DB_ACTION:
|
|
208
|
-
const action = this.fetchDatabaseAction(tag);
|
|
224
|
+
const action = await this.fetchDatabaseAction(tag);
|
|
209
225
|
if (!action)
|
|
210
226
|
throw new Error(`DB Action ${tag} not found`);
|
|
211
227
|
data = useData ? action.data : action.filterData;
|
|
212
228
|
break;
|
|
213
229
|
case productsBuilder_types_1.FeatureEventTypes.NOTIFICATION:
|
|
214
230
|
size = 3;
|
|
215
|
-
|
|
216
|
-
|
|
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`);
|
|
217
234
|
}
|
|
218
|
-
const notification = this.fetchNotificationMessage(tag);
|
|
235
|
+
const notification = await this.fetchNotificationMessage(tag);
|
|
219
236
|
if (!notification)
|
|
220
237
|
throw new Error(`Notification ${tag} not found`);
|
|
221
|
-
if (
|
|
238
|
+
if (stage3Str === 'push') {
|
|
222
239
|
data = notification.push_notification_data;
|
|
223
240
|
}
|
|
224
241
|
if (stages[3] === 'callback') {
|
|
@@ -260,11 +277,11 @@ class ProductsBuilderService {
|
|
|
260
277
|
await validators_1.CreateProductBuilderSchema.validateAsync(data);
|
|
261
278
|
const exists = await this.checkIfProductExists(data.name);
|
|
262
279
|
if (exists && (exists === null || exists === void 0 ? void 0 : exists._id)) {
|
|
263
|
-
await this.initializeProduct(exists
|
|
280
|
+
// await this.initializeProduct(exists?._id);
|
|
264
281
|
}
|
|
265
282
|
else {
|
|
266
283
|
const product = await this.createNewProduct(data);
|
|
267
|
-
await this.initializeProduct(product._id);
|
|
284
|
+
// await this.initializeProduct(product._id);
|
|
268
285
|
}
|
|
269
286
|
}
|
|
270
287
|
catch (e) {
|
|
@@ -275,10 +292,26 @@ class ProductsBuilderService {
|
|
|
275
292
|
if (!this.workspace) {
|
|
276
293
|
this.workspace = await this.workspaceApi.fetchWorkspaceById(this.getUserAccess(), subCheck);
|
|
277
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;
|
|
278
311
|
}
|
|
279
312
|
async initializeProduct(product_id) {
|
|
280
313
|
try {
|
|
281
|
-
this.product = await this.productApi.
|
|
314
|
+
this.product = (await this.productApi.initProduct(product_id, this.getUserAccess()));
|
|
282
315
|
this.product_id = product_id;
|
|
283
316
|
}
|
|
284
317
|
catch (e) {
|
|
@@ -287,21 +320,64 @@ class ProductsBuilderService {
|
|
|
287
320
|
}
|
|
288
321
|
async initializeProductByTag(tag) {
|
|
289
322
|
try {
|
|
290
|
-
this.product = await this.productApi.
|
|
291
|
-
|
|
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
|
+
}
|
|
292
327
|
this.product_id = this.product._id;
|
|
293
328
|
}
|
|
294
329
|
catch (e) {
|
|
295
330
|
throw e;
|
|
296
331
|
}
|
|
297
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
|
+
}
|
|
298
375
|
async updateProduct(data) {
|
|
299
376
|
try {
|
|
300
377
|
if (!this.app_id)
|
|
301
378
|
throw new Error('Product not initialized');
|
|
302
379
|
await validators_1.CreateProductBuilderSchema.validateAsync(data);
|
|
303
380
|
await this.productApi.updateProduct(this.product_id, Object.assign({}, data), this.getUserAccess());
|
|
304
|
-
await this.initializeProduct(this.product_id);
|
|
305
381
|
}
|
|
306
382
|
catch (e) {
|
|
307
383
|
throw e;
|
|
@@ -318,11 +394,11 @@ class ProductsBuilderService {
|
|
|
318
394
|
return false;
|
|
319
395
|
}
|
|
320
396
|
}
|
|
321
|
-
fetchProduct() {
|
|
397
|
+
async fetchProduct() {
|
|
322
398
|
if (!this.product) {
|
|
323
399
|
throw new Error('Product not yet initiated');
|
|
324
400
|
}
|
|
325
|
-
return this.product;
|
|
401
|
+
return await this.productApi.fetchProductByTag(this.product.tag, this.getUserAccess());
|
|
326
402
|
}
|
|
327
403
|
async createSession(data, throwErrorIfExists = false) {
|
|
328
404
|
try {
|
|
@@ -330,7 +406,7 @@ class ProductsBuilderService {
|
|
|
330
406
|
if (!data.tag) {
|
|
331
407
|
throw new Error('tag field is required');
|
|
332
408
|
}
|
|
333
|
-
const exists = this.fetchSession(data.tag);
|
|
409
|
+
const exists = await this.fetchSession(data.tag);
|
|
334
410
|
if (!exists) {
|
|
335
411
|
if (!data.selector.startsWith('$Session{')) {
|
|
336
412
|
throw new Error('Selector should be in the format $Session{...}{key}');
|
|
@@ -345,19 +421,16 @@ class ProductsBuilderService {
|
|
|
345
421
|
throw new Error(`${data.selector} not found in event sample`);
|
|
346
422
|
}
|
|
347
423
|
}
|
|
348
|
-
if (current === null ||
|
|
349
|
-
|
|
350
|
-
typeof current === "object") {
|
|
351
|
-
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');
|
|
352
426
|
}
|
|
353
|
-
data.schema_data = await this.inputsService.parseJson({
|
|
427
|
+
data.schema_data = (await this.inputsService.parseJson({
|
|
354
428
|
data: data.schema,
|
|
355
|
-
expected: inputs_types_1.ExpectedValues.PARSESAMPLE
|
|
356
|
-
});
|
|
429
|
+
expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
|
|
430
|
+
}));
|
|
357
431
|
data.selectorValue = current;
|
|
358
432
|
const payload = Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE });
|
|
359
433
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
360
|
-
await this.initializeProduct(this.product_id);
|
|
361
434
|
}
|
|
362
435
|
else {
|
|
363
436
|
if (throwErrorIfExists)
|
|
@@ -370,7 +443,7 @@ class ProductsBuilderService {
|
|
|
370
443
|
}
|
|
371
444
|
async updateSession(tag, data) {
|
|
372
445
|
try {
|
|
373
|
-
const session = this.fetchSession(tag);
|
|
446
|
+
const session = await this.fetchSession(tag);
|
|
374
447
|
if (!session) {
|
|
375
448
|
throw new Error(`Session with tag: ${tag} not found`);
|
|
376
449
|
}
|
|
@@ -403,25 +476,39 @@ class ProductsBuilderService {
|
|
|
403
476
|
throw new Error(`${data.selector} not found in event sample`);
|
|
404
477
|
}
|
|
405
478
|
}
|
|
406
|
-
if (current === null ||
|
|
407
|
-
|
|
408
|
-
typeof current === "object") {
|
|
409
|
-
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');
|
|
410
481
|
}
|
|
411
482
|
}
|
|
412
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());
|
|
413
|
-
await this.initializeProduct(this.product_id);
|
|
414
484
|
}
|
|
415
485
|
catch (e) {
|
|
416
486
|
throw e;
|
|
417
487
|
}
|
|
418
488
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
return
|
|
489
|
+
async fetchSessions(version) {
|
|
490
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'session', this.getUserAccess());
|
|
491
|
+
return components;
|
|
422
492
|
}
|
|
423
|
-
|
|
424
|
-
|
|
493
|
+
async fetchSession(tag) {
|
|
494
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'session', tag, this.getUserAccess());
|
|
495
|
+
return component;
|
|
496
|
+
}
|
|
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
|
+
}
|
|
425
512
|
}
|
|
426
513
|
async createMessageBrokerTopic(data, throwErrorIfExists = false) {
|
|
427
514
|
try {
|
|
@@ -435,16 +522,17 @@ class ProductsBuilderService {
|
|
|
435
522
|
if (data.sample)
|
|
436
523
|
data.sample = JSON.stringify(data.sample);
|
|
437
524
|
await create_productMessageBrokerTopic_validator_1.default.validateAsync(data);
|
|
438
|
-
const exists = this.fetchMessageBrokerTopic(data.tag);
|
|
439
|
-
const broker = this.fetchMessageBroker(messageBrokerTag);
|
|
440
|
-
|
|
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
|
+
}
|
|
441
530
|
data.tag = tag;
|
|
442
531
|
if (!exists) {
|
|
443
532
|
if (data.sample) {
|
|
444
533
|
data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
|
|
445
534
|
}
|
|
446
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());
|
|
447
|
-
await this.initializeProduct(this.product_id);
|
|
448
536
|
}
|
|
449
537
|
else {
|
|
450
538
|
if (throwErrorIfExists)
|
|
@@ -467,12 +555,12 @@ class ProductsBuilderService {
|
|
|
467
555
|
if (!messageBrokerTag || !tag) {
|
|
468
556
|
throw new Error(`tag is expected to be defined as "messageBrokr_tag:topic_tag"`);
|
|
469
557
|
}
|
|
470
|
-
const exists = this.fetchMessageBrokerTopic(data.tag);
|
|
558
|
+
const exists = await this.fetchMessageBrokerTopic(data.tag);
|
|
471
559
|
if (!exists) {
|
|
472
560
|
throw new Error(`Topic ${data.tag} not found`);
|
|
473
561
|
}
|
|
474
|
-
const broker = this.fetchMessageBroker(messageBrokerTag);
|
|
475
|
-
if (data.queueUrls) {
|
|
562
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
563
|
+
if (data.queueUrls && broker) {
|
|
476
564
|
(0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
|
|
477
565
|
}
|
|
478
566
|
data.tag = tag;
|
|
@@ -481,7 +569,6 @@ class ProductsBuilderService {
|
|
|
481
569
|
data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
|
|
482
570
|
}
|
|
483
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());
|
|
484
|
-
await this.initializeProduct(this.product_id);
|
|
485
572
|
}
|
|
486
573
|
else {
|
|
487
574
|
throw new Error(`Message Broker Topic ${data.tag} not found`);
|
|
@@ -491,24 +578,157 @@ class ProductsBuilderService {
|
|
|
491
578
|
throw e;
|
|
492
579
|
}
|
|
493
580
|
}
|
|
494
|
-
fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
|
|
581
|
+
async fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
|
|
495
582
|
const [messageBrokerTag, topicTag] = tag.split(':');
|
|
496
583
|
if (!messageBrokerTag || !topicTag) {
|
|
497
584
|
throw new Error(`tag is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
498
585
|
}
|
|
499
|
-
const messageBroker = this.
|
|
586
|
+
const messageBroker = await this.fetchMessageBroker(messageBrokerTag);
|
|
500
587
|
if (!messageBroker)
|
|
501
588
|
throw new Error(`MessageBroker ${messageBrokerTag} not found`);
|
|
502
|
-
const
|
|
589
|
+
const topics = messageBroker.topics || [];
|
|
590
|
+
const topic = topics.find((data) => data.tag === topicTag);
|
|
503
591
|
if (!topic && throwErrorIfExists)
|
|
504
592
|
throw new Error(`MessageBroker topic ${tag} not found`);
|
|
505
|
-
return topic;
|
|
593
|
+
return topic || null;
|
|
594
|
+
}
|
|
595
|
+
async fetchMessageBrokerTopics(messageBrokerTag) {
|
|
596
|
+
const messageBroker = await this.fetchMessageBroker(messageBrokerTag);
|
|
597
|
+
if (!messageBroker)
|
|
598
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
599
|
+
return messageBroker.topics || [];
|
|
600
|
+
}
|
|
601
|
+
// ==================== MESSAGE BROKER PRODUCERS ====================
|
|
602
|
+
async createMessageBrokerProducer(data) {
|
|
603
|
+
var _a, _b;
|
|
604
|
+
try {
|
|
605
|
+
const [messageBrokerTag, topicTag] = data.topic.split(':');
|
|
606
|
+
if (!messageBrokerTag || !topicTag) {
|
|
607
|
+
throw new Error(`topic is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
608
|
+
}
|
|
609
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
610
|
+
if (!broker) {
|
|
611
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
612
|
+
}
|
|
613
|
+
// Check if topic exists
|
|
614
|
+
const topic = (_a = broker.topics) === null || _a === void 0 ? void 0 : _a.find((t) => t.tag === topicTag);
|
|
615
|
+
if (!topic) {
|
|
616
|
+
throw new Error(`Topic ${topicTag} not found in broker ${messageBrokerTag}`);
|
|
617
|
+
}
|
|
618
|
+
// Check if producer already exists
|
|
619
|
+
const existingProducer = (_b = broker.producers) === null || _b === void 0 ? void 0 : _b.find((p) => p.tag === data.tag);
|
|
620
|
+
if (existingProducer) {
|
|
621
|
+
throw new Error(`Producer ${data.tag} already exists in broker ${messageBrokerTag}`);
|
|
622
|
+
}
|
|
623
|
+
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());
|
|
624
|
+
}
|
|
625
|
+
catch (e) {
|
|
626
|
+
throw e;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
async updateMessageBrokerProducer(data) {
|
|
630
|
+
var _a;
|
|
631
|
+
try {
|
|
632
|
+
const [messageBrokerTag, topicTag] = data.topic.split(':');
|
|
633
|
+
if (!messageBrokerTag || !topicTag) {
|
|
634
|
+
throw new Error(`topic is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
635
|
+
}
|
|
636
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
637
|
+
if (!broker) {
|
|
638
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
639
|
+
}
|
|
640
|
+
// Check if producer exists
|
|
641
|
+
const existingProducer = (_a = broker.producers) === null || _a === void 0 ? void 0 : _a.find((p) => p.tag === data.tag);
|
|
642
|
+
if (!existingProducer) {
|
|
643
|
+
throw new Error(`Producer ${data.tag} not found in broker ${messageBrokerTag}`);
|
|
644
|
+
}
|
|
645
|
+
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());
|
|
646
|
+
}
|
|
647
|
+
catch (e) {
|
|
648
|
+
throw e;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
async fetchMessageBrokerProducer(brokerTag, tag) {
|
|
652
|
+
var _a;
|
|
653
|
+
const messageBrokers = this.product.messageBrokers || [];
|
|
654
|
+
const messageBroker = messageBrokers.find((data) => data.tag === brokerTag);
|
|
655
|
+
if (!messageBroker)
|
|
656
|
+
throw new Error(`MessageBroker ${brokerTag} not found`);
|
|
657
|
+
const producer = (_a = messageBroker.producers) === null || _a === void 0 ? void 0 : _a.find((p) => p.tag === tag);
|
|
658
|
+
return producer || null;
|
|
659
|
+
}
|
|
660
|
+
async fetchMessageBrokerProducers(messageBrokerTag) {
|
|
661
|
+
const messageBrokers = this.product.messageBrokers || [];
|
|
662
|
+
const messageBroker = messageBrokers.find((data) => data.tag === messageBrokerTag);
|
|
663
|
+
if (!messageBroker)
|
|
664
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
665
|
+
return messageBroker.producers || [];
|
|
666
|
+
}
|
|
667
|
+
// ==================== MESSAGE BROKER CONSUMERS ====================
|
|
668
|
+
async createMessageBrokerConsumer(data) {
|
|
669
|
+
var _a, _b;
|
|
670
|
+
try {
|
|
671
|
+
const [messageBrokerTag, topicTag] = data.topic.split(':');
|
|
672
|
+
if (!messageBrokerTag || !topicTag) {
|
|
673
|
+
throw new Error(`topic is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
674
|
+
}
|
|
675
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
676
|
+
if (!broker) {
|
|
677
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
678
|
+
}
|
|
679
|
+
// Check if topic exists
|
|
680
|
+
const topic = (_a = broker.topics) === null || _a === void 0 ? void 0 : _a.find((t) => t.tag === topicTag);
|
|
681
|
+
if (!topic) {
|
|
682
|
+
throw new Error(`Topic ${topicTag} not found in broker ${messageBrokerTag}`);
|
|
683
|
+
}
|
|
684
|
+
// Check if consumer already exists
|
|
685
|
+
const existingConsumer = (_b = broker.consumers) === null || _b === void 0 ? void 0 : _b.find((c) => c.tag === data.tag);
|
|
686
|
+
if (existingConsumer) {
|
|
687
|
+
throw new Error(`Consumer ${data.tag} already exists in broker ${messageBrokerTag}`);
|
|
688
|
+
}
|
|
689
|
+
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());
|
|
690
|
+
}
|
|
691
|
+
catch (e) {
|
|
692
|
+
throw e;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
async updateMessageBrokerConsumer(data) {
|
|
696
|
+
var _a;
|
|
697
|
+
try {
|
|
698
|
+
const [messageBrokerTag, topicTag] = data.topic.split(':');
|
|
699
|
+
if (!messageBrokerTag || !topicTag) {
|
|
700
|
+
throw new Error(`topic is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
701
|
+
}
|
|
702
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
703
|
+
if (!broker) {
|
|
704
|
+
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
705
|
+
}
|
|
706
|
+
// Check if consumer exists
|
|
707
|
+
const existingConsumer = (_a = broker.consumers) === null || _a === void 0 ? void 0 : _a.find((c) => c.tag === data.tag);
|
|
708
|
+
if (!existingConsumer) {
|
|
709
|
+
throw new Error(`Consumer ${data.tag} not found in broker ${messageBrokerTag}`);
|
|
710
|
+
}
|
|
711
|
+
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());
|
|
712
|
+
}
|
|
713
|
+
catch (e) {
|
|
714
|
+
throw e;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
async fetchMessageBrokerConsumer(brokerTag, tag) {
|
|
718
|
+
var _a;
|
|
719
|
+
const messageBrokers = this.product.messageBrokers || [];
|
|
720
|
+
const messageBroker = messageBrokers.find((data) => data.tag === brokerTag);
|
|
721
|
+
if (!messageBroker)
|
|
722
|
+
throw new Error(`MessageBroker ${brokerTag} not found`);
|
|
723
|
+
const consumer = (_a = messageBroker.consumers) === null || _a === void 0 ? void 0 : _a.find((c) => c.tag === tag);
|
|
724
|
+
return consumer || null;
|
|
506
725
|
}
|
|
507
|
-
|
|
508
|
-
const
|
|
726
|
+
async fetchMessageBrokerConsumers(messageBrokerTag) {
|
|
727
|
+
const messageBrokers = this.product.messageBrokers || [];
|
|
728
|
+
const messageBroker = messageBrokers.find((data) => data.tag === messageBrokerTag);
|
|
509
729
|
if (!messageBroker)
|
|
510
730
|
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
511
|
-
return messageBroker.
|
|
731
|
+
return messageBroker.consumers || [];
|
|
512
732
|
}
|
|
513
733
|
async validateQuotaFallbackInputAndOutput(data, type) {
|
|
514
734
|
const input = data.input;
|
|
@@ -542,7 +762,7 @@ class ProductsBuilderService {
|
|
|
542
762
|
this.checkActionQuotaFallbackInput(action.body, option.input.body, input, 'body');
|
|
543
763
|
}
|
|
544
764
|
else {
|
|
545
|
-
const feature = this.fetchFeature(option.event);
|
|
765
|
+
const feature = await this.fetchFeature(option.event);
|
|
546
766
|
if (!feature) {
|
|
547
767
|
throw new Error(`Feature ${option.event} not found`);
|
|
548
768
|
}
|
|
@@ -632,7 +852,7 @@ class ProductsBuilderService {
|
|
|
632
852
|
}
|
|
633
853
|
else {
|
|
634
854
|
// fetch feature
|
|
635
|
-
const feature = this.fetchFeature(option.event);
|
|
855
|
+
const feature = await this.fetchFeature(option.event);
|
|
636
856
|
if (!feature) {
|
|
637
857
|
throw new Error(`Feature ${option.event} not found`);
|
|
638
858
|
}
|
|
@@ -700,7 +920,7 @@ class ProductsBuilderService {
|
|
|
700
920
|
if (!data.tag) {
|
|
701
921
|
throw new Error('tag field is required');
|
|
702
922
|
}
|
|
703
|
-
if (!this.fetchQuota(data.tag)) {
|
|
923
|
+
if (!(await this.fetchQuota(data.tag))) {
|
|
704
924
|
await validators_1.CreateProductQuotaSchema.validateAsync(data);
|
|
705
925
|
await this.validateQuotaFallbackInputAndOutput(data, 'quota');
|
|
706
926
|
data.total_quota = 0;
|
|
@@ -725,7 +945,10 @@ class ProductsBuilderService {
|
|
|
725
945
|
if (!action) {
|
|
726
946
|
throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
|
|
727
947
|
}
|
|
728
|
-
if (action.headers.data.length > 0 ||
|
|
948
|
+
if (action.headers.data.length > 0 ||
|
|
949
|
+
action.body.data.length > 0 ||
|
|
950
|
+
action.params.data.length > 0 ||
|
|
951
|
+
action.query.data.length > 0) {
|
|
729
952
|
throw new Error('Healthcheck action is expected to have no headers, body, params or query');
|
|
730
953
|
}
|
|
731
954
|
}
|
|
@@ -743,7 +966,7 @@ class ProductsBuilderService {
|
|
|
743
966
|
}
|
|
744
967
|
async updateQuota(tag, data) {
|
|
745
968
|
try {
|
|
746
|
-
const quota = this.fetchQuota(tag);
|
|
969
|
+
const quota = await this.fetchQuota(tag);
|
|
747
970
|
if (quota) {
|
|
748
971
|
await validators_1.UpdateProductQuotaSchema.validateAsync(data);
|
|
749
972
|
if (data.options) {
|
|
@@ -771,7 +994,10 @@ class ProductsBuilderService {
|
|
|
771
994
|
if (!action) {
|
|
772
995
|
throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
|
|
773
996
|
}
|
|
774
|
-
if (action.headers.data.length > 0 ||
|
|
997
|
+
if (action.headers.data.length > 0 ||
|
|
998
|
+
action.body.data.length > 0 ||
|
|
999
|
+
action.params.data.length > 0 ||
|
|
1000
|
+
action.query.data.length > 0) {
|
|
775
1001
|
throw new Error('Healthcheck action is expected to have no headers, body, params or query');
|
|
776
1002
|
}
|
|
777
1003
|
}
|
|
@@ -791,18 +1017,36 @@ class ProductsBuilderService {
|
|
|
791
1017
|
throw e;
|
|
792
1018
|
}
|
|
793
1019
|
}
|
|
794
|
-
|
|
795
|
-
|
|
1020
|
+
async fetchQuotas(version) {
|
|
1021
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'quota', this.getUserAccess());
|
|
1022
|
+
return components;
|
|
1023
|
+
}
|
|
1024
|
+
async fetchQuota(tag, version) {
|
|
1025
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'quota', tag, this.getUserAccess());
|
|
1026
|
+
return component;
|
|
796
1027
|
}
|
|
797
|
-
|
|
798
|
-
|
|
1028
|
+
async deleteQuota(tag) {
|
|
1029
|
+
try {
|
|
1030
|
+
const quota = await this.fetchQuota(tag);
|
|
1031
|
+
if (!quota) {
|
|
1032
|
+
throw new Error(`Quota with tag: ${tag} not found`);
|
|
1033
|
+
}
|
|
1034
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1035
|
+
tag,
|
|
1036
|
+
component: enums_1.ProductComponents.QUOTA,
|
|
1037
|
+
action: enums_1.RequestAction.DELETE,
|
|
1038
|
+
}, this.getUserAccess());
|
|
1039
|
+
}
|
|
1040
|
+
catch (e) {
|
|
1041
|
+
throw e;
|
|
1042
|
+
}
|
|
799
1043
|
}
|
|
800
1044
|
async createFallback(data) {
|
|
801
1045
|
try {
|
|
802
1046
|
if (!data.tag) {
|
|
803
1047
|
throw new Error('tag field is required');
|
|
804
1048
|
}
|
|
805
|
-
if (!this.fetchFallback(data.tag)) {
|
|
1049
|
+
if (!(await this.fetchFallback(data.tag))) {
|
|
806
1050
|
await validators_1.CreateProductFallbackSchema.validateAsync(data);
|
|
807
1051
|
await this.validateQuotaFallbackInputAndOutput(data, 'fallback');
|
|
808
1052
|
await Promise.all(data.options.map(async (d) => {
|
|
@@ -824,7 +1068,10 @@ class ProductsBuilderService {
|
|
|
824
1068
|
if (!action) {
|
|
825
1069
|
throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
|
|
826
1070
|
}
|
|
827
|
-
if (action.headers.data.length > 0 ||
|
|
1071
|
+
if (action.headers.data.length > 0 ||
|
|
1072
|
+
action.body.data.length > 0 ||
|
|
1073
|
+
action.params.data.length > 0 ||
|
|
1074
|
+
action.query.data.length > 0) {
|
|
828
1075
|
throw new Error('Healthcheck action is expected to have no headers, body, params or query');
|
|
829
1076
|
}
|
|
830
1077
|
}
|
|
@@ -842,7 +1089,7 @@ class ProductsBuilderService {
|
|
|
842
1089
|
}
|
|
843
1090
|
async updateFallback(tag, data) {
|
|
844
1091
|
try {
|
|
845
|
-
const fallback = this.fetchFallback(tag);
|
|
1092
|
+
const fallback = await this.fetchFallback(tag);
|
|
846
1093
|
if (fallback) {
|
|
847
1094
|
await validators_1.UpdateProductFallbackSchema.validateAsync(data);
|
|
848
1095
|
if (data.options) {
|
|
@@ -867,7 +1114,10 @@ class ProductsBuilderService {
|
|
|
867
1114
|
if (!action) {
|
|
868
1115
|
throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
|
|
869
1116
|
}
|
|
870
|
-
if (action.headers.data.length > 0 ||
|
|
1117
|
+
if (action.headers.data.length > 0 ||
|
|
1118
|
+
action.body.data.length > 0 ||
|
|
1119
|
+
action.params.data.length > 0 ||
|
|
1120
|
+
action.query.data.length > 0) {
|
|
871
1121
|
throw new Error('Healthcheck action is expected to have no headers, body, params or query');
|
|
872
1122
|
}
|
|
873
1123
|
}
|
|
@@ -887,19 +1137,36 @@ class ProductsBuilderService {
|
|
|
887
1137
|
throw e;
|
|
888
1138
|
}
|
|
889
1139
|
}
|
|
890
|
-
|
|
891
|
-
|
|
1140
|
+
async fetchFallbacks(version) {
|
|
1141
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'fallback', this.getUserAccess());
|
|
1142
|
+
return components;
|
|
892
1143
|
}
|
|
893
|
-
|
|
894
|
-
|
|
1144
|
+
async fetchFallback(tag, version) {
|
|
1145
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'fallback', tag, this.getUserAccess());
|
|
1146
|
+
return component;
|
|
1147
|
+
}
|
|
1148
|
+
async deleteFallback(tag) {
|
|
1149
|
+
try {
|
|
1150
|
+
const fallback = await this.fetchFallback(tag);
|
|
1151
|
+
if (!fallback) {
|
|
1152
|
+
throw new Error(`Fallback with tag: ${tag} not found`);
|
|
1153
|
+
}
|
|
1154
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1155
|
+
tag,
|
|
1156
|
+
component: enums_1.ProductComponents.FALLBACK,
|
|
1157
|
+
action: enums_1.RequestAction.DELETE,
|
|
1158
|
+
}, this.getUserAccess());
|
|
1159
|
+
}
|
|
1160
|
+
catch (e) {
|
|
1161
|
+
throw e;
|
|
1162
|
+
}
|
|
895
1163
|
}
|
|
896
1164
|
async createEnv(data, throwErrorIfExists = false) {
|
|
897
1165
|
try {
|
|
898
1166
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
899
|
-
if (!this.fetchEnv(data.slug)) {
|
|
1167
|
+
if (!(await this.fetchEnv(data.slug))) {
|
|
900
1168
|
await validators_1.CreateProductEnvSchema.validateAsync(data);
|
|
901
1169
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.ENV, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
902
|
-
await this.initializeProduct(this.product_id);
|
|
903
1170
|
}
|
|
904
1171
|
else {
|
|
905
1172
|
if (throwErrorIfExists)
|
|
@@ -912,137 +1179,238 @@ class ProductsBuilderService {
|
|
|
912
1179
|
}
|
|
913
1180
|
async updateEnv(slug, data) {
|
|
914
1181
|
try {
|
|
915
|
-
const env = this.fetchEnv(slug
|
|
1182
|
+
const env = await this.fetchEnv(slug);
|
|
916
1183
|
if (!env) {
|
|
917
1184
|
throw new Error(`Env ${slug} not found`);
|
|
918
1185
|
}
|
|
919
1186
|
const { _id } = env;
|
|
920
1187
|
await validators_1.UpdateProductEnvSchema.validateAsync(data); // Change to update;
|
|
921
|
-
if (data.slug && this.fetchEnv(data.slug)) {
|
|
1188
|
+
if (data.slug && (await this.fetchEnv(data.slug))) {
|
|
922
1189
|
throw new Error(`slug ${slug} is in use`); // TODO: also check on the backend
|
|
923
1190
|
}
|
|
924
1191
|
if (!data.slug) {
|
|
925
1192
|
data.slug = slug;
|
|
926
1193
|
}
|
|
927
1194
|
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());
|
|
928
|
-
await this.initializeProduct(this.product_id);
|
|
929
1195
|
}
|
|
930
1196
|
catch (e) {
|
|
931
1197
|
throw e;
|
|
932
1198
|
}
|
|
933
1199
|
}
|
|
934
|
-
fetchEnvs() {
|
|
935
|
-
|
|
1200
|
+
async fetchEnvs(version) {
|
|
1201
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'env', this.getUserAccess());
|
|
1202
|
+
return components;
|
|
1203
|
+
}
|
|
1204
|
+
async fetchEnv(slug) {
|
|
1205
|
+
console.log;
|
|
1206
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'env', slug, this.getUserAccess());
|
|
1207
|
+
return component;
|
|
936
1208
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1209
|
+
async deleteEnv(slug) {
|
|
1210
|
+
try {
|
|
1211
|
+
const env = await this.fetchEnv(slug);
|
|
1212
|
+
if (!env) {
|
|
1213
|
+
throw new Error(`Environment with slug: ${slug} not found`);
|
|
1214
|
+
}
|
|
1215
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1216
|
+
slug,
|
|
1217
|
+
component: enums_1.ProductComponents.ENV,
|
|
1218
|
+
action: enums_1.RequestAction.DELETE,
|
|
1219
|
+
}, this.getUserAccess());
|
|
1220
|
+
}
|
|
1221
|
+
catch (e) {
|
|
1222
|
+
throw e;
|
|
1223
|
+
}
|
|
942
1224
|
}
|
|
943
1225
|
async createMessageBroker(data, throwErrorIfExists = false) {
|
|
944
|
-
|
|
1226
|
+
var _a;
|
|
1227
|
+
const logPrefix = '[MessageBroker:Create]';
|
|
1228
|
+
console.log(`${logPrefix} Starting creation for broker: ${data.tag}`);
|
|
1229
|
+
console.log(`${logPrefix} Broker name: ${data.name}`);
|
|
1230
|
+
console.log(`${logPrefix} Broker description: ${data.description || 'N/A'}`);
|
|
1231
|
+
console.log(`${logPrefix} Number of environments: ${((_a = data.envs) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
|
|
1232
|
+
const existingBroker = await this.fetchMessageBroker(data.tag);
|
|
1233
|
+
if (!existingBroker) {
|
|
1234
|
+
console.log(`${logPrefix} Broker ${data.tag} does not exist, proceeding with creation`);
|
|
1235
|
+
console.log(`${logPrefix} Validating schema...`);
|
|
945
1236
|
await validators_1.CreateMessageBrokerSchema.validateAsync(data);
|
|
946
|
-
|
|
947
|
-
|
|
1237
|
+
console.log(`${logPrefix} Schema validation passed`);
|
|
1238
|
+
const processedEnvs = [];
|
|
1239
|
+
for (const env of data.envs) {
|
|
1240
|
+
console.log(`${logPrefix} Processing env: ${env.slug} (type: ${env.type})`);
|
|
1241
|
+
const exists = await this.fetchEnv(env.slug);
|
|
948
1242
|
if (!exists) {
|
|
1243
|
+
console.error(`${logPrefix} Env ${env.slug} does not exist`);
|
|
949
1244
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
950
1245
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
1246
|
+
console.log(`${logPrefix} Env ${env.slug} exists, verified`);
|
|
1247
|
+
// Store sensitive credentials as secrets
|
|
1248
|
+
console.log(`${logPrefix} Processing secrets for env: ${env.slug}...`);
|
|
1249
|
+
env.config = await this.processMessageBrokerConfigSecrets(env.config, env.type, data.tag, env.slug);
|
|
1250
|
+
console.log(`${logPrefix} Secrets processed for env: ${env.slug}`);
|
|
1251
|
+
console.log(`${logPrefix} Encrypting config for env: ${env.slug}...`);
|
|
1252
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1253
|
+
console.log(`${logPrefix} Config encrypted for env: ${env.slug}`);
|
|
1254
|
+
processedEnvs.push(env);
|
|
1255
|
+
}
|
|
1256
|
+
data.envs = processedEnvs;
|
|
1257
|
+
console.log(`${logPrefix} All environments processed: ${processedEnvs.length}`);
|
|
1258
|
+
const envs = await this.fetchEnvs();
|
|
1259
|
+
console.log(`${logPrefix} Product has ${envs.length} environments defined`);
|
|
1260
|
+
for (const env of envs) {
|
|
956
1261
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
957
1262
|
if (exists === -1) {
|
|
1263
|
+
console.error(`${logPrefix} Product env ${env.slug} is not defined in broker config`);
|
|
958
1264
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
959
1265
|
}
|
|
960
|
-
}
|
|
1266
|
+
}
|
|
1267
|
+
console.log(`${logPrefix} All product environments have broker configs`);
|
|
1268
|
+
console.log(`${logPrefix} Sending create request to API...`);
|
|
961
1269
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.MESSAGEBROKER, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
962
|
-
|
|
1270
|
+
console.log(`${logPrefix} Message broker ${data.tag} created successfully`);
|
|
963
1271
|
}
|
|
964
1272
|
else {
|
|
1273
|
+
console.log(`${logPrefix} Broker ${data.tag} already exists`);
|
|
965
1274
|
if (throwErrorIfExists)
|
|
966
1275
|
throw new Error(`Message Broker ${data.tag} already exists`);
|
|
967
1276
|
}
|
|
968
1277
|
}
|
|
969
1278
|
async updateMessageBroker(tag, data) {
|
|
1279
|
+
var _a, _b;
|
|
1280
|
+
const logPrefix = '[MessageBroker:Update]';
|
|
1281
|
+
console.log(`${logPrefix} Starting update for broker: ${tag}`);
|
|
1282
|
+
console.log(`${logPrefix} New tag (if changed): ${data.tag || 'unchanged'}`);
|
|
1283
|
+
console.log(`${logPrefix} New name: ${data.name || 'unchanged'}`);
|
|
1284
|
+
console.log(`${logPrefix} Number of environments in update: ${((_a = data.envs) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
|
|
970
1285
|
try {
|
|
971
|
-
|
|
1286
|
+
console.log(`${logPrefix} Fetching existing broker: ${tag}`);
|
|
1287
|
+
const messageBroker = await this.fetchMessageBroker(tag);
|
|
972
1288
|
if (!messageBroker) {
|
|
1289
|
+
console.error(`${logPrefix} Broker ${tag} not found`);
|
|
973
1290
|
throw new Error(`Broker ${tag} not found`);
|
|
974
1291
|
}
|
|
1292
|
+
console.log(`${logPrefix} Existing broker found with ${((_b = messageBroker.envs) === null || _b === void 0 ? void 0 : _b.length) || 0} environments`);
|
|
975
1293
|
const { _id, envs } = messageBroker;
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1294
|
+
console.log(`${logPrefix} Broker ID: ${_id}`);
|
|
1295
|
+
console.log(`${logPrefix} Validating update schema...`);
|
|
1296
|
+
await validators_1.UpdateMessageBrokerSchema.validateAsync(data);
|
|
1297
|
+
console.log(`${logPrefix} Schema validation passed`);
|
|
1298
|
+
if (data.tag && (await this.fetchMessageBroker(data.tag))) {
|
|
1299
|
+
console.error(`${logPrefix} Tag ${data.tag} is already in use`);
|
|
1300
|
+
throw new Error(`tag ${tag} is in use`);
|
|
1301
|
+
}
|
|
1302
|
+
const processedEnvs = [];
|
|
1303
|
+
for (const env of data.envs) {
|
|
1304
|
+
console.log(`${logPrefix} Processing env: ${env.slug} (type: ${env.type})`);
|
|
1305
|
+
const exists = await this.fetchEnv(env.slug);
|
|
983
1306
|
if (!exists) {
|
|
1307
|
+
console.error(`${logPrefix} Env ${env.slug} does not exist`);
|
|
984
1308
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
985
1309
|
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1310
|
+
console.log(`${logPrefix} Env ${env.slug} exists, verified`);
|
|
1311
|
+
if (env.config) {
|
|
1312
|
+
// Store sensitive credentials as secrets
|
|
1313
|
+
console.log(`${logPrefix} Processing secrets for env: ${env.slug}...`);
|
|
1314
|
+
env.config = await this.processMessageBrokerConfigSecrets(env.config, env.type, data.tag || tag, env.slug);
|
|
1315
|
+
console.log(`${logPrefix} Secrets processed for env: ${env.slug}`);
|
|
1316
|
+
console.log(`${logPrefix} Encrypting config for env: ${env.slug}...`);
|
|
1317
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1318
|
+
console.log(`${logPrefix} Config encrypted for env: ${env.slug}`);
|
|
1319
|
+
}
|
|
1320
|
+
else {
|
|
1321
|
+
console.log(`${logPrefix} No config provided for env: ${env.slug}, skipping secrets processing`);
|
|
1322
|
+
}
|
|
1323
|
+
processedEnvs.push(env);
|
|
1324
|
+
}
|
|
1325
|
+
data.envs = processedEnvs;
|
|
1326
|
+
console.log(`${logPrefix} All environments processed: ${processedEnvs.length}`);
|
|
990
1327
|
const overwrite = [];
|
|
991
1328
|
const newEnvs = [];
|
|
992
|
-
data.envs
|
|
1329
|
+
for (const dataEnv of data.envs) {
|
|
993
1330
|
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
994
|
-
if (!this.fetchEnv(dataEnv.slug)) {
|
|
1331
|
+
if (!(await this.fetchEnv(dataEnv.slug))) {
|
|
1332
|
+
console.error(`${logPrefix} Product Environment ${dataEnv.slug} doesn't exist`);
|
|
995
1333
|
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
996
1334
|
}
|
|
997
1335
|
if (exists === -1) {
|
|
1336
|
+
console.log(`${logPrefix} Env ${dataEnv.slug} is a NEW environment`);
|
|
998
1337
|
if (!dataEnv.config) {
|
|
1338
|
+
console.error(`${logPrefix} Config is required for new env ${dataEnv.slug}`);
|
|
999
1339
|
throw new Error(`config is required for new env ${data.envs[exists].slug}`);
|
|
1000
1340
|
}
|
|
1001
1341
|
newEnvs.push(dataEnv);
|
|
1002
1342
|
}
|
|
1003
1343
|
else {
|
|
1344
|
+
console.log(`${logPrefix} Env ${dataEnv.slug} will OVERWRITE existing config`);
|
|
1004
1345
|
if (envs[exists].config) {
|
|
1005
|
-
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.
|
|
1346
|
+
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.product.private_key);
|
|
1006
1347
|
}
|
|
1007
1348
|
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1008
1349
|
}
|
|
1009
|
-
}
|
|
1350
|
+
}
|
|
1010
1351
|
const unchanged = [];
|
|
1011
|
-
|
|
1352
|
+
for (const env of envs) {
|
|
1012
1353
|
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1013
1354
|
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1014
1355
|
if (!newEnv && !overwriteEnv) {
|
|
1356
|
+
console.log(`${logPrefix} Env ${env.slug} is UNCHANGED`);
|
|
1015
1357
|
if (env.config) {
|
|
1016
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.
|
|
1358
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1017
1359
|
}
|
|
1018
1360
|
unchanged.push(env);
|
|
1019
1361
|
}
|
|
1020
|
-
}
|
|
1362
|
+
}
|
|
1021
1363
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1364
|
+
console.log(`${logPrefix} Final env breakdown - Unchanged: ${unchanged.length}, Overwrite: ${overwrite.length}, New: ${newEnvs.length}`);
|
|
1365
|
+
console.log(`${logPrefix} Sending update request to API...`);
|
|
1022
1366
|
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());
|
|
1023
|
-
|
|
1367
|
+
console.log(`${logPrefix} Message broker ${tag} updated successfully`);
|
|
1024
1368
|
}
|
|
1025
1369
|
catch (e) {
|
|
1370
|
+
console.error(`${logPrefix} Update failed:`, e);
|
|
1026
1371
|
throw e;
|
|
1027
1372
|
}
|
|
1028
1373
|
}
|
|
1029
|
-
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1374
|
+
async fetchMessageBrokers(version) {
|
|
1375
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'message_broker', this.getUserAccess());
|
|
1376
|
+
return components;
|
|
1377
|
+
}
|
|
1378
|
+
async fetchMessageBroker(tag, version) {
|
|
1379
|
+
var _a, _b;
|
|
1380
|
+
console.log(`[ProductsBuilderService] fetchMessageBroker() called with tag: ${tag}`);
|
|
1381
|
+
console.log(`[ProductsBuilderService] product_id: ${this.product_id}`);
|
|
1382
|
+
console.log(`[ProductsBuilderService] has product: ${!!this.product}`);
|
|
1383
|
+
console.log(`[ProductsBuilderService] product.messageBrokers count: ${((_b = (_a = this.product) === null || _a === void 0 ? void 0 : _a.messageBrokers) === null || _b === void 0 ? void 0 : _b.length) || 0}`);
|
|
1384
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'message_broker', tag, this.getUserAccess());
|
|
1385
|
+
console.log(`[ProductsBuilderService] fetchProductComponentByTag result:`, component ? `found (tag=${component.tag})` : 'null');
|
|
1386
|
+
if (component) {
|
|
1387
|
+
// Ensure envs array exists before mapping
|
|
1388
|
+
const envs = component.envs || [];
|
|
1389
|
+
console.log(`[ProductsBuilderService] component.envs count: ${envs.length}`);
|
|
1390
|
+
const decryptedEnvs = envs.map((env) => {
|
|
1391
|
+
return Object.assign(Object.assign({}, env), { config: env.config ? JSON.parse((0, processor_utils_1.decrypt)(env.config, this.product.private_key)) : {} });
|
|
1038
1392
|
});
|
|
1393
|
+
console.log(`[ProductsBuilderService] Decrypted ${decryptedEnvs.length} environments`);
|
|
1394
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
1039
1395
|
}
|
|
1040
|
-
|
|
1396
|
+
console.log(`[ProductsBuilderService] Returning null - component not found`);
|
|
1397
|
+
return component;
|
|
1041
1398
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1399
|
+
async deleteMessageBroker(tag) {
|
|
1400
|
+
try {
|
|
1401
|
+
const messageBroker = await this.fetchMessageBroker(tag);
|
|
1402
|
+
if (!messageBroker) {
|
|
1403
|
+
throw new Error(`Message broker with tag: ${tag} not found`);
|
|
1404
|
+
}
|
|
1405
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1406
|
+
tag,
|
|
1407
|
+
component: enums_1.ProductComponents.MESSAGEBROKER,
|
|
1408
|
+
action: enums_1.RequestAction.DELETE,
|
|
1409
|
+
}, this.getUserAccess());
|
|
1410
|
+
}
|
|
1411
|
+
catch (e) {
|
|
1412
|
+
throw e;
|
|
1413
|
+
}
|
|
1046
1414
|
}
|
|
1047
1415
|
async fetchStorageFiles(filter) {
|
|
1048
1416
|
try {
|
|
@@ -1058,7 +1426,7 @@ class ProductsBuilderService {
|
|
|
1058
1426
|
});
|
|
1059
1427
|
}
|
|
1060
1428
|
catch (e) {
|
|
1061
|
-
throw
|
|
1429
|
+
throw e;
|
|
1062
1430
|
}
|
|
1063
1431
|
}
|
|
1064
1432
|
async fetchSessionUsers(filter) {
|
|
@@ -1074,14 +1442,15 @@ class ProductsBuilderService {
|
|
|
1074
1442
|
});
|
|
1075
1443
|
}
|
|
1076
1444
|
catch (e) {
|
|
1077
|
-
throw
|
|
1445
|
+
throw e;
|
|
1078
1446
|
}
|
|
1079
1447
|
}
|
|
1080
1448
|
async createStorage(data, throwErrorIfExists = false) {
|
|
1081
|
-
if (!this.fetchStorage(data.tag
|
|
1449
|
+
if (!(await this.fetchStorage(data.tag))) {
|
|
1082
1450
|
await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
|
|
1083
|
-
|
|
1084
|
-
|
|
1451
|
+
const processedEnvs = [];
|
|
1452
|
+
for (const env of data.envs) {
|
|
1453
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1085
1454
|
if (!exists) {
|
|
1086
1455
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
1087
1456
|
}
|
|
@@ -1089,18 +1458,20 @@ class ProductsBuilderService {
|
|
|
1089
1458
|
// @ts-ignore
|
|
1090
1459
|
//env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
|
|
1091
1460
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1461
|
+
// Store sensitive credentials as secrets
|
|
1462
|
+
env.config = await this.processStorageConfigSecrets(env.config, env.type, data.tag, env.slug);
|
|
1463
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1464
|
+
processedEnvs.push(env);
|
|
1465
|
+
}
|
|
1466
|
+
data.envs = processedEnvs;
|
|
1467
|
+
const envs = await this.fetchEnvs();
|
|
1468
|
+
for (const env of envs) {
|
|
1097
1469
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
1098
1470
|
if (exists === -1) {
|
|
1099
1471
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
1100
1472
|
}
|
|
1101
|
-
}
|
|
1473
|
+
}
|
|
1102
1474
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1103
|
-
await this.initializeProduct(this.product_id);
|
|
1104
1475
|
}
|
|
1105
1476
|
else {
|
|
1106
1477
|
if (throwErrorIfExists)
|
|
@@ -1109,84 +1480,747 @@ class ProductsBuilderService {
|
|
|
1109
1480
|
}
|
|
1110
1481
|
async updateStorage(tag, data) {
|
|
1111
1482
|
try {
|
|
1112
|
-
const storage = this.fetchStorage(tag);
|
|
1483
|
+
const storage = await this.fetchStorage(tag);
|
|
1113
1484
|
if (!storage) {
|
|
1114
1485
|
throw new Error(`Storage ${tag} not found`);
|
|
1115
1486
|
}
|
|
1116
1487
|
const { _id, envs } = storage;
|
|
1117
1488
|
await create_productStorage_validator_1.UpdateProductStorageSchema.validateAsync(data); // Change to update;
|
|
1118
|
-
if (data.tag && this.fetchStorage(data.tag)) {
|
|
1489
|
+
if (data.tag && await this.fetchStorage(data.tag)) {
|
|
1119
1490
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1120
1491
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
// @ts-ignore
|
|
1128
|
-
//env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
|
|
1129
|
-
}
|
|
1130
|
-
if (env.config)
|
|
1131
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
|
|
1132
|
-
return env;
|
|
1133
|
-
});
|
|
1134
|
-
const overwrite = [];
|
|
1135
|
-
const newEnvs = [];
|
|
1136
|
-
data.envs.map((dataEnv) => {
|
|
1137
|
-
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1138
|
-
if (!this.fetchEnv(dataEnv.slug)) {
|
|
1139
|
-
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
1140
|
-
}
|
|
1141
|
-
if (exists === -1) {
|
|
1142
|
-
if (!dataEnv.config) {
|
|
1143
|
-
throw new Error(`config is required for new env ${data.envs[exists].slug}`);
|
|
1492
|
+
// Only process envs if they are provided in the update
|
|
1493
|
+
if (data.envs && data.envs.length > 0) {
|
|
1494
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
1495
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1496
|
+
if (!exists) {
|
|
1497
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
1144
1498
|
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
if (envs[exists].config) {
|
|
1149
|
-
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.fetchProduct().private_key);
|
|
1499
|
+
if (env.type === productsBuilder_types_1.StorageProviders.GCP) {
|
|
1500
|
+
// @ts-ignore
|
|
1501
|
+
//env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
|
|
1150
1502
|
}
|
|
1151
|
-
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1152
|
-
}
|
|
1153
|
-
});
|
|
1154
|
-
const unchanged = [];
|
|
1155
|
-
envs.map((env) => {
|
|
1156
|
-
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1157
|
-
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1158
|
-
if (!newEnv && !overwriteEnv) {
|
|
1159
1503
|
if (env.config) {
|
|
1160
|
-
|
|
1504
|
+
// Store sensitive credentials as secrets
|
|
1505
|
+
env.config = await this.processStorageConfigSecrets(env.config, env.type, data.tag || tag, env.slug);
|
|
1506
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1161
1507
|
}
|
|
1162
|
-
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1508
|
+
return env;
|
|
1509
|
+
}));
|
|
1510
|
+
const overwrite = [];
|
|
1511
|
+
const newEnvs = [];
|
|
1512
|
+
data.envs.map((dataEnv) => {
|
|
1513
|
+
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1514
|
+
if (!this.fetchEnv(dataEnv.slug)) {
|
|
1515
|
+
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
1516
|
+
}
|
|
1517
|
+
if (exists === -1) {
|
|
1518
|
+
if (!dataEnv.config) {
|
|
1519
|
+
throw new Error(`config is required for new env ${data.envs[exists].slug}`);
|
|
1520
|
+
}
|
|
1521
|
+
newEnvs.push(dataEnv);
|
|
1522
|
+
}
|
|
1523
|
+
else {
|
|
1524
|
+
if (envs[exists].config) {
|
|
1525
|
+
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.product.private_key);
|
|
1526
|
+
}
|
|
1527
|
+
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
const unchanged = [];
|
|
1531
|
+
envs.map((env) => {
|
|
1532
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1533
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1534
|
+
if (!newEnv && !overwriteEnv) {
|
|
1535
|
+
if (env.config) {
|
|
1536
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1537
|
+
}
|
|
1538
|
+
unchanged.push(env);
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1542
|
+
}
|
|
1543
|
+
// Build the update payload - only send fields that are being updated
|
|
1544
|
+
// Remove fields that shouldn't be in the update request
|
|
1545
|
+
const { envs: dataEnvs } = data, dataWithoutEnvs = __rest(data, ["envs"]);
|
|
1546
|
+
// Only include envs if they were explicitly provided and processed
|
|
1547
|
+
// Don't spread ...storage - only send the fields being updated
|
|
1548
|
+
const updatePayload = Object.assign(Object.assign(Object.assign({ _id }, storage), { tag }), dataWithoutEnvs);
|
|
1549
|
+
// Add processed envs only if they were provided in the update
|
|
1550
|
+
if (data.envs && data.envs.length > 0) {
|
|
1551
|
+
updatePayload.envs = data.envs;
|
|
1552
|
+
}
|
|
1553
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, updatePayload), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1168
1554
|
}
|
|
1169
1555
|
catch (e) {
|
|
1170
1556
|
throw e;
|
|
1171
1557
|
}
|
|
1172
1558
|
}
|
|
1173
|
-
|
|
1174
|
-
const
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
}
|
|
1559
|
+
async fetchStorages(version) {
|
|
1560
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'storage', this.getUserAccess());
|
|
1561
|
+
return components;
|
|
1562
|
+
}
|
|
1563
|
+
async fetchStorage(tag, version) {
|
|
1564
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'storage', tag, this.getUserAccess());
|
|
1565
|
+
if (component) {
|
|
1566
|
+
const decryptedEnvs = component.envs.map((env) => {
|
|
1567
|
+
return Object.assign(Object.assign({}, env), { config: JSON.parse((0, processor_utils_1.decrypt)(env.config, this.product.private_key)) });
|
|
1182
1568
|
});
|
|
1569
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
1570
|
+
}
|
|
1571
|
+
return component;
|
|
1572
|
+
}
|
|
1573
|
+
async deleteStorage(tag) {
|
|
1574
|
+
try {
|
|
1575
|
+
const storage = await this.fetchStorage(tag);
|
|
1576
|
+
if (!storage) {
|
|
1577
|
+
throw new Error(`Storage with tag: ${tag} not found`);
|
|
1578
|
+
}
|
|
1579
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1580
|
+
tag,
|
|
1581
|
+
component: enums_1.ProductComponents.STORAGE,
|
|
1582
|
+
action: enums_1.RequestAction.DELETE,
|
|
1583
|
+
}, this.getUserAccess());
|
|
1584
|
+
}
|
|
1585
|
+
catch (e) {
|
|
1586
|
+
throw e;
|
|
1183
1587
|
}
|
|
1184
|
-
return storage;
|
|
1185
1588
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1589
|
+
// ==================== VECTOR DATABASE METHODS ====================
|
|
1590
|
+
/**
|
|
1591
|
+
* Create a new vector database configuration
|
|
1592
|
+
* @param data Vector database configuration
|
|
1593
|
+
* @param throwErrorIfExists Whether to throw error if vector config already exists
|
|
1594
|
+
*/
|
|
1595
|
+
async createVector(data, throwErrorIfExists = false) {
|
|
1596
|
+
var _a, _b, _c, _d;
|
|
1597
|
+
console.log('[ProductsService.createVector] Starting vector creation:', {
|
|
1598
|
+
tag: data.tag,
|
|
1599
|
+
name: data.name,
|
|
1600
|
+
type: data.type,
|
|
1601
|
+
envsCount: (_a = data.envs) === null || _a === void 0 ? void 0 : _a.length,
|
|
1602
|
+
productTag: (_b = this.product) === null || _b === void 0 ? void 0 : _b.tag,
|
|
1189
1603
|
});
|
|
1604
|
+
if (!(await this.fetchVector(data.tag))) {
|
|
1605
|
+
await validators_1.CreateProductVectorSchema.validateAsync(data);
|
|
1606
|
+
const processedEnvs = [];
|
|
1607
|
+
for (const env of data.envs) {
|
|
1608
|
+
console.log('[ProductsService.createVector] Processing env:', {
|
|
1609
|
+
slug: env.slug,
|
|
1610
|
+
hasApiKey: !!env.apiKey,
|
|
1611
|
+
hasEndpoint: !!env.endpoint,
|
|
1612
|
+
});
|
|
1613
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1614
|
+
if (!exists) {
|
|
1615
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
1616
|
+
}
|
|
1617
|
+
// Store API key as secret and encrypt
|
|
1618
|
+
if (env.apiKey) {
|
|
1619
|
+
console.log('[ProductsService.createVector] Converting API key to secret for env:', env.slug);
|
|
1620
|
+
const originalApiKey = env.apiKey;
|
|
1621
|
+
env.apiKey = await this.storeVectorApiKeyAsSecret(env.apiKey, data.tag, env.slug);
|
|
1622
|
+
console.log('[ProductsService.createVector] API key after secret conversion:', {
|
|
1623
|
+
wasConverted: originalApiKey !== env.apiKey,
|
|
1624
|
+
isSecretRef: (_c = env.apiKey) === null || _c === void 0 ? void 0 : _c.startsWith('$Secret{'),
|
|
1625
|
+
});
|
|
1626
|
+
env.apiKey = (0, processor_utils_1.encrypt)(env.apiKey, this.product.private_key);
|
|
1627
|
+
console.log('[ProductsService.createVector] API key encrypted');
|
|
1628
|
+
}
|
|
1629
|
+
// Store endpoint as secret and encrypt
|
|
1630
|
+
if (env.endpoint) {
|
|
1631
|
+
console.log('[ProductsService.createVector] Converting endpoint to secret for env:', env.slug);
|
|
1632
|
+
const originalEndpoint = env.endpoint;
|
|
1633
|
+
env.endpoint = await this.storeVectorEndpointAsSecret(env.endpoint, data.tag, env.slug);
|
|
1634
|
+
console.log('[ProductsService.createVector] Endpoint after secret conversion:', {
|
|
1635
|
+
wasConverted: originalEndpoint !== env.endpoint,
|
|
1636
|
+
isSecretRef: (_d = env.endpoint) === null || _d === void 0 ? void 0 : _d.startsWith('$Secret{'),
|
|
1637
|
+
});
|
|
1638
|
+
env.endpoint = (0, processor_utils_1.encrypt)(env.endpoint, this.product.private_key);
|
|
1639
|
+
console.log('[ProductsService.createVector] Endpoint encrypted');
|
|
1640
|
+
}
|
|
1641
|
+
processedEnvs.push(env);
|
|
1642
|
+
console.log('[ProductsService.createVector] Env processed successfully:', env.slug);
|
|
1643
|
+
}
|
|
1644
|
+
data.envs = processedEnvs;
|
|
1645
|
+
console.log('[ProductsService.createVector] All envs processed, total:', processedEnvs.length);
|
|
1646
|
+
const envs = await this.fetchEnvs();
|
|
1647
|
+
for (const env of envs) {
|
|
1648
|
+
const exists = data.envs.findIndex((vecEnv) => vecEnv.slug === env.slug);
|
|
1649
|
+
if (exists === -1) {
|
|
1650
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.VECTOR, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1654
|
+
}
|
|
1655
|
+
else {
|
|
1656
|
+
if (throwErrorIfExists)
|
|
1657
|
+
throw new Error(`Vector ${data.tag} already exists`);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Update an existing vector database configuration
|
|
1662
|
+
* @param tag Vector config tag
|
|
1663
|
+
* @param data Updated vector configuration
|
|
1664
|
+
*/
|
|
1665
|
+
async updateVector(tag, data) {
|
|
1666
|
+
var _a, _b;
|
|
1667
|
+
console.log('[ProductsService.updateVector] Starting vector update:', {
|
|
1668
|
+
tag,
|
|
1669
|
+
newTag: data.tag,
|
|
1670
|
+
name: data.name,
|
|
1671
|
+
envsCount: (_a = data.envs) === null || _a === void 0 ? void 0 : _a.length,
|
|
1672
|
+
productTag: (_b = this.product) === null || _b === void 0 ? void 0 : _b.tag,
|
|
1673
|
+
});
|
|
1674
|
+
try {
|
|
1675
|
+
const vector = await this.fetchVector(tag);
|
|
1676
|
+
if (!vector) {
|
|
1677
|
+
throw new Error(`Vector ${tag} not found`);
|
|
1678
|
+
}
|
|
1679
|
+
const { _id, envs } = vector;
|
|
1680
|
+
console.log('[ProductsService.updateVector] Found existing vector:', {
|
|
1681
|
+
_id,
|
|
1682
|
+
existingEnvsCount: envs === null || envs === void 0 ? void 0 : envs.length,
|
|
1683
|
+
});
|
|
1684
|
+
await validators_1.UpdateProductVectorSchema.validateAsync(data);
|
|
1685
|
+
if (data.tag && (await this.fetchVector(data.tag))) {
|
|
1686
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
1687
|
+
}
|
|
1688
|
+
if (data.envs) {
|
|
1689
|
+
console.log('[ProductsService.updateVector] Processing envs update');
|
|
1690
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
1691
|
+
var _a, _b;
|
|
1692
|
+
console.log('[ProductsService.updateVector] Processing env:', {
|
|
1693
|
+
slug: env.slug,
|
|
1694
|
+
hasApiKey: !!env.apiKey,
|
|
1695
|
+
hasEndpoint: !!env.endpoint,
|
|
1696
|
+
});
|
|
1697
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1698
|
+
if (!exists) {
|
|
1699
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
1700
|
+
}
|
|
1701
|
+
// Store API key as secret and encrypt
|
|
1702
|
+
if (env.apiKey) {
|
|
1703
|
+
console.log('[ProductsService.updateVector] Converting API key to secret for env:', env.slug);
|
|
1704
|
+
const originalApiKey = env.apiKey;
|
|
1705
|
+
env.apiKey = await this.storeVectorApiKeyAsSecret(env.apiKey, data.tag || tag, env.slug);
|
|
1706
|
+
console.log('[ProductsService.updateVector] API key after secret conversion:', {
|
|
1707
|
+
wasConverted: originalApiKey !== env.apiKey,
|
|
1708
|
+
isSecretRef: (_a = env.apiKey) === null || _a === void 0 ? void 0 : _a.startsWith('$Secret{'),
|
|
1709
|
+
});
|
|
1710
|
+
env.apiKey = (0, processor_utils_1.encrypt)(env.apiKey, this.product.private_key);
|
|
1711
|
+
console.log('[ProductsService.updateVector] API key encrypted');
|
|
1712
|
+
}
|
|
1713
|
+
// Store endpoint as secret and encrypt
|
|
1714
|
+
if (env.endpoint) {
|
|
1715
|
+
console.log('[ProductsService.updateVector] Converting endpoint to secret for env:', env.slug);
|
|
1716
|
+
const originalEndpoint = env.endpoint;
|
|
1717
|
+
env.endpoint = await this.storeVectorEndpointAsSecret(env.endpoint, data.tag || tag, env.slug);
|
|
1718
|
+
console.log('[ProductsService.updateVector] Endpoint after secret conversion:', {
|
|
1719
|
+
wasConverted: originalEndpoint !== env.endpoint,
|
|
1720
|
+
isSecretRef: (_b = env.endpoint) === null || _b === void 0 ? void 0 : _b.startsWith('$Secret{'),
|
|
1721
|
+
});
|
|
1722
|
+
env.endpoint = (0, processor_utils_1.encrypt)(env.endpoint, this.product.private_key);
|
|
1723
|
+
console.log('[ProductsService.updateVector] Endpoint encrypted');
|
|
1724
|
+
}
|
|
1725
|
+
console.log('[ProductsService.updateVector] Env processed successfully:', env.slug);
|
|
1726
|
+
return env;
|
|
1727
|
+
}));
|
|
1728
|
+
const overwrite = [];
|
|
1729
|
+
const newEnvs = [];
|
|
1730
|
+
data.envs.forEach((dataEnv) => {
|
|
1731
|
+
const existsIdx = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1732
|
+
if (existsIdx === -1) {
|
|
1733
|
+
newEnvs.push(dataEnv);
|
|
1734
|
+
}
|
|
1735
|
+
else {
|
|
1736
|
+
overwrite.push(Object.assign(Object.assign({}, envs[existsIdx]), dataEnv));
|
|
1737
|
+
}
|
|
1738
|
+
});
|
|
1739
|
+
const unchanged = [];
|
|
1740
|
+
envs.forEach((env) => {
|
|
1741
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1742
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1743
|
+
if (!newEnv && !overwriteEnv) {
|
|
1744
|
+
unchanged.push(env);
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1748
|
+
}
|
|
1749
|
+
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());
|
|
1750
|
+
}
|
|
1751
|
+
catch (e) {
|
|
1752
|
+
throw e;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
/**
|
|
1756
|
+
* Fetch all vector database configurations
|
|
1757
|
+
* @param version Optional version
|
|
1758
|
+
*/
|
|
1759
|
+
async fetchVectors(version) {
|
|
1760
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'vector', this.getUserAccess());
|
|
1761
|
+
// Decrypt sensitive fields in vector envs to reveal $Secret{key} references
|
|
1762
|
+
const decryptedComponents = components.map((vectorComponent) => {
|
|
1763
|
+
var _a;
|
|
1764
|
+
const decryptedEnvs = (_a = vectorComponent.envs) === null || _a === void 0 ? void 0 : _a.map((env) => {
|
|
1765
|
+
return Object.assign(Object.assign({}, env), { apiKey: env.apiKey ? (0, processor_utils_1.decrypt)(env.apiKey, this.product.private_key) : env.apiKey, endpoint: env.endpoint ? (0, processor_utils_1.decrypt)(env.endpoint, this.product.private_key) : env.endpoint });
|
|
1766
|
+
});
|
|
1767
|
+
return Object.assign(Object.assign({}, vectorComponent), { envs: decryptedEnvs });
|
|
1768
|
+
});
|
|
1769
|
+
return decryptedComponents;
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Fetch a specific vector database configuration by tag
|
|
1773
|
+
* @param tag Vector config tag
|
|
1774
|
+
* @param version Optional version
|
|
1775
|
+
*/
|
|
1776
|
+
async fetchVector(tag, version) {
|
|
1777
|
+
var _a;
|
|
1778
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'vector', tag, this.getUserAccess());
|
|
1779
|
+
if (component) {
|
|
1780
|
+
// Decrypt sensitive fields in vector envs to reveal $Secret{key} references
|
|
1781
|
+
const decryptedEnvs = (_a = component.envs) === null || _a === void 0 ? void 0 : _a.map((env) => {
|
|
1782
|
+
return Object.assign(Object.assign({}, env), { apiKey: env.apiKey ? (0, processor_utils_1.decrypt)(env.apiKey, this.product.private_key) : env.apiKey, endpoint: env.endpoint ? (0, processor_utils_1.decrypt)(env.endpoint, this.product.private_key) : env.endpoint });
|
|
1783
|
+
});
|
|
1784
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
1785
|
+
}
|
|
1786
|
+
return component;
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* Delete a vector database configuration
|
|
1790
|
+
* @param tag Vector config tag
|
|
1791
|
+
*/
|
|
1792
|
+
async deleteVector(tag) {
|
|
1793
|
+
try {
|
|
1794
|
+
const vector = await this.fetchVector(tag);
|
|
1795
|
+
if (!vector) {
|
|
1796
|
+
throw new Error(`Vector with tag: ${tag} not found`);
|
|
1797
|
+
}
|
|
1798
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1799
|
+
tag,
|
|
1800
|
+
component: enums_1.ProductComponents.VECTOR,
|
|
1801
|
+
action: enums_1.RequestAction.DELETE,
|
|
1802
|
+
}, this.getUserAccess());
|
|
1803
|
+
}
|
|
1804
|
+
catch (e) {
|
|
1805
|
+
throw e;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
// ==================== VECTOR ACTION METHODS ====================
|
|
1809
|
+
/**
|
|
1810
|
+
* Create a new vector action
|
|
1811
|
+
* @param vectorTag Vector database tag
|
|
1812
|
+
* @param data Vector action data
|
|
1813
|
+
* @returns Created vector action
|
|
1814
|
+
*/
|
|
1815
|
+
async createVectorAction(vectorTag, data) {
|
|
1816
|
+
try {
|
|
1817
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1818
|
+
if (!vector) {
|
|
1819
|
+
throw new Error(`Vector with tag: ${vectorTag} not found`);
|
|
1820
|
+
}
|
|
1821
|
+
if (!data.tag) {
|
|
1822
|
+
throw new Error('Action tag is required');
|
|
1823
|
+
}
|
|
1824
|
+
if (!data.name) {
|
|
1825
|
+
throw new Error('Action name is required');
|
|
1826
|
+
}
|
|
1827
|
+
// Parse the tag to get action-only part (format: vector_tag:action_tag)
|
|
1828
|
+
const tagParts = data.tag.split(':');
|
|
1829
|
+
const actionTag = tagParts.length > 1 ? tagParts[tagParts.length - 1] : data.tag;
|
|
1830
|
+
// Check if action already exists
|
|
1831
|
+
const existingActions = vector.actions || [];
|
|
1832
|
+
const exists = existingActions.find(a => a.tag === data.tag || a.tag === `${vectorTag}:${actionTag}`);
|
|
1833
|
+
if (exists) {
|
|
1834
|
+
throw new Error(`Vector action with tag: ${data.tag} already exists`);
|
|
1835
|
+
}
|
|
1836
|
+
// Build the full action tag
|
|
1837
|
+
const fullTag = data.tag.includes(':') ? data.tag : `${vectorTag}:${actionTag}`;
|
|
1838
|
+
const newAction = {
|
|
1839
|
+
name: data.name,
|
|
1840
|
+
tag: fullTag,
|
|
1841
|
+
description: data.description,
|
|
1842
|
+
type: data.type,
|
|
1843
|
+
template: data.template || { options: {} },
|
|
1844
|
+
parameters: data.parameters || [],
|
|
1845
|
+
created_at: new Date(),
|
|
1846
|
+
updated_at: new Date(),
|
|
1847
|
+
};
|
|
1848
|
+
// Add to vector's actions array
|
|
1849
|
+
const updatedActions = [...existingActions, newAction];
|
|
1850
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1851
|
+
tag: vectorTag,
|
|
1852
|
+
actions: updatedActions,
|
|
1853
|
+
component: enums_1.ProductComponents.VECTOR,
|
|
1854
|
+
action: enums_1.RequestAction.UPDATE,
|
|
1855
|
+
}, this.getUserAccess());
|
|
1856
|
+
return newAction;
|
|
1857
|
+
}
|
|
1858
|
+
catch (e) {
|
|
1859
|
+
throw e;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Update an existing vector action
|
|
1864
|
+
* @param vectorTag Vector database tag
|
|
1865
|
+
* @param data Vector action update data (must include tag)
|
|
1866
|
+
* @returns Updated vector action
|
|
1867
|
+
*/
|
|
1868
|
+
async updateVectorAction(vectorTag, data) {
|
|
1869
|
+
try {
|
|
1870
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1871
|
+
if (!vector) {
|
|
1872
|
+
throw new Error(`Vector with tag: ${vectorTag} not found`);
|
|
1873
|
+
}
|
|
1874
|
+
if (!data.tag) {
|
|
1875
|
+
throw new Error('Action tag is required');
|
|
1876
|
+
}
|
|
1877
|
+
const existingActions = vector.actions || [];
|
|
1878
|
+
const actionIndex = existingActions.findIndex(a => a.tag === data.tag);
|
|
1879
|
+
if (actionIndex === -1) {
|
|
1880
|
+
throw new Error(`Vector action with tag: ${data.tag} not found`);
|
|
1881
|
+
}
|
|
1882
|
+
// Merge with existing action
|
|
1883
|
+
const updatedAction = Object.assign(Object.assign(Object.assign({}, existingActions[actionIndex]), data), { updated_at: new Date() });
|
|
1884
|
+
// Update in the array
|
|
1885
|
+
const updatedActions = [...existingActions];
|
|
1886
|
+
updatedActions[actionIndex] = updatedAction;
|
|
1887
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1888
|
+
tag: vectorTag,
|
|
1889
|
+
actions: updatedActions,
|
|
1890
|
+
component: enums_1.ProductComponents.VECTOR,
|
|
1891
|
+
action: enums_1.RequestAction.UPDATE,
|
|
1892
|
+
}, this.getUserAccess());
|
|
1893
|
+
return updatedAction;
|
|
1894
|
+
}
|
|
1895
|
+
catch (e) {
|
|
1896
|
+
throw e;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* Fetch a specific vector action
|
|
1901
|
+
* @param vectorTag Vector database tag
|
|
1902
|
+
* @param actionTag Action tag
|
|
1903
|
+
* @returns Vector action or null
|
|
1904
|
+
*/
|
|
1905
|
+
async fetchVectorAction(vectorTag, actionTag) {
|
|
1906
|
+
try {
|
|
1907
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1908
|
+
if (!vector) {
|
|
1909
|
+
return null;
|
|
1910
|
+
}
|
|
1911
|
+
const actions = vector.actions || [];
|
|
1912
|
+
const action = actions.find(a => a.tag === actionTag || a.tag === `${vectorTag}:${actionTag}`);
|
|
1913
|
+
return action || null;
|
|
1914
|
+
}
|
|
1915
|
+
catch (e) {
|
|
1916
|
+
throw e;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
/**
|
|
1920
|
+
* Fetch all vector actions for a vector database
|
|
1921
|
+
* @param vectorTag Vector database tag
|
|
1922
|
+
* @returns Array of vector actions
|
|
1923
|
+
*/
|
|
1924
|
+
async fetchVectorActions(vectorTag) {
|
|
1925
|
+
try {
|
|
1926
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1927
|
+
if (!vector) {
|
|
1928
|
+
return [];
|
|
1929
|
+
}
|
|
1930
|
+
return vector.actions || [];
|
|
1931
|
+
}
|
|
1932
|
+
catch (e) {
|
|
1933
|
+
throw e;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Delete a vector action
|
|
1938
|
+
* @param vectorTag Vector database tag
|
|
1939
|
+
* @param actionTag Action tag to delete
|
|
1940
|
+
*/
|
|
1941
|
+
async deleteVectorAction(vectorTag, actionTag) {
|
|
1942
|
+
try {
|
|
1943
|
+
const vector = await this.fetchVector(vectorTag);
|
|
1944
|
+
if (!vector) {
|
|
1945
|
+
throw new Error(`Vector with tag: ${vectorTag} not found`);
|
|
1946
|
+
}
|
|
1947
|
+
const existingActions = vector.actions || [];
|
|
1948
|
+
const actionIndex = existingActions.findIndex(a => a.tag === actionTag || a.tag === `${vectorTag}:${actionTag}`);
|
|
1949
|
+
if (actionIndex === -1) {
|
|
1950
|
+
throw new Error(`Vector action with tag: ${actionTag} not found`);
|
|
1951
|
+
}
|
|
1952
|
+
// Remove from array
|
|
1953
|
+
const updatedActions = existingActions.filter((_, idx) => idx !== actionIndex);
|
|
1954
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
1955
|
+
tag: vectorTag,
|
|
1956
|
+
actions: updatedActions,
|
|
1957
|
+
component: enums_1.ProductComponents.VECTOR,
|
|
1958
|
+
action: enums_1.RequestAction.UPDATE,
|
|
1959
|
+
}, this.getUserAccess());
|
|
1960
|
+
}
|
|
1961
|
+
catch (e) {
|
|
1962
|
+
throw e;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
// ==================== AGENT METHODS ====================
|
|
1966
|
+
/**
|
|
1967
|
+
* Create a new agent configuration
|
|
1968
|
+
* @param data Agent configuration data
|
|
1969
|
+
* @param throwErrorIfExists Whether to throw an error if agent already exists
|
|
1970
|
+
*/
|
|
1971
|
+
async createAgent(data, throwErrorIfExists = false) {
|
|
1972
|
+
if (!(await this.fetchAgent(data.tag))) {
|
|
1973
|
+
await validators_1.CreateProductAgentSchema.validateAsync(data);
|
|
1974
|
+
// Validate envs if provided
|
|
1975
|
+
if (data.envs) {
|
|
1976
|
+
for (const env of data.envs) {
|
|
1977
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1978
|
+
if (!exists) {
|
|
1979
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
// Validate that all product envs are configured
|
|
1984
|
+
const envs = await this.fetchEnvs();
|
|
1985
|
+
if (data.envs) {
|
|
1986
|
+
for (const env of envs) {
|
|
1987
|
+
const exists = data.envs.findIndex((agentEnv) => agentEnv.slug === env.slug);
|
|
1988
|
+
if (exists === -1) {
|
|
1989
|
+
// Auto-add missing envs with default config
|
|
1990
|
+
data.envs.push({ slug: env.slug, active: true });
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
else {
|
|
1995
|
+
// Initialize envs with all product envs
|
|
1996
|
+
data.envs = envs.map((env) => ({ slug: env.slug, active: true }));
|
|
1997
|
+
}
|
|
1998
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.AGENT, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1999
|
+
}
|
|
2000
|
+
else {
|
|
2001
|
+
if (throwErrorIfExists)
|
|
2002
|
+
throw new Error(`Agent ${data.tag} already exists`);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Update an existing agent configuration
|
|
2007
|
+
* @param tag Agent tag
|
|
2008
|
+
* @param data Updated agent configuration
|
|
2009
|
+
*/
|
|
2010
|
+
async updateAgent(tag, data) {
|
|
2011
|
+
try {
|
|
2012
|
+
const agent = await this.fetchAgent(tag);
|
|
2013
|
+
if (!agent) {
|
|
2014
|
+
throw new Error(`Agent ${tag} not found`);
|
|
2015
|
+
}
|
|
2016
|
+
const { _id, envs } = agent;
|
|
2017
|
+
await validators_1.UpdateProductAgentSchema.validateAsync(data);
|
|
2018
|
+
if (data.tag && data.tag !== tag && (await this.fetchAgent(data.tag))) {
|
|
2019
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
2020
|
+
}
|
|
2021
|
+
if (data.envs) {
|
|
2022
|
+
// Validate that all provided envs exist
|
|
2023
|
+
for (const env of data.envs) {
|
|
2024
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2025
|
+
if (!exists) {
|
|
2026
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
const overwrite = [];
|
|
2030
|
+
const newEnvs = [];
|
|
2031
|
+
data.envs.forEach((dataEnv) => {
|
|
2032
|
+
var _a;
|
|
2033
|
+
const existsIdx = (_a = envs === null || envs === void 0 ? void 0 : envs.findIndex((env) => env.slug === dataEnv.slug)) !== null && _a !== void 0 ? _a : -1;
|
|
2034
|
+
if (existsIdx === -1) {
|
|
2035
|
+
newEnvs.push(dataEnv);
|
|
2036
|
+
}
|
|
2037
|
+
else {
|
|
2038
|
+
overwrite.push(Object.assign(Object.assign({}, envs[existsIdx]), dataEnv));
|
|
2039
|
+
}
|
|
2040
|
+
});
|
|
2041
|
+
const unchanged = [];
|
|
2042
|
+
envs === null || envs === void 0 ? void 0 : envs.forEach((env) => {
|
|
2043
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
2044
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
2045
|
+
if (!newEnv && !overwriteEnv) {
|
|
2046
|
+
unchanged.push(env);
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
2050
|
+
}
|
|
2051
|
+
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());
|
|
2052
|
+
}
|
|
2053
|
+
catch (e) {
|
|
2054
|
+
throw e;
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Fetch all agent configurations
|
|
2059
|
+
* @param version Optional version
|
|
2060
|
+
*/
|
|
2061
|
+
async fetchAgents(version) {
|
|
2062
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'agent', this.getUserAccess());
|
|
2063
|
+
return components;
|
|
2064
|
+
}
|
|
2065
|
+
/**
|
|
2066
|
+
* Fetch a specific agent configuration by tag
|
|
2067
|
+
* @param tag Agent tag
|
|
2068
|
+
* @param version Optional version
|
|
2069
|
+
*/
|
|
2070
|
+
async fetchAgent(tag, version) {
|
|
2071
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'agent', tag, this.getUserAccess());
|
|
2072
|
+
return component;
|
|
2073
|
+
}
|
|
2074
|
+
/**
|
|
2075
|
+
* Delete an agent configuration
|
|
2076
|
+
* @param tag Agent tag
|
|
2077
|
+
*/
|
|
2078
|
+
async deleteAgent(tag) {
|
|
2079
|
+
try {
|
|
2080
|
+
const agent = await this.fetchAgent(tag);
|
|
2081
|
+
if (!agent) {
|
|
2082
|
+
throw new Error(`Agent with tag: ${tag} not found`);
|
|
2083
|
+
}
|
|
2084
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2085
|
+
tag,
|
|
2086
|
+
component: enums_1.ProductComponents.AGENT,
|
|
2087
|
+
action: enums_1.RequestAction.DELETE,
|
|
2088
|
+
}, this.getUserAccess());
|
|
2089
|
+
}
|
|
2090
|
+
catch (e) {
|
|
2091
|
+
throw e;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
// ==================== LLM MODEL METHODS ====================
|
|
2095
|
+
/**
|
|
2096
|
+
* Create a new LLM model configuration
|
|
2097
|
+
* API keys are automatically encrypted using the product's private key
|
|
2098
|
+
* @param data LLM model configuration
|
|
2099
|
+
* @param throwErrorIfExists Whether to throw error if model already exists
|
|
2100
|
+
*/
|
|
2101
|
+
async createModel(data, throwErrorIfExists = false) {
|
|
2102
|
+
if (!(await this.fetchModel(data.tag))) {
|
|
2103
|
+
await validators_1.CreateProductModelSchema.validateAsync(data);
|
|
2104
|
+
const processedEnvs = [];
|
|
2105
|
+
for (const env of data.envs) {
|
|
2106
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2107
|
+
if (!exists) {
|
|
2108
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
2109
|
+
}
|
|
2110
|
+
// Store API key as secret and encrypt
|
|
2111
|
+
if (env.apiKey) {
|
|
2112
|
+
env.apiKey = await this.storeModelApiKeyAsSecret(env.apiKey, data.tag, env.slug);
|
|
2113
|
+
env.apiKey = (0, processor_utils_1.encrypt)(env.apiKey, this.product.private_key);
|
|
2114
|
+
}
|
|
2115
|
+
processedEnvs.push(env);
|
|
2116
|
+
}
|
|
2117
|
+
data.envs = processedEnvs;
|
|
2118
|
+
const envs = await this.fetchEnvs();
|
|
2119
|
+
for (const env of envs) {
|
|
2120
|
+
const exists = data.envs.findIndex((modelEnv) => modelEnv.slug === env.slug);
|
|
2121
|
+
if (exists === -1) {
|
|
2122
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide API key configuration`);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.MODEL, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2126
|
+
}
|
|
2127
|
+
else {
|
|
2128
|
+
if (throwErrorIfExists)
|
|
2129
|
+
throw new Error(`Model ${data.tag} already exists`);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* Update an existing LLM model configuration
|
|
2134
|
+
* @param tag Model tag
|
|
2135
|
+
* @param data Updated model configuration
|
|
2136
|
+
*/
|
|
2137
|
+
async updateModel(tag, data) {
|
|
2138
|
+
try {
|
|
2139
|
+
const model = await this.fetchModel(tag);
|
|
2140
|
+
if (!model) {
|
|
2141
|
+
throw new Error(`Model ${tag} not found`);
|
|
2142
|
+
}
|
|
2143
|
+
const { _id, envs } = model;
|
|
2144
|
+
await validators_1.UpdateProductModelSchema.validateAsync(data);
|
|
2145
|
+
if (data.tag && (await this.fetchModel(data.tag))) {
|
|
2146
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
2147
|
+
}
|
|
2148
|
+
if (data.envs) {
|
|
2149
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
2150
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2151
|
+
if (!exists) {
|
|
2152
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
2153
|
+
}
|
|
2154
|
+
// Store API key as secret and encrypt
|
|
2155
|
+
if (env.apiKey) {
|
|
2156
|
+
env.apiKey = await this.storeModelApiKeyAsSecret(env.apiKey, data.tag || tag, env.slug);
|
|
2157
|
+
env.apiKey = (0, processor_utils_1.encrypt)(env.apiKey, this.product.private_key);
|
|
2158
|
+
}
|
|
2159
|
+
return env;
|
|
2160
|
+
}));
|
|
2161
|
+
const overwrite = [];
|
|
2162
|
+
const newEnvs = [];
|
|
2163
|
+
data.envs.forEach((dataEnv) => {
|
|
2164
|
+
const existsIdx = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
2165
|
+
if (existsIdx === -1) {
|
|
2166
|
+
newEnvs.push(dataEnv);
|
|
2167
|
+
}
|
|
2168
|
+
else {
|
|
2169
|
+
overwrite.push(Object.assign(Object.assign({}, envs[existsIdx]), dataEnv));
|
|
2170
|
+
}
|
|
2171
|
+
});
|
|
2172
|
+
const unchanged = [];
|
|
2173
|
+
envs.forEach((env) => {
|
|
2174
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
2175
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
2176
|
+
if (!newEnv && !overwriteEnv) {
|
|
2177
|
+
unchanged.push(env);
|
|
2178
|
+
}
|
|
2179
|
+
});
|
|
2180
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
2181
|
+
}
|
|
2182
|
+
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());
|
|
2183
|
+
}
|
|
2184
|
+
catch (e) {
|
|
2185
|
+
throw e;
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Fetch all LLM model configurations
|
|
2190
|
+
* @param version Optional version
|
|
2191
|
+
*/
|
|
2192
|
+
async fetchModels(version) {
|
|
2193
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'model', this.getUserAccess());
|
|
2194
|
+
return components;
|
|
2195
|
+
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Fetch a specific LLM model configuration by tag
|
|
2198
|
+
* @param tag Model tag
|
|
2199
|
+
* @param version Optional version
|
|
2200
|
+
*/
|
|
2201
|
+
async fetchModel(tag, version) {
|
|
2202
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'model', tag, this.getUserAccess());
|
|
2203
|
+
return component;
|
|
2204
|
+
}
|
|
2205
|
+
/**
|
|
2206
|
+
* Delete an LLM model configuration
|
|
2207
|
+
* @param tag Model tag
|
|
2208
|
+
*/
|
|
2209
|
+
async deleteModel(tag) {
|
|
2210
|
+
try {
|
|
2211
|
+
const model = await this.fetchModel(tag);
|
|
2212
|
+
if (!model) {
|
|
2213
|
+
throw new Error(`Model with tag: ${tag} not found`);
|
|
2214
|
+
}
|
|
2215
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2216
|
+
tag,
|
|
2217
|
+
component: enums_1.ProductComponents.MODEL,
|
|
2218
|
+
action: enums_1.RequestAction.DELETE,
|
|
2219
|
+
}, this.getUserAccess());
|
|
2220
|
+
}
|
|
2221
|
+
catch (e) {
|
|
2222
|
+
throw e;
|
|
2223
|
+
}
|
|
1190
2224
|
}
|
|
1191
2225
|
async validateAppData(appData, app) {
|
|
1192
2226
|
// TODO:
|
|
@@ -1209,6 +2243,9 @@ class ProductsBuilderService {
|
|
|
1209
2243
|
}
|
|
1210
2244
|
}
|
|
1211
2245
|
validateVariablesValues(variables, appVariables) {
|
|
2246
|
+
if (!variables) {
|
|
2247
|
+
variables = [];
|
|
2248
|
+
}
|
|
1212
2249
|
if (appVariables && appVariables.length) {
|
|
1213
2250
|
appVariables.map((data) => {
|
|
1214
2251
|
const find = variables.find((value) => value.key === data.key);
|
|
@@ -1225,20 +2262,21 @@ class ProductsBuilderService {
|
|
|
1225
2262
|
const { envs: appEnvs } = version;
|
|
1226
2263
|
return envs.map((env) => {
|
|
1227
2264
|
const { auth } = env;
|
|
1228
|
-
this.fetchEnv(env.product_env_slug
|
|
2265
|
+
this.fetchEnv(env.product_env_slug);
|
|
1229
2266
|
const appEnv = appEnvs.find((appEnv) => appEnv.slug === env.app_env_slug);
|
|
1230
2267
|
if (!appEnv) {
|
|
1231
2268
|
throw new Error(`app_slug ${env.app_env_slug} not found`);
|
|
1232
2269
|
}
|
|
1233
|
-
const updates = this.validateAppAuth(auth, version);
|
|
2270
|
+
// const updates = this.validateAppAuth(auth, version);
|
|
1234
2271
|
this.validateVariablesSchema(env.variables, version.variables);
|
|
1235
2272
|
this.validateVariablesValues(env.variables, version.variables);
|
|
1236
|
-
if (updates && updates.data) {
|
|
1237
|
-
|
|
2273
|
+
/*if (updates && updates.data) {
|
|
2274
|
+
env.auth.data = updates.data;
|
|
1238
2275
|
}
|
|
2276
|
+
|
|
1239
2277
|
if (updates && updates.values) {
|
|
1240
|
-
|
|
1241
|
-
}
|
|
2278
|
+
env.auth.values = updates.values;
|
|
2279
|
+
}*/
|
|
1242
2280
|
return env;
|
|
1243
2281
|
});
|
|
1244
2282
|
}
|
|
@@ -1315,10 +2353,10 @@ class ProductsBuilderService {
|
|
|
1315
2353
|
});
|
|
1316
2354
|
(0, inputs_utils_create_1.validateInputSchema)(queryValues, querySchema);
|
|
1317
2355
|
}
|
|
1318
|
-
const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.
|
|
2356
|
+
const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.product.private_key);
|
|
1319
2357
|
let updateValues = null;
|
|
1320
2358
|
if (exists.setup_type === enums_1.AuthTypes.TOKEN) {
|
|
1321
|
-
updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.
|
|
2359
|
+
updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.product.private_key);
|
|
1322
2360
|
}
|
|
1323
2361
|
return { data: updateData, values: updateValues };
|
|
1324
2362
|
}
|
|
@@ -1341,7 +2379,7 @@ class ProductsBuilderService {
|
|
|
1341
2379
|
try {
|
|
1342
2380
|
await validators_1.CreateProductAppSchema.validateAsync(app);
|
|
1343
2381
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1344
|
-
if (!this.fetchApp(app.access_tag, throwErrorIfExists)) {
|
|
2382
|
+
if (!await this.fetchApp(app.access_tag, throwErrorIfExists)) {
|
|
1345
2383
|
const _a = await this.appApi.fetchAccessByTag(app.access_tag, this.getUserAccess()), { version } = _a, access = __rest(_a, ["version"]);
|
|
1346
2384
|
if (!access) {
|
|
1347
2385
|
throw new Error(`Access to app ${app.access_tag} not found`);
|
|
@@ -1351,8 +2389,11 @@ class ProductsBuilderService {
|
|
|
1351
2389
|
throw new Error(`App ${app.access_tag} not found`);
|
|
1352
2390
|
}
|
|
1353
2391
|
const cleanedAppData = await this.validateAppData(appData, app);
|
|
2392
|
+
if (!cleanedAppData.pricing_tag) {
|
|
2393
|
+
cleanedAppData.pricing_tag = `${appData.tag}:${productsBuilder_types_1.PricingTag.FREE}`;
|
|
2394
|
+
}
|
|
2395
|
+
console.log(cleanedAppData);
|
|
1354
2396
|
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());
|
|
1355
|
-
await this.initializeProduct(this.product_id);
|
|
1356
2397
|
}
|
|
1357
2398
|
else {
|
|
1358
2399
|
if (throwErrorIfExists)
|
|
@@ -1383,7 +2424,7 @@ class ProductsBuilderService {
|
|
|
1383
2424
|
}
|
|
1384
2425
|
async updateApp(access_tag, data) {
|
|
1385
2426
|
try {
|
|
1386
|
-
const app = this.fetchApp(access_tag);
|
|
2427
|
+
const app = await this.fetchApp(access_tag);
|
|
1387
2428
|
if (!app) {
|
|
1388
2429
|
throw new Error(`App ${access_tag} not found`);
|
|
1389
2430
|
}
|
|
@@ -1399,28 +2440,44 @@ class ProductsBuilderService {
|
|
|
1399
2440
|
throw new Error(`access_tag ${access_tag} is in use`); // TODO: also check on the backend
|
|
1400
2441
|
}*/
|
|
1401
2442
|
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());
|
|
1402
|
-
await this.initializeProduct(this.product_id);
|
|
1403
2443
|
}
|
|
1404
2444
|
catch (e) {
|
|
1405
2445
|
throw e;
|
|
1406
2446
|
}
|
|
1407
2447
|
}
|
|
1408
|
-
fetchApps() {
|
|
1409
|
-
|
|
2448
|
+
async fetchApps() {
|
|
2449
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'app', this.getUserAccess());
|
|
2450
|
+
return components;
|
|
1410
2451
|
}
|
|
1411
|
-
fetchApp(tag, throwErrorIfExists = false) {
|
|
1412
|
-
const
|
|
1413
|
-
if (!
|
|
2452
|
+
async fetchApp(tag, throwErrorIfExists = false) {
|
|
2453
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'app', tag, this.getUserAccess());
|
|
2454
|
+
if (!component && throwErrorIfExists)
|
|
1414
2455
|
throw new Error(`App ${tag} not found`);
|
|
1415
|
-
return
|
|
2456
|
+
return component;
|
|
2457
|
+
}
|
|
2458
|
+
async deleteApp(tag) {
|
|
2459
|
+
try {
|
|
2460
|
+
const app = await this.fetchApp(tag, true);
|
|
2461
|
+
if (!app) {
|
|
2462
|
+
throw new Error(`App with tag: ${tag} not found`);
|
|
2463
|
+
}
|
|
2464
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2465
|
+
tag: app.access_tag,
|
|
2466
|
+
component: enums_1.ProductComponents.APP,
|
|
2467
|
+
action: enums_1.RequestAction.DELETE,
|
|
2468
|
+
}, this.getUserAccess());
|
|
2469
|
+
}
|
|
2470
|
+
catch (e) {
|
|
2471
|
+
throw e;
|
|
2472
|
+
}
|
|
1416
2473
|
}
|
|
1417
2474
|
async createFunction(data, throwErrorIfExists = false) {
|
|
1418
2475
|
try {
|
|
1419
2476
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1420
|
-
if (!this.fetchFunction(data.tag)) {
|
|
2477
|
+
if (!(await this.fetchFunction(data.tag))) {
|
|
1421
2478
|
await validators_1.CreateProductFunctionSchema.validateAsync(data);
|
|
1422
2479
|
data.envs.map((env) => {
|
|
1423
|
-
env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.
|
|
2480
|
+
env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.product.private_key);
|
|
1424
2481
|
});
|
|
1425
2482
|
data.sample_data = (await this.inputsService.parseJson({
|
|
1426
2483
|
data: data.sample,
|
|
@@ -1433,7 +2490,6 @@ class ProductsBuilderService {
|
|
|
1433
2490
|
category: enums_1.Categories.DATA,
|
|
1434
2491
|
}));
|
|
1435
2492
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FUNCTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1436
|
-
await this.initializeProduct(this.product_id);
|
|
1437
2493
|
}
|
|
1438
2494
|
else {
|
|
1439
2495
|
if (throwErrorIfExists)
|
|
@@ -1446,37 +2502,51 @@ class ProductsBuilderService {
|
|
|
1446
2502
|
}
|
|
1447
2503
|
async updateFunction(tag, data) {
|
|
1448
2504
|
try {
|
|
1449
|
-
const func = this.fetchFunction(tag);
|
|
2505
|
+
const func = await this.fetchFunction(tag);
|
|
1450
2506
|
if (!func) {
|
|
1451
2507
|
throw new Error(`Function ${tag} not found`);
|
|
1452
2508
|
}
|
|
1453
2509
|
const { _id } = func;
|
|
1454
2510
|
await validators_1.UpdateProductFunctionSchema.validateAsync(data); // Change to update;
|
|
1455
|
-
if (data.tag && this.fetchFunction(data.tag)) {
|
|
2511
|
+
if (data.tag && (await this.fetchFunction(data.tag))) {
|
|
1456
2512
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1457
2513
|
}
|
|
1458
2514
|
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());
|
|
1459
|
-
await this.initializeProduct(this.product_id);
|
|
1460
2515
|
}
|
|
1461
2516
|
catch (e) {
|
|
1462
2517
|
throw e;
|
|
1463
2518
|
}
|
|
1464
2519
|
}
|
|
1465
|
-
fetchFunctions() {
|
|
1466
|
-
|
|
2520
|
+
async fetchFunctions(version) {
|
|
2521
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'function', this.getUserAccess());
|
|
2522
|
+
return components;
|
|
2523
|
+
}
|
|
2524
|
+
async fetchFunction(tag, version) {
|
|
2525
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'function', tag, this.getUserAccess());
|
|
2526
|
+
return component;
|
|
1467
2527
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
2528
|
+
async deleteFunction(tag) {
|
|
2529
|
+
try {
|
|
2530
|
+
const func = await this.fetchFunction(tag);
|
|
2531
|
+
if (!func) {
|
|
2532
|
+
throw new Error(`Function with tag: ${tag} not found`);
|
|
2533
|
+
}
|
|
2534
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2535
|
+
tag,
|
|
2536
|
+
component: enums_1.ProductComponents.FUNCTION,
|
|
2537
|
+
action: enums_1.RequestAction.DELETE,
|
|
2538
|
+
}, this.getUserAccess());
|
|
2539
|
+
}
|
|
2540
|
+
catch (e) {
|
|
2541
|
+
throw e;
|
|
2542
|
+
}
|
|
1472
2543
|
}
|
|
1473
2544
|
async createCache(data, throwErrorIfExists = false) {
|
|
1474
2545
|
try {
|
|
1475
2546
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1476
|
-
if (!this.fetchCache(data.tag)) {
|
|
2547
|
+
if (!(await this.fetchCache(data.tag))) {
|
|
1477
2548
|
await validators_1.CreateProductCacheSchema.validateAsync(data);
|
|
1478
2549
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.CACHE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1479
|
-
await this.initializeProduct(this.product_id);
|
|
1480
2550
|
}
|
|
1481
2551
|
else {
|
|
1482
2552
|
if (throwErrorIfExists)
|
|
@@ -1489,62 +2559,75 @@ class ProductsBuilderService {
|
|
|
1489
2559
|
}
|
|
1490
2560
|
async updateCache(tag, data) {
|
|
1491
2561
|
try {
|
|
1492
|
-
const cache = this.fetchCache(tag);
|
|
2562
|
+
const cache = await this.fetchCache(tag);
|
|
1493
2563
|
if (!cache) {
|
|
1494
2564
|
throw new Error(`Cache ${tag} not found`);
|
|
1495
2565
|
}
|
|
1496
2566
|
const { _id } = cache;
|
|
1497
2567
|
await validators_1.UpdateProductCacheSchema.validateAsync(data); // Change to update;
|
|
1498
|
-
if (data.tag && this.fetchCache(data.tag)) {
|
|
2568
|
+
if (data.tag && (await this.fetchCache(data.tag))) {
|
|
1499
2569
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1500
2570
|
}
|
|
1501
2571
|
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());
|
|
1502
|
-
await this.initializeProduct(this.product_id);
|
|
1503
2572
|
}
|
|
1504
2573
|
catch (e) {
|
|
1505
2574
|
throw e;
|
|
1506
2575
|
}
|
|
1507
2576
|
}
|
|
1508
|
-
|
|
1509
|
-
const
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
2577
|
+
async fetchCaches(version) {
|
|
2578
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'cache', this.getUserAccess());
|
|
2579
|
+
return components;
|
|
2580
|
+
}
|
|
2581
|
+
async fetchCache(tag, version) {
|
|
2582
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'cache', tag, this.getUserAccess());
|
|
2583
|
+
return component;
|
|
1513
2584
|
}
|
|
1514
|
-
|
|
1515
|
-
|
|
2585
|
+
async deleteCache(tag) {
|
|
2586
|
+
try {
|
|
2587
|
+
const cache = await this.fetchCache(tag);
|
|
2588
|
+
if (!cache) {
|
|
2589
|
+
throw new Error(`Cache with tag: ${tag} not found`);
|
|
2590
|
+
}
|
|
2591
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2592
|
+
tag,
|
|
2593
|
+
component: enums_1.ProductComponents.CACHE,
|
|
2594
|
+
action: enums_1.RequestAction.DELETE,
|
|
2595
|
+
}, this.getUserAccess());
|
|
2596
|
+
}
|
|
2597
|
+
catch (e) {
|
|
2598
|
+
throw e;
|
|
2599
|
+
}
|
|
1516
2600
|
}
|
|
1517
2601
|
async createNotification(data, throwErrorIfExists = false) {
|
|
1518
2602
|
try {
|
|
1519
2603
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1520
|
-
if (!this.fetchNotification(data.tag)) {
|
|
2604
|
+
if (!(await this.fetchNotification(data.tag))) {
|
|
1521
2605
|
await validators_1.CreateProductNotificationSchema.validateAsync(data);
|
|
1522
|
-
const envs = this.fetchEnvs();
|
|
1523
|
-
|
|
2606
|
+
const envs = await this.fetchEnvs();
|
|
2607
|
+
for (const env of envs) {
|
|
1524
2608
|
const exists = data.envs.findIndex((nEnv) => nEnv.slug === env.slug);
|
|
1525
2609
|
if (exists === -1) {
|
|
1526
2610
|
throw new Error(`Notification for environment ${env.slug} is not defined, please provide the environment details`);
|
|
1527
2611
|
}
|
|
1528
|
-
}
|
|
2612
|
+
}
|
|
1529
2613
|
for (let i = 0; i < data.envs.length; i++) {
|
|
2614
|
+
// Process secrets for each notification handler
|
|
2615
|
+
const processedEnv = await this.processNotificationEnvSecrets(data.envs[i], data.tag, data.envs[i].slug);
|
|
1530
2616
|
const updates = {
|
|
1531
|
-
push_notifications:
|
|
1532
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(
|
|
2617
|
+
push_notifications: processedEnv.push_notifications
|
|
2618
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.push_notifications), this.product.private_key)
|
|
1533
2619
|
: undefined,
|
|
1534
|
-
emails:
|
|
1535
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(
|
|
2620
|
+
emails: processedEnv.emails
|
|
2621
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.emails), this.product.private_key)
|
|
1536
2622
|
: undefined,
|
|
1537
|
-
callbacks:
|
|
1538
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(
|
|
1539
|
-
: undefined,
|
|
1540
|
-
sms: data.envs[i].sms
|
|
1541
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].sms), this.fetchProduct().private_key)
|
|
2623
|
+
callbacks: processedEnv.callbacks
|
|
2624
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.callbacks), this.product.private_key)
|
|
1542
2625
|
: undefined,
|
|
2626
|
+
sms: processedEnv.sms ? (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.sms), this.product.private_key) : undefined,
|
|
1543
2627
|
};
|
|
1544
2628
|
data.envs[i] = Object.assign(Object.assign({}, data.envs[i]), updates);
|
|
1545
2629
|
}
|
|
1546
2630
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1547
|
-
await this.initializeProduct(this.product_id);
|
|
1548
2631
|
}
|
|
1549
2632
|
else {
|
|
1550
2633
|
if (throwErrorIfExists)
|
|
@@ -1565,7 +2648,7 @@ class ProductsBuilderService {
|
|
|
1565
2648
|
if (!notificationTag || !tag) {
|
|
1566
2649
|
throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
|
|
1567
2650
|
}
|
|
1568
|
-
const exists = this.fetchNotificationMessage(data.tag);
|
|
2651
|
+
const exists = await this.fetchNotificationMessage(data.tag);
|
|
1569
2652
|
data.tag = tag;
|
|
1570
2653
|
if (!exists) {
|
|
1571
2654
|
if (!data.email && !data.push_notification && !data.callback) {
|
|
@@ -1602,7 +2685,6 @@ class ProductsBuilderService {
|
|
|
1602
2685
|
data.sms_data = (0, string_utils_1.extractPlaceholders)(data.sms, '');
|
|
1603
2686
|
}
|
|
1604
2687
|
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());
|
|
1605
|
-
await this.initializeProduct(this.product_id);
|
|
1606
2688
|
}
|
|
1607
2689
|
else {
|
|
1608
2690
|
if (throwErrorIfExists)
|
|
@@ -1613,12 +2695,12 @@ class ProductsBuilderService {
|
|
|
1613
2695
|
throw e;
|
|
1614
2696
|
}
|
|
1615
2697
|
}
|
|
1616
|
-
fetchNotificationMessage(tag, throwErrorIfExists = false) {
|
|
2698
|
+
async fetchNotificationMessage(tag, throwErrorIfExists = false) {
|
|
1617
2699
|
const [notificationTag, messageTag] = tag.split(':');
|
|
1618
2700
|
if (!notificationTag || !messageTag) {
|
|
1619
2701
|
throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
|
|
1620
2702
|
}
|
|
1621
|
-
const notification = this.fetchNotification(notificationTag);
|
|
2703
|
+
const notification = await this.fetchNotification(notificationTag);
|
|
1622
2704
|
if (!notification)
|
|
1623
2705
|
throw new Error(`Notification ${notificationTag} not found`);
|
|
1624
2706
|
const message = notification.messages.find((data) => data.tag === messageTag);
|
|
@@ -1626,7 +2708,7 @@ class ProductsBuilderService {
|
|
|
1626
2708
|
throw new Error(`Notification message ${tag} not found`);
|
|
1627
2709
|
return message;
|
|
1628
2710
|
}
|
|
1629
|
-
fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
|
|
2711
|
+
async fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
|
|
1630
2712
|
const notification = this.product.notifications.find((data) => data.tag === notificationTag);
|
|
1631
2713
|
if (!notification)
|
|
1632
2714
|
throw new Error(`Notification ${notificationTag} not found`);
|
|
@@ -1634,7 +2716,7 @@ class ProductsBuilderService {
|
|
|
1634
2716
|
}
|
|
1635
2717
|
async updateNotificationMessage(data) {
|
|
1636
2718
|
try {
|
|
1637
|
-
console.log(
|
|
2719
|
+
console.log('NOTIFICATION DATA!!', data);
|
|
1638
2720
|
await update_productNotificationMessage_validator_1.default.validateAsync(data);
|
|
1639
2721
|
if (!data.tag) {
|
|
1640
2722
|
throw new Error('tag field is required');
|
|
@@ -1680,7 +2762,6 @@ class ProductsBuilderService {
|
|
|
1680
2762
|
const payload = Object.assign(Object.assign(Object.assign({}, message), data), { notificationTag, component: enums_1.ProductComponents.NOTIFICATION_MESSAGE, action: enums_1.RequestAction.UPDATE });
|
|
1681
2763
|
// Update product and reinitialize
|
|
1682
2764
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
1683
|
-
await this.initializeProduct(this.product_id);
|
|
1684
2765
|
}
|
|
1685
2766
|
catch (error) {
|
|
1686
2767
|
throw error;
|
|
@@ -1688,21 +2769,25 @@ class ProductsBuilderService {
|
|
|
1688
2769
|
}
|
|
1689
2770
|
async updateNotification(tag, data) {
|
|
1690
2771
|
try {
|
|
1691
|
-
const
|
|
1692
|
-
if (
|
|
2772
|
+
const notificationResult = await this.fetchNotification(tag);
|
|
2773
|
+
if (!notificationResult) {
|
|
2774
|
+
throw new Error(`Notification with tag ${tag} not found`);
|
|
2775
|
+
}
|
|
2776
|
+
const { _id, envs } = notificationResult;
|
|
2777
|
+
if (data.tag && tag !== data.tag && (await this.fetchNotification(data.tag))) {
|
|
1693
2778
|
throw new Error(`Notification of tag ${data.tag} already exists`);
|
|
1694
2779
|
}
|
|
1695
2780
|
await validators_1.UpdateProductNotificationSchema.validateAsync(data); // Change to update;
|
|
1696
|
-
let notification = this.fetchNotification(tag);
|
|
2781
|
+
let notification = await this.fetchNotification(tag);
|
|
1697
2782
|
if (!notification) {
|
|
1698
2783
|
throw new Error(`Notification with tag ${tag} not found`);
|
|
1699
2784
|
}
|
|
1700
2785
|
if (data.envs) {
|
|
1701
2786
|
const overwrite = [];
|
|
1702
2787
|
const newEnvs = [];
|
|
1703
|
-
data.envs
|
|
2788
|
+
for (const dataEnv of data.envs) {
|
|
1704
2789
|
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1705
|
-
if (!this.fetchEnv(dataEnv.slug)) {
|
|
2790
|
+
if (!(await this.fetchEnv(dataEnv.slug))) {
|
|
1706
2791
|
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
1707
2792
|
}
|
|
1708
2793
|
if (exists === -1) {
|
|
@@ -1712,74 +2797,107 @@ class ProductsBuilderService {
|
|
|
1712
2797
|
else {
|
|
1713
2798
|
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1714
2799
|
}
|
|
1715
|
-
}
|
|
2800
|
+
}
|
|
1716
2801
|
const unchanged = [];
|
|
1717
|
-
|
|
2802
|
+
for (const env of envs) {
|
|
1718
2803
|
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1719
2804
|
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1720
2805
|
if (!newEnv && !overwriteEnv) {
|
|
1721
2806
|
unchanged.push(env);
|
|
1722
2807
|
}
|
|
1723
|
-
}
|
|
2808
|
+
}
|
|
1724
2809
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1725
2810
|
}
|
|
1726
2811
|
const update = Object.assign(Object.assign({}, notification), data);
|
|
1727
|
-
update.envs.
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
2812
|
+
for (let i = 0; i < update.envs.length; i++) {
|
|
2813
|
+
const env = update.envs[i];
|
|
2814
|
+
// Process secrets for each notification handler
|
|
2815
|
+
const processedEnv = await this.processNotificationEnvSecrets(env, data.tag || tag, env.slug);
|
|
2816
|
+
if (processedEnv.emails)
|
|
2817
|
+
update.envs[i].emails = (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.emails), this.product.private_key);
|
|
2818
|
+
if (processedEnv.push_notifications)
|
|
2819
|
+
update.envs[i].push_notifications = (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.push_notifications), this.product.private_key);
|
|
2820
|
+
if (processedEnv.callbacks)
|
|
2821
|
+
update.envs[i].callbacks = (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.callbacks), this.product.private_key);
|
|
2822
|
+
if (processedEnv.sms)
|
|
2823
|
+
update.envs[i].sms = (0, processor_utils_1.encrypt)(JSON.stringify(processedEnv.sms), this.product.private_key);
|
|
2824
|
+
}
|
|
1738
2825
|
const payload = Object.assign(Object.assign({ _id }, update), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.UPDATE });
|
|
1739
2826
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
1740
|
-
await this.initializeProduct(this.product_id);
|
|
1741
2827
|
}
|
|
1742
2828
|
catch (e) {
|
|
1743
2829
|
throw e;
|
|
1744
2830
|
}
|
|
1745
2831
|
}
|
|
1746
|
-
|
|
1747
|
-
const
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
2832
|
+
async fetchNotifications(version) {
|
|
2833
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'notification', this.getUserAccess());
|
|
2834
|
+
return components.map((component) => this.decryptNotificationChannelConfigs(component));
|
|
2835
|
+
}
|
|
2836
|
+
async fetchNotification(tag, version) {
|
|
2837
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'notification', tag, this.getUserAccess());
|
|
2838
|
+
if (!component)
|
|
2839
|
+
return null;
|
|
2840
|
+
return this.decryptNotificationChannelConfigs(component);
|
|
2841
|
+
}
|
|
2842
|
+
decryptNotificationChannelConfigs(notification) {
|
|
2843
|
+
const envs = notification.envs || [];
|
|
2844
|
+
const decryptedEnvs = envs.map((env) => {
|
|
2845
|
+
const out = Object.assign({}, env);
|
|
2846
|
+
if (env.push_notifications) {
|
|
2847
|
+
try {
|
|
2848
|
+
out.push_notifications = JSON.parse((0, processor_utils_1.decrypt)(env.push_notifications, this.product.private_key));
|
|
1760
2849
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
2850
|
+
catch (_a) {
|
|
2851
|
+
out.push_notifications = env.push_notifications;
|
|
1763
2852
|
}
|
|
1764
|
-
|
|
1765
|
-
|
|
2853
|
+
}
|
|
2854
|
+
if (env.emails) {
|
|
2855
|
+
try {
|
|
2856
|
+
out.emails = JSON.parse((0, processor_utils_1.decrypt)(env.emails, this.product.private_key));
|
|
1766
2857
|
}
|
|
1767
|
-
|
|
1768
|
-
|
|
2858
|
+
catch (_b) {
|
|
2859
|
+
out.emails = env.emails;
|
|
1769
2860
|
}
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
2861
|
+
}
|
|
2862
|
+
if (env.callbacks) {
|
|
2863
|
+
try {
|
|
2864
|
+
out.callbacks = JSON.parse((0, processor_utils_1.decrypt)(env.callbacks, this.product.private_key));
|
|
2865
|
+
}
|
|
2866
|
+
catch (_c) {
|
|
2867
|
+
out.callbacks = env.callbacks;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
if (env.sms) {
|
|
2871
|
+
try {
|
|
2872
|
+
out.sms = JSON.parse((0, processor_utils_1.decrypt)(env.sms, this.product.private_key));
|
|
2873
|
+
}
|
|
2874
|
+
catch (_d) {
|
|
2875
|
+
out.sms = env.sms;
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
return out;
|
|
2879
|
+
});
|
|
2880
|
+
return Object.assign(Object.assign({}, notification), { envs: decryptedEnvs });
|
|
2881
|
+
}
|
|
2882
|
+
async deleteNotification(tag) {
|
|
2883
|
+
try {
|
|
2884
|
+
const notification = await this.fetchNotification(tag);
|
|
2885
|
+
if (!notification) {
|
|
2886
|
+
throw new Error(`Notification with tag: ${tag} not found`);
|
|
2887
|
+
}
|
|
2888
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
2889
|
+
tag,
|
|
2890
|
+
component: enums_1.ProductComponents.NOTIFICATION,
|
|
2891
|
+
action: enums_1.RequestAction.DELETE,
|
|
2892
|
+
}, this.getUserAccess());
|
|
2893
|
+
}
|
|
2894
|
+
catch (e) {
|
|
2895
|
+
throw e;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
validateFeatureSequence(array) {
|
|
2899
|
+
// Validate uniqueness of sequence_tag
|
|
2900
|
+
const uniqueTags = new Set();
|
|
1783
2901
|
for (const item of array) {
|
|
1784
2902
|
if (uniqueTags.has(item.tag)) {
|
|
1785
2903
|
throw new Error(`Duplicate sequence_tag found: ${item.tag}`);
|
|
@@ -1875,24 +2993,27 @@ class ProductsBuilderService {
|
|
|
1875
2993
|
await this.validateActionDataInput(data, action, event.input, event_index, sequence_index);
|
|
1876
2994
|
}
|
|
1877
2995
|
async checkAndValidateFunctionDataInput(data, sequence_index, event, event_index) {
|
|
1878
|
-
const func = this.fetchFunction(event.event);
|
|
2996
|
+
const func = (await this.fetchFunction(event.event));
|
|
1879
2997
|
await this.validateActionDataInput(data, func, event.input, event_index, sequence_index);
|
|
1880
2998
|
}
|
|
1881
2999
|
async checkAndValidateDBActionDataInput(data, sequence_index, event, event_index) {
|
|
1882
3000
|
console.log('EVENTY', event.event);
|
|
1883
|
-
const { filterData, data: dbData, filterTemplate, template } = this.fetchDatabaseAction(event.event);
|
|
3001
|
+
const { filterData, data: dbData, filterTemplate, template } = await this.fetchDatabaseAction(event.event);
|
|
1884
3002
|
await this.validateDBActionDataInput(data, { filterData, data: dbData, template, filter: filterTemplate }, event.input, event_index, sequence_index);
|
|
1885
3003
|
}
|
|
1886
3004
|
async checkAndValidateFeatureDataInput(data, sequence_index, event, event_index) {
|
|
1887
|
-
const
|
|
3005
|
+
const feature = await this.fetchFeature(event.event);
|
|
3006
|
+
if (!feature)
|
|
3007
|
+
throw new Error(`Feature ${event.event} not found`);
|
|
3008
|
+
const { input } = feature;
|
|
1888
3009
|
await this.validateFeatureDataInput(data, input, event.input, event_index, sequence_index);
|
|
1889
3010
|
}
|
|
1890
3011
|
async checkAndValidateNotificationDataInput(data, sequence_index, event, event_index) {
|
|
1891
|
-
const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = this.fetchNotificationMessage(event.event);
|
|
3012
|
+
const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = await this.fetchNotificationMessage(event.event);
|
|
1892
3013
|
await this.validateNotificationDataInput(data, { callback, notification, email, sms }, event.input, event_index, sequence_index);
|
|
1893
3014
|
}
|
|
1894
3015
|
async checkAndValidatePublishDataInput(data, sequence_index, event, event_index) {
|
|
1895
|
-
const topic = this.fetchMessageBrokerTopic(event.event);
|
|
3016
|
+
const topic = await this.fetchMessageBrokerTopic(event.event);
|
|
1896
3017
|
if (!topic) {
|
|
1897
3018
|
throw new Error(`Topic ${event.event} not registered`);
|
|
1898
3019
|
}
|
|
@@ -1900,14 +3021,14 @@ class ProductsBuilderService {
|
|
|
1900
3021
|
//await this.validatePublishTopicDataInput(data, { data: topicData }, event.input, event_index, sequence_index)
|
|
1901
3022
|
}
|
|
1902
3023
|
async checkAndValidateStorageDataInput(data, sequence_index, event, event_index) {
|
|
1903
|
-
const storage = this.fetchStorage(event.event);
|
|
3024
|
+
const storage = await this.fetchStorage(event.event);
|
|
1904
3025
|
if (!storage) {
|
|
1905
3026
|
throw new Error(`Storage ${event.event} does not exist`);
|
|
1906
3027
|
}
|
|
1907
3028
|
//await this.validateStorageDataInput(data, {}, event.input, event_index, sequence_index);
|
|
1908
3029
|
}
|
|
1909
3030
|
async checkAndValidateJobDataInput(data, sequence_index, event, event_index) {
|
|
1910
|
-
const job = this.fetchJob(event.event);
|
|
3031
|
+
const job = await this.fetchJob(event.event);
|
|
1911
3032
|
if (job.type === productsBuilder_types_1.JobEventTypes.ACTION) {
|
|
1912
3033
|
await this.checkAndValidateActionDataInput(data, sequence_index, event, event_index);
|
|
1913
3034
|
}
|
|
@@ -1923,9 +3044,6 @@ class ProductsBuilderService {
|
|
|
1923
3044
|
if (job.type === productsBuilder_types_1.JobEventTypes.PUBLISH) {
|
|
1924
3045
|
await this.checkAndValidatePublishDataInput(data, sequence_index, event, event_index);
|
|
1925
3046
|
}
|
|
1926
|
-
if (job.type === productsBuilder_types_1.JobEventTypes.FUNCTION) {
|
|
1927
|
-
await this.checkAndValidateFunctionDataInput(data, sequence_index, event, event_index);
|
|
1928
|
-
}
|
|
1929
3047
|
}
|
|
1930
3048
|
async checkAndValidateFallbackDataInput(data, sequence_index, event, event_index) { }
|
|
1931
3049
|
async validateEvent(data, sequence_index, event, event_index) {
|
|
@@ -1947,7 +3065,7 @@ class ProductsBuilderService {
|
|
|
1947
3065
|
await this.checkAndValidatePublishDataInput(data, sequence_index, event, event_index);
|
|
1948
3066
|
}
|
|
1949
3067
|
/*if (event.type === FeatureEventTypes.SUBSCRIBE) {
|
|
1950
|
-
const topic = this.fetchMessageBrokerTopic(event.event);
|
|
3068
|
+
const topic = await this.fetchMessageBrokerTopic(event.event);
|
|
1951
3069
|
|
|
1952
3070
|
if(!topic) {
|
|
1953
3071
|
throw new Error(`Topic ${event.event} not registered`);
|
|
@@ -2167,7 +3285,7 @@ class ProductsBuilderService {
|
|
|
2167
3285
|
throw new Error(`option event index ${optionIndex}, ${data.type} should not be ${obj}`);
|
|
2168
3286
|
}
|
|
2169
3287
|
}
|
|
2170
|
-
if (sequence &&
|
|
3288
|
+
if (sequence && Object.values(obj).length > 0 && ((_b = data.sample.data) === null || _b === void 0 ? void 0 : _b.length) === 0) {
|
|
2171
3289
|
if (!option) {
|
|
2172
3290
|
throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should be an empty object`);
|
|
2173
3291
|
}
|
|
@@ -2354,7 +3472,9 @@ class ProductsBuilderService {
|
|
|
2354
3472
|
let current_input = input;
|
|
2355
3473
|
for (let i = 0; i < stages.length; i++) {
|
|
2356
3474
|
let stage = stages[i];
|
|
2357
|
-
|
|
3475
|
+
// Convert to string for .match() call
|
|
3476
|
+
const stageStr = String(stage);
|
|
3477
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2358
3478
|
if (matches && matches.length === 2) {
|
|
2359
3479
|
const number = parseInt(matches[1], 10);
|
|
2360
3480
|
if (!isNaN(number)) {
|
|
@@ -2410,14 +3530,16 @@ class ProductsBuilderService {
|
|
|
2410
3530
|
}
|
|
2411
3531
|
else {
|
|
2412
3532
|
//const envs =
|
|
2413
|
-
const app = this.fetchApp(access_tag);
|
|
3533
|
+
const app = await this.fetchApp(access_tag);
|
|
2414
3534
|
const { envs } = app;
|
|
2415
3535
|
await Promise.all(envs.map((env) => {
|
|
2416
3536
|
if (stages[0] !== env.auth.auth_tag) {
|
|
2417
3537
|
throw new Error(`Auth ${stages[0]} does not exist on env ${env.product_env_slug} on app ${access_tag}`);
|
|
2418
3538
|
}
|
|
2419
|
-
const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.
|
|
2420
|
-
|
|
3539
|
+
const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.product.private_key));
|
|
3540
|
+
// Convert stages to string[] for findFaultyKeys
|
|
3541
|
+
const stringStages = stages.slice(1).map((stage) => String(stage));
|
|
3542
|
+
const check = (0, objects_utils_1.findFaultyKeys)(stringStages, decrypted);
|
|
2421
3543
|
if (check.faultyKeys) {
|
|
2422
3544
|
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}`);
|
|
2423
3545
|
}
|
|
@@ -2433,7 +3555,9 @@ class ProductsBuilderService {
|
|
|
2433
3555
|
let i = 1;
|
|
2434
3556
|
while (i < stages.length) {
|
|
2435
3557
|
let stage = stages[i];
|
|
2436
|
-
|
|
3558
|
+
// Convert to string for .match() call
|
|
3559
|
+
const stageStr = String(stage);
|
|
3560
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2437
3561
|
if (matches && matches.length === 2) {
|
|
2438
3562
|
const number = parseInt(matches[1], 10);
|
|
2439
3563
|
if (!isNaN(number)) {
|
|
@@ -2507,11 +3631,15 @@ class ProductsBuilderService {
|
|
|
2507
3631
|
// let current_data;
|
|
2508
3632
|
if (i === 0) {
|
|
2509
3633
|
// find sequence by tag, see if it exists and its before current sequence
|
|
2510
|
-
|
|
2511
|
-
|
|
3634
|
+
// Convert stage to string for function calls
|
|
3635
|
+
const stageStr = String(stage);
|
|
3636
|
+
this.validateSequenceInputParents(stageStr, meta.sequence_index, meta.feature.sequence);
|
|
3637
|
+
sequence = this.fetchPriorSequence(meta, stageStr);
|
|
2512
3638
|
}
|
|
2513
3639
|
if (i === 1 && sequence) {
|
|
2514
|
-
|
|
3640
|
+
// Convert stage to string for function calls
|
|
3641
|
+
const stageStr = String(stage);
|
|
3642
|
+
event = this.fetchSequenceEvent(sequence, stageStr);
|
|
2515
3643
|
if (!event) {
|
|
2516
3644
|
throw new Error(`event ${stage} not found in sequence ${sequence.tag}`);
|
|
2517
3645
|
}
|
|
@@ -2540,7 +3668,9 @@ class ProductsBuilderService {
|
|
|
2540
3668
|
if (i > 1 && response) {
|
|
2541
3669
|
let parent_index = 0;
|
|
2542
3670
|
let increment = false;
|
|
2543
|
-
|
|
3671
|
+
// Convert to string for .match() call
|
|
3672
|
+
const stageStr = String(stage);
|
|
3673
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2544
3674
|
if (matches && matches.length === 2) {
|
|
2545
3675
|
const number = parseInt(matches[1], 10);
|
|
2546
3676
|
if (!isNaN(number)) {
|
|
@@ -2598,7 +3728,7 @@ class ProductsBuilderService {
|
|
|
2598
3728
|
if (stages.length > 2) {
|
|
2599
3729
|
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`);
|
|
2600
3730
|
}
|
|
2601
|
-
const app = this.fetchApp(stages[0]);
|
|
3731
|
+
const app = await this.fetchApp(String(stages[0]));
|
|
2602
3732
|
if (!app) {
|
|
2603
3733
|
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}. `);
|
|
2604
3734
|
}
|
|
@@ -2615,8 +3745,8 @@ class ProductsBuilderService {
|
|
|
2615
3745
|
if (stages.length !== 2) {
|
|
2616
3746
|
throw new Error(`When using constants you need to specify the constant in the format $Constant{app_tag}{key} instead of ${value}`);
|
|
2617
3747
|
}
|
|
2618
|
-
const app_tag = stages[0];
|
|
2619
|
-
const key = stages[1];
|
|
3748
|
+
const app_tag = String(stages[0]);
|
|
3749
|
+
const key = String(stages[1]);
|
|
2620
3750
|
const _c = await this.fetchThirdPartyAppByAccessTag(app_tag), { version } = _c, app = __rest(_c, ["version"]);
|
|
2621
3751
|
if (!app) {
|
|
2622
3752
|
throw new Error(`App ${app_tag} not found in constant ${value}`);
|
|
@@ -2753,12 +3883,11 @@ class ProductsBuilderService {
|
|
|
2753
3883
|
}
|
|
2754
3884
|
async createFeature(data, throwErrorIfExists = false) {
|
|
2755
3885
|
try {
|
|
2756
|
-
if (!this.fetchFeature(data.tag
|
|
3886
|
+
if (!(await this.fetchFeature(data.tag))) {
|
|
2757
3887
|
await validators_1.CreateProductFeatureSchema.validateAsync(data);
|
|
2758
3888
|
try {
|
|
2759
3889
|
await this.validateFeatureData(data);
|
|
2760
3890
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2761
|
-
await this.initializeProduct(this.product_id);
|
|
2762
3891
|
}
|
|
2763
3892
|
catch (e) {
|
|
2764
3893
|
throw e;
|
|
@@ -2775,7 +3904,7 @@ class ProductsBuilderService {
|
|
|
2775
3904
|
}
|
|
2776
3905
|
async updateFeature(tag, data) {
|
|
2777
3906
|
try {
|
|
2778
|
-
const feature = this.fetchFeature(tag);
|
|
3907
|
+
const feature = await this.fetchFeature(tag);
|
|
2779
3908
|
if (!feature) {
|
|
2780
3909
|
throw new Error(`Feature ${tag} not found`);
|
|
2781
3910
|
}
|
|
@@ -2787,43 +3916,58 @@ class ProductsBuilderService {
|
|
|
2787
3916
|
}
|
|
2788
3917
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id,
|
|
2789
3918
|
tag }, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
2790
|
-
await this.initializeProduct(this.product_id);
|
|
2791
3919
|
}
|
|
2792
3920
|
catch (e) {
|
|
2793
3921
|
throw e;
|
|
2794
3922
|
}
|
|
2795
3923
|
}
|
|
2796
|
-
|
|
2797
|
-
const
|
|
2798
|
-
|
|
2799
|
-
throw new Error(`Feature ${tag} not found`);
|
|
2800
|
-
return feature;
|
|
3924
|
+
async fetchFeatures() {
|
|
3925
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'feature', this.getUserAccess());
|
|
3926
|
+
return components;
|
|
2801
3927
|
}
|
|
2802
|
-
|
|
2803
|
-
|
|
3928
|
+
async fetchFeature(tag) {
|
|
3929
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'feature', tag, this.getUserAccess());
|
|
3930
|
+
return component;
|
|
3931
|
+
}
|
|
3932
|
+
async deleteFeature(tag) {
|
|
3933
|
+
try {
|
|
3934
|
+
const feature = await this.fetchFeature(tag);
|
|
3935
|
+
if (!feature) {
|
|
3936
|
+
throw new Error(`Feature with tag: ${tag} not found`);
|
|
3937
|
+
}
|
|
3938
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
3939
|
+
tag,
|
|
3940
|
+
component: enums_1.ProductComponents.FEATURE,
|
|
3941
|
+
action: enums_1.RequestAction.DELETE,
|
|
3942
|
+
}, this.getUserAccess());
|
|
3943
|
+
}
|
|
3944
|
+
catch (e) {
|
|
3945
|
+
throw e;
|
|
3946
|
+
}
|
|
2804
3947
|
}
|
|
2805
3948
|
async createDatabase(data, throwErrorIfExists = false) {
|
|
2806
3949
|
try {
|
|
2807
3950
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
2808
|
-
if (!this.fetchDatabase(data.tag
|
|
3951
|
+
if (!(await this.fetchDatabase(data.tag))) {
|
|
2809
3952
|
await validators_1.CreateProductDatabaseSchema.validateAsync(data);
|
|
2810
|
-
|
|
2811
|
-
|
|
3953
|
+
const processedEnvs = [];
|
|
3954
|
+
for (const env of data.envs) {
|
|
3955
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2812
3956
|
if (!exists) {
|
|
2813
3957
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
2814
3958
|
}
|
|
2815
|
-
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.
|
|
2816
|
-
|
|
2817
|
-
}
|
|
2818
|
-
|
|
2819
|
-
envs.
|
|
3959
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
3960
|
+
processedEnvs.push(env);
|
|
3961
|
+
}
|
|
3962
|
+
data.envs = processedEnvs;
|
|
3963
|
+
const envs = await this.fetchEnvs();
|
|
3964
|
+
for (const env of envs) {
|
|
2820
3965
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
2821
3966
|
if (exists === -1) {
|
|
2822
3967
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
2823
3968
|
}
|
|
2824
|
-
}
|
|
3969
|
+
}
|
|
2825
3970
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.DATABASE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2826
|
-
await this.initializeProduct(this.product_id);
|
|
2827
3971
|
}
|
|
2828
3972
|
else {
|
|
2829
3973
|
if (throwErrorIfExists)
|
|
@@ -2836,7 +3980,7 @@ class ProductsBuilderService {
|
|
|
2836
3980
|
}
|
|
2837
3981
|
async updateDatabase(tag, data) {
|
|
2838
3982
|
try {
|
|
2839
|
-
const db = this.fetchDatabase(tag);
|
|
3983
|
+
const db = await this.fetchDatabase(tag);
|
|
2840
3984
|
if (!db) {
|
|
2841
3985
|
throw new Error(`Database ${tag} not found`);
|
|
2842
3986
|
}
|
|
@@ -2845,15 +3989,16 @@ class ProductsBuilderService {
|
|
|
2845
3989
|
if (data.tag && this.fetchDatabase(data.tag)) {
|
|
2846
3990
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
2847
3991
|
}
|
|
2848
|
-
data.envs = data.envs.map((env) => {
|
|
2849
|
-
const exists = this.fetchEnv(env.slug);
|
|
3992
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
3993
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2850
3994
|
if (!exists) {
|
|
2851
3995
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
2852
3996
|
}
|
|
2853
|
-
if (env.connection_url)
|
|
2854
|
-
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.
|
|
3997
|
+
if (env.connection_url) {
|
|
3998
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
3999
|
+
}
|
|
2855
4000
|
return env;
|
|
2856
|
-
});
|
|
4001
|
+
}));
|
|
2857
4002
|
const overwrite = [];
|
|
2858
4003
|
const newEnvs = [];
|
|
2859
4004
|
data.envs.map((dataEnv) => {
|
|
@@ -2882,23 +4027,348 @@ class ProductsBuilderService {
|
|
|
2882
4027
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
2883
4028
|
//console.log("UPDATED!!!", JSON.stringify(data.envs))
|
|
2884
4029
|
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());
|
|
2885
|
-
await this.initializeProduct(this.product_id);
|
|
2886
4030
|
}
|
|
2887
4031
|
catch (e) {
|
|
2888
4032
|
throw e;
|
|
2889
4033
|
}
|
|
2890
4034
|
}
|
|
2891
|
-
|
|
2892
|
-
const
|
|
2893
|
-
|
|
2894
|
-
|
|
4035
|
+
async fetchDatabases() {
|
|
4036
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'database', this.getUserAccess());
|
|
4037
|
+
const decryptedComponents = components.map((component) => {
|
|
4038
|
+
const dbComponent = component;
|
|
4039
|
+
const decryptedEnvs = dbComponent.envs.map((env) => {
|
|
4040
|
+
return Object.assign(Object.assign({}, env), { connection_url: (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key) });
|
|
4041
|
+
});
|
|
4042
|
+
return Object.assign(Object.assign({}, dbComponent), { envs: decryptedEnvs });
|
|
4043
|
+
});
|
|
4044
|
+
return decryptedComponents;
|
|
4045
|
+
}
|
|
4046
|
+
async fetchDatabase(tag) {
|
|
4047
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'database', tag, this.getUserAccess());
|
|
4048
|
+
if (component) {
|
|
4049
|
+
const decryptedEnvs = component.envs.map((env) => {
|
|
4050
|
+
return Object.assign(Object.assign({}, env), { connection_url: (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key) });
|
|
4051
|
+
});
|
|
4052
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
4053
|
+
}
|
|
4054
|
+
return component;
|
|
4055
|
+
}
|
|
4056
|
+
async deleteDatabase(tag) {
|
|
4057
|
+
try {
|
|
4058
|
+
const database = await this.fetchDatabase(tag);
|
|
4059
|
+
if (!database) {
|
|
4060
|
+
throw new Error(`Database with tag: ${tag} not found`);
|
|
4061
|
+
}
|
|
4062
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4063
|
+
tag,
|
|
4064
|
+
component: enums_1.ProductComponents.DATABASE,
|
|
4065
|
+
action: enums_1.RequestAction.DELETE,
|
|
4066
|
+
}, this.getUserAccess());
|
|
4067
|
+
}
|
|
4068
|
+
catch (e) {
|
|
4069
|
+
throw e;
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
4072
|
+
// GRAPH CRUD METHODS
|
|
4073
|
+
async createGraph(data, throwErrorIfExists = false) {
|
|
4074
|
+
var _a, _b, _c;
|
|
4075
|
+
console.log('[ProductsService.createGraph] Starting graph creation:', {
|
|
4076
|
+
tag: data.tag,
|
|
4077
|
+
name: data.name,
|
|
4078
|
+
type: data.type,
|
|
4079
|
+
envsCount: (_a = data.envs) === null || _a === void 0 ? void 0 : _a.length,
|
|
4080
|
+
productTag: (_b = this.product) === null || _b === void 0 ? void 0 : _b.tag,
|
|
4081
|
+
});
|
|
4082
|
+
try {
|
|
4083
|
+
if (!(await this.fetchGraph(data.tag))) {
|
|
4084
|
+
await validators_1.CreateProductGraphSchema.validateAsync(data);
|
|
4085
|
+
const processedEnvs = [];
|
|
4086
|
+
for (const env of data.envs) {
|
|
4087
|
+
console.log('[ProductsService.createGraph] Processing env:', {
|
|
4088
|
+
slug: env.slug,
|
|
4089
|
+
hasConnectionUrl: !!env.connection_url,
|
|
4090
|
+
hasUsername: !!env.username,
|
|
4091
|
+
hasPassword: !!env.password,
|
|
4092
|
+
});
|
|
4093
|
+
const exists = await this.fetchEnv(env.slug);
|
|
4094
|
+
if (!exists) {
|
|
4095
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
4096
|
+
}
|
|
4097
|
+
// Store connection URL as secret
|
|
4098
|
+
console.log('[ProductsService.createGraph] Converting connection URL to secret for env:', env.slug);
|
|
4099
|
+
const originalUrl = env.connection_url;
|
|
4100
|
+
env.connection_url = await this.storeGraphConnectionUrlAsSecret(env.connection_url, data.tag, env.slug);
|
|
4101
|
+
console.log('[ProductsService.createGraph] Connection URL after secret conversion:', {
|
|
4102
|
+
wasConverted: originalUrl !== env.connection_url,
|
|
4103
|
+
isSecretRef: (_c = env.connection_url) === null || _c === void 0 ? void 0 : _c.startsWith('$Secret{'),
|
|
4104
|
+
});
|
|
4105
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
4106
|
+
console.log('[ProductsService.createGraph] Connection URL encrypted');
|
|
4107
|
+
// Encrypt username and password if provided
|
|
4108
|
+
if (env.username) {
|
|
4109
|
+
console.log('[ProductsService.createGraph] Encrypting username for env:', env.slug);
|
|
4110
|
+
env.username = (0, processor_utils_1.encrypt)(env.username, this.product.private_key);
|
|
4111
|
+
}
|
|
4112
|
+
if (env.password) {
|
|
4113
|
+
console.log('[ProductsService.createGraph] Encrypting password for env:', env.slug);
|
|
4114
|
+
env.password = (0, processor_utils_1.encrypt)(env.password, this.product.private_key);
|
|
4115
|
+
}
|
|
4116
|
+
processedEnvs.push(env);
|
|
4117
|
+
console.log('[ProductsService.createGraph] Env processed successfully:', env.slug);
|
|
4118
|
+
}
|
|
4119
|
+
data.envs = processedEnvs;
|
|
4120
|
+
console.log('[ProductsService.createGraph] All envs processed, total:', processedEnvs.length);
|
|
4121
|
+
const envs = await this.fetchEnvs();
|
|
4122
|
+
for (const env of envs) {
|
|
4123
|
+
const exists = data.envs.findIndex((graphEnv) => graphEnv.slug === env.slug);
|
|
4124
|
+
if (exists === -1) {
|
|
4125
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
4126
|
+
}
|
|
4127
|
+
}
|
|
4128
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.GRAPH, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
4129
|
+
}
|
|
4130
|
+
else {
|
|
4131
|
+
if (throwErrorIfExists)
|
|
4132
|
+
throw new Error(`Graph ${data.tag} already exists`);
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4135
|
+
catch (e) {
|
|
4136
|
+
throw e;
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
4139
|
+
async updateGraph(tag, data) {
|
|
4140
|
+
var _a, _b;
|
|
4141
|
+
console.log('[ProductsService.updateGraph] Starting graph update:', {
|
|
4142
|
+
tag,
|
|
4143
|
+
newTag: data.tag,
|
|
4144
|
+
name: data.name,
|
|
4145
|
+
type: data.type,
|
|
4146
|
+
envsCount: (_a = data.envs) === null || _a === void 0 ? void 0 : _a.length,
|
|
4147
|
+
productTag: (_b = this.product) === null || _b === void 0 ? void 0 : _b.tag,
|
|
4148
|
+
});
|
|
4149
|
+
try {
|
|
4150
|
+
const graph = await this.fetchGraph(tag);
|
|
4151
|
+
if (!graph) {
|
|
4152
|
+
throw new Error(`Graph ${tag} not found`);
|
|
4153
|
+
}
|
|
4154
|
+
const { _id, envs } = graph;
|
|
4155
|
+
console.log('[ProductsService.updateGraph] Found existing graph:', {
|
|
4156
|
+
_id,
|
|
4157
|
+
existingEnvsCount: envs === null || envs === void 0 ? void 0 : envs.length,
|
|
4158
|
+
});
|
|
4159
|
+
await validators_1.UpdateProductGraphSchema.validateAsync(data);
|
|
4160
|
+
if (data.tag && this.fetchGraph(data.tag)) {
|
|
4161
|
+
throw new Error(`tag ${tag} is in use`);
|
|
4162
|
+
}
|
|
4163
|
+
console.log('[ProductsService.updateGraph] Processing envs update');
|
|
4164
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
4165
|
+
var _a;
|
|
4166
|
+
console.log('[ProductsService.updateGraph] Processing env:', {
|
|
4167
|
+
slug: env.slug,
|
|
4168
|
+
hasConnectionUrl: !!env.connection_url,
|
|
4169
|
+
hasUsername: !!env.username,
|
|
4170
|
+
hasPassword: !!env.password,
|
|
4171
|
+
});
|
|
4172
|
+
const exists = await this.fetchEnv(env.slug);
|
|
4173
|
+
if (!exists) {
|
|
4174
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
4175
|
+
}
|
|
4176
|
+
if (env.connection_url) {
|
|
4177
|
+
// Store connection URL as secret
|
|
4178
|
+
console.log('[ProductsService.updateGraph] Converting connection URL to secret for env:', env.slug);
|
|
4179
|
+
const originalUrl = env.connection_url;
|
|
4180
|
+
env.connection_url = await this.storeGraphConnectionUrlAsSecret(env.connection_url, data.tag || tag, env.slug);
|
|
4181
|
+
console.log('[ProductsService.updateGraph] Connection URL after secret conversion:', {
|
|
4182
|
+
wasConverted: originalUrl !== env.connection_url,
|
|
4183
|
+
isSecretRef: (_a = env.connection_url) === null || _a === void 0 ? void 0 : _a.startsWith('$Secret{'),
|
|
4184
|
+
});
|
|
4185
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
4186
|
+
console.log('[ProductsService.updateGraph] Connection URL encrypted');
|
|
4187
|
+
}
|
|
4188
|
+
// Encrypt username and password if provided
|
|
4189
|
+
if (env.username) {
|
|
4190
|
+
console.log('[ProductsService.updateGraph] Encrypting username for env:', env.slug);
|
|
4191
|
+
env.username = (0, processor_utils_1.encrypt)(env.username, this.product.private_key);
|
|
4192
|
+
}
|
|
4193
|
+
if (env.password) {
|
|
4194
|
+
console.log('[ProductsService.updateGraph] Encrypting password for env:', env.slug);
|
|
4195
|
+
env.password = (0, processor_utils_1.encrypt)(env.password, this.product.private_key);
|
|
4196
|
+
}
|
|
4197
|
+
console.log('[ProductsService.updateGraph] Env processed successfully:', env.slug);
|
|
4198
|
+
return env;
|
|
4199
|
+
}));
|
|
4200
|
+
const overwrite = [];
|
|
4201
|
+
const newEnvs = [];
|
|
4202
|
+
data.envs.map((dataEnv) => {
|
|
4203
|
+
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
4204
|
+
if (!this.fetchEnv(dataEnv.slug)) {
|
|
4205
|
+
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
4206
|
+
}
|
|
4207
|
+
if (exists === -1) {
|
|
4208
|
+
if (!dataEnv.connection_url) {
|
|
4209
|
+
throw new Error(`connection_url is required for new env ${data.envs[exists].slug}`);
|
|
4210
|
+
}
|
|
4211
|
+
newEnvs.push(dataEnv);
|
|
4212
|
+
}
|
|
4213
|
+
else {
|
|
4214
|
+
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
4215
|
+
}
|
|
4216
|
+
});
|
|
4217
|
+
const unchanged = [];
|
|
4218
|
+
envs.map((env) => {
|
|
4219
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
4220
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
4221
|
+
if (!newEnv && !overwriteEnv) {
|
|
4222
|
+
unchanged.push(env);
|
|
4223
|
+
}
|
|
4224
|
+
});
|
|
4225
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
4226
|
+
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());
|
|
4227
|
+
}
|
|
4228
|
+
catch (e) {
|
|
4229
|
+
throw e;
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
async fetchGraphs() {
|
|
4233
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'graph', this.getUserAccess());
|
|
4234
|
+
// Decrypt sensitive fields in graph envs
|
|
4235
|
+
const decryptedComponents = components.map((component) => {
|
|
4236
|
+
const graphComponent = component;
|
|
4237
|
+
const decryptedEnvs = graphComponent.envs.map((env) => {
|
|
4238
|
+
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 });
|
|
4239
|
+
});
|
|
4240
|
+
return Object.assign(Object.assign({}, graphComponent), { envs: decryptedEnvs });
|
|
2895
4241
|
});
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
4242
|
+
return decryptedComponents;
|
|
4243
|
+
}
|
|
4244
|
+
async fetchGraph(tag) {
|
|
4245
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'graph', tag, this.getUserAccess());
|
|
4246
|
+
if (component) {
|
|
4247
|
+
// Decrypt sensitive fields in graph envs
|
|
4248
|
+
const decryptedEnvs = component.envs.map((env) => {
|
|
4249
|
+
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 });
|
|
4250
|
+
});
|
|
4251
|
+
return Object.assign(Object.assign({}, component), { envs: decryptedEnvs });
|
|
4252
|
+
}
|
|
4253
|
+
return component;
|
|
4254
|
+
}
|
|
4255
|
+
async deleteGraph(tag) {
|
|
4256
|
+
try {
|
|
4257
|
+
const graph = await this.fetchGraph(tag);
|
|
4258
|
+
if (!graph) {
|
|
4259
|
+
throw new Error(`Graph with tag: ${tag} not found`);
|
|
4260
|
+
}
|
|
4261
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4262
|
+
tag,
|
|
4263
|
+
component: enums_1.ProductComponents.GRAPH,
|
|
4264
|
+
action: enums_1.RequestAction.DELETE,
|
|
4265
|
+
}, this.getUserAccess());
|
|
4266
|
+
}
|
|
4267
|
+
catch (e) {
|
|
4268
|
+
throw e;
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
// ==================== GRAPH ACTIONS ====================
|
|
4272
|
+
async createGraphAction(graphTag, data) {
|
|
4273
|
+
try {
|
|
4274
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4275
|
+
if (!graph) {
|
|
4276
|
+
throw new Error(`Graph with tag: ${graphTag} not found`);
|
|
4277
|
+
}
|
|
4278
|
+
// Initialize actions array if it doesn't exist
|
|
4279
|
+
if (!graph.actions) {
|
|
4280
|
+
graph.actions = [];
|
|
4281
|
+
}
|
|
4282
|
+
// Check if action already exists
|
|
4283
|
+
const existingAction = graph.actions.find((a) => a.tag === data.tag);
|
|
4284
|
+
if (existingAction) {
|
|
4285
|
+
throw new Error(`Action with tag: ${data.tag} already exists`);
|
|
4286
|
+
}
|
|
4287
|
+
graph.actions.push(data);
|
|
4288
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4289
|
+
tag: graphTag,
|
|
4290
|
+
actions: graph.actions,
|
|
4291
|
+
component: enums_1.ProductComponents.GRAPH,
|
|
4292
|
+
action: enums_1.RequestAction.UPDATE,
|
|
4293
|
+
}, this.getUserAccess());
|
|
4294
|
+
}
|
|
4295
|
+
catch (e) {
|
|
4296
|
+
throw e;
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
async updateGraphAction(graphTag, actionTag, data) {
|
|
4300
|
+
try {
|
|
4301
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4302
|
+
if (!graph) {
|
|
4303
|
+
throw new Error(`Graph with tag: ${graphTag} not found`);
|
|
4304
|
+
}
|
|
4305
|
+
if (!graph.actions) {
|
|
4306
|
+
throw new Error(`Action with tag: ${actionTag} not found`);
|
|
4307
|
+
}
|
|
4308
|
+
const actionIndex = graph.actions.findIndex((a) => a.tag === actionTag);
|
|
4309
|
+
if (actionIndex === -1) {
|
|
4310
|
+
throw new Error(`Action with tag: ${actionTag} not found`);
|
|
4311
|
+
}
|
|
4312
|
+
graph.actions[actionIndex] = Object.assign(Object.assign({}, graph.actions[actionIndex]), data);
|
|
4313
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4314
|
+
tag: graphTag,
|
|
4315
|
+
actions: graph.actions,
|
|
4316
|
+
component: enums_1.ProductComponents.GRAPH,
|
|
4317
|
+
action: enums_1.RequestAction.UPDATE,
|
|
4318
|
+
}, this.getUserAccess());
|
|
4319
|
+
}
|
|
4320
|
+
catch (e) {
|
|
4321
|
+
throw e;
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
async fetchGraphAction(graphTag, actionTag) {
|
|
4325
|
+
try {
|
|
4326
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4327
|
+
if (!graph || !graph.actions) {
|
|
4328
|
+
return null;
|
|
4329
|
+
}
|
|
4330
|
+
return graph.actions.find((a) => a.tag === actionTag) || null;
|
|
4331
|
+
}
|
|
4332
|
+
catch (e) {
|
|
4333
|
+
throw e;
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
async fetchGraphActions(graphTag) {
|
|
4337
|
+
try {
|
|
4338
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4339
|
+
if (!graph) {
|
|
4340
|
+
throw new Error(`Graph with tag: ${graphTag} not found`);
|
|
4341
|
+
}
|
|
4342
|
+
return graph.actions || [];
|
|
4343
|
+
}
|
|
4344
|
+
catch (e) {
|
|
4345
|
+
throw e;
|
|
4346
|
+
}
|
|
2899
4347
|
}
|
|
2900
|
-
|
|
2901
|
-
|
|
4348
|
+
async deleteGraphAction(graphTag, actionTag) {
|
|
4349
|
+
try {
|
|
4350
|
+
const graph = await this.fetchGraph(graphTag);
|
|
4351
|
+
if (!graph) {
|
|
4352
|
+
throw new Error(`Graph with tag: ${graphTag} not found`);
|
|
4353
|
+
}
|
|
4354
|
+
if (!graph.actions) {
|
|
4355
|
+
throw new Error(`Action with tag: ${actionTag} not found`);
|
|
4356
|
+
}
|
|
4357
|
+
const actionIndex = graph.actions.findIndex((a) => a.tag === actionTag);
|
|
4358
|
+
if (actionIndex === -1) {
|
|
4359
|
+
throw new Error(`Action with tag: ${actionTag} not found`);
|
|
4360
|
+
}
|
|
4361
|
+
graph.actions.splice(actionIndex, 1);
|
|
4362
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4363
|
+
tag: graphTag,
|
|
4364
|
+
actions: graph.actions,
|
|
4365
|
+
component: enums_1.ProductComponents.GRAPH,
|
|
4366
|
+
action: enums_1.RequestAction.UPDATE,
|
|
4367
|
+
}, this.getUserAccess());
|
|
4368
|
+
}
|
|
4369
|
+
catch (e) {
|
|
4370
|
+
throw e;
|
|
4371
|
+
}
|
|
2902
4372
|
}
|
|
2903
4373
|
async createDatabaseAction(data, throwErrorIfExists = false) {
|
|
2904
4374
|
try {
|
|
@@ -2909,10 +4379,10 @@ class ProductsBuilderService {
|
|
|
2909
4379
|
if (!databaseTag || !tag) {
|
|
2910
4380
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
2911
4381
|
}
|
|
2912
|
-
const exists = this.fetchDatabaseAction(data.tag);
|
|
4382
|
+
const exists = await this.fetchDatabaseAction(data.tag);
|
|
2913
4383
|
data.tag = tag;
|
|
2914
4384
|
if (!exists) {
|
|
2915
|
-
const database = this.fetchDatabase(databaseTag);
|
|
4385
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
2916
4386
|
let values, template;
|
|
2917
4387
|
if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
|
|
2918
4388
|
await create_productDatabaseAction_validator_1.NOSQLDatabaseActionsSchema.validateAsync(data);
|
|
@@ -2936,7 +4406,6 @@ class ProductsBuilderService {
|
|
|
2936
4406
|
}
|
|
2937
4407
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { data: values, template,
|
|
2938
4408
|
databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2939
|
-
await this.initializeProduct(this.product_id);
|
|
2940
4409
|
}
|
|
2941
4410
|
else {
|
|
2942
4411
|
if (throwErrorIfExists)
|
|
@@ -2947,7 +4416,7 @@ class ProductsBuilderService {
|
|
|
2947
4416
|
throw e;
|
|
2948
4417
|
}
|
|
2949
4418
|
}
|
|
2950
|
-
fetchDatabaseAction(tag, throwErrorIfExists = false) {
|
|
4419
|
+
async fetchDatabaseAction(tag, throwErrorIfExists = false) {
|
|
2951
4420
|
const [databaseTag, actionTag] = tag.split(':');
|
|
2952
4421
|
if (!databaseTag || !actionTag) {
|
|
2953
4422
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
@@ -2974,7 +4443,7 @@ class ProductsBuilderService {
|
|
|
2974
4443
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
2975
4444
|
}
|
|
2976
4445
|
// Fetch required data
|
|
2977
|
-
const database = await this.fetchDatabase(databaseTag
|
|
4446
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
2978
4447
|
const action = await this.fetchDatabaseAction(data.tag, true);
|
|
2979
4448
|
// Construct payload
|
|
2980
4449
|
const payload = Object.assign(Object.assign(Object.assign({}, action), data), { databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.UPDATE });
|
|
@@ -3002,13 +4471,12 @@ class ProductsBuilderService {
|
|
|
3002
4471
|
}
|
|
3003
4472
|
// Update product and reinitialize
|
|
3004
4473
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
3005
|
-
await this.initializeProduct(this.product_id);
|
|
3006
4474
|
}
|
|
3007
4475
|
catch (error) {
|
|
3008
4476
|
throw error;
|
|
3009
4477
|
}
|
|
3010
4478
|
}
|
|
3011
|
-
fetchDatabaseActions(databaseTag) {
|
|
4479
|
+
async fetchDatabaseActions(databaseTag) {
|
|
3012
4480
|
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
3013
4481
|
if (!database)
|
|
3014
4482
|
throw new Error(`Database ${databaseTag} not found`);
|
|
@@ -3020,6 +4488,27 @@ class ProductsBuilderService {
|
|
|
3020
4488
|
}
|
|
3021
4489
|
return actions;
|
|
3022
4490
|
}
|
|
4491
|
+
async deleteDatabaseAction(tag) {
|
|
4492
|
+
try {
|
|
4493
|
+
const [databaseTag, actionTag] = tag.split(':');
|
|
4494
|
+
if (!databaseTag || !actionTag) {
|
|
4495
|
+
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
4496
|
+
}
|
|
4497
|
+
const action = await this.fetchDatabaseAction(tag, true);
|
|
4498
|
+
if (!action) {
|
|
4499
|
+
throw new Error(`Database action with tag: ${tag} not found`);
|
|
4500
|
+
}
|
|
4501
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4502
|
+
tag: actionTag,
|
|
4503
|
+
databaseTag,
|
|
4504
|
+
component: enums_1.ProductComponents.DATABASE_ACTION,
|
|
4505
|
+
action: enums_1.RequestAction.DELETE,
|
|
4506
|
+
}, this.getUserAccess());
|
|
4507
|
+
}
|
|
4508
|
+
catch (e) {
|
|
4509
|
+
throw e;
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
3023
4512
|
async createDatabaseMigration(data, throwErrorIfExists) {
|
|
3024
4513
|
if (!data.tag) {
|
|
3025
4514
|
throw new Error('tag field is required');
|
|
@@ -3028,21 +4517,47 @@ class ProductsBuilderService {
|
|
|
3028
4517
|
if (!databaseTag || !tag) {
|
|
3029
4518
|
throw new Error(`tag is expected to be defined as "database_tag:migration_tag"`);
|
|
3030
4519
|
}
|
|
3031
|
-
const exists = this.fetchDatabaseMigration(data.tag);
|
|
4520
|
+
const exists = await this.fetchDatabaseMigration(data.tag);
|
|
3032
4521
|
data.tag = tag;
|
|
3033
|
-
await create_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag }));
|
|
4522
|
+
await create_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag }));
|
|
3034
4523
|
if (!exists) {
|
|
3035
|
-
const database = this.fetchDatabase(databaseTag
|
|
4524
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
3036
4525
|
if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
|
|
3037
4526
|
throw new Error(`${database.type} does not support migrations`);
|
|
3038
4527
|
}
|
|
3039
|
-
|
|
3040
|
-
|
|
4528
|
+
// Process migration value - supports both simple strings and rich operations
|
|
4529
|
+
let processedValue = data.value;
|
|
4530
|
+
if (data.value) {
|
|
4531
|
+
processedValue = {
|
|
4532
|
+
up: this.processMigrationOperations(data.value.up),
|
|
4533
|
+
down: this.processMigrationOperations(data.value.down),
|
|
4534
|
+
};
|
|
4535
|
+
}
|
|
4536
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { value: processedValue, databaseTag, component: enums_1.ProductComponents.DATABASE_MIGRATION }), this.getUserAccess());
|
|
3041
4537
|
}
|
|
3042
4538
|
else {
|
|
3043
4539
|
if (throwErrorIfExists)
|
|
3044
|
-
throw new Error(`Database
|
|
3045
|
-
}
|
|
4540
|
+
throw new Error(`Database Migration ${data.tag} already exists`);
|
|
4541
|
+
}
|
|
4542
|
+
}
|
|
4543
|
+
/**
|
|
4544
|
+
* Process migration operations - handles both string and object formats
|
|
4545
|
+
* Strings are passed through as-is (raw SQL/CQL)
|
|
4546
|
+
* Objects are serialized for storage and executed by the migration engine
|
|
4547
|
+
*/
|
|
4548
|
+
processMigrationOperations(operations) {
|
|
4549
|
+
if (!operations || !Array.isArray(operations))
|
|
4550
|
+
return [];
|
|
4551
|
+
return operations.map((op) => {
|
|
4552
|
+
if (typeof op === 'string') {
|
|
4553
|
+
return op; // Raw SQL/CQL string
|
|
4554
|
+
}
|
|
4555
|
+
// Rich operation object - validate it has required 'type' field
|
|
4556
|
+
if (typeof op === 'object' && op !== null && 'type' in op) {
|
|
4557
|
+
return op;
|
|
4558
|
+
}
|
|
4559
|
+
throw new Error(`Invalid migration operation format. Expected string or object with 'type' field.`);
|
|
4560
|
+
});
|
|
3046
4561
|
}
|
|
3047
4562
|
async updateDatabaseMigration(data) {
|
|
3048
4563
|
if (!data.tag) {
|
|
@@ -3052,16 +4567,23 @@ class ProductsBuilderService {
|
|
|
3052
4567
|
if (!databaseTag || !tag) {
|
|
3053
4568
|
throw new Error(`tag is expected to be defined as "database_tag:migration_tag"`);
|
|
3054
4569
|
}
|
|
3055
|
-
await update_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag }));
|
|
3056
|
-
const
|
|
3057
|
-
if (!
|
|
4570
|
+
await update_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag }));
|
|
4571
|
+
const existing = await this.fetchDatabaseMigration(data.tag);
|
|
4572
|
+
if (!existing) {
|
|
3058
4573
|
throw new Error(`Migration ${data.tag} not found`);
|
|
3059
4574
|
}
|
|
3060
4575
|
data.tag = tag;
|
|
3061
|
-
|
|
3062
|
-
|
|
4576
|
+
// Process migration value if provided - supports both simple strings and rich operations
|
|
4577
|
+
let processedValue = data.value;
|
|
4578
|
+
if (data.value) {
|
|
4579
|
+
processedValue = {
|
|
4580
|
+
up: this.processMigrationOperations(data.value.up),
|
|
4581
|
+
down: this.processMigrationOperations(data.value.down),
|
|
4582
|
+
};
|
|
4583
|
+
}
|
|
4584
|
+
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());
|
|
3063
4585
|
}
|
|
3064
|
-
fetchDatabaseMigration(tag, throwError = false) {
|
|
4586
|
+
async fetchDatabaseMigration(tag, throwError = false) {
|
|
3065
4587
|
const [databaseTag, migrationTag] = tag.split(':');
|
|
3066
4588
|
if (!databaseTag || !migrationTag) {
|
|
3067
4589
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
@@ -3074,13 +4596,126 @@ class ProductsBuilderService {
|
|
|
3074
4596
|
throw new Error(`Database migration ${tag} not found`);
|
|
3075
4597
|
return migration;
|
|
3076
4598
|
}
|
|
3077
|
-
fetchDatabaseMigrations(databaseTag) {
|
|
4599
|
+
async fetchDatabaseMigrations(databaseTag) {
|
|
3078
4600
|
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
3079
4601
|
if (!database)
|
|
3080
4602
|
throw new Error(`Database ${databaseTag} not found`);
|
|
3081
4603
|
const migrations = database.migrations;
|
|
3082
4604
|
return migrations;
|
|
3083
4605
|
}
|
|
4606
|
+
async deleteDatabaseMigration(tag) {
|
|
4607
|
+
try {
|
|
4608
|
+
const [databaseTag, migrationTag] = tag.split(':');
|
|
4609
|
+
if (!databaseTag || !migrationTag) {
|
|
4610
|
+
throw new Error(`tag is expected to be defined as "database_tag:migration_tag"`);
|
|
4611
|
+
}
|
|
4612
|
+
const migration = await this.fetchDatabaseMigration(tag, true);
|
|
4613
|
+
if (!migration) {
|
|
4614
|
+
throw new Error(`Database migration with tag: ${tag} not found`);
|
|
4615
|
+
}
|
|
4616
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4617
|
+
tag: migrationTag,
|
|
4618
|
+
databaseTag,
|
|
4619
|
+
component: enums_1.ProductComponents.DATABASE_MIGRATION,
|
|
4620
|
+
action: enums_1.RequestAction.DELETE,
|
|
4621
|
+
}, this.getUserAccess());
|
|
4622
|
+
}
|
|
4623
|
+
catch (e) {
|
|
4624
|
+
throw e;
|
|
4625
|
+
}
|
|
4626
|
+
}
|
|
4627
|
+
// ==================== DATABASE TRIGGER CRUD ====================
|
|
4628
|
+
async createDatabaseTrigger(data, throwErrorIfExists = false) {
|
|
4629
|
+
try {
|
|
4630
|
+
if (!data.tag) {
|
|
4631
|
+
throw new Error('tag field is required');
|
|
4632
|
+
}
|
|
4633
|
+
const [databaseTag, triggerTag] = data.tag.split(':');
|
|
4634
|
+
if (!databaseTag || !triggerTag) {
|
|
4635
|
+
throw new Error(`tag is expected to be defined as "database_tag:trigger_tag"`);
|
|
4636
|
+
}
|
|
4637
|
+
const exists = await this.fetchDatabaseTrigger(data.tag);
|
|
4638
|
+
if (exists) {
|
|
4639
|
+
if (throwErrorIfExists) {
|
|
4640
|
+
throw new Error(`Database trigger with tag: ${data.tag} already exists`);
|
|
4641
|
+
}
|
|
4642
|
+
return;
|
|
4643
|
+
}
|
|
4644
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
4645
|
+
if (!database) {
|
|
4646
|
+
throw new Error(`Database ${databaseTag} not found`);
|
|
4647
|
+
}
|
|
4648
|
+
// Initialize triggers array if not present
|
|
4649
|
+
if (!database.triggers) {
|
|
4650
|
+
database.triggers = [];
|
|
4651
|
+
}
|
|
4652
|
+
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());
|
|
4653
|
+
}
|
|
4654
|
+
catch (e) {
|
|
4655
|
+
throw e;
|
|
4656
|
+
}
|
|
4657
|
+
}
|
|
4658
|
+
async updateDatabaseTrigger(data) {
|
|
4659
|
+
try {
|
|
4660
|
+
if (!data.tag) {
|
|
4661
|
+
throw new Error('tag field is required');
|
|
4662
|
+
}
|
|
4663
|
+
const [databaseTag, triggerTag] = data.tag.split(':');
|
|
4664
|
+
if (!databaseTag || !triggerTag) {
|
|
4665
|
+
throw new Error(`tag is expected to be defined as "database_tag:trigger_tag"`);
|
|
4666
|
+
}
|
|
4667
|
+
const exists = await this.fetchDatabaseTrigger(data.tag, true);
|
|
4668
|
+
if (!exists) {
|
|
4669
|
+
throw new Error(`Database trigger with tag: ${data.tag} not found`);
|
|
4670
|
+
}
|
|
4671
|
+
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());
|
|
4672
|
+
}
|
|
4673
|
+
catch (e) {
|
|
4674
|
+
throw e;
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
async fetchDatabaseTrigger(tag, throwError = false) {
|
|
4678
|
+
const [databaseTag, triggerTag] = tag.split(':');
|
|
4679
|
+
if (!databaseTag || !triggerTag) {
|
|
4680
|
+
throw new Error(`tag is expected to be defined as "database_tag:trigger_tag"`);
|
|
4681
|
+
}
|
|
4682
|
+
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
4683
|
+
if (!database)
|
|
4684
|
+
throw new Error(`Database ${databaseTag} not found`);
|
|
4685
|
+
const triggers = database.triggers || [];
|
|
4686
|
+
const trigger = triggers.find((data) => data.tag === triggerTag);
|
|
4687
|
+
if (!trigger && throwError)
|
|
4688
|
+
throw new Error(`Database trigger ${tag} not found`);
|
|
4689
|
+
return trigger || null;
|
|
4690
|
+
}
|
|
4691
|
+
async fetchDatabaseTriggers(databaseTag) {
|
|
4692
|
+
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
4693
|
+
if (!database)
|
|
4694
|
+
throw new Error(`Database ${databaseTag} not found`);
|
|
4695
|
+
const triggers = database.triggers || [];
|
|
4696
|
+
return triggers;
|
|
4697
|
+
}
|
|
4698
|
+
async deleteDatabaseTrigger(tag) {
|
|
4699
|
+
try {
|
|
4700
|
+
const [databaseTag, triggerTag] = tag.split(':');
|
|
4701
|
+
if (!databaseTag || !triggerTag) {
|
|
4702
|
+
throw new Error(`tag is expected to be defined as "database_tag:trigger_tag"`);
|
|
4703
|
+
}
|
|
4704
|
+
const trigger = await this.fetchDatabaseTrigger(tag, true);
|
|
4705
|
+
if (!trigger) {
|
|
4706
|
+
throw new Error(`Database trigger with tag: ${tag} not found`);
|
|
4707
|
+
}
|
|
4708
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4709
|
+
tag: triggerTag,
|
|
4710
|
+
databaseTag,
|
|
4711
|
+
component: enums_1.ProductComponents.DATABASE_TRIGGER,
|
|
4712
|
+
action: enums_1.RequestAction.DELETE,
|
|
4713
|
+
}, this.getUserAccess());
|
|
4714
|
+
}
|
|
4715
|
+
catch (e) {
|
|
4716
|
+
throw e;
|
|
4717
|
+
}
|
|
4718
|
+
}
|
|
3084
4719
|
async validateJobEvent(data) {
|
|
3085
4720
|
const { type, app, event } = data;
|
|
3086
4721
|
if (type === productsBuilder_types_1.JobEventTypes.ACTION) {
|
|
@@ -3095,31 +4730,25 @@ class ProductsBuilderService {
|
|
|
3095
4730
|
}
|
|
3096
4731
|
}
|
|
3097
4732
|
if (type === productsBuilder_types_1.JobEventTypes.DATABASE_ACTION) {
|
|
3098
|
-
const found = this.fetchDatabaseAction(event);
|
|
4733
|
+
const found = await this.fetchDatabaseAction(event);
|
|
3099
4734
|
if (!found) {
|
|
3100
4735
|
throw new Error(`Database action ${event} not found`);
|
|
3101
4736
|
}
|
|
3102
4737
|
}
|
|
3103
|
-
if (type === productsBuilder_types_1.JobEventTypes.FUNCTION) {
|
|
3104
|
-
const found = this.fetchFunction(event);
|
|
3105
|
-
if (!found) {
|
|
3106
|
-
throw new Error(`Cloud function ${event} not found`);
|
|
3107
|
-
}
|
|
3108
|
-
}
|
|
3109
4738
|
if (type === productsBuilder_types_1.JobEventTypes.STORAGE) {
|
|
3110
|
-
const found = this.fetchStorage(event);
|
|
4739
|
+
const found = await this.fetchStorage(event);
|
|
3111
4740
|
if (!found) {
|
|
3112
4741
|
throw new Error(`Storage ${event} not found`);
|
|
3113
4742
|
}
|
|
3114
4743
|
}
|
|
3115
4744
|
if (type === productsBuilder_types_1.JobEventTypes.NOTIFICATION) {
|
|
3116
|
-
const found = this.fetchNotification(event);
|
|
4745
|
+
const found = await this.fetchNotification(event);
|
|
3117
4746
|
if (!found) {
|
|
3118
4747
|
throw new Error(`Notification ${event} not found`);
|
|
3119
4748
|
}
|
|
3120
4749
|
}
|
|
3121
4750
|
if (type === productsBuilder_types_1.JobEventTypes.PUBLISH) {
|
|
3122
|
-
const found = this.fetchMessageBroker(event);
|
|
4751
|
+
const found = await this.fetchMessageBroker(event);
|
|
3123
4752
|
if (!found) {
|
|
3124
4753
|
throw new Error(`Message Broker ${event} not found`);
|
|
3125
4754
|
}
|
|
@@ -3128,7 +4757,7 @@ class ProductsBuilderService {
|
|
|
3128
4757
|
async createJob(data, throwErrorIfExists = false) {
|
|
3129
4758
|
try {
|
|
3130
4759
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
3131
|
-
if (!this.fetchJob(data.tag)) {
|
|
4760
|
+
if (!(await this.fetchJob(data.tag))) {
|
|
3132
4761
|
await validators_1.CreateProductJobSchema.validateAsync(data);
|
|
3133
4762
|
await this.validateJobEvent(data);
|
|
3134
4763
|
if (data.type === productsBuilder_types_1.JobEventTypes.ACTION) {
|
|
@@ -3150,7 +4779,6 @@ class ProductsBuilderService {
|
|
|
3150
4779
|
const dbAction = await this.fetchDatabaseAction(data.event);
|
|
3151
4780
|
}
|
|
3152
4781
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.JOB, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
3153
|
-
await this.initializeProduct(this.product_id);
|
|
3154
4782
|
}
|
|
3155
4783
|
else {
|
|
3156
4784
|
if (throwErrorIfExists)
|
|
@@ -3173,20 +4801,111 @@ class ProductsBuilderService {
|
|
|
3173
4801
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
3174
4802
|
}
|
|
3175
4803
|
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());
|
|
3176
|
-
await this.initializeProduct(this.product_id);
|
|
3177
4804
|
}
|
|
3178
4805
|
catch (e) {
|
|
3179
4806
|
throw e;
|
|
3180
4807
|
}
|
|
3181
4808
|
}
|
|
3182
|
-
|
|
3183
|
-
const
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
4809
|
+
async fetchJobs() {
|
|
4810
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'job', this.getUserAccess());
|
|
4811
|
+
return components;
|
|
4812
|
+
}
|
|
4813
|
+
async fetchJob(tag) {
|
|
4814
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'job', tag, this.getUserAccess());
|
|
4815
|
+
return component;
|
|
4816
|
+
}
|
|
4817
|
+
async deleteJob(tag) {
|
|
4818
|
+
try {
|
|
4819
|
+
const job = await this.fetchJob(tag);
|
|
4820
|
+
if (!job) {
|
|
4821
|
+
throw new Error(`Job with tag: ${tag} not found`);
|
|
4822
|
+
}
|
|
4823
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4824
|
+
tag,
|
|
4825
|
+
component: enums_1.ProductComponents.JOB,
|
|
4826
|
+
action: enums_1.RequestAction.DELETE,
|
|
4827
|
+
}, this.getUserAccess());
|
|
4828
|
+
}
|
|
4829
|
+
catch (e) {
|
|
4830
|
+
throw e;
|
|
4831
|
+
}
|
|
4832
|
+
}
|
|
4833
|
+
// ==================== WORKFLOW CRUD METHODS ====================
|
|
4834
|
+
async createWorkflow(data, throwErrorIfExists = false) {
|
|
4835
|
+
try {
|
|
4836
|
+
if (!(await this.fetchWorkflow(data.tag))) {
|
|
4837
|
+
// Validate required fields
|
|
4838
|
+
if (!data.name || !data.tag) {
|
|
4839
|
+
throw new Error('Workflow requires name and tag');
|
|
4840
|
+
}
|
|
4841
|
+
// Validate envs if provided
|
|
4842
|
+
if (data.envs && data.envs.length > 0) {
|
|
4843
|
+
for (const env of data.envs) {
|
|
4844
|
+
const exists = await this.fetchEnv(env.slug);
|
|
4845
|
+
if (!exists) {
|
|
4846
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
4847
|
+
}
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4850
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.WORKFLOW, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
4851
|
+
}
|
|
4852
|
+
else {
|
|
4853
|
+
if (throwErrorIfExists)
|
|
4854
|
+
throw new Error(`Workflow ${data.tag} already exists`);
|
|
4855
|
+
}
|
|
4856
|
+
}
|
|
4857
|
+
catch (e) {
|
|
4858
|
+
throw e;
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
async updateWorkflow(tag, data) {
|
|
4862
|
+
try {
|
|
4863
|
+
const workflow = await this.fetchWorkflow(tag);
|
|
4864
|
+
if (!workflow) {
|
|
4865
|
+
throw new Error(`Workflow ${tag} not found`);
|
|
4866
|
+
}
|
|
4867
|
+
const { _id } = workflow;
|
|
4868
|
+
if (data.tag && data.tag !== tag && (await this.fetchWorkflow(data.tag))) {
|
|
4869
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
4870
|
+
}
|
|
4871
|
+
// Validate envs if provided
|
|
4872
|
+
if (data.envs && data.envs.length > 0) {
|
|
4873
|
+
for (const env of data.envs) {
|
|
4874
|
+
const exists = await this.fetchEnv(env.slug);
|
|
4875
|
+
if (!exists) {
|
|
4876
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
}
|
|
4880
|
+
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());
|
|
4881
|
+
}
|
|
4882
|
+
catch (e) {
|
|
4883
|
+
throw e;
|
|
4884
|
+
}
|
|
4885
|
+
}
|
|
4886
|
+
async fetchWorkflows() {
|
|
4887
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'workflow', this.getUserAccess());
|
|
4888
|
+
return components;
|
|
3187
4889
|
}
|
|
3188
|
-
|
|
3189
|
-
|
|
4890
|
+
async fetchWorkflow(tag) {
|
|
4891
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'workflow', tag, this.getUserAccess());
|
|
4892
|
+
return component;
|
|
4893
|
+
}
|
|
4894
|
+
async deleteWorkflow(tag) {
|
|
4895
|
+
try {
|
|
4896
|
+
const workflow = await this.fetchWorkflow(tag);
|
|
4897
|
+
if (!workflow) {
|
|
4898
|
+
throw new Error(`Workflow with tag: ${tag} not found`);
|
|
4899
|
+
}
|
|
4900
|
+
await this.productApi.updateProduct(this.product_id, {
|
|
4901
|
+
tag,
|
|
4902
|
+
component: enums_1.ProductComponents.WORKFLOW,
|
|
4903
|
+
action: enums_1.RequestAction.DELETE,
|
|
4904
|
+
}, this.getUserAccess());
|
|
4905
|
+
}
|
|
4906
|
+
catch (e) {
|
|
4907
|
+
throw e;
|
|
4908
|
+
}
|
|
3190
4909
|
}
|
|
3191
4910
|
getUserAccess() {
|
|
3192
4911
|
return {
|
|
@@ -3194,11 +4913,776 @@ class ProductsBuilderService {
|
|
|
3194
4913
|
workspace_id: this.workspace_id,
|
|
3195
4914
|
token: this.token,
|
|
3196
4915
|
public_key: this.public_key,
|
|
4916
|
+
access_key: this.access_key,
|
|
3197
4917
|
};
|
|
3198
4918
|
}
|
|
3199
4919
|
async fetchSessionUser(ductape_user_id) {
|
|
3200
4920
|
return await this.productApi.fetchProductSessionUser(ductape_user_id, this.getUserAccess());
|
|
3201
4921
|
}
|
|
4922
|
+
/**
|
|
4923
|
+
* Process storage config to store sensitive credentials as secrets
|
|
4924
|
+
* Format: STORAGE_{PRODUCT}_{STORAGE_TAG}_{ENV}_{KEY}
|
|
4925
|
+
*
|
|
4926
|
+
* Product parsing: split by ":", select first element
|
|
4927
|
+
* Storage tag: replace "-" with "_"
|
|
4928
|
+
*/
|
|
4929
|
+
async processStorageConfigSecrets(config, providerType, storageTag, envSlug) {
|
|
4930
|
+
console.log(`[Storage Secrets] Processing secrets for storage: ${storageTag}, env: ${envSlug}, provider: ${providerType}`);
|
|
4931
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
4932
|
+
if (!secretsService) {
|
|
4933
|
+
console.log(`[Storage Secrets] No secrets service available, skipping secret storage`);
|
|
4934
|
+
return config;
|
|
4935
|
+
}
|
|
4936
|
+
const generateSecretKey = (keyName) => {
|
|
4937
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
4938
|
+
const productParts = this.product.tag.split(':');
|
|
4939
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
4940
|
+
const storageKey = storageTag.replace(/-/g, '_');
|
|
4941
|
+
const key = `STORAGE_${sanitize(productKey)}_${sanitize(storageKey)}_${sanitize(envSlug)}_${sanitize(keyName)}`;
|
|
4942
|
+
console.log(`[Storage Secrets] Generated secret key: ${key}`);
|
|
4943
|
+
return key;
|
|
4944
|
+
};
|
|
4945
|
+
const storeAsSecret = async (value, keyName) => {
|
|
4946
|
+
const secretCheck = (0, secrets_1.isSecretReference)(value);
|
|
4947
|
+
if (secretCheck.isSecret) {
|
|
4948
|
+
console.log(`[Storage Secrets] ${keyName} is already a secret reference, skipping`);
|
|
4949
|
+
return value; // Already a secret reference
|
|
4950
|
+
}
|
|
4951
|
+
const secretKey = generateSecretKey(keyName);
|
|
4952
|
+
try {
|
|
4953
|
+
const exists = await secretsService.exists(secretKey);
|
|
4954
|
+
if (exists) {
|
|
4955
|
+
console.log(`[Storage Secrets] Updating existing secret: ${secretKey}`);
|
|
4956
|
+
await secretsService.update(secretKey, { value });
|
|
4957
|
+
}
|
|
4958
|
+
else {
|
|
4959
|
+
console.log(`[Storage Secrets] Creating new secret: ${secretKey}`);
|
|
4960
|
+
await secretsService.create({
|
|
4961
|
+
key: secretKey,
|
|
4962
|
+
value,
|
|
4963
|
+
description: `Storage ${keyName} for ${storageTag} in ${envSlug}`,
|
|
4964
|
+
scope: [this.product.tag, storageTag],
|
|
4965
|
+
envs: [envSlug],
|
|
4966
|
+
});
|
|
4967
|
+
}
|
|
4968
|
+
console.log(`[Storage Secrets] Successfully stored ${keyName} as secret: $Secret{${secretKey}}`);
|
|
4969
|
+
return `$Secret{${secretKey}}`;
|
|
4970
|
+
}
|
|
4971
|
+
catch (error) {
|
|
4972
|
+
console.warn(`[Storage Secrets] Failed to store storage credential as secret: ${error}`);
|
|
4973
|
+
return value;
|
|
4974
|
+
}
|
|
4975
|
+
};
|
|
4976
|
+
if (providerType === productsBuilder_types_1.StorageProviders.AWS) {
|
|
4977
|
+
console.log(`[Storage Secrets] Processing AWS S3 credentials`);
|
|
4978
|
+
const awsConfig = config;
|
|
4979
|
+
const result = Object.assign(Object.assign({}, awsConfig), { accessKeyId: await storeAsSecret(awsConfig.accessKeyId, 'ACCESS_KEY_ID'), secretAccessKey: await storeAsSecret(awsConfig.secretAccessKey, 'SECRET_ACCESS_KEY') });
|
|
4980
|
+
console.log(`[Storage Secrets] AWS S3 config processed successfully`);
|
|
4981
|
+
return result;
|
|
4982
|
+
}
|
|
4983
|
+
else if (providerType === productsBuilder_types_1.StorageProviders.GCP) {
|
|
4984
|
+
console.log(`[Storage Secrets] Processing GCP credentials`);
|
|
4985
|
+
const gcpConfig = config;
|
|
4986
|
+
if (gcpConfig.config) {
|
|
4987
|
+
const processedConfig = Object.assign({}, gcpConfig.config);
|
|
4988
|
+
// Store private_key_id as secret
|
|
4989
|
+
if (processedConfig.private_key_id) {
|
|
4990
|
+
processedConfig.private_key_id = await storeAsSecret(processedConfig.private_key_id, 'PRIVATE_KEY_ID');
|
|
4991
|
+
}
|
|
4992
|
+
// Store private_key as secret
|
|
4993
|
+
if (processedConfig.private_key) {
|
|
4994
|
+
processedConfig.private_key = await storeAsSecret(processedConfig.private_key, 'PRIVATE_KEY');
|
|
4995
|
+
}
|
|
4996
|
+
// Store client_email as secret
|
|
4997
|
+
if (processedConfig.client_email) {
|
|
4998
|
+
processedConfig.client_email = await storeAsSecret(processedConfig.client_email, 'CLIENT_EMAIL');
|
|
4999
|
+
}
|
|
5000
|
+
// Store client_id as secret
|
|
5001
|
+
if (processedConfig.client_id) {
|
|
5002
|
+
processedConfig.client_id = await storeAsSecret(processedConfig.client_id, 'CLIENT_ID');
|
|
5003
|
+
}
|
|
5004
|
+
const result = Object.assign(Object.assign({}, gcpConfig), { config: processedConfig });
|
|
5005
|
+
console.log(`[Storage Secrets] GCP config processed successfully`);
|
|
5006
|
+
console.log(`[Storage Secrets] Converted GCP config:`, JSON.stringify(result, null, 2));
|
|
5007
|
+
return result;
|
|
5008
|
+
}
|
|
5009
|
+
console.log(`[Storage Secrets] GCP config has no nested config, skipping`);
|
|
5010
|
+
return gcpConfig;
|
|
5011
|
+
}
|
|
5012
|
+
else if (providerType === productsBuilder_types_1.StorageProviders.AZURE) {
|
|
5013
|
+
console.log(`[Storage Secrets] Processing Azure Blob credentials`);
|
|
5014
|
+
const azureConfig = config;
|
|
5015
|
+
const result = Object.assign(Object.assign({}, azureConfig), { connectionString: await storeAsSecret(azureConfig.connectionString, 'CONNECTION_STRING') });
|
|
5016
|
+
console.log(`[Storage Secrets] Azure Blob config processed successfully`);
|
|
5017
|
+
return result;
|
|
5018
|
+
}
|
|
5019
|
+
console.log(`[Storage Secrets] Unknown provider type: ${providerType}, returning config as-is`);
|
|
5020
|
+
return config;
|
|
5021
|
+
}
|
|
5022
|
+
/**
|
|
5023
|
+
* Process message broker config to store sensitive credentials as secrets
|
|
5024
|
+
* Format: BROKER_{PRODUCT}_{BROKER_TAG}_{ENV}_{KEY}
|
|
5025
|
+
*
|
|
5026
|
+
* Product parsing: split by ":", select first element
|
|
5027
|
+
* Broker tag: replace "-" with "_"
|
|
5028
|
+
*/
|
|
5029
|
+
async processMessageBrokerConfigSecrets(config, brokerType, brokerTag, envSlug) {
|
|
5030
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
5031
|
+
const logPrefix = '[MessageBroker:Secrets]';
|
|
5032
|
+
console.log(`${logPrefix} Processing secrets for broker: ${brokerTag}, env: ${envSlug}, type: ${brokerType}`);
|
|
5033
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5034
|
+
if (!secretsService) {
|
|
5035
|
+
console.log(`${logPrefix} No secrets service available, skipping secret storage`);
|
|
5036
|
+
return config;
|
|
5037
|
+
}
|
|
5038
|
+
console.log(`${logPrefix} Secrets service available`);
|
|
5039
|
+
const generateSecretKey = (keyName) => {
|
|
5040
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5041
|
+
const productParts = this.product.tag.split(':');
|
|
5042
|
+
const productKey = productParts[1] || productParts[0];
|
|
5043
|
+
const brokerKey = brokerTag.replace(/-/g, '_');
|
|
5044
|
+
const key = `BROKER_${sanitize(productKey)}_${sanitize(brokerKey)}_${sanitize(envSlug)}_${sanitize(keyName)}`;
|
|
5045
|
+
console.log(`${logPrefix} Generated secret key: ${key}`);
|
|
5046
|
+
return key;
|
|
5047
|
+
};
|
|
5048
|
+
const storeAsSecret = async (value, keyName) => {
|
|
5049
|
+
console.log(`${logPrefix} Processing field: ${keyName}`);
|
|
5050
|
+
if (!value) {
|
|
5051
|
+
console.log(`${logPrefix} Field ${keyName} is empty, skipping`);
|
|
5052
|
+
return value;
|
|
5053
|
+
}
|
|
5054
|
+
const secretCheck = (0, secrets_1.isSecretReference)(value);
|
|
5055
|
+
if (secretCheck.isSecret) {
|
|
5056
|
+
console.log(`${logPrefix} Field ${keyName} is already a secret reference: ${value}`);
|
|
5057
|
+
return value;
|
|
5058
|
+
}
|
|
5059
|
+
const secretKey = generateSecretKey(keyName);
|
|
5060
|
+
console.log(`${logPrefix} Storing ${keyName} as secret with key: ${secretKey}`);
|
|
5061
|
+
try {
|
|
5062
|
+
const exists = await secretsService.exists(secretKey);
|
|
5063
|
+
console.log(`${logPrefix} Secret ${secretKey} exists: ${exists}`);
|
|
5064
|
+
if (exists) {
|
|
5065
|
+
console.log(`${logPrefix} Updating existing secret: ${secretKey}`);
|
|
5066
|
+
await secretsService.update(secretKey, { value });
|
|
5067
|
+
console.log(`${logPrefix} Secret ${secretKey} updated successfully`);
|
|
5068
|
+
}
|
|
5069
|
+
else {
|
|
5070
|
+
console.log(`${logPrefix} Creating new secret: ${secretKey}`);
|
|
5071
|
+
await secretsService.create({
|
|
5072
|
+
key: secretKey,
|
|
5073
|
+
value,
|
|
5074
|
+
description: `Message broker ${keyName} for ${brokerTag} in ${envSlug}`,
|
|
5075
|
+
scope: [this.product.tag, brokerTag],
|
|
5076
|
+
envs: [envSlug],
|
|
5077
|
+
});
|
|
5078
|
+
console.log(`${logPrefix} Secret ${secretKey} created successfully`);
|
|
5079
|
+
}
|
|
5080
|
+
const secretRef = `$Secret{${secretKey}}`;
|
|
5081
|
+
console.log(`${logPrefix} Field ${keyName} converted to secret reference: ${secretRef}`);
|
|
5082
|
+
return secretRef;
|
|
5083
|
+
}
|
|
5084
|
+
catch (error) {
|
|
5085
|
+
console.error(`${logPrefix} Failed to store ${keyName} as secret:`, error);
|
|
5086
|
+
console.warn(`${logPrefix} Returning original value for ${keyName}`);
|
|
5087
|
+
return value;
|
|
5088
|
+
}
|
|
5089
|
+
};
|
|
5090
|
+
// Handle different broker types - config is passed directly without wrapper
|
|
5091
|
+
console.log(`${logPrefix} Processing broker type: ${brokerType}`);
|
|
5092
|
+
if (brokerType === productsBuilder_types_1.MessageBrokerTypes.REDIS) {
|
|
5093
|
+
console.log(`${logPrefix} Redis config detected`);
|
|
5094
|
+
console.log(`${logPrefix} Redis fields - host: ${config.host}, port: ${config.port}, password: ${config.password ? '[SET]' : '[NOT SET]'}`);
|
|
5095
|
+
if (config.password) {
|
|
5096
|
+
config.password = await storeAsSecret(config.password, 'PASSWORD');
|
|
5097
|
+
}
|
|
5098
|
+
}
|
|
5099
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.RABBITMQ) {
|
|
5100
|
+
console.log(`${logPrefix} RabbitMQ config detected`);
|
|
5101
|
+
console.log(`${logPrefix} RabbitMQ fields - url: ${config.url ? '[SET]' : '[NOT SET]'}`);
|
|
5102
|
+
if (config.url) {
|
|
5103
|
+
config.url = await storeAsSecret(config.url, 'URL');
|
|
5104
|
+
}
|
|
5105
|
+
}
|
|
5106
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.KAFKA) {
|
|
5107
|
+
console.log(`${logPrefix} Kafka config detected`);
|
|
5108
|
+
console.log(`${logPrefix} Kafka fields - brokers: ${(_a = config.brokers) === null || _a === void 0 ? void 0 : _a.join(', ')}, clientId: ${config.clientId}, ssl: ${config.ssl}`);
|
|
5109
|
+
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]'}`);
|
|
5110
|
+
if ((_e = config.sasl) === null || _e === void 0 ? void 0 : _e.username) {
|
|
5111
|
+
config.sasl.username = await storeAsSecret(config.sasl.username, 'SASL_USERNAME');
|
|
5112
|
+
}
|
|
5113
|
+
if ((_f = config.sasl) === null || _f === void 0 ? void 0 : _f.password) {
|
|
5114
|
+
config.sasl.password = await storeAsSecret(config.sasl.password, 'SASL_PASSWORD');
|
|
5115
|
+
}
|
|
5116
|
+
}
|
|
5117
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.AWS_SQS) {
|
|
5118
|
+
console.log(`${logPrefix} AWS SQS config detected`);
|
|
5119
|
+
console.log(`${logPrefix} AWS SQS fields - region: ${config.region}, accessKeyId: ${config.accessKeyId ? '[SET]' : '[NOT SET]'}, secretAccessKey: ${config.secretAccessKey ? '[SET]' : '[NOT SET]'}`);
|
|
5120
|
+
if (config.accessKeyId) {
|
|
5121
|
+
config.accessKeyId = await storeAsSecret(config.accessKeyId, 'ACCESS_KEY_ID');
|
|
5122
|
+
}
|
|
5123
|
+
if (config.secretAccessKey) {
|
|
5124
|
+
config.secretAccessKey = await storeAsSecret(config.secretAccessKey, 'SECRET_ACCESS_KEY');
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5127
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.NATS) {
|
|
5128
|
+
console.log(`${logPrefix} NATS config detected`);
|
|
5129
|
+
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}`);
|
|
5130
|
+
if (config.token) {
|
|
5131
|
+
config.token = await storeAsSecret(config.token, 'TOKEN');
|
|
5132
|
+
}
|
|
5133
|
+
if (config.user) {
|
|
5134
|
+
config.user = await storeAsSecret(config.user, 'USER');
|
|
5135
|
+
}
|
|
5136
|
+
if (config.pass) {
|
|
5137
|
+
config.pass = await storeAsSecret(config.pass, 'PASSWORD');
|
|
5138
|
+
}
|
|
5139
|
+
}
|
|
5140
|
+
else if (brokerType === productsBuilder_types_1.MessageBrokerTypes.GOOGLE_PUBSUB) {
|
|
5141
|
+
console.log(`${logPrefix} Google Pub/Sub config detected`);
|
|
5142
|
+
console.log(`${logPrefix} Google Pub/Sub fields - projectId: ${config.projectId}, credentials: ${config.credentials ? '[SET]' : '[NOT SET]'}`);
|
|
5143
|
+
if (config.credentials) {
|
|
5144
|
+
console.log(`${logPrefix} Google Pub/Sub credentials - type: ${config.credentials.type}, project_id: ${config.credentials.project_id}`);
|
|
5145
|
+
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]'}`);
|
|
5146
|
+
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]'}`);
|
|
5147
|
+
if (config.credentials.private_key_id) {
|
|
5148
|
+
config.credentials.private_key_id = await storeAsSecret(config.credentials.private_key_id, 'PRIVATE_KEY_ID');
|
|
5149
|
+
}
|
|
5150
|
+
if (config.credentials.private_key) {
|
|
5151
|
+
config.credentials.private_key = await storeAsSecret(config.credentials.private_key, 'PRIVATE_KEY');
|
|
5152
|
+
}
|
|
5153
|
+
if (config.credentials.client_email) {
|
|
5154
|
+
config.credentials.client_email = await storeAsSecret(config.credentials.client_email, 'CLIENT_EMAIL');
|
|
5155
|
+
}
|
|
5156
|
+
if (config.credentials.client_id) {
|
|
5157
|
+
config.credentials.client_id = await storeAsSecret(config.credentials.client_id, 'CLIENT_ID');
|
|
5158
|
+
}
|
|
5159
|
+
}
|
|
5160
|
+
}
|
|
5161
|
+
else {
|
|
5162
|
+
console.log(`${logPrefix} Unknown broker type: ${brokerType}, no secrets processing`);
|
|
5163
|
+
}
|
|
5164
|
+
console.log(`${logPrefix} Secrets processing completed for ${brokerTag}:${envSlug}`);
|
|
5165
|
+
return config;
|
|
5166
|
+
}
|
|
5167
|
+
/**
|
|
5168
|
+
* Process notification environment config to store sensitive credentials as secrets
|
|
5169
|
+
* Format: NOTIFIER_{PRODUCT}_{NOTIFIER_TAG}_{ENV}_{KEY}
|
|
5170
|
+
*
|
|
5171
|
+
* Product parsing: split by ":", select first element
|
|
5172
|
+
* Notifier tag: replace "-" with "_"
|
|
5173
|
+
*/
|
|
5174
|
+
async processNotificationEnvSecrets(env, notifierTag, envSlug) {
|
|
5175
|
+
var _a, _b, _c, _d, _e;
|
|
5176
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5177
|
+
if (!secretsService) {
|
|
5178
|
+
return env;
|
|
5179
|
+
}
|
|
5180
|
+
const generateSecretKey = (keyName) => {
|
|
5181
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5182
|
+
// Support both ':' and '.' delimiters for product tags (e.g., 'ductape:rematch' or 'ductape.rematch')
|
|
5183
|
+
const productParts = this.product.tag.includes(':')
|
|
5184
|
+
? this.product.tag.split(':')
|
|
5185
|
+
: this.product.tag.split('.');
|
|
5186
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
5187
|
+
const workspace = productParts[0];
|
|
5188
|
+
// Support both ':' and '.' delimiters for notification tags
|
|
5189
|
+
const notifierParts = notifierTag.includes(':')
|
|
5190
|
+
? notifierTag.split(':')
|
|
5191
|
+
: notifierTag.split('.');
|
|
5192
|
+
let notifierKey;
|
|
5193
|
+
if (notifierParts.length > 1 && notifierParts[0] === workspace) {
|
|
5194
|
+
// Same workspace prefix, use second part
|
|
5195
|
+
notifierKey = notifierParts[1];
|
|
5196
|
+
}
|
|
5197
|
+
else {
|
|
5198
|
+
// Different or no prefix, use full tag
|
|
5199
|
+
notifierKey = notifierTag;
|
|
5200
|
+
}
|
|
5201
|
+
// Replace '-' with '_' for consistency with Storage/Message Broker pattern
|
|
5202
|
+
notifierKey = notifierKey.replace(/-/g, '_');
|
|
5203
|
+
return `NOTIFIER_${sanitize(productKey)}_${sanitize(notifierKey)}_${sanitize(envSlug)}_${sanitize(keyName)}`;
|
|
5204
|
+
};
|
|
5205
|
+
const storeAsSecret = async (value, keyName) => {
|
|
5206
|
+
if (!value)
|
|
5207
|
+
return value;
|
|
5208
|
+
const secretCheck = (0, secrets_1.isSecretReference)(value);
|
|
5209
|
+
if (secretCheck.isSecret) {
|
|
5210
|
+
return value; // Already a secret reference
|
|
5211
|
+
}
|
|
5212
|
+
const secretKey = generateSecretKey(keyName);
|
|
5213
|
+
try {
|
|
5214
|
+
const exists = await secretsService.exists(secretKey);
|
|
5215
|
+
if (exists) {
|
|
5216
|
+
await secretsService.update(secretKey, { value });
|
|
5217
|
+
}
|
|
5218
|
+
else {
|
|
5219
|
+
await secretsService.create({
|
|
5220
|
+
key: secretKey,
|
|
5221
|
+
value,
|
|
5222
|
+
description: `Notification ${keyName} for ${notifierTag} in ${envSlug}`,
|
|
5223
|
+
scope: [this.product.tag, notifierTag],
|
|
5224
|
+
envs: [envSlug],
|
|
5225
|
+
});
|
|
5226
|
+
}
|
|
5227
|
+
return `$Secret{${secretKey}}`;
|
|
5228
|
+
}
|
|
5229
|
+
catch (error) {
|
|
5230
|
+
console.warn(`Failed to store notification credential as secret: ${error}`);
|
|
5231
|
+
return value;
|
|
5232
|
+
}
|
|
5233
|
+
};
|
|
5234
|
+
const result = Object.assign({}, env);
|
|
5235
|
+
// Process email handler
|
|
5236
|
+
if (result.emails) {
|
|
5237
|
+
const emailUpdates = Object.assign({}, result.emails);
|
|
5238
|
+
// SMTP: auth.user and auth.pass
|
|
5239
|
+
if ((_a = result.emails.smtp) === null || _a === void 0 ? void 0 : _a.auth) {
|
|
5240
|
+
emailUpdates.smtp = Object.assign(Object.assign({}, result.emails.smtp), { auth: Object.assign(Object.assign({}, result.emails.smtp.auth), { user: result.emails.smtp.auth.user
|
|
5241
|
+
? await storeAsSecret(result.emails.smtp.auth.user, 'EMAIL_SMTP_USER')
|
|
5242
|
+
: result.emails.smtp.auth.user, pass: result.emails.smtp.auth.pass
|
|
5243
|
+
? await storeAsSecret(result.emails.smtp.auth.pass, 'EMAIL_PASSWORD')
|
|
5244
|
+
: result.emails.smtp.auth.pass }) });
|
|
5245
|
+
}
|
|
5246
|
+
// SendGrid: apiKey
|
|
5247
|
+
if ((_b = result.emails.sendgrid) === null || _b === void 0 ? void 0 : _b.apiKey) {
|
|
5248
|
+
emailUpdates.sendgrid = Object.assign(Object.assign({}, result.emails.sendgrid), { apiKey: await storeAsSecret(result.emails.sendgrid.apiKey, 'EMAIL_SENDGRID_API_KEY') });
|
|
5249
|
+
}
|
|
5250
|
+
// Mailgun: apiKey and domain (domain may contain sensitive info)
|
|
5251
|
+
if (result.emails.mailgun) {
|
|
5252
|
+
const mailgunUpdates = Object.assign({}, result.emails.mailgun);
|
|
5253
|
+
if (result.emails.mailgun.apiKey) {
|
|
5254
|
+
mailgunUpdates.apiKey = await storeAsSecret(result.emails.mailgun.apiKey, 'EMAIL_MAILGUN_API_KEY');
|
|
5255
|
+
}
|
|
5256
|
+
if (result.emails.mailgun.domain) {
|
|
5257
|
+
mailgunUpdates.domain = await storeAsSecret(result.emails.mailgun.domain, 'EMAIL_MAILGUN_DOMAIN');
|
|
5258
|
+
}
|
|
5259
|
+
emailUpdates.mailgun = mailgunUpdates;
|
|
5260
|
+
}
|
|
5261
|
+
// Postmark: serverToken
|
|
5262
|
+
if ((_c = result.emails.postmark) === null || _c === void 0 ? void 0 : _c.serverToken) {
|
|
5263
|
+
emailUpdates.postmark = Object.assign(Object.assign({}, result.emails.postmark), { serverToken: await storeAsSecret(result.emails.postmark.serverToken, 'EMAIL_POSTMARK_SERVER_TOKEN') });
|
|
5264
|
+
}
|
|
5265
|
+
// Brevo: apiKey
|
|
5266
|
+
if ((_d = result.emails.brevo) === null || _d === void 0 ? void 0 : _d.apiKey) {
|
|
5267
|
+
emailUpdates.brevo = Object.assign(Object.assign({}, result.emails.brevo), { apiKey: await storeAsSecret(result.emails.brevo.apiKey, 'EMAIL_BREVO_API_KEY') });
|
|
5268
|
+
}
|
|
5269
|
+
// Legacy SMTP format (for backward compatibility)
|
|
5270
|
+
if (result.emails.auth && !result.emails.smtp) {
|
|
5271
|
+
emailUpdates.auth = Object.assign(Object.assign({}, result.emails.auth), { user: result.emails.auth.user
|
|
5272
|
+
? await storeAsSecret(result.emails.auth.user, 'EMAIL_SMTP_USER')
|
|
5273
|
+
: result.emails.auth.user, pass: result.emails.auth.pass
|
|
5274
|
+
? await storeAsSecret(result.emails.auth.pass, 'EMAIL_PASSWORD')
|
|
5275
|
+
: result.emails.auth.pass });
|
|
5276
|
+
}
|
|
5277
|
+
result.emails = emailUpdates;
|
|
5278
|
+
}
|
|
5279
|
+
// Process SMS handler
|
|
5280
|
+
if (result.sms) {
|
|
5281
|
+
const smsUpdates = {};
|
|
5282
|
+
if (result.sms.authToken) {
|
|
5283
|
+
smsUpdates.authToken = await storeAsSecret(result.sms.authToken, 'SMS_AUTH_TOKEN');
|
|
5284
|
+
}
|
|
5285
|
+
if (result.sms.apiSecret) {
|
|
5286
|
+
smsUpdates.apiSecret = await storeAsSecret(result.sms.apiSecret, 'SMS_API_SECRET');
|
|
5287
|
+
}
|
|
5288
|
+
if (result.sms.apiKey) {
|
|
5289
|
+
smsUpdates.apiKey = await storeAsSecret(result.sms.apiKey, 'SMS_API_KEY');
|
|
5290
|
+
}
|
|
5291
|
+
if (result.sms.accountSid) {
|
|
5292
|
+
smsUpdates.accountSid = await storeAsSecret(result.sms.accountSid, 'SMS_ACCOUNT_SID');
|
|
5293
|
+
}
|
|
5294
|
+
result.sms = Object.assign(Object.assign({}, result.sms), smsUpdates);
|
|
5295
|
+
}
|
|
5296
|
+
// Process push notifications handler (Firebase credentials)
|
|
5297
|
+
if ((_e = result.push_notifications) === null || _e === void 0 ? void 0 : _e.credentials) {
|
|
5298
|
+
const creds = result.push_notifications.credentials;
|
|
5299
|
+
const updatedCreds = Object.assign({}, creds);
|
|
5300
|
+
// Store all Firebase credential fields as secrets
|
|
5301
|
+
if (creds.private_key) {
|
|
5302
|
+
updatedCreds.private_key = await storeAsSecret(creds.private_key, 'PUSH_PRIVATE_KEY');
|
|
5303
|
+
}
|
|
5304
|
+
if (creds.private_key_id) {
|
|
5305
|
+
updatedCreds.private_key_id = await storeAsSecret(creds.private_key_id, 'PUSH_PRIVATE_KEY_ID');
|
|
5306
|
+
}
|
|
5307
|
+
if (creds.client_email) {
|
|
5308
|
+
updatedCreds.client_email = await storeAsSecret(creds.client_email, 'PUSH_CLIENT_EMAIL');
|
|
5309
|
+
}
|
|
5310
|
+
if (creds.client_id) {
|
|
5311
|
+
updatedCreds.client_id = await storeAsSecret(creds.client_id, 'PUSH_CLIENT_ID');
|
|
5312
|
+
}
|
|
5313
|
+
if (creds.project_id) {
|
|
5314
|
+
updatedCreds.project_id = await storeAsSecret(creds.project_id, 'PUSH_PROJECT_ID');
|
|
5315
|
+
}
|
|
5316
|
+
result.push_notifications = Object.assign(Object.assign({}, result.push_notifications), { credentials: updatedCreds });
|
|
5317
|
+
// Store databaseUrl as secret if present
|
|
5318
|
+
if (result.push_notifications.databaseUrl) {
|
|
5319
|
+
result.push_notifications.databaseUrl = await storeAsSecret(result.push_notifications.databaseUrl, 'PUSH_DATABASE_URL');
|
|
5320
|
+
}
|
|
5321
|
+
}
|
|
5322
|
+
// Process callbacks handler (webhook configuration)
|
|
5323
|
+
// Cast to extended type: ICallbackHandler only has url/method/auth; runtime may include headers, query, params, body
|
|
5324
|
+
if (result.callbacks) {
|
|
5325
|
+
const callbacks = result.callbacks;
|
|
5326
|
+
const callbackUpdates = Object.assign({}, callbacks);
|
|
5327
|
+
// Store URL as secret (may contain sensitive paths or tokens)
|
|
5328
|
+
if (callbacks.url) {
|
|
5329
|
+
callbackUpdates.url = await storeAsSecret(callbacks.url, 'CALLBACK_URL');
|
|
5330
|
+
}
|
|
5331
|
+
// Process headers
|
|
5332
|
+
if (callbacks.headers) {
|
|
5333
|
+
const headers = callbacks.headers;
|
|
5334
|
+
const updatedHeaders = Object.assign({}, headers);
|
|
5335
|
+
// Store Authorization header as secret
|
|
5336
|
+
if (headers.Authorization) {
|
|
5337
|
+
updatedHeaders.Authorization = await storeAsSecret(headers.Authorization, 'CALLBACK_AUTHORIZATION');
|
|
5338
|
+
}
|
|
5339
|
+
// Store other common auth headers
|
|
5340
|
+
if (headers['X-API-Key']) {
|
|
5341
|
+
updatedHeaders['X-API-Key'] = await storeAsSecret(headers['X-API-Key'], 'CALLBACK_X_API_KEY');
|
|
5342
|
+
}
|
|
5343
|
+
if (headers['X-Api-Key']) {
|
|
5344
|
+
updatedHeaders['X-Api-Key'] = await storeAsSecret(headers['X-Api-Key'], 'CALLBACK_X_API_KEY');
|
|
5345
|
+
}
|
|
5346
|
+
if (headers['api-key']) {
|
|
5347
|
+
updatedHeaders['api-key'] = await storeAsSecret(headers['api-key'], 'CALLBACK_API_KEY');
|
|
5348
|
+
}
|
|
5349
|
+
if (headers['X-Auth-Token']) {
|
|
5350
|
+
updatedHeaders['X-Auth-Token'] = await storeAsSecret(headers['X-Auth-Token'], 'CALLBACK_X_AUTH_TOKEN');
|
|
5351
|
+
}
|
|
5352
|
+
if (headers['X-Access-Token']) {
|
|
5353
|
+
updatedHeaders['X-Access-Token'] = await storeAsSecret(headers['X-Access-Token'], 'CALLBACK_X_ACCESS_TOKEN');
|
|
5354
|
+
}
|
|
5355
|
+
callbackUpdates.headers = updatedHeaders;
|
|
5356
|
+
}
|
|
5357
|
+
// Process query parameters (may contain sensitive data)
|
|
5358
|
+
if (callbacks.query && typeof callbacks.query === 'object') {
|
|
5359
|
+
const query = callbacks.query;
|
|
5360
|
+
const updatedQuery = {};
|
|
5361
|
+
for (const [key, value] of Object.entries(query)) {
|
|
5362
|
+
// Store common sensitive query params as secrets
|
|
5363
|
+
if (key.toLowerCase().includes('token') ||
|
|
5364
|
+
key.toLowerCase().includes('key') ||
|
|
5365
|
+
key.toLowerCase().includes('secret') ||
|
|
5366
|
+
key.toLowerCase().includes('auth') ||
|
|
5367
|
+
key.toLowerCase().includes('password')) {
|
|
5368
|
+
updatedQuery[key] = await storeAsSecret(value, `CALLBACK_QUERY_${key.toUpperCase()}`);
|
|
5369
|
+
}
|
|
5370
|
+
else {
|
|
5371
|
+
updatedQuery[key] = value;
|
|
5372
|
+
}
|
|
5373
|
+
}
|
|
5374
|
+
callbackUpdates.query = updatedQuery;
|
|
5375
|
+
}
|
|
5376
|
+
// Process path parameters (may contain sensitive data)
|
|
5377
|
+
if (callbacks.params && typeof callbacks.params === 'object') {
|
|
5378
|
+
const params = callbacks.params;
|
|
5379
|
+
const updatedParams = {};
|
|
5380
|
+
for (const [key, value] of Object.entries(params)) {
|
|
5381
|
+
// Store common sensitive path params as secrets
|
|
5382
|
+
if (key.toLowerCase().includes('token') ||
|
|
5383
|
+
key.toLowerCase().includes('key') ||
|
|
5384
|
+
key.toLowerCase().includes('secret') ||
|
|
5385
|
+
key.toLowerCase().includes('auth') ||
|
|
5386
|
+
key.toLowerCase().includes('password')) {
|
|
5387
|
+
updatedParams[key] = await storeAsSecret(value, `CALLBACK_PARAMS_${key.toUpperCase()}`);
|
|
5388
|
+
}
|
|
5389
|
+
else {
|
|
5390
|
+
updatedParams[key] = value;
|
|
5391
|
+
}
|
|
5392
|
+
}
|
|
5393
|
+
callbackUpdates.params = updatedParams;
|
|
5394
|
+
}
|
|
5395
|
+
// Process body (may contain sensitive data - store entire body as secret if it's a string)
|
|
5396
|
+
if (callbacks.body) {
|
|
5397
|
+
if (typeof callbacks.body === 'string') {
|
|
5398
|
+
callbackUpdates.body = await storeAsSecret(callbacks.body, 'CALLBACK_BODY');
|
|
5399
|
+
}
|
|
5400
|
+
else if (typeof callbacks.body === 'object') {
|
|
5401
|
+
// If body is an object, check for sensitive fields
|
|
5402
|
+
const body = callbacks.body;
|
|
5403
|
+
const updatedBody = {};
|
|
5404
|
+
for (const [key, value] of Object.entries(body)) {
|
|
5405
|
+
if (typeof value === 'string' &&
|
|
5406
|
+
(key.toLowerCase().includes('token') ||
|
|
5407
|
+
key.toLowerCase().includes('key') ||
|
|
5408
|
+
key.toLowerCase().includes('secret') ||
|
|
5409
|
+
key.toLowerCase().includes('auth') ||
|
|
5410
|
+
key.toLowerCase().includes('password'))) {
|
|
5411
|
+
updatedBody[key] = await storeAsSecret(value, `CALLBACK_BODY_${key.toUpperCase()}`);
|
|
5412
|
+
}
|
|
5413
|
+
else {
|
|
5414
|
+
updatedBody[key] = value;
|
|
5415
|
+
}
|
|
5416
|
+
}
|
|
5417
|
+
callbackUpdates.body = updatedBody;
|
|
5418
|
+
}
|
|
5419
|
+
}
|
|
5420
|
+
result.callbacks = callbackUpdates;
|
|
5421
|
+
}
|
|
5422
|
+
return result;
|
|
5423
|
+
}
|
|
5424
|
+
/**
|
|
5425
|
+
* Store graph connection URL as a secret
|
|
5426
|
+
* Format: GRAPH_{PRODUCT}_{GRAPH_TAG}_{ENV}_URL
|
|
5427
|
+
*/
|
|
5428
|
+
async storeGraphConnectionUrlAsSecret(connectionUrl, graphTag, envSlug) {
|
|
5429
|
+
var _a;
|
|
5430
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Starting secret conversion:', {
|
|
5431
|
+
graphTag,
|
|
5432
|
+
envSlug,
|
|
5433
|
+
hasConnectionUrl: !!connectionUrl,
|
|
5434
|
+
connectionUrlLength: connectionUrl === null || connectionUrl === void 0 ? void 0 : connectionUrl.length,
|
|
5435
|
+
productTag: (_a = this.product) === null || _a === void 0 ? void 0 : _a.tag,
|
|
5436
|
+
});
|
|
5437
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5438
|
+
if (!secretsService) {
|
|
5439
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] No secrets service available, returning original value');
|
|
5440
|
+
return connectionUrl;
|
|
5441
|
+
}
|
|
5442
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secrets service is available');
|
|
5443
|
+
const secretCheck = (0, secrets_1.isSecretReference)(connectionUrl);
|
|
5444
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secret reference check:', {
|
|
5445
|
+
isSecret: secretCheck.isSecret,
|
|
5446
|
+
secretKey: secretCheck.isSecret ? secretCheck.key : null,
|
|
5447
|
+
});
|
|
5448
|
+
if (secretCheck.isSecret) {
|
|
5449
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Value is already a secret reference, returning as-is');
|
|
5450
|
+
return connectionUrl;
|
|
5451
|
+
}
|
|
5452
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5453
|
+
const productParts = this.product.tag.split(':');
|
|
5454
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
5455
|
+
const graphKey = graphTag.replace(/-/g, '_');
|
|
5456
|
+
const secretKey = `GRAPH_${sanitize(productKey)}_${sanitize(graphKey)}_${sanitize(envSlug)}_URL`;
|
|
5457
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Generated secret key:', {
|
|
5458
|
+
secretKey,
|
|
5459
|
+
productParts,
|
|
5460
|
+
productKey,
|
|
5461
|
+
graphKey,
|
|
5462
|
+
});
|
|
5463
|
+
try {
|
|
5464
|
+
const exists = await secretsService.exists(secretKey);
|
|
5465
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secret exists check:', { secretKey, exists });
|
|
5466
|
+
if (exists) {
|
|
5467
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Updating existing secret:', secretKey);
|
|
5468
|
+
await secretsService.update(secretKey, { value: connectionUrl });
|
|
5469
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secret updated successfully');
|
|
5470
|
+
}
|
|
5471
|
+
else {
|
|
5472
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Creating new secret:', {
|
|
5473
|
+
secretKey,
|
|
5474
|
+
description: `Graph connection URL for ${graphTag} in ${envSlug}`,
|
|
5475
|
+
scope: [this.product.tag, graphTag],
|
|
5476
|
+
envs: [envSlug],
|
|
5477
|
+
});
|
|
5478
|
+
await secretsService.create({
|
|
5479
|
+
key: secretKey,
|
|
5480
|
+
value: connectionUrl,
|
|
5481
|
+
description: `Graph connection URL for ${graphTag} in ${envSlug}`,
|
|
5482
|
+
scope: [this.product.tag, graphTag],
|
|
5483
|
+
envs: [envSlug],
|
|
5484
|
+
});
|
|
5485
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Secret created successfully');
|
|
5486
|
+
}
|
|
5487
|
+
const secretRef = `$Secret{${secretKey}}`;
|
|
5488
|
+
console.log('[ProductsService.storeGraphConnectionUrlAsSecret] Returning secret reference:', secretRef);
|
|
5489
|
+
return secretRef;
|
|
5490
|
+
}
|
|
5491
|
+
catch (error) {
|
|
5492
|
+
console.error('[ProductsService.storeGraphConnectionUrlAsSecret] Failed to store secret:', {
|
|
5493
|
+
secretKey,
|
|
5494
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5495
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
5496
|
+
});
|
|
5497
|
+
return connectionUrl;
|
|
5498
|
+
}
|
|
5499
|
+
}
|
|
5500
|
+
/**
|
|
5501
|
+
* Generate a secret key for vector configuration field
|
|
5502
|
+
* Format: VECTOR_{PRODUCT}_{ASSET_TAG}_{ENV}_{KEY}
|
|
5503
|
+
*
|
|
5504
|
+
* Where:
|
|
5505
|
+
* - PRODUCT = productTag.split('.')[1] (second part after workspace)
|
|
5506
|
+
* - ASSET_TAG = if vectorTag starts with same workspace prefix, use second part; otherwise sanitize full tag
|
|
5507
|
+
* - All parts are automatically capitalized
|
|
5508
|
+
*/
|
|
5509
|
+
generateVectorSecretKey(vectorTag, envSlug, field) {
|
|
5510
|
+
var _a;
|
|
5511
|
+
console.log('[ProductsService.generateVectorSecretKey] Generating secret key:', {
|
|
5512
|
+
vectorTag,
|
|
5513
|
+
envSlug,
|
|
5514
|
+
field,
|
|
5515
|
+
productTag: (_a = this.product) === null || _a === void 0 ? void 0 : _a.tag,
|
|
5516
|
+
});
|
|
5517
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5518
|
+
// Support both ':' and '.' delimiters for product tags (e.g., 'ductape:rematch' or 'ductape.rematch')
|
|
5519
|
+
const productParts = this.product.tag.includes(':')
|
|
5520
|
+
? this.product.tag.split(':')
|
|
5521
|
+
: this.product.tag.split('.');
|
|
5522
|
+
const product = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
5523
|
+
const workspace = productParts[0];
|
|
5524
|
+
console.log('[ProductsService.generateVectorSecretKey] Product parsing:', {
|
|
5525
|
+
productParts,
|
|
5526
|
+
product,
|
|
5527
|
+
workspace,
|
|
5528
|
+
});
|
|
5529
|
+
// Support both ':' and '.' delimiters for vector tags
|
|
5530
|
+
const vectorParts = vectorTag.includes(':') ? vectorTag.split(':') : vectorTag.split('.');
|
|
5531
|
+
let assetTag;
|
|
5532
|
+
if (vectorParts.length > 1 && vectorParts[0] === workspace) {
|
|
5533
|
+
// Same workspace prefix, use second part
|
|
5534
|
+
assetTag = vectorParts[1];
|
|
5535
|
+
console.log('[ProductsService.generateVectorSecretKey] Using second part of vectorTag:', assetTag);
|
|
5536
|
+
}
|
|
5537
|
+
else {
|
|
5538
|
+
// Different or no prefix, use full tag
|
|
5539
|
+
assetTag = vectorTag;
|
|
5540
|
+
console.log('[ProductsService.generateVectorSecretKey] Using full vectorTag:', assetTag);
|
|
5541
|
+
}
|
|
5542
|
+
const secretKey = `VECTOR_${sanitize(product)}_${sanitize(assetTag)}_${sanitize(envSlug)}_${sanitize(field)}`;
|
|
5543
|
+
console.log('[ProductsService.generateVectorSecretKey] Generated secret key:', secretKey);
|
|
5544
|
+
return secretKey;
|
|
5545
|
+
}
|
|
5546
|
+
/**
|
|
5547
|
+
* Store a vector field value as a secret if it exists and is not already a secret reference
|
|
5548
|
+
* @returns The secret reference if stored, or the original value
|
|
5549
|
+
*/
|
|
5550
|
+
async storeVectorFieldAsSecret(value, vectorTag, envSlug, fieldName, description) {
|
|
5551
|
+
var _a;
|
|
5552
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Starting secret conversion:', {
|
|
5553
|
+
vectorTag,
|
|
5554
|
+
envSlug,
|
|
5555
|
+
fieldName,
|
|
5556
|
+
hasValue: !!value,
|
|
5557
|
+
valueLength: value === null || value === void 0 ? void 0 : value.length,
|
|
5558
|
+
productTag: (_a = this.product) === null || _a === void 0 ? void 0 : _a.tag,
|
|
5559
|
+
});
|
|
5560
|
+
if (!value) {
|
|
5561
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] No value provided, returning undefined');
|
|
5562
|
+
return undefined;
|
|
5563
|
+
}
|
|
5564
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5565
|
+
if (!secretsService) {
|
|
5566
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] No secrets service available, returning original value');
|
|
5567
|
+
return value;
|
|
5568
|
+
}
|
|
5569
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secrets service is available');
|
|
5570
|
+
const secretCheck = (0, secrets_1.isSecretReference)(value);
|
|
5571
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secret reference check:', {
|
|
5572
|
+
isSecret: secretCheck.isSecret,
|
|
5573
|
+
secretKey: secretCheck.isSecret ? secretCheck.key : null,
|
|
5574
|
+
});
|
|
5575
|
+
if (secretCheck.isSecret) {
|
|
5576
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Value is already a secret reference, returning as-is');
|
|
5577
|
+
return value;
|
|
5578
|
+
}
|
|
5579
|
+
const secretKey = this.generateVectorSecretKey(vectorTag, envSlug, fieldName);
|
|
5580
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Generated secret key:', secretKey);
|
|
5581
|
+
try {
|
|
5582
|
+
const exists = await secretsService.exists(secretKey);
|
|
5583
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secret exists check:', { secretKey, exists });
|
|
5584
|
+
if (exists) {
|
|
5585
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Updating existing secret:', secretKey);
|
|
5586
|
+
await secretsService.update(secretKey, { value });
|
|
5587
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secret updated successfully');
|
|
5588
|
+
}
|
|
5589
|
+
else {
|
|
5590
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Creating new secret:', {
|
|
5591
|
+
secretKey,
|
|
5592
|
+
description,
|
|
5593
|
+
scope: [this.product.tag, vectorTag],
|
|
5594
|
+
envs: [envSlug],
|
|
5595
|
+
});
|
|
5596
|
+
await secretsService.create({
|
|
5597
|
+
key: secretKey,
|
|
5598
|
+
value,
|
|
5599
|
+
description,
|
|
5600
|
+
scope: [this.product.tag, vectorTag],
|
|
5601
|
+
envs: [envSlug],
|
|
5602
|
+
});
|
|
5603
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Secret created successfully');
|
|
5604
|
+
}
|
|
5605
|
+
const secretRef = `$Secret{${secretKey}}`;
|
|
5606
|
+
console.log('[ProductsService.storeVectorFieldAsSecret] Returning secret reference:', secretRef);
|
|
5607
|
+
return secretRef;
|
|
5608
|
+
}
|
|
5609
|
+
catch (error) {
|
|
5610
|
+
console.error('[ProductsService.storeVectorFieldAsSecret] Failed to store secret:', {
|
|
5611
|
+
secretKey,
|
|
5612
|
+
fieldName,
|
|
5613
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5614
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
5615
|
+
});
|
|
5616
|
+
return value;
|
|
5617
|
+
}
|
|
5618
|
+
}
|
|
5619
|
+
async storeVectorApiKeyAsSecret(apiKey, vectorTag, envSlug) {
|
|
5620
|
+
console.log('[ProductsService.storeVectorApiKeyAsSecret] Storing API key as secret:', {
|
|
5621
|
+
vectorTag,
|
|
5622
|
+
envSlug,
|
|
5623
|
+
hasApiKey: !!apiKey,
|
|
5624
|
+
apiKeyLength: apiKey === null || apiKey === void 0 ? void 0 : apiKey.length,
|
|
5625
|
+
});
|
|
5626
|
+
const result = await this.storeVectorFieldAsSecret(apiKey, vectorTag, envSlug, 'API_KEY', `Vector API key for ${vectorTag} in ${envSlug}`);
|
|
5627
|
+
console.log('[ProductsService.storeVectorApiKeyAsSecret] Result:', {
|
|
5628
|
+
hasResult: !!result,
|
|
5629
|
+
isSecretRef: result === null || result === void 0 ? void 0 : result.startsWith('$Secret{'),
|
|
5630
|
+
});
|
|
5631
|
+
return result || apiKey;
|
|
5632
|
+
}
|
|
5633
|
+
async storeVectorEndpointAsSecret(endpoint, vectorTag, envSlug) {
|
|
5634
|
+
console.log('[ProductsService.storeVectorEndpointAsSecret] Storing endpoint as secret:', {
|
|
5635
|
+
vectorTag,
|
|
5636
|
+
envSlug,
|
|
5637
|
+
hasEndpoint: !!endpoint,
|
|
5638
|
+
endpointLength: endpoint === null || endpoint === void 0 ? void 0 : endpoint.length,
|
|
5639
|
+
});
|
|
5640
|
+
const result = await this.storeVectorFieldAsSecret(endpoint, vectorTag, envSlug, 'ENDPOINT', `Vector endpoint for ${vectorTag} in ${envSlug}`);
|
|
5641
|
+
console.log('[ProductsService.storeVectorEndpointAsSecret] Result:', {
|
|
5642
|
+
hasResult: !!result,
|
|
5643
|
+
isSecretRef: result === null || result === void 0 ? void 0 : result.startsWith('$Secret{'),
|
|
5644
|
+
});
|
|
5645
|
+
return result || endpoint;
|
|
5646
|
+
}
|
|
5647
|
+
/**
|
|
5648
|
+
* Store LLM model API key as a secret
|
|
5649
|
+
* Format: MODEL_{PRODUCT}_{MODEL_TAG}_{ENV}_API_KEY
|
|
5650
|
+
*/
|
|
5651
|
+
async storeModelApiKeyAsSecret(apiKey, modelTag, envSlug) {
|
|
5652
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
5653
|
+
if (!secretsService) {
|
|
5654
|
+
return apiKey;
|
|
5655
|
+
}
|
|
5656
|
+
const secretCheck = (0, secrets_1.isSecretReference)(apiKey);
|
|
5657
|
+
if (secretCheck.isSecret) {
|
|
5658
|
+
return apiKey;
|
|
5659
|
+
}
|
|
5660
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
5661
|
+
const productParts = this.product.tag.split(':');
|
|
5662
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
5663
|
+
const modelKey = modelTag.replace(/-/g, '_');
|
|
5664
|
+
const secretKey = `MODEL_${sanitize(productKey)}_${sanitize(modelKey)}_${sanitize(envSlug)}_API_KEY`;
|
|
5665
|
+
try {
|
|
5666
|
+
const exists = await secretsService.exists(secretKey);
|
|
5667
|
+
if (exists) {
|
|
5668
|
+
await secretsService.update(secretKey, { value: apiKey });
|
|
5669
|
+
}
|
|
5670
|
+
else {
|
|
5671
|
+
await secretsService.create({
|
|
5672
|
+
key: secretKey,
|
|
5673
|
+
value: apiKey,
|
|
5674
|
+
description: `LLM model API key for ${modelTag} in ${envSlug}`,
|
|
5675
|
+
scope: [this.product.tag, modelTag],
|
|
5676
|
+
envs: [envSlug],
|
|
5677
|
+
});
|
|
5678
|
+
}
|
|
5679
|
+
return `$Secret{${secretKey}}`;
|
|
5680
|
+
}
|
|
5681
|
+
catch (error) {
|
|
5682
|
+
console.warn(`Failed to store model API key as secret: ${error}`);
|
|
5683
|
+
return apiKey;
|
|
5684
|
+
}
|
|
5685
|
+
}
|
|
3202
5686
|
}
|
|
3203
5687
|
exports.default = ProductsBuilderService;
|
|
3204
5688
|
//# sourceMappingURL=products.service.js.map
|