@carbon/ai-chat 0.1.6 → 0.1.7-test-no-cjs

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 (144) hide show
  1. package/dist/es/{cds-aichat-internal.js → AppContainer.js} +50756 -18310
  2. package/dist/es/Carousel.js +14 -8
  3. package/dist/es/GenesysMessengerServiceDesk.js +17 -11
  4. package/dist/es/HumanAgentServiceImpl.js +17 -12
  5. package/dist/es/NiceDFOServiceDesk.js +17 -12
  6. package/dist/es/PDFViewerContainer.js +15 -108
  7. package/dist/es/ReactPlayer.js +2 -2
  8. package/dist/es/SFServiceDesk.js +18 -11
  9. package/dist/es/ServiceDeskImpl.js +2 -2
  10. package/dist/es/Table.js +429 -315
  11. package/dist/es/ZendeskServiceDesk.js +17 -11
  12. package/dist/es/_node-resolve_empty.js +2 -2
  13. package/dist/es/aiChatEntry.js +137 -120
  14. package/dist/es/ar-dz.js +3 -4
  15. package/dist/es/ar-kw.js +3 -4
  16. package/dist/es/ar-ly.js +3 -4
  17. package/dist/es/ar-ma.js +3 -4
  18. package/dist/es/ar-sa.js +3 -4
  19. package/dist/es/ar-tn.js +3 -4
  20. package/dist/es/ar.js +3 -4
  21. package/dist/es/ar2.js +2 -2
  22. package/dist/es/cds-aichat-container.js +104 -18
  23. package/dist/es/cds-aichat-custom-element.js +31 -21
  24. package/dist/es/cs.js +3 -4
  25. package/dist/es/cs2.js +2 -2
  26. package/dist/es/de-at.js +3 -4
  27. package/dist/es/de-ch.js +3 -4
  28. package/dist/es/de.js +3 -4
  29. package/dist/es/de2.js +2 -2
  30. package/dist/es/en-au.js +3 -4
  31. package/dist/es/en-ca.js +3 -4
  32. package/dist/es/en-gb.js +3 -4
  33. package/dist/es/en-ie.js +3 -4
  34. package/dist/es/en-il.js +3 -4
  35. package/dist/es/en-nz.js +3 -4
  36. package/dist/es/es-do.js +3 -4
  37. package/dist/es/es-us.js +3 -4
  38. package/dist/es/es.js +3 -4
  39. package/dist/es/es2.js +2 -2
  40. package/dist/es/export.js +3 -3
  41. package/dist/es/export.legacy.js +3 -3
  42. package/dist/es/fontUtils.js +2 -2
  43. package/dist/es/fr-ca.js +3 -4
  44. package/dist/es/fr-ch.js +3 -4
  45. package/dist/es/fr.js +3 -4
  46. package/dist/es/fr2.js +2 -2
  47. package/dist/es/it-ch.js +3 -4
  48. package/dist/es/it.js +3 -4
  49. package/dist/es/it2.js +2 -2
  50. package/dist/es/ja.js +3 -4
  51. package/dist/es/ja2.js +2 -2
  52. package/dist/es/ko.js +3 -4
  53. package/dist/es/ko2.js +2 -2
  54. package/dist/es/mockServiceDesk.js +17 -11
  55. package/dist/es/nl.js +3 -4
  56. package/dist/es/nl2.js +2 -2
  57. package/dist/es/pt-br.js +3 -4
  58. package/dist/es/pt-br2.js +2 -2
  59. package/dist/es/pt.js +3 -4
  60. package/dist/es/render.js +25 -12
  61. package/dist/es/zh-cn.js +3 -4
  62. package/dist/es/zh-tw.js +3 -4
  63. package/dist/es/zh-tw2.js +2 -2
  64. package/dist/es/zh.js +2 -2
  65. package/dist/types/aiChatEntry.d.ts +599 -11
  66. package/package.json +29 -21
  67. package/dist/cjs/Carousel.js +0 -5711
  68. package/dist/cjs/Chat.js +0 -8838
  69. package/dist/cjs/GenesysMessengerServiceDesk.js +0 -598
  70. package/dist/cjs/HumanAgentServiceImpl.js +0 -1145
  71. package/dist/cjs/NiceDFOServiceDesk.js +0 -2116
  72. package/dist/cjs/PDFViewerContainer.js +0 -83227
  73. package/dist/cjs/ReactPlayer.js +0 -57
  74. package/dist/cjs/SFServiceDesk.js +0 -1031
  75. package/dist/cjs/ServiceDeskImpl.js +0 -74
  76. package/dist/cjs/Table.js +0 -3146
  77. package/dist/cjs/ZendeskServiceDesk.js +0 -670
  78. package/dist/cjs/_node-resolve_empty.js +0 -27
  79. package/dist/cjs/agentActions.js +0 -214
  80. package/dist/cjs/aiChatEntry.js +0 -354
  81. package/dist/cjs/anonymousUserIDStorage.js +0 -254
  82. package/dist/cjs/ar-dz.js +0 -57
  83. package/dist/cjs/ar-kw.js +0 -57
  84. package/dist/cjs/ar-ly.js +0 -57
  85. package/dist/cjs/ar-ma.js +0 -57
  86. package/dist/cjs/ar-sa.js +0 -57
  87. package/dist/cjs/ar-tn.js +0 -57
  88. package/dist/cjs/ar.js +0 -57
  89. package/dist/cjs/ar2.js +0 -763
  90. package/dist/cjs/cds-aichat-container.js +0 -143
  91. package/dist/cjs/cds-aichat-custom-element.js +0 -200
  92. package/dist/cjs/cds-aichat-internal.js +0 -39150
  93. package/dist/cjs/cs.js +0 -57
  94. package/dist/cjs/cs2.js +0 -763
  95. package/dist/cjs/de-at.js +0 -57
  96. package/dist/cjs/de-ch.js +0 -57
  97. package/dist/cjs/de.js +0 -57
  98. package/dist/cjs/de2.js +0 -763
  99. package/dist/cjs/en-au.js +0 -57
  100. package/dist/cjs/en-ca.js +0 -57
  101. package/dist/cjs/en-gb.js +0 -57
  102. package/dist/cjs/en-ie.js +0 -57
  103. package/dist/cjs/en-il.js +0 -57
  104. package/dist/cjs/en-nz.js +0 -57
  105. package/dist/cjs/es-do.js +0 -57
  106. package/dist/cjs/es-us.js +0 -57
  107. package/dist/cjs/es.js +0 -57
  108. package/dist/cjs/es2.js +0 -763
  109. package/dist/cjs/export.js +0 -27
  110. package/dist/cjs/export.legacy.js +0 -27
  111. package/dist/cjs/fontUtils.js +0 -1038
  112. package/dist/cjs/fr-ca.js +0 -57
  113. package/dist/cjs/fr-ch.js +0 -57
  114. package/dist/cjs/fr.js +0 -57
  115. package/dist/cjs/fr2.js +0 -763
  116. package/dist/cjs/highlight_js.js +0 -15325
  117. package/dist/cjs/it-ch.js +0 -57
  118. package/dist/cjs/it.js +0 -57
  119. package/dist/cjs/it2.js +0 -763
  120. package/dist/cjs/ja.js +0 -57
  121. package/dist/cjs/ja2.js +0 -763
  122. package/dist/cjs/jstz.min.js +0 -43
  123. package/dist/cjs/ko.js +0 -57
  124. package/dist/cjs/ko2.js +0 -763
  125. package/dist/cjs/markdown.js +0 -8505
  126. package/dist/cjs/markdown_attrs.js +0 -805
  127. package/dist/cjs/mockServiceDesk.js +0 -887
  128. package/dist/cjs/nl.js +0 -57
  129. package/dist/cjs/nl2.js +0 -763
  130. package/dist/cjs/pt-br.js +0 -57
  131. package/dist/cjs/pt-br2.js +0 -763
  132. package/dist/cjs/pt.js +0 -57
  133. package/dist/cjs/render.js +0 -94
  134. package/dist/cjs/zh-cn.js +0 -57
  135. package/dist/cjs/zh-tw.js +0 -57
  136. package/dist/cjs/zh-tw2.js +0 -763
  137. package/dist/cjs/zh.js +0 -763
  138. package/dist/es/Chat.js +0 -8836
  139. package/dist/es/agentActions.js +0 -186
  140. package/dist/es/anonymousUserIDStorage.js +0 -249
  141. package/dist/es/highlight_js.js +0 -15320
  142. package/dist/es/jstz.min.js +0 -41
  143. package/dist/es/markdown.js +0 -8501
  144. package/dist/es/markdown_attrs.js +0 -803
