openredaction 1.0.5 → 1.0.7

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/dist/index.mjs CHANGED
@@ -5,7 +5,6 @@ import * as path from "path";
5
5
  import { join } from "path";
6
6
  import { Worker } from "worker_threads";
7
7
  import { cpus } from "os";
8
- import { useCallback, useEffect, useMemo, useState } from "react";
9
8
 
10
9
  //#region rolldown:runtime
11
10
  var __defProp = Object.defineProperty;
@@ -3894,6 +3893,18 @@ const AWS_ACCESS_KEY = {
3894
3893
  description: "AWS Access Key ID"
3895
3894
  };
3896
3895
  /**
3896
+ * OpenAI API Key
3897
+ * Format: sk-proj- (~160 chars) or legacy sk- (51 chars)
3898
+ */
3899
+ const OPENAI_API_KEY = {
3900
+ type: "OPENAI_API_KEY",
3901
+ regex: /\b(sk-proj-[A-Za-z0-9_-]{100,200}|sk-[A-Za-z0-9_-]{48,52})\b/g,
3902
+ placeholder: "[OPENAI_API_KEY_{n}]",
3903
+ priority: 99,
3904
+ severity: "high",
3905
+ description: "OpenAI API Key"
3906
+ };
3907
+ /**
3897
3908
  * AWS Secret Access Key
3898
3909
  * Format: 40 base64 characters
3899
3910
  */
@@ -4274,6 +4285,7 @@ const OAUTH_TOKEN = {
4274
4285
  };
4275
4286
  const technologyPatterns = [
4276
4287
  AWS_ACCESS_KEY,
4288
+ OPENAI_API_KEY,
4277
4289
  AWS_SECRET_KEY,
4278
4290
  GOOGLE_API_KEY,
4279
4291
  STRIPE_API_KEY,
@@ -12770,7 +12782,7 @@ function calculateContextConfidence(_value, patternType, context) {
12770
12782
  "ADDRESS"
12771
12783
  ].includes(patternType.split("_")[0])) confidence += .1;
12772
12784
  }
12773
- if (context.features.hasExampleContext) confidence -= .15;
12785
+ if (context.features.hasExampleContext && patternType === "EMAIL") confidence -= .15;
12774
12786
  if (context.features.hasMedicalContext && [
12775
12787
  "MEDICAL",
12776
12788
  "MRN",
@@ -12790,7 +12802,8 @@ function calculateContextConfidence(_value, patternType, context) {
12790
12802
  "BITCOIN",
12791
12803
  "ETHEREUM",
12792
12804
  "CRYPTO",
12793
- "PAYMENT"
12805
+ "PAYMENT",
12806
+ "CREDIT_CARD"
12794
12807
  ].some((p) => patternType.includes(p))) confidence += .15;
12795
12808
  if (context.features.hasTechnicalContext && ![
12796
12809
  "API_KEY",
@@ -13221,7 +13234,8 @@ const defaultPasses = [
13221
13234
  "PRIVATE_KEY",
13222
13235
  "AWS",
13223
13236
  "GITHUB",
13224
- "STRIPE"
13237
+ "STRIPE",
13238
+ "OPENAI"
13225
13239
  ],
13226
13240
  description: "Critical credentials and API keys (priority 95-100)"
13227
13241
  },
@@ -13327,7 +13341,8 @@ function createSimpleMultiPass(options) {
13327
13341
  "AWS",
13328
13342
  "GITHUB",
13329
13343
  "STRIPE",
13330
- "JWT"
13344
+ "JWT",
13345
+ "OPENAI"
13331
13346
  ],
13332
13347
  description: "Credentials and API keys"
13333
13348
  });
@@ -13754,7 +13769,10 @@ const DEFAULT_PROXIMITY_RULES = [
13754
13769
  "visa",
13755
13770
  "mastercard",
13756
13771
  "amex",
13757
- "discover"
13772
+ "discover",
13773
+ "カード",
13774
+ "クレジット",
13775
+ "番号"
13758
13776
  ],
13759
13777
  proximityWindow: 8,
13760
13778
  confidenceBoost: .2,
