Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add-linting
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanjoshi914 committed Aug 10, 2023
2 parents 69a6d53 + f92ba8b commit 518d4d6
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 92 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
# Enable version updates for npm
- package-ecosystem: "npm"
# Look for `package.json` and `lock` files in the `root` directory
directory: "/"
# Check the npm registry for updates every day (weekdays)
schedule:
interval: "daily"
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn test
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Publish package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: yarn install --frozen-lockfile
- run: yarn test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: yarn install --frozen-lockfile
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@getalby/sdk",
"version": "2.1.4",
"version": "2.2.1",
"description": "The SDK to integrate with Nostr Wallet Connect and the Alby API",
"repository": "https://github.com/getAlby/alby-js-sdk.git",
"bugs": "https://github.com/getAlby/alby-js-sdk/issues",
"repository": "https://github.com/getAlby/js-sdk.git",
"bugs": "https://github.com/getAlby/js-sdk/issues",
"funding": {
"type": "lightning",
"url": "lightning:[email protected]"
Expand All @@ -19,8 +19,8 @@
],
"exports": {
"require": "./dist/index.cjs",
"default": "./dist/index.modern.js",
"types": "./dist/index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.modern.js"
},
"scripts": {
"prebuild": "yarn run clean",
Expand Down
114 changes: 89 additions & 25 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { rest, RequestOptions } from "./request";
import { OAuth2Bearer } from "./auth";
import { keysendParamsFromBoostagram } from "./helpers";
import { RequestOptions, rest } from "./request";
import {
AuthClient,
BaseWebhookEndpointResponse,
CreateSwapParams,
CreateSwapResponse,
CreateWebhookEndpointParams,
CreateWebhookEndpointResponse,
GetAccountBalanceResponse,
GetAccountInformationResponse,
Invoice,
InvoiceRequestParams,
KeysendRequestParams,
SendPaymentRequestParams,
SendBoostagramRequestParams,
SendToAlbyRequestParams,
CreateWebhookEndpointResponse,
BaseWebhookEndpointResponse,
SendPaymentRequestParams,
SendPaymentResponse,
Invoice,
GetAccountBalanceResponse,
GetAccountInformationResponse
SendToAlbyRequestParams,
SwapInfoResponse,
} from "./types";
import { keysendParamsFromBoostagram } from "./helpers";
import { OAuth2Bearer } from "./auth";


export class Client {
auth: AuthClient;
Expand All @@ -29,11 +31,14 @@ export class Client {
this.auth = typeof auth === "string" ? new OAuth2Bearer(auth) : auth;
this.defaultRequestOptions = {
...requestOptions,
user_agent: requestOptions?.user_agent
user_agent: requestOptions?.user_agent,
};
}

accountBalance(params: {}, request_options?: Partial<RequestOptions>): Promise<GetAccountBalanceResponse> {
accountBalance(
params: {},
request_options?: Partial<RequestOptions>
): Promise<GetAccountBalanceResponse> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -55,7 +60,10 @@ export class Client {
});
}

accountInformation(params: {}, request_options?: Partial<RequestOptions>): Promise<GetAccountInformationResponse> {
accountInformation(
params: {},
request_options?: Partial<RequestOptions>
): Promise<GetAccountInformationResponse> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -77,7 +85,10 @@ export class Client {
});
}

incomingInvoices(params: {}, request_options?: Partial<RequestOptions>): Promise<Invoice[]> {
incomingInvoices(
params: {},
request_options?: Partial<RequestOptions>
): Promise<Invoice[]> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -88,7 +99,10 @@ export class Client {
});
}

outgoingInvoices(params: {}, request_options?: Partial<RequestOptions>): Promise<Invoice[]> {
outgoingInvoices(
params: {},
request_options?: Partial<RequestOptions>
): Promise<Invoice[]> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -99,7 +113,10 @@ export class Client {
});
}

getInvoice(paymentHash: string, request_options?: Partial<RequestOptions>): Promise<Invoice> {
getInvoice(
paymentHash: string,
request_options?: Partial<RequestOptions>
): Promise<Invoice> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -109,7 +126,10 @@ export class Client {
});
}

