Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

BrightspaceHypermediaComponents/node-landlord-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

landlord-client

Coverage Status

Simple helper for interacting with the Landlord APIs

Install

npm install @d2l/landlord-client --save

Usage

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
	});

API


new LandlordClient([Object options]) -> LandlordClient

Option: endpoint

You may optionally specify the Landlord instance to connect to.

...new LandlordClient({ endpoint: 'https://landlord.brightspace.com' });
Option: cache AbstractLandlordCache (LRULandlordCache)

You may optionally specifiy an instance of a cache inheriting from LandlordClient.AbstractLandlordCache.

Option: name String

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' })
Option: blockOnRefresh boolean (false)

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.


.lookupTenantId(String host) -> Promise<String>

Given the host, will fetch then TenantId from Landlord. Returns a Promise to a String.


.lookupTenantUrl(String TenantId) -> Promise<String>

Given the TenantId, well fetch the base url from Landlord. Returns a Promise to a String.


.validateConfiguration() -> Promise<String>

Checks availability by pinging Landlord. Returns a Promise to a String.


.on('error', Function<Error> callback) -> LandlordClient

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;


LandlordClient.errors -> Object

Provided as part of the export is an object containing the well-typed errors which may be returned from function calls.

Testing

npm test

Contributing

  1. Fork the repository. Committing directly against this repository is highly discouraged.

  2. Make your modifications in a branch, updating and writing new unit tests as necessary in the spec directory.

  3. Ensure that all tests pass with npm test

  4. rebase your changes against master. Do not merge.

  5. Submit a pull request to this repository. Wait for tests to run and someone to chime in.

Code Style

This repository is configured with EditorConfig and ESLint ESLint rules. See the docs.dev code style article for information on installing editor extensions.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%