Skip to content

Commit afc0a02

Browse files
committed
Expanded scan text method to support entire API spec
1 parent 09f69b3 commit afc0a02

File tree

5 files changed

+82
-19
lines changed

5 files changed

+82
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/dist
2-
/node_modules
2+
/node_modules
3+
tsconfig.tsbuildinfo

src/nightfall.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class Nightfall {
99
/**
1010
* Create an instance of the Nightfall client.
1111
*
12-
* @param {string} apiKey Your Nightfall API key
12+
* @param apiKey Your Nightfall API key
1313
*/
1414
constructor(apiKey: string) {
1515
this.API_KEY = apiKey
@@ -30,7 +30,7 @@ export class Nightfall {
3030
*
3131
* @param payload An array of strings that you would like to scan
3232
* @param config The configuration to use to scan the payload
33-
* @returns {Promise} A promise object representing the Nightfall response
33+
* @returns A promise object representing the Nightfall response
3434
*/
3535
async scanText(payload: string[], config: ScanText.RequestConfig): Promise<NightfallResponse<ScanText.Response>> {
3636
try {
@@ -57,8 +57,8 @@ export class Nightfall {
5757
* A helpder function to determine whether the error is a generic JavaScript error or a
5858
* Nightfall API error.
5959
*
60-
* @param {Object} error The error object
61-
* @returns {boolean} A boolean that indicates if the error is a Nightfall error
60+
* @param error The error object
61+
* @returns A boolean that indicates if the error is a Nightfall error
6262
*/
6363
private isNightfallError(error: any): boolean {
6464
if (error.hasOwnProperty('isAxiosError') && error.isAxiosError && error.response.data.hasOwnProperty('code')) {

src/types/detectors.ts

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export namespace Detector {
2-
export enum MinConfidence {
2+
export enum Confidence {
33
VeryUnlikely = 'VERY_UNLIKELY',
44
Unlikely = 'UNLIKELY',
55
Possible = 'POSSIBLE',
@@ -13,11 +13,66 @@ export namespace Detector {
1313
WordList = 'WORD_LIST'
1414
}
1515

16+
type Regex = {
17+
pattern: string
18+
isCaseSensitive: boolean
19+
}
20+
21+
type WordList = {
22+
values: string[]
23+
isCaseSensitive: boolean
24+
}
25+
26+
type ContextRule = {
27+
regex: Regex
28+
proximity: {
29+
windowBefore: number
30+
windowAfter: number
31+
}
32+
confidenceAdjustment: Confidence
33+
}
34+
35+
type ExclusionRule = {
36+
matchType: 'PARTIAL' | 'FULL'
37+
exclusionType: Type.Regex | Type.WordList
38+
regex?: Regex
39+
wordList?: WordList
40+
}
41+
42+
export interface RedactionConfig {
43+
maskConfig?: MaskConfig;
44+
infoTypeSubstitutionConfig?: { [key: string]: string };
45+
substitutionConfig?: SubstitutionConfig;
46+
cryptoConfig?: CryptoConfig;
47+
removeFinding?: boolean;
48+
}
49+
50+
export interface MaskConfig {
51+
charsToIgnore: string[];
52+
maskingChar: string;
53+
numCharsToLeaveUnmasked: number;
54+
maskLeftToRight: boolean;
55+
}
56+
57+
export interface SubstitutionConfig {
58+
substitutionPhrase: string;
59+
}
60+
61+
export interface CryptoConfig {
62+
publicKey: string;
63+
}
64+
1665
export interface Properties {
1766
minNumFindings: number
18-
minConfidence: MinConfidence | string
67+
minConfidence: Confidence | string
68+
detectorUUID?: string,
1969
displayName: string
2070
detectorType: Type | string
21-
nightfallDetector: string
71+
nightfallDetector?: string
72+
regex?: Regex
73+
wordList?: WordList
74+
contextRules?: ContextRule[]
75+
exclusionRules?: ExclusionRule[]
76+
redactionConfig?: RedactionConfig
2277
}
2378
}

src/types/scanText.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export namespace ScanText {
44
export interface RequestConfig {
55
detectionRuleUUIDs?: string[]
66
detectionRules?: DetectionRule[]
7+
contextBytes?: number
78
}
89

910
export interface DetectionRule {
@@ -18,22 +19,29 @@ export namespace ScanText {
1819
}
1920

2021
export interface Finding {
21-
finding: string;
22+
finding: string
23+
redactedFinding?: string
24+
beforeContext?: string
25+
afterContext?: string
2226
detector: {
23-
name: string;
24-
uuid: string;
27+
name: string
28+
uuid: string
2529
};
26-
confidence: string;
30+
confidence: string
2731
location: {
28-
byteRange: FindingRange;
29-
codepointRange: FindingRange;
32+
byteRange: FindingRange
33+
codepointRange: FindingRange
3034
};
31-
matchedDetectionRuleUUIDs: any[];
32-
matchedDetectionRules: string[];
35+
redactedLocation?: {
36+
byteRange: FindingRange
37+
codepointRange: FindingRange
38+
}
39+
matchedDetectionRuleUUIDs: any[]
40+
matchedDetectionRules: string[]
3341
}
3442

3543
type FindingRange = {
36-
start: number;
37-
end: number;
44+
start: number
45+
end: number
3846
}
3947
}

tsconfig.tsbuildinfo

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)