resuxjs 0.3.11 → 0.4.0-beta.2
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/README.md +23 -1
- package/dist/bin.d.ts +1 -2
- package/dist/bin.js +4 -0
- package/dist/bin.js.map +1 -1
- package/dist/build/index.d.ts +28 -0
- package/dist/build/index.js +51 -0
- package/dist/build/index.js.map +1 -0
- package/dist/cli.d.ts +15 -5
- package/dist/cli.js +2648 -3671
- package/dist/cli.js.map +1 -1
- package/dist/compiler/adapter.d.ts +14 -11
- package/dist/compiler/adapter.js +68 -93
- package/dist/compiler/adapter.js.map +1 -1
- package/dist/compiler/dev-warnings.d.ts +8 -5
- package/dist/compiler/dev-warnings.js +248 -321
- package/dist/compiler/dev-warnings.js.map +1 -1
- package/dist/compiler/directives.d.ts +3 -0
- package/dist/compiler/directives.js +124 -150
- package/dist/compiler/directives.js.map +1 -1
- package/dist/compiler/implementation.d.ts +96 -93
- package/dist/compiler/implementation.js +2967 -3430
- package/dist/compiler/index.d.ts +14 -11
- package/dist/compiler/index.js +68 -93
- package/dist/compiler/index.js.map +1 -1
- package/dist/core/config.d.ts +12 -5
- package/dist/core/config.js +42 -25
- package/dist/core/config.js.map +1 -1
- package/dist/core/hooks.d.ts +127 -126
- package/dist/core/hooks.js +45 -55
- package/dist/core/hooks.js.map +1 -1
- package/dist/core/index.d.ts +5 -4
- package/dist/core/index.js +5 -5
- package/dist/core/module-container.d.ts +76 -74
- package/dist/core/module-container.js +181 -186
- package/dist/core/module-container.js.map +1 -1
- package/dist/core/resux.d.ts +15 -12
- package/dist/core/resux.js +17 -13
- package/dist/core/resux.js.map +1 -1
- package/dist/create-bin.d.ts +1 -2
- package/dist/create-bin.js +4 -0
- package/dist/create-bin.js.map +1 -1
- package/dist/create.d.ts +3 -0
- package/dist/create.js +499 -638
- package/dist/create.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts +4 -1
- package/dist/deploy/cloudflare.js +30 -34
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/deploy/common.d.ts +6 -4
- package/dist/deploy/common.js +118 -188
- package/dist/deploy/common.js.map +1 -1
- package/dist/deploy/framework-runtime.d.ts +3 -0
- package/dist/deploy/framework-runtime.js +43 -48
- package/dist/deploy/framework-runtime.js.map +1 -1
- package/dist/deploy/index.d.ts +4 -1
- package/dist/deploy/index.js +58 -80
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/netlify.d.ts +4 -1
- package/dist/deploy/netlify.js +40 -41
- package/dist/deploy/netlify.js.map +1 -1
- package/dist/deploy/node.d.ts +4 -1
- package/dist/deploy/node.js +24 -19
- package/dist/deploy/node.js.map +1 -1
- package/dist/deploy/production-report.d.ts +3 -0
- package/dist/deploy/production-report.js +14 -14
- package/dist/deploy/production-report.js.map +1 -1
- package/dist/deploy/runtime-dependencies.d.ts +3 -0
- package/dist/deploy/runtime-dependencies.js +158 -220
- package/dist/deploy/runtime-dependencies.js.map +1 -1
- package/dist/deploy/static.d.ts +4 -1
- package/dist/deploy/static.js +16 -14
- package/dist/deploy/static.js.map +1 -1
- package/dist/deploy/types.d.ts +25 -22
- package/dist/deploy/types.js +0 -1
- package/dist/deploy/vercel.d.ts +4 -1
- package/dist/deploy/vercel.js +137 -188
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/fonts/index.d.ts +15 -11
- package/dist/fonts/index.js +114 -134
- package/dist/fonts/index.js.map +1 -1
- package/dist/globals.d.ts +79 -78
- package/dist/globals.js +0 -1
- package/dist/halal-core/ai/classifyProject.d.ts +4 -1
- package/dist/halal-core/ai/classifyProject.js +81 -95
- package/dist/halal-core/ai/classifyProject.js.map +1 -1
- package/dist/halal-core/ai/classifyRuntimeContent.d.ts +5 -2
- package/dist/halal-core/ai/classifyRuntimeContent.js +77 -95
- package/dist/halal-core/ai/classifyRuntimeContent.js.map +1 -1
- package/dist/halal-core/ai/createProjectSummary.d.ts +38 -35
- package/dist/halal-core/ai/createProjectSummary.js +38 -39
- package/dist/halal-core/ai/createProjectSummary.js.map +1 -1
- package/dist/halal-core/ai/halalClassifierPrompt.d.ts +3 -0
- package/dist/halal-core/ai/halalClassifierPrompt.js +5 -1
- package/dist/halal-core/ai/halalClassifierPrompt.js.map +1 -1
- package/dist/halal-core/ai/redactSensitiveData.d.ts +3 -0
- package/dist/halal-core/ai/redactSensitiveData.js +82 -110
- package/dist/halal-core/ai/redactSensitiveData.js.map +1 -1
- package/dist/halal-core/ai/validateAiResponse.d.ts +4 -1
- package/dist/halal-core/ai/validateAiResponse.js +58 -85
- package/dist/halal-core/ai/validateAiResponse.js.map +1 -1
- package/dist/halal-core/cli/check.d.ts +3 -0
- package/dist/halal-core/cli/check.js +28 -30
- package/dist/halal-core/cli/check.js.map +1 -1
- package/dist/halal-core/cli/explain.d.ts +3 -0
- package/dist/halal-core/cli/explain.js +27 -31
- package/dist/halal-core/cli/explain.js.map +1 -1
- package/dist/halal-core/cli/report.d.ts +3 -0
- package/dist/halal-core/cli/report.js +14 -10
- package/dist/halal-core/cli/report.js.map +1 -1
- package/dist/halal-core/cli/submitReview.d.ts +3 -0
- package/dist/halal-core/cli/submitReview.js +13 -9
- package/dist/halal-core/cli/submitReview.js.map +1 -1
- package/dist/halal-core/cli/verifyReview.d.ts +3 -0
- package/dist/halal-core/cli/verifyReview.js +18 -15
- package/dist/halal-core/cli/verifyReview.js.map +1 -1
- package/dist/halal-core/config.d.ts +30 -27
- package/dist/halal-core/config.js +76 -118
- package/dist/halal-core/config.js.map +1 -1
- package/dist/halal-core/crypto/integrity.d.ts +6 -3
- package/dist/halal-core/crypto/integrity.js +64 -87
- package/dist/halal-core/crypto/integrity.js.map +1 -1
- package/dist/halal-core/enforce.d.ts +3 -0
- package/dist/halal-core/enforce.js +92 -105
- package/dist/halal-core/enforce.js.map +1 -1
- package/dist/halal-core/index.d.ts +20 -16
- package/dist/halal-core/index.js +18 -19
- package/dist/halal-core/lifecycle.d.ts +3 -0
- package/dist/halal-core/lifecycle.js +15 -13
- package/dist/halal-core/lifecycle.js.map +1 -1
- package/dist/halal-core/policy.d.ts +4 -1
- package/dist/halal-core/policy.js +6 -2
- package/dist/halal-core/policy.js.map +1 -1
- package/dist/halal-core/report/formatBrowserOverlay.d.ts +4 -1
- package/dist/halal-core/report/formatBrowserOverlay.js +10 -8
- package/dist/halal-core/report/formatBrowserOverlay.js.map +1 -1
- package/dist/halal-core/report/formatTerminalReport.d.ts +4 -1
- package/dist/halal-core/report/formatTerminalReport.js +27 -37
- package/dist/halal-core/report/formatTerminalReport.js.map +1 -1
- package/dist/halal-core/report/generateHalalReport.d.ts +7 -4
- package/dist/halal-core/report/generateHalalReport.js +26 -26
- package/dist/halal-core/report/generateHalalReport.js.map +1 -1
- package/dist/halal-core/report/signReport.d.ts +4 -1
- package/dist/halal-core/report/signReport.js +16 -12
- package/dist/halal-core/report/signReport.js.map +1 -1
- package/dist/halal-core/report/verifyReport.d.ts +9 -6
- package/dist/halal-core/report/verifyReport.js +51 -41
- package/dist/halal-core/report/verifyReport.js.map +1 -1
- package/dist/halal-core/review/createReviewRequest.d.ts +4 -1
- package/dist/halal-core/review/createReviewRequest.js +21 -17
- package/dist/halal-core/review/createReviewRequest.js.map +1 -1
- package/dist/halal-core/review/reviewPolicy.d.ts +3 -0
- package/dist/halal-core/review/reviewPolicy.js +19 -17
- package/dist/halal-core/review/reviewPolicy.js.map +1 -1
- package/dist/halal-core/review/signedReviewFile.d.ts +11 -8
- package/dist/halal-core/review/signedReviewFile.js +24 -22
- package/dist/halal-core/review/signedReviewFile.js.map +1 -1
- package/dist/halal-core/review/verifyReviewApproval.d.ts +9 -6
- package/dist/halal-core/review/verifyReviewApproval.js +68 -62
- package/dist/halal-core/review/verifyReviewApproval.js.map +1 -1
- package/dist/halal-core/rules/adultContentRules.d.ts +3 -0
- package/dist/halal-core/rules/adultContentRules.js +23 -23
- package/dist/halal-core/rules/adultContentRules.js.map +1 -1
- package/dist/halal-core/rules/alcoholDrugVapeRules.d.ts +3 -0
- package/dist/halal-core/rules/alcoholDrugVapeRules.js +22 -22
- package/dist/halal-core/rules/alcoholDrugVapeRules.js.map +1 -1
- package/dist/halal-core/rules/childSafetyRules.d.ts +3 -0
- package/dist/halal-core/rules/childSafetyRules.js +19 -19
- package/dist/halal-core/rules/childSafetyRules.js.map +1 -1
- package/dist/halal-core/rules/coreCategories.d.ts +7 -4
- package/dist/halal-core/rules/coreCategories.js +237 -110
- package/dist/halal-core/rules/coreCategories.js.map +1 -1
- package/dist/halal-core/rules/cyberAbuseRules.d.ts +3 -0
- package/dist/halal-core/rules/cyberAbuseRules.js +27 -27
- package/dist/halal-core/rules/cyberAbuseRules.js.map +1 -1
- package/dist/halal-core/rules/defaultBlockedRules.d.ts +21 -18
- package/dist/halal-core/rules/defaultBlockedRules.js +158 -199
- package/dist/halal-core/rules/defaultBlockedRules.js.map +1 -1
- package/dist/halal-core/rules/dependencyRules.d.ts +8 -5
- package/dist/halal-core/rules/dependencyRules.js +50 -56
- package/dist/halal-core/rules/dependencyRules.js.map +1 -1
- package/dist/halal-core/rules/endpointRules.d.ts +6 -3
- package/dist/halal-core/rules/endpointRules.js +21 -23
- package/dist/halal-core/rules/endpointRules.js.map +1 -1
- package/dist/halal-core/rules/environmentalHarmRules.d.ts +3 -0
- package/dist/halal-core/rules/environmentalHarmRules.js +17 -17
- package/dist/halal-core/rules/environmentalHarmRules.js.map +1 -1
- package/dist/halal-core/rules/financeRibaRules.d.ts +3 -0
- package/dist/halal-core/rules/financeRibaRules.js +20 -20
- package/dist/halal-core/rules/financeRibaRules.js.map +1 -1
- package/dist/halal-core/rules/gamblingRules.d.ts +3 -0
- package/dist/halal-core/rules/gamblingRules.js +22 -22
- package/dist/halal-core/rules/gamblingRules.js.map +1 -1
- package/dist/halal-core/rules/generalHarmRules.d.ts +3 -0
- package/dist/halal-core/rules/generalHarmRules.js +15 -15
- package/dist/halal-core/rules/generalHarmRules.js.map +1 -1
- package/dist/halal-core/rules/healthHarmRules.d.ts +3 -0
- package/dist/halal-core/rules/healthHarmRules.js +19 -19
- package/dist/halal-core/rules/healthHarmRules.js.map +1 -1
- package/dist/halal-core/rules/keywordRules.d.ts +11 -8
- package/dist/halal-core/rules/keywordRules.js +90 -39
- package/dist/halal-core/rules/keywordRules.js.map +1 -1
- package/dist/halal-core/rules/privacyAbuseRules.d.ts +3 -0
- package/dist/halal-core/rules/privacyAbuseRules.js +21 -21
- package/dist/halal-core/rules/privacyAbuseRules.js.map +1 -1
- package/dist/halal-core/rules/scamFraudRules.d.ts +3 -0
- package/dist/halal-core/rules/scamFraudRules.js +29 -29
- package/dist/halal-core/rules/scamFraudRules.js.map +1 -1
- package/dist/halal-core/rules/selfHarmRules.d.ts +3 -0
- package/dist/halal-core/rules/selfHarmRules.js +17 -17
- package/dist/halal-core/rules/selfHarmRules.js.map +1 -1
- package/dist/halal-core/rules/violenceExtremismRules.d.ts +3 -0
- package/dist/halal-core/rules/violenceExtremismRules.js +30 -30
- package/dist/halal-core/rules/violenceExtremismRules.js.map +1 -1
- package/dist/halal-core/runtime/guard.d.ts +17 -14
- package/dist/halal-core/runtime/guard.js +162 -183
- package/dist/halal-core/runtime/guard.js.map +1 -1
- package/dist/halal-core/runtime/index.d.ts +5 -4
- package/dist/halal-core/runtime/index.js +4 -5
- package/dist/halal-core/runtime/reviewedMemory.d.ts +4 -1
- package/dist/halal-core/runtime/reviewedMemory.js +74 -110
- package/dist/halal-core/runtime/reviewedMemory.js.map +1 -1
- package/dist/halal-core/runtime/serializeRuntimeContent.d.ts +10 -7
- package/dist/halal-core/runtime/serializeRuntimeContent.js +132 -156
- package/dist/halal-core/runtime/serializeRuntimeContent.js.map +1 -1
- package/dist/halal-core/runtime/types.d.ts +44 -41
- package/dist/halal-core/runtime/types.js +0 -1
- package/dist/halal-core/scanner/scanApiRoutes.d.ts +3 -0
- package/dist/halal-core/scanner/scanApiRoutes.js +32 -36
- package/dist/halal-core/scanner/scanApiRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanComponents.d.ts +3 -0
- package/dist/halal-core/scanner/scanComponents.js +12 -13
- package/dist/halal-core/scanner/scanComponents.js.map +1 -1
- package/dist/halal-core/scanner/scanContent.d.ts +5 -2
- package/dist/halal-core/scanner/scanContent.js +193 -263
- package/dist/halal-core/scanner/scanContent.js.map +1 -1
- package/dist/halal-core/scanner/scanDependencies.d.ts +3 -0
- package/dist/halal-core/scanner/scanDependencies.js +16 -15
- package/dist/halal-core/scanner/scanDependencies.js.map +1 -1
- package/dist/halal-core/scanner/scanDomains.d.ts +5 -2
- package/dist/halal-core/scanner/scanDomains.js +12 -12
- package/dist/halal-core/scanner/scanDomains.js.map +1 -1
- package/dist/halal-core/scanner/scanEnvNames.d.ts +3 -0
- package/dist/halal-core/scanner/scanEnvNames.js +23 -26
- package/dist/halal-core/scanner/scanEnvNames.js.map +1 -1
- package/dist/halal-core/scanner/scanMetadata.d.ts +6 -3
- package/dist/halal-core/scanner/scanMetadata.js +20 -29
- package/dist/halal-core/scanner/scanMetadata.js.map +1 -1
- package/dist/halal-core/scanner/scanPages.d.ts +3 -0
- package/dist/halal-core/scanner/scanPages.js +12 -15
- package/dist/halal-core/scanner/scanPages.js.map +1 -1
- package/dist/halal-core/scanner/scanProject.d.ts +15 -10
- package/dist/halal-core/scanner/scanProject.js +43 -49
- package/dist/halal-core/scanner/scanProject.js.map +1 -1
- package/dist/halal-core/scanner/scanRoutes.d.ts +3 -0
- package/dist/halal-core/scanner/scanRoutes.js +32 -39
- package/dist/halal-core/scanner/scanRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanTranslations.d.ts +3 -0
- package/dist/halal-core/scanner/scanTranslations.js +21 -29
- package/dist/halal-core/scanner/scanTranslations.js.map +1 -1
- package/dist/halal-core/status.d.ts +14 -11
- package/dist/halal-core/status.js +0 -1
- package/dist/halal-core/tamper/verifyCoreIntegrity.d.ts +3 -0
- package/dist/halal-core/tamper/verifyCoreIntegrity.js +26 -24
- package/dist/halal-core/tamper/verifyCoreIntegrity.js.map +1 -1
- package/dist/halal-core/tamper/verifyLifecycleHooks.d.ts +3 -0
- package/dist/halal-core/tamper/verifyLifecycleHooks.js +13 -12
- package/dist/halal-core/tamper/verifyLifecycleHooks.js.map +1 -1
- package/dist/halal-core/tamper/verifyReportSignature.d.ts +6 -3
- package/dist/halal-core/tamper/verifyReportSignature.js +20 -14
- package/dist/halal-core/tamper/verifyReportSignature.js.map +1 -1
- package/dist/halal.d.ts +20 -1
- package/dist/halal.js +18 -2
- package/dist/i18n/index.d.ts +34 -31
- package/dist/i18n/index.js +219 -288
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/shared.d.ts +18 -15
- package/dist/i18n/shared.js +204 -266
- package/dist/i18n/shared.js.map +1 -1
- package/dist/icons/index.d.ts +143 -139
- package/dist/icons/index.js +322 -273
- package/dist/icons/index.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +7 -2
- package/dist/kit/index.d.ts +9 -6
- package/dist/kit/index.js +45 -43
- package/dist/kit/index.js.map +1 -1
- package/dist/nitro-server/index.d.ts +7 -4
- package/dist/nitro-server/index.js +6 -2
- package/dist/nitro-server/index.js.map +1 -1
- package/dist/node.d.ts +6 -3
- package/dist/node.js +88 -116
- package/dist/node.js.map +1 -1
- package/dist/reactivity/computed.d.ts +6 -3
- package/dist/reactivity/computed.js +46 -53
- package/dist/reactivity/computed.js.map +1 -1
- package/dist/reactivity/effect.d.ts +8 -5
- package/dist/reactivity/effect.js +105 -146
- package/dist/reactivity/effect.js.map +1 -1
- package/dist/reactivity/index.d.ts +8 -8
- package/dist/reactivity/index.js +7 -8
- package/dist/reactivity/reactive.d.ts +3 -0
- package/dist/reactivity/reactive.js +93 -133
- package/dist/reactivity/reactive.js.map +1 -1
- package/dist/reactivity/readonly.d.ts +2 -1
- package/dist/reactivity/readonly.js +2 -2
- package/dist/reactivity/ref.d.ts +15 -15
- package/dist/reactivity/ref.js +73 -81
- package/dist/reactivity/ref.js.map +1 -1
- package/dist/reactivity/scheduler.d.ts +3 -1
- package/dist/reactivity/scheduler.js +67 -69
- package/dist/reactivity/scheduler.js.map +1 -1
- package/dist/reactivity/types.d.ts +17 -14
- package/dist/reactivity/types.js +0 -1
- package/dist/reactivity/utils.d.ts +7 -4
- package/dist/reactivity/utils.js +25 -24
- package/dist/reactivity/utils.js.map +1 -1
- package/dist/reactivity/watch.d.ts +4 -2
- package/dist/reactivity/watch.js +75 -103
- package/dist/reactivity/watch.js.map +1 -1
- package/dist/runtime/core.d.ts +31 -0
- package/dist/runtime/core.js +156 -0
- package/dist/runtime/core.js.map +1 -0
- package/dist/runtime/index.d.ts +487 -461
- package/dist/runtime/index.js +4129 -5254
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/reactivity.d.ts +7 -0
- package/dist/runtime/reactivity.js +6 -0
- package/dist/runtime/resume.d.ts +79 -0
- package/dist/runtime/resume.js +482 -0
- package/dist/runtime/resume.js.map +1 -0
- package/dist/runtime/router.d.ts +20 -0
- package/dist/runtime/router.js +60 -0
- package/dist/runtime/router.js.map +1 -0
- package/dist/runtime/streaming.d.ts +24 -0
- package/dist/runtime/streaming.js +200 -0
- package/dist/runtime/streaming.js.map +1 -0
- package/dist/security/media-fetch.d.ts +32 -0
- package/dist/security/media-fetch.js +301 -0
- package/dist/security/media-fetch.js.map +1 -0
- package/dist/security/path-boundary.d.ts +7 -0
- package/dist/security/path-boundary.js +70 -0
- package/dist/security/path-boundary.js.map +1 -0
- package/dist/ui/index.d.ts +1580 -1576
- package/dist/ui/index.js +975 -674
- package/dist/ui/index.js.map +1 -1
- package/dist/vite-builder/index.d.ts +6 -3
- package/dist/vite-builder/index.js +6 -2
- package/dist/vite-builder/index.js.map +1 -1
- package/package.json +46 -86
- package/dist/compiler/implementation.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/deploy/types.js.map +0 -1
- package/dist/globals.js.map +0 -1
- package/dist/halal-core/index.js.map +0 -1
- package/dist/halal-core/runtime/index.js.map +0 -1
- package/dist/halal-core/runtime/types.js.map +0 -1
- package/dist/halal-core/status.js.map +0 -1
- package/dist/halal.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/reactivity/index.js.map +0 -1
- package/dist/reactivity/readonly.js.map +0 -1
- package/dist/reactivity/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../../src/halal-core/runtime/guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,qBAAqB,GAEtB,MAAM,8BAA8B,CAAC;AAOtC,MAAM,WAAW,GAAqC;IACpD,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,eAAe,EAAE,CAAC;IAClB,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,SAAS,GAAkD;IAC/D,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxC,QAAQ,CAAuB;IAExC,YAAY,QAA8B;QACxC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,kDAAkD,CAAC,CAAC;QACjF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,UAAU,uBAAuB,CAAC,UAAoC,EAAE;IAC5E,OAAO;QACL,KAAK,CAAC,OAA4B;YAChC,OAAO,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;QAED,gBAA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CAAC,UAAU,CAAC,CAAC;QACpE,UAAU;QACV,OAAO,EAAE,aAAa,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3D,YAAY,EAAE,aAAa,CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;QAC1E,eAAe,EAAE,aAAa,CAAC,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;QACnF,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;KAC9C,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,MAAgB;IACrC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
|
1
|
+
{"version":3,"file":"guard.js","names":[],"sources":["../../../src/halal-core/runtime/guard.ts"],"sourcesContent":["import { classifyRuntimeContentWithAi } from \"../ai/classifyRuntimeContent.js\";\nimport { evaluateRules } from \"../rules/defaultBlockedRules.js\";\nimport { scanDomains } from \"../scanner/scanDomains.js\";\nimport type { HalalCheckResult, HalalGuardStatus } from \"../status.js\";\nimport {\n createRuntimeContentFingerprint,\n findReviewedRuntimeDecision,\n} from \"./reviewedMemory.js\";\nimport {\n prepareRuntimeContent,\n type RuntimeContentInspectionIssue,\n} from \"./serializeRuntimeContent.js\";\nimport type {\n HalalRuntimeContent,\n HalalRuntimeDecision,\n HalalRuntimeGuardOptions,\n} from \"./types.js\";\n\nconst STATUS_RANK: Record<HalalGuardStatus, number> = {\n allowed: 0,\n warning: 1,\n review_required: 2,\n blocked: 3,\n};\n\nconst RISK_RANK: Record<HalalCheckResult[\"riskLevel\"], number> = {\n low: 0,\n medium: 1,\n high: 2,\n critical: 3,\n};\n\nexport class HalalRuntimeBlockedError extends Error {\n readonly decision: HalalRuntimeDecision;\n\n constructor(decision: HalalRuntimeDecision) {\n super(decision.reasons[0] || \"Runtime content was rejected by the halal guard.\");\n this.name = \"HalalRuntimeBlockedError\";\n this.decision = decision;\n }\n}\n\nexport function createHalalRuntimeGuard(options: HalalRuntimeGuardOptions = {}) {\n return {\n check(content: HalalRuntimeContent): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent(content, options);\n },\n\n checkDynamicPage(content: Omit<HalalRuntimeContent, \"kind\">): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent({ ...content, kind: \"dynamic_page\" }, options);\n },\n\n checkAd(content: Omit<HalalRuntimeContent, \"kind\">): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent({ ...content, kind: \"advertisement\" }, options);\n },\n\n async assertAllowed(content: HalalRuntimeContent): Promise<HalalRuntimeDecision> {\n const decision = await evaluateHalalRuntimeContent(content, options);\n if (!decision.allowed) {\n throw new HalalRuntimeBlockedError(decision);\n }\n return decision;\n },\n\n async filterAds<T extends Omit<HalalRuntimeContent, \"kind\">>(ads: readonly T[]) {\n const checked = await Promise.all(ads.map(async (ad) => ({\n ad,\n decision: await evaluateHalalRuntimeContent({ ...ad, kind: \"advertisement\" }, options),\n })));\n return {\n allowed: checked.filter((entry) => entry.decision.allowed).map((entry) => entry.ad),\n rejected: checked.filter((entry) => !entry.decision.allowed),\n };\n },\n };\n}\n\nexport async function evaluateHalalRuntimeContent(\n content: HalalRuntimeContent,\n options: HalalRuntimeGuardOptions = {},\n): Promise<HalalRuntimeDecision> {\n const serialized = prepareRuntimeContent(content, options.maxContentCharacters);\n const fingerprint = createRuntimeContentFingerprint(content);\n const file = `runtime:${content.kind}:${content.id || content.route || \"anonymous\"}`;\n const scannedResult = evaluateRules({\n routes: content.route ? [content.route] : [],\n pages: content.kind === \"dynamic_page\" && content.route ? [content.route] : [],\n components: [],\n metadata: {\n title: content.title,\n description: content.advertiser\n ? `Advertiser: ${content.advertiser}`\n : `${content.kind} runtime content`,\n },\n envNames: [],\n dependencies: {},\n i18nWords: [],\n contentTexts: [{ file, text: serialized.localText }],\n endpoints: scanDomains([{ file, text: serialized.localText }]),\n }, options.policy ?? {});\n\n let localResult = scannedResult;\n if (serialized.truncated) {\n localResult = mergeResults(\n localResult,\n truncatedContentResult(file, serialized.maxCharacters),\n );\n }\n if (serialized.inspectionIssues.length > 0) {\n localResult = mergeResults(\n localResult,\n uninspectableContentResult(file, serialized.inspectionIssues),\n );\n }\n\n const reviewed = findReviewedRuntimeDecision(\n content,\n options.reviewedDecisions,\n options.reviewSecret,\n );\n if (reviewed) {\n const reviewedResult = decisionFromReviewedMemory(content, fingerprint, reviewed, options.strict === true);\n if (STATUS_RANK[reviewedResult.status] >= STATUS_RANK[localResult.status]\n || STATUS_RANK[localResult.status] <= STATUS_RANK.warning) {\n return reviewedResult;\n }\n }\n\n if (localResult.status === \"blocked\") {\n return finalizeDecision(content, fingerprint, localResult, \"local_rules\", options.strict === true);\n }\n\n const aiResult = await classifyRuntimeContentWithAi(\n content,\n serialized.aiText,\n localResult,\n options.ai,\n );\n const requiresAi = content.kind === \"advertisement\"\n ? options.ai?.requireForAds !== false\n : options.ai?.requireForDynamicContent === true;\n\n if (!aiResult && requiresAi) {\n const unverified = mergeResults(localResult, {\n status: \"review_required\",\n riskLevel: \"medium\",\n categories: [content.kind === \"advertisement\" ? \"unverified_ad\" : \"unverified_dynamic_content\"],\n confidence: 0,\n reasons: [\"Required runtime AI verification is not configured or unavailable.\"],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Do not render this content until AI verification or signed human review is available.\",\n });\n return finalizeDecision(content, fingerprint, unverified, \"local_rules\", options.strict === true);\n }\n\n const result = aiResult ? mergeResults(localResult, aiResult) : localResult;\n return finalizeDecision(\n content,\n fingerprint,\n result,\n aiResult ? \"local_and_ai\" : \"local_rules\",\n options.strict === true,\n );\n}\n\nfunction truncatedContentResult(file: string, maxCharacters: number): HalalCheckResult {\n return {\n status: \"review_required\",\n riskLevel: \"medium\",\n categories: [\"runtime_content_truncated\"],\n confidence: 1,\n reasons: [\n `Runtime content exceeded the ${maxCharacters}-character scan limit and was not fully inspected.`,\n ],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Increase maxContentCharacters or complete a manual review before rendering.\",\n };\n}\n\nfunction uninspectableContentResult(\n file: string,\n issues: readonly RuntimeContentInspectionIssue[],\n): HalalCheckResult {\n const issueDescriptions = issues.map((issue) => {\n if (issue === \"max_depth\") return \"maximum serialization depth was reached\";\n if (issue === \"unreadable_property\") return \"one or more properties could not be read\";\n return \"one or more objects could not be inspected\";\n });\n\n return {\n status: \"review_required\",\n riskLevel: \"high\",\n categories: [\"runtime_content_uninspectable\"],\n confidence: 1,\n reasons: [\n `Runtime content could not be fully inspected: ${uniqueStrings(issueDescriptions).join(\"; \")}.`,\n ],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Normalize runtime content to plain inspectable data or complete a manual review before rendering.\",\n };\n}\n\nfunction decisionFromReviewedMemory(\n content: HalalRuntimeContent,\n fingerprint: string,\n reviewed: NonNullable<HalalRuntimeGuardOptions[\"reviewedDecisions\"]>[number],\n strict: boolean,\n): HalalRuntimeDecision {\n const result: HalalCheckResult = {\n status: reviewed.status,\n riskLevel: reviewed.status === \"blocked\"\n ? \"high\"\n : reviewed.status === \"review_required\"\n ? \"medium\"\n : reviewed.status === \"warning\"\n ? \"medium\"\n : \"low\",\n categories: reviewed.categories,\n confidence: 1,\n reasons: [`Signed review by ${reviewed.reviewerId}: ${reviewed.reason}`],\n matchedFiles: [],\n matchedSnippets: [],\n recommendedAction: reviewed.status === \"allowed\"\n ? \"Render the exact reviewed content.\"\n : \"Follow the signed runtime review decision.\",\n };\n return finalizeDecision(content, fingerprint, result, \"reviewed_memory\", strict);\n}\n\nfunction finalizeDecision(\n content: HalalRuntimeContent,\n fingerprint: string,\n result: HalalCheckResult,\n source: HalalRuntimeDecision[\"source\"],\n strict: boolean,\n): HalalRuntimeDecision {\n return {\n ...result,\n contentKind: content.kind,\n fingerprint,\n source,\n allowed: result.status === \"allowed\" || (result.status === \"warning\" && !strict),\n };\n}\n\nfunction mergeResults(left: HalalCheckResult, right: HalalCheckResult): HalalCheckResult {\n const leftRank = STATUS_RANK[left.status];\n const rightRank = STATUS_RANK[right.status];\n const dominant = rightRank > leftRank ? right : left;\n const riskLevel = RISK_RANK[right.riskLevel] > RISK_RANK[left.riskLevel]\n ? right.riskLevel\n : left.riskLevel;\n const confidence = leftRank === rightRank\n ? Math.max(left.confidence, right.confidence)\n : dominant.confidence;\n\n return {\n status: dominant.status,\n riskLevel,\n categories: uniqueStrings([...left.categories, ...right.categories]),\n confidence,\n reasons: uniqueStrings([...left.reasons, ...right.reasons]),\n matchedFiles: uniqueStrings([...left.matchedFiles, ...right.matchedFiles]),\n matchedSnippets: uniqueStrings([...left.matchedSnippets, ...right.matchedSnippets]),\n recommendedAction: dominant.recommendedAction,\n };\n}\n\nfunction uniqueStrings(values: string[]): string[] {\n return [...new Set(values.filter(Boolean))];\n}\n"],"mappings":";;;;;;AAkBA,MAAM,cAAgD;CACpD,SAAS;CACT,SAAS;CACT,iBAAiB;CACjB,SAAS;AACX;AAEA,MAAM,YAA2D;CAC/D,KAAK;CACL,QAAQ;CACR,MAAM;CACN,UAAU;AACZ;AAEA,IAAa,2BAAb,cAA8C,MAAM;CAClD;CAEA,YAAY,UAAgC;EAC1C,MAAM,SAAS,QAAQ,MAAM,kDAAkD;EAC/E,KAAK,OAAO;EACZ,KAAK,WAAW;CAClB;AACF;AAEA,SAAgB,wBAAwB,UAAoC,CAAC,GAAG;CAC9E,OAAO;EACL,MAAM,SAA6D;GACjE,OAAO,4BAA4B,SAAS,OAAO;EACrD;EAEA,iBAAiB,SAA2E;GAC1F,OAAO,4BAA4B;IAAE,GAAG;IAAS,MAAM;GAAe,GAAG,OAAO;EAClF;EAEA,QAAQ,SAA2E;GACjF,OAAO,4BAA4B;IAAE,GAAG;IAAS,MAAM;GAAgB,GAAG,OAAO;EACnF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,YAAY,GAAG,MAAM,UAAU,CAAC;EACnE;EACA,SAAS,cAAc,CAAC,GAAG,KAAK,SAAS,GAAG,MAAM,OAAO,CAAC;EAC1D,cAAc,cAAc,CAAC,GAAG,KAAK,cAAc,GAAG,MAAM,YAAY,CAAC;EACzE,iBAAiB,cAAc,CAAC,GAAG,KAAK,iBAAiB,GAAG,MAAM,eAAe,CAAC;EAClF,mBAAmB,SAAS;CAC9B;AACF;AAEA,SAAS,cAAc,QAA4B;CACjD,OAAO,CAAC,GAAG,IAAI,IAAI,OAAO,OAAO,OAAO,CAAC,CAAC;AAC5C"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { HalalRuntimeAiOptions, HalalRuntimeContent, HalalRuntimeContentKind, HalalRuntimeDecision, HalalRuntimeDecisionSource, HalalRuntimeGuardOptions, HalalRuntimeReviewDecision, HalalRuntimeReviewInput, SignedHalalRuntimeDecision } from "./types.js";
|
|
2
|
+
import { PreparedRuntimeContent, RuntimeContentInspectionIssue, prepareRuntimeContent, serializeRuntimeContent, serializeRuntimeContentCanonical } from "./serializeRuntimeContent.js";
|
|
3
|
+
import { createRuntimeContentFingerprint, createSignedHalalRuntimeDecision, findReviewedRuntimeDecision, verifySignedHalalRuntimeDecision } from "./reviewedMemory.js";
|
|
4
|
+
import { HalalRuntimeBlockedError, createHalalRuntimeGuard, evaluateHalalRuntimeContent } from "./guard.js";
|
|
5
|
+
export { HalalRuntimeAiOptions, HalalRuntimeBlockedError, HalalRuntimeContent, HalalRuntimeContentKind, HalalRuntimeDecision, HalalRuntimeDecisionSource, HalalRuntimeGuardOptions, HalalRuntimeReviewDecision, HalalRuntimeReviewInput, PreparedRuntimeContent, RuntimeContentInspectionIssue, SignedHalalRuntimeDecision, createHalalRuntimeGuard, createRuntimeContentFingerprint, createSignedHalalRuntimeDecision, evaluateHalalRuntimeContent, findReviewedRuntimeDecision, prepareRuntimeContent, serializeRuntimeContent, serializeRuntimeContentCanonical, verifySignedHalalRuntimeDecision };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { prepareRuntimeContent, serializeRuntimeContent, serializeRuntimeContentCanonical } from "./serializeRuntimeContent.js";
|
|
2
|
+
import { createRuntimeContentFingerprint, createSignedHalalRuntimeDecision, findReviewedRuntimeDecision, verifySignedHalalRuntimeDecision } from "./reviewedMemory.js";
|
|
3
|
+
import { HalalRuntimeBlockedError, createHalalRuntimeGuard, evaluateHalalRuntimeContent } from "./guard.js";
|
|
4
|
+
export { HalalRuntimeBlockedError, createHalalRuntimeGuard, createRuntimeContentFingerprint, createSignedHalalRuntimeDecision, evaluateHalalRuntimeContent, findReviewedRuntimeDecision, prepareRuntimeContent, serializeRuntimeContent, serializeRuntimeContentCanonical, verifySignedHalalRuntimeDecision };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { HalalRuntimeContent, HalalRuntimeReviewInput, SignedHalalRuntimeDecision } from "./types.js";
|
|
2
|
+
//#region src/halal-core/runtime/reviewedMemory.d.ts
|
|
2
3
|
export declare function createRuntimeContentFingerprint(content: HalalRuntimeContent, _maxContentCharacters?: number): string;
|
|
3
4
|
export declare function createSignedHalalRuntimeDecision(content: HalalRuntimeContent, review: HalalRuntimeReviewInput, secret?: string): SignedHalalRuntimeDecision;
|
|
4
5
|
export declare function verifySignedHalalRuntimeDecision(decision: unknown, secret?: string): decision is SignedHalalRuntimeDecision;
|
|
5
6
|
export declare function findReviewedRuntimeDecision(content: HalalRuntimeContent, decisions: readonly SignedHalalRuntimeDecision[] | undefined, secret?: string, _maxContentCharacters?: number): SignedHalalRuntimeDecision | undefined;
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=reviewedMemory.d.ts.map
|
|
@@ -1,131 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createIntegritySignature, verifyIntegritySignature, } from "../crypto/integrity.js";
|
|
1
|
+
import { createIntegritySignature, verifyIntegritySignature } from "../crypto/integrity.js";
|
|
3
2
|
import { serializeRuntimeContentCanonical } from "./serializeRuntimeContent.js";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
//#region src/halal-core/runtime/reviewedMemory.ts
|
|
4
5
|
const REVIEW_SECRET_ENV = "RESUX_HALAL_REVIEW_SECRET";
|
|
5
|
-
const MAX_CLOCK_SKEW_MS =
|
|
6
|
+
const MAX_CLOCK_SKEW_MS = 3e5;
|
|
6
7
|
const STATUS_RANK = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
allowed: 0,
|
|
9
|
+
warning: 1,
|
|
10
|
+
review_required: 2,
|
|
11
|
+
blocked: 3
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
function createRuntimeContentFingerprint(content, _maxContentCharacters) {
|
|
14
|
+
const canonical = serializeRuntimeContentCanonical(content);
|
|
15
|
+
return createHash("sha256").update(canonical).digest("hex");
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}),
|
|
37
|
-
};
|
|
17
|
+
function createSignedHalalRuntimeDecision(content, review, secret) {
|
|
18
|
+
const createdAt = /* @__PURE__ */ new Date();
|
|
19
|
+
const unsigned = {
|
|
20
|
+
version: 1,
|
|
21
|
+
fingerprint: createRuntimeContentFingerprint(content),
|
|
22
|
+
status: review.status,
|
|
23
|
+
categories: normalizeCategories(review.categories),
|
|
24
|
+
reason: requireText(review.reason, "Review reason"),
|
|
25
|
+
reviewerId: requireText(review.reviewerId, "Reviewer ID"),
|
|
26
|
+
createdAt: createdAt.toISOString(),
|
|
27
|
+
...review.expiresAt ? { expiresAt: validateFutureDate(review.expiresAt, "Review expiry", createdAt.getTime()) } : {}
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
...unsigned,
|
|
31
|
+
signature: createIntegritySignature(unsigned, {
|
|
32
|
+
envName: REVIEW_SECRET_ENV,
|
|
33
|
+
secret,
|
|
34
|
+
requireSecret: true
|
|
35
|
+
})
|
|
36
|
+
};
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const createdAt = Date.parse(decision.createdAt);
|
|
56
|
-
if (!Number.isFinite(createdAt) || createdAt > Date.now() + MAX_CLOCK_SKEW_MS) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
if (decision.expiresAt !== undefined) {
|
|
60
|
-
if (typeof decision.expiresAt !== "string") {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
const expiresAt = Date.parse(decision.expiresAt);
|
|
64
|
-
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() || expiresAt <= createdAt) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const { signature, ...unsigned } = decision;
|
|
69
|
-
return verifyIntegritySignature(unsigned, signature, {
|
|
70
|
-
envName: REVIEW_SECRET_ENV,
|
|
71
|
-
secret,
|
|
72
|
-
requireSecret: true,
|
|
73
|
-
});
|
|
38
|
+
function verifySignedHalalRuntimeDecision(decision, secret) {
|
|
39
|
+
if (!isRecord(decision) || decision.version !== 1 || typeof decision.signature !== "string") return false;
|
|
40
|
+
if (!isValidStatus(decision.status) || typeof decision.fingerprint !== "string" || !/^[a-f0-9]{64}$/.test(decision.fingerprint) || typeof decision.reason !== "string" || !decision.reason.trim() || typeof decision.reviewerId !== "string" || !decision.reviewerId.trim() || typeof decision.createdAt !== "string" || !Array.isArray(decision.categories) || decision.categories.some((entry) => typeof entry !== "string")) return false;
|
|
41
|
+
const createdAt = Date.parse(decision.createdAt);
|
|
42
|
+
if (!Number.isFinite(createdAt) || createdAt > Date.now() + MAX_CLOCK_SKEW_MS) return false;
|
|
43
|
+
if (decision.expiresAt !== void 0) {
|
|
44
|
+
if (typeof decision.expiresAt !== "string") return false;
|
|
45
|
+
const expiresAt = Date.parse(decision.expiresAt);
|
|
46
|
+
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() || expiresAt <= createdAt) return false;
|
|
47
|
+
}
|
|
48
|
+
const { signature, ...unsigned } = decision;
|
|
49
|
+
return verifyIntegritySignature(unsigned, signature, {
|
|
50
|
+
envName: REVIEW_SECRET_ENV,
|
|
51
|
+
secret,
|
|
52
|
+
requireSecret: true
|
|
53
|
+
});
|
|
74
54
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (!selected || isNewerOrStricter(decision, selected)) {
|
|
87
|
-
selected = decision;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return selected;
|
|
55
|
+
function findReviewedRuntimeDecision(content, decisions, secret, _maxContentCharacters) {
|
|
56
|
+
if (!decisions?.length) return;
|
|
57
|
+
const fingerprint = createRuntimeContentFingerprint(content);
|
|
58
|
+
let selected;
|
|
59
|
+
for (const decision of decisions) {
|
|
60
|
+
if (decision.fingerprint !== fingerprint || !verifySignedHalalRuntimeDecision(decision, secret)) continue;
|
|
61
|
+
if (!selected || isNewerOrStricter(decision, selected)) selected = decision;
|
|
62
|
+
}
|
|
63
|
+
return selected;
|
|
91
64
|
}
|
|
92
65
|
function isNewerOrStricter(candidate, current) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
return STATUS_RANK[candidate.status] > STATUS_RANK[current.status];
|
|
66
|
+
const candidateCreatedAt = Date.parse(candidate.createdAt);
|
|
67
|
+
const currentCreatedAt = Date.parse(current.createdAt);
|
|
68
|
+
if (candidateCreatedAt !== currentCreatedAt) return candidateCreatedAt > currentCreatedAt;
|
|
69
|
+
return STATUS_RANK[candidate.status] > STATUS_RANK[current.status];
|
|
99
70
|
}
|
|
100
71
|
function normalizeCategories(categories) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return [...new Set(categories.map((entry) => entry.trim()).filter(Boolean))].slice(0, 50);
|
|
72
|
+
if (!categories) return [];
|
|
73
|
+
return [...new Set(categories.map((entry) => entry.trim()).filter(Boolean))].slice(0, 50);
|
|
104
74
|
}
|
|
105
75
|
function requireText(value, label) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
return normalized.slice(0, 2_000);
|
|
76
|
+
const normalized = String(value || "").trim();
|
|
77
|
+
if (!normalized) throw new Error(`${label} is required.`);
|
|
78
|
+
return normalized.slice(0, 2e3);
|
|
111
79
|
}
|
|
112
80
|
function validateFutureDate(value, label, createdAt) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (timestamp <= createdAt) {
|
|
118
|
-
throw new Error(`${label} must be later than the review creation time.`);
|
|
119
|
-
}
|
|
120
|
-
return new Date(timestamp).toISOString();
|
|
81
|
+
const timestamp = Date.parse(value);
|
|
82
|
+
if (!Number.isFinite(timestamp)) throw new Error(`${label} must be a valid date.`);
|
|
83
|
+
if (timestamp <= createdAt) throw new Error(`${label} must be later than the review creation time.`);
|
|
84
|
+
return new Date(timestamp).toISOString();
|
|
121
85
|
}
|
|
122
86
|
function isValidStatus(value) {
|
|
123
|
-
|
|
124
|
-
|| value === "warning"
|
|
125
|
-
|| value === "review_required"
|
|
126
|
-
|| value === "blocked";
|
|
87
|
+
return value === "allowed" || value === "warning" || value === "review_required" || value === "blocked";
|
|
127
88
|
}
|
|
128
89
|
function isRecord(value) {
|
|
129
|
-
|
|
90
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
130
91
|
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { createRuntimeContentFingerprint, createSignedHalalRuntimeDecision, findReviewedRuntimeDecision, verifySignedHalalRuntimeDecision };
|
|
94
|
+
|
|
131
95
|
//# sourceMappingURL=reviewedMemory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewedMemory.js","
|
|
1
|
+
{"version":3,"file":"reviewedMemory.js","names":[],"sources":["../../../src/halal-core/runtime/reviewedMemory.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport {\n createIntegritySignature,\n verifyIntegritySignature,\n} from \"../crypto/integrity.js\";\nimport { serializeRuntimeContentCanonical } from \"./serializeRuntimeContent.js\";\nimport type {\n HalalRuntimeContent,\n HalalRuntimeReviewInput,\n SignedHalalRuntimeDecision,\n} from \"./types.js\";\n\nconst REVIEW_SECRET_ENV = \"RESUX_HALAL_REVIEW_SECRET\";\nconst MAX_CLOCK_SKEW_MS = 5 * 60 * 1_000;\nconst STATUS_RANK: Record<SignedHalalRuntimeDecision[\"status\"], number> = {\n allowed: 0,\n warning: 1,\n review_required: 2,\n blocked: 3,\n};\n\nexport function createRuntimeContentFingerprint(\n content: HalalRuntimeContent,\n _maxContentCharacters?: number,\n): string {\n const canonical = serializeRuntimeContentCanonical(content);\n return createHash(\"sha256\").update(canonical).digest(\"hex\");\n}\n\nexport function createSignedHalalRuntimeDecision(\n content: HalalRuntimeContent,\n review: HalalRuntimeReviewInput,\n secret?: string,\n): SignedHalalRuntimeDecision {\n const createdAt = new Date();\n const unsigned = {\n version: 1 as const,\n fingerprint: createRuntimeContentFingerprint(content),\n status: review.status,\n categories: normalizeCategories(review.categories),\n reason: requireText(review.reason, \"Review reason\"),\n reviewerId: requireText(review.reviewerId, \"Reviewer ID\"),\n createdAt: createdAt.toISOString(),\n ...(review.expiresAt\n ? { expiresAt: validateFutureDate(review.expiresAt, \"Review expiry\", createdAt.getTime()) }\n : {}),\n };\n\n return {\n ...unsigned,\n signature: createIntegritySignature(unsigned, {\n envName: REVIEW_SECRET_ENV,\n secret,\n requireSecret: true,\n }),\n };\n}\n\nexport function verifySignedHalalRuntimeDecision(\n decision: unknown,\n secret?: string,\n): decision is SignedHalalRuntimeDecision {\n if (!isRecord(decision) || decision.version !== 1 || typeof decision.signature !== \"string\") {\n return false;\n }\n if (!isValidStatus(decision.status)\n || typeof decision.fingerprint !== \"string\"\n || !/^[a-f0-9]{64}$/.test(decision.fingerprint)\n || typeof decision.reason !== \"string\"\n || !decision.reason.trim()\n || typeof decision.reviewerId !== \"string\"\n || !decision.reviewerId.trim()\n || typeof decision.createdAt !== \"string\"\n || !Array.isArray(decision.categories)\n || decision.categories.some((entry) => typeof entry !== \"string\")) {\n return false;\n }\n\n const createdAt = Date.parse(decision.createdAt);\n if (!Number.isFinite(createdAt) || createdAt > Date.now() + MAX_CLOCK_SKEW_MS) {\n return false;\n }\n if (decision.expiresAt !== undefined) {\n if (typeof decision.expiresAt !== \"string\") {\n return false;\n }\n const expiresAt = Date.parse(decision.expiresAt);\n if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() || expiresAt <= createdAt) {\n return false;\n }\n }\n\n const { signature, ...unsigned } = decision;\n return verifyIntegritySignature(unsigned, signature, {\n envName: REVIEW_SECRET_ENV,\n secret,\n requireSecret: true,\n });\n}\n\nexport function findReviewedRuntimeDecision(\n content: HalalRuntimeContent,\n decisions: readonly SignedHalalRuntimeDecision[] | undefined,\n secret?: string,\n _maxContentCharacters?: number,\n): SignedHalalRuntimeDecision | undefined {\n if (!decisions?.length) {\n return undefined;\n }\n\n const fingerprint = createRuntimeContentFingerprint(content);\n let selected: SignedHalalRuntimeDecision | undefined;\n\n for (const decision of decisions) {\n if (decision.fingerprint !== fingerprint\n || !verifySignedHalalRuntimeDecision(decision, secret)) {\n continue;\n }\n if (!selected || isNewerOrStricter(decision, selected)) {\n selected = decision;\n }\n }\n\n return selected;\n}\n\nfunction isNewerOrStricter(\n candidate: SignedHalalRuntimeDecision,\n current: SignedHalalRuntimeDecision,\n): boolean {\n const candidateCreatedAt = Date.parse(candidate.createdAt);\n const currentCreatedAt = Date.parse(current.createdAt);\n if (candidateCreatedAt !== currentCreatedAt) {\n return candidateCreatedAt > currentCreatedAt;\n }\n return STATUS_RANK[candidate.status] > STATUS_RANK[current.status];\n}\n\nfunction normalizeCategories(categories: string[] | undefined): string[] {\n if (!categories) return [];\n return [...new Set(categories.map((entry) => entry.trim()).filter(Boolean))].slice(0, 50);\n}\n\nfunction requireText(value: string, label: string): string {\n const normalized = String(value || \"\").trim();\n if (!normalized) {\n throw new Error(`${label} is required.`);\n }\n return normalized.slice(0, 2_000);\n}\n\nfunction validateFutureDate(value: string, label: string, createdAt: number): string {\n const timestamp = Date.parse(value);\n if (!Number.isFinite(timestamp)) {\n throw new Error(`${label} must be a valid date.`);\n }\n if (timestamp <= createdAt) {\n throw new Error(`${label} must be later than the review creation time.`);\n }\n return new Date(timestamp).toISOString();\n}\n\nfunction isValidStatus(value: unknown): value is SignedHalalRuntimeDecision[\"status\"] {\n return value === \"allowed\"\n || value === \"warning\"\n || value === \"review_required\"\n || value === \"blocked\";\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value && typeof value === \"object\" && !Array.isArray(value));\n}\n"],"mappings":";;;;AAYA,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAC1B,MAAM,cAAoE;CACxE,SAAS;CACT,SAAS;CACT,iBAAiB;CACjB,SAAS;AACX;AAEA,SAAgB,gCACd,SACA,uBACQ;CACR,MAAM,YAAY,iCAAiC,OAAO;C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,SAAS,GAC5B,MAAM,IAAI,MAAM,GAAG,MAAM,uBAAuB;CAElD,IAAI,aAAa,WACf,MAAM,IAAI,MAAM,GAAG,MAAM,8CAA8C;CAEzE,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,YAAY;AACzC;AAEA,SAAS,cAAc,OAA+D;CACpF,OAAO,UAAU,aACZ,UAAU,aACV,UAAU,qBACV,UAAU;AACjB;AAEA,SAAS,SAAS,OAAkD;CAClE,OAAO,QAAQ,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,CAAC;AAC5E"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { HalalRuntimeContent } from "./types.js";
|
|
2
|
+
//#region src/halal-core/runtime/serializeRuntimeContent.d.ts
|
|
2
3
|
export type RuntimeContentInspectionIssue = "max_depth" | "unreadable_object" | "unreadable_property";
|
|
3
4
|
export interface PreparedRuntimeContent {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
canonical: string;
|
|
6
|
+
localText: string;
|
|
7
|
+
aiText: string;
|
|
8
|
+
truncated: boolean;
|
|
9
|
+
maxCharacters: number;
|
|
10
|
+
inspectionIssues: RuntimeContentInspectionIssue[];
|
|
10
11
|
}
|
|
11
12
|
export declare function serializeRuntimeContent(content: HalalRuntimeContent, maxCharacters?: number): string;
|
|
12
13
|
export declare function prepareRuntimeContent(content: HalalRuntimeContent, maxCharacters?: number): PreparedRuntimeContent;
|
|
13
14
|
export declare function serializeRuntimeContentCanonical(content: HalalRuntimeContent): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
//# sourceMappingURL=serializeRuntimeContent.d.ts.map
|