@proveanything/smartlinks 1.11.1 → 1.11.4
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/docs/API_SUMMARY.md +1 -1
- package/dist/docs/app-manifest.md +24 -16
- package/dist/docs/app-objects.md +17 -4
- package/dist/docs/mobile-admin-container.md +30 -14
- package/dist/docs/records-admin-pattern.md +305 -334
- package/dist/docs/ui-utils.md +257 -41
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/mobile-admin/errors.d.ts +66 -0
- package/dist/mobile-admin/errors.js +72 -0
- package/dist/mobile-admin/types.d.ts +234 -0
- package/dist/mobile-admin/types.js +1 -0
- package/docs/API_SUMMARY.md +1 -1
- package/docs/app-manifest.md +24 -16
- package/docs/app-objects.md +17 -4
- package/docs/mobile-admin-container.md +30 -14
- package/docs/records-admin-pattern.md +305 -334
- package/docs/ui-utils.md +257 -41
- package/package.json +1 -1
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -117,14 +117,18 @@ The manifest is loaded automatically by the platform for every collection page.
|
|
|
117
117
|
|
|
118
118
|
"records": {
|
|
119
119
|
"nutrition": {
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"
|
|
120
|
+
"label": "Nutrition info",
|
|
121
|
+
"cardinality": "singleton",
|
|
122
|
+
"allowFacetRules": true,
|
|
123
|
+
"scopes": ["collection", "rule", "product", "facet", "batch"],
|
|
124
|
+
"defaultScope": "product"
|
|
123
125
|
},
|
|
124
126
|
"cooking_steps": {
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
127
|
+
"label": "Cooking steps",
|
|
128
|
+
"cardinality": "singleton",
|
|
129
|
+
"allowFacetRules": false,
|
|
130
|
+
"scopes": ["collection", "product"],
|
|
131
|
+
"defaultScope": "product"
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
}
|
|
@@ -268,25 +272,29 @@ See the [Deep Link Discovery guide](deep-link-discovery.md) for the full dual-so
|
|
|
268
272
|
|
|
269
273
|
Declares which `app.records` record types the app stores, and which scopes each type supports. Required for any app that follows the [Records-Based Admin Pattern](records-admin-pattern.md). Omit if the app does not use scoped records.
|
|
270
274
|
|
|
271
|
-
The platform and the `<RecordsAdminShell>` from `@proveanything/
|
|
275
|
+
The platform and the `<RecordsAdminShell>` from `@proveanything/smartlinks-utils-ui` read this block to render the right scope tabs, rule editor, and cardinality-appropriate right pane.
|
|
272
276
|
|
|
273
277
|
```json
|
|
274
278
|
"records": {
|
|
275
279
|
"<recordType>": {
|
|
276
|
-
"
|
|
277
|
-
"
|
|
278
|
-
"
|
|
280
|
+
"label": "Human-readable label",
|
|
281
|
+
"cardinality": "singleton",
|
|
282
|
+
"allowFacetRules": false,
|
|
283
|
+
"scopes": ["collection", "product", "variant", "batch", "facet"],
|
|
284
|
+
"defaultScope": "product"
|
|
279
285
|
}
|
|
280
286
|
}
|
|
281
287
|
```
|
|
282
288
|
|
|
283
|
-
| Field
|
|
284
|
-
|
|
285
|
-
| `
|
|
286
|
-
| `
|
|
287
|
-
| `
|
|
289
|
+
| Field | Type | Default | Description |
|
|
290
|
+
|-------------------|----------|---------|-------------|
|
|
291
|
+
| `label` | string | — | Human-readable label for the record type, used in headings and tabs. |
|
|
292
|
+
| `cardinality` | string | `'singleton'` | `'singleton'` — one record wins per scope (e.g. ingredients, nutrition). `'collection'` — every matching record is returned in resolution order (e.g. FAQs, recipes). Drives which hook to use on the public side (`useResolvedRecord` vs `useCollectedRecords`) and how the shell lays out the right pane. |
|
|
293
|
+
| `allowFacetRules` | boolean | `false` | When `true`, the shell renders a **Rule** scope tab and embeds `<FacetRuleEditor>`. Add `'rule'` to `scopes` when setting this. |
|
|
294
|
+
| `scopes` | string[] | — | Allowed scope kinds in resolution order. Valid values: `"collection"`, `"product"`, `"variant"`, `"batch"`, `"facet"`, `"proof"`, `"rule"`. `'rule'` is a synthetic scope holding `facetRule`-targeted records. `'collection'` replaces the legacy empty-ref catch-all — **there is no `'global'` scope**. |
|
|
295
|
+
| `defaultScope` | string | — | The scope the "Create new" button targets in the admin shell. Must be one of the declared `scopes`. |
|
|
288
296
|
|
|
289
|
-
An app may declare multiple record types under different keys (e.g. `"nutrition"` and `"cooking_steps"`).
|
|
297
|
+
An app may declare multiple record types under different keys (e.g. `"nutrition"` and `"cooking_steps"`). See [records-admin-pattern.md](records-admin-pattern.md) for the full admin + public pattern.
|
|
290
298
|
|
|
291
299
|
#### `executor`
|
|
292
300
|
|
package/dist/docs/app-objects.md
CHANGED
|
@@ -495,7 +495,7 @@ The `ref` field is derived automatically from anchor fields when omitted:
|
|
|
495
495
|
```
|
|
496
496
|
productId: 'prod_abc' → ref: 'product:prod_abc'
|
|
497
497
|
productId: 'prod_abc', variantId: 'var_x' → ref: 'product:prod_abc/variant:var_x'
|
|
498
|
-
(no anchor fields) → ref: '' (
|
|
498
|
+
(no anchor fields) → ref: '' (collection-level catch-all)
|
|
499
499
|
facetRule: { ... } → ref: 'rule:<ulid>'
|
|
500
500
|
```
|
|
501
501
|
|
|
@@ -513,6 +513,20 @@ When multiple scoped records match a context, they are ordered by `specificity`.
|
|
|
513
513
|
| Per `anyOf` value | +1 |
|
|
514
514
|
| No anchors / no rule | 0 |
|
|
515
515
|
|
|
516
|
+
### Resolution order
|
|
517
|
+
|
|
518
|
+
When the public side of a records-based app needs "the data that applies to this product context", the platform walks a canonical chain from most-specific to least-specific:
|
|
519
|
+
|
|
520
|
+
```
|
|
521
|
+
proof → batch → variant → product → rule(*) → facet(*) → collection
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
- `rule(*)` — `facetRule`-targeted records are scored by **specificity** (number of clauses + number of constrained values). The most specific rule wins at its tier.
|
|
525
|
+
- `facet(*)` — legacy single-facet anchors, walked alphabetically. Prefer `facetRule` for new work.
|
|
526
|
+
- `collection` — the top of the chain and the catch-all for any record with no anchor fields. **There is no `'global'` tier above collection.**
|
|
527
|
+
|
|
528
|
+
For a **singleton** record type (one answer wins), use `useResolvedRecord` — it performs this walk server-side and returns the first match plus a `matchedAt` tag. For a **collection** record type (every match is shown), use `useCollectedRecords`. See [records-admin-pattern.md §2](records-admin-pattern.md#2-resolution-order-one-canonical-chain) for the full guide.
|
|
529
|
+
|
|
516
530
|
### Singleton Cardinality
|
|
517
531
|
|
|
518
532
|
By default, `create` always inserts a new row — calling it twice produces two records with identical anchor fields. **Singleton cardinality** changes that: pass `singletonPer` on creation and the server will **upsert** instead, ensuring at most one record of a given `recordType` exists per scope boundary.
|
|
@@ -592,12 +606,11 @@ for (const entry of data) {
|
|
|
592
606
|
case 'product': /* "Inherited from product" */ break;
|
|
593
607
|
case 'facet': /* "Tier-specific" */ break;
|
|
594
608
|
case 'collection': /* "Collection default" */ break;
|
|
595
|
-
case 'universal': /* "Default" */ break;
|
|
596
609
|
}
|
|
597
610
|
}
|
|
598
611
|
```
|
|
599
612
|
|
|
600
|
-
Precedence follows: `
|
|
613
|
+
Precedence follows: `proof > batch > variant > product > rule > facet > collection`. There is no scope above `collection` — a record with no anchor fields is a collection-level catch-all.
|
|
601
614
|
|
|
602
615
|
#### React — `useResolvedRecord`
|
|
603
616
|
|
|
@@ -806,7 +819,7 @@ Examples:
|
|
|
806
819
|
| `productId: 'prod_abc', variantId: 'var_500ml'` | `product:prod_abc/variant:var_500ml` |
|
|
807
820
|
| `batchId: 'batch_q1'` | `batch:batch_q1` |
|
|
808
821
|
| `facetRule: { ... }` | `rule:<ulid>` |
|
|
809
|
-
| *(no anchor fields)* | `''` (
|
|
822
|
+
| *(no anchor fields)* | `''` (collection-level catch-all) |
|
|
810
823
|
|
|
811
824
|
`parseRef` / `buildRef` in `data/refs.ts` should be used for **display and URL round-tripping only**, never as upsert keys. For ETL use cases, set an explicit `ref` using a stable external key (see [External ID / ETL Workflow](#external-id--etl-workflow)).
|
|
812
825
|
|
|
@@ -58,6 +58,8 @@ Your container **never** detects the host directly. It receives a `host` prop fr
|
|
|
58
58
|
|
|
59
59
|
Every container mounted by the SmartLinks Mobile launcher receives a single `host` prop — `AdminMobileHostContext`. Do not reach for `window.SmartlinksScanner` or `window.Capacitor` directly; both are wrapped here.
|
|
60
60
|
|
|
61
|
+
> **SDK export** — `AdminMobileHostContext`, `AdminMobileCapability`, `ActionableCapability`, `AdminMobileHostId`, `AdminMobileEvent`, `AdminMobileEventCallback`, `AdminMobileEventSubscriber`, `AdminMobileComponentManifest`, and `AdminMobileBundleManifest` are all exported from `@proveanything/smartlinks`. Import via `import type { AdminMobileHostContext } from '@proveanything/smartlinks'` — no local mirror needed. `ScannerEventSubscriber`, `MobileAdminComponentManifest`, and `MobileAdminBundleManifest` still export as deprecated aliases.
|
|
62
|
+
|
|
61
63
|
```typescript
|
|
62
64
|
interface AdminMobileHostContext {
|
|
63
65
|
// Identity
|
|
@@ -80,8 +82,8 @@ interface AdminMobileHostContext {
|
|
|
80
82
|
keyboard: boolean
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
// Unified hardware event stream
|
|
84
|
-
events: { subscribe:
|
|
85
|
+
// Unified hardware event stream — callback type: AdminMobileEventCallback
|
|
86
|
+
events: { subscribe: (cb: AdminMobileEventCallback) => () => void }
|
|
85
87
|
|
|
86
88
|
// Promise-based hardware actions — reject with a structured error when unavailable
|
|
87
89
|
actions: {
|
|
@@ -95,12 +97,12 @@ interface AdminMobileHostContext {
|
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
// Host-provided UI helpers
|
|
100
|
+
// Host-provided UI helpers — all optional, see §3 note
|
|
99
101
|
ui: {
|
|
100
|
-
toast
|
|
101
|
-
haptic
|
|
102
|
-
setHeaderTitle
|
|
103
|
-
navigateBack
|
|
102
|
+
toast?: (opts: { title: string; description?: string; variant?: 'default' | 'destructive' }) => void
|
|
103
|
+
haptic?: (style?: 'light' | 'success' | 'error') => void
|
|
104
|
+
setHeaderTitle?: (title: string | null) => void
|
|
105
|
+
navigateBack?: () => void
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
// Network & device info
|
|
@@ -141,9 +143,10 @@ if (host.hardware.nfc) {
|
|
|
141
143
|
|
|
142
144
|
### `host.ui` — native helpers vs. your own components
|
|
143
145
|
|
|
144
|
-
|
|
146
|
+
All four `host.ui` methods are **optional by design**. A container may run in the Sidekick mobile shell, a standalone PWA or browser tab, Storybook, or a screenshot harness — none of those environments is guaranteed to have a native toast system, a managed header, or a back stack. Forcing every host implementer to provide them would exclude the web and desktop use-cases the rest of the contract explicitly supports. Always guard with `?.`:
|
|
145
147
|
|
|
146
|
-
`host.ui.toast()`
|
|
148
|
+
- `host.ui.toast?.({...})` / `host.ui.haptic?.('success')` — optional native feedback. Fall back to your own `<Toaster />` when absent.
|
|
149
|
+
- `host.ui.setHeaderTitle?.('Scanning…')` / `host.ui.navigateBack?.()` — host-shell integrations with no in-container equivalent. Silently no-op when the host doesn't implement them.
|
|
147
150
|
|
|
148
151
|
**Stub pattern for testing and Storybook:**
|
|
149
152
|
|
|
@@ -220,12 +223,23 @@ The custom Kotlin shell and both Capacitor shells ship the same baseline plugin
|
|
|
220
223
|
| `@capacitor/device` | `host.device.info()` |
|
|
221
224
|
| `@capacitor/share` | `host.actions.share()` |
|
|
222
225
|
| `@capacitor/clipboard` | `host.actions.clipboard.*` |
|
|
223
|
-
| `@capacitor/preferences` | `host.storage.*` *(planned)* |
|
|
226
|
+
| `@capacitor/preferences` | `host.storage.*` *(planned — see note below)* |
|
|
224
227
|
| `@capacitor/app` | host-managed (back button, deep links) |
|
|
225
228
|
| `@capacitor/status-bar` | host-managed |
|
|
226
229
|
| `@capacitor/keyboard` | host-managed |
|
|
227
230
|
| `@capacitor/toast` | wired into `host.ui.toast()` |
|
|
228
231
|
|
|
232
|
+
> **`host.storage` — planned shape.** Once released, the surface will wrap `@capacitor/preferences` directly:
|
|
233
|
+
> ```ts
|
|
234
|
+
> host.storage: {
|
|
235
|
+
> get(key: string): Promise<string | null>
|
|
236
|
+
> set(key: string, value: string): Promise<void>
|
|
237
|
+
> remove(key: string): Promise<void>
|
|
238
|
+
> keys(): Promise<string[]>
|
|
239
|
+
> }
|
|
240
|
+
> ```
|
|
241
|
+
> Until then: `localStorage` works on web hosts; use `@capacitor/preferences` directly (bundle it in) on native.
|
|
242
|
+
|
|
229
243
|
### Tier 2 — capability-gated (declare in manifest)
|
|
230
244
|
|
|
231
245
|
| Plugin | Capability flag |
|
|
@@ -383,7 +397,9 @@ try {
|
|
|
383
397
|
| `lifecycle: 'pause'` | App backgrounded | Pause readers to save battery |
|
|
384
398
|
| `lifecycle: 'resume'` | App foregrounded | Resubscribe; refresh stale data |
|
|
385
399
|
|
|
386
|
-
Use `host.events.subscribe` for all lifecycle events —
|
|
400
|
+
Use `host.events.subscribe` for all lifecycle events — all five host types (`custom-android`, `capacitor-ios`, `capacitor-android`, `pwa`, `browser`) are guaranteed to emit every `'pause'`/`'resume'`/`'offline'`/`'online'` phase. No `window.addEventListener('online')` fallback is needed.
|
|
401
|
+
|
|
402
|
+
> **Planned** — `phase: 'mount' | 'unmount'` events are on the roadmap. These will fire when the container becomes visible / is removed from the host view stack, enabling deferred reader start-up without a `useEffect` dependency.
|
|
387
403
|
|
|
388
404
|
---
|
|
389
405
|
|
|
@@ -460,7 +476,7 @@ vite build --config vite.config.mobile-admin.ts
|
|
|
460
476
|
```typescript
|
|
461
477
|
// src/mobile-admin/WarehousePickContainer.tsx
|
|
462
478
|
import { useEffect, useState } from 'react'
|
|
463
|
-
import type { AdminMobileHostContext } from '
|
|
479
|
+
import type { AdminMobileHostContext } from '@proveanything/smartlinks'
|
|
464
480
|
|
|
465
481
|
interface Props {
|
|
466
482
|
host: AdminMobileHostContext
|
|
@@ -519,8 +535,8 @@ export const MOBILE_ADMIN_MANIFEST = {
|
|
|
519
535
|
|
|
520
536
|
- **Always check `host.hardware.X` before calling `host.actions.X`** — never assume a capability is available.
|
|
521
537
|
- **Always wrap action calls in try/catch** — handle `HostPermissionDeniedError`, `HostTimeoutError`, and `HostCapabilityUnavailableError`.
|
|
522
|
-
- **
|
|
523
|
-
- **`host.ui.
|
|
538
|
+
- **All four `host.ui` methods are optional** (`toast`, `haptic`, `setHeaderTitle`, `navigateBack`) — guard every call with `?.`. See the `host.ui` section above.
|
|
539
|
+
- **`host.ui.setHeaderTitle` and `host.ui.navigateBack`** integrate with the host shell and have no in-container equivalent; call with `?.`.
|
|
524
540
|
- **Use `host.events.subscribe` for lifecycle events** — `'offline'`/`'online'`/`'pause'`/`'resume'` fire consistently on every host.
|
|
525
541
|
- **Never call `initializeApi`, never use top-level SDK imports for API calls** — `host.SL` is already configured. `SL.method()` instead of `host.SL.method()` silently uses the wrong baseURL.
|
|
526
542
|
- **Bundle Capacitor plugins in** (do not externalise) — so the component degrades gracefully on PWA/browser without crashing.
|