@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.
Files changed (295) hide show
  1. package/dist/agents/agent-context.d.ts +3 -1
  2. package/dist/agents/agent-context.js +19 -3
  3. package/dist/agents/agent-context.js.map +1 -1
  4. package/dist/agents/agents.service.js +9 -5
  5. package/dist/agents/agents.service.js.map +1 -1
  6. package/dist/agents/types/agents.types.d.ts +14 -1
  7. package/dist/agents/types/agents.types.js.map +1 -1
  8. package/dist/api/services/appApi.service.js +15 -6
  9. package/dist/api/services/appApi.service.js.map +1 -1
  10. package/dist/api/services/logsApi.service.d.ts +51 -0
  11. package/dist/api/services/logsApi.service.js +19 -2
  12. package/dist/api/services/logsApi.service.js.map +1 -1
  13. package/dist/api/services/processorApi.service.d.ts +568 -2
  14. package/dist/api/services/processorApi.service.js +412 -21
  15. package/dist/api/services/processorApi.service.js.map +1 -1
  16. package/dist/api/services/productsApi.service.d.ts +20 -0
  17. package/dist/api/services/productsApi.service.js +44 -15
  18. package/dist/api/services/productsApi.service.js.map +1 -1
  19. package/dist/api/services/secretsApi.service.js +0 -11
  20. package/dist/api/services/secretsApi.service.js.map +1 -1
  21. package/dist/api/services/webhooksApi.service.js +13 -6
  22. package/dist/api/services/webhooksApi.service.js.map +1 -1
  23. package/dist/api/services/workflowApi.service.js +30 -12
  24. package/dist/api/services/workflowApi.service.js.map +1 -1
  25. package/dist/api/urls.d.ts +26 -0
  26. package/dist/api/urls.js +30 -3
  27. package/dist/api/urls.js.map +1 -1
  28. package/dist/apps/validators/joi-validators/update.appAction.validator.js +12 -1
  29. package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
  30. package/dist/brokers/brokers.service.d.ts +140 -2
  31. package/dist/brokers/brokers.service.js +444 -36
  32. package/dist/brokers/brokers.service.js.map +1 -1
  33. package/dist/brokers/types/index.d.ts +251 -0
  34. package/dist/brokers/utils/providers/rabbitmq.service.d.ts +14 -4
  35. package/dist/brokers/utils/providers/rabbitmq.service.js +22 -35
  36. package/dist/brokers/utils/providers/rabbitmq.service.js.map +1 -1
  37. package/dist/cache/cache.manager.d.ts +84 -5
  38. package/dist/cache/cache.manager.js +478 -38
  39. package/dist/cache/cache.manager.js.map +1 -1
  40. package/dist/cache/cache.service.d.ts +5 -0
  41. package/dist/cache/cache.service.js +163 -6
  42. package/dist/cache/cache.service.js.map +1 -1
  43. package/dist/cache/index.d.ts +1 -1
  44. package/dist/cache/index.js +3 -1
  45. package/dist/cache/index.js.map +1 -1
  46. package/dist/cache/types/index.d.ts +4 -0
  47. package/dist/database/databases.service.d.ts +70 -2
  48. package/dist/database/databases.service.js +150 -35
  49. package/dist/database/databases.service.js.map +1 -1
  50. package/dist/database/types/dashboard.interface.d.ts +74 -0
  51. package/dist/database/types/dashboard.interface.js +7 -0
  52. package/dist/database/types/dashboard.interface.js.map +1 -0
  53. package/dist/database/types/index.d.ts +1 -0
  54. package/dist/graph/graphs.service.d.ts +50 -12
  55. package/dist/graph/graphs.service.js +689 -203
  56. package/dist/graph/graphs.service.js.map +1 -1
  57. package/dist/graph/types/connection.interface.d.ts +2 -2
  58. package/dist/index.d.ts +286 -4
  59. package/dist/index.js +370 -21
  60. package/dist/index.js.map +1 -1
  61. package/dist/logs/logs.types.d.ts +16 -3
  62. package/dist/logs/logs.types.js +11 -0
  63. package/dist/logs/logs.types.js.map +1 -1
  64. package/dist/notifications/notifications.service.d.ts +3 -0
  65. package/dist/notifications/notifications.service.js +57 -14
  66. package/dist/notifications/notifications.service.js.map +1 -1
  67. package/dist/notifications/types/notifications.types.d.ts +50 -0
  68. package/dist/processor/services/processor.service.d.ts +132 -8
  69. package/dist/processor/services/processor.service.js +1174 -267
  70. package/dist/processor/services/processor.service.js.map +1 -1
  71. package/dist/processor/utils/processor.utils.d.ts +5 -0
  72. package/dist/processor/utils/processor.utils.js +65 -12
  73. package/dist/processor/utils/processor.utils.js.map +1 -1
  74. package/dist/processor/utils/storage.util.js +11 -2
  75. package/dist/processor/utils/storage.util.js.map +1 -1
  76. package/dist/products/services/products.service.d.ts +19 -2
  77. package/dist/products/services/products.service.js +388 -54
  78. package/dist/products/services/products.service.js.map +1 -1
  79. package/dist/products/validators/joi-validators/create.productFeature.validator.js +1 -1
  80. package/dist/products/validators/joi-validators/create.productJob.validator.js +2 -2
  81. package/dist/products/validators/joi-validators/create.productJob.validator.js.map +1 -1
  82. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +1 -0
  83. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
  84. package/dist/products/validators/joi-validators/create.productNotification.validator.js +23 -12
  85. package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
  86. package/dist/resilience/fallback.service.d.ts +1 -0
  87. package/dist/resilience/fallback.service.js +2 -0
  88. package/dist/resilience/fallback.service.js.map +1 -1
  89. package/dist/resilience/quota.service.d.ts +1 -0
  90. package/dist/resilience/quota.service.js +2 -0
  91. package/dist/resilience/quota.service.js.map +1 -1
  92. package/dist/secrets/secrets.resolver.js +4 -1
  93. package/dist/secrets/secrets.resolver.js.map +1 -1
  94. package/dist/secrets/secrets.service.js +0 -12
  95. package/dist/secrets/secrets.service.js.map +1 -1
  96. package/dist/secrets/secrets.types.d.ts +3 -3
  97. package/dist/secrets/secrets.types.js +5 -5
  98. package/dist/secrets/secrets.types.js.map +1 -1
  99. package/dist/sessions/index.d.ts +1 -1
  100. package/dist/sessions/index.js +4 -1
  101. package/dist/sessions/index.js.map +1 -1
  102. package/dist/sessions/sessions.helper.d.ts +23 -3
  103. package/dist/sessions/sessions.helper.js +20 -3
  104. package/dist/sessions/sessions.helper.js.map +1 -1
  105. package/dist/sessions/sessions.resolver.d.ts +31 -0
  106. package/dist/sessions/sessions.resolver.js +230 -1
  107. package/dist/sessions/sessions.resolver.js.map +1 -1
  108. package/dist/sessions/sessions.service.d.ts +18 -2
  109. package/dist/sessions/sessions.service.js +121 -57
  110. package/dist/sessions/sessions.service.js.map +1 -1
  111. package/dist/sessions/types/index.d.ts +65 -21
  112. package/dist/storage/storage.service.d.ts +3 -0
  113. package/dist/storage/storage.service.js +179 -39
  114. package/dist/storage/storage.service.js.map +1 -1
  115. package/dist/types/index.types.d.ts +2 -0
  116. package/dist/types/inputs.types.d.ts +1 -0
  117. package/dist/types/inputs.types.js +3 -2
  118. package/dist/types/inputs.types.js.map +1 -1
  119. package/dist/types/processor.types.d.ts +72 -6
  120. package/dist/types/processor.types.js.map +1 -1
  121. package/dist/types/productsBuilder.types.d.ts +10 -0
  122. package/dist/types/productsBuilder.types.js +4 -0
  123. package/dist/types/productsBuilder.types.js.map +1 -1
  124. package/dist/vector/adapters/weaviate.adapter.js +22 -6
  125. package/dist/vector/adapters/weaviate.adapter.js.map +1 -1
  126. package/dist/vector/vector-database.service.d.ts +4 -2
  127. package/dist/vector/vector-database.service.js +71 -29
  128. package/dist/vector/vector-database.service.js.map +1 -1
  129. package/dist/workflows/types/workflows.types.d.ts +61 -3
  130. package/dist/workflows/types/workflows.types.js.map +1 -1
  131. package/dist/workflows/workflow-builder.js +17 -2
  132. package/dist/workflows/workflow-builder.js.map +1 -1
  133. package/dist/workflows/workflow-executor.d.ts +97 -18
  134. package/dist/workflows/workflow-executor.js +1449 -244
  135. package/dist/workflows/workflow-executor.js.map +1 -1
  136. package/dist/workflows/workflows.service.d.ts +2 -0
  137. package/dist/workflows/workflows.service.js +538 -74
  138. package/dist/workflows/workflows.service.js.map +1 -1
  139. package/package.json +11 -1
  140. package/dist/processor/services/fallback.service.d.ts +0 -5
  141. package/dist/processor/services/fallback.service.js +0 -43
  142. package/dist/processor/services/fallback.service.js.map +0 -1
  143. package/dist/processor/services/messagebrokers/aws-sqs.service.d.ts +0 -15
  144. package/dist/processor/services/messagebrokers/aws-sqs.service.js +0 -77
  145. package/dist/processor/services/messagebrokers/aws-sqs.service.js.map +0 -1
  146. package/dist/processor/services/messagebrokers/google-pubsub.service.d.ts +0 -16
  147. package/dist/processor/services/messagebrokers/google-pubsub.service.js +0 -34
  148. package/dist/processor/services/messagebrokers/google-pubsub.service.js.map +0 -1
  149. package/dist/processor/services/messagebrokers/index.d.ts +0 -3
  150. package/dist/processor/services/messagebrokers/index.js +0 -26
  151. package/dist/processor/services/messagebrokers/index.js.map +0 -1
  152. package/dist/processor/services/messagebrokers/kafka.service.d.ts +0 -14
  153. package/dist/processor/services/messagebrokers/kafka.service.js +0 -45
  154. package/dist/processor/services/messagebrokers/kafka.service.js.map +0 -1
  155. package/dist/processor/services/messagebrokers/messagebrokers.type.d.ts +0 -6
  156. package/dist/processor/services/messagebrokers/messagebrokers.type.js +0 -3
  157. package/dist/processor/services/messagebrokers/messagebrokers.type.js.map +0 -1
  158. package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +0 -14
  159. package/dist/processor/services/messagebrokers/rabbitmq.service.js +0 -67
  160. package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +0 -1
  161. package/dist/processor/services/messagebrokers/redis.service.d.ts +0 -18
  162. package/dist/processor/services/messagebrokers/redis.service.js +0 -82
  163. package/dist/processor/services/messagebrokers/redis.service.js.map +0 -1
  164. package/dist/processor/services/quota.service.d.ts +0 -15
  165. package/dist/processor/services/quota.service.js +0 -63
  166. package/dist/processor/services/quota.service.js.map +0 -1
  167. package/dist/test/index.d.ts +0 -3
  168. package/dist/test/index.js +0 -11
  169. package/dist/test/index.js.map +0 -1
  170. package/dist/test/test.appBuilder.d.ts +0 -0
  171. package/dist/test/test.appBuilder.js +0 -1
  172. package/dist/test/test.appBuilder.js.map +0 -1
  173. package/dist/test/test.broker.kafka.d.ts +0 -1
  174. package/dist/test/test.broker.kafka.js +0 -172
  175. package/dist/test/test.broker.kafka.js.map +0 -1
  176. package/dist/test/test.broker.nats.d.ts +0 -1
  177. package/dist/test/test.broker.nats.js +0 -193
  178. package/dist/test/test.broker.nats.js.map +0 -1
  179. package/dist/test/test.broker.pubsub.d.ts +0 -1
  180. package/dist/test/test.broker.pubsub.js +0 -171
  181. package/dist/test/test.broker.pubsub.js.map +0 -1
  182. package/dist/test/test.broker.rabbitmq.d.ts +0 -1
  183. package/dist/test/test.broker.rabbitmq.js +0 -164
  184. package/dist/test/test.broker.rabbitmq.js.map +0 -1
  185. package/dist/test/test.broker.redis.d.ts +0 -1
  186. package/dist/test/test.broker.redis.js +0 -168
  187. package/dist/test/test.broker.redis.js.map +0 -1
  188. package/dist/test/test.broker.sqs.d.ts +0 -1
  189. package/dist/test/test.broker.sqs.js +0 -158
  190. package/dist/test/test.broker.sqs.js.map +0 -1
  191. package/dist/test/test.caches.d.ts +0 -1
  192. package/dist/test/test.caches.js +0 -231
  193. package/dist/test/test.caches.js.map +0 -1
  194. package/dist/test/test.database.d.ts +0 -1
  195. package/dist/test/test.database.dynamo.d.ts +0 -1
  196. package/dist/test/test.database.dynamo.js +0 -265
  197. package/dist/test/test.database.dynamo.js.map +0 -1
  198. package/dist/test/test.database.js +0 -140
  199. package/dist/test/test.database.js.map +0 -1
  200. package/dist/test/test.database.mongo.d.ts +0 -1
  201. package/dist/test/test.database.mongo.js +0 -371
  202. package/dist/test/test.database.mongo.js.map +0 -1
  203. package/dist/test/test.database.mysql.d.ts +0 -1
  204. package/dist/test/test.database.mysql.js +0 -415
  205. package/dist/test/test.database.mysql.js.map +0 -1
  206. package/dist/test/test.database.postgres.d.ts +0 -1
  207. package/dist/test/test.database.postgres.js +0 -412
  208. package/dist/test/test.database.postgres.js.map +0 -1
  209. package/dist/test/test.email.brevo.d.ts +0 -1
  210. package/dist/test/test.email.brevo.js +0 -326
  211. package/dist/test/test.email.brevo.js.map +0 -1
  212. package/dist/test/test.email.mailgun.d.ts +0 -1
  213. package/dist/test/test.email.mailgun.js +0 -352
  214. package/dist/test/test.email.mailgun.js.map +0 -1
  215. package/dist/test/test.email.postmark.d.ts +0 -1
  216. package/dist/test/test.email.postmark.js +0 -316
  217. package/dist/test/test.email.postmark.js.map +0 -1
  218. package/dist/test/test.email.sendgrid.d.ts +0 -1
  219. package/dist/test/test.email.sendgrid.js +0 -365
  220. package/dist/test/test.email.sendgrid.js.map +0 -1
  221. package/dist/test/test.email.smtp.d.ts +0 -1
  222. package/dist/test/test.email.smtp.js +0 -323
  223. package/dist/test/test.email.smtp.js.map +0 -1
  224. package/dist/test/test.graph.arangodb.d.ts +0 -1
  225. package/dist/test/test.graph.arangodb.js +0 -358
  226. package/dist/test/test.graph.arangodb.js.map +0 -1
  227. package/dist/test/test.graph.memgraph.d.ts +0 -1
  228. package/dist/test/test.graph.memgraph.js +0 -320
  229. package/dist/test/test.graph.memgraph.js.map +0 -1
  230. package/dist/test/test.graph.neo4j.d.ts +0 -1
  231. package/dist/test/test.graph.neo4j.js +0 -218
  232. package/dist/test/test.graph.neo4j.js.map +0 -1
  233. package/dist/test/test.graph.neptune.d.ts +0 -1
  234. package/dist/test/test.graph.neptune.js +0 -331
  235. package/dist/test/test.graph.neptune.js.map +0 -1
  236. package/dist/test/test.health.d.ts +0 -0
  237. package/dist/test/test.health.js +0 -1
  238. package/dist/test/test.health.js.map +0 -1
  239. package/dist/test/test.import.d.ts +0 -0
  240. package/dist/test/test.import.js +0 -1
  241. package/dist/test/test.import.js.map +0 -1
  242. package/dist/test/test.import.openapi.d.ts +0 -0
  243. package/dist/test/test.import.openapi.js +0 -1
  244. package/dist/test/test.import.openapi.js.map +0 -1
  245. package/dist/test/test.imports.d.ts +0 -1
  246. package/dist/test/test.imports.js +0 -21
  247. package/dist/test/test.imports.js.map +0 -1
  248. package/dist/test/test.logs.d.ts +0 -0
  249. package/dist/test/test.logs.js +0 -1
  250. package/dist/test/test.logs.js.map +0 -1
  251. package/dist/test/test.notifications.d.ts +0 -1
  252. package/dist/test/test.notifications.js +0 -198
  253. package/dist/test/test.notifications.js.map +0 -1
  254. package/dist/test/test.notifiers.d.ts +0 -0
  255. package/dist/test/test.notifiers.js +0 -1
  256. package/dist/test/test.notifiers.js.map +0 -1
  257. package/dist/test/test.processor.d.ts +0 -0
  258. package/dist/test/test.processor.js +0 -1
  259. package/dist/test/test.processor.js.map +0 -1
  260. package/dist/test/test.productBuilder.d.ts +0 -0
  261. package/dist/test/test.productBuilder.js +0 -1
  262. package/dist/test/test.productBuilder.js.map +0 -1
  263. package/dist/test/test.products.d.ts +0 -0
  264. package/dist/test/test.products.js +0 -1
  265. package/dist/test/test.products.js.map +0 -1
  266. package/dist/test/test.push.expo.d.ts +0 -1
  267. package/dist/test/test.push.expo.js +0 -442
  268. package/dist/test/test.push.expo.js.map +0 -1
  269. package/dist/test/test.push.firebase.d.ts +0 -1
  270. package/dist/test/test.push.firebase.js +0 -409
  271. package/dist/test/test.push.firebase.js.map +0 -1
  272. package/dist/test/test.session.d.ts +0 -1
  273. package/dist/test/test.session.js +0 -299
  274. package/dist/test/test.session.js.map +0 -1
  275. package/dist/test/test.sms.nexmo.d.ts +0 -1
  276. package/dist/test/test.sms.nexmo.js +0 -278
  277. package/dist/test/test.sms.nexmo.js.map +0 -1
  278. package/dist/test/test.sms.twilio.d.ts +0 -1
  279. package/dist/test/test.sms.twilio.js +0 -275
  280. package/dist/test/test.sms.twilio.js.map +0 -1
  281. package/dist/test/test.storage.d.ts +0 -1
  282. package/dist/test/test.storage.js +0 -202
  283. package/dist/test/test.storage.js.map +0 -1
  284. package/dist/test/test.triggers.d.ts +0 -1
  285. package/dist/test/test.triggers.js +0 -314
  286. package/dist/test/test.triggers.js.map +0 -1
  287. package/dist/test/test.vector.pinecone.d.ts +0 -1
  288. package/dist/test/test.vector.pinecone.js +0 -238
  289. package/dist/test/test.vector.pinecone.js.map +0 -1
  290. package/dist/test/test.vector.qdrant.d.ts +0 -1
  291. package/dist/test/test.vector.qdrant.js +0 -307
  292. package/dist/test/test.vector.qdrant.js.map +0 -1
  293. package/dist/test/test.vector.weaviate.d.ts +0 -1
  294. package/dist/test/test.vector.weaviate.js +0 -325
  295. 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 if Redis client is provided
103
- if (config === null || config === void 0 ? void 0 : config.redis_client) {
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: options.product || '',
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
- (_g = this.logService) === null || _g === void 0 ? void 0 : _g.add(Object.assign(Object.assign({}, baseLogs), { start,
883
- end, message: `Database query - cache hit (${cached.source})`, successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
884
- (_h = this.logService) === null || _h === void 0 ? void 0 : _h.publish();
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: options.product || '',
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
- await this.cacheManager.store(cacheOptions, result);
937
+ this.cacheManager.store(cacheOptions, result); // Fire-and-forget
903
938
  }
904
939
  const end = Date.now();
905
- (_j = this.logService) === null || _j === void 0 ? void 0 : _j.add(Object.assign(Object.assign({}, baseLogs), { start,
906
- end, message: 'Database query - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
907
- (_k = this.logService) === null || _k === void 0 ? void 0 : _k.publish();
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
- (_l = this.logService) === null || _l === void 0 ? void 0 : _l.add(Object.assign(Object.assign({}, baseLogs), { start,
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 ((_m = this.logService) === null || _m === void 0 ? void 0 : _m.publish());
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
- await this.cacheManager.store(cacheOptions, result);
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
  /**