stentor-guards 1.56.41 → 1.56.44

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.
package/lib/isIntent.d.ts CHANGED
@@ -1,5 +1,10 @@
1
- /*! Copyright (c) 2019, XAPPmedia */
2
1
  import { Intent, Handler } from "stentor-models";
2
+ /**
3
+ * Detect if the intent is a
4
+ * @param props
5
+ * @returns
6
+ */
7
+ export declare function isBuiltInIntent(props: Handler | Intent): boolean;
3
8
  /**
4
9
  * Determine if the props are for an Intent
5
10
  *
package/lib/isIntent.js CHANGED
@@ -1,14 +1,81 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isIntent = void 0;
3
+ exports.isIntent = exports.isBuiltInIntent = void 0;
4
+ /*! Copyright (c) 2019, XAPPmedia */
5
+ const stentor_constants_1 = require("stentor-constants");
4
6
  const isHandler_1 = require("./isHandler");
7
+ /**
8
+ * Detect if the intent is a
9
+ * @param props
10
+ * @returns
11
+ */
12
+ function isBuiltInIntent(props) {
13
+ var _a, _b;
14
+ const intentId = props.intentId;
15
+ const BUILT_INS = [
16
+ stentor_constants_1.CANCEL_INTENT,
17
+ stentor_constants_1.FIRST_INTENT,
18
+ stentor_constants_1.HELP_INTENT,
19
+ stentor_constants_1.LATEST_INTENT,
20
+ stentor_constants_1.LOOP_OFF_INTENT,
21
+ stentor_constants_1.LOOP_ON_INTENT,
22
+ stentor_constants_1.NEXT_INTENT,
23
+ stentor_constants_1.NO_INTENT,
24
+ stentor_constants_1.PAUSE_INTENT,
25
+ stentor_constants_1.PREVIOUS_INTENT,
26
+ stentor_constants_1.REPEAT_INTENT,
27
+ stentor_constants_1.RESUME_INTENT,
28
+ stentor_constants_1.SHUFFLE_OFF_INTENT,
29
+ stentor_constants_1.SHUFFLE_ON_INTENT,
30
+ stentor_constants_1.START_OVER_INTENT,
31
+ stentor_constants_1.STOP_INTENT,
32
+ stentor_constants_1.YES_INTENT,
33
+ // This one is a special one
34
+ stentor_constants_1.INPUT_UNKNOWN
35
+ ];
36
+ if (BUILT_INS.includes(intentId)) {
37
+ return true;
38
+ }
39
+ // We also check overrides
40
+ if (!!props.nlu && typeof props.nlu === "object" && Object.keys(props.nlu).length > 0) {
41
+ const lex = props.nlu["lex"] || props.nlu["lex-connect"] || props.nlu["alexa"];
42
+ if ((_a = lex === null || lex === void 0 ? void 0 : lex.type) === null || _a === void 0 ? void 0 : _a.startsWith("AMAZON.")) {
43
+ return true;
44
+ }
45
+ const dialogflow = props.nlu["dialogflow"];
46
+ if ((_b = dialogflow === null || dialogflow === void 0 ? void 0 : dialogflow.type) === null || _b === void 0 ? void 0 : _b.startsWith("actions.intent")) {
47
+ return true;
48
+ }
49
+ }
50
+ return false;
51
+ }
52
+ exports.isBuiltInIntent = isBuiltInIntent;
5
53
  /**
6
54
  * Determine if the props are for an Intent
7
55
  *
8
56
  * @public
9
57
  */
10
58
  function isIntent(props) {
11
- return !!props && (!(0, isHandler_1.isHandler)(props) || (Array.isArray(props.utterancePatterns) && props.utterancePatterns.length > 0));
59
+ if (!props) {
60
+ return false;
61
+ }
62
+ // if not a handler, return true!
63
+ if (!(0, isHandler_1.isHandler)(props)) {
64
+ return true;
65
+ }
66
+ // if they have utterance patterns, even an empty array, it is true
67
+ if (Array.isArray(props.utterancePatterns)) {
68
+ return true;
69
+ }
70
+ // built-ins dont need any utterances
71
+ if (isBuiltInIntent(props)) {
72
+ return true;
73
+ }
74
+ // if they do any kind of override we are going to trust them
75
+ if (!!props.nlu && typeof props.nlu === "object" && Object.keys(props.nlu).length > 0) {
76
+ return true;
77
+ }
78
+ return false;
12
79
  }
13
80
  exports.isIntent = isIntent;
14
81
  //# sourceMappingURL=isIntent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isIntent.js","sourceRoot":"","sources":["../src/isIntent.ts"],"names":[],"mappings":";;;AAEA,2CAAwC;AAExC;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,KAAuB;IAC5C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AAC,SAAS,CAAC,EAAE;YAClC,OAAO,IAAI,CAAC;SACf;QAGD,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAE3C,IAAI,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,0CAAE,UAAU,CAAC,gBAAgB,CAAC,EAAE;YAChD,OAAO,IAAI,CAAC;SACf;KACJ;IAED,OAAO,KAAK,CAAA;AAChB,CAAC;AAhDD,0CAgDC;AAED;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,KAAuB;IAE5C,IAAI,CAAC,KAAK,EAAE;QACR,OAAO,KAAK,CAAC;KAChB;IAED,iCAAiC;IACjC,IAAI,CAAC,IAAA,qBAAS,EAAC,KAAK,CAAC,EAAE;QACnB,OAAO,IAAI,CAAC;KACf;IAED,mEAAmE;IACnE,IAAI,KAAK,CAAC,OAAO,CAAE,KAAgB,CAAC,iBAAiB,CAAC,EAAE;QACpD,OAAO,IAAI,CAAC;KACf;IAED,sCAAsC;IACtC,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,IAAI,CAAC;KACf;IAED,6DAA6D;IAC7D,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QACnF,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AA3BD,4BA2BC"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "1.56.41",
7
+ "version": "1.56.44",
8
8
  "description": "Common type guards for 📣 stentor",
9
9
  "types": "lib/index",
10
10
  "main": "lib/index",
@@ -23,12 +23,12 @@
23
23
  "mocha": "9.2.2",
24
24
  "sinon": "14.0.0",
25
25
  "sinon-chai": "3.7.0",
26
- "stentor-models": "1.56.41",
26
+ "stentor-models": "1.56.44",
27
27
  "ts-node": "10.9.1",
28
28
  "typescript": "4.7.4"
29
29
  },
30
30
  "dependencies": {
31
- "stentor-constants": "1.56.41"
31
+ "stentor-constants": "1.56.44"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "stentor-models": "1.x"
@@ -38,5 +38,5 @@
38
38
  "clean": "rm -rf ./lib/* ",
39
39
  "test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
40
40
  },
41
- "gitHead": "d9bbd617c758fff5bc46f401b22f27321026ffe0"
41
+ "gitHead": "32ab2078e1386b2a2ecea8811dcd64c487791d2f"
42
42
  }