@voiceflow/utils-designer 1.8.5 → 1.9.0

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.
@@ -1,5 +1,5 @@
1
1
  import type { Entity, Intent, Variable } from '@voiceflow/dtos';
2
- import { SystemVariable } from '@voiceflow/dtos';
2
+ import { SystemVariable, VariableDatatype } from '@voiceflow/dtos';
3
3
  export declare const isSystemVariableName: (variableName: string) => variableName is SystemVariable;
4
4
  export declare const variableNameSpellingValidator: (value: string) => import("./main").IValidatorResult<string>;
5
5
  export declare const variableNameUniqVariablesValidator: import("./main").IValidatorWithContext<string, {
@@ -20,4 +20,11 @@ export declare const variableNameValidator: import("./main").IValidatorWithConte
20
20
  } & {
21
21
  intents: Intent[];
22
22
  }>;
23
+ export interface VariableDeclaration {
24
+ name: string;
25
+ defaultValue: string | null;
26
+ datatype: VariableDatatype;
27
+ isSystem: boolean;
28
+ }
29
+ export declare function parseCMSVariableDefaultValue(declare: VariableDeclaration): string | number | boolean | Date | null;
23
30
  //# sourceMappingURL=variable.util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variable.util.d.ts","sourceRoot":"","sources":["../../src/variable.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAe,MAAM,iBAAiB,CAAC;AAI9D,eAAO,MAAM,oBAAoB,iBAAkB,MAAM,mCACe,CAAC;AAEzE,eAAO,MAAM,6BAA6B,8DAA8C,CAAC;AAEzF,eAAO,MAAM,kCAAkC;eACU,QAAQ,EAAE;gBAAc,MAAM,GAAG,IAAI;EAG7F,CAAC;AAEF,eAAO,MAAM,iCAAiC;cACH,MAAM,EAAE;EAElD,CAAC;AAEF,eAAO,MAAM,gCAAgC;aACJ,MAAM,EAAE;EAEhD,CAAC;AAEF,eAAO,MAAM,qBAAqB;eAfuB,QAAQ,EAAE;gBAAc,MAAM,GAAG,IAAI;;cAMnD,MAAM,EAAE;;aAKV,MAAM,EAAE;EAShD,CAAC"}
