botframework-webchat-core 4.13.0 → 4.14.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.
Files changed (107) hide show
  1. package/lib/createPromiseQueue.js +1 -1
  2. package/lib/createStore.d.ts +3 -2
  3. package/lib/createStore.d.ts.map +1 -0
  4. package/lib/createStore.js +1 -1
  5. package/lib/index.d.ts +49 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +26 -6
  8. package/lib/reducer.d.ts +1 -0
  9. package/lib/reducer.d.ts.map +1 -0
  10. package/lib/reducers/activities.js +1 -1
  11. package/lib/reducers/clockSkewAdjustment.js +1 -1
  12. package/lib/reducers/lastTypingAt.js +1 -1
  13. package/lib/reducers/notifications.js +1 -1
  14. package/lib/reducers/typing.js +1 -1
  15. package/lib/sagas/connectSaga.js +14 -8
  16. package/lib/sagas/connectionStatusToNotificationSaga.js +1 -1
  17. package/lib/sagas/effects/forkPut.js +1 -1
  18. package/lib/sagas/markAllAsSpokenOnStopSpeakActivitySaga.js +1 -1
  19. package/lib/sagas/observeActivitySaga.js +1 -1
  20. package/lib/sagas/postActivitySaga.js +39 -32
  21. package/lib/sagas/queueIncomingActivitySaga.js +7 -3
  22. package/lib/sagas/sendMessageBackToPostActivitySaga.js +4 -4
  23. package/lib/sagas/sendPostBackToPostActivitySaga.js +4 -4
  24. package/lib/selectors/combineSelectors.js +1 -1
  25. package/lib/types/OneOrMany.d.ts +3 -0
  26. package/lib/types/OneOrMany.d.ts.map +1 -0
  27. package/lib/types/OneOrMany.js +2 -0
  28. package/lib/types/external/DirectLineActivity.d.ts +3 -0
  29. package/lib/types/external/DirectLineActivity.d.ts.map +1 -0
  30. package/lib/types/external/DirectLineActivity.js +2 -0
  31. package/lib/types/external/DirectLineAnimationCard.d.ts +3 -0
  32. package/lib/types/external/DirectLineAnimationCard.d.ts.map +1 -0
  33. package/lib/types/external/DirectLineAnimationCard.js +2 -0
  34. package/lib/types/external/DirectLineAttachment.d.ts +3 -0
  35. package/lib/types/external/DirectLineAttachment.d.ts.map +1 -0
  36. package/lib/types/external/DirectLineAttachment.js +2 -0
  37. package/lib/types/external/DirectLineAudioCard.d.ts +3 -0
  38. package/lib/types/external/DirectLineAudioCard.d.ts.map +1 -0
  39. package/lib/types/external/DirectLineAudioCard.js +2 -0
  40. package/lib/types/external/DirectLineCardAction.d.ts +110 -0
  41. package/lib/types/external/DirectLineCardAction.d.ts.map +1 -0
  42. package/lib/types/external/DirectLineCardAction.js +2 -0
  43. package/lib/types/external/DirectLineHeroCard.d.ts +3 -0
  44. package/lib/types/external/DirectLineHeroCard.d.ts.map +1 -0
  45. package/lib/types/external/DirectLineHeroCard.js +2 -0
  46. package/lib/types/external/DirectLineJSBotConnection.d.ts +3 -0
  47. package/lib/types/external/DirectLineJSBotConnection.d.ts.map +1 -0
  48. package/lib/types/external/DirectLineJSBotConnection.js +2 -0
  49. package/lib/types/external/DirectLineOAuthCard.d.ts +3 -0
  50. package/lib/types/external/DirectLineOAuthCard.d.ts.map +1 -0
  51. package/lib/types/external/DirectLineOAuthCard.js +2 -0
  52. package/lib/types/external/DirectLineReceiptCard.d.ts +3 -0
  53. package/lib/types/external/DirectLineReceiptCard.d.ts.map +1 -0
  54. package/lib/types/external/DirectLineReceiptCard.js +2 -0
  55. package/lib/types/external/DirectLineSignInCard.d.ts +3 -0
  56. package/lib/types/external/DirectLineSignInCard.d.ts.map +1 -0
  57. package/lib/types/external/DirectLineSignInCard.js +2 -0
  58. package/lib/types/external/DirectLineSuggestedAction.d.ts +3 -0
  59. package/lib/types/external/DirectLineSuggestedAction.d.ts.map +1 -0
  60. package/lib/types/external/DirectLineSuggestedAction.js +2 -0
  61. package/lib/types/external/DirectLineThumbnailCard.d.ts +3 -0
  62. package/lib/types/external/DirectLineThumbnailCard.d.ts.map +1 -0
  63. package/lib/types/external/DirectLineThumbnailCard.js +2 -0
  64. package/lib/types/external/DirectLineVideoCard.d.ts +3 -0
  65. package/lib/types/external/DirectLineVideoCard.d.ts.map +1 -0
  66. package/lib/types/external/DirectLineVideoCard.js +2 -0
  67. package/lib/utils/dateToLocaleISOString.js +37 -0
  68. package/lib/utils/deleteKey.js +1 -1
  69. package/lib/utils/once.d.ts +2 -0
  70. package/lib/utils/once.d.ts.map +1 -0
  71. package/lib/utils/once.js +17 -0
  72. package/lib/utils/singleToArray.d.ts +2 -0
  73. package/lib/utils/singleToArray.d.ts.map +1 -0
  74. package/lib/utils/singleToArray.js +11 -0
  75. package/lib/utils/warnOnce.d.ts +2 -0
  76. package/lib/utils/warnOnce.d.ts.map +1 -0
  77. package/lib/utils/warnOnce.js +17 -0
  78. package/package.json +25 -21
  79. package/src/createStore.ts +2 -2
  80. package/src/{index.js → index.ts} +38 -4
  81. package/src/sagas/connectSaga.js +9 -2
  82. package/src/sagas/postActivitySaga.js +11 -4
  83. package/src/sagas/sendMessageBackToPostActivitySaga.js +3 -3
  84. package/src/sagas/sendPostBackToPostActivitySaga.js +2 -3
  85. package/src/tsconfig.json +7 -3
  86. package/src/types/OneOrMany.ts +3 -0
  87. package/src/types/external/DirectLineActivity.ts +6 -0
  88. package/src/types/external/DirectLineAnimationCard.ts +6 -0
  89. package/src/types/external/DirectLineAttachment.ts +6 -0
  90. package/src/types/external/DirectLineAudioCard.ts +6 -0
  91. package/src/types/external/DirectLineCardAction.ts +128 -0
  92. package/src/types/external/DirectLineHeroCard.ts +6 -0
  93. package/src/types/external/DirectLineJSBotConnection.ts +6 -0
  94. package/src/types/external/DirectLineOAuthCard.ts +6 -0
  95. package/src/types/external/DirectLineReceiptCard.ts +6 -0
  96. package/src/types/external/DirectLineSignInCard.ts +6 -0
  97. package/src/types/external/DirectLineSuggestedAction.ts +6 -0
  98. package/src/types/external/DirectLineThumbnailCard.ts +6 -0
  99. package/src/types/external/DirectLineVideoCard.ts +6 -0
  100. package/src/utils/dateToLocaleISOString.chatham.spec.js +13 -0
  101. package/src/utils/dateToLocaleISOString.japan.spec.js +13 -0
  102. package/src/utils/dateToLocaleISOString.js +34 -0
  103. package/src/utils/dateToLocaleISOString.pacific.spec.js +13 -0
  104. package/src/utils/dateToLocaleISOString.utc.spec.js +20 -0
  105. package/src/utils/once.ts +10 -0
  106. package/src/utils/singleToArray.ts +3 -0
  107. package/src/utils/warnOnce.ts +5 -0
