Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
withStaticProps({
async load() {
let settings = await this.findOne({ query: { key: SETTINGS_KEY } });
if (!settings) {
settings = new FilesSettings();
await settings.save();
}
return settings;
}
}),
withFields({
key: setOnce()(string({ value: SETTINGS_KEY })),
data: fields({
value: {},
instanceOf: withFields({
installed: boolean({ value: false }),
srcPrefix: onSet(value => {
// Make sure srcPrefix always ends with forward slash.
if (typeof value === "string") {
return value.endsWith("/") ? value : value + "/";
}
return value;
})(
string({
validation: validation.create("required"),
value: "/files/"
})
)
})()
})
})
)(createBase());
withFields(instance => ({
key: setOnce()(string({ value: SETTINGS_KEY })),
data: fields({
instanceOf: withFields({
enabled: boolean(),
apiKey: onSet(value => {
if (value && value !== instance.apiKey) {
instance.registerHookCallback("beforeSave", async () => {
console.log("TODO: setOnce");
const mailchimp = new MailchimpApi({ apiKey: value });
const valid = await mailchimp.isValidApiKey();
if (!valid) {
throw Error("API key invalid.");
}
});
}
return value;
})(string())
})()
})
export default ({ createBase }) => {
const SecurityRole = flow(
withName("SecurityRole"),
withFields({
name: string(),
slug: string(),
description: string(),
system: boolean(),
scopes: string({ list: true })
}),
withHooks({
async beforeCreate() {
const existingRole = await SecurityRole.findOne({
query: { slug: this.slug }
});
if (existingRole) {
throw Error(`Role with slug "${this.slug}" already exists.`);
}
},
async beforeDelete() {
if (this.system) {
throw Error(`Cannot delete system role.`);
}
}
const step = () =>
fields({
value: {},
instanceOf: flow(
withFields({
started: boolean({ value: false }),
startedOn: date(),
completed: boolean({ value: false }),
completedOn: date()
}),
withProps({
markAsStarted() {
this.started = true;
this.startedOn = new Date();
},
markAsCompleted() {
this.completed = true;
this.completedOn = new Date();
}
})
)()
});
const step = () =>
fields({
value: {},
instanceOf: flow(
withFields({
started: boolean({ value: false }),
startedOn: date(),
completed: boolean({ value: false }),
completedOn: date()
}),
withProps({
markAsStarted() {
this.started = true;
this.startedOn = new Date();
},
markAsCompleted() {
this.completed = true;
this.completedOn = new Date();
}
})
)()
});
export default ({ createBase }) => {
return flow(
withName("Settings"),
withStaticProps({
async load() {
return await this.findOne({ query: { key: SETTINGS_KEY } });
}
}),
withFields({
key: setOnce()(string({ value: SETTINGS_KEY })),
data: fields({
instanceOf: withFields({
enabled: boolean(),
code: string()
})()
})
})
)(createBase());
};
background: string(),
text: string()
})();
return flow(
withName("Settings"),
withStaticProps({
async load() {
return await this.findOne({ query: { key: SETTINGS_KEY } });
}
}),
withFields({
key: setOnce()(string({ value: SETTINGS_KEY })),
data: fields({
instanceOf: withFields({
enabled: boolean(),
position: string({
value: "bottom",
validation: validation.create("in:bottom:top:bottom-left:bottom-right")
}),
palette: fields({
instanceOf: withFields({
popup: fields({ instanceOf: ColorsModel }),
button: fields({ instanceOf: ColorsModel })
})()
}),
content: fields({
instanceOf: withFields({
href: string(),
message: string(),
dismiss: string(),
link: string()
withFields(() => ({
description: string(),
name: string(),
slug: string(),
system: boolean(),
roles: ref({
list: true,
instanceOf: [SecurityRole, "model"],
using: [SecurityRoles2Models, "role"]
})
})),
withHooks({
get siteKey() {
return new Promise(async resolve => {
const settings = await FormSettings.load();
resolve(get(settings, "data.reCaptcha.siteKey"));
});
},
get secretKey() {
return new Promise(async resolve => {
const settings = await FormSettings.load();
resolve(get(settings, "data.reCaptcha.secretKey"));
});
}
}
}),
withFields({
enabled: boolean(),
errorMessage: i18nString({
context,
value: {
values: [
{
locale: defaultLocale,
value: "Please verify that you are not a robot."
}
]
}
})
})
)(),
value: {}
})
})();