@proveanything/smartlinks 2.0.0-alpha.4 → 2.0.0-alpha.6
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/api/sequence.d.ts +7 -1
- package/dist/docs/API_SUMMARY.md +7 -1
- package/dist/docs/sequences.md +26 -15
- package/dist/http.d.ts +20 -0
- package/dist/http.js +81 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/docs/API_SUMMARY.md +7 -1
- package/docs/sequences.md +26 -15
- package/package.json +1 -1
package/dist/api/sequence.d.ts
CHANGED
|
@@ -3,7 +3,13 @@ export interface AllocateSequenceInput {
|
|
|
3
3
|
appId: string;
|
|
4
4
|
/** The configured sequence id — the key of data.sequenceConfigs on the app config. */
|
|
5
5
|
sequenceId: string;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* The STABLE subject identity. For a `claimSet` sequence, pass the tap's virtual-proof id
|
|
8
|
+
* `<claimSetId>-<code>` (e.g. "23-oOkf8o") for a per-wristband raffle — the code is the tag's
|
|
9
|
+
* permanent id, so re-taps of the same wristband return the same number; the number is stamped
|
|
10
|
+
* on that code's doc and surfaces in `tagData`. Pass a bare claim-set id for one number per
|
|
11
|
+
* group. Never a value that changes per tap.
|
|
12
|
+
*/
|
|
7
13
|
subjectId: string;
|
|
8
14
|
/** Optional product scope, when the sequence config is scoped per product. */
|
|
9
15
|
productId?: string;
|
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.6 | Generated: 2026-09-14T20:20:02.351Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -159,6 +159,12 @@ The Smartlinks SDK is organized into the following namespaces:
|
|
|
159
159
|
|
|
160
160
|
Core HTTP functions for API configuration and communication:
|
|
161
161
|
|
|
162
|
+
**getHttpCacheDiagnostics**() → `void`
|
|
163
|
+
Snapshot of cache counters + current keys. Call from the console via `window.__slHttpDiag()`.
|
|
164
|
+
|
|
165
|
+
**resetHttpCacheDiagnostics**() → `void`
|
|
166
|
+
Reset the diagnostics counters (does not touch the cache itself).
|
|
167
|
+
|
|
162
168
|
**isProxyEnabled**() → `boolean`
|
|
163
169
|
Return whether proxy mode is currently enabled.
|
|
164
170
|
|
package/dist/docs/sequences.md
CHANGED
|
@@ -45,22 +45,27 @@ subject first and return the number it already has, rather than allocating a sec
|
|
|
45
45
|
## Idempotency subject — use a *stable* id
|
|
46
46
|
|
|
47
47
|
The number is deduped by the **subject id** you pass, so it must be the **stable** identity:
|
|
48
|
-
- **
|
|
49
|
-
|
|
48
|
+
- **Virtual-proof id `<claimSetId>-<code>`** (e.g. `23-oOkf8o`) — the right key for a
|
|
49
|
+
per-wristband raffle. The `code` is the physical tag's permanent id, so a re-tap of the same
|
|
50
|
+
wristband resolves to the same code doc → same number. The virtual proof record is transient,
|
|
51
|
+
but the **code** inside its id is stable — that's what the sink keys on (it splits the id and
|
|
52
|
+
uses only `<claimSetId>` + `<code>`).
|
|
53
|
+
- **Bare claim-set id** — when one number per *group* is intended.
|
|
50
54
|
- The authenticated **user/contact** — if they sign in / claim.
|
|
51
55
|
|
|
52
|
-
Do **not** key on
|
|
53
|
-
on
|
|
56
|
+
Do **not** key on the transient part of a per-tap identity (a freshly-minted virtual proof
|
|
57
|
+
record) — key on the stable **code**, which is exactly what the `<claimSetId>-<code>` subject
|
|
58
|
+
carries.
|
|
54
59
|
|
|
55
60
|
## Where the number is stored (the sink)
|
|
56
61
|
|
|
57
62
|
The stamp target is configurable — the number lives wherever you'll read it:
|
|
58
63
|
|
|
59
|
-
| Target | Use |
|
|
60
|
-
|
|
61
|
-
| `claimSet` | The Firestore wristband
|
|
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
|
+
| Target | Subject id | Use |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `claimSet` | the virtual-proof id `<claimSetId>-<code>` (e.g. `23-oOkf8o`) **or** a bare `<claimSetId>` | The Firestore claim-set world. **The subject decides the exact doc:** a `<claimSetId>-<code>` id stamps the individual **code** doc (per-wristband — rides back as `tagData` on the next tap, every wristband its own number); a bare id stamps the whole **set** doc (one shared value). Claim-set ids are hyphen-free, so a hyphen unambiguously means the per-code form. |
|
|
67
|
+
| `proof` | the proof id | A minted proof (value or attestation) — when the number should travel with the proof. |
|
|
68
|
+
| `appRecord` | the record id | A structured app record — for queryable, per-app data. |
|
|
64
69
|
|
|
65
70
|
## Configure the sequence (once, server-side)
|
|
66
71
|
|
|
@@ -72,14 +77,19 @@ makes the public endpoint safe: the target/field/scope are set by you, not the c
|
|
|
72
77
|
{
|
|
73
78
|
"raffle": {
|
|
74
79
|
"key": "raffle:2026-cup", // the named counter (data.sequences.<key>)
|
|
75
|
-
"target": "claimSet", // claimSet | proof | appRecord —
|
|
76
|
-
"field": "raffleNumber", // the property written on the target
|
|
77
|
-
"productId": "wristbands-2026", // counter scope (optional; else collection-wide)
|
|
80
|
+
"target": "claimSet", // claimSet | proof | appRecord — the ledger domain
|
|
81
|
+
"field": "raffleNumber", // the property written on the target (comes back in tagData)
|
|
78
82
|
"start": 1 // first number (optional, default 1)
|
|
83
|
+
// no productId → one collection-wide counter (all wristbands share the sequence)
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
```
|
|
82
87
|
|
|
88
|
+
> **Per-wristband raffle.** Keep `target: "claimSet"` and pass the tap's virtual-proof id
|
|
89
|
+
> (`<claimSetId>-<code>`) as the subject — the sink writes the individual tag's **code** doc, so
|
|
90
|
+
> each wristband gets its own number and it surfaces in `tagData` on the next tap. Pass a bare
|
|
91
|
+
> claim-set id instead only if you want one number for the whole group.
|
|
92
|
+
|
|
83
93
|
## Call it (the widget)
|
|
84
94
|
|
|
85
95
|
Your widget calls one bounded, public endpoint on tap. It passes only the **subject id** —
|
|
@@ -87,12 +97,13 @@ never the target/field:
|
|
|
87
97
|
|
|
88
98
|
```
|
|
89
99
|
POST /api/v1/public/collection/:collectionId/sequence/allocate
|
|
90
|
-
{ "appId": "
|
|
100
|
+
{ "appId": "liveWidgets", "sequenceId": "raffle", "subjectId": "23-oOkf8o" }
|
|
91
101
|
→ { "number": 42, "isNew": true } // re-tap → { "number": 42, "isNew": false }
|
|
92
102
|
```
|
|
93
103
|
|
|
94
|
-
- **`subjectId`** is the STABLE identity
|
|
95
|
-
|
|
104
|
+
- **`subjectId`** is the STABLE identity. For `claimCode` it's the virtual-proof id
|
|
105
|
+
`<claimSetId>-<code>` (e.g. `23-oOkf8o`) straight off the tap — re-taps of the same wristband
|
|
106
|
+
collapse to one number. (For `claimSet` it's the claim-set id.)
|
|
96
107
|
- **Idempotent**, so both your flows are the *same call*:
|
|
97
108
|
- **Auto:** on load, call allocate → get your number (existing or freshly minted).
|
|
98
109
|
- **Button:** click → animate → same call → "Your raffle number is 42."
|
package/dist/http.d.ts
CHANGED
|
@@ -5,6 +5,26 @@ type Logger = {
|
|
|
5
5
|
error?: (...args: any[]) => void;
|
|
6
6
|
log?: (...args: any[]) => void;
|
|
7
7
|
} | ((...args: any[]) => void);
|
|
8
|
+
/** Snapshot of cache counters + current keys. Call from the console via `window.__slHttpDiag()`. */
|
|
9
|
+
export declare function getHttpCacheDiagnostics(): {
|
|
10
|
+
size: number;
|
|
11
|
+
keys: string[];
|
|
12
|
+
inflight: string[];
|
|
13
|
+
cacheEnabled: boolean;
|
|
14
|
+
cacheDefaultTtlMs: number;
|
|
15
|
+
cachePersistence: "none" | "indexeddb";
|
|
16
|
+
cacheClearOnPageLoad: boolean;
|
|
17
|
+
l1Hits: number;
|
|
18
|
+
inflightDedups: number;
|
|
19
|
+
l2Hits: number;
|
|
20
|
+
networkFetches: number;
|
|
21
|
+
skips: number;
|
|
22
|
+
clears: number;
|
|
23
|
+
lastClearReason: string | null;
|
|
24
|
+
lastClearAt: number;
|
|
25
|
+
};
|
|
26
|
+
/** Reset the diagnostics counters (does not touch the cache itself). */
|
|
27
|
+
export declare function resetHttpCacheDiagnostics(): void;
|
|
8
28
|
/** Return whether proxy mode is currently enabled. */
|
|
9
29
|
export declare function isProxyEnabled(): boolean;
|
|
10
30
|
export declare function initializeApi(options: {
|
package/dist/http.js
CHANGED
|
@@ -79,6 +79,69 @@ const TOKEN_STORAGE_KEY = 'sl:token';
|
|
|
79
79
|
let cachePersistenceTtlMs = 7 * 24 * 60 * 60000;
|
|
80
80
|
/** When true (default), serve stale L2 data via SmartlinksOfflineError on network failure. */
|
|
81
81
|
let cacheServeStaleOnOffline = true;
|
|
82
|
+
let logger;
|
|
83
|
+
const httpCacheStats = {
|
|
84
|
+
l1Hits: 0, inflightDedups: 0, l2Hits: 0, networkFetches: 0, skips: 0,
|
|
85
|
+
clears: 0, lastClearReason: null, lastClearAt: 0,
|
|
86
|
+
};
|
|
87
|
+
function httpDebugEnabled() {
|
|
88
|
+
var _a;
|
|
89
|
+
try {
|
|
90
|
+
if (typeof window !== 'undefined') {
|
|
91
|
+
if (window.__SL_HTTP_DEBUG__)
|
|
92
|
+
return true;
|
|
93
|
+
// URL opt-in so boot-time GETs can be traced on a deployed app without any
|
|
94
|
+
// code change: just append ?__slhttpdebug=1 (or &…) to the page URL and reload.
|
|
95
|
+
if (/[?&]__slhttpdebug=1\b/.test(((_a = window.location) === null || _a === void 0 ? void 0 : _a.search) || ''))
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (_b) { }
|
|
100
|
+
return !!logger;
|
|
101
|
+
}
|
|
102
|
+
function httpDebug(...args) {
|
|
103
|
+
if (!httpDebugEnabled())
|
|
104
|
+
return;
|
|
105
|
+
try {
|
|
106
|
+
(console.info || console.log).call(console, '[sl-http]', ...args);
|
|
107
|
+
}
|
|
108
|
+
catch (_a) { }
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Single choke-point for wiping the in-memory GET cache. Routing every clear
|
|
112
|
+
* through here means each one is counted and logged with a reason — so a test
|
|
113
|
+
* run shows exactly which cache clears fired and why (e.g. token change on a
|
|
114
|
+
* public page that should never have cleared).
|
|
115
|
+
*/
|
|
116
|
+
function clearHttpCache(reason) {
|
|
117
|
+
httpCacheStats.clears++;
|
|
118
|
+
httpCacheStats.lastClearReason = reason;
|
|
119
|
+
httpCacheStats.lastClearAt = Date.now();
|
|
120
|
+
httpDebug('cache CLEAR', { reason, hadEntries: httpCache.size });
|
|
121
|
+
httpCache.clear();
|
|
122
|
+
}
|
|
123
|
+
/** Snapshot of cache counters + current keys. Call from the console via `window.__slHttpDiag()`. */
|
|
124
|
+
export function getHttpCacheDiagnostics() {
|
|
125
|
+
const keys = [...httpCache.keys()];
|
|
126
|
+
return Object.assign(Object.assign({}, httpCacheStats), { size: httpCache.size, keys, inflight: [...httpCache.entries()].filter(([, v]) => v.promise).map(([k]) => k), cacheEnabled, cacheDefaultTtlMs, cachePersistence, cacheClearOnPageLoad });
|
|
127
|
+
}
|
|
128
|
+
/** Reset the diagnostics counters (does not touch the cache itself). */
|
|
129
|
+
export function resetHttpCacheDiagnostics() {
|
|
130
|
+
httpCacheStats.l1Hits = 0;
|
|
131
|
+
httpCacheStats.inflightDedups = 0;
|
|
132
|
+
httpCacheStats.l2Hits = 0;
|
|
133
|
+
httpCacheStats.networkFetches = 0;
|
|
134
|
+
httpCacheStats.skips = 0;
|
|
135
|
+
httpCacheStats.clears = 0;
|
|
136
|
+
httpCacheStats.lastClearReason = null;
|
|
137
|
+
httpCacheStats.lastClearAt = 0;
|
|
138
|
+
}
|
|
139
|
+
// Expose on window for zero-wiring console access after a build.
|
|
140
|
+
try {
|
|
141
|
+
if (typeof window !== 'undefined')
|
|
142
|
+
window.__slHttpDiag = getHttpCacheDiagnostics;
|
|
143
|
+
}
|
|
144
|
+
catch (_a) { }
|
|
82
145
|
/**
|
|
83
146
|
* Per-resource TTL overrides — checked in order, first match wins.
|
|
84
147
|
*
|
|
@@ -143,7 +206,7 @@ function evictLruIfNeeded() {
|
|
|
143
206
|
function clearSessionCachesOnPageLoad() {
|
|
144
207
|
if (typeof window === 'undefined')
|
|
145
208
|
return; // Node.js environment
|
|
146
|
-
|
|
209
|
+
clearHttpCache('pageLoad session reset');
|
|
147
210
|
try {
|
|
148
211
|
if (typeof sessionStorage !== 'undefined') {
|
|
149
212
|
const sessionKeys = Object.keys(sessionStorage).filter(k => k.startsWith('smartlinks:cache:'));
|
|
@@ -216,7 +279,6 @@ function isNetworkError(err) {
|
|
|
216
279
|
// fetch() throws TypeError on network failure; SmartlinksApiError is not a TypeError
|
|
217
280
|
return err instanceof TypeError;
|
|
218
281
|
}
|
|
219
|
-
let logger;
|
|
220
282
|
function logDebug(...args) {
|
|
221
283
|
if (!logger)
|
|
222
284
|
return;
|
|
@@ -421,7 +483,7 @@ export function initializeApi(options) {
|
|
|
421
483
|
// Clear both cache tiers on forced re-initialization so stale data
|
|
422
484
|
// from the previous configuration cannot bleed through.
|
|
423
485
|
if (options.force) {
|
|
424
|
-
|
|
486
|
+
clearHttpCache('initializeApi(force)');
|
|
425
487
|
idbClear().catch(() => { });
|
|
426
488
|
}
|
|
427
489
|
logger = options.logger;
|
|
@@ -468,7 +530,7 @@ export function setBearerToken(token) {
|
|
|
468
530
|
catch (_b) { }
|
|
469
531
|
}
|
|
470
532
|
}
|
|
471
|
-
|
|
533
|
+
clearHttpCache(`setBearerToken(${token ? 'set' : 'cleared'})`);
|
|
472
534
|
if (cachePersistence !== 'none')
|
|
473
535
|
idbClear().catch(() => { });
|
|
474
536
|
}
|
|
@@ -492,7 +554,7 @@ export function setGrantToken(token) {
|
|
|
492
554
|
if (token === grantToken)
|
|
493
555
|
return;
|
|
494
556
|
grantToken = token;
|
|
495
|
-
|
|
557
|
+
clearHttpCache(`setGrantToken(${token ? 'set' : 'cleared'})`);
|
|
496
558
|
if (cachePersistence !== 'none')
|
|
497
559
|
idbClear().catch(() => { });
|
|
498
560
|
}
|
|
@@ -612,7 +674,7 @@ export function configureSdkCache(options) {
|
|
|
612
674
|
*/
|
|
613
675
|
export function invalidateCache(urlPattern) {
|
|
614
676
|
if (!urlPattern) {
|
|
615
|
-
|
|
677
|
+
clearHttpCache('invalidateCache(all)');
|
|
616
678
|
if (cachePersistence !== 'none')
|
|
617
679
|
idbClear().catch(() => { });
|
|
618
680
|
return;
|
|
@@ -1094,19 +1156,28 @@ export async function request(path) {
|
|
|
1094
1156
|
const skipCache = shouldSkipCache(path);
|
|
1095
1157
|
const cacheKey = buildCacheKey(path);
|
|
1096
1158
|
const ttl = skipCache ? 0 : getTtlForPath(path);
|
|
1159
|
+
if (skipCache) {
|
|
1160
|
+
httpCacheStats.skips++;
|
|
1161
|
+
httpDebug('GET skip-cache', { path });
|
|
1162
|
+
}
|
|
1097
1163
|
if (!skipCache) {
|
|
1098
1164
|
// 1. L1 hit — return from memory immediately
|
|
1099
1165
|
const l1 = getHttpCacheHit(cacheKey, ttl);
|
|
1100
1166
|
if (l1 !== null) {
|
|
1167
|
+
httpCacheStats.l1Hits++;
|
|
1168
|
+
httpDebug('GET L1 hit', { path, ttlMs: ttl });
|
|
1101
1169
|
logDebug('[smartlinks] GET cache hit (L1)', { path });
|
|
1102
1170
|
return l1;
|
|
1103
1171
|
}
|
|
1104
1172
|
// 2. In-flight deduplication — share an already-pending promise
|
|
1105
1173
|
const inflight = httpCache.get(cacheKey);
|
|
1106
1174
|
if (inflight === null || inflight === void 0 ? void 0 : inflight.promise) {
|
|
1175
|
+
httpCacheStats.inflightDedups++;
|
|
1176
|
+
httpDebug('GET in-flight dedup', { path });
|
|
1107
1177
|
logDebug('[smartlinks] GET in-flight dedup', { path });
|
|
1108
1178
|
return inflight.promise;
|
|
1109
1179
|
}
|
|
1180
|
+
httpDebug('GET MISS → will fetch', { path, ttlMs: ttl, cacheKey });
|
|
1110
1181
|
}
|
|
1111
1182
|
// 3. Build the fetch promise.
|
|
1112
1183
|
// The IIFE starts synchronously until its first `await`, then the outer
|
|
@@ -1117,6 +1188,8 @@ export async function request(path) {
|
|
|
1117
1188
|
if (!skipCache && cachePersistence !== 'none') {
|
|
1118
1189
|
const l2 = await idbGet(cacheKey);
|
|
1119
1190
|
if (l2 && Date.now() - l2.timestamp <= ttl) {
|
|
1191
|
+
httpCacheStats.l2Hits++;
|
|
1192
|
+
httpDebug('GET L2 hit', { path });
|
|
1120
1193
|
logDebug('[smartlinks] GET cache hit (L2)', { path });
|
|
1121
1194
|
setHttpCacheEntry(cacheKey, l2.data);
|
|
1122
1195
|
return l2.data;
|
|
@@ -1124,6 +1197,8 @@ export async function request(path) {
|
|
|
1124
1197
|
}
|
|
1125
1198
|
// 3b. Network fetch
|
|
1126
1199
|
try {
|
|
1200
|
+
httpCacheStats.networkFetches++;
|
|
1201
|
+
httpDebug('GET NETWORK fetch', { path, skipCache, ttlMs: ttl });
|
|
1127
1202
|
let data;
|
|
1128
1203
|
if (proxyMode) {
|
|
1129
1204
|
logDebug('[smartlinks] GET via proxy', { path });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken } from "./http";
|
|
1
|
+
export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, getHttpCacheDiagnostics, resetHttpCacheDiagnostics, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken } from "./http";
|
|
2
2
|
export * from "./api";
|
|
3
3
|
export * from "./types";
|
|
4
4
|
export { iframe } from "./iframe";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
// Top-level entrypoint of the npm package. Re-export initializeApi + all namespaces.
|
|
3
|
-
export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken } from "./http";
|
|
3
|
+
export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, getHttpCacheDiagnostics, resetHttpCacheDiagnostics, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken } from "./http";
|
|
4
4
|
export * from "./api";
|
|
5
5
|
export * from "./types";
|
|
6
6
|
// Iframe namespace
|
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.6 | Generated: 2026-09-14T20:20:02.351Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -159,6 +159,12 @@ The Smartlinks SDK is organized into the following namespaces:
|
|
|
159
159
|
|
|
160
160
|
Core HTTP functions for API configuration and communication:
|
|
161
161
|
|
|
162
|
+
**getHttpCacheDiagnostics**() → `void`
|
|
163
|
+
Snapshot of cache counters + current keys. Call from the console via `window.__slHttpDiag()`.
|
|
164
|
+
|
|
165
|
+
**resetHttpCacheDiagnostics**() → `void`
|
|
166
|
+
Reset the diagnostics counters (does not touch the cache itself).
|
|
167
|
+
|
|
162
168
|
**isProxyEnabled**() → `boolean`
|
|
163
169
|
Return whether proxy mode is currently enabled.
|
|
164
170
|
|
package/docs/sequences.md
CHANGED
|
@@ -45,22 +45,27 @@ subject first and return the number it already has, rather than allocating a sec
|
|
|
45
45
|
## Idempotency subject — use a *stable* id
|
|
46
46
|
|
|
47
47
|
The number is deduped by the **subject id** you pass, so it must be the **stable** identity:
|
|
48
|
-
- **
|
|
49
|
-
|
|
48
|
+
- **Virtual-proof id `<claimSetId>-<code>`** (e.g. `23-oOkf8o`) — the right key for a
|
|
49
|
+
per-wristband raffle. The `code` is the physical tag's permanent id, so a re-tap of the same
|
|
50
|
+
wristband resolves to the same code doc → same number. The virtual proof record is transient,
|
|
51
|
+
but the **code** inside its id is stable — that's what the sink keys on (it splits the id and
|
|
52
|
+
uses only `<claimSetId>` + `<code>`).
|
|
53
|
+
- **Bare claim-set id** — when one number per *group* is intended.
|
|
50
54
|
- The authenticated **user/contact** — if they sign in / claim.
|
|
51
55
|
|
|
52
|
-
Do **not** key on
|
|
53
|
-
on
|
|
56
|
+
Do **not** key on the transient part of a per-tap identity (a freshly-minted virtual proof
|
|
57
|
+
record) — key on the stable **code**, which is exactly what the `<claimSetId>-<code>` subject
|
|
58
|
+
carries.
|
|
54
59
|
|
|
55
60
|
## Where the number is stored (the sink)
|
|
56
61
|
|
|
57
62
|
The stamp target is configurable — the number lives wherever you'll read it:
|
|
58
63
|
|
|
59
|
-
| Target | Use |
|
|
60
|
-
|
|
61
|
-
| `claimSet` | The Firestore wristband
|
|
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
|
+
| Target | Subject id | Use |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `claimSet` | the virtual-proof id `<claimSetId>-<code>` (e.g. `23-oOkf8o`) **or** a bare `<claimSetId>` | The Firestore claim-set world. **The subject decides the exact doc:** a `<claimSetId>-<code>` id stamps the individual **code** doc (per-wristband — rides back as `tagData` on the next tap, every wristband its own number); a bare id stamps the whole **set** doc (one shared value). Claim-set ids are hyphen-free, so a hyphen unambiguously means the per-code form. |
|
|
67
|
+
| `proof` | the proof id | A minted proof (value or attestation) — when the number should travel with the proof. |
|
|
68
|
+
| `appRecord` | the record id | A structured app record — for queryable, per-app data. |
|
|
64
69
|
|
|
65
70
|
## Configure the sequence (once, server-side)
|
|
66
71
|
|
|
@@ -72,14 +77,19 @@ makes the public endpoint safe: the target/field/scope are set by you, not the c
|
|
|
72
77
|
{
|
|
73
78
|
"raffle": {
|
|
74
79
|
"key": "raffle:2026-cup", // the named counter (data.sequences.<key>)
|
|
75
|
-
"target": "claimSet", // claimSet | proof | appRecord —
|
|
76
|
-
"field": "raffleNumber", // the property written on the target
|
|
77
|
-
"productId": "wristbands-2026", // counter scope (optional; else collection-wide)
|
|
80
|
+
"target": "claimSet", // claimSet | proof | appRecord — the ledger domain
|
|
81
|
+
"field": "raffleNumber", // the property written on the target (comes back in tagData)
|
|
78
82
|
"start": 1 // first number (optional, default 1)
|
|
83
|
+
// no productId → one collection-wide counter (all wristbands share the sequence)
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
```
|
|
82
87
|
|
|
88
|
+
> **Per-wristband raffle.** Keep `target: "claimSet"` and pass the tap's virtual-proof id
|
|
89
|
+
> (`<claimSetId>-<code>`) as the subject — the sink writes the individual tag's **code** doc, so
|
|
90
|
+
> each wristband gets its own number and it surfaces in `tagData` on the next tap. Pass a bare
|
|
91
|
+
> claim-set id instead only if you want one number for the whole group.
|
|
92
|
+
|
|
83
93
|
## Call it (the widget)
|
|
84
94
|
|
|
85
95
|
Your widget calls one bounded, public endpoint on tap. It passes only the **subject id** —
|
|
@@ -87,12 +97,13 @@ never the target/field:
|
|
|
87
97
|
|
|
88
98
|
```
|
|
89
99
|
POST /api/v1/public/collection/:collectionId/sequence/allocate
|
|
90
|
-
{ "appId": "
|
|
100
|
+
{ "appId": "liveWidgets", "sequenceId": "raffle", "subjectId": "23-oOkf8o" }
|
|
91
101
|
→ { "number": 42, "isNew": true } // re-tap → { "number": 42, "isNew": false }
|
|
92
102
|
```
|
|
93
103
|
|
|
94
|
-
- **`subjectId`** is the STABLE identity
|
|
95
|
-
|
|
104
|
+
- **`subjectId`** is the STABLE identity. For `claimCode` it's the virtual-proof id
|
|
105
|
+
`<claimSetId>-<code>` (e.g. `23-oOkf8o`) straight off the tap — re-taps of the same wristband
|
|
106
|
+
collapse to one number. (For `claimSet` it's the claim-set id.)
|
|
96
107
|
- **Idempotent**, so both your flows are the *same call*:
|
|
97
108
|
- **Auto:** on load, call allocate → get your number (existing or freshly minted).
|
|
98
109
|
- **Button:** click → animate → same call → "Your raffle number is 42."
|