auth0 2.36.0 → 2.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +554 -0
  2. package/README.md +33 -11
  3. package/package.json +22 -15
  4. package/src/Auth0RestClient.js +72 -71
  5. package/src/RetryRestClient.js +78 -81
  6. package/src/auth/DatabaseAuthenticator.js +242 -259
  7. package/src/auth/OAUthWithIDTokenValidation.js +99 -103
  8. package/src/auth/OAuthAuthenticator.js +325 -344
  9. package/src/auth/PasswordlessAuthenticator.js +237 -252
  10. package/src/auth/TokensManager.js +231 -246
  11. package/src/auth/UsersManager.js +149 -160
  12. package/src/auth/idToken.js +22 -19
  13. package/src/auth/index.js +510 -581
  14. package/src/errors.js +23 -23
  15. package/src/index.js +3 -2
  16. package/src/management/ActionsManager.js +503 -585
  17. package/src/management/BlacklistedTokensManager.js +77 -84
  18. package/src/management/BrandingManager.js +141 -163
  19. package/src/management/ClientGrantsManager.js +132 -145
  20. package/src/management/ClientsManager.js +145 -161
  21. package/src/management/ConnectionsManager.js +215 -204
  22. package/src/management/CustomDomainsManager.js +140 -157
  23. package/src/management/DeviceCredentialsManager.js +95 -111
  24. package/src/management/EmailProviderManager.js +110 -128
  25. package/src/management/EmailTemplatesManager.js +96 -112
  26. package/src/management/GrantsManager.js +94 -101
  27. package/src/management/GuardianManager.js +381 -455
  28. package/src/management/HooksManager.js +283 -325
  29. package/src/management/JobsManager.js +310 -343
  30. package/src/management/LogStreamsManager.js +142 -158
  31. package/src/management/LogsManager.js +92 -99
  32. package/src/management/ManagementTokenProvider.js +112 -120
  33. package/src/management/MigrationsManager.js +81 -90
  34. package/src/management/OrganizationsManager.js +686 -761
  35. package/src/management/PromptsManager.js +160 -178
  36. package/src/management/ResourceServersManager.js +143 -160
  37. package/src/management/RolesManager.js +323 -369
  38. package/src/management/RulesConfigsManager.js +94 -110
  39. package/src/management/RulesManager.js +154 -176
  40. package/src/management/StatsManager.js +87 -103
  41. package/src/management/TenantManager.js +81 -97
  42. package/src/management/TicketsManager.js +107 -115
  43. package/src/management/UserBlocksManager.js +135 -162
  44. package/src/management/UsersManager.js +729 -852
  45. package/src/management/index.js +3094 -3619
  46. package/src/utils.js +31 -60
@@ -1,661 +1,579 @@
1
- var ArgumentError = require('rest-facade').ArgumentError;
2
- var utils = require('../utils');
3
- var Auth0RestClient = require('../Auth0RestClient');
4
- var RetryRestClient = require('../RetryRestClient');
1
+ const { ArgumentError } = require('rest-facade');
2
+ const Auth0RestClient = require('../Auth0RestClient');
3
+ const RetryRestClient = require('../RetryRestClient');
5
4
 
6
5
  /**
7
- * Simple facade for consuming a REST API endpoint.
8
- * @external RestClient
9
- * @see https://github.com/ngonzalvez/rest-facade
10
- */
11
-
12
- /**
13
- * @class ActionsManager
14
6
  * {@link https://auth0.com/docs/api/v2#!/Actions/get_actions Actions} provide a way to extend
15
7
  * Auth0 flows with custom logic.
16
8
  * See the {@link https://auth0.com/docs/actions Actions documentation} for more information.
17
- * @constructor
18
- * @memberOf module:management
19
- *
20
- * @param {Object} options The client options.
21
- * @param {String} options.baseUrl The URL of the API.
22
- * @param {Object} [options.headers] Headers to be included in all requests.
23
- * @param {Object} [options.retry] Retry Policy Config
24
9
  */
