diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ab55b66 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +# ![Virtua SA logo](https://www.virtua.ch/favicon.png) VPX - Virtua Parse eXtender :: Changelog + +## 1.0.1 + +* Add `VpxLoggedEntities` configuration to force *VPX* to monitor only given entities +* *VPX* is now able to run Parse Server intances older than 2.7.2 + +## 1.0.0 - First public release + +*VPX* supports for now : + +* Entity operation logging (`created`, `updated`, `deleted`) in `VpxOperationEntityLog` +* Custom cloud code execution (stored in `VpxCustomCloudCode`, called with `vpx-exec-ccc`) \ No newline at end of file diff --git a/README.md b/README.md index 2fce486..5ce7b56 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ ``` 3. Restart your Parse server. +Note : *VPX* requires at least `parse-server@2.7.2` to work properly, but it has been made compatible in a degraded mode for older versions. + ## Usage *VPX* will monitor every modification made on user Parse entities and log them in the class `VpxEntityOperationLog`: @@ -37,6 +39,7 @@ These parameters can be created with Parse Dashboard in `Config > Create a param | Parameter | Type | Default value | Description | :-------------------- | :------- | :---------------------------------- | :------------------------------------------- | `VpxCustomCloudCode` | `String` | `null` | Your custom cloud code to run on Parse server +| `VpxLoggedEntities` | `Array` | `null` | Names of entities to monitor, use `null` to let *VPX* discover new entities | `VpxLoggedOperations` | `Array` | `["created", "updated", "deleted"]` | Operation types allowed to be logged ## Jobs diff --git a/cloud/virtua-parse-extended.js b/cloud/virtua-parse-extended.js index 84afb40..fc03fcc 100644 --- a/cloud/virtua-parse-extended.js +++ b/cloud/virtua-parse-extended.js @@ -21,6 +21,12 @@ //var Parse = require('parse/node'); function VirtuaParseExtended() { + /** + * Operation on these entities are logged by VPX. + * @type string[] + */ + var currentLoggedOperationEntities = []; + /** * Custom script that can be evaluated. * @private @@ -37,9 +43,11 @@ function VirtuaParseExtended() { /** * Operation on these entities will be logged by VPX. + * An empty array means no entities will be monitored, + * a null value means all entities will be monitored. * @type string[] */ - var loggedOperationEntities = []; + var loggedOperationEntities = null; /** * Initialize VPX. @@ -48,15 +56,19 @@ function VirtuaParseExtended() { this.init = function() { console.info('[VPX] Initializing ...'); // Create the VpxEntityOperationLog collection if needed - var schema = new Parse.Schema('VpxEntityOperationLog'); - schema.get().catch(function(error) { - const schema = new Parse.Schema('VpxEntityOperationLog'); - schema.addString('targetClass') - .addString('targetId') - .addString('operation'); - schema.save(); - console.info('[VPX] VpxEntityOperationLog schema created.'); - }); + if (typeof Parse.Schema === "function") { + var schema = new Parse.Schema('VpxEntityOperationLog'); + schema.get().catch(function(error) { + const schema = new Parse.Schema('VpxEntityOperationLog'); + schema.addString('targetClass') + .addString('targetId') + .addString('operation'); + schema.save(); + console.info('[VPX] VpxEntityOperationLog schema created.'); + }); + } else { + console.warn('[VPX] VpxEntityOperationLog schema cannot be created, please upgrade to parse-server@2.7.2 !'); + } // Register jobs Parse.Cloud.job('vpx-reload', reloadJob); Parse.Cloud.job('vpx-exec-ccc', execCustomCloudCodeJob); @@ -114,33 +126,47 @@ function VirtuaParseExtended() { }); } + /** + * Register triggers on user Parse entities. + * @argument object entity + */ + monitorEntityOperation = function(className) { + // Skip Parse Core entities, the log itself and already monitored entities + if (!(className.startsWith('_') || className == 'VpxEntityOperationLog' || currentLoggedOperationEntities.includes(className))) { + console.info('[VPX] Processing : ' + className + ' ...'); + Parse.Cloud.afterSave(className, afterSaveTrigger); + Parse.Cloud.afterDelete(className, afterDeleteTrigger); + currentLoggedOperationEntities.push(className); + console.info('[VPX] Registred entity for operation logging: ' + className); + } + } + /** * Loads configuration of Virtua Parse eXtended. * @returns void */ load = function() { - console.log('[VPX] Already monitored entities: ' + loggedOperationEntities); - // Register the triggers for every entities managed by Parse - Parse.Schema.all().then(function(result) { - result.forEach(function(entity) { - var className = entity.className; - // Skip Parse Core entities, the log itself and already monitored entities - if (!(className.startsWith('_') || className == 'VpxEntityOperationLog' || loggedOperationEntities.includes(className))) { - console.info('[VPX] Processing : ' + className + ' ...'); - Parse.Cloud.afterSave(className, afterSaveTrigger); - Parse.Cloud.afterDelete(className, afterDeleteTrigger); - loggedOperationEntities.push(className); - console.info('[VPX] Registred entity for operation logging: ' + className); - } - }); - console.log('[VPX] Monitored entities: ' + loggedOperationEntities); - }); // Load configuration Parse.Config.get().then(function(config) { customCloudCode = config.get('VpxCustomCloudCode') || customCloudCode; + loggedOperationEntities = config.get('VpxLoggedEntities') || loggedOperationEntities; loggedOperationTypes = config.get('VpxLoggedOperations') || loggedOperationTypes; console.info('[VPX] VpxCustomCloudCode: ' + customCloudCode); + console.info('[VPX] VpxLoggedEntities: ' + loggedOperationEntities); console.info('[VPX] VpxLoggedOperations: ' + loggedOperationTypes); + console.info('[VPX] Already monitored entities: ' + currentLoggedOperationEntities); + // Register the triggers for every entities managed by Parse + if (loggedOperationEntities === null && typeof Parse.Schema === "function") { + console.info('[VPX] Discovering new entities to monitor ...'); + Parse.Schema.all().then(function(result) { + result.map(x => x.className).forEach(monitorEntityOperation); + console.info('[VPX] Monitored entities: ' + currentLoggedOperationEntities); + }); + } else { + console.info('[VPX] Using value of VpxLoggedEntities to register new entities to monitor ...'); + loggedOperationEntities.forEach(monitorEntityOperation); + console.info('[VPX] Monitored entities: ' + currentLoggedOperationEntities); + } }); } diff --git a/docker-compose.yml b/docker-compose.yml index 72b9997..97fee60 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,10 @@ mongo: - image: mongo + image: mongo:3.6 labels: - "com.dnsdock.alias=mongo.vpx.docker" parse-server: - image: parseplatform/parse-server + image: parseplatform/parse-server:2.7.2 environment: - PARSE_SERVER_APPLICATION_ID=VPX-Test - PARSE_SERVER_CLOUD=/parse-server/cloud/main.js @@ -22,7 +22,7 @@ parse-server: - ./logs:/parse-server/logs parse-dashboard: - image: parseplatform/parse-dashboard + image: parseplatform/parse-dashboard:1.1.2 environment: - PARSE_DASHBOARD_ALLOW_INSECURE_HTTP=1 - PARSE_DASHBOARD_APP_ID=VPX-Test