@@ -14215,6 +14233,7 @@ const DEFAULT_SEVERITY_MAP = {
14215
14233
  "AWS_ACCESS_KEY": "high",
14216
14234
  "STRIPE_KEY": "high",
14217
14235
  "GOOGLE_API_KEY": "high",
14236
+ "OPENAI_API_KEY": "high",
14218
14237
  "PRESCRIPTION": "high",
14219
14238
  "BIOMETRIC": "high",
14220
14239
  "EMPLOYEE_ID": "medium",
@@ -18838,279 +18857,6 @@ function generateReport(options = {}) {
18838
18857
  };
18839
18858
  }
18840
18859
 
18841
- //#endregion
18842
- //#region src/integrations/react.ts
18843
- /**
18844
- * React hooks for PII detection
18845
- * Local-first client-side PII detection in React applications
18846
- *
18847
- * NOTE: These are TypeScript hook definitions.
18848
- * React is a peer dependency - users must install React separately.
18849
- */
18850
- /**
18851
- * Hook for PII detection in React components
18852
- *
18853
- * @example
18854
- * ```tsx
18855
- * function MyForm() {
18856
- * const { detect, result, isDetecting } = useOpenRedaction();
18857
- *
18858
- * const handleSubmit = (text: string) => {
18859
- * const detection = detect(text);
18860
- * if (detection.detections.length > 0) {
18861
- * alert('PII detected!');
18862
- * }
18863
- * };
18864
- * }
18865
- * ```
18866
- */
18867
- function useOpenRedaction(options) {
18868
- const detector = useMemo(() => new OpenRedaction(options), [options]);
18869
- const [result, setResult] = useState(null);
18870
- const [isDetecting, setIsDetecting] = useState(false);
18871
- const detect = useCallback(async (text) => {
18872
- setIsDetecting(true);
18873
- try {
18874
- const detection = await detector.detect(text);
18875
- setResult(detection);
18876
- setIsDetecting(false);
18877
- return detection;
18878
- } catch (error) {
18879
- setIsDetecting(false);
18880
- throw error;
18881
- }
18882
- }, [detector]);
18883
- const clear = useCallback(() => {
18884
- setResult(null);
18885
- }, []);
18886
- return {
18887
- detect,
18888
- result,
18889
- isDetecting,
18890
- hasPII: result ? result.detections.length > 0 : false,
18891
- count: result ? result.detections.length : 0,
18892
- clear,
18893
- detector
18894
- };
18895
- }
18896
- /**
18897
- * Hook for real-time PII detection with debouncing
18898
- *
18899
- * @example
18900
- * ```tsx
18901
- * function EmailInput() {
18902
- * const [email, setEmail] = useState('');
18903
- * const { result, hasPII } = usePIIDetector(email, { debounce: 500 });
18904
- *
18905
- * return (
18906
- * <div>
18907
- * <input value={email} onChange={e => setEmail(e.target.value)} />
18908
- * {hasPII && <Warning>PII detected!</Warning>}
18909
- * </div>
18910
- * );
18911
- * }
18912
- * ```
18913
- */
18914
- function usePIIDetector(text, options) {
18915
- const { debounce = 300, ...redactOptions } = options || {};
18916
- const detector = useMemo(() => new OpenRedaction(redactOptions), [redactOptions]);
18917
- const [result, setResult] = useState(null);
18918
- const [isDetecting, setIsDetecting] = useState(false);
18919
- useEffect(() => {
18920
- if (!text) {
18921
- setResult(null);
18922
- return;
18923
- }
18924
- setIsDetecting(true);
18925
- const timer = setTimeout(async () => {
18926
- try {
18927
- setResult(await detector.detect(text));
18928
- setIsDetecting(false);
18929
- } catch (error) {
18930
- setIsDetecting(false);
18931
- }
18932
- }, debounce);
18933
- return () => {
18934
- clearTimeout(timer);
18935
- setIsDetecting(false);
18936
- };
18937
- }, [
18938
- text,
18939
- detector,
18940
- debounce
18941
- ]);
18942
- return {
18943
- result,
18944
- isDetecting,
18945
- hasPII: result ? result.detections.length > 0 : false,
18946
- count: result ? result.detections.length : 0,
18947
- detections: result?.detections || []
18948
- };
18949
- }
18950
- /**
18951
- * Hook for form field PII validation
18952
- *
18953
- * @example
18954
- * ```tsx
18955
- * function UserForm() {
18956
- * const emailValidation = useFormFieldValidator({
18957
- * failOnPII: true,
18958
- * types: ['EMAIL', 'PHONE']
18959
- * });
18960
- *
18961
- * return (
18962
- * <input
18963
- * {...emailValidation.getFieldProps()}
18964
- * onChange={e => emailValidation.validate(e.target.value)}
18965
- * />
18966
- * );
18967
- * }
18968
- * ```
18969
- */
18970
- function useFormFieldValidator(options) {
18971
- const { failOnPII = false, types = [], onPIIDetected, ...redactOptions } = options || {};
18972
- const detector = useMemo(() => new OpenRedaction(redactOptions), [redactOptions]);
18973
- const [value, setValue] = useState("");
18974
- const [error, setError] = useState(null);
18975
- const [result, setResult] = useState(null);
18976
- return {
18977
- value,
18978
- error,
18979
- result,
18980
- validate: useCallback(async (inputValue) => {
18981
- setValue(inputValue);
18982
- if (!inputValue) {
18983
- setError(null);
18984
- setResult(null);
18985
- return true;
18986
- }
18987
- try {
18988
- const detection = await detector.detect(inputValue);
18989
- setResult(detection);
18990
- const relevantDetections = types.length > 0 ? detection.detections.filter((d) => types.includes(d.type)) : detection.detections;
18991
- if (relevantDetections.length > 0) {
18992
- if (failOnPII) setError(`Sensitive information detected: ${relevantDetections[0].type}`);
18993
- if (onPIIDetected) onPIIDetected(detection);
18994
- return false;
18995
- }
18996
- setError(null);
18997
- return true;
18998
- } catch (error) {
18999
- setError("Validation failed");
19000
- return false;
19001
- }
19002
- }, [
19003
- detector,
19004
- failOnPII,
19005
- types,
19006
- onPIIDetected
19007
- ]),
19008
- getFieldProps: useCallback(() => ({
19009
- value,
19010
- "aria-invalid": error ? "true" : "false",
19011
- "aria-describedby": error ? "pii-error" : void 0
19012
- }), [value, error]),
19013
- isValid: !error,
19014
- hasPII: result ? result.detections.length > 0 : false
19015
- };
19016
- }
19017
- /**
19018
- * Hook for batch PII detection
19019
- *
19020
- * @example
19021
- * ```tsx
19022
- * function BatchProcessor() {
19023
- * const { processAll, results, isProcessing } = useBatchDetector();
19024
- *
19025
- * const handleProcess = async () => {
19026
- * const documents = ['text1', 'text2', 'text3'];
19027
- * await processAll(documents);
19028
- * };
19029
- * }
19030
- * ```
19031
- */
19032
- function useBatchDetector(options) {
19033
- const detector = useMemo(() => new OpenRedaction(options), [options]);
19034
- const [results, setResults] = useState([]);
19035
- const [isProcessing, setIsProcessing] = useState(false);
19036
- const [progress, setProgress] = useState(0);
19037
- const processAll = useCallback(async (texts) => {
19038
- setIsProcessing(true);
19039
- setProgress(0);
19040
- const detections = [];
19041
- for (let i = 0; i < texts.length; i++) {
19042
- const result = await detector.detect(texts[i]);
19043
- detections.push(result);
19044
- setProgress((i + 1) / texts.length * 100);
19045
- await new Promise((resolve) => setTimeout(resolve, 0));
19046
- }
19047
- setResults(detections);
19048
- setIsProcessing(false);
19049
- setProgress(100);
19050
- return detections;
19051
- }, [detector]);
19052
- const clear = useCallback(() => {
19053
- setResults([]);
19054
- setProgress(0);
19055
- }, []);
19056
- return {
19057
- processAll,
19058
- results,
19059
- isProcessing,
19060
- progress,
19061
- totalDetections: useMemo(() => results.reduce((sum, r) => sum + r.detections.length, 0), [results]),
19062
- clear
19063
- };
19064
- }
19065
- /**
19066
- * Hook for PII detection with auto-redaction
19067
- *
19068
- * @example
19069
- * ```tsx
19070
- * function SecureTextArea() {
19071
- * const { text, setText, redactedText, hasPII } = useAutoRedact();
19072
- *
19073
- * return (
19074
- * <div>
19075
- * <textarea value={text} onChange={e => setText(e.target.value)} />
19076
- * {hasPII && <div>Redacted: {redactedText}</div>}
19077
- * </div>
19078
- * );
19079
- * }
19080
- * ```
19081
- */
19082
- function useAutoRedact(options) {
19083
- const { debounce = 300, ...redactOptions } = options || {};
19084
- const detector = useMemo(() => new OpenRedaction(redactOptions), [redactOptions]);
19085
- const [text, setText] = useState("");
19086
- const [result, setResult] = useState(null);
19087
- useEffect(() => {
19088
- if (!text) {
19089
- setResult(null);
19090
- return;
19091
- }
19092
- const timer = setTimeout(async () => {
19093
- try {
19094
- setResult(await detector.detect(text));
19095
- } catch (error) {}
19096
- }, debounce);
19097
- return () => clearTimeout(timer);
19098
- }, [
19099
- text,
19100
- detector,
19101
- debounce
19102
- ]);
19103
- return {
19104
- text,
19105
- setText,
19106
- result,
19107
- redactedText: result?.redacted || text,
19108
- hasPII: result ? result.detections.length > 0 : false,
19109
- detections: result?.detections || [],
19110
- count: result ? result.detections.length : 0
19111
- };
19112
- }
19113
-
19114
18860
  //#endregion
