Skip to content
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

[SDKs] Node.js improvement - Part 2 #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
37 changes: 9 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,21 @@

#### USING THE SDK IN NODEJS ####

* You need to include the npm package 'latch-sdk' in your package.json file and then require the "latch-sdk" in your NodeJS file.
* You need to include the npm package 'latch-sdk' in your package.json file and then import the "latch-sdk" with the needed functions in your NodeJS file.
```
var latch = require('latch-sdk');
import { init, pair ... } from 'latch-sdk';
```

* Initialize latch with your AppId and SecretKey. Hostname and port are optional.
```
latch.init({ appId: 'MY_APP_ID', secretKey: 'MY_SECRET_KEY', hostname: 'HOSTNAME:PORT' });
init({ appId: 'MY_APP_ID', secretKey: 'MY_SECRET_KEY', hostname: 'HOSTNAME:PORT' });
```

* Call to Latch Server. Pairing will return an account id that you should store for future api calls
```
let PAIRING_CODE = "<PAIRING_CODE>"

let response = latch.pair(PAIRING_CODE, function (err, result) {
if (err) {
console.log(util.inspect(err, {showHidden: true, depth: null, colors: true}));
} else {
console.log(util.inspect(result, {showHidden: true, depth: null, colors: true}));
}
});
let response = await pair(PAIRING_CODE);
console.dir(response, { depth: null });
```

#### USING THE SDK IN NODEJS FOR WEB3 SERVICES ####
Expand All @@ -54,23 +48,10 @@ The two additional parameters are:
- MESSAGE TO SIGN : "Latch-Web3"

* Call to Latch Server for pairing as usual, but with the newly methods:
```
let MY_APPID = "<MY_APPID>"
let MY_SECRETKEY = "<MY_SECRETKEY>"

let WEB3WALLET = "<WEB3WALLET>"
let WEB3SIGNATURE = "<WEB3SIGNATURE>"
let PAIRING_CODE = "<PAIRING_CODE>"

latch.init({ appId: MY_APPID, secretKey: MY_SECRETKEY });

let response = latch.pair(PAIRING_CODE, function (err, result) {
if (err) {
console.log(util.inspect(err, {showHidden: true, depth: null, colors: true}));
} else {
console.log(util.inspect(result, {showHidden: true, depth: null, colors: true}));
}
}, WEB3WALLET, WEB3SIGNATURE);
```
init({ appId: <MY_APPID>, secretKey: <MY_SECRETKEY> });
let response = await pair(<PAIRING_CODE>, <WEB3WALLET>, <WEB3SIGNATURE>);
console.dir(response, { depth: null });
```

You have an example of use in the file [example](examples/example.js)
54 changes: 26 additions & 28 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,35 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

API_VERSION = "1.3"
const API_VERSION = '1.3'

var config = {
appId: '',
secretKey: '',
export const config = {
APP_ID: '',
SECRET_KEY: '',

API_HOST: "https://latch.tu.com:443",
API_CHECK_STATUS_URL: "/api/" + API_VERSION + "/status",
API_PAIR_URL: "/api/" + API_VERSION + "/pair",
API_PAIR_WITH_ID_URL: "/api/" + API_VERSION + "/pairWithId",
API_UNPAIR_URL: "/api/" + API_VERSION + "/unpair",
API_LOCK_URL: "/api/" + API_VERSION + "/lock",
API_UNLOCK_URL: "/api/" + API_VERSION + "/unlock",
API_HISTORY_URL: "/api/" + API_VERSION + "/history",
API_OPERATION_URL: "/api/" + API_VERSION + "/operation",
API_SUBSCRIPTION_URL: "/api/" + API_VERSION + "/subscription",
API_APPLICATION_URL: "/api/" + API_VERSION + "/application",
API_INSTANCE_URL: "/api/" + API_VERSION + "/instance",
API_TOTP_URL: "/api/" + API_VERSION + "/totps",
API_CONTROL_STATUS_CHECK_URL: "/api/" + API_VERSION + "/control-status",
API_HOST: 'https://latch.tu.com:443',
API_CHECK_STATUS_URL: `/api/${API_VERSION}/status`,
API_PAIR_URL: `/api/${API_VERSION}/pair`,
API_PAIR_WITH_ID_URL: `/api/${API_VERSION}/pairWithId`,
API_UNPAIR_URL: `/api/${API_VERSION}/unpair`,
API_LOCK_URL: `/api/${API_VERSION}/lock`,
API_UNLOCK_URL: `/api/${API_VERSION}/unlock`,
API_HISTORY_URL: `/api/${API_VERSION}/history`,
API_OPERATION_URL: `/api/${API_VERSION}/operation`,
API_SUBSCRIPTION_URL: `/api/${API_VERSION}/subscription`,
API_APPLICATION_URL: `/api/${API_VERSION}/application`,
API_INSTANCE_URL: `/api/${API_VERSION}/instance`,
API_TOTP_URL: `/api/${API_VERSION}/totps`,
API_CONTROL_STATUS_CHECK_URL: `/api/${API_VERSION}/control-status`,

AUTHORIZATION_HEADER_NAME: "Authorization",
DATE_HEADER_NAME: "X-11Paths-Date",
PLUGIN_HEADER_NAME: "Latch-Plugin-Name",
AUTHORIZATION_METHOD: "11PATHS",
AUTHORIZATION_HEADER_FIELD_SEPARATOR: " ",
AUTHORIZATION_HEADER_NAME: 'Authorization',
DATE_HEADER_NAME: 'X-11Paths-Date',
PLUGIN_HEADER_NAME: 'Latch-Plugin-Name',
AUTHORIZATION_METHOD: '11PATHS',
AUTHORIZATION_HEADER_FIELD_SEPARATOR: ' ',

UTC_STRING_FORMAT: "%Y-%m-%d %H:%M:%S",
UTC_STRING_FORMAT: '%Y-%m-%d %H:%M:%S',

X_11PATHS_HEADER_PREFIX: "X-11paths-",
X_11PATHS_HEADER_SEPARATOR: ":",
X_11PATHS_HEADER_PREFIX: 'X-11paths-',
X_11PATHS_HEADER_SEPARATOR: ':',
};

module.exports = config;
28 changes: 28 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import mochaPlugin from 'eslint-plugin-mocha';


export default [
{
languageOptions: {
globals: globals.node
}
},
pluginJs.configs.recommended,
{
rules: {
// note you must disable the base rule as it can report incorrect errors
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn", // or "error"
{
"argsIgnorePattern": "_",
"varsIgnorePattern": "_",
"caughtErrorsIgnorePattern": "_"
}
]
}
},
mochaPlugin.configs.flat.recommended
];
Loading