@resolveio/server-lib 22.3.219 → 22.3.221
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/.nodemon.json +5 -0
- package/.vscode/settings.json +21 -0
- package/AGENTS.md +195 -0
- package/README.md +22 -0
- package/build_package.sh +5 -0
- package/compileDTS.pl +64 -0
- package/docs/ai-assistant-nightly-eval.md +65 -0
- package/docs/ai-assistant-preflight-checklist.md +23 -0
- package/docs/ai-assistant-report-builder-bridge-playbook.md +115 -0
- package/eslint-plugin-custom/index.js +7 -0
- package/eslint-plugin-custom/rules/no-filter-zero-index.js +44 -0
- package/eslint.config.js +103 -0
- package/gulpfile.js +216 -0
- package/methodAndPublicationListGenerator.py +375 -0
- package/mongodbensurers.js +2 -0
- package/mongostop.js +3 -0
- package/package.json +1 -1
- package/scripts/cleanup-bypassed-callmethod-logs.js +616 -0
- package/settings.development.json +25 -0
- package/settings.development.redacted.json +25 -0
- package/src/.env +12 -0
- package/src/ai/assistant-core-heuristics.ts +379 -0
- package/src/ai/resolveio-platform-intelligence-memory-corpus.ts +185 -0
- package/src/ai/resolveio-platform-intelligence-memory.ts +325 -0
- package/{ai/resolveio-platform-intelligence-types.d.ts → src/ai/resolveio-platform-intelligence-types.ts} +20 -15
- package/src/ai/resolveio-platform-intelligence.ts +462 -0
- package/src/client-server-app.ts +12 -0
- package/src/collections/ai-run.collection.ts +117 -0
- package/src/collections/ai-terminal-conversation.collection.ts +91 -0
- package/src/collections/ai-terminal-issue-report.collection.ts +99 -0
- package/src/collections/ai-terminal-message.collection.ts +77 -0
- package/src/collections/app-setting.collection.ts +104 -0
- package/src/collections/app-status.collection.ts +58 -0
- package/src/collections/communication-metric.collection.ts +84 -0
- package/src/collections/counter.collection.ts +56 -0
- package/src/collections/cron-job-history.collection.ts +94 -0
- package/src/collections/cron-job.collection.ts +92 -0
- package/src/collections/customer-notification.collection.ts +131 -0
- package/src/collections/customer-portal-password.collection.ts +76 -0
- package/src/collections/email-history.collection.ts +134 -0
- package/src/collections/email-verified.collection.ts +62 -0
- package/src/collections/file.collection.ts +74 -0
- package/src/collections/flag-update.collection.ts +57 -0
- package/src/collections/flag.collection.ts +57 -0
- package/src/collections/log-method-latency.collection.ts +77 -0
- package/src/collections/log-subscription.collection.ts +80 -0
- package/src/collections/log.collection.ts +93 -0
- package/src/collections/logged-in-users.collection.ts +67 -0
- package/src/collections/monitor-cpu.collection.ts +65 -0
- package/src/collections/monitor-function.collection.ts +74 -0
- package/src/collections/monitor-memory.collection.ts +77 -0
- package/src/collections/monitor-mongo.collection.ts +71 -0
- package/src/collections/notification.collection.ts +57 -0
- package/src/collections/openai-usage-ledger.collection.ts +131 -0
- package/src/collections/report-builder-dashboard-builder.collection.ts +109 -0
- package/src/collections/report-builder-library.collection.ts +89 -0
- package/src/collections/report-builder-report.collection.ts +184 -0
- package/src/collections/user-group.collection.ts +89 -0
- package/src/collections/user-guide.collection.ts +57 -0
- package/src/collections/user.collection.ts +181 -0
- package/src/cron/cron.ts +117 -0
- package/src/fixtures/cron-jobs.ts +95 -0
- package/src/fixtures/init.ts +35 -0
- package/src/http/auth.ts +818 -0
- package/src/http/health.ts +7 -0
- package/src/http/home.ts +90 -0
- package/src/http/slow-query-publication.ts +49 -0
- package/src/index.ts +1 -0
- package/src/managers/ai-assistant-codex-manager.manager.ts +1131 -0
- package/src/managers/ai-run-evidence.manager.ts +264 -0
- package/src/managers/communication-metric.manager.ts +82 -0
- package/src/managers/cron.manager.ts +333 -0
- package/src/managers/customer-notification-content.manager.ts +236 -0
- package/src/managers/diagnostic-manager-bootstrap.ts +165 -0
- package/src/managers/error-auto-fix.manager.ts +2767 -0
- package/src/managers/local-log.manager.ts +113 -0
- package/src/managers/method.manager.ts +1857 -0
- package/src/managers/mongo.manager.ts +4575 -0
- package/src/managers/monitor.manager.ts +507 -0
- package/src/managers/openai-usage-ledger.manager.ts +112 -0
- package/src/managers/slow-query-verifier.manager.ts +3590 -0
- package/src/managers/slow-query.manager.ts +519 -0
- package/src/managers/subscription.manager.ts +3128 -0
- package/src/managers/websocket.manager.ts +746 -0
- package/src/managers/worker-dispatcher.manager.ts +1360 -0
- package/src/managers/worker-server.manager.ts +536 -0
- package/src/methods/accounts.ts +532 -0
- package/src/methods/ai-terminal.ts +29070 -0
- package/src/methods/app-settings.ts +114 -0
- package/src/methods/aws.ts +649 -0
- package/src/methods/collections.ts +641 -0
- package/src/methods/counters.ts +69 -0
- package/src/methods/cron-jobs.ts +2614 -0
- package/src/methods/customer-notifications.ts +458 -0
- package/src/methods/diagnostics.ts +616 -0
- package/src/methods/flag-updates.ts +7 -0
- package/src/methods/flags.ts +7 -0
- package/src/methods/logs.ts +657 -0
- package/src/methods/mongo-explorer.ts +1880 -0
- package/src/methods/monitor.ts +540 -0
- package/src/methods/pdf.ts +1236 -0
- package/src/methods/publications.ts +129 -0
- package/src/methods/report-builder.ts +3300 -0
- package/src/methods/support.ts +335 -0
- package/src/models/ai-run.model.ts +27 -0
- package/src/models/ai-terminal-conversation.model.ts +19 -0
- package/src/models/ai-terminal-issue-report.model.ts +21 -0
- package/src/models/ai-terminal-message.model.ts +24 -0
- package/src/models/app-setting.model.ts +17 -0
- package/{models/app-status.model.d.ts → src/models/app-status.model.ts} +3 -2
- package/{models/billing-logged-in-users.model.d.ts → src/models/billing-logged-in-users.model.ts} +5 -4
- package/src/models/collection-document.model.ts +24 -0
- package/src/models/communication-metric.model.ts +23 -0
- package/{models/counter.model.d.ts → src/models/counter.model.ts} +4 -3
- package/src/models/cron-job-history.model.ts +16 -0
- package/src/models/cron-job.model.ts +15 -0
- package/src/models/customer-notification.model.ts +28 -0
- package/src/models/customer-portal-password.model.ts +12 -0
- package/src/models/dialog.model.ts +25 -0
- package/{models/email-history.model.js → src/models/email-history.model.ts} +36 -4
- package/{models/email-verified.model.d.ts → src/models/email-verified.model.ts} +6 -5
- package/{models/file.model.d.ts → src/models/file.model.ts} +8 -7
- package/{models/flag-update.model.d.ts → src/models/flag-update.model.ts} +4 -3
- package/{models/flag.model.d.ts → src/models/flag.model.ts} +4 -3
- package/src/models/log-method-latency.model.ts +11 -0
- package/{models/log-subscription.model.d.ts → src/models/log-subscription.model.ts} +11 -9
- package/src/models/log.model.ts +19 -0
- package/{models/logged-in-users.model.d.ts → src/models/logged-in-users.model.ts} +6 -5
- package/{models/method-response.model.d.ts → src/models/method-response.model.ts} +7 -6
- package/src/models/method.model.ts +25 -0
- package/{models/monitor-cpu.model.d.ts → src/models/monitor-cpu.model.ts} +9 -7
- package/src/models/monitor-function.model.ts +16 -0
- package/src/models/monitor-memory.model.ts +17 -0
- package/src/models/monitor-mongo.model.ts +15 -0
- package/{models/notification.model.d.ts → src/models/notification.model.ts} +6 -4
- package/src/models/openai-usage-ledger.model.ts +56 -0
- package/src/models/pagination.model.ts +35 -0
- package/src/models/permission.model.ts +14 -0
- package/src/models/report-builder-dashboard-builder.model.ts +29 -0
- package/src/models/report-builder-library.model.ts +20 -0
- package/src/models/report-builder-report.model.ts +136 -0
- package/src/models/report-builder.model.ts +68 -0
- package/src/models/select-data-label.model.ts +9 -0
- package/src/models/server-message.model.ts +31 -0
- package/src/models/slow-query-report.model.ts +23 -0
- package/src/models/subscription.model.ts +73 -0
- package/src/models/support-ticket.model.ts +104 -0
- package/src/models/user-group.model.ts +24 -0
- package/{models/user-guide.model.d.ts → src/models/user-guide.model.ts} +5 -4
- package/src/models/user.model.ts +96 -0
- package/src/private/images/ResolveIO.png +0 -0
- package/src/publications/ai-terminal.ts +73 -0
- package/src/publications/app-settings.ts +25 -0
- package/src/publications/app-status.ts +13 -0
- package/src/publications/cron-jobs.ts +40 -0
- package/src/publications/customer-notifications.ts +101 -0
- package/src/publications/files.ts +33 -0
- package/src/publications/flags-update.ts +19 -0
- package/src/publications/flags.ts +19 -0
- package/src/publications/logs.ts +163 -0
- package/src/publications/notifications.ts +13 -0
- package/src/publications/report-builder-dashboard-builders.ts +39 -0
- package/src/publications/report-builder-libraries.ts +41 -0
- package/src/publications/report-builder-reports.ts +47 -0
- package/src/publications/super-admin.ts +13 -0
- package/src/publications/user-groups.ts +12 -0
- package/src/publications/user-guides.ts +12 -0
- package/src/resolveio-server-app.ts +617 -0
- package/src/server-app.ts +3354 -0
- package/src/services/codex-client.ts +1231 -0
- package/src/services/openai-client.ts +265 -0
- package/src/types/error-report.ts +26 -0
- package/src/types/js-tiktoken.d.ts +11 -0
- package/src/types/slow-query-report.ts +28 -0
- package/src/util/ai-qa-policy.ts +925 -0
- package/src/util/ai-run-evidence-adapters.ts +8347 -0
- package/src/util/ai-run-evidence-dashboard.ts +323 -0
- package/src/util/ai-run-evidence-eval.ts +1057 -0
- package/src/util/ai-run-evidence.ts +1430 -0
- package/src/util/ai-runner-artifacts.ts +586 -0
- package/src/util/ai-runner-manager-autopilot.ts +961 -0
- package/src/util/ai-runner-manager-policy.ts +5011 -0
- package/src/util/ai-runner-qa-auth.ts +838 -0
- package/src/util/ai-runner-qa-tools.ts +3536 -0
- package/src/util/aicoder-runner-v6.ts +3121 -0
- package/src/util/common.ts +649 -0
- package/src/util/customer-portal-password.ts +183 -0
- package/src/util/error-reporter.ts +332 -0
- package/src/util/error-tracking.ts +79 -0
- package/src/util/openai-usage-cost.ts +114 -0
- package/src/util/report-builder-unwinds.ts +180 -0
- package/src/util/runner-process-janitor.ts +219 -0
- package/src/util/schema-report-builder.ts +448 -0
- package/src/util/slow-query-reporter.ts +216 -0
- package/src/util/subscription-dependency-context.ts +1096 -0
- package/src/util/support-runner-v5.ts +10040 -0
- package/src/util/tokenizer.ts +38 -0
- package/src/workers/codex-runner.worker.ts +142 -0
- package/start_server.sh +5 -0
- package/tests/ai-assistant-corpus-build.ts +484 -0
- package/tests/ai-assistant-corpus-replay-e2e.ts +774 -0
- package/tests/ai-assistant-data-parity-e2e.ts +1989 -0
- package/tests/ai-assistant-eval-triage.ts +831 -0
- package/tests/ai-assistant-openai-e2e.ts +1061 -0
- package/tests/ai-assistant-openai-git-e2e.ts +155 -0
- package/tests/ai-assistant-preflight-matrix.ts +215 -0
- package/tests/ai-assistant-routing-eval.test.ts +585 -0
- package/tests/ai-assistant-snf-live-eval.ts +975 -0
- package/tests/ai-assistant-utils.test.ts +4834 -0
- package/tests/ai-manager-autopilot-snapshot.test.ts +193 -0
- package/tests/ai-manager-recovery-checkpoint.test.ts +1383 -0
- package/tests/ai-run-eval.test.ts +132 -0
- package/tests/ai-run-evidence.test.ts +3773 -0
- package/tests/ai-runner-contract.test.ts +515 -0
- package/tests/aicoder-runner-v6.test.ts +822 -0
- package/tests/error-reporter.test.ts +145 -0
- package/tests/method-publication-generator.test.ts +46 -0
- package/tests/report-builder-linking.test.ts +79 -0
- package/tests/resolveio-platform-intelligence.test.ts +352 -0
- package/tests/server-app-cron-owner.test.ts +127 -0
- package/tests/subscription-connect-race.test.ts +158 -0
- package/tests/subscription-dependency-context.test.ts +324 -0
- package/tests/subscription-manager-collection-tracking.test.ts +86 -0
- package/tests/subscription-manager-invalidation.test.ts +86 -0
- package/tests/support-runner-v5.test.ts +3201 -0
- package/tsconfig.json +34 -0
- package/ai/assistant-core-heuristics.d.ts +0 -11
- package/ai/assistant-core-heuristics.js +0 -356
- package/ai/assistant-core-heuristics.js.map +0 -1
- package/ai/resolveio-platform-intelligence-memory-corpus.d.ts +0 -3
- package/ai/resolveio-platform-intelligence-memory-corpus.js +0 -214
- package/ai/resolveio-platform-intelligence-memory-corpus.js.map +0 -1
- package/ai/resolveio-platform-intelligence-memory.d.ts +0 -20
- package/ai/resolveio-platform-intelligence-memory.js +0 -341
- package/ai/resolveio-platform-intelligence-memory.js.map +0 -1
- package/ai/resolveio-platform-intelligence-types.js +0 -4
- package/ai/resolveio-platform-intelligence-types.js.map +0 -1
- package/ai/resolveio-platform-intelligence.d.ts +0 -6
- package/ai/resolveio-platform-intelligence.js +0 -463
- package/ai/resolveio-platform-intelligence.js.map +0 -1
- package/client-server-app.d.ts +0 -1
- package/client-server-app.js +0 -68
- package/client-server-app.js.map +0 -1
- package/collections/ai-run.collection.d.ts +0 -3
- package/collections/ai-run.collection.js +0 -170
- package/collections/ai-run.collection.js.map +0 -1
- package/collections/ai-terminal-conversation.collection.d.ts +0 -2
- package/collections/ai-terminal-conversation.collection.js +0 -140
- package/collections/ai-terminal-conversation.collection.js.map +0 -1
- package/collections/ai-terminal-issue-report.collection.d.ts +0 -2
- package/collections/ai-terminal-issue-report.collection.js +0 -148
- package/collections/ai-terminal-issue-report.collection.js.map +0 -1
- package/collections/ai-terminal-message.collection.d.ts +0 -2
- package/collections/ai-terminal-message.collection.js +0 -121
- package/collections/ai-terminal-message.collection.js.map +0 -1
- package/collections/app-setting.collection.d.ts +0 -3
- package/collections/app-setting.collection.js +0 -103
- package/collections/app-setting.collection.js.map +0 -1
- package/collections/app-status.collection.d.ts +0 -3
- package/collections/app-status.collection.js +0 -57
- package/collections/app-status.collection.js.map +0 -1
- package/collections/communication-metric.collection.d.ts +0 -2
- package/collections/communication-metric.collection.js +0 -133
- package/collections/communication-metric.collection.js.map +0 -1
- package/collections/counter.collection.d.ts +0 -3
- package/collections/counter.collection.js +0 -56
- package/collections/counter.collection.js.map +0 -1
- package/collections/cron-job-history.collection.d.ts +0 -3
- package/collections/cron-job-history.collection.js +0 -137
- package/collections/cron-job-history.collection.js.map +0 -1
- package/collections/cron-job.collection.d.ts +0 -3
- package/collections/cron-job.collection.js +0 -92
- package/collections/cron-job.collection.js.map +0 -1
- package/collections/customer-notification.collection.d.ts +0 -3
- package/collections/customer-notification.collection.js +0 -130
- package/collections/customer-notification.collection.js.map +0 -1
- package/collections/customer-portal-password.collection.d.ts +0 -3
- package/collections/customer-portal-password.collection.js +0 -75
- package/collections/customer-portal-password.collection.js.map +0 -1
- package/collections/email-history.collection.d.ts +0 -3
- package/collections/email-history.collection.js +0 -134
- package/collections/email-history.collection.js.map +0 -1
- package/collections/email-verified.collection.d.ts +0 -3
- package/collections/email-verified.collection.js +0 -62
- package/collections/email-verified.collection.js.map +0 -1
- package/collections/file.collection.d.ts +0 -3
- package/collections/file.collection.js +0 -74
- package/collections/file.collection.js.map +0 -1
- package/collections/flag-update.collection.d.ts +0 -3
- package/collections/flag-update.collection.js +0 -57
- package/collections/flag-update.collection.js.map +0 -1
- package/collections/flag.collection.d.ts +0 -3
- package/collections/flag.collection.js +0 -57
- package/collections/flag.collection.js.map +0 -1
- package/collections/log-method-latency.collection.d.ts +0 -3
- package/collections/log-method-latency.collection.js +0 -77
- package/collections/log-method-latency.collection.js.map +0 -1
- package/collections/log-subscription.collection.d.ts +0 -3
- package/collections/log-subscription.collection.js +0 -80
- package/collections/log-subscription.collection.js.map +0 -1
- package/collections/log.collection.d.ts +0 -3
- package/collections/log.collection.js +0 -93
- package/collections/log.collection.js.map +0 -1
- package/collections/logged-in-users.collection.d.ts +0 -3
- package/collections/logged-in-users.collection.js +0 -67
- package/collections/logged-in-users.collection.js.map +0 -1
- package/collections/monitor-cpu.collection.d.ts +0 -3
- package/collections/monitor-cpu.collection.js +0 -65
- package/collections/monitor-cpu.collection.js.map +0 -1
- package/collections/monitor-function.collection.d.ts +0 -3
- package/collections/monitor-function.collection.js +0 -74
- package/collections/monitor-function.collection.js.map +0 -1
- package/collections/monitor-memory.collection.d.ts +0 -3
- package/collections/monitor-memory.collection.js +0 -77
- package/collections/monitor-memory.collection.js.map +0 -1
- package/collections/monitor-mongo.collection.d.ts +0 -3
- package/collections/monitor-mongo.collection.js +0 -71
- package/collections/monitor-mongo.collection.js.map +0 -1
- package/collections/notification.collection.d.ts +0 -3
- package/collections/notification.collection.js +0 -57
- package/collections/notification.collection.js.map +0 -1
- package/collections/openai-usage-ledger.collection.d.ts +0 -2
- package/collections/openai-usage-ledger.collection.js +0 -188
- package/collections/openai-usage-ledger.collection.js.map +0 -1
- package/collections/report-builder-dashboard-builder.collection.d.ts +0 -3
- package/collections/report-builder-dashboard-builder.collection.js +0 -109
- package/collections/report-builder-dashboard-builder.collection.js.map +0 -1
- package/collections/report-builder-library.collection.d.ts +0 -3
- package/collections/report-builder-library.collection.js +0 -87
- package/collections/report-builder-library.collection.js.map +0 -1
- package/collections/report-builder-report.collection.d.ts +0 -4
- package/collections/report-builder-report.collection.js +0 -184
- package/collections/report-builder-report.collection.js.map +0 -1
- package/collections/user-group.collection.d.ts +0 -4
- package/collections/user-group.collection.js +0 -89
- package/collections/user-group.collection.js.map +0 -1
- package/collections/user-guide.collection.d.ts +0 -3
- package/collections/user-guide.collection.js +0 -57
- package/collections/user-guide.collection.js.map +0 -1
- package/collections/user.collection.d.ts +0 -4
- package/collections/user.collection.js +0 -180
- package/collections/user.collection.js.map +0 -1
- package/cron/cron.d.ts +0 -14
- package/cron/cron.js +0 -216
- package/cron/cron.js.map +0 -1
- package/fixtures/cron-jobs.d.ts +0 -1
- package/fixtures/cron-jobs.js +0 -150
- package/fixtures/cron-jobs.js.map +0 -1
- package/fixtures/init.d.ts +0 -1
- package/fixtures/init.js +0 -91
- package/fixtures/init.js.map +0 -1
- package/http/auth.d.ts +0 -2
- package/http/auth.js +0 -951
- package/http/auth.js.map +0 -1
- package/http/health.d.ts +0 -1
- package/http/health.js +0 -11
- package/http/health.js.map +0 -1
- package/http/home.d.ts +0 -1
- package/http/home.js +0 -134
- package/http/home.js.map +0 -1
- package/http/slow-query-publication.d.ts +0 -2
- package/http/slow-query-publication.js +0 -99
- package/http/slow-query-publication.js.map +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -19
- package/index.js.map +0 -1
- package/managers/ai-assistant-codex-manager.manager.d.ts +0 -67
- package/managers/ai-assistant-codex-manager.manager.js +0 -1113
- package/managers/ai-assistant-codex-manager.manager.js.map +0 -1
- package/managers/ai-run-evidence.manager.d.ts +0 -36
- package/managers/ai-run-evidence.manager.js +0 -377
- package/managers/ai-run-evidence.manager.js.map +0 -1
- package/managers/communication-metric.manager.d.ts +0 -16
- package/managers/communication-metric.manager.js +0 -134
- package/managers/communication-metric.manager.js.map +0 -1
- package/managers/cron.manager.d.ts +0 -20
- package/managers/cron.manager.js +0 -534
- package/managers/cron.manager.js.map +0 -1
- package/managers/customer-notification-content.manager.d.ts +0 -55
- package/managers/customer-notification-content.manager.js +0 -158
- package/managers/customer-notification-content.manager.js.map +0 -1
- package/managers/diagnostic-manager-bootstrap.d.ts +0 -9
- package/managers/diagnostic-manager-bootstrap.js +0 -260
- package/managers/diagnostic-manager-bootstrap.js.map +0 -1
- package/managers/error-auto-fix.manager.d.ts +0 -149
- package/managers/error-auto-fix.manager.js +0 -3064
- package/managers/error-auto-fix.manager.js.map +0 -1
- package/managers/local-log.manager.d.ts +0 -18
- package/managers/local-log.manager.js +0 -88
- package/managers/local-log.manager.js.map +0 -1
- package/managers/method.manager.d.ts +0 -84
- package/managers/method.manager.js +0 -1964
- package/managers/method.manager.js.map +0 -1
- package/managers/mongo.manager.d.ts +0 -224
- package/managers/mongo.manager.js +0 -5000
- package/managers/mongo.manager.js.map +0 -1
- package/managers/monitor.manager.d.ts +0 -70
- package/managers/monitor.manager.js +0 -550
- package/managers/monitor.manager.js.map +0 -1
- package/managers/openai-usage-ledger.manager.d.ts +0 -30
- package/managers/openai-usage-ledger.manager.js +0 -142
- package/managers/openai-usage-ledger.manager.js.map +0 -1
- package/managers/slow-query-verifier.manager.d.ts +0 -144
- package/managers/slow-query-verifier.manager.js +0 -3857
- package/managers/slow-query-verifier.manager.js.map +0 -1
- package/managers/slow-query.manager.d.ts +0 -28
- package/managers/slow-query.manager.js +0 -468
- package/managers/slow-query.manager.js.map +0 -1
- package/managers/subscription.manager.d.ts +0 -169
- package/managers/subscription.manager.js +0 -3434
- package/managers/subscription.manager.js.map +0 -1
- package/managers/websocket.manager.d.ts +0 -73
- package/managers/websocket.manager.js +0 -673
- package/managers/websocket.manager.js.map +0 -1
- package/managers/worker-dispatcher.manager.d.ts +0 -120
- package/managers/worker-dispatcher.manager.js +0 -1266
- package/managers/worker-dispatcher.manager.js.map +0 -1
- package/managers/worker-server.manager.d.ts +0 -35
- package/managers/worker-server.manager.js +0 -582
- package/managers/worker-server.manager.js.map +0 -1
- package/methods/accounts.d.ts +0 -2
- package/methods/accounts.js +0 -624
- package/methods/accounts.js.map +0 -1
- package/methods/ai-terminal.d.ts +0 -458
- package/methods/ai-terminal.js +0 -27991
- package/methods/ai-terminal.js.map +0 -1
- package/methods/app-settings.d.ts +0 -2
- package/methods/app-settings.js +0 -169
- package/methods/app-settings.js.map +0 -1
- package/methods/aws.d.ts +0 -2
- package/methods/aws.js +0 -877
- package/methods/aws.js.map +0 -1
- package/methods/collections.d.ts +0 -2
- package/methods/collections.js +0 -719
- package/methods/collections.js.map +0 -1
- package/methods/counters.d.ts +0 -2
- package/methods/counters.js +0 -113
- package/methods/counters.js.map +0 -1
- package/methods/cron-jobs.d.ts +0 -2
- package/methods/cron-jobs.js +0 -2475
- package/methods/cron-jobs.js.map +0 -1
- package/methods/customer-notifications.d.ts +0 -2
- package/methods/customer-notifications.js +0 -528
- package/methods/customer-notifications.js.map +0 -1
- package/methods/diagnostics.d.ts +0 -2
- package/methods/diagnostics.js +0 -703
- package/methods/diagnostics.js.map +0 -1
- package/methods/flag-updates.d.ts +0 -2
- package/methods/flag-updates.js +0 -8
- package/methods/flag-updates.js.map +0 -1
- package/methods/flags.d.ts +0 -2
- package/methods/flags.js +0 -8
- package/methods/flags.js.map +0 -1
- package/methods/logs.d.ts +0 -2
- package/methods/logs.js +0 -751
- package/methods/logs.js.map +0 -1
- package/methods/mongo-explorer.d.ts +0 -2
- package/methods/mongo-explorer.js +0 -1808
- package/methods/mongo-explorer.js.map +0 -1
- package/methods/monitor.d.ts +0 -2
- package/methods/monitor.js +0 -543
- package/methods/monitor.js.map +0 -1
- package/methods/pdf.d.ts +0 -2
- package/methods/pdf.js +0 -1216
- package/methods/pdf.js.map +0 -1
- package/methods/publications.d.ts +0 -1
- package/methods/publications.js +0 -183
- package/methods/publications.js.map +0 -1
- package/methods/report-builder.d.ts +0 -2
- package/methods/report-builder.js +0 -3094
- package/methods/report-builder.js.map +0 -1
- package/methods/support.d.ts +0 -2
- package/methods/support.js +0 -430
- package/methods/support.js.map +0 -1
- package/models/ai-run.model.d.ts +0 -19
- package/models/ai-run.model.js +0 -4
- package/models/ai-run.model.js.map +0 -1
- package/models/ai-terminal-conversation.model.d.ts +0 -17
- package/models/ai-terminal-conversation.model.js +0 -4
- package/models/ai-terminal-conversation.model.js.map +0 -1
- package/models/ai-terminal-issue-report.model.d.ts +0 -19
- package/models/ai-terminal-issue-report.model.js +0 -4
- package/models/ai-terminal-issue-report.model.js.map +0 -1
- package/models/ai-terminal-message.model.d.ts +0 -22
- package/models/ai-terminal-message.model.js +0 -4
- package/models/ai-terminal-message.model.js.map +0 -1
- package/models/app-setting.model.d.ts +0 -16
- package/models/app-setting.model.js +0 -4
- package/models/app-setting.model.js.map +0 -1
- package/models/app-status.model.js +0 -4
- package/models/app-status.model.js.map +0 -1
- package/models/billing-logged-in-users.model.js +0 -4
- package/models/billing-logged-in-users.model.js.map +0 -1
- package/models/collection-document.model.d.ts +0 -21
- package/models/collection-document.model.js +0 -4
- package/models/collection-document.model.js.map +0 -1
- package/models/communication-metric.model.d.ts +0 -20
- package/models/communication-metric.model.js +0 -4
- package/models/communication-metric.model.js.map +0 -1
- package/models/counter.model.js +0 -4
- package/models/counter.model.js.map +0 -1
- package/models/cron-job-history.model.d.ts +0 -15
- package/models/cron-job-history.model.js +0 -4
- package/models/cron-job-history.model.js.map +0 -1
- package/models/cron-job.model.d.ts +0 -14
- package/models/cron-job.model.js +0 -4
- package/models/cron-job.model.js.map +0 -1
- package/models/customer-notification.model.d.ts +0 -26
- package/models/customer-notification.model.js +0 -4
- package/models/customer-notification.model.js.map +0 -1
- package/models/customer-portal-password.model.d.ts +0 -11
- package/models/customer-portal-password.model.js +0 -4
- package/models/customer-portal-password.model.js.map +0 -1
- package/models/dialog.model.d.ts +0 -23
- package/models/dialog.model.js +0 -4
- package/models/dialog.model.js.map +0 -1
- package/models/email-history.model.d.ts +0 -32
- package/models/email-history.model.js.map +0 -1
- package/models/email-verified.model.js +0 -4
- package/models/email-verified.model.js.map +0 -1
- package/models/file.model.js +0 -4
- package/models/file.model.js.map +0 -1
- package/models/flag-update.model.js +0 -4
- package/models/flag-update.model.js.map +0 -1
- package/models/flag.model.js +0 -4
- package/models/flag.model.js.map +0 -1
- package/models/log-method-latency.model.d.ts +0 -10
- package/models/log-method-latency.model.js +0 -4
- package/models/log-method-latency.model.js.map +0 -1
- package/models/log-subscription.model.js +0 -4
- package/models/log-subscription.model.js.map +0 -1
- package/models/log.model.d.ts +0 -17
- package/models/log.model.js +0 -4
- package/models/log.model.js.map +0 -1
- package/models/logged-in-users.model.js +0 -4
- package/models/logged-in-users.model.js.map +0 -1
- package/models/method-response.model.js +0 -4
- package/models/method-response.model.js.map +0 -1
- package/models/method.model.d.ts +0 -26
- package/models/method.model.js +0 -4
- package/models/method.model.js.map +0 -1
- package/models/monitor-cpu.model.js +0 -4
- package/models/monitor-cpu.model.js.map +0 -1
- package/models/monitor-function.model.d.ts +0 -14
- package/models/monitor-function.model.js +0 -4
- package/models/monitor-function.model.js.map +0 -1
- package/models/monitor-memory.model.d.ts +0 -15
- package/models/monitor-memory.model.js +0 -4
- package/models/monitor-memory.model.js.map +0 -1
- package/models/monitor-mongo.model.d.ts +0 -13
- package/models/monitor-mongo.model.js +0 -4
- package/models/monitor-mongo.model.js.map +0 -1
- package/models/notification.model.js +0 -4
- package/models/notification.model.js.map +0 -1
- package/models/openai-usage-ledger.model.d.ts +0 -30
- package/models/openai-usage-ledger.model.js +0 -4
- package/models/openai-usage-ledger.model.js.map +0 -1
- package/models/pagination.model.d.ts +0 -11
- package/models/pagination.model.js +0 -28
- package/models/pagination.model.js.map +0 -1
- package/models/permission.model.d.ts +0 -12
- package/models/permission.model.js +0 -4
- package/models/permission.model.js.map +0 -1
- package/models/report-builder-dashboard-builder.model.d.ts +0 -25
- package/models/report-builder-dashboard-builder.model.js +0 -4
- package/models/report-builder-dashboard-builder.model.js.map +0 -1
- package/models/report-builder-library.model.d.ts +0 -17
- package/models/report-builder-library.model.js +0 -4
- package/models/report-builder-library.model.js.map +0 -1
- package/models/report-builder-report.model.d.ts +0 -121
- package/models/report-builder-report.model.js +0 -4
- package/models/report-builder-report.model.js.map +0 -1
- package/models/report-builder.model.d.ts +0 -61
- package/models/report-builder.model.js +0 -4
- package/models/report-builder.model.js.map +0 -1
- package/models/select-data-label.model.d.ts +0 -9
- package/models/select-data-label.model.js +0 -4
- package/models/select-data-label.model.js.map +0 -1
- package/models/server-message.model.d.ts +0 -32
- package/models/server-message.model.js +0 -4
- package/models/server-message.model.js.map +0 -1
- package/models/slow-query-report.model.d.ts +0 -23
- package/models/slow-query-report.model.js +0 -4
- package/models/slow-query-report.model.js.map +0 -1
- package/models/subscription.model.d.ts +0 -31
- package/models/subscription.model.js +0 -4
- package/models/subscription.model.js.map +0 -1
- package/models/support-ticket.model.d.ts +0 -87
- package/models/support-ticket.model.js +0 -4
- package/models/support-ticket.model.js.map +0 -1
- package/models/user-group.model.d.ts +0 -20
- package/models/user-group.model.js +0 -4
- package/models/user-group.model.js.map +0 -1
- package/models/user-guide.model.js +0 -4
- package/models/user-guide.model.js.map +0 -1
- package/models/user.model.d.ts +0 -84
- package/models/user.model.js +0 -4
- package/models/user.model.js.map +0 -1
- package/private/images/ResolveIO.png +0 -0
- package/public_api.js +0 -127
- package/public_api.js.map +0 -1
- package/publications/ai-terminal.d.ts +0 -1
- package/publications/ai-terminal.js +0 -122
- package/publications/ai-terminal.js.map +0 -1
- package/publications/app-settings.d.ts +0 -2
- package/publications/app-settings.js +0 -28
- package/publications/app-settings.js.map +0 -1
- package/publications/app-status.d.ts +0 -2
- package/publications/app-status.js +0 -16
- package/publications/app-status.js.map +0 -1
- package/publications/cron-jobs.d.ts +0 -2
- package/publications/cron-jobs.js +0 -88
- package/publications/cron-jobs.js.map +0 -1
- package/publications/customer-notifications.d.ts +0 -2
- package/publications/customer-notifications.js +0 -161
- package/publications/customer-notifications.js.map +0 -1
- package/publications/files.d.ts +0 -2
- package/publications/files.js +0 -36
- package/publications/files.js.map +0 -1
- package/publications/flags-update.d.ts +0 -2
- package/publications/flags-update.js +0 -22
- package/publications/flags-update.js.map +0 -1
- package/publications/flags.d.ts +0 -2
- package/publications/flags.js +0 -22
- package/publications/flags.js.map +0 -1
- package/publications/logs.d.ts +0 -2
- package/publications/logs.js +0 -164
- package/publications/logs.js.map +0 -1
- package/publications/notifications.d.ts +0 -2
- package/publications/notifications.js +0 -16
- package/publications/notifications.js.map +0 -1
- package/publications/report-builder-dashboard-builders.d.ts +0 -2
- package/publications/report-builder-dashboard-builders.js +0 -42
- package/publications/report-builder-dashboard-builders.js.map +0 -1
- package/publications/report-builder-libraries.d.ts +0 -2
- package/publications/report-builder-libraries.js +0 -90
- package/publications/report-builder-libraries.js.map +0 -1
- package/publications/report-builder-reports.d.ts +0 -2
- package/publications/report-builder-reports.js +0 -50
- package/publications/report-builder-reports.js.map +0 -1
- package/publications/super-admin.d.ts +0 -2
- package/publications/super-admin.js +0 -16
- package/publications/super-admin.js.map +0 -1
- package/publications/user-groups.d.ts +0 -1
- package/publications/user-groups.js +0 -16
- package/publications/user-groups.js.map +0 -1
- package/publications/user-guides.d.ts +0 -1
- package/publications/user-guides.js +0 -16
- package/publications/user-guides.js.map +0 -1
- package/resolveio-server-app.d.ts +0 -70
- package/resolveio-server-app.js +0 -801
- package/resolveio-server-app.js.map +0 -1
- package/server-app.d.ts +0 -228
- package/server-app.js +0 -3566
- package/server-app.js.map +0 -1
- package/services/codex-client.d.ts +0 -128
- package/services/codex-client.js +0 -1629
- package/services/codex-client.js.map +0 -1
- package/services/openai-client.d.ts +0 -46
- package/services/openai-client.js +0 -318
- package/services/openai-client.js.map +0 -1
- package/types/error-report.d.ts +0 -25
- package/types/error-report.js +0 -4
- package/types/error-report.js.map +0 -1
- package/types/slow-query-report.d.ts +0 -27
- package/types/slow-query-report.js +0 -6
- package/types/slow-query-report.js.map +0 -1
- package/util/ai-qa-policy.d.ts +0 -124
- package/util/ai-qa-policy.js +0 -736
- package/util/ai-qa-policy.js.map +0 -1
- package/util/ai-run-evidence-adapters.d.ts +0 -109
- package/util/ai-run-evidence-adapters.js +0 -7234
- package/util/ai-run-evidence-adapters.js.map +0 -1
- package/util/ai-run-evidence-dashboard.d.ts +0 -88
- package/util/ai-run-evidence-dashboard.js +0 -343
- package/util/ai-run-evidence-dashboard.js.map +0 -1
- package/util/ai-run-evidence-eval.d.ts +0 -86
- package/util/ai-run-evidence-eval.js +0 -1018
- package/util/ai-run-evidence-eval.js.map +0 -1
- package/util/ai-run-evidence.d.ts +0 -244
- package/util/ai-run-evidence.js +0 -1096
- package/util/ai-run-evidence.js.map +0 -1
- package/util/ai-runner-artifacts.d.ts +0 -82
- package/util/ai-runner-artifacts.js +0 -713
- package/util/ai-runner-artifacts.js.map +0 -1
- package/util/ai-runner-manager-autopilot.d.ts +0 -210
- package/util/ai-runner-manager-autopilot.js +0 -642
- package/util/ai-runner-manager-autopilot.js.map +0 -1
- package/util/ai-runner-manager-policy.d.ts +0 -807
- package/util/ai-runner-manager-policy.js +0 -3501
- package/util/ai-runner-manager-policy.js.map +0 -1
- package/util/ai-runner-qa-auth.d.ts +0 -5
- package/util/ai-runner-qa-auth.js +0 -839
- package/util/ai-runner-qa-auth.js.map +0 -1
- package/util/ai-runner-qa-tools.d.ts +0 -26
- package/util/ai-runner-qa-tools.js +0 -3520
- package/util/ai-runner-qa-tools.js.map +0 -1
- package/util/aicoder-runner-v6.d.ts +0 -426
- package/util/aicoder-runner-v6.js +0 -2464
- package/util/aicoder-runner-v6.js.map +0 -1
- package/util/common.d.ts +0 -31
- package/util/common.js +0 -683
- package/util/common.js.map +0 -1
- package/util/customer-portal-password.d.ts +0 -13
- package/util/customer-portal-password.js +0 -209
- package/util/customer-portal-password.js.map +0 -1
- package/util/error-reporter.d.ts +0 -52
- package/util/error-reporter.js +0 -326
- package/util/error-reporter.js.map +0 -1
- package/util/error-tracking.d.ts +0 -13
- package/util/error-tracking.js +0 -120
- package/util/error-tracking.js.map +0 -1
- package/util/openai-usage-cost.d.ts +0 -6
- package/util/openai-usage-cost.js +0 -103
- package/util/openai-usage-cost.js.map +0 -1
- package/util/report-builder-unwinds.d.ts +0 -15
- package/util/report-builder-unwinds.js +0 -156
- package/util/report-builder-unwinds.js.map +0 -1
- package/util/runner-process-janitor.d.ts +0 -27
- package/util/runner-process-janitor.js +0 -208
- package/util/runner-process-janitor.js.map +0 -1
- package/util/schema-report-builder.d.ts +0 -6
- package/util/schema-report-builder.js +0 -481
- package/util/schema-report-builder.js.map +0 -1
- package/util/slow-query-reporter.d.ts +0 -28
- package/util/slow-query-reporter.js +0 -226
- package/util/slow-query-reporter.js.map +0 -1
- package/util/subscription-dependency-context.d.ts +0 -34
- package/util/subscription-dependency-context.js +0 -1283
- package/util/subscription-dependency-context.js.map +0 -1
- package/util/support-runner-v5.d.ts +0 -1426
- package/util/support-runner-v5.js +0 -7624
- package/util/support-runner-v5.js.map +0 -1
- package/util/tokenizer.d.ts +0 -5
- package/util/tokenizer.js +0 -41
- package/util/tokenizer.js.map +0 -1
- package/workers/codex-runner.worker.d.ts +0 -1
- package/workers/codex-runner.worker.js +0 -192
- package/workers/codex-runner.worker.js.map +0 -1
- /package/{private → src/private}/email-templates/enrollment.html +0 -0
- /package/{private → src/private}/email-templates/forgot-password.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-deleted.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-modified.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket.html +0 -0
- /package/{public_api.d.ts → src/public_api.ts} +0 -0
package/server-app.js
DELETED
|
@@ -1,3566 +0,0 @@
|
|
|
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.ResolveIOMainServer = void 0;
|
|
87
|
-
var express = require("express");
|
|
88
|
-
var xmlParser = require("express-xml-bodyparser");
|
|
89
|
-
var http_1 = require("http");
|
|
90
|
-
var crypto = require("crypto");
|
|
91
|
-
var fs = require("fs");
|
|
92
|
-
var jwt = require("jsonwebtoken");
|
|
93
|
-
var moment = require("moment-timezone");
|
|
94
|
-
var msgpackr_1 = require("msgpackr");
|
|
95
|
-
var os = require("os");
|
|
96
|
-
var path = require("path");
|
|
97
|
-
var perf_hooks_1 = require("perf_hooks");
|
|
98
|
-
var inspector = require("inspector");
|
|
99
|
-
var child_process_1 = require("child_process");
|
|
100
|
-
var url_1 = require("url");
|
|
101
|
-
var WebSocket = require("ws");
|
|
102
|
-
var log_collection_1 = require("./collections/log.collection");
|
|
103
|
-
var user_collection_1 = require("./collections/user.collection");
|
|
104
|
-
var cron_manager_1 = require("./managers/cron.manager");
|
|
105
|
-
var method_manager_1 = require("./managers/method.manager");
|
|
106
|
-
var monitor_manager_1 = require("./managers/monitor.manager");
|
|
107
|
-
var subscription_manager_1 = require("./managers/subscription.manager");
|
|
108
|
-
var common_1 = require("./util/common");
|
|
109
|
-
var error_reporter_1 = require("./util/error-reporter");
|
|
110
|
-
var error_tracking_1 = require("./util/error-tracking");
|
|
111
|
-
var mongodb_1 = require("mongodb");
|
|
112
|
-
var auth_1 = require("./http/auth");
|
|
113
|
-
var health_1 = require("./http/health");
|
|
114
|
-
var home_1 = require("./http/home");
|
|
115
|
-
var slow_query_publication_1 = require("./http/slow-query-publication");
|
|
116
|
-
var websocket_manager_1 = require("./managers/websocket.manager");
|
|
117
|
-
var worker_dispatcher_manager_1 = require("./managers/worker-dispatcher.manager");
|
|
118
|
-
var worker_server_manager_1 = require("./managers/worker-server.manager");
|
|
119
|
-
var ai_assistant_codex_manager_manager_1 = require("./managers/ai-assistant-codex-manager.manager");
|
|
120
|
-
var resolveio_server_app_1 = require("./resolveio-server-app");
|
|
121
|
-
var CLIENT_REQUEST_LOG_SKIP_LIST = new Set([
|
|
122
|
-
'reportBuilderGetResults',
|
|
123
|
-
'reportBuilderGetDistinctValue',
|
|
124
|
-
'reportBuilderBuildTree',
|
|
125
|
-
'generatePDF',
|
|
126
|
-
'getWOOfflineData',
|
|
127
|
-
'countQuery',
|
|
128
|
-
'countWithQuery',
|
|
129
|
-
'countCollectionWithQuery',
|
|
130
|
-
'find',
|
|
131
|
-
'findOne',
|
|
132
|
-
'findWithOptions',
|
|
133
|
-
'getDrivers',
|
|
134
|
-
'processAirdropDistribution',
|
|
135
|
-
'qbHandleResponse',
|
|
136
|
-
'getSignedUrls',
|
|
137
|
-
'getSignedUrl',
|
|
138
|
-
'getSignedUrlWithId',
|
|
139
|
-
'getSignedUrlsAndFilesWithId',
|
|
140
|
-
'updateDocumentProps',
|
|
141
|
-
'insertDocument',
|
|
142
|
-
'updateDocument',
|
|
143
|
-
'uploadFileAndSave'
|
|
144
|
-
]);
|
|
145
|
-
function isCorsPreflightRequest(req) {
|
|
146
|
-
return req.method === 'OPTIONS' && !!req.headers.origin && !!req.headers['access-control-request-method'];
|
|
147
|
-
}
|
|
148
|
-
function shouldWriteClientRequestLog(methodName) {
|
|
149
|
-
return !CLIENT_REQUEST_LOG_SKIP_LIST.has(methodName);
|
|
150
|
-
}
|
|
151
|
-
var ResolveIOMainServer = /** @class */ (function () {
|
|
152
|
-
function ResolveIOMainServer() {
|
|
153
|
-
this._offlineUpdates = [];
|
|
154
|
-
this.sesMail = false;
|
|
155
|
-
this.publicProgram = false;
|
|
156
|
-
this._rebootFlag = false;
|
|
157
|
-
this.LOGGER = 'ERROR'; //ERROR / DEBUG
|
|
158
|
-
this._clientRoutes = [];
|
|
159
|
-
this._aiAssistantCodexManager = null;
|
|
160
|
-
this._httpServerClosePromise = null;
|
|
161
|
-
this._websocketServerClosePromise = null;
|
|
162
|
-
this._wsConnectDebug = false;
|
|
163
|
-
this._perfDebug = false;
|
|
164
|
-
this._perfDebugIntervalMs = 2000;
|
|
165
|
-
this._perfDebugTimer = null;
|
|
166
|
-
this._perfDebugLastCpu = null;
|
|
167
|
-
this._perfDebugLastTs = 0;
|
|
168
|
-
this._eventLoopHistogram = null;
|
|
169
|
-
this._cpuProfileOnStart = false;
|
|
170
|
-
this._cpuProfileAuto = false;
|
|
171
|
-
this._cpuProfileDurationMs = 15000;
|
|
172
|
-
this._cpuProfileThresholdPct = 90;
|
|
173
|
-
this._cpuProfileTriggerCount = 3;
|
|
174
|
-
this._cpuProfileHighCount = 0;
|
|
175
|
-
this._cpuProfileDir = null;
|
|
176
|
-
this._cpuProfileSession = null;
|
|
177
|
-
this._timerDebug = false;
|
|
178
|
-
this._timerDebugThresholdMs = 50;
|
|
179
|
-
this._timerDebugMinDelayMs = 5;
|
|
180
|
-
this._timerDebugSampleRate = 1;
|
|
181
|
-
this._timerDebugLogLimit = 100;
|
|
182
|
-
this._timerDebugLogCount = 0;
|
|
183
|
-
this._aiWorkerDebug = false;
|
|
184
|
-
this._standaloneNodeReaperEnabled = false;
|
|
185
|
-
this._standaloneNodeReaperIntervalMs = 60000;
|
|
186
|
-
this._standaloneNodeReaperMinAgeSeconds = 300;
|
|
187
|
-
this._standaloneNodeReaperMaxKillsPerSignature = 1;
|
|
188
|
-
this._standaloneNodeReaperKillWindowMs = 60 * 60 * 1000;
|
|
189
|
-
this._standaloneNodeReaperIncludeSystemdServices = false;
|
|
190
|
-
this._standaloneNodeReaperHighCpuPct = 85;
|
|
191
|
-
this._standaloneNodeReaperHighRssMb = 4096;
|
|
192
|
-
this._standaloneNodeReaperHighMinAgeSeconds = 60;
|
|
193
|
-
this._standaloneNodeReaperHighConsecutiveScans = 2;
|
|
194
|
-
this._standaloneNodeReaperDryRun = false;
|
|
195
|
-
this._standaloneNodeReaperAlertWindowMs = 60 * 60 * 1000;
|
|
196
|
-
this._standaloneNodeReaperTimer = null;
|
|
197
|
-
this._standaloneNodeReaperRunning = false;
|
|
198
|
-
this._standaloneNodeReaperKillCounts = new Map();
|
|
199
|
-
this._standaloneNodeReaperSuppressedSignatures = new Set();
|
|
200
|
-
this._standaloneNodeReaperResourceHits = new Map();
|
|
201
|
-
this._standaloneNodeReaperAlertTimes = new Map();
|
|
202
|
-
this._lastErrorMsg = null;
|
|
203
|
-
this._debugMsgRecv = 0;
|
|
204
|
-
this._debugMsgQueue = 0;
|
|
205
|
-
this._isWorkersEnabled = false;
|
|
206
|
-
this._isWorkerInstance = false;
|
|
207
|
-
this._safeShutdown = false;
|
|
208
|
-
this._dynamicAppGatewayEnabled = false;
|
|
209
|
-
this._dynamicAppGatewayCache = new Map();
|
|
210
|
-
this._socketTier = '';
|
|
211
|
-
this._maxClientSockets = 0;
|
|
212
|
-
this._singleIpPerUser = false;
|
|
213
|
-
this._socketPolicyUpgradeUrl = '';
|
|
214
|
-
this._clientHeartbeatIntervalMs = 20000;
|
|
215
|
-
this._clientHeartbeatInitialDelayMs = 5000;
|
|
216
|
-
this._clientHeartbeatBackpressureBytes = 5 * 1024 * 1024;
|
|
217
|
-
this._dynamicAppGatewayCacheMs = 30 * 1000;
|
|
218
|
-
}
|
|
219
|
-
ResolveIOMainServer.create = function () {
|
|
220
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
-
var resolveioMainServer;
|
|
222
|
-
return __generator(this, function (_a) {
|
|
223
|
-
switch (_a.label) {
|
|
224
|
-
case 0:
|
|
225
|
-
resolveioMainServer = new ResolveIOMainServer();
|
|
226
|
-
return [4 /*yield*/, resolveioMainServer.initialize()];
|
|
227
|
-
case 1:
|
|
228
|
-
_a.sent();
|
|
229
|
-
return [2 /*return*/, resolveioMainServer];
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
};
|
|
234
|
-
ResolveIOMainServer.prototype.initialize = function () {
|
|
235
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
236
|
-
var _a, workerRole, workerIndex, workerInstance, skipWorkerServerConnection, skipCronForProcessOnly;
|
|
237
|
-
var _this = this;
|
|
238
|
-
return __generator(this, function (_b) {
|
|
239
|
-
switch (_b.label) {
|
|
240
|
-
case 0:
|
|
241
|
-
this._serverStartTime = new Date();
|
|
242
|
-
this._lastErrorMsg = null;
|
|
243
|
-
this._wsConnectDebug = this.resolveConnectDebug();
|
|
244
|
-
this._perfDebug = this.resolvePerfDebug();
|
|
245
|
-
this._cpuProfileOnStart = this.resolveCpuProfileOnStart();
|
|
246
|
-
this._cpuProfileAuto = this.resolveCpuProfileAuto();
|
|
247
|
-
this._cpuProfileDurationMs = this.resolveCpuProfileDurationMs();
|
|
248
|
-
this._cpuProfileThresholdPct = this.resolveCpuProfileThresholdPct();
|
|
249
|
-
this._cpuProfileTriggerCount = this.resolveCpuProfileTriggerCount();
|
|
250
|
-
this._cpuProfileDir = this.resolveCpuProfileDir();
|
|
251
|
-
this._timerDebug = this.resolveTimerDebug();
|
|
252
|
-
this._timerDebugThresholdMs = this.resolveTimerDebugThresholdMs();
|
|
253
|
-
this._timerDebugMinDelayMs = this.resolveTimerDebugMinDelayMs();
|
|
254
|
-
this._timerDebugSampleRate = this.resolveTimerDebugSampleRate();
|
|
255
|
-
this._timerDebugLogLimit = this.resolveTimerDebugLogLimit();
|
|
256
|
-
this._aiWorkerDebug = this.parseDebugFlag(process.env.AI_ASSISTANT_WORKER_DEBUG);
|
|
257
|
-
this._standaloneNodeReaperEnabled = this.resolveStandaloneNodeReaperEnabled();
|
|
258
|
-
this._standaloneNodeReaperIntervalMs = this.resolveStandaloneNodeReaperIntervalMs();
|
|
259
|
-
this._standaloneNodeReaperMinAgeSeconds = this.resolveStandaloneNodeReaperMinAgeSeconds();
|
|
260
|
-
this._standaloneNodeReaperMaxKillsPerSignature = this.resolveStandaloneNodeReaperMaxKillsPerSignature();
|
|
261
|
-
this._standaloneNodeReaperKillWindowMs = this.resolveStandaloneNodeReaperKillWindowMs();
|
|
262
|
-
this._standaloneNodeReaperIncludeSystemdServices = this.resolveStandaloneNodeReaperIncludeSystemdServices();
|
|
263
|
-
this._standaloneNodeReaperHighCpuPct = this.resolveStandaloneNodeReaperHighCpuPct();
|
|
264
|
-
this._standaloneNodeReaperHighRssMb = this.resolveStandaloneNodeReaperHighRssMb();
|
|
265
|
-
this._standaloneNodeReaperHighMinAgeSeconds = this.resolveStandaloneNodeReaperHighMinAgeSeconds();
|
|
266
|
-
this._standaloneNodeReaperHighConsecutiveScans = this.resolveStandaloneNodeReaperHighConsecutiveScans();
|
|
267
|
-
this._standaloneNodeReaperDryRun = this.resolveStandaloneNodeReaperDryRun();
|
|
268
|
-
this._standaloneNodeReaperAlertWindowMs = this.resolveStandaloneNodeReaperAlertWindowMs();
|
|
269
|
-
this._dynamicAppGatewayEnabled = this.resolveDynamicAppGatewayEnabled();
|
|
270
|
-
this._socketTier = this.resolveSocketTier();
|
|
271
|
-
this._maxClientSockets = this.resolveMaxClientSockets(this._socketTier);
|
|
272
|
-
this._singleIpPerUser = this.resolveSingleIpPerUserPolicy(this._socketTier);
|
|
273
|
-
this._socketPolicyUpgradeUrl = this.resolveSocketPolicyUpgradeUrl();
|
|
274
|
-
if (this._maxClientSockets > 0 || this._singleIpPerUser) {
|
|
275
|
-
console.info(new Date(), '[Socket Policy] configured', {
|
|
276
|
-
tier: this._socketTier || 'none',
|
|
277
|
-
maxClientSockets: this._maxClientSockets,
|
|
278
|
-
singleIpPerUser: this._singleIpPerUser
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
_a = this;
|
|
282
|
-
return [4 /*yield*/, monitor_manager_1.MonitorManager.create()];
|
|
283
|
-
case 1:
|
|
284
|
-
_a._monitorManager = _b.sent();
|
|
285
|
-
this._monitorManagerFunction = new monitor_manager_1.MonitorManagerFunction();
|
|
286
|
-
this.installTimerDebug();
|
|
287
|
-
this.startPerfDebug();
|
|
288
|
-
if (this._cpuProfileOnStart) {
|
|
289
|
-
this.startCpuProfile('on-start');
|
|
290
|
-
}
|
|
291
|
-
// Check for workers and decide what to start
|
|
292
|
-
this._isWorkersEnabled = process.env.IS_WORKERS_ENABLED === 'true';
|
|
293
|
-
this._isWorkerInstance = process.env.IS_WORKER_INSTANCE === 'true';
|
|
294
|
-
this.startStandaloneNodeReaper();
|
|
295
|
-
setInterval(function () {
|
|
296
|
-
if (_this._methodManager && _this._methodManager.getEnableDebug()) {
|
|
297
|
-
console.log(new Date(), 'Server App', 'Msg Recv Hits', _this._debugMsgRecv);
|
|
298
|
-
console.log(new Date(), 'Server App', 'Msg Queue Hits', _this._debugMsgQueue);
|
|
299
|
-
}
|
|
300
|
-
_this._debugMsgQueue = 0;
|
|
301
|
-
_this._debugMsgRecv = 0;
|
|
302
|
-
}, 60000);
|
|
303
|
-
process.removeAllListeners('unhandledRejection');
|
|
304
|
-
process.on('unhandledRejection', function (error, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
305
|
-
var _a, normalizedError, correlationId, errorDetails, diffTimeSec;
|
|
306
|
-
var _this = this;
|
|
307
|
-
return __generator(this, function (_b) {
|
|
308
|
-
switch (_b.label) {
|
|
309
|
-
case 0:
|
|
310
|
-
_a = (0, error_tracking_1.ensureErrorWithCorrelation)(error), normalizedError = _a.error, correlationId = _a.correlationId;
|
|
311
|
-
if (this._methodManager.getEnableDebug()) {
|
|
312
|
-
console.error(new Date(), 'ERROR DETECTED w/ Debug Flag Active: unhandledRejection', [normalizedError, rej, { correlationId: correlationId }]);
|
|
313
|
-
}
|
|
314
|
-
// Condition to filter out the MongoError with specific codes
|
|
315
|
-
if (normalizedError && normalizedError['name'] === 'MongoError' && (normalizedError['code'] === 48 || normalizedError['code'] === 26 || normalizedError['code'] === 11000 || normalizedError['code'] === 251)) {
|
|
316
|
-
return [2 /*return*/]; // Simply return without doing anything further
|
|
317
|
-
}
|
|
318
|
-
// if (normalizedError && normalizedError['name'] === 'MongoServerError' && (!initServerFlag || normalizedError['code'] === 26 || normalizedError['code'] === 11000 || normalizedError['code'] === 86 || normalizedError['code'] === 251)) {
|
|
319
|
-
// return; // Simply return without doing anything further
|
|
320
|
-
// }
|
|
321
|
-
if (normalizedError && normalizedError['name'] === 'MongoServerError') {
|
|
322
|
-
return [2 /*return*/]; // Simply return without doing anything further
|
|
323
|
-
}
|
|
324
|
-
errorDetails = {
|
|
325
|
-
id: correlationId,
|
|
326
|
-
name: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.name,
|
|
327
|
-
message: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.message,
|
|
328
|
-
stack: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.stack,
|
|
329
|
-
code: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.code,
|
|
330
|
-
codeName: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.codeName
|
|
331
|
-
};
|
|
332
|
-
console.error(new Date(), 'Unhandled Rejection at Promise', [errorDetails]);
|
|
333
|
-
diffTimeSec = moment().diff(this._serverStartTime, 'seconds');
|
|
334
|
-
if (!(normalizedError && (normalizedError['name'] === 'MongoNetworkTimeoutError' || normalizedError instanceof mongodb_1.MongoNetworkTimeoutError))) return [3 /*break*/, 1];
|
|
335
|
-
if (diffTimeSec > 60 && !this._lastErrorMsg) {
|
|
336
|
-
this._lastErrorMsg = new Date();
|
|
337
|
-
setTimeout(function () {
|
|
338
|
-
_this._lastErrorMsg = null;
|
|
339
|
-
}, 60000);
|
|
340
|
-
// Exiting the process
|
|
341
|
-
process.exit(1);
|
|
342
|
-
}
|
|
343
|
-
return [3 /*break*/, 5];
|
|
344
|
-
case 1:
|
|
345
|
-
if (!(normalizedError && normalizedError['name'] === 'MongoError' && normalizedError['message'] === 'not master')) return [3 /*break*/, 2];
|
|
346
|
-
if (diffTimeSec > 60 && !this._lastErrorMsg) {
|
|
347
|
-
this._lastErrorMsg = new Date();
|
|
348
|
-
setTimeout(function () {
|
|
349
|
-
_this._lastErrorMsg = null;
|
|
350
|
-
}, 60000);
|
|
351
|
-
}
|
|
352
|
-
process.exit(1);
|
|
353
|
-
return [3 /*break*/, 5];
|
|
354
|
-
case 2:
|
|
355
|
-
if (!(normalizedError && normalizedError['name'] === 'MongoError' && normalizedError['message'] === 'not master and slaveOk=false')) return [3 /*break*/, 3];
|
|
356
|
-
if (diffTimeSec > 60 && !this._lastErrorMsg) {
|
|
357
|
-
this._lastErrorMsg = new Date();
|
|
358
|
-
setTimeout(function () {
|
|
359
|
-
_this._lastErrorMsg = null;
|
|
360
|
-
}, 60000);
|
|
361
|
-
}
|
|
362
|
-
process.exit(1);
|
|
363
|
-
return [3 /*break*/, 5];
|
|
364
|
-
case 3:
|
|
365
|
-
if (!(normalizedError && normalizedError['name'] !== 'StatusError' && normalizedError['message'] !== '')) return [3 /*break*/, 5];
|
|
366
|
-
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 5];
|
|
367
|
-
this._lastErrorMsg = new Date();
|
|
368
|
-
setTimeout(function () {
|
|
369
|
-
_this._lastErrorMsg = null;
|
|
370
|
-
}, 60000);
|
|
371
|
-
return [4 /*yield*/, this.reportServerError('SERVER - Unhandled Rejection - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, errorDetails, {
|
|
372
|
-
context: 'unhandledRejection',
|
|
373
|
-
scenario: 'General'
|
|
374
|
-
})];
|
|
375
|
-
case 4:
|
|
376
|
-
_b.sent();
|
|
377
|
-
_b.label = 5;
|
|
378
|
-
case 5: return [2 /*return*/];
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
}); });
|
|
382
|
-
process.on('uncaughtException', function (error) { return __awaiter(_this, void 0, void 0, function () {
|
|
383
|
-
var _a, normalizedError, correlationId, diffTimeSec, errorDetails;
|
|
384
|
-
var _this = this;
|
|
385
|
-
return __generator(this, function (_b) {
|
|
386
|
-
switch (_b.label) {
|
|
387
|
-
case 0:
|
|
388
|
-
_a = (0, error_tracking_1.ensureErrorWithCorrelation)(error), normalizedError = _a.error, correlationId = _a.correlationId;
|
|
389
|
-
console.error(normalizedError, 'Uncaught Exception thrown', { correlationId: correlationId });
|
|
390
|
-
diffTimeSec = moment().diff(this._serverStartTime, 'seconds');
|
|
391
|
-
if (!(diffTimeSec > 60 && !this._lastErrorMsg)) return [3 /*break*/, 2];
|
|
392
|
-
this._lastErrorMsg = new Date();
|
|
393
|
-
setTimeout(function () {
|
|
394
|
-
_this._lastErrorMsg = null;
|
|
395
|
-
}, 60000);
|
|
396
|
-
errorDetails = {
|
|
397
|
-
id: correlationId,
|
|
398
|
-
name: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.name,
|
|
399
|
-
message: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.message,
|
|
400
|
-
stack: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.stack,
|
|
401
|
-
code: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.code,
|
|
402
|
-
codeName: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.codeName
|
|
403
|
-
};
|
|
404
|
-
return [4 /*yield*/, this.reportServerError('SERVER - Unhandled Exception - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, errorDetails, {
|
|
405
|
-
context: 'uncaughtException'
|
|
406
|
-
})];
|
|
407
|
-
case 1:
|
|
408
|
-
_b.sent();
|
|
409
|
-
_b.label = 2;
|
|
410
|
-
case 2: return [2 /*return*/];
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
}); });
|
|
414
|
-
//PM2 wants to reboot/restart
|
|
415
|
-
process.on('SIGINT', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
416
|
-
var error_1;
|
|
417
|
-
return __generator(this, function (_a) {
|
|
418
|
-
switch (_a.label) {
|
|
419
|
-
case 0:
|
|
420
|
-
this._rebootFlag = true;
|
|
421
|
-
_a.label = 1;
|
|
422
|
-
case 1:
|
|
423
|
-
_a.trys.push([1, 3, , 4]);
|
|
424
|
-
return [4 /*yield*/, this.shutdownNetworkServers()];
|
|
425
|
-
case 2:
|
|
426
|
-
_a.sent();
|
|
427
|
-
return [3 /*break*/, 4];
|
|
428
|
-
case 3:
|
|
429
|
-
error_1 = _a.sent();
|
|
430
|
-
console.error(new Date(), 'Error closing network servers (SIGINT)', error_1);
|
|
431
|
-
return [3 /*break*/, 4];
|
|
432
|
-
case 4: return [4 /*yield*/, this.safeShutdown()];
|
|
433
|
-
case 5:
|
|
434
|
-
_a.sent();
|
|
435
|
-
return [2 /*return*/];
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
}); });
|
|
439
|
-
process.on('SIGTERM', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
440
|
-
var error_2;
|
|
441
|
-
return __generator(this, function (_a) {
|
|
442
|
-
switch (_a.label) {
|
|
443
|
-
case 0:
|
|
444
|
-
this._rebootFlag = true;
|
|
445
|
-
_a.label = 1;
|
|
446
|
-
case 1:
|
|
447
|
-
_a.trys.push([1, 3, , 4]);
|
|
448
|
-
return [4 /*yield*/, this.shutdownNetworkServers()];
|
|
449
|
-
case 2:
|
|
450
|
-
_a.sent();
|
|
451
|
-
return [3 /*break*/, 4];
|
|
452
|
-
case 3:
|
|
453
|
-
error_2 = _a.sent();
|
|
454
|
-
console.error(new Date(), 'Error closing network servers (SIGTERM)', error_2);
|
|
455
|
-
return [3 /*break*/, 4];
|
|
456
|
-
case 4: return [4 /*yield*/, this.safeShutdown()];
|
|
457
|
-
case 5:
|
|
458
|
-
_a.sent();
|
|
459
|
-
return [2 /*return*/];
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
}); });
|
|
463
|
-
process.on('SIGQUIT', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
464
|
-
var error_3;
|
|
465
|
-
return __generator(this, function (_a) {
|
|
466
|
-
switch (_a.label) {
|
|
467
|
-
case 0:
|
|
468
|
-
this._rebootFlag = true;
|
|
469
|
-
_a.label = 1;
|
|
470
|
-
case 1:
|
|
471
|
-
_a.trys.push([1, 3, , 4]);
|
|
472
|
-
return [4 /*yield*/, this.shutdownNetworkServers()];
|
|
473
|
-
case 2:
|
|
474
|
-
_a.sent();
|
|
475
|
-
return [3 /*break*/, 4];
|
|
476
|
-
case 3:
|
|
477
|
-
error_3 = _a.sent();
|
|
478
|
-
console.error(new Date(), 'Error closing network servers (SIGQUIT)', error_3);
|
|
479
|
-
return [3 /*break*/, 4];
|
|
480
|
-
case 4: return [4 /*yield*/, this.safeShutdown()];
|
|
481
|
-
case 5:
|
|
482
|
-
_a.sent();
|
|
483
|
-
return [2 /*return*/];
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
}); });
|
|
487
|
-
if (this.LOGGER === 'DEBUG') {
|
|
488
|
-
console.log('Starting ResolveIO Server');
|
|
489
|
-
}
|
|
490
|
-
if (this._isWorkersEnabled) {
|
|
491
|
-
if (this._isWorkerInstance) {
|
|
492
|
-
workerRole = this.resolveWorkerRole();
|
|
493
|
-
workerIndex = this.normalizeWorkerSelectorValue(process.env.WORKER_INDEX) || 'UNKNOWN';
|
|
494
|
-
workerInstance = this.normalizeWorkerSelectorValue(process.env.NODE_APP_INSTANCE) || 'UNKNOWN';
|
|
495
|
-
console.log("Running as Worker: ".concat(workerRole), workerIndex, workerInstance);
|
|
496
|
-
this._methodManager = method_manager_1.MethodManager.create(null, this._monitorManagerFunction, this._isWorkersEnabled, this._isWorkerInstance);
|
|
497
|
-
this._subscriptionManager = subscription_manager_1.SubscriptionManager.createPublicationRegistry(resolveio_server_app_1.ResolveIOServer.getServerConfig());
|
|
498
|
-
skipWorkerServerConnection = this.parseDebugFlag(process.env.DISABLE_WORKER_SERVER_CONNECTION)
|
|
499
|
-
|| this.parseDebugFlag(process.env.SUPPORT_CODEX_MANAGER_PROCESS_ONLY)
|
|
500
|
-
|| this.parseDebugFlag(process.env.SUPPORT_AUTO_MANAGER_PROCESS_ONLY)
|
|
501
|
-
|| this.parseDebugFlag(process.env.AI_ASSISTANT_CODEX_MANAGER_PROCESS_ONLY);
|
|
502
|
-
if (skipWorkerServerConnection) {
|
|
503
|
-
console.log(new Date(), 'Worker server connection disabled for process-only runtime', {
|
|
504
|
-
workerIndex: process.env.WORKER_INDEX || null,
|
|
505
|
-
workerInstance: process.env.NODE_APP_INSTANCE || null
|
|
506
|
-
});
|
|
507
|
-
this._workerServerManager = null;
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
this._workerServerManager = worker_server_manager_1.WorkerServerManager.create(this._methodManager, this.getServerConfig());
|
|
511
|
-
}
|
|
512
|
-
skipCronForProcessOnly = this.parseDebugFlag(process.env.SUPPORT_CODEX_MANAGER_PROCESS_ONLY)
|
|
513
|
-
|| this.parseDebugFlag(process.env.SUPPORT_AUTO_MANAGER_PROCESS_ONLY)
|
|
514
|
-
|| this.parseDebugFlag(process.env.AI_ASSISTANT_CODEX_MANAGER_PROCESS_ONLY);
|
|
515
|
-
if (this.shouldStartCronManagerForWorker() && !skipCronForProcessOnly) {
|
|
516
|
-
this._cronManager = cron_manager_1.CronManager.create();
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
console.log('Running as a Server instance', process.env.NODE_APP_INSTANCE);
|
|
521
|
-
this._websocketManager = websocket_manager_1.WebSocketManager.create(this);
|
|
522
|
-
this._methodManager = method_manager_1.MethodManager.create(this._websocketManager, this._monitorManagerFunction, this._isWorkersEnabled, this._isWorkerInstance);
|
|
523
|
-
this._workerDispatcherManager = worker_dispatcher_manager_1.WorkerDispatcherManager.create(this._websocketManager, this._methodManager);
|
|
524
|
-
this._subscriptionManager = subscription_manager_1.SubscriptionManager.create(this._serverWSS, resolveio_server_app_1.ResolveIOServer.getServerConfig(), this._monitorManagerFunction);
|
|
525
|
-
this.startServerInstance();
|
|
526
|
-
this.listen();
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
console.log('Running with Workers Disabled', process.env.NODE_APP_INSTANCE);
|
|
531
|
-
this._websocketManager = websocket_manager_1.WebSocketManager.create(this);
|
|
532
|
-
this._methodManager = method_manager_1.MethodManager.create(this._websocketManager, this._monitorManagerFunction, this._isWorkersEnabled, this._isWorkerInstance);
|
|
533
|
-
this._subscriptionManager = subscription_manager_1.SubscriptionManager.create(this._serverWSS, resolveio_server_app_1.ResolveIOServer.getServerConfig(), this._monitorManagerFunction);
|
|
534
|
-
this._cronManager = cron_manager_1.CronManager.create();
|
|
535
|
-
this.startServerInstance();
|
|
536
|
-
this.listen();
|
|
537
|
-
}
|
|
538
|
-
this.startAiAssistantCodexManagerIfEnabled();
|
|
539
|
-
return [2 /*return*/];
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
};
|
|
544
|
-
ResolveIOMainServer.prototype.startAiAssistantCodexManagerIfEnabled = function () {
|
|
545
|
-
try {
|
|
546
|
-
this._aiAssistantCodexManager = ai_assistant_codex_manager_manager_1.AiAssistantCodexManager.createIfEnabled({
|
|
547
|
-
isWorkersEnabled: this._isWorkersEnabled,
|
|
548
|
-
isWorkerInstance: this._isWorkerInstance,
|
|
549
|
-
workerIndex: process.env.WORKER_INDEX || null,
|
|
550
|
-
workerInstance: process.env.NODE_APP_INSTANCE || null
|
|
551
|
-
});
|
|
552
|
-
resolveio_server_app_1.ResolveIOServer['AiAssistantCodexManager'] = this._aiAssistantCodexManager;
|
|
553
|
-
}
|
|
554
|
-
catch (error) {
|
|
555
|
-
console.error(new Date(), 'Failed to start AI Assistant Codex Manager', error);
|
|
556
|
-
resolveio_server_app_1.ResolveIOServer['AiAssistantCodexManager'] = null;
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
ResolveIOMainServer.prototype.startStandaloneNodeReaper = function () {
|
|
560
|
-
var _this = this;
|
|
561
|
-
var _a, _b, _c;
|
|
562
|
-
if (!this._standaloneNodeReaperEnabled || this._standaloneNodeReaperTimer) {
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
if (process.platform !== 'linux' || !this.isPm2ManagedRuntime() || !this.isPrimaryPm2Instance()) {
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
var initialDelayMs = Math.min(30000, this._standaloneNodeReaperIntervalMs);
|
|
569
|
-
var firstRunTimer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
570
|
-
var error_4;
|
|
571
|
-
return __generator(this, function (_a) {
|
|
572
|
-
switch (_a.label) {
|
|
573
|
-
case 0:
|
|
574
|
-
_a.trys.push([0, 2, , 3]);
|
|
575
|
-
return [4 /*yield*/, this.reapStandaloneNodeProcesses()];
|
|
576
|
-
case 1:
|
|
577
|
-
_a.sent();
|
|
578
|
-
return [3 /*break*/, 3];
|
|
579
|
-
case 2:
|
|
580
|
-
error_4 = _a.sent();
|
|
581
|
-
console.error(new Date(), '[Standalone Node Reaper] failed', error_4);
|
|
582
|
-
return [3 /*break*/, 3];
|
|
583
|
-
case 3: return [2 /*return*/];
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
}); }, initialDelayMs);
|
|
587
|
-
(_a = firstRunTimer.unref) === null || _a === void 0 ? void 0 : _a.call(firstRunTimer);
|
|
588
|
-
this._standaloneNodeReaperTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
589
|
-
var error_5;
|
|
590
|
-
return __generator(this, function (_a) {
|
|
591
|
-
switch (_a.label) {
|
|
592
|
-
case 0:
|
|
593
|
-
_a.trys.push([0, 2, , 3]);
|
|
594
|
-
return [4 /*yield*/, this.reapStandaloneNodeProcesses()];
|
|
595
|
-
case 1:
|
|
596
|
-
_a.sent();
|
|
597
|
-
return [3 /*break*/, 3];
|
|
598
|
-
case 2:
|
|
599
|
-
error_5 = _a.sent();
|
|
600
|
-
console.error(new Date(), '[Standalone Node Reaper] failed', error_5);
|
|
601
|
-
return [3 /*break*/, 3];
|
|
602
|
-
case 3: return [2 /*return*/];
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
}); }, this._standaloneNodeReaperIntervalMs);
|
|
606
|
-
(_c = (_b = this._standaloneNodeReaperTimer).unref) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
607
|
-
console.log(new Date(), '[Standalone Node Reaper] enabled', {
|
|
608
|
-
intervalMs: this._standaloneNodeReaperIntervalMs,
|
|
609
|
-
minAgeSeconds: this._standaloneNodeReaperMinAgeSeconds,
|
|
610
|
-
maxKillsPerSignature: this._standaloneNodeReaperMaxKillsPerSignature,
|
|
611
|
-
killWindowMs: this._standaloneNodeReaperKillWindowMs,
|
|
612
|
-
highCpuPct: this._standaloneNodeReaperHighCpuPct,
|
|
613
|
-
highRssMb: this._standaloneNodeReaperHighRssMb,
|
|
614
|
-
highMinAgeSeconds: this._standaloneNodeReaperHighMinAgeSeconds,
|
|
615
|
-
highConsecutiveScans: this._standaloneNodeReaperHighConsecutiveScans,
|
|
616
|
-
alertWindowMs: this._standaloneNodeReaperAlertWindowMs,
|
|
617
|
-
dryRun: this._standaloneNodeReaperDryRun
|
|
618
|
-
});
|
|
619
|
-
};
|
|
620
|
-
ResolveIOMainServer.prototype.reapStandaloneNodeProcesses = function () {
|
|
621
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
622
|
-
var processes, protectedPids, _loop_1, this_1, processes_1, processes_1_1, proc, e_1_1;
|
|
623
|
-
var e_1, _a;
|
|
624
|
-
var _this = this;
|
|
625
|
-
var _b;
|
|
626
|
-
return __generator(this, function (_c) {
|
|
627
|
-
switch (_c.label) {
|
|
628
|
-
case 0:
|
|
629
|
-
if (this._standaloneNodeReaperRunning) {
|
|
630
|
-
return [2 /*return*/];
|
|
631
|
-
}
|
|
632
|
-
this._standaloneNodeReaperRunning = true;
|
|
633
|
-
_c.label = 1;
|
|
634
|
-
case 1:
|
|
635
|
-
_c.trys.push([1, , 11, 12]);
|
|
636
|
-
return [4 /*yield*/, this.listSystemProcesses()];
|
|
637
|
-
case 2:
|
|
638
|
-
processes = _c.sent();
|
|
639
|
-
protectedPids = this.resolvePm2ProtectedPids(processes);
|
|
640
|
-
_loop_1 = function (proc) {
|
|
641
|
-
var signature, reason, details, details, killTimer, error_6;
|
|
642
|
-
return __generator(this, function (_d) {
|
|
643
|
-
switch (_d.label) {
|
|
644
|
-
case 0:
|
|
645
|
-
if (!this_1.shouldReapStandaloneNodeProcess(proc, protectedPids)) {
|
|
646
|
-
return [2 /*return*/, "continue"];
|
|
647
|
-
}
|
|
648
|
-
signature = this_1.resolveStandaloneNodeProcessSignature(proc);
|
|
649
|
-
if (!this_1.canReapStandaloneNodeSignature(signature)) {
|
|
650
|
-
this_1.logStandaloneNodeReaperSuppressed(proc, signature);
|
|
651
|
-
return [2 /*return*/, "continue"];
|
|
652
|
-
}
|
|
653
|
-
reason = this_1.resolveStandaloneNodeReaperReason(proc);
|
|
654
|
-
if (!this_1._standaloneNodeReaperDryRun) return [3 /*break*/, 2];
|
|
655
|
-
this_1.recordStandaloneNodeReaperKill(signature);
|
|
656
|
-
details = this_1.createStandaloneNodeReaperDetails(proc, reason, 'dry-run');
|
|
657
|
-
console.warn(new Date(), '[Standalone Node Reaper] dry-run would terminate stale node process', details);
|
|
658
|
-
return [4 /*yield*/, this_1.reportStandaloneNodeReaperAction(proc, reason, 'dry-run')];
|
|
659
|
-
case 1:
|
|
660
|
-
_d.sent();
|
|
661
|
-
return [2 /*return*/, "continue"];
|
|
662
|
-
case 2:
|
|
663
|
-
_d.trys.push([2, 4, , 5]);
|
|
664
|
-
process.kill(proc.pid, 'SIGTERM');
|
|
665
|
-
this_1.recordStandaloneNodeReaperKill(signature);
|
|
666
|
-
details = this_1.createStandaloneNodeReaperDetails(proc, reason, 'terminated');
|
|
667
|
-
console.warn(new Date(), '[Standalone Node Reaper] terminated stale node process', details);
|
|
668
|
-
return [4 /*yield*/, this_1.reportStandaloneNodeReaperAction(proc, reason, 'terminated')];
|
|
669
|
-
case 3:
|
|
670
|
-
_d.sent();
|
|
671
|
-
killTimer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
672
|
-
var _a;
|
|
673
|
-
return __generator(this, function (_b) {
|
|
674
|
-
switch (_b.label) {
|
|
675
|
-
case 0:
|
|
676
|
-
_b.trys.push([0, 2, , 3]);
|
|
677
|
-
process.kill(proc.pid, 0);
|
|
678
|
-
process.kill(proc.pid, 'SIGKILL');
|
|
679
|
-
console.warn(new Date(), '[Standalone Node Reaper] force killed stale node process', {
|
|
680
|
-
pid: proc.pid,
|
|
681
|
-
reason: reason,
|
|
682
|
-
command: proc.args
|
|
683
|
-
});
|
|
684
|
-
return [4 /*yield*/, this.reportStandaloneNodeReaperAction(proc, reason, 'force-killed')];
|
|
685
|
-
case 1:
|
|
686
|
-
_b.sent();
|
|
687
|
-
return [3 /*break*/, 3];
|
|
688
|
-
case 2:
|
|
689
|
-
_a = _b.sent();
|
|
690
|
-
return [3 /*break*/, 3];
|
|
691
|
-
case 3: return [2 /*return*/];
|
|
692
|
-
}
|
|
693
|
-
});
|
|
694
|
-
}); }, 10000);
|
|
695
|
-
(_b = killTimer.unref) === null || _b === void 0 ? void 0 : _b.call(killTimer);
|
|
696
|
-
return [3 /*break*/, 5];
|
|
697
|
-
case 4:
|
|
698
|
-
error_6 = _d.sent();
|
|
699
|
-
if ((error_6 === null || error_6 === void 0 ? void 0 : error_6['code']) !== 'ESRCH') {
|
|
700
|
-
console.error(new Date(), '[Standalone Node Reaper] kill failed', {
|
|
701
|
-
pid: proc.pid,
|
|
702
|
-
command: proc.args,
|
|
703
|
-
error: (error_6 === null || error_6 === void 0 ? void 0 : error_6['message']) || error_6
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
return [3 /*break*/, 5];
|
|
707
|
-
case 5: return [2 /*return*/];
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
};
|
|
711
|
-
this_1 = this;
|
|
712
|
-
_c.label = 3;
|
|
713
|
-
case 3:
|
|
714
|
-
_c.trys.push([3, 8, 9, 10]);
|
|
715
|
-
processes_1 = __values(processes), processes_1_1 = processes_1.next();
|
|
716
|
-
_c.label = 4;
|
|
717
|
-
case 4:
|
|
718
|
-
if (!!processes_1_1.done) return [3 /*break*/, 7];
|
|
719
|
-
proc = processes_1_1.value;
|
|
720
|
-
return [5 /*yield**/, _loop_1(proc)];
|
|
721
|
-
case 5:
|
|
722
|
-
_c.sent();
|
|
723
|
-
_c.label = 6;
|
|
724
|
-
case 6:
|
|
725
|
-
processes_1_1 = processes_1.next();
|
|
726
|
-
return [3 /*break*/, 4];
|
|
727
|
-
case 7: return [3 /*break*/, 10];
|
|
728
|
-
case 8:
|
|
729
|
-
e_1_1 = _c.sent();
|
|
730
|
-
e_1 = { error: e_1_1 };
|
|
731
|
-
return [3 /*break*/, 10];
|
|
732
|
-
case 9:
|
|
733
|
-
try {
|
|
734
|
-
if (processes_1_1 && !processes_1_1.done && (_a = processes_1.return)) _a.call(processes_1);
|
|
735
|
-
}
|
|
736
|
-
finally { if (e_1) throw e_1.error; }
|
|
737
|
-
return [7 /*endfinally*/];
|
|
738
|
-
case 10: return [3 /*break*/, 12];
|
|
739
|
-
case 11:
|
|
740
|
-
this._standaloneNodeReaperRunning = false;
|
|
741
|
-
return [7 /*endfinally*/];
|
|
742
|
-
case 12: return [2 /*return*/];
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
});
|
|
746
|
-
};
|
|
747
|
-
ResolveIOMainServer.prototype.createStandaloneNodeReaperDetails = function (proc, reason, action) {
|
|
748
|
-
return {
|
|
749
|
-
action: action,
|
|
750
|
-
pid: proc.pid,
|
|
751
|
-
ppid: proc.ppid,
|
|
752
|
-
ageSeconds: proc.ageSeconds,
|
|
753
|
-
cpuPct: proc.cpuPct,
|
|
754
|
-
rssMb: (0, common_1.round)(proc.rssKb / 1024),
|
|
755
|
-
reason: reason,
|
|
756
|
-
command: proc.args
|
|
757
|
-
};
|
|
758
|
-
};
|
|
759
|
-
ResolveIOMainServer.prototype.reportStandaloneNodeReaperAction = function (proc, reason, action) {
|
|
760
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
761
|
-
var signature, alertKey, now, lastReportedAt, error_7;
|
|
762
|
-
var _a;
|
|
763
|
-
return __generator(this, function (_b) {
|
|
764
|
-
switch (_b.label) {
|
|
765
|
-
case 0:
|
|
766
|
-
signature = this.resolveStandaloneNodeProcessSignature(proc);
|
|
767
|
-
alertKey = "".concat(action, "|").concat(signature);
|
|
768
|
-
now = Date.now();
|
|
769
|
-
lastReportedAt = this._standaloneNodeReaperAlertTimes.get(alertKey);
|
|
770
|
-
if (lastReportedAt && (now - lastReportedAt) < this._standaloneNodeReaperAlertWindowMs) {
|
|
771
|
-
return [2 /*return*/];
|
|
772
|
-
}
|
|
773
|
-
_b.label = 1;
|
|
774
|
-
case 1:
|
|
775
|
-
_b.trys.push([1, 3, , 4]);
|
|
776
|
-
return [4 /*yield*/, this.reportServerError("SERVER - Standalone Node Reaper ".concat(action, " process - ").concat(((_a = resolveio_server_app_1.ResolveIOServer.getServerConfig()) === null || _a === void 0 ? void 0 : _a['CLIENT_NAME']) || resolveio_server_app_1.ResolveIOServer.getClientName()), crypto.randomUUID(), __assign(__assign({}, this.createStandaloneNodeReaperDetails(proc, reason, action)), { host: os.hostname(), workerIndex: process.env.WORKER_INDEX || null, workerInstance: process.env.NODE_APP_INSTANCE || null, dryRun: this._standaloneNodeReaperDryRun, alertWindowMs: this._standaloneNodeReaperAlertWindowMs }), {
|
|
777
|
-
context: 'standaloneNodeReaper',
|
|
778
|
-
action: action,
|
|
779
|
-
reason: reason,
|
|
780
|
-
signature: signature
|
|
781
|
-
}, 'warning')];
|
|
782
|
-
case 2:
|
|
783
|
-
_b.sent();
|
|
784
|
-
this._standaloneNodeReaperAlertTimes.set(alertKey, now);
|
|
785
|
-
return [3 /*break*/, 4];
|
|
786
|
-
case 3:
|
|
787
|
-
error_7 = _b.sent();
|
|
788
|
-
console.error(new Date(), '[Standalone Node Reaper] alert failed', {
|
|
789
|
-
action: action,
|
|
790
|
-
pid: proc.pid,
|
|
791
|
-
error: (error_7 === null || error_7 === void 0 ? void 0 : error_7['message']) || error_7
|
|
792
|
-
});
|
|
793
|
-
return [3 /*break*/, 4];
|
|
794
|
-
case 4: return [2 /*return*/];
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
});
|
|
798
|
-
};
|
|
799
|
-
ResolveIOMainServer.prototype.listSystemProcesses = function () {
|
|
800
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
801
|
-
var output;
|
|
802
|
-
var _this = this;
|
|
803
|
-
return __generator(this, function (_a) {
|
|
804
|
-
switch (_a.label) {
|
|
805
|
-
case 0: return [4 /*yield*/, this.execFileText('ps', ['-eo', 'pid=,ppid=,etimes=,pcpu=,rss=,comm=,args='], 5000)];
|
|
806
|
-
case 1:
|
|
807
|
-
output = _a.sent();
|
|
808
|
-
return [2 /*return*/, output
|
|
809
|
-
.split('\n')
|
|
810
|
-
.map(function (line) { return line.trim(); })
|
|
811
|
-
.filter(Boolean)
|
|
812
|
-
.map(function (line) { return _this.parseProcessSnapshot(line); })
|
|
813
|
-
.filter(function (proc) { return proc !== null; })];
|
|
814
|
-
}
|
|
815
|
-
});
|
|
816
|
-
});
|
|
817
|
-
};
|
|
818
|
-
ResolveIOMainServer.prototype.parseProcessSnapshot = function (line) {
|
|
819
|
-
var match = line.match(/^(\d+)\s+(\d+)\s+(\d+)\s+([\d.]+)\s+(\d+)\s+(\S+)\s+(.*)$/);
|
|
820
|
-
if (!match) {
|
|
821
|
-
return null;
|
|
822
|
-
}
|
|
823
|
-
return {
|
|
824
|
-
pid: parseInt(match[1], 10),
|
|
825
|
-
ppid: parseInt(match[2], 10),
|
|
826
|
-
ageSeconds: parseInt(match[3], 10),
|
|
827
|
-
cpuPct: parseFloat(match[4]),
|
|
828
|
-
rssKb: parseInt(match[5], 10),
|
|
829
|
-
command: match[6],
|
|
830
|
-
args: match[7] || ''
|
|
831
|
-
};
|
|
832
|
-
};
|
|
833
|
-
ResolveIOMainServer.prototype.execFileText = function (command, args, timeoutMs) {
|
|
834
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
835
|
-
return new Promise(function (resolve, reject) {
|
|
836
|
-
(0, child_process_1.execFile)(command, args, { timeout: timeoutMs, maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
|
837
|
-
if (error) {
|
|
838
|
-
reject(error);
|
|
839
|
-
return;
|
|
840
|
-
}
|
|
841
|
-
resolve(stdout || '');
|
|
842
|
-
});
|
|
843
|
-
});
|
|
844
|
-
};
|
|
845
|
-
ResolveIOMainServer.prototype.resolvePm2ProtectedPids = function (processes) {
|
|
846
|
-
var e_2, _a, e_3, _b;
|
|
847
|
-
var byPid = new Map();
|
|
848
|
-
var children = new Map();
|
|
849
|
-
try {
|
|
850
|
-
for (var processes_2 = __values(processes), processes_2_1 = processes_2.next(); !processes_2_1.done; processes_2_1 = processes_2.next()) {
|
|
851
|
-
var proc = processes_2_1.value;
|
|
852
|
-
byPid.set(proc.pid, proc);
|
|
853
|
-
if (!children.has(proc.ppid)) {
|
|
854
|
-
children.set(proc.ppid, []);
|
|
855
|
-
}
|
|
856
|
-
children.get(proc.ppid).push(proc.pid);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
860
|
-
finally {
|
|
861
|
-
try {
|
|
862
|
-
if (processes_2_1 && !processes_2_1.done && (_a = processes_2.return)) _a.call(processes_2);
|
|
863
|
-
}
|
|
864
|
-
finally { if (e_2) throw e_2.error; }
|
|
865
|
-
}
|
|
866
|
-
var protectedPids = new Set();
|
|
867
|
-
var addWithDescendants = function (pid) {
|
|
868
|
-
var e_4, _a;
|
|
869
|
-
if (protectedPids.has(pid)) {
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
protectedPids.add(pid);
|
|
873
|
-
try {
|
|
874
|
-
for (var _b = __values(children.get(pid) || []), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
875
|
-
var childPid = _c.value;
|
|
876
|
-
addWithDescendants(childPid);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
880
|
-
finally {
|
|
881
|
-
try {
|
|
882
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
883
|
-
}
|
|
884
|
-
finally { if (e_4) throw e_4.error; }
|
|
885
|
-
}
|
|
886
|
-
};
|
|
887
|
-
try {
|
|
888
|
-
for (var processes_3 = __values(processes), processes_3_1 = processes_3.next(); !processes_3_1.done; processes_3_1 = processes_3.next()) {
|
|
889
|
-
var proc = processes_3_1.value;
|
|
890
|
-
if (proc.args.includes('pm2-runtime') || proc.args.includes('/pm2/')) {
|
|
891
|
-
addWithDescendants(proc.pid);
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
896
|
-
finally {
|
|
897
|
-
try {
|
|
898
|
-
if (processes_3_1 && !processes_3_1.done && (_b = processes_3.return)) _b.call(processes_3);
|
|
899
|
-
}
|
|
900
|
-
finally { if (e_3) throw e_3.error; }
|
|
901
|
-
}
|
|
902
|
-
var currentPid = process.pid;
|
|
903
|
-
while (currentPid && byPid.has(currentPid)) {
|
|
904
|
-
protectedPids.add(currentPid);
|
|
905
|
-
currentPid = byPid.get(currentPid).ppid;
|
|
906
|
-
}
|
|
907
|
-
return protectedPids;
|
|
908
|
-
};
|
|
909
|
-
ResolveIOMainServer.prototype.shouldReapStandaloneNodeProcess = function (proc, protectedPids) {
|
|
910
|
-
if (proc.pid === process.pid || proc.ppid !== 1 || protectedPids.has(proc.pid)) {
|
|
911
|
-
return false;
|
|
912
|
-
}
|
|
913
|
-
if (!this.isNodeProcess(proc) || !this.isSameUidProcess(proc.pid)) {
|
|
914
|
-
return false;
|
|
915
|
-
}
|
|
916
|
-
if (!this._standaloneNodeReaperIncludeSystemdServices && this.isProtectedSystemdServiceProcess(proc)) {
|
|
917
|
-
return false;
|
|
918
|
-
}
|
|
919
|
-
if (!this.isResolveIOAppProcess(proc)) {
|
|
920
|
-
return false;
|
|
921
|
-
}
|
|
922
|
-
if (proc.ageSeconds >= this._standaloneNodeReaperMinAgeSeconds) {
|
|
923
|
-
return true;
|
|
924
|
-
}
|
|
925
|
-
if (proc.ageSeconds < this._standaloneNodeReaperHighMinAgeSeconds || !this.hasHighStandaloneNodeResourceUsage(proc)) {
|
|
926
|
-
this.clearStandaloneNodeResourceHit(proc);
|
|
927
|
-
return false;
|
|
928
|
-
}
|
|
929
|
-
return this.recordStandaloneNodeResourceHit(proc) >= this._standaloneNodeReaperHighConsecutiveScans;
|
|
930
|
-
};
|
|
931
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperReason = function (proc) {
|
|
932
|
-
if (proc.ageSeconds >= this._standaloneNodeReaperMinAgeSeconds) {
|
|
933
|
-
return "orphan_age_seconds_gte_".concat(this._standaloneNodeReaperMinAgeSeconds);
|
|
934
|
-
}
|
|
935
|
-
var rssMb = proc.rssKb / 1024;
|
|
936
|
-
if (proc.cpuPct >= this._standaloneNodeReaperHighCpuPct && rssMb >= this._standaloneNodeReaperHighRssMb) {
|
|
937
|
-
return "orphan_high_cpu_and_rss_for_".concat(this._standaloneNodeReaperHighConsecutiveScans, "_scans");
|
|
938
|
-
}
|
|
939
|
-
if (proc.cpuPct >= this._standaloneNodeReaperHighCpuPct) {
|
|
940
|
-
return "orphan_high_cpu_for_".concat(this._standaloneNodeReaperHighConsecutiveScans, "_scans");
|
|
941
|
-
}
|
|
942
|
-
if (rssMb >= this._standaloneNodeReaperHighRssMb) {
|
|
943
|
-
return "orphan_high_rss_for_".concat(this._standaloneNodeReaperHighConsecutiveScans, "_scans");
|
|
944
|
-
}
|
|
945
|
-
return 'orphan_stale_node_process';
|
|
946
|
-
};
|
|
947
|
-
ResolveIOMainServer.prototype.isNodeProcess = function (proc) {
|
|
948
|
-
return proc.command === 'node' || proc.command.startsWith('node ') || proc.args === 'node' || proc.args.startsWith('node ');
|
|
949
|
-
};
|
|
950
|
-
ResolveIOMainServer.prototype.isResolveIOAppProcess = function (proc) {
|
|
951
|
-
var e_5, _a;
|
|
952
|
-
var normalizedArgs = proc.args || '';
|
|
953
|
-
var appDirs = this.resolveCurrentAppDirs();
|
|
954
|
-
try {
|
|
955
|
-
for (var appDirs_1 = __values(appDirs), appDirs_1_1 = appDirs_1.next(); !appDirs_1_1.done; appDirs_1_1 = appDirs_1.next()) {
|
|
956
|
-
var appDir = appDirs_1_1.value;
|
|
957
|
-
if (normalizedArgs.includes(appDir)) {
|
|
958
|
-
return true;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
963
|
-
finally {
|
|
964
|
-
try {
|
|
965
|
-
if (appDirs_1_1 && !appDirs_1_1.done && (_a = appDirs_1.return)) _a.call(appDirs_1);
|
|
966
|
-
}
|
|
967
|
-
finally { if (e_5) throw e_5.error; }
|
|
968
|
-
}
|
|
969
|
-
if (normalizedArgs.includes('server-app.js') && normalizedArgs.includes('require(')) {
|
|
970
|
-
return true;
|
|
971
|
-
}
|
|
972
|
-
var cwd = this.resolveProcessCwd(proc.pid);
|
|
973
|
-
return cwd !== null && appDirs.has(cwd) && /\b(index|server-app)\.js\b/.test(normalizedArgs);
|
|
974
|
-
};
|
|
975
|
-
ResolveIOMainServer.prototype.hasHighStandaloneNodeResourceUsage = function (proc) {
|
|
976
|
-
var rssMb = proc.rssKb / 1024;
|
|
977
|
-
return proc.cpuPct >= this._standaloneNodeReaperHighCpuPct || rssMb >= this._standaloneNodeReaperHighRssMb;
|
|
978
|
-
};
|
|
979
|
-
ResolveIOMainServer.prototype.recordStandaloneNodeResourceHit = function (proc) {
|
|
980
|
-
var signature = this.resolveStandaloneNodeProcessSignature(proc);
|
|
981
|
-
var now = Date.now();
|
|
982
|
-
var current = this._standaloneNodeReaperResourceHits.get(signature);
|
|
983
|
-
if (!current || (now - current.lastSeenMs) > (this._standaloneNodeReaperIntervalMs * 3)) {
|
|
984
|
-
this._standaloneNodeReaperResourceHits.set(signature, { count: 1, lastSeenMs: now });
|
|
985
|
-
return 1;
|
|
986
|
-
}
|
|
987
|
-
current.count += 1;
|
|
988
|
-
current.lastSeenMs = now;
|
|
989
|
-
return current.count;
|
|
990
|
-
};
|
|
991
|
-
ResolveIOMainServer.prototype.clearStandaloneNodeResourceHit = function (proc) {
|
|
992
|
-
this._standaloneNodeReaperResourceHits.delete(this.resolveStandaloneNodeProcessSignature(proc));
|
|
993
|
-
};
|
|
994
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeProcessSignature = function (proc) {
|
|
995
|
-
var cwd = this.resolveProcessCwd(proc.pid) || '';
|
|
996
|
-
return "".concat(cwd, "|").concat(proc.args);
|
|
997
|
-
};
|
|
998
|
-
ResolveIOMainServer.prototype.canReapStandaloneNodeSignature = function (signature) {
|
|
999
|
-
var now = Date.now();
|
|
1000
|
-
var current = this._standaloneNodeReaperKillCounts.get(signature);
|
|
1001
|
-
if (!current || (now - current.windowStartMs) > this._standaloneNodeReaperKillWindowMs) {
|
|
1002
|
-
this._standaloneNodeReaperKillCounts.set(signature, { count: 0, windowStartMs: now });
|
|
1003
|
-
this._standaloneNodeReaperSuppressedSignatures.delete(signature);
|
|
1004
|
-
return true;
|
|
1005
|
-
}
|
|
1006
|
-
return current.count < this._standaloneNodeReaperMaxKillsPerSignature;
|
|
1007
|
-
};
|
|
1008
|
-
ResolveIOMainServer.prototype.recordStandaloneNodeReaperKill = function (signature) {
|
|
1009
|
-
var now = Date.now();
|
|
1010
|
-
var current = this._standaloneNodeReaperKillCounts.get(signature);
|
|
1011
|
-
if (!current || (now - current.windowStartMs) > this._standaloneNodeReaperKillWindowMs) {
|
|
1012
|
-
this._standaloneNodeReaperKillCounts.set(signature, { count: 1, windowStartMs: now });
|
|
1013
|
-
this._standaloneNodeReaperSuppressedSignatures.delete(signature);
|
|
1014
|
-
return;
|
|
1015
|
-
}
|
|
1016
|
-
current.count += 1;
|
|
1017
|
-
};
|
|
1018
|
-
ResolveIOMainServer.prototype.logStandaloneNodeReaperSuppressed = function (proc, signature) {
|
|
1019
|
-
if (this._standaloneNodeReaperSuppressedSignatures.has(signature)) {
|
|
1020
|
-
return;
|
|
1021
|
-
}
|
|
1022
|
-
this._standaloneNodeReaperSuppressedSignatures.add(signature);
|
|
1023
|
-
console.warn(new Date(), '[Standalone Node Reaper] suppressing recurring stale node process', {
|
|
1024
|
-
pid: proc.pid,
|
|
1025
|
-
ppid: proc.ppid,
|
|
1026
|
-
ageSeconds: proc.ageSeconds,
|
|
1027
|
-
cpuPct: proc.cpuPct,
|
|
1028
|
-
rssMb: (0, common_1.round)(proc.rssKb / 1024),
|
|
1029
|
-
maxKillsPerSignature: this._standaloneNodeReaperMaxKillsPerSignature,
|
|
1030
|
-
killWindowMs: this._standaloneNodeReaperKillWindowMs,
|
|
1031
|
-
command: proc.args
|
|
1032
|
-
});
|
|
1033
|
-
};
|
|
1034
|
-
ResolveIOMainServer.prototype.resolveCurrentAppDirs = function () {
|
|
1035
|
-
var e_6, _a;
|
|
1036
|
-
var _b;
|
|
1037
|
-
var dirs = new Set();
|
|
1038
|
-
try {
|
|
1039
|
-
for (var _c = __values([process.cwd(), (_b = resolveio_server_app_1.ResolveIOServer.getClientDir) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)]), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1040
|
-
var value = _d.value;
|
|
1041
|
-
if (!value) {
|
|
1042
|
-
continue;
|
|
1043
|
-
}
|
|
1044
|
-
var resolved = this.safeRealpath(value);
|
|
1045
|
-
if (resolved) {
|
|
1046
|
-
dirs.add(resolved);
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1051
|
-
finally {
|
|
1052
|
-
try {
|
|
1053
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1054
|
-
}
|
|
1055
|
-
finally { if (e_6) throw e_6.error; }
|
|
1056
|
-
}
|
|
1057
|
-
return dirs;
|
|
1058
|
-
};
|
|
1059
|
-
ResolveIOMainServer.prototype.resolveProcessCwd = function (pid) {
|
|
1060
|
-
return this.safeRealpath("/proc/".concat(pid, "/cwd"));
|
|
1061
|
-
};
|
|
1062
|
-
ResolveIOMainServer.prototype.safeRealpath = function (value) {
|
|
1063
|
-
try {
|
|
1064
|
-
return fs.realpathSync(value);
|
|
1065
|
-
}
|
|
1066
|
-
catch (_a) {
|
|
1067
|
-
return null;
|
|
1068
|
-
}
|
|
1069
|
-
};
|
|
1070
|
-
ResolveIOMainServer.prototype.isSameUidProcess = function (pid) {
|
|
1071
|
-
if (typeof process.getuid !== 'function') {
|
|
1072
|
-
return true;
|
|
1073
|
-
}
|
|
1074
|
-
try {
|
|
1075
|
-
var status_1 = fs.readFileSync("/proc/".concat(pid, "/status"), 'utf8');
|
|
1076
|
-
var uidLine = status_1.split('\n').find(function (line) { return line.startsWith('Uid:'); });
|
|
1077
|
-
if (!uidLine) {
|
|
1078
|
-
return false;
|
|
1079
|
-
}
|
|
1080
|
-
var uid = parseInt(uidLine.split(/\s+/)[1], 10);
|
|
1081
|
-
return uid === process.getuid();
|
|
1082
|
-
}
|
|
1083
|
-
catch (_a) {
|
|
1084
|
-
return false;
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
ResolveIOMainServer.prototype.isProtectedSystemdServiceProcess = function (proc) {
|
|
1088
|
-
var serviceName = this.resolveSystemdServiceName(proc.pid);
|
|
1089
|
-
if (!serviceName) {
|
|
1090
|
-
return false;
|
|
1091
|
-
}
|
|
1092
|
-
return /\bindex\.js\b/.test(proc.args);
|
|
1093
|
-
};
|
|
1094
|
-
ResolveIOMainServer.prototype.resolveSystemdServiceName = function (pid) {
|
|
1095
|
-
try {
|
|
1096
|
-
var cgroup = fs.readFileSync("/proc/".concat(pid, "/cgroup"), 'utf8');
|
|
1097
|
-
var serviceLine = cgroup.split('\n').find(function (line) { return line.includes('/system.slice/') && line.includes('.service'); });
|
|
1098
|
-
if (!serviceLine) {
|
|
1099
|
-
return null;
|
|
1100
|
-
}
|
|
1101
|
-
var match = serviceLine.match(/\/system\.slice\/([^/]+\.service)/);
|
|
1102
|
-
return match ? match[1] : null;
|
|
1103
|
-
}
|
|
1104
|
-
catch (_a) {
|
|
1105
|
-
return null;
|
|
1106
|
-
}
|
|
1107
|
-
};
|
|
1108
|
-
ResolveIOMainServer.prototype.shutdownNetworkServers = function () {
|
|
1109
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1110
|
-
return __generator(this, function (_a) {
|
|
1111
|
-
switch (_a.label) {
|
|
1112
|
-
case 0: return [4 /*yield*/, this.closeWebSocketServerGracefully()];
|
|
1113
|
-
case 1:
|
|
1114
|
-
_a.sent();
|
|
1115
|
-
return [4 /*yield*/, this.closeHttpServerGracefully()];
|
|
1116
|
-
case 2:
|
|
1117
|
-
_a.sent();
|
|
1118
|
-
return [2 /*return*/];
|
|
1119
|
-
}
|
|
1120
|
-
});
|
|
1121
|
-
});
|
|
1122
|
-
};
|
|
1123
|
-
ResolveIOMainServer.prototype.closeHttpServerGracefully = function () {
|
|
1124
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1125
|
-
var _this = this;
|
|
1126
|
-
return __generator(this, function (_a) {
|
|
1127
|
-
switch (_a.label) {
|
|
1128
|
-
case 0:
|
|
1129
|
-
if (!this._serverHTTP) {
|
|
1130
|
-
return [2 /*return*/];
|
|
1131
|
-
}
|
|
1132
|
-
if (!(this._httpServerClosePromise !== null)) return [3 /*break*/, 2];
|
|
1133
|
-
return [4 /*yield*/, this._httpServerClosePromise];
|
|
1134
|
-
case 1:
|
|
1135
|
-
_a.sent();
|
|
1136
|
-
return [2 /*return*/];
|
|
1137
|
-
case 2:
|
|
1138
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
1139
|
-
this._httpServerClosePromise = new Promise(function (resolve) {
|
|
1140
|
-
try {
|
|
1141
|
-
_this._serverHTTP.close(function (error) {
|
|
1142
|
-
if (error && error['code'] !== 'ERR_SERVER_NOT_RUNNING') {
|
|
1143
|
-
console.error(new Date(), 'Error closing HTTP server before shutdown', error);
|
|
1144
|
-
}
|
|
1145
|
-
resolve();
|
|
1146
|
-
});
|
|
1147
|
-
}
|
|
1148
|
-
catch (error) {
|
|
1149
|
-
if (error && error['code'] !== 'ERR_SERVER_NOT_RUNNING') {
|
|
1150
|
-
console.error(new Date(), 'Error closing HTTP server before shutdown', error);
|
|
1151
|
-
}
|
|
1152
|
-
resolve();
|
|
1153
|
-
}
|
|
1154
|
-
});
|
|
1155
|
-
return [4 /*yield*/, this._httpServerClosePromise];
|
|
1156
|
-
case 3:
|
|
1157
|
-
_a.sent();
|
|
1158
|
-
return [2 /*return*/];
|
|
1159
|
-
}
|
|
1160
|
-
});
|
|
1161
|
-
});
|
|
1162
|
-
};
|
|
1163
|
-
ResolveIOMainServer.prototype.closeWebSocketServerGracefully = function () {
|
|
1164
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1165
|
-
var _this = this;
|
|
1166
|
-
return __generator(this, function (_a) {
|
|
1167
|
-
switch (_a.label) {
|
|
1168
|
-
case 0:
|
|
1169
|
-
if (!this._serverWSS) {
|
|
1170
|
-
return [2 /*return*/];
|
|
1171
|
-
}
|
|
1172
|
-
if (!(this._websocketServerClosePromise !== null)) return [3 /*break*/, 2];
|
|
1173
|
-
return [4 /*yield*/, this._websocketServerClosePromise];
|
|
1174
|
-
case 1:
|
|
1175
|
-
_a.sent();
|
|
1176
|
-
return [2 /*return*/];
|
|
1177
|
-
case 2:
|
|
1178
|
-
this._serverWSS.clients.forEach(function (ws) {
|
|
1179
|
-
try {
|
|
1180
|
-
ws.close(1001, 'Server restarting');
|
|
1181
|
-
}
|
|
1182
|
-
catch (error) {
|
|
1183
|
-
console.error(new Date(), 'Error closing WebSocket client before shutdown', error);
|
|
1184
|
-
}
|
|
1185
|
-
});
|
|
1186
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
1187
|
-
this._websocketServerClosePromise = new Promise(function (resolve) {
|
|
1188
|
-
try {
|
|
1189
|
-
_this._serverWSS.close(function (error) {
|
|
1190
|
-
if (error) {
|
|
1191
|
-
console.error(new Date(), 'Error closing WebSocket server before shutdown', error);
|
|
1192
|
-
}
|
|
1193
|
-
resolve();
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
catch (error) {
|
|
1197
|
-
console.error(new Date(), 'Error closing WebSocket server before shutdown', error);
|
|
1198
|
-
resolve();
|
|
1199
|
-
}
|
|
1200
|
-
});
|
|
1201
|
-
return [4 /*yield*/, this._websocketServerClosePromise];
|
|
1202
|
-
case 3:
|
|
1203
|
-
_a.sent();
|
|
1204
|
-
return [2 /*return*/];
|
|
1205
|
-
}
|
|
1206
|
-
});
|
|
1207
|
-
});
|
|
1208
|
-
};
|
|
1209
|
-
ResolveIOMainServer.prototype.startServerInstance = function () {
|
|
1210
|
-
// Start express app
|
|
1211
|
-
this._app = express();
|
|
1212
|
-
// Use built-in express JSON parser
|
|
1213
|
-
this._app.use(express.json({
|
|
1214
|
-
limit: '50mb',
|
|
1215
|
-
reviver: common_1.dateReviver // Note: 'reviver' is an option for JSON.parse, which can be passed here
|
|
1216
|
-
}));
|
|
1217
|
-
// Use built-in express URL-encoded parser
|
|
1218
|
-
this._app.use(express.urlencoded({
|
|
1219
|
-
limit: '50mb',
|
|
1220
|
-
extended: true, // `extended` must be explicitly true or false
|
|
1221
|
-
parameterLimit: 1000000
|
|
1222
|
-
}));
|
|
1223
|
-
this._app.use(xmlParser());
|
|
1224
|
-
// Set port
|
|
1225
|
-
this._portHTTP = process.env.NODE_APP_INSTANCE ? parseInt('808' + process.env.NODE_APP_INSTANCE) : 8080;
|
|
1226
|
-
if (this.LOGGER === 'DEBUG') {
|
|
1227
|
-
console.log('Setup ports');
|
|
1228
|
-
}
|
|
1229
|
-
// Create http server and websock server
|
|
1230
|
-
this.createServer();
|
|
1231
|
-
if (this.LOGGER === 'DEBUG') {
|
|
1232
|
-
console.log('Create server');
|
|
1233
|
-
}
|
|
1234
|
-
// Set CORS
|
|
1235
|
-
this._app.use(function (req, res, next) {
|
|
1236
|
-
var requestOrigin = String(req.headers.origin || '').trim();
|
|
1237
|
-
if (requestOrigin && (0, common_1.isAllowedOrigin)(requestOrigin, resolveio_server_app_1.ResolveIOServer.getServerConfig())) {
|
|
1238
|
-
res.setHeader('Access-Control-Allow-Origin', requestOrigin);
|
|
1239
|
-
res.setHeader('Vary', 'Origin');
|
|
1240
|
-
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
1241
|
-
}
|
|
1242
|
-
else {
|
|
1243
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
1244
|
-
res.setHeader('Access-Control-Allow-Credentials', 'false');
|
|
1245
|
-
}
|
|
1246
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
|
|
1247
|
-
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Rio-Token, X-API-Key, X-AI-Coder-App-Token, X-AI-Coder-Session');
|
|
1248
|
-
res.setHeader('Access-Control-Allow-Private-Network', 'true');
|
|
1249
|
-
if (isCorsPreflightRequest(req)) {
|
|
1250
|
-
res.status(204).end();
|
|
1251
|
-
return;
|
|
1252
|
-
}
|
|
1253
|
-
next();
|
|
1254
|
-
});
|
|
1255
|
-
if (this.LOGGER === 'DEBUG') {
|
|
1256
|
-
console.log('Setup cors');
|
|
1257
|
-
}
|
|
1258
|
-
this.installDynamicAppGatewayMiddleware();
|
|
1259
|
-
// Set up http login route
|
|
1260
|
-
(0, auth_1.setupAuthRoutes)(this, this._app, resolveio_server_app_1.ResolveIOServer.getServerConfig());
|
|
1261
|
-
(0, health_1.setupHealthRoutes)(this._app);
|
|
1262
|
-
(0, slow_query_publication_1.setupSlowQueryPublicationRoutes)(this._app);
|
|
1263
|
-
if (resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'] === 'ResolveIO' || this.publicProgram) {
|
|
1264
|
-
(0, home_1.setupHomeRoutes)(this, this._app, resolveio_server_app_1.ResolveIOServer.getServerConfig());
|
|
1265
|
-
}
|
|
1266
|
-
if (this.LOGGER === 'DEBUG') {
|
|
1267
|
-
console.log('Setup express routes');
|
|
1268
|
-
}
|
|
1269
|
-
};
|
|
1270
|
-
ResolveIOMainServer.prototype.installDynamicAppGatewayMiddleware = function () {
|
|
1271
|
-
var _this = this;
|
|
1272
|
-
if (!this._dynamicAppGatewayEnabled) {
|
|
1273
|
-
return;
|
|
1274
|
-
}
|
|
1275
|
-
this._app.use(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
1276
|
-
var appId, appDoc, allowedHosts, controlHosts, requestHost, originHeader, originHost, expectedToken, providedToken, error_8;
|
|
1277
|
-
var _a, _b, _c;
|
|
1278
|
-
return __generator(this, function (_d) {
|
|
1279
|
-
switch (_d.label) {
|
|
1280
|
-
case 0:
|
|
1281
|
-
appId = this.extractDynamicAppGatewayId(req);
|
|
1282
|
-
if (!appId) {
|
|
1283
|
-
next();
|
|
1284
|
-
return [2 /*return*/];
|
|
1285
|
-
}
|
|
1286
|
-
_d.label = 1;
|
|
1287
|
-
case 1:
|
|
1288
|
-
_d.trys.push([1, 3, , 4]);
|
|
1289
|
-
return [4 /*yield*/, this.resolveCachedDynamicAppGatewayApp(appId)];
|
|
1290
|
-
case 2:
|
|
1291
|
-
appDoc = _d.sent();
|
|
1292
|
-
if (!appDoc) {
|
|
1293
|
-
res.status(404).send(JSON.stringify({
|
|
1294
|
-
error: true,
|
|
1295
|
-
result: 'App not found.'
|
|
1296
|
-
}));
|
|
1297
|
-
return [2 /*return*/];
|
|
1298
|
-
}
|
|
1299
|
-
allowedHosts = this.resolveDynamicAppAllowedHosts(appDoc);
|
|
1300
|
-
controlHosts = this.resolveDynamicAppControlHosts();
|
|
1301
|
-
requestHost = this.normalizeHostname(this.normalizeHeaderValue((_a = req.headers) === null || _a === void 0 ? void 0 : _a['x-forwarded-host'])
|
|
1302
|
-
|| this.normalizeHeaderValue((_b = req.headers) === null || _b === void 0 ? void 0 : _b.host));
|
|
1303
|
-
originHeader = this.normalizeHeaderValue((_c = req.headers) === null || _c === void 0 ? void 0 : _c.origin);
|
|
1304
|
-
originHost = this.resolveOriginHostname(originHeader);
|
|
1305
|
-
if (requestHost && controlHosts.has(requestHost) && !this.isLocalHostname(requestHost)) {
|
|
1306
|
-
res.status(403).send(JSON.stringify({
|
|
1307
|
-
error: true,
|
|
1308
|
-
result: 'App API must be requested from an app domain.'
|
|
1309
|
-
}));
|
|
1310
|
-
return [2 /*return*/];
|
|
1311
|
-
}
|
|
1312
|
-
if (requestHost && !allowedHosts.has(requestHost) && !this.isLocalHostname(requestHost)) {
|
|
1313
|
-
res.status(403).send(JSON.stringify({
|
|
1314
|
-
error: true,
|
|
1315
|
-
result: 'Host not allowed for app API.'
|
|
1316
|
-
}));
|
|
1317
|
-
return [2 /*return*/];
|
|
1318
|
-
}
|
|
1319
|
-
if (originHost && controlHosts.has(originHost) && !this.isLocalHostname(originHost)) {
|
|
1320
|
-
res.status(403).send(JSON.stringify({
|
|
1321
|
-
error: true,
|
|
1322
|
-
result: 'App API origin must be an app domain.'
|
|
1323
|
-
}));
|
|
1324
|
-
return [2 /*return*/];
|
|
1325
|
-
}
|
|
1326
|
-
if (originHost && !allowedHosts.has(originHost)) {
|
|
1327
|
-
res.status(403).send(JSON.stringify({
|
|
1328
|
-
error: true,
|
|
1329
|
-
result: 'Origin not allowed for app API.'
|
|
1330
|
-
}));
|
|
1331
|
-
return [2 /*return*/];
|
|
1332
|
-
}
|
|
1333
|
-
if (originHeader) {
|
|
1334
|
-
this.applyDynamicAppGatewayCorsHeaders(res, originHeader);
|
|
1335
|
-
}
|
|
1336
|
-
if (isCorsPreflightRequest(req)) {
|
|
1337
|
-
res.status(204).end();
|
|
1338
|
-
return [2 /*return*/];
|
|
1339
|
-
}
|
|
1340
|
-
expectedToken = this.normalizeHeaderValue(appDoc === null || appDoc === void 0 ? void 0 : appDoc.rio_token);
|
|
1341
|
-
if (!expectedToken) {
|
|
1342
|
-
res.status(500).send(JSON.stringify({
|
|
1343
|
-
error: true,
|
|
1344
|
-
result: 'App token is not configured.'
|
|
1345
|
-
}));
|
|
1346
|
-
return [2 /*return*/];
|
|
1347
|
-
}
|
|
1348
|
-
providedToken = this.resolveDynamicAppGatewayToken(req);
|
|
1349
|
-
if (!providedToken || providedToken !== expectedToken) {
|
|
1350
|
-
res.status(401).send(JSON.stringify({
|
|
1351
|
-
error: true,
|
|
1352
|
-
result: 'Invalid or missing RIO token.'
|
|
1353
|
-
}));
|
|
1354
|
-
return [2 /*return*/];
|
|
1355
|
-
}
|
|
1356
|
-
next();
|
|
1357
|
-
return [3 /*break*/, 4];
|
|
1358
|
-
case 3:
|
|
1359
|
-
error_8 = _d.sent();
|
|
1360
|
-
console.error(new Date(), '[DynamicAppGateway] middleware failure', error_8);
|
|
1361
|
-
res.status(500).send(JSON.stringify({
|
|
1362
|
-
error: true,
|
|
1363
|
-
result: (error_8 === null || error_8 === void 0 ? void 0 : error_8.message) || 'Dynamic app gateway error.'
|
|
1364
|
-
}));
|
|
1365
|
-
return [3 /*break*/, 4];
|
|
1366
|
-
case 4: return [2 /*return*/];
|
|
1367
|
-
}
|
|
1368
|
-
});
|
|
1369
|
-
}); });
|
|
1370
|
-
};
|
|
1371
|
-
ResolveIOMainServer.prototype.resolveDynamicAppGatewayEnabled = function () {
|
|
1372
|
-
var _a;
|
|
1373
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
1374
|
-
var raw = (_a = config['AI_CODER_DYNAMIC_APP_GATEWAY']) !== null && _a !== void 0 ? _a : process.env.AI_CODER_DYNAMIC_APP_GATEWAY;
|
|
1375
|
-
if (raw !== undefined && raw !== null && "".concat(raw).trim() !== '') {
|
|
1376
|
-
return this.parseDebugFlag(raw);
|
|
1377
|
-
}
|
|
1378
|
-
var urls = [
|
|
1379
|
-
config['ROOT_URL'],
|
|
1380
|
-
config['SEC_ROOT_URL'],
|
|
1381
|
-
config['SERVER_URL'],
|
|
1382
|
-
process.env.ROOT_URL,
|
|
1383
|
-
process.env.SEC_ROOT_URL,
|
|
1384
|
-
process.env.SERVER_URL
|
|
1385
|
-
]
|
|
1386
|
-
.map(function (value) { return "".concat(value || '').trim().toLowerCase(); })
|
|
1387
|
-
.filter(Boolean);
|
|
1388
|
-
return urls.some(function (value) { return value.includes('aicoder'); });
|
|
1389
|
-
};
|
|
1390
|
-
ResolveIOMainServer.prototype.extractDynamicAppGatewayId = function (req) {
|
|
1391
|
-
var rawPath = "".concat(req.originalUrl || req.url || req.path || '');
|
|
1392
|
-
var normalizedPath = rawPath.split('?')[0];
|
|
1393
|
-
if (!normalizedPath.startsWith('/api/apps/')) {
|
|
1394
|
-
return '';
|
|
1395
|
-
}
|
|
1396
|
-
var parts = normalizedPath.split('/').filter(Boolean);
|
|
1397
|
-
if (parts.length < 3) {
|
|
1398
|
-
return '';
|
|
1399
|
-
}
|
|
1400
|
-
return "".concat(parts[2] || '').trim();
|
|
1401
|
-
};
|
|
1402
|
-
ResolveIOMainServer.prototype.resolveDynamicAppGatewayToken = function (req) {
|
|
1403
|
-
var e_7, _a, e_8, _b, e_9, _c;
|
|
1404
|
-
var _d, _e, _f, _g, _h;
|
|
1405
|
-
var authHeader = this.normalizeHeaderValue(((_d = req.headers) === null || _d === void 0 ? void 0 : _d.authorization) || ((_e = req.headers) === null || _e === void 0 ? void 0 : _e.Authorization));
|
|
1406
|
-
if (authHeader) {
|
|
1407
|
-
var bearerMatch = authHeader.match(/^bearer\s+(.+)$/i);
|
|
1408
|
-
if (bearerMatch && bearerMatch[1]) {
|
|
1409
|
-
return bearerMatch[1].trim();
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
var headerCandidates = [
|
|
1413
|
-
(_f = req.headers) === null || _f === void 0 ? void 0 : _f['x-rio-token'],
|
|
1414
|
-
(_g = req.headers) === null || _g === void 0 ? void 0 : _g['x-app-token'],
|
|
1415
|
-
(_h = req.headers) === null || _h === void 0 ? void 0 : _h['x-api-key']
|
|
1416
|
-
];
|
|
1417
|
-
try {
|
|
1418
|
-
for (var headerCandidates_1 = __values(headerCandidates), headerCandidates_1_1 = headerCandidates_1.next(); !headerCandidates_1_1.done; headerCandidates_1_1 = headerCandidates_1.next()) {
|
|
1419
|
-
var candidate = headerCandidates_1_1.value;
|
|
1420
|
-
var value = this.normalizeHeaderValue(candidate);
|
|
1421
|
-
if (value) {
|
|
1422
|
-
return value;
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1427
|
-
finally {
|
|
1428
|
-
try {
|
|
1429
|
-
if (headerCandidates_1_1 && !headerCandidates_1_1.done && (_a = headerCandidates_1.return)) _a.call(headerCandidates_1);
|
|
1430
|
-
}
|
|
1431
|
-
finally { if (e_7) throw e_7.error; }
|
|
1432
|
-
}
|
|
1433
|
-
var body = req.body || {};
|
|
1434
|
-
var query = req.query || {};
|
|
1435
|
-
var bodyCandidates = [body.rioToken, body.rio_token, body.apiKey, body.token];
|
|
1436
|
-
try {
|
|
1437
|
-
for (var bodyCandidates_1 = __values(bodyCandidates), bodyCandidates_1_1 = bodyCandidates_1.next(); !bodyCandidates_1_1.done; bodyCandidates_1_1 = bodyCandidates_1.next()) {
|
|
1438
|
-
var candidate = bodyCandidates_1_1.value;
|
|
1439
|
-
var value = this.normalizeHeaderValue(candidate);
|
|
1440
|
-
if (value) {
|
|
1441
|
-
return value;
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
1446
|
-
finally {
|
|
1447
|
-
try {
|
|
1448
|
-
if (bodyCandidates_1_1 && !bodyCandidates_1_1.done && (_b = bodyCandidates_1.return)) _b.call(bodyCandidates_1);
|
|
1449
|
-
}
|
|
1450
|
-
finally { if (e_8) throw e_8.error; }
|
|
1451
|
-
}
|
|
1452
|
-
var queryCandidates = [query.rioToken, query.rio_token, query.apiKey, query.token];
|
|
1453
|
-
try {
|
|
1454
|
-
for (var queryCandidates_1 = __values(queryCandidates), queryCandidates_1_1 = queryCandidates_1.next(); !queryCandidates_1_1.done; queryCandidates_1_1 = queryCandidates_1.next()) {
|
|
1455
|
-
var candidate = queryCandidates_1_1.value;
|
|
1456
|
-
var value = this.normalizeHeaderValue(candidate);
|
|
1457
|
-
if (value) {
|
|
1458
|
-
return value;
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
1463
|
-
finally {
|
|
1464
|
-
try {
|
|
1465
|
-
if (queryCandidates_1_1 && !queryCandidates_1_1.done && (_c = queryCandidates_1.return)) _c.call(queryCandidates_1);
|
|
1466
|
-
}
|
|
1467
|
-
finally { if (e_9) throw e_9.error; }
|
|
1468
|
-
}
|
|
1469
|
-
return '';
|
|
1470
|
-
};
|
|
1471
|
-
ResolveIOMainServer.prototype.normalizeHeaderValue = function (value) {
|
|
1472
|
-
if (Array.isArray(value)) {
|
|
1473
|
-
return value.map(function (entry) { return "".concat(entry || '').trim(); }).filter(Boolean).join(',');
|
|
1474
|
-
}
|
|
1475
|
-
return "".concat(value || '').trim();
|
|
1476
|
-
};
|
|
1477
|
-
ResolveIOMainServer.prototype.normalizeHostname = function (value) {
|
|
1478
|
-
var raw = "".concat(value || '').trim();
|
|
1479
|
-
if (!raw) {
|
|
1480
|
-
return '';
|
|
1481
|
-
}
|
|
1482
|
-
var candidate = raw.split(',')[0].trim();
|
|
1483
|
-
if (!candidate) {
|
|
1484
|
-
return '';
|
|
1485
|
-
}
|
|
1486
|
-
try {
|
|
1487
|
-
if (candidate.startsWith('http://') || candidate.startsWith('https://')) {
|
|
1488
|
-
return new url_1.URL(candidate).hostname.toLowerCase();
|
|
1489
|
-
}
|
|
1490
|
-
if (candidate.includes('/')) {
|
|
1491
|
-
return new url_1.URL("http://".concat(candidate)).hostname.toLowerCase();
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
catch (_a) { }
|
|
1495
|
-
candidate = candidate.replace(/^\[/, '').replace(/\]$/, '');
|
|
1496
|
-
var lastColon = candidate.lastIndexOf(':');
|
|
1497
|
-
if (lastColon > -1 && candidate.indexOf(':') === lastColon) {
|
|
1498
|
-
candidate = candidate.slice(0, lastColon);
|
|
1499
|
-
}
|
|
1500
|
-
return candidate.toLowerCase();
|
|
1501
|
-
};
|
|
1502
|
-
ResolveIOMainServer.prototype.resolveOriginHostname = function (origin) {
|
|
1503
|
-
var raw = "".concat(origin || '').trim();
|
|
1504
|
-
if (!raw) {
|
|
1505
|
-
return '';
|
|
1506
|
-
}
|
|
1507
|
-
try {
|
|
1508
|
-
return new url_1.URL(raw).hostname.toLowerCase();
|
|
1509
|
-
}
|
|
1510
|
-
catch (_a) {
|
|
1511
|
-
return this.normalizeHostname(raw);
|
|
1512
|
-
}
|
|
1513
|
-
};
|
|
1514
|
-
ResolveIOMainServer.prototype.isLocalHostname = function (hostname) {
|
|
1515
|
-
var normalized = this.normalizeHostname(hostname);
|
|
1516
|
-
return normalized === 'localhost' || normalized === '127.0.0.1' || normalized === '::1';
|
|
1517
|
-
};
|
|
1518
|
-
ResolveIOMainServer.prototype.resolveDynamicAppControlHosts = function () {
|
|
1519
|
-
var e_10, _a;
|
|
1520
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
1521
|
-
var hosts = new Set();
|
|
1522
|
-
var candidates = [
|
|
1523
|
-
config['ROOT_URL'],
|
|
1524
|
-
config['SEC_ROOT_URL'],
|
|
1525
|
-
config['SERVER_URL'],
|
|
1526
|
-
process.env.ROOT_URL,
|
|
1527
|
-
process.env.SEC_ROOT_URL,
|
|
1528
|
-
process.env.SERVER_URL,
|
|
1529
|
-
process.env.AI_CODER_ROOT_URL,
|
|
1530
|
-
process.env.AI_CODER_SEC_ROOT_URL,
|
|
1531
|
-
process.env.AI_CODER_SERVER_URL
|
|
1532
|
-
];
|
|
1533
|
-
try {
|
|
1534
|
-
for (var candidates_1 = __values(candidates), candidates_1_1 = candidates_1.next(); !candidates_1_1.done; candidates_1_1 = candidates_1.next()) {
|
|
1535
|
-
var candidate = candidates_1_1.value;
|
|
1536
|
-
var normalized = this.normalizeHostname("".concat(candidate || ''));
|
|
1537
|
-
if (normalized) {
|
|
1538
|
-
hosts.add(normalized);
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
1543
|
-
finally {
|
|
1544
|
-
try {
|
|
1545
|
-
if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
|
|
1546
|
-
}
|
|
1547
|
-
finally { if (e_10) throw e_10.error; }
|
|
1548
|
-
}
|
|
1549
|
-
return hosts;
|
|
1550
|
-
};
|
|
1551
|
-
ResolveIOMainServer.prototype.resolveDynamicAppAllowedHosts = function (appDoc) {
|
|
1552
|
-
var e_11, _a;
|
|
1553
|
-
var hosts = new Set();
|
|
1554
|
-
var candidates = [
|
|
1555
|
-
appDoc === null || appDoc === void 0 ? void 0 : appDoc.domain,
|
|
1556
|
-
appDoc === null || appDoc === void 0 ? void 0 : appDoc.backend_domain
|
|
1557
|
-
];
|
|
1558
|
-
if ((appDoc === null || appDoc === void 0 ? void 0 : appDoc.subdomain) && (appDoc === null || appDoc === void 0 ? void 0 : appDoc.domain_base)) {
|
|
1559
|
-
candidates.push("".concat(appDoc.subdomain, ".").concat(appDoc.domain_base));
|
|
1560
|
-
}
|
|
1561
|
-
try {
|
|
1562
|
-
for (var candidates_2 = __values(candidates), candidates_2_1 = candidates_2.next(); !candidates_2_1.done; candidates_2_1 = candidates_2.next()) {
|
|
1563
|
-
var candidate = candidates_2_1.value;
|
|
1564
|
-
var normalized = this.normalizeHostname("".concat(candidate || ''));
|
|
1565
|
-
if (normalized) {
|
|
1566
|
-
hosts.add(normalized);
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1571
|
-
finally {
|
|
1572
|
-
try {
|
|
1573
|
-
if (candidates_2_1 && !candidates_2_1.done && (_a = candidates_2.return)) _a.call(candidates_2);
|
|
1574
|
-
}
|
|
1575
|
-
finally { if (e_11) throw e_11.error; }
|
|
1576
|
-
}
|
|
1577
|
-
return hosts;
|
|
1578
|
-
};
|
|
1579
|
-
ResolveIOMainServer.prototype.applyDynamicAppGatewayCorsHeaders = function (res, origin) {
|
|
1580
|
-
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
1581
|
-
res.setHeader('Vary', 'Origin');
|
|
1582
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
|
|
1583
|
-
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Rio-Token, X-API-Key, X-AI-Coder-App-Token, X-AI-Coder-Session');
|
|
1584
|
-
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
1585
|
-
res.setHeader('Access-Control-Allow-Private-Network', 'true');
|
|
1586
|
-
res.setHeader('Access-Control-Max-Age', '600');
|
|
1587
|
-
};
|
|
1588
|
-
ResolveIOMainServer.prototype.resolveCachedDynamicAppGatewayApp = function (appId) {
|
|
1589
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1590
|
-
var now, cached, db, appCollection, appDoc, generated;
|
|
1591
|
-
return __generator(this, function (_a) {
|
|
1592
|
-
switch (_a.label) {
|
|
1593
|
-
case 0:
|
|
1594
|
-
now = Date.now();
|
|
1595
|
-
cached = this._dynamicAppGatewayCache.get(appId);
|
|
1596
|
-
if (cached && cached.expiresAt > now) {
|
|
1597
|
-
return [2 /*return*/, cached.app];
|
|
1598
|
-
}
|
|
1599
|
-
db = resolveio_server_app_1.ResolveIOServer.getMainDB();
|
|
1600
|
-
if (!db) {
|
|
1601
|
-
return [2 /*return*/, null];
|
|
1602
|
-
}
|
|
1603
|
-
appCollection = db.collection('ai-coder-apps');
|
|
1604
|
-
return [4 /*yield*/, appCollection.findOne({ _id: appId }, {
|
|
1605
|
-
projection: {
|
|
1606
|
-
_id: 1,
|
|
1607
|
-
domain: 1,
|
|
1608
|
-
backend_domain: 1,
|
|
1609
|
-
subdomain: 1,
|
|
1610
|
-
domain_base: 1,
|
|
1611
|
-
rio_token: 1
|
|
1612
|
-
}
|
|
1613
|
-
})];
|
|
1614
|
-
case 1:
|
|
1615
|
-
appDoc = _a.sent();
|
|
1616
|
-
if (!appDoc) {
|
|
1617
|
-
this._dynamicAppGatewayCache.delete(appId);
|
|
1618
|
-
return [2 /*return*/, null];
|
|
1619
|
-
}
|
|
1620
|
-
if (!!this.normalizeHeaderValue(appDoc.rio_token)) return [3 /*break*/, 3];
|
|
1621
|
-
generated = crypto.randomBytes(32).toString('hex');
|
|
1622
|
-
return [4 /*yield*/, appCollection.updateOne({ _id: appId }, {
|
|
1623
|
-
$set: {
|
|
1624
|
-
rio_token: generated,
|
|
1625
|
-
updatedAt: new Date()
|
|
1626
|
-
}
|
|
1627
|
-
})];
|
|
1628
|
-
case 2:
|
|
1629
|
-
_a.sent();
|
|
1630
|
-
appDoc.rio_token = generated;
|
|
1631
|
-
_a.label = 3;
|
|
1632
|
-
case 3:
|
|
1633
|
-
this._dynamicAppGatewayCache.set(appId, {
|
|
1634
|
-
expiresAt: now + this._dynamicAppGatewayCacheMs,
|
|
1635
|
-
app: appDoc
|
|
1636
|
-
});
|
|
1637
|
-
return [2 /*return*/, appDoc];
|
|
1638
|
-
}
|
|
1639
|
-
});
|
|
1640
|
-
});
|
|
1641
|
-
};
|
|
1642
|
-
ResolveIOMainServer.prototype.safeShutdown = function () {
|
|
1643
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1644
|
-
var _a;
|
|
1645
|
-
var _this = this;
|
|
1646
|
-
return __generator(this, function (_b) {
|
|
1647
|
-
switch (_b.label) {
|
|
1648
|
-
case 0:
|
|
1649
|
-
if (!this._safeShutdown) {
|
|
1650
|
-
console.log(new Date(), 'Safe Shutdown Command Received');
|
|
1651
|
-
}
|
|
1652
|
-
if (!(!this._monitorManagerFunction.getActiveMonitorFunctions().length
|
|
1653
|
-
&& !this._offlineUpdates.length && (!this._workerDispatcherManager || this._workerDispatcherManager.isSafeShutdown()))) return [3 /*break*/, 7];
|
|
1654
|
-
if (!resolveio_server_app_1.ResolveIOServer.getMongoConnection()) return [3 /*break*/, 5];
|
|
1655
|
-
_b.label = 1;
|
|
1656
|
-
case 1:
|
|
1657
|
-
_b.trys.push([1, 3, , 4]);
|
|
1658
|
-
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoConnection().close(false)];
|
|
1659
|
-
case 2:
|
|
1660
|
-
_b.sent();
|
|
1661
|
-
console.log(new Date(), 'Safe Exit Complete, Process Exit');
|
|
1662
|
-
process.exit(0);
|
|
1663
|
-
return [3 /*break*/, 4];
|
|
1664
|
-
case 3:
|
|
1665
|
-
_a = _b.sent();
|
|
1666
|
-
process.exit(1);
|
|
1667
|
-
return [3 /*break*/, 4];
|
|
1668
|
-
case 4:
|
|
1669
|
-
;
|
|
1670
|
-
return [3 /*break*/, 6];
|
|
1671
|
-
case 5:
|
|
1672
|
-
process.exit(0);
|
|
1673
|
-
_b.label = 6;
|
|
1674
|
-
case 6: return [3 /*break*/, 8];
|
|
1675
|
-
case 7:
|
|
1676
|
-
if (!this._safeShutdown) {
|
|
1677
|
-
this._safeShutdown = true;
|
|
1678
|
-
setTimeout(function () {
|
|
1679
|
-
_this._safeShutdown = false;
|
|
1680
|
-
}, 1000);
|
|
1681
|
-
console.log(new Date(), 'Safe Exit In Progress', this._monitorManagerFunction.getActiveMonitorFunctions().length, this._offlineUpdates.length);
|
|
1682
|
-
}
|
|
1683
|
-
setImmediate(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1684
|
-
return __generator(this, function (_a) {
|
|
1685
|
-
switch (_a.label) {
|
|
1686
|
-
case 0: return [4 /*yield*/, this.safeShutdown()];
|
|
1687
|
-
case 1:
|
|
1688
|
-
_a.sent();
|
|
1689
|
-
return [2 /*return*/];
|
|
1690
|
-
}
|
|
1691
|
-
});
|
|
1692
|
-
}); });
|
|
1693
|
-
_b.label = 8;
|
|
1694
|
-
case 8: return [2 /*return*/];
|
|
1695
|
-
}
|
|
1696
|
-
});
|
|
1697
|
-
});
|
|
1698
|
-
};
|
|
1699
|
-
ResolveIOMainServer.prototype.getIsWorkersEnabled = function () {
|
|
1700
|
-
return this._isWorkersEnabled;
|
|
1701
|
-
};
|
|
1702
|
-
ResolveIOMainServer.prototype.getIsWorkerInstance = function () {
|
|
1703
|
-
return this._isWorkerInstance;
|
|
1704
|
-
};
|
|
1705
|
-
ResolveIOMainServer.prototype.getWSList = function () {
|
|
1706
|
-
var res = [];
|
|
1707
|
-
this._serverWSS.clients.forEach(function (ws) {
|
|
1708
|
-
res.push(ws['id_socket']);
|
|
1709
|
-
});
|
|
1710
|
-
return res;
|
|
1711
|
-
};
|
|
1712
|
-
ResolveIOMainServer.prototype.getWSUserList = function () {
|
|
1713
|
-
var res = [];
|
|
1714
|
-
this._serverWSS.clients.forEach(function (ws) {
|
|
1715
|
-
res.push(ws['id_user']);
|
|
1716
|
-
});
|
|
1717
|
-
return res;
|
|
1718
|
-
};
|
|
1719
|
-
ResolveIOMainServer.prototype.getHTTPServer = function () {
|
|
1720
|
-
return this._serverHTTP;
|
|
1721
|
-
};
|
|
1722
|
-
ResolveIOMainServer.prototype.getCronManager = function () {
|
|
1723
|
-
return this._cronManager;
|
|
1724
|
-
};
|
|
1725
|
-
ResolveIOMainServer.prototype.reportServerError = function (subject_1, correlationId_1, context_1, meta_1) {
|
|
1726
|
-
return __awaiter(this, arguments, void 0, function (subject, correlationId, context, meta, severity, stackOverride) {
|
|
1727
|
-
var config, metadata;
|
|
1728
|
-
if (severity === void 0) { severity = 'error'; }
|
|
1729
|
-
return __generator(this, function (_a) {
|
|
1730
|
-
switch (_a.label) {
|
|
1731
|
-
case 0:
|
|
1732
|
-
config = resolveio_server_app_1.ResolveIOServer.getServerConfig();
|
|
1733
|
-
metadata = Object.assign({}, meta || {});
|
|
1734
|
-
if (correlationId && !metadata.correlationId) {
|
|
1735
|
-
metadata.correlationId = correlationId;
|
|
1736
|
-
}
|
|
1737
|
-
return [4 /*yield*/, error_reporter_1.ErrorReporter.report({
|
|
1738
|
-
sourceApp: 'server-app',
|
|
1739
|
-
message: subject,
|
|
1740
|
-
environment: (config === null || config === void 0 ? void 0 : config.ROOT_URL) || process.env.NODE_ENV || 'unknown',
|
|
1741
|
-
clientSlug: resolveio_server_app_1.ResolveIOServer.getClientName(),
|
|
1742
|
-
clientName: config === null || config === void 0 ? void 0 : config.CLIENT_NAME,
|
|
1743
|
-
severity: severity,
|
|
1744
|
-
stack: stackOverride || (typeof (context === null || context === void 0 ? void 0 : context.stack) === 'string' ? context.stack : undefined),
|
|
1745
|
-
context: context,
|
|
1746
|
-
metadata: metadata,
|
|
1747
|
-
correlationId: correlationId
|
|
1748
|
-
})];
|
|
1749
|
-
case 1:
|
|
1750
|
-
_a.sent();
|
|
1751
|
-
return [2 /*return*/];
|
|
1752
|
-
}
|
|
1753
|
-
});
|
|
1754
|
-
});
|
|
1755
|
-
};
|
|
1756
|
-
ResolveIOMainServer.prototype.getMethodManager = function () {
|
|
1757
|
-
return this._methodManager;
|
|
1758
|
-
};
|
|
1759
|
-
ResolveIOMainServer.prototype.getSubscriptionManager = function () {
|
|
1760
|
-
return this._subscriptionManager;
|
|
1761
|
-
};
|
|
1762
|
-
ResolveIOMainServer.prototype.getMonitorManager = function () {
|
|
1763
|
-
return this._monitorManager;
|
|
1764
|
-
};
|
|
1765
|
-
ResolveIOMainServer.prototype.getRebootFlag = function () {
|
|
1766
|
-
return this._rebootFlag;
|
|
1767
|
-
};
|
|
1768
|
-
ResolveIOMainServer.prototype.getWebSocketManager = function () {
|
|
1769
|
-
return this._websocketManager;
|
|
1770
|
-
};
|
|
1771
|
-
ResolveIOMainServer.prototype.createServer = function () {
|
|
1772
|
-
var _this = this;
|
|
1773
|
-
this._serverHTTP = (0, http_1.createServer)(this._app);
|
|
1774
|
-
this._serverHTTP.keepAliveTimeout = 65000;
|
|
1775
|
-
this._serverHTTP.headersTimeout = 66000;
|
|
1776
|
-
this._serverWSS = new WebSocket.Server({
|
|
1777
|
-
server: this._serverHTTP,
|
|
1778
|
-
verifyClient: this.publicProgram ? null : function (info, cb) {
|
|
1779
|
-
if (_this._rebootFlag) {
|
|
1780
|
-
cb(false, 409, 'Unable To Process');
|
|
1781
|
-
}
|
|
1782
|
-
else {
|
|
1783
|
-
if (_this.LOGGER === 'DEBUG') {
|
|
1784
|
-
console.log('Verify Client', info, cb);
|
|
1785
|
-
}
|
|
1786
|
-
// If it's a worker, we might skip token checks or do a simple check:
|
|
1787
|
-
if (info.req.url && info.req.url.includes('workerToken=')) {
|
|
1788
|
-
var requestUrl = void 0;
|
|
1789
|
-
var rootUrl = resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] || 'http://localhost';
|
|
1790
|
-
try {
|
|
1791
|
-
requestUrl = new url_1.URL(info.req.url, rootUrl);
|
|
1792
|
-
}
|
|
1793
|
-
catch (_a) {
|
|
1794
|
-
cb(false, 400, 'Bad Request');
|
|
1795
|
-
return;
|
|
1796
|
-
}
|
|
1797
|
-
var workerToken = requestUrl.searchParams.get('workerToken') || '';
|
|
1798
|
-
var workerIndex = _this.normalizeWorkerSelectorValue(requestUrl.searchParams.get('workerIndex'));
|
|
1799
|
-
var workerInstance = _this.normalizeWorkerSelectorValue(requestUrl.searchParams.get('workerInstance'));
|
|
1800
|
-
var expectedWorkerToken = String(resolveio_server_app_1.ResolveIOServer.getServerConfig()['WORKER_TOKEN'] || '');
|
|
1801
|
-
if (!workerIndex || !workerInstance) {
|
|
1802
|
-
cb(false, 400, 'Missing worker identity');
|
|
1803
|
-
return;
|
|
1804
|
-
}
|
|
1805
|
-
if (workerToken === expectedWorkerToken) {
|
|
1806
|
-
info.req['workerIndex'] = workerIndex;
|
|
1807
|
-
info.req['workerInstance'] = workerInstance;
|
|
1808
|
-
cb(true);
|
|
1809
|
-
}
|
|
1810
|
-
else {
|
|
1811
|
-
cb(false, 401, 'Unauthorized');
|
|
1812
|
-
}
|
|
1813
|
-
return;
|
|
1814
|
-
}
|
|
1815
|
-
var protocolsHeader = info.req.headers['sec-websocket-protocol'];
|
|
1816
|
-
if (!protocolsHeader || typeof protocolsHeader !== 'string') {
|
|
1817
|
-
cb(false, 401, 'Unauthorized');
|
|
1818
|
-
return;
|
|
1819
|
-
}
|
|
1820
|
-
var infoData = protocolsHeader.split(/,/);
|
|
1821
|
-
if (!(0, common_1.isAllowedOrigin)(info.origin, resolveio_server_app_1.ResolveIOServer.getServerConfig())) {
|
|
1822
|
-
cb(false, 401, 'Unauthorized');
|
|
1823
|
-
}
|
|
1824
|
-
else {
|
|
1825
|
-
var token = infoData[0];
|
|
1826
|
-
if (!token) {
|
|
1827
|
-
cb(false, 401, 'Unauthorized');
|
|
1828
|
-
}
|
|
1829
|
-
else {
|
|
1830
|
-
jwt.verify(token, resolveio_server_app_1.ResolveIOServer.getServerConfig()['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
|
|
1831
|
-
var user, socketAdmission, _a;
|
|
1832
|
-
return __generator(this, function (_b) {
|
|
1833
|
-
switch (_b.label) {
|
|
1834
|
-
case 0:
|
|
1835
|
-
if (!err) return [3 /*break*/, 1];
|
|
1836
|
-
cb(false, 401, 'Unauthorized');
|
|
1837
|
-
return [3 /*break*/, 8];
|
|
1838
|
-
case 1:
|
|
1839
|
-
info.req['id_user'] = decoded['id_user'];
|
|
1840
|
-
_b.label = 2;
|
|
1841
|
-
case 2:
|
|
1842
|
-
_b.trys.push([2, 7, , 8]);
|
|
1843
|
-
return [4 /*yield*/, user_collection_1.Users.findById(decoded['id_user'])];
|
|
1844
|
-
case 3:
|
|
1845
|
-
user = _b.sent();
|
|
1846
|
-
if (!user) return [3 /*break*/, 5];
|
|
1847
|
-
return [4 /*yield*/, this.evaluateClientSocketAdmission(decoded['id_user'], info.req)];
|
|
1848
|
-
case 4:
|
|
1849
|
-
socketAdmission = _b.sent();
|
|
1850
|
-
if (!socketAdmission.allowed) {
|
|
1851
|
-
cb(false, socketAdmission.statusCode, socketAdmission.message || 'Socket connection rejected.');
|
|
1852
|
-
return [2 /*return*/];
|
|
1853
|
-
}
|
|
1854
|
-
info.req['user'] = user.fullname;
|
|
1855
|
-
info.req['user_readonly'] = user.readonly || false;
|
|
1856
|
-
info.req['doc_user'] = user;
|
|
1857
|
-
info.req['client_ip'] = socketAdmission.clientIp;
|
|
1858
|
-
cb(true);
|
|
1859
|
-
return [3 /*break*/, 6];
|
|
1860
|
-
case 5:
|
|
1861
|
-
cb(false);
|
|
1862
|
-
_b.label = 6;
|
|
1863
|
-
case 6: return [3 /*break*/, 8];
|
|
1864
|
-
case 7:
|
|
1865
|
-
_a = _b.sent();
|
|
1866
|
-
cb(false);
|
|
1867
|
-
return [3 /*break*/, 8];
|
|
1868
|
-
case 8: return [2 /*return*/];
|
|
1869
|
-
}
|
|
1870
|
-
});
|
|
1871
|
-
}); });
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
});
|
|
1877
|
-
};
|
|
1878
|
-
/**
|
|
1879
|
-
* Listen for connections from clients or workers.
|
|
1880
|
-
*/
|
|
1881
|
-
ResolveIOMainServer.prototype.listen = function () {
|
|
1882
|
-
var _this = this;
|
|
1883
|
-
var host = process.env.RESOLVEIO_BIND_HOST || '127.0.0.1';
|
|
1884
|
-
this._serverHTTP.listen(this._portHTTP, host, function () {
|
|
1885
|
-
console.log('Running HTTP/WS server on port %s', _this._portHTTP);
|
|
1886
|
-
});
|
|
1887
|
-
this._serverWSS.on('connection', function (ws, req) { return __awaiter(_this, void 0, void 0, function () {
|
|
1888
|
-
var workerId_1, workerIndex, workerInstance, rootUrl, requestUrl, workerIndexForLog, workerInstanceForLog, interval_1, lastComm_1, missedPongs_1, heartbeatIntervalMs, maxMissedPongs_1, maxSilenceMs_1, socketAdmission, socketPolicyError_1;
|
|
1889
|
-
var _this = this;
|
|
1890
|
-
var _a;
|
|
1891
|
-
return __generator(this, function (_b) {
|
|
1892
|
-
switch (_b.label) {
|
|
1893
|
-
case 0:
|
|
1894
|
-
if (!(req.url && req.url.includes('workerToken='))) return [3 /*break*/, 1];
|
|
1895
|
-
workerId_1 = (0, common_1.objectIdHexString)();
|
|
1896
|
-
ws['id_worker'] = workerId_1;
|
|
1897
|
-
workerIndex = null;
|
|
1898
|
-
workerInstance = null;
|
|
1899
|
-
ws['supportsBinary'] = true;
|
|
1900
|
-
if (req.url) {
|
|
1901
|
-
rootUrl = resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] || 'http://localhost';
|
|
1902
|
-
try {
|
|
1903
|
-
requestUrl = new url_1.URL(req.url, rootUrl);
|
|
1904
|
-
workerIndex = requestUrl.searchParams.get('workerIndex');
|
|
1905
|
-
workerInstance = requestUrl.searchParams.get('workerInstance');
|
|
1906
|
-
}
|
|
1907
|
-
catch (_c) {
|
|
1908
|
-
workerIndex = null;
|
|
1909
|
-
workerInstance = null;
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
if (!workerIndex && req['workerIndex']) {
|
|
1913
|
-
workerIndex = req['workerIndex'];
|
|
1914
|
-
}
|
|
1915
|
-
if (!workerInstance && req['workerInstance']) {
|
|
1916
|
-
workerInstance = req['workerInstance'];
|
|
1917
|
-
}
|
|
1918
|
-
workerIndex = this.normalizeWorkerSelectorValue(workerIndex);
|
|
1919
|
-
workerInstance = this.normalizeWorkerSelectorValue(workerInstance);
|
|
1920
|
-
if (!workerIndex || !workerInstance) {
|
|
1921
|
-
console.warn(new Date(), 'Rejected worker connection with missing identity', {
|
|
1922
|
-
workerId: workerId_1,
|
|
1923
|
-
workerIndex: workerIndex || null,
|
|
1924
|
-
workerInstance: workerInstance || null
|
|
1925
|
-
});
|
|
1926
|
-
ws.close(1008, 'Missing worker identity');
|
|
1927
|
-
return [2 /*return*/];
|
|
1928
|
-
}
|
|
1929
|
-
ws['workerIndex'] = workerIndex;
|
|
1930
|
-
ws['workerInstance'] = workerInstance;
|
|
1931
|
-
workerIndexForLog = ws['workerIndex'] || 'UNKNOWN';
|
|
1932
|
-
workerInstanceForLog = ws['workerInstance'] || 'UNKNOWN';
|
|
1933
|
-
console.log(new Date(), 'Worker Connected', workerIndexForLog, workerInstanceForLog);
|
|
1934
|
-
this._workerDispatcherManager.addWorker(ws);
|
|
1935
|
-
interval_1 = null;
|
|
1936
|
-
lastComm_1 = new Date();
|
|
1937
|
-
missedPongs_1 = 0;
|
|
1938
|
-
heartbeatIntervalMs = 30000;
|
|
1939
|
-
maxMissedPongs_1 = 2;
|
|
1940
|
-
maxSilenceMs_1 = heartbeatIntervalMs * (maxMissedPongs_1 + 1);
|
|
1941
|
-
this._workerDispatcherManager.sendWorkerPayload(ws, 'ping');
|
|
1942
|
-
interval_1 = setInterval(function () {
|
|
1943
|
-
var now = Date.now();
|
|
1944
|
-
var last = lastComm_1 ? lastComm_1.getTime() : 0;
|
|
1945
|
-
var silenceMs = last ? now - last : maxSilenceMs_1 + 1;
|
|
1946
|
-
if (silenceMs > maxSilenceMs_1 || missedPongs_1 > maxMissedPongs_1) {
|
|
1947
|
-
_this._workerDispatcherManager.disconnectWorker(ws['id_worker']);
|
|
1948
|
-
ws.close();
|
|
1949
|
-
return;
|
|
1950
|
-
}
|
|
1951
|
-
missedPongs_1 += 1;
|
|
1952
|
-
_this._workerDispatcherManager.sendWorkerPayload(ws, 'ping');
|
|
1953
|
-
}, heartbeatIntervalMs);
|
|
1954
|
-
ws.on('message', function (message) {
|
|
1955
|
-
lastComm_1 = new Date();
|
|
1956
|
-
if (typeof message === 'string') {
|
|
1957
|
-
if (message === 'ping') {
|
|
1958
|
-
_this._workerDispatcherManager.sendWorkerPayload(ws, 'pong');
|
|
1959
|
-
}
|
|
1960
|
-
else if (message === 'pong') {
|
|
1961
|
-
missedPongs_1 = 0;
|
|
1962
|
-
}
|
|
1963
|
-
else {
|
|
1964
|
-
_this._workerDispatcherManager.handleWorkerMessage(ws['id_worker'], message);
|
|
1965
|
-
}
|
|
1966
|
-
return;
|
|
1967
|
-
}
|
|
1968
|
-
var buffer;
|
|
1969
|
-
if (Buffer.isBuffer(message)) {
|
|
1970
|
-
buffer = message;
|
|
1971
|
-
}
|
|
1972
|
-
else if (Array.isArray(message)) {
|
|
1973
|
-
var chunks = message;
|
|
1974
|
-
buffer = Buffer.concat(chunks);
|
|
1975
|
-
}
|
|
1976
|
-
else if (message instanceof ArrayBuffer) {
|
|
1977
|
-
buffer = Buffer.from(message);
|
|
1978
|
-
}
|
|
1979
|
-
else if (ArrayBuffer.isView(message)) {
|
|
1980
|
-
var view = message;
|
|
1981
|
-
buffer = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
1982
|
-
}
|
|
1983
|
-
else {
|
|
1984
|
-
buffer = Buffer.from(message);
|
|
1985
|
-
}
|
|
1986
|
-
if (buffer.length === 4) {
|
|
1987
|
-
var heartbeat = buffer.toString('utf8');
|
|
1988
|
-
if (heartbeat === 'ping') {
|
|
1989
|
-
_this._workerDispatcherManager.sendWorkerPayload(ws, 'pong');
|
|
1990
|
-
return;
|
|
1991
|
-
}
|
|
1992
|
-
else if (heartbeat === 'pong') {
|
|
1993
|
-
missedPongs_1 = 0;
|
|
1994
|
-
return;
|
|
1995
|
-
}
|
|
1996
|
-
}
|
|
1997
|
-
_this._workerDispatcherManager.handleWorkerMessage(ws['id_worker'], buffer);
|
|
1998
|
-
});
|
|
1999
|
-
ws.on('close', function () {
|
|
2000
|
-
_this._workerDispatcherManager.disconnectWorker(ws['id_worker']);
|
|
2001
|
-
console.log(new Date(), 'Worker disconnected:', workerId_1);
|
|
2002
|
-
if (interval_1) {
|
|
2003
|
-
clearInterval(interval_1);
|
|
2004
|
-
}
|
|
2005
|
-
});
|
|
2006
|
-
ws.on('error', function (error) {
|
|
2007
|
-
_this._workerDispatcherManager.disconnectWorker(ws['id_worker']);
|
|
2008
|
-
console.error('Error on WS Worker', error);
|
|
2009
|
-
ws.close();
|
|
2010
|
-
});
|
|
2011
|
-
return [3 /*break*/, 6];
|
|
2012
|
-
case 1:
|
|
2013
|
-
// Normal client
|
|
2014
|
-
ws['id_socket'] = (0, common_1.objectIdHexString)();
|
|
2015
|
-
ws['supportsBinary'] = true;
|
|
2016
|
-
ws['id_user'] = req['id_user'];
|
|
2017
|
-
ws['user'] = req['user'];
|
|
2018
|
-
ws['user_readonly'] = req['user_readonly'];
|
|
2019
|
-
ws['doc_user'] = req['doc_user'];
|
|
2020
|
-
ws['client_ip'] = this.resolveClientIp(req);
|
|
2021
|
-
socketAdmission = void 0;
|
|
2022
|
-
_b.label = 2;
|
|
2023
|
-
case 2:
|
|
2024
|
-
_b.trys.push([2, 4, , 5]);
|
|
2025
|
-
return [4 /*yield*/, this.evaluateClientSocketAdmission(ws['id_user'], req)];
|
|
2026
|
-
case 3:
|
|
2027
|
-
socketAdmission = _b.sent();
|
|
2028
|
-
return [3 /*break*/, 5];
|
|
2029
|
-
case 4:
|
|
2030
|
-
socketPolicyError_1 = _b.sent();
|
|
2031
|
-
this.logConnectDebug('WS socket policy evaluation failed', {
|
|
2032
|
-
id_socket: ws['id_socket'],
|
|
2033
|
-
id_user: ws['id_user'],
|
|
2034
|
-
user: ws['user'],
|
|
2035
|
-
ip: ws['client_ip'],
|
|
2036
|
-
error: (socketPolicyError_1 === null || socketPolicyError_1 === void 0 ? void 0 : socketPolicyError_1.message) || socketPolicyError_1
|
|
2037
|
-
});
|
|
2038
|
-
try {
|
|
2039
|
-
ws.close(1011, 'Socket policy error');
|
|
2040
|
-
}
|
|
2041
|
-
catch (_d) { }
|
|
2042
|
-
return [2 /*return*/];
|
|
2043
|
-
case 5:
|
|
2044
|
-
if (!socketAdmission.allowed) {
|
|
2045
|
-
this.logConnectDebug('WS client rejected', {
|
|
2046
|
-
id_socket: ws['id_socket'],
|
|
2047
|
-
id_user: ws['id_user'],
|
|
2048
|
-
user: ws['user'],
|
|
2049
|
-
ip: ws['client_ip'],
|
|
2050
|
-
reason: socketAdmission.message
|
|
2051
|
-
});
|
|
2052
|
-
try {
|
|
2053
|
-
ws.close(1008, this.buildSocketLimitCloseReason());
|
|
2054
|
-
}
|
|
2055
|
-
catch (_e) { }
|
|
2056
|
-
return [2 /*return*/];
|
|
2057
|
-
}
|
|
2058
|
-
ws['client_ip'] = socketAdmission.clientIp || ws['client_ip'];
|
|
2059
|
-
this._websocketManager.addWebSocket(ws);
|
|
2060
|
-
this.logConnectDebug('WS client connected', {
|
|
2061
|
-
id_socket: ws['id_socket'],
|
|
2062
|
-
id_user: ws['id_user'],
|
|
2063
|
-
user: ws['user'],
|
|
2064
|
-
url: req === null || req === void 0 ? void 0 : req.url,
|
|
2065
|
-
ip: ws['client_ip'],
|
|
2066
|
-
origin: (_a = req === null || req === void 0 ? void 0 : req.headers) === null || _a === void 0 ? void 0 : _a.origin
|
|
2067
|
-
});
|
|
2068
|
-
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2069
|
-
return __generator(this, function (_a) {
|
|
2070
|
-
switch (_a.label) {
|
|
2071
|
-
case 0: return [4 /*yield*/, this.triggerClientHeartbeat(ws)];
|
|
2072
|
-
case 1:
|
|
2073
|
-
_a.sent();
|
|
2074
|
-
return [2 /*return*/];
|
|
2075
|
-
}
|
|
2076
|
-
});
|
|
2077
|
-
}); }, this._clientHeartbeatInitialDelayMs);
|
|
2078
|
-
if (this.LOGGER === 'DEBUG') {
|
|
2079
|
-
console.log('Connection from user: ' + req['user']);
|
|
2080
|
-
}
|
|
2081
|
-
ws['isAlive'] = true;
|
|
2082
|
-
ws['retryCnt'] = 0;
|
|
2083
|
-
ws.on('pong', function () {
|
|
2084
|
-
ws['isAlive'] = true;
|
|
2085
|
-
ws['pongTime'] = new Date();
|
|
2086
|
-
if (ws['pingTime']) {
|
|
2087
|
-
ws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();
|
|
2088
|
-
_this._subscriptionManager.loggedInLatency(ws);
|
|
2089
|
-
}
|
|
2090
|
-
});
|
|
2091
|
-
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
2092
|
-
var socketData, usedBinary, bufferPayload, decodeResult, decodeResult, decodeResult, view, decodeResult, e_12, correlationId, context;
|
|
2093
|
-
return __generator(this, function (_a) {
|
|
2094
|
-
switch (_a.label) {
|
|
2095
|
-
case 0:
|
|
2096
|
-
this._debugMsgRecv += 1;
|
|
2097
|
-
socketData = [];
|
|
2098
|
-
usedBinary = false;
|
|
2099
|
-
_a.label = 1;
|
|
2100
|
-
case 1:
|
|
2101
|
-
_a.trys.push([1, 2, , 4]);
|
|
2102
|
-
if (typeof message === 'string') {
|
|
2103
|
-
if (message === 'ping' || message === 'pong') {
|
|
2104
|
-
socketData = message;
|
|
2105
|
-
}
|
|
2106
|
-
else {
|
|
2107
|
-
socketData = JSON.parse(message, common_1.dateReviver);
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
else if (Buffer.isBuffer(message)) {
|
|
2111
|
-
bufferPayload = message;
|
|
2112
|
-
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
2113
|
-
socketData = decodeResult.data;
|
|
2114
|
-
usedBinary = decodeResult.usedBinary;
|
|
2115
|
-
}
|
|
2116
|
-
else if (Array.isArray(message)) {
|
|
2117
|
-
bufferPayload = Buffer.concat(message);
|
|
2118
|
-
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
2119
|
-
socketData = decodeResult.data;
|
|
2120
|
-
usedBinary = decodeResult.usedBinary;
|
|
2121
|
-
}
|
|
2122
|
-
else if (message instanceof ArrayBuffer) {
|
|
2123
|
-
bufferPayload = Buffer.from(message);
|
|
2124
|
-
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
2125
|
-
socketData = decodeResult.data;
|
|
2126
|
-
usedBinary = decodeResult.usedBinary;
|
|
2127
|
-
}
|
|
2128
|
-
else if (ArrayBuffer.isView(message)) {
|
|
2129
|
-
view = message;
|
|
2130
|
-
bufferPayload = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
2131
|
-
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
2132
|
-
socketData = decodeResult.data;
|
|
2133
|
-
usedBinary = decodeResult.usedBinary;
|
|
2134
|
-
}
|
|
2135
|
-
else {
|
|
2136
|
-
throw new Error('Unsupported WebSocket message type: ' + typeof message);
|
|
2137
|
-
}
|
|
2138
|
-
return [3 /*break*/, 4];
|
|
2139
|
-
case 2:
|
|
2140
|
-
e_12 = _a.sent();
|
|
2141
|
-
console.log('Error - WS message parse', e_12);
|
|
2142
|
-
correlationId = (0, common_1.objectIdHexString)();
|
|
2143
|
-
context = {
|
|
2144
|
-
rawBinary: bufferPayload ? bufferPayload.toString('base64') : undefined,
|
|
2145
|
-
rawMessage: typeof message === 'string' ? message : undefined,
|
|
2146
|
-
error: e_12 instanceof Error ? { name: e_12.name, message: e_12.message, stack: e_12.stack } : e_12
|
|
2147
|
-
};
|
|
2148
|
-
return [4 /*yield*/, this.reportServerError('SERVER - JSON Parse Error - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, context, { context: 'websocket-message-parse' }, 'error', e_12 instanceof Error ? e_12.stack : undefined)];
|
|
2149
|
-
case 3:
|
|
2150
|
-
_a.sent();
|
|
2151
|
-
return [2 /*return*/];
|
|
2152
|
-
case 4:
|
|
2153
|
-
if (usedBinary) {
|
|
2154
|
-
ws['supportsBinary'] = true;
|
|
2155
|
-
}
|
|
2156
|
-
// call our existing processSocketMessage
|
|
2157
|
-
return [4 /*yield*/, this.processSocketMessage(ws, socketData)];
|
|
2158
|
-
case 5:
|
|
2159
|
-
// call our existing processSocketMessage
|
|
2160
|
-
_a.sent();
|
|
2161
|
-
return [2 /*return*/];
|
|
2162
|
-
}
|
|
2163
|
-
});
|
|
2164
|
-
}); })
|
|
2165
|
-
.on('end', function () {
|
|
2166
|
-
ws.close();
|
|
2167
|
-
})
|
|
2168
|
-
.on('error', function () {
|
|
2169
|
-
ws.close();
|
|
2170
|
-
})
|
|
2171
|
-
.on('close', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2172
|
-
return __generator(this, function (_a) {
|
|
2173
|
-
switch (_a.label) {
|
|
2174
|
-
case 0:
|
|
2175
|
-
this.logConnectDebug('WS client closed', {
|
|
2176
|
-
id_socket: ws['id_socket'],
|
|
2177
|
-
id_user: ws['id_user'],
|
|
2178
|
-
user: ws['user']
|
|
2179
|
-
});
|
|
2180
|
-
return [4 /*yield*/, this.unsubscribeWS(ws)];
|
|
2181
|
-
case 1:
|
|
2182
|
-
_a.sent();
|
|
2183
|
-
return [2 /*return*/];
|
|
2184
|
-
}
|
|
2185
|
-
});
|
|
2186
|
-
}); });
|
|
2187
|
-
// Do not block message handler registration on DB write; this avoids losing
|
|
2188
|
-
// very-early subscription messages sent immediately after websocket open.
|
|
2189
|
-
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2190
|
-
var error_9;
|
|
2191
|
-
return __generator(this, function (_a) {
|
|
2192
|
-
switch (_a.label) {
|
|
2193
|
-
case 0:
|
|
2194
|
-
_a.trys.push([0, 2, , 3]);
|
|
2195
|
-
return [4 /*yield*/, this._subscriptionManager.createLoggedInUser(ws['id_socket'])];
|
|
2196
|
-
case 1:
|
|
2197
|
-
_a.sent();
|
|
2198
|
-
return [3 /*break*/, 3];
|
|
2199
|
-
case 2:
|
|
2200
|
-
error_9 = _a.sent();
|
|
2201
|
-
console.error(new Date(), 'Error creating logged-in user', ws['id_socket'], error_9);
|
|
2202
|
-
this.logConnectDebug('Create logged-in user failed', {
|
|
2203
|
-
id_socket: ws['id_socket'],
|
|
2204
|
-
id_user: ws['id_user'],
|
|
2205
|
-
user: ws['user'],
|
|
2206
|
-
error: (error_9 === null || error_9 === void 0 ? void 0 : error_9.message) || error_9
|
|
2207
|
-
});
|
|
2208
|
-
return [3 /*break*/, 3];
|
|
2209
|
-
case 3: return [2 /*return*/];
|
|
2210
|
-
}
|
|
2211
|
-
});
|
|
2212
|
-
}); }, 0);
|
|
2213
|
-
_b.label = 6;
|
|
2214
|
-
case 6: return [2 /*return*/];
|
|
2215
|
-
}
|
|
2216
|
-
});
|
|
2217
|
-
}); });
|
|
2218
|
-
// Keep alive timer
|
|
2219
|
-
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2220
|
-
var _a, _b, ws, e_13_1;
|
|
2221
|
-
var e_13, _c;
|
|
2222
|
-
return __generator(this, function (_d) {
|
|
2223
|
-
switch (_d.label) {
|
|
2224
|
-
case 0:
|
|
2225
|
-
_d.trys.push([0, 10, 11, 12]);
|
|
2226
|
-
_a = __values(this._serverWSS.clients), _b = _a.next();
|
|
2227
|
-
_d.label = 1;
|
|
2228
|
-
case 1:
|
|
2229
|
-
if (!!_b.done) return [3 /*break*/, 9];
|
|
2230
|
-
ws = _b.value;
|
|
2231
|
-
if (!(ws['pingTime'] && Date.now() - ws['pingTime'].getTime() >= this._clientHeartbeatIntervalMs)) return [3 /*break*/, 8];
|
|
2232
|
-
if (this.shouldDeferHeartbeat(ws)) {
|
|
2233
|
-
ws['isAlive'] = true;
|
|
2234
|
-
ws['retryCnt'] = 0;
|
|
2235
|
-
ws['pingTime'] = new Date();
|
|
2236
|
-
return [3 /*break*/, 8];
|
|
2237
|
-
}
|
|
2238
|
-
if (!(ws['isAlive'] === false)) return [3 /*break*/, 6];
|
|
2239
|
-
ws['retryCnt']++;
|
|
2240
|
-
if (!(ws['retryCnt'] >= 3)) return [3 /*break*/, 3];
|
|
2241
|
-
return [4 /*yield*/, this.unsubscribeWS(ws)];
|
|
2242
|
-
case 2:
|
|
2243
|
-
_d.sent();
|
|
2244
|
-
return [3 /*break*/, 5];
|
|
2245
|
-
case 3: return [4 /*yield*/, this.triggerClientHeartbeat(ws)];
|
|
2246
|
-
case 4:
|
|
2247
|
-
_d.sent();
|
|
2248
|
-
_d.label = 5;
|
|
2249
|
-
case 5: return [3 /*break*/, 8];
|
|
2250
|
-
case 6:
|
|
2251
|
-
ws['retryCnt'] = 0;
|
|
2252
|
-
ws['isAlive'] = false;
|
|
2253
|
-
return [4 /*yield*/, this.triggerClientHeartbeat(ws)];
|
|
2254
|
-
case 7:
|
|
2255
|
-
_d.sent();
|
|
2256
|
-
_d.label = 8;
|
|
2257
|
-
case 8:
|
|
2258
|
-
_b = _a.next();
|
|
2259
|
-
return [3 /*break*/, 1];
|
|
2260
|
-
case 9: return [3 /*break*/, 12];
|
|
2261
|
-
case 10:
|
|
2262
|
-
e_13_1 = _d.sent();
|
|
2263
|
-
e_13 = { error: e_13_1 };
|
|
2264
|
-
return [3 /*break*/, 12];
|
|
2265
|
-
case 11:
|
|
2266
|
-
try {
|
|
2267
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2268
|
-
}
|
|
2269
|
-
finally { if (e_13) throw e_13.error; }
|
|
2270
|
-
return [7 /*endfinally*/];
|
|
2271
|
-
case 12: return [2 /*return*/];
|
|
2272
|
-
}
|
|
2273
|
-
});
|
|
2274
|
-
}); }, this._clientHeartbeatIntervalMs);
|
|
2275
|
-
};
|
|
2276
|
-
ResolveIOMainServer.prototype.processSocketMessage = function (ws, socketData) {
|
|
2277
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2278
|
-
var socketData_1, socketData_1_1, message, e_14_1;
|
|
2279
|
-
var e_14, _a;
|
|
2280
|
-
return __generator(this, function (_b) {
|
|
2281
|
-
switch (_b.label) {
|
|
2282
|
-
case 0:
|
|
2283
|
-
if (typeof socketData === 'string' && socketData === 'ping') {
|
|
2284
|
-
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
2285
|
-
ws.send('pong');
|
|
2286
|
-
}
|
|
2287
|
-
return [2 /*return*/];
|
|
2288
|
-
}
|
|
2289
|
-
else if (typeof socketData === 'string' && socketData === 'pong') {
|
|
2290
|
-
ws['isAlive'] = true;
|
|
2291
|
-
ws['pongTime'] = new Date();
|
|
2292
|
-
ws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();
|
|
2293
|
-
this._subscriptionManager.loggedInLatency(ws);
|
|
2294
|
-
return [2 /*return*/];
|
|
2295
|
-
}
|
|
2296
|
-
// If the top level is not an array, let's skip
|
|
2297
|
-
if (!Array.isArray(socketData[0])) {
|
|
2298
|
-
console.log('Invalid message format (expected array of arrays)', socketData);
|
|
2299
|
-
this.logConnectDebug('Invalid message format', {
|
|
2300
|
-
id_socket: ws ? ws['id_socket'] : null,
|
|
2301
|
-
user: ws ? ws['user'] : null,
|
|
2302
|
-
preview: Array.isArray(socketData) ? socketData.slice(0, 3) : socketData
|
|
2303
|
-
});
|
|
2304
|
-
return [2 /*return*/];
|
|
2305
|
-
}
|
|
2306
|
-
_b.label = 1;
|
|
2307
|
-
case 1:
|
|
2308
|
-
_b.trys.push([1, 6, 7, 8]);
|
|
2309
|
-
socketData_1 = __values(socketData), socketData_1_1 = socketData_1.next();
|
|
2310
|
-
_b.label = 2;
|
|
2311
|
-
case 2:
|
|
2312
|
-
if (!!socketData_1_1.done) return [3 /*break*/, 5];
|
|
2313
|
-
message = socketData_1_1.value;
|
|
2314
|
-
return [4 /*yield*/, this.handleClientMessage(ws, message)];
|
|
2315
|
-
case 3:
|
|
2316
|
-
_b.sent();
|
|
2317
|
-
_b.label = 4;
|
|
2318
|
-
case 4:
|
|
2319
|
-
socketData_1_1 = socketData_1.next();
|
|
2320
|
-
return [3 /*break*/, 2];
|
|
2321
|
-
case 5: return [3 /*break*/, 8];
|
|
2322
|
-
case 6:
|
|
2323
|
-
e_14_1 = _b.sent();
|
|
2324
|
-
e_14 = { error: e_14_1 };
|
|
2325
|
-
return [3 /*break*/, 8];
|
|
2326
|
-
case 7:
|
|
2327
|
-
try {
|
|
2328
|
-
if (socketData_1_1 && !socketData_1_1.done && (_a = socketData_1.return)) _a.call(socketData_1);
|
|
2329
|
-
}
|
|
2330
|
-
finally { if (e_14) throw e_14.error; }
|
|
2331
|
-
return [7 /*endfinally*/];
|
|
2332
|
-
case 8: return [2 /*return*/];
|
|
2333
|
-
}
|
|
2334
|
-
});
|
|
2335
|
-
});
|
|
2336
|
-
};
|
|
2337
|
-
ResolveIOMainServer.prototype.decodeBufferPayload = function (buffer) {
|
|
2338
|
-
var textPayload = buffer.toString('utf8');
|
|
2339
|
-
if (this.looksLikeTextPayload(textPayload)) {
|
|
2340
|
-
try {
|
|
2341
|
-
return { data: this.parseTextFallback(textPayload), usedBinary: false };
|
|
2342
|
-
}
|
|
2343
|
-
catch (_a) {
|
|
2344
|
-
// fall through to attempt MessagePack decode
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
try {
|
|
2348
|
-
return { data: (0, msgpackr_1.unpack)(buffer), usedBinary: true };
|
|
2349
|
-
}
|
|
2350
|
-
catch (binaryErr) {
|
|
2351
|
-
try {
|
|
2352
|
-
return { data: this.parseTextFallback(textPayload), usedBinary: false };
|
|
2353
|
-
}
|
|
2354
|
-
catch (_b) {
|
|
2355
|
-
throw binaryErr;
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
};
|
|
2359
|
-
ResolveIOMainServer.prototype.parseTextFallback = function (rawMessage) {
|
|
2360
|
-
if (rawMessage === 'ping' || rawMessage === 'pong') {
|
|
2361
|
-
return rawMessage;
|
|
2362
|
-
}
|
|
2363
|
-
try {
|
|
2364
|
-
return JSON.parse(rawMessage, common_1.dateReviver);
|
|
2365
|
-
}
|
|
2366
|
-
catch (err) {
|
|
2367
|
-
throw err;
|
|
2368
|
-
}
|
|
2369
|
-
};
|
|
2370
|
-
ResolveIOMainServer.prototype.looksLikeTextPayload = function (text) {
|
|
2371
|
-
if (!text) {
|
|
2372
|
-
return false;
|
|
2373
|
-
}
|
|
2374
|
-
var trimmed = text.trim();
|
|
2375
|
-
if (!trimmed) {
|
|
2376
|
-
return false;
|
|
2377
|
-
}
|
|
2378
|
-
var first = trimmed[0];
|
|
2379
|
-
return first === '[' || first === '{' || first === '"' || first === 'p' || first === 'P';
|
|
2380
|
-
};
|
|
2381
|
-
ResolveIOMainServer.prototype.resolveConnectDebug = function () {
|
|
2382
|
-
var _a, _b, _c;
|
|
2383
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2384
|
-
var raw = (_c = (_b = (_a = process.env.WS_CONNECT_DEBUG) !== null && _a !== void 0 ? _a : process.env.CONNECT_DEBUG) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['WS_CONNECT_DEBUG']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['CONNECT_DEBUG'];
|
|
2385
|
-
return this.parseDebugFlag(raw);
|
|
2386
|
-
};
|
|
2387
|
-
ResolveIOMainServer.prototype.resolvePerfDebug = function () {
|
|
2388
|
-
var _a, _b, _c;
|
|
2389
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2390
|
-
var raw = (_c = (_b = (_a = process.env.PERF_DEBUG) !== null && _a !== void 0 ? _a : process.env.CPU_DEBUG) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['PERF_DEBUG']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['CPU_DEBUG'];
|
|
2391
|
-
return this.parseDebugFlag(raw);
|
|
2392
|
-
};
|
|
2393
|
-
ResolveIOMainServer.prototype.resolveCpuProfileOnStart = function () {
|
|
2394
|
-
var _a, _b, _c;
|
|
2395
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2396
|
-
var raw = (_c = (_b = (_a = process.env.CPU_PROFILE_ON_START) !== null && _a !== void 0 ? _a : process.env.CPU_PROFILE_START) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['CPU_PROFILE_ON_START']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['CPU_PROFILE_START'];
|
|
2397
|
-
return this.parseDebugFlag(raw);
|
|
2398
|
-
};
|
|
2399
|
-
ResolveIOMainServer.prototype.resolveCpuProfileAuto = function () {
|
|
2400
|
-
var _a;
|
|
2401
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2402
|
-
var raw = (_a = process.env.CPU_PROFILE_AUTO) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['CPU_PROFILE_AUTO'];
|
|
2403
|
-
return this.parseDebugFlag(raw);
|
|
2404
|
-
};
|
|
2405
|
-
ResolveIOMainServer.prototype.resolveCpuProfileDurationMs = function () {
|
|
2406
|
-
var _a, _b, _c;
|
|
2407
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2408
|
-
var raw = (_c = (_b = (_a = process.env.CPU_PROFILE_DURATION_MS) !== null && _a !== void 0 ? _a : process.env.PERF_PROFILE_DURATION_MS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['CPU_PROFILE_DURATION_MS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['PERF_PROFILE_DURATION_MS'];
|
|
2409
|
-
return this.parsePositiveInt(raw, this._cpuProfileDurationMs);
|
|
2410
|
-
};
|
|
2411
|
-
ResolveIOMainServer.prototype.resolveCpuProfileThresholdPct = function () {
|
|
2412
|
-
var _a, _b, _c;
|
|
2413
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2414
|
-
var raw = (_c = (_b = (_a = process.env.CPU_PROFILE_THRESHOLD_PCT) !== null && _a !== void 0 ? _a : process.env.PERF_PROFILE_THRESHOLD_PCT) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['CPU_PROFILE_THRESHOLD_PCT']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['PERF_PROFILE_THRESHOLD_PCT'];
|
|
2415
|
-
return this.parsePositiveFloat(raw, this._cpuProfileThresholdPct);
|
|
2416
|
-
};
|
|
2417
|
-
ResolveIOMainServer.prototype.resolveCpuProfileTriggerCount = function () {
|
|
2418
|
-
var _a;
|
|
2419
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2420
|
-
var raw = (_a = process.env.CPU_PROFILE_TRIGGER_COUNT) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['CPU_PROFILE_TRIGGER_COUNT'];
|
|
2421
|
-
return this.parsePositiveInt(raw, this._cpuProfileTriggerCount);
|
|
2422
|
-
};
|
|
2423
|
-
ResolveIOMainServer.prototype.resolveCpuProfileDir = function () {
|
|
2424
|
-
var _a;
|
|
2425
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2426
|
-
var raw = (_a = process.env.CPU_PROFILE_DIR) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['CPU_PROFILE_DIR'];
|
|
2427
|
-
return typeof raw === 'string' && raw.trim() ? raw.trim() : null;
|
|
2428
|
-
};
|
|
2429
|
-
ResolveIOMainServer.prototype.resolveTimerDebug = function () {
|
|
2430
|
-
var _a;
|
|
2431
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2432
|
-
var raw = (_a = process.env.TIMER_DEBUG) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['TIMER_DEBUG'];
|
|
2433
|
-
return this.parseDebugFlag(raw);
|
|
2434
|
-
};
|
|
2435
|
-
ResolveIOMainServer.prototype.resolveTimerDebugThresholdMs = function () {
|
|
2436
|
-
var _a;
|
|
2437
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2438
|
-
var raw = (_a = process.env.TIMER_DEBUG_THRESHOLD_MS) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['TIMER_DEBUG_THRESHOLD_MS'];
|
|
2439
|
-
return this.parsePositiveFloat(raw, this._timerDebugThresholdMs);
|
|
2440
|
-
};
|
|
2441
|
-
ResolveIOMainServer.prototype.resolveTimerDebugMinDelayMs = function () {
|
|
2442
|
-
var _a;
|
|
2443
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2444
|
-
var raw = (_a = process.env.TIMER_DEBUG_MIN_DELAY_MS) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['TIMER_DEBUG_MIN_DELAY_MS'];
|
|
2445
|
-
return this.parsePositiveFloat(raw, this._timerDebugMinDelayMs);
|
|
2446
|
-
};
|
|
2447
|
-
ResolveIOMainServer.prototype.resolveTimerDebugSampleRate = function () {
|
|
2448
|
-
var _a;
|
|
2449
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2450
|
-
var raw = (_a = process.env.TIMER_DEBUG_SAMPLE_RATE) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['TIMER_DEBUG_SAMPLE_RATE'];
|
|
2451
|
-
var parsed = parseFloat(raw !== null && raw !== void 0 ? raw : '');
|
|
2452
|
-
if (Number.isFinite(parsed) && parsed > 0 && parsed <= 1) {
|
|
2453
|
-
return parsed;
|
|
2454
|
-
}
|
|
2455
|
-
return this._timerDebugSampleRate;
|
|
2456
|
-
};
|
|
2457
|
-
ResolveIOMainServer.prototype.resolveTimerDebugLogLimit = function () {
|
|
2458
|
-
var _a;
|
|
2459
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2460
|
-
var raw = (_a = process.env.TIMER_DEBUG_LOG_LIMIT) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['TIMER_DEBUG_LOG_LIMIT'];
|
|
2461
|
-
return this.parsePositiveInt(raw, this._timerDebugLogLimit);
|
|
2462
|
-
};
|
|
2463
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperEnabled = function () {
|
|
2464
|
-
var _a, _b, _c;
|
|
2465
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2466
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_ENABLED) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_ENABLED) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_ENABLED']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_ENABLED'];
|
|
2467
|
-
var configured = this.parseOptionalBoolean(raw);
|
|
2468
|
-
if (configured !== null) {
|
|
2469
|
-
return configured;
|
|
2470
|
-
}
|
|
2471
|
-
return this.isPm2ManagedRuntime() && !this.isLocalRuntime();
|
|
2472
|
-
};
|
|
2473
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperIntervalMs = function () {
|
|
2474
|
-
var _a, _b, _c;
|
|
2475
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2476
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_INTERVAL_MS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_INTERVAL_MS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_INTERVAL_MS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_INTERVAL_MS'];
|
|
2477
|
-
return this.parsePositiveInt(raw, this._standaloneNodeReaperIntervalMs);
|
|
2478
|
-
};
|
|
2479
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperMinAgeSeconds = function () {
|
|
2480
|
-
var _a, _b, _c;
|
|
2481
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2482
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_MIN_AGE_SECONDS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_MIN_AGE_SECONDS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_MIN_AGE_SECONDS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_MIN_AGE_SECONDS'];
|
|
2483
|
-
return this.parsePositiveInt(raw, this._standaloneNodeReaperMinAgeSeconds);
|
|
2484
|
-
};
|
|
2485
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperMaxKillsPerSignature = function () {
|
|
2486
|
-
var _a, _b, _c;
|
|
2487
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2488
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_MAX_KILLS_PER_SIGNATURE) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_MAX_KILLS_PER_SIGNATURE) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_MAX_KILLS_PER_SIGNATURE']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_MAX_KILLS_PER_SIGNATURE'];
|
|
2489
|
-
return this.parsePositiveInt(raw, this._standaloneNodeReaperMaxKillsPerSignature);
|
|
2490
|
-
};
|
|
2491
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperKillWindowMs = function () {
|
|
2492
|
-
var _a, _b, _c;
|
|
2493
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2494
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_KILL_WINDOW_MS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_KILL_WINDOW_MS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_KILL_WINDOW_MS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_KILL_WINDOW_MS'];
|
|
2495
|
-
return this.parsePositiveInt(raw, this._standaloneNodeReaperKillWindowMs);
|
|
2496
|
-
};
|
|
2497
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperIncludeSystemdServices = function () {
|
|
2498
|
-
var _a, _b, _c;
|
|
2499
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2500
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_INCLUDE_SYSTEMD_SERVICES) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_INCLUDE_SYSTEMD_SERVICES) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_INCLUDE_SYSTEMD_SERVICES']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_INCLUDE_SYSTEMD_SERVICES'];
|
|
2501
|
-
return this.parseDebugFlag(raw);
|
|
2502
|
-
};
|
|
2503
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperHighCpuPct = function () {
|
|
2504
|
-
var _a, _b, _c;
|
|
2505
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2506
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_CPU_PCT) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_HIGH_CPU_PCT) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_CPU_PCT']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_HIGH_CPU_PCT'];
|
|
2507
|
-
return this.parsePositiveFloat(raw, this._standaloneNodeReaperHighCpuPct);
|
|
2508
|
-
};
|
|
2509
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperHighRssMb = function () {
|
|
2510
|
-
var _a, _b, _c;
|
|
2511
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2512
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_RSS_MB) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_HIGH_RSS_MB) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_RSS_MB']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_HIGH_RSS_MB'];
|
|
2513
|
-
return this.parsePositiveFloat(raw, this._standaloneNodeReaperHighRssMb);
|
|
2514
|
-
};
|
|
2515
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperHighMinAgeSeconds = function () {
|
|
2516
|
-
var _a, _b, _c;
|
|
2517
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2518
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_MIN_AGE_SECONDS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_HIGH_MIN_AGE_SECONDS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_MIN_AGE_SECONDS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_HIGH_MIN_AGE_SECONDS'];
|
|
2519
|
-
return this.parsePositiveInt(raw, this._standaloneNodeReaperHighMinAgeSeconds);
|
|
2520
|
-
};
|
|
2521
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperHighConsecutiveScans = function () {
|
|
2522
|
-
var _a, _b, _c;
|
|
2523
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2524
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_CONSECUTIVE_SCANS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_HIGH_CONSECUTIVE_SCANS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_CONSECUTIVE_SCANS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_HIGH_CONSECUTIVE_SCANS'];
|
|
2525
|
-
return this.parsePositiveInt(raw, this._standaloneNodeReaperHighConsecutiveScans);
|
|
2526
|
-
};
|
|
2527
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperDryRun = function () {
|
|
2528
|
-
var _a, _b, _c;
|
|
2529
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2530
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_DRY_RUN) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_DRY_RUN) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_DRY_RUN']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_DRY_RUN'];
|
|
2531
|
-
return this.parseDebugFlag(raw);
|
|
2532
|
-
};
|
|
2533
|
-
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperAlertWindowMs = function () {
|
|
2534
|
-
var _a, _b, _c;
|
|
2535
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2536
|
-
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_ALERT_WINDOW_MS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_ALERT_WINDOW_MS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_ALERT_WINDOW_MS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_ALERT_WINDOW_MS'];
|
|
2537
|
-
return this.parsePositiveInt(raw, this._standaloneNodeReaperAlertWindowMs);
|
|
2538
|
-
};
|
|
2539
|
-
ResolveIOMainServer.prototype.isPm2ManagedRuntime = function () {
|
|
2540
|
-
return Boolean(process.env.pm_id
|
|
2541
|
-
|| process.env.PM2_HOME
|
|
2542
|
-
|| process.env.NODE_APP_INSTANCE
|
|
2543
|
-
|| "".concat(process.env._ || '').includes('pm2'));
|
|
2544
|
-
};
|
|
2545
|
-
ResolveIOMainServer.prototype.isPrimaryPm2Instance = function () {
|
|
2546
|
-
var appInstance = this.normalizeWorkerSelectorValue(process.env.NODE_APP_INSTANCE);
|
|
2547
|
-
return !appInstance || appInstance === '0';
|
|
2548
|
-
};
|
|
2549
|
-
ResolveIOMainServer.prototype.isLocalRuntime = function () {
|
|
2550
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2551
|
-
var rootUrl = "".concat(process.env.ROOT_URL || (config === null || config === void 0 ? void 0 : config['ROOT_URL']) || '').trim().toLowerCase();
|
|
2552
|
-
var serverUrl = "".concat(process.env.SERVER_URL || (config === null || config === void 0 ? void 0 : config['SERVER_URL']) || '').trim().toLowerCase();
|
|
2553
|
-
return rootUrl.includes('localhost') || rootUrl.includes('127.0.0.1') || serverUrl.includes('localhost') || serverUrl.includes('127.0.0.1');
|
|
2554
|
-
};
|
|
2555
|
-
ResolveIOMainServer.prototype.normalizeWorkerSelectorValue = function (value) {
|
|
2556
|
-
if (value === null || value === undefined) {
|
|
2557
|
-
return null;
|
|
2558
|
-
}
|
|
2559
|
-
var normalized = String(value).trim();
|
|
2560
|
-
return normalized.length ? normalized : null;
|
|
2561
|
-
};
|
|
2562
|
-
ResolveIOMainServer.prototype.shouldStartCronManagerForWorker = function () {
|
|
2563
|
-
var workerIndex = this.normalizeWorkerSelectorValue(process.env.WORKER_INDEX);
|
|
2564
|
-
var workerInstance = this.normalizeWorkerSelectorValue(process.env.NODE_APP_INSTANCE) || '0';
|
|
2565
|
-
var hasExplicitServerManagerOwner = process.env.SERVER_MANAGER_WORKER_INDEX !== undefined
|
|
2566
|
-
|| process.env.SERVER_MANAGER_WORKER_INSTANCE !== undefined
|
|
2567
|
-
|| process.env.SERVER_MANAGER_NODE_APP_INSTANCE !== undefined;
|
|
2568
|
-
if (!hasExplicitServerManagerOwner) {
|
|
2569
|
-
return workerIndex === '0';
|
|
2570
|
-
}
|
|
2571
|
-
var serverManagerWorkerIndex = this.normalizeWorkerSelectorValue(process.env.SERVER_MANAGER_WORKER_INDEX) || '0';
|
|
2572
|
-
var serverManagerWorkerInstance = this.normalizeWorkerSelectorValue(process.env.SERVER_MANAGER_WORKER_INSTANCE || process.env.SERVER_MANAGER_NODE_APP_INSTANCE) || '0';
|
|
2573
|
-
return workerIndex === serverManagerWorkerIndex && workerInstance === serverManagerWorkerInstance;
|
|
2574
|
-
};
|
|
2575
|
-
ResolveIOMainServer.prototype.parseWorkerSelector = function (value) {
|
|
2576
|
-
if (value === null || value === undefined) {
|
|
2577
|
-
return null;
|
|
2578
|
-
}
|
|
2579
|
-
var raw = Array.isArray(value) ? value.join(',') : String(value);
|
|
2580
|
-
var parts = raw.split(',').map(function (part) { return part.trim(); }).filter(Boolean);
|
|
2581
|
-
if (!parts.length) {
|
|
2582
|
-
return null;
|
|
2583
|
-
}
|
|
2584
|
-
return new Set(parts);
|
|
2585
|
-
};
|
|
2586
|
-
ResolveIOMainServer.prototype.workerMatchesSelector = function (workerIndex, workerInstance, indexes, instances) {
|
|
2587
|
-
if (!indexes && !instances) {
|
|
2588
|
-
return false;
|
|
2589
|
-
}
|
|
2590
|
-
var indexMatch = indexes ? (workerIndex ? indexes.has(workerIndex) : false) : true;
|
|
2591
|
-
var instanceMatch = instances ? (workerInstance ? instances.has(workerInstance) : false) : true;
|
|
2592
|
-
return indexMatch && instanceMatch;
|
|
2593
|
-
};
|
|
2594
|
-
ResolveIOMainServer.prototype.resolveWorkerRole = function () {
|
|
2595
|
-
var workerIndex = this.normalizeWorkerSelectorValue(process.env.WORKER_INDEX);
|
|
2596
|
-
var workerInstance = this.normalizeWorkerSelectorValue(process.env.NODE_APP_INSTANCE);
|
|
2597
|
-
var publicationIndexes = this.parseWorkerSelector(process.env.PUBLICATION_WORKER_INDEX
|
|
2598
|
-
|| process.env.SUBSCRIPTION_WORKER_INDEX
|
|
2599
|
-
|| process.env.WORKER_PUBLICATION_INDEX);
|
|
2600
|
-
var publicationInstances = this.parseWorkerSelector(process.env.PUBLICATION_WORKER_INSTANCE
|
|
2601
|
-
|| process.env.SUBSCRIPTION_WORKER_INSTANCE
|
|
2602
|
-
|| process.env.WORKER_PUBLICATION_INSTANCE);
|
|
2603
|
-
var codexIndexes = this.parseWorkerSelector(process.env.AI_ASSISTANT_CODEX_WORKER_INDEX
|
|
2604
|
-
|| process.env.CODEX_WORKER_INDEX
|
|
2605
|
-
|| process.env.WORKER_CODEX_INDEX);
|
|
2606
|
-
var codexInstances = this.parseWorkerSelector(process.env.AI_ASSISTANT_CODEX_WORKER_INSTANCE
|
|
2607
|
-
|| process.env.CODEX_WORKER_INSTANCE
|
|
2608
|
-
|| process.env.WORKER_CODEX_INSTANCE);
|
|
2609
|
-
if (this.workerMatchesSelector(workerIndex, workerInstance, publicationIndexes, publicationInstances)) {
|
|
2610
|
-
return 'Subscription';
|
|
2611
|
-
}
|
|
2612
|
-
if (this.workerMatchesSelector(workerIndex, workerInstance, codexIndexes, codexInstances)) {
|
|
2613
|
-
return 'Codex';
|
|
2614
|
-
}
|
|
2615
|
-
return 'Other';
|
|
2616
|
-
};
|
|
2617
|
-
ResolveIOMainServer.prototype.parsePositiveInt = function (value, fallback) {
|
|
2618
|
-
var parsed = parseInt(value !== null && value !== void 0 ? value : '', 10);
|
|
2619
|
-
if (Number.isNaN(parsed) || parsed <= 0) {
|
|
2620
|
-
return fallback;
|
|
2621
|
-
}
|
|
2622
|
-
return parsed;
|
|
2623
|
-
};
|
|
2624
|
-
ResolveIOMainServer.prototype.parsePositiveFloat = function (value, fallback) {
|
|
2625
|
-
var parsed = parseFloat(value !== null && value !== void 0 ? value : '');
|
|
2626
|
-
if (Number.isNaN(parsed) || parsed <= 0) {
|
|
2627
|
-
return fallback;
|
|
2628
|
-
}
|
|
2629
|
-
return parsed;
|
|
2630
|
-
};
|
|
2631
|
-
ResolveIOMainServer.prototype.startPerfDebug = function () {
|
|
2632
|
-
var _this = this;
|
|
2633
|
-
var _a;
|
|
2634
|
-
if (!this._perfDebug || this._perfDebugTimer) {
|
|
2635
|
-
return;
|
|
2636
|
-
}
|
|
2637
|
-
this._perfDebugIntervalMs = this.parsePositiveInt((_a = process.env.PERF_DEBUG_INTERVAL_MS) !== null && _a !== void 0 ? _a : process.env.CPU_DEBUG_INTERVAL_MS, this._perfDebugIntervalMs);
|
|
2638
|
-
this._perfDebugLastCpu = process.cpuUsage();
|
|
2639
|
-
this._perfDebugLastTs = Date.now();
|
|
2640
|
-
this._eventLoopHistogram = (0, perf_hooks_1.monitorEventLoopDelay)({ resolution: 20 });
|
|
2641
|
-
this._eventLoopHistogram.enable();
|
|
2642
|
-
this._perfDebugTimer = setInterval(function () {
|
|
2643
|
-
var now = Date.now();
|
|
2644
|
-
var elapsedMs = now - _this._perfDebugLastTs;
|
|
2645
|
-
var cpuDiff = _this._perfDebugLastCpu ? process.cpuUsage(_this._perfDebugLastCpu) : process.cpuUsage();
|
|
2646
|
-
var cpuMs = (cpuDiff.user + cpuDiff.system) / 1000;
|
|
2647
|
-
var cpuPct = elapsedMs > 0 ? (cpuMs / elapsedMs) * 100 : 0;
|
|
2648
|
-
var mem = process.memoryUsage();
|
|
2649
|
-
var heapUsedMb = (0, common_1.round)((mem.heapUsed / 1024 / 1024) * 10) / 10;
|
|
2650
|
-
var rssMb = (0, common_1.round)((mem.rss / 1024 / 1024) * 10) / 10;
|
|
2651
|
-
var handles = typeof process._getActiveHandles === 'function'
|
|
2652
|
-
? process._getActiveHandles().length
|
|
2653
|
-
: null;
|
|
2654
|
-
var requests = typeof process._getActiveRequests === 'function'
|
|
2655
|
-
? process._getActiveRequests().length
|
|
2656
|
-
: null;
|
|
2657
|
-
var histogram = _this._eventLoopHistogram;
|
|
2658
|
-
var eventLoop = histogram ? {
|
|
2659
|
-
meanMs: (0, common_1.round)((histogram.mean / 1e6) * 100) / 100,
|
|
2660
|
-
p50Ms: (0, common_1.round)((histogram.percentile(50) / 1e6) * 100) / 100,
|
|
2661
|
-
p95Ms: (0, common_1.round)((histogram.percentile(95) / 1e6) * 100) / 100,
|
|
2662
|
-
p99Ms: (0, common_1.round)((histogram.percentile(99) / 1e6) * 100) / 100,
|
|
2663
|
-
maxMs: (0, common_1.round)((histogram.max / 1e6) * 100) / 100
|
|
2664
|
-
} : null;
|
|
2665
|
-
histogram === null || histogram === void 0 ? void 0 : histogram.reset();
|
|
2666
|
-
console.log(new Date(), '[Perf Debug]', JSON.stringify({
|
|
2667
|
-
cpuPct: (0, common_1.round)(cpuPct * 10) / 10,
|
|
2668
|
-
cpuMs: (0, common_1.round)(cpuMs),
|
|
2669
|
-
elapsedMs: elapsedMs,
|
|
2670
|
-
eventLoop: eventLoop,
|
|
2671
|
-
heapUsedMb: heapUsedMb,
|
|
2672
|
-
rssMb: rssMb,
|
|
2673
|
-
activeHandles: handles,
|
|
2674
|
-
activeRequests: requests,
|
|
2675
|
-
msgRecv: _this._debugMsgRecv,
|
|
2676
|
-
msgQueue: _this._debugMsgQueue
|
|
2677
|
-
}));
|
|
2678
|
-
if (_this._cpuProfileAuto) {
|
|
2679
|
-
if (cpuPct >= _this._cpuProfileThresholdPct) {
|
|
2680
|
-
_this._cpuProfileHighCount += 1;
|
|
2681
|
-
}
|
|
2682
|
-
else {
|
|
2683
|
-
_this._cpuProfileHighCount = 0;
|
|
2684
|
-
}
|
|
2685
|
-
if (_this._cpuProfileHighCount >= _this._cpuProfileTriggerCount) {
|
|
2686
|
-
_this._cpuProfileHighCount = 0;
|
|
2687
|
-
_this.startCpuProfile('auto-high-cpu');
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
_this._perfDebugLastCpu = process.cpuUsage();
|
|
2691
|
-
_this._perfDebugLastTs = now;
|
|
2692
|
-
}, this._perfDebugIntervalMs);
|
|
2693
|
-
};
|
|
2694
|
-
ResolveIOMainServer.prototype.installTimerDebug = function () {
|
|
2695
|
-
var _this = this;
|
|
2696
|
-
if (!this._timerDebug) {
|
|
2697
|
-
return;
|
|
2698
|
-
}
|
|
2699
|
-
var g = global;
|
|
2700
|
-
if (g.__resolveioTimerDebugInstalled) {
|
|
2701
|
-
return;
|
|
2702
|
-
}
|
|
2703
|
-
g.__resolveioTimerDebugInstalled = true;
|
|
2704
|
-
var originalSetTimeout = global.setTimeout;
|
|
2705
|
-
var originalSetInterval = global.setInterval;
|
|
2706
|
-
var thresholdMs = this._timerDebugThresholdMs;
|
|
2707
|
-
var minDelayMs = this._timerDebugMinDelayMs;
|
|
2708
|
-
var sampleRate = this._timerDebugSampleRate;
|
|
2709
|
-
var shouldSample = function () { return sampleRate >= 1 || Math.random() <= sampleRate; };
|
|
2710
|
-
var logTimer = function (type, durationMs, delayMs, createdStack) {
|
|
2711
|
-
if (_this._timerDebugLogLimit > 0 && _this._timerDebugLogCount >= _this._timerDebugLogLimit) {
|
|
2712
|
-
return;
|
|
2713
|
-
}
|
|
2714
|
-
_this._timerDebugLogCount += 1;
|
|
2715
|
-
var stackLines = createdStack
|
|
2716
|
-
? createdStack.split('\n').slice(1, 6).map(function (line) { return line.trim(); }).join(' | ')
|
|
2717
|
-
: undefined;
|
|
2718
|
-
console.log(new Date(), '[Timer Debug]', JSON.stringify({
|
|
2719
|
-
type: type,
|
|
2720
|
-
durationMs: (0, common_1.round)(durationMs * 10) / 10,
|
|
2721
|
-
delayMs: delayMs !== null && delayMs !== void 0 ? delayMs : null,
|
|
2722
|
-
createdAt: stackLines
|
|
2723
|
-
}));
|
|
2724
|
-
};
|
|
2725
|
-
var wrapTimer = function (handler, type, delayMs) {
|
|
2726
|
-
if (typeof handler !== 'function') {
|
|
2727
|
-
return handler;
|
|
2728
|
-
}
|
|
2729
|
-
var createdStack = new Error().stack;
|
|
2730
|
-
var shouldFlagShortDelay = typeof delayMs === 'number' && delayMs <= minDelayMs;
|
|
2731
|
-
return function wrappedTimer() {
|
|
2732
|
-
var args = [];
|
|
2733
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2734
|
-
args[_i] = arguments[_i];
|
|
2735
|
-
}
|
|
2736
|
-
var start = process.hrtime.bigint();
|
|
2737
|
-
try {
|
|
2738
|
-
return handler.apply(this, args);
|
|
2739
|
-
}
|
|
2740
|
-
finally {
|
|
2741
|
-
var elapsedMs = Number(process.hrtime.bigint() - start) / 1e6;
|
|
2742
|
-
if (shouldSample() && (elapsedMs >= thresholdMs || shouldFlagShortDelay)) {
|
|
2743
|
-
logTimer(type, elapsedMs, delayMs, createdStack);
|
|
2744
|
-
}
|
|
2745
|
-
}
|
|
2746
|
-
};
|
|
2747
|
-
};
|
|
2748
|
-
global.setTimeout = (function (handler, timeout) {
|
|
2749
|
-
var args = [];
|
|
2750
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
2751
|
-
args[_i - 2] = arguments[_i];
|
|
2752
|
-
}
|
|
2753
|
-
return originalSetTimeout.apply(void 0, __spreadArray([wrapTimer(handler, 'setTimeout', timeout), timeout], __read(args), false));
|
|
2754
|
-
});
|
|
2755
|
-
global.setInterval = (function (handler, timeout) {
|
|
2756
|
-
var args = [];
|
|
2757
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
2758
|
-
args[_i - 2] = arguments[_i];
|
|
2759
|
-
}
|
|
2760
|
-
return originalSetInterval.apply(void 0, __spreadArray([wrapTimer(handler, 'setInterval', timeout), timeout], __read(args), false));
|
|
2761
|
-
});
|
|
2762
|
-
};
|
|
2763
|
-
ResolveIOMainServer.prototype.startCpuProfile = function (trigger) {
|
|
2764
|
-
var _this = this;
|
|
2765
|
-
if (this._cpuProfileSession) {
|
|
2766
|
-
return;
|
|
2767
|
-
}
|
|
2768
|
-
try {
|
|
2769
|
-
var session_1 = new inspector.Session();
|
|
2770
|
-
session_1.connect();
|
|
2771
|
-
session_1.post('Profiler.enable', function () {
|
|
2772
|
-
session_1.post('Profiler.start', function () {
|
|
2773
|
-
_this._cpuProfileSession = session_1;
|
|
2774
|
-
console.log(new Date(), '[Perf Debug]', 'CPU profile started', trigger);
|
|
2775
|
-
setTimeout(function () {
|
|
2776
|
-
_this.stopCpuProfile(trigger);
|
|
2777
|
-
}, _this._cpuProfileDurationMs);
|
|
2778
|
-
});
|
|
2779
|
-
});
|
|
2780
|
-
}
|
|
2781
|
-
catch (error) {
|
|
2782
|
-
console.error(new Date(), '[Perf Debug]', 'CPU profile start failed', error);
|
|
2783
|
-
}
|
|
2784
|
-
};
|
|
2785
|
-
ResolveIOMainServer.prototype.stopCpuProfile = function (trigger) {
|
|
2786
|
-
var _this = this;
|
|
2787
|
-
var session = this._cpuProfileSession;
|
|
2788
|
-
if (!session) {
|
|
2789
|
-
return;
|
|
2790
|
-
}
|
|
2791
|
-
session.post('Profiler.stop', function (err, res) {
|
|
2792
|
-
var _a;
|
|
2793
|
-
if (err) {
|
|
2794
|
-
console.error(new Date(), '[Perf Debug]', 'CPU profile stop failed', err);
|
|
2795
|
-
}
|
|
2796
|
-
else {
|
|
2797
|
-
try {
|
|
2798
|
-
var dir = _this.resolveWritableProfileDir();
|
|
2799
|
-
var filename = "resolveio-cpuprofile-".concat(process.pid, "-").concat(Date.now(), ".cpuprofile");
|
|
2800
|
-
var filePath = path.join(dir, filename);
|
|
2801
|
-
fs.writeFileSync(filePath, JSON.stringify((_a = res === null || res === void 0 ? void 0 : res.profile) !== null && _a !== void 0 ? _a : {}));
|
|
2802
|
-
console.log(new Date(), '[Perf Debug]', 'CPU profile saved', filePath, trigger);
|
|
2803
|
-
}
|
|
2804
|
-
catch (writeErr) {
|
|
2805
|
-
console.error(new Date(), '[Perf Debug]', 'CPU profile write failed', writeErr);
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
try {
|
|
2809
|
-
session.disconnect();
|
|
2810
|
-
}
|
|
2811
|
-
catch (_b) { }
|
|
2812
|
-
_this._cpuProfileSession = null;
|
|
2813
|
-
});
|
|
2814
|
-
};
|
|
2815
|
-
ResolveIOMainServer.prototype.resolveWritableProfileDir = function () {
|
|
2816
|
-
var preferred = this._cpuProfileDir;
|
|
2817
|
-
if (preferred) {
|
|
2818
|
-
try {
|
|
2819
|
-
fs.mkdirSync(preferred, { recursive: true });
|
|
2820
|
-
return preferred;
|
|
2821
|
-
}
|
|
2822
|
-
catch (_a) { }
|
|
2823
|
-
}
|
|
2824
|
-
return os.tmpdir();
|
|
2825
|
-
};
|
|
2826
|
-
ResolveIOMainServer.prototype.parseDebugFlag = function (value) {
|
|
2827
|
-
if (value === true) {
|
|
2828
|
-
return true;
|
|
2829
|
-
}
|
|
2830
|
-
if (value === false || value === null || value === undefined) {
|
|
2831
|
-
return false;
|
|
2832
|
-
}
|
|
2833
|
-
if (typeof value === 'number') {
|
|
2834
|
-
return value === 1;
|
|
2835
|
-
}
|
|
2836
|
-
if (typeof value === 'string') {
|
|
2837
|
-
var normalized = value.trim().toLowerCase();
|
|
2838
|
-
return ['1', 'true', 'yes', 'y', 'on'].includes(normalized);
|
|
2839
|
-
}
|
|
2840
|
-
return false;
|
|
2841
|
-
};
|
|
2842
|
-
ResolveIOMainServer.prototype.parseOptionalBoolean = function (value) {
|
|
2843
|
-
if (value === null || value === undefined) {
|
|
2844
|
-
return null;
|
|
2845
|
-
}
|
|
2846
|
-
var normalized = "".concat(value).trim();
|
|
2847
|
-
if (!normalized) {
|
|
2848
|
-
return null;
|
|
2849
|
-
}
|
|
2850
|
-
return this.parseDebugFlag(normalized);
|
|
2851
|
-
};
|
|
2852
|
-
ResolveIOMainServer.prototype.parseNonNegativeInt = function (value, fallback) {
|
|
2853
|
-
var parsed = parseInt("".concat(value !== null && value !== void 0 ? value : ''), 10);
|
|
2854
|
-
if (Number.isNaN(parsed) || parsed < 0) {
|
|
2855
|
-
return fallback;
|
|
2856
|
-
}
|
|
2857
|
-
return parsed;
|
|
2858
|
-
};
|
|
2859
|
-
ResolveIOMainServer.prototype.resolveSocketTier = function () {
|
|
2860
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2861
|
-
return "".concat(process.env.AI_CODER_PLAN_TIER || config['AI_CODER_PLAN_TIER'] || '').trim().toLowerCase();
|
|
2862
|
-
};
|
|
2863
|
-
ResolveIOMainServer.prototype.resolveSocketTierKeySuffix = function (planTier) {
|
|
2864
|
-
return "".concat(planTier || '')
|
|
2865
|
-
.trim()
|
|
2866
|
-
.toUpperCase()
|
|
2867
|
-
.replace(/[^A-Z0-9]+/g, '_');
|
|
2868
|
-
};
|
|
2869
|
-
ResolveIOMainServer.prototype.resolveMaxClientSockets = function (planTier) {
|
|
2870
|
-
var _a, _b, _c;
|
|
2871
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2872
|
-
var explicitLimit = this.parseNonNegativeInt((_a = config['AI_CODER_MAX_SOCKETS']) !== null && _a !== void 0 ? _a : process.env.AI_CODER_MAX_SOCKETS, -1);
|
|
2873
|
-
if (explicitLimit >= 0) {
|
|
2874
|
-
return explicitLimit;
|
|
2875
|
-
}
|
|
2876
|
-
var normalizedTier = "".concat(planTier || '').trim().toLowerCase();
|
|
2877
|
-
var tierKeySuffix = this.resolveSocketTierKeySuffix(normalizedTier);
|
|
2878
|
-
if (tierKeySuffix) {
|
|
2879
|
-
var tierLimitKey = "AI_CODER_MAX_SOCKETS_".concat(tierKeySuffix);
|
|
2880
|
-
var tierLimit = this.parseNonNegativeInt((_b = config[tierLimitKey]) !== null && _b !== void 0 ? _b : process.env[tierLimitKey], -1);
|
|
2881
|
-
if (tierLimit >= 0) {
|
|
2882
|
-
return tierLimit;
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
var maxUsers = this.parseNonNegativeInt((_c = config['AI_CODER_MAX_USERS']) !== null && _c !== void 0 ? _c : process.env.AI_CODER_MAX_USERS, -1);
|
|
2886
|
-
if (maxUsers > 0) {
|
|
2887
|
-
return maxUsers === 1 ? 1 : maxUsers * 2;
|
|
2888
|
-
}
|
|
2889
|
-
if (normalizedTier === 'tool') {
|
|
2890
|
-
return 1;
|
|
2891
|
-
}
|
|
2892
|
-
if (normalizedTier === 'small') {
|
|
2893
|
-
return 10;
|
|
2894
|
-
}
|
|
2895
|
-
if (normalizedTier === 'medium') {
|
|
2896
|
-
return 50;
|
|
2897
|
-
}
|
|
2898
|
-
if (normalizedTier === 'large') {
|
|
2899
|
-
return 200;
|
|
2900
|
-
}
|
|
2901
|
-
if (normalizedTier === 'enterprise') {
|
|
2902
|
-
return 0;
|
|
2903
|
-
}
|
|
2904
|
-
return 0;
|
|
2905
|
-
};
|
|
2906
|
-
ResolveIOMainServer.prototype.resolveSingleIpPerUserPolicy = function (planTier) {
|
|
2907
|
-
var _a, _b;
|
|
2908
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2909
|
-
var normalizedTier = "".concat(planTier || '').trim().toLowerCase();
|
|
2910
|
-
var tierKeySuffix = this.resolveSocketTierKeySuffix(normalizedTier);
|
|
2911
|
-
if (tierKeySuffix) {
|
|
2912
|
-
var tierPolicyKey = "AI_CODER_SINGLE_IP_PER_USER_".concat(tierKeySuffix);
|
|
2913
|
-
var tierPolicy = this.parseOptionalBoolean((_a = config[tierPolicyKey]) !== null && _a !== void 0 ? _a : process.env[tierPolicyKey]);
|
|
2914
|
-
if (tierPolicy !== null) {
|
|
2915
|
-
return tierPolicy;
|
|
2916
|
-
}
|
|
2917
|
-
}
|
|
2918
|
-
var policy = this.parseOptionalBoolean((_b = config['AI_CODER_SINGLE_IP_PER_USER']) !== null && _b !== void 0 ? _b : process.env.AI_CODER_SINGLE_IP_PER_USER);
|
|
2919
|
-
if (policy !== null) {
|
|
2920
|
-
return policy;
|
|
2921
|
-
}
|
|
2922
|
-
return !!normalizedTier;
|
|
2923
|
-
};
|
|
2924
|
-
ResolveIOMainServer.prototype.resolveSocketPolicyUpgradeUrl = function () {
|
|
2925
|
-
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2926
|
-
var direct = "".concat(config['AI_CODER_SOCKET_UPGRADE_URL'] || process.env.AI_CODER_SOCKET_UPGRADE_URL || '').trim();
|
|
2927
|
-
if (direct) {
|
|
2928
|
-
return direct.replace(/\/$/, '');
|
|
2929
|
-
}
|
|
2930
|
-
var dashboard = "".concat(config['AI_CODER_CLIENT_DASHBOARD_URL'] || process.env.AI_CODER_CLIENT_DASHBOARD_URL || '').trim();
|
|
2931
|
-
if (dashboard) {
|
|
2932
|
-
return dashboard.replace(/\/$/, '');
|
|
2933
|
-
}
|
|
2934
|
-
var root = "".concat(config['AI_CODER_ROOT_URL'] || process.env.AI_CODER_ROOT_URL || config['ROOT_URL'] || process.env.ROOT_URL || '').trim();
|
|
2935
|
-
if (!root) {
|
|
2936
|
-
return '';
|
|
2937
|
-
}
|
|
2938
|
-
return "".concat(root.replace(/\/$/, ''), "/dashboard/client");
|
|
2939
|
-
};
|
|
2940
|
-
ResolveIOMainServer.prototype.resolveSocketUpgradeUrlWithAppId = function () {
|
|
2941
|
-
var base = "".concat(this._socketPolicyUpgradeUrl || '').trim();
|
|
2942
|
-
if (!base) {
|
|
2943
|
-
return '';
|
|
2944
|
-
}
|
|
2945
|
-
var appId = "".concat(process.env.AI_CODER_APP_ID || '').trim();
|
|
2946
|
-
if (!appId) {
|
|
2947
|
-
return base;
|
|
2948
|
-
}
|
|
2949
|
-
var separator = base.includes('?') ? '&' : '?';
|
|
2950
|
-
return "".concat(base).concat(separator, "appId=").concat(encodeURIComponent(appId));
|
|
2951
|
-
};
|
|
2952
|
-
ResolveIOMainServer.prototype.normalizeIpAddress = function (value) {
|
|
2953
|
-
var ip = "".concat(value || '').trim();
|
|
2954
|
-
if (!ip) {
|
|
2955
|
-
return '';
|
|
2956
|
-
}
|
|
2957
|
-
if (ip.includes(',')) {
|
|
2958
|
-
ip = ip.split(',')[0].trim();
|
|
2959
|
-
}
|
|
2960
|
-
if (ip.startsWith('::ffff:')) {
|
|
2961
|
-
ip = ip.slice(7);
|
|
2962
|
-
}
|
|
2963
|
-
if (/^\d+\.\d+\.\d+\.\d+:\d+$/.test(ip)) {
|
|
2964
|
-
ip = ip.split(':')[0].trim();
|
|
2965
|
-
}
|
|
2966
|
-
if (ip === '::1') {
|
|
2967
|
-
return '127.0.0.1';
|
|
2968
|
-
}
|
|
2969
|
-
return ip.toLowerCase();
|
|
2970
|
-
};
|
|
2971
|
-
ResolveIOMainServer.prototype.resolveClientIp = function (req) {
|
|
2972
|
-
var _a, _b, _c, _d;
|
|
2973
|
-
var forwardedFor = this.normalizeHeaderValue((_a = req === null || req === void 0 ? void 0 : req.headers) === null || _a === void 0 ? void 0 : _a['x-forwarded-for']);
|
|
2974
|
-
if (forwardedFor) {
|
|
2975
|
-
return this.normalizeIpAddress(forwardedFor);
|
|
2976
|
-
}
|
|
2977
|
-
var realIp = this.normalizeHeaderValue((_b = req === null || req === void 0 ? void 0 : req.headers) === null || _b === void 0 ? void 0 : _b['x-real-ip']);
|
|
2978
|
-
if (realIp) {
|
|
2979
|
-
return this.normalizeIpAddress(realIp);
|
|
2980
|
-
}
|
|
2981
|
-
var socketIp = ((_c = req === null || req === void 0 ? void 0 : req.socket) === null || _c === void 0 ? void 0 : _c.remoteAddress) || ((_d = req === null || req === void 0 ? void 0 : req.connection) === null || _d === void 0 ? void 0 : _d.remoteAddress) || (req === null || req === void 0 ? void 0 : req.ip) || '';
|
|
2982
|
-
return this.normalizeIpAddress(socketIp);
|
|
2983
|
-
};
|
|
2984
|
-
ResolveIOMainServer.prototype.buildSocketLimitMessage = function (activeSockets) {
|
|
2985
|
-
var tierLabel = this._socketTier ? this._socketTier[0].toUpperCase() + this._socketTier.slice(1) : 'Current';
|
|
2986
|
-
var upgradeUrl = this.resolveSocketUpgradeUrlWithAppId();
|
|
2987
|
-
var base = "Socket connection limit reached (".concat(activeSockets, "/").concat(this._maxClientSockets, ") for the ").concat(tierLabel, " tier.");
|
|
2988
|
-
if (!upgradeUrl) {
|
|
2989
|
-
return "".concat(base, " Upgrade to increase capacity.");
|
|
2990
|
-
}
|
|
2991
|
-
return "".concat(base, " Upgrade at ").concat(upgradeUrl, ".");
|
|
2992
|
-
};
|
|
2993
|
-
ResolveIOMainServer.prototype.buildSocketLimitCloseReason = function () {
|
|
2994
|
-
return "Socket limit reached (".concat(this._maxClientSockets, ")");
|
|
2995
|
-
};
|
|
2996
|
-
ResolveIOMainServer.prototype.disconnectUserSocketsFromDifferentIps = function (idUser, incomingIp) {
|
|
2997
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2998
|
-
var normalizedUser, normalizedIncomingIp, userSockets, disconnected, userSockets_1, userSockets_1_1, existingSocket, existingIp, e_15_1;
|
|
2999
|
-
var e_15, _a;
|
|
3000
|
-
return __generator(this, function (_b) {
|
|
3001
|
-
switch (_b.label) {
|
|
3002
|
-
case 0:
|
|
3003
|
-
if (!this._websocketManager) {
|
|
3004
|
-
return [2 /*return*/, 0];
|
|
3005
|
-
}
|
|
3006
|
-
normalizedUser = "".concat(idUser || '').trim();
|
|
3007
|
-
normalizedIncomingIp = this.normalizeIpAddress(incomingIp);
|
|
3008
|
-
if (!normalizedUser || !normalizedIncomingIp) {
|
|
3009
|
-
return [2 /*return*/, 0];
|
|
3010
|
-
}
|
|
3011
|
-
userSockets = this._websocketManager.getUserWebSockets(normalizedUser);
|
|
3012
|
-
disconnected = 0;
|
|
3013
|
-
_b.label = 1;
|
|
3014
|
-
case 1:
|
|
3015
|
-
_b.trys.push([1, 6, 7, 8]);
|
|
3016
|
-
userSockets_1 = __values(userSockets), userSockets_1_1 = userSockets_1.next();
|
|
3017
|
-
_b.label = 2;
|
|
3018
|
-
case 2:
|
|
3019
|
-
if (!!userSockets_1_1.done) return [3 /*break*/, 5];
|
|
3020
|
-
existingSocket = userSockets_1_1.value;
|
|
3021
|
-
existingIp = this.normalizeIpAddress(existingSocket === null || existingSocket === void 0 ? void 0 : existingSocket['client_ip']);
|
|
3022
|
-
if (!existingIp || existingIp === normalizedIncomingIp) {
|
|
3023
|
-
return [3 /*break*/, 4];
|
|
3024
|
-
}
|
|
3025
|
-
this.logConnectDebug('WS single-ip enforcement disconnect', {
|
|
3026
|
-
id_socket: existingSocket === null || existingSocket === void 0 ? void 0 : existingSocket['id_socket'],
|
|
3027
|
-
id_user: normalizedUser,
|
|
3028
|
-
existingIp: existingIp,
|
|
3029
|
-
incomingIp: normalizedIncomingIp
|
|
3030
|
-
});
|
|
3031
|
-
return [4 /*yield*/, this.unsubscribeWS(existingSocket)];
|
|
3032
|
-
case 3:
|
|
3033
|
-
_b.sent();
|
|
3034
|
-
if (existingSocket.readyState === WebSocket.OPEN || existingSocket.readyState === WebSocket.CONNECTING) {
|
|
3035
|
-
try {
|
|
3036
|
-
existingSocket.close(1008, 'Signed in from another IP');
|
|
3037
|
-
}
|
|
3038
|
-
catch (_c) { }
|
|
3039
|
-
}
|
|
3040
|
-
disconnected += 1;
|
|
3041
|
-
_b.label = 4;
|
|
3042
|
-
case 4:
|
|
3043
|
-
userSockets_1_1 = userSockets_1.next();
|
|
3044
|
-
return [3 /*break*/, 2];
|
|
3045
|
-
case 5: return [3 /*break*/, 8];
|
|
3046
|
-
case 6:
|
|
3047
|
-
e_15_1 = _b.sent();
|
|
3048
|
-
e_15 = { error: e_15_1 };
|
|
3049
|
-
return [3 /*break*/, 8];
|
|
3050
|
-
case 7:
|
|
3051
|
-
try {
|
|
3052
|
-
if (userSockets_1_1 && !userSockets_1_1.done && (_a = userSockets_1.return)) _a.call(userSockets_1);
|
|
3053
|
-
}
|
|
3054
|
-
finally { if (e_15) throw e_15.error; }
|
|
3055
|
-
return [7 /*endfinally*/];
|
|
3056
|
-
case 8: return [2 /*return*/, disconnected];
|
|
3057
|
-
}
|
|
3058
|
-
});
|
|
3059
|
-
});
|
|
3060
|
-
};
|
|
3061
|
-
ResolveIOMainServer.prototype.evaluateClientSocketAdmission = function (idUser, req) {
|
|
3062
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3063
|
-
var normalizedUser, clientIp, activeSockets, message;
|
|
3064
|
-
return __generator(this, function (_a) {
|
|
3065
|
-
switch (_a.label) {
|
|
3066
|
-
case 0:
|
|
3067
|
-
normalizedUser = "".concat(idUser || '').trim();
|
|
3068
|
-
clientIp = this.resolveClientIp(req);
|
|
3069
|
-
if (!this._singleIpPerUser) return [3 /*break*/, 2];
|
|
3070
|
-
return [4 /*yield*/, this.disconnectUserSocketsFromDifferentIps(normalizedUser, clientIp)];
|
|
3071
|
-
case 1:
|
|
3072
|
-
_a.sent();
|
|
3073
|
-
_a.label = 2;
|
|
3074
|
-
case 2:
|
|
3075
|
-
if (this._maxClientSockets > 0 && this._websocketManager) {
|
|
3076
|
-
activeSockets = this._websocketManager.getActiveWebSocketCount();
|
|
3077
|
-
if (activeSockets >= this._maxClientSockets) {
|
|
3078
|
-
message = this.buildSocketLimitMessage(activeSockets);
|
|
3079
|
-
this.logConnectDebug('WS socket limit blocked', {
|
|
3080
|
-
id_user: normalizedUser,
|
|
3081
|
-
clientIp: clientIp,
|
|
3082
|
-
activeSockets: activeSockets,
|
|
3083
|
-
maxClientSockets: this._maxClientSockets
|
|
3084
|
-
});
|
|
3085
|
-
return [2 /*return*/, {
|
|
3086
|
-
allowed: false,
|
|
3087
|
-
statusCode: 429,
|
|
3088
|
-
message: message,
|
|
3089
|
-
clientIp: clientIp
|
|
3090
|
-
}];
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
3093
|
-
return [2 /*return*/, {
|
|
3094
|
-
allowed: true,
|
|
3095
|
-
statusCode: 200,
|
|
3096
|
-
message: '',
|
|
3097
|
-
clientIp: clientIp
|
|
3098
|
-
}];
|
|
3099
|
-
}
|
|
3100
|
-
});
|
|
3101
|
-
});
|
|
3102
|
-
};
|
|
3103
|
-
ResolveIOMainServer.prototype.logConnectDebug = function (message, details) {
|
|
3104
|
-
if (!this._wsConnectDebug) {
|
|
3105
|
-
return;
|
|
3106
|
-
}
|
|
3107
|
-
if (details) {
|
|
3108
|
-
console.log(new Date(), '[Connect Debug]', message, JSON.stringify(details));
|
|
3109
|
-
}
|
|
3110
|
-
else {
|
|
3111
|
-
console.log(new Date(), '[Connect Debug]', message);
|
|
3112
|
-
}
|
|
3113
|
-
};
|
|
3114
|
-
ResolveIOMainServer.prototype.triggerClientHeartbeat = function (ws) {
|
|
3115
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3116
|
-
var err_1;
|
|
3117
|
-
var _this = this;
|
|
3118
|
-
var _a;
|
|
3119
|
-
return __generator(this, function (_b) {
|
|
3120
|
-
switch (_b.label) {
|
|
3121
|
-
case 0:
|
|
3122
|
-
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
3123
|
-
return [2 /*return*/];
|
|
3124
|
-
}
|
|
3125
|
-
ws['pingTime'] = new Date();
|
|
3126
|
-
_b.label = 1;
|
|
3127
|
-
case 1:
|
|
3128
|
-
_b.trys.push([1, 2, , 4]);
|
|
3129
|
-
if (typeof ws.ping === 'function') {
|
|
3130
|
-
ws.ping();
|
|
3131
|
-
}
|
|
3132
|
-
return [3 /*break*/, 4];
|
|
3133
|
-
case 2:
|
|
3134
|
-
err_1 = _b.sent();
|
|
3135
|
-
if ((_a = this._methodManager) === null || _a === void 0 ? void 0 : _a.getEnableDebug()) {
|
|
3136
|
-
console.log(new Date(), 'Server App', 'Error WS Ping Frame', err_1);
|
|
3137
|
-
}
|
|
3138
|
-
return [4 /*yield*/, this.unsubscribeWS(ws)];
|
|
3139
|
-
case 3:
|
|
3140
|
-
_b.sent();
|
|
3141
|
-
return [2 /*return*/];
|
|
3142
|
-
case 4:
|
|
3143
|
-
ws.send('ping', function (error) { return __awaiter(_this, void 0, void 0, function () {
|
|
3144
|
-
var _a;
|
|
3145
|
-
return __generator(this, function (_b) {
|
|
3146
|
-
switch (_b.label) {
|
|
3147
|
-
case 0:
|
|
3148
|
-
if (!error) return [3 /*break*/, 2];
|
|
3149
|
-
if ((_a = this._methodManager) === null || _a === void 0 ? void 0 : _a.getEnableDebug()) {
|
|
3150
|
-
console.log(new Date(), 'Server App', 'Error WS Ping');
|
|
3151
|
-
}
|
|
3152
|
-
return [4 /*yield*/, this.unsubscribeWS(ws)];
|
|
3153
|
-
case 1:
|
|
3154
|
-
_b.sent();
|
|
3155
|
-
_b.label = 2;
|
|
3156
|
-
case 2: return [2 /*return*/];
|
|
3157
|
-
}
|
|
3158
|
-
});
|
|
3159
|
-
}); });
|
|
3160
|
-
return [2 /*return*/];
|
|
3161
|
-
}
|
|
3162
|
-
});
|
|
3163
|
-
});
|
|
3164
|
-
};
|
|
3165
|
-
ResolveIOMainServer.prototype.shouldDeferHeartbeat = function (ws) {
|
|
3166
|
-
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
3167
|
-
return false;
|
|
3168
|
-
}
|
|
3169
|
-
var bufferedAmount = typeof ws.bufferedAmount === 'number' ? ws.bufferedAmount : 0;
|
|
3170
|
-
return bufferedAmount >= this._clientHeartbeatBackpressureBytes;
|
|
3171
|
-
};
|
|
3172
|
-
ResolveIOMainServer.prototype.handleClientMessage = function (ws, msg) {
|
|
3173
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3174
|
-
var messageRoute_1, messageDate, messageId, type, subType, pub, serverRes, offlineUpdates, i, update, data, updateRoute, updateDate, updateMessageId, updateType, method, serverResMethod, err_2, dataCopy_1, date, msgId_1, msgType, methodName_1, ack, method, forceWorker, targetWorkerIndex, targetWorkerInstance, hasWorkerForMethod, isAiCodex, isExcludedFromWorker, shouldDispatchToWorker, queueSnapshot, err_3;
|
|
3175
|
-
var _a;
|
|
3176
|
-
var _this = this;
|
|
3177
|
-
return __generator(this, function (_b) {
|
|
3178
|
-
switch (_b.label) {
|
|
3179
|
-
case 0:
|
|
3180
|
-
_b.trys.push([0, 24, , 25]);
|
|
3181
|
-
messageRoute_1 = msg[0];
|
|
3182
|
-
messageDate = msg[1];
|
|
3183
|
-
messageId = msg[2];
|
|
3184
|
-
type = msg[3];
|
|
3185
|
-
if (!this.publicProgram && this._clientRoutes.some(function (a) { return messageRoute_1.includes(a); }) && !ws['doc_user'].roles.groups.some(function (a) { return a.views.some(function (b) { return messageRoute_1.includes(b) || b.includes(messageRoute_1); }); }) && !ws['doc_user'].roles.super_admin) {
|
|
3186
|
-
return [2 /*return*/];
|
|
3187
|
-
}
|
|
3188
|
-
if (!(type === 'subscription')) return [3 /*break*/, 4];
|
|
3189
|
-
subType = msg[4];
|
|
3190
|
-
pub = msg[5];
|
|
3191
|
-
this.logConnectDebug('Subscription message', {
|
|
3192
|
-
subType: subType,
|
|
3193
|
-
publication: pub,
|
|
3194
|
-
messageId: messageId,
|
|
3195
|
-
messageRoute: messageRoute_1,
|
|
3196
|
-
args: Math.max(0, msg.length - 6),
|
|
3197
|
-
id_socket: ws ? ws['id_socket'] : null,
|
|
3198
|
-
user: ws ? ws['user'] : null
|
|
3199
|
-
});
|
|
3200
|
-
if (!(subType === 'sub')) return [3 /*break*/, 2];
|
|
3201
|
-
return [4 /*yield*/, this._subscriptionManager.subscribe(messageRoute_1, messageDate, ws, messageId, pub, msg.slice(6))];
|
|
3202
|
-
case 1:
|
|
3203
|
-
_b.sent();
|
|
3204
|
-
return [3 /*break*/, 3];
|
|
3205
|
-
case 2:
|
|
3206
|
-
this._subscriptionManager.unsubscribe(messageRoute_1, messageDate, ws, messageId, pub, msg.slice(6));
|
|
3207
|
-
_b.label = 3;
|
|
3208
|
-
case 3: return [3 /*break*/, 23];
|
|
3209
|
-
case 4:
|
|
3210
|
-
if (!(!this.publicProgram && type === 'offline')) return [3 /*break*/, 16];
|
|
3211
|
-
serverRes = {
|
|
3212
|
-
messageId: messageId,
|
|
3213
|
-
hasError: false,
|
|
3214
|
-
data: 'ACK'
|
|
3215
|
-
};
|
|
3216
|
-
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
3217
|
-
this._websocketManager.send(ws, serverRes);
|
|
3218
|
-
}
|
|
3219
|
-
this._offlineUpdates.push(ws);
|
|
3220
|
-
offlineUpdates = msg[4];
|
|
3221
|
-
i = 0;
|
|
3222
|
-
_b.label = 5;
|
|
3223
|
-
case 5:
|
|
3224
|
-
if (!(i < offlineUpdates.length)) return [3 /*break*/, 15];
|
|
3225
|
-
update = offlineUpdates[i];
|
|
3226
|
-
data = update.data;
|
|
3227
|
-
updateRoute = data.shift();
|
|
3228
|
-
updateDate = data.shift();
|
|
3229
|
-
updateMessageId = data.shift();
|
|
3230
|
-
updateType = data.shift();
|
|
3231
|
-
method = data.shift();
|
|
3232
|
-
serverResMethod = {
|
|
3233
|
-
messageId: updateMessageId,
|
|
3234
|
-
hasError: false,
|
|
3235
|
-
data: 'ACK'
|
|
3236
|
-
};
|
|
3237
|
-
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
3238
|
-
this._websocketManager.send(ws, serverResMethod);
|
|
3239
|
-
}
|
|
3240
|
-
if (method === 'insertDocument' && data[0] === 'driver-gps') {
|
|
3241
|
-
return [3 /*break*/, 14];
|
|
3242
|
-
}
|
|
3243
|
-
if (!shouldWriteClientRequestLog(method)) return [3 /*break*/, 8];
|
|
3244
|
-
if (!resolveio_server_app_1.ResolveIOServer.shouldWriteLogsOffline()) return [3 /*break*/, 6];
|
|
3245
|
-
resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({
|
|
3246
|
-
type: 'log',
|
|
3247
|
-
data: {
|
|
3248
|
-
_id: (0, common_1.objectIdHexString)(),
|
|
3249
|
-
createdAt: new Date(),
|
|
3250
|
-
type: 'client-request',
|
|
3251
|
-
collection: '',
|
|
3252
|
-
id_document: '',
|
|
3253
|
-
payload: (0, common_1.getBinarySize)(JSON.stringify([data])) < 1000000 ? JSON.stringify([data], null, 2) : 'Too Big',
|
|
3254
|
-
method: method,
|
|
3255
|
-
id_user: ws['id_user'] || '',
|
|
3256
|
-
user: ws['user'] || '',
|
|
3257
|
-
messageId: messageId,
|
|
3258
|
-
route: messageRoute_1,
|
|
3259
|
-
instance_index: process.env.NODE_APP_INSTANCE || '0'
|
|
3260
|
-
}
|
|
3261
|
-
});
|
|
3262
|
-
return [3 /*break*/, 8];
|
|
3263
|
-
case 6: return [4 /*yield*/, log_collection_1.Logs.insertOne({
|
|
3264
|
-
_id: (0, common_1.objectIdHexString)(),
|
|
3265
|
-
type: 'client-request',
|
|
3266
|
-
collection: '',
|
|
3267
|
-
id_document: '',
|
|
3268
|
-
payload: (0, common_1.getBinarySize)(JSON.stringify([data])) < 1000000 ? JSON.stringify([data], null, 2) : 'Too Big',
|
|
3269
|
-
method: method,
|
|
3270
|
-
id_user: ws['id_user'] || '',
|
|
3271
|
-
user: ws['user'] || '',
|
|
3272
|
-
messageId: messageId,
|
|
3273
|
-
route: messageRoute_1,
|
|
3274
|
-
client: 'ResolveIO',
|
|
3275
|
-
instance: resolveio_server_app_1.ResolveIOServer.getInstanceHost(),
|
|
3276
|
-
instance_index: process.env.NODE_APP_INSTANCE || '0'
|
|
3277
|
-
})];
|
|
3278
|
-
case 7:
|
|
3279
|
-
_b.sent();
|
|
3280
|
-
_b.label = 8;
|
|
3281
|
-
case 8:
|
|
3282
|
-
if (!this._methodManager._methods[method]) return [3 /*break*/, 13];
|
|
3283
|
-
_b.label = 9;
|
|
3284
|
-
case 9:
|
|
3285
|
-
_b.trys.push([9, 11, , 12]);
|
|
3286
|
-
return [4 /*yield*/, (_a = this._methodManager.callMethod).call.apply(_a, __spreadArray([Object.assign({}, this._methodManager, method_manager_1.MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] }), method], __read(data), false))];
|
|
3287
|
-
case 10:
|
|
3288
|
-
_b.sent();
|
|
3289
|
-
return [3 /*break*/, 12];
|
|
3290
|
-
case 11:
|
|
3291
|
-
err_2 = _b.sent();
|
|
3292
|
-
console.log(new Date(), 'Offline Error', JSON.stringify(err_2, null, 2));
|
|
3293
|
-
return [3 /*break*/, 12];
|
|
3294
|
-
case 12:
|
|
3295
|
-
if (method === 'updateDocumentOffline' || method === 'updateDocumentPropsOffline') {
|
|
3296
|
-
resolveio_server_app_1.ResolveIOServer.getMongoManager().invalidateQueryCache(data[0]);
|
|
3297
|
-
}
|
|
3298
|
-
return [3 /*break*/, 14];
|
|
3299
|
-
case 13:
|
|
3300
|
-
console.log('Offline - Could not find method: ' + method);
|
|
3301
|
-
_b.label = 14;
|
|
3302
|
-
case 14:
|
|
3303
|
-
i++;
|
|
3304
|
-
return [3 /*break*/, 5];
|
|
3305
|
-
case 15:
|
|
3306
|
-
this._offlineUpdates.splice(this._offlineUpdates.map(function (a) { return a['id_socket']; }).indexOf(ws['id_socket']), 1);
|
|
3307
|
-
return [3 /*break*/, 23];
|
|
3308
|
-
case 16:
|
|
3309
|
-
dataCopy_1 = __spreadArray([], __read(msg), false);
|
|
3310
|
-
dataCopy_1.shift();
|
|
3311
|
-
date = dataCopy_1.shift();
|
|
3312
|
-
msgId_1 = dataCopy_1.shift();
|
|
3313
|
-
msgType = dataCopy_1.shift();
|
|
3314
|
-
if (!(msgType === 'method')) return [3 /*break*/, 23];
|
|
3315
|
-
methodName_1 = dataCopy_1.shift();
|
|
3316
|
-
if (ws['user_readonly']) {
|
|
3317
|
-
return [2 /*return*/];
|
|
3318
|
-
}
|
|
3319
|
-
if (!shouldWriteClientRequestLog(methodName_1)) return [3 /*break*/, 19];
|
|
3320
|
-
if (!resolveio_server_app_1.ResolveIOServer.shouldWriteLogsOffline()) return [3 /*break*/, 17];
|
|
3321
|
-
resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({
|
|
3322
|
-
type: 'log',
|
|
3323
|
-
data: {
|
|
3324
|
-
_id: (0, common_1.objectIdHexString)(),
|
|
3325
|
-
createdAt: new Date(),
|
|
3326
|
-
type: 'client-request',
|
|
3327
|
-
collection: '',
|
|
3328
|
-
id_document: '',
|
|
3329
|
-
payload: (0, common_1.getBinarySize)(JSON.stringify([dataCopy_1])) < 1000000 ? JSON.stringify([dataCopy_1], null, 2) : 'Too Big',
|
|
3330
|
-
method: methodName_1,
|
|
3331
|
-
id_user: ws['id_user'] || '',
|
|
3332
|
-
user: ws['user'] || '',
|
|
3333
|
-
messageId: messageId,
|
|
3334
|
-
route: messageRoute_1,
|
|
3335
|
-
instance_index: process.env.NODE_APP_INSTANCE || '0'
|
|
3336
|
-
}
|
|
3337
|
-
});
|
|
3338
|
-
return [3 /*break*/, 19];
|
|
3339
|
-
case 17: return [4 /*yield*/, log_collection_1.Logs.insertOne({
|
|
3340
|
-
_id: (0, common_1.objectIdHexString)(),
|
|
3341
|
-
type: 'client-request',
|
|
3342
|
-
collection: '',
|
|
3343
|
-
id_document: '',
|
|
3344
|
-
payload: (0, common_1.getBinarySize)(JSON.stringify([dataCopy_1])) < 1000000 ? JSON.stringify([dataCopy_1], null, 2) : 'Too Big',
|
|
3345
|
-
method: methodName_1,
|
|
3346
|
-
id_user: ws['id_user'] || '',
|
|
3347
|
-
user: ws['user'] || '',
|
|
3348
|
-
messageId: messageId,
|
|
3349
|
-
route: messageRoute_1,
|
|
3350
|
-
client: 'ResolveIO',
|
|
3351
|
-
instance: resolveio_server_app_1.ResolveIOServer.getInstanceHost(),
|
|
3352
|
-
instance_index: process.env.NODE_APP_INSTANCE || '0'
|
|
3353
|
-
})];
|
|
3354
|
-
case 18:
|
|
3355
|
-
_b.sent();
|
|
3356
|
-
_b.label = 19;
|
|
3357
|
-
case 19:
|
|
3358
|
-
ack = {
|
|
3359
|
-
messageId: msgId_1,
|
|
3360
|
-
hasError: false,
|
|
3361
|
-
data: 'ACK'
|
|
3362
|
-
};
|
|
3363
|
-
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
3364
|
-
this._websocketManager.send(ws, ack);
|
|
3365
|
-
}
|
|
3366
|
-
method = this._methodManager.getMethod(methodName_1);
|
|
3367
|
-
forceWorker = this._isWorkersEnabled && !!(method === null || method === void 0 ? void 0 : method.forceWorker);
|
|
3368
|
-
targetWorkerIndex = this._isWorkersEnabled && method ? method.targetWorkerIndex : null;
|
|
3369
|
-
targetWorkerInstance = this._isWorkersEnabled && method ? method.targetWorkerInstance : null;
|
|
3370
|
-
hasWorkerForMethod = this._workerDispatcherManager ? this._workerDispatcherManager.hasWorkersForMethod(methodName_1) : false;
|
|
3371
|
-
isAiCodex = methodName_1 === 'aiCoderTerminalRunCodex' || methodName_1 === 'aiCoderAppRunCodex';
|
|
3372
|
-
isExcludedFromWorker = (methodName_1 === 'find' ||
|
|
3373
|
-
methodName_1 === 'insertDocument' ||
|
|
3374
|
-
methodName_1 === 'countWithQuery' ||
|
|
3375
|
-
methodName_1 === 'findOne' ||
|
|
3376
|
-
methodName_1 === 'updateDocumentProps' ||
|
|
3377
|
-
methodName_1 === 'findWithOptions' ||
|
|
3378
|
-
methodName_1 === 'updateDocument' ||
|
|
3379
|
-
methodName_1 === 'insertErrorLog' ||
|
|
3380
|
-
methodName_1 === 'removeDocument' ||
|
|
3381
|
-
methodName_1 === 'supportCreateBillingUser' ||
|
|
3382
|
-
methodName_1 === 'getSignedUrl' ||
|
|
3383
|
-
methodName_1 === 'getSignedUrls' ||
|
|
3384
|
-
methodName_1 === 'getSignedUrlWithId' ||
|
|
3385
|
-
methodName_1 === 'incorrectUser' ||
|
|
3386
|
-
methodName_1 === 'reloadWS' ||
|
|
3387
|
-
methodName_1 === 'reconnectWS' ||
|
|
3388
|
-
methodName_1 === 'disconnectWS');
|
|
3389
|
-
if ((targetWorkerIndex || targetWorkerInstance || forceWorker) && this._isWorkersEnabled && !hasWorkerForMethod && this._methodManager.getEnableDebug()) {
|
|
3390
|
-
console.warn(new Date(), '[WorkerDispatcher] Worker unavailable, running method locally', {
|
|
3391
|
-
method: methodName_1,
|
|
3392
|
-
targetWorkerIndex: targetWorkerIndex || null,
|
|
3393
|
-
targetWorkerInstance: targetWorkerInstance || null,
|
|
3394
|
-
forceWorker: forceWorker
|
|
3395
|
-
});
|
|
3396
|
-
}
|
|
3397
|
-
shouldDispatchToWorker = (method &&
|
|
3398
|
-
!method.skipWorker &&
|
|
3399
|
-
this._isWorkersEnabled &&
|
|
3400
|
-
this._workerDispatcherManager &&
|
|
3401
|
-
hasWorkerForMethod &&
|
|
3402
|
-
(forceWorker || !isExcludedFromWorker));
|
|
3403
|
-
if (isAiCodex && this._aiWorkerDebug) {
|
|
3404
|
-
queueSnapshot = this._workerDispatcherManager ? this._workerDispatcherManager.getQueueSnapshot() : null;
|
|
3405
|
-
console.log(new Date(), '[AI Worker Debug] dispatch check', {
|
|
3406
|
-
isWorkersEnabled: this._isWorkersEnabled,
|
|
3407
|
-
isWorkerInstance: this._isWorkerInstance,
|
|
3408
|
-
forceWorker: forceWorker,
|
|
3409
|
-
hasWorkerForMethod: hasWorkerForMethod,
|
|
3410
|
-
targetWorkerIndex: targetWorkerIndex || null,
|
|
3411
|
-
targetWorkerInstance: targetWorkerInstance || null,
|
|
3412
|
-
shouldDispatchToWorker: shouldDispatchToWorker,
|
|
3413
|
-
queueSnapshot: queueSnapshot
|
|
3414
|
-
});
|
|
3415
|
-
}
|
|
3416
|
-
if (!shouldDispatchToWorker) return [3 /*break*/, 20];
|
|
3417
|
-
this._workerDispatcherManager.sendClientTask(msgId_1, methodName_1, dataCopy_1, {
|
|
3418
|
-
id_user: ws['id_user'],
|
|
3419
|
-
user: ws['user'],
|
|
3420
|
-
id_ws: ws['id_socket']
|
|
3421
|
-
});
|
|
3422
|
-
return [3 /*break*/, 23];
|
|
3423
|
-
case 20:
|
|
3424
|
-
if (!(methodName_1 === 'aiCoderTerminalRunCodex' || methodName_1 === 'aiCoderAppRunCodex')) return [3 /*break*/, 21];
|
|
3425
|
-
if (this._aiWorkerDebug) {
|
|
3426
|
-
console.warn(new Date(), '[AI Worker Debug] AI execution running locally', {
|
|
3427
|
-
isWorkersEnabled: this._isWorkersEnabled,
|
|
3428
|
-
isWorkerInstance: this._isWorkerInstance,
|
|
3429
|
-
targetWorkerIndex: targetWorkerIndex || null,
|
|
3430
|
-
targetWorkerInstance: targetWorkerInstance || null,
|
|
3431
|
-
hasWorkerForMethod: hasWorkerForMethod
|
|
3432
|
-
});
|
|
3433
|
-
}
|
|
3434
|
-
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3435
|
-
var error_10;
|
|
3436
|
-
return __generator(this, function (_a) {
|
|
3437
|
-
switch (_a.label) {
|
|
3438
|
-
case 0:
|
|
3439
|
-
_a.trys.push([0, 2, , 3]);
|
|
3440
|
-
return [4 /*yield*/, this.callMethodLocally(ws, msgId_1, methodName_1, dataCopy_1)];
|
|
3441
|
-
case 1:
|
|
3442
|
-
_a.sent();
|
|
3443
|
-
return [3 /*break*/, 3];
|
|
3444
|
-
case 2:
|
|
3445
|
-
error_10 = _a.sent();
|
|
3446
|
-
console.error(new Date(), 'AI execution run failed:', error_10);
|
|
3447
|
-
return [3 /*break*/, 3];
|
|
3448
|
-
case 3: return [2 /*return*/];
|
|
3449
|
-
}
|
|
3450
|
-
});
|
|
3451
|
-
}); }, 0);
|
|
3452
|
-
return [3 /*break*/, 23];
|
|
3453
|
-
case 21: return [4 /*yield*/, this.callMethodLocally(ws, msgId_1, methodName_1, dataCopy_1)];
|
|
3454
|
-
case 22:
|
|
3455
|
-
_b.sent();
|
|
3456
|
-
_b.label = 23;
|
|
3457
|
-
case 23: return [3 /*break*/, 25];
|
|
3458
|
-
case 24:
|
|
3459
|
-
err_3 = _b.sent();
|
|
3460
|
-
throw err_3;
|
|
3461
|
-
case 25: return [2 /*return*/];
|
|
3462
|
-
}
|
|
3463
|
-
});
|
|
3464
|
-
});
|
|
3465
|
-
};
|
|
3466
|
-
/**
|
|
3467
|
-
* callMethodLocally is your old approach for invoking the method in-process.
|
|
3468
|
-
*/
|
|
3469
|
-
ResolveIOMainServer.prototype.callMethodLocally = function (ws, messageId, method, params) {
|
|
3470
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3471
|
-
var serverRes, result, resultBytes, err_4;
|
|
3472
|
-
var _a;
|
|
3473
|
-
return __generator(this, function (_b) {
|
|
3474
|
-
switch (_b.label) {
|
|
3475
|
-
case 0:
|
|
3476
|
-
serverRes = {
|
|
3477
|
-
messageId: messageId,
|
|
3478
|
-
hasError: false,
|
|
3479
|
-
data: null
|
|
3480
|
-
};
|
|
3481
|
-
_b.label = 1;
|
|
3482
|
-
case 1:
|
|
3483
|
-
_b.trys.push([1, 3, , 4]);
|
|
3484
|
-
return [4 /*yield*/, (_a = this._methodManager.callMethod).call.apply(_a, __spreadArray([Object.assign({}, this._methodManager, method_manager_1.MethodManager.prototype, {
|
|
3485
|
-
id_user: ws['id_user'],
|
|
3486
|
-
user: ws['user'],
|
|
3487
|
-
id_ws: ws['id_socket']
|
|
3488
|
-
}),
|
|
3489
|
-
method], __read(params), false))];
|
|
3490
|
-
case 2:
|
|
3491
|
-
result = _b.sent();
|
|
3492
|
-
serverRes.data = result;
|
|
3493
|
-
if (this._aiWorkerDebug && typeof method === 'string' && method.startsWith('ai')) {
|
|
3494
|
-
resultBytes = null;
|
|
3495
|
-
try {
|
|
3496
|
-
resultBytes = Buffer.byteLength(JSON.stringify(result));
|
|
3497
|
-
}
|
|
3498
|
-
catch (_c) {
|
|
3499
|
-
resultBytes = null;
|
|
3500
|
-
}
|
|
3501
|
-
console.log(new Date(), '[AI Worker Debug] local method result', {
|
|
3502
|
-
method: method,
|
|
3503
|
-
messageId: messageId,
|
|
3504
|
-
id_socket: ws ? ws['id_socket'] : null,
|
|
3505
|
-
id_user: ws ? ws['id_user'] : null,
|
|
3506
|
-
resultBytes: resultBytes
|
|
3507
|
-
});
|
|
3508
|
-
}
|
|
3509
|
-
return [3 /*break*/, 4];
|
|
3510
|
-
case 3:
|
|
3511
|
-
err_4 = _b.sent();
|
|
3512
|
-
serverRes.hasError = true;
|
|
3513
|
-
serverRes.data = err_4 || 'Unknown error';
|
|
3514
|
-
return [3 /*break*/, 4];
|
|
3515
|
-
case 4:
|
|
3516
|
-
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
3517
|
-
this._websocketManager.send(ws, serverRes);
|
|
3518
|
-
}
|
|
3519
|
-
return [2 /*return*/];
|
|
3520
|
-
}
|
|
3521
|
-
});
|
|
3522
|
-
});
|
|
3523
|
-
};
|
|
3524
|
-
/**
|
|
3525
|
-
* Cleanly remove a client from the subscription manager, etc.
|
|
3526
|
-
*/
|
|
3527
|
-
ResolveIOMainServer.prototype.unsubscribeWS = function (ws) {
|
|
3528
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3529
|
-
return __generator(this, function (_a) {
|
|
3530
|
-
switch (_a.label) {
|
|
3531
|
-
case 0:
|
|
3532
|
-
if (this._subscriptionManager && this._methodManager.getEnableDebug()) {
|
|
3533
|
-
console.log(new Date(), 'Server App', 'Unsub WS', ws['user'], ws['id_socket']);
|
|
3534
|
-
}
|
|
3535
|
-
this.logConnectDebug('WS unsubscribe', {
|
|
3536
|
-
id_socket: ws ? ws['id_socket'] : null,
|
|
3537
|
-
id_user: ws ? ws['id_user'] : null,
|
|
3538
|
-
user: ws ? ws['user'] : null
|
|
3539
|
-
});
|
|
3540
|
-
return [4 /*yield*/, this._subscriptionManager.unsubscribeAll(ws)];
|
|
3541
|
-
case 1:
|
|
3542
|
-
_a.sent();
|
|
3543
|
-
ws.removeAllListeners();
|
|
3544
|
-
ws = null;
|
|
3545
|
-
return [2 /*return*/];
|
|
3546
|
-
}
|
|
3547
|
-
});
|
|
3548
|
-
});
|
|
3549
|
-
};
|
|
3550
|
-
ResolveIOMainServer.prototype.getApp = function () {
|
|
3551
|
-
return this._app;
|
|
3552
|
-
};
|
|
3553
|
-
ResolveIOMainServer.prototype.getServerConfig = function () {
|
|
3554
|
-
return resolveio_server_app_1.ResolveIOServer.getServerConfig();
|
|
3555
|
-
};
|
|
3556
|
-
ResolveIOMainServer.prototype.getWorkerDispatcherManager = function () {
|
|
3557
|
-
return this._workerDispatcherManager;
|
|
3558
|
-
};
|
|
3559
|
-
ResolveIOMainServer.prototype.getWorkerServerManager = function () {
|
|
3560
|
-
return this._workerServerManager;
|
|
3561
|
-
};
|
|
3562
|
-
return ResolveIOMainServer;
|
|
3563
|
-
}());
|
|
3564
|
-
exports.ResolveIOMainServer = ResolveIOMainServer;
|
|
3565
|
-
|
|
3566
|
-
//# sourceMappingURL=server-app.js.map
|