@myop/sdk 0.3.33 → 0.3.36
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/bundled-declarations.d.ts +66 -3
- package/dist/cjs/{_IframeSDK.e5b2bc49.js → _IframeSDK.3283252f.js} +76 -34
- package/dist/cjs/{_IframeSDK.e5b2bc49.js.map → _IframeSDK.3283252f.js.map} +2 -2
- package/dist/cjs/_IframeSDK.652f4774.min.js +1 -0
- package/dist/cjs/{_MyopHelpers.95610381.js → _MyopHelpers.08d1cf5d.js} +68 -20
- package/dist/cjs/{_MyopHelpers.95610381.js.map → _MyopHelpers.08d1cf5d.js.map} +2 -2
- package/dist/cjs/_MyopHelpers.59521d8f.min.js +1 -0
- package/dist/cjs/_WebComponentSDK.8fe7c9bf.min.js +1 -0
- package/dist/cjs/{_WebComponentSDK.a7e660ab.js → _WebComponentSDK.e84be6ea.js} +76 -34
- package/dist/cjs/{_WebComponentSDK.a7e660ab.js.map → _WebComponentSDK.e84be6ea.js.map} +2 -2
- package/dist/cjs/_hostSDK.de2d767e.min.js +1 -0
- package/dist/cjs/{_hostSDK.1905850e.js → _hostSDK.fa5b3ccf.js} +76 -34
- package/dist/cjs/{_hostSDK.1905850e.js.map → _hostSDK.fa5b3ccf.js.map} +2 -2
- package/dist/cjs/myop_sdk.js +14 -14
- package/dist/cjs/myop_sdk.js.map +1 -1
- package/dist/cjs/myop_sdk.min.js +1 -1
- package/dist/cjs-bundled/myop_sdk.bundled.js +85 -36
- package/dist/cjs-bundled/myop_sdk.bundled.js.map +2 -2
- package/dist/cjs-bundled/myop_sdk.bundled.min.js +1 -1
- package/dist/module/Iframe/index.js +79 -35
- package/dist/module/Iframe/index.js.map +2 -2
- package/dist/module/SDK.js +87 -36
- package/dist/module/SDK.js.map +2 -2
- package/dist/module/embeddedSDK.js +1 -1
- package/dist/module/helpers/CloudRepository.d.ts +43 -0
- package/dist/module/helpers/cloudRepositoryHelpers.d.ts +21 -2
- package/dist/module/helpers/index.js +70 -21
- package/dist/module/helpers/index.js.map +2 -2
- package/dist/module/host/embeddedSDK.js +1 -1
- package/dist/module/host/index.js +79 -35
- package/dist/module/host/index.js.map +2 -2
- package/dist/module/host/loaders/HTMLComponentLoader.d.ts +2 -1
- package/dist/module/webcomponent/index.js +79 -35
- package/dist/module/webcomponent/index.js.map +2 -2
- package/package.json +1 -1
- package/dist/cjs/_IframeSDK.c7a53057.min.js +0 -1
- package/dist/cjs/_MyopHelpers.ca1b3a3c.min.js +0 -1
- package/dist/cjs/_WebComponentSDK.3a72ed95.min.js +0 -1
- package/dist/cjs/_hostSDK.0529d5ed.min.js +0 -1
|
@@ -1710,7 +1710,8 @@ declare module "@myop/sdk/host/loaders/HTMLComponentLoader" {
|
|
|
1710
1710
|
*/
|
|
1711
1711
|
private extractWebComponentScript;
|
|
1712
1712
|
/**
|
|
1713
|
-
* Execute the web component script on the host document
|
|
1713
|
+
* Execute the web component script on the host document.
|
|
1714
|
+
* Returns the custom element tag name this script registered.
|
|
1714
1715
|
*/
|
|
1715
1716
|
private executeWebComponentScript;
|
|
1716
1717
|
/**
|
|
@@ -1821,9 +1822,28 @@ declare module "@myop/sdk/helpers/CloudRepository" {
|
|
|
1821
1822
|
env: string;
|
|
1822
1823
|
preview: boolean;
|
|
1823
1824
|
} | undefined;
|
|
1825
|
+
/**
|
|
1826
|
+
* Resolve a component config: fetch it once, then serve it from this
|
|
1827
|
+
* repository's cache.
|
|
1828
|
+
*
|
|
1829
|
+
* This is the name to use. `fetchComponentV2` is the same method under its
|
|
1830
|
+
* versioned name and stays for backward compatibility — note that the
|
|
1831
|
+
* unversioned `fetchComponent` is a *deprecated v1* API and is NOT this.
|
|
1832
|
+
*
|
|
1833
|
+
* Completes the trio with {@link getResolvedConfig} (synchronous read of an
|
|
1834
|
+
* already-resolved config) and {@link hydrateComponent} (seed one you
|
|
1835
|
+
* already hold).
|
|
1836
|
+
*
|
|
1837
|
+
* Prefer the module-level `preloadComponents([id])` in app code; reach for
|
|
1838
|
+
* this when you need an isolated repository instance whose cache lifetime
|
|
1839
|
+
* you control — a server with its own TTL, for example.
|
|
1840
|
+
*/
|
|
1841
|
+
resolveComponent(componentId: string, env?: string, preview?: boolean): Promise<IComponentConfig>;
|
|
1824
1842
|
/**
|
|
1825
1843
|
* Fetch a v2 component config
|
|
1826
1844
|
* If env/preview not specified and component was preloaded, uses preloaded params
|
|
1845
|
+
*
|
|
1846
|
+
* @see resolveComponent — the unversioned name for this method
|
|
1827
1847
|
*/
|
|
1828
1848
|
fetchComponentV2(componentId: string, environmentIdentifier?: string, preview?: boolean): Promise<IComponentConfig>;
|
|
1829
1849
|
/**
|
|
@@ -1840,6 +1860,30 @@ declare module "@myop/sdk/helpers/CloudRepository" {
|
|
|
1840
1860
|
* skipping the WEBVIEW_READY → fetch → inject round trip entirely.
|
|
1841
1861
|
*/
|
|
1842
1862
|
getResolvedConfig(componentId: string, env?: string, preview?: boolean): IComponentConfig | null;
|
|
1863
|
+
/**
|
|
1864
|
+
* Resolve which (env, preview) pair — and therefore which cache key — a call
|
|
1865
|
+
* for `componentId` refers to.
|
|
1866
|
+
*
|
|
1867
|
+
* Single source of truth for fetchComponentV2, getResolvedConfig and
|
|
1868
|
+
* hydrateComponent, so a hydrated config always lands on the key a later
|
|
1869
|
+
* fetch will look under.
|
|
1870
|
+
*/
|
|
1871
|
+
private resolveParams;
|
|
1872
|
+
/**
|
|
1873
|
+
* Seed an already-resolved component config into the cache, without any
|
|
1874
|
+
* network request.
|
|
1875
|
+
*
|
|
1876
|
+
* The counterpart to {@link fetchComponentV2}: use it when the config was
|
|
1877
|
+
* resolved somewhere else — most often on a server, then embedded in the
|
|
1878
|
+
* page — so the browser can render the component with no round trip.
|
|
1879
|
+
*
|
|
1880
|
+
* After hydrating, `fetchComponentV2`, `getResolvedConfig` and `isPreloaded`
|
|
1881
|
+
* all answer for this component from memory.
|
|
1882
|
+
*
|
|
1883
|
+
* Pass the same `env` / `preview` the config was resolved with; the defaults
|
|
1884
|
+
* match what a plain `fetchComponentV2(componentId)` would have used.
|
|
1885
|
+
*/
|
|
1886
|
+
hydrateComponent(componentId: string, config: IComponentConfig, env?: string, preview?: boolean): void;
|
|
1843
1887
|
/**
|
|
1844
1888
|
* Fetch a v1 component from a flow
|
|
1845
1889
|
*/
|
|
@@ -1862,6 +1906,7 @@ declare module "@myop/sdk/helpers/exec" {
|
|
|
1862
1906
|
}
|
|
1863
1907
|
declare module "@myop/sdk/helpers/cloudRepositoryHelpers" {
|
|
1864
1908
|
import { CloudRepository } from "@myop/sdk/helpers/CloudRepository";
|
|
1909
|
+
import { IComponentConfig } from "@myop/sdk/common";
|
|
1865
1910
|
export const getCloudRepository: () => CloudRepository;
|
|
1866
1911
|
export const isPreloaded: (componentId: string, env?: string, preview?: boolean) => boolean;
|
|
1867
1912
|
export const getPreloadedParams: (componentId: string) => {
|
|
@@ -1878,8 +1923,26 @@ declare module "@myop/sdk/helpers/cloudRepositoryHelpers" {
|
|
|
1878
1923
|
export const enableSelfHosted: (cdnUrl: string, queryParams?: Record<string, string>) => void;
|
|
1879
1924
|
export const setCloudRepository: (repository: CloudRepository) => void;
|
|
1880
1925
|
export const setEnvironment: (env: string) => void;
|
|
1881
|
-
export const getResolvedConfig: (componentId: string, env?: string, preview?: boolean) =>
|
|
1882
|
-
export const preloadComponents: (ids: string[], env?: string, preview?: boolean) => Promise<PromiseSettledResult<
|
|
1926
|
+
export const getResolvedConfig: (componentId: string, env?: string, preview?: boolean) => IComponentConfig;
|
|
1927
|
+
export const preloadComponents: (ids: string[], env?: string, preview?: boolean) => Promise<PromiseSettledResult<IComponentConfig>[]>;
|
|
1928
|
+
/**
|
|
1929
|
+
* Seed already-resolved component configs into the SDK cache, with no network
|
|
1930
|
+
* request. The counterpart to {@link preloadComponents}.
|
|
1931
|
+
*
|
|
1932
|
+
* Use it when the configs were resolved somewhere else — typically on a server
|
|
1933
|
+
* and embedded in the page — so the component renders with zero round trips:
|
|
1934
|
+
*
|
|
1935
|
+
* ```ts
|
|
1936
|
+
* // server: const configs = { [id]: await new CloudRepository().fetchComponentV2(id) }
|
|
1937
|
+
* // client:
|
|
1938
|
+
* hydrateComponents(configs);
|
|
1939
|
+
* // <MyopComponent componentId={id} /> now renders without fetching
|
|
1940
|
+
* ```
|
|
1941
|
+
*
|
|
1942
|
+
* Pass the same `env` / `preview` the configs were resolved with; the defaults
|
|
1943
|
+
* match what a plain `preloadComponents([id])` would have used.
|
|
1944
|
+
*/
|
|
1945
|
+
export const hydrateComponents: (configs: Record<string, IComponentConfig>, env?: string, preview?: boolean) => void;
|
|
1883
1946
|
}
|
|
1884
1947
|
declare module "@myop/sdk/helpers" {
|
|
1885
1948
|
export * from "@myop/sdk/helpers/applyStylesheet";
|
|
@@ -2142,7 +2142,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
|
|
|
2142
2142
|
};
|
|
2143
2143
|
|
|
2144
2144
|
// version:myop-sdk-version
|
|
2145
|
-
var myop_sdk_version_default = "0.3.
|
|
2145
|
+
var myop_sdk_version_default = "0.3.36";
|
|
2146
2146
|
|
|
2147
2147
|
// src/webcomponent/messageHandlers/BaseWebComponentMessageHandler.ts
|
|
2148
2148
|
var BaseWebComponentMessageHandler = class extends BaseContextMessageHandler {
|
|
@@ -2474,7 +2474,7 @@ var HAS_EMBEDDED_SDK = false;
|
|
|
2474
2474
|
// src/host/loaders/HTMLComponentLoader.ts
|
|
2475
2475
|
var MYOP_WEB_COMPONENT_MARKER = "<!-- myop-web-component -->";
|
|
2476
2476
|
var MYOP_WEB_COMPONENT_SCRIPT_ID = "myop-web-component";
|
|
2477
|
-
var extractedWebComponentScripts = /* @__PURE__ */ new
|
|
2477
|
+
var extractedWebComponentScripts = /* @__PURE__ */ new Map();
|
|
2478
2478
|
var seen2 = [];
|
|
2479
2479
|
var sdk;
|
|
2480
2480
|
var getInitiatedSdk = async () => {
|
|
@@ -2715,19 +2715,25 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
2715
2715
|
return (script == null ? void 0 : script.textContent) || null;
|
|
2716
2716
|
}
|
|
2717
2717
|
/**
|
|
2718
|
-
* Execute the web component script on the host document
|
|
2718
|
+
* Execute the web component script on the host document.
|
|
2719
|
+
* Returns the custom element tag name this script registered.
|
|
2719
2720
|
*/
|
|
2720
2721
|
executeWebComponentScript(scriptContent, scriptId) {
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2722
|
+
const cachedTagName = extractedWebComponentScripts.get(scriptId);
|
|
2723
|
+
if (cachedTagName) {
|
|
2724
|
+
console.log("[MyopWebComponent] Script already executed for ".concat(scriptId, ", reusing <").concat(cachedTagName, ">"));
|
|
2725
|
+
return cachedTagName;
|
|
2724
2726
|
}
|
|
2725
2727
|
const script = document.createElement("script");
|
|
2726
2728
|
script.textContent = scriptContent;
|
|
2727
2729
|
script.id = "myop-extracted-".concat(scriptId);
|
|
2728
2730
|
document.head.appendChild(script);
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
+
const tagName = window.__MYOP_TAG_NAME__;
|
|
2732
|
+
if (tagName) {
|
|
2733
|
+
extractedWebComponentScripts.set(scriptId, tagName);
|
|
2734
|
+
}
|
|
2735
|
+
console.log("[MyopWebComponent] Executed web component script: ".concat(scriptId, " -> <").concat(tagName, ">"));
|
|
2736
|
+
return tagName;
|
|
2731
2737
|
}
|
|
2732
2738
|
/**
|
|
2733
2739
|
* Load a Myop Web Component (extracted and run on host document)
|
|
@@ -2738,15 +2744,10 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
2738
2744
|
throw new Error('[MyopWebComponent] No <script id="myop-web-component"> found in HTML');
|
|
2739
2745
|
}
|
|
2740
2746
|
const scriptId = "".concat(componentDefinition.id, "-").concat(skin.id);
|
|
2741
|
-
const
|
|
2742
|
-
this.executeWebComponentScript(scriptContent, scriptId);
|
|
2743
|
-
const tagName = window.__MYOP_TAG_NAME__;
|
|
2747
|
+
const tagName = this.executeWebComponentScript(scriptContent, scriptId);
|
|
2744
2748
|
if (!tagName) {
|
|
2745
2749
|
throw new Error("[MyopWebComponent] Script did not set window.__MYOP_TAG_NAME__");
|
|
2746
2750
|
}
|
|
2747
|
-
if (previousTagName && previousTagName !== tagName) {
|
|
2748
|
-
console.warn("[MyopWebComponent] __MYOP_TAG_NAME__ changed from ".concat(previousTagName, " to ").concat(tagName));
|
|
2749
|
-
}
|
|
2750
2751
|
const domId = "myop-comp-".concat(uuidv4());
|
|
2751
2752
|
const element = document.createElement(tagName);
|
|
2752
2753
|
element.id = domId;
|
|
@@ -2922,24 +2923,33 @@ var _CloudRepository = class _CloudRepository {
|
|
|
2922
2923
|
getPreloadedParams(componentId) {
|
|
2923
2924
|
return this.preloadedComponents[componentId];
|
|
2924
2925
|
}
|
|
2926
|
+
/**
|
|
2927
|
+
* Resolve a component config: fetch it once, then serve it from this
|
|
2928
|
+
* repository's cache.
|
|
2929
|
+
*
|
|
2930
|
+
* This is the name to use. `fetchComponentV2` is the same method under its
|
|
2931
|
+
* versioned name and stays for backward compatibility — note that the
|
|
2932
|
+
* unversioned `fetchComponent` is a *deprecated v1* API and is NOT this.
|
|
2933
|
+
*
|
|
2934
|
+
* Completes the trio with {@link getResolvedConfig} (synchronous read of an
|
|
2935
|
+
* already-resolved config) and {@link hydrateComponent} (seed one you
|
|
2936
|
+
* already hold).
|
|
2937
|
+
*
|
|
2938
|
+
* Prefer the module-level `preloadComponents([id])` in app code; reach for
|
|
2939
|
+
* this when you need an isolated repository instance whose cache lifetime
|
|
2940
|
+
* you control — a server with its own TTL, for example.
|
|
2941
|
+
*/
|
|
2942
|
+
async resolveComponent(componentId, env, preview) {
|
|
2943
|
+
return this.fetchComponentV2(componentId, env, preview);
|
|
2944
|
+
}
|
|
2925
2945
|
/**
|
|
2926
2946
|
* Fetch a v2 component config
|
|
2927
2947
|
* If env/preview not specified and component was preloaded, uses preloaded params
|
|
2948
|
+
*
|
|
2949
|
+
* @see resolveComponent — the unversioned name for this method
|
|
2928
2950
|
*/
|
|
2929
2951
|
async fetchComponentV2(componentId, environmentIdentifier, preview) {
|
|
2930
|
-
const
|
|
2931
|
-
const hasExplicitParams = environmentIdentifier !== void 0 || preview !== void 0;
|
|
2932
|
-
let env;
|
|
2933
|
-
let usePreview;
|
|
2934
|
-
if (!hasExplicitParams && preloaded) {
|
|
2935
|
-
env = preloaded.env;
|
|
2936
|
-
usePreview = preloaded.preview;
|
|
2937
|
-
} else {
|
|
2938
|
-
env = environmentIdentifier || this._defaultEnv;
|
|
2939
|
-
const hasEffectiveEnv = environmentIdentifier || this._envExplicitlySet;
|
|
2940
|
-
usePreview = preview === true ? true : preview === false ? false : !hasEffectiveEnv;
|
|
2941
|
-
}
|
|
2942
|
-
const cacheKey = "".concat(componentId, ":").concat(env, ":").concat(usePreview ? "preview" : "live");
|
|
2952
|
+
const { env, usePreview, cacheKey } = this.resolveParams(componentId, environmentIdentifier, preview);
|
|
2943
2953
|
console.log("[CloudRepository] fetchComponentV2", {
|
|
2944
2954
|
componentId: componentId.slice(0, 8) + "...",
|
|
2945
2955
|
env,
|
|
@@ -3008,20 +3018,52 @@ var _CloudRepository = class _CloudRepository {
|
|
|
3008
3018
|
*/
|
|
3009
3019
|
getResolvedConfig(componentId, env, preview) {
|
|
3010
3020
|
var _a;
|
|
3021
|
+
const { cacheKey } = this.resolveParams(componentId, env, preview);
|
|
3022
|
+
return ((_a = this.variants[cacheKey]) == null ? void 0 : _a.resolved) || null;
|
|
3023
|
+
}
|
|
3024
|
+
/**
|
|
3025
|
+
* Resolve which (env, preview) pair — and therefore which cache key — a call
|
|
3026
|
+
* for `componentId` refers to.
|
|
3027
|
+
*
|
|
3028
|
+
* Single source of truth for fetchComponentV2, getResolvedConfig and
|
|
3029
|
+
* hydrateComponent, so a hydrated config always lands on the key a later
|
|
3030
|
+
* fetch will look under.
|
|
3031
|
+
*/
|
|
3032
|
+
resolveParams(componentId, environmentIdentifier, preview) {
|
|
3011
3033
|
const preloaded = this.preloadedComponents[componentId];
|
|
3012
|
-
const hasExplicitParams =
|
|
3013
|
-
let
|
|
3034
|
+
const hasExplicitParams = environmentIdentifier !== void 0 || preview !== void 0;
|
|
3035
|
+
let env;
|
|
3014
3036
|
let usePreview;
|
|
3015
3037
|
if (!hasExplicitParams && preloaded) {
|
|
3016
|
-
|
|
3038
|
+
env = preloaded.env;
|
|
3017
3039
|
usePreview = preloaded.preview;
|
|
3018
3040
|
} else {
|
|
3019
|
-
|
|
3020
|
-
const hasEffectiveEnv =
|
|
3041
|
+
env = environmentIdentifier || this._defaultEnv;
|
|
3042
|
+
const hasEffectiveEnv = environmentIdentifier || this._envExplicitlySet;
|
|
3021
3043
|
usePreview = preview === true ? true : preview === false ? false : !hasEffectiveEnv;
|
|
3022
3044
|
}
|
|
3023
|
-
|
|
3024
|
-
|
|
3045
|
+
return { env, usePreview, cacheKey: "".concat(componentId, ":").concat(env, ":").concat(usePreview ? "preview" : "live") };
|
|
3046
|
+
}
|
|
3047
|
+
/**
|
|
3048
|
+
* Seed an already-resolved component config into the cache, without any
|
|
3049
|
+
* network request.
|
|
3050
|
+
*
|
|
3051
|
+
* The counterpart to {@link fetchComponentV2}: use it when the config was
|
|
3052
|
+
* resolved somewhere else — most often on a server, then embedded in the
|
|
3053
|
+
* page — so the browser can render the component with no round trip.
|
|
3054
|
+
*
|
|
3055
|
+
* After hydrating, `fetchComponentV2`, `getResolvedConfig` and `isPreloaded`
|
|
3056
|
+
* all answer for this component from memory.
|
|
3057
|
+
*
|
|
3058
|
+
* Pass the same `env` / `preview` the config was resolved with; the defaults
|
|
3059
|
+
* match what a plain `fetchComponentV2(componentId)` would have used.
|
|
3060
|
+
*/
|
|
3061
|
+
hydrateComponent(componentId, config, env, preview) {
|
|
3062
|
+
const { env: resolvedEnv, usePreview, cacheKey } = this.resolveParams(componentId, env, preview);
|
|
3063
|
+
const promise = Promise.resolve(config);
|
|
3064
|
+
promise.resolved = config;
|
|
3065
|
+
this.variants[cacheKey] = promise;
|
|
3066
|
+
this.preloadedComponents[componentId] = { env: resolvedEnv, preview: usePreview };
|
|
3025
3067
|
}
|
|
3026
3068
|
// ============ V1 Methods (Legacy) ============
|
|
3027
3069
|
/**
|