Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/oauth/boostagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getAuthClient } from "./helper";

const userAgent = "AlbySDK-Example/0.1 (boostagram-demo)";

const client = await getAuthClient(userAgent);
const client = await getAuthClient(userAgent, ["payments:send"]);

// use an array if you want to send multiple boostagrams with one call
const response = await client.sendBoostagram([
Expand Down
10 changes: 5 additions & 5 deletions examples/oauth/create-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { getAuthClient } from "./helper";

const userAgent = "AlbySDK-Example/0.1 (create_webhook-demo)"
const userAgent = "AlbySDK-Example/0.1 (create_webhook-demo)";

const client = await getAuthClient(userAgent);
const client = await getAuthClient(userAgent, ["invoices:read"]);

const rl = readline.createInterface({ input, output });
const webhookUrl = await rl.question("Enter your webhook URL (get a test URL at https://webhook.site/): ");
const webhookUrl = await rl.question(
"Enter your webhook URL (get a test URL at https://webhook.site/): ",
);
rl.close();

// Create a webhook
Expand All @@ -16,5 +18,3 @@ const webhook = await client.createWebhookEndpoint({
filter_types: ["invoice.incoming.settled", "invoice.outgoing.settled"],
});
console.log("Webhook Id: ", JSON.stringify(webhook.id));


4 changes: 2 additions & 2 deletions examples/oauth/decode-invoice.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getAuthClient } from "./helper";

const userAgent = "AlbySDK-Example/0.1 (decode_invoice-demo)"
const userAgent = "AlbySDK-Example/0.1 (decode_invoice-demo)";
const paymentRequest =
"lnbc10u1pj4t6w0pp54wm83znxp8xly6qzuff2z7u6585rnlcw9uduf2haa42qcz09f5wqdq023jhxapqd4jk6mccqzzsxqyz5vqsp5mlvjs8nktpz98s5dcrhsuelrz94kl2vjukvu789yzkewast6m00q9qyyssqupynqdv7e5y8nlul0trva5t97g7v3gwx7akhu2dvu4pn66eu2pr5zkcnegp8myz3wrpj9ht06pwyfn4dvpmnr96ejq6ygex43ymaffqq3gud4d";

const client = await getAuthClient(userAgent);
const client = await getAuthClient(userAgent, ["invoices:read"]);
const response = await client.decodeInvoice(paymentRequest);

console.log(JSON.stringify(response, null, 2));
8 changes: 4 additions & 4 deletions examples/oauth/delete-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { getAuthClient } from "./helper";

const userAgent = "AlbySDK-Example/0.1 (delete_webhook-demo)"
const userAgent = "AlbySDK-Example/0.1 (delete_webhook-demo)";

const client = await getAuthClient(userAgent);
const client = await getAuthClient(userAgent, ["invoices:read"]);

const rl = readline.createInterface({ input, output });
const webhookId = await rl.question("Enter the webhook ID to delete: ");
rl.close();

// Delete a webhook
const deleteResult = await client.deleteWebhookEndpoint(webhookId)
console.log("webhook deleted", JSON.stringify(deleteResult));
const deleteResult = await client.deleteWebhookEndpoint(webhookId);
console.log("webhook deleted", JSON.stringify(deleteResult));
6 changes: 3 additions & 3 deletions examples/oauth/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import dotenv from "dotenv";
dotenv.config();
import { Client, OAuth2User } from "@getalby/sdk/oauth";
import { Client, OAuth2Scopes, OAuth2User } from "@getalby/sdk/oauth";

async function getAuthClient(user_agent: string) {
async function getAuthClient(user_agent: string, scopes: OAuth2Scopes[]) {
if (process.env.CLIENT_ID && process.env.CLIENT_SECRET) {
const rl = readline.createInterface({ input, output });

Expand All @@ -13,7 +13,7 @@ async function getAuthClient(user_agent: string) {
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
callback: "http://localhost:8080",
scopes: ["invoices:read", "account:read", "balance:read"],
scopes,
user_agent,
token: {
access_token: undefined,
Expand Down
2 changes: 1 addition & 1 deletion examples/oauth/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getAuthClient } from "./helper";

const userAgent = "AlbySDK-Example/0.1 (invoices-demo)";

const client = await getAuthClient(userAgent);
const client = await getAuthClient(userAgent, ["invoices:read"]);

const params: GetInvoicesRequestParams = {
page: 1,
Expand Down
4 changes: 2 additions & 2 deletions examples/oauth/keysends.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getAuthClient } from "./helper";

const userAgent = "AlbySDK-Example/0.1 (keysends-demo)"
const userAgent = "AlbySDK-Example/0.1 (keysends-demo)";

const client = await getAuthClient(userAgent);
const client = await getAuthClient(userAgent, ["payments:send"]);

const response = client.keysend([
{
Expand Down
4 changes: 2 additions & 2 deletions examples/oauth/send-to-ln-address.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { LightningAddress } from "@getalby/lightning-tools";
import { getAuthClient } from "./helper";

const userAgent = "AlbySDK-Example/0.1 (send_to_ln_address-demo)"
const userAgent = "AlbySDK-Example/0.1 (send_to_ln_address-demo)";

const client = await getAuthClient(userAgent);
const client = await getAuthClient(userAgent, ["payments:send"]);
const ln = new LightningAddress("[email protected]");
// fetch the LNURL data
await ln.fetch();
Expand Down