1
+ {"version":3,"file":"variable.util.d.ts","sourceRoot":"","sources":["../../src/variable.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAA4B,cAAc,EAAE,gBAAgB,EAAe,MAAM,iBAAiB,CAAC;AAI1G,eAAO,MAAM,oBAAoB,iBAAkB,MAAM,mCACe,CAAC;AAEzE,eAAO,MAAM,6BAA6B,8DAA8C,CAAC;AAEzF,eAAO,MAAM,kCAAkC;eACU,QAAQ,EAAE;gBAAc,MAAM,GAAG,IAAI;EAG7F,CAAC;AAEF,eAAO,MAAM,iCAAiC;cACH,MAAM,EAAE;EAElD,CAAC;AAEF,eAAO,MAAM,gCAAgC;aACJ,MAAM,EAAE;EAEhD,CAAC;AAEF,eAAO,MAAM,qBAAqB;eAfuB,QAAQ,EAAE;gBAAc,MAAM,GAAG,IAAI;;cAMnD,MAAM,EAAE;;aAKV,MAAM,EAAE;EAShD,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,mBAAmB,2CAqBxE"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.variableNameValidator = exports.variableNameUniqIntentsValidator = exports.variableNameUniqEntitiesValidator = exports.variableNameUniqVariablesValidator = exports.variableNameSpellingValidator = exports.isSystemVariableName = void 0;
3
+ exports.parseCMSVariableDefaultValue = exports.variableNameValidator = exports.variableNameUniqIntentsValidator = exports.variableNameUniqEntitiesValidator = exports.variableNameUniqVariablesValidator = exports.variableNameSpellingValidator = exports.isSystemVariableName = void 0;
4
4
  const dtos_1 = require("@voiceflow/dtos");
5
5
  const validator_util_1 = require("./validator/validator.util");
6
6
  const isSystemVariableName = (variableName) => Object.values(dtos_1.SystemVariable).includes(variableName);
@@ -10,3 +10,24 @@ exports.variableNameUniqVariablesValidator = (0, validator_util_1.validatorFacto
10
10
  exports.variableNameUniqEntitiesValidator = (0, validator_util_1.validatorFactory)((name, { entities }) => entities.every((entity) => entity.name !== name), () => `Entity name already exists.`);
11
11
  exports.variableNameUniqIntentsValidator = (0, validator_util_1.validatorFactory)((name, { intents }) => intents.every((intent) => intent.name !== name), () => `Intent name already exists.`);
12
12
  exports.variableNameValidator = (0, validator_util_1.composeValidators)(exports.variableNameSpellingValidator, exports.variableNameUniqVariablesValidator, exports.variableNameUniqEntitiesValidator, exports.variableNameUniqIntentsValidator);
13
+ function parseCMSVariableDefaultValue(declare) {
14
+ const { name, datatype, defaultValue, isSystem } = declare;
15
+ if (!defaultValue)
16
+ return defaultValue;
17
+ const type = isSystem && (0, exports.isSystemVariableName)(name) ? dtos_1.SYSTEM_VARIABLE_TYPE_MAP[name] : datatype;
18
+ switch (type) {
19
+ case dtos_1.VariableDatatype.BOOLEAN:
20
+ return defaultValue.toLowerCase() === 'true';
21
+ case dtos_1.VariableDatatype.DATE:
22
+ return new Date(defaultValue);
23
+ case dtos_1.VariableDatatype.NUMBER:
24
+ return parseFloat(defaultValue);
25
+ case dtos_1.VariableDatatype.TEXT:
26
+ case dtos_1.VariableDatatype.IMAGE:
27
+ case dtos_1.VariableDatatype.ANY:
28
+ return defaultValue;
29
+ default:
30
+ throw new Error(`Received unexpected variable type '${type}'`);
31
+ }
32
+ }
33
+ exports.parseCMSVariableDefaultValue = parseCMSVariableDefaultValue;
@@ -1,5 +1,5 @@
1
1
  import type { Entity, Intent, Variable } from '@voiceflow/dtos';
2
- import { SystemVariable } from '@voiceflow/dtos';
2
+ import { SystemVariable, VariableDatatype } from '@voiceflow/dtos';
3
3
  export declare const isSystemVariableName: (variableName: string) => variableName is SystemVariable;
4
4
  export declare const variableNameSpellingValidator: (value: string) => import("./main.js").IValidatorResult<string>;
5
5
  export declare const variableNameUniqVariablesValidator: import("./main.js").IValidatorWithContext<string, {
@@ -20,4 +20,11 @@ export declare const variableNameValidator: import("./main.js").IValidatorWithCo
20
20
  } & {
21
21
  intents: Intent[];
22
22
  }>;
23
+ export interface VariableDeclaration {
24
+ name: string;
25
+ defaultValue: string | null;
26
+ datatype: VariableDatatype;
27
+ isSystem: boolean;
28
+ }
29
+ export declare function parseCMSVariableDefaultValue(declare: VariableDeclaration): string | number | boolean | Date | null;
23
30
  //# sourceMappingURL=variable.util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variable.util.d.ts","sourceRoot":"","sources":["../../src/variable.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAe,MAAM,iBAAiB,CAAC;AAI9D,eAAO,MAAM,oBAAoB,iBAAkB,MAAM,mCACe,CAAC;AAEzE,eAAO,MAAM,6BAA6B,8DAA8C,CAAC;AAEzF,eAAO,MAAM,kCAAkC;eACU,QAAQ,EAAE;gBAAc,MAAM,GAAG,IAAI;EAG7F,CAAC;AAEF,eAAO,MAAM,iCAAiC;cACH,MAAM,EAAE;EAElD,CAAC;AAEF,eAAO,MAAM,gCAAgC;aACJ,MAAM,EAAE;EAEhD,CAAC;AAEF,eAAO,MAAM,qBAAqB;eAfuB,QAAQ,EAAE;gBAAc,MAAM,GAAG,IAAI;;cAMnD,MAAM,EAAE;;aAKV,MAAM,EAAE;EAShD,CAAC"}
1
+ {"version":3,"file":"variable.util.d.ts","sourceRoot":"","sources":["../../src/variable.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAA4B,cAAc,EAAE,gBAAgB,EAAe,MAAM,iBAAiB,CAAC;AAI1G,eAAO,MAAM,oBAAoB,iBAAkB,MAAM,mCACe,CAAC;AAEzE,eAAO,MAAM,6BAA6B,8DAA8C,CAAC;AAEzF,eAAO,MAAM,kCAAkC;eACU,QAAQ,EAAE;gBAAc,MAAM,GAAG,IAAI;EAG7F,CAAC;AAEF,eAAO,MAAM,iCAAiC;cACH,MAAM,EAAE;EAElD,CAAC;AAEF,eAAO,MAAM,gCAAgC;aACJ,MAAM,EAAE;EAEhD,CAAC;AAEF,eAAO,MAAM,qBAAqB;eAfuB,QAAQ,EAAE;gBAAc,MAAM,GAAG,IAAI;;cAMnD,MAAM,EAAE;;aAKV,MAAM,EAAE;EAShD,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,mBAAmB,2CAqBxE"}
@@ -1,4 +1,4 @@
1
- import { SystemVariable, VariableDTO } from '@voiceflow/dtos';
1
+ import { SYSTEM_VARIABLE_TYPE_MAP, SystemVariable, VariableDatatype, VariableDTO } from '@voiceflow/dtos';
2
2
  import { composeValidators, validatorFactory, validatorZodFactory } from './validator/validator.util.js';
3
3
  export const isSystemVariableName = (variableName) => Object.values(SystemVariable).includes(variableName);
4
4
  export const variableNameSpellingValidator = validatorZodFactory(VariableDTO.shape.name);
@@ -6,3 +6,23 @@ export const variableNameUniqVariablesValidator = validatorFactory((name, { vari
6
6
  export const variableNameUniqEntitiesValidator = validatorFactory((name, { entities }) => entities.every((entity) => entity.name !== name), () => `Entity name already exists.`);
7
7
  export const variableNameUniqIntentsValidator = validatorFactory((name, { intents }) => intents.every((intent) => intent.name !== name), () => `Intent name already exists.`);
8
8
  export const variableNameValidator = composeValidators(variableNameSpellingValidator, variableNameUniqVariablesValidator, variableNameUniqEntitiesValidator, variableNameUniqIntentsValidator);
9
+ export function parseCMSVariableDefaultValue(declare) {
10
+ const { name, datatype, defaultValue, isSystem } = declare;
11
+ if (!defaultValue)
12
+ return defaultValue;
13
+ const type = isSystem && isSystemVariableName(name) ? SYSTEM_VARIABLE_TYPE_MAP[name] : datatype;
14
+ switch (type) {
15
+ case VariableDatatype.BOOLEAN:
16
+ return defaultValue.toLowerCase() === 'true';
17
+ case VariableDatatype.DATE:
18
+ return new Date(defaultValue);
19
+ case VariableDatatype.NUMBER:
20
+ return parseFloat(defaultValue);
21
+ case VariableDatatype.TEXT:
22
+ case VariableDatatype.IMAGE:
23
+ case VariableDatatype.ANY:
24
+ return defaultValue;
25
+ default:
26
+ throw new Error(`Received unexpected variable type '${type}'`);
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voiceflow/utils-designer",
3
- "version": "1.8.5",
3
+ "version": "1.9.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./build/cjs/main.d.ts",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@voiceflow/common": "8.2.7",
39
- "@voiceflow/dtos": "1.32.0",
39
+ "@voiceflow/dtos": "1.33.0",
40
40
  "bidirectional-adapter": "1.2.1",
41
41
  "ts-pattern": "^5.0.5",
42
42
  "zod": "3.22.4"
@@ -49,5 +49,5 @@
49
49
  "tsd": {
50
50
  "directory": "src"
51
51
  },
52
- "gitHead": "28e301c33087ea6b6d0a87960f9dd5b4768cdb90"
52
+ "gitHead": "b48c0e30c88de2446aadf9bfdbe4eb4a7269ba23"
53
53
  }