diff --git a/samples/package.json b/samples/package.json index 3dd8ce0..794ce7e 100644 --- a/samples/package.json +++ b/samples/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "dependencies": { - "skyflow-node": "1.14.0-dev.c0f4b46" + "skyflow-node": "1.14.0" } } diff --git a/samples/vault-api/Insert.ts b/samples/vault-api/Insert.ts index ebaf497..4ae72c7 100644 --- a/samples/vault-api/Insert.ts +++ b/samples/vault-api/Insert.ts @@ -34,8 +34,8 @@ const skyflow_client = new Skyflow({ //sample data const insertData = [ - { cardumber: '4111111111111111', cvv: '1234' }, - { cardumber: '42424242424242424', cvv: '321' }, + { card_number: '4111111111111111', cvv: '1234' }, + { card_number: '42424242424242424', cvv: '321' }, ] const insertReq = new InsertRequest( diff --git a/samples/vault-api/Update.ts b/samples/vault-api/Update.ts index 1c6a7b2..c466b29 100644 --- a/samples/vault-api/Update.ts +++ b/samples/vault-api/Update.ts @@ -47,7 +47,7 @@ const updateOptions = new UpdateOptions() updateOptions.setReturnTokens(true); -skyflow_client.vault("e796617671d742c6aeb69f5cc62acf26").update( +skyflow_client.vault("VAULT_ID").update( updateReq, updateOptions ).then(resp=>{ diff --git a/samples/vault-api/file-upload.ts b/samples/vault-api/file-upload.ts index 79c0938..4e976a5 100644 --- a/samples/vault-api/file-upload.ts +++ b/samples/vault-api/file-upload.ts @@ -1,3 +1,4 @@ +//please use node version 18 & above to run file upload import { Env, FileUploadRequest, LogLevel, Skyflow } from "skyflow-node"; // To generate Bearer Token from credentials string. diff --git a/samples/vault-api/invoke.ts b/samples/vault-api/invoke.ts index 644280d..045dc0d 100644 --- a/samples/vault-api/invoke.ts +++ b/samples/vault-api/invoke.ts @@ -1,4 +1,4 @@ -import { Env, Skyflow, InvokeConnectionRequest, METHOD, LogLevel } from "skyflow-node"; +import { Env, Skyflow, InvokeConnectionRequest, Method, LogLevel } from "skyflow-node"; // To generate Bearer Token from credentials string. const cred = { @@ -49,7 +49,7 @@ const headers = { }; const invokeReq = new InvokeConnectionRequest( - METHOD.POST, + Method.POST, body, headers ); diff --git a/src/index.ts b/src/index.ts index 3149be8..1d12fb3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import Skyflow from './vault/skyflow'; -import { LogLevel, Env, RedactionType, METHOD, OrderByEnum, BYOT } from './utils'; +import { LogLevel, Env, RedactionType, Method, OrderByEnum, BYOT } from './utils'; import InsertRequest from './vault/model/request/insert'; import InsertOptions from './vault/model/options/insert'; import GetRequest from './vault/model/request/get'; @@ -30,7 +30,7 @@ import InvokeConnectionResponse from './vault/model/response/invoke/invoke'; export { Env, LogLevel, - METHOD, + Method, Skyflow, generateBearerToken, generateBearerTokenFromCreds, diff --git a/src/utils/index.ts b/src/utils/index.ts index 9d4dd15..5df8cd8 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -54,7 +54,7 @@ export enum MessageType { ERROR = 'ERROR', } -export enum METHOD { +export enum Method { POST = 'POST', GET = 'GET', PUT = 'PUT', diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index 53a1084..c49bb45 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -1,4 +1,4 @@ -import { CONNECTION, CONNECTION_ID, Env, isValidURL, LogLevel, METHOD, OrderByEnum, RedactionType, VAULT, VAULT_ID } from ".."; +import { CONNECTION, CONNECTION_ID, Env, isValidURL, LogLevel, Method, OrderByEnum, RedactionType, VAULT, VAULT_ID } from ".."; import { V1BYOT } from "../../ _generated_/rest"; import SkyflowError from "../../error"; import SKYFLOW_ERROR_CODE from "../../error/codes"; @@ -40,7 +40,7 @@ export function isOrderBy(value?: string): boolean { } export function isMethod(value?: string): boolean { - return value !== undefined && Object.values(METHOD).includes(value as METHOD); + return value !== undefined && Object.values(Method).includes(value as Method); } export function isLogLevel(value?: string): boolean { @@ -631,10 +631,7 @@ export const validateDetokenizeRequest = (detokenizeRequest: DetokenizeRequest, } }); - if (!detokenizeRequest?.redactionType || !Object.prototype.hasOwnProperty.call(detokenizeRequest, '_redactionType')) - throw new SkyflowError(SKYFLOW_ERROR_CODE.EMPTY_REDACTION_TYPE); - - if (typeof detokenizeRequest.redactionType !== 'string' || detokenizeRequest.redactionType.trim().length === 0) { + if (detokenizeRequest?.redactionType && typeof detokenizeRequest.redactionType !== 'string' && !isRedactionType(detokenizeRequest.redactionType)) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_REDACTION_TYPE); } diff --git a/src/vault/controller/connections/index.ts b/src/vault/controller/connections/index.ts index f1b0e3f..9ad0872 100644 --- a/src/vault/controller/connections/index.ts +++ b/src/vault/controller/connections/index.ts @@ -1,6 +1,6 @@ //imports import axios from "axios"; -import { fillUrlWithPathAndQueryParams, generateSDKMetrics, getBearerToken, LogLevel, MessageType, METHOD, parameterizedString, printLog, SDK_METRICS_HEADER_KEY, SKYFLOW_AUTH_HEADER_KEY, REQUEST_ID_KEY, TYPES } from "../../../utils"; +import { fillUrlWithPathAndQueryParams, generateSDKMetrics, getBearerToken, LogLevel, MessageType, Method, parameterizedString, printLog, SDK_METRICS_HEADER_KEY, SKYFLOW_AUTH_HEADER_KEY, REQUEST_ID_KEY, TYPES } from "../../../utils"; import InvokeConnectionRequest from "../../model/request/inkove"; import logs from "../../../utils/logs"; import { validateInvokeConnectionRequest } from "../../../utils/validations"; @@ -32,7 +32,7 @@ class ConnectionController { sdkHeaders[SDK_METRICS_HEADER_KEY] = JSON.stringify(generateSDKMetrics()); axios({ url: filledUrl, - method: invokeRequest.method || METHOD.POST, + method: invokeRequest.method || Method.POST, data: invokeRequest.body, headers: { ...invokeRequest.headers, ...sdkHeaders } }).then((response: any) => { diff --git a/src/vault/model/request/inkove/index.ts b/src/vault/model/request/inkove/index.ts index c1f6905..e631be7 100644 --- a/src/vault/model/request/inkove/index.ts +++ b/src/vault/model/request/inkove/index.ts @@ -1,16 +1,16 @@ //imports -import { METHOD } from "../../../../utils"; +import { Method } from "../../../../utils"; import { StringKeyValueMapType } from "../../../types"; class InvokeConnectionRequest { //fields - method?: METHOD; + method: Method; queryParams?: StringKeyValueMapType; pathParams?: StringKeyValueMapType; body?: StringKeyValueMapType; headers?: StringKeyValueMapType; - constructor(method?: METHOD, body?: StringKeyValueMapType, headers?: StringKeyValueMapType, pathParams?: StringKeyValueMapType, queryParams?: StringKeyValueMapType) { + constructor(method: Method, body?: StringKeyValueMapType, headers?: StringKeyValueMapType, pathParams?: StringKeyValueMapType, queryParams?: StringKeyValueMapType) { this.method = method; this.pathParams = pathParams; this.queryParams = queryParams; diff --git a/test/vault/controller/connection.test.js b/test/vault/controller/connection.test.js index 74d15ad..5f04791 100644 --- a/test/vault/controller/connection.test.js +++ b/test/vault/controller/connection.test.js @@ -1,5 +1,5 @@ import axios from "axios"; -import { fillUrlWithPathAndQueryParams, generateSDKMetrics, getBearerToken, LogLevel, MessageType, METHOD, parameterizedString, printLog, SDK_METRICS_HEADER_KEY, TYPES } from "../../../src/utils"; +import { fillUrlWithPathAndQueryParams, generateSDKMetrics, getBearerToken, LogLevel, MessageType, Method, parameterizedString, printLog, SDK_METRICS_HEADER_KEY, TYPES } from "../../../src/utils"; import logs from "../../../src/utils/logs"; import { validateInvokeConnectionRequest } from "../../../src/utils/validations"; import VaultClient from "../../../src/vault/client"; @@ -24,7 +24,7 @@ describe("ConnectionController", () => { pathParams: { id: "123" }, queryParams: { search: "test" }, body: { data: "sample" }, - method: METHOD.POST, + method: Method.POST, headers: { "Custom-Header": "value" }, }; @@ -46,7 +46,7 @@ describe("ConnectionController", () => { expect(getBearerToken).toHaveBeenCalledWith(mockClient.getCredentials(), LogLevel.ERROR); expect(axios).toHaveBeenCalledWith({ url: "https://api.example.com/resource", - method: METHOD.POST, + method: Method.POST, data: invokeRequest.body, headers: { ...invokeRequest.headers, @@ -62,7 +62,7 @@ describe("ConnectionController", () => { pathParams: { id: "123" }, queryParams: { search: "test" }, body: { data: "sample" }, - method: METHOD.POST, + method: Method.POST, headers: { "Custom-Header": "value" }, }; @@ -79,7 +79,7 @@ describe("ConnectionController", () => { pathParams: { id: "123" }, queryParams: { search: "test" }, body: { data: "sample" }, - // method: METHOD.POST, + // method: Method.POST, headers: { "Custom-Header": "value" }, }; @@ -114,7 +114,7 @@ describe("ConnectionController", () => { pathParams: { id: "123" }, queryParams: { search: "test" }, body: { data: "sample" }, - method: METHOD.POST, + method: Method.POST, headers: { "Custom-Header": "value" }, };