-
Notifications
You must be signed in to change notification settings - Fork 303
/
TenantManager.js
106 lines (92 loc) · 2.56 KB
/
TenantManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var RestClient = require('rest-facade').Client;
var ArgumentError = require('rest-facade').ArgumentError;
/**
* Simple facade for consuming a REST API endpoint.
* @external RestClient
* @see https://github.com/ngonzalvez/rest-facade
*/
/**
* @class
* Abstracts interaction with the tenant endpoint.
* @constructor
* @memberOf module:management
*
* @param {Object} options The client options.
* @param {String} options.baseUrl The URL of the API.
* @param {Object} [options.headers] Headers to be included in all requests.
*/
var TenantManager = function (options){
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide manager options');
}
if (options.baseUrl === null || options.baseUrl === undefined) {
throw new ArgumentError('Must provide a base URL for the API');
}
if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
throw new ArgumentError('The provided base URL is invalid');
}
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
/**
* Provides an abstraction layer for consuming the
* {@link https://auth0.com/docs/api/v2#!/Stats Stats endpoint}.
*
* @type {external:RestClient}
*/
this.tenant = new RestClient(options.baseUrl + '/tenants/settings', clientOptions);
};
/**
* Update the tenant settings.
*
* @method updateSettings
* @memberOf module:management.TenantManager.prototype
*
* @example
* management.tenant.updateSettings(data, function (err) {
* if (err) {
* // Handle error.
* }
* });
*
* @param {Object} data The new tenant settings.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
TenantManager.prototype.updateSettings = function (data, cb) {
if (cb && cb instanceof Function) {
return this.tenant.patch({}, data, cb);
}
// Return a promise.
return this.tenant.patch({}, data);
};
/**
* Get the tenant settings..
*
* @method getSettings
* @memberOf module:management.TenantManager.prototype
*
* @example
* management.tenant.getSettings(function (err, settings) {
* if (err) {
* // Handle error.
* }
*
* console.log(settings);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
TenantManager.prototype.getSettings = function (cb) {
if (cb && cb instanceof Function) {
return this.tenant.get({}, cb);
}
// Return a promise.
return this.tenant.get({});
};
module.exports = TenantManager;