@omnizap-system/omnizap 2.5.12
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/.clusterfuzzlite/Dockerfile +10 -0
- package/.env.example +907 -0
- package/.github/codeql/codeql-config.yml +10 -0
- package/.github/dependabot.yml +35 -0
- package/.github/workflows/ci.yml +73 -0
- package/.github/workflows/codeql.yml +106 -0
- package/.github/workflows/db-migration-check.yml +98 -0
- package/.github/workflows/dependency-review.yml +22 -0
- package/.github/workflows/deploy.yml +95 -0
- package/.github/workflows/release.yml +106 -0
- package/.github/workflows/security-attest-provenance.yml +51 -0
- package/.github/workflows/security-gitleaks.yml +34 -0
- package/.github/workflows/security-runner-hardening.yml +31 -0
- package/.github/workflows/security-scorecard.yml +44 -0
- package/.github/workflows/security-zap-baseline.yml +44 -0
- package/.github/workflows/security-zap-full-scan.yml +43 -0
- package/.github/workflows/security-zizmor.yml +36 -0
- package/.github/workflows/wiki-sync.yml +44 -0
- package/.gitleaks.toml +15 -0
- package/.prettierrc +34 -0
- package/CODE_OF_CONDUCT.md +114 -0
- package/LICENSE +56 -0
- package/README.md +110 -0
- package/SECURITY.md +110 -0
- package/app/config/index.js +4 -0
- package/app/configParts/adminIdentity.js +92 -0
- package/app/configParts/baileysConfig.js +1818 -0
- package/app/configParts/groupUtils.js +692 -0
- package/app/configParts/loggerConfig.js +394 -0
- package/app/configParts/messagePersistenceService.js +305 -0
- package/app/connection/baileysCompatibility.test.js +40 -0
- package/app/connection/baileysDbAuthState.js +344 -0
- package/app/connection/socketController.js +2243 -0
- package/app/controllers/messageController.js +7 -0
- package/app/controllers/messagePipeline/commandMiddleware.js +146 -0
- package/app/controllers/messagePipeline/conversationMiddleware.js +183 -0
- package/app/controllers/messagePipeline/messagePipelineMiddlewares.test.js +522 -0
- package/app/controllers/messagePipeline/postProcessingMiddleware.js +41 -0
- package/app/controllers/messagePipeline/preProcessingMiddlewares.js +166 -0
- package/app/controllers/messageProcessingPipeline.js +699 -0
- package/app/modules/adminModule/AGENT.md +4056 -0
- package/app/modules/adminModule/adminAiHelpService.js +56 -0
- package/app/modules/adminModule/adminConfigRuntime.js +177 -0
- package/app/modules/adminModule/commandConfig.json +7122 -0
- package/app/modules/adminModule/groupCommandHandlers.js +1823 -0
- package/app/modules/adminModule/groupCommandHandlers.test.js +350 -0
- package/app/modules/adminModule/groupEventHandlers.js +399 -0
- package/app/modules/aiModule/AGENT.md +547 -0
- package/app/modules/aiModule/aiAiHelpService.js +14 -0
- package/app/modules/aiModule/aiConfigRuntime.js +135 -0
- package/app/modules/aiModule/catCommand.js +967 -0
- package/app/modules/aiModule/commandConfig.json +981 -0
- package/app/modules/analyticsModule/messageAnalysisEventRepository.js +83 -0
- package/app/modules/gameModule/AGENT.md +196 -0
- package/app/modules/gameModule/commandConfig.json +366 -0
- package/app/modules/gameModule/diceCommand.js +42 -0
- package/app/modules/gameModule/gameAiHelpService.js +14 -0
- package/app/modules/gameModule/gameConfigRuntime.js +68 -0
- package/app/modules/menuModule/AGENT.md +205 -0
- package/app/modules/menuModule/commandConfig.json +366 -0
- package/app/modules/menuModule/common.js +316 -0
- package/app/modules/menuModule/menuAiHelpService.js +14 -0
- package/app/modules/menuModule/menuConfigRuntime.js +68 -0
- package/app/modules/menuModule/menus.js +66 -0
- package/app/modules/playModule/AGENT.md +321 -0
- package/app/modules/playModule/commandConfig.json +584 -0
- package/app/modules/playModule/playAiHelpService.js +14 -0
- package/app/modules/playModule/playCommand.js +1417 -0
- package/app/modules/playModule/playConfigRuntime.js +68 -0
- package/app/modules/quoteModule/AGENT.md +199 -0
- package/app/modules/quoteModule/commandConfig.json +366 -0
- package/app/modules/quoteModule/quoteAiHelpService.js +14 -0
- package/app/modules/quoteModule/quoteCommand.js +842 -0
- package/app/modules/quoteModule/quoteConfigRuntime.js +68 -0
- package/app/modules/rpgPokemonModule/AGENT.md +229 -0
- package/app/modules/rpgPokemonModule/commandConfig.json +386 -0
- package/app/modules/rpgPokemonModule/rpgBattleCanvasRenderer.js +795 -0
- package/app/modules/rpgPokemonModule/rpgBattleService.js +2110 -0
- package/app/modules/rpgPokemonModule/rpgBattleService.test.js +770 -0
- package/app/modules/rpgPokemonModule/rpgEvolutionUtils.js +22 -0
- package/app/modules/rpgPokemonModule/rpgPokemonAiHelpService.js +14 -0
- package/app/modules/rpgPokemonModule/rpgPokemonCommand.js +174 -0
- package/app/modules/rpgPokemonModule/rpgPokemonConfigRuntime.js +68 -0
- package/app/modules/rpgPokemonModule/rpgPokemonDomain.js +192 -0
- package/app/modules/rpgPokemonModule/rpgPokemonDomain.test.js +93 -0
- package/app/modules/rpgPokemonModule/rpgPokemonEvolution.test.js +46 -0
- package/app/modules/rpgPokemonModule/rpgPokemonMessages.js +746 -0
- package/app/modules/rpgPokemonModule/rpgPokemonRepository.js +1847 -0
- package/app/modules/rpgPokemonModule/rpgPokemonService.js +6839 -0
- package/app/modules/rpgPokemonModule/rpgProfileCanvasRenderer.js +354 -0
- package/app/modules/statsModule/AGENT.md +320 -0
- package/app/modules/statsModule/commandConfig.json +540 -0
- package/app/modules/statsModule/globalRankingCommand.js +64 -0
- package/app/modules/statsModule/rankingCommand.js +41 -0
- package/app/modules/statsModule/rankingCommon.js +1305 -0
- package/app/modules/statsModule/statsAiHelpService.js +14 -0
- package/app/modules/statsModule/statsConfigRuntime.js +68 -0
- package/app/modules/stickerModule/AGENT.md +692 -0
- package/app/modules/stickerModule/addStickerMetadata.js +239 -0
- package/app/modules/stickerModule/commandConfig.json +1216 -0
- package/app/modules/stickerModule/convertToWebp.js +367 -0
- package/app/modules/stickerModule/stickerAiHelpService.js +14 -0
- package/app/modules/stickerModule/stickerCommand.js +446 -0
- package/app/modules/stickerModule/stickerConfigRuntime.js +68 -0
- package/app/modules/stickerModule/stickerConvertCommand.js +159 -0
- package/app/modules/stickerModule/stickerTextCommand.js +653 -0
- package/app/modules/stickerPackModule/AGENT.md +215 -0
- package/app/modules/stickerPackModule/autoPackCollectorRuntime.js +20 -0
- package/app/modules/stickerPackModule/autoPackCollectorService.js +357 -0
- package/app/modules/stickerPackModule/commandConfig.json +387 -0
- package/app/modules/stickerPackModule/domainEventOutboxRepository.js +227 -0
- package/app/modules/stickerPackModule/domainEvents.js +52 -0
- package/app/modules/stickerPackModule/semanticReclassificationEngine.js +429 -0
- package/app/modules/stickerPackModule/semanticReclassificationEngine.test.js +75 -0
- package/app/modules/stickerPackModule/semanticThemeClusterService.js +544 -0
- package/app/modules/stickerPackModule/stickerAssetClassificationRepository.js +400 -0
- package/app/modules/stickerPackModule/stickerAssetRepository.js +400 -0
- package/app/modules/stickerPackModule/stickerAssetReprocessQueueRepository.js +175 -0
- package/app/modules/stickerPackModule/stickerAutoPackByTagsRuntime.js +3702 -0
- package/app/modules/stickerPackModule/stickerClassificationBackgroundRuntime.js +559 -0
- package/app/modules/stickerPackModule/stickerClassificationService.js +557 -0
- package/app/modules/stickerPackModule/stickerDedicatedTaskWorkerRuntime.js +249 -0
- package/app/modules/stickerPackModule/stickerDomainEventBus.js +65 -0
- package/app/modules/stickerPackModule/stickerDomainEventConsumerRuntime.js +208 -0
- package/app/modules/stickerPackModule/stickerMarketplaceDriftService.js +99 -0
- package/app/modules/stickerPackModule/stickerObjectStorageService.js +285 -0
- package/app/modules/stickerPackModule/stickerPackAiHelpService.js +14 -0
- package/app/modules/stickerPackModule/stickerPackCommandHandlers.js +1148 -0
- package/app/modules/stickerPackModule/stickerPackConfigRuntime.js +68 -0
- package/app/modules/stickerPackModule/stickerPackEngagementRepository.js +152 -0
- package/app/modules/stickerPackModule/stickerPackErrors.js +30 -0
- package/app/modules/stickerPackModule/stickerPackInteractionEventRepository.js +101 -0
- package/app/modules/stickerPackModule/stickerPackItemRepository.js +432 -0
- package/app/modules/stickerPackModule/stickerPackMarketplaceService.js +313 -0
- package/app/modules/stickerPackModule/stickerPackMessageService.js +268 -0
- package/app/modules/stickerPackModule/stickerPackRepository.js +450 -0
- package/app/modules/stickerPackModule/stickerPackScoreSnapshotRepository.js +179 -0
- package/app/modules/stickerPackModule/stickerPackScoreSnapshotRuntime.js +271 -0
- package/app/modules/stickerPackModule/stickerPackService.js +733 -0
- package/app/modules/stickerPackModule/stickerPackServiceRuntime.js +32 -0
- package/app/modules/stickerPackModule/stickerPackUtils.js +107 -0
- package/app/modules/stickerPackModule/stickerStorageService.js +559 -0
- package/app/modules/stickerPackModule/stickerWorkerPipelineRuntime.js +242 -0
- package/app/modules/stickerPackModule/stickerWorkerTaskQueueRepository.js +242 -0
- package/app/modules/systemMetricsModule/AGENT.md +193 -0
- package/app/modules/systemMetricsModule/commandConfig.json +344 -0
- package/app/modules/systemMetricsModule/pingCommand.js +399 -0
- package/app/modules/systemMetricsModule/systemMetricsAiHelpService.js +14 -0
- package/app/modules/systemMetricsModule/systemMetricsConfigRuntime.js +68 -0
- package/app/modules/tiktokModule/AGENT.md +196 -0
- package/app/modules/tiktokModule/commandConfig.json +366 -0
- package/app/modules/tiktokModule/tiktokAiHelpService.js +14 -0
- package/app/modules/tiktokModule/tiktokCommand.js +716 -0
- package/app/modules/tiktokModule/tiktokConfigRuntime.js +68 -0
- package/app/modules/userModule/AGENT.md +200 -0
- package/app/modules/userModule/commandConfig.json +386 -0
- package/app/modules/userModule/userAiHelpService.js +14 -0
- package/app/modules/userModule/userCommand.js +1155 -0
- package/app/modules/userModule/userConfigRuntime.js +68 -0
- package/app/modules/waifuPicsModule/AGENT.md +431 -0
- package/app/modules/waifuPicsModule/commandConfig.json +780 -0
- package/app/modules/waifuPicsModule/waifuPicsAiHelpService.js +14 -0
- package/app/modules/waifuPicsModule/waifuPicsCommand.js +586 -0
- package/app/modules/waifuPicsModule/waifuPicsConfigRuntime.js +68 -0
- package/app/observability/metrics.js +766 -0
- package/app/services/ai/aiHelpResponseCacheRepository.js +280 -0
- package/app/services/ai/aiLearningRepository.js +400 -0
- package/app/services/ai/commandConfigEnrichmentRepository.js +769 -0
- package/app/services/ai/commandConfigEnrichmentService.js +452 -0
- package/app/services/ai/commandConfigValidationService.js +443 -0
- package/app/services/ai/commandToolBuilderService.js +192 -0
- package/app/services/ai/conversationRouterService.js +516 -0
- package/app/services/ai/geminiService.js +115 -0
- package/app/services/ai/geminiService.test.js +87 -0
- package/app/services/ai/globalModuleAiHelpService.js +1412 -0
- package/app/services/ai/globalToolCallingService.js +203 -0
- package/app/services/ai/messageCommandExecutionService.js +391 -0
- package/app/services/ai/moduleAiHelpCoreService.js +1099 -0
- package/app/services/ai/moduleAiHelpWrapperFactory.js +65 -0
- package/app/services/ai/moduleCommandConfigRuntimeService.js +113 -0
- package/app/services/ai/moduleToolExecutorService.js +464 -0
- package/app/services/ai/moduleToolRegistryService.js +178 -0
- package/app/services/ai/toolCandidateSelectorService.js +781 -0
- package/app/services/auth/googleWebLinkService.js +80 -0
- package/app/services/auth/whatsappLoginLinkService.js +230 -0
- package/app/services/external/pokeApiService.js +398 -0
- package/app/services/group/groupMetadataService.js +311 -0
- package/app/services/infra/dbWriteQueue.js +874 -0
- package/app/services/infra/featureFlagService.js +131 -0
- package/app/services/infra/queueUtils.js +55 -0
- package/app/services/messaging/captchaService.js +491 -0
- package/app/services/messaging/messagePersistenceService.js +1 -0
- package/app/services/messaging/newsBroadcastService.js +347 -0
- package/app/services/sticker/stickerFocusService.js +347 -0
- package/app/services/sticker/stickerFocusService.test.js +43 -0
- package/app/store/aiPromptStore.js +38 -0
- package/app/store/conversationSessionStore.js +131 -0
- package/app/store/groupConfigStore.js +58 -0
- package/app/store/premiumUserStore.js +54 -0
- package/app/utils/antiLink/antiLinkModule.js +700 -0
- package/app/utils/http/getImageBufferModule.js +18 -0
- package/app/utils/json/jsonSanitizer.js +113 -0
- package/app/utils/json/jsonSanitizer.test.js +40 -0
- package/app/utils/systemMetrics/systemMetricsModule.js +88 -0
- package/app/workers/aiLearningWorker.js +605 -0
- package/app/workers/commandConfigEnrichmentWorker.js +242 -0
- package/database/index.js +2075 -0
- package/database/init.js +151 -0
- package/database/migrations/.gitkeep +0 -0
- package/database/migrations/20260307_d0_hardening_down.sql +64 -0
- package/database/migrations/20260307_d0_hardening_up.sql +79 -0
- package/database/migrations/20260307_d1_terms_acceptance_down.sql +11 -0
- package/database/migrations/20260307_d1_terms_acceptance_up.sql +37 -0
- package/database/migrations/20260307_d2_auth_hardening_down.sql +75 -0
- package/database/migrations/20260307_d2_auth_hardening_up.sql +100 -0
- package/database/migrations/20260314_d7_canonical_sender_down.sql +53 -0
- package/database/migrations/20260314_d7_canonical_sender_up.sql +114 -0
- package/database/migrations/20260406_d30_security_analytics_down.sql +95 -0
- package/database/migrations/20260406_d30_security_analytics_up.sql +292 -0
- package/database/migrations/20260407_d31_web_google_session_token_hardening_down.sql +2 -0
- package/database/migrations/20260407_d31_web_google_session_token_hardening_up.sql +17 -0
- package/database/migrations/20260408_d32_ai_help_response_cache_down.sql +1 -0
- package/database/migrations/20260408_d32_ai_help_response_cache_up.sql +22 -0
- package/database/migrations/20260409_d33_ai_learning_tables_down.sql +4 -0
- package/database/migrations/20260409_d33_ai_learning_tables_up.sql +52 -0
- package/database/migrations/20260410_d34_command_config_enrichment_down.sql +3 -0
- package/database/migrations/20260410_d34_command_config_enrichment_up.sql +48 -0
- package/database/schema.sql +1186 -0
- package/docker-compose.yml +104 -0
- package/docs/audits/stickerCatalogController-out-of-scope.md +103 -0
- package/docs/audits/stickerCatalogController-symbols.md +58 -0
- package/docs/compliance/acceptable-use-policy-2026-03-07.md +35 -0
- package/docs/compliance/dpa-b2b-standard-2026-03-07.md +80 -0
- package/docs/compliance/monthly-compliance-checklist-2026-03-07.md +88 -0
- package/docs/compliance/notice-and-takedown-policy-2026-03-07.md +34 -0
- package/docs/compliance/privacy-policy-2026-03-07.md +75 -0
- package/docs/compliance/subprocessors-inventory-2026-03-07.md +16 -0
- package/docs/database/production-db-evolution-runbook-2026q1.md +365 -0
- package/docs/security/dsar-lgpd-runbook-2026-03-07.md +86 -0
- package/docs/security/incident-response-lgpd-anpd-runbook-2026-03-07.md +77 -0
- package/docs/security/network-hardening-runbook-2026-03-07.md +137 -0
- package/docs/seo/omnizap-seo-playbook-br-2026-02-28.md +238 -0
- package/docs/seo/satellite-page-template.md +116 -0
- package/docs/seo/satellite-pages-phase1.json +364 -0
- package/docs/wiki/Home.md +120 -0
- package/docs/wiki/pair-extraordinaire-2026-03-08.md +3 -0
- package/docs/wiki/recent-changes-2026-03-08.md +47 -0
- package/ecosystem.prod.config.cjs +135 -0
- package/eslint.config.js +89 -0
- package/index.js +488 -0
- package/ml/clip_classifier/Dockerfile +18 -0
- package/ml/clip_classifier/README.md +118 -0
- package/ml/clip_classifier/adaptive_scoring.py +40 -0
- package/ml/clip_classifier/classifier.py +654 -0
- package/ml/clip_classifier/embedding_store.py +481 -0
- package/ml/clip_classifier/env_loader.py +15 -0
- package/ml/clip_classifier/llm_label_expander.py +144 -0
- package/ml/clip_classifier/main.py +213 -0
- package/ml/clip_classifier/requirements.txt +10 -0
- package/ml/clip_classifier/similarity_engine.py +74 -0
- package/new-logo.png +0 -0
- package/observability/alert-rules.yml +60 -0
- package/observability/grafana/dashboards/omnizap-mysql.json +136 -0
- package/observability/grafana/dashboards/omnizap-overview.json +170 -0
- package/observability/grafana/provisioning/dashboards/dashboards.yml +11 -0
- package/observability/grafana/provisioning/datasources/datasources.yml +15 -0
- package/observability/loki-config.yml +38 -0
- package/observability/mysql-setup.sql +46 -0
- package/observability/prometheus.yml +35 -0
- package/observability/promtail-config.yml +84 -0
- package/observability/sticker-catalog-slo.md +83 -0
- package/observability/sticker-scale-hardening-rollout.md +128 -0
- package/package.json +144 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/assets/css/commands-react.input.css +71 -0
- package/public/assets/css/create-pack-react.input.css +31 -0
- package/public/assets/css/home-react.input.css +106 -0
- package/public/assets/css/login-react.input.css +58 -0
- package/public/assets/css/stickers-react.input.css +18 -0
- package/public/assets/css/terms-react.input.css +115 -0
- package/public/assets/css/user-react.input.css +57 -0
- package/public/assets/images/brand-icon-192.png +0 -0
- package/public/assets/images/brand-logo-128.webp +0 -0
- package/public/assets/images/hero-banner-1280.jpg +0 -0
- package/public/comandos/commands-catalog.json +4517 -0
- package/public/css/api-docs.css +161 -0
- package/public/css/stickers-admin.css +1288 -0
- package/public/css/styles.css +679 -0
- package/public/css/systemadm/admin.css +474 -0
- package/public/css/systemadm/base.css +73 -0
- package/public/css/systemadm/components.css +662 -0
- package/public/css/systemadm/layout.css +229 -0
- package/public/css/systemadm/tokens.css +56 -0
- package/public/favicon-16x16.png +0 -0
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/js/apps/apiDocsApp.js +235 -0
- package/public/js/apps/commandsReactApp.js +528 -0
- package/public/js/apps/createPackApp.js +1646 -0
- package/public/js/apps/homeReactApp.js +942 -0
- package/public/js/apps/loginReactApp.js +496 -0
- package/public/js/apps/stickersAdminApp.js +1753 -0
- package/public/js/apps/stickersApp.js +3797 -0
- package/public/js/apps/termsReactApp.js +528 -0
- package/public/js/apps/userApp.js +2540 -0
- package/public/js/apps/userProfile/actions.js +66 -0
- package/public/js/apps/userReactApp.js +547 -0
- package/public/js/catalog.js +950 -0
- package/public/pages/api-docs.html +40 -0
- package/public/pages/aup.html +158 -0
- package/public/pages/comandos.html +41 -0
- package/public/pages/dpa.html +227 -0
- package/public/pages/home.html +45 -0
- package/public/pages/licenca.html +182 -0
- package/public/pages/login.html +40 -0
- package/public/pages/notice-and-takedown.html +234 -0
- package/public/pages/politica-de-privacidade.html +251 -0
- package/public/pages/seo-bot-whatsapp-para-grupo.html +350 -0
- package/public/pages/seo-bot-whatsapp-sem-programar.html +350 -0
- package/public/pages/seo-como-automatizar-avisos-no-whatsapp.html +350 -0
- package/public/pages/seo-como-criar-comandos-whatsapp.html +350 -0
- package/public/pages/seo-como-evitar-spam-no-whatsapp.html +350 -0
- package/public/pages/seo-como-moderar-grupo-whatsapp.html +350 -0
- package/public/pages/seo-como-organizar-comunidade-whatsapp.html +350 -0
- package/public/pages/seo-melhor-bot-whatsapp-para-grupos.html +350 -0
- package/public/pages/stickers-admin.html +31 -0
- package/public/pages/stickers-create.html +41 -0
- package/public/pages/stickers.html +45 -0
- package/public/pages/suboperadores.html +237 -0
- package/public/pages/termos-de-uso-texto-integral.html +241 -0
- package/public/pages/termos-de-uso.html +41 -0
- package/public/pages/user-password-reset.html +32 -0
- package/public/pages/user-systemadm.html +508 -0
- package/public/pages/user.html +39 -0
- package/public/robots.txt +9 -0
- package/public/site.webmanifest +24 -0
- package/public/sitemap.xml +98 -0
- package/schemas/command-config.schema.json +582 -0
- package/scripts/baileys-compat-smoke.mjs +12 -0
- package/scripts/cache-bust.mjs +142 -0
- package/scripts/deploy.sh +916 -0
- package/scripts/email-broadcast-terms-update.mjs +170 -0
- package/scripts/enrich-command-discovery-fields.mjs +286 -0
- package/scripts/generate-command-config-schema.mjs +273 -0
- package/scripts/generate-commands-catalog.mjs +308 -0
- package/scripts/generate-module-agents.mjs +631 -0
- package/scripts/generate-seo-satellite-pages.mjs +400 -0
- package/scripts/github-deploy-notify.mjs +174 -0
- package/scripts/github-release-notify.mjs +219 -0
- package/scripts/release.sh +599 -0
- package/scripts/run-codeql-local.sh +116 -0
- package/scripts/run-prettier-all.mjs +25 -0
- package/scripts/security-smoketest.mjs +581 -0
- package/scripts/sticker-catalog-loadtest.mjs +210 -0
- package/scripts/sticker-worker-task.mjs +119 -0
- package/scripts/sync-readme-snapshot.mjs +133 -0
- package/scripts/validate-command-config-schema.mjs +130 -0
- package/scripts/validate-command-configs.mjs +15 -0
- package/scripts/wiki-sync.sh +191 -0
- package/server/auth/googleWebAuth/googleWebAuthRuntime.js +62 -0
- package/server/auth/googleWebAuth/googleWebAuthService.js +807 -0
- package/server/auth/jwt/webJwtService.js +147 -0
- package/server/auth/stickerCatalogAuthContext.js +165 -0
- package/server/auth/termsAcceptance/termsAcceptanceHandler.js +189 -0
- package/server/auth/userPassword/index.js +14 -0
- package/server/auth/userPassword/userPasswordAuthService.js +422 -0
- package/server/auth/userPassword/userPasswordCrypto.js +199 -0
- package/server/auth/userPassword/userPasswordCrypto.test.js +76 -0
- package/server/auth/userPassword/userPasswordRecoveryService.js +728 -0
- package/server/auth/validation/authSchemas.js +236 -0
- package/server/auth/webAccount/webAccountHandlers.js +1434 -0
- package/server/controllers/admin/adminBanService.js +138 -0
- package/server/controllers/admin/adminPanelHandlers.js +2083 -0
- package/server/controllers/admin/stickerCatalogAdminContext.js +17 -0
- package/server/controllers/admin/systemAdminController.js +201 -0
- package/server/controllers/email/emailAutomationController.js +239 -0
- package/server/controllers/metricsController.js +21 -0
- package/server/controllers/seo/stickerCatalogSeoContext.js +514 -0
- package/server/controllers/sticker/nonCatalogHandlers.js +303 -0
- package/server/controllers/sticker/stickerCatalogController.js +4700 -0
- package/server/controllers/system/contactController.js +115 -0
- package/server/controllers/system/githubController.js +137 -0
- package/server/controllers/system/stickerCatalogSystemContext.js +758 -0
- package/server/controllers/system/storageController.js +154 -0
- package/server/controllers/system/systemController.js +135 -0
- package/server/controllers/system/systemMetricsController.js +156 -0
- package/server/controllers/system/visitController.js +90 -0
- package/server/controllers/userController.js +145 -0
- package/server/email/emailAutomationRuntime.js +225 -0
- package/server/email/emailAutomationService.js +125 -0
- package/server/email/emailOutboxRepository.js +282 -0
- package/server/email/emailTemplateService.js +480 -0
- package/server/email/emailTransportService.js +156 -0
- package/server/http/clientIp.js +95 -0
- package/server/http/httpRequestUtils.js +262 -0
- package/server/http/httpRequestUtils.test.js +80 -0
- package/server/http/httpServer.js +180 -0
- package/server/http/requestContext.js +20 -0
- package/server/http/siteRoutingUtils.js +87 -0
- package/server/index.js +1 -0
- package/server/middleware/cachePolicy.js +26 -0
- package/server/middleware/cachePolicyHelpers.js +1 -0
- package/server/middleware/endpointRateLimit.js +181 -0
- package/server/middleware/rateLimit.js +70 -0
- package/server/middleware/requireAdminAuth.js +48 -0
- package/server/middleware/securityHeaders.js +97 -0
- package/server/routes/admin/systemAdminRouter.js +64 -0
- package/server/routes/email/emailAutomationRouter.js +46 -0
- package/server/routes/health/healthRouter.js +41 -0
- package/server/routes/indexRouter.js +234 -0
- package/server/routes/metrics/metricsRouter.js +58 -0
- package/server/routes/static/staticPageRouter.js +134 -0
- package/server/routes/sticker/catalogHandlers/catalogAdminHttp.js +105 -0
- package/server/routes/sticker/catalogHandlers/catalogAuthHttp.js +77 -0
- package/server/routes/sticker/catalogHandlers/catalogPublicHttp.js +120 -0
- package/server/routes/sticker/catalogHandlers/catalogUploadHttp.js +83 -0
- package/server/routes/sticker/catalogRouter.js +77 -0
- package/server/routes/sticker/stickerApiRouter.js +84 -0
- package/server/routes/sticker/stickerDataRouter.js +145 -0
- package/server/routes/sticker/stickerSiteRouter.js +43 -0
- package/server/routes/user/userApiPaths.js +66 -0
- package/server/routes/user/userRouter.js +65 -0
- package/server/utils/safePath.js +26 -0
- package/utils/logger/loggerModule.js +35 -0
- package/vite.config.mjs +38 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import https from 'node:https';
|
|
4
|
+
import { performance } from 'node:perf_hooks';
|
|
5
|
+
import fs from 'node:fs/promises';
|
|
6
|
+
import { URL } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_BASE_URL = process.env.STICKER_LOADTEST_BASE_URL || 'http://127.0.0.1:9102';
|
|
9
|
+
const DEFAULT_PATHS = ['/api/sticker-packs?limit=24&offset=0&sort=popular', '/api/sticker-packs/stats', '/api/sticker-packs/creators?limit=25'];
|
|
10
|
+
const DEFAULT_DURATION_SECONDS = 30;
|
|
11
|
+
const DEFAULT_CONCURRENCY = 20;
|
|
12
|
+
const DEFAULT_TIMEOUT_MS = 12_000;
|
|
13
|
+
const DEFAULT_HTTP_SLO_MS = Number(process.env.HTTP_SLO_TARGET_MS || 750);
|
|
14
|
+
|
|
15
|
+
const parseCliArgs = (argv) => {
|
|
16
|
+
const args = new Map();
|
|
17
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
18
|
+
const token = argv[i];
|
|
19
|
+
if (!token.startsWith('--')) continue;
|
|
20
|
+
const next = argv[i + 1];
|
|
21
|
+
if (!next || next.startsWith('--')) {
|
|
22
|
+
args.set(token, true);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
args.set(token, next);
|
|
26
|
+
i += 1;
|
|
27
|
+
}
|
|
28
|
+
return args;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const args = parseCliArgs(process.argv.slice(2));
|
|
32
|
+
const baseUrl = String(args.get('--base-url') || DEFAULT_BASE_URL)
|
|
33
|
+
.trim()
|
|
34
|
+
.replace(/\/+$/, '');
|
|
35
|
+
const durationSeconds = Math.max(5, Number(args.get('--duration-seconds') || DEFAULT_DURATION_SECONDS));
|
|
36
|
+
const concurrency = Math.max(1, Number(args.get('--concurrency') || DEFAULT_CONCURRENCY));
|
|
37
|
+
const timeoutMs = Math.max(1000, Number(args.get('--timeout-ms') || DEFAULT_TIMEOUT_MS));
|
|
38
|
+
const outFile = String(args.get('--out') || '').trim();
|
|
39
|
+
const sloMs = Math.max(50, Number(args.get('--slo-ms') || DEFAULT_HTTP_SLO_MS));
|
|
40
|
+
const paths = String(args.get('--paths') || '')
|
|
41
|
+
.split(',')
|
|
42
|
+
.map((entry) => entry.trim())
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
const requestPaths = paths.length ? paths : DEFAULT_PATHS;
|
|
45
|
+
|
|
46
|
+
const url = new URL(baseUrl);
|
|
47
|
+
const isHttps = url.protocol === 'https:';
|
|
48
|
+
const requestClient = isHttps ? https : http;
|
|
49
|
+
|
|
50
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
51
|
+
|
|
52
|
+
const quantile = (sortedValues, q) => {
|
|
53
|
+
if (!sortedValues.length) return 0;
|
|
54
|
+
const index = Math.max(0, Math.min(sortedValues.length - 1, Math.floor((sortedValues.length - 1) * q)));
|
|
55
|
+
return sortedValues[index];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const runRequest = (pathName) =>
|
|
59
|
+
new Promise((resolve) => {
|
|
60
|
+
const started = performance.now();
|
|
61
|
+
const req = requestClient.request(
|
|
62
|
+
{
|
|
63
|
+
protocol: url.protocol,
|
|
64
|
+
hostname: url.hostname,
|
|
65
|
+
port: url.port || (isHttps ? 443 : 80),
|
|
66
|
+
path: pathName,
|
|
67
|
+
method: 'GET',
|
|
68
|
+
timeout: timeoutMs,
|
|
69
|
+
headers: {
|
|
70
|
+
Connection: 'keep-alive',
|
|
71
|
+
Accept: 'application/json',
|
|
72
|
+
'X-Viewer-Key': 'loadtest',
|
|
73
|
+
'X-Session-Key': 'loadtest',
|
|
74
|
+
'User-Agent': 'omnizap-sticker-loadtest/1.0',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
(res) => {
|
|
78
|
+
res.resume();
|
|
79
|
+
res.on('end', () => {
|
|
80
|
+
const durationMs = performance.now() - started;
|
|
81
|
+
resolve({
|
|
82
|
+
ok: res.statusCode >= 200 && res.statusCode < 500,
|
|
83
|
+
statusCode: Number(res.statusCode || 0),
|
|
84
|
+
durationMs,
|
|
85
|
+
pathName,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
req.on('timeout', () => {
|
|
92
|
+
req.destroy(new Error('timeout'));
|
|
93
|
+
});
|
|
94
|
+
req.on('error', (error) => {
|
|
95
|
+
const durationMs = performance.now() - started;
|
|
96
|
+
resolve({
|
|
97
|
+
ok: false,
|
|
98
|
+
statusCode: 0,
|
|
99
|
+
durationMs,
|
|
100
|
+
pathName,
|
|
101
|
+
error: error?.message || 'request_error',
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
req.end();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const runWorker = async ({ deadlineMs, workerIndex, stats }) => {
|
|
108
|
+
let requestIndex = workerIndex % requestPaths.length;
|
|
109
|
+
while (Date.now() < deadlineMs) {
|
|
110
|
+
const pathName = requestPaths[requestIndex % requestPaths.length];
|
|
111
|
+
requestIndex += 1;
|
|
112
|
+
|
|
113
|
+
const result = await runRequest(pathName);
|
|
114
|
+
stats.total += 1;
|
|
115
|
+
stats.latencies.push(result.durationMs);
|
|
116
|
+
stats.byStatus.set(result.statusCode, Number(stats.byStatus.get(result.statusCode) || 0) + 1);
|
|
117
|
+
if (result.ok) {
|
|
118
|
+
stats.success += 1;
|
|
119
|
+
} else {
|
|
120
|
+
stats.errors += 1;
|
|
121
|
+
stats.lastErrors.push({
|
|
122
|
+
path: pathName,
|
|
123
|
+
status_code: result.statusCode,
|
|
124
|
+
error: result.error || null,
|
|
125
|
+
});
|
|
126
|
+
if (stats.lastErrors.length > 10) stats.lastErrors.shift();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const main = async () => {
|
|
132
|
+
const startedAt = Date.now();
|
|
133
|
+
const deadlineMs = startedAt + durationSeconds * 1000;
|
|
134
|
+
const stats = {
|
|
135
|
+
total: 0,
|
|
136
|
+
success: 0,
|
|
137
|
+
errors: 0,
|
|
138
|
+
latencies: [],
|
|
139
|
+
byStatus: new Map(),
|
|
140
|
+
lastErrors: [],
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
console.log(`[loadtest] base_url=${baseUrl}`);
|
|
144
|
+
console.log(`[loadtest] duration_seconds=${durationSeconds} concurrency=${concurrency} paths=${requestPaths.join(',')}`);
|
|
145
|
+
await sleep(250);
|
|
146
|
+
|
|
147
|
+
await Promise.all(
|
|
148
|
+
Array.from({ length: concurrency }).map((_, index) =>
|
|
149
|
+
runWorker({
|
|
150
|
+
deadlineMs,
|
|
151
|
+
workerIndex: index,
|
|
152
|
+
stats,
|
|
153
|
+
}),
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const elapsedSeconds = Math.max(0.001, (Date.now() - startedAt) / 1000);
|
|
158
|
+
const sortedLatencies = [...stats.latencies].sort((a, b) => a - b);
|
|
159
|
+
const p50 = quantile(sortedLatencies, 0.5);
|
|
160
|
+
const p90 = quantile(sortedLatencies, 0.9);
|
|
161
|
+
const p95 = quantile(sortedLatencies, 0.95);
|
|
162
|
+
const p99 = quantile(sortedLatencies, 0.99);
|
|
163
|
+
const throughputRps = stats.total / elapsedSeconds;
|
|
164
|
+
const errorRate = stats.total > 0 ? stats.errors / stats.total : 1;
|
|
165
|
+
|
|
166
|
+
const summary = {
|
|
167
|
+
started_at: new Date(startedAt).toISOString(),
|
|
168
|
+
ended_at: new Date().toISOString(),
|
|
169
|
+
base_url: baseUrl,
|
|
170
|
+
duration_seconds: Number(elapsedSeconds.toFixed(3)),
|
|
171
|
+
concurrency,
|
|
172
|
+
paths: requestPaths,
|
|
173
|
+
requests_total: stats.total,
|
|
174
|
+
requests_success: stats.success,
|
|
175
|
+
requests_error: stats.errors,
|
|
176
|
+
error_rate: Number(errorRate.toFixed(6)),
|
|
177
|
+
throughput_rps: Number(throughputRps.toFixed(3)),
|
|
178
|
+
latency_ms: {
|
|
179
|
+
p50: Number(p50.toFixed(2)),
|
|
180
|
+
p90: Number(p90.toFixed(2)),
|
|
181
|
+
p95: Number(p95.toFixed(2)),
|
|
182
|
+
p99: Number(p99.toFixed(2)),
|
|
183
|
+
max: Number((sortedLatencies[sortedLatencies.length - 1] || 0).toFixed(2)),
|
|
184
|
+
},
|
|
185
|
+
by_status: Object.fromEntries(stats.byStatus.entries()),
|
|
186
|
+
slo: {
|
|
187
|
+
target_ms: sloMs,
|
|
188
|
+
p95_within_target: p95 <= sloMs,
|
|
189
|
+
},
|
|
190
|
+
sample_errors: stats.lastErrors,
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
194
|
+
if (outFile) {
|
|
195
|
+
await fs.writeFile(outFile, `${JSON.stringify(summary, null, 2)}\n`, 'utf8');
|
|
196
|
+
console.log(`[loadtest] report_written=${outFile}`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (summary.requests_total <= 0) {
|
|
200
|
+
process.exitCode = 2;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (summary.slo.p95_within_target && summary.error_rate <= 0.02) return;
|
|
204
|
+
process.exitCode = 1;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
main().catch((error) => {
|
|
208
|
+
console.error('[loadtest] fatal_error', error?.message || error);
|
|
209
|
+
process.exitCode = 2;
|
|
210
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
|
|
4
|
+
import logger from '#logger';
|
|
5
|
+
import initializeDatabase from '../database/init.js';
|
|
6
|
+
import { closePool } from '../database/index.js';
|
|
7
|
+
import { isSupportedStickerWorkerTaskType, startDedicatedStickerWorker } from '../app/modules/stickerPackModule/stickerDedicatedTaskWorkerRuntime.js';
|
|
8
|
+
|
|
9
|
+
const parseCliArgs = (argv = []) => {
|
|
10
|
+
const args = new Map();
|
|
11
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
12
|
+
const token = argv[index];
|
|
13
|
+
if (!token.startsWith('--')) continue;
|
|
14
|
+
const next = argv[index + 1];
|
|
15
|
+
if (!next || next.startsWith('--')) {
|
|
16
|
+
args.set(token, true);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
args.set(token, next);
|
|
20
|
+
index += 1;
|
|
21
|
+
}
|
|
22
|
+
return args;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const args = parseCliArgs(process.argv.slice(2));
|
|
26
|
+
const workerTaskType = String(args.get('--task-type') || process.env.STICKER_WORKER_TASK_TYPE || '')
|
|
27
|
+
.trim()
|
|
28
|
+
.toLowerCase();
|
|
29
|
+
|
|
30
|
+
if (!isSupportedStickerWorkerTaskType(workerTaskType)) {
|
|
31
|
+
logger.error('Tipo de task inválido para worker dedicado.', {
|
|
32
|
+
action: 'sticker_worker_task_invalid_type',
|
|
33
|
+
task_type: workerTaskType || null,
|
|
34
|
+
});
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let shuttingDown = false;
|
|
39
|
+
let workerHandle = null;
|
|
40
|
+
|
|
41
|
+
const shutdown = async (signal, error = null) => {
|
|
42
|
+
if (shuttingDown) return;
|
|
43
|
+
shuttingDown = true;
|
|
44
|
+
|
|
45
|
+
logger.warn('Encerrando worker dedicado de sticker.', {
|
|
46
|
+
action: 'sticker_worker_task_shutdown',
|
|
47
|
+
signal,
|
|
48
|
+
task_type: workerTaskType,
|
|
49
|
+
error: error?.message || null,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
workerHandle?.stop?.();
|
|
54
|
+
} catch (stopError) {
|
|
55
|
+
logger.warn('Falha ao encerrar loop do worker dedicado.', {
|
|
56
|
+
action: 'sticker_worker_task_stop_failed',
|
|
57
|
+
task_type: workerTaskType,
|
|
58
|
+
error: stopError?.message,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await closePool();
|
|
64
|
+
} catch (poolError) {
|
|
65
|
+
logger.warn('Falha ao encerrar pool MySQL no worker dedicado.', {
|
|
66
|
+
action: 'sticker_worker_task_pool_close_failed',
|
|
67
|
+
task_type: workerTaskType,
|
|
68
|
+
error: poolError?.message,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
process.exit(error ? 1 : 0);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
process.on('SIGINT', () => {
|
|
76
|
+
void shutdown('SIGINT');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
process.on('SIGTERM', () => {
|
|
80
|
+
void shutdown('SIGTERM');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
process.on('uncaughtException', (error) => {
|
|
84
|
+
logger.error('Exceção não capturada no worker dedicado de sticker.', {
|
|
85
|
+
action: 'sticker_worker_task_uncaught_exception',
|
|
86
|
+
task_type: workerTaskType,
|
|
87
|
+
error: error?.message,
|
|
88
|
+
stack: error?.stack,
|
|
89
|
+
});
|
|
90
|
+
void shutdown('uncaughtException', error);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
process.on('unhandledRejection', (reason) => {
|
|
94
|
+
const message = reason instanceof Error ? reason.message : String(reason || '');
|
|
95
|
+
logger.error('Promise rejeitada sem tratamento no worker dedicado de sticker.', {
|
|
96
|
+
action: 'sticker_worker_task_unhandled_rejection',
|
|
97
|
+
task_type: workerTaskType,
|
|
98
|
+
error: message,
|
|
99
|
+
});
|
|
100
|
+
void shutdown('unhandledRejection', reason instanceof Error ? reason : new Error(message));
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const start = async () => {
|
|
104
|
+
await initializeDatabase();
|
|
105
|
+
workerHandle = startDedicatedStickerWorker({
|
|
106
|
+
taskType: workerTaskType,
|
|
107
|
+
label: `process:${process.pid}`,
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
start().catch((error) => {
|
|
112
|
+
logger.error('Falha ao inicializar worker dedicado de sticker.', {
|
|
113
|
+
action: 'sticker_worker_task_start_failed',
|
|
114
|
+
task_type: workerTaskType,
|
|
115
|
+
error: error?.message,
|
|
116
|
+
stack: error?.stack,
|
|
117
|
+
});
|
|
118
|
+
void shutdown('startup_error', error);
|
|
119
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import dotenv from 'dotenv';
|
|
7
|
+
|
|
8
|
+
dotenv.config({ path: '.env' });
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
const projectRoot = path.resolve(__dirname, '..');
|
|
13
|
+
|
|
14
|
+
const START_MARKER = '<!-- README_SNAPSHOT:START -->';
|
|
15
|
+
const END_MARKER = '<!-- README_SNAPSHOT:END -->';
|
|
16
|
+
const DEFAULT_README_TARGET = 'README.md';
|
|
17
|
+
const DEFAULT_TIMEOUT_MS = 15000;
|
|
18
|
+
const DEFAULT_MAX_BYTES = 500_000;
|
|
19
|
+
|
|
20
|
+
const escapeRegExp = (value) => String(value || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
21
|
+
const isLocalHostname = (hostname) => ['localhost', '127.0.0.1', '::1'].includes(String(hostname || '').toLowerCase());
|
|
22
|
+
const toPositiveInt = (value, fallback, min = 1) => {
|
|
23
|
+
const parsed = Number(value);
|
|
24
|
+
if (!Number.isFinite(parsed) || parsed < min) return fallback;
|
|
25
|
+
return Math.floor(parsed);
|
|
26
|
+
};
|
|
27
|
+
const toBool = (value, fallback = false) => {
|
|
28
|
+
if (value === undefined || value === null || value === '') return fallback;
|
|
29
|
+
return ['1', 'true', 'yes', 'on'].includes(String(value).trim().toLowerCase());
|
|
30
|
+
};
|
|
31
|
+
const ensurePathWithinRoot = (rootPath, targetPath) => {
|
|
32
|
+
const relative = path.relative(rootPath, targetPath);
|
|
33
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
34
|
+
throw new Error(`Caminho fora do projeto não permitido: ${targetPath}`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const readmePath = path.resolve(projectRoot, process.env.README_SNAPSHOT_TARGET_PATH || DEFAULT_README_TARGET);
|
|
39
|
+
ensurePathWithinRoot(projectRoot, readmePath);
|
|
40
|
+
|
|
41
|
+
const siteOrigin = String(process.env.SITE_ORIGIN || 'https://omnizap.shop')
|
|
42
|
+
.trim()
|
|
43
|
+
.replace(/\/+$/, '');
|
|
44
|
+
const sourceUrlRaw = String(process.env.README_SNAPSHOT_SOURCE_URL || `${siteOrigin}/api/readme-markdown`).trim();
|
|
45
|
+
const timeoutMs = Math.max(1000, toPositiveInt(process.env.README_SNAPSHOT_TIMEOUT_MS, DEFAULT_TIMEOUT_MS, 1000));
|
|
46
|
+
const maxBytes = Math.max(1024, toPositiveInt(process.env.README_SNAPSHOT_MAX_BYTES, DEFAULT_MAX_BYTES, 1024));
|
|
47
|
+
const allowExternalSource = toBool(process.env.README_SNAPSHOT_ALLOW_EXTERNAL_SOURCE, false);
|
|
48
|
+
|
|
49
|
+
const resolveSourceUrl = (candidateUrl, trustedSiteOrigin, allowExternal) => {
|
|
50
|
+
let trusted;
|
|
51
|
+
let source;
|
|
52
|
+
try {
|
|
53
|
+
trusted = new URL(trustedSiteOrigin);
|
|
54
|
+
source = new URL(candidateUrl);
|
|
55
|
+
} catch {
|
|
56
|
+
throw new Error('SITE_ORIGIN ou README_SNAPSHOT_SOURCE_URL inválido.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (source.protocol !== 'https:' && !isLocalHostname(source.hostname)) {
|
|
60
|
+
throw new Error(`README_SNAPSHOT_SOURCE_URL deve usar HTTPS (ou localhost): ${source.origin}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!allowExternal && source.origin !== trusted.origin) {
|
|
64
|
+
throw new Error(`README_SNAPSHOT_SOURCE_URL fora do domínio confiável (${trusted.origin}). Defina README_SNAPSHOT_ALLOW_EXTERNAL_SOURCE=1 para liberar.`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return source.toString();
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const sourceUrl = resolveSourceUrl(sourceUrlRaw, siteOrigin, allowExternalSource);
|
|
71
|
+
|
|
72
|
+
const fetchWithTimeout = async (url, timeout, maxContentBytes) => {
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
75
|
+
try {
|
|
76
|
+
const response = await fetch(url, {
|
|
77
|
+
method: 'GET',
|
|
78
|
+
headers: { 'User-Agent': 'omnizap-readme-sync/1.0' },
|
|
79
|
+
signal: controller.signal,
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
throw new Error(`HTTP ${response.status} ao buscar snapshot`);
|
|
83
|
+
}
|
|
84
|
+
const content = String(await response.text()).trim();
|
|
85
|
+
if (!content) {
|
|
86
|
+
throw new Error('Snapshot markdown vazio');
|
|
87
|
+
}
|
|
88
|
+
const contentBytes = Buffer.byteLength(content, 'utf8');
|
|
89
|
+
if (contentBytes > maxContentBytes) {
|
|
90
|
+
throw new Error(`Snapshot excede limite de ${maxContentBytes} bytes.`);
|
|
91
|
+
}
|
|
92
|
+
if (content.includes(START_MARKER) || content.includes(END_MARKER)) {
|
|
93
|
+
throw new Error('Snapshot não pode conter os marcadores START/END.');
|
|
94
|
+
}
|
|
95
|
+
return content;
|
|
96
|
+
} finally {
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const syncReadmeSnapshot = async () => {
|
|
102
|
+
const markdown = await fetchWithTimeout(sourceUrl, timeoutMs, maxBytes);
|
|
103
|
+
const readme = await fs.readFile(readmePath, 'utf8');
|
|
104
|
+
|
|
105
|
+
const blockRegex = new RegExp(`${escapeRegExp(START_MARKER)}[\\s\\S]*?${escapeRegExp(END_MARKER)}`, 'm');
|
|
106
|
+
if (!blockRegex.test(readme)) {
|
|
107
|
+
throw new Error(`Marcadores não encontrados em ${path.relative(projectRoot, readmePath)} (${START_MARKER} ... ${END_MARKER})`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const replacement = `${START_MARKER}\n${markdown}\n${END_MARKER}`;
|
|
111
|
+
const nextReadme = readme.replace(blockRegex, replacement);
|
|
112
|
+
|
|
113
|
+
if (nextReadme === readme) {
|
|
114
|
+
console.log('[readme-sync] Snapshot já está atualizado.');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const tempPath = `${readmePath}.tmp-${process.pid}-${Date.now()}`;
|
|
119
|
+
try {
|
|
120
|
+
// lgtm[js/http-to-file-access]
|
|
121
|
+
await fs.writeFile(tempPath, nextReadme, 'utf8');
|
|
122
|
+
await fs.rename(tempPath, readmePath);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
await fs.rm(tempPath, { force: true }).catch(() => {});
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
console.log(`[readme-sync] README atualizado com snapshot de ${sourceUrl}`);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
syncReadmeSnapshot().catch((error) => {
|
|
131
|
+
console.error(`[readme-sync] Falha: ${error?.message || error}`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import Ajv2020 from 'ajv/dist/2020.js';
|
|
6
|
+
|
|
7
|
+
const parseCliArgs = (argv = []) => {
|
|
8
|
+
const args = new Map();
|
|
9
|
+
const positional = [];
|
|
10
|
+
|
|
11
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
12
|
+
const token = argv[index];
|
|
13
|
+
if (!token.startsWith('--')) {
|
|
14
|
+
positional.push(token);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const next = argv[index + 1];
|
|
19
|
+
if (!next || next.startsWith('--')) {
|
|
20
|
+
args.set(token, true);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (token === '--file') {
|
|
25
|
+
const current = args.get(token);
|
|
26
|
+
if (Array.isArray(current)) {
|
|
27
|
+
current.push(next);
|
|
28
|
+
} else if (typeof current === 'string') {
|
|
29
|
+
args.set(token, [current, next]);
|
|
30
|
+
} else {
|
|
31
|
+
args.set(token, next);
|
|
32
|
+
}
|
|
33
|
+
index += 1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
args.set(token, next);
|
|
38
|
+
index += 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { args, positional };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const asArray = (value) => {
|
|
45
|
+
if (!value) return [];
|
|
46
|
+
if (Array.isArray(value)) return value;
|
|
47
|
+
return [value];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const discoverDefaultConfigFiles = () => {
|
|
51
|
+
const modulesRoot = path.join(process.cwd(), 'app', 'modules');
|
|
52
|
+
let moduleEntries = [];
|
|
53
|
+
try {
|
|
54
|
+
moduleEntries = fs.readdirSync(modulesRoot, { withFileTypes: true });
|
|
55
|
+
} catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return moduleEntries
|
|
60
|
+
.filter((entry) => entry.isDirectory())
|
|
61
|
+
.map((entry) => path.join(modulesRoot, entry.name, 'commandConfig.json'))
|
|
62
|
+
.filter((configPath) => fs.existsSync(configPath))
|
|
63
|
+
.sort((left, right) => left.localeCompare(right));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const formatAjvError = (error) => {
|
|
67
|
+
const instancePath = error?.instancePath || '/';
|
|
68
|
+
const message = error?.message || 'invalid';
|
|
69
|
+
const keyword = error?.keyword ? ` [${error.keyword}]` : '';
|
|
70
|
+
return `${instancePath}${keyword}: ${message}`;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const { args, positional } = parseCliArgs(process.argv.slice(2));
|
|
74
|
+
const schemaPath = path.resolve(String(args.get('--schema') || path.join(process.cwd(), 'schemas', 'command-config.schema.json')));
|
|
75
|
+
const explicitFiles = [...asArray(args.get('--file')), ...positional].map((file) => path.resolve(String(file)));
|
|
76
|
+
const targetFiles = explicitFiles.length ? explicitFiles : discoverDefaultConfigFiles();
|
|
77
|
+
|
|
78
|
+
if (!fs.existsSync(schemaPath)) {
|
|
79
|
+
console.error(`[command-config-schema] schema nao encontrado: ${schemaPath}`);
|
|
80
|
+
console.error('Gere antes com: npm run command-config:schema:generate');
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!targetFiles.length) {
|
|
85
|
+
console.error('[command-config-schema] nenhum arquivo alvo encontrado para validacao');
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const rawSchema = fs.readFileSync(schemaPath, 'utf8');
|
|
90
|
+
const schema = JSON.parse(rawSchema);
|
|
91
|
+
|
|
92
|
+
const ajv = new Ajv2020({ allErrors: true, strict: false });
|
|
93
|
+
const validate = ajv.compile(schema);
|
|
94
|
+
|
|
95
|
+
let hasErrors = false;
|
|
96
|
+
|
|
97
|
+
for (const targetFile of targetFiles) {
|
|
98
|
+
if (!fs.existsSync(targetFile)) {
|
|
99
|
+
hasErrors = true;
|
|
100
|
+
console.error(`\n✖ ${path.relative(process.cwd(), targetFile)} (arquivo nao encontrado)`);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let payload = null;
|
|
105
|
+
try {
|
|
106
|
+
payload = JSON.parse(fs.readFileSync(targetFile, 'utf8'));
|
|
107
|
+
} catch (error) {
|
|
108
|
+
hasErrors = true;
|
|
109
|
+
console.error(`\n✖ ${path.relative(process.cwd(), targetFile)} (json invalido: ${error?.message || error})`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const ok = validate(payload);
|
|
114
|
+
if (ok) {
|
|
115
|
+
console.log(`✔ ${path.relative(process.cwd(), targetFile)}`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
hasErrors = true;
|
|
120
|
+
console.error(`\n✖ ${path.relative(process.cwd(), targetFile)}`);
|
|
121
|
+
for (const error of validate.errors || []) {
|
|
122
|
+
console.error(` - ${formatAjvError(error)}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (hasErrors) {
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
console.log(`\n[command-config-schema] ok (${targetFiles.length} arquivo(s))`);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { formatCommandConfigValidationReport, validateAllCommandConfigs } from '../app/services/ai/commandConfigValidationService.js';
|
|
4
|
+
|
|
5
|
+
const report = validateAllCommandConfigs();
|
|
6
|
+
const printable = formatCommandConfigValidationReport(report, { maxErrors: 80 });
|
|
7
|
+
|
|
8
|
+
if (!report.ok) {
|
|
9
|
+
console.error('[command-config-validation] falhou');
|
|
10
|
+
console.error(printable);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
console.log('[command-config-validation] ok');
|
|
15
|
+
console.log(printable);
|