@aws-amplify/interactions 5.2.12-unstable.7762f1a.0 → 6.0.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.
Files changed (261) hide show
  1. package/README.md +3 -0
  2. package/lex-v1/package.json +7 -0
  3. package/lex-v2/package.json +7 -0
  4. package/lib/errors/InteractionsError.d.ts +4 -0
  5. package/lib/errors/InteractionsError.js +16 -0
  6. package/lib/errors/assertValidationError.d.ts +2 -0
  7. package/lib/errors/assertValidationError.js +18 -0
  8. package/lib/errors/index.d.ts +2 -0
  9. package/lib/errors/index.js +9 -0
  10. package/lib/errors/validation.d.ts +5 -0
  11. package/lib/errors/validation.js +14 -0
  12. package/lib/index.d.ts +2 -5
  13. package/lib/index.js +3 -9
  14. package/lib/lex-v1/AWSLexProvider.d.ts +20 -0
  15. package/lib/lex-v1/AWSLexProvider.js +119 -0
  16. package/lib/lex-v1/apis/index.d.ts +2 -0
  17. package/lib/lex-v1/apis/index.js +9 -0
  18. package/lib/lex-v1/apis/onComplete.d.ts +2 -0
  19. package/lib/lex-v1/apis/onComplete.js +15 -0
  20. package/lib/lex-v1/apis/send.d.ts +2 -0
  21. package/lib/lex-v1/apis/send.js +15 -0
  22. package/lib/lex-v1/index.d.ts +6 -0
  23. package/lib/lex-v1/index.js +13 -0
  24. package/lib/lex-v1/types/AWSLexProviderOption.d.ts +11 -0
  25. package/lib/{types/Response.js → lex-v1/types/AWSLexProviderOption.js} +0 -1
  26. package/lib/lex-v1/types/index.d.ts +3 -0
  27. package/lib/lex-v1/types/index.js +4 -0
  28. package/lib/lex-v1/types/inputs.d.ts +9 -0
  29. package/lib/lex-v1/types/inputs.js +4 -0
  30. package/lib/lex-v1/types/outputs.d.ts +5 -0
  31. package/lib/lex-v1/types/outputs.js +4 -0
  32. package/lib/lex-v1/utils/index.d.ts +1 -0
  33. package/lib/lex-v1/utils/index.js +7 -0
  34. package/lib/lex-v1/utils/resolveBotConfig.d.ts +2 -0
  35. package/lib/lex-v1/utils/resolveBotConfig.js +13 -0
  36. package/lib/lex-v2/AWSLexV2Provider.d.ts +52 -0
  37. package/lib/lex-v2/AWSLexV2Provider.js +166 -0
  38. package/lib/lex-v2/apis/index.d.ts +2 -0
  39. package/lib/lex-v2/apis/index.js +9 -0
  40. package/lib/lex-v2/apis/onComplete.d.ts +2 -0
  41. package/lib/lex-v2/apis/onComplete.js +15 -0
  42. package/lib/lex-v2/apis/send.d.ts +2 -0
  43. package/lib/lex-v2/apis/send.js +15 -0
  44. package/lib/lex-v2/index.d.ts +3 -0
  45. package/lib/lex-v2/index.js +10 -0
  46. package/lib/lex-v2/types/AWSLexV2ProviderOption.d.ts +13 -0
  47. package/lib/lex-v2/types/AWSLexV2ProviderOption.js +4 -0
  48. package/lib/lex-v2/types/index.d.ts +3 -0
  49. package/lib/lex-v2/types/index.js +4 -0
  50. package/lib/lex-v2/types/inputs.d.ts +9 -0
  51. package/lib/lex-v2/types/inputs.js +4 -0
  52. package/lib/lex-v2/types/outputs.d.ts +5 -0
  53. package/lib/lex-v2/types/outputs.js +4 -0
  54. package/lib/lex-v2/utils/index.d.ts +1 -0
  55. package/lib/lex-v2/utils/index.js +7 -0
  56. package/lib/lex-v2/utils/resolveBotConfig.d.ts +2 -0
  57. package/lib/lex-v2/utils/resolveBotConfig.js +13 -0
  58. package/lib/tsconfig.tsbuildinfo +1 -0
  59. package/lib/types/Interactions.d.ts +7 -6
  60. package/lib/types/Interactions.js +2 -1
  61. package/lib/types/index.d.ts +2 -5
  62. package/lib/types/index.js +2 -1
  63. package/lib/types/inputs.d.ts +9 -0
  64. package/lib/types/inputs.js +4 -0
  65. package/lib/types/outputs.d.ts +2 -0
  66. package/lib/types/outputs.js +4 -0
  67. package/lib/utils/commonUtils.d.ts +1 -0
  68. package/lib/utils/commonUtils.js +19 -0
  69. package/lib/utils/index.d.ts +2 -0
  70. package/lib/utils/index.js +11 -0
  71. package/lib/utils/utils.js +32 -0
  72. package/lib/utils/utils.native.js +45 -0
  73. package/lib-esm/errors/InteractionsError.d.ts +4 -0
  74. package/lib-esm/errors/InteractionsError.js +12 -0
  75. package/lib-esm/errors/assertValidationError.d.ts +2 -0
  76. package/lib-esm/errors/assertValidationError.js +14 -0
  77. package/lib-esm/errors/index.d.ts +2 -0
  78. package/lib-esm/errors/index.js +4 -0
  79. package/lib-esm/errors/validation.d.ts +5 -0
  80. package/lib-esm/errors/validation.js +11 -0
  81. package/lib-esm/index.d.ts +2 -5
  82. package/lib-esm/index.js +1 -5
  83. package/lib-esm/lex-v1/AWSLexProvider.d.ts +20 -0
  84. package/lib-esm/lex-v1/AWSLexProvider.js +116 -0
  85. package/lib-esm/lex-v1/apis/index.d.ts +2 -0
  86. package/lib-esm/lex-v1/apis/index.js +4 -0
  87. package/lib-esm/lex-v1/apis/onComplete.d.ts +2 -0
  88. package/lib-esm/lex-v1/apis/onComplete.js +11 -0
  89. package/lib-esm/lex-v1/apis/send.d.ts +2 -0
  90. package/lib-esm/lex-v1/apis/send.js +11 -0
  91. package/lib-esm/lex-v1/index.d.ts +6 -0
  92. package/lib-esm/lex-v1/index.js +10 -0
  93. package/lib-esm/lex-v1/types/AWSLexProviderOption.d.ts +11 -0
  94. package/lib-esm/{types/Response.js → lex-v1/types/AWSLexProviderOption.js} +1 -1
  95. package/lib-esm/lex-v1/types/index.d.ts +3 -0
  96. package/lib-esm/lex-v1/types/index.js +3 -0
  97. package/lib-esm/lex-v1/types/inputs.d.ts +9 -0
  98. package/lib-esm/lex-v1/types/inputs.js +3 -0
  99. package/lib-esm/lex-v1/types/outputs.d.ts +5 -0
  100. package/lib-esm/lex-v1/types/outputs.js +3 -0
  101. package/lib-esm/lex-v1/utils/index.d.ts +1 -0
  102. package/lib-esm/lex-v1/utils/index.js +3 -0
  103. package/lib-esm/lex-v1/utils/resolveBotConfig.d.ts +2 -0
  104. package/lib-esm/lex-v1/utils/resolveBotConfig.js +9 -0
  105. package/lib-esm/lex-v2/AWSLexV2Provider.d.ts +52 -0
  106. package/lib-esm/lex-v2/AWSLexV2Provider.js +163 -0
  107. package/lib-esm/lex-v2/apis/index.d.ts +2 -0
  108. package/lib-esm/lex-v2/apis/index.js +4 -0
  109. package/lib-esm/lex-v2/apis/onComplete.d.ts +2 -0
  110. package/lib-esm/lex-v2/apis/onComplete.js +11 -0
  111. package/lib-esm/lex-v2/apis/send.d.ts +2 -0
  112. package/lib-esm/lex-v2/apis/send.js +11 -0
  113. package/lib-esm/lex-v2/index.d.ts +3 -0
  114. package/lib-esm/lex-v2/index.js +7 -0
  115. package/lib-esm/lex-v2/types/AWSLexV2ProviderOption.d.ts +13 -0
  116. package/lib-esm/lex-v2/types/AWSLexV2ProviderOption.js +3 -0
  117. package/lib-esm/lex-v2/types/index.d.ts +3 -0
  118. package/lib-esm/lex-v2/types/index.js +3 -0
  119. package/lib-esm/lex-v2/types/inputs.d.ts +9 -0
  120. package/lib-esm/lex-v2/types/inputs.js +3 -0
  121. package/lib-esm/lex-v2/types/outputs.d.ts +5 -0
  122. package/lib-esm/lex-v2/types/outputs.js +3 -0
  123. package/lib-esm/lex-v2/utils/index.d.ts +1 -0
  124. package/lib-esm/lex-v2/utils/index.js +3 -0
  125. package/lib-esm/lex-v2/utils/resolveBotConfig.d.ts +2 -0
  126. package/lib-esm/lex-v2/utils/resolveBotConfig.js +9 -0
  127. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  128. package/lib-esm/types/Interactions.d.ts +7 -6
  129. package/lib-esm/types/Interactions.js +3 -1
  130. package/lib-esm/types/index.d.ts +2 -5
  131. package/lib-esm/types/index.js +3 -1
  132. package/lib-esm/types/inputs.d.ts +9 -0
  133. package/lib-esm/types/inputs.js +3 -0
  134. package/lib-esm/types/outputs.d.ts +2 -0
  135. package/lib-esm/types/outputs.js +3 -0
  136. package/lib-esm/utils/commonUtils.d.ts +1 -0
  137. package/lib-esm/utils/commonUtils.js +15 -0
  138. package/lib-esm/utils/index.d.ts +2 -0
  139. package/lib-esm/utils/index.js +4 -0
  140. package/lib-esm/utils/utils.js +26 -0
  141. package/lib-esm/utils/utils.native.js +39 -0
  142. package/package.json +67 -28
  143. package/src/errors/InteractionsError.ts +18 -0
  144. package/src/errors/assertValidationError.ts +24 -0
  145. package/src/errors/index.ts +5 -0
  146. package/src/errors/validation.ts +15 -0
  147. package/src/index.ts +2 -5
  148. package/src/lex-v1/AWSLexProvider.ts +167 -0
  149. package/src/lex-v1/apis/index.ts +5 -0
  150. package/src/lex-v1/apis/onComplete.ts +21 -0
  151. package/src/lex-v1/apis/send.ts +21 -0
  152. package/src/lex-v1/index.ts +14 -0
  153. package/src/lex-v1/types/AWSLexProviderOption.ts +16 -0
  154. package/src/lex-v1/types/index.ts +6 -0
  155. package/src/lex-v1/types/inputs.ts +17 -0
  156. package/src/lex-v1/types/outputs.ts +9 -0
  157. package/src/{types/Response.ts → lex-v1/utils/index.ts} +1 -3
  158. package/src/lex-v1/utils/resolveBotConfig.ts +15 -0
  159. package/src/{Providers → lex-v2}/AWSLexV2Provider.ts +67 -137
  160. package/src/lex-v2/apis/index.ts +5 -0
  161. package/src/lex-v2/apis/onComplete.ts +21 -0
  162. package/src/lex-v2/apis/send.ts +21 -0
  163. package/src/lex-v2/index.ts +11 -0
  164. package/src/{types/Providers/AWSLexV2Provider.ts → lex-v2/types/AWSLexV2ProviderOption.ts} +7 -4
  165. package/src/lex-v2/types/index.ts +6 -0
  166. package/src/lex-v2/types/inputs.ts +17 -0
  167. package/src/lex-v2/types/outputs.ts +9 -0
  168. package/src/lex-v2/utils/index.ts +4 -0
  169. package/src/lex-v2/utils/resolveBotConfig.ts +15 -0
  170. package/src/types/Interactions.ts +9 -3
  171. package/src/types/index.ts +3 -5
  172. package/src/types/inputs.ts +17 -0
  173. package/src/types/outputs.ts +6 -0
  174. package/src/utils/index.ts +5 -0
  175. package/lib/.tsbuildinfo +0 -3
  176. package/lib/Interactions.d.ts +0 -24
  177. package/lib/Interactions.js +0 -123
  178. package/lib/Interactions.js.map +0 -1
  179. package/lib/Providers/AWSLexProvider.d.ts +0 -24
  180. package/lib/Providers/AWSLexProvider.js +0 -187
  181. package/lib/Providers/AWSLexProvider.js.map +0 -1
  182. package/lib/Providers/AWSLexProviderHelper/commonUtils.d.ts +0 -1
  183. package/lib/Providers/AWSLexProviderHelper/commonUtils.js +0 -29
  184. package/lib/Providers/AWSLexProviderHelper/commonUtils.js.map +0 -1
  185. package/lib/Providers/AWSLexProviderHelper/utils.js +0 -38
  186. package/lib/Providers/AWSLexProviderHelper/utils.js.map +0 -1
  187. package/lib/Providers/AWSLexProviderHelper/utils.native.js +0 -55
  188. package/lib/Providers/AWSLexProviderHelper/utils.native.js.map +0 -1
  189. package/lib/Providers/AWSLexV2Provider.d.ts +0 -58
  190. package/lib/Providers/AWSLexV2Provider.js +0 -282
  191. package/lib/Providers/AWSLexV2Provider.js.map +0 -1
  192. package/lib/Providers/InteractionsProvider.d.ts +0 -11
  193. package/lib/Providers/InteractionsProvider.js +0 -32
  194. package/lib/Providers/InteractionsProvider.js.map +0 -1
  195. package/lib/Providers/index.d.ts +0 -3
  196. package/lib/Providers/index.js +0 -11
  197. package/lib/Providers/index.js.map +0 -1
  198. package/lib/index.js.map +0 -1
  199. package/lib/types/Interactions.js.map +0 -1
  200. package/lib/types/Provider.d.ts +0 -12
  201. package/lib/types/Provider.js +0 -3
  202. package/lib/types/Provider.js.map +0 -1
  203. package/lib/types/Providers/AWSLexProvider.d.ts +0 -10
  204. package/lib/types/Providers/AWSLexProvider.js +0 -3
  205. package/lib/types/Providers/AWSLexProvider.js.map +0 -1
  206. package/lib/types/Providers/AWSLexV2Provider.d.ts +0 -12
  207. package/lib/types/Providers/AWSLexV2Provider.js +0 -3
  208. package/lib/types/Providers/AWSLexV2Provider.js.map +0 -1
  209. package/lib/types/Response.d.ts +0 -3
  210. package/lib/types/Response.js.map +0 -1
  211. package/lib/types/index.js.map +0 -1
  212. package/lib-esm/.tsbuildinfo +0 -3
  213. package/lib-esm/Interactions.d.ts +0 -24
  214. package/lib-esm/Interactions.js +0 -121
  215. package/lib-esm/Interactions.js.map +0 -1
  216. package/lib-esm/Providers/AWSLexProvider.d.ts +0 -24
  217. package/lib-esm/Providers/AWSLexProvider.js +0 -185
  218. package/lib-esm/Providers/AWSLexProvider.js.map +0 -1
  219. package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.d.ts +0 -1
  220. package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.js +0 -27
  221. package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.js.map +0 -1
  222. package/lib-esm/Providers/AWSLexProviderHelper/utils.js +0 -36
  223. package/lib-esm/Providers/AWSLexProviderHelper/utils.js.map +0 -1
  224. package/lib-esm/Providers/AWSLexProviderHelper/utils.native.js +0 -53
  225. package/lib-esm/Providers/AWSLexProviderHelper/utils.native.js.map +0 -1
  226. package/lib-esm/Providers/AWSLexV2Provider.d.ts +0 -58
  227. package/lib-esm/Providers/AWSLexV2Provider.js +0 -280
  228. package/lib-esm/Providers/AWSLexV2Provider.js.map +0 -1
  229. package/lib-esm/Providers/InteractionsProvider.d.ts +0 -11
  230. package/lib-esm/Providers/InteractionsProvider.js +0 -30
  231. package/lib-esm/Providers/InteractionsProvider.js.map +0 -1
  232. package/lib-esm/Providers/index.d.ts +0 -3
  233. package/lib-esm/Providers/index.js +0 -6
  234. package/lib-esm/Providers/index.js.map +0 -1
  235. package/lib-esm/index.js.map +0 -1
  236. package/lib-esm/types/Interactions.js.map +0 -1
  237. package/lib-esm/types/Provider.d.ts +0 -12
  238. package/lib-esm/types/Provider.js +0 -1
  239. package/lib-esm/types/Provider.js.map +0 -1
  240. package/lib-esm/types/Providers/AWSLexProvider.d.ts +0 -10
  241. package/lib-esm/types/Providers/AWSLexProvider.js +0 -1
  242. package/lib-esm/types/Providers/AWSLexProvider.js.map +0 -1
  243. package/lib-esm/types/Providers/AWSLexV2Provider.d.ts +0 -12
  244. package/lib-esm/types/Providers/AWSLexV2Provider.js +0 -1
  245. package/lib-esm/types/Providers/AWSLexV2Provider.js.map +0 -1
  246. package/lib-esm/types/Response.d.ts +0 -3
  247. package/lib-esm/types/Response.js.map +0 -1
  248. package/lib-esm/types/index.js.map +0 -1
  249. package/src/Interactions.ts +0 -162
  250. package/src/Providers/AWSLexProvider.ts +0 -212
  251. package/src/Providers/InteractionsProvider.ts +0 -49
  252. package/src/Providers/index.ts +0 -5
  253. package/src/types/Provider.ts +0 -26
  254. package/src/types/Providers/AWSLexProvider.ts +0 -13
  255. /package/lib/{Providers/AWSLexProviderHelper → utils}/utils.d.ts +0 -0
  256. /package/lib/{Providers/AWSLexProviderHelper → utils}/utils.native.d.ts +0 -0
  257. /package/lib-esm/{Providers/AWSLexProviderHelper → utils}/utils.d.ts +0 -0
  258. /package/lib-esm/{Providers/AWSLexProviderHelper → utils}/utils.native.d.ts +0 -0
  259. /package/src/{Providers/AWSLexProviderHelper → utils}/commonUtils.ts +0 -0
  260. /package/src/{Providers/AWSLexProviderHelper → utils}/utils.native.ts +0 -0
  261. /package/src/{Providers/AWSLexProviderHelper → utils}/utils.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/interactions",
