resuxjs 0.3.11 → 0.4.0-beta.3
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 +5 -0
- package/dist/bin.js.map +1 -1
- package/dist/build/index.d.ts +29 -0
- package/dist/build/index.js +51 -0
- package/dist/build/index.js.map +1 -0
- package/dist/cli.d.ts +19 -8
- package/dist/cli.js +2653 -3688
- package/dist/cli.js.map +1 -1
- package/dist/compiler/adapter.d.ts +19 -15
- package/dist/compiler/adapter.js +69 -93
- package/dist/compiler/adapter.js.map +1 -1
- package/dist/compiler/dev-warnings.d.ts +14 -10
- package/dist/compiler/dev-warnings.js +247 -319
- package/dist/compiler/dev-warnings.js.map +1 -1
- package/dist/compiler/directives.d.ts +7 -3
- package/dist/compiler/directives.js +125 -150
- package/dist/compiler/directives.js.map +1 -1
- package/dist/compiler/implementation.d.ts +117 -112
- package/dist/compiler/implementation.js +2954 -3426
- package/dist/compiler/index.d.ts +19 -15
- package/dist/compiler/index.js +69 -93
- package/dist/compiler/index.js.map +1 -1
- package/dist/core/config.d.ts +19 -10
- package/dist/core/config.js +42 -25
- package/dist/core/config.js.map +1 -1
- package/dist/core/hooks.d.ts +133 -131
- 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 +6 -5
- package/dist/core/module-container.d.ts +97 -93
- package/dist/core/module-container.js +180 -185
- package/dist/core/module-container.js.map +1 -1
- package/dist/core/resux.d.ts +20 -15
- package/dist/core/resux.js +18 -13
- package/dist/core/resux.js.map +1 -1
- package/dist/create-bin.d.ts +1 -2
- package/dist/create-bin.js +5 -0
- package/dist/create-bin.js.map +1 -1
- package/dist/create.d.ts +6 -2
- package/dist/create.js +496 -638
- package/dist/create.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts +7 -2
- package/dist/deploy/cloudflare.js +31 -34
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/deploy/common.d.ts +19 -15
- package/dist/deploy/common.js +119 -188
- package/dist/deploy/common.js.map +1 -1
- package/dist/deploy/framework-runtime.d.ts +5 -1
- package/dist/deploy/framework-runtime.js +44 -48
- package/dist/deploy/framework-runtime.js.map +1 -1
- package/dist/deploy/index.d.ts +8 -3
- package/dist/deploy/index.js +56 -80
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/netlify.d.ts +7 -2
- package/dist/deploy/netlify.js +41 -41
- package/dist/deploy/netlify.js.map +1 -1
- package/dist/deploy/node.d.ts +7 -2
- package/dist/deploy/node.js +24 -19
- package/dist/deploy/node.js.map +1 -1
- package/dist/deploy/production-report.d.ts +5 -1
- package/dist/deploy/production-report.js +15 -14
- package/dist/deploy/production-report.js.map +1 -1
- package/dist/deploy/runtime-dependencies.d.ts +8 -4
- package/dist/deploy/runtime-dependencies.js +158 -220
- package/dist/deploy/runtime-dependencies.js.map +1 -1
- package/dist/deploy/static.d.ts +7 -2
- package/dist/deploy/static.js +17 -14
- package/dist/deploy/static.js.map +1 -1
- package/dist/deploy/types.d.ts +33 -29
- package/dist/deploy/types.js +1 -2
- package/dist/deploy/vercel.d.ts +8 -3
- package/dist/deploy/vercel.js +138 -188
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/fonts/index.d.ts +19 -14
- package/dist/fonts/index.js +115 -134
- package/dist/fonts/index.js.map +1 -1
- package/dist/globals.d.ts +79 -78
- package/dist/globals.js +1 -2
- package/dist/halal-core/ai/classifyProject.d.ts +9 -4
- package/dist/halal-core/ai/classifyProject.js +82 -95
- package/dist/halal-core/ai/classifyProject.js.map +1 -1
- package/dist/halal-core/ai/classifyRuntimeContent.d.ts +8 -3
- package/dist/halal-core/ai/classifyRuntimeContent.js +78 -95
- package/dist/halal-core/ai/classifyRuntimeContent.js.map +1 -1
- package/dist/halal-core/ai/createProjectSummary.d.ts +40 -36
- package/dist/halal-core/ai/createProjectSummary.js +39 -39
- package/dist/halal-core/ai/createProjectSummary.js.map +1 -1
- package/dist/halal-core/ai/halalClassifierPrompt.d.ts +5 -1
- 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 +5 -1
- 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 +7 -2
- package/dist/halal-core/ai/validateAiResponse.js +56 -83
- package/dist/halal-core/ai/validateAiResponse.js.map +1 -1
- package/dist/halal-core/cli/check.d.ts +5 -1
- 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 +5 -1
- 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 +5 -1
- 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 +5 -1
- 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 +5 -1
- package/dist/halal-core/cli/verifyReview.js +17 -15
- package/dist/halal-core/cli/verifyReview.js.map +1 -1
- package/dist/halal-core/config.d.ts +39 -35
- package/dist/halal-core/config.js +77 -118
- package/dist/halal-core/config.js.map +1 -1
- package/dist/halal-core/crypto/integrity.d.ts +12 -8
- package/dist/halal-core/crypto/integrity.js +65 -87
- package/dist/halal-core/crypto/integrity.js.map +1 -1
- package/dist/halal-core/enforce.d.ts +9 -5
- package/dist/halal-core/enforce.js +90 -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 +19 -19
- package/dist/halal-core/lifecycle.d.ts +5 -1
- package/dist/halal-core/lifecycle.js +16 -13
- package/dist/halal-core/lifecycle.js.map +1 -1
- package/dist/halal-core/policy.d.ts +7 -2
- package/dist/halal-core/policy.js +7 -2
- package/dist/halal-core/policy.js.map +1 -1
- package/dist/halal-core/report/formatBrowserOverlay.d.ts +7 -2
- 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 +7 -2
- 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 +11 -6
- package/dist/halal-core/report/generateHalalReport.js +25 -27
- package/dist/halal-core/report/generateHalalReport.js.map +1 -1
- package/dist/halal-core/report/signReport.d.ts +8 -3
- package/dist/halal-core/report/signReport.js +17 -12
- package/dist/halal-core/report/signReport.js.map +1 -1
- package/dist/halal-core/report/verifyReport.d.ts +14 -9
- package/dist/halal-core/report/verifyReport.js +52 -41
- package/dist/halal-core/report/verifyReport.js.map +1 -1
- package/dist/halal-core/review/createReviewRequest.d.ts +7 -2
- 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 +7 -3
- 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 +17 -12
- package/dist/halal-core/review/signedReviewFile.js +25 -22
- package/dist/halal-core/review/signedReviewFile.js.map +1 -1
- package/dist/halal-core/review/verifyReviewApproval.d.ts +12 -8
- package/dist/halal-core/review/verifyReviewApproval.js +69 -62
- package/dist/halal-core/review/verifyReviewApproval.js.map +1 -1
- package/dist/halal-core/rules/adultContentRules.d.ts +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +10 -6
- 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 +6 -2
- 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 +24 -19
- package/dist/halal-core/rules/defaultBlockedRules.js +156 -199
- package/dist/halal-core/rules/defaultBlockedRules.js.map +1 -1
- package/dist/halal-core/rules/dependencyRules.d.ts +11 -7
- 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 +9 -5
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +13 -9
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +22 -17
- package/dist/halal-core/runtime/guard.js +163 -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 +5 -5
- package/dist/halal-core/runtime/reviewedMemory.d.ts +10 -5
- package/dist/halal-core/runtime/reviewedMemory.js +75 -110
- package/dist/halal-core/runtime/reviewedMemory.js.map +1 -1
- package/dist/halal-core/runtime/serializeRuntimeContent.d.ts +17 -12
- package/dist/halal-core/runtime/serializeRuntimeContent.js +133 -156
- package/dist/halal-core/runtime/serializeRuntimeContent.js.map +1 -1
- package/dist/halal-core/runtime/types.d.ts +55 -50
- package/dist/halal-core/runtime/types.js +1 -2
- package/dist/halal-core/scanner/scanApiRoutes.d.ts +5 -1
- package/dist/halal-core/scanner/scanApiRoutes.js +33 -36
- package/dist/halal-core/scanner/scanApiRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanComponents.d.ts +5 -1
- package/dist/halal-core/scanner/scanComponents.js +13 -13
- package/dist/halal-core/scanner/scanComponents.js.map +1 -1
- package/dist/halal-core/scanner/scanContent.d.ts +8 -4
- package/dist/halal-core/scanner/scanContent.js +192 -261
- package/dist/halal-core/scanner/scanContent.js.map +1 -1
- package/dist/halal-core/scanner/scanDependencies.d.ts +5 -1
- package/dist/halal-core/scanner/scanDependencies.js +17 -15
- package/dist/halal-core/scanner/scanDependencies.js.map +1 -1
- package/dist/halal-core/scanner/scanDomains.d.ts +7 -3
- 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 +5 -1
- package/dist/halal-core/scanner/scanEnvNames.js +24 -26
- package/dist/halal-core/scanner/scanEnvNames.js.map +1 -1
- package/dist/halal-core/scanner/scanMetadata.d.ts +9 -5
- package/dist/halal-core/scanner/scanMetadata.js +21 -29
- package/dist/halal-core/scanner/scanMetadata.js.map +1 -1
- package/dist/halal-core/scanner/scanPages.d.ts +5 -1
- package/dist/halal-core/scanner/scanPages.js +13 -15
- package/dist/halal-core/scanner/scanPages.js.map +1 -1
- package/dist/halal-core/scanner/scanProject.d.ts +19 -12
- package/dist/halal-core/scanner/scanProject.js +44 -49
- package/dist/halal-core/scanner/scanProject.js.map +1 -1
- package/dist/halal-core/scanner/scanRoutes.d.ts +5 -1
- package/dist/halal-core/scanner/scanRoutes.js +33 -39
- package/dist/halal-core/scanner/scanRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanTranslations.d.ts +5 -1
- package/dist/halal-core/scanner/scanTranslations.js +22 -29
- package/dist/halal-core/scanner/scanTranslations.js.map +1 -1
- package/dist/halal-core/status.d.ts +17 -13
- package/dist/halal-core/status.js +1 -2
- package/dist/halal-core/tamper/verifyCoreIntegrity.d.ts +5 -1
- package/dist/halal-core/tamper/verifyCoreIntegrity.js +27 -24
- package/dist/halal-core/tamper/verifyCoreIntegrity.js.map +1 -1
- package/dist/halal-core/tamper/verifyLifecycleHooks.d.ts +5 -1
- 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 +9 -4
- 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 +19 -2
- package/dist/i18n/index.d.ts +44 -40
- package/dist/i18n/index.js +218 -288
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/shared.d.ts +33 -29
- package/dist/i18n/shared.js +204 -266
- package/dist/i18n/shared.js.map +1 -1
- package/dist/icons/index.d.ts +160 -154
- package/dist/icons/index.js +323 -273
- package/dist/icons/index.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +8 -2
- package/dist/kit/index.d.ts +32 -27
- package/dist/kit/index.js +46 -43
- package/dist/kit/index.js.map +1 -1
- package/dist/nitro-server/index.d.ts +10 -6
- package/dist/nitro-server/index.js +6 -2
- package/dist/nitro-server/index.js.map +1 -1
- package/dist/node.d.ts +9 -4
- package/dist/node.js +89 -116
- package/dist/node.js.map +1 -1
- package/dist/reactivity/computed.d.ts +11 -6
- package/dist/reactivity/computed.js +46 -53
- package/dist/reactivity/computed.js.map +1 -1
- package/dist/reactivity/effect.d.ts +23 -18
- package/dist/reactivity/effect.js +105 -147
- package/dist/reactivity/effect.js.map +1 -1
- package/dist/reactivity/index.d.ts +8 -8
- package/dist/reactivity/index.js +8 -8
- package/dist/reactivity/reactive.d.ts +9 -5
- package/dist/reactivity/reactive.js +95 -134
- package/dist/reactivity/reactive.js.map +1 -1
- package/dist/reactivity/readonly.d.ts +2 -1
- package/dist/reactivity/readonly.js +3 -2
- package/dist/reactivity/ref.d.ts +23 -21
- package/dist/reactivity/ref.js +71 -81
- package/dist/reactivity/ref.js.map +1 -1
- package/dist/reactivity/scheduler.d.ts +8 -5
- package/dist/reactivity/scheduler.js +67 -69
- package/dist/reactivity/scheduler.js.map +1 -1
- package/dist/reactivity/types.d.ts +29 -25
- package/dist/reactivity/types.js +1 -2
- package/dist/reactivity/utils.d.ts +17 -13
- package/dist/reactivity/utils.js +25 -24
- package/dist/reactivity/utils.js.map +1 -1
- package/dist/reactivity/watch.d.ts +8 -4
- package/dist/reactivity/watch.js +74 -103
- package/dist/reactivity/watch.js.map +1 -1
- package/dist/runtime/core.d.ts +32 -0
- package/dist/runtime/core.js +155 -0
- package/dist/runtime/core.js.map +1 -0
- package/dist/runtime/index.d.ts +649 -622
- package/dist/runtime/index.js +4105 -5243
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/reactivity.d.ts +7 -0
- package/dist/runtime/reactivity.js +7 -0
- package/dist/runtime/resume.d.ts +80 -0
- package/dist/runtime/resume.js +482 -0
- package/dist/runtime/resume.js.map +1 -0
- package/dist/runtime/router.d.ts +21 -0
- package/dist/runtime/router.js +60 -0
- package/dist/runtime/router.js.map +1 -0
- package/dist/runtime/streaming.d.ts +25 -0
- package/dist/runtime/streaming.js +200 -0
- package/dist/runtime/streaming.js.map +1 -0
- package/dist/security/media-fetch.d.ts +33 -0
- package/dist/security/media-fetch.js +302 -0
- package/dist/security/media-fetch.js.map +1 -0
- package/dist/security/path-boundary.d.ts +8 -0
- package/dist/security/path-boundary.js +71 -0
- package/dist/security/path-boundary.js.map +1 -0
- package/dist/ui/index.d.ts +1774 -1768
- package/dist/ui/index.js +974 -674
- package/dist/ui/index.js.map +1 -1
- package/dist/vite-builder/index.d.ts +9 -5
- 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
|
@@ -2,127 +2,86 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import ts from "typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/halal-core/config.ts
|
|
5
7
|
const FORBIDDEN_FIELDS = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
"enabled",
|
|
9
|
+
"mode",
|
|
10
|
+
"ignoreCoreRules",
|
|
11
|
+
"allowBlockedCategories",
|
|
12
|
+
"disableHarmDetection",
|
|
13
|
+
"removeDefaultRules",
|
|
14
|
+
"halalGuard"
|
|
13
15
|
];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (config.halalAI.enabled === false) {
|
|
25
|
-
throw new Error(`[resux-halal-core] Invalid configuration: "halalAI.enabled" cannot be set to false. You are not permitted to disable, bypass, or weaken the core safety and halal guidelines of ResuxJS.`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// Basic validation of types
|
|
29
|
-
if (config.projectName && typeof config.projectName !== "string") {
|
|
30
|
-
throw new Error("[resux-halal-core] 'projectName' must be a string.");
|
|
31
|
-
}
|
|
32
|
-
if (config.projectType && typeof config.projectType !== "string") {
|
|
33
|
-
throw new Error("[resux-halal-core] 'projectType' must be a string.");
|
|
34
|
-
}
|
|
35
|
-
if (config.description && typeof config.description !== "string") {
|
|
36
|
-
throw new Error("[resux-halal-core] 'description' must be a string.");
|
|
37
|
-
}
|
|
38
|
-
return config;
|
|
16
|
+
function validatePolicyConfig(config) {
|
|
17
|
+
if (!config) return {};
|
|
18
|
+
for (const field of FORBIDDEN_FIELDS) if (field in config) throw new Error(`[resux-halal-core] Invalid configuration field "${field}". You are not permitted to disable, bypass, or weaken the core safety and halal guidelines of ResuxJS.`);
|
|
19
|
+
if (config.halalAI) {
|
|
20
|
+
if (config.halalAI.enabled === false) throw new Error(`[resux-halal-core] Invalid configuration: "halalAI.enabled" cannot be set to false. You are not permitted to disable, bypass, or weaken the core safety and halal guidelines of ResuxJS.`);
|
|
21
|
+
}
|
|
22
|
+
if (config.projectName && typeof config.projectName !== "string") throw new Error("[resux-halal-core] 'projectName' must be a string.");
|
|
23
|
+
if (config.projectType && typeof config.projectType !== "string") throw new Error("[resux-halal-core] 'projectType' must be a string.");
|
|
24
|
+
if (config.description && typeof config.description !== "string") throw new Error("[resux-halal-core] 'description' must be a string.");
|
|
25
|
+
return config;
|
|
39
26
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const module = await import(fileUrl);
|
|
73
|
-
const config = module.default || module;
|
|
74
|
-
return config;
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
try {
|
|
78
|
-
fs.unlinkSync(tempPath);
|
|
79
|
-
}
|
|
80
|
-
catch { }
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
console.warn(`[resux-halal-core] Warning: failed to load resux.config.ts for Halal AI check: ${err.message}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return {};
|
|
27
|
+
async function loadMainResuxConfig(appRoot) {
|
|
28
|
+
const possiblePaths = [
|
|
29
|
+
path.join(appRoot, "resux.config.ts"),
|
|
30
|
+
path.join(appRoot, "resux.config.js"),
|
|
31
|
+
path.join(appRoot, "resux.config.mjs")
|
|
32
|
+
];
|
|
33
|
+
for (const configPath of possiblePaths) if (existsSync(configPath)) try {
|
|
34
|
+
let compiledSource;
|
|
35
|
+
if (configPath.endsWith(".ts")) {
|
|
36
|
+
const normalized = readFileSync(configPath, "utf8").replace(/\bdefineResuxConfig\s*\(/g, "(");
|
|
37
|
+
compiledSource = ts.transpileModule(normalized, { compilerOptions: {
|
|
38
|
+
target: ts.ScriptTarget.ES2022,
|
|
39
|
+
module: ts.ModuleKind.ES2022
|
|
40
|
+
} }).outputText;
|
|
41
|
+
} else compiledSource = readFileSync(configPath, "utf8");
|
|
42
|
+
const tempDir = path.join(appRoot, ".resux", "server");
|
|
43
|
+
const fs = await import("node:fs");
|
|
44
|
+
if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir, { recursive: true });
|
|
45
|
+
const tempPath = path.join(tempDir, `halal-temp-config-${Date.now()}.mjs`);
|
|
46
|
+
fs.writeFileSync(tempPath, compiledSource, "utf8");
|
|
47
|
+
try {
|
|
48
|
+
const module = await import(pathToFileURL(tempPath).href);
|
|
49
|
+
return module.default || module;
|
|
50
|
+
} finally {
|
|
51
|
+
try {
|
|
52
|
+
fs.unlinkSync(tempPath);
|
|
53
|
+
} catch {}
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.warn(`[resux-halal-core] Warning: failed to load resux.config.ts for Halal AI check: ${err.message}`);
|
|
57
|
+
}
|
|
58
|
+
return {};
|
|
89
59
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
const fileUrl = pathToFileURL(configPath).href;
|
|
115
|
-
const module = await import(fileUrl);
|
|
116
|
-
const config = module.default || module;
|
|
117
|
-
const validated = validatePolicyConfig(config);
|
|
118
|
-
Object.assign(policy, validated);
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
throw new Error(`[resux-halal-core] Failed to load halal configuration at ${configPath}: ${err.message}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return validatePolicyConfig(policy);
|
|
60
|
+
async function loadProjectPolicy(appRoot) {
|
|
61
|
+
const policy = {};
|
|
62
|
+
try {
|
|
63
|
+
const mainConfig = await loadMainResuxConfig(appRoot);
|
|
64
|
+
if (mainConfig.halalAI) policy.halalAI = mainConfig.halalAI;
|
|
65
|
+
if (mainConfig.projectType) policy.projectType = mainConfig.projectType;
|
|
66
|
+
} catch (err) {
|
|
67
|
+
if (err.message.includes("not permitted to disable")) throw err;
|
|
68
|
+
}
|
|
69
|
+
const possiblePaths = [
|
|
70
|
+
path.join(appRoot, "resux.halal.config.ts"),
|
|
71
|
+
path.join(appRoot, "resux.halal.config.js"),
|
|
72
|
+
path.join(appRoot, "resux.halal.config.mjs")
|
|
73
|
+
];
|
|
74
|
+
for (const configPath of possiblePaths) if (existsSync(configPath)) try {
|
|
75
|
+
const module = await import(pathToFileURL(configPath).href);
|
|
76
|
+
const validated = validatePolicyConfig(module.default || module);
|
|
77
|
+
Object.assign(policy, validated);
|
|
78
|
+
break;
|
|
79
|
+
} catch (err) {
|
|
80
|
+
throw new Error(`[resux-halal-core] Failed to load halal configuration at ${configPath}: ${err.message}`);
|
|
81
|
+
}
|
|
82
|
+
return validatePolicyConfig(policy);
|
|
127
83
|
}
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
export { loadMainResuxConfig, loadProjectPolicy, validatePolicyConfig };
|
|
128
87
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../../src/halal-core/config.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport ts from \"typescript\";\n\nexport interface ReviewContact {\n name: string;\n email: string;\n}\n\nexport interface ReviewEvidence {\n type: string;\n path: string;\n description: string;\n}\n\nexport interface StricterRules {\n blockAiChatWithoutModeration?: boolean;\n blockUnmoderatedUserUploads?: boolean;\n [key: string]: boolean | undefined;\n}\n\nexport interface HalalAIConfig {\n enabled?: boolean;\n strict?: boolean;\n blockProductionBuild?: boolean;\n scanRoutes?: boolean;\n scanMeta?: boolean;\n scanContent?: boolean;\n scanExternalLinks?: boolean;\n scanRuntimeConfig?: boolean;\n scanDependencies?: boolean;\n categories?: Record<string, \"block\" | \"warn\" | \"review\" | \"allow\">;\n}\n\nexport interface ResuxHalalPolicy {\n projectName?: string;\n projectType?: string;\n description?: string;\n reviewContact?: ReviewContact;\n stricterRules?: StricterRules;\n additionalBlockedCategories?: string[];\n evidence?: ReviewEvidence[];\n internalTeamNotes?: string;\n halalAI?: HalalAIConfig;\n}\n\nconst FORBIDDEN_FIELDS = [\n \"enabled\",\n \"mode\",\n \"ignoreCoreRules\",\n \"allowBlockedCategories\",\n \"disableHarmDetection\",\n \"removeDefaultRules\",\n \"halalGuard\",\n];\n\nexport function validatePolicyConfig(config: Record<string, any>): ResuxHalalPolicy {\n if (!config) {\n return {};\n }\n\n for (const field of FORBIDDEN_FIELDS) {\n if (field in config) {\n throw new Error(\n `[resux-halal-core] Invalid configuration field \"${field}\". You are not permitted to disable, bypass, or weaken the core safety and halal guidelines of ResuxJS.`\n );\n }\n }\n\n if (config.halalAI) {\n if (config.halalAI.enabled === false) {\n throw new Error(\n `[resux-halal-core] Invalid configuration: \"halalAI.enabled\" cannot be set to false. You are not permitted to disable, bypass, or weaken the core safety and halal guidelines of ResuxJS.`\n );\n }\n }\n\n // Basic validation of types\n if (config.projectName && typeof config.projectName !== \"string\") {\n throw new Error(\"[resux-halal-core] 'projectName' must be a string.\");\n }\n if (config.projectType && typeof config.projectType !== \"string\") {\n throw new Error(\"[resux-halal-core] 'projectType' must be a string.\");\n }\n if (config.description && typeof config.description !== \"string\") {\n throw new Error(\"[resux-halal-core] 'description' must be a string.\");\n }\n\n return config as ResuxHalalPolicy;\n}\n\nexport async function loadMainResuxConfig(appRoot: string): Promise<Record<string, any>> {\n const possiblePaths = [\n path.join(appRoot, \"resux.config.ts\"),\n path.join(appRoot, \"resux.config.js\"),\n path.join(appRoot, \"resux.config.mjs\"),\n ];\n\n for (const configPath of possiblePaths) {\n if (existsSync(configPath)) {\n try {\n let compiledSource: string;\n if (configPath.endsWith(\".ts\")) {\n const source = readFileSync(configPath, \"utf8\");\n const normalized = source.replace(/\\bdefineResuxConfig\\s*\\(/g, \"(\");\n compiledSource = ts.transpileModule(normalized, {\n compilerOptions: {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.ES2022\n }\n }).outputText;\n } else {\n compiledSource = readFileSync(configPath, \"utf8\");\n }\n\n const tempDir = path.join(appRoot, \".resux\", \"server\");\n const fs = await import(\"node:fs\");\n if (!fs.existsSync(tempDir)) {\n fs.mkdirSync(tempDir, { recursive: true });\n }\n const tempPath = path.join(tempDir, `halal-temp-config-${Date.now()}.mjs`);\n fs.writeFileSync(tempPath, compiledSource, \"utf8\");\n\n try {\n const fileUrl = pathToFileURL(tempPath).href;\n const module = await import(fileUrl);\n const config = module.default || module;\n return config;\n } finally {\n try {\n fs.unlinkSync(tempPath);\n } catch {}\n }\n } catch (err: any) {\n console.warn(`[resux-halal-core] Warning: failed to load resux.config.ts for Halal AI check: ${err.message}`);\n }\n }\n }\n return {};\n}\n\nexport async function loadProjectPolicy(appRoot: string): Promise<ResuxHalalPolicy> {\n const policy: ResuxHalalPolicy = {};\n\n try {\n const mainConfig = await loadMainResuxConfig(appRoot);\n if (mainConfig.halalAI) {\n policy.halalAI = mainConfig.halalAI;\n }\n if (mainConfig.projectType) {\n policy.projectType = mainConfig.projectType;\n }\n } catch (err: any) {\n if (err.message.includes(\"not permitted to disable\")) {\n throw err;\n }\n }\n\n const possiblePaths = [\n path.join(appRoot, \"resux.halal.config.ts\"),\n path.join(appRoot, \"resux.halal.config.js\"),\n path.join(appRoot, \"resux.halal.config.mjs\"),\n ];\n\n for (const configPath of possiblePaths) {\n if (existsSync(configPath)) {\n try {\n const fileUrl = pathToFileURL(configPath).href;\n const module = await import(fileUrl);\n const config = module.default || module;\n const validated = validatePolicyConfig(config);\n Object.assign(policy, validated);\n break;\n } catch (err: any) {\n throw new Error(`[resux-halal-core] Failed to load halal configuration at ${configPath}: ${err.message}`);\n }\n }\n }\n\n return validatePolicyConfig(policy);\n}\n"],"mappings":";;;;;;AA+CA,MAAM,mBAAmB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,QAA+C;AAClF,KAAI,CAAC,OACH,QAAO,EAAE;AAGX,MAAK,MAAM,SAAS,iBAClB,KAAI,SAAS,OACX,OAAM,IAAI,MACR,mDAAmD,MAAM,yGAC1D;AAIL,KAAI,OAAO,SACT;MAAI,OAAO,QAAQ,YAAY,MAC7B,OAAM,IAAI,MACR,2LACD;;AAKL,KAAI,OAAO,eAAe,OAAO,OAAO,gBAAgB,SACtD,OAAM,IAAI,MAAM,qDAAqD;AAEvE,KAAI,OAAO,eAAe,OAAO,OAAO,gBAAgB,SACtD,OAAM,IAAI,MAAM,qDAAqD;AAEvE,KAAI,OAAO,eAAe,OAAO,OAAO,gBAAgB,SACtD,OAAM,IAAI,MAAM,qDAAqD;AAGvE,QAAO;;AAGT,eAAsB,oBAAoB,SAA+C;CACvF,MAAM,gBAAgB;EACpB,KAAK,KAAK,SAAS,kBAAkB;EACrC,KAAK,KAAK,SAAS,kBAAkB;EACrC,KAAK,KAAK,SAAS,mBAAmB;EACvC;AAED,MAAK,MAAM,cAAc,cACvB,KAAI,WAAW,WAAW,CACxB,KAAI;EACF,IAAI;AACJ,MAAI,WAAW,SAAS,MAAM,EAAE;GAE9B,MAAM,aADS,aAAa,YAAY,OAAO,CACrB,QAAQ,6BAA6B,IAAI;AACnE,oBAAiB,GAAG,gBAAgB,YAAY,EAC9C,iBAAiB;IACf,QAAQ,GAAG,aAAa;IACxB,QAAQ,GAAG,WAAW;IACvB,EACF,CAAC,CAAC;QAEH,kBAAiB,aAAa,YAAY,OAAO;EAGnD,MAAM,UAAU,KAAK,KAAK,SAAS,UAAU,SAAS;EACtD,MAAM,KAAK,MAAM,OAAO;AACxB,MAAI,CAAC,GAAG,WAAW,QAAQ,CACzB,IAAG,UAAU,SAAS,EAAE,WAAW,MAAM,CAAC;EAE5C,MAAM,WAAW,KAAK,KAAK,SAAS,qBAAqB,KAAK,KAAK,CAAC,MAAM;AAC1E,KAAG,cAAc,UAAU,gBAAgB,OAAO;AAElD,MAAI;GAEF,MAAM,SAAS,MAAM,OADL,cAAc,SAAS,CAAC;AAGxC,UADe,OAAO,WAAW;YAEzB;AACR,OAAI;AACF,OAAG,WAAW,SAAS;WACjB;;UAEH,KAAU;AACjB,UAAQ,KAAK,kFAAkF,IAAI,UAAU;;AAInH,QAAO,EAAE;;AAGX,eAAsB,kBAAkB,SAA4C;CAClF,MAAM,SAA2B,EAAE;AAEnC,KAAI;EACF,MAAM,aAAa,MAAM,oBAAoB,QAAQ;AACrD,MAAI,WAAW,QACb,QAAO,UAAU,WAAW;AAE9B,MAAI,WAAW,YACb,QAAO,cAAc,WAAW;UAE3B,KAAU;AACjB,MAAI,IAAI,QAAQ,SAAS,2BAA2B,CAClD,OAAM;;CAIV,MAAM,gBAAgB;EACpB,KAAK,KAAK,SAAS,wBAAwB;EAC3C,KAAK,KAAK,SAAS,wBAAwB;EAC3C,KAAK,KAAK,SAAS,yBAAyB;EAC7C;AAED,MAAK,MAAM,cAAc,cACvB,KAAI,WAAW,WAAW,CACxB,KAAI;EAEF,MAAM,SAAS,MAAM,OADL,cAAc,WAAW,CAAC;EAG1C,MAAM,YAAY,qBADH,OAAO,WAAW,OACa;AAC9C,SAAO,OAAO,QAAQ,UAAU;AAChC;UACO,KAAU;AACjB,QAAM,IAAI,MAAM,4DAA4D,WAAW,IAAI,IAAI,UAAU;;AAK/G,QAAO,qBAAqB,OAAO"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//#region src/halal-core/crypto/integrity.d.ts
|
|
2
|
+
interface IntegrityOptions {
|
|
3
|
+
envName: string;
|
|
4
|
+
secret?: string;
|
|
5
|
+
requireSecret?: boolean;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
declare function createIntegritySignature(value: unknown, options: IntegrityOptions): string;
|
|
8
|
+
declare function verifyIntegritySignature(value: unknown, signature: unknown, options: IntegrityOptions): boolean;
|
|
9
|
+
declare function isAuthenticatedIntegritySignature(signature: unknown): boolean;
|
|
10
|
+
declare function stableSerialize(value: unknown): string;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { IntegrityOptions, createIntegritySignature, isAuthenticatedIntegritySignature, stableSerialize, verifyIntegritySignature };
|
|
13
|
+
//# sourceMappingURL=integrity.d.ts.map
|
|
@@ -1,101 +1,79 @@
|
|
|
1
1
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const digest = createHash("sha256").update(payload).digest("hex");
|
|
10
|
-
return `sha256:${digest}`;
|
|
2
|
+
|
|
3
|
+
//#region src/halal-core/crypto/integrity.ts
|
|
4
|
+
function createIntegritySignature(value, options) {
|
|
5
|
+
const payload = stableSerialize(value);
|
|
6
|
+
const secret = resolveIntegritySecret(options);
|
|
7
|
+
if (secret) return `hmac-sha256:${createHmac("sha256", secret).update(payload).digest("hex")}`;
|
|
8
|
+
return `sha256:${createHash("sha256").update(payload).digest("hex")}`;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
return constantTimeEqual(expected, signature);
|
|
10
|
+
function verifyIntegritySignature(value, signature, options) {
|
|
11
|
+
if (typeof signature !== "string") return false;
|
|
12
|
+
const separator = signature.indexOf(":");
|
|
13
|
+
if (separator <= 0) return false;
|
|
14
|
+
const algorithm = signature.slice(0, separator);
|
|
15
|
+
if (algorithm !== "hmac-sha256" && algorithm !== "sha256") return false;
|
|
16
|
+
if (options.requireSecret === true && algorithm !== "hmac-sha256") return false;
|
|
17
|
+
let expected;
|
|
18
|
+
try {
|
|
19
|
+
if (algorithm === "hmac-sha256") expected = createIntegritySignature(value, {
|
|
20
|
+
...options,
|
|
21
|
+
requireSecret: true
|
|
22
|
+
});
|
|
23
|
+
else expected = createIntegritySignature(value, {
|
|
24
|
+
...options,
|
|
25
|
+
secret: "",
|
|
26
|
+
requireSecret: false
|
|
27
|
+
});
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return constantTimeEqual(expected, signature);
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
function isAuthenticatedIntegritySignature(signature) {
|
|
34
|
+
return typeof signature === "string" && signature.startsWith("hmac-sha256:");
|
|
43
35
|
}
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
function stableSerialize(value) {
|
|
37
|
+
return JSON.stringify(normalizeJsonValue(value));
|
|
46
38
|
}
|
|
47
39
|
function resolveIntegritySecret(options) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (secret.length < 32) {
|
|
56
|
-
throw new Error(`${options.envName} must contain at least 32 characters.`);
|
|
57
|
-
}
|
|
58
|
-
return secret;
|
|
40
|
+
const secret = options.secret ?? process.env[options.envName];
|
|
41
|
+
if (secret === void 0 || secret === "") {
|
|
42
|
+
if (options.requireSecret === true) throw new Error(`${options.envName} must be configured with at least 32 characters before creating authenticated signatures.`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (secret.length < 32) throw new Error(`${options.envName} must contain at least 32 characters.`);
|
|
46
|
+
return secret;
|
|
59
47
|
}
|
|
60
48
|
function normalizeJsonValue(value) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const output = Object.create(null);
|
|
78
|
-
const keys = Object.keys(value).sort(compareCanonicalKeys);
|
|
79
|
-
for (const key of keys) {
|
|
80
|
-
const entry = value[key];
|
|
81
|
-
if (entry !== undefined) {
|
|
82
|
-
output[key] = normalizeJsonValue(entry);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return output;
|
|
86
|
-
}
|
|
87
|
-
throw new TypeError(`Integrity payloads must be JSON-serializable; received ${typeof value}.`);
|
|
49
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
50
|
+
if (typeof value === "number") {
|
|
51
|
+
if (!Number.isFinite(value)) throw new TypeError("Integrity payloads cannot contain non-finite numbers.");
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(value)) return value.map((entry) => entry === void 0 ? null : normalizeJsonValue(entry));
|
|
55
|
+
if (typeof value === "object") {
|
|
56
|
+
const output = Object.create(null);
|
|
57
|
+
const keys = Object.keys(value).sort(compareCanonicalKeys);
|
|
58
|
+
for (const key of keys) {
|
|
59
|
+
const entry = value[key];
|
|
60
|
+
if (entry !== void 0) output[key] = normalizeJsonValue(entry);
|
|
61
|
+
}
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
64
|
+
throw new TypeError(`Integrity payloads must be JSON-serializable; received ${typeof value}.`);
|
|
88
65
|
}
|
|
89
66
|
function compareCanonicalKeys(left, right) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return 1;
|
|
94
|
-
return 0;
|
|
67
|
+
if (left < right) return -1;
|
|
68
|
+
if (left > right) return 1;
|
|
69
|
+
return 0;
|
|
95
70
|
}
|
|
96
71
|
function constantTimeEqual(left, right) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
72
|
+
const leftBuffer = Buffer.from(left, "utf8");
|
|
73
|
+
const rightBuffer = Buffer.from(right, "utf8");
|
|
74
|
+
return leftBuffer.length === rightBuffer.length && timingSafeEqual(leftBuffer, rightBuffer);
|
|
100
75
|
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { createIntegritySignature, isAuthenticatedIntegritySignature, stableSerialize, verifyIntegritySignature };
|
|
101
79
|
//# sourceMappingURL=integrity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integrity.js","
|
|
1
|
+
{"version":3,"file":"integrity.js","names":[],"sources":["../../../src/halal-core/crypto/integrity.ts"],"sourcesContent":["import { createHash, createHmac, timingSafeEqual } from \"node:crypto\";\n\nexport interface IntegrityOptions {\n envName: string;\n secret?: string;\n requireSecret?: boolean;\n}\n\nexport function createIntegritySignature(value: unknown, options: IntegrityOptions): string {\n const payload = stableSerialize(value);\n const secret = resolveIntegritySecret(options);\n\n if (secret) {\n const digest = createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n return `hmac-sha256:${digest}`;\n }\n\n const digest = createHash(\"sha256\").update(payload).digest(\"hex\");\n return `sha256:${digest}`;\n}\n\nexport function verifyIntegritySignature(\n value: unknown,\n signature: unknown,\n options: IntegrityOptions,\n): boolean {\n if (typeof signature !== \"string\") {\n return false;\n }\n\n const separator = signature.indexOf(\":\");\n if (separator <= 0) {\n return false;\n }\n\n const algorithm = signature.slice(0, separator);\n if (algorithm !== \"hmac-sha256\" && algorithm !== \"sha256\") {\n return false;\n }\n if (options.requireSecret === true && algorithm !== \"hmac-sha256\") {\n return false;\n }\n\n let expected: string;\n try {\n if (algorithm === \"hmac-sha256\") {\n expected = createIntegritySignature(value, { ...options, requireSecret: true });\n } else {\n expected = createIntegritySignature(value, { ...options, secret: \"\", requireSecret: false });\n }\n } catch {\n return false;\n }\n\n return constantTimeEqual(expected, signature);\n}\n\nexport function isAuthenticatedIntegritySignature(signature: unknown): boolean {\n return typeof signature === \"string\" && signature.startsWith(\"hmac-sha256:\");\n}\n\nexport function stableSerialize(value: unknown): string {\n return JSON.stringify(normalizeJsonValue(value));\n}\n\nfunction resolveIntegritySecret(options: IntegrityOptions): string | undefined {\n const secret = options.secret ?? process.env[options.envName];\n if (secret === undefined || secret === \"\") {\n if (options.requireSecret === true) {\n throw new Error(\n `${options.envName} must be configured with at least 32 characters before creating authenticated signatures.`,\n );\n }\n return undefined;\n }\n\n if (secret.length < 32) {\n throw new Error(`${options.envName} must contain at least 32 characters.`);\n }\n return secret;\n}\n\nfunction normalizeJsonValue(value: unknown): unknown {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") {\n return value;\n }\n if (typeof value === \"number\") {\n if (!Number.isFinite(value)) {\n throw new TypeError(\"Integrity payloads cannot contain non-finite numbers.\");\n }\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((entry) => entry === undefined ? null : normalizeJsonValue(entry));\n }\n if (typeof value === \"object\") {\n // A null-prototype object preserves special JSON keys such as \"__proto__\"\n // instead of invoking the legacy Object.prototype setter and dropping them\n // from the canonical payload.\n const output: Record<string, unknown> = Object.create(null) as Record<string, unknown>;\n const keys = Object.keys(value as Record<string, unknown>).sort(compareCanonicalKeys);\n for (const key of keys) {\n const entry = (value as Record<string, unknown>)[key];\n if (entry !== undefined) {\n output[key] = normalizeJsonValue(entry);\n }\n }\n return output;\n }\n throw new TypeError(`Integrity payloads must be JSON-serializable; received ${typeof value}.`);\n}\n\nfunction compareCanonicalKeys(left: string, right: string): number {\n if (left < right) return -1;\n if (left > right) return 1;\n return 0;\n}\n\nfunction constantTimeEqual(left: string, right: string): boolean {\n const leftBuffer = Buffer.from(left, \"utf8\");\n const rightBuffer = Buffer.from(right, \"utf8\");\n return leftBuffer.length === rightBuffer.length && timingSafeEqual(leftBuffer, rightBuffer);\n}\n"],"mappings":";;;AAQA,SAAgB,yBAAyB,OAAgB,SAAmC;CAC1F,MAAM,UAAU,gBAAgB,MAAM;CACtC,MAAM,SAAS,uBAAuB,QAAQ;AAE9C,KAAI,OAEF,QAAO,eADQ,WAAW,UAAU,OAAO,CAAC,OAAO,QAAQ,CAAC,OAAO,MAAM;AAK3E,QAAO,UADQ,WAAW,SAAS,CAAC,OAAO,QAAQ,CAAC,OAAO,MAAM;;AAInE,SAAgB,yBACd,OACA,WACA,SACS;AACT,KAAI,OAAO,cAAc,SACvB,QAAO;CAGT,MAAM,YAAY,UAAU,QAAQ,IAAI;AACxC,KAAI,aAAa,EACf,QAAO;CAGT,MAAM,YAAY,UAAU,MAAM,GAAG,UAAU;AAC/C,KAAI,cAAc,iBAAiB,cAAc,SAC/C,QAAO;AAET,KAAI,QAAQ,kBAAkB,QAAQ,cAAc,cAClD,QAAO;CAGT,IAAI;AACJ,KAAI;AACF,MAAI,cAAc,cAChB,YAAW,yBAAyB,OAAO;GAAE,GAAG;GAAS,eAAe;GAAM,CAAC;MAE/E,YAAW,yBAAyB,OAAO;GAAE,GAAG;GAAS,QAAQ;GAAI,eAAe;GAAO,CAAC;SAExF;AACN,SAAO;;AAGT,QAAO,kBAAkB,UAAU,UAAU;;AAG/C,SAAgB,kCAAkC,WAA6B;AAC7E,QAAO,OAAO,cAAc,YAAY,UAAU,WAAW,eAAe;;AAG9E,SAAgB,gBAAgB,OAAwB;AACtD,QAAO,KAAK,UAAU,mBAAmB,MAAM,CAAC;;AAGlD,SAAS,uBAAuB,SAA+C;CAC7E,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI,QAAQ;AACrD,KAAI,WAAW,UAAa,WAAW,IAAI;AACzC,MAAI,QAAQ,kBAAkB,KAC5B,OAAM,IAAI,MACR,GAAG,QAAQ,QAAQ,2FACpB;AAEH;;AAGF,KAAI,OAAO,SAAS,GAClB,OAAM,IAAI,MAAM,GAAG,QAAQ,QAAQ,uCAAuC;AAE5E,QAAO;;AAGT,SAAS,mBAAmB,OAAyB;AACnD,KAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,UAClE,QAAO;AAET,KAAI,OAAO,UAAU,UAAU;AAC7B,MAAI,CAAC,OAAO,SAAS,MAAM,CACzB,OAAM,IAAI,UAAU,wDAAwD;AAE9E,SAAO;;AAET,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,KAAK,UAAU,UAAU,SAAY,OAAO,mBAAmB,MAAM,CAAC;AAErF,KAAI,OAAO,UAAU,UAAU;EAI7B,MAAM,SAAkC,OAAO,OAAO,KAAK;EAC3D,MAAM,OAAO,OAAO,KAAK,MAAiC,CAAC,KAAK,qBAAqB;AACrF,OAAK,MAAM,OAAO,MAAM;GACtB,MAAM,QAAS,MAAkC;AACjD,OAAI,UAAU,OACZ,QAAO,OAAO,mBAAmB,MAAM;;AAG3C,SAAO;;AAET,OAAM,IAAI,UAAU,0DAA0D,OAAO,MAAM,GAAG;;AAGhG,SAAS,qBAAqB,MAAc,OAAuB;AACjE,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,MAAO,QAAO;AACzB,QAAO;;AAGT,SAAS,kBAAkB,MAAc,OAAwB;CAC/D,MAAM,aAAa,OAAO,KAAK,MAAM,OAAO;CAC5C,MAAM,cAAc,OAAO,KAAK,OAAO,OAAO;AAC9C,QAAO,WAAW,WAAW,YAAY,UAAU,gBAAgB,YAAY,YAAY"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/halal-core/enforce.d.ts
|
|
2
|
+
declare function enforceDevGuard(appRoot: string, outDir: string): Promise<void>;
|
|
3
|
+
declare function enforceBuildGuard(appRoot: string, outDir: string): Promise<void>;
|
|
4
|
+
declare function enforcePreviewGuard(outDir: string): void;
|
|
5
|
+
declare function enforceProductionServerGuard(outDir: string): void;
|
|
6
|
+
declare function enforceDeploymentGuard(outDir: string): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { enforceBuildGuard, enforceDeploymentGuard, enforceDevGuard, enforcePreviewGuard, enforceProductionServerGuard };
|
|
9
|
+
//# sourceMappingURL=enforce.d.ts.map
|