@widgetic/ui-sdk 0.1.12 → 0.1.13
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 +31 -22
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk/loader/ui.d.cts +25 -22
- package/dist/sdk/loader/ui.d.ts +25 -22
- package/dist/sdk/loader/ui.d.ts.map +1 -1
- package/dist/sdk/types/component.d.cts +9 -9
- package/dist/sdk/types/component.d.ts +9 -9
- package/dist/sdk/types/module-events.d.cts +50 -3
- package/dist/sdk/types/module-events.d.ts +50 -3
- package/dist/sdk/types/module-events.d.ts.map +1 -1
- package/dist/sdk/version.d.cts +1 -1
- package/dist/sdk/version.d.ts +1 -1
- package/dist/umd/ui-sdk.js +1 -1
- package/dist/umd/ui-sdk.js.map +1 -1
- package/modules/README.md +60 -15
- package/package.json +1 -1
package/modules/README.md
CHANGED
|
@@ -414,7 +414,12 @@ canvas of Composition, Trigger and Condition blocks that go forward only (up to
|
|
|
414
414
|
a draft that is saved while you work, publish and discard, a history of versions that never change, a Test run that plays a
|
|
415
415
|
visitor through the draft, a Runs tab with how many visitors went through each block, and a Settings tab (time zone, embed
|
|
416
416
|
code, pause, archive, duplicate, delete). A trigger is enabled for a composition only when its widget can supply it (values a
|
|
417
|
-
visitor adds need a Pro widget that keeps data); the reason is told next to the choice.
|
|
417
|
+
visitor adds need a Pro widget that keeps data); the reason is told next to the choice. *New workflow* asks for a name and for
|
|
418
|
+
where to start: a blank workflow, or a starting point (a preset) the workspace is offered, which is Widgetic's for a person with a
|
|
419
|
+
Widgetic account and the partner's for a partner's customer (an editor session); a pick gives the person their own copy of the
|
|
420
|
+
preset's widgets and a draft workflow wired like it, and nothing they change reaches the preset. A workflow can be deleted in any
|
|
421
|
+
state, after a confirmation that says what goes with it by how far it got (only a draft; or versions and counts too; and, for a
|
|
422
|
+
live one, that embeds then show only their first composition). The package's README lists it all.
|
|
418
423
|
|
|
419
424
|
```js
|
|
420
425
|
import { mountModule } from '@widgetic/ui-sdk';
|
|
@@ -440,14 +445,27 @@ window.addEventListener('popstate', () => workflows.module.setWorkflow(workflowO
|
|
|
440
445
|
| Option | What it does |
|
|
441
446
|
| --- | --- |
|
|
442
447
|
| `container` | The element the screen fills (it needs a height). |
|
|
443
|
-
| `workspaceId` | **Required.** `personal`, or the id of the organization whose workflows are shown and edited. |
|
|
444
|
-
| `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 }`.
|
|
448
|
+
| `workspaceId` | **Required.** `personal`, or the id of the organization whose workflows are shown and edited. With an editor session (below) it is `personal`: a session may call only `/workspaces/personal/workflows…`. |
|
|
449
|
+
| `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 }`. Two kinds work: 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, or an **editor session** your server minted for one of your customers with `surfaces: ['workflows']` ("Showing it to your customers"). 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). |
|
|
445
450
|
| `apiUrl` | The API origin (`https://api.widgetic.com` unless you run your own). |
|
|
446
451
|
| `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. |
|
|
447
452
|
| `presence` | `true` tells the people of a team who else has the workflow open: "Anna is editing", with a choice to take over or to only look (default `false`, read once when the module mounts). It is for an organization's workspace and a person who may change the workflow; for `personal`, or for a token the edit-lease routes refuse (an editor session), the screen carries on as if it were off, without asking again. It is presence, never a lock: nobody is shut out, and a save that finds the draft changed by somebody else asks the person what to do (*Keep my changes as a copy* first, if they like, then *Load the latest version*) whether `presence` is on or not. A value that is not `true` or `false` is ignored, with one warning in the console. |
|
|
448
453
|
| `theme`, `themeFromHost` | The colours, the corners and the typeface ("Looking like your product"). |
|
|
449
454
|
| `locale`, `messages` | The language ("Speaking your visitors' language"). |
|
|
450
455
|
|
|
456
|
+
**Showing it to your customers.** A partner that has a Widgetic account for each of its customers (managed users) mounts the
|
|
457
|
+
screen with an *editor session*: its server mints one for the customer exactly as for the other modules (`POST
|
|
458
|
+
/v1/managed-users/{id}/editor-sessions`) with `surfaces: ['workflows']`, and `getToken` returns it. Pass `workspaceId:
|
|
459
|
+
'personal'`. A session may call only the workflow routes of that workspace, so any other value is refused with
|
|
460
|
+
`EDITOR_SESSION_ROUTE_NOT_ALLOWED` and the screen **shows** the refusal with a "Try again" button instead of an empty list.
|
|
461
|
+
The customer sees and edits **their own workflows only**: another customer's workflow answers "not found", the same as one
|
|
462
|
+
that does not exist. A block that runs a composition offers **their own compositions** and nobody else's, and a workflow
|
|
463
|
+
cannot name a foreign one. Each customer can hold up to 50 workflows (archived ones count; a 51st is refused with a message
|
|
464
|
+
the screen shows). Names of the people who published a version are not shown to a customer. Your account owns, bills and
|
|
465
|
+
serves what a customer makes (the customer is only a tag on it), so what a customer's workflow does to a visitor is covered
|
|
466
|
+
by your plan and your standing, and your own staff, signed in as the partner, see every customer's workflows in the same
|
|
467
|
+
screen.
|
|
468
|
+
|
|
451
469
|
**What it tells the page.** `ready`, with no payload, once the screen is drawn. `openWorkflow` `{ workflowId }`: the person
|
|
452
470
|
opened a workflow, or went back to the list (`workflowId: null`), so the page can keep its address in step.
|
|
453
471
|
`showEmbedCode` `{ workflowId }`: the person asked for the tag of a workflow. The page shows it, because it knows how the tag
|
|
@@ -456,7 +474,10 @@ mounts**. `error` `{ message, code?, fatal }`: `fatal: true` when it could not s
|
|
|
456
474
|
console says `[widgetic-ui] Workflows failed to start:` with the cause), and `fatal: false` for `RENDER_FAILED` (a part of
|
|
457
475
|
the screen could not be drawn: the rest stays and the visitor is offered "Try again" in its place), `REQUEST_FAILED` (a
|
|
458
476
|
request to the API failed: the screen tells the person by itself), `SESSION_ENDED` (the API no longer accepts the token
|
|
459
|
-
`getToken` gives) and `TOKEN_REFRESH_FAILED`. The
|
|
477
|
+
`getToken` gives) and `TOKEN_REFRESH_FAILED`. The SDK types the events (`WorkflowsEvents`): `mountModule('workflows', …)`
|
|
478
|
+
checks the names in `on` and what each handler is given. To type `workflows.module` as well, give both type arguments
|
|
479
|
+
(`mountModule<WorkflowsModule, 'workflows'>('workflows', …)`); the form with one type argument is for the modules that have
|
|
480
|
+
an overload of their own and does not compile for Workflows (see "Known gaps of Workflows").
|
|
460
481
|
|
|
461
482
|
**What it puts on your page.** What every module does, and nothing else: one `<widgetic-ui-module>` in your container and
|
|
462
483
|
the namespaced `<style>` of font rules in `<head>`. Its menus, dialogs and the canvas's own pieces stay inside the shadow
|
|
@@ -484,7 +505,8 @@ sets `:root { --primary: yellow }` repaints the module. It also reads the text c
|
|
|
484
505
|
|
|
485
506
|
**What the tests check.** `tests/workflowsModule.test.ts` for the module's logic. On the hostile page
|
|
486
507
|
(`harness/workflows.html`, with the mock API of `harness/mockWorkflows.mjs`; `?theme=`, `?themeFromHost=1`, `?height=`,
|
|
487
|
-
`?mount=no`, `?locale=`, `?messages=`, `?pseudo=1`, `?workflow=`, `?workspace=`, `?embedCode=yes`, `?lifetime
|
|
508
|
+
`?mount=no`, `?locale=`, `?messages=`, `?pseudo=1`, `?workflow=`, `?workspace=`, `?embedCode=yes`, `?lifetime=`,
|
|
509
|
+
`?customer=userA|userB|userNew`):
|
|
488
510
|
`e2e/workflowsModule.spec.ts` (the page is not touched and nothing is left behind, the requests it makes, the
|
|
489
511
|
Content-Security-Policies, how well the text reads in four looks), `e2e/workflowsEditor.spec.ts` (the list and its
|
|
490
512
|
questions to the API, opening and making a workflow, the canvas drawn among the page's own CSS, adding and connecting
|
|
@@ -492,7 +514,29 @@ blocks with a real mouse drag, publishing with its `Idempotency-Key` and revisio
|
|
|
492
514
|
and that taking the screen away in the middle of an edit leaves nothing behind),
|
|
493
515
|
`e2e/workflowsLanguage.spec.ts` (the pseudo language: every word a visitor can read is a message; `messages`,
|
|
494
516
|
`setLanguage`, `checkMessages`) and `e2e/workflowsRtl.spec.ts` (the screen, its list and its editor mirrored for
|
|
495
|
-
`locale: 'ar'` without a word of Arabic, and not decided by the page's own direction).
|
|
517
|
+
`locale: 'ar'` without a word of Arabic, and not decided by the page's own direction).
|
|
518
|
+
|
|
519
|
+
The mock holds two kinds of caller to two sets of rules. A token that names a customer (`?customer=userA`, `userB` or
|
|
520
|
+
`userNew` give the page one: `wgt_ses_harness_userA_1` ...) is an **editor session**, and `harness/creatorDoor.mjs` holds it
|
|
521
|
+
to **the gateway's own list of what a session may call** (`harness/fixtures/editorSessionRoutes.json`, the 19 rows of the
|
|
522
|
+
`workflows` surface, all on `/workspaces/personal/workflows`): a route that is not on the list is refused with `403
|
|
523
|
+
EDITOR_SESSION_ROUTE_NOT_ALLOWED`, a body field the row does not list with `403 EDITOR_SESSION_FIELD_NOT_ALLOWED`, and a
|
|
524
|
+
workflow that is another customer's answers `404 RESOURCE_WORKFLOW_NOT_FOUND` ("Workflow not found"), exactly as one that does
|
|
525
|
+
not exist, before the workflow is looked up. A customer sees, makes and changes their own workflows only, their workflows have
|
|
526
|
+
UUIDs, and a version shows no publisher. Any other token is the signed-in person the first four specs use, without the door.
|
|
527
|
+
Two routes are about where a workflow starts: the mock lists two presets (`GET .../workflows/presets`) and makes a draft of the
|
|
528
|
+
caller's own from either (`POST .../workflows/from-preset`: an `Idempotency-Key` is needed, a preset that is not offered is
|
|
529
|
+
`404 RESOURCE_WORKFLOW_PRESET_NOT_FOUND`, the name is the preset's title when none is given), and a workflow is deleted in any
|
|
530
|
+
state (`{ removed: true }`, and "not found" from then on), as the gateway does. The module draws the starting-point picker of
|
|
531
|
+
*New workflow* and the confirmation of a delete from the release of `@widgetic/workflows` it carries.
|
|
532
|
+
`tests/mockWorkflowsDoor.test.mjs` checks the mock's side of it (its mutations are killed one by one), and
|
|
533
|
+
`e2e/workflowsSession.spec.ts` checks the module's: it asks the API for the workflow routes of `personal` and nothing else,
|
|
534
|
+
with the session as its bearer; it shows a customer their own workflows and no one else's; making, opening, changing and saving
|
|
535
|
+
a workflow sends only calls and body fields the allow-list names; so does starting from a preset (what the dialog offers, the
|
|
536
|
+
name, the key that makes a retry safe, a preset that is gone, presets that cannot be read while the blank start keeps working);
|
|
537
|
+
a delete asks first, says what goes with the workflow by how far it got, sends nothing until the person agrees and then sends
|
|
538
|
+
one delete for the customer's own workflow; and a refusal (another customer's workflow, a workspace other than `personal`) is
|
|
539
|
+
shown to the person with a way to try again and reported to the page with an `error`, never hidden behind an empty list. The themes matrix
|
|
496
540
|
(`e2e/themes.spec.ts`) and the React page (`e2e/reactPage.spec.ts`) run it too, and `e2e/sdkLoader.spec.ts` checks that the
|
|
497
541
|
theme the page sets through the SDK reaches it.
|
|
498
542
|
|
|
@@ -647,7 +691,7 @@ files.setLanguage({ locale: 'de', messages: germanMessages }); // later, while i
|
|
|
647
691
|
| `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. |
|
|
648
692
|
| `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. |
|
|
649
693
|
|
|
650
|
-
**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 **
|
|
694
|
+
**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 **10 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 431 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.
|
|
651
695
|
|
|
652
696
|
**`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).
|
|
653
697
|
|
|
@@ -871,15 +915,15 @@ creator.setLanguage({ locale: 'de', messages: germanMessages }); // every screen
|
|
|
871
915
|
code stay left to right.
|
|
872
916
|
|
|
873
917
|
**Workflows.** It takes the same `locale`, `messages`, `setLanguage`, `defaultMessages` and `checkMessages`, with **one**
|
|
874
|
-
`messages` object for all of it: its
|
|
918
|
+
`messages` object for all of it: its 431 `workflows.` keys (the list, the editor and its panels, the names of blocks,
|
|
875
919
|
operators and units, what the engine finds wrong with a workflow, what a failed request means, and the words of the screen
|
|
876
920
|
that says a part could not be drawn). The words of a block are made of parts the screen puts together (`{field} {value}`,
|
|
877
921
|
`{count, plural, ...}`), so a language that puts them in another order can say so in its own message.
|
|
878
922
|
|
|
879
923
|
- **It speaks the twelve languages of the other modules.** `Workflows.supportedLocales` lists them (`fr`, `de`, `es`,
|
|
880
924
|
`pt-BR`, `nl`, `da`, `sv`, `zh-CN`, `ar`, `he`, `fa`, `ur`) and `Workflows.localePackStatus(tag)` is `'provisional'` for
|
|
881
|
-
each: a `locale` that has a pack fetches one lazy file of
|
|
882
|
-
|
|
925
|
+
each: a `locale` that has a pack fetches one lazy file of 431 messages (30 to 43 kB, 7.8 to 9.1 kB gzipped; the budget is
|
|
926
|
+
10 kB gzipped), and `mount()` waits for it, so the first paint is already in that language. A `locale` with no pack
|
|
883
927
|
(English, `zh-TW`, an unknown tag) downloads nothing and says nothing in the console: the words stay English, while the
|
|
884
928
|
plural rules and the direction follow `locale` either way. Your `messages` win over the pack, key by key. The packs are
|
|
885
929
|
machine translations written from the English words (Workflows has no Shopify base to start from) and no native speaker
|
|
@@ -1366,11 +1410,12 @@ What is open:
|
|
|
1366
1410
|
counts how many went through each block, never who.
|
|
1367
1411
|
- **Twelve languages, as lazy packs.** The same twelve as the other modules, provisional until a native speaker has read
|
|
1368
1412
|
them: `supportedLocales` lists them (see "Speaking your visitors' language").
|
|
1369
|
-
- **
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
`mountModule<MyModule, 'workflows'>(...)`. `
|
|
1413
|
+
- **Typing the module as well takes both type arguments.** The SDK types the events of Workflows (`WorkflowsEvents`)
|
|
1414
|
+
through its map of events alone, with no overload of its own: `mountModule('workflows', ...)` checks the names in `on` and
|
|
1415
|
+
what each handler is given. A fourth overload by name makes TypeScript report a mistake against the wrong module, so there
|
|
1416
|
+
are three, and the form with one type argument (`mountModule<MyModule>('workflows', ...)`) does not compile for Workflows:
|
|
1417
|
+
give both, `mountModule<MyModule, 'workflows'>(...)`. The reasoning is in `src/sdk/loader/ui.ts`;
|
|
1418
|
+
`tests/unit/fixtures/typedEvents.fixture.ts` pins what compiles and what does not.
|
|
1374
1419
|
- **The end-to-end tests cannot make the screen fail.** A part of the screen that cannot be drawn (`RENDER_FAILED`, the
|
|
1375
1420
|
"Try again" button) is covered by the module's unit tests and the package's, not by a browser test, because a page has
|
|
1376
1421
|
no way to make a Svelte component throw.
|