@myop/sdk 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +368 -208
  2. package/dist/bundled-declarations.d.ts +27 -200
  3. package/dist/cjs/{_IframeSDK.c7f71dba.js → _IframeSDK.69b595c4.js} +45 -31
  4. package/dist/cjs/{_IframeSDK.c7f71dba.js.map → _IframeSDK.69b595c4.js.map} +3 -3
  5. package/dist/cjs/{_IframeSDK.012474c1.min.js → _IframeSDK.845b6f30.min.js} +1 -1
  6. package/dist/cjs/_MyopHelpers.3d50ac48.min.js +1 -0
  7. package/dist/cjs/_MyopHelpers.7baba8b8.js +462 -0
  8. package/dist/cjs/_MyopHelpers.7baba8b8.js.map +7 -0
  9. package/dist/cjs/{_WebComponentSDK.93d3959a.js → _WebComponentSDK.38d1c6e7.js} +45 -31
  10. package/dist/cjs/{_WebComponentSDK.93d3959a.js.map → _WebComponentSDK.38d1c6e7.js.map} +3 -3
  11. package/dist/cjs/{_WebComponentSDK.15ffefb6.min.js → _WebComponentSDK.a9eff853.min.js} +1 -1
  12. package/dist/cjs/{_hostSDK.eeb98d7f.js → _hostSDK.083b3333.js} +45 -31
  13. package/dist/cjs/{_hostSDK.eeb98d7f.js.map → _hostSDK.083b3333.js.map} +3 -3
  14. package/dist/cjs/{_hostSDK.a852b7b7.min.js → _hostSDK.2a26ea6c.min.js} +1 -1
  15. package/dist/cjs/myop_sdk.js +14 -14
  16. package/dist/cjs/myop_sdk.js.map +1 -1
  17. package/dist/cjs/myop_sdk.min.js +1 -1
  18. package/dist/cjs-bundled/myop_sdk.bundled.js +3947 -0
  19. package/dist/cjs-bundled/myop_sdk.bundled.js.map +7 -0
  20. package/dist/cjs-bundled/myop_sdk.bundled.min.js +1 -0
  21. package/dist/module/Iframe/index.js +49 -33
  22. package/dist/module/Iframe/index.js.map +3 -3
  23. package/dist/module/SDK.js +52 -120
  24. package/dist/module/SDK.js.map +3 -3
  25. package/dist/module/helpers/CloudRepository.d.ts +27 -185
  26. package/dist/module/helpers/index.d.ts +0 -1
  27. package/dist/module/helpers/index.js +52 -2521
  28. package/dist/module/helpers/index.js.map +4 -4
  29. package/dist/module/host/index.js +49 -33
  30. package/dist/module/host/index.js.map +3 -3
  31. package/dist/module/webcomponent/index.js +49 -33
  32. package/dist/module/webcomponent/index.js.map +3 -3
  33. package/package.json +1 -1
  34. package/dist/cjs/_MyopHelpers.75e0fd8d.js +0 -2810
  35. package/dist/cjs/_MyopHelpers.75e0fd8d.js.map +0 -7
  36. package/dist/cjs/_MyopHelpers.ecfd80d9.min.js +0 -1
  37. package/dist/module/helpers/enableV2.d.ts +0 -12
@@ -1436,220 +1436,48 @@ declare module "@myop/sdk/helpers/configBuilder" {
1436
1436
  }
1437
1437
  }
