@widgetic/ui-sdk 0.1.9 → 0.1.11

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/modules/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @widgetic/ui-sdk-modules
2
2
 
3
- The heavy UI modules a partner mounts into its own page: the **File Browser**, the **composition editor** and the AI
4
- **widget creator**. Each module is **one self-contained ES module file** (`dist/<name>/index.js`) that brings its own Svelte,
3
+ The UI modules a partner mounts into its own page: the **File Browser**, the **composition editor**, the AI
4
+ **widget creator** and **Workflows**. Each module is **one self-contained ES module file** (`dist/<name>/index.js`) that brings its own Svelte,
5
5
  design system and CSS, and draws inside a **shadow root**, so the partner's CSS cannot restyle it and its CSS cannot
6
6
  touch the partner's page. The only other files are a few **lazy files** next to it (`dist/<name>/chunks/`): pdf.js and
7
7
  its worker, which only a visitor who previews a PDF needs (see "One file, and the parts that are not in it").
@@ -213,7 +213,9 @@ away. `correlationId` is what Widgetic's support needs to find the request.
213
213
 
214
214
  Methods (on `editor.module` when you mounted it with the SDK): `save()` saves what is unsaved now, `flush()` saves
215
215
  everything and waits, both resolving `true` when nothing is left unsaved; `isDirty()`; `reload()` loads the composition