25
- var ActionsManager = function(options) {
26
- if (options === null || typeof options !== 'object') {
27
- throw new ArgumentError('Must provide client options');
28
- }
29
-
30
- if (options.baseUrl === null || options.baseUrl === undefined) {
31
- throw new ArgumentError('Must provide a base URL for the API');
32
- }
33
-
34
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
35
- throw new ArgumentError('The provided base URL is invalid');
36
- }
37
-
10
+ class ActionsManager {
38
11
  /**
39
- * Options object for the Rest Client instance.
40
- *
41
- * @type {Object}
12
+ * @param {object} options The client options.
13
+ * @param {string} options.baseUrl The URL of the API.
14
+ * @param {object} [options.headers] Headers to be included in all requests.
15
+ * @param {object} [options.retry] Retry Policy Config
42
16
  */
43
- var clientOptions = {
44
- errorFormatter: { message: 'message', name: 'error' },
45
- headers: options.headers,
46
- query: { repeatParams: false }
47
- };
17
+ constructor(options) {
18
+ if (options === null || typeof options !== 'object') {
19
+ throw new ArgumentError('Must provide client options');
20
+ }
21
+
22
+ if (options.baseUrl === null || options.baseUrl === undefined) {
23
+ throw new ArgumentError('Must provide a base URL for the API');
24
+ }
25
+
26
+ if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
27
+ throw new ArgumentError('The provided base URL is invalid');
28
+ }
29
+
30
+ /**
31
+ * Options object for the Rest Client instance.
32
+ *
33
+ * @type {object}
34
+ */
35
+ const clientOptions = {
36
+ errorFormatter: { message: 'message', name: 'error' },
37
+ headers: options.headers,
38
+ query: { repeatParams: false },
39
+ };
40
+
41
+ /**
42
+ * Provides an abstraction layer for consuming the
43
+ * [Auth0 Actions endpoint]{@link https://auth0.com/docs/api/v2#!/actions}.
44
+ *
45
+ * @type {external:RestClient}
46
+ */
47
+ const auth0RestClient = new Auth0RestClient(
48
+ `${options.baseUrl}/actions/actions/:id`,
49
+ clientOptions,
50
+ options.tokenProvider
51
+ );
52
+ this.resource = new RetryRestClient(auth0RestClient, options.retry);
53
+
54
+ const actionsDeployRestClient = new Auth0RestClient(
55
+ `${options.baseUrl}/actions/actions/:id/deploy`,
56
+ clientOptions,
57
+ options.tokenProvider
58
+ );
59
+ this.actionsDeploy = new RetryRestClient(actionsDeployRestClient, options.retry);
60
+
61
+ const actionsTestRestClient = new Auth0RestClient(
62
+ `${options.baseUrl}/actions/actions/:id/test`,
63
+ clientOptions,
64
+ options.tokenProvider
65
+ );
66
+ this.actionsTest = new RetryRestClient(actionsTestRestClient, options.retry);
67
+
68
+ const triggersRestClient = new Auth0RestClient(
69
+ `${options.baseUrl}/actions/triggers/:trigger_id`,
70
+ clientOptions,
71
+ options.tokenProvider
72
+ );
73
+ this.triggers = new RetryRestClient(triggersRestClient, options.retry);
74
+
75
+ const triggerBindingsRestClient = new Auth0RestClient(
76
+ `${options.baseUrl}/actions/triggers/:trigger_id/bindings`,
77
+ clientOptions,
78
+ options.tokenProvider
79
+ );
80
+ this.triggerBindings = new RetryRestClient(triggerBindingsRestClient, options.retry);
81
+
82
+ const executionsRestClient = new Auth0RestClient(
83
+ `${options.baseUrl}/actions/executions/:execution_id`,
84
+ clientOptions,
85
+ options.tokenProvider
86
+ );
87
+ this.executions = new RetryRestClient(executionsRestClient, options.retry);
88
+
89
+ const actionVersionRestClient = new Auth0RestClient(
90
+ `${options.baseUrl}/actions/actions/:id/versions/:version_id`,
91
+ clientOptions,
92
+ options.tokenProvider
93
+ );
94
+ this.actionVersions = new RetryRestClient(actionVersionRestClient, options.retry);
95
+
96
+ const deployActionVersionRestClient = new Auth0RestClient(
97
+ `${options.baseUrl}/actions/actions/:id/versions/:version_id/deploy`,
98
+ clientOptions,
99
+ options.tokenProvider
100
+ );
101
+ this.actionVersionDeploy = new RetryRestClient(deployActionVersionRestClient, options.retry);
102
+ }
48
103
 
49
104
  /**
50
- * Provides an abstraction layer for consuming the
51
- * [Auth0 Actions endpoint]{@link https://auth0.com/docs/api/v2#!/actions}.
105
+ * Get all Triggers.
52
106
  *
53
- * @type {external:RestClient}
107
+ * @example <caption>
108
+ * This method takes an optional object as first argument that may be used to
109
+ * specify pagination settings. If pagination options are not present,
110
+ * the first page of a limited number of results will be returned.
111
+ * </caption>
112
+ * // Pagination settings.
113
+ * var params = {
114
+ * per_page: 10,
115
+ * page: 0
116
+ * };
117
+ *
118
+ * management.actions.getAllTriggers(params, function (err, actions) {
119
+ * console.log(actions.length);
120
+ * });
121
+ * @param {object} [params] Actions parameters.
122
+ * @param {number} [params.per_page] Number of results per page.
123
+ * @param {number} [params.page] Page number, zero indexed.
124
+ * @param {Function} [cb] Callback function.
125
+ * @returns {Promise|undefined}
54
126
  */
