@thoughtspot/visual-embed-sdk 1.36.3 → 1.36.4
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/cjs/package.json +1 -1
- package/cjs/src/embed/app.d.ts.map +1 -1
- package/cjs/src/embed/app.js +1 -1
- package/cjs/src/embed/app.js.map +1 -1
- package/cjs/src/embed/base.d.ts +4 -0
- package/cjs/src/embed/base.d.ts.map +1 -1
- package/cjs/src/embed/base.js +27 -1
- package/cjs/src/embed/base.js.map +1 -1
- package/cjs/src/embed/bodyless-conversation.d.ts.map +1 -1
- package/cjs/src/embed/bodyless-conversation.js +1 -1
- package/cjs/src/embed/bodyless-conversation.js.map +1 -1
- package/cjs/src/embed/conversation.d.ts.map +1 -1
- package/cjs/src/embed/conversation.js +1 -1
- package/cjs/src/embed/conversation.js.map +1 -1
- package/cjs/src/embed/embedConfig.d.ts.map +1 -1
- package/cjs/src/embed/embedConfig.js.map +1 -1
- package/cjs/src/embed/liveboard.d.ts +2 -2
- package/cjs/src/embed/liveboard.d.ts.map +1 -1
- package/cjs/src/embed/liveboard.js +4 -5
- package/cjs/src/embed/liveboard.js.map +1 -1
- package/cjs/src/embed/liveboard.spec.js +11 -11
- package/cjs/src/embed/liveboard.spec.js.map +1 -1
- package/cjs/src/embed/sage.d.ts.map +1 -1
- package/cjs/src/embed/sage.js +1 -1
- package/cjs/src/embed/sage.js.map +1 -1
- package/cjs/src/embed/search-bar.d.ts.map +1 -1
- package/cjs/src/embed/search-bar.js +1 -1
- package/cjs/src/embed/search-bar.js.map +1 -1
- package/cjs/src/embed/search.d.ts.map +1 -1
- package/cjs/src/embed/search.js +1 -1
- package/cjs/src/embed/search.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts +4 -3
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +25 -16
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +71 -5
- package/cjs/src/embed/ts-embed.spec.js.map +1 -1
- package/cjs/src/errors.d.ts +1 -0
- package/cjs/src/errors.d.ts.map +1 -1
- package/cjs/src/errors.js +1 -0
- package/cjs/src/errors.js.map +1 -1
- package/cjs/src/react/all-types-export.d.ts +1 -1
- package/cjs/src/react/all-types-export.d.ts.map +1 -1
- package/cjs/src/react/all-types-export.js +2 -1
- package/cjs/src/react/all-types-export.js.map +1 -1
- package/cjs/src/react/index.d.ts +16 -0
- package/cjs/src/react/index.d.ts.map +1 -1
- package/cjs/src/react/index.js +25 -2
- package/cjs/src/react/index.js.map +1 -1
- package/cjs/src/utils/with-resolvers-polyfill.d.ts +1 -0
- package/cjs/src/utils/with-resolvers-polyfill.d.ts.map +1 -0
- package/cjs/src/utils/with-resolvers-polyfill.js +12 -0
- package/cjs/src/utils/with-resolvers-polyfill.js.map +1 -0
- package/cjs/src/utils.d.ts +17 -2
- package/cjs/src/utils.d.ts.map +1 -1
- package/cjs/src/utils.js +27 -3
- package/cjs/src/utils.js.map +1 -1
- package/dist/{index-BJx3m5_V.js → index-NZYq1Tu3.js} +1 -1
- package/dist/src/embed/app.d.ts.map +1 -1
- package/dist/src/embed/base.d.ts +4 -0
- package/dist/src/embed/base.d.ts.map +1 -1
- package/dist/src/embed/bodyless-conversation.d.ts.map +1 -1
- package/dist/src/embed/conversation.d.ts.map +1 -1
- package/dist/src/embed/embedConfig.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts +2 -2
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/embed/sage.d.ts.map +1 -1
- package/dist/src/embed/search-bar.d.ts.map +1 -1
- package/dist/src/embed/search.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +4 -3
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/dist/src/errors.d.ts +1 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/react/all-types-export.d.ts +1 -1
- package/dist/src/react/all-types-export.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +16 -0
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/utils/with-resolvers-polyfill.d.ts +1 -0
- package/dist/src/utils/with-resolvers-polyfill.d.ts.map +1 -0
- package/dist/src/utils.d.ts +17 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/tsembed-react.es.js +349 -45
- package/dist/tsembed-react.js +347 -42
- package/dist/tsembed.es.js +85 -32
- package/dist/tsembed.js +84 -31
- package/dist/visual-embed-sdk-react-full.d.ts +1233 -1214
- package/dist/visual-embed-sdk-react.d.ts +668 -649
- package/dist/visual-embed-sdk.d.ts +9 -4
- package/lib/package.json +1 -1
- package/lib/src/embed/app.d.ts.map +1 -1
- package/lib/src/embed/app.js +1 -1
- package/lib/src/embed/app.js.map +1 -1
- package/lib/src/embed/base.d.ts +4 -0
- package/lib/src/embed/base.d.ts.map +1 -1
- package/lib/src/embed/base.js +24 -1
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/bodyless-conversation.d.ts.map +1 -1
- package/lib/src/embed/bodyless-conversation.js +1 -1
- package/lib/src/embed/bodyless-conversation.js.map +1 -1
- package/lib/src/embed/conversation.d.ts.map +1 -1
- package/lib/src/embed/conversation.js +1 -1
- package/lib/src/embed/conversation.js.map +1 -1
- package/lib/src/embed/embedConfig.d.ts.map +1 -1
- package/lib/src/embed/embedConfig.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts +2 -2
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +4 -5
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +11 -11
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/sage.d.ts.map +1 -1
- package/lib/src/embed/sage.js +1 -1
- package/lib/src/embed/sage.js.map +1 -1
- package/lib/src/embed/search-bar.d.ts.map +1 -1
- package/lib/src/embed/search-bar.js +1 -1
- package/lib/src/embed/search-bar.js.map +1 -1
- package/lib/src/embed/search.d.ts.map +1 -1
- package/lib/src/embed/search.js +1 -1
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +4 -3
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +26 -17
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +71 -5
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/errors.d.ts +1 -0
- package/lib/src/errors.d.ts.map +1 -1
- package/lib/src/errors.js +1 -0
- package/lib/src/errors.js.map +1 -1
- package/lib/src/react/all-types-export.d.ts +1 -1
- package/lib/src/react/all-types-export.d.ts.map +1 -1
- package/lib/src/react/all-types-export.js +1 -1
- package/lib/src/react/all-types-export.js.map +1 -1
- package/lib/src/react/index.d.ts +16 -0
- package/lib/src/react/index.d.ts.map +1 -1
- package/lib/src/react/index.js +23 -1
- package/lib/src/react/index.js.map +1 -1
- package/lib/src/utils/with-resolvers-polyfill.d.ts +1 -0
- package/lib/src/utils/with-resolvers-polyfill.d.ts.map +1 -0
- package/lib/src/utils/with-resolvers-polyfill.js +12 -0
- package/lib/src/utils/with-resolvers-polyfill.js.map +1 -0
- package/lib/src/utils.d.ts +17 -2
- package/lib/src/utils.d.ts.map +1 -1
- package/lib/src/utils.js +25 -2
- package/lib/src/utils.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +10 -5
- package/package.json +1 -1
- package/src/embed/app.ts +2 -1
- package/src/embed/base.ts +41 -1
- package/src/embed/bodyless-conversation.ts +2 -1
- package/src/embed/conversation.ts +2 -1
- package/src/embed/embedConfig.ts +1 -1
- package/src/embed/liveboard.spec.ts +11 -11
- package/src/embed/liveboard.ts +5 -6
- package/src/embed/sage.ts +1 -2
- package/src/embed/search-bar.tsx +1 -2
- package/src/embed/search.ts +1 -2
- package/src/embed/ts-embed.spec.ts +83 -5
- package/src/embed/ts-embed.ts +33 -17
- package/src/errors.ts +1 -0
- package/src/react/all-types-export.ts +1 -0
- package/src/react/index.tsx +27 -2
- package/src/utils/with-resolvers-polyfill.ts +11 -0
- package/src/utils.ts +35 -4
package/src/embed/ts-embed.ts
CHANGED
|
@@ -66,6 +66,8 @@ import { processTrigger } from '../utils/processTrigger';
|
|
|
66
66
|
import pkgInfo from '../../package.json';
|
|
67
67
|
import {
|
|
68
68
|
getAuthPromise, renderInQueue, handleAuth, notifyAuthFailure,
|
|
69
|
+
getInitPromise,
|
|
70
|
+
getIsInitCalled,
|
|
69
71
|
} from './base';
|
|
70
72
|
import { AuthFailureType } from '../auth';
|
|
71
73
|
import { getEmbedConfig } from './embedConfig';
|
|
@@ -180,15 +182,10 @@ export class TsEmbed {
|
|
|
180
182
|
|
|
181
183
|
protected hostEventClient: HostEventClient;
|
|
182
184
|
|
|
185
|
+
protected isReadyForRenderPromise;
|
|
186
|
+
|
|
183
187
|
constructor(domSelector: DOMSelector, viewConfig?: ViewConfig) {
|
|
184
188
|
this.el = getDOMNode(domSelector);
|
|
185
|
-
// TODO: handle error
|
|
186
|
-
this.embedConfig = getEmbedConfig();
|
|
187
|
-
if (!this.embedConfig.authTriggerContainer && !this.embedConfig.useEventForSAMLPopup) {
|
|
188
|
-
this.embedConfig.authTriggerContainer = domSelector;
|
|
189
|
-
}
|
|
190
|
-
this.thoughtSpotHost = getThoughtSpotHost(this.embedConfig);
|
|
191
|
-
this.thoughtSpotV2Base = getV2BasePath(this.embedConfig);
|
|
192
189
|
this.eventHandlerMap = new Map();
|
|
193
190
|
this.isError = false;
|
|
194
191
|
this.viewConfig = {
|
|
@@ -196,12 +193,22 @@ export class TsEmbed {
|
|
|
196
193
|
excludeRuntimeParametersfromURL: false,
|
|
197
194
|
...viewConfig,
|
|
198
195
|
};
|
|
199
|
-
this.shouldEncodeUrlQueryParams = this.embedConfig.shouldEncodeUrlQueryParams;
|
|
200
196
|
this.registerAppInit();
|
|
201
197
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_EMBED_CREATE, {
|
|
202
198
|
...viewConfig,
|
|
203
199
|
});
|
|
204
200
|
this.hostEventClient = new HostEventClient(this.iFrame);
|
|
201
|
+
|
|
202
|
+
this.isReadyForRenderPromise = getInitPromise().then(async () => {
|
|
203
|
+
const embedConfig = getEmbedConfig();
|
|
204
|
+
this.embedConfig = embedConfig;
|
|
205
|
+
if (!embedConfig.authTriggerContainer && !embedConfig.useEventForSAMLPopup) {
|
|
206
|
+
this.embedConfig.authTriggerContainer = domSelector;
|
|
207
|
+
}
|
|
208
|
+
this.thoughtSpotHost = getThoughtSpotHost(embedConfig);
|
|
209
|
+
this.thoughtSpotV2Base = getV2BasePath(embedConfig);
|
|
210
|
+
this.shouldEncodeUrlQueryParams = embedConfig.shouldEncodeUrlQueryParams;
|
|
211
|
+
});
|
|
205
212
|
}
|
|
206
213
|
|
|
207
214
|
/**
|
|
@@ -723,6 +730,7 @@ export class TsEmbed {
|
|
|
723
730
|
});
|
|
724
731
|
|
|
725
732
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_START);
|
|
733
|
+
|
|
726
734
|
return getAuthPromise()
|
|
727
735
|
?.then((isLoggedIn: boolean) => {
|
|
728
736
|
if (!isLoggedIn) {
|
|
@@ -1119,8 +1127,11 @@ export class TsEmbed {
|
|
|
1119
1127
|
* @param args
|
|
1120
1128
|
*/
|
|
1121
1129
|
public async render(): Promise<TsEmbed> {
|
|
1130
|
+
if (!getIsInitCalled()) {
|
|
1131
|
+
logger.error(ERROR_MESSAGE.RENDER_CALLED_BEFORE_INIT);
|
|
1132
|
+
}
|
|
1133
|
+
await this.isReadyForRenderPromise;
|
|
1122
1134
|
this.isRendered = true;
|
|
1123
|
-
|
|
1124
1135
|
return this;
|
|
1125
1136
|
}
|
|
1126
1137
|
|
|
@@ -1129,22 +1140,21 @@ export class TsEmbed {
|
|
|
1129
1140
|
}
|
|
1130
1141
|
|
|
1131
1142
|
protected handleRenderForPrerender() {
|
|
1132
|
-
this.render();
|
|
1143
|
+
return this.render();
|
|
1133
1144
|
}
|
|
1134
1145
|
|
|
1135
1146
|
/**
|
|
1136
1147
|
* Creates the preRender shell
|
|
1137
1148
|
* @param showPreRenderByDefault - Show the preRender after render, hidden by default
|
|
1138
1149
|
*/
|
|
1139
|
-
public preRender(showPreRenderByDefault = false): TsEmbed {
|
|
1150
|
+
public async preRender(showPreRenderByDefault = false): Promise<TsEmbed> {
|
|
1140
1151
|
if (!this.viewConfig.preRenderId) {
|
|
1141
1152
|
logger.error(ERROR_MESSAGE.PRERENDER_ID_MISSING);
|
|
1142
1153
|
return this;
|
|
1143
1154
|
}
|
|
1144
1155
|
this.isPreRendered = true;
|
|
1145
1156
|
this.showPreRenderByDefault = showPreRenderByDefault;
|
|
1146
|
-
this.handleRenderForPrerender();
|
|
1147
|
-
return this;
|
|
1157
|
+
return this.handleRenderForPrerender();
|
|
1148
1158
|
}
|
|
1149
1159
|
|
|
1150
1160
|
/**
|
|
@@ -1204,6 +1214,11 @@ export class TsEmbed {
|
|
|
1204
1214
|
* @returns
|
|
1205
1215
|
*/
|
|
1206
1216
|
public async prerenderGeneric(): Promise<any> {
|
|
1217
|
+
if (!getIsInitCalled()) {
|
|
1218
|
+
logger.error(ERROR_MESSAGE.RENDER_CALLED_BEFORE_INIT);
|
|
1219
|
+
}
|
|
1220
|
+
await this.isReadyForRenderPromise;
|
|
1221
|
+
|
|
1207
1222
|
const prerenderFrameSrc = this.getRootIframeSrc();
|
|
1208
1223
|
this.isRendered = true;
|
|
1209
1224
|
return this.renderIFrame(prerenderFrameSrc);
|
|
@@ -1246,18 +1261,17 @@ export class TsEmbed {
|
|
|
1246
1261
|
* Also, synchronizes the style of the PreRender component with the embedding
|
|
1247
1262
|
* element.
|
|
1248
1263
|
*/
|
|
1249
|
-
public showPreRender():
|
|
1264
|
+
public async showPreRender(): Promise<TsEmbed> {
|
|
1250
1265
|
if (!this.viewConfig.preRenderId) {
|
|
1251
1266
|
logger.error(ERROR_MESSAGE.PRERENDER_ID_MISSING);
|
|
1252
|
-
return;
|
|
1267
|
+
return this;
|
|
1253
1268
|
}
|
|
1254
1269
|
if (!this.isPreRenderAvailable()) {
|
|
1255
1270
|
const isAvailable = this.connectPreRendered();
|
|
1256
1271
|
|
|
1257
1272
|
if (!isAvailable) {
|
|
1258
1273
|
// if the Embed component is not preRendered , Render it now and
|
|
1259
|
-
this.preRender(true);
|
|
1260
|
-
return;
|
|
1274
|
+
return this.preRender(true);
|
|
1261
1275
|
}
|
|
1262
1276
|
this.validatePreRenderViewConfig(this.viewConfig);
|
|
1263
1277
|
}
|
|
@@ -1284,6 +1298,8 @@ export class TsEmbed {
|
|
|
1284
1298
|
removeStyleProperties(this.preRenderWrapper, ['z-index', 'opacity', 'pointer-events']);
|
|
1285
1299
|
|
|
1286
1300
|
this.subscribeToEvents();
|
|
1301
|
+
|
|
1302
|
+
return this;
|
|
1287
1303
|
}
|
|
1288
1304
|
|
|
1289
1305
|
/**
|
package/src/errors.ts
CHANGED
|
@@ -16,4 +16,5 @@ export const ERROR_MESSAGE = {
|
|
|
16
16
|
CSP_VIOLATION_ALERT: 'CSP violation detected. Please check the console errors for more details.',
|
|
17
17
|
CSP_FRAME_HOST_VIOLATION_LOG_MESSAGE: 'Please set up CSP correctly for the application to start working. For more information, see https://developers.thoughtspot.com/docs/security-settings#csp-viz-embed-hosts. \n If the issue persists, refer to https://developers.thoughtspot.com/docs/security-settings#csp-viz-embed-hosts',
|
|
18
18
|
MISSING_REPORTING_OBSERVER: 'ReportingObserver not supported',
|
|
19
|
+
RENDER_CALLED_BEFORE_INIT: 'Looks like render was called before calling init, the render won\'t start until init is called.\nFor more info check\n1. https://developers.thoughtspot.com/docs/Function_init#_init\n2.https://developers.thoughtspot.com/docs/getting-started#initSdk',
|
|
19
20
|
};
|
package/src/react/index.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
2
|
import useDeepCompareEffect from 'use-deep-compare-effect';
|
|
3
|
+
import { AuthEventEmitter } from '../auth';
|
|
3
4
|
import { deepMerge } from '../utils';
|
|
4
5
|
import { SearchBarEmbed as _SearchBarEmbed, SearchBarViewConfig } from '../embed/search-bar';
|
|
5
6
|
import { SageEmbed as _SageEmbed, SageViewConfig } from '../embed/sage';
|
|
@@ -8,9 +9,10 @@ import { AppEmbed as _AppEmbed, AppViewConfig } from '../embed/app';
|
|
|
8
9
|
import { LiveboardEmbed as _LiveboardEmbed, LiveboardViewConfig } from '../embed/liveboard';
|
|
9
10
|
import { TsEmbed } from '../embed/ts-embed';
|
|
10
11
|
|
|
11
|
-
import { EmbedEvent, ViewConfig } from '../types';
|
|
12
|
+
import { EmbedConfig, EmbedEvent, ViewConfig } from '../types';
|
|
12
13
|
import { EmbedProps, getViewPropsAndListeners } from './util';
|
|
13
14
|
import { ConversationEmbed as _ConversationEmbed, ConversationViewConfig } from '../embed/conversation';
|
|
15
|
+
import { init } from '../embed/base';
|
|
14
16
|
|
|
15
17
|
const componentFactory = <T extends typeof TsEmbed, U extends EmbedProps, V extends ViewConfig>(
|
|
16
18
|
EmbedConstructor: T,
|
|
@@ -404,6 +406,29 @@ export function useEmbedRef<T extends EmbedComponent>():
|
|
|
404
406
|
return React.useRef<React.ComponentRef<T>>(null);
|
|
405
407
|
}
|
|
406
408
|
|
|
409
|
+
/**
|
|
410
|
+
*
|
|
411
|
+
* @param config - EmbedConfig
|
|
412
|
+
* @returns AuthEventEmitter
|
|
413
|
+
* @example
|
|
414
|
+
* ```
|
|
415
|
+
* function Component() {
|
|
416
|
+
* const authEE = useInit({ ...initConfig });
|
|
417
|
+
* return <LiveboardEmbed ref={ref} liveboardId={<id>} />
|
|
418
|
+
* }
|
|
419
|
+
* ```
|
|
420
|
+
* @version SDK: 1.36.2 | ThoughtSpot: *
|
|
421
|
+
*/
|
|
422
|
+
export function useInit(config: EmbedConfig) {
|
|
423
|
+
const ref = useRef<AuthEventEmitter | null>(null);
|
|
424
|
+
useDeepCompareEffect(() => {
|
|
425
|
+
const authEE = init(config);
|
|
426
|
+
ref.current = authEE;
|
|
427
|
+
}, [config]);
|
|
428
|
+
|
|
429
|
+
return ref;
|
|
430
|
+
}
|
|
431
|
+
|
|
407
432
|
export {
|
|
408
433
|
LiveboardViewConfig,
|
|
409
434
|
SearchViewConfig,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
if (typeof (Promise as any).withResolvers === 'undefined') {
|
|
2
|
+
(Promise as any).withResolvers = () => {
|
|
3
|
+
let resolve;
|
|
4
|
+
let reject;
|
|
5
|
+
const promise = new Promise((res, rej) => {
|
|
6
|
+
resolve = res;
|
|
7
|
+
reject = rej;
|
|
8
|
+
});
|
|
9
|
+
return { promise, resolve, reject };
|
|
10
|
+
};
|
|
11
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -342,17 +342,48 @@ const sdkWindowKey = '_tsEmbedSDK' as any;
|
|
|
342
342
|
* Stores a value in the global `window` object under the `_tsEmbedSDK` namespace.
|
|
343
343
|
* @param key - The key under which the value will be stored.
|
|
344
344
|
* @param value - The value to store.
|
|
345
|
+
* @param options - Additional options.
|
|
346
|
+
* @param options.ignoreIfAlreadyExists - Does not set if value for key is set.
|
|
347
|
+
*
|
|
348
|
+
* @returns The stored value.
|
|
349
|
+
*
|
|
350
|
+
* @version SDK: 1.36.2 | ThoughtSpot: *
|
|
345
351
|
*/
|
|
346
|
-
export
|
|
352
|
+
export function storeValueInWindow<T>(
|
|
353
|
+
key: string,
|
|
354
|
+
value: T,
|
|
355
|
+
options: { ignoreIfAlreadyExists?: boolean } = {},
|
|
356
|
+
): T {
|
|
347
357
|
if (!window[sdkWindowKey]) {
|
|
348
358
|
(window as any)[sdkWindowKey] = {};
|
|
349
359
|
}
|
|
350
|
-
|
|
351
|
-
|
|
360
|
+
|
|
361
|
+
if (options.ignoreIfAlreadyExists && key in (window as any)[sdkWindowKey]) {
|
|
362
|
+
return (window as any)[sdkWindowKey][key];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
(window as any)[sdkWindowKey][key] = value;
|
|
366
|
+
return value;
|
|
367
|
+
}
|
|
352
368
|
|
|
353
369
|
/**
|
|
354
370
|
* Retrieves a stored value from the global `window` object under the `_tsEmbedSDK` namespace.
|
|
355
371
|
* @param key - The key whose value needs to be retrieved.
|
|
356
372
|
* @returns The stored value or `undefined` if the key is not found.
|
|
357
373
|
*/
|
|
358
|
-
export const getValueFromWindow =
|
|
374
|
+
export const getValueFromWindow = <T = any>
|
|
375
|
+
(key: string): T => (window as any)?.[sdkWindowKey]?.[key];
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Resets the key if it exists in the `window` object under the `_tsEmbedSDK` key.
|
|
379
|
+
* Returns true if the key was reset, false otherwise.
|
|
380
|
+
* @param key - Key to reset
|
|
381
|
+
* @returns - boolean indicating if the key was reset
|
|
382
|
+
*/
|
|
383
|
+
export function resetValueFromWindow(key: string): boolean {
|
|
384
|
+
if (key in window[sdkWindowKey]) {
|
|
385
|
+
delete (window as any)[sdkWindowKey][key];
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
return false;
|
|
389
|
+
}
|