Comparing version 1.3.0-179 to 1.3.0-187
@@ -31,3 +31,43 @@ module.exports = { | ||
} | ||
} | ||
}, | ||
FORM_CONSTANTS: { | ||
DATA_SOURCE_TYPE_STATIC: "static", | ||
DATA_SOURCE_TYPE_DATA_SOURCE: "dataSource", | ||
FIELD_TYPE_CHECKBOXES: "checkboxes", | ||
FIELD_TYPE_RADIO: "radio", | ||
FIELD_TYPE_DROPDOWN: "dropdown", | ||
FIELD_TYPE_TEXT: "text", | ||
FIELD_TYPE_TEXT_AREA: "textarea", | ||
FIELD_TYPE_URL: "url", | ||
FIELD_TYPE_NUMBER: "number", | ||
FIELD_TYPE_EMAIL: "emailAddress", | ||
FIELD_TYPE_LOCATION: "location", | ||
FIELD_TYPE_MAP: "locationMap", | ||
FIELD_TYPE_PHOTO: "photo", | ||
FIELD_TYPE_SIGNATURE: "signature", | ||
FIELD_TYPE_FILE: "file", | ||
FIELD_TYPE_DATE_TIME: "dateTime", | ||
FIELD_TYPE_SECTION_BREAK: "sectionBreak", | ||
FIELD_TYPE_MATRIX: "matrix", | ||
FIELD_TYPE_BARCODE: "barcode", | ||
FIELD_TYPE_SLIDER_NUMBER: "sliderNumber" | ||
}, | ||
MODELNAMES: { | ||
FORM: "Form", | ||
PAGE: "Page", | ||
FIELD: "Field", | ||
THEME: "Theme", | ||
FIELD_RULE : "FieldRule", | ||
PAGE_RULE: "PageRule", | ||
APP_FORMS: "AppForms", | ||
APP_THEMES: "AppThemes", | ||
FORM_SUBMISSION: "FormSubmission", | ||
GROUPS: "Groups", | ||
APP_CONFIG: "AppConfig", | ||
DATA_SOURCE: "DataSource", | ||
DATA_SOURCE_CACHE: "DataSourceCache", | ||
DATA_TARGET: "DataTarget" | ||
}, | ||
SCHEMA_OPTIONS: { strict: true, versionKey: false }, | ||
SCHEMA_OPTIONS_NO_ID: { strict: true, versionKey: false , _id: false } | ||
}; |
var mongoose = require('mongoose'), | ||
Schema = mongoose.Schema; | ||
var CONSTANTS = require('./constants.js'); | ||
var logger = require('./logger').getLogger(); | ||
var _ = require('underscore'); | ||
var FORM_CONSTANTS = { | ||
DATA_SOURCE_TYPE_STATIC: "static", | ||
DATA_SOURCE_TYPE_DATA_SOURCE: "dataSource", | ||
FIELD_TYPE_CHECKBOXES: "checkboxes", | ||
FIELD_TYPE_RADIO: "radio", | ||
FIELD_TYPE_DROPDOWN: "dropdown", | ||
FIELD_TYPE_TEXT: "text", | ||
FIELD_TYPE_TEXT_AREA: "textarea", | ||
FIELD_TYPE_URL: "url", | ||
FIELD_TYPE_NUMBER: "number", | ||
FIELD_TYPE_EMAIL: "emailAddress", | ||
FIELD_TYPE_LOCATION: "location", | ||
FIELD_TYPE_MAP: "locationMap", | ||
FIELD_TYPE_PHOTO: "photo", | ||
FIELD_TYPE_SIGNATURE: "signature", | ||
FIELD_TYPE_FILE: "file", | ||
FIELD_TYPE_DATE_TIME: "dateTime", | ||
FIELD_TYPE_SECTION_BREAK: "sectionBreak", | ||
FIELD_TYPE_MATRIX: "matrix", | ||
FIELD_TYPE_BARCODE: "barcode", | ||
FIELD_TYPE_SLIDER_NUMBER: "sliderNumber" | ||
}; | ||
var FORM_CONSTANTS = CONSTANTS.FORM_CONSTANTS; | ||
/** | ||
* Converting DS Cache Entries To Field Format | ||
* @param fieldType | ||
* @param cacheEntries | ||
* @returns {Array} | ||
* @private | ||
*/ | ||
function convertDSCacheToFieldOptions(fieldType, cacheEntries){ | ||
//Radio and Dropdown only allow the first option to be selected | ||
//Checkboxes can have multiple options selected. | ||
var schemas = require('./schemas'); | ||
var alreadySelected = false; | ||
return _.map(cacheEntries, function(cacheEntry){ | ||
var valToReturn = { | ||
key: cacheEntry.key, | ||
label: cacheEntry.value, | ||
checked: cacheEntry.selected && (!alreadySelected || fieldType === FORM_CONSTANTS.FIELD_TYPE_CHECKBOXES) | ||
}; | ||
if(valToReturn.checked){ | ||
alreadySelected = true; | ||
} | ||
return valToReturn; | ||
}); | ||
} | ||
module.exports = function (){ | ||
var MODELNAMES = { | ||
FORM: "Form", | ||
PAGE: "Page", | ||
FIELD: "Field", | ||
THEME: "Theme", | ||
FIELD_RULE : "FieldRule", | ||
PAGE_RULE: "PageRule", | ||
APP_FORMS: "AppForms", | ||
APP_THEMES: "AppThemes", | ||
FORM_SUBMISSION: "FormSubmission", | ||
GROUPS: "Groups", | ||
APP_CONFIG: "AppConfig", | ||
DATA_SOURCE: "DataSource", | ||
DATA_SOURCE_CACHE: "DataSourceCache", | ||
DATA_TARGET: "DataTarget" | ||
}; | ||
var MODELNAMES = CONSTANTS.MODELNAMES; | ||
var allowedFontStyles = ["normal", "bold", "italic"]; | ||
var allowedBorderThicknesses = ["none", "thin", "medium", "thick"]; | ||
var allowedBorderStyles = ["solid", "dotted", "dashed", "double"]; | ||
var default_config = { | ||
"client": { | ||
"sent_save_min": 5, | ||
"sent_save_max": 100, | ||
"sent_items_to_keep_list": [5, 10, 20, 30, 40, 50, 100], | ||
"targetWidth": 480, | ||
"targetHeight": 640, | ||
"quality": 75, | ||
"debug_mode": false, | ||
"logger" : false, | ||
"max_retries" : 0, | ||
"timeout" : 30, | ||
"log_line_limit": 300, | ||
"log_email": "" | ||
}, | ||
"cloud": { | ||
"logging": { | ||
"enabled":false | ||
} | ||
} | ||
}; | ||
var defaults = { | ||
refreshIntervalMin: 1, | ||
refreshIntervalMax: 10080 | ||
}; | ||
function isValidDataSourceFieldType(type){ | ||
return type === FORM_CONSTANTS.FIELD_TYPE_CHECKBOXES || type === FORM_CONSTANTS.FIELD_TYPE_RADIO || type === FORM_CONSTANTS.FIELD_TYPE_DROPDOWN; | ||
} | ||
return { | ||
@@ -113,242 +16,4 @@ "init": function (conn, config) { | ||
var schemaOptions = { strict: true, versionKey: false }; | ||
var schemaOptionsNoId = _.extend({_id: false}, schemaOptions); | ||
var pageSchema = new Schema({ | ||
"name" : String, | ||
"description": String, | ||
"fields" : [{ type: Schema.Types.ObjectId, ref: MODELNAMES.FIELD }] | ||
}, schemaOptions); | ||
var fieldSchema = new Schema({ | ||
"name": {type: String, required: true}, | ||
"helpText": String, | ||
"dataSource": { type: Schema.Types.ObjectId, ref: MODELNAMES.DATA_SOURCE, required: false }, | ||
"dataSourceType": {type: String, enum: [FORM_CONSTANTS.DATA_SOURCE_TYPE_STATIC, FORM_CONSTANTS.DATA_SOURCE_TYPE_DATA_SOURCE], default: FORM_CONSTANTS.DATA_SOURCE_TYPE_STATIC}, | ||
"fieldCode": {type: String, required: false},//Unique field code defined by the user. | ||
"type": {type: String, required: true, enum: [FORM_CONSTANTS.FIELD_TYPE_TEXT, FORM_CONSTANTS.FIELD_TYPE_TEXT_AREA, FORM_CONSTANTS.FIELD_TYPE_URL, FORM_CONSTANTS.FIELD_TYPE_NUMBER, FORM_CONSTANTS.FIELD_TYPE_EMAIL, FORM_CONSTANTS.FIELD_TYPE_CHECKBOXES, FORM_CONSTANTS.FIELD_TYPE_RADIO, FORM_CONSTANTS.FIELD_TYPE_DROPDOWN, FORM_CONSTANTS.FIELD_TYPE_LOCATION, FORM_CONSTANTS.FIELD_TYPE_MAP, FORM_CONSTANTS.FIELD_TYPE_PHOTO, FORM_CONSTANTS.FIELD_TYPE_SIGNATURE, FORM_CONSTANTS.FIELD_TYPE_FILE, FORM_CONSTANTS.FIELD_TYPE_DATE_TIME, FORM_CONSTANTS.FIELD_TYPE_SECTION_BREAK, FORM_CONSTANTS.FIELD_TYPE_MATRIX, FORM_CONSTANTS.FIELD_TYPE_BARCODE, FORM_CONSTANTS.FIELD_TYPE_SLIDER_NUMBER]}, | ||
"repeating": {type: Boolean, default: false}, //All fields can be repeating. | ||
"fieldOptions": {type: Schema.Types.Mixed, default: {}, required: true}, | ||
"required": {type: Boolean, required: true}, | ||
"adminOnly": {type: Boolean, default: false} | ||
}, schemaOptions); | ||
fieldSchema.path('dataSourceType').validate(function(dataSourceType){ | ||
logger.debug("Validating Data Source Type", this, dataSourceType); | ||
//If the field type is set to be a dataSource, then a data source id should have been provided. | ||
if(dataSourceType === FORM_CONSTANTS.DATA_SOURCE_TYPE_DATA_SOURCE){ | ||
return this.dataSource !== undefined; | ||
} | ||
return true; | ||
}, "Invalid Data Source Option"); | ||
//Validating That Data Sources Are Not Applied To Incorrect Fields | ||
fieldSchema.path('dataSourceType').validate(function(dataSourceType){ | ||
if(dataSourceType === FORM_CONSTANTS.DATA_SOURCE_TYPE_DATA_SOURCE){ | ||
return isValidDataSourceFieldType(this.type); | ||
} | ||
return true; | ||
}, "Data Sources Can Only Be Applied To Radio, Checkbox And Dropdown Fields"); | ||
fieldSchema.path('fieldOptions').validate(function(fieldOptions){ | ||
//If the data source type is static, then there should be field options specified | ||
if(this.dataSourceType === FORM_CONSTANTS.DATA_SOURCE_TYPE_STATIC && isValidDataSourceFieldType(this.type)){ | ||
var definition = fieldOptions.definition || {}; | ||
var options = definition.options || []; | ||
return options.length > 0; | ||
} | ||
//If it is data source, then no options are required. | ||
return true; | ||
}, "A Static Radio, Checkboxes or Dropdown Field Type Must Contain Field Options"); | ||
var ruleConditionalStatementsSchema = new Schema({ | ||
"sourceField": { type: Schema.Types.ObjectId, ref: MODELNAMES.FIELD, required: true}, | ||
"restriction": {type: String, required: true, enum: ["is not","is equal to","is greater than","is less than","is at","is before","is after","is", "contains", "does not contain", "begins with", "ends with"]}, | ||
"sourceValue": {type: String, required: true} | ||
}, {_id : false, versionKey: false}); | ||
var fieldRulesSchema = new Schema({ // All fields in a fieldRule are required | ||
"type": {type: String, required: true, enum: ["show", "hide"]}, | ||
"relationType" : {"type": String, "required" : true, "default": "and", "enum": ["and", "or"]}, | ||
"ruleConditionalOperator" : {"type": String, "required" : true, "default": "and", "enum": ["and", "or"]}, | ||
"ruleConditionalStatements" : [ruleConditionalStatementsSchema], | ||
"targetField": [{ type: Schema.Types.ObjectId, ref: MODELNAMES.FIELD, required: true }] | ||
}, schemaOptions); | ||
var pageRulesSchema = new Schema({ // All fields in a page rule are required | ||
"type": {type: String, required: true, enum: ["skip", "show"]}, | ||
"relationType" : {"type": String, "required" : true, "default": "and", "enum": ["and", "or"]}, | ||
"ruleConditionalOperator" : {"type": String, "required" : true, "default": "and", "enum": ["and", "or"]}, | ||
"ruleConditionalStatements" : [ruleConditionalStatementsSchema], | ||
"targetPage": [{ type: Schema.Types.ObjectId, ref: MODELNAMES.PAGE, required: true }] | ||
}, schemaOptions); | ||
var formSchema = new Schema({ | ||
"dateCreated": {type : Date, default : Date.now, required: true}, | ||
"lastUpdated": {type : Date, default : Date.now, required: true}, | ||
"updatedBy" : {type: String, required: true}, | ||
"createdBy": {type:String, required: true}, | ||
"name" : {type: String, required: true}, | ||
"description": String, | ||
"pages" : [{ type: Schema.Types.ObjectId, ref: MODELNAMES.PAGE }], | ||
"fieldRules": [{ type: Schema.Types.ObjectId, ref: MODELNAMES.FIELD_RULE }], | ||
"pageRules": [{ type: Schema.Types.ObjectId, ref: MODELNAMES.PAGE_RULE }], | ||
"subscribers" : [{type: String}], | ||
"dataSources": { | ||
"formDataSources": [{type: Schema.Types.ObjectId, ref: MODELNAMES.DATA_SOURCE}], | ||
"lastRefresh": {type: Date, required: false} | ||
}, | ||
"dataTargets": [{type: Schema.Types.ObjectId, ref: MODELNAMES.DATA_TARGET}] | ||
}, schemaOptions); | ||
formSchema.pre('validate', function (next){ | ||
// all new forms will have a createdby this allows for old forms which do not have a createdBy | ||
if(! this.createdBy){ | ||
this.createdBy = this.updatedBy; | ||
} | ||
next(); | ||
}); | ||
var styleSubSectionSchema = new Schema({ | ||
"label": {type: String, requried: true}, | ||
"id": {type: String, required: true}, | ||
"typography": { | ||
"fontFamily": {type: String, required: false}, | ||
"fontStyle": {type: String, required: false, enum: allowedFontStyles}, | ||
"fontSize": {type: String, required: false}, | ||
"fontColour": {type: String, required: false} | ||
}, | ||
"border": { | ||
"thickness": {type: String, required: false, enum: allowedBorderThicknesses}, | ||
"style": {type: String, required: false, enum: allowedBorderStyles}, | ||
"colour": {type: String, required: false} | ||
}, | ||
"background": { | ||
"background_color": {type: String, required: false} | ||
}, | ||
"margin":{ | ||
"top": {type: String, required: false}, | ||
"right": {type: String, required: false}, | ||
"bottom": {type: String, required: false}, | ||
"left": {type: String, required: false} | ||
}, | ||
"padding":{ | ||
"top": {type: String, required: false}, | ||
"right": {type: String, required: false}, | ||
"bottom": {type: String, required: false}, | ||
"left": {type: String, required: false} | ||
} | ||
}, {_id : false}); | ||
var styleSectionSchema = new Schema({ | ||
"label": {type: String, required: true}, | ||
"id": {type: String, required: true}, | ||
"sub_sections": [styleSubSectionSchema] | ||
}, {_id : false}); | ||
var staticCSSSchema = new Schema({ | ||
"key": {type: String, required:true}, | ||
"value": {type: String, required:true} | ||
}, {_id: false}); | ||
var themeStructureSubSections = new Schema({ | ||
"label": {type: String, requried: true}, | ||
"id": {type: String, required: true}, | ||
"style": { | ||
"typography": {type: Boolean, required: true}, | ||
"border": {type: Boolean, required: true}, | ||
"background": {type: Boolean, required: true}, | ||
"margin": { | ||
"top": {type: Boolean, required: false}, | ||
"right": {type: Boolean, required: false}, | ||
"bottom": {type: Boolean, required: false}, | ||
"left": {type: Boolean, required: false} | ||
}, | ||
"padding": { | ||
"top": {type: Boolean, required: false}, | ||
"right": {type: Boolean, required: false}, | ||
"bottom": {type: Boolean, required: false}, | ||
"left": {type: Boolean, required: false} | ||
} | ||
}, | ||
"staticCSS": [staticCSSSchema], | ||
"classAdditions": [{ | ||
"classNameAddition": {type: String, required:true}, | ||
"cssAdditions": [staticCSSSchema] | ||
}] | ||
}, {_id : false}); | ||
var themeStructureSchema = new Schema({ | ||
"label": {type: String, required: true}, | ||
"id": {type: String, required: true}, | ||
"sub_sections": [themeStructureSubSections] | ||
}, {_id : false}); | ||
var themeSchema = new Schema({ // When definining a theme, all fields are required except logo... | ||
"lastUpdated": {type : Date, default : Date.now}, | ||
"updatedBy" : {type: String, required: true}, | ||
"createdBy" : {type: String, required: true}, | ||
"name": {type: String, required: true}, | ||
"css" : {type : String, required:true, default: "/*Error Generating Appforms CSS*/"}, | ||
"logo": { | ||
"base64String": {type: String, required: true}, | ||
"height": {type: Number, required: true}, | ||
"width": {type: Number, required: true} | ||
}, | ||
"sections": [styleSectionSchema], | ||
"structure": { | ||
"sections": [themeStructureSchema], | ||
"logo": { | ||
"staticCSS": [staticCSSSchema] | ||
} | ||
} | ||
}, schemaOptions); | ||
themeSchema.pre('validate', function (next){ | ||
if(! this.createdBy){ | ||
this.createdBy = this.updatedBy; | ||
} | ||
next(); | ||
}); | ||
var appFormsSchema = new Schema({ | ||
"appId": {type: String, required: true}, | ||
"lastUpdated": {type : Date, default : Date.now, required: true}, | ||
"forms": [{ type: Schema.Types.ObjectId, ref: MODELNAMES.FORM, required: true}] | ||
}, schemaOptions); | ||
var appConfigSchema = new Schema({ | ||
"appId": {type: String, required: true, unique: true}, | ||
"client": { | ||
"sent_save_min": {type : Number, required: false, default: default_config.client.sent_save_min}, | ||
"sent_save_max": {type : Number, required: false, default: default_config.client.sent_save_max}, | ||
"sent_items_to_keep_list": [{type : Number, required: false, default: default_config.client.sent_items_to_keep_list}], | ||
"targetWidth": {type : Number, required: false, default: default_config.client.targetWidth}, | ||
"targetHeight": {type : Number, required: false, default: default_config.client.targetHeight}, | ||
"quality": {type : Number, required: false, default: default_config.client.quality}, | ||
"debug_mode": {type: Boolean, required: false, default: default_config.client.debug_mode}, | ||
"logger" : {type: Boolean, required: false, default: default_config.client.logger}, | ||
"max_retries" : {type : Number, required: false, default: default_config.client.max_retries}, | ||
"timeout" : {type : Number, required: false, default: default_config.client.timeout}, | ||
"log_line_limit": {type : Number, required: false, default: default_config.client.log_line_limit}, | ||
"log_email": {type: String, default: default_config.client.log_email}, | ||
"config_admin_user": [{type: String}], | ||
"log_level": {type:String,required:true, default:1}, | ||
"log_levels": {type:Array, required: false, default:["error", "warning", "log", "debug"]} | ||
}, | ||
"cloud": { | ||
"logging": { | ||
"enabled": {type: Boolean, required: false, default: default_config.cloud.logging.enabled} | ||
} | ||
} | ||
}, schemaOptions); | ||
var appThemesSchema = new Schema({ | ||
"appId": {type: String, required: true}, | ||
"theme": { type: Schema.Types.ObjectId, ref: MODELNAMES.THEME, required: true } | ||
}, schemaOptions); | ||
///GROUPS ARE NOW REDUNDANT, NOT NEEDED ANY MORE | ||
var groupsSchema = new Schema({ | ||
@@ -370,154 +35,17 @@ "name": {type: String, required: true}, | ||
var formFieldsSchema = new Schema({ | ||
"fieldId": { type: Schema.Types.ObjectId, ref: MODELNAMES.FIELD}, | ||
"fieldValues": Schema.Types.Mixed | ||
}, {_id : false}); | ||
///GROUPS ARE NOW REDUNDANT, NOT NEEDED ANY MORE | ||
var submissionCommentsSchema = new Schema({ | ||
"madeBy": {type: String, required: true}, | ||
"madeOn": {type: Date, required: true}, | ||
"value": {type: String, required: true} | ||
}, {_id : false, versionKey: false}); | ||
var formSubmissionSchema = new Schema({ | ||
"submissionCompletedTimestamp": {"type": Date, default: 0, required: true}, | ||
"updatedBy": {type: String}, | ||
"updatedTimestamp": {"type": Date, default: Date.now}, | ||
"metaData": {type: Schema.Types.Mixed}, | ||
"timezoneOffset" : {"type" : Number, required: true}, | ||
"appId": {type: String, required: true}, | ||
"appClientId": {type: String, required: true}, | ||
"appCloudName": {type: String, required: true}, | ||
"appEnvironment": {type: String, required: true}, | ||
"formSubmittedAgainst":{type: Object, required: false}, | ||
"formId": { type: Schema.Types.ObjectId, ref: MODELNAMES.FORM , required: true}, | ||
"userId": {type: String, required: false}, | ||
"deviceId": {type: String, required: true}, | ||
"deviceIPAddress": {type: String, required: true}, | ||
"submissionStartedTimestamp": {type : Date, default : Date.now, required: true}, | ||
"status": {type: String, enum: ["pending", "complete", "error"], required:true, default: "pending"}, | ||
"deviceFormTimestamp": {type: Date, required: true}, | ||
"masterFormTimestamp": {type: Date, required: true}, | ||
"comments": [submissionCommentsSchema], | ||
"formFields": [formFieldsSchema] | ||
}, schemaOptions); | ||
formSubmissionSchema.pre('save', function (next) { | ||
var newTimestamp = Date.now(); | ||
if (process.env.FH_FORMS_DEBUG) console.log('formSubmissionSchema pre save this.updatedTimestamp:', this.updatedTimestamp.getTime(), ' newTimestamp:', newTimestamp); | ||
this.updatedTimestamp = newTimestamp; | ||
next(); | ||
}); | ||
var dataSourceCacheOption = new Schema({ | ||
key: {type: String, required: true}, | ||
value: {type: String, required: true}, | ||
selected: {type: Boolean, required: true} | ||
}, schemaOptionsNoId); | ||
//Validator To Ensure Data Is Updated Correctly | ||
function emptyValidator(value){ | ||
if(this.currentStatus && this.currentStatus.status === "ok"){ | ||
return !!value; | ||
} | ||
return true; | ||
} | ||
var dataSourceCacheSchema = new Schema({ | ||
lastRefreshed: {type: Date, validate: emptyValidator}, | ||
currentStatus: { | ||
status: {type: String, enum: ["ok", "error"], required: true, default: "ok"}, | ||
error: { | ||
code: {type: String, required: false}, | ||
userDetail: {type: String, required: false}, | ||
systemDetail: {type: String, required: false} | ||
} | ||
}, | ||
dataHash: {type: String, validate: emptyValidator}, | ||
data: { | ||
type: [dataSourceCacheOption], | ||
validate: function(value){ | ||
if(this.currentStatus && this.currentStatus.status === "ok"){ | ||
return value.length > 0 | ||
} | ||
return true; | ||
} | ||
} | ||
}, schemaOptionsNoId); | ||
var dataSourceSchema = new Schema({ | ||
name: {type: String, required: true}, | ||
description: {type: String, required: true}, | ||
lastUpdated: {type : Date, default : Date.now, required: true}, | ||
dateCreated: {type : Date, default : Date.now, required: true}, | ||
updatedBy : {type: String, required: true}, | ||
createdBy: {type:String, required: true}, | ||
endpoint: {type: String, required: true}, | ||
refreshInterval: {type: Number, required: true, min: config.refreshIntervalMin || defaults.refreshIntervalMin, max: config.refreshIntervalMax || defaults.refreshIntervalMax}, | ||
serviceGuid: {type: String, required: true}, | ||
cache: [dataSourceCacheSchema] | ||
}, schemaOptions); | ||
//There should only ever be at most one cache entry. | ||
function cacheValidator(cacheArray){ | ||
return cacheArray.length <= 1; | ||
} | ||
dataSourceSchema.path('cache').validate(cacheValidator, 'Data Cache Is Invalid'); | ||
var dataTargetSchema = new Schema({ | ||
name: {type: String, required: true}, | ||
description: {type: String, required: true}, | ||
lastUpdated: {type : Date, default : Date.now, required: true}, | ||
dateCreated: {type : Date, default : Date.now, required: true}, | ||
updatedBy : {type: String, required: true}, | ||
createdBy: {type:String, required: true}, | ||
endpoints: { | ||
postProcessing: {type: String, required: false}, | ||
realTimeData: {type: String, required: false}, | ||
realTimeFile: {type: String, required: false} | ||
}, | ||
serviceGuid: {type: String, required: true}, | ||
type: {type: String, required: true, enum: [CONSTANTS.DATA_TARGET_TYPE_POST_PROCESSING, CONSTANTS.DATA_TARGET_TYPE_REAL_TIME]} | ||
}, schemaOptions); | ||
dataTargetSchema.pre('save', function(next){ | ||
var endpoints = this.endpoints || {}; | ||
//If The Data Target Is postProcessing, the postProcessing Endpoint Must Be Set | ||
var error; | ||
if(this.type === CONSTANTS.DATA_TARGET_TYPE_POST_PROCESSING){ | ||
if(!endpoints.postProcessing){ | ||
error = new Error("Post Processing Data Target Requires A Post Processing Endpoint"); | ||
} | ||
} | ||
//Real Time Data Targets Required Two Endpoints: | ||
// Data Endpoint For JSON Submission | ||
// File Endpoint For Submission Files | ||
if(this.type === CONSTANTS.DATA_TARGET_TYPE_REAL_TIME){ | ||
if(!endpoints.realTimeData || !endpoints.realTimeFile){ | ||
error = new Error("Real Time Data Target Requires A Real Time Data And Real Time File Endpoints"); | ||
} | ||
} | ||
return next(error); | ||
}); | ||
conn.model(MODELNAMES.FORM, formSchema); | ||
conn.model(MODELNAMES.PAGE, pageSchema); | ||
conn.model(MODELNAMES.FIELD, fieldSchema); | ||
conn.model(MODELNAMES.FIELD_RULE, fieldRulesSchema); | ||
conn.model(MODELNAMES.PAGE_RULE, pageRulesSchema); | ||
conn.model(MODELNAMES.THEME, themeSchema); | ||
conn.model(MODELNAMES.APP_FORMS, appFormsSchema); | ||
conn.model(MODELNAMES.APP_THEMES, appThemesSchema); | ||
conn.model(MODELNAMES.FORM_SUBMISSION, formSubmissionSchema); | ||
conn.model(MODELNAMES.FORM, schemas.form()); | ||
conn.model(MODELNAMES.PAGE, schemas.page()); | ||
conn.model(MODELNAMES.FIELD, schemas.field()); | ||
conn.model(MODELNAMES.FIELD_RULE, schemas.fieldRule()); | ||
conn.model(MODELNAMES.PAGE_RULE, schemas.pageRule()); | ||
conn.model(MODELNAMES.THEME, schemas.theme()); | ||
conn.model(MODELNAMES.APP_FORMS, schemas.projectForms()); | ||
conn.model(MODELNAMES.APP_THEMES, schemas.projectTheme()); | ||
conn.model(MODELNAMES.FORM_SUBMISSION, schemas.submission()); | ||
conn.model(MODELNAMES.GROUPS, groupsSchema); | ||
conn.model(MODELNAMES.APP_CONFIG, appConfigSchema); | ||
conn.model(MODELNAMES.DATA_SOURCE, dataSourceSchema); | ||
conn.model(MODELNAMES.DATA_TARGET, dataTargetSchema); | ||
conn.model(MODELNAMES.APP_CONFIG, schemas.projectConfig()); | ||
conn.model(MODELNAMES.DATA_SOURCE, schemas.dataSource(config)); | ||
conn.model(MODELNAMES.DATA_TARGET, schemas.dataTarget()); | ||
}, | ||
@@ -530,4 +58,4 @@ "get": function(conn, modelName){ | ||
"CONSTANTS": CONSTANTS, | ||
convertDSCacheToFieldOptions: convertDSCacheToFieldOptions | ||
convertDSCacheToFieldOptions: schemas.dataSourceCache.convertDSCacheToFieldOptions | ||
}; | ||
}; | ||
}; |
@@ -55,2 +55,4 @@ var models = require('../../common/models.js')(); | ||
* @param params | ||
* _id: Data Source Id | ||
* includeAuditLog: flag to include a data source audit log or not. | ||
* @param cb | ||
@@ -104,3 +106,5 @@ */ | ||
var dataSourceJSON = dataSources[0]; | ||
dataSourceJSON = processDataSourceResponse(dataSourceJSON); | ||
dataSourceJSON = processDataSourceResponse(dataSourceJSON, { | ||
includeAuditLog: params.includeAuditLog | ||
}); | ||
@@ -235,3 +239,3 @@ return cb(undefined, dataSourceJSON); | ||
//Can't update the docuemnt ID field. | ||
delete dataSourceJSON[CONSTANTS.DATA_SOURCE_ID]; | ||
dataSourceJSON = _.omit(dataSourceJSON, CONSTANTS.DATA_SOURCE_ID); | ||
@@ -306,3 +310,3 @@ dataSourceDocument = _.extend(dataSourceDocument, dataSourceJSON); | ||
newDataSource = processDataSourceResponse(newDataSource.toJSON()) | ||
newDataSource = processDataSourceResponse(newDataSource.toJSON()); | ||
@@ -403,3 +407,4 @@ return cb(undefined, newDataSource); | ||
data: dataSourceToValidate.data, | ||
lastRefreshed: new Date().getTime() | ||
lastRefreshed: new Date().getTime(), | ||
updateTimestamp: new Date().getTime() | ||
}; | ||
@@ -418,11 +423,4 @@ | ||
//Not interested in the last update timestamp as the data source is not saved to the database. | ||
delete dataSourceJSON.lastRefreshed; | ||
dataSourceJSON = _.omit(dataSourceJSON, "lastRefreshed", "currentStatus", "updateTimestamp", CONSTANTS.DATA_SOURCE_ID); | ||
//Not Interested In The Curent Status As It Is Not Stored In The Database. | ||
delete dataSourceJSON.currentStatus; | ||
//Not Interested In The _id As It Is Not Stored In The Database. | ||
delete dataSourceJSON[CONSTANTS.DATA_SOURCE_ID]; | ||
dataSourceJSON.validationResult = { | ||
@@ -429,0 +427,0 @@ valid: valid, |
@@ -8,6 +8,9 @@ | ||
* @param dataSourceJSON | ||
* @param params | ||
* - includeAuditLog: Flag to identify if an audit log is to be returned or not. | ||
* @returns {*} | ||
*/ | ||
module.exports = function processDataSourceResponse(dataSourceJSON){ | ||
module.exports = function processDataSourceResponse(dataSourceJSON, params){ | ||
var cacheEntry = dataSourceJSON.cache[0]; | ||
params = params || {}; | ||
@@ -17,8 +20,8 @@ //If there is a cache entry, map the keys to the json, remove the entry | ||
//Moving The Cache Entry To The Top Of The Object For API Consistency. | ||
delete cacheEntry[CONSTANTS.DATA_SOURCE_ID]; //Not Interested In The Cache Entry _id | ||
//Not Interested In The Cache Entry _id | ||
cacheEntry = _.omit(cacheEntry, CONSTANTS.DATA_SOURCE_ID); | ||
//Remove The _id parameter from option subdocuments. | ||
cacheEntry.data = _.map(cacheEntry.data, function(optionEntry){ | ||
delete optionEntry[CONSTANTS.DATA_SOURCE_ID]; | ||
return optionEntry; | ||
return _.omit(optionEntry, CONSTANTS.DATA_SOURCE_ID); | ||
}); | ||
@@ -29,5 +32,10 @@ | ||
delete dataSourceJSON.cache; | ||
//Don't need the cache entry any more | ||
dataSourceJSON = _.omit(dataSourceJSON, "cache"); | ||
//Assigning The Audit Log If Required, otherwise don't need it in the response. | ||
//Useful for limiting the amount of data returned. | ||
dataSourceJSON = params.includeAuditLog ? dataSourceJSON : _.omit(dataSourceJSON, "auditLogs"); | ||
return dataSourceJSON; | ||
}; |
@@ -34,3 +34,3 @@ var models = require('../../common/models.js')(); | ||
invalid: invalidDataSources | ||
} | ||
}; | ||
} | ||
@@ -86,3 +86,3 @@ | ||
//If the document is found, assign it to the object, if not, set an error; | ||
//If the document is found, assign it to the object, if not, set an error | ||
if(matchingDocument){ | ||
@@ -220,3 +220,2 @@ validDataSource.document = matchingDocument; | ||
if(!cacheElement){ | ||
@@ -228,2 +227,5 @@ dataSourceDocument.cache.push({}); | ||
//Assigning the last attempt to updat the data source | ||
cacheElement.updateTimestamp = params.currentTime; | ||
var existingData = cacheElement.data; | ||
@@ -266,3 +268,3 @@ var existingHash = cacheElement.dataHash; | ||
error: dataSourceData.error | ||
} | ||
}; | ||
} | ||
@@ -284,2 +286,11 @@ | ||
//An Audit Log Entry Is Based On The Cache Update Entry. | ||
var auditLogEntry = cacheElement.toJSON(); | ||
//Adding Service Detils To The Audit Log Entry | ||
_.extend(auditLogEntry, _.pick(dataSourceDocument, "serviceGuid", "endpoint")); | ||
//Adding the audit log | ||
dataSourceDocument.auditLogs.push(auditLogEntry); | ||
//Data Source Data Is Now valid, can save it - whether it is in an error state or not. | ||
@@ -297,3 +308,3 @@ dataSourceDocument.save(function(err){ | ||
//Not interested in the document if the save is invalid | ||
delete dataSourceData.document; | ||
dataSourceData = _.omit(dataSourceData, 'document'); | ||
@@ -361,3 +372,3 @@ return cb(undefined, dataSourceData); | ||
if(!params.currentTime){ | ||
return cb(buildErrorResponse({error: new Error("Expected a Current Time Parameter To Be Set"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS})) | ||
return cb(buildErrorResponse({error: new Error("Expected a Current Time Parameter To Be Set"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS})); | ||
} | ||
@@ -364,0 +375,0 @@ |
{ | ||
"name": "fh-forms", | ||
"version": "1.3.0-179", | ||
"version": "1.3.0-187", | ||
"dependencies": { | ||
@@ -185,5 +185,5 @@ "archiver": { | ||
"fh-gridfs": { | ||
"version": "0.2.4-18", | ||
"from": "https://registry.npmjs.org/fh-gridfs/-/fh-gridfs-0.2.4-18.tgz", | ||
"resolved": "https://registry.npmjs.org/fh-gridfs/-/fh-gridfs-0.2.4-18.tgz", | ||
"version": "0.2.7", | ||
"from": "https://registry.npmjs.org/fh-gridfs/-/fh-gridfs-0.2.7.tgz", | ||
"resolved": "https://registry.npmjs.org/fh-gridfs/-/fh-gridfs-0.2.7.tgz", | ||
"dependencies": { | ||
@@ -260,5 +260,5 @@ "archiver": { | ||
"through": { | ||
"version": "2.3.8", | ||
"from": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", | ||
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz" | ||
"version": "2.3.7", | ||
"from": "https://registry.npmjs.org/through/-/through-2.3.7.tgz", | ||
"resolved": "https://registry.npmjs.org/through/-/through-2.3.7.tgz" | ||
} | ||
@@ -299,5 +299,5 @@ } | ||
"fh-mbaas-client": { | ||
"version": "0.3.8", | ||
"from": "https://registry.npmjs.org/fh-mbaas-client/-/fh-mbaas-client-0.3.8.tgz", | ||
"resolved": "https://registry.npmjs.org/fh-mbaas-client/-/fh-mbaas-client-0.3.8.tgz", | ||
"version": "0.5.2", | ||
"from": "fh-mbaas-client@0.5.2", | ||
"resolved": "https://registry.npmjs.org/fh-mbaas-client/-/fh-mbaas-client-0.5.2.tgz", | ||
"dependencies": { | ||
@@ -588,3 +588,3 @@ "bunyan": { | ||
"version": "0.8.0", | ||
"from": "fheng/phantomjs-node#514c855834", | ||
"from": "git://github.com/fheng/phantomjs-node.git#514c855834056d08d9d60fddcd2d4243254c1955", | ||
"resolved": "git://github.com/fheng/phantomjs-node.git#514c855834056d08d9d60fddcd2d4243254c1955", | ||
@@ -594,3 +594,3 @@ "dependencies": { | ||
"version": "1.2.2", | ||
"from": "dnode@>=1.2.2", | ||
"from": "https://registry.npmjs.org/dnode/-/dnode-1.2.2.tgz", | ||
"resolved": "https://registry.npmjs.org/dnode/-/dnode-1.2.2.tgz", | ||
@@ -600,3 +600,3 @@ "dependencies": { | ||
"version": "0.2.2", | ||
"from": "dnode-protocol@>=0.2.2 <0.3.0", | ||
"from": "https://registry.npmjs.org/dnode-protocol/-/dnode-protocol-0.2.2.tgz", | ||
"resolved": "https://registry.npmjs.org/dnode-protocol/-/dnode-protocol-0.2.2.tgz" | ||
@@ -606,3 +606,3 @@ }, | ||
"version": "0.0.0", | ||
"from": "jsonify@>=0.0.0 <0.1.0", | ||
"from": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", | ||
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz" | ||
@@ -612,3 +612,3 @@ }, | ||
"version": "1.0.0", | ||
"from": "weak@>=1.0.0 <2.0.0", | ||
"from": "https://registry.npmjs.org/weak/-/weak-1.0.0.tgz", | ||
"resolved": "https://registry.npmjs.org/weak/-/weak-1.0.0.tgz", | ||
@@ -618,3 +618,3 @@ "dependencies": { | ||
"version": "1.2.1", | ||
"from": "bindings@>=1.2.1 <2.0.0", | ||
"from": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz", | ||
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz" | ||
@@ -624,3 +624,3 @@ }, | ||
"version": "2.0.9", | ||
"from": "nan@>=2.0.5 <3.0.0", | ||
"from": "https://registry.npmjs.org/nan/-/nan-2.0.9.tgz", | ||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.0.9.tgz" | ||
@@ -634,3 +634,3 @@ } | ||
"version": "0.0.15", | ||
"from": "fheng/shoe#45429420fe", | ||
"from": "git://github.com/fheng/shoe.git#45429420fece517b6df9ffc856aa5ba661a10741", | ||
"resolved": "git://github.com/fheng/shoe.git#45429420fece517b6df9ffc856aa5ba661a10741", | ||
@@ -640,3 +640,3 @@ "dependencies": { | ||
"version": "0.3.7", | ||
"from": "sockjs@0.3.7", | ||
"from": "https://registry.npmjs.org/sockjs/-/sockjs-0.3.7.tgz", | ||
"resolved": "https://registry.npmjs.org/sockjs/-/sockjs-0.3.7.tgz", | ||
@@ -646,3 +646,3 @@ "dependencies": { | ||
"version": "1.3.3", | ||
"from": "node-uuid@1.3.3", | ||
"from": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.3.3.tgz", | ||
"resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.3.3.tgz" | ||
@@ -652,3 +652,3 @@ }, | ||
"version": "0.4.4", | ||
"from": "faye-websocket@0.4.4", | ||
"from": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.4.4.tgz", | ||
"resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.4.4.tgz" | ||
@@ -665,3 +665,3 @@ } | ||
"version": "2.0.0", | ||
"from": "win-spawn@>=2.0.0 <2.1.0", | ||
"from": "https://registry.npmjs.org/win-spawn/-/win-spawn-2.0.0.tgz", | ||
"resolved": "https://registry.npmjs.org/win-spawn/-/win-spawn-2.0.0.tgz" | ||
@@ -671,3 +671,3 @@ }, | ||
"version": "0.6.6", | ||
"from": "traverse@>=0.6.3 <0.7.0", | ||
"from": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz", | ||
"resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz" | ||
@@ -674,0 +674,0 @@ } |
{ | ||
"name": "fh-forms", | ||
"version": "1.3.0-179", | ||
"version": "1.3.0-187", | ||
"description": "Cloud Forms API for form submission", | ||
@@ -24,5 +24,5 @@ "main": "fhforms.js", | ||
"async": "0.2.9", | ||
"fh-gridfs": "0.2.4-18", | ||
"fh-mbaas-client": "0.3.8", | ||
"handlebars": "^4.0.1", | ||
"fh-gridfs": "0.2.7", | ||
"fh-mbaas-client": "0.5.2", | ||
"handlebars": "4.0.1", | ||
"lodash": "2.2.1", | ||
@@ -32,5 +32,5 @@ "mime": "1.2.11", | ||
"mongodb": "1.3.19", | ||
"mongoose": "~3.8.2", | ||
"mongoose": "3.8.33", | ||
"phantom": "fheng/phantomjs-node#514c855834", | ||
"request": "^2.45.0", | ||
"request": "2.58.0", | ||
"underscore": "1.8.0" | ||
@@ -37,0 +37,0 @@ }, |
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
94
13357
6
554616
+ Addedamdefine@1.0.1(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.5(transitive)
+ Addedasync@1.5.22.6.4(transitive)
+ Addedaws-sign2@0.5.0(transitive)
+ Addedbluebird@2.11.02.9.26(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedcamelcase@1.2.1(transitive)
+ Addedcaseless@0.10.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addedctype@0.5.3(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedextend@2.0.2(transitive)
+ Addedfh-gridfs@0.2.7(transitive)
+ Addedfh-mbaas-client@0.5.2(transitive)
+ Addedform-data@1.0.1(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedhandlebars@4.0.1(transitive)
+ Addedhar-validator@1.8.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhawk@2.3.1(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@0.11.0(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.12.0(transitive)
+ Addedmime-types@2.0.14(transitive)
+ Addedminimist@0.0.10(transitive)
+ Addedmongoose@3.8.33(transitive)
+ Addedmquery@1.6.1(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedoptimist@0.6.1(transitive)
+ Addedqs@3.1.0(transitive)
+ Addedrequest@2.58.0(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedsource-map@0.1.340.4.4(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtldts@6.1.56(transitive)
+ Addedtldts-core@6.1.56(transitive)
+ Addedtough-cookie@5.0.0(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
+ Addeduglify-js@2.4.24(transitive)
+ Addeduglify-to-browserify@1.0.2(transitive)
+ Addedwindow-size@0.1.0(transitive)
+ Addedwordwrap@0.0.20.0.3(transitive)
+ Addedyargs@3.5.4(transitive)
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbluebird@2.10.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfh-gridfs@0.2.4-18(transitive)
- Removedfh-mbaas-client@0.3.8(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhandlebars@4.7.8(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmongoose@3.8.40(transitive)
- Removedmquery@1.10.0(transitive)
- Removedneo-async@2.6.2(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduglify-js@3.19.3(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedwordwrap@1.0.0(transitive)
Updatedfh-gridfs@0.2.7
Updatedfh-mbaas-client@0.5.2
Updatedhandlebars@4.0.1
Updatedmongoose@3.8.33
Updatedrequest@2.58.0