@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.
- package/README.md +368 -208
- package/dist/bundled-declarations.d.ts +27 -200
- package/dist/cjs/{_IframeSDK.c7f71dba.js → _IframeSDK.69b595c4.js} +45 -31
- package/dist/cjs/{_IframeSDK.c7f71dba.js.map → _IframeSDK.69b595c4.js.map} +3 -3
- package/dist/cjs/{_IframeSDK.012474c1.min.js → _IframeSDK.845b6f30.min.js} +1 -1
- package/dist/cjs/_MyopHelpers.3d50ac48.min.js +1 -0
- package/dist/cjs/_MyopHelpers.7baba8b8.js +462 -0
- package/dist/cjs/_MyopHelpers.7baba8b8.js.map +7 -0
- package/dist/cjs/{_WebComponentSDK.93d3959a.js → _WebComponentSDK.38d1c6e7.js} +45 -31
- package/dist/cjs/{_WebComponentSDK.93d3959a.js.map → _WebComponentSDK.38d1c6e7.js.map} +3 -3
- package/dist/cjs/{_WebComponentSDK.15ffefb6.min.js → _WebComponentSDK.a9eff853.min.js} +1 -1
- package/dist/cjs/{_hostSDK.eeb98d7f.js → _hostSDK.083b3333.js} +45 -31
- package/dist/cjs/{_hostSDK.eeb98d7f.js.map → _hostSDK.083b3333.js.map} +3 -3
- package/dist/cjs/{_hostSDK.a852b7b7.min.js → _hostSDK.2a26ea6c.min.js} +1 -1
- 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 +3947 -0
- package/dist/cjs-bundled/myop_sdk.bundled.js.map +7 -0
- package/dist/cjs-bundled/myop_sdk.bundled.min.js +1 -0
- package/dist/module/Iframe/index.js +49 -33
- package/dist/module/Iframe/index.js.map +3 -3
- package/dist/module/SDK.js +52 -120
- package/dist/module/SDK.js.map +3 -3
- package/dist/module/helpers/CloudRepository.d.ts +27 -185
- package/dist/module/helpers/index.d.ts +0 -1
- package/dist/module/helpers/index.js +52 -2521
- package/dist/module/helpers/index.js.map +4 -4
- package/dist/module/host/index.js +49 -33
- package/dist/module/host/index.js.map +3 -3
- package/dist/module/webcomponent/index.js +49 -33
- package/dist/module/webcomponent/index.js.map +3 -3
- package/package.json +1 -1
- package/dist/cjs/_MyopHelpers.75e0fd8d.js +0 -2810
- package/dist/cjs/_MyopHelpers.75e0fd8d.js.map +0 -7
- package/dist/cjs/_MyopHelpers.ecfd80d9.min.js +0 -1
- package/dist/module/helpers/enableV2.d.ts +0 -12
|
@@ -1,196 +1,38 @@
|
|
|
1
|
-
import { IUserFlow } from "../common";
|
|
1
|
+
import { IUserFlow, v2_IVariantConfig } from "../common";
|
|
2
2
|
/**
|
|
3
|
+
* CloudRepository - Unified cloud data access layer for Myop components
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* ## Class Structure
|
|
9
|
-
*
|
|
10
|
-
* ### Constructor
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* constructor(private _baseUrl = 'https://cloud.myop.dev')
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* **Parameters:**
|
|
17
|
-
* - `_baseUrl` (optional): The base URL for the Myop.dev cloud API. Defaults to `'https://cloud.myop.dev'`
|
|
18
|
-
*
|
|
19
|
-
* ### Static Properties
|
|
20
|
-
*
|
|
21
|
-
* #### Main
|
|
22
|
-
* ```typescript
|
|
23
|
-
* static Main = new CloudRepository();
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* A singleton instance of the `CloudRepository` class that can be used throughout the application without creating multiple instances.
|
|
27
|
-
*
|
|
28
|
-
* ### Private Properties
|
|
29
|
-
*
|
|
30
|
-
* #### userFlows
|
|
31
|
-
* ```typescript
|
|
32
|
-
* private userFlows: Record<string, Promise<IUserFlow>> = {};
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* 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.
|
|
36
|
-
*
|
|
37
|
-
* #### _baseUrl
|
|
38
|
-
* ```typescript
|
|
39
|
-
* private _baseUrl: string
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* The base URL for the cloud API endpoints, set during construction.
|
|
43
|
-
*
|
|
44
|
-
* ## Methods
|
|
45
|
-
*
|
|
46
|
-
* ### fetchFlow(flowId: string)
|
|
47
|
-
*
|
|
48
|
-
* Retrieves a complete user flow from the cloud repository, including all resolved components.
|
|
49
|
-
*
|
|
50
|
-
* **Parameters:**
|
|
51
|
-
* - `flowId`: The unique identifier for the user flow to retrieve
|
|
52
|
-
*
|
|
53
|
-
* **Returns:**
|
|
54
|
-
* - `Promise<IUserFlow>`: A promise that resolves to the complete user flow object
|
|
55
|
-
*
|
|
56
|
-
* **Behavior:**
|
|
57
|
-
* - Implements request caching to avoid duplicate API calls for the same flow ID
|
|
58
|
-
* - Makes a GET request to `/flow?id={flowId}&resolve=components`
|
|
59
|
-
* - Automatically resolves component references within the flow
|
|
60
|
-
* - Stores the promise in the cache for future use
|
|
61
|
-
*
|
|
62
|
-
* **Example Usage:**
|
|
63
|
-
* ```typescript
|
|
64
|
-
* const flow = await CloudRepository.Main.fetchFlow('my-flow-id');
|
|
65
|
-
* console.log(flow.components);
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* ### fetchComponent(componentId: string, flowId: string)
|
|
69
|
-
*
|
|
70
|
-
* Retrieves a specific component from within a user flow.
|
|
71
|
-
*
|
|
72
|
-
* **Parameters:**
|
|
73
|
-
* - `componentId`: The unique identifier for the component to retrieve
|
|
74
|
-
* - `flowId`: The unique identifier for the user flow containing the component
|
|
75
|
-
*
|
|
76
|
-
* **Returns:**
|
|
77
|
-
* - `Promise<Component | undefined>`: A promise that resolves to the component object if found, or undefined if not found
|
|
78
|
-
*
|
|
79
|
-
* **Behavior:**
|
|
80
|
-
* - First fetches the complete flow using `fetchFlow()`
|
|
81
|
-
* - Searches through the flow's components array to find the matching component
|
|
82
|
-
* - Uses the component's `type.id` property for matching
|
|
83
|
-
*
|
|
84
|
-
* **Example Usage:**
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const component = await CloudRepository.Main.fetchComponent('button-component', 'my-flow-id');
|
|
87
|
-
* if (component) {
|
|
88
|
-
* console.log('Component found:', component);
|
|
89
|
-
* } else {
|
|
90
|
-
* console.log('Component not found in flow');
|
|
91
|
-
* }
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* ## API Integration
|
|
95
|
-
*
|
|
96
|
-
* ### Endpoint Structure
|
|
97
|
-
*
|
|
98
|
-
* The class integrates with the following Myop.dev cloud API endpoint:
|
|
99
|
-
*
|
|
100
|
-
* ```
|
|
101
|
-
* GET {baseUrl}/flow?id={flowId}&resolve=components
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* **Query Parameters:**
|
|
105
|
-
* - `id`: The flow identifier
|
|
106
|
-
* - `resolve=components`: Instructs the API to include resolved component data in the response
|
|
107
|
-
*
|
|
108
|
-
* ### Response Format
|
|
109
|
-
*
|
|
110
|
-
* The API is expected to return a JSON response with the following structure:
|
|
111
|
-
*
|
|
112
|
-
* ```json
|
|
113
|
-
* {
|
|
114
|
-
* "item": {
|
|
115
|
-
* // IUserFlow object with resolved components
|
|
116
|
-
* "components": [
|
|
117
|
-
* {
|
|
118
|
-
* "type": {
|
|
119
|
-
* "id": "component-id"
|
|
120
|
-
* }
|
|
121
|
-
* // ... other component properties
|
|
122
|
-
* }
|
|
123
|
-
* ]
|
|
124
|
-
* // ... other flow properties
|
|
125
|
-
* }
|
|
126
|
-
* }
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* ## Caching Strategy
|
|
130
|
-
*
|
|
131
|
-
* The `CloudRepository` implements a promise-based caching mechanism:
|
|
132
|
-
*
|
|
133
|
-
* 1. **Cache Key**: Flow ID is used as the cache key
|
|
134
|
-
* 2. **Cache Value**: Promises are cached rather than resolved values to handle concurrent requests
|
|
135
|
-
* 3. **Cache Duration**: Cache persists for the lifetime of the repository instance
|
|
136
|
-
* 4. **Cache Invalidation**: No automatic cache invalidation is implemented
|
|
137
|
-
*
|
|
138
|
-
* ## Error Handling
|
|
139
|
-
*
|
|
140
|
-
* - Network errors and API failures are propagated through promise rejection
|
|
141
|
-
* - No specific error handling or retry logic is implemented at the repository level
|
|
142
|
-
* - Consumers should implement appropriate error handling when calling repository methods
|
|
143
|
-
*
|
|
144
|
-
* ## Usage Patterns
|
|
145
|
-
*
|
|
146
|
-
* ### Singleton Access
|
|
147
|
-
* ```typescript
|
|
148
|
-
* import { CloudRepository } from './path/to/CloudRepository';
|
|
149
|
-
*
|
|
150
|
-
* // Use the singleton instance
|
|
151
|
-
* const flow = await CloudRepository.Main.fetchFlow('flow-id');
|
|
152
|
-
* ```
|
|
153
|
-
*
|
|
154
|
-
* ### Custom Instance
|
|
155
|
-
* ```typescript
|
|
156
|
-
* // Create a custom instance with different base URL
|
|
157
|
-
* const customRepo = new CloudRepository('https://custom-api.example.com');
|
|
158
|
-
* const flow = await customRepo.fetchFlow('flow-id');
|
|
159
|
-
* ```
|
|
160
|
-
*
|
|
161
|
-
* ### Component Retrieval
|
|
162
|
-
* ```typescript
|
|
163
|
-
* // Get a specific component from a flow
|
|
164
|
-
* const component = await CloudRepository.Main.fetchComponent('component-id', 'flow-id');
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* ## Dependencies
|
|
168
|
-
*
|
|
169
|
-
* - **IUserFlow**: Interface imported from `../common` that defines the structure of user flow objects
|
|
170
|
-
* - **Fetch API**: Uses the native `fetch` function for HTTP requests
|
|
171
|
-
*
|
|
172
|
-
* ## Performance Considerations
|
|
173
|
-
*
|
|
174
|
-
* - **Caching**: Prevents duplicate API calls for the same flow ID
|
|
175
|
-
* - **Promise Caching**: Handles concurrent requests efficiently by caching promises
|
|
176
|
-
* - **Component Resolution**: The `resolve=components` parameter ensures components are fully resolved in a single API call
|
|
177
|
-
*
|
|
178
|
-
* ## Future Enhancements
|
|
179
|
-
*
|
|
180
|
-
* The class structure suggests planned functionality that could be implemented:
|
|
181
|
-
*
|
|
182
|
-
* - **Component Caching**: The commented `components` property indicates potential individual component caching
|
|
183
|
-
* - **Cache Invalidation**: Methods to clear or refresh cached data
|
|
184
|
-
* - **Error Retry Logic**: Automatic retry mechanisms for failed requests
|
|
185
|
-
* - **Batch Operations**: Methods to fetch multiple flows or components in a single request
|
|
186
|
-
*
|
|
5
|
+
* Supports both v2 (default) and v1 modes:
|
|
6
|
+
* - v2: Uses /consume endpoint for fetching variants
|
|
7
|
+
* - v1: Uses /flow endpoint for fetching user flows
|
|
187
8
|
*/
|
|
188
9
|
export declare class CloudRepository {
|
|
189
10
|
private _baseUrl;
|
|
190
11
|
static Main: CloudRepository;
|
|
12
|
+
private variants;
|
|
191
13
|
private userFlows;
|
|
192
14
|
constructor(_baseUrl?: string);
|
|
193
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Check if a component is already cached/preloaded (v2)
|
|
17
|
+
*/
|
|
18
|
+
isPreloaded(componentId: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Fetch a v2 component variant
|
|
21
|
+
*/
|
|
22
|
+
fetchComponentV2(componentId: string, environmentIdentifier?: string): Promise<v2_IVariantConfig>;
|
|
23
|
+
/**
|
|
24
|
+
* Fetch a v1 component from a flow
|
|
25
|
+
*/
|
|
26
|
+
fetchComponentV1(componentId: string, flowId?: string): Promise<import("../common").IComponentConfig>;
|
|
194
27
|
fetchAutoFlow(componentId: string): Promise<IUserFlow>;
|
|
195
28
|
fetchFlow(flowId: string): Promise<IUserFlow>;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use fetchComponentV2 or fetchComponentV1 explicitly
|
|
31
|
+
* Defaults to v1 behavior for backward compatibility with existing code
|
|
32
|
+
*/
|
|
33
|
+
fetchComponent(componentId: string, flowId?: string): Promise<import("../common").IComponentConfig>;
|
|
196
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use CloudRepository instead
|
|
37
|
+
*/
|
|
38
|
+
export declare const v2_CloudRepository: typeof CloudRepository;
|