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",