@ministryofjustice/fb-client v2.1.7
Client
Clients for Email, SMS, Submitter, User Data Store, User File Store, and JWT.
JSON Web Token client
Base client for requests to endpoints which require a JSON Web Token for authentication.
Using a client
const FBJWTClient = require('@ministryofjustice/fb-client/user/jwt/client')
const jwtClient = new FBJWTClient(serviceSecret, serviceSlug, microserviceUrl, [errorClass])Service Secret
A serviceSecret is required.
The constructor will throw an error if no serviceSecret is provided.
Service Slug
A serviceSlug is required.
The constructor will throw an error if no serviceSlug is provided.
Microservice URL
A microserviceUrl is required.
The constructor will throw an error if no microserviceUrl is provided.
Error Class
An errorClass is optional.
Extending
class FBMyClient extends FBJWTClient {
constructor (serviceSecret, serviceSlug, microserviceUrl, [myVar]) {
super(serviceSecret, serviceSlug, microserviceUrl)
this.myVar = myVar // assign the optional constructor argument
}
}
const myClient = new FBMyClient('service_secret', 'myservice', 'http://myservice', ['my var'])// a custom error class extending the base error class
class FBAnotherClientError extends FBJWTClient.prototype.ErrorClass {}
class FBAnotherClient extends FBJWTClient {
constructor (serviceSecret, serviceSlug, microserviceUrl) {
super(serviceSecret, serviceSlug, microserviceUrl, FBAnotherClientError)
}
}Methods
generateAccessTokenGenerate a JWT access token
createEndpointUrlCreate the URL for an endpoint
sendGetDispatch
GETrequests to an endpointsendPostDispatch
POSTrequests to an endpointencryptEncrypt data with AES 256
decryptDecrypt data
encryptUserIdAndTokenEncrypt the user ID and token using the service secret
decryptUserIdAndTokenDecrypt the user ID and token using the service secret
handleRequestErrorThis function will be invoked with an error an argument when the transaction fails
createRequestOptionsCreate request options, whether
GETorPOSTthrowRequestErrorThis function can be invoked to throw request errors
JSON Web Token client implementations
Data Store client
Client for requests to datastore endpoints.
Using a client
const FBUserDataStoreClient = require('@ministryofjustice/fb-client/user/datastore/client')
const userDataStoreClient = new FBUserDataStoreClient(serviceSecret, serviceSlug, userDataStoreUrl)Fetching and storing
// fetch user data
const userData = await userDataStoreClient.getData(userId, userToken)
// store user data
await userDataStoreClient.setData(userId, userToken, userData)File Store client
Client for requests to filestore endpoints.
Using a client
const FBUserFileStoreClient = require('@ministryofjustice/fb-client/user/filestore/client')
const userFileStoreClient = new FBUserFileStoreClient(serviceSecret, serviceSlug, userFileStoreUrl)Fetching and storing
Fetching
// fetch user file
const userFile = await userFileStoreClient.fetch(userId, userToken, fingerprint)Storing
Define a policy:
const policy = { [max_size], [expires], [allowed_types] }Either:
// store user file from file data
const uploadDetails = await userFileStoreClient.store(userId, userToken, file, policy)Or:
// store user file from file path
const uploadDetails = await userFileStoreClient.storeFromPath(userId, userToken, filePath, policy)4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago