@ductape/sdk 0.0.4-v99 → 0.0.5
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 +3 -1
- package/dist/agents/agent-context.js +19 -3
- package/dist/agents/agent-context.js.map +1 -1
- package/dist/agents/agents.service.js +9 -5
- package/dist/agents/agents.service.js.map +1 -1
- package/dist/agents/types/agents.types.d.ts +14 -1
- package/dist/agents/types/agents.types.js.map +1 -1
- package/dist/api/services/appApi.service.js +15 -6
- 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 +19 -2
- package/dist/api/services/logsApi.service.js.map +1 -1
- package/dist/api/services/processorApi.service.d.ts +568 -2
- package/dist/api/services/processorApi.service.js +412 -21
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +20 -0
- package/dist/api/services/productsApi.service.js +44 -15
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/secretsApi.service.js +0 -11
- package/dist/api/services/secretsApi.service.js.map +1 -1
- package/dist/api/services/webhooksApi.service.js +13 -6
- package/dist/api/services/webhooksApi.service.js.map +1 -1
- package/dist/api/services/workflowApi.service.js +30 -12
- package/dist/api/services/workflowApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +26 -0
- package/dist/api/urls.js +30 -3
- package/dist/api/urls.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +12 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
- package/dist/brokers/brokers.service.d.ts +140 -2
- package/dist/brokers/brokers.service.js +444 -36
- package/dist/brokers/brokers.service.js.map +1 -1
- package/dist/brokers/types/index.d.ts +251 -0
- package/dist/brokers/utils/providers/rabbitmq.service.d.ts +14 -4
- package/dist/brokers/utils/providers/rabbitmq.service.js +22 -35
- package/dist/brokers/utils/providers/rabbitmq.service.js.map +1 -1
- package/dist/cache/cache.manager.d.ts +84 -5
- package/dist/cache/cache.manager.js +478 -38
- package/dist/cache/cache.manager.js.map +1 -1
- package/dist/cache/cache.service.d.ts +5 -0
- package/dist/cache/cache.service.js +163 -6
- package/dist/cache/cache.service.js.map +1 -1
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.js +3 -1
- package/dist/cache/index.js.map +1 -1
- package/dist/cache/types/index.d.ts +4 -0
- package/dist/database/databases.service.d.ts +70 -2
- package/dist/database/databases.service.js +150 -35
- package/dist/database/databases.service.js.map +1 -1
- 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/index.d.ts +1 -0
- package/dist/graph/graphs.service.d.ts +50 -12
- package/dist/graph/graphs.service.js +689 -203
- package/dist/graph/graphs.service.js.map +1 -1
- package/dist/graph/types/connection.interface.d.ts +2 -2
- package/dist/index.d.ts +286 -4
- package/dist/index.js +370 -21
- package/dist/index.js.map +1 -1
- package/dist/logs/logs.types.d.ts +16 -3
- package/dist/logs/logs.types.js +11 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/notifications/notifications.service.d.ts +3 -0
- package/dist/notifications/notifications.service.js +57 -14
- package/dist/notifications/notifications.service.js.map +1 -1
- package/dist/notifications/types/notifications.types.d.ts +50 -0
- package/dist/processor/services/processor.service.d.ts +132 -8
- package/dist/processor/services/processor.service.js +1174 -267
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/utils/processor.utils.d.ts +5 -0
- package/dist/processor/utils/processor.utils.js +65 -12
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/storage.util.js +11 -2
- package/dist/processor/utils/storage.util.js.map +1 -1
- package/dist/products/services/products.service.d.ts +19 -2
- package/dist/products/services/products.service.js +388 -54
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productFeature.validator.js +1 -1
- package/dist/products/validators/joi-validators/create.productJob.validator.js +2 -2
- package/dist/products/validators/joi-validators/create.productJob.validator.js.map +1 -1
- 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.productNotification.validator.js +23 -12
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/resilience/fallback.service.d.ts +1 -0
- package/dist/resilience/fallback.service.js +2 -0
- package/dist/resilience/fallback.service.js.map +1 -1
- package/dist/resilience/quota.service.d.ts +1 -0
- package/dist/resilience/quota.service.js +2 -0
- package/dist/resilience/quota.service.js.map +1 -1
- package/dist/secrets/secrets.resolver.js +4 -1
- package/dist/secrets/secrets.resolver.js.map +1 -1
- package/dist/secrets/secrets.service.js +0 -12
- package/dist/secrets/secrets.service.js.map +1 -1
- package/dist/secrets/secrets.types.d.ts +3 -3
- package/dist/secrets/secrets.types.js +5 -5
- package/dist/secrets/secrets.types.js.map +1 -1
- package/dist/sessions/index.d.ts +1 -1
- package/dist/sessions/index.js +4 -1
- package/dist/sessions/index.js.map +1 -1
- package/dist/sessions/sessions.helper.d.ts +23 -3
- package/dist/sessions/sessions.helper.js +20 -3
- package/dist/sessions/sessions.helper.js.map +1 -1
- package/dist/sessions/sessions.resolver.d.ts +31 -0
- package/dist/sessions/sessions.resolver.js +230 -1
- package/dist/sessions/sessions.resolver.js.map +1 -1
- package/dist/sessions/sessions.service.d.ts +18 -2
- package/dist/sessions/sessions.service.js +121 -57
- package/dist/sessions/sessions.service.js.map +1 -1
- package/dist/sessions/types/index.d.ts +65 -21
- package/dist/storage/storage.service.d.ts +3 -0
- package/dist/storage/storage.service.js +179 -39
- package/dist/storage/storage.service.js.map +1 -1
- package/dist/types/index.types.d.ts +2 -0
- package/dist/types/inputs.types.d.ts +1 -0
- package/dist/types/inputs.types.js +3 -2
- package/dist/types/inputs.types.js.map +1 -1
- package/dist/types/processor.types.d.ts +72 -6
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +10 -0
- package/dist/types/productsBuilder.types.js +4 -0
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/vector/adapters/weaviate.adapter.js +22 -6
- package/dist/vector/adapters/weaviate.adapter.js.map +1 -1
- package/dist/vector/vector-database.service.d.ts +4 -2
- package/dist/vector/vector-database.service.js +71 -29
- package/dist/vector/vector-database.service.js.map +1 -1
- package/dist/workflows/types/workflows.types.d.ts +61 -3
- package/dist/workflows/types/workflows.types.js.map +1 -1
- package/dist/workflows/workflow-builder.js +17 -2
- package/dist/workflows/workflow-builder.js.map +1 -1
- package/dist/workflows/workflow-executor.d.ts +97 -18
- package/dist/workflows/workflow-executor.js +1449 -244
- package/dist/workflows/workflow-executor.js.map +1 -1
- package/dist/workflows/workflows.service.d.ts +2 -0
- package/dist/workflows/workflows.service.js +538 -74
- package/dist/workflows/workflows.service.js.map +1 -1
- package/package.json +11 -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.d.ts +0 -15
- 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.d.ts +0 -16
- package/dist/processor/services/messagebrokers/google-pubsub.service.js +0 -34
- 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 +0 -3
- package/dist/processor/services/messagebrokers/messagebrokers.type.js.map +0 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +0 -14
- 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.d.ts +0 -18
- package/dist/processor/services/messagebrokers/redis.service.js +0 -82
- 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/test/index.d.ts +0 -3
- package/dist/test/index.js +0 -11
- package/dist/test/index.js.map +0 -1
- package/dist/test/test.appBuilder.d.ts +0 -0
- package/dist/test/test.appBuilder.js +0 -1
- package/dist/test/test.appBuilder.js.map +0 -1
- package/dist/test/test.broker.kafka.d.ts +0 -1
- package/dist/test/test.broker.kafka.js +0 -172
- package/dist/test/test.broker.kafka.js.map +0 -1
- package/dist/test/test.broker.nats.d.ts +0 -1
- package/dist/test/test.broker.nats.js +0 -193
- package/dist/test/test.broker.nats.js.map +0 -1
- package/dist/test/test.broker.pubsub.d.ts +0 -1
- package/dist/test/test.broker.pubsub.js +0 -171
- package/dist/test/test.broker.pubsub.js.map +0 -1
- package/dist/test/test.broker.rabbitmq.d.ts +0 -1
- package/dist/test/test.broker.rabbitmq.js +0 -164
- package/dist/test/test.broker.rabbitmq.js.map +0 -1
- package/dist/test/test.broker.redis.d.ts +0 -1
- package/dist/test/test.broker.redis.js +0 -168
- package/dist/test/test.broker.redis.js.map +0 -1
- package/dist/test/test.broker.sqs.d.ts +0 -1
- package/dist/test/test.broker.sqs.js +0 -158
- package/dist/test/test.broker.sqs.js.map +0 -1
- package/dist/test/test.caches.d.ts +0 -1
- package/dist/test/test.caches.js +0 -231
- package/dist/test/test.caches.js.map +0 -1
- package/dist/test/test.database.d.ts +0 -1
- package/dist/test/test.database.dynamo.d.ts +0 -1
- package/dist/test/test.database.dynamo.js +0 -265
- package/dist/test/test.database.dynamo.js.map +0 -1
- package/dist/test/test.database.js +0 -140
- package/dist/test/test.database.js.map +0 -1
- package/dist/test/test.database.mongo.d.ts +0 -1
- package/dist/test/test.database.mongo.js +0 -371
- package/dist/test/test.database.mongo.js.map +0 -1
- package/dist/test/test.database.mysql.d.ts +0 -1
- package/dist/test/test.database.mysql.js +0 -415
- package/dist/test/test.database.mysql.js.map +0 -1
- package/dist/test/test.database.postgres.d.ts +0 -1
- package/dist/test/test.database.postgres.js +0 -412
- package/dist/test/test.database.postgres.js.map +0 -1
- package/dist/test/test.email.brevo.d.ts +0 -1
- package/dist/test/test.email.brevo.js +0 -326
- package/dist/test/test.email.brevo.js.map +0 -1
- package/dist/test/test.email.mailgun.d.ts +0 -1
- package/dist/test/test.email.mailgun.js +0 -352
- package/dist/test/test.email.mailgun.js.map +0 -1
- package/dist/test/test.email.postmark.d.ts +0 -1
- package/dist/test/test.email.postmark.js +0 -316
- package/dist/test/test.email.postmark.js.map +0 -1
- package/dist/test/test.email.sendgrid.d.ts +0 -1
- package/dist/test/test.email.sendgrid.js +0 -365
- package/dist/test/test.email.sendgrid.js.map +0 -1
- package/dist/test/test.email.smtp.d.ts +0 -1
- package/dist/test/test.email.smtp.js +0 -323
- package/dist/test/test.email.smtp.js.map +0 -1
- package/dist/test/test.graph.arangodb.d.ts +0 -1
- package/dist/test/test.graph.arangodb.js +0 -358
- package/dist/test/test.graph.arangodb.js.map +0 -1
- package/dist/test/test.graph.memgraph.d.ts +0 -1
- package/dist/test/test.graph.memgraph.js +0 -320
- package/dist/test/test.graph.memgraph.js.map +0 -1
- package/dist/test/test.graph.neo4j.d.ts +0 -1
- package/dist/test/test.graph.neo4j.js +0 -218
- package/dist/test/test.graph.neo4j.js.map +0 -1
- package/dist/test/test.graph.neptune.d.ts +0 -1
- package/dist/test/test.graph.neptune.js +0 -331
- package/dist/test/test.graph.neptune.js.map +0 -1
- package/dist/test/test.health.d.ts +0 -0
- package/dist/test/test.health.js +0 -1
- package/dist/test/test.health.js.map +0 -1
- package/dist/test/test.import.d.ts +0 -0
- package/dist/test/test.import.js +0 -1
- package/dist/test/test.import.js.map +0 -1
- package/dist/test/test.import.openapi.d.ts +0 -0
- package/dist/test/test.import.openapi.js +0 -1
- 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 -21
- package/dist/test/test.imports.js.map +0 -1
- package/dist/test/test.logs.d.ts +0 -0
- package/dist/test/test.logs.js +0 -1
- package/dist/test/test.logs.js.map +0 -1
- package/dist/test/test.notifications.d.ts +0 -1
- package/dist/test/test.notifications.js +0 -198
- package/dist/test/test.notifications.js.map +0 -1
- package/dist/test/test.notifiers.d.ts +0 -0
- package/dist/test/test.notifiers.js +0 -1
- package/dist/test/test.notifiers.js.map +0 -1
- package/dist/test/test.processor.d.ts +0 -0
- package/dist/test/test.processor.js +0 -1
- package/dist/test/test.processor.js.map +0 -1
- package/dist/test/test.productBuilder.d.ts +0 -0
- package/dist/test/test.productBuilder.js +0 -1
- package/dist/test/test.productBuilder.js.map +0 -1
- package/dist/test/test.products.d.ts +0 -0
- package/dist/test/test.products.js +0 -1
- package/dist/test/test.products.js.map +0 -1
- package/dist/test/test.push.expo.d.ts +0 -1
- package/dist/test/test.push.expo.js +0 -442
- package/dist/test/test.push.expo.js.map +0 -1
- package/dist/test/test.push.firebase.d.ts +0 -1
- package/dist/test/test.push.firebase.js +0 -409
- package/dist/test/test.push.firebase.js.map +0 -1
- package/dist/test/test.session.d.ts +0 -1
- package/dist/test/test.session.js +0 -299
- package/dist/test/test.session.js.map +0 -1
- package/dist/test/test.sms.nexmo.d.ts +0 -1
- package/dist/test/test.sms.nexmo.js +0 -278
- package/dist/test/test.sms.nexmo.js.map +0 -1
- package/dist/test/test.sms.twilio.d.ts +0 -1
- package/dist/test/test.sms.twilio.js +0 -275
- package/dist/test/test.sms.twilio.js.map +0 -1
- package/dist/test/test.storage.d.ts +0 -1
- package/dist/test/test.storage.js +0 -202
- package/dist/test/test.storage.js.map +0 -1
- package/dist/test/test.triggers.d.ts +0 -1
- package/dist/test/test.triggers.js +0 -314
- package/dist/test/test.triggers.js.map +0 -1
- package/dist/test/test.vector.pinecone.d.ts +0 -1
- package/dist/test/test.vector.pinecone.js +0 -238
- package/dist/test/test.vector.pinecone.js.map +0 -1
- package/dist/test/test.vector.qdrant.d.ts +0 -1
- package/dist/test/test.vector.qdrant.js +0 -307
- package/dist/test/test.vector.qdrant.js.map +0 -1
- package/dist/test/test.vector.weaviate.d.ts +0 -1
- package/dist/test/test.vector.weaviate.js +0 -325
- package/dist/test/test.vector.weaviate.js.map +0 -1
|
@@ -94,20 +94,22 @@ class DatabaseService {
|
|
|
94
94
|
this.cacheManager = null;
|
|
95
95
|
/** Private keys cache for products (keyed by product tag) */
|
|
96
96
|
this.privateKeys = new Map();
|
|
97
|
+
/** Local cache for cache configurations to avoid repeated API calls (5 minute TTL) */
|
|
98
|
+
this.cacheConfigCache = new Map();
|
|
97
99
|
this.config = config || null;
|
|
98
100
|
this.adapterFactory = new adapter_factory_1.AdapterFactory();
|
|
99
101
|
this.transactionManager = new transaction_manager_1.TransactionManager();
|
|
100
102
|
this.actionManager = new action_manager_1.ActionManager(this);
|
|
101
103
|
this._privateKey = (config === null || config === void 0 ? void 0 : config.private_key) || '';
|
|
102
|
-
// Initialize CacheManager
|
|
103
|
-
if (config === null || config === void 0 ? void 0 : config.
|
|
104
|
+
// Initialize CacheManager (Redis is optional - Tier 1 internal cache and Tier 3 remote cache always work)
|
|
105
|
+
if ((config === null || config === void 0 ? void 0 : config.workspace_id) && (config === null || config === void 0 ? void 0 : config.public_key) && (config === null || config === void 0 ? void 0 : config.user_id) && (config === null || config === void 0 ? void 0 : config.token)) {
|
|
104
106
|
this.cacheManager = new cache_manager_1.CacheManager({
|
|
105
107
|
workspace_id: config.workspace_id,
|
|
106
108
|
public_key: config.public_key,
|
|
107
109
|
user_id: config.user_id,
|
|
108
110
|
token: config.token,
|
|
109
111
|
env_type: config.env_type,
|
|
110
|
-
redis_client: config.redis_client,
|
|
112
|
+
redis_client: config.redis_client, // Optional - Tier 2 cache
|
|
111
113
|
});
|
|
112
114
|
}
|
|
113
115
|
}
|
|
@@ -352,6 +354,28 @@ class DatabaseService {
|
|
|
352
354
|
getConfig() {
|
|
353
355
|
return this.config;
|
|
354
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Validate cache tag exists in product and return cache configuration
|
|
359
|
+
* Uses local in-memory cache to avoid repeated API calls (5 minute TTL)
|
|
360
|
+
*/
|
|
361
|
+
async validateCache(productTag, cacheTag) {
|
|
362
|
+
const cacheKey = `${productTag}:${cacheTag}`;
|
|
363
|
+
const cached = this.cacheConfigCache.get(cacheKey);
|
|
364
|
+
const now = Date.now();
|
|
365
|
+
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
366
|
+
// Return cached config if still valid
|
|
367
|
+
if (cached && (now - cached.fetchedAt) < CACHE_TTL) {
|
|
368
|
+
return { expiry: cached.expiry };
|
|
369
|
+
}
|
|
370
|
+
// Fetch from API and cache the result
|
|
371
|
+
const builder = await this.getProductBuilder(productTag);
|
|
372
|
+
const cache = await builder.fetchCache(cacheTag);
|
|
373
|
+
if (!cache) {
|
|
374
|
+
throw new database_error_1.DatabaseError(`Cache configuration '${cacheTag}' does not exist`, enums_1.DatabaseErrorType.NOT_FOUND);
|
|
375
|
+
}
|
|
376
|
+
this.cacheConfigCache.set(cacheKey, { expiry: cache.expiry, fetchedAt: now });
|
|
377
|
+
return { expiry: cache.expiry };
|
|
378
|
+
}
|
|
355
379
|
/**
|
|
356
380
|
* Update the service configuration (used after auth is complete)
|
|
357
381
|
*/
|
|
@@ -829,7 +853,7 @@ class DatabaseService {
|
|
|
829
853
|
* });
|
|
830
854
|
*/
|
|
831
855
|
async query(options) {
|
|
832
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
856
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
833
857
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
834
858
|
const start = Date.now();
|
|
835
859
|
this.initializeLogService();
|
|
@@ -842,7 +866,12 @@ class DatabaseService {
|
|
|
842
866
|
const privateKey = builder.fetchPrivateKey();
|
|
843
867
|
if (privateKey) {
|
|
844
868
|
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
845
|
-
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env
|
|
869
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env, {
|
|
870
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
871
|
+
const sessionConfig = await builder.fetchSession(sessionTag);
|
|
872
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
873
|
+
},
|
|
874
|
+
});
|
|
846
875
|
if (sessionResult.error) {
|
|
847
876
|
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
848
877
|
}
|
|
@@ -864,24 +893,28 @@ class DatabaseService {
|
|
|
864
893
|
include: options.include,
|
|
865
894
|
} }, sessionLogFields);
|
|
866
895
|
(_f = this.logService) === null || _f === void 0 ? void 0 : _f.add(Object.assign(Object.assign({}, baseLogs), { start, message: 'Database query - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
896
|
+
// Check cache if cache tag is provided
|
|
897
|
+
// Use product from options or from current context (set during connect)
|
|
898
|
+
const productTag = options.product || ((_g = this.currentContext) === null || _g === void 0 ? void 0 : _g.product);
|
|
899
|
+
const privateKey = productTag ? this.privateKeys.get(productTag) : undefined;
|
|
900
|
+
let queryCacheKey;
|
|
867
901
|
try {
|
|
868
|
-
// Check cache if cache tag is provided
|
|
869
|
-
const privateKey = options.product ? this.privateKeys.get(options.product) : undefined;
|
|
870
902
|
if (options.cache && this.cacheManager && privateKey) {
|
|
871
903
|
const cacheOptions = {
|
|
872
904
|
cache_tag: options.cache,
|
|
873
|
-
product_tag:
|
|
874
|
-
component_tag: options.database || '',
|
|
905
|
+
product_tag: productTag || '',
|
|
906
|
+
component_tag: options.database || ((_h = this.currentContext) === null || _h === void 0 ? void 0 : _h.database) || '',
|
|
875
907
|
component_type: 'database',
|
|
876
908
|
input: { table: options.table, where: options.where, select: options.select, orderBy: options.orderBy, limit: options.limit, offset: options.offset },
|
|
877
909
|
privateKey,
|
|
878
910
|
};
|
|
879
911
|
const cached = await this.cacheManager.fetch(cacheOptions);
|
|
912
|
+
queryCacheKey = cached.key;
|
|
880
913
|
if (cached.hit && cached.data) {
|
|
881
914
|
const end = Date.now();
|
|
882
|
-
(
|
|
883
|
-
end, message: `Database query - cache hit (${cached.source})`, successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
884
|
-
(
|
|
915
|
+
(_j = this.logService) === null || _j === void 0 ? void 0 : _j.add(Object.assign(Object.assign({}, baseLogs), { start,
|
|
916
|
+
end, message: `Database query - cache hit (${cached.source})`, successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS, cache_tag: options.cache, cache_key: cached.key, cache_status: true }));
|
|
917
|
+
(_k = this.logService) === null || _k === void 0 ? void 0 : _k.publish();
|
|
885
918
|
return cached.data;
|
|
886
919
|
}
|
|
887
920
|
}
|
|
@@ -890,28 +923,30 @@ class DatabaseService {
|
|
|
890
923
|
const builtQuery = queryBuilder.buildQuery(resolvedOptions);
|
|
891
924
|
const result = await adapter.query(builtQuery);
|
|
892
925
|
// Store in cache if cache tag is provided
|
|
893
|
-
if (options.cache && this.cacheManager && privateKey) {
|
|
926
|
+
if (options.cache && this.cacheManager && privateKey && productTag) {
|
|
927
|
+
const cacheConfig = await this.validateCache(productTag, options.cache);
|
|
894
928
|
const cacheOptions = {
|
|
895
929
|
cache_tag: options.cache,
|
|
896
|
-
product_tag:
|
|
897
|
-
component_tag: options.database || '',
|
|
930
|
+
product_tag: productTag,
|
|
931
|
+
component_tag: options.database || ((_l = this.currentContext) === null || _l === void 0 ? void 0 : _l.database) || '',
|
|
898
932
|
component_type: 'database',
|
|
899
933
|
input: { table: options.table, where: options.where, select: options.select, orderBy: options.orderBy, limit: options.limit, offset: options.offset },
|
|
900
934
|
privateKey,
|
|
935
|
+
expiry: cacheConfig.expiry,
|
|
901
936
|
};
|
|
902
|
-
|
|
937
|
+
this.cacheManager.store(cacheOptions, result); // Fire-and-forget
|
|
903
938
|
}
|
|
904
939
|
const end = Date.now();
|
|
905
|
-
(
|
|
906
|
-
end, message: 'Database query - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
907
|
-
(
|
|
940
|
+
(_m = this.logService) === null || _m === void 0 ? void 0 : _m.add(Object.assign(Object.assign({}, baseLogs), { start,
|
|
941
|
+
end, message: options.cache ? 'Database query - cache miss' : 'Database query - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS, cache_tag: options.cache, cache_key: queryCacheKey }));
|
|
942
|
+
(_o = this.logService) === null || _o === void 0 ? void 0 : _o.publish();
|
|
908
943
|
return result;
|
|
909
944
|
}
|
|
910
945
|
catch (error) {
|
|
911
946
|
const end = Date.now();
|
|
912
|
-
(
|
|
913
|
-
end, message: 'Database query - failed', failed_execution: true, data: { table: options.table, operation: 'query', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
914
|
-
await ((
|
|
947
|
+
(_p = this.logService) === null || _p === void 0 ? void 0 : _p.add(Object.assign(Object.assign({}, baseLogs), { start,
|
|
948
|
+
end, message: 'Database query - failed', failed_execution: true, data: { table: options.table, operation: 'query', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL, cache_tag: options.cache, cache_key: queryCacheKey }));
|
|
949
|
+
await ((_q = this.logService) === null || _q === void 0 ? void 0 : _q.publish());
|
|
915
950
|
throw error;
|
|
916
951
|
}
|
|
917
952
|
}
|
|
@@ -963,9 +998,10 @@ class DatabaseService {
|
|
|
963
998
|
},
|
|
964
999
|
};
|
|
965
1000
|
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { start, message: 'Database raw query - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
1001
|
+
// Check cache if cache tag is provided
|
|
1002
|
+
const privateKey = options.product ? this.privateKeys.get(options.product) : undefined;
|
|
1003
|
+
let rawQueryCacheKey;
|
|
966
1004
|
try {
|
|
967
|
-
// Check cache if cache tag is provided
|
|
968
|
-
const privateKey = options.product ? this.privateKeys.get(options.product) : undefined;
|
|
969
1005
|
if (options.cache && this.cacheManager && privateKey) {
|
|
970
1006
|
const cacheOptions = {
|
|
971
1007
|
cache_tag: options.cache,
|
|
@@ -976,10 +1012,11 @@ class DatabaseService {
|
|
|
976
1012
|
privateKey,
|
|
977
1013
|
};
|
|
978
1014
|
const cached = await this.cacheManager.fetch(cacheOptions);
|
|
1015
|
+
rawQueryCacheKey = cached.key;
|
|
979
1016
|
if (cached.hit && cached.data) {
|
|
980
1017
|
const end = Date.now();
|
|
981
1018
|
(_f = this.logService) === null || _f === void 0 ? void 0 : _f.add(Object.assign(Object.assign({}, baseLogs), { start,
|
|
982
|
-
end, message: `Database raw query - cache hit (${cached.source})`, successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
1019
|
+
end, message: `Database raw query - cache hit (${cached.source})`, successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS, cache_tag: options.cache, cache_key: cached.key, cache_status: true }));
|
|
983
1020
|
(_g = this.logService) === null || _g === void 0 ? void 0 : _g.publish();
|
|
984
1021
|
return cached.data;
|
|
985
1022
|
}
|
|
@@ -987,27 +1024,29 @@ class DatabaseService {
|
|
|
987
1024
|
const adapter = this.getAdapter(options);
|
|
988
1025
|
const result = await adapter.raw(options);
|
|
989
1026
|
// Store in cache if cache tag is provided
|
|
990
|
-
if (options.cache && this.cacheManager && privateKey) {
|
|
1027
|
+
if (options.cache && this.cacheManager && privateKey && options.product) {
|
|
1028
|
+
const cacheConfig = await this.validateCache(options.product, options.cache);
|
|
991
1029
|
const cacheOptions = {
|
|
992
1030
|
cache_tag: options.cache,
|
|
993
|
-
product_tag: options.product
|
|
1031
|
+
product_tag: options.product,
|
|
994
1032
|
component_tag: options.database || '',
|
|
995
1033
|
component_type: 'database',
|
|
996
1034
|
input: { query: options.query, params: options.params, collection: options.collection },
|
|
997
1035
|
privateKey,
|
|
1036
|
+
expiry: cacheConfig.expiry,
|
|
998
1037
|
};
|
|
999
|
-
|
|
1038
|
+
this.cacheManager.store(cacheOptions, result); // Fire-and-forget
|
|
1000
1039
|
}
|
|
1001
1040
|
const end = Date.now();
|
|
1002
1041
|
(_h = this.logService) === null || _h === void 0 ? void 0 : _h.add(Object.assign(Object.assign({}, baseLogs), { start,
|
|
1003
|
-
end, message: 'Database raw query - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
1042
|
+
end, message: options.cache ? 'Database raw query - cache miss' : 'Database raw query - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS, cache_tag: options.cache, cache_key: rawQueryCacheKey }));
|
|
1004
1043
|
(_j = this.logService) === null || _j === void 0 ? void 0 : _j.publish();
|
|
1005
1044
|
return result;
|
|
1006
1045
|
}
|
|
1007
1046
|
catch (error) {
|
|
1008
1047
|
const end = Date.now();
|
|
1009
1048
|
(_k = this.logService) === null || _k === void 0 ? void 0 : _k.add(Object.assign(Object.assign({}, baseLogs), { start,
|
|
1010
|
-
end, message: 'Database raw query - failed', failed_execution: true, data: { operation: 'raw', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
1049
|
+
end, message: 'Database raw query - failed', failed_execution: true, data: { operation: 'raw', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL, cache_tag: options.cache, cache_key: rawQueryCacheKey }));
|
|
1011
1050
|
await ((_l = this.logService) === null || _l === void 0 ? void 0 : _l.publish());
|
|
1012
1051
|
throw error;
|
|
1013
1052
|
}
|
|
@@ -1062,7 +1101,12 @@ class DatabaseService {
|
|
|
1062
1101
|
const privateKey = builder.fetchPrivateKey();
|
|
1063
1102
|
if (privateKey) {
|
|
1064
1103
|
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1065
|
-
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env
|
|
1104
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env, {
|
|
1105
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
1106
|
+
const sessionConfig = await builder.fetchSession(sessionTag);
|
|
1107
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
1108
|
+
},
|
|
1109
|
+
});
|
|
1066
1110
|
if (sessionResult.error) {
|
|
1067
1111
|
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1068
1112
|
}
|
|
@@ -1138,7 +1182,12 @@ class DatabaseService {
|
|
|
1138
1182
|
const privateKey = builder.fetchPrivateKey();
|
|
1139
1183
|
if (privateKey) {
|
|
1140
1184
|
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1141
|
-
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env
|
|
1185
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env, {
|
|
1186
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
1187
|
+
const sessionConfig = await builder.fetchSession(sessionTag);
|
|
1188
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
1189
|
+
},
|
|
1190
|
+
});
|
|
1142
1191
|
if (sessionResult.error) {
|
|
1143
1192
|
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1144
1193
|
}
|
|
@@ -1206,7 +1255,12 @@ class DatabaseService {
|
|
|
1206
1255
|
const privateKey = builder.fetchPrivateKey();
|
|
1207
1256
|
if (privateKey) {
|
|
1208
1257
|
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1209
|
-
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env
|
|
1258
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env, {
|
|
1259
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
1260
|
+
const sessionConfig = await builder.fetchSession(sessionTag);
|
|
1261
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
1262
|
+
},
|
|
1263
|
+
});
|
|
1210
1264
|
if (sessionResult.error) {
|
|
1211
1265
|
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1212
1266
|
}
|
|
@@ -1270,7 +1324,12 @@ class DatabaseService {
|
|
|
1270
1324
|
const privateKey = builder.fetchPrivateKey();
|
|
1271
1325
|
if (privateKey) {
|
|
1272
1326
|
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1273
|
-
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env
|
|
1327
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env, {
|
|
1328
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
1329
|
+
const sessionConfig = await builder.fetchSession(sessionTag);
|
|
1330
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
1331
|
+
},
|
|
1332
|
+
});
|
|
1274
1333
|
if (sessionResult.error) {
|
|
1275
1334
|
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1276
1335
|
}
|
|
@@ -2037,7 +2096,12 @@ class DatabaseService {
|
|
|
2037
2096
|
const privateKey = builder.fetchPrivateKey();
|
|
2038
2097
|
if (privateKey) {
|
|
2039
2098
|
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
2040
|
-
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env
|
|
2099
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env, {
|
|
2100
|
+
fetchSessionSelector: async (sessionTag) => {
|
|
2101
|
+
const sessionConfig = await builder.fetchSession(sessionTag);
|
|
2102
|
+
return sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.selector;
|
|
2103
|
+
},
|
|
2104
|
+
});
|
|
2041
2105
|
if (sessionResult.error) {
|
|
2042
2106
|
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
2043
2107
|
}
|
|
@@ -2584,6 +2648,57 @@ class DatabaseService {
|
|
|
2584
2648
|
}
|
|
2585
2649
|
return adapter;
|
|
2586
2650
|
}
|
|
2651
|
+
// ==================== DASHBOARD ====================
|
|
2652
|
+
/**
|
|
2653
|
+
* Fetch database dashboard metrics from logs
|
|
2654
|
+
*
|
|
2655
|
+
* @example
|
|
2656
|
+
* ```ts
|
|
2657
|
+
* const dashboard = await databases.fetchDashboard({
|
|
2658
|
+
* product: 'my-product',
|
|
2659
|
+
* database: 'my-database',
|
|
2660
|
+
* env: 'production',
|
|
2661
|
+
* });
|
|
2662
|
+
* console.log(dashboard.dau, dashboard.activityTimeline);
|
|
2663
|
+
* ```
|
|
2664
|
+
*/
|
|
2665
|
+
async fetchDashboard(options) {
|
|
2666
|
+
if (!this.config) {
|
|
2667
|
+
throw new database_error_1.DatabaseError('DatabaseService not configured. Please provide config when initializing.', enums_1.DatabaseErrorType.CONFIGURATION_ERROR);
|
|
2668
|
+
}
|
|
2669
|
+
const { product, database, env } = options;
|
|
2670
|
+
const { LogApiService } = await Promise.resolve().then(() => __importStar(require('../api/services/logsApi.service')));
|
|
2671
|
+
const logsApi = new LogApiService(this.config.env_type);
|
|
2672
|
+
try {
|
|
2673
|
+
const dashboard = await logsApi.fetchDatabaseDashboard({
|
|
2674
|
+
product_tag: product,
|
|
2675
|
+
database_tag: database,
|
|
2676
|
+
env,
|
|
2677
|
+
}, {
|
|
2678
|
+
workspace_id: this.config.workspace_id,
|
|
2679
|
+
user_id: this.config.user_id,
|
|
2680
|
+
public_key: this.config.public_key,
|
|
2681
|
+
token: this.config.token,
|
|
2682
|
+
});
|
|
2683
|
+
return {
|
|
2684
|
+
dau: dashboard.dau || { current: 0, previous: 0, change: 0 },
|
|
2685
|
+
wau: dashboard.wau || { current: 0, previous: 0, change: 0 },
|
|
2686
|
+
mau: dashboard.mau || { current: 0, previous: 0, change: 0 },
|
|
2687
|
+
totalOperations: dashboard.totalOperations || 0,
|
|
2688
|
+
successfulOperations: dashboard.successfulOperations || 0,
|
|
2689
|
+
failedOperations: dashboard.failedOperations || 0,
|
|
2690
|
+
newOperationsThisWeek: dashboard.newOperationsThisWeek || 0,
|
|
2691
|
+
avgExecutionTime: dashboard.avgExecutionTime || { current: '0ms', previous: '0ms', change: 0 },
|
|
2692
|
+
activityTimeline: dashboard.activityTimeline || [],
|
|
2693
|
+
peakHours: dashboard.peakHours || [],
|
|
2694
|
+
environmentBreakdown: dashboard.environmentBreakdown || [],
|
|
2695
|
+
methodBreakdown: dashboard.methodBreakdown || [],
|
|
2696
|
+
};
|
|
2697
|
+
}
|
|
2698
|
+
catch (error) {
|
|
2699
|
+
throw new database_error_1.DatabaseError(`Failed to fetch database dashboard: ${error}`, enums_1.DatabaseErrorType.QUERY_ERROR);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2587
2702
|
}
|
|
2588
2703
|
exports.DatabaseService = DatabaseService;
|
|
2589
2704
|
/**
|