@logictan/dsh-config-manager 0.1.60
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/LICENSE +21 -0
- package/README.md +105 -0
- package/cordis.patch.yml +21 -0
- package/lib/adapters/agent-instructions.d.ts +13 -0
- package/lib/adapters/agent-instructions.js +46 -0
- package/lib/adapters/agent-presets.d.ts +13 -0
- package/lib/adapters/agent-presets.js +14 -0
- package/lib/adapters/credentials.d.ts +37 -0
- package/lib/adapters/credentials.js +122 -0
- package/lib/adapters/file-collection.d.ts +15 -0
- package/lib/adapters/file-collection.js +127 -0
- package/lib/adapters/index.d.ts +57 -0
- package/lib/adapters/index.js +55 -0
- package/lib/adapters/link-report.d.ts +16 -0
- package/lib/adapters/link-report.js +47 -0
- package/lib/adapters/mcp.d.ts +28 -0
- package/lib/adapters/mcp.js +178 -0
- package/lib/adapters/plugin-files.d.ts +18 -0
- package/lib/adapters/plugin-files.js +142 -0
- package/lib/adapters/plugins.d.ts +41 -0
- package/lib/adapters/plugins.js +603 -0
- package/lib/adapters/pnpm-workspace.d.ts +26 -0
- package/lib/adapters/pnpm-workspace.js +147 -0
- package/lib/adapters/prompts.d.ts +30 -0
- package/lib/adapters/prompts.js +231 -0
- package/lib/adapters/providers.d.ts +34 -0
- package/lib/adapters/providers.js +155 -0
- package/lib/adapters/self.d.ts +17 -0
- package/lib/adapters/self.js +71 -0
- package/lib/adapters/sessions.d.ts +14 -0
- package/lib/adapters/sessions.js +15 -0
- package/lib/adapters/settings.d.ts +28 -0
- package/lib/adapters/settings.js +165 -0
- package/lib/adapters/skills.d.ts +13 -0
- package/lib/adapters/skills.js +14 -0
- package/lib/adapters/test-helpers.d.ts +125 -0
- package/lib/adapters/test-helpers.js +236 -0
- package/lib/adapters/ui.d.ts +27 -0
- package/lib/adapters/ui.js +89 -0
- package/lib/adapters/workspaces.d.ts +13 -0
- package/lib/adapters/workspaces.js +106 -0
- package/lib/client.d.ts +1026 -0
- package/lib/client.js +10047 -0
- package/lib/core/analyzer.d.ts +99 -0
- package/lib/core/analyzer.js +934 -0
- package/lib/core/backup.d.ts +138 -0
- package/lib/core/backup.js +513 -0
- package/lib/core/boot-rescue.d.ts +146 -0
- package/lib/core/boot-rescue.js +618 -0
- package/lib/core/cache-cleaner.d.ts +31 -0
- package/lib/core/cache-cleaner.js +95 -0
- package/lib/core/config-lifecycle.d.ts +180 -0
- package/lib/core/config-lifecycle.js +481 -0
- package/lib/core/config-snapshot.d.ts +135 -0
- package/lib/core/config-snapshot.js +424 -0
- package/lib/core/config-state.d.ts +70 -0
- package/lib/core/config-state.js +177 -0
- package/lib/core/consult-source.d.ts +58 -0
- package/lib/core/consult-source.js +260 -0
- package/lib/core/crash-report.d.ts +84 -0
- package/lib/core/crash-report.js +317 -0
- package/lib/core/exporter.d.ts +68 -0
- package/lib/core/exporter.js +375 -0
- package/lib/core/ghost-sweep.d.ts +19 -0
- package/lib/core/ghost-sweep.js +52 -0
- package/lib/core/importer.d.ts +60 -0
- package/lib/core/importer.js +29 -0
- package/lib/core/index.d.ts +14 -0
- package/lib/core/index.js +14 -0
- package/lib/core/journal.d.ts +197 -0
- package/lib/core/journal.js +418 -0
- package/lib/core/local-plugin-host.d.ts +35 -0
- package/lib/core/local-plugin-host.js +120 -0
- package/lib/core/local-plugin-pack.d.ts +135 -0
- package/lib/core/local-plugin-pack.js +278 -0
- package/lib/core/messages.d.ts +310 -0
- package/lib/core/messages.js +621 -0
- package/lib/core/migration-consult.d.ts +117 -0
- package/lib/core/migration-consult.js +363 -0
- package/lib/core/migration-history.d.ts +153 -0
- package/lib/core/migration-history.js +411 -0
- package/lib/core/model-tools.d.ts +50 -0
- package/lib/core/model-tools.js +148 -0
- package/lib/core/msg-types.d.ts +8 -0
- package/lib/core/msg-types.js +6 -0
- package/lib/core/phase3-child-crash.d.ts +1 -0
- package/lib/core/phase3-child-crash.js +87 -0
- package/lib/core/phase3-host.d.ts +138 -0
- package/lib/core/phase3-host.js +359 -0
- package/lib/core/phase3-prod-child.d.ts +1 -0
- package/lib/core/phase3-prod-child.js +35 -0
- package/lib/core/phase4-crash-child.d.ts +1 -0
- package/lib/core/phase4-crash-child.js +103 -0
- package/lib/core/plugin-cli.d.ts +150 -0
- package/lib/core/plugin-cli.js +497 -0
- package/lib/core/reconcile.d.ts +120 -0
- package/lib/core/reconcile.js +389 -0
- package/lib/core/recovery-orchestrator.d.ts +94 -0
- package/lib/core/recovery-orchestrator.js +327 -0
- package/lib/core/restore.d.ts +162 -0
- package/lib/core/restore.js +703 -0
- package/lib/core/rollback.d.ts +12 -0
- package/lib/core/rollback.js +145 -0
- package/lib/core/run-registry.d.ts +85 -0
- package/lib/core/run-registry.js +157 -0
- package/lib/core/startup-barrier.d.ts +53 -0
- package/lib/core/startup-barrier.js +77 -0
- package/lib/core/types.d.ts +515 -0
- package/lib/core/types.js +27 -0
- package/lib/core/undo.d.ts +73 -0
- package/lib/core/undo.js +87 -0
- package/lib/core/validator.d.ts +18 -0
- package/lib/core/validator.js +77 -0
- package/lib/core/verify-recovery.d.ts +21 -0
- package/lib/core/verify-recovery.js +256 -0
- package/lib/core/watcher.d.ts +101 -0
- package/lib/core/watcher.js +219 -0
- package/lib/index.d.ts +238 -0
- package/lib/index.js +2764 -0
- package/lib/migrations/index.d.ts +29 -0
- package/lib/migrations/index.js +56 -0
- package/lib/migrations/v1-to-v2.d.ts +9 -0
- package/lib/migrations/v1-to-v2.js +10 -0
- package/lib/profiles/index.d.ts +4 -0
- package/lib/profiles/index.js +5 -0
- package/lib/profiles/profile-manager.d.ts +106 -0
- package/lib/profiles/profile-manager.js +543 -0
- package/lib/schema/config.d.ts +28 -0
- package/lib/schema/config.js +165 -0
- package/lib/schema/index.d.ts +24 -0
- package/lib/schema/index.js +26 -0
- package/lib/schema/manifest.d.ts +28 -0
- package/lib/schema/manifest.js +109 -0
- package/lib/schema/tombstones.d.ts +46 -0
- package/lib/schema/tombstones.js +64 -0
- package/lib/schema/types.d.ts +232 -0
- package/lib/schema/types.js +8 -0
- package/lib/schema/versions.d.ts +27 -0
- package/lib/schema/versions.js +50 -0
- package/lib/security/encryption.d.ts +85 -0
- package/lib/security/encryption.js +279 -0
- package/lib/security/index.d.ts +16 -0
- package/lib/security/index.js +17 -0
- package/lib/security/integrity.d.ts +30 -0
- package/lib/security/integrity.js +78 -0
- package/lib/security/redaction.d.ts +26 -0
- package/lib/security/redaction.js +95 -0
- package/lib/security/secret-scanner.d.ts +86 -0
- package/lib/security/secret-scanner.js +404 -0
- package/lib/security/vault.d.ts +59 -0
- package/lib/security/vault.js +151 -0
- package/lib/security/zip-security.d.ts +27 -0
- package/lib/security/zip-security.js +154 -0
- package/lib/sync/autosync-config.d.ts +39 -0
- package/lib/sync/autosync-config.js +151 -0
- package/lib/sync/autosync-scheduler.d.ts +139 -0
- package/lib/sync/autosync-scheduler.js +564 -0
- package/lib/sync/fs.d.ts +18 -0
- package/lib/sync/fs.js +49 -0
- package/lib/sync/git/git-transport.d.ts +100 -0
- package/lib/sync/git/git-transport.js +437 -0
- package/lib/sync/github-auth.d.ts +131 -0
- package/lib/sync/github-auth.js +264 -0
- package/lib/sync/layout.d.ts +43 -0
- package/lib/sync/layout.js +203 -0
- package/lib/sync/snapshot-json.d.ts +9 -0
- package/lib/sync/snapshot-json.js +107 -0
- package/lib/sync/sync-config.d.ts +81 -0
- package/lib/sync/sync-config.js +281 -0
- package/lib/sync/sync-engine.d.ts +269 -0
- package/lib/sync/sync-engine.js +591 -0
- package/lib/sync/sync-history.d.ts +42 -0
- package/lib/sync/sync-history.js +78 -0
- package/lib/sync/sync-selection.d.ts +29 -0
- package/lib/sync/sync-selection.js +127 -0
- package/lib/sync/sync-session.d.ts +40 -0
- package/lib/sync/sync-session.js +54 -0
- package/lib/sync/sync-state.d.ts +37 -0
- package/lib/sync/sync-state.js +108 -0
- package/lib/sync/transport.d.ts +75 -0
- package/lib/sync/transport.js +55 -0
- package/lib/sync/ui-prefs.d.ts +34 -0
- package/lib/sync/ui-prefs.js +109 -0
- package/lib/sync/webdav/webdav-transport.d.ts +77 -0
- package/lib/sync/webdav/webdav-transport.js +451 -0
- package/lib/ui/errors.d.ts +19 -0
- package/lib/ui/errors.js +81 -0
- package/lib/ui/export-flow.d.ts +82 -0
- package/lib/ui/export-flow.js +98 -0
- package/lib/ui/i18n.d.ts +289 -0
- package/lib/ui/i18n.js +581 -0
- package/lib/ui/migration-consult-view.d.ts +91 -0
- package/lib/ui/migration-consult-view.js +115 -0
- package/lib/ui/progress.d.ts +38 -0
- package/lib/ui/progress.js +87 -0
- package/lib/ui/report.d.ts +23 -0
- package/lib/ui/report.js +153 -0
- package/lib/ui/test-helpers.d.ts +69 -0
- package/lib/ui/test-helpers.js +154 -0
- package/lib/ui/types.d.ts +257 -0
- package/lib/ui/types.js +21 -0
- package/lib/utils/atomic-write.d.ts +88 -0
- package/lib/utils/atomic-write.js +399 -0
- package/lib/utils/env-lock.d.ts +393 -0
- package/lib/utils/env-lock.js +930 -0
- package/lib/utils/hashing.d.ts +17 -0
- package/lib/utils/hashing.js +41 -0
- package/lib/utils/json.d.ts +24 -0
- package/lib/utils/json.js +76 -0
- package/lib/utils/logger.d.ts +39 -0
- package/lib/utils/logger.js +82 -0
- package/lib/utils/paths.d.ts +42 -0
- package/lib/utils/paths.js +189 -0
- package/lib/utils/proxy.d.ts +69 -0
- package/lib/utils/proxy.js +455 -0
- package/lib/utils/recursive-walk.d.ts +24 -0
- package/lib/utils/recursive-walk.js +134 -0
- package/lib/utils/zip.d.ts +54 -0
- package/lib/utils/zip.js +285 -0
- package/package.json +188 -0
- package/src/adapters/agent-instructions.ts +48 -0
- package/src/adapters/agent-presets.ts +14 -0
- package/src/adapters/credentials.test.ts +90 -0
- package/src/adapters/credentials.ts +143 -0
- package/src/adapters/file-collection.ts +137 -0
- package/src/adapters/files.test.ts +353 -0
- package/src/adapters/index.ts +94 -0
- package/src/adapters/link-report.test.ts +65 -0
- package/src/adapters/link-report.ts +61 -0
- package/src/adapters/mcp.test.ts +96 -0
- package/src/adapters/mcp.ts +185 -0
- package/src/adapters/plugin-files.ts +146 -0
- package/src/adapters/plugins.test.ts +326 -0
- package/src/adapters/plugins.ts +615 -0
- package/src/adapters/pnpm-workspace.test.ts +87 -0
- package/src/adapters/pnpm-workspace.ts +150 -0
- package/src/adapters/prompts.test.ts +110 -0
- package/src/adapters/prompts.ts +230 -0
- package/src/adapters/providers.test.ts +126 -0
- package/src/adapters/providers.ts +173 -0
- package/src/adapters/roundtrip.test.ts +190 -0
- package/src/adapters/self.test.ts +92 -0
- package/src/adapters/self.ts +75 -0
- package/src/adapters/sessions.ts +15 -0
- package/src/adapters/settings.test.ts +100 -0
- package/src/adapters/settings.ts +187 -0
- package/src/adapters/skills.ts +14 -0
- package/src/adapters/test-helpers.ts +248 -0
- package/src/adapters/ui.test.ts +57 -0
- package/src/adapters/ui.ts +108 -0
- package/src/adapters/workspaces.test.ts +106 -0
- package/src/adapters/workspaces.ts +109 -0
- package/src/client/ConfigManagerSection.tsx +90 -0
- package/src/client/api.ts +66 -0
- package/src/client/client-types.ts +18 -0
- package/src/client/common/ErrorBanner.tsx +73 -0
- package/src/client/common/Icon.tsx +129 -0
- package/src/client/common/Modal.tsx +173 -0
- package/src/client/common/ToastViewport.tsx +73 -0
- package/src/client/common/toast-store.test.ts +192 -0
- package/src/client/common/toast-store.ts +181 -0
- package/src/client/common/toast-types.ts +7 -0
- package/src/client/common/ui.tsx +342 -0
- package/src/client/config-manager.module.css +2971 -0
- package/src/client/css-modules.d.ts +8 -0
- package/src/client/index.ts +65 -0
- package/src/client/locales.ts +56 -0
- package/src/client/lucide-icons.d.ts +38 -0
- package/src/client/run-store.test.ts +223 -0
- package/src/client/run-store.ts +372 -0
- package/src/client/sync/SyncConfirmView.tsx +379 -0
- package/src/client/sync/SyncHistoryView.test.ts +40 -0
- package/src/client/sync/SyncHistoryView.tsx +220 -0
- package/src/client/sync/SyncSettingsView.tsx +1535 -0
- package/src/client/sync/history-model.test.ts +194 -0
- package/src/client/sync/history-model.ts +195 -0
- package/src/client/sync/sync-api.test.ts +585 -0
- package/src/client/sync/sync-api.ts +543 -0
- package/src/client/sync/sync-locales.ts +416 -0
- package/src/client/sync/sync-push-preview.test.ts +52 -0
- package/src/client/sync/sync-view-v2.test.ts +213 -0
- package/src/client/sync/sync-view.test.ts +487 -0
- package/src/client/sync/sync-view.ts +759 -0
- package/src/core/analyzer.ts +1068 -0
- package/src/core/backup.ts +605 -0
- package/src/core/boot-rescue.test.ts +847 -0
- package/src/core/boot-rescue.ts +737 -0
- package/src/core/cache-cleaner.test.ts +169 -0
- package/src/core/cache-cleaner.ts +121 -0
- package/src/core/config-lifecycle.test.ts +727 -0
- package/src/core/config-lifecycle.ts +573 -0
- package/src/core/config-snapshot.test.ts +369 -0
- package/src/core/config-snapshot.ts +522 -0
- package/src/core/config-state.test.ts +381 -0
- package/src/core/config-state.ts +207 -0
- package/src/core/consult-source.test.ts +199 -0
- package/src/core/consult-source.ts +293 -0
- package/src/core/crash-report.test.ts +380 -0
- package/src/core/crash-report.ts +369 -0
- package/src/core/exporter.ts +417 -0
- package/src/core/ghost-sweep.test.ts +94 -0
- package/src/core/ghost-sweep.ts +67 -0
- package/src/core/importer.ts +83 -0
- package/src/core/index.ts +56 -0
- package/src/core/journal.test.ts +257 -0
- package/src/core/journal.ts +518 -0
- package/src/core/local-plugin-host.ts +152 -0
- package/src/core/local-plugin-pack.test.ts +359 -0
- package/src/core/local-plugin-pack.ts +363 -0
- package/src/core/messages.test.ts +54 -0
- package/src/core/messages.ts +664 -0
- package/src/core/migration-consult.test.ts +315 -0
- package/src/core/migration-consult.ts +494 -0
- package/src/core/migration-history.test.ts +319 -0
- package/src/core/migration-history.ts +484 -0
- package/src/core/model-tools.test.ts +190 -0
- package/src/core/model-tools.ts +208 -0
- package/src/core/msg-types.ts +10 -0
- package/src/core/phase3-child-crash.ts +95 -0
- package/src/core/phase3-host.ts +411 -0
- package/src/core/phase3-p1.test.ts +212 -0
- package/src/core/phase3-p2b-fingerprint.test.ts +189 -0
- package/src/core/phase3-prod-child.ts +36 -0
- package/src/core/phase3-production-integration.test.ts +286 -0
- package/src/core/phase4-crash-child.ts +101 -0
- package/src/core/phase4-crash-injection.test.ts +166 -0
- package/src/core/plugin-cli.fs.test.ts +184 -0
- package/src/core/plugin-cli.test.ts +137 -0
- package/src/core/plugin-cli.ts +563 -0
- package/src/core/reconcile.test.ts +392 -0
- package/src/core/reconcile.ts +498 -0
- package/src/core/recovery-orchestrator.test.ts +145 -0
- package/src/core/recovery-orchestrator.ts +366 -0
- package/src/core/restore-manage.test.ts +94 -0
- package/src/core/restore.ts +849 -0
- package/src/core/rollback.ts +151 -0
- package/src/core/run-progress.test.ts +237 -0
- package/src/core/run-registry.test.ts +232 -0
- package/src/core/run-registry.ts +209 -0
- package/src/core/smoke.test.ts +842 -0
- package/src/core/startup-barrier.ts +99 -0
- package/src/core/types.ts +542 -0
- package/src/core/undo.ts +116 -0
- package/src/core/validator.ts +84 -0
- package/src/core/verify-recovery.ts +265 -0
- package/src/core/watcher.test.ts +326 -0
- package/src/core/watcher.ts +263 -0
- package/src/index.facade.test.ts +265 -0
- package/src/index.sync.test.ts +217 -0
- package/src/index.ts +2975 -0
- package/src/migrations/index.ts +71 -0
- package/src/migrations/v1-to-v2.ts +17 -0
- package/src/profiles/index.ts +8 -0
- package/src/profiles/profile-manager.test.ts +282 -0
- package/src/profiles/profile-manager.ts +630 -0
- package/src/schema/config.ts +165 -0
- package/src/schema/index.ts +71 -0
- package/src/schema/manifest-schema.test.ts +519 -0
- package/src/schema/manifest.ts +124 -0
- package/src/schema/tombstones.test.ts +131 -0
- package/src/schema/tombstones.ts +89 -0
- package/src/schema/types.ts +245 -0
- package/src/schema/versions.ts +55 -0
- package/src/security/encryption.ts +335 -0
- package/src/security/index.ts +16 -0
- package/src/security/integrity.ts +102 -0
- package/src/security/redaction.ts +101 -0
- package/src/security/secret-scanner.ts +445 -0
- package/src/security/security.test.ts +1215 -0
- package/src/security/vault.test.ts +164 -0
- package/src/security/vault.ts +198 -0
- package/src/security/zip-security.ts +180 -0
- package/src/sync/autosync-config.test.ts +147 -0
- package/src/sync/autosync-config.ts +179 -0
- package/src/sync/autosync-scheduler.test.ts +490 -0
- package/src/sync/autosync-scheduler.ts +646 -0
- package/src/sync/fs.ts +48 -0
- package/src/sync/git/git-transport.test.ts +673 -0
- package/src/sync/git/git-transport.ts +491 -0
- package/src/sync/github-auth.test.ts +280 -0
- package/src/sync/github-auth.ts +356 -0
- package/src/sync/layout.test.ts +270 -0
- package/src/sync/layout.ts +222 -0
- package/src/sync/snapshot-json.test.ts +119 -0
- package/src/sync/snapshot-json.ts +128 -0
- package/src/sync/sync-config.test.ts +310 -0
- package/src/sync/sync-config.ts +299 -0
- package/src/sync/sync-engine.test.ts +1074 -0
- package/src/sync/sync-engine.ts +754 -0
- package/src/sync/sync-history.test.ts +116 -0
- package/src/sync/sync-history.ts +120 -0
- package/src/sync/sync-selection.test.ts +186 -0
- package/src/sync/sync-selection.ts +143 -0
- package/src/sync/sync-session.test.ts +143 -0
- package/src/sync/sync-session.ts +77 -0
- package/src/sync/sync-state.test.ts +164 -0
- package/src/sync/sync-state.ts +131 -0
- package/src/sync/transport.test.ts +111 -0
- package/src/sync/transport.ts +118 -0
- package/src/sync/ui-prefs.test.ts +152 -0
- package/src/sync/ui-prefs.ts +135 -0
- package/src/sync/webdav/webdav-transport.test.ts +871 -0
- package/src/sync/webdav/webdav-transport.ts +535 -0
- package/src/ui/errors.test.ts +47 -0
- package/src/ui/errors.ts +100 -0
- package/src/ui/export-flow.test.ts +87 -0
- package/src/ui/export-flow.ts +156 -0
- package/src/ui/i18n.ts +590 -0
- package/src/ui/migration-consult-view.test.ts +151 -0
- package/src/ui/migration-consult-view.ts +178 -0
- package/src/ui/progress.test.ts +47 -0
- package/src/ui/progress.ts +102 -0
- package/src/ui/report.test.ts +101 -0
- package/src/ui/report.ts +146 -0
- package/src/ui/test-helpers.ts +184 -0
- package/src/ui/types.ts +325 -0
- package/src/utils/atomic-write.test.ts +312 -0
- package/src/utils/atomic-write.ts +422 -0
- package/src/utils/env-lock.test.ts +999 -0
- package/src/utils/env-lock.ts +1086 -0
- package/src/utils/hashing.ts +53 -0
- package/src/utils/json.ts +77 -0
- package/src/utils/logger.ts +114 -0
- package/src/utils/paths.ts +176 -0
- package/src/utils/proxy.test.ts +465 -0
- package/src/utils/proxy.ts +493 -0
- package/src/utils/recursive-walk.test.ts +148 -0
- package/src/utils/recursive-walk.ts +145 -0
- package/src/utils/zip.ts +332 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 完整性工具(integrity/checksums.json 的生成与校验)。
|
|
3
|
+
* m4 的 security/integrity.ts 可在此之上强化(本模块已实现规范 §18 全部语义)。
|
|
4
|
+
*/
|
|
5
|
+
import crypto from 'node:crypto';
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
7
|
+
|
|
8
|
+
export function sha256Hex(data: Uint8Array | string): string {
|
|
9
|
+
return crypto.createHash('sha256').update(data).digest('hex');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function hashFile(filePath: string): Promise<string> {
|
|
13
|
+
const data = await fs.readFile(filePath);
|
|
14
|
+
return sha256Hex(data);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 生成一组 ZIP 相对路径 → SHA-256 的校验表(路径必须为 ZIP 内正斜杠相对路径) */
|
|
18
|
+
export function buildChecksums(entries: { name: string; data: Uint8Array }[]): Record<string, string> {
|
|
19
|
+
const checksums: Record<string, string> = {};
|
|
20
|
+
for (const e of entries) {
|
|
21
|
+
checksums[e.name] = sha256Hex(e.data);
|
|
22
|
+
}
|
|
23
|
+
return checksums;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ChecksumVerifyResult {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
mismatches: string[];
|
|
29
|
+
missing: string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 校验:checksums 表内每个相对路径必须在 entries 中存在且 SHA-256 一致。
|
|
34
|
+
* entries 中多余的文件(如 manifest.json / checksums.json 自身)不参与校验。
|
|
35
|
+
*/
|
|
36
|
+
export function verifyChecksums(
|
|
37
|
+
entries: ReadonlyMap<string, Uint8Array>,
|
|
38
|
+
checksums: Record<string, string>,
|
|
39
|
+
): ChecksumVerifyResult {
|
|
40
|
+
const mismatches: string[] = [];
|
|
41
|
+
const missing: string[] = [];
|
|
42
|
+
for (const [relPath, expected] of Object.entries(checksums)) {
|
|
43
|
+
const data = entries.get(relPath);
|
|
44
|
+
if (data === undefined) {
|
|
45
|
+
missing.push(relPath);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (sha256Hex(data) !== expected) {
|
|
49
|
+
mismatches.push(relPath);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { ok: mismatches.length === 0 && missing.length === 0, mismatches, missing };
|
|
53
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON 深度保护:解析/序列化/克隆带嵌套深度上限(防 JSON 深度攻击,规范 §19.5)。
|
|
3
|
+
* 解析分两段:JSON.parse 可能因引擎栈限制抛 RangeError(捕获并归一),
|
|
4
|
+
* 再对结果做显式栈 walk 检查深度(避免 walk 自身递归爆栈)。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_MAX_JSON_DEPTH = 64;
|
|
8
|
+
export const DEFAULT_MAX_JSON_BYTES = 64 * 1024 * 1024;
|
|
9
|
+
|
|
10
|
+
export class JsonDepthError extends Error {
|
|
11
|
+
constructor(message = `JSON 嵌套深度超过上限 ${DEFAULT_MAX_JSON_DEPTH}`) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'JsonDepthError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 测量对象/数组的嵌套深度(迭代式显式栈,不会递归爆栈;二进制视为叶子) */
|
|
18
|
+
export function measureDepth(value: unknown): number {
|
|
19
|
+
let max = 0;
|
|
20
|
+
// 栈元素:[value, depth]
|
|
21
|
+
const stack: [unknown, number][] = [[value, 1]];
|
|
22
|
+
while (stack.length > 0) {
|
|
23
|
+
const [current, depth] = stack.pop()!;
|
|
24
|
+
if (depth > max) max = depth;
|
|
25
|
+
if (current !== null && typeof current === 'object' && !(current instanceof Uint8Array)) {
|
|
26
|
+
const next = depth + 1;
|
|
27
|
+
if (Array.isArray(current)) {
|
|
28
|
+
for (const item of current) stack.push([item, next]);
|
|
29
|
+
} else {
|
|
30
|
+
for (const key of Object.keys(current as Record<string, unknown>)) {
|
|
31
|
+
stack.push([(current as Record<string, unknown>)[key], next]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return max;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 深度保护解析:超限抛 JsonDepthError,非法 JSON 抛 SyntaxError */
|
|
40
|
+
export function parseJsonSafe(
|
|
41
|
+
text: string,
|
|
42
|
+
opts: { maxDepth?: number; maxBytes?: number } = {},
|
|
43
|
+
): unknown {
|
|
44
|
+
const maxDepth = opts.maxDepth ?? DEFAULT_MAX_JSON_DEPTH;
|
|
45
|
+
const maxBytes = opts.maxBytes ?? DEFAULT_MAX_JSON_BYTES;
|
|
46
|
+
if (text.length > maxBytes) {
|
|
47
|
+
throw new JsonDepthError(`JSON 体积超过上限 ${maxBytes} 字节`);
|
|
48
|
+
}
|
|
49
|
+
let parsed: unknown;
|
|
50
|
+
try {
|
|
51
|
+
parsed = JSON.parse(text);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
// 引擎栈限制导致的深层嵌套也会以 RangeError 出现 → 归一为 JsonDepthError
|
|
54
|
+
if (err instanceof RangeError) throw new JsonDepthError(`JSON 解析失败(可能是嵌套过深): ${String(err.message)}`);
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
const depth = measureDepth(parsed);
|
|
58
|
+
if (depth > maxDepth) {
|
|
59
|
+
throw new JsonDepthError(`JSON 嵌套深度 ${depth} 超过上限 ${maxDepth}`);
|
|
60
|
+
}
|
|
61
|
+
return parsed;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 深度保护序列化:先测深度再 stringify(默认不缩进) */
|
|
65
|
+
export function stringifyJsonSafe(value: unknown, opts: { maxDepth?: number; space?: number } = {}): string {
|
|
66
|
+
const maxDepth = opts.maxDepth ?? DEFAULT_MAX_JSON_DEPTH;
|
|
67
|
+
const depth = measureDepth(value);
|
|
68
|
+
if (depth > maxDepth) throw new JsonDepthError(`JSON 嵌套深度 ${depth} 超过上限 ${maxDepth}`);
|
|
69
|
+
return JSON.stringify(value, null, opts.space);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 深度保护深拷贝(迭代式,安全) */
|
|
73
|
+
export function deepClone<T>(value: T, maxDepth: number = DEFAULT_MAX_JSON_DEPTH): T {
|
|
74
|
+
const depth = measureDepth(value);
|
|
75
|
+
if (depth > maxDepth) throw new JsonDepthError();
|
|
76
|
+
return JSON.parse(JSON.stringify(value)) as T;
|
|
77
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 结构化日志(规范 §24):LEVEL / 消息 / 可选元数据,带 redact 钩子。
|
|
3
|
+
* Secret 值永不入日志:sink 前对 msg 做文本级掩码、对 meta 做字段名级掩码。
|
|
4
|
+
*/
|
|
5
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
6
|
+
|
|
7
|
+
/** 敏感字段名黑名单(大小写不敏感;命中即掩码值,规范 §6 清单) */
|
|
8
|
+
export const SENSITIVE_FIELD_BLACKLIST = [
|
|
9
|
+
'password', 'passwd', 'token', 'accesstoken', 'refreshtoken', 'apikey',
|
|
10
|
+
'secret', 'credential', 'authorization', 'cookie', 'privatekey', 'clientsecret',
|
|
11
|
+
'sessionkey', 'authtoken', 'bearer',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const REDACTED = '***REDACTED***';
|
|
15
|
+
|
|
16
|
+
/** 字段名是否命中敏感黑名单(大小写不敏感,子串匹配) */
|
|
17
|
+
export function isSensitiveField(field: string): boolean {
|
|
18
|
+
const lower = field.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
19
|
+
return SENSITIVE_FIELD_BLACKLIST.some((f) => lower.includes(f));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 对象级掩码:字段名命中黑名单 → 值替换(返回新对象,不改原对象) */
|
|
23
|
+
export function redactValue(value: unknown, blacklist: string[] = SENSITIVE_FIELD_BLACKLIST): unknown {
|
|
24
|
+
if (value === null || typeof value !== 'object') return value;
|
|
25
|
+
if (Array.isArray(value)) return value.map((v) => redactValue(v, blacklist));
|
|
26
|
+
const out: Record<string, unknown> = {};
|
|
27
|
+
for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
|
|
28
|
+
const lower = k.toLowerCase();
|
|
29
|
+
const hit = blacklist.some((f) => lower.includes(f));
|
|
30
|
+
out[k] = hit ? REDACTED : redactValue(v, blacklist);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 文本级掩码:JSON 片段 `"field": "value"`、`field=value`、`field: value` 形态 */
|
|
36
|
+
export function redact(text: string, blacklist: string[] = SENSITIVE_FIELD_BLACKLIST): string {
|
|
37
|
+
let out = text;
|
|
38
|
+
for (const field of blacklist) {
|
|
39
|
+
// "field": "anything"
|
|
40
|
+
out = out.replace(new RegExp(`("${field}"\\s*:\\s*")[^"]*(")`, 'gi'), `$1${REDACTED}$2`);
|
|
41
|
+
// field=value / field: value(不含 JSON 引号形态)
|
|
42
|
+
out = out.replace(new RegExp(`(\\b${field}\\s*=\\s*)[^\\s,;]+`, 'gi'), `$1${REDACTED}`);
|
|
43
|
+
out = out.replace(new RegExp(`(\\b${field}\\s*:\\s*)[^\\s,;}]+`, 'gi'), `$1${REDACTED}`);
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface LogMeta { [key: string]: unknown }
|
|
49
|
+
|
|
50
|
+
export interface LogSink {
|
|
51
|
+
(level: LogLevel, message: string, meta?: LogMeta): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface Logger {
|
|
55
|
+
level: LogLevel;
|
|
56
|
+
debug(message: string, meta?: LogMeta): void;
|
|
57
|
+
info(message: string, meta?: LogMeta): void;
|
|
58
|
+
warn(message: string, meta?: LogMeta): void;
|
|
59
|
+
error(message: string, meta?: LogMeta): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface LoggerOptions {
|
|
63
|
+
level?: LogLevel;
|
|
64
|
+
/** 输出目标;缺省写 console(单行 JSON)。测试可注入内存 sink。 */
|
|
65
|
+
sink?: LogSink;
|
|
66
|
+
/** 额外敏感字段黑名单 */
|
|
67
|
+
extraBlacklist?: string[];
|
|
68
|
+
/** 是否带时间戳前缀 */
|
|
69
|
+
timestamp?: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const LEVEL_ORDER: Record<LogLevel, number> = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
73
|
+
|
|
74
|
+
/** 创建结构化日志器(默认 console JSON 行,全部输出过 redact) */
|
|
75
|
+
export function createLogger(opts: LoggerOptions = {}): Logger {
|
|
76
|
+
const level = opts.level ?? 'info';
|
|
77
|
+
const blacklist = [...SENSITIVE_FIELD_BLACKLIST, ...(opts.extraBlacklist ?? [])];
|
|
78
|
+
const sink: LogSink = opts.sink ?? ((lvl, message, meta) => {
|
|
79
|
+
const line = JSON.stringify({
|
|
80
|
+
ts: new Date().toISOString(),
|
|
81
|
+
level: lvl,
|
|
82
|
+
msg: redact(message, blacklist),
|
|
83
|
+
...(meta ? { meta: redactValue(meta, blacklist) } : {}),
|
|
84
|
+
});
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
(lvl === 'error' ? console.error : lvl === 'warn' ? console.warn : console.log)(line);
|
|
87
|
+
});
|
|
88
|
+
const emit = (lvl: LogLevel, message: string, meta?: LogMeta): void => {
|
|
89
|
+
if (LEVEL_ORDER[lvl] < LEVEL_ORDER[level]) return;
|
|
90
|
+
try {
|
|
91
|
+
sink(lvl, message, meta);
|
|
92
|
+
} catch {
|
|
93
|
+
// 日志器自身永不抛错
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
level,
|
|
98
|
+
debug: (m, meta) => emit('debug', m, meta),
|
|
99
|
+
info: (m, meta) => emit('info', m, meta),
|
|
100
|
+
warn: (m, meta) => emit('warn', m, meta),
|
|
101
|
+
error: (m, meta) => emit('error', m, meta),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 静默日志器(测试用) */
|
|
106
|
+
export function nullLogger(): Logger {
|
|
107
|
+
return {
|
|
108
|
+
level: 'error',
|
|
109
|
+
debug: () => {},
|
|
110
|
+
info: () => {},
|
|
111
|
+
warn: () => {},
|
|
112
|
+
error: () => {},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路径处理唯一出口(node:path 不直接散落业务代码):
|
|
3
|
+
* 规范化、平台判定、绝对路径识别、前缀批量映射、ZIP 条目名安全校验。
|
|
4
|
+
*/
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import type { PathMapping } from '../core/types.ts';
|
|
7
|
+
|
|
8
|
+
/** 归一化内部表示:统一 `/` 分隔、去尾部斜杠(空串保持) */
|
|
9
|
+
export function normalizePath(p: string): string {
|
|
10
|
+
if (p === '') return '';
|
|
11
|
+
const norm = p.replaceAll('\\', '/');
|
|
12
|
+
return norm.length > 1 ? norm.replace(/\/+$/, '') : norm;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** 转当前平台原生路径 */
|
|
16
|
+
export function toNativePath(p: string): string {
|
|
17
|
+
const norm = normalizePath(p);
|
|
18
|
+
if (process.platform === 'win32') return norm.replaceAll('/', '\\');
|
|
19
|
+
return norm;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 跨平台绝对路径识别(POSIX `/x` 与 Windows `C:\x`、UNC `\\server\share`) */
|
|
23
|
+
export function isAbsolutePath(p: string): boolean {
|
|
24
|
+
if (p === '') return false;
|
|
25
|
+
if (p.startsWith('/')) return true;
|
|
26
|
+
if (/^[a-zA-Z]:[\\/]/.test(p)) return true; // 盘符
|
|
27
|
+
if (p.startsWith('\\\\') || p.startsWith('//')) return true; // UNC
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 路径是否为 home 目录(~ 或用户主目录开头) */
|
|
32
|
+
export function isHomePath(p: string, homeDir: string): boolean {
|
|
33
|
+
const norm = normalizePath(p);
|
|
34
|
+
const home = normalizePath(homeDir);
|
|
35
|
+
return norm === '~' || norm === home || norm.startsWith(home + '/') || norm.startsWith('~/');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 目标平台与当前平台是否一致 */
|
|
39
|
+
export function isSamePlatform(a: string, b: string): boolean {
|
|
40
|
+
return a === b;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** ZIP 条目名安全检查(Zip Slip / 绝对路径 / 盘符 / NUL,规范 §19.1-2)。
|
|
44
|
+
* 规则与 node:path 解耦:纯分段校验,跨平台无歧义。 */
|
|
45
|
+
export function isPathSafe(entryName: string): boolean {
|
|
46
|
+
if (entryName === '') return false;
|
|
47
|
+
if (entryName.includes('\0')) return false;
|
|
48
|
+
if (entryName.startsWith('/') || entryName.startsWith('\\')) return false; // 绝对路径
|
|
49
|
+
if (/^[a-zA-Z]:[\\/]/.test(entryName)) return false; // 盘符
|
|
50
|
+
if (/^\\\\/.test(entryName)) return false; // UNC
|
|
51
|
+
const segments = entryName.split(/[\\/]+/);
|
|
52
|
+
if (segments.some((s) => s === '..')) return false; // 目录穿越
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 候选目录是否位于父目录之内(含等于父目录) */
|
|
57
|
+
export function isSameOrChild(p: string, parent: string): boolean {
|
|
58
|
+
const rel = path.relative(parent, p);
|
|
59
|
+
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 内部 control-plane namespace(F23 修复):不可信 import(pluginFiles/self/file adapters)
|
|
64
|
+
* 不得把普通 config/file item 映射到这些 recovery storage 目录。
|
|
65
|
+
* 相对 homeDir 的路径(正斜杠归一)命中任一前缀 → 拒绝。
|
|
66
|
+
*/
|
|
67
|
+
const RESERVED_INTERNAL_PREFIXES: readonly string[] = [
|
|
68
|
+
'dsh-config-manager/snapshots/',
|
|
69
|
+
'dsh-config-manager/transactions/',
|
|
70
|
+
'dsh-config-manager/locks/',
|
|
71
|
+
'dsh-config-manager/safe-mode',
|
|
72
|
+
'dsh-config-manager/recovery-history/',
|
|
73
|
+
'dsh-config-manager/environment-fingerprint.token',
|
|
74
|
+
// Phase 6:迁移历史审计目录(统一历史引擎;防 F23 投毒链——不可信导入不得映射到该目录)。
|
|
75
|
+
'dsh-config-manager/migration-history/',
|
|
76
|
+
// 注意:不得整段保留 dsh-config-manager/sync/ —— self 分区合法持有 sync/*.json 白名单配置
|
|
77
|
+
//(sync-config / sync-selection / ui-prefs / backup-schedule),会误伤。
|
|
78
|
+
'dsh-config-manager/sync/snapshots/',
|
|
79
|
+
'dsh-config-manager/sync/work/',
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 归一化并折叠 `.` / `..` 路径段(Reviewer B P0 修复)。
|
|
84
|
+
* 宿主 fs 经 `resolve(join(homeDir, rel))` 会折叠 `..`,因此「看似不在保留命名空间、实际经 `..` 落到保留区」
|
|
85
|
+
* 的路径(如 `dsh-config-manager/../dsh-config-manager/snapshots/...`)必须在此折叠后再判,否则 F23 被绕过。
|
|
86
|
+
* 纯字符串、跨平台(只用 `/`)语义与 node:path normalize 一致;`..` 超根时按根截断(不越到 home 外)。
|
|
87
|
+
*/
|
|
88
|
+
export function normalizePathCollapsed(p: string): string {
|
|
89
|
+
const norm = normalizePath(p);
|
|
90
|
+
if (norm === '') return '';
|
|
91
|
+
if (norm === '.') return '';
|
|
92
|
+
const out: string[] = [];
|
|
93
|
+
for (const seg of norm.split('/')) {
|
|
94
|
+
if (seg === '' || seg === '.') continue;
|
|
95
|
+
if (seg === '..') {
|
|
96
|
+
if (out.length > 0) out.pop();
|
|
97
|
+
continue; // 超根 `..` 直接丢弃(home 相对路径不可能越出 homeDir)
|
|
98
|
+
}
|
|
99
|
+
out.push(seg);
|
|
100
|
+
}
|
|
101
|
+
return out.join('/');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** 判断相对 homeDir 的路径是否落在内部 control-plane namespace(F23 投毒防护)。
|
|
105
|
+
* 大小写不敏感(Windows 文件系统大小写不敏感,防 `DSh-Config-Manager/...` 绕过);
|
|
106
|
+
* 先折叠 `..`/`.` 段(宿主 fs 会折叠,此处必须同样折叠以免被路径穿越绕过)。 */
|
|
107
|
+
export function isReservedInternalRel(relPath: string): boolean {
|
|
108
|
+
const norm = normalizePathCollapsed(relPath).toLowerCase();
|
|
109
|
+
if (norm === '') return false;
|
|
110
|
+
for (const prefix of RESERVED_INTERNAL_PREFIXES) {
|
|
111
|
+
if (norm === prefix || norm.startsWith(prefix)) return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 前缀批量映射(规范 §12):把对象内所有字符串值中匹配 oldPrefix 的路径
|
|
118
|
+
* 替换为 newPrefix(路径感知:必须落在段边界)。返回新对象(不改原对象)。
|
|
119
|
+
*/
|
|
120
|
+
export function applyPrefixMappings(value: unknown, mappings: PathMapping[]): unknown {
|
|
121
|
+
if (mappings.length === 0) return value;
|
|
122
|
+
return mapStrings(value, (s) => {
|
|
123
|
+
let out = s;
|
|
124
|
+
for (const m of mappings) {
|
|
125
|
+
const oldNorm = normalizePath(m.oldPrefix);
|
|
126
|
+
if (oldNorm === '') continue;
|
|
127
|
+
const candidate = normalizePath(out);
|
|
128
|
+
if (candidate === oldNorm) {
|
|
129
|
+
out = normalizePath(m.newPrefix);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (candidate.startsWith(oldNorm + '/')) {
|
|
133
|
+
const rest = candidate.slice(oldNorm.length); // 含前导 /
|
|
134
|
+
out = normalizePath(normalizePath(m.newPrefix) + rest);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 对对象内所有字符串叶节点做变换(迭代式,保留非字符串原样;二进制 Uint8Array 视为叶子) */
|
|
142
|
+
export function mapStrings(value: unknown, fn: (s: string) => string): unknown {
|
|
143
|
+
if (typeof value === 'string') return fn(value);
|
|
144
|
+
if (value === null || typeof value !== 'object') return value;
|
|
145
|
+
if (value instanceof Uint8Array) return value; // 二进制不按字段展开
|
|
146
|
+
if (Array.isArray(value)) return value.map((v) => mapStrings(v, fn));
|
|
147
|
+
const out: Record<string, unknown> = {};
|
|
148
|
+
for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
|
|
149
|
+
out[k] = mapStrings(v, fn);
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 收集对象中所有绝对路径叶值(供 analyzer 做跨设备路径检测)。
|
|
156
|
+
* 返回 (value, jsonPath) 对;jsonPath 形如 "workspaces[0].path"。
|
|
157
|
+
*/
|
|
158
|
+
export function collectAbsolutePaths(value: unknown, prefix = ''): { value: string; path: string }[] {
|
|
159
|
+
const hits: { value: string; path: string }[] = [];
|
|
160
|
+
const visit = (v: unknown, p: string): void => {
|
|
161
|
+
if (typeof v === 'string') {
|
|
162
|
+
if (isAbsolutePath(v)) hits.push({ value: v, path: p });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (v === null || typeof v !== 'object') return;
|
|
166
|
+
if (Array.isArray(v)) {
|
|
167
|
+
v.forEach((item, i) => visit(item, `${p}[${i}]`));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
for (const [k, val] of Object.entries(v as Record<string, unknown>)) {
|
|
171
|
+
visit(val, p === '' ? k : `${p}.${k}`);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
visit(value, prefix);
|
|
175
|
+
return hits;
|
|
176
|
+
}
|