3
- "version": "5.2.12-unstable.7762f1a.0+7762f1a",
3
+ "version": "6.0.0",
4
4
  "description": "Interactions category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -8,10 +8,7 @@
8
8
  "react-native": {
9
9
  "./lib/index": "./lib-esm/index.js"
10
10
  },
11
- "sideEffects": [
12
- "./lib/Interactions.js",
13
- "./lib-esm/Interactions.js"
14
- ],
11
+ "sideEffects": false,
15
12
  "publishConfig": {
16
13
  "access": "public"
17
14
  },
@@ -19,16 +16,43 @@
19
16
  "test": "npm run lint && jest -w 1 --coverage",
20
17
  "test:size": "size-limit",
21
18
  "build-with-test": "npm run clean && npm test && tsc && webpack",
22
- "build:cjs": "node ./build es5 && webpack && webpack --config ./webpack.config.dev.js",
23
- "build:esm": "node ./build es6",
24
- "build:cjs:watch": "node ./build es5 --watch",
25
- "build:esm:watch": "node ./build es6 --watch",
19
+ "build:cjs": "rimraf lib && tsc -m commonjs --outDir lib && webpack && webpack --config ./webpack.config.dev.js",
20
+ "build:esm": "rimraf lib-esm && tsc -m esnext --outDir lib-esm",
21
+ "build:cjs:watch": "rimraf lib && tsc -m commonjs --outDir lib --watch",
22
+ "build:esm:watch": "rimraf lib-esm && tsc -m esnext --outDir lib-esm",
26
23
  "build": "npm run clean && npm run build:esm && npm run build:cjs",
