Skip to content

Commit 8a466d8

Browse files
SK-2645: Fix inconsistencies identified in extracted public interfaces doc. (#288)
* SK-2645: fix inconsistencies
1 parent b08a439 commit 8a466d8

8 files changed

Lines changed: 194 additions & 46 deletions

File tree

src/utils/validations/index.ts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -413,49 +413,43 @@ export const validateUpdateConnectionConfig = (connectionConfig: ConnectionConfi
413413
};
414414

415415
function validateInsertInput(input: unknown, index: number): void {
416-
try {
417-
const inputObject = input as { [key: string]: unknown };
418-
419-
// Check if the object is empty
420-
const entries = Object.entries(inputObject);
421-
422-
if (entries.length === 0) {
423-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_INSERT, [index]);
424-
}
416+
if (typeof input !== 'object' || input === null || Array.isArray(input)) {
417+
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_INSERT, [index]);
418+
}
425419

426-
for (const [key] of entries) {
427-
if (key && typeof key !== 'string') {
428-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_INSERT, [index]);
429-
}
430-
}
420+
const inputObject = input as { [key: string]: unknown };
421+
const entries = Object.entries(inputObject);
431422

432-
} catch (error) {
423+
if (entries.length === 0) {
433424
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_INSERT, [index]);
434425
}
435426

427+
for (const [key] of entries) {
428+
if (!key || typeof key !== 'string') {
429+
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_INSERT, [index]);
430+
}
431+
}
436432
}
437433

