@ductape/sdk 0.0.4-v12 → 0.0.4-v120
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/agent-context.d.ts +98 -0
- package/dist/agents/agent-context.js +588 -0
- package/dist/agents/agent-context.js.map +1 -0
- package/dist/agents/agent-executor.d.ts +180 -0
- package/dist/agents/agent-executor.js +715 -0
- package/dist/agents/agent-executor.js.map +1 -0
- package/dist/agents/agents.service.d.ts +310 -0
- package/dist/agents/agents.service.js +1254 -0
- package/dist/agents/agents.service.js.map +1 -0
- package/dist/agents/index.d.ts +55 -0
- package/dist/agents/index.js +110 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/memory-manager.d.ts +182 -0
- package/dist/agents/memory-manager.js +383 -0
- package/dist/agents/memory-manager.js.map +1 -0
- package/dist/agents/tool-registry.d.ts +141 -0
- package/dist/agents/tool-registry.js +355 -0
- package/dist/agents/tool-registry.js.map +1 -0
- package/dist/agents/types/agents.types.d.ts +1227 -0
- package/dist/agents/types/agents.types.js +12 -0
- package/dist/agents/types/agents.types.js.map +1 -0
- package/dist/agents/types/index.d.ts +6 -0
- package/dist/agents/types/index.js +23 -0
- package/dist/agents/types/index.js.map +1 -0
- package/dist/agents/vector-store-adapter.d.ts +108 -0
- package/dist/agents/vector-store-adapter.js +213 -0
- package/dist/agents/vector-store-adapter.js.map +1 -0
- package/dist/api/services/appApi.service.d.ts +51 -5
- package/dist/api/services/appApi.service.js +101 -3
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/logsApi.service.d.ts +51 -0
- package/dist/api/services/logsApi.service.js +14 -0
- package/dist/api/services/logsApi.service.js.map +1 -1
- package/dist/api/services/pricingApi.service.d.ts +10 -0
- package/dist/api/services/pricingApi.service.js +34 -0
- package/dist/api/services/pricingApi.service.js.map +1 -0
- package/dist/api/services/processorApi.service.d.ts +745 -0
- package/dist/api/services/processorApi.service.js +536 -2
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +103 -0
- package/dist/api/services/productsApi.service.js +133 -7
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/resilienceApi.service.d.ts +106 -0
- package/dist/api/services/resilienceApi.service.js +224 -0
- package/dist/api/services/resilienceApi.service.js.map +1 -0
- package/dist/api/services/secretsApi.service.d.ts +50 -0
- package/dist/api/services/secretsApi.service.js +113 -0
- package/dist/api/services/secretsApi.service.js.map +1 -0
- package/dist/api/services/workflowApi.service.d.ts +199 -0
- package/dist/api/services/workflowApi.service.js +183 -0
- package/dist/api/services/workflowApi.service.js.map +1 -0
- package/dist/api/services/workspaceApi.service.d.ts +8 -0
- package/dist/api/services/workspaceApi.service.js +20 -0
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +80 -0
- package/dist/api/urls.js +106 -17
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/auth.utils.d.ts +1 -3
- package/dist/api/utils/auth.utils.js.map +1 -1
- package/dist/api/utils/cache.utils.d.ts +1 -1
- package/dist/api/utils/cache.utils.js +2 -2
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/api/utils/strings.utils.d.ts +2 -0
- package/dist/api/utils/strings.utils.js +14 -0
- package/dist/api/utils/strings.utils.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +42 -33
- package/dist/apps/services/app.service.js +574 -223
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/utils/auth-context-manager.d.ts +137 -0
- package/dist/apps/utils/auth-context-manager.js +248 -0
- package/dist/apps/utils/auth-context-manager.js.map +1 -0
- package/dist/apps/utils/credential-manager.d.ts +128 -0
- package/dist/apps/utils/credential-manager.js +199 -0
- package/dist/apps/utils/credential-manager.js.map +1 -0
- package/dist/apps/utils/index.d.ts +10 -0
- package/dist/apps/utils/index.js +54 -0
- package/dist/apps/utils/index.js.map +1 -0
- package/dist/apps/utils/input-helpers.d.ts +67 -0
- package/dist/apps/utils/input-helpers.js +185 -0
- package/dist/apps/utils/input-helpers.js.map +1 -0
- package/dist/apps/utils/input-resolver.d.ts +165 -0
- package/dist/apps/utils/input-resolver.js +477 -0
- package/dist/apps/utils/input-resolver.js.map +1 -0
- package/dist/apps/utils/oauth-manager.d.ts +196 -0
- package/dist/apps/utils/oauth-manager.js +429 -0
- package/dist/apps/utils/oauth-manager.js.map +1 -0
- package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js +22 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.app.validator.js +2 -0
- package/dist/apps/validators/joi-validators/update.app.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +23 -2
- package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
- package/dist/bin.d.ts +26 -0
- package/dist/bin.js +28 -0
- package/dist/bin.js.map +1 -0
- package/dist/brokers/brokers.service.d.ts +418 -0
- package/dist/brokers/brokers.service.js +1156 -0
- package/dist/brokers/brokers.service.js.map +1 -0
- package/dist/brokers/index.d.ts +46 -0
- package/dist/brokers/index.js +83 -0
- package/dist/brokers/index.js.map +1 -0
- package/dist/brokers/types/index.d.ts +565 -0
- package/dist/brokers/types/index.js +8 -0
- package/dist/brokers/types/index.js.map +1 -0
- package/dist/brokers/utils/broker.util.d.ts +33 -0
- package/dist/brokers/utils/broker.util.js +125 -0
- package/dist/brokers/utils/broker.util.js.map +1 -0
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/aws-sqs.service.d.ts +3 -2
- package/dist/brokers/utils/providers/aws-sqs.service.js +71 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js.map +1 -0
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/google-pubsub.service.d.ts +2 -2
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/google-pubsub.service.js +16 -7
- package/dist/brokers/utils/providers/google-pubsub.service.js.map +1 -0
- package/dist/brokers/utils/providers/index.d.ts +6 -0
- package/dist/brokers/utils/providers/index.js +16 -0
- package/dist/brokers/utils/providers/index.js.map +1 -0
- package/dist/brokers/utils/providers/kafka.service.d.ts +23 -0
- package/dist/brokers/utils/providers/kafka.service.js +131 -0
- package/dist/brokers/utils/providers/kafka.service.js.map +1 -0
- package/dist/brokers/utils/providers/nats.service.d.ts +18 -0
- package/dist/brokers/utils/providers/nats.service.js +63 -0
- package/dist/brokers/utils/providers/nats.service.js.map +1 -0
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/rabbitmq.service.d.ts +4 -3
- package/dist/brokers/utils/providers/rabbitmq.service.js +118 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js.map +1 -0
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/redis.service.d.ts +3 -3
- package/dist/{processor/services/messagebrokers → brokers/utils/providers}/redis.service.js +25 -14
- package/dist/brokers/utils/providers/redis.service.js.map +1 -0
- package/dist/cache/cache.manager.d.ts +308 -0
- package/dist/cache/cache.manager.js +900 -0
- package/dist/cache/cache.manager.js.map +1 -0
- package/dist/cache/cache.service.d.ts +191 -0
- package/dist/cache/cache.service.js +594 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/cache/index.d.ts +52 -0
- package/dist/cache/index.js +81 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/types/index.d.ts +110 -0
- package/dist/cache/types/index.js +6 -0
- package/dist/cache/types/index.js.map +1 -0
- package/dist/clients/pricing.client.d.ts +3 -0
- package/dist/clients/pricing.client.js +33 -0
- package/dist/clients/pricing.client.js.map +1 -0
- package/dist/database/actions/action-manager.d.ts +170 -0
- package/dist/database/actions/action-manager.js +465 -0
- package/dist/database/actions/action-manager.js.map +1 -0
- package/dist/database/actions/index.d.ts +6 -0
- package/dist/database/actions/index.js +13 -0
- package/dist/database/actions/index.js.map +1 -0
- package/dist/database/adapters/adapter.factory.d.ts +62 -0
- package/dist/database/adapters/adapter.factory.js +97 -0
- package/dist/database/adapters/adapter.factory.js.map +1 -0
- package/dist/database/adapters/base.adapter.d.ts +423 -0
- package/dist/database/adapters/base.adapter.js +260 -0
- package/dist/database/adapters/base.adapter.js.map +1 -0
- package/dist/database/adapters/cassandra.adapter.d.ts +92 -0
- package/dist/database/adapters/cassandra.adapter.js +1091 -0
- package/dist/database/adapters/cassandra.adapter.js.map +1 -0
- package/dist/database/adapters/dynamodb.adapter.d.ts +110 -0
- package/dist/database/adapters/dynamodb.adapter.js +1564 -0
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
- package/dist/database/adapters/index.d.ts +11 -0
- package/dist/database/adapters/index.js +27 -0
- package/dist/database/adapters/index.js.map +1 -0
- package/dist/database/adapters/mariadb.adapter.d.ts +100 -0
- package/dist/database/adapters/mariadb.adapter.js +247 -0
- package/dist/database/adapters/mariadb.adapter.js.map +1 -0
- package/dist/database/adapters/mongodb.adapter.d.ts +121 -0
- package/dist/database/adapters/mongodb.adapter.js +1284 -0
- package/dist/database/adapters/mongodb.adapter.js.map +1 -0
- package/dist/database/adapters/mysql.adapter.d.ts +86 -0
- package/dist/database/adapters/mysql.adapter.js +1371 -0
- package/dist/database/adapters/mysql.adapter.js.map +1 -0
- package/dist/database/adapters/postgresql.adapter.d.ts +90 -0
- package/dist/database/adapters/postgresql.adapter.js +1487 -0
- package/dist/database/adapters/postgresql.adapter.js.map +1 -0
- package/dist/database/databases.service.d.ts +1476 -0
- package/dist/database/databases.service.js +3068 -0
- package/dist/database/databases.service.js.map +1 -0
- package/dist/database/index.d.ts +46 -0
- package/dist/database/index.js +109 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/migrations/index.d.ts +6 -0
- package/dist/database/migrations/index.js +12 -0
- package/dist/database/migrations/index.js.map +1 -0
- package/dist/database/migrations/migration-engine.d.ts +136 -0
- package/dist/database/migrations/migration-engine.js +1421 -0
- package/dist/database/migrations/migration-engine.js.map +1 -0
- package/dist/database/operators/aggregation-builder.d.ts +67 -0
- package/dist/database/operators/aggregation-builder.js +841 -0
- package/dist/database/operators/aggregation-builder.js.map +1 -0
- package/dist/database/operators/index.d.ts +7 -0
- package/dist/database/operators/index.js +15 -0
- package/dist/database/operators/index.js.map +1 -0
- package/dist/database/operators/query-builder.d.ts +69 -0
- package/dist/database/operators/query-builder.js +447 -0
- package/dist/database/operators/query-builder.js.map +1 -0
- package/dist/database/presave/decrypt.d.ts +25 -0
- package/dist/database/presave/decrypt.js +146 -0
- package/dist/database/presave/decrypt.js.map +1 -0
- package/dist/database/presave/index.d.ts +9 -0
- package/dist/database/presave/index.js +18 -0
- package/dist/database/presave/index.js.map +1 -0
- package/dist/database/presave/presave-processor.d.ts +148 -0
- package/dist/database/presave/presave-processor.js +702 -0
- package/dist/database/presave/presave-processor.js.map +1 -0
- package/dist/database/schema/index.d.ts +7 -0
- package/dist/database/schema/index.js +13 -0
- package/dist/database/schema/index.js.map +1 -0
- package/dist/database/schema/schema-manager.d.ts +258 -0
- package/dist/database/schema/schema-manager.js +638 -0
- package/dist/database/schema/schema-manager.js.map +1 -0
- package/dist/database/transactions/index.d.ts +6 -0
- package/dist/database/transactions/index.js +13 -0
- package/dist/database/transactions/index.js.map +1 -0
- package/dist/database/transactions/transaction-manager.d.ts +113 -0
- package/dist/database/transactions/transaction-manager.js +344 -0
- package/dist/database/transactions/transaction-manager.js.map +1 -0
- package/dist/database/triggers/index.d.ts +7 -0
- package/dist/database/triggers/index.js +14 -0
- package/dist/database/triggers/index.js.map +1 -0
- package/dist/database/triggers/trigger-processor.d.ts +239 -0
- package/dist/database/triggers/trigger-processor.js +1034 -0
- package/dist/database/triggers/trigger-processor.js.map +1 -0
- package/dist/database/types/action.interface.d.ts +148 -0
- package/dist/database/types/action.interface.js +6 -0
- package/dist/database/types/action.interface.js.map +1 -0
- package/dist/database/types/aggregation.interface.d.ts +185 -0
- package/dist/database/types/aggregation.interface.js +6 -0
- package/dist/database/types/aggregation.interface.js.map +1 -0
- package/dist/database/types/connection.interface.d.ts +137 -0
- package/dist/database/types/connection.interface.js +6 -0
- package/dist/database/types/connection.interface.js.map +1 -0
- package/dist/database/types/dashboard.interface.d.ts +74 -0
- package/dist/database/types/dashboard.interface.js +7 -0
- package/dist/database/types/dashboard.interface.js.map +1 -0
- package/dist/database/types/enums.d.ts +195 -0
- package/dist/database/types/enums.js +244 -0
- package/dist/database/types/enums.js.map +1 -0
- package/dist/database/types/index.d.ts +15 -0
- package/dist/database/types/index.js +31 -0
- package/dist/database/types/index.js.map +1 -0
- package/dist/database/types/migration.interface.d.ts +686 -0
- package/dist/database/types/migration.interface.js +9 -0
- package/dist/database/types/migration.interface.js.map +1 -0
- package/dist/database/types/presave.interface.d.ts +292 -0
- package/dist/database/types/presave.interface.js +60 -0
- package/dist/database/types/presave.interface.js.map +1 -0
- package/dist/database/types/query.interface.d.ts +205 -0
- package/dist/database/types/query.interface.js +6 -0
- package/dist/database/types/query.interface.js.map +1 -0
- package/dist/database/types/schema.interface.d.ts +412 -0
- package/dist/database/types/schema.interface.js +6 -0
- package/dist/database/types/schema.interface.js.map +1 -0
- package/dist/database/types/transaction.interface.d.ts +84 -0
- package/dist/database/types/transaction.interface.js +6 -0
- package/dist/database/types/transaction.interface.js.map +1 -0
- package/dist/database/types/trigger.interface.d.ts +612 -0
- package/dist/database/types/trigger.interface.js +121 -0
- package/dist/database/types/trigger.interface.js.map +1 -0
- package/dist/database/types/write.interface.d.ts +216 -0
- package/dist/database/types/write.interface.js +6 -0
- package/dist/database/types/write.interface.js.map +1 -0
- package/dist/database/utils/database-error.d.ts +96 -0
- package/dist/database/utils/database-error.js +221 -0
- package/dist/database/utils/database-error.js.map +1 -0
- package/dist/database/utils/index.d.ts +6 -0
- package/dist/database/utils/index.js +11 -0
- package/dist/database/utils/index.js.map +1 -0
- package/dist/graph/adapters/adapter.factory.d.ts +47 -0
- package/dist/graph/adapters/adapter.factory.js +77 -0
- package/dist/graph/adapters/adapter.factory.js.map +1 -0
- package/dist/graph/adapters/arangodb.adapter.d.ts +86 -0
- package/dist/graph/adapters/arangodb.adapter.js +1588 -0
- package/dist/graph/adapters/arangodb.adapter.js.map +1 -0
- package/dist/graph/adapters/base.adapter.d.ts +264 -0
- package/dist/graph/adapters/base.adapter.js +156 -0
- package/dist/graph/adapters/base.adapter.js.map +1 -0
- package/dist/graph/adapters/index.d.ts +11 -0
- package/dist/graph/adapters/index.js +21 -0
- package/dist/graph/adapters/index.js.map +1 -0
- package/dist/graph/adapters/memgraph.adapter.d.ts +110 -0
- package/dist/graph/adapters/memgraph.adapter.js +1452 -0
- package/dist/graph/adapters/memgraph.adapter.js.map +1 -0
- package/dist/graph/adapters/neo4j.adapter.d.ts +81 -0
- package/dist/graph/adapters/neo4j.adapter.js +1317 -0
- package/dist/graph/adapters/neo4j.adapter.js.map +1 -0
- package/dist/graph/adapters/neptune.adapter.d.ts +82 -0
- package/dist/graph/adapters/neptune.adapter.js +1369 -0
- package/dist/graph/adapters/neptune.adapter.js.map +1 -0
- package/dist/graph/graphs.service.d.ts +606 -0
- package/dist/graph/graphs.service.js +2434 -0
- package/dist/graph/graphs.service.js.map +1 -0
- package/dist/graph/index.d.ts +57 -0
- package/dist/graph/index.js +77 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/transactions/index.d.ts +4 -0
- package/dist/graph/transactions/index.js +9 -0
- package/dist/graph/transactions/index.js.map +1 -0
- package/dist/graph/transactions/transaction-manager.d.ts +61 -0
- package/dist/graph/transactions/transaction-manager.js +126 -0
- package/dist/graph/transactions/transaction-manager.js.map +1 -0
- package/dist/graph/types/connection.interface.d.ts +149 -0
- package/dist/graph/types/connection.interface.js +9 -0
- package/dist/graph/types/connection.interface.js.map +1 -0
- package/dist/graph/types/enums.d.ts +101 -0
- package/dist/graph/types/enums.js +114 -0
- package/dist/graph/types/enums.js.map +1 -0
- package/dist/graph/types/index.d.ts +13 -0
- package/dist/graph/types/index.js +20 -0
- package/dist/graph/types/index.js.map +1 -0
- package/dist/graph/types/node.interface.d.ts +248 -0
- package/dist/graph/types/node.interface.js +9 -0
- package/dist/graph/types/node.interface.js.map +1 -0
- package/dist/graph/types/query.interface.d.ts +175 -0
- package/dist/graph/types/query.interface.js +9 -0
- package/dist/graph/types/query.interface.js.map +1 -0
- package/dist/graph/types/relationship.interface.d.ts +207 -0
- package/dist/graph/types/relationship.interface.js +9 -0
- package/dist/graph/types/relationship.interface.js.map +1 -0
- package/dist/graph/types/schema.interface.d.ts +295 -0
- package/dist/graph/types/schema.interface.js +9 -0
- package/dist/graph/types/schema.interface.js.map +1 -0
- package/dist/graph/types/transaction.interface.d.ts +55 -0
- package/dist/graph/types/transaction.interface.js +9 -0
- package/dist/graph/types/transaction.interface.js.map +1 -0
- package/dist/graph/types/traversal.interface.d.ts +181 -0
- package/dist/graph/types/traversal.interface.js +9 -0
- package/dist/graph/types/traversal.interface.js.map +1 -0
- package/dist/graph/utils/graph-error.d.ts +71 -0
- package/dist/graph/utils/graph-error.js +142 -0
- package/dist/graph/utils/graph-error.js.map +1 -0
- package/dist/graph/utils/index.d.ts +4 -0
- package/dist/graph/utils/index.js +9 -0
- package/dist/graph/utils/index.js.map +1 -0
- package/dist/imports/imports.service.d.ts +3 -3
- package/dist/imports/imports.service.js +8 -7
- package/dist/imports/imports.service.js.map +1 -1
- package/dist/imports/imports.types.d.ts +8 -0
- package/dist/imports/repos/openApi.repo.d.ts +1 -1
- package/dist/imports/repos/openApi.repo.js +414 -47
- package/dist/imports/repos/openApi.repo.js.map +1 -1
- package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
- package/dist/imports/repos/postmanV21.repo.js +126 -83
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +3366 -743
- package/dist/index.js +4885 -1107
- package/dist/index.js.map +1 -1
- package/dist/init.interface.d.ts +407 -0
- package/dist/{processor/services/messagebrokers/messagebrokers.type.js → init.interface.js} +1 -1
- package/dist/init.interface.js.map +1 -0
- package/dist/inputs/inputs.service.d.ts +1 -1
- package/dist/inputs/utils/inputs.utils.create.js +1 -1
- package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
- package/dist/jobs/index.d.ts +38 -0
- package/dist/jobs/index.js +50 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/jobs.service.d.ts +154 -0
- package/dist/jobs/jobs.service.js +491 -0
- package/dist/jobs/jobs.service.js.map +1 -0
- package/dist/jobs/jobs.state.d.ts +113 -0
- package/dist/jobs/jobs.state.js +447 -0
- package/dist/jobs/jobs.state.js.map +1 -0
- package/dist/jobs/types.d.ts +449 -0
- package/dist/jobs/types.js +74 -0
- package/dist/jobs/types.js.map +1 -0
- package/dist/logs/logs.service.js +6 -2
- package/dist/logs/logs.service.js.map +1 -1
- package/dist/logs/logs.types.d.ts +24 -1
- package/dist/logs/logs.types.js +9 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.js +11 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/models.service.d.ts +137 -0
- package/dist/models/models.service.js +195 -0
- package/dist/models/models.service.js.map +1 -0
- package/dist/notifications/index.d.ts +13 -0
- package/dist/notifications/index.js +26 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/notifications.service.d.ts +268 -0
- package/dist/notifications/notifications.service.js +905 -0
- package/dist/notifications/notifications.service.js.map +1 -0
- package/dist/notifications/types/index.d.ts +4 -0
- package/dist/notifications/types/index.js +21 -0
- package/dist/notifications/types/index.js.map +1 -0
- package/dist/notifications/types/notifications.types.d.ts +404 -0
- package/dist/notifications/types/notifications.types.js +49 -0
- package/dist/notifications/types/notifications.types.js.map +1 -0
- package/dist/parsers/index.d.ts +3 -0
- package/dist/parsers/index.js +27 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
- package/dist/parsers/pipelines/postman.pipelines.js +103 -0
- package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
- package/dist/parsers/types/postman.types.d.ts +200 -0
- package/dist/parsers/types/postman.types.js +3 -0
- package/dist/parsers/types/postman.types.js.map +1 -0
- package/dist/parsers/utils/postman.utils.d.ts +12 -0
- package/dist/parsers/utils/postman.utils.js +116 -0
- package/dist/parsers/utils/postman.utils.js.map +1 -0
- package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
- package/dist/parsers/validators/postman-auth.validators.js +127 -0
- package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
- package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-request.validators.js +139 -0
- package/dist/parsers/validators/postman-request.validators.js.map +1 -0
- package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-response.validators.js +150 -0
- package/dist/parsers/validators/postman-response.validators.js.map +1 -0
- package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
- package/dist/parsers/validators/postman-variable.validators.js +163 -0
- package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
- package/dist/pricing/pricing.repo.js +1 -0
- package/dist/pricing/pricing.repo.js.map +1 -0
- package/dist/pricing/pricing.service.d.ts +24 -0
- package/dist/pricing/pricing.service.js +51 -0
- package/dist/pricing/pricing.service.js.map +1 -0
- package/dist/pricing/pricing.types.d.ts +76 -0
- package/dist/pricing/pricing.types.js +21 -0
- package/dist/pricing/pricing.types.js.map +1 -0
- package/dist/pricing/utils/string.utils.d.ts +1 -0
- package/dist/pricing/utils/string.utils.js +9 -0
- package/dist/pricing/utils/string.utils.js.map +1 -0
- package/dist/processor/services/processor.service.d.ts +101 -72
- package/dist/processor/services/processor.service.js +1573 -1343
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/request.service.d.ts +36 -0
- package/dist/processor/services/request.service.js +304 -0
- package/dist/processor/services/request.service.js.map +1 -0
- package/dist/processor/types/request.types.d.ts +14 -0
- package/dist/processor/types/request.types.js +3 -0
- package/dist/processor/types/request.types.js.map +1 -0
- package/dist/processor/utils/processor.utils.js +32 -20
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/request.utils.d.ts +20 -0
- package/dist/processor/utils/request.utils.js +113 -0
- package/dist/processor/utils/request.utils.js.map +1 -0
- package/dist/products/services/products.service.d.ts +358 -79
- package/dist/products/services/products.service.js +2918 -434
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/utils/string.utils.d.ts +1 -1
- package/dist/products/utils/string.utils.js +14 -2
- package/dist/products/utils/string.utils.js.map +1 -1
- package/dist/products/validators/index.d.ts +6 -1
- package/dist/products/validators/index.js +14 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productAgent.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js +266 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productApp.validator.js +2 -2
- package/dist/products/validators/joi-validators/create.productApp.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productGraph.validator.js +89 -0
- package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +81 -25
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productModel.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productModel.validator.js +132 -0
- package/dist/products/validators/joi-validators/create.productModel.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productNotification.validator.js +150 -51
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productStorage.validator.js +77 -18
- package/dist/products/validators/joi-validators/create.productStorage.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productVector.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js +136 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/update.productDatabase.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
- package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productGraph.validator.js +88 -0
- package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -0
- package/dist/resilience/fallback.service.d.ts +140 -0
- package/dist/resilience/fallback.service.js +764 -0
- package/dist/resilience/fallback.service.js.map +1 -0
- package/dist/resilience/healthcheck.service.d.ts +159 -0
- package/dist/resilience/healthcheck.service.js +943 -0
- package/dist/resilience/healthcheck.service.js.map +1 -0
- package/dist/resilience/index.d.ts +104 -0
- package/dist/resilience/index.js +140 -0
- package/dist/resilience/index.js.map +1 -0
- package/dist/resilience/quota.service.d.ts +82 -0
- package/dist/resilience/quota.service.js +516 -0
- package/dist/resilience/quota.service.js.map +1 -0
- package/dist/resilience/resilience.service.d.ts +98 -0
- package/dist/resilience/resilience.service.js +560 -0
- package/dist/resilience/resilience.service.js.map +1 -0
- package/dist/resilience/types/index.d.ts +513 -0
- package/dist/resilience/types/index.js +29 -0
- package/dist/resilience/types/index.js.map +1 -0
- package/dist/secrets/index.d.ts +10 -0
- package/dist/secrets/index.js +33 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/secrets/secrets.resolver.d.ts +52 -0
- package/dist/secrets/secrets.resolver.js +236 -0
- package/dist/secrets/secrets.resolver.js.map +1 -0
- package/dist/secrets/secrets.service.d.ts +93 -0
- package/dist/secrets/secrets.service.js +246 -0
- package/dist/secrets/secrets.service.js.map +1 -0
- package/dist/secrets/secrets.types.d.ts +188 -0
- package/dist/secrets/secrets.types.js +87 -0
- package/dist/secrets/secrets.types.js.map +1 -0
- package/dist/sessions/index.d.ts +50 -0
- package/dist/sessions/index.js +96 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/sessions.helper.d.ts +88 -0
- package/dist/sessions/sessions.helper.js +133 -0
- package/dist/sessions/sessions.helper.js.map +1 -0
- package/dist/sessions/sessions.resolver.d.ts +188 -0
- package/dist/sessions/sessions.resolver.js +603 -0
- package/dist/sessions/sessions.resolver.js.map +1 -0
- package/dist/sessions/sessions.service.d.ts +194 -0
- package/dist/sessions/sessions.service.js +987 -0
- package/dist/sessions/sessions.service.js.map +1 -0
- package/dist/sessions/types/index.d.ts +342 -0
- package/dist/sessions/types/index.js +6 -0
- package/dist/sessions/types/index.js.map +1 -0
- package/dist/storage/index.d.ts +66 -0
- package/dist/storage/index.js +99 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/storage.service.d.ts +177 -0
- package/dist/storage/storage.service.js +897 -0
- package/dist/storage/storage.service.js.map +1 -0
- package/dist/storage/types/index.d.ts +267 -0
- package/dist/storage/types/index.js +6 -0
- package/dist/storage/types/index.js.map +1 -0
- package/dist/storage/utils/storage.util.d.ts +62 -0
- package/dist/storage/utils/storage.util.js +593 -0
- package/dist/storage/utils/storage.util.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +12 -3
- package/dist/types/enums.d.ts +10 -1
- package/dist/types/enums.js +9 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/index.types.d.ts +4 -7
- package/dist/types/index.types.js +0 -1
- package/dist/types/index.types.js.map +1 -1
- package/dist/types/inputs.types.js +1 -1
- package/dist/types/inputs.types.js.map +1 -1
- package/dist/types/pricing.types.d.ts +4 -0
- package/dist/types/pricing.types.js +3 -0
- package/dist/types/pricing.types.js.map +1 -0
- package/dist/types/processor.types.d.ts +265 -38
- package/dist/types/processor.types.js +9 -1
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +954 -29
- package/dist/types/productsBuilder.types.js +210 -3
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/types/request-tracker.interface.js +1 -0
- package/dist/types/request-tracker.interface.js.map +1 -0
- package/dist/types/requests.types.d.ts +2 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +24 -52
- package/dist/utils/index.js.map +1 -1
- package/dist/vector/actions/action-manager.d.ts +140 -0
- package/dist/vector/actions/action-manager.js +356 -0
- package/dist/vector/actions/action-manager.js.map +1 -0
- package/dist/vector/adapters/base.adapter.d.ts +169 -0
- package/dist/vector/adapters/base.adapter.js +218 -0
- package/dist/vector/adapters/base.adapter.js.map +1 -0
- package/dist/vector/adapters/index.d.ts +10 -0
- package/dist/vector/adapters/index.js +19 -0
- package/dist/vector/adapters/index.js.map +1 -0
- package/dist/vector/adapters/memory.adapter.d.ts +85 -0
- package/dist/vector/adapters/memory.adapter.js +505 -0
- package/dist/vector/adapters/memory.adapter.js.map +1 -0
- package/dist/vector/adapters/pinecone.adapter.d.ts +52 -0
- package/dist/vector/adapters/pinecone.adapter.js +433 -0
- package/dist/vector/adapters/pinecone.adapter.js.map +1 -0
- package/dist/vector/adapters/qdrant.adapter.d.ts +56 -0
- package/dist/vector/adapters/qdrant.adapter.js +442 -0
- package/dist/vector/adapters/qdrant.adapter.js.map +1 -0
- package/dist/vector/adapters/weaviate.adapter.d.ts +68 -0
- package/dist/vector/adapters/weaviate.adapter.js +661 -0
- package/dist/vector/adapters/weaviate.adapter.js.map +1 -0
- package/dist/vector/index.d.ts +36 -0
- package/dist/vector/index.js +70 -0
- package/dist/vector/index.js.map +1 -0
- package/dist/vector/types/action.interface.d.ts +195 -0
- package/dist/vector/types/action.interface.js +100 -0
- package/dist/vector/types/action.interface.js.map +1 -0
- package/dist/vector/types/connection.interface.d.ts +151 -0
- package/dist/vector/types/connection.interface.js +8 -0
- package/dist/vector/types/connection.interface.js.map +1 -0
- package/dist/vector/types/embedding.interface.d.ts +144 -0
- package/dist/vector/types/embedding.interface.js +8 -0
- package/dist/vector/types/embedding.interface.js.map +1 -0
- package/dist/vector/types/enums.d.ts +104 -0
- package/dist/vector/types/enums.js +113 -0
- package/dist/vector/types/enums.js.map +1 -0
- package/dist/vector/types/index.d.ts +11 -0
- package/dist/vector/types/index.js +23 -0
- package/dist/vector/types/index.js.map +1 -0
- package/dist/vector/types/vector.interface.d.ts +315 -0
- package/dist/vector/types/vector.interface.js +8 -0
- package/dist/vector/types/vector.interface.js.map +1 -0
- package/dist/vector/utils/index.d.ts +6 -0
- package/dist/vector/utils/index.js +11 -0
- package/dist/vector/utils/index.js.map +1 -0
- package/dist/vector/utils/vector-error.d.ts +69 -0
- package/dist/vector/utils/vector-error.js +116 -0
- package/dist/vector/utils/vector-error.js.map +1 -0
- package/dist/vector/vector-database.service.d.ts +476 -0
- package/dist/vector/vector-database.service.js +892 -0
- package/dist/vector/vector-database.service.js.map +1 -0
- package/dist/vector/vector.service.d.ts +283 -0
- package/dist/vector/vector.service.js +544 -0
- package/dist/vector/vector.service.js.map +1 -0
- package/dist/warehouse/executor/index.d.ts +5 -0
- package/dist/warehouse/executor/index.js +12 -0
- package/dist/warehouse/executor/index.js.map +1 -0
- package/dist/warehouse/executor/joins/index.d.ts +5 -0
- package/dist/warehouse/executor/joins/index.js +11 -0
- package/dist/warehouse/executor/joins/index.js.map +1 -0
- package/dist/warehouse/executor/joins/join-executor.d.ts +101 -0
- package/dist/warehouse/executor/joins/join-executor.js +493 -0
- package/dist/warehouse/executor/joins/join-executor.js.map +1 -0
- package/dist/warehouse/executor/joins/semantic-join.d.ts +64 -0
- package/dist/warehouse/executor/joins/semantic-join.js +241 -0
- package/dist/warehouse/executor/joins/semantic-join.js.map +1 -0
- package/dist/warehouse/executor/single-source-executor.d.ts +155 -0
- package/dist/warehouse/executor/single-source-executor.js +573 -0
- package/dist/warehouse/executor/single-source-executor.js.map +1 -0
- package/dist/warehouse/index.d.ts +79 -0
- package/dist/warehouse/index.js +111 -0
- package/dist/warehouse/index.js.map +1 -0
- package/dist/warehouse/parser/index.d.ts +4 -0
- package/dist/warehouse/parser/index.js +10 -0
- package/dist/warehouse/parser/index.js.map +1 -0
- package/dist/warehouse/parser/query-parser.d.ts +181 -0
- package/dist/warehouse/parser/query-parser.js +415 -0
- package/dist/warehouse/parser/query-parser.js.map +1 -0
- package/dist/warehouse/registry/data-source-registry.d.ts +207 -0
- package/dist/warehouse/registry/data-source-registry.js +396 -0
- package/dist/warehouse/registry/data-source-registry.js.map +1 -0
- package/dist/warehouse/registry/index.d.ts +4 -0
- package/dist/warehouse/registry/index.js +9 -0
- package/dist/warehouse/registry/index.js.map +1 -0
- package/dist/warehouse/transactions/index.d.ts +4 -0
- package/dist/warehouse/transactions/index.js +9 -0
- package/dist/warehouse/transactions/index.js.map +1 -0
- package/dist/warehouse/transactions/saga-orchestrator.d.ts +92 -0
- package/dist/warehouse/transactions/saga-orchestrator.js +383 -0
- package/dist/warehouse/transactions/saga-orchestrator.js.map +1 -0
- package/dist/warehouse/types/index.d.ts +9 -0
- package/dist/warehouse/types/index.js +33 -0
- package/dist/warehouse/types/index.js.map +1 -0
- package/dist/warehouse/types/join.interface.d.ts +225 -0
- package/dist/warehouse/types/join.interface.js +87 -0
- package/dist/warehouse/types/join.interface.js.map +1 -0
- package/dist/warehouse/types/query.interface.d.ts +232 -0
- package/dist/warehouse/types/query.interface.js +9 -0
- package/dist/warehouse/types/query.interface.js.map +1 -0
- package/dist/warehouse/types/transaction.interface.d.ts +236 -0
- package/dist/warehouse/types/transaction.interface.js +74 -0
- package/dist/warehouse/types/transaction.interface.js.map +1 -0
- package/dist/warehouse/types/where.interface.d.ts +208 -0
- package/dist/warehouse/types/where.interface.js +89 -0
- package/dist/warehouse/types/where.interface.js.map +1 -0
- package/dist/warehouse/warehouse.service.d.ts +200 -0
- package/dist/warehouse/warehouse.service.js +470 -0
- package/dist/warehouse/warehouse.service.js.map +1 -0
- package/dist/workflows/index.d.ts +30 -0
- package/dist/workflows/index.js +64 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/types/index.d.ts +6 -0
- package/dist/workflows/types/index.js +23 -0
- package/dist/workflows/types/index.js.map +1 -0
- package/dist/workflows/types/workflows.types.d.ts +1037 -0
- package/dist/workflows/types/workflows.types.js +13 -0
- package/dist/workflows/types/workflows.types.js.map +1 -0
- package/dist/workflows/workflow-builder.d.ts +70 -0
- package/dist/workflows/workflow-builder.js +338 -0
- package/dist/workflows/workflow-builder.js.map +1 -0
- package/dist/workflows/workflow-executor.d.ts +208 -0
- package/dist/workflows/workflow-executor.js +1194 -0
- package/dist/workflows/workflow-executor.js.map +1 -0
- package/dist/workflows/workflows.service.d.ts +412 -0
- package/dist/workflows/workflows.service.js +1746 -0
- package/dist/workflows/workflows.service.js.map +1 -0
- package/package.json +75 -13
- package/dist/actions/actions.repo.js +0 -13
- package/dist/actions/actions.repo.js.map +0 -1
- package/dist/actions/actions.service.js +0 -24
- package/dist/actions/actions.service.js.map +0 -1
- package/dist/actions/utils/actions.util.read.d.ts +0 -0
- package/dist/actions/utils/actions.util.read.js +0 -427
- package/dist/actions/utils/actions.util.read.js.map +0 -1
- package/dist/api/services/integrationsApi.service.d.ts +0 -18
- package/dist/api/services/integrationsApi.service.js +0 -80
- package/dist/api/services/integrationsApi.service.js.map +0 -1
- package/dist/appBuilder/services/app.service.d.ts +0 -111
- package/dist/appBuilder/services/app.service.js +0 -737
- package/dist/appBuilder/services/app.service.js.map +0 -1
- package/dist/appBuilder/services/appBuilder.service.d.ts +0 -111
- package/dist/appBuilder/services/appBuilder.service.js +0 -662
- package/dist/appBuilder/services/appBuilder.service.js.map +0 -1
- package/dist/appBuilder/utils/objects.utils.d.ts +0 -3
- package/dist/appBuilder/utils/objects.utils.js +0 -9
- package/dist/appBuilder/utils/objects.utils.js.map +0 -1
- package/dist/appBuilder/utils/string.utils.d.ts +0 -2
- package/dist/appBuilder/utils/string.utils.js +0 -57
- package/dist/appBuilder/utils/string.utils.js.map +0 -1
- package/dist/appBuilder/validators/index.d.ts +0 -19
- package/dist/appBuilder/validators/index.js +0 -40
- package/dist/appBuilder/validators/index.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.app.validator.js +0 -10
- package/dist/appBuilder/validators/joi-validators/create.app.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js +0 -20
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.d.ts +0 -7
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js +0 -44
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js +0 -31
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js +0 -11
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js +0 -12
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js +0 -17
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.d.ts +0 -5
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js +0 -30
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js +0 -14
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/sample.validator.d.ts +0 -5
- package/dist/appBuilder/validators/joi-validators/sample.validator.js +0 -26
- package/dist/appBuilder/validators/joi-validators/sample.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.app.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.app.validator.js +0 -34
- package/dist/appBuilder/validators/joi-validators/update.app.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js +0 -23
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js +0 -21
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js +0 -19
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js +0 -12
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js +0 -17
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js +0 -16
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js +0 -14
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js +0 -27
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js.map +0 -1
- package/dist/apps/validators/joi-validators/create.appEvent.validator.d.ts +0 -5
- package/dist/apps/validators/joi-validators/create.appEvent.validator.js +0 -30
- package/dist/apps/validators/joi-validators/create.appEvent.validator.js.map +0 -1
- package/dist/apps/validators/joi-validators/update.appEvent.validator.d.ts +0 -4
- package/dist/apps/validators/joi-validators/update.appEvent.validator.js +0 -16
- package/dist/apps/validators/joi-validators/update.appEvent.validator.js.map +0 -1
- package/dist/clients/integrations.client.d.ts +0 -2
- package/dist/clients/integrations.client.js +0 -26
- package/dist/clients/integrations.client.js.map +0 -1
- package/dist/integrationsBuilder/services/integration.service.d.ts +0 -138
- package/dist/integrationsBuilder/services/integration.service.js +0 -1148
- package/dist/integrationsBuilder/services/integration.service.js.map +0 -1
- package/dist/integrationsBuilder/services/integrationBuilder.service.d.ts +0 -130
- package/dist/integrationsBuilder/services/integrationBuilder.service.js +0 -1017
- package/dist/integrationsBuilder/services/integrationBuilder.service.js.map +0 -1
- package/dist/integrationsBuilder/utils/objects.utils.d.ts +0 -2
- package/dist/integrationsBuilder/utils/objects.utils.js +0 -48
- package/dist/integrationsBuilder/utils/objects.utils.js.map +0 -1
- package/dist/integrationsBuilder/utils/string.utils.d.ts +0 -1
- package/dist/integrationsBuilder/utils/string.utils.js +0 -9
- package/dist/integrationsBuilder/utils/string.utils.js.map +0 -1
- package/dist/integrationsBuilder/validators/index.d.ts +0 -18
- package/dist/integrationsBuilder/validators/index.js +0 -38
- package/dist/integrationsBuilder/validators/index.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.d.ts +0 -4
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js +0 -26
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js +0 -60
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js +0 -9
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js.map +0 -1
- package/dist/postman.d.ts +0 -1
- package/dist/postman.js +0 -21674
- package/dist/postman.js.map +0 -1
- package/dist/processor/services/fallback.service.d.ts +0 -5
- package/dist/processor/services/fallback.service.js +0 -43
- package/dist/processor/services/fallback.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/aws-sqs.service.js +0 -77
- package/dist/processor/services/messagebrokers/aws-sqs.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/google-pubsub.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/index.d.ts +0 -3
- package/dist/processor/services/messagebrokers/index.js +0 -26
- package/dist/processor/services/messagebrokers/index.js.map +0 -1
- package/dist/processor/services/messagebrokers/kafka.service.d.ts +0 -14
- package/dist/processor/services/messagebrokers/kafka.service.js +0 -45
- package/dist/processor/services/messagebrokers/kafka.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/messagebrokers.type.d.ts +0 -6
- package/dist/processor/services/messagebrokers/messagebrokers.type.js.map +0 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.js +0 -67
- package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +0 -1
- package/dist/processor/services/messagebrokers/redis.service.js.map +0 -1
- package/dist/processor/services/quota.service.d.ts +0 -15
- package/dist/processor/services/quota.service.js +0 -63
- package/dist/processor/services/quota.service.js.map +0 -1
- package/dist/processor/utils/mongo.util.d.ts +0 -0
- package/dist/processor/utils/mongo.util.js +0 -152
- package/dist/processor/utils/mongo.util.js.map +0 -1
- package/dist/processor/utils/postgres.util.d.ts +0 -14
- package/dist/processor/utils/postgres.util.js +0 -83
- package/dist/processor/utils/postgres.util.js.map +0 -1
- package/dist/products/validators/joi-validators/create.product.validator.d.ts +0 -3
- package/dist/products/validators/joi-validators/create.product.validator.js +0 -10
- package/dist/products/validators/joi-validators/create.product.validator.js.map +0 -1
- package/dist/test/test.appBuilder.d.ts +0 -1
- package/dist/test/test.appBuilder.js +0 -16
- package/dist/test/test.appBuilder.js.map +0 -1
- package/dist/test/test.health.d.ts +0 -1
- package/dist/test/test.health.js +0 -49
- package/dist/test/test.health.js.map +0 -1
- package/dist/test/test.import.d.ts +0 -1
- package/dist/test/test.import.js +0 -1460
- package/dist/test/test.import.js.map +0 -1
- package/dist/test/test.import.openapi.d.ts +0 -1
- package/dist/test/test.import.openapi.js +0 -76
- package/dist/test/test.import.openapi.js.map +0 -1
- package/dist/test/test.imports.d.ts +0 -1
- package/dist/test/test.imports.js +0 -62
- package/dist/test/test.imports.js.map +0 -1
- package/dist/test/test.logs.d.ts +0 -1
- package/dist/test/test.logs.js +0 -18
- package/dist/test/test.logs.js.map +0 -1
- package/dist/test/test.processor.d.ts +0 -1
- package/dist/test/test.processor.js +0 -123
- package/dist/test/test.processor.js.map +0 -1
- package/dist/test/test.productBuilder.d.ts +0 -1
- package/dist/test/test.productBuilder.js +0 -661
- package/dist/test/test.productBuilder.js.map +0 -1
- package/dist/test.appBuilder.d.ts +0 -1
- package/dist/test.appBuilder.js +0 -14
- package/dist/test.appBuilder.js.map +0 -1
- package/dist/test.import.d.ts +0 -0
- package/dist/test.import.js +0 -24
- package/dist/test.import.js.map +0 -1
- package/dist/test.imports.d.ts +0 -1
- package/dist/test.imports.js +0 -28
- package/dist/test.imports.js.map +0 -1
- package/dist/test.integrationBuilder.d.ts +0 -1
- package/dist/test.integrationBuilder.js +0 -276
- package/dist/test.integrationBuilder.js.map +0 -1
- package/dist/test.processor.d.ts +0 -1
- package/dist/test.processor.js +0 -23
- package/dist/test.processor.js.map +0 -1
- package/dist/test.utils.d.ts +0 -1
- package/dist/test.utils.js +0 -25
- package/dist/test.utils.js.map +0 -1
- package/dist/types/integrationsBuilder.types.d.ts +0 -276
- package/dist/types/integrationsBuilder.types.js +0 -51
- package/dist/types/integrationsBuilder.types.js.map +0 -1
- /package/dist/{actions/actions.repo.d.ts → pricing/pricing.repo.d.ts} +0 -0
- /package/dist/{appBuilder/validators/joi-validators/create.app.validator.d.ts → products/validators/joi-validators/create.productGraph.validator.d.ts} +0 -0
- /package/dist/{appBuilder/validators/joi-validators/update.validation.entityData.validator.d.ts → products/validators/joi-validators/update.productGraph.validator.d.ts} +0 -0
- /package/dist/{actions/actions.service.d.ts → types/request-tracker.interface.d.ts} +0 -0
|
@@ -54,41 +54,46 @@ const inputs_service_1 = __importDefault(require("../../inputs/inputs.service"))
|
|
|
54
54
|
const processor_utils_1 = require("../utils/processor.utils");
|
|
55
55
|
const axios_1 = __importDefault(require("axios"));
|
|
56
56
|
const processorApi_service_1 = require("../../api/services/processorApi.service");
|
|
57
|
+
const cache_service_1 = require("../../cache/cache.service");
|
|
57
58
|
const expo_client_1 = __importDefault(require("../../clients/expo.client"));
|
|
58
59
|
const handlebars_1 = require("handlebars");
|
|
59
|
-
const functions_utils_1 = require("../../products/utils/functions.utils");
|
|
60
60
|
const string_utils_1 = require("../../products/utils/string.utils");
|
|
61
61
|
const create_productFeature_validator_1 = require("../../products/validators/joi-validators/create.productFeature.validator");
|
|
62
62
|
const validators_1 = require("../../products/validators");
|
|
63
63
|
const uuid_1 = require("uuid");
|
|
64
64
|
const urls_1 = require("../../api/urls");
|
|
65
|
-
//import { createBrokerService } from './messagebrokers';
|
|
66
65
|
const date_fns_1 = require("date-fns");
|
|
67
|
-
const mongo_repo_1 = require("../repos/mongo.repo");
|
|
68
|
-
const postgres_repo_1 = require("../repos/postgres.repo");
|
|
69
66
|
const storage_util_1 = require("../utils/storage.util");
|
|
70
67
|
const sms_repo_1 = require("../repos/sms.repo");
|
|
71
|
-
const
|
|
72
|
-
|
|
68
|
+
const pricing_service_1 = __importDefault(require("../../pricing/pricing.service"));
|
|
69
|
+
const request_utils_1 = require("../utils/request.utils");
|
|
70
|
+
const request_service_1 = __importDefault(require("./request.service"));
|
|
71
|
+
const app_service_1 = __importDefault(require("../../apps/services/app.service"));
|
|
72
|
+
const utils_1 = require("../../apps/utils");
|
|
73
|
+
const credential_manager_1 = require("../../apps/utils/credential-manager");
|
|
74
|
+
const oauth_manager_1 = require("../../apps/utils/oauth-manager");
|
|
75
|
+
const secrets_1 = require("../../secrets");
|
|
73
76
|
async function loadBrokerService() {
|
|
74
77
|
if (typeof window === 'undefined') {
|
|
75
|
-
const {
|
|
76
|
-
return
|
|
78
|
+
const { loadBrokerService: loadBroker } = await Promise.resolve().then(() => __importStar(require('../../brokers')));
|
|
79
|
+
return loadBroker();
|
|
77
80
|
}
|
|
78
81
|
return null;
|
|
79
82
|
}
|
|
80
83
|
async function loadJWT() {
|
|
81
84
|
if (typeof window === 'undefined') {
|
|
82
|
-
const JWT = await Promise.resolve().then(() => __importStar(require(
|
|
85
|
+
const JWT = await Promise.resolve().then(() => __importStar(require('jsonwebtoken')));
|
|
83
86
|
return JWT;
|
|
84
87
|
}
|
|
85
88
|
return null;
|
|
86
89
|
}
|
|
87
90
|
class ProcessorService {
|
|
88
|
-
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client, queues }) {
|
|
91
|
+
constructor({ workspace_id, public_key, user_id, token, env_type, private_key, access_key, redis_client, queues }) {
|
|
89
92
|
this.workspace_id = workspace_id;
|
|
90
93
|
this.public_key = public_key;
|
|
91
94
|
this.user_id = user_id;
|
|
95
|
+
this._privateKey = private_key;
|
|
96
|
+
this.accessKey = access_key;
|
|
92
97
|
this.token = token;
|
|
93
98
|
this.published = false;
|
|
94
99
|
this.productBuilderService = new products_service_1.default({
|
|
@@ -97,7 +102,23 @@ class ProcessorService {
|
|
|
97
102
|
user_id,
|
|
98
103
|
token,
|
|
99
104
|
env_type,
|
|
100
|
-
redis_client
|
|
105
|
+
redis_client,
|
|
106
|
+
});
|
|
107
|
+
this.appBuilderService = new app_service_1.default({
|
|
108
|
+
workspace_id,
|
|
109
|
+
public_key,
|
|
110
|
+
user_id,
|
|
111
|
+
token,
|
|
112
|
+
env_type,
|
|
113
|
+
redis_client,
|
|
114
|
+
});
|
|
115
|
+
this.pricingService = new pricing_service_1.default({
|
|
116
|
+
workspace_id,
|
|
117
|
+
public_key,
|
|
118
|
+
user_id,
|
|
119
|
+
token,
|
|
120
|
+
env_type,
|
|
121
|
+
redis_client,
|
|
101
122
|
});
|
|
102
123
|
this.inputService = new inputs_service_1.default();
|
|
103
124
|
this.requestTime = 0;
|
|
@@ -109,11 +130,26 @@ class ProcessorService {
|
|
|
109
130
|
skipped: [],
|
|
110
131
|
};
|
|
111
132
|
this.apps = [];
|
|
133
|
+
this.requestTrackerService = request_service_1.default.getInstance(redis_client);
|
|
112
134
|
this.processorApiService = new processorApi_service_1.ProcessorApiService(env_type);
|
|
113
135
|
this.environment = env_type;
|
|
114
|
-
|
|
136
|
+
// Initialize CacheService
|
|
137
|
+
this.cacheService = new cache_service_1.CacheService({
|
|
138
|
+
workspace_id,
|
|
139
|
+
public_key,
|
|
140
|
+
user_id,
|
|
141
|
+
token,
|
|
142
|
+
env_type,
|
|
143
|
+
});
|
|
144
|
+
// Connect CacheService to Redis if available
|
|
145
|
+
if (redis_client) {
|
|
115
146
|
this.redisClient = redis_client;
|
|
116
|
-
//
|
|
147
|
+
// Note: CacheService.connectRedis() requires a URL string, but we have a client instance
|
|
148
|
+
// For now, CacheService will work with remote cache only
|
|
149
|
+
// TODO: Consider adding a method to CacheService to accept an existing Redis client
|
|
150
|
+
}
|
|
151
|
+
// Start healthcheck workers only if product tag is available
|
|
152
|
+
if (redis_client && this.productTag) {
|
|
117
153
|
this.startHealthcheckWorkers();
|
|
118
154
|
}
|
|
119
155
|
if (queues) {
|
|
@@ -128,9 +164,8 @@ class ProcessorService {
|
|
|
128
164
|
// Fetch all products (or the current product if context is single-tenant)
|
|
129
165
|
// For demo, we use the current product only
|
|
130
166
|
await this.productBuilderService.initializeProductByTag(this.productTag);
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const privateKey = product.private_key;
|
|
167
|
+
const healthchecks = await this.productBuilderService.fetchProductHealthchecks();
|
|
168
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
134
169
|
for (const healthcheck of healthchecks) {
|
|
135
170
|
for (const env of healthcheck.envs) {
|
|
136
171
|
// Each env gets its own worker (setInterval)
|
|
@@ -145,10 +180,10 @@ class ProcessorService {
|
|
|
145
180
|
// Prepare action input
|
|
146
181
|
const actionInput = {
|
|
147
182
|
env: env.slug,
|
|
148
|
-
product:
|
|
183
|
+
product: this.productTag,
|
|
149
184
|
app: healthcheck.app,
|
|
150
185
|
input: decryptedInput,
|
|
151
|
-
|
|
186
|
+
action: healthcheck.event,
|
|
152
187
|
retries: healthcheck.retries || 0,
|
|
153
188
|
};
|
|
154
189
|
// Process the action
|
|
@@ -168,9 +203,8 @@ class ProcessorService {
|
|
|
168
203
|
*/
|
|
169
204
|
async processAllHealthchecksForProduct(productTag) {
|
|
170
205
|
await this.productBuilderService.initializeProductByTag(productTag);
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const privateKey = product.private_key;
|
|
206
|
+
const healthchecks = await this.productBuilderService.fetchProductHealthchecks();
|
|
207
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
174
208
|
for (const healthcheck of healthchecks) {
|
|
175
209
|
for (const env of healthcheck.envs) {
|
|
176
210
|
try {
|
|
@@ -180,10 +214,10 @@ class ProcessorService {
|
|
|
180
214
|
}
|
|
181
215
|
const actionInput = {
|
|
182
216
|
env: env.slug,
|
|
183
|
-
product:
|
|
217
|
+
product: productTag,
|
|
184
218
|
app: healthcheck.app,
|
|
185
219
|
input: decryptedInput,
|
|
186
|
-
|
|
220
|
+
action: healthcheck.event,
|
|
187
221
|
retries: healthcheck.retries || 0,
|
|
188
222
|
};
|
|
189
223
|
const result = await this.processAction(actionInput);
|
|
@@ -198,38 +232,42 @@ class ProcessorService {
|
|
|
198
232
|
async generateSession(payload) {
|
|
199
233
|
try {
|
|
200
234
|
const { product: product_tag, env: slug, tag, data } = payload;
|
|
201
|
-
const input = await this.inputService.parseJson({
|
|
235
|
+
const input = (await this.inputService.parseJson({
|
|
202
236
|
data,
|
|
203
237
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
204
|
-
});
|
|
238
|
+
}));
|
|
205
239
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
206
|
-
|
|
207
|
-
const session = this.productBuilderService.fetchSession(tag);
|
|
240
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
241
|
+
const session = await this.productBuilderService.fetchSession(tag);
|
|
208
242
|
if (!session) {
|
|
209
243
|
throw new Error(`Session with tag ${tag} does not exist`);
|
|
210
244
|
}
|
|
211
|
-
const env = this.productBuilderService.fetchEnv(slug);
|
|
245
|
+
const env = await this.productBuilderService.fetchEnv(slug);
|
|
212
246
|
if (!env) {
|
|
213
247
|
throw new Error(`Env with slug ${slug} does not exist`);
|
|
214
248
|
}
|
|
215
249
|
await this.inputService.validateInput(input, session.schema_data);
|
|
216
250
|
const stages = (0, string_utils_1.extractStages)(session.selector);
|
|
217
|
-
|
|
251
|
+
// Convert stages to string[] for functions expecting string[]
|
|
252
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
253
|
+
const user = (0, processor_utils_1.extractSelectorValue)(data, stringStages, session.selector);
|
|
218
254
|
const expiry = (0, processor_utils_1.calculateJWTExpiry)(session.expiry, session.period);
|
|
219
255
|
const end_at = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
|
|
220
256
|
const JWT = await loadJWT();
|
|
221
257
|
if (JWT) {
|
|
222
258
|
const session_id = (0, uuid_1.v4)();
|
|
223
|
-
const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data },
|
|
224
|
-
|
|
259
|
+
const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, privateKey, {
|
|
260
|
+
expiresIn: expiry,
|
|
261
|
+
});
|
|
262
|
+
const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), privateKey);
|
|
225
263
|
// WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
|
|
226
264
|
const details = {
|
|
227
265
|
identifier: user,
|
|
228
266
|
start_at: Date.now(),
|
|
229
267
|
end_at,
|
|
230
268
|
session_tag: tag,
|
|
231
|
-
data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)),
|
|
232
|
-
session_id
|
|
269
|
+
data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), privateKey),
|
|
270
|
+
session_id,
|
|
233
271
|
};
|
|
234
272
|
await this.processorApiService.createSessionInfo(Object.assign({ product_tag, env: slug, refreshToken }, details), this.getUserAccess());
|
|
235
273
|
return {
|
|
@@ -247,11 +285,12 @@ class ProcessorService {
|
|
|
247
285
|
}
|
|
248
286
|
async refreshSession(payload) {
|
|
249
287
|
await this.productBuilderService.initializeProductByTag(payload.product);
|
|
288
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
250
289
|
// validate token validity
|
|
251
290
|
const { refreshToken } = payload, payloadData = __rest(payload, ["refreshToken"]);
|
|
252
291
|
const valid = await this.processorApiService.validateRefreshToken({ refreshToken, product: payload.product, env: payload.env }, this.getUserAccess());
|
|
253
292
|
if (valid) {
|
|
254
|
-
const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken,
|
|
293
|
+
const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, privateKey));
|
|
255
294
|
return await this.generateSession(Object.assign(Object.assign({}, payloadData), { data }));
|
|
256
295
|
}
|
|
257
296
|
else {
|
|
@@ -260,12 +299,13 @@ class ProcessorService {
|
|
|
260
299
|
}
|
|
261
300
|
async decryptSession(data) {
|
|
262
301
|
await this.productBuilderService.initializeProductByTag(data.product);
|
|
302
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
263
303
|
const JWT = await loadJWT();
|
|
264
304
|
if (!JWT) {
|
|
265
305
|
throw new Error(`Running in browser, token service not loaded.`);
|
|
266
306
|
}
|
|
267
307
|
try {
|
|
268
|
-
const res = await JWT.verify(data.token,
|
|
308
|
+
const res = (await JWT.verify(data.token, privateKey));
|
|
269
309
|
if (res.session !== data.tag) {
|
|
270
310
|
throw new Error(`Invalid token for session ${data.tag}`);
|
|
271
311
|
}
|
|
@@ -276,14 +316,13 @@ class ProcessorService {
|
|
|
276
316
|
}
|
|
277
317
|
catch (e) {
|
|
278
318
|
console.log(e);
|
|
279
|
-
throw new Error(
|
|
319
|
+
throw new Error('Invalid/Expired token');
|
|
280
320
|
}
|
|
281
321
|
}
|
|
282
322
|
async registerWebhook(data) {
|
|
283
323
|
const { product: product_tag, access_tag, webhook_tag, envs } = data;
|
|
284
324
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
285
|
-
const
|
|
286
|
-
const { version, envs: appEnvs } = this.productBuilderService.fetchApp(access_tag);
|
|
325
|
+
const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
|
|
287
326
|
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
|
|
288
327
|
const { webhooks } = app.versions.find((data) => data.tag === version);
|
|
289
328
|
if (!webhooks) {
|
|
@@ -294,7 +333,7 @@ class ProcessorService {
|
|
|
294
333
|
if (!webhook) {
|
|
295
334
|
throw new Error(`Webhook tag ${webhook_tag} not found`);
|
|
296
335
|
}
|
|
297
|
-
const productEnvs = this.productBuilderService.fetchEnvs();
|
|
336
|
+
const productEnvs = await this.productBuilderService.fetchEnvs();
|
|
298
337
|
productEnvs.map((env) => {
|
|
299
338
|
const exists = envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
300
339
|
if (exists === -1) {
|
|
@@ -338,7 +377,7 @@ class ProcessorService {
|
|
|
338
377
|
if (replacedUrl && replacedUrl !== env.url && replacedUrl) {
|
|
339
378
|
throw new Error(`Ductape expects the url ${replacedUrl} in request body to match inputted url ${env.url}`);
|
|
340
379
|
}
|
|
341
|
-
const exists = this.fetchEnv(env.slug, {});
|
|
380
|
+
const exists = await this.fetchEnv(env.slug, {});
|
|
342
381
|
if (!exists) {
|
|
343
382
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
344
383
|
}
|
|
@@ -360,7 +399,7 @@ class ProcessorService {
|
|
|
360
399
|
webhook_tag,
|
|
361
400
|
version,
|
|
362
401
|
sender_workspace_id: app.workspace_id,
|
|
363
|
-
receiver_workspace_id:
|
|
402
|
+
receiver_workspace_id: this.getUserAccess().workspace_id,
|
|
364
403
|
app_tag: app.tag,
|
|
365
404
|
product_tag,
|
|
366
405
|
active,
|
|
@@ -371,8 +410,7 @@ class ProcessorService {
|
|
|
371
410
|
async generateWebhookLink(data) {
|
|
372
411
|
const { product: product_tag, access_tag, webhook_tag, env: product_env, url, method } = data;
|
|
373
412
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
374
|
-
const
|
|
375
|
-
const { version, envs: appEnvs } = this.productBuilderService.fetchApp(access_tag);
|
|
413
|
+
const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
|
|
376
414
|
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
|
|
377
415
|
const { webhooks } = app.versions.find((data) => data.tag === version);
|
|
378
416
|
if (!webhooks) {
|
|
@@ -393,7 +431,7 @@ class ProcessorService {
|
|
|
393
431
|
webhook_tag,
|
|
394
432
|
version,
|
|
395
433
|
sender_workspace_id: app.workspace_id,
|
|
396
|
-
receiver_workspace_id:
|
|
434
|
+
receiver_workspace_id: this.getUserAccess().workspace_id,
|
|
397
435
|
app_tag: app.tag,
|
|
398
436
|
product_tag,
|
|
399
437
|
active: false,
|
|
@@ -401,239 +439,6 @@ class ProcessorService {
|
|
|
401
439
|
return await this.webhookApi.generateLink(payload, this.getUserAccess());
|
|
402
440
|
//return res.link;
|
|
403
441
|
}
|
|
404
|
-
async processQuota(data) {
|
|
405
|
-
this.start = Date.now();
|
|
406
|
-
const { product: product_tag, env, input, tag: quota_tag } = data;
|
|
407
|
-
try {
|
|
408
|
-
this.productTag = product_tag;
|
|
409
|
-
const additional_logs = {
|
|
410
|
-
name: 'Process Quota',
|
|
411
|
-
type: types_1.LogEventTypes.QUOTA,
|
|
412
|
-
parent_tag: quota_tag,
|
|
413
|
-
};
|
|
414
|
-
await this.intializeProduct(additional_logs);
|
|
415
|
-
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
416
|
-
this.process_id = process_id;
|
|
417
|
-
this.baseLogs = {
|
|
418
|
-
product_tag: this.productTag,
|
|
419
|
-
product_id: this.productId,
|
|
420
|
-
workspace_id: this.workspace_id,
|
|
421
|
-
env,
|
|
422
|
-
type: types_1.LogEventTypes.QUOTA,
|
|
423
|
-
process_id,
|
|
424
|
-
data: input,
|
|
425
|
-
};
|
|
426
|
-
this.quota = this.fetchQuota(quota_tag, additional_logs);
|
|
427
|
-
if (!this.quota) {
|
|
428
|
-
throw new Error(`Quota ${quota_tag} not found`);
|
|
429
|
-
}
|
|
430
|
-
this.logService.setFeatureId(this.quota._id);
|
|
431
|
-
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
432
|
-
if (!this.processEnv.active) {
|
|
433
|
-
throw new Error(`Environment ${data.env} is not active`);
|
|
434
|
-
}
|
|
435
|
-
const { input: quotaInput, options } = this.quota;
|
|
436
|
-
// validate feature input and log failure
|
|
437
|
-
this.validateJSONFeatureInput(input, quotaInput, additional_logs);
|
|
438
|
-
// split processes
|
|
439
|
-
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
440
|
-
await this.logService.publish();
|
|
441
|
-
return await this.runQuotaOptions(options, input, additional_logs);
|
|
442
|
-
}
|
|
443
|
-
catch (e) {
|
|
444
|
-
this.end = Date.now();
|
|
445
|
-
await this.logService.publish();
|
|
446
|
-
throw e;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
async runQuotaOptions(options, input, additional_logs) {
|
|
450
|
-
try {
|
|
451
|
-
const quotaManager = new quota_service_1.default(options, this.redisClient);
|
|
452
|
-
const getNextProvider = quotaManager.getNextProvider();
|
|
453
|
-
const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
|
|
454
|
-
const result = await this.processEvent({
|
|
455
|
-
app: getNextProvider.app,
|
|
456
|
-
type: getNextProvider.type,
|
|
457
|
-
event: getNextProvider.event,
|
|
458
|
-
input: quotaInput,
|
|
459
|
-
retries: getNextProvider.retries,
|
|
460
|
-
allow_fail: false
|
|
461
|
-
});
|
|
462
|
-
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 }));
|
|
463
|
-
return result;
|
|
464
|
-
}
|
|
465
|
-
catch (e) {
|
|
466
|
-
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 }));
|
|
467
|
-
throw e;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
async mapQuotaFallbackInput(providerInput, quotaInput, app) {
|
|
471
|
-
if (Array.isArray(providerInput)) {
|
|
472
|
-
return providerInput.map(async (item) => await this.mapQuotaFallbackInput(item, quotaInput, app));
|
|
473
|
-
}
|
|
474
|
-
else if (providerInput && typeof providerInput === 'object') {
|
|
475
|
-
const result = {};
|
|
476
|
-
for (const key in providerInput) {
|
|
477
|
-
result[key] = await this.mapQuotaFallbackInput(providerInput[key], quotaInput, app);
|
|
478
|
-
}
|
|
479
|
-
return result;
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
// Base case: primitive value
|
|
483
|
-
return await this.overrideQuotaFallbackInput(providerInput, quotaInput, app);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
async overrideQuotaFallbackInput(value, quotaInput, app) {
|
|
487
|
-
if (value.startsWith('$Input{')) {
|
|
488
|
-
return quotaInput[(0, string_utils_1.extractStages)(value)[0]];
|
|
489
|
-
}
|
|
490
|
-
else if (value.startsWith('$Auth')) {
|
|
491
|
-
return await this.generateAuthValue((0, string_utils_1.extractStages)(value), app, [], {});
|
|
492
|
-
}
|
|
493
|
-
else if (value.startsWith('$')) {
|
|
494
|
-
this.input = Object.assign(Object.assign({}, this.input), { input: quotaInput });
|
|
495
|
-
return await this.generateOperatorValues(value, '', {});
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
return value;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
async runFallbackOptions(options, input, additional_logs) {
|
|
502
|
-
return await this.executeActionWithFallback(options, input);
|
|
503
|
-
}
|
|
504
|
-
async executeActionWithFallback(providers, input) {
|
|
505
|
-
let index = 0;
|
|
506
|
-
for (const provider of providers) {
|
|
507
|
-
try {
|
|
508
|
-
const payload = {
|
|
509
|
-
app: provider.app,
|
|
510
|
-
type: provider.type,
|
|
511
|
-
event: provider.event,
|
|
512
|
-
input: await this.mapQuotaFallbackInput(provider.input, input, provider.app),
|
|
513
|
-
retries: provider.retries,
|
|
514
|
-
allow_fail: false
|
|
515
|
-
};
|
|
516
|
-
const result = await this.processEvent(payload);
|
|
517
|
-
if (result.status === types_1.LogEventStatus.FAIL) {
|
|
518
|
-
throw new Error(result.errors);
|
|
519
|
-
}
|
|
520
|
-
index++;
|
|
521
|
-
}
|
|
522
|
-
catch (error) {
|
|
523
|
-
if (index > 0) {
|
|
524
|
-
throw error;
|
|
525
|
-
}
|
|
526
|
-
console.warn(`${provider.app || provider.event} failed: ${error}`);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
//throw new Error("All providers failed.");
|
|
530
|
-
}
|
|
531
|
-
async processFallback(data) {
|
|
532
|
-
this.start = Date.now();
|
|
533
|
-
const { product: product_tag, env, input, tag: fallback_tag } = data;
|
|
534
|
-
try {
|
|
535
|
-
this.productTag = product_tag;
|
|
536
|
-
const additional_logs = {
|
|
537
|
-
name: 'Process Fallback',
|
|
538
|
-
type: types_1.LogEventTypes.FALLBACK,
|
|
539
|
-
parent_tag: fallback_tag,
|
|
540
|
-
};
|
|
541
|
-
await this.intializeProduct(additional_logs);
|
|
542
|
-
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
543
|
-
this.process_id = process_id;
|
|
544
|
-
this.baseLogs = {
|
|
545
|
-
product_tag: this.productTag,
|
|
546
|
-
product_id: this.productId,
|
|
547
|
-
workspace_id: this.workspace_id,
|
|
548
|
-
env,
|
|
549
|
-
type: types_1.LogEventTypes.FALLBACK,
|
|
550
|
-
process_id,
|
|
551
|
-
data: input,
|
|
552
|
-
};
|
|
553
|
-
this.fallback = this.fetchFallback(fallback_tag, additional_logs);
|
|
554
|
-
if (!this.fallback) {
|
|
555
|
-
throw new Error(`Fallback "${fallback_tag}" not found`);
|
|
556
|
-
}
|
|
557
|
-
this.logService.setFeatureId(this.fallback._id);
|
|
558
|
-
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
559
|
-
if (!this.processEnv.active) {
|
|
560
|
-
throw new Error(`Environment ${data.env} is not active`);
|
|
561
|
-
}
|
|
562
|
-
const { input: fallbackInput, options } = this.fallback;
|
|
563
|
-
// validate feature input and log failure
|
|
564
|
-
this.validateJSONFeatureInput(input, fallbackInput, additional_logs);
|
|
565
|
-
// split processes
|
|
566
|
-
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
567
|
-
return await this.runFallbackOptions(options, input, additional_logs);
|
|
568
|
-
}
|
|
569
|
-
catch (e) {
|
|
570
|
-
this.end = Date.now();
|
|
571
|
-
await this.logService.publish();
|
|
572
|
-
throw e;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
async processFeature(data, awaitResolution = false) {
|
|
576
|
-
this.start = Date.now();
|
|
577
|
-
this.input = data;
|
|
578
|
-
const { product: product_tag, env, input, tag: feature_tag } = data;
|
|
579
|
-
let additional_logs;
|
|
580
|
-
let passedValidation;
|
|
581
|
-
try {
|
|
582
|
-
this.productTag = product_tag;
|
|
583
|
-
additional_logs = {
|
|
584
|
-
name: 'Process feature',
|
|
585
|
-
type: types_1.LogEventTypes.FEATURE,
|
|
586
|
-
};
|
|
587
|
-
await this.intializeProduct(additional_logs);
|
|
588
|
-
this.component = types_1.LogEventTypes.FEATURE;
|
|
589
|
-
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
590
|
-
this.process_id = process_id;
|
|
591
|
-
this.feature = this.fetchFeature(feature_tag, additional_logs);
|
|
592
|
-
if (!this.feature) {
|
|
593
|
-
throw new Error(`Feature "${feature_tag}" not found`);
|
|
594
|
-
}
|
|
595
|
-
this.baseLogs = {
|
|
596
|
-
product_tag: this.productTag,
|
|
597
|
-
product_id: this.productId,
|
|
598
|
-
workspace_id: this.workspace_id,
|
|
599
|
-
env,
|
|
600
|
-
type: types_1.LogEventTypes.FEATURE,
|
|
601
|
-
process_id,
|
|
602
|
-
data: input,
|
|
603
|
-
feature_tag: feature_tag,
|
|
604
|
-
feature_id: this.feature._id,
|
|
605
|
-
};
|
|
606
|
-
this.logService.setFeatureId(this.feature._id);
|
|
607
|
-
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
608
|
-
if (!this.processEnv.active) {
|
|
609
|
-
throw new Error(`Environment ${data.env} is not active`);
|
|
610
|
-
}
|
|
611
|
-
const { input: featureInput, sequence, output } = this.feature;
|
|
612
|
-
// validate feature input and log failure
|
|
613
|
-
this.validateJSONFeatureInput(input, featureInput, additional_logs);
|
|
614
|
-
// split processes
|
|
615
|
-
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
616
|
-
await this.processSequenceLevels(additional_logs);
|
|
617
|
-
return { process_id };
|
|
618
|
-
//return this.generateOutput(output as unknown as Record<string, IFeatureOutput>);
|
|
619
|
-
}
|
|
620
|
-
catch (e) {
|
|
621
|
-
this.end = Date.now();
|
|
622
|
-
if (this.logService) {
|
|
623
|
-
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 }));
|
|
624
|
-
await this.logService.publish();
|
|
625
|
-
if (passedValidation) {
|
|
626
|
-
return { process_id: this.process_id };
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
throw e;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
else {
|
|
633
|
-
throw e;
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
442
|
async intializeProduct(additional_logs) {
|
|
638
443
|
if (!this.logService) {
|
|
639
444
|
this.logService = new logs_service_1.default({
|
|
@@ -652,8 +457,8 @@ class ProcessorService {
|
|
|
652
457
|
else {
|
|
653
458
|
await this.productBuilderService.initializeProduct(this.productId);
|
|
654
459
|
}
|
|
655
|
-
|
|
656
|
-
|
|
460
|
+
this.productId = this.productBuilderService.fetchProductId();
|
|
461
|
+
const workspace_id = this.productBuilderService.fetchWorkspaceId();
|
|
657
462
|
if (workspace_id !== this.workspace_id) {
|
|
658
463
|
throw new Error('Access Denied');
|
|
659
464
|
}
|
|
@@ -664,42 +469,35 @@ class ProcessorService {
|
|
|
664
469
|
throw e;
|
|
665
470
|
}
|
|
666
471
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
}
|
|
678
|
-
fetchQuota(tag, additional_logs) {
|
|
679
|
-
try {
|
|
680
|
-
const quota = this.productBuilderService.fetchQuota(tag); // validate feature exists
|
|
681
|
-
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 }));
|
|
682
|
-
return quota;
|
|
683
|
-
}
|
|
684
|
-
catch (e) {
|
|
685
|
-
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 }));
|
|
686
|
-
throw e;
|
|
472
|
+
async initializePricing(additional_logs, access_tag) {
|
|
473
|
+
if (!this.logService) {
|
|
474
|
+
this.logService = new logs_service_1.default({
|
|
475
|
+
product_id: this.productId,
|
|
476
|
+
workspace_id: this.workspace_id,
|
|
477
|
+
public_key: this.public_key,
|
|
478
|
+
user_id: this.user_id,
|
|
479
|
+
token: this.token,
|
|
480
|
+
env_type: this.environment,
|
|
481
|
+
});
|
|
687
482
|
}
|
|
688
|
-
}
|
|
689
|
-
fetchFallback(tag, additional_logs) {
|
|
690
483
|
try {
|
|
691
|
-
|
|
692
|
-
this.
|
|
693
|
-
|
|
484
|
+
console.log(`Initializing pricing for access tag: ${access_tag}`);
|
|
485
|
+
const product_app = await this.productBuilderService.fetchApp(access_tag); // validate app exists
|
|
486
|
+
console.log(`Found product app: ${JSON.stringify(product_app)}`);
|
|
487
|
+
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(product_app.access_tag);
|
|
488
|
+
await this.pricingService.initializePricingByTag(product_app.pricing_tag, app._id);
|
|
489
|
+
const { pricing_tag } = this.pricingService.fetchPricing();
|
|
490
|
+
this.pricingTag = pricing_tag;
|
|
491
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - success', data: { pricing_tag: this.pricingTag }, status: types_1.LogEventStatus.SUCCESS }));
|
|
694
492
|
}
|
|
695
493
|
catch (e) {
|
|
696
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: '
|
|
494
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
697
495
|
throw e;
|
|
698
496
|
}
|
|
699
497
|
}
|
|
700
|
-
fetchEnv(env, additional_logs) {
|
|
498
|
+
async fetchEnv(env, additional_logs) {
|
|
701
499
|
try {
|
|
702
|
-
const product_env = this.productBuilderService.fetchEnv(env); // validate env exists
|
|
500
|
+
const product_env = await this.productBuilderService.fetchEnv(env); // validate env exists
|
|
703
501
|
if (!product_env) {
|
|
704
502
|
throw new Error(`Env ${env} not found`);
|
|
705
503
|
}
|
|
@@ -711,271 +509,6 @@ class ProcessorService {
|
|
|
711
509
|
throw e;
|
|
712
510
|
}
|
|
713
511
|
}
|
|
714
|
-
validateJSONFeatureInput(input, feature_input, additional_logs) {
|
|
715
|
-
try {
|
|
716
|
-
(0, processor_utils_1.validateFeatureJSONInput)(input, feature_input);
|
|
717
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
718
|
-
}
|
|
719
|
-
catch (e) {
|
|
720
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
721
|
-
throw e;
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
async splitSequenceIntoLevels(data, additional_logs) {
|
|
725
|
-
try {
|
|
726
|
-
const levels = {};
|
|
727
|
-
const tagMap = new Map(data.map((seq) => [seq.tag, seq]));
|
|
728
|
-
const assignedLevels = new Map();
|
|
729
|
-
let currentLevel = 1;
|
|
730
|
-
let remainingSequences = [...data];
|
|
731
|
-
while (remainingSequences.length > 0) {
|
|
732
|
-
const currentLevelSequences = [];
|
|
733
|
-
remainingSequences = remainingSequences.filter((seq) => {
|
|
734
|
-
var _a;
|
|
735
|
-
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; })) || [];
|
|
736
|
-
const isCurrentLevel = parentLevels.length === 0 || Math.max(...parentLevels) === currentLevel - 1;
|
|
737
|
-
if (isCurrentLevel) {
|
|
738
|
-
currentLevelSequences.push(seq);
|
|
739
|
-
assignedLevels.set(seq.tag, currentLevel);
|
|
740
|
-
return false; // Remove from remainingSequences
|
|
741
|
-
}
|
|
742
|
-
return true;
|
|
743
|
-
});
|
|
744
|
-
if (currentLevelSequences.length > 0) {
|
|
745
|
-
levels[currentLevel] = currentLevelSequences;
|
|
746
|
-
currentLevel++;
|
|
747
|
-
}
|
|
748
|
-
else {
|
|
749
|
-
break; // Prevent infinite loop if there's a cycle
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - success', data: { levels }, status: types_1.LogEventStatus.SUCCESS }));
|
|
753
|
-
return levels;
|
|
754
|
-
}
|
|
755
|
-
catch (e) {
|
|
756
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
757
|
-
throw e;
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
async processSequenceLevels(additional_logs) {
|
|
761
|
-
try {
|
|
762
|
-
const levelEvents = {};
|
|
763
|
-
Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
|
|
764
|
-
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
|
|
765
|
-
});
|
|
766
|
-
let previousLevelComplete = true;
|
|
767
|
-
for (const level of Object.keys(levelEvents)
|
|
768
|
-
.map(Number)
|
|
769
|
-
.sort((a, b) => a - b)) {
|
|
770
|
-
if (previousLevelComplete) {
|
|
771
|
-
previousLevelComplete = await this.processLevelEvents(levelEvents[level], additional_logs);
|
|
772
|
-
}
|
|
773
|
-
else {
|
|
774
|
-
break;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
this.doneWithProcessing = true;
|
|
778
|
-
if (previousLevelComplete && !this.published) {
|
|
779
|
-
let message;
|
|
780
|
-
let status;
|
|
781
|
-
let successful_feature_execution;
|
|
782
|
-
let failed_feature_execution;
|
|
783
|
-
if (this.processingOutput.failure.length === 0) {
|
|
784
|
-
message = 'Process feature - success';
|
|
785
|
-
status = types_1.LogEventStatus.SUCCESS;
|
|
786
|
-
successful_feature_execution = true;
|
|
787
|
-
}
|
|
788
|
-
else if (this.processingFailure) {
|
|
789
|
-
message = 'Process feature - processing';
|
|
790
|
-
status = types_1.LogEventStatus.PROCESSING;
|
|
791
|
-
successful_feature_execution = false;
|
|
792
|
-
failed_feature_execution = false;
|
|
793
|
-
}
|
|
794
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_feature_execution,
|
|
795
|
-
failed_feature_execution,
|
|
796
|
-
message, data: {}, status }));
|
|
797
|
-
await this.logService.publish();
|
|
798
|
-
this.end = Date.now();
|
|
799
|
-
await this.writeResult(status);
|
|
800
|
-
}
|
|
801
|
-
return true;
|
|
802
|
-
}
|
|
803
|
-
catch (e) {
|
|
804
|
-
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 }));
|
|
805
|
-
throw e;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
async processLevelEvents(events, additional_logs) {
|
|
809
|
-
try {
|
|
810
|
-
const promises = events.map((event) => {
|
|
811
|
-
const dependants = this.fetchActionRequestDependents(event.input, additional_logs);
|
|
812
|
-
const passed = this.checkDependentsSuccess(dependants);
|
|
813
|
-
if (passed) {
|
|
814
|
-
// TODO: comparison to see if all depending events are in success || dependants is empty
|
|
815
|
-
return this.processEvent(event);
|
|
816
|
-
}
|
|
817
|
-
else {
|
|
818
|
-
this.addToWaitingOutput(event, dependants);
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
return Promise.all(promises);
|
|
822
|
-
}
|
|
823
|
-
catch (e) {
|
|
824
|
-
throw e;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
async processFailedEvents(additional_logs) {
|
|
828
|
-
try {
|
|
829
|
-
const { failure } = this.processingOutput;
|
|
830
|
-
const promises = failure.map((failed) => {
|
|
831
|
-
if (failed.retries_left > 0 && new Date().getTime() > failed.retry_at) {
|
|
832
|
-
return this.processEvent(failed.event); // process events should also take care of this.processingOutput
|
|
833
|
-
}
|
|
834
|
-
if (failed.retries_left === 0 && !failed.allow_fail) {
|
|
835
|
-
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 }));
|
|
836
|
-
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`);
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
Promise.all(promises);
|
|
840
|
-
}
|
|
841
|
-
catch (e) {
|
|
842
|
-
throw e;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
async processWaitingEvents(additional_logs) {
|
|
846
|
-
try {
|
|
847
|
-
const { waiting } = this.processingOutput;
|
|
848
|
-
const promises = waiting.map((waiting) => {
|
|
849
|
-
const { dependants } = waiting;
|
|
850
|
-
if (this.checkDependentsSuccess(dependants)) {
|
|
851
|
-
// TODO: comparison to see if all depending events are in success || dependants is empty
|
|
852
|
-
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 }));
|
|
853
|
-
return this.processEvent(waiting.event);
|
|
854
|
-
}
|
|
855
|
-
else {
|
|
856
|
-
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 }));
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
return Promise.all(promises);
|
|
860
|
-
}
|
|
861
|
-
catch (e) {
|
|
862
|
-
throw e;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
checkDependentsSuccess(dependants) {
|
|
866
|
-
let pass = true;
|
|
867
|
-
for (let i = 0; i < dependants.length; i++) {
|
|
868
|
-
if (!this.processingOutput.success.find((item) => item.event.sequence_tag === dependants[i].sequence_tag && item.event.event === dependants[i].event_tag)) {
|
|
869
|
-
pass = false;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
return pass;
|
|
873
|
-
}
|
|
874
|
-
fetchActionRequestDependents(input, additional_logs) {
|
|
875
|
-
try {
|
|
876
|
-
const dependents = [];
|
|
877
|
-
if (input.query) {
|
|
878
|
-
dependents.push(...this.fetchDependents(input.query, additional_logs));
|
|
879
|
-
}
|
|
880
|
-
if (input.body) {
|
|
881
|
-
dependents.push(...this.fetchDependents(input.body, additional_logs));
|
|
882
|
-
}
|
|
883
|
-
if (input.headers) {
|
|
884
|
-
dependents.push(...this.fetchDependents(input.headers, additional_logs));
|
|
885
|
-
}
|
|
886
|
-
if (input.params) {
|
|
887
|
-
dependents.push(...this.fetchDependents(input.params, additional_logs));
|
|
888
|
-
}
|
|
889
|
-
if (input.data) {
|
|
890
|
-
dependents.push(...this.fetchDependents(input.data, additional_logs));
|
|
891
|
-
}
|
|
892
|
-
if (input.fileName) {
|
|
893
|
-
dependents.push(...this.valueStringDepsCheck(input.fileName));
|
|
894
|
-
}
|
|
895
|
-
if (input.buffer) {
|
|
896
|
-
dependents.push(...this.valueStringDepsCheck(input.buffer));
|
|
897
|
-
}
|
|
898
|
-
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 }));
|
|
899
|
-
return dependents;
|
|
900
|
-
}
|
|
901
|
-
catch (e) {
|
|
902
|
-
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 }));
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
fetchDependents(obj, additional_logs) {
|
|
906
|
-
try {
|
|
907
|
-
const dependants = [];
|
|
908
|
-
for (const key in obj) {
|
|
909
|
-
const value = obj[key];
|
|
910
|
-
if (typeof value === 'object') {
|
|
911
|
-
if ('function' in value && 'values' in value) {
|
|
912
|
-
const { function: func, values } = value;
|
|
913
|
-
for (let i = 0; i < values.length; i++) {
|
|
914
|
-
if (values[i].startsWith('$Sequence')) {
|
|
915
|
-
const stages = this.productBuilderService.extractStages(values[i]);
|
|
916
|
-
dependants.push({
|
|
917
|
-
sequence_tag: stages[0],
|
|
918
|
-
event_tag: stages[1],
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
else if (values[i].startsWith('$')) {
|
|
922
|
-
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(values[i]);
|
|
923
|
-
if (funcArgs.args.length) {
|
|
924
|
-
funcArgs.args.map((arg) => {
|
|
925
|
-
if (arg.startsWith('$Sequence')) {
|
|
926
|
-
const stages = this.productBuilderService.extractStages(arg);
|
|
927
|
-
dependants.push({
|
|
928
|
-
sequence_tag: stages[0],
|
|
929
|
-
event_tag: stages[1],
|
|
930
|
-
});
|
|
931
|
-
}
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
else {
|
|
938
|
-
dependants.push(...this.fetchDependents(value, additional_logs));
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
else if (typeof value === 'string') {
|
|
942
|
-
dependants.push(...this.valueStringDepsCheck(value.trim()));
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
return dependants;
|
|
946
|
-
}
|
|
947
|
-
catch (e) {
|
|
948
|
-
throw e;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
valueStringDepsCheck(value) {
|
|
952
|
-
const dependants = [];
|
|
953
|
-
if (value.startsWith('$Sequence')) {
|
|
954
|
-
const stages = this.productBuilderService.extractStages(value);
|
|
955
|
-
dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
|
|
956
|
-
}
|
|
957
|
-
else if (value.startsWith('$')) {
|
|
958
|
-
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(value);
|
|
959
|
-
if (funcArgs && funcArgs.args.length) {
|
|
960
|
-
funcArgs.args.map((arg) => {
|
|
961
|
-
if (arg.startsWith('$Sequence')) {
|
|
962
|
-
const stages = this.productBuilderService.extractStages(arg);
|
|
963
|
-
dependants.push({
|
|
964
|
-
sequence_tag: stages[0],
|
|
965
|
-
event_tag: stages[1],
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
else {
|
|
969
|
-
const args = arg.split(',');
|
|
970
|
-
args.map((arg) => {
|
|
971
|
-
dependants.push(...this.valueStringDepsCheck(arg.trim()));
|
|
972
|
-
});
|
|
973
|
-
}
|
|
974
|
-
});
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
return dependants;
|
|
978
|
-
}
|
|
979
512
|
async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
|
|
980
513
|
try {
|
|
981
514
|
const payload = {};
|
|
@@ -1035,7 +568,7 @@ class ProcessorService {
|
|
|
1035
568
|
async generatePayload(obj, event, additional_logs, sample = [], index = {}, loopIndex = null) {
|
|
1036
569
|
try {
|
|
1037
570
|
const payload = {};
|
|
1038
|
-
console.log(
|
|
571
|
+
console.log('Payload Construction', { obj, event, sample, index, loopIndex });
|
|
1039
572
|
const keys = Object.keys(obj);
|
|
1040
573
|
for (let i = 0; i < keys.length; i++) {
|
|
1041
574
|
const key = keys[i];
|
|
@@ -1081,22 +614,32 @@ class ProcessorService {
|
|
|
1081
614
|
const locatorFor$Index = (0, string_utils_1.validateAndLocateTag)(value);
|
|
1082
615
|
if (value.startsWith('$Auth{') && value.endsWith('}')) {
|
|
1083
616
|
// should only be allowed in apps
|
|
1084
|
-
|
|
617
|
+
// Convert stages to string[] for functions expecting string[]
|
|
618
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
619
|
+
return await this.generateAuthValue(stringStages, app, sample, additional_logs);
|
|
1085
620
|
}
|
|
1086
621
|
else if (value.startsWith('$Sequence{') && value.endsWith('}')) {
|
|
1087
|
-
|
|
622
|
+
// Convert stages to string[] for functions expecting string[]
|
|
623
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
624
|
+
return await this.generateSequenceValue(stringStages, locatorFor$Index, loopIndex); // pass
|
|
1088
625
|
}
|
|
1089
626
|
else if (value.startsWith('$Input{') && value.endsWith('}')) {
|
|
1090
|
-
|
|
627
|
+
// Convert stages to string[] for functions expecting string[]
|
|
628
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
629
|
+
return await this.generateInputValue(this.input.input, stringStages);
|
|
1091
630
|
}
|
|
1092
631
|
else if (value === '$Default') {
|
|
1093
632
|
return await this.generateDefaultValue(sample, Object.assign(Object.assign({}, index), { key }));
|
|
1094
633
|
}
|
|
1095
634
|
else if (value.startsWith('$Variable{') && value.endsWith('}')) {
|
|
1096
|
-
|
|
635
|
+
// Convert stages to string[] for functions expecting string[]
|
|
636
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
637
|
+
return await this.generateVariableValue(stringStages);
|
|
1097
638
|
}
|
|
1098
639
|
else if (value.startsWith('$Constant{') && value.endsWith('}')) {
|
|
1099
|
-
|
|
640
|
+
// Convert stages to string[] for functions expecting string[]
|
|
641
|
+
const stringStages = stages.map((stage) => String(stage));
|
|
642
|
+
return await this.generateConstantValue(stringStages);
|
|
1100
643
|
}
|
|
1101
644
|
else if (value.startsWith('$Size{') || value.startsWith('$Length{')) {
|
|
1102
645
|
const { matchLength, matchSize } = (0, string_utils_1.checkLengthAndSizeMatches)(value);
|
|
@@ -1494,7 +1037,7 @@ class ProcessorService {
|
|
|
1494
1037
|
}
|
|
1495
1038
|
async generateVariableValue(stages) {
|
|
1496
1039
|
try {
|
|
1497
|
-
const app = this.productBuilderService.fetchApp(stages[0]);
|
|
1040
|
+
const app = await this.productBuilderService.fetchApp(stages[0]);
|
|
1498
1041
|
const env = app.envs.find((items) => items.product_env_slug === this.processEnv.slug);
|
|
1499
1042
|
if (!env) {
|
|
1500
1043
|
throw new Error(`App ${stages[0]} variables needs to have a definition for env: ${this.processEnv.slug}`);
|
|
@@ -1540,7 +1083,7 @@ class ProcessorService {
|
|
|
1540
1083
|
}
|
|
1541
1084
|
async generateAuthValue(stages, app, sample, additional_logs) {
|
|
1542
1085
|
try {
|
|
1543
|
-
console.log(
|
|
1086
|
+
console.log('Generate Auth Data', { stages, app, sample });
|
|
1544
1087
|
let auth_data = await this.fetchAuthData(app, additional_logs); //TODO: should use stages[0]
|
|
1545
1088
|
// take the app tag in index 0..
|
|
1546
1089
|
if (!auth_data) {
|
|
@@ -1556,7 +1099,7 @@ class ProcessorService {
|
|
|
1556
1099
|
}
|
|
1557
1100
|
async fetchAuthData(app_tag, additional_logs) {
|
|
1558
1101
|
try {
|
|
1559
|
-
const app = this.productBuilderService.fetchApp(app_tag);
|
|
1102
|
+
const app = await this.productBuilderService.fetchApp(app_tag);
|
|
1560
1103
|
if (!app) {
|
|
1561
1104
|
throw new Error(`App ${app_tag} not found in $Auth value`);
|
|
1562
1105
|
}
|
|
@@ -1567,7 +1110,7 @@ class ProcessorService {
|
|
|
1567
1110
|
if (!env.auth) {
|
|
1568
1111
|
throw new Error(`App ${app_tag} in auth needs to have a definition for auth in env: ${this.processEnv.slug}`);
|
|
1569
1112
|
}
|
|
1570
|
-
console.log(
|
|
1113
|
+
console.log('Envroment', env.auth);
|
|
1571
1114
|
let values = env.auth.values;
|
|
1572
1115
|
if (!values) {
|
|
1573
1116
|
// no auth values
|
|
@@ -1575,10 +1118,10 @@ class ProcessorService {
|
|
|
1575
1118
|
}
|
|
1576
1119
|
if (!env.auth.expiry || (env.auth.expiry && Date.now() > new Date(env.auth.expiry).getTime())) {
|
|
1577
1120
|
// refresh
|
|
1578
|
-
console.log(
|
|
1121
|
+
console.log('REFRESH DATA', env, app_tag);
|
|
1579
1122
|
values = await this.getAndStoreAuth(env, app_tag);
|
|
1580
1123
|
}
|
|
1581
|
-
const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.
|
|
1124
|
+
const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchPrivateKey());
|
|
1582
1125
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch auth data - success', data: { auth: (0, processor_utils_1.anonymizeValue)(decrypted) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
1583
1126
|
return JSON.parse(decrypted);
|
|
1584
1127
|
}
|
|
@@ -1630,19 +1173,9 @@ class ProcessorService {
|
|
|
1630
1173
|
};
|
|
1631
1174
|
return this.runAction(event, additional_logs);
|
|
1632
1175
|
}
|
|
1633
|
-
if (event.type === types_1.FeatureEventTypes.
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
parent_tag,
|
|
1637
|
-
child_tag,
|
|
1638
|
-
type: types_1.LogEventTypes.DB_ACTION,
|
|
1639
|
-
name: 'Process feature database action',
|
|
1640
|
-
};
|
|
1641
|
-
return this.runDBAction(event, additional_logs);
|
|
1642
|
-
}
|
|
1643
|
-
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
1644
|
-
this.clone = (0, processor_utils_1.structuredClone)(event);
|
|
1645
|
-
(0, processor_utils_1.cleanBlob)(this.clone);
|
|
1176
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
1177
|
+
this.clone = (0, processor_utils_1.structuredClone)(event);
|
|
1178
|
+
(0, processor_utils_1.cleanBlob)(this.clone);
|
|
1646
1179
|
const additional_logs = {
|
|
1647
1180
|
parent_tag: event.event,
|
|
1648
1181
|
type: types_1.LogEventTypes.STORAGE,
|
|
@@ -1650,14 +1183,6 @@ class ProcessorService {
|
|
|
1650
1183
|
};
|
|
1651
1184
|
return this.runStorage(event, additional_logs);
|
|
1652
1185
|
}
|
|
1653
|
-
if (event.type === types_1.FeatureEventTypes.FEATURE) {
|
|
1654
|
-
const additional_logs = {
|
|
1655
|
-
parent_tag: event.event,
|
|
1656
|
-
type: types_1.LogEventTypes.FEATURE,
|
|
1657
|
-
name: 'Process sub-feature',
|
|
1658
|
-
};
|
|
1659
|
-
return this.runFeature(event, additional_logs);
|
|
1660
|
-
}
|
|
1661
1186
|
if (event.type === types_1.FeatureEventTypes.NOTIFICATION) {
|
|
1662
1187
|
const [parent_tag, child_tag] = event.event.split(':');
|
|
1663
1188
|
const additional_logs = {
|
|
@@ -1679,8 +1204,7 @@ class ProcessorService {
|
|
|
1679
1204
|
try {
|
|
1680
1205
|
return this.runBrokerPublish(event, additional_logs);
|
|
1681
1206
|
}
|
|
1682
|
-
catch (e) {
|
|
1683
|
-
}
|
|
1207
|
+
catch (e) { }
|
|
1684
1208
|
}
|
|
1685
1209
|
if (event.type === types_1.FeatureEventTypes.JOB) {
|
|
1686
1210
|
const additional_logs = {
|
|
@@ -1696,7 +1220,7 @@ class ProcessorService {
|
|
|
1696
1220
|
input: event.input,
|
|
1697
1221
|
start_at: event.start_at || 0,
|
|
1698
1222
|
cache: event.cache,
|
|
1699
|
-
session: this.input.session
|
|
1223
|
+
session: this.input.session,
|
|
1700
1224
|
};
|
|
1701
1225
|
// TODO: fix this
|
|
1702
1226
|
return this.processJob(input, additional_logs);
|
|
@@ -1706,189 +1230,574 @@ class ProcessorService {
|
|
|
1706
1230
|
throw e;
|
|
1707
1231
|
}
|
|
1708
1232
|
}
|
|
1709
|
-
async runFeature(event, additional_logs) {
|
|
1710
|
-
const freshInstance = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
1711
|
-
const result = await freshInstance.processFeature({
|
|
1712
|
-
product: this.productTag,
|
|
1713
|
-
tag: event.event,
|
|
1714
|
-
env: this.processEnv.slug,
|
|
1715
|
-
input: event.input,
|
|
1716
|
-
}, true);
|
|
1717
|
-
const output = await freshInstance.generateOutput(result.process_id);
|
|
1718
|
-
if (output.status === types_1.LogEventStatus.FAIL) {
|
|
1719
|
-
await this.addToFailureOutput(output.errors, event, { process_id: result.process_id }, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
|
|
1720
|
-
}
|
|
1721
|
-
else if (output.status === types_1.LogEventStatus.SUCCESS) {
|
|
1722
|
-
await this.addToSuccessOutput(event, output.data, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
|
|
1723
|
-
}
|
|
1724
|
-
return output;
|
|
1725
|
-
}
|
|
1726
1233
|
async runJobs(job, additional_logs = {}) {
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
|
|
1734
|
-
if (!result) {
|
|
1735
|
-
throw new Error(`Invalid process id ${process_id}`);
|
|
1234
|
+
var _a;
|
|
1235
|
+
const jobId = (_a = job.data) === null || _a === void 0 ? void 0 : _a._job_id;
|
|
1236
|
+
const jobType = job.name;
|
|
1237
|
+
// Update job status to running
|
|
1238
|
+
if (jobId && this.redisClient) {
|
|
1239
|
+
await this.updateJobStatus(jobId, 'running', { started_at: Date.now() });
|
|
1736
1240
|
}
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
}
|
|
1742
|
-
async generateOutput(process_id) {
|
|
1743
|
-
var _a, _b, _c, _d;
|
|
1744
|
-
const result = await this.fetchResult(process_id);
|
|
1745
|
-
if (result.component === types_1.LogEventTypes.FEATURE) {
|
|
1746
|
-
const additional_logs = {
|
|
1747
|
-
parent_tag: result.input.tag,
|
|
1748
|
-
type: types_1.LogEventTypes.FEATURE,
|
|
1749
|
-
name: 'Fetching Process Result',
|
|
1750
|
-
};
|
|
1751
|
-
if (result.status === types_1.LogEventStatus.PROCESSING) {
|
|
1752
|
-
return { process_id, status: result.status };
|
|
1241
|
+
try {
|
|
1242
|
+
let result;
|
|
1243
|
+
if (jobType === types_1.JobEventTypes.ACTION || jobType === types_1.FeatureEventTypes.ACTION) {
|
|
1244
|
+
result = await this.processAction(job.data);
|
|
1753
1245
|
}
|
|
1754
|
-
else if (
|
|
1755
|
-
|
|
1756
|
-
await this.intializeProduct(additional_logs);
|
|
1757
|
-
this.processingOutput = result.result;
|
|
1758
|
-
this.process_id = process_id;
|
|
1759
|
-
this.input = result.input;
|
|
1760
|
-
this.feature = await this.fetchFeature(result.input.tag, additional_logs);
|
|
1761
|
-
const { input: featureInput, sequence, output } = this.feature;
|
|
1762
|
-
const data = await this.generatePayload(output, null, additional_logs, []);
|
|
1763
|
-
return { process_id, status: result.status, data };
|
|
1246
|
+
else if (jobType === types_1.JobEventTypes.NOTIFICATION) {
|
|
1247
|
+
result = await this.processNotification(job.data);
|
|
1764
1248
|
}
|
|
1765
|
-
else if (
|
|
1766
|
-
|
|
1767
|
-
return { process_id, status: result.status, errors };
|
|
1249
|
+
else if (jobType === types_1.JobEventTypes.STORAGE) {
|
|
1250
|
+
result = await this.processStorage(job.data);
|
|
1768
1251
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1252
|
+
else if (jobType === types_1.JobEventTypes.PUBLISH) {
|
|
1253
|
+
result = await this.processMessageBrokerPublish(job.data);
|
|
1254
|
+
}
|
|
1255
|
+
else if (jobType === types_1.JobEventTypes.DATABASE_ACTION) {
|
|
1256
|
+
// Database actions use processAction with database-specific input
|
|
1257
|
+
result = await this.processDatabaseAction(job.data);
|
|
1773
1258
|
}
|
|
1774
|
-
else if (
|
|
1775
|
-
|
|
1259
|
+
else if (jobType === types_1.JobEventTypes.DATABASE_OPERATION) {
|
|
1260
|
+
// Handle database operations
|
|
1261
|
+
result = await this.processDatabaseOperation(job.data);
|
|
1262
|
+
}
|
|
1263
|
+
else if (jobType === types_1.JobEventTypes.GRAPH_ACTION) {
|
|
1264
|
+
result = await this.processGraphAction(job.data);
|
|
1265
|
+
}
|
|
1266
|
+
else if (jobType === types_1.JobEventTypes.GRAPH_OPERATION) {
|
|
1267
|
+
result = await this.processGraphOperation(job.data);
|
|
1268
|
+
}
|
|
1269
|
+
else if (jobType === types_1.JobEventTypes.WORKFLOW) {
|
|
1270
|
+
result = await this.processWorkflow(job.data);
|
|
1776
1271
|
}
|
|
1777
1272
|
else {
|
|
1778
|
-
|
|
1273
|
+
throw new Error(`Unknown job type: ${jobType}`);
|
|
1779
1274
|
}
|
|
1275
|
+
// Update job status to completed
|
|
1276
|
+
if (jobId && this.redisClient) {
|
|
1277
|
+
await this.updateJobStatus(jobId, 'completed', {
|
|
1278
|
+
completed_at: Date.now(),
|
|
1279
|
+
result,
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
return result;
|
|
1780
1283
|
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1284
|
+
catch (error) {
|
|
1285
|
+
// Update job status to failed or schedule retry
|
|
1286
|
+
if (jobId && this.redisClient) {
|
|
1287
|
+
const jobData = await this.getJobData(jobId);
|
|
1288
|
+
if (jobData) {
|
|
1289
|
+
const { shouldRetry, delay } = this.calculateJobRetry(jobData, error.code);
|
|
1290
|
+
if (shouldRetry) {
|
|
1291
|
+
await this.updateJobStatus(jobId, 'scheduled', {
|
|
1292
|
+
retry_count: (jobData.retry_count || 0) + 1,
|
|
1293
|
+
last_error: error.message,
|
|
1294
|
+
last_error_code: error.code,
|
|
1295
|
+
scheduled_at: Date.now() + delay,
|
|
1296
|
+
});
|
|
1297
|
+
// Re-queue the job with delay
|
|
1298
|
+
await this.queues.jobs.add(jobType, job.data, {
|
|
1299
|
+
jobId: `${jobId}_retry_${jobData.retry_count + 1}`,
|
|
1300
|
+
delay,
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
else {
|
|
1304
|
+
await this.updateJobStatus(jobId, 'failed', {
|
|
1305
|
+
completed_at: Date.now(),
|
|
1306
|
+
last_error: error.message,
|
|
1307
|
+
last_error_code: error.code,
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
// Add to execution history
|
|
1311
|
+
await this.addJobExecution(jobId, {
|
|
1312
|
+
number: (jobData.execution_count || 0) + 1,
|
|
1313
|
+
started_at: jobData.started_at || Date.now(),
|
|
1314
|
+
completed_at: Date.now(),
|
|
1315
|
+
duration_ms: Date.now() - (jobData.started_at || Date.now()),
|
|
1316
|
+
status: 'failed',
|
|
1317
|
+
error: error.message,
|
|
1318
|
+
error_code: error.code,
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1818
1321
|
}
|
|
1819
|
-
|
|
1322
|
+
throw error;
|
|
1820
1323
|
}
|
|
1821
|
-
return { process_id };
|
|
1822
1324
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1325
|
+
/**
|
|
1326
|
+
* Get job data from Redis
|
|
1327
|
+
*/
|
|
1328
|
+
async getJobData(jobId) {
|
|
1329
|
+
if (!this.redisClient)
|
|
1330
|
+
return null;
|
|
1331
|
+
const redis = this.redisClient;
|
|
1332
|
+
const jobKey = `job:${this.workspace_id}:${jobId}`;
|
|
1333
|
+
const data = await redis.get(jobKey);
|
|
1334
|
+
if (!data)
|
|
1335
|
+
return null;
|
|
1336
|
+
return JSON.parse(data);
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Update job status in Redis
|
|
1340
|
+
*/
|
|
1341
|
+
async updateJobStatus(jobId, status, updates = {}) {
|
|
1342
|
+
if (!this.redisClient)
|
|
1343
|
+
return;
|
|
1344
|
+
const redis = this.redisClient;
|
|
1345
|
+
const jobKey = `job:${this.workspace_id}:${jobId}`;
|
|
1346
|
+
const data = await redis.get(jobKey);
|
|
1347
|
+
if (!data)
|
|
1348
|
+
return;
|
|
1349
|
+
const jobData = JSON.parse(data);
|
|
1350
|
+
const oldStatus = jobData.status;
|
|
1351
|
+
const updatedJob = Object.assign(Object.assign(Object.assign({}, jobData), updates), { status, updated_at: Date.now(), execution_count: status === 'completed' || status === 'failed'
|
|
1352
|
+
? (jobData.execution_count || 0) + 1
|
|
1353
|
+
: jobData.execution_count });
|
|
1354
|
+
// Update job data
|
|
1355
|
+
await redis.setex(jobKey, 90 * 24 * 60 * 60, JSON.stringify(updatedJob));
|
|
1356
|
+
// Update status indices
|
|
1357
|
+
if (oldStatus !== status) {
|
|
1358
|
+
const oldStatusKey = `job_status:${this.workspace_id}:${oldStatus}`;
|
|
1359
|
+
const newStatusKey = `job_status:${this.workspace_id}:${status}`;
|
|
1360
|
+
await redis.srem(oldStatusKey, jobId);
|
|
1361
|
+
await redis.sadd(newStatusKey, jobId);
|
|
1828
1362
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
await
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
// split processes
|
|
1852
|
-
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1853
|
-
await this.processSequenceLevels(additional_logs);
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Add job execution record to history
|
|
1366
|
+
*/
|
|
1367
|
+
async addJobExecution(jobId, execution) {
|
|
1368
|
+
if (!this.redisClient)
|
|
1369
|
+
return;
|
|
1370
|
+
const redis = this.redisClient;
|
|
1371
|
+
const historyKey = `job_history:${this.workspace_id}:${jobId}`;
|
|
1372
|
+
await redis.lpush(historyKey, JSON.stringify(execution));
|
|
1373
|
+
await redis.ltrim(historyKey, 0, 99); // Keep last 100 executions
|
|
1374
|
+
await redis.expire(historyKey, 30 * 24 * 60 * 60); // 30 days TTL
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Calculate retry delay based on job configuration
|
|
1378
|
+
*/
|
|
1379
|
+
calculateJobRetry(jobData, errorCode) {
|
|
1380
|
+
const retryConfig = jobData.retry_config || {};
|
|
1381
|
+
const { initialDelay = 1000, maxDelay = 300000, backoffMultiplier = 2, retryableErrors, nonRetryableErrors, jitter = false, jitterPercent = 0.3, } = retryConfig;
|
|
1382
|
+
// Check if we've exceeded max retries
|
|
1383
|
+
if ((jobData.retry_count || 0) >= (jobData.retries || 0)) {
|
|
1384
|
+
return { shouldRetry: false, delay: 0 };
|
|
1854
1385
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
this.end = Date.now();
|
|
1864
|
-
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
1865
|
-
await this.logService.publish();
|
|
1386
|
+
// Check error-based retry rules
|
|
1387
|
+
if (errorCode) {
|
|
1388
|
+
if (nonRetryableErrors === null || nonRetryableErrors === void 0 ? void 0 : nonRetryableErrors.includes(errorCode)) {
|
|
1389
|
+
return { shouldRetry: false, delay: 0 };
|
|
1390
|
+
}
|
|
1391
|
+
if (retryableErrors && !retryableErrors.includes(errorCode)) {
|
|
1392
|
+
return { shouldRetry: false, delay: 0 };
|
|
1393
|
+
}
|
|
1866
1394
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1395
|
+
// Calculate exponential backoff delay
|
|
1396
|
+
let delay = initialDelay * Math.pow(backoffMultiplier, jobData.retry_count || 0);
|
|
1397
|
+
delay = Math.min(delay, maxDelay);
|
|
1398
|
+
// Add jitter if enabled
|
|
1399
|
+
if (jitter) {
|
|
1400
|
+
const jitterAmount = delay * jitterPercent * Math.random();
|
|
1401
|
+
delay = delay + jitterAmount;
|
|
1873
1402
|
}
|
|
1874
|
-
return
|
|
1403
|
+
return { shouldRetry: true, delay: Math.round(delay) };
|
|
1875
1404
|
}
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1405
|
+
/**
|
|
1406
|
+
* Process database action job (predefined database actions)
|
|
1407
|
+
* Integrates with the database action manager to execute predefined operations
|
|
1408
|
+
*/
|
|
1409
|
+
async processDatabaseAction(data) {
|
|
1410
|
+
var _a;
|
|
1411
|
+
const { env, product, database, event, input } = data;
|
|
1412
|
+
// Initialize product builder if not already done
|
|
1413
|
+
if (product) {
|
|
1414
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1415
|
+
}
|
|
1416
|
+
// Fetch the database action configuration
|
|
1417
|
+
const databaseAction = await this.productBuilderService.fetchDatabaseAction(`${database}:${event}`);
|
|
1418
|
+
if (!databaseAction) {
|
|
1419
|
+
throw new Error(`Database action '${event}' not found on database '${database}'`);
|
|
1420
|
+
}
|
|
1421
|
+
// Get the database environment configuration
|
|
1422
|
+
const databaseConfig = await this.productBuilderService.fetchDatabase(database);
|
|
1423
|
+
if (!databaseConfig) {
|
|
1424
|
+
throw new Error(`Database '${database}' not found`);
|
|
1425
|
+
}
|
|
1426
|
+
const databaseEnv = (_a = databaseConfig.envs) === null || _a === void 0 ? void 0 : _a.find((e) => e.slug === env);
|
|
1427
|
+
if (!databaseEnv) {
|
|
1428
|
+
throw new Error(`Environment '${env}' not found for database '${database}'`);
|
|
1429
|
+
}
|
|
1430
|
+
// Execute the database action using the database service
|
|
1431
|
+
const { DatabaseService } = await Promise.resolve().then(() => __importStar(require('../../database/databases.service')));
|
|
1432
|
+
const dbService = new DatabaseService({
|
|
1433
|
+
workspace_id: this.workspace_id,
|
|
1434
|
+
public_key: this.public_key,
|
|
1435
|
+
user_id: this.user_id,
|
|
1436
|
+
token: this.token,
|
|
1437
|
+
env_type: this.environment,
|
|
1438
|
+
private_key: this._privateKey,
|
|
1439
|
+
access_key: this.accessKey,
|
|
1440
|
+
});
|
|
1441
|
+
const result = await dbService.execute({
|
|
1442
|
+
product,
|
|
1443
|
+
env,
|
|
1444
|
+
database,
|
|
1445
|
+
action: event,
|
|
1446
|
+
input: input || {},
|
|
1447
|
+
});
|
|
1448
|
+
return { success: true, data: result };
|
|
1449
|
+
}
|
|
1450
|
+
/**
|
|
1451
|
+
* Process database operation job (direct CRUD operations)
|
|
1452
|
+
* Handles operations like insert, find, update, delete, aggregate
|
|
1453
|
+
*/
|
|
1454
|
+
async processDatabaseOperation(data) {
|
|
1455
|
+
var _a;
|
|
1456
|
+
const { env, product, database, operation, input } = data;
|
|
1457
|
+
// Initialize product builder if not already done
|
|
1458
|
+
if (product) {
|
|
1459
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1460
|
+
}
|
|
1461
|
+
// Get the database configuration
|
|
1462
|
+
const databaseConfig = await this.productBuilderService.fetchDatabase(database);
|
|
1463
|
+
if (!databaseConfig) {
|
|
1464
|
+
throw new Error(`Database '${database}' not found`);
|
|
1465
|
+
}
|
|
1466
|
+
const databaseEnv = (_a = databaseConfig.envs) === null || _a === void 0 ? void 0 : _a.find((e) => e.slug === env);
|
|
1467
|
+
if (!databaseEnv) {
|
|
1468
|
+
throw new Error(`Environment '${env}' not found for database '${database}'`);
|
|
1469
|
+
}
|
|
1470
|
+
// Execute the database operation using the database service
|
|
1471
|
+
const { DatabaseService } = await Promise.resolve().then(() => __importStar(require('../../database/databases.service')));
|
|
1472
|
+
const dbService = new DatabaseService({
|
|
1473
|
+
workspace_id: this.workspace_id,
|
|
1474
|
+
public_key: this.public_key,
|
|
1475
|
+
user_id: this.user_id,
|
|
1476
|
+
token: this.token,
|
|
1477
|
+
env_type: this.environment,
|
|
1478
|
+
private_key: this._privateKey,
|
|
1479
|
+
access_key: this.accessKey,
|
|
1480
|
+
});
|
|
1481
|
+
// Connect to the database
|
|
1482
|
+
await dbService.connect({
|
|
1483
|
+
product,
|
|
1484
|
+
env,
|
|
1485
|
+
database,
|
|
1486
|
+
});
|
|
1487
|
+
let result;
|
|
1488
|
+
// Execute the appropriate operation based on the operation type
|
|
1489
|
+
switch (operation) {
|
|
1490
|
+
case 'insert':
|
|
1491
|
+
result = await dbService.insert({
|
|
1492
|
+
product,
|
|
1493
|
+
env,
|
|
1494
|
+
database,
|
|
1495
|
+
table: input.table,
|
|
1496
|
+
data: input.data,
|
|
1497
|
+
returning: input.returning,
|
|
1498
|
+
});
|
|
1499
|
+
break;
|
|
1500
|
+
case 'find':
|
|
1501
|
+
case 'query':
|
|
1502
|
+
result = await dbService.query({
|
|
1503
|
+
product,
|
|
1504
|
+
env,
|
|
1505
|
+
database,
|
|
1506
|
+
table: input.table,
|
|
1507
|
+
where: input.where,
|
|
1508
|
+
select: input.select,
|
|
1509
|
+
include: input.include,
|
|
1510
|
+
orderBy: input.orderBy,
|
|
1511
|
+
limit: input.limit,
|
|
1512
|
+
offset: input.offset,
|
|
1513
|
+
});
|
|
1514
|
+
break;
|
|
1515
|
+
case 'update':
|
|
1516
|
+
result = await dbService.update({
|
|
1517
|
+
product,
|
|
1518
|
+
env,
|
|
1519
|
+
database,
|
|
1520
|
+
table: input.table,
|
|
1521
|
+
data: input.data,
|
|
1522
|
+
where: input.where,
|
|
1523
|
+
returning: input.returning,
|
|
1524
|
+
});
|
|
1525
|
+
break;
|
|
1526
|
+
case 'delete':
|
|
1527
|
+
result = await dbService.delete({
|
|
1528
|
+
product,
|
|
1529
|
+
env,
|
|
1530
|
+
database,
|
|
1531
|
+
table: input.table,
|
|
1532
|
+
where: input.where,
|
|
1533
|
+
});
|
|
1534
|
+
break;
|
|
1535
|
+
case 'upsert':
|
|
1536
|
+
result = await dbService.upsert({
|
|
1537
|
+
product,
|
|
1538
|
+
env,
|
|
1539
|
+
database,
|
|
1540
|
+
table: input.table,
|
|
1541
|
+
data: input.data,
|
|
1542
|
+
conflictKeys: input.conflictKeys || input.conflictFields,
|
|
1543
|
+
updateColumns: input.updateColumns,
|
|
1544
|
+
returning: input.returning,
|
|
1545
|
+
});
|
|
1546
|
+
break;
|
|
1547
|
+
case 'aggregate':
|
|
1548
|
+
result = await dbService.aggregate({
|
|
1549
|
+
product,
|
|
1550
|
+
env,
|
|
1551
|
+
database,
|
|
1552
|
+
table: input.table,
|
|
1553
|
+
operations: input.operations,
|
|
1554
|
+
where: input.where,
|
|
1555
|
+
});
|
|
1556
|
+
break;
|
|
1557
|
+
case 'groupBy':
|
|
1558
|
+
result = await dbService.groupBy({
|
|
1559
|
+
product,
|
|
1560
|
+
env,
|
|
1561
|
+
database,
|
|
1562
|
+
table: input.table,
|
|
1563
|
+
groupBy: input.groupBy || input.by,
|
|
1564
|
+
operations: input.operations,
|
|
1565
|
+
where: input.where,
|
|
1566
|
+
having: input.having,
|
|
1567
|
+
orderBy: input.orderBy,
|
|
1568
|
+
limit: input.limit,
|
|
1569
|
+
offset: input.offset,
|
|
1570
|
+
});
|
|
1571
|
+
break;
|
|
1572
|
+
case 'count':
|
|
1573
|
+
result = await dbService.count({
|
|
1574
|
+
product,
|
|
1575
|
+
env,
|
|
1576
|
+
database,
|
|
1577
|
+
table: input.table,
|
|
1578
|
+
where: input.where,
|
|
1579
|
+
});
|
|
1580
|
+
break;
|
|
1581
|
+
default:
|
|
1582
|
+
throw new Error(`Unknown database operation: ${operation}`);
|
|
1882
1583
|
}
|
|
1883
|
-
return
|
|
1584
|
+
return { success: true, data: result };
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Process graph action job (predefined graph actions)
|
|
1588
|
+
* Integrates with the graph service to execute predefined graph operations
|
|
1589
|
+
*/
|
|
1590
|
+
async processGraphAction(data) {
|
|
1591
|
+
const { env, product, graph, event, input } = data;
|
|
1592
|
+
// Initialize product builder if not already done
|
|
1593
|
+
if (product) {
|
|
1594
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1595
|
+
}
|
|
1596
|
+
// Execute the graph action using the graph service
|
|
1597
|
+
const { GraphService } = await Promise.resolve().then(() => __importStar(require('../../graph/graphs.service')));
|
|
1598
|
+
const graphService = new GraphService({
|
|
1599
|
+
workspace_id: this.workspace_id,
|
|
1600
|
+
public_key: this.public_key,
|
|
1601
|
+
user_id: this.user_id,
|
|
1602
|
+
token: this.token,
|
|
1603
|
+
env_type: this.environment,
|
|
1604
|
+
private_key: this._privateKey,
|
|
1605
|
+
access_key: this.accessKey,
|
|
1606
|
+
});
|
|
1607
|
+
// Connect to the graph database
|
|
1608
|
+
await graphService.connect({
|
|
1609
|
+
product,
|
|
1610
|
+
env,
|
|
1611
|
+
graph,
|
|
1612
|
+
});
|
|
1613
|
+
// Execute the graph action
|
|
1614
|
+
const result = await graphService.execute({
|
|
1615
|
+
product,
|
|
1616
|
+
env,
|
|
1617
|
+
graph,
|
|
1618
|
+
action: event,
|
|
1619
|
+
input: input || {},
|
|
1620
|
+
});
|
|
1621
|
+
return { success: result.success, data: result.data, error: result.error };
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Process graph operation job (direct graph operations)
|
|
1625
|
+
* Handles operations like createNode, findNodes, createRelationship, traverse, etc.
|
|
1626
|
+
*/
|
|
1627
|
+
async processGraphOperation(data) {
|
|
1628
|
+
const { env, product, graph, operation, input } = data;
|
|
1629
|
+
// Initialize product builder if not already done
|
|
1630
|
+
if (product) {
|
|
1631
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1632
|
+
}
|
|
1633
|
+
// Execute the graph operation using the graph service
|
|
1634
|
+
const { GraphService } = await Promise.resolve().then(() => __importStar(require('../../graph/graphs.service')));
|
|
1635
|
+
const graphService = new GraphService({
|
|
1636
|
+
workspace_id: this.workspace_id,
|
|
1637
|
+
public_key: this.public_key,
|
|
1638
|
+
user_id: this.user_id,
|
|
1639
|
+
token: this.token,
|
|
1640
|
+
env_type: this.environment,
|
|
1641
|
+
private_key: this._privateKey,
|
|
1642
|
+
access_key: this.accessKey,
|
|
1643
|
+
});
|
|
1644
|
+
// Connect to the graph database
|
|
1645
|
+
await graphService.connect({
|
|
1646
|
+
product,
|
|
1647
|
+
env,
|
|
1648
|
+
graph,
|
|
1649
|
+
});
|
|
1650
|
+
let result;
|
|
1651
|
+
// Execute the appropriate operation based on the operation type
|
|
1652
|
+
switch (operation) {
|
|
1653
|
+
case 'createNode':
|
|
1654
|
+
result = await graphService.createNode({
|
|
1655
|
+
labels: input.labels,
|
|
1656
|
+
properties: input.properties,
|
|
1657
|
+
});
|
|
1658
|
+
break;
|
|
1659
|
+
case 'findNodes':
|
|
1660
|
+
result = await graphService.findNodes({
|
|
1661
|
+
labels: input.labels,
|
|
1662
|
+
where: input.where,
|
|
1663
|
+
limit: input.limit,
|
|
1664
|
+
offset: input.offset,
|
|
1665
|
+
orderBy: input.orderBy,
|
|
1666
|
+
});
|
|
1667
|
+
break;
|
|
1668
|
+
case 'findNodeById':
|
|
1669
|
+
result = await graphService.findNodeById(input.id);
|
|
1670
|
+
break;
|
|
1671
|
+
case 'updateNode':
|
|
1672
|
+
result = await graphService.updateNode({
|
|
1673
|
+
id: input.id,
|
|
1674
|
+
properties: input.properties,
|
|
1675
|
+
labels: input.labels,
|
|
1676
|
+
});
|
|
1677
|
+
break;
|
|
1678
|
+
case 'deleteNode':
|
|
1679
|
+
result = await graphService.deleteNode({
|
|
1680
|
+
id: input.id,
|
|
1681
|
+
detach: input.detach,
|
|
1682
|
+
});
|
|
1683
|
+
break;
|
|
1684
|
+
case 'mergeNode':
|
|
1685
|
+
result = await graphService.mergeNode({
|
|
1686
|
+
labels: input.labels,
|
|
1687
|
+
matchProperties: input.matchProperties,
|
|
1688
|
+
onCreate: input.onCreate || input.setProperties,
|
|
1689
|
+
onMatch: input.onMatch,
|
|
1690
|
+
});
|
|
1691
|
+
break;
|
|
1692
|
+
case 'createRelationship':
|
|
1693
|
+
result = await graphService.createRelationship({
|
|
1694
|
+
type: input.type,
|
|
1695
|
+
startNodeId: input.startNodeId || input.from,
|
|
1696
|
+
endNodeId: input.endNodeId || input.to,
|
|
1697
|
+
properties: input.properties,
|
|
1698
|
+
});
|
|
1699
|
+
break;
|
|
1700
|
+
case 'findRelationships':
|
|
1701
|
+
result = await graphService.findRelationships({
|
|
1702
|
+
types: input.types,
|
|
1703
|
+
startNodeId: input.startNodeId,
|
|
1704
|
+
endNodeId: input.endNodeId,
|
|
1705
|
+
where: input.where,
|
|
1706
|
+
limit: input.limit,
|
|
1707
|
+
});
|
|
1708
|
+
break;
|
|
1709
|
+
case 'updateRelationship':
|
|
1710
|
+
result = await graphService.updateRelationship({
|
|
1711
|
+
id: input.id,
|
|
1712
|
+
properties: input.properties,
|
|
1713
|
+
});
|
|
1714
|
+
break;
|
|
1715
|
+
case 'deleteRelationship':
|
|
1716
|
+
result = await graphService.deleteRelationship({
|
|
1717
|
+
id: input.id,
|
|
1718
|
+
});
|
|
1719
|
+
break;
|
|
1720
|
+
case 'traverse':
|
|
1721
|
+
result = await graphService.traverse({
|
|
1722
|
+
startNodeId: input.startNodeId,
|
|
1723
|
+
direction: input.direction,
|
|
1724
|
+
relationshipTypes: input.relationshipTypes,
|
|
1725
|
+
maxDepth: input.maxDepth,
|
|
1726
|
+
minDepth: input.minDepth,
|
|
1727
|
+
nodeFilter: input.nodeFilter || input.where,
|
|
1728
|
+
relationshipFilter: input.relationshipFilter,
|
|
1729
|
+
limit: input.limit,
|
|
1730
|
+
});
|
|
1731
|
+
break;
|
|
1732
|
+
case 'shortestPath':
|
|
1733
|
+
result = await graphService.shortestPath({
|
|
1734
|
+
startNodeId: input.startNodeId,
|
|
1735
|
+
endNodeId: input.endNodeId,
|
|
1736
|
+
relationshipTypes: input.relationshipTypes,
|
|
1737
|
+
maxDepth: input.maxDepth,
|
|
1738
|
+
});
|
|
1739
|
+
break;
|
|
1740
|
+
case 'query':
|
|
1741
|
+
result = await graphService.query(input.query, input.params);
|
|
1742
|
+
break;
|
|
1743
|
+
case 'countNodes':
|
|
1744
|
+
result = await graphService.countNodes(input.labels, input.where);
|
|
1745
|
+
break;
|
|
1746
|
+
case 'countRelationships':
|
|
1747
|
+
result = await graphService.countRelationships(input.types, input.where);
|
|
1748
|
+
break;
|
|
1749
|
+
case 'getStatistics':
|
|
1750
|
+
result = await graphService.getStatistics();
|
|
1751
|
+
break;
|
|
1752
|
+
default:
|
|
1753
|
+
throw new Error(`Unknown graph operation: ${operation}`);
|
|
1754
|
+
}
|
|
1755
|
+
return { success: true, data: result };
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Process workflow job
|
|
1759
|
+
* Executes a workflow using the workflow service
|
|
1760
|
+
*/
|
|
1761
|
+
async processWorkflow(data) {
|
|
1762
|
+
const { env, product, workflow, input, idempotency_key } = data;
|
|
1763
|
+
// Initialize product builder if not already done
|
|
1764
|
+
if (product) {
|
|
1765
|
+
await this.productBuilderService.initializeProductByTag(product);
|
|
1766
|
+
}
|
|
1767
|
+
// Execute the workflow using the workflow service
|
|
1768
|
+
const { WorkflowService } = await Promise.resolve().then(() => __importStar(require('../../workflows/workflows.service')));
|
|
1769
|
+
const workflowService = new WorkflowService({
|
|
1770
|
+
workspace_id: this.workspace_id,
|
|
1771
|
+
public_key: this.public_key,
|
|
1772
|
+
user_id: this.user_id,
|
|
1773
|
+
token: this.token,
|
|
1774
|
+
env_type: this.environment,
|
|
1775
|
+
private_key: this._privateKey,
|
|
1776
|
+
access_key: this.accessKey
|
|
1777
|
+
});
|
|
1778
|
+
// Execute the workflow
|
|
1779
|
+
const result = await workflowService.execute({
|
|
1780
|
+
product,
|
|
1781
|
+
env,
|
|
1782
|
+
tag: workflow,
|
|
1783
|
+
input: input || {},
|
|
1784
|
+
idempotency_key,
|
|
1785
|
+
});
|
|
1786
|
+
return {
|
|
1787
|
+
success: result.status === 'completed',
|
|
1788
|
+
data: result.output,
|
|
1789
|
+
workflow_id: result.workflow_id,
|
|
1790
|
+
status: result.status,
|
|
1791
|
+
error: result.error,
|
|
1792
|
+
};
|
|
1884
1793
|
}
|
|
1885
1794
|
async getAndStoreAuth(appEnv, access_tag) {
|
|
1886
1795
|
try {
|
|
1887
|
-
// const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.
|
|
1888
|
-
const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.
|
|
1796
|
+
// const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.fetchPrivateKey()));
|
|
1797
|
+
const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.fetchPrivateKey()));
|
|
1889
1798
|
let app = await this.fetchThirdPartyApp(access_tag);
|
|
1890
1799
|
const auth = app.auths.find((item) => item.tag === appEnv.auth.auth_tag);
|
|
1891
|
-
console.log(
|
|
1800
|
+
console.log('JAMESY', auth);
|
|
1892
1801
|
if (!auth) {
|
|
1893
1802
|
// throw an error
|
|
1894
1803
|
throw new Error(`Cannot find auth ${appEnv.auth.auth_tag} on environment ${appEnv.product_env_slug}`);
|
|
@@ -1903,10 +1812,16 @@ class ProcessorService {
|
|
|
1903
1812
|
if (env.base_url) {
|
|
1904
1813
|
request_base_url = env.base_url;
|
|
1905
1814
|
}
|
|
1906
|
-
|
|
1815
|
+
if (action.envs && action.envs.length) {
|
|
1816
|
+
const env = action.envs.find((item) => item.slug === appEnv.app_env_slug);
|
|
1817
|
+
if (env && env.base_url) {
|
|
1818
|
+
request_base_url = env.base_url;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
console.log('payloadabi!!!!', payload);
|
|
1907
1822
|
const results = await this.sendActionRequest(request_base_url, url, payload, method, appEnv.app_env_slug);
|
|
1908
|
-
const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.
|
|
1909
|
-
const productApp = this.productBuilderService.fetchApp(access_tag);
|
|
1823
|
+
const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchPrivateKey());
|
|
1824
|
+
const productApp = await this.productBuilderService.fetchApp(access_tag);
|
|
1910
1825
|
for (let i = 0; i < productApp.envs.length; i++) {
|
|
1911
1826
|
if (productApp.envs[i].app_env_slug === env.slug) {
|
|
1912
1827
|
productApp.envs[i].auth.values = values; // write new values
|
|
@@ -2002,7 +1917,7 @@ class ProcessorService {
|
|
|
2002
1917
|
// generate indexes
|
|
2003
1918
|
return (0, processor_utils_1.generateIndexes)(operator, iter, init, valueValue);
|
|
2004
1919
|
}
|
|
2005
|
-
async runAction(event, additional_logs, returnValue = true) {
|
|
1920
|
+
async runAction(event, additional_logs, returnValue = true, bootstrapData) {
|
|
2006
1921
|
try {
|
|
2007
1922
|
const { event: action_tag, app: access_tag, condition, cache: cache_tag } = event;
|
|
2008
1923
|
let indexes = [];
|
|
@@ -2015,28 +1930,59 @@ class ProcessorService {
|
|
|
2015
1930
|
if (condition && condition.type === types_1.Conditions.LOOP) {
|
|
2016
1931
|
indexes = await this.extractLoopIndexes(event, additional_logs);
|
|
2017
1932
|
}
|
|
2018
|
-
let
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
if
|
|
2026
|
-
|
|
1933
|
+
let action;
|
|
1934
|
+
let env;
|
|
1935
|
+
let retries;
|
|
1936
|
+
let recipient_workspace_id;
|
|
1937
|
+
let app_active;
|
|
1938
|
+
let app_id = '';
|
|
1939
|
+
let app_env_slug = '';
|
|
1940
|
+
// Use bootstrap data if provided, otherwise fetch via API
|
|
1941
|
+
if (bootstrapData) {
|
|
1942
|
+
action = bootstrapData.action;
|
|
1943
|
+
env = bootstrapData.app_env;
|
|
1944
|
+
retries = bootstrapData.retries;
|
|
1945
|
+
recipient_workspace_id = bootstrapData.recipient_workspace_id;
|
|
1946
|
+
app_active = bootstrapData.app_active;
|
|
1947
|
+
app_env_slug = env.slug;
|
|
1948
|
+
additional_logs.app_env = app_env_slug;
|
|
2027
1949
|
}
|
|
2028
|
-
|
|
2029
|
-
|
|
1950
|
+
else {
|
|
1951
|
+
// Fallback to original API-based fetching (for features/workflows that don't use bootstrap)
|
|
1952
|
+
const appData = await this.fetchThirdPartyApp(access_tag);
|
|
1953
|
+
const { actions, envs: appEnvs, retries: appRetries, workspace_id: appWorkspaceId, active } = appData;
|
|
1954
|
+
const productApp = await this.productBuilderService.fetchApp(access_tag);
|
|
1955
|
+
const { envs: productEnvs } = productApp;
|
|
1956
|
+
const envMapping = productEnvs.find((item) => item.product_env_slug === this.processEnv.slug);
|
|
1957
|
+
app_env_slug = (envMapping === null || envMapping === void 0 ? void 0 : envMapping.app_env_slug) || '';
|
|
1958
|
+
additional_logs.app_env = app_env_slug;
|
|
1959
|
+
env = appEnvs.find((item) => item.slug === app_env_slug);
|
|
1960
|
+
action = actions.find((item) => item.tag === action_tag);
|
|
1961
|
+
retries = appRetries;
|
|
1962
|
+
recipient_workspace_id = appWorkspaceId;
|
|
1963
|
+
app_active = active;
|
|
1964
|
+
app_id = appData._id;
|
|
1965
|
+
if (!action) {
|
|
1966
|
+
throw new Error(`Action ${action_tag} not found in ${access_tag}`);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
if (!app_active && recipient_workspace_id !== this.baseLogs.workspace_id) {
|
|
1970
|
+
throw new Error(`App ${event.app} is not active`);
|
|
2030
1971
|
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
throw new Error(`Action ${action_tag} not found in ${access_tag}`);
|
|
1972
|
+
if (!env.active) {
|
|
1973
|
+
throw new Error(`Action environment ${env.slug} is not active`);
|
|
2034
1974
|
}
|
|
2035
1975
|
const { query, headers, body, params, request_type, method, base_url, resource } = action;
|
|
2036
1976
|
let request_base_url = base_url;
|
|
2037
1977
|
if (env.base_url) {
|
|
2038
1978
|
request_base_url = env.base_url;
|
|
2039
1979
|
}
|
|
1980
|
+
if (action.envs && action.envs.length) {
|
|
1981
|
+
const actionEnv = action.envs.find((item) => item.slug === app_env_slug);
|
|
1982
|
+
if (actionEnv && actionEnv.base_url) {
|
|
1983
|
+
request_base_url = actionEnv.base_url;
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
2040
1986
|
const samples = {
|
|
2041
1987
|
query: (query === null || query === void 0 ? void 0 : query.data) || [],
|
|
2042
1988
|
headers: (headers === null || headers === void 0 ? void 0 : headers.data) || [],
|
|
@@ -2045,9 +1991,10 @@ class ProcessorService {
|
|
|
2045
1991
|
};
|
|
2046
1992
|
let payloads;
|
|
2047
1993
|
let result;
|
|
2048
|
-
const product = this.productBuilderService.fetchProduct();
|
|
2049
|
-
|
|
2050
|
-
|
|
1994
|
+
//const product = this.productBuilderService.fetchProduct();
|
|
1995
|
+
// Check cache for existing result (skip if early cache check already done)
|
|
1996
|
+
if (cache_tag && this.redisClient && !event.skipCacheFetch) {
|
|
1997
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
2051
1998
|
if (!productCache) {
|
|
2052
1999
|
throw new Error('Invalid cache tag ');
|
|
2053
2000
|
}
|
|
@@ -2055,7 +2002,7 @@ class ProcessorService {
|
|
|
2055
2002
|
const check = await this.fetchFromCache({
|
|
2056
2003
|
cache_tag,
|
|
2057
2004
|
input: inputString,
|
|
2058
|
-
privateKey:
|
|
2005
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
2059
2006
|
expiry: productCache.expiry,
|
|
2060
2007
|
}, additional_logs);
|
|
2061
2008
|
if (check) {
|
|
@@ -2068,31 +2015,32 @@ class ProcessorService {
|
|
|
2068
2015
|
}
|
|
2069
2016
|
if (request_type === types_1.DataFormats.JSON || request_type === types_1.DataFormats.URLENCODED || !request_type) {
|
|
2070
2017
|
if (indexes.length == 0) {
|
|
2071
|
-
payloads = await this.constructJSONDataPayloads(event.input, additional_logs, samples, event);
|
|
2018
|
+
payloads = (await this.constructJSONDataPayloads(event.input, additional_logs, samples, event));
|
|
2072
2019
|
if (request_type === types_1.DataFormats.URLENCODED) {
|
|
2073
2020
|
payloads.body = (0, processor_utils_1.toFormUrlEncoded)(payloads.body);
|
|
2074
2021
|
}
|
|
2075
2022
|
additional_logs.recipient_workspace_id = recipient_workspace_id;
|
|
2076
|
-
result = await this.processRequest({ request_base_url, resource, method, env, payloads, app_id
|
|
2023
|
+
result = await this.processRequest({ request_base_url, resource, method, env, payloads, app_id }, event, { retries }, additional_logs, returnValue);
|
|
2077
2024
|
}
|
|
2078
2025
|
else {
|
|
2079
2026
|
const promises = indexes.map(async (index) => {
|
|
2080
2027
|
payloads = await this.constructJSONDataPayloads(event.input, additional_logs, samples, event, index);
|
|
2081
2028
|
additional_logs.recipient_workspace_id = recipient_workspace_id;
|
|
2082
|
-
await this.processRequest({ request_base_url, resource, method, env, payloads, app_id
|
|
2029
|
+
await this.processRequest({ request_base_url, resource, method, env, payloads, app_id }, event, { retries }, additional_logs, returnValue);
|
|
2083
2030
|
});
|
|
2084
2031
|
result = await Promise.all(promises);
|
|
2085
2032
|
}
|
|
2086
2033
|
}
|
|
2087
2034
|
if (cache_tag && this.redisClient && result) {
|
|
2088
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
2035
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
2089
2036
|
if (!productCache) {
|
|
2090
2037
|
throw new Error('Invalid cache tag ');
|
|
2091
2038
|
}
|
|
2092
2039
|
const inputString = JSON.stringify(event.input);
|
|
2093
|
-
|
|
2040
|
+
// Fire-and-forget cache store
|
|
2041
|
+
this.addToCache({
|
|
2094
2042
|
input: inputString,
|
|
2095
|
-
privateKey:
|
|
2043
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
2096
2044
|
data: JSON.stringify(result),
|
|
2097
2045
|
cache_tag,
|
|
2098
2046
|
timestamp: Date.now(),
|
|
@@ -2109,6 +2057,7 @@ class ProcessorService {
|
|
|
2109
2057
|
}
|
|
2110
2058
|
}
|
|
2111
2059
|
async processRequest(payload, event, retries, additional_logs, returnValue = false) {
|
|
2060
|
+
var _a;
|
|
2112
2061
|
const { request_base_url, resource, payloads, method, env, app_id } = payload;
|
|
2113
2062
|
const start = Date.now();
|
|
2114
2063
|
try {
|
|
@@ -2119,7 +2068,11 @@ class ProcessorService {
|
|
|
2119
2068
|
const end = Date.now();
|
|
2120
2069
|
this.requestTime += end - start;
|
|
2121
2070
|
this.totalRequests += 1;
|
|
2122
|
-
this.
|
|
2071
|
+
const { pricing_tag, pricing_cost, is_overage, currency } = await this.processPricingCost(Object.assign(Object.assign({}, additional_logs), { app_id, workspace_id: this.workspace_id }));
|
|
2072
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { pricing_tag,
|
|
2073
|
+
pricing_cost,
|
|
2074
|
+
currency,
|
|
2075
|
+
is_overage, message: 'Process http request - success', successful_execution: true, data: { response: (0, processor_utils_1.anonymizeObject)(results) }, status: types_1.LogEventStatus.SUCCESS, app_id, action: event.event, start,
|
|
2123
2076
|
end }));
|
|
2124
2077
|
await this.addToSuccessOutput(event, results, additional_logs);
|
|
2125
2078
|
if (returnValue) {
|
|
@@ -2132,7 +2085,7 @@ class ProcessorService {
|
|
|
2132
2085
|
catch (e) {
|
|
2133
2086
|
const end = Date.now();
|
|
2134
2087
|
let error = e;
|
|
2135
|
-
if (e.response.data) {
|
|
2088
|
+
if ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) {
|
|
2136
2089
|
error = e.response.data;
|
|
2137
2090
|
}
|
|
2138
2091
|
this.requestTime += end - start;
|
|
@@ -2165,6 +2118,67 @@ class ProcessorService {
|
|
|
2165
2118
|
}
|
|
2166
2119
|
}
|
|
2167
2120
|
}
|
|
2121
|
+
async processPricingCost(additional_logs) {
|
|
2122
|
+
try {
|
|
2123
|
+
const { app_id, workspace_id } = additional_logs;
|
|
2124
|
+
if (!app_id || !workspace_id) {
|
|
2125
|
+
throw new Error('app_id and workspace_id are required in additional_logs');
|
|
2126
|
+
}
|
|
2127
|
+
const primaryPricing = this.pricingService.fetchPricing();
|
|
2128
|
+
const overagePricing = this.pricingService.fetchOveragePricing();
|
|
2129
|
+
const requests = await this.requestTrackerService.incrementRequest(app_id, workspace_id);
|
|
2130
|
+
const limitCheck = (0, request_utils_1.checkLimitExceeded)(requests, primaryPricing.limits);
|
|
2131
|
+
let finalCost = 0;
|
|
2132
|
+
let usedPricing = primaryPricing;
|
|
2133
|
+
let isOverage = false;
|
|
2134
|
+
let finalCurrency = primaryPricing.currency;
|
|
2135
|
+
if ((0, request_utils_1.isFreeTag)(primaryPricing.pricing_tag)) {
|
|
2136
|
+
if (limitCheck.exceeded) {
|
|
2137
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2138
|
+
finalCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2139
|
+
usedPricing = overagePricing;
|
|
2140
|
+
isOverage = true;
|
|
2141
|
+
finalCurrency = overagePricing.currency;
|
|
2142
|
+
}
|
|
2143
|
+
else {
|
|
2144
|
+
finalCost = 0;
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
else {
|
|
2148
|
+
if (limitCheck.exceeded) {
|
|
2149
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2150
|
+
const overageCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2151
|
+
finalCost = overageCost;
|
|
2152
|
+
isOverage = true;
|
|
2153
|
+
}
|
|
2154
|
+
else {
|
|
2155
|
+
const pricingRequests = (0, request_utils_1.calculateRequests)(requests);
|
|
2156
|
+
finalCost = (0, request_utils_1.calculateCost)(primaryPricing.pricing_mode, primaryPricing.unit_price, pricingRequests);
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - success', data: {
|
|
2160
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2161
|
+
cost: finalCost,
|
|
2162
|
+
currency: finalCurrency,
|
|
2163
|
+
is_overage: isOverage,
|
|
2164
|
+
requests: requests,
|
|
2165
|
+
limit_exceeded: limitCheck.exceeded,
|
|
2166
|
+
}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2167
|
+
return {
|
|
2168
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2169
|
+
pricing_cost: Math.round(finalCost * 100) / 100,
|
|
2170
|
+
currency: finalCurrency,
|
|
2171
|
+
is_overage: isOverage,
|
|
2172
|
+
requests_made: requests,
|
|
2173
|
+
limit_exceeded: limitCheck.exceeded,
|
|
2174
|
+
exceeded_limits: limitCheck.exceededLimits,
|
|
2175
|
+
};
|
|
2176
|
+
}
|
|
2177
|
+
catch (e) {
|
|
2178
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - failed', data: { error: e }, status: types_1.LogEventStatus.FAIL }));
|
|
2179
|
+
throw e;
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2168
2182
|
async addToSuccessOutput(event, output, additional_logs) {
|
|
2169
2183
|
// Remove event from failed, skipped, and waiting arrays
|
|
2170
2184
|
this.processingOutput.failure = this.processingOutput.failure.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
@@ -2174,7 +2188,6 @@ class ProcessorService {
|
|
|
2174
2188
|
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2175
2189
|
}
|
|
2176
2190
|
this.processingOutput.success.push({ event, output });
|
|
2177
|
-
await this.processWaitingEvents(additional_logs);
|
|
2178
2191
|
if (this.checkIsSuccessful() && this.doneWithProcessing) {
|
|
2179
2192
|
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 }));
|
|
2180
2193
|
await this.logService.publish();
|
|
@@ -2194,18 +2207,6 @@ class ProcessorService {
|
|
|
2194
2207
|
}
|
|
2195
2208
|
return success;
|
|
2196
2209
|
}
|
|
2197
|
-
addToWaitingOutput(event, dependants) {
|
|
2198
|
-
const exists = this.processingOutput.waiting.findIndex((item) => {
|
|
2199
|
-
return item.event.event === event.event && item.event.sequence_tag === event.sequence_tag;
|
|
2200
|
-
});
|
|
2201
|
-
const skipped = this.processingOutput.skipped.findIndex((item) => {
|
|
2202
|
-
return item.event.event === event.event && item.event.sequence_tag === event.sequence_tag;
|
|
2203
|
-
});
|
|
2204
|
-
if (!exists && !skipped) {
|
|
2205
|
-
this.processingOutput.waiting.push({ event, dependants });
|
|
2206
|
-
}
|
|
2207
|
-
// addToSkippedOutput()
|
|
2208
|
-
}
|
|
2209
2210
|
async addToFailureOutput(e, event, payload, additional_logs, policy = {}) {
|
|
2210
2211
|
try {
|
|
2211
2212
|
this.processingFailure = true;
|
|
@@ -2230,7 +2231,7 @@ class ProcessorService {
|
|
|
2230
2231
|
let retryable = true;
|
|
2231
2232
|
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2232
2233
|
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2233
|
-
if (!
|
|
2234
|
+
if (!event.allow_fail)
|
|
2234
2235
|
retryable = false;
|
|
2235
2236
|
}
|
|
2236
2237
|
let retries_left = retries || max;
|
|
@@ -2263,9 +2264,6 @@ class ProcessorService {
|
|
|
2263
2264
|
if (event.type === types_1.FeatureEventTypes.ACTION) {
|
|
2264
2265
|
this.processRequest(payload, event, policy, additional_logs);
|
|
2265
2266
|
}
|
|
2266
|
-
if (event.type === types_1.FeatureEventTypes.DB_ACTION) {
|
|
2267
|
-
this.processDBRequest(event, event.input, payload.database_tag, payload.databaseEnv, payload.action_tag, additional_logs);
|
|
2268
|
-
}
|
|
2269
2267
|
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2270
2268
|
this.processStorageRequest(event, event.input, payload.storageEnv, additional_logs);
|
|
2271
2269
|
}
|
|
@@ -2273,9 +2271,6 @@ class ProcessorService {
|
|
|
2273
2271
|
}
|
|
2274
2272
|
if (allow_fail === false && retries_left === 0) {
|
|
2275
2273
|
this.published = true;
|
|
2276
|
-
if (this.feature) {
|
|
2277
|
-
additional_logs.failed_feature_execution = true;
|
|
2278
|
-
}
|
|
2279
2274
|
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 }));
|
|
2280
2275
|
//throw new Error("Run out of retries")
|
|
2281
2276
|
this.end = Date.now();
|
|
@@ -2322,9 +2317,9 @@ class ProcessorService {
|
|
|
2322
2317
|
params: query,
|
|
2323
2318
|
headers: authHeaders,
|
|
2324
2319
|
timeout: 15000,
|
|
2325
|
-
withCredentials: false
|
|
2320
|
+
withCredentials: false,
|
|
2326
2321
|
};
|
|
2327
|
-
console.log(
|
|
2322
|
+
console.log('REQUEST!!!!', request);
|
|
2328
2323
|
const response = await axios_1.default.request(request);
|
|
2329
2324
|
return response.data;
|
|
2330
2325
|
}
|
|
@@ -2335,12 +2330,15 @@ class ProcessorService {
|
|
|
2335
2330
|
}
|
|
2336
2331
|
async processStorage(action) {
|
|
2337
2332
|
//TODO: schema validation
|
|
2338
|
-
const { env, input, retries, event, product: product_tag } = action;
|
|
2333
|
+
const { env, input, retries, event, product: product_tag, session, cache } = action;
|
|
2339
2334
|
const additional_logs = {
|
|
2340
2335
|
parent_tag: event,
|
|
2341
2336
|
type: types_1.LogEventTypes.STORAGE,
|
|
2342
2337
|
name: 'Process Storage',
|
|
2343
2338
|
};
|
|
2339
|
+
// Session log fields (will be populated if session is provided)
|
|
2340
|
+
let sessionLogFields = {};
|
|
2341
|
+
let resolvedInput = input;
|
|
2344
2342
|
try {
|
|
2345
2343
|
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2346
2344
|
this.input = input;
|
|
@@ -2353,23 +2351,62 @@ class ProcessorService {
|
|
|
2353
2351
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
2354
2352
|
this.baseLogs = Object.assign({ product_tag: this.productTag, product_id: this.productId, workspace_id: this.workspace_id, env,
|
|
2355
2353
|
process_id, data: this.clone }, additional_logs);
|
|
2356
|
-
|
|
2354
|
+
// Single bootstrap call to fetch all storage data
|
|
2355
|
+
const bootstrapData = await this.productBuilderService.bootstrapStorage({
|
|
2356
|
+
product_tag,
|
|
2357
|
+
env_slug: env,
|
|
2358
|
+
storage_tag: event,
|
|
2359
|
+
});
|
|
2360
|
+
// Initialize from bootstrap data
|
|
2361
|
+
this.productId = bootstrapData.product_id;
|
|
2362
|
+
this.processEnv = bootstrapData.env;
|
|
2363
|
+
// Process session if provided - verify and resolve $Session{} references
|
|
2364
|
+
if (session && bootstrapData.private_key) {
|
|
2365
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../../sessions')));
|
|
2366
|
+
const sessionResult = await processSessionForExecution(session, bootstrapData.private_key, input, env, {
|
|
2367
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
2368
|
+
const sessionConfig = await this.productBuilderService.fetchSession(sessionTag);
|
|
2369
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
2370
|
+
},
|
|
2371
|
+
});
|
|
2372
|
+
if (sessionResult.error) {
|
|
2373
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
2374
|
+
}
|
|
2375
|
+
resolvedInput = sessionResult.input;
|
|
2376
|
+
sessionLogFields = sessionResult.logFields;
|
|
2377
|
+
}
|
|
2378
|
+
// Initialize log service if needed
|
|
2379
|
+
if (!this.logService) {
|
|
2380
|
+
this.logService = new logs_service_1.default({
|
|
2381
|
+
product_id: this.productId,
|
|
2382
|
+
workspace_id: this.workspace_id,
|
|
2383
|
+
public_key: this.public_key,
|
|
2384
|
+
user_id: this.user_id,
|
|
2385
|
+
token: this.token,
|
|
2386
|
+
env_type: this.environment,
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2357
2389
|
this.process_id = process_id;
|
|
2358
|
-
|
|
2359
|
-
|
|
2390
|
+
this.baseLogs.product_id = this.productId;
|
|
2391
|
+
// Add session fields to base logs
|
|
2392
|
+
this.baseLogs = Object.assign(Object.assign({}, this.baseLogs), sessionLogFields);
|
|
2393
|
+
const productEnv = bootstrapData.env;
|
|
2360
2394
|
if (!productEnv.active) {
|
|
2361
2395
|
throw new Error(`Environment ${env} is not active`);
|
|
2362
2396
|
}
|
|
2363
2397
|
const payload = {
|
|
2364
2398
|
type: types_1.FeatureEventTypes.STORAGE,
|
|
2365
2399
|
event,
|
|
2366
|
-
cache:
|
|
2367
|
-
input,
|
|
2400
|
+
cache: cache,
|
|
2401
|
+
input: resolvedInput,
|
|
2368
2402
|
env: productEnv,
|
|
2369
2403
|
retries: retries || 0,
|
|
2370
2404
|
allow_fail: false,
|
|
2371
2405
|
};
|
|
2372
|
-
const result = await this.runStorage(payload
|
|
2406
|
+
const result = await this.runStorage(payload, additional_logs, {
|
|
2407
|
+
storage: bootstrapData.storage,
|
|
2408
|
+
storage_env: bootstrapData.storage_env,
|
|
2409
|
+
});
|
|
2373
2410
|
this.end = Date.now();
|
|
2374
2411
|
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 }));
|
|
2375
2412
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
@@ -2404,7 +2441,7 @@ class ProcessorService {
|
|
|
2404
2441
|
await this.intializeProduct(additional_logs);
|
|
2405
2442
|
this.baseLogs.product_id = this.productId;
|
|
2406
2443
|
this.process_id = process_id;
|
|
2407
|
-
const productEnv = this.fetchEnv(data.env, additional_logs);
|
|
2444
|
+
const productEnv = await this.fetchEnv(data.env, additional_logs);
|
|
2408
2445
|
this.processEnv = productEnv;
|
|
2409
2446
|
if (!productEnv.active) {
|
|
2410
2447
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -2443,6 +2480,9 @@ class ProcessorService {
|
|
|
2443
2480
|
type: types_1.LogEventTypes.MESSAGEBROKER,
|
|
2444
2481
|
name: 'Publish to broker topic',
|
|
2445
2482
|
};
|
|
2483
|
+
// Session log fields (will be populated if session is provided)
|
|
2484
|
+
let sessionLogFields = {};
|
|
2485
|
+
let resolvedInput = data.input;
|
|
2446
2486
|
try {
|
|
2447
2487
|
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2448
2488
|
this.start = Date.now();
|
|
@@ -2456,7 +2496,25 @@ class ProcessorService {
|
|
|
2456
2496
|
await this.intializeProduct(additional_logs);
|
|
2457
2497
|
this.baseLogs.product_id = this.productId;
|
|
2458
2498
|
this.process_id = process_id;
|
|
2459
|
-
|
|
2499
|
+
// Process session if provided - verify and resolve $Session{} references
|
|
2500
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
2501
|
+
if (data.session && privateKey) {
|
|
2502
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../../sessions')));
|
|
2503
|
+
const sessionResult = await processSessionForExecution(data.session, privateKey, data.input, data.env, {
|
|
2504
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
2505
|
+
const sessionConfig = await this.productBuilderService.fetchSession(sessionTag);
|
|
2506
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
2507
|
+
},
|
|
2508
|
+
});
|
|
2509
|
+
if (sessionResult.error) {
|
|
2510
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
2511
|
+
}
|
|
2512
|
+
resolvedInput = sessionResult.input;
|
|
2513
|
+
sessionLogFields = sessionResult.logFields;
|
|
2514
|
+
}
|
|
2515
|
+
// Add session fields to base logs
|
|
2516
|
+
this.baseLogs = Object.assign(Object.assign({}, this.baseLogs), sessionLogFields);
|
|
2517
|
+
const productEnv = await this.fetchEnv(data.env, additional_logs);
|
|
2460
2518
|
this.processEnv = productEnv;
|
|
2461
2519
|
if (!productEnv.active) {
|
|
2462
2520
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -2465,7 +2523,7 @@ class ProcessorService {
|
|
|
2465
2523
|
type: types_1.FeatureEventTypes.PUBLISH,
|
|
2466
2524
|
event: data.event,
|
|
2467
2525
|
cache: data.cache,
|
|
2468
|
-
input:
|
|
2526
|
+
input: resolvedInput,
|
|
2469
2527
|
env: productEnv,
|
|
2470
2528
|
retries: 0,
|
|
2471
2529
|
allow_fail: false,
|
|
@@ -2485,8 +2543,8 @@ class ProcessorService {
|
|
|
2485
2543
|
}
|
|
2486
2544
|
}
|
|
2487
2545
|
async processJob(job, additional_logs = {}) {
|
|
2488
|
-
var _a;
|
|
2489
|
-
const productJob = this.productBuilderService.fetchJob(job.event);
|
|
2546
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2547
|
+
const productJob = await this.productBuilderService.fetchJob(job.event);
|
|
2490
2548
|
if (!productJob) {
|
|
2491
2549
|
throw new Error(`Job ${job.event} not found`);
|
|
2492
2550
|
}
|
|
@@ -2494,8 +2552,10 @@ class ProcessorService {
|
|
|
2494
2552
|
const NOW = Date.now();
|
|
2495
2553
|
// Treat anything above Jan 1, 2023 as a timestamp (to be safe and future-proof)
|
|
2496
2554
|
const IS_PROBABLY_TIMESTAMP = job.start_at > 1672531200000;
|
|
2497
|
-
const
|
|
2555
|
+
const scheduled_at = IS_PROBABLY_TIMESTAMP ? job.start_at : NOW + job.start_at;
|
|
2556
|
+
const delay = Math.max(0, scheduled_at - NOW);
|
|
2498
2557
|
let jobInput;
|
|
2558
|
+
let namespace = productJob.type;
|
|
2499
2559
|
if (productJob.type === types_1.JobEventTypes.ACTION) {
|
|
2500
2560
|
const input = {
|
|
2501
2561
|
env: job.env,
|
|
@@ -2503,93 +2563,220 @@ class ProcessorService {
|
|
|
2503
2563
|
app: productJob.app,
|
|
2504
2564
|
cache: job.cache,
|
|
2505
2565
|
input: job.input,
|
|
2506
|
-
|
|
2507
|
-
session: job.session
|
|
2566
|
+
action: job.event,
|
|
2567
|
+
session: job.session,
|
|
2508
2568
|
};
|
|
2509
2569
|
jobInput = input;
|
|
2570
|
+
namespace = 'actions';
|
|
2510
2571
|
}
|
|
2511
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2572
|
+
else if (productJob.type === types_1.JobEventTypes.NOTIFICATION) {
|
|
2512
2573
|
const input = {
|
|
2513
2574
|
env: job.env,
|
|
2514
2575
|
product: job.product,
|
|
2515
|
-
cache: job.cache,
|
|
2516
|
-
input: job.input,
|
|
2517
2576
|
event: job.event,
|
|
2577
|
+
input: job.input,
|
|
2518
2578
|
session: job.session,
|
|
2579
|
+
cache: job.cache,
|
|
2519
2580
|
};
|
|
2520
2581
|
jobInput = input;
|
|
2582
|
+
namespace = 'notifications';
|
|
2521
2583
|
}
|
|
2522
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2584
|
+
else if (productJob.type === types_1.JobEventTypes.PUBLISH) {
|
|
2523
2585
|
const input = {
|
|
2524
|
-
input: job.input,
|
|
2525
|
-
product: job.product,
|
|
2526
2586
|
env: job.env,
|
|
2527
|
-
|
|
2528
|
-
|
|
2587
|
+
product: job.product,
|
|
2588
|
+
event: job.event,
|
|
2529
2589
|
cache: job.cache,
|
|
2590
|
+
session: job.session,
|
|
2591
|
+
input: job.input,
|
|
2530
2592
|
};
|
|
2531
2593
|
jobInput = input;
|
|
2594
|
+
namespace = 'events';
|
|
2532
2595
|
}
|
|
2533
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2596
|
+
else if (productJob.type === types_1.JobEventTypes.STORAGE) {
|
|
2534
2597
|
const input = {
|
|
2535
2598
|
env: job.env,
|
|
2536
2599
|
product: job.product,
|
|
2537
2600
|
event: job.event,
|
|
2601
|
+
cache: job.cache,
|
|
2602
|
+
session: job.session,
|
|
2538
2603
|
input: job.input,
|
|
2604
|
+
};
|
|
2605
|
+
jobInput = input;
|
|
2606
|
+
namespace = 'storage';
|
|
2607
|
+
}
|
|
2608
|
+
else if (productJob.type === types_1.JobEventTypes.DATABASE_ACTION) {
|
|
2609
|
+
// Database action job - predefined database actions
|
|
2610
|
+
const input = {
|
|
2611
|
+
env: job.env,
|
|
2612
|
+
product: job.product,
|
|
2613
|
+
database: productJob.app,
|
|
2614
|
+
event: productJob.event,
|
|
2615
|
+
cache: job.cache,
|
|
2539
2616
|
session: job.session,
|
|
2540
|
-
|
|
2617
|
+
input: job.input,
|
|
2541
2618
|
};
|
|
2542
2619
|
jobInput = input;
|
|
2620
|
+
namespace = 'database';
|
|
2543
2621
|
}
|
|
2544
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2622
|
+
else if (productJob.type === types_1.JobEventTypes.DATABASE_OPERATION) {
|
|
2623
|
+
// Database operation job - direct database operations like createOne, findMany, etc.
|
|
2545
2624
|
const input = {
|
|
2546
2625
|
env: job.env,
|
|
2547
2626
|
product: job.product,
|
|
2548
|
-
|
|
2627
|
+
database: productJob.app,
|
|
2628
|
+
operation: productJob.event,
|
|
2549
2629
|
cache: job.cache,
|
|
2550
2630
|
session: job.session,
|
|
2551
|
-
input: job.input
|
|
2631
|
+
input: job.input,
|
|
2552
2632
|
};
|
|
2553
2633
|
jobInput = input;
|
|
2634
|
+
namespace = 'database';
|
|
2554
2635
|
}
|
|
2555
|
-
else if (productJob.type === types_1.JobEventTypes.
|
|
2636
|
+
else if (productJob.type === types_1.JobEventTypes.GRAPH_ACTION) {
|
|
2637
|
+
// Graph action job - predefined graph actions
|
|
2556
2638
|
const input = {
|
|
2557
2639
|
env: job.env,
|
|
2558
2640
|
product: job.product,
|
|
2559
|
-
|
|
2641
|
+
graph: productJob.app,
|
|
2642
|
+
event: productJob.event,
|
|
2560
2643
|
cache: job.cache,
|
|
2561
2644
|
session: job.session,
|
|
2562
|
-
input: job.input
|
|
2645
|
+
input: job.input,
|
|
2563
2646
|
};
|
|
2564
2647
|
jobInput = input;
|
|
2648
|
+
namespace = 'graphs';
|
|
2565
2649
|
}
|
|
2566
|
-
else {
|
|
2567
|
-
|
|
2650
|
+
else if (productJob.type === types_1.JobEventTypes.GRAPH_OPERATION) {
|
|
2651
|
+
// Graph operation job - direct graph operations like createNode, traverse, etc.
|
|
2652
|
+
const input = {
|
|
2653
|
+
env: job.env,
|
|
2654
|
+
product: job.product,
|
|
2655
|
+
graph: productJob.app,
|
|
2656
|
+
operation: productJob.event,
|
|
2657
|
+
cache: job.cache,
|
|
2658
|
+
session: job.session,
|
|
2659
|
+
input: job.input,
|
|
2660
|
+
};
|
|
2661
|
+
jobInput = input;
|
|
2662
|
+
namespace = 'graphs';
|
|
2568
2663
|
}
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2664
|
+
else if (productJob.type === types_1.JobEventTypes.WORKFLOW) {
|
|
2665
|
+
// Workflow job - execute a workflow
|
|
2666
|
+
const input = {
|
|
2667
|
+
env: job.env,
|
|
2668
|
+
product: job.product,
|
|
2669
|
+
workflow: productJob.app,
|
|
2670
|
+
cache: job.cache,
|
|
2671
|
+
session: job.session,
|
|
2672
|
+
input: job.input,
|
|
2673
|
+
};
|
|
2674
|
+
jobInput = input;
|
|
2675
|
+
namespace = 'workflows';
|
|
2676
|
+
}
|
|
2677
|
+
else {
|
|
2678
|
+
throw new Error(`Job type ${productJob.type} not supported`);
|
|
2679
|
+
}
|
|
2680
|
+
// Determine if this is a recurring job
|
|
2681
|
+
const isRecurring = !!(((_a = job.repeat) === null || _a === void 0 ? void 0 : _a.cron) || ((_b = job.repeat) === null || _b === void 0 ? void 0 : _b.every));
|
|
2682
|
+
// Generate a unique job ID
|
|
2683
|
+
const jobId = `job_${(0, uuid_1.v4)().replace(/-/g, '').substring(0, 16)}`;
|
|
2684
|
+
// Build queue options
|
|
2685
|
+
const options = {
|
|
2686
|
+
jobId,
|
|
2687
|
+
};
|
|
2688
|
+
// Handle `delay` only if repeat.every is not defined
|
|
2689
|
+
if (!((_c = job.repeat) === null || _c === void 0 ? void 0 : _c.every) && delay > 0) {
|
|
2690
|
+
options.delay = delay;
|
|
2573
2691
|
}
|
|
2574
2692
|
// Add repeat config if defined
|
|
2693
|
+
let next_run_at;
|
|
2575
2694
|
if (job.repeat) {
|
|
2576
2695
|
const { every, cron, tz, limit, endDate } = job.repeat;
|
|
2577
|
-
|
|
2578
|
-
|
|
2696
|
+
if (cron) {
|
|
2697
|
+
options.repeat = {
|
|
2579
2698
|
cron,
|
|
2580
2699
|
tz,
|
|
2581
2700
|
limit,
|
|
2582
2701
|
endDate,
|
|
2702
|
+
};
|
|
2703
|
+
// Calculate next run time from cron
|
|
2704
|
+
try {
|
|
2705
|
+
const cronParser = require('cron-parser');
|
|
2706
|
+
const cronOptions = {};
|
|
2707
|
+
if (tz)
|
|
2708
|
+
cronOptions.tz = tz;
|
|
2709
|
+
const interval = cronParser.parseExpression(cron, cronOptions);
|
|
2710
|
+
next_run_at = interval.next().getTime();
|
|
2583
2711
|
}
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2712
|
+
catch (err) {
|
|
2713
|
+
next_run_at = NOW;
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
else if (every) {
|
|
2717
|
+
options.repeat = {
|
|
2718
|
+
every,
|
|
2719
|
+
limit,
|
|
2720
|
+
endDate,
|
|
2721
|
+
};
|
|
2722
|
+
next_run_at = NOW + every;
|
|
2723
|
+
}
|
|
2591
2724
|
}
|
|
2725
|
+
// Store job metadata in Redis if redisClient is available
|
|
2726
|
+
if (this.redisClient) {
|
|
2727
|
+
const jobData = {
|
|
2728
|
+
id: jobId,
|
|
2729
|
+
status: delay > 0 ? 'scheduled' : 'queued',
|
|
2730
|
+
type: productJob.type,
|
|
2731
|
+
namespace,
|
|
2732
|
+
product: job.product,
|
|
2733
|
+
env: job.env,
|
|
2734
|
+
event: job.event,
|
|
2735
|
+
app: productJob.app,
|
|
2736
|
+
scheduled_at,
|
|
2737
|
+
recurring: isRecurring,
|
|
2738
|
+
cron: (_d = job.repeat) === null || _d === void 0 ? void 0 : _d.cron,
|
|
2739
|
+
every: (_e = job.repeat) === null || _e === void 0 ? void 0 : _e.every,
|
|
2740
|
+
next_run_at,
|
|
2741
|
+
execution_count: 0,
|
|
2742
|
+
limit: (_f = job.repeat) === null || _f === void 0 ? void 0 : _f.limit,
|
|
2743
|
+
end_date: ((_g = job.repeat) === null || _g === void 0 ? void 0 : _g.endDate)
|
|
2744
|
+
? typeof job.repeat.endDate === 'string'
|
|
2745
|
+
? new Date(job.repeat.endDate).getTime()
|
|
2746
|
+
: job.repeat.endDate
|
|
2747
|
+
: undefined,
|
|
2748
|
+
tz: (_h = job.repeat) === null || _h === void 0 ? void 0 : _h.tz,
|
|
2749
|
+
retries: job.retries || 0,
|
|
2750
|
+
retry_count: 0,
|
|
2751
|
+
input: jobInput,
|
|
2752
|
+
session: job.session,
|
|
2753
|
+
cache: job.cache,
|
|
2754
|
+
workspace_id: this.workspace_id,
|
|
2755
|
+
created_at: NOW,
|
|
2756
|
+
updated_at: NOW,
|
|
2757
|
+
};
|
|
2758
|
+
// Store in Redis with TTL of 90 days
|
|
2759
|
+
const jobKey = `job:${this.workspace_id}:${jobId}`;
|
|
2760
|
+
const redis = this.redisClient;
|
|
2761
|
+
await redis.setex(jobKey, 90 * 24 * 60 * 60, JSON.stringify(jobData));
|
|
2762
|
+
// Add to status index
|
|
2763
|
+
const statusKey = `job_status:${this.workspace_id}:${jobData.status}`;
|
|
2764
|
+
await redis.sadd(statusKey, jobId);
|
|
2765
|
+
// Add to product index
|
|
2766
|
+
const productKey = `job_product:${this.workspace_id}:${job.product}`;
|
|
2767
|
+
await redis.sadd(productKey, jobId);
|
|
2768
|
+
}
|
|
2769
|
+
// Add job input with the job ID for tracking
|
|
2770
|
+
jobInput._job_id = jobId;
|
|
2771
|
+
// Add job to queue
|
|
2592
2772
|
await this.queues.jobs.add(productJob.type, jobInput, options);
|
|
2773
|
+
return {
|
|
2774
|
+
job_id: jobId,
|
|
2775
|
+
status: delay > 0 ? 'scheduled' : 'queued',
|
|
2776
|
+
scheduled_at,
|
|
2777
|
+
recurring: isRecurring,
|
|
2778
|
+
next_run_at,
|
|
2779
|
+
};
|
|
2593
2780
|
}
|
|
2594
2781
|
async sendExpoNotification(payload, device_tokens) {
|
|
2595
2782
|
const message = {
|
|
@@ -2644,19 +2831,53 @@ class ProcessorService {
|
|
|
2644
2831
|
await this.sendFirebaseNotification({ title, body, data }, payload.device_tokens, notification.credentials);
|
|
2645
2832
|
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 }));
|
|
2646
2833
|
}
|
|
2647
|
-
async runNotification(notification, additional_logs) {
|
|
2648
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2834
|
+
async runNotification(notification, additional_logs, bootstrapData) {
|
|
2835
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2649
2836
|
const { event } = notification;
|
|
2650
2837
|
const input = notification.input;
|
|
2651
2838
|
try {
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
if
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2839
|
+
let notificationEvent;
|
|
2840
|
+
let message;
|
|
2841
|
+
let envConfig;
|
|
2842
|
+
// Use bootstrap data if provided, otherwise fetch via API
|
|
2843
|
+
if (bootstrapData) {
|
|
2844
|
+
notificationEvent = bootstrapData.notification;
|
|
2845
|
+
message = bootstrapData.message;
|
|
2846
|
+
envConfig = bootstrapData.env_config;
|
|
2847
|
+
}
|
|
2848
|
+
else {
|
|
2849
|
+
// Fallback to original API-based fetching
|
|
2850
|
+
notificationEvent = (await this.productBuilderService.fetchNotification(event.split(':')[0]));
|
|
2851
|
+
message = await this.productBuilderService.fetchNotificationMessage(event);
|
|
2852
|
+
if (!message) {
|
|
2853
|
+
throw new Error(`Message ${event} not found`);
|
|
2854
|
+
}
|
|
2855
|
+
envConfig = (_a = notificationEvent.envs) === null || _a === void 0 ? void 0 : _a.find((data) => data.slug === notification.env.slug);
|
|
2856
|
+
}
|
|
2857
|
+
if (!envConfig) {
|
|
2858
|
+
throw new Error(`Notification env config for ${notification.env.slug} not found`);
|
|
2859
|
+
}
|
|
2860
|
+
let { push_notifications: notifications, emails, callbacks, sms: smses, } = envConfig;
|
|
2861
|
+
// Resolve any $Secret{} references in notification configs
|
|
2862
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
2863
|
+
if (secretsService) {
|
|
2864
|
+
if (notifications && (0, secrets_1.mightContainSecrets)(notifications)) {
|
|
2865
|
+
const resolved = await secretsService.resolve(notifications, { env: notification.env.slug });
|
|
2866
|
+
notifications = resolved.value;
|
|
2867
|
+
}
|
|
2868
|
+
if (emails && (0, secrets_1.mightContainSecrets)(emails)) {
|
|
2869
|
+
const resolved = await secretsService.resolve(emails, { env: notification.env.slug });
|
|
2870
|
+
emails = resolved.value;
|
|
2871
|
+
}
|
|
2872
|
+
if (callbacks && (0, secrets_1.mightContainSecrets)(callbacks)) {
|
|
2873
|
+
const resolved = await secretsService.resolve(callbacks, { env: notification.env.slug });
|
|
2874
|
+
callbacks = resolved.value;
|
|
2875
|
+
}
|
|
2876
|
+
if (smses && (0, secrets_1.mightContainSecrets)(smses)) {
|
|
2877
|
+
const resolved = await secretsService.resolve(smses, { env: notification.env.slug });
|
|
2878
|
+
smses = resolved.value;
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2660
2881
|
const { push_notification: push, email, callback, sms } = message;
|
|
2661
2882
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching notification', data: notificationEvent, status: types_1.LogEventStatus.SUCCESS }));
|
|
2662
2883
|
if (push) {
|
|
@@ -2702,7 +2923,11 @@ class ProcessorService {
|
|
|
2702
2923
|
const templateMaker = (0, handlebars_1.compile)(email.template);
|
|
2703
2924
|
const template = templateMaker(input.email.template);
|
|
2704
2925
|
const subject = (0, processor_utils_1.replacePlaceholderString)(email.subject, input.email.subject || {});
|
|
2705
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - success', data: {
|
|
2926
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - success', data: {
|
|
2927
|
+
template: (0, processor_utils_1.anonymizeValue)(template),
|
|
2928
|
+
subject: (0, processor_utils_1.anonymizeValue)(subject),
|
|
2929
|
+
input: (0, processor_utils_1.anonymizeObject)(input.email),
|
|
2930
|
+
}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2706
2931
|
const mailOptions = {
|
|
2707
2932
|
from,
|
|
2708
2933
|
to: input.email.recipients,
|
|
@@ -2720,10 +2945,10 @@ class ProcessorService {
|
|
|
2720
2945
|
}
|
|
2721
2946
|
if (callback && callbacks) {
|
|
2722
2947
|
const payload = {
|
|
2723
|
-
query: Object.assign(Object.assign({}, (
|
|
2724
|
-
headers: Object.assign(Object.assign({}, (
|
|
2725
|
-
params: Object.assign(Object.assign({}, (
|
|
2726
|
-
body: Object.assign(Object.assign({}, (
|
|
2948
|
+
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),
|
|
2949
|
+
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),
|
|
2950
|
+
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),
|
|
2951
|
+
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),
|
|
2727
2952
|
};
|
|
2728
2953
|
input.callback.body = await this.generatePayload(payload.body, notification, additional_logs, message.callback_data.filter((data) => data.parent_key === 'body'));
|
|
2729
2954
|
input.callback.query = await this.generatePayload(payload.query, notification, additional_logs, message.callback_data.filter((data) => data.parent_key === 'query'));
|
|
@@ -2745,7 +2970,7 @@ class ProcessorService {
|
|
|
2745
2970
|
}
|
|
2746
2971
|
if (sms && smses) {
|
|
2747
2972
|
try {
|
|
2748
|
-
input.sms.body = await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body);
|
|
2973
|
+
input.sms.body = (await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body));
|
|
2749
2974
|
const SmsClient = await (0, sms_repo_1.loadSMSClient)();
|
|
2750
2975
|
const smsClient = new SmsClient(smses);
|
|
2751
2976
|
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 }));
|
|
@@ -2764,193 +2989,123 @@ class ProcessorService {
|
|
|
2764
2989
|
throw e;
|
|
2765
2990
|
}
|
|
2766
2991
|
}
|
|
2767
|
-
async runMigration(product_tag, tag, env, type) {
|
|
2768
|
-
try {
|
|
2769
|
-
this.productTag = product_tag;
|
|
2770
|
-
const [dbTag, migrationTag] = tag.split(':');
|
|
2771
|
-
if (!dbTag || !migrationTag) {
|
|
2772
|
-
throw new Error('tag should be in the format database_tag:migration_tag');
|
|
2773
|
-
}
|
|
2774
|
-
this.start = Date.now();
|
|
2775
|
-
const additional_logs = {
|
|
2776
|
-
parent_tag: dbTag,
|
|
2777
|
-
child_tag: migrationTag,
|
|
2778
|
-
type: types_1.LogEventTypes.DB_MIGRATION,
|
|
2779
|
-
name: 'Run Migration',
|
|
2780
|
-
};
|
|
2781
|
-
await this.intializeProduct(additional_logs);
|
|
2782
|
-
const db = this.productBuilderService.fetchDatabase(dbTag);
|
|
2783
|
-
if (!db) {
|
|
2784
|
-
throw new Error('Database not found');
|
|
2785
|
-
}
|
|
2786
|
-
if (db.type === types_1.DatabaseTypes.MONGODB) {
|
|
2787
|
-
throw new Error(`${db.type} does not support migrations`);
|
|
2788
|
-
}
|
|
2789
|
-
const migration = this.productBuilderService.fetchDatabaseMigration(tag);
|
|
2790
|
-
if (!migration) {
|
|
2791
|
-
throw new Error('Database migration not found');
|
|
2792
|
-
}
|
|
2793
|
-
const dbEnv = db.envs.find((el) => el.slug === env);
|
|
2794
|
-
if (!dbEnv) {
|
|
2795
|
-
throw new Error(`Environment ${env} not found`);
|
|
2796
|
-
}
|
|
2797
|
-
const productEnv = this.fetchEnv(env, additional_logs);
|
|
2798
|
-
if (!productEnv.active) {
|
|
2799
|
-
throw new Error(`Environment ${env} is not active`);
|
|
2800
|
-
}
|
|
2801
|
-
const product = this.productBuilderService.fetchProduct();
|
|
2802
|
-
const migrations = this.productBuilderService.fetchDatabaseMigrations(dbTag);
|
|
2803
|
-
//this.processEnv = productEnv;
|
|
2804
|
-
/* const check = migration.envs.find((migrationEnv) => migrationEnv.slug === env);
|
|
2805
|
-
if (!check) {
|
|
2806
|
-
throw new Error(`Migration does not exist for environment ${env}`);
|
|
2807
|
-
}*/
|
|
2808
|
-
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
2809
|
-
this.baseLogs = Object.assign({ product_tag: this.productTag, product_id: this.productId, workspace_id: this.workspace_id, env,
|
|
2810
|
-
process_id, data: { tag, env } }, additional_logs);
|
|
2811
|
-
const migrationsToRun = (0, processor_utils_1.getMigrationsToRun)((0, processor_utils_1.structuredClone)(migrations), type, migrationTag, env);
|
|
2812
|
-
if (db.type === types_1.DatabaseTypes.POSTGRES) {
|
|
2813
|
-
const PostgresDBHandler = await (0, postgres_repo_1.loadPostgresHandler)();
|
|
2814
|
-
const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(dbEnv.connection_url, product.private_key));
|
|
2815
|
-
for (const migrationToRun of migrationsToRun) {
|
|
2816
|
-
const envS = migration.envs.find((envT) => envT.slug === env && type === envT.type);
|
|
2817
|
-
if (envS && envS.status === types_1.MigrationStatus.PROCESSED) {
|
|
2818
|
-
continue;
|
|
2819
|
-
}
|
|
2820
|
-
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 }));
|
|
2821
|
-
const { type: migType, result, status, processed_at, } = await pgHandler.runMigration(migrationToRun.value[type], type, envS);
|
|
2822
|
-
if (!envS) {
|
|
2823
|
-
migrationToRun.envs.push({ slug: env, results: result, status, type, processed_at });
|
|
2824
|
-
}
|
|
2825
|
-
else {
|
|
2826
|
-
migrationToRun.envs.map((envT) => {
|
|
2827
|
-
if (envT.slug === env && type === envT.type) {
|
|
2828
|
-
envT.results = [...result];
|
|
2829
|
-
envT.processed_at = processed_at;
|
|
2830
|
-
return envT;
|
|
2831
|
-
}
|
|
2832
|
-
return envT;
|
|
2833
|
-
});
|
|
2834
|
-
}
|
|
2835
|
-
this.productBuilderService.updateDatabaseMigration(Object.assign(Object.assign({}, migrationToRun), { tag }));
|
|
2836
|
-
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 }));
|
|
2837
|
-
}
|
|
2838
|
-
return { process_id };
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
catch (e) {
|
|
2842
|
-
this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { failed_execution: true, message: 'Attempt migration - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
2843
|
-
await this.logService.publish();
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
2992
|
/*async runFunction(data: IFeatureEvent, additional_logs: Partial<ILogData>): Promise<any> {
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
});
|
|
2860
|
-
|
|
2861
|
-
const process_id = generateObjectId();
|
|
2862
|
-
this.process_id = process_id;
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
try {
|
|
2866
|
-
await this.intializeProduct(additional_logs);
|
|
2867
|
-
this.logService.add({
|
|
2868
|
-
...this.baseLogs,
|
|
2869
|
-
...additional_logs,
|
|
2870
|
-
message: 'Attempt function - initiated',
|
|
2871
|
-
data,
|
|
2872
|
-
status: LogEventStatus.PROCESSING,
|
|
2873
|
-
});
|
|
2874
|
-
|
|
2875
|
-
this.logService.add({
|
|
2876
|
-
...this.baseLogs,
|
|
2877
|
-
...additional_logs,
|
|
2878
|
-
message: 'Fetch function - initiated',
|
|
2879
|
-
data: data,
|
|
2880
|
-
status: LogEventStatus.PROCESSING,
|
|
2881
|
-
});
|
|
2882
|
-
|
|
2883
|
-
const cloudFunction = this.productBuilderService.fetchFunction(data.event);
|
|
2884
|
-
|
|
2885
|
-
this.logService.add({
|
|
2886
|
-
...this.baseLogs,
|
|
2887
|
-
...additional_logs,
|
|
2888
|
-
message: 'Fetch function - success',
|
|
2889
|
-
data: data,
|
|
2890
|
-
status: LogEventStatus.SUCCESS,
|
|
2891
|
-
});
|
|
2892
|
-
|
|
2893
|
-
this.logService.add({
|
|
2894
|
-
...this.baseLogs,
|
|
2895
|
-
...additional_logs,
|
|
2896
|
-
message: 'Validate function payload - initiated',
|
|
2897
|
-
data: { data, payload: input.payload },
|
|
2898
|
-
status: LogEventStatus.PROCESSING,
|
|
2899
|
-
});
|
|
2900
|
-
|
|
2901
|
-
validateFunctionInputKeys(cloudFunction.inputs, input.payload);
|
|
2902
|
-
|
|
2903
|
-
this.logService.add({
|
|
2904
|
-
...this.baseLogs,
|
|
2905
|
-
...additional_logs,
|
|
2906
|
-
message: 'Validate function payload - success',
|
|
2907
|
-
data: { data, payload: input.payload },
|
|
2908
|
-
status: LogEventStatus.SUCCESS,
|
|
2909
|
-
});
|
|
2910
|
-
|
|
2911
|
-
this.logService.add({
|
|
2912
|
-
...this.baseLogs,
|
|
2913
|
-
...additional_logs,
|
|
2914
|
-
message: 'Run function - initiated',
|
|
2915
|
-
data: { data, payload: input.payload },
|
|
2916
|
-
status: LogEventStatus.PROCESSING,
|
|
2917
|
-
});
|
|
2918
|
-
|
|
2919
|
-
const response = await makeFunctionsRequest(cloudFunction, input.payload);
|
|
2920
|
-
|
|
2921
|
-
this.logService.add({
|
|
2922
|
-
...this.baseLogs,
|
|
2923
|
-
...additional_logs,
|
|
2924
|
-
message: 'Run function - success',
|
|
2925
|
-
data: { data, payload: input.payload },
|
|
2926
|
-
status: LogEventStatus.SUCCESS,
|
|
2927
|
-
});
|
|
2928
|
-
} catch (e) {
|
|
2929
|
-
this.logService.add({
|
|
2930
|
-
...this.baseLogs,
|
|
2931
|
-
...additional_logs,
|
|
2932
|
-
message: 'Run function - failed',
|
|
2933
|
-
data: e,
|
|
2934
|
-
status: LogEventStatus.FAIL,
|
|
2993
|
+
const { product_id, env } = data;
|
|
2994
|
+
const input = data.input as IFunctionRequest;
|
|
2995
|
+
|
|
2996
|
+
this.productId = product_id;
|
|
2997
|
+
|
|
2998
|
+
this.logService = new LogsService({
|
|
2999
|
+
product_id,
|
|
3000
|
+
workspace_id: this.workspace_id,
|
|
3001
|
+
public_key: this.public_key,
|
|
3002
|
+
user_id: this.user_id,
|
|
3003
|
+
token: this.token,
|
|
3004
|
+
env_type: this.environment,
|
|
2935
3005
|
});
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
3006
|
+
|
|
3007
|
+
const process_id = generateObjectId();
|
|
3008
|
+
this.process_id = process_id;
|
|
3009
|
+
|
|
3010
|
+
|
|
3011
|
+
try {
|
|
3012
|
+
await this.intializeProduct(additional_logs);
|
|
3013
|
+
this.logService.add({
|
|
3014
|
+
...this.baseLogs,
|
|
3015
|
+
...additional_logs,
|
|
3016
|
+
message: 'Attempt function - initiated',
|
|
3017
|
+
data,
|
|
3018
|
+
status: LogEventStatus.PROCESSING,
|
|
3019
|
+
});
|
|
3020
|
+
|
|
3021
|
+
this.logService.add({
|
|
3022
|
+
...this.baseLogs,
|
|
3023
|
+
...additional_logs,
|
|
3024
|
+
message: 'Fetch function - initiated',
|
|
3025
|
+
data: data,
|
|
3026
|
+
status: LogEventStatus.PROCESSING,
|
|
3027
|
+
});
|
|
3028
|
+
|
|
3029
|
+
const cloudFunction = await this.productBuilderService.fetchFunction(data.event);
|
|
3030
|
+
|
|
3031
|
+
this.logService.add({
|
|
3032
|
+
...this.baseLogs,
|
|
3033
|
+
...additional_logs,
|
|
3034
|
+
message: 'Fetch function - success',
|
|
3035
|
+
data: data,
|
|
3036
|
+
status: LogEventStatus.SUCCESS,
|
|
3037
|
+
});
|
|
3038
|
+
|
|
3039
|
+
this.logService.add({
|
|
3040
|
+
...this.baseLogs,
|
|
3041
|
+
...additional_logs,
|
|
3042
|
+
message: 'Validate function payload - initiated',
|
|
3043
|
+
data: { data, payload: input.payload },
|
|
3044
|
+
status: LogEventStatus.PROCESSING,
|
|
3045
|
+
});
|
|
3046
|
+
|
|
3047
|
+
validateFunctionInputKeys(cloudFunction.inputs, input.payload);
|
|
3048
|
+
|
|
3049
|
+
this.logService.add({
|
|
3050
|
+
...this.baseLogs,
|
|
3051
|
+
...additional_logs,
|
|
3052
|
+
message: 'Validate function payload - success',
|
|
3053
|
+
data: { data, payload: input.payload },
|
|
3054
|
+
status: LogEventStatus.SUCCESS,
|
|
3055
|
+
});
|
|
3056
|
+
|
|
3057
|
+
this.logService.add({
|
|
3058
|
+
...this.baseLogs,
|
|
3059
|
+
...additional_logs,
|
|
3060
|
+
message: 'Run function - initiated',
|
|
3061
|
+
data: { data, payload: input.payload },
|
|
3062
|
+
status: LogEventStatus.PROCESSING,
|
|
3063
|
+
});
|
|
3064
|
+
|
|
3065
|
+
const response = await makeFunctionsRequest(cloudFunction, input.payload);
|
|
3066
|
+
|
|
3067
|
+
this.logService.add({
|
|
3068
|
+
...this.baseLogs,
|
|
3069
|
+
...additional_logs,
|
|
3070
|
+
message: 'Run function - success',
|
|
3071
|
+
data: { data, payload: input.payload },
|
|
3072
|
+
status: LogEventStatus.SUCCESS,
|
|
3073
|
+
});
|
|
3074
|
+
} catch (e) {
|
|
3075
|
+
this.logService.add({
|
|
3076
|
+
...this.baseLogs,
|
|
3077
|
+
...additional_logs,
|
|
3078
|
+
message: 'Run function - failed',
|
|
3079
|
+
data: e,
|
|
3080
|
+
status: LogEventStatus.FAIL,
|
|
3081
|
+
});
|
|
3082
|
+
await this.logService.publish();
|
|
3083
|
+
}
|
|
3084
|
+
}*/
|
|
3085
|
+
async runStorage(data, additional_logs = {}, bootstrapData) {
|
|
2940
3086
|
const { product_id, env, event, cache: cache_tag } = data;
|
|
2941
3087
|
const input = data.input;
|
|
2942
3088
|
try {
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
3089
|
+
let storage;
|
|
3090
|
+
let storageEnv;
|
|
3091
|
+
// Use bootstrap data if provided, otherwise fetch via API
|
|
3092
|
+
if (bootstrapData) {
|
|
3093
|
+
storage = bootstrapData.storage;
|
|
3094
|
+
storageEnv = bootstrapData.storage_env;
|
|
3095
|
+
}
|
|
3096
|
+
else {
|
|
3097
|
+
// Fallback to original API-based fetching
|
|
3098
|
+
await this.intializeProduct(additional_logs);
|
|
3099
|
+
storage = await this.productBuilderService.fetchStorage(event);
|
|
3100
|
+
storageEnv = storage.envs.find((el) => el.slug === env.slug);
|
|
3101
|
+
}
|
|
2946
3102
|
if (!storageEnv) {
|
|
2947
3103
|
throw new Error(`Storage env for ${env.slug} not found`);
|
|
2948
3104
|
}
|
|
2949
3105
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch storage details - success', data: { storage }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2950
|
-
const product = this.productBuilderService.fetchProduct();
|
|
2951
3106
|
let result;
|
|
2952
3107
|
if (cache_tag && this.redisClient) {
|
|
2953
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
3108
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
2954
3109
|
if (!productCache) {
|
|
2955
3110
|
throw new Error('Invalid cache tag ');
|
|
2956
3111
|
}
|
|
@@ -2958,7 +3113,7 @@ class ProcessorService {
|
|
|
2958
3113
|
const check = await this.fetchFromCache({
|
|
2959
3114
|
cache_tag,
|
|
2960
3115
|
input: inputString,
|
|
2961
|
-
privateKey:
|
|
3116
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
2962
3117
|
expiry: productCache.expiry,
|
|
2963
3118
|
}, additional_logs);
|
|
2964
3119
|
if (check) {
|
|
@@ -2968,18 +3123,23 @@ class ProcessorService {
|
|
|
2968
3123
|
}
|
|
2969
3124
|
}
|
|
2970
3125
|
input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
|
|
2971
|
-
input.fileName = input.fileName
|
|
2972
|
-
|
|
3126
|
+
input.fileName = input.fileName
|
|
3127
|
+
? await this.generateStringValues(input.fileName, '', additional_logs, [])
|
|
3128
|
+
: undefined;
|
|
3129
|
+
input.mimeType = input.mimeType
|
|
3130
|
+
? await this.generateStringValues(input.mimeType, '', additional_logs, [])
|
|
3131
|
+
: undefined;
|
|
2973
3132
|
result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
|
|
2974
3133
|
if (cache_tag && this.redisClient) {
|
|
2975
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
3134
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
2976
3135
|
if (!productCache) {
|
|
2977
3136
|
throw new Error('Invalid cache tag ');
|
|
2978
3137
|
}
|
|
2979
3138
|
const inputString = JSON.stringify(input);
|
|
2980
|
-
|
|
3139
|
+
// Fire-and-forget cache store
|
|
3140
|
+
this.addToCache({
|
|
2981
3141
|
input: inputString,
|
|
2982
|
-
privateKey:
|
|
3142
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
2983
3143
|
data: JSON.stringify(result),
|
|
2984
3144
|
cache_tag,
|
|
2985
3145
|
timestamp: Date.now(),
|
|
@@ -2994,131 +3154,13 @@ class ProcessorService {
|
|
|
2994
3154
|
throw e;
|
|
2995
3155
|
}
|
|
2996
3156
|
}
|
|
2997
|
-
async runDBAction(db_action, additional_logs = {}) {
|
|
2998
|
-
const { product_id, env, event, cache: cache_tag } = db_action;
|
|
2999
|
-
const input = db_action.input;
|
|
3000
|
-
try {
|
|
3001
|
-
//await this.intializeProduct(additional_logs);
|
|
3002
|
-
const [database_tag, action_tag] = event.split(':');
|
|
3003
|
-
const product = this.productBuilderService.fetchProduct();
|
|
3004
|
-
const database = await this.productBuilderService.fetchDatabase(database_tag);
|
|
3005
|
-
const databaseAction = await this.productBuilderService.fetchDatabaseAction(event);
|
|
3006
|
-
const databaseEnv = database.envs.find((el) => el.slug === env.slug);
|
|
3007
|
-
if (!databaseEnv) {
|
|
3008
|
-
throw new Error(`Database env for ${env.slug} not found`);
|
|
3009
|
-
}
|
|
3010
|
-
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 }));
|
|
3011
|
-
input.data = await this.generatePayload(input.data, db_action, additional_logs, databaseAction.data);
|
|
3012
|
-
if (Array.isArray(input.data)) {
|
|
3013
|
-
await Promise.all(input.data.map(async (d) => {
|
|
3014
|
-
const dataValidationPayload = (await this.inputService.parseJson({
|
|
3015
|
-
data: d,
|
|
3016
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
3017
|
-
}));
|
|
3018
|
-
this.inputService.validateInput(dataValidationPayload, databaseAction.data);
|
|
3019
|
-
}));
|
|
3020
|
-
}
|
|
3021
|
-
else {
|
|
3022
|
-
const dataValidationPayload = (await this.inputService.parseJson({
|
|
3023
|
-
data: input.data,
|
|
3024
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
3025
|
-
}));
|
|
3026
|
-
this.inputService.validateInput(dataValidationPayload, databaseAction.data);
|
|
3027
|
-
if (input.filter) {
|
|
3028
|
-
const filterValidationPayload = (await this.inputService.parseJson({
|
|
3029
|
-
data: input.filter,
|
|
3030
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
3031
|
-
}));
|
|
3032
|
-
this.inputService.validateInput(filterValidationPayload, databaseAction.filterData);
|
|
3033
|
-
}
|
|
3034
|
-
}
|
|
3035
|
-
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 }));
|
|
3036
|
-
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
3037
|
-
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
3038
|
-
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 }));
|
|
3039
|
-
}
|
|
3040
|
-
}
|
|
3041
|
-
let result;
|
|
3042
|
-
if (cache_tag && this.redisClient) {
|
|
3043
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
3044
|
-
if (!productCache) {
|
|
3045
|
-
throw new Error('Invalid cache tag ');
|
|
3046
|
-
}
|
|
3047
|
-
const inputString = JSON.stringify(input);
|
|
3048
|
-
const check = await this.fetchFromCache({
|
|
3049
|
-
cache_tag,
|
|
3050
|
-
input: inputString,
|
|
3051
|
-
privateKey: product.private_key,
|
|
3052
|
-
expiry: productCache.expiry,
|
|
3053
|
-
}, additional_logs);
|
|
3054
|
-
if (check) {
|
|
3055
|
-
result = JSON.parse(check);
|
|
3056
|
-
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 }));
|
|
3057
|
-
return result;
|
|
3058
|
-
}
|
|
3059
|
-
}
|
|
3060
|
-
const template = typeof databaseAction.template === 'string' ? databaseAction.template : JSON.stringify(databaseAction.template);
|
|
3061
|
-
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
3062
|
-
const MongoDBHandler = await (0, mongo_repo_1.loadMongoDbHandler)();
|
|
3063
|
-
if (!MongoDBHandler) {
|
|
3064
|
-
throw new Error(`Running in browser, mongo handler not loaded.`);
|
|
3065
|
-
}
|
|
3066
|
-
const mongoHandler = new MongoDBHandler(databaseEnv.connection_url);
|
|
3067
|
-
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
3068
|
-
const filterTemplate = typeof databaseAction.filterTemplate === 'string'
|
|
3069
|
-
? databaseAction.filterTemplate
|
|
3070
|
-
: JSON.stringify(databaseAction.filterTemplate);
|
|
3071
|
-
result = await mongoHandler[databaseAction.type](databaseAction.data, template, input.data, databaseAction.tableName, databaseAction.filterData, filterTemplate, input.filter);
|
|
3072
|
-
}
|
|
3073
|
-
else {
|
|
3074
|
-
result = await mongoHandler[databaseAction.type](databaseAction.data, template, input.data, databaseAction.tableName);
|
|
3075
|
-
}
|
|
3076
|
-
}
|
|
3077
|
-
else if (database.type === types_1.DatabaseTypes.POSTGRES) {
|
|
3078
|
-
const PostgresDBHandler = await (0, postgres_repo_1.loadPostgresHandler)();
|
|
3079
|
-
if (!PostgresDBHandler) {
|
|
3080
|
-
throw new Error(`Running in browser, postgres handler not loaded.`);
|
|
3081
|
-
}
|
|
3082
|
-
const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchProduct().private_key));
|
|
3083
|
-
if (databaseAction.type !== types_1.DatabaseActionTypes.AGGREGATE) {
|
|
3084
|
-
result = await pgHandler[databaseAction.type](databaseAction.data, template, input.data);
|
|
3085
|
-
}
|
|
3086
|
-
}
|
|
3087
|
-
//await this.logService.publish();
|
|
3088
|
-
// const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
|
|
3089
|
-
await this.addToSuccessOutput(db_action, result, additional_logs);
|
|
3090
|
-
if (cache_tag && this.redisClient) {
|
|
3091
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
3092
|
-
if (!productCache) {
|
|
3093
|
-
throw new Error('Invalid cache tag ');
|
|
3094
|
-
}
|
|
3095
|
-
const inputString = JSON.stringify(input);
|
|
3096
|
-
await this.addToCache({
|
|
3097
|
-
input: inputString,
|
|
3098
|
-
privateKey: product.private_key,
|
|
3099
|
-
data: JSON.stringify(result),
|
|
3100
|
-
cache_tag,
|
|
3101
|
-
timestamp: Date.now(),
|
|
3102
|
-
product_tag: this.productTag,
|
|
3103
|
-
component_tag: database_tag,
|
|
3104
|
-
component_type: types_1.ProductComponents.DATABASE_ACTION,
|
|
3105
|
-
}, additional_logs);
|
|
3106
|
-
}
|
|
3107
|
-
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 }));
|
|
3108
|
-
return result;
|
|
3109
|
-
}
|
|
3110
|
-
catch (e) {
|
|
3111
|
-
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 }));
|
|
3112
|
-
throw e;
|
|
3113
|
-
}
|
|
3114
|
-
}
|
|
3115
3157
|
async runBrokerSubscribe(data, additional_logs = {}) {
|
|
3116
3158
|
const { env, event } = data;
|
|
3117
3159
|
const input = data.input;
|
|
3118
3160
|
try {
|
|
3119
3161
|
await this.intializeProduct(additional_logs);
|
|
3120
3162
|
const [brokerTag, topicTag] = event.split(':');
|
|
3121
|
-
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
3163
|
+
const broker = await this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
3122
3164
|
if (!broker) {
|
|
3123
3165
|
throw new Error(`Message Broker ${brokerTag} not found`);
|
|
3124
3166
|
}
|
|
@@ -3126,7 +3168,7 @@ class ProcessorService {
|
|
|
3126
3168
|
if (!brokerEnv) {
|
|
3127
3169
|
throw new Error(`Broker env for ${env.slug} not found`);
|
|
3128
3170
|
}
|
|
3129
|
-
const topic = this.productBuilderService.fetchMessageBrokerTopic(event);
|
|
3171
|
+
const topic = await this.productBuilderService.fetchMessageBrokerTopic(event);
|
|
3130
3172
|
if (!topic) {
|
|
3131
3173
|
throw new Error(`Topic ${topicTag} not found in broker ${brokerTag}`);
|
|
3132
3174
|
}
|
|
@@ -3146,9 +3188,7 @@ class ProcessorService {
|
|
|
3146
3188
|
if (createBrokerService) {
|
|
3147
3189
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
3148
3190
|
await brokerService.subscribe(url, input.callback);
|
|
3149
|
-
|
|
3150
|
-
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 }));
|
|
3151
|
-
}
|
|
3191
|
+
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 }));
|
|
3152
3192
|
return;
|
|
3153
3193
|
}
|
|
3154
3194
|
else {
|
|
@@ -3167,7 +3207,7 @@ class ProcessorService {
|
|
|
3167
3207
|
try {
|
|
3168
3208
|
await this.intializeProduct(additional_logs);
|
|
3169
3209
|
const [brokerTag, topicTag] = event.split(':');
|
|
3170
|
-
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
3210
|
+
const broker = await this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
3171
3211
|
if (!broker) {
|
|
3172
3212
|
throw new Error(`Message Broker ${brokerTag} not found`);
|
|
3173
3213
|
}
|
|
@@ -3175,7 +3215,7 @@ class ProcessorService {
|
|
|
3175
3215
|
if (!brokerEnv) {
|
|
3176
3216
|
throw new Error(`Broker env for ${env.slug} not found`);
|
|
3177
3217
|
}
|
|
3178
|
-
const topic = this.productBuilderService.fetchMessageBrokerTopic(event);
|
|
3218
|
+
const topic = await this.productBuilderService.fetchMessageBrokerTopic(event);
|
|
3179
3219
|
if (!topic) {
|
|
3180
3220
|
throw new Error(`Topic ${topicTag} not found in broker ${brokerTag}`);
|
|
3181
3221
|
}
|
|
@@ -3195,9 +3235,7 @@ class ProcessorService {
|
|
|
3195
3235
|
if (createBrokerService) {
|
|
3196
3236
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
3197
3237
|
await brokerService.publish(url, input.message);
|
|
3198
|
-
|
|
3199
|
-
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 }));
|
|
3200
|
-
}
|
|
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 }));
|
|
3201
3239
|
return;
|
|
3202
3240
|
}
|
|
3203
3241
|
else {
|
|
@@ -3239,7 +3277,7 @@ class ProcessorService {
|
|
|
3239
3277
|
const result = { url: await (0, storage_util_1.uploadBlobToCloud)({ data: input.buffer, destinationPath: input.fileName, config }) };
|
|
3240
3278
|
try {
|
|
3241
3279
|
await this.processorApiService.saveFileURL({
|
|
3242
|
-
url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.
|
|
3280
|
+
url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchPrivateKey()),
|
|
3243
3281
|
provider: storageEnv.type,
|
|
3244
3282
|
product: this.productTag,
|
|
3245
3283
|
process_id: this.process_id,
|
|
@@ -3247,7 +3285,7 @@ class ProcessorService {
|
|
|
3247
3285
|
type: input.mimeType,
|
|
3248
3286
|
event: data.event,
|
|
3249
3287
|
env: data.env.slug,
|
|
3250
|
-
size: Buffer.from(input.buffer).length
|
|
3288
|
+
size: Buffer.from(input.buffer).length,
|
|
3251
3289
|
}, this.getUserAccess());
|
|
3252
3290
|
}
|
|
3253
3291
|
catch (e) { }
|
|
@@ -3264,35 +3302,6 @@ class ProcessorService {
|
|
|
3264
3302
|
throw e;
|
|
3265
3303
|
}
|
|
3266
3304
|
}
|
|
3267
|
-
async processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs, returnValue = false) {
|
|
3268
|
-
try {
|
|
3269
|
-
const result = await this.processorApiService.processProduct(this.productId, {
|
|
3270
|
-
input: input,
|
|
3271
|
-
database_tag: database_tag,
|
|
3272
|
-
database_env_slug: databaseEnv.slug,
|
|
3273
|
-
tag: action_tag,
|
|
3274
|
-
component: types_1.ProductComponents.DATABASE_ACTION,
|
|
3275
|
-
}, {
|
|
3276
|
-
user_id: this.user_id,
|
|
3277
|
-
token: this.token,
|
|
3278
|
-
workspace_id: this.workspace_id,
|
|
3279
|
-
public_key: this.public_key,
|
|
3280
|
-
});
|
|
3281
|
-
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 }));
|
|
3282
|
-
return result;
|
|
3283
|
-
}
|
|
3284
|
-
catch (e) {
|
|
3285
|
-
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 }));
|
|
3286
|
-
const value = await this.addToFailureOutput(e, db_action, {
|
|
3287
|
-
db_action,
|
|
3288
|
-
input,
|
|
3289
|
-
database_tag,
|
|
3290
|
-
databaseEnv,
|
|
3291
|
-
action_tag,
|
|
3292
|
-
}, additional_logs);
|
|
3293
|
-
return value;
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
3305
|
async writeResult(status, retryable = true) {
|
|
3297
3306
|
this.processorApiService.saveResult({
|
|
3298
3307
|
status,
|
|
@@ -3300,14 +3309,108 @@ class ProcessorService {
|
|
|
3300
3309
|
start: this.start,
|
|
3301
3310
|
end: this.end,
|
|
3302
3311
|
retryable,
|
|
3303
|
-
result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.
|
|
3312
|
+
result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchPrivateKey()),
|
|
3304
3313
|
process_id: this.process_id,
|
|
3305
|
-
feature_id:
|
|
3314
|
+
feature_id: null,
|
|
3306
3315
|
product_id: this.productId,
|
|
3307
3316
|
env: this.processEnv.slug,
|
|
3308
|
-
input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.
|
|
3317
|
+
input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchPrivateKey()),
|
|
3309
3318
|
}, this.getUserAccess());
|
|
3310
3319
|
}
|
|
3320
|
+
/**
|
|
3321
|
+
* Separate credentials into prefixed (e.g., 'headers:Authorization') and non-prefixed (e.g., 'api_key').
|
|
3322
|
+
* Prefixed credentials are applied directly to the correct section after resolution.
|
|
3323
|
+
* Non-prefixed credentials go through InputResolver to determine their placement.
|
|
3324
|
+
*/
|
|
3325
|
+
separateCredentials(credentials) {
|
|
3326
|
+
const prefixed = {};
|
|
3327
|
+
const nonPrefixed = {};
|
|
3328
|
+
for (const [key, value] of Object.entries(credentials)) {
|
|
3329
|
+
if (key.startsWith('headers:') || key.startsWith('body:') ||
|
|
3330
|
+
key.startsWith('params:') || key.startsWith('query:')) {
|
|
3331
|
+
prefixed[key] = value;
|
|
3332
|
+
}
|
|
3333
|
+
else {
|
|
3334
|
+
nonPrefixed[key] = value;
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
return { prefixed, nonPrefixed };
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* Check if a key exists in the action schema for a given section (headers, body, params, query).
|
|
3341
|
+
* Returns true if the key is defined in the schema, false otherwise.
|
|
3342
|
+
*/
|
|
3343
|
+
isKeyInActionSchema(action, section, key) {
|
|
3344
|
+
if (!action)
|
|
3345
|
+
return false;
|
|
3346
|
+
const sectionSchema = action[section];
|
|
3347
|
+
if (!sectionSchema || !sectionSchema.data)
|
|
3348
|
+
return false;
|
|
3349
|
+
// Check if the key exists in the schema's data array
|
|
3350
|
+
return sectionSchema.data.some(item => item.key === key);
|
|
3351
|
+
}
|
|
3352
|
+
/**
|
|
3353
|
+
* Apply prefixed credentials (e.g., 'headers:Authorization') to resolved input.
|
|
3354
|
+
* Credentials are applied with lower priority - existing values in resolvedInput take precedence.
|
|
3355
|
+
* Only applies credentials if the action schema defines the corresponding field.
|
|
3356
|
+
*/
|
|
3357
|
+
applyPrefixedCredentials(credentials, resolvedInput, action) {
|
|
3358
|
+
const result = {
|
|
3359
|
+
body: Object.assign({}, (resolvedInput.body || {})),
|
|
3360
|
+
params: Object.assign({}, (resolvedInput.params || {})),
|
|
3361
|
+
query: Object.assign({}, (resolvedInput.query || {})),
|
|
3362
|
+
headers: Object.assign({}, (resolvedInput.headers || {})),
|
|
3363
|
+
};
|
|
3364
|
+
for (const [key, value] of Object.entries(credentials)) {
|
|
3365
|
+
if (key.startsWith('headers:')) {
|
|
3366
|
+
const headerKey = key.substring(8); // Remove 'headers:' prefix
|
|
3367
|
+
// Only apply if the action schema expects this header field
|
|
3368
|
+
if (!this.isKeyInActionSchema(action, 'headers', headerKey)) {
|
|
3369
|
+
continue; // Skip - action doesn't expect this credential
|
|
3370
|
+
}
|
|
3371
|
+
// Only set if not already present (user input takes precedence)
|
|
3372
|
+
if (!(headerKey in (result.headers || {}))) {
|
|
3373
|
+
result.headers = result.headers || {};
|
|
3374
|
+
result.headers[headerKey] = value;
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
else if (key.startsWith('body:')) {
|
|
3378
|
+
const bodyKey = key.substring(5); // Remove 'body:' prefix
|
|
3379
|
+
// Only apply if the action schema expects this body field
|
|
3380
|
+
if (!this.isKeyInActionSchema(action, 'body', bodyKey)) {
|
|
3381
|
+
continue; // Skip - action doesn't expect this credential
|
|
3382
|
+
}
|
|
3383
|
+
if (!(bodyKey in (result.body || {}))) {
|
|
3384
|
+
result.body = result.body || {};
|
|
3385
|
+
result.body[bodyKey] = value;
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
else if (key.startsWith('params:')) {
|
|
3389
|
+
const paramsKey = key.substring(7); // Remove 'params:' prefix
|
|
3390
|
+
// Only apply if the action schema expects this params field
|
|
3391
|
+
if (!this.isKeyInActionSchema(action, 'params', paramsKey)) {
|
|
3392
|
+
continue; // Skip - action doesn't expect this credential
|
|
3393
|
+
}
|
|
3394
|
+
if (!(paramsKey in (result.params || {}))) {
|
|
3395
|
+
result.params = result.params || {};
|
|
3396
|
+
result.params[paramsKey] = value;
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3399
|
+
else if (key.startsWith('query:')) {
|
|
3400
|
+
const queryKey = key.substring(6); // Remove 'query:' prefix
|
|
3401
|
+
// Only apply if the action schema expects this query field
|
|
3402
|
+
if (!this.isKeyInActionSchema(action, 'query', queryKey)) {
|
|
3403
|
+
continue; // Skip - action doesn't expect this credential
|
|
3404
|
+
}
|
|
3405
|
+
if (!(queryKey in (result.query || {}))) {
|
|
3406
|
+
result.query = result.query || {};
|
|
3407
|
+
result.query[queryKey] = value;
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
// Ignore keys without recognized prefixes - credentials should always be prefixed
|
|
3411
|
+
}
|
|
3412
|
+
return result;
|
|
3413
|
+
}
|
|
3311
3414
|
async validateActionDataMappingInput(input, type) {
|
|
3312
3415
|
try {
|
|
3313
3416
|
if (type === types_1.FeatureEventTypes.ACTION || type === types_1.WebhookEventTypes.WEBHOOK_REGISTER) {
|
|
@@ -3327,7 +3430,7 @@ class ProcessorService {
|
|
|
3327
3430
|
}
|
|
3328
3431
|
async processAction(action) {
|
|
3329
3432
|
//TODO: schema validation
|
|
3330
|
-
const { env, input, retries, event, app, product: product_tag } = action;
|
|
3433
|
+
const { env, input, retries, action: event, app, product: product_tag, session, cache } = action;
|
|
3331
3434
|
const additional_logs = {
|
|
3332
3435
|
parent_tag: (0, string_utils_1.extractOriginAndTag)(app),
|
|
3333
3436
|
child_tag: event,
|
|
@@ -3335,39 +3438,168 @@ class ProcessorService {
|
|
|
3335
3438
|
name: 'Process Action',
|
|
3336
3439
|
};
|
|
3337
3440
|
this.component = types_1.LogEventTypes.ACTION;
|
|
3441
|
+
// Session log fields (will be populated if session is provided)
|
|
3442
|
+
let sessionLogFields = {};
|
|
3443
|
+
let resolvedInput = input;
|
|
3338
3444
|
try {
|
|
3339
|
-
// validate input do not allow $Sequence or $Length and $Size of $Input
|
|
3340
|
-
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3341
3445
|
this.input = action;
|
|
3342
3446
|
this.start = Date.now();
|
|
3343
|
-
this.productTag = product_tag;
|
|
3344
3447
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
3448
|
+
if (product_tag) {
|
|
3449
|
+
this.productTag = product_tag;
|
|
3450
|
+
}
|
|
3345
3451
|
this.baseLogs = {
|
|
3346
|
-
product_tag: this.productTag,
|
|
3452
|
+
product_tag: this.productTag || '',
|
|
3347
3453
|
workspace_id: this.workspace_id,
|
|
3348
3454
|
env,
|
|
3349
3455
|
type: types_1.LogEventTypes.ACTION,
|
|
3350
3456
|
process_id,
|
|
3351
3457
|
data: input,
|
|
3352
3458
|
};
|
|
3353
|
-
await this.intializeProduct(additional_logs);
|
|
3354
3459
|
this.process_id = process_id;
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3460
|
+
// Initialize log service early to ensure error handling works
|
|
3461
|
+
if (!this.logService) {
|
|
3462
|
+
this.logService = new logs_service_1.default({
|
|
3463
|
+
product_id: this.productId,
|
|
3464
|
+
workspace_id: this.workspace_id,
|
|
3465
|
+
public_key: this.public_key,
|
|
3466
|
+
user_id: this.user_id,
|
|
3467
|
+
token: this.token,
|
|
3468
|
+
env_type: this.environment,
|
|
3469
|
+
});
|
|
3470
|
+
}
|
|
3471
|
+
// Early cache check - before expensive bootstrap/API calls
|
|
3472
|
+
if (cache && this.redisClient) {
|
|
3473
|
+
const productCache = await this.productBuilderService.fetchCache(cache);
|
|
3474
|
+
if (productCache) {
|
|
3475
|
+
const inputString = JSON.stringify(input);
|
|
3476
|
+
const cachedResult = await this.fetchFromCache({
|
|
3477
|
+
cache_tag: cache,
|
|
3478
|
+
input: inputString,
|
|
3479
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
3480
|
+
expiry: productCache.expiry,
|
|
3481
|
+
}, additional_logs);
|
|
3482
|
+
if (cachedResult) {
|
|
3483
|
+
const result = JSON.parse(cachedResult);
|
|
3484
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Action response from cache (early check)', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS, cache_tag: cache, action: event }));
|
|
3485
|
+
this.end = Date.now();
|
|
3486
|
+
await this.logService.publish();
|
|
3487
|
+
return result;
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
// Single ultra-lightweight bootstrap call - returns action data directly
|
|
3492
|
+
const bootstrapData = await this.productBuilderService.bootstrapAction({
|
|
3493
|
+
product_tag,
|
|
3494
|
+
env_slug: env,
|
|
3495
|
+
access_tag: app,
|
|
3496
|
+
action_tag: event,
|
|
3497
|
+
});
|
|
3498
|
+
// Initialize from bootstrap data
|
|
3499
|
+
if (bootstrapData.product_id) {
|
|
3500
|
+
this.productId = bootstrapData.product_id;
|
|
3501
|
+
}
|
|
3502
|
+
// Resolve flat input to structured format using action schema
|
|
3503
|
+
// This must happen AFTER bootstrap when we have the action schema
|
|
3504
|
+
if (bootstrapData.action && input && typeof input === 'object') {
|
|
3505
|
+
if (!(0, utils_1.isStructuredInput)(input)) {
|
|
3506
|
+
// Flat input detected - resolve using action schema
|
|
3507
|
+
let flatInput = Object.assign({}, input);
|
|
3508
|
+
// Gather all credentials (static + OAuth)
|
|
3509
|
+
// Priority: user input > OAuth > static config
|
|
3510
|
+
const allCredentials = {};
|
|
3511
|
+
// Static credentials (lowest priority)
|
|
3512
|
+
const sharedCredentials = credential_manager_1.credentialManager.get({ product: product_tag, app, env });
|
|
3513
|
+
if (sharedCredentials) {
|
|
3514
|
+
Object.assign(allCredentials, sharedCredentials);
|
|
3515
|
+
}
|
|
3516
|
+
// OAuth credentials (higher priority, overwrites static)
|
|
3517
|
+
if (product_tag && oauth_manager_1.oauthManager.has(product_tag, app, env)) {
|
|
3518
|
+
const oauthCredentials = await oauth_manager_1.oauthManager.getCredentials(product_tag, app, env);
|
|
3519
|
+
if (oauthCredentials) {
|
|
3520
|
+
Object.assign(allCredentials, oauthCredentials);
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
// Separate credentials into prefixed and non-prefixed
|
|
3524
|
+
const { prefixed, nonPrefixed } = this.separateCredentials(allCredentials);
|
|
3525
|
+
const inputResolver = new utils_1.InputResolver();
|
|
3526
|
+
// Build location map to check which keys exist in the schema
|
|
3527
|
+
const locationMap = inputResolver.buildLocationMap(bootstrapData.action);
|
|
3528
|
+
// Merge non-prefixed credentials into flatInput BEFORE resolution
|
|
3529
|
+
// Only include credentials that exist in the action schema
|
|
3530
|
+
// User input takes precedence over credentials
|
|
3531
|
+
for (const [key, value] of Object.entries(nonPrefixed)) {
|
|
3532
|
+
// Skip if user already provided this key
|
|
3533
|
+
if (key in flatInput) {
|
|
3534
|
+
continue;
|
|
3535
|
+
}
|
|
3536
|
+
// Only include if the key exists in the action schema
|
|
3537
|
+
if (locationMap.allValidKeys.has(key)) {
|
|
3538
|
+
flatInput[key] = value;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
try {
|
|
3542
|
+
resolvedInput = inputResolver.resolve(flatInput, bootstrapData.action, { strict: true });
|
|
3543
|
+
}
|
|
3544
|
+
catch (e) {
|
|
3545
|
+
if (e instanceof utils_1.InputResolutionError) {
|
|
3546
|
+
throw new Error(`Input resolution failed for action '${event}': ${e.message}`);
|
|
3547
|
+
}
|
|
3548
|
+
throw e;
|
|
3549
|
+
}
|
|
3550
|
+
// Apply prefixed credentials AFTER resolution (directly to correct section)
|
|
3551
|
+
// Only credentials that match fields in the action schema are applied
|
|
3552
|
+
if (Object.keys(prefixed).length > 0) {
|
|
3553
|
+
resolvedInput = this.applyPrefixedCredentials(prefixed, resolvedInput, bootstrapData.action);
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
else {
|
|
3557
|
+
// Already structured - validate with existing schema
|
|
3558
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
else {
|
|
3562
|
+
// Fallback: validate with existing schema if no action bootstrap data
|
|
3563
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3564
|
+
}
|
|
3565
|
+
// Process session if provided - verify and resolve $Session{} references
|
|
3566
|
+
if (session && bootstrapData.private_key) {
|
|
3567
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../../sessions')));
|
|
3568
|
+
const sessionResult = await processSessionForExecution(session, bootstrapData.private_key, resolvedInput, env, {
|
|
3569
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
3570
|
+
const sessionConfig = await this.productBuilderService.fetchSession(sessionTag);
|
|
3571
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
3572
|
+
},
|
|
3573
|
+
});
|
|
3574
|
+
if (sessionResult.error) {
|
|
3575
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
3576
|
+
}
|
|
3577
|
+
resolvedInput = sessionResult.input;
|
|
3578
|
+
sessionLogFields = sessionResult.logFields;
|
|
3360
3579
|
}
|
|
3580
|
+
// Update log service with product_id from bootstrap
|
|
3581
|
+
this.baseLogs.product_id = this.productId;
|
|
3582
|
+
// Add session fields to base logs
|
|
3583
|
+
this.baseLogs = Object.assign(Object.assign({}, this.baseLogs), sessionLogFields);
|
|
3584
|
+
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 }));
|
|
3361
3585
|
const result = await this.runAction({
|
|
3362
3586
|
type: types_1.FeatureEventTypes.ACTION,
|
|
3363
3587
|
event,
|
|
3364
|
-
cache:
|
|
3588
|
+
cache: cache,
|
|
3589
|
+
skipCacheFetch: true, // Early cache check already done above, skip duplicate fetch
|
|
3365
3590
|
app,
|
|
3366
|
-
input,
|
|
3367
|
-
env:
|
|
3591
|
+
input: resolvedInput,
|
|
3592
|
+
env: this.processEnv,
|
|
3368
3593
|
retries: retries || 0,
|
|
3369
3594
|
allow_fail: false,
|
|
3370
|
-
|
|
3595
|
+
hasProduct: !!product_tag,
|
|
3596
|
+
}, additional_logs, true, {
|
|
3597
|
+
action: bootstrapData.action,
|
|
3598
|
+
app_env: bootstrapData.app_env,
|
|
3599
|
+
retries: bootstrapData.retries,
|
|
3600
|
+
app_active: bootstrapData.app_active,
|
|
3601
|
+
recipient_workspace_id: bootstrapData.recipient_workspace_id,
|
|
3602
|
+
});
|
|
3371
3603
|
this.end = Date.now();
|
|
3372
3604
|
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 }));
|
|
3373
3605
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
@@ -3375,71 +3607,19 @@ class ProcessorService {
|
|
|
3375
3607
|
return result;
|
|
3376
3608
|
}
|
|
3377
3609
|
catch (e) {
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
return { process_id: this.process_id };
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
async processDBAction(action) {
|
|
3387
|
-
//TODO: schema validation
|
|
3388
|
-
const { env, input, retries, event, product: product_tag } = action;
|
|
3389
|
-
const [parent_tag, child_tag] = event.split(':');
|
|
3390
|
-
this.component = types_1.LogEventTypes.DB_ACTION;
|
|
3391
|
-
if (!parent_tag || !child_tag) {
|
|
3392
|
-
throw new Error(`database action events should be in the format notification_tag:message_tag`);
|
|
3393
|
-
}
|
|
3394
|
-
const additional_logs = {
|
|
3395
|
-
parent_tag,
|
|
3396
|
-
child_tag,
|
|
3397
|
-
type: types_1.LogEventTypes.DB_ACTION,
|
|
3398
|
-
name: 'Process database action',
|
|
3399
|
-
};
|
|
3400
|
-
try {
|
|
3401
|
-
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3402
|
-
this.input = action;
|
|
3403
|
-
this.start = Date.now();
|
|
3404
|
-
this.productTag = product_tag;
|
|
3405
|
-
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
3406
|
-
this.baseLogs = Object.assign({ product_tag: this.productTag, workspace_id: this.workspace_id, env,
|
|
3407
|
-
process_id, data: input }, additional_logs);
|
|
3408
|
-
await this.intializeProduct(additional_logs);
|
|
3409
|
-
this.baseLogs.product_id = this.productId;
|
|
3410
|
-
this.process_id = process_id;
|
|
3411
|
-
const productEnv = this.fetchEnv(env, additional_logs);
|
|
3412
|
-
this.processEnv = productEnv;
|
|
3413
|
-
if (!productEnv.active) {
|
|
3414
|
-
throw new Error(`Environment ${env} is not active`);
|
|
3610
|
+
if (this.logService) {
|
|
3611
|
+
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 }));
|
|
3612
|
+
this.end = Date.now();
|
|
3613
|
+
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
3614
|
+
await this.logService.publish();
|
|
3415
3615
|
}
|
|
3416
|
-
|
|
3417
|
-
type: types_1.FeatureEventTypes.DB_ACTION,
|
|
3418
|
-
event,
|
|
3419
|
-
input,
|
|
3420
|
-
cache: action.cache,
|
|
3421
|
-
env: productEnv,
|
|
3422
|
-
retries: retries || 0,
|
|
3423
|
-
allow_fail: false,
|
|
3424
|
-
};
|
|
3425
|
-
const result = await this.runDBAction(payload, additional_logs);
|
|
3426
|
-
this.end = Date.now();
|
|
3427
|
-
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 }));
|
|
3428
|
-
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3429
|
-
await this.logService.publish();
|
|
3430
|
-
return result;
|
|
3431
|
-
}
|
|
3432
|
-
catch (e) {
|
|
3433
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
3434
|
-
this.end = Date.now();
|
|
3435
|
-
await this.logService.publish();
|
|
3436
|
-
return { process_id: this.process_id };
|
|
3616
|
+
throw e;
|
|
3437
3617
|
}
|
|
3438
3618
|
}
|
|
3439
|
-
async processFunction(data) { }
|
|
3440
3619
|
async processNotification(action) {
|
|
3441
3620
|
//TODO: schema validation
|
|
3442
|
-
|
|
3621
|
+
var _a;
|
|
3622
|
+
const { env, input, retries, event, product: product_tag, session, cache } = action;
|
|
3443
3623
|
const [parent_tag, child_tag] = event.split(':');
|
|
3444
3624
|
if (!parent_tag || !child_tag) {
|
|
3445
3625
|
throw new Error(`database action events should be in the format notification_tag:message_tag`);
|
|
@@ -3451,6 +3631,9 @@ class ProcessorService {
|
|
|
3451
3631
|
type: types_1.LogEventTypes.NOTIFICATIONS,
|
|
3452
3632
|
name: 'Process Notification',
|
|
3453
3633
|
};
|
|
3634
|
+
// Session log fields (will be populated if session is provided)
|
|
3635
|
+
let sessionLogFields = {};
|
|
3636
|
+
let resolvedInput = input;
|
|
3454
3637
|
try {
|
|
3455
3638
|
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3456
3639
|
this.input = action;
|
|
@@ -3459,24 +3642,66 @@ class ProcessorService {
|
|
|
3459
3642
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
3460
3643
|
this.baseLogs = Object.assign({ product_tag: this.productTag, workspace_id: this.workspace_id, env,
|
|
3461
3644
|
process_id, data: input }, additional_logs);
|
|
3462
|
-
|
|
3645
|
+
// Single bootstrap call to fetch all notification data
|
|
3646
|
+
const bootstrapData = await this.productBuilderService.bootstrapNotification({
|
|
3647
|
+
product_tag,
|
|
3648
|
+
env_slug: env,
|
|
3649
|
+
notification_tag: parent_tag,
|
|
3650
|
+
message_tag: child_tag,
|
|
3651
|
+
});
|
|
3652
|
+
// Initialize from bootstrap data
|
|
3653
|
+
this.productId = bootstrapData.product_id;
|
|
3654
|
+
this.processEnv = bootstrapData.env;
|
|
3655
|
+
// Process session if provided - verify and resolve $Session{} references
|
|
3656
|
+
if (session && bootstrapData.private_key) {
|
|
3657
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../../sessions')));
|
|
3658
|
+
const sessionResult = await processSessionForExecution(session, bootstrapData.private_key, input, env, {
|
|
3659
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
3660
|
+
const sessionConfig = await this.productBuilderService.fetchSession(sessionTag);
|
|
3661
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
3662
|
+
},
|
|
3663
|
+
});
|
|
3664
|
+
if (sessionResult.error) {
|
|
3665
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
3666
|
+
}
|
|
3667
|
+
resolvedInput = sessionResult.input;
|
|
3668
|
+
sessionLogFields = sessionResult.logFields;
|
|
3669
|
+
}
|
|
3670
|
+
// Initialize log service if needed
|
|
3671
|
+
if (!this.logService) {
|
|
3672
|
+
this.logService = new logs_service_1.default({
|
|
3673
|
+
product_id: this.productId,
|
|
3674
|
+
workspace_id: this.workspace_id,
|
|
3675
|
+
public_key: this.public_key,
|
|
3676
|
+
user_id: this.user_id,
|
|
3677
|
+
token: this.token,
|
|
3678
|
+
env_type: this.environment,
|
|
3679
|
+
});
|
|
3680
|
+
}
|
|
3463
3681
|
this.process_id = process_id;
|
|
3464
3682
|
this.baseLogs.product_id = this.productId;
|
|
3465
|
-
|
|
3466
|
-
this.
|
|
3683
|
+
// Add session fields to base logs
|
|
3684
|
+
this.baseLogs = Object.assign(Object.assign({}, this.baseLogs), sessionLogFields);
|
|
3685
|
+
const productEnv = bootstrapData.env;
|
|
3467
3686
|
if (!productEnv.active) {
|
|
3468
3687
|
throw new Error(`Environment ${env} is not active`);
|
|
3469
3688
|
}
|
|
3470
3689
|
const payload = {
|
|
3471
3690
|
type: types_1.FeatureEventTypes.NOTIFICATION,
|
|
3472
3691
|
event,
|
|
3473
|
-
input,
|
|
3474
|
-
cache:
|
|
3692
|
+
input: resolvedInput,
|
|
3693
|
+
cache: cache,
|
|
3475
3694
|
env: productEnv,
|
|
3476
3695
|
retries: retries || 0,
|
|
3477
3696
|
allow_fail: false,
|
|
3478
3697
|
};
|
|
3479
|
-
|
|
3698
|
+
// Find the env config for the notification
|
|
3699
|
+
const envConfig = (_a = bootstrapData.notification.envs) === null || _a === void 0 ? void 0 : _a.find((data) => data.slug === env);
|
|
3700
|
+
const result = await this.runNotification(payload, additional_logs, {
|
|
3701
|
+
notification: bootstrapData.notification,
|
|
3702
|
+
message: bootstrapData.message,
|
|
3703
|
+
env_config: envConfig,
|
|
3704
|
+
});
|
|
3480
3705
|
this.end = Date.now();
|
|
3481
3706
|
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 }));
|
|
3482
3707
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
@@ -3494,7 +3719,7 @@ class ProcessorService {
|
|
|
3494
3719
|
try {
|
|
3495
3720
|
const data = await this.processorApiService.fetchRemoteCaches(payload, this.getUserAccess());
|
|
3496
3721
|
return data.map((data) => {
|
|
3497
|
-
data.value = (0, processor_utils_1.decrypt)(data.value, this.productBuilderService.
|
|
3722
|
+
data.value = (0, processor_utils_1.decrypt)(data.value, this.productBuilderService.fetchPrivateKey());
|
|
3498
3723
|
return data;
|
|
3499
3724
|
});
|
|
3500
3725
|
}
|
|
@@ -3510,57 +3735,62 @@ class ProcessorService {
|
|
|
3510
3735
|
public_key: this.public_key,
|
|
3511
3736
|
};
|
|
3512
3737
|
}
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3738
|
+
/**
|
|
3739
|
+
* Add data to cache - fire-and-forget pattern.
|
|
3740
|
+
* Does not block the main operation.
|
|
3741
|
+
*/
|
|
3742
|
+
addToCache(payload, additional_logs) {
|
|
3517
3743
|
const { input, privateKey, data, cache_tag, timestamp, expiry, product_tag, component_tag, component_type } = payload;
|
|
3518
3744
|
// sha-512 instead of md5, private key is fetch product.privatekey
|
|
3519
3745
|
const key = `${cache_tag}-${CryptoJS.SHA512(input)}`;
|
|
3520
3746
|
const encryptedData = (0, processor_utils_1.encrypt)(data, privateKey);
|
|
3521
|
-
let expiresAt =
|
|
3747
|
+
let expiresAt = undefined;
|
|
3522
3748
|
if (expiry) {
|
|
3523
|
-
expiresAt = timestamp + expiry;
|
|
3524
|
-
}
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3749
|
+
expiresAt = new Date(timestamp + expiry);
|
|
3750
|
+
}
|
|
3751
|
+
// Use CacheService to store the value (fire-and-forget)
|
|
3752
|
+
this.cacheService.set({
|
|
3753
|
+
product: product_tag,
|
|
3754
|
+
cache: cache_tag,
|
|
3755
|
+
key,
|
|
3756
|
+
value: encryptedData,
|
|
3757
|
+
componentTag: component_tag,
|
|
3758
|
+
componentType: component_type,
|
|
3759
|
+
expiry: expiresAt,
|
|
3760
|
+
}).then(() => {
|
|
3761
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Cache value stored', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag, cache_key: key }));
|
|
3762
|
+
}).catch((error) => {
|
|
3763
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Cache store failed (non-blocking)', data: { key, error: String(error) }, status: types_1.LogEventStatus.FAIL, cache_tag, cache_key: key }));
|
|
3764
|
+
});
|
|
3532
3765
|
}
|
|
3533
3766
|
async fetchFromCache(payload, additional_logs) {
|
|
3534
|
-
var _a;
|
|
3535
3767
|
const { input, privateKey, cache_tag, expiry } = payload;
|
|
3536
3768
|
const key = `${cache_tag}-${CryptoJS.SHA512(input)}`;
|
|
3537
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching from Cache', data: { key }, status: types_1.LogEventStatus.PROCESSING, cache_tag }));
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
const checkRemote = await this.processorApiService.fetchRemoteCacheByKey(key, this.getUserAccess());
|
|
3544
|
-
if (!checkRemote) {
|
|
3545
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Remote Cache Not Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.FAIL, cache_tag }));
|
|
3769
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching from Cache', data: { key }, status: types_1.LogEventStatus.PROCESSING, cache_tag, cache_key: key }));
|
|
3770
|
+
try {
|
|
3771
|
+
// Use CacheService to fetch the value
|
|
3772
|
+
const cacheValue = await this.cacheService.get({ key });
|
|
3773
|
+
if (!cacheValue) {
|
|
3774
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Remote Cache Not Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.FAIL, cache_tag, cache_key: key, cache_status: false }));
|
|
3546
3775
|
return null;
|
|
3547
3776
|
}
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
if (record.lastUpdated) {
|
|
3552
|
-
const lastUpdated = Number(record.lastUpdated);
|
|
3553
|
-
if (expiry) {
|
|
3554
|
-
const expiryTime = lastUpdated + expiry;
|
|
3777
|
+
// Check expiry if provided
|
|
3778
|
+
if (expiry && cacheValue.expiry) {
|
|
3779
|
+
const expiryTime = new Date(cacheValue.expiry).getTime();
|
|
3555
3780
|
if (Date.now() > expiryTime) {
|
|
3556
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Deleting expired Cache Value', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
|
|
3557
|
-
await this.
|
|
3781
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Deleting expired Cache Value', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag, cache_key: key }));
|
|
3782
|
+
await this.cacheService.clear({ key });
|
|
3558
3783
|
return null;
|
|
3559
3784
|
}
|
|
3560
3785
|
}
|
|
3786
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Cache Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag, cache_key: key, cache_status: true }));
|
|
3787
|
+
// Decrypt the value (CacheService returns encrypted value)
|
|
3788
|
+
return (0, processor_utils_1.decrypt)(cacheValue.value, privateKey);
|
|
3789
|
+
}
|
|
3790
|
+
catch (error) {
|
|
3791
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Cache fetch error', data: { key, error: String(error) }, successful_execution: false, status: types_1.LogEventStatus.FAIL, cache_tag, cache_key: key, cache_status: false }));
|
|
3792
|
+
return null;
|
|
3561
3793
|
}
|
|
3562
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Cache Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
|
|
3563
|
-
return (0, processor_utils_1.decrypt)(record.data, privateKey);
|
|
3564
3794
|
}
|
|
3565
3795
|
/**
|
|
3566
3796
|
* Writes the healthcheck result to Redis cache for fast status retrieval.
|
|
@@ -3569,7 +3799,7 @@ class ProcessorService {
|
|
|
3569
3799
|
if (!this.redisClient)
|
|
3570
3800
|
return;
|
|
3571
3801
|
const key = `healthcheck:${data.product}:${data.healthcheck}:${data.env}`;
|
|
3572
|
-
console.log(
|
|
3802
|
+
console.log('LOG TO CACHE', key, JSON.stringify(result));
|
|
3573
3803
|
await this.redisClient.set(key, JSON.stringify(result));
|
|
3574
3804
|
console.log();
|
|
3575
3805
|
}
|