diff --git a/examples/oauth/boostagram.ts b/examples/oauth/boostagram.ts index ddf53f5..70ca6a9 100644 --- a/examples/oauth/boostagram.ts +++ b/examples/oauth/boostagram.ts @@ -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([ diff --git a/examples/oauth/create-webhook.ts b/examples/oauth/create-webhook.ts index 560a436..31dcacb 100644 --- a/examples/oauth/create-webhook.ts +++ b/examples/oauth/create-webhook.ts @@ -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 @@ -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)); - - diff --git a/examples/oauth/decode-invoice.ts b/examples/oauth/decode-invoice.ts index a75c3ef..02c4369 100644 --- a/examples/oauth/decode-invoice.ts +++ b/examples/oauth/decode-invoice.ts @@ -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)); diff --git a/examples/oauth/delete-webhook.ts b/examples/oauth/delete-webhook.ts index 19db760..9a58b2e 100644 --- a/examples/oauth/delete-webhook.ts +++ b/examples/oauth/delete-webhook.ts @@ -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)); \ No newline at end of file +const deleteResult = await client.deleteWebhookEndpoint(webhookId); +console.log("webhook deleted", JSON.stringify(deleteResult)); diff --git a/examples/oauth/helper.ts b/examples/oauth/helper.ts index 1f22514..3269e4e 100644 --- a/examples/oauth/helper.ts +++ b/examples/oauth/helper.ts @@ -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 }); @@ -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, diff --git a/examples/oauth/invoices.ts b/examples/oauth/invoices.ts index 3453888..ee73575 100644 --- a/examples/oauth/invoices.ts +++ b/examples/oauth/invoices.ts @@ -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, diff --git a/examples/oauth/keysends.ts b/examples/oauth/keysends.ts index e54748c..4493de9 100644 --- a/examples/oauth/keysends.ts +++ b/examples/oauth/keysends.ts @@ -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([ { diff --git a/examples/oauth/send-to-ln-address.ts b/examples/oauth/send-to-ln-address.ts index c9dffe6..27edcd1 100644 --- a/examples/oauth/send-to-ln-address.ts +++ b/examples/oauth/send-to-ln-address.ts @@ -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("hello@getalby.com"); // fetch the LNURL data await ln.fetch();