From 8907d21ccf0b4a23556698671e7ebccb360cdadd Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow <156889717+saileshwar-skyflow@users.noreply.github.com> Date: Mon, 12 May 2025 13:25:29 +0530 Subject: [PATCH 01/30] SK-2040: Implement public interface for detect (#207) * SK-2040: add detect public interfaces. --- package-lock.json | 89 +- package.json | 29 +- src/ _generated_/rest/Client.ts | 18 + .../rest/api/errors/BadRequestError.ts | 2 +- .../rest/api/errors/InternalServerError.ts | 19 + .../rest/api/errors/NotFoundError.ts | 2 +- .../rest/api/errors/UnauthorizedError.ts | 2 +- src/ _generated_/rest/api/errors/index.ts | 1 + .../rest/api/resources/audit/client/Client.ts | 5 +- .../resources/authentication/client/Client.ts | 15 +- .../api/resources/binLookup/client/Client.ts | 5 +- .../api/resources/deprecated/client/Client.ts | 305 +++++ .../api/resources/deprecated/client/index.ts | 1 + .../DetectServiceDetectStatusRequest.ts | 14 + .../DetectServiceDetectTextRequest.ts | 34 + .../client/requests/V1DetectFileRequest.ts | 46 + .../deprecated/client/requests/index.ts | 3 + .../rest/api/resources/deprecated/index.ts | 1 + .../rest/api/resources/files/client/Client.ts | 1100 +++++++++++++++++ .../rest/api/resources/files/client/index.ts | 1 + .../client/requests/DeidentifyAudioRequest.ts | 47 + .../requests/DeidentifyDocumentRequest.ts | 35 + .../client/requests/DeidentifyFileRequest.ts | 35 + .../client/requests/DeidentifyImageRequest.ts | 41 + .../client/requests/DeidentifyPdfRequest.ts | 39 + .../requests/DeidentifyPresentationRequest.ts | 35 + .../requests/DeidentifySpreadsheetRequest.ts | 35 + .../DeidentifyStructuredTextRequest.ts | 35 + .../client/requests/DeidentifyTextRequest.ts | 35 + .../files/client/requests/GetRunRequest.ts | 28 + .../resources/files/client/requests/index.ts | 10 + .../rest/api/resources/files/index.ts | 2 + .../files/types/DeidentifyAudioRequestFile.ts | 15 + .../DeidentifyAudioRequestFileDataFormat.ts | 12 + ...identifyAudioRequestOutputTranscription.ts | 20 + .../types/DeidentifyDocumentRequestFile.ts | 15 + ...DeidentifyDocumentRequestFileDataFormat.ts | 13 + .../files/types/DeidentifyFileRequestFile.ts | 15 + .../DeidentifyFileRequestFileDataFormat.ts | 48 + .../files/types/DeidentifyImageRequestFile.ts | 15 + .../DeidentifyImageRequestFileDataFormat.ts | 16 + .../DeidentifyImageRequestMaskingMethod.ts | 12 + .../files/types/DeidentifyPdfRequestFile.ts | 13 + .../DeidentifyPresentationRequestFile.ts | 15 + ...entifyPresentationRequestFileDataFormat.ts | 12 + .../types/DeidentifySpreadsheetRequestFile.ts | 15 + ...dentifySpreadsheetRequestFileDataFormat.ts | 13 + .../DeidentifyStructuredTextRequestFile.ts | 15 + ...tifyStructuredTextRequestFileDataFormat.ts | 12 + .../files/types/DeidentifyTextRequestFile.ts | 13 + .../rest/api/resources/files/types/index.ts | 18 + src/ _generated_/rest/api/resources/index.ts | 8 + .../rest/api/resources/query/client/Client.ts | 5 +- .../api/resources/records/client/Client.ts | 50 +- .../api/resources/strings/client/Client.ts | 277 +++++ .../api/resources/strings/client/index.ts | 1 + .../requests/DeidentifyStringRequest.ts | 72 ++ .../requests/ReidentifyStringRequest.ts | 21 + .../strings/client/requests/index.ts | 2 + .../rest/api/resources/strings/index.ts | 2 + .../types/ReidentifyStringRequestFormat.ts | 17 + .../rest/api/resources/strings/types/index.ts | 1 + .../api/resources/tokens/client/Client.ts | 10 +- .../api/types/AdvancedOptionsColumnMapping.ts | 17 + .../types/AdvancedOptionsEntityColumnMap.ts | 14 + .../api/types/AdvancedOptionsVaultSchema.ts | 14 + src/ _generated_/rest/api/types/AllowRegex.ts | 8 + .../api/types/AudioConfigTranscriptionType.ts | 41 + .../rest/api/types/DeidentifyFileOutput.ts | 17 + .../DeidentifyFileOutputProcessedFileType.ts | 30 + .../rest/api/types/DeidentifyFileResponse.ts | 11 + .../api/types/DeidentifyStatusResponse.ts | 31 + .../DeidentifyStatusResponseOutputType.ts | 12 + .../types/DeidentifyStatusResponseStatus.ts | 13 + .../api/types/DeidentifyStringResponse.ts | 19 + .../rest/api/types/DetectDataAccuracy.ts | 35 + .../rest/api/types/DetectDataEntities.ts | 200 +++ .../api/types/DetectFileRequestDataType.ts | 15 + .../types/DetectRequestDeidentifyOption.ts | 17 + .../rest/api/types/DetectedEntity.ts | 20 + .../rest/api/types/EntityLocation.ts | 17 + src/ _generated_/rest/api/types/EntityType.ts | 136 ++ .../rest/api/types/EntityTypes.ts | 10 + .../rest/api/types/ErrorResponse.ts | 9 + .../rest/api/types/ErrorResponseError.ts | 14 + .../rest/api/types/ErrorString.ts | 8 + .../ProcessedFileOutputProcessedFileType.ts | 41 + .../api/types/ReidentifyStringResponse.ts | 11 + src/ _generated_/rest/api/types/ResourceId.ts | 8 + .../rest/api/types/RestrictRegex.ts | 8 + src/ _generated_/rest/api/types/TokenType.ts | 18 + .../rest/api/types/TokenTypeDefault.ts | 10 + .../rest/api/types/TokenTypeWithoutVault.ts | 16 + .../api/types/TokenTypeWithoutVaultDefault.ts | 9 + .../rest/api/types/Transformations.ts | 13 + .../api/types/TransformationsShiftDates.ts | 17 + ...ransformationsShiftDatesEntityTypesItem.ts | 10 + src/ _generated_/rest/api/types/Uuid.ts | 8 + .../rest/api/types/V1AdvancedOptions.ts | 16 + .../rest/api/types/V1AudioConfig.ts | 15 + .../rest/api/types/V1AudioOptions.ts | 19 + .../rest/api/types/V1DetectFileResponse.ts | 11 + .../rest/api/types/V1DetectStatusResponse.ts | 16 + .../api/types/V1DetectStatusResponseStatus.ts | 19 + .../rest/api/types/V1DetectTextRequest.ts | 30 + .../rest/api/types/V1DetectTextResponse.ts | 15 + .../rest/api/types/V1FileDataFormat.ts | 68 + .../rest/api/types/V1ImageOptions.ts | 13 + .../rest/api/types/V1Locations.ts | 17 + .../rest/api/types/V1PdfConfig.ts | 12 + .../rest/api/types/V1PdfOptions.ts | 13 + .../rest/api/types/V1ProcessedFileOutput.ts | 15 + .../rest/api/types/V1ResponseEntities.ts | 20 + src/ _generated_/rest/api/types/VaultId.ts | 8 + src/ _generated_/rest/api/types/index.ts | 51 + src/error/codes/index.ts | 35 + src/error/messages/index.ts | 41 + src/index.ts | 32 +- src/utils/index.ts | 106 ++ src/utils/logs/index.ts | 9 +- src/utils/validations/index.ts | 173 +++ src/vault/client/index.ts | 12 + src/vault/controller/detect/index.ts | 637 +++++++++- src/vault/controller/vault/index.ts | 1 - .../deidentify-file/bleep-audio/index.ts | 31 + .../model/options/deidentify-file/index.ts | 155 +++ .../model/options/deidentify-text/index.ts | 56 + .../deidentify-text/token-format/index.ts | 45 + .../deidentify-text/transformations/index.ts | 22 + .../model/options/reidentify-text/index.ts | 36 + .../model/request/deidentify-file/index.ts | 17 + .../model/request/deidentify-text/index.ts | 21 + .../model/request/reidentify-text/index.ts | 21 + .../model/response/deidentify-file/index.ts | 64 + .../model/response/deidentify-text/index.ts | 44 + .../model/response/reidentify-text/index.ts | 16 + src/vault/skyflow/index.ts | 53 +- src/vault/types/index.ts | 5 +- test/vault/client/client.test.js | 7 + test/vault/controller/detect.test.js | 768 ++++++++++++ test/vault/controller/vault.test.js | 8 - test/vault/skyflow/skyflow.test.js | 75 ++ 142 files changed, 6405 insertions(+), 162 deletions(-) create mode 100644 src/ _generated_/rest/api/errors/InternalServerError.ts create mode 100644 src/ _generated_/rest/api/resources/deprecated/client/Client.ts create mode 100644 src/ _generated_/rest/api/resources/deprecated/client/index.ts create mode 100644 src/ _generated_/rest/api/resources/deprecated/client/requests/DetectServiceDetectStatusRequest.ts create mode 100644 src/ _generated_/rest/api/resources/deprecated/client/requests/DetectServiceDetectTextRequest.ts create mode 100644 src/ _generated_/rest/api/resources/deprecated/client/requests/V1DetectFileRequest.ts create mode 100644 src/ _generated_/rest/api/resources/deprecated/client/requests/index.ts create mode 100644 src/ _generated_/rest/api/resources/deprecated/index.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/Client.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/index.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifyAudioRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifyDocumentRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifyFileRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifyImageRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifyPdfRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifyPresentationRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifySpreadsheetRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifyStructuredTextRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/DeidentifyTextRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/GetRunRequest.ts create mode 100644 src/ _generated_/rest/api/resources/files/client/requests/index.ts create mode 100644 src/ _generated_/rest/api/resources/files/index.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestFileDataFormat.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestOutputTranscription.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyDocumentRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyDocumentRequestFileDataFormat.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyFileRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyFileRequestFileDataFormat.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestFileDataFormat.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestMaskingMethod.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyPdfRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyPresentationRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyPresentationRequestFileDataFormat.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifySpreadsheetRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifySpreadsheetRequestFileDataFormat.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyStructuredTextRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyStructuredTextRequestFileDataFormat.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/DeidentifyTextRequestFile.ts create mode 100644 src/ _generated_/rest/api/resources/files/types/index.ts create mode 100644 src/ _generated_/rest/api/resources/strings/client/Client.ts create mode 100644 src/ _generated_/rest/api/resources/strings/client/index.ts create mode 100644 src/ _generated_/rest/api/resources/strings/client/requests/DeidentifyStringRequest.ts create mode 100644 src/ _generated_/rest/api/resources/strings/client/requests/ReidentifyStringRequest.ts create mode 100644 src/ _generated_/rest/api/resources/strings/client/requests/index.ts create mode 100644 src/ _generated_/rest/api/resources/strings/index.ts create mode 100644 src/ _generated_/rest/api/resources/strings/types/ReidentifyStringRequestFormat.ts create mode 100644 src/ _generated_/rest/api/resources/strings/types/index.ts create mode 100644 src/ _generated_/rest/api/types/AdvancedOptionsColumnMapping.ts create mode 100644 src/ _generated_/rest/api/types/AdvancedOptionsEntityColumnMap.ts create mode 100644 src/ _generated_/rest/api/types/AdvancedOptionsVaultSchema.ts create mode 100644 src/ _generated_/rest/api/types/AllowRegex.ts create mode 100644 src/ _generated_/rest/api/types/AudioConfigTranscriptionType.ts create mode 100644 src/ _generated_/rest/api/types/DeidentifyFileOutput.ts create mode 100644 src/ _generated_/rest/api/types/DeidentifyFileOutputProcessedFileType.ts create mode 100644 src/ _generated_/rest/api/types/DeidentifyFileResponse.ts create mode 100644 src/ _generated_/rest/api/types/DeidentifyStatusResponse.ts create mode 100644 src/ _generated_/rest/api/types/DeidentifyStatusResponseOutputType.ts create mode 100644 src/ _generated_/rest/api/types/DeidentifyStatusResponseStatus.ts create mode 100644 src/ _generated_/rest/api/types/DeidentifyStringResponse.ts create mode 100644 src/ _generated_/rest/api/types/DetectDataAccuracy.ts create mode 100644 src/ _generated_/rest/api/types/DetectDataEntities.ts create mode 100644 src/ _generated_/rest/api/types/DetectFileRequestDataType.ts create mode 100644 src/ _generated_/rest/api/types/DetectRequestDeidentifyOption.ts create mode 100644 src/ _generated_/rest/api/types/DetectedEntity.ts create mode 100644 src/ _generated_/rest/api/types/EntityLocation.ts create mode 100644 src/ _generated_/rest/api/types/EntityType.ts create mode 100644 src/ _generated_/rest/api/types/EntityTypes.ts create mode 100644 src/ _generated_/rest/api/types/ErrorResponse.ts create mode 100644 src/ _generated_/rest/api/types/ErrorResponseError.ts create mode 100644 src/ _generated_/rest/api/types/ErrorString.ts create mode 100644 src/ _generated_/rest/api/types/ProcessedFileOutputProcessedFileType.ts create mode 100644 src/ _generated_/rest/api/types/ReidentifyStringResponse.ts create mode 100644 src/ _generated_/rest/api/types/ResourceId.ts create mode 100644 src/ _generated_/rest/api/types/RestrictRegex.ts create mode 100644 src/ _generated_/rest/api/types/TokenType.ts create mode 100644 src/ _generated_/rest/api/types/TokenTypeDefault.ts create mode 100644 src/ _generated_/rest/api/types/TokenTypeWithoutVault.ts create mode 100644 src/ _generated_/rest/api/types/TokenTypeWithoutVaultDefault.ts create mode 100644 src/ _generated_/rest/api/types/Transformations.ts create mode 100644 src/ _generated_/rest/api/types/TransformationsShiftDates.ts create mode 100644 src/ _generated_/rest/api/types/TransformationsShiftDatesEntityTypesItem.ts create mode 100644 src/ _generated_/rest/api/types/Uuid.ts create mode 100644 src/ _generated_/rest/api/types/V1AdvancedOptions.ts create mode 100644 src/ _generated_/rest/api/types/V1AudioConfig.ts create mode 100644 src/ _generated_/rest/api/types/V1AudioOptions.ts create mode 100644 src/ _generated_/rest/api/types/V1DetectFileResponse.ts create mode 100644 src/ _generated_/rest/api/types/V1DetectStatusResponse.ts create mode 100644 src/ _generated_/rest/api/types/V1DetectStatusResponseStatus.ts create mode 100644 src/ _generated_/rest/api/types/V1DetectTextRequest.ts create mode 100644 src/ _generated_/rest/api/types/V1DetectTextResponse.ts create mode 100644 src/ _generated_/rest/api/types/V1FileDataFormat.ts create mode 100644 src/ _generated_/rest/api/types/V1ImageOptions.ts create mode 100644 src/ _generated_/rest/api/types/V1Locations.ts create mode 100644 src/ _generated_/rest/api/types/V1PdfConfig.ts create mode 100644 src/ _generated_/rest/api/types/V1PdfOptions.ts create mode 100644 src/ _generated_/rest/api/types/V1ProcessedFileOutput.ts create mode 100644 src/ _generated_/rest/api/types/V1ResponseEntities.ts create mode 100644 src/ _generated_/rest/api/types/VaultId.ts create mode 100644 src/vault/model/options/deidentify-file/bleep-audio/index.ts create mode 100644 src/vault/model/options/deidentify-file/index.ts create mode 100644 src/vault/model/options/deidentify-text/index.ts create mode 100644 src/vault/model/options/deidentify-text/token-format/index.ts create mode 100644 src/vault/model/options/deidentify-text/transformations/index.ts create mode 100644 src/vault/model/options/reidentify-text/index.ts create mode 100644 src/vault/model/request/deidentify-file/index.ts create mode 100644 src/vault/model/request/deidentify-text/index.ts create mode 100644 src/vault/model/request/reidentify-text/index.ts create mode 100644 src/vault/model/response/deidentify-file/index.ts create mode 100644 src/vault/model/response/deidentify-text/index.ts create mode 100644 src/vault/model/response/reidentify-text/index.ts create mode 100644 test/vault/controller/detect.test.js diff --git a/package-lock.json b/package-lock.json index 80f07f65..933ac9f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,15 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.3-dev.197a956", + "version": "2.0.0-beta.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "skyflow-node", - "version": "2.0.0-beta.3-dev.197a956", + "version": "2.0.0-beta.4", "license": "MIT", "dependencies": { + "@babel/runtime": "^7.27.1", "dotenv": "^16.4.5", "form-data": "^4.0.0", "form-data-encoder": "^4.0.2", @@ -73,9 +74,9 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.27.1.tgz", - "integrity": "sha512-Q+E+rd/yBzNQhXkG+zQnF58e4zoZfBedaxwzPmicKsiK3nt8iJYrSrDbjwFFDGC4f+rPafqRaPH6TsDoSvMf7A==", + "version": "7.27.2", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.27.2.tgz", + "integrity": "sha512-TUtMJYRPyUb/9aU8f3K0mjmjf6M9N5Woshn2CS6nqJSeJtTtQcpLUXjGt9vbF8ZGff0El99sWkLgzwW3VXnxZQ==", "dev": true, "license": "MIT", "engines": { @@ -144,13 +145,13 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.27.1.tgz", - "integrity": "sha512-2YaDd/Rd9E598B5+WIc8wJPmWETiiJXFYVE60oX8FDohv7rAUU3CQj+A1MgeEmcsk2+dQuEjIe/GDvig0SqL4g==", + "version": "7.27.2", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.27.2.tgz", + "integrity": "sha512-2+1thGUUWWjLTYTHZWK1n8Yga0ijBz1XAhUXcKy81rd5g6yh7hGqMp45v7cadSbEHc9G3OTv45SyneRN3ps4DQ==", "dev": true, "license": "MIT", "dependencies": { - "@babel/compat-data": "^7.27.1", + "@babel/compat-data": "^7.27.2", "@babel/helper-validator-option": "^7.27.1", "browserslist": "^4.24.0", "lru-cache": "^5.1.1", @@ -396,9 +397,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.1.tgz", - "integrity": "sha512-I0dZ3ZpCrJ1c04OqlNsQcKiZlsrXf/kkE4FXzID9rIOYICsAbA8mMDzhW/luRNAHdCNt7os/u8wenklZDlUVUQ==", + "version": "7.27.2", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.2.tgz", + "integrity": "sha512-QYLs8299NA7WM/bZAdp+CviYYkVoYXlDW2rzliy3chxd1PQjej7JORuMJDJXJUb9g0TT+B99EwaVLKmX+sPXWw==", "dev": true, "license": "MIT", "dependencies": { @@ -1335,14 +1336,15 @@ } }, "node_modules/@babel/plugin-transform-object-rest-spread": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-rest-spread/-/plugin-transform-object-rest-spread-7.27.1.tgz", - "integrity": "sha512-/sSliVc9gHE20/7D5qsdGlq7RG5NCDTWsAhyqzGuq174EtWJoGzIu1BQ7G56eDsTcy1jseBZwv50olSdXOlGuA==", + "version": "7.27.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-rest-spread/-/plugin-transform-object-rest-spread-7.27.2.tgz", + "integrity": "sha512-AIUHD7xJ1mCrj3uPozvtngY3s0xpv7Nu7DoUSnzNY6Xam1Cy4rUznR//pvMHOhQ4AvbCexhbqXCtpxGHOGOO6g==", "dev": true, "license": "MIT", "dependencies": { - "@babel/helper-compilation-targets": "^7.27.1", + "@babel/helper-compilation-targets": "^7.27.2", "@babel/helper-plugin-utils": "^7.27.1", + "@babel/plugin-transform-destructuring": "^7.27.1", "@babel/plugin-transform-parameters": "^7.27.1" }, "engines": { @@ -1708,14 +1710,14 @@ } }, "node_modules/@babel/preset-env": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.27.1.tgz", - "integrity": "sha512-TZ5USxFpLgKDpdEt8YWBR7p6g+bZo6sHaXLqP2BY/U0acaoI8FTVflcYCr/v94twM1C5IWFdZ/hscq9WjUeLXA==", + "version": "7.27.2", + "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.27.2.tgz", + "integrity": "sha512-Ma4zSuYSlGNRlCLO+EAzLnCmJK2vdstgv+n7aUP+/IKZrOfWHOJVdSJtuub8RzHTj3ahD37k5OKJWvzf16TQyQ==", "dev": true, "license": "MIT", "dependencies": { - "@babel/compat-data": "^7.27.1", - "@babel/helper-compilation-targets": "^7.27.1", + "@babel/compat-data": "^7.27.2", + "@babel/helper-compilation-targets": "^7.27.2", "@babel/helper-plugin-utils": "^7.27.1", "@babel/helper-validator-option": "^7.27.1", "@babel/plugin-bugfix-firefox-class-in-computed-class-key": "^7.27.1", @@ -1757,7 +1759,7 @@ "@babel/plugin-transform-new-target": "^7.27.1", "@babel/plugin-transform-nullish-coalescing-operator": "^7.27.1", "@babel/plugin-transform-numeric-separator": "^7.27.1", - "@babel/plugin-transform-object-rest-spread": "^7.27.1", + "@babel/plugin-transform-object-rest-spread": "^7.27.2", "@babel/plugin-transform-object-super": "^7.27.1", "@babel/plugin-transform-optional-catch-binding": "^7.27.1", "@babel/plugin-transform-optional-chaining": "^7.27.1", @@ -1826,15 +1828,24 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/template": { + "node_modules/@babel/runtime": { "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.1.tgz", - "integrity": "sha512-Fyo3ghWMqkHHpHQCoBs2VnYjR4iWFFjguTDEqA5WgZDOrFesVjMhMM2FSqTKSoUSDO1VQtavj8NFpdRBEvJTtg==", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.27.1.tgz", + "integrity": "sha512-1x3D2xEk2fRo3PAhwQwu5UubzgiVWSXTBfWpVd2Mx2AzRqJuDJCsgaDVZ7HB5iGzDW1Hl1sWN2mFyKjmR9uAog==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/template": { + "version": "7.27.2", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.2.tgz", + "integrity": "sha512-LPDZ85aEJyYSd18/DkjNh4/y1ntkE5KwUHWTiqgRxruuZL2F1yuHligVHLvcHY2vMHXttKFpJn6LwfI7cw7ODw==", "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.27.1", - "@babel/parser": "^7.27.1", + "@babel/parser": "^7.27.2", "@babel/types": "^7.27.1" }, "engines": { @@ -2461,9 +2472,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "18.19.96", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.96.tgz", - "integrity": "sha512-PzBvgsZ7YdFs/Kng1BSW8IGv68/SPcOxYYhT7luxD7QyzIhFS1xPTpfK3K9eHBa7hVwlW+z8nN0mOd515yaduQ==", + "version": "18.19.100", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.100.tgz", + "integrity": "sha512-ojmMP8SZBKprc3qGrGk8Ujpo80AXkrP7G2tOT4VWr5jlr5DHjsJF+emXJz+Wm0glmy4Js62oKMdZZ6B9Y+tEcA==", "dev": true, "license": "MIT", "dependencies": { @@ -3665,9 +3676,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.150", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.150.tgz", - "integrity": "sha512-rOOkP2ZUMx1yL4fCxXQKDHQ8ZXwisb2OycOQVKHgvB3ZI4CvehOd4y2tfnnLDieJ3Zs1RL1Dlp3cMkyIn7nnXA==", + "version": "1.5.151", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.151.tgz", + "integrity": "sha512-Rl6uugut2l9sLojjS4H4SAr3A4IgACMLgpuEMPYCVcKydzfyPrn5absNRju38IhQOf/NwjJY8OGWjlteqYeBCA==", "dev": true, "license": "ISC" }, @@ -5409,12 +5420,12 @@ } }, "node_modules/jwa": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", - "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.2.tgz", + "integrity": "sha512-eeH5JO+21J78qMvTIDdBXidBd6nG2kZjg5Ohz/1fpa28Z4CcsWUzJ1ZZyFq/3z3N17aZy+ZuBoHljASbL1WfOw==", "license": "MIT", "dependencies": { - "buffer-equal-constant-time": "1.0.1", + "buffer-equal-constant-time": "^1.0.1", "ecdsa-sig-formatter": "1.0.11", "safe-buffer": "^5.0.1" } @@ -7158,9 +7169,9 @@ } }, "node_modules/webpack": { - "version": "5.99.7", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.99.7.tgz", - "integrity": "sha512-CNqKBRMQjwcmKR0idID5va1qlhrqVUKpovi+Ec79ksW8ux7iS1+A6VqzfZXgVYCFRKl7XL5ap3ZoMpwBJxcg0w==", + "version": "5.99.8", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.99.8.tgz", + "integrity": "sha512-lQ3CPiSTpfOnrEGeXDwoq5hIGzSjmwD72GdfVzF7CQAI7t47rJG9eDWvcEkEn3CUQymAElVvDg3YNTlCYj+qUQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index aff04994..84ccf4df 100644 --- a/package.json +++ b/package.json @@ -32,17 +32,18 @@ "tokenization" ], "dependencies": { + "@babel/runtime": "^7.27.1", "dotenv": "^16.4.5", - "jsonwebtoken": "^9.0.2", - "jwt-decode": "^2.2.0", - "url-join": "4.0.1", "form-data": "^4.0.0", + "form-data-encoder": "^4.0.2", "formdata-node": "^6.0.3", + "js-base64": "3.7.7", + "jsonwebtoken": "^9.0.2", + "jwt-decode": "^2.2.0", "node-fetch": "^2.7.0", "qs": "^6.13.1", "readable-stream": "^4.5.2", - "js-base64": "3.7.7", - "form-data-encoder": "^4.0.2" + "url-join": "4.0.1" }, "devDependencies": { "@babel/plugin-proposal-decorators": "^7.25.7", @@ -50,19 +51,19 @@ "@babel/plugin-transform-runtime": "^7.25.7", "@babel/preset-env": "^7.25.8", "@babel/preset-typescript": "^7.25.7", + "@types/jest": "^29.5.14", "@types/jsonwebtoken": "^9.0.6", "@types/node": "^18.19.70", - "jest": "^29.7.0", - "ts-jest": "^29.1.1", - "typescript": "~5.7.2", - "@types/url-join": "4.0.1", - "@types/qs": "^6.9.17", "@types/node-fetch": "^2.6.12", + "@types/qs": "^6.9.17", "@types/readable-stream": "^4.0.18", - "webpack": "^5.97.1", - "ts-loader": "^9.5.1", - "@types/jest": "^29.5.14", + "@types/url-join": "4.0.1", + "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", - "prettier": "^3.4.2" + "prettier": "^3.4.2", + "ts-jest": "^29.1.1", + "ts-loader": "^9.5.1", + "typescript": "~5.7.2", + "webpack": "^5.97.1" } } diff --git a/src/ _generated_/rest/Client.ts b/src/ _generated_/rest/Client.ts index ebbf651b..0ca90c4e 100644 --- a/src/ _generated_/rest/Client.ts +++ b/src/ _generated_/rest/Client.ts @@ -10,6 +10,9 @@ import { Records } from "./api/resources/records/client/Client"; import { Tokens } from "./api/resources/tokens/client/Client"; import { Query } from "./api/resources/query/client/Client"; import { Authentication } from "./api/resources/authentication/client/Client"; +import { Deprecated } from "./api/resources/deprecated/client/Client"; +import { Strings } from "./api/resources/strings/client/Client"; +import { Files } from "./api/resources/files/client/Client"; export declare namespace SkyflowClient { export interface Options { @@ -39,6 +42,9 @@ export class SkyflowClient { protected _tokens: Tokens | undefined; protected _query: Query | undefined; protected _authentication: Authentication | undefined; + protected _deprecated: Deprecated | undefined; + protected _strings: Strings | undefined; + protected _files: Files | undefined; constructor(protected readonly _options: SkyflowClient.Options) {} @@ -65,4 +71,16 @@ export class SkyflowClient { public get authentication(): Authentication { return (this._authentication ??= new Authentication(this._options)); } + + public get deprecated(): Deprecated { + return (this._deprecated ??= new Deprecated(this._options)); + } + + public get strings(): Strings { + return (this._strings ??= new Strings(this._options)); + } + + public get files(): Files { + return (this._files ??= new Files(this._options)); + } } diff --git a/src/ _generated_/rest/api/errors/BadRequestError.ts b/src/ _generated_/rest/api/errors/BadRequestError.ts index e19131a1..1776da9a 100644 --- a/src/ _generated_/rest/api/errors/BadRequestError.ts +++ b/src/ _generated_/rest/api/errors/BadRequestError.ts @@ -6,7 +6,7 @@ import * as errors from "../../errors/index"; import * as core from "../../core"; export class BadRequestError extends errors.SkyflowError { - constructor(body: Record, rawResponse?: core.RawResponse) { + constructor(body?: unknown, rawResponse?: core.RawResponse) { super({ message: "BadRequestError", statusCode: 400, diff --git a/src/ _generated_/rest/api/errors/InternalServerError.ts b/src/ _generated_/rest/api/errors/InternalServerError.ts new file mode 100644 index 00000000..4141147e --- /dev/null +++ b/src/ _generated_/rest/api/errors/InternalServerError.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as errors from "../../errors/index"; +import * as Skyflow from "../index"; +import * as core from "../../core"; + +export class InternalServerError extends errors.SkyflowError { + constructor(body: Skyflow.ErrorResponse, rawResponse?: core.RawResponse) { + super({ + message: "InternalServerError", + statusCode: 500, + body: body, + rawResponse: rawResponse, + }); + Object.setPrototypeOf(this, InternalServerError.prototype); + } +} diff --git a/src/ _generated_/rest/api/errors/NotFoundError.ts b/src/ _generated_/rest/api/errors/NotFoundError.ts index ff59e84a..357bc100 100644 --- a/src/ _generated_/rest/api/errors/NotFoundError.ts +++ b/src/ _generated_/rest/api/errors/NotFoundError.ts @@ -6,7 +6,7 @@ import * as errors from "../../errors/index"; import * as core from "../../core"; export class NotFoundError extends errors.SkyflowError { - constructor(body: Record, rawResponse?: core.RawResponse) { + constructor(body?: unknown, rawResponse?: core.RawResponse) { super({ message: "NotFoundError", statusCode: 404, diff --git a/src/ _generated_/rest/api/errors/UnauthorizedError.ts b/src/ _generated_/rest/api/errors/UnauthorizedError.ts index 73c2b114..5dc2279b 100644 --- a/src/ _generated_/rest/api/errors/UnauthorizedError.ts +++ b/src/ _generated_/rest/api/errors/UnauthorizedError.ts @@ -6,7 +6,7 @@ import * as errors from "../../errors/index"; import * as core from "../../core"; export class UnauthorizedError extends errors.SkyflowError { - constructor(body: Record, rawResponse?: core.RawResponse) { + constructor(body?: unknown, rawResponse?: core.RawResponse) { super({ message: "UnauthorizedError", statusCode: 401, diff --git a/src/ _generated_/rest/api/errors/index.ts b/src/ _generated_/rest/api/errors/index.ts index f88b64db..07acead1 100644 --- a/src/ _generated_/rest/api/errors/index.ts +++ b/src/ _generated_/rest/api/errors/index.ts @@ -1,3 +1,4 @@ export * from "./NotFoundError"; export * from "./BadRequestError"; export * from "./UnauthorizedError"; +export * from "./InternalServerError"; diff --git a/src/ _generated_/rest/api/resources/audit/client/Client.ts b/src/ _generated_/rest/api/resources/audit/client/Client.ts index 89b42416..a184cd0a 100644 --- a/src/ _generated_/rest/api/resources/audit/client/Client.ts +++ b/src/ _generated_/rest/api/resources/audit/client/Client.ts @@ -253,10 +253,7 @@ export class Audit { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, diff --git a/src/ _generated_/rest/api/resources/authentication/client/Client.ts b/src/ _generated_/rest/api/resources/authentication/client/Client.ts index 7c3b0039..63edf19c 100644 --- a/src/ _generated_/rest/api/resources/authentication/client/Client.ts +++ b/src/ _generated_/rest/api/resources/authentication/client/Client.ts @@ -91,20 +91,11 @@ export class Authentication { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: - throw new Skyflow.BadRequestError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); case 401: - throw new Skyflow.UnauthorizedError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, diff --git a/src/ _generated_/rest/api/resources/binLookup/client/Client.ts b/src/ _generated_/rest/api/resources/binLookup/client/Client.ts index 2a88056a..f25ff9d6 100644 --- a/src/ _generated_/rest/api/resources/binLookup/client/Client.ts +++ b/src/ _generated_/rest/api/resources/binLookup/client/Client.ts @@ -88,10 +88,7 @@ export class BinLookup { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, diff --git a/src/ _generated_/rest/api/resources/deprecated/client/Client.ts b/src/ _generated_/rest/api/resources/deprecated/client/Client.ts new file mode 100644 index 00000000..77006f92 --- /dev/null +++ b/src/ _generated_/rest/api/resources/deprecated/client/Client.ts @@ -0,0 +1,305 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments"; +import * as core from "../../../../core"; +import * as Skyflow from "../../../index"; +import urlJoin from "url-join"; +import * as errors from "../../../../errors/index"; + +export declare namespace Deprecated { + export interface Options { + environment?: core.Supplier; + /** Specify a custom URL to connect the client to. */ + baseUrl?: core.Supplier; + token: core.Supplier; + fetcher?: core.FetchFunction; + } + + export interface RequestOptions { + /** The maximum time to wait for a response in seconds. */ + timeoutInSeconds?: number; + /** The number of times to retry the request. Defaults to 2. */ + maxRetries?: number; + /** A hook to abort the request. */ + abortSignal?: AbortSignal; + /** Additional headers to include in the request. */ + headers?: Record; + } +} + +export class Deprecated { + constructor(protected readonly _options: Deprecated.Options) {} + + /** + * Note: This operation is deprecated. Use one of the De-identify File operations.

Detects and deidentifies sensitive data from image, audio, and video files. + * + * @param {Skyflow.V1DetectFileRequest} request + * @param {Deprecated.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.NotFoundError} + * + * @example + * await client.deprecated.detectServiceDetectFileInput({ + * file: "fkdjfhdlnnggtsjj...", + * data_format: "mp3", + * input_type: "BASE64", + * vault_id: "a372f752689c9bfc8ca3d4dba", + * restrict_entity_types: ["name", "age", "location", "ssn", "bank_account", "credit_card", "credit_card_expiration", "cvv", "date", "date_interval", "dob", "driver_license", "email_address", "healthcare_number", "numerical_pii", "phone_number", "medical_code", "account_number", "gender_sexuality", "name_medical_professional", "occupation", "organization", "organization_medical_facility"], + * return_entities: true, + * accuracy: "high_multilingual", + * audio: { + * output_transcription: "none", + * output_processed_audio: false + * } + * }) + */ + public detectServiceDetectFileInput( + request: Skyflow.V1DetectFileRequest, + requestOptions?: Deprecated.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__detectServiceDetectFileInput(request, requestOptions)); + } + + private async __detectServiceDetectFileInput( + request: Skyflow.V1DetectFileRequest, + requestOptions?: Deprecated.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/file", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.V1DetectFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 404: + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError("Timeout exceeded when calling POST /v1/detect/file."); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Note: This operation is deprecated. Use Get Detect Run.

Returns the status of a file deidentification request. + * + * @param {string} id - ID of the deidentification request. + * @param {Skyflow.DetectServiceDetectStatusRequest} request + * @param {Deprecated.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.NotFoundError} + * + * @example + * await client.deprecated.detectServiceDetectStatus("ID") + */ + public detectServiceDetectStatus( + id: string, + request: Skyflow.DetectServiceDetectStatusRequest = {}, + requestOptions?: Deprecated.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__detectServiceDetectStatus(id, request, requestOptions)); + } + + private async __detectServiceDetectStatus( + id: string, + request: Skyflow.DetectServiceDetectStatusRequest = {}, + requestOptions?: Deprecated.RequestOptions, + ): Promise> { + const { vault_id: vaultId } = request; + const _queryParams: Record = {}; + if (vaultId != null) { + _queryParams["vault_id"] = vaultId; + } + + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + `v1/detect/status/${encodeURIComponent(id)}`, + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + queryParameters: _queryParams, + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.V1DetectStatusResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 404: + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError("Timeout exceeded when calling GET /v1/detect/status/{ID}."); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Note: This operation is deprecated. Use De-identify String.

Detects and deidentifies sensitive data from text. + * + * @param {Skyflow.DetectServiceDetectTextRequest} request + * @param {Deprecated.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.NotFoundError} + * + * @example + * await client.deprecated.detectServiceDetectText({ + * text: "text", + * vault_id: "c848741aefb74bf38780da5399a76507" + * }) + */ + public detectServiceDetectText( + request: Skyflow.DetectServiceDetectTextRequest, + requestOptions?: Deprecated.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__detectServiceDetectText(request, requestOptions)); + } + + private async __detectServiceDetectText( + request: Skyflow.DetectServiceDetectTextRequest, + requestOptions?: Deprecated.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/text", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.V1DetectTextResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 404: + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError("Timeout exceeded when calling POST /v1/detect/text."); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + protected async _getAuthorizationHeader(): Promise { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/ _generated_/rest/api/resources/deprecated/client/index.ts b/src/ _generated_/rest/api/resources/deprecated/client/index.ts new file mode 100644 index 00000000..415726b7 --- /dev/null +++ b/src/ _generated_/rest/api/resources/deprecated/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/ _generated_/rest/api/resources/deprecated/client/requests/DetectServiceDetectStatusRequest.ts b/src/ _generated_/rest/api/resources/deprecated/client/requests/DetectServiceDetectStatusRequest.ts new file mode 100644 index 00000000..aa322f8e --- /dev/null +++ b/src/ _generated_/rest/api/resources/deprecated/client/requests/DetectServiceDetectStatusRequest.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * @example + * {} + */ +export interface DetectServiceDetectStatusRequest { + /** + * ID of the vault. + */ + vault_id?: string; +} diff --git a/src/ _generated_/rest/api/resources/deprecated/client/requests/DetectServiceDetectTextRequest.ts b/src/ _generated_/rest/api/resources/deprecated/client/requests/DetectServiceDetectTextRequest.ts new file mode 100644 index 00000000..2ca28786 --- /dev/null +++ b/src/ _generated_/rest/api/resources/deprecated/client/requests/DetectServiceDetectTextRequest.ts @@ -0,0 +1,34 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * text: "text", + * vault_id: "c848741aefb74bf38780da5399a76507" + * } + */ +export interface DetectServiceDetectTextRequest { + /** Data to deidentify. */ + text: string; + /** ID of the vault. */ + vault_id: string; + /** Will give a handle to delete the tokens generated during a specific interaction. */ + session_id?: string; + /** Entities to detect and deidentify. */ + restrict_entity_types?: Skyflow.DetectDataEntities[]; + deidentify_token_format?: Skyflow.DetectRequestDeidentifyOption; + /** Regular expressions to ignore when detecting entities. */ + allow_regex?: string[]; + /** Regular expressions to always restrict. Strings matching these regular expressions are replaced with 'RESTRICTED'. */ + restrict_regex?: string[]; + /** If `true`, returns the details for the detected entities. */ + return_entities?: boolean; + accuracy?: Skyflow.DetectDataAccuracy; + advanced_options?: Skyflow.V1AdvancedOptions; + /** Indicates whether entities should be stored in the vault. */ + store_entities?: boolean; +} diff --git a/src/ _generated_/rest/api/resources/deprecated/client/requests/V1DetectFileRequest.ts b/src/ _generated_/rest/api/resources/deprecated/client/requests/V1DetectFileRequest.ts new file mode 100644 index 00000000..8164b613 --- /dev/null +++ b/src/ _generated_/rest/api/resources/deprecated/client/requests/V1DetectFileRequest.ts @@ -0,0 +1,46 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * file: "fkdjfhdlnnggtsjj...", + * data_format: "mp3", + * input_type: "BASE64", + * vault_id: "a372f752689c9bfc8ca3d4dba", + * restrict_entity_types: ["name", "age", "location", "ssn", "bank_account", "credit_card", "credit_card_expiration", "cvv", "date", "date_interval", "dob", "driver_license", "email_address", "healthcare_number", "numerical_pii", "phone_number", "medical_code", "account_number", "gender_sexuality", "name_medical_professional", "occupation", "organization", "organization_medical_facility"], + * return_entities: true, + * accuracy: "high_multilingual", + * audio: { + * output_transcription: "none", + * output_processed_audio: false + * } + * } + */ +export interface V1DetectFileRequest { + /** Path of the file or base64-encoded data that has to be processed. */ + file: string; + data_format: Skyflow.V1FileDataFormat; + input_type: Skyflow.DetectFileRequestDataType; + /** ID of the vault. */ + vault_id: string; + /** Will give a handle to delete the tokens generated during a specific interaction. */ + session_id?: string; + /** Entities to detect and deidentify. */ + restrict_entity_types?: Skyflow.DetectDataEntities[]; + /** Regular expressions to ignore when detecting entities. */ + allow_regex?: string[]; + /** Regular expressions to always restrict. Strings matching these regular expressions are replaced with 'RESTRICTED'. */ + restrict_regex?: string[]; + /** If `true`, returns the details for the detected entities. */ + return_entities?: boolean; + accuracy?: Skyflow.DetectDataAccuracy; + audio?: Skyflow.V1AudioConfig; + image?: Skyflow.V1ImageOptions; + pdf?: Skyflow.V1PdfConfig; + advanced_options?: Skyflow.V1AdvancedOptions; + deidentify_token_format?: Skyflow.DetectRequestDeidentifyOption; +} diff --git a/src/ _generated_/rest/api/resources/deprecated/client/requests/index.ts b/src/ _generated_/rest/api/resources/deprecated/client/requests/index.ts new file mode 100644 index 00000000..7720b72e --- /dev/null +++ b/src/ _generated_/rest/api/resources/deprecated/client/requests/index.ts @@ -0,0 +1,3 @@ +export { type V1DetectFileRequest } from "./V1DetectFileRequest"; +export { type DetectServiceDetectStatusRequest } from "./DetectServiceDetectStatusRequest"; +export { type DetectServiceDetectTextRequest } from "./DetectServiceDetectTextRequest"; diff --git a/src/ _generated_/rest/api/resources/deprecated/index.ts b/src/ _generated_/rest/api/resources/deprecated/index.ts new file mode 100644 index 00000000..5ec76921 --- /dev/null +++ b/src/ _generated_/rest/api/resources/deprecated/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/ _generated_/rest/api/resources/files/client/Client.ts b/src/ _generated_/rest/api/resources/files/client/Client.ts new file mode 100644 index 00000000..02e6bfca --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/Client.ts @@ -0,0 +1,1100 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments"; +import * as core from "../../../../core"; +import * as Skyflow from "../../../index"; +import urlJoin from "url-join"; +import * as errors from "../../../../errors/index"; + +export declare namespace Files { + export interface Options { + environment?: core.Supplier; + /** Specify a custom URL to connect the client to. */ + baseUrl?: core.Supplier; + token: core.Supplier; + fetcher?: core.FetchFunction; + } + + export interface RequestOptions { + /** The maximum time to wait for a response in seconds. */ + timeoutInSeconds?: number; + /** The number of times to retry the request. Defaults to 2. */ + maxRetries?: number; + /** A hook to abort the request. */ + abortSignal?: AbortSignal; + /** Additional headers to include in the request. */ + headers?: Record; + } +} + +export class Files { + constructor(protected readonly _options: Files.Options) {} + + /** + * De-identifies sensitive data from a file. This operation includes options applicable to all supported file types.

For more specific options, see the category-specific operations (like De-identify Document) and the file type-specific opertions (like De-identify PDF). + * + * @param {Skyflow.DeidentifyFileRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifyFile({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "Zm9vYmFy", + * data_format: "txt" + * } + * }) + * + * @example + * await client.files.deidentifyFile({ + * vault_id: "VAULT_ID", + * file: { + * base64: "Zm9vYmFy", + * data_format: "txt" + * } + * }) + */ + public deidentifyFile( + request: Skyflow.DeidentifyFileRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyFile(request, requestOptions)); + } + + private async __deidentifyFile( + request: Skyflow.DeidentifyFileRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError("Timeout exceeded when calling POST /v1/detect/deidentify/file."); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * De-identifies sensitive data from a document file. This operation includes options applicable to all supported document file types.

For more specific options, see the file type-specific opertions (like De-identify PDF) where they're available. For broader file type support, see De-identify File. + * + * @param {Skyflow.DeidentifyDocumentRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifyDocument({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "docx" + * } + * }) + * + * @example + * await client.files.deidentifyDocument({ + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "docx" + * } + * }) + */ + public deidentifyDocument( + request: Skyflow.DeidentifyDocumentRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyDocument(request, requestOptions)); + } + + private async __deidentifyDocument( + request: Skyflow.DeidentifyDocumentRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file/document", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/file/document.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * De-identifies sensitive data from a PDF file. This operation includes options specific to PDF files.

For broader file type support, see De-identify Document and De-identify File. + * + * @param {Skyflow.DeidentifyPdfRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifyPdf({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "pdf" + * } + * }) + * + * @example + * await client.files.deidentifyPdf({ + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "pdf" + * } + * }) + */ + public deidentifyPdf( + request: Skyflow.DeidentifyPdfRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyPdf(request, requestOptions)); + } + + private async __deidentifyPdf( + request: Skyflow.DeidentifyPdfRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file/document/pdf", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/file/document/pdf.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * De-identifies sensitive data from an image file. This operation includes options applicable to all supported image file types.

For broader file type support, see De-identify File. + * + * @param {Skyflow.DeidentifyImageRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifyImage({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "jpg" + * } + * }) + * + * @example + * await client.files.deidentifyImage({ + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "jpg" + * } + * }) + */ + public deidentifyImage( + request: Skyflow.DeidentifyImageRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyImage(request, requestOptions)); + } + + private async __deidentifyImage( + request: Skyflow.DeidentifyImageRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file/image", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/file/image.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * De-identifies sensitive data from a text file. This operation includes options applicable to all supported image text types.

For broader file type support, see De-identify File. + * + * @param {Skyflow.DeidentifyTextRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifyText({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "Zm9vYmFy", + * data_format: "txt" + * } + * }) + * + * @example + * await client.files.deidentifyText({ + * vault_id: "VAULT_ID", + * file: { + * base64: "Zm9vYmFy", + * data_format: "txt" + * } + * }) + */ + public deidentifyText( + request: Skyflow.DeidentifyTextRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyText(request, requestOptions)); + } + + private async __deidentifyText( + request: Skyflow.DeidentifyTextRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file/text", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/file/text.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * De-identifies sensitive data from a structured text file. This operation includes options applicable to all supported structured text file types.

For broader file type support, see De-identify File. + * + * @param {Skyflow.DeidentifyStructuredTextRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifyStructuredText({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "json" + * } + * }) + * + * @example + * await client.files.deidentifyStructuredText({ + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "json" + * } + * }) + */ + public deidentifyStructuredText( + request: Skyflow.DeidentifyStructuredTextRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyStructuredText(request, requestOptions)); + } + + private async __deidentifyStructuredText( + request: Skyflow.DeidentifyStructuredTextRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file/structured_text", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/file/structured_text.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * De-identifies sensitive data from a spreadsheet file. This operation includes options applicable to all supported spreadsheet file types.

For broader file type support, see De-identify File. + * + * @param {Skyflow.DeidentifySpreadsheetRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifySpreadsheet({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "csv" + * } + * }) + * + * @example + * await client.files.deidentifySpreadsheet({ + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "csv" + * } + * }) + */ + public deidentifySpreadsheet( + request: Skyflow.DeidentifySpreadsheetRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifySpreadsheet(request, requestOptions)); + } + + private async __deidentifySpreadsheet( + request: Skyflow.DeidentifySpreadsheetRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file/spreadsheet", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/file/spreadsheet.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * De-identifies sensitive data from a presentation file. This operation includes options applicable to all supported presentation file types.

For broader file type support, see De-identify File. + * + * @param {Skyflow.DeidentifyPresentationRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifyPresentation({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "pptx" + * } + * }) + * + * @example + * await client.files.deidentifyPresentation({ + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "pptx" + * } + * }) + */ + public deidentifyPresentation( + request: Skyflow.DeidentifyPresentationRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyPresentation(request, requestOptions)); + } + + private async __deidentifyPresentation( + request: Skyflow.DeidentifyPresentationRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file/presentation", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/file/presentation.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * De-identifies sensitive data from an audio file. This operation includes options applicable to all supported audio file types.

For broader file type support, see De-identify File. + * + * @param {Skyflow.DeidentifyAudioRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.deidentifyAudio({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "mp3" + * } + * }) + * + * @example + * await client.files.deidentifyAudio({ + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "mp3" + * } + * }) + */ + public deidentifyAudio( + request: Skyflow.DeidentifyAudioRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyAudio(request, requestOptions)); + } + + private async __deidentifyAudio( + request: Skyflow.DeidentifyAudioRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/file/audio", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyFileResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/file/audio.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Returns the status of the detect run. + * + * @param {Skyflow.Uuid} runId - ID of the detect run. + * @param {Skyflow.GetRunRequest} request + * @param {Files.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.NotFoundError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.files.getRun("run_id", { + * vault_id: "vault_id" + * }) + */ + public getRun( + runId: Skyflow.Uuid, + request: Skyflow.GetRunRequest, + requestOptions?: Files.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getRun(runId, request, requestOptions)); + } + + private async __getRun( + runId: Skyflow.Uuid, + request: Skyflow.GetRunRequest, + requestOptions?: Files.RequestOptions, + ): Promise> { + const { vault_id: vaultId } = request; + const _queryParams: Record = {}; + _queryParams["vault_id"] = vaultId; + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + `v1/detect/runs/${encodeURIComponent(runId)}`, + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + queryParameters: _queryParams, + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyStatusResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError("Timeout exceeded when calling GET /v1/detect/runs/{run_id}."); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + protected async _getAuthorizationHeader(): Promise { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/ _generated_/rest/api/resources/files/client/index.ts b/src/ _generated_/rest/api/resources/files/client/index.ts new file mode 100644 index 00000000..415726b7 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyAudioRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyAudioRequest.ts new file mode 100644 index 00000000..1da9531d --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyAudioRequest.ts @@ -0,0 +1,47 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "mp3" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "mp3" + * } + * } + */ +export interface DeidentifyAudioRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifyAudioRequestFile; + /** If `true`, includes processed audio file in the response. */ + output_processed_audio?: boolean; + /** Type of transcription to output. */ + output_transcription?: Skyflow.DeidentifyAudioRequestOutputTranscription; + /** Relative loudness of the bleep in dB. Positive values increase its loudness, and negative values decrease it. */ + bleep_gain?: number; + /** The pitch of the bleep sound, in Hz. The higher the number, the higher the pitch. */ + bleep_frequency?: number; + /** Padding added to the beginning of a bleep, in seconds. */ + bleep_start_padding?: number; + /** Padding added to the end of a bleep, in seconds. */ + bleep_stop_padding?: number; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyDocumentRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyDocumentRequest.ts new file mode 100644 index 00000000..3b4e7b89 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyDocumentRequest.ts @@ -0,0 +1,35 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "docx" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "docx" + * } + * } + */ +export interface DeidentifyDocumentRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifyDocumentRequestFile; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyFileRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyFileRequest.ts new file mode 100644 index 00000000..4a549f24 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyFileRequest.ts @@ -0,0 +1,35 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "Zm9vYmFy", + * data_format: "txt" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "Zm9vYmFy", + * data_format: "txt" + * } + * } + */ +export interface DeidentifyFileRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifyFileRequestFile; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyImageRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyImageRequest.ts new file mode 100644 index 00000000..f34f70f2 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyImageRequest.ts @@ -0,0 +1,41 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "jpg" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "jpg" + * } + * } + */ +export interface DeidentifyImageRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifyImageRequestFile; + /** If `true`, includes processed image in the output. */ + output_processed_image?: boolean; + /** If `true`, includes OCR text output in the response. */ + output_ocr_text?: boolean; + /** Method to mask the entities in the image. */ + masking_method?: Skyflow.DeidentifyImageRequestMaskingMethod; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyPdfRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyPdfRequest.ts new file mode 100644 index 00000000..0ffcd8fc --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyPdfRequest.ts @@ -0,0 +1,39 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "pdf" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "pdf" + * } + * } + */ +export interface DeidentifyPdfRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifyPdfRequestFile; + /** Pixel density at which to process the PDF file. */ + density?: number; + /** Max resolution at which to process the PDF file. */ + max_resolution?: number; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyPresentationRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyPresentationRequest.ts new file mode 100644 index 00000000..ee660819 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyPresentationRequest.ts @@ -0,0 +1,35 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "pptx" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "pptx" + * } + * } + */ +export interface DeidentifyPresentationRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifyPresentationRequestFile; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifySpreadsheetRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifySpreadsheetRequest.ts new file mode 100644 index 00000000..9560ed75 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifySpreadsheetRequest.ts @@ -0,0 +1,35 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "csv" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "csv" + * } + * } + */ +export interface DeidentifySpreadsheetRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifySpreadsheetRequestFile; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyStructuredTextRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyStructuredTextRequest.ts new file mode 100644 index 00000000..74daccbb --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyStructuredTextRequest.ts @@ -0,0 +1,35 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "SGkgaSBhbSBEZXZhbnNodSwgbGl2...aW5nIGluIGNhbGlmb3JuaWEuIA==", + * data_format: "json" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "BASE64_DATA", + * data_format: "json" + * } + * } + */ +export interface DeidentifyStructuredTextRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifyStructuredTextRequestFile; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyTextRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyTextRequest.ts new file mode 100644 index 00000000..66af6144 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/DeidentifyTextRequest.ts @@ -0,0 +1,35 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * file: { + * base64: "Zm9vYmFy", + * data_format: "txt" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * file: { + * base64: "Zm9vYmFy", + * data_format: "txt" + * } + * } + */ +export interface DeidentifyTextRequest { + vault_id: Skyflow.VaultId; + /** File to de-identify. Files are specified as Base64-encoded data. */ + file: Skyflow.DeidentifyTextRequestFile; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenTypeWithoutVault; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/GetRunRequest.ts b/src/ _generated_/rest/api/resources/files/client/requests/GetRunRequest.ts new file mode 100644 index 00000000..4feb3c84 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/GetRunRequest.ts @@ -0,0 +1,28 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "vault_id" + * } + * + * @example + * { + * vault_id: "vault_id" + * } + * + * @example + * { + * vault_id: "vault_id" + * } + */ +export interface GetRunRequest { + /** + * ID of the vault. + */ + vault_id: Skyflow.ResourceId; +} diff --git a/src/ _generated_/rest/api/resources/files/client/requests/index.ts b/src/ _generated_/rest/api/resources/files/client/requests/index.ts new file mode 100644 index 00000000..d01e1608 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/client/requests/index.ts @@ -0,0 +1,10 @@ +export { type DeidentifyFileRequest } from "./DeidentifyFileRequest"; +export { type DeidentifyDocumentRequest } from "./DeidentifyDocumentRequest"; +export { type DeidentifyPdfRequest } from "./DeidentifyPdfRequest"; +export { type DeidentifyImageRequest } from "./DeidentifyImageRequest"; +export { type DeidentifyTextRequest } from "./DeidentifyTextRequest"; +export { type DeidentifyStructuredTextRequest } from "./DeidentifyStructuredTextRequest"; +export { type DeidentifySpreadsheetRequest } from "./DeidentifySpreadsheetRequest"; +export { type DeidentifyPresentationRequest } from "./DeidentifyPresentationRequest"; +export { type DeidentifyAudioRequest } from "./DeidentifyAudioRequest"; +export { type GetRunRequest } from "./GetRunRequest"; diff --git a/src/ _generated_/rest/api/resources/files/index.ts b/src/ _generated_/rest/api/resources/files/index.ts new file mode 100644 index 00000000..c9240f83 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/index.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./client"; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestFile.ts new file mode 100644 index 00000000..fb5bb6a9 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestFile.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../index"; + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifyAudioRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: Skyflow.DeidentifyAudioRequestFileDataFormat; +} diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestFileDataFormat.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestFileDataFormat.ts new file mode 100644 index 00000000..87938c0a --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestFileDataFormat.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Data format of the file. + */ +export type DeidentifyAudioRequestFileDataFormat = "mp3" | "wav"; +export const DeidentifyAudioRequestFileDataFormat = { + Mp3: "mp3", + Wav: "wav", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestOutputTranscription.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestOutputTranscription.ts new file mode 100644 index 00000000..b370f8b3 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyAudioRequestOutputTranscription.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Type of transcription to output. + */ +export type DeidentifyAudioRequestOutputTranscription = + | "diarized_transcription" + | "medical_diarized_transcription" + | "medical_transcription" + | "plaintext_transcription" + | "transcription"; +export const DeidentifyAudioRequestOutputTranscription = { + DiarizedTranscription: "diarized_transcription", + MedicalDiarizedTranscription: "medical_diarized_transcription", + MedicalTranscription: "medical_transcription", + PlaintextTranscription: "plaintext_transcription", + Transcription: "transcription", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyDocumentRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyDocumentRequestFile.ts new file mode 100644 index 00000000..b3894b96 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyDocumentRequestFile.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../index"; + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifyDocumentRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: Skyflow.DeidentifyDocumentRequestFileDataFormat; +} diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyDocumentRequestFileDataFormat.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyDocumentRequestFileDataFormat.ts new file mode 100644 index 00000000..850c863f --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyDocumentRequestFileDataFormat.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Data format of the file. + */ +export type DeidentifyDocumentRequestFileDataFormat = "doc" | "docx" | "pdf"; +export const DeidentifyDocumentRequestFileDataFormat = { + Doc: "doc", + Docx: "docx", + Pdf: "pdf", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyFileRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyFileRequestFile.ts new file mode 100644 index 00000000..749adb46 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyFileRequestFile.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../index"; + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifyFileRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: Skyflow.DeidentifyFileRequestFileDataFormat; +} diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyFileRequestFileDataFormat.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyFileRequestFileDataFormat.ts new file mode 100644 index 00000000..5927453a --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyFileRequestFileDataFormat.ts @@ -0,0 +1,48 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Data format of the file. + */ +export type DeidentifyFileRequestFileDataFormat = + | "bmp" + | "csv" + | "doc" + | "docx" + | "jpeg" + | "jpg" + | "json" + | "mp3" + | "pdf" + | "png" + | "ppt" + | "pptx" + | "tif" + | "tiff" + | "txt" + | "wav" + | "xls" + | "xlsx" + | "xml"; +export const DeidentifyFileRequestFileDataFormat = { + Bmp: "bmp", + Csv: "csv", + Doc: "doc", + Docx: "docx", + Jpeg: "jpeg", + Jpg: "jpg", + Json: "json", + Mp3: "mp3", + Pdf: "pdf", + Png: "png", + Ppt: "ppt", + Pptx: "pptx", + Tif: "tif", + Tiff: "tiff", + Txt: "txt", + Wav: "wav", + Xls: "xls", + Xlsx: "xlsx", + Xml: "xml", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestFile.ts new file mode 100644 index 00000000..da7cb1c2 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestFile.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../index"; + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifyImageRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: Skyflow.DeidentifyImageRequestFileDataFormat; +} diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestFileDataFormat.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestFileDataFormat.ts new file mode 100644 index 00000000..00a407fa --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestFileDataFormat.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Data format of the file. + */ +export type DeidentifyImageRequestFileDataFormat = "bmp" | "jpeg" | "jpg" | "png" | "tif" | "tiff"; +export const DeidentifyImageRequestFileDataFormat = { + Bmp: "bmp", + Jpeg: "jpeg", + Jpg: "jpg", + Png: "png", + Tif: "tif", + Tiff: "tiff", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestMaskingMethod.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestMaskingMethod.ts new file mode 100644 index 00000000..ced4ca50 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyImageRequestMaskingMethod.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Method to mask the entities in the image. + */ +export type DeidentifyImageRequestMaskingMethod = "blackout" | "blur"; +export const DeidentifyImageRequestMaskingMethod = { + Blackout: "blackout", + Blur: "blur", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyPdfRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyPdfRequestFile.ts new file mode 100644 index 00000000..f8efc2b5 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyPdfRequestFile.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifyPdfRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: "pdf"; +} diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyPresentationRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyPresentationRequestFile.ts new file mode 100644 index 00000000..57871605 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyPresentationRequestFile.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../index"; + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifyPresentationRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: Skyflow.DeidentifyPresentationRequestFileDataFormat; +} diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyPresentationRequestFileDataFormat.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyPresentationRequestFileDataFormat.ts new file mode 100644 index 00000000..94f9d253 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyPresentationRequestFileDataFormat.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Data format of the file. + */ +export type DeidentifyPresentationRequestFileDataFormat = "ppt" | "pptx"; +export const DeidentifyPresentationRequestFileDataFormat = { + Ppt: "ppt", + Pptx: "pptx", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifySpreadsheetRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifySpreadsheetRequestFile.ts new file mode 100644 index 00000000..41cb9fe2 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifySpreadsheetRequestFile.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../index"; + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifySpreadsheetRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: Skyflow.DeidentifySpreadsheetRequestFileDataFormat; +} diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifySpreadsheetRequestFileDataFormat.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifySpreadsheetRequestFileDataFormat.ts new file mode 100644 index 00000000..041eb16e --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifySpreadsheetRequestFileDataFormat.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Data format of the file. + */ +export type DeidentifySpreadsheetRequestFileDataFormat = "csv" | "xls" | "xlsx"; +export const DeidentifySpreadsheetRequestFileDataFormat = { + Csv: "csv", + Xls: "xls", + Xlsx: "xlsx", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyStructuredTextRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyStructuredTextRequestFile.ts new file mode 100644 index 00000000..66432e03 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyStructuredTextRequestFile.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../index"; + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifyStructuredTextRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: Skyflow.DeidentifyStructuredTextRequestFileDataFormat; +} diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyStructuredTextRequestFileDataFormat.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyStructuredTextRequestFileDataFormat.ts new file mode 100644 index 00000000..74dc1435 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyStructuredTextRequestFileDataFormat.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Data format of the file. + */ +export type DeidentifyStructuredTextRequestFileDataFormat = "json" | "xml"; +export const DeidentifyStructuredTextRequestFileDataFormat = { + Json: "json", + Xml: "xml", +} as const; diff --git a/src/ _generated_/rest/api/resources/files/types/DeidentifyTextRequestFile.ts b/src/ _generated_/rest/api/resources/files/types/DeidentifyTextRequestFile.ts new file mode 100644 index 00000000..7b1a08ca --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/DeidentifyTextRequestFile.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * File to de-identify. Files are specified as Base64-encoded data. + */ +export interface DeidentifyTextRequestFile { + /** Base64-encoded data of the file to de-identify. */ + base64: string; + /** Data format of the file. */ + data_format: "txt"; +} diff --git a/src/ _generated_/rest/api/resources/files/types/index.ts b/src/ _generated_/rest/api/resources/files/types/index.ts new file mode 100644 index 00000000..51f03325 --- /dev/null +++ b/src/ _generated_/rest/api/resources/files/types/index.ts @@ -0,0 +1,18 @@ +export * from "./DeidentifyFileRequestFileDataFormat"; +export * from "./DeidentifyFileRequestFile"; +export * from "./DeidentifyDocumentRequestFileDataFormat"; +export * from "./DeidentifyDocumentRequestFile"; +export * from "./DeidentifyPdfRequestFile"; +export * from "./DeidentifyImageRequestFileDataFormat"; +export * from "./DeidentifyImageRequestFile"; +export * from "./DeidentifyImageRequestMaskingMethod"; +export * from "./DeidentifyTextRequestFile"; +export * from "./DeidentifyStructuredTextRequestFileDataFormat"; +export * from "./DeidentifyStructuredTextRequestFile"; +export * from "./DeidentifySpreadsheetRequestFileDataFormat"; +export * from "./DeidentifySpreadsheetRequestFile"; +export * from "./DeidentifyPresentationRequestFileDataFormat"; +export * from "./DeidentifyPresentationRequestFile"; +export * from "./DeidentifyAudioRequestFileDataFormat"; +export * from "./DeidentifyAudioRequestFile"; +export * from "./DeidentifyAudioRequestOutputTranscription"; diff --git a/src/ _generated_/rest/api/resources/index.ts b/src/ _generated_/rest/api/resources/index.ts index a6ae3aed..4d7fe175 100644 --- a/src/ _generated_/rest/api/resources/index.ts +++ b/src/ _generated_/rest/api/resources/index.ts @@ -2,13 +2,21 @@ export * as audit from "./audit"; export * from "./audit/types"; export * as records from "./records"; export * from "./records/types"; +export * as strings from "./strings"; +export * from "./strings/types"; +export * as files from "./files"; +export * from "./files/types"; export * as binLookup from "./binLookup"; export * as tokens from "./tokens"; export * as query from "./query"; export * as authentication from "./authentication"; +export * as deprecated from "./deprecated"; export * from "./audit/client/requests"; export * from "./binLookup/client/requests"; export * from "./records/client/requests"; export * from "./tokens/client/requests"; export * from "./query/client/requests"; export * from "./authentication/client/requests"; +export * from "./deprecated/client/requests"; +export * from "./strings/client/requests"; +export * from "./files/client/requests"; diff --git a/src/ _generated_/rest/api/resources/query/client/Client.ts b/src/ _generated_/rest/api/resources/query/client/Client.ts index d6339a16..8754ac4a 100644 --- a/src/ _generated_/rest/api/resources/query/client/Client.ts +++ b/src/ _generated_/rest/api/resources/query/client/Client.ts @@ -91,10 +91,7 @@ export class Query { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, diff --git a/src/ _generated_/rest/api/resources/records/client/Client.ts b/src/ _generated_/rest/api/resources/records/client/Client.ts index 96ea98ce..c0682f3f 100644 --- a/src/ _generated_/rest/api/resources/records/client/Client.ts +++ b/src/ _generated_/rest/api/resources/records/client/Client.ts @@ -117,10 +117,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -274,10 +271,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -387,10 +381,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -483,10 +474,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -602,10 +590,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -709,10 +694,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -802,10 +784,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -910,10 +889,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -1006,10 +982,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -1102,10 +1075,7 @@ export class Records { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, diff --git a/src/ _generated_/rest/api/resources/strings/client/Client.ts b/src/ _generated_/rest/api/resources/strings/client/Client.ts new file mode 100644 index 00000000..c0e588ea --- /dev/null +++ b/src/ _generated_/rest/api/resources/strings/client/Client.ts @@ -0,0 +1,277 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments"; +import * as core from "../../../../core"; +import * as Skyflow from "../../../index"; +import urlJoin from "url-join"; +import * as errors from "../../../../errors/index"; + +export declare namespace Strings { + export interface Options { + environment?: core.Supplier; + /** Specify a custom URL to connect the client to. */ + baseUrl?: core.Supplier; + token: core.Supplier; + fetcher?: core.FetchFunction; + } + + export interface RequestOptions { + /** The maximum time to wait for a response in seconds. */ + timeoutInSeconds?: number; + /** The number of times to retry the request. Defaults to 2. */ + maxRetries?: number; + /** A hook to abort the request. */ + abortSignal?: AbortSignal; + /** Additional headers to include in the request. */ + headers?: Record; + } +} + +export class Strings { + constructor(protected readonly _options: Strings.Options) {} + + /** + * De-identifies sensitive data from a string. + * + * @param {Skyflow.DeidentifyStringRequest} request + * @param {Strings.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.strings.deidentifyString({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * text: "My name is John Doe, and my email is johndoe@acme.com." + * }) + * + * @example + * await client.strings.deidentifyString({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * text: "S: 62yo female here for first visit. No concerns today. Her FP (Dr. Benyamin) is retiring soon. Up to date on pap, mammo, labs, BMD. On the waitlist for colonoscopy. Past Medical and Surgical hx: nil. Meds: nil. Allergies: Pn. Family and Social hx: see CPP. O: Temp 35.2;BP 145-73; HR 58. Appears well. A: First visit. P: CPP updated. RTC prn. A007. First visit. Type Name: Clinical Note" + * }) + * + * @example + * await client.strings.deidentifyString({ + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * text: "My name is John Doe, and my email is johndoe@acme.com.", + * entity_types: ["name", "email_address"], + * token_type: { + * default: "entity_only" + * } + * }) + * + * @example + * await client.strings.deidentifyString({ + * vault_id: "VAULT_ID", + * text: "My name is John Doe, and my email is johndoe@acme.com.", + * token_type: { + * default: "vault_token" + * } + * }) + * + * @example + * await client.strings.deidentifyString({ + * vault_id: "VAULT_ID", + * text: "My name is John Doe, and my email is johndoe@acme.com." + * }) + * + * @example + * await client.strings.deidentifyString({ + * vault_id: "VAULT_ID", + * text: "My name is John, and my email is johndoe@acme.com.", + * entity_types: ["name", "email_address"], + * token_type: { + * default: "entity_only" + * }, + * allow_regex: ["John"], + * transformations: { + * shift_dates: { + * max_days: 5, + * min_days: 1, + * entity_types: ["date"] + * } + * } + * }) + */ + public deidentifyString( + request: Skyflow.DeidentifyStringRequest, + requestOptions?: Strings.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deidentifyString(request, requestOptions)); + } + + private async __deidentifyString( + request: Skyflow.DeidentifyStringRequest, + requestOptions?: Strings.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/deidentify/string", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.DeidentifyStringResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/deidentify/string.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Re-identifies tokens in a string. + * + * @param {Skyflow.ReidentifyStringRequest} request + * @param {Strings.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Skyflow.BadRequestError} + * @throws {@link Skyflow.UnauthorizedError} + * @throws {@link Skyflow.InternalServerError} + * + * @example + * await client.strings.reidentifyString({ + * text: "My name is [NAME_1], and my email is [EMAIL_1].", + * vault_id: "1ad6db07-8405-46cf-9a1e-db148ff9f4c5" + * }) + */ + public reidentifyString( + request: Skyflow.ReidentifyStringRequest, + requestOptions?: Strings.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__reidentifyString(request, requestOptions)); + } + + private async __reidentifyString( + request: Skyflow.ReidentifyStringRequest, + requestOptions?: Strings.RequestOptions, + ): Promise> { + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.SkyflowEnvironment.Production, + "v1/detect/reidentify/string", + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "skyflow", + "X-Fern-SDK-Version": "1.0.21", + "User-Agent": "skyflow/1.0.21", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Skyflow.ReidentifyStringResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 500: + throw new Skyflow.InternalServerError( + _response.error.body as Skyflow.ErrorResponse, + _response.rawResponse, + ); + default: + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SkyflowError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.SkyflowTimeoutError( + "Timeout exceeded when calling POST /v1/detect/reidentify/string.", + ); + case "unknown": + throw new errors.SkyflowError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + protected async _getAuthorizationHeader(): Promise { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/ _generated_/rest/api/resources/strings/client/index.ts b/src/ _generated_/rest/api/resources/strings/client/index.ts new file mode 100644 index 00000000..415726b7 --- /dev/null +++ b/src/ _generated_/rest/api/resources/strings/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/ _generated_/rest/api/resources/strings/client/requests/DeidentifyStringRequest.ts b/src/ _generated_/rest/api/resources/strings/client/requests/DeidentifyStringRequest.ts new file mode 100644 index 00000000..d157c3ce --- /dev/null +++ b/src/ _generated_/rest/api/resources/strings/client/requests/DeidentifyStringRequest.ts @@ -0,0 +1,72 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * text: "My name is John Doe, and my email is johndoe@acme.com." + * } + * + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * text: "S: 62yo female here for first visit. No concerns today. Her FP (Dr. Benyamin) is retiring soon. Up to date on pap, mammo, labs, BMD. On the waitlist for colonoscopy. Past Medical and Surgical hx: nil. Meds: nil. Allergies: Pn. Family and Social hx: see CPP. O: Temp 35.2;BP 145-73; HR 58. Appears well. A: First visit. P: CPP updated. RTC prn. A007. First visit. Type Name: Clinical Note" + * } + * + * @example + * { + * vault_id: "f4b3b3b33b3b3b3b3b3b3b3b3b3b3b3b", + * text: "My name is John Doe, and my email is johndoe@acme.com.", + * entity_types: ["name", "email_address"], + * token_type: { + * default: "entity_only" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * text: "My name is John Doe, and my email is johndoe@acme.com.", + * token_type: { + * default: "vault_token" + * } + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * text: "My name is John Doe, and my email is johndoe@acme.com." + * } + * + * @example + * { + * vault_id: "VAULT_ID", + * text: "My name is John, and my email is johndoe@acme.com.", + * entity_types: ["name", "email_address"], + * token_type: { + * default: "entity_only" + * }, + * allow_regex: ["John"], + * transformations: { + * shift_dates: { + * max_days: 5, + * min_days: 1, + * entity_types: ["date"] + * } + * } + * } + */ +export interface DeidentifyStringRequest { + vault_id: Skyflow.VaultId; + /** String to de-identify. */ + text: string; + entity_types?: Skyflow.EntityTypes; + token_type?: Skyflow.TokenType; + allow_regex?: Skyflow.AllowRegex; + restrict_regex?: Skyflow.RestrictRegex; + transformations?: Skyflow.Transformations; +} diff --git a/src/ _generated_/rest/api/resources/strings/client/requests/ReidentifyStringRequest.ts b/src/ _generated_/rest/api/resources/strings/client/requests/ReidentifyStringRequest.ts new file mode 100644 index 00000000..0a8a2f86 --- /dev/null +++ b/src/ _generated_/rest/api/resources/strings/client/requests/ReidentifyStringRequest.ts @@ -0,0 +1,21 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../../index"; + +/** + * @example + * { + * text: "My name is [NAME_1], and my email is [EMAIL_1].", + * vault_id: "1ad6db07-8405-46cf-9a1e-db148ff9f4c5" + * } + */ +export interface ReidentifyStringRequest { + /** String to re-identify. */ + text: string; + /** ID of the vault where the entities are stored. */ + vault_id: string; + /** Mapping of perferred data formatting options to entity types. Returned values are dependent on the configuration of the vault storing the data and the permissions of the user or account making the request. */ + format?: Skyflow.ReidentifyStringRequestFormat; +} diff --git a/src/ _generated_/rest/api/resources/strings/client/requests/index.ts b/src/ _generated_/rest/api/resources/strings/client/requests/index.ts new file mode 100644 index 00000000..a10c579b --- /dev/null +++ b/src/ _generated_/rest/api/resources/strings/client/requests/index.ts @@ -0,0 +1,2 @@ +export { type DeidentifyStringRequest } from "./DeidentifyStringRequest"; +export { type ReidentifyStringRequest } from "./ReidentifyStringRequest"; diff --git a/src/ _generated_/rest/api/resources/strings/index.ts b/src/ _generated_/rest/api/resources/strings/index.ts new file mode 100644 index 00000000..c9240f83 --- /dev/null +++ b/src/ _generated_/rest/api/resources/strings/index.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./client"; diff --git a/src/ _generated_/rest/api/resources/strings/types/ReidentifyStringRequestFormat.ts b/src/ _generated_/rest/api/resources/strings/types/ReidentifyStringRequestFormat.ts new file mode 100644 index 00000000..712a5f81 --- /dev/null +++ b/src/ _generated_/rest/api/resources/strings/types/ReidentifyStringRequestFormat.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../../../index"; + +/** + * Mapping of perferred data formatting options to entity types. Returned values are dependent on the configuration of the vault storing the data and the permissions of the user or account making the request. + */ +export interface ReidentifyStringRequestFormat { + /** Entity types to fully redact. */ + redacted?: Skyflow.EntityType[]; + /** Entity types to mask. */ + masked?: Skyflow.EntityType[]; + /** Entity types to return in plaintext. */ + plaintext?: Skyflow.EntityType[]; +} diff --git a/src/ _generated_/rest/api/resources/strings/types/index.ts b/src/ _generated_/rest/api/resources/strings/types/index.ts new file mode 100644 index 00000000..58b77ca6 --- /dev/null +++ b/src/ _generated_/rest/api/resources/strings/types/index.ts @@ -0,0 +1 @@ +export * from "./ReidentifyStringRequestFormat"; diff --git a/src/ _generated_/rest/api/resources/tokens/client/Client.ts b/src/ _generated_/rest/api/resources/tokens/client/Client.ts index 5f5b90fc..8ce2956c 100644 --- a/src/ _generated_/rest/api/resources/tokens/client/Client.ts +++ b/src/ _generated_/rest/api/resources/tokens/client/Client.ts @@ -98,10 +98,7 @@ export class Tokens { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, @@ -187,10 +184,7 @@ export class Tokens { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 404: - throw new Skyflow.NotFoundError( - _response.error.body as Record, - _response.rawResponse, - ); + throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.SkyflowError({ statusCode: _response.error.statusCode, diff --git a/src/ _generated_/rest/api/types/AdvancedOptionsColumnMapping.ts b/src/ _generated_/rest/api/types/AdvancedOptionsColumnMapping.ts new file mode 100644 index 00000000..77a428f1 --- /dev/null +++ b/src/ _generated_/rest/api/types/AdvancedOptionsColumnMapping.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Contains map of what has to be stored in which column. + */ +export interface AdvancedOptionsColumnMapping { + /** Table name of the vault. */ + session_id: string; + /** Name of column to store data in when no explicit mapping exists. */ + default: string; + /** Column mapping for different entities. */ + entity_column_map?: Skyflow.AdvancedOptionsEntityColumnMap[]; +} diff --git a/src/ _generated_/rest/api/types/AdvancedOptionsEntityColumnMap.ts b/src/ _generated_/rest/api/types/AdvancedOptionsEntityColumnMap.ts new file mode 100644 index 00000000..20d3664f --- /dev/null +++ b/src/ _generated_/rest/api/types/AdvancedOptionsEntityColumnMap.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Contains map of what entity has to be stored in which column. + */ +export interface AdvancedOptionsEntityColumnMap { + entity_type?: Skyflow.DetectDataEntities; + /** Column name where the entity has to be stored. */ + column_name?: string; +} diff --git a/src/ _generated_/rest/api/types/AdvancedOptionsVaultSchema.ts b/src/ _generated_/rest/api/types/AdvancedOptionsVaultSchema.ts new file mode 100644 index 00000000..02dffb1c --- /dev/null +++ b/src/ _generated_/rest/api/types/AdvancedOptionsVaultSchema.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Contains table name and column mapping. + */ +export interface AdvancedOptionsVaultSchema { + /** Table name of the vault. */ + table_name: string; + mapping: Skyflow.AdvancedOptionsColumnMapping; +} diff --git a/src/ _generated_/rest/api/types/AllowRegex.ts b/src/ _generated_/rest/api/types/AllowRegex.ts new file mode 100644 index 00000000..e069febd --- /dev/null +++ b/src/ _generated_/rest/api/types/AllowRegex.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Regular expressions to display in plaintext. Expressions must match the entirety of a detected entity, not just a substring, for the entity to display in plaintext. Expressions don't match across entity boundaries. If a string or entity matches both `allow_regex` and `restrict_regex`, the entity is displayed in plaintext. + */ +export type AllowRegex = string[]; diff --git a/src/ _generated_/rest/api/types/AudioConfigTranscriptionType.ts b/src/ _generated_/rest/api/types/AudioConfigTranscriptionType.ts new file mode 100644 index 00000000..fc860d8b --- /dev/null +++ b/src/ _generated_/rest/api/types/AudioConfigTranscriptionType.ts @@ -0,0 +1,41 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Type of transcription. + * + * - none: Indicates transcriptionType is not set. + * - skyflow_transcription: Sends Skyflow transcribed text. + * - aws_transcription: Sends AWS transcribed text. + * - aws_transcription_diarize: Sends AWS diarized text. + * - aws_medical_transcription: Sends AWS medical transcribed text. + * - aws_medical_transcription_diarize: Sends AWS medical diarized text. + * - aws_transcription_diarize_json: Sends AWS transcribed redacted json. + * - deepgram_transcription_diarize: deepgram transcribed diarized text. + * - deepgram_transcription_json: deepgram transcribed redacted json. + * - deepgram_wrapper: deepgram diarized text. + */ +export type AudioConfigTranscriptionType = + | "none" + | "skyflow_transcription" + | "aws_transcription" + | "aws_transcription_diarize" + | "aws_medical_transcription" + | "aws_medical_transcription_diarize" + | "aws_transcription_diarize_json" + | "deepgram_transcription_diarize" + | "deepgram_transcription_json" + | "deepgram_wrapper"; +export const AudioConfigTranscriptionType = { + None: "none", + SkyflowTranscription: "skyflow_transcription", + AwsTranscription: "aws_transcription", + AwsTranscriptionDiarize: "aws_transcription_diarize", + AwsMedicalTranscription: "aws_medical_transcription", + AwsMedicalTranscriptionDiarize: "aws_medical_transcription_diarize", + AwsTranscriptionDiarizeJson: "aws_transcription_diarize_json", + DeepgramTranscriptionDiarize: "deepgram_transcription_diarize", + DeepgramTranscriptionJson: "deepgram_transcription_json", + DeepgramWrapper: "deepgram_wrapper", +} as const; diff --git a/src/ _generated_/rest/api/types/DeidentifyFileOutput.ts b/src/ _generated_/rest/api/types/DeidentifyFileOutput.ts new file mode 100644 index 00000000..f90709f8 --- /dev/null +++ b/src/ _generated_/rest/api/types/DeidentifyFileOutput.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Details and contents of the processed file. + */ +export interface DeidentifyFileOutput { + /** URL or base64-encoded data of the output. */ + processed_file?: string; + /** Type of the processed file. */ + processed_file_type?: Skyflow.DeidentifyFileOutputProcessedFileType; + /** Extension of the processed file. */ + processed_file_extension?: string; +} diff --git a/src/ _generated_/rest/api/types/DeidentifyFileOutputProcessedFileType.ts b/src/ _generated_/rest/api/types/DeidentifyFileOutputProcessedFileType.ts new file mode 100644 index 00000000..d47699a1 --- /dev/null +++ b/src/ _generated_/rest/api/types/DeidentifyFileOutputProcessedFileType.ts @@ -0,0 +1,30 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Type of the processed file. + */ +export type DeidentifyFileOutputProcessedFileType = + | "entities" + | "plaintext_transcription" + | "redacted_audio" + | "redacted_diarized_transcription" + | "redacted_file" + | "redacted_image" + | "redacted_medical_diarized_transcription" + | "redacted_medical_transcription" + | "redacted_text" + | "redacted_transcription"; +export const DeidentifyFileOutputProcessedFileType = { + Entities: "entities", + PlaintextTranscription: "plaintext_transcription", + RedactedAudio: "redacted_audio", + RedactedDiarizedTranscription: "redacted_diarized_transcription", + RedactedFile: "redacted_file", + RedactedImage: "redacted_image", + RedactedMedicalDiarizedTranscription: "redacted_medical_diarized_transcription", + RedactedMedicalTranscription: "redacted_medical_transcription", + RedactedText: "redacted_text", + RedactedTranscription: "redacted_transcription", +} as const; diff --git a/src/ _generated_/rest/api/types/DeidentifyFileResponse.ts b/src/ _generated_/rest/api/types/DeidentifyFileResponse.ts new file mode 100644 index 00000000..81cc67e5 --- /dev/null +++ b/src/ _generated_/rest/api/types/DeidentifyFileResponse.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Response to de-identify a file. + */ +export interface DeidentifyFileResponse { + /** Status URL for the detect run. */ + run_id: string; +} diff --git a/src/ _generated_/rest/api/types/DeidentifyStatusResponse.ts b/src/ _generated_/rest/api/types/DeidentifyStatusResponse.ts new file mode 100644 index 00000000..8a5fa2c7 --- /dev/null +++ b/src/ _generated_/rest/api/types/DeidentifyStatusResponse.ts @@ -0,0 +1,31 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Response to get the status of a detect run. + */ +export interface DeidentifyStatusResponse { + /** Status of the detect run. */ + status: Skyflow.DeidentifyStatusResponseStatus; + /** How the input file was specified. */ + output: Skyflow.DeidentifyFileOutput[]; + /** How the output file is specified. */ + output_type: Skyflow.DeidentifyStatusResponseOutputType; + /** Status details about the detect run. */ + message: string; + /** Number of words in the processed text. */ + word_count?: number; + /** Number of characters in the processed text. */ + character_count?: number; + /** Size of the processed text in kilobytes (KB). */ + size?: number; + /** Duration of the processed audio in seconds. */ + duration?: number; + /** Number of pages in the processed PDF. */ + pages?: number; + /** Number of slides in the processed presentation. */ + slides?: number; +} diff --git a/src/ _generated_/rest/api/types/DeidentifyStatusResponseOutputType.ts b/src/ _generated_/rest/api/types/DeidentifyStatusResponseOutputType.ts new file mode 100644 index 00000000..5e8dfc87 --- /dev/null +++ b/src/ _generated_/rest/api/types/DeidentifyStatusResponseOutputType.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * How the output file is specified. + */ +export type DeidentifyStatusResponseOutputType = "base64" | "efs_path"; +export const DeidentifyStatusResponseOutputType = { + Base64: "base64", + EfsPath: "efs_path", +} as const; diff --git a/src/ _generated_/rest/api/types/DeidentifyStatusResponseStatus.ts b/src/ _generated_/rest/api/types/DeidentifyStatusResponseStatus.ts new file mode 100644 index 00000000..78e92829 --- /dev/null +++ b/src/ _generated_/rest/api/types/DeidentifyStatusResponseStatus.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Status of the detect run. + */ +export type DeidentifyStatusResponseStatus = "failed" | "in_progress" | "success"; +export const DeidentifyStatusResponseStatus = { + Failed: "failed", + InProgress: "in_progress", + Success: "success", +} as const; diff --git a/src/ _generated_/rest/api/types/DeidentifyStringResponse.ts b/src/ _generated_/rest/api/types/DeidentifyStringResponse.ts new file mode 100644 index 00000000..3ae4af74 --- /dev/null +++ b/src/ _generated_/rest/api/types/DeidentifyStringResponse.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Response to deidentify a string. + */ +export interface DeidentifyStringResponse { + /** De-identified text. */ + processed_text: string; + /** Detected entities. */ + entities: Skyflow.DetectedEntity[]; + /** Number of words from the input text. */ + word_count: number; + /** Number of characters from the input text. */ + character_count: number; +} diff --git a/src/ _generated_/rest/api/types/DetectDataAccuracy.ts b/src/ _generated_/rest/api/types/DetectDataAccuracy.ts new file mode 100644 index 00000000..9043bb6a --- /dev/null +++ b/src/ _generated_/rest/api/types/DetectDataAccuracy.ts @@ -0,0 +1,35 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Accuracy of the detection. The higher the accuracy, the more time it takes to process the request. Use multilingual options if the input contains languages other than English. + * + * - unknown: Unknown accuracy. + * - standard: Base-level accuracy. + * - standard_plus: Improved accuracy. + * - standard_plus_multilingual: Improved accuracy with multilingual support. + * - standard_plus_automatic: Improved accuracy with automatic language detection. + * - high: High accuracy. + * - high_multilingual: High accuracy with multilingual support. + * - high_automatic: High accuracy with automatic language detection. + */ +export type DetectDataAccuracy = + | "unknown" + | "standard" + | "standard_plus" + | "standard_plus_multilingual" + | "standard_plus_automatic" + | "high" + | "high_multilingual" + | "high_automatic"; +export const DetectDataAccuracy = { + Unknown: "unknown", + Standard: "standard", + StandardPlus: "standard_plus", + StandardPlusMultilingual: "standard_plus_multilingual", + StandardPlusAutomatic: "standard_plus_automatic", + High: "high", + HighMultilingual: "high_multilingual", + HighAutomatic: "high_automatic", +} as const; diff --git a/src/ _generated_/rest/api/types/DetectDataEntities.ts b/src/ _generated_/rest/api/types/DetectDataEntities.ts new file mode 100644 index 00000000..758aefb6 --- /dev/null +++ b/src/ _generated_/rest/api/types/DetectDataEntities.ts @@ -0,0 +1,200 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Entities to detect and deidentify. + * + * - age: Numbers associated with an individual’s age. + * - bank_account: Bank account numbers and international equivalents. + * - credit_card: Credit card numbers. + * - credit_card_expiration: Expiration date of a credit card. + * - cvv: 3 or 4 digit card verification codes and equivalents. + * - date: Specific calendar dates, which can include days of the week, dates, months, or years. + * - date_interval: Broader time periods, including date ranges, months, seasons, years, and decades. + * - dob: Dates of birth. + * - driver_license: Driver's permit numbers. + * - email_address: Email addresses. + * - healthcare_number: Healthcare numbers and health plan beneficiary numbers. + * - ip_address: Internet IP address, including IPv4 and IPv6 formats. + * - location: Metaclass for any named location reference; See subclasses below. + * - name: Names of individuals, not including personal titles such as ‘Mrs.’ or ‘Mr.’. + * - numerical_pii: Numerical PII (including alphanumeric strings) such as device serial numbers, POS codes etc. + * - phone_number: Telephone or fax numbers. + * - ssn: Social Security Numbers or international equivalent government identification numbers. + * - url: Internet addresses. + * - vehicle_id: Vehicle identification numbers (VINs), vehicle serial numbers, and license plate numbers. + * - medical_code: Codes belonging to medical classification systems. + * - name_family: Names indicating a person’s family or community. + * - name_given: Names given to an individual, usually at birth. + * - account_number: Customer account or membership identification number. + * - event: Names of events or holidays. + * - filename: Names of computer files, including the extension or filepath. + * - gender_sexuality: Terms indicating gender identity or sexual orientation, including slang terms. + * - language: Names of natural languages. + * - location_address: Full or partial physical mailing addresses. + * - location_city: Municipality names, including villages, towns, and cities. + * - location_coordinate: Geographic positions referred to using latitude, longitude, and/or elevation coordinates. + * - location_country: Country names. + * - location_state: State, province, territory, or prefecture names. + * - location_zip: Zip codes (including Zip+4), postcodes, or postal codes. + * - marital_status: Terms indicating marital status. + * - money: Names and/or amounts of currency. + * - name_medical_professional: Full names, including professional titles and certifications, of medical professional, such as doctors and nurses + * - occupation: Job titles or professions. + * - organization: Names of organizations or departments within an organization. + * - organization_medical_facility: Names of medical facilities, such as hospitals, clinics, pharmacies, etc. + * - origin: Terms indicating nationality, ethnicity, or provenance. + * - passport_number: Passport numbers, issued by any country. + * - password: Account passwords, PINs, access keys, or verification answers. + * - physical_attribute: Distinctive bodily attributes, including terms indicating race. + * - political_affiliation: Terms referring to a political party, movement, or ideology. + * - religion: Terms indicating religious affiliation. + * - time: Expressions indicating clock times. + * - username: Usernames, login names, or handles. + * - zodiac_sign: Names of Zodiac signs. + * - blood_type: Blood types. + * - condition: Names of medical conditions. + * - dose: Medically prescribed quantity of a medication. + * - drug: Medications, vitamins, and supplements. + * - injury: Bodily injuries. + * - medical_process: Medical processes, including treatments, procedures, and tests. + * - statistics: Medical statistics. + * - routing_number: Routing number associated with a bank or financial institution. + * - corporate_action: Any action a company takes that could affect its stock value or its shareholders. + * - financial_metric: Financial metrics or financial ratios are quantitative indicators of a company’s financial health. + * - product: Names or model numbers of items made by an organization. + * - trend: A description of the “quality” or the direction in which a financial measurement is going. + * - duration: Periods of time, specified as a number and a unit of time. + * - location_address_street: A subclass of location_address, covering: a building number and street name, plus information like a unit numbers, office numbers, floor numbers and building names, where applicable. + * - all: Indicates all entities. + */ +export type DetectDataEntities = + | "age" + | "bank_account" + | "credit_card" + | "credit_card_expiration" + | "cvv" + | "date" + | "date_interval" + | "dob" + | "driver_license" + | "email_address" + | "healthcare_number" + | "ip_address" + | "location" + | "name" + | "numerical_pii" + | "phone_number" + | "ssn" + | "url" + | "vehicle_id" + | "medical_code" + | "name_family" + | "name_given" + | "account_number" + | "event" + | "filename" + | "gender_sexuality" + | "language" + | "location_address" + | "location_city" + | "location_coordinate" + | "location_country" + | "location_state" + | "location_zip" + | "marital_status" + | "money" + | "name_medical_professional" + | "occupation" + | "organization" + | "organization_medical_facility" + | "origin" + | "passport_number" + | "password" + | "physical_attribute" + | "political_affiliation" + | "religion" + | "time" + | "username" + | "zodiac_sign" + | "blood_type" + | "condition" + | "dose" + | "drug" + | "injury" + | "medical_process" + | "statistics" + | "routing_number" + | "corporate_action" + | "financial_metric" + | "product" + | "trend" + | "duration" + | "location_address_street" + | "all"; +export const DetectDataEntities = { + Age: "age", + BankAccount: "bank_account", + CreditCard: "credit_card", + CreditCardExpiration: "credit_card_expiration", + Cvv: "cvv", + Date: "date", + DateInterval: "date_interval", + Dob: "dob", + DriverLicense: "driver_license", + EmailAddress: "email_address", + HealthcareNumber: "healthcare_number", + IpAddress: "ip_address", + Location: "location", + Name: "name", + NumericalPii: "numerical_pii", + PhoneNumber: "phone_number", + Ssn: "ssn", + Url: "url", + VehicleId: "vehicle_id", + MedicalCode: "medical_code", + NameFamily: "name_family", + NameGiven: "name_given", + AccountNumber: "account_number", + Event: "event", + Filename: "filename", + GenderSexuality: "gender_sexuality", + Language: "language", + LocationAddress: "location_address", + LocationCity: "location_city", + LocationCoordinate: "location_coordinate", + LocationCountry: "location_country", + LocationState: "location_state", + LocationZip: "location_zip", + MaritalStatus: "marital_status", + Money: "money", + NameMedicalProfessional: "name_medical_professional", + Occupation: "occupation", + Organization: "organization", + OrganizationMedicalFacility: "organization_medical_facility", + Origin: "origin", + PassportNumber: "passport_number", + Password: "password", + PhysicalAttribute: "physical_attribute", + PoliticalAffiliation: "political_affiliation", + Religion: "religion", + Time: "time", + Username: "username", + ZodiacSign: "zodiac_sign", + BloodType: "blood_type", + Condition: "condition", + Dose: "dose", + Drug: "drug", + Injury: "injury", + MedicalProcess: "medical_process", + Statistics: "statistics", + RoutingNumber: "routing_number", + CorporateAction: "corporate_action", + FinancialMetric: "financial_metric", + Product: "product", + Trend: "trend", + Duration: "duration", + LocationAddressStreet: "location_address_street", + All: "all", +} as const; diff --git a/src/ _generated_/rest/api/types/DetectFileRequestDataType.ts b/src/ _generated_/rest/api/types/DetectFileRequestDataType.ts new file mode 100644 index 00000000..9117b503 --- /dev/null +++ b/src/ _generated_/rest/api/types/DetectFileRequestDataType.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * How the input file is specified. + * + * - UNKNOWN: Unknown data type. + * - BASE64: Base64 encoded data. + */ +export type DetectFileRequestDataType = "UNKNOWN" | "BASE64"; +export const DetectFileRequestDataType = { + Unknown: "UNKNOWN", + Base64: "BASE64", +} as const; diff --git a/src/ _generated_/rest/api/types/DetectRequestDeidentifyOption.ts b/src/ _generated_/rest/api/types/DetectRequestDeidentifyOption.ts new file mode 100644 index 00000000..b274cec9 --- /dev/null +++ b/src/ _generated_/rest/api/types/DetectRequestDeidentifyOption.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Type of token to generate for detected entities. + * + * - UNKNOWN: unknown. + * - ENTITY_UNQ_COUNTER: Sensitive words are replaced with the entity type and a unique number. For example, "John and Jane" becomes "[NAME_1] and [NAME_2]". + * - ENTITY_ONLY: Sensitive words are replaced with the entity type. For example, "John and Jane" becomes "[NAME] and [NAME]". + */ +export type DetectRequestDeidentifyOption = "UNKNOWN" | "ENTITY_UNQ_COUNTER" | "ENTITY_ONLY"; +export const DetectRequestDeidentifyOption = { + Unknown: "UNKNOWN", + EntityUnqCounter: "ENTITY_UNQ_COUNTER", + EntityOnly: "ENTITY_ONLY", +} as const; diff --git a/src/ _generated_/rest/api/types/DetectedEntity.ts b/src/ _generated_/rest/api/types/DetectedEntity.ts new file mode 100644 index 00000000..420f8297 --- /dev/null +++ b/src/ _generated_/rest/api/types/DetectedEntity.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Detected entities. + */ +export interface DetectedEntity { + /** Processed text of the entity. */ + token?: string; + /** Original text of the entity. */ + value?: string; + location?: Skyflow.EntityLocation; + /** Highest-rated label. */ + entity_type?: string; + /** entity_scores and their scores. */ + entity_scores?: Record; +} diff --git a/src/ _generated_/rest/api/types/EntityLocation.ts b/src/ _generated_/rest/api/types/EntityLocation.ts new file mode 100644 index 00000000..885c1a41 --- /dev/null +++ b/src/ _generated_/rest/api/types/EntityLocation.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Locations of an entity in the text. + */ +export interface EntityLocation { + /** Index of the first character of the string in the original text. */ + start_index?: number; + /** Index of the last character of the string in the original text. */ + end_index?: number; + /** Index of the first character of the string in the processed text. */ + start_index_processed?: number; + /** Index of the last character of the string in the processed text. */ + end_index_processed?: number; +} diff --git a/src/ _generated_/rest/api/types/EntityType.ts b/src/ _generated_/rest/api/types/EntityType.ts new file mode 100644 index 00000000..7d679f30 --- /dev/null +++ b/src/ _generated_/rest/api/types/EntityType.ts @@ -0,0 +1,136 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Kinds of entities to de-identify. For details on specific entity types, how they're processed, and language support, see [Entity types and languages](/detect-entity-types). + */ +export type EntityType = + | "account_number" + | "age" + | "all" + | "bank_account" + | "blood_type" + | "condition" + | "corporate_action" + | "credit_card" + | "credit_card_expiration" + | "cvv" + | "date" + | "date_interval" + | "dob" + | "dose" + | "driver_license" + | "drug" + | "duration" + | "email_address" + | "event" + | "filename" + | "financial_metric" + | "gender_sexuality" + | "healthcare_number" + | "injury" + | "ip_address" + | "language" + | "location" + | "location_address" + | "location_address_street" + | "location_city" + | "location_coordinate" + | "location_country" + | "location_state" + | "location_zip" + | "marital_status" + | "medical_code" + | "medical_process" + | "money" + | "name" + | "name_family" + | "name_given" + | "name_medical_professional" + | "numerical_pii" + | "occupation" + | "organization" + | "organization_medical_facility" + | "origin" + | "passport_number" + | "password" + | "phone_number" + | "physical_attribute" + | "political_affiliation" + | "product" + | "religion" + | "routing_number" + | "ssn" + | "statistics" + | "time" + | "trend" + | "url" + | "username" + | "vehicle_id" + | "zodiac_sign"; +export const EntityType = { + AccountNumber: "account_number", + Age: "age", + All: "all", + BankAccount: "bank_account", + BloodType: "blood_type", + Condition: "condition", + CorporateAction: "corporate_action", + CreditCard: "credit_card", + CreditCardExpiration: "credit_card_expiration", + Cvv: "cvv", + Date: "date", + DateInterval: "date_interval", + Dob: "dob", + Dose: "dose", + DriverLicense: "driver_license", + Drug: "drug", + Duration: "duration", + EmailAddress: "email_address", + Event: "event", + Filename: "filename", + FinancialMetric: "financial_metric", + GenderSexuality: "gender_sexuality", + HealthcareNumber: "healthcare_number", + Injury: "injury", + IpAddress: "ip_address", + Language: "language", + Location: "location", + LocationAddress: "location_address", + LocationAddressStreet: "location_address_street", + LocationCity: "location_city", + LocationCoordinate: "location_coordinate", + LocationCountry: "location_country", + LocationState: "location_state", + LocationZip: "location_zip", + MaritalStatus: "marital_status", + MedicalCode: "medical_code", + MedicalProcess: "medical_process", + Money: "money", + Name: "name", + NameFamily: "name_family", + NameGiven: "name_given", + NameMedicalProfessional: "name_medical_professional", + NumericalPii: "numerical_pii", + Occupation: "occupation", + Organization: "organization", + OrganizationMedicalFacility: "organization_medical_facility", + Origin: "origin", + PassportNumber: "passport_number", + Password: "password", + PhoneNumber: "phone_number", + PhysicalAttribute: "physical_attribute", + PoliticalAffiliation: "political_affiliation", + Product: "product", + Religion: "religion", + RoutingNumber: "routing_number", + Ssn: "ssn", + Statistics: "statistics", + Time: "time", + Trend: "trend", + Url: "url", + Username: "username", + VehicleId: "vehicle_id", + ZodiacSign: "zodiac_sign", +} as const; diff --git a/src/ _generated_/rest/api/types/EntityTypes.ts b/src/ _generated_/rest/api/types/EntityTypes.ts new file mode 100644 index 00000000..44630141 --- /dev/null +++ b/src/ _generated_/rest/api/types/EntityTypes.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Entities to detect and de-identify. + */ +export type EntityTypes = Skyflow.EntityType[]; diff --git a/src/ _generated_/rest/api/types/ErrorResponse.ts b/src/ _generated_/rest/api/types/ErrorResponse.ts new file mode 100644 index 00000000..822dd151 --- /dev/null +++ b/src/ _generated_/rest/api/types/ErrorResponse.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +export interface ErrorResponse { + error: Skyflow.ErrorResponseError; +} diff --git a/src/ _generated_/rest/api/types/ErrorResponseError.ts b/src/ _generated_/rest/api/types/ErrorResponseError.ts new file mode 100644 index 00000000..6b4777f3 --- /dev/null +++ b/src/ _generated_/rest/api/types/ErrorResponseError.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface ErrorResponseError { + /** gRPC status codes. See https://grpc.io/docs/guides/status-codes. */ + grpc_code: number; + /** HTTP status codes. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status. */ + http_code: number; + /** HTTP status message. */ + http_status: string; + message: string; + details?: Record[]; +} diff --git a/src/ _generated_/rest/api/types/ErrorString.ts b/src/ _generated_/rest/api/types/ErrorString.ts new file mode 100644 index 00000000..78dd85f5 --- /dev/null +++ b/src/ _generated_/rest/api/types/ErrorString.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Error message. + */ +export type ErrorString = string; diff --git a/src/ _generated_/rest/api/types/ProcessedFileOutputProcessedFileType.ts b/src/ _generated_/rest/api/types/ProcessedFileOutputProcessedFileType.ts new file mode 100644 index 00000000..d70d15a5 --- /dev/null +++ b/src/ _generated_/rest/api/types/ProcessedFileOutputProcessedFileType.ts @@ -0,0 +1,41 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Indicates type of processed_file. + * + * - none: Nothing is set. + * - redacted_audio: Processed file is audio. + * - redacted_image: Processed file is image. + * - redacted_transcription: Processed file is transcribed data. + * - redacted_file: Processed file contains redacted file data. + * - redacted_text: Processed file contains redacted text. + * - entities: Processed file contains entities. + * - redacted_aws_transcription_diarize_json: Processed file contains aws transcribed redacted json. + * - redacted_deepgram_transcription_diarize_json: Processed file contains deepgram transcribed redacted json. + * - plaintext_transcribed: Processed file contains deepgram plain transcribed json. + */ +export type ProcessedFileOutputProcessedFileType = + | "none" + | "redacted_audio" + | "redacted_image" + | "redacted_transcription" + | "redacted_file" + | "redacted_text" + | "entities" + | "redacted_aws_transcription_diarize_json" + | "redacted_deepgram_transcription_diarize_json" + | "plaintext_transcribed"; +export const ProcessedFileOutputProcessedFileType = { + None: "none", + RedactedAudio: "redacted_audio", + RedactedImage: "redacted_image", + RedactedTranscription: "redacted_transcription", + RedactedFile: "redacted_file", + RedactedText: "redacted_text", + Entities: "entities", + RedactedAwsTranscriptionDiarizeJson: "redacted_aws_transcription_diarize_json", + RedactedDeepgramTranscriptionDiarizeJson: "redacted_deepgram_transcription_diarize_json", + PlaintextTranscribed: "plaintext_transcribed", +} as const; diff --git a/src/ _generated_/rest/api/types/ReidentifyStringResponse.ts b/src/ _generated_/rest/api/types/ReidentifyStringResponse.ts new file mode 100644 index 00000000..a1d61ad4 --- /dev/null +++ b/src/ _generated_/rest/api/types/ReidentifyStringResponse.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Re-identify string response. + */ +export interface ReidentifyStringResponse { + /** Re-identified text. */ + processed_text?: string; +} diff --git a/src/ _generated_/rest/api/types/ResourceId.ts b/src/ _generated_/rest/api/types/ResourceId.ts new file mode 100644 index 00000000..b9d80732 --- /dev/null +++ b/src/ _generated_/rest/api/types/ResourceId.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * ID of a resource. + */ +export type ResourceId = string; diff --git a/src/ _generated_/rest/api/types/RestrictRegex.ts b/src/ _generated_/rest/api/types/RestrictRegex.ts new file mode 100644 index 00000000..1f6a47aa --- /dev/null +++ b/src/ _generated_/rest/api/types/RestrictRegex.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Regular expressions to replace with '[RESTRICTED]'. Expressions must match the entirety of a detected entity, not just a substring, for the entity to be restricted. Expressions don't match across entity boundaries. If a string or entity matches both `allow_regex` and `restrict_regex`, the entity is displayed in plaintext. + */ +export type RestrictRegex = string[]; diff --git a/src/ _generated_/rest/api/types/TokenType.ts b/src/ _generated_/rest/api/types/TokenType.ts new file mode 100644 index 00000000..823af7cd --- /dev/null +++ b/src/ _generated_/rest/api/types/TokenType.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Mapping of tokens to generation for detected entities. Can't be specified together with `token_type`. + */ +export interface TokenType { + default?: Skyflow.TokenTypeDefault; + /** Entity types to replace with vault tokens. */ + vault_token?: Skyflow.EntityType[]; + /** Entity types to replace with entity tokens with unique counters. */ + entity_unq_counter?: Skyflow.EntityType[]; + /** Entity types to replace with entity tokens. */ + entity_only?: Skyflow.EntityType[]; +} diff --git a/src/ _generated_/rest/api/types/TokenTypeDefault.ts b/src/ _generated_/rest/api/types/TokenTypeDefault.ts new file mode 100644 index 00000000..6453d7c8 --- /dev/null +++ b/src/ _generated_/rest/api/types/TokenTypeDefault.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type TokenTypeDefault = "entity_only" | "entity_unq_counter" | "vault_token"; +export const TokenTypeDefault = { + EntityOnly: "entity_only", + EntityUnqCounter: "entity_unq_counter", + VaultToken: "vault_token", +} as const; diff --git a/src/ _generated_/rest/api/types/TokenTypeWithoutVault.ts b/src/ _generated_/rest/api/types/TokenTypeWithoutVault.ts new file mode 100644 index 00000000..07e0ff9b --- /dev/null +++ b/src/ _generated_/rest/api/types/TokenTypeWithoutVault.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Mapping of tokens to generation for detected entities. Can't be specified together with `token_type`. + */ +export interface TokenTypeWithoutVault { + default?: Skyflow.TokenTypeWithoutVaultDefault; + /** Entity types to replace with entity tokens with unique counters. */ + entity_unq_counter?: Skyflow.EntityType[]; + /** Entity types to replace with entity tokens. */ + entity_only?: Skyflow.EntityType[]; +} diff --git a/src/ _generated_/rest/api/types/TokenTypeWithoutVaultDefault.ts b/src/ _generated_/rest/api/types/TokenTypeWithoutVaultDefault.ts new file mode 100644 index 00000000..6e1a58df --- /dev/null +++ b/src/ _generated_/rest/api/types/TokenTypeWithoutVaultDefault.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type TokenTypeWithoutVaultDefault = "entity_only" | "entity_unq_counter"; +export const TokenTypeWithoutVaultDefault = { + EntityOnly: "entity_only", + EntityUnqCounter: "entity_unq_counter", +} as const; diff --git a/src/ _generated_/rest/api/types/Transformations.ts b/src/ _generated_/rest/api/types/Transformations.ts new file mode 100644 index 00000000..da11b88a --- /dev/null +++ b/src/ _generated_/rest/api/types/Transformations.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Transformations to apply to the detected entities. + */ +export interface Transformations { + /** Shift dates by a specified number of days. */ + shift_dates?: Skyflow.TransformationsShiftDates; +} diff --git a/src/ _generated_/rest/api/types/TransformationsShiftDates.ts b/src/ _generated_/rest/api/types/TransformationsShiftDates.ts new file mode 100644 index 00000000..ee24dfcb --- /dev/null +++ b/src/ _generated_/rest/api/types/TransformationsShiftDates.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Shift dates by a specified number of days. + */ +export interface TransformationsShiftDates { + /** Maximum number of days to shift the date by. */ + max_days?: number; + /** Minimum number of days to shift the date by. */ + min_days?: number; + /** Entity types to shift dates for. */ + entity_types?: Skyflow.TransformationsShiftDatesEntityTypesItem[]; +} diff --git a/src/ _generated_/rest/api/types/TransformationsShiftDatesEntityTypesItem.ts b/src/ _generated_/rest/api/types/TransformationsShiftDatesEntityTypesItem.ts new file mode 100644 index 00000000..60f41ebd --- /dev/null +++ b/src/ _generated_/rest/api/types/TransformationsShiftDatesEntityTypesItem.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type TransformationsShiftDatesEntityTypesItem = "date" | "date_interval" | "dob"; +export const TransformationsShiftDatesEntityTypesItem = { + Date: "date", + DateInterval: "date_interval", + Dob: "dob", +} as const; diff --git a/src/ _generated_/rest/api/types/Uuid.ts b/src/ _generated_/rest/api/types/Uuid.ts new file mode 100644 index 00000000..b5af5445 --- /dev/null +++ b/src/ _generated_/rest/api/types/Uuid.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * UUID. + */ +export type Uuid = string; diff --git a/src/ _generated_/rest/api/types/V1AdvancedOptions.ts b/src/ _generated_/rest/api/types/V1AdvancedOptions.ts new file mode 100644 index 00000000..33ca50f4 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1AdvancedOptions.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Advanced options for post processing. + */ +export interface V1AdvancedOptions { + /** No. of days by which original date has to be shifted to. */ + date_shift?: number; + /** Custom client specific logic. */ + custom_client?: boolean; + schema?: Skyflow.AdvancedOptionsVaultSchema; +} diff --git a/src/ _generated_/rest/api/types/V1AudioConfig.ts b/src/ _generated_/rest/api/types/V1AudioConfig.ts new file mode 100644 index 00000000..33b4d814 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1AudioConfig.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * How to handle audio files. + */ +export interface V1AudioConfig { + output_transcription?: Skyflow.AudioConfigTranscriptionType; + /** If `true`, includes processed audio file in the response. */ + output_processed_audio?: boolean; + options?: Skyflow.V1AudioOptions; +} diff --git a/src/ _generated_/rest/api/types/V1AudioOptions.ts b/src/ _generated_/rest/api/types/V1AudioOptions.ts new file mode 100644 index 00000000..c30377cd --- /dev/null +++ b/src/ _generated_/rest/api/types/V1AudioOptions.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Options for audio files. + */ +export interface V1AudioOptions { + /** Padding added to the beginning of a bleep, in seconds. */ + bleep_start_padding?: number; + /** Padding added to the end of a bleep, in seconds. */ + bleep_end_padding?: number; + /** Specifies how the distortion will be made. Providing a number more than 0 will result in a higher tone and a coefficient less than 0 will result in a lower tone. */ + distortion_steps?: number; + /** This parameter configures the frequency of the sine wave used for the bleep sound in an audio segment. */ + bleep_frequency?: number; + /** It controls the relative loudness of the bleep,positive values increase its loudness, and negative values decrease it. */ + bleep_gain?: number; +} diff --git a/src/ _generated_/rest/api/types/V1DetectFileResponse.ts b/src/ _generated_/rest/api/types/V1DetectFileResponse.ts new file mode 100644 index 00000000..51e69905 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1DetectFileResponse.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Response to deidentify a file. + */ +export interface V1DetectFileResponse { + /** Status URL for the deidentification request. */ + status_url?: string; +} diff --git a/src/ _generated_/rest/api/types/V1DetectStatusResponse.ts b/src/ _generated_/rest/api/types/V1DetectStatusResponse.ts new file mode 100644 index 00000000..c6fdd92e --- /dev/null +++ b/src/ _generated_/rest/api/types/V1DetectStatusResponse.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Response to get the status of a file deidentification request. + */ +export interface V1DetectStatusResponse { + status?: Skyflow.V1DetectStatusResponseStatus; + /** How the input file was specified. */ + output?: Skyflow.V1ProcessedFileOutput[]; + /** Status details about the deidentification request. */ + message?: string; +} diff --git a/src/ _generated_/rest/api/types/V1DetectStatusResponseStatus.ts b/src/ _generated_/rest/api/types/V1DetectStatusResponseStatus.ts new file mode 100644 index 00000000..ef62b56c --- /dev/null +++ b/src/ _generated_/rest/api/types/V1DetectStatusResponseStatus.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Status of the deidentification request. + * + * - UNKNOWN: Unknown status. + * - FAILED: Deidentification failed. + * - SUCCESS: Deidentification succeeded. + * - IN_PROGRESS: Deidentification ongoing. + */ +export type V1DetectStatusResponseStatus = "UNKNOWN" | "FAILED" | "SUCCESS" | "IN_PROGRESS"; +export const V1DetectStatusResponseStatus = { + Unknown: "UNKNOWN", + Failed: "FAILED", + Success: "SUCCESS", + InProgress: "IN_PROGRESS", +} as const; diff --git a/src/ _generated_/rest/api/types/V1DetectTextRequest.ts b/src/ _generated_/rest/api/types/V1DetectTextRequest.ts new file mode 100644 index 00000000..582e856f --- /dev/null +++ b/src/ _generated_/rest/api/types/V1DetectTextRequest.ts @@ -0,0 +1,30 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Request to deidentify a string. + */ +export interface V1DetectTextRequest { + /** Data to deidentify. */ + text: string; + /** ID of the vault. */ + vault_id: string; + /** Will give a handle to delete the tokens generated during a specific interaction. */ + session_id?: string; + /** Entities to detect and deidentify. */ + restrict_entity_types?: Skyflow.DetectDataEntities[]; + deidentify_token_format?: Skyflow.DetectRequestDeidentifyOption; + /** Regular expressions to ignore when detecting entities. */ + allow_regex?: string[]; + /** Regular expressions to always restrict. Strings matching these regular expressions are replaced with 'RESTRICTED'. */ + restrict_regex?: string[]; + /** If `true`, returns the details for the detected entities. */ + return_entities?: boolean; + accuracy?: Skyflow.DetectDataAccuracy; + advanced_options?: Skyflow.V1AdvancedOptions; + /** Indicates whether entities should be stored in the vault. */ + store_entities?: boolean; +} diff --git a/src/ _generated_/rest/api/types/V1DetectTextResponse.ts b/src/ _generated_/rest/api/types/V1DetectTextResponse.ts new file mode 100644 index 00000000..be3c7788 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1DetectTextResponse.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Response to deidentify a string. + */ +export interface V1DetectTextResponse { + /** Deidentified text. If the input was a file, text that was extracted or transcribed from the file and deidentified. */ + processed_text?: string; + /** Detected entities. */ + entities?: Skyflow.V1ResponseEntities[]; +} diff --git a/src/ _generated_/rest/api/types/V1FileDataFormat.ts b/src/ _generated_/rest/api/types/V1FileDataFormat.ts new file mode 100644 index 00000000..56c2ee64 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1FileDataFormat.ts @@ -0,0 +1,68 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Supported input file data formats. + * + * - unknown: If data format is not provided. + * - mp3: Audio mp3 file. + * - wav: Audio wav file. + * - pdf: Text pdf file. + * - txt: Plain text file. + * - csv: CSV file. + * - json: JSON file. + * - jpg: JPG image file. + * - jpeg: JPEG image file. + * - tif: TIF image file. + * - tiff: TIFF image file. + * - png: PNG image file. + * - bmp: Bitmap image file. + * - xls: XLS Excel file. + * - xlsx: XLSX Excel file. + * - doc: DOC Word file. + * - docx: DOCS Word file. + * - ppt: PPT PowerPoint file. + * - pptx: PPTX PowerPoint file. + */ +export type V1FileDataFormat = + | "bmp" + | "csv" + | "doc" + | "docx" + | "jpeg" + | "jpg" + | "json" + | "mp3" + | "pdf" + | "png" + | "ppt" + | "pptx" + | "tif" + | "tiff" + | "txt" + | "unknown" + | "wav" + | "xls" + | "xlsx"; +export const V1FileDataFormat = { + Bmp: "bmp", + Csv: "csv", + Doc: "doc", + Docx: "docx", + Jpeg: "jpeg", + Jpg: "jpg", + Json: "json", + Mp3: "mp3", + Pdf: "pdf", + Png: "png", + Ppt: "ppt", + Pptx: "pptx", + Tif: "tif", + Tiff: "tiff", + Txt: "txt", + Unknown: "unknown", + Wav: "wav", + Xls: "xls", + Xlsx: "xlsx", +} as const; diff --git a/src/ _generated_/rest/api/types/V1ImageOptions.ts b/src/ _generated_/rest/api/types/V1ImageOptions.ts new file mode 100644 index 00000000..fb33b7fc --- /dev/null +++ b/src/ _generated_/rest/api/types/V1ImageOptions.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * How to handle image files. + */ +export interface V1ImageOptions { + /** If `true`, includes processed image in the output. */ + output_processed_image?: boolean; + /** If `true`, includes OCR text output in the response. */ + output_ocr_text?: boolean; +} diff --git a/src/ _generated_/rest/api/types/V1Locations.ts b/src/ _generated_/rest/api/types/V1Locations.ts new file mode 100644 index 00000000..82fc7d10 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1Locations.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Locations of an entity in the text. + */ +export interface V1Locations { + /** Index of the first character of the string in the original text. */ + start_index?: number; + /** Index of the last character of the string in the original text. */ + end_index?: number; + /** Index of the first character of the string in the processed text. */ + start_index_processed?: number; + /** Index of the last character of the string in the processed text. */ + end_index_processed?: number; +} diff --git a/src/ _generated_/rest/api/types/V1PdfConfig.ts b/src/ _generated_/rest/api/types/V1PdfConfig.ts new file mode 100644 index 00000000..74d58161 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1PdfConfig.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * How to handle PDF files. + */ +export interface V1PdfConfig { + options?: Skyflow.V1PdfOptions; +} diff --git a/src/ _generated_/rest/api/types/V1PdfOptions.ts b/src/ _generated_/rest/api/types/V1PdfOptions.ts new file mode 100644 index 00000000..efb2a664 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1PdfOptions.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * How to handle PDF files. + */ +export interface V1PdfOptions { + /** Pixel density at which to process the PDF file. */ + density?: number; + /** Max resolution at which to process the PDF file. */ + max_resolution?: number; +} diff --git a/src/ _generated_/rest/api/types/V1ProcessedFileOutput.ts b/src/ _generated_/rest/api/types/V1ProcessedFileOutput.ts new file mode 100644 index 00000000..7d40c433 --- /dev/null +++ b/src/ _generated_/rest/api/types/V1ProcessedFileOutput.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Contains details and contents of the processed file. + */ +export interface V1ProcessedFileOutput { + output_type?: Skyflow.DetectFileRequestDataType; + /** URL or base64-encoded data of the output. */ + processed_file?: string; + processed_file_type?: Skyflow.ProcessedFileOutputProcessedFileType; +} diff --git a/src/ _generated_/rest/api/types/V1ResponseEntities.ts b/src/ _generated_/rest/api/types/V1ResponseEntities.ts new file mode 100644 index 00000000..9554698f --- /dev/null +++ b/src/ _generated_/rest/api/types/V1ResponseEntities.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Skyflow from "../index"; + +/** + * Detected entities. + */ +export interface V1ResponseEntities { + /** Processed text of the entity. */ + processed_text?: string; + /** Original text of the entity. */ + original_text?: string; + location?: Skyflow.V1Locations; + /** Highest rated label. */ + best_label?: string; + /** Labels and their scores. */ + labels?: Record; +} diff --git a/src/ _generated_/rest/api/types/VaultId.ts b/src/ _generated_/rest/api/types/VaultId.ts new file mode 100644 index 00000000..6d06d4de --- /dev/null +++ b/src/ _generated_/rest/api/types/VaultId.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * ID of a vault you have Detect Invoker or Vault Owner permissions for. + */ +export type VaultId = string; diff --git a/src/ _generated_/rest/api/types/index.ts b/src/ _generated_/rest/api/types/index.ts index b3448324..6db978dd 100644 --- a/src/ _generated_/rest/api/types/index.ts +++ b/src/ _generated_/rest/api/types/index.ts @@ -9,6 +9,15 @@ export * from "./DetokenizeRecordResponseValueType"; export * from "./V1GetAuthTokenResponse"; export * from "./RedactionEnumRedaction"; export * from "./RequestActionType"; +export * from "./AdvancedOptionsColumnMapping"; +export * from "./AdvancedOptionsEntityColumnMap"; +export * from "./AdvancedOptionsVaultSchema"; +export * from "./AudioConfigTranscriptionType"; +export * from "./DetectDataAccuracy"; +export * from "./DetectDataEntities"; +export * from "./DetectFileRequestDataType"; +export * from "./DetectRequestDeidentifyOption"; +export * from "./ProcessedFileOutputProcessedFileType"; export * from "./GooglerpcStatus"; export * from "./ProtobufAny"; export * from "./V1AuditAfterOptions"; @@ -41,3 +50,45 @@ export * from "./V1TokenizeResponse"; export * from "./V1UpdateRecordResponse"; export * from "./V1VaultFieldMapping"; export * from "./V1VaultSchemaConfig"; +export * from "./V1AdvancedOptions"; +export * from "./V1AudioConfig"; +export * from "./V1AudioOptions"; +export * from "./V1DetectFileResponse"; +export * from "./V1DetectStatusResponse"; +export * from "./V1DetectStatusResponseStatus"; +export * from "./V1DetectTextRequest"; +export * from "./V1DetectTextResponse"; +export * from "./V1FileDataFormat"; +export * from "./V1ImageOptions"; +export * from "./V1Locations"; +export * from "./V1PdfConfig"; +export * from "./V1PdfOptions"; +export * from "./V1ProcessedFileOutput"; +export * from "./V1ResponseEntities"; +export * from "./EntityType"; +export * from "./ErrorString"; +export * from "./ErrorResponseError"; +export * from "./ErrorResponse"; +export * from "./DeidentifyStatusResponseStatus"; +export * from "./DeidentifyStatusResponseOutputType"; +export * from "./DeidentifyStatusResponse"; +export * from "./EntityLocation"; +export * from "./DeidentifyFileOutputProcessedFileType"; +export * from "./DeidentifyFileOutput"; +export * from "./DetectedEntity"; +export * from "./TokenTypeDefault"; +export * from "./TokenType"; +export * from "./TokenTypeWithoutVaultDefault"; +export * from "./TokenTypeWithoutVault"; +export * from "./DeidentifyStringResponse"; +export * from "./TransformationsShiftDatesEntityTypesItem"; +export * from "./TransformationsShiftDates"; +export * from "./Transformations"; +export * from "./VaultId"; +export * from "./AllowRegex"; +export * from "./RestrictRegex"; +export * from "./EntityTypes"; +export * from "./DeidentifyFileResponse"; +export * from "./ReidentifyStringResponse"; +export * from "./Uuid"; +export * from "./ResourceId"; diff --git a/src/error/codes/index.ts b/src/error/codes/index.ts index fc312b84..71a1ee08 100644 --- a/src/error/codes/index.ts +++ b/src/error/codes/index.ts @@ -189,6 +189,41 @@ const SKYFLOW_ERROR_CODE = { EMPTY_VAULT_CLIENTS: { http_code: 400, message: errorMessages.EMPTY_VAULT_CLIENTS }, EMPTY_CONNECTION_CLIENTS: { http_code: 400, message: errorMessages.EMPTY_CONNECTION_CLIENTS }, + + INVALID_TEXT_IN_DEIDENTIFY: { http_code: 400, message: errorMessages.INVALID_TEXT_IN_DEIDENTIFY }, + INVALID_ENTITIES_IN_DEIDENTIFY: { http_code: 400, message: errorMessages.INVALID_ENTITIES_IN_DEIDENTIFY }, + 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_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 }, + INVALID_PLAIN_TEXT_ENTITIES_IN_REIDENTIFY: { http_code: 400, message: errorMessages.INVALID_PLAIN_TEXT_ENTITIES_IN_REIDENTIFY }, + + 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_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_WAIT_TIME:{ http_code: 400, message: errorMessages.INVALID_WAIT_TIME }, + INVALID_OUTPUT_DIRECTORY:{ http_code: 400, message: errorMessages.INVALID_OUTPUT_DIRECTORY }, + INVALID_OUTPUT_DIRECTORY_PATH:{ http_code: 400, message: errorMessages.INVALID_OUTPUT_DIRECTORY_PATH }, }; export default SKYFLOW_ERROR_CODE; \ No newline at end of file diff --git a/src/error/messages/index.ts b/src/error/messages/index.ts index 8c9eab65..63554708 100644 --- a/src/error/messages/index.ts +++ b/src/error/messages/index.ts @@ -196,6 +196,47 @@ const errorMessages = { EMPTY_CONNECTION_CLIENTS: `${errorPrefix} Validation error. No connection config found. Please add a connection config`, GENERIC_API_ERROR: `${errorPrefix} Validation error. Invalid configuration. Please add a valid vault configuration`, + INVALID_TEXT_IN_DEIDENTIFY: `${errorPrefix} Validation error. The text field is required and must be a non-empty string. Specify a valid text.`, + INVALID_ENTITIES_IN_DEIDENTIFY: `${errorPrefix} Validation error. The entities field must be an array of DetectEntities enums. Specify a valid entities.`, + INVALID_ALLOW_REGEX_LIST: `${errorPrefix} Validation error. The allowRegexList field must be an array of strings. Specify a valid allowRegexList.`, + 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_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.`, + INVALID_MASKED_ENTITIES_IN_REIDENTIFY: `${errorPrefix} Validation error. The maskedEntities field must be an array of DetectEntities enums. Specify a valid maskedEntities.`, + INVALID_PLAIN_TEXT_ENTITIES_IN_REIDENTIFY: `${errorPrefix} Validation error. The plainTextEntities field must be an array of DetectEntities enums. Specify a valid plainTextEntities.`, + + 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.`, + 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.`, + 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_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_WAIT_TIME: `${errorPrefix} Validation error. Invalid wait time. Specify a valid wait time as number and should not be greater than 20 secs.`, + INVALID_OUTPUT_DIRECTORY: `${errorPrefix} Validation error. Invalid output directory. Specify a valid output directory as string.`, + INVALID_OUTPUT_DIRECTORY_PATH: `${errorPrefix} Validation error. Invalid output directory path. Specify a valid output directory path as string.`, }; export default errorMessages; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 145621f4..e4c99f0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import Skyflow from './vault/skyflow'; -import { LogLevel, Env, RedactionType, RequestMethod, OrderByEnum, TokenMode } from './utils'; +import { LogLevel, Env, RedactionType, RequestMethod, OrderByEnum, TokenMode, DetectEntities } from './utils'; import InsertRequest from './vault/model/request/insert'; import InsertOptions from './vault/model/options/insert'; import GetRequest from './vault/model/request/get'; @@ -31,7 +31,19 @@ import { SkyflowConfig, TokenizeRequestType, DetokenizeData } from './vault/type import VaultConfig from './vault/config/vault'; import SkyflowError from './error'; import ConnectionConfig from './vault/config/connection'; - +import DeidentifyTextRequest from './vault/model/request/deidentify-text'; +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 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'; +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 { TokenType } from './utils'; +import { Bleep } from './vault/model/options/deidentify-file/bleep-audio'; export { Env, LogLevel, @@ -78,5 +90,19 @@ export { TokenizeRequest, TokenizeResponse, InvokeConnectionRequest, - InvokeConnectionResponse + InvokeConnectionResponse, + DeidentifyTextRequest, + DeidentifyTextOptions, + DetectEntities, + DeidentifyTextResponse, + ReidentifyTextRequest, + ReidentifyTextOptions, + ReidentifyTextResponse, + TokenFormat, + Transformations, + DeidentifyFileOptions, + DeidentifyFileRequest, + DeidentifyFileResponse, + TokenType, + Bleep }; \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index b75dce9f..020fc092 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -96,9 +96,115 @@ export const TYPES = { GET: 'GET', FILE_UPLOAD: 'FILE_UPLOAD', QUERY: 'QUERY', + 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 const CONTROLLER_TYPES = { + DETECT: 'DETECT', + VAULT: 'VAULT', + CONNECTION: 'CONNECTION', +} + +export enum DetectOutputTranscription { + DIARIZED_TRANSCRIPTION = "diarized_transcription", + MEDICAL_DIARIZED_TRANSCRIPTION = "medical_diarized_transcription", + MEDICAL_TRANSCRIPTION = "medical_transcription", + PLAINTEXT_TRANSCRIPTION = "plaintext_transcription", + TRANSCRIPTION = "transcription", +} + +export enum MaskingMethod{ + Blackout= "blackout", + Blur= "blur", +} + +export enum DetectEntities { + ACCOUNT_NUMBER = "account_number", + AGE = 'age', + ALL = 'all', + BANK_ACCOUNT = 'bank_account', + BLOOD_TYPE = 'blood_type', + CONDITION = 'condition', + CORPORATE_ACTION = 'corporate_action', + CREDIT_CARD = 'credit_card', + CREDIT_CARD_EXPIRATION = 'credit_card_expiration', + CVV = 'cvv', + DATE = 'date', + DATE_INTERVAL = 'date_interval', + DOB = 'dob', + DOSE = 'dose', + DRIVER_LICENSE = 'driver_license', + DRUG = 'drug', + DURATION = 'duration', + EMAIL_ADDRESS = 'email_address', + EVENT = 'event', + FILENAME = 'filename', + FINANCIAL_METRIC = 'financial_metric', + GENDER_SEXUALITY = 'gender_sexuality', + HEALTHCARE_NUMBER = 'healthcare_number', + INJURY = 'injury', + IP_ADDRESS = 'ip_address', + LANGUAGE = 'language', + LOCATION = 'location', + LOCATION_ADDRESS = 'location_address', + LOCATION_ADDRESS_STREET = 'location_address_street', + LOCATION_CITY = 'location_city', + LOCATION_COORDINATE = 'location_coordinate', + LOCATION_COUNTRY = 'location_country', + LOCATION_STATE = 'location_state', + LOCATION_ZIP = 'location_zip', + MARITAL_STATUS = 'marital_status', + MEDICAL_CODE = 'medical_code', + MEDICAL_PROCESS = 'medical_process', + MONEY = 'money', + NAME = 'name', + NAME_FAMILY = 'name_family', + NAME_GIVEN = 'name_given', + NAME_MEDICAL_PROFESSIONAL = 'name_medical_professional', + NUMERICAL_PII = 'numerical_pii', + OCCUPATION = 'occupation', + ORGANIZATION = 'organization', + ORGANIZATION_MEDICAL_FACILITY = 'organization_medical_facility', + ORIGIN = 'origin', + PASSPORT_NUMBER = 'passport_number', + PASSWORD = 'password', + PHONE_NUMBER = 'phone_number', + PHYSICAL_ATTRIBUTE = 'physical_attribute', + POLITICAL_AFFILIATION = 'political_affiliation', + PRODUCT = 'product', + RELIGION = 'religion', + ROUTING_NUMBER = 'routing_number', + SSN = 'ssn', + STATISTICS = 'statistics', + TIME = 'time', + TREND = 'trend', + URL = 'url', + USERNAME = 'username', + VEHICLE_ID = 'vehicle_id', + ZODIAC_SIGN = 'zodiac_sign', +} + +export enum TokenType { + ENTITY_UNIQUE_COUNTER = 'entity_unq_counter', + ENTITY_ONLY = 'entity_only', + VAULT_TOKEN = 'vault_token' +} + 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 3b4211a4..822c0966 100644 --- a/src/utils/logs/index.ts +++ b/src/utils/logs/index.ts @@ -9,6 +9,7 @@ const logs = { VALIDATING_VAULT_CONFIG: 'Validating vault config.', VALIDATING_CONNECTION_CONFIG: 'Validating connection config.', VAULT_CONTROLLER_INITIALIZED: 'Initialized vault controller with vault ID %s1.', + DETECT_CONTROLLER_INITIALIZED: 'Initialized detect controller with vault ID %s1.', CONNECTION_CONTROLLER_INITIALIZED: 'Intitialized connection controller with connection ID %s1.', vaultId_CONFIG_EXISTS: 'Vault config with vault ID %s1 already exists.', vaultId_CONFIG_DOES_NOT_EXIST: `Vault config with vault ID %s1 doesn't exist.`, @@ -65,7 +66,13 @@ const logs = { USING_API_KEY: 'Using api key from credentials', USING_CREDENTIALS_STRING: 'Using credentials string from credentials', USING_PATH: 'Using path from credentials', - USING_SKYFLOW_CREDENTIALS_ENV: 'Using SKYFLOW_CREDENTIALS from env' + USING_SKYFLOW_CREDENTIALS_ENV: 'Using SKYFLOW_CREDENTIALS from env', + DEIDENTIFY_TEXT_TRIGGERED: 'Deidentify text method triggered', + VALIDATE_DEIDENTIFY_TEXT_INPUT: 'Validating deidentify text input', + REIDENTIFY_TEXT_TRIGGERED: 'Reidentify text method triggered', + VALIDATE_REIDENTIFY_TEXT_INPUT: 'Validating reidentify text input', + VALIDATE_DETECT_FILE_INPUT: 'Validating deidentify file input.', + DETECT_FILE_TRIGGERED: 'Deidentify file triggered.', }, errorLogs: { VAULT_CONFIG_KEY_MISSING: "Invalid skyflow config. Vaults configs key missing in skyflow config.", diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index f930f913..427a5554 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -21,9 +21,18 @@ import TokenizeRequest from "../../vault/model/request/tokenize"; import UpdateRequest from "../../vault/model/request/update"; import { SkyflowConfig, StringKeyValueMapType } from "../../vault/types"; import * as fs from 'fs'; +import * as path from 'path'; import { isExpired } from "../jwt-utils"; import logs from "../logs"; import FileUploadOptions from "../../vault/model/options/fileUpload"; +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 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"; export function isEnv(value?: string): boolean { return value !== undefined && Object.values(Env).includes(value as Env); @@ -931,6 +940,170 @@ export const validateQueryRequest = (queryRequest: QueryRequest, logLevel: LogLe } } +export const validateDeIdentifyTextRequest = (deIdentifyTextRequest: DeidentifyTextRequest, options?: DeidentifyTextOptions, logLevel: LogLevel = LogLevel.ERROR) => { + if (!deIdentifyTextRequest.text || typeof deIdentifyTextRequest.text !== 'string' || deIdentifyTextRequest.text.trim().length === 0) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TEXT_IN_DEIDENTIFY); + } + + if (options) { + if (options.getEntities() && !Array.isArray(options.getEntities())) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ENTITIES_IN_DEIDENTIFY); + } + + if (options.getAllowRegexList() && !Array.isArray(options.getAllowRegexList())) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ALLOW_REGEX_LIST); + } + + if (options.getRestrictRegexList() && !Array.isArray(options.getRestrictRegexList())) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RESTRICT_REGEX_LIST); + } + + if (options.getTokenFormat() && !(options.getTokenFormat() instanceof TokenFormat)) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKEN_FORMAT); + } + + if (options.getTransformations() && !(options.getTransformations() instanceof Transformations)) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TRANSFORMATIONS); + } + } +}; + +export const validateReidentifyTextRequest = (request: ReidentifyTextRequest, options?: ReidentifyTextOptions, logLevel: LogLevel = LogLevel.ERROR) => { + if (!request.text || typeof request.text !== 'string' || request.text.trim().length === 0) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TEXT_IN_REIDENTIFY); + } + + if (options) { + if (options.getRedactedEntities() && !Array.isArray(options.getRedactedEntities())) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_REDACTED_ENTITIES_IN_REIDENTIFY); + } + + if (options.getMaskedEntities() && !Array.isArray(options.getMaskedEntities())) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_MASKED_ENTITIES_IN_REIDENTIFY); + } + if (options.getPlainTextEntities() && !Array.isArray(options.getPlainTextEntities())) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_PLAIN_TEXT_ENTITIES_IN_REIDENTIFY); + } + } +}; + + +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 + if (file instanceof File) { + if (!file.name || typeof file.name !== 'string' || file.name.trim().length === 0) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE); + } + // Validate fileBaseName + const fileBaseName = path.parse(file.name).name; + if (!fileBaseName || typeof fileBaseName !== 'string' || fileBaseName.trim().length === 0) { + 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 waitTime + const waitTime = deidentifyFileOptions.getWaitTime(); + if (waitTime !== undefined) { + if (typeof waitTime !== 'number' || waitTime > 20) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_WAIT_TIME); + } + } + + // Validate outputDirectory + const outputDirectory = deidentifyFileOptions.getOutputDirectory(); + if (outputDirectory !== undefined) { + if (typeof outputDirectory !== 'string') { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OUTPUT_DIRECTORY); + } + if (!fs.existsSync(outputDirectory) || !fs.lstatSync(outputDirectory).isDirectory()) { + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OUTPUT_DIRECTORY_PATH); + } + } + + // 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); + } +}; + function isStringKeyValueMap(obj: any): obj is StringKeyValueMapType { if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) { return false; diff --git a/src/vault/client/index.ts b/src/vault/client/index.ts index 357f0a25..acf068bc 100644 --- a/src/vault/client/index.ts +++ b/src/vault/client/index.ts @@ -1,6 +1,8 @@ // 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"; import { Tokens } from "../../ _generated_/rest/api/resources/tokens/client/Client"; import SkyflowError from "../../error"; import errorMessages from "../../error/messages"; @@ -23,6 +25,10 @@ class VaultClient { queryAPI!: Query; + stringsAPI!: Strings; + + filesAPI!: Files; + individualCredentials?: Credentials; skyflowCredentials?: Credentials; @@ -77,6 +83,12 @@ class VaultClient { case TYPES.QUERY: this.queryAPI = new Query(this.configuration); 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 e467a486..9a5a11fc 100644 --- a/src/vault/controller/detect/index.ts +++ b/src/vault/controller/detect/index.ts @@ -1,27 +1,650 @@ //imports +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, TokenTypeWithoutVault } from "../../../ _generated_/rest/api"; +import { DeidentifyFileRequest as DeidentifyFileRequest2} from "../../../ _generated_/rest/api"; + +import { TokenType } from "../../../ _generated_/rest/api"; +import { DeidenitfyFileRequestTypes, generateSDKMetrics, getBearerToken, MessageType, parameterizedString, printLog, removeSDKVersion, SDK_METRICS_HEADER_KEY, TYPES } from "../../../utils"; +import logs from "../../../utils/logs"; +import { validateDeIdentifyTextRequest, validateReidentifyTextRequest, validateDeidentifyFileRequest } from "../../../utils/validations"; +import VaultClient from "../../client"; +import DeidentifyTextOptions from "../../model/options/deidentify-text"; +import ReidentifyTextOptions from "../../model/options/reidentify-text"; +import DeidentifyTextRequest from "../../model/request/deidentify-text"; +import ReidentifyTextRequest from "../../model/request/reidentify-text"; +import DeidentifiedTextResponse from "../../model/response/deidentify-text"; +import DeidentifyTextResponse from "../../model/response/deidentify-text"; +import ReidentifyTextResponse from "../../model/response/reidentify-text"; +import DeidentifyFileOptions from "../../model/options/deidentify-file"; +import DeidentifyFileRequest from "../../model/request/deidentify-file"; +import DeidentifyFileResponse from "../../model/response/deidentify-file"; +import * as fs from 'fs'; +import SkyflowError from "../../../error"; +import SKYFLOW_ERROR_CODE from "../../../error/codes"; + class DetectController { - constructor() { + private client: VaultClient; + + private waitTime: number = 20; + + constructor(client: VaultClient) { + this.client = client; + } + + private createSdkHeaders() { + return { [SDK_METRICS_HEADER_KEY]: JSON.stringify(generateSDKMetrics()) }; + } + + private async getBase64FileContent(file: File){ + const arrayBuffer = await file.arrayBuffer(); + const buffer = Buffer.from(arrayBuffer); + const base64String = buffer.toString('base64'); + return base64String; + } + + private async buildAudioRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions, fileExtension?: string): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + var audioRequest : DeidentifyAudioRequest = { + file: { + base64: base64String as string, + data_format: fileExtension as DeidentifyAudioRequestFileDataFormat, + }, + vault_id: this.client.vaultId, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + 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 async buildTextFileRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + + var textFileRequest: DeidentifyTextRequest2 = { + vault_id: this.client.vaultId, + file: { + base64: base64String, + data_format: "txt", + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + } + return textFileRequest; + } + private async buildPdfRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + var pdfRequest: DeidentifyPdfRequest = { + file: { + base64: base64String as string, + data_format: "pdf", + }, + vault_id: this.client.vaultId, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + max_resolution: options?.getMaxResolution(), + density: options?.getDensity(), + } + return pdfRequest; + } + + private async buildImageRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions, fileExtension?: string): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + var imageRequest: DeidentifyImageRequest = { + vault_id: this.client.vaultId, + file: { + base64: base64String as string, + data_format: fileExtension 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?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + }; + + return imageRequest; + } + + private async buildPptRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions, fileExtension?: string): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + var pptRequest: DeidentifyPresentationRequest = { + vault_id: this.client.vaultId, + file: { + base64: base64String as string, + data_format: fileExtension as DeidentifyPresentationRequestFileDataFormat, + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + return pptRequest; + } + + private async buildSpreadsheetRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions, fileExtension?: string): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + var spreadsheetRequest: DeidentifySpreadsheetRequest = { + vault_id: this.client.vaultId, + file: { + base64: base64String as string, + data_format: fileExtension as DeidentifySpreadsheetRequestFileDataFormat, + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + return spreadsheetRequest; + } + + private async buildStructuredTextRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions, fileExtension?: string): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + var structuredTextRequest: DeidentifyStructuredTextRequest = { + vault_id: this.client.vaultId, + file: { + base64: base64String as string, + data_format: fileExtension as DeidentifyStructuredTextRequestFileDataFormat, + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + return structuredTextRequest; + } + + private async buildDocumentRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions, fileExtension?: string): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + var documentRequest: DeidentifyDocumentRequest = { + vault_id: this.client.vaultId, + file: { + base64: base64String as string, + data_format: fileExtension as DeidentifyDocumentRequestFileDataFormat, + }, + entity_types: options?.getEntities() as EntityType[], + token_type: { + default: options?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + }; + return documentRequest; + } + + private async buildGenericFileRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions, fileExtension?: string): Promise { + const base64String = await this.getBase64FileContent(baseRequest.getFile()); + var genericRequest: DeidentifyFileRequest2 = { + vault_id: this.client.vaultId, + file: { + base64: base64String as string, + data_format: fileExtension as DeidentifyAudioRequestFileDataFormat, + }, + token_type: { + default: options?.getTokenFormat()?.getDefault(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenTypeWithoutVault, + allow_regex: options?.getAllowRegexList(), + restrict_regex: options?.getRestrictRegexList(), + transformations: options?.getTransformations() as Transformations, + entity_types: options?.getEntities() as EntityType[], + } + return genericRequest; + } + + 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, fileBaseName: 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, processedFileExtension } = fileObject; + + if (!processedFile || !processedFileExtension) { + return; + } + + // Determine the output file name and path + const outputFileName = `processed-${fileBaseName}.${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 if ( processedFileExtension === 'mp3' || processedFileExtension === 'wav') { + const mp3Data = Buffer.from(processedFile, 'base64'); + fs.writeFileSync(outputFilePath, mp3Data, { encoding: 'binary' }); + } else { + // Handle other file types (e.g., images, PDFs, etc.) + this.decodeBase64AndSaveToFile(processedFile, outputFilePath); + } + }); + } catch (error) { + throw error; + } + } + + 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 pollForProcessedFile(runId: string, req: GetRunRequest, maxWaitTime: number, resolve: Function, reject: Function): void { + let currentWaitTime = 1; // Start with 1 second + + const poll = () => { + this.client.filesAPI.getRun(runId, req) + .then((response: any) => { + if (response.status === 'IN_PROGRESS') { + if (currentWaitTime > maxWaitTime) { + resolve({ runId }); // Resolve with runId if max wait time is exceeded + } else { + setTimeout(() => { + currentWaitTime *= 2; // Exponential backoff + poll(); + }, currentWaitTime * 1000); + } + } else if (response.status === 'SUCCESS') { + resolve(response); // Resolve with the processed file response + } + }) + .catch((error: any) => { + reject(error); + }); + }; + + poll(); // Start polling + } + 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()); + const sdkHeaders = this.createSdkHeaders(); + getBearerToken(this.client.getCredentials(), this.client.getLogLevel()).then(authInfo => { + this.client.initAPI(authInfo, requestType); + apiCall({ headers: { ...sdkHeaders } }) + .then((response: any) => { + const { data, rawResponse } = response; + const requestId = rawResponse?.headers?.get('x-request-id'); + printLog(logs.infoLogs[`${requestType}_REQUEST_RESOLVED`], MessageType.LOG, this.client.getLogLevel()); + switch (requestType) { + case TYPES.DETECT: + resolve({records: data, requestId}) + break; + case TYPES.DEIDENTIFY_FILE: + const req: GetRunRequest = { + vault_id: this.client.vaultId, + } + + const maxWaitTime = this.waitTime; + + this.pollForProcessedFile(data.run_id, req, maxWaitTime, resolve, reject); // Call the extracted polling function + break; + } + }).catch((error: any) => { + printLog(logs.errorLogs[`${requestType}_REQUEST_REJECTED`], MessageType.ERROR, this.client.getLogLevel()); + this.client.failureResponse(error).catch((err) => reject(err)) + }); + }).catch(reject); + }); } - static initialize() { - //return detect object + 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(), + token_type: { + default: options?.getTokenFormat()?.getDefault(), + vault_token: options?.getTokenFormat()?.getVaultToken(), + entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), + entity_only: options?.getTokenFormat()?.getEntityOnly(), + } as TokenType, + transformations: { + shift_dates: { + max_days: options?.getTransformations()?.getShiftDays()?.max, + min_days: options?.getTransformations()?.getShiftDays()?.min, + entity_types: options?.getTransformations()?.getShiftDays()?.entities, + } + } as Transformations, + }; } - deIdentify() { - return this; + private parseDeidentifyTextResponse(data: any) { + return { + processedText: data.records.processed_text, + entities: data.records.entities.map((entity: DetectedEntity) => ({ + token: entity.token, + value: entity.value, + textIndex: { + start: entity.location?.start_index, + end: entity.location?.end_index, + }, + processedIndex: { + start: entity.location?.start_index_processed, + end: entity.location?.end_index_processed, + }, + entity: entity.entity_type, + scores: entity.entity_scores, + })), + wordCount: data.records.word_count, + charCount: data.records.character_count, + }; } - text() { + deidentifyText(request: DeidentifyTextRequest, options?: DeidentifyTextOptions): Promise { + return new Promise((resolve, reject) => { + try { + printLog(logs.infoLogs.DEIDENTIFY_TEXT_TRIGGERED, MessageType.LOG, this.client.getLogLevel()); + printLog(logs.infoLogs.VALIDATE_DEIDENTIFY_TEXT_INPUT, MessageType.LOG, this.client.getLogLevel()); + + validateDeIdentifyTextRequest(request, options, this.client.getLogLevel()); + const requestBody = this.buildDeidentifyTextRequest(request, options); + this.handleRequest( + () => this.client.stringsAPI.deidentifyString( + requestBody + ).withRawResponse(), + TYPES.DETECT + ).then(data => { + const parsedResponse = new DeidentifyTextResponse(this.parseDeidentifyTextResponse(data)) + resolve(parsedResponse); + }).catch(error => { + reject(error) + }); + } catch (error) { + if (error instanceof Error) + printLog(removeSDKVersion(error.message), MessageType.ERROR, this.client.getLogLevel()); + reject(error); + } + }); } - file() { + reidentifyText(request: ReidentifyTextRequest, options?: ReidentifyTextOptions): Promise { + return new Promise((resolve, reject) => { + try { + printLog(logs.infoLogs.REIDENTIFY_TEXT_TRIGGERED, MessageType.LOG, this.client.getLogLevel()); + printLog(logs.infoLogs.VALIDATE_REIDENTIFY_TEXT_INPUT, MessageType.LOG, this.client.getLogLevel()); + validateReidentifyTextRequest(request, options, this.client.getLogLevel()); + const requestBody = { + text: request.text, + vault_id: this.client.vaultId, + format: { + redacted: options?.getRedactedEntities(), + masked: options?.getMaskedEntities(), + plaintext: options?.getPlainTextEntities(), + } + }; + this.handleRequest( + () => this.client.stringsAPI.reidentifyString( + requestBody + ).withRawResponse(), + TYPES.DETECT + ).then(data => { + resolve(new ReidentifyTextResponse({ + processedText: data.records.text + })); + }).catch(error => { + reject(error) + }); + + } catch (error) { + if (error instanceof Error) + printLog(removeSDKVersion(error.message), MessageType.ERROR, this.client.getLogLevel()); + reject(error); + } + }); } + 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()); + + const fileName = request.getFile().name; + const fileBaseName = path.parse(request.getFile().name).name; + const fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1); + + this.waitTime = options?.getWaitTime() ?? this.waitTime; + + var reqType : DeidenitfyFileRequestTypes = this.getReqType(fileExtension); + var promiseReq: Promise; + switch (reqType){ + case DeidenitfyFileRequestTypes.AUDIO: + promiseReq = this.buildAudioRequest(request, options, fileExtension) + .then((audioReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifyAudio( + audioReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + case DeidenitfyFileRequestTypes.TEXT: + promiseReq = this.buildTextFileRequest(request, options) + .then((textFileReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifyText( + textFileReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + case DeidenitfyFileRequestTypes.PDF: + promiseReq = this.buildPdfRequest(request, options) + .then((pdfReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifyPdf( + pdfReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + case DeidenitfyFileRequestTypes.IMAGE: + promiseReq = this.buildImageRequest(request, options, fileExtension) + .then((imageReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifyImage( + imageReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + case DeidenitfyFileRequestTypes.PPT: + promiseReq = this.buildPptRequest(request, options, fileExtension) + .then((pptReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifyPresentation( + pptReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + case DeidenitfyFileRequestTypes.SPREADSHEET: + promiseReq = this.buildSpreadsheetRequest(request, options, fileExtension) + .then((spreadsheetReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifySpreadsheet( + spreadsheetReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + case DeidenitfyFileRequestTypes.STRUCTURED_TEXT: + promiseReq = this.buildStructuredTextRequest(request, options, fileExtension) + .then((structuredTextReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifyStructuredText( + structuredTextReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + case DeidenitfyFileRequestTypes.DOCUMENT: + promiseReq = this.buildDocumentRequest(request, options, fileExtension) + .then((documentReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifyDocument( + documentReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + default: + promiseReq = this.buildGenericFileRequest(request, options, fileExtension) + .then((defaultReq) => { + return this.handleRequest( + () => this.client.filesAPI.deidentifyFile( + defaultReq + ).withRawResponse(), + TYPES.DEIDENTIFY_FILE + ); + }); + break; + } + + promiseReq.then(data => { + if(data.runId){ + resolve(new DeidentifyFileResponse({ + runId: data.runId, + })); + } + if (options?.getOutputDirectory() && data.status === "SUCCESS") { + this.processDeidentifyFileResponse(data, options.getOutputDirectory() as string, fileBaseName); + } + 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); + } + }); + } } export default DetectController; diff --git a/src/vault/controller/vault/index.ts b/src/vault/controller/vault/index.ts index b504bb74..82d6db59 100644 --- a/src/vault/controller/vault/index.ts +++ b/src/vault/controller/vault/index.ts @@ -37,7 +37,6 @@ class VaultController { constructor(client: VaultClient) { this.client = client; - printLog(logs.infoLogs.CONTROLLER_INITIALIZED, MessageType.LOG, this.client.getLogLevel()); } private createSdkHeaders() { 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..630dd8af --- /dev/null +++ b/src/vault/model/options/deidentify-file/bleep-audio/index.ts @@ -0,0 +1,31 @@ +export 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..0444a15c --- /dev/null +++ b/src/vault/model/options/deidentify-file/index.ts @@ -0,0 +1,155 @@ +import { DetectEntities, DetectOutputTranscription, MaskingMethod } from "../../../../utils"; +import TokenFormat from "../deidentify-text/token-format"; +import Transformations from "../deidentify-text/transformations"; +import { Bleep } from './bleep-audio' + + +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 _density?: number; + private _waitTime?: number; + + constructor() { + } + + getDensity(): number | undefined{ + return this._density; + } + setDensity(density: number) { + this._density = density; + } + + 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; + } + + getWaitTime(): number | undefined { + return this._waitTime; + } + + setWaitTime(waitTime: number | undefined) { + this._waitTime = waitTime; + } +} + +export default DeidentifyFileOptions; diff --git a/src/vault/model/options/deidentify-text/index.ts b/src/vault/model/options/deidentify-text/index.ts new file mode 100644 index 00000000..0fcbb078 --- /dev/null +++ b/src/vault/model/options/deidentify-text/index.ts @@ -0,0 +1,56 @@ +import { DetectEntities } from "../../../../utils"; +import TokenFormat from "./token-format"; +import Transformations from "./transformations"; + +class DeidentifyTextOptions { + // Fields + private _entities?: DetectEntities[]; + private _allowRegexList?: string[]; + private _restrictRegexList?: string[]; + private _tokenFormat?: TokenFormat; + private _transformations?: Transformations; + + // Setters + setEntities(entities: DetectEntities[]) { + this._entities = entities; + } + + setAllowRegexList(allowRegexList: string[]) { + this._allowRegexList = allowRegexList; + } + + setRestrictRegexList(restrictRegexList: string[]) { + this._restrictRegexList = restrictRegexList; + } + + setTokenFormat(tokenFormat: TokenFormat) { + this._tokenFormat = tokenFormat; + } + + setTransformations(transformations: Transformations) { + this._transformations = transformations; + } + + // Getters + getEntities(): DetectEntities[] | undefined { + return this._entities; + } + + getAllowRegexList(): string[] | undefined { + return this._allowRegexList; + } + + getRestrictRegexList(): string[] | undefined { + return this._restrictRegexList; + } + + getTokenFormat(): TokenFormat | undefined { + return this._tokenFormat; + } + + getTransformations(): Transformations | undefined { + return this._transformations; + } +} + +export default DeidentifyTextOptions; \ No newline at end of file diff --git a/src/vault/model/options/deidentify-text/token-format/index.ts b/src/vault/model/options/deidentify-text/token-format/index.ts new file mode 100644 index 00000000..a2c6fb07 --- /dev/null +++ b/src/vault/model/options/deidentify-text/token-format/index.ts @@ -0,0 +1,45 @@ +import { DetectEntities, TokenType } from "../../../../../utils"; + +class TokenFormat { + // Fields + private _default?: TokenType = TokenType.ENTITY_UNIQUE_COUNTER; + private _vaultToken?: DetectEntities[]; + private _entityUniqueCounter?: DetectEntities[]; + private _entityOnly?: DetectEntities[]; + + // Setters + setDefault(defaultToken: TokenType) { + this._default = defaultToken; + } + + setVaultToken(vaultToken: DetectEntities[]) { + this._vaultToken = vaultToken; + } + + setEntityUniqueCounter(entityUniqueCounter: DetectEntities[]) { + this._entityUniqueCounter = entityUniqueCounter; + } + + setEntityOnly(entityOnly: DetectEntities[]) { + this._entityOnly = entityOnly; + } + + // Getters + getDefault(): string | undefined { + return this._default; + } + + getVaultToken(): string[] | undefined { + return this._vaultToken; + } + + getEntityUniqueCounter(): string[] | undefined { + return this._entityUniqueCounter; + } + + getEntityOnly(): string[] | undefined { + return this._entityOnly; + } +} + +export default TokenFormat; \ No newline at end of file diff --git a/src/vault/model/options/deidentify-text/transformations/index.ts b/src/vault/model/options/deidentify-text/transformations/index.ts new file mode 100644 index 00000000..85fa2612 --- /dev/null +++ b/src/vault/model/options/deidentify-text/transformations/index.ts @@ -0,0 +1,22 @@ +import { DetectEntities } from "../../../../../utils"; + +class Transformations { + // Fields + private _shiftDays?: { + max: number; + min: number; + entities: DetectEntities[]; + }; + + // Setters + setShiftDays(shiftDays: { max: number; min: number; entities: DetectEntities[] }) { + this._shiftDays = shiftDays; + } + + // Getters + getShiftDays(): { max: number; min: number; entities: DetectEntities[] } | undefined { + return this._shiftDays; + } +} + +export default Transformations; \ No newline at end of file diff --git a/src/vault/model/options/reidentify-text/index.ts b/src/vault/model/options/reidentify-text/index.ts new file mode 100644 index 00000000..3cbd69e9 --- /dev/null +++ b/src/vault/model/options/reidentify-text/index.ts @@ -0,0 +1,36 @@ +import { DetectEntities } from "../../../../utils"; + +class ReidentifyTextOptions { + // Fields + private _redactedEntities?: DetectEntities[]; + private _maskedEntities?: DetectEntities[]; + private _plainTextEntities?: DetectEntities[]; + + // Setters + setRedactedEntities(redactedEntities: DetectEntities[]) { + this._redactedEntities = redactedEntities; + } + + setMaskedEntities(maskedEntities: DetectEntities[]) { + this._maskedEntities = maskedEntities; + } + + setPlainTextEntities(plainTextEntities: DetectEntities[]) { + this._plainTextEntities = plainTextEntities; + } + + // Getters + getRedactedEntities(): DetectEntities[] | undefined { + return this._redactedEntities; + } + + getMaskedEntities(): DetectEntities[] | undefined { + return this._maskedEntities; + } + + getPlainTextEntities(): DetectEntities[] | undefined { + return this._plainTextEntities; + } +} + +export default ReidentifyTextOptions; \ 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/request/deidentify-text/index.ts b/src/vault/model/request/deidentify-text/index.ts new file mode 100644 index 00000000..668a814c --- /dev/null +++ b/src/vault/model/request/deidentify-text/index.ts @@ -0,0 +1,21 @@ +class DeidentifyTextRequest { + // Field + private _text: string; + + // Constructor + constructor(text: string) { + this._text = text; + } + + // Getter for text + public get text(): string { + return this._text; + } + + // Setter for text + public set text(value: string) { + this._text = value; + } +} + +export default DeidentifyTextRequest; \ No newline at end of file diff --git a/src/vault/model/request/reidentify-text/index.ts b/src/vault/model/request/reidentify-text/index.ts new file mode 100644 index 00000000..d83d3809 --- /dev/null +++ b/src/vault/model/request/reidentify-text/index.ts @@ -0,0 +1,21 @@ +class ReidentifyTextRequest { + // Field + private _text: string; + + // Constructor + constructor(text: string) { + this._text = text; + } + + // Getter for text + public get text(): string { + return this._text; + } + + // Setter for text + public set text(value: string) { + this._text = value; + } +} + +export default ReidentifyTextRequest; \ 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..214802ba --- /dev/null +++ b/src/vault/model/response/deidentify-file/index.ts @@ -0,0 +1,64 @@ +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; + runId?: string; + + constructor({ + file, + type, + outputType, + extension, + wordCount, + charCount, + sizeInKb, + durationInSeconds, + pageCount, + slideCount, + entities, + runId + } :{ + 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; + }>; + runId?: 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; + this.runId = runId; + } + +} + +export default DeidentifyFileResponse; \ No newline at end of file diff --git a/src/vault/model/response/deidentify-text/index.ts b/src/vault/model/response/deidentify-text/index.ts new file mode 100644 index 00000000..6d370720 --- /dev/null +++ b/src/vault/model/response/deidentify-text/index.ts @@ -0,0 +1,44 @@ +//imports + +class DeidentifyTextResponse { + //fields + processedText: string; + entities: Array<{ + token: string; + value: string; + textIndex: object; + processedIndex: object; + entity: string; + scores: object; + }>; + wordCount: number; + charCount: number; + + constructor({ + processedText, + entities, + wordCount, + charCount, + }: { + processedText: string; + entities: Array<{ + token: string; + value: string; + textIndex: object; + processedIndex: object; + entity: string; + scores: object; + }>; + wordCount: number; + charCount: number; + }) { + this.processedText = processedText; + this.entities = entities; + this.wordCount = wordCount; + this.charCount = charCount; + } + + //getters and setters +} + +export default DeidentifyTextResponse; \ No newline at end of file diff --git a/src/vault/model/response/reidentify-text/index.ts b/src/vault/model/response/reidentify-text/index.ts new file mode 100644 index 00000000..0aea2b99 --- /dev/null +++ b/src/vault/model/response/reidentify-text/index.ts @@ -0,0 +1,16 @@ +// imports + +class ReidentifyTextResponse { + //fields + processedText: string; + + constructor({ + processedText, + }: { + processedText: string; + }) { + this.processedText = processedText; + } +} + +export default ReidentifyTextResponse; \ No newline at end of file diff --git a/src/vault/skyflow/index.ts b/src/vault/skyflow/index.ts index d352e602..85b33427 100644 --- a/src/vault/skyflow/index.ts +++ b/src/vault/skyflow/index.ts @@ -1,4 +1,4 @@ -import { CONNECTION_ID, CREDENTIALS, Env, getVaultURL, ISkyflowError, LOGLEVEL, LogLevel, MessageType, parameterizedString, printLog, VAULT_ID } from "../../utils"; +import { CONNECTION_ID, CONTROLLER_TYPES, CREDENTIALS, Env, getVaultURL, ISkyflowError, LOGLEVEL, LogLevel, MessageType, parameterizedString, printLog, VAULT_ID } from "../../utils"; import ConnectionConfig from "../config/connection"; import VaultConfig from "../config/vault"; import { SkyflowConfig, ClientObj } from "../types"; @@ -10,6 +10,7 @@ import SkyflowError from "../../error"; import logs from "../../utils/logs"; import { isLogLevel, validateConnectionConfig, validateSkyflowConfig, validateSkyflowCredentials, validateUpdateConnectionConfig, validateUpdateVaultConfig, validateVaultConfig } from "../../utils/validations"; import SKYFLOW_ERROR_CODE from "../../error/codes"; +import DetectController from "../controller/detect"; class Skyflow { @@ -49,16 +50,17 @@ class Skyflow { const env = config.env || Env.PROD; const vaultUrl = getVaultURL(config.clusterId, env); const client = new VaultClient(vaultUrl, config.vaultId, config?.credentials, this.commonCredentials, this.logLevel); - const controller = new VaultController(client); - printLog(parameterizedString(logs.infoLogs.VAULT_CONTROLLER_INITIALIZED, [config.vaultId]), MessageType.LOG, this.logLevel); - clients[config.vaultId] = { config, client, controller }; + const vaultController = new VaultController(client); + const detectController = new DetectController(client); + printLog(logs.infoLogs.CONTROLLER_INITIALIZED, MessageType.LOG, this.logLevel); + clients[config.vaultId] = { config, client, vaultController, detectController }; } private addConnectionClient(config: ConnectionConfig, clients: ClientObj) { const client = new VaultClient(config.connectionUrl, '', config?.credentials, this.commonCredentials, this.logLevel); - const controller = new ConnectionController(client); + const connectionController = new ConnectionController(client); printLog(parameterizedString(logs.infoLogs.CONNECTION_CONTROLLER_INITIALIZED, [config.connectionId]), MessageType.LOG, this.logLevel); - clients[config.connectionId] = { config, client, controller }; + clients[config.connectionId] = { config, client, connectionController }; } addVaultConfig(config: VaultConfig) { @@ -201,20 +203,45 @@ class Skyflow { } vault(vaultId?: string) { - return this.getClient(vaultId, this.vaultClients, VAULT_ID) as VaultController; + return this.getClient(vaultId, this.vaultClients, VAULT_ID, CONTROLLER_TYPES.VAULT) as VaultController; + } + + detect(vaultId?: string) { + return this.getClient(vaultId, this.vaultClients, VAULT_ID, CONTROLLER_TYPES.DETECT) as DetectController; } connection(connectionId?: string) { - return this.getClient(connectionId, this.connectionClients, CONNECTION_ID) as ConnectionController; + return this.getClient(connectionId, this.connectionClients, CONNECTION_ID, CONTROLLER_TYPES.CONNECTION) as ConnectionController; } - private getClient(id: string | undefined, clients: ClientObj, idKey: string) { - if(Object.keys(clients).length === 0) this.throwErrorForEmptyClients(idKey) + private getClient( + id: string | undefined, + clients: ClientObj, + idKey: string, + controllerType: string + ) { + if (Object.keys(clients).length === 0) { + this.throwErrorForEmptyClients(idKey); + } + const clientId = id || Object.keys(clients)[0]; - if (clientId && clients[clientId]?.controller) { - return clients[clientId].controller; + if (clientId) { + const clientData = clients[clientId]; + + if (controllerType === CONTROLLER_TYPES.VAULT && clientData?.vaultController) { + return clientData.vaultController; + } + + if (controllerType === CONTROLLER_TYPES.DETECT && clientData?.detectController) { + return clientData.detectController; + } + + if (controllerType === CONTROLLER_TYPES.CONNECTION && clientData?.connectionController) { + return clientData.connectionController; + } + + this.throwErrorForUnknownId(clientId, idKey); } - if (clientId) this.throwErrorForUnknownId(clientId, idKey) } private updateClients(updateType: string) { diff --git a/src/vault/types/index.ts b/src/vault/types/index.ts index d3551f95..b99d3d39 100644 --- a/src/vault/types/index.ts +++ b/src/vault/types/index.ts @@ -5,6 +5,7 @@ import Credentials from "../config/credentials"; import VaultController from "../controller/vault"; import ConnectionController from "../controller/connections"; import VaultClient from "../client"; +import DetectController from "../controller/detect"; export interface SkyflowConfig { vaultConfigs?: VaultConfig[]; @@ -15,7 +16,9 @@ export interface SkyflowConfig { export interface ClientConfig { config: VaultConfig | ConnectionConfig; - controller: VaultController | ConnectionController; + vaultController?: VaultController; + connectionController?: ConnectionController; + detectController?: DetectController; client: VaultClient; } diff --git a/test/vault/client/client.test.js b/test/vault/client/client.test.js index 7ac03949..da9c622b 100644 --- a/test/vault/client/client.test.js +++ b/test/vault/client/client.test.js @@ -5,11 +5,13 @@ import { Tokens } from '../../../src/ _generated_/rest/api/resources/tokens/clie import { AuthType, LogLevel, TYPES } from '../../../src/utils'; import { isExpired } from '../../../src/utils/jwt-utils'; import SkyflowError from '../../../src/error'; +import { Strings } from '../../../src/ _generated_/rest/api/resources/strings/client/Client'; jest.mock('../../../src/ _generated_/rest'); jest.mock('../../../src/ _generated_/rest/api/resources/records/client/Client'); jest.mock('../../../src/ _generated_/rest/api/resources/query/client/Client'); jest.mock('../../../src/ _generated_/rest/api/resources/tokens/client/Client'); +jest.mock('../../../src/ _generated_/rest/api/resources/strings/client/Client'); jest.mock('../../../src/utils/jwt-utils'); jest.mock('../../../src/error'); @@ -91,6 +93,11 @@ describe('VaultClient', () => { expect(Query).toHaveBeenCalled(); }); + test('should initialize Strings for DETECT', () => { + vaultClient.initAPI(authInfo, TYPES.DETECT); + expect(Strings).toHaveBeenCalled(); + }); + test('should not initialize API for unsupported type', () => { vaultClient.initAPI(authInfo, 'UNSUPPORTED_TYPE'); expect(Records).not.toHaveBeenCalled(); diff --git a/test/vault/controller/detect.test.js b/test/vault/controller/detect.test.js new file mode 100644 index 00000000..cdaf284d --- /dev/null +++ b/test/vault/controller/detect.test.js @@ -0,0 +1,768 @@ +import DetectController from '../../../src/vault/controller/detect'; +import { validateDeidentifyFileRequest, validateDeIdentifyTextRequest, validateReidentifyTextRequest } from '../../../src/utils/validations'; +import DeidentifyTextResponse from '../../../src/vault/model/response/deidentify-text'; +import ReidentifyTextResponse from '../../../src/vault/model/response/reidentify-text'; +import DeidentifyFileRequest from '../../../src/vault/model/request/deidentify-file'; +import DeidentifyFileOptions from '../../../src/vault/model/options/deidentify-file'; +import { TYPES } from '../../../src/utils'; +import fs from 'fs'; + +jest.mock('../../../src/utils', () => ({ + printLog: jest.fn(), + parameterizedString: jest.fn(), + removeSDKVersion: jest.fn(), + MessageType: { + LOG: 'LOG', + ERROR: 'ERROR', + }, + TYPES: { + DETECT: 'DETECT', + DEIDENTIFY_FILE: 'DEIDENTIFY_FILE', + }, + DeidenitfyFileRequestTypes: { + AUDIO: 'AUDIO', + TEXT: 'TEXT', + PDF: 'PDF', + IMAGE: 'IMAGE', + PPT: 'PPT', + SPREADSHEET: 'SPREADSHEET', + STRUCTURED_TEXT: 'STRUCTURED_TEXT', + DOCUMENT: 'DOCUMENT', + FILE: 'FILE', + }, + generateSDKMetrics: jest.fn().mockReturnValue({ sdk: 'metrics' }), + getBearerToken: jest.fn().mockResolvedValue(Promise.resolve('your-bearer-token')), +})); + +jest.mock('../../../src/utils/validations', () => ({ + validateDeIdentifyTextRequest: jest.fn(), + validateReidentifyTextRequest: jest.fn(), + validateDeidentifyFileRequest: jest.fn(), +})); + +describe('DetectController', () => { + let mockVaultClient; + let detectController; + + beforeEach(() => { + mockVaultClient = { + getLogLevel: jest.fn().mockReturnValue('DEBUG'), + getCredentials: jest.fn().mockReturnValue({}), + initAPI: jest.fn(), + stringsAPI: { + deidentifyString: jest.fn(), + reidentifyString: jest.fn(), + }, + failureResponse: jest.fn().mockRejectedValue(new Error('API error')), + vaultId: 'vault123', + }; + jest.clearAllMocks(); + }); + + test('should initialize DetectController and call printLog with correct parameters', () => { + detectController = new DetectController(mockVaultClient); + expect(detectController).toBeInstanceOf(DetectController); + }); +}); + +describe('deidentifyText', () => { + + let mockVaultClient; + let detectController; + + beforeEach(() => { + mockVaultClient = { + getLogLevel: jest.fn().mockReturnValue('DEBUG'), + getCredentials: jest.fn().mockReturnValue({}), + initAPI: jest.fn(), + stringsAPI: { + deidentifyString: jest.fn(), + reidentifyString: jest.fn(), + }, + failureResponse: jest.fn().mockRejectedValue(new Error('API error')), + vaultId: 'vault123', + }; + detectController = new DetectController(mockVaultClient); + jest.clearAllMocks(); + }); + + test('should successfully deidentify text', async () => { + const mockRequest = { + text: 'Sensitive data to deidentify', + }; + const mockOptions = { + getEntities: jest.fn().mockReturnValue(['NAME', 'EMAIL']), + getAllowRegexList: jest.fn().mockReturnValue(['regex1']), + getRestrictRegexList: jest.fn().mockReturnValue(['regex2']), + getTransformations: jest.fn().mockReturnValue({ + getShiftDays: jest.fn().mockReturnValue({ + max: 10, + min: 5, + entities: ['DATE'], + }), + }), + getTokenFormat: jest.fn().mockReturnValue({ + getDefault: jest.fn().mockReturnValue('default'), + getVaultToken: jest.fn().mockReturnValue('vault-token'), + getEntityUniqueCounter: jest.fn().mockReturnValue('entity-unique-counter'), + getEntityOnly: jest.fn().mockReturnValue('entity-only'), + }) + }; + + const mockResponseData = { + processed_text: 'Processed text', + entities: [ + { + token: 'token1', + value: 'value1', + location: { + start_index: 0, + end_index: 5, + start_index_processed: 0, + end_index_processed: 5, + }, + entity_type: 'NAME', + entity_scores: [0.9], + }, + ], + word_count: 5, + character_count: 30, + }; + + mockVaultClient.stringsAPI.deidentifyString.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: mockResponseData, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const response = await detectController.deidentifyText(mockRequest, mockOptions); + + expect(validateDeIdentifyTextRequest).toHaveBeenCalledWith(mockRequest, mockOptions, 'DEBUG'); + expect(mockVaultClient.stringsAPI.deidentifyString).toHaveBeenCalledWith( + expect.objectContaining({ + text: mockRequest.text, + vault_id: 'vault123', + entity_types: ['NAME', 'EMAIL'], + allow_regex: ['regex1'], + restrict_regex: ['regex2'], + transformations: { + shift_dates: { + max_days: 10, + min_days: 5, + entity_types: ['DATE'], + }, + }, + }) + ); + expect(response).toBeInstanceOf(DeidentifyTextResponse); + expect(response.processedText).toBe('Processed text'); + expect(response.entities).toHaveLength(1); + expect(response.wordCount).toBe(5); + expect(response.charCount).toBe(30); + }); + + test('should handle validation errors', async () => { + const mockRequest = { + text: 'Sensitive data to deidentify', + }; + const mockOptions = {}; + + validateDeIdentifyTextRequest.mockImplementation(() => { + throw new Error('Validation error'); + }); + + await expect(detectController.deidentifyText(mockRequest, mockOptions)).rejects.toThrow( + 'Validation error' + ); + expect(validateDeIdentifyTextRequest).toHaveBeenCalledWith(mockRequest, mockOptions, 'DEBUG'); + expect(mockVaultClient.stringsAPI.deidentifyString).not.toHaveBeenCalled(); + }); + + test('should handle API errors during deidentifyText', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeIdentifyTextRequest: jest.fn(), + validateReidentifyTextRequest: jest.fn(), + })); + validateDeIdentifyTextRequest.mockImplementation(() => { + // No validation error + }); + const mockRequest = { + text: 'Sensitive data to deidentify', + }; + const mockOptions = { + getEntities: jest.fn().mockReturnValue([]), // Return an empty array for entities + getAllowRegexList: jest.fn().mockReturnValue([]), // Return an empty array for allow regex + getRestrictRegexList: jest.fn().mockReturnValue([]), // Return an empty array for restrict regex + getTransformations: jest.fn().mockReturnValue({ + getShiftDays: jest.fn().mockReturnValue({ + max: 10, + min: 5, + entities: ['DATE'], + }), + }), + getTokenFormat: jest.fn().mockReturnValue({ + getDefault: jest.fn().mockReturnValue('default'), + getVaultToken: jest.fn().mockReturnValue('vault-token'), + getEntityUniqueCounter: jest.fn().mockReturnValue('entity-unique-counter'), + getEntityOnly: jest.fn().mockReturnValue('entity-only'), + }) + }; + + mockVaultClient.stringsAPI.deidentifyString.mockImplementation(() => ({ + withRawResponse: jest.fn().mockRejectedValue(new Error('API error')), + })); + + await expect(detectController.deidentifyText(mockRequest, mockOptions)).rejects.toThrow( + 'API error' + ); + expect(mockVaultClient.stringsAPI.deidentifyString).toHaveBeenCalled(); + }); +}); + +describe('reidentifyText', () => { + let mockVaultClient; + let detectController; + + beforeEach(() => { + mockVaultClient = { + getLogLevel: jest.fn().mockReturnValue('DEBUG'), + getCredentials: jest.fn().mockReturnValue({}), + initAPI: jest.fn(), + stringsAPI: { + deidentifyString: jest.fn(), + reidentifyString: jest.fn(), + }, + failureResponse: jest.fn().mockRejectedValue(new Error('API error')), + vaultId: 'vault123', + }; + detectController = new DetectController(mockVaultClient); + jest.clearAllMocks(); + }); + test('should successfully reidentify text', async () => { + const mockRequest = { + text: 'Redacted text to reidentify', + }; + const mockOptions = { + getRedactedEntities: jest.fn().mockReturnValue(['NAME']), + getMaskedEntities: jest.fn().mockReturnValue(['EMAIL']), + getPlainTextEntities: jest.fn().mockReturnValue(['PHONE']), + }; + + const mockResponseData = { + text: 'Reidentified text', + }; + + mockVaultClient.stringsAPI.reidentifyString.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: mockResponseData, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const response = await detectController.reidentifyText(mockRequest, mockOptions); + + expect(validateReidentifyTextRequest).toHaveBeenCalledWith(mockRequest, mockOptions, 'DEBUG'); + expect(mockVaultClient.stringsAPI.reidentifyString).toHaveBeenCalledWith( + expect.objectContaining({ + text: mockRequest.text, + vault_id: 'vault123', + format: { + redacted: ['NAME'], + masked: ['EMAIL'], + plaintext: ['PHONE'], + }, + }) + ); + expect(response).toBeInstanceOf(ReidentifyTextResponse); + expect(response.processedText).toBe('Reidentified text'); + }); + + test('should handle validation errors', async () => { + const mockRequest = { + text: 'Redacted text to reidentify', + }; + const mockOptions = { + getRedactedEntities: jest.fn().mockReturnValue(['NAME']), + getMaskedEntities: jest.fn().mockReturnValue(['EMAIL']), + getPlainTextEntities: jest.fn().mockReturnValue(['PHONE']), + }; + + validateReidentifyTextRequest.mockImplementation(() => { + throw new Error('Validation error'); + }); + + await expect(detectController.reidentifyText(mockRequest, mockOptions)).rejects.toThrow( + 'Validation error' + ); + expect(validateReidentifyTextRequest).toHaveBeenCalledWith(mockRequest, mockOptions, 'DEBUG'); + expect(mockVaultClient.stringsAPI.reidentifyString).not.toHaveBeenCalled(); + }); + + test('should handle API errors during reidentifyText', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeIdentifyTextRequest: jest.fn(), + validateReidentifyTextRequest: jest.fn(), + })); + validateReidentifyTextRequest.mockImplementation(() => { + // No validation error + }); + const mockRequest = { + text: 'Redacted text to reidentify', + }; + const mockOptions = { + getRedactedEntities: jest.fn().mockReturnValue(['NAME']), + getMaskedEntities: jest.fn().mockReturnValue(['EMAIL']), + getPlainTextEntities: jest.fn().mockReturnValue(['PHONE']), + }; + + mockVaultClient.stringsAPI.reidentifyString.mockImplementation(() => ({ + withRawResponse: jest.fn().mockRejectedValue(new Error('API error')), + })); + + await expect(detectController.reidentifyText(mockRequest, mockOptions)).rejects.toThrow( + 'API error' + ); + expect(mockVaultClient.stringsAPI.reidentifyString).toHaveBeenCalled(); + }); +}); + +describe('DetectController - Files', () => { + let mockVaultClient; + let detectController; + + beforeEach(() => { + mockVaultClient = { + getLogLevel: jest.fn().mockReturnValue('DEBUG'), + getCredentials: jest.fn().mockReturnValue({}), + initAPI: jest.fn(), + filesAPI: { + deidentifyText: jest.fn(), + deidentifyAudio: jest.fn(), + deidentifyPdf: jest.fn(), + deidentifyImage: jest.fn(), + deidentifyPresentation: jest.fn(), + deidentifySpreadsheet: jest.fn(), + deidentifyStructuredText: jest.fn(), + deidentifyDocument: jest.fn(), + deidentifyFile: jest.fn(), + getRun: jest.fn(), + }, + failureResponse: jest.fn().mockRejectedValue(new Error('API error')), + vaultId: 'vault123', + }; + jest.clearAllMocks(); + }); + + const mockFile = new File(['test content'], 'test.txt', { type: 'text/plain' }); + const mockRequest = new DeidentifyFileRequest(mockFile); + const mockOptions = new DeidentifyFileOptions(); + mockOptions.setWaitTime(16); + + const mockPollResponse = { + status: 'SUCCESS', + output: [ + { + processedFile: 'mockProcessedFile', + processedFileType: 'text', + processedFileExtension: 'txt', + }, + ], + wordCharacterCount: { + wordCount: 100, + characterCount: 500, + }, + size: 1024, + duration: 0, + pages: 0, + slides: 0, + }; + + const setupPolling = () => { + mockVaultClient.filesAPI.getRun + .mockResolvedValueOnce({ status: 'IN_PROGRESS' }) // First poll + .mockResolvedValueOnce({ status: 'IN_PROGRESS' }) // Second poll + .mockResolvedValueOnce(mockPollResponse); // Final poll + }; + + test('should successfully deidentify an audio file', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const audioFile = new File(['audio content'], 'test.mp3', { type: 'audio/mpeg' }); + const audioRequest = new DeidentifyFileRequest(audioFile); + + setupPolling(); + + mockVaultClient.filesAPI.deidentifyAudio.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.deidentifyFile(audioRequest, mockOptions); + + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + expect(result.extension).toBe('txt'); + }); + + test('should successfully deidentify a PDF file', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const pdfFile = new File(['pdf content'], 'test.pdf', { type: 'application/pdf' }); + const pdfRequest = new DeidentifyFileRequest(pdfFile); + + setupPolling(); + + mockVaultClient.filesAPI.deidentifyPdf.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.deidentifyFile(pdfRequest, mockOptions); + + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + expect(result.extension).toBe('txt'); + }); + + test('should successfully deidentify a PDF file and save processed file to output directory', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + + detectController = new DetectController(mockVaultClient); + + const pdfFile = new File(['pdf content'], 'test.pdf', { type: 'application/pdf' }); + const pdfRequest = new DeidentifyFileRequest(pdfFile); + + const mockOptions = new DeidentifyFileOptions(); + mockOptions.setWaitTime(16); + mockOptions.setOutputDirectory('/mock/output/directory'); // Set the output directory + + // Mock the deidentifyPdf API call + mockVaultClient.filesAPI.deidentifyPdf.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + // Mock the getRun API call for polling + mockVaultClient.filesAPI.getRun = jest.fn() + .mockResolvedValueOnce({ status: 'IN_PROGRESS' }) // First poll + .mockResolvedValueOnce({ status: 'IN_PROGRESS' }) // Second poll + .mockResolvedValueOnce({ // Final poll + status: 'SUCCESS', + output: [ + { + processedFile: Buffer.from('mockProcessedFileContent').toString('base64'), // Base64-encoded content + processedFileType: 'pdf', + processedFileExtension: 'pdf', + }, + ], + wordCharacterCount: { + wordCount: 100, + characterCount: 500, + }, + size: 1024, + duration: 0, + pages: 10, + slides: 0, + }); + + // Mock the file system to avoid actual file writes + jest.spyOn(fs, 'existsSync').mockImplementation((path) => path === '/mock/output/directory'); + jest.spyOn(fs, 'mkdirSync').mockImplementation(() => {}); + jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {}); + + const result = await detectController.deidentifyFile(pdfRequest, mockOptions); + + // Assertions for the response + expect(result.extension).toBe('pdf'); + + // Assertions for processDeidentifyFileResponse + expect(fs.existsSync).toHaveBeenCalledWith('/mock/output/directory'); + expect(fs.writeFileSync).toHaveBeenCalledWith( + '/mock/output/directory/processed-test.pdf', + expect.any(Buffer) + ); + }); + + test('should successfully deidentify an image file', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const imageFile = new File(['image content'], 'test.png', { type: 'image/png' }); + const imageRequest = new DeidentifyFileRequest(imageFile); + + setupPolling(); + + mockVaultClient.filesAPI.deidentifyImage.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.deidentifyFile(imageRequest, mockOptions); + + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + expect(result.extension).toBe('txt'); + }); + + test('should successfully deidentify a presentation file', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const pptFile = new File(['ppt content'], 'test.pptx', { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' }); + const pptRequest = new DeidentifyFileRequest(pptFile); + + setupPolling(); + + mockVaultClient.filesAPI.deidentifyPresentation.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.deidentifyFile(pptRequest, mockOptions); + + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + expect(result.extension).toBe('txt'); + }); + + test('should successfully deidentify a spreadsheet file', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const spreadsheetFile = new File(['spreadsheet content'], 'test.xlsx', { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); + const spreadsheetRequest = new DeidentifyFileRequest(spreadsheetFile); + + setupPolling(); + + mockVaultClient.filesAPI.deidentifySpreadsheet.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.deidentifyFile(spreadsheetRequest, mockOptions); + + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + expect(result.extension).toBe('txt'); + }); + + test('should successfully deidentify a structured text file', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const structuredTextFile = new File(['structured text content'], 'test.json', { type: 'application/json' }); + const structuredTextRequest = new DeidentifyFileRequest(structuredTextFile); + + setupPolling(); + + mockVaultClient.filesAPI.deidentifyStructuredText.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.deidentifyFile(structuredTextRequest, mockOptions); + + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + expect(result.extension).toBe('txt'); + }); + + test('should successfully deidentify a document file', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const documentFile = new File(['document content'], 'test.docx', { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }); + const documentRequest = new DeidentifyFileRequest(documentFile); + + setupPolling(); + + mockVaultClient.filesAPI.deidentifyDocument.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.deidentifyFile(documentRequest, mockOptions); + + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + expect(result.extension).toBe('txt'); + }); + + test('should successfully deidentify a generic file', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const genericFile = new File(['generic content'], 'test.zip', { type: 'application/zip' }); + const genericRequest = new DeidentifyFileRequest(genericFile); + + setupPolling(); + + mockVaultClient.filesAPI.deidentifyFile.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.deidentifyFile(genericRequest, mockOptions); + + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + expect(result.extension).toBe('txt'); + }); + + test('should throw validation error', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + throw new Error("Validation error"); + }); + + // Initialize DetectController + detectController = new DetectController(mockVaultClient); + + // Create a generic file and request + const genericFile = new File(['generic content'], 'test.zip', { type: 'application/zip' }); + const genericRequest = new DeidentifyFileRequest(genericFile); + + // Assert that the deidentifyFile method throws the validation error + await expect(detectController.deidentifyFile(genericRequest, mockOptions)).rejects.toThrow("Validation error"); + }); + + test('should successfully deidentify a text file with processed file after polling', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + detectController = new DetectController(mockVaultClient); + const mockFile = new File(['test content'], 'test.txt', { type: 'text/plain' }); + const mockRequest = new DeidentifyFileRequest(mockFile); + const mockOptions = new DeidentifyFileOptions(); + mockOptions.setWaitTime(16); + + mockVaultClient.filesAPI.deidentifyText.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + mockVaultClient.filesAPI.getRun = jest.fn() + .mockResolvedValueOnce({ status: 'IN_PROGRESS' }) // First poll + .mockResolvedValueOnce({ status: 'IN_PROGRESS' }) // Second poll + .mockResolvedValueOnce({ // Final poll + status: 'SUCCESS', + output: [ + { + processedFile: 'mockProcessedFile', + processedFileType: 'text', + processedFileExtension: 'txt', + }, + ], + wordCharacterCount: { + wordCount: 100, + characterCount: 500, + }, + size: 1024, + duration: 0, + pages: 0, + slides: 0, + }); + + + const result = await detectController.deidentifyFile(mockRequest, mockOptions); + expect(result.file).toBe('mockProcessedFile'); + expect(result.type).toBe('text'); + }); + + test('should handle error when getRun method rejects during polling', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateDeidentifyFileRequest: jest.fn(), + })); + validateDeidentifyFileRequest.mockImplementation(() => { + // No validation error + }); + + detectController = new DetectController(mockVaultClient); + const mockFile = new File(['test content'], 'test.txt', { type: 'text/plain' }); + const mockRequest = new DeidentifyFileRequest(mockFile); + const mockOptions = new DeidentifyFileOptions(); + mockOptions.setWaitTime(16); + + mockVaultClient.filesAPI.deidentifyText.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: { run_id: 'mockRunId' }, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + // Simulate getRun method rejecting with an error + mockVaultClient.filesAPI.getRun = jest.fn() + .mockResolvedValueOnce({ status: 'IN_PROGRESS' }) // First poll + .mockResolvedValueOnce({ status: 'IN_PROGRESS' }) // Second poll + .mockRejectedValueOnce(new Error('Polling failed')); // Third poll rejects with an error + + await expect(detectController.deidentifyFile(mockRequest, mockOptions)).rejects.toThrow('Polling failed'); + }); + + +}); \ No newline at end of file diff --git a/test/vault/controller/vault.test.js b/test/vault/controller/vault.test.js index 5adbbab1..5fb54172 100644 --- a/test/vault/controller/vault.test.js +++ b/test/vault/controller/vault.test.js @@ -96,14 +96,6 @@ describe('VaultController', () => { // Ensure the constructor sets the client and logs the initialization expect(vaultController).toBeInstanceOf(VaultController); expect(vaultController.client).toBe(mockVaultClient); - - // Verify printLog is called with expected parameters - expect(printLog).toHaveBeenCalledTimes(1); - expect(printLog).toHaveBeenCalledWith( - logs.infoLogs.CONTROLLER_INITIALIZED, - MessageType.LOG, - 'DEBUG' // getLogLevel() should return 'DEBUG' - ); }); test('should have the connection method defined', () => { diff --git a/test/vault/skyflow/skyflow.test.js b/test/vault/skyflow/skyflow.test.js index 9582ab4f..2a5ca9b7 100644 --- a/test/vault/skyflow/skyflow.test.js +++ b/test/vault/skyflow/skyflow.test.js @@ -82,6 +82,81 @@ describe('Skyflow initialization', () => { })).toThrowError(invalidConnectionConfigError); }); + + describe('Detect Controller Tests', () => { + const validVaultConfig = { + vaultId: "VAULT_ID", + clusterId: "CLUSTER_ID" + }; + + const noConfigFoundError = "No vault config found."; + const missingVaultConfigError = "VAULT_ID is missing from the config."; + + test('should return detect controller', () => { + const skyflow = new Skyflow({ + vaultConfigs: [validVaultConfig] + }); + expect(skyflow.detect("VAULT_ID")).toBeTruthy(); + }); + + test('should return detect controller when called without vault id', () => { + const skyflow = new Skyflow({ + vaultConfigs: [validVaultConfig] + }); + expect(skyflow.detect()).toBeTruthy(); + }); + + test('should throw error for invalid vault id in detect method', () => { + const skyflow = new Skyflow({ + vaultConfigs: [validVaultConfig], + }); + skyflow.removeVaultConfig("VAULT_ID"); + expect(() => skyflow.detect("ID")).toThrowError(noConfigFoundError); + }); + + test('should throw error when no vault configs exist for detect method', () => { + const skyflow = new Skyflow({ + vaultConfigs: [validVaultConfig], + }); + skyflow.removeVaultConfig("VAULT_ID"); + expect(() => skyflow.detect("ID")).toThrowError(noConfigFoundError); + }); + }); + + describe('Update Clients Tests', () => { + const validVaultConfig = { + vaultId: "VAULT_ID", + clusterId: "CLUSTER_ID" + }; + + const validConnectionConfig = { + connectionId: "CONN_ID", + connectionUrl: "https://connection-url.com" + }; + + test('should update log level for all clients', () => { + const skyflow = new Skyflow({ + vaultConfigs: [validVaultConfig], + connectionConfigs: [validConnectionConfig] + }); + skyflow.setLogLevel(LogLevel.OFF); + expect(skyflow.getLogLevel()).toBe(LogLevel.OFF); + }); + + test('should update credentials for all clients', () => { + const skyflow = new Skyflow({ + vaultConfigs: [validVaultConfig], + connectionConfigs: [validConnectionConfig], + skyflowCredentials: { + apiKey: "sky-KEY" + } + }); + const newCredentials = { apiKey: "sky-VALID_KEY" }; + skyflow.updateSkyflowCredentials(newCredentials); + expect(skyflow.getSkyflowCredentials()).toBe(newCredentials); + }); + }); + describe('Log Level Tests', () => { const validVaultConfig = [{ vaultId: "VAULT_ID", From 601a1d15da7b08072873570bb8b6b37909bd9173 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 07:55:47 +0000 Subject: [PATCH 02/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.8907d21 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 84ccf4df..2fb02816 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4", + "version": "2.0.0-beta.4-dev.8907d21", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From e7edb609aa60294cfa09cbada8c729f577fb340e Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 13:33:35 +0530 Subject: [PATCH 03/30] SK-2040: fix common release workflow --- .github/workflows/common-release.yml | 2 +- src/utils/validations/index.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/common-release.yml b/.github/workflows/common-release.yml index 598fc39c..a9b4ebc1 100644 --- a/.github/workflows/common-release.yml +++ b/.github/workflows/common-release.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/setup-node@v1 with: node-version: '20.x' - registry-url: "https://registry.npmjs.org" + registry-url: ${{ (inputs.tag == 'beta' || inputs.tag == 'public') && 'https://registry.npmjs.org' || (inputs.tag == 'internal' && 'https://prekarilabs.jfrog.io/prekarilabs/api/npm/npm/') }} - name: Install Packages run: npm install diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index 427a5554..4974a2e3 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -987,7 +987,6 @@ export const validateReidentifyTextRequest = (request: ReidentifyTextRequest, op } }; - export const validateDeidentifyFileRequest = (deidentifyFileRequest: DeidentifyFileRequest, deidentifyFileOptions?: DeidentifyFileOptions, logLevel: LogLevel = LogLevel.ERROR) => { if (!deidentifyFileRequest) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_DEIDENTIFY_FILE_REQUEST); From 7e7bd3ce1b112267c09852d9c41c7b3030e1e8b3 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 13:36:10 +0530 Subject: [PATCH 04/30] SK-2040: fix common release workflow --- .github/workflows/common-release.yml | 1 - src/vault/client/index.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/common-release.yml b/.github/workflows/common-release.yml index a9b4ebc1..c7ec0dd1 100644 --- a/.github/workflows/common-release.yml +++ b/.github/workflows/common-release.yml @@ -19,7 +19,6 @@ jobs: - uses: actions/setup-node@v1 with: node-version: '20.x' - registry-url: ${{ (inputs.tag == 'beta' || inputs.tag == 'public') && 'https://registry.npmjs.org' || (inputs.tag == 'internal' && 'https://prekarilabs.jfrog.io/prekarilabs/api/npm/npm/') }} - name: Install Packages run: npm install diff --git a/src/vault/client/index.ts b/src/vault/client/index.ts index acf068bc..e4b6d968 100644 --- a/src/vault/client/index.ts +++ b/src/vault/client/index.ts @@ -255,7 +255,6 @@ class VaultClient { this.logAndRejectError(description, err, requestId, reject, undefined, grpcCode, details, isNewFormat); } - private logAndRejectError( description: string, err: any, From a2038aec22b921deb5a6488c9744ea1a41a952f4 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 08:06:32 +0000 Subject: [PATCH 05/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.7e7bd3c --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2fb02816..dcdb0c5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.8907d21", + "version": "2.0.0-beta.4-dev.7e7bd3c", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From 5f1f332ba08ecfff38442fd756731c43811ccd31 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 16:55:21 +0530 Subject: [PATCH 06/30] SK-2040: add enums for export --- src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index e4c99f0e..47525e45 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,7 +42,7 @@ import Transformations from './vault/model/options/deidentify-text/transformatio 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 { TokenType } from './utils'; +import { TokenType, MaskingMethod, DetectOutputTranscription } from './utils'; import { Bleep } from './vault/model/options/deidentify-file/bleep-audio'; export { Env, @@ -104,5 +104,7 @@ export { DeidentifyFileRequest, DeidentifyFileResponse, TokenType, - Bleep + Bleep, + MaskingMethod, + DetectOutputTranscription }; \ No newline at end of file From 11490b704c192e1d4020c85b6fa584aa590053d1 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 11:25:58 +0000 Subject: [PATCH 07/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.5f1f332 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dcdb0c5e..a712f0fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.7e7bd3c", + "version": "2.0.0-beta.4-dev.5f1f332", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From c6b14429062c94c94ba39322254212dcf1758148 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 21:52:03 +0530 Subject: [PATCH 08/30] SK-2040: removed redundant options --- src/vault/controller/detect/index.ts | 2 +- src/vault/model/options/deidentify-file/index.ts | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/vault/controller/detect/index.ts b/src/vault/controller/detect/index.ts index 9a5a11fc..da7b2621 100644 --- a/src/vault/controller/detect/index.ts +++ b/src/vault/controller/detect/index.ts @@ -109,7 +109,7 @@ class DetectController { restrict_regex: options?.getRestrictRegexList(), transformations: options?.getTransformations() as Transformations, max_resolution: options?.getMaxResolution(), - density: options?.getDensity(), + density: options?.getPixelDensity(), } return pdfRequest; } diff --git a/src/vault/model/options/deidentify-file/index.ts b/src/vault/model/options/deidentify-file/index.ts index 0444a15c..03a39170 100644 --- a/src/vault/model/options/deidentify-file/index.ts +++ b/src/vault/model/options/deidentify-file/index.ts @@ -19,19 +19,11 @@ class DeidentifyFileOptions { private _outputTranscription?: DetectOutputTranscription; private _bleep?: Bleep; private _outputDirectory?: string; - private _density?: number; private _waitTime?: number; constructor() { } - getDensity(): number | undefined{ - return this._density; - } - setDensity(density: number) { - this._density = density; - } - getEntities(): string[] | undefined { return this._entities; } From 9d2ee8556d4a1ce479ac46f01a8f0612e96034cb Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 16:23:44 +0000 Subject: [PATCH 09/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.c6b1442 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a712f0fd..7210f581 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.5f1f332", + "version": "2.0.0-beta.4-dev.c6b1442", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From a3ccb6a1771f35cfb9e7905abd87f25ec8f19259 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 01:30:35 +0530 Subject: [PATCH 10/30] SK-2040: update validations for detect file --- src/utils/validations/index.ts | 7 ++++--- src/vault/model/response/deidentify-file/index.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index 4974a2e3..b574c3aa 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -33,6 +33,7 @@ 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 { Bleep } from "../../vault/model/options/deidentify-file/bleep-audio"; export function isEnv(value?: string): boolean { return value !== undefined && Object.values(Env).includes(value as Env); @@ -1058,12 +1059,12 @@ export const validateDeidentifyFileOptions = (deidentifyFileOptions: DeidentifyF } // Validate tokenFormat - if (deidentifyFileOptions.getTokenFormat() && typeof deidentifyFileOptions.getTokenFormat !== 'object') { + if (deidentifyFileOptions.getTokenFormat() && !(deidentifyFileOptions.getTokenFormat() instanceof TokenFormat)) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKEN_FORMAT); } // Validate transformations - if (deidentifyFileOptions.getTransformations() && typeof deidentifyFileOptions.getTransformations() !== 'object') { + if (deidentifyFileOptions.getTransformations() && !(deidentifyFileOptions.getTransformations() instanceof Transformations)) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TRANSFORMATIONS); } @@ -1098,7 +1099,7 @@ export const validateDeidentifyFileOptions = (deidentifyFileOptions: DeidentifyF throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OUTPUT_TRANSCRIPTION); } - if (deidentifyFileOptions.getBleep() !== undefined && typeof deidentifyFileOptions.getBleep() !== 'object') { + if (deidentifyFileOptions.getBleep() && !(deidentifyFileOptions.getBleep() instanceof Bleep)) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_BLEEP); } }; diff --git a/src/vault/model/response/deidentify-file/index.ts b/src/vault/model/response/deidentify-file/index.ts index 214802ba..1e85fae9 100644 --- a/src/vault/model/response/deidentify-file/index.ts +++ b/src/vault/model/response/deidentify-file/index.ts @@ -1,7 +1,7 @@ class DeidentifyFileResponse { // fields file?: string; - enities?: Array<{ + entities?: Array<{ file: string; extension: string; }> = []; @@ -55,7 +55,7 @@ class DeidentifyFileResponse { this.durationInSeconds = durationInSeconds; this.pageCount = pageCount; this.slideCount = slideCount; - this.enities = entities; + this.entities = entities; this.runId = runId; } From c6a05cb498616f01f1e81b88b16149f1fb042f1d Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 12 May 2025 20:01:45 +0000 Subject: [PATCH 11/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.a3ccb6a --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7210f581..17d40f64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.c6b1442", + "version": "2.0.0-beta.4-dev.a3ccb6a", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From 2a112b4c6f9d9db8b67d0f82244b8520a2bbea3e Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 12:07:21 +0530 Subject: [PATCH 12/30] SK-2048: add samples and update README --- README.md | 507 ++++++++++++++++++++++++++ samples/detect-api/deidentify-file.ts | 134 +++++++ samples/detect-api/deidentify-text.ts | 106 ++++++ samples/detect-api/reidentify-text.ts | 77 ++++ 4 files changed, 824 insertions(+) create mode 100644 samples/detect-api/deidentify-file.ts create mode 100644 samples/detect-api/deidentify-text.ts create mode 100644 samples/detect-api/reidentify-text.ts diff --git a/README.md b/README.md index 819b8336..a5e1430f 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ SDK for the Skyflow Data Privacy Vault. - [Delete](#delete) - [Invoke Connection](#invoke-a-connection) - [Query](#query) + - [Detect](#detect) + - [Deidentify Text](#deidentify-text) + - [Reidentify Text](#reidentify-text) + - [Deidentify File](#deidentify-file) - [Connections](#connections) - [Invoke a connection](#invoke-a-connection) - [Authenticate with bearer tokens](#authenticate-with-bearer-tokens) @@ -1844,6 +1848,509 @@ QueryResponse { } ``` +## Detect +Skyflow Detect enables you to deidentify and reidentify sensitive data in text and files, supporting advanced privacy-preserving workflows. The Detect API supports the following operations: + +### Deidentify Text +To deidentify text, use the `deidentifyText` method. The `DeidentifyTextRequest` class creates a deidentify text request, which includes the text to be deidentified. Additionally, you can provide optional parameters using the `DeidentifyTextOptions` class. + +```typescript +import { + DeidentifyTextRequest, + DeidentifyTextOptions, + SkyflowError, + TokenFormat, + TokenType, + Transformations, + DetectEntities +} from 'skyflow-node'; + +try { + // Step 1: Prepare the text to be deidentified + const deidentifyTextRequest = new DeidentifyTextRequest( + '' + ); + + // Step 2: Configure DeidentifyTextOptions + const options = new DeidentifyTextOptions(); + options.setEntities([DetectEntities.ACCOUNT_NUMBER, DetectEntities.SSN]); // Entities to deidentify + options.setAllowRegexList(['']); // Allowlist regex patterns + options.setRestrictRegexList(['']); // Restrict regex patterns + + const tokenFormat = new TokenFormat(); // Specify the token format for deidentified entities + tokenFormat.setDefault(TokenType.VAULT_TOKEN); + optionsText.setTokenFormat(tokenFormat); + + const transformations = new Transformations(); // Specify custom transformations for entities + transformations.setShiftDays({ + max: 30, // Maximum shift days + min: 30, // Minimum shift days + entities: [DetectEntities.ACCOUNT_NUMBER, DetectEntities.SSN], // Entities to apply the shift + }); + optionsText.setTransformations(transformations); + + // Step 3: Call deidentifyText + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyText(deidentifyTextRequest, options); + + console.log('Deidentify Text Response:', response); + +} catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Error:', error.message); + } else { + console.error('Unexpected Error:', error); + } +} +``` + +#### An example of a deidentify text call + +```typescript +import { + SkyflowError, + DeidentifyTextRequest, + DeidentifyTextOptions, + TokenFormat, + TokenType, + Transformations, + DetectEntities +} from 'skyflow-node'; + +/** + * Skyflow Deidentify Text Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a deidentify text request + * 4. Use all available options for deidentification + * 5. Handle response and errors + */ + +async function performDeidentifyText() { + try { + + // Step 1: Prepare Deidentify Text Request + const textReq = new DeidentifyTextRequest( + 'My SSN is 123-45-6789 and my card is 4111 1111 1111 1111.', // Text to be deidentified + ); + + // Step 2: Configure DeidentifyTextOptions + const optionsText = new DeidentifyTextOptions(); + + // setEntities: Specify which entities to deidentify + optionsText.setEntities([DetectEntities.SSN, DetectEntities.CREDIT_CARD_NUMBER]); + + // setTokenFormat: Specify the token format for deidentified entities + const tokenFormat = new TokenFormat(); + tokenFormat.setDefault(TokenType.VAULT_TOKEN); + optionsText.setTokenFormat(tokenFormat); + + // setTransformations: Specify custom transformations for entities + const transformations = new Transformations(); + transformations.setShiftDays({ + max: 30, // Maximum shift days + min: 30, // Minimum shift days + entities: [DetectEntities.DOB], // Entities to apply the shift + }); + optionsText.setTransformations(transformations); + + // Step 3: Call deidentifyText API + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyText(textReq, optionsText); + + // Handle Successful Response + console.log('Deidentify Text Response:', response); + + } catch (error) { + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +// Invoke the deidentify text function +performDeidentifyText(); + +``` +Sample Response: + +```typescript +{ + "processedText": "My SSN is [SSN_0ykQWPA] and my card is [CREDIT_CARD_N92QAVa].", + "entities": [ + { + "token": "SSN_0ykQWPA", + "value": "123-45-6789", + "textIndex": { + "start": 10, + "end": 21 + }, + "processedIndex": { + "start": 10, + "end": 23 + }, + "entity": "SSN", + "scores": { + "SSN": 0.9383999705314636 + } + }, + { + "token": "CREDIT_CARD_N92QAVa", + "value": "4111 1111 1111 1111", + "textIndex": { + "start": 37, + "end": 56 + }, + "processedIndex": { + "start": 39, + "end": 60 + }, + "entity": "CREDIT_CARD", + "scores": { + "CREDIT_CARD": 0.9050999879837 + } + } + ], + "wordCount": 9, + "charCount": 57 +} +``` + +### Reidentify Text + +To reidentify text, use the `reidentifyText` method. The `ReidentifyTextRequest` class creates a reidentify text request, which includes the redacted or deidentified text to be reidentified. Additionally, you can provide optional parameters using the `ReidentifyTextOptions` class to control how specific entities are returned (as redacted, masked, or plain text). + + +```typescript +import { + ReidentifyTextRequest, + ReidentifyTextOptions, + SkyflowError, + DetectEntities +} from 'skyflow-node'; + +try { + // Step 1: Prepare the redacted text to be reidentified + const textReq = new ReidentifyTextRequest( + '' + ); + + // Step 2: Configure ReidentifyTextOptions + const options = new ReidentifyTextOptions(); + options.setRedactedEntities([DetectEntities.SSN]); // Entities to keep redacted + options.setMaskedEntities([DetectEntities.CREDIT_CARD_NUMBER]); // Entities to mask + options.setPlainTextEntities([DetectEntities.NAME]); // Entities to return as plain text + + // Step 3: Call reidentifyText + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .reidentifyText(textReq, options); + + console.log('Reidentify Text Response:', response); + +} catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Error:', error.message); + } else { + console.error('Unexpected Error:', error); + } +} +``` + +#### An example of a reidentify text call + +```typescript +import { + ReidentifyTextRequest, + ReidentifyTextOptions, + DetectEntities +} from 'skyflow-node'; + +/** + * Skyflow Deidentify Text Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a reidentify text request + * 4. Use all available options for reidentification + * 5. Handle response and errors + */ + +async function performReidentifyText() { + try { + // Step 1: Prepare Reidentify Text Request + const reidentifyTextRequest = new ReidentifyTextRequest( + '' // The redacted text to reidentify + ); + + // Step 2: Configure ReidentifyTextOptions + const options = new ReidentifyTextOptions(); + + // Specify which entities to reidentify as redacted, masked, or plain text + options.setRedactedEntities([DetectEntities.NAME, DetectEntities.SSN]); + options.setMaskedEntities([DetectEntities.DOB]); + options.setPlainTextEntities([DetectEntities.PHONE_NUMBER]); + + // Step 4: Call reidentifyText + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .reidentifyText(reidentifyTextRequest, options); + + // Step 5: Handle response + console.log('Reidentified Text Response:', response); + + } catch (error) { + console.error('Error during reidentifyText:', error); + } +} + +// Invoke the reidentify text function +performReidentifyText(); +``` + +Sample Response: + +```typescript +{ + processedText: 'My SSN is 123-45-6789 and my card is 4111 1111 1111 1111.' +} +``` + +### Deidentify File + +To deidentify files, use the `deidentifyFile` method. The `DeidentifyFileRequest` class creates a deidentify file request, which includes the file to be deidentified (such as images, PDFs, audio, documents, spreadsheets, or presentations). Additionally, you can provide optional parameters using the `DeidentifyFileOptions` class to control how entities are detected and deidentified, as well as how the output is generated for different file types. + +```typescript +import { + DeidentifyFileRequest, + DeidentifyFileOptions, + SkyflowError, + DetectEntities, + MaskingMethod, + DetectOutputTranscription, + Bleep +} from 'skyflow-node'; + +try { + // Step 1: Prepare the file to be deidentified + const buffer = fs.readFileSync(''); + const file = new File([buffer], ''); + const fileReq = new DeidentifyFileRequest(file); + + // Step 2: Configure DeidentifyFileOptions + const options = new DeidentifyFileOptions(); + options.setEntities([DetectEntities.SSN, DetectEntities.ACCOUNT_NUMBER]); + options.setAllowRegexList(['']); + options.setRestrictRegexList(['']); + + const tokenFormat = new TokenFormat(); // Token format for deidentified entities + tokenFormat.setDefault(TokenType.VAULT_TOKEN); + options.setTokenFormat(tokenFormat); + + const transformations = new Transformations(); // transformations for entities + transformations.setShiftDays({ + max: 30, + min: 10, + entities: [DetectEntities.SSN], + }); + options.setTransformations(transformations); + + options.setOutputDirectory(''); // Output directory for saving the deidentified file + + options.setWaitTime(15); // Wait time for response (max 20 seconds; throws error if more) + + // ===== Image Options (apply when file is an image) ===== + + // options.setOutputProcessedImage(true); // Include processed image in output + + // options.setOutputOcrText(true); // Include OCR text in response + + // options.setMaskingMethod(MaskingMethod.Blackout); // Masking method for image entities + + // ===== PDF Options (apply when file is a PDF) ===== + + // options.setPixelDensity(300); // Pixel density for PDF processing + + // options.setMaxResolution(2000); // Max resolution for PDF + + // ===== Audio Options (apply when file is audio) ===== + + // options.setOutputProcessedAudio(true); // Include processed audio in output + + // options.setOutputTranscription(DetectOutputTranscription.PLAINTEXT_TRANSCRIPTION); // Type of transcription + + // const bleep = new Bleep(); // Bleep audio configuration + // bleep.setGain(5); // Relative loudness in dB + // bleep.setFrequency(1000); // Pitch in Hz + // bleep.setStartPadding(0.1); // Padding at start in seconds + // bleep.setStopPadding(0.2); // Padding at end in seconds + // options.setBleep(bleep); + + // Step 3: Call deidentifyFile + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyFile(fileReq, options); + + console.log('Deidentify File Response:', response); + +} catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Error:', error.message); + } else { + console.error('Unexpected Error:', error); + } +} +``` + +#### An example of a deidentify file + +```typescript +import { + SkyflowError, + DeidentifyFileRequest, + DeidentifyFileOptions, + DetectEntities, + TokenFormat, + TokenType, + Transformations, +} from 'skyflow-node'; +import fs from 'fs'; + +/** + * Skyflow Deidentify File Example + * + * This sample demonstrates how to use all available options for deidentifying files. + * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. + */ + +async function performDeidentifyFile() { + try { + // Step 4: Prepare Deidentify File Request + // Replace with your file object (e.g., from fs.readFileSync or browser File API) + const buffer = fs.readFileSync(''); + const file = new File([buffer], ''); + const fileReq = new DeidentifyFileRequest(file); + + // Step 5: Configure DeidentifyFileOptions + const options = new DeidentifyFileOptions(); + + // Entities to detect and deidentify + options.setEntities([DetectEntities.SSN, DetectEntities.ACCOUNT_NUMBER]); + + // Token format for deidentified entities + const tokenFormat = new TokenFormat(); + tokenFormat.setDefault(TokenType.VAULT_TOKEN); + options.setTokenFormat(tokenFormat); + + // Custom transformations for entities + const transformations = new Transformations(); + transformations.setShiftDays({ + max: 30, + min: 10, + entities: [DetectEntities.SSN], + }); + options.setTransformations(transformations); + + // Output directory for saving the deidentified file + options.setOutputDirectory('/home/user/output'); // Replace with your desired output directory + + // Wait time for response (max 20 seconds) + options.setWaitTime(15); + + + // Step 6: Call deidentifyFile API + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyFile(fileReq, options); + + // Handle Successful Response + console.log('Deidentify File Response:', response); + + } catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +// Invoke the deidentify file function +performDeidentifyFile(); + +``` + + +**Supported file types:** +- Documents: `doc`, `docx`, `pdf` +- PDFs: `pdf` +- Images: `bmp`, `jpeg`, `jpg`, `png`, `tif`, `tiff` +- Structured text: `json`, `xml` +- Spreadsheets: `csv`, `xls`, `xlsx` +- Presentations: `ppt`, `pptx` +- Audio: `mp3`, `wav` + +**Note:** +- The `waitTime` option must be ≤ 20 seconds; otherwise, an error is thrown. + +Sample Response: + +```typescript +{ + entities: [ + { + file: '0X2xhYmVsIjoiQ1JFRElUX0NB==', + extension: 'json' + } + ], + file: 'TXkgU1NOIGlzIFtTU0==', + type: 'redacted_file', + extension: 'txt', + wordCount: 12, + charCount: 58, + sizeInKb: 0.06, + durationInSeconds: 0, + pageCount: 0, + slideCount: 0, + runId: undefined +} +``` +- If the API takes more than 20 seconds to process the file, it will return only the run ID in the response. + +Sample response (when the API takes more than 20 seconds): +```typescript + +{ + entities: undefined, + file: undefined, + type: undefined, + extension: undefined, + wordCount: undefined, + charCount: undefined, + sizeInKb: undefined, + durationInSeconds: undefined, + pageCount: undefined, + slideCount: undefined, + runId: '1ad6dc12-8405-46cf-1c13-db1123f9f4c5' +} +``` + ## Connections Skyflow Connections is a gateway service that uses tokenization to securely send and receive data between your systems and first- or third-party services. The [connections](https://github.com/skyflowapi/skyflow-node/tree/v2/src/vault/controller/connections) module invokes both inbound and/or outbound connections. diff --git a/samples/detect-api/deidentify-file.ts b/samples/detect-api/deidentify-file.ts new file mode 100644 index 00000000..dfd30b03 --- /dev/null +++ b/samples/detect-api/deidentify-file.ts @@ -0,0 +1,134 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + SkyflowError, + DeidentifyFileRequest, + DeidentifyFileOptions, + DetectEntities, + MaskingMethod, + DetectOutputTranscription, + TokenFormat, + TokenType, + Transformations, + Bleep, + VaultConfig, +} from '../../src'; +import fs from 'fs'; + +/** + * Skyflow Deidentify File Example + * + * This sample demonstrates how to use all available options for deidentifying files. + * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. + */ + +async function performDeidentifyFile() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: '', // Replace with your BEARER token + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Deidentify File Request + // Replace with your file object (e.g., from fs.readFileSync or browser File API) + const buffer = fs.readFileSync(''); // Replace with the path to your file + const file = new File([buffer], ''); + const deidentifyFile = new DeidentifyFileRequest(file); + + // Step 5: Configure DeidentifyFileOptions + const options = new DeidentifyFileOptions(); + + // Entities to detect and deidentify + options.setEntities([DetectEntities.SSN, DetectEntities.CREDIT_CARD]); + + // Allowlist regex patterns (entities matching these will NOT be deidentified) + options.setAllowRegexList(['']); + + // Restrict deidentification to entities matching these regex patterns + options.setRestrictRegexList(['']); + + // Token format for deidentified entities + const tokenFormat = new TokenFormat(); + tokenFormat.setDefault(TokenType.VAULT_TOKEN); + options.setTokenFormat(tokenFormat); + + // Custom transformations for entities + const transformations = new Transformations(); + transformations.setShiftDays({ + max: 30, + min: 10, + entities: [DetectEntities.SSN], + }); + options.setTransformations(transformations); + + // Output directory for saving the deidentified file + options.setOutputDirectory(''); // Replace with your output directory + + // Wait time for response (max 20 seconds) + options.setWaitTime(15); + + // --- Image Options (apply when file is an image) --- + // options.setOutputProcessedImage(true); // Include processed image in output + // options.setOutputOcrText(true); // Include OCR text in response + // options.setMaskingMethod(MaskingMethod.Blackout); // Masking method for image entities + + // --- PDF Options (apply when file is a PDF) --- + // options.setPixelDensity(1.5); // Pixel density for PDF processing + // options.setMaxResolution(2000); // Max resolution for PDF + + // --- Audio Options (apply when file is audio) --- + // options.setOutputProcessedAudio(true); // Include processed audio in output + // options.setOutputTranscription(DetectOutputTranscription.PLAINTEXT_TRANSCRIPTION); // Type of transcription + + // Bleep audio configuration + // const bleep = new Bleep(); + // bleep.setGain(5); // Loudness in dB + // bleep.setFrequency(1000); // Pitch in Hz + // bleep.setStartPadding(0.1); // Padding at start in seconds + // bleep.setStopPadding(0.2); // Padding at end in seconds + // options.setBleep(bleep); + + + // Step 6: Call deidentifyFile API + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyFile(deidentifyFile, options); + + // Handle Successful Response + console.log('Deidentify File Response:', response); + + } catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +// Invoke the deidentify file function +performDeidentifyFile(); diff --git a/samples/detect-api/deidentify-text.ts b/samples/detect-api/deidentify-text.ts new file mode 100644 index 00000000..e65f016e --- /dev/null +++ b/samples/detect-api/deidentify-text.ts @@ -0,0 +1,106 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError, + DeidentifyTextRequest, + DeidentifyTextOptions, + TokenFormat, + TokenType, + Transformations, + DetectEntities +} from 'skyflow-node'; + +/** + * Skyflow Deidentify Text Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a deidentify text request + * 4. Use all available options for deidentification + * 5. Handle response and errors + */ + +async function performDeidentifyText() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: '', // Replace with your BEARER token + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', // Unique vault identifier + clusterId: '', // From vault URL + env: Env.DEV, // Deployment environment + credentials: credentials // Authentication method + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Deidentify Text Request + const deidentifyTextRequest = new DeidentifyTextRequest( + 'My SSN is 123-45-6789 and my card is 4111 1111 1111 1111.', // Text to be deidentified + ); + + // Step 5: Configure DeidentifyTextOptions + const optionsText = new DeidentifyTextOptions(); + + // setEntities: Specify which entities to deidentify + optionsText.setEntities([DetectEntities.CREDIT_CARD, DetectEntities.SSN]); + + // setAllowRegexList: Allowlist regex patterns (entities matching these will not be deidentified) + // optionsText.setAllowRegexList(['']); + + // setRestrictRegexList: Restrict deidentification to entities matching these regex patterns + // optionsText.setRestrictRegexList(['']); + + // setTokenFormat: Specify the token format for deidentified entities + const tokenFormat = new TokenFormat(); + tokenFormat.setDefault(TokenType.VAULT_TOKEN); + optionsText.setTokenFormat(tokenFormat); + + // setTransformations: Specify custom transformations for entities + const transformations = new Transformations(); + transformations.setShiftDays({ + max: 30, // Maximum shift days + min: 30, // Minimum shift days + entities: [DetectEntities.DOB], // Entities to apply the shift + }); + optionsText.setTransformations(transformations); + + // Step 6: Call deidentifyText API + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyText(deidentifyTextRequest, optionsText); + + // Handle Successful Response + console.log('Deidentify Text Response:', response); + + } catch (error) { + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +// Invoke the deidentify text function +performDeidentifyText(); diff --git a/samples/detect-api/reidentify-text.ts b/samples/detect-api/reidentify-text.ts new file mode 100644 index 00000000..e8ec04a2 --- /dev/null +++ b/samples/detect-api/reidentify-text.ts @@ -0,0 +1,77 @@ +// Sample: Using reidentifyText with ReidentifyTextOptions + +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + ReidentifyTextRequest, + ReidentifyTextOptions, + DetectEntities +} from 'skyflow-node'; + +/** + * Skyflow Deidentify Text Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a reidentify text request + * 4. Use all available options for reidentification + * 5. Handle response and errors + */ + +async function performReidentifyText() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: '', // Replace with your BEARER token + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Reidentify Text Request + const reidentifyRequest = new ReidentifyTextRequest( + '' // The redacted text to reidentify + ); + + // Step 5: Configure ReidentifyTextOptions + const options = new ReidentifyTextOptions(); + + // Specify which entities to reidentify as redacted, masked, or plain text + options.setRedactedEntities([DetectEntities.NAME, DetectEntities.SSN]); + options.setMaskedEntities([DetectEntities.DOB]); + options.setPlainTextEntities([DetectEntities.PHONE_NUMBER]); + + // Step 6: Call reidentifyText + const response = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .reidentifyText(reidentifyRequest, options); + + // Step 7: Handle response + console.log('Reidentified Text Response:', response); + + } catch (error) { + console.error('Error during reidentifyText:', error); + } +} + +// Invoke the reidentify text function +performReidentifyText(); From 6ff5b880adbdabd0d421c5f13a1d339dd816d43e Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 14:16:07 +0530 Subject: [PATCH 13/30] SK-2048: add get detect run public interface --- src/error/codes/index.ts | 2 + src/error/messages/index.ts | 2 + src/index.ts | 4 +- src/utils/index.ts | 1 + src/utils/logs/index.ts | 5 +- src/utils/validations/index.ts | 14 +++++ src/vault/client/index.ts | 1 + src/vault/controller/detect/index.ts | 81 ++++++++++++++++++------- test/vault/controller/detect.test.js | 91 +++++++++++++++++++++++++++- 9 files changed, 177 insertions(+), 24 deletions(-) diff --git a/src/error/codes/index.ts b/src/error/codes/index.ts index 71a1ee08..dcc6c5c1 100644 --- a/src/error/codes/index.ts +++ b/src/error/codes/index.ts @@ -224,6 +224,8 @@ const SKYFLOW_ERROR_CODE = { INVALID_WAIT_TIME:{ http_code: 400, message: errorMessages.INVALID_WAIT_TIME }, INVALID_OUTPUT_DIRECTORY:{ http_code: 400, message: errorMessages.INVALID_OUTPUT_DIRECTORY }, INVALID_OUTPUT_DIRECTORY_PATH:{ http_code: 400, message: errorMessages.INVALID_OUTPUT_DIRECTORY_PATH }, + EMPTY_RUN_ID:{ http_code: 400, message: errorMessages.EMPTY_RUN_ID }, + INVALID_RUN_ID:{ http_code: 400, message: errorMessages.INVALID_RUN_ID }, }; export default SKYFLOW_ERROR_CODE; \ No newline at end of file diff --git a/src/error/messages/index.ts b/src/error/messages/index.ts index 63554708..bebf54c1 100644 --- a/src/error/messages/index.ts +++ b/src/error/messages/index.ts @@ -237,6 +237,8 @@ const errorMessages = { INVALID_WAIT_TIME: `${errorPrefix} Validation error. Invalid wait time. Specify a valid wait time as number and should not be greater than 20 secs.`, INVALID_OUTPUT_DIRECTORY: `${errorPrefix} Validation error. Invalid output directory. Specify a valid output directory as string.`, INVALID_OUTPUT_DIRECTORY_PATH: `${errorPrefix} Validation error. Invalid output directory path. Specify a valid output directory path as string.`, + EMPTY_RUN_ID: `${errorPrefix} Validation error. Run id cannot be empty. Specify a valid run id.`, + INVALID_RUN_ID: `${errorPrefix} Validation error. Invalid run id. Specify a valid run id as string.`, }; export default errorMessages; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 47525e45..9eecf2e3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,6 +42,7 @@ import Transformations from './vault/model/options/deidentify-text/transformatio 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 GetDetectRunRequest from './vault/model/request/get-detect-run'; import { TokenType, MaskingMethod, DetectOutputTranscription } from './utils'; import { Bleep } from './vault/model/options/deidentify-file/bleep-audio'; export { @@ -106,5 +107,6 @@ export { TokenType, Bleep, MaskingMethod, - DetectOutputTranscription + DetectOutputTranscription, + GetDetectRunRequest }; \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index 020fc092..b1ff6e66 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -100,6 +100,7 @@ export const TYPES = { INVOKE_CONNECTION: 'INVOKE_CONNECTION', DEIDENTIFY_TEXT: 'DEIDENTIFY_TEXT', DEIDENTIFY_FILE: 'DEIDENTIFY_FILE', + DETECT_RUN: 'DETECT_RUN', }; export enum DeidenitfyFileRequestTypes { diff --git a/src/utils/logs/index.ts b/src/utils/logs/index.ts index 822c0966..262c680a 100644 --- a/src/utils/logs/index.ts +++ b/src/utils/logs/index.ts @@ -73,6 +73,8 @@ const logs = { VALIDATE_REIDENTIFY_TEXT_INPUT: 'Validating reidentify text input', VALIDATE_DETECT_FILE_INPUT: 'Validating deidentify file input.', DETECT_FILE_TRIGGERED: 'Deidentify file triggered.', + GET_DETECT_RUN_TRIGGERED: 'Get detect run triggered.', + VALIDATE_GET_DETECT_RUN_INPUT: 'Validating get detect run input.', }, errorLogs: { VAULT_CONFIG_KEY_MISSING: "Invalid skyflow config. Vaults configs key missing in skyflow config.", @@ -164,7 +166,8 @@ const logs = { INVALID_TABLE_IN_FILE_UPLOAD: "Invalid file upload request. Table name is required.", EMPTY_SKYFLOW_ID_IN_FILE_UPLOAD: "Invalid file upload request. Skyflow Id can not be empty.", INVALID_SKYFLOW_ID_IN_FILE_UPLOAD: "Invalid file upload request. Skyflow Id is required.", - + EMPTY_RUN_ID: "Invalid Run Id. Run Id can not be empty.", + INVALID_RUN_ID: "Invalid Run ID. A Run ID of string type is required.", }, warnLogs: { } diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index b574c3aa..1216ce37 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -34,6 +34,7 @@ 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 { Bleep } from "../../vault/model/options/deidentify-file/bleep-audio"; +import GetDetectRunRequest from "../../vault/model/request/get-detect-run"; export function isEnv(value?: string): boolean { return value !== undefined && Object.values(Env).includes(value as Env); @@ -1019,6 +1020,19 @@ export const validateDeidentifyFileRequest = (deidentifyFileRequest: DeidentifyF } }; +export const validateGetDetectRunRequest = (getDetectRunRequest: GetDetectRunRequest, logLevel: LogLevel = LogLevel.ERROR) => { + if (getDetectRunRequest) { + if (!getDetectRunRequest?.runId) { + printLog(logs.errorLogs.EMPTY_RUN_ID, MessageType.ERROR, logLevel); + throw new SkyflowError(SKYFLOW_ERROR_CODE.EMPTY_RUN_ID); + } + if (typeof getDetectRunRequest.runId !== 'string' || getDetectRunRequest.runId.trim().length === 0) { + printLog(logs.errorLogs.INVALID_RUN_ID, MessageType.ERROR, logLevel); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RUN_ID); + } + } +} + export const validateDeidentifyFileOptions = (deidentifyFileOptions: DeidentifyFileOptions) => { if (!deidentifyFileOptions) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_DEIDENTIFY_FILE_OPTIONS); diff --git a/src/vault/client/index.ts b/src/vault/client/index.ts index e4b6d968..0e52e168 100644 --- a/src/vault/client/index.ts +++ b/src/vault/client/index.ts @@ -87,6 +87,7 @@ class VaultClient { this.stringsAPI = new Strings(this.configuration); break; case TYPES.DEIDENTIFY_FILE: + case TYPES.DETECT_RUN: this.filesAPI = new Files(this.configuration); break; default: diff --git a/src/vault/controller/detect/index.ts b/src/vault/controller/detect/index.ts index da7b2621..1214bacd 100644 --- a/src/vault/controller/detect/index.ts +++ b/src/vault/controller/detect/index.ts @@ -7,7 +7,7 @@ import { DeidentifyFileRequest as DeidentifyFileRequest2} from "../../../ _gene import { TokenType } from "../../../ _generated_/rest/api"; import { DeidenitfyFileRequestTypes, generateSDKMetrics, getBearerToken, MessageType, parameterizedString, printLog, removeSDKVersion, SDK_METRICS_HEADER_KEY, TYPES } from "../../../utils"; import logs from "../../../utils/logs"; -import { validateDeIdentifyTextRequest, validateReidentifyTextRequest, validateDeidentifyFileRequest } from "../../../utils/validations"; +import { validateDeIdentifyTextRequest, validateReidentifyTextRequest, validateDeidentifyFileRequest, validateGetDetectRunRequest } from "../../../utils/validations"; import VaultClient from "../../client"; import DeidentifyTextOptions from "../../model/options/deidentify-text"; import ReidentifyTextOptions from "../../model/options/reidentify-text"; @@ -22,6 +22,7 @@ import DeidentifyFileResponse from "../../model/response/deidentify-file"; import * as fs from 'fs'; import SkyflowError from "../../../error"; import SKYFLOW_ERROR_CODE from "../../../error/codes"; +import GetDetectRunRequest from "../../model/request/get-detect-run"; class DetectController { @@ -369,7 +370,11 @@ class DetectController { const maxWaitTime = this.waitTime; this.pollForProcessedFile(data.run_id, req, maxWaitTime, resolve, reject); // Call the extracted polling function - break; + break; + case TYPES.DETECT_RUN: + resolve({data, requestId}) + break; + } }).catch((error: any) => { printLog(logs.errorLogs[`${requestType}_REQUEST_REJECTED`], MessageType.ERROR, this.client.getLogLevel()); @@ -424,6 +429,27 @@ class DetectController { }; } + private parseDeidentifyFileResponse(data: any): DeidentifyFileResponse { + return 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') + .map((fileObject: any) => ({ + file: fileObject.processedFile, + extension: fileObject.processedFileExtension, + })), + runId: data.runId ?? data.run_id, // Handles both camelCase and snake_case + }); + } + deidentifyText(request: DeidentifyTextRequest, options?: DeidentifyTextOptions): Promise { return new Promise((resolve, reject) => { try { @@ -489,6 +515,37 @@ class DetectController { }); } + getDetectRun(request: GetDetectRunRequest): Promise { + return new Promise((resolve, reject) => { + try { + printLog(logs.infoLogs.GET_DETECT_RUN_TRIGGERED, MessageType.LOG, this.client.getLogLevel()); + printLog(logs.infoLogs.VALIDATE_GET_DETECT_RUN_INPUT, MessageType.LOG, this.client.getLogLevel()); + validateGetDetectRunRequest(request, this.client.getLogLevel()); + + const req: GetRunRequest = { + vault_id: this.client.vaultId + } + + this.handleRequest( + () => this.client.filesAPI.getRun( + request.runId, + req + ).withRawResponse(), + TYPES.DETECT_RUN + ).then(response => { + const deidentifiedFileResponse = this.parseDeidentifyFileResponse(response.data); + resolve(deidentifiedFileResponse); + }).catch(error => { + reject(error) + }); + } catch (error) { + if (error instanceof Error) + printLog(removeSDKVersion(error.message), MessageType.ERROR, this.client.getLogLevel()); + reject(error); + } + }); + } + deidentifyFile(request: DeidentifyFileRequest, options?: DeidentifyFileOptions): Promise { return new Promise((resolve, reject) => { try { @@ -615,25 +672,7 @@ class DetectController { if (options?.getOutputDirectory() && data.status === "SUCCESS") { this.processDeidentifyFileResponse(data, options.getOutputDirectory() as string, fileBaseName); } - 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, - })), - } - ) + const deidentifiedFileResponse = this.parseDeidentifyFileResponse(data); resolve(deidentifiedFileResponse); }).catch(error => { reject(error) diff --git a/test/vault/controller/detect.test.js b/test/vault/controller/detect.test.js index cdaf284d..90a8322c 100644 --- a/test/vault/controller/detect.test.js +++ b/test/vault/controller/detect.test.js @@ -1,5 +1,5 @@ import DetectController from '../../../src/vault/controller/detect'; -import { validateDeidentifyFileRequest, validateDeIdentifyTextRequest, validateReidentifyTextRequest } from '../../../src/utils/validations'; +import { validateDeidentifyFileRequest, validateDeIdentifyTextRequest, validateGetDetectRunRequest, validateReidentifyTextRequest } from '../../../src/utils/validations'; import DeidentifyTextResponse from '../../../src/vault/model/response/deidentify-text'; import ReidentifyTextResponse from '../../../src/vault/model/response/reidentify-text'; import DeidentifyFileRequest from '../../../src/vault/model/request/deidentify-file'; @@ -18,6 +18,7 @@ jest.mock('../../../src/utils', () => ({ TYPES: { DETECT: 'DETECT', DEIDENTIFY_FILE: 'DEIDENTIFY_FILE', + DETECT_RUN: 'DETECT_RUN', }, DeidenitfyFileRequestTypes: { AUDIO: 'AUDIO', @@ -38,6 +39,7 @@ jest.mock('../../../src/utils/validations', () => ({ validateDeIdentifyTextRequest: jest.fn(), validateReidentifyTextRequest: jest.fn(), validateDeidentifyFileRequest: jest.fn(), + validateGetDetectRunRequest: jest.fn(), })); describe('DetectController', () => { @@ -765,4 +767,91 @@ describe('DetectController - Files', () => { }); +}); + +describe('getDetectRun', () => { + let mockVaultClient; + let detectController; + + beforeEach(() => { + mockVaultClient = { + getLogLevel: jest.fn().mockReturnValue('DEBUG'), + getCredentials: jest.fn().mockReturnValue({}), + initAPI: jest.fn(), + filesAPI: { + getRun: jest.fn(), + }, + failureResponse: jest.fn().mockRejectedValue(new Error('API error')), + vaultId: 'vault123', + }; + detectController = new DetectController(mockVaultClient); + jest.clearAllMocks(); + }); + + test('should successfully get detect run and parse response', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateGetDetectRunRequest: jest.fn(), + })); + validateGetDetectRunRequest.mockImplementation(() => { + // No validation error + }); + const mockRequest = { runId: 'mockRunId' }; + const mockResponseData = { + output: [ + { + processedFile: 'mockProcessedFile', + processedFileType: 'text', + processedFileExtension: 'txt', + }, + ], + wordCharacterCount: { + wordCount: 100, + characterCount: 500, + }, + size: 1024, + duration: 0, + pages: 1, + slides: 0, + run_id: 'mockRunId', + }; + + mockVaultClient.filesAPI.getRun.mockImplementation(() => ({ + withRawResponse: jest.fn().mockResolvedValue({ + data: mockResponseData, + rawResponse: { headers: { get: jest.fn().mockReturnValue('request-id-123') } }, + }), + })); + + const result = await detectController.getDetectRun(mockRequest); + + expect(mockVaultClient.filesAPI.getRun).toHaveBeenCalledWith( + mockRequest.runId, + { vault_id: 'vault123' } + ); + }); + + test('should handle validation errors', async () => { + const mockRequest = { runId: 'mockRunId' }; + validateGetDetectRunRequest.mockImplementation(() => { + throw new Error('Validation error'); + }); + + await expect(detectController.getDetectRun(mockRequest)).rejects.toThrow('Validation error'); + expect(mockVaultClient.filesAPI.getRun).not.toHaveBeenCalled(); + }); + + test('should handle API errors during getDetectRun', async () => { + jest.mock('../../../src/utils/validations', () => ({ + validateGetDetectRunRequest: jest.fn(), + })); + validateGetDetectRunRequest.mockImplementation(() => { + // No validation error + }); + const mockRequest = { runId: 'mockRunId' }; + mockVaultClient.filesAPI.getRun.mockImplementation(() => ({ + withRawResponse: jest.fn().mockRejectedValue(new Error('API error')), + })); + + await expect(detectController.getDetectRun(mockRequest)).rejects.toThrow('API error'); + }); }); \ No newline at end of file From 93fbafd72037fa9904e84d3e39b7e9b7a7163795 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 14:18:08 +0530 Subject: [PATCH 14/30] SK-2048: add get detect run request model --- .../model/request/get-detect-run/index.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/vault/model/request/get-detect-run/index.ts diff --git a/src/vault/model/request/get-detect-run/index.ts b/src/vault/model/request/get-detect-run/index.ts new file mode 100644 index 00000000..563dabb8 --- /dev/null +++ b/src/vault/model/request/get-detect-run/index.ts @@ -0,0 +1,21 @@ +class GetDetectRunRequest { + // Field + private _runId: string; + + // Constructor + constructor(runId: string) { + this._runId = runId; + } + + // Getter for runId + public get runId(): string { + return this._runId; + } + + // Setter for runId + public set runId(value: string) { + this._runId = value; + } +} + +export default GetDetectRunRequest; \ No newline at end of file From 884faadf631081fbc443aefba270e1496d0abb07 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 08:48:34 +0000 Subject: [PATCH 15/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.93fbafd --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 17d40f64..ae9d7011 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.a3ccb6a", + "version": "2.0.0-beta.4-dev.93fbafd", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From f80b961917b55adc7046454dad1131a120bc8ad4 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 14:58:15 +0530 Subject: [PATCH 16/30] SK-2048: added get detect run in readme --- README.md | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/README.md b/README.md index a5e1430f..26a461d1 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ SDK for the Skyflow Data Privacy Vault. - [Deidentify Text](#deidentify-text) - [Reidentify Text](#reidentify-text) - [Deidentify File](#deidentify-file) + - [Get Run](#get-run) - [Connections](#connections) - [Invoke a connection](#invoke-a-connection) - [Authenticate with bearer tokens](#authenticate-with-bearer-tokens) @@ -2351,6 +2352,145 @@ Sample response (when the API takes more than 20 seconds): } ``` +### Get run +To retrieve the results of a previously started file deidentification operation, use the `getDetectRun` method. +The `GetDetectRunRequest` class is initialized with the `runId` returned from a prior `deidentifyFile` call. +This method allows you to fetch the final results of the file processing operation once they are available. + + +```typescript +import { + GetDetectRunRequest, + DeidentifyFileResponse, + SkyflowError +} from 'skyflow-node'; + +try { + // Step 1: Prepare the GetDetectRunRequest with the runId from a previous deidentifyFile call + const getDetectRunRequest = new GetDetectRunRequest({ + runId: '', // Replace with the runId you received earlier + }); + + // Step 2: Call getDetectRun + const response: DeidentifyFileResponse = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .getDetectRun(getDetectRunRequest); + + // Step 3: Handle the response + console.log('Get Detect Run Response:', response); + +} catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Error:', error.message); + } else { + console.error('Unexpected Error:', error); + } +} +``` + +#### An example of a get run function + +```typescript +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError, + GetDetectRunRequest, + DeidentifyFileResponse +} from 'skyflow-node'; + +/** + * Skyflow Get Detect Run Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a get detect run request + * 4. Call getDetectRun to poll for file processing results + * 5. Handle response and errors + */ + +async function performGetDetectRun() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: '', // Replace with your BEARER token + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', // Unique vault identifier + clusterId: '', // From vault URL + env: Env.DEV, // Deployment environment + credentials: credentials // Authentication method + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare GetDetectRunRequest + const getDetectRunRequest = new GetDetectRunRequest({ + runId: '', // Replace with the runId from a previous deidentifyFile call + }); + + // Step 5: Call getDetectRun API + const response: DeidentifyFileResponse = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .getDetectRun(getDetectRunRequest); + + // Handle Successful Response + console.log('Get Detect Run Response:', response); + + } catch (error) { + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +// Invoke the get detect run function +performGetDetectRun(); +``` + +Sample Response + +```typescript +{ + entities: [ + { + file: '0X2xhYmVsIjoiQ1JFRElUX0NB==', + extension: 'json' + } + ], + file: 'TXkgU1NOIGlzIFtTU0==', + type: 'redacted_file', + extension: 'txt', + wordCount: 12, + charCount: 58, + sizeInKb: 0.06, + durationInSeconds: 0, + pageCount: 0, + slideCount: 0, +} +``` + ## Connections Skyflow Connections is a gateway service that uses tokenization to securely send and receive data between your systems and first- or third-party services. The [connections](https://github.com/skyflowapi/skyflow-node/tree/v2/src/vault/controller/connections) module invokes both inbound and/or outbound connections. From f6af2aa286ce458343d56a08a5563e3996464b8e Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 15:00:11 +0530 Subject: [PATCH 17/30] SK-2048: added get detect run sample --- samples/detect-api/get-detect-run.ts | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 samples/detect-api/get-detect-run.ts diff --git a/samples/detect-api/get-detect-run.ts b/samples/detect-api/get-detect-run.ts new file mode 100644 index 00000000..4c0adcfe --- /dev/null +++ b/samples/detect-api/get-detect-run.ts @@ -0,0 +1,76 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError, + GetDetectRunRequest, + DeidentifyFileResponse +} from 'skyflow-node'; + +/** + * Skyflow Get Detect Run Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a get detect run request + * 4. Call getDetectRun to poll for file processing results + * 5. Handle response and errors + */ + +async function performGetDetectRun() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: '', // Replace with your BEARER token + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', // Unique vault identifier + clusterId: '', // From vault URL + env: Env.DEV, // Deployment environment + credentials: credentials // Authentication method + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare GetDetectRunRequest + const getDetectRunRequest = new GetDetectRunRequest( + '', // Replace with the runId from deidentifyFile call + ); + + // Step 5: Call getDetectRun API + const response: DeidentifyFileResponse = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .getDetectRun(getDetectRunRequest); + + // Handle Successful Response + console.log('Get Detect Run Response:', response); + + } catch (error) { + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +// Invoke the get detect run function +performGetDetectRun(); \ No newline at end of file From bb22d9d63cbe55d94f267f3c4aafb86704a280a7 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 19:14:14 +0530 Subject: [PATCH 18/30] SK-2048: update polling --- src/error/codes/index.ts | 1 + src/error/messages/index.ts | 1 + src/utils/validations/index.ts | 2 +- src/vault/controller/detect/index.ts | 26 ++++++++++++++----- .../model/response/deidentify-file/index.ts | 6 ++++- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/error/codes/index.ts b/src/error/codes/index.ts index dcc6c5c1..9f751137 100644 --- a/src/error/codes/index.ts +++ b/src/error/codes/index.ts @@ -226,6 +226,7 @@ const SKYFLOW_ERROR_CODE = { INVALID_OUTPUT_DIRECTORY_PATH:{ http_code: 400, message: errorMessages.INVALID_OUTPUT_DIRECTORY_PATH }, EMPTY_RUN_ID:{ http_code: 400, message: errorMessages.EMPTY_RUN_ID }, INVALID_RUN_ID:{ http_code: 400, message: errorMessages.INVALID_RUN_ID }, + INTERNAL_SERVER_ERROR: { http_code: 500, message: errorMessages.INTERNAL_SERVER_ERROR }, }; export default SKYFLOW_ERROR_CODE; \ No newline at end of file diff --git a/src/error/messages/index.ts b/src/error/messages/index.ts index bebf54c1..21096fad 100644 --- a/src/error/messages/index.ts +++ b/src/error/messages/index.ts @@ -239,6 +239,7 @@ const errorMessages = { INVALID_OUTPUT_DIRECTORY_PATH: `${errorPrefix} Validation error. Invalid output directory path. Specify a valid output directory path as string.`, EMPTY_RUN_ID: `${errorPrefix} Validation error. Run id cannot be empty. Specify a valid run id.`, INVALID_RUN_ID: `${errorPrefix} Validation error. Invalid run id. Specify a valid run id as string.`, + INTERNAL_SERVER_ERROR: `${errorPrefix}. Internal server error. %s1.`, }; export default errorMessages; \ No newline at end of file diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index 1216ce37..1b9d51af 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -1041,7 +1041,7 @@ export const validateDeidentifyFileOptions = (deidentifyFileOptions: DeidentifyF //Validate waitTime const waitTime = deidentifyFileOptions.getWaitTime(); if (waitTime !== undefined) { - if (typeof waitTime !== 'number' || waitTime > 20) { + if (typeof waitTime !== 'number' || waitTime > 64) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_WAIT_TIME); } } diff --git a/src/vault/controller/detect/index.ts b/src/vault/controller/detect/index.ts index 1214bacd..047e3782 100644 --- a/src/vault/controller/detect/index.ts +++ b/src/vault/controller/detect/index.ts @@ -28,7 +28,7 @@ class DetectController { private client: VaultClient; - private waitTime: number = 20; + private waitTime: number = 64; constructor(client: VaultClient) { this.client = client; @@ -327,17 +327,28 @@ class DetectController { this.client.filesAPI.getRun(runId, req) .then((response: any) => { if (response.status === 'IN_PROGRESS') { - if (currentWaitTime > maxWaitTime) { + if (currentWaitTime >= maxWaitTime) { resolve({ runId }); // Resolve with runId if max wait time is exceeded } else { + const nextWaitTime = currentWaitTime * 2; + let waitTime = 0; + if (nextWaitTime >= maxWaitTime) { + waitTime = maxWaitTime - currentWaitTime; + currentWaitTime = maxWaitTime; + } else { + waitTime = nextWaitTime; + currentWaitTime = nextWaitTime; + } setTimeout(() => { - currentWaitTime *= 2; // Exponential backoff poll(); - }, currentWaitTime * 1000); + }, waitTime * 1000); } } else if (response.status === 'SUCCESS') { resolve(response); // Resolve with the processed file response } + else if (response.status === 'FAILED') { + reject(new SkyflowError(SKYFLOW_ERROR_CODE.INTERNAL_SERVER_ERROR, [response.message])); + } }) .catch((error: any) => { reject(error); @@ -429,8 +440,9 @@ class DetectController { }; } - private parseDeidentifyFileResponse(data: any): DeidentifyFileResponse { + private parseDeidentifyFileResponse(data: any, runId?: string, status?: string): DeidentifyFileResponse { return new DeidentifyFileResponse({ + status: status, file: data.output?.[0]?.processedFile ?? '', type: data.output?.[0]?.processedFileType ?? '', extension: data.output?.[0]?.processedFileExtension ?? '', @@ -446,7 +458,7 @@ class DetectController { file: fileObject.processedFile, extension: fileObject.processedFileExtension, })), - runId: data.runId ?? data.run_id, // Handles both camelCase and snake_case + runId: data.runId ?? data.run_id ?? runId, // Handles both camelCase and snake_case }); } @@ -533,7 +545,7 @@ class DetectController { ).withRawResponse(), TYPES.DETECT_RUN ).then(response => { - const deidentifiedFileResponse = this.parseDeidentifyFileResponse(response.data); + const deidentifiedFileResponse = this.parseDeidentifyFileResponse(response.data, request.runId, response.data.status); resolve(deidentifiedFileResponse); }).catch(error => { reject(error) diff --git a/src/vault/model/response/deidentify-file/index.ts b/src/vault/model/response/deidentify-file/index.ts index 1e85fae9..8ef92cad 100644 --- a/src/vault/model/response/deidentify-file/index.ts +++ b/src/vault/model/response/deidentify-file/index.ts @@ -14,6 +14,7 @@ class DeidentifyFileResponse { pageCount?: number; slideCount?: number; runId?: string; + status?: string; constructor({ file, @@ -27,7 +28,8 @@ class DeidentifyFileResponse { pageCount, slideCount, entities, - runId + runId, + status } :{ file?: string; type?: string; @@ -44,6 +46,7 @@ class DeidentifyFileResponse { extension: string; }>; runId?: string; + status?: string; }) { this.file = file; this.type = type; @@ -57,6 +60,7 @@ class DeidentifyFileResponse { this.slideCount = slideCount; this.entities = entities; this.runId = runId; + this.status = status; } } From 26f0b5eca8f0adfa7ad172e4d731d819e07d0610 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 13:45:52 +0000 Subject: [PATCH 19/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.bb22d9d --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ae9d7011..414ce26e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.93fbafd", + "version": "2.0.0-beta.4-dev.bb22d9d", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From 95715b0bd3587f700558c44888e65340147e3737 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 23:06:19 +0530 Subject: [PATCH 20/30] SK-2048: fix transformations --- src/utils/index.ts | 1 + src/utils/logs/index.ts | 10 ++++ src/vault/client/index.ts | 3 +- src/vault/controller/detect/index.ts | 48 ++++++++++--------- .../model/response/deidentify-file/index.ts | 3 -- test/vault/controller/detect.test.js | 2 + 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index b1ff6e66..28991206 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -99,6 +99,7 @@ export const TYPES = { DETECT: 'DETECT', INVOKE_CONNECTION: 'INVOKE_CONNECTION', DEIDENTIFY_TEXT: 'DEIDENTIFY_TEXT', + REIDENTIFY_TEXT: 'REIDENTIFY_TEXT', DEIDENTIFY_FILE: 'DEIDENTIFY_FILE', DETECT_RUN: 'DETECT_RUN', }; diff --git a/src/utils/logs/index.ts b/src/utils/logs/index.ts index 262c680a..36ee565b 100644 --- a/src/utils/logs/index.ts +++ b/src/utils/logs/index.ts @@ -61,6 +61,11 @@ const logs = { GENERATE_SIGNED_DATA_TOKENS_TRIGGERED: "generateSignedDataTokens is triggered", UPDATE_TRIGGERED: 'Update method triggered.', UPDATE_REQUEST_RESOLVED: 'Update request is resolved.', + DETECT_REQUEST_RESOLVED: 'Detect request is resolved.', + DEIDENTIFY_FILE_REQUEST_RESOLVED: 'Deidentify file request is resolved.', + DETECT_RUN_REQUEST_RESOLVED: 'Detect get run request is resolved.', + DEIDENTIFY_TEXT_REQUEST_RESOLVED: 'Deidentify text request is resolved.', + REIDENTIFY_TEXT_REQUEST_RESOLVED: 'Reidentify text request is resolved.', UNABLE_TO_GENERATE_SDK_METRIC: 'Unable to generate %s1 metric.', USING_BEARER_TOKEN: 'Using token from credentials', USING_API_KEY: 'Using api key from credentials', @@ -168,6 +173,11 @@ const logs = { INVALID_SKYFLOW_ID_IN_FILE_UPLOAD: "Invalid file upload request. Skyflow Id is required.", EMPTY_RUN_ID: "Invalid Run Id. Run Id can not be empty.", INVALID_RUN_ID: "Invalid Run ID. A Run ID of string type is required.", + DETECT_REQUEST_RESOLVED: 'Detect request is resolved.', + DEIDENTIFY_FILE_REQUEST_REJECTED: 'Deidentify file resulted in failure.', + DETECT_RUN_REQUEST_REJECTED: 'Detect get run resulted in failure.', + DEIDENTIFY_TEXT_REQUEST_REJECTED: 'Deidentify text resulted in failure.', + REIDENTIFY_TEXT_REQUEST_REJECTED: 'Reidentify text resulted in failure.', }, warnLogs: { } diff --git a/src/vault/client/index.ts b/src/vault/client/index.ts index 0e52e168..0fb9ef22 100644 --- a/src/vault/client/index.ts +++ b/src/vault/client/index.ts @@ -83,7 +83,8 @@ class VaultClient { case TYPES.QUERY: this.queryAPI = new Query(this.configuration); break; - case TYPES.DETECT: + case TYPES.DEIDENTIFY_TEXT: + case TYPES.REIDENTIFY_TEXT: this.stringsAPI = new Strings(this.configuration); break; case TYPES.DEIDENTIFY_FILE: diff --git a/src/vault/controller/detect/index.ts b/src/vault/controller/detect/index.ts index 047e3782..0c7efe82 100644 --- a/src/vault/controller/detect/index.ts +++ b/src/vault/controller/detect/index.ts @@ -1,7 +1,7 @@ //imports 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, TokenTypeWithoutVault } from "../../../ _generated_/rest/api"; +import { DeidentifyTextRequest as DeidentifyTextRequest2,DeidentifyAudioRequest, DeidentifyAudioRequestFileDataFormat, DeidentifyDocumentRequest, DeidentifyDocumentRequestFileDataFormat, DeidentifyFileRequestFileDataFormat, DeidentifyImageRequest, DeidentifyImageRequestFileDataFormat, DeidentifyImageRequestMaskingMethod, DeidentifyPdfRequest, DeidentifyPresentationRequest, DeidentifyPresentationRequestFileDataFormat, DeidentifySpreadsheetRequest, DeidentifySpreadsheetRequestFileDataFormat, DeidentifyStructuredTextRequest, DeidentifyStructuredTextRequestFileDataFormat, DetectedEntity, EntityType, GetRunRequest, Transformations as GeneratedTransformations, TokenTypeWithoutVault } from "../../../ _generated_/rest/api"; import { DeidentifyFileRequest as DeidentifyFileRequest2} from "../../../ _generated_/rest/api"; import { TokenType } from "../../../ _generated_/rest/api"; @@ -23,6 +23,7 @@ import * as fs from 'fs'; import SkyflowError from "../../../error"; import SKYFLOW_ERROR_CODE from "../../../error/codes"; import GetDetectRunRequest from "../../model/request/get-detect-run"; +import Transformations from "../../model/options/deidentify-text/transformations"; class DetectController { @@ -45,6 +46,17 @@ class DetectController { return base64String; } + private getTransformations(options?: DeidentifyFileOptions) { + const transformations = options?.getTransformations() as Transformations | undefined; + return { + shift_dates: { + max_days: transformations?.getShiftDays()?.max, + min_days: transformations?.getShiftDays()?.min, + entity_types: transformations?.getShiftDays()?.entities, + } + }; + } + private async buildAudioRequest(baseRequest: DeidentifyFileRequest, options?: DeidentifyFileOptions, fileExtension?: string): Promise { const base64String = await this.getBase64FileContent(baseRequest.getFile()); var audioRequest : DeidentifyAudioRequest = { @@ -61,7 +73,7 @@ class DetectController { } as TokenTypeWithoutVault, allow_regex: options?.getAllowRegexList(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, + transformations: this.getTransformations(options) as GeneratedTransformations, output_transcription: options?.getOutputTranscription(), output_processed_audio: options?.getOutputProcessedAudio(), bleep_gain: options?.getBleep()?.getGain(), @@ -88,7 +100,7 @@ class DetectController { } as TokenTypeWithoutVault, allow_regex: options?.getAllowRegexList(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, + transformations: this.getTransformations(options) as GeneratedTransformations, } return textFileRequest; } @@ -108,7 +120,6 @@ class DetectController { } as TokenTypeWithoutVault, allow_regex: options?.getAllowRegexList(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, max_resolution: options?.getMaxResolution(), density: options?.getPixelDensity(), } @@ -129,7 +140,6 @@ class DetectController { output_ocr_text: options?.getOutputOcrText(), output_processed_image: options?.getOutputProcessedImage(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, token_type: { default: options?.getTokenFormat()?.getDefault(), entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), @@ -156,7 +166,6 @@ class DetectController { } as TokenTypeWithoutVault, allow_regex: options?.getAllowRegexList(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, }; return pptRequest; } @@ -177,7 +186,7 @@ class DetectController { } as TokenTypeWithoutVault, allow_regex: options?.getAllowRegexList(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, + transformations: this.getTransformations(options) as GeneratedTransformations, }; return spreadsheetRequest; } @@ -198,7 +207,7 @@ class DetectController { } as TokenTypeWithoutVault, allow_regex: options?.getAllowRegexList(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, + transformations: this.getTransformations(options) as GeneratedTransformations, }; return structuredTextRequest; } @@ -219,7 +228,6 @@ class DetectController { } as TokenTypeWithoutVault, allow_regex: options?.getAllowRegexList(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, }; return documentRequest; } @@ -239,7 +247,7 @@ class DetectController { } as TokenTypeWithoutVault, allow_regex: options?.getAllowRegexList(), restrict_regex: options?.getRestrictRegexList(), - transformations: options?.getTransformations() as Transformations, + transformations: this.getTransformations(options) as GeneratedTransformations, entity_types: options?.getEntities() as EntityType[], } return genericRequest; @@ -370,7 +378,8 @@ class DetectController { const requestId = rawResponse?.headers?.get('x-request-id'); printLog(logs.infoLogs[`${requestType}_REQUEST_RESOLVED`], MessageType.LOG, this.client.getLogLevel()); switch (requestType) { - case TYPES.DETECT: + case TYPES.DEIDENTIFY_TEXT: + case TYPES.REIDENTIFY_TEXT: resolve({records: data, requestId}) break; case TYPES.DEIDENTIFY_FILE: @@ -408,13 +417,7 @@ class DetectController { entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), entity_only: options?.getTokenFormat()?.getEntityOnly(), } as TokenType, - transformations: { - shift_dates: { - max_days: options?.getTransformations()?.getShiftDays()?.max, - min_days: options?.getTransformations()?.getShiftDays()?.min, - entity_types: options?.getTransformations()?.getShiftDays()?.entities, - } - } as Transformations, + transformations: options?.getTransformations() as GeneratedTransformations, }; } @@ -442,7 +445,6 @@ class DetectController { private parseDeidentifyFileResponse(data: any, runId?: string, status?: string): DeidentifyFileResponse { return new DeidentifyFileResponse({ - status: status, file: data.output?.[0]?.processedFile ?? '', type: data.output?.[0]?.processedFileType ?? '', extension: data.output?.[0]?.processedFileExtension ?? '', @@ -459,6 +461,7 @@ class DetectController { extension: fileObject.processedFileExtension, })), runId: data.runId ?? data.run_id ?? runId, // Handles both camelCase and snake_case + status: status, }); } @@ -475,7 +478,7 @@ class DetectController { () => this.client.stringsAPI.deidentifyString( requestBody ).withRawResponse(), - TYPES.DETECT + TYPES.DEIDENTIFY_TEXT ).then(data => { const parsedResponse = new DeidentifyTextResponse(this.parseDeidentifyTextResponse(data)) resolve(parsedResponse); @@ -510,7 +513,7 @@ class DetectController { () => this.client.stringsAPI.reidentifyString( requestBody ).withRawResponse(), - TYPES.DETECT + TYPES.REIDENTIFY_TEXT ).then(data => { resolve(new ReidentifyTextResponse({ processedText: data.records.text @@ -679,12 +682,13 @@ class DetectController { if(data.runId){ resolve(new DeidentifyFileResponse({ runId: data.runId, + status: 'IN_PROGRESS', })); } if (options?.getOutputDirectory() && data.status === "SUCCESS") { this.processDeidentifyFileResponse(data, options.getOutputDirectory() as string, fileBaseName); } - const deidentifiedFileResponse = this.parseDeidentifyFileResponse(data); + const deidentifiedFileResponse = this.parseDeidentifyFileResponse(data, undefined, data.status); resolve(deidentifiedFileResponse); }).catch(error => { reject(error) diff --git a/src/vault/model/response/deidentify-file/index.ts b/src/vault/model/response/deidentify-file/index.ts index 8ef92cad..4a5fe12c 100644 --- a/src/vault/model/response/deidentify-file/index.ts +++ b/src/vault/model/response/deidentify-file/index.ts @@ -19,7 +19,6 @@ class DeidentifyFileResponse { constructor({ file, type, - outputType, extension, wordCount, charCount, @@ -33,7 +32,6 @@ class DeidentifyFileResponse { } :{ file?: string; type?: string; - outputType?: string; extension?: string; wordCount?: number; charCount?: number; @@ -50,7 +48,6 @@ class DeidentifyFileResponse { }) { this.file = file; this.type = type; - this.extension = outputType; this.extension = extension; this.wordCount = wordCount; this.charCount = charCount; diff --git a/test/vault/controller/detect.test.js b/test/vault/controller/detect.test.js index 90a8322c..ade596ee 100644 --- a/test/vault/controller/detect.test.js +++ b/test/vault/controller/detect.test.js @@ -19,6 +19,8 @@ jest.mock('../../../src/utils', () => ({ DETECT: 'DETECT', DEIDENTIFY_FILE: 'DEIDENTIFY_FILE', DETECT_RUN: 'DETECT_RUN', + DEIDENTIFY_TEXT: 'DEIDENTIFY_TEXT', + REIDENTIFY_TEXT: 'REIDENTIFY_TEXT', }, DeidenitfyFileRequestTypes: { AUDIO: 'AUDIO', From 619836a2707336996b42377a6d687610e90e6caf Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 17:36:59 +0000 Subject: [PATCH 21/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.95715b0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 414ce26e..82d3e639 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.bb22d9d", + "version": "2.0.0-beta.4-dev.95715b0", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From 7c2f2e75c3a96482a9d4c27561a64f210d4b0dbf Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 23:23:19 +0530 Subject: [PATCH 22/30] SK-2048: update deidentify text --- src/vault/controller/detect/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vault/controller/detect/index.ts b/src/vault/controller/detect/index.ts index 0c7efe82..b6fceed9 100644 --- a/src/vault/controller/detect/index.ts +++ b/src/vault/controller/detect/index.ts @@ -46,7 +46,7 @@ class DetectController { return base64String; } - private getTransformations(options?: DeidentifyFileOptions) { + private getTransformations(options?: DeidentifyFileOptions | DeidentifyTextOptions) { const transformations = options?.getTransformations() as Transformations | undefined; return { shift_dates: { @@ -417,7 +417,7 @@ class DetectController { entity_unq_counter: options?.getTokenFormat()?.getEntityUniqueCounter(), entity_only: options?.getTokenFormat()?.getEntityOnly(), } as TokenType, - transformations: options?.getTransformations() as GeneratedTransformations, + transformations: this.getTransformations(options) as GeneratedTransformations, }; } From 09c132c90751c33121f7128d77a1d448320a8e21 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 17:54:36 +0000 Subject: [PATCH 23/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.7c2f2e7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 82d3e639..91d3cbcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.95715b0", + "version": "2.0.0-beta.4-dev.7c2f2e7", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From 1936ea58b8428d666054e637773f4a2711a885bc Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 23:37:39 +0530 Subject: [PATCH 24/30] SK-2048: update imports and wait time --- README.md | 10 +++++----- samples/detect-api/deidentify-file.ts | 18 +++++++++--------- samples/detect-api/reidentify-text.ts | 4 +--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 26a461d1..0494eff8 100644 --- a/README.md +++ b/README.md @@ -2170,7 +2170,7 @@ try { options.setOutputDirectory(''); // Output directory for saving the deidentified file - options.setWaitTime(15); // Wait time for response (max 20 seconds; throws error if more) + options.setWaitTime(15); // Wait time for response (max 64 seconds; throws error if more) // ===== Image Options (apply when file is an image) ===== @@ -2267,7 +2267,7 @@ async function performDeidentifyFile() { // Output directory for saving the deidentified file options.setOutputDirectory('/home/user/output'); // Replace with your desired output directory - // Wait time for response (max 20 seconds) + // Wait time for response (max 64 seconds) options.setWaitTime(15); @@ -2308,7 +2308,7 @@ performDeidentifyFile(); - Audio: `mp3`, `wav` **Note:** -- The `waitTime` option must be ≤ 20 seconds; otherwise, an error is thrown. +- The `waitTime` option must be ≤ 64 seconds; otherwise, an error is thrown. Sample Response: @@ -2332,9 +2332,9 @@ Sample Response: runId: undefined } ``` -- If the API takes more than 20 seconds to process the file, it will return only the run ID in the response. +- If the API takes more than 64 seconds to process the file, it will return only the run ID in the response. -Sample response (when the API takes more than 20 seconds): +Sample response (when the API takes more than 64 seconds): ```typescript { diff --git a/samples/detect-api/deidentify-file.ts b/samples/detect-api/deidentify-file.ts index dfd30b03..ec79f86a 100644 --- a/samples/detect-api/deidentify-file.ts +++ b/samples/detect-api/deidentify-file.ts @@ -15,7 +15,7 @@ import { Transformations, Bleep, VaultConfig, -} from '../../src'; +} from 'skyflow-node'; import fs from 'fs'; /** @@ -73,18 +73,18 @@ async function performDeidentifyFile() { options.setTokenFormat(tokenFormat); // Custom transformations for entities - const transformations = new Transformations(); - transformations.setShiftDays({ - max: 30, - min: 10, - entities: [DetectEntities.SSN], - }); - options.setTransformations(transformations); + // const transformations = new Transformations(); + // transformations.setShiftDays({ + // max: 30, + // min: 10, + // entities: [DetectEntities.SSN], + // }); + // options.setTransformations(transformations); // Output directory for saving the deidentified file options.setOutputDirectory(''); // Replace with your output directory - // Wait time for response (max 20 seconds) + // Wait time for response (max 64 seconds) options.setWaitTime(15); // --- Image Options (apply when file is an image) --- diff --git a/samples/detect-api/reidentify-text.ts b/samples/detect-api/reidentify-text.ts index e8ec04a2..43ca576f 100644 --- a/samples/detect-api/reidentify-text.ts +++ b/samples/detect-api/reidentify-text.ts @@ -1,5 +1,3 @@ -// Sample: Using reidentifyText with ReidentifyTextOptions - import { Credentials, Env, @@ -13,7 +11,7 @@ import { } from 'skyflow-node'; /** - * Skyflow Deidentify Text Example + * Skyflow Reidentify Text Example * * This example demonstrates how to: * 1. Configure credentials From 7531edc0021611adb6d248ce056658e6ccac3f64 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 14 May 2025 00:08:06 +0530 Subject: [PATCH 25/30] SK-2048: update common workflow --- .github/workflows/common-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/common-ci.yml b/.github/workflows/common-ci.yml index 92f51d18..d240364b 100644 --- a/.github/workflows/common-ci.yml +++ b/.github/workflows/common-ci.yml @@ -15,6 +15,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: '20.x' + registry-url: "https://registry.npmjs.org" - name: Install Packages run: npm install From bfaf8cc68af2380f202ddd7ebc7e0d6a2ae49ba6 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 13 May 2025 18:38:55 +0000 Subject: [PATCH 26/30] [AUTOMATED] Private Release 2.0.0-beta.4-dev.7531edc --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 91d3cbcd..6135d923 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skyflow-node", - "version": "2.0.0-beta.4-dev.7c2f2e7", + "version": "2.0.0-beta.4-dev.7531edc", "description": "Skyflow SDK for Node.js", "main": "./lib/index.js", "module": "./lib/index.js", From 4dcca112fa8aa8c74d1a729784809325aef05e39 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 14 May 2025 00:11:13 +0530 Subject: [PATCH 27/30] SK-2048: update common release --- .github/workflows/common-ci.yml | 1 - .github/workflows/common-release.yml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/common-ci.yml b/.github/workflows/common-ci.yml index d240364b..92f51d18 100644 --- a/.github/workflows/common-ci.yml +++ b/.github/workflows/common-ci.yml @@ -15,7 +15,6 @@ jobs: - uses: actions/setup-node@v3 with: node-version: '20.x' - registry-url: "https://registry.npmjs.org" - name: Install Packages run: npm install diff --git a/.github/workflows/common-release.yml b/.github/workflows/common-release.yml index c7ec0dd1..598fc39c 100644 --- a/.github/workflows/common-release.yml +++ b/.github/workflows/common-release.yml @@ -19,6 +19,7 @@ jobs: - uses: actions/setup-node@v1 with: node-version: '20.x' + registry-url: "https://registry.npmjs.org" - name: Install Packages run: npm install From 3ac0decd0e5ad552028238f2c1176a154c9234c8 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 14 May 2025 13:42:21 +0530 Subject: [PATCH 28/30] SK-2048: update env in samples and readme --- README.md | 115 +++++++++++++++----------- samples/detect-api/deidentify-file.ts | 27 +++--- samples/detect-api/deidentify-text.ts | 6 +- samples/detect-api/get-detect-run.ts | 6 +- samples/detect-api/reidentify-text.ts | 18 +++- 5 files changed, 104 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 0494eff8..dafcc289 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ const primaryVaultConfig: VaultConfig = { const skyflowConfig: SkyflowConfig = { vaultConfigs: [primaryVaultConfig], skyflowCredentials: credentials, // Skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // Logging verbosity + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. }; // Initialize Skyflow Client @@ -466,7 +466,7 @@ const tertiaryVaultConfig: VaultConfig = { const skyflowConfig: SkyflowConfig = { vaultConfigs: [primaryVaultConfig, secondaryVaultConfig, tertiaryVaultConfig], // Add the primary, secondary and tertiary vault configurations. skyflowCredentials: skyflowCredentials, // Add JSON-formatted credentials if applicable. - logLevel: LogLevel.INFO // Set log level for debugging or monitoring purposes. + logLevel: LogLevel.INFO // Recommended to use LogLevel.ERROR in production environment. }; // Step 10: Initialize Skyflow Client @@ -1901,7 +1901,7 @@ try { if (error instanceof SkyflowError) { console.error('Skyflow Error:', error.message); } else { - console.error('Unexpected Error:', error); + console.error('Unexpected Error:', JSON.stringify(error)); } } ``` @@ -1975,7 +1975,7 @@ async function performDeidentifyText() { details: error.error?.details, }); } else { - console.error('Unexpected Error:', error); + console.error('Unexpected Error:', JSON.stringify(error)); } } } @@ -2061,11 +2061,16 @@ try { console.log('Reidentify Text Response:', response); } catch (error) { - if (error instanceof SkyflowError) { - console.error('Skyflow Error:', error.message); - } else { - console.error('Unexpected Error:', error); - } + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', JSON.stringify(error)); + } } ``` @@ -2079,7 +2084,7 @@ import { } from 'skyflow-node'; /** - * Skyflow Deidentify Text Example + * Skyflow Reidentify Text Example * * This example demonstrates how to: * 1. Configure credentials @@ -2093,16 +2098,14 @@ async function performReidentifyText() { try { // Step 1: Prepare Reidentify Text Request const reidentifyTextRequest = new ReidentifyTextRequest( - '' // The redacted text to reidentify + 'My SSN is [SSN_0ykQWPA] and my card is [CREDIT_CARD_N92QAVa].' // The redacted text to reidentify ); // Step 2: Configure ReidentifyTextOptions const options = new ReidentifyTextOptions(); // Specify which entities to reidentify as redacted, masked, or plain text - options.setRedactedEntities([DetectEntities.NAME, DetectEntities.SSN]); - options.setMaskedEntities([DetectEntities.DOB]); - options.setPlainTextEntities([DetectEntities.PHONE_NUMBER]); + options.setPlainTextEntities([DetectEntities.CREDIT_CARD, DetectEntities.SSN]); // Step 4: Call reidentifyText const response = await skyflowClient @@ -2113,7 +2116,16 @@ async function performReidentifyText() { console.log('Reidentified Text Response:', response); } catch (error) { - console.error('Error during reidentifyText:', error); + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', JSON.stringify(error)); + } } } @@ -2133,6 +2145,8 @@ Sample Response: To deidentify files, use the `deidentifyFile` method. The `DeidentifyFileRequest` class creates a deidentify file request, which includes the file to be deidentified (such as images, PDFs, audio, documents, spreadsheets, or presentations). Additionally, you can provide optional parameters using the `DeidentifyFileOptions` class to control how entities are detected and deidentified, as well as how the output is generated for different file types. +**Note:** File deidentification requires Node.js version 20 or above. + ```typescript import { DeidentifyFileRequest, @@ -2157,7 +2171,7 @@ try { options.setRestrictRegexList(['']); const tokenFormat = new TokenFormat(); // Token format for deidentified entities - tokenFormat.setDefault(TokenType.VAULT_TOKEN); + tokenFormat.setDefault(TokenType.ENTITY_ONLY); options.setTokenFormat(tokenFormat); const transformations = new Transformations(); // transformations for entities @@ -2207,10 +2221,15 @@ try { console.log('Deidentify File Response:', response); } catch (error) { + // Comprehensive Error Handling if (error instanceof SkyflowError) { - console.error('Skyflow Error:', error.message); + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); } else { - console.error('Unexpected Error:', error); + console.error('Unexpected Error:', JSON.stringify(error)); } } ``` @@ -2240,8 +2259,8 @@ async function performDeidentifyFile() { try { // Step 4: Prepare Deidentify File Request // Replace with your file object (e.g., from fs.readFileSync or browser File API) - const buffer = fs.readFileSync(''); - const file = new File([buffer], ''); + const buffer = fs.readFileSync('/detect/sample.txt'); + const file = new File([buffer], '/detect/sample.txt'); const fileReq = new DeidentifyFileRequest(file); // Step 5: Configure DeidentifyFileOptions @@ -2252,7 +2271,7 @@ async function performDeidentifyFile() { // Token format for deidentified entities const tokenFormat = new TokenFormat(); - tokenFormat.setDefault(TokenType.VAULT_TOKEN); + tokenFormat.setDefault(TokenType.ENTITY_ONLY); options.setTokenFormat(tokenFormat); // Custom transformations for entities @@ -2280,14 +2299,15 @@ async function performDeidentifyFile() { console.log('Deidentify File Response:', response); } catch (error) { + // Comprehensive Error Handling if (error instanceof SkyflowError) { - console.error('Skyflow Specific Error:', { - code: error.error?.http_code, - message: error.message, - details: error.error?.details, - }); + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); } else { - console.error('Unexpected Error:', error); + console.error('Unexpected Error:', JSON.stringify(error)); } } } @@ -2297,19 +2317,6 @@ performDeidentifyFile(); ``` - -**Supported file types:** -- Documents: `doc`, `docx`, `pdf` -- PDFs: `pdf` -- Images: `bmp`, `jpeg`, `jpg`, `png`, `tif`, `tiff` -- Structured text: `json`, `xml` -- Spreadsheets: `csv`, `xls`, `xlsx` -- Presentations: `ppt`, `pptx` -- Audio: `mp3`, `wav` - -**Note:** -- The `waitTime` option must be ≤ 64 seconds; otherwise, an error is thrown. - Sample Response: ```typescript @@ -2329,9 +2336,23 @@ Sample Response: durationInSeconds: 0, pageCount: 0, slideCount: 0, - runId: undefined + runId: undefined, + status: 'SUCCESS' } ``` + +**Supported file types:** +- Documents: `doc`, `docx`, `pdf` +- PDFs: `pdf` +- Images: `bmp`, `jpeg`, `jpg`, `png`, `tif`, `tiff` +- Structured text: `json`, `xml` +- Spreadsheets: `csv`, `xls`, `xlsx` +- Presentations: `ppt`, `pptx` +- Audio: `mp3`, `wav` + +**Note:** +- The `waitTime` option must be ≤ 64 seconds; otherwise, an error is thrown. + - If the API takes more than 64 seconds to process the file, it will return only the run ID in the response. Sample response (when the API takes more than 64 seconds): @@ -2349,6 +2370,7 @@ Sample response (when the API takes more than 64 seconds): pageCount: undefined, slideCount: undefined, runId: '1ad6dc12-8405-46cf-1c13-db1123f9f4c5' + status: 'IN_PROGRESS' } ``` @@ -2425,14 +2447,14 @@ async function performGetDetectRun() { const primaryVaultConfig: VaultConfig = { vaultId: '', // Unique vault identifier clusterId: '', // From vault URL - env: Env.DEV, // Deployment environment + env: Env.PROD, // Deployment environment credentials: credentials // Authentication method }; // Step 3: Configure Skyflow Client const skyflowConfig: SkyflowConfig = { vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, // Logging verbosity + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. }; // Initialize Skyflow Client @@ -2488,6 +2510,7 @@ Sample Response durationInSeconds: 0, pageCount: 0, slideCount: 0, + status: 'SUCCESS' } ``` @@ -2626,7 +2649,7 @@ try { // Step 2: Configure Skyflow Client const skyflowConfig: SkyflowConfig = { connectionConfigs: [connectionConfig], // Add connection configuration to client - logLevel: LogLevel.DEBUG // Set log level to DEBUG for detailed logs + logLevel: LogLevel.INFO // Recommended to use LogLevel.ERROR in production environment. }; // Step 3: Initialize Skyflow Client @@ -3159,7 +3182,7 @@ async function main() { // Creating a Skyflow client instance with the configured vault const skyflowConfig: SkyflowConfig = { vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.ERROR, // Setting log level to ERROR + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. }; const skyflowClient: Skyflow = new Skyflow(skyflowConfig); @@ -3254,7 +3277,7 @@ try { const skyflowConfig: SkyflowConfig = { vaultConfigs: [vaultConfig], // Add the Vault configuration skyflowCredentials: skyflowCredentials, // Use Skyflow credentials if no token is passed - logLevel: LogLevel.INFO // Set log level to INFO (default is ERROR) + logLevel: LogLevel.INFO // Recommended to use LogLevel.ERROR in production environment. }; // Step 10: Initialize Skyflow Client diff --git a/samples/detect-api/deidentify-file.ts b/samples/detect-api/deidentify-file.ts index ec79f86a..01748251 100644 --- a/samples/detect-api/deidentify-file.ts +++ b/samples/detect-api/deidentify-file.ts @@ -23,20 +23,22 @@ import fs from 'fs'; * * This sample demonstrates how to use all available options for deidentifying files. * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. + * + * Note: File deidentification requires Node.js version 20 or above. */ async function performDeidentifyFile() { try { // Step 1: Configure Credentials const credentials: Credentials = { - token: '', // Replace with your BEARER token + path: 'path-to-credentials-json', // Path to credentials file }; // Step 2: Configure Vault const primaryVaultConfig: VaultConfig = { vaultId: '', clusterId: '', - env: Env.DEV, + env: Env.PROD, credentials: credentials, }; @@ -69,7 +71,7 @@ async function performDeidentifyFile() { // Token format for deidentified entities const tokenFormat = new TokenFormat(); - tokenFormat.setDefault(TokenType.VAULT_TOKEN); + tokenFormat.setDefault(TokenType.ENTITY_ONLY); options.setTokenFormat(tokenFormat); // Custom transformations for entities @@ -118,15 +120,16 @@ async function performDeidentifyFile() { console.log('Deidentify File Response:', response); } catch (error) { - if (error instanceof SkyflowError) { - console.error('Skyflow Specific Error:', { - code: error.error?.http_code, - message: error.message, - details: error.error?.details, - }); - } else { - console.error('Unexpected Error:', error); - } + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', JSON.stringify(error)); + } } } diff --git a/samples/detect-api/deidentify-text.ts b/samples/detect-api/deidentify-text.ts index e65f016e..564f2932 100644 --- a/samples/detect-api/deidentify-text.ts +++ b/samples/detect-api/deidentify-text.ts @@ -29,14 +29,14 @@ async function performDeidentifyText() { try { // Step 1: Configure Credentials const credentials: Credentials = { - token: '', // Replace with your BEARER token + path: 'path-to-credentials-json', // Path to credentials file }; // Step 2: Configure Vault const primaryVaultConfig: VaultConfig = { vaultId: '', // Unique vault identifier clusterId: '', // From vault URL - env: Env.DEV, // Deployment environment + env: Env.PROD, // Deployment environment credentials: credentials // Authentication method }; @@ -97,7 +97,7 @@ async function performDeidentifyText() { details: error.error?.details, }); } else { - console.error('Unexpected Error:', error); + console.error('Unexpected Error:', JSON.stringify(error)); } } } diff --git a/samples/detect-api/get-detect-run.ts b/samples/detect-api/get-detect-run.ts index 4c0adcfe..4477048e 100644 --- a/samples/detect-api/get-detect-run.ts +++ b/samples/detect-api/get-detect-run.ts @@ -25,14 +25,14 @@ async function performGetDetectRun() { try { // Step 1: Configure Credentials const credentials: Credentials = { - token: '', // Replace with your BEARER token + path: 'path-to-credentials-json', // Path to credentials file }; // Step 2: Configure Vault const primaryVaultConfig: VaultConfig = { vaultId: '', // Unique vault identifier clusterId: '', // From vault URL - env: Env.DEV, // Deployment environment + env: Env.PROD, // Deployment environment credentials: credentials // Authentication method }; @@ -67,7 +67,7 @@ async function performGetDetectRun() { details: error.error?.details, }); } else { - console.error('Unexpected Error:', error); + console.error('Unexpected Error:', JSON.stringify(error)); } } } diff --git a/samples/detect-api/reidentify-text.ts b/samples/detect-api/reidentify-text.ts index 43ca576f..f60c737c 100644 --- a/samples/detect-api/reidentify-text.ts +++ b/samples/detect-api/reidentify-text.ts @@ -7,7 +7,8 @@ import { VaultConfig, ReidentifyTextRequest, ReidentifyTextOptions, - DetectEntities + DetectEntities, + SkyflowError } from 'skyflow-node'; /** @@ -25,14 +26,14 @@ async function performReidentifyText() { try { // Step 1: Configure Credentials const credentials: Credentials = { - token: '', // Replace with your BEARER token + path: 'path-to-credentials-json', // Path to credentials file }; // Step 2: Configure Vault const primaryVaultConfig: VaultConfig = { vaultId: '', clusterId: '', - env: Env.DEV, + env: Env.PROD, credentials: credentials }; @@ -67,7 +68,16 @@ async function performReidentifyText() { console.log('Reidentified Text Response:', response); } catch (error) { - console.error('Error during reidentifyText:', error); + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', JSON.stringify(error)); + } } } From cdb4e83c88c742aa0c3468b891984deb46e34cc0 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 14 May 2025 13:45:54 +0530 Subject: [PATCH 29/30] SK-2048: update log level in samples --- samples/detect-api/deidentify-file.ts | 2 +- samples/detect-api/deidentify-text.ts | 2 +- samples/detect-api/get-detect-run.ts | 2 +- samples/detect-api/reidentify-text.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/detect-api/deidentify-file.ts b/samples/detect-api/deidentify-file.ts index 01748251..13a66e7e 100644 --- a/samples/detect-api/deidentify-file.ts +++ b/samples/detect-api/deidentify-file.ts @@ -45,7 +45,7 @@ async function performDeidentifyFile() { // Step 3: Configure Skyflow Client const skyflowConfig: SkyflowConfig = { vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. }; // Initialize Skyflow Client diff --git a/samples/detect-api/deidentify-text.ts b/samples/detect-api/deidentify-text.ts index 564f2932..40387aea 100644 --- a/samples/detect-api/deidentify-text.ts +++ b/samples/detect-api/deidentify-text.ts @@ -43,7 +43,7 @@ async function performDeidentifyText() { // Step 3: Configure Skyflow Client const skyflowConfig: SkyflowConfig = { vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, // Logging verbosity + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. }; // Initialize Skyflow Client diff --git a/samples/detect-api/get-detect-run.ts b/samples/detect-api/get-detect-run.ts index 4477048e..c8645d3f 100644 --- a/samples/detect-api/get-detect-run.ts +++ b/samples/detect-api/get-detect-run.ts @@ -39,7 +39,7 @@ async function performGetDetectRun() { // Step 3: Configure Skyflow Client const skyflowConfig: SkyflowConfig = { vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, // Logging verbosity + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. }; // Initialize Skyflow Client diff --git a/samples/detect-api/reidentify-text.ts b/samples/detect-api/reidentify-text.ts index f60c737c..db940717 100644 --- a/samples/detect-api/reidentify-text.ts +++ b/samples/detect-api/reidentify-text.ts @@ -40,7 +40,7 @@ async function performReidentifyText() { // Step 3: Configure Skyflow Client const skyflowConfig: SkyflowConfig = { vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. }; // Initialize Skyflow Client From 03287119c1624996c2c8d004dcb8f7ccd5235ebb Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 14 May 2025 13:57:13 +0530 Subject: [PATCH 30/30] SK-2048: add comments for transformations --- README.md | 4 +++- samples/detect-api/deidentify-file.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dafcc289..bcd63f02 100644 --- a/README.md +++ b/README.md @@ -2351,6 +2351,8 @@ Sample Response: - Audio: `mp3`, `wav` **Note:** +- Transformations cannot be applied to Documents, Images, or PDFs file formats. + - The `waitTime` option must be ≤ 64 seconds; otherwise, an error is thrown. - If the API takes more than 64 seconds to process the file, it will return only the run ID in the response. @@ -2369,7 +2371,7 @@ Sample response (when the API takes more than 64 seconds): durationInSeconds: undefined, pageCount: undefined, slideCount: undefined, - runId: '1ad6dc12-8405-46cf-1c13-db1123f9f4c5' + runId: '1ad6dc12-8405-46cf-1c13-db1123f9f4c5', status: 'IN_PROGRESS' } ``` diff --git a/samples/detect-api/deidentify-file.ts b/samples/detect-api/deidentify-file.ts index 13a66e7e..2c6b8768 100644 --- a/samples/detect-api/deidentify-file.ts +++ b/samples/detect-api/deidentify-file.ts @@ -75,7 +75,7 @@ async function performDeidentifyFile() { options.setTokenFormat(tokenFormat); // Custom transformations for entities - // const transformations = new Transformations(); + // const transformations = new Transformations(); // Transformations cannot be applied to Documents, Images, or PDFs file formats. // transformations.setShiftDays({ // max: 30, // min: 10,