0.1.0 • Published 6 years ago
@pilon-io/js-sdk v0.1.0
js-sdk
The official Pilon JavaScript SDK
Installation
Using npm npm install @pilon-io/js-sdk
or with yarn yarn add @pilon-io/js-sdk
Usage
The SDK provides helpers for authenticating merchants, customers and anonymous customers with the Pilon API.
Anonymous
To use the anonymous customer interface you need an environmentId. Once you are authenticated you will have access to the public details of the environment. Here's how to use the helper to retrieve a token
import { AnonymousAuth } from "@pilon-io/js-sdk"
const authToken = await AnonymousAuth.getToken(environmentId)
// Creating a graphql client
GraphQLClient(`${baseUrl}/graphql`, {
headers: {
Authorization: `CUSTOMER-SESSION-ID ${authToken}`,
},
})
Merchant user
To authenticate with as a merchant user on the Pilon API you need to use the UserAuth
helper. Here are some examples
import { UserAuth } from "js-sdk"
await UserAuth.login({
username,
password,
onSuccess: () => {
navigate("/dashboard")
},
onFailure: () => {
// Display error
this.setState({ errorMessage: "Please enter valid credentials!" })
},
onNewPasswordChallenge: () => {
navigate("/new-password-required")
},
})
const user = await UserAuth.getCurrentUser()
Building
The SDK is built using rollup. yarn clean && yarn build
will build the SDK
0.1.0
6 years ago