1438
1438
  declare module "@myop/sdk/helpers/CloudRepository" {
1439
- import { IUserFlow } from "@myop/sdk/common";
1439
+ import { IUserFlow, v2_IVariantConfig } from "@myop/sdk/common";
1440
1440
  /**
1441
+ * CloudRepository - Unified cloud data access layer for Myop components
1441
1442
  *
1442
- * ## Overview
1443
- *
1444
- * The `CloudRepository` class serves as a centralized data access layer for retrieving user flows and components from the Myop.dev cloud service. It implements a singleton pattern and provides caching mechanisms to optimize API calls and improve performance.
1445
- *
1446
- * ## Class Structure
1447
- *
1448
- * ### Constructor
1449
- *
1450
- * ```typescript
1451
- * constructor(private _baseUrl = 'https://cloud.myop.dev')
1452
- * ```
1453
- *
1454
- * **Parameters:**
1455
- * - `_baseUrl` (optional): The base URL for the Myop.dev cloud API. Defaults to `'https://cloud.myop.dev'`
1456
- *
1457
- * ### Static Properties
1458
- *
1459
- * #### Main
1460
- * ```typescript
1461
- * static Main = new CloudRepository();
1462
- * ```
1463
- *
1464
- * A singleton instance of the `CloudRepository` class that can be used throughout the application without creating multiple instances.
1465
- *
1466
- * ### Private Properties
1467
- *
1468
- * #### userFlows
1469
- * ```typescript
1470
- * private userFlows: Record<string, Promise<IUserFlow>> = {};
1471
- * ```
1472
- *
1473
- * A cache object that stores promises for user flows, indexed by flow ID. This prevents duplicate API calls for the same flow and ensures consistent data retrieval.
1474
- *
1475
- * #### _baseUrl
1476
- * ```typescript
1477
- * private _baseUrl: string
1478
- * ```
1479
- *
1480
- * The base URL for the cloud API endpoints, set during construction.
1481
- *
1482
- * ## Methods
1483
- *
1484
- * ### fetchFlow(flowId: string)
1485
- *
1486
- * Retrieves a complete user flow from the cloud repository, including all resolved components.
1487
- *
1488
- * **Parameters:**
1489
- * - `flowId`: The unique identifier for the user flow to retrieve
1490
- *
1491
- * **Returns:**
1492
- * - `Promise<IUserFlow>`: A promise that resolves to the complete user flow object
1493
- *
1494
- * **Behavior:**
1495
- * - Implements request caching to avoid duplicate API calls for the same flow ID
1496
- * - Makes a GET request to `/flow?id={flowId}&resolve=components`
1497
- * - Automatically resolves component references within the flow
1498
- * - Stores the promise in the cache for future use
1499
- *
1500
- * **Example Usage:**
1501
- * ```typescript
1502
- * const flow = await CloudRepository.Main.fetchFlow('my-flow-id');
1503
- * console.log(flow.components);
1504
- * ```
1505
- *
1506
- * ### fetchComponent(componentId: string, flowId: string)
1507
- *
1508
- * Retrieves a specific component from within a user flow.
1509
- *
1510
- * **Parameters:**
1511
- * - `componentId`: The unique identifier for the component to retrieve
1512
- * - `flowId`: The unique identifier for the user flow containing the component
1513
- *
1514
- * **Returns:**
1515
- * - `Promise<Component | undefined>`: A promise that resolves to the component object if found, or undefined if not found
1516
- *
1517
- * **Behavior:**
1518
- * - First fetches the complete flow using `fetchFlow()`
1519
- * - Searches through the flow's components array to find the matching component
1520
- * - Uses the component's `type.id` property for matching
1521
- *
1522
- * **Example Usage:**
1523
- * ```typescript
1524
- * const component = await CloudRepository.Main.fetchComponent('button-component', 'my-flow-id');
1525
- * if (component) {
1526
- * console.log('Component found:', component);
1527
- * } else {
1528
- * console.log('Component not found in flow');
1529
- * }
1530
- * ```
1531
- *
1532
- * ## API Integration
1533
- *
1534
- * ### Endpoint Structure
1535
- *
1536
- * The class integrates with the following Myop.dev cloud API endpoint:
1537
- *
1538
- * ```
1539
- * GET {baseUrl}/flow?id={flowId}&resolve=components
1540
- * ```
1541
- *
1542
- * **Query Parameters:**
1543
- * - `id`: The flow identifier
1544
- * - `resolve=components`: Instructs the API to include resolved component data in the response
1545
- *
1546
- * ### Response Format
1547
- *
1548
- * The API is expected to return a JSON response with the following structure:
1549
- *
1550
- * ```json
1551
- * {
1552
- * "item": {
1553
- * // IUserFlow object with resolved components
1554
- * "components": [
1555
- * {
1556
- * "type": {
1557
- * "id": "component-id"
1558
- * }
1559
- * // ... other component properties
1560
- * }
1561
- * ]
1562
- * // ... other flow properties
1563
- * }
1564
- * }
1565
- * ```
1566
- *
1567
- * ## Caching Strategy
1568
- *
1569
- * The `CloudRepository` implements a promise-based caching mechanism:
1570
- *
1571
- * 1. **Cache Key**: Flow ID is used as the cache key
1572
- * 2. **Cache Value**: Promises are cached rather than resolved values to handle concurrent requests
1573
- * 3. **Cache Duration**: Cache persists for the lifetime of the repository instance
1574
- * 4. **Cache Invalidation**: No automatic cache invalidation is implemented
1575
- *
1576
- * ## Error Handling
1577
- *
1578
- * - Network errors and API failures are propagated through promise rejection
1579
- * - No specific error handling or retry logic is implemented at the repository level
1580
- * - Consumers should implement appropriate error handling when calling repository methods
1581
- *
1582
- * ## Usage Patterns
1583
- *
1584
- * ### Singleton Access
1585
- * ```typescript
1586
- * import { CloudRepository } from './path/to/CloudRepository';
1587
- *
1588
- * // Use the singleton instance
1589
- * const flow = await CloudRepository.Main.fetchFlow('flow-id');
1590
- * ```
1591
- *
1592
- * ### Custom Instance
1593
- * ```typescript
1594
- * // Create a custom instance with different base URL
1595
- * const customRepo = new CloudRepository('https://custom-api.example.com');
1596
- * const flow = await customRepo.fetchFlow('flow-id');
1597
- * ```
1598
- *
1599
- * ### Component Retrieval
1600
- * ```typescript
1601
- * // Get a specific component from a flow
1602
- * const component = await CloudRepository.Main.fetchComponent('component-id', 'flow-id');
1603
- * ```
1604
- *
1605
- * ## Dependencies
1606
- *
1607
- * - **IUserFlow**: Interface imported from `../common` that defines the structure of user flow objects
1608
- * - **Fetch API**: Uses the native `fetch` function for HTTP requests
1609
- *
1610
- * ## Performance Considerations
1611
- *
1612
- * - **Caching**: Prevents duplicate API calls for the same flow ID
1613
- * - **Promise Caching**: Handles concurrent requests efficiently by caching promises
1614
- * - **Component Resolution**: The `resolve=components` parameter ensures components are fully resolved in a single API call
1615
- *
1616
- * ## Future Enhancements
1617
- *
1618
- * The class structure suggests planned functionality that could be implemented:
1619
- *
1620
- * - **Component Caching**: The commented `components` property indicates potential individual component caching
1621
- * - **Cache Invalidation**: Methods to clear or refresh cached data
1622
- * - **Error Retry Logic**: Automatic retry mechanisms for failed requests
1623
- * - **Batch Operations**: Methods to fetch multiple flows or components in a single request
1624
- *
1443
+ * Supports both v2 (default) and v1 modes:
1444
+ * - v2: Uses /consume endpoint for fetching variants
1445
+ * - v1: Uses /flow endpoint for fetching user flows
1625
1446
  */
1626
1447
  export class CloudRepository {
1627
1448
  private _baseUrl;
1628
1449
  static Main: CloudRepository;
1450
+ private variants;
1629
1451
  private userFlows;
1630
1452
  constructor(_baseUrl?: string);
1631
- fetchComponent(componentId: string, flowId?: string): Promise<import("common").IComponentConfig>;
1453
+ /**
1454
+ * Check if a component is already cached/preloaded (v2)
1455
+ */
1456
+ isPreloaded(componentId: string): boolean;
1457
+ /**
1458
+ * Fetch a v2 component variant
1459
+ */
1460
+ fetchComponentV2(componentId: string, environmentIdentifier?: string): Promise<v2_IVariantConfig>;
1461
+ /**
1462
+ * Fetch a v1 component from a flow
1463
+ */
1464
+ fetchComponentV1(componentId: string, flowId?: string): Promise<import("common").IComponentConfig>;
1632
1465
  fetchAutoFlow(componentId: string): Promise<IUserFlow>;
1633
1466
  fetchFlow(flowId: string): Promise<IUserFlow>;
1467
+ /**
1468
+ * @deprecated Use fetchComponentV2 or fetchComponentV1 explicitly
1469
+ * Defaults to v1 behavior for backward compatibility with existing code
1470
+ */
1471
+ fetchComponent(componentId: string, flowId?: string): Promise<import("common").IComponentConfig>;
1634
1472
  }
1473
+ /**
1474
+ * @deprecated Use CloudRepository instead
1475
+ */
1476
+ export const v2_CloudRepository: typeof CloudRepository;
1635
1477
  }
