@onify/flow-extensions 8.0.1 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ exports.OnifyTimerEventDefinition = void 0;
7
7
  var _cronParser = _interopRequireDefault(require("cron-parser"));
8
8
  var _bpmnElements = require("bpmn-elements");
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const invalidCronEntryPattern = /Invalid (characters|range)/i;
10
11
  class OnifyTimerEventDefinition extends _bpmnElements.TimerEventDefinition {
11
12
  constructor(activity, def) {
12
13
  super(activity, def);
@@ -15,15 +16,21 @@ class OnifyTimerEventDefinition extends _bpmnElements.TimerEventDefinition {
15
16
  });
16
17
  }
17
18
  parse(timerType, value) {
18
- let cron;
19
- if (timerType === 'timeCycle' && (cron = _cronParser.default.parseString(value))) {
20
- if (cron.expressions?.length) {
21
- // cronParser.parseString expressions disregards seconds, so we have to parse again
19
+ if (timerType === 'timeCycle') {
20
+ try {
21
+ return super.parse(timerType, value);
22
+ } catch (err) {
23
+ var rangeError = err;
24
+ }
25
+ try {
22
26
  const expireAt = _cronParser.default.parseExpression(value).next().toDate();
23
27
  return {
24
28
  expireAt,
25
29
  delay: expireAt - Date.now()
26
30
  };
31
+ } catch (err) {
32
+ if (invalidCronEntryPattern.test(err.message)) throw rangeError;
33
+ throw err;
27
34
  }
28
35
  }
29
36
  return super.parse(timerType, value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onify/flow-extensions",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "Onify Flow extensions",
5
5
  "type": "module",
6
6
  "module": "src/index.js",
@@ -1,6 +1,8 @@
1
1
  import cronParser from 'cron-parser';
2
2
  import { TimerEventDefinition } from 'bpmn-elements';
3
3
 
4
+ const invalidCronEntryPattern = /Invalid (characters|range)/i;
5
+
4
6
  export class OnifyTimerEventDefinition extends TimerEventDefinition {
5
7
  constructor(activity, def) {
6
8
  super(activity, def);
@@ -9,16 +11,23 @@ export class OnifyTimerEventDefinition extends TimerEventDefinition {
9
11
  });
10
12
  }
11
13
  parse(timerType, value) {
12
- let cron;
13
- if (timerType === 'timeCycle' && (cron = cronParser.parseString(value))) {
14
- if (cron.expressions?.length) {
15
- // cronParser.parseString expressions disregards seconds, so we have to parse again
14
+ if (timerType === 'timeCycle') {
15
+ try {
16
+ return super.parse(timerType, value);
17
+ } catch (err) {
18
+ var rangeError = err;
19
+ }
20
+
21
+ try {
16
22
  const expireAt = cronParser.parseExpression(value).next().toDate();
17
23
 
18
24
  return {
19
25
  expireAt,
20
26
  delay: expireAt - Date.now(),
21
27
  };
28
+ } catch (err) {
29
+ if (invalidCronEntryPattern.test(err.message)) throw rangeError;
30
+ throw err;
22
31
  }
23
32
  }
24
33