27
24
  "clean": "npm run clean:size && rimraf lib-esm lib dist",
28
25
  "clean:size": "rimraf dual-publish-tmp tmp*",
29
26
  "format": "echo \"Not implemented\"",
30
27
  "lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
31
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88.6"
28
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 88.6"
29
+ },
30
+ "typesVersions": {
31
+ ">=4.2": {
32
+ "lex-v1": [
33
+ "./lib-esm/lex-v1/index.d.ts"
34
+ ],
35
+ "lex-v2": [
36
+ "./lib-esm/lex-v2/index.d.ts"
37
+ ]
38
+ }
39
+ },
40
+ "exports": {
41
+ ".": {
42
+ "types": "./lib-esm/index.d.ts",
43
+ "import": "./lib-esm/index.js",
44
+ "require": "./lib/index.js"
45
+ },
46
+ "./lex-v1": {
47
+ "types": "./lib-esm/lex-v1/index.d.ts",
48
+ "import": "./lib-esm/lex-v1/index.js",
49
+ "require": "./lib/lex-v1/index.js"
50
+ },
51
+ "./lex-v2": {
52
+ "types": "./lib-esm/lex-v2/index.d.ts",
53
+ "import": "./lib-esm/lex-v2/index.js",
54
+ "require": "./lib/lex-v2/index.js"
55
+ }
32
56
  },
