diff --git a/src/error/codes/index.ts b/src/error/codes/index.ts index 0a30afe8..0194e55e 100644 --- a/src/error/codes/index.ts +++ b/src/error/codes/index.ts @@ -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 }, diff --git a/src/error/messages/index.ts b/src/error/messages/index.ts index f9344a77..5442e2cd 100644 --- a/src/error/messages/index.ts +++ b/src/error/messages/index.ts @@ -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.`, diff --git a/src/index.ts b/src/index.ts index 27f55d2d..e4f52a73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -93,6 +96,9 @@ export { DeidentifyTextResponse, ReidentifyTextRequest, ReidentifyTextOptions, + DeidentifyFileOptions, + DeidentifyFileRequest, + DeidentifyFileResponse, ReidentifyTextResponse, TokenFormat, Transformations diff --git a/src/utils/index.ts b/src/utils/index.ts index c74cdaf6..02a75081 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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', @@ -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, diff --git a/src/utils/logs/index.ts b/src/utils/logs/index.ts index 5a4645fb..0cb32fe2 100644 --- a/src/utils/logs/index.ts +++ b/src/utils/logs/index.ts @@ -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.', @@ -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.', diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index 67dda007..0534bb6f 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -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"; @@ -1037,4 +1040,96 @@ export const validateInvokeConnectionRequest = (invokeRequest: InvokeConnectionR } else { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_INVOKE_CONNECTION_REQUEST); } -}; \ No newline at end of file +}; + +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); + } +}; diff --git a/src/vault/client/index.ts b/src/vault/client/index.ts index c3266c7e..abb4b30e 100644 --- a/src/vault/client/index.ts +++ b/src/vault/client/index.ts @@ -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"; @@ -26,6 +27,8 @@ class VaultClient { stringsAPI!: Strings; + filesAPI!: Files; + individualCredentials?: Credentials; skyflowCredentials?: Credentials; @@ -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; } diff --git a/src/vault/controller/detect/index.ts b/src/vault/controller/detect/index.ts index 0ce94f5c..392cb76a 100644 --- a/src/vault/controller/detect/index.ts +++ b/src/vault/controller/detect/index.ts @@ -1,16 +1,28 @@ //imports -import { DetectedEntity, EntityType, Transformations } from "../../../ _generated_/rest/api"; -import { generateSDKMetrics, getBearerToken, MessageType, parameterizedString, printLog, removeSDKVersion, SDK_METRICS_HEADER_KEY, TYPES } from "../../../utils"; +import path from "path"; +import { DeidentifyTextRequest as DeidentifyTextRequest2,DeidentifyAudioRequest, DeidentifyAudioRequestFileDataFormat, DeidentifyDocumentRequest, DeidentifyDocumentRequestFileDataFormat, DeidentifyFileRequestFileDataFormat, DeidentifyImageRequest, DeidentifyImageRequestFileDataFormat, DeidentifyImageRequestMaskingMethod, DeidentifyPdfRequest, DeidentifyPresentationRequest, DeidentifyPresentationRequestFileDataFormat, DeidentifySpreadsheetRequest, DeidentifySpreadsheetRequestFileDataFormat, DeidentifyStructuredTextRequest, DeidentifyStructuredTextRequestFileDataFormat, DetectedEntity, EntityType, GetRunRequest, Transformations, DeidentifyStatusResponse } from "../../../ _generated_/rest/api"; +import { DeidentifyFileRequest as DeidentifyFileRequest2} from "../../../ _generated_/rest/api"; +import { generateSDKMetrics, getBearerToken, MessageType, parameterizedString, printLog, removeSDKVersion, SDK_METRICS_HEADER_KEY, TYPES, DeidenitfyFileRequestTypes } from "../../../utils"; import logs from "../../../utils/logs"; +import { validateDeidentifyFileRequest, validateDeIdentifyText } from "../../../utils/validations"; import { validateDeIdentifyTextRequest, validateReidentifyTextRequest } from "../../../utils/validations"; import VaultClient from "../../client"; +import DeidentifyFileOptions from "../../model/options/deidentify-file"; import DeidentifyTextOptions from "../../model/options/deidentify-text"; import ReidentifyTextOptions from "../../model/options/reidentify-text"; +import DeidentifyFileRequest from "../../model/request/deidentify-file"; import DeidentifyTextRequest from "../../model/request/deidentify-text"; import ReidentifyTextRequest from "../../model/request/reidentify-text"; +import DeidentifyFileResponse from "../../model/response/deidentify-file"; import DeidentifiedTextResponse from "../../model/response/deidentify-text"; import DeidentifyTextResponse from "../../model/response/deidentify-text"; +import * as fs from 'fs'; +import SkyflowError from "../../../error"; +import SKYFLOW_ERROR_CODE from "../../../error/codes"; + +const mime = require('mime-types'); + import ReidentifyTextResponse from "../../model/response/reidentify-text"; class DetectController { @@ -25,7 +37,354 @@ class DetectController { private createSdkHeaders() { return { [SDK_METRICS_HEADER_KEY]: JSON.stringify(generateSDKMetrics()) }; } + private buildAudioRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifyAudioRequest { + var audioRequest : DeidentifyAudioRequest = { + file: { + base64: baseRequest.getFile().base64 as string, + data_format: baseRequest.getFile().format as DeidentifyAudioRequestFileDataFormat, + }, + vault_id: this.client.vaultId, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + }, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + output_transcription: options?.getOutputTranscription(), + output_processed_audio: options?.getOutputProcessedAudio(), + bleep_gain: options?.getBleep()?.getGain(), + bleep_frequency: options?.getBleep()?.getFrequency(), + bleep_start_padding: options?.getBleep()?.getStartPadding(), + bleep_stop_padding: options?.getBleep()?.getStopPadding(), + } + return audioRequest; + } + private buildTextFileRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifyTextRequest2 { + var textFileRequest: DeidentifyTextRequest2 = { + vault_id: this.client.vaultId, + file: { + base64: baseRequest.getFile().base64 as string, + data_format: "txt", + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + }, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + } + return textFileRequest; + } + + private buildPdfRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifyPdfRequest { + var pdfRequest: DeidentifyPdfRequest = { + file: { + base64: baseRequest.getFile().base64 as string, + data_format: "pdf", + }, + vault_id: this.client.vaultId, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + }, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + max_resolution: options?.getMaxResolution(), + density: options?.getDensity(), + } + return pdfRequest; + } + + private buildImageRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifyImageRequest { + var imageRequest: DeidentifyImageRequest = { + vault_id: this.client.vaultId, + file: { + base64: baseRequest.getFile().base64 as string, + data_format: baseRequest.getFile().format as DeidentifyImageRequestFileDataFormat, + }, + allow_regex: options?.getAllowRegexList(), + entity_types: options?.getEntities() as EntityType[], + masking_method: options?.getMaskingMethod() as DeidentifyImageRequestMaskingMethod, + output_ocr_text: options?.getOutputOcrText(), + output_processed_image: options?.getOutputProcessedImage(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + } + }; + return imageRequest; + } + + private buildPptRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifyPresentationRequest { + var pptRequest: DeidentifyPresentationRequest = { + vault_id: this.client.vaultId, + file: { + base64: baseRequest.getFile().base64 as string, + data_format: baseRequest.getFile().format as DeidentifyPresentationRequestFileDataFormat, + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + }, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + return pptRequest; + } + + private buildSpreadsheetRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifySpreadsheetRequest { + var spreadsheetRequest: DeidentifySpreadsheetRequest = { + vault_id: this.client.vaultId, + file: { + base64: baseRequest.getFile().base64 as string, + data_format: baseRequest.getFile().format as DeidentifySpreadsheetRequestFileDataFormat, + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + }, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + return spreadsheetRequest; + } + + private buildStructuredTextRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifyStructuredTextRequest { + var structuredTextRequest: DeidentifyStructuredTextRequest = { + vault_id: this.client.vaultId, + file: { + base64: baseRequest.getFile().base64 as string, + data_format: baseRequest.getFile().format as DeidentifyStructuredTextRequestFileDataFormat, + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + }, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + return structuredTextRequest; + } + + private buildDocumentRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifyDocumentRequest { + var documentRequest: DeidentifyDocumentRequest = { + vault_id: this.client.vaultId, + file: { + base64: baseRequest.getFile().base64 as string, + data_format: baseRequest.getFile().format as DeidentifyDocumentRequestFileDataFormat, + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + }, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + return documentRequest; + } + + private buildGenericFileRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): DeidentifyFileRequest2 { + var genericRequest: DeidentifyFileRequest2 = { + vault_id: this.client.vaultId, + file: { + base64: baseRequest.getFile().base64 as string, + data_format: baseRequest.getFile().format as DeidentifyAudioRequestFileDataFormat, + }, + token_type: { + default: options?.getTokenType()?.getDefault(), + entity_only: options?.getTokenType()?.getEntityOnly(), + entity_unq_counter: options?.getTokenType()?.getEntityUnqCounter(), + }, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + entity_types: options?.getEntities() as EntityType[], + } + return genericRequest; + } + + private buildDeidentifyTextRequest(request: DeidentifyTextRequest, options?: DeidentifyTextOptions) { + return { + vault_id: this.client.vaultId, + text: request.text, + entity_types: options?.getEntities() as EntityType[], + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + } + + private decodeBase64AndSaveToFile(base64Data: string, outputFilePath: string) { + try { + // Decode the base64 string + const buffer = Buffer.from(base64Data, 'base64'); + + // Write the decoded data to the specified file + fs.writeFileSync(outputFilePath, buffer); + } catch (error) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_DEIDENTIFY_FILE_REQUEST); + + } + } + + private processDeidentifyFileResponse(response: any, outputDirectory: string) { + try { + // Ensure the output directory exists + if (!fs.existsSync(outputDirectory)) { + fs.mkdirSync(outputDirectory, { recursive: true }); + } + + // Iterate over the output array in the response + response.output.forEach((fileObject: any, index: number) => { + const { processedFile, processedFileType, processedFileExtension } = fileObject; + + if (!processedFile || !processedFileExtension) { + return; + } + + // Determine the output file name and path + const outputFileName = `processed-file-${processedFileType}.${processedFileExtension}`; + const outputFilePath = path.join(outputDirectory, outputFileName); + + // Handle JSON files + if (processedFileExtension === 'json') { + const jsonData = Buffer.from(processedFile, 'base64').toString('utf-8'); + fs.writeFileSync(outputFilePath, jsonData); + } else { + // Handle other file types (e.g., images, PDFs, etc.) + this.decodeBase64AndSaveToFile(processedFile, outputFilePath); + } + }); + } catch (error) { + throw error; + } + } + + // private getFileExtension(request: DeidentifyFileRequest): string { + // let fileType: string = ''; + + // // Check if path is present and base64 is not present + // if (request.getFile().path && !request.getFile().base64) { + // try { + // const fileBuffer = fs.readFileSync(request.getFile().path ?? ''); + + // // Extract file type from the file path + // const fileExtension = request.getFile().path?.split('.').pop() ?? ''; + // if (fileExtension) { + // fileType = fileExtension.toLowerCase(); + // } else { + // throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE); + // } + + // // Convert file to base64 + // request.getFile().base64 = fileBuffer.toString('base64'); + // } catch (error) { + // throw new SkyflowError(SKYFLOW_ERROR_CODE.FILE_READ_ERROR); + // } + // } else if (request.getFile().base64) { + // // Extract file type from base64 header + // const base64Header = request.getFile().base64?.split(',')[0]; + // const match = base64Header?.match(/data:(.*?);base64/); + // if (match && match[1]) { + // fileType = match[1].split('/')[1]; // Extract the file type (e.g., "png", "jpeg") + // } else { + // throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_BASE64_HEADER); + // } + // } + + // if (!fileType) { + // throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE); + // } + + // return fileType; + // } + private getFileExtension(file: File | Buffer): string { + if (file instanceof File) { + // Extract file extension from the File object + const fileName = file.name; + const fileExtension = fileName.split('.').pop(); + if (!fileExtension) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE); + } + return fileExtension.toLowerCase(); + } else if (file instanceof Buffer) { + // Use mime-types to determine the file type from the Buffer + const mimeType = mime.lookup(file); + if (!mimeType) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE); + } + return mime.extension(mimeType) ?? ''; + } + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE); + } + private async convertFileToBase64(file: File | Buffer): Promise { + if (file instanceof File) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve((reader.result as string).split(',')[1]); // Remove base64 header + reader.onerror = reject; + reader.readAsDataURL(file); + }); + } else if (file instanceof Buffer) { + return file.toString('base64'); + } + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE); + } + private getFileType(extension: string): string { + const mimeType = mime.lookup(extension); // 'image/jpeg' + console.log(`MIME type for .${extension}:`, mimeType); + return mimeType; + } + private getReqType(format: string): DeidenitfyFileRequestTypes{ + var reqType: DeidenitfyFileRequestTypes + if (Object.values(DeidentifyAudioRequestFileDataFormat).includes(format as DeidentifyAudioRequestFileDataFormat)){ + reqType = DeidenitfyFileRequestTypes.AUDIO; + } else if (format.includes('pdf')){ + reqType = DeidenitfyFileRequestTypes.PDF + } else if (format.includes('txt')){ + reqType = DeidenitfyFileRequestTypes.TEXT + } else if (Object.values(DeidentifyImageRequestFileDataFormat).includes(format as DeidentifyImageRequestFileDataFormat)){ + reqType = DeidenitfyFileRequestTypes.IMAGE; + } else if (Object.values(DeidentifyPresentationRequestFileDataFormat).includes(format as DeidentifyPresentationRequestFileDataFormat)){ + reqType = DeidenitfyFileRequestTypes.PPT; + } else if (Object.values(DeidentifySpreadsheetRequestFileDataFormat).includes(format as DeidentifySpreadsheetRequestFileDataFormat)){ + reqType = DeidenitfyFileRequestTypes.SPREADSHEET; + } else if (Object.values(DeidentifyStructuredTextRequestFileDataFormat).includes(format as DeidentifyStructuredTextRequestFileDataFormat)){ + reqType = DeidenitfyFileRequestTypes.STRUCTURED_TEXT; + } else if (Object.values(DeidentifyDocumentRequestFileDataFormat).includes(format as DeidentifyDocumentRequestFileDataFormat)){ + reqType = DeidenitfyFileRequestTypes.DOCUMENT; + } else if (Object.values(DeidentifyFileRequestFileDataFormat).includes(format as DeidentifyFileRequestFileDataFormat)){ + reqType = DeidenitfyFileRequestTypes.FILE + } else { + reqType = DeidenitfyFileRequestTypes.FILE + } + return reqType; + } private handleRequest(apiCall: Function, requestType: string): Promise { return new Promise((resolve, reject) => { printLog(parameterizedString(logs.infoLogs.EMIT_REQUEST, TYPES[requestType]), MessageType.LOG, this.client.getLogLevel()); @@ -42,6 +401,18 @@ class DetectController { case TYPES.DETECT: resolve({records: data, requestId}) break; + case TYPES.DEIDENTIFY_FILE: + const req: GetRunRequest = { + vault_id: this.client.vaultId, + } + // setTimeout(() => { + // }, 3000); + this.client.filesAPI.getRun(data.run_id, req).then((response: any) => { + resolve(response); + }).catch((error: any) => { + reject(error); + }); + break; } }).catch((error: any) => { printLog(logs.errorLogs[`${requestType}_REQUEST_REJECTED`], MessageType.ERROR, this.client.getLogLevel()); @@ -150,6 +521,144 @@ class DetectController { } }); } + deidentifyFile(request: DeidentifyFileRequest, options?: DeidentifyFileOptions): Promise { + return new Promise((resolve, reject) => { + try { + printLog(logs.infoLogs.DETECT_FILE_TRIGGERED, MessageType.LOG, this.client.getLogLevel()); + printLog(logs.infoLogs.VALIDATE_DETECT_FILE_INPUT, MessageType.LOG, this.client.getLogLevel()); + validateDeidentifyFileRequest(request, options, this.client.getLogLevel()); + var file: string = "" + if (!request.getFile().format) { + request.getFile().format = this.getFileExtension(request); + } + if (request.getFile().path && !request.getFile().base64) { + request.getFile().base64 = fs.readFileSync(request.getFile().path ?? '').toString('base64'); + } + // this.convertFileToBase64(file).then((base64) => { + // }).catch((error) => { + // }); + + var reqType : DeidenitfyFileRequestTypes = this.getReqType(request.getFile().format ?? ''); + var promiseReq: Promise; + switch (reqType){ + case DeidenitfyFileRequestTypes.AUDIO: + const audioReq = this.buildAudioRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyAudio( + audioReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + case DeidenitfyFileRequestTypes.TEXT: + const textFileReq = this.buildTextFileRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyText( + textFileReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + case DeidenitfyFileRequestTypes.PDF: + const pdfReq = this.buildPdfRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyPdf( + pdfReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + case DeidenitfyFileRequestTypes.IMAGE: + const imageReq = this.buildImageRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyImage( + imageReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + case DeidenitfyFileRequestTypes.PPT: + const pptReq = this.buildPptRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyPresentation( + pptReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + case DeidenitfyFileRequestTypes.SPREADSHEET: + const spreadsheetReq = this.buildSpreadsheetRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifySpreadsheet( + spreadsheetReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + case DeidenitfyFileRequestTypes.STRUCTURED_TEXT: + const structuredTextReq = this.buildStructuredTextRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyStructuredText( + structuredTextReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + case DeidenitfyFileRequestTypes.DOCUMENT: + const documentReq = this.buildDocumentRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyDocument( + documentReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + case DeidenitfyFileRequestTypes.FILE: + const genericReq = this.buildGenericFileRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyFile( + genericReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + default: + const defaultReq = this.buildGenericFileRequest(request, options); + promiseReq = this.handleRequest( + () => this.client.filesAPI.deidentifyFile( + defaultReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE) + break; + } + + promiseReq.then(data => { + + if (options?.getOutputDirectory() && data.status === "SUCCESS") { + this.processDeidentifyFileResponse(data, options.getOutputDirectory() as string); + } + console.log("response", data); + const deidentifiedFileResponse = new DeidentifyFileResponse( + { + file: data.output[0]?.processedFile ?? '', + type: data.output[0]?.processedFileType ?? '', + extension: data.output[0]?.processedFileExtension ?? '', + wordCount: data.wordCharacterCount?.wordCount ?? 0, + charCount: data.wordCharacterCount?.characterCount ?? 0, + sizeInKb: data.size ?? 0, + durationInSeconds: data.duration ?? 0, + pageCount: data.pages ?? 0, + slideCount: data.slides ?? 0, + entities: data.output + .filter((fileObject: any) => fileObject.processedFileType === 'entities') // Filter for 'entities' + .map((fileObject: any) => ({ + file: fileObject.processedFile, + extension: fileObject.processedFileExtension, + })), + } + ) + resolve(deidentifiedFileResponse); + }).catch(error => { + reject(error) + }); + } catch (error) { + if (error instanceof Error) + printLog(removeSDKVersion(error.message), MessageType.ERROR, this.client.getLogLevel()); + reject(error); + } + }); + } } diff --git a/src/vault/model/options/deidentify-file/bleep-audio/index.ts b/src/vault/model/options/deidentify-file/bleep-audio/index.ts new file mode 100644 index 00000000..40eb3b0f --- /dev/null +++ b/src/vault/model/options/deidentify-file/bleep-audio/index.ts @@ -0,0 +1,31 @@ +class Bleep { + private _gain?: number; + private _frequency?: number; + private _start_padding?: number; + private _stop_padding?: number; + + getGain(): number | undefined { + return this._gain; + } + setGain(gain: number) { + this._gain = gain; + } + getFrequency(): number | undefined { + return this._frequency; + } + setFrequency(frequency: number) { + this._frequency = frequency; + } + getStartPadding(): number | undefined { + return this._start_padding; + } + setStartPadding(start_padding: number) { + this._start_padding = start_padding; + } + getStopPadding(): number | undefined { + return this._stop_padding; + } + setStopPadding(stop_padding: number) { + this._stop_padding = stop_padding; + } +} \ No newline at end of file diff --git a/src/vault/model/options/deidentify-file/index.ts b/src/vault/model/options/deidentify-file/index.ts new file mode 100644 index 00000000..27ffd028 --- /dev/null +++ b/src/vault/model/options/deidentify-file/index.ts @@ -0,0 +1,154 @@ +import { DetectEntities, DetectOutputTranscription, MaskingMethod } from "../../../../utils"; +import TokenFormat from "../deidentify-text/token-format"; +import Transformations from "../deidentify-text/transformations"; +import { TokenTypes } from "./token-type"; + + +class DeidentifyFileOptions { + private _entities?: DetectEntities[]; + private _allowRegexList?: string[]; + private _restrictRegexList?: string[]; + private _tokenFormat?: TokenFormat; + private _transformations?: Transformations; + private _outputProcessedImage?: boolean; + private _outputOcrText?: boolean; + private _maskingMethod?: MaskingMethod; + private _pixelDensity?: number; + private _maxResolution?: number; + private _outputProcessedAudio?: boolean; + private _outputTranscription?: DetectOutputTranscription; + private _bleep?: Bleep; + private _outputDirectory?: string; + private _tokenTypes?: TokenTypes; + private _density?: number; + + constructor() { + } + + getDensity(): number | undefined{ + return this._density; + } + setDensity(density: number) { + this._density = density; + } + + getTokenType(): TokenTypes | undefined { + return this._tokenTypes; + } + setTokenType(tokenTypes: TokenTypes) { + this._tokenTypes = tokenTypes; + } + + getEntities(): string[] | undefined { + return this._entities; + } + + // Setters + setEntities(entities: DetectEntities[]) { + this._entities = entities; + } + + getAllowRegexList(): string[] | undefined { + return this._allowRegexList; + } + + setAllowRegexList(allowRegexList: string[]) { + this._allowRegexList = allowRegexList; + } + + getRestrictRegexList(): string[] | undefined{ + return this._restrictRegexList; + } + + setRestrictRegexList(restrictRegexList: string[]) { + this._restrictRegexList = restrictRegexList; + } + + getTokenFormat(): TokenFormat | undefined{ + return this._tokenFormat; + } + + setTokenFormat(tokenFormat: TokenFormat) { + this._tokenFormat = tokenFormat; + } + + getTransformations(): object | undefined{ + return this._transformations; + } + + setTransformations(transformations: Transformations) { + this._transformations = transformations; + } + + getOutputProcessedImage(): boolean | undefined { + return this._outputProcessedImage; + } + + setOutputProcessedImage(value: boolean | undefined) { + this._outputProcessedImage = value; + } + + getOutputOcrText(): boolean | undefined { + return this._outputOcrText; + } + + setOutputOcrText(outputOcrText: boolean | undefined) { + this._outputOcrText = outputOcrText; + } + + getMaskingMethod(): MaskingMethod | undefined { + return this._maskingMethod; + } + + setMaskingMethod(maskingMethod: MaskingMethod | undefined) { + this._maskingMethod = maskingMethod; + } + + getPixelDensity(): number | undefined { + return this._pixelDensity; + } + + setPixelDensity(pixelDensity: number | undefined) { + this._pixelDensity = pixelDensity; + } + + getMaxResolution(): number | undefined { + return this._maxResolution; + } + + setMaxResolution(maxResolution: number | undefined) { + this._maxResolution = maxResolution; + } + + getOutputProcessedAudio(): boolean | undefined { + return this._outputProcessedAudio; + } + + setOutputProcessedAudio(outputProcessedAudio: boolean | undefined) { + this._outputProcessedAudio = outputProcessedAudio; + } + + getOutputTranscription(): DetectOutputTranscription | undefined { + return this._outputTranscription; + } + + setOutputTranscription(outputTranscription: DetectOutputTranscription | undefined) { + this._outputTranscription = outputTranscription; + } + + getBleep(): Bleep | undefined { + return this._bleep; + } + + setBleep(bleep: Bleep | undefined) { + this._bleep = bleep; + } + getOutputDirectory(): string | undefined { + return this._outputDirectory; + } + setOutputDirectory(outputDirectory: string | undefined) { + this._outputDirectory = outputDirectory; + } +} + +export default DeidentifyFileOptions; \ No newline at end of file diff --git a/src/vault/model/options/deidentify-file/token-type/index.ts b/src/vault/model/options/deidentify-file/token-type/index.ts new file mode 100644 index 00000000..92a5f749 --- /dev/null +++ b/src/vault/model/options/deidentify-file/token-type/index.ts @@ -0,0 +1,26 @@ +import { DetectEntities, DetectTokenTypeWithoutVault } from "../../../../../utils"; + +export class TokenTypes { + private _default?: DetectTokenTypeWithoutVault; + private _enitityUnqCounter?: DetectEntities[]; + private _entityOnly?: DetectEntities[]; + + getDefault(): DetectTokenTypeWithoutVault | undefined { + return this._default; + } + setDefault(defaultValue: DetectTokenTypeWithoutVault) { + this._default = defaultValue; + } + getEntityUnqCounter(): DetectEntities[] | undefined { + return this._enitityUnqCounter; + } + setEntityUnqCounter(entityUnqCounter: DetectEntities[]) { + this._enitityUnqCounter = entityUnqCounter; + } + getEntityOnly(): DetectEntities[] | undefined { + return this._entityOnly; + } + setEntityOnly(entityOnly: DetectEntities[]) { + this._entityOnly = entityOnly; + } +} \ No newline at end of file diff --git a/src/vault/model/request/deidentify-file/index.ts b/src/vault/model/request/deidentify-file/index.ts new file mode 100644 index 00000000..5aff8aa2 --- /dev/null +++ b/src/vault/model/request/deidentify-file/index.ts @@ -0,0 +1,17 @@ +class DeidentifyFileRequest { + private _file: File ; // Accepts a native file object (File for browser, Buffer for Node.js) + + constructor(file: File ) { + this._file = file; + } + + public getFile(): File { + return this._file; + } + + public setFile(file: File ): void { + this._file = file; + } +} + +export default DeidentifyFileRequest; \ No newline at end of file diff --git a/src/vault/model/response/deidentify-file/index.ts b/src/vault/model/response/deidentify-file/index.ts new file mode 100644 index 00000000..bc65be0b --- /dev/null +++ b/src/vault/model/response/deidentify-file/index.ts @@ -0,0 +1,60 @@ +class DeidentifyFileResponse { + // fields + file: string; + enities?: Array<{ + file: string; + extension: string; + }> = []; + type: string; + extension?: string; + wordCount?: number; + charCount?: number; + sizeInKb?: number; + durationInSeconds?: number; + pageCount?: number; + slideCount?: number; + + constructor({ + file, + type, + outputType, + extension, + wordCount, + charCount, + sizeInKb, + durationInSeconds, + pageCount, + slideCount, + entities + } :{ + file: string; + type: string; + outputType?: string; + extension?: string; + wordCount?: number; + charCount?: number; + sizeInKb?: number; + durationInSeconds?: number; + pageCount?: number; + slideCount?: number; + entities?: Array<{ + file: string; + extension: string; + }>; + }) { + this.file = file; + this.type = type; + this.extension = outputType; + this.extension = extension; + this.wordCount = wordCount; + this.charCount = charCount; + this.sizeInKb = sizeInKb; + this.durationInSeconds = durationInSeconds; + this.pageCount = pageCount; + this.slideCount = slideCount; + this.enities = entities; + } + +} + +export default DeidentifyFileResponse; \ No newline at end of file