Clients for Email, SMS, Submitter, User Data Store, User File Store, and JWT.
Base client for requests to endpoints which require a JSON Web Token for authentication.
const FBJWTClient = require('@ministryofjustice/fb-client/user/jwt/client')
const jwtClient = new FBJWTClient(serviceSecret, serviceSlug, microserviceUrl, [errorClass])
A serviceSecret
is required.
The constructor will throw an error if no serviceSecret
is provided.
A serviceSlug
is required.
The constructor will throw an error if no serviceSlug
is provided.
A microserviceUrl
is required.
The constructor will throw an error if no microserviceUrl
is provided.
An errorClass
is optional.
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)
}
}
-
generateAccessToken
Generate a JWT access token
-
createEndpointUrl
Create the URL for an endpoint
-
sendGet
Dispatch
GET
requests to an endpoint -
sendPost
Dispatch
POST
requests to an endpoint -
encrypt
Encrypt data with AES 256
-
decrypt
Decrypt data
-
encryptUserIdAndToken
Encrypt the user ID and token using the service secret
-
decryptUserIdAndToken
Decrypt the user ID and token using the service secret
-
handleRequestError
This function will be invoked with an error an argument when the transaction fails
-
createRequestOptions
Create request options, whether
GET
orPOST
-
throwRequestError
This function can be invoked to throw request errors
Client for requests to datastore endpoints.
const FBUserDataStoreClient = require('@ministryofjustice/fb-client/user/datastore/client')
const userDataStoreClient = new FBUserDataStoreClient(serviceSecret, serviceSlug, userDataStoreUrl)
// fetch user data
const userData = await userDataStoreClient.getData(userId, userToken)
// store user data
await userDataStoreClient.setData(userId, userToken, userData)
Client for requests to filestore endpoints.
const FBUserFileStoreClient = require('@ministryofjustice/fb-client/user/filestore/client')
const userFileStoreClient = new FBUserFileStoreClient(serviceSecret, serviceSlug, userFileStoreUrl)
// fetch user file
const userFile = await userFileStoreClient.fetch(userId, userToken, fingerprint)
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)