@servicetitan/web-components 39.3.0 → 40.1.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.
- package/dist/loader.js +3 -1
- package/dist/loader.js.map +1 -1
- package/dist/utils/get-bundle-info.d.ts +1 -1
- package/dist/utils/get-bundle-info.d.ts.map +1 -1
- package/dist/utils/get-bundle-info.js +2 -10
- package/dist/utils/get-bundle-info.js.map +1 -1
- package/dist/utils/get-mfe-supports-versioned-ld-client.d.ts +3 -0
- package/dist/utils/get-mfe-supports-versioned-ld-client.d.ts.map +1 -0
- package/dist/utils/get-mfe-supports-versioned-ld-client.js +11 -0
- package/dist/utils/get-mfe-supports-versioned-ld-client.js.map +1 -0
- package/dist/utils/web-component.d.ts.map +1 -1
- package/dist/utils/web-component.js +1 -4
- package/dist/utils/web-component.js.map +1 -1
- package/package.json +12 -15
- package/src/__tests__/loader.test.tsx +31 -43
- package/src/loader.tsx +7 -3
- package/src/utils/__tests__/get-mfe-supports-versioned-ld-client.test.ts +38 -0
- package/src/utils/__tests__/load-scripts.test.ts +0 -1
- package/src/utils/get-bundle-info.ts +2 -11
- package/src/utils/get-mfe-supports-versioned-ld-client.ts +12 -0
- package/src/utils/web-component.tsx +1 -5
package/dist/loader.js
CHANGED
|
@@ -131,7 +131,9 @@ function lazyWebComponent(props) {
|
|
|
131
131
|
packageUrl: src
|
|
132
132
|
});
|
|
133
133
|
await loadScripts(bundleInfo);
|
|
134
|
-
const
|
|
134
|
+
const hostLDService = exposedInstanceDependencies === null || exposedInstanceDependencies === void 0 ? void 0 : (_exposedInstanceDependencies_launchDarkly = exposedInstanceDependencies.launchDarkly) === null || _exposedInstanceDependencies_launchDarkly === void 0 ? void 0 : _exposedInstanceDependencies_launchDarkly.ldService;
|
|
135
|
+
const hostSupportsVersionedLDClient = typeof (hostLDService === null || hostLDService === void 0 ? void 0 : hostLDService.getVersionClient) === 'function';
|
|
136
|
+
const ldService = bundleInfo.mfeHasCompatibleLaunchDarklyVersion || bundleInfo.mfeSupportsVersionedLDClient && hostSupportsVersionedLDClient ? hostLDService : undefined;
|
|
135
137
|
return {
|
|
136
138
|
default: webComponent({
|
|
137
139
|
basename,
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/loader.tsx"],"sourcesContent":["import { ErrorBoundary } from '@servicetitan/error-boundary';\nimport { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport {\n ReactElement,\n ReactNode,\n Ref,\n Suspense,\n forwardRef,\n lazy,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from 'react';\nimport {\n EXPOSED_DEPENDENCIES_TOKEN,\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,\n ExposedInstanceDependencies,\n GetJsonError,\n} from './common';\nimport { MFEContextData } from './contexts/mfe-data-context';\nimport { Delayed } from './delayed';\nimport { EVENT_BUS_TOKEN, EventBus } from './event-bus';\nimport { EXPOSED_DEPENDENCIES, EXPOSED_INSTANCE_DEPENDENCIES } from './globals';\nimport {\n BundleInfo,\n getBundleInfo,\n getLDServiceToken,\n loadScripts,\n validateBundleInfo,\n webComponent,\n} from './utils';\n\nexport type LoaderRef = EventBus;\n\nexport type FallbackNode = NonNullable<ReactNode> | null;\n\nexport interface UnrestrictedLoaderProps<T = {}> {\n src: string;\n fallbackSrc?: string;\n /** Values in the object will be stringified and then parsed before being delivered to the MFE via props or context. */\n data?: MFEContextData<T>;\n basename?: string;\n loadingFallback?: FallbackNode;\n loadingFallbackDelayed?: boolean;\n errorFallback?: FallbackNode;\n className?: string;\n retries?: number;\n isHeadless?: boolean;\n cache?: boolean | number;\n onRequestError?(error: GetJsonError): boolean;\n}\n\nexport type LoaderProps<T> = Pick<\n UnrestrictedLoaderProps<T>,\n | 'src'\n | 'fallbackSrc'\n | 'data'\n | 'basename'\n | 'loadingFallback'\n | 'loadingFallbackDelayed'\n | 'errorFallback'\n | 'className'\n | 'retries'\n | 'cache'\n | 'onRequestError'\n>;\n\nexport type LoaderDataProps = Pick<UnrestrictedLoaderProps, 'data' | 'className'> & {\n LoadingFallback: () => JSX.Element;\n};\n\nconst UnrestrictedLoader = <T,>(props: UnrestrictedLoaderProps<T>, ref: Ref<LoaderRef>) => {\n const { cache = -1, basename, fallbackSrc, isHeadless, onRequestError, retries, src } = props;\n const { loadingFallback, loadingFallbackDelayed = true } = props;\n\n const bus = useEventBus();\n const [logService, exposedDependencies = EXPOSED_DEPENDENCIES, eventBus = bus] =\n useOptionalDependencies(Log, EXPOSED_DEPENDENCIES_TOKEN, EVENT_BUS_TOKEN);\n let [exposedInstanceDependencies = EXPOSED_INSTANCE_DEPENDENCIES] = useOptionalDependencies(\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN\n );\n const [ldService] = useOptionalDependencies(getLDServiceToken() ?? Symbol());\n\n const LoadingFallback = useMemo(() => {\n const message = `Loading${isLocalHost(src) ? ` ${src}` : ''}...`;\n return getFallback(loadingFallback, message, { delayed: loadingFallbackDelayed });\n }, [loadingFallback, loadingFallbackDelayed, src]);\n\n const ErrorFallback = useMemo(() => {\n const message = `Something went wrong${isLocalHost(src) ? ` loading ${src}` : ''}`;\n return getFallback(props.errorFallback, message);\n }, [props.errorFallback, src]);\n\n exposedInstanceDependencies = useMemo(\n () => ensureLDService(exposedInstanceDependencies, ldService),\n [exposedInstanceDependencies, ldService]\n );\n\n const Loader = useMemo(() => {\n const cancelation = new AbortController();\n return lazyLoader({\n basename,\n cache,\n cancelation,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n });\n }, [\n basename,\n cache,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n ]);\n\n useImperativeHandle(ref, () => eventBus, [eventBus]);\n\n return (\n <ErrorBoundary moduleName={src} fallback={ErrorFallback}>\n <Suspense fallback={<LoadingFallback />}>\n <Loader\n data={props.data ?? {}}\n className={props.className}\n LoadingFallback={LoadingFallback}\n />\n </Suspense>\n </ErrorBoundary>\n );\n};\n\nexport const Loader = forwardRef(UnrestrictedLoader) as <T = {}>(\n props: LoaderProps<NoInfer<T>> & { ref?: Ref<LoaderRef> }\n) => ReturnType<typeof UnrestrictedLoader>;\n\ntype LazyLoaderProps = UnrestrictedLoaderProps<any> & {\n cancelation: AbortController;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n eventBus: EventBus;\n logService?: Log;\n cache: Required<UnrestrictedLoaderProps<any>>['cache'];\n};\n\nfunction lazyLoader(props: LazyLoaderProps) {\n const { cancelation } = props;\n\n const LazyWebComponent = lazyWebComponent(props);\n\n return (props: LoaderDataProps) => {\n useEffect(() => {\n return () => {\n cancelation.abort();\n };\n }, []);\n\n return (\n <LazyWebComponent\n data={props.data}\n className={props.className}\n LoadingFallback={props.LoadingFallback}\n />\n );\n };\n}\n\nfunction lazyWebComponent(props: LazyLoaderProps) {\n const {\n basename,\n cache,\n cancelation,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n } = props;\n\n return lazy<(_: LoaderDataProps) => JSX.Element | null>(async () => {\n let bundleInfo: BundleInfo;\n try {\n bundleInfo = await getBundleInfo({\n cache,\n mainPackageUrl: src,\n fallbackPackageUrl: fallbackSrc,\n isHeadless,\n exposedDependencies,\n exposedInstanceDependencies,\n signal: cancelation.signal,\n retries,\n onRequestError,\n });\n } catch (e) {\n if (cancelation.signal.aborted) {\n return {\n default: () => null,\n };\n }\n\n throw e;\n }\n\n validateBundleInfo(bundleInfo, {\n exposedDependencies,\n exposedInstanceDependencies,\n logService,\n packageUrl: src,\n });\n\n await loadScripts(bundleInfo);\n\n const ldService = bundleInfo.mfeHasCompatibleLaunchDarklyVersion\n ? exposedInstanceDependencies?.launchDarkly?.ldService\n : undefined;\n\n return {\n default: webComponent({\n basename,\n bundleInfo,\n eventBus,\n exposedDependencies,\n exposedInstanceDependencies,\n ldService,\n logService,\n }),\n };\n });\n}\n\nfunction getFallback(\n node: FallbackNode | undefined,\n message: string,\n { delayed = false }: { delayed?: boolean } = {}\n) {\n const fallbackNode = node !== undefined ? (node as ReactElement) : <h2>{message}</h2>;\n return delayed ? () => <Delayed>{fallbackNode}</Delayed> : () => fallbackNode;\n}\n\nfunction isLocalHost(source: string) {\n return ['localhost', '127.0.0.1'].some(host => source.indexOf(host) >= 0);\n}\n\nfunction ensureLDService(\n exposedInstanceDependencies?: ExposedInstanceDependencies,\n ldService?: LDService\n) {\n const launchDarkly = exposedInstanceDependencies?.launchDarkly;\n if (launchDarkly?.version && !launchDarkly.ldService && ldService) {\n return { ...exposedInstanceDependencies, launchDarkly: { ...launchDarkly, ldService } };\n }\n return exposedInstanceDependencies;\n}\n\nfunction useEventBus() {\n return useRef(new EventBus()).current;\n}\n"],"names":["ErrorBoundary","Log","useOptionalDependencies","Suspense","forwardRef","lazy","useEffect","useImperativeHandle","useMemo","useRef","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","Delayed","EVENT_BUS_TOKEN","EventBus","EXPOSED_DEPENDENCIES","EXPOSED_INSTANCE_DEPENDENCIES","getBundleInfo","getLDServiceToken","loadScripts","validateBundleInfo","webComponent","UnrestrictedLoader","props","ref","cache","basename","fallbackSrc","isHeadless","onRequestError","retries","src","loadingFallback","loadingFallbackDelayed","bus","useEventBus","logService","exposedDependencies","eventBus","exposedInstanceDependencies","ldService","Symbol","LoadingFallback","message","isLocalHost","getFallback","delayed","ErrorFallback","errorFallback","ensureLDService","Loader","cancelation","AbortController","lazyLoader","moduleName","fallback","data","className","LazyWebComponent","lazyWebComponent","abort","bundleInfo","mainPackageUrl","fallbackPackageUrl","signal","e","aborted","default","packageUrl","mfeHasCompatibleLaunchDarklyVersion","launchDarkly","undefined","node","fallbackNode","h2","source","some","host","indexOf","version","current"],"mappings":";AAAA,SAASA,aAAa,QAAQ,+BAA+B;AAE7D,SAASC,GAAG,QAAQ,4BAA4B;AAChD,SAASC,uBAAuB,QAAQ,0BAA0B;AAElE,SAIIC,QAAQ,EACRC,UAAU,EACVC,IAAI,EACJC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,QACH,QAAQ;AACf,SACIC,0BAA0B,EAC1BC,mCAAmC,QAGhC,WAAW;AAElB,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,eAAe,EAAEC,QAAQ,QAAQ,cAAc;AACxD,SAASC,oBAAoB,EAAEC,6BAA6B,QAAQ,YAAY;AAChF,SAEIC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,QACT,UAAU;AAyCjB,MAAMC,qBAAqB,CAAKC,OAAmCC;QAUnBN,oBAqDtBK;IA9DtB,MAAM,EAAEE,QAAQ,CAAC,CAAC,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,UAAU,EAAEC,cAAc,EAAEC,OAAO,EAAEC,GAAG,EAAE,GAAGR;IACxF,MAAM,EAAES,eAAe,EAAEC,yBAAyB,IAAI,EAAE,GAAGV;IAE3D,MAAMW,MAAMC;IACZ,MAAM,CAACC,YAAYC,sBAAsBtB,oBAAoB,EAAEuB,WAAWJ,GAAG,CAAC,GAC1EhC,wBAAwBD,KAAKS,4BAA4BG;IAC7D,IAAI,CAAC0B,8BAA8BvB,6BAA6B,CAAC,GAAGd,wBAChES;IAEJ,MAAM,CAAC6B,UAAU,GAAGtC,yBAAwBgB,qBAAAA,iCAAAA,gCAAAA,qBAAuBuB;IAEnE,MAAMC,kBAAkBlC,QAAQ;QAC5B,MAAMmC,UAAU,CAAC,OAAO,EAAEC,YAAYb,OAAO,CAAC,CAAC,EAAEA,KAAK,G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B,YAAY+B,MAAc;IAC/B,OAAO;QAAC;QAAa;KAAY,CAACC,IAAI,CAACC,CAAAA,OAAQF,OAAOG,OAAO,CAACD,SAAS;AAC3E;AAEA,SAAS5B,gBACLV,2BAAyD,EACzDC,SAAqB;IAErB,MAAM8B,eAAe/B,wCAAAA,kDAAAA,4BAA6B+B,YAAY;IAC9D,IAAIA,CAAAA,yBAAAA,mCAAAA,aAAcS,OAAO,KAAI,CAACT,aAAa9B,SAAS,IAAIA,WAAW;QAC/D,OAAO;YAAE,GAAGD,2BAA2B;YAAE+B,cAAc;gBAAE,GAAGA,YAAY;gBAAE9B;YAAU;QAAE;IAC1F;IACA,OAAOD;AACX;AAEA,SAASJ;IACL,OAAO1B,OAAO,IAAIK,YAAYkE,OAAO;AACzC"}
|
|
1
|
+
{"version":3,"sources":["../src/loader.tsx"],"sourcesContent":["import { ErrorBoundary } from '@servicetitan/error-boundary';\nimport { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport {\n ReactElement,\n ReactNode,\n Ref,\n Suspense,\n forwardRef,\n lazy,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from 'react';\nimport {\n EXPOSED_DEPENDENCIES_TOKEN,\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,\n ExposedInstanceDependencies,\n GetJsonError,\n} from './common';\nimport { MFEContextData } from './contexts/mfe-data-context';\nimport { Delayed } from './delayed';\nimport { EVENT_BUS_TOKEN, EventBus } from './event-bus';\nimport { EXPOSED_DEPENDENCIES, EXPOSED_INSTANCE_DEPENDENCIES } from './globals';\nimport {\n BundleInfo,\n getBundleInfo,\n getLDServiceToken,\n loadScripts,\n validateBundleInfo,\n webComponent,\n} from './utils';\n\nexport type LoaderRef = EventBus;\n\nexport type FallbackNode = NonNullable<ReactNode> | null;\n\nexport interface UnrestrictedLoaderProps<T = {}> {\n src: string;\n fallbackSrc?: string;\n /** Values in the object will be stringified and then parsed before being delivered to the MFE via props or context. */\n data?: MFEContextData<T>;\n basename?: string;\n loadingFallback?: FallbackNode;\n loadingFallbackDelayed?: boolean;\n errorFallback?: FallbackNode;\n className?: string;\n retries?: number;\n isHeadless?: boolean;\n cache?: boolean | number;\n onRequestError?(error: GetJsonError): boolean;\n}\n\nexport type LoaderProps<T> = Pick<\n UnrestrictedLoaderProps<T>,\n | 'src'\n | 'fallbackSrc'\n | 'data'\n | 'basename'\n | 'loadingFallback'\n | 'loadingFallbackDelayed'\n | 'errorFallback'\n | 'className'\n | 'retries'\n | 'cache'\n | 'onRequestError'\n>;\n\nexport type LoaderDataProps = Pick<UnrestrictedLoaderProps, 'data' | 'className'> & {\n LoadingFallback: () => JSX.Element;\n};\n\nconst UnrestrictedLoader = <T,>(props: UnrestrictedLoaderProps<T>, ref: Ref<LoaderRef>) => {\n const { cache = -1, basename, fallbackSrc, isHeadless, onRequestError, retries, src } = props;\n const { loadingFallback, loadingFallbackDelayed = true } = props;\n\n const bus = useEventBus();\n const [logService, exposedDependencies = EXPOSED_DEPENDENCIES, eventBus = bus] =\n useOptionalDependencies(Log, EXPOSED_DEPENDENCIES_TOKEN, EVENT_BUS_TOKEN);\n let [exposedInstanceDependencies = EXPOSED_INSTANCE_DEPENDENCIES] = useOptionalDependencies(\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN\n );\n const [ldService] = useOptionalDependencies(getLDServiceToken() ?? Symbol());\n\n const LoadingFallback = useMemo(() => {\n const message = `Loading${isLocalHost(src) ? ` ${src}` : ''}...`;\n return getFallback(loadingFallback, message, { delayed: loadingFallbackDelayed });\n }, [loadingFallback, loadingFallbackDelayed, src]);\n\n const ErrorFallback = useMemo(() => {\n const message = `Something went wrong${isLocalHost(src) ? ` loading ${src}` : ''}`;\n return getFallback(props.errorFallback, message);\n }, [props.errorFallback, src]);\n\n exposedInstanceDependencies = useMemo(\n () => ensureLDService(exposedInstanceDependencies, ldService),\n [exposedInstanceDependencies, ldService]\n );\n\n const Loader = useMemo(() => {\n const cancelation = new AbortController();\n return lazyLoader({\n basename,\n cache,\n cancelation,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n });\n }, [\n basename,\n cache,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n ]);\n\n useImperativeHandle(ref, () => eventBus, [eventBus]);\n\n return (\n <ErrorBoundary moduleName={src} fallback={ErrorFallback}>\n <Suspense fallback={<LoadingFallback />}>\n <Loader\n data={props.data ?? {}}\n className={props.className}\n LoadingFallback={LoadingFallback}\n />\n </Suspense>\n </ErrorBoundary>\n );\n};\n\nexport const Loader = forwardRef(UnrestrictedLoader) as <T = {}>(\n props: LoaderProps<NoInfer<T>> & { ref?: Ref<LoaderRef> }\n) => ReturnType<typeof UnrestrictedLoader>;\n\ntype LazyLoaderProps = UnrestrictedLoaderProps<any> & {\n cancelation: AbortController;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n eventBus: EventBus;\n logService?: Log;\n cache: Required<UnrestrictedLoaderProps<any>>['cache'];\n};\n\nfunction lazyLoader(props: LazyLoaderProps) {\n const { cancelation } = props;\n\n const LazyWebComponent = lazyWebComponent(props);\n\n return (props: LoaderDataProps) => {\n useEffect(() => {\n return () => {\n cancelation.abort();\n };\n }, []);\n\n return (\n <LazyWebComponent\n data={props.data}\n className={props.className}\n LoadingFallback={props.LoadingFallback}\n />\n );\n };\n}\n\nfunction lazyWebComponent(props: LazyLoaderProps) {\n const {\n basename,\n cache,\n cancelation,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n } = props;\n\n return lazy<(_: LoaderDataProps) => JSX.Element | null>(async () => {\n let bundleInfo: BundleInfo;\n try {\n bundleInfo = await getBundleInfo({\n cache,\n mainPackageUrl: src,\n fallbackPackageUrl: fallbackSrc,\n isHeadless,\n exposedDependencies,\n exposedInstanceDependencies,\n signal: cancelation.signal,\n retries,\n onRequestError,\n });\n } catch (e) {\n if (cancelation.signal.aborted) {\n return {\n default: () => null,\n };\n }\n\n throw e;\n }\n\n validateBundleInfo(bundleInfo, {\n exposedDependencies,\n exposedInstanceDependencies,\n logService,\n packageUrl: src,\n });\n\n await loadScripts(bundleInfo);\n\n const hostLDService = exposedInstanceDependencies?.launchDarkly?.ldService;\n const hostSupportsVersionedLDClient = typeof hostLDService?.getVersionClient === 'function';\n const ldService =\n bundleInfo.mfeHasCompatibleLaunchDarklyVersion ||\n (bundleInfo.mfeSupportsVersionedLDClient && hostSupportsVersionedLDClient)\n ? hostLDService\n : undefined;\n\n return {\n default: webComponent({\n basename,\n bundleInfo,\n eventBus,\n exposedDependencies,\n exposedInstanceDependencies,\n ldService,\n logService,\n }),\n };\n });\n}\n\nfunction getFallback(\n node: FallbackNode | undefined,\n message: string,\n { delayed = false }: { delayed?: boolean } = {}\n) {\n const fallbackNode = node !== undefined ? (node as ReactElement) : <h2>{message}</h2>;\n return delayed ? () => <Delayed>{fallbackNode}</Delayed> : () => fallbackNode;\n}\n\nfunction isLocalHost(source: string) {\n return ['localhost', '127.0.0.1'].some(host => source.indexOf(host) >= 0);\n}\n\nfunction ensureLDService(\n exposedInstanceDependencies?: ExposedInstanceDependencies,\n ldService?: LDService\n) {\n const launchDarkly = exposedInstanceDependencies?.launchDarkly;\n if (launchDarkly?.version && !launchDarkly.ldService && ldService) {\n return { ...exposedInstanceDependencies, launchDarkly: { ...launchDarkly, ldService } };\n }\n return exposedInstanceDependencies;\n}\n\nfunction useEventBus() {\n return useRef(new EventBus()).current;\n}\n"],"names":["ErrorBoundary","Log","useOptionalDependencies","Suspense","forwardRef","lazy","useEffect","useImperativeHandle","useMemo","useRef","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","Delayed","EVENT_BUS_TOKEN","EventBus","EXPOSED_DEPENDENCIES","EXPOSED_INSTANCE_DEPENDENCIES","getBundleInfo","getLDServiceToken","loadScripts","validateBundleInfo","webComponent","UnrestrictedLoader","props","ref","cache","basename","fallbackSrc","isHeadless","onRequestError","retries","src","loadingFallback","loadingFallbackDelayed","bus","useEventBus","logService","exposedDependencies","eventBus","exposedInstanceDependencies","ldService","Symbol","LoadingFallback","message","isLocalHost","getFallback","delayed","ErrorFallback","errorFallback","ensureLDService","Loader","cancelation","AbortController","lazyLoader","moduleName","fallback","data","className","LazyWebComponent","lazyWebComponent","abort","bundleInfo","mainPackageUrl","fallbackPackageUrl","signal","e","aborted","default","packageUrl","hostLDService","launchDarkly","hostSupportsVersionedLDClient","getVersionClient","mfeHasCompatibleLaunchDarklyVersion","mfeSupportsVersionedLDClient","undefined","node","fallbackNode","h2","source","some","host","indexOf","version","current"],"mappings":";AAAA,SAASA,aAAa,QAAQ,+BAA+B;AAE7D,SAASC,GAAG,QAAQ,4BAA4B;AAChD,SAASC,uBAAuB,QAAQ,0BAA0B;AAElE,SAIIC,QAAQ,EACRC,UAAU,EACVC,IAAI,EACJC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,QACH,QAAQ;AACf,SACIC,0BAA0B,EAC1BC,mCAAmC,QAGhC,WAAW;AAElB,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,eAAe,EAAEC,QAAQ,QAAQ,cAAc;AACxD,SAASC,oBAAoB,EAAEC,6BAA6B,QAAQ,YAAY;AAChF,SAEIC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,QACT,UAAU;AAyCjB,MAAMC,qBAAqB,CAAKC,OAAmCC;QAUnBN,oBAqDtBK;IA9DtB,MAAM,EAAEE,QAAQ,CAAC,CAAC,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,UAAU,EAAEC,cAAc,EAAE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YAAY0C;QAElB,MAAMQ,gBAAgB9B,wCAAAA,mDAAAA,4CAAAA,4BAA6B+B,YAAY,cAAzC/B,gEAAAA,0CAA2CC,SAAS;QAC1E,MAAM+B,gCAAgC,QAAOF,0BAAAA,oCAAAA,cAAeG,gBAAgB,MAAK;QACjF,MAAMhC,YACFqB,WAAWY,mCAAmC,IAC7CZ,WAAWa,4BAA4B,IAAIH,gCACtCF,gBACAM;QAEV,OAAO;YACHR,SAAS9C,aAAa;gBAClBK;gBACAmC;gBACAvB;gBACAD;gBACAE;gBACAC;gBACAJ;YACJ;QACJ;IACJ;AACJ;AAEA,SAASS,YACL+B,IAA8B,EAC9BjC,OAAe,EACf,EAAEG,UAAU,KAAK,EAAyB,GAAG,CAAC,CAAC;IAE/C,MAAM+B,eAAeD,SAASD,YAAaC,qBAAwB,KAACE;kBAAInC;;IACxE,OAAOG,UAAU,kBAAM,KAAClC;sBAASiE;aAA0B,IAAMA;AACrE;AAEA,SAASjC,YAAYmC,MAAc;IAC/B,OAAO;QAAC;QAAa;KAAY,CAACC,IAAI,CAACC,CAAAA,OAAQF,OAAOG,OAAO,CAACD,SAAS;AAC3E;AAEA,SAAShC,gBACLV,2BAAyD,EACzDC,SAAqB;IAErB,MAAM8B,eAAe/B,wCAAAA,kDAAAA,4BAA6B+B,YAAY;IAC9D,IAAIA,CAAAA,yBAAAA,mCAAAA,aAAca,OAAO,KAAI,CAACb,aAAa9B,SAAS,IAAIA,WAAW;QAC/D,OAAO;YAAE,GAAGD,2BAA2B;YAAE+B,cAAc;gBAAE,GAAGA,YAAY;gBAAE9B;YAAU;QAAE;IAC1F;IACA,OAAOD;AACX;AAEA,SAASJ;IACL,OAAO1B,OAAO,IAAIK,YAAYsE,OAAO;AACzC"}
|
|
@@ -16,10 +16,10 @@ interface GetBundleInfoProps {
|
|
|
16
16
|
export declare function getBundleInfo({ cache, mainPackageUrl, fallbackPackageUrl, exposedDependencies, exposedInstanceDependencies, isHeadless, signal, retries, onRequestError, }: GetBundleInfoProps): Promise<{
|
|
17
17
|
bundledWith: Record<string, string | undefined> | undefined;
|
|
18
18
|
cacheHit: boolean | undefined;
|
|
19
|
-
disposer: () => void;
|
|
20
19
|
mfeSupportsRerendering: boolean;
|
|
21
20
|
mfeHasUniqueChunkNamespace: boolean;
|
|
22
21
|
mfeHasCompatibleLaunchDarklyVersion: boolean | undefined;
|
|
22
|
+
mfeSupportsVersionedLDClient: boolean;
|
|
23
23
|
mismatch: Record<string, {
|
|
24
24
|
host: string;
|
|
25
25
|
package: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-bundle-info.d.ts","sourceRoot":"","sources":["../../src/utils/get-bundle-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAwB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"get-bundle-info.d.ts","sourceRoot":"","sources":["../../src/utils/get-bundle-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAwB,MAAM,6BAA6B,CAAC;AAExF,OAAO,EAAE,2BAA2B,EAAW,YAAY,EAAE,MAAM,WAAW,CAAC;AAI/E,OAAO,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAMjE,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC;AAEnE,UAAU,kBAAkB;IACxB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;IAC1D,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;CACxB;AAED,wBAAsB,aAAa,CAAC,EAChC,KAAK,EACL,cAAc,EACd,kBAAkB,EAClB,mBAAwB,EACxB,2BAAgC,EAChC,UAAU,EACV,MAAM,EACN,OAAO,EACP,cAAc,GACjB,EAAE,kBAAkB;;;;;;;;;;;;;;;;GAqFpB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getVersionMismatches } from '@servicetitan/startup-utils';
|
|
2
|
-
import get from 'lodash.get';
|
|
3
2
|
import semver from 'semver';
|
|
4
3
|
import { getJson } from '../common';
|
|
5
4
|
import { getCacheSetting } from './get-cache-setting';
|
|
@@ -8,6 +7,7 @@ import { getEntrypoints } from './get-entry-points';
|
|
|
8
7
|
import { getMFEHasCompatibleLaunchDarklyVersion } from './get-mfe-has-compatible-launchdarkly-version';
|
|
9
8
|
import { getMFEHasUniqueChunkNamespace } from './get-mfe-has-unique-chunk-namespace';
|
|
10
9
|
import { getMFESupportsRerendering } from './get-mfe-supports-rerendering';
|
|
10
|
+
import { getMFESupportsVersionedLDClient } from './get-mfe-supports-versioned-ld-client';
|
|
11
11
|
export async function getBundleInfo({ cache, mainPackageUrl, fallbackPackageUrl, exposedDependencies = {}, exposedInstanceDependencies = {}, isHeadless, signal, retries, onRequestError }) {
|
|
12
12
|
var _metadata_entrypoints;
|
|
13
13
|
const { cacheHit, data: metadata, url: packageUrl } = await getCachedMetadata({
|
|
@@ -50,14 +50,6 @@ export async function getBundleInfo({ cache, mainPackageUrl, fallbackPackageUrl,
|
|
|
50
50
|
} else {
|
|
51
51
|
entrypoints = await getEntrypoints(`${bundleBaseUrl}/entrypoints.json`, requestCache);
|
|
52
52
|
}
|
|
53
|
-
const disposer = ()=>{
|
|
54
|
-
if (resolvedBundleType === 'light') {
|
|
55
|
-
const path = Object.values(sharedDependencies).shift();
|
|
56
|
-
if (path) {
|
|
57
|
-
get(window, path).getStorage().clear(name);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
53
|
let baseUrl = bundleBaseUrl;
|
|
62
54
|
// Per-MFE dev-server port only happens during local development
|
|
63
55
|
if (process.env.NODE_ENV !== 'production' && entrypoints.port) {
|
|
@@ -73,10 +65,10 @@ export async function getBundleInfo({ cache, mainPackageUrl, fallbackPackageUrl,
|
|
|
73
65
|
return {
|
|
74
66
|
bundledWith,
|
|
75
67
|
cacheHit,
|
|
76
|
-
disposer,
|
|
77
68
|
mfeSupportsRerendering: getMFESupportsRerendering(bundledWith, dependencies),
|
|
78
69
|
mfeHasUniqueChunkNamespace: getMFEHasUniqueChunkNamespace(bundledWith),
|
|
79
70
|
mfeHasCompatibleLaunchDarklyVersion: getMFEHasCompatibleLaunchDarklyVersion(bundledWith, exposedInstanceDependencies),
|
|
71
|
+
mfeSupportsVersionedLDClient: getMFESupportsVersionedLDClient(bundledWith),
|
|
80
72
|
mismatch,
|
|
81
73
|
resolvedBundleType,
|
|
82
74
|
urls,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/get-bundle-info.ts"],"sourcesContent":["import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils';\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get-bundle-info.ts"],"sourcesContent":["import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils';\nimport semver from 'semver';\nimport { ExposedInstanceDependencies, getJson, GetJsonError } from '../common';\nimport type { Metadata } from '../types';\nimport { getCacheSetting } from './get-cache-setting';\nimport { getCachedMetadata } from './get-cached-metadata';\nimport { EntryPoints, getEntrypoints } from './get-entry-points';\nimport { getMFEHasCompatibleLaunchDarklyVersion } from './get-mfe-has-compatible-launchdarkly-version';\nimport { getMFEHasUniqueChunkNamespace } from './get-mfe-has-unique-chunk-namespace';\nimport { getMFESupportsRerendering } from './get-mfe-supports-rerendering';\nimport { getMFESupportsVersionedLDClient } from './get-mfe-supports-versioned-ld-client';\n\nexport type BundleInfo = Awaited<ReturnType<typeof getBundleInfo>>;\n\ninterface GetBundleInfoProps {\n cache: boolean | number;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n fallbackPackageUrl?: string;\n isHeadless?: boolean;\n mainPackageUrl: string;\n onRequestError?: (error: GetJsonError) => void;\n retries?: number;\n signal?: AbortSignal;\n}\n\nexport async function getBundleInfo({\n cache,\n mainPackageUrl,\n fallbackPackageUrl,\n exposedDependencies = {},\n exposedInstanceDependencies = {},\n isHeadless,\n signal,\n retries,\n onRequestError,\n}: GetBundleInfoProps) {\n const {\n cacheHit,\n data: metadata,\n url: packageUrl,\n } = await getCachedMetadata({\n cache,\n fallbackPackageUrl,\n mainPackageUrl,\n onRequestError,\n retries,\n signal,\n });\n\n const { bundledWith, name, sharedDependencies } = metadata;\n const exactPackageUrl = packageUrl.replace('/dist/metadata.json', '');\n const requestCache = getCacheSetting(exactPackageUrl);\n\n let dependencies: NonNullable<Metadata['dependencies']>;\n if (metadata.dependencies) {\n dependencies = metadata.dependencies;\n } else {\n const { data: packageJson } = await getJson(`${exactPackageUrl}/package.json`, {\n cache: requestCache,\n retries,\n signal,\n });\n\n dependencies = packageJson.dependencies;\n }\n\n let mismatch: ReturnType<typeof getVersionMismatches>;\n let resolvedBundleType: 'headless' | 'light' | 'full';\n\n if (isHeadless) {\n resolvedBundleType = 'headless';\n } else {\n mismatch = getVersionMismatches(exposedDependencies, dependencies, sharedDependencies);\n const startupVersion = bundledWith?.['@servicetitan/startup'];\n const supportLightBundles = !!startupVersion && semver.gte(startupVersion, '17.0.0');\n const embed = !mismatch && supportLightBundles;\n resolvedBundleType = embed ? 'light' : 'full';\n }\n\n const bundleBaseUrl = `${exactPackageUrl}/dist/bundle/${resolvedBundleType}`;\n\n let entrypoints: EntryPoints;\n if (metadata.entrypoints?.[resolvedBundleType]) {\n entrypoints = metadata.entrypoints[resolvedBundleType];\n } else {\n entrypoints = await getEntrypoints(`${bundleBaseUrl}/entrypoints.json`, requestCache);\n }\n\n let baseUrl = bundleBaseUrl;\n // Per-MFE dev-server port only happens during local development\n if (process.env.NODE_ENV !== 'production' && entrypoints.port) {\n const url = new URL(baseUrl);\n url.port = String(entrypoints.port);\n baseUrl = url.toString();\n }\n\n const urls: EntryPoints = {\n css: entrypoints.css.map(path => `${baseUrl}/${path}`),\n js: entrypoints.js.map(path => `${baseUrl}/${path}`),\n };\n\n const elementName = resolvedBundleType === 'headless' ? `headless-${name}` : name;\n\n return {\n bundledWith,\n cacheHit,\n mfeSupportsRerendering: getMFESupportsRerendering(bundledWith, dependencies),\n mfeHasUniqueChunkNamespace: getMFEHasUniqueChunkNamespace(bundledWith),\n mfeHasCompatibleLaunchDarklyVersion: getMFEHasCompatibleLaunchDarklyVersion(\n bundledWith,\n exposedInstanceDependencies\n ),\n mfeSupportsVersionedLDClient: getMFESupportsVersionedLDClient(bundledWith),\n mismatch,\n resolvedBundleType,\n urls,\n WebComponent: elementName,\n version: metadata.version,\n module: entrypoints.module,\n };\n}\n"],"names":["getVersionMismatches","semver","getJson","getCacheSetting","getCachedMetadata","getEntrypoints","getMFEHasCompatibleLaunchDarklyVersion","getMFEHasUniqueChunkNamespace","getMFESupportsRerendering","getMFESupportsVersionedLDClient","getBundleInfo","cache","mainPackageUrl","fallbackPackageUrl","exposedDependencies","exposedInstanceDependencies","isHeadless","signal","retries","onRequestError","metadata","cacheHit","data","url","packageUrl","bundledWith","name","sharedDependencies","exactPackageUrl","replace","requestCache","dependencies","packageJson","mismatch","resolvedBundleType","startupVersion","supportLightBundles","gte","embed","bundleBaseUrl","entrypoints","baseUrl","process","env","NODE_ENV","port","URL","String","toString","urls","css","map","path","js","elementName","mfeSupportsRerendering","mfeHasUniqueChunkNamespace","mfeHasCompatibleLaunchDarklyVersion","mfeSupportsVersionedLDClient","WebComponent","version","module"],"mappings":"AAAA,SAA8BA,oBAAoB,QAAQ,8BAA8B;AACxF,OAAOC,YAAY,SAAS;AAC5B,SAAsCC,OAAO,QAAsB,YAAY;AAE/E,SAASC,eAAe,QAAQ,sBA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client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAOzC,wBAAgB,+BAA+B,CAAC,WAAW,EAAE,QAAQ,CAAC,aAAa,CAAC,WAGnF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
/*
|
|
3
|
+
* Check if the MFE's @servicetitan/launchdarkly-service is new enough to prefer
|
|
4
|
+
* LDService.getVersionClient over LDService.getClient, and so can safely receive a
|
|
5
|
+
* host-provided LDService even when the LaunchDarkly SDK versions don't match exactly.
|
|
6
|
+
*/ export function getMFESupportsVersionedLDClient(bundledWith) {
|
|
7
|
+
const version = bundledWith === null || bundledWith === void 0 ? void 0 : bundledWith['@servicetitan/launchdarkly-service'];
|
|
8
|
+
return !!version && semver.gte(version, '40.0.0');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=get-mfe-supports-versioned-ld-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get-mfe-supports-versioned-ld-client.ts"],"sourcesContent":["import semver from 'semver';\nimport type { Metadata } from '../types';\n\n/*\n * Check if the MFE's @servicetitan/launchdarkly-service is new enough to prefer\n * LDService.getVersionClient over LDService.getClient, and so can safely receive a\n * host-provided LDService even when the LaunchDarkly SDK versions don't match exactly.\n */\nexport function getMFESupportsVersionedLDClient(bundledWith: Metadata['bundledWith']) {\n const version = bundledWith?.['@servicetitan/launchdarkly-service'];\n return !!version && semver.gte(version, '40.0.0');\n}\n"],"names":["semver","getMFESupportsVersionedLDClient","bundledWith","version","gte"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAG5B;;;;CAIC,GACD,OAAO,SAASC,gCAAgCC,WAAoC;IAChF,MAAMC,UAAUD,wBAAAA,kCAAAA,WAAa,CAAC,qCAAqC;IACnE,OAAO,CAAC,CAACC,WAAWH,OAAOI,GAAG,CAACD,SAAS;AAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-component.d.ts","sourceRoot":"","sources":["../../src/utils/web-component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,2BAA2B,EAAiB,MAAM,WAAW,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,UAAU,iBAAiB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;IAC1D,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"web-component.d.ts","sourceRoot":"","sources":["../../src/utils/web-component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,2BAA2B,EAAiB,MAAM,WAAW,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,UAAU,iBAAiB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;IAC1D,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,IAUzC,oCAAoC,eAAe,6CA0D9D"}
|
|
@@ -6,7 +6,7 @@ import { getElementName } from './get-element-name';
|
|
|
6
6
|
export function webComponent(props) {
|
|
7
7
|
var _bundleInfo_bundledWith;
|
|
8
8
|
const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;
|
|
9
|
-
const { WebComponent, resolvedBundleType,
|
|
9
|
+
const { WebComponent, resolvedBundleType, mfeSupportsRerendering, version } = bundleInfo;
|
|
10
10
|
const elementName = getElementName(bundleInfo);
|
|
11
11
|
const exposedInstanceDependencies = ensureLDVersion(props.exposedInstanceDependencies, (_bundleInfo_bundledWith = bundleInfo.bundledWith) === null || _bundleInfo_bundledWith === void 0 ? void 0 : _bundleInfo_bundledWith['launchdarkly-js-client-sdk']);
|
|
12
12
|
return ({ LoadingFallback, ...innerProps })=>{
|
|
@@ -23,9 +23,6 @@ export function webComponent(props) {
|
|
|
23
23
|
basename,
|
|
24
24
|
onReady: ()=>{
|
|
25
25
|
setIsLoading(false);
|
|
26
|
-
},
|
|
27
|
-
onDispose: ()=>{
|
|
28
|
-
disposer();
|
|
29
26
|
}
|
|
30
27
|
});
|
|
31
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/web-component.tsx"],"sourcesContent":["import { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport { Fragment, useMemo, useState } from 'react';\nimport { ExposedInstanceDependencies, IWebComponent } from '../common';\nimport { MFEContextData } from '../contexts/mfe-data-context';\nimport { EventBus } from '../event-bus';\nimport { HistoryManager } from '../history-manager';\nimport { LoaderDataProps } from '../loader';\nimport { BundleInfo } from './get-bundle-info';\nimport { getElementName } from './get-element-name';\n\ninterface WebComponentProps {\n basename?: string;\n bundleInfo: BundleInfo;\n eventBus: EventBus;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n ldService?: LDService;\n logService?: Log;\n}\n\nexport function webComponent(props: WebComponentProps) {\n const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;\n const { WebComponent, resolvedBundleType,
|
|
1
|
+
{"version":3,"sources":["../../src/utils/web-component.tsx"],"sourcesContent":["import { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport { Fragment, useMemo, useState } from 'react';\nimport { ExposedInstanceDependencies, IWebComponent } from '../common';\nimport { MFEContextData } from '../contexts/mfe-data-context';\nimport { EventBus } from '../event-bus';\nimport { HistoryManager } from '../history-manager';\nimport { LoaderDataProps } from '../loader';\nimport { BundleInfo } from './get-bundle-info';\nimport { getElementName } from './get-element-name';\n\ninterface WebComponentProps {\n basename?: string;\n bundleInfo: BundleInfo;\n eventBus: EventBus;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n ldService?: LDService;\n logService?: Log;\n}\n\nexport function webComponent(props: WebComponentProps) {\n const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;\n const { WebComponent, resolvedBundleType, mfeSupportsRerendering, version } = bundleInfo;\n const elementName = getElementName(bundleInfo);\n\n const exposedInstanceDependencies = ensureLDVersion(\n props.exposedInstanceDependencies,\n bundleInfo.bundledWith?.['launchdarkly-js-client-sdk']\n );\n\n return ({ LoadingFallback, ...innerProps }: LoaderDataProps) => {\n const [isLoading, setIsLoading] = useState(true);\n const [historyManager] = useOptionalDependencies(HistoryManager);\n\n const handleRef = (webComponent: IWebComponent | null) => {\n webComponent?.provide({\n ldService,\n logService,\n historyManager,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n basename,\n onReady: () => {\n setIsLoading(false);\n },\n });\n };\n\n // Stringify data object so that it can be passed as a data-attribute\n const stringifiedData = useMemo(() => JSON.stringify(innerProps.data), [innerProps.data]);\n\n /*\n * Set key for rendering the web component so that if the data from the Host change,\n * and the MFE's version of startup doesn't support watching for data changes, then\n * the web component will be re-mounted whenever the data changes.\n * This is only used as a fallback when the MFE's version is older.\n */\n const key = mfeSupportsRerendering ? undefined : stringifiedData;\n const dataAttrs = useMemo(() => composeDataAttributes(innerProps.data), [innerProps.data]);\n const styleUrls = getStyleUrls(bundleInfo);\n\n return (\n <Fragment>\n {isLoading && <LoadingFallback />}\n <WebComponent\n key={key}\n ref={handleRef}\n class={innerProps.className}\n {...(styleUrls && { 'style-urls': styleUrls })}\n /*\n * Continue to spread data as separate data attributes for backwards compatibility,\n * in case the Host has updated web-components, but the MFE has not\n */\n {...dataAttrs}\n data-mfe-data={stringifiedData}\n data-mfe-name={elementName}\n {...(version && { 'data-mfe-version': version })}\n // @ts-expect-error style exists on HTMLElement\n style={\n isLoading || resolvedBundleType === 'headless'\n ? { display: 'none' }\n : undefined\n }\n />\n </Fragment>\n );\n };\n}\n\n/*\n * Convert camelCase data props to kebab-case data attributes, prepended with data-\n * Ex: fooBar -> data-foo-bar\n */\nfunction composeDataAttributes(data: MFEContextData<{}> | undefined = {}) {\n return Object.fromEntries(\n Object.entries(data).map(([key, value]) => [\n 'data-' + key.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase()),\n value,\n ])\n );\n}\n\nfunction ensureLDVersion(\n exposedInstanceDependencies: ExposedInstanceDependencies = {},\n version?: string\n) {\n if (version && !exposedInstanceDependencies.launchDarkly?.ldService) {\n return { ...exposedInstanceDependencies, launchDarkly: { version } };\n }\n return exposedInstanceDependencies;\n}\n\nfunction getStyleUrls({ urls }: Pick<BundleInfo, 'urls'>) {\n if (urls.css.length) {\n return encodeURIComponent(JSON.stringify(urls.css));\n }\n}\n"],"names":["useOptionalDependencies","Fragment","useMemo","useState","HistoryManager","getElementName","webComponent","props","bundleInfo","basename","eventBus","exposedDependencies","ldService","logService","WebComponent","resolvedBundleType","mfeSupportsRerendering","version","elementName","exposedInstanceDependencies","ensureLDVersion","bundledWith","LoadingFallback","innerProps","isLoading","setIsLoading","historyManager","handleRef","provide","onReady","stringifiedData","JSON","stringify","data","key","undefined","dataAttrs","composeDataAttributes","styleUrls","getStyleUrls","ref","class","className","data-mfe-data","data-mfe-name","style","display","Object","fromEntries","entries","map","value","replace","letter","toLowerCase","launchDarkly","urls","css","length","encodeURIComponent"],"mappings":";AAEA,SAASA,uBAAuB,QAAQ,0BAA0B;AAElE,SAASC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAIpD,SAASC,cAAc,QAAQ,qBAAqB;AAGpD,SAASC,cAAc,QAAQ,qBAAqB;AAYpD,OAAO,SAASC,aAAaC,KAAwB;QAO7CC;IANJ,MAAM,EAAEC,QAAQ,EAAED,UAAU,EAAEE,QAAQ,EAAEC,mBAAmB,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGN;IACvF,MAAM,EAAEO,YAAY,EAAEC,kBAAkB,EAAEC,sBAAsB,EAAEC,OAAO,EAAE,GAAGT;IAC9E,MAAMU,cAAcb,eAAeG;IAEnC,MAAMW,8BAA8BC,gBAChCb,MAAMY,2BAA2B,GACjCX,0BAAAA,WAAWa,WAAW,cAAtBb,8CAAAA,uBAAwB,CAAC,6BAA6B;IAG1D,OAAO,CAAC,EAAEc,eAAe,EAAE,GAAGC,YAA6B;QACvD,MAAM,CAACC,WAAWC,aAAa,GAAGtB,S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E,4CAAAA,4BAA4BoC,YAAY,cAAxCpC,gEAAAA,0CAA0CP,SAAS,GAAE;QACjE,OAAO;YAAE,GAAGO,2BAA2B;YAAEoC,cAAc;gBAAEtC;YAAQ;QAAE;IACvE;IACA,OAAOE;AACX;AAEA,SAASoB,aAAa,EAAEiB,IAAI,EAA4B;IACpD,IAAIA,KAAKC,GAAG,CAACC,MAAM,EAAE;QACjB,OAAOC,mBAAmB5B,KAAKC,SAAS,CAACwB,KAAKC,GAAG;IACrD;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/web-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "40.1.0",
|
|
4
4
|
"description": "Framework to build, register, and load Microfrontends into host applications",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/uikit/web-components",
|
|
6
6
|
"repository": {
|
|
@@ -31,38 +31,35 @@
|
|
|
31
31
|
"src"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@servicetitan/error-boundary": "
|
|
35
|
-
"@servicetitan/startup-utils": "
|
|
36
|
-
"lodash.get": "~4.4.2",
|
|
34
|
+
"@servicetitan/error-boundary": "40.1.0",
|
|
35
|
+
"@servicetitan/startup-utils": "40.1.0",
|
|
37
36
|
"mitt": "~3.0.1",
|
|
38
37
|
"semver": "~7.8.5"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"@servicetitan/anvil2": "^3.
|
|
40
|
+
"@servicetitan/anvil2": "^3.15.0",
|
|
42
41
|
"@servicetitan/design-system": "~14.5.3",
|
|
43
|
-
"@servicetitan/launchdarkly-service": "
|
|
44
|
-
"@servicetitan/log-service": "
|
|
45
|
-
"@servicetitan/react-ioc": "
|
|
46
|
-
"@testing-library/dom": "^10.4.
|
|
42
|
+
"@servicetitan/launchdarkly-service": "40.1.0",
|
|
43
|
+
"@servicetitan/log-service": "40.1.0",
|
|
44
|
+
"@servicetitan/react-ioc": "40.1.0",
|
|
45
|
+
"@testing-library/dom": "^10.4.2",
|
|
47
46
|
"@testing-library/jest-dom": "^7.0.1",
|
|
48
47
|
"@testing-library/react": "^16.3.3",
|
|
49
48
|
"@types/history": "~4.7.10",
|
|
50
|
-
"@types/lodash.get": "~4.4.6",
|
|
51
49
|
"@types/react": "~18.3.3",
|
|
52
50
|
"@types/react-dom": "~18.3.0",
|
|
53
51
|
"@types/semver": "~7.7.1",
|
|
54
52
|
"history": "~4.10.1",
|
|
55
|
-
"launchdarkly-react-client-sdk": "3.6.1",
|
|
56
53
|
"react": "~18.3.1",
|
|
57
54
|
"react-dom": "~18.3.1",
|
|
58
|
-
"shadow-dom-testing-library": "^1.14.
|
|
55
|
+
"shadow-dom-testing-library": "^1.14.2"
|
|
59
56
|
},
|
|
60
57
|
"peerDependencies": {
|
|
61
58
|
"@servicetitan/anvil2": ">=1.5.0",
|
|
62
59
|
"@servicetitan/design-system": ">=14.5.3",
|
|
63
|
-
"@servicetitan/launchdarkly-service": "
|
|
64
|
-
"@servicetitan/log-service": "
|
|
65
|
-
"@servicetitan/react-ioc": "
|
|
60
|
+
"@servicetitan/launchdarkly-service": "40.1.0",
|
|
61
|
+
"@servicetitan/log-service": "40.1.0",
|
|
62
|
+
"@servicetitan/react-ioc": "40.1.0",
|
|
66
63
|
"history": "~4.10.1",
|
|
67
64
|
"react": ">=17.0.2",
|
|
68
65
|
"react-dom": ">=17.0.2"
|
|
@@ -18,12 +18,14 @@ import { Loader, LoaderProps, UnrestrictedLoaderProps } from '../loader';
|
|
|
18
18
|
import { Metadata } from '../types';
|
|
19
19
|
import { getMFEHasCompatibleLaunchDarklyVersion } from '../utils/get-mfe-has-compatible-launchdarkly-version';
|
|
20
20
|
import { getMFEHasUniqueChunkNamespace } from '../utils/get-mfe-has-unique-chunk-namespace';
|
|
21
|
+
import { getMFESupportsVersionedLDClient } from '../utils/get-mfe-supports-versioned-ld-client';
|
|
21
22
|
|
|
22
23
|
jest.mock('@servicetitan/startup-utils', () => ({
|
|
23
24
|
getVersionMismatches: jest.fn(),
|
|
24
25
|
}));
|
|
25
26
|
jest.mock('../utils/get-mfe-has-compatible-launchdarkly-version');
|
|
26
27
|
jest.mock('../utils/get-mfe-has-unique-chunk-namespace');
|
|
28
|
+
jest.mock('../utils/get-mfe-supports-versioned-ld-client');
|
|
27
29
|
|
|
28
30
|
describe('[web-components] Loader', () => {
|
|
29
31
|
const localHosts = ['localhost', '127.0.0.1'];
|
|
@@ -136,6 +138,7 @@ describe('[web-components] Loader', () => {
|
|
|
136
138
|
jest.mocked(getMFEHasCompatibleLaunchDarklyVersion).mockReturnValue(true);
|
|
137
139
|
jest.mocked(getVersionMismatches).mockReturnValue(undefined);
|
|
138
140
|
jest.mocked(getMFEHasUniqueChunkNamespace).mockReturnValue(true);
|
|
141
|
+
jest.mocked(getMFESupportsVersionedLDClient).mockReturnValue(false);
|
|
139
142
|
});
|
|
140
143
|
|
|
141
144
|
const Root = () => (
|
|
@@ -732,9 +735,10 @@ describe('[web-components] Loader', () => {
|
|
|
732
735
|
});
|
|
733
736
|
|
|
734
737
|
describe('when ldService is provided via EXPOSED_INSTANCE_DEPENDENCIES', () => {
|
|
735
|
-
|
|
738
|
+
let ldService: { getVersionClient?: jest.Mock };
|
|
736
739
|
|
|
737
740
|
beforeEach(() => {
|
|
741
|
+
ldService = {};
|
|
738
742
|
singletons?.push({
|
|
739
743
|
provide: EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,
|
|
740
744
|
useValue: { launchDarkly: { version: '1.0', ldService } },
|
|
@@ -751,9 +755,32 @@ describe('[web-components] Loader', () => {
|
|
|
751
755
|
jest.mocked(getMFEHasCompatibleLaunchDarklyVersion).mockReturnValue(false);
|
|
752
756
|
});
|
|
753
757
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
758
|
+
function itDoesNotProvideLDService() {
|
|
759
|
+
test('does not provide ldService to the web component', async () => {
|
|
760
|
+
await webComponentReadySetup();
|
|
761
|
+
expect(webComponentState.ldService).toBeUndefined();
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
itDoesNotProvideLDService();
|
|
766
|
+
|
|
767
|
+
describe('when MFE supports a versioned LD client', () => {
|
|
768
|
+
beforeEach(() => {
|
|
769
|
+
jest.mocked(getMFESupportsVersionedLDClient).mockReturnValue(true);
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
itDoesNotProvideLDService();
|
|
773
|
+
|
|
774
|
+
describe("when the host's LDService supports a versioned client", () => {
|
|
775
|
+
beforeEach(() => {
|
|
776
|
+
ldService.getVersionClient = jest.fn();
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
test('provides ldService to the web component', async () => {
|
|
780
|
+
await webComponentReadySetup();
|
|
781
|
+
expect(webComponentState.ldService).toEqual(ldService);
|
|
782
|
+
});
|
|
783
|
+
});
|
|
757
784
|
});
|
|
758
785
|
});
|
|
759
786
|
});
|
|
@@ -835,45 +862,6 @@ describe('[web-components] Loader', () => {
|
|
|
835
862
|
});
|
|
836
863
|
});
|
|
837
864
|
|
|
838
|
-
describe('when onDispose is called from the web component', () => {
|
|
839
|
-
async function onDisposeSetup() {
|
|
840
|
-
await webComponentReadySetup();
|
|
841
|
-
webComponentState.onDispose!();
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
const clearSpy = jest.fn();
|
|
845
|
-
|
|
846
|
-
beforeEach(() => {
|
|
847
|
-
Object.defineProperty(window, 'SharedDependencies.ServiceTitan.DesignSystem', {
|
|
848
|
-
value: {
|
|
849
|
-
getStorage: () => ({
|
|
850
|
-
clear: clearSpy,
|
|
851
|
-
}),
|
|
852
|
-
},
|
|
853
|
-
configurable: true,
|
|
854
|
-
});
|
|
855
|
-
});
|
|
856
|
-
|
|
857
|
-
test('storage is not cleared', async () => {
|
|
858
|
-
await onDisposeSetup();
|
|
859
|
-
expect(clearSpy).not.toHaveBeenCalledWith(WEB_COMPONENT_NAME);
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
describe('when peerDependencies are provided', () => {
|
|
863
|
-
beforeEach(() => {
|
|
864
|
-
metadata.sharedDependencies = {
|
|
865
|
-
'@servicetitan/design-system':
|
|
866
|
-
'SharedDependencies.ServiceTitan.DesignSystem',
|
|
867
|
-
};
|
|
868
|
-
});
|
|
869
|
-
|
|
870
|
-
test('storage is cleared', async () => {
|
|
871
|
-
await onDisposeSetup();
|
|
872
|
-
expect(clearSpy).toHaveBeenCalledWith(WEB_COMPONENT_NAME);
|
|
873
|
-
});
|
|
874
|
-
});
|
|
875
|
-
});
|
|
876
|
-
|
|
877
865
|
describe('when a script tag (without a webComponent data attr) for this bundle is in the DOM before Loader is rendered', () => {
|
|
878
866
|
const originalOnloadSpy = jest.fn();
|
|
879
867
|
|
package/src/loader.tsx
CHANGED
|
@@ -229,9 +229,13 @@ function lazyWebComponent(props: LazyLoaderProps) {
|
|
|
229
229
|
|
|
230
230
|
await loadScripts(bundleInfo);
|
|
231
231
|
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
const hostLDService = exposedInstanceDependencies?.launchDarkly?.ldService;
|
|
233
|
+
const hostSupportsVersionedLDClient = typeof hostLDService?.getVersionClient === 'function';
|
|
234
|
+
const ldService =
|
|
235
|
+
bundleInfo.mfeHasCompatibleLaunchDarklyVersion ||
|
|
236
|
+
(bundleInfo.mfeSupportsVersionedLDClient && hostSupportsVersionedLDClient)
|
|
237
|
+
? hostLDService
|
|
238
|
+
: undefined;
|
|
235
239
|
|
|
236
240
|
return {
|
|
237
241
|
default: webComponent({
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Metadata } from '../../types';
|
|
2
|
+
import { getMFESupportsVersionedLDClient } from '../get-mfe-supports-versioned-ld-client';
|
|
3
|
+
|
|
4
|
+
describe(`[web-components] ${getMFESupportsVersionedLDClient.name}`, () => {
|
|
5
|
+
let bundledWith: NonNullable<Metadata['bundledWith']>;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
bundledWith = {};
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const subject = () => getMFESupportsVersionedLDClient(bundledWith);
|
|
12
|
+
|
|
13
|
+
function itReturns(value: boolean) {
|
|
14
|
+
test(`returns ${value}`, () => {
|
|
15
|
+
expect(subject()).toBe(value);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
itReturns(false);
|
|
20
|
+
|
|
21
|
+
describe('when bundledWith @servicetitan/launchdarkly-service is below the threshold version', () => {
|
|
22
|
+
beforeEach(() => (bundledWith['@servicetitan/launchdarkly-service'] = '39.5.0'));
|
|
23
|
+
|
|
24
|
+
itReturns(false);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('when bundledWith @servicetitan/launchdarkly-service meets the threshold version', () => {
|
|
28
|
+
beforeEach(() => (bundledWith['@servicetitan/launchdarkly-service'] = '40.0.0'));
|
|
29
|
+
|
|
30
|
+
itReturns(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('when bundledWith @servicetitan/launchdarkly-service exceeds the threshold version', () => {
|
|
34
|
+
beforeEach(() => (bundledWith['@servicetitan/launchdarkly-service'] = '41.0.0'));
|
|
35
|
+
|
|
36
|
+
itReturns(true);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils';
|
|
2
|
-
import get from 'lodash.get';
|
|
3
2
|
import semver from 'semver';
|
|
4
3
|
import { ExposedInstanceDependencies, getJson, GetJsonError } from '../common';
|
|
5
4
|
import type { Metadata } from '../types';
|
|
@@ -9,6 +8,7 @@ import { EntryPoints, getEntrypoints } from './get-entry-points';
|
|
|
9
8
|
import { getMFEHasCompatibleLaunchDarklyVersion } from './get-mfe-has-compatible-launchdarkly-version';
|
|
10
9
|
import { getMFEHasUniqueChunkNamespace } from './get-mfe-has-unique-chunk-namespace';
|
|
11
10
|
import { getMFESupportsRerendering } from './get-mfe-supports-rerendering';
|
|
11
|
+
import { getMFESupportsVersionedLDClient } from './get-mfe-supports-versioned-ld-client';
|
|
12
12
|
|
|
13
13
|
export type BundleInfo = Awaited<ReturnType<typeof getBundleInfo>>;
|
|
14
14
|
|
|
@@ -87,15 +87,6 @@ export async function getBundleInfo({
|
|
|
87
87
|
entrypoints = await getEntrypoints(`${bundleBaseUrl}/entrypoints.json`, requestCache);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
const disposer = () => {
|
|
91
|
-
if (resolvedBundleType === 'light') {
|
|
92
|
-
const path = Object.values<string>(sharedDependencies).shift();
|
|
93
|
-
if (path) {
|
|
94
|
-
get(window, path).getStorage().clear(name);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
90
|
let baseUrl = bundleBaseUrl;
|
|
100
91
|
// Per-MFE dev-server port only happens during local development
|
|
101
92
|
if (process.env.NODE_ENV !== 'production' && entrypoints.port) {
|
|
@@ -114,13 +105,13 @@ export async function getBundleInfo({
|
|
|
114
105
|
return {
|
|
115
106
|
bundledWith,
|
|
116
107
|
cacheHit,
|
|
117
|
-
disposer,
|
|
118
108
|
mfeSupportsRerendering: getMFESupportsRerendering(bundledWith, dependencies),
|
|
119
109
|
mfeHasUniqueChunkNamespace: getMFEHasUniqueChunkNamespace(bundledWith),
|
|
120
110
|
mfeHasCompatibleLaunchDarklyVersion: getMFEHasCompatibleLaunchDarklyVersion(
|
|
121
111
|
bundledWith,
|
|
122
112
|
exposedInstanceDependencies
|
|
123
113
|
),
|
|
114
|
+
mfeSupportsVersionedLDClient: getMFESupportsVersionedLDClient(bundledWith),
|
|
124
115
|
mismatch,
|
|
125
116
|
resolvedBundleType,
|
|
126
117
|
urls,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import type { Metadata } from '../types';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Check if the MFE's @servicetitan/launchdarkly-service is new enough to prefer
|
|
6
|
+
* LDService.getVersionClient over LDService.getClient, and so can safely receive a
|
|
7
|
+
* host-provided LDService even when the LaunchDarkly SDK versions don't match exactly.
|
|
8
|
+
*/
|
|
9
|
+
export function getMFESupportsVersionedLDClient(bundledWith: Metadata['bundledWith']) {
|
|
10
|
+
const version = bundledWith?.['@servicetitan/launchdarkly-service'];
|
|
11
|
+
return !!version && semver.gte(version, '40.0.0');
|
|
12
|
+
}
|
|
@@ -23,8 +23,7 @@ interface WebComponentProps {
|
|
|
23
23
|
|
|
24
24
|
export function webComponent(props: WebComponentProps) {
|
|
25
25
|
const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;
|
|
26
|
-
const { WebComponent, resolvedBundleType,
|
|
27
|
-
bundleInfo;
|
|
26
|
+
const { WebComponent, resolvedBundleType, mfeSupportsRerendering, version } = bundleInfo;
|
|
28
27
|
const elementName = getElementName(bundleInfo);
|
|
29
28
|
|
|
30
29
|
const exposedInstanceDependencies = ensureLDVersion(
|
|
@@ -48,9 +47,6 @@ export function webComponent(props: WebComponentProps) {
|
|
|
48
47
|
onReady: () => {
|
|
49
48
|
setIsLoading(false);
|
|
50
49
|
},
|
|
51
|
-
onDispose: () => {
|
|
52
|
-
disposer();
|
|
53
|
-
},
|
|
54
50
|
});
|
|
55
51
|
};
|
|
56
52
|
|