-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrepl.js
32 lines (25 loc) · 1.05 KB
/
repl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as repl from 'node:repl';
import { auth, Client, webln } from "./dist/index.module.js";
import 'websocket-polyfill';
try {
globalThis.crypto = await import('node:crypto');
} catch (err) {
console.error('crypto not found!');
}
const authClient = new auth.OAuth2User({
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
callback: "http://localhost:8080/callback",
scopes: ["invoices:read", "account:read", "balance:read", "invoices:create", "invoices:read", "payments:send"],
token: { access_token: process.env.ACCESS_TOKEN, refresh_token: process.env.REFRESH_TOKEN, expires_at: undefined } // initialize with existing token
});
console.log('Welcome to the alby-js-sdk REPL');
if (!process.env.CLIENT_ID) {
console.log("Configure the environment variable `CLIENT_ID` and option; `CLIENT_SECRET`, `ACCESS_TOKEN`");
process.exit();
}
console.log('use `authClient` and `alby` (the client)');
const r = repl.start('> ');
r.context.webln = webln;
r.context.authClient = authClient;
r.context.alby = new Client(authClient);