@zenginehq/frontend-config
Advanced tools
Comparing version 3.8.3 to 3.9.0
{ | ||
"name": "@zenginehq/frontend-config", | ||
"version": "3.8.3", | ||
"version": "3.9.0", | ||
"description": "Helper module for implementing Zengine plugin configuration forms.", | ||
@@ -9,3 +9,3 @@ "scripts": { | ||
"build": "node-sass src --output src --output-style compressed", | ||
"release": "jshint --config .jshintrc ./src && npm run build && standard-version" | ||
"release": "jshint --config .jshintrc ./src && npm run build && standard-version -t ''" | ||
}, | ||
@@ -12,0 +12,0 @@ "repository": { |
@@ -22,5 +22,6 @@ # zn-frontend-config | ||
Note: when using maya, it's crucial that this gets run inside the `plugins/myplugin/src` directory alongside your plugin's other code to get built properly. | ||
If you are using the newer [mayan](https://github.com/ZengineHQ/mayan) then you can just run the install from your frontend plugin's root. | ||
Note: when using the soon-to-be-deprecated legacy maya, it's crucial that this gets run inside the `plugins/myplugin/src` directory alongside your plugin's other code to get built properly. | ||
If, however, you are using the shiny new [mayan](https://github.com/ZengineHQ/mayan) then you can just run the install from your frontend plugin's root `plugins/myplugin`, as you'd expect! | ||
## Updating | ||
@@ -27,0 +28,0 @@ |
@@ -124,3 +124,9 @@ plugin.controller('wgnConfigCtrl', ['$scope', '$q', '$routeParams', 'znData', 'znModal', 'znMessage', 'wgnConfigSrv', | ||
return doRunHook('delete', shallowCopy($scope.editing.config)).finally(function () { | ||
return _webhook ? _webhook.service.delete($scope.editing.config.webhookId) : $q.when(); | ||
return _webhook | ||
? Array.isArray(_webhook.options) | ||
? $q.all(_webhook.options.map(function (opts, i) { | ||
return _webhook.service.delete($scope.editing.config['webhook' + i + 'Id']); | ||
})) | ||
: _webhook.service.delete($scope.editing.config.webhookId) | ||
: $q.when(); | ||
}).then(function () { | ||
@@ -192,3 +198,9 @@ doDiscardChanges(); | ||
return doSaveConfig($scope.editing.config).then(function () { | ||
return _webhook ? _webhook.service.disable($scope.editing.config.webhookId) : $q.when(); | ||
return _webhook | ||
? Array.isArray(_webhook.options) | ||
? $q.all(_webhook.options.map(function (opts, i) { | ||
return _webhook.service.disable($scope.editing.config['webhook' + i + 'Id']); | ||
})) | ||
: _webhook.service.disable($scope.editing.config.webhookId) | ||
: $q.when(); | ||
}); | ||
@@ -214,3 +226,9 @@ }).catch(function () { | ||
return doSaveConfig($scope.editing.config).then(function () { | ||
return _webhook ? _webhook.service.enable($scope.editing.config.webhookId) : $q.when(); | ||
return _webhook | ||
? Array.isArray(_webhook.options) | ||
? $q.all(_webhook.options.map(function (opts, i) { | ||
return _webhook.service.enable($scope.editing.config['webhook' + i + 'Id']); | ||
})) | ||
: _webhook.service.enable($scope.editing.config.webhookId) | ||
: $q.when(); | ||
}); | ||
@@ -458,3 +476,9 @@ }).catch(function () { | ||
znMessage('Configuration ' + config.name + ' enabled!', 'saved'); | ||
return _webhook ? _webhook.service.enable(config.webhookId) : $q.when(); | ||
return _webhook | ||
? Array.isArray(_webhook.options) | ||
? $q.all(_webhook.options.map(function (opts, i) { | ||
return _webhook.service.enable(config['webhook' + i + 'Id']); | ||
})) | ||
: _webhook.service.enable(config.webhookId) | ||
: $q.when(); | ||
}); | ||
@@ -466,3 +490,9 @@ }); | ||
znMessage('Configuration ' + config.name + ' disabled!', 'saved'); | ||
return _webhook ? _webhook.service.disable(config.webhookId) : $q.when(); | ||
return _webhook | ||
? Array.isArray(_webhook.options) | ||
? $q.all(_webhook.options.map(function (opts, i) { | ||
return _webhook.service.disable(config['webhook' + i + 'Id']); | ||
})) | ||
: _webhook.service.disable(config.webhookId) | ||
: $q.when(); | ||
}); | ||
@@ -721,38 +751,108 @@ }); | ||
function doSaveConfig (config) { | ||
/*jshint maxcomplexity:11 */ | ||
var promise = $q.when(config); | ||
var multiWebhooks = _webhook && Array.isArray(_webhook.options); | ||
if (_webhook && !('webhookId' in config)) { | ||
var options = Object.assign({}, _webhook.options); | ||
if (_webhook && !('webhookId' in config || 'webhook0Id' in config)) { | ||
var options = multiWebhooks | ||
? _webhook.options.map(function (opts) { | ||
return Object.assign({}, opts); | ||
}) | ||
: Object.assign({}, _webhook.options); | ||
if (!(options['form.id'] in config)) { | ||
throw new Error('Config: Invalid form.id for webhook'); | ||
} | ||
if (multiWebhooks) { | ||
promise = $q.all(options.map(function (opts) { | ||
if (!(opts['form.id'] in config)) { | ||
throw new Error('Config: Invalid form.id for webhook'); | ||
} | ||
options['form.id'] = config[options['form.id']]; | ||
opts['form.id'] = config[opts['form.id']]; | ||
if (options.filter) { | ||
options.filter = reconstructFilter(options.filter, config); | ||
if (opts.filter) { | ||
opts.filter = reconstructFilter(opts.filter, config); | ||
} | ||
return _webhook.service.create(opts); | ||
})) | ||
.then(function (webhooks) { | ||
return webhooks.reduce(function (cfg, wh, i) { | ||
cfg['webhook' + i + 'Id'] = wh.id; | ||
cfg['webhook' + i + 'Key'] = wh.secretKey; | ||
return cfg; | ||
}, config); | ||
}) | ||
.catch(function (err) { | ||
znMessage('There was an error creating the webhook.', 'error'); | ||
return config; | ||
}); | ||
} else { | ||
if (!(options['form.id'] in config)) { | ||
throw new Error('Config: Invalid form.id for webhook'); | ||
} | ||
options['form.id'] = config[options['form.id']]; | ||
if (options.filter) { | ||
options.filter = reconstructFilter(options.filter, config); | ||
} | ||
promise = _webhook.service.create(options) | ||
.then(function (webhook) { | ||
config.webhookId = webhook.id; | ||
config.webhookKey = webhook.secretKey; | ||
return config; | ||
}) | ||
.catch(function (err) { | ||
znMessage('There was an error creating the webhook.', 'error'); | ||
return config; | ||
}); | ||
} | ||
} else if ( | ||
_webhook && ( | ||
_webhook.options.filter || Array.isArray(_webhook.options) && _webhook.options.some(function (opts) { | ||
return opts.filter; | ||
}) | ||
) | ||
) { | ||
var updateOptions = multiWebhooks | ||
? _webhook.options.map(function (opts) { | ||
return Object.assign({}, opts); | ||
}) | ||
: Object.assign({}, _webhook.options); | ||
promise = _webhook.service.create(options).then(function (webhook) { | ||
config.webhookId = webhook.id; | ||
config.webhookKey = webhook.secretKey; | ||
return config; | ||
}).catch(function (err) { | ||
znMessage('There was an error creating the webhook.', 'error'); | ||
return config; | ||
}); | ||
} else if (_webhook && _webhook.options.filter) { | ||
var updateOptions = Object.assign({}, _webhook.options); | ||
updateOptions.filter = reconstructFilter(updateOptions.filter, config); | ||
if (multiWebhooks) { | ||
updateOptions.forEach(function (opts) { | ||
if (opts.filter) { | ||
opts.filter = reconstructFilter(opts.filter, config); | ||
} | ||
}); | ||
promise = _webhook.service.update({ | ||
id: config.webhookId, | ||
filter: updateOptions.filter | ||
}).then(function (webhook) { | ||
return config; | ||
}).catch(function (err) { | ||
znMessage('There was an error creating the webhook.', 'error'); | ||
return config; | ||
}); | ||
promise = $q.all(updateOptions.map(function (opts, i) { | ||
return _webhook.service.update({ | ||
id: config['webhook' + i + 'Id'], | ||
filter: opts.filter | ||
}); | ||
})) | ||
.then(function (webhooks) { | ||
return config; | ||
}) | ||
.catch(function (err) { | ||
znMessage('There was an error creating the webhook.', 'error'); | ||
return config; | ||
}); | ||
} else { | ||
updateOptions.filter = reconstructFilter(updateOptions.filter, config); | ||
promise = _webhook.service.update({ | ||
id: config.webhookId, | ||
filter: updateOptions.filter | ||
}) | ||
.then(function (webhook) { | ||
return config; | ||
}) | ||
.catch(function (err) { | ||
znMessage('There was an error creating the webhook.', 'error'); | ||
return config; | ||
}); | ||
} | ||
} | ||
@@ -767,11 +867,27 @@ | ||
if ($scope.settings.multi && _webhook) { | ||
return _webhook.service.load(cfg.webhookId).then(function (wh) { | ||
if (wh.url.indexOf('config=') === -1) { | ||
var separator = wh.url.indexOf('?') === -1 ? '?' : '&'; | ||
return _webhook.service.update({ | ||
id: wh.id, | ||
url: wh.url + separator + 'config=' + encodeURI(cfg.$id) | ||
if (Array.isArray(_webhook.options)) { | ||
return $q.all(_webhook.options.map(function (opts, i) { | ||
return _webhook.service.load(cfg['webhook' + i + 'Id']).then(function (wh) { | ||
if (wh.url.indexOf('config=') === -1) { | ||
var separator = wh.url.indexOf('?') === -1 ? '?' : '&'; | ||
return _webhook.service.update({ | ||
id: wh.id, | ||
url: wh.url + separator + 'config=' + encodeURI(cfg.$id) | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
})); | ||
} else { | ||
return _webhook.service.load(cfg.webhookId).then(function (wh) { | ||
if (wh.url.indexOf('config=') === -1) { | ||
var separator = wh.url.indexOf('?') === -1 ? '?' : '&'; | ||
return _webhook.service.update({ | ||
id: wh.id, | ||
url: wh.url + separator + 'config=' + encodeURI(cfg.$id) | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -791,3 +907,3 @@ }); | ||
function reconstructFilter (filter, config) { | ||
/*jshint maxcomplexity:10 */ | ||
/*jshint maxcomplexity:11 */ | ||
var newFilter = angular.extend({}, filter); | ||
@@ -822,4 +938,5 @@ /** | ||
if (filter.prefix.replaceValue) { | ||
var prefixValue = config[filter.prefix.replaceValue] === 'is' ? '' : config[filter.prefix.replaceValue]; | ||
// Prefix cannot be a fieldID, so only replaceValue is handled | ||
newFilter.prefix = config[filter.prefix.replaceValue]; | ||
newFilter.prefix = prefixValue; | ||
} | ||
@@ -826,0 +943,0 @@ |
@@ -250,13 +250,30 @@ plugin.service('wgnConfigSettings', ['$q', 'wgnConfigInputs', function ($q, configInputs) { | ||
// Validate required options. | ||
if (!('url' in options)) { | ||
throw new Error('Config: Missing required param "url" in webhook options.'); | ||
} | ||
if (Array.isArray(options)) { | ||
options.forEach(function (opts) { | ||
if (!('url' in opts)) { | ||
throw new Error('Config: Missing required param "url" in webhook options.'); | ||
} | ||
if (!('form.id' in options)) { | ||
throw new Error('Config: Missing required param "form.id" in webhook options.'); | ||
} | ||
if (!('form.id' in opts)) { | ||
throw new Error('Config: Missing required param "form.id" in webhook options.'); | ||
} | ||
// Finally make sure the form.id acually exists. | ||
if (_formInputs.indexOf(options['form.id']) === -1) { | ||
throw new Error('Config: Inexistent form id specified in param "form.id" in webhook options.'); | ||
// Finally make sure the form.id acually exists. | ||
if (_formInputs.indexOf(opts['form.id']) === -1) { | ||
throw new Error('Config: Inexistent form id specified in param "form.id" in webhook options.'); | ||
} | ||
}); | ||
} else { | ||
if (!('url' in options)) { | ||
throw new Error('Config: Missing required param "url" in webhook options.'); | ||
} | ||
if (!('form.id' in options)) { | ||
throw new Error('Config: Missing required param "form.id" in webhook options.'); | ||
} | ||
// Finally make sure the form.id acually exists. | ||
if (_formInputs.indexOf(options['form.id']) === -1) { | ||
throw new Error('Config: Inexistent form id specified in param "form.id" in webhook options.'); | ||
} | ||
} | ||
@@ -263,0 +280,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
287130
34
1836
37
1