@proveanything/smartlinks 2.2.1 → 3.0.0-alpha.1

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 (326) hide show
  1. package/README.md +741 -754
  2. package/dist/README.md +573 -573
  3. package/dist/adminCardsView.js +55 -55
  4. package/dist/api/adminCards.d.ts +8 -0
  5. package/dist/api/adminCards.js +9 -1
  6. package/dist/api/ai.d.ts +22 -11
  7. package/dist/api/ai.js +18 -14
  8. package/dist/api/analytics.d.ts +13 -0
  9. package/dist/api/analytics.js +13 -0
  10. package/dist/api/appConfiguration.d.ts +17 -14
  11. package/dist/api/appConfiguration.js +14 -12
  12. package/dist/api/appObjects.d.ts +80 -16
  13. package/dist/api/appObjects.js +74 -11
  14. package/dist/api/asset.d.ts +55 -19
  15. package/dist/api/asset.js +52 -32
  16. package/dist/api/attestation.d.ts +3 -2
  17. package/dist/api/attestation.js +1 -1
  18. package/dist/api/attestations.d.ts +22 -7
  19. package/dist/api/attestations.js +22 -7
  20. package/dist/api/authKit.d.ts +22 -5
  21. package/dist/api/authKit.js +21 -4
  22. package/dist/api/batch.d.ts +23 -16
  23. package/dist/api/batch.js +19 -13
  24. package/dist/api/bookings.d.ts +45 -9
  25. package/dist/api/bookings.js +39 -3
  26. package/dist/api/broadcasts.d.ts +26 -6
  27. package/dist/api/broadcasts.js +22 -2
  28. package/dist/api/claimSet.d.ts +48 -13
  29. package/dist/api/claimSet.js +43 -7
  30. package/dist/api/collection.d.ts +20 -6
  31. package/dist/api/collection.js +19 -8
  32. package/dist/api/comms.d.ts +43 -12
  33. package/dist/api/comms.js +43 -13
  34. package/dist/api/conditions.d.ts +12 -2
  35. package/dist/api/conditions.js +10 -1
  36. package/dist/api/config.d.ts +15 -2
  37. package/dist/api/config.js +12 -0
  38. package/dist/api/contact.d.ts +34 -13
  39. package/dist/api/contact.js +35 -10
  40. package/dist/api/containers.d.ts +41 -23
  41. package/dist/api/containers.js +37 -21
  42. package/dist/api/crate.d.ts +9 -8
  43. package/dist/api/crate.js +8 -8
  44. package/dist/api/dpp.d.ts +58 -10
  45. package/dist/api/dpp.js +57 -15
  46. package/dist/api/facets.d.ts +71 -0
  47. package/dist/api/facets.js +71 -0
  48. package/dist/api/files.d.ts +11 -5
  49. package/dist/api/files.js +9 -1
  50. package/dist/api/form.d.ts +9 -2
  51. package/dist/api/form.js +7 -1
  52. package/dist/api/index.d.ts +0 -1
  53. package/dist/api/index.js +0 -1
  54. package/dist/api/integrations.d.ts +82 -27
  55. package/dist/api/integrations.js +63 -7
  56. package/dist/api/interactions.d.ts +42 -6
  57. package/dist/api/interactions.js +41 -5
  58. package/dist/api/jobs.d.ts +9 -2
  59. package/dist/api/jobs.js +6 -0
  60. package/dist/api/journeys.d.ts +13 -2
  61. package/dist/api/journeys.js +10 -1
  62. package/dist/api/journeysAnalytics.d.ts +12 -3
  63. package/dist/api/journeysAnalytics.js +9 -1
  64. package/dist/api/knowledge.d.ts +43 -10
  65. package/dist/api/knowledge.js +37 -5
  66. package/dist/api/location.d.ts +10 -3
  67. package/dist/api/location.js +7 -1
  68. package/dist/api/lots.d.ts +40 -13
  69. package/dist/api/lots.js +38 -8
  70. package/dist/api/loyalty.d.ts +70 -12
  71. package/dist/api/loyalty.js +60 -3
  72. package/dist/api/nfc.d.ts +8 -2
  73. package/dist/api/nfc.js +6 -1
  74. package/dist/api/order.d.ts +51 -160
  75. package/dist/api/order.js +46 -208
  76. package/dist/api/partner.d.ts +41 -8
  77. package/dist/api/partner.js +36 -4
  78. package/dist/api/products.d.ts +41 -8
  79. package/dist/api/products.js +33 -4
  80. package/dist/api/proof.d.ts +50 -13
  81. package/dist/api/proof.js +43 -7
  82. package/dist/api/realtime.d.ts +1 -11
  83. package/dist/api/realtime.js +1 -22
  84. package/dist/api/secrets.d.ts +25 -5
  85. package/dist/api/secrets.js +21 -2
  86. package/dist/api/segments.d.ts +26 -6
  87. package/dist/api/segments.js +22 -2
  88. package/dist/api/serviceAccounts.d.ts +8 -1
  89. package/dist/api/serviceAccounts.js +8 -1
  90. package/dist/api/shop.d.ts +41 -13
  91. package/dist/api/shop.js +35 -4
  92. package/dist/api/subscriptions.d.ts +47 -12
  93. package/dist/api/subscriptions.js +40 -4
  94. package/dist/api/tags.d.ts +40 -19
  95. package/dist/api/tags.js +38 -18
  96. package/dist/api/template.d.ts +31 -3
  97. package/dist/api/template.js +27 -0
  98. package/dist/api/translations.d.ts +17 -2
  99. package/dist/api/translations.js +14 -0
  100. package/dist/api/userGroups.d.ts +35 -9
  101. package/dist/api/userGroups.js +30 -5
  102. package/dist/api/variant.d.ts +11 -3
  103. package/dist/api/variant.js +9 -2
  104. package/dist/api/wallet.d.ts +23 -10
  105. package/dist/api/wallet.js +20 -2
  106. package/dist/apiVersion.d.ts +1 -1
  107. package/dist/apiVersion.js +1 -1
  108. package/dist/baseline.css +194 -194
  109. package/dist/docs/API_SUMMARY.md +1389 -2298
  110. package/dist/docs/PRODUCT_FACETS_SDK.md +10 -15
  111. package/dist/docs/admin-cards.md +189 -189
  112. package/dist/docs/admin-lists-and-pickers.md +1 -1
  113. package/dist/docs/agent-tools.md +156 -156
  114. package/dist/docs/ai-tools-and-skills.md +180 -180
  115. package/dist/docs/ai.md +1721 -1721
  116. package/dist/docs/analytics.md +3 -2
  117. package/dist/docs/api-versions.md +85 -76
  118. package/dist/docs/app-data-storage.md +277 -277
  119. package/dist/docs/app-docs.md +73 -73
  120. package/dist/docs/app-manifest.md +852 -852
  121. package/dist/docs/app-objects.md +38 -50
  122. package/dist/docs/app-records-pattern.md +388 -388
  123. package/dist/docs/appConfig.md +550 -550
  124. package/dist/docs/assets.md +17 -3
  125. package/dist/docs/assistant-apps.md +172 -172
  126. package/dist/docs/assistant-context.md +119 -119
  127. package/dist/docs/attestations.md +5 -4
  128. package/dist/docs/auth-kit.md +1 -1
  129. package/dist/docs/bookings.md +442 -442
  130. package/dist/docs/comms.md +689 -686
  131. package/dist/docs/connectors.md +340 -340
  132. package/dist/docs/contact-search.md +4 -3
  133. package/dist/docs/container-tracking.md +7 -7
  134. package/dist/docs/css-baseline.md +133 -133
  135. package/dist/docs/customer-guide.md +70 -70
  136. package/dist/docs/deploying-apps.md +340 -340
  137. package/dist/docs/dpp.md +115 -115
  138. package/dist/docs/entitlements.md +90 -90
  139. package/dist/docs/executor.md +1 -1
  140. package/dist/docs/files.md +69 -69
  141. package/dist/docs/forms.md +1 -1
  142. package/dist/docs/headless-providers.md +3 -3
  143. package/dist/docs/host-dependency-contract.md +252 -210
  144. package/dist/docs/integrations.md +322 -322
  145. package/dist/docs/interactions.md +544 -545
  146. package/dist/docs/item-context.md +181 -181
  147. package/dist/docs/knowledge.md +105 -102
  148. package/dist/docs/lists.md +114 -0
  149. package/dist/docs/lots.md +112 -111
  150. package/dist/docs/loyalty.md +348 -352
  151. package/dist/docs/members.md +183 -183
  152. package/dist/docs/memberships.md +150 -149
  153. package/dist/docs/mobile-admin-container.md +693 -693
  154. package/dist/docs/operations.md +281 -281
  155. package/dist/docs/overview.md +485 -485
  156. package/dist/docs/proof-claiming-methods.md +6 -6
  157. package/dist/docs/proof-comms-triggers.md +142 -142
  158. package/dist/docs/proof-ownership-transfer.md +155 -155
  159. package/dist/docs/proof-product-data-scoping.md +462 -462
  160. package/dist/docs/proof-share-grants.md +305 -305
  161. package/dist/docs/realtime.md +139 -138
  162. package/dist/docs/records-admin-pattern.md +304 -304
  163. package/dist/docs/server-functions.md +2 -2
  164. package/dist/docs/service-accounts.md +64 -64
  165. package/dist/docs/shop.md +4 -2
  166. package/dist/docs/site-seo.md +2 -1
  167. package/dist/docs/standard-query.md +187 -187
  168. package/dist/docs/tag-codes.md +97 -97
  169. package/dist/docs/tag-ranges.md +106 -106
  170. package/dist/docs/theme-tokens.md +252 -252
  171. package/dist/docs/translations.md +6 -1
  172. package/dist/docs/upgrading-to-3.md +430 -0
  173. package/dist/docs/user-groups.md +4 -4
  174. package/dist/docs/utils.md +1 -1
  175. package/dist/docs/wallet-passes.md +107 -107
  176. package/dist/docs/websites.md +123 -123
  177. package/dist/headless.d.ts +1 -1
  178. package/dist/headless.js +2 -2
  179. package/dist/http.d.ts +15 -2
  180. package/dist/http.js +60 -2
  181. package/dist/index.d.ts +7 -8
  182. package/dist/index.js +2 -0
  183. package/dist/list.d.ts +24 -0
  184. package/dist/list.js +80 -0
  185. package/dist/mobile-admin/types.d.ts +0 -16
  186. package/dist/openapi.yaml +290 -2723
  187. package/dist/shared-dependencies.d.ts +3 -3
  188. package/dist/shared-dependencies.js +13 -5
  189. package/dist/site.d.ts +1 -7
  190. package/dist/site.js +1 -14
  191. package/dist/theme-boot.js +82 -82
  192. package/dist/theme.css +75 -75
  193. package/dist/types/adminCards.d.ts +6 -3
  194. package/dist/types/ai.d.ts +0 -6
  195. package/dist/types/analytics.d.ts +5 -8
  196. package/dist/types/appManifest.d.ts +4 -5
  197. package/dist/types/appObjects.d.ts +14 -18
  198. package/dist/types/appObjects.js +0 -1
  199. package/dist/types/appOptions.d.ts +18 -0
  200. package/dist/types/asset.d.ts +3 -22
  201. package/dist/types/attestations.d.ts +7 -10
  202. package/dist/types/batch.d.ts +6 -14
  203. package/dist/types/bookings.d.ts +22 -4
  204. package/dist/types/broadcasts.d.ts +5 -13
  205. package/dist/types/broadcasts.js +0 -1
  206. package/dist/types/claimSet.d.ts +0 -5
  207. package/dist/types/comms.d.ts +11 -9
  208. package/dist/types/contact.d.ts +5 -29
  209. package/dist/types/contact.js +0 -13
  210. package/dist/types/containers.d.ts +15 -26
  211. package/dist/types/crate.d.ts +4 -12
  212. package/dist/types/dpp.d.ts +3 -3
  213. package/dist/types/dpp.js +0 -1
  214. package/dist/types/error.d.ts +8 -5
  215. package/dist/types/error.js +12 -5
  216. package/dist/types/facets.d.ts +15 -15
  217. package/dist/types/index.d.ts +1 -0
  218. package/dist/types/index.js +1 -0
  219. package/dist/types/integrations.d.ts +3 -28
  220. package/dist/types/interaction.d.ts +3 -9
  221. package/dist/types/jobs.d.ts +3 -8
  222. package/dist/types/jobs.js +0 -1
  223. package/dist/types/journeys.d.ts +3 -8
  224. package/dist/types/journeys.js +0 -1
  225. package/dist/types/journeysAnalytics.d.ts +0 -1
  226. package/dist/types/list.d.ts +24 -0
  227. package/dist/types/list.js +2 -0
  228. package/dist/types/location.d.ts +0 -4
  229. package/dist/types/lots.d.ts +0 -9
  230. package/dist/types/loyalty.d.ts +0 -9
  231. package/dist/types/order.d.ts +7 -134
  232. package/dist/types/product.d.ts +11 -24
  233. package/dist/types/proof.d.ts +16 -0
  234. package/dist/types/realtime.d.ts +0 -29
  235. package/dist/types/segments.d.ts +5 -13
  236. package/dist/types/segments.js +0 -1
  237. package/dist/types/serviceAccounts.d.ts +3 -2
  238. package/dist/types/serviceAccounts.js +0 -1
  239. package/dist/types/shop.d.ts +5 -12
  240. package/dist/types/shop.js +0 -4
  241. package/dist/types/subscriptions.d.ts +18 -0
  242. package/dist/types/subscriptions.js +0 -8
  243. package/dist/types/tags.d.ts +6 -16
  244. package/dist/types/tags.js +0 -7
  245. package/dist/types/translations.d.ts +3 -9
  246. package/dist/types/variant.d.ts +0 -2
  247. package/dist/version.d.ts +1 -1
  248. package/dist/version.js +1 -1
  249. package/docs/API_SUMMARY.md +1389 -2298
  250. package/docs/PRODUCT_FACETS_SDK.md +10 -15
  251. package/docs/admin-cards.md +189 -189
  252. package/docs/admin-lists-and-pickers.md +1 -1
  253. package/docs/agent-tools.md +156 -156
  254. package/docs/ai-tools-and-skills.md +180 -180
  255. package/docs/ai.md +1721 -1721
  256. package/docs/analytics.md +3 -2
  257. package/docs/api-versions.md +85 -76
  258. package/docs/app-data-storage.md +277 -277
  259. package/docs/app-docs.md +73 -73
  260. package/docs/app-manifest.md +852 -852
  261. package/docs/app-objects.md +38 -50
  262. package/docs/app-records-pattern.md +388 -388
  263. package/docs/appConfig.md +550 -550
  264. package/docs/assets.md +17 -3
  265. package/docs/assistant-apps.md +172 -172
  266. package/docs/assistant-context.md +119 -119
  267. package/docs/attestations.md +5 -4
  268. package/docs/auth-kit.md +1 -1
  269. package/docs/bookings.md +442 -442
  270. package/docs/comms.md +689 -686
  271. package/docs/connectors.md +340 -340
  272. package/docs/contact-search.md +4 -3
  273. package/docs/container-tracking.md +7 -7
  274. package/docs/css-baseline.md +133 -133
  275. package/docs/customer-guide.md +70 -70
  276. package/docs/deploying-apps.md +340 -340
  277. package/docs/dpp.md +115 -115
  278. package/docs/entitlements.md +90 -90
  279. package/docs/executor.md +1 -1
  280. package/docs/files.md +69 -69
  281. package/docs/forms.md +1 -1
  282. package/docs/headless-providers.md +3 -3
  283. package/docs/host-dependency-contract.md +252 -210
  284. package/docs/integrations.md +322 -322
  285. package/docs/interactions.md +544 -545
  286. package/docs/item-context.md +181 -181
  287. package/docs/knowledge.md +105 -102
  288. package/docs/lists.md +114 -0
  289. package/docs/lots.md +112 -111
  290. package/docs/loyalty.md +348 -352
  291. package/docs/members.md +183 -183
  292. package/docs/memberships.md +150 -149
  293. package/docs/mobile-admin-container.md +693 -693
  294. package/docs/operations.md +281 -281
  295. package/docs/overview.md +485 -485
  296. package/docs/proof-claiming-methods.md +6 -6
  297. package/docs/proof-comms-triggers.md +142 -142
  298. package/docs/proof-ownership-transfer.md +155 -155
  299. package/docs/proof-product-data-scoping.md +462 -462
  300. package/docs/proof-share-grants.md +305 -305
  301. package/docs/realtime.md +139 -138
  302. package/docs/server-functions.md +2 -2
  303. package/docs/service-accounts.md +64 -64
  304. package/docs/shop.md +4 -2
  305. package/docs/site-seo.md +2 -1
  306. package/docs/standard-query.md +187 -187
  307. package/docs/tag-codes.md +97 -97
  308. package/docs/tag-ranges.md +106 -106
  309. package/docs/theme-lookbook.v1.json +120 -120
  310. package/docs/theme-tokens.md +252 -252
  311. package/docs/translations.md +6 -1
  312. package/docs/upgrading-to-3.md +430 -0
  313. package/docs/user-groups.md +4 -4
  314. package/docs/utils.md +1 -1
  315. package/docs/wallet-passes.md +107 -107
  316. package/docs/websites.md +123 -123
  317. package/openapi.yaml +290 -2723
  318. package/package.json +8 -4
  319. package/scripts/headless-check.mjs +87 -87
  320. package/scripts/lib/bare-imports.mjs +57 -57
  321. package/scripts/lib/keyed-app-data.mjs +21 -21
  322. package/scripts/lib/upgrade.mjs +512 -0
  323. package/scripts/publish.mjs +272 -272
  324. package/scripts/register-release.mjs +91 -91
  325. package/scripts/upgrade.mjs +56 -0
  326. package/upgrade/3.json +2213 -0
@@ -1,485 +1,485 @@
1
- # SmartLinks Microapp Development Guide
2
-
3
- > **Platform revision:** R5 · **SDK:** `@proveanything/smartlinks@^2` · 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@^2.0`** (R5). Install/update with `npm install @proveanything/smartlinks@^2.0`. 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
+ | **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.