@@ -0,0 +1,128 @@
1
+ type CardActionWithImageAndTitle =
2
+ | { image: string }
3
+ | { title: string }
4
+ | {
5
+ image: string;
6
+ title: string;
7
+ };
8
+
9
+ /**
10
+ * A `call` action represents a telephone number that may be called.
11
+ *
12
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#call
13
+ */
14
+ type CallCardAction = CardActionWithImageAndTitle & {
15
+ type: 'call';
16
+ value: string;
17
+ };
18
+
19
+ /**
20
+ * A `downloadFile` action represents a hyperlink to be downloaded.
21
+ *
22
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#download-file-actions
23
+ */
24
+ type DownloadFileCardAction = CardActionWithImageAndTitle & {
25
+ type: 'downloadFile';
26
+ value: string;
27
+ };
28
+
29
+ /**
30
+ * An `imBack` action represents a text response that is added to the chat feed.
31
+ *
32
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#im-back
33
+ */
34
+ type IMBackCardAction = CardActionWithImageAndTitle & {
35
+ type: 'imBack';
36
+ value: string;
37
+ };
38
+
39
+ /**
40
+ * A `messageBack` action represents a text response to be sent via the chat system.
41
+ *
42
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#message-back
43
+ */
44
+ type MessageBackCardAction = CardActionWithImageAndTitle & {
45
+ displayText?: string;
46
+ text?: string;
47
+ type: 'messageBack';
48
+ value?: { [key: string]: any };
49
+ };
50
+
51
+ /**
52
+ * An `openUrl` action represents a hyperlink to be handled by the client.
53
+ *
54
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#open-url-actions
55
+ */
56
+ type OpenURLCardAction = CardActionWithImageAndTitle & {
57
+ type: 'openUrl';
58
+ value: string;
59
+ };
60
+
61
+ /**
62
+ * A `playAudio` action represents audio media that may be played.
63
+ *
64
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#play-audio
65
+ */
66
+ type PlayAudioCardAction = CardActionWithImageAndTitle & {
67
+ type: 'playAudio';
68
+ value: string;
69
+ };
70
+
71
+ /**
72
+ * A `playVideo` action represents video media that may be played.
73
+ *
74
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#play-video
75
+ */
76
+ type PlayVideoCardAction = CardActionWithImageAndTitle & {
77
+ type: 'playVideo';
78
+ value: string;
79
+ };
80
+
81
+ /**
82
+ * A `postBack` action represents a text response that is not added to the chat feed.
83
+ *
84
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#post-back
85
+ */
86
+ type PostBackCardAction = CardActionWithImageAndTitle & {
87
+ type: 'postBack';
88
+ value: any; // For legacy reason, postBack support any.
89
+ };
90
+
91
+ /**
92
+ * A `showImage` action represents an image that may be displayed.
93
+ *
94
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#show-image-file-actions
95
+ */
96
+ type ShowImageCardAction = CardActionWithImageAndTitle & {
97
+ type: 'showImage';
98
+ value: string;
99
+ };
100
+
101
+ /**
102
+ * A `signin` action represents a hyperlink to be handled by the client's signin system.
103
+ *
104
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#signin
105
+ */
106
+ type SignInCardAction = CardActionWithImageAndTitle & {
107
+ type: 'signin';
108
+ value: string;
109
+ };
110
+
111
+ /**
112
+ * A card action represents a clickable or interactive button for use within cards or as suggested actions. They are used to solicit input from users. Despite their name, card actions are not limited to use solely on cards.
113
+ *
114
+ * https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#card-action
115
+ */
116
+ type DirectLineCardAction =
117
+ | CallCardAction
118
+ | DownloadFileCardAction
119
+ | IMBackCardAction
120
+ | MessageBackCardAction
121
+ | OpenURLCardAction
122
+ | PlayAudioCardAction
123
+ | PlayVideoCardAction
124
+ | PostBackCardAction
125
+ | ShowImageCardAction
126
+ | SignInCardAction;
127
+
128
+ export default DirectLineCardAction;
@@ -0,0 +1,6 @@
1
+ // TODO: [P1] #3953 We should fully type it out.
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type DirectLineHeroCard = any;
5
+
6
+ export default DirectLineHeroCard;
@@ -0,0 +1,6 @@
1
+ // TODO: [P1] #3953 We should fully type it out.
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type DirectLineJSBotConnection = any;
5
+
6
+ export default DirectLineJSBotConnection;
@@ -0,0 +1,6 @@
1
+ // TODO: [P1] #3953 We should fully type it out.
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type DirectLineOAuthCard = any;
5
+
6
+ export default DirectLineOAuthCard;
@@ -0,0 +1,6 @@
1
+ // TODO: [P1] #3953 We should fully type it out.
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type DirectLineReceiptCard = any;
5
+
6
+ export default DirectLineReceiptCard;
@@ -0,0 +1,6 @@
1
+ // TODO: [P1] #3953 We should fully type it out.
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type DirectLineSignInCard = any;
5
+
6
+ export default DirectLineSignInCard;
@@ -0,0 +1,6 @@
1
+ // TODO: [P1] #3953 We should fully type it out.
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type DirectLineSuggestedAction = any;
5
+
6
+ export default DirectLineSuggestedAction;
@@ -0,0 +1,6 @@
1
+ // TODO: [P1] #3953 We should fully type it out.
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type DirectLineThumbnailCard = any;
5
+
6
+ export default DirectLineThumbnailCard;
@@ -0,0 +1,6 @@
1
+ // TODO: [P1] #3953 We should fully type it out.
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type DirectLineVideoCard = any;
5
+
6
+ export default DirectLineVideoCard;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @jest-environment ../../../__tests__/setup/jestNodeEnvironmentWithTimezone.js
3
+ * @timezone Pacific/Chatham
4
+ */
5
+
6
+ import dateToLocaleISOString from './dateToLocaleISOString';
7
+
8
+ test('formatting a time in Chatham Islands timezone', () => {
9
+ const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 567));
10
+ const actual = dateToLocaleISOString(date);
11
+
12
+ expect(actual).toMatchInlineSnapshot(`"2000-01-01T13:57:34.567+13:45"`);
13
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @jest-environment ../../../__tests__/setup/jestNodeEnvironmentWithTimezone.js
3
+ * @timezone Asia/Tokyo
4
+ */
5
+
6
+ import dateToLocaleISOString from './dateToLocaleISOString';
7
+
8
+ test('formatting a time in Japan timezone', () => {
9
+ const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 567));
10
+ const actual = dateToLocaleISOString(date);
11
+
12
+ expect(actual).toMatchInlineSnapshot(`"2000-01-01T09:12:34.567+09:00"`);
13
+ });
@@ -0,0 +1,34 @@
1
+ /* eslint no-magic-numbers: ["off", { "ignore": [1, 2, 3, 60] }] */
2
+
3
+ function pad(value, count = 2) {
4
+ if (typeof value !== 'number') {
5
+ throw new Error('First argument must be a number');
6
+ }
7
+
8
+ value += '';
9
+
10
+ while (value.length < count) {
11
+ value = '0' + value;
12
+ }
13
+
14
+ return value;
15
+ }
16
+
17
+ // Adopted from https://stackoverflow.com/questions/17415579/how-to-iso-8601-format-a-date-with-timezone-offset-in-javascript.
18
+ export default function dateToLocaleISOString(date) {
19
+ if (!(date instanceof Date)) {
20
+ throw new Error('First argument must be a Date object');
21
+ }
22
+
23
+ const timezoneOffset = -date.getTimezoneOffset();
24
+ const timezoneSign = timezoneOffset < 0 ? '-' : '+';
25
+
26
+ // "yyyy-MM-DDTHH:mm:ss.fff+08:00" for GMT+08
27
+ // "yyyy-MM-DDTHH:mm:ss.fffZ" for UTC
28
+
29
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
30
+ date.getMinutes()
31
+ )}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}${
32
+ timezoneOffset ? `${timezoneSign}${pad(~~(Math.abs(timezoneOffset) / 60))}:${pad(timezoneOffset % 60)}` : 'Z'
33
+ }`;
34
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @jest-environment ../../../__tests__/setup/jestNodeEnvironmentWithTimezone.js
3
+ * @timezone America/Los_Angeles
4
+ */
5
+
6
+ import dateToLocaleISOString from './dateToLocaleISOString';
7
+
8
+ test('formatting a time in Pacific Standard Time timezone', () => {
9
+ const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 567));
10
+ const actual = dateToLocaleISOString(date);
11
+
12
+ expect(actual).toMatchInlineSnapshot(`"1999-12-31T16:12:34.567-08:00"`);
13
+ });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @jest-environment ../../../__tests__/setup/jestNodeEnvironmentWithTimezone.js
3
+ * @timezone Etc/UTC
4
+ */
5
+
6
+ import dateToLocaleISOString from './dateToLocaleISOString';
7
+
8
+ test('formatting a time in UTC timezone', () => {
9
+ const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 567));
10
+ const actual = dateToLocaleISOString(date);
11
+
12
+ expect(actual).toMatchInlineSnapshot(`"2000-01-01T00:12:34.567Z"`);
13
+ });
14
+
15
+ test('formatting a time in UTC timezone with zero milliseconds', () => {
16
+ const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 0));
17
+ const actual = dateToLocaleISOString(date);
18
+
19
+ expect(actual).toMatchInlineSnapshot(`"2000-01-01T00:12:34.000Z"`);
20
+ });
@@ -0,0 +1,10 @@
1
+ export default function once(fn: () => void): () => void {
2
+ let done;
3
+
4
+ return () => {
5
+ if (!done) {
6
+ fn();
7
+ done = 1;
8
+ }
9
+ };
10
+ }
@@ -0,0 +1,3 @@
1
+ export default function singleToArray<T>(singleOrArray: T | T[]): T[] {
2
+ return singleOrArray ? (Array.isArray(singleOrArray) ? singleOrArray : [singleOrArray]) : [];
3
+ }
@@ -0,0 +1,5 @@
1
+ import once from './once';
2
+
3
+ export default function warnOnce(message: string): () => void {
4
+ return once(() => console.warn(`botframework-webchat: ${message}.`));
5
+ }