33
57
  "repository": {
34
58
  "type": "git",
@@ -43,23 +67,41 @@
43
67
  "files": [
44
68
  "lib",
45
69
  "lib-esm",
46
- "src"
70
+ "src",
71
+ "lex-v1",
72
+ "lex-v2"
47
73
  ],
48
74
  "dependencies": {
49
- "@aws-amplify/core": "5.8.6-unstable.7762f1a.0+7762f1a",
50
- "@aws-sdk/client-lex-runtime-service": "3.186.3",
51
- "@aws-sdk/client-lex-runtime-v2": "3.186.3",
75
+ "@aws-sdk/client-lex-runtime-service": "3.398.0",
76
+ "@aws-sdk/client-lex-runtime-v2": "3.398.0",
52
77
  "base-64": "1.0.0",
53
78
  "fflate": "0.7.3",
54
79
  "pako": "2.0.4",
55
- "tslib": "^1.8.0"
80
+ "tslib": "^2.5.0",
81
+ "uuid": "^9.0.0"
82
+ },
83
+ "devDependencies": {
84
+ "@aws-amplify/core": "6.0.0",
85
+ "typescript": "^5.0.2"
56
86
  },
57
87
  "size-limit": [
58
88
  {
59
- "name": "Interactions (top-level class with Lex v2)",
89
+ "name": "Interactions (default to Lex v2)",
60
90
  "path": "./lib-esm/index.js",
61
- "import": "{ Amplify, Interactions, AWSLexV2Provider }",
62
- "limit": "76.02 kB"
91
+ "import": "{ Amplify, Interactions }",
92
+ "limit": "52.00 kB"
93
+ },
94
+ {
95
+ "name": "Interactions (Lex v2)",
96
+ "path": "./lib-esm/lex-v2/index.js",
97
+ "import": "{ Amplify, Interactions }",
98
+ "limit": "52.00 kB"
99
+ },
100
+ {
101
+ "name": "Interactions (Lex v1)",
102
+ "path": "./lib-esm/lex-v1/index.js",
103
+ "import": "{ Amplify, Interactions }",
104
+ "limit": "47.00 kB"
63
105
  }
64
106
  ],
65
107
  "jest": {
@@ -67,20 +109,17 @@
67
109
  "ts-jest": {
68
110
  "diagnostics": false,
69
111
  "tsConfig": {
70
- "lib": [
71
- "es5",
72
- "es2015",
73
- "dom",
74
- "esnext.asynciterable",
75
- "es2017.object"
76
- ],
77
- "allowJs": true
112
+ "allowJs": true,
113
+ "noEmitOnError": false
78
114
  }
79
115
  }
80
116
  },
81
117
  "transform": {
82
118
  "^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
83
119
  },
120
+ "testPathIgnorePatterns": [
121
+ "/testUtils/"
122
+ ],
84
123
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
85
124
  "moduleFileExtensions": [
86
125
  "ts",
@@ -100,11 +139,11 @@
100
139
  }
101
140
  },
