Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/error/codes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,29 @@ const SKYFLOW_ERROR_CODE = {
INVALID_RESTRICT_REGEX_LIST: { http_code: 400, message: errorMessages.INVALID_RESTRICT_REGEX_LIST },
INVALID_TOKEN_FORMAT: { http_code: 400, message: errorMessages.INVALID_TOKEN_FORMAT },
INVALID_TRANSFORMATIONS: { http_code: 400, message: errorMessages.INVALID_TRANSFORMATIONS },

INVALID_DEIDENTIFY_FILE_REQUEST: { http_code: 400, message: errorMessages.INVALID_DEIDENTIFY_FILE_REQUEST },
EMPTY_FILE_OBJECT:{ http_code: 400, message: errorMessages.EMPTY_FILE_OBJECT },
INVALID_FILE_FORMAT: { http_code: 400, message: errorMessages.INVALID_FILE_FORMAT },
MISSING_FILE_SOURCE: { http_code: 400, message: errorMessages.MISSING_FILE_SOURCE },
INVALID_BASE64_STRING: { http_code: 400, message: errorMessages.INVALID_BASE64_STRING },
INVALID_DEIDENTIFY_FILE_OPTIONS: { http_code: 400, message: errorMessages.INVALID_DEIDENTIFY_FILE_OPTIONS },
INVALID_ENTITIES: { http_code: 400, message: errorMessages.INVALID_ENTITIES },
// INVALID_ALLOW_REGEX_LIST: { http_code: 400, message: errorMessages.INVALID_ALLOW_REGEX_LIST },
// INVALID_RESTRICT_REGEX_LIST: { http_code: 400, message: errorMessages.INVALID_RESTRICT_REGEX_LIST },
// INVALID_TOKEN_FORMAT: { http_code: 400, message: errorMessages.INVALID_TOKEN_FORMAT },
// INVALID_TRANSFORMATIONS: { http_code: 400, message: errorMessages.INVALID_TRANSFORMATIONS },
INVALID_OUTPUT_PROCESSED_IMAGE: { http_code: 400, message: errorMessages.INVALID_OUTPUT_PROCESSED_IMAGE },
INVALID_OUTPUT_OCR_TEXT: { http_code: 400, message: errorMessages.INVALID_OUTPUT_OCR_TEXT },
INVALID_MASKING_METHOD: { http_code: 400, message: errorMessages.INVALID_MASKING_METHOD },
INVALID_PIXEL_DENSITY: { http_code: 400, message: errorMessages.INVALID_PIXEL_DENSITY },
INVALID_MAX_RESOLUTION: { http_code: 400, message: errorMessages.INVALID_MAX_RESOLUTION },
INVALID_OUTPUT_PROCESSED_AUDIO: { http_code: 400, message: errorMessages.INVALID_OUTPUT_PROCESSED_AUDIO },
INVALID_OUTPUT_TRANSCRIPTION: { http_code: 400, message: errorMessages.INVALID_OUTPUT_TRANSCRIPTION },
INVALID_BLEEP:{ http_code: 400, message: errorMessages.INVALID_BLEEP },
INVALID_FILE_OR_ENCODED_FILE:{ http_code: 400, message: errorMessages.INVALID_FILE_OR_ENCODED_FILE },
INVALID_FILE_TYPE:{ http_code: 400, message: errorMessages.INVALID_FILE_TYPE },
FILE_READ_ERROR:{ http_code: 400, message: errorMessages.FILE_READ_ERROR },
INVALID_BASE64_HEADER:{ http_code: 400, message: errorMessages.INVALID_BASE64_HEADER },
INVALID_TEXT_IN_REIDENTIFY: { http_code: 400, message: errorMessages.INVALID_TEXT_IN_REIDENTIFY },
INVALID_REDACTED_ENTITIES_IN_REIDENTIFY: { http_code: 400, message: errorMessages.INVALID_REDACTED_ENTITIES_IN_REIDENTIFY },
INVALID_MASKED_ENTITIES_IN_REIDENTIFY: { http_code: 400, message: errorMessages.INVALID_MASKED_ENTITIES_IN_REIDENTIFY },
Expand Down
30 changes: 30 additions & 0 deletions src/error/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,36 @@ const errorMessages = {
INVALID_RESTRICT_REGEX_LIST: `${errorPrefix} Validation error. The restrictRegexList field must be an array of strings. Specify a valid restrictRegexList.`,
INVALID_TOKEN_FORMAT: `${errorPrefix} Validation error. The tokenFormat key must be an instance of TokenFormat. Specify a valid token format.`,
INVALID_TRANSFORMATIONS: `${errorPrefix} Validation error. The transformations key must be an instance of Transformations. Specify a valid transformations.`,
INVALID_DEIDENTIFY_FILE_REQUEST: `${errorPrefix} Validation error. Invalid deidentify file request. Specify a valid deidentify file request.`,
EMPTY_FILE_OBJECT: `${errorPrefix} Validation error. File object cannot be empty. Specify a valid file object.`,
INVALID_FILE_FORMAT: `${errorPrefix} Validation error. Invalid file format. Specify a valid file format.`,
MISSING_FILE_SOURCE: `${errorPrefix} Validation error. Provide exactly one of filePath, base64, or fileObject.`,
INVALID_FILE_OBJECT: `${errorPrefix} Validation error. Invalid file object. Specify a valid file object.`,
INVALID_BASE64_STRING: `${errorPrefix} Validation error. Invalid base64 string. Specify a valid base64 string.`,
INVALID_DEIDENTIFY_FILE_OPTIONS: `${errorPrefix} Validation error. Invalid deidentify file options. Specify a valid deidentify file options.`,
INVALID_ENTITIES: `${errorPrefix} Validation error. Invalid entities. Specify valid entities as string array.`,
EMPTY_ENTITIES: `${errorPrefix} Validation error. Entities cannot be empty. Specify valid entities.`,
// INVALID_ALLOW_REGEX_LIST: `${errorPrefix} Validation error. Invalid allow regex list. Specify valid allow regex list as string array.`,
EMPTY_ALLOW_REGEX_LIST: `${errorPrefix} Validation error. Allow regex list cannot be empty. Specify valid allow regex list.`,
INVALID_ALLOW_REGEX: `${errorPrefix} Validation error. Invalid allow regex. Specify valid allow regex at index %s1.`,
// INVALID_RESTRICT_REGEX_LIST: `${errorPrefix} Validation error. Invalid restrict regex list. Specify valid restrict regex list as string array.`,
EMPTY_RESTRICT_REGEX_LIST: `${errorPrefix} Validation error. Restrict regex list cannot be empty. Specify valid restrict regex list.`,
INVALID_RESTRICT_REGEX: `${errorPrefix} Validation error. Invalid restrict regex. Specify valid restrict regex at index %s1.`,
// INVALID_TOKEN_FORMAT: `${errorPrefix} Validation error. Invalid token format. Specify valid token format as string.`,
// INVALID_TRANSFORMATIONS: `${errorPrefix} Validation error. Invalid transformations. Specify valid transformations as string array.`,
INVALID_OUTPUT_PROCESSED_IMAGE: `${errorPrefix} Validation error. Invalid output processed image. Specify valid output processed image as string.`,
INVALID_OUTPUT_OCR_TEXT: `${errorPrefix} Validation error. Invalid output ocr text. Specify valid output ocr text as string.`,
INVALID_MASKING_METHOD: `${errorPrefix} Validation error. Invalid masking method. Specify valid masking method as string.`,
INVALID_PIXEL_DENSITY: `${errorPrefix} Validation error. Invalid pixel density. Specify valid pixel density as string.`,
INVALID_OUTPUT_TRANSCRIPTION: `${errorPrefix} Validation error. Invalid output transcription. Specify valid output transcription as string.`,
INVALID_OUTPUT_PROCESSED_AUDIO: `${errorPrefix} Validation error. Invalid output processed audio. Specify valid output processed audio as string.`,
INVALID_MAX_RESOLUTION: `${errorPrefix} Validation error. Invalid max resolution. Specify valid max resolution as string.`,
INVALID_BLEEP: `${errorPrefix} Validation error. Invalid bleep. Specify valid bleep as object.`,
INVALID_FILE_OR_ENCODED_FILE: `${errorPrefix} . Error while decoding base64 and saving file`,
INVALID_FILE_TYPE : `${errorPrefix} Validation error. Invalid file type. Specify a valid file type.`,
INVALID_FILE_NAME: `${errorPrefix} Validation error. Invalid file name. Specify a valid file name.`,
FILE_READ_ERROR: `${errorPrefix} Validation error. Unable to read file. Verify the file path.`,
INVALID_BASE64_HEADER: `${errorPrefix} Validation error. Invalid base64 header. Specify a valid base64 header.`,

INVALID_TEXT_IN_REIDENTIFY: `${errorPrefix} Validation error. The text field is required and must be a non-empty string. Specify a valid text.`,
INVALID_REDACTED_ENTITIES_IN_REIDENTIFY: `${errorPrefix} Validation error. The redactedEntities field must be an array of DetectEntities enums. Specify a valid redactedEntities.`,
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import DeidentifyTextOptions from './vault/model/options/deidentify-text';
import DeidentifyTextResponse from './vault/model/response/deidentify-text';
import ReidentifyTextRequest from './vault/model/request/reidentify-text';
import ReidentifyTextOptions from './vault/model/options/reidentify-text';
import DeidentifyFileOptions from './vault/model/options/deidentify-file';
import DeidentifyFileRequest from './vault/model/request/deidentify-file';
import DeidentifyFileResponse from './vault/model/response/deidentify-file';
import ReidentifyTextResponse from './vault/model/response/reidentify-text';
import TokenFormat from './vault/model/options/deidentify-text/token-format';
import Transformations from './vault/model/options/deidentify-text/transformations';
Expand Down Expand Up @@ -93,6 +96,9 @@ export {
DeidentifyTextResponse,
ReidentifyTextRequest,
ReidentifyTextOptions,
DeidentifyFileOptions,
DeidentifyFileRequest,
DeidentifyFileResponse,
ReidentifyTextResponse,
TokenFormat,
Transformations
Expand Down
29 changes: 29 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,31 @@ export const TYPES = {
DETECT: 'DETECT',
INVOKE_CONNECTION: 'INVOKE_CONNECTION',
DEIDENTIFY_TEXT: 'DEIDENTIFY_TEXT',
DEIDENTIFY_FILE: 'DEIDENTIFY_FILE',
};

export enum DeidenitfyFileRequestTypes {
IMAGE= "IMAGE",
FILE= 'FILE',
AUDIO= 'AUDIO',
PPT= 'PPT',
DOCUMENT= 'DOCUMENT',
PDF= 'PDF',
SPREADSHEET= 'SPREADSHEET',
STRUCTURED_TEXT= 'STRUCTURED_TEXT',
TEXT='TEXT'
}
export enum DetectTokenTypeWithoutVault {
ENTITY_ONLY= "entity_only",
ENTITY_UNQ_COUNTER= "entity_unq_counter",
}

export enum DetectOutputTranscription {
DIARIZED_TRANSCRIPTION = "diarized_transcription",
MEDICAL_DIARIZED_TRANSCRIPTION = "medical_diarized_transcription",
MEDICAL_TRANSCRIPTION = "medical_transcription",
PLAINTEXT_TRANSCRIPTION = "plaintext_transcription",
TRANSCRIPTION = "transcription",
export const CONTROLLER_TYPES = {
DETECT: 'DETECT',
VAULT: 'VAULT',
Expand Down Expand Up @@ -173,6 +196,12 @@ export enum DetectEntities {
ZODIAC_SIGN = 'zodiac_sign',
}

export enum MaskingMethod{
Blackout= "blackout",
Blur= "blur",
}


export interface ISkyflowError {
http_status?: string | number | null,
grpc_code?: string | number | null,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const logs = {
CURRENT_LOG_LEVEL: 'Current log level is %s1.',
CLIENT_INITIALIZED: 'Initialized skyflow client successfully.',
VALIDATE_INSERT_INPUT: 'Validating insert input.',
VALIDATE_DETECT_FILE_INPUT: 'Validating deidentify file input.',
VALIDATE_DETOKENIZE_INPUT: 'Validating detokenize input.',
VALIDATE_TOKENIZE_INPUT: 'Validating tokenize input.',
VALIDATE_FILE_UPLOAD_INPUT: 'Validating detokenize input.',
Expand All @@ -39,6 +40,7 @@ const logs = {
REUSE_API_KEY: 'Reusing api key.',
CONTROLLER_INITIALIZED: 'SkyflowController initialized.',
INSERT_TRIGGERED: 'Insert method triggered.',
DETECT_FILE_TRIGGERED: 'Deidentify file triggered.',
DETOKENIZE_TRIGGERED: 'Detokenize method triggered.',
TOKENIZE_TRIGGERED: 'Tokenize method triggered.',
GET_BY_ID_TRIGGERED: 'Get by ID triggered.',
Expand Down
97 changes: 96 additions & 1 deletion src/utils/validations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import DeidentifyTextRequest from "../../vault/model/request/deidentify-text";
import DeidentifyTextOptions from "../../vault/model/options/deidentify-text";
import TokenFormat from "../../vault/model/options/deidentify-text/token-format";
import Transformations from "../../vault/model/options/deidentify-text/transformations";
import DeidentifyFileOptions from "../../vault/model/options/deidentify-file";
import DeidentifyFileRequest from "../../vault/model/request/deidentify-file";

import ReidentifyTextRequest from "../../vault/model/request/reidentify-text";
import ReidentifyTextOptions from "../../vault/model/options/reidentify-text";

Expand Down Expand Up @@ -1037,4 +1040,96 @@ export const validateInvokeConnectionRequest = (invokeRequest: InvokeConnectionR
} else {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_INVOKE_CONNECTION_REQUEST);
}
};
};

export const validateDeidentifyFileRequest = (deidentifyFileRequest: DeidentifyFileRequest, deidentifyFileOptions?: DeidentifyFileOptions, logLevel: LogLevel = LogLevel.ERROR) => {
if (!deidentifyFileRequest) {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_DEIDENTIFY_FILE_REQUEST);
}

// Validate file object
const file = deidentifyFileRequest.getFile();

// Check if the file is a valid File (browser) or Buffer (Node.js)
if (!(file instanceof File)) {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE);
}

// Additional validation for File (browser)
if (file instanceof File) {
if (!file.name || !file.size) {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE);
}
}

// Validate options if provided
if (deidentifyFileOptions) {
validateDeidentifyFileOptions(deidentifyFileOptions);
}
};

export const validateDeidentifyFileOptions = (deidentifyFileOptions: DeidentifyFileOptions) => {
if (!deidentifyFileOptions) {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_DEIDENTIFY_FILE_OPTIONS);
}

// Validate entities
if (deidentifyFileOptions.getEntities() !== undefined && (!Array.isArray(deidentifyFileOptions.getEntities()))) {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ENTITIES);
}

// Validate allowRegexList
if (deidentifyFileOptions.getAllowRegexList() && !Array.isArray(deidentifyFileOptions.getAllowRegexList())) {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ALLOW_REGEX_LIST);
}

