-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CI and extended token store functionality (#2)
* initial typescript setup * gotten tests to work * created token store * added alby wallet * tested axios interceptor wrapper * chore: update copyright year in LICENSE file * refactor: remove sample.spec.js test file * chore: Update launch.json and package.json refactor: added method + hostname functionality to token store. * added github actions. * initial typescript setup * gotten tests to work * added alby wallet * tested axios interceptor wrapper * refactor: remove sample.spec.js test file * chore: Update launch.json and package.json refactor: added method + hostname functionality to token store. * added github actions. --------- Co-authored-by: Samuel Alarco <[email protected]>
- Loading branch information
Showing
11 changed files
with
2,178 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: CI Workflow | ||
|
||
on: | ||
# Run on pull requests to any branch | ||
pull_request: | ||
branches: | ||
- '*' | ||
|
||
# Run on any push to the main branch | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-test: | ||
name: Build and Test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
||
- name: Generate coverage report | ||
run: | | ||
npm install -g nyc | ||
nyc report --reporter=text --reporter=html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"all": true, | ||
"include": ["dist/**/*.js"], | ||
"exclude": ["dist/**/*.test.js", "**/test/**"], | ||
"extension": [".js"], | ||
"reporter": ["text", "html"], | ||
"sourceMap": false, | ||
"instrument": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Import required dependencies | ||
const axios = require('axios'); | ||
const { setupL402Interceptor, AlbyWallet, MemoryTokenStore } = require('../dist'); // Adjust path to your interceptor file | ||
const { Client } = require('@getalby/sdk'); | ||
require('dotenv').config(); | ||
|
||
// Load the Alby token from an environment variable | ||
const albyToken = process.env.ALBY_BEARER_TOKEN; | ||
if (!albyToken) { | ||
console.error('Missing ALBY_BEARER_TOKEN environment variable.'); | ||
process.exit(1); | ||
} | ||
|
||
const albyClient = new Client(albyToken) | ||
|
||
// Initialize the AlbyWallet using the bearer token | ||
const albyWallet = new AlbyWallet(albyClient); | ||
|
||
// Initialize the MemoryTokenStore | ||
const store = new MemoryTokenStore(); | ||
|
||
// Create an Axios instance and configure it with the L402 interceptor | ||
const axiosInstance = axios.create({ | ||
baseURL: 'https://rnd.ln.sulu.sh', | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
|
||
// Set up the L402 interceptor with the real Alby wallet and token store | ||
setupL402Interceptor(axiosInstance, albyWallet, store); | ||
|
||
// Function to fetch a random number using the configured Axios instance | ||
async function fetchRandomNumber() { | ||
try { | ||
// Make a GET request to the random number API | ||
const response = await axiosInstance.get('/randomnumber'); | ||
console.log('Random Number:', response.data); | ||
} catch (error) { | ||
// Handle errors gracefully | ||
if (axios.isAxiosError(error)) { | ||
console.error('Axios Error:', error.message, error.response?.status); | ||
} else { | ||
console.error('Unknown Error:', error); | ||
} | ||
} | ||
} | ||
|
||
// Execute the function to fetch the random number | ||
fetchRandomNumber(); |
Oops, something went wrong.