Skip to content

Commit

Permalink
Update to ES modules
Browse files Browse the repository at this point in the history
Updated dependecies

Refactored and face cleaning

Update JsDoc

Updated tests

Add interactive examples
  • Loading branch information
eozores-telefonica committed Nov 15, 2024
1 parent a0c6169 commit 97e9917
Show file tree
Hide file tree
Showing 9 changed files with 1,793 additions and 1,010 deletions.
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

0 comments on commit 97e9917

Please sign in to comment.