@lokavaluto/lokapi-browser v0.1.0
LokAPI is a JavaScript library intended to be used in mobile applications or web application to abstract all logics with lokavaluto's server.
This packages holds implementation details that are usable for browser or node support and as such, this package brings you all functionality of the LokAPI on these platforms.
Adding @lokavaluto/lokapi-browser to your project
From the root of your project:
npm install --save @lokavaluto/lokapi-browserOr better, as lokapi-browser is still in early release,
npm install --save Lokavaluto/lokapi-browser#masterTo be sure to get the latest version, relaunch this last command whenever you want to update.
Setting up @lokavaluto/lokapi-browser
Subclassing LokAPIBrowserAbstract
To use @lokavaluto/lokapi, you'll need to load backends. These
manages the actual inner exchanges of a currency. Go check
@lokavaluto/lokapi-backend-cyclos, or
@lokavaluto/lokapi-backend-comchain for more information.
Once you've chosen your backends, you can instantiate the
LokAPIBrowserAbstract. You'll need to provide at least:
BackendFactories :: A mapping of currency backends loaded
(optional) requestLogin :: a function to trigger a login screen when automatic authorization fails or when no automatic autorization data exists. This will be triggered only if a protected request is made on the administration backend side.
(optional) requestLocalPassword :: a function for backends to
trigger a request to the user for a password that is meant
to be kept locally on the device. This is typically used before
payment with some backends (to see an example see package
lokapi-backend-comchain), or administrative tasks. And takes
usually the form of a popup.
Here's an example using sweetalert2 as popup
import LokAPIBrowserAbstract from "@lokavaluto/lokapi-browser"
import comchain from '@lokavaluto/lokapi-backend-comchain'
import cyclos from '@lokavaluto/lokapi-backend-cyclos'
import Swal from "sweetalert2"
class LokAPI extends LokAPIBrowserAbstract {
BackendFactories = {
comchain,
cyclos
}
requestLocalPassword = async function (state: string) {
let text
if (state === 'firstTry') {
text = ''
} else if (state === 'failedUnlock') {
text = 'Failed to unlock ! Please retry...'
}
const ret = await Swal.fire({
title: 'Enter your password',
text,
showCloseButton: true,
input: 'password',
inputLabel: 'wallet password',
inputPlaceholder: 'your wallet password',
inputAttributes: {
maxlength: '32',
autocapitalize: 'off',
autocorrect: 'off'
}
})
if (ret.isConfirmed) {
return ret.value
}
throw new Error('User canceled the dialog box')
}
requestLogin() {
// XXXvlab: for now `requestLogin` is not using the same
// interface than `requestLocalPassword`. To make it work
// meanwhile, use this callback to trigger a
// `lokapi.login(..)`.
console.log("Login requested !")
}
}Usage
Instantiating LokAPI
On instantiation time, LokAPI class will require you to provide:
host :: as a string (example: "lokavaluto.fr")
database :: as a string (example: "myodoodb")
For instance:
var lokAPI = new LokAPI('lokavaluto.fr', 'myodoodb')Further usages
You can go check the documentation of the main package LokAPI
Developer
Building the project from fresh clone
npm installTranspilation to JavaScript
npx tscor with watch support:
npx tsc -wChangelog
0.0.3-alpha.202304230054
New
- Export
LocalStorefor convenience. Valentin Lab
Changes
Switch to browser implementation. Valentin Lab
The browser implementation uses
fetchAPI and is more adapted and more compatible than previous one based on node interface.In particular, some incompatibility on iOS platform where found when loading package local files.
Chg: fix: compatibility with new exception location in
@lokavaluto/lokapi!api. Valentin LabNote that we broke also client API. The main class is now exported with
RestExc, types and is as a consequence not anymore the default import.
Fix
Add missing
timeoutoption support for correct polling. Valentin LabThis was used by
lokapi-backend-comchainthanks to thejsc3land could potentially freeze despite thetimeoutbeing specified.Prevent double slash at beginning of path. Valentin Lab
Fill response headers as before. Valentin Lab
In
@0k.io/browser-requestversion0.0.1, the response headers were not filled up correctly.
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago