Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SK-1621: node sdk v2 implementation #155

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
src
test
test
coverage
samples
scripts
1,052 changes: 521 additions & 531 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "skyflow-node",
"version": "1.14.0",
"description": "Skyflow SDK for Node.js",
"main": "./lib/src/index.js",
"module": "./lib/src/index.js",
"main": "./lib/index.js",
"module": "./lib/index.js",
"scripts": {
"test": "jest --coverage",
"build": "tsc",
Expand Down
8 changes: 8 additions & 0 deletions src/error/codes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const SKYFLOW_ERROR_CODE = {
CONFIG_MISSING: { http_code: 400, message: errorMessages.CONFIG_MISSING },
INVALID_TYPE_FOR_CONFIG: { http_code: 400, message: errorMessages.INVALID_TYPE_FOR_CONFIG },
EMPTY_VAULT_CONFIG: { http_code: 400, message: errorMessages.EMPTY_VAULT_CONFIG },
EMPTY_CONNECTION_CONFIG: { http_code: 400, message: errorMessages.EMPTY_CONNECTION_CONFIG },
INVALID_SKYFLOW_CONFIG: { http_code: 400, message: errorMessages.INVALID_SKYFLOW_CONFIG },

EMPTY_VAULT_ID: { http_code: 400, message: errorMessages.EMPTY_VAULT_ID },
EMPTY_VAULT_ID_VALIDATION: { http_code: 400, message: errorMessages.EMPTY_VAULT_ID_VALIDATION },
INVALID_VAULT_ID: { http_code: 400, message: errorMessages.INVALID_VAULT_ID },
EMPTY_CLUSTER_ID: { http_code: 400, message: errorMessages.EMPTY_CLUSTER_ID },
INVALID_CLUSTER_ID: { http_code: 400, message: errorMessages.INVALID_CLUSTER_ID },
Expand All @@ -30,6 +32,7 @@ const SKYFLOW_ERROR_CODE = {

EMPTY_CONNECTION_ID: { http_code: 400, message: errorMessages.EMPTY_CONNECTION_ID },
INVALID_CONNECTION_ID: { http_code: 400, message: errorMessages.INVALID_CONNECTION_ID },
EMPTY_CONNECTION_ID_VALIDATION: { http_code: 400, message: errorMessages.EMPTY_CONNECTION_ID_VALIDATION },
EMPTY_CONNECTION_URL: { http_code: 400, message: errorMessages.EMPTY_CONNECTION_URL },
INVALID_CONNECTION_URL: { http_code: 400, message: errorMessages.INVALID_CONNECTION_URL },

Expand Down Expand Up @@ -88,11 +91,13 @@ const SKYFLOW_ERROR_CODE = {
EMPTY_RECORD_IN_INSERT: { http_code: 400, message: errorMessages.EMPTY_RECORD_IN_INSERT },
EMPTY_DATA_IN_INSERT: { http_code: 400, message: errorMessages.EMPTY_DATA_IN_INSERT },
INVALID_TYPE_OF_DATA_IN_INSERT: { http_code: 400, message: errorMessages.INVALID_TYPE_OF_DATA_IN_INSERT },
INVALID_RECORD_IN_UPDATE: { http_code: 400, message: errorMessages.INVALID_RECORD_IN_UPDATE },

MISSING_VALUES_IN_TOKENIZE: { http_code: 400, message: errorMessages.MISSING_VALUES_IN_TOKENIZE },
INVALID_VALUES_TYPE_IN_TOKENIZE: { http_code: 400, message: errorMessages.INVALID_VALUES_TYPE_IN_TOKENIZE },
EMPTY_VALUES_IN_TOKENIZE: { http_code: 400, message: errorMessages.EMPTY_VALUES_IN_TOKENIZE },
EMPTY_DATA_IN_TOKENIZE: { http_code: 400, message: errorMessages.EMPTY_DATA_IN_TOKENIZE },
INVALID_DATA_IN_TOKENIZE: { http_code: 400, message: errorMessages.INVALID_DATA_IN_TOKENIZE },
INVALID_TOKENIZE_REQUEST: { http_code: 400, message: errorMessages.INVALID_TOKENIZE_REQUEST },
INVALID_VALUE_IN_TOKENIZE: { http_code: 400, message: errorMessages.INVALID_VALUE_IN_TOKENIZE },
INVALID_COLUMN_GROUP_IN_TOKENIZE: { http_code: 400, message: errorMessages.INVALID_COLUMN_GROUP_IN_TOKENIZE },
Expand Down Expand Up @@ -170,6 +175,9 @@ const SKYFLOW_ERROR_CODE = {

INVALID_ORDER_BY: { http_code: 400, message: errorMessages.INVALID_ORDER_BY },
INVALID_FIELDS: { http_code: 400, message: errorMessages.INVALID_FIELDS },

EMPTY_VAULT_CLIENTS: { http_code: 400, message: errorMessages.EMPTY_VAULT_CLIENTS },
EMPTY_CONNECTION_CLIENTS: { http_code: 400, message: errorMessages.EMPTY_CONNECTION_CLIENTS },
};

export default SKYFLOW_ERROR_CODE;
52 changes: 30 additions & 22 deletions src/error/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ const errorPrefix = `Skyflow Node SDK v${sdkDetails.version}`;

const errorMessages = {
CONFIG_MISSING: `${errorPrefix} Initialization failed. Skyflow config cannot be empty. Specify a valid skyflow config.`,
INVALID_SKYFLOW_CONFIG: `${errorPrefix} Initialization failed. Invalid skyflow config. Specify a valid skyflow config.`,
INVALID_SKYFLOW_CONFIG: `${errorPrefix} Initialization failed. Invalid skyflow config. Vaults configs key missing in skyflow config.`,
INVALID_TYPE_FOR_CONFIG: `${errorPrefix} Initialization failed. Invalid %s1 config. Specify a valid %s1 config.`,
EMPTY_VAULT_CONFIG: `${errorPrefix} Initialization failed. Vault config cannot be empty. Specify a valid vault config.`,
EMPTY_CONNECTION_CONFIG: `${errorPrefix} Initialization failed. Connection config cannot be empty. Specify a valid connection config.`,

EMPTY_VAULT_ID: `${errorPrefix} Initialization failed. Invalid vault ID. Specify a valid vault Id.`,
EMPTY_VAULT_ID_VALIDATION: `${errorPrefix} Validation error. Invalid vault ID. Specify a valid vault Id.`,
INVALID_VAULT_ID: `${errorPrefix} Initialization failed. Invalid vault ID. Specify a valid vault Id as a string.`,
EMPTY_CLUSTER_ID: `${errorPrefix} Initialization failed. Invalid cluster ID. Specify a valid cluster Id for vault with vaultId %s1 .`,
INVALID_CLUSTER_ID: `${errorPrefix} Initialization failed. Invalid cluster ID. Specify cluster Id as a string for vault with vaultId %s1.`,
Expand All @@ -29,10 +31,11 @@ const errorMessages = {
INVALID_PARSED_CREDENTIALS_STRING_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Specify a valid credentials string for %s1 with %s2 %s3.`,
INVALID_BEARER_TOKEN_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Specify a valid token for %s1 with %s2 %s3.`,

EMPTY_CONNECTION_ID_VALIDATION: `${errorPrefix} Validation error. Invalid connection ID. Specify a valid connection Id.`,
EMPTY_CONNECTION_ID: `${errorPrefix} Initialization failed. Invalid connection ID. Specify a valid connection Id.`,
INVALID_CONNECTION_ID: `${errorPrefix} Initialization failed. Invalid connection ID. Specify connection Id as a string.`,
EMPTY_CONNECTION_URL: `${errorPrefix} Initialization failed. Invalid connection URL. Specify a valid connection Url.`,
INVALID_CONNECTION_URL: `${errorPrefix} Initialization failed. Invalid connection URL. Specify connection Url as a string.`,
INVALID_CONNECTION_URL: `${errorPrefix} Initialization failed. Invalid connection URL. Specify connection Url as a valid url.`,

VAULT_ID_NOT_IN_CONFIG_LIST: `${errorPrefix} Validation error. %s1 is missing from the config. Specify the vaultId's from config.`,
CONNECTION_ID_NOT_IN_CONFIG_LIST: `${errorPrefix} Validation error. %s1 is missing from the config. Specify the connectionIds from config.`,
Expand Down Expand Up @@ -74,21 +77,23 @@ const errorMessages = {
INVALID_REDACTION_TYPE_IN_DETOKENIZE: `${errorPrefix} Validation error. Invalid redaction type in detokenize request. Specify a redaction type.`,
INVALID_TOKENS_TYPE_IN_DETOKENIZE: `${errorPrefix} Validation error. Invalid tokens type in detokenize request. Specify tokens as a string array.`,
EMPTY_TOKENS_IN_DETOKENIZE: `${errorPrefix} Validation error. Tokens array cannot be empty. Specify token's in detokenize request.`,
EMPTY_TOKEN_IN_DETOKENIZE: `${errorPrefix} Validation error. Token cannot be empty in detokenize request. Specify a valid token.`,
EMPTY_TOKEN_IN_DETOKENIZE: `${errorPrefix} Validation error. Token cannot be empty in detokenize request. Specify a valid token at index %s1.`,
INVALID_TOKEN_IN_DETOKENIZE: `${errorPrefix} Validation error. Invalid type of token passed in detokenize request. token must be of type string at index %s1.`,
INVALID_DETOKENIZE_REQUEST: `${errorPrefix} Validation error. Invalid detokenize request. Specify a valid detokenize request.`,

MISSING_VALUES_IN_TOKENIZE: `${errorPrefix} Validation error. Values cannot be empty in tokenize request. Specify valid values.`,
INVALID_VALUES_TYPE_IN_TOKENIZE: `${errorPrefix} Validation error. Invalid values type in tokenize request. Specify valid values of type array.`,
EMPTY_VALUES_IN_TOKENIZE: `${errorPrefix} Validation error. Values array cannot be empty. Specify value's in tokenize request.`,
EMPTY_DATA_IN_TOKENIZE: `${errorPrefix} Validation error. Data cannot be empty in tokenize request. Specify a valid data at index %s1.`,
INVALID_DATA_IN_TOKENIZE: `${errorPrefix} Validation error. Invalid Data. Specify a valid data at index %s1.`,
INVALID_COLUMN_GROUP_IN_TOKENIZE: `${errorPrefix} Validation error. Invalid type of column group passed in tokenize request. Column group must be of type string at index %s1.`,
INVALID_VALUE_IN_TOKENIZE: `${errorPrefix} Validation error. Invalid type of value passed in tokenize request. Value must be of type string at index %s1.`,
INVALID_TOKENIZE_REQUEST: `${errorPrefix} Validation error. Invalid tokenize request. Specify a valid tokenize request.`,
EMPTY_COLUMN_GROUP_IN_TOKENIZE: `${errorPrefix} Validation error. Column group cannot be empty in tokenize request. Specify a valid column group.`,
EMPTY_VALUE_IN_TOKENIZE: `${errorPrefix} Validation error. Value cannot be empty in tokenize request. Specify a valid value.`,
EMPTY_COLUMN_GROUP_IN_TOKENIZE: `${errorPrefix} Validation error. Column group cannot be empty in tokenize request. Specify a valid column group at index %s1.`,
EMPTY_VALUE_IN_TOKENIZE: `${errorPrefix} Validation error. Value cannot be empty in tokenize request. Specify a valid value at index %s1.`,

INVALID_RECORD_IN_INSERT: `${errorPrefix} Validation error. Invalid data in insert request. data must be of type object at index %s1.`,
INVALID_RECORD_IN_UPDATE: `${errorPrefix} Validation error. Invalid data in update request. data must be of type object.`,
EMPTY_RECORD_IN_INSERT: `${errorPrefix} Validation error. Data cannot be empty in insert request. Specify valid data at index %s1.`,
INVALID_INSERT_REQUEST: `${errorPrefix} Validation error. Invalid insert request. Specify a valid insert request.`,
INVALID_TYPE_OF_DATA_IN_INSERT: `${errorPrefix} Validation error. Invalid type of data in insert request. Specify data as a object array.`,
Expand All @@ -99,30 +104,30 @@ const errorMessages = {
INVALID_QUERY: `${errorPrefix} Validation error. Invalid query in query request. Specify a valid query.`,

INVALID_FILE_UPLOAD_REQUEST: `${errorPrefix} Validation error. Invalid file upload request. Specify a valid file upload request.`,
MISSING_TABLE_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid table name. Specify table name as a string.`,
INVALID_TABLE_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid table name. Specify a valid table name.`,
MISSING_SKYFLOW_ID_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid skyflow Id. Specify a valid skyflow Id as string.`,
INVALID_SKYFLOW_ID_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid skyflow Id. Specify a valid skyflow Id.`,
MISSING_COLUMN_NAME_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid column name. Specify a valid column name as string.`,
INVALID_COLUMN_NAME_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid column name. Specify a valid column name.`,
MISSING_FILE_PATH_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid file path. Specify a valid file path as string.`,
INVALID_FILE_PATH_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid file path. Specify a valid file path.`,

MISSING_SKYFLOW_ID_IN_UPDATE: `${errorPrefix} Validation error. Skyflow Id name cannot be empty. Specify a skyflow Id name as string.`,
INVALID_SKYFLOW_ID_IN_UPDATE: `${errorPrefix} Validation error. Invalid skyflow Id. Specify a valid skyflow Id.`,
INVALID_TYPE_OF_UPDATE_DATA: `${errorPrefix} Validation error. Invalid update data. Specify a valid update data as array of object.`,
EMPTY_UPDATE_DATA: `${errorPrefix} Validation error. Update data cannot be empty. Specify a valid update data.`,
MISSING_TABLE_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Table name cannot be empty in file upload request. Specify table name as a string.`,
INVALID_TABLE_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid table name in file upload request. Specify a valid table name.`,
MISSING_SKYFLOW_ID_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Skyflow id cannot be empty in file upload request. Specify a valid skyflow Id as string.`,
INVALID_SKYFLOW_ID_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid skyflow Id in file upload request. Specify a valid skyflow Id.`,
MISSING_COLUMN_NAME_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Column name cannot be empty in file upload request. Specify a valid column name as string.`,
INVALID_COLUMN_NAME_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid column name in file upload request. Specify a valid column name.`,
MISSING_FILE_PATH_IN_UPLOAD_FILE: `${errorPrefix} Validation error. File path cannot be empty in file upload request. Specify a valid file path as string.`,
INVALID_FILE_PATH_IN_UPLOAD_FILE: `${errorPrefix} Validation error. Invalid file path in file upload request. Specify a valid file path.`,

MISSING_SKYFLOW_ID_IN_UPDATE: `${errorPrefix} Validation error. Skyflow id name cannot be empty in update request. Specify a skyflow Id name as string.`,
INVALID_SKYFLOW_ID_IN_UPDATE: `${errorPrefix} Validation error. Invalid skyflow Id in update request. Specify a valid skyflow Id.`,
INVALID_TYPE_OF_UPDATE_DATA: `${errorPrefix} Validation error. Invalid update data in update request. Specify a valid update data as array of object.`,
EMPTY_UPDATE_DATA: `${errorPrefix} Validation error. Update data cannot be empty in update request. Specify a valid update data.`,
INVALID_UPDATE_REQUEST: `${errorPrefix} Validation error. Invalid update request. Specify a valid update request.`,
INVALID_DATA_IN_UPDATE: `${errorPrefix} Validation error. Invalid data. data must be of type object at index %s1.`,
EMPTY_DATA_IN_UPDATE: `${errorPrefix} Validation error. Data cannot be empty. Specify a valid data at index %s1.`,
INVALID_DATA_IN_UPDATE: `${errorPrefix} Validation error. Invalid data in update request. data must be of type object at index %s1.`,
EMPTY_DATA_IN_UPDATE: `${errorPrefix} Validation error. Data cannot be empty in update request. Specify a valid data at index %s1.`,

EMPTY_TABLE_NAME: `${errorPrefix} Validation error. Table name cannot be empty. Specify a valid table name.`,
INVALID_TABLE_NAME: `${errorPrefix} Validation error. Invalid table name. Specify a valid table name as string.`,
EMPTY_REDACTION_TYPE: `${errorPrefix} Validation error. Redaction type cannot be empty. Specify a valid redaction type.`,
INVALID_REDACTION_TYPE: `${errorPrefix} Validation error. Invalid redaction type. Specify a valid redaction type.`,

INVALID_TYPE_OF_IDS: `${errorPrefix} Validation error. Invalid ids passed. Specify valid ids as array of string.`,
EMPTY_IDS_IN_GET: `${errorPrefix} Validation error. Ids cannot be empty. Specify valid ids.`,
INVALID_TYPE_OF_IDS: `${errorPrefix} Validation error. Invalid ids passed in get request. Specify valid ids as array of string.`,
EMPTY_IDS_IN_GET: `${errorPrefix} Validation error. Ids cannot be empty in get request. Specify valid ids.`,
EMPTY_ID_IN_GET: `${errorPrefix} Validation error. Id cannot be empty. Specify a valid Id at index %s1.`,
INVALID_ID_IN_GET: `${errorPrefix} Validation error. Invalid Id. Specify a valid Id at index %s1 as string.`,
INVALID_GET_REQUEST: `${errorPrefix} Validation error. Invalid get request. Specify a valid get request.`,
Expand Down Expand Up @@ -174,6 +179,9 @@ const errorMessages = {
INVALID_FIELDS: `${errorPrefix} Validation error. The fields key has a value of type %s1. Specify fields as array of strings.`,

INVAILD_JSON_RESPONSE: `${errorPrefix} Validation error. The invalid json response. Please reach out to skyflow using requestId - %s1.`,

EMPTY_VAULT_CLIENTS: `${errorPrefix} Validation error. No vault config found. Please add a vault config`,
EMPTY_CONNECTION_CLIENTS: `${errorPrefix} Validation error. No connection config found. Please add a connection config`
};

export default errorMessages;
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import QueryRequest from './vault/model/request/query';
import Credentials from './vault/config/credentials';
import TokenizeRequest from './vault/model/request/tokenize';
import TokenizeResponse from './vault/model/response/tokenize';
import { generateBearerToken, generateBearerTokenFromCreds } from './service-account';
import { generateBearerToken, generateBearerTokenFromCreds, generateSignedDataTokens, generateSignedDataTokensFromCreds } from './service-account';
import { isExpired } from './utils/jwt-utils';
import UpdateOptions from './vault/model/options/update';
import InvokeConnectionRequest from './vault/model/request/inkove';
Expand All @@ -24,6 +24,8 @@ export {
Skyflow,
generateBearerToken,
generateBearerTokenFromCreds,
generateSignedDataTokens,
generateSignedDataTokensFromCreds,
isExpired,
Credentials,
RedactionType,
Expand Down
9 changes: 6 additions & 3 deletions src/service-account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,29 @@ function failureResponse(err: any) {
if (contentType && contentType.includes('application/json')) {
let description = data;
if (description?.error?.message) {
description = requestId ? `${description?.error?.message} - requestId: ${requestId}` : description?.error?.message;
description =description?.error?.message;
}
printLog(description, MessageType.ERROR);
reject(new SkyflowError({
http_code: err.response.status,
message: description,
request_ID: requestId,
}));
} else if (contentType && contentType.includes('text/plain')) {
let description = requestId ? `${data} - requestId: ${requestId}` : data
let description = data
printLog(description, MessageType.ERROR);
reject(new SkyflowError({
http_code: err.response.status,
message: description,
request_ID: requestId
}));
} else {
let description = requestId ? `${logs.errorLogs.ERROR_OCCURED} - requestId: ${requestId}` : logs.errorLogs.ERROR_OCCURED
let description = logs.errorLogs.ERROR_OCCURED;
printLog(description, MessageType.ERROR);
reject(new SkyflowError({
http_code: err.response.status,
message: description,
request_ID: requestId
}));
}
} else {
Expand Down
Loading
Loading