@myop/cli 0.1.41 → 0.1.42

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/myop-cli.js CHANGED
@@ -1906,7 +1906,7 @@ const $e = (o = !1) => {
1906
1906
  new Fe(),
1907
1907
  ...Et
1908
1908
  ];
1909
- const eo = "0.1.41";
1909
+ const eo = "0.1.42";
1910
1910
  y.program = new ft();
1911
1911
  y.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(eo);
1912
1912
  y.program.addOption(new me("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
@@ -224,10 +224,53 @@ project/
224
224
  | `myop logout` | Clear stored credentials |
225
225
  | `myop whoami` | Show current authenticated user |
226
226
 
227
+ ## Deploying with `myop push`
228
+
229
+ `myop push` uploads the current component HTML to the Myop platform. After a successful push, any CTA wiring (e.g., `myop_cta_handler('button-clicked', …)`) is live in the Myop host — no rebuild or redeploy of the host application is needed.
230
+
231
+ ### What push does
232
+
233
+ 1. Reads `myop.config.json` to identify the component
234
+ 2. Locates the HTML file (`index.html` for single-file mode, `dist/index.html` for multi-file)
235
+ 3. Authenticates with Myop (prompts login if needed)
236
+ 4. Uploads the HTML via a presigned URL
237
+ 5. On first push: assigns a real `componentId` (UUID) and `organization` to `myop.config.json`
238
+ 6. On subsequent pushes: adds a new version to the existing component
239
+
240
+ ### Running push
241
+
242
+ From the component's project directory:
243
+
244
+ ```bash
245
+ myop push
246
+ ```
247
+
248
+ Or using npx (no global install needed):
249
+
250
+ ```bash
251
+ npx @myop/cli push
252
+ ```
253
+
254
+ ### When the user asks to push
255
+
256
+ When the user says **"push to myop"**, **"deploy"**, **"upload"**, or **"run the push"**, you should:
257
+
258
+ 1. `cd` into the component's project directory (where `myop.config.json` lives)
259
+ 2. Run `npx @myop/cli push` via the terminal
260
+ 3. If push succeeds, report the dashboard URL: `https://dashboard.myop.dev/dashboard/2.0/component/<componentId>`
261
+ 4. If push fails, show the error output and suggest the user run the command manually
262
+
263
+ ### Push behavior
264
+
265
+ - **First push** — `componentId` in `myop.config.json` changes from `"DEV"` to a real UUID. The `organization` field is also added. The component now exists on the Myop platform.
266
+ - **Subsequent pushes** — A new version is added to the existing component. The previous version remains accessible. The latest version becomes the live version immediately.
267
+ - **What goes live** — The full HTML file is uploaded as-is. All CTA handlers, type definitions, styles, and preview scripts are included. The host application picks up changes automatically on next load (no host redeploy).
268
+ - **Multi-file projects** — For projects with a build step, run `myop sync` instead (which runs `npm run build` first, then uploads `dist/index.html`).
269
+
227
270
  ## Workflow Summary
228
271
 
229
272
  1. `myop create` - Scaffold a new component
230
273
  2. Edit `index.html` - Build your component UI
231
274
  3. `myop dev` - Preview with hot reload at http://localhost:9292
232
- 4. `myop push` - Upload to Myop platform
275
+ 4. `myop push` - Upload to Myop platform (live immediately)
233
276
  5. View on dashboard: `https://dashboard.myop.dev/dashboard/2.0/component/<componentId>`
@@ -323,35 +323,135 @@ The `<script id="myop_preview">` block provides mock data for development. In pr
323
323
 
324
324
  ## Host-Side Integration
325
325
 
326
- For context on how the host application uses these functions (useful when debugging):
326
+ For context on how the host application consumes these functions in React (useful when debugging or advising host developers):
327
327
 
328
- ```javascript
329
- // React host example using @myop/sdk
330
- import { getHostModule } from '@myop/sdk';
328
+ ### Option 1: Auto-Generated React Package (Recommended)
331
329
 
332
- const { hostSDK } = await getHostModule();
333
- const component = await hostSDK.loadComponent(componentConfig, containerElement);
330
+ Myop auto-generates a fully typed React package for every component. Install it directly:
334
331
 
335
- // Send data to component
336
- component.props.myop_init_interface({
337
- tasks: fetchedTasks
338
- });
332
+ ```bash
333
+ npm install https://cloud.myop.dev/npm/{component-id}/react
334
+ ```
339
335
 
340
- // Listen for component actions
341
- component.props.myop_cta_handler = (action, payload) => {
342
- switch (action) {
343
- case 'task-toggled':
344
- updateTask(payload.taskId, { completed: payload.completed });
345
- break;
346
- case 'task-deleted':
347
- deleteTask(payload.taskId);
348
- break;
349
- case 'size-requested':
350
- resizeContainer(payload);
351
- break;
352
- }
353
- };
336
+ Then import and use it like any React component — with full TypeScript types for `data` and all CTA event payloads:
337
+
338
+ ```tsx
339
+ // Auto-generated package gives you a typed React component
340
+ // e.g. npm install https://cloud.myop.dev/npm/{component-id}/react
341
+ import { TaskList } from "@myop/task-list";
342
+
343
+ function App() {
344
+ const [tasks, setTasks] = useState(fetchedTasks);
345
+
346
+ return (
347
+ <TaskList
348
+ data={{ tasks }}
349
+ onTaskToggled={(payload) => {
350
+ // payload is typed as { taskId: string; completed: boolean }
351
+ updateTask(payload.taskId, { completed: payload.completed });
352
+ }}
353
+ onTaskDeleted={(payload) => {
354
+ // payload is typed as { taskId: string }
355
+ deleteTask(payload.taskId);
356
+ }}
357
+ />
358
+ );
359
+ }
360
+ ```
361
+
362
+ **Why auto-generated packages are preferred:**
363
+ - Fully typed — TypeScript types for `data` and all CTA event payloads are auto-generated
364
+ - Zero configuration — no `componentId` needed, component is loaded automatically
365
+ - Zero bundle impact — the package is a thin typed wrapper (~6KB total for `@myop/react`), actual component loads at runtime
366
+
367
+ ### Option 2: MyopComponent with `data` and `on` Props
368
+
369
+ For cases where you don't want to install a per-component package, use `MyopComponent` directly:
370
+
371
+ ```tsx
372
+ import { MyopComponent } from "@myop/react";
373
+
374
+ function App() {
375
+ const [tasks, setTasks] = useState(fetchedTasks);
376
+
377
+ return (
378
+ <MyopComponent
379
+ componentId="your-component-id"
380
+ data={{ tasks }}
381
+ on={(action, payload) => {
382
+ switch (action) {
383
+ case 'task-toggled':
384
+ updateTask(payload.taskId, { completed: payload.completed });
385
+ break;
386
+ case 'task-deleted':
387
+ deleteTask(payload.taskId);
388
+ break;
389
+ }
390
+ }}
391
+ />
392
+ );
393
+ }
394
+ ```
395
+
396
+ You can also use typed specific handlers alongside the generic `on` handler:
397
+
398
+ ```tsx
399
+ <MyopComponent<TaskData, TaskCtaPayloads>
400
+ componentId="your-component-id"
401
+ data={{ tasks }}
402
+ onTaskToggled={(payload) => {
403
+ updateTask(payload.taskId, { completed: payload.completed });
404
+ }}
405
+ onTaskDeleted={(payload) => {
406
+ deleteTask(payload.taskId);
407
+ }}
408
+ />
409
+ ```
410
+
411
+ ### Key Props
412
+
413
+ | Prop | Type | Description |
414
+ |------|------|-------------|
415
+ | `componentId` | `string` | The Myop component ID (not needed with auto-generated packages) |
416
+ | `data` | `TData` | Data passed to the component via `myop_init_interface` |
417
+ | `on` | `(action, payload) => void` | Generic handler for all CTA events |
418
+ | `on[ActionName]` | `(payload) => void` | Typed handler for a specific CTA (e.g., `onTaskToggled`) |
419
+ | `style` | `CSSProperties` | CSS styles for the container |
420
+ | `environment` | `string` | Load from a specific environment (e.g., `"staging"`) |
421
+ | `preview` | `boolean` | Load the unpublished preview version |
422
+
423
+ ### Preloading Components
424
+
425
+ Preloading fetches and caches component configs before they render, eliminating the network delay when the component mounts. This is useful for components that appear on user navigation or behind tabs — preload them early so they render instantly when needed.
354
426
 
355
- // Read current component state
356
- const currentState = component.props.myop_init_interface();
427
+ ```tsx
428
+ import { preloadComponents, isPreloaded } from "@myop/react";
429
+
430
+ // Preload on app startup or route entry
431
+ await preloadComponents(["component-id-1", "component-id-2"]);
432
+
433
+ // Optionally preload for a specific environment
434
+ await preloadComponents(["component-id-1"], "staging");
435
+
436
+ // Check if a component is already cached
437
+ if (isPreloaded("component-id-1")) {
438
+ console.log("Ready — will render without loading delay");
439
+ }
357
440
  ```
441
+
442
+ **How it works:**
443
+ - `preloadComponents(ids, env?, preview?)` fetches each component config from the Myop cloud and caches it in memory. Uses `Promise.allSettled` so a single failure doesn't block the rest.
444
+ - When `<MyopComponent>` (or an auto-generated component) later mounts with a preloaded ID, it hits the cache and loads instantly — no network request, no loader flash.
445
+ - The cache is keyed by `{componentId}:{environment}:{preview|live}`, so the same component can be preloaded for different environments separately.
446
+ - If no explicit `environment`/`preview` props are passed to the component, it automatically uses the params from the preload call.
447
+
448
+ **When to preload:**
449
+ - App startup — preload components used on the landing page
450
+ - Route transitions — preload components for the next likely page
451
+ - Tab containers — preload all tab contents when the container mounts
452
+
453
+ | Function | Returns | Description |
454
+ |----------|---------|-------------|
455
+ | `preloadComponents(ids, env?, preview?)` | `Promise<PromiseSettledResult[]>` | Fetch and cache component configs ahead of time |
456
+ | `isPreloaded(id, env?, preview?)` | `boolean` | Check if a component is already cached |
457
+ | `getPreloadedParams(id)` | `{ env, preview } \| undefined` | Get the environment/preview params used during preload |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myop/cli",
3
- "version": "0.1.41",
3
+ "version": "0.1.42",
4
4
  "description": "Myop cli",
5
5
  "type": "module",
6
6
  "repository": {