Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setForm(form) {
// Create the form.
this._form = form;
// Allow the form to provide component overrides.
if (form && form.settings && form.settings.components) {
this.options.components = form.settings.components;
}
this.initialized = false;
const rebuild = this.rebuild() || NativePromise.resolve();
return rebuild.then(() => {
this.emit('formLoad', form);
this.triggerRecaptcha();
// Make sure to trigger onChange after a render event occurs to speed up form rendering.
setTimeout(() => {
this.onChange();
this.formReadyResolve();
}, 0);
return this.formReady;
});
}
localize() {
if (i18next.initialized) {
return Promise.resolve(i18next);
}
i18next.initialized = true;
return new Promise((resolve, reject) => {
try {
i18next.init(this.options.i18n, (err) => {
// Get language but remove any ;q=1 that might exist on it.
this.options.language = i18next.language.split(';')[0];
if (err) {
return reject(err);
}
resolve(i18next);
});
}
catch (err) {
return reject(err);
}
});
}
watchedFiles[file].forEach(function(assembly) {
promises.push(new Promise(function(resolve, reject) {
touch(assembly, function() {
resolve();
});
}));
});
// Remove references to the file but don't unwatch it
delete watchedFiles[file];
}
// Add events always fire a change event for the same file, so we'll ignore add events
if (event !== 'add') {
// The file is done touching any parent files
Promise.all(promises).then(function() {
touchedFiles++;
// fire the event once all filesToTouch and have been touched
if (filesToTouch > 0 && touchedFiles === filesToTouch) {
filesToTouch = 1; // always count the staring file
touchedFiles = 0;
touchEvents.emit('allTouched');
}
});
}
}
property: 'submission',
value: this.resource
});
return {
name: parent,
resource: resource
};
}
return null;
}));
}
});
// When all the parents have loaded, emit that to the onParents emitter.
Promise.all(parentsLoaded).then((parents: any) => this.onParents.emit(parents));
}
BaseComponent.requireLibrary = function(name, property, src, polling) {
if (!BaseComponent.externalLibraries.hasOwnProperty(name)) {
BaseComponent.externalLibraries[name] = {};
BaseComponent.externalLibraries[name].ready = new Promise((resolve, reject) => {
BaseComponent.externalLibraries[name].resolve = resolve;
BaseComponent.externalLibraries[name].reject = reject;
});
if (!polling && !window[name + 'Callback']) {
window[name + 'Callback'] = function() {
this.resolve();
}.bind(BaseComponent.externalLibraries[name]);
}
// See if the plugin already exists.
let plugin = _get(window, property);
if (plugin) {
BaseComponent.externalLibraries[name].resolve(plugin);
}
else {
// Skip if setting is falsy
if (!boolValue(setting)) {
return true;
}
// Skip if value is empty
if (!value || _.isEmpty(value)) {
return true;
}
// Skip if we don't have a database connection
if (!config.db) {
return true;
}
return new NativePromise(resolve => {
const form = config.form;
const submission = config.submission;
const path = `data.${component.path}`;
// Build the query
const query = { form: form._id };
if (_.isString(value)) {
query[path] = {
$regex: new RegExp(`^${escapeRegExCharacters(value)}$`),
$options: 'i'
};
}
// FOR-213 - Pluck the unique location id
else if (_.isPlainObject(value) && value.hasOwnProperty('address_components') && value.hasOwnProperty('place_id')) {
query[`${path}.place_id`] = {
}
// iframe url is not a Vimeo url
if (element.nodeName === 'IFRAME' && !isVimeoUrl(element.getAttribute('src') || '')) {
throw new Error('The player element passed isn’t a Vimeo embed.');
}
// If there is already a player object in the map, return that
if (playerMap.has(element)) {
return playerMap.get(element);
}
this.element = element;
this.origin = '*';
const readyPromise = new Promise((resolve, reject) => {
const onMessage = (event) => {
if (!isVimeoUrl(event.origin) || this.element.contentWindow !== event.source) {
return;
}
if (this.origin === '*') {
this.origin = event.origin;
}
const data = parseMessageData(event.data);
const isError = data && data.event === 'error';
const isReadyError = isError && data.data && data.data.method === 'ready';
if (isReadyError) {
const error = new Error(data.data.message);
error.name = data.data.name;
check(value) {
// Skip if value is empty
if (!value || _.isEmpty(value)) {
return true;
}
// Skip if we don't have a database connection
if (!this.config.db) {
return true;
}
return new NativePromise(resolve => {
const form = this.config.form;
const submission = this.config.submission;
const path = `data.${this.component.path}`;
// Build the query
const query = { form: form._id };
if (_.isString(value)) {
query[path] = {
$regex: new RegExp(`^${escapeRegExCharacters(value)}$`),
$options: 'i'
};
}
// FOR-213 - Pluck the unique location id
else if (_.isPlainObject(value) && value.hasOwnProperty('address_components') && value.hasOwnProperty('place_id')) {
query[`${path}.place_id`] = {
loadFormRevision(vid, query, opts) {
if (!this.formUrl && !this.vUrl) {
return NativePromise.reject('No form url set.');
}
// Set the version url if not set.
if (vid && !this.vUrl) {
this.vId = vid;
this.vUrl = `${this.formUrl}/v/${vid}`;
}
// If they specified a revision form, load the revised form components.
if (query && isObject(query)) {
query = Formio.serialize(query.params);
}
if (query) {
query = this.query ? (`${this.query}&${query}`) : (`?${query}`);
}
else {
static ssoInit(type, options) {
switch (type) {
case 'saml':
return Formio.samlInit(options);
case 'okta':
return Formio.oktaInit(options);
default:
console.warn('Unknown SSO type');
return NativePromise.reject('Unknown SSO type');
}
}