auth0 2.36.2 → 2.39.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 +41 -0
  2. package/README.md +33 -11
  3. package/package.json +22 -14
  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 +238 -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 +510 -584
  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 -182
  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,587 @@
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');
10
+ class ActionsManager {
11
+ /**
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
16
+ */
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);
36
102
  }
37
103
 
38
104
  /**
39
- * Options object for the Rest Client instance.
105
+ * Get all Triggers.
40
106
  *
41
- * @type {Object}
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}
42
126
  */
43
- var clientOptions = {
44
- errorFormatter: { message: 'message', name: 'error' },
45
- headers: options.headers,
46
- query: { repeatParams: false }
47
- };
127
+ getAllTriggers(params, cb) {
128
+ params = params || {};
129
+
130
+ if (cb && cb instanceof Function) {
131
+ return this.triggers.getAll(params, cb);
132
+ }
133
+
134
+ return this.triggers.getAll(params);
135
+ }
48
136
 
49
137
  /**
50
- * Provides an abstraction layer for consuming the
51
- * [Auth0 Actions endpoint]{@link https://auth0.com/docs/api/v2#!/actions}.
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 };
52
143
  *
53
- * @type {external:RestClient}
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}
54
157
  */
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
- };
158
+ updateTriggerBindings(params, data, cb) {
159
+ params = params || {};
111
160
 
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 || {};
161
+ if (cb && cb instanceof Function) {
162
+ return this.triggerBindings.patch(params, data, cb);
163
+ }
142
164
 
143
- if (cb && cb instanceof Function) {
144
- return this.triggers.getAll(params, cb);
165
+ return this.triggerBindings.patch(params, data);
145
166
  }
146
167
 
147
- return this.triggers.getAll(params);
148
- };
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 || {};
149
189
 
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 || {};
190
+ if (cb && cb instanceof Function) {
191
+ return this.triggerBindings.getAll(params, cb);
192
+ }
178
193
 
179
- if (cb && cb instanceof Function) {
180
- return this.triggerBindings.patch(params, data, cb);
194
+ return this.triggerBindings.getAll(params);
181
195
  }
182
196
 
183
- return this.triggerBindings.patch(params, data);
184
- };
185
-
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 || {};
212
-
213
- if (cb && cb instanceof Function) {
214
- return this.triggerBindings.getAll(params, cb);
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);
215
214
  }
216
215
 
217
- return this.triggerBindings.getAll(params);
218
- };
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
+ }
219
246
 
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');
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 || {};
241
265
 
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');
266
+ if (params.action_id) {
267
+ params.id = params.action_id;
268
+ delete params.action_id;
269
+ }
275
270
 
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 || {};
271
+ if (cb && cb instanceof Function) {
272
+ return this.resource.get(params, cb);
273
+ }
299
274
 
300
- if (params.action_id) {
301
- params.id = params.action_id;
302
- delete params.action_id;
275
+ return this.resource.get(params);
303
276
  }
304
277
 
305
- if (cb && cb instanceof Function) {
306
- return this.resource.get(params, cb);
307
- }
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 || {};
308
310
 
309
- return this.resource.get(params);
310
- };
311
+ if (params.action_id) {
312
+ params.id = params.action_id;
313
+ delete params.action_id;
314
+ }
311
315
 
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 || {};
316
+ if (cb && cb instanceof Function) {
317
+ return this.resource.patch(params, data, cb);
318
+ }
349
319
 
350
- if (params.action_id) {
351
- params.id = params.action_id;
352
- delete params.action_id;
320
+ return this.resource.patch(params, data);
353
321
  }
354
322
 
355
- if (cb && cb instanceof Function) {
356
- return this.resource.patch(params, data, cb);
357
- }
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 || {};
358
341
 
359
- return this.resource.patch(params, data);
360
- };
342
+ if (params.action_id) {
343
+ params.id = params.action_id;
344
+ delete params.action_id;
345
+ }
361
346
 
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 || {};
347
+ if (cb && cb instanceof Function) {
348
+ return this.resource.delete(params, cb);
349
+ }
385
350
 
386
- if (params.action_id) {
387
- params.id = params.action_id;
388
- delete params.action_id;
351
+ return this.resource.delete(params);
389
352
  }
390
353
 
391
- if (cb && cb instanceof Function) {
392
- return this.resource.delete(params, cb);
393
- }
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 || {};
394
373
 
395
- return this.resource.delete(params);
396
- };
374
+ if (params.action_id) {
375
+ params.id = params.action_id;
376
+ delete params.action_id;
377
+ }
397
378
 
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 || {};
379
+ if (cb && cb instanceof Function) {
380
+ return this.actionsTest.create(params, payload, cb);
381
+ }
423
382
 
424
- if (params.action_id) {
425
- params.id = params.action_id;
426
- delete params.action_id;
383
+ return this.actionsTest.create(params, payload);
427
384
  }
428
385
 
429
- if (cb && cb instanceof Function) {
430
- return this.actionsTest.create(params, payload, cb);
431
- }
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 || {};
432
404
 
