@ductape/sdk 0.0.4-v51 → 0.0.4-v52
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/README.md +1 -1
- 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 +304 -0
- package/dist/agents/agents.service.js +1244 -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 +1225 -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.js +4 -5
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/processorApi.service.d.ts +322 -0
- package/dist/api/services/processorApi.service.js +252 -0
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +69 -1
- package/dist/api/services/productsApi.service.js +67 -31
- 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 +38 -0
- package/dist/api/services/secretsApi.service.js +96 -0
- package/dist/api/services/secretsApi.service.js.map +1 -0
- package/dist/api/services/userApi.service.js +0 -1
- package/dist/api/services/userApi.service.js.map +1 -1
- 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.js +0 -1
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +57 -0
- package/dist/api/urls.js +68 -1
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/cache.utils.js +4 -10
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +0 -10
- package/dist/apps/services/app.service.js +74 -30
- 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 +405 -0
- package/dist/apps/utils/oauth-manager.js.map +1 -0
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.d.ts +2 -1
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +15 -2
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appWebhook.validator.d.ts +2 -1
- package/dist/apps/validators/joi-validators/update.appWebhook.validator.js +14 -2
- package/dist/apps/validators/joi-validators/update.appWebhook.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 +257 -0
- package/dist/brokers/brokers.service.js +604 -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 +288 -0
- package/dist/brokers/types/index.js +8 -0
- package/dist/brokers/types/index.js.map +1 -0
- package/dist/brokers/utils/broker.util.d.ts +33 -0
- package/dist/brokers/utils/broker.util.js +125 -0
- package/dist/brokers/utils/broker.util.js.map +1 -0
- package/dist/brokers/utils/providers/aws-sqs.service.d.ts +16 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js +71 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js.map +1 -0
- package/dist/brokers/utils/providers/google-pubsub.service.d.ts +16 -0
- package/dist/brokers/utils/providers/google-pubsub.service.js +43 -0
- package/dist/brokers/utils/providers/google-pubsub.service.js.map +1 -0
- package/dist/brokers/utils/providers/index.d.ts +6 -0
- package/dist/brokers/utils/providers/index.js +16 -0
- package/dist/brokers/utils/providers/index.js.map +1 -0
- package/dist/brokers/utils/providers/kafka.service.d.ts +16 -0
- package/dist/brokers/utils/providers/kafka.service.js +52 -0
- package/dist/brokers/utils/providers/kafka.service.js.map +1 -0
- package/dist/brokers/utils/providers/nats.service.d.ts +18 -0
- package/dist/brokers/utils/providers/nats.service.js +63 -0
- package/dist/brokers/utils/providers/nats.service.js.map +1 -0
- package/dist/brokers/utils/providers/rabbitmq.service.d.ts +14 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js +67 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js.map +1 -0
- package/dist/brokers/utils/providers/redis.service.d.ts +18 -0
- package/dist/brokers/utils/providers/redis.service.js +93 -0
- package/dist/brokers/utils/providers/redis.service.js.map +1 -0
- package/dist/cache/cache.manager.d.ts +159 -0
- package/dist/cache/cache.manager.js +265 -0
- package/dist/cache/cache.manager.js.map +1 -0
- package/dist/cache/cache.service.d.ts +186 -0
- package/dist/cache/cache.service.js +437 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/cache/index.d.ts +52 -0
- package/dist/cache/index.js +79 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/types/index.d.ts +106 -0
- package/dist/cache/types/index.js +6 -0
- package/dist/cache/types/index.js.map +1 -0
- package/dist/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 +307 -90
- package/dist/database/adapters/base.adapter.js +139 -20
- package/dist/database/adapters/base.adapter.js.map +1 -1
- package/dist/database/adapters/cassandra.adapter.d.ts +90 -0
- package/dist/database/adapters/cassandra.adapter.js +1019 -0
- package/dist/database/adapters/cassandra.adapter.js.map +1 -0
- package/dist/database/adapters/dynamodb.adapter.d.ts +94 -77
- package/dist/database/adapters/dynamodb.adapter.js +1162 -1305
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -1
- 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 +105 -57
- package/dist/database/adapters/mongodb.adapter.js +941 -838
- package/dist/database/adapters/mongodb.adapter.js.map +1 -1
- package/dist/database/adapters/mysql.adapter.d.ts +76 -138
- package/dist/database/adapters/mysql.adapter.js +990 -1246
- package/dist/database/adapters/mysql.adapter.js.map +1 -1
- package/dist/database/adapters/postgresql.adapter.d.ts +75 -139
- package/dist/database/adapters/postgresql.adapter.js +1076 -1346
- package/dist/database/adapters/postgresql.adapter.js.map +1 -1
- package/dist/database/databases.service.d.ts +1374 -0
- package/dist/database/databases.service.js +2680 -0
- package/dist/database/databases.service.js.map +1 -0
- package/dist/database/index.d.ts +41 -13
- package/dist/database/index.js +97 -86
- package/dist/database/index.js.map +1 -1
- 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 +132 -0
- package/dist/database/migrations/migration-engine.js +1356 -0
- package/dist/database/migrations/migration-engine.js.map +1 -0
- package/dist/database/operators/aggregation-builder.d.ts +64 -0
- package/dist/database/operators/aggregation-builder.js +746 -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 +55 -0
- package/dist/database/operators/query-builder.js +365 -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 +637 -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 +179 -0
- package/dist/database/types/aggregation.interface.js +6 -0
- package/dist/database/types/aggregation.interface.js.map +1 -0
- package/dist/database/types/connection.interface.d.ts +137 -0
- package/dist/database/types/connection.interface.js +6 -0
- package/dist/database/types/connection.interface.js.map +1 -0
- package/dist/database/types/enums.d.ts +195 -0
- package/dist/database/types/enums.js +244 -0
- package/dist/database/types/enums.js.map +1 -0
- package/dist/database/types/index.d.ts +12 -10
- package/dist/database/types/index.js +26 -32
- package/dist/database/types/index.js.map +1 -1
- 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 +199 -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 +398 -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 +208 -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 +78 -72
- package/dist/graph/adapters/arangodb.adapter.js +1310 -1220
- package/dist/graph/adapters/arangodb.adapter.js.map +1 -1
- package/dist/graph/adapters/base.adapter.d.ts +135 -118
- package/dist/graph/adapters/base.adapter.js +46 -20
- package/dist/graph/adapters/base.adapter.js.map +1 -1
- package/dist/graph/adapters/index.d.ts +5 -4
- package/dist/graph/adapters/index.js +6 -8
- package/dist/graph/adapters/index.js.map +1 -1
- package/dist/graph/adapters/memgraph.adapter.d.ts +98 -73
- package/dist/graph/adapters/memgraph.adapter.js +1050 -1202
- package/dist/graph/adapters/memgraph.adapter.js.map +1 -1
- package/dist/graph/adapters/neo4j.adapter.d.ts +71 -78
- package/dist/graph/adapters/neo4j.adapter.js +912 -1605
- package/dist/graph/adapters/neo4j.adapter.js.map +1 -1
- package/dist/graph/adapters/neptune.adapter.d.ts +76 -81
- package/dist/graph/adapters/neptune.adapter.js +1095 -1228
- package/dist/graph/adapters/neptune.adapter.js.map +1 -1
- package/dist/graph/graphs.service.d.ts +524 -0
- package/dist/graph/graphs.service.js +1683 -0
- package/dist/graph/graphs.service.js.map +1 -0
- package/dist/graph/index.d.ts +54 -8
- package/dist/graph/index.js +67 -32
- package/dist/graph/index.js.map +1 -1
- 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 +141 -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 +11 -9
- package/dist/graph/types/index.js +15 -30
- package/dist/graph/types/index.js.map +1 -1
- 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 +168 -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/index.d.ts +1905 -875
- package/dist/index.js +3063 -1282
- package/dist/index.js.map +1 -1
- package/dist/init.interface.d.ts +407 -0
- package/dist/init.interface.js +3 -0
- package/dist/init.interface.js.map +1 -0
- package/dist/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.types.d.ts +12 -2
- package/dist/logs/logs.types.js +5 -1
- 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 +252 -0
- package/dist/notifications/notifications.service.js +654 -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 +400 -0
- package/dist/notifications/types/notifications.types.js +49 -0
- package/dist/notifications/types/notifications.types.js.map +1 -0
- package/dist/processor/services/messagebrokers/kafka.service.js +2 -0
- package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +1 -9
- package/dist/processor/services/messagebrokers/rabbitmq.service.js +11 -40
- package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +86 -70
- package/dist/processor/services/processor.service.js +1353 -1259
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/utils/processor.utils.js +5 -1
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/products/services/products.service.d.ts +167 -25
- package/dist/products/services/products.service.js +1248 -412
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/validators/index.d.ts +6 -3
- package/dist/products/validators/index.js +14 -5
- 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 +218 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.d.ts +4 -15
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +109 -501
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productGraph.validator.js +14 -9
- package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +0 -1
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +87 -30
- 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 +135 -50
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productStorage.validator.js +77 -18
- package/dist/products/validators/joi-validators/create.productStorage.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productVector.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js +135 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.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.productDatabaseAction.validator.d.ts +0 -6
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js +26 -28
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productGraph.validator.js +11 -12
- package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js +0 -1
- package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js.map +1 -1
- package/dist/resilience/fallback.service.d.ts +88 -0
- package/dist/resilience/fallback.service.js +511 -0
- package/dist/resilience/fallback.service.js.map +1 -0
- package/dist/resilience/healthcheck.service.d.ts +106 -0
- package/dist/resilience/healthcheck.service.js +379 -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 +90 -0
- package/dist/resilience/quota.service.js +519 -0
- package/dist/resilience/quota.service.js.map +1 -0
- package/dist/resilience/resilience.service.d.ts +95 -0
- package/dist/resilience/resilience.service.js +525 -0
- package/dist/resilience/resilience.service.js.map +1 -0
- package/dist/resilience/types/index.d.ts +479 -0
- package/dist/resilience/types/index.js +26 -0
- package/dist/resilience/types/index.js.map +1 -0
- package/dist/secrets/index.d.ts +10 -0
- package/dist/secrets/index.js +33 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/secrets/secrets.resolver.d.ts +52 -0
- package/dist/secrets/secrets.resolver.js +233 -0
- package/dist/secrets/secrets.resolver.js.map +1 -0
- package/dist/secrets/secrets.service.d.ts +83 -0
- package/dist/secrets/secrets.service.js +159 -0
- package/dist/secrets/secrets.service.js.map +1 -0
- package/dist/secrets/secrets.types.d.ts +188 -0
- package/dist/secrets/secrets.types.js +87 -0
- package/dist/secrets/secrets.types.js.map +1 -0
- package/dist/sessions/index.d.ts +50 -0
- package/dist/sessions/index.js +93 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/sessions.helper.d.ts +68 -0
- package/dist/sessions/sessions.helper.js +116 -0
- package/dist/sessions/sessions.helper.js.map +1 -0
- package/dist/sessions/sessions.resolver.d.ts +150 -0
- package/dist/sessions/sessions.resolver.js +356 -0
- package/dist/sessions/sessions.resolver.js.map +1 -0
- package/dist/sessions/sessions.service.d.ts +170 -0
- package/dist/sessions/sessions.service.js +736 -0
- package/dist/sessions/sessions.service.js.map +1 -0
- package/dist/sessions/types/index.d.ts +290 -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 +98 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/storage.service.d.ts +123 -0
- package/dist/storage/storage.service.js +478 -0
- package/dist/storage/storage.service.js.map +1 -0
- package/dist/storage/types/index.d.ts +207 -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 +51 -0
- package/dist/storage/utils/storage.util.js +402 -0
- package/dist/storage/utils/storage.util.js.map +1 -0
- package/dist/test/index.d.ts +3 -0
- package/dist/test/index.js +13 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/test.appBuilder.d.ts +0 -1
- package/dist/test/test.appBuilder.js +0 -15
- package/dist/test/test.appBuilder.js.map +1 -1
- package/dist/test/test.database.js +140 -0
- package/dist/test/test.database.js.map +1 -0
- package/dist/test/test.health.d.ts +0 -1
- package/dist/test/test.health.js +0 -48
- package/dist/test/test.health.js.map +1 -1
- package/dist/test/test.import.d.ts +0 -1
- package/dist/test/test.import.js +0 -1506
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.import.openapi.d.ts +0 -1
- package/dist/test/test.import.openapi.js +0 -75
- package/dist/test/test.import.openapi.js.map +1 -1
- package/dist/test/test.imports.d.ts +0 -1
- package/dist/test/test.imports.js +0 -76
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.logs.d.ts +0 -1
- package/dist/test/test.logs.js +0 -17
- package/dist/test/test.logs.js.map +1 -1
- package/dist/test/test.notifiers.d.ts +0 -1
- package/dist/test/test.notifiers.js +0 -84
- package/dist/test/test.notifiers.js.map +1 -1
- package/dist/test/test.processor.d.ts +0 -1
- package/dist/test/test.processor.js +0 -37
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.productBuilder.d.ts +0 -1
- package/dist/test/test.productBuilder.js +0 -660
- package/dist/test/test.productBuilder.js.map +1 -1
- package/dist/test/test.products.d.ts +0 -1
- package/dist/test/test.products.js +0 -48
- package/dist/test/test.products.js.map +1 -1
- package/dist/test/test.storage.js +332 -0
- package/dist/test/test.storage.js.map +1 -0
- package/dist/test/test.triggers.js +314 -0
- package/dist/test/test.triggers.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +1 -1
- package/dist/types/enums.d.ts +6 -1
- package/dist/types/enums.js +5 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/processor.types.d.ts +197 -35
- package/dist/types/processor.types.js +9 -1
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +837 -75
- package/dist/types/productsBuilder.types.js +168 -62
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +2 -49
- package/dist/utils/index.js.map +1 -1
- package/dist/vector/adapters/base.adapter.d.ts +152 -0
- package/dist/vector/adapters/base.adapter.js +137 -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 +400 -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 +392 -0
- package/dist/vector/adapters/qdrant.adapter.js.map +1 -0
- package/dist/vector/adapters/weaviate.adapter.d.ts +64 -0
- package/dist/vector/adapters/weaviate.adapter.js +478 -0
- package/dist/vector/adapters/weaviate.adapter.js.map +1 -0
- package/dist/vector/index.d.ts +47 -0
- package/dist/vector/index.js +72 -0
- package/dist/vector/index.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 +9 -0
- package/dist/vector/types/index.js +16 -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 +117 -0
- package/dist/vector/utils/vector-error.js.map +1 -0
- package/dist/vector/vector-database.service.d.ts +405 -0
- package/dist/vector/vector-database.service.js +544 -0
- package/dist/vector/vector-database.service.js.map +1 -0
- package/dist/vector/vector.service.d.ts +245 -0
- package/dist/vector/vector.service.js +381 -0
- package/dist/vector/vector.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 +1035 -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 +205 -0
- package/dist/workflows/workflow-executor.js +1186 -0
- package/dist/workflows/workflow-executor.js.map +1 -0
- package/dist/workflows/workflows.service.d.ts +398 -0
- package/dist/workflows/workflows.service.js +1595 -0
- package/dist/workflows/workflows.service.js.map +1 -0
- package/package.json +16 -13
- package/dist/actions/actions.repo.d.ts +0 -0
- package/dist/actions/actions.repo.js +0 -13
- package/dist/actions/actions.repo.js.map +0 -1
- package/dist/actions/actions.service.d.ts +0 -0
- 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/api/services/workspaceSecretsApi.service.d.ts +0 -75
- package/dist/api/services/workspaceSecretsApi.service.js +0 -62
- package/dist/api/services/workspaceSecretsApi.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.d.ts +0 -3
- 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.d.ts +0 -3
- 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/database/database.service.d.ts +0 -232
- package/dist/database/database.service.js +0 -802
- package/dist/database/database.service.js.map +0 -1
- package/dist/database/types/aggregation.types.d.ts +0 -261
- package/dist/database/types/aggregation.types.js +0 -21
- package/dist/database/types/aggregation.types.js.map +0 -1
- package/dist/database/types/connection.types.d.ts +0 -132
- package/dist/database/types/connection.types.js +0 -6
- package/dist/database/types/connection.types.js.map +0 -1
- package/dist/database/types/database.types.d.ts +0 -175
- package/dist/database/types/database.types.js +0 -75
- package/dist/database/types/database.types.js.map +0 -1
- package/dist/database/types/index.types.d.ts +0 -220
- package/dist/database/types/index.types.js +0 -27
- package/dist/database/types/index.types.js.map +0 -1
- package/dist/database/types/migration.types.d.ts +0 -205
- package/dist/database/types/migration.types.js +0 -44
- package/dist/database/types/migration.types.js.map +0 -1
- package/dist/database/types/query.types.d.ts +0 -305
- package/dist/database/types/query.types.js +0 -57
- package/dist/database/types/query.types.js.map +0 -1
- package/dist/database/types/result.types.d.ts +0 -220
- package/dist/database/types/result.types.js +0 -6
- package/dist/database/types/result.types.js.map +0 -1
- package/dist/database/types/schema.types.d.ts +0 -190
- package/dist/database/types/schema.types.js +0 -69
- package/dist/database/types/schema.types.js.map +0 -1
- package/dist/database/utils/helpers.d.ts +0 -66
- package/dist/database/utils/helpers.js +0 -501
- package/dist/database/utils/helpers.js.map +0 -1
- package/dist/database/utils/migration.utils.d.ts +0 -151
- package/dist/database/utils/migration.utils.js +0 -476
- package/dist/database/utils/migration.utils.js.map +0 -1
- package/dist/database/utils/transaction.d.ts +0 -64
- package/dist/database/utils/transaction.js +0 -130
- package/dist/database/utils/transaction.js.map +0 -1
- package/dist/database/validators/connection.validator.d.ts +0 -20
- package/dist/database/validators/connection.validator.js +0 -267
- package/dist/database/validators/connection.validator.js.map +0 -1
- package/dist/database/validators/query.validator.d.ts +0 -31
- package/dist/database/validators/query.validator.js +0 -305
- package/dist/database/validators/query.validator.js.map +0 -1
- package/dist/database/validators/schema.validator.d.ts +0 -31
- package/dist/database/validators/schema.validator.js +0 -334
- package/dist/database/validators/schema.validator.js.map +0 -1
- package/dist/graph/graph.service.d.ts +0 -278
- package/dist/graph/graph.service.js +0 -687
- package/dist/graph/graph.service.js.map +0 -1
- package/dist/graph/types/connection.types.d.ts +0 -158
- package/dist/graph/types/connection.types.js +0 -43
- package/dist/graph/types/connection.types.js.map +0 -1
- package/dist/graph/types/graph.types.d.ts +0 -144
- package/dist/graph/types/graph.types.js +0 -84
- package/dist/graph/types/graph.types.js.map +0 -1
- package/dist/graph/types/node.types.d.ts +0 -193
- package/dist/graph/types/node.types.js +0 -49
- package/dist/graph/types/node.types.js.map +0 -1
- package/dist/graph/types/path.types.d.ts +0 -224
- package/dist/graph/types/path.types.js +0 -38
- package/dist/graph/types/path.types.js.map +0 -1
- package/dist/graph/types/query.types.d.ts +0 -247
- package/dist/graph/types/query.types.js +0 -23
- package/dist/graph/types/query.types.js.map +0 -1
- package/dist/graph/types/relationship.types.d.ts +0 -224
- package/dist/graph/types/relationship.types.js +0 -35
- package/dist/graph/types/relationship.types.js.map +0 -1
- package/dist/graph/types/result.types.d.ts +0 -237
- package/dist/graph/types/result.types.js +0 -7
- package/dist/graph/types/result.types.js.map +0 -1
- package/dist/graph/validators/index.d.ts +0 -81
- package/dist/graph/validators/index.js +0 -243
- package/dist/graph/validators/index.js.map +0 -1
- package/dist/integrationsBuilder/services/integration.service.d.ts +0 -138
- package/dist/integrationsBuilder/services/integration.service.js +0 -1148
- package/dist/integrationsBuilder/services/integration.service.js.map +0 -1
- package/dist/integrationsBuilder/services/integrationBuilder.service.d.ts +0 -130
- package/dist/integrationsBuilder/services/integrationBuilder.service.js +0 -1017
- package/dist/integrationsBuilder/services/integrationBuilder.service.js.map +0 -1
- package/dist/integrationsBuilder/utils/objects.utils.d.ts +0 -2
- package/dist/integrationsBuilder/utils/objects.utils.js +0 -48
- package/dist/integrationsBuilder/utils/objects.utils.js.map +0 -1
- package/dist/integrationsBuilder/utils/string.utils.d.ts +0 -1
- package/dist/integrationsBuilder/utils/string.utils.js +0 -9
- package/dist/integrationsBuilder/utils/string.utils.js.map +0 -1
- package/dist/integrationsBuilder/validators/index.d.ts +0 -18
- package/dist/integrationsBuilder/validators/index.js +0 -38
- package/dist/integrationsBuilder/validators/index.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.d.ts +0 -4
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js +0 -26
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js +0 -60
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js +0 -9
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js.map +0 -1
- package/dist/postman.d.ts +0 -1
- package/dist/postman.js +0 -21674
- package/dist/postman.js.map +0 -1
- package/dist/processor/utils/mongo.util.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/services/utils/crypt.utils.d.ts +0 -1
- package/dist/products/services/utils/crypt.utils.js +0 -17
- package/dist/products/services/utils/crypt.utils.js.map +0 -1
- package/dist/products/services/utils/functions.utils.d.ts +0 -13
- package/dist/products/services/utils/functions.utils.js +0 -289
- package/dist/products/services/utils/functions.utils.js.map +0 -1
- package/dist/products/services/utils/objects.utils.d.ts +0 -13
- package/dist/products/services/utils/objects.utils.js +0 -89
- package/dist/products/services/utils/objects.utils.js.map +0 -1
- package/dist/products/services/utils/string.utils.d.ts +0 -12
- package/dist/products/services/utils/string.utils.js +0 -168
- package/dist/products/services/utils/string.utils.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/products/validators/joi-validators/create.productGraphAction.validator.d.ts +0 -14
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.js +0 -696
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.js.map +0 -1
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.d.ts +0 -7
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.js +0 -72
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.js.map +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.js +0 -28
- package/dist/test.imports.js.map +0 -1
- package/dist/test.integrationBuilder.js +0 -276
- package/dist/test.integrationBuilder.js.map +0 -1
- package/dist/test.processor.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/tsconfig.tsbuildinfo +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/{test.appBuilder.d.ts → test/test.database.d.ts} +0 -0
- /package/dist/{test.imports.d.ts → test/test.storage.d.ts} +0 -0
- /package/dist/{test.integrationBuilder.d.ts → test/test.triggers.d.ts} +0 -0
|
@@ -56,30 +56,31 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
56
56
|
const processorApi_service_1 = require("../../api/services/processorApi.service");
|
|
57
57
|
const expo_client_1 = __importDefault(require("../../clients/expo.client"));
|
|
58
58
|
const handlebars_1 = require("handlebars");
|
|
59
|
-
const
|
|
60
|
-
const string_utils_1 = require("../../products/services/utils/string.utils");
|
|
59
|
+
const string_utils_1 = require("../../products/utils/string.utils");
|
|
61
60
|
const create_productFeature_validator_1 = require("../../products/validators/joi-validators/create.productFeature.validator");
|
|
61
|
+
const validators_1 = require("../../products/validators");
|
|
62
62
|
const uuid_1 = require("uuid");
|
|
63
|
-
|
|
63
|
+
const urls_1 = require("../../api/urls");
|
|
64
64
|
const date_fns_1 = require("date-fns");
|
|
65
|
-
const mongo_repo_1 = require("../repos/mongo.repo");
|
|
66
|
-
const postgres_repo_1 = require("../repos/postgres.repo");
|
|
67
65
|
const storage_util_1 = require("../utils/storage.util");
|
|
68
66
|
const sms_repo_1 = require("../repos/sms.repo");
|
|
69
|
-
const quota_service_1 = __importDefault(require("./quota.service"));
|
|
70
67
|
const pricing_service_1 = __importDefault(require("../../pricing/pricing.service"));
|
|
71
68
|
const request_utils_1 = require("../utils/request.utils");
|
|
72
69
|
const request_service_1 = __importDefault(require("./request.service"));
|
|
70
|
+
const app_service_1 = __importDefault(require("../../apps/services/app.service"));
|
|
71
|
+
const utils_1 = require("../../apps/utils");
|
|
72
|
+
const credential_manager_1 = require("../../apps/utils/credential-manager");
|
|
73
|
+
const oauth_manager_1 = require("../../apps/utils/oauth-manager");
|
|
73
74
|
async function loadBrokerService() {
|
|
74
75
|
if (typeof window === 'undefined') {
|
|
75
|
-
const {
|
|
76
|
-
return
|
|
76
|
+
const { loadBrokerService: loadBroker } = await Promise.resolve().then(() => __importStar(require('../../brokers')));
|
|
77
|
+
return loadBroker();
|
|
77
78
|
}
|
|
78
79
|
return null;
|
|
79
80
|
}
|
|
80
81
|
async function loadJWT() {
|
|
81
82
|
if (typeof window === 'undefined') {
|
|
82
|
-
const JWT = await Promise.resolve().then(() => __importStar(require(
|
|
83
|
+
const JWT = await Promise.resolve().then(() => __importStar(require('jsonwebtoken')));
|
|
83
84
|
return JWT;
|
|
84
85
|
}
|
|
85
86
|
return null;
|
|
@@ -97,7 +98,15 @@ class ProcessorService {
|
|
|
97
98
|
user_id,
|
|
98
99
|
token,
|
|
99
100
|
env_type,
|
|
100
|
-
redis_client
|
|
101
|
+
redis_client,
|
|
102
|
+
});
|
|
103
|
+
this.appBuilderService = new app_service_1.default({
|
|
104
|
+
workspace_id,
|
|
105
|
+
public_key,
|
|
106
|
+
user_id,
|
|
107
|
+
token,
|
|
108
|
+
env_type,
|
|
109
|
+
redis_client,
|
|
101
110
|
});
|
|
102
111
|
this.pricingService = new pricing_service_1.default({
|
|
103
112
|
workspace_id,
|
|
@@ -120,9 +129,12 @@ class ProcessorService {
|
|
|
120
129
|
this.requestTrackerService = request_service_1.default.getInstance(redis_client);
|
|
121
130
|
this.processorApiService = new processorApi_service_1.ProcessorApiService(env_type);
|
|
122
131
|
this.environment = env_type;
|
|
123
|
-
|
|
132
|
+
// Store redis client for job state management
|
|
133
|
+
if (redis_client) {
|
|
124
134
|
this.redisClient = redis_client;
|
|
125
|
-
|
|
135
|
+
}
|
|
136
|
+
// Start healthcheck workers only if product tag is available
|
|
137
|
+
if (redis_client && this.productTag) {
|
|
126
138
|
this.startHealthcheckWorkers();
|
|
127
139
|
}
|
|
128
140
|
if (queues) {
|
|
@@ -156,7 +168,7 @@ class ProcessorService {
|
|
|
156
168
|
product: this.productTag,
|
|
157
169
|
app: healthcheck.app,
|
|
158
170
|
input: decryptedInput,
|
|
159
|
-
|
|
171
|
+
action: healthcheck.event,
|
|
160
172
|
retries: healthcheck.retries || 0,
|
|
161
173
|
};
|
|
162
174
|
// Process the action
|
|
@@ -190,7 +202,7 @@ class ProcessorService {
|
|
|
190
202
|
product: productTag,
|
|
191
203
|
app: healthcheck.app,
|
|
192
204
|
input: decryptedInput,
|
|
193
|
-
|
|
205
|
+
action: healthcheck.event,
|
|
194
206
|
retries: healthcheck.retries || 0,
|
|
195
207
|
};
|
|
196
208
|
const result = await this.processAction(actionInput);
|
|
@@ -205,10 +217,10 @@ class ProcessorService {
|
|
|
205
217
|
async generateSession(payload) {
|
|
206
218
|
try {
|
|
207
219
|
const { product: product_tag, env: slug, tag, data } = payload;
|
|
208
|
-
const input = await this.inputService.parseJson({
|
|
220
|
+
const input = (await this.inputService.parseJson({
|
|
209
221
|
data,
|
|
210
222
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
211
|
-
});
|
|
223
|
+
}));
|
|
212
224
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
213
225
|
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
214
226
|
const session = await this.productBuilderService.fetchSession(tag);
|
|
@@ -222,14 +234,16 @@ class ProcessorService {
|
|
|
222
234
|
await this.inputService.validateInput(input, session.schema_data);
|
|
223
235
|
const stages = (0, string_utils_1.extractStages)(session.selector);
|
|
224
236
|
// Convert stages to string[] for functions expecting string[]
|
|
225
|
-
const stringStages = stages.map(stage => String(stage));
|
|
237
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
226
238
|
const user = (0, processor_utils_1.extractSelectorValue)(data, stringStages, session.selector);
|
|
227
239
|
const expiry = (0, processor_utils_1.calculateJWTExpiry)(session.expiry, session.period);
|
|
228
240
|
const end_at = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
|
|
229
241
|
const JWT = await loadJWT();
|
|
230
242
|
if (JWT) {
|
|
231
243
|
const session_id = (0, uuid_1.v4)();
|
|
232
|
-
const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, privateKey, {
|
|
244
|
+
const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, privateKey, {
|
|
245
|
+
expiresIn: expiry,
|
|
246
|
+
});
|
|
233
247
|
const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), privateKey);
|
|
234
248
|
// WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
|
|
235
249
|
const details = {
|
|
@@ -238,7 +252,7 @@ class ProcessorService {
|
|
|
238
252
|
end_at,
|
|
239
253
|
session_tag: tag,
|
|
240
254
|
data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), privateKey),
|
|
241
|
-
session_id
|
|
255
|
+
session_id,
|
|
242
256
|
};
|
|
243
257
|
await this.processorApiService.createSessionInfo(Object.assign({ product_tag, env: slug, refreshToken }, details), this.getUserAccess());
|
|
244
258
|
return {
|
|
@@ -276,7 +290,7 @@ class ProcessorService {
|
|
|
276
290
|
throw new Error(`Running in browser, token service not loaded.`);
|
|
277
291
|
}
|
|
278
292
|
try {
|
|
279
|
-
const res = await JWT.verify(data.token, privateKey);
|
|
293
|
+
const res = (await JWT.verify(data.token, privateKey));
|
|
280
294
|
if (res.session !== data.tag) {
|
|
281
295
|
throw new Error(`Invalid token for session ${data.tag}`);
|
|
282
296
|
}
|
|
@@ -287,9 +301,97 @@ class ProcessorService {
|
|
|
287
301
|
}
|
|
288
302
|
catch (e) {
|
|
289
303
|
console.log(e);
|
|
290
|
-
throw new Error(
|
|
304
|
+
throw new Error('Invalid/Expired token');
|
|
291
305
|
}
|
|
292
306
|
}
|
|
307
|
+
async registerWebhook(data) {
|
|
308
|
+
const { product: product_tag, access_tag, webhook_tag, envs } = data;
|
|
309
|
+
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
310
|
+
const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
|
|
311
|
+
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
|
|
312
|
+
const { webhooks } = app.versions.find((data) => data.tag === version);
|
|
313
|
+
if (!webhooks) {
|
|
314
|
+
throw new Error(`Webhooks not found for app ${access_tag}`);
|
|
315
|
+
}
|
|
316
|
+
await validators_1.RegisterWebhookEnvSchema.validateAsync(envs);
|
|
317
|
+
const webhook = webhooks.find((data) => data.tag === webhook_tag);
|
|
318
|
+
if (!webhook) {
|
|
319
|
+
throw new Error(`Webhook tag ${webhook_tag} not found`);
|
|
320
|
+
}
|
|
321
|
+
const productEnvs = await this.productBuilderService.fetchEnvs();
|
|
322
|
+
productEnvs.map((env) => {
|
|
323
|
+
const exists = envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
324
|
+
if (exists === -1) {
|
|
325
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
const dataArray = await Promise.all(envs.map(async (env) => {
|
|
329
|
+
await this.validateActionDataMappingInput(env.auth, types_1.WebhookEventTypes.WEBHOOK_REGISTER);
|
|
330
|
+
const productEnvData = productEnvs.find((data) => data.slug === env.slug);
|
|
331
|
+
if (!productEnvData) {
|
|
332
|
+
throw new Error(`Error finding product env ${env.slug}`);
|
|
333
|
+
}
|
|
334
|
+
const envData = productEnvData.envs.find((productEnvMap) => productEnvMap.product_env_slug === env.slug);
|
|
335
|
+
if (!envData) {
|
|
336
|
+
throw new Error(`Error finding env data for ${env.slug}`);
|
|
337
|
+
}
|
|
338
|
+
const { app_env_slug: appEnv, product_env_slug: productEnv } = envData;
|
|
339
|
+
const envWebhookData = webhook.envs.find((webhookEnv) => webhookEnv.slug === appEnv);
|
|
340
|
+
if (!envWebhookData) {
|
|
341
|
+
throw new Error(`Error finding webhook registration sample ${webhook_tag} for env ${env.slug}`);
|
|
342
|
+
}
|
|
343
|
+
const uuid = (0, uuid_1.v4)();
|
|
344
|
+
const url = `${urls_1.WEBHOOK_BASE_URL}/webhooks/v1/process/${uuid}`;
|
|
345
|
+
let active = false;
|
|
346
|
+
if (envWebhookData.sample) {
|
|
347
|
+
const samples = {
|
|
348
|
+
query: envWebhookData.sample_data.filter((data) => data.parent_key === 'query'),
|
|
349
|
+
params: envWebhookData.sample_data.filter((data) => data.parent_key === 'params'),
|
|
350
|
+
body: envWebhookData.sample_data.filter((data) => data.parent_key === 'body'),
|
|
351
|
+
headers: envWebhookData.sample_data.filter((data) => data.parent_key === 'headers'),
|
|
352
|
+
};
|
|
353
|
+
let payload = (await this.constructJSONDataPayloads(env.auth, {}, samples, {
|
|
354
|
+
app: access_tag,
|
|
355
|
+
event: '',
|
|
356
|
+
input: env.auth,
|
|
357
|
+
type: types_1.FeatureEventTypes.ACTION,
|
|
358
|
+
retries: 0,
|
|
359
|
+
allow_fail: false,
|
|
360
|
+
}));
|
|
361
|
+
const { updatedObj, replacedUrl } = (0, processor_utils_1.updateUrlsInObject)(payload, url);
|
|
362
|
+
if (replacedUrl && replacedUrl !== env.url && replacedUrl) {
|
|
363
|
+
throw new Error(`Ductape expects the url ${replacedUrl} in request body to match inputted url ${env.url}`);
|
|
364
|
+
}
|
|
365
|
+
const exists = await this.fetchEnv(env.slug, {});
|
|
366
|
+
if (!exists) {
|
|
367
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
368
|
+
}
|
|
369
|
+
payload = updatedObj;
|
|
370
|
+
if (!replacedUrl) {
|
|
371
|
+
payload.body.url = url;
|
|
372
|
+
}
|
|
373
|
+
const parsedUrl = new URL(envWebhookData.registration_url);
|
|
374
|
+
await this.sendActionRequest(parsedUrl.origin, parsedUrl.pathname, payload, envWebhookData.method, env.slug);
|
|
375
|
+
active = true;
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
appEnv,
|
|
379
|
+
productEnv,
|
|
380
|
+
uuid,
|
|
381
|
+
url: env.url,
|
|
382
|
+
method: env.method,
|
|
383
|
+
access_tag,
|
|
384
|
+
webhook_tag,
|
|
385
|
+
version,
|
|
386
|
+
sender_workspace_id: app.workspace_id,
|
|
387
|
+
receiver_workspace_id: this.getUserAccess().workspace_id,
|
|
388
|
+
app_tag: app.tag,
|
|
389
|
+
product_tag,
|
|
390
|
+
active,
|
|
391
|
+
};
|
|
392
|
+
}));
|
|
393
|
+
await this.webhookApi.registerWebhooks(dataArray, this.getUserAccess());
|
|
394
|
+
}
|
|
293
395
|
async generateWebhookLink(data) {
|
|
294
396
|
const { product: product_tag, access_tag, webhook_tag, env: product_env, url, method } = data;
|
|
295
397
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
@@ -322,243 +424,6 @@ class ProcessorService {
|
|
|
322
424
|
return await this.webhookApi.generateLink(payload, this.getUserAccess());
|
|
323
425
|
//return res.link;
|
|
324
426
|
}
|
|
325
|
-
async processQuota(data) {
|
|
326
|
-
this.start = Date.now();
|
|
327
|
-
const { product: product_tag, env, input, tag: quota_tag } = data;
|
|
328
|
-
try {
|
|
329
|
-
this.productTag = product_tag;
|
|
330
|
-
const additional_logs = {
|
|
331
|
-
name: 'Process Quota',
|
|
332
|
-
type: types_1.LogEventTypes.QUOTA,
|
|
333
|
-
parent_tag: quota_tag,
|
|
334
|
-
};
|
|
335
|
-
await this.intializeProduct(additional_logs);
|
|
336
|
-
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
337
|
-
this.process_id = process_id;
|
|
338
|
-
this.baseLogs = {
|
|
339
|
-
product_tag: this.productTag,
|
|
340
|
-
product_id: this.productId,
|
|
341
|
-
workspace_id: this.workspace_id,
|
|
342
|
-
env,
|
|
343
|
-
type: types_1.LogEventTypes.QUOTA,
|
|
344
|
-
process_id,
|
|
345
|
-
data: input,
|
|
346
|
-
};
|
|
347
|
-
this.quota = await this.fetchQuota(quota_tag, additional_logs);
|
|
348
|
-
if (!this.quota) {
|
|
349
|
-
throw new Error(`Quota ${quota_tag} not found`);
|
|
350
|
-
}
|
|
351
|
-
this.logService.setFeatureId(this.quota._id);
|
|
352
|
-
this.processEnv = await this.fetchEnv(env, additional_logs);
|
|
353
|
-
if (!this.processEnv.active) {
|
|
354
|
-
throw new Error(`Environment ${data.env} is not active`);
|
|
355
|
-
}
|
|
356
|
-
const { input: quotaInput, options } = this.quota;
|
|
357
|
-
// validate feature input and log failure
|
|
358
|
-
this.validateJSONFeatureInput(input, quotaInput, additional_logs);
|
|
359
|
-
// split processes
|
|
360
|
-
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
361
|
-
await this.logService.publish();
|
|
362
|
-
return await this.runQuotaOptions(options, input, additional_logs);
|
|
363
|
-
}
|
|
364
|
-
catch (e) {
|
|
365
|
-
this.end = Date.now();
|
|
366
|
-
await this.logService.publish();
|
|
367
|
-
throw e;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
async runQuotaOptions(options, input, additional_logs) {
|
|
371
|
-
try {
|
|
372
|
-
const quotaManager = new quota_service_1.default(options, this.redisClient);
|
|
373
|
-
const getNextProvider = quotaManager.getNextProvider();
|
|
374
|
-
const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
|
|
375
|
-
const result = await this.processEvent({
|
|
376
|
-
app: getNextProvider.app,
|
|
377
|
-
type: getNextProvider.type,
|
|
378
|
-
event: getNextProvider.event,
|
|
379
|
-
input: quotaInput,
|
|
380
|
-
retries: getNextProvider.retries,
|
|
381
|
-
allow_fail: false
|
|
382
|
-
});
|
|
383
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota successful', successful_execution: true, data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
384
|
-
return result;
|
|
385
|
-
}
|
|
386
|
-
catch (e) {
|
|
387
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota failed', failed_execution: true, data: { e }, status: types_1.LogEventStatus.PROCESSING }));
|
|
388
|
-
throw e;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
async mapQuotaFallbackInput(providerInput, quotaInput, app) {
|
|
392
|
-
if (Array.isArray(providerInput)) {
|
|
393
|
-
return providerInput.map(async (item) => await this.mapQuotaFallbackInput(item, quotaInput, app));
|
|
394
|
-
}
|
|
395
|
-
else if (providerInput && typeof providerInput === 'object') {
|
|
396
|
-
const result = {};
|
|
397
|
-
for (const key in providerInput) {
|
|
398
|
-
result[key] = await this.mapQuotaFallbackInput(providerInput[key], quotaInput, app);
|
|
399
|
-
}
|
|
400
|
-
return result;
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
// Base case: primitive value
|
|
404
|
-
return await this.overrideQuotaFallbackInput(providerInput, quotaInput, app);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
async overrideQuotaFallbackInput(value, quotaInput, app) {
|
|
408
|
-
if (value.startsWith('$Input{')) {
|
|
409
|
-
const stages = (0, string_utils_1.extractStages)(value);
|
|
410
|
-
return quotaInput[String(stages[0])];
|
|
411
|
-
}
|
|
412
|
-
else if (value.startsWith('$Auth')) {
|
|
413
|
-
const stages = (0, string_utils_1.extractStages)(value);
|
|
414
|
-
// Convert stages to string[] for functions expecting string[]
|
|
415
|
-
const stringStages = stages.map(stage => String(stage));
|
|
416
|
-
return await this.generateAuthValue(stringStages, app, [], {});
|
|
417
|
-
}
|
|
418
|
-
else if (value.startsWith('$')) {
|
|
419
|
-
this.input = Object.assign(Object.assign({}, this.input), { input: quotaInput });
|
|
420
|
-
return await this.generateOperatorValues(value, '', {});
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
return value;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
async runFallbackOptions(options, input, additional_logs) {
|
|
427
|
-
return await this.executeActionWithFallback(options, input);
|
|
428
|
-
}
|
|
429
|
-
async executeActionWithFallback(providers, input) {
|
|
430
|
-
let index = 0;
|
|
431
|
-
for (const provider of providers) {
|
|
432
|
-
try {
|
|
433
|
-
const payload = {
|
|
434
|
-
app: provider.app,
|
|
435
|
-
type: provider.type,
|
|
436
|
-
event: provider.event,
|
|
437
|
-
input: await this.mapQuotaFallbackInput(provider.input, input, provider.app),
|
|
438
|
-
retries: provider.retries,
|
|
439
|
-
allow_fail: false
|
|
440
|
-
};
|
|
441
|
-
const result = await this.processEvent(payload);
|
|
442
|
-
if (result.status === types_1.LogEventStatus.FAIL) {
|
|
443
|
-
throw new Error(result.errors);
|
|
444
|
-
}
|
|
445
|
-
index++;
|
|
446
|
-
}
|
|
447
|
-
catch (error) {
|
|
448
|
-
if (index > 0) {
|
|
449
|
-
throw error;
|
|
450
|
-
}
|
|
451
|
-
console.warn(`${provider.app || provider.event} failed: ${error}`);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
//throw new Error("All providers failed.");
|
|
455
|
-
}
|
|
456
|
-
async processFallback(data) {
|
|
457
|
-
this.start = Date.now();
|
|
458
|
-
const { product: product_tag, env, input, tag: fallback_tag } = data;
|
|
459
|
-
try {
|
|
460
|
-
this.productTag = product_tag;
|
|
461
|
-
const additional_logs = {
|
|
462
|
-
name: 'Process Fallback',
|
|
463
|
-
type: types_1.LogEventTypes.FALLBACK,
|
|
464
|
-
parent_tag: fallback_tag,
|
|
465
|
-
};
|
|
466
|
-
await this.intializeProduct(additional_logs);
|
|
467
|
-
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
468
|
-
this.process_id = process_id;
|
|
469
|
-
this.baseLogs = {
|
|
470
|
-
product_tag: this.productTag,
|
|
471
|
-
product_id: this.productId,
|
|
472
|
-
workspace_id: this.workspace_id,
|
|
473
|
-
env,
|
|
474
|
-
type: types_1.LogEventTypes.FALLBACK,
|
|
475
|
-
process_id,
|
|
476
|
-
data: input,
|
|
477
|
-
};
|
|
478
|
-
this.fallback = await this.fetchFallback(fallback_tag, additional_logs);
|
|
479
|
-
if (!this.fallback) {
|
|
480
|
-
throw new Error(`Fallback "${fallback_tag}" not found`);
|
|
481
|
-
}
|
|
482
|
-
this.logService.setFeatureId(this.fallback._id);
|
|
483
|
-
this.processEnv = await this.fetchEnv(env, additional_logs);
|
|
484
|
-
if (!this.processEnv.active) {
|
|
485
|
-
throw new Error(`Environment ${data.env} is not active`);
|
|
486
|
-
}
|
|
487
|
-
const { input: fallbackInput, options } = this.fallback;
|
|
488
|
-
// validate feature input and log failure
|
|
489
|
-
this.validateJSONFeatureInput(input, fallbackInput, additional_logs);
|
|
490
|
-
// split processes
|
|
491
|
-
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
492
|
-
return await this.runFallbackOptions(options, input, additional_logs);
|
|
493
|
-
}
|
|
494
|
-
catch (e) {
|
|
495
|
-
this.end = Date.now();
|
|
496
|
-
await this.logService.publish();
|
|
497
|
-
throw e;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
async processFeature(data, awaitResolution = false) {
|
|
501
|
-
this.start = Date.now();
|
|
502
|
-
this.input = data;
|
|
503
|
-
const { product: product_tag, env, input, tag: feature_tag } = data;
|
|
504
|
-
let additional_logs;
|
|
505
|
-
let passedValidation;
|
|
506
|
-
try {
|
|
507
|
-
this.productTag = product_tag;
|
|
508
|
-
additional_logs = {
|
|
509
|
-
name: 'Process feature',
|
|
510
|
-
type: types_1.LogEventTypes.FEATURE,
|
|
511
|
-
};
|
|
512
|
-
await this.intializeProduct(additional_logs);
|
|
513
|
-
this.component = types_1.LogEventTypes.FEATURE;
|
|
514
|
-
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
515
|
-
this.process_id = process_id;
|
|
516
|
-
this.feature = await this.fetchFeature(feature_tag, additional_logs);
|
|
517
|
-
if (!this.feature) {
|
|
518
|
-
throw new Error(`Feature "${feature_tag}" not found`);
|
|
519
|
-
}
|
|
520
|
-
this.baseLogs = {
|
|
521
|
-
product_tag: this.productTag,
|
|
522
|
-
product_id: this.productId,
|
|
523
|
-
workspace_id: this.workspace_id,
|
|
524
|
-
env,
|
|
525
|
-
type: types_1.LogEventTypes.FEATURE,
|
|
526
|
-
process_id,
|
|
527
|
-
data: input,
|
|
528
|
-
feature_tag: feature_tag,
|
|
529
|
-
feature_id: this.feature._id,
|
|
530
|
-
};
|
|
531
|
-
this.logService.setFeatureId(this.feature._id);
|
|
532
|
-
this.processEnv = await this.fetchEnv(env, additional_logs);
|
|
533
|
-
if (!this.processEnv.active) {
|
|
534
|
-
throw new Error(`Environment ${data.env} is not active`);
|
|
535
|
-
}
|
|
536
|
-
const { input: featureInput, sequence, output } = this.feature;
|
|
537
|
-
// validate feature input and log failure
|
|
538
|
-
this.validateJSONFeatureInput(input, featureInput, additional_logs);
|
|
539
|
-
// split processes
|
|
540
|
-
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
541
|
-
await this.processSequenceLevels(additional_logs);
|
|
542
|
-
return { process_id };
|
|
543
|
-
//return this.generateOutput(output as unknown as Record<string, IFeatureOutput>);
|
|
544
|
-
}
|
|
545
|
-
catch (e) {
|
|
546
|
-
this.end = Date.now();
|
|
547
|
-
if (this.logService) {
|
|
548
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process feature - failed', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
549
|
-
await this.logService.publish();
|
|
550
|
-
if (passedValidation) {
|
|
551
|
-
return { process_id: this.process_id };
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
throw e;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
throw e;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
427
|
async intializeProduct(additional_logs) {
|
|
563
428
|
if (!this.logService) {
|
|
564
429
|
this.logService = new logs_service_1.default({
|
|
@@ -615,39 +480,6 @@ class ProcessorService {
|
|
|
615
480
|
throw e;
|
|
616
481
|
}
|
|
617
482
|
}
|
|
618
|
-
async fetchFeature(tag, additional_logs) {
|
|
619
|
-
try {
|
|
620
|
-
const feature = await this.productBuilderService.fetchFeature(tag); // validate feature exists
|
|
621
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch feature - success', data: { tag, feature }, status: types_1.LogEventStatus.SUCCESS }));
|
|
622
|
-
return feature;
|
|
623
|
-
}
|
|
624
|
-
catch (e) {
|
|
625
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch feature - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
626
|
-
throw e;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
async fetchQuota(tag, additional_logs) {
|
|
630
|
-
try {
|
|
631
|
-
const quota = await this.productBuilderService.fetchQuota(tag); // validate feature exists
|
|
632
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch quota - success', data: { tag, quota }, status: types_1.LogEventStatus.SUCCESS }));
|
|
633
|
-
return quota;
|
|
634
|
-
}
|
|
635
|
-
catch (e) {
|
|
636
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch quota - failed', data: { tag, e }, status: types_1.LogEventStatus.FAIL }));
|
|
637
|
-
throw e;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
async fetchFallback(tag, additional_logs) {
|
|
641
|
-
try {
|
|
642
|
-
const fallback = await this.productBuilderService.fetchFallback(tag); // validate feature exists
|
|
643
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch fallback - success', data: { tag, fallback }, status: types_1.LogEventStatus.SUCCESS }));
|
|
644
|
-
return fallback;
|
|
645
|
-
}
|
|
646
|
-
catch (e) {
|
|
647
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch fallback - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
648
|
-
throw e;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
483
|
async fetchEnv(env, additional_logs) {
|
|
652
484
|
try {
|
|
653
485
|
const product_env = await this.productBuilderService.fetchEnv(env); // validate env exists
|
|
@@ -662,271 +494,6 @@ class ProcessorService {
|
|
|
662
494
|
throw e;
|
|
663
495
|
}
|
|
664
496
|
}
|
|
665
|
-
validateJSONFeatureInput(input, feature_input, additional_logs) {
|
|
666
|
-
try {
|
|
667
|
-
(0, processor_utils_1.validateFeatureJSONInput)(input, feature_input);
|
|
668
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
669
|
-
}
|
|
670
|
-
catch (e) {
|
|
671
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
672
|
-
throw e;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
async splitSequenceIntoLevels(data, additional_logs) {
|
|
676
|
-
try {
|
|
677
|
-
const levels = {};
|
|
678
|
-
const tagMap = new Map(data.map((seq) => [seq.tag, seq]));
|
|
679
|
-
const assignedLevels = new Map();
|
|
680
|
-
let currentLevel = 1;
|
|
681
|
-
let remainingSequences = [...data];
|
|
682
|
-
while (remainingSequences.length > 0) {
|
|
683
|
-
const currentLevelSequences = [];
|
|
684
|
-
remainingSequences = remainingSequences.filter((seq) => {
|
|
685
|
-
var _a;
|
|
686
|
-
const parentLevels = ((_a = seq.parents) === null || _a === void 0 ? void 0 : _a.map((parent) => { var _a; return (_a = assignedLevels.get(parent)) !== null && _a !== void 0 ? _a : -1; })) || [];
|
|
687
|
-
const isCurrentLevel = parentLevels.length === 0 || Math.max(...parentLevels) === currentLevel - 1;
|
|
688
|
-
if (isCurrentLevel) {
|
|
689
|
-
currentLevelSequences.push(seq);
|
|
690
|
-
assignedLevels.set(seq.tag, currentLevel);
|
|
691
|
-
return false; // Remove from remainingSequences
|
|
692
|
-
}
|
|
693
|
-
return true;
|
|
694
|
-
});
|
|
695
|
-
if (currentLevelSequences.length > 0) {
|
|
696
|
-
levels[currentLevel] = currentLevelSequences;
|
|
697
|
-
currentLevel++;
|
|
698
|
-
}
|
|
699
|
-
else {
|
|
700
|
-
break; // Prevent infinite loop if there's a cycle
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - success', data: { levels }, status: types_1.LogEventStatus.SUCCESS }));
|
|
704
|
-
return levels;
|
|
705
|
-
}
|
|
706
|
-
catch (e) {
|
|
707
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
708
|
-
throw e;
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
async processSequenceLevels(additional_logs) {
|
|
712
|
-
try {
|
|
713
|
-
const levelEvents = {};
|
|
714
|
-
Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
|
|
715
|
-
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
|
|
716
|
-
});
|
|
717
|
-
let previousLevelComplete = true;
|
|
718
|
-
for (const level of Object.keys(levelEvents)
|
|
719
|
-
.map(Number)
|
|
720
|
-
.sort((a, b) => a - b)) {
|
|
721
|
-
if (previousLevelComplete) {
|
|
722
|
-
previousLevelComplete = await this.processLevelEvents(levelEvents[level], additional_logs);
|
|
723
|
-
}
|
|
724
|
-
else {
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
this.doneWithProcessing = true;
|
|
729
|
-
if (previousLevelComplete && !this.published) {
|
|
730
|
-
let message;
|
|
731
|
-
let status;
|
|
732
|
-
let successful_feature_execution;
|
|
733
|
-
let failed_feature_execution;
|
|
734
|
-
if (this.processingOutput.failure.length === 0) {
|
|
735
|
-
message = 'Process feature - success';
|
|
736
|
-
status = types_1.LogEventStatus.SUCCESS;
|
|
737
|
-
successful_feature_execution = true;
|
|
738
|
-
}
|
|
739
|
-
else if (this.processingFailure) {
|
|
740
|
-
message = 'Process feature - processing';
|
|
741
|
-
status = types_1.LogEventStatus.PROCESSING;
|
|
742
|
-
successful_feature_execution = false;
|
|
743
|
-
failed_feature_execution = false;
|
|
744
|
-
}
|
|
745
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_feature_execution,
|
|
746
|
-
failed_feature_execution,
|
|
747
|
-
message, data: {}, status }));
|
|
748
|
-
await this.logService.publish();
|
|
749
|
-
this.end = Date.now();
|
|
750
|
-
await this.writeResult(status);
|
|
751
|
-
}
|
|
752
|
-
return true;
|
|
753
|
-
}
|
|
754
|
-
catch (e) {
|
|
755
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process sequence levels - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
756
|
-
throw e;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
async processLevelEvents(events, additional_logs) {
|
|
760
|
-
try {
|
|
761
|
-
const promises = events.map((event) => {
|
|
762
|
-
const dependants = this.fetchActionRequestDependents(event.input, additional_logs);
|
|
763
|
-
const passed = this.checkDependentsSuccess(dependants);
|
|
764
|
-
if (passed) {
|
|
765
|
-
// TODO: comparison to see if all depending events are in success || dependants is empty
|
|
766
|
-
return this.processEvent(event);
|
|
767
|
-
}
|
|
768
|
-
else {
|
|
769
|
-
this.addToWaitingOutput(event, dependants);
|
|
770
|
-
}
|
|
771
|
-
});
|
|
772
|
-
return Promise.all(promises);
|
|
773
|
-
}
|
|
774
|
-
catch (e) {
|
|
775
|
-
throw e;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
async processFailedEvents(additional_logs) {
|
|
779
|
-
try {
|
|
780
|
-
const { failure } = this.processingOutput;
|
|
781
|
-
const promises = failure.map((failed) => {
|
|
782
|
-
if (failed.retries_left > 0 && new Date().getTime() > failed.retry_at) {
|
|
783
|
-
return this.processEvent(failed.event); // process events should also take care of this.processingOutput
|
|
784
|
-
}
|
|
785
|
-
if (failed.retries_left === 0 && !failed.allow_fail) {
|
|
786
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess failed events - failed', data: Object.assign(Object.assign({}, failed), { reason: 'Ran out of Retries' }), status: types_1.LogEventStatus.FAIL }));
|
|
787
|
-
throw new Error(`Event ${failed.event.event} failed in sequence ${failed.event.sequence_tag}, ran out of retries and the feature cannot run without it succeeding`);
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
Promise.all(promises);
|
|
791
|
-
}
|
|
792
|
-
catch (e) {
|
|
793
|
-
throw e;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
async processWaitingEvents(additional_logs) {
|
|
797
|
-
try {
|
|
798
|
-
const { waiting } = this.processingOutput;
|
|
799
|
-
const promises = waiting.map((waiting) => {
|
|
800
|
-
const { dependants } = waiting;
|
|
801
|
-
if (this.checkDependentsSuccess(dependants)) {
|
|
802
|
-
// TODO: comparison to see if all depending events are in success || dependants is empty
|
|
803
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess waiting events - initiated', data: Object.assign({}, waiting), status: types_1.LogEventStatus.PROCESSING }));
|
|
804
|
-
return this.processEvent(waiting.event);
|
|
805
|
-
}
|
|
806
|
-
else {
|
|
807
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess waiting events - waiting', data: Object.assign({}, waiting), status: types_1.LogEventStatus.WAITING }));
|
|
808
|
-
}
|
|
809
|
-
});
|
|
810
|
-
return Promise.all(promises);
|
|
811
|
-
}
|
|
812
|
-
catch (e) {
|
|
813
|
-
throw e;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
checkDependentsSuccess(dependants) {
|
|
817
|
-
let pass = true;
|
|
818
|
-
for (let i = 0; i < dependants.length; i++) {
|
|
819
|
-
if (!this.processingOutput.success.find((item) => item.event.sequence_tag === dependants[i].sequence_tag && item.event.event === dependants[i].event_tag)) {
|
|
820
|
-
pass = false;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
return pass;
|
|
824
|
-
}
|
|
825
|
-
fetchActionRequestDependents(input, additional_logs) {
|
|
826
|
-
try {
|
|
827
|
-
const dependents = [];
|
|
828
|
-
if (input.query) {
|
|
829
|
-
dependents.push(...this.fetchDependents(input.query, additional_logs));
|
|
830
|
-
}
|
|
831
|
-
if (input.body) {
|
|
832
|
-
dependents.push(...this.fetchDependents(input.body, additional_logs));
|
|
833
|
-
}
|
|
834
|
-
if (input.headers) {
|
|
835
|
-
dependents.push(...this.fetchDependents(input.headers, additional_logs));
|
|
836
|
-
}
|
|
837
|
-
if (input.params) {
|
|
838
|
-
dependents.push(...this.fetchDependents(input.params, additional_logs));
|
|
839
|
-
}
|
|
840
|
-
if (input.data) {
|
|
841
|
-
dependents.push(...this.fetchDependents(input.data, additional_logs));
|
|
842
|
-
}
|
|
843
|
-
if (input.fileName) {
|
|
844
|
-
dependents.push(...this.valueStringDepsCheck(input.fileName));
|
|
845
|
-
}
|
|
846
|
-
if (input.buffer) {
|
|
847
|
-
dependents.push(...this.valueStringDepsCheck(input.buffer));
|
|
848
|
-
}
|
|
849
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch request dependencies - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), dependents }, status: types_1.LogEventStatus.SUCCESS }));
|
|
850
|
-
return dependents;
|
|
851
|
-
}
|
|
852
|
-
catch (e) {
|
|
853
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch request dependents - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
fetchDependents(obj, additional_logs) {
|
|
857
|
-
try {
|
|
858
|
-
const dependants = [];
|
|
859
|
-
for (const key in obj) {
|
|
860
|
-
const value = obj[key];
|
|
861
|
-
if (typeof value === 'object') {
|
|
862
|
-
if ('function' in value && 'values' in value) {
|
|
863
|
-
const { function: func, values } = value;
|
|
864
|
-
for (let i = 0; i < values.length; i++) {
|
|
865
|
-
if (values[i].startsWith('$Sequence')) {
|
|
866
|
-
const stages = this.productBuilderService.extractStages(values[i]);
|
|
867
|
-
dependants.push({
|
|
868
|
-
sequence_tag: String(stages[0]),
|
|
869
|
-
event_tag: String(stages[1]),
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
else if (values[i].startsWith('$')) {
|
|
873
|
-
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(values[i]);
|
|
874
|
-
if (funcArgs.args.length) {
|
|
875
|
-
funcArgs.args.map((arg) => {
|
|
876
|
-
if (arg.startsWith('$Sequence')) {
|
|
877
|
-
const stages = this.productBuilderService.extractStages(arg);
|
|
878
|
-
dependants.push({
|
|
879
|
-
sequence_tag: String(stages[0]),
|
|
880
|
-
event_tag: String(stages[1]),
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
else {
|
|
889
|
-
dependants.push(...this.fetchDependents(value, additional_logs));
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
else if (typeof value === 'string') {
|
|
893
|
-
dependants.push(...this.valueStringDepsCheck(value.trim()));
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
return dependants;
|
|
897
|
-
}
|
|
898
|
-
catch (e) {
|
|
899
|
-
throw e;
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
valueStringDepsCheck(value) {
|
|
903
|
-
const dependants = [];
|
|
904
|
-
if (value.startsWith('$Sequence')) {
|
|
905
|
-
const stages = this.productBuilderService.extractStages(value);
|
|
906
|
-
dependants.push({ sequence_tag: String(stages[0]), event_tag: String(stages[1]) });
|
|
907
|
-
}
|
|
908
|
-
else if (value.startsWith('$')) {
|
|
909
|
-
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(value);
|
|
910
|
-
if (funcArgs && funcArgs.args.length) {
|
|
911
|
-
funcArgs.args.map((arg) => {
|
|
912
|
-
if (arg.startsWith('$Sequence')) {
|
|
913
|
-
const stages = this.productBuilderService.extractStages(arg);
|
|
914
|
-
dependants.push({
|
|
915
|
-
sequence_tag: String(stages[0]),
|
|
916
|
-
event_tag: String(stages[1]),
|
|
917
|
-
});
|
|
918
|
-
}
|
|
919
|
-
else {
|
|
920
|
-
const args = arg.split(',');
|
|
921
|
-
args.map((arg) => {
|
|
922
|
-
dependants.push(...this.valueStringDepsCheck(arg.trim()));
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
});
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
return dependants;
|
|
929
|
-
}
|
|
930
497
|
async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
|
|
931
498
|
try {
|
|
932
499
|
const payload = {};
|
|
@@ -986,7 +553,7 @@ class ProcessorService {
|
|
|
986
553
|
async generatePayload(obj, event, additional_logs, sample = [], index = {}, loopIndex = null) {
|
|
987
554
|
try {
|
|
988
555
|
const payload = {};
|
|
989
|
-
console.log(
|
|
556
|
+
console.log('Payload Construction', { obj, event, sample, index, loopIndex });
|
|
990
557
|
const keys = Object.keys(obj);
|
|
991
558
|
for (let i = 0; i < keys.length; i++) {
|
|
992
559
|
const key = keys[i];
|
|
@@ -1033,17 +600,17 @@ class ProcessorService {
|
|
|
1033
600
|
if (value.startsWith('$Auth{') && value.endsWith('}')) {
|
|
1034
601
|
// should only be allowed in apps
|
|
1035
602
|
// Convert stages to string[] for functions expecting string[]
|
|
1036
|
-
const stringStages = stages.map(stage => String(stage));
|
|
603
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
1037
604
|
return await this.generateAuthValue(stringStages, app, sample, additional_logs);
|
|
1038
605
|
}
|
|
1039
606
|
else if (value.startsWith('$Sequence{') && value.endsWith('}')) {
|
|
1040
607
|
// Convert stages to string[] for functions expecting string[]
|
|
1041
|
-
const stringStages = stages.map(stage => String(stage));
|
|
608
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
1042
609
|
return await this.generateSequenceValue(stringStages, locatorFor$Index, loopIndex); // pass
|
|
1043
610
|
}
|
|
1044
611
|
else if (value.startsWith('$Input{') && value.endsWith('}')) {
|
|
1045
612
|
// Convert stages to string[] for functions expecting string[]
|
|
1046
|
-
const stringStages = stages.map(stage => String(stage));
|
|
613
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
1047
614
|
return await this.generateInputValue(this.input.input, stringStages);
|
|
1048
615
|
}
|
|
1049
616
|
else if (value === '$Default') {
|
|
@@ -1051,12 +618,12 @@ class ProcessorService {
|
|
|
1051
618
|
}
|
|
1052
619
|
else if (value.startsWith('$Variable{') && value.endsWith('}')) {
|
|
1053
620
|
// Convert stages to string[] for functions expecting string[]
|
|
1054
|
-
const stringStages = stages.map(stage => String(stage));
|
|
621
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
1055
622
|
return await this.generateVariableValue(stringStages);
|
|
1056
623
|
}
|
|
1057
624
|
else if (value.startsWith('$Constant{') && value.endsWith('}')) {
|
|
1058
625
|
// Convert stages to string[] for functions expecting string[]
|
|
1059
|
-
const stringStages = stages.map(stage => String(stage));
|
|
626
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
1060
627
|
return await this.generateConstantValue(stringStages);
|
|
1061
628
|
}
|
|
1062
629
|
else if (value.startsWith('$Size{') || value.startsWith('$Length{')) {
|
|
@@ -1501,7 +1068,7 @@ class ProcessorService {
|
|
|
1501
1068
|
}
|
|
1502
1069
|
async generateAuthValue(stages, app, sample, additional_logs) {
|
|
1503
1070
|
try {
|
|
1504
|
-
console.log(
|
|
1071
|
+
console.log('Generate Auth Data', { stages, app, sample });
|
|
1505
1072
|
let auth_data = await this.fetchAuthData(app, additional_logs); //TODO: should use stages[0]
|
|
1506
1073
|
// take the app tag in index 0..
|
|
1507
1074
|
if (!auth_data) {
|
|
@@ -1528,7 +1095,7 @@ class ProcessorService {
|
|
|
1528
1095
|
if (!env.auth) {
|
|
1529
1096
|
throw new Error(`App ${app_tag} in auth needs to have a definition for auth in env: ${this.processEnv.slug}`);
|
|
1530
1097
|
}
|
|
1531
|
-
console.log(
|
|
1098
|
+
console.log('Envroment', env.auth);
|
|
1532
1099
|
let values = env.auth.values;
|
|
1533
1100
|
if (!values) {
|
|
1534
1101
|
// no auth values
|
|
@@ -1536,7 +1103,7 @@ class ProcessorService {
|
|
|
1536
1103
|
}
|
|
1537
1104
|
if (!env.auth.expiry || (env.auth.expiry && Date.now() > new Date(env.auth.expiry).getTime())) {
|
|
1538
1105
|
// refresh
|
|
1539
|
-
console.log(
|
|
1106
|
+
console.log('REFRESH DATA', env, app_tag);
|
|
1540
1107
|
values = await this.getAndStoreAuth(env, app_tag);
|
|
1541
1108
|
}
|
|
1542
1109
|
const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchPrivateKey());
|
|
@@ -1591,16 +1158,6 @@ class ProcessorService {
|
|
|
1591
1158
|
};
|
|
1592
1159
|
return this.runAction(event, additional_logs);
|
|
1593
1160
|
}
|
|
1594
|
-
if (event.type === types_1.FeatureEventTypes.DB_ACTION) {
|
|
1595
|
-
const [parent_tag, child_tag] = event.event.split(':');
|
|
1596
|
-
const additional_logs = {
|
|
1597
|
-
parent_tag,
|
|
1598
|
-
child_tag,
|
|
1599
|
-
type: types_1.LogEventTypes.DB_ACTION,
|
|
1600
|
-
name: 'Process feature database action',
|
|
1601
|
-
};
|
|
1602
|
-
return this.runDBAction(event, additional_logs);
|
|
1603
|
-
}
|
|
1604
1161
|
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
1605
1162
|
this.clone = (0, processor_utils_1.structuredClone)(event);
|
|
1606
1163
|
(0, processor_utils_1.cleanBlob)(this.clone);
|
|
@@ -1611,14 +1168,6 @@ class ProcessorService {
|
|
|
1611
1168
|
};
|
|
1612
1169
|
return this.runStorage(event, additional_logs);
|
|
1613
1170
|
}
|
|
1614
|
-
if (event.type === types_1.FeatureEventTypes.FEATURE) {
|
|
1615
|
-
const additional_logs = {
|
|
1616
|
-
parent_tag: event.event,
|
|
1617
|
-
type: types_1.LogEventTypes.FEATURE,
|
|
1618
|
-
name: 'Process sub-feature',
|
|
1619
|
-
};
|
|
1620
|
-
return this.runFeature(event, additional_logs);
|
|
1621
|
-
}
|
|
1622
1171
|
if (event.type === types_1.FeatureEventTypes.NOTIFICATION) {
|
|
1623
1172
|
const [parent_tag, child_tag] = event.event.split(':');
|
|
1624
1173
|
const additional_logs = {
|
|
@@ -1640,8 +1189,7 @@ class ProcessorService {
|
|
|
1640
1189
|
try {
|
|
1641
1190
|
return this.runBrokerPublish(event, additional_logs);
|
|
1642
1191
|
}
|
|
1643
|
-
catch (e) {
|
|
1644
|
-
}
|
|
1192
|
+
catch (e) { }
|
|
1645
1193
|
}
|
|
1646
1194
|
if (event.type === types_1.FeatureEventTypes.JOB) {
|
|
1647
1195
|
const additional_logs = {
|
|
@@ -1657,7 +1205,7 @@ class ProcessorService {
|
|
|
1657
1205
|
input: event.input,
|
|
1658
1206
|
start_at: event.start_at || 0,
|
|
1659
1207
|
cache: event.cache,
|
|
1660
|
-
session: this.input.session
|
|
1208
|
+
session: this.input.session,
|
|
1661
1209
|
};
|
|
1662
1210
|
// TODO: fix this
|
|
1663
1211
|
return this.processJob(input, additional_logs);
|
|
@@ -1667,181 +1215,556 @@ class ProcessorService {
|
|
|
1667
1215
|
throw e;
|
|
1668
1216
|
}
|
|
1669
1217
|
}
|
|
1670
|
-
async runFeature(event, additional_logs) {
|
|
1671
|
-
const freshInstance = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
1672
|
-
const result = await freshInstance.processFeature({
|
|
1673
|
-
product: this.productTag,
|
|
1674
|
-
tag: event.event,
|
|
1675
|
-
env: this.processEnv.slug,
|
|
1676
|
-
input: event.input,
|
|
1677
|
-
}, true);
|
|
1678
|
-
const output = await freshInstance.generateOutput(result.process_id);
|
|
1679
|
-
if (output.status === types_1.LogEventStatus.FAIL) {
|
|
1680
|
-
await this.addToFailureOutput(output.errors, event, { process_id: result.process_id }, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
|
|
1681
|
-
}
|
|
1682
|
-
else if (output.status === types_1.LogEventStatus.SUCCESS) {
|
|
1683
|
-
await this.addToSuccessOutput(event, output.data, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
|
|
1684
|
-
}
|
|
1685
|
-
return output;
|
|
1686
|
-
}
|
|
1687
1218
|
async runJobs(job, additional_logs = {}) {
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
|
|
1695
|
-
if (!result) {
|
|
1696
|
-
throw new Error(`Invalid process id ${process_id}`);
|
|
1219
|
+
var _a;
|
|
1220
|
+
const jobId = (_a = job.data) === null || _a === void 0 ? void 0 : _a._job_id;
|
|
1221
|
+
const jobType = job.name;
|
|
1222
|
+
// Update job status to running
|
|
1223
|
+
if (jobId && this.redisClient) {
|
|
1224
|
+
await this.updateJobStatus(jobId, 'running', { started_at: Date.now() });
|
|
1697
1225
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
}
|
|
1703
|
-
async generateOutput(process_id) {
|
|
1704
|
-
var _a, _b, _c, _d;
|
|
1705
|
-
const result = await this.fetchResult(process_id);
|
|
1706
|
-
if (result.component === types_1.LogEventTypes.FEATURE) {
|
|
1707
|
-
const additional_logs = {
|
|
1708
|
-
parent_tag: result.input.tag,
|
|
1709
|
-
type: types_1.LogEventTypes.FEATURE,
|
|
1710
|
-
name: 'Fetching Process Result',
|
|
1711
|
-
};
|
|
1712
|
-
if (result.status === types_1.LogEventStatus.PROCESSING) {
|
|
1713
|
-
return { process_id, status: result.status };
|
|
1226
|
+
try {
|
|
1227
|
+
let result;
|
|
1228
|
+
if (jobType === types_1.JobEventTypes.ACTION || jobType === types_1.FeatureEventTypes.ACTION) {
|
|
1229
|
+
result = await this.processAction(job.data);
|
|
1714
1230
|
}
|
|
1715
|
-
else if (
|
|
1716
|
-
|
|
1717
|
-
await this.intializeProduct(additional_logs);
|
|
1718
|
-
this.processingOutput = result.result;
|
|
1719
|
-
this.process_id = process_id;
|
|
1720
|
-
this.input = result.input;
|
|
1721
|
-
this.feature = await this.fetchFeature(result.input.tag, additional_logs);
|
|
1722
|
-
const { input: featureInput, sequence, output } = this.feature;
|
|
1723
|
-
const data = await this.generatePayload(output, null, additional_logs, []);
|
|
1724
|
-
return { process_id, status: result.status, data };
|
|
1231
|
+
else if (jobType === types_1.JobEventTypes.NOTIFICATION) {
|
|
1232
|
+
result = await this.processNotification(job.data);
|
|
1725
1233
|
}
|
|
1726
|
-
else if (
|
|
1727
|
-
|
|
1728
|
-
return { process_id, status: result.status, errors };
|
|
1234
|
+
else if (jobType === types_1.JobEventTypes.STORAGE) {
|
|
1235
|
+
result = await this.processStorage(job.data);
|
|
1729
1236
|
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
if ((_a = result.result.success[0]) === null || _a === void 0 ? void 0 : _a.output) {
|
|
1733
|
-
return { process_id, status: result.status, data: (_b = result.result.success[0]) === null || _b === void 0 ? void 0 : _b.output };
|
|
1237
|
+
else if (jobType === types_1.JobEventTypes.PUBLISH) {
|
|
1238
|
+
result = await this.processMessageBrokerPublish(job.data);
|
|
1734
1239
|
}
|
|
1735
|
-
else if (
|
|
1736
|
-
|
|
1240
|
+
else if (jobType === types_1.JobEventTypes.DATABASE_ACTION) {
|
|
1241
|
+
// Database actions use processAction with database-specific input
|
|
1242
|
+
result = await this.processDatabaseAction(job.data);
|
|
1243
|
+
}
|
|
1244
|
+
else if (jobType === types_1.JobEventTypes.DATABASE_OPERATION) {
|
|
1245
|
+
// Handle database operations
|
|
1246
|
+
result = await this.processDatabaseOperation(job.data);
|
|
1247
|
+
}
|
|
1248
|
+
else if (jobType === types_1.JobEventTypes.GRAPH_ACTION) {
|
|
1249
|
+
result = await this.processGraphAction(job.data);
|
|
1250
|
+
}
|
|
1251
|
+
else if (jobType === types_1.JobEventTypes.GRAPH_OPERATION) {
|
|
1252
|
+
result = await this.processGraphOperation(job.data);
|
|
1253
|
+
}
|
|
1254
|
+
else if (jobType === types_1.JobEventTypes.WORKFLOW) {
|
|
1255
|
+
result = await this.processWorkflow(job.data);
|
|
1737
1256
|
}
|
|
1738
1257
|
else {
|
|
1739
|
-
|
|
1258
|
+
throw new Error(`Unknown job type: ${jobType}`);
|
|
1740
1259
|
}
|
|
1260
|
+
// Update job status to completed
|
|
1261
|
+
if (jobId && this.redisClient) {
|
|
1262
|
+
await this.updateJobStatus(jobId, 'completed', {
|
|
1263
|
+
completed_at: Date.now(),
|
|
1264
|
+
result,
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
return result;
|
|
1741
1268
|
}
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1269
|
+
catch (error) {
|
|
1270
|
+
// Update job status to failed or schedule retry
|
|
1271
|
+
if (jobId && this.redisClient) {
|
|
1272
|
+
const jobData = await this.getJobData(jobId);
|
|
1273
|
+
if (jobData) {
|
|
1274
|
+
const { shouldRetry, delay } = this.calculateJobRetry(jobData, error.code);
|
|
1275
|
+
if (shouldRetry) {
|
|
1276
|
+
await this.updateJobStatus(jobId, 'scheduled', {
|
|
1277
|
+
retry_count: (jobData.retry_count || 0) + 1,
|
|
1278
|
+
last_error: error.message,
|
|
1279
|
+
last_error_code: error.code,
|
|
1280
|
+
scheduled_at: Date.now() + delay,
|
|
1281
|
+
});
|
|
1282
|
+
// Re-queue the job with delay
|
|
1283
|
+
await this.queues.jobs.add(jobType, job.data, {
|
|
1284
|
+
jobId: `${jobId}_retry_${jobData.retry_count + 1}`,
|
|
1285
|
+
delay,
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
else {
|
|
1289
|
+
await this.updateJobStatus(jobId, 'failed', {
|
|
1290
|
+
completed_at: Date.now(),
|
|
1291
|
+
last_error: error.message,
|
|
1292
|
+
last_error_code: error.code,
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
// Add to execution history
|
|
1296
|
+
await this.addJobExecution(jobId, {
|
|
1297
|
+
number: (jobData.execution_count || 0) + 1,
|
|
1298
|
+
started_at: jobData.started_at || Date.now(),
|
|
1299
|
+
completed_at: Date.now(),
|
|
1300
|
+
duration_ms: Date.now() - (jobData.started_at || Date.now()),
|
|
1301
|
+
status: 'failed',
|
|
1302
|
+
error: error.message,
|
|
1303
|
+
error_code: error.code,
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1779
1306
|
}
|
|
1780
|
-
|
|
1307
|
+
throw error;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Get job data from Redis
|
|
1312
|
+
*/
|
|
1313
|
+
async getJobData(jobId) {
|
|
1314
|
+
if (!this.redisClient)
|
|
1315
|
+
return null;
|
|
1316
|
+
const redis = this.redisClient;
|
|
1317
|
+
const jobKey = `job:${this.workspace_id}:${jobId}`;
|
|
1318
|
+
const data = await redis.get(jobKey);
|
|
1319
|
+
if (!data)
|
|
1320
|
+
return null;
|
|
1321
|
+
return JSON.parse(data);
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Update job status in Redis
|
|
1325
|
+
*/
|
|
1326
|
+
async updateJobStatus(jobId, status, updates = {}) {
|
|
1327
|
+
if (!this.redisClient)
|
|
1328
|
+
return;
|
|
1329
|
+
const redis = this.redisClient;
|
|
1330
|
+
const jobKey = `job:${this.workspace_id}:${jobId}`;
|
|
1331
|
+
const data = await redis.get(jobKey);
|
|
1332
|
+
if (!data)
|
|
1333
|
+
return;
|
|
1334
|
+
const jobData = JSON.parse(data);
|
|
1335
|
+
const oldStatus = jobData.status;
|
|
1336
|
+
const updatedJob = Object.assign(Object.assign(Object.assign({}, jobData), updates), { status, updated_at: Date.now(), execution_count: status === 'completed' || status === 'failed'
|
|
1337
|
+
? (jobData.execution_count || 0) + 1
|
|
1338
|
+
: jobData.execution_count });
|
|
1339
|
+
// Update job data
|
|
1340
|
+
await redis.setex(jobKey, 90 * 24 * 60 * 60, JSON.stringify(updatedJob));
|
|
1341
|
+
// Update status indices
|
|
1342
|
+
if (oldStatus !== status) {
|
|
1343
|
+
const oldStatusKey = `job_status:${this.workspace_id}:${oldStatus}`;
|
|
1344
|
+
const newStatusKey = `job_status:${this.workspace_id}:${status}`;
|
|
1345
|
+
await redis.srem(oldStatusKey, jobId);
|
|
1346
|
+
await redis.sadd(newStatusKey, jobId);
|
|
1781
1347
|
}
|
|
1782
|
-
return { process_id };
|
|
1783
1348
|
}
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1349
|
+
/**
|
|
1350
|
+
* Add job execution record to history
|
|
1351
|
+
*/
|
|
1352
|
+
async addJobExecution(jobId, execution) {
|
|
1353
|
+
if (!this.redisClient)
|
|
1354
|
+
return;
|
|
1355
|
+
const redis = this.redisClient;
|
|
1356
|
+
const historyKey = `job_history:${this.workspace_id}:${jobId}`;
|
|
1357
|
+
await redis.lpush(historyKey, JSON.stringify(execution));
|
|
1358
|
+
await redis.ltrim(historyKey, 0, 99); // Keep last 100 executions
|
|
1359
|
+
await redis.expire(historyKey, 30 * 24 * 60 * 60); // 30 days TTL
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Calculate retry delay based on job configuration
|
|
1363
|
+
*/
|
|
1364
|
+
calculateJobRetry(jobData, errorCode) {
|
|
1365
|
+
const retryConfig = jobData.retry_config || {};
|
|
1366
|
+
const { initialDelay = 1000, maxDelay = 300000, backoffMultiplier = 2, retryableErrors, nonRetryableErrors, jitter = false, jitterPercent = 0.3, } = retryConfig;
|
|
1367
|
+
// Check if we've exceeded max retries
|
|
1368
|
+
if ((jobData.retry_count || 0) >= (jobData.retries || 0)) {
|
|
1369
|
+
return { shouldRetry: false, delay: 0 };
|
|
1789
1370
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
name: 'Replay Process',
|
|
1799
|
-
};
|
|
1800
|
-
await this.intializeProduct(additional_logs);
|
|
1801
|
-
//await this.processFailedEvents(additional_logs);
|
|
1802
|
-
if (result.component === types_1.LogEventTypes.FEATURE) {
|
|
1803
|
-
//await this.processWaitingEvents(additional_logs);
|
|
1804
|
-
this.feature = await this.fetchFeature(result.input.tag, additional_logs);
|
|
1805
|
-
const { input: featureInput, sequence, output } = this.feature;
|
|
1806
|
-
this.processEnv = await this.fetchEnv(result.env, additional_logs);
|
|
1807
|
-
if (!this.processEnv.active) {
|
|
1808
|
-
throw new Error(`Environment ${result.env} is not active`);
|
|
1809
|
-
}
|
|
1810
|
-
// validate feature input and log failure
|
|
1811
|
-
this.validateJSONFeatureInput(result.input.input, featureInput, additional_logs);
|
|
1812
|
-
// split processes
|
|
1813
|
-
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1814
|
-
await this.processSequenceLevels(additional_logs);
|
|
1371
|
+
// Check error-based retry rules
|
|
1372
|
+
if (errorCode) {
|
|
1373
|
+
if (nonRetryableErrors === null || nonRetryableErrors === void 0 ? void 0 : nonRetryableErrors.includes(errorCode)) {
|
|
1374
|
+
return { shouldRetry: false, delay: 0 };
|
|
1375
|
+
}
|
|
1376
|
+
if (retryableErrors && !retryableErrors.includes(errorCode)) {
|
|
1377
|
+
return { shouldRetry: false, delay: 0 };
|
|
1378
|
+
}
|
|
1815
1379
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
await this.processEvent(event);
|
|
1824
|
-
this.end = Date.now();
|
|
1825
|
-
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
1826
|
-
await this.logService.publish();
|
|
1380
|
+
// Calculate exponential backoff delay
|
|
1381
|
+
let delay = initialDelay * Math.pow(backoffMultiplier, jobData.retry_count || 0);
|
|
1382
|
+
delay = Math.min(delay, maxDelay);
|
|
1383
|
+
// Add jitter if enabled
|
|
1384
|
+
if (jitter) {
|
|
1385
|
+
const jitterAmount = delay * jitterPercent * Math.random();
|
|
1386
|
+
delay = delay + jitterAmount;
|
|
1827
1387
|
}
|
|
1828
|
-
return {
|
|
1388
|
+
return { shouldRetry: true, delay: Math.round(delay) };
|
|
1829
1389
|
}
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1390
|
+
/**
|
|
1391
|
+
* Process database action job (predefined database actions)
|
|
1392
|
+
* Integrates with the database action manager to execute predefined operations
|
|
1393
|
+
*/
|
|
1394
|
+
async processDatabaseAction(data) {
|
|
1395
|
+
var _a;
|
|
1396
|
+
const { env, product, database, event, input } = data;
|
|
1397
|
+
// Initialize product builder if not already done
|
|
1398
|
+
if (product) {
|
|
1399
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1400
|
+
}
|
|
1401
|
+
// Fetch the database action configuration
|
|
1402
|
+
const databaseAction = await this.productBuilderService.fetchDatabaseAction(`${database}:${event}`);
|
|
1403
|
+
if (!databaseAction) {
|
|
1404
|
+
throw new Error(`Database action '${event}' not found on database '${database}'`);
|
|
1405
|
+
}
|
|
1406
|
+
// Get the database environment configuration
|
|
1407
|
+
const databaseConfig = await this.productBuilderService.fetchDatabase(database);
|
|
1408
|
+
if (!databaseConfig) {
|
|
1409
|
+
throw new Error(`Database '${database}' not found`);
|
|
1410
|
+
}
|
|
1411
|
+
const databaseEnv = (_a = databaseConfig.envs) === null || _a === void 0 ? void 0 : _a.find((e) => e.slug === env);
|
|
1412
|
+
if (!databaseEnv) {
|
|
1413
|
+
throw new Error(`Environment '${env}' not found for database '${database}'`);
|
|
1414
|
+
}
|
|
1415
|
+
// Execute the database action using the database service
|
|
1416
|
+
const { DatabaseService } = await Promise.resolve().then(() => __importStar(require('../../database/databases.service')));
|
|
1417
|
+
const dbService = new DatabaseService({
|
|
1418
|
+
workspace_id: this.workspace_id,
|
|
1419
|
+
public_key: this.public_key,
|
|
1420
|
+
user_id: this.user_id,
|
|
1421
|
+
token: this.token,
|
|
1422
|
+
env_type: this.environment,
|
|
1423
|
+
});
|
|
1424
|
+
const result = await dbService.execute({
|
|
1425
|
+
product,
|
|
1426
|
+
env,
|
|
1427
|
+
database,
|
|
1428
|
+
action: event,
|
|
1429
|
+
input: input || {},
|
|
1430
|
+
});
|
|
1431
|
+
return { success: true, data: result };
|
|
1836
1432
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1433
|
+
/**
|
|
1434
|
+
* Process database operation job (direct CRUD operations)
|
|
1435
|
+
* Handles operations like insert, find, update, delete, aggregate
|
|
1436
|
+
*/
|
|
1437
|
+
async processDatabaseOperation(data) {
|
|
1438
|
+
var _a;
|
|
1439
|
+
const { env, product, database, operation, input } = data;
|
|
1440
|
+
// Initialize product builder if not already done
|
|
1441
|
+
if (product) {
|
|
1442
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1443
|
+
}
|
|
1444
|
+
// Get the database configuration
|
|
1445
|
+
const databaseConfig = await this.productBuilderService.fetchDatabase(database);
|
|
1446
|
+
if (!databaseConfig) {
|
|
1447
|
+
throw new Error(`Database '${database}' not found`);
|
|
1448
|
+
}
|
|
1449
|
+
const databaseEnv = (_a = databaseConfig.envs) === null || _a === void 0 ? void 0 : _a.find((e) => e.slug === env);
|
|
1450
|
+
if (!databaseEnv) {
|
|
1451
|
+
throw new Error(`Environment '${env}' not found for database '${database}'`);
|
|
1452
|
+
}
|
|
1453
|
+
// Execute the database operation using the database service
|
|
1454
|
+
const { DatabaseService } = await Promise.resolve().then(() => __importStar(require('../../database/databases.service')));
|
|
1455
|
+
const dbService = new DatabaseService({
|
|
1456
|
+
workspace_id: this.workspace_id,
|
|
1457
|
+
public_key: this.public_key,
|
|
1458
|
+
user_id: this.user_id,
|
|
1459
|
+
token: this.token,
|
|
1460
|
+
env_type: this.environment,
|
|
1461
|
+
});
|
|
1462
|
+
// Connect to the database
|
|
1463
|
+
await dbService.connect({
|
|
1464
|
+
product,
|
|
1465
|
+
env,
|
|
1466
|
+
database,
|
|
1467
|
+
});
|
|
1468
|
+
let result;
|
|
1469
|
+
// Execute the appropriate operation based on the operation type
|
|
1470
|
+
switch (operation) {
|
|
1471
|
+
case 'insert':
|
|
1472
|
+
result = await dbService.insert({
|
|
1473
|
+
product,
|
|
1474
|
+
env,
|
|
1475
|
+
database,
|
|
1476
|
+
table: input.table,
|
|
1477
|
+
data: input.data,
|
|
1478
|
+
returning: input.returning,
|
|
1479
|
+
});
|
|
1480
|
+
break;
|
|
1481
|
+
case 'find':
|
|
1482
|
+
case 'query':
|
|
1483
|
+
result = await dbService.query({
|
|
1484
|
+
product,
|
|
1485
|
+
env,
|
|
1486
|
+
database,
|
|
1487
|
+
table: input.table,
|
|
1488
|
+
where: input.where,
|
|
1489
|
+
select: input.select,
|
|
1490
|
+
include: input.include,
|
|
1491
|
+
orderBy: input.orderBy,
|
|
1492
|
+
limit: input.limit,
|
|
1493
|
+
offset: input.offset,
|
|
1494
|
+
});
|
|
1495
|
+
break;
|
|
1496
|
+
case 'update':
|
|
1497
|
+
result = await dbService.update({
|
|
1498
|
+
product,
|
|
1499
|
+
env,
|
|
1500
|
+
database,
|
|
1501
|
+
table: input.table,
|
|
1502
|
+
data: input.data,
|
|
1503
|
+
where: input.where,
|
|
1504
|
+
returning: input.returning,
|
|
1505
|
+
});
|
|
1506
|
+
break;
|
|
1507
|
+
case 'delete':
|
|
1508
|
+
result = await dbService.delete({
|
|
1509
|
+
product,
|
|
1510
|
+
env,
|
|
1511
|
+
database,
|
|
1512
|
+
table: input.table,
|
|
1513
|
+
where: input.where,
|
|
1514
|
+
});
|
|
1515
|
+
break;
|
|
1516
|
+
case 'upsert':
|
|
1517
|
+
result = await dbService.upsert({
|
|
1518
|
+
product,
|
|
1519
|
+
env,
|
|
1520
|
+
database,
|
|
1521
|
+
table: input.table,
|
|
1522
|
+
data: input.data,
|
|
1523
|
+
conflictKeys: input.conflictKeys || input.conflictFields,
|
|
1524
|
+
updateColumns: input.updateColumns,
|
|
1525
|
+
returning: input.returning,
|
|
1526
|
+
});
|
|
1527
|
+
break;
|
|
1528
|
+
case 'aggregate':
|
|
1529
|
+
result = await dbService.aggregate({
|
|
1530
|
+
product,
|
|
1531
|
+
env,
|
|
1532
|
+
database,
|
|
1533
|
+
table: input.table,
|
|
1534
|
+
operations: input.operations,
|
|
1535
|
+
where: input.where,
|
|
1536
|
+
});
|
|
1537
|
+
break;
|
|
1538
|
+
case 'groupBy':
|
|
1539
|
+
result = await dbService.groupBy({
|
|
1540
|
+
product,
|
|
1541
|
+
env,
|
|
1542
|
+
database,
|
|
1543
|
+
table: input.table,
|
|
1544
|
+
groupBy: input.groupBy || input.by,
|
|
1545
|
+
operations: input.operations,
|
|
1546
|
+
where: input.where,
|
|
1547
|
+
having: input.having,
|
|
1548
|
+
orderBy: input.orderBy,
|
|
1549
|
+
limit: input.limit,
|
|
1550
|
+
offset: input.offset,
|
|
1551
|
+
});
|
|
1552
|
+
break;
|
|
1553
|
+
case 'count':
|
|
1554
|
+
result = await dbService.count({
|
|
1555
|
+
product,
|
|
1556
|
+
env,
|
|
1557
|
+
database,
|
|
1558
|
+
table: input.table,
|
|
1559
|
+
where: input.where,
|
|
1560
|
+
});
|
|
1561
|
+
break;
|
|
1562
|
+
default:
|
|
1563
|
+
throw new Error(`Unknown database operation: ${operation}`);
|
|
1843
1564
|
}
|
|
1844
|
-
return
|
|
1565
|
+
return { success: true, data: result };
|
|
1566
|
+
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Process graph action job (predefined graph actions)
|
|
1569
|
+
* Integrates with the graph service to execute predefined graph operations
|
|
1570
|
+
*/
|
|
1571
|
+
async processGraphAction(data) {
|
|
1572
|
+
const { env, product, graph, event, input } = data;
|
|
1573
|
+
// Initialize product builder if not already done
|
|
1574
|
+
if (product) {
|
|
1575
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1576
|
+
}
|
|
1577
|
+
// Execute the graph action using the graph service
|
|
1578
|
+
const { GraphService } = await Promise.resolve().then(() => __importStar(require('../../graph/graphs.service')));
|
|
1579
|
+
const graphService = new GraphService({
|
|
1580
|
+
workspace_id: this.workspace_id,
|
|
1581
|
+
public_key: this.public_key,
|
|
1582
|
+
user_id: this.user_id,
|
|
1583
|
+
token: this.token,
|
|
1584
|
+
env_type: this.environment,
|
|
1585
|
+
});
|
|
1586
|
+
// Connect to the graph database
|
|
1587
|
+
await graphService.connect({
|
|
1588
|
+
product,
|
|
1589
|
+
env,
|
|
1590
|
+
graph,
|
|
1591
|
+
});
|
|
1592
|
+
// Execute the graph action
|
|
1593
|
+
const result = await graphService.execute({
|
|
1594
|
+
product,
|
|
1595
|
+
env,
|
|
1596
|
+
graph,
|
|
1597
|
+
action: event,
|
|
1598
|
+
input: input || {},
|
|
1599
|
+
});
|
|
1600
|
+
return { success: result.success, data: result.data, error: result.error };
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Process graph operation job (direct graph operations)
|
|
1604
|
+
* Handles operations like createNode, findNodes, createRelationship, traverse, etc.
|
|
1605
|
+
*/
|
|
1606
|
+
async processGraphOperation(data) {
|
|
1607
|
+
const { env, product, graph, operation, input } = data;
|
|
1608
|
+
// Initialize product builder if not already done
|
|
1609
|
+
if (product) {
|
|
1610
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1611
|
+
}
|
|
1612
|
+
// Execute the graph operation using the graph service
|
|
1613
|
+
const { GraphService } = await Promise.resolve().then(() => __importStar(require('../../graph/graphs.service')));
|
|
1614
|
+
const graphService = new GraphService({
|
|
1615
|
+
workspace_id: this.workspace_id,
|
|
1616
|
+
public_key: this.public_key,
|
|
1617
|
+
user_id: this.user_id,
|
|
1618
|
+
token: this.token,
|
|
1619
|
+
env_type: this.environment,
|
|
1620
|
+
});
|
|
1621
|
+
// Connect to the graph database
|
|
1622
|
+
await graphService.connect({
|
|
1623
|
+
product,
|
|
1624
|
+
env,
|
|
1625
|
+
graph,
|
|
1626
|
+
});
|
|
1627
|
+
let result;
|
|
1628
|
+
// Execute the appropriate operation based on the operation type
|
|
1629
|
+
switch (operation) {
|
|
1630
|
+
case 'createNode':
|
|
1631
|
+
result = await graphService.createNode({
|
|
1632
|
+
labels: input.labels,
|
|
1633
|
+
properties: input.properties,
|
|
1634
|
+
});
|
|
1635
|
+
break;
|
|
1636
|
+
case 'findNodes':
|
|
1637
|
+
result = await graphService.findNodes({
|
|
1638
|
+
labels: input.labels,
|
|
1639
|
+
where: input.where,
|
|
1640
|
+
limit: input.limit,
|
|
1641
|
+
offset: input.offset,
|
|
1642
|
+
orderBy: input.orderBy,
|
|
1643
|
+
});
|
|
1644
|
+
break;
|
|
1645
|
+
case 'findNodeById':
|
|
1646
|
+
result = await graphService.findNodeById(input.id);
|
|
1647
|
+
break;
|
|
1648
|
+
case 'updateNode':
|
|
1649
|
+
result = await graphService.updateNode({
|
|
1650
|
+
id: input.id,
|
|
1651
|
+
properties: input.properties,
|
|
1652
|
+
labels: input.labels,
|
|
1653
|
+
});
|
|
1654
|
+
break;
|
|
1655
|
+
case 'deleteNode':
|
|
1656
|
+
result = await graphService.deleteNode({
|
|
1657
|
+
id: input.id,
|
|
1658
|
+
detach: input.detach,
|
|
1659
|
+
});
|
|
1660
|
+
break;
|
|
1661
|
+
case 'mergeNode':
|
|
1662
|
+
result = await graphService.mergeNode({
|
|
1663
|
+
labels: input.labels,
|
|
1664
|
+
matchProperties: input.matchProperties,
|
|
1665
|
+
onCreate: input.onCreate || input.setProperties,
|
|
1666
|
+
onMatch: input.onMatch,
|
|
1667
|
+
});
|
|
1668
|
+
break;
|
|
1669
|
+
case 'createRelationship':
|
|
1670
|
+
result = await graphService.createRelationship({
|
|
1671
|
+
type: input.type,
|
|
1672
|
+
startNodeId: input.startNodeId || input.from,
|
|
1673
|
+
endNodeId: input.endNodeId || input.to,
|
|
1674
|
+
properties: input.properties,
|
|
1675
|
+
});
|
|
1676
|
+
break;
|
|
1677
|
+
case 'findRelationships':
|
|
1678
|
+
result = await graphService.findRelationships({
|
|
1679
|
+
types: input.types,
|
|
1680
|
+
startNodeId: input.startNodeId,
|
|
1681
|
+
endNodeId: input.endNodeId,
|
|
1682
|
+
where: input.where,
|
|
1683
|
+
limit: input.limit,
|
|
1684
|
+
});
|
|
1685
|
+
break;
|
|
1686
|
+
case 'updateRelationship':
|
|
1687
|
+
result = await graphService.updateRelationship({
|
|
1688
|
+
id: input.id,
|
|
1689
|
+
properties: input.properties,
|
|
1690
|
+
});
|
|
1691
|
+
break;
|
|
1692
|
+
case 'deleteRelationship':
|
|
1693
|
+
result = await graphService.deleteRelationship({
|
|
1694
|
+
id: input.id,
|
|
1695
|
+
});
|
|
1696
|
+
break;
|
|
1697
|
+
case 'traverse':
|
|
1698
|
+
result = await graphService.traverse({
|
|
1699
|
+
startNodeId: input.startNodeId,
|
|
1700
|
+
direction: input.direction,
|
|
1701
|
+
relationshipTypes: input.relationshipTypes,
|
|
1702
|
+
maxDepth: input.maxDepth,
|
|
1703
|
+
minDepth: input.minDepth,
|
|
1704
|
+
nodeFilter: input.nodeFilter || input.where,
|
|
1705
|
+
relationshipFilter: input.relationshipFilter,
|
|
1706
|
+
limit: input.limit,
|
|
1707
|
+
});
|
|
1708
|
+
break;
|
|
1709
|
+
case 'shortestPath':
|
|
1710
|
+
result = await graphService.shortestPath({
|
|
1711
|
+
startNodeId: input.startNodeId,
|
|
1712
|
+
endNodeId: input.endNodeId,
|
|
1713
|
+
relationshipTypes: input.relationshipTypes,
|
|
1714
|
+
maxDepth: input.maxDepth,
|
|
1715
|
+
});
|
|
1716
|
+
break;
|
|
1717
|
+
case 'query':
|
|
1718
|
+
result = await graphService.query(input.query, input.params);
|
|
1719
|
+
break;
|
|
1720
|
+
case 'countNodes':
|
|
1721
|
+
result = await graphService.countNodes(input.labels, input.where);
|
|
1722
|
+
break;
|
|
1723
|
+
case 'countRelationships':
|
|
1724
|
+
result = await graphService.countRelationships(input.types, input.where);
|
|
1725
|
+
break;
|
|
1726
|
+
case 'getStatistics':
|
|
1727
|
+
result = await graphService.getStatistics();
|
|
1728
|
+
break;
|
|
1729
|
+
default:
|
|
1730
|
+
throw new Error(`Unknown graph operation: ${operation}`);
|
|
1731
|
+
}
|
|
1732
|
+
return { success: true, data: result };
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* Process workflow job
|
|
1736
|
+
* Executes a workflow using the workflow service
|
|
1737
|
+
*/
|
|
1738
|
+
async processWorkflow(data) {
|
|
1739
|
+
const { env, product, workflow, input, idempotency_key } = data;
|
|
1740
|
+
// Initialize product builder if not already done
|
|
1741
|
+
if (product) {
|
|
1742
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1743
|
+
}
|
|
1744
|
+
// Execute the workflow using the workflow service
|
|
1745
|
+
const { WorkflowService } = await Promise.resolve().then(() => __importStar(require('../../workflows/workflows.service')));
|
|
1746
|
+
const workflowService = new WorkflowService({
|
|
1747
|
+
workspace_id: this.workspace_id,
|
|
1748
|
+
public_key: this.public_key,
|
|
1749
|
+
user_id: this.user_id,
|
|
1750
|
+
token: this.token,
|
|
1751
|
+
env_type: this.environment,
|
|
1752
|
+
});
|
|
1753
|
+
// Execute the workflow
|
|
1754
|
+
const result = await workflowService.execute({
|
|
1755
|
+
product,
|
|
1756
|
+
env,
|
|
1757
|
+
tag: workflow,
|
|
1758
|
+
input: input || {},
|
|
1759
|
+
idempotency_key,
|
|
1760
|
+
});
|
|
1761
|
+
return {
|
|
1762
|
+
success: result.status === 'completed',
|
|
1763
|
+
data: result.output,
|
|
1764
|
+
workflow_id: result.workflow_id,
|
|
1765
|
+
status: result.status,
|
|
1766
|
+
error: result.error,
|
|
1767
|
+
};
|
|
1845
1768
|
}
|
|
1846
1769
|
async getAndStoreAuth(appEnv, access_tag) {
|
|
1847
1770
|
try {
|
|
@@ -1849,7 +1772,7 @@ class ProcessorService {
|
|
|
1849
1772
|
const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.fetchPrivateKey()));
|
|
1850
1773
|
let app = await this.fetchThirdPartyApp(access_tag);
|
|
1851
1774
|
const auth = app.auths.find((item) => item.tag === appEnv.auth.auth_tag);
|
|
1852
|
-
console.log(
|
|
1775
|
+
console.log('JAMESY', auth);
|
|
1853
1776
|
if (!auth) {
|
|
1854
1777
|
// throw an error
|
|
1855
1778
|
throw new Error(`Cannot find auth ${appEnv.auth.auth_tag} on environment ${appEnv.product_env_slug}`);
|
|
@@ -1870,7 +1793,7 @@ class ProcessorService {
|
|
|
1870
1793
|
request_base_url = env.base_url;
|
|
1871
1794
|
}
|
|
1872
1795
|
}
|
|
1873
|
-
console.log(
|
|
1796
|
+
console.log('payloadabi!!!!', payload);
|
|
1874
1797
|
const results = await this.sendActionRequest(request_base_url, url, payload, method, appEnv.app_env_slug);
|
|
1875
1798
|
const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchPrivateKey());
|
|
1876
1799
|
const productApp = await this.productBuilderService.fetchApp(access_tag);
|
|
@@ -1969,7 +1892,7 @@ class ProcessorService {
|
|
|
1969
1892
|
// generate indexes
|
|
1970
1893
|
return (0, processor_utils_1.generateIndexes)(operator, iter, init, valueValue);
|
|
1971
1894
|
}
|
|
1972
|
-
async runAction(event, additional_logs, returnValue = true) {
|
|
1895
|
+
async runAction(event, additional_logs, returnValue = true, bootstrapData) {
|
|
1973
1896
|
try {
|
|
1974
1897
|
const { event: action_tag, app: access_tag, condition, cache: cache_tag } = event;
|
|
1975
1898
|
let indexes = [];
|
|
@@ -1982,23 +1905,47 @@ class ProcessorService {
|
|
|
1982
1905
|
if (condition && condition.type === types_1.Conditions.LOOP) {
|
|
1983
1906
|
indexes = await this.extractLoopIndexes(event, additional_logs);
|
|
1984
1907
|
}
|
|
1985
|
-
let
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
if (
|
|
1994
|
-
|
|
1908
|
+
let action;
|
|
1909
|
+
let env;
|
|
1910
|
+
let retries;
|
|
1911
|
+
let recipient_workspace_id;
|
|
1912
|
+
let app_active;
|
|
1913
|
+
let app_id = '';
|
|
1914
|
+
let app_env_slug = '';
|
|
1915
|
+
// Use bootstrap data if provided, otherwise fetch via API
|
|
1916
|
+
if (bootstrapData) {
|
|
1917
|
+
action = bootstrapData.action;
|
|
1918
|
+
env = bootstrapData.app_env;
|
|
1919
|
+
retries = bootstrapData.retries;
|
|
1920
|
+
recipient_workspace_id = bootstrapData.recipient_workspace_id;
|
|
1921
|
+
app_active = bootstrapData.app_active;
|
|
1922
|
+
app_env_slug = env.slug;
|
|
1923
|
+
additional_logs.app_env = app_env_slug;
|
|
1995
1924
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
1925
|
+
else {
|
|
1926
|
+
// Fallback to original API-based fetching (for features/workflows that don't use bootstrap)
|
|
1927
|
+
const appData = await this.fetchThirdPartyApp(access_tag);
|
|
1928
|
+
const { actions, envs: appEnvs, retries: appRetries, workspace_id: appWorkspaceId, active } = appData;
|
|
1929
|
+
const productApp = await this.productBuilderService.fetchApp(access_tag);
|
|
1930
|
+
const { envs: productEnvs } = productApp;
|
|
1931
|
+
const envMapping = productEnvs.find((item) => item.product_env_slug === this.processEnv.slug);
|
|
1932
|
+
app_env_slug = (envMapping === null || envMapping === void 0 ? void 0 : envMapping.app_env_slug) || '';
|
|
1933
|
+
additional_logs.app_env = app_env_slug;
|
|
1934
|
+
env = appEnvs.find((item) => item.slug === app_env_slug);
|
|
1935
|
+
action = actions.find((item) => item.tag === action_tag);
|
|
1936
|
+
retries = appRetries;
|
|
1937
|
+
recipient_workspace_id = appWorkspaceId;
|
|
1938
|
+
app_active = active;
|
|
1939
|
+
app_id = appData._id;
|
|
1940
|
+
if (!action) {
|
|
1941
|
+
throw new Error(`Action ${action_tag} not found in ${access_tag}`);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
if (!app_active && recipient_workspace_id !== this.baseLogs.workspace_id) {
|
|
1945
|
+
throw new Error(`App ${event.app} is not active`);
|
|
1998
1946
|
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
throw new Error(`Action ${action_tag} not found in ${access_tag}`);
|
|
1947
|
+
if (!env.active) {
|
|
1948
|
+
throw new Error(`Action environment ${env.slug} is not active`);
|
|
2002
1949
|
}
|
|
2003
1950
|
const { query, headers, body, params, request_type, method, base_url, resource } = action;
|
|
2004
1951
|
let request_base_url = base_url;
|
|
@@ -2006,9 +1953,9 @@ class ProcessorService {
|
|
|
2006
1953
|
request_base_url = env.base_url;
|
|
2007
1954
|
}
|
|
2008
1955
|
if (action.envs && action.envs.length) {
|
|
2009
|
-
const
|
|
2010
|
-
if (
|
|
2011
|
-
request_base_url =
|
|
1956
|
+
const actionEnv = action.envs.find((item) => item.slug === app_env_slug);
|
|
1957
|
+
if (actionEnv && actionEnv.base_url) {
|
|
1958
|
+
request_base_url = actionEnv.base_url;
|
|
2012
1959
|
}
|
|
2013
1960
|
}
|
|
2014
1961
|
const samples = {
|
|
@@ -2042,18 +1989,18 @@ class ProcessorService {
|
|
|
2042
1989
|
}
|
|
2043
1990
|
if (request_type === types_1.DataFormats.JSON || request_type === types_1.DataFormats.URLENCODED || !request_type) {
|
|
2044
1991
|
if (indexes.length == 0) {
|
|
2045
|
-
payloads = await this.constructJSONDataPayloads(event.input, additional_logs, samples, event);
|
|
1992
|
+
payloads = (await this.constructJSONDataPayloads(event.input, additional_logs, samples, event));
|
|
2046
1993
|
if (request_type === types_1.DataFormats.URLENCODED) {
|
|
2047
1994
|
payloads.body = (0, processor_utils_1.toFormUrlEncoded)(payloads.body);
|
|
2048
1995
|
}
|
|
2049
1996
|
additional_logs.recipient_workspace_id = recipient_workspace_id;
|
|
2050
|
-
result = await this.processRequest({ request_base_url, resource, method, env, payloads, app_id
|
|
1997
|
+
result = await this.processRequest({ request_base_url, resource, method, env, payloads, app_id }, event, { retries }, additional_logs, returnValue);
|
|
2051
1998
|
}
|
|
2052
1999
|
else {
|
|
2053
2000
|
const promises = indexes.map(async (index) => {
|
|
2054
2001
|
payloads = await this.constructJSONDataPayloads(event.input, additional_logs, samples, event, index);
|
|
2055
2002
|
additional_logs.recipient_workspace_id = recipient_workspace_id;
|
|
2056
|
-
await this.processRequest({ request_base_url, resource, method, env, payloads, app_id
|
|
2003
|
+
await this.processRequest({ request_base_url, resource, method, env, payloads, app_id }, event, { retries }, additional_logs, returnValue);
|
|
2057
2004
|
});
|
|
2058
2005
|
result = await Promise.all(promises);
|
|
2059
2006
|
}
|
|
@@ -2188,7 +2135,7 @@ class ProcessorService {
|
|
|
2188
2135
|
currency: finalCurrency,
|
|
2189
2136
|
is_overage: isOverage,
|
|
2190
2137
|
requests: requests,
|
|
2191
|
-
limit_exceeded: limitCheck.exceeded
|
|
2138
|
+
limit_exceeded: limitCheck.exceeded,
|
|
2192
2139
|
}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2193
2140
|
return {
|
|
2194
2141
|
pricing_tag: usedPricing.pricing_tag,
|
|
@@ -2197,7 +2144,7 @@ class ProcessorService {
|
|
|
2197
2144
|
is_overage: isOverage,
|
|
2198
2145
|
requests_made: requests,
|
|
2199
2146
|
limit_exceeded: limitCheck.exceeded,
|
|
2200
|
-
exceeded_limits: limitCheck.exceededLimits
|
|
2147
|
+
exceeded_limits: limitCheck.exceededLimits,
|
|
2201
2148
|
};
|
|
2202
2149
|
}
|
|
2203
2150
|
catch (e) {
|
|
@@ -2214,7 +2161,6 @@ class ProcessorService {
|
|
|
2214
2161
|
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2215
2162
|
}
|
|
2216
2163
|
this.processingOutput.success.push({ event, output });
|
|
2217
|
-
await this.processWaitingEvents(additional_logs);
|
|
2218
2164
|
if (this.checkIsSuccessful() && this.doneWithProcessing) {
|
|
2219
2165
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_feature_execution: true, message: 'Process feature - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2220
2166
|
await this.logService.publish();
|
|
@@ -2234,18 +2180,6 @@ class ProcessorService {
|
|
|
2234
2180
|
}
|
|
2235
2181
|
return success;
|
|
2236
2182
|
}
|
|
2237
|
-
addToWaitingOutput(event, dependants) {
|
|
2238
|
-
const exists = this.processingOutput.waiting.findIndex((item) => {
|
|
2239
|
-
return item.event.event === event.event && item.event.sequence_tag === event.sequence_tag;
|
|
2240
|
-
});
|
|
2241
|
-
const skipped = this.processingOutput.skipped.findIndex((item) => {
|
|
2242
|
-
return item.event.event === event.event && item.event.sequence_tag === event.sequence_tag;
|
|
2243
|
-
});
|
|
2244
|
-
if (!exists && !skipped) {
|
|
2245
|
-
this.processingOutput.waiting.push({ event, dependants });
|
|
2246
|
-
}
|
|
2247
|
-
// addToSkippedOutput()
|
|
2248
|
-
}
|
|
2249
2183
|
async addToFailureOutput(e, event, payload, additional_logs, policy = {}) {
|
|
2250
2184
|
try {
|
|
2251
2185
|
this.processingFailure = true;
|
|
@@ -2270,7 +2204,7 @@ class ProcessorService {
|
|
|
2270
2204
|
let retryable = true;
|
|
2271
2205
|
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2272
2206
|
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2273
|
-
if (!
|
|
2207
|
+
if (!event.allow_fail)
|
|
2274
2208
|
retryable = false;
|
|
2275
2209
|
}
|
|
2276
2210
|
let retries_left = retries || max;
|
|
@@ -2303,9 +2237,6 @@ class ProcessorService {
|
|
|
2303
2237
|
if (event.type === types_1.FeatureEventTypes.ACTION) {
|
|
2304
2238
|
this.processRequest(payload, event, policy, additional_logs);
|
|
2305
2239
|
}
|
|
2306
|
-
if (event.type === types_1.FeatureEventTypes.DB_ACTION) {
|
|
2307
|
-
this.processDBRequest(event, event.input, payload.database_tag, payload.databaseEnv, payload.action_tag, additional_logs);
|
|
2308
|
-
}
|
|
2309
2240
|
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2310
2241
|
this.processStorageRequest(event, event.input, payload.storageEnv, additional_logs);
|
|
2311
2242
|
}
|
|
@@ -2313,9 +2244,6 @@ class ProcessorService {
|
|
|
2313
2244
|
}
|
|
2314
2245
|
if (allow_fail === false && retries_left === 0) {
|
|
2315
2246
|
this.published = true;
|
|
2316
|
-
if (this.feature) {
|
|
2317
|
-
additional_logs.failed_feature_execution = true;
|
|
2318
|
-
}
|
|
2319
2247
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Ran out of retries - failed', data: Object.assign(Object.assign({}, output), { payload: (0, processor_utils_1.anonymizeObject)(output.payload) }), status: types_1.LogEventStatus.FAIL }));
|
|
2320
2248
|
//throw new Error("Run out of retries")
|
|
2321
2249
|
this.end = Date.now();
|
|
@@ -2362,9 +2290,9 @@ class ProcessorService {
|
|
|
2362
2290
|
params: query,
|
|
2363
2291
|
headers: authHeaders,
|
|
2364
2292
|
timeout: 15000,
|
|
2365
|
-
withCredentials: false
|
|
2293
|
+
withCredentials: false,
|
|
2366
2294
|
};
|
|
2367
|
-
console.log(
|
|
2295
|
+
console.log('REQUEST!!!!', request);
|
|
2368
2296
|
const response = await axios_1.default.request(request);
|
|
2369
2297
|
return response.data;
|
|
2370
2298
|
}
|
|
@@ -2375,12 +2303,15 @@ class ProcessorService {
|
|
|
2375
2303
|
}
|
|
2376
2304
|
async processStorage(action) {
|
|
2377
2305
|
//TODO: schema validation
|
|
2378
|
-
const { env, input, retries, event, product: product_tag } = action;
|
|
2306
|
+
const { env, input, retries, event, product: product_tag, session, cache } = action;
|
|
2379
2307
|
const additional_logs = {
|
|
2380
2308
|
parent_tag: event,
|
|
2381
2309
|
type: types_1.LogEventTypes.STORAGE,
|
|
2382
2310
|
name: 'Process Storage',
|
|
2383
2311
|
};
|
|
2312
|
+
// Session log fields (will be populated if session is provided)
|
|
2313
|
+
let sessionLogFields = {};
|
|
2314
|
+
let resolvedInput = input;
|
|
2384
2315
|
try {
|
|
2385
2316
|
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2386
2317
|
this.input = input;
|
|
@@ -2393,23 +2324,57 @@ class ProcessorService {
|
|
|
2393
2324
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
2394
2325
|
this.baseLogs = Object.assign({ product_tag: this.productTag, product_id: this.productId, workspace_id: this.workspace_id, env,
|
|
2395
2326
|
process_id, data: this.clone }, additional_logs);
|
|
2396
|
-
|
|
2327
|
+
// Single bootstrap call to fetch all storage data
|
|
2328
|
+
const bootstrapData = await this.productBuilderService.bootstrapStorage({
|
|
2329
|
+
product_tag,
|
|
2330
|
+
env_slug: env,
|
|
2331
|
+
storage_tag: event,
|
|
2332
|
+
});
|
|
2333
|
+
// Initialize from bootstrap data
|
|
2334
|
+
this.productId = bootstrapData.product_id;
|
|
2335
|
+
this.processEnv = bootstrapData.env;
|
|
2336
|
+
// Process session if provided - verify and resolve $Session{} references
|
|
2337
|
+
if (session && bootstrapData.private_key) {
|
|
2338
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../../sessions')));
|
|
2339
|
+
const sessionResult = await processSessionForExecution(session, bootstrapData.private_key, input, env);
|
|
2340
|
+
if (sessionResult.error) {
|
|
2341
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
2342
|
+
}
|
|
2343
|
+
resolvedInput = sessionResult.input;
|
|
2344
|
+
sessionLogFields = sessionResult.logFields;
|
|
2345
|
+
}
|
|
2346
|
+
// Initialize log service if needed
|
|
2347
|
+
if (!this.logService) {
|
|
2348
|
+
this.logService = new logs_service_1.default({
|
|
2349
|
+
product_id: this.productId,
|
|
2350
|
+
workspace_id: this.workspace_id,
|
|
2351
|
+
public_key: this.public_key,
|
|
2352
|
+
user_id: this.user_id,
|
|
2353
|
+
token: this.token,
|
|
2354
|
+
env_type: this.environment,
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2397
2357
|
this.process_id = process_id;
|
|
2398
|
-
|
|
2399
|
-
|
|
2358
|
+
this.baseLogs.product_id = this.productId;
|
|
2359
|
+
// Add session fields to base logs
|
|
2360
|
+
this.baseLogs = Object.assign(Object.assign({}, this.baseLogs), sessionLogFields);
|
|
2361
|
+
const productEnv = bootstrapData.env;
|
|
2400
2362
|
if (!productEnv.active) {
|
|
2401
2363
|
throw new Error(`Environment ${env} is not active`);
|
|
2402
2364
|
}
|
|
2403
2365
|
const payload = {
|
|
2404
2366
|
type: types_1.FeatureEventTypes.STORAGE,
|
|
2405
2367
|
event,
|
|
2406
|
-
cache:
|
|
2407
|
-
input,
|
|
2368
|
+
cache: cache,
|
|
2369
|
+
input: resolvedInput,
|
|
2408
2370
|
env: productEnv,
|
|
2409
2371
|
retries: retries || 0,
|
|
2410
2372
|
allow_fail: false,
|
|
2411
2373
|
};
|
|
2412
|
-
const result = await this.runStorage(payload
|
|
2374
|
+
const result = await this.runStorage(payload, additional_logs, {
|
|
2375
|
+
storage: bootstrapData.storage,
|
|
2376
|
+
storage_env: bootstrapData.storage_env,
|
|
2377
|
+
});
|
|
2413
2378
|
this.end = Date.now();
|
|
2414
2379
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - success', data: { input: this.clone, result }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2415
2380
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
@@ -2435,13 +2400,12 @@ class ProcessorService {
|
|
|
2435
2400
|
name: `Subscribe to broker topic`,
|
|
2436
2401
|
};
|
|
2437
2402
|
try {
|
|
2438
|
-
|
|
2439
|
-
const input = { callback: data.callback };
|
|
2403
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2440
2404
|
this.start = Date.now();
|
|
2441
2405
|
this.productTag = data.product;
|
|
2442
2406
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
2443
|
-
this.input =
|
|
2444
|
-
this.baseLogs = Object.assign({ product_tag: this.productTag, product_id: this.productId, workspace_id: this.workspace_id, env: data.env, process_id, data: input }, additional_logs);
|
|
2407
|
+
this.input = data;
|
|
2408
|
+
this.baseLogs = Object.assign({ product_tag: this.productTag, product_id: this.productId, workspace_id: this.workspace_id, env: data.env, process_id, data: data.input }, additional_logs);
|
|
2445
2409
|
await this.intializeProduct(additional_logs);
|
|
2446
2410
|
this.baseLogs.product_id = this.productId;
|
|
2447
2411
|
this.process_id = process_id;
|
|
@@ -2454,7 +2418,7 @@ class ProcessorService {
|
|
|
2454
2418
|
const payload = {
|
|
2455
2419
|
type: types_1.FeatureEventTypes.SUBSCRIBE,
|
|
2456
2420
|
event: data.event,
|
|
2457
|
-
input: input,
|
|
2421
|
+
input: data.input,
|
|
2458
2422
|
env: productEnv,
|
|
2459
2423
|
retries: 0,
|
|
2460
2424
|
allow_fail: false,
|
|
@@ -2484,12 +2448,14 @@ class ProcessorService {
|
|
|
2484
2448
|
type: types_1.LogEventTypes.MESSAGEBROKER,
|
|
2485
2449
|
name: 'Publish to broker topic',
|
|
2486
2450
|
};
|
|
2451
|
+
// Session log fields (will be populated if session is provided)
|
|
2452
|
+
let sessionLogFields = {};
|
|
2453
|
+
let resolvedInput = data.input;
|
|
2487
2454
|
try {
|
|
2488
|
-
|
|
2489
|
-
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.PUBLISH);
|
|
2455
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2490
2456
|
this.start = Date.now();
|
|
2491
2457
|
// clone
|
|
2492
|
-
this.clone = (0, processor_utils_1.structuredClone)(input);
|
|
2458
|
+
this.clone = (0, processor_utils_1.structuredClone)(data.input);
|
|
2493
2459
|
this.input = data;
|
|
2494
2460
|
this.productTag = data.product;
|
|
2495
2461
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
@@ -2498,6 +2464,19 @@ class ProcessorService {
|
|
|
2498
2464
|
await this.intializeProduct(additional_logs);
|
|
2499
2465
|
this.baseLogs.product_id = this.productId;
|
|
2500
2466
|
this.process_id = process_id;
|
|
2467
|
+
// Process session if provided - verify and resolve $Session{} references
|
|
2468
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
2469
|
+
if (data.session && privateKey) {
|
|
2470
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../../sessions')));
|
|
2471
|
+
const sessionResult = await processSessionForExecution(data.session, privateKey, data.input, data.env);
|
|
2472
|
+
if (sessionResult.error) {
|
|
2473
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
2474
|
+
}
|
|
2475
|
+
resolvedInput = sessionResult.input;
|
|
2476
|
+
sessionLogFields = sessionResult.logFields;
|
|
2477
|
+
}
|
|
2478
|
+
// Add session fields to base logs
|
|
2479
|
+
this.baseLogs = Object.assign(Object.assign({}, this.baseLogs), sessionLogFields);
|
|
2501
2480
|
const productEnv = await this.fetchEnv(data.env, additional_logs);
|
|
2502
2481
|
this.processEnv = productEnv;
|
|
2503
2482
|
if (!productEnv.active) {
|
|
@@ -2507,7 +2486,7 @@ class ProcessorService {
|
|
|
2507
2486
|
type: types_1.FeatureEventTypes.PUBLISH,
|
|
2508
2487
|
event: data.event,
|
|
2509
2488
|
cache: data.cache,
|
|
2510
|
-
input:
|
|
2489
|
+
input: resolvedInput,
|
|
2511
2490
|
env: productEnv,
|
|
2512
2491
|
retries: 0,
|
|
2513
2492
|
allow_fail: false,
|
|
@@ -2527,7 +2506,7 @@ class ProcessorService {
|
|
|
2527
2506
|
}
|
|
2528
2507
|
}
|
|
2529
2508
|
async processJob(job, additional_logs = {}) {
|
|
2530
|
-
var _a;
|
|
2509
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2531
2510
|
const productJob = await this.productBuilderService.fetchJob(job.event);
|
|
2532
2511
|
if (!productJob) {
|
|
2533
2512
|
throw new Error(`Job ${job.event} not found`);
|
|
@@ -2536,8 +2515,10 @@ class ProcessorService {
|
|
|
2536
2515
|
const NOW = Date.now();
|
|
2537
2516
|
// Treat anything above Jan 1, 2023 as a timestamp (to be safe and future-proof)
|
|
2538
2517
|
const IS_PROBABLY_TIMESTAMP = job.start_at > 1672531200000;
|
|
2539
|
-
const
|
|
2518
|
+
const scheduled_at = IS_PROBABLY_TIMESTAMP ? job.start_at : NOW + job.start_at;
|
|
2519
|
+
const delay = Math.max(0, scheduled_at - NOW);
|
|
2540
2520
|
let jobInput;
|
|
2521
|
+
let namespace = productJob.type;
|
|
2541
2522
|
if (productJob.type === types_1.JobEventTypes.ACTION) {
|
|
2542
2523
|
const input = {
|
|
2543
2524
|
env: job.env,
|
|
@@ -2545,93 +2526,220 @@ class ProcessorService {
|
|
|
2545
2526
|
app: productJob.app,
|
|
2546
2527
|
cache: job.cache,
|
|
2547
2528
|
input: job.input,
|
|
2529
|
+
action: job.event,
|
|
2530
|
+
session: job.session,
|
|
2531
|
+
};
|
|
2532
|
+
jobInput = input;
|
|
2533
|
+
namespace = 'actions';
|
|
2534
|
+
}
|
|
2535
|
+
else if (productJob.type === types_1.JobEventTypes.NOTIFICATION) {
|
|
2536
|
+
const input = {
|
|
2537
|
+
env: job.env,
|
|
2538
|
+
product: job.product,
|
|
2548
2539
|
event: job.event,
|
|
2549
|
-
|
|
2540
|
+
input: job.input,
|
|
2541
|
+
session: job.session,
|
|
2542
|
+
cache: job.cache,
|
|
2550
2543
|
};
|
|
2551
2544
|
jobInput = input;
|
|
2545
|
+
namespace = 'notifications';
|
|
2552
2546
|
}
|
|
2553
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2547
|
+
else if (productJob.type === types_1.JobEventTypes.PUBLISH) {
|
|
2554
2548
|
const input = {
|
|
2555
2549
|
env: job.env,
|
|
2556
2550
|
product: job.product,
|
|
2551
|
+
event: job.event,
|
|
2557
2552
|
cache: job.cache,
|
|
2553
|
+
session: job.session,
|
|
2558
2554
|
input: job.input,
|
|
2555
|
+
};
|
|
2556
|
+
jobInput = input;
|
|
2557
|
+
namespace = 'events';
|
|
2558
|
+
}
|
|
2559
|
+
else if (productJob.type === types_1.JobEventTypes.STORAGE) {
|
|
2560
|
+
const input = {
|
|
2561
|
+
env: job.env,
|
|
2562
|
+
product: job.product,
|
|
2559
2563
|
event: job.event,
|
|
2564
|
+
cache: job.cache,
|
|
2560
2565
|
session: job.session,
|
|
2566
|
+
input: job.input,
|
|
2561
2567
|
};
|
|
2562
2568
|
jobInput = input;
|
|
2569
|
+
namespace = 'storage';
|
|
2563
2570
|
}
|
|
2564
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2571
|
+
else if (productJob.type === types_1.JobEventTypes.DATABASE_ACTION) {
|
|
2572
|
+
// Database action job - predefined database actions
|
|
2565
2573
|
const input = {
|
|
2566
|
-
input: job.input,
|
|
2567
|
-
product: job.product,
|
|
2568
2574
|
env: job.env,
|
|
2569
|
-
|
|
2570
|
-
|
|
2575
|
+
product: job.product,
|
|
2576
|
+
database: productJob.app,
|
|
2577
|
+
event: productJob.event,
|
|
2571
2578
|
cache: job.cache,
|
|
2579
|
+
session: job.session,
|
|
2580
|
+
input: job.input,
|
|
2572
2581
|
};
|
|
2573
2582
|
jobInput = input;
|
|
2583
|
+
namespace = 'database';
|
|
2574
2584
|
}
|
|
2575
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2585
|
+
else if (productJob.type === types_1.JobEventTypes.DATABASE_OPERATION) {
|
|
2586
|
+
// Database operation job - direct database operations like createOne, findMany, etc.
|
|
2576
2587
|
const input = {
|
|
2577
2588
|
env: job.env,
|
|
2578
2589
|
product: job.product,
|
|
2579
|
-
|
|
2590
|
+
database: productJob.app,
|
|
2591
|
+
operation: productJob.event,
|
|
2592
|
+
cache: job.cache,
|
|
2593
|
+
session: job.session,
|
|
2580
2594
|
input: job.input,
|
|
2595
|
+
};
|
|
2596
|
+
jobInput = input;
|
|
2597
|
+
namespace = 'database';
|
|
2598
|
+
}
|
|
2599
|
+
else if (productJob.type === types_1.JobEventTypes.GRAPH_ACTION) {
|
|
2600
|
+
// Graph action job - predefined graph actions
|
|
2601
|
+
const input = {
|
|
2602
|
+
env: job.env,
|
|
2603
|
+
product: job.product,
|
|
2604
|
+
graph: productJob.app,
|
|
2605
|
+
event: productJob.event,
|
|
2606
|
+
cache: job.cache,
|
|
2581
2607
|
session: job.session,
|
|
2582
|
-
|
|
2608
|
+
input: job.input,
|
|
2583
2609
|
};
|
|
2584
2610
|
jobInput = input;
|
|
2611
|
+
namespace = 'graphs';
|
|
2585
2612
|
}
|
|
2586
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2613
|
+
else if (productJob.type === types_1.JobEventTypes.GRAPH_OPERATION) {
|
|
2614
|
+
// Graph operation job - direct graph operations like createNode, traverse, etc.
|
|
2587
2615
|
const input = {
|
|
2588
2616
|
env: job.env,
|
|
2589
2617
|
product: job.product,
|
|
2590
|
-
|
|
2618
|
+
graph: productJob.app,
|
|
2619
|
+
operation: productJob.event,
|
|
2591
2620
|
cache: job.cache,
|
|
2592
2621
|
session: job.session,
|
|
2593
|
-
|
|
2622
|
+
input: job.input,
|
|
2594
2623
|
};
|
|
2595
2624
|
jobInput = input;
|
|
2625
|
+
namespace = 'graphs';
|
|
2596
2626
|
}
|
|
2597
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2627
|
+
else if (productJob.type === types_1.JobEventTypes.WORKFLOW) {
|
|
2628
|
+
// Workflow job - execute a workflow
|
|
2598
2629
|
const input = {
|
|
2599
2630
|
env: job.env,
|
|
2600
2631
|
product: job.product,
|
|
2601
|
-
|
|
2632
|
+
workflow: productJob.app,
|
|
2602
2633
|
cache: job.cache,
|
|
2603
2634
|
session: job.session,
|
|
2604
|
-
input: job.input
|
|
2635
|
+
input: job.input,
|
|
2605
2636
|
};
|
|
2606
2637
|
jobInput = input;
|
|
2638
|
+
namespace = 'workflows';
|
|
2607
2639
|
}
|
|
2608
2640
|
else {
|
|
2609
2641
|
throw new Error(`Job type ${productJob.type} not supported`);
|
|
2610
2642
|
}
|
|
2611
|
-
|
|
2643
|
+
// Determine if this is a recurring job
|
|
2644
|
+
const isRecurring = !!(((_a = job.repeat) === null || _a === void 0 ? void 0 : _a.cron) || ((_b = job.repeat) === null || _b === void 0 ? void 0 : _b.every));
|
|
2645
|
+
// Generate a unique job ID
|
|
2646
|
+
const jobId = `job_${(0, uuid_1.v4)().replace(/-/g, '').substring(0, 16)}`;
|
|
2647
|
+
// Build queue options
|
|
2648
|
+
const options = {
|
|
2649
|
+
jobId,
|
|
2650
|
+
};
|
|
2612
2651
|
// Handle `delay` only if repeat.every is not defined
|
|
2613
|
-
if (!((
|
|
2652
|
+
if (!((_c = job.repeat) === null || _c === void 0 ? void 0 : _c.every) && delay > 0) {
|
|
2614
2653
|
options.delay = delay;
|
|
2615
2654
|
}
|
|
2616
2655
|
// Add repeat config if defined
|
|
2656
|
+
let next_run_at;
|
|
2617
2657
|
if (job.repeat) {
|
|
2618
2658
|
const { every, cron, tz, limit, endDate } = job.repeat;
|
|
2619
|
-
|
|
2620
|
-
|
|
2659
|
+
if (cron) {
|
|
2660
|
+
options.repeat = {
|
|
2621
2661
|
cron,
|
|
2622
2662
|
tz,
|
|
2623
2663
|
limit,
|
|
2624
2664
|
endDate,
|
|
2665
|
+
};
|
|
2666
|
+
// Calculate next run time from cron
|
|
2667
|
+
try {
|
|
2668
|
+
const cronParser = require('cron-parser');
|
|
2669
|
+
const cronOptions = {};
|
|
2670
|
+
if (tz)
|
|
2671
|
+
cronOptions.tz = tz;
|
|
2672
|
+
const interval = cronParser.parseExpression(cron, cronOptions);
|
|
2673
|
+
next_run_at = interval.next().getTime();
|
|
2625
2674
|
}
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2675
|
+
catch (err) {
|
|
2676
|
+
next_run_at = NOW;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
else if (every) {
|
|
2680
|
+
options.repeat = {
|
|
2681
|
+
every,
|
|
2682
|
+
limit,
|
|
2683
|
+
endDate,
|
|
2684
|
+
};
|
|
2685
|
+
next_run_at = NOW + every;
|
|
2686
|
+
}
|
|
2633
2687
|
}
|
|
2688
|
+
// Store job metadata in Redis if redisClient is available
|
|
2689
|
+
if (this.redisClient) {
|
|
2690
|
+
const jobData = {
|
|
2691
|
+
id: jobId,
|
|
2692
|
+
status: delay > 0 ? 'scheduled' : 'queued',
|
|
2693
|
+
type: productJob.type,
|
|
2694
|
+
namespace,
|
|
2695
|
+
product: job.product,
|
|
2696
|
+
env: job.env,
|
|
2697
|
+
event: job.event,
|
|
2698
|
+
app: productJob.app,
|
|
2699
|
+
scheduled_at,
|
|
2700
|
+
recurring: isRecurring,
|
|
2701
|
+
cron: (_d = job.repeat) === null || _d === void 0 ? void 0 : _d.cron,
|
|
2702
|
+
every: (_e = job.repeat) === null || _e === void 0 ? void 0 : _e.every,
|
|
2703
|
+
next_run_at,
|
|
2704
|
+
execution_count: 0,
|
|
2705
|
+
limit: (_f = job.repeat) === null || _f === void 0 ? void 0 : _f.limit,
|
|
2706
|
+
end_date: ((_g = job.repeat) === null || _g === void 0 ? void 0 : _g.endDate)
|
|
2707
|
+
? typeof job.repeat.endDate === 'string'
|
|
2708
|
+
? new Date(job.repeat.endDate).getTime()
|
|
2709
|
+
: job.repeat.endDate
|
|
2710
|
+
: undefined,
|
|
2711
|
+
tz: (_h = job.repeat) === null || _h === void 0 ? void 0 : _h.tz,
|
|
2712
|
+
retries: job.retries || 0,
|
|
2713
|
+
retry_count: 0,
|
|
2714
|
+
input: jobInput,
|
|
2715
|
+
session: job.session,
|
|
2716
|
+
cache: job.cache,
|
|
2717
|
+
workspace_id: this.workspace_id,
|
|
2718
|
+
created_at: NOW,
|
|
2719
|
+
updated_at: NOW,
|
|
2720
|
+
};
|
|
2721
|
+
// Store in Redis with TTL of 90 days
|
|
2722
|
+
const jobKey = `job:${this.workspace_id}:${jobId}`;
|
|
2723
|
+
const redis = this.redisClient;
|
|
2724
|
+
await redis.setex(jobKey, 90 * 24 * 60 * 60, JSON.stringify(jobData));
|
|
2725
|
+
// Add to status index
|
|
2726
|
+
const statusKey = `job_status:${this.workspace_id}:${jobData.status}`;
|
|
2727
|
+
await redis.sadd(statusKey, jobId);
|
|
2728
|
+
// Add to product index
|
|
2729
|
+
const productKey = `job_product:${this.workspace_id}:${job.product}`;
|
|
2730
|
+
await redis.sadd(productKey, jobId);
|
|
2731
|
+
}
|
|
2732
|
+
// Add job input with the job ID for tracking
|
|
2733
|
+
jobInput._job_id = jobId;
|
|
2734
|
+
// Add job to queue
|
|
2634
2735
|
await this.queues.jobs.add(productJob.type, jobInput, options);
|
|
2736
|
+
return {
|
|
2737
|
+
job_id: jobId,
|
|
2738
|
+
status: delay > 0 ? 'scheduled' : 'queued',
|
|
2739
|
+
scheduled_at,
|
|
2740
|
+
recurring: isRecurring,
|
|
2741
|
+
next_run_at,
|
|
2742
|
+
};
|
|
2635
2743
|
}
|
|
2636
2744
|
async sendExpoNotification(payload, device_tokens) {
|
|
2637
2745
|
const message = {
|
|
@@ -2686,19 +2794,33 @@ class ProcessorService {
|
|
|
2686
2794
|
await this.sendFirebaseNotification({ title, body, data }, payload.device_tokens, notification.credentials);
|
|
2687
2795
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Firebase notification - success', data: { title, body: (0, processor_utils_1.anonymizeObject)(data), data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2688
2796
|
}
|
|
2689
|
-
async runNotification(notification, additional_logs) {
|
|
2690
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2797
|
+
async runNotification(notification, additional_logs, bootstrapData) {
|
|
2798
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2691
2799
|
const { event } = notification;
|
|
2692
2800
|
const input = notification.input;
|
|
2693
2801
|
try {
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
if
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2802
|
+
let notificationEvent;
|
|
2803
|
+
let message;
|
|
2804
|
+
let envConfig;
|
|
2805
|
+
// Use bootstrap data if provided, otherwise fetch via API
|
|
2806
|
+
if (bootstrapData) {
|
|
2807
|
+
notificationEvent = bootstrapData.notification;
|
|
2808
|
+
message = bootstrapData.message;
|
|
2809
|
+
envConfig = bootstrapData.env_config;
|
|
2810
|
+
}
|
|
2811
|
+
else {
|
|
2812
|
+
// Fallback to original API-based fetching
|
|
2813
|
+
notificationEvent = (await this.productBuilderService.fetchNotification(event.split(':')[0]));
|
|
2814
|
+
message = await this.productBuilderService.fetchNotificationMessage(event);
|
|
2815
|
+
if (!message) {
|
|
2816
|
+
throw new Error(`Message ${event} not found`);
|
|
2817
|
+
}
|
|
2818
|
+
envConfig = (_a = notificationEvent.envs) === null || _a === void 0 ? void 0 : _a.find((data) => data.slug === notification.env.slug);
|
|
2819
|
+
}
|
|
2820
|
+
if (!envConfig) {
|
|
2821
|
+
throw new Error(`Notification env config for ${notification.env.slug} not found`);
|
|
2822
|
+
}
|
|
2823
|
+
const { push_notifications: notifications, emails, callbacks, sms: smses, } = envConfig;
|
|
2702
2824
|
const { push_notification: push, email, callback, sms } = message;
|
|
2703
2825
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching notification', data: notificationEvent, status: types_1.LogEventStatus.SUCCESS }));
|
|
2704
2826
|
if (push) {
|
|
@@ -2744,7 +2866,11 @@ class ProcessorService {
|
|
|
2744
2866
|
const templateMaker = (0, handlebars_1.compile)(email.template);
|
|
2745
2867
|
const template = templateMaker(input.email.template);
|
|
2746
2868
|
const subject = (0, processor_utils_1.replacePlaceholderString)(email.subject, input.email.subject || {});
|
|
2747
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - success', data: {
|
|
2869
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - success', data: {
|
|
2870
|
+
template: (0, processor_utils_1.anonymizeValue)(template),
|
|
2871
|
+
subject: (0, processor_utils_1.anonymizeValue)(subject),
|
|
2872
|
+
input: (0, processor_utils_1.anonymizeObject)(input.email),
|
|
2873
|
+
}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2748
2874
|
const mailOptions = {
|
|
2749
2875
|
from,
|
|
2750
2876
|
to: input.email.recipients,
|
|
@@ -2762,10 +2888,10 @@ class ProcessorService {
|
|
|
2762
2888
|
}
|
|
2763
2889
|
if (callback && callbacks) {
|
|
2764
2890
|
const payload = {
|
|
2765
|
-
query: Object.assign(Object.assign({}, (
|
|
2766
|
-
headers: Object.assign(Object.assign({}, (
|
|
2767
|
-
params: Object.assign(Object.assign({}, (
|
|
2768
|
-
body: Object.assign(Object.assign({}, (
|
|
2891
|
+
query: Object.assign(Object.assign({}, (_b = input.callback) === null || _b === void 0 ? void 0 : _b.query), (_c = callbacks.auth) === null || _c === void 0 ? void 0 : _c.query),
|
|
2892
|
+
headers: Object.assign(Object.assign({}, (_d = input.callback) === null || _d === void 0 ? void 0 : _d.headers), (_e = callbacks.auth) === null || _e === void 0 ? void 0 : _e.headers),
|
|
2893
|
+
params: Object.assign(Object.assign({}, (_f = input.callback) === null || _f === void 0 ? void 0 : _f.params), (_g = callbacks.auth) === null || _g === void 0 ? void 0 : _g.params),
|
|
2894
|
+
body: Object.assign(Object.assign({}, (_h = input.callback) === null || _h === void 0 ? void 0 : _h.body), (_j = callbacks.auth) === null || _j === void 0 ? void 0 : _j.body),
|
|
2769
2895
|
};
|
|
2770
2896
|
input.callback.body = await this.generatePayload(payload.body, notification, additional_logs, message.callback_data.filter((data) => data.parent_key === 'body'));
|
|
2771
2897
|
input.callback.query = await this.generatePayload(payload.query, notification, additional_logs, message.callback_data.filter((data) => data.parent_key === 'query'));
|
|
@@ -2787,7 +2913,7 @@ class ProcessorService {
|
|
|
2787
2913
|
}
|
|
2788
2914
|
if (sms && smses) {
|
|
2789
2915
|
try {
|
|
2790
|
-
input.sms.body = await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body);
|
|
2916
|
+
input.sms.body = (await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body));
|
|
2791
2917
|
const SmsClient = await (0, sms_repo_1.loadSMSClient)();
|
|
2792
2918
|
const smsClient = new SmsClient(smses);
|
|
2793
2919
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - initiated', data: { message: input.sms.body, config: (0, processor_utils_1.anonymizeObject)(smses) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
@@ -2806,184 +2932,116 @@ class ProcessorService {
|
|
|
2806
2932
|
throw e;
|
|
2807
2933
|
}
|
|
2808
2934
|
}
|
|
2809
|
-
async runMigration(product_tag, tag, env, type) {
|
|
2810
|
-
try {
|
|
2811
|
-
this.productTag = product_tag;
|
|
2812
|
-
const [dbTag, migrationTag] = tag.split(':');
|
|
2813
|
-
if (!dbTag || !migrationTag) {
|
|
2814
|
-
throw new Error('tag should be in the format database_tag:migration_tag');
|
|
2815
|
-
}
|
|
2816
|
-
this.start = Date.now();
|
|
2817
|
-
const additional_logs = {
|
|
2818
|
-
parent_tag: dbTag,
|
|
2819
|
-
child_tag: migrationTag,
|
|
2820
|
-
type: types_1.LogEventTypes.DB_MIGRATION,
|
|
2821
|
-
name: 'Run Migration',
|
|
2822
|
-
};
|
|
2823
|
-
await this.intializeProduct(additional_logs);
|
|
2824
|
-
const db = await this.productBuilderService.fetchDatabase(dbTag);
|
|
2825
|
-
if (!db) {
|
|
2826
|
-
throw new Error('Database not found');
|
|
2827
|
-
}
|
|
2828
|
-
if (db.type === types_1.DatabaseTypes.MONGODB) {
|
|
2829
|
-
throw new Error(`${db.type} does not support migrations`);
|
|
2830
|
-
}
|
|
2831
|
-
const migration = await this.productBuilderService.fetchDatabaseMigration(tag);
|
|
2832
|
-
if (!migration) {
|
|
2833
|
-
throw new Error('Database migration not found');
|
|
2834
|
-
}
|
|
2835
|
-
const dbEnv = db.envs.find((el) => el.slug === env);
|
|
2836
|
-
if (!dbEnv) {
|
|
2837
|
-
throw new Error(`Environment ${env} not found`);
|
|
2838
|
-
}
|
|
2839
|
-
const productEnv = await this.fetchEnv(env, additional_logs);
|
|
2840
|
-
if (!productEnv.active) {
|
|
2841
|
-
throw new Error(`Environment ${env} is not active`);
|
|
2842
|
-
}
|
|
2843
|
-
const migrations = await this.productBuilderService.fetchDatabaseMigrations(dbTag);
|
|
2844
|
-
//this.processEnv = productEnv;
|
|
2845
|
-
/* const check = migration.envs.find((migrationEnv) => migrationEnv.slug === env);
|
|
2846
|
-
if (!check) {
|
|
2847
|
-
throw new Error(`Migration does not exist for environment ${env}`);
|
|
2848
|
-
}*/
|
|
2849
|
-
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
2850
|
-
this.baseLogs = Object.assign({ product_tag: this.productTag, product_id: this.productId, workspace_id: this.workspace_id, env,
|
|
2851
|
-
process_id, data: { tag, env } }, additional_logs);
|
|
2852
|
-
const migrationsToRun = (0, processor_utils_1.getMigrationsToRun)((0, processor_utils_1.structuredClone)(migrations), type, migrationTag, env);
|
|
2853
|
-
if (db.type === types_1.DatabaseTypes.POSTGRES) {
|
|
2854
|
-
const PostgresDBHandler = await (0, postgres_repo_1.loadPostgresHandler)();
|
|
2855
|
-
const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(dbEnv.connection_url, this.productBuilderService.fetchPrivateKey()));
|
|
2856
|
-
for (const migrationToRun of migrationsToRun) {
|
|
2857
|
-
const envS = migration.envs.find((envT) => envT.slug === env && type === envT.type);
|
|
2858
|
-
if (envS && envS.status === types_1.MigrationStatus.PROCESSED) {
|
|
2859
|
-
continue;
|
|
2860
|
-
}
|
|
2861
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: `Starting migration ${type} name: ${migrationToRun.name}`, data: { migration: migrationToRun, type }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2862
|
-
const { type: migType, result, status, processed_at, } = await pgHandler.runMigration(migrationToRun.value[type], type, envS);
|
|
2863
|
-
if (!envS) {
|
|
2864
|
-
migrationToRun.envs.push({ slug: env, results: result, status, type, processed_at });
|
|
2865
|
-
}
|
|
2866
|
-
else {
|
|
2867
|
-
migrationToRun.envs.map((envT) => {
|
|
2868
|
-
if (envT.slug === env && type === envT.type) {
|
|
2869
|
-
envT.results = [...result];
|
|
2870
|
-
envT.processed_at = processed_at;
|
|
2871
|
-
return envT;
|
|
2872
|
-
}
|
|
2873
|
-
return envT;
|
|
2874
|
-
});
|
|
2875
|
-
}
|
|
2876
|
-
this.productBuilderService.updateDatabaseMigration(Object.assign(Object.assign({}, migrationToRun), { tag }));
|
|
2877
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: `Starting migration ${type} name: ${migrationToRun.name}`, data: { migration: migrationToRun, type }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2878
|
-
}
|
|
2879
|
-
return { process_id };
|
|
2880
|
-
}
|
|
2881
|
-
}
|
|
2882
|
-
catch (e) {
|
|
2883
|
-
this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { failed_execution: true, message: 'Attempt migration - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
2884
|
-
await this.logService.publish();
|
|
2885
|
-
}
|
|
2886
|
-
}
|
|
2887
2935
|
/*async runFunction(data: IFeatureEvent, additional_logs: Partial<ILogData>): Promise<any> {
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
});
|
|
2901
|
-
|
|
2902
|
-
const process_id = generateObjectId();
|
|
2903
|
-
this.process_id = process_id;
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
try {
|
|
2907
|
-
await this.intializeProduct(additional_logs);
|
|
2908
|
-
this.logService.add({
|
|
2909
|
-
...this.baseLogs,
|
|
2910
|
-
...additional_logs,
|
|
2911
|
-
message: 'Attempt function - initiated',
|
|
2912
|
-
data,
|
|
2913
|
-
status: LogEventStatus.PROCESSING,
|
|
2914
|
-
});
|
|
2915
|
-
|
|
2916
|
-
this.logService.add({
|
|
2917
|
-
...this.baseLogs,
|
|
2918
|
-
...additional_logs,
|
|
2919
|
-
message: 'Fetch function - initiated',
|
|
2920
|
-
data: data,
|
|
2921
|
-
status: LogEventStatus.PROCESSING,
|
|
2922
|
-
});
|
|
2923
|
-
|
|
2924
|
-
const cloudFunction = await this.productBuilderService.fetchFunction(data.event);
|
|
2925
|
-
|
|
2926
|
-
this.logService.add({
|
|
2927
|
-
...this.baseLogs,
|
|
2928
|
-
...additional_logs,
|
|
2929
|
-
message: 'Fetch function - success',
|
|
2930
|
-
data: data,
|
|
2931
|
-
status: LogEventStatus.SUCCESS,
|
|
2932
|
-
});
|
|
2933
|
-
|
|
2934
|
-
this.logService.add({
|
|
2935
|
-
...this.baseLogs,
|
|
2936
|
-
...additional_logs,
|
|
2937
|
-
message: 'Validate function payload - initiated',
|
|
2938
|
-
data: { data, payload: input.payload },
|
|
2939
|
-
status: LogEventStatus.PROCESSING,
|
|
2940
|
-
});
|
|
2941
|
-
|
|
2942
|
-
validateFunctionInputKeys(cloudFunction.inputs, input.payload);
|
|
2943
|
-
|
|
2944
|
-
this.logService.add({
|
|
2945
|
-
...this.baseLogs,
|
|
2946
|
-
...additional_logs,
|
|
2947
|
-
message: 'Validate function payload - success',
|
|
2948
|
-
data: { data, payload: input.payload },
|
|
2949
|
-
status: LogEventStatus.SUCCESS,
|
|
2950
|
-
});
|
|
2951
|
-
|
|
2952
|
-
this.logService.add({
|
|
2953
|
-
...this.baseLogs,
|
|
2954
|
-
...additional_logs,
|
|
2955
|
-
message: 'Run function - initiated',
|
|
2956
|
-
data: { data, payload: input.payload },
|
|
2957
|
-
status: LogEventStatus.PROCESSING,
|
|
2958
|
-
});
|
|
2959
|
-
|
|
2960
|
-
const response = await makeFunctionsRequest(cloudFunction, input.payload);
|
|
2961
|
-
|
|
2962
|
-
this.logService.add({
|
|
2963
|
-
...this.baseLogs,
|
|
2964
|
-
...additional_logs,
|
|
2965
|
-
message: 'Run function - success',
|
|
2966
|
-
data: { data, payload: input.payload },
|
|
2967
|
-
status: LogEventStatus.SUCCESS,
|
|
2936
|
+
const { product_id, env } = data;
|
|
2937
|
+
const input = data.input as IFunctionRequest;
|
|
2938
|
+
|
|
2939
|
+
this.productId = product_id;
|
|
2940
|
+
|
|
2941
|
+
this.logService = new LogsService({
|
|
2942
|
+
product_id,
|
|
2943
|
+
workspace_id: this.workspace_id,
|
|
2944
|
+
public_key: this.public_key,
|
|
2945
|
+
user_id: this.user_id,
|
|
2946
|
+
token: this.token,
|
|
2947
|
+
env_type: this.environment,
|
|
2968
2948
|
});
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2949
|
+
|
|
2950
|
+
const process_id = generateObjectId();
|
|
2951
|
+
this.process_id = process_id;
|
|
2952
|
+
|
|
2953
|
+
|
|
2954
|
+
try {
|
|
2955
|
+
await this.intializeProduct(additional_logs);
|
|
2956
|
+
this.logService.add({
|
|
2957
|
+
...this.baseLogs,
|
|
2958
|
+
...additional_logs,
|
|
2959
|
+
message: 'Attempt function - initiated',
|
|
2960
|
+
data,
|
|
2961
|
+
status: LogEventStatus.PROCESSING,
|
|
2962
|
+
});
|
|
2963
|
+
|
|
2964
|
+
this.logService.add({
|
|
2965
|
+
...this.baseLogs,
|
|
2966
|
+
...additional_logs,
|
|
2967
|
+
message: 'Fetch function - initiated',
|
|
2968
|
+
data: data,
|
|
2969
|
+
status: LogEventStatus.PROCESSING,
|
|
2970
|
+
});
|
|
2971
|
+
|
|
2972
|
+
const cloudFunction = await this.productBuilderService.fetchFunction(data.event);
|
|
2973
|
+
|
|
2974
|
+
this.logService.add({
|
|
2975
|
+
...this.baseLogs,
|
|
2976
|
+
...additional_logs,
|
|
2977
|
+
message: 'Fetch function - success',
|
|
2978
|
+
data: data,
|
|
2979
|
+
status: LogEventStatus.SUCCESS,
|
|
2980
|
+
});
|
|
2981
|
+
|
|
2982
|
+
this.logService.add({
|
|
2983
|
+
...this.baseLogs,
|
|
2984
|
+
...additional_logs,
|
|
2985
|
+
message: 'Validate function payload - initiated',
|
|
2986
|
+
data: { data, payload: input.payload },
|
|
2987
|
+
status: LogEventStatus.PROCESSING,
|
|
2988
|
+
});
|
|
2989
|
+
|
|
2990
|
+
validateFunctionInputKeys(cloudFunction.inputs, input.payload);
|
|
2991
|
+
|
|
2992
|
+
this.logService.add({
|
|
2993
|
+
...this.baseLogs,
|
|
2994
|
+
...additional_logs,
|
|
2995
|
+
message: 'Validate function payload - success',
|
|
2996
|
+
data: { data, payload: input.payload },
|
|
2997
|
+
status: LogEventStatus.SUCCESS,
|
|
2998
|
+
});
|
|
2999
|
+
|
|
3000
|
+
this.logService.add({
|
|
3001
|
+
...this.baseLogs,
|
|
3002
|
+
...additional_logs,
|
|
3003
|
+
message: 'Run function - initiated',
|
|
3004
|
+
data: { data, payload: input.payload },
|
|
3005
|
+
status: LogEventStatus.PROCESSING,
|
|
3006
|
+
});
|
|
3007
|
+
|
|
3008
|
+
const response = await makeFunctionsRequest(cloudFunction, input.payload);
|
|
3009
|
+
|
|
3010
|
+
this.logService.add({
|
|
3011
|
+
...this.baseLogs,
|
|
3012
|
+
...additional_logs,
|
|
3013
|
+
message: 'Run function - success',
|
|
3014
|
+
data: { data, payload: input.payload },
|
|
3015
|
+
status: LogEventStatus.SUCCESS,
|
|
3016
|
+
});
|
|
3017
|
+
} catch (e) {
|
|
3018
|
+
this.logService.add({
|
|
3019
|
+
...this.baseLogs,
|
|
3020
|
+
...additional_logs,
|
|
3021
|
+
message: 'Run function - failed',
|
|
3022
|
+
data: e,
|
|
3023
|
+
status: LogEventStatus.FAIL,
|
|
3024
|
+
});
|
|
3025
|
+
await this.logService.publish();
|
|
3026
|
+
}
|
|
3027
|
+
}*/
|
|
3028
|
+
async runStorage(data, additional_logs = {}, bootstrapData) {
|
|
2981
3029
|
const { product_id, env, event, cache: cache_tag } = data;
|
|
2982
3030
|
const input = data.input;
|
|
2983
3031
|
try {
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
3032
|
+
let storage;
|
|
3033
|
+
let storageEnv;
|
|
3034
|
+
// Use bootstrap data if provided, otherwise fetch via API
|
|
3035
|
+
if (bootstrapData) {
|
|
3036
|
+
storage = bootstrapData.storage;
|
|
3037
|
+
storageEnv = bootstrapData.storage_env;
|
|
3038
|
+
}
|
|
3039
|
+
else {
|
|
3040
|
+
// Fallback to original API-based fetching
|
|
3041
|
+
await this.intializeProduct(additional_logs);
|
|
3042
|
+
storage = await this.productBuilderService.fetchStorage(event);
|
|
3043
|
+
storageEnv = storage.envs.find((el) => el.slug === env.slug);
|
|
3044
|
+
}
|
|
2987
3045
|
if (!storageEnv) {
|
|
2988
3046
|
throw new Error(`Storage env for ${env.slug} not found`);
|
|
2989
3047
|
}
|
|
@@ -3008,8 +3066,12 @@ class ProcessorService {
|
|
|
3008
3066
|
}
|
|
3009
3067
|
}
|
|
3010
3068
|
input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
|
|
3011
|
-
input.fileName = input.fileName
|
|
3012
|
-
|
|
3069
|
+
input.fileName = input.fileName
|
|
3070
|
+
? await this.generateStringValues(input.fileName, '', additional_logs, [])
|
|
3071
|
+
: undefined;
|
|
3072
|
+
input.mimeType = input.mimeType
|
|
3073
|
+
? await this.generateStringValues(input.mimeType, '', additional_logs, [])
|
|
3074
|
+
: undefined;
|
|
3013
3075
|
result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
|
|
3014
3076
|
if (cache_tag && this.redisClient) {
|
|
3015
3077
|
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
@@ -3034,123 +3096,6 @@ class ProcessorService {
|
|
|
3034
3096
|
throw e;
|
|
3035
3097
|
}
|
|
3036
3098
|
}
|
|
3037
|
-
async runDBAction(db_action, additional_logs = {}) {
|
|
3038
|
-
const { product_id, env, event, cache: cache_tag } = db_action;
|
|
3039
|
-
const input = db_action.input;
|
|
3040
|
-
try {
|
|
3041
|
-
//await this.intializeProduct(additional_logs);
|
|
3042
|
-
const [database_tag, action_tag] = event.split(':');
|
|
3043
|
-
const database = await this.productBuilderService.fetchDatabase(database_tag);
|
|
3044
|
-
const databaseAction = await this.productBuilderService.fetchDatabaseAction(event);
|
|
3045
|
-
const databaseEnv = database.envs.find((el) => el.slug === env.slug);
|
|
3046
|
-
if (!databaseEnv) {
|
|
3047
|
-
throw new Error(`Database env for ${env.slug} not found`);
|
|
3048
|
-
}
|
|
3049
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch database action - success', data: databaseAction, status: types_1.LogEventStatus.SUCCESS }));
|
|
3050
|
-
input.data = await this.generatePayload(input.data, db_action, additional_logs, databaseAction.data);
|
|
3051
|
-
if (Array.isArray(input.data)) {
|
|
3052
|
-
await Promise.all(input.data.map(async (d) => {
|
|
3053
|
-
const dataValidationPayload = (await this.inputService.parseJson({
|
|
3054
|
-
data: d,
|
|
3055
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
3056
|
-
}));
|
|
3057
|
-
this.inputService.validateInput(dataValidationPayload, databaseAction.data);
|
|
3058
|
-
}));
|
|
3059
|
-
}
|
|
3060
|
-
else {
|
|
3061
|
-
const dataValidationPayload = (await this.inputService.parseJson({
|
|
3062
|
-
data: input.data,
|
|
3063
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
3064
|
-
}));
|
|
3065
|
-
this.inputService.validateInput(dataValidationPayload, databaseAction.data);
|
|
3066
|
-
if (input.filter) {
|
|
3067
|
-
const filterValidationPayload = (await this.inputService.parseJson({
|
|
3068
|
-
data: input.filter,
|
|
3069
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
3070
|
-
}));
|
|
3071
|
-
this.inputService.validateInput(filterValidationPayload, databaseAction.filterData);
|
|
3072
|
-
}
|
|
3073
|
-
}
|
|
3074
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database action payload - success', data: { db_action, payload: (0, processor_utils_1.anonymizeObject)(input.data) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3075
|
-
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
3076
|
-
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
3077
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database update action filter - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
3078
|
-
}
|
|
3079
|
-
}
|
|
3080
|
-
let result;
|
|
3081
|
-
if (cache_tag && this.redisClient) {
|
|
3082
|
-
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
3083
|
-
if (!productCache) {
|
|
3084
|
-
throw new Error('Invalid cache tag ');
|
|
3085
|
-
}
|
|
3086
|
-
const inputString = JSON.stringify(input);
|
|
3087
|
-
const check = await this.fetchFromCache({
|
|
3088
|
-
cache_tag,
|
|
3089
|
-
input: inputString,
|
|
3090
|
-
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
3091
|
-
expiry: productCache.expiry,
|
|
3092
|
-
}, additional_logs);
|
|
3093
|
-
if (check) {
|
|
3094
|
-
result = JSON.parse(check);
|
|
3095
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run database action query - return from cache', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3096
|
-
return result;
|
|
3097
|
-
}
|
|
3098
|
-
}
|
|
3099
|
-
const template = typeof databaseAction.template === 'string' ? databaseAction.template : JSON.stringify(databaseAction.template);
|
|
3100
|
-
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
3101
|
-
const MongoDBHandler = await (0, mongo_repo_1.loadMongoDbHandler)();
|
|
3102
|
-
if (!MongoDBHandler) {
|
|
3103
|
-
throw new Error(`Running in browser, mongo handler not loaded.`);
|
|
3104
|
-
}
|
|
3105
|
-
const mongoHandler = new MongoDBHandler(databaseEnv.connection_url);
|
|
3106
|
-
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
3107
|
-
const filterTemplate = typeof databaseAction.filterTemplate === 'string'
|
|
3108
|
-
? databaseAction.filterTemplate
|
|
3109
|
-
: JSON.stringify(databaseAction.filterTemplate);
|
|
3110
|
-
result = await mongoHandler[databaseAction.type](databaseAction.data, template, input.data, databaseAction.tableName, databaseAction.filterData, filterTemplate, input.filter);
|
|
3111
|
-
}
|
|
3112
|
-
else {
|
|
3113
|
-
result = await mongoHandler[databaseAction.type](databaseAction.data, template, input.data, databaseAction.tableName);
|
|
3114
|
-
}
|
|
3115
|
-
}
|
|
3116
|
-
else if (database.type === types_1.DatabaseTypes.POSTGRES) {
|
|
3117
|
-
const PostgresDBHandler = await (0, postgres_repo_1.loadPostgresHandler)();
|
|
3118
|
-
if (!PostgresDBHandler) {
|
|
3119
|
-
throw new Error(`Running in browser, postgres handler not loaded.`);
|
|
3120
|
-
}
|
|
3121
|
-
const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchPrivateKey()));
|
|
3122
|
-
if (databaseAction.type !== types_1.DatabaseActionTypes.AGGREGATE) {
|
|
3123
|
-
result = await pgHandler[databaseAction.type](databaseAction.data, template, input.data);
|
|
3124
|
-
}
|
|
3125
|
-
}
|
|
3126
|
-
//await this.logService.publish();
|
|
3127
|
-
// const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
|
|
3128
|
-
await this.addToSuccessOutput(db_action, result, additional_logs);
|
|
3129
|
-
if (cache_tag && this.redisClient) {
|
|
3130
|
-
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
3131
|
-
if (!productCache) {
|
|
3132
|
-
throw new Error('Invalid cache tag ');
|
|
3133
|
-
}
|
|
3134
|
-
const inputString = JSON.stringify(input);
|
|
3135
|
-
await this.addToCache({
|
|
3136
|
-
input: inputString,
|
|
3137
|
-
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
3138
|
-
data: JSON.stringify(result),
|
|
3139
|
-
cache_tag,
|
|
3140
|
-
timestamp: Date.now(),
|
|
3141
|
-
product_tag: this.productTag,
|
|
3142
|
-
component_tag: database_tag,
|
|
3143
|
-
component_type: types_1.ProductComponents.DATABASE_ACTION,
|
|
3144
|
-
}, additional_logs);
|
|
3145
|
-
}
|
|
3146
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Attempt database action - successful', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3147
|
-
return result;
|
|
3148
|
-
}
|
|
3149
|
-
catch (e) {
|
|
3150
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt database action - failed', data: { e: e.toString() }, status: types_1.LogEventStatus.FAIL }));
|
|
3151
|
-
throw e;
|
|
3152
|
-
}
|
|
3153
|
-
}
|
|
3154
3099
|
async runBrokerSubscribe(data, additional_logs = {}) {
|
|
3155
3100
|
const { env, event } = data;
|
|
3156
3101
|
const input = data.input;
|
|
@@ -3185,9 +3130,7 @@ class ProcessorService {
|
|
|
3185
3130
|
if (createBrokerService) {
|
|
3186
3131
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
3187
3132
|
await brokerService.subscribe(url, input.callback);
|
|
3188
|
-
|
|
3189
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Subscribe to broker topic - success', data: { event }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3190
|
-
}
|
|
3133
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Subscribe to broker topic - success', data: { event }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3191
3134
|
return;
|
|
3192
3135
|
}
|
|
3193
3136
|
else {
|
|
@@ -3234,9 +3177,7 @@ class ProcessorService {
|
|
|
3234
3177
|
if (createBrokerService) {
|
|
3235
3178
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
3236
3179
|
await brokerService.publish(url, input.message);
|
|
3237
|
-
|
|
3238
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to broker topic - success', successful_execution: true, data: { event }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3239
|
-
}
|
|
3180
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to broker topic - success', successful_execution: true, data: { event }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3240
3181
|
return;
|
|
3241
3182
|
}
|
|
3242
3183
|
else {
|
|
@@ -3286,7 +3227,7 @@ class ProcessorService {
|
|
|
3286
3227
|
type: input.mimeType,
|
|
3287
3228
|
event: data.event,
|
|
3288
3229
|
env: data.env.slug,
|
|
3289
|
-
size: Buffer.from(input.buffer).length
|
|
3230
|
+
size: Buffer.from(input.buffer).length,
|
|
3290
3231
|
}, this.getUserAccess());
|
|
3291
3232
|
}
|
|
3292
3233
|
catch (e) { }
|
|
@@ -3303,35 +3244,6 @@ class ProcessorService {
|
|
|
3303
3244
|
throw e;
|
|
3304
3245
|
}
|
|
3305
3246
|
}
|
|
3306
|
-
async processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs, returnValue = false) {
|
|
3307
|
-
try {
|
|
3308
|
-
const result = await this.processorApiService.processProduct(this.productId, {
|
|
3309
|
-
input: input,
|
|
3310
|
-
database_tag: database_tag,
|
|
3311
|
-
database_env_slug: databaseEnv.slug,
|
|
3312
|
-
tag: action_tag,
|
|
3313
|
-
component: types_1.ProductComponents.DATABASE_ACTION,
|
|
3314
|
-
}, {
|
|
3315
|
-
user_id: this.user_id,
|
|
3316
|
-
token: this.token,
|
|
3317
|
-
workspace_id: this.workspace_id,
|
|
3318
|
-
public_key: this.public_key,
|
|
3319
|
-
});
|
|
3320
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Run database query - success', data: { payload: (0, processor_utils_1.anonymizeObject)(input) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3321
|
-
return result;
|
|
3322
|
-
}
|
|
3323
|
-
catch (e) {
|
|
3324
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Running database query - failed', data: { payload: (0, processor_utils_1.anonymizeObject)(input), e }, status: types_1.LogEventStatus.FAIL }));
|
|
3325
|
-
const value = await this.addToFailureOutput(e, db_action, {
|
|
3326
|
-
db_action,
|
|
3327
|
-
input,
|
|
3328
|
-
database_tag,
|
|
3329
|
-
databaseEnv,
|
|
3330
|
-
action_tag,
|
|
3331
|
-
}, additional_logs);
|
|
3332
|
-
return value;
|
|
3333
|
-
}
|
|
3334
|
-
}
|
|
3335
3247
|
async writeResult(status, retryable = true) {
|
|
3336
3248
|
this.processorApiService.saveResult({
|
|
3337
3249
|
status,
|
|
@@ -3341,12 +3253,106 @@ class ProcessorService {
|
|
|
3341
3253
|
retryable,
|
|
3342
3254
|
result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchPrivateKey()),
|
|
3343
3255
|
process_id: this.process_id,
|
|
3344
|
-
feature_id:
|
|
3256
|
+
feature_id: null,
|
|
3345
3257
|
product_id: this.productId,
|
|
3346
3258
|
env: this.processEnv.slug,
|
|
3347
3259
|
input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchPrivateKey()),
|
|
3348
3260
|
}, this.getUserAccess());
|
|
3349
3261
|
}
|
|
3262
|
+
/**
|
|
3263
|
+
* Separate credentials into prefixed (e.g., 'headers:Authorization') and non-prefixed (e.g., 'api_key').
|
|
3264
|
+
* Prefixed credentials are applied directly to the correct section after resolution.
|
|
3265
|
+
* Non-prefixed credentials go through InputResolver to determine their placement.
|
|
3266
|
+
*/
|
|
3267
|
+
separateCredentials(credentials) {
|
|
3268
|
+
const prefixed = {};
|
|
3269
|
+
const nonPrefixed = {};
|
|
3270
|
+
for (const [key, value] of Object.entries(credentials)) {
|
|
3271
|
+
if (key.startsWith('headers:') || key.startsWith('body:') ||
|
|
3272
|
+
key.startsWith('params:') || key.startsWith('query:')) {
|
|
3273
|
+
prefixed[key] = value;
|
|
3274
|
+
}
|
|
3275
|
+
else {
|
|
3276
|
+
nonPrefixed[key] = value;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
return { prefixed, nonPrefixed };
|
|
3280
|
+
}
|
|
3281
|
+
/**
|
|
3282
|
+
* Check if a key exists in the action schema for a given section (headers, body, params, query).
|
|
3283
|
+
* Returns true if the key is defined in the schema, false otherwise.
|
|
3284
|
+
*/
|
|
3285
|
+
isKeyInActionSchema(action, section, key) {
|
|
3286
|
+
if (!action)
|
|
3287
|
+
return false;
|
|
3288
|
+
const sectionSchema = action[section];
|
|
3289
|
+
if (!sectionSchema || !sectionSchema.data)
|
|
3290
|
+
return false;
|
|
3291
|
+
// Check if the key exists in the schema's data array
|
|
3292
|
+
return sectionSchema.data.some(item => item.key === key);
|
|
3293
|
+
}
|
|
3294
|
+
/**
|
|
3295
|
+
* Apply prefixed credentials (e.g., 'headers:Authorization') to resolved input.
|
|
3296
|
+
* Credentials are applied with lower priority - existing values in resolvedInput take precedence.
|
|
3297
|
+
* Only applies credentials if the action schema defines the corresponding field.
|
|
3298
|
+
*/
|
|
3299
|
+
applyPrefixedCredentials(credentials, resolvedInput, action) {
|
|
3300
|
+
const result = {
|
|
3301
|
+
body: Object.assign({}, (resolvedInput.body || {})),
|
|
3302
|
+
params: Object.assign({}, (resolvedInput.params || {})),
|
|
3303
|
+
query: Object.assign({}, (resolvedInput.query || {})),
|
|
3304
|
+
headers: Object.assign({}, (resolvedInput.headers || {})),
|
|
3305
|
+
};
|
|
3306
|
+
for (const [key, value] of Object.entries(credentials)) {
|
|
3307
|
+
if (key.startsWith('headers:')) {
|
|
3308
|
+
const headerKey = key.substring(8); // Remove 'headers:' prefix
|
|
3309
|
+
// Only apply if the action schema expects this header field
|
|
3310
|
+
if (!this.isKeyInActionSchema(action, 'headers', headerKey)) {
|
|
3311
|
+
continue; // Skip - action doesn't expect this credential
|
|
3312
|
+
}
|
|
3313
|
+
// Only set if not already present (user input takes precedence)
|
|
3314
|
+
if (!(headerKey in (result.headers || {}))) {
|
|
3315
|
+
result.headers = result.headers || {};
|
|
3316
|
+
result.headers[headerKey] = value;
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
else if (key.startsWith('body:')) {
|
|
3320
|
+
const bodyKey = key.substring(5); // Remove 'body:' prefix
|
|
3321
|
+
// Only apply if the action schema expects this body field
|
|
3322
|
+
if (!this.isKeyInActionSchema(action, 'body', bodyKey)) {
|
|
3323
|
+
continue; // Skip - action doesn't expect this credential
|
|
3324
|
+
}
|
|
3325
|
+
if (!(bodyKey in (result.body || {}))) {
|
|
3326
|
+
result.body = result.body || {};
|
|
3327
|
+
result.body[bodyKey] = value;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
else if (key.startsWith('params:')) {
|
|
3331
|
+
const paramsKey = key.substring(7); // Remove 'params:' prefix
|
|
3332
|
+
// Only apply if the action schema expects this params field
|
|
3333
|
+
if (!this.isKeyInActionSchema(action, 'params', paramsKey)) {
|
|
3334
|
+
continue; // Skip - action doesn't expect this credential
|
|
3335
|
+
}
|
|
3336
|
+
if (!(paramsKey in (result.params || {}))) {
|
|
3337
|
+
result.params = result.params || {};
|
|
3338
|
+
result.params[paramsKey] = value;
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
else if (key.startsWith('query:')) {
|
|
3342
|
+
const queryKey = key.substring(6); // Remove 'query:' prefix
|
|
3343
|
+
// Only apply if the action schema expects this query field
|
|
3344
|
+
if (!this.isKeyInActionSchema(action, 'query', queryKey)) {
|
|
3345
|
+
continue; // Skip - action doesn't expect this credential
|
|
3346
|
+
}
|
|
3347
|
+
if (!(queryKey in (result.query || {}))) {
|
|
3348
|
+
result.query = result.query || {};
|
|
3349
|
+
result.query[queryKey] = value;
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
// Ignore keys without recognized prefixes - credentials should always be prefixed
|
|
3353
|
+
}
|
|
3354
|
+
return result;
|
|
3355
|
+
}
|
|
3350
3356
|
async validateActionDataMappingInput(input, type) {
|
|
3351
3357
|
try {
|
|
3352
3358
|
if (type === types_1.FeatureEventTypes.ACTION || type === types_1.WebhookEventTypes.WEBHOOK_REGISTER) {
|
|
@@ -3366,7 +3372,7 @@ class ProcessorService {
|
|
|
3366
3372
|
}
|
|
3367
3373
|
async processAction(action) {
|
|
3368
3374
|
//TODO: schema validation
|
|
3369
|
-
const { env, input, retries, event, app, product: product_tag } = action;
|
|
3375
|
+
const { env, input, retries, action: event, app, product: product_tag, session, cache } = action;
|
|
3370
3376
|
const additional_logs = {
|
|
3371
3377
|
parent_tag: (0, string_utils_1.extractOriginAndTag)(app),
|
|
3372
3378
|
child_tag: event,
|
|
@@ -3374,40 +3380,141 @@ class ProcessorService {
|
|
|
3374
3380
|
name: 'Process Action',
|
|
3375
3381
|
};
|
|
3376
3382
|
this.component = types_1.LogEventTypes.ACTION;
|
|
3383
|
+
// Session log fields (will be populated if session is provided)
|
|
3384
|
+
let sessionLogFields = {};
|
|
3385
|
+
let resolvedInput = input;
|
|
3377
3386
|
try {
|
|
3378
|
-
// validate input do not allow $Sequence or $Length and $Size of $Input
|
|
3379
|
-
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3380
3387
|
this.input = action;
|
|
3381
3388
|
this.start = Date.now();
|
|
3382
|
-
this.productTag = product_tag;
|
|
3383
3389
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
3390
|
+
if (product_tag) {
|
|
3391
|
+
this.productTag = product_tag;
|
|
3392
|
+
}
|
|
3384
3393
|
this.baseLogs = {
|
|
3385
|
-
product_tag: this.productTag,
|
|
3394
|
+
product_tag: this.productTag || '',
|
|
3386
3395
|
workspace_id: this.workspace_id,
|
|
3387
3396
|
env,
|
|
3388
3397
|
type: types_1.LogEventTypes.ACTION,
|
|
3389
3398
|
process_id,
|
|
3390
3399
|
data: input,
|
|
3391
3400
|
};
|
|
3392
|
-
|
|
3393
|
-
await this.
|
|
3401
|
+
// Single ultra-lightweight bootstrap call - returns action data directly
|
|
3402
|
+
const bootstrapData = await this.productBuilderService.bootstrapAction({
|
|
3403
|
+
product_tag,
|
|
3404
|
+
env_slug: env,
|
|
3405
|
+
access_tag: app,
|
|
3406
|
+
action_tag: event,
|
|
3407
|
+
});
|
|
3408
|
+
// Initialize from bootstrap data
|
|
3409
|
+
if (bootstrapData.product_id) {
|
|
3410
|
+
this.productId = bootstrapData.product_id;
|
|
3411
|
+
}
|
|
3412
|
+
// Resolve flat input to structured format using action schema
|
|
3413
|
+
// This must happen AFTER bootstrap when we have the action schema
|
|
3414
|
+
if (bootstrapData.action && input && typeof input === 'object') {
|
|
3415
|
+
if (!(0, utils_1.isStructuredInput)(input)) {
|
|
3416
|
+
// Flat input detected - resolve using action schema
|
|
3417
|
+
let flatInput = Object.assign({}, input);
|
|
3418
|
+
// Gather all credentials (static + OAuth)
|
|
3419
|
+
// Priority: user input > OAuth > static config
|
|
3420
|
+
const allCredentials = {};
|
|
3421
|
+
// Static credentials (lowest priority)
|
|
3422
|
+
const sharedCredentials = credential_manager_1.credentialManager.get({ product: product_tag, app, env });
|
|
3423
|
+
if (sharedCredentials) {
|
|
3424
|
+
Object.assign(allCredentials, sharedCredentials);
|
|
3425
|
+
}
|
|
3426
|
+
// OAuth credentials (higher priority, overwrites static)
|
|
3427
|
+
if (product_tag && oauth_manager_1.oauthManager.has(product_tag, app, env)) {
|
|
3428
|
+
const oauthCredentials = await oauth_manager_1.oauthManager.getCredentials(product_tag, app, env);
|
|
3429
|
+
if (oauthCredentials) {
|
|
3430
|
+
Object.assign(allCredentials, oauthCredentials);
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
// Separate credentials into prefixed and non-prefixed
|
|
3434
|
+
const { prefixed, nonPrefixed } = this.separateCredentials(allCredentials);
|
|
3435
|
+
const inputResolver = new utils_1.InputResolver();
|
|
3436
|
+
// Build location map to check which keys exist in the schema
|
|
3437
|
+
const locationMap = inputResolver.buildLocationMap(bootstrapData.action);
|
|
3438
|
+
// Merge non-prefixed credentials into flatInput BEFORE resolution
|
|
3439
|
+
// Only include credentials that exist in the action schema
|
|
3440
|
+
// User input takes precedence over credentials
|
|
3441
|
+
for (const [key, value] of Object.entries(nonPrefixed)) {
|
|
3442
|
+
// Skip if user already provided this key
|
|
3443
|
+
if (key in flatInput) {
|
|
3444
|
+
continue;
|
|
3445
|
+
}
|
|
3446
|
+
// Only include if the key exists in the action schema
|
|
3447
|
+
if (locationMap.allValidKeys.has(key)) {
|
|
3448
|
+
flatInput[key] = value;
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
try {
|
|
3452
|
+
resolvedInput = inputResolver.resolve(flatInput, bootstrapData.action, { strict: true });
|
|
3453
|
+
}
|
|
3454
|
+
catch (e) {
|
|
3455
|
+
if (e instanceof utils_1.InputResolutionError) {
|
|
3456
|
+
throw new Error(`Input resolution failed for action '${event}': ${e.message}`);
|
|
3457
|
+
}
|
|
3458
|
+
throw e;
|
|
3459
|
+
}
|
|
3460
|
+
// Apply prefixed credentials AFTER resolution (directly to correct section)
|
|
3461
|
+
// Only credentials that match fields in the action schema are applied
|
|
3462
|
+
if (Object.keys(prefixed).length > 0) {
|
|
3463
|
+
resolvedInput = this.applyPrefixedCredentials(prefixed, resolvedInput, bootstrapData.action);
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
else {
|
|
3467
|
+
// Already structured - validate with existing schema
|
|
3468
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
else {
|
|
3472
|
+
// Fallback: validate with existing schema if no action bootstrap data
|
|
3473
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3474
|
+
}
|
|
3475
|
+
// Process session if provided - verify and resolve $Session{} references
|
|
3476
|
+
if (session && bootstrapData.private_key) {
|
|
3477
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../../sessions')));
|
|
3478
|
+
const sessionResult = await processSessionForExecution(session, bootstrapData.private_key, resolvedInput, env);
|
|
3479
|
+
if (sessionResult.error) {
|
|
3480
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
3481
|
+
}
|
|
3482
|
+
resolvedInput = sessionResult.input;
|
|
3483
|
+
sessionLogFields = sessionResult.logFields;
|
|
3484
|
+
}
|
|
3485
|
+
// Initialize log service if needed
|
|
3486
|
+
if (!this.logService) {
|
|
3487
|
+
this.logService = new logs_service_1.default({
|
|
3488
|
+
product_id: this.productId,
|
|
3489
|
+
workspace_id: this.workspace_id,
|
|
3490
|
+
public_key: this.public_key,
|
|
3491
|
+
user_id: this.user_id,
|
|
3492
|
+
token: this.token,
|
|
3493
|
+
env_type: this.environment,
|
|
3494
|
+
});
|
|
3495
|
+
}
|
|
3394
3496
|
this.process_id = process_id;
|
|
3395
3497
|
this.baseLogs.product_id = this.productId;
|
|
3396
|
-
|
|
3397
|
-
this.
|
|
3398
|
-
|
|
3399
|
-
throw new Error(`Environment ${env} is not active`);
|
|
3400
|
-
}
|
|
3498
|
+
// Add session fields to base logs
|
|
3499
|
+
this.baseLogs = Object.assign(Object.assign({}, this.baseLogs), sessionLogFields);
|
|
3500
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Bootstrap action - success', data: { product_id: this.productId, env: env }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3401
3501
|
const result = await this.runAction({
|
|
3402
3502
|
type: types_1.FeatureEventTypes.ACTION,
|
|
3403
3503
|
event,
|
|
3404
|
-
cache:
|
|
3504
|
+
cache: cache,
|
|
3405
3505
|
app,
|
|
3406
|
-
input,
|
|
3407
|
-
env:
|
|
3506
|
+
input: resolvedInput,
|
|
3507
|
+
env: this.processEnv,
|
|
3408
3508
|
retries: retries || 0,
|
|
3409
3509
|
allow_fail: false,
|
|
3410
|
-
|
|
3510
|
+
hasProduct: !!product_tag,
|
|
3511
|
+
}, additional_logs, true, {
|
|
3512
|
+
action: bootstrapData.action,
|
|
3513
|
+
app_env: bootstrapData.app_env,
|
|
3514
|
+
retries: bootstrapData.retries,
|
|
3515
|
+
app_active: bootstrapData.app_active,
|
|
3516
|
+
recipient_workspace_id: bootstrapData.recipient_workspace_id,
|
|
3517
|
+
});
|
|
3411
3518
|
this.end = Date.now();
|
|
3412
3519
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3413
3520
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
@@ -3415,7 +3522,7 @@ class ProcessorService {
|
|
|
3415
3522
|
return result;
|
|
3416
3523
|
}
|
|
3417
3524
|
catch (e) {
|
|
3418
|
-
console.log(
|
|
3525
|
+
console.log('ERRRRROORRRRR!!!!!!', e);
|
|
3419
3526
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - failed', data: { e: e.toString() }, status: types_1.LogEventStatus.FAIL }));
|
|
3420
3527
|
this.end = Date.now();
|
|
3421
3528
|
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
@@ -3423,63 +3530,10 @@ class ProcessorService {
|
|
|
3423
3530
|
return { process_id: this.process_id };
|
|
3424
3531
|
}
|
|
3425
3532
|
}
|
|
3426
|
-
async processDBAction(action) {
|
|
3427
|
-
//TODO: schema validation
|
|
3428
|
-
const { env, input, retries, event, product: product_tag } = action;
|
|
3429
|
-
const [parent_tag, child_tag] = event.split(':');
|
|
3430
|
-
this.component = types_1.LogEventTypes.DB_ACTION;
|
|
3431
|
-
if (!parent_tag || !child_tag) {
|
|
3432
|
-
throw new Error(`database action events should be in the format notification_tag:message_tag`);
|
|
3433
|
-
}
|
|
3434
|
-
const additional_logs = {
|
|
3435
|
-
parent_tag,
|
|
3436
|
-
child_tag,
|
|
3437
|
-
type: types_1.LogEventTypes.DB_ACTION,
|
|
3438
|
-
name: 'Process database action',
|
|
3439
|
-
};
|
|
3440
|
-
try {
|
|
3441
|
-
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3442
|
-
this.input = action;
|
|
3443
|
-
this.start = Date.now();
|
|
3444
|
-
this.productTag = product_tag;
|
|
3445
|
-
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
3446
|
-
this.baseLogs = Object.assign({ product_tag: this.productTag, workspace_id: this.workspace_id, env,
|
|
3447
|
-
process_id, data: input }, additional_logs);
|
|
3448
|
-
await this.intializeProduct(additional_logs);
|
|
3449
|
-
this.baseLogs.product_id = this.productId;
|
|
3450
|
-
this.process_id = process_id;
|
|
3451
|
-
const productEnv = await this.fetchEnv(env, additional_logs);
|
|
3452
|
-
this.processEnv = productEnv;
|
|
3453
|
-
if (!productEnv.active) {
|
|
3454
|
-
throw new Error(`Environment ${env} is not active`);
|
|
3455
|
-
}
|
|
3456
|
-
const payload = {
|
|
3457
|
-
type: types_1.FeatureEventTypes.DB_ACTION,
|
|
3458
|
-
event,
|
|
3459
|
-
input,
|
|
3460
|
-
cache: action.cache,
|
|
3461
|
-
env: productEnv,
|
|
3462
|
-
retries: retries || 0,
|
|
3463
|
-
allow_fail: false,
|
|
3464
|
-
};
|
|
3465
|
-
const result = await this.runDBAction(payload, additional_logs);
|
|
3466
|
-
this.end = Date.now();
|
|
3467
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3468
|
-
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3469
|
-
await this.logService.publish();
|
|
3470
|
-
return result;
|
|
3471
|
-
}
|
|
3472
|
-
catch (e) {
|
|
3473
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
3474
|
-
this.end = Date.now();
|
|
3475
|
-
await this.logService.publish();
|
|
3476
|
-
return { process_id: this.process_id };
|
|
3477
|
-
}
|
|
3478
|
-
}
|
|
3479
|
-
async processFunction(data) { }
|
|
3480
3533
|
async processNotification(action) {
|
|
3481
3534
|
//TODO: schema validation
|
|
3482
|
-
|
|
3535
|
+
var _a;
|
|
3536
|
+
const { env, input, retries, event, product: product_tag, session, cache } = action;
|
|
3483
3537
|
const [parent_tag, child_tag] = event.split(':');
|
|
3484
3538
|
if (!parent_tag || !child_tag) {
|
|
3485
3539
|
throw new Error(`database action events should be in the format notification_tag:message_tag`);
|
|
@@ -3491,6 +3545,9 @@ class ProcessorService {
|
|
|
3491
3545
|
type: types_1.LogEventTypes.NOTIFICATIONS,
|
|
3492
3546
|
name: 'Process Notification',
|
|
3493
3547
|
};
|
|
3548
|
+
// Session log fields (will be populated if session is provided)
|
|
3549
|
+
let sessionLogFields = {};
|
|
3550
|
+
let resolvedInput = input;
|
|
3494
3551
|
try {
|
|
3495
3552
|
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3496
3553
|
this.input = action;
|
|
@@ -3499,24 +3556,61 @@ class ProcessorService {
|
|
|
3499
3556
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
3500
3557
|
this.baseLogs = Object.assign({ product_tag: this.productTag, workspace_id: this.workspace_id, env,
|
|
3501
3558
|
process_id, data: input }, additional_logs);
|
|
3502
|
-
|
|
3559
|
+
// Single bootstrap call to fetch all notification data
|
|
3560
|
+
const bootstrapData = await this.productBuilderService.bootstrapNotification({
|
|
3561
|
+
product_tag,
|
|
3562
|
+
env_slug: env,
|
|
3563
|
+
notification_tag: parent_tag,
|
|
3564
|
+
message_tag: child_tag,
|
|
3565
|
+
});
|
|
3566
|
+
// Initialize from bootstrap data
|
|
3567
|
+
this.productId = bootstrapData.product_id;
|
|
3568
|
+
this.processEnv = bootstrapData.env;
|
|
3569
|
+
// Process session if provided - verify and resolve $Session{} references
|
|
3570
|
+
if (session && bootstrapData.private_key) {
|
|
3571
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../../sessions')));
|
|
3572
|
+
const sessionResult = await processSessionForExecution(session, bootstrapData.private_key, input, env);
|
|
3573
|
+
if (sessionResult.error) {
|
|
3574
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
3575
|
+
}
|
|
3576
|
+
resolvedInput = sessionResult.input;
|
|
3577
|
+
sessionLogFields = sessionResult.logFields;
|
|
3578
|
+
}
|
|
3579
|
+
// Initialize log service if needed
|
|
3580
|
+
if (!this.logService) {
|
|
3581
|
+
this.logService = new logs_service_1.default({
|
|
3582
|
+
product_id: this.productId,
|
|
3583
|
+
workspace_id: this.workspace_id,
|
|
3584
|
+
public_key: this.public_key,
|
|
3585
|
+
user_id: this.user_id,
|
|
3586
|
+
token: this.token,
|
|
3587
|
+
env_type: this.environment,
|
|
3588
|
+
});
|
|
3589
|
+
}
|
|
3503
3590
|
this.process_id = process_id;
|
|
3504
3591
|
this.baseLogs.product_id = this.productId;
|
|
3505
|
-
|
|
3506
|
-
this.
|
|
3592
|
+
// Add session fields to base logs
|
|
3593
|
+
this.baseLogs = Object.assign(Object.assign({}, this.baseLogs), sessionLogFields);
|
|
3594
|
+
const productEnv = bootstrapData.env;
|
|
3507
3595
|
if (!productEnv.active) {
|
|
3508
3596
|
throw new Error(`Environment ${env} is not active`);
|
|
3509
3597
|
}
|
|
3510
3598
|
const payload = {
|
|
3511
3599
|
type: types_1.FeatureEventTypes.NOTIFICATION,
|
|
3512
3600
|
event,
|
|
3513
|
-
input,
|
|
3514
|
-
cache:
|
|
3601
|
+
input: resolvedInput,
|
|
3602
|
+
cache: cache,
|
|
3515
3603
|
env: productEnv,
|
|
3516
3604
|
retries: retries || 0,
|
|
3517
3605
|
allow_fail: false,
|
|
3518
3606
|
};
|
|
3519
|
-
|
|
3607
|
+
// Find the env config for the notification
|
|
3608
|
+
const envConfig = (_a = bootstrapData.notification.envs) === null || _a === void 0 ? void 0 : _a.find((data) => data.slug === env);
|
|
3609
|
+
const result = await this.runNotification(payload, additional_logs, {
|
|
3610
|
+
notification: bootstrapData.notification,
|
|
3611
|
+
message: bootstrapData.message,
|
|
3612
|
+
env_config: envConfig,
|
|
3613
|
+
});
|
|
3520
3614
|
this.end = Date.now();
|
|
3521
3615
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send notification - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3522
3616
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
@@ -3609,7 +3703,7 @@ class ProcessorService {
|
|
|
3609
3703
|
if (!this.redisClient)
|
|
3610
3704
|
return;
|
|
3611
3705
|
const key = `healthcheck:${data.product}:${data.healthcheck}:${data.env}`;
|
|
3612
|
-
console.log(
|
|
3706
|
+
console.log('LOG TO CACHE', key, JSON.stringify(result));
|
|
3613
3707
|
await this.redisClient.set(key, JSON.stringify(result));
|
|
3614
3708
|
console.log();
|
|
3615
3709
|
}
|