102
141
  "coveragePathIgnorePatterns": [
103
- "/node_modules/",
142
+ "node_modules",
104
143
  "dist",
105
144
  "lib",
106
145
  "lib-esm"
107
146
  ]
108
147
  },
109
- "gitHead": "7762f1a7076e622ec354c24539a3b57ce3ec4290"
148
+ "gitHead": "d505105326d7f6214f6bd1e06eb20be3a3651377"
110
149
  }
@@ -0,0 +1,18 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ AmplifyError,
6
+ AmplifyErrorParams,
7
+ } from '@aws-amplify/core/internals/utils';
8
+
9
+ export class InteractionsError extends AmplifyError {
10
+ constructor(params: AmplifyErrorParams) {
11
+ super(params);
12
+
13
+ // Hack for making the custom error class work when transpiled to es5
14
+ // TODO: Delete the following 2 lines after we change the build target to >= es2015
15
+ this.constructor = InteractionsError;
16
+ Object.setPrototypeOf(this, InteractionsError.prototype);
17
+ }
18
+ }
@@ -0,0 +1,24 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ InteractionsValidationErrorCode,
6
+ validationErrorMap,
7
+ } from './validation';
8
+ import { InteractionsError } from './InteractionsError';
9
+
10
+ export function assertValidationError(
11
+ assertion: boolean,
12
+ name: InteractionsValidationErrorCode,
13
+ message?: string
14
+ ): asserts assertion {
15
+ if (!assertion) {
16
+ const { message: defaultMessage, recoverySuggestion } =
17
+ validationErrorMap[name];
18
+ throw new InteractionsError({
19
+ name,
20
+ message: message ?? defaultMessage,
21
+ recoverySuggestion,
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { assertValidationError } from './assertValidationError';
5
+ export { InteractionsValidationErrorCode } from './validation';
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
5
+
6
+ export enum InteractionsValidationErrorCode {
7
+ NoBotConfig = 'NoBotConfig',
8
+ }
9
+
10
+ export const validationErrorMap: AmplifyErrorMap<InteractionsValidationErrorCode> =
11
+ {
12
+ [InteractionsValidationErrorCode.NoBotConfig]: {
13
+ message: 'Missing configuration for the bot',
14
+ },
15
+ };
package/src/index.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- export { Interactions } from './Interactions';
5
- export * from './types';
6
- export { AbstractInteractionsProvider } from './Providers/InteractionsProvider';
7
- export { AWSLexProvider } from './Providers/AWSLexProvider';
8
- export { AWSLexV2Provider } from './Providers/AWSLexV2Provider';
4
+ export { Interactions } from './lex-v2';
5
+ export { SendInput, OnCompleteInput, SendOutput } from './lex-v2/types';
@@ -0,0 +1,167 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import {
4
+ InteractionsOnCompleteCallback,
5
+ InteractionsMessage,
6
+ InteractionsResponse,
7
+ } from '../types/Interactions';
8
+ import {
9
+ DialogState,
10
+ LexRuntimeServiceClient,
11
+ PostContentCommand,
12
+ PostContentCommandInput,
13
+ PostContentCommandOutput,
14
+ PostTextCommand,
15
+ PostTextCommandInput,
16
+ PostTextCommandOutput,
17
+ } from '@aws-sdk/client-lex-runtime-service';
18
+ import { getAmplifyUserAgentObject } from '@aws-amplify/core/internals/utils';
19
+ import { ConsoleLogger, fetchAuthSession } from '@aws-amplify/core';
20
+ import { convert } from '../utils';
21
+ import { AWSLexProviderOption } from './types';
22
+
23
+ const logger = new ConsoleLogger('AWSLexProvider');
24
+
25
+ interface PostContentCommandOutputFormatted
26
+ extends Omit<PostContentCommandOutput, 'audioStream'> {
27
+ audioStream?: Uint8Array;
28
+ }
29
+
30
+ type AWSLexProviderSendResponse =
31
+ | PostTextCommandOutput
32
+ | PostContentCommandOutputFormatted;
33
+
34
+ class AWSLexProvider {
35
+ private readonly _botsCompleteCallback: Record<
36
+ string,
37
+ InteractionsOnCompleteCallback
38
+ > = {};
39
+
40
+ /**
41
+ * @deprecated
42
+ * This is used internally by 'sendMessage' to call onComplete callback
43
+ * for a bot if configured
44
+ */
45
+ reportBotStatus(
46
+ data: AWSLexProviderSendResponse,
47
+ { name }: AWSLexProviderOption
48
+ ) {
49
+ const callback = this._botsCompleteCallback[name];
50
+ if (!callback) {
51
+ return;
52
+ }
53
+ // Check if state is fulfilled to resolve onFullfilment promise
54
+ logger.debug('postContent state', data.dialogState);
55
+
56
+ switch (data.dialogState) {
57
+ case DialogState.READY_FOR_FULFILLMENT:
58
+ case DialogState.FULFILLED:
59
+ callback(undefined, data);
60
+ break;
61
+ case DialogState.FAILED:
62
+ callback(new Error('Bot conversation failed'));
63
+ break;
64
+ default:
65
+ break;
66
+ }
67
+ }
68
+
69
+ async sendMessage(
70
+ botConfig: AWSLexProviderOption,
71
+ message: string | InteractionsMessage
72
+ ): Promise<InteractionsResponse> {
73
+ // check if credentials are present
74
+ let session;
75
+ try {
76
+ session = await fetchAuthSession();
77
+ } catch (error) {
78
+ return Promise.reject('No credentials');
79
+ }
80
+
81
+ const { name, region, alias } = botConfig;
82
+ const client = new LexRuntimeServiceClient({
83
+ region,
84
+ credentials: session.credentials,
85
+ customUserAgent: getAmplifyUserAgentObject(),
86
+ });
87
+
88
+ let params: PostTextCommandInput | PostContentCommandInput;
89
+ if (typeof message === 'string') {
90
+ params = {
91
+ botAlias: alias,
92
+ botName: name,
93
+ inputText: message,
94
+ userId: session.identityId,
95
+ };
96
+
97
+ logger.debug('postText to lex', message);
98
+ try {
99
+ const postTextCommand = new PostTextCommand(params);
100
+ const data = await client.send(postTextCommand);
101
+
102
+ this.reportBotStatus(data, botConfig);
103
+ return data;
104
+ } catch (err) {
105
+ return Promise.reject(err);
106
+ }
107
+ } else {
108
+ const {
109
+ content,
110
+ options: { messageType },
111
+ } = message;
112
+ if (messageType === 'voice') {
113
+ if (typeof content !== 'object') {
114
+ return Promise.reject('invalid content type');
115
+ }
116
+ const inputStream =
117
+ content instanceof Uint8Array ? content : await convert(content);
118
+
119
+ params = {
120
+ botAlias: alias,
121
+ botName: name,
122
+ contentType: 'audio/x-l16; sample-rate=16000; channel-count=1',
123
+ userId: session.identityId,
124
+ accept: 'audio/mpeg',
125
+ inputStream,
126
+ };
127
+ } else {
128
+ if (typeof content !== 'string')
129
+ return Promise.reject('invalid content type');
130
+
131
+ params = {
132
+ botAlias: alias,
133
+ botName: name,
134
+ contentType: 'text/plain; charset=utf-8',
135
+ inputStream: content,
136
+ userId: session.identityId,
137
+ accept: 'audio/mpeg',
138
+ };
139
+ }
140
+ logger.debug('postContent to lex', message);
141
+ try {
142
+ const postContentCommand = new PostContentCommand(params);
143
+ const data = await client.send(postContentCommand);
144
+
145
+ const audioArray = data.audioStream
146
+ ? await convert(data.audioStream)
147
+ : undefined;
148
+
149
+ const response = { ...data, ...{ audioStream: audioArray } };
150
+
151
+ this.reportBotStatus(response, botConfig);
152
+ return response;
153
+ } catch (err) {
154
+ return Promise.reject(err);
155
+ }
156
+ }
157
+ }
158
+
159
+ onComplete(
160
+ { name }: AWSLexProviderOption,
161
+ callback: InteractionsOnCompleteCallback
162
+ ) {
163
+ this._botsCompleteCallback[name] = callback;
164
+ }
165
+ }
166
+
167
+ export const lexProvider = new AWSLexProvider();
@@ -0,0 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { send } from './send';
5
+ export { onComplete } from './onComplete';
@@ -0,0 +1,21 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { OnCompleteInput } from '../types';
5
+ import { resolveBotConfig } from '../utils';
6
+ import { lexProvider } from '../AWSLexProvider';
7
+ import {
8
+ assertValidationError,
9
+ InteractionsValidationErrorCode,
10
+ } from '../../errors';
11
+
12
+ export const onComplete = (input: OnCompleteInput): void => {
13
+ const { botName, callback } = input;
14
+ const botConfig = resolveBotConfig(botName);
15
+ assertValidationError(
16
+ !!botConfig,
17
+ InteractionsValidationErrorCode.NoBotConfig,
18
+ `Bot ${botName} does not exist.`
19
+ );
20
+ lexProvider.onComplete(botConfig, callback);
21
+ };
@@ -0,0 +1,21 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { SendInput, SendOutput } from '../types';
5
+ import { resolveBotConfig } from '../utils';
6
+ import { lexProvider } from '../AWSLexProvider';
7
+ import {
8
+ assertValidationError,
9
+ InteractionsValidationErrorCode,
10
+ } from '../../errors';
11
+
12
+ export const send = async (input: SendInput): Promise<SendOutput> => {
13
+ const { botName, message } = input;
14
+ const botConfig = resolveBotConfig(botName);
15
+ assertValidationError(
16
+ !!botConfig,
17
+ InteractionsValidationErrorCode.NoBotConfig,
18
+ `Bot ${botName} does not exist.`
19
+ );
20
+ return lexProvider.sendMessage(botConfig, message);
21
+ };
@@ -0,0 +1,14 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { send, onComplete } from './apis';
5
+ import { IInteractions } from './types/AWSLexProviderOption';
6
+
7
+ /**
8
+ * @deprecated recommend to migrate to AWS Lex V2 instead
9
+ * */
10
+ export const Interactions: IInteractions = {
11
+ send,
12
+ onComplete,
13
+ };
14
+ export { SendInput, OnCompleteInput, SendOutput } from './types';
@@ -0,0 +1,16 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { SendInput, OnCompleteInput } from './inputs';
5
+ import { SendOutput } from './outputs';
6
+
7
+ export interface AWSLexProviderOption {
8
+ name: string;
9
+ alias: string;
10
+ region: string;
11
+ }
12
+
13
+ export interface IInteractions {
14
+ send(input: SendInput): Promise<SendOutput>;
15
+ onComplete(input: OnCompleteInput): void;
16
+ }
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { AWSLexProviderOption } from './AWSLexProviderOption';
5
+ export { SendInput, OnCompleteInput } from './inputs';
6
+ export { SendOutput } from './outputs';
@@ -0,0 +1,17 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ InteractionsSendInput,
6
+ InteractionsOnCompleteInput,
7
+ } from '../../types';
8
+
9
+ /**
10
+ * Input type for LexV1 send API.
11
+ */
12
+ export type SendInput = InteractionsSendInput;
13
+
14
+ /**
15
+ * Input type for LexV1 onComplete API.
16
+ */
17
+ export type OnCompleteInput = InteractionsOnCompleteInput;
@@ -0,0 +1,9 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { InteractionsSendOutput } from '../../types';
5
+
6
+ /**
7
+ * Output type for LexV1 send API.
8
+ */
9
+ export type SendOutput = InteractionsSendOutput;
@@ -1,6 +1,4 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- export type InteractionsResponse = {
5
- [key: string]: any;
6
- };
4
+ export { resolveBotConfig } from './resolveBotConfig';
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AWSLexProviderOption } from '../types';
5
+ import { Amplify } from '@aws-amplify/core';
6
+
7
+ export const resolveBotConfig = (
8
+ botName: string
9
+ ): AWSLexProviderOption | undefined => {
10
+ const { [botName]: botConfig = undefined } =
11
+ Amplify.getConfig().Interactions?.LexV1 ?? {};
12
+ if (botConfig !== undefined) {
13
+ return { ...botConfig, name: botName };
14
+ }
15
+ };