1636
1478
  declare module "@myop/sdk/helpers/exec" {
1637
1479
  export const exec: (getter: any) => Promise<any>;
1638
1480
  }
1639
- declare module "@myop/sdk/helpers/enableV2" {
1640
- import { v2_IVariantConfig } from "@myop/sdk/common";
1641
- import { loaderOptions } from "@myop/sdk/host/hostSDK";
1642
- export class v2_CloudRepository {
1643
- private _baseUrl;
1644
- static Main: v2_CloudRepository;
1645
- private variants;
1646
- constructor(_baseUrl?: string);
1647
- fetchComponent(componentId: string, environmentIdentifier?: string): Promise<v2_IVariantConfig>;
1648
- }
1649
- export const enableV2: (environmentIdentifier: string, cloudRepository?: v2_CloudRepository) => {
1650
- loadComponent: (componentId: string, container: HTMLElement, options?: loaderOptions) => Promise<import("host").IMyopComponent<any, any>>;
1651
- };
1652
- }
1653
1481
  declare module "@myop/sdk/helpers" {
1654
1482
  export * from "@myop/sdk/helpers/applyStylesheet";
1655
1483
  export * from "@myop/sdk/helpers/iframeSkinUrlTokenizer";
@@ -1657,7 +1485,6 @@ declare module "@myop/sdk/helpers" {
1657
1485
  export * from "@myop/sdk/helpers/configBuilder";
1658
1486
  export * from "@myop/sdk/helpers/CloudRepository";
1659
1487
  export * from "@myop/sdk/helpers/exec";
1660
- export * from "@myop/sdk/helpers/enableV2";
1661
1488
  }
1662
1489
  declare module "@myop/sdk/host/myopOverride" {
1663
1490
  import { IComponentConfig } from "@myop/sdk/common";
@@ -1731,7 +1731,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
1731
1731
  };
1732
1732
 
1733
1733
  // version:myop-sdk-version
1734
- var myop_sdk_version_default = "0.2.3";
1734
+ var myop_sdk_version_default = "0.2.5";
1735
1735
 
1736
1736
  // src/webcomponent/messageHandlers/BaseWebComponentMessageHandler.ts
1737
1737
  var BaseWebComponentMessageHandler = class extends BaseContextMessageHandler {
@@ -2171,12 +2171,46 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
2171
2171
 
2172
2172
  // src/helpers/CloudRepository.ts
2173
2173
  var _CloudRepository = class _CloudRepository {
2174
- // private components: Record<string, Promise<IUserFlow>> = {};
2175
2174
  constructor(_baseUrl = "https://cloud.myop.dev") {
2176
2175
  this._baseUrl = _baseUrl;
2176
+ // v2 cache
2177
+ __publicField(this, "variants", {});
2178
+ // v1 cache
2177
2179
  __publicField(this, "userFlows", {});
2178
2180
  }
2179
- async fetchComponent(componentId, flowId) {
2181
+ // ============ V2 Methods (Default) ============
2182
+ /**
2183
+ * Check if a component is already cached/preloaded (v2)
2184
+ */
2185
+ isPreloaded(componentId) {
2186
+ return componentId in this.variants;
2187
+ }
2188
+ /**
2189
+ * Fetch a v2 component variant
2190
+ */
2191
+ async fetchComponentV2(componentId, environmentIdentifier) {
2192
+ if (!this.variants[componentId]) {
2193
+ this.variants[componentId] = new Promise(
2194
+ async (resolve, reject) => {
2195
+ try {
2196
+ const res = await fetch(
2197
+ "".concat(this._baseUrl, "/consume?id=").concat(componentId, "&env=").concat(environmentIdentifier)
2198
+ );
2199
+ const json = await res.json();
2200
+ resolve(json.item);
2201
+ } catch (e) {
2202
+ reject(e);
2203
+ }
2204
+ }
2205
+ );
2206
+ }
2207
+ return await this.variants[componentId];
2208
+ }
2209
+ // ============ V1 Methods (Legacy) ============
2210
+ /**
2211
+ * Fetch a v1 component from a flow
2212
+ */
2213
+ async fetchComponentV1(componentId, flowId) {
2180
2214
  if (flowId) {
2181
2215
  const flow = await this.fetchFlow(flowId);
2182
2216
  return flow.components.find((c) => c.type.id === componentId);
@@ -2221,38 +2255,18 @@ var _CloudRepository = class _CloudRepository {
2221
2255
  }
2222
2256
  return await this.userFlows[flowId];
2223
2257
  }
2258
+ // ============ Backward Compatibility ============
2259
+ /**
2260
+ * @deprecated Use fetchComponentV2 or fetchComponentV1 explicitly
2261
+ * Defaults to v1 behavior for backward compatibility with existing code
2262
+ */
2263
+ async fetchComponent(componentId, flowId) {
2264
+ return this.fetchComponentV1(componentId, flowId);
2265
+ }
2224
2266
  };
2225
2267
  __publicField(_CloudRepository, "Main", new _CloudRepository());
2226
2268
  var CloudRepository = _CloudRepository;
2227
2269
 
2228
- // src/helpers/enableV2.ts
2229
- var _v2_CloudRepository = class _v2_CloudRepository {
2230
- constructor(_baseUrl = "https://cloud.myop.dev") {
2231
- this._baseUrl = _baseUrl;
2232
- __publicField(this, "variants", {});
2233
- }
2234
- async fetchComponent(componentId, environmentIdentifier) {
2235
- if (!this.variants[componentId]) {
2236
- this.variants[componentId] = new Promise(
2237
- async (resolve, reject) => {
2238
- try {
2239
- const res = await fetch(
2240
- "".concat(this._baseUrl, "/consume?id=").concat(componentId, "&env=").concat(environmentIdentifier)
2241
- );
2242
- const json = await res.json();
2243
- resolve(json.item);
2244
- } catch (e) {
2245
- reject(e);
2246
- }
2247
- }
2248
- );
2249
- }
2250
- return await this.variants[componentId];
2251
- }
2252
- };
2253
- __publicField(_v2_CloudRepository, "Main", new _v2_CloudRepository());
2254
- var v2_CloudRepository = _v2_CloudRepository;
2255
-
2256
2270
  // src/host/myopOverride.ts
2257
2271
  var checkMyopOverride = async (componentConfig) => {
2258
2272
  try {