-
Notifications
You must be signed in to change notification settings - Fork 303
/
ConnectionsManager.js
167 lines (149 loc) · 4.22 KB
/
ConnectionsManager.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
var RestClient = require('rest-facade').Client;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');
/**
* @class ConnectionsManager
* Represents the relationship between Auth0 and an Identity provider.
* @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 ConnectionsManager = function (options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client 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');
}
/**
* Options object for the Rest Client instance.
*
* @type {Object}
*/
var apiOptions = {
headers: options.headers,
query: { repeatParams: false }
};
/**
* Provides an abstraction layer for performing CRUD operations on
* {@link https://auth0.com/docs/api/v2#!/ConnectionsManagers Auth0
* Connections}.
*
* @type {external:RestClient}
*/
this.resource = new RestClient(options.baseUrl + '/connections/:id ', apiOptions);
};
/**
* Create a new connection.
*
* @method create
* @memberOf module:management.ConnectionsManager.prototype
*
* @example
* management.connections.create(data, function (err) {
* if (err) {
* // Handle error.
* }
*
* // Conection created.
* });
*
* @param {Object} data Connection data object.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ConnectionsManager, 'create', 'resource.create');
/**
* Get all connections.
*
* @method getAll
* @memberOf module:management.ConnectionsManager.prototype
*
* @example
* management.connections.getAll(function (err, connections) {
* console.log(connections.length);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ConnectionsManager, 'getAll', 'resource.getAll');
/**
* Get an Auth0 connection.
*
* @method get
* @memberOf module:management.ConnectionsManager.prototype
*
* @example
* management.connections.get({ id: CONNECTION_ID }, function (err, connection) {
* if (err) {
* // Handle error.
* }
*
* console.log(connection);
* });
*
* @param {Object} params Connection parameters.
* @param {String} params.id Connection ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ConnectionsManager, 'get', 'resource.get');
/**
* Update an existing connection.
*
* @method update
* @memberOf module:management.ConnectionsManager.prototype
*
* @example
* var data = { name: 'newConnectionName' };
* var params = { id: CONNECTION_ID };
*
* management.connections.update(params, data, function (err, connection) {
* if (err) {
* // Handle error.
* }
*
* console.log(connection.name); // 'newConnectionName'
* });
*
* @param {Object} params Conneciton parameters.
* @param {String} params.id Connection ID.
* @param {Object} data Updated connection data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ConnectionsManager, 'update', 'resource.patch');
/**
* Delete an existing connection.
*
* @method delete
* @memberOf module:management.ConnectionsManager.prototype
*
* @example
* management.connections.delete({ id: CONNECTION_ID }, function (err) {
* if (err) {
* // Handle error.
* }
*
* // Conection deleted.
* });
*
* @param {Object} params Connection parameters.
* @param {String} params.id Connection ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ConnectionsManager, 'delete', 'resource.delete');
module.exports = ConnectionsManager;