From 61c6b5f6d53f00f5f884c951ad907573cb24944d Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Fri, 1 Sep 2023 16:25:45 -0600 Subject: [PATCH] chore: update examples, add file posting to index.cjs --- examples/node/index.cjs | 17 ++++++++++++++++- examples/node/index.mjs | 10 +++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/node/index.cjs b/examples/node/index.cjs index 16f66251..b2b62a38 100644 --- a/examples/node/index.cjs +++ b/examples/node/index.cjs @@ -3,6 +3,8 @@ const { TurboFactory, TurboUnauthenticatedPaymentService } = await import( '../../lib/index.js' ); + const path = require('path'); + const fs = require('fs'); /** * Fetching rates using an unauthenticated Turbo client. */ @@ -51,11 +53,24 @@ ); /** - * Fetch the estimated amount of winc returned for $1 USD + * Fetch the estimated amount of winc returned for 10 USD (1000 cents). */ const estimatedWinc = await turboAuthClient.getWincForFiat({ amount: 1000, currency: 'usd', }); console.log('10 USD to winc:', estimatedWinc); + + /** + * Post local files to the Turbo service. + */ + console.log('Posting raw files to Turbo service...'); + const filePaths = [path.join(__dirname, './files/0_kb.txt')]; + const fileStreamGenerators = filePaths.map( + (filePath) => () => fs.createReadStream(filePath), + ); + const uploadResult = await turboAuthClient.uploadFiles({ + fileStreamGenerators: fileStreamGenerators, + }); + console.log(JSON.stringify(uploadResult, null, 2)); })(); diff --git a/examples/node/index.mjs b/examples/node/index.mjs index b855a227..16ffeef2 100644 --- a/examples/node/index.mjs +++ b/examples/node/index.mjs @@ -47,7 +47,7 @@ import { ); /** - * Fetch the estimated amount of winc returned for 10 USD (1000 cents) + * Fetch the estimated amount of winc returned for 10 USD (1000 cents). */ const estimatedWinc = await turboAuthClient.getWincForFiat({ amount: 1000, @@ -56,12 +56,12 @@ import { console.log('10 USD to winc:', estimatedWinc); /** - * Post some local raw files to the Turbo service. + * Post local files to the Turbo service. */ console.log('Posting raw files to Turbo service...'); - const files = [new URL('files/0_kb.txt', import.meta.url).pathname]; - const fileStreamGenerators = files.map( - (file) => () => fs.createReadStream(file), + const filePaths = [new URL('files/0_kb.txt', import.meta.url).pathname]; + const fileStreamGenerators = filePaths.map( + (filePath) => () => fs.createReadStream(filePath), ); const uploadResult = await turboAuthClient.uploadFiles({ fileStreamGenerators: fileStreamGenerators,