216
- again (unsaved edits are lost); `setTheme(theme)` (see "Looking like your product"); `setLanguage({ locale?, messages? })`, and
216
+ again (unsaved edits are lost); `adoptEmbedSettings(settings)` for a page that saves the composition's `embedSettings` itself
217
+ (call it after `await flush()`, with the settings the API now holds, so a later save of the editor does not put the old ones
218
+ back; nothing becomes unsaved); `adoptName(name)` for a page that renames the composition itself (same use); `setTheme(theme)` (see "Looking like your product"); `setLanguage({ locale?, messages? })`, and
217
219
  `CompositionEditorModule.defaultMessages` and `checkMessages(messages)`, which are also on the instance (see "Speaking your
218
220
  visitors' language").
219
221
 
@@ -378,11 +380,108 @@ only the API's origin (connections, pictures and frames), `data:` fonts and `dat
378
380
  **One creator per page.** Its chat, its file lists and its user are stores of the whole page, so a second `mount()` is
379
381
  refused with a message that says so; unmount the first one before mounting another.
380
382
 
383
+ ## Using the Workflows module
384
+
385
+ The page where a team builds **workflows**: a set of compositions, and the filters between them that decide which
386
+ composition an embed shows next. It is for team accounts and partners (the API refuses any other workspace and the screen
387
+ says so). What an embed does on its own page (how and when it appears) belongs to the Embed SDK and stays there: a
388
+ workflow only decides **which composition** the embed shows, and the Embed SDK follows it from the tag
389
+ (`<widgetic workflow-id="..." composition-id="...">`). The screen is the package `@widgetic/workflows` (its own repository,
390
+ `widgeticai/Frontend/workflows`, which has the screen's README and `__docs/concepts.md`: what a workflow is and why); the
391
+ module gives it a shadow root, a theme, a language, a session and a way to tell your page what happened.
392
+
393
+ **What the screen does.** The list of the workspace's workflows (search by name, show or hide the archived ones, order by
394
+ name, date created, last published or visitors, new workflow, duplicate, delete) and, when one is opened, the editor: a
395
+ canvas of Composition, Trigger and Condition blocks that go forward only (up to 25), a side panel for the selected block,
396
+ a draft that is saved while you work, publish and discard, a history of versions that never change, a Test run that plays a
397
+ visitor through the draft, a Runs tab with how many visitors went through each block, and a Settings tab (time zone, embed
398
+ code, pause, archive, duplicate, delete). A trigger is enabled for a composition only when its widget can supply it (values a
399
+ visitor adds need a Pro widget that keeps data); the reason is told next to the choice. The package's README lists it all.
400
+
401
+ ```js
402
+ import { mountModule } from '@widgetic/ui-sdk';
403
+
404
+ const workflows = await mountModule('workflows', {
405
+ container: '#workflows', // give it a height: it fills its container, and scrolls inside it when that is short
406
+ workspaceId: 'personal', // or the id of an organization
407
+ getToken: async ({ reason }) => (await fetch(`/my-server/widgetic-token?reason=${reason}`)).text(),
408
+ workflowId: workflowOfTheAddress(), // optional: the workflow to open first; leave it out for the list
409
+ theme: 'light',
410
+ on: {
411
+ ready: () => {},
412
+ openWorkflow: ({ workflowId }) => history.pushState(null, '', workflowId ? `/workflows/${workflowId}` : '/workflows'),
413
+ showEmbedCode: ({ workflowId }) => showMyEmbedCodeDialog(workflowId),
414
+ error: ({ message, code, fatal }) => report(code, message),
415
+ },
416
+ });
417
+
418
+ // The page owns where the person is: when it moves (the back button), tell the screen
419
+ window.addEventListener('popstate', () => workflows.module.setWorkflow(workflowOfTheAddress()));
420
+ ```
421
+
422
+ | Option | What it does |
423
+ | --- | --- |
424
+ | `container` | The element the screen fills (it needs a height). |
425
+ | `workspaceId` | **Required.** `personal`, or the id of the organization whose workflows are shown and edited. |
426
+ | `getToken` | **Required**, and the same as for the other modules: `getToken({ reason })` resolves with a token the API accepts for the workspace's workflows, bare or as `{ token, expiresAt }`. It must be the token of a **signed-in person who may work in that workspace** (a member of the team, or the partner's own account), the way the Widgetic site calls the API: an *editor session* minted for one of a partner's customers is refused on these routes (`403`), because an editor session may call only what its allow-list names and workflows are not on it. It is called once before the screen appears (a `getToken` that fails fails the mount), and again when the token is about to run out or the API refuses it (`reason: 'expired'`, once per refusal). |
427
+ | `apiUrl` | The API origin (`https://api.widgetic.com` unless you run your own). |
428
+ | `workflowId` | The workflow to open first. Leave it out for the list. After mounting the screen moves by itself (and says so with `openWorkflow`); `setWorkflow` moves it from the page. |
429
+ | `theme`, `themeFromHost` | The colours, the corners and the typeface ("Looking like your product"). |
430
+ | `locale`, `messages` | The language ("Speaking your visitors' language"). |
431
+
432
+ **What it tells the page.** `ready`, with no payload, once the screen is drawn. `openWorkflow` `{ workflowId }`: the person
433
+ opened a workflow, or went back to the list (`workflowId: null`), so the page can keep its address in step.
434
+ `showEmbedCode` `{ workflowId }`: the person asked for the tag of a workflow. The page shows it, because it knows how the tag
435
+ is built for its Embed SDK; the screen has the button **only when something listens for this event at the moment it
436
+ mounts**. `error` `{ message, code?, fatal }`: `fatal: true` when it could not start (`mount()` rejects as well, and the
437
+ console says `[widgetic-ui] Workflows failed to start:` with the cause), and `fatal: false` for `RENDER_FAILED` (a part of
438
+ the screen could not be drawn: the rest stays and the visitor is offered "Try again" in its place), `REQUEST_FAILED` (a
439
+ request to the API failed: the screen tells the person by itself), `SESSION_ENDED` (the API no longer accepts the token
440
+ `getToken` gives) and `TOKEN_REFRESH_FAILED`. The events are not typed in the SDK yet (see "Known gaps of Workflows").
441
+
442
+ **What it puts on your page.** What every module does, and nothing else: one `<widgetic-ui-module>` in your container and
443
+ the namespaced `<style>` of font rules in `<head>`. Its menus, dialogs and the canvas's own pieces stay inside the shadow
444
+ root (nothing is appended to your `<body>`). It adds nothing to your `window` but Svelte's own version marker (`__svelte`,
445
+ as in every module), and writes nothing to your storage, cookies or address bar.
446
+
447
+ **What it needs from your page.** A container with a height, a `getToken`, and a workspace. Under a strict
448
+ Content-Security-Policy: **scripts from the CDN, inline styles and `data:` fonts, the API for requests, and the CDN for the
449
+ thumbnails of compositions**, nothing else: `default-src 'none'; script-src 'self' https://cdn.widgetic.com;
450
+ connect-src https://api.widgetic.com; style-src 'unsafe-inline'; font-src data:; img-src https://cdn.widgetic.com` (see the
451
+ policy in the SDK's README). No `frame-src`, `worker-src`, inline script or `eval`. The pictures come from where the API's
452
+ answer says (`thumbnailUrl`), which is the CDN. `e2e/workflowsModule.spec.ts` opens the screen under this policy with the
453
+ harness's own origins in place of the CDN and the API, and `e2e/workflowsEditor.spec.ts` draws the canvas and its pictures
454
+ under a strict one: both fail on a violation.
455
+
456
+ **How it is built.** `src/workflows/` has `index.ts` (the module), `WorkflowsHost.svelte` (what the module mounts),
457
+ `language.ts`, `localePackLoad.ts`, `module.css` and `CHANGELOG.md`. The screen is the package `@widgetic/workflows`
458
+ (which bundles `@widgetic/workflows-engine` and the canvas library `kaykay`, pinned to one exact version). It bundles
459
+ neither pdf.js nor the rich text editor, so it needs none of the patches the other modules apply to those packages
460
+ (`packagePatches: []`), and the swaps of the design system's files that work inside a shadow root apply to whatever it
461
+ imports (`MODULES` says `overridesMayGoUnused: true`, so the build does not fail when a swap goes unused). Its `module.css`
462
+ imports `FileBrowser.css` for the theme tokens a module has to own (`--primary`, `--radius` ...): without them a page that
463
+ sets `:root { --primary: yellow }` repaints the module. It also reads the text colour of a main button from the theme
464
+ (`--wg-on-primary`), so a light brand colour keeps dark words.
465
+
466
+ **What the tests check.** `tests/workflowsModule.test.ts` for the module's logic. On the hostile page
467
+ (`harness/workflows.html`, with the mock API of `harness/mockWorkflows.mjs`; `?theme=`, `?themeFromHost=1`, `?height=`,
468
+ `?mount=no`, `?locale=`, `?messages=`, `?pseudo=1`, `?workflow=`, `?workspace=`, `?embedCode=yes`, `?lifetime=`):
469
+ `e2e/workflowsModule.spec.ts` (the page is not touched and nothing is left behind, the requests it makes, the
470
+ Content-Security-Policies, how well the text reads in four looks), `e2e/workflowsEditor.spec.ts` (the list and its
471
+ questions to the API, opening and making a workflow, the canvas drawn among the page's own CSS, adding and connecting
472
+ blocks with a real mouse drag, publishing with its `Idempotency-Key` and revision, the Runs counts, the version history,
473
+ and that taking the screen away in the middle of an edit leaves nothing behind),
474
+ `e2e/workflowsLanguage.spec.ts` (the pseudo language: every word a visitor can read is a message; `messages`,
475
+ `setLanguage`, `checkMessages`) and `e2e/workflowsRtl.spec.ts` (the screen, its list and its editor mirrored for
476
+ `locale: 'ar'` without a word of Arabic, and not decided by the page's own direction). The themes matrix
477
+ (`e2e/themes.spec.ts`) and the React page (`e2e/reactPage.spec.ts`) run it too, and `e2e/sdkLoader.spec.ts` checks that the
478
+ theme the page sets through the SDK reaches it.
479
+
381
480
  ## Looking like your product (themes)
382
481
 
383
482
  Every module takes a `theme`. It changes **colours, the roundness of corners and the typeface**, never the layout or the
384
483
  controls, so a page with a design system of its own can have the modules match it. Each module has its own theme: the File
385
- Browser, the composition editor and the widget creator can look the same or different.
484
+ Browser, the composition editor, the widget creator and Workflows can look the same or different.
386
485
 
387
486
  ```js
388
487
  const editor = await mountModule('composition-editor', {
@@ -495,17 +594,17 @@ editor.setTheme({ radius: 'none' }); // one module alone
495
594
  theme the creator's greys are Tailwind's own, never more than 4 of 255 from what they were in a colour channel. The
496
595
  console says what stays light when a creator gets a dark theme. The File Browser and the composition editor follow a dark
497
596
  theme.
498
- - **No layout and no icons.** Components and spacing are Widgetic's. The words of the File Browser, the composition editor and the widget creator can be changed (see "Speaking your visitors' language").
597
+ - **No layout and no icons.** Components and spacing are Widgetic's. The words of the File Browser, the composition editor, the widget creator and Workflows can be changed (see "Speaking your visitors' language").
499
598
  - **Only colours the module can read as they are** (see "Writing a colour"): no CSS variables, and no gradient or image for a colour.
500
599
  - The old `ThemeConfig` object (`{ mode, colors: { secondary, surface, text }, spacing }`) is no longer accepted by `theme`: it never
501
600
  changed anything in a module. Use the settings above.
502
601
 
503
602
  ## Speaking your visitors' language
504
603
 
505
- The **File Browser**, the **composition editor** and the **widget creator** can speak your visitors' language. Every word
506
- they show is a *message* with a key: your page hands over the words it wants to change and every key it leaves out stays
507
- English, so a language can be added one screen at a time. The examples below are the File Browser's; "The composition
508
- editor" and "The widget creator" say what is different.
604
+ The **File Browser**, the **composition editor**, the **widget creator** and **Workflows** can speak your visitors'
605
+ language. Every word they show is a *message* with a key: your page hands over the words it wants to change and every key
606
+ it leaves out stays English, so a language can be added one screen at a time. The examples below are the File Browser's;
607
+ "The composition editor", "The widget creator" and "Workflows" say what is different.
509
608
 
510
609
  ```js
511
610
  const files = await mountModule('file-browser', {
@@ -524,12 +623,12 @@ files.setLanguage({ locale: 'de', messages: germanMessages }); // later, while i
524
623
 
525
624
  | Option | |
526
625
  | --- | --- |
527
- | `locale` | A BCP 47 language tag (`de`, `pt-BR`). It decides the plural rules and how numbers, dates ("2 days ago") and file sizes are written, through `Intl`. When a **translation pack** exists for the tag (see below), the module loads it as a lazy file next to `index.js` and applies those words before your `messages`. A tag with no pack keeps English for words; plural rules and direction still follow `locale`. Blank or left out is English. It is also the `lang` of the module's elements (a screen reader says the words in that language), and a language that is written right to left (`ar`, `he`, `fa`, `ur` ...) turns the whole screen of the File Browser, the composition editor and the widget creator around: see "Right to left". `new WidgeticUI({ locale })` hands it to every module of the page. |
626
+ | `locale` | A BCP 47 language tag (`de`, `pt-BR`). It decides the plural rules and how numbers, dates ("2 days ago") and file sizes are written, through `Intl`. When a **translation pack** exists for the tag (see below), the module loads it as a lazy file next to `index.js` and applies those words before your `messages`. A tag with no pack keeps English for words; plural rules and direction still follow `locale`. Blank or left out is English. It is also the `lang` of the module's elements (a screen reader says the words in that language), and a language that is written right to left (`ar`, `he`, `fa`, `ur` ...) turns the whole screen of the File Browser, the composition editor, the widget creator and Workflows around: see "Right to left". `new WidgeticUI({ locale })` hands it to every module of the page. |
528
627
  | `messages` | The words you want to change, `{ 'action.cancel': 'Anuluj', ... }`. A key you leave out stays English. |
529
628
  | `selectLabel` | The text of the button that hands the pick to your page, for a page that only wants to rename that one button (default "Select"). `messages['action.addToEditor']` does the same and wins when both are given. |
530
629
  | `setLanguage({ locale?, messages? })` | On the handle (`files.setLanguage`) and on a module you made yourself. Changes the language at once, while the module is on screen or before `mount()`. A value the call leaves out keeps what it was. `messages` it gives **replace** all the earlier ones: a page that switches from German to French passes the French only, and `setLanguage({ locale: '', messages: {} })` goes back to English. `null` counts as "not said". When `locale` changes, the module loads the matching pack (if any) and applies it in one step; two quick calls end in the language of the last call. |
531
630
 
532
- **Translation packs (shipped languages).** Each pack is one lazy file next to `index.js` (gzip budget per pack: File Browser **5 kB**, composition editor **9 kB**, widget creator **28 kB**; the build fails when a pack grows past its module's budget). **Twelve** languages ship today as lazy JSON packs on the CDN: the eight left-to-right ones (`fr`, `de`, `es`, `pt-BR`, `nl`, `da`, `sv`, `zh-CN`) and four right-to-left ones (`ar`, `he`, `fa`, `ur`; Hebrew also answers to the legacy tag `iw`). Every pack is **provisional** until a native speaker has reviewed it. Each module exposes `Module.supportedLocales` (the list above) and `Module.localePackStatus(tag)` (`'provisional' | 'reviewed' | null`). Master files for translators live in `modules/locales/<tag>.json` (union of all keys); the build splits them into one pack per module. Missing keys in a pack fall back to English. **Merge order:** pack → module English shortcuts (`selectLabel`, `presetLabels`, the File Browser's "Select" / "Files selected" toasts) → your `messages` (your page always wins). **Fallback examples:** `pt-PT` and `pt` → `pt-BR` pack; `fr-CA` → `fr`; `zh` / `zh-Hans` / `zh-SG` → `zh-CN`; `zh-TW` / `zh-Hant` → no pack (English words, Simplified is not used); `ar-SA`, `ar-EG` → `ar`; `he-IL` and `iw` → `he`; `fa-IR`, `fa-AF` → `fa`; `ur-PK`, `ur-IN` → `ur`; `en*` → no pack; unknown tag → English (no console line). A pack file that fails to load is reported once in the console; the module keeps working in English. On `mount()`, the module waits for the pack in parallel with its session token so the first paint can be in the pack language when the file arrives in time. Commands: `npm run locales:export-english`, `locales:import-shopify`, `locales:coverage`. Report a wrong translation to Widgetic support with the module name, `locale`, message key and what you expected.
631
+ **Translation packs (shipped languages).** Each pack is one lazy file next to `index.js` (gzip budget per pack: File Browser **5 kB**, composition editor **9 kB**, widget creator **28 kB**, Workflows **9 kB**; the build fails when a pack grows past its module's budget). **Twelve** languages ship today as lazy JSON packs on the CDN: the eight left-to-right ones (`fr`, `de`, `es`, `pt-BR`, `nl`, `da`, `sv`, `zh-CN`) and four right-to-left ones (`ar`, `he`, `fa`, `ur`; Hebrew also answers to the legacy tag `iw`). Every pack is **provisional** until a native speaker has reviewed it. Each module exposes `Module.supportedLocales` (the list above) and `Module.localePackStatus(tag)` (`'provisional' | 'reviewed' | null`). Master files for translators live in `modules/locales/<tag>.json` (union of all keys, with the 390 of Workflows); the build splits them into one pack per module. Missing keys in a pack fall back to English. **Merge order:** pack → module English shortcuts (`selectLabel`, `presetLabels`, the File Browser's "Select" / "Files selected" toasts) → your `messages` (your page always wins). **Fallback examples:** `pt-PT` and `pt` → `pt-BR` pack; `fr-CA` → `fr`; `zh` / `zh-Hans` / `zh-SG` → `zh-CN`; `zh-TW` / `zh-Hant` → no pack (English words, Simplified is not used); `ar-SA`, `ar-EG` → `ar`; `he-IL` and `iw` → `he`; `fa-IR`, `fa-AF` → `fa`; `ur-PK`, `ur-IN` → `ur`; `en*` → no pack; unknown tag → English (no console line). A pack file that fails to load is reported once in the console; the module keeps working in English. On `mount()`, the module waits for the pack in parallel with its session token so the first paint can be in the pack language when the file arrives in time (Workflows waits for the token and the pack both before it draws anything, so its first paint is always in the language). Commands: `npm run locales:export-english`, `locales:import-shopify`, `locales:coverage`. Report a wrong translation to Widgetic support with the module name, `locale`, message key and what you expected.
533
632
 
534
633
  **`action.addToEditor` vs Shopify.** The confirm button of the file picker is the message `action.addToEditor`. In these modules its English text is **Select** (`selectLabel` is a shortcut for the same key; `messages` wins over both). Packs seeded from the Shopify app's File Browser used Shopify's wording ("Add to Editor") for that key; the import script replaces it with Select in each language. There is no separate `action.select` key in the module catalogs (Shopify's JSON may list `action.select` for another button).
535
634
 
@@ -570,7 +669,7 @@ the module's English), not "Added 2 files to the editor", which is a sentence ab
570
669
  `locale: 5` throws a `TypeError` that names the option. `setLanguage` throws it itself and changes nothing; in
571
670
  `mountModule` it comes as a `ModuleMountError` (`MOUNT_FAILED`) with the `TypeError` as its `cause`.
572
671
 
573
- **Right to left.** Each of the three modules is read the way its `locale` is. For a language that is written right to left
672
+ **Right to left.** Each of the four modules is read the way its `locale` is. For a language that is written right to left
574
673
  (Arabic, Hebrew, Persian, Urdu and the others: the script of the language decides, not a list, so `ar-Latn` stays left to
575
674
  right) the whole screen turns around and starts a line on the right. `setLanguage({ locale: 'ar' })` turns a module that is
576
675
  on screen around, and `setLanguage({ locale: 'de' })` turns it back, with no new mount.
@@ -596,6 +695,14 @@ await mountModule('file-browser', { container: '#media', getToken, locale: 'ar'
596
695
  start, the title of a widget in its panel keeps the room it needs, and the pop-up of the brand kit hangs from the
597
696
  start edge of its button. The composition editor and the File Browser inside the creator are turned around the same
598
697
  way.
698
+ - **Workflows:** everything is placed by the start and the end of the line (the package's `tests/workflows-direction.test.mjs`
699
+ fails on a physical side), so the list, the top bar of the editor, the tabs, the side panel, the menus and the dialogs
700
+ mirror as a whole. **The canvas is the exception:** a workflow is read from its first block forward, so it is drawn left to
701
+ right in every language (`dir="ltr"` on it) and the lines run from the block on the left to the next one on its right.
702
+ Every element that names a direction says `rtl` outside the canvas (a library's own `dir` cannot put the screen back). A
703
+ page that calls `setLanguage` turns it around and back with no new mount, and `e2e/workflowsRtl.spec.ts` checks all of
704
+ this with `locale: 'ar'` and the English words as `messages` (they win over the Arabic pack, so the same text is laid out
705
+ both ways and a box can be compared to its mirror), because `locale` decides.
599
706
  - **What a visitor types** (a text field or the tags of the editor, the chat, a text in the quick edit of the creator) is
600
707
  read by its own first letter on a right to left screen: a sentence in Latin letters is set from the left and one in
601
708
  Arabic from the right, side by side. A field with nothing in it yet has no first letter, so it takes the direction of
@@ -739,8 +846,34 @@ creator.setLanguage({ locale: 'de', messages: germanMessages }); // every screen
739
846
  right to left, as the composition editor's is (see "Right to left" above); the canvas board, the live previews and the
740
847
  code stay left to right.
741
848
 
849
+ **Workflows.** It takes the same `locale`, `messages`, `setLanguage`, `defaultMessages` and `checkMessages`, with **one**
850
+ `messages` object for all of it: its 390 `workflows.` keys (the list, the editor and its panels, the names of blocks,
851
+ operators and units, what the engine finds wrong with a workflow, what a failed request means, and the words of the screen
852
+ that says a part could not be drawn). The words of a block are made of parts the screen puts together (`{field} {value}`,
853
+ `{count, plural, ...}`), so a language that puts them in another order can say so in its own message.
854
+
855
+ - **It speaks the twelve languages of the other modules.** `Workflows.supportedLocales` lists them (`fr`, `de`, `es`,
856
+ `pt-BR`, `nl`, `da`, `sv`, `zh-CN`, `ar`, `he`, `fa`, `ur`) and `Workflows.localePackStatus(tag)` is `'provisional'` for
857
+ each: a `locale` that has a pack fetches one lazy file of 390 messages (26 to 37 kB, 7 to 8 kB gzipped; the budget is
858
+ 9 kB gzipped), and `mount()` waits for it, so the first paint is already in that language. A `locale` with no pack
859
+ (English, `zh-TW`, an unknown tag) downloads nothing and says nothing in the console: the words stay English, while the
860
+ plural rules and the direction follow `locale` either way. Your `messages` win over the pack, key by key. The packs are
861
+ machine translations written from the English words (Workflows has no Shopify base to start from) and no native speaker
862
+ has read them yet; Arabic, Hebrew, Persian and Urdu put the technical words of a rule (a table, a column) between
863
+ left-to-right marks so they read in order, and Urdu puts a rule's parts in the order its sentence needs. They are built
864
+ like the other modules': `workflows` is in `MODULES` of `scripts/locales/lib/constants.mjs`, its keys are in
865
+ `locales/module-keys.json`, `src/workflows/localePackLoad.ts` fetches them and its budget is in
866
+ `LOCALE_PACK_MAX_GZIP_BYTES` in `scripts/lib/bundleBudget.mjs`. When the words of the screen change: change them in
867
+ `@widgetic/workflows`, run `npm run locales:export-english`, give the new keys a text in each of the twelve
868
+ `locales/<tag>.json` (`npm run locales:coverage` shows what is missing), and run `npm run locales:prepare-packs`.
869
+ - **A mistake never breaks the screen.** A key that does not exist (the console says which one you probably meant), a text
870
+ that is not a string or cannot be read: each is said once in the console as `[Workflows] ...` and the English text is
871
+ used. Only a *wrong shape* throws, naming the option (`messages: 'Abbrechen'`, `locale: 5`).
872
+ - **What stays as it is.** The `message` of its `error` events (use `code`).
873
+
742
874
  The page that makes sure of the first point is `harness/hostile.html?library=host&pseudo=1` (for the composition editor,
743
- `harness/composition-editor.html?pseudo=1`, for the widget creator `harness/widget-creator.html?pseudo=1`), which gives the module a `messages` object holding **every** default message
875
+ `harness/composition-editor.html?pseudo=1`, for the widget creator `harness/widget-creator.html?pseudo=1`, for Workflows
876
+ `harness/workflows.html?pseudo=1`), which gives the module a `messages` object holding **every** default message
744
877
  wrapped in marks (`Delete` becomes `⟦Delete⟧`): anything a visitor can read that has no marks is English the module wrote
745
878
  itself, which no `messages` could ever translate. The same trick works on your own page.
746
879
 
@@ -749,9 +882,9 @@ itself, which no `messages` could ever translate. The same trick works on your o
749
882
  | Command | What it does |
750
883
  | --- | --- |
751
884
  | `npm install` | Installs, then `patch-package` applies each file in `patches/` (none at the moment: see "Workarounds, and when to delete each"). A patch that no longer applies stops the install in the pipeline, where `patch-package` turns `--error-on-fail` on by itself; on your machine it prints the error and exits 0 |
752
- | `npm run build` / `npm run build:file-browser` / `npm run build:composition-editor` / `npm run build:widget-creator` | Builds `dist/<name>/index.js` and the lazy files in `dist/<name>/chunks/` (+ hidden source maps: no file points at them), prints the size, and fails when a file imports another to start, when it is over its budget or holds a script in a `data:` URL (see "Size budget" and "One file, and the parts that are not in it"). `npm run build` builds the three modules **one process each** (`scripts/lib/buildPlan.mjs`): the CSS compiler keeps what it learned in one build for the next, so the third module of a single process (widget-creator) came out with rules for the composition editor's classes and in another order than the file that is live, which a hand publish builds alone. Every process gets the flags of the first, the 6 GB heap that `npm run build` sets (`--max-old-space-size=6144`, the same as the pipeline's build job): at Node's default of about 4 GB the third module of one process used to stop with `JavaScript heap out of memory`, and one module alone fits (peak about 3.2 GB), so the `build:<name>` scripts need no flag |
753
- | `npm test` | Unit tests (vitest): token source, session token provider, emitter, picked files, shadow mount, the composition editor and widget creator modules, the creator's route list, CSS transforms, fonts, the publishing rules, the R2 store, the release plan and the two scripts of the release pipeline |
754
- | `npm run harness` | Serves `harness/hostile.html`, `harness/composition-editor.html`, `harness/widget-creator.html` and a mock Widgetic API on http://localhost:5290 |
885
+ | `npm run build` / `npm run build:file-browser` / `npm run build:composition-editor` / `npm run build:widget-creator` / `npm run build:workflows` | Builds `dist/<name>/index.js` and the lazy files in `dist/<name>/chunks/` (+ hidden source maps: no file points at them), prints the size, and fails when a file imports another to start, when it is over its budget or holds a script in a `data:` URL (see "Size budget" and "One file, and the parts that are not in it"). `npm run build` builds the four modules **one process each** (`scripts/lib/buildPlan.mjs`): the CSS compiler keeps what it learned in one build for the next, so the third module of a single process (widget-creator) came out with rules for the composition editor's classes and in another order than the file that is live, which a hand publish builds alone. Every process gets the flags of the first, the 6 GB heap that `npm run build` sets (`--max-old-space-size=6144`, the same as the pipeline's build job): at Node's default of about 4 GB the third module of one process used to stop with `JavaScript heap out of memory`, and one module alone fits (peak about 3.2 GB), so the `build:<name>` scripts need no flag |
886
+ | `npm test` | Unit tests (vitest): token source, session token provider, emitter, picked files, shadow mount, the composition editor, widget creator and Workflows modules, the creator's route list, CSS transforms, fonts, the publishing rules, the R2 store, the release plan and the two scripts of the release pipeline |
887
+ | `npm run harness` | Serves `harness/hostile.html`, `harness/composition-editor.html`, `harness/widget-creator.html`, `harness/workflows.html` and a mock Widgetic API on http://localhost:5290 |
755
888
  | `npm run test:e2e` | Playwright against the harness (`PLAYWRIGHT_CHANNEL=chrome` uses the installed Google Chrome instead of Playwright's download) |
756
889
  | `npm run check:creator-routes` | Reads the packages the creator is made of and checks that every route they can call is on the gateway's list for a creator session, or is listed with the reason a visitor can never reach it (`-- --inventory` prints it as JSON, see "What the end-to-end tests check") |
757
890
  | `npm run publish:cdn -- <module> [options]` | Releases a module to the CDN: see "Publishing". `--help` lists every option |
@@ -820,7 +953,7 @@ SDK's README), and fails if the module needs anything more. `e2e/examplePage.spe
820
953
  `harness/react-page.html` is a page built with React 18 (its browser builds come from this workspace's `node_modules`, so
821
954
  the page needs no build) with the component of the SDK's README, for any module. `e2e/reactPage.spec.ts` runs it in
822
955
  `<React.StrictMode>` (React runs the effect, cleans it up and runs it again) and out of it, for the File Browser, the
823
- composition editor and the widget creator. The first run is cancelled before it counts as an instance, so the one-instance
956
+ composition editor, the widget creator and Workflows. The first run is cancelled before it counts as an instance, so the one-instance
824
957
  guards do not refuse the second; the module is downloaded once; nothing reaches the console; a component that React
825
958
  removes (its container leaves the page *before* the clean-up runs, and the module is taken down from it) leaves nothing
826
959
  behind; one that comes back mounts a fresh module; and a pick goes to the newest `onPick` without mounting again. Taking
@@ -921,6 +1054,14 @@ button is pressed (and that ordinary rate limiting is not reported as a limit).
921
1054
  one for each managed user, to check that the two work at once on their own canvases without refusing, telling or showing
922
1055
  each other anything.
923
1056
 
1057
+ Two rules of the gateway decide whether a call reaches these mocks at all, and `harness/gatewayRequestRules.mjs` holds both.
1058
+ The first is the request headers a page on another origin may send (the gateway's `ALLOWED_REQUEST_HEADERS`, in its
1059
+ `src/middleware/editorSessionCors.ts`, plus the File Browser's upload headers): the browser enforces it at the preflight, so a
1060
+ module that sends a header the list lacks never reaches the mock, and a test that waits for the answer times out without
1061
+ saying why. The second is the compression of a body: the creator gzips any JSON request of 4 KB or more (`Content-Encoding:
1062
+ gzip`: a canvas, a composition, a message with attachments), and the mocks read it inflated, as the gateway does. When the
1063
+ gateway changes either rule, change it there the same day; `tests/gatewayRequestRules.test.mjs` pins them.
1064
+
924
1065
  `e2e/widgetCreatorDarkMode.spec.ts` checks that the creator can be read in a dark look. It reads every text of the creator
925
1066
  the way the browser paints it (`e2e/support/contrastProbe.ts`: the colour of the text over what is behind it, through the
926
1067
  creator's shadow root and the chat's inside it, with an element's opacity and the translucent surfaces in between) and fails,
@@ -1082,8 +1223,9 @@ These are known, tracked for the File Browser work, and not hidden by the module
1082
1223
  from or written to `localStorage`: the module turns that off.)
1083
1224
  - **Files on another website need CORS for some previews.** Pictures, audio and video are shown without it; the text,
1084
1225
  PDF and font previews read the file with a script and need `Access-Control-Allow-Origin` on the file's host.
1085
- - **Words you can change.** The File Browser, the composition editor and the widget creator take `locale` and `messages`
1086
- (see "Speaking your visitors' language"); what each leaves in English is listed there and under its own known gaps.
1226
+ - **Words you can change.** The File Browser, the composition editor, the widget creator and Workflows take `locale` and
1227
+ `messages` (see "Speaking your visitors' language"); what each leaves in English is listed there and under its own
1228
+ known gaps.
1087
1229
  - **Right to left: what is left out.** The canvas board, the live previews and the code of the widget creator stay left to
1088
1230
  right on purpose (see "Right to left"), and two small things are open: the weekday names of an Urdu calendar are the
1089
1231
  short ones, which are whole words (the browser has no one-letter names for Urdu), and the panel of a widget in the
@@ -1184,6 +1326,36 @@ What is left:
1184
1326
  - **Publishing is covered by the gateway's tests, not by the end-to-end ones.** The harness answers 501 for publishing a
1185
1327
  widget, setting a version live and previewing a version.
1186
1328
 
1329
+ ### Known gaps of Workflows
1330
+
1331
+ What is open:
1332
+
1333
+ - **A touch screen reads the canvas only.** The canvas needs a pointer to move blocks and to drag a line from one point to
1334
+ another, so on a touch screen it is read-only: the side panel still changes the selected block, and a banner says so.
1335
+ - **No copy, cut or paste on the canvas.** A pasted block would bring ids and rules from somewhere else. Use Add block, or
1336
+ duplicate the whole workflow in Settings.
1337
+ - **The embed-code button needs a listener at mount time.** The page shows the code (it knows how its tag is built), so the
1338
+ screen has the button only when something listens for `showEmbedCode` when it mounts; a listener added later is not seen.
1339
+ - **The Runs tab counts in UTC days**, whatever the time zone of the workflow, which only decides when a scheduled trigger fires.
1340
+ - **There is no list of visitors.** Where a visitor is in a workflow is kept in that visitor's own browser, and the Runs tab
1341
+ counts how many went through each block, never who.
1342
+ - **Twelve languages, as lazy packs.** The same twelve as the other modules, provisional until a native speaker has read
1343
+ them: `supportedLocales` lists them (see "Speaking your visitors' language").
1344
+ - **Its events are not typed in the SDK.** The SDK types the events of three modules by name; a fourth typed overload makes
1345
+ TypeScript report a mistake against the wrong module, so Workflows is open, like a module the SDK knows nothing about:
1346
+ `on` takes any name and a handler is given what the module sent, unchecked. The reasoning is in `src/sdk/loader/ui.ts`.
1347
+ The form with one type argument (`mountModule<MyModule>('workflows', ...)`) does not compile for it: give both,
1348
+ `mountModule<MyModule, 'workflows'>(...)`. `tests/unit/fixtures/typedEvents.fixture.ts` pins both.
1349
+ - **The end-to-end tests cannot make the screen fail.** A part of the screen that cannot be drawn (`RENDER_FAILED`, the
1350
+ "Try again" button) is covered by the module's unit tests and the package's, not by a browser test, because a page has
1351
+ no way to make a Svelte component throw.
1352
+ - **Two listeners of Svelte's own on `document`.** While the screen is mounted Svelte's runtime listens to `click` on
1353
+ `document` (it delegates the events of its components) and takes it off again on unmount; its `reset` listener stays.
1354
+ The tests name both (`LISTENERS_OF_SVELTE_WHILE_MOUNTED`, `LISTENERS_LEFT_BY_SVELTE`), so a listener of the module's own
1355
+ is not hidden among them.
1356
+ - **The Arabic in the samples is not reviewed.** The Arabic sentence of the package's dev page and the one of
1357
+ `e2e/workflowsRtl.spec.ts` are samples to see the layout turn around, not translations a native speaker has read.
1358
+
1187
1359
  ## Publishing
1188
1360
 
1189
1361
  Partners' pages load three kinds of file from the CDN (`https://cdn.widgetic.com`, the `widgets` bucket on Cloudflare R2,
@@ -1212,7 +1384,7 @@ released. To release them:
1212
1384
 
1213
1385
  ```bash
1214
1386
  cd Frontend/ui-sdk/modules
1215
- # first, add the entry for <x.y.z> to src/file-browser/, src/composition-editor/ and src/widget-creator/CHANGELOG.md
1387
+ # first, add the entry for <x.y.z> to src/file-browser/, src/composition-editor/, src/widget-creator/ and src/workflows/CHANGELOG.md
1216
1388
  npm version <x.y.z> --no-git-tag-version # the version in package.json is the version that gets published
1217
1389
  git commit -am "Modules <x.y.z>" # merged into main the way every change is
1218
1390
  git switch main && git pull
@@ -1421,6 +1593,40 @@ module that needs a first release.
1421
1593
  Publish the modules **before** a `@widgetic/ui-sdk` version whose defaults point at them: `@widgetic/ui-sdk` 0.1.1 was on
1422
1594
  npm before step 5 was done, and until then its `mountModule` failed with `MODULE_NOT_FOUND`.
1423
1595
 
1596
+ ### The first release of a module added later
1597
+
1598
+ `workflows` was added after the three above, and the way it was released is the way the next module added later will be:
1599
+ **by a person, with steps 2 to 6 above**, and **before the next release of the loader** (a `version` bump pushed to `main`,
1600
+ or a `modules-v<x.y.z>` tag). That release builds every module in `MODULES`, and the first pass of the publishing job
1601
+ (`modules-publish` for `main`, `publish` for a tag) refuses a module that has no manifest. Nothing is written when it
1602
+ refuses, and the job can be run again once the module has its manifest, but nobody gets the release until then. `workflows`
1603
+ was released this way at 0.1.5 on 2026-10-26. In order, for a module that has no manifest yet:
1604
+
1605
+ 1. **Release `@widgetic/workflows` to npm** (the module bundles the package, and `npm ci` has to find it). The first
1606
+ publish of a package is made by hand, then the package is given a Trusted Publisher so that every later one is made by
1607
+ its pipeline: "Publish @widgetic packages to npm" in the Releases and deployments doc has the steps.
1608
+ 2. **In `modules/`, run `npm install` once and commit the lockfile.** Until `@widgetic/workflows` is on npm the lockfile
1609
+ cannot list it, and `npm run release:check` says so; this is the only time the lockfile is made by hand.
1610
+ 3. **Merge to `main`.** The merge releases nothing while the loader's `version` is unchanged.
1611
+ 4. **Build from that commit and publish `workflows` by hand**, as in steps 4 and 5 above, for this one module:
1612
+
1613
+ ```bash
1614
+ cd Frontend/ui-sdk/modules
1615
+ npm ci
1616
+ npm run build
1617
+ npm run publish:cdn -- workflows --skip-build --allow-create --dry-run
1618
+ npm run publish:cdn -- workflows --skip-build --allow-create
1619
+ ```
1620
+
1621
+ It is published at the version in `package.json`, and needs an entry for that version in
1622
+ `src/workflows/CHANGELOG.md`: the file starts with the entry the module was added under, so if the version has moved on
1623
+ by then, change that heading to the version and the date of the release before you publish.
1624
+ 5. **Look at what a page gets** (step 6 above): `https://cdn.widgetic.com/modules/workflows/manifest.json` answers with the
1625
+ version, and a page that calls `mountModule('workflows', ...)` with no `version` no longer fails with `MODULE_NOT_FOUND`.
1626
+
1627
+ From then on the module is released with the others: the next release raises the patch, writes its changelog sentence and
1628
+ publishes all of them, `workflows` included.
1629
+
1424
1630
  ### By hand
1425
1631
 
1426
1632
  ```bash
@@ -1502,13 +1708,38 @@ Publish a module **before** the `@widgetic/ui-sdk` version whose defaults point
1502
1708
 
1503
1709
  ## Adding a module
1504
1710
 
1505
- 1. Create `src/<name>/` with `index.ts` (a class extending `ModuleEmitter`, using `TokenSource` and `createShadowMount`),
1506
- a host `.svelte` file and a `module.css` that imports the design-system styles and sets `@source` for the package's
1507
- components.
1711
+ 1. Create `src/<name>/` with `index.ts` (a class extending `ModuleEmitter`, using `TokenSource` when it talks to the API,
1712
+ and `createShadowMount`), a host `.svelte` file and a `module.css` that imports the design-system styles **and the
1713
+ theme tokens** (`@import '../../node_modules/@widgetic/file-browser/dist/components/core/FileBrowser.css'`, as the other
1714
+ modules do) and sets `@source` for the package's components. A module has to own the tokens it draws with
1715
+ (`--primary`, `--radius` ...): without them it takes whatever the partner's page defines, and a page that sets
1716
+ `:root { --primary: yellow }` repaints it. `e2e/themes.spec.ts` found this in Workflows.
1508
1717
  2. Register it in `MODULES` in `scripts/build-module.mjs`, build it, and give it a size budget in
1509
1718
  `scripts/lib/bundleBudget.mjs` a little above what it weighs, for the first load and for the module with its lazy files
1510
1719
  (see "Size budget"): a module with no budget fails the build. If it has a heavy part that few visitors need, see
1511
- "One file, and the parts that are not in it" before adding it to `LAZY_IMPORTS`.
1512
- 3. Add a harness page, an end-to-end spec on the hostile page, and unit tests for anything with logic.
1720
+ "One file, and the parts that are not in it" before adding it to `LAZY_IMPORTS`. The build swaps some files of the
1721
+ design system for ones that work inside a shadow root (`PACKAGE_FILE_OVERRIDES`) and **fails when one of them is not
1722
+ used**, which is how a renamed file is noticed. A module that has no use for some of them (a screen with no modal, menu
1723
+ or popover imports no `Portal.svelte`) says `overridesMayGoUnused: true` in its entry: the swaps still apply to whatever
1724
+ it does import, so a dialog added later is not left with the file that cannot work; only the check is waived. Say it
1725
+ only when that is the reason.
1726
+ 3. Add a harness page, an end-to-end spec on the hostile page, and unit tests for anything with logic. Add the module to
1727
+ the lists that run on every module: the `MODULES` of `e2e/themes.spec.ts` (with `componentsAddTheirOwnStyles: false`
1728
+ when its screen has no component `<style>` of its own, as Workflows' is made of Tailwind classes only: the test then
1729
+ expects none, and says so when that stops being true) and `e2e/reactPage.spec.ts`. Every module also needs an entry for
1730
+ the current version in its `src/<name>/CHANGELOG.md`: `tests/changelogFiles.test.mjs` fails without one.
1513
1731
  4. Anything a package does that cannot work inside a shadow root goes into "Workarounds" above with its removal
1514
1732
  condition, never into the partner's page.
1733
+ 5. Words: if the module has messages, give it `supportedLocales` and `localePackStatus` (a module with no packs says `[]`
1734
+ and `null`) so that a page can ask any module the same question. Packs are a separate step: "Workflows" under
1735
+ "Speaking your visitors' language" lists the files a module's packs are made of, and Workflows is the newest module
1736
+ that has them.
1737
+ 6. The loader (the root of this repository) has to know its name: `ComponentType` in `src/sdk/types/component.ts`,
1738
+ `types/index.d.ts` and `demo/svelte/routes/sdk/types/component.ts`, and `getComponentMinHeight` in
1739
+ `src/sdk/core/lifecycle.ts` (the height of the placeholder while the module downloads). Typed events are
1740
+ optional and limited: the SDK types the events of three modules by name, and a fourth overload makes TypeScript report
1741
+ a mistake against the wrong module, so a new module is open (`on` takes any name) until the overloads are
1742
+ restructured. Say so in `src/sdk/loader/ui.ts` and keep `tests/unit/fixtures/typedEvents.fixture.ts` honest.
1743
+ 7. Its package goes into the list of packages that are published (`Frontend/dev-tools`: the publish walk, the package
1744
+ list and the changelog paths of this repository) before the first release of the module, and `modules/package.json`
1745
+ asks for it. The first release of the module is made by hand ("The first release of a module added later").
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/ui-sdk",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Framework-agnostic UI components for building Widgetic integrations",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "main": "dist/index.cjs",