@proveanything/smartlinks 2.1.47 → 2.2.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 (133) hide show
  1. package/README.md +754 -754
  2. package/dist/README.md +573 -573
  3. package/dist/adminCardsView.js +55 -55
  4. package/dist/api/dpp.d.ts +6 -0
  5. package/dist/api/dpp.js +12 -0
  6. package/dist/api/shop.d.ts +5 -1
  7. package/dist/api/shop.js +7 -7
  8. package/dist/api/subscriptions.d.ts +2 -1
  9. package/dist/api/subscriptions.js +4 -12
  10. package/dist/apiVersion.d.ts +9 -0
  11. package/dist/apiVersion.js +15 -0
  12. package/dist/baseline.css +194 -194
  13. package/dist/docs/API_SUMMARY.md +821 -811
  14. package/dist/docs/admin-cards.md +189 -189
  15. package/dist/docs/agent-tools.md +156 -156
  16. package/dist/docs/ai-tools-and-skills.md +180 -180
  17. package/dist/docs/ai.md +1721 -1721
  18. package/dist/docs/analytics.md +39 -39
  19. package/dist/docs/api-versions.md +76 -0
  20. package/dist/docs/app-data-storage.md +277 -277
  21. package/dist/docs/app-docs.md +73 -73
  22. package/dist/docs/app-manifest.md +852 -852
  23. package/dist/docs/app-records-pattern.md +388 -388
  24. package/dist/docs/appConfig.md +550 -550
  25. package/dist/docs/assistant-apps.md +172 -172
  26. package/dist/docs/assistant-context.md +119 -119
  27. package/dist/docs/bookings.md +442 -442
  28. package/dist/docs/comms.md +686 -686
  29. package/dist/docs/connectors.md +340 -340
  30. package/dist/docs/css-baseline.md +133 -133
  31. package/dist/docs/customer-guide.md +70 -70
  32. package/dist/docs/deploying-apps.md +340 -340
  33. package/dist/docs/dpp.md +115 -99
  34. package/dist/docs/entitlements.md +90 -90
  35. package/dist/docs/files.md +69 -69
  36. package/dist/docs/host-dependency-contract.md +210 -210
  37. package/dist/docs/i18n.md +46 -292
  38. package/dist/docs/integrations.md +322 -322
  39. package/dist/docs/interactions.md +545 -545
  40. package/dist/docs/item-context.md +181 -181
  41. package/dist/docs/knowledge.md +102 -102
  42. package/dist/docs/lots.md +111 -111
  43. package/dist/docs/loyalty.md +352 -352
  44. package/dist/docs/members.md +183 -183
  45. package/dist/docs/memberships.md +149 -149
  46. package/dist/docs/mobile-admin-container.md +693 -693
  47. package/dist/docs/operations.md +281 -281
  48. package/dist/docs/overview.md +485 -485
  49. package/dist/docs/proof-comms-triggers.md +142 -142
  50. package/dist/docs/proof-ownership-transfer.md +155 -155
  51. package/dist/docs/proof-product-data-scoping.md +462 -462
  52. package/dist/docs/proof-share-grants.md +305 -305
  53. package/dist/docs/realtime.md +138 -138
  54. package/dist/docs/records-admin-pattern.md +304 -304
  55. package/dist/docs/server-functions.md +1 -1
  56. package/dist/docs/service-accounts.md +64 -64
  57. package/dist/docs/standard-query.md +187 -187
  58. package/dist/docs/tag-codes.md +97 -97
  59. package/dist/docs/theme-tokens.md +252 -252
  60. package/dist/docs/wallet-passes.md +107 -107
  61. package/dist/docs/websites.md +123 -123
  62. package/dist/http.d.ts +14 -0
  63. package/dist/http.js +65 -3
  64. package/dist/i18n.d.ts +14 -2
  65. package/dist/i18n.js +23 -6
  66. package/dist/index.d.ts +2 -1
  67. package/dist/index.js +3 -1
  68. package/dist/openapi.yaml +6 -3
  69. package/dist/theme-boot.js +82 -82
  70. package/dist/theme.css +75 -75
  71. package/dist/types/dpp.d.ts +14 -5
  72. package/dist/utils/index.d.ts +1 -0
  73. package/dist/utils/index.js +1 -0
  74. package/dist/utils/money.d.ts +15 -0
  75. package/dist/utils/money.js +72 -0
  76. package/dist/version.d.ts +1 -0
  77. package/dist/version.js +2 -0
  78. package/docs/API_SUMMARY.md +821 -811
  79. package/docs/admin-cards.md +189 -189
  80. package/docs/agent-tools.md +156 -156
  81. package/docs/ai-tools-and-skills.md +180 -180
  82. package/docs/ai.md +1721 -1721
  83. package/docs/analytics.md +39 -39
  84. package/docs/api-versions.md +76 -0
  85. package/docs/app-data-storage.md +277 -277
  86. package/docs/app-docs.md +73 -73
  87. package/docs/app-manifest.md +852 -852
  88. package/docs/app-records-pattern.md +388 -388
  89. package/docs/appConfig.md +550 -550
  90. package/docs/assistant-apps.md +172 -172
  91. package/docs/assistant-context.md +119 -119
  92. package/docs/bookings.md +442 -442
  93. package/docs/comms.md +686 -686
  94. package/docs/connectors.md +340 -340
  95. package/docs/css-baseline.md +133 -133
  96. package/docs/customer-guide.md +70 -70
  97. package/docs/deploying-apps.md +340 -340
  98. package/docs/dpp.md +115 -99
  99. package/docs/entitlements.md +90 -90
  100. package/docs/files.md +69 -69
  101. package/docs/host-dependency-contract.md +210 -210
  102. package/docs/i18n.md +46 -292
  103. package/docs/integrations.md +322 -322
  104. package/docs/interactions.md +545 -545
  105. package/docs/item-context.md +181 -181
  106. package/docs/knowledge.md +102 -102
  107. package/docs/lots.md +111 -111
  108. package/docs/loyalty.md +352 -352
  109. package/docs/members.md +183 -183
  110. package/docs/memberships.md +149 -149
  111. package/docs/mobile-admin-container.md +693 -693
  112. package/docs/operations.md +281 -281
  113. package/docs/overview.md +485 -485
  114. package/docs/proof-comms-triggers.md +142 -142
  115. package/docs/proof-ownership-transfer.md +155 -155
  116. package/docs/proof-product-data-scoping.md +462 -462
  117. package/docs/proof-share-grants.md +305 -305
  118. package/docs/realtime.md +138 -138
  119. package/docs/server-functions.md +1 -1
  120. package/docs/service-accounts.md +64 -64
  121. package/docs/standard-query.md +187 -187
  122. package/docs/tag-codes.md +97 -97
  123. package/docs/theme-lookbook.v1.json +120 -120
  124. package/docs/theme-tokens.md +252 -252
  125. package/docs/wallet-passes.md +107 -107
  126. package/docs/websites.md +123 -123
  127. package/openapi.yaml +6 -3
  128. package/package.json +87 -87
  129. package/scripts/headless-check.mjs +87 -87
  130. package/scripts/lib/bare-imports.mjs +57 -57
  131. package/scripts/lib/keyed-app-data.mjs +21 -21
  132. package/scripts/publish.mjs +272 -272
  133. package/scripts/register-release.mjs +91 -91
