@proveanything/smartlinks 3.0.0-alpha.1 → 3.0.0-alpha.3

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.
Files changed (272) hide show
  1. package/README.md +741 -741
  2. package/dist/README.md +573 -573
  3. package/dist/adminCardsView.js +55 -55
  4. package/dist/api/analytics.d.ts +5 -4
  5. package/dist/api/analytics.js +5 -4
  6. package/dist/api/appConfiguration.d.ts +23 -18
  7. package/dist/api/appConfiguration.js +24 -18
  8. package/dist/api/appObjects.d.ts +54 -10
  9. package/dist/api/appObjects.js +75 -40
  10. package/dist/api/asset.d.ts +28 -22
  11. package/dist/api/asset.js +45 -56
  12. package/dist/api/attestation.d.ts +11 -3
  13. package/dist/api/attestation.js +12 -3
  14. package/dist/api/attestations.d.ts +12 -8
  15. package/dist/api/attestations.js +18 -21
  16. package/dist/api/authKit.d.ts +15 -10
  17. package/dist/api/authKit.js +17 -11
  18. package/dist/api/batch.d.ts +36 -25
  19. package/dist/api/batch.js +46 -39
  20. package/dist/api/bookings.d.ts +67 -11
  21. package/dist/api/bookings.js +82 -15
  22. package/dist/api/broadcasts.js +3 -17
  23. package/dist/api/claimSet.d.ts +26 -12
  24. package/dist/api/claimSet.js +32 -24
  25. package/dist/api/collection.d.ts +15 -10
  26. package/dist/api/collection.js +17 -11
  27. package/dist/api/comms.d.ts +12 -6
  28. package/dist/api/comms.js +12 -6
  29. package/dist/api/conditions.d.ts +7 -6
  30. package/dist/api/conditions.js +8 -6
  31. package/dist/api/contact.d.ts +6 -2
  32. package/dist/api/contact.js +25 -60
  33. package/dist/api/containers.d.ts +14 -10
  34. package/dist/api/containers.js +19 -14
  35. package/dist/api/crate.js +7 -9
  36. package/dist/api/dpp.d.ts +20 -13
  37. package/dist/api/dpp.js +23 -15
  38. package/dist/api/facets.d.ts +38 -13
  39. package/dist/api/facets.js +40 -15
  40. package/dist/api/files.d.ts +5 -2
  41. package/dist/api/files.js +7 -4
  42. package/dist/api/form.d.ts +8 -5
  43. package/dist/api/form.js +9 -5
  44. package/dist/api/index.d.ts +1 -1
  45. package/dist/api/index.js +1 -1
  46. package/dist/api/integrations.d.ts +29 -17
  47. package/dist/api/integrations.js +32 -25
  48. package/dist/api/interactions.d.ts +11 -6
  49. package/dist/api/interactions.js +14 -23
  50. package/dist/api/jobs.d.ts +16 -6
  51. package/dist/api/jobs.js +30 -20
  52. package/dist/api/journeys.js +2 -14
  53. package/dist/api/journeysAnalytics.d.ts +8 -5
  54. package/dist/api/journeysAnalytics.js +8 -5
  55. package/dist/api/knowledge.d.ts +20 -14
  56. package/dist/api/knowledge.js +22 -15
  57. package/dist/api/location.d.ts +6 -3
  58. package/dist/api/location.js +8 -22
  59. package/dist/api/lots.d.ts +9 -5
  60. package/dist/api/lots.js +22 -26
  61. package/dist/api/loyalty.d.ts +25 -16
  62. package/dist/api/loyalty.js +33 -32
  63. package/dist/api/nfc.d.ts +3 -1
  64. package/dist/api/nfc.js +3 -1
  65. package/dist/api/order.d.ts +45 -39
  66. package/dist/api/order.js +48 -65
  67. package/dist/api/partner.d.ts +17 -14
  68. package/dist/api/partner.js +21 -22
  69. package/dist/api/payments.d.ts +60 -0
  70. package/dist/api/payments.js +94 -0
  71. package/dist/api/products.d.ts +35 -12
  72. package/dist/api/products.js +36 -13
  73. package/dist/api/proof.d.ts +41 -19
  74. package/dist/api/proof.js +44 -23
  75. package/dist/api/realtime.d.ts +3 -0
  76. package/dist/api/realtime.js +10 -2
  77. package/dist/api/segments.js +3 -15
  78. package/dist/api/serviceAccounts.d.ts +8 -5
  79. package/dist/api/serviceAccounts.js +9 -6
  80. package/dist/api/shop.d.ts +7 -5
  81. package/dist/api/shop.js +13 -19
  82. package/dist/api/subscriptions.d.ts +12 -10
  83. package/dist/api/subscriptions.js +17 -25
  84. package/dist/api/tags.d.ts +23 -20
  85. package/dist/api/tags.js +40 -52
  86. package/dist/api/template.d.ts +16 -11
  87. package/dist/api/template.js +19 -13
  88. package/dist/api/translations.js +2 -12
  89. package/dist/api/userGroups.d.ts +26 -16
  90. package/dist/api/userGroups.js +43 -30
  91. package/dist/api/variant.d.ts +10 -7
  92. package/dist/api/variant.js +11 -7
  93. package/dist/api/wallet.d.ts +14 -11
  94. package/dist/api/wallet.js +15 -12
  95. package/dist/baseline.css +194 -194
  96. package/dist/dataChanged.d.ts +74 -0
  97. package/dist/dataChanged.js +162 -0
  98. package/dist/docs/API_SUMMARY.md +1443 -1409
  99. package/dist/docs/admin-cards.md +189 -189
  100. package/dist/docs/agent-tools.md +156 -156
  101. package/dist/docs/ai-tools-and-skills.md +180 -180
  102. package/dist/docs/ai.md +1721 -1721
  103. package/dist/docs/analytics.md +1 -1
  104. package/dist/docs/api-versions.md +85 -85
  105. package/dist/docs/app-data-storage.md +277 -277
  106. package/dist/docs/app-docs.md +73 -73
  107. package/dist/docs/app-manifest.md +852 -852
  108. package/dist/docs/app-objects.md +4 -4
  109. package/dist/docs/app-records-pattern.md +388 -388
  110. package/dist/docs/appConfig.md +550 -550
  111. package/dist/docs/assistant-apps.md +172 -172
  112. package/dist/docs/assistant-context.md +119 -119
  113. package/dist/docs/attestations.md +8 -8
  114. package/dist/docs/bookings.md +105 -8
  115. package/dist/docs/caching.md +32 -3
  116. package/dist/docs/comms.md +689 -689
  117. package/dist/docs/connectors.md +340 -340
  118. package/dist/docs/contact-search.md +2 -3
  119. package/dist/docs/css-baseline.md +133 -133
  120. package/dist/docs/customer-guide.md +70 -70
  121. package/dist/docs/data-changed.md +91 -0
  122. package/dist/docs/deploying-apps.md +340 -340
  123. package/dist/docs/dpp.md +115 -115
  124. package/dist/docs/entitlements.md +90 -90
  125. package/dist/docs/files.md +69 -69
  126. package/dist/docs/host-dependency-contract.md +252 -252
  127. package/dist/docs/iframe-responder.md +11 -0
  128. package/dist/docs/integrations.md +322 -322
  129. package/dist/docs/interactions.md +544 -544
  130. package/dist/docs/item-context.md +181 -181
  131. package/dist/docs/knowledge.md +105 -105
  132. package/dist/docs/lists.md +157 -114
  133. package/dist/docs/lots.md +112 -112
  134. package/dist/docs/loyalty.md +348 -348
  135. package/dist/docs/members.md +183 -183
  136. package/dist/docs/memberships.md +150 -150
  137. package/dist/docs/mobile-admin-container.md +693 -693
  138. package/dist/docs/operations.md +281 -281
  139. package/dist/docs/overview.md +487 -485
  140. package/dist/docs/payments.md +94 -0
  141. package/dist/docs/proof-comms-triggers.md +142 -142
  142. package/dist/docs/proof-ownership-transfer.md +155 -155
  143. package/dist/docs/proof-product-data-scoping.md +462 -462
  144. package/dist/docs/proof-share-grants.md +305 -305
  145. package/dist/docs/realtime.md +149 -139
  146. package/dist/docs/records-admin-pattern.md +304 -304
  147. package/dist/docs/service-accounts.md +64 -64
  148. package/dist/docs/standard-query.md +196 -187
  149. package/dist/docs/tag-codes.md +97 -97
  150. package/dist/docs/tag-ranges.md +106 -106
  151. package/dist/docs/theme-tokens.md +252 -252
  152. package/dist/docs/upgrading-to-3.md +550 -430
  153. package/dist/docs/wallet-passes.md +107 -107
  154. package/dist/docs/websites.md +123 -123
  155. package/dist/http.d.ts +6 -3
  156. package/dist/http.js +48 -19
  157. package/dist/iframeResponder.d.ts +7 -0
  158. package/dist/iframeResponder.js +10 -0
  159. package/dist/index.d.ts +2 -0
  160. package/dist/index.js +2 -0
  161. package/dist/list.d.ts +12 -0
  162. package/dist/list.js +59 -0
  163. package/dist/openapi.yaml +722 -660
  164. package/dist/testing/bookingsMemory.d.ts +29 -1
  165. package/dist/testing/bookingsMemory.js +89 -1
  166. package/dist/testing/index.js +4 -1
  167. package/dist/theme-boot.js +82 -82
  168. package/dist/theme.css +75 -75
  169. package/dist/types/analytics.d.ts +7 -3
  170. package/dist/types/appManifest.d.ts +26 -4
  171. package/dist/types/appObjects.d.ts +27 -12
  172. package/dist/types/appOptions.d.ts +2 -2
  173. package/dist/types/asset.d.ts +5 -6
  174. package/dist/types/attestations.d.ts +7 -9
  175. package/dist/types/batch.d.ts +5 -5
  176. package/dist/types/bookings.d.ts +109 -6
  177. package/dist/types/comms.d.ts +9 -5
  178. package/dist/types/contact.d.ts +7 -4
  179. package/dist/types/containers.d.ts +2 -1
  180. package/dist/types/facets.d.ts +14 -2
  181. package/dist/types/files.d.ts +3 -2
  182. package/dist/types/index.d.ts +1 -0
  183. package/dist/types/index.js +1 -0
  184. package/dist/types/integrations.d.ts +2 -1
  185. package/dist/types/interaction.d.ts +15 -7
  186. package/dist/types/jobs.d.ts +1 -1
  187. package/dist/types/journeysAnalytics.d.ts +3 -2
  188. package/dist/types/knowledge.d.ts +6 -3
  189. package/dist/types/knowledge.js +0 -1
  190. package/dist/types/list.d.ts +30 -2
  191. package/dist/types/location.d.ts +7 -2
  192. package/dist/types/location.js +0 -1
  193. package/dist/types/lots.d.ts +5 -2
  194. package/dist/types/lots.js +0 -6
  195. package/dist/types/order.d.ts +22 -20
  196. package/dist/types/payments.d.ts +101 -0
  197. package/dist/types/payments.js +5 -0
  198. package/dist/types/product.d.ts +28 -11
  199. package/dist/types/proof.d.ts +7 -8
  200. package/dist/types/realtime.d.ts +5 -1
  201. package/dist/types/tags.d.ts +5 -3
  202. package/dist/types/userGroups.d.ts +3 -3
  203. package/dist/types/userGroups.js +0 -4
  204. package/dist/version.d.ts +1 -1
  205. package/dist/version.js +1 -1
  206. package/docs/API_SUMMARY.md +1443 -1409
  207. package/docs/admin-cards.md +189 -189
  208. package/docs/agent-tools.md +156 -156
  209. package/docs/ai-tools-and-skills.md +180 -180
  210. package/docs/ai.md +1721 -1721
  211. package/docs/analytics.md +1 -1
  212. package/docs/api-versions.md +85 -85
  213. package/docs/app-data-storage.md +277 -277
  214. package/docs/app-docs.md +73 -73
  215. package/docs/app-manifest.md +852 -852
  216. package/docs/app-objects.md +4 -4
  217. package/docs/app-records-pattern.md +388 -388
  218. package/docs/appConfig.md +550 -550
  219. package/docs/assistant-apps.md +172 -172
  220. package/docs/assistant-context.md +119 -119
  221. package/docs/attestations.md +8 -8
  222. package/docs/bookings.md +105 -8
  223. package/docs/caching.md +32 -3
  224. package/docs/comms.md +689 -689
  225. package/docs/connectors.md +340 -340
  226. package/docs/contact-search.md +2 -3
  227. package/docs/css-baseline.md +133 -133
  228. package/docs/customer-guide.md +70 -70
  229. package/docs/data-changed.md +91 -0
  230. package/docs/deploying-apps.md +340 -340
  231. package/docs/dpp.md +115 -115
  232. package/docs/entitlements.md +90 -90
  233. package/docs/files.md +69 -69
  234. package/docs/host-dependency-contract.md +252 -252
  235. package/docs/iframe-responder.md +11 -0
  236. package/docs/integrations.md +322 -322
  237. package/docs/interactions.md +544 -544
  238. package/docs/item-context.md +181 -181
  239. package/docs/knowledge.md +105 -105
  240. package/docs/lists.md +157 -114
  241. package/docs/lots.md +112 -112
  242. package/docs/loyalty.md +348 -348
  243. package/docs/members.md +183 -183
  244. package/docs/memberships.md +150 -150
  245. package/docs/mobile-admin-container.md +693 -693
  246. package/docs/operations.md +281 -281
  247. package/docs/overview.md +487 -485
  248. package/docs/payments.md +94 -0
  249. package/docs/proof-comms-triggers.md +142 -142
  250. package/docs/proof-ownership-transfer.md +155 -155
  251. package/docs/proof-product-data-scoping.md +462 -462
  252. package/docs/proof-share-grants.md +305 -305
  253. package/docs/realtime.md +149 -139
  254. package/docs/service-accounts.md +64 -64
  255. package/docs/standard-query.md +196 -187
  256. package/docs/tag-codes.md +97 -97
  257. package/docs/tag-ranges.md +106 -106
  258. package/docs/theme-lookbook.v1.json +120 -120
  259. package/docs/theme-tokens.md +252 -252
  260. package/docs/upgrading-to-3.md +550 -430
  261. package/docs/wallet-passes.md +107 -107
  262. package/docs/websites.md +123 -123
  263. package/openapi.yaml +722 -660
  264. package/package.json +91 -91
  265. package/scripts/headless-check.mjs +87 -87
  266. package/scripts/lib/bare-imports.mjs +57 -57
  267. package/scripts/lib/keyed-app-data.mjs +21 -21
  268. package/scripts/lib/upgrade.mjs +708 -512
  269. package/scripts/publish.mjs +272 -272
  270. package/scripts/register-release.mjs +91 -91
  271. package/scripts/upgrade.mjs +79 -56
  272. package/upgrade/3.json +2731 -2213