// Validate restrictRegexList
if (deidentifyFileOptions.getRestrictRegexList() && !Array.isArray(deidentifyFileOptions.getRestrictRegexList())) {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RESTRICT_REGEX_LIST);
}

// Validate tokenFormat
if (deidentifyFileOptions.getTokenFormat() && typeof deidentifyFileOptions.getTokenFormat !== 'object') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKEN_FORMAT);
}

// Validate transformations
if (deidentifyFileOptions.getTransformations() && typeof deidentifyFileOptions.getTransformations() !== 'object') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TRANSFORMATIONS);
}

// Validate image-specific options
if (deidentifyFileOptions.getOutputProcessedImage() !== undefined && typeof deidentifyFileOptions.getOutputProcessedImage() !== 'boolean') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OUTPUT_PROCESSED_IMAGE);
}

if (deidentifyFileOptions.getOutputOcrText() !== undefined && typeof deidentifyFileOptions.getOutputOcrText() !== 'boolean') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OUTPUT_OCR_TEXT);
}

if (deidentifyFileOptions.getMaskingMethod() !== undefined && typeof deidentifyFileOptions.getMaskingMethod() !== 'string') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_MASKING_METHOD);
}

// Validate PDF-specific options
if (deidentifyFileOptions.getPixelDensity() !== undefined && typeof deidentifyFileOptions.getPixelDensity() !== 'number') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_PIXEL_DENSITY);
}

