@clausehq/flows-analysis
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -59,2 +59,12 @@ const { validation } = require('../index'); | ||
}); | ||
test('scheduled trigger flow, to be ran periodically, each 20 minutes with a set timezone', () => { | ||
expect(validation.triggerType( | ||
{ | ||
$class: 'io.clause.flows.trigger.Schedule', | ||
type: 'periodic', | ||
interval: '20 minutes', | ||
timezone: 'Asia/Gaza', | ||
} | ||
)).toBe(true); | ||
}); | ||
test('scheduled trigger flow, to be ran periodically, each 20 minutes (CRON expression)', () => { | ||
@@ -157,3 +167,13 @@ expect(validation.triggerType( | ||
}); | ||
test('scheduled trigger flow, to be ran periodically, with an invalid timezone', () => { | ||
expect(() => validation.triggerType( | ||
{ | ||
$class: 'io.clause.flows.trigger.Schedule', | ||
type: 'periodic', | ||
interval: '20 minutes', | ||
timezone: 'Europe/Foobaristan' | ||
} | ||
)).toThrow(); | ||
}); | ||
}); | ||
}); |
const humanInterval = require('human-interval'); | ||
const dayjs = require('dayjs'); | ||
const cronParser = require('cron-parser'); | ||
const utc = require('dayjs/plugin/utc'); // dependent on utc plugin | ||
const timezone = require('dayjs/plugin/timezone'); | ||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
const PERIODIC_INTERVAL_MINIMUM_MS = 1000 * 60 * 10; | ||
@@ -61,3 +66,3 @@ | ||
const validateTypePeriodic = ({ interval }) => { | ||
const validateTypePeriodicInterval = ({ interval }) => { | ||
if (isHumanIntervalValid(interval)) { | ||
@@ -86,2 +91,22 @@ if (humanInterval(interval) < PERIODIC_INTERVAL_MINIMUM_MS) { | ||
const validateTypePeriodicTimezone = ({ timezone }) => { | ||
if (timezone && typeof timezone === 'string') { | ||
try { | ||
dayjs().tz(timezone); | ||
return true; | ||
} catch (err) { | ||
if (err.message.includes('Invalid time zone specified')) { | ||
throw buildValidationError( | ||
`Invalid timezone: ${timezone}.` | ||
); | ||
} | ||
throw err; | ||
} | ||
} | ||
return true; | ||
}; | ||
const validateTypePeriodic = ({ interval, timezone }) => validateTypePeriodicInterval({ interval }) | ||
&& validateTypePeriodicTimezone({ timezone }); | ||
const validateScheduledFlowTriggerType = triggerType => { | ||
@@ -88,0 +113,0 @@ if (typeof triggerType.type !== 'string' || typeof triggerType.interval !== 'string') { |
{ | ||
"name": "@clausehq/flows-analysis", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "A utility for doing static analysis on flows", | ||
@@ -5,0 +5,0 @@ "license": "UNLICENSED", |
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
22271
611