@@ -1,485 +1,487 @@
1
- # SmartLinks Microapp Development Guide
2
-
3
- > **Platform revision:** R5 · **SDK:** `@proveanything/smartlinks@^3` · React 19 · Vite 8 · Router 7 · Tailwind 4 · TS 6.
4
- > The canonical version/host stack lives in [host-dependency-contract.md](host-dependency-contract.md).
5
-
6
- ---
7
-
8
- ## What Is a SmartLinks Microapp?
9
-
10
- SmartLinks connects **physical products to digital experiences**: each item has a digital identity — a **proof** — that a consumer reaches by scanning a QR / NFC tag, then claims and enriches over time. A **microapp** is a focused, embeddable React experience a brand adds to that product's digital life: product info, warranty registration, authenticity checks, manuals, competitions, loyalty, post-purchase support, and more.
11
-
12
- Rather than baking every feature into the core platform, functionality is distributed across purpose-built apps, so a brand adds exactly the experiences its product needs. Each app:
13
-
14
- - **Embeds** in the SmartLinks Portal (public) and Admin Console (management)
15
- - **Shares context** through URL parameters (collection, product, proof)
16
- - **Inherits identity** from the parent platform's auth
17
- - **Adapts** to the brand's theme
18
- - **Communicates** with the parent via postMessage for deep linking and navigation
19
-
20
- ### Deployment Modes
21
-
22
- Each microapp can be consumed in one or more of the following ways:
23
-
24
- | Mode | Description |
25
- |------|-------------|
26
- | **Container** | Full app in parent React tree. ~150 KB+ lazy-loaded. The primary consumer surface. |
27
- | **Iframe App** | Full React app inside an iframe. Fallback when sandboxing is required; still the standard for setup admin screens. |
28
- | **Widget** | Lightweight React component in parent tree. ~10 KB, loaded immediately alongside the page. |
29
- | **Mobile Admin Container** | Separate bundle for in-the-field operator/admin workflows on mobile. Built independently; may use Capacitor, Preact, or any other runtime. |
30
- | **Executor** | JS library, no UI. Programmatic config, SEO metadata, LLM content for AI/server. |
31
-
32
- Widgets and containers run in the parent's React tree (not iframes). Mobile Admin Containers are a separate bundle loaded by a dedicated mobile shell (Capacitor or PWA). Executors have no UI — they expose functions that AI orchestrators and the server call directly.
33
-
34
- > **Admin vs consumer:** Admin experiences always ship as a **separate bundle** (`mobileAdmin` or iframe). The `containers` bundle is for consumer-facing surfaces only.
35
-
36
- ---
37
-
38
- ## SDK Documentation Reference
39
-
40
- The SmartLinks SDK (`@proveanything/smartlinks`) includes comprehensive documentation in `node_modules/@proveanything/smartlinks/docs/`. **Always read these files for detailed implementation guidance.**
41
-
42
- > Product endpoints: use `products` (plural) for new integrations. The older `product` (singular) namespace remains for backward compatibility and is deprecated.
43
-
44
- > **SDK baseline: `@proveanything/smartlinks@^3`** (R5). Install/update with `npm install @proveanything/smartlinks@^3`. Moving an app from SDK 2: [`upgrading-to-3.md`](upgrading-to-3.md). Every list returns `{ items, nextCursor, count? }`: [`lists.md`](lists.md). Individual features may need a higher minor — see the relevant doc. The single source of truth for the R5 host/version stack is [`host-dependency-contract.md`](host-dependency-contract.md).
45
-
46
- | Topic | File | When to Use |
47
- |-------|------|-------------|
48
- | **API Reference** | `docs/API_SUMMARY.md` | Complete SDK function reference, types, error handling |
49
- | **Assets** | `docs/assets.md` | Asset object, AssetRef, upload, replace, soft-delete, restore, bulk-delete, public token-based uploads |
50
- | **Files** | `docs/files.md` | Temporary or kept files, fetched by address, and text / Markdown / OCR / fields extracted from them; hidden from asset lists until kept |
51
- | **Building React Components** | `docs/building-react-components.md` | **READ THIS FIRST** — Dual-mode rendering, router rules, useAppContext pattern |
52
- | **Multi-Page Architecture** | `docs/mpa.md` | Build pipeline, entry points, multi-page setup, content hashing |
53
- | **AI & Chat** | `docs/ai.md` | Chat completions, RAG, streaming, tool calling, voice, podcasts, TTS |
54
- | **Analytics** | `docs/analytics.md` | Fire-and-forget page/click/tag analytics plus admin dashboard queries |
55
- | **Translations** | `docs/translations.md` | Runtime translation lookup, local-first IndexedDB caching, and translation admin APIs |
56
- | **Theming** | `docs/theme.system.md` | Implementing dynamic themes via URL params or postMessage |
57
- | **Theme Defaults** | `docs/theme-defaults.md` | Default colour values for light/dark modes |
58
- | **Internationalization** | `docs/i18n.md` | Adding multi-language support, translation patterns |
59
- | **Widgets** | `docs/widgets.md` | Building widgets, shared deps contract, settings schema |
60
- | **Containers** | `docs/containers.md` | Building full-app embeddable containers (lazy-loaded) |
61
- | **Mobile Admin Container** | `docs/mobile-admin-container.md` | Building a separate Capacitor-aware mobile admin bundle for field operators |
62
- | **Executors** | `docs/executor.md` | Building executor bundles for SEO, LLM content, programmatic config |
63
- | **Server Functions** | `docs/server-functions.md` | App-authored server-side functions `(ctx, event) ⇒ result`: security model, runtime surface, invoking |
64
- | **Agent Tools** | `docs/agent-tools.md` | Exposing your app's actions to the SmartLinks agent — an MCP facade over server functions; **opt-in per app, additive, no migration**; complements `app.admin.json` (functions serve/adapt it, don't replace it); live loop staged |
65
- | **Deploying & Registering** | `docs/deploying-apps.md` | Getting your app into the platform: fast dev publish, channels, deploy keys, registering releases |
66
- | **Host Dependency Contract (R5)** | `docs/host-dependency-contract.md` | The libraries the host provides (React 19, Router 7, Radix, liquidjs, …), the externalise-don't-bundle rule + Vite config, and React-18 backwards-compat |
67
- | **CSS Baseline** (`sl-baseline` v1) | `docs/css-baseline.md` | A small, frozen, `sl-`-namespaced set of structural helpers (layout, spacing, responsive flow, type scale, motion) the SDK ships (`@proveanything/smartlinks/baseline.css`) and the host guarantees — a teachable floor for apps + AI content. No colours/fonts/components. Opt-in via `meta.cssBaseline` |
68
- | **Deep Linking** | `docs/deep-link-discovery.md` | URL state management, navigable states, portal menus, AI nav |
69
- | **Admin Views** | `docs/admin-views.md` | The admin side's screens by name (`adminViews`): the app's side menu, Studio's menu and the assistant; host → app `smartlinks:navigate`; `chrome=none` |
70
- | **Portal Back Button** | `docs/portal-back-button.md` | Hierarchy-aware "up" navigation inside embedded apps |
71
- | **Portal Request Action** | `docs/portal-request-action.md` | Triggering portal built-in actions (__qrScanner, __share, __logout, etc.) from sub-apps |
72
- | **Interactions** | `docs/interactions.md` | Business events, outcomes, voting, competitions, and journey triggers |
73
- | **App Config Files** | `docs/app-manifest.md` | Full field-by-field reference for both JSON config files |
74
- | **Admin cards** | `docs/admin-cards.md` | Cards on the collection's dashboard in Studio: declare a card + an admin function returning its data; cached, refreshed only when its data changes |
75
- | **Realtime** | `docs/realtime.md` | Live updates: change events (refetch when something changes) and declared app channels (a draw, a status) — no provider library or keys |
76
- | **Liquid Templates** | `docs/liquid-templates.md` | Dynamic content rendering with LiquidJS |
77
- | **Iframe Responder** | `docs/iframe-responder.md` | Iframe communication and proxy mode internals |
78
- | **AI Guide Template** | `docs/ai-guide-template.md` | Template for creating `public/ai-guide.md` — customise per app |
79
- | **Forms** | `docs/forms.md` | Form definitions, schema-driven rendering, submission patterns |
80
- | **Auth Kit** | `docs/auth-kit.md` | End-user sign-in: email/password, magic links, phone OTP, Google OAuth |
81
- | **EU Digital Product Passports** | `docs/dpp.md` | Passports hosted at their own address in the EU format (public + restricted views, versions), the brand's EU registry connection, and registering them (`dpp.*`) |
82
- | **Service accounts** | `docs/service-accounts.md` | Identities for other systems (an ERP, a warehouse system) to work with one collection: own key, own access level, made and removed by the collection's admins |
83
- | **Members** | `docs/members.md` | Signed-in members with a level (clubs, leagues, members' areas): the level field, members-only functions, joining rules |
84
- | **Portal Request Login** | `docs/portal-request-login.md` | How sub-apps ask the portal to authenticate the user; hook and iframe postMessage contracts |
85
- | **Portal Auth Broadcast** | `docs/portal-auth-broadcast.md` | Publishing custom auth flows to the portal; syncing sessions across containers and iframes |
86
- | **Contact Search** | `docs/contact-search.md` | Admin contact search: free-text, typeahead, identity/tag/JSONB filters, and pagination |
87
- | **App Records Pattern** | `docs/app-records-pattern.md` | Standard pattern for per-product/facet/variant/batch admin + public widget UIs |
88
- | **UI Utils** | `docs/ui-utils.md` | `@proveanything/smartlinks-utils-ui` — React shells, hooks, and primitives for records-based apps |
89
- | **Product/Proof Data Scoping** | `docs/proof-product-data-scoping.md` | Canonical spec for `product.data`/`.admin` and `proof.data`/`.admin`/`.values` (owner/personal) — who can read and write each bucket |
90
- | **Proof Claiming** | `docs/proof-claiming-methods.md` | The ways a user claims a proof (serial, NFC, claim-set, auto-generate) |
91
- | **Proof Share Grants** | `docs/proof-share-grants.md` | Delegated, scoped, revocable bearer access to a single proof (read/comment/verify-owner) |
92
- | **Proof Ownership Transfer** | `docs/proof-ownership-transfer.md` | Moving a proof's single owner (directed transfer / open release), accept/cancel, and the state machine |
93
- | **appConfig / Feature Flags** | `docs/appConfig.md` | `appConfig` settings contract — installed apps, `system.features`/`entitledAppGroups`/`meters`, `isFeatureEnabled()` helper |
94
- | **App Objects** | `docs/app-objects.md` | Queryable domain objects — `app.records` / `app.cases` / `app.threads`: JSONB zones, visibility, policies, aggregations |
95
- | **Bookings** | `docs/bookings.md` | Slots, bookings and allocations for events and appointments: no double-booking, holds, per-app public rules, `utils.freeTimes` |
96
- | **Shop** | `docs/shop.md` | Sell from any site: prices, Stripe checkout into the seller's account, stock held while paying, physical and digital delivery (files, proofs, access), orders, shipping, refunds, order events for emails and integrations |
97
- | **Memberships** | `docs/memberships.md` | Paid plans (monthly, yearly, one-off) that keep a member's level and user groups switched on while paid: join pages, "my membership", cancel and change plan, staff grants, `ctx.sl.subscriptions` |
98
- | **User groups** | `docs/user-groups.md` | Who may do what: named lists of people (staff who aren't admins, third parties), `userGroups` on a server function, `ctx.caller.userGroups`, `userGroups.mine()` |
99
- | **Operations** | `docs/operations.md` | Factory floor and warehouse: work orders with stages, stock as quantities in containers, movements, bills of materials, made-from, sales and purchase orders, and a product's position (on hand, on order, needed, when it runs short) |
100
- | **App Data Storage** | `docs/app-data-storage.md` | Decision guide: pick between `appConfiguration` / `userAppData` / `app.records` |
101
- | **Attestations** | `docs/attestations.md` | Postgres attestations API (proof-level user/admin data; replaces the legacy Firestore path) |
102
- | **Caching** | `docs/caching.md` | SDK GET cache tiers + TTLs, `invalidateCache({ exact })`, and `force`/push guidance |
103
- | **Comms & Broadcasts** | `docs/comms.md` | Transactional comms, campaigns, consent, push |
104
- | **Container Tracking** | `docs/container-tracking.md` | Physical/logical **item** container groupings — *not* app containers (see containers.md) |
105
- | **Lots** | `docs/lots.md` | Cross-SKU production "Lot" entity |
106
- | **Loyalty** | `docs/loyalty.md` | Points, members, earning rules |
107
- | **Integrations** | `docs/integrations.md` | Inbound/outbound external-system integration flows |
108
- | **Connectors** | `docs/connectors.md` | Connector apps: the manifest `connector` block + the functions the integration engine calls |
109
- | **Item Context** | `docs/item-context.md` | The `itemContext` container prop (serial / NFC authenticity context) |
110
- | **Native Facade** | `docs/native-facade.md` | `host.native` / `SL.native` device-capability facade |
111
- | **Product Facets** | `docs/PRODUCT_FACETS_SDK.md` | Facet API reference (admin + public endpoints, types) |
112
- | **AI Tools & Skills** | `docs/ai-tools-and-skills.md` | Platform AI capability registry (web research, extraction, images) |
113
- | **Proof Comms Triggers** | `docs/proof-comms-triggers.md` | Transactional comms fired as a side-effect of proof actions |
114
-
115
- ---
116
-
117
- ## Technical Overview
118
-
119
- - **Iframe-based** — Apps run inside iframes in both the public Portal and Admin Console
120
- - **Hash routing** — Uses `/#/` routes for iframe compatibility (e.g., `/#/`, `/#/admin`)
121
- - **Context via URL params** — All contextual data is passed through URL parameters
122
- - **SmartLinks NPM module** — All data access and platform interaction goes through `@proveanything/smartlinks`
123
- - **No standalone auth** — Authentication is handled by the parent SmartLinks platform
124
-
125
- > **Use the host-provided `SL`, don't instantiate your own.** When your app runs in a
126
- > container/iframe, the host injects an already-initialized, authenticated SDK instance (the
127
- > `SL` prop / the externalized `@proveanything/smartlinks` singleton). Import and use *that*.
128
- > Calling `initializeApi()` yourself to spin up a **second** SDK instance is a common source
129
- > of bugs: it won't share the host's auth (so it looks signed-out), won't share the host's
130
- > cache (duplicate requests, stale data), and in proxy mode it bypasses the host's request
131
- > routing. Rule of thumb: **host-provided `SL` for anything the platform owns** (auth, config,
132
- > data, cache); only app-owned state is yours.
133
- - **Multi-page build** — Separate bundles for public and admin — see `docs/mpa.md`
134
- - **Embedded back navigation** — Use `docs/portal-back-button.md` when a sub-app has a real content hierarchy
135
-
136
- ---
137
-
138
- ## Data Model Hierarchy
139
-
140
- ```
141
- Collection (Business/Brand)
142
- └── Product (Product Type/Definition)
143
- └── Proof (Specific Instance with Owner)
144
- └── Attestation (User/Admin Data on Proof)
145
- ```
146
-
147
- | Entity | Description | Example |
148
- |--------|-------------|---------|
149
- | **Collection** | Top-level container representing a business or brand | "Acme Wine Co." |
150
- | **Product** | A type of product (not a specific item) | "2023 Cabernet Sauvignon" |
151
- | **Proof** | A specific instance of a product, often with an owner | Bottle #12345 claimed by user@email.com |
152
- | **Attestation** | Data attached to a proof by users or admins | Warranty registration, tasting notes |
153
-
154
- ### URL Parameters
155
-
156
- | Parameter | Type | Description |
157
- |-----------|------|-------------|
158
- | `collectionId` | string | The collection being viewed/managed |
159
- | `productId` | string | The specific product (within collection) |
160
- | `proofId` | string | The specific proof instance |
161
- | `appId` | string | This app's unique identifier (for data scoping) |
162
- | `dark` | `1` or `0` | Whether to use dark mode |
163
- | `theme` | base64 | Full theme configuration (see `docs/theme.system.md`) |
164
-
165
- ---
166
-
167
- ## Authentication & Permissions
168
-
169
- SmartLinks apps do **not** implement their own authentication. The parent platform handles all auth:
170
-
171
- - Use `SL.auth.getAccount()` to check if a user is logged in
172
- - The response includes whether the user is an `admin` or regular user
173
- - Many SmartLinks API functions behave differently based on admin status
174
-
175
- | Capability | Admin | Regular User |
176
- |------------|-------|-------------|
177
- | Read collection/product data | ✅ | ✅ |
178
- | Write app configuration | ✅ | ❌ |
179
- | Write attestations | ✅ | ✅ (own proofs only) |
180
- | Access admin-only API fields | ✅ | ❌ |
181
-
182
- ---
183
-
184
- ## Data Storage Patterns
185
-
186
- ### ⚠️ Critical: Admin Mode Flag
187
-
188
- **When building admin interfaces, you MUST pass `admin: true` in API options.**
189
-
190
- Without this flag, API calls use the public endpoint and will fail to write data:
191
-
192
- ```typescript
193
- // ❌ WRONG — will fail in admin interface
194
- await SL.appConfiguration.setConfig({ collectionId, appId, config: myConfig });
195
-
196
- // ✅ CORRECT — include admin: true
197
- await SL.appConfiguration.setConfig({ collectionId, appId, config: myConfig, admin: true });
198
- ```
199
-
200
- This applies to all write operations: `setConfig`, `setDataItem`, `updateDataItem`, etc.
201
-
202
- ### Endpoint Auth vs Data Visibility
203
-
204
- `admin: true` is an endpoint selector, not a privacy marker.
205
-
206
- - It tells the SDK to call the admin endpoint.
207
- - It allows writes and admin reads.
208
- - It does **not** mean every root-level field you save becomes admin-only.
209
-
210
- For `appConfiguration` config blobs and `collection.getSettings()` groups, root-level fields are typically the public-facing settings. If you need private values such as tokens or secrets, store them inside a top-level `admin` object:
211
-
212
- ```typescript
213
- await SL.appConfiguration.setConfig({
214
- collectionId,
215
- appId,
216
- admin: true,
217
- config: {
218
- publicLabel: 'Warranty Portal',
219
- color: '#B68C2A',
220
- admin: {
221
- accessToken: 'secret-token'
222
- }
223
- }
224
- })
225
- ```
226
-
227
- Public reads omit the `admin` block. Admin reads include it.
228
-
229
- ### Config vs Data
230
-
231
- | Storage Type | Function | Use Case |
232
- |-------------|---------|---------|
233
- | **Config** (`getConfig`/`setConfig`) | Single JSON document | App settings, feature flags, global options |
234
- | **Data** (`getData`/`setDataItem`) | Array of documents with IDs | Lists of items, records, entries |
235
- | **App Objects** (`app.records` / `app.cases` / `app.threads`) | Queryable domain objects | Real app entities, workflows, conversations, richer access control |
236
-
237
- Both can be scoped to **collection level** or **product level** by including `productId`.
238
-
239
- For config/settings visibility, remember: root fields are the normal shared payload, while a reserved top-level `admin` object is the place for admin-only values.
240
-
241
- Prefer `app.records` over `setDataItem` when the data is becoming a real entity that needs lifecycle, ownership, visibility, relationships, or filtering. Keep `setDataItem` for simple keyed scoped documents and config-adjacent content.
242
-
243
- ### Feature Flags & Entitlements (`appConfig`)
244
-
245
- The platform-owned `appConfig` settings group (`system.features`, `system.meters`, `system.entitledAppGroups`, installed `apps[]`) tells a microapp what's installed and entitled for a collection. Use `SL.appConfiguration.isFeatureEnabled(collectionId, flag)` to gate a feature — it's the standard, cache-backed way to do this rather than hand-rolling a `getConfig` call:
246
-
247
- ```ts
248
- if (await SL.appConfiguration.isFeatureEnabled(collectionId, 'custom_domain')) {
249
- enableCustomDomainUI();
250
- }
251
- ```
252
-
253
- It's async (the first check for a collection has nothing cached yet); `SL.appConfiguration.isFeatureEnabledSync()` gives a synchronous, cache-only read (`boolean | undefined`) for callers that warmed the cache earlier and can't await. See `docs/appConfig.md` for the full contract, including `systemPrivate` (admin-only overrides, always stripped for non-admin reads).
254
-
255
- ### Attestations (Proof-level data)
256
-
257
- For data attached to specific proof instances, use `SL.attestation.create()` and `SL.attestation.list()`.
258
-
259
- ### Custom Data Scoping (Product & Proof)
260
-
261
- `product.data`/`product.admin` and `proof.data`/`proof.admin`/`proof.values` are the canonical buckets for custom fields on products and proofs — `data` is public and business-writable, `admin` is business-only, and `proof.values` additionally supports owner-scoped (`values.owner`) and per-user (`values.personal[userId]`) sub-keys. This is a different mechanism from the app-scoped storage in `docs/app-data-storage.md` (which is for app-owned config/records, not the product/proof documents themselves).
262
-
263
- See `docs/proof-product-data-scoping.md` for the full read/write authority matrix, worked examples, and the `productFields`/`proofFields` collection-settings schemas that drive field-config editors.
264
-
265
- ---
266
-
267
- ## Error Handling
268
-
269
- The SmartLinks SDK returns structured `SmartlinksApiError` objects. Use `instanceof SmartlinksApiError` to access `.statusCode`, `.message`, and helper methods:
270
-
271
- - `.isAuthError()` — 401/403 responses
272
- - `.isNotFound()` — 404 responses
273
- - `.isRateLimited()` — 429 responses
274
- - `.isServerError()` — 5xx responses
275
-
276
- See `docs/API_SUMMARY.md` for complete error handling documentation.
277
-
278
- ---
279
-
280
- ## AI Integration
281
-
282
- SmartLinks provides comprehensive AI capabilities through the `SL.ai` namespace. **Always use SmartLinks AI for microapps** — do not integrate external AI services (OpenAI, Anthropic, Lovable Cloud AI, etc.) directly.
283
-
284
- Key capabilities: chat completions (streaming + tool calling), RAG document Q&A, voice input/output, podcast generation, text-to-speech, model listing.
285
-
286
- See `docs/ai.md` for complete documentation.
287
-
288
- ---
289
-
290
- ## Interactions & Event Tracking
291
-
292
- The `SL.interactions` namespace tracks user engagement — competition entries, votes, form submissions, warranty registrations. Events can trigger automated journeys and communications.
293
-
294
- **The one rule:** you never choose an interaction id. In admin, `SL.interactions.ensureType(collectionId, { appId, key: 'vote', … })` finds-or-creates the type and returns its server-minted `id`; store it in app config (`interactionIds: { vote: type.id }`); everywhere else — public widgets included — read `interactionIds.vote` from config and pass that as `interactionId`. Never write an interactionId as a string literal.
295
-
296
- Key functions: `submitPublicEvent()`, `appendEvent()` (admin), `countsByOutcome()`, `query()`.
297
-
298
- See `docs/interactions.md` for complete documentation.
299
-
300
- ---
301
-
302
- ## Liquid Templating
303
-
304
- Use the `<LiquidContent>` component, `useLiquidTemplate` hook, and `renderLiquid` utility for admin-configured dynamic content using Liquid syntax.
305
-
306
- See `docs/liquid-templates.md` for full context variables, filters, and examples.
307
-
308
- ---
309
-
310
- ## Design Principles
311
-
312
- ### Public Interface (Portal)
313
-
314
- - **Mobile-first** — Assume users are on phones
315
- - **Non-technical** — Never show raw IDs or technical data
316
- - **Accessible** — Follow WCAG guidelines
317
-
318
- ### Admin Interface
319
-
320
- - **Feature-rich** — Power users expect advanced controls
321
- - **Efficient** — Minimise clicks for common tasks
322
- - **Desktop-optimised** — Admins typically use desktop browsers
323
-
324
- ### Theming
325
-
326
- Apps receive theme configuration from the parent platform via URL parameter (`?theme=base64…`) and PostMessage updates. See `docs/theme.system.md`.
327
-
328
- ---
329
-
330
- ## Common Hooks
331
-
332
- ```typescript
333
- // Fetch collection/product/proof data
334
- useCollectionData(collectionId)
335
- useProductData(collectionId, productId)
336
- useProofData(collectionId, productId, proofId)
337
-
338
- // Fetch app configuration
339
- useCollectionAppConfig(collectionId, appId)
340
- useProductAppConfig(collectionId, productId, appId)
341
-
342
- // Fetch app data (array of items)
343
- useCollectionAppData(collectionId, appId)
344
- useProductAppData(collectionId, productId, appId)
345
-
346
- // Fetch attestations
347
- useAttestationsData(collectionId, productId, proofId)
348
-
349
- // URL parameter management
350
- usePersistentQueryParams()
351
-
352
- // Theme management
353
- useSmartLinksTheme()
354
-
355
- // Liquid templating
356
- useLiquidTemplate(templateString, contextData)
357
- ```
358
-
359
- ---
360
-
361
- ## API Namespaces
362
-
363
- The SmartLinks SDK is organised into namespaces. See `docs/API_SUMMARY.md` for the complete reference. Key namespaces:
364
-
365
- - `appConfiguration` — Config and data storage (most apps use this)
366
- - `attestation` — Proof-level user/admin data
367
- - `interactions` — Event tracking and analytics
368
- - `ai` — AI content generation, chat, RAG (see `docs/ai.md`)
369
- - `auth` / `authKit` — Admin and end-user authentication
370
- - `contact` — Customer contact management
371
- - `comms` / `broadcasts` — Notifications and campaigns
372
- - `asset` — File/image uploads
373
- - `adminCards` — the collection's dashboard: `list`, `refresh`, `saveLayout` (see `docs/admin-cards.md`)
374
- - `realtime` — SmartLinks Realtime: `onChange`, `channel`, `onMine` (see `docs/realtime.md`)
375
-
376
- ---
377
-
378
- ## File Structure
379
-
380
- ```
381
- ├── index.html ← Public portal entry
382
- ├── admin.html ← Admin console entry
383
- ├── public/
384
- │ ├── app.manifest.json ← Public discovery manifest
385
- │ ├── app.admin.json ← Admin manifest (on-demand)
386
- │ └── ai-guide.md ← AI orchestrator prose guide
387
- ├── src/
388
- │ ├── main.tsx ← Public React entry
389
- │ ├── admin-main.tsx ← Admin React entry
390
- │ ├── App.tsx ← Shared providers (QueryClient, Toaster, etc.)
391
- │ ├── PublicApp.tsx ← Public app shell (routes only public pages)
392
- │ ├── AdminApp.tsx ← Admin app shell (routes only admin pages)
393
- │ ├── components/ ← Reusable UI components
394
- │ ├── containers/ ← Embeddable full-app containers
395
- │ ├── executor/ ← Executor bundle (SEO, LLM content, config API)
396
- │ ├── hooks/ ← React hooks (data fetching, state)
397
- │ ├── pages/
398
- │ │ ├── PublicPage.tsx ← Portal content (/#/)
399
- │ │ ├── AdminPage.tsx ← Admin content (admin.html#/)
400
- │ │ └── DevPage.tsx ← Development helper (dev only)
401
- │ ├── widgets/ ← Embeddable widget components
402
- │ └── utils/
403
- │ ├── smartlinks/ ← SmartLinks utilities
404
- │ └── theme.ts ← Theme utilities
405
- ├── vite.config.ts ← Multi-page build config
406
- ├── vite.config.widget.ts ← Widget library build config
407
- ├── vite.config.container.ts ← Container library build config
408
- └── vite.config.executor.ts ← Executor library build config
409
- ```
410
-
411
- ---
412
-
413
- ## Anti-Patterns to Avoid
414
-
415
- ❌ **Don't implement custom auth** — Use SmartLinks auth via `SL.auth.getAccount()`
416
-
417
- ❌ **Don't use BrowserRouter** — Always use HashRouter for iframe compatibility
418
-
419
- ❌ **Don't hardcode URLs** — Use relative paths and let the platform provide context
420
-
421
- ❌ **Don't store secrets in code** — Use environment variables or platform configuration
422
-
423
- ❌ **Don't assume screen size** — Support both mobile (Portal) and desktop (Admin)
424
-
425
- ❌ **Don't expose technical IDs** — Show human-readable names to users
426
-
427
- ❌ **Don't import AdminPage in PublicApp** — Keep bundles separate for optimal size
428
-
429
- ❌ **Don't use external AI services** — Use SmartLinks AI via `SL.ai`, not OpenAI/Anthropic/Lovable Cloud AI directly
430
-
431
- ❌ **Don't forget `admin: true`** — All admin write operations require this flag
432
-
433
- ---
434
-
435
- ## Quick Reference
436
-
437
- ### Initialise the API
438
-
439
- ```typescript
440
- import { initializeAPI } from '@/utils/smartlinks/initialization';
441
- initializeAPI(); // Call once at app startup
442
- ```
443
-
444
- ### Get Context from URL
445
-
446
- ```typescript
447
- const { persistentQueryParams } = usePersistentQueryParams();
448
- const { collectionId, productId, appId } = persistentQueryParams;
449
- ```
450
-
451
- ### Check Admin Status
452
-
453
- ```typescript
454
- const account = await SL.auth.getAccount();
455
- const isAdmin = account?.admin === true;
456
- ```
457
-
458
- ### Save Configuration (Admin Only)
459
-
460
- ```typescript
461
- await SL.appConfiguration.setConfig({
462
- collectionId, appId,
463
- config: { myKey: 'myValue' },
464
- admin: true // Required!
465
- });
466
- ```
467
-
468
- ### Handle Dark Mode + Theming
469
-
470
- ```typescript
471
- // In App.tsx — already integrated in the template
472
- useDarkMode(); // Handles ?dark=1 parameter
473
- useSmartLinksTheme(); // Handles ?theme=base64 parameter
474
- useDeepLinkSync(); // Syncs route changes to parent
475
- ```
476
-
477
- ### Deep Linking
478
-
479
- ```typescript
480
- const { navigateWithState, getAppState } = usePersistentQueryParams();
481
- const { tab = 'general' } = getAppState();
482
- navigateWithState('/', { tab: 'advanced' });
483
- ```
484
-
485
- See `docs/deep-link-discovery.md` for full implementation details.
1
+ # SmartLinks Microapp Development Guide
2
+
3
+ > **Platform revision:** R5 · **SDK:** `@proveanything/smartlinks@^3` · React 19 · Vite 8 · Router 7 · Tailwind 4 · TS 6.
4
+ > The canonical version/host stack lives in [host-dependency-contract.md](host-dependency-contract.md).
5
+
6
+ ---
7
+
8
+ ## What Is a SmartLinks Microapp?
9
+
10
+ SmartLinks connects **physical products to digital experiences**: each item has a digital identity — a **proof** — that a consumer reaches by scanning a QR / NFC tag, then claims and enriches over time. A **microapp** is a focused, embeddable React experience a brand adds to that product's digital life: product info, warranty registration, authenticity checks, manuals, competitions, loyalty, post-purchase support, and more.
11
+
12
+ Rather than baking every feature into the core platform, functionality is distributed across purpose-built apps, so a brand adds exactly the experiences its product needs. Each app:
13
+
14
+ - **Embeds** in the SmartLinks Portal (public) and Admin Console (management)
15
+ - **Shares context** through URL parameters (collection, product, proof)
16
+ - **Inherits identity** from the parent platform's auth
17
+ - **Adapts** to the brand's theme
18
+ - **Communicates** with the parent via postMessage for deep linking and navigation
19
+
20
+ ### Deployment Modes
21
+
22
+ Each microapp can be consumed in one or more of the following ways:
23
+
24
+ | Mode | Description |
25
+ |------|-------------|
26
+ | **Container** | Full app in parent React tree. ~150 KB+ lazy-loaded. The primary consumer surface. |
27
+ | **Iframe App** | Full React app inside an iframe. Fallback when sandboxing is required; still the standard for setup admin screens. |
28
+ | **Widget** | Lightweight React component in parent tree. ~10 KB, loaded immediately alongside the page. |
29
+ | **Mobile Admin Container** | Separate bundle for in-the-field operator/admin workflows on mobile. Built independently; may use Capacitor, Preact, or any other runtime. |
30
+ | **Executor** | JS library, no UI. Programmatic config, SEO metadata, LLM content for AI/server. |
31
+
32
+ Widgets and containers run in the parent's React tree (not iframes). Mobile Admin Containers are a separate bundle loaded by a dedicated mobile shell (Capacitor or PWA). Executors have no UI — they expose functions that AI orchestrators and the server call directly.
33
+
34
+ > **Admin vs consumer:** Admin experiences always ship as a **separate bundle** (`mobileAdmin` or iframe). The `containers` bundle is for consumer-facing surfaces only.
35
+
36
+ ---
37
+
38
+ ## SDK Documentation Reference
39
+
40
+ The SmartLinks SDK (`@proveanything/smartlinks`) includes comprehensive documentation in `node_modules/@proveanything/smartlinks/docs/`. **Always read these files for detailed implementation guidance.**
41
+
42
+ > Product endpoints: use `products` (plural) for new integrations. The older `product` (singular) namespace remains for backward compatibility and is deprecated.
43
+
44
+ > **SDK baseline: `@proveanything/smartlinks@^3`** (R5). Install/update with `npm install @proveanything/smartlinks@^3`. Moving an app from SDK 2: [`upgrading-to-3.md`](upgrading-to-3.md). Every list returns `{ items, nextCursor, count? }`: [`lists.md`](lists.md). Individual features may need a higher minor — see the relevant doc. The single source of truth for the R5 host/version stack is [`host-dependency-contract.md`](host-dependency-contract.md).
45
+
46
+ | Topic | File | When to Use |
47
+ |-------|------|-------------|
48
+ | **API Reference** | `docs/API_SUMMARY.md` | Complete SDK function reference, types, error handling |
49
+ | **Assets** | `docs/assets.md` | Asset object, AssetRef, upload, replace, soft-delete, restore, bulk-delete, public token-based uploads |
50
+ | **Files** | `docs/files.md` | Temporary or kept files, fetched by address, and text / Markdown / OCR / fields extracted from them; hidden from asset lists until kept |
51
+ | **Building React Components** | `docs/building-react-components.md` | **READ THIS FIRST** — Dual-mode rendering, router rules, useAppContext pattern |
52
+ | **Multi-Page Architecture** | `docs/mpa.md` | Build pipeline, entry points, multi-page setup, content hashing |
53
+ | **AI & Chat** | `docs/ai.md` | Chat completions, RAG, streaming, tool calling, voice, podcasts, TTS |
54
+ | **Analytics** | `docs/analytics.md` | Fire-and-forget page/click/tag analytics plus admin dashboard queries |
55
+ | **Translations** | `docs/translations.md` | Runtime translation lookup, local-first IndexedDB caching, and translation admin APIs |
56
+ | **Theming** | `docs/theme.system.md` | Implementing dynamic themes via URL params or postMessage |
57
+ | **Theme Defaults** | `docs/theme-defaults.md` | Default colour values for light/dark modes |
58
+ | **Internationalization** | `docs/i18n.md` | Adding multi-language support, translation patterns |
59
+ | **Widgets** | `docs/widgets.md` | Building widgets, shared deps contract, settings schema |
60
+ | **Containers** | `docs/containers.md` | Building full-app embeddable containers (lazy-loaded) |
61
+ | **Mobile Admin Container** | `docs/mobile-admin-container.md` | Building a separate Capacitor-aware mobile admin bundle for field operators |
62
+ | **Executors** | `docs/executor.md` | Building executor bundles for SEO, LLM content, programmatic config |
63
+ | **Server Functions** | `docs/server-functions.md` | App-authored server-side functions `(ctx, event) ⇒ result`: security model, runtime surface, invoking |
64
+ | **Agent Tools** | `docs/agent-tools.md` | Exposing your app's actions to the SmartLinks agent — an MCP facade over server functions; **opt-in per app, additive, no migration**; complements `app.admin.json` (functions serve/adapt it, don't replace it); live loop staged |
65
+ | **Deploying & Registering** | `docs/deploying-apps.md` | Getting your app into the platform: fast dev publish, channels, deploy keys, registering releases |
66
+ | **Host Dependency Contract (R5)** | `docs/host-dependency-contract.md` | The libraries the host provides (React 19, Router 7, Radix, liquidjs, …), the externalise-don't-bundle rule + Vite config, and React-18 backwards-compat |
67
+ | **CSS Baseline** (`sl-baseline` v1) | `docs/css-baseline.md` | A small, frozen, `sl-`-namespaced set of structural helpers (layout, spacing, responsive flow, type scale, motion) the SDK ships (`@proveanything/smartlinks/baseline.css`) and the host guarantees — a teachable floor for apps + AI content. No colours/fonts/components. Opt-in via `meta.cssBaseline` |
68
+ | **Deep Linking** | `docs/deep-link-discovery.md` | URL state management, navigable states, portal menus, AI nav |
69
+ | **Admin Views** | `docs/admin-views.md` | The admin side's screens by name (`adminViews`): the app's side menu, Studio's menu and the assistant; host → app `smartlinks:navigate`; `chrome=none` |
70
+ | **Portal Back Button** | `docs/portal-back-button.md` | Hierarchy-aware "up" navigation inside embedded apps |
71
+ | **Portal Request Action** | `docs/portal-request-action.md` | Triggering portal built-in actions (__qrScanner, __share, __logout, etc.) from sub-apps |
72
+ | **Interactions** | `docs/interactions.md` | Business events, outcomes, voting, competitions, and journey triggers |
73
+ | **App Config Files** | `docs/app-manifest.md` | Full field-by-field reference for both JSON config files |
74
+ | **Admin cards** | `docs/admin-cards.md` | Cards on the collection's dashboard in Studio: declare a card + an admin function returning its data; cached, refreshed only when its data changes |
75
+ | **Realtime** | `docs/realtime.md` | Live updates: change events (refetch when something changes) and declared app channels (a draw, a status) — no provider library or keys |
76
+ | **Liquid Templates** | `docs/liquid-templates.md` | Dynamic content rendering with LiquidJS |
77
+ | **Iframe Responder** | `docs/iframe-responder.md` | Iframe communication and proxy mode internals |
78
+ | **AI Guide Template** | `docs/ai-guide-template.md` | Template for creating `public/ai-guide.md` — customise per app |
79
+ | **Forms** | `docs/forms.md` | Form definitions, schema-driven rendering, submission patterns |
80
+ | **Auth Kit** | `docs/auth-kit.md` | End-user sign-in: email/password, magic links, phone OTP, Google OAuth |
81
+ | **EU Digital Product Passports** | `docs/dpp.md` | Passports hosted at their own address in the EU format (public + restricted views, versions), the brand's EU registry connection, and registering them (`dpp.*`) |
82
+ | **Service accounts** | `docs/service-accounts.md` | Identities for other systems (an ERP, a warehouse system) to work with one collection: own key, own access level, made and removed by the collection's admins |
83
+ | **Members** | `docs/members.md` | Signed-in members with a level (clubs, leagues, members' areas): the level field, members-only functions, joining rules |
84
+ | **Portal Request Login** | `docs/portal-request-login.md` | How sub-apps ask the portal to authenticate the user; hook and iframe postMessage contracts |
85
+ | **Portal Auth Broadcast** | `docs/portal-auth-broadcast.md` | Publishing custom auth flows to the portal; syncing sessions across containers and iframes |
86
+ | **Contact Search** | `docs/contact-search.md` | Admin contact search: free-text, typeahead, identity/tag/JSONB filters, and pagination |
87
+ | **App Records Pattern** | `docs/app-records-pattern.md` | Standard pattern for per-product/facet/variant/batch admin + public widget UIs |
88
+ | **UI Utils** | `docs/ui-utils.md` | `@proveanything/smartlinks-utils-ui` — React shells, hooks, and primitives for records-based apps |
89
+ | **Product/Proof Data Scoping** | `docs/proof-product-data-scoping.md` | Canonical spec for `product.data`/`.admin` and `proof.data`/`.admin`/`.values` (owner/personal) — who can read and write each bucket |
90
+ | **Proof Claiming** | `docs/proof-claiming-methods.md` | The ways a user claims a proof (serial, NFC, claim-set, auto-generate) |
91
+ | **Proof Share Grants** | `docs/proof-share-grants.md` | Delegated, scoped, revocable bearer access to a single proof (read/comment/verify-owner) |
92
+ | **Proof Ownership Transfer** | `docs/proof-ownership-transfer.md` | Moving a proof's single owner (directed transfer / open release), accept/cancel, and the state machine |
93
+ | **appConfig / Feature Flags** | `docs/appConfig.md` | `appConfig` settings contract — installed apps, `system.features`/`entitledAppGroups`/`meters`, `isFeatureEnabled()` helper |
94
+ | **App Objects** | `docs/app-objects.md` | Queryable domain objects — `app.records` / `app.cases` / `app.threads`: JSONB zones, visibility, policies, aggregations |
95
+ | **Bookings** | `docs/bookings.md` | Slots, bookings and allocations for events and appointments: no double-booking, holds, per-app public rules, `utils.freeTimes` |
96
+ | **Shop** | `docs/shop.md` | Sell from any site: prices, Stripe checkout into the seller's account, stock held while paying, physical and digital delivery (files, proofs, access), orders, shipping, refunds, order events for emails and integrations |
97
+ | **Payments** | `docs/payments.md` | One Stripe Connect account per business (Studio → Payments) for every app: in-page payments (Payment Element, Apple Pay, Google Pay) for donations and tips, connect status, reconciling an app's payments. No Stripe keys in apps |
98
+ | **Memberships** | `docs/memberships.md` | Paid plans (monthly, yearly, one-off) that keep a member's level and user groups switched on while paid: join pages, "my membership", cancel and change plan, staff grants, `ctx.sl.subscriptions` |
99
+ | **User groups** | `docs/user-groups.md` | Who may do what: named lists of people (staff who aren't admins, third parties), `userGroups` on a server function, `ctx.caller.userGroups`, `userGroups.mine()` |
100
+ | **Operations** | `docs/operations.md` | Factory floor and warehouse: work orders with stages, stock as quantities in containers, movements, bills of materials, made-from, sales and purchase orders, and a product's position (on hand, on order, needed, when it runs short) |
101
+ | **App Data Storage** | `docs/app-data-storage.md` | Decision guide: pick between `appConfiguration` / `userAppData` / `app.records` |
102
+ | **Attestations** | `docs/attestations.md` | Postgres attestations API (proof-level user/admin data; replaces the legacy Firestore path) |
103
+ | **Caching** | `docs/caching.md` | SDK GET cache tiers + TTLs, `invalidateCache({ exact })`, and `force`/push guidance |
104
+ | **Data Changed** | `docs/data-changed.md` | The host tells an open admin screen that records changed behind its back (the assistant, another app): `onDataChanged`, `postDataChanged`, and what to do with a form in mid-edit |
105
+ | **Comms & Broadcasts** | `docs/comms.md` | Transactional comms, campaigns, consent, push |
106
+ | **Container Tracking** | `docs/container-tracking.md` | Physical/logical **item** container groupings — *not* app containers (see containers.md) |
107
+ | **Lots** | `docs/lots.md` | Cross-SKU production "Lot" entity |
108
+ | **Loyalty** | `docs/loyalty.md` | Points, members, earning rules |
109
+ | **Integrations** | `docs/integrations.md` | Inbound/outbound external-system integration flows |
110
+ | **Connectors** | `docs/connectors.md` | Connector apps: the manifest `connector` block + the functions the integration engine calls |
111
+ | **Item Context** | `docs/item-context.md` | The `itemContext` container prop (serial / NFC authenticity context) |
112
+ | **Native Facade** | `docs/native-facade.md` | `host.native` / `SL.native` device-capability facade |
113
+ | **Product Facets** | `docs/PRODUCT_FACETS_SDK.md` | Facet API reference (admin + public endpoints, types) |
114
+ | **AI Tools & Skills** | `docs/ai-tools-and-skills.md` | Platform AI capability registry (web research, extraction, images) |
115
+ | **Proof Comms Triggers** | `docs/proof-comms-triggers.md` | Transactional comms fired as a side-effect of proof actions |
116
+
117
+ ---
118
+
119
+ ## Technical Overview
120
+
121
+ - **Iframe-based** — Apps run inside iframes in both the public Portal and Admin Console
122
+ - **Hash routing** — Uses `/#/` routes for iframe compatibility (e.g., `/#/`, `/#/admin`)
123
+ - **Context via URL params** — All contextual data is passed through URL parameters
124
+ - **SmartLinks NPM module** — All data access and platform interaction goes through `@proveanything/smartlinks`
125
+ - **No standalone auth** — Authentication is handled by the parent SmartLinks platform
126
+
127
+ > **Use the host-provided `SL`, don't instantiate your own.** When your app runs in a
128
+ > container/iframe, the host injects an already-initialized, authenticated SDK instance (the
129
+ > `SL` prop / the externalized `@proveanything/smartlinks` singleton). Import and use *that*.
130
+ > Calling `initializeApi()` yourself to spin up a **second** SDK instance is a common source
131
+ > of bugs: it won't share the host's auth (so it looks signed-out), won't share the host's
132
+ > cache (duplicate requests, stale data), and in proxy mode it bypasses the host's request
133
+ > routing. Rule of thumb: **host-provided `SL` for anything the platform owns** (auth, config,
134
+ > data, cache); only app-owned state is yours.
135
+ - **Multi-page build** — Separate bundles for public and admin — see `docs/mpa.md`
136
+ - **Embedded back navigation** — Use `docs/portal-back-button.md` when a sub-app has a real content hierarchy
137
+
138
+ ---
139
+
140
+ ## Data Model Hierarchy
141
+
142
+ ```
143
+ Collection (Business/Brand)
144
+ └── Product (Product Type/Definition)
145
+ └── Proof (Specific Instance with Owner)
146
+ └── Attestation (User/Admin Data on Proof)
147
+ ```
148
+
149
+ | Entity | Description | Example |
150
+ |--------|-------------|---------|
151
+ | **Collection** | Top-level container representing a business or brand | "Acme Wine Co." |
152
+ | **Product** | A type of product (not a specific item) | "2023 Cabernet Sauvignon" |
153
+ | **Proof** | A specific instance of a product, often with an owner | Bottle #12345 claimed by user@email.com |
154
+ | **Attestation** | Data attached to a proof by users or admins | Warranty registration, tasting notes |
155
+
156
+ ### URL Parameters
157
+
158
+ | Parameter | Type | Description |
159
+ |-----------|------|-------------|
160
+ | `collectionId` | string | The collection being viewed/managed |
161
+ | `productId` | string | The specific product (within collection) |
162
+ | `proofId` | string | The specific proof instance |
163
+ | `appId` | string | This app's unique identifier (for data scoping) |
164
+ | `dark` | `1` or `0` | Whether to use dark mode |
165
+ | `theme` | base64 | Full theme configuration (see `docs/theme.system.md`) |
166
+
167
+ ---
168
+
169
+ ## Authentication & Permissions
170
+
171
+ SmartLinks apps do **not** implement their own authentication. The parent platform handles all auth:
172
+
173
+ - Use `SL.auth.getAccount()` to check if a user is logged in
174
+ - The response includes whether the user is an `admin` or regular user
175
+ - Many SmartLinks API functions behave differently based on admin status
176
+
177
+ | Capability | Admin | Regular User |
178
+ |------------|-------|-------------|
179
+ | Read collection/product data | ✅ | ✅ |
180
+ | Write app configuration | ✅ | ❌ |
181
+ | Write attestations | ✅ | ✅ (own proofs only) |
182
+ | Access admin-only API fields | ✅ | ❌ |
183
+
184
+ ---
185
+
186
+ ## Data Storage Patterns
187
+
188
+ ### ⚠️ Critical: Admin Mode Flag
189
+
190
+ **When building admin interfaces, you MUST pass `admin: true` in API options.**
191
+
192
+ Without this flag, API calls use the public endpoint and will fail to write data:
193
+
194
+ ```typescript
195
+ // ❌ WRONG — will fail in admin interface
196
+ await SL.appConfiguration.setConfig({ collectionId, appId, config: myConfig });
197
+
198
+ // ✅ CORRECT — include admin: true
199
+ await SL.appConfiguration.setConfig({ collectionId, appId, config: myConfig, admin: true });
200
+ ```
201
+
202
+ This applies to all write operations: `setConfig`, `setDataItem`, `updateDataItem`, etc.
203
+
204
+ ### Endpoint Auth vs Data Visibility
205
+
206
+ `admin: true` is an endpoint selector, not a privacy marker.
207
+
208
+ - It tells the SDK to call the admin endpoint.
209
+ - It allows writes and admin reads.
210
+ - It does **not** mean every root-level field you save becomes admin-only.
211
+
212
+ For `appConfiguration` config blobs and `collection.getSettings()` groups, root-level fields are typically the public-facing settings. If you need private values such as tokens or secrets, store them inside a top-level `admin` object:
213
+
214
+ ```typescript
215
+ await SL.appConfiguration.setConfig({
216
+ collectionId,
217
+ appId,
218
+ admin: true,
219
+ config: {
220
+ publicLabel: 'Warranty Portal',
221
+ color: '#B68C2A',
222
+ admin: {
223
+ accessToken: 'secret-token'
224
+ }
225
+ }
226
+ })
227
+ ```
228
+
229
+ Public reads omit the `admin` block. Admin reads include it.
230
+
231
+ ### Config vs Data
232
+
233
+ | Storage Type | Function | Use Case |
234
+ |-------------|---------|---------|
235
+ | **Config** (`getConfig`/`setConfig`) | Single JSON document | App settings, feature flags, global options |
236
+ | **Data** (`getData`/`setDataItem`) | Array of documents with IDs | Lists of items, records, entries |
237
+ | **App Objects** (`app.records` / `app.cases` / `app.threads`) | Queryable domain objects | Real app entities, workflows, conversations, richer access control |
238
+
239
+ Both can be scoped to **collection level** or **product level** by including `productId`.
240
+
241
+ For config/settings visibility, remember: root fields are the normal shared payload, while a reserved top-level `admin` object is the place for admin-only values.
242
+
243
+ Prefer `app.records` over `setDataItem` when the data is becoming a real entity that needs lifecycle, ownership, visibility, relationships, or filtering. Keep `setDataItem` for simple keyed scoped documents and config-adjacent content.
244
+
245
+ ### Feature Flags & Entitlements (`appConfig`)
246
+
247
+ The platform-owned `appConfig` settings group (`system.features`, `system.meters`, `system.entitledAppGroups`, installed `apps[]`) tells a microapp what's installed and entitled for a collection. Use `SL.appConfiguration.isFeatureEnabled(collectionId, flag)` to gate a feature — it's the standard, cache-backed way to do this rather than hand-rolling a `getConfig` call:
248
+
249
+ ```ts
250
+ if (await SL.appConfiguration.isFeatureEnabled(collectionId, 'custom_domain')) {
251
+ enableCustomDomainUI();
252
+ }
253
+ ```
254
+
255
+ It's async (the first check for a collection has nothing cached yet); `SL.appConfiguration.isFeatureEnabledSync()` gives a synchronous, cache-only read (`boolean | undefined`) for callers that warmed the cache earlier and can't await. See `docs/appConfig.md` for the full contract, including `systemPrivate` (admin-only overrides, always stripped for non-admin reads).
256
+
257
+ ### Attestations (Proof-level data)
258
+
259
+ For data attached to specific proof instances, use `SL.attestation.create()` and `SL.attestation.list()`.
260
+
261
+ ### Custom Data Scoping (Product & Proof)
262
+
263
+ `product.data`/`product.admin` and `proof.data`/`proof.admin`/`proof.values` are the canonical buckets for custom fields on products and proofs — `data` is public and business-writable, `admin` is business-only, and `proof.values` additionally supports owner-scoped (`values.owner`) and per-user (`values.personal[userId]`) sub-keys. This is a different mechanism from the app-scoped storage in `docs/app-data-storage.md` (which is for app-owned config/records, not the product/proof documents themselves).
264
+
265
+ See `docs/proof-product-data-scoping.md` for the full read/write authority matrix, worked examples, and the `productFields`/`proofFields` collection-settings schemas that drive field-config editors.
266
+
267
+ ---
268
+
269
+ ## Error Handling
270
+
271
+ The SmartLinks SDK returns structured `SmartlinksApiError` objects. Use `instanceof SmartlinksApiError` to access `.statusCode`, `.message`, and helper methods:
272
+
273
+ - `.isAuthError()` — 401/403 responses
274
+ - `.isNotFound()` — 404 responses
275
+ - `.isRateLimited()` — 429 responses
276
+ - `.isServerError()` — 5xx responses
277
+
278
+ See `docs/API_SUMMARY.md` for complete error handling documentation.
279
+
280
+ ---
281
+
282
+ ## AI Integration
283
+
284
+ SmartLinks provides comprehensive AI capabilities through the `SL.ai` namespace. **Always use SmartLinks AI for microapps** — do not integrate external AI services (OpenAI, Anthropic, Lovable Cloud AI, etc.) directly.
285
+
286
+ Key capabilities: chat completions (streaming + tool calling), RAG document Q&A, voice input/output, podcast generation, text-to-speech, model listing.
287
+
288
+ See `docs/ai.md` for complete documentation.
289
+
290
+ ---
291
+
292
+ ## Interactions & Event Tracking
293
+
294
+ The `SL.interactions` namespace tracks user engagement — competition entries, votes, form submissions, warranty registrations. Events can trigger automated journeys and communications.
295
+
296
+ **The one rule:** you never choose an interaction id. In admin, `SL.interactions.ensureType(collectionId, { appId, key: 'vote', … })` finds-or-creates the type and returns its server-minted `id`; store it in app config (`interactionIds: { vote: type.id }`); everywhere else — public widgets included — read `interactionIds.vote` from config and pass that as `interactionId`. Never write an interactionId as a string literal.
297
+
298
+ Key functions: `submitPublicEvent()`, `appendEvent()` (admin), `countsByOutcome()`, `query()`.
299
+
300
+ See `docs/interactions.md` for complete documentation.
301
+
302
+ ---
303
+
304
+ ## Liquid Templating
305
+
306
+ Use the `<LiquidContent>` component, `useLiquidTemplate` hook, and `renderLiquid` utility for admin-configured dynamic content using Liquid syntax.
307
+
308
+ See `docs/liquid-templates.md` for full context variables, filters, and examples.
309
+
310
+ ---
311
+
312
+ ## Design Principles
313
+
314
+ ### Public Interface (Portal)
315
+
316
+ - **Mobile-first** — Assume users are on phones
317
+ - **Non-technical** — Never show raw IDs or technical data
318
+ - **Accessible** — Follow WCAG guidelines
319
+
320
+ ### Admin Interface
321
+
322
+ - **Feature-rich** — Power users expect advanced controls
323
+ - **Efficient** — Minimise clicks for common tasks
324
+ - **Desktop-optimised** — Admins typically use desktop browsers
325
+
326
+ ### Theming
327
+
328
+ Apps receive theme configuration from the parent platform via URL parameter (`?theme=base64…`) and PostMessage updates. See `docs/theme.system.md`.
329
+
330
+ ---
331
+
332
+ ## Common Hooks
333
+
334
+ ```typescript
335
+ // Fetch collection/product/proof data
336
+ useCollectionData(collectionId)
337
+ useProductData(collectionId, productId)
338
+ useProofData(collectionId, productId, proofId)
339
+
340
+ // Fetch app configuration
341
+ useCollectionAppConfig(collectionId, appId)
342
+ useProductAppConfig(collectionId, productId, appId)
343
+
344
+ // Fetch app data (array of items)
345
+ useCollectionAppData(collectionId, appId)
346
+ useProductAppData(collectionId, productId, appId)
347
+
348
+ // Fetch attestations
349
+ useAttestationsData(collectionId, productId, proofId)
350
+
351
+ // URL parameter management
352
+ usePersistentQueryParams()
353
+
354
+ // Theme management
355
+ useSmartLinksTheme()
356
+
357
+ // Liquid templating
358
+ useLiquidTemplate(templateString, contextData)
359
+ ```
360
+
361
+ ---
362
+
363
+ ## API Namespaces
364
+
365
+ The SmartLinks SDK is organised into namespaces. See `docs/API_SUMMARY.md` for the complete reference. Key namespaces:
366
+
367
+ - `appConfiguration` — Config and data storage (most apps use this)
368
+ - `attestation` — Proof-level user/admin data
369
+ - `interactions` — Event tracking and analytics
370
+ - `ai` — AI content generation, chat, RAG (see `docs/ai.md`)
371
+ - `auth` / `authKit` — Admin and end-user authentication
372
+ - `contact` — Customer contact management
373
+ - `comms` / `broadcasts` — Notifications and campaigns
374
+ - `asset` — File/image uploads
375
+ - `adminCards` — the collection's dashboard: `list`, `refresh`, `saveLayout` (see `docs/admin-cards.md`)
376
+ - `realtime` — SmartLinks Realtime: `onChange`, `channel`, `onMine` (see `docs/realtime.md`)
377
+
378
+ ---
379
+
380
+ ## File Structure
381
+
382
+ ```
383
+ ├── index.html ← Public portal entry
384
+ ├── admin.html ← Admin console entry
385
+ ├── public/
386
+ │ ├── app.manifest.json ← Public discovery manifest
387
+ │ ├── app.admin.json ← Admin manifest (on-demand)
388
+ │ └── ai-guide.md ← AI orchestrator prose guide
389
+ ├── src/
390
+ │ ├── main.tsx ← Public React entry
391
+ │ ├── admin-main.tsx ← Admin React entry
392
+ │ ├── App.tsx ← Shared providers (QueryClient, Toaster, etc.)
393
+ │ ├── PublicApp.tsx ← Public app shell (routes only public pages)
394
+ │ ├── AdminApp.tsx ← Admin app shell (routes only admin pages)
395
+ │ ├── components/ ← Reusable UI components
396
+ │ ├── containers/ ← Embeddable full-app containers
397
+ │ ├── executor/ ← Executor bundle (SEO, LLM content, config API)
398
+ │ ├── hooks/ ← React hooks (data fetching, state)
399
+ │ ├── pages/
400
+ │ │ ├── PublicPage.tsx ← Portal content (/#/)
401
+ │ │ ├── AdminPage.tsx ← Admin content (admin.html#/)
402
+ │ │ └── DevPage.tsx ← Development helper (dev only)
403
+ │ ├── widgets/ ← Embeddable widget components
404
+ │ └── utils/
405
+ │ ├── smartlinks/ ← SmartLinks utilities
406
+ │ └── theme.ts ← Theme utilities
407
+ ├── vite.config.ts ← Multi-page build config
408
+ ├── vite.config.widget.ts ← Widget library build config
409
+ ├── vite.config.container.ts ← Container library build config
410
+ └── vite.config.executor.ts ← Executor library build config
411
+ ```
412
+
413
+ ---
414
+
415
+ ## Anti-Patterns to Avoid
416
+
417
+ ❌ **Don't implement custom auth** — Use SmartLinks auth via `SL.auth.getAccount()`
418
+
419
+ ❌ **Don't use BrowserRouter** — Always use HashRouter for iframe compatibility
420
+
421
+ ❌ **Don't hardcode URLs** — Use relative paths and let the platform provide context
422
+
423
+ ❌ **Don't store secrets in code** — Use environment variables or platform configuration
424
+
425
+ ❌ **Don't assume screen size** — Support both mobile (Portal) and desktop (Admin)
426
+
427
+ ❌ **Don't expose technical IDs** — Show human-readable names to users
428
+
429
+ ❌ **Don't import AdminPage in PublicApp** — Keep bundles separate for optimal size
430
+
431
+ ❌ **Don't use external AI services** — Use SmartLinks AI via `SL.ai`, not OpenAI/Anthropic/Lovable Cloud AI directly
432
+
433
+ ❌ **Don't forget `admin: true`** — All admin write operations require this flag
434
+
435
+ ---
436
+
437
+ ## Quick Reference
438
+
439
+ ### Initialise the API
440
+
441
+ ```typescript
442
+ import { initializeAPI } from '@/utils/smartlinks/initialization';
443
+ initializeAPI(); // Call once at app startup
444
+ ```
445
+
446
+ ### Get Context from URL
447
+
448
+ ```typescript
449
+ const { persistentQueryParams } = usePersistentQueryParams();
450
+ const { collectionId, productId, appId } = persistentQueryParams;
451
+ ```
452
+
453
+ ### Check Admin Status
454
+
455
+ ```typescript
456
+ const account = await SL.auth.getAccount();
457
+ const isAdmin = account?.admin === true;
458
+ ```
459
+
460
+ ### Save Configuration (Admin Only)
461
+
462
+ ```typescript
463
+ await SL.appConfiguration.setConfig({
464
+ collectionId, appId,
465
+ config: { myKey: 'myValue' },
466
+ admin: true // Required!
467
+ });
468
+ ```
469
+
470
+ ### Handle Dark Mode + Theming
471
+
472
+ ```typescript
473
+ // In App.tsx — already integrated in the template
474
+ useDarkMode(); // Handles ?dark=1 parameter
475
+ useSmartLinksTheme(); // Handles ?theme=base64 parameter
476
+ useDeepLinkSync(); // Syncs route changes to parent
477
+ ```
478
+
479
+ ### Deep Linking
480
+
481
+ ```typescript
482
+ const { navigateWithState, getAppState } = usePersistentQueryParams();
483
+ const { tab = 'general' } = getAppState();
484
+ navigateWithState('/', { tab: 'advanced' });
485
+ ```
486
+
487
+ See `docs/deep-link-discovery.md` for full implementation details.