if (deidentifyFileOptions.getMaxResolution() !== undefined && typeof deidentifyFileOptions.getMaxResolution() !== 'number') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_MAX_RESOLUTION);
}

// Validate audio-specific options
if (deidentifyFileOptions.getOutputProcessedAudio() !== undefined && typeof deidentifyFileOptions.getOutputProcessedAudio() !== 'boolean') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OUTPUT_PROCESSED_AUDIO);
}

if (deidentifyFileOptions.getOutputTranscription() !== undefined && typeof deidentifyFileOptions.getOutputTranscription() !== 'string') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OUTPUT_TRANSCRIPTION);
}

if (deidentifyFileOptions.getBleep() !== undefined && typeof deidentifyFileOptions.getBleep() !== 'object') {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_BLEEP);
}
};
7 changes: 7 additions & 0 deletions src/vault/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// imports
import { Files } from "../../ _generated_/rest/api/resources/files/client/Client";
import { Query } from "../../ _generated_/rest/api/resources/query/client/Client";
import { Records } from "../../ _generated_/rest/api/resources/records/client/Client";
import { Strings } from "../../ _generated_/rest/api/resources/strings/client/Client";
Expand Down Expand Up @@ -26,6 +27,8 @@ class VaultClient {

stringsAPI!: Strings;

filesAPI!: Files;

individualCredentials?: Credentials;

skyflowCredentials?: Credentials;
Expand Down Expand Up @@ -82,6 +85,10 @@ class VaultClient {
break;
case TYPES.DETECT:
this.stringsAPI = new Strings(this.configuration);
break
case TYPES.DEIDENTIFY_FILE:
this.filesAPI = new Files(this.configuration);
break;
default:
break;
}
Expand Down
Loading
Loading