Skip to content

Migrate to TS #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 6, 2023
Merged
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
File renamed without changes.
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ jspm_packages
# Editors
.idea

# Lib
lib

others
.DS_Store

# build dir
dist

# other lockfiles
yarn.lock
package-lock.json
11 changes: 11 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://json.schemastore.org/mocharc",
"timeout": 5000,
"slow": 350,
"bail": true,
"reporter": "progress",
"watch-files": [
"dist/**/*.js",
"test/**/*.js"
]
}
14 changes: 8 additions & 6 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ coverage
# Dependency directories
node_modules

# npm package lock
# package lock
package-lock.json
pnpm-lock.json
yarn.lock

# project files
src
test
examples
CHANGELOG.md
.travis.yml
.babelrc
.DS_Store
.editorconf
.editorconfig
.eslintignore
.eslintrc
.babelrc
.gitignore
.editorconf
.DS_Store
.mocharc.json
.travis.yml
tsconfig.json
62 changes: 27 additions & 35 deletions examples/example.js → examples/example.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const opennode = require('opennode');
import * as opennode from "../src";

/**
* Setup your API Key and environment
*/
opennode.setCredentials('MY_API_KEY', 'dev');

opennode.setCredentials("MY_API_KEY", "dev");

/**
*
Expand All @@ -15,65 +14,64 @@ opennode.setCredentials('MY_API_KEY', 'dev');
* Using promises
*/

opennode.chargeInfo('47bb5224-bf50-49d0-a317-4adfd345221a')
.then(charge => {
opennode
.chargeInfo("47bb5224-bf50-49d0-a317-4adfd345221a")
.then((charge) => {
console.log(charge);
})
.catch(error => {
.catch((error) => {
console.error(`${error.status} | ${error.message}`);
})
});

/**
*
* Using async/await
*/

;(async () => {

(async () => {
try {
const data = await opennode.chargeInfo('47bb5224-bf50-49d0-a317-4adfd345221a');
const data = await opennode.chargeInfo(
"47bb5224-bf50-49d0-a317-4adfd345221a"
);
console.log(data);
}
catch (error) {
} catch (error) {
console.error(`${error.status} | ${error.message}`);
}
})()
})();

/**
*
* Creating a charge
*/


const charge = {
amount: 10.5,
currency: "USD",
callback_url: "https://example.com/webhook/opennode",
auto_settle: false
auto_settle: false,
};

/**
* Using promises
*/

opennode.createCharge(charge)
.then(response => {
opennode
.createCharge(charge)
.then((response) => {
console.log(response);
})
.catch(error => {
.catch((error) => {
console.error(`${error.status} | ${error.message}`);
});

/**
* Using async/await
*/

;(async () => {
(async () => {
try {
const response = await opennode.createCharge(charge);
console.log(response);
}
catch(error) {
} catch (error) {
console.error(`${error.status} | ${error.message}`);
}
})();
Expand All @@ -87,38 +85,32 @@ opennode.createCharge(charge)
* Using promises
*/

const withdrawal = {
const withdrawal = {
min_amt: 5000,
max_amt: 5000,
description: "Claim these 5000 sats",
external_id: "my-external-uuid",
callback_url: "https://example.com/webhook/opennode",
};


opennode.createLnUrlWithdrawal(withdrawal)
.then(response => {
opennode
.createLnUrlWithdrawal(withdrawal)
.then((response) => {
console.log(response);
})
.catch(error => {
.catch((error) => {
console.error(`${error.status} | ${error.message}`);
});

/**
* Using async/await
*/

;(async () => {
(async () => {
try {
const response = await opennode.createLnUrlWithdrawal(withdrawal);
console.log(response);
}
catch(error) {
} catch (error) {
console.error(`${error.status} | ${error.message}`);
}
})();





Loading