438434
function validateUpdateInput(input: unknown): void {
439-
try {
440-
const inputObject = input as { [key: string]: unknown };
435+
if (typeof input !== 'object' || input === null || Array.isArray(input)) {
436+
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
437+
}
441438

442-
// Check if the object is empty
443-
const entries = Object.entries(inputObject);
439+
const inputObject = input as { [key: string]: unknown };
444440

445-
if (entries.length === 0) {
446-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
447-
}
441+
// Exclude skyflow_id — it is the record identifier, not a data field to update
442+
const entries = Object.entries(inputObject).filter(([key]) => key !== SKYFLOW.ID);
448443

449-
for (const [key] of entries) {
450-
if (key && typeof key !== 'string') {
451-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
452-
}
453-
}
454-
455-
} catch (error) {
444+
if (entries.length === 0) {
456445
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
457446
}
458447

448+
for (const [key] of entries) {
449+
if (!key || typeof key !== 'string') {
450+
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
451+
}
452+
}
459453
}
460454

461455
function validateUpdateToken(input: unknown): void {

src/vault/controller/vault/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ class VaultController {
115115
if (body && Array.isArray(body.records)) {
116116
body.records.forEach((field: StringKeyValueMapType) => {
117117
response.success.push({
118-
skyflowId: String(field?.skyflow_id),
119-
requestIndex: index,
118+
skyflow_id: String(field?.skyflow_id),
119+
request_index: index,
120120
...(typeof field?.tokens === 'object' && field?.tokens !== null ? field.tokens : {})
121121
});
122122
});
@@ -213,7 +213,7 @@ class VaultController {
213213

214214
private parseBulkInsertResponse(records: Record<string, unknown>[]): InsertResponse {
215215
const insertedFields: InsertResponseType[] = records.map(record => ({
216-
skyflowId: String(record.skyflow_id),
216+
skyflow_id: String(record.skyflow_id),
217217
...(typeof record.tokens === 'object' && record.tokens !== null ? record.tokens : {})
218218
}));
219219
return new InsertResponse({ insertedFields, errors: null });
@@ -290,7 +290,7 @@ class VaultController {
290290
).then(data => {
291291
printLog(logs.infoLogs.UPDATE_SUCCESS, MessageType.LOG, this.client.getLogLevel());
292292
const updatedRecord = {
293-
skyflowId: data.skyflow_id,
293+
skyflow_id: data.skyflow_id,
294294
...data?.tokens
295295
};
296296
resolve(new UpdateResponse({ updatedField: updatedRecord, errors: null }));
@@ -490,7 +490,7 @@ class VaultController {
490490
printLog(logs.infoLogs.QUERY_SUCCESS, MessageType.LOG, this.client.getLogLevel());
491491
const processedRecords = response.records.map(record => ({
492492
...(typeof record.fields === 'object' && record.fields !== null ? record.fields : {}),
493-
tokenizedData: {
493+
tokenized_data: {
494494
...(typeof record.tokens === 'object' && record.tokens !== null ? record.tokens : {}),
495495
},
496496
}));

src/vault/model/response/invoke/invoke.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//imports
22

33
import { SkyflowRecordError } from "../../../../utils";
4-
import { QueryResponseType } from "../../../types";
54

65
class InvokeConnectionResponse {
76
//fields

src/vault/skyflow/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ class Skyflow {
186186
this.updateClients(CONFIG.LOGLEVEL);
187187
}
188188

189+
updateLogLevel(logLevel: LogLevel): Skyflow {
190+
if (logLevel && !isLogLevel(logLevel)) {
191+
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_LOG_LEVEL);
192+
}
193+
this.logLevel = logLevel;
194+
this.updateClients(CONFIG.LOGLEVEL);
195+
return this;
196+
}
197+
189198
getLogLevel() {
190199
return this.logLevel;
191200
}

src/vault/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface ClientObj {
4040
}
4141

4242
export interface InsertResponseType {
43-
skyflowId: string;
43+
skyflow_id: string;
4444
[key: string]: unknown;
4545
}
4646

test/utils/validations.test.js

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,6 @@ describe('validateInsertRequest', () => {
11641164
});
11651165

11661166
// Test valid cases
1167-
// Test valid cases
11681167
test('should accept valid insert request', () => {
11691168
const request = {
11701169
_table: 'users', // Changed from table to _table
@@ -1177,6 +1176,52 @@ test('should accept valid insert request', () => {
11771176
expect(() => validateInsertRequest(request)).not.toThrow();
11781177
});
11791178

1179+
test('should accept insert request with null field values', () => {
1180+
const request = {
1181+
_table: 'sensitive_data_table',
1182+
table: 'sensitive_data_table',
1183+
data: [
1184+
{ card_number: null }
1185+
]
1186+
};
1187+
expect(() => validateInsertRequest(request)).not.toThrow();
1188+
});
1189+
1190+
test('should accept insert request with empty string field values', () => {
1191+
const request = {
1192+
_table: 'sensitive_data_table',
1193+
table: 'sensitive_data_table',
1194+
data: [
1195+
{ card_number: '' }
1196+
]
1197+
};
1198+
expect(() => validateInsertRequest(request)).not.toThrow();
1199+
});
1200+
1201+
test('should accept insert request with mixed null, empty string and valid field values', () => {
1202+
const request = {
1203+
_table: 'sensitive_data_table',
1204+
table: 'sensitive_data_table',
1205+
data: [
1206+
{ card_number: '4111111111111112', cvv: null, expiry: '' }
1207+
]
1208+
};
1209+
expect(() => validateInsertRequest(request)).not.toThrow();
1210+
});
1211+
1212+
test('should accept insert request with multiple records containing null and empty values', () => {
1213+
const request = {
1214+
_table: 'sensitive_data_table',
1215+
table: 'sensitive_data_table',
1216+
data: [
1217+
{ card_number: '4111111111111112' },
1218+
{ card_number: null },
1219+
{ card_number: '' }
1220+
]
1221+
};
1222+
expect(() => validateInsertRequest(request)).not.toThrow();
1223+
});
1224+
11801225
// Also update other test cases that check table property
11811226
test('should throw error when table is missing', () => {
11821227
const request = {
@@ -1421,17 +1466,56 @@ describe('validateUpdateRequest - validateUpdateInput', () => {
14211466
.toThrow(SKYFLOW_ERROR_CODE.INVALID_TYPE_OF_UPDATE_DATA);
14221467
});
14231468

1424-
// Test validateUpdateInput with null values
1425-
test('should throw error when data contains null values', () => {
1469+
// Test validateUpdateInput with null values — should be accepted
1470+
test('should accept update data with null field values', () => {
14261471
const request = {
14271472
...validTable,
14281473
data: {
1429-
skyflow_id: 'valid-id',
1474+
skyflowId: 'valid-id',
14301475
field: null
14311476
}
14321477
};
1433-
expect(() => validateUpdateRequest(request))
1434-
.toThrow(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
1478+
expect(() => validateUpdateRequest(request)).not.toThrow();
1479+
});
1480+
1481+
// Test validateUpdateInput with empty string field values — should be accepted
1482+
test('should accept update data with empty string field values', () => {
1483+
const request = {
1484+
...validTable,
1485+
data: {
1486+
skyflowId: 'valid-id',
1487+
field: ''
1488+
}
1489+
};
1490+
expect(() => validateUpdateRequest(request)).not.toThrow();
1491+
});
1492+
1493+
// Test validateUpdateInput with mixed null, empty string and valid values
1494+
test('should accept update data with mixed null, empty string and valid field values', () => {
1495+
const request = {
1496+
...validTable,
1497+
data: {
1498+
skyflowId: 'valid-id',
1499+
card_number: null,
1500+
name: '',
1501+
ssn: '123-45-6789'
1502+
}
1503+
};
1504+
expect(() => validateUpdateRequest(request)).not.toThrow();
1505+
});
1506+
1507+
// Test validateUpdateInput with numeric and boolean field values
1508+
test('should accept update data with numeric and boolean field values', () => {
1509+
const request = {
1510+
...validTable,
1511+
data: {
1512+
skyflowId: 'valid-id',
1513+
age: 0,
1514+
active: false,
1515+
score: 99.5
1516+
}
1517+
};
1518+
expect(() => validateUpdateRequest(request)).not.toThrow();
14351519
});
14361520

14371521
// Test valid update data with multiple fields

test/vault/controller/vault.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ describe('VaultController query method', () => {
10071007
expect(response).toBeInstanceOf(QueryResponse);
10081008
expect(response.fields).toHaveLength(1);
10091009
expect(response.fields[0].id).toBe('1');
1010-
expect(response.fields[0].tokenizedData.id).toBe('token123');
1010+
expect(response.fields[0].tokenized_data.id).toBe('token123');
10111011
expect(response.errors).toBe(null);
10121012
});
10131013

@@ -1154,7 +1154,7 @@ describe('VaultController update method', () => {
11541154
expect.any(Object) // Headers
11551155
);
11561156
expect(response).toBeInstanceOf(UpdateResponse);
1157-
expect(response.updatedField.skyflowId).toBe('id123');
1157+
expect(response.updatedField.skyflow_id).toBe('id123');
11581158
expect(response.updatedField.field1).toBe('token123');
11591159
expect(response.errors).toBeNull();
11601160
});
@@ -1185,7 +1185,7 @@ describe('VaultController update method', () => {
11851185
expect.any(Object) // Headers
11861186
);
11871187
expect(response).toBeInstanceOf(UpdateResponse);
1188-
expect(response.updatedField.skyflowId).toBe('id123');
1188+
expect(response.updatedField.skyflow_id).toBe('id123');
11891189
expect(response.updatedField.field1).toBe('token123');
11901190
expect(response.errors).toBeNull();
11911191
});
@@ -1219,7 +1219,7 @@ describe('VaultController update method', () => {
12191219
expect.any(Object) // Headers
12201220
);
12211221
expect(response).toBeInstanceOf(UpdateResponse);
1222-
expect(response.updatedField.skyflowId).toBe('id123');
1222+
expect(response.updatedField.skyflow_id).toBe('id123');
12231223
expect(response.updatedField.field1).toBe('token123');
12241224
expect(response.errors).toBeNull();
12251225
});

test/vault/skyflow/skyflow.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,68 @@ describe('Skyflow initialization', () => {
190190
expect(() => skyflow.setLogLevel("DUMMY"))
191191
.toThrowError(invalidLogLevelError);
192192
});
193+
194+
test('should update log level using updateLogLevel and return Skyflow instance', () => {
195+
const skyflow = new Skyflow({
196+
vaultConfigs: validVaultConfig,
197+
logLevel: LogLevel.ERROR
198+
});
199+
const result = skyflow.updateLogLevel(LogLevel.DEBUG);
200+
expect(skyflow.getLogLevel()).toBe(LogLevel.DEBUG);
201+
expect(result).toBeInstanceOf(Skyflow);
202+
});
203+
204+
test('should support method chaining with updateLogLevel', () => {
205+
const skyflow = new Skyflow({
206+
vaultConfigs: validVaultConfig,
207+
logLevel: LogLevel.ERROR
208+
});
209+
const result = skyflow.updateLogLevel(LogLevel.INFO);
210+
expect(result).toBe(skyflow);
211+
});
212+
213+
test('should throw error when updateLogLevel is called with invalid logLevel', () => {
214+
const skyflow = new Skyflow({
215+
vaultConfigs: validVaultConfig,
216+
logLevel: LogLevel.ERROR
217+
});
218+
expect(() => skyflow.updateLogLevel("INVALID"))
219+
.toThrowError(invalidLogLevelError);
220+
});
221+
222+
test('should propagate updated log level to all vault clients via updateLogLevel', () => {
223+
const skyflow = new Skyflow({
224+
vaultConfigs: [
225+
{ vaultId: "VAULT_ID_1", clusterId: "CLUSTER_ID" },
226+
{ vaultId: "VAULT_ID_2", clusterId: "CLUSTER_ID" }
227+
],
228+
logLevel: LogLevel.ERROR
229+
});
230+
skyflow.updateLogLevel(LogLevel.WARN);
231+
expect(skyflow.getLogLevel()).toBe(LogLevel.WARN);
232+
});
233+
234+
test('should propagate updated log level to vault and connection clients via updateLogLevel', () => {
235+
const skyflow = new Skyflow({
236+
vaultConfigs: [{ vaultId: "VAULT_ID", clusterId: "CLUSTER_ID" }],
237+
connectionConfigs: [{ connectionId: "CONN_ID", connectionUrl: "https://conn.com" }],
238+
logLevel: LogLevel.ERROR
239+
});
240+
skyflow.updateLogLevel(LogLevel.OFF);
241+
expect(skyflow.getLogLevel()).toBe(LogLevel.OFF);
242+
});
243+
244+
test('should update log level to all valid LogLevel values via updateLogLevel', () => {
245+
const skyflow = new Skyflow({
246+
vaultConfigs: validVaultConfig,
247+
logLevel: LogLevel.ERROR
248+
});
249+
const levels = [LogLevel.DEBUG, LogLevel.INFO, LogLevel.WARN, LogLevel.ERROR, LogLevel.OFF];
250+
levels.forEach(level => {
251+
skyflow.updateLogLevel(level);
252+
expect(skyflow.getLogLevel()).toBe(level);
253+
});
254+
});
193255
});
194256

195257
describe('Skyflow Credentials Tests', () => {

0 commit comments

Comments
 (0)