From 8e54dfb4eb631439ef1caabbb216f946fe4b0d92 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Fri, 22 May 2026 13:29:50 +0530 Subject: [PATCH 1/5] SK-2841: Update deprecated samples --- .../deidentify-file-with-filepath.ts | 148 +++++++++++++++++ .../deprecated/detect-api/deidentify-file.ts | 148 +++++++++++++++++ .../deprecated/detect-api/deidentify-text.ts | 107 +++++++++++++ .../deprecated/detect-api/get-detect-run.ts | 76 +++++++++ .../deprecated/detect-api/reidentify-text.ts | 86 ++++++++++ .../bearer-token-expiry-example.ts | 102 ++++++++++++ .../deprecated/vault-api/client-operations.ts | 91 +++++++++++ .../vault-api/credentials-options.ts | 150 ++++++++++++++++++ .../deprecated/vault-api/data-residency.ts | 130 +++++++++++++++ .../deprecated/vault-api/delete-records.ts | 70 ++++++++ .../vault-api/detokenize-records.ts | 79 +++++++++ .../vault-api/detokenzie-records.ts | 95 +++++++++++ samples/deprecated/vault-api/file-upload.ts | 66 ++++++++ .../deprecated/vault-api/get-column-values.ts | 95 +++++++++++ samples/deprecated/vault-api/get-records.ts | 73 +++++++++ samples/deprecated/vault-api/insert-byot.ts | 74 +++++++++ .../vault-api/insert-continue-on-error.ts | 78 +++++++++ .../deprecated/vault-api/insert-records.ts | 68 ++++++++ .../deprecated/vault-api/invoke-connection.ts | 142 +++++++++++++++++ samples/deprecated/vault-api/query-records.ts | 61 +++++++ .../deprecated/vault-api/tokenize-records.ts | 78 +++++++++ samples/deprecated/vault-api/update-record.ts | 69 ++++++++ 22 files changed, 2086 insertions(+) create mode 100644 samples/deprecated/detect-api/deidentify-file-with-filepath.ts create mode 100644 samples/deprecated/detect-api/deidentify-file.ts create mode 100644 samples/deprecated/detect-api/deidentify-text.ts create mode 100644 samples/deprecated/detect-api/get-detect-run.ts create mode 100644 samples/deprecated/detect-api/reidentify-text.ts create mode 100644 samples/deprecated/service-account/bearer-token-expiry-example.ts create mode 100644 samples/deprecated/vault-api/client-operations.ts create mode 100644 samples/deprecated/vault-api/credentials-options.ts create mode 100644 samples/deprecated/vault-api/data-residency.ts create mode 100644 samples/deprecated/vault-api/delete-records.ts create mode 100644 samples/deprecated/vault-api/detokenize-records.ts create mode 100644 samples/deprecated/vault-api/detokenzie-records.ts create mode 100644 samples/deprecated/vault-api/file-upload.ts create mode 100644 samples/deprecated/vault-api/get-column-values.ts create mode 100644 samples/deprecated/vault-api/get-records.ts create mode 100644 samples/deprecated/vault-api/insert-byot.ts create mode 100644 samples/deprecated/vault-api/insert-continue-on-error.ts create mode 100644 samples/deprecated/vault-api/insert-records.ts create mode 100644 samples/deprecated/vault-api/invoke-connection.ts create mode 100644 samples/deprecated/vault-api/query-records.ts create mode 100644 samples/deprecated/vault-api/tokenize-records.ts create mode 100644 samples/deprecated/vault-api/update-record.ts diff --git a/samples/deprecated/detect-api/deidentify-file-with-filepath.ts b/samples/deprecated/detect-api/deidentify-file-with-filepath.ts new file mode 100644 index 00000000..0bd08372 --- /dev/null +++ b/samples/deprecated/detect-api/deidentify-file-with-filepath.ts @@ -0,0 +1,148 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + SkyflowError, + DeidentifyFileRequest, + DeidentifyFileOptions, + DetectEntities, + MaskingMethod, + DetectOutputTranscription, + TokenFormat, + TokenType, + Transformations, + Bleep, + VaultConfig, + DeidentifyFileResponse, + FileInput, + } from 'skyflow-node'; + import fs from 'fs'; + + /** + * Skyflow Deidentify File Example + * + * This sample demonstrates how to use all available options for de-identifying files. + * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. + * + * Note: File de-identification requires Node.js version 20 or above. + */ + + async function performDeidentifyFile() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Deidentify File Request + // Replace with your file object (e.g., from fs.readFileSync or browser File API) + + const filePath: string = ''; + + // Pass wither file object or file path, but not both. + const fileInput: FileInput = { + filePath + } + + const deidentifyFile = new DeidentifyFileRequest(fileInput); + + // Step 5: Configure DeidentifyFileOptions + const options = new DeidentifyFileOptions(); + + // Entities to detect and deidentify + options.setEntities([DetectEntities.SSN, DetectEntities.CREDIT_CARD]); + + // Allowlist regex patterns (entities matching these will NOT be deidentified) + // options.setAllowRegexList(['']); + + // Restrict de-identification to entities matching these regex patterns + // options.setRestrictRegexList(['']); + + // Token format for deidentified entities + const tokenFormat = new TokenFormat(); + tokenFormat.setDefault(TokenType.ENTITY_ONLY); + options.setTokenFormat(tokenFormat); + + // Custom transformations for entities + // const transformations = new Transformations(); // Transformations cannot be applied to Documents, Images, or PDFs file formats. + // transformations.setShiftDays({ + // max: 30, + // min: 10, + // entities: [DetectEntities.SSN], + // }); + // options.setTransformations(transformations); + + // Output directory for saving the deidentified file + // Providing an output directory is not supported in Cloudflare Workers + // options.setOutputDirectory(''); // Replace with your output directory + + // Wait time for response (max 64 seconds) + options.setWaitTime(15); + + // --- Image Options (apply when file is an image) --- + // options.setOutputProcessedImage(true); // Include processed image in output + // options.setOutputOcrText(true); // Include OCR text in response + // options.setMaskingMethod(MaskingMethod.Blackbox); // Masking method for image entities + + // --- PDF Options (apply when file is a PDF) --- + // options.setPixelDensity(1.5); // Pixel density for PDF processing + // options.setMaxResolution(2000); // Max resolution for PDF + + // --- Audio Options (apply when file is audio) --- + // options.setOutputProcessedAudio(true); // Include processed audio in output + // options.setOutputTranscription(DetectOutputTranscription.PLAINTEXT_TRANSCRIPTION); // Type of transcription + + // Bleep audio configuration + // const bleep = new Bleep(); + // bleep.setGain(5); // Loudness in dB + // bleep.setFrequency(1000); // Pitch in Hz + // bleep.setStartPadding(0.1); // Padding at start in seconds + // bleep.setStopPadding(0.2); // Padding at end in seconds + // options.setBleep(bleep); + + + // Step 6: Call deidentifyFile API + const response: DeidentifyFileResponse = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyFile(deidentifyFile, options); + + // Handle Successful Response + console.log('Deidentify File Response:', response); + console.log('Deidentified File:', response.file); + console.log('Deidentified File base64:', response.fileBase64); + + } 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:', JSON.stringify(error)); + } + } + } + + // Invoke the deidentify file function + performDeidentifyFile(); diff --git a/samples/deprecated/detect-api/deidentify-file.ts b/samples/deprecated/detect-api/deidentify-file.ts new file mode 100644 index 00000000..af7aef20 --- /dev/null +++ b/samples/deprecated/detect-api/deidentify-file.ts @@ -0,0 +1,148 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + SkyflowError, + DeidentifyFileRequest, + DeidentifyFileOptions, + DetectEntities, + MaskingMethod, + DetectOutputTranscription, + TokenFormat, + TokenType, + Transformations, + Bleep, + VaultConfig, + DeidentifyFileResponse, + FileInput, +} from 'skyflow-node'; +import fs from 'fs'; + +/** + * Skyflow Deidentify File Example + * + * This sample demonstrates how to use all available options for de-identifying files. + * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. + * + * Note: File de-identification requires Node.js version 20 or above. + */ + +async function performDeidentifyFile() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Deidentify File Request + // Replace with your file object (e.g., from fs.readFileSync or browser File API) + const filePath = ''; + const buffer = fs.readFileSync(filePath); + const file = new File([buffer], filePath); + + // Pass wither file object or file path, but not both. + const fileInput: FileInput = { + file + } + + const deidentifyFile = new DeidentifyFileRequest(fileInput); + + // Step 5: Configure DeidentifyFileOptions + const options = new DeidentifyFileOptions(); + + // Entities to detect and deidentify + options.setEntities([DetectEntities.SSN, DetectEntities.CREDIT_CARD]); + + // Allowlist regex patterns (entities matching these will NOT be deidentified) + // options.setAllowRegexList(['']); + + // Restrict de-identification to entities matching these regex patterns + // options.setRestrictRegexList(['']); + + // Token format for deidentified entities + const tokenFormat = new TokenFormat(); + tokenFormat.setDefault(TokenType.ENTITY_ONLY); + options.setTokenFormat(tokenFormat); + + // Custom transformations for entities + // const transformations = new Transformations(); // Transformations cannot be applied to Documents, Images, or PDFs file formats. + // transformations.setShiftDays({ + // max: 30, + // min: 10, + // entities: [DetectEntities.SSN], + // }); + // options.setTransformations(transformations); + + // Output directory for saving the deidentified file + // options.setOutputDirectory(''); // Replace with your output directory + + // Wait time for response (max 64 seconds) + options.setWaitTime(15); + + // --- Image Options (apply when file is an image) --- + // options.setOutputProcessedImage(true); // Include processed image in output + // options.setOutputOcrText(true); // Include OCR text in response + // options.setMaskingMethod(MaskingMethod.Blackbox); // Masking method for image entities + + // --- PDF Options (apply when file is a PDF) --- + // options.setPixelDensity(1.5); // Pixel density for PDF processing + // options.setMaxResolution(2000); // Max resolution for PDF + + // --- Audio Options (apply when file is audio) --- + // options.setOutputProcessedAudio(true); // Include processed audio in output + // options.setOutputTranscription(DetectOutputTranscription.PLAINTEXT_TRANSCRIPTION); // Type of transcription + + // Bleep audio configuration + // const bleep = new Bleep(); + // bleep.setGain(5); // Loudness in dB + // bleep.setFrequency(1000); // Pitch in Hz + // bleep.setStartPadding(0.1); // Padding at start in seconds + // bleep.setStopPadding(0.2); // Padding at end in seconds + // options.setBleep(bleep); + + + // Step 6: Call deidentifyFile API + const response: DeidentifyFileResponse = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyFile(deidentifyFile, options); + + // Handle Successful Response + console.log('Deidentify File Response:', response); + console.log('Deidentified File:', response.file); + console.log('Deidentified File base64:', response.fileBase64); + + } 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:', JSON.stringify(error)); + } + } +} + +// Invoke the deidentify file function +performDeidentifyFile(); diff --git a/samples/deprecated/detect-api/deidentify-text.ts b/samples/deprecated/detect-api/deidentify-text.ts new file mode 100644 index 00000000..7a068f85 --- /dev/null +++ b/samples/deprecated/detect-api/deidentify-text.ts @@ -0,0 +1,107 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError, + DeidentifyTextRequest, + DeidentifyTextOptions, + TokenFormat, + TokenType, + Transformations, + DetectEntities, + DeidentifyTextResponse +} from 'skyflow-node'; + +/** + * Skyflow Deidentify Text Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a deidentify text request + * 4. Use all available options for de-identification + * 5. Handle response and errors + */ + +async function performDeidentifyText() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials // Authentication method + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Deidentify Text Request + const deidentifyTextRequest = new DeidentifyTextRequest( + 'My SSN is 123-45-6789 and my card is 4111 1111 1111 1111.', // Text to be deidentified + ); + + // Step 5: Configure DeidentifyTextOptions + const options = new DeidentifyTextOptions(); + + // setEntities: Specify which entities to deidentify + options.setEntities([DetectEntities.CREDIT_CARD, DetectEntities.SSN]); + + // setAllowRegexList: Allowlist regex patterns (entities matching these will not be deidentified) + // optionsText.setAllowRegexList(['']); + + // setRestrictRegexList: Restrict de-identification to entities matching these regex patterns + // optionsText.setRestrictRegexList(['']); + + // setTokenFormat: Specify the token format for deidentified entities + const tokenFormat = new TokenFormat(); + tokenFormat.setDefault(TokenType.VAULT_TOKEN); + options.setTokenFormat(tokenFormat); + + // setTransformations: Specify custom transformations for entities + const transformations = new Transformations(); + transformations.setShiftDays({ + max: 30, // Maximum shift days + min: 30, // Minimum shift days + entities: [DetectEntities.DOB], // Entities to apply the shift + }); + options.setTransformations(transformations); + + // Step 6: Call deidentifyText API + const response: DeidentifyTextResponse = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .deidentifyText(deidentifyTextRequest, options); + + // Handle Successful Response + console.log('Deidentify Text Response:', response); + + } 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:', JSON.stringify(error)); + } + } +} + +// Invoke the deidentify text function +performDeidentifyText(); diff --git a/samples/deprecated/detect-api/get-detect-run.ts b/samples/deprecated/detect-api/get-detect-run.ts new file mode 100644 index 00000000..3d53d3d4 --- /dev/null +++ b/samples/deprecated/detect-api/get-detect-run.ts @@ -0,0 +1,76 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError, + GetDetectRunRequest, + DeidentifyFileResponse +} from 'skyflow-node'; + +/** + * Skyflow Get Detect Run Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a get detect run request + * 4. Call getDetectRun to poll for file processing results + * 5. Handle response and errors + */ + +async function performGetDetectRun() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare GetDetectRunRequest + const getDetectRunRequest = new GetDetectRunRequest( + '', + ); + + // Step 5: Call getDetectRun API + const response: DeidentifyFileResponse = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .getDetectRun(getDetectRunRequest); + + // Handle Successful Response + console.log('Get Detect Run Response:', response); + + } 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:', JSON.stringify(error)); + } + } +} + +// Invoke the get detect run function +performGetDetectRun(); diff --git a/samples/deprecated/detect-api/reidentify-text.ts b/samples/deprecated/detect-api/reidentify-text.ts new file mode 100644 index 00000000..8cbe2a96 --- /dev/null +++ b/samples/deprecated/detect-api/reidentify-text.ts @@ -0,0 +1,86 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + ReidentifyTextRequest, + ReidentifyTextOptions, + DetectEntities, + SkyflowError, + ReidentifyTextResponse +} from 'skyflow-node'; + +/** + * Skyflow Reidentify Text Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a reidentify text request + * 4. Use all available options for re-identification + * 5. Handle response and errors + */ + +async function performReidentifyText() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Reidentify Text Request + const reidentifyRequest = new ReidentifyTextRequest( + 'My SSN is [SSN_wNzooo5] and my card is [CREDIT_CARD_nevh1YK].' + ); + + // Step 5: Configure ReidentifyTextOptions + const options = new ReidentifyTextOptions(); + + // Specify which entities to reidentify as redacted, masked, or plain text + options.setRedactedEntities([DetectEntities.NAME, DetectEntities.SSN]); + options.setMaskedEntities([DetectEntities.DOB]); + options.setPlainTextEntities([DetectEntities.PHONE_NUMBER]); + + // Step 6: Call reidentifyText + const response: ReidentifyTextResponse = await skyflowClient + .detect(primaryVaultConfig.vaultId) + .reidentifyText(reidentifyRequest, options); + + // Step 7: Handle response + console.log('Re-identified Text Response:', response); + + } 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:', JSON.stringify(error)); + } + } +} + +// Invoke the reidentify text function +performReidentifyText(); 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/vault-api/client-operations.ts b/samples/deprecated/vault-api/client-operations.ts new file mode 100644 index 00000000..2572233e --- /dev/null +++ b/samples/deprecated/vault-api/client-operations.ts @@ -0,0 +1,91 @@ +import { + Credentials, + DeleteRequest, + Env, + InsertRequest, + InsertOptions, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError, + DeleteResponse, +} from 'skyflow-node'; + +// v1 nomenclature: skyflow_id on insert response, deletedIds null-guard +async function performSecureDataDeletion() { + try { + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.ERROR, + }; + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Config management — unchanged between v1 and v2 + const secondaryVaultConfig: VaultConfig = { + vaultId: 'secondary-vault-id-placeholder', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + skyflowClient.addVaultConfig(secondaryVaultConfig); + console.log('addVaultConfig: ok'); + + skyflowClient.updateVaultConfig({ + vaultId: '', + clusterId: '', + credentials: credentials, + }); + console.log('updateVaultConfig: ok'); + + skyflowClient.removeVaultConfig('secondary-vault-id-placeholder'); + console.log('removeVaultConfig: ok'); + + // Insert then delete (v1: access skyflow_id on insert response) + const insertReq = new InsertRequest('table1', [{ card_number: '4111111111111112' }]); + const insertOpts = new InsertOptions(); + insertOpts.setReturnTokens(false); + const insertResp = await skyflowClient.vault(primaryVaultConfig.vaultId).insert(insertReq, insertOpts); + + // v1: null-guard + skyflow_id (deprecated getter) + if (insertResp.insertedFields != null && insertResp.insertedFields.length > 0) { + const v1Id = (insertResp.insertedFields[0] as any).skyflow_id; + console.log('v1 inserted skyflow_id:', v1Id); + + const deleteRequest: DeleteRequest = new DeleteRequest('table1', [v1Id]); + const response: DeleteResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .delete(deleteRequest); + + // v1: deletedIds null-guard + if (response.deletedIds != null) { + console.log('v1 deletedIds:', response.deletedIds); + } + } + + } 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); + } + } +} + +performSecureDataDeletion(); 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/data-residency.ts b/samples/deprecated/vault-api/data-residency.ts new file mode 100644 index 00000000..df58ffe7 --- /dev/null +++ b/samples/deprecated/vault-api/data-residency.ts @@ -0,0 +1,130 @@ +import { + Credentials, + Env, + GetRequest, + GetOptions, + GetResponse, + InsertRequest, + LogLevel, + RedactionType, + Skyflow, + VaultConfig, + SkyflowConfig, + InsertResponse, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow Vault Data Transfer Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up primary and secondary vault configurations + * 3. Retrieve data from one vault + * 4. Insert data into another vault + * 5. Handle responses and errors + */ +async function transferDataBetweenVaults() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Primary Vault (source) + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials, + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.WARN, + }; + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: (In a real data-residency scenario, addVaultConfig a second vault here) + // For this demo, source and destination are the same vault. + + // Step 5: Get Data from Primary Vault + const getIds: Array = [ + '', + ]; + + const tableName: string = 'table1'; + + 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 + .vault('') + .get(getRequest, getOptions); + + // Step 6: Handle Get Response and Insert Data into Secondary Vault + const getResponseData: GetResponse = getResponse as GetResponse; + + const insertData: Array> = getResponseData.data!; + + // Remove skyflow_id from the data (if needed for re-insertion) + const sanitizedData = insertData.map((item: Record) => { + // Strip skyflowId, deprecated skyflow_id getter, file columns, and nulls before re-insertion + 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 + const insertRequest: InsertRequest = new InsertRequest( + tableName, // Same table name or different as needed + sanitizedData, + ); + + // Perform Insert request on Secondary Vault + const insertResponse: InsertResponse = await skyflowClient + .vault('') + .insert(insertRequest); + + console.log('Data successfully inserted into secondary vault:', insertResponse); + + // v1 backward-compat: skyflow_id deprecated getter on get response + const getRecord = getResponse.data?.[0]; + const v1GetId = (getRecord as any)?.skyflow_id; // fires WARN + console.log('[v1] get skyflow_id :', v1GetId); + console.log('[v2] get skyflowId :', getRecord?.skyflowId); + + // v1 backward-compat: skyflow_id deprecated getter on insert response + const insertField = insertResponse.insertedFields?.[0]; + const v1InsertId = (insertField as any)?.skyflow_id; // fires WARN + console.log('[v1] insert skyflow_id:', v1InsertId); + console.log('[v2] insert skyflowId :', insertField?.skyflowId); + + const getMatch = v1GetId && getRecord?.skyflowId && v1GetId === getRecord.skyflowId; + const insertMatch = v1InsertId && insertField?.skyflowId && v1InsertId === insertField.skyflowId; + console.log('v1/v2 get match :', getMatch ? 'PASS' : 'FAIL'); + console.log('v1/v2 insert match :', insertMatch ? 'PASS' : 'FAIL'); + + } 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 data transfer function +transferDataBetweenVaults(); diff --git a/samples/deprecated/vault-api/delete-records.ts b/samples/deprecated/vault-api/delete-records.ts new file mode 100644 index 00000000..dc5dce19 --- /dev/null +++ b/samples/deprecated/vault-api/delete-records.ts @@ -0,0 +1,70 @@ +import { + Credentials, + DeleteRequest, + DeleteResponse, + Env, + InsertRequest, + InsertOptions, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError, +} from 'skyflow-node'; + +// v1 nomenclature: null/undefined guard on deletedIds (was nullable before SK-2812) +async function performDeletion() { + 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); + + // Insert first so we have a valid ID to delete + const insertReq = new InsertRequest('table1', [{ card_number: '4111111111111112' }]); + const insertOpts = new InsertOptions(); + insertOpts.setReturnTokens(false); + const insertResp = await skyflowClient.vault(primaryVaultConfig.vaultId).insert(insertReq, insertOpts); + const idToDelete: string = insertResp.insertedFields[0].skyflowId; + + const deleteRequest: DeleteRequest = new DeleteRequest('table1', [idToDelete]); + + const response: DeleteResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .delete(deleteRequest); + + // v1: old null-guard pattern (deletedIds was string[] | undefined) + if (response.deletedIds != null && response.deletedIds != undefined) { + console.log('Deletion successful, deletedIds:', response.deletedIds); + for (const id of response.deletedIds) { + console.log('v1 deleted id:', 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); + } + } +} + +performDeletion(); diff --git a/samples/deprecated/vault-api/detokenize-records.ts b/samples/deprecated/vault-api/detokenize-records.ts new file mode 100644 index 00000000..5b924360 --- /dev/null +++ b/samples/deprecated/vault-api/detokenize-records.ts @@ -0,0 +1,79 @@ +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 skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + const detokenizeData: DetokenizeData[] = [ + { + token: '8561-9339-2309-3015', + redactionType: RedactionType.PLAIN_TEXT, + }, + ]; + + const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest(detokenizeData); + + const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions(); + detokenizeOptions.setContinueOnError(true); + + // v1: setDownloadURL uppercase — deprecated getter, still works + (detokenizeOptions as any).setDownloadURL(false); + + 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/detokenzie-records.ts b/samples/deprecated/vault-api/detokenzie-records.ts new file mode 100644 index 00000000..dfe22624 --- /dev/null +++ b/samples/deprecated/vault-api/detokenzie-records.ts @@ -0,0 +1,95 @@ +import { + Credentials, + DetokenizeOptions, + DetokenizeRequest, + DetokenizeResponse, + Env, + LogLevel, + RedactionType, + Skyflow, + SkyflowError, + VaultConfig, + SkyflowConfig, + DetokenizeData, + SkyflowRecordError +} from 'skyflow-node'; + +/** + * Skyflow Detokenization Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a detokenization request + * 4. Handle response and errors + */ +async function performDetokenization() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', // Unique vault identifier + clusterId: '', // From vault URL + env: Env.DEV, // Deployment environment + credentials: credentials // Authentication method + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.ERROR, // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Detokenization Data + const detokenizeData: DetokenizeData[] = [ + { + token: "8561-9339-2309-3015", // Token to be detokenized + redactionType: RedactionType.PLAIN_TEXT, // Redaction type + } + ]; + + // Create Detokenize Request + const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest( + detokenizeData + ); + + // Configure Detokenize Options + const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions(); + detokenizeOptions.setContinueOnError(true); // Continue processing on errors + detokenizeOptions.setDownloadUrl(false); // Disable download URL generation + + // Step 5: Perform Detokenization + const response: DetokenizeResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .detokenize(detokenizeRequest, detokenizeOptions); + + // Handle Successful Response + console.log('Detokenization successful:', response); + if (response.errors != null) { + (response.errors).forEach((error: SkyflowRecordError) => { + console.log('Handle Error:', error.requestIndex, error.token); + }); + } + } 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 detokenization function +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..50d8a84a --- /dev/null +++ b/samples/deprecated/vault-api/file-upload.ts @@ -0,0 +1,66 @@ +// 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, + }; + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // 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', + ); + + 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-column-values.ts b/samples/deprecated/vault-api/get-column-values.ts new file mode 100644 index 00000000..9dd78b7a --- /dev/null +++ b/samples/deprecated/vault-api/get-column-values.ts @@ -0,0 +1,95 @@ +import { + Env, + GetOptions, + LogLevel, + Skyflow, + GetColumnRequest, + Credentials, + SkyflowConfig, + VaultConfig, + SkyflowError, + GetResponse, + GetResponseData +} from 'skyflow-node'; + +/** + * Skyflow Secure Column-Based Retrieval Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a column-based get request + * 4. Handle response and errors + */ +async function performSecureColumnRetrieval() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.WARN, + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Column-Based Retrieval Data + const columnValues: Array = [ + '4111111111111112', + ]; + const tableName: string = 'table1'; + const columnName: string = 'card_number'; + + // Step 5: Create Get Column Request + const getRequest: GetColumnRequest = new GetColumnRequest( + tableName, + columnName, + columnValues // Column values of the records to return + ); + + // Step 6: Configure Get Options + const getOptions: GetOptions = new GetOptions(); + getOptions.setReturnTokens(false); // Column-based lookup returns plaintext values + + // Step 7: Perform Secure Retrieval + const response: GetResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .get(getRequest, getOptions); + + // Handle Successful Response + console.log('Column-based retrieval successful:', response); + if (response.data != null) { + response.data.forEach((record: GetResponseData) => { + console.log("Get data:", record); + // Handle record data + }); + } + + } 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 column retrieval function +performSecureColumnRetrieval(); diff --git a/samples/deprecated/vault-api/get-records.ts b/samples/deprecated/vault-api/get-records.ts new file mode 100644 index 00000000..fdb5ef27 --- /dev/null +++ b/samples/deprecated/vault-api/get-records.ts @@ -0,0 +1,73 @@ +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 skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + const getRequest: GetRequest = new GetRequest('table1', [ + '', + '', + ]); + + const getOptions: GetOptions = new GetOptions(); + getOptions.setReturnTokens(true); + + // v1: setDownloadURL (uppercase — deprecated, still works, emits WARN) + (getOptions as any).setDownloadURL(false); + + 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/insert-byot.ts b/samples/deprecated/vault-api/insert-byot.ts new file mode 100644 index 00000000..b4b0f9c6 --- /dev/null +++ b/samples/deprecated/vault-api/insert-byot.ts @@ -0,0 +1,74 @@ +import { + TokenMode, + Credentials, + Env, + InsertOptions, + InsertRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + InsertResponse, + SkyflowError, +} from 'skyflow-node'; + +// v1 nomenclature: skyflow_id on response (deprecated getter) +async function performSecureDataInsertionWithBYOT() { + 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); + + const insertReq: InsertRequest = new InsertRequest('table1', [ + { card_number: '6011111111111117' }, + ]); + + const tokens: Record[] = [ + { card_number: 'byot-v1-compat-test' }, + ]; + + const insertOptions: InsertOptions = new InsertOptions(); + insertOptions.setReturnTokens(true); + insertOptions.setTokenMode(TokenMode.ENABLE); + insertOptions.setTokens(tokens); + + const response: InsertResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .insert(insertReq, insertOptions); + + // v1: null-guard + skyflow_id access + if (response.insertedFields != null) { + for (const field of response.insertedFields) { + console.log('v1 skyflow_id:', (field as any).skyflow_id); + console.log('v1 field:', field); + } + } + + } 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); + } + } +} + +performSecureDataInsertionWithBYOT(); diff --git a/samples/deprecated/vault-api/insert-continue-on-error.ts b/samples/deprecated/vault-api/insert-continue-on-error.ts new file mode 100644 index 00000000..4c8bbe08 --- /dev/null +++ b/samples/deprecated/vault-api/insert-continue-on-error.ts @@ -0,0 +1,78 @@ +import { + Credentials, + Env, + InsertOptions, + InsertRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError, + InsertResponse, + SkyflowRecordError, +} from 'skyflow-node'; + +// v1 nomenclature: access request_ID on SkyflowRecordError (deprecated getter) +async function performSecureDataInsertion() { + 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); + + const insertReq: InsertRequest = new InsertRequest('table1', [ + { card_number: '4111111111111112' }, + { card_number: '4242424242424242', nonexistent_col: 'bad' }, + ]); + + const insertOptions: InsertOptions = new InsertOptions(); + insertOptions.setReturnTokens(true); + insertOptions.setContinueOnError(true); + + const response: InsertResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .insert(insertReq, insertOptions); + + if (response.insertedFields != null && response.insertedFields.length > 0) { + console.log('Inserted Fields:', response.insertedFields); + // v1: access skyflow_id on inserted fields + for (const field of response.insertedFields) { + console.log('v1 skyflow_id:', (field as any).skyflow_id); + } + } + + if (response.errors != null) { + for (const recordError of response.errors as SkyflowRecordError[]) { + // v1: access request_ID (deprecated getter) + console.log('v1 request_ID:', (recordError as any).request_ID); + console.log('v1 error:', recordError); + } + } + + } 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); + } + } +} + +performSecureDataInsertion(); diff --git a/samples/deprecated/vault-api/insert-records.ts b/samples/deprecated/vault-api/insert-records.ts new file mode 100644 index 00000000..64cd0785 --- /dev/null +++ b/samples/deprecated/vault-api/insert-records.ts @@ -0,0 +1,68 @@ +import { + Credentials, + Env, + InsertOptions, + InsertRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError, + InsertResponse, +} from 'skyflow-node'; + +// v1 nomenclature: accesses skyflow_id (deprecated getter) + null-guards insertedFields +async function performSecureDataInsertion() { + 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); + + const insertReq: InsertRequest = new InsertRequest('table1', [ + { card_number: '4111111111111112' }, + ]); + + const insertOptions: InsertOptions = new InsertOptions(); + insertOptions.setReturnTokens(true); + + const response: InsertResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .insert(insertReq, insertOptions); + + // v1: null-guard insertedFields (was nullable before SK-2812) + if (response.insertedFields != null) { + for (const field of response.insertedFields) { + // v1: access skyflow_id (deprecated getter, now warns but still works) + console.log('v1 skyflow_id:', (field as any).skyflow_id); + console.log('v1 field:', field); + } + } + + } 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); + } + } +} + +performSecureDataInsertion(); diff --git a/samples/deprecated/vault-api/invoke-connection.ts b/samples/deprecated/vault-api/invoke-connection.ts new file mode 100644 index 00000000..d4567509 --- /dev/null +++ b/samples/deprecated/vault-api/invoke-connection.ts @@ -0,0 +1,142 @@ +import { + Credentials, + Env, + InvokeConnectionRequest, + RequestMethod, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + ConnectionConfig, + SkyflowError, + InvokeConnectionResponse +} from 'skyflow-node'; + +/** + * Skyflow Connection Invocation Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault and connection configurations + * 3. Invoke a connection with multiple content-type formats + * 4. Handle response and errors + */ + +const NGROK_BASE = ''; + +async function invokeSkyflowConnection() { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials + }; + + // Step 3: Configure Connections (one per content-type format) + const connectionConfigs: ConnectionConfig[] = [ + { + connectionId: 'conn-json-to-json', + connectionUrl: `${NGROK_BASE}/v1/payment_methods/json`, + credentials: credentials + }, + { + connectionId: 'conn-json-to-xml', + connectionUrl: `${NGROK_BASE}/v1/payment_methods/json-to-xml`, + credentials: credentials + }, + { + connectionId: 'conn-urlencoded-to-json', + connectionUrl: `${NGROK_BASE}/v1/payment_methods/urlencoded-to-json`, + credentials: credentials + }, + { + connectionId: 'conn-xml-to-json', + connectionUrl: `${NGROK_BASE}/v1/payment_methods/xml-to-json`, + credentials: credentials + }, + { + connectionId: 'conn-json-to-urlencoded', + connectionUrl: `${NGROK_BASE}/v1/payment_methods/json-to-urlencoded`, + credentials: credentials + }, + ]; + + // Step 4: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + connectionConfigs: connectionConfigs, + logLevel: LogLevel.INFO + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + const jsonBody: Record = { + card_number: '4111111111111112', + cardholder_name: 'John Doe' + }; + + const tests: Array<{ label: string; connectionId: string; req: InvokeConnectionRequest }> = [ + { + label: 'JSON → JSON', + connectionId: 'conn-json-to-json', + req: new InvokeConnectionRequest(RequestMethod.POST, jsonBody, { 'Content-Type': 'application/json' }) + }, + { + label: 'JSON → XML', + connectionId: 'conn-json-to-xml', + req: new InvokeConnectionRequest(RequestMethod.POST, jsonBody, { 'Content-Type': 'application/json' }) + }, + { + label: 'URL-encoded → JSON', + connectionId: 'conn-urlencoded-to-json', + req: new InvokeConnectionRequest(RequestMethod.POST, jsonBody, { 'Content-Type': 'application/x-www-form-urlencoded' }) + }, + { + label: 'XML → JSON', + connectionId: 'conn-xml-to-json', + req: new InvokeConnectionRequest( + RequestMethod.POST, + '4111111111111112John Doe' as any, + { 'Content-Type': 'application/xml' } + ) + }, + { + label: 'JSON → URL-encoded', + connectionId: 'conn-json-to-urlencoded', + req: new InvokeConnectionRequest(RequestMethod.POST, jsonBody, { 'Content-Type': 'application/json' }) + }, + ]; + + // Step 5: Invoke each connection + for (const test of tests) { + console.log(`\n${'='.repeat(60)}`); + console.log(`[${test.label}]`); + try { + const response: InvokeConnectionResponse = await skyflowClient + .connection(test.connectionId) + .invoke(test.req); + + console.log('Connection invocation successful:', JSON.stringify(response.data, null, 2)); + } 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); + } + } + } +} + +// Invoke the connection function +invokeSkyflowConnection(); diff --git a/samples/deprecated/vault-api/query-records.ts b/samples/deprecated/vault-api/query-records.ts new file mode 100644 index 00000000..7d6016e7 --- /dev/null +++ b/samples/deprecated/vault-api/query-records.ts @@ -0,0 +1,61 @@ +import { + Credentials, + Env, + LogLevel, + QueryRequest, + QueryResponse, + Skyflow, + SkyflowConfig, + SkyflowError, + VaultConfig, +} from 'skyflow-node'; + +// v1 nomenclature: access skyflow_id on query fields (deprecated getter) +async function executeQuery() { + 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); + + const queryRequest: QueryRequest = new QueryRequest('select * from table1 limit 2'); + + const response: QueryResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .query(queryRequest); + + console.log('Query Result:', response); + + response.fields.forEach(record => { + // 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); + } + } +} + +executeQuery(); diff --git a/samples/deprecated/vault-api/tokenize-records.ts b/samples/deprecated/vault-api/tokenize-records.ts new file mode 100644 index 00000000..5e65d85e --- /dev/null +++ b/samples/deprecated/vault-api/tokenize-records.ts @@ -0,0 +1,78 @@ +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + TokenizeRequest, + VaultConfig, + TokenizeRequestType, + TokenizeResponse, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow Tokenization Example + * + * This example demonstrates how to: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Tokenize sensitive data + * 4. Handle response and errors + */ +async function executeTokenization() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + token: 'BEARER_TOKEN', + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', + clusterId: '', + env: Env.DEV, + credentials: credentials + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.WARN, + }; + + // Initialize Skyflow Client + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Prepare Tokenization Data + const tokenizeValues: Array = [ + { value: '4111111111111112', columnGroup: 'cg' }, + { value: '4242424242424242', columnGroup: 'cg' } + ]; + + const tokenReq: TokenizeRequest = new TokenizeRequest(tokenizeValues); + + // Step 5: Execute Tokenization + const response: TokenizeResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .tokenize(tokenReq); + + // Handle Successful Response + console.log('Tokenization Result:', response); + + } 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 tokenization function +executeTokenization(); 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(); From 50449fe1f7f1e34af608eaff8eef6f1d76aa5178 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Fri, 22 May 2026 13:54:10 +0530 Subject: [PATCH 2/5] SK-2841: Updated samples --- .../deidentify-file-with-filepath.ts | 4 +- samples/detect-api/deidentify-file.ts | 4 +- samples/detect-api/deidentify-text.ts | 4 +- samples/detect-api/get-detect-run.ts | 4 +- samples/detect-api/reidentify-text.ts | 4 +- .../bearer-token-expiry-example.ts | 2 +- .../scoped-token-generation-example.ts | 13 +++--- .../signed-token-generation-example.ts | 6 +-- .../token-generation-example.ts | 6 +-- .../token-generation-with-context-example.ts | 8 ++-- samples/vault-api/client-operations.ts | 6 ++- samples/vault-api/credentials-options.ts | 17 ++++---- samples/vault-api/data-residency.ts | 42 ++++++++++++------- samples/vault-api/delete-records.ts | 6 ++- samples/vault-api/detokenzie-records.ts | 4 +- samples/vault-api/file-upload.ts | 16 +++---- samples/vault-api/get-column-values.ts | 4 +- samples/vault-api/get-records.ts | 12 +++++- samples/vault-api/insert-byot.ts | 6 ++- samples/vault-api/insert-continue-on-error.ts | 7 ++-- samples/vault-api/insert-records.ts | 6 ++- samples/vault-api/invoke-connection.ts | 7 ++-- samples/vault-api/query-records.ts | 4 +- samples/vault-api/tokenize-records.ts | 4 +- samples/vault-api/update-record.ts | 7 +++- 25 files changed, 126 insertions(+), 77 deletions(-) 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..46c006ff 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,8 @@ function getScopedBearerTokenFromFilePath() { return new Promise((resolve, reject) => { try { const options = { - roleIDs: ['roleID1', 'roleID2'], + roleIds: ['roleID1', 'roleID2'], + logLevel: LogLevel.WARN, }; if (!isExpired(bearerToken)) resolve(bearerToken); else { @@ -46,7 +48,8 @@ function getScopedBearerTokenFromCreds() { return new Promise((resolve, reject) => { try { const options = { - roleIDs: ['roleID1', 'roleID2'], + roleIds: ['roleID1', 'roleID2'], + 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..33be3ff9 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: '', }; 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..fa61fdef 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 = '/home/aadt/Downloads/credentials (3).json'; 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); From 1e682d52932c7b4723c40d79decdf8fa62b708e5 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Fri, 22 May 2026 14:18:29 +0530 Subject: [PATCH 3/5] SK-2841: Updated remaniing in samples --- .../scoped-token-generation-example.ts | 50 +++++++++++++++++++ .../vault-api/detokenize-records.ts | 14 +++--- samples/deprecated/vault-api/file-upload.ts | 7 ++- samples/deprecated/vault-api/get-records.ts | 14 +++--- 4 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 samples/deprecated/service-account/scoped-token-generation-example.ts 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/detokenize-records.ts b/samples/deprecated/vault-api/detokenize-records.ts index 5b924360..a77d5486 100644 --- a/samples/deprecated/vault-api/detokenize-records.ts +++ b/samples/deprecated/vault-api/detokenize-records.ts @@ -33,6 +33,14 @@ async function performDetokenization() { 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[] = [ @@ -44,12 +52,6 @@ async function performDetokenization() { const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest(detokenizeData); - const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions(); - detokenizeOptions.setContinueOnError(true); - - // v1: setDownloadURL uppercase — deprecated getter, still works - (detokenizeOptions as any).setDownloadURL(false); - const response: DetokenizeResponse = await skyflowClient .vault(primaryVaultConfig.vaultId) .detokenize(detokenizeRequest, detokenizeOptions); diff --git a/samples/deprecated/vault-api/file-upload.ts b/samples/deprecated/vault-api/file-upload.ts index 50d8a84a..017273d9 100644 --- a/samples/deprecated/vault-api/file-upload.ts +++ b/samples/deprecated/vault-api/file-upload.ts @@ -31,8 +31,6 @@ async function performFileUpload() { logLevel: LogLevel.WARN, }; - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - // v1: 3-arg constructor (table, skyflowId, columnName) — deprecated, emits WARN, still works const uploadReq: FileUploadRequest = new FileUploadRequest( 'table1', @@ -40,6 +38,11 @@ async function performFileUpload() { '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 diff --git a/samples/deprecated/vault-api/get-records.ts b/samples/deprecated/vault-api/get-records.ts index fdb5ef27..dc1c08e0 100644 --- a/samples/deprecated/vault-api/get-records.ts +++ b/samples/deprecated/vault-api/get-records.ts @@ -30,6 +30,14 @@ async function performSecureDataRetrieval() { 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', [ @@ -37,12 +45,6 @@ async function performSecureDataRetrieval() { '', ]); - const getOptions: GetOptions = new GetOptions(); - getOptions.setReturnTokens(true); - - // v1: setDownloadURL (uppercase — deprecated, still works, emits WARN) - (getOptions as any).setDownloadURL(false); - const response: GetResponse = await skyflowClient .vault(primaryVaultConfig.vaultId) .get(getRequest, getOptions); From 5f8532836c6c5b59218b060cd6fc81df4222e0f0 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Fri, 22 May 2026 16:45:41 +0530 Subject: [PATCH 4/5] SK-2841: Removed duplicate changes --- .../deidentify-file-with-filepath.ts | 148 ------------------ .../deprecated/detect-api/deidentify-file.ts | 148 ------------------ .../deprecated/detect-api/deidentify-text.ts | 107 ------------- .../deprecated/detect-api/get-detect-run.ts | 76 --------- .../deprecated/detect-api/reidentify-text.ts | 86 ---------- .../deprecated/vault-api/client-operations.ts | 91 ----------- .../deprecated/vault-api/data-residency.ts | 130 --------------- .../deprecated/vault-api/delete-records.ts | 70 --------- .../vault-api/detokenzie-records.ts | 95 ----------- .../deprecated/vault-api/get-column-values.ts | 95 ----------- samples/deprecated/vault-api/insert-byot.ts | 74 --------- .../vault-api/insert-continue-on-error.ts | 78 --------- .../deprecated/vault-api/insert-records.ts | 68 -------- .../deprecated/vault-api/invoke-connection.ts | 142 ----------------- samples/deprecated/vault-api/query-records.ts | 61 -------- .../deprecated/vault-api/tokenize-records.ts | 78 --------- .../scoped-token-generation-example.ts | 2 + .../signed-token-generation-example.ts | 4 +- 18 files changed, 5 insertions(+), 1548 deletions(-) delete mode 100644 samples/deprecated/detect-api/deidentify-file-with-filepath.ts delete mode 100644 samples/deprecated/detect-api/deidentify-file.ts delete mode 100644 samples/deprecated/detect-api/deidentify-text.ts delete mode 100644 samples/deprecated/detect-api/get-detect-run.ts delete mode 100644 samples/deprecated/detect-api/reidentify-text.ts delete mode 100644 samples/deprecated/vault-api/client-operations.ts delete mode 100644 samples/deprecated/vault-api/data-residency.ts delete mode 100644 samples/deprecated/vault-api/delete-records.ts delete mode 100644 samples/deprecated/vault-api/detokenzie-records.ts delete mode 100644 samples/deprecated/vault-api/get-column-values.ts delete mode 100644 samples/deprecated/vault-api/insert-byot.ts delete mode 100644 samples/deprecated/vault-api/insert-continue-on-error.ts delete mode 100644 samples/deprecated/vault-api/insert-records.ts delete mode 100644 samples/deprecated/vault-api/invoke-connection.ts delete mode 100644 samples/deprecated/vault-api/query-records.ts delete mode 100644 samples/deprecated/vault-api/tokenize-records.ts diff --git a/samples/deprecated/detect-api/deidentify-file-with-filepath.ts b/samples/deprecated/detect-api/deidentify-file-with-filepath.ts deleted file mode 100644 index 0bd08372..00000000 --- a/samples/deprecated/detect-api/deidentify-file-with-filepath.ts +++ /dev/null @@ -1,148 +0,0 @@ -import { - Credentials, - Env, - LogLevel, - Skyflow, - SkyflowConfig, - SkyflowError, - DeidentifyFileRequest, - DeidentifyFileOptions, - DetectEntities, - MaskingMethod, - DetectOutputTranscription, - TokenFormat, - TokenType, - Transformations, - Bleep, - VaultConfig, - DeidentifyFileResponse, - FileInput, - } from 'skyflow-node'; - import fs from 'fs'; - - /** - * Skyflow Deidentify File Example - * - * This sample demonstrates how to use all available options for de-identifying files. - * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. - * - * Note: File de-identification requires Node.js version 20 or above. - */ - - async function performDeidentifyFile() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials, - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: Prepare Deidentify File Request - // Replace with your file object (e.g., from fs.readFileSync or browser File API) - - const filePath: string = ''; - - // Pass wither file object or file path, but not both. - const fileInput: FileInput = { - filePath - } - - const deidentifyFile = new DeidentifyFileRequest(fileInput); - - // Step 5: Configure DeidentifyFileOptions - const options = new DeidentifyFileOptions(); - - // Entities to detect and deidentify - options.setEntities([DetectEntities.SSN, DetectEntities.CREDIT_CARD]); - - // Allowlist regex patterns (entities matching these will NOT be deidentified) - // options.setAllowRegexList(['']); - - // Restrict de-identification to entities matching these regex patterns - // options.setRestrictRegexList(['']); - - // Token format for deidentified entities - const tokenFormat = new TokenFormat(); - tokenFormat.setDefault(TokenType.ENTITY_ONLY); - options.setTokenFormat(tokenFormat); - - // Custom transformations for entities - // const transformations = new Transformations(); // Transformations cannot be applied to Documents, Images, or PDFs file formats. - // transformations.setShiftDays({ - // max: 30, - // min: 10, - // entities: [DetectEntities.SSN], - // }); - // options.setTransformations(transformations); - - // Output directory for saving the deidentified file - // Providing an output directory is not supported in Cloudflare Workers - // options.setOutputDirectory(''); // Replace with your output directory - - // Wait time for response (max 64 seconds) - options.setWaitTime(15); - - // --- Image Options (apply when file is an image) --- - // options.setOutputProcessedImage(true); // Include processed image in output - // options.setOutputOcrText(true); // Include OCR text in response - // options.setMaskingMethod(MaskingMethod.Blackbox); // Masking method for image entities - - // --- PDF Options (apply when file is a PDF) --- - // options.setPixelDensity(1.5); // Pixel density for PDF processing - // options.setMaxResolution(2000); // Max resolution for PDF - - // --- Audio Options (apply when file is audio) --- - // options.setOutputProcessedAudio(true); // Include processed audio in output - // options.setOutputTranscription(DetectOutputTranscription.PLAINTEXT_TRANSCRIPTION); // Type of transcription - - // Bleep audio configuration - // const bleep = new Bleep(); - // bleep.setGain(5); // Loudness in dB - // bleep.setFrequency(1000); // Pitch in Hz - // bleep.setStartPadding(0.1); // Padding at start in seconds - // bleep.setStopPadding(0.2); // Padding at end in seconds - // options.setBleep(bleep); - - - // Step 6: Call deidentifyFile API - const response: DeidentifyFileResponse = await skyflowClient - .detect(primaryVaultConfig.vaultId) - .deidentifyFile(deidentifyFile, options); - - // Handle Successful Response - console.log('Deidentify File Response:', response); - console.log('Deidentified File:', response.file); - console.log('Deidentified File base64:', response.fileBase64); - - } 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:', JSON.stringify(error)); - } - } - } - - // Invoke the deidentify file function - performDeidentifyFile(); diff --git a/samples/deprecated/detect-api/deidentify-file.ts b/samples/deprecated/detect-api/deidentify-file.ts deleted file mode 100644 index af7aef20..00000000 --- a/samples/deprecated/detect-api/deidentify-file.ts +++ /dev/null @@ -1,148 +0,0 @@ -import { - Credentials, - Env, - LogLevel, - Skyflow, - SkyflowConfig, - SkyflowError, - DeidentifyFileRequest, - DeidentifyFileOptions, - DetectEntities, - MaskingMethod, - DetectOutputTranscription, - TokenFormat, - TokenType, - Transformations, - Bleep, - VaultConfig, - DeidentifyFileResponse, - FileInput, -} from 'skyflow-node'; -import fs from 'fs'; - -/** - * Skyflow Deidentify File Example - * - * This sample demonstrates how to use all available options for de-identifying files. - * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. - * - * Note: File de-identification requires Node.js version 20 or above. - */ - -async function performDeidentifyFile() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials, - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: Prepare Deidentify File Request - // Replace with your file object (e.g., from fs.readFileSync or browser File API) - const filePath = ''; - const buffer = fs.readFileSync(filePath); - const file = new File([buffer], filePath); - - // Pass wither file object or file path, but not both. - const fileInput: FileInput = { - file - } - - const deidentifyFile = new DeidentifyFileRequest(fileInput); - - // Step 5: Configure DeidentifyFileOptions - const options = new DeidentifyFileOptions(); - - // Entities to detect and deidentify - options.setEntities([DetectEntities.SSN, DetectEntities.CREDIT_CARD]); - - // Allowlist regex patterns (entities matching these will NOT be deidentified) - // options.setAllowRegexList(['']); - - // Restrict de-identification to entities matching these regex patterns - // options.setRestrictRegexList(['']); - - // Token format for deidentified entities - const tokenFormat = new TokenFormat(); - tokenFormat.setDefault(TokenType.ENTITY_ONLY); - options.setTokenFormat(tokenFormat); - - // Custom transformations for entities - // const transformations = new Transformations(); // Transformations cannot be applied to Documents, Images, or PDFs file formats. - // transformations.setShiftDays({ - // max: 30, - // min: 10, - // entities: [DetectEntities.SSN], - // }); - // options.setTransformations(transformations); - - // Output directory for saving the deidentified file - // options.setOutputDirectory(''); // Replace with your output directory - - // Wait time for response (max 64 seconds) - options.setWaitTime(15); - - // --- Image Options (apply when file is an image) --- - // options.setOutputProcessedImage(true); // Include processed image in output - // options.setOutputOcrText(true); // Include OCR text in response - // options.setMaskingMethod(MaskingMethod.Blackbox); // Masking method for image entities - - // --- PDF Options (apply when file is a PDF) --- - // options.setPixelDensity(1.5); // Pixel density for PDF processing - // options.setMaxResolution(2000); // Max resolution for PDF - - // --- Audio Options (apply when file is audio) --- - // options.setOutputProcessedAudio(true); // Include processed audio in output - // options.setOutputTranscription(DetectOutputTranscription.PLAINTEXT_TRANSCRIPTION); // Type of transcription - - // Bleep audio configuration - // const bleep = new Bleep(); - // bleep.setGain(5); // Loudness in dB - // bleep.setFrequency(1000); // Pitch in Hz - // bleep.setStartPadding(0.1); // Padding at start in seconds - // bleep.setStopPadding(0.2); // Padding at end in seconds - // options.setBleep(bleep); - - - // Step 6: Call deidentifyFile API - const response: DeidentifyFileResponse = await skyflowClient - .detect(primaryVaultConfig.vaultId) - .deidentifyFile(deidentifyFile, options); - - // Handle Successful Response - console.log('Deidentify File Response:', response); - console.log('Deidentified File:', response.file); - console.log('Deidentified File base64:', response.fileBase64); - - } 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:', JSON.stringify(error)); - } - } -} - -// Invoke the deidentify file function -performDeidentifyFile(); diff --git a/samples/deprecated/detect-api/deidentify-text.ts b/samples/deprecated/detect-api/deidentify-text.ts deleted file mode 100644 index 7a068f85..00000000 --- a/samples/deprecated/detect-api/deidentify-text.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { - Credentials, - Env, - LogLevel, - Skyflow, - SkyflowConfig, - VaultConfig, - SkyflowError, - DeidentifyTextRequest, - DeidentifyTextOptions, - TokenFormat, - TokenType, - Transformations, - DetectEntities, - DeidentifyTextResponse -} from 'skyflow-node'; - -/** - * Skyflow Deidentify Text Example - * - * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a deidentify text request - * 4. Use all available options for de-identification - * 5. Handle response and errors - */ - -async function performDeidentifyText() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials // Authentication method - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: Prepare Deidentify Text Request - const deidentifyTextRequest = new DeidentifyTextRequest( - 'My SSN is 123-45-6789 and my card is 4111 1111 1111 1111.', // Text to be deidentified - ); - - // Step 5: Configure DeidentifyTextOptions - const options = new DeidentifyTextOptions(); - - // setEntities: Specify which entities to deidentify - options.setEntities([DetectEntities.CREDIT_CARD, DetectEntities.SSN]); - - // setAllowRegexList: Allowlist regex patterns (entities matching these will not be deidentified) - // optionsText.setAllowRegexList(['']); - - // setRestrictRegexList: Restrict de-identification to entities matching these regex patterns - // optionsText.setRestrictRegexList(['']); - - // setTokenFormat: Specify the token format for deidentified entities - const tokenFormat = new TokenFormat(); - tokenFormat.setDefault(TokenType.VAULT_TOKEN); - options.setTokenFormat(tokenFormat); - - // setTransformations: Specify custom transformations for entities - const transformations = new Transformations(); - transformations.setShiftDays({ - max: 30, // Maximum shift days - min: 30, // Minimum shift days - entities: [DetectEntities.DOB], // Entities to apply the shift - }); - options.setTransformations(transformations); - - // Step 6: Call deidentifyText API - const response: DeidentifyTextResponse = await skyflowClient - .detect(primaryVaultConfig.vaultId) - .deidentifyText(deidentifyTextRequest, options); - - // Handle Successful Response - console.log('Deidentify Text Response:', response); - - } 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:', JSON.stringify(error)); - } - } -} - -// Invoke the deidentify text function -performDeidentifyText(); diff --git a/samples/deprecated/detect-api/get-detect-run.ts b/samples/deprecated/detect-api/get-detect-run.ts deleted file mode 100644 index 3d53d3d4..00000000 --- a/samples/deprecated/detect-api/get-detect-run.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { - Credentials, - Env, - LogLevel, - Skyflow, - SkyflowConfig, - VaultConfig, - SkyflowError, - GetDetectRunRequest, - DeidentifyFileResponse -} from 'skyflow-node'; - -/** - * Skyflow Get Detect Run Example - * - * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a get detect run request - * 4. Call getDetectRun to poll for file processing results - * 5. Handle response and errors - */ - -async function performGetDetectRun() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: Prepare GetDetectRunRequest - const getDetectRunRequest = new GetDetectRunRequest( - '', - ); - - // Step 5: Call getDetectRun API - const response: DeidentifyFileResponse = await skyflowClient - .detect(primaryVaultConfig.vaultId) - .getDetectRun(getDetectRunRequest); - - // Handle Successful Response - console.log('Get Detect Run Response:', response); - - } 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:', JSON.stringify(error)); - } - } -} - -// Invoke the get detect run function -performGetDetectRun(); diff --git a/samples/deprecated/detect-api/reidentify-text.ts b/samples/deprecated/detect-api/reidentify-text.ts deleted file mode 100644 index 8cbe2a96..00000000 --- a/samples/deprecated/detect-api/reidentify-text.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { - Credentials, - Env, - LogLevel, - Skyflow, - SkyflowConfig, - VaultConfig, - ReidentifyTextRequest, - ReidentifyTextOptions, - DetectEntities, - SkyflowError, - ReidentifyTextResponse -} from 'skyflow-node'; - -/** - * Skyflow Reidentify Text Example - * - * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a reidentify text request - * 4. Use all available options for re-identification - * 5. Handle response and errors - */ - -async function performReidentifyText() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment. - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: Prepare Reidentify Text Request - const reidentifyRequest = new ReidentifyTextRequest( - 'My SSN is [SSN_wNzooo5] and my card is [CREDIT_CARD_nevh1YK].' - ); - - // Step 5: Configure ReidentifyTextOptions - const options = new ReidentifyTextOptions(); - - // Specify which entities to reidentify as redacted, masked, or plain text - options.setRedactedEntities([DetectEntities.NAME, DetectEntities.SSN]); - options.setMaskedEntities([DetectEntities.DOB]); - options.setPlainTextEntities([DetectEntities.PHONE_NUMBER]); - - // Step 6: Call reidentifyText - const response: ReidentifyTextResponse = await skyflowClient - .detect(primaryVaultConfig.vaultId) - .reidentifyText(reidentifyRequest, options); - - // Step 7: Handle response - console.log('Re-identified Text Response:', response); - - } 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:', JSON.stringify(error)); - } - } -} - -// Invoke the reidentify text function -performReidentifyText(); diff --git a/samples/deprecated/vault-api/client-operations.ts b/samples/deprecated/vault-api/client-operations.ts deleted file mode 100644 index 2572233e..00000000 --- a/samples/deprecated/vault-api/client-operations.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { - Credentials, - DeleteRequest, - Env, - InsertRequest, - InsertOptions, - LogLevel, - Skyflow, - VaultConfig, - SkyflowConfig, - SkyflowError, - DeleteResponse, -} from 'skyflow-node'; - -// v1 nomenclature: skyflow_id on insert response, deletedIds null-guard -async function performSecureDataDeletion() { - try { - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials, - }; - - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.ERROR, - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Config management — unchanged between v1 and v2 - const secondaryVaultConfig: VaultConfig = { - vaultId: 'secondary-vault-id-placeholder', - clusterId: '', - env: Env.DEV, - credentials: credentials, - }; - skyflowClient.addVaultConfig(secondaryVaultConfig); - console.log('addVaultConfig: ok'); - - skyflowClient.updateVaultConfig({ - vaultId: '', - clusterId: '', - credentials: credentials, - }); - console.log('updateVaultConfig: ok'); - - skyflowClient.removeVaultConfig('secondary-vault-id-placeholder'); - console.log('removeVaultConfig: ok'); - - // Insert then delete (v1: access skyflow_id on insert response) - const insertReq = new InsertRequest('table1', [{ card_number: '4111111111111112' }]); - const insertOpts = new InsertOptions(); - insertOpts.setReturnTokens(false); - const insertResp = await skyflowClient.vault(primaryVaultConfig.vaultId).insert(insertReq, insertOpts); - - // v1: null-guard + skyflow_id (deprecated getter) - if (insertResp.insertedFields != null && insertResp.insertedFields.length > 0) { - const v1Id = (insertResp.insertedFields[0] as any).skyflow_id; - console.log('v1 inserted skyflow_id:', v1Id); - - const deleteRequest: DeleteRequest = new DeleteRequest('table1', [v1Id]); - const response: DeleteResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .delete(deleteRequest); - - // v1: deletedIds null-guard - if (response.deletedIds != null) { - console.log('v1 deletedIds:', response.deletedIds); - } - } - - } 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); - } - } -} - -performSecureDataDeletion(); diff --git a/samples/deprecated/vault-api/data-residency.ts b/samples/deprecated/vault-api/data-residency.ts deleted file mode 100644 index df58ffe7..00000000 --- a/samples/deprecated/vault-api/data-residency.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { - Credentials, - Env, - GetRequest, - GetOptions, - GetResponse, - InsertRequest, - LogLevel, - RedactionType, - Skyflow, - VaultConfig, - SkyflowConfig, - InsertResponse, - SkyflowError -} from 'skyflow-node'; - -/** - * Skyflow Vault Data Transfer Example - * - * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up primary and secondary vault configurations - * 3. Retrieve data from one vault - * 4. Insert data into another vault - * 5. Handle responses and errors - */ -async function transferDataBetweenVaults() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Primary Vault (source) - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials, - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.WARN, - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: (In a real data-residency scenario, addVaultConfig a second vault here) - // For this demo, source and destination are the same vault. - - // Step 5: Get Data from Primary Vault - const getIds: Array = [ - '', - ]; - - const tableName: string = 'table1'; - - 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 - .vault('') - .get(getRequest, getOptions); - - // Step 6: Handle Get Response and Insert Data into Secondary Vault - const getResponseData: GetResponse = getResponse as GetResponse; - - const insertData: Array> = getResponseData.data!; - - // Remove skyflow_id from the data (if needed for re-insertion) - const sanitizedData = insertData.map((item: Record) => { - // Strip skyflowId, deprecated skyflow_id getter, file columns, and nulls before re-insertion - 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 - const insertRequest: InsertRequest = new InsertRequest( - tableName, // Same table name or different as needed - sanitizedData, - ); - - // Perform Insert request on Secondary Vault - const insertResponse: InsertResponse = await skyflowClient - .vault('') - .insert(insertRequest); - - console.log('Data successfully inserted into secondary vault:', insertResponse); - - // v1 backward-compat: skyflow_id deprecated getter on get response - const getRecord = getResponse.data?.[0]; - const v1GetId = (getRecord as any)?.skyflow_id; // fires WARN - console.log('[v1] get skyflow_id :', v1GetId); - console.log('[v2] get skyflowId :', getRecord?.skyflowId); - - // v1 backward-compat: skyflow_id deprecated getter on insert response - const insertField = insertResponse.insertedFields?.[0]; - const v1InsertId = (insertField as any)?.skyflow_id; // fires WARN - console.log('[v1] insert skyflow_id:', v1InsertId); - console.log('[v2] insert skyflowId :', insertField?.skyflowId); - - const getMatch = v1GetId && getRecord?.skyflowId && v1GetId === getRecord.skyflowId; - const insertMatch = v1InsertId && insertField?.skyflowId && v1InsertId === insertField.skyflowId; - console.log('v1/v2 get match :', getMatch ? 'PASS' : 'FAIL'); - console.log('v1/v2 insert match :', insertMatch ? 'PASS' : 'FAIL'); - - } 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 data transfer function -transferDataBetweenVaults(); diff --git a/samples/deprecated/vault-api/delete-records.ts b/samples/deprecated/vault-api/delete-records.ts deleted file mode 100644 index dc5dce19..00000000 --- a/samples/deprecated/vault-api/delete-records.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { - Credentials, - DeleteRequest, - DeleteResponse, - Env, - InsertRequest, - InsertOptions, - LogLevel, - Skyflow, - SkyflowConfig, - VaultConfig, - SkyflowError, -} from 'skyflow-node'; - -// v1 nomenclature: null/undefined guard on deletedIds (was nullable before SK-2812) -async function performDeletion() { - 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); - - // Insert first so we have a valid ID to delete - const insertReq = new InsertRequest('table1', [{ card_number: '4111111111111112' }]); - const insertOpts = new InsertOptions(); - insertOpts.setReturnTokens(false); - const insertResp = await skyflowClient.vault(primaryVaultConfig.vaultId).insert(insertReq, insertOpts); - const idToDelete: string = insertResp.insertedFields[0].skyflowId; - - const deleteRequest: DeleteRequest = new DeleteRequest('table1', [idToDelete]); - - const response: DeleteResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .delete(deleteRequest); - - // v1: old null-guard pattern (deletedIds was string[] | undefined) - if (response.deletedIds != null && response.deletedIds != undefined) { - console.log('Deletion successful, deletedIds:', response.deletedIds); - for (const id of response.deletedIds) { - console.log('v1 deleted id:', 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); - } - } -} - -performDeletion(); diff --git a/samples/deprecated/vault-api/detokenzie-records.ts b/samples/deprecated/vault-api/detokenzie-records.ts deleted file mode 100644 index dfe22624..00000000 --- a/samples/deprecated/vault-api/detokenzie-records.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { - Credentials, - DetokenizeOptions, - DetokenizeRequest, - DetokenizeResponse, - Env, - LogLevel, - RedactionType, - Skyflow, - SkyflowError, - VaultConfig, - SkyflowConfig, - DetokenizeData, - SkyflowRecordError -} from 'skyflow-node'; - -/** - * Skyflow Detokenization Example - * - * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a detokenization request - * 4. Handle response and errors - */ -async function performDetokenization() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', // Unique vault identifier - clusterId: '', // From vault URL - env: Env.DEV, // Deployment environment - credentials: credentials // Authentication method - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.ERROR, // Logging verbosity - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: Prepare Detokenization Data - const detokenizeData: DetokenizeData[] = [ - { - token: "8561-9339-2309-3015", // Token to be detokenized - redactionType: RedactionType.PLAIN_TEXT, // Redaction type - } - ]; - - // Create Detokenize Request - const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest( - detokenizeData - ); - - // Configure Detokenize Options - const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions(); - detokenizeOptions.setContinueOnError(true); // Continue processing on errors - detokenizeOptions.setDownloadUrl(false); // Disable download URL generation - - // Step 5: Perform Detokenization - const response: DetokenizeResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .detokenize(detokenizeRequest, detokenizeOptions); - - // Handle Successful Response - console.log('Detokenization successful:', response); - if (response.errors != null) { - (response.errors).forEach((error: SkyflowRecordError) => { - console.log('Handle Error:', error.requestIndex, error.token); - }); - } - } 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 detokenization function -performDetokenization(); diff --git a/samples/deprecated/vault-api/get-column-values.ts b/samples/deprecated/vault-api/get-column-values.ts deleted file mode 100644 index 9dd78b7a..00000000 --- a/samples/deprecated/vault-api/get-column-values.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { - Env, - GetOptions, - LogLevel, - Skyflow, - GetColumnRequest, - Credentials, - SkyflowConfig, - VaultConfig, - SkyflowError, - GetResponse, - GetResponseData -} from 'skyflow-node'; - -/** - * Skyflow Secure Column-Based Retrieval Example - * - * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a column-based get request - * 4. Handle response and errors - */ -async function performSecureColumnRetrieval() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.WARN, - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: Prepare Column-Based Retrieval Data - const columnValues: Array = [ - '4111111111111112', - ]; - const tableName: string = 'table1'; - const columnName: string = 'card_number'; - - // Step 5: Create Get Column Request - const getRequest: GetColumnRequest = new GetColumnRequest( - tableName, - columnName, - columnValues // Column values of the records to return - ); - - // Step 6: Configure Get Options - const getOptions: GetOptions = new GetOptions(); - getOptions.setReturnTokens(false); // Column-based lookup returns plaintext values - - // Step 7: Perform Secure Retrieval - const response: GetResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .get(getRequest, getOptions); - - // Handle Successful Response - console.log('Column-based retrieval successful:', response); - if (response.data != null) { - response.data.forEach((record: GetResponseData) => { - console.log("Get data:", record); - // Handle record data - }); - } - - } 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 column retrieval function -performSecureColumnRetrieval(); diff --git a/samples/deprecated/vault-api/insert-byot.ts b/samples/deprecated/vault-api/insert-byot.ts deleted file mode 100644 index b4b0f9c6..00000000 --- a/samples/deprecated/vault-api/insert-byot.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - TokenMode, - Credentials, - Env, - InsertOptions, - InsertRequest, - LogLevel, - Skyflow, - VaultConfig, - SkyflowConfig, - InsertResponse, - SkyflowError, -} from 'skyflow-node'; - -// v1 nomenclature: skyflow_id on response (deprecated getter) -async function performSecureDataInsertionWithBYOT() { - 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); - - const insertReq: InsertRequest = new InsertRequest('table1', [ - { card_number: '6011111111111117' }, - ]); - - const tokens: Record[] = [ - { card_number: 'byot-v1-compat-test' }, - ]; - - const insertOptions: InsertOptions = new InsertOptions(); - insertOptions.setReturnTokens(true); - insertOptions.setTokenMode(TokenMode.ENABLE); - insertOptions.setTokens(tokens); - - const response: InsertResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .insert(insertReq, insertOptions); - - // v1: null-guard + skyflow_id access - if (response.insertedFields != null) { - for (const field of response.insertedFields) { - console.log('v1 skyflow_id:', (field as any).skyflow_id); - console.log('v1 field:', field); - } - } - - } 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); - } - } -} - -performSecureDataInsertionWithBYOT(); diff --git a/samples/deprecated/vault-api/insert-continue-on-error.ts b/samples/deprecated/vault-api/insert-continue-on-error.ts deleted file mode 100644 index 4c8bbe08..00000000 --- a/samples/deprecated/vault-api/insert-continue-on-error.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { - Credentials, - Env, - InsertOptions, - InsertRequest, - LogLevel, - Skyflow, - VaultConfig, - SkyflowConfig, - SkyflowError, - InsertResponse, - SkyflowRecordError, -} from 'skyflow-node'; - -// v1 nomenclature: access request_ID on SkyflowRecordError (deprecated getter) -async function performSecureDataInsertion() { - 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); - - const insertReq: InsertRequest = new InsertRequest('table1', [ - { card_number: '4111111111111112' }, - { card_number: '4242424242424242', nonexistent_col: 'bad' }, - ]); - - const insertOptions: InsertOptions = new InsertOptions(); - insertOptions.setReturnTokens(true); - insertOptions.setContinueOnError(true); - - const response: InsertResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .insert(insertReq, insertOptions); - - if (response.insertedFields != null && response.insertedFields.length > 0) { - console.log('Inserted Fields:', response.insertedFields); - // v1: access skyflow_id on inserted fields - for (const field of response.insertedFields) { - console.log('v1 skyflow_id:', (field as any).skyflow_id); - } - } - - if (response.errors != null) { - for (const recordError of response.errors as SkyflowRecordError[]) { - // v1: access request_ID (deprecated getter) - console.log('v1 request_ID:', (recordError as any).request_ID); - console.log('v1 error:', recordError); - } - } - - } 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); - } - } -} - -performSecureDataInsertion(); diff --git a/samples/deprecated/vault-api/insert-records.ts b/samples/deprecated/vault-api/insert-records.ts deleted file mode 100644 index 64cd0785..00000000 --- a/samples/deprecated/vault-api/insert-records.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { - Credentials, - Env, - InsertOptions, - InsertRequest, - LogLevel, - Skyflow, - VaultConfig, - SkyflowConfig, - SkyflowError, - InsertResponse, -} from 'skyflow-node'; - -// v1 nomenclature: accesses skyflow_id (deprecated getter) + null-guards insertedFields -async function performSecureDataInsertion() { - 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); - - const insertReq: InsertRequest = new InsertRequest('table1', [ - { card_number: '4111111111111112' }, - ]); - - const insertOptions: InsertOptions = new InsertOptions(); - insertOptions.setReturnTokens(true); - - const response: InsertResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .insert(insertReq, insertOptions); - - // v1: null-guard insertedFields (was nullable before SK-2812) - if (response.insertedFields != null) { - for (const field of response.insertedFields) { - // v1: access skyflow_id (deprecated getter, now warns but still works) - console.log('v1 skyflow_id:', (field as any).skyflow_id); - console.log('v1 field:', field); - } - } - - } 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); - } - } -} - -performSecureDataInsertion(); diff --git a/samples/deprecated/vault-api/invoke-connection.ts b/samples/deprecated/vault-api/invoke-connection.ts deleted file mode 100644 index d4567509..00000000 --- a/samples/deprecated/vault-api/invoke-connection.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { - Credentials, - Env, - InvokeConnectionRequest, - RequestMethod, - LogLevel, - Skyflow, - VaultConfig, - SkyflowConfig, - ConnectionConfig, - SkyflowError, - InvokeConnectionResponse -} from 'skyflow-node'; - -/** - * Skyflow Connection Invocation Example - * - * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault and connection configurations - * 3. Invoke a connection with multiple content-type formats - * 4. Handle response and errors - */ - -const NGROK_BASE = ''; - -async function invokeSkyflowConnection() { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials - }; - - // Step 3: Configure Connections (one per content-type format) - const connectionConfigs: ConnectionConfig[] = [ - { - connectionId: 'conn-json-to-json', - connectionUrl: `${NGROK_BASE}/v1/payment_methods/json`, - credentials: credentials - }, - { - connectionId: 'conn-json-to-xml', - connectionUrl: `${NGROK_BASE}/v1/payment_methods/json-to-xml`, - credentials: credentials - }, - { - connectionId: 'conn-urlencoded-to-json', - connectionUrl: `${NGROK_BASE}/v1/payment_methods/urlencoded-to-json`, - credentials: credentials - }, - { - connectionId: 'conn-xml-to-json', - connectionUrl: `${NGROK_BASE}/v1/payment_methods/xml-to-json`, - credentials: credentials - }, - { - connectionId: 'conn-json-to-urlencoded', - connectionUrl: `${NGROK_BASE}/v1/payment_methods/json-to-urlencoded`, - credentials: credentials - }, - ]; - - // Step 4: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - connectionConfigs: connectionConfigs, - logLevel: LogLevel.INFO - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - const jsonBody: Record = { - card_number: '4111111111111112', - cardholder_name: 'John Doe' - }; - - const tests: Array<{ label: string; connectionId: string; req: InvokeConnectionRequest }> = [ - { - label: 'JSON → JSON', - connectionId: 'conn-json-to-json', - req: new InvokeConnectionRequest(RequestMethod.POST, jsonBody, { 'Content-Type': 'application/json' }) - }, - { - label: 'JSON → XML', - connectionId: 'conn-json-to-xml', - req: new InvokeConnectionRequest(RequestMethod.POST, jsonBody, { 'Content-Type': 'application/json' }) - }, - { - label: 'URL-encoded → JSON', - connectionId: 'conn-urlencoded-to-json', - req: new InvokeConnectionRequest(RequestMethod.POST, jsonBody, { 'Content-Type': 'application/x-www-form-urlencoded' }) - }, - { - label: 'XML → JSON', - connectionId: 'conn-xml-to-json', - req: new InvokeConnectionRequest( - RequestMethod.POST, - '4111111111111112John Doe' as any, - { 'Content-Type': 'application/xml' } - ) - }, - { - label: 'JSON → URL-encoded', - connectionId: 'conn-json-to-urlencoded', - req: new InvokeConnectionRequest(RequestMethod.POST, jsonBody, { 'Content-Type': 'application/json' }) - }, - ]; - - // Step 5: Invoke each connection - for (const test of tests) { - console.log(`\n${'='.repeat(60)}`); - console.log(`[${test.label}]`); - try { - const response: InvokeConnectionResponse = await skyflowClient - .connection(test.connectionId) - .invoke(test.req); - - console.log('Connection invocation successful:', JSON.stringify(response.data, null, 2)); - } 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); - } - } - } -} - -// Invoke the connection function -invokeSkyflowConnection(); diff --git a/samples/deprecated/vault-api/query-records.ts b/samples/deprecated/vault-api/query-records.ts deleted file mode 100644 index 7d6016e7..00000000 --- a/samples/deprecated/vault-api/query-records.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { - Credentials, - Env, - LogLevel, - QueryRequest, - QueryResponse, - Skyflow, - SkyflowConfig, - SkyflowError, - VaultConfig, -} from 'skyflow-node'; - -// v1 nomenclature: access skyflow_id on query fields (deprecated getter) -async function executeQuery() { - 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); - - const queryRequest: QueryRequest = new QueryRequest('select * from table1 limit 2'); - - const response: QueryResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .query(queryRequest); - - console.log('Query Result:', response); - - response.fields.forEach(record => { - // 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); - } - } -} - -executeQuery(); diff --git a/samples/deprecated/vault-api/tokenize-records.ts b/samples/deprecated/vault-api/tokenize-records.ts deleted file mode 100644 index 5e65d85e..00000000 --- a/samples/deprecated/vault-api/tokenize-records.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { - Credentials, - Env, - LogLevel, - Skyflow, - SkyflowConfig, - TokenizeRequest, - VaultConfig, - TokenizeRequestType, - TokenizeResponse, - SkyflowError -} from 'skyflow-node'; - -/** - * Skyflow Tokenization Example - * - * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Tokenize sensitive data - * 4. Handle response and errors - */ -async function executeTokenization() { - try { - // Step 1: Configure Credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', - }; - - // Step 2: Configure Vault - const primaryVaultConfig: VaultConfig = { - vaultId: '', - clusterId: '', - env: Env.DEV, - credentials: credentials - }; - - // Step 3: Configure Skyflow Client - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [primaryVaultConfig], - logLevel: LogLevel.WARN, - }; - - // Initialize Skyflow Client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // Step 4: Prepare Tokenization Data - const tokenizeValues: Array = [ - { value: '4111111111111112', columnGroup: 'cg' }, - { value: '4242424242424242', columnGroup: 'cg' } - ]; - - const tokenReq: TokenizeRequest = new TokenizeRequest(tokenizeValues); - - // Step 5: Execute Tokenization - const response: TokenizeResponse = await skyflowClient - .vault(primaryVaultConfig.vaultId) - .tokenize(tokenReq); - - // Handle Successful Response - console.log('Tokenization Result:', response); - - } 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 tokenization function -executeTokenization(); diff --git a/samples/service-account/scoped-token-generation-example.ts b/samples/service-account/scoped-token-generation-example.ts index 46c006ff..97746f3b 100644 --- a/samples/service-account/scoped-token-generation-example.ts +++ b/samples/service-account/scoped-token-generation-example.ts @@ -25,6 +25,7 @@ function getScopedBearerTokenFromFilePath() { try { const options = { roleIds: ['roleID1', 'roleID2'], + tokenUri: '', // optional: overrides tokenUri from credentials file logLevel: LogLevel.WARN, }; if (!isExpired(bearerToken)) resolve(bearerToken); @@ -49,6 +50,7 @@ function getScopedBearerTokenFromCreds() { try { const options = { roleIds: ['roleID1', 'roleID2'], + tokenUri: '', // optional: overrides tokenUri from credentials string logLevel: LogLevel.WARN, }; if (!isExpired(bearerToken)) resolve(bearerToken); diff --git a/samples/service-account/signed-token-generation-example.ts b/samples/service-account/signed-token-generation-example.ts index 33be3ff9..071573fb 100644 --- a/samples/service-account/signed-token-generation-example.ts +++ b/samples/service-account/signed-token-generation-example.ts @@ -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), From 9c51cb9527397819f1f010dcd7ea625781ff5f01 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Fri, 22 May 2026 16:53:35 +0530 Subject: [PATCH 5/5] SK-2841: Updated placeholder --- .../service-account/token-generation-with-context-example.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/service-account/token-generation-with-context-example.ts b/samples/service-account/token-generation-with-context-example.ts index fa61fdef..86e80868 100644 --- a/samples/service-account/token-generation-with-context-example.ts +++ b/samples/service-account/token-generation-with-context-example.ts @@ -7,7 +7,7 @@ import { isExpired, } from 'skyflow-node'; -const filepath: string = '/home/aadt/Downloads/credentials (3).json'; +const filepath: string = ''; let bearerToken: string = ''; // To generate Bearer Token from credentials string.