55
- var auth0RestClient = new Auth0RestClient(
56
- options.baseUrl + '/actions/actions/:id',
57
- clientOptions,
58
- options.tokenProvider
59
- );
60
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
61
-
62
- var actionsDeployRestClient = new Auth0RestClient(
63
- options.baseUrl + '/actions/actions/:id/deploy',
64
- clientOptions,
65
- options.tokenProvider
66
- );
67
- this.actionsDeploy = new RetryRestClient(actionsDeployRestClient, options.retry);
68
-
69
- var actionsTestRestClient = new Auth0RestClient(
70
- options.baseUrl + '/actions/actions/:id/test',
71
- clientOptions,
72
- options.tokenProvider
73
- );
74
- this.actionsTest = new RetryRestClient(actionsTestRestClient, options.retry);
75
-
76
- var triggersRestClient = new Auth0RestClient(
77
- options.baseUrl + '/actions/triggers/:trigger_id',
78
- clientOptions,
79
- options.tokenProvider
80
- );
81
- this.triggers = new RetryRestClient(triggersRestClient, options.retry);
82
-
83
- var triggerBindingsRestClient = new Auth0RestClient(
84
- options.baseUrl + '/actions/triggers/:trigger_id/bindings',
85
- clientOptions,
86
- options.tokenProvider
87
- );
88
- this.triggerBindings = new RetryRestClient(triggerBindingsRestClient, options.retry);
89
-
90
- var executionsRestClient = new Auth0RestClient(
91
- options.baseUrl + '/actions/executions/:execution_id',
92
- clientOptions,
93
- options.tokenProvider
94
- );
95
- this.executions = new RetryRestClient(executionsRestClient, options.retry);
96
-
97
- var actionVersionRestClient = new Auth0RestClient(
98
- options.baseUrl + '/actions/actions/:id/versions/:version_id',
99
- clientOptions,
100
- options.tokenProvider
101
- );
102
- this.actionVersions = new RetryRestClient(actionVersionRestClient, options.retry);
103
-
104
- var deployActionVersionRestClient = new Auth0RestClient(
105
- options.baseUrl + '/actions/actions/:id/versions/:version_id/deploy',
106
- clientOptions,
107
- options.tokenProvider
108
- );
109
- this.actionVersionDeploy = new RetryRestClient(deployActionVersionRestClient, options.retry);
110
- };
127
+ getAllTriggers(params, cb) {
128
+ params = params || {};
111
129
 
112
- /**
113
- * Get all Triggers.
114
- *
115
- * @method getAllTriggers
116
- * @memberOf module:management.ActionsManager.prototype
117
- *
118
- * @example <caption>
119
- * This method takes an optional object as first argument that may be used to
120
- * specify pagination settings. If pagination options are not present,
121
- * the first page of a limited number of results will be returned.
122
- * </caption>
123
- * // Pagination settings.
124
- * var params = {
125
- * per_page: 10,
126
- * page: 0
127
- * };
128
- *
129
- * management.actions.getAllTriggers(params, function (err, actions) {
130
- * console.log(actions.length);
131
- * });
132
- *
133
- * @param {Object} [params] Actions parameters.
134
- * @param {Number} [params.per_page] Number of results per page.
135
- * @param {Number} [params.page] Page number, zero indexed.
136
- * @param {Function} [cb] Callback function.
137
- *
138
- * @return {Promise|undefined}
139
- */
140
- ActionsManager.prototype.getAllTriggers = function(params, cb) {
141
- params = params || {};
130
+ if (cb && cb instanceof Function) {
131
+ return this.triggers.getAll(params, cb);
132
+ }
142
133
 
143
- if (cb && cb instanceof Function) {
144
- return this.triggers.getAll(params, cb);
134
+ return this.triggers.getAll(params);
145
135
  }
146
136
 
147
- return this.triggers.getAll(params);
148
- };
137
+ /**
138
+ * Update the actions bound to a trigger .
139
+ *
140
+ * @example
141
+ * var data = { bindings: [{ id_type: "action_id", id_value: ACTION_ID1},{id_type: "action_name", id_value: ACTION_NAME2}];
142
+ * var params = { trigger_id: TRIGGER_ID };
143
+ *
144
+ * // Using auth0 instance.
145
+ * management.actions.updateTriggerBindings(params, data, function (err, bindings) {
146
+ * if (err) {
147
+ * // Handle error.
148
+ * }
149
+ *
150
+ * console.log(bindings.length); // 2
151
+ * });
152
+ * @param {object} params Actions Binding parameters.
153
+ * @param {string} params.trigger_id Actions Trigger ID.
154
+ * @param {object} data bindings array
155
+ * @param {Function} [cb] Callback function.
156
+ * @returns {Promise|undefined}
157
+ */
158
+ updateTriggerBindings(params, data, cb) {
159
+ params = params || {};
149
160
 
150
- /**
151
- * Update the actions bound to a trigger .
152
- *
153
- * @method updateTriggerBindings
154
- * @memberOf module:management.ActionsManager.prototype
155
- *
156
- * @example
157
- * var data = { bindings: [{ id_type: "action_id", id_value: ACTION_ID1},{id_type: "action_name", id_value: ACTION_NAME2}];
158
- * var params = { trigger_id: TRIGGER_ID };
159
- *
160
- * // Using auth0 instance.
161
- * management.actions.updateTriggerBindings(params, data, function (err, bindings) {
162
- * if (err) {
163
- * // Handle error.
164
- * }
165
- *
166
- * console.log(bindings.length); // 2
167
- * });
168
- *
169
- * @param {Object} params Actions Binding parameters.
170
- * @param {String} params.trigger_id Actions Trigger ID.
171
- * @param {Object} data bindings array
172
- * @param {Function} [cb] Callback function.
173
- *
174
- * @return {Promise|undefined}
175
- */
176
- ActionsManager.prototype.updateTriggerBindings = function(params, data, cb) {
177
- params = params || {};
161
+ if (cb && cb instanceof Function) {
162
+ return this.triggerBindings.patch(params, data, cb);
163
+ }
178
164
 
179
- if (cb && cb instanceof Function) {
180
- return this.triggerBindings.patch(params, data, cb);
165
+ return this.triggerBindings.patch(params, data);
181
166
  }
182
167
 
183
- return this.triggerBindings.patch(params, data);
184
- };
168
+ /**
169
+ * Get the actions bound to a trigger .
170
+ *
171
+ * @example
172
+ * var params = { trigger_id: TRIGGER_ID };
173
+ *
174
+ * // Using auth0 instance.
175
+ * management.actions.getTriggerBindings(params, function (err, bindings) {
176
+ * if (err) {
177
+ * // Handle error.
178
+ * }
179
+ *
180
+ * console.log(bindings.length); // 2
181
+ * });
182
+ * @param {object} params Actions Binding parameters.
183
+ * @param {string} params.trigger_id Actions Trigger ID.
184
+ * @param {Function} [cb] Callback function.
185
+ * @returns {Promise|undefined}
186
+ */
187
+ getTriggerBindings(params, cb) {
188
+ params = params || {};
185
189
 
186
- /**
187
- * Get the actions bound to a trigger .
188
- *
189
- * @method getTriggerBindings
190
- * @memberOf module:management.ActionsManager.prototype
191
- *
192
- * @example
193
- * var params = { trigger_id: TRIGGER_ID };
194
- *
195
- * // Using auth0 instance.
196
- * management.actions.getTriggerBindings(params, function (err, bindings) {
197
- * if (err) {
198
- * // Handle error.
199
- * }
200
- *
201
- * console.log(bindings.length); // 2
202
- * });
203
- *
204
- * @param {Object} params Actions Binding parameters.
205
- * @param {String} params.trigger_id Actions Trigger ID.
206
- * @param {Function} [cb] Callback function.
207
- *
208
- * @return {Promise|undefined}
209
- */
210
- ActionsManager.prototype.getTriggerBindings = function(params, cb) {
211
- params = params || {};
190
+ if (cb && cb instanceof Function) {
191
+ return this.triggerBindings.getAll(params, cb);
192
+ }
212
193
 
213
- if (cb && cb instanceof Function) {
214
- return this.triggerBindings.getAll(params, cb);
194
+ return this.triggerBindings.getAll(params);
215
195
  }
216
196
 
217
- return this.triggerBindings.getAll(params);
218
- };
197
+ /**
198
+ * Create a new Action.
199
+ *
200
+ * @example
201
+ * management.actions.create(data, function (err) {
202
+ * if (err) {
203
+ * // Handle error.
204
+ * }
205
+ *
206
+ * // Action created.
207
+ * });
208
+ * @param {object} data Action data object.
209
+ * @param {Function} [cb] Callback function.
210
+ * @returns {Promise|undefined}
211
+ */
212
+ create(...args) {
213
+ return this.resource.create(...args);
214
+ }
219
215
 
220
- /**
221
- * Create a new Action.
222
- *
223
- * @method create
224
- * @memberOf module:management.ActionsManager.prototype
225
- *
226
- * @example
227
- * management.actions.create(data, function (err) {
228
- * if (err) {
229
- * // Handle error.
230
- * }
231
- *
232
- * // Action created.
233
- * });
234
- *
235
- * @param {Object} data Action data object.
236
- * @param {Function} [cb] Callback function.
237
- *
238
- * @return {Promise|undefined}
239
- */
240
- utils.wrapPropertyMethod(ActionsManager, 'create', 'resource.create');
216
+ /**
217
+ * Get all actions.
218
+ *
219
+ * @example <caption>
220
+ * This method takes an optional object as first argument that may be used to
221
+ * specify pagination settings. If pagination options are not present,
222
+ * the first page of a limited number of results will be returned.
223
+ * </caption>
224
+ * // Pagination settings.
225
+ * var params = {
226
+ * per_page: 10,
227
+ * page: 0,
228
+ * triggerId:'TRIGGER_ID',
229
+ * actionName: 'ACTION_NAME'
230
+ * };
231
+ *
232
+ * management.actions.getAll(params, function (err, actions) {
233
+ * console.log(actions.length);
234
+ * });
235
+ * @param {object} [params] Actions parameters.
236
+ * @param {number} [params.per_page] Number of results per page.
237
+ * @param {number} [params.page] Page number, zero indexed.
238
+ * @param {string} [params.triggerId] The trigger ID of the actions to retrieve.
239
+ * @param {string} [params.actionName] The name of the actions to retrieve.
240
+ * @param {Function} [cb] Callback function.
241
+ * @returns {Promise|undefined}
242
+ */
243
+ getAll(...args) {
244
+ return this.resource.getAll(...args);
245
+ }
241
246
 
242
- /**
243
- * Get all actions.
244
- *
245
- * @method getAll
246
- * @memberOf module:management.ActionsManager.prototype
247
- *
248
- * @example <caption>
249
- * This method takes an optional object as first argument that may be used to
250
- * specify pagination settings. If pagination options are not present,
251
- * the first page of a limited number of results will be returned.
252
- * </caption>
253
- * // Pagination settings.
254
- * var params = {
255
- * per_page: 10,
256
- * page: 0,
257
- * triggerId:'TRIGGER_ID',
258
- * actionName: 'ACTION_NAME'
259
- * };
260
- *
261
- * management.actions.getAll(params, function (err, actions) {
262
- * console.log(actions.length);
263
- * });
264
- *
265
- * @param {Object} [params] Actions parameters.
266
- * @param {Number} [params.per_page] Number of results per page.
267
- * @param {Number} [params.page] Page number, zero indexed.
268
- * @param {String} [params.triggerId] The trigger ID of the actions to retrieve.
269
- * @param {String} [params.actionName] The name of the actions to retrieve.
270
- * @param {Function} [cb] Callback function.
271
- *
272
- * @return {Promise|undefined}
273
- */
274
- utils.wrapPropertyMethod(ActionsManager, 'getAll', 'resource.getAll');
247
+ /**
248
+ * Get an Auth0 action.
249
+ *
250
+ * @example
251
+ * management.actions.get({ id: ACTION_ID }, function (err, action) {
252
+ * if (err) {
253
+ * // Handle error.
254
+ * }
255
+ *
256
+ * console.log(action);
257
+ * });
258
+ * @param {object} params Action parameters.
259
+ * @param {string} params.id Action ID.
260
+ * @param {Function} [cb] Callback function.
261
+ * @returns {Promise|undefined}
262
+ */
263
+ get(params, cb) {
264
+ params = params || {};
275
265
 
276
- /**
277
- * Get an Auth0 action.
278
- *
279
- * @method get
280
- * @memberOf module:management.ActionsManager.prototype
281
- *
282
- * @example
283
- * management.actions.get({ id: ACTION_ID }, function (err, action) {
284
- * if (err) {
285
- * // Handle error.
286
- * }
287
- *
288
- * console.log(action);
289
- * });
290
- *
291
- * @param {Object} params Action parameters.
292
- * @param {String} params.id Action ID.
293
- * @param {Function} [cb] Callback function.
294
- *
295
- * @return {Promise|undefined}
296
- */
297
- ActionsManager.prototype.get = function(params, cb) {
298
- params = params || {};
266
+ if (params.action_id) {
267
+ params.id = params.action_id;
268
+ delete params.action_id;
269
+ }
299
270
 
300
- if (params.action_id) {
301
- params.id = params.action_id;
302
- delete params.action_id;
303
- }
271
+ if (cb && cb instanceof Function) {
272
+ return this.resource.get(params, cb);
273
+ }
304
274
 
305
- if (cb && cb instanceof Function) {
306
- return this.resource.get(params, cb);
275
+ return this.resource.get(params);
307
276
  }
308
277
 
309
- return this.resource.get(params);
310
- };
278
+ /**
279
+ * Update an existing action.
280
+ *
281
+ * @example
282
+ * var data = { name: 'new-name' };
283
+ * var params = { id: ACTION_ID };
284
+ *
285
+ * // Using auth0 instance.
286
+ * management.updateAction(params, data, function (err, action) {
287
+ * if (err) {
288
+ * // Handle error.
289
+ * }
290
+ *
291
+ * console.log(action.name); // 'new-name'
292
+ * });
293
+ *
294
+ * // Using the Actions manager directly.
295
+ * management.actions.update(params, data, function (err, action) {
296
+ * if (err) {
297
+ * // Handle error.
298
+ * }
299
+ *
300
+ * console.log(action.name); // 'new-name'
301
+ * });
302
+ * @param {object} params Action parameters.
303
+ * @param {string} params.id Action ID.
304
+ * @param {object} data Updated action data.
305
+ * @param {Function} [cb] Callback function.
306
+ * @returns {Promise|undefined}
307
+ */
308
+ update(params, data, cb) {
309
+ params = params || {};
311
310
 
312
- /**
313
- * Update an existing action.
314
- *
315
- * @method update
316
- * @memberOf module:management.ActionsManager.prototype
317
- *
318
- * @example
319
- * var data = { name: 'new-name' };
320
- * var params = { id: ACTION_ID };
321
- *
322
- * // Using auth0 instance.
323
- * management.updateAction(params, data, function (err, action) {
324
- * if (err) {
325
- * // Handle error.
326
- * }
327
- *
328
- * console.log(action.name); // 'new-name'
329
- * });
330
- *
331
- * // Using the Actions manager directly.
332
- * management.actions.update(params, data, function (err, action) {
333
- * if (err) {
334
- * // Handle error.
335
- * }
336
- *
337
- * console.log(action.name); // 'new-name'
338
- * });
339
- *
340
- * @param {Object} params Action parameters.
341
- * @param {String} params.id Action ID.
342
- * @param {Object} data Updated action data.
343
- * @param {Function} [cb] Callback function.
344
- *
345
- * @return {Promise|undefined}
346
- */
347
- ActionsManager.prototype.update = function(params, data, cb) {
348
- params = params || {};
311
+ if (params.action_id) {
312
+ params.id = params.action_id;
313
+ delete params.action_id;
314
+ }
349
315
 
350
- if (params.action_id) {
351
- params.id = params.action_id;
352
- delete params.action_id;
353
- }
316
+ if (cb && cb instanceof Function) {
317
+ return this.resource.patch(params, data, cb);
318
+ }
354
319
 
355
- if (cb && cb instanceof Function) {
356
- return this.resource.patch(params, data, cb);
320
+ return this.resource.patch(params, data);
357
321
  }
358
322
 
359
- return this.resource.patch(params, data);
360
- };
323
+ /**
324
+ * Delete an existing action. Deleting an Action deletes all the action's versions
325
+ *
326
+ * @example
327
+ * management.actions.delete({ id: ACTION_ID }, function (err) {
328
+ * if (err) {
329
+ * // Handle error.
330
+ * }
331
+ *
332
+ * // Action deleted.
333
+ * });
334
+ * @param {object} params Action parameters.
335
+ * @param {string} params.id Action ID.
336
+ * @param {Function} [cb] Callback function.
337
+ * @returns {Promise|undefined}
338
+ */
339
+ delete(params, cb) {
340
+ params = params || {};
361
341
 
362
- /**
363
- * Delete an existing action. Deleting an Action deletes all the action's versions
364
- *
365
- * @method delete
366
- * @memberOf module:management.ActionsManager.prototype
367
- *
368
- * @example
369
- * management.actions.delete({ id: ACTION_ID }, function (err) {
370
- * if (err) {
371
- * // Handle error.
372
- * }
373
- *
374
- * // Action deleted.
375
- * });
376
- *
377
- * @param {Object} params Action parameters.
378
- * @param {String} params.id Action ID.
379
- * @param {Function} [cb] Callback function.
380
- *
381
- * @return {Promise|undefined}
382
- */
383
- ActionsManager.prototype.delete = function(params, cb) {
384
- params = params || {};
342
+ if (params.action_id) {
343
+ params.id = params.action_id;
344
+ delete params.action_id;
345
+ }
385
346
 
386
- if (params.action_id) {
387
- params.id = params.action_id;
388
- delete params.action_id;
389
- }
347
+ if (cb && cb instanceof Function) {
348
+ return this.resource.delete(params, cb);
349
+ }
390
350
 
391
- if (cb && cb instanceof Function) {
392
- return this.resource.delete(params, cb);
351
+ return this.resource.delete(params);
393
352
  }
394
353
 
395
- return this.resource.delete(params);
396
- };
354
+ /**
355
+ * test an Action.
356
+ *
357
+ * @example
358
+ * var params = { id: ACTION_ID};
359
+ * management.actions.test(params, payload, function (err) {
360
+ * if (err) {
361
+ * // Handle error.
362
+ * }
363
+ * });
364
+ * @param {object} params Action parameters.
365
+ * @param {string} params.id Action ID.
366
+ * @param {object} payload Payload represents the entire structure necessary to test a particular trigger
367
+ * @param {Function} [cb] Callback function.
368
+ * @returns {Promise|undefined}
369
+ */
370
+ test(params, payload, cb) {
371
+ params = params || {};
372
+ payload = payload || {};
397
373
 
398
- /**
399
- * test an Action.
400
- *
401
- * @method test
402
- * @memberOf module:management.ActionsManager.prototype
403
- *
404
- * @example
405
- * var params = { id: ACTION_ID};
406
- * management.actions.test(params, payload, function (err) {
407
- * if (err) {
408
- * // Handle error.
409
- * }
410
-
411
- * });
412
- *
413
- * @param {Object} params Action parameters.
414
- * @param {String} params.id Action ID.
415
- * @param {Object} payload Payload represents the entire structure necessary to test a particular trigger
416
- * @param {Function} [cb] Callback function.
417
- *
418
- * @return {Promise|undefined}
419
- */
420
- ActionsManager.prototype.test = function(params, payload, cb) {
421
- params = params || {};
422
- payload = payload || {};
374
+ if (params.action_id) {
375
+ params.id = params.action_id;
376
+ delete params.action_id;
377
+ }
423
378
 
424
- if (params.action_id) {
425
- params.id = params.action_id;
426
- delete params.action_id;
427
- }
379
+ if (cb && cb instanceof Function) {
380
+ return this.actionsTest.create(params, payload, cb);
381
+ }
428
382
 
429
- if (cb && cb instanceof Function) {
430
- return this.actionsTest.create(params, payload, cb);
383
+ return this.actionsTest.create(params, payload);
431
384
  }
432
385
 
433
- return this.actionsTest.create(params, payload);
434
- };
386
+ /**
387
+ * deploy an Action.
388
+ * The action must be in a state of 'built' before it can be deployed.
389
+ *
390
+ * @example
391
+ * var params = { id: ACTION_ID};
392
+ * mangement.actions.deploy(params, function (err, actionVersion) {
393
+ * if (err) {
394
+ * // Handle error.
395
+ * }
396
+ * });
397
+ * @param {object} params Action parameters.
398
+ * @param {string} params.id Action ID.
399
+ * @param {Function} [cb] Callback function.
400
+ * @returns {Promise|undefined}
401
+ */
402
+ deploy(params, cb) {
403
+ params = params || {};
435
404
 
436
- /**
437
- * deploy an Action.
438
- * The action must be in a state of 'built' before it can be deployed.
439
- *
440
- * @method deploy
441
- * @memberOf module:management.ActionsManager.prototype
442
- *
443
- * @example
444
- * var params = { id: ACTION_ID};
445
- * mangement.actions.deploy(params, function (err, actionVersion) {
446
- * if (err) {
447
- * // Handle error.
448
- * }
449
-
450
- * });
451
- *
452
- * @param {Object} params Action parameters.
453
- * @param {String} params.id Action ID.
454
- * @param {Function} [cb] Callback function.
455
- *
456
- * @return {Promise|undefined}
457
- */
458
- ActionsManager.prototype.deploy = function(params, cb) {
459
- params = params || {};
405
+ if (params.action_id) {
406
+ params.id = params.action_id;
407
+ delete params.action_id;
408
+ }
460
409
 
461
- if (params.action_id) {
462
- params.id = params.action_id;
463
- delete params.action_id;
464
- }
410
+ if (cb && cb instanceof Function) {
411
+ return this.actionsDeploy.create(params, {}, cb);
412
+ }
465
413
 
466
- if (cb && cb instanceof Function) {
467
- return this.actionsDeploy.create(params, {}, cb);
414
+ return this.actionsDeploy.create(params, {});
468
415
  }
469
416
 
470
- return this.actionsDeploy.create(params, {});
471
- };
417
+ /**
418
+ * Get all action versions
419
+ *
420
+ * @example <caption>
421
+ * This method takes an optional object as first argument that may be used to
422
+ * specify pagination settings. If pagination options are not present,
423
+ * the first page of a limited number of results will be returned.
424
+ * </caption>
425
+ * // Pagination settings.
426
+ * var params = {
427
+ * per_page: 10,
428
+ * page: 0
429
+ * };
430
+ *
431
+ * management.actions.getVersions({ id: ACTION_ID }, function (err, actionVersions) {
432
+ * console.log(actionVersions.length);
433
+ * });
434
+ * @param {object} [params] ActionVersions parameters.
435
+ * @param {number} [params.per_page] Number of results per page.
436
+ * @param {number} [params.page] Page number, zero indexed.
437
+ * @param {string} [params.id] Action ID.
438
+ * @param {Function} [cb] Callback function.
439
+ * @returns {Promise|undefined}
440
+ */
441
+ getVersions(params, cb) {
442
+ params = params || {};
472
443
 
473
- /**
474
- * Get all action versions
475
- *
476
- * @method getVersions
477
- * @memberOf module:management.ActionsManager.prototype
478
- *
479
- * @example <caption>
480
- * This method takes an optional object as first argument that may be used to
481
- * specify pagination settings. If pagination options are not present,
482
- * the first page of a limited number of results will be returned.
483
- * </caption>
484
- * // Pagination settings.
485
- * var params = {
486
- * per_page: 10,
487
- * page: 0
488
- * };
489
- *
490
- * management.actions.getVersions({ id: ACTION_ID }, function (err, actionVersions) {
491
- * console.log(actionVersions.length);
492
- * });
493
- *
494
- * @param {Object} [params] ActionVersions parameters.
495
- * @param {Number} [params.per_page] Number of results per page.
496
- * @param {Number} [params.page] Page number, zero indexed.
497
- * @param {String} [params.id] Action ID.
498
- * @param {Function} [cb] Callback function.
499
- *
500
- * @return {Promise|undefined}
501
- */
502
- ActionsManager.prototype.getVersions = function(params, cb) {
503
- params = params || {};
444
+ if (params.action_id) {
445
+ params.id = params.action_id;
446
+ delete params.action_id;
447
+ }
504
448
 
505
- if (params.action_id) {
506
- params.id = params.action_id;
507
- delete params.action_id;
508
- }
449
+ if (cb && cb instanceof Function) {
450
+ return this.actionVersions.getAll(params, cb);
451
+ }
509
452
 
510
- if (cb && cb instanceof Function) {
511
- return this.actionVersions.getAll(params, cb);
453
+ return this.actionVersions.getAll(params);
512
454
  }
513
455
 
514
- return this.actionVersions.getAll(params);
515
- };
456
+ /**
457
+ * Get an Action Version.
458
+ *
459
+ * @example
460
+ * var params = { id: ACTION_ID, version_id: VERSION_ID };
461
+ * management.actions.getVersion(params, function (err, actionVersion) {
462
+ * if (err) {
463
+ * // Handle error.
464
+ * }
465
+ * });
466
+ * @param {object} params Action parameters.
467
+ * @param {string} params.id Action ID.
468
+ * @param {string} params.version_id ActionVersion ID.
469
+ * @param {Function} [cb] Callback function.
470
+ * @returns {Promise|undefined}
471
+ */
472
+ getVersion(params, cb) {
473
+ params = params || {};
516
474
 
517
- /**
518
- * Get an Action Version.
519
- *
520
- * @method getVersion
521
- * @memberOf module:management.ActionsManager.prototype
522
- *
523
- * @example
524
- * var params = { id: ACTION_ID, version_id: VERSION_ID };
525
- * management.actions.getVersion(params, function (err, actionVersion) {
526
- * if (err) {
527
- * // Handle error.
528
- * }
529
-
530
- * });
531
- *
532
- * @param {Object} params Action parameters.
533
- * @param {String} params.id Action ID.
534
- * @param {String} params.version_id ActionVersion ID.
535
- * @param {Function} [cb] Callback function.
536
- *
537
- * @return {Promise|undefined}
538
- */
539
- ActionsManager.prototype.getVersion = function(params, cb) {
540
- params = params || {};
475
+ if (params.action_id) {
476
+ params.id = params.action_id;
477
+ delete params.action_id;
478
+ }
541
479
 
542
- if (params.action_id) {
543
- params.id = params.action_id;
544
- delete params.action_id;
545
- }
480
+ if (cb && cb instanceof Function) {
481
+ return this.actionVersions.get(params, cb);
482
+ }
546
483
 
547
- if (cb && cb instanceof Function) {
548
- return this.actionVersions.get(params, cb);
484
+ return this.actionVersions.get(params);
549
485
  }
550
486
 
551
- return this.actionVersions.get(params);
552
- };
487
+ /**
488
+ * Create an Action Version. In general, updating an action and then
489
+ * deploying it is the preferred way of creating an action version, but
490
+ * this operation is supported as a way of creating versions without
491
+ * updating the action's code (which can be useful in some CI/CD scenarios).
492
+ *
493
+ * @example
494
+ * var params = { id: ACTION_ID };
495
+ * management.actions.createActionVersion(params, data, function (err, actionVersion) {
496
+ * if (err) {
497
+ * // Handle error.
498
+ * }
499
+ * });
500
+ * @param {object} params Action parameters.
501
+ * @param {string} params.id Action ID.
502
+ * @param {object} data ActionVersion parameters.
503
+ * @param {Function} [cb] Callback function.
504
+ * @returns {Promise|undefined}
505
+ */
506
+ createVersion(params, data, cb) {
507
+ params = params || {};
553
508
 
554
- /**
555
- * Create an Action Version. In general, updating an action and then
556
- * deploying it is the preferred way of creating an action version, but
557
- * this operation is supported as a way of creating versions without
558
- * updating the action's code (which can be useful in some CI/CD scenarios).
559
- *
560
- * @method createVersion
561
- * @memberOf module:management.ActionsManager.prototype
562
- *
563
- * @example
564
- * var params = { id: ACTION_ID };
565
- * management.actions.createActionVersion(params, data, function (err, actionVersion) {
566
- * if (err) {
567
- * // Handle error.
568
- * }
569
- * });
570
- *
571
- * @param {Object} params Action parameters.
572
- * @param {String} params.id Action ID.
573
- * @param {Object} data ActionVersion parameters.
574
- * @param {Function} [cb] Callback function.
575
- *
576
- * @return {Promise|undefined}
577
- */
578
- ActionsManager.prototype.createVersion = function(params, data, cb) {
579
- params = params || {};
509
+ if (params.action_id) {
510
+ params.id = params.action_id;
511
+ delete params.action_id;
512
+ }
580
513
 
581
- if (params.action_id) {
582
- params.id = params.action_id;
583
- delete params.action_id;
584
- }
514
+ if (cb && cb instanceof Function) {
515
+ return this.actionVersions.create(params, data, cb);
516
+ }
585
517
 
586
- if (cb && cb instanceof Function) {
587
- return this.actionVersions.create(params, data, cb);
518
+ return this.actionVersions.create(params, data);
588
519
  }
589
520
 
590
- return this.actionVersions.create(params, data);
591
- };
521
+ /**
522
+ * deploy an Action Version to roll back to a previous version.
523
+ *
524
+ * @example
525
+ * var params = { id: ACTION_ID, version_id: VERSION_ID };
526
+ * management.actions.deployVersion(params, function (err, actionVersion) {
527
+ * if (err) {
528
+ * // Handle error.
529
+ * }
530
+ * });
531
+ * @param {object} params Action parameters.
532
+ * @param {string} params.id Action ID.
533
+ * @param {string} params.version_id Action ID.
534
+ * @param {Function} [cb] Callback function.
535
+ * @returns {Promise|undefined}
536
+ */
537
+ deployVersion(params, cb) {
538
+ params = params || {};
592
539
 
593
- /**
594
- * deploy an Action Version to roll back to a previous version.
595
- *
596
- * @method deployVersion
597
- * @memberOf module:management.ActionsManager.prototype
598
- *
599
- * @example
600
- * var params = { id: ACTION_ID, version_id: VERSION_ID };
601
- * management.actions.deployVersion(params, function (err, actionVersion) {
602
- * if (err) {
603
- * // Handle error.
604
- * }
605
-
606
- * });
607
- *
608
- * @param {Object} params Action parameters.
609
- * @param {String} params.id Action ID.
610
- * @param {String} params.version_id Action ID.
611
- * @param {Function} [cb] Callback function.
612
- *
613
- * @return {Promise|undefined}
614
- */
615
- ActionsManager.prototype.deployVersion = function(params, cb) {
616
- params = params || {};
540
+ if (params.action_id) {
541
+ params.id = params.action_id;
542
+ delete params.action_id;
543
+ }
617
544
 
618
- if (params.action_id) {
619
- params.id = params.action_id;
620
- delete params.action_id;
621
- }
545
+ if (cb && cb instanceof Function) {
546
+ return this.actionVersionDeploy.create(params, {}, cb);
547
+ }
622
548
 
623
- if (cb && cb instanceof Function) {
624
- return this.actionVersionDeploy.create(params, {}, cb);
549
+ return this.actionVersionDeploy.create(params, {});
625
550
  }
626
551
 
627
- return this.actionVersionDeploy.create(params, {});
628
- };
552
+ /**
553
+ * Get an execution by ID.
554
+ *
555
+ * @example
556
+ * management.actions.getExecution({ execution_id: EXECUTION_ID }, function (err, action) {
557
+ * if (err) {
558
+ * // Handle error.
559
+ * }
560
+ *
561
+ * console.log(ActionExecution);
562
+ * });
563
+ * @param {object} params Action Execution parameters.
564
+ * @param {string} params.id Action Execution ID.
565
+ * @param {Function} [cb] Callback function.
566
+ * @returns {Promise|undefined}
567
+ */
568
+ getExecution(params, cb) {
569
+ params = params || {};
629
570
 
630
- /**
631
- * Get an execution by ID.
632
- *
633
- * @method getExecution
634
- * @memberOf module:management.ActionExecutionsManager.prototype
635
- *
636
- * @example
637
- * management.actions.getExecution({ execution_id: EXECUTION_ID }, function (err, action) {
638
- * if (err) {
639
- * // Handle error.
640
- * }
641
- *
642
- * console.log(ActionExecution);
643
- * });
644
- *
645
- * @param {Object} params Action Execution parameters.
646
- * @param {String} params.id Action Execution ID.
647
- * @param {Function} [cb] Callback function.
648
- *
649
- * @return {Promise|undefined}
650
- */
651
- ActionsManager.prototype.getExecution = function(params, cb) {
652
- params = params || {};
571
+ if (cb && cb instanceof Function) {
572
+ return this.executions.get(params, cb);
573
+ }
653
574
 
654
- if (cb && cb instanceof Function) {
655
- return this.executions.get(params, cb);
575
+ return this.executions.get(params);
656
576
  }
657
-
658
- return this.executions.get(params);
659
- };
577
+ }
660
578
 
661
579
  module.exports = ActionsManager;