@@ -1,186 +0,0 @@
1
- /*
2
-
3
-
4
- (C) Copyright IBM Corp. 2017, 2025. All Rights Reserved.
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
- in compliance with the License. You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software distributed under the License
12
- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
- or implied. See the License for the specific language governing permissions and limitations under
14
- the License.
15
-
16
- @carbon/ai-chat 0.1.6
17
-
18
- Built: Feb 3 2025 9:58 am -05:00
19
-
20
-
21
-
22
- */
23
- import { i as MessageResponseTypes, ac as uuid, ad as UUIDType } from './cds-aichat-internal.js';
24
-
25
- /**
26
- *
27
- * IBM Confidential
28
- *
29
- * (C) Copyright IBM Corp. 2020, 2023
30
- *
31
- * The source code for this program is not published or otherwise
32
- * divested of its trade secrets, irrespective of what has been
33
- * deposited with the U. S. Copyright Office
34
- *
35
- * US Government Users Restricted Rights - Use, duplication or
36
- * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
37
- *
38
- */
39
- /**
40
- * Takes data from the v2 message API and transforms into something usable by WAC.
41
- *
42
- * @param message Takes an object in the shape of a v2 message API Send object. With an additional `ui_state`
43
- * object for local state.
44
- * @param originalUserText The original text provided by the user before it was potentially modified on the
45
- * underlying {@link MessageRequest}. This value may be null if there is no text from the user to display.
46
- * instance.
47
- * @param id If you have already generated an id, it's ok to pass it in. If not, one will be generated.
48
- */
49
- function inputItemToLocalItem(message, originalUserText, id = uuid(UUIDType.LOCAL_MESSAGE)) {
50
- const localMessage = {
51
- // The individual message in the format of an item from output.generic in the docs above.
52
- item: {
53
- response_type: MessageResponseTypes.TEXT,
54
- ...message.input,
55
- },
56
- // ui_state is for rendering concerns and is not persistent.
57
- ui_state: {
58
- id,
59
- originalUserText,
60
- needsAnnouncement: false, // We don't announce text that came from the user.
61
- },
62
- fullMessageID: message.id,
63
- };
64
- return localMessage;
65
- }
66
-
67
- /**
68
- *
69
- * IBM Confidential
70
- *
71
- * (C) Copyright IBM Corp. 2019, 2023
72
- *
73
- * The source code for this program is not published or otherwise
74
- * divested of its trade secrets, irrespective of what has been
75
- * deposited with the U. S. Copyright Office
76
- *
77
- * US Government Users Restricted Rights - Use, duplication or
78
- * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
79
- *
80
- */
81
- /**
82
- * Redux action creators for human agent actions.
83
- */
84
- const HA_SET_AGENT_AVAILABILITY = 'HA_SET_AGENT_AVAILABILITY';
85
- const HA_SET_IS_CONNECTING = 'HA_SET_IS_CONNECTING';
86
- const HA_SET_IS_RECONNECTING = 'HA_SET_IS_RECONNECTING';
87
- const HA_SET_AGENT_JOINED = 'HA_SET_AGENT_JOINED';
88
- const HA_SET_AGENT_LEFT_CHAT = 'HA_SET_AGENT_LEFT_CHAT';
89
- const HA_END_CHAT = 'HA_END_CHAT';
90
- const HA_UPDATE_CAPABILITIES = 'HA_UPDATE_CAPABILITIES';
91
- const HA_UPDATE_FILE_UPLOAD_IN_PROGRESS = 'HA_UPDATE_FILE_UPLOAD_IN_PROGRESS';
92
- const HA_SET_SHOW_SCREEN_SHARE_REQUEST = 'HA_SET_SHOW_SCREEN_SHARE_REQUEST';
93
- const HA_SET_IS_SCREEN_SHARING = 'HA_SET_IS_SCREEN_SHARING';
94
- const HA_SET_PERSISTED_STATE = 'HA_SET_PERSISTED_STATE';
95
- const HA_UPDATE_IS_SUSPENDED = 'HA_UPDATE_IS_SUSPENDED';
96
- const HA_UPDATE_IS_TYPING = 'HA_UPDATE_IS_TYPING';
97
- /**
98
- * Sets the "is connecting" status for a human agent.
99
- */
100
- function setIsConnecting(isConnecting, localMessageID) {
101
- return {
102
- type: HA_SET_IS_CONNECTING,
103
- isConnecting,
104
- localMessageID,
105
- };
106
- }
107
- /**
108
- * Sets the "is reconnecting" status for a human agent.
109
- */
110
- function setIsReconnecting(isReconnecting) {
111
- return { type: HA_SET_IS_RECONNECTING, isReconnecting };
112
- }
113
- /**
114
- * Indicate agent has left chat.
115
- */
116
- function setAgentLeftChat() {
117
- return { type: HA_SET_AGENT_LEFT_CHAT };
118
- }
119
- /**
120
- * Ends the current chat.
121
- */
122
- function endChat() {
123
- return { type: HA_END_CHAT };
124
- }
125
- /**
126
- * Sets the availability information for a user who is waiting to be connected to an agent.
127
- */
128
- function setAgentAvailability(availability) {
129
- return {
130
- type: HA_SET_AGENT_AVAILABILITY,
131
- availability,
132
- };
133
- }
134
- /**
135
- * Sets the availability information for a user who is waiting to be connected to an agent.
136
- */
137
- function setAgentJoined(agentProfile) {
138
- return {
139
- type: HA_SET_AGENT_JOINED,
140
- agentProfile,
141
- };
142
- }
143
- /**
144
- * Updates web chat with the capabilities supported by the service desk.
145
- */
146
- function updateCapabilities(capabilities) {
147
- return { type: HA_UPDATE_CAPABILITIES, capabilities };
148
- }
149
- /**
150
- * Updates the indicator for if any files are being uploaded.
151
- */
152
- function updateFilesUploadInProgress(fileUploadInProgress) {
153
- return { type: HA_UPDATE_FILE_UPLOAD_IN_PROGRESS, fileUploadInProgress };
154
- }
155
- /**
156
- * Sets the state of the screen sharing modal.
157
- */
158
- function setShowScreenShareRequest(showRequest) {
159
- return { type: HA_SET_SHOW_SCREEN_SHARE_REQUEST, showRequest };
160
- }
161
- /**
162
- * Sets the state of screen sharing.
163
- */
164
- function setIsScreenSharing(isSharing) {
165
- return { type: HA_SET_IS_SCREEN_SHARING, isSharing };
166
- }
167
- /**
168
- * Updates the object that is stored containing state for the service desk.
169
- */
170
- function setPersistedServiceDeskState(state) {
171
- return { type: HA_SET_PERSISTED_STATE, state };
172
- }
173
- /**
174
- * Updates the suspended status for the current service desk.
175
- */
176
- function agentUpdateIsSuspended(isSuspended) {
177
- return { type: HA_UPDATE_IS_SUSPENDED, isSuspended };
178
- }
179
- /**
180
- * Updates the suspended status for the current service desk.
181
- */
182
- function agentUpdateIsTyping(isTyping) {
183
- return { type: HA_UPDATE_IS_TYPING, isTyping };
184
- }
185
-
186
- export { HA_SET_IS_CONNECTING as H, agentUpdateIsSuspended as a, HA_SET_IS_RECONNECTING as b, HA_SET_AGENT_AVAILABILITY as c, HA_SET_SHOW_SCREEN_SHARE_REQUEST as d, HA_SET_AGENT_JOINED as e, HA_SET_PERSISTED_STATE as f, HA_UPDATE_IS_SUSPENDED as g, HA_UPDATE_IS_TYPING as h, inputItemToLocalItem as i, HA_SET_AGENT_LEFT_CHAT as j, HA_UPDATE_CAPABILITIES as k, HA_SET_IS_SCREEN_SHARING as l, HA_UPDATE_FILE_UPLOAD_IN_PROGRESS as m, HA_END_CHAT as n, endChat as o, setIsScreenSharing as p, setIsReconnecting as q, setShowScreenShareRequest as r, setIsConnecting as s, updateCapabilities as t, updateFilesUploadInProgress as u, setAgentAvailability as v, setAgentJoined as w, agentUpdateIsTyping as x, setAgentLeftChat as y, setPersistedServiceDeskState as z };
@@ -1,249 +0,0 @@
1
- /*
2
-
3
-
4
- (C) Copyright IBM Corp. 2017, 2025. All Rights Reserved.
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
- in compliance with the License. You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software distributed under the License
12
- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
- or implied. See the License for the specific language governing permissions and limitations under
14
- the License.
15
-
16
- @carbon/ai-chat 0.1.6
17
-
18
- Built: Feb 3 2025 9:58 am -05:00
19
-
20
-
21
-
22
- */
23
- import { bE as IS_SESSION_STORAGE, e7 as isSecureHost, ac as uuid, ad as UUIDType } from './cds-aichat-internal.js';
24
-
25
- /*! js-cookie v3.0.5 | MIT */
26
- /* eslint-disable no-var */
27
- function assign (target) {
28
- for (var i = 1; i < arguments.length; i++) {
29
- var source = arguments[i];
30
- for (var key in source) {
31
- target[key] = source[key];
32
- }
33
- }
34
- return target
35
- }
36
- /* eslint-enable no-var */
37
-
38
- /* eslint-disable no-var */
39
- var defaultConverter = {
40
- read: function (value) {
41
- if (value[0] === '"') {
42
- value = value.slice(1, -1);
43
- }
44
- return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
45
- },
46
- write: function (value) {
47
- return encodeURIComponent(value).replace(
48
- /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
49
- decodeURIComponent
50
- )
51
- }
52
- };
53
- /* eslint-enable no-var */
54
-
55
- /* eslint-disable no-var */
56
-
57
- function init (converter, defaultAttributes) {
58
- function set (name, value, attributes) {
59
- if (typeof document === 'undefined') {
60
- return
61
- }
62
-
63
- attributes = assign({}, defaultAttributes, attributes);
64
-
65
- if (typeof attributes.expires === 'number') {
66
- attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
67
- }
68
- if (attributes.expires) {
69
- attributes.expires = attributes.expires.toUTCString();
70
- }
71
-
72
- name = encodeURIComponent(name)
73
- .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
74
- .replace(/[()]/g, escape);
75
-
76
- var stringifiedAttributes = '';
77
- for (var attributeName in attributes) {
78
- if (!attributes[attributeName]) {
79
- continue
80
- }
81
-
82
- stringifiedAttributes += '; ' + attributeName;
83
-
84
- if (attributes[attributeName] === true) {
85
- continue
86
- }
87
-
88
- // Considers RFC 6265 section 5.2:
89
- // ...
90
- // 3. If the remaining unparsed-attributes contains a %x3B (";")
91
- // character:
92
- // Consume the characters of the unparsed-attributes up to,
93
- // not including, the first %x3B (";") character.
94
- // ...
95
- stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
96
- }
97
-
98
- return (document.cookie =
99
- name + '=' + converter.write(value, name) + stringifiedAttributes)
100
- }
101
-
102
- function get (name) {
103
- if (typeof document === 'undefined' || (arguments.length && !name)) {
104
- return
105
- }
106
-
107
- // To prevent the for loop in the first place assign an empty array
108
- // in case there are no cookies at all.
109
- var cookies = document.cookie ? document.cookie.split('; ') : [];
110
- var jar = {};
111
- for (var i = 0; i < cookies.length; i++) {
112
- var parts = cookies[i].split('=');
113
- var value = parts.slice(1).join('=');
114
-
115
- try {
116
- var found = decodeURIComponent(parts[0]);
117
- jar[found] = converter.read(value, found);
118
-
119
- if (name === found) {
120
- break
121
- }
122
- } catch (e) {}
123
- }
124
-
125
- return name ? jar[name] : jar
126
- }
127
-
128
- return Object.create(
129
- {
130
- set,
131
- get,
132
- remove: function (name, attributes) {
133
- set(
134
- name,
135
- '',
136
- assign({}, attributes, {
137
- expires: -1
138
- })
139
- );
140
- },
141
- withAttributes: function (attributes) {
142
- return init(this.converter, assign({}, this.attributes, attributes))
143
- },
144
- withConverter: function (converter) {
145
- return init(assign({}, this.converter, converter), this.attributes)
146
- }
147
- },
148
- {
149
- attributes: { value: Object.freeze(defaultAttributes) },
150
- converter: { value: Object.freeze(converter) }
151
- }
152
- )
153
- }
154
-
155
- var api = init(defaultConverter, { path: '/' });
156
-
157
- /**
158
- *
159
- * IBM Confidential
160
- *
161
- * (C) Copyright IBM Corp. 2019, 2023
162
- *
163
- * The source code for this program is not published or otherwise
164
- * divested of its trade secrets, irrespective of what has been
165
- * deposited with the U. S. Copyright Office
166
- *
167
- * US Government Users Restricted Rights - Use, duplication or
168
- * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
169
- *
170
- */
171
- /**
172
- * This module is responsible for managing the storage of anonymousUserId. We use an anonymousUserId if the userId is
173
- * not set in order to not repeat bill unique users that are anonymous. The id is stored (preferentially) as a 1st
174
- * party cookie that expires in 45 days. The expiration date is so we don't leave data sitting in the user's browser
175
- * for a long period of time per IBM policy. The period of 45 days is chosen so that the cookie does not expire
176
- * within a given month of so which would result in the user being detected as a new user and thus causing the
177
- * client to be billed for an additional user. The number should be between 32 days (the minimum to cover a whole month)
178
- * and 365 days (the maximum allowed by IBM policy).
179
- */
180
- // The length of cookie the anonymous userID cookie should live in days. This may be fractions of days if needed.
181
- const COOKIE_DURATION = 45; // Days
182
- // The prefix attached to all anonymous user ids.
183
- const ANONYMOUS_USER_ID_PREFIX = 'anonymous_IBMuid-';
184
- // The key in browser storage that contains the session id for a particular user.
185
- const ANONYMOUS_USER_ID_KEY = 'IBM_WAC_ANONYMOUS_USER_ID';
186
- /**
187
- * Returns the anonymousUserId as recorded in local storage. If there is no defined anonymousUserId, this
188
- * will return undefined.
189
- */
190
- function getAnonymousUserID(useCookie) {
191
- // Return the value of the cookie, looking in session storage first as that's our fallback if cookies aren't
192
- // available.
193
- let userID;
194
- if (IS_SESSION_STORAGE()) {
195
- if (useCookie) {
196
- userID = window.sessionStorage.getItem(ANONYMOUS_USER_ID_KEY) || api.get(ANONYMOUS_USER_ID_KEY);
197
- }
198
- else {
199
- userID = window.sessionStorage.getItem(ANONYMOUS_USER_ID_KEY);
200
- }
201
- }
202
- else if (useCookie) {
203
- userID = api.get(ANONYMOUS_USER_ID_KEY);
204
- }
205
- // If there is an ID, we need to do a "set" again which will update the expiration date on the cookie.
206
- if (userID) {
207
- setAnonymousUserId(userID, useCookie);
208
- }
209
- return userID || null;
210
- }
211
- /**
212
- * Sets the anonymousUserId in local storage.
213
- */
214
- function setAnonymousUserId(anonymousUserId, useCookie) {
215
- if (useCookie) {
216
- api.set(ANONYMOUS_USER_ID_KEY, anonymousUserId, {
217
- expires: COOKIE_DURATION,
218
- sameSite: 'lax',
219
- secure: isSecureHost(),
220
- });
221
- }
222
- if ((!useCookie || !api.get(ANONYMOUS_USER_ID_KEY)) && IS_SESSION_STORAGE()) {
223
- // If the cookie failed to get set, it means we're in a higher security level and we need to attempt to use
224
- // session storage instead. If tracking is disabled, browsers may disable localStorage and cookies, but still allow
225
- // session storage. Falling back to session storage at least allows us to not bill each page view as an
226
- // individual user! https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Privacy/Storage_access_policy
227
- window.sessionStorage.setItem(ANONYMOUS_USER_ID_KEY, anonymousUserId);
228
- }
229
- }
230
- /**
231
- * Generated a new anonymousUserId (MUST start with anonymous_ to be handled correctly downstream).
232
- */
233
- function generateAndSetAnonymousUserId(useCookie) {
234
- const anonymousUserId = `${ANONYMOUS_USER_ID_PREFIX}${uuid(UUIDType.USER)}`;
235
- setAnonymousUserId(anonymousUserId, useCookie);
236
- return anonymousUserId;
237
- }
238
- /**
239
- * Clear the anonymousUserId from localStorage. Called when a real userId is set.
240
- *
241
- */
242
- function clearAnonymousUserId() {
243
- api.remove(ANONYMOUS_USER_ID_KEY);
244
- if (IS_SESSION_STORAGE()) {
245
- window.sessionStorage.removeItem(ANONYMOUS_USER_ID_KEY);
246
- }
247
- }
248
-
249
- export { ANONYMOUS_USER_ID_PREFIX as A, generateAndSetAnonymousUserId as a, clearAnonymousUserId as c, getAnonymousUserID as g };