@proveanything/smartlinks 2.0.0-alpha.1 → 2.0.0-alpha.3
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/dist/docs/API_SUMMARY.md +2 -1
- package/dist/docs/deploying-apps.md +86 -35
- package/dist/docs/sequences.md +91 -0
- package/docs/API_SUMMARY.md +2 -1
- package/docs/deploying-apps.md +86 -35
- package/docs/sequences.md +91 -0
- package/package.json +1 -1
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.0.0-alpha.
|
|
3
|
+
Version: 2.0.0-alpha.3 | Generated: 2026-09-14T14:38:59.597Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -54,6 +54,7 @@ For detailed guides on specific features:
|
|
|
54
54
|
- **[Forms](forms.md)** - Platform-managed form definitions, submissions, and schema-driven React form UI
|
|
55
55
|
- **[App Objects: Cases, Threads & Records](app-objects.md)** - Generic app-scoped building blocks for support cases, discussions, bookings, registrations, and more
|
|
56
56
|
- **[App Records Pattern](app-records-pattern.md)** - Canonical pattern for storing per-product, per-facet, or rule-targeted app data
|
|
57
|
+
- **[Sequences & Claim-Order](sequences.md)** - Allocate a guaranteed-unique, monotonic number (raffle tickets, "Nth to claim", queue positions) and stamp it onto a record — atomic app-config counter + idempotent per-subject stamping, concurrency-safe at stadium scale
|
|
57
58
|
- **[Communications](comms.md)** - Transactional sends, multi-channel broadcasts, consent management, push registration, and analytics
|
|
58
59
|
- **[Interactions & Event Tracking](interactions.md)** - Log user events, count outcomes, query history, and define interaction types with permissions
|
|
59
60
|
- **[Analytics](analytics.md)** - Web analytics, link-click tracking, QR/tag scan telemetry, and event reporting
|
|
@@ -20,20 +20,30 @@ This guide covers registration and how to wire it into your build.
|
|
|
20
20
|
|
|
21
21
|
Deploying touches two different locations — keep them distinct:
|
|
22
22
|
|
|
23
|
-
1. **The install endpoint (API host)** — *where you register*.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
1. **The install endpoint (API host)** — *where you register*. On the **main SaaS this is
|
|
24
|
+
`https://smartlinks.app`** (the API lives under `/api/v1` — the same base your app already
|
|
25
|
+
passes to `initializeApi`). A client's isolated (VPC) environment has its **own** host; you
|
|
26
|
+
install into it by calling that host. This is the value that varies per deployment.
|
|
27
|
+
2. **The bundle CDN** — *where your built files are actually served from*, which you pass at
|
|
28
|
+
registration as **`bundleBaseUrl`**. **This depends on the channel:**
|
|
29
|
+
- **`dev` (Lovable):** your files are served by **Lovable at your published app URL** — that
|
|
30
|
+
URL is your dev `bundleBaseUrl`. Lovable *is* the CDN for dev; nothing is uploaded to
|
|
31
|
+
SmartLinks.
|
|
32
|
+
- **`prod`:** files are published to the SmartLinks app CDN at
|
|
33
|
+
`https://smartlinks.app/apps/{appId}/{version}/…` by your prod deploy step; that base is
|
|
34
|
+
your prod `bundleBaseUrl`.
|
|
27
35
|
|
|
28
36
|
```
|
|
29
|
-
https://smartlinks.app/apps/{appId}/{version}/app.manifest.json
|
|
30
|
-
https://smartlinks.app/apps/{appId}/{version}/widgets-<hash>.umd.js
|
|
37
|
+
https://smartlinks.app/apps/{appId}/{version}/app.manifest.json # prod layout
|
|
31
38
|
https://smartlinks.app/apps/{appId}/{version}/functions.umd.js
|
|
32
39
|
```
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
Always pass `bundleBaseUrl` explicitly so it keeps working if a location changes.
|
|
42
|
+
|
|
43
|
+
> **Who publishes the bundles?** The platform does **not** fetch or mirror them for you —
|
|
44
|
+
> `bundleBaseUrl` must already serve the files at registration time. For `dev` that's Lovable
|
|
45
|
+
> (on Publish); for `prod` that's your own CDN deploy step. Registration records *where* the
|
|
46
|
+
> bundles are + the validated manifest; it does not host anything.
|
|
37
47
|
|
|
38
48
|
## Environments & the app registry
|
|
39
49
|
|
|
@@ -72,26 +82,36 @@ and exercise a build before it reaches `prod`.
|
|
|
72
82
|
|
|
73
83
|
## Deploy keys
|
|
74
84
|
|
|
75
|
-
Registration is authenticated by a **deploy key** — not a user login — scoped to the
|
|
76
|
-
|
|
77
|
-
what it was allowed to touch.
|
|
85
|
+
Registration is authenticated by a **deploy key** — not a user login — scoped to the channels
|
|
86
|
+
it may write. Security comes from the *scope*: a leaked key can only do what its scope allows.
|
|
78
87
|
|
|
79
|
-
| Key |
|
|
80
|
-
|
|
81
|
-
| **Dev key** |
|
|
82
|
-
| **Prod master key** | your Cloud Build
|
|
83
|
-
| **Per-app key** *(future)* |
|
|
88
|
+
| Key | Where to keep it | May write | If it leaks |
|
|
89
|
+
|---|---|---|---|
|
|
90
|
+
| **Dev key** | a **Lovable workspace Build Secret** (below) | `dev` channel, **any app in the environment** | someone can register/overwrite `dev` releases — which are served only to test collections — but **never** `beta`/`prod` |
|
|
91
|
+
| **Prod master key** | your CI/Cloud Build secret store **only** | all channels | full control — so keep it out of app source entirely |
|
|
92
|
+
| **Per-app key** *(future)* | provisioned per app | one specific app | scoped to that one app |
|
|
93
|
+
|
|
94
|
+
**Keep the dev key in Lovable Build Secrets — do not commit it.** Lovable exposes
|
|
95
|
+
**workspace-level Build Secrets** shared across every project in the workspace: set the dev key
|
|
96
|
+
there **once** and every microapp inherits it, nothing is committed, and there's a single value
|
|
97
|
+
to rotate. (An earlier draft of this guide said to put the key in app source — don't; use Build
|
|
98
|
+
Secrets.)
|
|
84
99
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
**Minting (current state, 2.0.0-alpha):** the `dev` and `prod` keys are **shared secrets
|
|
101
|
+
configured on the SmartLinks backend** — one `dev` key and one `prod` key covering all
|
|
102
|
+
first-party apps. There is **no self-service minting UI yet**: ask the platform owner for the
|
|
103
|
+
`dev` key and put it in your workspace Build Secret. Per-app keys, self-service minting, and
|
|
104
|
+
rotation are planned; rotating the shared `dev` key just means updating the one Build Secret
|
|
105
|
+
(registered releases are unaffected — the key authorizes *writes*, it isn't stored on releases).
|
|
106
|
+
|
|
107
|
+
Present the key in the `x-smartlinks-deploy-key` header.
|
|
88
108
|
|
|
89
109
|
---
|
|
90
110
|
|
|
91
111
|
## The registration endpoint
|
|
92
112
|
|
|
93
113
|
```
|
|
94
|
-
POST https
|
|
114
|
+
POST https://smartlinks.app/api/v1/apps/{appId}/releases # main SaaS; a VPC env uses its own host
|
|
95
115
|
x-smartlinks-deploy-key: <your deploy key>
|
|
96
116
|
Content-Type: application/json
|
|
97
117
|
```
|
|
@@ -124,6 +144,15 @@ Each validation error is `{ code, message, path }`, e.g.:
|
|
|
124
144
|
]}
|
|
125
145
|
```
|
|
126
146
|
|
|
147
|
+
### Re-registering & version collisions
|
|
148
|
+
|
|
149
|
+
Registration is an **upsert keyed by (app, channel)** — the newest registration becomes that
|
|
150
|
+
channel's live release. Registering again **overwrites** it (last write wins); there is **no**
|
|
151
|
+
version-collision error even if `meta.version` is unchanged. So re-publishing to `dev` without
|
|
152
|
+
bumping the version is a normal, intentional overwrite — which is what you want on `dev`. (A
|
|
153
|
+
stricter `prod` policy that rejects a duplicate `version` may come later; it isn't enforced
|
|
154
|
+
today.)
|
|
155
|
+
|
|
127
156
|
### What gets validated
|
|
128
157
|
|
|
129
158
|
- `manifest.meta.appId` must match the `{appId}` in the URL.
|
|
@@ -145,24 +174,36 @@ so a bad install fails the publish.
|
|
|
145
174
|
import { readFileSync } from 'node:fs'
|
|
146
175
|
import { execSync } from 'node:child_process'
|
|
147
176
|
|
|
148
|
-
const API
|
|
149
|
-
const KEY
|
|
150
|
-
const CHANNEL
|
|
177
|
+
const API = process.env.SMARTLINKS_API || 'https://smartlinks.app' // a VPC env: set to its host
|
|
178
|
+
const KEY = process.env.SMARTLINKS_DEPLOY_KEY // Lovable Build Secret (dev) / CI secret (prod)
|
|
179
|
+
const CHANNEL = process.env.SMARTLINKS_CHANNEL // 'dev' | 'beta' | 'prod'; UNSET ⇒ don't register
|
|
180
|
+
|
|
181
|
+
// --- Gate: only register when this build is meant to ---
|
|
182
|
+
// A preview / live-edit build (no channel) skips quietly so it never fails. A build that
|
|
183
|
+
// declares a channel but has no key is a hard error IF it's prod; dev skips quietly.
|
|
184
|
+
if (!CHANNEL) {
|
|
185
|
+
console.log('ℹ︎ SmartLinks: SMARTLINKS_CHANNEL unset — skipping release registration (preview build).')
|
|
186
|
+
process.exit(0)
|
|
187
|
+
}
|
|
188
|
+
if (!KEY) {
|
|
189
|
+
if (CHANNEL === 'prod') { console.error('❌ prod build but SMARTLINKS_DEPLOY_KEY is missing'); process.exit(1) }
|
|
190
|
+
console.log(`ℹ︎ SmartLinks: no deploy key for "${CHANNEL}" — skipping registration.`)
|
|
191
|
+
process.exit(0)
|
|
192
|
+
}
|
|
151
193
|
|
|
152
194
|
const manifest = JSON.parse(readFileSync('dist/app.manifest.json', 'utf8'))
|
|
153
195
|
const appId = manifest.meta.appId
|
|
154
196
|
const version = manifest.meta.version
|
|
155
197
|
const gitHash = (() => { try { return execSync('git rev-parse --short HEAD').toString().trim() } catch { return null } })()
|
|
198
|
+
// dev: your published Lovable URL; prod: the SmartLinks CDN base. Set SMARTLINKS_BUNDLE_BASE_URL.
|
|
199
|
+
const bundleBaseUrl = process.env.SMARTLINKS_BUNDLE_BASE_URL || `https://smartlinks.app/apps/${appId}/${version}`
|
|
156
200
|
|
|
157
201
|
const res = await fetch(`${API}/api/v1/apps/${appId}/releases`, {
|
|
158
202
|
method: 'POST',
|
|
159
203
|
headers: { 'content-type': 'application/json', 'x-smartlinks-deploy-key': KEY },
|
|
160
204
|
body: JSON.stringify({
|
|
161
|
-
channel: CHANNEL,
|
|
162
|
-
|
|
163
|
-
build: { at: new Date().toISOString(), gitHash, builder: CHANNEL === 'dev' ? 'lovable' : 'cloudbuild' },
|
|
164
|
-
manifest,
|
|
165
|
-
bundleBaseUrl: `https://smartlinks.app/apps/${appId}/${version}`,
|
|
205
|
+
channel: CHANNEL, version, manifest, bundleBaseUrl,
|
|
206
|
+
build: { at: new Date().toISOString(), gitHash, builder: CHANNEL === 'dev' ? 'lovable' : 'ci' },
|
|
166
207
|
}),
|
|
167
208
|
})
|
|
168
209
|
|
|
@@ -175,7 +216,7 @@ if (!res.ok || !body.ok) {
|
|
|
175
216
|
console.log(`✅ Registered ${appId}@${version} on "${CHANNEL}" — functions: ${(body.functions || []).join(', ') || 'none'}`)
|
|
176
217
|
```
|
|
177
218
|
|
|
178
|
-
Wire it after your bundle build/hash step
|
|
219
|
+
Wire it after your bundle build/hash step:
|
|
179
220
|
|
|
180
221
|
```jsonc
|
|
181
222
|
// package.json
|
|
@@ -185,9 +226,19 @@ Wire it after your bundle build/hash step, e.g.:
|
|
|
185
226
|
}
|
|
186
227
|
```
|
|
187
228
|
|
|
188
|
-
|
|
189
|
-
`SMARTLINKS_CHANNEL=dev`.
|
|
190
|
-
- **Prod (Cloud Build)** runs the same with the **prod key** and `SMARTLINKS_CHANNEL=prod`.
|
|
229
|
+
Registration is gated by **`SMARTLINKS_CHANNEL`**, so the three Lovable build types behave correctly:
|
|
191
230
|
|
|
192
|
-
|
|
193
|
-
|
|
231
|
+
| Build | `SMARTLINKS_CHANNEL` | Result |
|
|
232
|
+
|---|---|---|
|
|
233
|
+
| **Preview / live-edit** | unset | **skips quietly** — never registers, never fails |
|
|
234
|
+
| **Dev (Publish)** | `dev` | registers to `dev` with the workspace Build-Secret key + your Lovable `SMARTLINKS_BUNDLE_BASE_URL` |
|
|
235
|
+
| **Prod (CI)** | `prod` | registers to `prod` with the prod key; a missing key **hard-fails** |
|
|
236
|
+
|
|
237
|
+
The gate is `SMARTLINKS_CHANNEL`, so **set it only where you want a release** — i.e. on the
|
|
238
|
+
Publish/CI build, not on preview. If your host exposes a publish-only signal (an env var it sets
|
|
239
|
+
only on Publish), key `SMARTLINKS_CHANNEL` off that; otherwise set it in the Publish build's env
|
|
240
|
+
and leave it unset for preview. That one variable is the difference between "this build ships a
|
|
241
|
+
release" and "this build is just a preview."
|
|
242
|
+
|
|
243
|
+
That's it: a real Publish validates + registers your app (a broken manifest or function stops
|
|
244
|
+
the deploy with an actionable error), while preview builds stay quiet.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Sequences & claim-order allocation
|
|
2
|
+
|
|
3
|
+
> **Preview — SmartLinks SDK 2.0.0-alpha.** APIs may change before 2.0.0 stable.
|
|
4
|
+
|
|
5
|
+
A **sequence** hands out a guaranteed-unique, monotonic number — `1, 2, 3, …` — and stamps it
|
|
6
|
+
onto a record. It's the primitive behind raffle tickets, "you're the Nth to claim", queue
|
|
7
|
+
positions, and limited-edition numbering: cases where you need *the next number*, exactly
|
|
8
|
+
once per subject, even with a whole room (or stadium) acting at the same instant.
|
|
9
|
+
|
|
10
|
+
## The model: allocate, then stamp — and the target is the ledger
|
|
11
|
+
|
|
12
|
+
Two steps, one call:
|
|
13
|
+
|
|
14
|
+
1. **Allocate** — get the next number from an **atomic counter**. The counter lives inside
|
|
15
|
+
your **app-config** doc at `data.sequences.<key>`, so it's scoped exactly like your other
|
|
16
|
+
app config (per collection / product / variant / batch) and needs no dedicated storage.
|
|
17
|
+
It's incremented in a single statement, so 250 simultaneous taps each get a distinct
|
|
18
|
+
number in microseconds — never two the same.
|
|
19
|
+
2. **Stamp** — write that number onto the **subject's own record** (a claim set, a proof, or
|
|
20
|
+
an app record). **That record is the ledger** — there's no separate bookkeeping table.
|
|
21
|
+
Next time you read the subject, the number is just there.
|
|
22
|
+
|
|
23
|
+
Because the target is the ledger, allocation is **idempotent**: on a re-tap we read the
|
|
24
|
+
subject first and return the number it already has, rather than allocating a second one.
|
|
25
|
+
|
|
26
|
+
## Guarantees
|
|
27
|
+
|
|
28
|
+
- **Unique + monotonic** — the counter is an atomic increment, never a read-modify-write, so
|
|
29
|
+
there are no duplicates and no lost updates under load.
|
|
30
|
+
- **Idempotent per subject** — one number per subject; a re-tap returns the same number.
|
|
31
|
+
- **Concurrency-safe at scale** — the only shared hot spot is the one counter row (Postgres
|
|
32
|
+
serializes it); the stamp is per-subject (its own record), so the model holds from 250 in a
|
|
33
|
+
room to 60,000 in a stadium. A concurrent double-tap on the *same* subject at worst skips
|
|
34
|
+
one number (a harmless gap) — never puts two numbers on one person.
|
|
35
|
+
|
|
36
|
+
## Scoping
|
|
37
|
+
|
|
38
|
+
- **Counter scope** — the app-config doc it lives on: collection-wide, or per product /
|
|
39
|
+
variant / batch. All wristbands mapped to one product? Scope the counter to that product.
|
|
40
|
+
- **`key`** — a name within that doc (e.g. `raffle:2026-cup`), so one config doc can hold
|
|
41
|
+
several independent sequences.
|
|
42
|
+
- **`start`** — the first number (default `1`); use it to reserve a block (start at `51` and
|
|
43
|
+
tell people it's `1`, or just filter `< N` at draw time).
|
|
44
|
+
|
|
45
|
+
## Idempotency subject — use a *stable* id
|
|
46
|
+
|
|
47
|
+
The number is deduped by the **subject id** you pass, so it must be the **stable** identity:
|
|
48
|
+
- **Claim set id** (the wristband's permanent record) — the right key when people aren't
|
|
49
|
+
logged in. A re-tap resolves to the same claim set → same number.
|
|
50
|
+
- The authenticated **user/contact** — if they sign in / claim.
|
|
51
|
+
|
|
52
|
+
Do **not** key on a value that changes per interaction (e.g. a virtual proof id minted fresh
|
|
53
|
+
on each tap) — that would let one person take several numbers.
|
|
54
|
+
|
|
55
|
+
## Where the number is stored (the sink)
|
|
56
|
+
|
|
57
|
+
The stamp target is configurable — the number lives wherever you'll read it:
|
|
58
|
+
|
|
59
|
+
| Target | Use |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `claimSet` | The Firestore wristband record — fast, no proof mint on the hot path. |
|
|
62
|
+
| `proof` | A minted proof (value or attestation) — when the number should travel with the proof. |
|
|
63
|
+
| `appRecord` | A structured app record — for queryable, per-app data. |
|
|
64
|
+
|
|
65
|
+
## Worked example — a free raffle on NFC wristbands
|
|
66
|
+
|
|
67
|
+
Everyone taps a wristband and hits **Enter the raffle**. Each tap allocates the next number
|
|
68
|
+
and writes it onto that wristband's claim set — fast, unique, no proof mint:
|
|
69
|
+
|
|
70
|
+
```jsonc
|
|
71
|
+
// allocate-and-stamp (conceptual shape)
|
|
72
|
+
{
|
|
73
|
+
"appId": "raffle-app",
|
|
74
|
+
"productId": "wristbands-2026", // the counter's scope
|
|
75
|
+
"key": "raffle:2026-cup", // the named sequence
|
|
76
|
+
"start": 1,
|
|
77
|
+
"subjectId": "<claim set id>", // STABLE identity — re-taps collapse to one number
|
|
78
|
+
"target": "claimSet",
|
|
79
|
+
"field": "raffleNumber"
|
|
80
|
+
}
|
|
81
|
+
// → { "number": 42, "isNew": true } (re-tap → { "number": 42, "isNew": false })
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Drawing the winner needs no separate ledger either — query the claim sets (or proofs) where
|
|
85
|
+
`raffleNumber` is set; that field is your entry list, in allocation order.
|
|
86
|
+
|
|
87
|
+
## Status
|
|
88
|
+
|
|
89
|
+
The allocator + stamping run server-side today. The **public "enter" action** an app widget
|
|
90
|
+
calls on tap (and its SDK wrapper) is being wired in the 2.0.0-alpha line — this doc is the
|
|
91
|
+
contract it will expose.
|
package/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.0.0-alpha.
|
|
3
|
+
Version: 2.0.0-alpha.3 | Generated: 2026-09-14T14:38:59.597Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -54,6 +54,7 @@ For detailed guides on specific features:
|
|
|
54
54
|
- **[Forms](forms.md)** - Platform-managed form definitions, submissions, and schema-driven React form UI
|
|
55
55
|
- **[App Objects: Cases, Threads & Records](app-objects.md)** - Generic app-scoped building blocks for support cases, discussions, bookings, registrations, and more
|
|
56
56
|
- **[App Records Pattern](app-records-pattern.md)** - Canonical pattern for storing per-product, per-facet, or rule-targeted app data
|
|
57
|
+
- **[Sequences & Claim-Order](sequences.md)** - Allocate a guaranteed-unique, monotonic number (raffle tickets, "Nth to claim", queue positions) and stamp it onto a record — atomic app-config counter + idempotent per-subject stamping, concurrency-safe at stadium scale
|
|
57
58
|
- **[Communications](comms.md)** - Transactional sends, multi-channel broadcasts, consent management, push registration, and analytics
|
|
58
59
|
- **[Interactions & Event Tracking](interactions.md)** - Log user events, count outcomes, query history, and define interaction types with permissions
|
|
59
60
|
- **[Analytics](analytics.md)** - Web analytics, link-click tracking, QR/tag scan telemetry, and event reporting
|
package/docs/deploying-apps.md
CHANGED
|
@@ -20,20 +20,30 @@ This guide covers registration and how to wire it into your build.
|
|
|
20
20
|
|
|
21
21
|
Deploying touches two different locations — keep them distinct:
|
|
22
22
|
|
|
23
|
-
1. **The install endpoint (API host)** — *where you register*.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
1. **The install endpoint (API host)** — *where you register*. On the **main SaaS this is
|
|
24
|
+
`https://smartlinks.app`** (the API lives under `/api/v1` — the same base your app already
|
|
25
|
+
passes to `initializeApi`). A client's isolated (VPC) environment has its **own** host; you
|
|
26
|
+
install into it by calling that host. This is the value that varies per deployment.
|
|
27
|
+
2. **The bundle CDN** — *where your built files are actually served from*, which you pass at
|
|
28
|
+
registration as **`bundleBaseUrl`**. **This depends on the channel:**
|
|
29
|
+
- **`dev` (Lovable):** your files are served by **Lovable at your published app URL** — that
|
|
30
|
+
URL is your dev `bundleBaseUrl`. Lovable *is* the CDN for dev; nothing is uploaded to
|
|
31
|
+
SmartLinks.
|
|
32
|
+
- **`prod`:** files are published to the SmartLinks app CDN at
|
|
33
|
+
`https://smartlinks.app/apps/{appId}/{version}/…` by your prod deploy step; that base is
|
|
34
|
+
your prod `bundleBaseUrl`.
|
|
27
35
|
|
|
28
36
|
```
|
|
29
|
-
https://smartlinks.app/apps/{appId}/{version}/app.manifest.json
|
|
30
|
-
https://smartlinks.app/apps/{appId}/{version}/widgets-<hash>.umd.js
|
|
37
|
+
https://smartlinks.app/apps/{appId}/{version}/app.manifest.json # prod layout
|
|
31
38
|
https://smartlinks.app/apps/{appId}/{version}/functions.umd.js
|
|
32
39
|
```
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
Always pass `bundleBaseUrl` explicitly so it keeps working if a location changes.
|
|
42
|
+
|
|
43
|
+
> **Who publishes the bundles?** The platform does **not** fetch or mirror them for you —
|
|
44
|
+
> `bundleBaseUrl` must already serve the files at registration time. For `dev` that's Lovable
|
|
45
|
+
> (on Publish); for `prod` that's your own CDN deploy step. Registration records *where* the
|
|
46
|
+
> bundles are + the validated manifest; it does not host anything.
|
|
37
47
|
|
|
38
48
|
## Environments & the app registry
|
|
39
49
|
|
|
@@ -72,26 +82,36 @@ and exercise a build before it reaches `prod`.
|
|
|
72
82
|
|
|
73
83
|
## Deploy keys
|
|
74
84
|
|
|
75
|
-
Registration is authenticated by a **deploy key** — not a user login — scoped to the
|
|
76
|
-
|
|
77
|
-
what it was allowed to touch.
|
|
85
|
+
Registration is authenticated by a **deploy key** — not a user login — scoped to the channels
|
|
86
|
+
it may write. Security comes from the *scope*: a leaked key can only do what its scope allows.
|
|
78
87
|
|
|
79
|
-
| Key |
|
|
80
|
-
|
|
81
|
-
| **Dev key** |
|
|
82
|
-
| **Prod master key** | your Cloud Build
|
|
83
|
-
| **Per-app key** *(future)* |
|
|
88
|
+
| Key | Where to keep it | May write | If it leaks |
|
|
89
|
+
|---|---|---|---|
|
|
90
|
+
| **Dev key** | a **Lovable workspace Build Secret** (below) | `dev` channel, **any app in the environment** | someone can register/overwrite `dev` releases — which are served only to test collections — but **never** `beta`/`prod` |
|
|
91
|
+
| **Prod master key** | your CI/Cloud Build secret store **only** | all channels | full control — so keep it out of app source entirely |
|
|
92
|
+
| **Per-app key** *(future)* | provisioned per app | one specific app | scoped to that one app |
|
|
93
|
+
|
|
94
|
+
**Keep the dev key in Lovable Build Secrets — do not commit it.** Lovable exposes
|
|
95
|
+
**workspace-level Build Secrets** shared across every project in the workspace: set the dev key
|
|
96
|
+
there **once** and every microapp inherits it, nothing is committed, and there's a single value
|
|
97
|
+
to rotate. (An earlier draft of this guide said to put the key in app source — don't; use Build
|
|
98
|
+
Secrets.)
|
|
84
99
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
**Minting (current state, 2.0.0-alpha):** the `dev` and `prod` keys are **shared secrets
|
|
101
|
+
configured on the SmartLinks backend** — one `dev` key and one `prod` key covering all
|
|
102
|
+
first-party apps. There is **no self-service minting UI yet**: ask the platform owner for the
|
|
103
|
+
`dev` key and put it in your workspace Build Secret. Per-app keys, self-service minting, and
|
|
104
|
+
rotation are planned; rotating the shared `dev` key just means updating the one Build Secret
|
|
105
|
+
(registered releases are unaffected — the key authorizes *writes*, it isn't stored on releases).
|
|
106
|
+
|
|
107
|
+
Present the key in the `x-smartlinks-deploy-key` header.
|
|
88
108
|
|
|
89
109
|
---
|
|
90
110
|
|
|
91
111
|
## The registration endpoint
|
|
92
112
|
|
|
93
113
|
```
|
|
94
|
-
POST https
|
|
114
|
+
POST https://smartlinks.app/api/v1/apps/{appId}/releases # main SaaS; a VPC env uses its own host
|
|
95
115
|
x-smartlinks-deploy-key: <your deploy key>
|
|
96
116
|
Content-Type: application/json
|
|
97
117
|
```
|
|
@@ -124,6 +144,15 @@ Each validation error is `{ code, message, path }`, e.g.:
|
|
|
124
144
|
]}
|
|
125
145
|
```
|
|
126
146
|
|
|
147
|
+
### Re-registering & version collisions
|
|
148
|
+
|
|
149
|
+
Registration is an **upsert keyed by (app, channel)** — the newest registration becomes that
|
|
150
|
+
channel's live release. Registering again **overwrites** it (last write wins); there is **no**
|
|
151
|
+
version-collision error even if `meta.version` is unchanged. So re-publishing to `dev` without
|
|
152
|
+
bumping the version is a normal, intentional overwrite — which is what you want on `dev`. (A
|
|
153
|
+
stricter `prod` policy that rejects a duplicate `version` may come later; it isn't enforced
|
|
154
|
+
today.)
|
|
155
|
+
|
|
127
156
|
### What gets validated
|
|
128
157
|
|
|
129
158
|
- `manifest.meta.appId` must match the `{appId}` in the URL.
|
|
@@ -145,24 +174,36 @@ so a bad install fails the publish.
|
|
|
145
174
|
import { readFileSync } from 'node:fs'
|
|
146
175
|
import { execSync } from 'node:child_process'
|
|
147
176
|
|
|
148
|
-
const API
|
|
149
|
-
const KEY
|
|
150
|
-
const CHANNEL
|
|
177
|
+
const API = process.env.SMARTLINKS_API || 'https://smartlinks.app' // a VPC env: set to its host
|
|
178
|
+
const KEY = process.env.SMARTLINKS_DEPLOY_KEY // Lovable Build Secret (dev) / CI secret (prod)
|
|
179
|
+
const CHANNEL = process.env.SMARTLINKS_CHANNEL // 'dev' | 'beta' | 'prod'; UNSET ⇒ don't register
|
|
180
|
+
|
|
181
|
+
// --- Gate: only register when this build is meant to ---
|
|
182
|
+
// A preview / live-edit build (no channel) skips quietly so it never fails. A build that
|
|
183
|
+
// declares a channel but has no key is a hard error IF it's prod; dev skips quietly.
|
|
184
|
+
if (!CHANNEL) {
|
|
185
|
+
console.log('ℹ︎ SmartLinks: SMARTLINKS_CHANNEL unset — skipping release registration (preview build).')
|
|
186
|
+
process.exit(0)
|
|
187
|
+
}
|
|
188
|
+
if (!KEY) {
|
|
189
|
+
if (CHANNEL === 'prod') { console.error('❌ prod build but SMARTLINKS_DEPLOY_KEY is missing'); process.exit(1) }
|
|
190
|
+
console.log(`ℹ︎ SmartLinks: no deploy key for "${CHANNEL}" — skipping registration.`)
|
|
191
|
+
process.exit(0)
|
|
192
|
+
}
|
|
151
193
|
|
|
152
194
|
const manifest = JSON.parse(readFileSync('dist/app.manifest.json', 'utf8'))
|
|
153
195
|
const appId = manifest.meta.appId
|
|
154
196
|
const version = manifest.meta.version
|
|
155
197
|
const gitHash = (() => { try { return execSync('git rev-parse --short HEAD').toString().trim() } catch { return null } })()
|
|
198
|
+
// dev: your published Lovable URL; prod: the SmartLinks CDN base. Set SMARTLINKS_BUNDLE_BASE_URL.
|
|
199
|
+
const bundleBaseUrl = process.env.SMARTLINKS_BUNDLE_BASE_URL || `https://smartlinks.app/apps/${appId}/${version}`
|
|
156
200
|
|
|
157
201
|
const res = await fetch(`${API}/api/v1/apps/${appId}/releases`, {
|
|
158
202
|
method: 'POST',
|
|
159
203
|
headers: { 'content-type': 'application/json', 'x-smartlinks-deploy-key': KEY },
|
|
160
204
|
body: JSON.stringify({
|
|
161
|
-
channel: CHANNEL,
|
|
162
|
-
|
|
163
|
-
build: { at: new Date().toISOString(), gitHash, builder: CHANNEL === 'dev' ? 'lovable' : 'cloudbuild' },
|
|
164
|
-
manifest,
|
|
165
|
-
bundleBaseUrl: `https://smartlinks.app/apps/${appId}/${version}`,
|
|
205
|
+
channel: CHANNEL, version, manifest, bundleBaseUrl,
|
|
206
|
+
build: { at: new Date().toISOString(), gitHash, builder: CHANNEL === 'dev' ? 'lovable' : 'ci' },
|
|
166
207
|
}),
|
|
167
208
|
})
|
|
168
209
|
|
|
@@ -175,7 +216,7 @@ if (!res.ok || !body.ok) {
|
|
|
175
216
|
console.log(`✅ Registered ${appId}@${version} on "${CHANNEL}" — functions: ${(body.functions || []).join(', ') || 'none'}`)
|
|
176
217
|
```
|
|
177
218
|
|
|
178
|
-
Wire it after your bundle build/hash step
|
|
219
|
+
Wire it after your bundle build/hash step:
|
|
179
220
|
|
|
180
221
|
```jsonc
|
|
181
222
|
// package.json
|
|
@@ -185,9 +226,19 @@ Wire it after your bundle build/hash step, e.g.:
|
|
|
185
226
|
}
|
|
186
227
|
```
|
|
187
228
|
|
|
188
|
-
|
|
189
|
-
`SMARTLINKS_CHANNEL=dev`.
|
|
190
|
-
- **Prod (Cloud Build)** runs the same with the **prod key** and `SMARTLINKS_CHANNEL=prod`.
|
|
229
|
+
Registration is gated by **`SMARTLINKS_CHANNEL`**, so the three Lovable build types behave correctly:
|
|
191
230
|
|
|
192
|
-
|
|
193
|
-
|
|
231
|
+
| Build | `SMARTLINKS_CHANNEL` | Result |
|
|
232
|
+
|---|---|---|
|
|
233
|
+
| **Preview / live-edit** | unset | **skips quietly** — never registers, never fails |
|
|
234
|
+
| **Dev (Publish)** | `dev` | registers to `dev` with the workspace Build-Secret key + your Lovable `SMARTLINKS_BUNDLE_BASE_URL` |
|
|
235
|
+
| **Prod (CI)** | `prod` | registers to `prod` with the prod key; a missing key **hard-fails** |
|
|
236
|
+
|
|
237
|
+
The gate is `SMARTLINKS_CHANNEL`, so **set it only where you want a release** — i.e. on the
|
|
238
|
+
Publish/CI build, not on preview. If your host exposes a publish-only signal (an env var it sets
|
|
239
|
+
only on Publish), key `SMARTLINKS_CHANNEL` off that; otherwise set it in the Publish build's env
|
|
240
|
+
and leave it unset for preview. That one variable is the difference between "this build ships a
|
|
241
|
+
release" and "this build is just a preview."
|
|
242
|
+
|
|
243
|
+
That's it: a real Publish validates + registers your app (a broken manifest or function stops
|
|
244
|
+
the deploy with an actionable error), while preview builds stay quiet.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Sequences & claim-order allocation
|
|
2
|
+
|
|
3
|
+
> **Preview — SmartLinks SDK 2.0.0-alpha.** APIs may change before 2.0.0 stable.
|
|
4
|
+
|
|
5
|
+
A **sequence** hands out a guaranteed-unique, monotonic number — `1, 2, 3, …` — and stamps it
|
|
6
|
+
onto a record. It's the primitive behind raffle tickets, "you're the Nth to claim", queue
|
|
7
|
+
positions, and limited-edition numbering: cases where you need *the next number*, exactly
|
|
8
|
+
once per subject, even with a whole room (or stadium) acting at the same instant.
|
|
9
|
+
|
|
10
|
+
## The model: allocate, then stamp — and the target is the ledger
|
|
11
|
+
|
|
12
|
+
Two steps, one call:
|
|
13
|
+
|
|
14
|
+
1. **Allocate** — get the next number from an **atomic counter**. The counter lives inside
|
|
15
|
+
your **app-config** doc at `data.sequences.<key>`, so it's scoped exactly like your other
|
|
16
|
+
app config (per collection / product / variant / batch) and needs no dedicated storage.
|
|
17
|
+
It's incremented in a single statement, so 250 simultaneous taps each get a distinct
|
|
18
|
+
number in microseconds — never two the same.
|
|
19
|
+
2. **Stamp** — write that number onto the **subject's own record** (a claim set, a proof, or
|
|
20
|
+
an app record). **That record is the ledger** — there's no separate bookkeeping table.
|
|
21
|
+
Next time you read the subject, the number is just there.
|
|
22
|
+
|
|
23
|
+
Because the target is the ledger, allocation is **idempotent**: on a re-tap we read the
|
|
24
|
+
subject first and return the number it already has, rather than allocating a second one.
|
|
25
|
+
|
|
26
|
+
## Guarantees
|
|
27
|
+
|
|
28
|
+
- **Unique + monotonic** — the counter is an atomic increment, never a read-modify-write, so
|
|
29
|
+
there are no duplicates and no lost updates under load.
|
|
30
|
+
- **Idempotent per subject** — one number per subject; a re-tap returns the same number.
|
|
31
|
+
- **Concurrency-safe at scale** — the only shared hot spot is the one counter row (Postgres
|
|
32
|
+
serializes it); the stamp is per-subject (its own record), so the model holds from 250 in a
|
|
33
|
+
room to 60,000 in a stadium. A concurrent double-tap on the *same* subject at worst skips
|
|
34
|
+
one number (a harmless gap) — never puts two numbers on one person.
|
|
35
|
+
|
|
36
|
+
## Scoping
|
|
37
|
+
|
|
38
|
+
- **Counter scope** — the app-config doc it lives on: collection-wide, or per product /
|
|
39
|
+
variant / batch. All wristbands mapped to one product? Scope the counter to that product.
|
|
40
|
+
- **`key`** — a name within that doc (e.g. `raffle:2026-cup`), so one config doc can hold
|
|
41
|
+
several independent sequences.
|
|
42
|
+
- **`start`** — the first number (default `1`); use it to reserve a block (start at `51` and
|
|
43
|
+
tell people it's `1`, or just filter `< N` at draw time).
|
|
44
|
+
|
|
45
|
+
## Idempotency subject — use a *stable* id
|
|
46
|
+
|
|
47
|
+
The number is deduped by the **subject id** you pass, so it must be the **stable** identity:
|
|
48
|
+
- **Claim set id** (the wristband's permanent record) — the right key when people aren't
|
|
49
|
+
logged in. A re-tap resolves to the same claim set → same number.
|
|
50
|
+
- The authenticated **user/contact** — if they sign in / claim.
|
|
51
|
+
|
|
52
|
+
Do **not** key on a value that changes per interaction (e.g. a virtual proof id minted fresh
|
|
53
|
+
on each tap) — that would let one person take several numbers.
|
|
54
|
+
|
|
55
|
+
## Where the number is stored (the sink)
|
|
56
|
+
|
|
57
|
+
The stamp target is configurable — the number lives wherever you'll read it:
|
|
58
|
+
|
|
59
|
+
| Target | Use |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `claimSet` | The Firestore wristband record — fast, no proof mint on the hot path. |
|
|
62
|
+
| `proof` | A minted proof (value or attestation) — when the number should travel with the proof. |
|
|
63
|
+
| `appRecord` | A structured app record — for queryable, per-app data. |
|
|
64
|
+
|
|
65
|
+
## Worked example — a free raffle on NFC wristbands
|
|
66
|
+
|
|
67
|
+
Everyone taps a wristband and hits **Enter the raffle**. Each tap allocates the next number
|
|
68
|
+
and writes it onto that wristband's claim set — fast, unique, no proof mint:
|
|
69
|
+
|
|
70
|
+
```jsonc
|
|
71
|
+
// allocate-and-stamp (conceptual shape)
|
|
72
|
+
{
|
|
73
|
+
"appId": "raffle-app",
|
|
74
|
+
"productId": "wristbands-2026", // the counter's scope
|
|
75
|
+
"key": "raffle:2026-cup", // the named sequence
|
|
76
|
+
"start": 1,
|
|
77
|
+
"subjectId": "<claim set id>", // STABLE identity — re-taps collapse to one number
|
|
78
|
+
"target": "claimSet",
|
|
79
|
+
"field": "raffleNumber"
|
|
80
|
+
}
|
|
81
|
+
// → { "number": 42, "isNew": true } (re-tap → { "number": 42, "isNew": false })
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Drawing the winner needs no separate ledger either — query the claim sets (or proofs) where
|
|
85
|
+
`raffleNumber` is set; that field is your entry list, in allocation order.
|
|
86
|
+
|
|
87
|
+
## Status
|
|
88
|
+
|
|
89
|
+
The allocator + stamping run server-side today. The **public "enter" action** an app widget
|
|
90
|
+
calls on tap (and its SDK wrapper) is being wired in the 2.0.0-alpha line — this doc is the
|
|
91
|
+
contract it will expose.
|