Skip to content

Commit

Permalink
Merge pull request #68 from pavanjoshi914/format-sdk
Browse files Browse the repository at this point in the history
format files with prettier
  • Loading branch information
rolznz authored Aug 18, 2023
2 parents 59b898a + 556cb2d commit 73d1d5c
Show file tree
Hide file tree
Showing 27 changed files with 617 additions and 375 deletions.
232 changes: 145 additions & 87 deletions README.md

Large diffs are not rendered by default.

66 changes: 40 additions & 26 deletions examples/boostagram.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { auth, Client } from "../dist/index.module.js";

Expand All @@ -9,43 +9,57 @@ 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: undefined, refresh_token: undefined, expires_at: undefined } // initialize with existing token
scopes: [
"invoices:read",
"account:read",
"balance:read",
"invoices:create",
"invoices:read",
"payments:send",
],
token: {
access_token: undefined,
refresh_token: undefined,
expires_at: undefined,
}, // initialize with existing token
});

console.log(`Open the following URL and authenticate the app:`);
console.log(authClient.generateAuthURL());
console.log("----\n");

const code = await rl.question('Code: (localhost:8080?code=[THIS CODE]: ');
const code = await rl.question("Code: (localhost:8080?code=[THIS CODE]: ");
rl.close();

await authClient.requestAccessToken(code);
console.log(authClient.token);
const client = new Client(authClient);

// use an array if you want to send multiple boostagrams with one call
const response = await client.sendBoostagram([{
recipient: {
address: '030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3',
customKey: '696969',
customValue: 'bNVHj0WZ0aLPPAesnn9M'
const response = await client.sendBoostagram([
{
recipient: {
address:
"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",
customKey: "696969",
customValue: "bNVHj0WZ0aLPPAesnn9M",
},
amount: 10,
// spec: https://github.com/lightning/blips/blob/master/blip-0010.md
boostagram: {
app_name: "Alby SDK Demo",
value_msat_total: 49960, // TOTAL Number of millisats for the payment (all splits together, before fees. The actual number someone entered in their player, for numerology purposes.)
value_msat: 2121, // Number of millisats for this split payment
url: "https://feeds.buzzsprout.com/xxx.rss",
podcast: "Podcast title",
action: "boost",
episode: "The episode title",
episode_guid: "Buzzsprout-xxx",
ts: 574,
name: "Podcaster - the recipient name",
sender_name: "Satoshi - the sender/listener name",
},
},
amount: 10,
// spec: https://github.com/lightning/blips/blob/master/blip-0010.md
boostagram: {
"app_name": "Alby SDK Demo",
"value_msat_total": 49960, // TOTAL Number of millisats for the payment (all splits together, before fees. The actual number someone entered in their player, for numerology purposes.)
"value_msat": 2121, // Number of millisats for this split payment
"url": "https://feeds.buzzsprout.com/xxx.rss",
"podcast": "Podcast title",
"action": "boost",
"episode": "The episode title",
"episode_guid": "Buzzsprout-xxx",
"ts": 574,
"name": "Podcaster - the recipient name",
"sender_name": "Satoshi - the sender/listener name"
}
}]);
]);

console.log(JSON.stringify(response));
13 changes: 8 additions & 5 deletions examples/invoices.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { auth, Client } from "../dist/index.module.js";

Expand All @@ -10,14 +10,18 @@ const authClient = new auth.OAuth2User({
client_secret: process.env.CLIENT_SECRET,
callback: "http://localhost:8080",
scopes: ["invoices:read", "account:read", "balance:read"],
token: { access_token: undefined, refresh_token: undefined, expires_at: undefined } // initialize with existing token
token: {
access_token: undefined,
refresh_token: undefined,
expires_at: undefined,
}, // initialize with existing token
});

console.log(`Open the following URL and authenticate the app:`);
console.log(authClient.generateAuthURL());
console.log("----\n");

const code = await rl.question('Code: (localhost:8080?code=[THIS CODE]: ');
const code = await rl.question("Code: (localhost:8080?code=[THIS CODE]: ");
rl.close();

await authClient.requestAccessToken(code);
Expand All @@ -26,7 +30,6 @@ const client = new Client(authClient);

const response = await client.incomingInvoices();


console.log(JSON.stringify(response, null, 2));

if (response[0]) {
Expand Down
33 changes: 23 additions & 10 deletions examples/keysends.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { auth, Client } from "../dist/index.module.js";

Expand All @@ -9,15 +9,26 @@ 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: undefined, refresh_token: undefined, expires_at: undefined } // initialize with existing token
scopes: [
"invoices:read",
"account:read",
"balance:read",
"invoices:create",
"invoices:read",
"payments:send",
],
token: {
access_token: undefined,
refresh_token: undefined,
expires_at: undefined,
}, // initialize with existing token
});