package/docs/dpp.md CHANGED
@@ -1,99 +1,115 @@
1
- # EU Digital Product Passports
2
-
3
- SmartLinks hosts a brand's **EU Digital Product Passports** (ESPR) and registers them in the **EU registry** for
4
- the brand. Each passport has its own permanent address, which is the identifier the EU registers. The public view
5
- there is open to anyone; the restricted views (dismantling details, test reports, battery state of health) are served
6
- only to the EU registry, for that brand.
7
-
8
- Batteries come first (mandatory from 18 February 2027). Fields are named as in the Commission's own schemas
9
- (`batteryChemistry`, `manufacturerIdentification`, …): `dpp.groups()` lists them, with what's required.
10
-
11
- ## Connecting a brand to the EU registry
12
-
13
- The EU only lets an organisation register its own passports, so the **brand enrols itself**: an EU Login, and a
14
- declaration sealed with the brand's own **qualified e-seal** (from a provider on the EU trusted list). That happens
15
- on the EU's site. Nobody sends SmartLinks a seal, certificate or private key.
16
-
17
- Then, once per environment (`acc` = the EU test registry, `prod` = the live one):
18
-
19
- ```ts
20
- import { dpp } from "@proveanything/smartlinks"
21
-
22
- // 1. SmartLinks makes the key; the brand adds the PUBLIC key to a Service Account ("Register DPPs" role).
23
- const reg = await dpp.registry.makeKey(collectionId, "acc")
24
- showToAdmin(reg.publicPem) // also reg.publicJwk; reg.portal is the registry's address
25
-
26
- // 2. The brand pastes back three values from the registry.
27
- await dpp.registry.set(collectionId, "acc", {
28
- clientId: "…", // the Service Account's Client ID
29
- kid: "…", // the key ID the registry gave our key
30
- orgIdentifier: "…", // Organisation > Verification > Organisation ID, copied exactly
31
- })
32
-
33
- // 3. Check: signs in and reads the registry's product groups.
34
- const { registry } = await dpp.registry.check(collectionId, "acc")
35
- registry.lastCheck // { ok: true, … } or { ok: false, message: "…plain words…" }
36
- ```
37
-
38
- `dpp.registry.list(collectionId)` gives both environments, each with `nextStep`
39
- (`make-key` → `enter-service-account` → `enter-organisation-id` → `check` → `null` when connected). Show them as
40
- numbered steps.
41
-
42
- ## Publishing passports
43
-
44
- Say what a passport is for (a product, a batch or one item) and its granularity. SmartLinks updates that passport
45
- or makes it:
46
-
47
- ```ts
48
- const { passport, created, changed } = await dpp.passports.upsert(collectionId, {
49
- productId, // and/or batchId, proofId (one battery = a proof)
50
- productGroup: "BATTERIES",
51
- productSubGroup: "EV", // EV, LMT or IND
52
- granularity: "item", // item | batch | model
53
- modelIdentifier: "IC-75-LFP",
54
- public: { batteryChemistry: ["https://repository.product-passport.ec.europa.eu/product/batteries/vocabs/battery-chemistry#lithiumIonLFP"], /* … */ },
55
- restricted: { dismantlingInformation: [/* … */], batteryStatus: "…" },
56
- })
57
-
58
- passport.url // its address — what goes on the QR code and to the registry
59
- passport.check // { ready, missing: { pub: [...], res1: [...], res2: [...], res3: [...] } }
60
- passport.version // goes up by one each time what it says changes
61
- ```
62
-
63
- - **Publishing replaces**: the fields you send are the whole passport (`{ merge: true }` merges instead).
64
- Publishing the same content again changes nothing (`changed: false`).
65
- - **Many at once** (one per battery): `dpp.passports.upsertMany(collectionId, items)` — up to 500, each answering
66
- on its own.
67
- - **Versions**: `dpp.passports.versions(collectionId, id)`; read an earlier one with
68
- `dpp.read(collectionId, id, { version: 2 })` (also `?version=2` on its address).
69
- - **Withdraw / restore**: a withdrawn passport stays at its address, marked invalid.
70
- - Never put restricted fields in `public`: anyone can read the public view.
71
-
72
- `dpp.read(collectionId, passportId)` returns the public document exactly as served — use it for a public page,
73
- so restricted data never reaches the browser.
74
-
75
- ## Registering
76
-
77
- ```ts
78
- const { tasks, skipped } = await dpp.register(collectionId, "acc", passportIds, { wait: true })
79
- // skipped: not found, withdrawn, already registered, or missing required fields (with the list)
80
- // tasks[i].passports: each one's outcome — registered (with registryId) | rejected (problems) | not-sent
81
- ```
82
-
83
- The registry reads each passport at its address while validating it, and one bad passport rejects the whole
84
- request — so passports still missing required fields are never sent. Without `wait`, follow up with
85
- `dpp.tasks.refresh(collectionId, "acc", taskId)`; `dpp.tasks.list(collectionId, "acc")` lists past requests. Each
86
- passport's `registration.acc` / `registration.prod` holds its status.
87
-
88
- ## Reference
89
-
90
- | Call | Does |
91
- |---|---|
92
- | `dpp.groups(collectionId)` | product groups, kinds, every field and the required ones per view |
93
- | `dpp.read(collectionId, id, { version? })` | the public document at its address (no sign-in) |
94
- | `dpp.registry.list / get / makeKey / set / check` | the brand's registry connection |
95
- | `dpp.passports.list / get / create / update / upsert / upsertMany / versions / withdraw / restore` | passports |
96
- | `dpp.register(collectionId, env, ids, { wait? })` | send to the registry |
97
- | `dpp.tasks.list / refresh` | registry requests and their outcomes |
98
-
99
- Admin calls need a collection admin. Platform design: prove `server/docs/design/eu-dpp.md`.
1
+ # EU Digital Product Passports
2
+
3
+ SmartLinks hosts a brand's **EU Digital Product Passports** (ESPR) and registers them in the **EU registry** for
4
+ the brand. Each passport has its own permanent address, which is the identifier the EU registers. The public view
5
+ there is open to anyone; the restricted views (dismantling details, test reports, battery state of health) are served
6
+ only to the EU registry, for that brand.
7
+
8
+ Batteries come first (mandatory from 18 February 2027). Fields are named as in the Commission's own schemas
9
+ (`batteryChemistry`, `manufacturerIdentification`, …): `dpp.groups()` lists them, with what's required.
10
+
11
+ ## Connecting a brand to the EU registry
12
+
13
+ The EU only lets an organisation register its own passports, so the **brand enrols itself**: an EU Login, and a
14
+ declaration sealed with the brand's own **qualified e-seal** (from a provider on the EU trusted list). That happens
15
+ on the EU's site. Nobody sends SmartLinks a seal, certificate or private key.
16
+
17
+ Then, once per environment (`acc` = the EU test registry, `prod` = the live one):
18
+
19
+ ```ts
20
+ import { dpp } from "@proveanything/smartlinks"
21
+
22
+ // 1. SmartLinks makes the key; the brand adds the PUBLIC key to a Service Account ("Register DPPs" role).
23
+ const reg = await dpp.registry.makeKey(collectionId, "acc")
24
+ showToAdmin(reg.publicPem) // also reg.publicJwk; reg.portal is the registry's address
25
+
26
+ // 2. The brand pastes back three values from the registry.
27
+ await dpp.registry.set(collectionId, "acc", {
28
+ clientId: "…", // the Service Account's Client ID
29
+ kid: "…", // the key ID the registry gave our key
30
+ orgIdentifier: "…", // Organisation > Verification > Organisation ID, copied exactly
31
+ })
32
+
33
+ // 3. Check: signs in and reads the registry's product groups.
34
+ const { registry } = await dpp.registry.check(collectionId, "acc")
35
+ registry.lastCheck // { ok: true, … } or { ok: false, message: "…plain words…" }
36
+ ```
37
+
38
+ `dpp.registry.list(collectionId)` gives both environments, each with `nextStep`
39
+ (`make-key` → `enter-service-account` → `enter-organisation-id` → `check` → `null` when connected). Show them as
40
+ numbered steps.
41
+
42
+ ## Practising first: the SmartLinks practice registry
43
+
44
+ Until a brand is verified with the EU, connect it to the **SmartLinks practice registry** instead. It works like
45
+ the EU registry (it signs in as the brand, reads each passport at its address, checks the public and restricted
46
+ views and the required fields, and answers with registration ids), but **nothing reaches the EU**. Label it as
47
+ practice wherever it's shown (`registry.practice` is `true`).
48
+
49
+ ```ts
50
+ const { registry } = await dpp.registry.enrolPractice(collectionId) // key + enrolment + Service Account + check
51
+ await dpp.register(collectionId, "practice", passportIds, { wait: true })
52
+ // passport.registration.practice → { status: "registered", registryId: "uri_practice_…" }
53
+ ```
54
+
55
+ Moving to the EU later is the normal set-up for `acc` (then `prod`): the passports stay the same.
56
+
57
+ ## Publishing passports
58
+
59
+ Say what a passport is for (a product, a batch or one item) and its granularity. SmartLinks updates that passport
60
+ or makes it:
61
+
62
+ ```ts
63
+ const { passport, created, changed } = await dpp.passports.upsert(collectionId, {
64
+ productId, // and/or batchId, proofId (one battery = a proof)
65
+ productGroup: "BATTERIES",
66
+ productSubGroup: "EV", // EV, LMT or IND
67
+ granularity: "item", // item | batch | model
68
+ modelIdentifier: "IC-75-LFP",
69
+ public: { batteryChemistry: ["https://repository.product-passport.ec.europa.eu/product/batteries/vocabs/battery-chemistry#lithiumIonLFP"], /* … */ },
70
+ restricted: { dismantlingInformation: [/* … */], batteryStatus: "…" },
71
+ })
72
+
73
+ passport.url // its address — what goes on the QR code and to the registry
74
+ passport.check // { ready, missing: { pub: [...], res1: [...], res2: [...], res3: [...] } }
75
+ passport.version // goes up by one each time what it says changes
76
+ ```
77
+
78
+ - **Publishing replaces**: the fields you send are the whole passport (`{ merge: true }` merges instead).
79
+ Publishing the same content again changes nothing (`changed: false`).
80
+ - **Many at once** (one per battery): `dpp.passports.upsertMany(collectionId, items)` — up to 500, each answering
81
+ on its own.
82
+ - **Versions**: `dpp.passports.versions(collectionId, id)`; read an earlier one with
83
+ `dpp.read(collectionId, id, { version: 2 })` (also `?version=2` on its address).
84
+ - **Withdraw / restore**: a withdrawn passport stays at its address, marked invalid.
85
+ - Never put restricted fields in `public`: anyone can read the public view.
86
+
87
+ `dpp.read(collectionId, passportId)` returns the public document exactly as served — use it for a public page,
88
+ so restricted data never reaches the browser.
89
+
90
+ ## Registering
91
+
92
+ ```ts
93
+ const { tasks, skipped } = await dpp.register(collectionId, "acc", passportIds, { wait: true })
94
+ // skipped: not found, withdrawn, already registered, or missing required fields (with the list)
95
+ // tasks[i].passports: each one's outcome — registered (with registryId) | rejected (problems) | not-sent
96
+ ```
97
+
98
+ The registry reads each passport at its address while validating it, and one bad passport rejects the whole
99
+ request — so passports still missing required fields are never sent. Without `wait`, follow up with
100
+ `dpp.tasks.refresh(collectionId, "acc", taskId)`; `dpp.tasks.list(collectionId, "acc")` lists past requests. Each
101
+ passport's `registration.acc` / `registration.prod` holds its status.
102
+
103
+ ## Reference
104
+
105
+ | Call | Does |
106
+ |---|---|
107
+ | `dpp.groups(collectionId)` | product groups, kinds, every field and the required ones per view |
108
+ | `dpp.read(collectionId, id, { version? })` | the public document at its address (no sign-in) |
109
+ | `dpp.registry.list / get / makeKey / set / check` | the brand's registry connection |
110
+ | `dpp.registry.enrolPractice(collectionId)` | connect to the SmartLinks practice registry in one step (never the EU) |
111
+ | `dpp.passports.list / get / create / update / upsert / upsertMany / versions / withdraw / restore` | passports |
112
+ | `dpp.register(collectionId, env, ids, { wait? })` | send to the registry |
113
+ | `dpp.tasks.list / refresh` | registry requests and their outcomes |
114
+
115
+ Admin calls need a collection admin. Platform design: prove `server/docs/design/eu-dpp.md`.
@@ -1,90 +1,90 @@
1
- # Entitlements: "can this person do this?" without a mirror of their member base
2
-
3
- A brand with twenty million members wants a game only Gold members can play. SmartLinks never copies
4
- the member base to find out. A **gate** says what it needs — a predicate such as `tier>=gold` — and the
5
- platform asks the collection's configured **sources**, in order, stopping at the first that answers.
6
- The brand's system stays the record of truth; every answer says where it came from (`basis`) and how
7
- old it is (`asOf`).
8
-
9
- | Source | Data kept here | When it fits |
10
- |---|---|---|
11
- | **claims** | none | the brand's SSO or app issues a short-lived signed token carrying the tier; the caller presents it |
12
- | **lookup** | a hashed key → a small answer, for minutes | the loyalty connector's `lookup` step answers for one person; cached in Valkey under an HMAC of the identity for the TTL the brand sets (default 15 min; "not a member" 5 min); one in-flight lookup per key; the connector's own rate limit applies |
13
- | **contact** | what the contact already holds | `customFields.loyalty` / `loyaltyTier` written by the connector's member webhook (`ctx.sl.members.apply`) |
14
- | **fallback** | — | when nothing answered: `deny` (default), `allow`, or `degrade` (allow, flagged `degraded: true`) |
15
-
16
- Every decision is one structured log line — gate, predicate, allowed, basis, age, an identity **hash**
17
- — and never an identifier. A caller sees `attributes` (tier, points, status, member) and never a member
18
- id.
19
-
20
- ## Predicates
21
-
22
- ```
23
- 'tier>=gold' 'tier=silver' 'tier in gold,platinum' 'points>=500' 'member'
24
- { tier: { gte: 'gold' } } { tier: { in: ['gold', 'platinum'] } } { member: true }
25
- { attribute: { path: 'status', eq: 'active' } }
26
- { all: [p1, p2] } { any: [p1, p2] } { not: p }
27
- ```
28
-
29
- Tier comparisons use the collection's ordered `tiers` list (lowest first); a tier the list doesn't know
30
- never satisfies an ordered comparison. A malformed predicate is a configuration error (`BAD_PREDICATE`),
31
- never a silent denial.
32
-
33
- ## Where gates live
34
-
35
- **An interaction type** — the public submit route checks it; the caller may present a claim:
36
-
37
- ```ts
38
- await SL.interactions.updateInteraction(collectionId, appId, typeId, {
39
- permissions: { allowPublicSubmit: true, requires: { entitlement: 'tier>=gold', fallback: 'deny' } },
40
- })
41
- // A refused submit: 403 { error: 'FORBIDDEN', reason: 'entitlement_denied' }
42
- // With a claim: body.entitlementToken = '<jwt>' or header X-SmartLinks-Entitlement: <jwt>
43
- ```
44
-
45
- **A server function** — for the signed-in caller by default:
46
-
47
- ```ts
48
- const d = await ctx.sl.entitlements.check('tier>=gold') // needs sl:entitlements:read
49
- // → { allowed: true, basis: 'lookup-cache', asOf: '2026-11-08T09:00:00.000Z', attributes: { tier: 'gold', points: 1500, member: true } }
50
- if (!d.allowed) return new Response(JSON.stringify({ error: 'gold_only' }), { status: 403 })
51
- // Someone else, or a presented claim:
52
- await ctx.sl.entitlements.check({ points: { gte: 500 } }, { identity: { email }, token, fallback: 'degrade' })
53
- ```
54
-
55
- ## Configuring a collection
56
-
57
- The `entitlements` setting group (`settings.set(collectionId, 'entitlements', {...})`):
58
-
59
- ```jsonc
60
- {
61
- "sources": ["claims", "lookup", "contact"], // tried in this order
62
- "fallback": "deny",
63
- "tiers": ["bronze", "silver", "gold", "platinum"], // lowest first
64
- "claims": {
65
- "secretRef": "sec_brand_sso", // HS256 shared secret in the secret store …
66
- "publicKeyPem": "-----BEGIN PUBLIC KEY-----…", // … or an RS256 / ES256 public key
67
- "issuer": "https://login.brand.example", "audience": "smartlinks",
68
- "tierClaim": "tier", "memberIdClaim": "sub", "attributesClaim": "entitlements", "maxAgeSec": 900
69
- },
70
- "lookup": {
71
- "connectorAppId": "acme-loyalty", "provider": "acme-loyalty",
72
- "ttlSec": 900, "negativeTtlSec": 300,
73
- "identity": "raw", // what the connector's lookup receives: 'raw' (email/phone) or 'hashed'
74
- "want": ["tier", "points", "status"]
75
- }
76
- }
77
- ```
78
-
79
- The connector side (`lookup`) is one step: one identity in, `{ found, memberId, tier, points, status,
80
- asOf }` out; throw on an outage so the next source is tried — see
81
- [connectors.md](connectors.md#loyalty-and-crm-connectors).
82
-
83
- ## What a brand can be told
84
-
85
- - We never need a copy of your member base: claims and lookups hold nothing, or a minutes-old answer per
86
- active person.
87
- - Where you want a local copy, it holds no identifiers (the HMAC mirror — on request).
88
- - Your system remains the record of truth: every answer carries `asOf` and `basis`; TTLs are yours to set.
89
- - You see every call: the connector's calls are rate-limited, logged, and leave from a fixed egress IP.
90
- - Nothing leaves without a policy: the envelope's identity policy per flow.
1
+ # Entitlements: "can this person do this?" without a mirror of their member base
2
+
3
+ A brand with twenty million members wants a game only Gold members can play. SmartLinks never copies
4
+ the member base to find out. A **gate** says what it needs — a predicate such as `tier>=gold` — and the
5
+ platform asks the collection's configured **sources**, in order, stopping at the first that answers.
6
+ The brand's system stays the record of truth; every answer says where it came from (`basis`) and how
7
+ old it is (`asOf`).
8
+
9
+ | Source | Data kept here | When it fits |
10
+ |---|---|---|
11
+ | **claims** | none | the brand's SSO or app issues a short-lived signed token carrying the tier; the caller presents it |
12
+ | **lookup** | a hashed key → a small answer, for minutes | the loyalty connector's `lookup` step answers for one person; cached in Valkey under an HMAC of the identity for the TTL the brand sets (default 15 min; "not a member" 5 min); one in-flight lookup per key; the connector's own rate limit applies |
13
+ | **contact** | what the contact already holds | `customFields.loyalty` / `loyaltyTier` written by the connector's member webhook (`ctx.sl.members.apply`) |
14
+ | **fallback** | — | when nothing answered: `deny` (default), `allow`, or `degrade` (allow, flagged `degraded: true`) |
15
+
16
+ Every decision is one structured log line — gate, predicate, allowed, basis, age, an identity **hash**
17
+ — and never an identifier. A caller sees `attributes` (tier, points, status, member) and never a member
18
+ id.
19
+
20
+ ## Predicates
21
+
22
+ ```
23
+ 'tier>=gold' 'tier=silver' 'tier in gold,platinum' 'points>=500' 'member'
24
+ { tier: { gte: 'gold' } } { tier: { in: ['gold', 'platinum'] } } { member: true }
25
+ { attribute: { path: 'status', eq: 'active' } }
26
+ { all: [p1, p2] } { any: [p1, p2] } { not: p }
27
+ ```
28
+
29
+ Tier comparisons use the collection's ordered `tiers` list (lowest first); a tier the list doesn't know
30
+ never satisfies an ordered comparison. A malformed predicate is a configuration error (`BAD_PREDICATE`),
31
+ never a silent denial.
32
+
33
+ ## Where gates live
34
+
35
+ **An interaction type** — the public submit route checks it; the caller may present a claim:
36
+
37
+ ```ts
38
+ await SL.interactions.updateInteraction(collectionId, appId, typeId, {
39
+ permissions: { allowPublicSubmit: true, requires: { entitlement: 'tier>=gold', fallback: 'deny' } },
40
+ })
41
+ // A refused submit: 403 { error: 'FORBIDDEN', reason: 'entitlement_denied' }
42
+ // With a claim: body.entitlementToken = '<jwt>' or header X-SmartLinks-Entitlement: <jwt>
43
+ ```
44
+
45
+ **A server function** — for the signed-in caller by default:
46
+
47
+ ```ts
48
+ const d = await ctx.sl.entitlements.check('tier>=gold') // needs sl:entitlements:read
49
+ // → { allowed: true, basis: 'lookup-cache', asOf: '2026-11-08T09:00:00.000Z', attributes: { tier: 'gold', points: 1500, member: true } }
50
+ if (!d.allowed) return new Response(JSON.stringify({ error: 'gold_only' }), { status: 403 })
51
+ // Someone else, or a presented claim:
52
+ await ctx.sl.entitlements.check({ points: { gte: 500 } }, { identity: { email }, token, fallback: 'degrade' })
53
+ ```
54
+
55
+ ## Configuring a collection
56
+
57
+ The `entitlements` setting group (`settings.set(collectionId, 'entitlements', {...})`):
58
+
59
+ ```jsonc
60
+ {
61
+ "sources": ["claims", "lookup", "contact"], // tried in this order
62
+ "fallback": "deny",
63
+ "tiers": ["bronze", "silver", "gold", "platinum"], // lowest first
64
+ "claims": {
65
+ "secretRef": "sec_brand_sso", // HS256 shared secret in the secret store …
66
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----…", // … or an RS256 / ES256 public key
67
+ "issuer": "https://login.brand.example", "audience": "smartlinks",
68
+ "tierClaim": "tier", "memberIdClaim": "sub", "attributesClaim": "entitlements", "maxAgeSec": 900
69
+ },
70
+ "lookup": {
71
+ "connectorAppId": "acme-loyalty", "provider": "acme-loyalty",
72
+ "ttlSec": 900, "negativeTtlSec": 300,
73
+ "identity": "raw", // what the connector's lookup receives: 'raw' (email/phone) or 'hashed'
74
+ "want": ["tier", "points", "status"]
75
+ }
76
+ }
77
+ ```
78
+
79
+ The connector side (`lookup`) is one step: one identity in, `{ found, memberId, tier, points, status,
80
+ asOf }` out; throw on an outage so the next source is tried — see
81
+ [connectors.md](connectors.md#loyalty-and-crm-connectors).
82
+
83
+ ## What a brand can be told
84
+
85
+ - We never need a copy of your member base: claims and lookups hold nothing, or a minutes-old answer per
86
+ active person.
87
+ - Where you want a local copy, it holds no identifiers (the HMAC mirror — on request).
88
+ - Your system remains the record of truth: every answer carries `asOf` and `basis`; TTLs are yours to set.
89
+ - You see every call: the connector's calls are rate-limited, logged, and leave from a fixed egress IP.
90
+ - Nothing leaves without a policy: the envelope's identity policy per flow.
package/docs/files.md CHANGED
@@ -1,69 +1,69 @@
1
- # Files
2
-
3
- Files are for the things an app or an AI tool needs to hold onto that nobody browses: a supplier's spec sheet fetched
4
- to read product details from, a web page with a recipe, a deck to summarise, an image to read text from, a JSON result
5
- to pass between steps.
6
-
7
- A file is an asset, with three differences:
8
-
9
- - **It can be temporary.** It's removed at `expiresAt` (`ttl` from `1h` to `30d`, default `1d`).
10
- - **It's private** until kept. You read it through `files.read` or a signed link from `files.link`.
11
- - **It stays out of asset lists.** Pickers, the media library, the Hub and the portal never show temporary or
12
- extracted files. `files.keep` makes a file permanent and public (with an `assetUrl`), and it then shows like any
13
- upload.
14
-
15
- ## Fetch once, extract once
16
-
17
- ```typescript
18
- import { files } from '@proveanything/smartlinks'
19
-
20
- // The same address returns the same file while it's fresh; once stale, an unchanged page isn't downloaded again.
21
- const { file } = await files.fetch(collectionId, { url: 'https://supplier.example/spec.pdf', ttl: '7d' })
22
-
23
- // Each file is read each way once: asking again returns the same result (cached: true).
24
- const { text } = await files.extract(collectionId, file.id, { variant: 'markdown' })
25
-
26
- const { data } = await files.extract(collectionId, file.id, {
27
- variant: 'json',
28
- schema: { type: 'object', properties: { gtin: { type: 'string' }, weightKg: { type: 'number' } } },
29
- })
30
- ```
31
-
32
- | Variant | Gives | Works on |
33
- |---|---|---|
34
- | `text` | plain text | PDFs, HTML, text, JSON, and web pages / documents |
35
- | `markdown` | Markdown | web pages, PDFs, decks, documents |
36
- | `ocr` | text read from an image | images |
37
- | `json` | typed fields (`schema` and/or `prompt`) | anything readable |
38
-
39
- What's extracted is kept beside its source as a derived file (`origin: 'derived'`, `derivedFromId`, `variant`) and
40
- lives as long as the source does.
41
-
42
- ## Your own files
43
-
44
- ```typescript
45
- const { file } = await files.put(collectionId, { name: 'notes.json', json: { step: 2 }, ttl: '1d' })
46
- const { text } = await files.read(collectionId, file.id) // or 'base64'
47
- const { url } = await files.link(collectionId, file.id, 15) // a signed link for 15 minutes
48
- await files.keep(collectionId, file.id) // permanent, public, shows in pickers
49
- await files.remove(collectionId, file.id)
50
- const { files: mine } = await files.list(collectionId, { appId: 'my-app', origin: 'fetched' })
51
- ```
52
-
53
- ## In a server function
54
-
55
- The same calls are on `ctx.sl.files` (manifest scopes `sl:files:read` and `sl:files:write`), without the collection
56
- id. AI tools get `file.fetch`, `file.extract` and `file.read`, which hand back file references rather than pasting
57
- whole documents into the conversation.
58
-
59
- ```js
60
- const page = await ctx.sl.files.fetch('https://cook.example/pancakes', { ttl: '7d' })
61
- const { data } = await ctx.sl.files.extract(page.id, 'json', { schema })
62
- ```
63
-
64
- ## Limits
65
-
66
- - Fetching: public web addresses only (checked on every redirect), up to 50 MB.
67
- - Reading contents: up to 25 MB.
68
- - Temporary files per site: 5,000 files or 2 GB at once; past that the oldest temporary files go first. Kept files
69
- aren't capped here.
1
+ # Files
2
+
3
+ Files are for the things an app or an AI tool needs to hold onto that nobody browses: a supplier's spec sheet fetched
4
+ to read product details from, a web page with a recipe, a deck to summarise, an image to read text from, a JSON result
5
+ to pass between steps.
6
+
7
+ A file is an asset, with three differences:
8
+
9
+ - **It can be temporary.** It's removed at `expiresAt` (`ttl` from `1h` to `30d`, default `1d`).
10
+ - **It's private** until kept. You read it through `files.read` or a signed link from `files.link`.
11
+ - **It stays out of asset lists.** Pickers, the media library, the Hub and the portal never show temporary or
12
+ extracted files. `files.keep` makes a file permanent and public (with an `assetUrl`), and it then shows like any
13
+ upload.
14
+
15
+ ## Fetch once, extract once
16
+
17
+ ```typescript
18
+ import { files } from '@proveanything/smartlinks'
19
+
20
+ // The same address returns the same file while it's fresh; once stale, an unchanged page isn't downloaded again.
21
+ const { file } = await files.fetch(collectionId, { url: 'https://supplier.example/spec.pdf', ttl: '7d' })
22
+
23
+ // Each file is read each way once: asking again returns the same result (cached: true).
24
+ const { text } = await files.extract(collectionId, file.id, { variant: 'markdown' })
25
+
26
+ const { data } = await files.extract(collectionId, file.id, {
27
+ variant: 'json',
28
+ schema: { type: 'object', properties: { gtin: { type: 'string' }, weightKg: { type: 'number' } } },
29
+ })
30
+ ```
31
+
32
+ | Variant | Gives | Works on |
33
+ |---|---|---|
34
+ | `text` | plain text | PDFs, HTML, text, JSON, and web pages / documents |
35
+ | `markdown` | Markdown | web pages, PDFs, decks, documents |
36
+ | `ocr` | text read from an image | images |
37
+ | `json` | typed fields (`schema` and/or `prompt`) | anything readable |
38
+
39
+ What's extracted is kept beside its source as a derived file (`origin: 'derived'`, `derivedFromId`, `variant`) and
40
+ lives as long as the source does.
41
+
42
+ ## Your own files
43
+
44
+ ```typescript
45
+ const { file } = await files.put(collectionId, { name: 'notes.json', json: { step: 2 }, ttl: '1d' })
46
+ const { text } = await files.read(collectionId, file.id) // or 'base64'
47
+ const { url } = await files.link(collectionId, file.id, 15) // a signed link for 15 minutes
48
+ await files.keep(collectionId, file.id) // permanent, public, shows in pickers
49
+ await files.remove(collectionId, file.id)
50
+ const { files: mine } = await files.list(collectionId, { appId: 'my-app', origin: 'fetched' })
51
+ ```
52
+
53
+ ## In a server function
54
+
55
+ The same calls are on `ctx.sl.files` (manifest scopes `sl:files:read` and `sl:files:write`), without the collection
56
+ id. AI tools get `file.fetch`, `file.extract` and `file.read`, which hand back file references rather than pasting
57
+ whole documents into the conversation.
58
+
59
+ ```js
60
+ const page = await ctx.sl.files.fetch('https://cook.example/pancakes', { ttl: '7d' })
61
+ const { data } = await ctx.sl.files.extract(page.id, 'json', { schema })
62
+ ```
63
+
64
+ ## Limits
65
+
66
+ - Fetching: public web addresses only (checked on every redirect), up to 50 MB.
67
+ - Reading contents: up to 25 MB.
68
+ - Temporary files per site: 5,000 files or 2 GB at once; past that the oldest temporary files go first. Kept files
69
+ aren't capped here.