@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,550 +1,550 @@
1
- # `appConfig` — collection settings contract
2
-
3
- **Settings group:** `appConfig` (a.k.a. `settings/appConfig`, app id `appConfig`)
4
- **Owner:** platform (`entitlements-reconcile` edge function is the sole authority for the `system` block)
5
- **Written by:** wizard signup, admin tools, module installer, add-on toggles, `entitlements-reconcile`
6
- **Read by:** every microapp that needs to know "what is installed / entitled / metered" for a collection
7
-
8
- This document is the source of truth for the shape and semantics of the
9
- `appConfig` settings document, and for the SDK helpers microapps should use
10
- to read it — in particular `appConfiguration.isFeatureEnabled()`, the
11
- standard way for a subapp to check whether a feature flag is on for a
12
- collection.
13
-
14
- ---
15
-
16
- ## 0. TypeScript definition
17
-
18
- The SDK exports this as `AppConfigSettings` (see `src/types/appConfiguration.ts`).
19
- The document also carries a `systemPrivate` block (admin-only overrides and
20
- internal metadata) that's stripped by the API for non-admin callers — see §5.
21
- Its shape is intentionally not part of this SDK's public type surface, so it
22
- doesn't appear below; treat it as opaque and never rely on it from client code.
23
-
24
- ```ts
25
- /** Full appConfig settings document for a SmartLinks collection. */
26
- export interface AppConfigSettings {
27
- id: 'appConfig';
28
-
29
- // ── USER-OWNED (client may PATCH freely) ──────────────────────────
30
- /** Installed modules — the customer's chosen surface. */
31
- apps: AppEntry[];
32
- /** Optional mirror of add-on keys the customer has toggled. */
33
- addOns?: string[];
34
- /** Wizard hint — which base plan the customer picked pre-checkout. */
35
- requestedBasePlanId?: string;
36
-
37
- /** How the account handles individual physical items. */
38
- itemRecordMode?: 'registered' | 'owned' | null;
39
- /** What the collection has switched on (absent key = on) — see §8a. */
40
- enabled?: Record<string, boolean>;
41
-
42
- // ── SYSTEM-OWNED, PUBLIC (reconcile writes; client read-only) ─────
43
- /** Resolved entitlement truth. Read this to gate features. */
44
- system?: SystemBlock;
45
-
46
- // Also carries a `systemPrivate` block, stripped for non-admin reads.
47
- // Not part of the public SDK contract — see §5.
48
- }
49
-
50
- /** One installed module instance on this collection. */
51
- export interface AppEntry {
52
- id: string; // instance id (typically === uniqueName)
53
- uniqueName: string; // module id from the module catalog
54
- customName?: string; // display name, overrideable
55
- active: boolean; // user toggle
56
- all?: boolean; // legacy scope flag
57
- live?: boolean; // legacy flag
58
- faIcon?: string; // optional FA icon override
59
- versionChannel?: 'stable' | 'beta' | 'dev';
60
- /** Set by reconcile when app category is not in entitledAppGroups. */
61
- reason?: 'not_entitled';
62
- [k: string]: unknown; // per-module inline settings preserved
63
- }
64
-
65
- /** Known `productMode` tiers, low → high — see §4.1. Not exhaustive; unrecognised values are future tiers. */
66
- export type ProductMode = 'simple_redirect' | 'rich_redirect' | 'inform' | 'engage';
67
-
68
- /** Resolved entitlements — safe for every client to read. */
69
- export interface SystemBlock {
70
- /** Internal billing identifier — not a capability signal, see §4. */
71
- basePlanId?: string;
72
- /** Stable capability tier — see §4.1. Prefer this over basePlanId. */
73
- productMode?: ProductMode | (string & {});
74
- addOnKeys?: string[];
75
- apps?: string[]; // apps unlocked by add-ons
76
- features?: Record<string, boolean>; // explicit overrides only — see §4.4 for absent-key resolution
77
- meters?: Record<string, MeterEntry>;
78
- entitledAppGroups?: string[]; // lowercased category names
79
- /** 'enterprise' flips every feature flag's default to on unless explicitly false — see §4.4/§4.7. */
80
- accountType?: 'enterprise' | 'standard';
81
- syncedAt?: string; // ISO-8601 UTC
82
- syncedFromSubscriptionId?: string;
83
- /** Diagnostic: which override keys reconcile applied on this pass. */
84
- appliedOverrides?: AppliedOverridesSummary;
85
- }
86
-
87
- export interface MeterEntry {
88
- included: number;
89
- stripePriceId?: string;
90
- stripeMeterId?: string;
91
- }
92
-
93
- export interface AppliedOverridesSummary {
94
- features?: string[];
95
- meters?: string[];
96
- entitledAppGroups?: string[];
97
- addOnKeys?: string[];
98
- apps?: string[];
99
- accountType?: boolean;
100
- note?: string;
101
- }
102
- ```
103
-
104
- `systemPrivate`'s shape is deliberately omitted here — see §5.
105
-
106
- ---
107
-
108
- ## 1. Where it lives
109
-
110
- Per SmartLinks collection, in the `appConfig` settings group — but for
111
- public (non-admin) reads, **don't call the settings-group endpoint
112
- directly.** As of 2026-07-18, `/public/collection/:id/app/config`
113
- (`collection.getAppsConfig()`) returns the same entitlements data merged
114
- into its response alongside the app catalog, so one call gets both:
115
-
116
- ```ts
117
- import * as SL from '@proveanything/smartlinks';
118
-
119
- // Recommended — one request, cached (see §6.0)
120
- const cfg = await SL.appConfiguration.getAppConfig(collectionId);
121
- console.log(cfg.apps); // app catalog (AppConfig[]) — see §3.1
122
- console.log(cfg.system?.features); // entitlements — see §4
123
-
124
- // Equivalent low-level call — getAppConfig() is a thin, cached wrapper over this
125
- const cfgRaw = await SL.collection.getAppsConfig(collectionId);
126
- ```
127
-
128
- `systemPrivate` (§5) is **never** returned by this endpoint — it's public-only.
129
- If you need it (admin surfaces), call the settings-group endpoint directly:
130
-
131
- ```ts
132
- const cfgAdmin = await SL.appConfiguration.getConfig({
133
- collectionId,
134
- appId: 'appConfig', // group id
135
- admin: true, // required for systemPrivate
136
- });
137
- ```
138
-
139
- - Admin writes to `system` / `systemPrivate` MUST go through
140
- `entitlements-reconcile` (never patch them directly from the client).
141
- - The settings-group endpoint's own `apps` field is shaped differently from
142
- the combined endpoint's — see §3.1 before assuming they're interchangeable.
143
-
144
- ## 2. Access tiers
145
-
146
- Three tiers, symmetric in-gate / out-gate rules:
147
-
148
- | Block | Client read | Client write | Admin read | Admin write path |
149
- | ---------------- | ----------- | ------------ | ---------- | ---------------------- |
150
- | user-owned root | yes | yes | yes | client SDK |
151
- | `system` | yes | no | yes | `entitlements-reconcile` only |
152
- | `systemPrivate` | **stripped** | no | yes | `plan-migration` `write_app_config` (super-admin) |
153
-
154
- The strip happens at the settings API layer — `systemPrivate` genuinely
155
- does not leave the server for non-admin callers. This convention
156
- generalises to every settings group, not just `appConfig`.
157
-
158
- ## 3. `apps[]` — installed modules
159
-
160
- See `AppEntry` in §0. Notes:
161
-
162
- - `id` and `uniqueName` are historically distinct but currently
163
- identical for new installs. Consumers should key off `uniqueName`.
164
- - `customName` is seeded from the module definition's `name`.
165
- - `active: false` + `reason: "not_entitled"` means reconcile flagged
166
- this app as outside the current plan's `entitledAppGroups`. UI should
167
- show it as disabled with an upgrade prompt; do not delete it.
168
- - Unknown extra keys are preserved by reconcile — safe to add per-module
169
- settings inline.
170
-
171
- ### 3.1 Two different `apps[]` shapes — don't conflate them
172
-
173
- This settings document's own `apps` field is `AppEntry[]` — installed
174
- *instances* (`uniqueName`, `customName`, `active`, `reason`).
175
-
176
- `collection.getAppsConfig()` / `appConfiguration.getAppConfig()` (§1, §6.0)
177
- return a **different** `apps` field: `AppConfig[]`, the module *catalog*
178
- definitions (`srcAppId`, `category`, `usage`, iframe/manifest URLs — see
179
- `src/types/collection.ts`), used for resolving which bundle to load. The
180
- entitlements fields (`system`, `addOns`, `itemRecordMode`, etc.) got merged
181
- onto that response; the `AppEntry[]` shape did not replace it.
182
-
183
- If you need the installed-instance list (`active`/`reason` per app), fetch
184
- the settings group directly (§1); if you need the catalog + entitlements
185
- together, use `appConfiguration.getAppConfig()`.
186
-
187
- ## 4. `system` — reconciled truth
188
-
189
- Written only by `entitlements-reconcile`. Represents the union of:
190
-
191
- - the customer's base plan (`grantsFeatures`, `grantsAppGroups`)
192
- - every add-on line item on their Stripe subscription
193
- - `systemPrivate.overrides` (applied last, always wins)
194
-
195
- `basePlanId` is an internal Stripe billing/plan identifier (string,
196
- sourced from subscription metadata) — a billing concern, not a capability
197
- signal. Don't branch app behavior on its literal value or its internal
198
- plan names; that's what `productMode` is for.
199
-
200
- ### 4.1 `productMode`
201
-
202
- Stable capability tier the app should branch on instead of `basePlanId`
203
- (a billing identity that can change independently of capability). Written
204
- by `entitlements-reconcile` on every sync. Typed as `ProductMode` in the
205
- SDK (`src/types/appConfiguration.ts`) — a union of the known tiers below,
206
- plus any other string, since future tiers will show up as new values
207
- before the SDK type is updated to know their names.
208
-
209
- Ladder, low → high:
210
-
211
- | `productMode` | Unlocks (roughly) |
212
- | ------------------ | --------------------------------------------------------------------------------- |
213
- | `simple_redirect` | Redirect-only: scanning a tag/QR sends the user straight to a URL — no product/proof page, no catalog UI. |
214
- | `rich_redirect` | Adds a rendered product/proof page (image, description, spec data) — still no deeper apps. |
215
- | `inform` | Adds informational surfaces beyond the basic page — documentation, provenance, facts-style apps. |
216
- | `engage` | Adds engagement/ownership capabilities — claim, CRM, loyalty, interaction tracking. Top of the ladder today. |
217
-
218
- > These four one-liners are inferred from the tier names and ladder
219
- > ordering, not copied from an authoritative source — worth a sanity check
220
- > against the actual capability gating before treating them as precise.
221
-
222
- ```ts
223
- const mode = cfg.system?.productMode;
224
- if (mode === 'simple_redirect' || mode === 'rich_redirect') {
225
- // redirect-only surface — hide catalog UI
226
- }
227
- ```
228
-
229
- Unknown values (future tiers your code predates) should fail closed to
230
- the nearest tier you understand, not throw or assume the top tier.
231
-
232
- Not a feature flag and not a billing key — per-capability gating still
233
- goes through `features` (§4.4); Stripe price selection still goes
234
- through `basePlanId` + add-ons.
235
-
236
- ### 4.2 `addOnKeys[]`
237
-
238
- Sorted array of every add-on key currently on the subscription. Matches
239
- `platform-addons` catalog `key` field.
240
-
241
- ```ts
242
- const hasCustomDomain = cfg.system.addOnKeys.includes('addon_custom_domain');
243
- ```
244
-
245
- ### 4.3 `apps[]` (system-side)
246
-
247
- Sorted array of app ids granted by add-ons whose `category === 'apps'`.
248
- Entitlement view — not the same as the top-level installed `apps[]`.
249
- Prefer `entitledAppGroups` for gating.
250
-
251
- ### 4.4 `features`
252
-
253
- Flat map of feature flag → explicit `true`/`false` override.
254
-
255
- **A missing key is not "off" — it means "use the accountType default."**
256
- Resolution rule (see `resolveFeature()` / `isFeatureEnabled()`, §6.0):
257
-
258
- | `features[flag]` | `accountType: 'enterprise'` | `accountType: 'standard'` / missing |
259
- | ----------------- | ---------------------------- | -------------------------------------- |
260
- | `true` (explicit) | on | on |
261
- | `false` (explicit) | **off** | off |
262
- | absent | **on** (enterprise default) | off (standard default) |
263
-
264
- This is why reading `cfg.system.features.customDomain` directly is wrong
265
- for enterprise accounts — an absent key there does NOT mean disabled:
266
-
267
- ```ts
268
- // ❌ WRONG for enterprise accounts — absent key silently reads as "off"
269
- if (cfg.system.features.customDomain) enableCustomDomainUI();
270
-
271
- // ✅ CORRECT — applies the enterprise default
272
- if (await appConfiguration.isFeatureEnabled(collectionId, 'customDomain')) {
273
- enableCustomDomainUI();
274
- }
275
- ```
276
-
277
- Feature flag naming: camelCase, no `feature`/`is`/`has` prefix (e.g.
278
- `customDomain`, not `feature_custom_domain` or `isCustomDomainEnabled`).
279
- Flags belonging to the same topic/module may use a dotted grouping prefix,
280
- e.g. `crm.broadcasts`, `crm.segments` — this is a plain string key in
281
- `features`, not a nested object, so resolve it the same way:
282
- `isFeatureEnabled(collectionId, 'crm.broadcasts')`.
283
-
284
- Always resolve flags through `appConfiguration.isFeatureEnabled(collectionId, flag)`
285
- / `isFeatureEnabledSync()` (§6.0), or `appConfiguration.resolveFeature(cfg.system, flag)`
286
- if you already have a `system` block from elsewhere — never read
287
- `cfg.system.features[flag]` directly.
288
-
289
- #### 4.4.1 Common feature flags
290
-
291
- `features` is an open map — any microapp can define its own key — but
292
- these are the major, cross-cutting flags most integrations will care
293
- about:
294
-
295
- | Flag | Gates |
296
- | -------------- | ---------------------------------------------------------------------- |
297
- | `analytics` | Analytics surfaces (dashboards, reporting, event exploration). |
298
- | `authenticity` | Live authenticity tracking — flags genuine vs. counterfeit items and enables auditing/tracing on them (e.g. impossible-travel detection). |
299
- | `crm` | Customer interaction / CRM — contact records, broadcasts, segments. Sub-features hang off the `crm.*` dotted prefix, e.g. `crm.broadcasts`, `crm.segments`. |
300
- | `hub` | The Hub module. |
301
- | `portal` | QR code scan portals. |
302
- | `virtualItems` | Virtual items — algorithmic per-item IDs with no persistent row (battery serials, scan-to-collect points, bulk QR sheets). Replaces the old root-level `virtualItemsEnabled` boolean, which has been removed (§8) — resolve this like any other feature flag, not as a separate config key. Independent of `itemRecordMode`. |
303
- | `batches` | Batch support. Used to be the `Collection.batches` boolean; that field has been removed — this flag is now the only source of truth. Also gates AI(10) **batch** resolution on a GS1 Digital Link scan (§ see `lots.md`). |
304
- | `variants` | Variant support. Used to be the `Collection.variants` boolean; that field has been removed — this flag is now the only source of truth. |
305
- | `lots` | Lot support — collection-scoped production groupings spanning many SKUs (see `lots.md`). Gates AI(10) **lot** resolution on a GS1 Digital Link scan. Independent of `batches`; when both are on, a scanned AI(10) value resolves batch-first (specific SKU) then lot (broad). |
306
-
307
- Same resolution rule as any flag (§4.4) — don't read these off
308
- `cfg.system.features` directly, always go through `isFeatureEnabled()`.
309
-
310
- ### 4.5 `meters`
311
-
312
- Map keyed by add-on key. Apps reporting usage should call the
313
- metered-usage endpoint using `stripeMeterId` (see
314
- `platform-metered-usage-endpoint.md`).
315
-
316
- ### 4.6 `entitledAppGroups[]`
317
-
318
- Sorted, lowercased category names the customer's plan unlocks. Match
319
- against a module's `category` (see `src/config/app-categories.ts`):
320
-
321
- ```
322
- "authenticity" | "documentation" | "digital-product-passports" |
323
- "commerce" | "engagement" | "ai" | "integration" | "other"
324
- ```
325
-
326
- **Empty array = permissive.** Reconcile treats an empty array as "no
327
- gating configured yet" and does not flag any apps.
328
-
329
- ### 4.7 `accountType`
330
-
331
- Explicit account tier. `"enterprise"` flips the default for **every**
332
- feature flag to on — not just a curated "everything on" baseline — so an
333
- app that has never heard of a given flag still reads it as enabled for an
334
- enterprise account. See §4.4 for the exact resolution rule. Sourced
335
- from `systemPrivate.overrides.accountType` and copied here by reconcile
336
- so the client never has to peek at private data. Missing = standard
337
- (every flag defaults off unless explicitly `true`).
338
-
339
- ### 4.8 `syncedAt` / `syncedFromSubscriptionId`
340
-
341
- Diagnostic. `syncedAt` is ISO-8601 UTC. `syncedFromSubscriptionId`
342
- absent means "no subscription on file, defaults applied".
343
-
344
- ### 4.9 `appliedOverrides`
345
-
346
- Diagnostic — records which keys came from `systemPrivate.overrides`
347
- this reconcile pass, so admins can see comp-driven flips vs
348
- Stripe-derived truth without opening the private block.
349
-
350
- ## 5. `systemPrivate` — admin-only overrides & metadata
351
-
352
- Super-admin-owned block for enterprise / custom deals and internal
353
- metadata, applied by `entitlements-reconcile` after Stripe derivation
354
- (§4) so it always wins. Its shape is intentionally **not documented
355
- here or in the SDK types** — it's internal to the platform, not part of
356
- the public `appConfig` contract.
357
-
358
- - Stripped from every non-admin response at the API boundary (§2).
359
- - Edited only via the `plan-migration` action `write_app_config` (admin) —
360
- the account detail page has a dedicated editor card.
361
- - Client apps should NEVER attempt to read or depend on `systemPrivate`;
362
- the SDK's public types don't expose it, and the API strips it anyway.
363
- - What it feeds into `system` (which client apps DO read) is documented
364
- where it lands: `system.accountType` (§4.7) and `system.appliedOverrides`
365
- (§4.9).
366
-
367
- ## 6. Consumer patterns
368
-
369
- ### 6.0 Feature gate — recommended: `isFeatureEnabled()`
370
-
371
- This is the standard way for a subapp to check whether a feature is on for
372
- a collection. It fetches (and caches) the whole `appConfig` document the
373
- first time it's called for a collection, then reads through that cache on
374
- every subsequent call — so calling it once per component, or once per
375
- render, doesn't cause repeat network requests.
376
-
377
- ```ts
378
- if (await SL.appConfiguration.isFeatureEnabled(collectionId, 'customDomain')) {
379
- enableCustomDomainUI();
380
- }
381
- ```
382
-
383
- It's always `async` — the very first call for a collection has nothing
384
- cached yet, so there's no way to answer without an `await`. If you need a
385
- synchronous read (e.g. inside a render function that can't await), warm the
386
- cache once during app init and use the sync variant afterwards:
387
-
388
- ```ts
389
- // Once, e.g. in a top-level effect or before first render:
390
- useEffect(() => {
391
- SL.appConfiguration.isFeatureEnabled(collectionId, 'customDomain')
392
- }, [collectionId]);
393
-
394
- // Anywhere else, read synchronously — no await:
395
- const enabled = SL.appConfiguration.isFeatureEnabledSync(collectionId, 'customDomain');
396
- if (enabled === undefined) {
397
- // not warmed yet this page load — treat as "not yet known", not "off"
398
- }
399
- ```
400
-
401
- `isFeatureEnabledSync` returns `boolean | undefined`: `undefined` means the
402
- cache hasn't been warmed yet for this collection, not that the flag is off.
403
- Don't treat `undefined` as `false`.
404
-
405
- The cache TTL is 5 minutes (in-memory + sessionStorage, cleared on full
406
- page reload). Pass `{ force: true }` to `getAppConfig` / `isFeatureEnabled`
407
- to bypass it — e.g. immediately after your own code calls
408
- `entitlements-reconcile` and the flags may have changed:
409
-
410
- ```ts
411
- await SL.appConfiguration.isFeatureEnabled(collectionId, 'customDomain', { force: true });
412
- ```
413
-
414
- ### 6.1 Reading the raw config
415
-
416
- If you need more than one flag, or other parts of the document, fetch the
417
- whole thing once and resolve multiple flags off it with `resolveFeature()`
418
- — still cached, still one network request. **Do not** read
419
- `cfg.system.features[flag]` directly (`Boolean(...)`/truthiness checks); an
420
- absent key means "use the accountType default" (§4.4), not "off":
421
-
422
- ```ts
423
- const cfg = await SL.appConfiguration.getAppConfig(collectionId);
424
- const enabled = SL.appConfiguration.resolveFeature(cfg?.system, flag);
425
- ```
426
-
427
- ### 6.2 App entitlement gate
428
-
429
- ```ts
430
- const cfg = await SL.appConfiguration.getAppConfig(collectionId);
431
- const groups = new Set(cfg?.system?.entitledAppGroups ?? []);
432
- const canInstall = groups.size === 0 || groups.has(myModuleCategory.toLowerCase());
433
- ```
434
-
435
- ### 6.3 Enterprise detection
436
-
437
- ```ts
438
- const cfg = await SL.appConfiguration.getAppConfig(collectionId);
439
- const isEnterprise = cfg?.system?.accountType === 'enterprise';
440
- ```
441
-
442
- ### 6.4 Meter lookup
443
-
444
- ```ts
445
- const cfg = await SL.appConfiguration.getAppConfig(collectionId);
446
- const meter = cfg?.system?.meters?.[addOnKey];
447
- if (meter) reportUsage(meter.stripeMeterId, quantity);
448
- ```
449
-
450
- ### 6.5 Reacting to changes
451
-
452
- `appConfig` is not push-based today — read it on load and after any
453
- subscription mutation you initiate. Client code that changes
454
- entitlements MUST call `entitlements-reconcile` afterwards, then re-read
455
- with `{ force: true }` (§6.0) rather than trusting the cache or merging
456
- with a stale local copy.
457
-
458
- ## 7. Write paths
459
-
460
- | Actor | Endpoint | Writes |
461
- | --------------------------- | ---------------------------------------------------------------------------- | ------------------------- |
462
- | Wizard signup | `stripe-wizard-webhook` → `entitlements-reconcile` | full doc |
463
- | Add-on toggle (client) | `entitlements-reconcile` (`changes[]`) | full doc |
464
- | Module install / uninstall | client `setConfig` on `apps[]`, then `entitlements-reconcile` (no changes) | `apps[]` + `system` |
465
- | Admin migration | `plan-migration` action `apply` | full doc |
466
- | Admin manual edit | `plan-migration` action `write_app_config` | full doc verbatim (incl. `systemPrivate`) |
467
- | Stripe webhook | `entitlements-reconcile` | `system` block |
468
-
469
- Clients MUST NOT write directly to `system` or `systemPrivate`.
470
- `entitlements-reconcile` merges user-owned fields through untouched.
471
-
472
- ## 8. Item handling (`itemRecordMode`)
473
-
474
- A root-level, user-owned key describing how the account treats
475
- individual physical items. Reconcile never touches it.
476
-
477
- Two axes (do NOT conflate):
478
-
479
- 1. **Item records** — `itemRecordMode`. Materialise a persistent row
480
- per physical item. `null` / missing = **disabled** (no separate
481
- `"none"` enum — reads collapse to `mode === "off"` via the
482
- `useItemRecordMode()` hook).
483
- - `"registered"` — tag row, no owner. Authenticity / warranty /
484
- provenance without a customer relationship.
485
- - `"owned"` — tag row + owner + interaction history. Requires
486
- `basePlanId >= "engage"`. Enables claim / transfer / CRM.
487
- 2. **CRM** — downstream consequence of `owned`; not a peer flag.
488
-
489
- **Virtual items are not part of this key.** Algorithmic IDs with no
490
- per-item row (battery serials, scan-to-collect points, bulk QR sheets)
491
- used to be a separate root-level `virtualItemsEnabled: boolean` — that
492
- field has been removed. Virtual items are now gated by the `virtualItems`
493
- feature flag under `system.features` (§4.4.1), same as every other
494
- feature — resolve it with `isFeatureEnabled(collectionId, 'virtualItems')`.
495
- It's independent of `itemRecordMode` and can be on with item records off.
496
-
497
- **Billing:** the usage ledger stamps `tier` at event time from
498
- `itemRecordMode`. Writes with `mode === null` MUST be rejected. Mode
499
- changes are forward-only per record — existing items keep their tier.
500
-
501
- **UI:** rendered as a single "Item handling" section at the top of
502
- the customer add-ons page (`src/components/pricing/ItemHandlingSection`)
503
- because these settings change the whole UX shape (claim, ownership,
504
- CRM visibility), not just a capability flag.
505
-
506
- ## 8a. What's switched on (`enabled`)
507
-
508
- A root-level, user-owned map (like `itemRecordMode`; reconcile never touches it) saying which parts of
509
- the platform this collection **uses** — separate from what its plan **allows** (`system.features`):
510
-
511
- | | Plan allows (`system.features`) | Switched on (`enabled`) |
512
- |---|---|---|
513
- | Written by | billing (`entitlements-reconcile`) | the collection: sign-up wizards, admins |
514
- | Means | "you may have this" | "this business uses this" |
515
- | Missing key | standard: off · enterprise: on | **on** |
516
-
517
- ```json
518
- { "enabled": { "products": false, "crm": false, "hub": false, "portal": false, "printStudio": false } }
519
- ```
520
-
521
- **A missing key is on**, so a collection that never set `enabled` behaves exactly as before. Only an
522
- explicit `false` switches something off. A website-only sign-up switches off what it doesn't use
523
- (products, CRM, Hub, Portal…), and Studio hides the menus, dashboard cards and setup steps for them;
524
- an admin can switch them back on.
525
-
526
- Known keys: `products`, `crm`, `analytics`, `hub`, `portal`, `printStudio`. The map is open — an app
527
- may define its own key.
528
-
529
- ```ts
530
- if (await SL.appConfiguration.isEnabled(collectionId, 'products')) showProducts()
531
- // already have the config:
532
- SL.appConfiguration.resolveEnabled(cfg, 'crm')
533
- ```
534
-
535
- For something a plan gates, show it only when both hold: `resolveEnabled(cfg, key)` **and**
536
- `resolveFeature(cfg.system, flag)`.
537
-
538
- Write it through the admin settings route (`collection.updateSettings(collectionId, 'appConfig',
539
- { enabled: { products: true } })`) — keys merge, so set only the ones you change.
540
-
541
- ## 9. Migration notes
542
-
543
- - Legacy `entitlements` settings group is deprecated. Everything moved
544
- into `appConfig.system`.
545
- - `appConfig.apps[]` is the master install list. Old split between
546
- `entitlements.apps` and `settings.apps` is gone.
547
- - Empty `system.features` is legitimate for base plans that grant no
548
- features yet.
549
- - `systemOverrides` (old root-level key) → `systemPrivate.overrides`.
550
- One-off backfill moves the block and re-runs reconcile.
1
+ # `appConfig` — collection settings contract
2
+
3
+ **Settings group:** `appConfig` (a.k.a. `settings/appConfig`, app id `appConfig`)
4
+ **Owner:** platform (`entitlements-reconcile` edge function is the sole authority for the `system` block)
5
+ **Written by:** wizard signup, admin tools, module installer, add-on toggles, `entitlements-reconcile`
6
+ **Read by:** every microapp that needs to know "what is installed / entitled / metered" for a collection
7
+
8
+ This document is the source of truth for the shape and semantics of the
9
+ `appConfig` settings document, and for the SDK helpers microapps should use
10
+ to read it — in particular `appConfiguration.isFeatureEnabled()`, the
11
+ standard way for a subapp to check whether a feature flag is on for a
12
+ collection.
13
+
14
+ ---
15
+
16
+ ## 0. TypeScript definition
17
+
18
+ The SDK exports this as `AppConfigSettings` (see `src/types/appConfiguration.ts`).
19
+ The document also carries a `systemPrivate` block (admin-only overrides and
20
+ internal metadata) that's stripped by the API for non-admin callers — see §5.
21
+ Its shape is intentionally not part of this SDK's public type surface, so it
22
+ doesn't appear below; treat it as opaque and never rely on it from client code.
23
+
24
+ ```ts
25
+ /** Full appConfig settings document for a SmartLinks collection. */
26
+ export interface AppConfigSettings {
27
+ id: 'appConfig';
28
+
29
+ // ── USER-OWNED (client may PATCH freely) ──────────────────────────
30
+ /** Installed modules — the customer's chosen surface. */
31
+ apps: AppEntry[];
32
+ /** Optional mirror of add-on keys the customer has toggled. */
33
+ addOns?: string[];
34
+ /** Wizard hint — which base plan the customer picked pre-checkout. */
35
+ requestedBasePlanId?: string;
36
+
37
+ /** How the account handles individual physical items. */
38
+ itemRecordMode?: 'registered' | 'owned' | null;
39
+ /** What the collection has switched on (absent key = on) — see §8a. */
40
+ enabled?: Record<string, boolean>;
41
+
42
+ // ── SYSTEM-OWNED, PUBLIC (reconcile writes; client read-only) ─────
43
+ /** Resolved entitlement truth. Read this to gate features. */
44
+ system?: SystemBlock;
45
+
46
+ // Also carries a `systemPrivate` block, stripped for non-admin reads.
47
+ // Not part of the public SDK contract — see §5.
48
+ }
49
+
50
+ /** One installed module instance on this collection. */
51
+ export interface AppEntry {
52
+ id: string; // instance id (typically === uniqueName)
53
+ uniqueName: string; // module id from the module catalog
54
+ customName?: string; // display name, overrideable
55
+ active: boolean; // user toggle
56
+ all?: boolean; // legacy scope flag
57
+ live?: boolean; // legacy flag
58
+ faIcon?: string; // optional FA icon override
59
+ versionChannel?: 'stable' | 'beta' | 'dev';
60
+ /** Set by reconcile when app category is not in entitledAppGroups. */
61
+ reason?: 'not_entitled';
62
+ [k: string]: unknown; // per-module inline settings preserved
63
+ }
64
+
65
+ /** Known `productMode` tiers, low → high — see §4.1. Not exhaustive; unrecognised values are future tiers. */
66
+ export type ProductMode = 'simple_redirect' | 'rich_redirect' | 'inform' | 'engage';
67
+
68
+ /** Resolved entitlements — safe for every client to read. */
69
+ export interface SystemBlock {
70
+ /** Internal billing identifier — not a capability signal, see §4. */
71
+ basePlanId?: string;
72
+ /** Stable capability tier — see §4.1. Prefer this over basePlanId. */
73
+ productMode?: ProductMode | (string & {});
74
+ addOnKeys?: string[];
75
+ apps?: string[]; // apps unlocked by add-ons
76
+ features?: Record<string, boolean>; // explicit overrides only — see §4.4 for absent-key resolution
77
+ meters?: Record<string, MeterEntry>;
78
+ entitledAppGroups?: string[]; // lowercased category names
79
+ /** 'enterprise' flips every feature flag's default to on unless explicitly false — see §4.4/§4.7. */
80
+ accountType?: 'enterprise' | 'standard';
81
+ syncedAt?: string; // ISO-8601 UTC
82
+ syncedFromSubscriptionId?: string;
83
+ /** Diagnostic: which override keys reconcile applied on this pass. */
84
+ appliedOverrides?: AppliedOverridesSummary;
85
+ }
86
+
87
+ export interface MeterEntry {
88
+ included: number;
89
+ stripePriceId?: string;
90
+ stripeMeterId?: string;
91
+ }
92
+
93
+ export interface AppliedOverridesSummary {
94
+ features?: string[];
95
+ meters?: string[];
96
+ entitledAppGroups?: string[];
97
+ addOnKeys?: string[];
98
+ apps?: string[];
99
+ accountType?: boolean;
100
+ note?: string;
101
+ }
102
+ ```
103
+
104
+ `systemPrivate`'s shape is deliberately omitted here — see §5.
105
+
106
+ ---
107
+
108
+ ## 1. Where it lives
109
+
110
+ Per SmartLinks collection, in the `appConfig` settings group — but for
111
+ public (non-admin) reads, **don't call the settings-group endpoint
112
+ directly.** As of 2026-07-18, `/public/collection/:id/app/config`
113
+ (`collection.getAppsConfig()`) returns the same entitlements data merged
114
+ into its response alongside the app catalog, so one call gets both:
115
+
116
+ ```ts
117
+ import * as SL from '@proveanything/smartlinks';
118
+
119
+ // Recommended — one request, cached (see §6.0)
120
+ const cfg = await SL.appConfiguration.getAppConfig(collectionId);
121
+ console.log(cfg.apps); // app catalog (AppConfig[]) — see §3.1
122
+ console.log(cfg.system?.features); // entitlements — see §4
123
+
124
+ // Equivalent low-level call — getAppConfig() is a thin, cached wrapper over this
125
+ const cfgRaw = await SL.collection.getAppsConfig(collectionId);
126
+ ```
127
+
128
+ `systemPrivate` (§5) is **never** returned by this endpoint — it's public-only.
129
+ If you need it (admin surfaces), call the settings-group endpoint directly:
130
+
131
+ ```ts
132
+ const cfgAdmin = await SL.appConfiguration.getConfig({
133
+ collectionId,
134
+ appId: 'appConfig', // group id
135
+ admin: true, // required for systemPrivate
136
+ });
137
+ ```
138
+
139
+ - Admin writes to `system` / `systemPrivate` MUST go through
140
+ `entitlements-reconcile` (never patch them directly from the client).
141
+ - The settings-group endpoint's own `apps` field is shaped differently from
142
+ the combined endpoint's — see §3.1 before assuming they're interchangeable.
143
+
144
+ ## 2. Access tiers
145
+
146
+ Three tiers, symmetric in-gate / out-gate rules:
147
+
148
+ | Block | Client read | Client write | Admin read | Admin write path |
149
+ | ---------------- | ----------- | ------------ | ---------- | ---------------------- |
150
+ | user-owned root | yes | yes | yes | client SDK |
151
+ | `system` | yes | no | yes | `entitlements-reconcile` only |
152
+ | `systemPrivate` | **stripped** | no | yes | `plan-migration` `write_app_config` (super-admin) |
153
+
154
+ The strip happens at the settings API layer — `systemPrivate` genuinely
155
+ does not leave the server for non-admin callers. This convention
156
+ generalises to every settings group, not just `appConfig`.
157
+
158
+ ## 3. `apps[]` — installed modules
159
+
160
+ See `AppEntry` in §0. Notes:
161
+
162
+ - `id` and `uniqueName` are historically distinct but currently
163
+ identical for new installs. Consumers should key off `uniqueName`.
164
+ - `customName` is seeded from the module definition's `name`.
165
+ - `active: false` + `reason: "not_entitled"` means reconcile flagged
166
+ this app as outside the current plan's `entitledAppGroups`. UI should
167
+ show it as disabled with an upgrade prompt; do not delete it.
168
+ - Unknown extra keys are preserved by reconcile — safe to add per-module
169
+ settings inline.
170
+
171
+ ### 3.1 Two different `apps[]` shapes — don't conflate them
172
+
173
+ This settings document's own `apps` field is `AppEntry[]` — installed
174
+ *instances* (`uniqueName`, `customName`, `active`, `reason`).
175
+
176
+ `collection.getAppsConfig()` / `appConfiguration.getAppConfig()` (§1, §6.0)
177
+ return a **different** `apps` field: `AppConfig[]`, the module *catalog*
178
+ definitions (`srcAppId`, `category`, `usage`, iframe/manifest URLs — see
179
+ `src/types/collection.ts`), used for resolving which bundle to load. The
180
+ entitlements fields (`system`, `addOns`, `itemRecordMode`, etc.) got merged
181
+ onto that response; the `AppEntry[]` shape did not replace it.
182
+
183
+ If you need the installed-instance list (`active`/`reason` per app), fetch
184
+ the settings group directly (§1); if you need the catalog + entitlements
185
+ together, use `appConfiguration.getAppConfig()`.
186
+
187
+ ## 4. `system` — reconciled truth
188
+
189
+ Written only by `entitlements-reconcile`. Represents the union of:
190
+
191
+ - the customer's base plan (`grantsFeatures`, `grantsAppGroups`)
192
+ - every add-on line item on their Stripe subscription
193
+ - `systemPrivate.overrides` (applied last, always wins)
194
+
195
+ `basePlanId` is an internal Stripe billing/plan identifier (string,
196
+ sourced from subscription metadata) — a billing concern, not a capability
197
+ signal. Don't branch app behavior on its literal value or its internal
198
+ plan names; that's what `productMode` is for.
199
+
200
+ ### 4.1 `productMode`
201
+
202
+ Stable capability tier the app should branch on instead of `basePlanId`
203
+ (a billing identity that can change independently of capability). Written
204
+ by `entitlements-reconcile` on every sync. Typed as `ProductMode` in the
205
+ SDK (`src/types/appConfiguration.ts`) — a union of the known tiers below,
206
+ plus any other string, since future tiers will show up as new values
207
+ before the SDK type is updated to know their names.
208
+
209
+ Ladder, low → high:
210
+
211
+ | `productMode` | Unlocks (roughly) |
212
+ | ------------------ | --------------------------------------------------------------------------------- |
213
+ | `simple_redirect` | Redirect-only: scanning a tag/QR sends the user straight to a URL — no product/proof page, no catalog UI. |
214
+ | `rich_redirect` | Adds a rendered product/proof page (image, description, spec data) — still no deeper apps. |
215
+ | `inform` | Adds informational surfaces beyond the basic page — documentation, provenance, facts-style apps. |
216
+ | `engage` | Adds engagement/ownership capabilities — claim, CRM, loyalty, interaction tracking. Top of the ladder today. |
217
+
218
+ > These four one-liners are inferred from the tier names and ladder
219
+ > ordering, not copied from an authoritative source — worth a sanity check
220
+ > against the actual capability gating before treating them as precise.
221
+
222
+ ```ts
223
+ const mode = cfg.system?.productMode;
224
+ if (mode === 'simple_redirect' || mode === 'rich_redirect') {
225
+ // redirect-only surface — hide catalog UI
226
+ }
227
+ ```
228
+
229
+ Unknown values (future tiers your code predates) should fail closed to
230
+ the nearest tier you understand, not throw or assume the top tier.
231
+
232
+ Not a feature flag and not a billing key — per-capability gating still
233
+ goes through `features` (§4.4); Stripe price selection still goes
234
+ through `basePlanId` + add-ons.
235
+
236
+ ### 4.2 `addOnKeys[]`
237
+
238
+ Sorted array of every add-on key currently on the subscription. Matches
239
+ `platform-addons` catalog `key` field.
240
+
241
+ ```ts
242
+ const hasCustomDomain = cfg.system.addOnKeys.includes('addon_custom_domain');
243
+ ```
244
+
245
+ ### 4.3 `apps[]` (system-side)
246
+
247
+ Sorted array of app ids granted by add-ons whose `category === 'apps'`.
248
+ Entitlement view — not the same as the top-level installed `apps[]`.
249
+ Prefer `entitledAppGroups` for gating.
250
+
251
+ ### 4.4 `features`
252
+
253
+ Flat map of feature flag → explicit `true`/`false` override.
254
+
255
+ **A missing key is not "off" — it means "use the accountType default."**
256
+ Resolution rule (see `resolveFeature()` / `isFeatureEnabled()`, §6.0):
257
+
258
+ | `features[flag]` | `accountType: 'enterprise'` | `accountType: 'standard'` / missing |
259
+ | ----------------- | ---------------------------- | -------------------------------------- |
260
+ | `true` (explicit) | on | on |
261
+ | `false` (explicit) | **off** | off |
262
+ | absent | **on** (enterprise default) | off (standard default) |
263
+
264
+ This is why reading `cfg.system.features.customDomain` directly is wrong
265
+ for enterprise accounts — an absent key there does NOT mean disabled:
266
+
267
+ ```ts
268
+ // ❌ WRONG for enterprise accounts — absent key silently reads as "off"
269
+ if (cfg.system.features.customDomain) enableCustomDomainUI();
270
+
271
+ // ✅ CORRECT — applies the enterprise default
272
+ if (await appConfiguration.isFeatureEnabled(collectionId, 'customDomain')) {
273
+ enableCustomDomainUI();
274
+ }
275
+ ```
276
+
277
+ Feature flag naming: camelCase, no `feature`/`is`/`has` prefix (e.g.
278
+ `customDomain`, not `feature_custom_domain` or `isCustomDomainEnabled`).
279
+ Flags belonging to the same topic/module may use a dotted grouping prefix,
280
+ e.g. `crm.broadcasts`, `crm.segments` — this is a plain string key in
281
+ `features`, not a nested object, so resolve it the same way:
282
+ `isFeatureEnabled(collectionId, 'crm.broadcasts')`.
283
+
284
+ Always resolve flags through `appConfiguration.isFeatureEnabled(collectionId, flag)`
285
+ / `isFeatureEnabledSync()` (§6.0), or `appConfiguration.resolveFeature(cfg.system, flag)`
286
+ if you already have a `system` block from elsewhere — never read
287
+ `cfg.system.features[flag]` directly.
288
+
289
+ #### 4.4.1 Common feature flags
290
+
291
+ `features` is an open map — any microapp can define its own key — but
292
+ these are the major, cross-cutting flags most integrations will care
293
+ about:
294
+
295
+ | Flag | Gates |
296
+ | -------------- | ---------------------------------------------------------------------- |
297
+ | `analytics` | Analytics surfaces (dashboards, reporting, event exploration). |
298
+ | `authenticity` | Live authenticity tracking — flags genuine vs. counterfeit items and enables auditing/tracing on them (e.g. impossible-travel detection). |
299
+ | `crm` | Customer interaction / CRM — contact records, broadcasts, segments. Sub-features hang off the `crm.*` dotted prefix, e.g. `crm.broadcasts`, `crm.segments`. |
300
+ | `hub` | The Hub module. |
301
+ | `portal` | QR code scan portals. |
302
+ | `virtualItems` | Virtual items — algorithmic per-item IDs with no persistent row (battery serials, scan-to-collect points, bulk QR sheets). Replaces the old root-level `virtualItemsEnabled` boolean, which has been removed (§8) — resolve this like any other feature flag, not as a separate config key. Independent of `itemRecordMode`. |
303
+ | `batches` | Batch support. Used to be the `Collection.batches` boolean; that field has been removed — this flag is now the only source of truth. Also gates AI(10) **batch** resolution on a GS1 Digital Link scan (§ see `lots.md`). |
304
+ | `variants` | Variant support. Used to be the `Collection.variants` boolean; that field has been removed — this flag is now the only source of truth. |
305
+ | `lots` | Lot support — collection-scoped production groupings spanning many SKUs (see `lots.md`). Gates AI(10) **lot** resolution on a GS1 Digital Link scan. Independent of `batches`; when both are on, a scanned AI(10) value resolves batch-first (specific SKU) then lot (broad). |
306
+
307
+ Same resolution rule as any flag (§4.4) — don't read these off
308
+ `cfg.system.features` directly, always go through `isFeatureEnabled()`.
309
+
310
+ ### 4.5 `meters`
311
+
312
+ Map keyed by add-on key. Apps reporting usage should call the
313
+ metered-usage endpoint using `stripeMeterId` (see
314
+ `platform-metered-usage-endpoint.md`).
315
+
316
+ ### 4.6 `entitledAppGroups[]`
317
+
318
+ Sorted, lowercased category names the customer's plan unlocks. Match
319
+ against a module's `category` (see `src/config/app-categories.ts`):
320
+
321
+ ```
322
+ "authenticity" | "documentation" | "digital-product-passports" |
323
+ "commerce" | "engagement" | "ai" | "integration" | "other"
324
+ ```
325
+
326
+ **Empty array = permissive.** Reconcile treats an empty array as "no
327
+ gating configured yet" and does not flag any apps.
328
+
329
+ ### 4.7 `accountType`
330
+
331
+ Explicit account tier. `"enterprise"` flips the default for **every**
332
+ feature flag to on — not just a curated "everything on" baseline — so an
333
+ app that has never heard of a given flag still reads it as enabled for an
334
+ enterprise account. See §4.4 for the exact resolution rule. Sourced
335
+ from `systemPrivate.overrides.accountType` and copied here by reconcile
336
+ so the client never has to peek at private data. Missing = standard
337
+ (every flag defaults off unless explicitly `true`).
338
+
339
+ ### 4.8 `syncedAt` / `syncedFromSubscriptionId`
340
+
341
+ Diagnostic. `syncedAt` is ISO-8601 UTC. `syncedFromSubscriptionId`
342
+ absent means "no subscription on file, defaults applied".
343
+
344
+ ### 4.9 `appliedOverrides`
345
+
346
+ Diagnostic — records which keys came from `systemPrivate.overrides`
347
+ this reconcile pass, so admins can see comp-driven flips vs
348
+ Stripe-derived truth without opening the private block.
349
+
350
+ ## 5. `systemPrivate` — admin-only overrides & metadata
351
+
352
+ Super-admin-owned block for enterprise / custom deals and internal
353
+ metadata, applied by `entitlements-reconcile` after Stripe derivation
354
+ (§4) so it always wins. Its shape is intentionally **not documented
355
+ here or in the SDK types** — it's internal to the platform, not part of
356
+ the public `appConfig` contract.
357
+
358
+ - Stripped from every non-admin response at the API boundary (§2).
359
+ - Edited only via the `plan-migration` action `write_app_config` (admin) —
360
+ the account detail page has a dedicated editor card.
361
+ - Client apps should NEVER attempt to read or depend on `systemPrivate`;
362
+ the SDK's public types don't expose it, and the API strips it anyway.
363
+ - What it feeds into `system` (which client apps DO read) is documented
364
+ where it lands: `system.accountType` (§4.7) and `system.appliedOverrides`
365
+ (§4.9).
366
+
367
+ ## 6. Consumer patterns
368
+
369
+ ### 6.0 Feature gate — recommended: `isFeatureEnabled()`
370
+
371
+ This is the standard way for a subapp to check whether a feature is on for
372
+ a collection. It fetches (and caches) the whole `appConfig` document the
373
+ first time it's called for a collection, then reads through that cache on
374
+ every subsequent call — so calling it once per component, or once per
375
+ render, doesn't cause repeat network requests.
376
+
377
+ ```ts
378
+ if (await SL.appConfiguration.isFeatureEnabled(collectionId, 'customDomain')) {
379
+ enableCustomDomainUI();
380
+ }
381
+ ```
382
+
383
+ It's always `async` — the very first call for a collection has nothing
384
+ cached yet, so there's no way to answer without an `await`. If you need a
385
+ synchronous read (e.g. inside a render function that can't await), warm the
386
+ cache once during app init and use the sync variant afterwards:
387
+
388
+ ```ts
389
+ // Once, e.g. in a top-level effect or before first render:
390
+ useEffect(() => {
391
+ SL.appConfiguration.isFeatureEnabled(collectionId, 'customDomain')
392
+ }, [collectionId]);
393
+
394
+ // Anywhere else, read synchronously — no await:
395
+ const enabled = SL.appConfiguration.isFeatureEnabledSync(collectionId, 'customDomain');
396
+ if (enabled === undefined) {
397
+ // not warmed yet this page load — treat as "not yet known", not "off"
398
+ }
399
+ ```
400
+
401
+ `isFeatureEnabledSync` returns `boolean | undefined`: `undefined` means the
402
+ cache hasn't been warmed yet for this collection, not that the flag is off.
403
+ Don't treat `undefined` as `false`.
404
+
405
+ The cache TTL is 5 minutes (in-memory + sessionStorage, cleared on full
406
+ page reload). Pass `{ force: true }` to `getAppConfig` / `isFeatureEnabled`
407
+ to bypass it — e.g. immediately after your own code calls
408
+ `entitlements-reconcile` and the flags may have changed:
409
+
410
+ ```ts
411
+ await SL.appConfiguration.isFeatureEnabled(collectionId, 'customDomain', { force: true });
412
+ ```
413
+
414
+ ### 6.1 Reading the raw config
415
+
416
+ If you need more than one flag, or other parts of the document, fetch the
417
+ whole thing once and resolve multiple flags off it with `resolveFeature()`
418
+ — still cached, still one network request. **Do not** read
419
+ `cfg.system.features[flag]` directly (`Boolean(...)`/truthiness checks); an
420
+ absent key means "use the accountType default" (§4.4), not "off":
421
+
422
+ ```ts
423
+ const cfg = await SL.appConfiguration.getAppConfig(collectionId);
424
+ const enabled = SL.appConfiguration.resolveFeature(cfg?.system, flag);
425
+ ```
426
+
427
+ ### 6.2 App entitlement gate
428
+
429
+ ```ts
430
+ const cfg = await SL.appConfiguration.getAppConfig(collectionId);
431
+ const groups = new Set(cfg?.system?.entitledAppGroups ?? []);
432
+ const canInstall = groups.size === 0 || groups.has(myModuleCategory.toLowerCase());
433
+ ```
434
+
435
+ ### 6.3 Enterprise detection
436
+
437
+ ```ts
438
+ const cfg = await SL.appConfiguration.getAppConfig(collectionId);
439
+ const isEnterprise = cfg?.system?.accountType === 'enterprise';
440
+ ```
441
+
442
+ ### 6.4 Meter lookup
443
+
444
+ ```ts
445
+ const cfg = await SL.appConfiguration.getAppConfig(collectionId);
446
+ const meter = cfg?.system?.meters?.[addOnKey];
447
+ if (meter) reportUsage(meter.stripeMeterId, quantity);
448
+ ```
449
+
450
+ ### 6.5 Reacting to changes
451
+
452
+ `appConfig` is not push-based today — read it on load and after any
453
+ subscription mutation you initiate. Client code that changes
454
+ entitlements MUST call `entitlements-reconcile` afterwards, then re-read
455
+ with `{ force: true }` (§6.0) rather than trusting the cache or merging
456
+ with a stale local copy.
457
+
458
+ ## 7. Write paths
459
+
460
+ | Actor | Endpoint | Writes |
461
+ | --------------------------- | ---------------------------------------------------------------------------- | ------------------------- |
462
+ | Wizard signup | `stripe-wizard-webhook` → `entitlements-reconcile` | full doc |
463
+ | Add-on toggle (client) | `entitlements-reconcile` (`changes[]`) | full doc |
464
+ | Module install / uninstall | client `setConfig` on `apps[]`, then `entitlements-reconcile` (no changes) | `apps[]` + `system` |
465
+ | Admin migration | `plan-migration` action `apply` | full doc |
466
+ | Admin manual edit | `plan-migration` action `write_app_config` | full doc verbatim (incl. `systemPrivate`) |
467
+ | Stripe webhook | `entitlements-reconcile` | `system` block |
468
+
469
+ Clients MUST NOT write directly to `system` or `systemPrivate`.
470
+ `entitlements-reconcile` merges user-owned fields through untouched.
471
+
472
+ ## 8. Item handling (`itemRecordMode`)
473
+
474
+ A root-level, user-owned key describing how the account treats
475
+ individual physical items. Reconcile never touches it.
476
+
477
+ Two axes (do NOT conflate):
478
+
479
+ 1. **Item records** — `itemRecordMode`. Materialise a persistent row
480
+ per physical item. `null` / missing = **disabled** (no separate
481
+ `"none"` enum — reads collapse to `mode === "off"` via the
482
+ `useItemRecordMode()` hook).
483
+ - `"registered"` — tag row, no owner. Authenticity / warranty /
484
+ provenance without a customer relationship.
485
+ - `"owned"` — tag row + owner + interaction history. Requires
486
+ `basePlanId >= "engage"`. Enables claim / transfer / CRM.
487
+ 2. **CRM** — downstream consequence of `owned`; not a peer flag.
488
+
489
+ **Virtual items are not part of this key.** Algorithmic IDs with no
490
+ per-item row (battery serials, scan-to-collect points, bulk QR sheets)
491
+ used to be a separate root-level `virtualItemsEnabled: boolean` — that
492
+ field has been removed. Virtual items are now gated by the `virtualItems`
493
+ feature flag under `system.features` (§4.4.1), same as every other
494
+ feature — resolve it with `isFeatureEnabled(collectionId, 'virtualItems')`.
495
+ It's independent of `itemRecordMode` and can be on with item records off.
496
+
497
+ **Billing:** the usage ledger stamps `tier` at event time from
498
+ `itemRecordMode`. Writes with `mode === null` MUST be rejected. Mode
499
+ changes are forward-only per record — existing items keep their tier.
500
+
501
+ **UI:** rendered as a single "Item handling" section at the top of
502
+ the customer add-ons page (`src/components/pricing/ItemHandlingSection`)
503
+ because these settings change the whole UX shape (claim, ownership,
504
+ CRM visibility), not just a capability flag.
505
+
506
+ ## 8a. What's switched on (`enabled`)
507
+
508
+ A root-level, user-owned map (like `itemRecordMode`; reconcile never touches it) saying which parts of
509
+ the platform this collection **uses** — separate from what its plan **allows** (`system.features`):
510
+
511
+ | | Plan allows (`system.features`) | Switched on (`enabled`) |
512
+ |---|---|---|
513
+ | Written by | billing (`entitlements-reconcile`) | the collection: sign-up wizards, admins |
514
+ | Means | "you may have this" | "this business uses this" |
515
+ | Missing key | standard: off · enterprise: on | **on** |
516
+
517
+ ```json
518
+ { "enabled": { "products": false, "crm": false, "hub": false, "portal": false, "printStudio": false } }
519
+ ```
520
+
521
+ **A missing key is on**, so a collection that never set `enabled` behaves exactly as before. Only an
522
+ explicit `false` switches something off. A website-only sign-up switches off what it doesn't use
523
+ (products, CRM, Hub, Portal…), and Studio hides the menus, dashboard cards and setup steps for them;
524
+ an admin can switch them back on.
525
+
526
+ Known keys: `products`, `crm`, `analytics`, `hub`, `portal`, `printStudio`. The map is open — an app
527
+ may define its own key.
528
+
529
+ ```ts
530
+ if (await SL.appConfiguration.isEnabled(collectionId, 'products')) showProducts()
531
+ // already have the config:
532
+ SL.appConfiguration.resolveEnabled(cfg, 'crm')
533
+ ```
534
+
535
+ For something a plan gates, show it only when both hold: `resolveEnabled(cfg, key)` **and**
536
+ `resolveFeature(cfg.system, flag)`.
537
+
538
+ Write it through the admin settings route (`collection.updateSettings(collectionId, 'appConfig',
539
+ { enabled: { products: true } })`) — keys merge, so set only the ones you change.
540
+
541
+ ## 9. Migration notes
542
+
543
+ - Legacy `entitlements` settings group is deprecated. Everything moved
544
+ into `appConfig.system`.
545
+ - `appConfig.apps[]` is the master install list. Old split between
546
+ `entitlements.apps` and `settings.apps` is gone.
547
+ - Empty `system.features` is legitimate for base plans that grant no
548
+ features yet.
549
+ - `systemOverrides` (old root-level key) → `systemPrivate.overrides`.
550
+ One-off backfill moves the block and re-runs reconcile.