Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
cleanroom
Advanced tools
Readme
Compose your business logic into commands that validate input.
npm install cleanroom --save
import Cleanroom from 'cleanroom';
class UserSignUp extends Cleanroom.Command {
static schema = {
properties: {
email: { type: 'string', format: 'email' },
name: { type: 'string' },
newsletter_subscribe: { type: 'boolean' }
},
required: ['email', 'name'],
additionalProperties: false,
}
static execute(inputs) {
const user = new User(inputs);
// Do something with the user like save to a database.
// ...
return user;
}
}
Cleanroom.initCommand(UserSignUp);
// Sometime later in a file far, far away....
function signUpAction(inputs) {
const outcome = UserSignUp.run(inputs)
// Then check to see if it worked:
if (outcome.success) {
return { message: `Great success, ${outcome.result.name}!` };
} else {
return { errors: outcome.errors };
}
}
Some things to note about the example:
additionalProperties
is set to false, any additional properties will be
removed.You have three choices. Given a command UserSignUp, you can do this:
const outcome = UserSignUp.run(inputs);
if (outcome.success) {
console.log(outcome.result);
} else {
console.error(outcome.errors);
}
Or, you can do this:
// returns the result of ::execute(), or throws ValidationError
try {
const result = UserSignUp.runExplicitly(inputs);
console.log(result);
} catch (e) {
console.error(e);
}
Or, you can do this:
// returns a Promise with the result of ::execute() as the resolved value,
// or rejects with the validation errors.
UserSignUp.runPromise(inputs)
.then(console.log)
.catch(console.error);
class YourCommand extends Cleanroom.Command {
}
Schemas are defined using the JSON Schema specification. See Understanding JSON Schema for basics on JSON Schema.
class YourCommand extends Cleanroom.Command {
static schema = {
properties: {
name: { type: 'string', maxLength: 10 },
state: { type: 'string', enum: ['AL', 'AK', 'AR', ...] },
age: { type: 'integer' },
isSpecial: { type: 'boolean', default: true },
account: { type: 'object' },
tags: { type: 'array', items: { type: 'string' } },
prefs: {
type: 'object',
properties: {
smoking: { type: 'boolean' },
view: { type: 'boolean' },
additionalProperties: false
}
}
},
required: ['name', 'state', 'age', 'isSpecial', 'account'],
additionalProperties: false
}
}
class YourCommand extends Cleanroom.Command {
static schema = {
// ...
}
static execute(inputs) {
const record = doThing(inputs);
// ...
return record;
}
}
Cleanroom.initCommand(YourCommand);
Validations are handled by the ajv library by epoberezkin.
Please see the ajv documenation until an overview of validation errors is written.
Highly inspired by cypriss/mutations from the Ruby world.
FAQs
Compose your business logic into commands that validate input.
The npm package cleanroom receives a total of 10 weekly downloads. As such, cleanroom popularity was classified as not popular.
We found that cleanroom demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.