console.log(`Open the following URL and authenticate the app:`);
console.log(authClient.generateAuthURL());
console.log("----\n");

const code = await rl.question('Code: (localhost:8080?code=[THIS CODE]: ');
const code = await rl.question("Code: (localhost:8080?code=[THIS CODE]: ");
rl.close();

await authClient.requestAccessToken(code);
Expand All @@ -27,14 +38,16 @@ const client = new Client(authClient);
const response = client.keysend([
{
amount: 10,
destination: '03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6',
customRecords: { "34349334": 'I love amboss' }
destination:
"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6",
customRecords: { 34349334: "I love amboss" },
},
{
amount: 11,
destination: '03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6',
customRecords: { "34349334": 'I love amboss' }
}
destination:
"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6",
customRecords: { 34349334: "I love amboss" },
},
]);

console.log(JSON.stringify(response));
18 changes: 11 additions & 7 deletions examples/nwc/get-balance.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import * as crypto from 'node:crypto'; // required in node.js
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import 'websocket-polyfill' // required in node.js
import "websocket-polyfill"; // required in node.js

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { webln as providers } from "../../dist/index.module.js";

const rl = readline.createInterface({ input, output });

const nwcUrl = await rl.question('Nostr Wallet Connect URL (nostrwalletconnect://...): ');
const nwcUrl = await rl.question(
"Nostr Wallet Connect URL (nostrwalletconnect://...): ",
);
rl.close();

const webln = new providers.NostrWebLNProvider({ nostrWalletConnectUrl: nwcUrl });
const webln = new providers.NostrWebLNProvider({
nostrWalletConnectUrl: nwcUrl,
});
await webln.enable();
const response = await webln.getBalance();

console.log(response);

webln.close();
webln.close();
20 changes: 12 additions & 8 deletions examples/nwc/make-invoice.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import * as crypto from 'node:crypto'; // required in node.js
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import 'websocket-polyfill' // required in node.js
import "websocket-polyfill"; // required in node.js

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { webln as providers } from "../../dist/index.module.js";

const rl = readline.createInterface({ input, output });

const nwcUrl = await rl.question('Nostr Wallet Connect URL (nostrwalletconnect://...): ');
const nwcUrl = await rl.question(
"Nostr Wallet Connect URL (nostrwalletconnect://...): ",
);
rl.close();

const webln = new providers.NostrWebLNProvider({ nostrWalletConnectUrl: nwcUrl });
const webln = new providers.NostrWebLNProvider({
nostrWalletConnectUrl: nwcUrl,
});
await webln.enable();
const response = await webln.makeInvoice({
amount: 100,
defaultMemo: "NWC WebLN example"
defaultMemo: "NWC WebLN example",
});

console.log(response);

webln.close();
webln.close();
20 changes: 12 additions & 8 deletions examples/nwc/send-payment.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import * as crypto from 'node:crypto'; // required in node.js
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import 'websocket-polyfill' // required in node.js
import "websocket-polyfill"; // required in node.js

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { webln as providers } from "../../dist/index.module.js";

const rl = readline.createInterface({ input, output });

const nwcUrl = await rl.question('Nostr Wallet Connect URL (nostrwalletconnect://...): ');
const invoice = await rl.question('Lightning invoice: ');
const nwcUrl = await rl.question(
"Nostr Wallet Connect URL (nostrwalletconnect://...): ",
);
const invoice = await rl.question("Lightning invoice: ");
rl.close();

