@proveanything/smartlinks 2.1.39 → 2.1.41

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 (121) 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/adminViews.d.ts +1 -1
  5. package/dist/adminViews.js +3 -1
  6. package/dist/ai-tools.d.ts +2 -1
  7. package/dist/ai-tools.js +3 -0
  8. package/dist/api/ai.d.ts +2 -21
  9. package/dist/api/ai.js +0 -35
  10. package/dist/api/collection.d.ts +8 -1
  11. package/dist/api/collection.js +10 -0
  12. package/dist/api/index.d.ts +1 -0
  13. package/dist/api/index.js +1 -0
  14. package/dist/api/knowledge.d.ts +64 -0
  15. package/dist/api/knowledge.js +97 -0
  16. package/dist/baseline.css +194 -194
  17. package/dist/docs/API_SUMMARY.md +1046 -964
  18. package/dist/docs/admin-cards.md +189 -189
  19. package/dist/docs/admin-views.md +257 -255
  20. package/dist/docs/agent-tools.md +156 -156
  21. package/dist/docs/ai-tools-and-skills.md +180 -180
  22. package/dist/docs/ai.md +1721 -1834
  23. package/dist/docs/analytics.md +39 -39
  24. package/dist/docs/app-data-storage.md +277 -277
  25. package/dist/docs/app-docs.md +73 -73
  26. package/dist/docs/app-manifest.md +852 -852
  27. package/dist/docs/app-records-pattern.md +388 -388
  28. package/dist/docs/appConfig.md +550 -550
  29. package/dist/docs/assistant-apps.md +172 -172
  30. package/dist/docs/assistant-context.md +119 -119
  31. package/dist/docs/bookings.md +442 -442
  32. package/dist/docs/comms.md +686 -686
  33. package/dist/docs/connectors.md +340 -340
  34. package/dist/docs/css-baseline.md +133 -133
  35. package/dist/docs/customer-guide.md +70 -70
  36. package/dist/docs/deploying-apps.md +340 -340
  37. package/dist/docs/entitlements.md +90 -90
  38. package/dist/docs/files.md +69 -69
  39. package/dist/docs/host-dependency-contract.md +210 -210
  40. package/dist/docs/integrations.md +322 -322
  41. package/dist/docs/interactions.md +545 -545
  42. package/dist/docs/item-context.md +181 -181
  43. package/dist/docs/knowledge.md +102 -0
  44. package/dist/docs/lots.md +111 -111
  45. package/dist/docs/loyalty.md +352 -352
  46. package/dist/docs/members.md +182 -182
  47. package/dist/docs/mobile-admin-container.md +693 -693
  48. package/dist/docs/operations.md +281 -281
  49. package/dist/docs/overview.md +482 -482
  50. package/dist/docs/proof-comms-triggers.md +142 -142
  51. package/dist/docs/proof-ownership-transfer.md +155 -155
  52. package/dist/docs/proof-product-data-scoping.md +462 -462
  53. package/dist/docs/proof-share-grants.md +305 -305
  54. package/dist/docs/realtime.md +138 -138
  55. package/dist/docs/records-admin-pattern.md +304 -304
  56. package/dist/docs/standard-query.md +187 -187
  57. package/dist/docs/tag-codes.md +97 -97
  58. package/dist/docs/theme-tokens.md +252 -252
  59. package/dist/docs/wallet-passes.md +107 -107
  60. package/dist/docs/websites.md +123 -123
  61. package/dist/openapi.yaml +320 -306
  62. package/dist/theme-boot.js +78 -78
  63. package/dist/theme.css +75 -75
  64. package/dist/types/ai.d.ts +9 -91
  65. package/dist/types/appManifest.d.ts +21 -0
  66. package/dist/types/collection.d.ts +26 -0
  67. package/dist/types/index.d.ts +1 -0
  68. package/dist/types/index.js +1 -0
  69. package/dist/types/knowledge.d.ts +120 -0
  70. package/dist/types/knowledge.js +2 -0
  71. package/docs/API_SUMMARY.md +1046 -964
  72. package/docs/admin-cards.md +189 -189
  73. package/docs/admin-views.md +257 -255
  74. package/docs/agent-tools.md +156 -156
  75. package/docs/ai-tools-and-skills.md +180 -180
  76. package/docs/ai.md +1721 -1834
  77. package/docs/analytics.md +39 -39
  78. package/docs/app-data-storage.md +277 -277
  79. package/docs/app-docs.md +73 -73
  80. package/docs/app-manifest.md +852 -852
  81. package/docs/app-records-pattern.md +388 -388
  82. package/docs/appConfig.md +550 -550
  83. package/docs/assistant-apps.md +172 -172
  84. package/docs/assistant-context.md +119 -119
  85. package/docs/bookings.md +442 -442
  86. package/docs/comms.md +686 -686
  87. package/docs/connectors.md +340 -340
  88. package/docs/css-baseline.md +133 -133
  89. package/docs/customer-guide.md +70 -70
  90. package/docs/deploying-apps.md +340 -340
  91. package/docs/entitlements.md +90 -90
  92. package/docs/files.md +69 -69
  93. package/docs/host-dependency-contract.md +210 -210
  94. package/docs/integrations.md +322 -322
  95. package/docs/interactions.md +545 -545
  96. package/docs/item-context.md +181 -181
  97. package/docs/knowledge.md +102 -0
  98. package/docs/lots.md +111 -111
  99. package/docs/loyalty.md +352 -352
  100. package/docs/members.md +182 -182
  101. package/docs/mobile-admin-container.md +693 -693
  102. package/docs/operations.md +281 -281
  103. package/docs/overview.md +482 -482
  104. package/docs/proof-comms-triggers.md +142 -142
  105. package/docs/proof-ownership-transfer.md +155 -155
  106. package/docs/proof-product-data-scoping.md +462 -462
  107. package/docs/proof-share-grants.md +305 -305
  108. package/docs/realtime.md +138 -138
  109. package/docs/standard-query.md +187 -187
  110. package/docs/tag-codes.md +97 -97
  111. package/docs/theme-lookbook.v1.json +120 -120
  112. package/docs/theme-tokens.md +252 -252
  113. package/docs/wallet-passes.md +107 -107
  114. package/docs/websites.md +123 -123
  115. package/openapi.yaml +320 -306
  116. package/package.json +87 -87
  117. package/scripts/headless-check.mjs +87 -87
  118. package/scripts/lib/bare-imports.mjs +57 -57
  119. package/scripts/lib/keyed-app-data.mjs +21 -21
  120. package/scripts/publish.mjs +272 -272
  121. package/scripts/register-release.mjs +91 -91
@@ -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.
@@ -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.