Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@clausehq/flows-analysis

Package Overview
Dependencies
Maintainers
8
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clausehq/flows-analysis - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

__tests__/validation.js

108

lib/validation.js

@@ -1,5 +0,106 @@

const scheduledTrigger = (triggerType) => {
if (triggerType && triggerType.$class === 'io.clause.flows.trigger.Schedule') {
const humanInterval = require('human-interval');
const dayjs = require('dayjs');
const cronParser = require('cron-parser');
const PERIODIC_INTERVAL_MINIMUM_MS = 1000 * 60 * 10;
const buildError = (errName, message) => {
const err = new Error(errName);
err.name = errName;
err.message = message;
return err;
};
const buildValidationError = (message) => buildError(
'validationError',
message,
);
const isHumanIntervalValid = humanIntervalString => !Number.isNaN(
humanInterval(humanIntervalString)
);
const isIso8601Valid = iso8601String => dayjs(iso8601String).isValid();
const isCronExpressionValid = cronExpressionString => {
try {
cronParser.parseExpression(cronExpressionString);
return true;
} catch (err) {
if (err.message.includes('Validation') || err.message.includes('Constraint')) {
return false;
}
throw err;
}
};
const getPeriodicCadenceInMsFromCronExpression = cronExpressionString => cronParser
.parseExpression(cronExpressionString).next()._date.ts
- cronParser
.parseExpression(cronExpressionString).prev()._date.ts;
const validateTypeOnce = ({ interval }) => {
if (isIso8601Valid(interval)) {
if (dayjs(interval).diff(dayjs()) < 0) {
throw buildValidationError(
`Invalid scheduled flow once-off interval: ${interval}. The time set should not be in the past.`
);
}
return true;
}
if (isHumanIntervalValid(interval)) {
if (humanInterval(interval) < 0) {
throw buildValidationError(
`Invalid scheduled flow once-off interval: ${interval}. The time set should not be in the past.`
);
}
return true;
}
throw buildValidationError(
`Invalid scheduled flow once-off interval: ${interval}. Please use either the Human Interval format or an ISO 8601 string.`
);
};
const validateTypePeriodic = ({ interval }) => {
if (isHumanIntervalValid(interval)) {
if (humanInterval(interval) < PERIODIC_INTERVAL_MINIMUM_MS) {
throw buildValidationError(
`Invalid scheduled flow periodic interval: ${interval}. The interval should not be less than 10 minutes.`
);
}
return true;
}
if (isCronExpressionValid(interval)) {
if (getPeriodicCadenceInMsFromCronExpression(interval) < PERIODIC_INTERVAL_MINIMUM_MS) {
throw buildValidationError(
`Invalid scheduled flow periodic interval: ${interval}. The interval should not be less than 10 minutes.`
);
}
return true;
}
throw buildValidationError(
`Invalid scheduled flow periodic interval: ${interval}. Please use either the Human Interval format or a CRON expression.`
);
};
const validateScheduledFlowTriggerType = triggerType => {
if (typeof triggerType.type !== 'string' || typeof triggerType.interval !== 'string') {
throw buildValidationError('Scheduled flow type or interval missing.');
}
switch (triggerType.type) {
case 'once':
return validateTypeOnce(triggerType);
case 'periodic':
return validateTypePeriodic(triggerType);
default:
throw buildValidationError(
`Invalid scheduled flow scheduling type: ${triggerType.type}.`
);
}
};
const triggerType = triggerType => {
if (triggerType && triggerType.$class === 'io.clause.flows.trigger.Schedule') {
return validateScheduledFlowTriggerType(triggerType);
}
return true;

@@ -9,3 +110,4 @@ };

module.exports = {
scheduledTrigger,
triggerType,
validateScheduledFlowTriggerType,
};

5

package.json
{
"name": "@clausehq/flows-analysis",
"version": "0.1.2",
"version": "0.1.3",
"description": "A utility for doing static analysis on flows",

@@ -18,2 +18,5 @@ "license": "UNLICENSED",

"dependencies": {
"cron-parser": "^3.4.0",
"dayjs": "^1.10.4",
"human-interval": "^2.0.1",
"jsonpath": "^1.0.2"

@@ -20,0 +23,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc