@proveanything/smartlinks 2.2.0 → 3.0.0-alpha.0
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.
- package/README.md +741 -754
- package/dist/README.md +573 -573
- package/dist/adminCardsView.js +55 -55
- package/dist/api/adminCards.d.ts +8 -0
- package/dist/api/adminCards.js +9 -1
- package/dist/api/ai.d.ts +22 -11
- package/dist/api/ai.js +18 -14
- package/dist/api/analytics.d.ts +13 -0
- package/dist/api/analytics.js +13 -0
- package/dist/api/appConfiguration.d.ts +17 -14
- package/dist/api/appConfiguration.js +14 -12
- package/dist/api/appObjects.d.ts +80 -16
- package/dist/api/appObjects.js +74 -11
- package/dist/api/asset.d.ts +55 -19
- package/dist/api/asset.js +52 -32
- package/dist/api/attestation.d.ts +3 -2
- package/dist/api/attestation.js +1 -1
- package/dist/api/attestations.d.ts +22 -7
- package/dist/api/attestations.js +22 -7
- package/dist/api/authKit.d.ts +22 -5
- package/dist/api/authKit.js +21 -4
- package/dist/api/batch.d.ts +23 -16
- package/dist/api/batch.js +19 -13
- package/dist/api/bookings.d.ts +45 -9
- package/dist/api/bookings.js +39 -3
- package/dist/api/broadcasts.d.ts +26 -6
- package/dist/api/broadcasts.js +22 -2
- package/dist/api/claimSet.d.ts +48 -13
- package/dist/api/claimSet.js +43 -7
- package/dist/api/collection.d.ts +20 -6
- package/dist/api/collection.js +19 -8
- package/dist/api/comms.d.ts +43 -12
- package/dist/api/comms.js +43 -13
- package/dist/api/conditions.d.ts +12 -2
- package/dist/api/conditions.js +10 -1
- package/dist/api/config.d.ts +15 -2
- package/dist/api/config.js +12 -0
- package/dist/api/contact.d.ts +34 -13
- package/dist/api/contact.js +35 -10
- package/dist/api/containers.d.ts +41 -23
- package/dist/api/containers.js +37 -21
- package/dist/api/crate.d.ts +9 -8
- package/dist/api/crate.js +8 -8
- package/dist/api/dpp.d.ts +58 -10
- package/dist/api/dpp.js +57 -15
- package/dist/api/facets.d.ts +71 -0
- package/dist/api/facets.js +71 -0
- package/dist/api/files.d.ts +11 -5
- package/dist/api/files.js +9 -1
- package/dist/api/form.d.ts +9 -2
- package/dist/api/form.js +7 -1
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.js +0 -1
- package/dist/api/integrations.d.ts +82 -27
- package/dist/api/integrations.js +63 -7
- package/dist/api/interactions.d.ts +42 -6
- package/dist/api/interactions.js +41 -5
- package/dist/api/jobs.d.ts +9 -2
- package/dist/api/jobs.js +6 -0
- package/dist/api/journeys.d.ts +13 -2
- package/dist/api/journeys.js +10 -1
- package/dist/api/journeysAnalytics.d.ts +12 -3
- package/dist/api/journeysAnalytics.js +9 -1
- package/dist/api/knowledge.d.ts +43 -10
- package/dist/api/knowledge.js +37 -5
- package/dist/api/location.d.ts +10 -3
- package/dist/api/location.js +7 -1
- package/dist/api/lots.d.ts +40 -13
- package/dist/api/lots.js +38 -8
- package/dist/api/loyalty.d.ts +70 -12
- package/dist/api/loyalty.js +60 -3
- package/dist/api/nfc.d.ts +8 -2
- package/dist/api/nfc.js +6 -1
- package/dist/api/order.d.ts +51 -160
- package/dist/api/order.js +46 -208
- package/dist/api/partner.d.ts +41 -8
- package/dist/api/partner.js +36 -4
- package/dist/api/products.d.ts +41 -8
- package/dist/api/products.js +33 -4
- package/dist/api/proof.d.ts +50 -13
- package/dist/api/proof.js +43 -7
- package/dist/api/realtime.d.ts +1 -11
- package/dist/api/realtime.js +1 -22
- package/dist/api/secrets.d.ts +25 -5
- package/dist/api/secrets.js +21 -2
- package/dist/api/segments.d.ts +26 -6
- package/dist/api/segments.js +22 -2
- package/dist/api/serviceAccounts.d.ts +8 -1
- package/dist/api/serviceAccounts.js +8 -1
- package/dist/api/shop.d.ts +41 -13
- package/dist/api/shop.js +35 -4
- package/dist/api/subscriptions.d.ts +47 -12
- package/dist/api/subscriptions.js +40 -4
- package/dist/api/tags.d.ts +40 -19
- package/dist/api/tags.js +38 -18
- package/dist/api/template.d.ts +31 -3
- package/dist/api/template.js +27 -0
- package/dist/api/translations.d.ts +17 -2
- package/dist/api/translations.js +14 -0
- package/dist/api/userGroups.d.ts +35 -9
- package/dist/api/userGroups.js +30 -5
- package/dist/api/variant.d.ts +11 -3
- package/dist/api/variant.js +9 -2
- package/dist/api/wallet.d.ts +23 -10
- package/dist/api/wallet.js +20 -2
- package/dist/apiVersion.d.ts +1 -1
- package/dist/apiVersion.js +1 -1
- package/dist/baseline.css +194 -194
- package/dist/docs/API_SUMMARY.md +1389 -2298
- package/dist/docs/PRODUCT_FACETS_SDK.md +10 -15
- package/dist/docs/admin-cards.md +189 -189
- package/dist/docs/admin-lists-and-pickers.md +1 -1
- package/dist/docs/agent-tools.md +156 -156
- package/dist/docs/ai-tools-and-skills.md +180 -180
- package/dist/docs/ai.md +1721 -1721
- package/dist/docs/analytics.md +3 -2
- package/dist/docs/api-versions.md +85 -76
- package/dist/docs/app-data-storage.md +277 -277
- package/dist/docs/app-docs.md +73 -73
- package/dist/docs/app-manifest.md +852 -852
- package/dist/docs/app-objects.md +38 -50
- package/dist/docs/app-records-pattern.md +388 -388
- package/dist/docs/appConfig.md +550 -550
- package/dist/docs/assets.md +17 -3
- package/dist/docs/assistant-apps.md +172 -172
- package/dist/docs/assistant-context.md +119 -119
- package/dist/docs/attestations.md +5 -4
- package/dist/docs/auth-kit.md +1 -1
- package/dist/docs/bookings.md +442 -442
- package/dist/docs/comms.md +689 -686
- package/dist/docs/connectors.md +340 -340
- package/dist/docs/contact-search.md +4 -3
- package/dist/docs/container-tracking.md +7 -7
- package/dist/docs/css-baseline.md +133 -133
- package/dist/docs/customer-guide.md +70 -70
- package/dist/docs/deploying-apps.md +340 -340
- package/dist/docs/dpp.md +115 -115
- package/dist/docs/entitlements.md +90 -90
- package/dist/docs/executor.md +1 -1
- package/dist/docs/files.md +69 -69
- package/dist/docs/forms.md +1 -1
- package/dist/docs/headless-providers.md +3 -3
- package/dist/docs/host-dependency-contract.md +252 -210
- package/dist/docs/i18n.md +9 -9
- package/dist/docs/integrations.md +322 -322
- package/dist/docs/interactions.md +544 -545
- package/dist/docs/item-context.md +181 -181
- package/dist/docs/knowledge.md +105 -102
- package/dist/docs/lists.md +114 -0
- package/dist/docs/lots.md +112 -111
- package/dist/docs/loyalty.md +348 -352
- package/dist/docs/members.md +183 -183
- package/dist/docs/memberships.md +150 -149
- package/dist/docs/mobile-admin-container.md +693 -693
- package/dist/docs/operations.md +281 -281
- package/dist/docs/overview.md +485 -485
- package/dist/docs/proof-claiming-methods.md +6 -6
- package/dist/docs/proof-comms-triggers.md +142 -142
- package/dist/docs/proof-ownership-transfer.md +155 -155
- package/dist/docs/proof-product-data-scoping.md +462 -462
- package/dist/docs/proof-share-grants.md +305 -305
- package/dist/docs/realtime.md +139 -138
- package/dist/docs/records-admin-pattern.md +304 -304
- package/dist/docs/server-functions.md +2 -2
- package/dist/docs/service-accounts.md +64 -64
- package/dist/docs/shop.md +4 -2
- package/dist/docs/site-seo.md +2 -1
- package/dist/docs/standard-query.md +187 -187
- package/dist/docs/tag-codes.md +97 -97
- package/dist/docs/tag-ranges.md +106 -106
- package/dist/docs/theme-tokens.md +252 -252
- package/dist/docs/translations.md +6 -1
- package/dist/docs/upgrading-to-3.md +430 -0
- package/dist/docs/user-groups.md +4 -4
- package/dist/docs/utils.md +1 -1
- package/dist/docs/wallet-passes.md +107 -107
- package/dist/docs/websites.md +123 -123
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +2 -2
- package/dist/http.d.ts +15 -2
- package/dist/http.js +60 -2
- package/dist/index.d.ts +7 -8
- package/dist/index.js +2 -0
- package/dist/list.d.ts +24 -0
- package/dist/list.js +80 -0
- package/dist/mobile-admin/types.d.ts +0 -16
- package/dist/openapi.yaml +290 -2723
- package/dist/shared-dependencies.d.ts +3 -3
- package/dist/shared-dependencies.js +13 -5
- package/dist/site.d.ts +1 -7
- package/dist/site.js +1 -14
- package/dist/theme-boot.js +82 -82
- package/dist/theme.css +75 -75
- package/dist/types/adminCards.d.ts +6 -3
- package/dist/types/ai.d.ts +0 -6
- package/dist/types/analytics.d.ts +5 -8
- package/dist/types/appManifest.d.ts +4 -5
- package/dist/types/appObjects.d.ts +14 -18
- package/dist/types/appObjects.js +0 -1
- package/dist/types/appOptions.d.ts +18 -0
- package/dist/types/asset.d.ts +3 -22
- package/dist/types/attestations.d.ts +7 -10
- package/dist/types/batch.d.ts +6 -14
- package/dist/types/bookings.d.ts +22 -4
- package/dist/types/broadcasts.d.ts +5 -13
- package/dist/types/broadcasts.js +0 -1
- package/dist/types/claimSet.d.ts +0 -5
- package/dist/types/comms.d.ts +11 -9
- package/dist/types/contact.d.ts +5 -29
- package/dist/types/contact.js +0 -13
- package/dist/types/containers.d.ts +15 -26
- package/dist/types/crate.d.ts +4 -12
- package/dist/types/dpp.d.ts +3 -3
- package/dist/types/dpp.js +0 -1
- package/dist/types/error.d.ts +8 -5
- package/dist/types/error.js +12 -5
- package/dist/types/facets.d.ts +15 -15
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/integrations.d.ts +3 -28
- package/dist/types/interaction.d.ts +3 -9
- package/dist/types/jobs.d.ts +3 -8
- package/dist/types/jobs.js +0 -1
- package/dist/types/journeys.d.ts +3 -8
- package/dist/types/journeys.js +0 -1
- package/dist/types/journeysAnalytics.d.ts +0 -1
- package/dist/types/list.d.ts +24 -0
- package/dist/types/list.js +2 -0
- package/dist/types/location.d.ts +0 -4
- package/dist/types/lots.d.ts +0 -9
- package/dist/types/loyalty.d.ts +0 -9
- package/dist/types/order.d.ts +7 -134
- package/dist/types/product.d.ts +11 -24
- package/dist/types/proof.d.ts +16 -0
- package/dist/types/realtime.d.ts +0 -29
- package/dist/types/segments.d.ts +5 -13
- package/dist/types/segments.js +0 -1
- package/dist/types/serviceAccounts.d.ts +3 -2
- package/dist/types/serviceAccounts.js +0 -1
- package/dist/types/shop.d.ts +5 -12
- package/dist/types/shop.js +0 -4
- package/dist/types/subscriptions.d.ts +18 -0
- package/dist/types/subscriptions.js +0 -8
- package/dist/types/tags.d.ts +6 -16
- package/dist/types/tags.js +0 -7
- package/dist/types/translations.d.ts +3 -9
- package/dist/types/variant.d.ts +0 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/API_SUMMARY.md +1389 -2298
- package/docs/PRODUCT_FACETS_SDK.md +10 -15
- package/docs/admin-cards.md +189 -189
- package/docs/admin-lists-and-pickers.md +1 -1
- package/docs/agent-tools.md +156 -156
- package/docs/ai-tools-and-skills.md +180 -180
- package/docs/ai.md +1721 -1721
- package/docs/analytics.md +3 -2
- package/docs/api-versions.md +85 -76
- package/docs/app-data-storage.md +277 -277
- package/docs/app-docs.md +73 -73
- package/docs/app-manifest.md +852 -852
- package/docs/app-objects.md +38 -50
- package/docs/app-records-pattern.md +388 -388
- package/docs/appConfig.md +550 -550
- package/docs/assets.md +17 -3
- package/docs/assistant-apps.md +172 -172
- package/docs/assistant-context.md +119 -119
- package/docs/attestations.md +5 -4
- package/docs/auth-kit.md +1 -1
- package/docs/bookings.md +442 -442
- package/docs/comms.md +689 -686
- package/docs/connectors.md +340 -340
- package/docs/contact-search.md +4 -3
- package/docs/container-tracking.md +7 -7
- package/docs/css-baseline.md +133 -133
- package/docs/customer-guide.md +70 -70
- package/docs/deploying-apps.md +340 -340
- package/docs/dpp.md +115 -115
- package/docs/entitlements.md +90 -90
- package/docs/executor.md +1 -1
- package/docs/files.md +69 -69
- package/docs/forms.md +1 -1
- package/docs/headless-providers.md +3 -3
- package/docs/host-dependency-contract.md +252 -210
- package/docs/i18n.md +9 -9
- package/docs/integrations.md +322 -322
- package/docs/interactions.md +544 -545
- package/docs/item-context.md +181 -181
- package/docs/knowledge.md +105 -102
- package/docs/lists.md +114 -0
- package/docs/lots.md +112 -111
- package/docs/loyalty.md +348 -352
- package/docs/members.md +183 -183
- package/docs/memberships.md +150 -149
- package/docs/mobile-admin-container.md +693 -693
- package/docs/operations.md +281 -281
- package/docs/overview.md +485 -485
- package/docs/proof-claiming-methods.md +6 -6
- package/docs/proof-comms-triggers.md +142 -142
- package/docs/proof-ownership-transfer.md +155 -155
- package/docs/proof-product-data-scoping.md +462 -462
- package/docs/proof-share-grants.md +305 -305
- package/docs/realtime.md +139 -138
- package/docs/server-functions.md +2 -2
- package/docs/service-accounts.md +64 -64
- package/docs/shop.md +4 -2
- package/docs/site-seo.md +2 -1
- package/docs/standard-query.md +187 -187
- package/docs/tag-codes.md +97 -97
- package/docs/tag-ranges.md +106 -106
- package/docs/theme-lookbook.v1.json +120 -120
- package/docs/theme-tokens.md +252 -252
- package/docs/translations.md +6 -1
- package/docs/upgrading-to-3.md +430 -0
- package/docs/user-groups.md +4 -4
- package/docs/utils.md +1 -1
- package/docs/wallet-passes.md +107 -107
- package/docs/websites.md +123 -123
- package/openapi.yaml +290 -2723
- package/package.json +91 -87
- package/scripts/headless-check.mjs +87 -87
- package/scripts/lib/bare-imports.mjs +57 -57
- package/scripts/lib/keyed-app-data.mjs +21 -21
- package/scripts/lib/upgrade.mjs +512 -0
- package/scripts/publish.mjs +272 -272
- package/scripts/register-release.mjs +91 -91
- package/scripts/upgrade.mjs +56 -0
- package/upgrade/3.json +2213 -0
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
# Wallet passes
|
|
2
|
-
|
|
3
|
-
Put an **event ticket**, a **booking**, a **membership card** or a **loyalty card** in the person's Apple Wallet or
|
|
4
|
-
Google Wallet. SmartLinks is the issuer and signs the passes. Each pass is branded from your site's name, logo and
|
|
5
|
-
colour, and your app decides what it says.
|
|
6
|
-
|
|
7
|
-
- **Who gets one:** only someone the business knows. A pass is issued to the signed-in owner of what it's for, or
|
|
8
|
-
by your app's own server function.
|
|
9
|
-
- **What the phone does:** the pass shows its QR code offline, appears near the time (and place, if you give
|
|
10
|
-
`venue.lat` / `lng`), and updates when you change it.
|
|
11
|
-
- **Bookings look after themselves:** when a booking is moved its pass shows the new time, and when it's cancelled
|
|
12
|
-
the pass is voided.
|
|
13
|
-
|
|
14
|
-
## In a page: "Add to Wallet"
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
17
|
-
import { wallet } from '@proveanything/smartlinks'
|
|
18
|
-
|
|
19
|
-
// The signed-in person's booking, membership card, or a pass your app issued them
|
|
20
|
-
const { pass } = await wallet.addLinks(collectionId, { type: 'booking', id: booking.id })
|
|
21
|
-
// pass.links.apple → opens the .pkpass on an iPhone
|
|
22
|
-
// pass.links.google → opens Google's "Save to Google Wallet" page
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
- `{ type: 'booking', id }` and `{ type: 'contact', id: 'me' }` are made on first ask:
|
|
26
|
-
- a booking pass, from the booking's date and time
|
|
27
|
-
- a membership card, from the person's `level` and `memberUntil` fields
|
|
28
|
-
- For anything else (an event ticket with your own title, a loyalty card with points), issue the pass in your server
|
|
29
|
-
function first. `addLinks` then returns that pass for its owner.
|
|
30
|
-
- Show the official "Add to Apple Wallet" and "Add to Google Wallet" badges, and only the one that suits the
|
|
31
|
-
device. A wallet that isn't set up yet is left out of `links`.
|
|
32
|
-
- `wallet.mine(collectionId)` lists the person's passes
|
|
33
|
-
|
|
34
|
-
## In a server function: issue, change, void, message
|
|
35
|
-
|
|
36
|
-
Declare `sl:wallet:write` in the function's capabilities.
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
// An event ticket
|
|
40
|
-
const pass = await ctx.sl.wallet.issue({
|
|
41
|
-
ref: { type: 'booking', id: booking.id }, // what it's for; issuing again changes the same pass
|
|
42
|
-
pass: {
|
|
43
|
-
kind: 'event',
|
|
44
|
-
title: 'Jazz on the Terrace',
|
|
45
|
-
start: '2026-12-24T19:00:00Z', end: '2026-12-24T22:00:00Z', timezone: 'Europe/London',
|
|
46
|
-
venue: { name: 'The Terrace', address: '1 High St, Bath', lat: 51.38, lng: -2.36 },
|
|
47
|
-
holder: 'Sam Lee', number: 'T-0042',
|
|
48
|
-
fields: [{ label: 'Seat', value: 'Table 6' }],
|
|
49
|
-
},
|
|
50
|
-
})
|
|
51
|
-
return { links: pass.links } // hand these to the page
|
|
52
|
-
|
|
53
|
-
// A loyalty card, kept up to date
|
|
54
|
-
await ctx.sl.wallet.issue({ ref: { type: 'loyalty', id: accountId }, pass: { kind: 'loyalty', title: 'Bloom Rewards', points: 120, holder: 'Sam' } })
|
|
55
|
-
await ctx.sl.wallet.update(passId, { points: 145 })
|
|
56
|
-
|
|
57
|
-
await ctx.sl.wallet.void(passId, 'refunded')
|
|
58
|
-
await ctx.sl.wallet.message(passId, { header: 'Doors open', body: 'Doors open at 7pm. See you soon!' })
|
|
59
|
-
// Everyone holding a ticket for this event
|
|
60
|
-
await ctx.sl.wallet.messageAll({ type: 'event', id: eventId }, { header: 'Running late', body: 'We start at 7:30 tonight.' })
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
- **Contact:** `contactId` defaults to the caller's contact.
|
|
64
|
-
- **Reading:** `ctx.sl.wallet.get(passId)`, `forRef(ref)`, `byCode(code)` and `mine()` need only `sl:wallet:read`.
|
|
65
|
-
- **Messages:** you can also send a message to wallet with `ctx.sl.messages` and `channel: 'wallet'`. It goes to the
|
|
66
|
-
person's passes about the message's `about`, otherwise to your app's own passes for them. It's worded from the
|
|
67
|
-
template's push version.
|
|
68
|
-
|
|
69
|
-
## Knowing who added it
|
|
70
|
-
|
|
71
|
-
Every pass belongs to a known person, so you can tell who has actually put it in their wallet:
|
|
72
|
-
|
|
73
|
-
- **Apple:** the phone registers the pass with SmartLinks when it's added, and unregisters it when it's removed.
|
|
74
|
-
- **Google:** Google sends a signed "saved" or "deleted" notice.
|
|
75
|
-
|
|
76
|
-
The pass's `inWallet` shows `{ apple: { saved, savedAt }, google: { saved, savedAt } }`. Each change raises an
|
|
77
|
-
event for the pass holder, so a flow in your app's blueprint can react, for example by sending a "see you there"
|
|
78
|
-
email when someone adds their ticket:
|
|
79
|
-
|
|
80
|
-
| Event | When |
|
|
81
|
-
|---|---|
|
|
82
|
-
| `wallet.pass_added` | the person added the pass to Apple or Google Wallet |
|
|
83
|
-
| `wallet.pass_removed` | they removed it |
|
|
84
|
-
|
|
85
|
-
Google's notices are best-effort, so treat them as a good signal rather than a guarantee.
|
|
86
|
-
|
|
87
|
-
## Checking a pass at the door
|
|
88
|
-
|
|
89
|
-
The QR holds the pass's own code, never an id. Scan it, then:
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
const { pass, valid } = await wallet.byCode(collectionId, scanned) // admin
|
|
93
|
-
// or in a function: await ctx.sl.wallet.byCode(scanned)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## What a pass can show
|
|
97
|
-
|
|
98
|
-
| Field | Use |
|
|
99
|
-
|---|---|
|
|
100
|
-
| `kind` | `event`, `booking`, `membership` or `loyalty` |
|
|
101
|
-
| `title` / `subtitle` | the main line and a second line |
|
|
102
|
-
| `start` / `end` / `timezone` | when; the pass surfaces near `start` |
|
|
103
|
-
| `venue` | `name`, `address`, and `lat` / `lng` for the lock screen nearby |
|
|
104
|
-
| `holder`, `number`, `level`, `points`, `validUntil` | the person, a reference or member number, a level, a balance, an end date |
|
|
105
|
-
| `fields` (up to 4), `back` | extra lines on the front and the back |
|
|
106
|
-
| `image`, `url` | https only: a picture, a link back to your site |
|
|
107
|
-
| `barcode` | your own QR value, instead of the pass's code |
|
|
1
|
+
# Wallet passes
|
|
2
|
+
|
|
3
|
+
Put an **event ticket**, a **booking**, a **membership card** or a **loyalty card** in the person's Apple Wallet or
|
|
4
|
+
Google Wallet. SmartLinks is the issuer and signs the passes. Each pass is branded from your site's name, logo and
|
|
5
|
+
colour, and your app decides what it says.
|
|
6
|
+
|
|
7
|
+
- **Who gets one:** only someone the business knows. A pass is issued to the signed-in owner of what it's for, or
|
|
8
|
+
by your app's own server function.
|
|
9
|
+
- **What the phone does:** the pass shows its QR code offline, appears near the time (and place, if you give
|
|
10
|
+
`venue.lat` / `lng`), and updates when you change it.
|
|
11
|
+
- **Bookings look after themselves:** when a booking is moved its pass shows the new time, and when it's cancelled
|
|
12
|
+
the pass is voided.
|
|
13
|
+
|
|
14
|
+
## In a page: "Add to Wallet"
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { wallet } from '@proveanything/smartlinks'
|
|
18
|
+
|
|
19
|
+
// The signed-in person's booking, membership card, or a pass your app issued them
|
|
20
|
+
const { pass } = await wallet.addLinks(collectionId, { type: 'booking', id: booking.id })
|
|
21
|
+
// pass.links.apple → opens the .pkpass on an iPhone
|
|
22
|
+
// pass.links.google → opens Google's "Save to Google Wallet" page
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- `{ type: 'booking', id }` and `{ type: 'contact', id: 'me' }` are made on first ask:
|
|
26
|
+
- a booking pass, from the booking's date and time
|
|
27
|
+
- a membership card, from the person's `level` and `memberUntil` fields
|
|
28
|
+
- For anything else (an event ticket with your own title, a loyalty card with points), issue the pass in your server
|
|
29
|
+
function first. `addLinks` then returns that pass for its owner.
|
|
30
|
+
- Show the official "Add to Apple Wallet" and "Add to Google Wallet" badges, and only the one that suits the
|
|
31
|
+
device. A wallet that isn't set up yet is left out of `links`.
|
|
32
|
+
- `wallet.mine(collectionId)` lists the person's passes: `{ items, nextCursor: null }`.
|
|
33
|
+
|
|
34
|
+
## In a server function: issue, change, void, message
|
|
35
|
+
|
|
36
|
+
Declare `sl:wallet:write` in the function's capabilities.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// An event ticket
|
|
40
|
+
const pass = await ctx.sl.wallet.issue({
|
|
41
|
+
ref: { type: 'booking', id: booking.id }, // what it's for; issuing again changes the same pass
|
|
42
|
+
pass: {
|
|
43
|
+
kind: 'event',
|
|
44
|
+
title: 'Jazz on the Terrace',
|
|
45
|
+
start: '2026-12-24T19:00:00Z', end: '2026-12-24T22:00:00Z', timezone: 'Europe/London',
|
|
46
|
+
venue: { name: 'The Terrace', address: '1 High St, Bath', lat: 51.38, lng: -2.36 },
|
|
47
|
+
holder: 'Sam Lee', number: 'T-0042',
|
|
48
|
+
fields: [{ label: 'Seat', value: 'Table 6' }],
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
return { links: pass.links } // hand these to the page
|
|
52
|
+
|
|
53
|
+
// A loyalty card, kept up to date
|
|
54
|
+
await ctx.sl.wallet.issue({ ref: { type: 'loyalty', id: accountId }, pass: { kind: 'loyalty', title: 'Bloom Rewards', points: 120, holder: 'Sam' } })
|
|
55
|
+
await ctx.sl.wallet.update(passId, { points: 145 })
|
|
56
|
+
|
|
57
|
+
await ctx.sl.wallet.void(passId, 'refunded')
|
|
58
|
+
await ctx.sl.wallet.message(passId, { header: 'Doors open', body: 'Doors open at 7pm. See you soon!' })
|
|
59
|
+
// Everyone holding a ticket for this event
|
|
60
|
+
await ctx.sl.wallet.messageAll({ type: 'event', id: eventId }, { header: 'Running late', body: 'We start at 7:30 tonight.' })
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- **Contact:** `contactId` defaults to the caller's contact.
|
|
64
|
+
- **Reading:** `ctx.sl.wallet.get(passId)`, `forRef(ref)`, `byCode(code)` and `mine()` need only `sl:wallet:read`.
|
|
65
|
+
- **Messages:** you can also send a message to wallet with `ctx.sl.messages` and `channel: 'wallet'`. It goes to the
|
|
66
|
+
person's passes about the message's `about`, otherwise to your app's own passes for them. It's worded from the
|
|
67
|
+
template's push version.
|
|
68
|
+
|
|
69
|
+
## Knowing who added it
|
|
70
|
+
|
|
71
|
+
Every pass belongs to a known person, so you can tell who has actually put it in their wallet:
|
|
72
|
+
|
|
73
|
+
- **Apple:** the phone registers the pass with SmartLinks when it's added, and unregisters it when it's removed.
|
|
74
|
+
- **Google:** Google sends a signed "saved" or "deleted" notice.
|
|
75
|
+
|
|
76
|
+
The pass's `inWallet` shows `{ apple: { saved, savedAt }, google: { saved, savedAt } }`. Each change raises an
|
|
77
|
+
event for the pass holder, so a flow in your app's blueprint can react, for example by sending a "see you there"
|
|
78
|
+
email when someone adds their ticket:
|
|
79
|
+
|
|
80
|
+
| Event | When |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `wallet.pass_added` | the person added the pass to Apple or Google Wallet |
|
|
83
|
+
| `wallet.pass_removed` | they removed it |
|
|
84
|
+
|
|
85
|
+
Google's notices are best-effort, so treat them as a good signal rather than a guarantee.
|
|
86
|
+
|
|
87
|
+
## Checking a pass at the door
|
|
88
|
+
|
|
89
|
+
The QR holds the pass's own code, never an id. Scan it, then:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const { pass, valid } = await wallet.byCode(collectionId, scanned) // admin
|
|
93
|
+
// or in a function: await ctx.sl.wallet.byCode(scanned)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## What a pass can show
|
|
97
|
+
|
|
98
|
+
| Field | Use |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `kind` | `event`, `booking`, `membership` or `loyalty` |
|
|
101
|
+
| `title` / `subtitle` | the main line and a second line |
|
|
102
|
+
| `start` / `end` / `timezone` | when; the pass surfaces near `start` |
|
|
103
|
+
| `venue` | `name`, `address`, and `lat` / `lng` for the lock screen nearby |
|
|
104
|
+
| `holder`, `number`, `level`, `points`, `validUntil` | the person, a reference or member number, a level, a balance, an end date |
|
|
105
|
+
| `fields` (up to 4), `back` | extra lines on the front and the back |
|
|
106
|
+
| `image`, `url` | https only: a picture, a link back to your site |
|
|
107
|
+
| `barcode` | your own QR value, instead of the pass's code |
|
package/dist/docs/websites.md
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
# Websites: server-rendered on the SmartLinks site runtime
|
|
2
|
-
|
|
3
|
-
A website built on SmartLinks is an app whose public side is a **server-rendered site** at its own
|
|
4
|
-
address: an automatic `*.smartlinks.host` name, a chosen name, or the business's own domain. Every
|
|
5
|
-
page arrives as finished HTML, so search engines, AI crawlers and link previews see the real
|
|
6
|
-
content, and visitors see it before any JavaScript runs.
|
|
7
|
-
|
|
8
|
-
## How a request is served
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
visitor / crawler / agent
|
|
12
|
-
└─► SmartLinks site router (edge)
|
|
13
|
-
├─ /robots.txt, /sitemap.xml, /llms.txt made by the platform (site-seo.md)
|
|
14
|
-
├─ a file in your build (has an extension) served from the build, cached at the edge
|
|
15
|
-
└─ anything else your site's server renders it
|
|
16
|
-
• runs in an isolated worker, close to the SmartLinks API
|
|
17
|
-
• may call the SmartLinks API and the hosts you declare, nothing else
|
|
18
|
-
• request header x-sl-site says which site it is (SL.site.fromRequest)
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
The router also adds the canonical or noindex header, the security headers, and
|
|
22
|
-
`window.__SMARTLINKS_SITE__` to every HTML page (read in the browser with `SL.site.current()` or
|
|
23
|
-
`SL.readContext()`).
|
|
24
|
-
|
|
25
|
-
## The build
|
|
26
|
-
|
|
27
|
-
The website template (TanStack Start) produces this; you don't write it by hand.
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
dist/
|
|
31
|
-
├── index.html? / assets/… the client build (hashed files: cached for a year)
|
|
32
|
-
├── sitemap-paths.txt your pages, "<path> [Title]" per line (site-seo.md)
|
|
33
|
-
├── _server/ the server bundle: one ES module entry + its chunks
|
|
34
|
-
│ └── index.mjs exports default { fetch(request, env, ctx) } (WinterTC)
|
|
35
|
-
└── app.manifest.json
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Manifest:
|
|
39
|
-
|
|
40
|
-
```jsonc
|
|
41
|
-
"site": {
|
|
42
|
-
"server": {
|
|
43
|
-
"main": "_server/index.mjs", // the server entry, inside the build
|
|
44
|
-
"compatibilityFlags": ["nodejs_compat"] // allowed: nodejs_compat, nodejs_compat_v2, nodejs_als
|
|
45
|
-
},
|
|
46
|
-
"network": ["api.example-weather.com"] // other hosts the server may call (optional)
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
On publish, the server folder becomes the site's server for that channel. Promote copies the same
|
|
51
|
-
bytes. `_server/` is never served to visitors.
|
|
52
|
-
|
|
53
|
-
## The server's rules
|
|
54
|
-
|
|
55
|
-
- **Which site:** `const site = SL.site.fromRequest(request)` gives `{ host, collectionId, appId,
|
|
56
|
-
channel, canonicalHost }`. One build serves every site it's installed on, so always take the
|
|
57
|
-
collection from here, never from a constant.
|
|
58
|
-
- **Data:** call the SmartLinks API with the SDK as you would in the browser. The server reads what
|
|
59
|
-
an anonymous visitor could read on that site, and only that collection. It holds no keys and no
|
|
60
|
-
signed-in user.
|
|
61
|
-
- **Writes** (contact forms, entries, sign-ups) go to your app's **server functions**
|
|
62
|
-
(server-functions.md), called from the browser as today. Their capabilities, secrets and limits
|
|
63
|
-
apply.
|
|
64
|
-
- **Other hosts:** only those in `site.network`. Anything else is refused (`403 Blocked`).
|
|
65
|
-
- **Limits per request:** a CPU-time budget and a cap on outgoing calls. A page that needs more is
|
|
66
|
-
doing work that belongs in a server function or a scheduled job.
|
|
67
|
-
- **No secrets** in the server bundle and no Node built-ins beyond `nodejs_compat`.
|
|
68
|
-
|
|
69
|
-
## Using another app's pages
|
|
70
|
-
|
|
71
|
-
Some apps do a job a site shouldn't rebuild: a booking journey holds the time rules, the clash
|
|
72
|
-
handling and the confirmation; "my bookings" holds who may change what. Those apps declare their pages
|
|
73
|
-
in `linkable` (app-manifest.md), each with a stable `id`, a `path` and the params it `accepts`. A site
|
|
74
|
-
embeds one with **`IframeResponder`** (iframe-responder.md), from the browser:
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
const site = SL.site.current()
|
|
78
|
-
const responder = new SL.IframeResponder({
|
|
79
|
-
collectionId: site.collectionId,
|
|
80
|
-
appId: 'appointments', // the app's id on this collection
|
|
81
|
-
initialPath: '/my-bookings', // the page's `path`
|
|
82
|
-
params: { service: 'svc_123' }, // what the page `accepts`
|
|
83
|
-
autoHeight: { minHeight: 480 }, // the iframe is as tall as the page: your page scrolls, never the iframe
|
|
84
|
-
})
|
|
85
|
-
iframe.src = await responder.attach(iframe)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
- **Size it with `autoHeight`, not by hand.** The responder sets the iframe's height from the page's own
|
|
89
|
-
height and counts the iframe's border and padding, so there's nothing left to scroll. Setting
|
|
90
|
-
`iframe.style.height` from `onResize` yourself goes wrong in a site: `onResize` also fires on every
|
|
91
|
-
window resize with "the window below the iframe" (for a full-screen host), and a bordered iframe
|
|
92
|
-
(Tailwind's border-box) ends up a few pixels short — a scrollbar inside the frame.
|
|
93
|
-
|
|
94
|
-
- **The visitor's session goes with it.** The page's API calls are proxied through the site, so it
|
|
95
|
-
acts as whoever is signed in to the site (or as a guest). Never pass a token in the URL.
|
|
96
|
-
- **The app must be installed** on the site's collection; its address comes from there.
|
|
97
|
-
- **Show the app's content natively where you can** (its `headless` data: services, staff, events)
|
|
98
|
-
for your own design and SEO, and embed the page only for the part that does the work.
|
|
99
|
-
- Pages render on the client, after load: they aren't part of the server-rendered HTML.
|
|
100
|
-
|
|
101
|
-
## Caching
|
|
102
|
-
|
|
103
|
-
The router keeps a rendered page at the edge when your response says it may:
|
|
104
|
-
|
|
105
|
-
| Your response | At the edge |
|
|
106
|
-
|---|---|
|
|
107
|
-
| `Cache-Control: public, s-maxage=300` (the template's default for pages) | kept up to 5 minutes |
|
|
108
|
-
| `private`, `no-store`, `no-cache`, or a `Set-Cookie` | never kept |
|
|
109
|
-
| no `Cache-Control` | never kept |
|
|
110
|
-
|
|
111
|
-
Cached pages are keyed by the release and the collection's **content generation**: when products,
|
|
112
|
-
public app records, app settings or the collection change, the generation moves and every page of
|
|
113
|
-
the collection's sites re-renders on its next visit (within about 30 seconds). Publishing a release
|
|
114
|
-
does the same. Tracking parameters (`utm_*`, `gclid`, `fbclid`…) don't create separate entries.
|
|
115
|
-
|
|
116
|
-
Keep pages the same for every visitor. Anything personal (a signed-in owner's products, a basket)
|
|
117
|
-
renders in the browser after load.
|
|
118
|
-
|
|
119
|
-
## Locally
|
|
120
|
-
|
|
121
|
-
`npm run dev` runs the site with your dev collection (`.env`: `VITE_SL_COLLECTION_ID`), because
|
|
122
|
-
there's no router to say which site it is: `SL.site.fromRequest()` is null, so fall back to it.
|
|
123
|
-
Forge's preview runs the same server code the site runtime does.
|
|
1
|
+
# Websites: server-rendered on the SmartLinks site runtime
|
|
2
|
+
|
|
3
|
+
A website built on SmartLinks is an app whose public side is a **server-rendered site** at its own
|
|
4
|
+
address: an automatic `*.smartlinks.host` name, a chosen name, or the business's own domain. Every
|
|
5
|
+
page arrives as finished HTML, so search engines, AI crawlers and link previews see the real
|
|
6
|
+
content, and visitors see it before any JavaScript runs.
|
|
7
|
+
|
|
8
|
+
## How a request is served
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
visitor / crawler / agent
|
|
12
|
+
└─► SmartLinks site router (edge)
|
|
13
|
+
├─ /robots.txt, /sitemap.xml, /llms.txt made by the platform (site-seo.md)
|
|
14
|
+
├─ a file in your build (has an extension) served from the build, cached at the edge
|
|
15
|
+
└─ anything else your site's server renders it
|
|
16
|
+
• runs in an isolated worker, close to the SmartLinks API
|
|
17
|
+
• may call the SmartLinks API and the hosts you declare, nothing else
|
|
18
|
+
• request header x-sl-site says which site it is (SL.site.fromRequest)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The router also adds the canonical or noindex header, the security headers, and
|
|
22
|
+
`window.__SMARTLINKS_SITE__` to every HTML page (read in the browser with `SL.site.current()` or
|
|
23
|
+
`SL.readContext()`).
|
|
24
|
+
|
|
25
|
+
## The build
|
|
26
|
+
|
|
27
|
+
The website template (TanStack Start) produces this; you don't write it by hand.
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
dist/
|
|
31
|
+
├── index.html? / assets/… the client build (hashed files: cached for a year)
|
|
32
|
+
├── sitemap-paths.txt your pages, "<path> [Title]" per line (site-seo.md)
|
|
33
|
+
├── _server/ the server bundle: one ES module entry + its chunks
|
|
34
|
+
│ └── index.mjs exports default { fetch(request, env, ctx) } (WinterTC)
|
|
35
|
+
└── app.manifest.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Manifest:
|
|
39
|
+
|
|
40
|
+
```jsonc
|
|
41
|
+
"site": {
|
|
42
|
+
"server": {
|
|
43
|
+
"main": "_server/index.mjs", // the server entry, inside the build
|
|
44
|
+
"compatibilityFlags": ["nodejs_compat"] // allowed: nodejs_compat, nodejs_compat_v2, nodejs_als
|
|
45
|
+
},
|
|
46
|
+
"network": ["api.example-weather.com"] // other hosts the server may call (optional)
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
On publish, the server folder becomes the site's server for that channel. Promote copies the same
|
|
51
|
+
bytes. `_server/` is never served to visitors.
|
|
52
|
+
|
|
53
|
+
## The server's rules
|
|
54
|
+
|
|
55
|
+
- **Which site:** `const site = SL.site.fromRequest(request)` gives `{ host, collectionId, appId,
|
|
56
|
+
channel, canonicalHost }`. One build serves every site it's installed on, so always take the
|
|
57
|
+
collection from here, never from a constant.
|
|
58
|
+
- **Data:** call the SmartLinks API with the SDK as you would in the browser. The server reads what
|
|
59
|
+
an anonymous visitor could read on that site, and only that collection. It holds no keys and no
|
|
60
|
+
signed-in user.
|
|
61
|
+
- **Writes** (contact forms, entries, sign-ups) go to your app's **server functions**
|
|
62
|
+
(server-functions.md), called from the browser as today. Their capabilities, secrets and limits
|
|
63
|
+
apply.
|
|
64
|
+
- **Other hosts:** only those in `site.network`. Anything else is refused (`403 Blocked`).
|
|
65
|
+
- **Limits per request:** a CPU-time budget and a cap on outgoing calls. A page that needs more is
|
|
66
|
+
doing work that belongs in a server function or a scheduled job.
|
|
67
|
+
- **No secrets** in the server bundle and no Node built-ins beyond `nodejs_compat`.
|
|
68
|
+
|
|
69
|
+
## Using another app's pages
|
|
70
|
+
|
|
71
|
+
Some apps do a job a site shouldn't rebuild: a booking journey holds the time rules, the clash
|
|
72
|
+
handling and the confirmation; "my bookings" holds who may change what. Those apps declare their pages
|
|
73
|
+
in `linkable` (app-manifest.md), each with a stable `id`, a `path` and the params it `accepts`. A site
|
|
74
|
+
embeds one with **`IframeResponder`** (iframe-responder.md), from the browser:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const site = SL.site.current()
|
|
78
|
+
const responder = new SL.IframeResponder({
|
|
79
|
+
collectionId: site.collectionId,
|
|
80
|
+
appId: 'appointments', // the app's id on this collection
|
|
81
|
+
initialPath: '/my-bookings', // the page's `path`
|
|
82
|
+
params: { service: 'svc_123' }, // what the page `accepts`
|
|
83
|
+
autoHeight: { minHeight: 480 }, // the iframe is as tall as the page: your page scrolls, never the iframe
|
|
84
|
+
})
|
|
85
|
+
iframe.src = await responder.attach(iframe)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- **Size it with `autoHeight`, not by hand.** The responder sets the iframe's height from the page's own
|
|
89
|
+
height and counts the iframe's border and padding, so there's nothing left to scroll. Setting
|
|
90
|
+
`iframe.style.height` from `onResize` yourself goes wrong in a site: `onResize` also fires on every
|
|
91
|
+
window resize with "the window below the iframe" (for a full-screen host), and a bordered iframe
|
|
92
|
+
(Tailwind's border-box) ends up a few pixels short — a scrollbar inside the frame.
|
|
93
|
+
|
|
94
|
+
- **The visitor's session goes with it.** The page's API calls are proxied through the site, so it
|
|
95
|
+
acts as whoever is signed in to the site (or as a guest). Never pass a token in the URL.
|
|
96
|
+
- **The app must be installed** on the site's collection; its address comes from there.
|
|
97
|
+
- **Show the app's content natively where you can** (its `headless` data: services, staff, events)
|
|
98
|
+
for your own design and SEO, and embed the page only for the part that does the work.
|
|
99
|
+
- Pages render on the client, after load: they aren't part of the server-rendered HTML.
|
|
100
|
+
|
|
101
|
+
## Caching
|
|
102
|
+
|
|
103
|
+
The router keeps a rendered page at the edge when your response says it may:
|
|
104
|
+
|
|
105
|
+
| Your response | At the edge |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `Cache-Control: public, s-maxage=300` (the template's default for pages) | kept up to 5 minutes |
|
|
108
|
+
| `private`, `no-store`, `no-cache`, or a `Set-Cookie` | never kept |
|
|
109
|
+
| no `Cache-Control` | never kept |
|
|
110
|
+
|
|
111
|
+
Cached pages are keyed by the release and the collection's **content generation**: when products,
|
|
112
|
+
public app records, app settings or the collection change, the generation moves and every page of
|
|
113
|
+
the collection's sites re-renders on its next visit (within about 30 seconds). Publishing a release
|
|
114
|
+
does the same. Tracking parameters (`utm_*`, `gclid`, `fbclid`…) don't create separate entries.
|
|
115
|
+
|
|
116
|
+
Keep pages the same for every visitor. Anything personal (a signed-in owner's products, a basket)
|
|
117
|
+
renders in the browser after load.
|
|
118
|
+
|
|
119
|
+
## Locally
|
|
120
|
+
|
|
121
|
+
`npm run dev` runs the site with your dev collection (`.env`: `VITE_SL_COLLECTION_ID`), because
|
|
122
|
+
there's no router to say which site it is: `SL.site.fromRequest()` is null, so fall back to it.
|
|
123
|
+
Forge's preview runs the same server code the site runtime does.
|
package/dist/headless.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface HeadlessValidation {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* What a type's read calls return, and where one item's declared fields live — fixed by the storage
|
|
25
|
-
* kind (see app-objects.md "Paginated List Responses"). Sites must read items from `response.
|
|
25
|
+
* kind (see app-objects.md "Paginated List Responses"). Sites must read items from `response.items`.
|
|
26
26
|
*/
|
|
27
27
|
export declare function responseShape(type: AppDataType): {
|
|
28
28
|
returns: string;
|
package/dist/headless.js
CHANGED
|
@@ -20,12 +20,12 @@ const STORAGE_KINDS = new Set(['record', 'case', 'thread', 'config']);
|
|
|
20
20
|
const SEMVER = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
21
21
|
/**
|
|
22
22
|
* What a type's read calls return, and where one item's declared fields live — fixed by the storage
|
|
23
|
-
* kind (see app-objects.md "Paginated List Responses"). Sites must read items from `response.
|
|
23
|
+
* kind (see app-objects.md "Paginated List Responses"). Sites must read items from `response.items`.
|
|
24
24
|
*/
|
|
25
25
|
export function responseShape(type) {
|
|
26
26
|
const s = type.storage;
|
|
27
27
|
const first = Object.keys(type.fields || {})[0] || 'field';
|
|
28
|
-
const paged = (name) => `list → {
|
|
28
|
+
const paged = (name) => `list → { items: ${name}[], nextCursor: string | null, count: number }. The items are in response.items (not response.data / response.records); page with limit and cursor (the previous page's nextCursor) until nextCursor is null. get → one ${name}.`;
|
|
29
29
|
switch (s && s.kind) {
|
|
30
30
|
case 'record':
|
|
31
31
|
return { returns: paged('AppRecord'), item: `Each record's declared fields are in record.data (e.g. record.data.${first}); record.id, record.productId, record.status, record.createdAt are top-level.` };
|
package/dist/http.d.ts
CHANGED
|
@@ -66,10 +66,23 @@ export declare function initializeApi(options: {
|
|
|
66
66
|
*/
|
|
67
67
|
appVersion?: string;
|
|
68
68
|
/**
|
|
69
|
-
* The API version to ask for, as year-month (for example `"
|
|
70
|
-
* release was built for (`API_VERSION`), which is what you want
|
|
69
|
+
* The API version to ask for, as year-month (for example `"2027-06"`). Defaults to the version this SDK
|
|
70
|
+
* release was built for (`API_VERSION`), which is what you want. A NEWER version can be asked for, to try
|
|
71
|
+
* it; an older one is ignored, because this SDK's functions return the shapes of its own version.
|
|
71
72
|
*/
|
|
72
73
|
apiVersion?: string;
|
|
74
|
+
/**
|
|
75
|
+
* For a HOST that has two copies of the SDK on one page (it serves SDK 3 to apps built for it, beside
|
|
76
|
+
* the SDK 2 the page itself runs on): where this copy gets its sign-in. Called for every request; return
|
|
77
|
+
* the other copy's `getApiHeaders()`. This copy then sends exactly the sign-in the host has at that
|
|
78
|
+
* moment (API key, bearer token, grant token), and forgets cached answers when it changes.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* SL3.initializeApi({ baseURL: SL.getBaseURL()!, signInFrom: () => SL.getApiHeaders() })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
signInFrom?: () => Record<string, string>;
|
|
73
86
|
/**
|
|
74
87
|
* The release channel this build is running as ('dev' | 'alpha' | 'beta' | 'stable'). Normally
|
|
75
88
|
* left unset — hosts that run a non-production build (Forge preview of a Test build) pass
|
package/dist/http.js
CHANGED
|
@@ -55,7 +55,48 @@ export function getClientHeaders() {
|
|
|
55
55
|
export function getApiVersion() {
|
|
56
56
|
return apiVersionSent;
|
|
57
57
|
}
|
|
58
|
+
// A second copy of the SDK on one page (a host that serves SDK 3 beside SDK 2) has no sign-in of its own:
|
|
59
|
+
// it asks the host's copy for the current one each time (initializeApi({ signInFrom })), so the two can
|
|
60
|
+
// never disagree about who is signed in.
|
|
61
|
+
let signInFrom = null;
|
|
62
|
+
let signInSeen = '';
|
|
63
|
+
/** The host's sign-in headers right now ({} when this copy doesn't follow a host). */
|
|
64
|
+
function hostSignIn() {
|
|
65
|
+
if (!signInFrom)
|
|
66
|
+
return {};
|
|
67
|
+
let h = {};
|
|
68
|
+
try {
|
|
69
|
+
h = Object.assign({}, (signInFrom() || {}));
|
|
70
|
+
}
|
|
71
|
+
catch (_a) {
|
|
72
|
+
h = {};
|
|
73
|
+
}
|
|
74
|
+
// Only sign-in travels across. Which API version and SDK this copy is, it says itself.
|
|
75
|
+
for (const k of Object.keys(h))
|
|
76
|
+
if (/^smartlinks-(version|sdk|app)$/i.test(k))
|
|
77
|
+
delete h[k];
|
|
78
|
+
// A different person (or none) since the last look: what was cached for the last one must go.
|
|
79
|
+
const seen = JSON.stringify(Object.keys(h).sort().map((k) => [k.toLowerCase(), h[k]]));
|
|
80
|
+
if (seen !== signInSeen) {
|
|
81
|
+
const first = signInSeen === '';
|
|
82
|
+
signInSeen = seen;
|
|
83
|
+
if (!first) {
|
|
84
|
+
clearHttpCache('host sign-in changed');
|
|
85
|
+
if (cachePersistence !== 'none')
|
|
86
|
+
idbClear().catch(() => { });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return h;
|
|
90
|
+
}
|
|
58
91
|
function addClientHeaders(headers) {
|
|
92
|
+
// The host's sign-in replaces whatever this copy holds (it holds none of its own).
|
|
93
|
+
const host = hostSignIn();
|
|
94
|
+
for (const [k, v] of Object.entries(host)) {
|
|
95
|
+
for (const mine of Object.keys(headers))
|
|
96
|
+
if (mine.toLowerCase() === k.toLowerCase())
|
|
97
|
+
delete headers[mine];
|
|
98
|
+
headers[k] = v;
|
|
99
|
+
}
|
|
59
100
|
const lower = new Set(Object.keys(headers).map((k) => k.toLowerCase()));
|
|
60
101
|
for (const [k, v] of Object.entries(getClientHeaders()))
|
|
61
102
|
if (!lower.has(k.toLowerCase()))
|
|
@@ -608,8 +649,11 @@ export function initializeApi(options) {
|
|
|
608
649
|
? !!options.ngrokSkipBrowserWarning
|
|
609
650
|
: inferredNgrok;
|
|
610
651
|
extraHeadersGlobal = options.extraHeaders ? Object.assign({}, options.extraHeaders) : {};
|
|
611
|
-
|
|
652
|
+
// Year-month sorts as text, so "newer" is a plain comparison.
|
|
653
|
+
apiVersionSent = options.apiVersion && /^\d{4}-(0[1-9]|1[0-2])$/.test(options.apiVersion) && options.apiVersion >= API_VERSION ? options.apiVersion : API_VERSION;
|
|
612
654
|
clientAppVersion = options.appVersion ? String(options.appVersion).slice(0, 30) : null;
|
|
655
|
+
signInFrom = typeof options.signInFrom === 'function' ? options.signInFrom : null;
|
|
656
|
+
signInSeen = '';
|
|
613
657
|
// Platform opt-in (native refresh tokens). Preserve an earlier value when a
|
|
614
658
|
// re-init call omits it, so long-lived native sessions aren't downgraded by a
|
|
615
659
|
// later bootstrap that forgot to pass platform.
|
|
@@ -713,7 +757,13 @@ export function getGrantToken() {
|
|
|
713
757
|
* so this returns `undefined` even when the caller is authenticated.
|
|
714
758
|
*/
|
|
715
759
|
export function getBearerToken() {
|
|
716
|
-
|
|
760
|
+
if (bearerToken || !signInFrom)
|
|
761
|
+
return bearerToken;
|
|
762
|
+
// Following a host: the token is the host's.
|
|
763
|
+
const host = hostSignIn();
|
|
764
|
+
const key = Object.keys(host).find((k) => k.toLowerCase() === 'authorization');
|
|
765
|
+
const m = key ? /^Bearer\s+(.+)$/i.exec(host[key]) : null;
|
|
766
|
+
return m ? m[1] : undefined;
|
|
717
767
|
}
|
|
718
768
|
/**
|
|
719
769
|
* Get the currently configured API base URL.
|
|
@@ -1338,6 +1388,7 @@ export async function proxyUploadFormData(path, formData, onProgress) {
|
|
|
1338
1388
|
*/
|
|
1339
1389
|
export async function request(path) {
|
|
1340
1390
|
await ensureAuthReady();
|
|
1391
|
+
hostSignIn(); // before the cache is read: a change of sign-in on the host empties it
|
|
1341
1392
|
const skipCache = shouldSkipCache(path);
|
|
1342
1393
|
const cacheKey = buildCacheKey(path);
|
|
1343
1394
|
const ttl = skipCache ? 0 : getTtlForPath(path);
|
|
@@ -1877,6 +1928,13 @@ export function getApiHeaders() {
|
|
|
1877
1928
|
for (const [k, v] of Object.entries(extraHeadersGlobal))
|
|
1878
1929
|
if (!(k in headers))
|
|
1879
1930
|
headers[k] = v;
|
|
1931
|
+
// A copy that follows a host's sign-in passes that on.
|
|
1932
|
+
for (const [k, v] of Object.entries(hostSignIn())) {
|
|
1933
|
+
for (const mine of Object.keys(headers))
|
|
1934
|
+
if (mine.toLowerCase() === k.toLowerCase())
|
|
1935
|
+
delete headers[mine];
|
|
1936
|
+
headers[k] = v;
|
|
1937
|
+
}
|
|
1880
1938
|
return headers;
|
|
1881
1939
|
}
|
|
1882
1940
|
/**
|