433
- return this.actionsTest.create(params, payload);
434
- };
405
+ if (params.action_id) {
406
+ params.id = params.action_id;
407
+ delete params.action_id;
408
+ }
435
409
 
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 || {};
410
+ if (cb && cb instanceof Function) {
411
+ return this.actionsDeploy.create(params, {}, cb);
412
+ }
460
413
 
461
- if (params.action_id) {
462
- params.id = params.action_id;
463
- delete params.action_id;
414
+ return this.actionsDeploy.create(params, {});
464
415
  }
465
416
 
466
- if (cb && cb instanceof Function) {
467
- return this.actionsDeploy.create(params, {}, cb);
468
- }
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 || {};
469
443
 
470
- return this.actionsDeploy.create(params, {});
471
- };
444
+ if (params.action_id) {
445
+ params.id = params.action_id;
446
+ delete params.action_id;
447
+ }
472
448
 
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 || {};
449
+ if (cb && cb instanceof Function) {
450
+ return this.actionVersions.getAll(params, cb);
451
+ }
504
452
 
505
- if (params.action_id) {
506
- params.id = params.action_id;
507
- delete params.action_id;
453
+ return this.actionVersions.getAll(params);
508
454
  }
509
455
 
510
- if (cb && cb instanceof Function) {
511
- return this.actionVersions.getAll(params, cb);
512
- }
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 || {};
513
474
 
514
- return this.actionVersions.getAll(params);
515
- };
475
+ if (params.action_id) {
476
+ params.id = params.action_id;
477
+ delete params.action_id;
478
+ }
516
479
 
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 || {};
480
+ if (cb && cb instanceof Function) {
481
+ return this.actionVersions.get(params, cb);
482
+ }
541
483
 
542
- if (params.action_id) {
543
- params.id = params.action_id;
544
- delete params.action_id;
484
+ return this.actionVersions.get(params);
545
485
  }
546
486
 
547
- if (cb && cb instanceof Function) {
548
- return this.actionVersions.get(params, cb);
549
- }
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 || {};
550
508
 
551
- return this.actionVersions.get(params);
552
- };
509
+ if (params.action_id) {
510
+ params.id = params.action_id;
511
+ delete params.action_id;
512
+ }
553
513
 
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 || {};
514
+ if (cb && cb instanceof Function) {
515
+ return this.actionVersions.create(params, data, cb);
516
+ }
580
517
 
581
- if (params.action_id) {
582
- params.id = params.action_id;
583
- delete params.action_id;
518
+ return this.actionVersions.create(params, data);
584
519
  }
585
520
 
586
- if (cb && cb instanceof Function) {
587
- return this.actionVersions.create(params, data, cb);
588
- }
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 {boolean} params.update_draft Update draft
535
+ * @param {Function} [cb] Callback function.
536
+ * @returns {Promise|undefined}
537
+ */
538
+ deployVersion(params, cb) {
539
+ params = params || {};
589
540
 
590
- return this.actionVersions.create(params, data);
591
- };
541
+ if (params.action_id) {
542
+ params.id = params.action_id;
543
+ delete params.action_id;
544
+ }
592
545
 
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 || {};
546
+ const body = {};
617
547
 
618
- if (params.action_id) {
619
- params.id = params.action_id;
620
- delete params.action_id;
621
- }
548
+ if (params.update_draft) {
549
+ body.update_draft = params.update_draft;
550
+ delete params.update_draft;
551
+ }
552
+
553
+ if (cb && cb instanceof Function) {
554
+ return this.actionVersionDeploy.create(params, body, cb);
555
+ }
622
556
 
623
- if (cb && cb instanceof Function) {
624
- return this.actionVersionDeploy.create(params, {}, cb);
557
+ return this.actionVersionDeploy.create(params, body);
625
558
  }
626
559
 
627
- return this.actionVersionDeploy.create(params, {});
628
- };
560
+ /**
561
+ * Get an execution by ID.
562
+ *
563
+ * @example
564
+ * management.actions.getExecution({ execution_id: EXECUTION_ID }, function (err, action) {
565
+ * if (err) {
566
+ * // Handle error.
567
+ * }
568
+ *
569
+ * console.log(ActionExecution);
570
+ * });
571
+ * @param {object} params Action Execution parameters.
572
+ * @param {string} params.id Action Execution ID.
573
+ * @param {Function} [cb] Callback function.
574
+ * @returns {Promise|undefined}
575
+ */
576
+ getExecution(params, cb) {
577
+ params = params || {};
629
578
 
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 || {};
579
+ if (cb && cb instanceof Function) {
580
+ return this.executions.get(params, cb);
581
+ }
653
582
 
654
- if (cb && cb instanceof Function) {
655
- return this.executions.get(params, cb);
583
+ return this.executions.get(params);
656
584
  }
657
-
658
- return this.executions.get(params);
659
- };
585
+ }
660
586
 
661
587
  module.exports = ActionsManager;