@resolveio/server-lib 22.3.221 → 22.3.223
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/ai/assistant-core-heuristics.d.ts +11 -0
- package/ai/assistant-core-heuristics.js +356 -0
- package/ai/assistant-core-heuristics.js.map +1 -0
- package/ai/resolveio-platform-intelligence-memory-corpus.d.ts +3 -0
- package/ai/resolveio-platform-intelligence-memory-corpus.js +214 -0
- package/ai/resolveio-platform-intelligence-memory-corpus.js.map +1 -0
- package/ai/resolveio-platform-intelligence-memory.d.ts +20 -0
- package/ai/resolveio-platform-intelligence-memory.js +341 -0
- package/ai/resolveio-platform-intelligence-memory.js.map +1 -0
- package/{src/ai/resolveio-platform-intelligence-types.ts → ai/resolveio-platform-intelligence-types.d.ts} +15 -20
- package/ai/resolveio-platform-intelligence-types.js +4 -0
- package/ai/resolveio-platform-intelligence-types.js.map +1 -0
- package/ai/resolveio-platform-intelligence.d.ts +6 -0
- package/ai/resolveio-platform-intelligence.js +463 -0
- package/ai/resolveio-platform-intelligence.js.map +1 -0
- package/client-server-app.d.ts +1 -0
- package/client-server-app.js +68 -0
- package/client-server-app.js.map +1 -0
- package/collections/ai-run.collection.d.ts +3 -0
- package/collections/ai-run.collection.js +170 -0
- package/collections/ai-run.collection.js.map +1 -0
- package/collections/ai-terminal-conversation.collection.d.ts +2 -0
- package/collections/ai-terminal-conversation.collection.js +140 -0
- package/collections/ai-terminal-conversation.collection.js.map +1 -0
- package/collections/ai-terminal-issue-report.collection.d.ts +2 -0
- package/collections/ai-terminal-issue-report.collection.js +148 -0
- package/collections/ai-terminal-issue-report.collection.js.map +1 -0
- package/collections/ai-terminal-message.collection.d.ts +2 -0
- package/collections/ai-terminal-message.collection.js +121 -0
- package/collections/ai-terminal-message.collection.js.map +1 -0
- package/collections/app-setting.collection.d.ts +3 -0
- package/collections/app-setting.collection.js +103 -0
- package/collections/app-setting.collection.js.map +1 -0
- package/collections/app-status.collection.d.ts +3 -0
- package/collections/app-status.collection.js +57 -0
- package/collections/app-status.collection.js.map +1 -0
- package/collections/communication-metric.collection.d.ts +2 -0
- package/collections/communication-metric.collection.js +133 -0
- package/collections/communication-metric.collection.js.map +1 -0
- package/collections/counter.collection.d.ts +3 -0
- package/collections/counter.collection.js +56 -0
- package/collections/counter.collection.js.map +1 -0
- package/collections/cron-job-history.collection.d.ts +3 -0
- package/collections/cron-job-history.collection.js +137 -0
- package/collections/cron-job-history.collection.js.map +1 -0
- package/collections/cron-job.collection.d.ts +3 -0
- package/collections/cron-job.collection.js +92 -0
- package/collections/cron-job.collection.js.map +1 -0
- package/collections/customer-notification.collection.d.ts +3 -0
- package/collections/customer-notification.collection.js +130 -0
- package/collections/customer-notification.collection.js.map +1 -0
- package/collections/customer-portal-password.collection.d.ts +3 -0
- package/collections/customer-portal-password.collection.js +75 -0
- package/collections/customer-portal-password.collection.js.map +1 -0
- package/collections/email-history.collection.d.ts +3 -0
- package/collections/email-history.collection.js +134 -0
- package/collections/email-history.collection.js.map +1 -0
- package/collections/email-verified.collection.d.ts +3 -0
- package/collections/email-verified.collection.js +62 -0
- package/collections/email-verified.collection.js.map +1 -0
- package/collections/file.collection.d.ts +3 -0
- package/collections/file.collection.js +74 -0
- package/collections/file.collection.js.map +1 -0
- package/collections/flag-update.collection.d.ts +3 -0
- package/collections/flag-update.collection.js +57 -0
- package/collections/flag-update.collection.js.map +1 -0
- package/collections/flag.collection.d.ts +3 -0
- package/collections/flag.collection.js +57 -0
- package/collections/flag.collection.js.map +1 -0
- package/collections/log-method-latency.collection.d.ts +3 -0
- package/collections/log-method-latency.collection.js +77 -0
- package/collections/log-method-latency.collection.js.map +1 -0
- package/collections/log-subscription.collection.d.ts +3 -0
- package/collections/log-subscription.collection.js +80 -0
- package/collections/log-subscription.collection.js.map +1 -0
- package/collections/log.collection.d.ts +3 -0
- package/collections/log.collection.js +93 -0
- package/collections/log.collection.js.map +1 -0
- package/collections/logged-in-users.collection.d.ts +3 -0
- package/collections/logged-in-users.collection.js +67 -0
- package/collections/logged-in-users.collection.js.map +1 -0
- package/collections/monitor-cpu.collection.d.ts +3 -0
- package/collections/monitor-cpu.collection.js +65 -0
- package/collections/monitor-cpu.collection.js.map +1 -0
- package/collections/monitor-function.collection.d.ts +3 -0
- package/collections/monitor-function.collection.js +74 -0
- package/collections/monitor-function.collection.js.map +1 -0
- package/collections/monitor-memory.collection.d.ts +3 -0
- package/collections/monitor-memory.collection.js +77 -0
- package/collections/monitor-memory.collection.js.map +1 -0
- package/collections/monitor-mongo.collection.d.ts +3 -0
- package/collections/monitor-mongo.collection.js +71 -0
- package/collections/monitor-mongo.collection.js.map +1 -0
- package/collections/notification.collection.d.ts +3 -0
- package/collections/notification.collection.js +57 -0
- package/collections/notification.collection.js.map +1 -0
- package/collections/openai-usage-ledger.collection.d.ts +2 -0
- package/collections/openai-usage-ledger.collection.js +188 -0
- package/collections/openai-usage-ledger.collection.js.map +1 -0
- package/collections/report-builder-dashboard-builder.collection.d.ts +3 -0
- package/collections/report-builder-dashboard-builder.collection.js +109 -0
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -0
- package/collections/report-builder-library.collection.d.ts +3 -0
- package/collections/report-builder-library.collection.js +87 -0
- package/collections/report-builder-library.collection.js.map +1 -0
- package/collections/report-builder-report.collection.d.ts +4 -0
- package/collections/report-builder-report.collection.js +184 -0
- package/collections/report-builder-report.collection.js.map +1 -0
- package/collections/user-group.collection.d.ts +4 -0
- package/collections/user-group.collection.js +89 -0
- package/collections/user-group.collection.js.map +1 -0
- package/collections/user-guide.collection.d.ts +3 -0
- package/collections/user-guide.collection.js +57 -0
- package/collections/user-guide.collection.js.map +1 -0
- package/collections/user.collection.d.ts +4 -0
- package/collections/user.collection.js +180 -0
- package/collections/user.collection.js.map +1 -0
- package/cron/cron.d.ts +14 -0
- package/cron/cron.js +216 -0
- package/cron/cron.js.map +1 -0
- package/fixtures/cron-jobs.d.ts +1 -0
- package/fixtures/cron-jobs.js +150 -0
- package/fixtures/cron-jobs.js.map +1 -0
- package/fixtures/init.d.ts +1 -0
- package/fixtures/init.js +91 -0
- package/fixtures/init.js.map +1 -0
- package/http/auth.d.ts +2 -0
- package/http/auth.js +951 -0
- package/http/auth.js.map +1 -0
- package/http/health.d.ts +1 -0
- package/http/health.js +11 -0
- package/http/health.js.map +1 -0
- package/http/home.d.ts +1 -0
- package/http/home.js +134 -0
- package/http/home.js.map +1 -0
- package/http/slow-query-publication.d.ts +2 -0
- package/http/slow-query-publication.js +99 -0
- package/http/slow-query-publication.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +19 -0
- package/index.js.map +1 -0
- package/managers/ai-assistant-codex-manager.manager.d.ts +67 -0
- package/managers/ai-assistant-codex-manager.manager.js +1113 -0
- package/managers/ai-assistant-codex-manager.manager.js.map +1 -0
- package/managers/ai-run-evidence.manager.d.ts +36 -0
- package/managers/ai-run-evidence.manager.js +377 -0
- package/managers/ai-run-evidence.manager.js.map +1 -0
- package/managers/communication-metric.manager.d.ts +16 -0
- package/managers/communication-metric.manager.js +134 -0
- package/managers/communication-metric.manager.js.map +1 -0
- package/managers/cron.manager.d.ts +20 -0
- package/managers/cron.manager.js +534 -0
- package/managers/cron.manager.js.map +1 -0
- package/managers/customer-notification-content.manager.d.ts +55 -0
- package/managers/customer-notification-content.manager.js +158 -0
- package/managers/customer-notification-content.manager.js.map +1 -0
- package/managers/diagnostic-manager-bootstrap.d.ts +9 -0
- package/managers/diagnostic-manager-bootstrap.js +260 -0
- package/managers/diagnostic-manager-bootstrap.js.map +1 -0
- package/managers/error-auto-fix.manager.d.ts +149 -0
- package/managers/error-auto-fix.manager.js +3064 -0
- package/managers/error-auto-fix.manager.js.map +1 -0
- package/managers/local-log.manager.d.ts +18 -0
- package/managers/local-log.manager.js +88 -0
- package/managers/local-log.manager.js.map +1 -0
- package/managers/method.manager.d.ts +84 -0
- package/managers/method.manager.js +1964 -0
- package/managers/method.manager.js.map +1 -0
- package/managers/mongo.manager.d.ts +224 -0
- package/managers/mongo.manager.js +5000 -0
- package/managers/mongo.manager.js.map +1 -0
- package/managers/monitor.manager.d.ts +70 -0
- package/managers/monitor.manager.js +550 -0
- package/managers/monitor.manager.js.map +1 -0
- package/managers/openai-usage-ledger.manager.d.ts +30 -0
- package/managers/openai-usage-ledger.manager.js +142 -0
- package/managers/openai-usage-ledger.manager.js.map +1 -0
- package/managers/slow-query-verifier.manager.d.ts +144 -0
- package/managers/slow-query-verifier.manager.js +3857 -0
- package/managers/slow-query-verifier.manager.js.map +1 -0
- package/managers/slow-query.manager.d.ts +28 -0
- package/managers/slow-query.manager.js +468 -0
- package/managers/slow-query.manager.js.map +1 -0
- package/managers/subscription.manager.d.ts +169 -0
- package/managers/subscription.manager.js +3434 -0
- package/managers/subscription.manager.js.map +1 -0
- package/managers/websocket.manager.d.ts +73 -0
- package/managers/websocket.manager.js +673 -0
- package/managers/websocket.manager.js.map +1 -0
- package/managers/worker-dispatcher.manager.d.ts +120 -0
- package/managers/worker-dispatcher.manager.js +1266 -0
- package/managers/worker-dispatcher.manager.js.map +1 -0
- package/managers/worker-server.manager.d.ts +35 -0
- package/managers/worker-server.manager.js +582 -0
- package/managers/worker-server.manager.js.map +1 -0
- package/methods/accounts.d.ts +2 -0
- package/methods/accounts.js +624 -0
- package/methods/accounts.js.map +1 -0
- package/methods/ai-terminal.d.ts +458 -0
- package/methods/ai-terminal.js +27991 -0
- package/methods/ai-terminal.js.map +1 -0
- package/methods/app-settings.d.ts +2 -0
- package/methods/app-settings.js +169 -0
- package/methods/app-settings.js.map +1 -0
- package/methods/aws.d.ts +2 -0
- package/methods/aws.js +877 -0
- package/methods/aws.js.map +1 -0
- package/methods/collections.d.ts +2 -0
- package/methods/collections.js +719 -0
- package/methods/collections.js.map +1 -0
- package/methods/counters.d.ts +2 -0
- package/methods/counters.js +113 -0
- package/methods/counters.js.map +1 -0
- package/methods/cron-jobs.d.ts +2 -0
- package/methods/cron-jobs.js +2475 -0
- package/methods/cron-jobs.js.map +1 -0
- package/methods/customer-notifications.d.ts +2 -0
- package/methods/customer-notifications.js +528 -0
- package/methods/customer-notifications.js.map +1 -0
- package/methods/diagnostics.d.ts +2 -0
- package/methods/diagnostics.js +703 -0
- package/methods/diagnostics.js.map +1 -0
- package/methods/flag-updates.d.ts +2 -0
- package/methods/flag-updates.js +8 -0
- package/methods/flag-updates.js.map +1 -0
- package/methods/flags.d.ts +2 -0
- package/methods/flags.js +8 -0
- package/methods/flags.js.map +1 -0
- package/methods/logs.d.ts +2 -0
- package/methods/logs.js +751 -0
- package/methods/logs.js.map +1 -0
- package/methods/mongo-explorer.d.ts +2 -0
- package/methods/mongo-explorer.js +1808 -0
- package/methods/mongo-explorer.js.map +1 -0
- package/methods/monitor.d.ts +2 -0
- package/methods/monitor.js +543 -0
- package/methods/monitor.js.map +1 -0
- package/methods/pdf.d.ts +2 -0
- package/methods/pdf.js +1216 -0
- package/methods/pdf.js.map +1 -0
- package/methods/publications.d.ts +1 -0
- package/methods/publications.js +183 -0
- package/methods/publications.js.map +1 -0
- package/methods/report-builder.d.ts +2 -0
- package/methods/report-builder.js +3094 -0
- package/methods/report-builder.js.map +1 -0
- package/methods/support.d.ts +2 -0
- package/methods/support.js +430 -0
- package/methods/support.js.map +1 -0
- package/models/ai-run.model.d.ts +19 -0
- package/models/ai-run.model.js +4 -0
- package/models/ai-run.model.js.map +1 -0
- package/models/ai-terminal-conversation.model.d.ts +17 -0
- package/models/ai-terminal-conversation.model.js +4 -0
- package/models/ai-terminal-conversation.model.js.map +1 -0
- package/models/ai-terminal-issue-report.model.d.ts +19 -0
- package/models/ai-terminal-issue-report.model.js +4 -0
- package/models/ai-terminal-issue-report.model.js.map +1 -0
- package/models/ai-terminal-message.model.d.ts +22 -0
- package/models/ai-terminal-message.model.js +4 -0
- package/models/ai-terminal-message.model.js.map +1 -0
- package/models/app-setting.model.d.ts +16 -0
- package/models/app-setting.model.js +4 -0
- package/models/app-setting.model.js.map +1 -0
- package/{src/models/app-status.model.ts → models/app-status.model.d.ts} +2 -3
- package/models/app-status.model.js +4 -0
- package/models/app-status.model.js.map +1 -0
- package/{src/models/billing-logged-in-users.model.ts → models/billing-logged-in-users.model.d.ts} +4 -5
- package/models/billing-logged-in-users.model.js +4 -0
- package/models/billing-logged-in-users.model.js.map +1 -0
- package/models/collection-document.model.d.ts +21 -0
- package/models/collection-document.model.js +4 -0
- package/models/collection-document.model.js.map +1 -0
- package/models/communication-metric.model.d.ts +20 -0
- package/models/communication-metric.model.js +4 -0
- package/models/communication-metric.model.js.map +1 -0
- package/{src/models/counter.model.ts → models/counter.model.d.ts} +3 -4
- package/models/counter.model.js +4 -0
- package/models/counter.model.js.map +1 -0
- package/models/cron-job-history.model.d.ts +15 -0
- package/models/cron-job-history.model.js +4 -0
- package/models/cron-job-history.model.js.map +1 -0
- package/models/cron-job.model.d.ts +14 -0
- package/models/cron-job.model.js +4 -0
- package/models/cron-job.model.js.map +1 -0
- package/models/customer-notification.model.d.ts +26 -0
- package/models/customer-notification.model.js +4 -0
- package/models/customer-notification.model.js.map +1 -0
- package/models/customer-portal-password.model.d.ts +11 -0
- package/models/customer-portal-password.model.js +4 -0
- package/models/customer-portal-password.model.js.map +1 -0
- package/models/dialog.model.d.ts +23 -0
- package/models/dialog.model.js +4 -0
- package/models/dialog.model.js.map +1 -0
- package/models/email-history.model.d.ts +32 -0
- package/{src/models/email-history.model.ts → models/email-history.model.js} +4 -36
- package/models/email-history.model.js.map +1 -0
- package/{src/models/email-verified.model.ts → models/email-verified.model.d.ts} +5 -6
- package/models/email-verified.model.js +4 -0
- package/models/email-verified.model.js.map +1 -0
- package/{src/models/file.model.ts → models/file.model.d.ts} +7 -8
- package/models/file.model.js +4 -0
- package/models/file.model.js.map +1 -0
- package/{src/models/flag-update.model.ts → models/flag-update.model.d.ts} +3 -4
- package/models/flag-update.model.js +4 -0
- package/models/flag-update.model.js.map +1 -0
- package/{src/models/flag.model.ts → models/flag.model.d.ts} +3 -4
- package/models/flag.model.js +4 -0
- package/models/flag.model.js.map +1 -0
- package/models/log-method-latency.model.d.ts +10 -0
- package/models/log-method-latency.model.js +4 -0
- package/models/log-method-latency.model.js.map +1 -0
- package/{src/models/log-subscription.model.ts → models/log-subscription.model.d.ts} +9 -11
- package/models/log-subscription.model.js +4 -0
- package/models/log-subscription.model.js.map +1 -0
- package/models/log.model.d.ts +17 -0
- package/models/log.model.js +4 -0
- package/models/log.model.js.map +1 -0
- package/{src/models/logged-in-users.model.ts → models/logged-in-users.model.d.ts} +5 -6
- package/models/logged-in-users.model.js +4 -0
- package/models/logged-in-users.model.js.map +1 -0
- package/{src/models/method-response.model.ts → models/method-response.model.d.ts} +6 -7
- package/models/method-response.model.js +4 -0
- package/models/method-response.model.js.map +1 -0
- package/models/method.model.d.ts +26 -0
- package/models/method.model.js +4 -0
- package/models/method.model.js.map +1 -0
- package/{src/models/monitor-cpu.model.ts → models/monitor-cpu.model.d.ts} +7 -9
- package/models/monitor-cpu.model.js +4 -0
- package/models/monitor-cpu.model.js.map +1 -0
- package/models/monitor-function.model.d.ts +14 -0
- package/models/monitor-function.model.js +4 -0
- package/models/monitor-function.model.js.map +1 -0
- package/models/monitor-memory.model.d.ts +15 -0
- package/models/monitor-memory.model.js +4 -0
- package/models/monitor-memory.model.js.map +1 -0
- package/models/monitor-mongo.model.d.ts +13 -0
- package/models/monitor-mongo.model.js +4 -0
- package/models/monitor-mongo.model.js.map +1 -0
- package/{src/models/notification.model.ts → models/notification.model.d.ts} +4 -6
- package/models/notification.model.js +4 -0
- package/models/notification.model.js.map +1 -0
- package/models/openai-usage-ledger.model.d.ts +30 -0
- package/models/openai-usage-ledger.model.js +4 -0
- package/models/openai-usage-ledger.model.js.map +1 -0
- package/models/pagination.model.d.ts +11 -0
- package/models/pagination.model.js +28 -0
- package/models/pagination.model.js.map +1 -0
- package/models/permission.model.d.ts +12 -0
- package/models/permission.model.js +4 -0
- package/models/permission.model.js.map +1 -0
- package/models/report-builder-dashboard-builder.model.d.ts +25 -0
- package/models/report-builder-dashboard-builder.model.js +4 -0
- package/models/report-builder-dashboard-builder.model.js.map +1 -0
- package/models/report-builder-library.model.d.ts +17 -0
- package/models/report-builder-library.model.js +4 -0
- package/models/report-builder-library.model.js.map +1 -0
- package/models/report-builder-report.model.d.ts +121 -0
- package/models/report-builder-report.model.js +4 -0
- package/models/report-builder-report.model.js.map +1 -0
- package/models/report-builder.model.d.ts +61 -0
- package/models/report-builder.model.js +4 -0
- package/models/report-builder.model.js.map +1 -0
- package/models/select-data-label.model.d.ts +9 -0
- package/models/select-data-label.model.js +4 -0
- package/models/select-data-label.model.js.map +1 -0
- package/models/server-message.model.d.ts +32 -0
- package/models/server-message.model.js +4 -0
- package/models/server-message.model.js.map +1 -0
- package/models/slow-query-report.model.d.ts +23 -0
- package/models/slow-query-report.model.js +4 -0
- package/models/slow-query-report.model.js.map +1 -0
- package/models/subscription.model.d.ts +31 -0
- package/models/subscription.model.js +4 -0
- package/models/subscription.model.js.map +1 -0
- package/models/support-ticket.model.d.ts +87 -0
- package/models/support-ticket.model.js +4 -0
- package/models/support-ticket.model.js.map +1 -0
- package/models/user-group.model.d.ts +20 -0
- package/models/user-group.model.js +4 -0
- package/models/user-group.model.js.map +1 -0
- package/{src/models/user-guide.model.ts → models/user-guide.model.d.ts} +4 -5
- package/models/user-guide.model.js +4 -0
- package/models/user-guide.model.js.map +1 -0
- package/models/user.model.d.ts +84 -0
- package/models/user.model.js +4 -0
- package/models/user.model.js.map +1 -0
- package/package.json +1 -1
- package/private/images/ResolveIO.png +0 -0
- package/public_api.js +127 -0
- package/public_api.js.map +1 -0
- package/publications/ai-terminal.d.ts +1 -0
- package/publications/ai-terminal.js +122 -0
- package/publications/ai-terminal.js.map +1 -0
- package/publications/app-settings.d.ts +2 -0
- package/publications/app-settings.js +28 -0
- package/publications/app-settings.js.map +1 -0
- package/publications/app-status.d.ts +2 -0
- package/publications/app-status.js +16 -0
- package/publications/app-status.js.map +1 -0
- package/publications/cron-jobs.d.ts +2 -0
- package/publications/cron-jobs.js +88 -0
- package/publications/cron-jobs.js.map +1 -0
- package/publications/customer-notifications.d.ts +2 -0
- package/publications/customer-notifications.js +161 -0
- package/publications/customer-notifications.js.map +1 -0
- package/publications/files.d.ts +2 -0
- package/publications/files.js +36 -0
- package/publications/files.js.map +1 -0
- package/publications/flags-update.d.ts +2 -0
- package/publications/flags-update.js +22 -0
- package/publications/flags-update.js.map +1 -0
- package/publications/flags.d.ts +2 -0
- package/publications/flags.js +22 -0
- package/publications/flags.js.map +1 -0
- package/publications/logs.d.ts +2 -0
- package/publications/logs.js +164 -0
- package/publications/logs.js.map +1 -0
- package/publications/notifications.d.ts +2 -0
- package/publications/notifications.js +16 -0
- package/publications/notifications.js.map +1 -0
- package/publications/report-builder-dashboard-builders.d.ts +2 -0
- package/publications/report-builder-dashboard-builders.js +42 -0
- package/publications/report-builder-dashboard-builders.js.map +1 -0
- package/publications/report-builder-libraries.d.ts +2 -0
- package/publications/report-builder-libraries.js +90 -0
- package/publications/report-builder-libraries.js.map +1 -0
- package/publications/report-builder-reports.d.ts +2 -0
- package/publications/report-builder-reports.js +50 -0
- package/publications/report-builder-reports.js.map +1 -0
- package/publications/super-admin.d.ts +2 -0
- package/publications/super-admin.js +16 -0
- package/publications/super-admin.js.map +1 -0
- package/publications/user-groups.d.ts +1 -0
- package/publications/user-groups.js +16 -0
- package/publications/user-groups.js.map +1 -0
- package/publications/user-guides.d.ts +1 -0
- package/publications/user-guides.js +16 -0
- package/publications/user-guides.js.map +1 -0
- package/resolveio-server-app.d.ts +70 -0
- package/resolveio-server-app.js +801 -0
- package/resolveio-server-app.js.map +1 -0
- package/server-app.d.ts +228 -0
- package/server-app.js +3566 -0
- package/server-app.js.map +1 -0
- package/services/codex-client.d.ts +128 -0
- package/services/codex-client.js +1629 -0
- package/services/codex-client.js.map +1 -0
- package/services/openai-client.d.ts +46 -0
- package/services/openai-client.js +318 -0
- package/services/openai-client.js.map +1 -0
- package/types/error-report.d.ts +25 -0
- package/types/error-report.js +4 -0
- package/types/error-report.js.map +1 -0
- package/types/slow-query-report.d.ts +27 -0
- package/types/slow-query-report.js +6 -0
- package/types/slow-query-report.js.map +1 -0
- package/util/ai-qa-policy.d.ts +124 -0
- package/util/ai-qa-policy.js +736 -0
- package/util/ai-qa-policy.js.map +1 -0
- package/util/ai-run-evidence-adapters.d.ts +109 -0
- package/util/ai-run-evidence-adapters.js +7234 -0
- package/util/ai-run-evidence-adapters.js.map +1 -0
- package/util/ai-run-evidence-dashboard.d.ts +88 -0
- package/util/ai-run-evidence-dashboard.js +343 -0
- package/util/ai-run-evidence-dashboard.js.map +1 -0
- package/util/ai-run-evidence-eval.d.ts +86 -0
- package/util/ai-run-evidence-eval.js +1018 -0
- package/util/ai-run-evidence-eval.js.map +1 -0
- package/util/ai-run-evidence.d.ts +244 -0
- package/util/ai-run-evidence.js +1096 -0
- package/util/ai-run-evidence.js.map +1 -0
- package/util/ai-runner-artifacts.d.ts +82 -0
- package/util/ai-runner-artifacts.js +713 -0
- package/util/ai-runner-artifacts.js.map +1 -0
- package/util/ai-runner-manager-autopilot.d.ts +210 -0
- package/util/ai-runner-manager-autopilot.js +642 -0
- package/util/ai-runner-manager-autopilot.js.map +1 -0
- package/util/ai-runner-manager-policy.d.ts +807 -0
- package/util/ai-runner-manager-policy.js +3501 -0
- package/util/ai-runner-manager-policy.js.map +1 -0
- package/util/ai-runner-qa-auth.d.ts +5 -0
- package/util/ai-runner-qa-auth.js +839 -0
- package/util/ai-runner-qa-auth.js.map +1 -0
- package/util/ai-runner-qa-tools.d.ts +26 -0
- package/util/ai-runner-qa-tools.js +3520 -0
- package/util/ai-runner-qa-tools.js.map +1 -0
- package/util/aicoder-runner-v6.d.ts +426 -0
- package/util/aicoder-runner-v6.js +2464 -0
- package/util/aicoder-runner-v6.js.map +1 -0
- package/util/common.d.ts +31 -0
- package/util/common.js +683 -0
- package/util/common.js.map +1 -0
- package/util/customer-portal-password.d.ts +13 -0
- package/util/customer-portal-password.js +209 -0
- package/util/customer-portal-password.js.map +1 -0
- package/util/error-reporter.d.ts +52 -0
- package/util/error-reporter.js +326 -0
- package/util/error-reporter.js.map +1 -0
- package/util/error-tracking.d.ts +13 -0
- package/util/error-tracking.js +120 -0
- package/util/error-tracking.js.map +1 -0
- package/util/openai-usage-cost.d.ts +6 -0
- package/util/openai-usage-cost.js +103 -0
- package/util/openai-usage-cost.js.map +1 -0
- package/util/report-builder-unwinds.d.ts +15 -0
- package/util/report-builder-unwinds.js +156 -0
- package/util/report-builder-unwinds.js.map +1 -0
- package/util/runner-process-janitor.d.ts +27 -0
- package/util/runner-process-janitor.js +208 -0
- package/util/runner-process-janitor.js.map +1 -0
- package/util/schema-report-builder.d.ts +6 -0
- package/util/schema-report-builder.js +481 -0
- package/util/schema-report-builder.js.map +1 -0
- package/util/slow-query-reporter.d.ts +28 -0
- package/util/slow-query-reporter.js +226 -0
- package/util/slow-query-reporter.js.map +1 -0
- package/util/subscription-dependency-context.d.ts +34 -0
- package/util/subscription-dependency-context.js +1283 -0
- package/util/subscription-dependency-context.js.map +1 -0
- package/util/support-runner-v5.d.ts +1426 -0
- package/util/support-runner-v5.js +7647 -0
- package/util/support-runner-v5.js.map +1 -0
- package/util/tokenizer.d.ts +5 -0
- package/util/tokenizer.js +41 -0
- package/util/tokenizer.js.map +1 -0
- package/workers/codex-runner.worker.d.ts +1 -0
- package/workers/codex-runner.worker.js +192 -0
- package/workers/codex-runner.worker.js.map +1 -0
- package/.nodemon.json +0 -5
- package/.vscode/settings.json +0 -21
- package/AGENTS.md +0 -195
- package/README.md +0 -22
- package/build_package.sh +0 -5
- package/compileDTS.pl +0 -64
- package/docs/ai-assistant-nightly-eval.md +0 -65
- package/docs/ai-assistant-preflight-checklist.md +0 -23
- package/docs/ai-assistant-report-builder-bridge-playbook.md +0 -115
- package/eslint-plugin-custom/index.js +0 -7
- package/eslint-plugin-custom/rules/no-filter-zero-index.js +0 -44
- package/eslint.config.js +0 -103
- package/gulpfile.js +0 -216
- package/methodAndPublicationListGenerator.py +0 -375
- package/mongodbensurers.js +0 -2
- package/mongostop.js +0 -3
- package/scripts/cleanup-bypassed-callmethod-logs.js +0 -616
- package/settings.development.json +0 -25
- package/settings.development.redacted.json +0 -25
- package/src/.env +0 -12
- package/src/ai/assistant-core-heuristics.ts +0 -379
- package/src/ai/resolveio-platform-intelligence-memory-corpus.ts +0 -185
- package/src/ai/resolveio-platform-intelligence-memory.ts +0 -325
- package/src/ai/resolveio-platform-intelligence.ts +0 -462
- package/src/client-server-app.ts +0 -12
- package/src/collections/ai-run.collection.ts +0 -117
- package/src/collections/ai-terminal-conversation.collection.ts +0 -91
- package/src/collections/ai-terminal-issue-report.collection.ts +0 -99
- package/src/collections/ai-terminal-message.collection.ts +0 -77
- package/src/collections/app-setting.collection.ts +0 -104
- package/src/collections/app-status.collection.ts +0 -58
- package/src/collections/communication-metric.collection.ts +0 -84
- package/src/collections/counter.collection.ts +0 -56
- package/src/collections/cron-job-history.collection.ts +0 -94
- package/src/collections/cron-job.collection.ts +0 -92
- package/src/collections/customer-notification.collection.ts +0 -131
- package/src/collections/customer-portal-password.collection.ts +0 -76
- package/src/collections/email-history.collection.ts +0 -134
- package/src/collections/email-verified.collection.ts +0 -62
- package/src/collections/file.collection.ts +0 -74
- package/src/collections/flag-update.collection.ts +0 -57
- package/src/collections/flag.collection.ts +0 -57
- package/src/collections/log-method-latency.collection.ts +0 -77
- package/src/collections/log-subscription.collection.ts +0 -80
- package/src/collections/log.collection.ts +0 -93
- package/src/collections/logged-in-users.collection.ts +0 -67
- package/src/collections/monitor-cpu.collection.ts +0 -65
- package/src/collections/monitor-function.collection.ts +0 -74
- package/src/collections/monitor-memory.collection.ts +0 -77
- package/src/collections/monitor-mongo.collection.ts +0 -71
- package/src/collections/notification.collection.ts +0 -57
- package/src/collections/openai-usage-ledger.collection.ts +0 -131
- package/src/collections/report-builder-dashboard-builder.collection.ts +0 -109
- package/src/collections/report-builder-library.collection.ts +0 -89
- package/src/collections/report-builder-report.collection.ts +0 -184
- package/src/collections/user-group.collection.ts +0 -89
- package/src/collections/user-guide.collection.ts +0 -57
- package/src/collections/user.collection.ts +0 -181
- package/src/cron/cron.ts +0 -117
- package/src/fixtures/cron-jobs.ts +0 -95
- package/src/fixtures/init.ts +0 -35
- package/src/http/auth.ts +0 -818
- package/src/http/health.ts +0 -7
- package/src/http/home.ts +0 -90
- package/src/http/slow-query-publication.ts +0 -49
- package/src/index.ts +0 -1
- package/src/managers/ai-assistant-codex-manager.manager.ts +0 -1131
- package/src/managers/ai-run-evidence.manager.ts +0 -264
- package/src/managers/communication-metric.manager.ts +0 -82
- package/src/managers/cron.manager.ts +0 -333
- package/src/managers/customer-notification-content.manager.ts +0 -236
- package/src/managers/diagnostic-manager-bootstrap.ts +0 -165
- package/src/managers/error-auto-fix.manager.ts +0 -2767
- package/src/managers/local-log.manager.ts +0 -113
- package/src/managers/method.manager.ts +0 -1857
- package/src/managers/mongo.manager.ts +0 -4575
- package/src/managers/monitor.manager.ts +0 -507
- package/src/managers/openai-usage-ledger.manager.ts +0 -112
- package/src/managers/slow-query-verifier.manager.ts +0 -3590
- package/src/managers/slow-query.manager.ts +0 -519
- package/src/managers/subscription.manager.ts +0 -3128
- package/src/managers/websocket.manager.ts +0 -746
- package/src/managers/worker-dispatcher.manager.ts +0 -1360
- package/src/managers/worker-server.manager.ts +0 -536
- package/src/methods/accounts.ts +0 -532
- package/src/methods/ai-terminal.ts +0 -29070
- package/src/methods/app-settings.ts +0 -114
- package/src/methods/aws.ts +0 -649
- package/src/methods/collections.ts +0 -641
- package/src/methods/counters.ts +0 -69
- package/src/methods/cron-jobs.ts +0 -2614
- package/src/methods/customer-notifications.ts +0 -458
- package/src/methods/diagnostics.ts +0 -616
- package/src/methods/flag-updates.ts +0 -7
- package/src/methods/flags.ts +0 -7
- package/src/methods/logs.ts +0 -657
- package/src/methods/mongo-explorer.ts +0 -1880
- package/src/methods/monitor.ts +0 -540
- package/src/methods/pdf.ts +0 -1236
- package/src/methods/publications.ts +0 -129
- package/src/methods/report-builder.ts +0 -3300
- package/src/methods/support.ts +0 -335
- package/src/models/ai-run.model.ts +0 -27
- package/src/models/ai-terminal-conversation.model.ts +0 -19
- package/src/models/ai-terminal-issue-report.model.ts +0 -21
- package/src/models/ai-terminal-message.model.ts +0 -24
- package/src/models/app-setting.model.ts +0 -17
- package/src/models/collection-document.model.ts +0 -24
- package/src/models/communication-metric.model.ts +0 -23
- package/src/models/cron-job-history.model.ts +0 -16
- package/src/models/cron-job.model.ts +0 -15
- package/src/models/customer-notification.model.ts +0 -28
- package/src/models/customer-portal-password.model.ts +0 -12
- package/src/models/dialog.model.ts +0 -25
- package/src/models/log-method-latency.model.ts +0 -11
- package/src/models/log.model.ts +0 -19
- package/src/models/method.model.ts +0 -25
- package/src/models/monitor-function.model.ts +0 -16
- package/src/models/monitor-memory.model.ts +0 -17
- package/src/models/monitor-mongo.model.ts +0 -15
- package/src/models/openai-usage-ledger.model.ts +0 -56
- package/src/models/pagination.model.ts +0 -35
- package/src/models/permission.model.ts +0 -14
- package/src/models/report-builder-dashboard-builder.model.ts +0 -29
- package/src/models/report-builder-library.model.ts +0 -20
- package/src/models/report-builder-report.model.ts +0 -136
- package/src/models/report-builder.model.ts +0 -68
- package/src/models/select-data-label.model.ts +0 -9
- package/src/models/server-message.model.ts +0 -31
- package/src/models/slow-query-report.model.ts +0 -23
- package/src/models/subscription.model.ts +0 -73
- package/src/models/support-ticket.model.ts +0 -104
- package/src/models/user-group.model.ts +0 -24
- package/src/models/user.model.ts +0 -96
- package/src/private/images/ResolveIO.png +0 -0
- package/src/publications/ai-terminal.ts +0 -73
- package/src/publications/app-settings.ts +0 -25
- package/src/publications/app-status.ts +0 -13
- package/src/publications/cron-jobs.ts +0 -40
- package/src/publications/customer-notifications.ts +0 -101
- package/src/publications/files.ts +0 -33
- package/src/publications/flags-update.ts +0 -19
- package/src/publications/flags.ts +0 -19
- package/src/publications/logs.ts +0 -163
- package/src/publications/notifications.ts +0 -13
- package/src/publications/report-builder-dashboard-builders.ts +0 -39
- package/src/publications/report-builder-libraries.ts +0 -41
- package/src/publications/report-builder-reports.ts +0 -47
- package/src/publications/super-admin.ts +0 -13
- package/src/publications/user-groups.ts +0 -12
- package/src/publications/user-guides.ts +0 -12
- package/src/resolveio-server-app.ts +0 -617
- package/src/server-app.ts +0 -3354
- package/src/services/codex-client.ts +0 -1231
- package/src/services/openai-client.ts +0 -265
- package/src/types/error-report.ts +0 -26
- package/src/types/js-tiktoken.d.ts +0 -11
- package/src/types/slow-query-report.ts +0 -28
- package/src/util/ai-qa-policy.ts +0 -925
- package/src/util/ai-run-evidence-adapters.ts +0 -8347
- package/src/util/ai-run-evidence-dashboard.ts +0 -323
- package/src/util/ai-run-evidence-eval.ts +0 -1057
- package/src/util/ai-run-evidence.ts +0 -1430
- package/src/util/ai-runner-artifacts.ts +0 -586
- package/src/util/ai-runner-manager-autopilot.ts +0 -961
- package/src/util/ai-runner-manager-policy.ts +0 -5011
- package/src/util/ai-runner-qa-auth.ts +0 -838
- package/src/util/ai-runner-qa-tools.ts +0 -3536
- package/src/util/aicoder-runner-v6.ts +0 -3121
- package/src/util/common.ts +0 -649
- package/src/util/customer-portal-password.ts +0 -183
- package/src/util/error-reporter.ts +0 -332
- package/src/util/error-tracking.ts +0 -79
- package/src/util/openai-usage-cost.ts +0 -114
- package/src/util/report-builder-unwinds.ts +0 -180
- package/src/util/runner-process-janitor.ts +0 -219
- package/src/util/schema-report-builder.ts +0 -448
- package/src/util/slow-query-reporter.ts +0 -216
- package/src/util/subscription-dependency-context.ts +0 -1096
- package/src/util/support-runner-v5.ts +0 -10040
- package/src/util/tokenizer.ts +0 -38
- package/src/workers/codex-runner.worker.ts +0 -142
- package/start_server.sh +0 -5
- package/tests/ai-assistant-corpus-build.ts +0 -484
- package/tests/ai-assistant-corpus-replay-e2e.ts +0 -774
- package/tests/ai-assistant-data-parity-e2e.ts +0 -1989
- package/tests/ai-assistant-eval-triage.ts +0 -831
- package/tests/ai-assistant-openai-e2e.ts +0 -1061
- package/tests/ai-assistant-openai-git-e2e.ts +0 -155
- package/tests/ai-assistant-preflight-matrix.ts +0 -215
- package/tests/ai-assistant-routing-eval.test.ts +0 -585
- package/tests/ai-assistant-snf-live-eval.ts +0 -975
- package/tests/ai-assistant-utils.test.ts +0 -4834
- package/tests/ai-manager-autopilot-snapshot.test.ts +0 -193
- package/tests/ai-manager-recovery-checkpoint.test.ts +0 -1383
- package/tests/ai-run-eval.test.ts +0 -132
- package/tests/ai-run-evidence.test.ts +0 -3773
- package/tests/ai-runner-contract.test.ts +0 -515
- package/tests/aicoder-runner-v6.test.ts +0 -822
- package/tests/error-reporter.test.ts +0 -145
- package/tests/method-publication-generator.test.ts +0 -46
- package/tests/report-builder-linking.test.ts +0 -79
- package/tests/resolveio-platform-intelligence.test.ts +0 -352
- package/tests/server-app-cron-owner.test.ts +0 -127
- package/tests/subscription-connect-race.test.ts +0 -158
- package/tests/subscription-dependency-context.test.ts +0 -324
- package/tests/subscription-manager-collection-tracking.test.ts +0 -86
- package/tests/subscription-manager-invalidation.test.ts +0 -86
- package/tests/support-runner-v5.test.ts +0 -3201
- package/tsconfig.json +0 -34
- /package/{src/private → private}/email-templates/enrollment.html +0 -0
- /package/{src/private → private}/email-templates/forgot-password.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket-deleted.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket-modified.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket.html +0 -0
- /package/{src/public_api.ts → public_api.d.ts} +0 -0
|
@@ -0,0 +1,2475 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __values = (this && this.__values) || function(o) {
|
|
50
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
+
if (m) return m.call(o);
|
|
52
|
+
if (o && typeof o.length === "number") return {
|
|
53
|
+
next: function () {
|
|
54
|
+
if (o && i >= o.length) o = void 0;
|
|
55
|
+
return { value: o && o[i++], done: !o };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
+
};
|
|
60
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
61
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
62
|
+
if (!m) return o;
|
|
63
|
+
var i = m.call(o), r, ar = [], e;
|
|
64
|
+
try {
|
|
65
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
66
|
+
}
|
|
67
|
+
catch (error) { e = { error: error }; }
|
|
68
|
+
finally {
|
|
69
|
+
try {
|
|
70
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
71
|
+
}
|
|
72
|
+
finally { if (e) throw e.error; }
|
|
73
|
+
}
|
|
74
|
+
return ar;
|
|
75
|
+
};
|
|
76
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
77
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
78
|
+
if (ar || !(i in from)) {
|
|
79
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
80
|
+
ar[i] = from[i];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
84
|
+
};
|
|
85
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
+
exports.loadCronJobMethods = loadCronJobMethods;
|
|
87
|
+
var axios_1 = require("axios");
|
|
88
|
+
var Excel = require("exceljs");
|
|
89
|
+
var moment = require("moment-timezone");
|
|
90
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
91
|
+
var cron_job_collection_1 = require("../collections/cron-job.collection");
|
|
92
|
+
var communication_metric_collection_1 = require("../collections/communication-metric.collection");
|
|
93
|
+
var file_collection_1 = require("../collections/file.collection");
|
|
94
|
+
var openai_usage_ledger_collection_1 = require("../collections/openai-usage-ledger.collection");
|
|
95
|
+
var report_builder_report_collection_1 = require("../collections/report-builder-report.collection");
|
|
96
|
+
var resolveio_server_app_1 = require("../resolveio-server-app");
|
|
97
|
+
var common_1 = require("../util/common");
|
|
98
|
+
function getFilterTargets(fieldPath, report) {
|
|
99
|
+
if (!fieldPath) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
if (fieldPath.startsWith('layout_col_')) {
|
|
103
|
+
var normalized = fieldPath.replace(/^layout_col_/, '');
|
|
104
|
+
var parts = normalized.split('_');
|
|
105
|
+
var idx_1 = parseInt(parts[parts.length - 1], 10);
|
|
106
|
+
if (!isNaN(idx_1)) {
|
|
107
|
+
var layoutTargets = ((report === null || report === void 0 ? void 0 : report.fields_selected) || [])
|
|
108
|
+
.filter(function (f) { return f && (f.layoutColumnIndex === idx_1 || (f.id || '').includes("f_layout_".concat(idx_1, "_"))); })
|
|
109
|
+
.map(function (f) { return f.fieldPath; });
|
|
110
|
+
if (layoutTargets.length) {
|
|
111
|
+
return layoutTargets;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return [fieldPath];
|
|
116
|
+
}
|
|
117
|
+
function buildFilterExpression(filter, path) {
|
|
118
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
119
|
+
if (!filter || !filter.condition || (!filter.field && !path)) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
var hasValue = filter.value !== null && (Array.isArray(filter.value) ? filter.value.length > 0 : true);
|
|
123
|
+
if (!hasValue && filter.condition !== 'null' && filter.condition !== 'nnull') {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
if (filter.condition === 'bw') {
|
|
127
|
+
if (filter.fieldType === 'Date' && filter.is_rolling) {
|
|
128
|
+
var startDate = null;
|
|
129
|
+
var endDate = null;
|
|
130
|
+
if (filter.rolling_interval === 'Q1') {
|
|
131
|
+
startDate = moment().startOf('year').toDate();
|
|
132
|
+
endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
|
|
133
|
+
}
|
|
134
|
+
else if (filter.rolling_interval === 'Q2') {
|
|
135
|
+
startDate = moment().startOf('year').quarter(2).toDate();
|
|
136
|
+
endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
|
|
137
|
+
}
|
|
138
|
+
else if (filter.rolling_interval === 'Q3') {
|
|
139
|
+
startDate = moment().startOf('year').quarter(3).toDate();
|
|
140
|
+
endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
|
|
141
|
+
}
|
|
142
|
+
else if (filter.rolling_interval === 'Q4') {
|
|
143
|
+
startDate = moment().startOf('year').quarter(4).toDate();
|
|
144
|
+
endDate = moment().endOf('year').toDate();
|
|
145
|
+
}
|
|
146
|
+
else if (filter.rolling_interval === 'Today') {
|
|
147
|
+
startDate = moment().startOf('day').toDate();
|
|
148
|
+
endDate = moment().endOf('day').toDate();
|
|
149
|
+
}
|
|
150
|
+
else if (filter.rolling_interval === 'Yesterday') {
|
|
151
|
+
startDate = moment().subtract(1, 'days').startOf('day').toDate();
|
|
152
|
+
endDate = moment().subtract(1, 'days').endOf('day').toDate();
|
|
153
|
+
}
|
|
154
|
+
else if (filter.rolling_interval === 'Week') {
|
|
155
|
+
startDate = moment().startOf('isoWeek').toDate();
|
|
156
|
+
endDate = moment().endOf('day').toDate();
|
|
157
|
+
}
|
|
158
|
+
else if (filter.rolling_interval === 'Last Week') {
|
|
159
|
+
endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
|
|
160
|
+
startDate = moment(endDate).startOf('isoWeek').toDate();
|
|
161
|
+
}
|
|
162
|
+
else if (filter.rolling_interval === 'Month') {
|
|
163
|
+
startDate = moment().startOf('month').toDate();
|
|
164
|
+
endDate = moment().endOf('day').toDate();
|
|
165
|
+
}
|
|
166
|
+
else if (filter.rolling_interval === 'Last Month') {
|
|
167
|
+
endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
|
|
168
|
+
startDate = moment(endDate).startOf('month').toDate();
|
|
169
|
+
}
|
|
170
|
+
else if (filter.rolling_interval === 'Last 30 Days') {
|
|
171
|
+
endDate = moment().endOf('day').toDate();
|
|
172
|
+
startDate = moment().subtract(30, 'days').startOf('day').toDate();
|
|
173
|
+
}
|
|
174
|
+
else if (filter.rolling_interval === 'Quarter') {
|
|
175
|
+
startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
|
|
176
|
+
endDate = moment().endOf('day').toDate();
|
|
177
|
+
}
|
|
178
|
+
else if (filter.rolling_interval === 'Last Quarter') {
|
|
179
|
+
endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
|
|
180
|
+
startDate = moment(endDate).startOf('quarter').toDate();
|
|
181
|
+
}
|
|
182
|
+
else if (filter.rolling_interval === 'Year') {
|
|
183
|
+
startDate = moment().startOf('year').toDate();
|
|
184
|
+
endDate = moment().endOf('day').toDate();
|
|
185
|
+
}
|
|
186
|
+
else if (filter.rolling_interval === 'Last Year') {
|
|
187
|
+
endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
|
|
188
|
+
startDate = moment(endDate).startOf('year').toDate();
|
|
189
|
+
}
|
|
190
|
+
else if (filter.rolling_interval === 'All') {
|
|
191
|
+
startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
|
|
192
|
+
endDate = moment().endOf('day').toDate();
|
|
193
|
+
}
|
|
194
|
+
return { $and: [(_a = {}, _a[path] = { '$gte': startDate }, _a), (_b = {}, _b[path] = { '$lte': endDate }, _b)] };
|
|
195
|
+
}
|
|
196
|
+
return { $and: [(_c = {}, _c[path] = { '$gte': filter.value }, _c), (_d = {}, _d[path] = { '$lte': filter.highValue }, _d)] };
|
|
197
|
+
}
|
|
198
|
+
else if (filter.condition === 'nnull') {
|
|
199
|
+
var and = [];
|
|
200
|
+
and.push((_e = {}, _e[path] = { '$exists': true }, _e));
|
|
201
|
+
and.push((_f = {}, _f[path] = { '$ne': null }, _f));
|
|
202
|
+
if (filter.fieldType === 'String') {
|
|
203
|
+
and.push((_g = {}, _g[path] = { '$ne': '' }, _g));
|
|
204
|
+
}
|
|
205
|
+
return { $and: and };
|
|
206
|
+
}
|
|
207
|
+
else if (filter.condition === 'null') {
|
|
208
|
+
return _h = {}, _h[path] = { '$eq': null }, _h;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
if (Array.isArray(filter.value)) {
|
|
212
|
+
if (filter.condition === 'ne') {
|
|
213
|
+
var and_1 = [];
|
|
214
|
+
filter.value.forEach(function (filt) {
|
|
215
|
+
var _a, _b;
|
|
216
|
+
and_1.push((_a = {}, _a[path] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
217
|
+
});
|
|
218
|
+
if (and_1.length > 1) {
|
|
219
|
+
return { $and: and_1 };
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
return and_1[0];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
var or_1 = [];
|
|
227
|
+
filter.value.forEach(function (filt) {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
or_1.push((_a = {}, _a[path] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
230
|
+
});
|
|
231
|
+
if (or_1.length > 1) {
|
|
232
|
+
return { $or: or_1 };
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
return or_1[0];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return _j = {}, _j[path] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
function parseLayoutColIndex(fieldRef) {
|
|
246
|
+
if (!fieldRef || !fieldRef.startsWith('layout_col_')) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
var normalized = fieldRef.replace(/^layout_col_/, '');
|
|
250
|
+
var parts = normalized.split('_');
|
|
251
|
+
var idx = parseInt(parts[parts.length - 1], 10);
|
|
252
|
+
return isNaN(idx) ? null : idx;
|
|
253
|
+
}
|
|
254
|
+
function resolveLayoutColumnPrimaryLeafId(fieldRef, report) {
|
|
255
|
+
var idx = parseLayoutColIndex(fieldRef);
|
|
256
|
+
if (idx === null) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
var candidates = ((report === null || report === void 0 ? void 0 : report.fields_selected) || []).filter(function (f) { return f && typeof f.layoutColumnIndex !== 'undefined' && f.layoutColumnIndex === idx; });
|
|
260
|
+
if (!candidates.length) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
var root = report === null || report === void 0 ? void 0 : report.collection_root;
|
|
264
|
+
var preferred = candidates.find(function (c) { return c.collection_name === root || c.layoutCollection === root; }) || candidates[0];
|
|
265
|
+
return (preferred === null || preferred === void 0 ? void 0 : preferred.id) || null;
|
|
266
|
+
}
|
|
267
|
+
function resolveFieldRefToLeafId(fieldRef, report) {
|
|
268
|
+
if (!fieldRef) {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
if (fieldRef.startsWith('layout_col_')) {
|
|
272
|
+
return resolveLayoutColumnPrimaryLeafId(fieldRef, report);
|
|
273
|
+
}
|
|
274
|
+
return fieldRef;
|
|
275
|
+
}
|
|
276
|
+
function buildCollectionKeysFromReport(report) {
|
|
277
|
+
var keys = [];
|
|
278
|
+
if (report === null || report === void 0 ? void 0 : report.collection_root) {
|
|
279
|
+
keys.push(report.collection_root);
|
|
280
|
+
}
|
|
281
|
+
((report === null || report === void 0 ? void 0 : report.collection_joins) || []).forEach(function (join) {
|
|
282
|
+
if (!join) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
var alias = (join.alias || '').trim();
|
|
286
|
+
if (alias && !keys.includes(alias)) {
|
|
287
|
+
keys.push(alias);
|
|
288
|
+
}
|
|
289
|
+
else if (join.collection && !keys.includes(join.collection)) {
|
|
290
|
+
keys.push(join.collection);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
return keys.length ? keys : ['root'];
|
|
294
|
+
}
|
|
295
|
+
function buildLayoutColumnsFromFields(report, fields) {
|
|
296
|
+
if (fields === void 0) { fields = []; }
|
|
297
|
+
var keys = buildCollectionKeysFromReport(report);
|
|
298
|
+
return (fields || []).map(function (field, index) {
|
|
299
|
+
var header = field.columnName || field.fieldName || "Column ".concat(index + 1);
|
|
300
|
+
var isCustom = (((field === null || field === void 0 ? void 0 : field.id) || (field === null || field === void 0 ? void 0 : field.fieldPath) || '') + '').startsWith('c_') || (field === null || field === void 0 ? void 0 : field.fieldPathName) === 'Custom Field';
|
|
301
|
+
var mappings = keys.map(function (key) {
|
|
302
|
+
var matchesKey = key === report.collection_root
|
|
303
|
+
? (field.collection_name === report.collection_root || isCustom)
|
|
304
|
+
: (key === (field.lookup_as || '').trim()) || key === field.collection_name;
|
|
305
|
+
if (matchesKey) {
|
|
306
|
+
return {
|
|
307
|
+
collection: key,
|
|
308
|
+
mode: 'variable',
|
|
309
|
+
fieldPath: field.fieldPath || '',
|
|
310
|
+
fieldId: field.id || "f_layout_".concat(index),
|
|
311
|
+
text: '',
|
|
312
|
+
leafValueType: field.leafValueType || 'Value',
|
|
313
|
+
leafFormatType: field.leafFormatType || ''
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
collection: key,
|
|
318
|
+
mode: 'text',
|
|
319
|
+
fieldPath: '',
|
|
320
|
+
fieldId: '',
|
|
321
|
+
text: '',
|
|
322
|
+
leafValueType: 'Value',
|
|
323
|
+
leafFormatType: ''
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
return {
|
|
327
|
+
id: field.id ? "layout_".concat(field.id) : "layout_".concat(index),
|
|
328
|
+
header: header,
|
|
329
|
+
mappings: mappings
|
|
330
|
+
};
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function ensureLayoutHasCustomField(report, layout, customId, columnName, leafValueType) {
|
|
334
|
+
if (layout === void 0) { layout = []; }
|
|
335
|
+
if (!layout || !customId) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
var hasCustomField = (layout || []).some(function (col) { return ((col === null || col === void 0 ? void 0 : col.mappings) || []).some(function (m) {
|
|
339
|
+
return (m === null || m === void 0 ? void 0 : m.mode) === 'variable' && (m.fieldId === customId || m.fieldPath === customId);
|
|
340
|
+
}); });
|
|
341
|
+
if (hasCustomField) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
var keys = buildCollectionKeysFromReport(report);
|
|
345
|
+
var rootKey = (report === null || report === void 0 ? void 0 : report.collection_root) || '';
|
|
346
|
+
var header = columnName || customId;
|
|
347
|
+
var mappings = keys.map(function (key) {
|
|
348
|
+
if (key === rootKey) {
|
|
349
|
+
return {
|
|
350
|
+
collection: key,
|
|
351
|
+
mode: 'variable',
|
|
352
|
+
fieldPath: customId,
|
|
353
|
+
fieldId: customId,
|
|
354
|
+
text: '',
|
|
355
|
+
leafValueType: leafValueType || 'Value',
|
|
356
|
+
leafFormatType: 'Number'
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
collection: key,
|
|
361
|
+
mode: 'text',
|
|
362
|
+
fieldPath: '',
|
|
363
|
+
fieldId: '',
|
|
364
|
+
text: '',
|
|
365
|
+
leafValueType: 'Value',
|
|
366
|
+
leafFormatType: ''
|
|
367
|
+
};
|
|
368
|
+
});
|
|
369
|
+
layout.push({
|
|
370
|
+
id: "layout_".concat(customId),
|
|
371
|
+
header: header,
|
|
372
|
+
mappings: mappings
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
function ensureLayoutIncludesCustomFields(report, layout) {
|
|
376
|
+
if (layout === void 0) { layout = []; }
|
|
377
|
+
var fieldsCustom = (report === null || report === void 0 ? void 0 : report.fields_custom) || [];
|
|
378
|
+
if (!fieldsCustom.length) {
|
|
379
|
+
return layout;
|
|
380
|
+
}
|
|
381
|
+
fieldsCustom.forEach(function (custom) {
|
|
382
|
+
ensureLayoutHasCustomField(report, layout, custom === null || custom === void 0 ? void 0 : custom.id, custom === null || custom === void 0 ? void 0 : custom.columnName, custom === null || custom === void 0 ? void 0 : custom.leafValueType);
|
|
383
|
+
});
|
|
384
|
+
return layout;
|
|
385
|
+
}
|
|
386
|
+
function getLayoutColumnsFromReport(report) {
|
|
387
|
+
var layout = [];
|
|
388
|
+
if ((report === null || report === void 0 ? void 0 : report.fields_layout) && report.fields_layout.length) {
|
|
389
|
+
layout = (0, common_1.deepCopy)(report.fields_layout);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
layout = buildLayoutColumnsFromFields(report, (report === null || report === void 0 ? void 0 : report.fields_selected) || []);
|
|
393
|
+
}
|
|
394
|
+
return ensureLayoutIncludesCustomFields(report, layout);
|
|
395
|
+
}
|
|
396
|
+
function syncSelectedFieldsFromLayout(report, layoutColumns) {
|
|
397
|
+
if (layoutColumns === void 0) { layoutColumns = []; }
|
|
398
|
+
var fields = [];
|
|
399
|
+
var sourceFields = (0, common_1.deepCopy)((report === null || report === void 0 ? void 0 : report.fields_selected) || []);
|
|
400
|
+
var byId = new Map();
|
|
401
|
+
var byPath = new Map();
|
|
402
|
+
sourceFields.forEach(function (f) {
|
|
403
|
+
if (f === null || f === void 0 ? void 0 : f.id) {
|
|
404
|
+
byId.set(f.id, f);
|
|
405
|
+
}
|
|
406
|
+
if (f === null || f === void 0 ? void 0 : f.fieldPath) {
|
|
407
|
+
byPath.set(f.fieldPath, f);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
layoutColumns.forEach(function (col, colIndex) {
|
|
411
|
+
(col.mappings || []).forEach(function (map, mapIndex) {
|
|
412
|
+
if (map.mode === 'variable' && map.fieldPath) {
|
|
413
|
+
var baseField = byId.get(map.fieldId) || byPath.get(map.fieldPath);
|
|
414
|
+
if (!baseField) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
var clone = (0, common_1.deepCopy)(baseField);
|
|
418
|
+
clone.columnName = col.header || baseField.columnName || baseField.fieldPathName || 'Column';
|
|
419
|
+
clone.show = (typeof map.show === 'boolean')
|
|
420
|
+
? map.show
|
|
421
|
+
: (typeof baseField.show === 'boolean' ? baseField.show : true);
|
|
422
|
+
clone.leafValueType = map.leafValueType || clone.leafValueType;
|
|
423
|
+
clone.leafFormatType = map.leafFormatType || clone.leafFormatType;
|
|
424
|
+
clone.id = map.fieldId || clone.id || "f_layout_".concat(colIndex, "_").concat(mapIndex);
|
|
425
|
+
clone.layoutCollection = map.collection;
|
|
426
|
+
clone.layoutColumnIndex = colIndex;
|
|
427
|
+
if (!map.fieldId) {
|
|
428
|
+
map.fieldId = clone.id;
|
|
429
|
+
}
|
|
430
|
+
fields.push(clone);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
return fields;
|
|
435
|
+
}
|
|
436
|
+
function materializeLayoutRow(report, layoutColumns, selectedFields, row) {
|
|
437
|
+
var materialized = { _id: row === null || row === void 0 ? void 0 : row._id };
|
|
438
|
+
var hasDataForCollection = function (collection) {
|
|
439
|
+
if (!collection) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
return (selectedFields || []).some(function (f) {
|
|
443
|
+
return f.layoutCollection === collection &&
|
|
444
|
+
row &&
|
|
445
|
+
Object.prototype.hasOwnProperty.call(row, f.id) &&
|
|
446
|
+
row[f.id] !== undefined &&
|
|
447
|
+
row[f.id] !== null &&
|
|
448
|
+
row[f.id] !== '';
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
(layoutColumns || []).forEach(function (col, colIndex) {
|
|
452
|
+
var values = [];
|
|
453
|
+
(col.mappings || []).forEach(function (map) {
|
|
454
|
+
if (map.mode === 'text' && map.text) {
|
|
455
|
+
if (hasDataForCollection(map.collection)) {
|
|
456
|
+
values.push({ collection: map.collection, value: map.text });
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
else if (map.mode === 'variable' && map.fieldId && row && Object.prototype.hasOwnProperty.call(row, map.fieldId)) {
|
|
460
|
+
values.push({ collection: map.collection, value: row[map.fieldId] });
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
materialized[colIndex] = values;
|
|
464
|
+
});
|
|
465
|
+
return materialized;
|
|
466
|
+
}
|
|
467
|
+
function getLayoutCellExportValue(report, layoutRow, colIndex) {
|
|
468
|
+
if (!layoutRow || layoutRow[colIndex] === undefined || layoutRow[colIndex] === null) {
|
|
469
|
+
return '';
|
|
470
|
+
}
|
|
471
|
+
var cellValues = Array.isArray(layoutRow[colIndex]) ? layoutRow[colIndex] : [layoutRow[colIndex]];
|
|
472
|
+
var filtered = cellValues.filter(function (v) { return v !== undefined && v !== null && v.value !== undefined && v.value !== null && v.value !== ''; });
|
|
473
|
+
if (!filtered.length) {
|
|
474
|
+
return '';
|
|
475
|
+
}
|
|
476
|
+
var rootCollection = report === null || report === void 0 ? void 0 : report.collection_root;
|
|
477
|
+
var preferred = filtered.find(function (v) { return v.collection === rootCollection; }) || filtered[0];
|
|
478
|
+
var value = preferred === null || preferred === void 0 ? void 0 : preferred.value;
|
|
479
|
+
if (value === undefined || value === null) {
|
|
480
|
+
return '';
|
|
481
|
+
}
|
|
482
|
+
if (Array.isArray(value)) {
|
|
483
|
+
return value;
|
|
484
|
+
}
|
|
485
|
+
return typeof value === 'string' ? value.trim().replace(/\t/g, '').replace(/\n/g, '') : value;
|
|
486
|
+
}
|
|
487
|
+
function getPrimaryFieldForLayoutColumn(col, selectedFields) {
|
|
488
|
+
if (!(col === null || col === void 0 ? void 0 : col.mappings)) {
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
var target = col.mappings.find(function (m) { return m.mode === 'variable' && m.fieldId; });
|
|
492
|
+
if (!target) {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
return (selectedFields || []).find(function (f) { return f.id === target.fieldId; }) || null;
|
|
496
|
+
}
|
|
497
|
+
var STRING_DATE_FORMATS = [
|
|
498
|
+
moment.ISO_8601,
|
|
499
|
+
'MM/DD/YYYY',
|
|
500
|
+
'M/D/YYYY',
|
|
501
|
+
'MM/DD/YYYY h:mm A',
|
|
502
|
+
'M/D/YYYY h:mm A',
|
|
503
|
+
'MM/DD/YYYY hh:mm A',
|
|
504
|
+
'M/D/YYYY hh:mm A',
|
|
505
|
+
'MM/DD/YYYY h:mm:ss A',
|
|
506
|
+
'M/D/YYYY h:mm:ss A',
|
|
507
|
+
'MM/DD/YYYY hh:mm:ss A',
|
|
508
|
+
'M/D/YYYY hh:mm:ss A',
|
|
509
|
+
'MM/DD/YYYY H:mm',
|
|
510
|
+
'M/D/YYYY H:mm',
|
|
511
|
+
'MM/DD/YYYY HH:mm',
|
|
512
|
+
'M/D/YYYY HH:mm',
|
|
513
|
+
'MM/DD/YYYY H:mm:ss',
|
|
514
|
+
'M/D/YYYY H:mm:ss',
|
|
515
|
+
'MM/DD/YYYY HH:mm:ss',
|
|
516
|
+
'M/D/YYYY HH:mm:ss'
|
|
517
|
+
];
|
|
518
|
+
function parseMoment(value) {
|
|
519
|
+
if (value === null || value === undefined) {
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
if (moment.isMoment(value)) {
|
|
523
|
+
return value;
|
|
524
|
+
}
|
|
525
|
+
if (value instanceof Date || typeof value === 'number') {
|
|
526
|
+
var m_1 = moment(value);
|
|
527
|
+
return m_1.isValid() ? m_1 : null;
|
|
528
|
+
}
|
|
529
|
+
if (typeof value === 'string' || value instanceof String) {
|
|
530
|
+
var str = "".concat(value).trim();
|
|
531
|
+
if (!str) {
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
var m_2 = moment(str, STRING_DATE_FORMATS, true);
|
|
535
|
+
if (m_2.isValid()) {
|
|
536
|
+
return m_2;
|
|
537
|
+
}
|
|
538
|
+
var loose = moment(str, STRING_DATE_FORMATS, false);
|
|
539
|
+
if (loose.isValid()) {
|
|
540
|
+
return loose;
|
|
541
|
+
}
|
|
542
|
+
var jsDateStr = str.replace(/\s*\([^)]*\)\s*$/, '');
|
|
543
|
+
var jsDate = moment(jsDateStr, 'ddd MMM DD YYYY HH:mm:ss [GMT]ZZ', true);
|
|
544
|
+
if (jsDate.isValid()) {
|
|
545
|
+
return jsDate;
|
|
546
|
+
}
|
|
547
|
+
if (/[T:\\/\\-]/.test(str) || /GMT|UTC/i.test(str)) {
|
|
548
|
+
var fallback = moment(str);
|
|
549
|
+
return fallback.isValid() ? fallback : null;
|
|
550
|
+
}
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
var m = moment(value);
|
|
554
|
+
return m.isValid() ? m : null;
|
|
555
|
+
}
|
|
556
|
+
function parseExcelNumber(value) {
|
|
557
|
+
if (typeof value === 'number') {
|
|
558
|
+
return Number.isFinite(value) ? value : null;
|
|
559
|
+
}
|
|
560
|
+
if (typeof value !== 'string') {
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
var s = value.trim();
|
|
564
|
+
if (!s) {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
var negative = false;
|
|
568
|
+
var parenMatch = s.match(/^\((.*)\)$/);
|
|
569
|
+
if (parenMatch) {
|
|
570
|
+
negative = true;
|
|
571
|
+
s = parenMatch[1].trim();
|
|
572
|
+
}
|
|
573
|
+
s = s
|
|
574
|
+
.replace(/[\t\n\r]/g, '')
|
|
575
|
+
.replace(/\$/g, '')
|
|
576
|
+
.replace(/,/g, '');
|
|
577
|
+
s = s.trim();
|
|
578
|
+
if (!s) {
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
var num = Number(s);
|
|
582
|
+
if (!Number.isFinite(num)) {
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
return negative ? -num : num;
|
|
586
|
+
}
|
|
587
|
+
function isExcelNumericField(field) {
|
|
588
|
+
return !!field && (field.fieldType === 'Number' ||
|
|
589
|
+
field.leafValueType === 'Count' ||
|
|
590
|
+
field.leafValueType === 'Sum' ||
|
|
591
|
+
field.leafValueType === 'Average');
|
|
592
|
+
}
|
|
593
|
+
function writeExcelCell(cell, value, fieldMeta) {
|
|
594
|
+
if (value === null || value === undefined) {
|
|
595
|
+
cell.value = '';
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
if ((fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.fieldType) === 'Date') {
|
|
599
|
+
var rawValue = Array.isArray(value) ? value.find(function (v) { return v !== null && v !== undefined && v !== ''; }) : value;
|
|
600
|
+
var m = parseMoment(rawValue);
|
|
601
|
+
if (m) {
|
|
602
|
+
var timezone = process.env.TZ_CLIENT;
|
|
603
|
+
var local = timezone ? moment.tz(m.toDate(), timezone) : m.clone().local();
|
|
604
|
+
var leafFormatType = fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.leafFormatType;
|
|
605
|
+
var excelSerial = (Date.UTC(local.year(), local.month(), local.date(), local.hour(), local.minute(), local.second(), local.millisecond()) - Date.UTC(1899, 11, 30)) / 86400000;
|
|
606
|
+
if (leafFormatType === 'Date' || leafFormatType === 'Date_long') {
|
|
607
|
+
cell.value = Math.floor(excelSerial);
|
|
608
|
+
}
|
|
609
|
+
else if (leafFormatType === 'Time' || leafFormatType === 'DateTime' || leafFormatType === 'DateTime_long') {
|
|
610
|
+
cell.value = excelSerial;
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
cell.value = local.toDate();
|
|
614
|
+
}
|
|
615
|
+
switch (leafFormatType) {
|
|
616
|
+
case 'Time':
|
|
617
|
+
cell.numFmt = 'h:mm AM/PM';
|
|
618
|
+
break;
|
|
619
|
+
case 'DateTime':
|
|
620
|
+
case 'DateTime_long':
|
|
621
|
+
cell.numFmt = 'mm/dd/yyyy h:mm AM/PM';
|
|
622
|
+
break;
|
|
623
|
+
case 'Date':
|
|
624
|
+
cell.numFmt = 'mm/dd/yyyy';
|
|
625
|
+
break;
|
|
626
|
+
case 'Date_long':
|
|
627
|
+
default:
|
|
628
|
+
cell.numFmt = 'mm/dd/yyyy';
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (Array.isArray(value)) {
|
|
635
|
+
cell.value = value.join(', ');
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (isExcelNumericField(fieldMeta)) {
|
|
639
|
+
var parsed = parseExcelNumber(value);
|
|
640
|
+
if (parsed !== null) {
|
|
641
|
+
cell.value = parsed;
|
|
642
|
+
if ((fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.leafFormatType) === 'Currency') {
|
|
643
|
+
cell.numFmt = '"$"#,##0.00;[Red]-"$"#,##0.00';
|
|
644
|
+
}
|
|
645
|
+
else if ((fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.leafFormatType) === 'Number' || (fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.leafValueType) === 'Count') {
|
|
646
|
+
cell.numFmt = '#,##0';
|
|
647
|
+
}
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
if (typeof value === 'string') {
|
|
652
|
+
cell.value = value.replace(/\t/g, '').replace(/\n/g, '');
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
cell.value = value;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
function getMaxRows(row) {
|
|
659
|
+
var keys = Object.keys(row || {});
|
|
660
|
+
var maxArray = [];
|
|
661
|
+
for (var i = 0; i < keys.length; i++) {
|
|
662
|
+
if (Array.isArray(row[keys[i]]) && row[keys[i]].length > maxArray.length) {
|
|
663
|
+
maxArray = row[keys[i]];
|
|
664
|
+
}
|
|
665
|
+
else if (maxArray.length === 0) {
|
|
666
|
+
maxArray = [row[keys[i]]];
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return maxArray;
|
|
670
|
+
}
|
|
671
|
+
function applyClientGroupSortToData(results, report, sorts) {
|
|
672
|
+
if (sorts === void 0) { sorts = []; }
|
|
673
|
+
if (!Array.isArray(results) || !results.length) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
var groupIds = ((report === null || report === void 0 ? void 0 : report.groups_row) || []).map(function (g) { return g.id; }).filter(Boolean);
|
|
677
|
+
if (!groupIds.length) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
var groupOrderById = {};
|
|
681
|
+
var leafSorts = [];
|
|
682
|
+
(sorts || []).forEach(function (s) {
|
|
683
|
+
if (!(s === null || s === void 0 ? void 0 : s.field)) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
if (groupIds.includes(s.field)) {
|
|
687
|
+
groupOrderById[s.field] = s.order || 'asc';
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
var leafId = resolveFieldRefToLeafId(s.field, report);
|
|
691
|
+
if (leafId) {
|
|
692
|
+
leafSorts.push({ leafId: leafId, order: s.order || 'asc' });
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
var compareScalar = function (aVal, bVal, order) {
|
|
697
|
+
var dir = order === 'desc' ? -1 : 1;
|
|
698
|
+
var aNull = aVal === null || aVal === undefined || aVal === '';
|
|
699
|
+
var bNull = bVal === null || bVal === undefined || bVal === '';
|
|
700
|
+
if (aNull && bNull) {
|
|
701
|
+
return 0;
|
|
702
|
+
}
|
|
703
|
+
if (aNull) {
|
|
704
|
+
return 1;
|
|
705
|
+
}
|
|
706
|
+
if (bNull) {
|
|
707
|
+
return -1;
|
|
708
|
+
}
|
|
709
|
+
var aNum = typeof aVal === 'number' ? aVal : Number(aVal);
|
|
710
|
+
var bNum = typeof bVal === 'number' ? bVal : Number(bVal);
|
|
711
|
+
if (!isNaN(aNum) && !isNaN(bNum)) {
|
|
712
|
+
if (aNum === bNum) {
|
|
713
|
+
return 0;
|
|
714
|
+
}
|
|
715
|
+
return aNum > bNum ? dir : -dir;
|
|
716
|
+
}
|
|
717
|
+
var aStr = ('' + aVal).toLowerCase();
|
|
718
|
+
var bStr = ('' + bVal).toLowerCase();
|
|
719
|
+
if (aStr === bStr) {
|
|
720
|
+
return 0;
|
|
721
|
+
}
|
|
722
|
+
return aStr > bStr ? dir : -dir;
|
|
723
|
+
};
|
|
724
|
+
var selectedIds = ((report === null || report === void 0 ? void 0 : report.fields_selected) || []).map(function (f) { return f.id; }).filter(Boolean);
|
|
725
|
+
var sortLeafArraysInRow = function (row) {
|
|
726
|
+
if (!row || !leafSorts.length) {
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
var arraysToReorder = selectedIds.filter(function (id) { return Array.isArray(row[id]); });
|
|
730
|
+
if (!arraysToReorder.length) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
var length = 0;
|
|
734
|
+
arraysToReorder.forEach(function (id) {
|
|
735
|
+
length = Math.max(length, row[id].length || 0);
|
|
736
|
+
});
|
|
737
|
+
if (length <= 1) {
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
var getArrayVal = function (id, idx) {
|
|
741
|
+
var arr = row[id];
|
|
742
|
+
if (!Array.isArray(arr) || !arr.length) {
|
|
743
|
+
return null;
|
|
744
|
+
}
|
|
745
|
+
return arr[idx] !== undefined ? arr[idx] : arr[arr.length - 1];
|
|
746
|
+
};
|
|
747
|
+
var indices = Array.from({ length: length }, function (_, i) { return i; });
|
|
748
|
+
indices.sort(function (i, j) {
|
|
749
|
+
var e_1, _a;
|
|
750
|
+
try {
|
|
751
|
+
for (var leafSorts_1 = __values(leafSorts), leafSorts_1_1 = leafSorts_1.next(); !leafSorts_1_1.done; leafSorts_1_1 = leafSorts_1.next()) {
|
|
752
|
+
var s = leafSorts_1_1.value;
|
|
753
|
+
var aVal = Array.isArray(row[s.leafId]) ? getArrayVal(s.leafId, i) : row[s.leafId];
|
|
754
|
+
var bVal = Array.isArray(row[s.leafId]) ? getArrayVal(s.leafId, j) : row[s.leafId];
|
|
755
|
+
var cmp = compareScalar(aVal, bVal, s.order);
|
|
756
|
+
if (cmp !== 0) {
|
|
757
|
+
return cmp;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
762
|
+
finally {
|
|
763
|
+
try {
|
|
764
|
+
if (leafSorts_1_1 && !leafSorts_1_1.done && (_a = leafSorts_1.return)) _a.call(leafSorts_1);
|
|
765
|
+
}
|
|
766
|
+
finally { if (e_1) throw e_1.error; }
|
|
767
|
+
}
|
|
768
|
+
return 0;
|
|
769
|
+
});
|
|
770
|
+
arraysToReorder.forEach(function (id) {
|
|
771
|
+
row[id] = indices.map(function (idx) { return getArrayVal(id, idx); });
|
|
772
|
+
});
|
|
773
|
+
};
|
|
774
|
+
var sortGroupLevel = function (rows, depth) {
|
|
775
|
+
if (!Array.isArray(rows) || !rows.length) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
var groupId = groupIds[depth];
|
|
779
|
+
var order = groupOrderById[groupId] || 'asc';
|
|
780
|
+
rows.sort(function (a, b) { var _a, _b; return compareScalar((_a = a === null || a === void 0 ? void 0 : a._id) === null || _a === void 0 ? void 0 : _a[groupId], (_b = b === null || b === void 0 ? void 0 : b._id) === null || _b === void 0 ? void 0 : _b[groupId], order); });
|
|
781
|
+
if (depth < groupIds.length - 1) {
|
|
782
|
+
var childId_1 = groupIds[depth + 1];
|
|
783
|
+
rows.forEach(function (r) {
|
|
784
|
+
var children = r ? r[childId_1] : null;
|
|
785
|
+
if (Array.isArray(children)) {
|
|
786
|
+
sortGroupLevel(children, depth + 1);
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
else {
|
|
791
|
+
rows.forEach(function (r) { return sortLeafArraysInRow(r); });
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
sortGroupLevel(results, 0);
|
|
795
|
+
}
|
|
796
|
+
var OPENAI_USAGE_BILLING_ENDPOINT = 'https://backend.resolveio.com/api/openai-usage/report';
|
|
797
|
+
var AI_USAGE_SYNC_JOB_NAME = 'AI Usage Billing Sync';
|
|
798
|
+
var LEGACY_AI_USAGE_SYNC_JOB_NAME = 'OpenAI Usage Billing Sync';
|
|
799
|
+
var OPENAI_USAGE_DEFAULT_LOOKBACK_DAYS = 30;
|
|
800
|
+
var OPENAI_USAGE_DEFAULT_BATCH_SIZE = 500;
|
|
801
|
+
var OPENAI_USAGE_DEFAULT_OVERLAP_MINUTES = 10;
|
|
802
|
+
var COMMUNICATION_METRICS_ENDPOINT = 'https://backend.resolveio.com/api/communication-metrics/report';
|
|
803
|
+
var COMMUNICATION_METRICS_DEFAULT_LOOKBACK_DAYS = 30;
|
|
804
|
+
var COMMUNICATION_METRICS_DEFAULT_BATCH_SIZE = 1000;
|
|
805
|
+
var COMMUNICATION_METRICS_DEFAULT_OVERLAP_MINUTES = 10;
|
|
806
|
+
var toNumberSetting = function (value, fallback, allowZero) {
|
|
807
|
+
if (allowZero === void 0) { allowZero = false; }
|
|
808
|
+
var parsed = Number(value);
|
|
809
|
+
if (!Number.isFinite(parsed)) {
|
|
810
|
+
return fallback;
|
|
811
|
+
}
|
|
812
|
+
if (allowZero && parsed === 0) {
|
|
813
|
+
return 0;
|
|
814
|
+
}
|
|
815
|
+
return parsed > 0 ? Math.floor(parsed) : fallback;
|
|
816
|
+
};
|
|
817
|
+
var normalizeString = function (value) {
|
|
818
|
+
if (typeof value !== 'string') {
|
|
819
|
+
return '';
|
|
820
|
+
}
|
|
821
|
+
return value.trim();
|
|
822
|
+
};
|
|
823
|
+
var normalizeIdentifier = function (value) {
|
|
824
|
+
if (value === undefined || value === null) {
|
|
825
|
+
return '';
|
|
826
|
+
}
|
|
827
|
+
return String(value).trim();
|
|
828
|
+
};
|
|
829
|
+
var normalizeDate = function (value) {
|
|
830
|
+
if (!value) {
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
833
|
+
var date = value instanceof Date ? value : new Date(value);
|
|
834
|
+
if (Number.isNaN(date.getTime())) {
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
return date;
|
|
838
|
+
};
|
|
839
|
+
var resolveOpenAIUsageSyncConfig = function () {
|
|
840
|
+
var _a, _b;
|
|
841
|
+
var config = ((_a = resolveio_server_app_1.ResolveIOServer.getServerConfig) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer)) || {};
|
|
842
|
+
var endpoint = normalizeString(config['OPENAI_USAGE_BILLING_URL']
|
|
843
|
+
|| config['OPENAI_USAGE_REPORT_URL']
|
|
844
|
+
|| process.env.OPENAI_USAGE_BILLING_URL
|
|
845
|
+
|| process.env.OPENAI_USAGE_REPORT_URL) || OPENAI_USAGE_BILLING_ENDPOINT;
|
|
846
|
+
var apiKey = normalizeString(config['OPENAI_USAGE_INGEST_KEY']
|
|
847
|
+
|| config['OPENAI_USAGE_API_KEY']
|
|
848
|
+
|| process.env.OPENAI_USAGE_INGEST_KEY
|
|
849
|
+
|| process.env.OPENAI_USAGE_API_KEY
|
|
850
|
+
|| process.env.OPENAI_USAGE_REPORT_KEY);
|
|
851
|
+
var batchSize = toNumberSetting(config['OPENAI_USAGE_SYNC_BATCH_SIZE'] || process.env.OPENAI_USAGE_SYNC_BATCH_SIZE, OPENAI_USAGE_DEFAULT_BATCH_SIZE);
|
|
852
|
+
var lookbackDays = toNumberSetting(config['OPENAI_USAGE_SYNC_LOOKBACK_DAYS'] || process.env.OPENAI_USAGE_SYNC_LOOKBACK_DAYS, OPENAI_USAGE_DEFAULT_LOOKBACK_DAYS);
|
|
853
|
+
var overlapMinutes = toNumberSetting(config['OPENAI_USAGE_SYNC_OVERLAP_MINUTES'] || process.env.OPENAI_USAGE_SYNC_OVERLAP_MINUTES, OPENAI_USAGE_DEFAULT_OVERLAP_MINUTES, true);
|
|
854
|
+
var enabledRaw = (_b = config['OPENAI_USAGE_SYNC_ENABLED']) !== null && _b !== void 0 ? _b : process.env.OPENAI_USAGE_SYNC_ENABLED;
|
|
855
|
+
var enabled = typeof enabledRaw === 'string'
|
|
856
|
+
? enabledRaw.trim().toLowerCase() !== 'false' && enabledRaw.trim() !== '0'
|
|
857
|
+
: enabledRaw !== false;
|
|
858
|
+
return { config: config, endpoint: endpoint, apiKey: apiKey, batchSize: batchSize, lookbackDays: lookbackDays, overlapMinutes: overlapMinutes, enabled: enabled };
|
|
859
|
+
};
|
|
860
|
+
var buildOpenAIUsageQuery = function (cursorAt, cursorId) {
|
|
861
|
+
var base = {
|
|
862
|
+
billable: { $ne: false }
|
|
863
|
+
};
|
|
864
|
+
if (!cursorId) {
|
|
865
|
+
base.timestamp = { $gte: cursorAt };
|
|
866
|
+
return base;
|
|
867
|
+
}
|
|
868
|
+
base.$or = [
|
|
869
|
+
{ timestamp: { $gt: cursorAt } },
|
|
870
|
+
{ timestamp: cursorAt, _id: { $gt: cursorId } }
|
|
871
|
+
];
|
|
872
|
+
return base;
|
|
873
|
+
};
|
|
874
|
+
var normalizeUsagePayloadEntry = function (entry) {
|
|
875
|
+
if (!entry) {
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
878
|
+
var timestamp = normalizeDate(entry.timestamp);
|
|
879
|
+
var idClient = normalizeIdentifier(entry.id_client);
|
|
880
|
+
if (!timestamp || !idClient) {
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
var id = normalizeIdentifier(entry._id) || normalizeIdentifier(entry.id) || '';
|
|
884
|
+
return {
|
|
885
|
+
_id: id || undefined,
|
|
886
|
+
id_client: idClient,
|
|
887
|
+
timestamp: timestamp,
|
|
888
|
+
model: normalizeString(entry.model) || 'unknown',
|
|
889
|
+
input_tokens: Number(entry.input_tokens || 0),
|
|
890
|
+
output_tokens: Number(entry.output_tokens || 0),
|
|
891
|
+
total_tokens: Number(entry.total_tokens || 0),
|
|
892
|
+
cost_estimate: Number(entry.cost_estimate || 0),
|
|
893
|
+
billable: entry.billable !== false,
|
|
894
|
+
category: normalizeString(entry.category),
|
|
895
|
+
id_request: normalizeIdentifier(entry.id_request),
|
|
896
|
+
id_conversation: normalizeIdentifier(entry.id_conversation)
|
|
897
|
+
};
|
|
898
|
+
};
|
|
899
|
+
var resolveCommunicationMetricsSyncConfig = function () {
|
|
900
|
+
var _a, _b;
|
|
901
|
+
var config = ((_a = resolveio_server_app_1.ResolveIOServer.getServerConfig) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer)) || {};
|
|
902
|
+
var endpoint = normalizeString(config['COMMUNICATION_METRICS_REPORT_URL']
|
|
903
|
+
|| config['COMMUNICATION_METRICS_BILLING_URL']
|
|
904
|
+
|| process.env.COMMUNICATION_METRICS_REPORT_URL
|
|
905
|
+
|| process.env.COMMUNICATION_METRICS_BILLING_URL) || COMMUNICATION_METRICS_ENDPOINT;
|
|
906
|
+
var apiKey = normalizeString(config['COMMUNICATION_METRICS_INGEST_KEY']
|
|
907
|
+
|| config['COMMUNICATION_METRICS_API_KEY']
|
|
908
|
+
|| process.env.COMMUNICATION_METRICS_INGEST_KEY
|
|
909
|
+
|| process.env.COMMUNICATION_METRICS_API_KEY
|
|
910
|
+
|| config['OPENAI_USAGE_INGEST_KEY']
|
|
911
|
+
|| config['OPENAI_USAGE_API_KEY']
|
|
912
|
+
|| process.env.OPENAI_USAGE_INGEST_KEY
|
|
913
|
+
|| process.env.OPENAI_USAGE_API_KEY
|
|
914
|
+
|| process.env.OPENAI_USAGE_REPORT_KEY);
|
|
915
|
+
var batchSize = toNumberSetting(config['COMMUNICATION_METRICS_SYNC_BATCH_SIZE'] || process.env.COMMUNICATION_METRICS_SYNC_BATCH_SIZE, COMMUNICATION_METRICS_DEFAULT_BATCH_SIZE);
|
|
916
|
+
var lookbackDays = toNumberSetting(config['COMMUNICATION_METRICS_SYNC_LOOKBACK_DAYS'] || process.env.COMMUNICATION_METRICS_SYNC_LOOKBACK_DAYS, COMMUNICATION_METRICS_DEFAULT_LOOKBACK_DAYS);
|
|
917
|
+
var overlapMinutes = toNumberSetting(config['COMMUNICATION_METRICS_SYNC_OVERLAP_MINUTES'] || process.env.COMMUNICATION_METRICS_SYNC_OVERLAP_MINUTES, COMMUNICATION_METRICS_DEFAULT_OVERLAP_MINUTES, true);
|
|
918
|
+
var enabledRaw = (_b = config['COMMUNICATION_METRICS_SYNC_ENABLED']) !== null && _b !== void 0 ? _b : process.env.COMMUNICATION_METRICS_SYNC_ENABLED;
|
|
919
|
+
var enabled = typeof enabledRaw === 'string'
|
|
920
|
+
? enabledRaw.trim().toLowerCase() !== 'false' && enabledRaw.trim() !== '0'
|
|
921
|
+
: enabledRaw !== false;
|
|
922
|
+
return { config: config, endpoint: endpoint, apiKey: apiKey, batchSize: batchSize, lookbackDays: lookbackDays, overlapMinutes: overlapMinutes, enabled: enabled };
|
|
923
|
+
};
|
|
924
|
+
var buildCommunicationMetricsQuery = function (cursorAt, cursorId) {
|
|
925
|
+
if (!cursorId) {
|
|
926
|
+
return { date: { $gte: cursorAt } };
|
|
927
|
+
}
|
|
928
|
+
return {
|
|
929
|
+
$or: [
|
|
930
|
+
{ date: { $gt: cursorAt } },
|
|
931
|
+
{ date: cursorAt, _id: { $gt: cursorId } }
|
|
932
|
+
]
|
|
933
|
+
};
|
|
934
|
+
};
|
|
935
|
+
var normalizeCommunicationMetricEntry = function (entry) {
|
|
936
|
+
var _a, _b;
|
|
937
|
+
if (!entry) {
|
|
938
|
+
return null;
|
|
939
|
+
}
|
|
940
|
+
var date = normalizeDate(entry.date || entry.timestamp);
|
|
941
|
+
var type = normalizeString(entry.type);
|
|
942
|
+
if (!date || !type) {
|
|
943
|
+
return null;
|
|
944
|
+
}
|
|
945
|
+
var value = Number((_b = (_a = entry.value) !== null && _a !== void 0 ? _a : entry.count) !== null && _b !== void 0 ? _b : 0);
|
|
946
|
+
if (!Number.isFinite(value) || !value) {
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
var id = normalizeIdentifier(entry._id) || normalizeIdentifier(entry.id) || '';
|
|
950
|
+
var unit = normalizeString(entry.unit);
|
|
951
|
+
var metadata = entry.metadata && typeof entry.metadata === 'object' ? entry.metadata : undefined;
|
|
952
|
+
return {
|
|
953
|
+
_id: id || undefined,
|
|
954
|
+
date: date,
|
|
955
|
+
type: type,
|
|
956
|
+
value: value,
|
|
957
|
+
unit: unit || undefined,
|
|
958
|
+
metadata: metadata
|
|
959
|
+
};
|
|
960
|
+
};
|
|
961
|
+
function loadCronJobMethods(methodManager) {
|
|
962
|
+
methodManager.methods({
|
|
963
|
+
cronEmailMergedDocsCleanUp: {
|
|
964
|
+
function: function () {
|
|
965
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
966
|
+
var files;
|
|
967
|
+
return __generator(this, function (_a) {
|
|
968
|
+
switch (_a.label) {
|
|
969
|
+
case 0: return [4 /*yield*/, file_collection_1.Files.find({ $and: [{ type: 'Email Merged Docs' }, { createdAt: { $lte: moment().subtract(1, 'day').toDate() } }] })];
|
|
970
|
+
case 1:
|
|
971
|
+
files = _a.sent();
|
|
972
|
+
if (!files.length) return [3 /*break*/, 4];
|
|
973
|
+
return [4 /*yield*/, this.callMethod('deleteFiles', files.map(function (file) { return file.key; }))];
|
|
974
|
+
case 2:
|
|
975
|
+
_a.sent();
|
|
976
|
+
return [4 /*yield*/, file_collection_1.Files.deleteMany({ _id: { $in: files.map(function (a) { return a._id; }) } })];
|
|
977
|
+
case 3:
|
|
978
|
+
_a.sent();
|
|
979
|
+
_a.label = 4;
|
|
980
|
+
case 4: return [2 /*return*/, true];
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
},
|
|
986
|
+
stuckCronJob: {
|
|
987
|
+
function: function () {
|
|
988
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
989
|
+
var fiveMin, cronJobs;
|
|
990
|
+
return __generator(this, function (_a) {
|
|
991
|
+
switch (_a.label) {
|
|
992
|
+
case 0:
|
|
993
|
+
fiveMin = moment().subtract(5, 'minutes').toDate();
|
|
994
|
+
return [4 /*yield*/, cron_job_collection_1.CronJobs.find({ running: true, updatedAt: { $lte: fiveMin } })];
|
|
995
|
+
case 1:
|
|
996
|
+
cronJobs = _a.sent();
|
|
997
|
+
if (!cronJobs.length) return [3 /*break*/, 3];
|
|
998
|
+
return [4 /*yield*/, cron_job_collection_1.CronJobs.updateMany({ _id: { $in: cronJobs.map(function (a) { return a._id; }) } }, { $set: { running: false } })];
|
|
999
|
+
case 2:
|
|
1000
|
+
_a.sent();
|
|
1001
|
+
_a.label = 3;
|
|
1002
|
+
case 3: return [2 /*return*/, true];
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
},
|
|
1008
|
+
cronOpenAIUsageBillingSync: {
|
|
1009
|
+
check: new simpl_schema_1.default({
|
|
1010
|
+
data: {
|
|
1011
|
+
type: Object,
|
|
1012
|
+
blackbox: true
|
|
1013
|
+
}
|
|
1014
|
+
}),
|
|
1015
|
+
function: function () {
|
|
1016
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1017
|
+
var _a, config, endpoint, apiKey, batchSize, lookbackDays, overlapMinutes, enabled, rootUrl, jobDoc, runData, lastSyncedAt, lastSyncedId, lookbackMs, cursorAt, cursorId, totalSent, cursorMoved, source, i, query, entries, payloadEntries, lastEntry, jobSelector;
|
|
1018
|
+
var _b;
|
|
1019
|
+
return __generator(this, function (_c) {
|
|
1020
|
+
switch (_c.label) {
|
|
1021
|
+
case 0:
|
|
1022
|
+
_a = resolveOpenAIUsageSyncConfig(), config = _a.config, endpoint = _a.endpoint, apiKey = _a.apiKey, batchSize = _a.batchSize, lookbackDays = _a.lookbackDays, overlapMinutes = _a.overlapMinutes, enabled = _a.enabled;
|
|
1023
|
+
if (!enabled) {
|
|
1024
|
+
return [2 /*return*/, true];
|
|
1025
|
+
}
|
|
1026
|
+
rootUrl = normalizeString(config['ROOT_URL']);
|
|
1027
|
+
if (rootUrl === 'https://resolveio.com' || rootUrl === 'http://localhost:4200') {
|
|
1028
|
+
return [2 /*return*/, true];
|
|
1029
|
+
}
|
|
1030
|
+
if (!endpoint || !apiKey) {
|
|
1031
|
+
console.warn('[AI Usage Sync] Missing endpoint or API key.');
|
|
1032
|
+
return [2 /*return*/, false];
|
|
1033
|
+
}
|
|
1034
|
+
return [4 /*yield*/, cron_job_collection_1.CronJobs.findOne({
|
|
1035
|
+
name: {
|
|
1036
|
+
$in: [AI_USAGE_SYNC_JOB_NAME, LEGACY_AI_USAGE_SYNC_JOB_NAME]
|
|
1037
|
+
}
|
|
1038
|
+
})];
|
|
1039
|
+
case 1:
|
|
1040
|
+
jobDoc = _c.sent();
|
|
1041
|
+
runData = jobDoc === null || jobDoc === void 0 ? void 0 : jobDoc.method_run_data;
|
|
1042
|
+
lastSyncedAt = normalizeDate(runData === null || runData === void 0 ? void 0 : runData.last_synced_at);
|
|
1043
|
+
lastSyncedId = normalizeString(runData === null || runData === void 0 ? void 0 : runData.last_synced_id);
|
|
1044
|
+
lookbackMs = lookbackDays * 24 * 60 * 60 * 1000;
|
|
1045
|
+
cursorAt = lastSyncedAt || new Date(Date.now() - lookbackMs);
|
|
1046
|
+
if (lastSyncedAt && overlapMinutes > 0) {
|
|
1047
|
+
cursorAt = new Date(cursorAt.getTime() - overlapMinutes * 60 * 1000);
|
|
1048
|
+
}
|
|
1049
|
+
cursorId = lastSyncedId;
|
|
1050
|
+
totalSent = 0;
|
|
1051
|
+
cursorMoved = false;
|
|
1052
|
+
source = {
|
|
1053
|
+
clientSlug: (_b = resolveio_server_app_1.ResolveIOServer.getClientName) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer),
|
|
1054
|
+
clientName: normalizeString(config['CLIENT_NAME']),
|
|
1055
|
+
rootUrl: rootUrl,
|
|
1056
|
+
reportedAt: new Date(),
|
|
1057
|
+
appVersion: process.env.APP_VERSION
|
|
1058
|
+
};
|
|
1059
|
+
i = 0;
|
|
1060
|
+
_c.label = 2;
|
|
1061
|
+
case 2:
|
|
1062
|
+
if (!(i < 1000)) return [3 /*break*/, 7];
|
|
1063
|
+
query = buildOpenAIUsageQuery(cursorAt, cursorId);
|
|
1064
|
+
return [4 /*yield*/, openai_usage_ledger_collection_1.OpenAIUsageLedger.find(query, {
|
|
1065
|
+
sort: { timestamp: 1, _id: 1 },
|
|
1066
|
+
limit: batchSize
|
|
1067
|
+
})];
|
|
1068
|
+
case 3:
|
|
1069
|
+
entries = _c.sent();
|
|
1070
|
+
if (!entries.length) {
|
|
1071
|
+
return [3 /*break*/, 7];
|
|
1072
|
+
}
|
|
1073
|
+
payloadEntries = entries
|
|
1074
|
+
.map(function (entry) { return normalizeUsagePayloadEntry(entry); })
|
|
1075
|
+
.filter(Boolean);
|
|
1076
|
+
if (!payloadEntries.length) return [3 /*break*/, 5];
|
|
1077
|
+
return [4 /*yield*/, axios_1.default.post(endpoint, { entries: payloadEntries, source: source }, {
|
|
1078
|
+
headers: {
|
|
1079
|
+
'Content-Type': 'application/json',
|
|
1080
|
+
'X-ResolveIO-OpenAI-Usage-Key': apiKey,
|
|
1081
|
+
'X-OpenAI-Usage-Key': apiKey,
|
|
1082
|
+
'X-API-Key': apiKey
|
|
1083
|
+
},
|
|
1084
|
+
timeout: 20000
|
|
1085
|
+
})];
|
|
1086
|
+
case 4:
|
|
1087
|
+
_c.sent();
|
|
1088
|
+
totalSent += payloadEntries.length;
|
|
1089
|
+
_c.label = 5;
|
|
1090
|
+
case 5:
|
|
1091
|
+
lastEntry = entries[entries.length - 1];
|
|
1092
|
+
if (lastEntry) {
|
|
1093
|
+
cursorAt = normalizeDate(lastEntry.timestamp) || cursorAt;
|
|
1094
|
+
cursorId = normalizeString(lastEntry._id) || cursorId;
|
|
1095
|
+
cursorMoved = true;
|
|
1096
|
+
}
|
|
1097
|
+
if (entries.length < batchSize) {
|
|
1098
|
+
return [3 /*break*/, 7];
|
|
1099
|
+
}
|
|
1100
|
+
_c.label = 6;
|
|
1101
|
+
case 6:
|
|
1102
|
+
i++;
|
|
1103
|
+
return [3 /*break*/, 2];
|
|
1104
|
+
case 7:
|
|
1105
|
+
if (!cursorMoved) return [3 /*break*/, 9];
|
|
1106
|
+
jobSelector = (jobDoc === null || jobDoc === void 0 ? void 0 : jobDoc._id)
|
|
1107
|
+
? { _id: jobDoc._id }
|
|
1108
|
+
: { name: AI_USAGE_SYNC_JOB_NAME };
|
|
1109
|
+
return [4 /*yield*/, cron_job_collection_1.CronJobs.updateOne(jobSelector, {
|
|
1110
|
+
$set: {
|
|
1111
|
+
name: AI_USAGE_SYNC_JOB_NAME,
|
|
1112
|
+
'method_run_data.last_synced_at': cursorAt,
|
|
1113
|
+
'method_run_data.last_synced_id': cursorId,
|
|
1114
|
+
'method_run_data.last_sent_at': new Date(),
|
|
1115
|
+
'method_run_data.last_sent_count': totalSent
|
|
1116
|
+
}
|
|
1117
|
+
})];
|
|
1118
|
+
case 8:
|
|
1119
|
+
_c.sent();
|
|
1120
|
+
_c.label = 9;
|
|
1121
|
+
case 9: return [2 /*return*/, true];
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
},
|
|
1127
|
+
cronCommunicationMetricsSync: {
|
|
1128
|
+
check: new simpl_schema_1.default({
|
|
1129
|
+
data: {
|
|
1130
|
+
type: Object,
|
|
1131
|
+
blackbox: true
|
|
1132
|
+
}
|
|
1133
|
+
}),
|
|
1134
|
+
function: function () {
|
|
1135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1136
|
+
var _a, config, endpoint, apiKey, batchSize, lookbackDays, overlapMinutes, enabled, rootUrl, jobDoc, runData, lastSyncedAt, lastSyncedId, lookbackMs, cursorAt, cursorId, totalSent, cursorMoved, source, i, query, entries, payloadEntries, lastEntry;
|
|
1137
|
+
var _b;
|
|
1138
|
+
return __generator(this, function (_c) {
|
|
1139
|
+
switch (_c.label) {
|
|
1140
|
+
case 0:
|
|
1141
|
+
_a = resolveCommunicationMetricsSyncConfig(), config = _a.config, endpoint = _a.endpoint, apiKey = _a.apiKey, batchSize = _a.batchSize, lookbackDays = _a.lookbackDays, overlapMinutes = _a.overlapMinutes, enabled = _a.enabled;
|
|
1142
|
+
if (!enabled) {
|
|
1143
|
+
return [2 /*return*/, true];
|
|
1144
|
+
}
|
|
1145
|
+
rootUrl = normalizeString(config['ROOT_URL']);
|
|
1146
|
+
if (rootUrl === 'https://resolveio.com' || rootUrl === 'http://localhost:4200') {
|
|
1147
|
+
return [2 /*return*/, true];
|
|
1148
|
+
}
|
|
1149
|
+
if (!endpoint || !apiKey) {
|
|
1150
|
+
console.warn('[Communication Metrics Sync] Missing endpoint or API key.');
|
|
1151
|
+
return [2 /*return*/, false];
|
|
1152
|
+
}
|
|
1153
|
+
return [4 /*yield*/, cron_job_collection_1.CronJobs.findOne({ name: 'Communication Metrics Sync' })];
|
|
1154
|
+
case 1:
|
|
1155
|
+
jobDoc = _c.sent();
|
|
1156
|
+
runData = jobDoc === null || jobDoc === void 0 ? void 0 : jobDoc.method_run_data;
|
|
1157
|
+
lastSyncedAt = normalizeDate(runData === null || runData === void 0 ? void 0 : runData.last_synced_at);
|
|
1158
|
+
lastSyncedId = normalizeString(runData === null || runData === void 0 ? void 0 : runData.last_synced_id);
|
|
1159
|
+
lookbackMs = lookbackDays * 24 * 60 * 60 * 1000;
|
|
1160
|
+
cursorAt = lastSyncedAt || new Date(Date.now() - lookbackMs);
|
|
1161
|
+
if (lastSyncedAt && overlapMinutes > 0) {
|
|
1162
|
+
cursorAt = new Date(cursorAt.getTime() - overlapMinutes * 60 * 1000);
|
|
1163
|
+
}
|
|
1164
|
+
cursorId = lastSyncedId;
|
|
1165
|
+
totalSent = 0;
|
|
1166
|
+
cursorMoved = false;
|
|
1167
|
+
source = {
|
|
1168
|
+
clientSlug: (_b = resolveio_server_app_1.ResolveIOServer.getClientName) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer),
|
|
1169
|
+
clientName: normalizeString(config['CLIENT_NAME']),
|
|
1170
|
+
rootUrl: rootUrl,
|
|
1171
|
+
reportedAt: new Date(),
|
|
1172
|
+
appVersion: process.env.APP_VERSION
|
|
1173
|
+
};
|
|
1174
|
+
i = 0;
|
|
1175
|
+
_c.label = 2;
|
|
1176
|
+
case 2:
|
|
1177
|
+
if (!(i < 1000)) return [3 /*break*/, 7];
|
|
1178
|
+
query = buildCommunicationMetricsQuery(cursorAt, cursorId);
|
|
1179
|
+
return [4 /*yield*/, communication_metric_collection_1.CommunicationMetrics.find(query, {
|
|
1180
|
+
sort: { date: 1, _id: 1 },
|
|
1181
|
+
limit: batchSize
|
|
1182
|
+
})];
|
|
1183
|
+
case 3:
|
|
1184
|
+
entries = _c.sent();
|
|
1185
|
+
if (!entries.length) {
|
|
1186
|
+
return [3 /*break*/, 7];
|
|
1187
|
+
}
|
|
1188
|
+
payloadEntries = entries
|
|
1189
|
+
.map(function (entry) { return normalizeCommunicationMetricEntry(entry); })
|
|
1190
|
+
.filter(Boolean);
|
|
1191
|
+
if (!payloadEntries.length) return [3 /*break*/, 5];
|
|
1192
|
+
return [4 /*yield*/, axios_1.default.post(endpoint, { entries: payloadEntries, source: source }, {
|
|
1193
|
+
headers: {
|
|
1194
|
+
'Content-Type': 'application/json',
|
|
1195
|
+
'X-ResolveIO-Communication-Metrics-Key': apiKey,
|
|
1196
|
+
'X-ResolveIO-OpenAI-Usage-Key': apiKey,
|
|
1197
|
+
'X-OpenAI-Usage-Key': apiKey,
|
|
1198
|
+
'X-API-Key': apiKey
|
|
1199
|
+
},
|
|
1200
|
+
timeout: 20000
|
|
1201
|
+
})];
|
|
1202
|
+
case 4:
|
|
1203
|
+
_c.sent();
|
|
1204
|
+
totalSent += payloadEntries.length;
|
|
1205
|
+
_c.label = 5;
|
|
1206
|
+
case 5:
|
|
1207
|
+
lastEntry = entries[entries.length - 1];
|
|
1208
|
+
if (lastEntry) {
|
|
1209
|
+
cursorAt = normalizeDate(lastEntry.date) || cursorAt;
|
|
1210
|
+
cursorId = normalizeString(lastEntry._id) || cursorId;
|
|
1211
|
+
cursorMoved = true;
|
|
1212
|
+
}
|
|
1213
|
+
if (entries.length < batchSize) {
|
|
1214
|
+
return [3 /*break*/, 7];
|
|
1215
|
+
}
|
|
1216
|
+
_c.label = 6;
|
|
1217
|
+
case 6:
|
|
1218
|
+
i++;
|
|
1219
|
+
return [3 /*break*/, 2];
|
|
1220
|
+
case 7:
|
|
1221
|
+
if (!cursorMoved) return [3 /*break*/, 9];
|
|
1222
|
+
return [4 /*yield*/, cron_job_collection_1.CronJobs.updateOne({ name: 'Communication Metrics Sync' }, {
|
|
1223
|
+
$set: {
|
|
1224
|
+
'method_run_data.last_synced_at': cursorAt,
|
|
1225
|
+
'method_run_data.last_synced_id': cursorId,
|
|
1226
|
+
'method_run_data.last_sent_at': new Date(),
|
|
1227
|
+
'method_run_data.last_sent_count': totalSent
|
|
1228
|
+
}
|
|
1229
|
+
})];
|
|
1230
|
+
case 8:
|
|
1231
|
+
_c.sent();
|
|
1232
|
+
_c.label = 9;
|
|
1233
|
+
case 9: return [2 /*return*/, true];
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
},
|
|
1239
|
+
reportbuilderCronJob: {
|
|
1240
|
+
check: new simpl_schema_1.default({
|
|
1241
|
+
data: {
|
|
1242
|
+
type: Object,
|
|
1243
|
+
blackbox: true
|
|
1244
|
+
}
|
|
1245
|
+
}),
|
|
1246
|
+
function: function (data) {
|
|
1247
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1248
|
+
var report, layoutColumns_1, selectedFields, fieldsObj_1, selectedFieldsForQuery_1, groupIds_1, userSorts, userSortByField_1, groupSorts, nonGroupSorts, effectiveSorts, sortObj_1, totalsForQuery, rootOptions, filters_1, filterArrayFields_1, filterArrays_1, res, results_1, reportTotals, customFields, exportFields_1, wb, ws_1, currentRow_1, row_1, useLayout_1, headers_1, exportResults, buffer, _a, _b, email, e_2_1, err_1, wb, ws_2, currentRow_2, row, copy, widths_1, i, now, buffer, _c, _d, email, e_3_1, err_2, datedUniqueDates_1, datedUniqueGroups_1, datedData_1, reportTotalGroups_1, reportTotalDates_1, _loop_1, i, tmpResults, wb, ws, currentRow, currentCol_1, row_2, _loop_2, i, i, total, j, field, buffer, _e, _f, email, e_4_1, err_3, err_4;
|
|
1249
|
+
var e_2, _g, e_3, _h, e_4, _j;
|
|
1250
|
+
return __generator(this, function (_k) {
|
|
1251
|
+
switch (_k.label) {
|
|
1252
|
+
case 0:
|
|
1253
|
+
if (data && data['active'] === false) {
|
|
1254
|
+
return [2 /*return*/, true];
|
|
1255
|
+
}
|
|
1256
|
+
return [4 /*yield*/, report_builder_report_collection_1.ReportBuilderReports.findById(data['id_report'])];
|
|
1257
|
+
case 1:
|
|
1258
|
+
report = _k.sent();
|
|
1259
|
+
_k.label = 2;
|
|
1260
|
+
case 2:
|
|
1261
|
+
_k.trys.push([2, 43, , 44]);
|
|
1262
|
+
layoutColumns_1 = getLayoutColumnsFromReport(report);
|
|
1263
|
+
selectedFields = syncSelectedFieldsFromLayout(report, layoutColumns_1);
|
|
1264
|
+
report.fields_selected = selectedFields;
|
|
1265
|
+
report.fields_layout = layoutColumns_1;
|
|
1266
|
+
(report.fields_selected || []).forEach(function (field, index) {
|
|
1267
|
+
if (!(field === null || field === void 0 ? void 0 : field.id)) {
|
|
1268
|
+
field.id = "f_".concat(index);
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
(report.fields_custom || []).forEach(function (custom) {
|
|
1272
|
+
if (!custom) {
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
if (!custom.selFieldId && custom.id) {
|
|
1276
|
+
var match = (report.fields_selected || []).find(function (field) { return field.fieldPath === custom.id; });
|
|
1277
|
+
if (match === null || match === void 0 ? void 0 : match.id) {
|
|
1278
|
+
custom.selFieldId = match.id;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
report.fields_selected.forEach(function (field) {
|
|
1283
|
+
var _a, _b;
|
|
1284
|
+
if (!(field === null || field === void 0 ? void 0 : field.fieldPath)) {
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
var dotPath = field.fieldPath.replace(/\.\$/g, '');
|
|
1288
|
+
var fieldData = dotPath.split('.');
|
|
1289
|
+
field.fieldPathObj = null;
|
|
1290
|
+
for (var i = fieldData.length - 1; i >= 0; i--) {
|
|
1291
|
+
if (!field.fieldPathObj) {
|
|
1292
|
+
field.fieldPathObj = (_a = {}, _a[fieldData[i]] = 1, _a);
|
|
1293
|
+
}
|
|
1294
|
+
else {
|
|
1295
|
+
field.fieldPathObj = (_b = {}, _b[fieldData[i]] = field.fieldPathObj, _b);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
if (!((report.fields_selected && report.fields_selected.length) || (report.groups_row && report.groups_row.length))) return [3 /*break*/, 42];
|
|
1300
|
+
fieldsObj_1 = {};
|
|
1301
|
+
selectedFieldsForQuery_1 = (report.fields_selected || []).filter(function (field) { return !(((field === null || field === void 0 ? void 0 : field.fieldPath) || '').startsWith('c_')); });
|
|
1302
|
+
report.fields_sort = report.fields_sort || [];
|
|
1303
|
+
selectedFieldsForQuery_1.forEach(function (field) {
|
|
1304
|
+
if (field.collection_name === report.collection_root && field.fieldPathObj) {
|
|
1305
|
+
fieldsObj_1 = (0, common_1.mergeDeep)(fieldsObj_1, field.fieldPathObj);
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
groupIds_1 = (report.groups_row || []).map(function (g) { return g.id; }).filter(Boolean);
|
|
1309
|
+
userSorts = (report.fields_sort || []).filter(function (s) { return !!s.field; });
|
|
1310
|
+
userSortByField_1 = {};
|
|
1311
|
+
userSorts.forEach(function (s) {
|
|
1312
|
+
userSortByField_1[s.field] = s;
|
|
1313
|
+
});
|
|
1314
|
+
groupSorts = groupIds_1.map(function (id) { return userSortByField_1[id] || { field: id, order: 'asc' }; });
|
|
1315
|
+
nonGroupSorts = userSorts.filter(function (s) { return !groupIds_1.includes(s.field); });
|
|
1316
|
+
effectiveSorts = groupIds_1.length ? __spreadArray(__spreadArray([], __read(groupSorts), false), __read(nonGroupSorts), false) : userSorts;
|
|
1317
|
+
sortObj_1 = null;
|
|
1318
|
+
if (effectiveSorts.length) {
|
|
1319
|
+
sortObj_1 = {};
|
|
1320
|
+
effectiveSorts.forEach(function (sortField) {
|
|
1321
|
+
var targetField = sortField.field;
|
|
1322
|
+
if (!targetField) {
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
if (targetField.startsWith('layout_col_')) {
|
|
1326
|
+
var resolved = resolveFieldRefToLeafId(targetField, report);
|
|
1327
|
+
targetField = resolved || targetField;
|
|
1328
|
+
}
|
|
1329
|
+
if (targetField.startsWith('gr_')) {
|
|
1330
|
+
sortObj_1['_id.' + targetField] = (sortField.order === 'asc' ? 1 : -1);
|
|
1331
|
+
}
|
|
1332
|
+
else {
|
|
1333
|
+
sortObj_1[targetField] = (sortField.order === 'asc' ? 1 : -1);
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
totalsForQuery = (report.fields_total || []).map(function (total) {
|
|
1338
|
+
var mappedFields = (total.fields || [])
|
|
1339
|
+
.map(function (ref) {
|
|
1340
|
+
if (!ref) {
|
|
1341
|
+
return null;
|
|
1342
|
+
}
|
|
1343
|
+
if (ref.startsWith('layout_col_')) {
|
|
1344
|
+
return resolveFieldRefToLeafId(ref, report);
|
|
1345
|
+
}
|
|
1346
|
+
return ref;
|
|
1347
|
+
})
|
|
1348
|
+
.filter(function (f) { return !!f; });
|
|
1349
|
+
return __assign(__assign({}, total), { fields: mappedFields });
|
|
1350
|
+
}).filter(function (total) { return (total.fields || []).length; });
|
|
1351
|
+
report.fields_total = totalsForQuery;
|
|
1352
|
+
rootOptions = {
|
|
1353
|
+
limit: 0,
|
|
1354
|
+
skip: 0,
|
|
1355
|
+
fields: fieldsObj_1,
|
|
1356
|
+
sort: sortObj_1
|
|
1357
|
+
};
|
|
1358
|
+
filters_1 = [];
|
|
1359
|
+
filterArrayFields_1 = [];
|
|
1360
|
+
filterArrays_1 = [];
|
|
1361
|
+
selectedFieldsForQuery_1
|
|
1362
|
+
.filter(function (f) { return (f.fieldPath || '').includes('.$.'); })
|
|
1363
|
+
.forEach(function (sel) {
|
|
1364
|
+
if (!filterArrayFields_1.some(function (f) { return (f === null || f === void 0 ? void 0 : f.fieldPath) === sel.fieldPath; })) {
|
|
1365
|
+
filterArrayFields_1.push(sel);
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
(report.fields_filter || []).forEach(function (filterAnd) {
|
|
1369
|
+
var ors = [];
|
|
1370
|
+
var hasArrayTarget = false;
|
|
1371
|
+
(filterAnd.ors || []).forEach(function (filter) {
|
|
1372
|
+
var targets = getFilterTargets(filter.field, report);
|
|
1373
|
+
if (!targets.length) {
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
targets.forEach(function (path) {
|
|
1377
|
+
var isArrayTarget = path.includes('.$.');
|
|
1378
|
+
var normalizedPath = path.replace(/\.\$/g, '');
|
|
1379
|
+
var expr = buildFilterExpression(filter, normalizedPath);
|
|
1380
|
+
if (expr) {
|
|
1381
|
+
ors.push(expr);
|
|
1382
|
+
}
|
|
1383
|
+
if (isArrayTarget) {
|
|
1384
|
+
hasArrayTarget = true;
|
|
1385
|
+
var leaf_1 = selectedFieldsForQuery_1.find(function (a) { return a.fieldPath === path; });
|
|
1386
|
+
if (leaf_1 && !filterArrayFields_1.some(function (f) { return (f === null || f === void 0 ? void 0 : f.fieldPath) === leaf_1.fieldPath; })) {
|
|
1387
|
+
filterArrayFields_1.push(leaf_1);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
});
|
|
1392
|
+
if (ors.length) {
|
|
1393
|
+
var filterObj = { $or: ors };
|
|
1394
|
+
if (hasArrayTarget) {
|
|
1395
|
+
filterArrays_1.push(filterObj);
|
|
1396
|
+
}
|
|
1397
|
+
else {
|
|
1398
|
+
filters_1.push(filterObj);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
});
|
|
1402
|
+
return [4 /*yield*/, this.callMethod('reportBuilderGetResults', report.type, report.collection_root, rootOptions, filters_1, filterArrays_1, filterArrayFields_1, selectedFieldsForQuery_1, report.fields_custom, report.groups_row, totalsForQuery, report.fields_link, report.id_date_field || null, report.date_interval || null, report.group_type)];
|
|
1403
|
+
case 3:
|
|
1404
|
+
res = _k.sent();
|
|
1405
|
+
if (!(res && res[0])) return [3 /*break*/, 42];
|
|
1406
|
+
results_1 = res[0].results;
|
|
1407
|
+
reportTotals = res[0].totals;
|
|
1408
|
+
if (report.type === 'Group') {
|
|
1409
|
+
applyClientGroupSortToData(results_1, report, effectiveSorts);
|
|
1410
|
+
}
|
|
1411
|
+
customFields = (report.fields_custom || []).map(function (cust) { return (__assign(__assign({}, cust), { id: cust.selFieldId, fieldType: 'Number', leafValueType: cust.leafValueType || 'Value', leafFormatType: 'Number', columnName: cust.columnName || cust.id, show: true })); });
|
|
1412
|
+
exportFields_1 = report.fields_selected.filter(function (a) { return a.show; }).concat(customFields);
|
|
1413
|
+
if (!(report.type === 'List')) return [3 /*break*/, 16];
|
|
1414
|
+
exportFields_1.forEach(function (field) {
|
|
1415
|
+
if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
|
|
1416
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1417
|
+
result[field.id] = result[field.id].toLocaleString();
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
|
|
1421
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1422
|
+
result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
|
|
1426
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1427
|
+
result[field.id] = (0, common_1.round)(result[field.id], 2).toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
|
|
1431
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1432
|
+
result[field.id] = result[field.id] === true ? 'True' : 'False';
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
|
|
1436
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1437
|
+
result[field.id] = result[field.id] === true ? 'Yes' : 'No';
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
|
|
1441
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1442
|
+
result[field.id] = result[field.id] === true ? 1 : 0;
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
|
|
1446
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1447
|
+
result[field.id] = moment(result[field.id]).format('L');
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
|
|
1451
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1452
|
+
result[field.id] = moment(result[field.id]).format('LT');
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
|
|
1456
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1457
|
+
result[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
|
|
1461
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1462
|
+
result[field.id] = moment(result[field.id]).format('LL');
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
|
|
1466
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1467
|
+
result[field.id] = moment(result[field.id]).format('LLL');
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
|
|
1471
|
+
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
1472
|
+
result[field.id] = moment(result[field.id]).toDate().getTime();
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
});
|
|
1476
|
+
wb = new Excel.Workbook();
|
|
1477
|
+
ws_1 = wb.addWorksheet('RB_1', { views: [{ showGridLines: true }] });
|
|
1478
|
+
wb.properties.date1904 = false;
|
|
1479
|
+
wb.calcProperties.fullCalcOnLoad = true;
|
|
1480
|
+
currentRow_1 = 1;
|
|
1481
|
+
row_1 = ws_1.getRow(currentRow_1);
|
|
1482
|
+
row_1.getCell(2).font = {
|
|
1483
|
+
name: 'Arial',
|
|
1484
|
+
bold: true,
|
|
1485
|
+
size: 14
|
|
1486
|
+
};
|
|
1487
|
+
row_1.getCell(4).font = {
|
|
1488
|
+
name: 'Arial',
|
|
1489
|
+
size: 14
|
|
1490
|
+
};
|
|
1491
|
+
row_1.getCell(2).value = 'Report Name:';
|
|
1492
|
+
row_1.getCell(4).value = report.report_name;
|
|
1493
|
+
currentRow_1 += 1;
|
|
1494
|
+
row_1 = ws_1.getRow(currentRow_1);
|
|
1495
|
+
row_1.getCell(2).font = {
|
|
1496
|
+
name: 'Arial',
|
|
1497
|
+
bold: true,
|
|
1498
|
+
size: 14
|
|
1499
|
+
};
|
|
1500
|
+
row_1.getCell(4).font = {
|
|
1501
|
+
name: 'Arial',
|
|
1502
|
+
size: 14
|
|
1503
|
+
};
|
|
1504
|
+
row_1.getCell(2).value = 'Run Date:';
|
|
1505
|
+
row_1.getCell(4).value = moment().format('LLL');
|
|
1506
|
+
currentRow_1 += 2;
|
|
1507
|
+
row_1 = ws_1.getRow(currentRow_1);
|
|
1508
|
+
useLayout_1 = (layoutColumns_1 && layoutColumns_1.length > 0);
|
|
1509
|
+
headers_1 = [];
|
|
1510
|
+
report.groups_row.forEach(function (group) {
|
|
1511
|
+
headers_1.push(group.columnName);
|
|
1512
|
+
});
|
|
1513
|
+
if (useLayout_1) {
|
|
1514
|
+
layoutColumns_1.forEach(function (col, idx) {
|
|
1515
|
+
headers_1.push(col.header || "Column ".concat(idx + 1));
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
else {
|
|
1519
|
+
exportFields_1.forEach(function (field) {
|
|
1520
|
+
headers_1.push(field.columnName);
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
headers_1.forEach(function (header, headerIdx) {
|
|
1524
|
+
row_1.getCell(headerIdx + 1).value = header;
|
|
1525
|
+
});
|
|
1526
|
+
currentRow_1 += 1;
|
|
1527
|
+
row_1 = ws_1.getRow(currentRow_1);
|
|
1528
|
+
exportResults = (0, common_1.deepCopy)(results_1 || []);
|
|
1529
|
+
exportResults.forEach(function (result) {
|
|
1530
|
+
var currentCol = 1;
|
|
1531
|
+
report.groups_row.forEach(function (group) {
|
|
1532
|
+
var _a, _b;
|
|
1533
|
+
writeExcelCell(row_1.getCell(currentCol), (_b = (_a = result === null || result === void 0 ? void 0 : result._id) === null || _a === void 0 ? void 0 : _a[group.id]) !== null && _b !== void 0 ? _b : '', group.treeItem);
|
|
1534
|
+
currentCol += 1;
|
|
1535
|
+
});
|
|
1536
|
+
if (useLayout_1) {
|
|
1537
|
+
var layoutRow_1 = materializeLayoutRow(report, layoutColumns_1, report.fields_selected, result);
|
|
1538
|
+
layoutColumns_1.forEach(function (col, colIdx) {
|
|
1539
|
+
var cellValue = getLayoutCellExportValue(report, layoutRow_1, colIdx);
|
|
1540
|
+
var primaryFieldMeta = getPrimaryFieldForLayoutColumn(col, report.fields_selected);
|
|
1541
|
+
writeExcelCell(row_1.getCell(currentCol), cellValue === undefined ? '' : cellValue, primaryFieldMeta);
|
|
1542
|
+
currentCol += 1;
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
else {
|
|
1546
|
+
exportFields_1.forEach(function (field) {
|
|
1547
|
+
var _a;
|
|
1548
|
+
writeExcelCell(row_1.getCell(currentCol), (_a = result[field.id]) !== null && _a !== void 0 ? _a : '', field);
|
|
1549
|
+
currentCol += 1;
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
currentRow_1 += 1;
|
|
1553
|
+
row_1 = ws_1.getRow(currentRow_1);
|
|
1554
|
+
});
|
|
1555
|
+
_k.label = 4;
|
|
1556
|
+
case 4:
|
|
1557
|
+
_k.trys.push([4, 14, , 15]);
|
|
1558
|
+
return [4 /*yield*/, wb.xlsx.writeBuffer()];
|
|
1559
|
+
case 5:
|
|
1560
|
+
buffer = _k.sent();
|
|
1561
|
+
_k.label = 6;
|
|
1562
|
+
case 6:
|
|
1563
|
+
_k.trys.push([6, 11, 12, 13]);
|
|
1564
|
+
_a = __values(data['emails']), _b = _a.next();
|
|
1565
|
+
_k.label = 7;
|
|
1566
|
+
case 7:
|
|
1567
|
+
if (!!_b.done) return [3 /*break*/, 10];
|
|
1568
|
+
email = _b.value;
|
|
1569
|
+
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t<b>" + this.serverConfig['CLIENT_NAME'] + " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>" + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>" + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
|
|
1570
|
+
{
|
|
1571
|
+
filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',
|
|
1572
|
+
content: buffer
|
|
1573
|
+
}
|
|
1574
|
+
], this.serverConfig['MAIL_FROM_REPORTS'], '')];
|
|
1575
|
+
case 8:
|
|
1576
|
+
_k.sent();
|
|
1577
|
+
_k.label = 9;
|
|
1578
|
+
case 9:
|
|
1579
|
+
_b = _a.next();
|
|
1580
|
+
return [3 /*break*/, 7];
|
|
1581
|
+
case 10: return [3 /*break*/, 13];
|
|
1582
|
+
case 11:
|
|
1583
|
+
e_2_1 = _k.sent();
|
|
1584
|
+
e_2 = { error: e_2_1 };
|
|
1585
|
+
return [3 /*break*/, 13];
|
|
1586
|
+
case 12:
|
|
1587
|
+
try {
|
|
1588
|
+
if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
|
|
1589
|
+
}
|
|
1590
|
+
finally { if (e_2) throw e_2.error; }
|
|
1591
|
+
return [7 /*endfinally*/];
|
|
1592
|
+
case 13: return [3 /*break*/, 15];
|
|
1593
|
+
case 14:
|
|
1594
|
+
err_1 = _k.sent();
|
|
1595
|
+
console.log('Error writing excel export', err_1);
|
|
1596
|
+
return [3 /*break*/, 15];
|
|
1597
|
+
case 15: return [3 /*break*/, 42];
|
|
1598
|
+
case 16:
|
|
1599
|
+
if (!(report.type === 'Group')) return [3 /*break*/, 29];
|
|
1600
|
+
exportFields_1.forEach(function (field) {
|
|
1601
|
+
results_1.forEach(function (result) {
|
|
1602
|
+
modifyDataTypeField(report, result, field, 1);
|
|
1603
|
+
});
|
|
1604
|
+
});
|
|
1605
|
+
wb = new Excel.Workbook();
|
|
1606
|
+
ws_2 = wb.addWorksheet('RB_1', { views: [{ showGridLines: false }] });
|
|
1607
|
+
wb.properties.date1904 = false;
|
|
1608
|
+
wb.calcProperties.fullCalcOnLoad = true;
|
|
1609
|
+
currentRow_2 = 1;
|
|
1610
|
+
row = ws_2.getRow(currentRow_2);
|
|
1611
|
+
row.getCell(2).font = {
|
|
1612
|
+
name: 'Arial',
|
|
1613
|
+
bold: true,
|
|
1614
|
+
size: 14
|
|
1615
|
+
};
|
|
1616
|
+
row.getCell(4).font = {
|
|
1617
|
+
name: 'Arial',
|
|
1618
|
+
size: 14
|
|
1619
|
+
};
|
|
1620
|
+
row.getCell(2).value = 'Report Name:';
|
|
1621
|
+
row.getCell(4).value = report.report_name;
|
|
1622
|
+
currentRow_2 += 1;
|
|
1623
|
+
row = ws_2.getRow(currentRow_2);
|
|
1624
|
+
row.getCell(2).font = {
|
|
1625
|
+
name: 'Arial',
|
|
1626
|
+
bold: true,
|
|
1627
|
+
size: 14
|
|
1628
|
+
};
|
|
1629
|
+
row.getCell(4).font = {
|
|
1630
|
+
name: 'Arial',
|
|
1631
|
+
size: 14
|
|
1632
|
+
};
|
|
1633
|
+
row.getCell(2).value = 'Run Date:';
|
|
1634
|
+
row.getCell(4).value = moment().format('LLL');
|
|
1635
|
+
currentRow_2 += 2;
|
|
1636
|
+
copy = (0, common_1.deepCopy)(results_1);
|
|
1637
|
+
widths_1 = [];
|
|
1638
|
+
copy.forEach(function (res) {
|
|
1639
|
+
currentRow_2 = tabGroupExcelRecursive(report, ws_2, currentRow_2, 1, res, exportFields_1);
|
|
1640
|
+
tabGroupExcelWidthRecursive(report, 1, res, widths_1, exportFields_1);
|
|
1641
|
+
});
|
|
1642
|
+
for (i = 1; i < ws_2.columns.length; i++) {
|
|
1643
|
+
ws_2.columns[i].width = widths_1[i - 1];
|
|
1644
|
+
}
|
|
1645
|
+
now = new Date();
|
|
1646
|
+
_k.label = 17;
|
|
1647
|
+
case 17:
|
|
1648
|
+
_k.trys.push([17, 27, , 28]);
|
|
1649
|
+
return [4 /*yield*/, wb.xlsx.writeBuffer()];
|
|
1650
|
+
case 18:
|
|
1651
|
+
buffer = _k.sent();
|
|
1652
|
+
_k.label = 19;
|
|
1653
|
+
case 19:
|
|
1654
|
+
_k.trys.push([19, 24, 25, 26]);
|
|
1655
|
+
_c = __values(data['emails']), _d = _c.next();
|
|
1656
|
+
_k.label = 20;
|
|
1657
|
+
case 20:
|
|
1658
|
+
if (!!_d.done) return [3 /*break*/, 23];
|
|
1659
|
+
email = _d.value;
|
|
1660
|
+
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t<b>" + this.serverConfig['CLIENT_NAME'] + " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>" + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>" + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
|
|
1661
|
+
{
|
|
1662
|
+
filename: 'Group_Report_' + report.report_name + '_' + now.getFullYear() + '_' + (now.getMonth() + 1) + '_' + now.getDate() + '.xlsx',
|
|
1663
|
+
content: buffer
|
|
1664
|
+
}
|
|
1665
|
+
], this.serverConfig['MAIL_FROM_REPORTS'], '')];
|
|
1666
|
+
case 21:
|
|
1667
|
+
_k.sent();
|
|
1668
|
+
_k.label = 22;
|
|
1669
|
+
case 22:
|
|
1670
|
+
_d = _c.next();
|
|
1671
|
+
return [3 /*break*/, 20];
|
|
1672
|
+
case 23: return [3 /*break*/, 26];
|
|
1673
|
+
case 24:
|
|
1674
|
+
e_3_1 = _k.sent();
|
|
1675
|
+
e_3 = { error: e_3_1 };
|
|
1676
|
+
return [3 /*break*/, 26];
|
|
1677
|
+
case 25:
|
|
1678
|
+
try {
|
|
1679
|
+
if (_d && !_d.done && (_h = _c.return)) _h.call(_c);
|
|
1680
|
+
}
|
|
1681
|
+
finally { if (e_3) throw e_3.error; }
|
|
1682
|
+
return [7 /*endfinally*/];
|
|
1683
|
+
case 26: return [3 /*break*/, 28];
|
|
1684
|
+
case 27:
|
|
1685
|
+
err_2 = _k.sent();
|
|
1686
|
+
console.log('Error writing excel export', err_2);
|
|
1687
|
+
return [3 /*break*/, 28];
|
|
1688
|
+
case 28:
|
|
1689
|
+
;
|
|
1690
|
+
return [3 /*break*/, 42];
|
|
1691
|
+
case 29:
|
|
1692
|
+
if (!(report.type === 'Dated')) return [3 /*break*/, 42];
|
|
1693
|
+
datedUniqueDates_1 = [];
|
|
1694
|
+
datedUniqueGroups_1 = [];
|
|
1695
|
+
datedData_1 = [];
|
|
1696
|
+
reportTotalGroups_1 = [];
|
|
1697
|
+
reportTotalDates_1 = [];
|
|
1698
|
+
// Step 1: Handle quarterly dates if applicable
|
|
1699
|
+
if (report.date_interval === 'Quarterly') {
|
|
1700
|
+
results_1.forEach(function (dataPt) {
|
|
1701
|
+
if (dataPt._id.month < 4) {
|
|
1702
|
+
dataPt._id.quarter = 1;
|
|
1703
|
+
}
|
|
1704
|
+
else if (dataPt._id.month < 7) {
|
|
1705
|
+
dataPt._id.quarter = 2;
|
|
1706
|
+
}
|
|
1707
|
+
else if (dataPt._id.month < 10) {
|
|
1708
|
+
dataPt._id.quarter = 3;
|
|
1709
|
+
}
|
|
1710
|
+
else {
|
|
1711
|
+
dataPt._id.quarter = 4;
|
|
1712
|
+
}
|
|
1713
|
+
delete dataPt._id.month;
|
|
1714
|
+
});
|
|
1715
|
+
_loop_1 = function (i) {
|
|
1716
|
+
var dataPt = results_1[i];
|
|
1717
|
+
if (results_1.filter(function (a) { return JSON.stringify(a._id) === JSON.stringify(dataPt._id); }).length > 1) {
|
|
1718
|
+
var tmpData_1 = results_1.find(function (a) { return JSON.stringify(a._id) === JSON.stringify(dataPt._id); });
|
|
1719
|
+
Object.keys(tmpData_1)
|
|
1720
|
+
.filter(function (a) { return a !== '_id'; })
|
|
1721
|
+
.forEach(function (key) {
|
|
1722
|
+
tmpData_1[key] += dataPt[key];
|
|
1723
|
+
});
|
|
1724
|
+
results_1.splice(i, 1); // Remove the duplicate entry
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
// Deduplicate quarterly data
|
|
1728
|
+
for (i = results_1.length - 1; i >= 1; i--) {
|
|
1729
|
+
_loop_1(i);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
tmpResults = (0, common_1.deepCopy)(results_1);
|
|
1733
|
+
tmpResults.forEach(function (result) {
|
|
1734
|
+
delete result._id.day;
|
|
1735
|
+
delete result._id.week;
|
|
1736
|
+
delete result._id.month;
|
|
1737
|
+
delete result._id.quarter;
|
|
1738
|
+
delete result._id.year;
|
|
1739
|
+
var tmpGroup = {};
|
|
1740
|
+
Object.keys(result._id).forEach(function (key) {
|
|
1741
|
+
tmpGroup[key] = result._id[key];
|
|
1742
|
+
});
|
|
1743
|
+
if (!datedUniqueGroups_1.find(function (a) { return JSON.stringify(a) === JSON.stringify(tmpGroup); })) {
|
|
1744
|
+
datedUniqueGroups_1.push(tmpGroup);
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
// Step 3: Prepare unique dates
|
|
1748
|
+
tmpResults = (0, common_1.deepCopy)(results_1);
|
|
1749
|
+
tmpResults.forEach(function (result) {
|
|
1750
|
+
Object.keys(result._id)
|
|
1751
|
+
.filter(function (a) { return a !== 'second' && a !== 'hour' && a !== 'minute' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; })
|
|
1752
|
+
.forEach(function (key) {
|
|
1753
|
+
delete result._id[key];
|
|
1754
|
+
});
|
|
1755
|
+
var tmpDate = {};
|
|
1756
|
+
Object.keys(result._id).forEach(function (key) {
|
|
1757
|
+
tmpDate[key] = result._id[key];
|
|
1758
|
+
});
|
|
1759
|
+
if (!datedUniqueDates_1.find(function (a) { return JSON.stringify(a) === JSON.stringify(tmpDate); })) {
|
|
1760
|
+
datedUniqueDates_1.push(tmpDate);
|
|
1761
|
+
}
|
|
1762
|
+
});
|
|
1763
|
+
// Build the date strings
|
|
1764
|
+
// Ensure moment is using America/Chicago timezone for all date processing
|
|
1765
|
+
datedUniqueDates_1.forEach(function (result) {
|
|
1766
|
+
if (!result.year) {
|
|
1767
|
+
result.dateString = 'No Date';
|
|
1768
|
+
}
|
|
1769
|
+
else {
|
|
1770
|
+
if (report.date_interval === 'Seconds') {
|
|
1771
|
+
result.date = moment.tz({
|
|
1772
|
+
year: result.year,
|
|
1773
|
+
month: result.month - 1, // Use `month - 1` since months are zero-indexed in moment as well
|
|
1774
|
+
day: result.day,
|
|
1775
|
+
hour: result.hour,
|
|
1776
|
+
minute: result.minute,
|
|
1777
|
+
second: result.second
|
|
1778
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).toDate();
|
|
1779
|
+
result.dateString = moment(result.date).format('MMM DD YYYY HH:mm:ss');
|
|
1780
|
+
}
|
|
1781
|
+
else if (report.date_interval === 'Minutes') {
|
|
1782
|
+
result.date = moment.tz({
|
|
1783
|
+
year: result.year,
|
|
1784
|
+
month: result.month - 1,
|
|
1785
|
+
day: result.day,
|
|
1786
|
+
hour: result.hour,
|
|
1787
|
+
minute: result.minute
|
|
1788
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).toDate();
|
|
1789
|
+
result.dateString = moment(result.date).format('MMM DD YYYY HH:mm');
|
|
1790
|
+
}
|
|
1791
|
+
else if (report.date_interval === 'Hours') {
|
|
1792
|
+
result.date = moment.tz({
|
|
1793
|
+
year: result.year,
|
|
1794
|
+
month: result.month - 1,
|
|
1795
|
+
day: result.day,
|
|
1796
|
+
hour: result.hour
|
|
1797
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).toDate();
|
|
1798
|
+
result.dateString = moment(result.date).format('MMM DD YYYY HH');
|
|
1799
|
+
}
|
|
1800
|
+
else if (report.date_interval === 'Daily') {
|
|
1801
|
+
result.date = moment.tz({
|
|
1802
|
+
year: result.year,
|
|
1803
|
+
month: result.month - 1,
|
|
1804
|
+
day: result.day
|
|
1805
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).toDate();
|
|
1806
|
+
result.dateString = moment(result.date).format('MMM DD YYYY');
|
|
1807
|
+
}
|
|
1808
|
+
else if (report.date_interval === 'Weekly') {
|
|
1809
|
+
result.date = moment.tz({
|
|
1810
|
+
year: result.year,
|
|
1811
|
+
week: result.week
|
|
1812
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).day('Monday').toDate();
|
|
1813
|
+
result.dateLast = moment.tz({
|
|
1814
|
+
year: result.year,
|
|
1815
|
+
week: result.week
|
|
1816
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).day('Sunday').toDate();
|
|
1817
|
+
result.dateString = 'Week #' + result.week + ' ' + result.year + ' (' + moment(result.date).format('MM/DD/YY') + ' - ' + moment(result.dateLast).format('MM/DD/YY') + ')';
|
|
1818
|
+
}
|
|
1819
|
+
else if (report.date_interval === 'Monthly') {
|
|
1820
|
+
result.date = moment.tz({
|
|
1821
|
+
year: result.year,
|
|
1822
|
+
month: result.month - 1, // Months are zero-indexed in moment
|
|
1823
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).toDate();
|
|
1824
|
+
result.dateString = moment(result.date).format('MMM YYYY');
|
|
1825
|
+
}
|
|
1826
|
+
else if (report.date_interval === 'Quarterly') {
|
|
1827
|
+
result.date = moment.tz({
|
|
1828
|
+
year: result.year
|
|
1829
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).quarter(result.quarter).toDate();
|
|
1830
|
+
;
|
|
1831
|
+
result.dateString = 'Q' + result.quarter + ' ' + result.year;
|
|
1832
|
+
}
|
|
1833
|
+
else if (report.date_interval === 'Yearly') {
|
|
1834
|
+
result.date = moment.tz({
|
|
1835
|
+
year: result.year
|
|
1836
|
+
}, (process.env.TZ_CLIENT || 'America/Chicago')).toDate();
|
|
1837
|
+
result.dateString = result.year.toString();
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
});
|
|
1841
|
+
datedUniqueDates_1 = datedUniqueDates_1.filter(function (a) { return !a.date; })
|
|
1842
|
+
.concat(datedUniqueDates_1.filter(function (a) { return a.date; }).sort(function (a, b) { return a.date.getTime() - b.date.getTime(); }));
|
|
1843
|
+
// Step 4: Build datedData and reportTotalGroups
|
|
1844
|
+
datedUniqueDates_1.forEach(function (date) {
|
|
1845
|
+
var tmpData = [];
|
|
1846
|
+
var tmpTotalDated = {};
|
|
1847
|
+
var tmpTotalCnt = {};
|
|
1848
|
+
var tmpTotalType = {};
|
|
1849
|
+
datedUniqueGroups_1.forEach(function (group) {
|
|
1850
|
+
var result = results_1.find(function (a) {
|
|
1851
|
+
var match = true;
|
|
1852
|
+
// Match the group fields
|
|
1853
|
+
Object.keys(group).forEach(function (key) {
|
|
1854
|
+
if (a._id[key] !== group[key]) {
|
|
1855
|
+
match = false;
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
// Match the date fields
|
|
1859
|
+
Object.keys(date).filter(function (key) { return key !== 'date' && key !== 'dateLast' && key !== 'dateString'; }).forEach(function (key) {
|
|
1860
|
+
if (a._id[key] !== date[key]) {
|
|
1861
|
+
match = false;
|
|
1862
|
+
}
|
|
1863
|
+
});
|
|
1864
|
+
return match;
|
|
1865
|
+
});
|
|
1866
|
+
if (result) {
|
|
1867
|
+
tmpData.push(result);
|
|
1868
|
+
Object.keys(result._id).filter(function (a) { return a; }).forEach(function (key) {
|
|
1869
|
+
if (report.fields_total.filter(function (a) { return a.fields.includes(key); }).length) {
|
|
1870
|
+
if (!tmpTotalDated[key]) {
|
|
1871
|
+
tmpTotalDated[key] = result._id[key];
|
|
1872
|
+
}
|
|
1873
|
+
else {
|
|
1874
|
+
tmpTotalDated[key] += result._id[key];
|
|
1875
|
+
}
|
|
1876
|
+
if (!tmpTotalCnt[key]) {
|
|
1877
|
+
tmpTotalCnt[key] = 1;
|
|
1878
|
+
}
|
|
1879
|
+
else {
|
|
1880
|
+
tmpTotalCnt[key] += 1;
|
|
1881
|
+
}
|
|
1882
|
+
tmpTotalType[key] = report.fields_total.find(function (a) { return a.fields.includes(key); }).type;
|
|
1883
|
+
}
|
|
1884
|
+
});
|
|
1885
|
+
Object.keys(result).filter(function (a) { return a && a !== '_id'; }).forEach(function (key) {
|
|
1886
|
+
if (report.fields_total.filter(function (a) { return a.fields.includes(key); }).length) {
|
|
1887
|
+
if (!tmpTotalDated[key]) {
|
|
1888
|
+
tmpTotalDated[key] = result[key];
|
|
1889
|
+
}
|
|
1890
|
+
else {
|
|
1891
|
+
tmpTotalDated[key] += result[key];
|
|
1892
|
+
}
|
|
1893
|
+
if (!tmpTotalCnt[key]) {
|
|
1894
|
+
tmpTotalCnt[key] = 1;
|
|
1895
|
+
}
|
|
1896
|
+
else {
|
|
1897
|
+
tmpTotalCnt[key] += 1;
|
|
1898
|
+
}
|
|
1899
|
+
tmpTotalType[key] = report.fields_total.find(function (a) { return a.fields.includes(key); }).type;
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
else {
|
|
1904
|
+
tmpData.push(null);
|
|
1905
|
+
}
|
|
1906
|
+
});
|
|
1907
|
+
// Handle averaging for totals
|
|
1908
|
+
Object.keys(tmpTotalType).forEach(function (totalKey) {
|
|
1909
|
+
if (tmpTotalType[totalKey] === 'avg') {
|
|
1910
|
+
tmpTotalDated[totalKey] = tmpTotalDated[totalKey] / tmpTotalCnt[totalKey];
|
|
1911
|
+
}
|
|
1912
|
+
tmpTotalDated[totalKey] = (0, common_1.round)(tmpTotalDated[totalKey], 2);
|
|
1913
|
+
});
|
|
1914
|
+
reportTotalDates_1.push(tmpTotalDated);
|
|
1915
|
+
datedData_1.push(tmpData);
|
|
1916
|
+
});
|
|
1917
|
+
// Calculate group-level totals
|
|
1918
|
+
datedUniqueGroups_1.forEach(function (group) {
|
|
1919
|
+
var tmpTotalGroup = {};
|
|
1920
|
+
var filteredData = results_1.filter(function (a) {
|
|
1921
|
+
var match = (!Object.keys(group).length || group._id === null) ? false : true;
|
|
1922
|
+
Object.keys(group).filter(function (a) { return a !== 'date' && a !== 'dateLast' && a !== 'dateString' && a !== 'second' && a !== 'minute' && a !== 'hour' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; }).forEach(function (key) {
|
|
1923
|
+
if (a._id[key] !== group[key]) {
|
|
1924
|
+
match = false;
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
return match;
|
|
1928
|
+
});
|
|
1929
|
+
report.fields_total.forEach(function (total) {
|
|
1930
|
+
total.fields.forEach(function (field) {
|
|
1931
|
+
if (filteredData.length) {
|
|
1932
|
+
tmpTotalGroup[field] = filteredData.filter(function (a) { return a && a[field]; })
|
|
1933
|
+
.map(function (a) { return a[field]; })
|
|
1934
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
1935
|
+
if (total.type === 'avg') {
|
|
1936
|
+
tmpTotalGroup[field] = (0, common_1.round)(tmpTotalGroup[field] / filteredData.length, 2);
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
else {
|
|
1940
|
+
tmpTotalGroup[field] = 0;
|
|
1941
|
+
}
|
|
1942
|
+
});
|
|
1943
|
+
});
|
|
1944
|
+
reportTotalGroups_1.push(tmpTotalGroup);
|
|
1945
|
+
});
|
|
1946
|
+
wb = new Excel.Workbook();
|
|
1947
|
+
ws = wb.addWorksheet('Dated_Report', { views: [{ showGridLines: true }] });
|
|
1948
|
+
wb.properties.date1904 = false;
|
|
1949
|
+
wb.calcProperties.fullCalcOnLoad = true;
|
|
1950
|
+
currentRow = 1;
|
|
1951
|
+
currentCol_1 = 1;
|
|
1952
|
+
row_2 = ws.getRow(currentRow);
|
|
1953
|
+
row_2.getCell(2).font = {
|
|
1954
|
+
name: 'Arial',
|
|
1955
|
+
bold: true,
|
|
1956
|
+
size: 14
|
|
1957
|
+
};
|
|
1958
|
+
row_2.getCell(4).font = {
|
|
1959
|
+
name: 'Arial',
|
|
1960
|
+
size: 14
|
|
1961
|
+
};
|
|
1962
|
+
row_2.getCell(2).value = 'Report Name:';
|
|
1963
|
+
row_2.getCell(4).value = report.report_name;
|
|
1964
|
+
currentRow += 1;
|
|
1965
|
+
row_2 = ws.getRow(currentRow);
|
|
1966
|
+
row_2.getCell(2).font = {
|
|
1967
|
+
name: 'Arial',
|
|
1968
|
+
bold: true,
|
|
1969
|
+
size: 14
|
|
1970
|
+
};
|
|
1971
|
+
row_2.getCell(4).font = {
|
|
1972
|
+
name: 'Arial',
|
|
1973
|
+
size: 14
|
|
1974
|
+
};
|
|
1975
|
+
row_2.getCell(2).value = 'Run Date:';
|
|
1976
|
+
row_2.getCell(4).value = moment().format('LLL');
|
|
1977
|
+
currentRow += 2;
|
|
1978
|
+
row_2 = ws.getRow(currentRow);
|
|
1979
|
+
// Add group column headers
|
|
1980
|
+
report.groups_row.forEach(function (group) {
|
|
1981
|
+
row_2.getCell(currentCol_1).value = group.columnName;
|
|
1982
|
+
currentCol_1++;
|
|
1983
|
+
});
|
|
1984
|
+
// Add field headers
|
|
1985
|
+
currentCol_1 += report.fields_selected.filter(function (a) { return a.show; }).length;
|
|
1986
|
+
// Add the date interval headers
|
|
1987
|
+
report.fields_selected.filter(function (a) { return a.show; }).forEach(function () {
|
|
1988
|
+
datedUniqueDates_1.forEach(function (date) {
|
|
1989
|
+
row_2.getCell(currentCol_1).value = date.dateString;
|
|
1990
|
+
currentCol_1++;
|
|
1991
|
+
});
|
|
1992
|
+
});
|
|
1993
|
+
// Add totals headers
|
|
1994
|
+
report.fields_total.forEach(function (total) {
|
|
1995
|
+
row_2.getCell(currentCol_1).value = 'Totals - ' + (0, common_1.toTitleCase)(total.type);
|
|
1996
|
+
currentCol_1++;
|
|
1997
|
+
});
|
|
1998
|
+
currentCol_1 = 1;
|
|
1999
|
+
currentRow += 1;
|
|
2000
|
+
row_2 = ws.getRow(currentRow);
|
|
2001
|
+
_loop_2 = function (i) {
|
|
2002
|
+
var group = datedUniqueGroups_1[i];
|
|
2003
|
+
var _loop_3 = function (j) {
|
|
2004
|
+
var field = report.fields_selected.filter(function (a) { return a.show; })[j];
|
|
2005
|
+
currentCol_1 = 1;
|
|
2006
|
+
row_2 = ws.getRow(currentRow);
|
|
2007
|
+
// Populate group data
|
|
2008
|
+
report.groups_row.forEach(function (groupRow) {
|
|
2009
|
+
row_2.getCell(currentCol_1).value = (j === 0) ? group[groupRow.id] : '';
|
|
2010
|
+
currentCol_1++;
|
|
2011
|
+
});
|
|
2012
|
+
// Populate field data
|
|
2013
|
+
row_2.getCell(currentCol_1).value = field.columnName;
|
|
2014
|
+
currentCol_1++;
|
|
2015
|
+
// Populate date interval data for each field
|
|
2016
|
+
for (var k = 0; k < datedUniqueDates_1.length; k++) {
|
|
2017
|
+
var result = datedData_1[k];
|
|
2018
|
+
if (result[i]) {
|
|
2019
|
+
row_2.getCell(currentCol_1).value = result[i][field.id] ? result[i][field.id] : '';
|
|
2020
|
+
}
|
|
2021
|
+
else {
|
|
2022
|
+
row_2.getCell(currentCol_1).value = '';
|
|
2023
|
+
}
|
|
2024
|
+
currentCol_1++;
|
|
2025
|
+
}
|
|
2026
|
+
// Add totals for each field in the report
|
|
2027
|
+
for (var k = 0; k < report.fields_total.length; k++) {
|
|
2028
|
+
row_2.getCell(currentCol_1).value = reportTotalGroups_1[i][field.id] ? reportTotalGroups_1[i][field.id] : '';
|
|
2029
|
+
currentCol_1++;
|
|
2030
|
+
}
|
|
2031
|
+
currentRow++; // Move to the next row for the next field
|
|
2032
|
+
};
|
|
2033
|
+
for (var j = 0; j < report.fields_selected.filter(function (a) { return a.show; }).length; j++) {
|
|
2034
|
+
_loop_3(j);
|
|
2035
|
+
}
|
|
2036
|
+
};
|
|
2037
|
+
// Populate data for each group and field with date intervals
|
|
2038
|
+
for (i = 0; i < datedUniqueGroups_1.length; i++) {
|
|
2039
|
+
_loop_2(i);
|
|
2040
|
+
}
|
|
2041
|
+
// Add report totals at the bottom
|
|
2042
|
+
if (reportTotals) {
|
|
2043
|
+
for (i = 0; i < report.fields_total.length; i++) {
|
|
2044
|
+
total = report.fields_total[i];
|
|
2045
|
+
row_2 = ws.getRow(currentRow);
|
|
2046
|
+
currentCol_1 = 1;
|
|
2047
|
+
row_2.getCell(currentCol_1).value = (0, common_1.toTitleCase)(total.type) + ' Totals';
|
|
2048
|
+
currentCol_1 += report.groups_row.length; // Skip group columns
|
|
2049
|
+
// Skip the date columns for the totals row
|
|
2050
|
+
report.fields_selected.filter(function (a) { return a.show; }).forEach(function () {
|
|
2051
|
+
currentCol_1 += 1;
|
|
2052
|
+
});
|
|
2053
|
+
datedUniqueDates_1.forEach(function () {
|
|
2054
|
+
currentCol_1++;
|
|
2055
|
+
});
|
|
2056
|
+
// Set totals in the correct fields
|
|
2057
|
+
for (j = 0; j < report.fields_selected.filter(function (a) { return a.show; }).length; j++) {
|
|
2058
|
+
field = report.fields_selected.filter(function (a) { return a.show; })[j];
|
|
2059
|
+
row_2.getCell(currentCol_1).value = reportTotals[total.id + '_' + field.id] || '';
|
|
2060
|
+
currentCol_1++;
|
|
2061
|
+
}
|
|
2062
|
+
currentRow++; // Move to the next row for the next total
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
_k.label = 30;
|
|
2066
|
+
case 30:
|
|
2067
|
+
_k.trys.push([30, 40, , 41]);
|
|
2068
|
+
return [4 /*yield*/, wb.xlsx.writeBuffer()];
|
|
2069
|
+
case 31:
|
|
2070
|
+
buffer = _k.sent();
|
|
2071
|
+
_k.label = 32;
|
|
2072
|
+
case 32:
|
|
2073
|
+
_k.trys.push([32, 37, 38, 39]);
|
|
2074
|
+
_e = __values(data['emails']), _f = _e.next();
|
|
2075
|
+
_k.label = 33;
|
|
2076
|
+
case 33:
|
|
2077
|
+
if (!!_f.done) return [3 /*break*/, 36];
|
|
2078
|
+
email = _f.value;
|
|
2079
|
+
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t<b>".concat(this.serverConfig['CLIENT_NAME'], " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>").concat(report.report_name, "<br>\n\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>").concat(data['user'], "<br><br>\n\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>"), [
|
|
2080
|
+
{
|
|
2081
|
+
filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',
|
|
2082
|
+
content: buffer
|
|
2083
|
+
}
|
|
2084
|
+
], this.serverConfig['MAIL_FROM_REPORTS'], '')];
|
|
2085
|
+
case 34:
|
|
2086
|
+
_k.sent();
|
|
2087
|
+
_k.label = 35;
|
|
2088
|
+
case 35:
|
|
2089
|
+
_f = _e.next();
|
|
2090
|
+
return [3 /*break*/, 33];
|
|
2091
|
+
case 36: return [3 /*break*/, 39];
|
|
2092
|
+
case 37:
|
|
2093
|
+
e_4_1 = _k.sent();
|
|
2094
|
+
e_4 = { error: e_4_1 };
|
|
2095
|
+
return [3 /*break*/, 39];
|
|
2096
|
+
case 38:
|
|
2097
|
+
try {
|
|
2098
|
+
if (_f && !_f.done && (_j = _e.return)) _j.call(_e);
|
|
2099
|
+
}
|
|
2100
|
+
finally { if (e_4) throw e_4.error; }
|
|
2101
|
+
return [7 /*endfinally*/];
|
|
2102
|
+
case 39: return [3 /*break*/, 41];
|
|
2103
|
+
case 40:
|
|
2104
|
+
err_3 = _k.sent();
|
|
2105
|
+
console.log('Error writing excel export', err_3);
|
|
2106
|
+
return [3 /*break*/, 41];
|
|
2107
|
+
case 41: return [2 /*return*/, true];
|
|
2108
|
+
case 42: return [3 /*break*/, 44];
|
|
2109
|
+
case 43:
|
|
2110
|
+
err_4 = _k.sent();
|
|
2111
|
+
err_4.message = "Error in Report Builder Cron Job - Report Builder Build Tree: ".concat(err_4.message);
|
|
2112
|
+
throw err_4;
|
|
2113
|
+
case 44: return [2 /*return*/, true];
|
|
2114
|
+
}
|
|
2115
|
+
});
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
function modifyDataTypeField(report, result, field, index) {
|
|
2122
|
+
var processFieldValue = function (value, field) {
|
|
2123
|
+
if (value === undefined || value === null) {
|
|
2124
|
+
return '';
|
|
2125
|
+
}
|
|
2126
|
+
if (field.fieldType === 'Boolean') {
|
|
2127
|
+
if (!field.leafFormatType || field.leafFormatType === 'Boolean') {
|
|
2128
|
+
return value === true ? 'True' : 'False';
|
|
2129
|
+
}
|
|
2130
|
+
else if (field.leafFormatType === 'String') {
|
|
2131
|
+
return value === true ? 'Yes' : 'No';
|
|
2132
|
+
}
|
|
2133
|
+
else if (field.leafFormatType === 'Boolean_Number') {
|
|
2134
|
+
return value === true ? 1 : 0;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
else if (field.fieldType === 'Number' || field.leafValueType === 'Count') {
|
|
2138
|
+
if (field.leafFormatType === 'Number') {
|
|
2139
|
+
return value.toLocaleString();
|
|
2140
|
+
}
|
|
2141
|
+
else if (field.leafFormatType === 'String') {
|
|
2142
|
+
return value.toString();
|
|
2143
|
+
}
|
|
2144
|
+
else if (field.leafFormatType === 'Currency') {
|
|
2145
|
+
return (0, common_1.round)(value, 2).toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
else if (field.fieldType === 'Date') {
|
|
2149
|
+
switch (field.leafFormatType) {
|
|
2150
|
+
case 'Date':
|
|
2151
|
+
return moment(value).format('L');
|
|
2152
|
+
case 'Time':
|
|
2153
|
+
return moment(value).format('LT');
|
|
2154
|
+
case 'DateTime':
|
|
2155
|
+
return moment(value).format('MM/DD/YYYY h:mm A');
|
|
2156
|
+
case 'Date_long':
|
|
2157
|
+
return moment(value).format('LL');
|
|
2158
|
+
case 'DateTime_long':
|
|
2159
|
+
return moment(value).format('LLL');
|
|
2160
|
+
case 'Timestamp':
|
|
2161
|
+
return moment(value).toDate().getTime();
|
|
2162
|
+
default:
|
|
2163
|
+
return value;
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
return value;
|
|
2167
|
+
};
|
|
2168
|
+
var processArrayField = function (array, field) {
|
|
2169
|
+
return array.map(function (value) { return processFieldValue(value, field); });
|
|
2170
|
+
};
|
|
2171
|
+
if (index < report.groups_row.length) {
|
|
2172
|
+
// Handle grouped data
|
|
2173
|
+
var groupKey = 'gr_' + (index + 1);
|
|
2174
|
+
if (result[groupKey]) {
|
|
2175
|
+
result[groupKey].forEach(function (subResult) {
|
|
2176
|
+
modifyDataTypeField(report, subResult, field, index + 1);
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
else {
|
|
2181
|
+
// Process final-level fields
|
|
2182
|
+
if (Array.isArray(result[field.id])) {
|
|
2183
|
+
result[field.id] = processArrayField(result[field.id], field);
|
|
2184
|
+
}
|
|
2185
|
+
else {
|
|
2186
|
+
result[field.id] = processFieldValue(result[field.id], field);
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
function tabGroupExcelRecursive(report, ws, currentRow, level, result, fields) {
|
|
2191
|
+
var row = ws.getRow(currentRow);
|
|
2192
|
+
var fieldCount = fields.length;
|
|
2193
|
+
if (level < report.groups_row.length) {
|
|
2194
|
+
row.getCell(2).fill = {
|
|
2195
|
+
fgColor: { argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff' },
|
|
2196
|
+
type: 'pattern',
|
|
2197
|
+
pattern: 'solid'
|
|
2198
|
+
};
|
|
2199
|
+
row.getCell(2).font = {
|
|
2200
|
+
color: { argb: report.groups_row[level - 1].font_color ? report.groups_row[level - 1].font_color.replace('#', '') : '000000' },
|
|
2201
|
+
name: 'Arial',
|
|
2202
|
+
bold: true,
|
|
2203
|
+
size: 14
|
|
2204
|
+
};
|
|
2205
|
+
var currentGroup = report.groups_row[level - 1];
|
|
2206
|
+
row.getCell(2).value = currentGroup.columnName + ': ' + (result._id[currentGroup.id] || '');
|
|
2207
|
+
ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(fieldCount + 1).$col$row);
|
|
2208
|
+
row.getCell(2).border = {
|
|
2209
|
+
top: { style: 'thick' },
|
|
2210
|
+
left: { style: 'thick' },
|
|
2211
|
+
right: { style: 'thick' }
|
|
2212
|
+
};
|
|
2213
|
+
if (report.fields_total.length) {
|
|
2214
|
+
report.fields_total.forEach(function (total) {
|
|
2215
|
+
currentRow += 1;
|
|
2216
|
+
row = ws.getRow(currentRow);
|
|
2217
|
+
fields.forEach(function (field, fieldIndex) {
|
|
2218
|
+
if (total.fields.includes(field.id)) {
|
|
2219
|
+
row.getCell(fieldIndex + 2).value = field.columnName;
|
|
2220
|
+
row.getCell(fieldIndex + 2).font = {
|
|
2221
|
+
name: 'Arial',
|
|
2222
|
+
bold: true,
|
|
2223
|
+
size: 10
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
if (field.leafFormatType === 'Currency') {
|
|
2227
|
+
row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
|
|
2228
|
+
}
|
|
2229
|
+
else if (field.leafFormatType === 'Number') {
|
|
2230
|
+
row.getCell(fieldIndex + 2).numFmt = '#,##0';
|
|
2231
|
+
}
|
|
2232
|
+
if (fieldIndex === 0) {
|
|
2233
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2234
|
+
left: { style: 'thick' }
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2237
|
+
else if (fieldIndex === fieldCount - 1) {
|
|
2238
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2239
|
+
right: { style: 'thick' }
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
});
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2245
|
+
// Totals
|
|
2246
|
+
report.fields_total.forEach(function (total) {
|
|
2247
|
+
currentRow += 1;
|
|
2248
|
+
row = ws.getRow(currentRow);
|
|
2249
|
+
fields.forEach(function (field, fieldIndex) {
|
|
2250
|
+
if (total.fields.includes(field.id)) {
|
|
2251
|
+
row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
|
|
2252
|
+
row.getCell(fieldIndex + 2).font = {
|
|
2253
|
+
name: 'Arial',
|
|
2254
|
+
bold: true,
|
|
2255
|
+
size: 10
|
|
2256
|
+
};
|
|
2257
|
+
if (field.leafFormatType === 'Currency') {
|
|
2258
|
+
row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
|
|
2259
|
+
}
|
|
2260
|
+
else if (field.leafFormatType === 'Number') {
|
|
2261
|
+
row.getCell(fieldIndex + 2).numFmt = '#,##0';
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
if (fieldIndex === 0) {
|
|
2265
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2266
|
+
top: { style: 'thin' },
|
|
2267
|
+
left: { style: 'thick' },
|
|
2268
|
+
bottom: { style: 'thick' }
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
else if (fieldIndex === fieldCount - 1) {
|
|
2272
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2273
|
+
top: { style: 'thin' },
|
|
2274
|
+
bottom: { style: 'thick' },
|
|
2275
|
+
right: { style: 'thick' }
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
else {
|
|
2279
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2280
|
+
top: { style: 'thin' },
|
|
2281
|
+
bottom: { style: 'thick' }
|
|
2282
|
+
};
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
});
|
|
2286
|
+
currentRow += 1;
|
|
2287
|
+
var nextGroup = report.groups_row[level];
|
|
2288
|
+
if (nextGroup) {
|
|
2289
|
+
var nextResults = result[nextGroup.id];
|
|
2290
|
+
if (Array.isArray(nextResults)) {
|
|
2291
|
+
nextResults.forEach(function (tDataRes) {
|
|
2292
|
+
currentRow = tabGroupExcelRecursive(report, ws, currentRow, level + 1, tDataRes, fields);
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
else {
|
|
2298
|
+
row.getCell(2).fill = {
|
|
2299
|
+
fgColor: { argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff' },
|
|
2300
|
+
type: 'pattern',
|
|
2301
|
+
pattern: 'solid'
|
|
2302
|
+
};
|
|
2303
|
+
row.getCell(2).font = {
|
|
2304
|
+
color: { argb: report.groups_row[level - 1].font_color ? report.groups_row[level - 1].font_color.replace('#', '') : '000000' },
|
|
2305
|
+
name: 'Arial',
|
|
2306
|
+
bold: true,
|
|
2307
|
+
size: 12
|
|
2308
|
+
};
|
|
2309
|
+
var finalGroup = report.groups_row[level - 1];
|
|
2310
|
+
row.getCell(2).value = finalGroup.columnName + ': ' + (result._id[finalGroup.id] || '');
|
|
2311
|
+
ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(fieldCount + 1).$col$row);
|
|
2312
|
+
row.getCell(2).border = {
|
|
2313
|
+
top: { style: 'thick' },
|
|
2314
|
+
left: { style: 'thick' },
|
|
2315
|
+
right: { style: 'thick' }
|
|
2316
|
+
};
|
|
2317
|
+
currentRow += 1;
|
|
2318
|
+
row = ws.getRow(currentRow);
|
|
2319
|
+
// Headers
|
|
2320
|
+
fields.forEach(function (field, fieldIndex) {
|
|
2321
|
+
row.getCell(fieldIndex + 2).value = field.columnName;
|
|
2322
|
+
row.getCell(fieldIndex + 2).font = {
|
|
2323
|
+
name: 'Arial',
|
|
2324
|
+
bold: true,
|
|
2325
|
+
size: 10
|
|
2326
|
+
};
|
|
2327
|
+
if (field.leafFormatType === 'Currency') {
|
|
2328
|
+
row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
|
|
2329
|
+
}
|
|
2330
|
+
else if (field.leafFormatType === 'Number') {
|
|
2331
|
+
row.getCell(fieldIndex + 2).numFmt = '#,##0';
|
|
2332
|
+
}
|
|
2333
|
+
if (fieldIndex === 0) {
|
|
2334
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2335
|
+
left: { style: 'thick' }
|
|
2336
|
+
};
|
|
2337
|
+
}
|
|
2338
|
+
else if (fieldIndex === fieldCount - 1) {
|
|
2339
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2340
|
+
right: { style: 'thick' }
|
|
2341
|
+
};
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
// Data
|
|
2345
|
+
getMaxRows(result).forEach(function (res, resIndex) {
|
|
2346
|
+
currentRow += 1;
|
|
2347
|
+
row = ws.getRow(currentRow);
|
|
2348
|
+
fields.forEach(function (field, fieldIndex) {
|
|
2349
|
+
var value = null;
|
|
2350
|
+
if (Array.isArray(result[field.id])) {
|
|
2351
|
+
value = result[field.id][resIndex] !== undefined ? result[field.id][resIndex] : result[field.id][result[field.id].length - 1];
|
|
2352
|
+
}
|
|
2353
|
+
else {
|
|
2354
|
+
value = result[field.id];
|
|
2355
|
+
}
|
|
2356
|
+
if (field.fieldType === 'Number' && typeof (value) === 'string' && value) {
|
|
2357
|
+
row.getCell(fieldIndex + 2).value = parseFloat(value.replace(new RegExp(/\,/g), '').replace(new RegExp(/\$/g), ''));
|
|
2358
|
+
}
|
|
2359
|
+
else {
|
|
2360
|
+
row.getCell(fieldIndex + 2).value = value;
|
|
2361
|
+
}
|
|
2362
|
+
if (field.leafFormatType === 'Currency') {
|
|
2363
|
+
row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
|
|
2364
|
+
}
|
|
2365
|
+
else if (field.leafFormatType === 'Number') {
|
|
2366
|
+
row.getCell(fieldIndex + 2).numFmt = '#,##0';
|
|
2367
|
+
}
|
|
2368
|
+
row.getCell(fieldIndex + 2).font = {
|
|
2369
|
+
name: 'Arial',
|
|
2370
|
+
size: 10
|
|
2371
|
+
};
|
|
2372
|
+
if (fieldIndex === 0) {
|
|
2373
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2374
|
+
left: { style: 'thick' }
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
else if (fieldIndex === fieldCount - 1) {
|
|
2378
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2379
|
+
right: { style: 'thick' }
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2382
|
+
});
|
|
2383
|
+
});
|
|
2384
|
+
// Totals
|
|
2385
|
+
report.fields_total.forEach(function (total) {
|
|
2386
|
+
currentRow += 1;
|
|
2387
|
+
row = ws.getRow(currentRow);
|
|
2388
|
+
fields.forEach(function (field, fieldIndex) {
|
|
2389
|
+
if (total.fields.includes(field.id)) {
|
|
2390
|
+
row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
|
|
2391
|
+
row.getCell(fieldIndex + 2).font = {
|
|
2392
|
+
name: 'Arial',
|
|
2393
|
+
bold: true,
|
|
2394
|
+
size: 10
|
|
2395
|
+
};
|
|
2396
|
+
if (field.leafFormatType === 'Currency') {
|
|
2397
|
+
row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
|
|
2398
|
+
}
|
|
2399
|
+
else if (field.leafFormatType === 'Number') {
|
|
2400
|
+
row.getCell(fieldIndex + 2).numFmt = '#,##0';
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
if (fieldIndex === 0) {
|
|
2404
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2405
|
+
top: { style: 'thin' },
|
|
2406
|
+
left: { style: 'thick' },
|
|
2407
|
+
bottom: { style: 'thick' }
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
else if (fieldIndex === fieldCount - 1) {
|
|
2411
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2412
|
+
top: { style: 'thin' },
|
|
2413
|
+
bottom: { style: 'thick' },
|
|
2414
|
+
right: { style: 'thick' }
|
|
2415
|
+
};
|
|
2416
|
+
}
|
|
2417
|
+
else {
|
|
2418
|
+
row.getCell(fieldIndex + 2).border = {
|
|
2419
|
+
top: { style: 'thin' },
|
|
2420
|
+
bottom: { style: 'thick' }
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
});
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
return currentRow + 1;
|
|
2427
|
+
}
|
|
2428
|
+
function tabGroupExcelWidthRecursive(report, level, result, cols, fields) {
|
|
2429
|
+
if (level < report.groups_row.length) {
|
|
2430
|
+
var nextGroup = report.groups_row[level];
|
|
2431
|
+
if (nextGroup) {
|
|
2432
|
+
var nextResults = result[nextGroup.id];
|
|
2433
|
+
if (Array.isArray(nextResults)) {
|
|
2434
|
+
nextResults.forEach(function (tDataRes) {
|
|
2435
|
+
cols = tabGroupExcelWidthRecursive(report, level + 1, tDataRes, cols, fields);
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
else {
|
|
2441
|
+
fields.forEach(function (field, fieldIndex) {
|
|
2442
|
+
if (Array.isArray(result[field.id])) {
|
|
2443
|
+
result[field.id].forEach(function (res) {
|
|
2444
|
+
var length = 10;
|
|
2445
|
+
if (res) {
|
|
2446
|
+
length = res.length + 3;
|
|
2447
|
+
}
|
|
2448
|
+
if (!cols[fieldIndex]) {
|
|
2449
|
+
cols[fieldIndex] = Math.max(10, field.columnName.length);
|
|
2450
|
+
}
|
|
2451
|
+
if (length > cols[fieldIndex]) {
|
|
2452
|
+
cols[fieldIndex] = length;
|
|
2453
|
+
}
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
else {
|
|
2457
|
+
var res = result[field.id];
|
|
2458
|
+
var length_1 = 10;
|
|
2459
|
+
if (res !== null && res !== undefined) {
|
|
2460
|
+
var resStr = (typeof res === 'string') ? res : "".concat(res);
|
|
2461
|
+
length_1 = resStr.length + 3;
|
|
2462
|
+
}
|
|
2463
|
+
if (!cols[fieldIndex]) {
|
|
2464
|
+
cols[fieldIndex] = Math.max(10, field.columnName.length);
|
|
2465
|
+
}
|
|
2466
|
+
if (length_1 > cols[fieldIndex]) {
|
|
2467
|
+
cols[fieldIndex] = length_1;
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
return cols;
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
//# sourceMappingURL=cron-jobs.js.map
|