createInvoice(invoice: InvoiceRequestParams, request_options?: Partial<RequestOptions>): Promise<Invoice> {
createInvoice(
invoice: InvoiceRequestParams,
request_options?: Partial<RequestOptions>
): Promise<Invoice> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -120,7 +140,10 @@ export class Client {
});
}

keysend(args: KeysendRequestParams | KeysendRequestParams[], request_options?: Partial<RequestOptions>): Promise<SendPaymentResponse> {
keysend(
args: KeysendRequestParams | KeysendRequestParams[],
request_options?: Partial<RequestOptions>
): Promise<SendPaymentResponse> {
let endpoint, request_body;
if (Array.isArray(args)) {
endpoint = "/payments/keysend/multi";
Expand All @@ -139,7 +162,10 @@ export class Client {
});
}

sendPayment(params: SendPaymentRequestParams, request_options?: Partial<RequestOptions>): Promise<SendPaymentResponse> {
sendPayment(
params: SendPaymentRequestParams,
request_options?: Partial<RequestOptions>
): Promise<SendPaymentResponse> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -150,7 +176,10 @@ export class Client {
});
}

sendBoostagram(args: SendBoostagramRequestParams | SendBoostagramRequestParams[], request_options?: Partial<RequestOptions>) {
sendBoostagram(
args: SendBoostagramRequestParams | SendBoostagramRequestParams[],
request_options?: Partial<RequestOptions>
) {
let endpoint, request_body;
if (Array.isArray(args)) {
endpoint = "/payments/keysend/multi";
Expand All @@ -171,9 +200,13 @@ export class Client {
});
}

sendToAlbyAccount(args: SendToAlbyRequestParams, request_options?: Partial<RequestOptions>) {
sendToAlbyAccount(
args: SendToAlbyRequestParams,
request_options?: Partial<RequestOptions>
) {
const params = {
destination: "030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",
destination:
"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",
customRecords: {
"696969": args.account,
},
Expand All @@ -190,7 +223,10 @@ export class Client {
});
}

createWebhookEndpoint(params: CreateWebhookEndpointParams, request_options?: Partial<RequestOptions>): Promise<CreateWebhookEndpointResponse> {
createWebhookEndpoint(
params: CreateWebhookEndpointParams,
request_options?: Partial<RequestOptions>
): Promise<CreateWebhookEndpointResponse> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -201,7 +237,10 @@ export class Client {
});
}

deleteWebhookEndpoint(id: string, request_options?: Partial<RequestOptions>): Promise<BaseWebhookEndpointResponse> {
deleteWebhookEndpoint(
id: string,
request_options?: Partial<RequestOptions>
): Promise<BaseWebhookEndpointResponse> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
Expand All @@ -211,4 +250,29 @@ export class Client {
});
}

getSwapInfo(
request_options?: Partial<RequestOptions>
): Promise<SwapInfoResponse> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
...request_options,
endpoint: `/swaps/info`,
method: "GET",
});
}

createSwap(
params: CreateSwapParams,
request_options?: Partial<RequestOptions>
): Promise<CreateSwapResponse> {
return rest({
auth: this.auth,
...this.defaultRequestOptions,
...request_options,
endpoint: `/swaps`,
method: "POST",
request_body: params,
});
}
}
7 changes: 3 additions & 4 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ export async function request({
{
headers: {
...(isPost
? { "Content-Type": "application/json; charset=utf-8" }
: undefined),
? { "Content-Type": "application/json; charset=utf-8" } : undefined),
...authHeader,
...headers,
...{
"User-Agent": user_agent ?? "alby-js-api",
"X-User-Agent": user_agent ?? "alby-js-api"
"User-Agent": user_agent ?? "@getalby/sdk",
"X-User-Agent": user_agent ?? "@getalby/sdk"
},
},
method,
Expand Down
Loading

0 comments on commit 518d4d6

Please sign in to comment.