shield360 1.1.0 → 1.2.1
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 +330 -3
- package/dist/__tests__/build-info.test.js +8 -1
- package/dist/__tests__/build-info.test.js.map +1 -1
- package/dist/__tests__/code-location.test.js +1 -1
- package/dist/__tests__/destination.test.js +15 -0
- package/dist/__tests__/destination.test.js.map +1 -1
- package/dist/__tests__/masking.test.d.ts +1 -0
- package/dist/__tests__/masking.test.js +66 -0
- package/dist/__tests__/masking.test.js.map +1 -0
- package/dist/__tests__/register.e2e.test.d.ts +1 -0
- package/dist/__tests__/register.e2e.test.js +279 -0
- package/dist/__tests__/register.e2e.test.js.map +1 -0
- package/dist/__tests__/register.test.js +60 -0
- package/dist/__tests__/register.test.js.map +1 -1
- package/dist/agents/__tests__/agents.test.d.ts +1 -0
- package/dist/agents/__tests__/agents.test.js +529 -0
- package/dist/agents/__tests__/agents.test.js.map +1 -0
- package/dist/agents/index.d.ts +15 -0
- package/dist/agents/index.js +25 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/passport.d.ts +92 -0
- package/dist/agents/passport.js +301 -0
- package/dist/agents/passport.js.map +1 -0
- package/dist/agents/policy.d.ts +24 -0
- package/dist/agents/policy.js +93 -0
- package/dist/agents/policy.js.map +1 -0
- package/dist/agents/replay.d.ts +20 -0
- package/dist/agents/replay.js +47 -0
- package/dist/agents/replay.js.map +1 -0
- package/dist/agents/report.d.ts +30 -0
- package/dist/agents/report.js +93 -0
- package/dist/agents/report.js.map +1 -0
- package/dist/agents/types.d.ts +148 -0
- package/dist/agents/types.js +37 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/agents/verifier.d.ts +33 -0
- package/dist/agents/verifier.js +276 -0
- package/dist/agents/verifier.js.map +1 -0
- package/dist/ai-security/__tests__/bench.test.d.ts +1 -0
- package/dist/ai-security/__tests__/bench.test.js +50 -0
- package/dist/ai-security/__tests__/bench.test.js.map +1 -0
- package/dist/ai-security/__tests__/checks.test.d.ts +1 -0
- package/dist/ai-security/__tests__/checks.test.js +248 -0
- package/dist/ai-security/__tests__/checks.test.js.map +1 -0
- package/dist/ai-security/__tests__/config.test.d.ts +1 -0
- package/dist/ai-security/__tests__/config.test.js +164 -0
- package/dist/ai-security/__tests__/config.test.js.map +1 -0
- package/dist/ai-security/__tests__/detection.test.d.ts +1 -0
- package/dist/ai-security/__tests__/detection.test.js +114 -0
- package/dist/ai-security/__tests__/detection.test.js.map +1 -0
- package/dist/ai-security/__tests__/fixtures.d.ts +8 -0
- package/dist/ai-security/__tests__/fixtures.js +30 -0
- package/dist/ai-security/__tests__/fixtures.js.map +1 -0
- package/dist/ai-security/__tests__/hooks.test.d.ts +1 -0
- package/dist/ai-security/__tests__/hooks.test.js +174 -0
- package/dist/ai-security/__tests__/hooks.test.js.map +1 -0
- package/dist/ai-security/__tests__/stream.test.d.ts +1 -0
- package/dist/ai-security/__tests__/stream.test.js +85 -0
- package/dist/ai-security/__tests__/stream.test.js.map +1 -0
- package/dist/ai-security/config.d.ts +94 -0
- package/dist/ai-security/config.js +241 -0
- package/dist/ai-security/config.js.map +1 -0
- package/dist/ai-security/context.d.ts +45 -0
- package/dist/ai-security/context.js +108 -0
- package/dist/ai-security/context.js.map +1 -0
- package/dist/ai-security/custom-kinds.d.ts +23 -0
- package/dist/ai-security/custom-kinds.js +97 -0
- package/dist/ai-security/custom-kinds.js.map +1 -0
- package/dist/ai-security/events.d.ts +77 -0
- package/dist/ai-security/events.js +153 -0
- package/dist/ai-security/events.js.map +1 -0
- package/dist/ai-security/hooks.d.ts +48 -0
- package/dist/ai-security/hooks.js +461 -0
- package/dist/ai-security/hooks.js.map +1 -0
- package/dist/ai-security/index.d.ts +209 -0
- package/dist/ai-security/index.js +587 -0
- package/dist/ai-security/index.js.map +1 -0
- package/dist/ai-security/injection-rules.json +1024 -0
- package/dist/ai-security/injection.d.ts +46 -0
- package/dist/ai-security/injection.js +635 -0
- package/dist/ai-security/injection.js.map +1 -0
- package/dist/ai-security/jailbreak.d.ts +38 -0
- package/dist/ai-security/jailbreak.js +73 -0
- package/dist/ai-security/jailbreak.js.map +1 -0
- package/dist/ai-security/limits.d.ts +84 -0
- package/dist/ai-security/limits.js +195 -0
- package/dist/ai-security/limits.js.map +1 -0
- package/dist/ai-security/mcp.d.ts +82 -0
- package/dist/ai-security/mcp.js +150 -0
- package/dist/ai-security/mcp.js.map +1 -0
- package/dist/ai-security/output.d.ts +107 -0
- package/dist/ai-security/output.js +390 -0
- package/dist/ai-security/output.js.map +1 -0
- package/dist/ai-security/policy.d.ts +125 -0
- package/dist/ai-security/policy.js +196 -0
- package/dist/ai-security/policy.js.map +1 -0
- package/dist/ai-security/rag.d.ts +70 -0
- package/dist/ai-security/rag.js +174 -0
- package/dist/ai-security/rag.js.map +1 -0
- package/dist/ai-security/tool-rules.json +203 -0
- package/dist/ai-security/tools.d.ts +46 -0
- package/dist/ai-security/tools.js +62 -0
- package/dist/ai-security/tools.js.map +1 -0
- package/dist/budgets/__tests__/budgets.test.d.ts +1 -0
- package/dist/budgets/__tests__/budgets.test.js +134 -0
- package/dist/budgets/__tests__/budgets.test.js.map +1 -0
- package/dist/budgets/auto.d.ts +25 -0
- package/dist/budgets/auto.js +63 -0
- package/dist/budgets/auto.js.map +1 -0
- package/dist/budgets/index.d.ts +110 -0
- package/dist/budgets/index.js +239 -0
- package/dist/budgets/index.js.map +1 -0
- package/dist/customer/__tests__/customer.test.d.ts +1 -0
- package/dist/customer/__tests__/customer.test.js +155 -0
- package/dist/customer/__tests__/customer.test.js.map +1 -0
- package/dist/customer/index.d.ts +48 -0
- package/dist/customer/index.js +132 -0
- package/dist/customer/index.js.map +1 -0
- package/dist/destination.d.ts +14 -0
- package/dist/destination.js +16 -0
- package/dist/destination.js.map +1 -1
- package/dist/feedback/__tests__/feedback.test.d.ts +1 -0
- package/dist/feedback/__tests__/feedback.test.js +80 -0
- package/dist/feedback/__tests__/feedback.test.js.map +1 -0
- package/dist/feedback/index.d.ts +48 -0
- package/dist/feedback/index.js +97 -0
- package/dist/feedback/index.js.map +1 -0
- package/dist/flags/__tests__/flags.test.d.ts +1 -0
- package/dist/flags/__tests__/flags.test.js +301 -0
- package/dist/flags/__tests__/flags.test.js.map +1 -0
- package/dist/flags/client.d.ts +131 -0
- package/dist/flags/client.js +301 -0
- package/dist/flags/client.js.map +1 -0
- package/dist/flags/engine.d.ts +200 -0
- package/dist/flags/engine.js +677 -0
- package/dist/flags/engine.js.map +1 -0
- package/dist/flags/index.d.ts +4 -0
- package/dist/flags/index.js +16 -0
- package/dist/flags/index.js.map +1 -0
- package/dist/guard/__tests__/findings.test.js +1 -1
- package/dist/guard/__tests__/report.test.js +67 -0
- package/dist/guard/__tests__/report.test.js.map +1 -1
- package/dist/guard/heartbeat.d.ts +34 -0
- package/dist/guard/heartbeat.js +83 -0
- package/dist/guard/heartbeat.js.map +1 -0
- package/dist/guard/integration.d.ts +9 -0
- package/dist/guard/integration.js +4 -2
- package/dist/guard/integration.js.map +1 -1
- package/dist/guard/report.d.ts +24 -1
- package/dist/guard/report.js +67 -18
- package/dist/guard/report.js.map +1 -1
- package/dist/index.d.ts +88 -0
- package/dist/index.js +203 -2
- package/dist/index.js.map +1 -1
- package/dist/instrumentation/__tests__/langchain-wrapper.test.js +1 -1
- package/dist/instrumentation/__tests__/langchain-wrapper.test.js.map +1 -1
- package/dist/instrumentation/anthropic/wrapper.js +4 -0
- package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
- package/dist/instrumentation/openai/wrapper.js +6 -0
- package/dist/instrumentation/openai/wrapper.js.map +1 -1
- package/dist/masking.d.ts +42 -0
- package/dist/masking.js +197 -0
- package/dist/masking.js.map +1 -0
- package/dist/otel/__tests__/app-logs-safety.test.d.ts +1 -0
- package/dist/otel/__tests__/app-logs-safety.test.js +129 -0
- package/dist/otel/__tests__/app-logs-safety.test.js.map +1 -0
- package/dist/otel/__tests__/app-logs.test.d.ts +1 -0
- package/dist/otel/__tests__/app-logs.test.js +269 -0
- package/dist/otel/__tests__/app-logs.test.js.map +1 -0
- package/dist/otel/__tests__/log-auto.test.d.ts +1 -0
- package/dist/otel/__tests__/log-auto.test.js +125 -0
- package/dist/otel/__tests__/log-auto.test.js.map +1 -0
- package/dist/otel/__tests__/log-bridges.test.d.ts +1 -0
- package/dist/otel/__tests__/log-bridges.test.js +170 -0
- package/dist/otel/__tests__/log-bridges.test.js.map +1 -0
- package/dist/otel/__tests__/system-metrics.test.d.ts +1 -0
- package/dist/otel/__tests__/system-metrics.test.js +79 -0
- package/dist/otel/__tests__/system-metrics.test.js.map +1 -0
- package/dist/otel/app-logs.d.ts +80 -0
- package/dist/otel/app-logs.js +195 -0
- package/dist/otel/app-logs.js.map +1 -0
- package/dist/otel/build-info.d.ts +2 -1
- package/dist/otel/build-info.js +3 -2
- package/dist/otel/build-info.js.map +1 -1
- package/dist/otel/events.d.ts +1 -0
- package/dist/otel/events.js +22 -13
- package/dist/otel/events.js.map +1 -1
- package/dist/otel/log-auto.d.ts +44 -0
- package/dist/otel/log-auto.js +200 -0
- package/dist/otel/log-auto.js.map +1 -0
- package/dist/otel/log-bridges.d.ts +54 -0
- package/dist/otel/log-bridges.js +307 -0
- package/dist/otel/log-bridges.js.map +1 -0
- package/dist/otel/metrics.js +1 -1
- package/dist/otel/metrics.js.map +1 -1
- package/dist/otel/system-metrics.d.ts +39 -0
- package/dist/otel/system-metrics.js +166 -0
- package/dist/otel/system-metrics.js.map +1 -0
- package/dist/otel/tracing.js +6 -2
- package/dist/otel/tracing.js.map +1 -1
- package/dist/protect/__tests__/protect.test.js +4 -0
- package/dist/protect/__tests__/protect.test.js.map +1 -1
- package/dist/protect/index.js +9 -4
- package/dist/protect/index.js.map +1 -1
- package/dist/rasp/__tests__/auto-http.test.d.ts +1 -0
- package/dist/rasp/__tests__/auto-http.test.js +136 -0
- package/dist/rasp/__tests__/auto-http.test.js.map +1 -0
- package/dist/rasp/__tests__/baseline.test.d.ts +1 -0
- package/dist/rasp/__tests__/baseline.test.js +86 -0
- package/dist/rasp/__tests__/baseline.test.js.map +1 -0
- package/dist/rasp/__tests__/benign-corpus.test.d.ts +1 -0
- package/dist/rasp/__tests__/benign-corpus.test.js +68 -0
- package/dist/rasp/__tests__/benign-corpus.test.js.map +1 -0
- package/dist/rasp/__tests__/capture-context.test.d.ts +1 -0
- package/dist/rasp/__tests__/capture-context.test.js +135 -0
- package/dist/rasp/__tests__/capture-context.test.js.map +1 -0
- package/dist/rasp/__tests__/code-hook.test.d.ts +1 -0
- package/dist/rasp/__tests__/code-hook.test.js +218 -0
- package/dist/rasp/__tests__/code-hook.test.js.map +1 -0
- package/dist/rasp/__tests__/config-client.test.d.ts +1 -0
- package/dist/rasp/__tests__/config-client.test.js +283 -0
- package/dist/rasp/__tests__/config-client.test.js.map +1 -0
- package/dist/rasp/__tests__/corpus.d.ts +13 -0
- package/dist/rasp/__tests__/corpus.js +111 -0
- package/dist/rasp/__tests__/corpus.js.map +1 -0
- package/dist/rasp/__tests__/custom-rules.test.d.ts +1 -0
- package/dist/rasp/__tests__/custom-rules.test.js +276 -0
- package/dist/rasp/__tests__/custom-rules.test.js.map +1 -0
- package/dist/rasp/__tests__/db-hook.test.d.ts +1 -0
- package/dist/rasp/__tests__/db-hook.test.js +438 -0
- package/dist/rasp/__tests__/db-hook.test.js.map +1 -0
- package/dist/rasp/__tests__/deception.test.d.ts +1 -0
- package/dist/rasp/__tests__/deception.test.js +567 -0
- package/dist/rasp/__tests__/deception.test.js.map +1 -0
- package/dist/rasp/__tests__/detect.test.d.ts +1 -0
- package/dist/rasp/__tests__/detect.test.js +276 -0
- package/dist/rasp/__tests__/detect.test.js.map +1 -0
- package/dist/rasp/__tests__/esm-exports.test.d.ts +1 -0
- package/dist/rasp/__tests__/esm-exports.test.js +20 -0
- package/dist/rasp/__tests__/esm-exports.test.js.map +1 -0
- package/dist/rasp/__tests__/fs-hook.test.d.ts +1 -0
- package/dist/rasp/__tests__/fs-hook.test.js +241 -0
- package/dist/rasp/__tests__/fs-hook.test.js.map +1 -0
- package/dist/rasp/__tests__/hook-contracts.test.d.ts +1 -0
- package/dist/rasp/__tests__/hook-contracts.test.js +201 -0
- package/dist/rasp/__tests__/hook-contracts.test.js.map +1 -0
- package/dist/rasp/__tests__/hook-kit.d.ts +42 -0
- package/dist/rasp/__tests__/hook-kit.js +139 -0
- package/dist/rasp/__tests__/hook-kit.js.map +1 -0
- package/dist/rasp/__tests__/http-hook.test.d.ts +1 -0
- package/dist/rasp/__tests__/http-hook.test.js +250 -0
- package/dist/rasp/__tests__/http-hook.test.js.map +1 -0
- package/dist/rasp/__tests__/iast.test.d.ts +1 -0
- package/dist/rasp/__tests__/iast.test.js +361 -0
- package/dist/rasp/__tests__/iast.test.js.map +1 -0
- package/dist/rasp/__tests__/include-hook.test.d.ts +1 -0
- package/dist/rasp/__tests__/include-hook.test.js +122 -0
- package/dist/rasp/__tests__/include-hook.test.js.map +1 -0
- package/dist/rasp/__tests__/middleware.test.d.ts +1 -0
- package/dist/rasp/__tests__/middleware.test.js +302 -0
- package/dist/rasp/__tests__/middleware.test.js.map +1 -0
- package/dist/rasp/__tests__/process-hook.test.d.ts +1 -0
- package/dist/rasp/__tests__/process-hook.test.js +238 -0
- package/dist/rasp/__tests__/process-hook.test.js.map +1 -0
- package/dist/rasp/__tests__/reporter.test.d.ts +1 -0
- package/dist/rasp/__tests__/reporter.test.js +114 -0
- package/dist/rasp/__tests__/reporter.test.js.map +1 -0
- package/dist/rasp/__tests__/route.test.d.ts +1 -0
- package/dist/rasp/__tests__/route.test.js +46 -0
- package/dist/rasp/__tests__/route.test.js.map +1 -0
- package/dist/rasp/__tests__/rule-expr.test.d.ts +1 -0
- package/dist/rasp/__tests__/rule-expr.test.js +151 -0
- package/dist/rasp/__tests__/rule-expr.test.js.map +1 -0
- package/dist/rasp/__tests__/rule-phases.test.d.ts +1 -0
- package/dist/rasp/__tests__/rule-phases.test.js +271 -0
- package/dist/rasp/__tests__/rule-phases.test.js.map +1 -0
- package/dist/rasp/__tests__/sinks-hook.test.d.ts +1 -0
- package/dist/rasp/__tests__/sinks-hook.test.js +177 -0
- package/dist/rasp/__tests__/sinks-hook.test.js.map +1 -0
- package/dist/rasp/__tests__/targets.test.d.ts +1 -0
- package/dist/rasp/__tests__/targets.test.js +82 -0
- package/dist/rasp/__tests__/targets.test.js.map +1 -0
- package/dist/rasp/__tests__/template-hook.test.d.ts +1 -0
- package/dist/rasp/__tests__/template-hook.test.js +254 -0
- package/dist/rasp/__tests__/template-hook.test.js.map +1 -0
- package/dist/rasp/__tests__/upload.test.d.ts +1 -0
- package/dist/rasp/__tests__/upload.test.js +81 -0
- package/dist/rasp/__tests__/upload.test.js.map +1 -0
- package/dist/rasp/__tests__/vpatch-engine.test.d.ts +1 -0
- package/dist/rasp/__tests__/vpatch-engine.test.js +177 -0
- package/dist/rasp/__tests__/vpatch-engine.test.js.map +1 -0
- package/dist/rasp/auto-http.d.ts +6 -0
- package/dist/rasp/auto-http.js +194 -0
- package/dist/rasp/auto-http.js.map +1 -0
- package/dist/rasp/baseline.d.ts +35 -0
- package/dist/rasp/baseline.js +91 -0
- package/dist/rasp/baseline.js.map +1 -0
- package/dist/rasp/capture.d.ts +76 -0
- package/dist/rasp/capture.js +304 -0
- package/dist/rasp/capture.js.map +1 -0
- package/dist/rasp/config-client.d.ts +122 -0
- package/dist/rasp/config-client.js +337 -0
- package/dist/rasp/config-client.js.map +1 -0
- package/dist/rasp/context.d.ts +65 -0
- package/dist/rasp/context.js +68 -0
- package/dist/rasp/context.js.map +1 -0
- package/dist/rasp/custom-rules.d.ts +68 -0
- package/dist/rasp/custom-rules.js +222 -0
- package/dist/rasp/custom-rules.js.map +1 -0
- package/dist/rasp/data/default-rules.json +199 -0
- package/dist/rasp/data/default-sinks.json +4 -0
- package/dist/rasp/data/dnslog-domains.json +11 -0
- package/dist/rasp/deception.d.ts +70 -0
- package/dist/rasp/deception.js +220 -0
- package/dist/rasp/deception.js.map +1 -0
- package/dist/rasp/detect.d.ts +68 -0
- package/dist/rasp/detect.js +671 -0
- package/dist/rasp/detect.js.map +1 -0
- package/dist/rasp/engine.d.ts +107 -0
- package/dist/rasp/engine.js +330 -0
- package/dist/rasp/engine.js.map +1 -0
- package/dist/rasp/hooks/code.d.ts +20 -0
- package/dist/rasp/hooks/code.js +334 -0
- package/dist/rasp/hooks/code.js.map +1 -0
- package/dist/rasp/hooks/db.d.ts +48 -0
- package/dist/rasp/hooks/db.js +322 -0
- package/dist/rasp/hooks/db.js.map +1 -0
- package/dist/rasp/hooks/esm.d.ts +7 -0
- package/dist/rasp/hooks/esm.js +18 -0
- package/dist/rasp/hooks/esm.js.map +1 -0
- package/dist/rasp/hooks/fs.d.ts +3 -0
- package/dist/rasp/hooks/fs.js +206 -0
- package/dist/rasp/hooks/fs.js.map +1 -0
- package/dist/rasp/hooks/http.d.ts +4 -0
- package/dist/rasp/hooks/http.js +213 -0
- package/dist/rasp/hooks/http.js.map +1 -0
- package/dist/rasp/hooks/include.d.ts +9 -0
- package/dist/rasp/hooks/include.js +79 -0
- package/dist/rasp/hooks/include.js.map +1 -0
- package/dist/rasp/hooks/marks.d.ts +2 -0
- package/dist/rasp/hooks/marks.js +16 -0
- package/dist/rasp/hooks/marks.js.map +1 -0
- package/dist/rasp/hooks/process.d.ts +22 -0
- package/dist/rasp/hooks/process.js +191 -0
- package/dist/rasp/hooks/process.js.map +1 -0
- package/dist/rasp/hooks/sinks.d.ts +54 -0
- package/dist/rasp/hooks/sinks.js +329 -0
- package/dist/rasp/hooks/sinks.js.map +1 -0
- package/dist/rasp/hooks/template.d.ts +21 -0
- package/dist/rasp/hooks/template.js +152 -0
- package/dist/rasp/hooks/template.js.map +1 -0
- package/dist/rasp/iast-rules.d.ts +82 -0
- package/dist/rasp/iast-rules.js +240 -0
- package/dist/rasp/iast-rules.js.map +1 -0
- package/dist/rasp/iast-scope.d.ts +29 -0
- package/dist/rasp/iast-scope.js +54 -0
- package/dist/rasp/iast-scope.js.map +1 -0
- package/dist/rasp/iast.d.ts +81 -0
- package/dist/rasp/iast.js +272 -0
- package/dist/rasp/iast.js.map +1 -0
- package/dist/rasp/index.d.ts +52 -0
- package/dist/rasp/index.js +280 -0
- package/dist/rasp/index.js.map +1 -0
- package/dist/rasp/lexers.d.ts +32 -0
- package/dist/rasp/lexers.js +444 -0
- package/dist/rasp/lexers.js.map +1 -0
- package/dist/rasp/middleware.d.ts +155 -0
- package/dist/rasp/middleware.js +568 -0
- package/dist/rasp/middleware.js.map +1 -0
- package/dist/rasp/model-output.d.ts +14 -0
- package/dist/rasp/model-output.js +107 -0
- package/dist/rasp/model-output.js.map +1 -0
- package/dist/rasp/normalize.d.ts +23 -0
- package/dist/rasp/normalize.js +140 -0
- package/dist/rasp/normalize.js.map +1 -0
- package/dist/rasp/reporter.d.ts +60 -0
- package/dist/rasp/reporter.js +230 -0
- package/dist/rasp/reporter.js.map +1 -0
- package/dist/rasp/rule-expr.d.ts +236 -0
- package/dist/rasp/rule-expr.js +1253 -0
- package/dist/rasp/rule-expr.js.map +1 -0
- package/dist/rasp/template.d.ts +53 -0
- package/dist/rasp/template.js +336 -0
- package/dist/rasp/template.js.map +1 -0
- package/dist/rasp/types.d.ts +110 -0
- package/dist/rasp/types.js +51 -0
- package/dist/rasp/types.js.map +1 -0
- package/dist/rasp/vpatch.d.ts +55 -0
- package/dist/rasp/vpatch.js +120 -0
- package/dist/rasp/vpatch.js.map +1 -0
- package/dist/register.js +52 -11
- package/dist/register.js.map +1 -1
- package/dist/semantic-convention.d.ts +2 -0
- package/dist/semantic-convention.js +5 -0
- package/dist/semantic-convention.js.map +1 -1
- package/dist/types.d.ts +77 -1
- package/dist/zero-code.d.ts +8 -0
- package/dist/zero-code.js +38 -0
- package/dist/zero-code.js.map +1 -0
- package/package.json +18 -2
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shield360 feature flags for Node: fetch an environment's flags, evaluate
|
|
4
|
+
* them locally, and stamp the variation served on the active span.
|
|
5
|
+
*
|
|
6
|
+
* import Shield360 from 'shield360';
|
|
7
|
+
* Shield360.init({ applicationName: 'checkout-api' }); // or SHIELD360_URL / SHIELD360_API_KEY
|
|
8
|
+
* if (Shield360.flags.isEnabled('new-checkout', { key: user.id, plan: user.plan })) { ... }
|
|
9
|
+
* const model = Shield360.flags.getFlag('model-choice', { key: user.id }, 'gpt-4o-mini');
|
|
10
|
+
*
|
|
11
|
+
* The client polls GET /api/flags/rules (every 30 seconds by default, with
|
|
12
|
+
* jitter, sending the last ETag so an unchanged environment costs a 304),
|
|
13
|
+
* keeps the rules in memory and evaluates with the same engine as the server
|
|
14
|
+
* (./engine.ts, a byte-identical copy of sdk/flags-core). It never throws
|
|
15
|
+
* into the app: until rules arrive, for an unknown flag, or on any error, the
|
|
16
|
+
* caller's default is returned.
|
|
17
|
+
*
|
|
18
|
+
* Each evaluation sets `shield360.flag.<key>` = the served variation's key on
|
|
19
|
+
* the active span, so cost, latency and evals can be compared per variant.
|
|
20
|
+
*/
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.flags = exports.FlagsClient = exports.DEFAULT_POLL_INTERVAL_MS = exports.SPAN_ATTRIBUTE_PREFIX = exports.RULES_PATH = void 0;
|
|
26
|
+
exports.promptRefOf = promptRefOf;
|
|
27
|
+
const api_1 = require("@opentelemetry/api");
|
|
28
|
+
const config_1 = __importDefault(require("../config"));
|
|
29
|
+
const prompt_hub_1 = __importDefault(require("../features/prompt-hub"));
|
|
30
|
+
const engine_1 = require("./engine");
|
|
31
|
+
exports.RULES_PATH = '/api/flags/rules';
|
|
32
|
+
exports.SPAN_ATTRIBUTE_PREFIX = 'shield360.flag.';
|
|
33
|
+
exports.DEFAULT_POLL_INTERVAL_MS = 30000;
|
|
34
|
+
const MIN_POLL_INTERVAL_MS = 5000;
|
|
35
|
+
const DEFAULT_TIMEOUT_MS = 10000;
|
|
36
|
+
/** The Prompt Hub reference a flag value names, or null. */
|
|
37
|
+
function promptRefOf(value) {
|
|
38
|
+
if (typeof value === 'string') {
|
|
39
|
+
const text = value.trim();
|
|
40
|
+
const at = text.lastIndexOf('@');
|
|
41
|
+
const name = at > 0 ? text.slice(0, at) : text;
|
|
42
|
+
const version = at > 0 ? text.slice(at + 1) : '';
|
|
43
|
+
if (!name || (at === 0))
|
|
44
|
+
return null;
|
|
45
|
+
return version ? { name, version } : { name };
|
|
46
|
+
}
|
|
47
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
48
|
+
const v = value;
|
|
49
|
+
if (typeof v.name !== 'string' || !v.name.trim())
|
|
50
|
+
return null;
|
|
51
|
+
if (v.version !== undefined && v.version !== null && typeof v.version !== 'string')
|
|
52
|
+
return null;
|
|
53
|
+
return v.version ? { name: v.name.trim(), version: v.version } : { name: v.name.trim() };
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function sameKind(value, fallback) {
|
|
58
|
+
if (fallback === undefined || fallback === null)
|
|
59
|
+
return true;
|
|
60
|
+
if (typeof fallback === 'object')
|
|
61
|
+
return value !== null && typeof value === 'object';
|
|
62
|
+
return typeof value === typeof fallback;
|
|
63
|
+
}
|
|
64
|
+
class FlagsClient {
|
|
65
|
+
constructor(options = {}) {
|
|
66
|
+
this.flags = new Map();
|
|
67
|
+
this.segments = [];
|
|
68
|
+
this.etag = null;
|
|
69
|
+
this.fetched = false;
|
|
70
|
+
this.timer = null;
|
|
71
|
+
this.started = false;
|
|
72
|
+
this.inFlight = null;
|
|
73
|
+
this.waiters = [];
|
|
74
|
+
this.warned = false;
|
|
75
|
+
this.options = { ...options };
|
|
76
|
+
}
|
|
77
|
+
/** Changes the options; takes effect on the next fetch. */
|
|
78
|
+
configure(options) {
|
|
79
|
+
this.options = { ...this.options, ...options };
|
|
80
|
+
}
|
|
81
|
+
destination() {
|
|
82
|
+
const env = typeof process !== 'undefined' ? process.env : {};
|
|
83
|
+
const url = (this.options.url ?? config_1.default.shield360Url ?? env.SHIELD360_URL ?? '').trim().replace(/\/+$/, '');
|
|
84
|
+
const apiKey = (this.options.apiKey ?? config_1.default.shield360ApiKey ?? env.SHIELD360_API_KEY ?? '').trim();
|
|
85
|
+
return url && apiKey ? { url, apiKey } : null;
|
|
86
|
+
}
|
|
87
|
+
applicationName() {
|
|
88
|
+
return this.options.applicationName ?? config_1.default.applicationName;
|
|
89
|
+
}
|
|
90
|
+
/** Starts polling (once). Called on first use; call it at startup to fetch early. */
|
|
91
|
+
start() {
|
|
92
|
+
if (this.started)
|
|
93
|
+
return;
|
|
94
|
+
this.started = true;
|
|
95
|
+
void this.refresh().finally(() => this.schedule());
|
|
96
|
+
}
|
|
97
|
+
schedule() {
|
|
98
|
+
if (!this.started)
|
|
99
|
+
return;
|
|
100
|
+
const interval = Math.max(this.options.pollIntervalMs ?? exports.DEFAULT_POLL_INTERVAL_MS, MIN_POLL_INTERVAL_MS);
|
|
101
|
+
// ±10% jitter, so many processes started together do not poll together.
|
|
102
|
+
const delay = Math.round(interval * (0.9 + Math.random() * 0.2));
|
|
103
|
+
this.timer = setTimeout(() => {
|
|
104
|
+
void this.refresh().finally(() => this.schedule());
|
|
105
|
+
}, delay);
|
|
106
|
+
const t = this.timer;
|
|
107
|
+
if (typeof t.unref === 'function')
|
|
108
|
+
t.unref();
|
|
109
|
+
}
|
|
110
|
+
/** Stops polling. Rules already fetched keep being served. */
|
|
111
|
+
close() {
|
|
112
|
+
this.started = false;
|
|
113
|
+
if (this.timer)
|
|
114
|
+
clearTimeout(this.timer);
|
|
115
|
+
this.timer = null;
|
|
116
|
+
}
|
|
117
|
+
/** Whether rules have been fetched at least once. */
|
|
118
|
+
isReady() {
|
|
119
|
+
return this.fetched;
|
|
120
|
+
}
|
|
121
|
+
/** Resolves true once rules have been fetched, or false after `timeoutMs`. */
|
|
122
|
+
ready(timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
123
|
+
this.start();
|
|
124
|
+
if (this.fetched)
|
|
125
|
+
return Promise.resolve(true);
|
|
126
|
+
return new Promise((resolve) => {
|
|
127
|
+
const timer = setTimeout(() => resolve(false), timeoutMs);
|
|
128
|
+
const t = timer;
|
|
129
|
+
if (typeof t.unref === 'function')
|
|
130
|
+
t.unref();
|
|
131
|
+
this.waiters.push((ok) => {
|
|
132
|
+
clearTimeout(timer);
|
|
133
|
+
resolve(ok);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** Fetches the rules now. Resolves true when the rules are current; never rejects. */
|
|
138
|
+
refresh() {
|
|
139
|
+
if (!this.inFlight) {
|
|
140
|
+
this.inFlight = this.fetchRules().finally(() => {
|
|
141
|
+
this.inFlight = null;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return this.inFlight;
|
|
145
|
+
}
|
|
146
|
+
async fetchRules() {
|
|
147
|
+
const dest = this.destination();
|
|
148
|
+
if (!dest) {
|
|
149
|
+
if (!this.warned) {
|
|
150
|
+
this.warned = true;
|
|
151
|
+
api_1.diag.warn('shield360 flags: no Shield360 URL and API key (SHIELD360_URL, SHIELD360_API_KEY); every flag serves its default.');
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const doFetch = this.options.fetch ?? (typeof fetch === 'function' ? fetch : undefined);
|
|
156
|
+
if (!doFetch)
|
|
157
|
+
return false;
|
|
158
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
|
159
|
+
const timeout = setTimeout(() => controller?.abort(), this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
160
|
+
try {
|
|
161
|
+
const headers = { Authorization: `Bearer ${dest.apiKey}`, Accept: 'application/json' };
|
|
162
|
+
if (this.etag)
|
|
163
|
+
headers['If-None-Match'] = this.etag;
|
|
164
|
+
const response = await doFetch(`${dest.url}${exports.RULES_PATH}`, { method: 'GET', headers, signal: controller?.signal });
|
|
165
|
+
if (response.status === 304) {
|
|
166
|
+
this.markFetched();
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
api_1.diag.debug(`shield360 flags: rules fetch answered ${response.status}`);
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const body = (await response.json());
|
|
174
|
+
if (!body || !Array.isArray(body.flags))
|
|
175
|
+
return false;
|
|
176
|
+
const next = new Map();
|
|
177
|
+
for (const raw of body.flags) {
|
|
178
|
+
// A flag that does not validate is left out: its callers get their default.
|
|
179
|
+
if ((0, engine_1.validateFlag)(raw).length)
|
|
180
|
+
continue;
|
|
181
|
+
const flag = raw;
|
|
182
|
+
next.set(flag.key, flag);
|
|
183
|
+
}
|
|
184
|
+
const segments = [];
|
|
185
|
+
for (const raw of Array.isArray(body.segments) ? body.segments : []) {
|
|
186
|
+
if (!(0, engine_1.validateSegment)(raw).length)
|
|
187
|
+
segments.push(raw);
|
|
188
|
+
}
|
|
189
|
+
this.flags = next;
|
|
190
|
+
this.segments = segments;
|
|
191
|
+
this.etag = response.headers.get('etag');
|
|
192
|
+
this.markFetched();
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
api_1.diag.debug(`shield360 flags: rules fetch failed: ${err instanceof Error ? err.name : 'error'}`);
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
clearTimeout(timeout);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
markFetched() {
|
|
204
|
+
this.fetched = true;
|
|
205
|
+
const waiting = this.waiters;
|
|
206
|
+
this.waiters = [];
|
|
207
|
+
for (const w of waiting)
|
|
208
|
+
w(true);
|
|
209
|
+
}
|
|
210
|
+
/** The flag's value for this context, with the variation and why; never throws. */
|
|
211
|
+
getFlagDetail(key, context = {}, defaultValue) {
|
|
212
|
+
try {
|
|
213
|
+
this.start();
|
|
214
|
+
if (!this.fetched)
|
|
215
|
+
return { value: defaultValue, variation: null, reason: { kind: 'NOT_READY' } };
|
|
216
|
+
const flag = this.flags.get(key);
|
|
217
|
+
const app = this.applicationName();
|
|
218
|
+
if (!flag || (flag.appName && flag.appName !== app)) {
|
|
219
|
+
return { value: defaultValue, variation: null, reason: { kind: 'FLAG_NOT_FOUND' } };
|
|
220
|
+
}
|
|
221
|
+
const result = (0, engine_1.evaluate)(flag, context, this.segments);
|
|
222
|
+
if (result.variation === null)
|
|
223
|
+
return { value: defaultValue, variation: null, reason: result.reason };
|
|
224
|
+
if (!sameKind(result.value, defaultValue)) {
|
|
225
|
+
return { value: defaultValue, variation: null, reason: { kind: 'WRONG_TYPE' } };
|
|
226
|
+
}
|
|
227
|
+
if (this.options.recordOnSpan !== false) {
|
|
228
|
+
const span = api_1.trace.getActiveSpan();
|
|
229
|
+
if (span && span.isRecording())
|
|
230
|
+
span.setAttribute(`${exports.SPAN_ATTRIBUTE_PREFIX}${key}`, result.variation);
|
|
231
|
+
}
|
|
232
|
+
return { value: result.value, variation: result.variation, reason: result.reason };
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return { value: defaultValue, variation: null, reason: { kind: 'ERROR' } };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
getFlag(key, context = {}, defaultValue) {
|
|
239
|
+
return this.getFlagDetail(key, context, defaultValue).value;
|
|
240
|
+
}
|
|
241
|
+
/** Whether a boolean flag is on for this context; false until rules arrive, for an unknown flag, or on error. */
|
|
242
|
+
isEnabled(key, context = {}) {
|
|
243
|
+
return this.getFlag(key, context, false) === true;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* AI: the model a model-switch flag serves this context — a string flag whose
|
|
247
|
+
* variations are provider/model ids such as `openai/gpt-4o-mini`. The default
|
|
248
|
+
* until rules arrive, for an unknown flag, or for an empty value.
|
|
249
|
+
*/
|
|
250
|
+
model(key, context = {}, defaultModel) {
|
|
251
|
+
const value = this.getFlag(key, context, defaultModel);
|
|
252
|
+
return typeof value === 'string' && value.trim() ? value : defaultModel;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* AI: whether a kill switch is engaged for this context — true means stop the
|
|
256
|
+
* feature. A kill switch is a boolean flag that serves true while the feature
|
|
257
|
+
* may run; switching it off (or serving false) engages it. Until rules
|
|
258
|
+
* arrive, or for an unknown flag, it is not engaged: the feature keeps running.
|
|
259
|
+
*/
|
|
260
|
+
killSwitch(key, context = {}) {
|
|
261
|
+
return this.getFlag(key, context, true) === false;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* AI: the Prompt Hub prompt a prompt-version flag serves this context. The
|
|
265
|
+
* flag's variations name prompts (`{ "name": "support-reply", "version":
|
|
266
|
+
* "1.2.0" }` or `"support-reply@1.2.0"`); the one served is fetched from
|
|
267
|
+
* Prompt Hub with the SDK's own fetch. Never rejects: on any failure
|
|
268
|
+
* `prompt` is null and `error` says why.
|
|
269
|
+
*/
|
|
270
|
+
async prompt(key, context = {}, defaultRef, options = {}) {
|
|
271
|
+
let ref = defaultRef;
|
|
272
|
+
let variation = null;
|
|
273
|
+
try {
|
|
274
|
+
const detail = this.getFlagDetail(key, context, undefined);
|
|
275
|
+
const served = detail.variation !== null ? promptRefOf(detail.value) : null;
|
|
276
|
+
if (served) {
|
|
277
|
+
ref = served;
|
|
278
|
+
variation = detail.variation;
|
|
279
|
+
}
|
|
280
|
+
const dest = this.destination();
|
|
281
|
+
const shouldCompile = options.shouldCompile ?? !!options.variables;
|
|
282
|
+
const answer = (await prompt_hub_1.default.getPrompts({
|
|
283
|
+
name: ref.name,
|
|
284
|
+
...(ref.version ? { version: ref.version } : {}),
|
|
285
|
+
shouldCompile,
|
|
286
|
+
variables: options.variables || {},
|
|
287
|
+
...(dest ? { url: dest.url, apiKey: dest.apiKey } : {}),
|
|
288
|
+
}));
|
|
289
|
+
const error = answer && answer.err ? String(answer.err) : null;
|
|
290
|
+
const prompt = error ? null : (answer?.res ?? answer?.data ?? null);
|
|
291
|
+
return { name: ref.name, version: ref.version ?? null, variation, prompt, error: prompt === null && !error ? 'empty response' : error };
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
return { name: ref?.name ?? '', version: ref?.version ?? null, variation, prompt: null, error: err instanceof Error ? err.message : 'error' };
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.FlagsClient = FlagsClient;
|
|
299
|
+
/** The SDK's own client, behind `Shield360.flags`. It reads init()'s settings when it first fetches. */
|
|
300
|
+
exports.flags = new FlagsClient();
|
|
301
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/flags/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;AAqEH,kCAgBC;AAnFD,4CAAiD;AACjD,uDAAwC;AACxC,wEAA+C;AAC/C,qCASkB;AAEL,QAAA,UAAU,GAAG,kBAAkB,CAAC;AAChC,QAAA,qBAAqB,GAAG,iBAAiB,CAAC;AAC1C,QAAA,wBAAwB,GAAG,KAAM,CAAC;AAC/C,MAAM,oBAAoB,GAAG,IAAK,CAAC;AACnC,MAAM,kBAAkB,GAAG,KAAM,CAAC;AAgDlC,4DAA4D;AAC5D,SAAgB,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1B,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/C,MAAM,OAAO,GAAG,EA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
+
*
|
|
4
|
+
* Canonical source: sdk/flags-core/src/engine.ts. Byte-identical copies live at
|
|
5
|
+
* sdk/typescript/src/flags/engine.ts (the TypeScript SDK) and
|
|
6
|
+
* src/client/src/lib/platform/flags/engine.ts (the server); tests in both fail
|
|
7
|
+
* when a copy differs. The Python, Go and .NET SDKs port it
|
|
8
|
+
* (sdk/python/src/shield360/flags/_engine.py, sdk/go/flags/engine.go,
|
|
9
|
+
* sdk/dotnet/src/Shield360/Flags/FlagEngine.cs), and every implementation is
|
|
10
|
+
* held to sdk/flags-core/testdata/vectors.json. Change the canonical file,
|
|
11
|
+
* copy it, port it, and add vectors.
|
|
12
|
+
*
|
|
13
|
+
* Pure and dependency-free: no imports, no Node built-ins, no clock, no
|
|
14
|
+
* randomness. The same flag and context always give the same answer.
|
|
15
|
+
*/
|
|
16
|
+
export type FlagType = 'boolean' | 'string' | 'number' | 'json';
|
|
17
|
+
export declare const FLAG_TYPES: readonly FlagType[];
|
|
18
|
+
export type FlagValue = boolean | string | number | null | FlagValue[] | {
|
|
19
|
+
[key: string]: FlagValue;
|
|
20
|
+
};
|
|
21
|
+
export type Variation = {
|
|
22
|
+
key: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
value: FlagValue;
|
|
25
|
+
};
|
|
26
|
+
export declare const OPERATORS: readonly ["equals", "not_equals", "in", "not_in", "contains", "starts_with", "lt", "lte", "gt", "gte", "semver_eq", "semver_lt", "semver_lte", "semver_gt", "semver_gte", "in_segment", "not_in_segment"];
|
|
27
|
+
export type Operator = (typeof OPERATORS)[number];
|
|
28
|
+
/**
|
|
29
|
+
* Segment operators: the condition's attribute is the literal `segment` and its
|
|
30
|
+
* values are segment keys. `in_segment` holds when the context is in any of
|
|
31
|
+
* them, `not_in_segment` when it is in none. A condition naming a segment the
|
|
32
|
+
* caller did not pass (or one that does not validate) never holds, either way.
|
|
33
|
+
*/
|
|
34
|
+
export declare const SEGMENT_OPERATORS: readonly Operator[];
|
|
35
|
+
export declare const SEGMENT_ATTRIBUTE = "segment";
|
|
36
|
+
export declare const isSegmentOperator: (v: unknown) => boolean;
|
|
37
|
+
export type ConditionValue = string | number | boolean;
|
|
38
|
+
export type Condition = {
|
|
39
|
+
attribute: string;
|
|
40
|
+
operator: Operator;
|
|
41
|
+
values: ConditionValue[];
|
|
42
|
+
};
|
|
43
|
+
export type RolloutWeight = {
|
|
44
|
+
variation: string;
|
|
45
|
+
weight: number;
|
|
46
|
+
};
|
|
47
|
+
export type Rollout = {
|
|
48
|
+
bucketBy?: string;
|
|
49
|
+
weights: RolloutWeight[];
|
|
50
|
+
};
|
|
51
|
+
export type Serve = {
|
|
52
|
+
variation: string;
|
|
53
|
+
} | {
|
|
54
|
+
rollout: Rollout;
|
|
55
|
+
};
|
|
56
|
+
export type Rule = {
|
|
57
|
+
id: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
conditions: Condition[];
|
|
60
|
+
serve: Serve;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* A named, reusable set of conditions of one environment: the context is in
|
|
64
|
+
* the segment when every condition holds. Segments do not reference segments.
|
|
65
|
+
*/
|
|
66
|
+
export type Segment = {
|
|
67
|
+
key: string;
|
|
68
|
+
conditions: Condition[];
|
|
69
|
+
version?: number;
|
|
70
|
+
};
|
|
71
|
+
export type FlagDefinition = {
|
|
72
|
+
key: string;
|
|
73
|
+
type: FlagType;
|
|
74
|
+
variations: Variation[];
|
|
75
|
+
/** The variation served while the flag is off (and while it is archived). */
|
|
76
|
+
offVariation: string;
|
|
77
|
+
on: boolean;
|
|
78
|
+
rules: Rule[];
|
|
79
|
+
/** Served when the flag is on and no rule matches. */
|
|
80
|
+
fallthrough: Serve;
|
|
81
|
+
salt: string;
|
|
82
|
+
archived?: boolean;
|
|
83
|
+
version?: number;
|
|
84
|
+
/** service.name of the one app this flag is for; null for every app. */
|
|
85
|
+
appName?: string | null;
|
|
86
|
+
};
|
|
87
|
+
export type ContextValue = string | number | boolean | null | undefined | ConditionValue[];
|
|
88
|
+
export type EvaluationContext = {
|
|
89
|
+
[attribute: string]: ContextValue;
|
|
90
|
+
};
|
|
91
|
+
export type ReasonKind = 'OFF' | 'ARCHIVED' | 'RULE_MATCH' | 'FALLTHROUGH' | 'ERROR';
|
|
92
|
+
export type Reason = {
|
|
93
|
+
kind: ReasonKind;
|
|
94
|
+
ruleIndex?: number;
|
|
95
|
+
ruleId?: string;
|
|
96
|
+
inRollout?: boolean;
|
|
97
|
+
bucket?: number;
|
|
98
|
+
errorKind?: 'MALFORMED_FLAG';
|
|
99
|
+
};
|
|
100
|
+
export type Evaluation = {
|
|
101
|
+
/** The served variation's key; null only when the flag is malformed. */
|
|
102
|
+
variation: string | null;
|
|
103
|
+
value: FlagValue;
|
|
104
|
+
reason: Reason;
|
|
105
|
+
};
|
|
106
|
+
/** Buckets run 0..99,999: a rollout weight of 1 is a thousandth of a percent. */
|
|
107
|
+
export declare const BUCKETS = 100000;
|
|
108
|
+
export declare const DEFAULT_BUCKET_BY = "key";
|
|
109
|
+
/**
|
|
110
|
+
* Counts every implementation checks alike. Lengths and sizes (names, text
|
|
111
|
+
* values, JSON size) are the server's to limit: string length is counted
|
|
112
|
+
* differently from one language to the next.
|
|
113
|
+
*/
|
|
114
|
+
export declare const LIMITS: {
|
|
115
|
+
variations: number;
|
|
116
|
+
rules: number;
|
|
117
|
+
conditions: number;
|
|
118
|
+
conditionValues: number;
|
|
119
|
+
/** Segments one condition may name. */
|
|
120
|
+
segmentsPerCondition: number;
|
|
121
|
+
};
|
|
122
|
+
export declare const isFlagKey: (v: unknown) => v is string;
|
|
123
|
+
export declare const isVariationKey: (v: unknown) => v is string;
|
|
124
|
+
export declare const isAttributeName: (v: unknown) => v is string;
|
|
125
|
+
export declare const isOperator: (v: unknown) => v is Operator;
|
|
126
|
+
/** UTF-8 bytes of a string, without TextEncoder (so nothing global is assumed). */
|
|
127
|
+
export declare function utf8(text: string): number[];
|
|
128
|
+
/** MurmurHash3 (x86, 32-bit, seed 0) of the UTF-8 bytes of `text`, unsigned. */
|
|
129
|
+
export declare function murmur3(text: string): number;
|
|
130
|
+
/** The bucket (0..99,999) a value falls in for a flag: stable across runs, processes and SDKs. */
|
|
131
|
+
export declare function bucketOf(flagKey: string, salt: string, value: string): number;
|
|
132
|
+
/**
|
|
133
|
+
* The text of a scalar, the same in every SDK: strings as they are, booleans
|
|
134
|
+
* as true/false, integers without a decimal point, other numbers as their
|
|
135
|
+
* shortest round-trip form. Null for anything else.
|
|
136
|
+
*/
|
|
137
|
+
export declare function textOf(v: unknown): string | null;
|
|
138
|
+
/** A finite number, or the text of one (no spaces); null otherwise. */
|
|
139
|
+
export declare function numberOf(v: unknown): number | null;
|
|
140
|
+
type SemVer = {
|
|
141
|
+
major: number;
|
|
142
|
+
minor: number;
|
|
143
|
+
patch: number;
|
|
144
|
+
pre: string[];
|
|
145
|
+
};
|
|
146
|
+
/** A semantic version; a missing minor or patch is 0, build metadata is ignored. */
|
|
147
|
+
export declare function parseSemver(v: unknown): SemVer | null;
|
|
148
|
+
/** -1, 0 or 1, by semver precedence. */
|
|
149
|
+
export declare function compareSemver(a: SemVer, b: SemVer): number;
|
|
150
|
+
/**
|
|
151
|
+
* Whether the context satisfies one condition. A missing (or null) attribute
|
|
152
|
+
* never matches, negated operators included. An array attribute matches a
|
|
153
|
+
* positive operator when any element does, and a negated one when none does.
|
|
154
|
+
*/
|
|
155
|
+
export declare function conditionMatches(condition: Condition, context: EvaluationContext, segments?: Segment[]): boolean;
|
|
156
|
+
/** The valid segment of this key among `segments`, or null. */
|
|
157
|
+
export declare function findSegment(segments: Segment[] | undefined, key: unknown): Segment | null;
|
|
158
|
+
/** Whether the context is in the segment: every one of its conditions holds. */
|
|
159
|
+
export declare function segmentMatches(segment: Segment, context: EvaluationContext): boolean;
|
|
160
|
+
/** Every condition holds (a rule with none never matches). */
|
|
161
|
+
export declare function ruleMatches(rule: Rule, context: EvaluationContext, segments?: Segment[]): boolean;
|
|
162
|
+
/** The segment keys a flag's rules name, each once, in order of first use. */
|
|
163
|
+
export declare function segmentKeysOf(flag: Pick<FlagDefinition, 'rules'>): string[];
|
|
164
|
+
/** The variation a rollout serves this context, and the bucket it fell in. */
|
|
165
|
+
export declare function rolloutVariation(flag: Pick<FlagDefinition, 'key' | 'salt'>, rollout: Rollout, context: EvaluationContext): {
|
|
166
|
+
variation: string;
|
|
167
|
+
bucket: number;
|
|
168
|
+
};
|
|
169
|
+
export type ValidationError = {
|
|
170
|
+
path: string;
|
|
171
|
+
code: string;
|
|
172
|
+
};
|
|
173
|
+
/** Whether `value` is of the flag's type. */
|
|
174
|
+
export declare function valueMatchesType(type: FlagType, value: unknown): boolean;
|
|
175
|
+
/** Null, a string, a boolean, a finite number, or arrays and plain objects of them, at most 20 deep. */
|
|
176
|
+
export declare function plainJson(v: unknown, depth: number): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Everything wrong with a flag definition, by path; empty when it is valid.
|
|
179
|
+
* The server refuses to save an invalid flag; the SDKs and the engine treat
|
|
180
|
+
* one as malformed and serve the caller's default.
|
|
181
|
+
*/
|
|
182
|
+
export declare function validateFlag(input: unknown): ValidationError[];
|
|
183
|
+
/**
|
|
184
|
+
* Everything wrong with a segment, by path; empty when it is valid. A segment
|
|
185
|
+
* has a key (the flag key pattern) and 1..20 conditions with the same
|
|
186
|
+
* operators as a rule's, except the segment operators: segments do not nest.
|
|
187
|
+
*/
|
|
188
|
+
export declare function validateSegment(input: unknown): ValidationError[];
|
|
189
|
+
/**
|
|
190
|
+
* The variation a flag serves a context (`segments` are the environment's
|
|
191
|
+
* segments, for rules that name them):
|
|
192
|
+
* archived -> the off variation (ARCHIVED)
|
|
193
|
+
* off -> the off variation (OFF)
|
|
194
|
+
* on -> the first rule, in order, whose conditions all hold (RULE_MATCH),
|
|
195
|
+
* else the fallthrough (FALLTHROUGH)
|
|
196
|
+
* A rollout picks by bucket. A malformed flag serves nothing (ERROR): the
|
|
197
|
+
* caller's default applies. Never throws.
|
|
198
|
+
*/
|
|
199
|
+
export declare function evaluate(flag: FlagDefinition, context?: EvaluationContext, segments?: Segment[]): Evaluation;
|
|
200
|
+
export {};
|