### FBJWTClient Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Base client for requests to endpoints which require a JSON Web Token for authentication. It supports generating access tokens, creating endpoint URLs, sending GET and POST requests, and encrypting/decrypting data. ```APIDOC ## FBJWTClient ### Description Base client for requests to endpoints which require a JSON Web Token for authentication. It supports generating access tokens, creating endpoint URLs, sending GET and POST requests, and encrypting/decrypting data. ### Constructor `new FBJWTClient(serviceSecret, serviceSlug, microserviceUrl, [errorClass])` #### Parameters - **serviceSecret** (string) - Required - The secret for the service. - **serviceSlug** (string) - Required - The slug for the service. - **microserviceUrl** (string) - Required - The URL of the microservice. - **errorClass** (ErrorClass) - Optional - A custom error class to use. ### Methods - `generateAccessToken()`: Generate a JWT access token. - `createEndpointUrl(endpoint)`: Create the URL for an endpoint. - `sendGet(endpoint, options)`: Dispatch `GET` requests to an endpoint. - `sendPost(endpoint, data, options)`: Dispatch `POST` requests to an endpoint. - `encrypt(data)`: Encrypt data with AES 256. - `decrypt(data)`: Decrypt data. - `encryptUserIdAndToken(userId, token)`: Encrypt the user ID and token using the service secret. - `decryptUserIdAndToken(encryptedData)`: Decrypt the user ID and token using the service secret. - `handleRequestError(error)`: This function will be invoked with an error an argument when the transaction fails. - `createRequestOptions(method, endpoint, data)`: Create request options, whether `GET` or `POST`. - `throwRequestError(error)`: This function can be invoked to throw request errors. ``` -------------------------------- ### Instantiate FBUserDataStoreClient Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Instantiate the client for interacting with datastore endpoints. Requires service credentials and the datastore URL. ```javascript const FBUserDataStoreClient = require('@ministryofjustice/fb-client/user/datastore/client') const userDataStoreClient = new FBUserDataStoreClient(serviceSecret, serviceSlug, userDataStoreUrl) ``` -------------------------------- ### Instantiate FBUserFileStoreClient Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Instantiate the client for interacting with filestore endpoints. Requires service credentials and the filestore URL. ```javascript const FBUserFileStoreClient = require('@ministryofjustice/fb-client/user/filestore/client') const userFileStoreClient = new FBUserFileStoreClient(serviceSecret, serviceSlug, userFileStoreUrl) ``` -------------------------------- ### Fetch User File Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Retrieve a user file using the `fetch` method. This requires user credentials and a fingerprint to identify the file. ```javascript // fetch user file const userFile = await userFileStoreClient.fetch(userId, userToken, fingerprint) ``` -------------------------------- ### Store User File from File Path Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Store a user file by providing its path. A policy object defining constraints like size, expiry, and types must be provided. ```javascript const policy = { [max_size], [expires], [allowed_types] } // store user file from file path const uploadDetails = await userFileStoreClient.storeFromPath(userId, userToken, filePath, policy) ``` -------------------------------- ### Fetch and Store User Data Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Perform operations to fetch user data using `getData` or store user data using `setData`. Both methods require user credentials and the data payload. ```javascript // fetch user data const userData = await userDataStoreClient.getData(userId, userToken) // store user data await userDataStoreClient.setData(userId, userToken, userData) ``` -------------------------------- ### FBUserFileStoreClient Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Client for requests to filestore endpoints. Allows fetching and storing user files. ```APIDOC ## FBUserFileStoreClient ### Description Client for requests to filestore endpoints. Allows fetching and storing user files. ### Constructor `new FBUserFileStoreClient(serviceSecret, serviceSlug, userFileStoreUrl)` #### Parameters - **serviceSecret** (string) - Required - The secret for the service. - **serviceSlug** (string) - Required - The slug for the service. - **userFileStoreUrl** (string) - Required - The URL of the user file store. ### Methods - `fetch(userId, userToken, fingerprint)`: Fetch user file. - `store(userId, userToken, file, policy)`: Store user file from file data. - `storeFromPath(userId, userToken, filePath, policy)`: #### Policy Object for Storing Files - **max_size** (number) - Maximum file size. - **expires** (number) - Expiration time in seconds. - **allowed_types** (array) - Array of allowed MIME types. ``` -------------------------------- ### Instantiate FBJWTClient Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Instantiate the base client for requests requiring JWT authentication. Ensure all required parameters are provided. ```javascript const FBJWTClient = require('@ministryofjustice/fb-client/user/jwt/client') const jwtClient = new FBJWTClient(serviceSecret, serviceSlug, microserviceUrl, [errorClass]) ``` -------------------------------- ### Store User File from File Data Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Store a user file directly from file data. A policy object defining constraints like size, expiry, and types must be provided. ```javascript const policy = { [max_size], [expires], [allowed_types] } // store user file from file data const uploadDetails = await userFileStoreClient.store(userId, userToken, file, policy) ``` -------------------------------- ### FBUserDataStoreClient Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Client for requests to datastore endpoints. Allows fetching and storing user data. ```APIDOC ## FBUserDataStoreClient ### Description Client for requests to datastore endpoints. Allows fetching and storing user data. ### Constructor `new FBUserDataStoreClient(serviceSecret, serviceSlug, userDataStoreUrl)` #### Parameters - **serviceSecret** (string) - Required - The secret for the service. - **serviceSlug** (string) - Required - The slug for the service. - **userDataStoreUrl** (string) - Required - The URL of the user data store. ### Methods - `getData(userId, userToken)`: Fetch user data. - `setData(userId, userToken, userData)`: Store user data. ``` -------------------------------- ### Extend FBJWTClient Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Extend the FBJWTClient to create custom clients with additional constructor arguments. The optional argument is assigned to a class property. ```javascript class FBMyClient extends FBJWTClient { constructor (serviceSecret, serviceSlug, microserviceUrl, [myVar]) { super(serviceSecret, serviceSlug, microserviceUrl) this.myVar = myVar // assign the optional constructor argument } } ``` ```javascript const myClient = new FBMyClient('service_secret', 'myservice', 'http://myservice', ['my var']) ``` -------------------------------- ### Create Custom Error Class for FBJWTClient Source: https://github.com/ministryofjustice/fb-client/blob/master/README.md Define a custom error class that extends the base error class provided by FBJWTClient. This allows for specialized error handling. ```javascript // a custom error class extending the base error class class FBAnotherClientError extends FBJWTClient.prototype.ErrorClass {} ``` ```javascript class FBAnotherClient extends FBJWTClient { constructor (serviceSecret, serviceSlug, microserviceUrl) { super(serviceSecret, serviceSlug, microserviceUrl, FBAnotherClientError) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.