Skip to content

Commit

Permalink
Merge pull request #159 from skyflowapi/SK-1621-node-sdk-v2
Browse files Browse the repository at this point in the history
SK-1621: node sdk v2
  • Loading branch information
amith-skyflow authored Oct 24, 2024
2 parents 52d3d26 + fb1f839 commit f55c2de
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"skyflow-node": "1.14.0-dev.c0f4b46"
"skyflow-node": "1.14.0"
}
}
4 changes: 2 additions & 2 deletions samples/vault-api/Insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion samples/vault-api/Update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=>{
Expand Down
1 change: 1 addition & 0 deletions samples/vault-api/file-upload.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions samples/vault-api/invoke.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -49,7 +49,7 @@ const headers = {
};

const invokeReq = new InvokeConnectionRequest(
METHOD.POST,
Method.POST,
body,
headers
);
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -30,7 +30,7 @@ import InvokeConnectionResponse from './vault/model/response/invoke/invoke';
export {
Env,
LogLevel,
METHOD,
Method,
Skyflow,
generateBearerToken,
generateBearerTokenFromCreds,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export enum MessageType {
ERROR = 'ERROR',
}

export enum METHOD {
export enum Method {
POST = 'POST',
GET = 'GET',
PUT = 'PUT',
Expand Down
9 changes: 3 additions & 6 deletions src/utils/validations/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/vault/controller/connections/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/vault/model/request/inkove/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 6 additions & 6 deletions test/vault/controller/connection.test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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" },
};

Expand All @@ -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,
Expand All @@ -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" },
};

Expand All @@ -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" },
};

Expand Down Expand Up @@ -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" },
};

Expand Down

0 comments on commit f55c2de

Please sign in to comment.