diff --git a/samples/deprecated/service-account/bearer-token-expiry-example.ts b/samples/deprecated/service-account/bearer-token-expiry-example.ts new file mode 100644 index 00000000..fc98bd3b --- /dev/null +++ b/samples/deprecated/service-account/bearer-token-expiry-example.ts @@ -0,0 +1,102 @@ +import { + Credentials, + DetokenizeOptions, + DetokenizeRequest, + DetokenizeResponse, + Env, + LogLevel, + RedactionType, + Skyflow, + SkyflowError, + VaultConfig, + SkyflowConfig, + DetokenizeData +} from 'skyflow-node'; + +/** +* This example demonstrates how to configure and use the Skyflow SDK +* to detokenize sensitive data stored in a Skyflow vault. +* It includes setting up credentials, configuring the vault, and +* making a detokenization request. The code also implements a retry +* mechanism to handle unauthorized access errors (HTTP 401). +*/ +async function detokenizeData(skyflowClient: Skyflow, vaultId: string) { + try { + // Creating a list of tokens to be detokenized + const detokenizeData: DetokenizeData[] = [ + { + token: '', + redactionType: RedactionType.PLAIN_TEXT + }, + { + token: '', + redactionType: RedactionType.PLAIN_TEXT + } + ]; + + // Building a detokenization request + const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest( + detokenizeData + ); + + // Configuring detokenization options + const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions(); + detokenizeOptions.setContinueOnError(false); // Stop on error + detokenizeOptions.setDownloadUrl(false); // Disable download URL generation + + // Sending the detokenization request and receiving the response + const response: DetokenizeResponse = await skyflowClient + .vault(vaultId) + .detokenize(detokenizeRequest, detokenizeOptions); + + // Printing the detokenized response + console.log('Detokenization successful:', response); + } catch (err) { + throw err; + } +} + +async function main() { + try { + // Setting up credentials for accessing the Skyflow vault + const credentials: Credentials = { + credentialsString: '', // Credentials string for authentication + }; + + // Configuring the Skyflow vault with necessary details + const primaryVaultConfig: VaultConfig = { + vaultId: '', // Vault ID + clusterId: '', // Cluster ID + env: Env.PROD, // Environment set to PROD + credentials: credentials // Setting credentials + }; + + // Creating a Skyflow client instance with the configured vault + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.ERROR, // Setting log level to ERROR + }; + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Attempting to detokenize data using the Skyflow client + try { + await detokenizeData(skyflowClient, primaryVaultConfig.vaultId); + } catch (err) { + // Retry detokenization if the error is due to unauthorized access (HTTP 401) + if (err instanceof SkyflowError && err.error?.http_code === 401) { + console.warn('Unauthorized access detected. Retrying...'); + await detokenizeData(skyflowClient, primaryVaultConfig.vaultId); + } else { + // Rethrow the exception for other error codes + throw err; + } + } + } catch (err) { + // Handling any exceptions that occur during the process + console.error('An error occurred:', err); + } +} + +// Invoke the main function +main(); diff --git a/samples/deprecated/service-account/scoped-token-generation-example.ts b/samples/deprecated/service-account/scoped-token-generation-example.ts new file mode 100644 index 00000000..4756cd28 --- /dev/null +++ b/samples/deprecated/service-account/scoped-token-generation-example.ts @@ -0,0 +1,50 @@ +/* + Copyright (c) 2022 Skyflow, Inc. +*/ +// v1 nomenclature: roleIDs (uppercase D) — deprecated alias for roleIds in BearerTokenOptions +import { + generateBearerTokenFromCreds, + isExpired, + LogLevel, +} from 'skyflow-node'; + +let bearerToken: string = ''; + +const cred = { + clientId: '', + clientName: '', + keyId: '', + tokenUri: '', + privateKey: '', +}; + +function getScopedBearerTokenFromCreds() { + return new Promise((resolve, reject) => { + try { + // v1: roleIDs (uppercase D) — deprecated key, emits WARN, still works + const options = { + roleIDs: [''] as string[], + logLevel: LogLevel.WARN, + }; + if (!isExpired(bearerToken)) resolve(bearerToken); + else { + generateBearerTokenFromCreds(JSON.stringify(cred), options as any) + .then(response => { + bearerToken = response.accessToken; + resolve(bearerToken); + }) + .catch(error => { + reject(error); + }); + } + } catch (e) { + reject(e); + } + }); +} + +const tokens = async () => { + console.log(await getScopedBearerTokenFromCreds()); +}; + +tokens(); diff --git a/samples/deprecated/vault-api/credentials-options.ts b/samples/deprecated/vault-api/credentials-options.ts new file mode 100644 index 00000000..6efcbee8 --- /dev/null +++ b/samples/deprecated/vault-api/credentials-options.ts @@ -0,0 +1,150 @@ +import { + Credentials, + DeleteRequest, + Env, + InsertOptions, + InsertRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError, + DeleteResponse, + StringCredentials +} from 'skyflow-node'; + +/** + * Skyflow Secure Data Deletion Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configurations + * 3. Create and perform delete requests + * 4. Handle response and errors + */ +const VAULT_ID = ''; +const CLUSTER_ID = ''; +const SETUP_TOKEN = 'BEARER_TOKEN'; + +async function setup(): Promise<[string, string]> { + const setupClient = new Skyflow({ + vaultConfigs: [{ vaultId: VAULT_ID, clusterId: CLUSTER_ID, env: Env.DEV, + credentials: { token: SETUP_TOKEN } }], + logLevel: LogLevel.WARN, + }); + const insertOpts = new InsertOptions(); insertOpts.setReturnTokens(false); + const insertResp = await setupClient.vault(VAULT_ID).insert( + new InsertRequest('table1', [ + { card_number: '4111111111111112' }, + { card_number: '4111111111111112' }, + ]), insertOpts + ); + const idV1 = insertResp.insertedFields![0].skyflowId!; + const idV2 = insertResp.insertedFields![1].skyflowId!; + console.log('Setup: inserted IDs:', idV1, idV2); + return [idV1, idV2]; +} + +async function performSecureDataDeletion() { + const [insertedIdV1, insertedIdV2] = await setup(); + + try { + // Step 1: Configure Skyflow client Credentials + const cred: Record = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '', + }; + + // v1 credentialsString — old field names (clientID, keyID, tokenURI) + const stringCredentials: StringCredentials = { + credentialsString: JSON.stringify(cred), + }; + const skyflowCredentials: Credentials = stringCredentials; + + // v2 credentialsString — new canonical field names (clientId, keyId, tokenUri) + const credV2: Record = { + clientId: cred.clientID, + clientName: cred.clientName, + keyId: cred.keyID, + tokenUri: cred.tokenURI, + privateKey: cred.privateKey, + }; + const stringCredentialsV2: StringCredentials = { + credentialsString: JSON.stringify(credV2), + }; + const skyflowCredentialsV2: Credentials = stringCredentialsV2; + + // Step 2: Configure Vaults + // Individual vault credentials take priority over skyflowCredentials + const primaryVaultConfig: VaultConfig = { + vaultId: VAULT_ID, + clusterId: CLUSTER_ID, + env: Env.DEV, + credentials: { token: SETUP_TOKEN }, // per-vault credential overrides skyflowCredentials + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.WARN, + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Delete Request for Primary Vault (uses v1 skyflowCredentials) + const primaryDeleteIds: Array = [insertedIdV1]; + + const primaryTableName: string = 'table1'; + + const primaryDeleteRequest: DeleteRequest = new DeleteRequest( + primaryTableName, + primaryDeleteIds, + ); + + // Perform Delete Operation for Primary Vault + const primaryDeleteResponse: DeleteResponse = await skyflowClient + .vault(VAULT_ID) + .delete(primaryDeleteRequest); + + console.log('Primary Vault Deletion Successful (v1 credentialsString):', primaryDeleteResponse); + + // Step 5: v2 credentialsString (clientId/keyId/tokenUri — new canonical names) + const skyflowConfigV2: SkyflowConfig = { + vaultConfigs: [{ + vaultId: VAULT_ID, + clusterId: CLUSTER_ID, + env: Env.DEV, + credentials: { token: SETUP_TOKEN }, + }], + skyflowCredentials: skyflowCredentialsV2, // v2 field names + logLevel: LogLevel.WARN, + }; + const skyflowClientV2: Skyflow = new Skyflow(skyflowConfigV2); + + const secondaryDeleteResponse: DeleteResponse = await skyflowClientV2 + .vault(VAULT_ID) + .delete(new DeleteRequest('table1', [insertedIdV2])); + + console.log('Secondary Vault Deletion Successful (v2 credentialsString):', secondaryDeleteResponse); + + } catch (error) { + // Comprehensive Error Handling + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +// Invoke the secure data deletion function +performSecureDataDeletion(); diff --git a/samples/deprecated/vault-api/detokenize-records.ts b/samples/deprecated/vault-api/detokenize-records.ts new file mode 100644 index 00000000..a77d5486 --- /dev/null +++ b/samples/deprecated/vault-api/detokenize-records.ts @@ -0,0 +1,81 @@ +import { + Credentials, + DetokenizeOptions, + DetokenizeRequest, + DetokenizeResponse, + Env, + LogLevel, + RedactionType, + Skyflow, + SkyflowError, + VaultConfig, + SkyflowConfig, + DetokenizeData, + SkyflowRecordError, +} from 'skyflow-node'; + +// v1 nomenclature: setDownloadURL (uppercase) on DetokenizeOptions +async function performDetokenization() { + try { + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.WARN, + }; + + const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions(); + detokenizeOptions.setContinueOnError(true); + + // v1: setDownloadURL uppercase — deprecated setter, still works + (detokenizeOptions as any).setDownloadURL(false); + // v1: getDownloadURL uppercase — deprecated getter, still works + console.log('v1 getDownloadURL:', (detokenizeOptions as any).getDownloadURL()); + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + const detokenizeData: DetokenizeData[] = [ + { + token: '8561-9339-2309-3015', + redactionType: RedactionType.PLAIN_TEXT, + }, + ]; + + const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest(detokenizeData); + + const response: DetokenizeResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .detokenize(detokenizeRequest, detokenizeOptions); + + console.log('Detokenization successful:', response); + + if (response.errors != null) { + response.errors.forEach((err: SkyflowRecordError) => { + // v1: access request_ID (deprecated) + console.log('v1 request_ID:', (err as any).request_ID); + }); + } + + } catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +performDetokenization(); diff --git a/samples/deprecated/vault-api/file-upload.ts b/samples/deprecated/vault-api/file-upload.ts new file mode 100644 index 00000000..017273d9 --- /dev/null +++ b/samples/deprecated/vault-api/file-upload.ts @@ -0,0 +1,69 @@ +// Please use Node version 20 & above to run file upload +import { + Credentials, + Env, + FileUploadRequest, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError, + FileUploadResponse, + FileUploadOptions, +} from 'skyflow-node'; + +// v1 nomenclature: 3-arg FileUploadRequest constructor (table, skyflowId, columnName) +async function performFileUpload() { + try { + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.WARN, + }; + + // v1: 3-arg constructor (table, skyflowId, columnName) — deprecated, emits WARN, still works + const uploadReq: FileUploadRequest = new FileUploadRequest( + 'table1', + '', // skyflowId as 2nd arg (old API) + 'file', + ); + + // v1: .skyflowId getter on FileUploadRequest — deprecated, emits WARN + console.log('v1 skyflowId getter:', (uploadReq as any).skyflowId); + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + const uploadOptions: FileUploadOptions = new FileUploadOptions(); + uploadOptions.setFilePath(''); + // v1: NO setSkyflowId() call — ID is in the constructor + + const response: FileUploadResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .uploadFile(uploadReq, uploadOptions); + + console.log('File upload successful:', response); + + } catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +performFileUpload(); diff --git a/samples/deprecated/vault-api/get-records.ts b/samples/deprecated/vault-api/get-records.ts new file mode 100644 index 00000000..dc1c08e0 --- /dev/null +++ b/samples/deprecated/vault-api/get-records.ts @@ -0,0 +1,75 @@ +import { + Credentials, + Env, + GetOptions, + GetRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError, + GetResponse, +} from 'skyflow-node'; + +// v1 nomenclature: setDownloadURL (uppercase) + skyflow_id on data +async function performSecureDataRetrieval() { + try { + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.WARN, + }; + + const getOptions: GetOptions = new GetOptions(); + getOptions.setReturnTokens(true); + + // v1: setDownloadURL (uppercase — deprecated, still works, emits WARN) + (getOptions as any).setDownloadURL(false); + // v1: getDownloadURL (uppercase — deprecated getter, still works, emits WARN) + console.log('v1 getDownloadURL:', (getOptions as any).getDownloadURL()); + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + const getRequest: GetRequest = new GetRequest('table1', [ + '', + '', + ]); + + const response: GetResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .get(getRequest, getOptions); + + console.log('Get response:', response); + + if (response.data != null) { + for (const record of response.data) { + // v1: access skyflow_id (deprecated getter) + console.log('v1 skyflow_id:', (record as any).skyflow_id); + console.log('v1 record:', record); + } + } + + } catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +performSecureDataRetrieval(); diff --git a/samples/deprecated/vault-api/update-record.ts b/samples/deprecated/vault-api/update-record.ts new file mode 100644 index 00000000..55e27b0b --- /dev/null +++ b/samples/deprecated/vault-api/update-record.ts @@ -0,0 +1,69 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + UpdateRequest, + UpdateOptions, + UpdateResponse, + SkyflowError, +} from 'skyflow-node'; + +// v1 nomenclature: skyflow_id key in request data + skyflow_id on response +async function performSecureDataUpdate() { + try { + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.WARN, + }; + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // v1: use skyflow_id (snake_case) as the record identifier key + const updateData: Record = { + skyflow_id: '', + card_number: '4111111111111111', + }; + + const updateReq: UpdateRequest = new UpdateRequest('table1', updateData); + + const updateOptions: UpdateOptions = new UpdateOptions(); + updateOptions.setReturnTokens(true); + + const response: UpdateResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .update(updateReq, updateOptions); + + // v1: access skyflow_id on response (deprecated getter) + console.log('Update response:', response); + if (response.updatedField != null) { + console.log('v1 skyflow_id:', (response.updatedField as any).skyflow_id); + } + + } catch (error) { + if (error instanceof SkyflowError) { + console.error('Skyflow Specific Error:', { + code: error.error?.http_code, + message: error.message, + details: error.error?.details, + }); + } else { + console.error('Unexpected Error:', error); + } + } +} + +performSecureDataUpdate(); diff --git a/samples/detect-api/deidentify-file-with-filepath.ts b/samples/detect-api/deidentify-file-with-filepath.ts index cd02e309..b0638776 100644 --- a/samples/detect-api/deidentify-file-with-filepath.ts +++ b/samples/detect-api/deidentify-file-with-filepath.ts @@ -134,7 +134,9 @@ import { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/detect-api/deidentify-file.ts b/samples/detect-api/deidentify-file.ts index 42299098..ace759bf 100644 --- a/samples/detect-api/deidentify-file.ts +++ b/samples/detect-api/deidentify-file.ts @@ -134,7 +134,9 @@ async function performDeidentifyFile() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/detect-api/deidentify-text.ts b/samples/detect-api/deidentify-text.ts index 1b97a882..d1d641e2 100644 --- a/samples/detect-api/deidentify-text.ts +++ b/samples/detect-api/deidentify-text.ts @@ -93,7 +93,9 @@ async function performDeidentifyText() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/detect-api/get-detect-run.ts b/samples/detect-api/get-detect-run.ts index c8645d3f..ba4d9538 100644 --- a/samples/detect-api/get-detect-run.ts +++ b/samples/detect-api/get-detect-run.ts @@ -62,7 +62,9 @@ async function performGetDetectRun() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/detect-api/reidentify-text.ts b/samples/detect-api/reidentify-text.ts index df11d223..8ecdcd44 100644 --- a/samples/detect-api/reidentify-text.ts +++ b/samples/detect-api/reidentify-text.ts @@ -72,7 +72,9 @@ async function performReidentifyText() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/service-account/bearer-token-expiry-example.ts b/samples/service-account/bearer-token-expiry-example.ts index fc98bd3b..d79d604c 100644 --- a/samples/service-account/bearer-token-expiry-example.ts +++ b/samples/service-account/bearer-token-expiry-example.ts @@ -84,7 +84,7 @@ async function main() { await detokenizeData(skyflowClient, primaryVaultConfig.vaultId); } catch (err) { // Retry detokenization if the error is due to unauthorized access (HTTP 401) - if (err instanceof SkyflowError && err.error?.http_code === 401) { + if (err instanceof SkyflowError && err.error?.httpCode === 401) { console.warn('Unauthorized access detected. Retrying...'); await detokenizeData(skyflowClient, primaryVaultConfig.vaultId); } else { diff --git a/samples/service-account/scoped-token-generation-example.ts b/samples/service-account/scoped-token-generation-example.ts index 7482dec8..97746f3b 100644 --- a/samples/service-account/scoped-token-generation-example.ts +++ b/samples/service-account/scoped-token-generation-example.ts @@ -5,6 +5,7 @@ import { generateBearerToken, generateBearerTokenFromCreds, isExpired, + LogLevel, } from 'skyflow-node'; const filepath = 'CREDENTIALS_FILE_PATH'; @@ -12,10 +13,10 @@ let bearerToken: string = ''; // To generate Bearer Token from credentials string. const cred = { - clientID: '', + clientId: '', clientName: '', - keyID: '', - tokenURI: '', + keyId: '', + tokenUri: '', privateKey: '', }; @@ -23,7 +24,9 @@ function getScopedBearerTokenFromFilePath() { return new Promise((resolve, reject) => { try { const options = { - roleIDs: ['roleID1', 'roleID2'], + roleIds: ['roleID1', 'roleID2'], + tokenUri: '', // optional: overrides tokenUri from credentials file + logLevel: LogLevel.WARN, }; if (!isExpired(bearerToken)) resolve(bearerToken); else { @@ -46,7 +49,9 @@ function getScopedBearerTokenFromCreds() { return new Promise((resolve, reject) => { try { const options = { - roleIDs: ['roleID1', 'roleID2'], + roleIds: ['roleID1', 'roleID2'], + tokenUri: '', // optional: overrides tokenUri from credentials string + logLevel: LogLevel.WARN, }; if (!isExpired(bearerToken)) resolve(bearerToken); else { diff --git a/samples/service-account/signed-token-generation-example.ts b/samples/service-account/signed-token-generation-example.ts index e717967b..071573fb 100644 --- a/samples/service-account/signed-token-generation-example.ts +++ b/samples/service-account/signed-token-generation-example.ts @@ -10,10 +10,10 @@ let filepath: string = 'CREDENTIALS_FILE_PATH'; // To generate Bearer Token from credentials string. let cred = { - clientID: '', + clientId: '', clientName: '', - keyID: '', - tokenURI: '', + keyId: '', + tokenUri: '', privateKey: '', }; @@ -23,7 +23,8 @@ function getSignedTokenFromFilePath() { const options = { ctx: 'ctx', dataTokens: ['dataToken1', 'dataToken2'], - timeToLive: 90 // In seconds. + timeToLive: 90, // In seconds. + tokenUri: '', // optional: overrides tokenUri from credentials file }; let response = await generateSignedDataTokens(filepath, options); resolve(response); @@ -40,6 +41,7 @@ function getSignedTokenFromCreds() { ctx: 'ctx', dataTokens: ['dataToken1', 'dataToken2'], timeToLive: 90, // In seconds. + tokenUri: '', // optional: overrides tokenUri from credentials string }; let response = await generateSignedDataTokensFromCreds( JSON.stringify(cred), diff --git a/samples/service-account/token-generation-example.ts b/samples/service-account/token-generation-example.ts index 040ec831..29e99527 100644 --- a/samples/service-account/token-generation-example.ts +++ b/samples/service-account/token-generation-example.ts @@ -12,10 +12,10 @@ let bearerToken: string = ''; // To generate Bearer Token from credentials string. const cred = { - clientID: '', + clientId: '', clientName: '', - keyID: '', - tokenURI: '', + keyId: '', + tokenUri: '', privateKey: '', }; diff --git a/samples/service-account/token-generation-with-context-example.ts b/samples/service-account/token-generation-with-context-example.ts index 308898d1..86e80868 100644 --- a/samples/service-account/token-generation-with-context-example.ts +++ b/samples/service-account/token-generation-with-context-example.ts @@ -7,15 +7,15 @@ import { isExpired, } from 'skyflow-node'; -const filepath: string = 'CREDENTIALS_FILE_PATH'; +const filepath: string = ''; let bearerToken: string = ''; // To generate Bearer Token from credentials string. const cred = { - clientID: '', + clientId: '', clientName: '', - keyID: '', - tokenURI: '', + keyId: '', + tokenUri: '', privateKey: '', }; diff --git a/samples/vault-api/client-operations.ts b/samples/vault-api/client-operations.ts index 1fc43b58..91687f92 100644 --- a/samples/vault-api/client-operations.ts +++ b/samples/vault-api/client-operations.ts @@ -92,9 +92,11 @@ async function performSecureDataDeletion() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, - details: error.error?.details + details: error.error?.details, }); } else { diff --git a/samples/vault-api/credentials-options.ts b/samples/vault-api/credentials-options.ts index bcbda5d3..0a316962 100644 --- a/samples/vault-api/credentials-options.ts +++ b/samples/vault-api/credentials-options.ts @@ -6,7 +6,7 @@ import { Skyflow, VaultConfig, SkyflowConfig, - SkyflowError, + SkyflowError, DeleteResponse, StringCredentials } from 'skyflow-node'; @@ -24,10 +24,10 @@ async function performSecureDataDeletion() { try { // Step 1: Configure Skyflow client Credentials const cred: Record = { - clientID: '', // Client identifier + clientId: '', // Client identifier clientName: '', // Client name - keyID: '', // Key identifier - tokenURI: '', // Token URI + keyId: '', // Key identifier + tokenUri: '', // Token URI privateKey: '' // Private key for authentication }; @@ -87,8 +87,7 @@ async function performSecureDataDeletion() { .vault('') // Specify the primary vault ID .delete(primaryDeleteRequest); - // Handle Successful Response - console.log('Primary Vault Deletion Successful:', primaryDeleteResponse); + console.log('Primary Vault Deletion Successful (v1 credentialsString):', primaryDeleteResponse); // Step 5: Prepare Delete Request for Secondary Vault const secondaryDeleteIds: Array = [ @@ -116,9 +115,11 @@ async function performSecureDataDeletion() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, - details: error.error?.details + details: error.error?.details, }); } else { console.error('Unexpected Error:', error); diff --git a/samples/vault-api/data-residency.ts b/samples/vault-api/data-residency.ts index 395a45bd..27804595 100644 --- a/samples/vault-api/data-residency.ts +++ b/samples/vault-api/data-residency.ts @@ -1,15 +1,17 @@ -import { - Credentials, - Env, - GetRequest, - GetResponse, - InsertRequest, - LogLevel, - Skyflow, - VaultConfig, - SkyflowConfig, - InsertResponse, - SkyflowError +import { + Credentials, + Env, + GetRequest, + GetOptions, + GetResponse, + InsertRequest, + LogLevel, + RedactionType, + Skyflow, + VaultConfig, + SkyflowConfig, + InsertResponse, + SkyflowError } from 'skyflow-node'; /** @@ -65,6 +67,9 @@ async function transferDataBetweenVaults() { const tableName: string = 'your-table-name'; // Replace with your table name const getRequest: GetRequest = new GetRequest(tableName, getIds); + const getOptions: GetOptions = new GetOptions(); + getOptions.setReturnTokens(false); // Get plaintext to re-insert into destination vault + getOptions.setRedactionType(RedactionType.PLAIN_TEXT); // Perform Get request on Primary Vault const getResponse: GetResponse = await skyflowClient @@ -78,9 +83,12 @@ async function transferDataBetweenVaults() { // Remove skyflow_id from the data (if needed for re-insertion) const sanitizedData = insertData.map((item: Record) => { - // eslint-disable-next-line camelcase - const { skyflow_id, ...rest } = item; // Exclude the skyflow_id field - return rest; + // SK-2812: strip skyflowId (new), skyflow_id (deprecated getter, enumerable), file (use uploadFile), nulls + return Object.fromEntries( + Object.entries(item).filter(([k, v]) => + k !== 'skyflowId' && k !== 'skyflow_id' && k !== 'file' && v !== null + ) + ); }); // Step 7: Insert Data into Secondary Vault @@ -100,7 +108,9 @@ async function transferDataBetweenVaults() { // Comprehensive error handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/vault-api/delete-records.ts b/samples/vault-api/delete-records.ts index 85d384bf..58d299e3 100644 --- a/samples/vault-api/delete-records.ts +++ b/samples/vault-api/delete-records.ts @@ -60,12 +60,16 @@ async function performDeletion() { // Handle Successful Response console.log('Deletion successful:', response); + console.log('deletedIds (non-nullable):', response.deletedIds); + console.log('deletedIds.length:', response.deletedIds.length); } catch (error) { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/vault-api/detokenzie-records.ts b/samples/vault-api/detokenzie-records.ts index 6b7b243e..debf346b 100644 --- a/samples/vault-api/detokenzie-records.ts +++ b/samples/vault-api/detokenzie-records.ts @@ -85,7 +85,9 @@ async function performDetokenization() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/vault-api/file-upload.ts b/samples/vault-api/file-upload.ts index 0546ebc8..9fe9dfc9 100644 --- a/samples/vault-api/file-upload.ts +++ b/samples/vault-api/file-upload.ts @@ -54,22 +54,16 @@ async function performFileUpload() { const columnName: string = 'column-name'; // Column name to store file const filePath: string = 'file-path'; // Path to the file for upload - // Step 5: Create File Upload Request + // Step 5: Create File Upload Request (SK-2812: 2-arg constructor, skyflowId moved to options) const uploadReq: FileUploadRequest = new FileUploadRequest( tableName, - skyflowId, columnName, ); // Step 6: Configure FileUpload Options const uploadOptions: FileUploadOptions = new FileUploadOptions(); - // Set any one of FilePath, Base64 or FileObject in FileUploadOptions - - // uploadOptions.setFilePath(filePath); // Set the file path - // uploadOptions.setBase64('base64-string'); // Set base64 string - // uploadOptions.setFileName('file-name'); // Set the file name when using base64 - const buffer = fs.readFileSync(filePath); - uploadOptions.setFileObject(new File([buffer], filePath)); // Set a File object + uploadOptions.setSkyflowId(skyflowId); // SK-2812: new API + uploadOptions.setFilePath(filePath); // Step 6: Perform File Upload const response: FileUploadResponse = await skyflowClient @@ -83,7 +77,9 @@ async function performFileUpload() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/vault-api/get-column-values.ts b/samples/vault-api/get-column-values.ts index 5c925451..c4e6016a 100644 --- a/samples/vault-api/get-column-values.ts +++ b/samples/vault-api/get-column-values.ts @@ -82,7 +82,9 @@ async function performSecureColumnRetrieval() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/vault-api/get-records.ts b/samples/vault-api/get-records.ts index 6317225c..9e0a8c8d 100644 --- a/samples/vault-api/get-records.ts +++ b/samples/vault-api/get-records.ts @@ -59,7 +59,13 @@ async function performSecureDataRetrieval() { // Step 6: Configure Get Options const getOptions: GetOptions = new GetOptions(); - getOptions.setReturnTokens(true); // Optional: Get tokens for retrieved data + getOptions.setReturnTokens(true); + + // NEW API (SK-2812): setDownloadUrl (camelCase) + getOptions.setDownloadUrl(false); + + // DEPRECATED API — still works, logs WARN: setDownloadURL (uppercase URL) + // getOptions.setDownloadURL(false); // Step 7: Perform Secure Retrieval const response: GetResponse = await skyflowClient @@ -80,7 +86,9 @@ async function performSecureDataRetrieval() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/vault-api/insert-byot.ts b/samples/vault-api/insert-byot.ts index c1392ec0..32741701 100644 --- a/samples/vault-api/insert-byot.ts +++ b/samples/vault-api/insert-byot.ts @@ -77,9 +77,11 @@ async function performSecureDataInsertionWithBYOT() { // Step 7: Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, - details: error.error?.details + details: error.error?.details, }); } else { console.error('Unexpected Error:', error); diff --git a/samples/vault-api/insert-continue-on-error.ts b/samples/vault-api/insert-continue-on-error.ts index 483d35f6..d33c86a8 100644 --- a/samples/vault-api/insert-continue-on-error.ts +++ b/samples/vault-api/insert-continue-on-error.ts @@ -29,7 +29,6 @@ async function performSecureDataInsertion() { apiKey: 'your-skyflow-api-key', }; - // Step 2: Configure Vault const primaryVaultConfig: VaultConfig = { vaultId: 'your-vault-id', // Unique vault identifier @@ -102,9 +101,11 @@ async function performSecureDataInsertion() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, - details: error.error?.details + details: error.error?.details, }); } else { console.error('Unexpected Error:', error); diff --git a/samples/vault-api/insert-records.ts b/samples/vault-api/insert-records.ts index 9ddf8966..9af76183 100644 --- a/samples/vault-api/insert-records.ts +++ b/samples/vault-api/insert-records.ts @@ -80,9 +80,11 @@ async function performSecureDataInsertion() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, - details: error.error?.details + details: error.error?.details, }); } else { console.error('Unexpected Error:', error); diff --git a/samples/vault-api/invoke-connection.ts b/samples/vault-api/invoke-connection.ts index fb9ea95e..88f50b53 100644 --- a/samples/vault-api/invoke-connection.ts +++ b/samples/vault-api/invoke-connection.ts @@ -82,12 +82,11 @@ async function invokeSkyflowConnection() { console.log('Connection invocation successful:', response); } catch (error) { - // Comprehensive Error Handling if (error instanceof SkyflowError) { - console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + console.error('SkyflowError:', { + httpCode: error.error?.httpCode, message: error.message, - details: error.error?.details + details: error.error?.details, }); } else { console.error('Unexpected Error:', error); diff --git a/samples/vault-api/query-records.ts b/samples/vault-api/query-records.ts index 1c27daa6..60c8dca0 100644 --- a/samples/vault-api/query-records.ts +++ b/samples/vault-api/query-records.ts @@ -68,7 +68,9 @@ async function executeQuery() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/vault-api/tokenize-records.ts b/samples/vault-api/tokenize-records.ts index 4c65d1d1..64390032 100644 --- a/samples/vault-api/tokenize-records.ts +++ b/samples/vault-api/tokenize-records.ts @@ -64,7 +64,9 @@ async function executeTokenization() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, details: error.error?.details, }); diff --git a/samples/vault-api/update-record.ts b/samples/vault-api/update-record.ts index 3e028c1b..a7c9c84f 100644 --- a/samples/vault-api/update-record.ts +++ b/samples/vault-api/update-record.ts @@ -46,6 +46,7 @@ async function performSecureDataUpdate() { const skyflowClient: Skyflow = new Skyflow(skyflowConfig); // Step 4: Prepare Update Data + // SK-2812: data object uses camelCase skyflowId (was skyflow_id) const updateData: Record = { skyflowId: 'your-skyflow-id', // Skyflow ID of the record to update card_number: '1234567890123456' // Updated sensitive data @@ -73,9 +74,11 @@ async function performSecureDataUpdate() { // Comprehensive Error Handling if (error instanceof SkyflowError) { console.error('Skyflow Specific Error:', { - code: error.error?.http_code, + httpCode: error.error?.httpCode, + grpcCode: error.error?.grpcCode, + httpStatus: error.error?.httpStatus, message: error.message, - details: error.error?.details + details: error.error?.details, }); } else { console.error('Unexpected Error:', error);