const webln = new providers.NostrWebLNProvider({ nostrWalletConnectUrl: nwcUrl });
const webln = new providers.NostrWebLNProvider({
nostrWalletConnectUrl: nwcUrl,
});
await webln.enable();
const sendPaymentResponse = await webln.sendPayment(invoice);
console.log(sendPaymentResponse);

const getBalanceResponse = await webln.getBalance();
console.log(getBalanceResponse);

webln.close();
webln.close();
14 changes: 9 additions & 5 deletions examples/send-to-ln-address.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { auth, Client } from "../dist/index.module.js";
import { LightningAddress } from "alby-tools";
Expand All @@ -11,14 +11,18 @@ const authClient = new auth.OAuth2User({
client_secret: process.env.CLIENT_SECRET,
callback: "http://localhost:8080",
scopes: ["payments:send"],
token: { access_token: undefined, refresh_token: undefined, expires_at: undefined } // initialize with existing token
token: {
access_token: undefined,
refresh_token: undefined,
expires_at: undefined,
}, // initialize with existing token
});

console.log(`Open the following URL and authenticate the app:`);
console.log(authClient.generateAuthURL());
console.log("----\n");

const code = await rl.question('Code: (localhost:8080?code=[THIS CODE]: ');
const code = await rl.question("Code: (localhost:8080?code=[THIS CODE]: ");
rl.close();

await authClient.requestAccessToken(code);
Expand All @@ -29,7 +33,7 @@ const ln = new LightningAddress("[email protected]");
// fetch the LNURL data
await ln.fetch();

const invoice = await ln.requestInvoice({satoshi: 1000});
const invoice = await ln.requestInvoice({ satoshi: 1000 });

const response = await client.sendPayment({ invoice: invoice.paymentRequest });

Expand Down
26 changes: 20 additions & 6 deletions examples/webhooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { auth, Client } from "../dist/index.module.js";

Expand All @@ -9,23 +9,37 @@ 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: undefined, refresh_token: undefined, expires_at: undefined } // initialize with existing token
scopes: [
"invoices:read",
"account:read",
"balance:read",
"invoices:create",
"invoices:read",
"payments:send",
],
token: {
access_token: undefined,
refresh_token: undefined,
expires_at: undefined,
}, // initialize with existing token
});

console.log(`Open the following URL and authenticate the app:`);
console.log(authClient.generateAuthURL());
console.log("----\n");

const code = await rl.question('Code: (localhost:8080?code=[THIS CODE]: ');
const code = await rl.question("Code: (localhost:8080?code=[THIS CODE]: ");
rl.close();

await authClient.requestAccessToken(code);
console.log(authClient.token);
const client = new Client(authClient);

// Create a webhook
response = await alby.createWebhookEndpoint({url: "https://example.com", filter_types: ["invoice.settled"]})
response = await alby.createWebhookEndpoint({
url: "https://example.com",
filter_types: ["invoice.settled"],
});

// Delete a webhook
// response = await alby.deleteWebhookEndpoint('ep_...').then(console.log)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"lint:js": "eslint src --ext .js,.ts --max-warnings 0",
"lint:js:fix": "eslint src --ext .js,.ts --fix",
"tsc:compile": "tsc --noEmit",
"format": "prettier --check '**/*.(md|json)' 'src/**/*.(js|ts)' 'example/**/*.(js|jsx)'",
"format:fix": "prettier --loglevel silent --write '**/*.(md|json)' 'src/**/*.(js|ts)' 'example/**/*.(js|jsx)'",
"format": "prettier --check '**/*.(md|json)' 'src/**/*.(js|ts)' 'examples/**/*.(js|jsx)'",
"format:fix": "prettier --loglevel silent --write '**/*.(md|json)' 'src/**/*.(js|ts)' 'examples/**/*.(js|jsx)'",
"prepack": "yarn run build",
"test": "jest",
"clean": "rm -rf dist",
Expand Down
Loading

0 comments on commit 73d1d5c

Please sign in to comment.