@proveanything/smartlinks 1.9.16 → 1.9.19

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.
@@ -369,23 +369,116 @@ export interface RelatedResponse {
369
369
  records: AppRecord[];
370
370
  }
371
371
  /**
372
- * Public create policy configuration
372
+ * Top-level public-create policy stored under the `publicCreate` key of an
373
+ * app config document. Controls which caller types may create objects on
374
+ * **public** App Objects endpoints.
375
+ *
376
+ * Set via `POST /api/v1/admin/collection/:collectionId/apps/:appId` with the
377
+ * policy as the request body (merged over any existing config).
378
+ *
379
+ * The server reads this document at request time — no cache invalidation or
380
+ * service restart is required after changing it.
373
381
  */
374
382
  export interface PublicCreatePolicy {
375
- cases?: PublicCreateRule;
376
- threads?: PublicCreateRule;
377
- records?: PublicCreateRule;
383
+ cases?: PublicCreateObjectRule;
384
+ threads?: PublicCreateObjectRule;
385
+ records?: PublicCreateObjectRule;
378
386
  }
379
387
  /**
380
- * Rule for public create operations
388
+ * Per-object-type rule within a {@link PublicCreatePolicy}.
389
+ * Each caller class (`anonymous`, `authenticated`) has its own independent
390
+ * branch so you can apply different enforcement for each.
381
391
  */
