Simple helper for interacting with the Landlord APIs
npm install @d2l/landlord-client --save
var LandlordClient = require('@d2l/landlord-client');
var client = new LandlordClient()
.on('error', console.error);
client
.lookupTenantId('valence.desire2learn.com:443')
.then(function (tenantId) {
// do something
})
.catch(function (err) {
// handle error
});
You may optionally specify the Landlord instance to connect to.
...new LandlordClient({ endpoint: 'https://landlord.brightspace.com' });
You may optionally specifiy an instance of a cache inheriting from
LandlordClient.AbstractLandlordCache
.
Recommended. You may optionally specify a name to send as part of the user agent when sending requests to Landlord. Assists in tracking issues and RCAs.
...new LandlordClient({ name: 'johns-service' })
You may optionally adjust the behaviour of lookupTenantUrl when the cache is
stale. By default a stale cache entry will be used immediately and the attempt
to update the cached value will occur in the background. Set blockOnRefresh
to true
to instead wait for the result of the refresh to complete, returning
the fresh value instead. An error will still be emitted, and the stale value
will still be used if the refresh fails.
Use this option if you believe you are slighly more sensitive to stale cache entries (you likely are not), or if you're in an environment that is not conducive to background / out-of-band work such as AWS Lambda.
Given the host, will fetch then TenantId from Landlord. Returns a Promise to a String.
Given the TenantId, well fetch the base url from Landlord. Returns a Promise to a String.
Checks availability by pinging Landlord. Returns a Promise to a String.
LandlordClient
is an EventEmitter
and will emit error
events for errors
which occur outside of the normal workflow (such as background fetches). You
should add an error handler , perhaps just to your logger. Failure to add an
error listener may lead your program to
exit;
Provided as part of the export is an object containing the well-typed errors which may be returned from function calls.
npm test
-
Fork the repository. Committing directly against this repository is highly discouraged.
-
Make your modifications in a branch, updating and writing new unit tests as necessary in the
spec
directory. -
Ensure that all tests pass with
npm test
-
rebase
your changes against master. Do not merge. -
Submit a pull request to this repository. Wait for tests to run and someone to chime in.
This repository is configured with EditorConfig and ESLint ESLint rules. See the docs.dev code style article for information on installing editor extensions.