19115
18861
  //#region src/tenancy/TenantManager.ts
19116
18862
  /**
@@ -20508,5 +20254,5 @@ init_ConfigExporter();
20508
20254
  init_HealthCheck();
20509
20255
 
20510
20256
  //#endregion
20511
- export { ADMIN_ROLE, ALL_PERMISSIONS, ANALYST_ROLE, APIServer, BatchProcessor, ConfigExporter, ConfigLoader, ConsoleAuditLogger, ContextRulesEngine, CsvProcessor, DEFAULT_DOMAIN_VOCABULARIES, DEFAULT_PROXIMITY_RULES, DEFAULT_SEVERITY_MAP, DEFAULT_TIER_QUOTAS, DocumentProcessor, ExplainAPI, GRAFANA_DASHBOARD_TEMPLATE, HealthChecker, InMemoryAuditLogger, InMemoryMetricsCollector, JsonProcessor, LocalLearningStore, NERDetector, OCRProcessor, OPERATOR_ROLE, OpenRedaction, OpenRedactionError, PersistentAuditLogger, PriorityOptimizer, PrometheusServer, RBACManager, RegexMaxMatchesError, RegexTimeoutError, ReportGenerator, SEVERITY_SCORES, SeverityClassifier, StreamingDetector, TenantManager, TenantNotFoundError, TenantQuotaExceededError, TenantSuspendedError, VIEWER_ROLE, WebhookManager, WorkerPool, XlsxProcessor, allPatterns, analyzeContextFeatures, analyzeFullContext, calculateContextConfidence, calculateRisk, callAIDetect, ccpaPreset, commonFalsePositives, compileSafeRegex, contactPatterns, convertAIEntityToDetection, createAPIServer, createBatchProcessor, createCacheDisabledError, createConfigLoadError, createConfigPreset, createContextRulesEngine, createCsvProcessor, createCustomRole, createDocumentProcessor, createExplainAPI, createHealthChecker, createHighMemoryError, createInvalidPatternError, createJsonProcessor, createLearningDisabledError, createMultiPassDisabledError, createNERDetector, createOCRProcessor, createOptimizationDisabledError, createPersistentAuditLogger, createPriorityOptimizer, createPrometheusServer, createRBACManager, createReportGenerator, createSeverityClassifier, createSimpleMultiPass, createStreamingDetector, createTenantManager, createValidationError, createWebhookManager, createWorkerPool, createXlsxProcessor, defaultPasses, detectPII, detectionsOverlap, educationPreset, exportForVersionControl, extractContext, filterFalsePositives, financePreset, financialPatterns, gdprPreset, generateReport, getAIEndpoint, getPatternsByCategory, getPredefinedRole, getPreset, getSeverity, governmentPatterns, groupPatternsByPass, healthCheckMiddleware, healthcarePreset, healthcareResearchPreset, hipaaPreset, inferDocumentType, isFalsePositive, isUnsafePattern, mergeAIEntities, mergePassDetections, networkPatterns, openredactionMiddleware, personalPatterns, safeExec, safeExecAll, transportLogisticsPreset, useAutoRedact, useBatchDetector, useFormFieldValidator, useOpenRedaction, usePIIDetector, validateAIEntity, validateEmail, validateIBAN, validateLuhn, validateNHS, validateNINO, validateName, validatePattern, validateSSN, validateSortCode, validateUKPassport, verifyWebhookSignature };
20257
+ export { ADMIN_ROLE, ALL_PERMISSIONS, ANALYST_ROLE, APIServer, BatchProcessor, ConfigExporter, ConfigLoader, ConsoleAuditLogger, ContextRulesEngine, CsvProcessor, DEFAULT_DOMAIN_VOCABULARIES, DEFAULT_PROXIMITY_RULES, DEFAULT_SEVERITY_MAP, DEFAULT_TIER_QUOTAS, DocumentProcessor, ExplainAPI, GRAFANA_DASHBOARD_TEMPLATE, HealthChecker, InMemoryAuditLogger, InMemoryMetricsCollector, JsonProcessor, LocalLearningStore, NERDetector, OCRProcessor, OPERATOR_ROLE, OpenRedaction, OpenRedactionError, PersistentAuditLogger, PriorityOptimizer, PrometheusServer, RBACManager, RegexMaxMatchesError, RegexTimeoutError, ReportGenerator, SEVERITY_SCORES, SeverityClassifier, StreamingDetector, TenantManager, TenantNotFoundError, TenantQuotaExceededError, TenantSuspendedError, VIEWER_ROLE, WebhookManager, WorkerPool, XlsxProcessor, allPatterns, analyzeContextFeatures, analyzeFullContext, calculateContextConfidence, calculateRisk, callAIDetect, ccpaPreset, commonFalsePositives, compileSafeRegex, contactPatterns, convertAIEntityToDetection, createAPIServer, createBatchProcessor, createCacheDisabledError, createConfigLoadError, createConfigPreset, createContextRulesEngine, createCsvProcessor, createCustomRole, createDocumentProcessor, createExplainAPI, createHealthChecker, createHighMemoryError, createInvalidPatternError, createJsonProcessor, createLearningDisabledError, createMultiPassDisabledError, createNERDetector, createOCRProcessor, createOptimizationDisabledError, createPersistentAuditLogger, createPriorityOptimizer, createPrometheusServer, createRBACManager, createReportGenerator, createSeverityClassifier, createSimpleMultiPass, createStreamingDetector, createTenantManager, createValidationError, createWebhookManager, createWorkerPool, createXlsxProcessor, defaultPasses, detectPII, detectionsOverlap, educationPreset, exportForVersionControl, extractContext, filterFalsePositives, financePreset, financialPatterns, gdprPreset, generateReport, getAIEndpoint, getPatternsByCategory, getPredefinedRole, getPreset, getSeverity, governmentPatterns, groupPatternsByPass, healthCheckMiddleware, healthcarePreset, healthcareResearchPreset, hipaaPreset, inferDocumentType, isFalsePositive, isUnsafePattern, mergeAIEntities, mergePassDetections, networkPatterns, openredactionMiddleware, personalPatterns, safeExec, safeExecAll, transportLogisticsPreset, validateAIEntity, validateEmail, validateIBAN, validateLuhn, validateNHS, validateNINO, validateName, validatePattern, validateSSN, validateSortCode, validateUKPassport, verifyWebhookSignature };
20512
20258
  //# sourceMappingURL=index.mjs.map