382
- export interface PublicCreateRule {
383
- allow: {
384
- anonymous?: boolean;
385
- authenticated?: boolean;
386
- };
392
+ export interface PublicCreateObjectRule {
393
+ /** Rules for unauthenticated (anonymous) callers */
394
+ anonymous?: PublicCreateBranch;
395
+ /** Rules for authenticated (signed-in contact) callers */
396
+ authenticated?: PublicCreateBranch;
397
+ }
398
+ /**
399
+ * Policy branch for a single caller class.
400
+ *
401
+ * ### Visibility enforcement guard-rails
402
+ *
403
+ * The server silently corrects misconfigured visibility values:
404
+ *
405
+ * | Caller type | `enforce.visibility` supplied | Server overrides to |
406
+ * |-----------------|-------------------------------|----------------------|
407
+ * | `anonymous` | `'owner'` | `'admin'` |
408
+ * | `authenticated` | `'public'` | `'owner'` |
409
+ *
410
+ * These guards exist because anonymous callers have no identity to own a
411
+ * record, and `'public'` visibility for authenticated-only objects would be
412
+ * a misconfiguration.
413
+ */
414
+ export interface PublicCreateBranch {
415
+ /** Whether creation is permitted for this caller class */
416
+ allow: boolean;
417
+ /**
418
+ * Field values merged **over** the caller's request body before writing.
419
+ * Use this to lock down `visibility` and `status` regardless of what the
420
+ * client sends.
421
+ */
387
422
  enforce?: {
388
- anonymous?: Partial<CreateCaseInput | CreateThreadInput | CreateRecordInput>;
389
- authenticated?: Partial<CreateCaseInput | CreateThreadInput | CreateRecordInput>;
423
+ visibility?: 'public' | 'owner' | 'admin';
424
+ status?: string;
425
+ };
426
+ /**
427
+ * Anonymous edit-token configuration.
428
+ * **Records only** — ignored for cases and threads.
429
+ *
430
+ * When `editToken: true`, the server generates a one-time 256-bit hex token
431
+ * on anonymous record creation, stores it in `admin.editToken` (never
432
+ * exposed to public / owner responses), and returns it **once** in the
433
+ * creation response under the `editToken` key.
434
+ *
435
+ * The client can then pass that token as the `X-Edit-Token` header on
436
+ * `PATCH /records/:recordId` to amend the `data` zone without
437
+ * authentication.
438
+ *
439
+ * @see {@link CreateRecordResponse} — creation response shape
440
+ * @see {@link records.updateWithToken} — SDK method for the amendment call
441
+ */
442
+ edit?: {
443
+ /** Enable edit-token generation on anonymous record creation */
444
+ editToken: boolean;
445
+ /**
446
+ * Optional expiry window in minutes from `createdAt`.
447
+ * After this many minutes the token is rejected with HTTP 403
448
+ * `EDIT_WINDOW_EXPIRED`. Omit for no expiry.
449
+ */
450
+ windowMinutes?: number;
390
451
  };
391
452
  }
453
+ /**
454
+ * Response from `app.records.create()` when the caller is anonymous and the
455
+ * app's `publicCreate.records.anonymous.edit.editToken` policy is `true`.
456
+ *
457
+ * The `editToken` field is present **only on the creation response** — it is
458
+ * stored in the record's `admin` zone and never returned again. Store it
459
+ * client-side immediately.
460
+ *
461
+ * Use `app.records.updateWithToken()` to amend the record's `data` zone with
462
+ * this token.
463
+ *
464
+ * @example
465
+ * ```ts
466
+ * const response = await app.records.create(collectionId, appId, {
467
+ * recordType: 'payment',
468
+ * visibility: 'public',
469
+ * data: { amount: 9900, currency: 'USD' },
470
+ * })
471
+ * // response.editToken is present when the policy has editToken: true
472
+ * const editToken = response.editToken
473
+ * ```
474
+ */
475
+ export interface CreateRecordResponse extends AppRecord {
476
+ /**
477
+ * Short-lived edit token. Present only when:
478
+ * 1. The caller is anonymous, AND
479
+ * 2. The app policy has `publicCreate.records.anonymous.edit.editToken: true`
480
+ *
481
+ * This value is returned **once** and cannot be retrieved again.
482
+ */
483
+ editToken?: string;
484
+ }
@@ -34,3 +34,4 @@ export * from "./appObjects";
34
34
  export * from "./loyalty";
35
35
  export * from "./translations";
36
36
  export * from "./config";
37
+ export * from "./widgets";
@@ -36,3 +36,4 @@ export * from "./appObjects";
36
36
  export * from "./loyalty";
37
37
  export * from "./translations";
38
38
  export * from "./config";
39
+ export * from "./widgets";
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Structured navigation request emitted via the `onNavigate` prop when a
3
+ * widget or container needs to navigate the parent platform shell to another
4
+ * app or to a specific deep-link within an app.
5
+ *
6
+ * The portal orchestrator receives this object and performs the navigation
7
+ * while preserving hierarchy context (`collectionId`, `productId`, etc.).
8
+ *
9
+ * Legacy callers may still pass a plain string path; the `onNavigate`
10
+ * signature accepts both. New widgets and containers should always use the
11
+ * structured form.
12
+ */
13
+ export interface NavigationRequest {
14
+ /** Target app ID to activate */
15
+ appId: string;
16
+ /** Deep link / page within the target app (forwarded as `pageId`) */
17
+ deepLink?: string;
18
+ /** Extra URL params forwarded to the target app */
19
+ params?: Record<string, string>;
20
+ /** Optionally switch to a specific product before showing the app */
21
+ productId?: string;
22
+ /** Optionally switch to a specific proof before showing the app */
23
+ proofId?: string;
24
+ }
25
+ /**
26
+ * Standard props received by every SmartLinks widget and container.
27
+ *
28
+ * These are passed by the parent platform (portal shell, OrchestratedPortal,
29
+ * or a custom host) when mounting a widget or container component.
30
+ *
31
+ * **`SL` type note:** at runtime `SL` is the fully-initialised
32
+ * `@proveanything/smartlinks` SDK instance. It is typed as
33
+ * `Record<string, unknown>` here to avoid a circular self-import; cast to
34
+ * a more specific type in your app code if needed.
35
+ */
36
+ export interface SmartLinksWidgetProps {
37
+ /** Collection context — required */
38
+ collectionId: string;
39
+ /** App identifier — required */
40
+ appId: string;
41
+ /** Product context — present when the portal is scoped to a product */
42
+ productId?: string;
43
+ /** Proof (scan/instance) context */
44
+ proofId?: string;
45
+ /** Authenticated user info, if the viewer is logged in */
46
+ user?: {
47
+ id?: string;
48
+ email?: string;
49
+ name?: string;
50
+ admin?: boolean;
51
+ };
52
+ /**
53
+ * Pre-initialised SmartLinks SDK instance provided by the parent platform.
54
+ * At runtime this is `typeof import('@proveanything/smartlinks')`.
55
+ */
56
+ SL: Record<string, unknown>;
57
+ /**
58
+ * Navigation callback. Emit a `NavigationRequest` to ask the parent
59
+ * platform to navigate to another app. A legacy plain-string path is also
60
+ * accepted for backward compatibility.
61
+ */
62
+ onNavigate?: (request: NavigationRequest | string) => void;
63
+ /** Base URL of the full public portal, used for constructing deep links */
64
+ publicPortalUrl?: string;
65
+ /** Responsive size hint */
66
+ size?: 'compact' | 'standard' | 'large';
67
+ /** BCP-47 language code (e.g. `'en'`, `'fr'`) */
68
+ lang?: string;
69
+ /** Translation key overrides */
70
+ translations?: Record<string, string>;
71
+ }
@@ -0,0 +1,2 @@
1
+ // src/types/widgets.ts
2
+ export {};
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.9.16 | Generated: 2026-04-13T17:25:57.673Z
3
+ Version: 1.9.19 | Generated: 2026-04-16T12:41:11.180Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -1957,22 +1957,51 @@ interface RelatedResponse {
1957
1957
  **PublicCreatePolicy** (interface)
1958
1958
  ```typescript
1959
1959
  interface PublicCreatePolicy {
1960
- cases?: PublicCreateRule
1961
- threads?: PublicCreateRule
1962
- records?: PublicCreateRule
1960
+ cases?: PublicCreateObjectRule
1961
+ threads?: PublicCreateObjectRule
1962
+ records?: PublicCreateObjectRule
1963
1963
  }
1964
1964
  ```
1965
1965
 
1966
- **PublicCreateRule** (interface)
1966
+ **PublicCreateObjectRule** (interface)
1967
1967
  ```typescript
1968
- interface PublicCreateRule {
1969
- allow: {
1970
- anonymous?: boolean
1971
- authenticated?: boolean
1972
- }
1968
+ interface PublicCreateObjectRule {
1969
+ anonymous?: PublicCreateBranch
1970
+ authenticated?: PublicCreateBranch
1971
+ }
1972
+ ```
1973
+
1974
+ **PublicCreateBranch** (interface)
1975
+ ```typescript
1976
+ interface PublicCreateBranch {
1977
+ allow: boolean
1978
+ * Field values merged **over** the caller's request body before writing.
1979
+ * Use this to lock down `visibility` and `status` regardless of what the
1980
+ * client sends.
1973
1981
  enforce?: {
1974
- anonymous?: Partial<CreateCaseInput | CreateThreadInput | CreateRecordInput>
1975
- authenticated?: Partial<CreateCaseInput | CreateThreadInput | CreateRecordInput>
1982
+ visibility?: 'public' | 'owner' | 'admin'
1983
+ status?: string
1984
+ }
1985
+ * Anonymous edit-token configuration.
1986
+ * **Records only** — ignored for cases and threads.
1987
+ *
1988
+ * When `editToken: true`, the server generates a one-time 256-bit hex token
1989
+ * on anonymous record creation, stores it in `admin.editToken` (never
1990
+ * exposed to public / owner responses), and returns it **once** in the
1991
+ * creation response under the `editToken` key.
1992
+ *
1993
+ * The client can then pass that token as the `X-Edit-Token` header on
1994
+ * `PATCH /records/:recordId` to amend the `data` zone without
1995
+ * authentication.
1996
+ *
1997
+ * @see {@link CreateRecordResponse} — creation response shape
1998
+ * @see {@link records.updateWithToken} — SDK method for the amendment call
1999
+ edit?: {
2000
+ editToken: boolean
2001
+ * Optional expiry window in minutes from `createdAt`.
2002
+ * After this many minutes the token is rejected with HTTP 403
2003
+ * `EDIT_WINDOW_EXPIRED`. Omit for no expiry.
2004
+ windowMinutes?: number
1976
2005
  }
1977
2006
  }
1978
2007
  ```
@@ -6654,6 +6683,46 @@ interface TranslationUpdateRequest {
6654
6683
 
6655
6684
  **VariantUpdateRequest** = `any`
6656
6685
 
6686
+ ### widgets
6687
+
6688
+ **NavigationRequest** (interface)
6689
+ ```typescript
6690
+ interface NavigationRequest {
6691
+ appId: string
6692
+ deepLink?: string
6693
+ params?: Record<string, string>
6694
+ productId?: string
6695
+ proofId?: string
6696
+ }
6697
+ ```
6698
+
6699
+ **SmartLinksWidgetProps** (interface)
6700
+ ```typescript
6701
+ interface SmartLinksWidgetProps {
6702
+ collectionId: string
6703
+ appId: string
6704
+ productId?: string
6705
+ proofId?: string
6706
+ user?: {
6707
+ id?: string
6708
+ email?: string
6709
+ name?: string
6710
+ admin?: boolean
6711
+ }
6712
+ * Pre-initialised SmartLinks SDK instance provided by the parent platform.
6713
+ * At runtime this is `typeof import('@proveanything/smartlinks')`.
6714
+ SL: Record<string, unknown>
6715
+ * Navigation callback. Emit a `NavigationRequest` to ask the parent
6716
+ * platform to navigate to another app. A legacy plain-string path is also
6717
+ * accepted for backward compatibility.
6718
+ onNavigate?: (request: NavigationRequest | string) => void
6719
+ publicPortalUrl?: string
6720
+ size?: 'compact' | 'standard' | 'large'
6721
+ lang?: string
6722
+ translations?: Record<string, string>
6723
+ }
6724
+ ```
6725
+
6657
6726
  ### appConfiguration (api)
6658
6727
 
6659
6728
  **AppConfigOptions** (type)
@@ -7024,8 +7093,8 @@ General-purpose structured app objects. Use these when a simple scoped data item
7024
7093
  **create**(collectionId: string,
7025
7094
  appId: string,
7026
7095
  input: CreateRecordInput,
7027
- admin: boolean = false) → `Promise<AppRecord>`
7028
- Create a new record POST /records
7096
+ admin: boolean = false) → `Promise<CreateRecordResponse>`
7097
+ Create a new record POST /records When called on the public endpoint (admin = false) with an anonymous caller, and the app's `publicCreate.records.anonymous.edit.editToken` policy is enabled, the response includes a one-time `editToken` string. Store it immediately — it is never returned again.
7029
7098
 
7030
7099
  **list**(collectionId: string,
7031
7100
  appId: string,
@@ -7046,6 +7115,13 @@ Get a single record by ID GET /records/:recordId
7046
7115
  admin: boolean = false) → `Promise<AppRecord>`
7047
7116
  Update a record PATCH /records/:recordId Admin can update any field, public (owner) can only update data and owner
7048
7117
 
7118
+ **updateWithToken**(collectionId: string,
7119
+ appId: string,
7120
+ recordId: string,
7121
+ data: Record<string, unknown>,
7122
+ editToken: string) → `Promise<AppRecord>`
7123
+ Amend the `data` zone of a record using an anonymous edit token. PATCH /records/:recordId (public endpoint, no auth) This is the follow-up call after an anonymous `create()` that returned an `editToken`. Present the token via `X-Edit-Token` — the server validates it with a constant-time comparison and, if `windowMinutes` is configured in the policy, checks that the token has not expired. **Scope:** only the `data` zone may be modified via this path. `owner`, `admin`, `status`, `visibility`, and indexed fields are immutable to anonymous token holders. ```ts const record = await app.records.create(collectionId, appId, { recordType: 'payment', visibility: 'public', data: { amount: 9900, currency: 'USD' }, }) const { editToken } = record // store this immediately! // Later, once the payment gateway confirms: const updated = await app.records.updateWithToken( collectionId, appId, record.id, { amount: 9900, currency: 'USD', transactionId: 'txn_abc123' }, editToken, ) ``` ### Error codes | HTTP | `errorCode` | Meaning | |------|-----------------------|---------------------------------------------------| | 401 | `UNAUTHORIZED` | No auth token and no `X-Edit-Token` header | | 403 | `FORBIDDEN` | Policy not enabled, or token does not match | | 403 | `EDIT_WINDOW_EXPIRED` | `windowMinutes` elapsed since record creation | | 404 | `NOT_FOUND` | Record does not exist |
7124
+
7049
7125
  **remove**(collectionId: string,
7050
7126
  appId: string,
7051
7127
  recordId: string,
@@ -576,47 +576,81 @@ const usageStats = await app.records.aggregate(collectionId, appId, {
576
576
 
577
577
  ## Public Create Policies
578
578
 
579
- Control who can create objects on **public endpoints** by setting a `publicCreate` policy on your app's config. This is a `publicCreate` field inside your app config object (identified by `appId` within your collection).
579
+ Control who can create objects on **public endpoints** by setting a `publicCreate` policy on your app's config document (identified by `appId` within your collection).
580
+
581
+ Set the policy via:
582
+ ```
583
+ POST /api/v1/admin/collection/:collectionId/apps/:appId
584
+ ```
585
+
586
+ The server reads this document at request time — no cache invalidation or service restart is required.
580
587
 
581
588
  ### Policy Structure
582
589
 
590
+ Each object type (`cases`, `threads`, `records`) has **independent branches** for anonymous and authenticated callers. Each branch carries its own `allow` flag, optional field overrides (`enforce`), and — for records — optional edit-token config (`edit`).
591
+
583
592
  ```typescript
584
593
  interface PublicCreatePolicy {
585
- cases?: {
586
- allow: {
587
- anonymous?: boolean // allow unauthenticated users
588
- authenticated?: boolean // allow authenticated contacts
589
- }
590
- enforce?: {
591
- anonymous?: Partial<CreateCaseInput> // force these values for anon
592
- authenticated?: Partial<CreateCaseInput> // force these values for auth
593
- }
594
+ cases?: PublicCreateObjectRule
595
+ threads?: PublicCreateObjectRule
596
+ records?: PublicCreateObjectRule
597
+ }
598
+
599
+ interface PublicCreateObjectRule {
600
+ anonymous?: PublicCreateBranch
601
+ authenticated?: PublicCreateBranch
602
+ }
603
+
604
+ interface PublicCreateBranch {
605
+ /** Whether creation is permitted for this caller class */
606
+ allow: boolean
607
+
608
+ /**
609
+ * Hard overrides merged over the caller's body before writing.
610
+ * Lock down visibility and status regardless of what clients send.
611
+ */
612
+ enforce?: {
613
+ visibility?: 'public' | 'owner' | 'admin'
614
+ status?: string
615
+ }
616
+
617
+ /**
618
+ * Anonymous edit-token config — records only.
619
+ * See "Anonymous Edit Tokens" section below.
620
+ */
621
+ edit?: {
622
+ editToken: boolean
623
+ windowMinutes?: number // omit for no expiry
594
624
  }
595
- threads?: { /* same structure */ }
596
- records?: { /* same structure */ }
597
625
  }
598
626
  ```
599
627
 
628
+ #### Visibility enforcement guard-rails
629
+
630
+ The server silently corrects misconfigured visibility values:
631
+
632
+ | Caller type | `enforce.visibility` supplied | Server overrides to |
633
+ |-----------------|-------------------------------|---------------------|
634
+ | `anonymous` | `'owner'` | `'admin'` |
635
+ | `authenticated` | `'public'` | `'owner'` |
636
+
637
+ These guards exist because anonymous callers have no identity to own a record, and `'public'` visibility on authenticated-only objects would be a misconfiguration.
638
+
600
639
  ### Example Policies
601
640
 
602
641
  **Support tickets from anyone:**
603
642
 
604
643
  ```json
605
644
  {
606
- "cases": {
607
- "allow": {
608
- "anonymous": true,
609
- "authenticated": true
610
- },
611
- "enforce": {
645
+ "publicCreate": {
646
+ "cases": {
612
647
  "anonymous": {
613
- "visibility": "owner",
614
- "status": "open",
615
- "category": "support"
648
+ "allow": true,
649
+ "enforce": { "visibility": "public", "status": "open" }
616
650
  },
617
651
  "authenticated": {
618
- "visibility": "owner",
619
- "status": "open"
652
+ "allow": true,
653
+ "enforce": { "visibility": "owner", "status": "open" }
620
654
  }
621
655
  }
622
656
  }
@@ -627,15 +661,35 @@ interface PublicCreatePolicy {
627
661
 
628
662
  ```json
629
663
  {
630
- "threads": {
631
- "allow": {
632
- "anonymous": false,
633
- "authenticated": true
634
- },
635
- "enforce": {
664
+ "publicCreate": {
665
+ "threads": {
666
+ "anonymous": { "allow": false },
636
667
  "authenticated": {
637
- "visibility": "public",
638
- "status": "open"
668
+ "allow": true,
669
+ "enforce": { "visibility": "public", "status": "open" }
670
+ }
671
+ }
672
+ }
673
+ }
674
+ ```
675
+
676
+ **Anonymous record creation with edit token (30-minute window):**
677
+
678
+ ```json
679
+ {
680
+ "publicCreate": {
681
+ "records": {
682
+ "anonymous": {
683
+ "allow": true,
684
+ "enforce": { "visibility": "public", "status": "pending" },
685
+ "edit": {
686
+ "editToken": true,
687
+ "windowMinutes": 30
688
+ }
689
+ },
690
+ "authenticated": {
691
+ "allow": true,
692
+ "enforce": { "visibility": "owner", "status": "pending" }
639
693
  }
640
694
  }
641
695
  }
@@ -646,16 +700,113 @@ interface PublicCreatePolicy {
646
700
 
647
701
  ```json
648
702
  {
649
- "records": {
650
- "allow": {
651
- "anonymous": false,
652
- "authenticated": false
703
+ "publicCreate": {
704
+ "records": {
705
+ "anonymous": { "allow": false },
706
+ "authenticated": { "allow": false }
653
707
  }
654
708
  }
655
709
  }
656
710
  ```
657
711
 
658
- The `enforce` values are **merged over** the caller's request body, so you can lock down fields like `visibility`, `status`, or `category` regardless of what clients send.
712
+ The `enforce` values are **merged over** the caller's request body, so you can lock down fields like `visibility` and `status` regardless of what clients send.
713
+
714
+ ---
715
+
716
+ ## Anonymous Edit Tokens
717
+
718
+ Enables an anonymous caller to amend a record they just created — without authentication — by presenting a short-lived secret token.
719
+
720
+ Designed for flows where a client needs to make a follow-up update before a server-side process locks the record. Common examples: payment + confirmation, multi-step forms, IoT device registration.
721
+
722
+ ### How It Works
723
+
724
+ ```
725
+ 1. Configure — set publicCreate.records.anonymous.edit.editToken: true in app config
726
+ 2. Create — anonymous POST /records returns { ...record, editToken: "3f8a2c1e..." }
727
+ Token is stored in record's admin zone; never visible again
728
+ 3. Amend — PATCH /records/:recordId with X-Edit-Token header
729
+ Only the data zone may be modified
730
+ 4. Expiry — if windowMinutes is set, token is rejected after that many minutes
731
+ ```
732
+
733
+ ### SDK Usage
734
+
735
+ ```typescript
736
+ import { app } from '@proveanything/smartlinks';
737
+
738
+ // Step 1: Create the record (anonymous caller — no auth token)
739
+ const response = await app.records.create(collectionId, appId, {
740
+ recordType: 'payment',
741
+ visibility: 'public',
742
+ data: { amount: 9900, currency: 'USD' },
743
+ })
744
+
745
+ // editToken is present only when the policy has editToken: true
746
+ const { editToken } = response // ⚠️ store immediately — returned once only
747
+
748
+ // Step 2: After external confirmation (e.g. payment gateway callback)
749
+ const updated = await app.records.updateWithToken(
750
+ collectionId,
751
+ appId,
752
+ response.id,
753
+ { amount: 9900, currency: 'USD', transactionId: 'txn_abc123' },
754
+ editToken,
755
+ )
756
+ ```
757
+
758
+ `app.records.updateWithToken()` sends the token as the `X-Edit-Token` request header on the public PATCH endpoint — no auth token needed.
759
+
760
+ ### Creation Response Shape
761
+
762
+ ```typescript
763
+ interface CreateRecordResponse extends AppRecord {
764
+ /**
765
+ * Present only on anonymous creation when editToken policy is enabled.
766
+ * Returned ONCE — store it client-side immediately.
767
+ */
768
+ editToken?: string
769
+ }
770
+ ```
771
+
772
+ Example creation response:
773
+
774
+ ```json
775
+ {
776
+ "id": "a1b2c3d4-...",
777
+ "recordType": "payment",
778
+ "status": "pending",
779
+ "visibility": "public",
780
+ "data": { "amount": 9900, "currency": "USD" },
781
+ "createdAt": "2026-04-16T12:00:00.000Z",
782
+ "editToken": "3f8a2c1e..."
783
+ }
784
+ ```
785
+
786
+ ### Amendment Scope
787
+
788
+ Anonymous token updates may only modify the **`data` zone**. The following are immutable via this path:
789
+
790
+ - `owner`, `admin` zones
791
+ - `status`, `visibility`
792
+ - All indexed fields (`recordType`, `ref`, `startsAt`, `expiresAt`, etc.)
793
+
794
+ ### Error Codes
795
+
796
+ | HTTP | `errorCode` | Meaning |
797
+ |------|------------------------|--------------------------------------------------|
798
+ | 401 | `UNAUTHORIZED` | No auth token and no `X-Edit-Token` header |
799
+ | 403 | `FORBIDDEN` | `editToken` policy not enabled for this app |
800
+ | 403 | `FORBIDDEN` | Token does not match |
801
+ | 403 | `EDIT_WINDOW_EXPIRED` | `windowMinutes` elapsed since record creation |
802
+ | 404 | `NOT_FOUND` | Record does not exist |
803
+
804
+ ### Security Notes
805
+
806
+ - The token is stored in `admin.editToken` and is **always stripped** from public and owner responses — it cannot be read back after creation.
807
+ - Token comparison uses `crypto.timingSafeEqual` to prevent timing-based oracle attacks.
808
+ - The token is a 32-byte (`crypto.randomBytes(32)`) hex string — 256 bits of entropy.
809
+ - For sensitive flows, combine `windowMinutes` with a server-side process that removes or overwrites the token once the record is confirmed.
659
810
 
660
811
  ---
661
812