@proveanything/smartlinks 1.9.19 → 1.9.21

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.
@@ -93,7 +93,7 @@ function summarizeConditionSet(condition) {
93
93
  return `${(_a = condition.type) !== null && _a !== void 0 ? _a : 'and'} (${(_c = (_b = condition.conditions) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0} conditions)`;
94
94
  }
95
95
  function summarizeCondition(condition) {
96
- var _a, _b;
96
+ var _a, _b, _c, _d, _e;
97
97
  switch (condition.type) {
98
98
  case 'country':
99
99
  return `country regions=${((_a = condition.regions) === null || _a === void 0 ? void 0 : _a.join(',')) || 'none'} countries=${((_b = condition.countries) === null || _b === void 0 ? void 0 : _b.join(',')) || 'none'} contains=${condition.contains}`;
@@ -115,6 +115,11 @@ function summarizeCondition(condition) {
115
115
  return `geofence contains=${condition.contains}`;
116
116
  case 'value':
117
117
  return `value field=${condition.field} ${condition.validationType} ${String(condition.value)}`;
118
+ case 'facet': {
119
+ const mode = (_c = condition.matchMode) !== null && _c !== void 0 ? _c : 'any';
120
+ const vals = (_e = (_d = condition.values) === null || _d === void 0 ? void 0 : _d.join(', ')) !== null && _e !== void 0 ? _e : '—';
121
+ return `facet key=${condition.facetKey} mode=${mode} values=[${vals}]`;
122
+ }
118
123
  case 'itemStatus':
119
124
  return `itemStatus ${condition.statusType}`;
120
125
  default:
@@ -143,6 +148,8 @@ async function evaluateConditionEntry(condition, params) {
143
148
  return validateGeofence(condition, params);
144
149
  case 'value':
145
150
  return validateValue(condition, params);
151
+ case 'facet':
152
+ return validateFacet(condition, params);
146
153
  case 'itemStatus':
147
154
  return validateItemStatus(condition, params);
148
155
  default:
@@ -162,6 +169,7 @@ async function evaluateConditionEntry(condition, params) {
162
169
  * - **user** - User authentication status (logged in, owner, admin)
163
170
  * - **product** - Product-specific conditions
164
171
  * - **tag** - Product tag-based conditions
172
+ * - **facet** - Product facet-based conditions (any/all/none of specific facet values)
165
173
  * - **date** - Time-based conditions (before, after, between dates)
166
174
  * - **geofence** - Location-based restrictions
167
175
  * - **value** - Custom field comparisons
@@ -730,6 +738,82 @@ async function validateValue(condition, params) {
730
738
  },
731
739
  };
732
740
  }
741
+ /**
742
+ * Validate facet-based condition
743
+ */
744
+ async function validateFacet(condition, params) {
745
+ var _a, _b, _c;
746
+ const { facetKey, matchMode = 'any', values = [] } = condition;
747
+ const facets = (_a = params.product) === null || _a === void 0 ? void 0 : _a.facets;
748
+ // No product
749
+ if (!((_b = params.product) === null || _b === void 0 ? void 0 : _b.id)) {
750
+ return {
751
+ passed: false,
752
+ detail: 'Product ID was not available.',
753
+ context: { facetKey, matchMode },
754
+ };
755
+ }
756
+ const assigned = (_c = facets === null || facets === void 0 ? void 0 : facets[facetKey]) !== null && _c !== void 0 ? _c : [];
757
+ const assignedKeys = assigned.map(v => v.key);
758
+ // Presence-only modes — ignore `values`
759
+ if (matchMode === 'hasFacet') {
760
+ return {
761
+ passed: assignedKeys.length > 0,
762
+ detail: `Product ${assigned.length > 0 ? 'has' : 'does not have'} values on facet '${facetKey}'.`,
763
+ context: { facetKey, assignedKeys },
764
+ };
765
+ }
766
+ if (matchMode === 'notHasFacet') {
767
+ return {
768
+ passed: assignedKeys.length === 0,
769
+ detail: `Product ${assigned.length === 0 ? 'has no' : 'has'} values on facet '${facetKey}'.`,
770
+ context: { facetKey, assignedKeys },
771
+ };
772
+ }
773
+ // Value-matching modes require at least one value to test
774
+ if (values.length === 0) {
775
+ return {
776
+ passed: false,
777
+ detail: `Facet condition for '${facetKey}' with matchMode '${matchMode}' requires at least one value.`,
778
+ context: { facetKey, matchMode },
779
+ };
780
+ }
781
+ if (matchMode === 'any') {
782
+ const matched = values.filter(v => assignedKeys.includes(v));
783
+ return {
784
+ passed: matched.length > 0,
785
+ detail: matched.length > 0
786
+ ? `Product matched facet '${facetKey}' value(s): [${matched.join(', ')}].`
787
+ : `Product did not match any of [${values.join(', ')}] on facet '${facetKey}'.`,
788
+ context: { facetKey, matchMode, testedValues: values, matched, assignedKeys },
789
+ };
790
+ }
791
+ if (matchMode === 'all') {
792
+ const missing = values.filter(v => !assignedKeys.includes(v));
793
+ return {
794
+ passed: missing.length === 0,
795
+ detail: missing.length === 0
796
+ ? `Product has all required values on facet '${facetKey}'.`
797
+ : `Product is missing [${missing.join(', ')}] on facet '${facetKey}'.`,
798
+ context: { facetKey, matchMode, testedValues: values, missing, assignedKeys },
799
+ };
800
+ }
801
+ if (matchMode === 'none') {
802
+ const matched = values.filter(v => assignedKeys.includes(v));
803
+ return {
804
+ passed: matched.length === 0,
805
+ detail: matched.length === 0
806
+ ? `Product correctly has none of [${values.join(', ')}] on facet '${facetKey}'.`
807
+ : `Product has forbidden value(s) [${matched.join(', ')}] on facet '${facetKey}'.`,
808
+ context: { facetKey, matchMode, testedValues: values, matched, assignedKeys },
809
+ };
810
+ }
811
+ return {
812
+ passed: false,
813
+ detail: `Unsupported facet matchMode '${matchMode}'.`,
814
+ context: { facetKey, matchMode },
815
+ };
816
+ }
733
817
  /**
734
818
  * Validate item status condition
735
819
  */
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.9.19 | Generated: 2026-04-16T12:41:11.180Z
3
+ Version: 1.9.21 | Generated: 2026-04-25T10:48:10.932Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -2994,6 +2994,8 @@ interface Collection {
2994
2994
  secondaryColor?: string
2995
2995
  portalUrl?: string // URL for the collection's portal (if applicable)
2996
2996
  allowAutoGenerateClaims?: boolean
2997
+ variants: boolean // does this collection support variants?
2998
+ batches: boolean // does this collection support batches?
2997
2999
  defaultAuthKitId: string // default auth kit for this collection, used for auth
2998
3000
  }
2999
3001
  ```
@@ -6847,6 +6849,18 @@ interface UserInfo {
6847
6849
  interface ProductInfo {
6848
6850
  id: string
6849
6851
  tags?: Record<string, any>
6852
+ * Facet values assigned to this product.
6853
+ * Shape mirrors `ProductFacetMap`: a map of facet key → array of value objects.
6854
+ * Each value object must have at minimum a `key` string property.
6855
+ *
6856
+ * @example
6857
+ * ```ts
6858
+ * {
6859
+ * material: [{ key: 'cotton', name: 'Cotton' }],
6860
+ * certifications: [{ key: 'organic', name: 'Organic' }, { key: 'recycled', name: 'Recycled' }]
6861
+ * }
6862
+ * ```
6863
+ facets?: Record<string, Array<{ key: string; [k: string]: unknown }>>
6850
6864
  }
6851
6865
  ```
6852
6866
 
@@ -95,7 +95,20 @@ The manifest is loaded automatically by the platform for every collection page.
95
95
  { "title": "Home", "path": "/" },
96
96
  { "title": "Gallery", "path": "/gallery" },
97
97
  { "title": "Settings", "path": "/settings", "params": { "tab": "advanced" } }
98
- ]
98
+ ],
99
+
100
+ "records": {
101
+ "nutrition": {
102
+ "scopes": ["product", "facet", "batch"],
103
+ "defaultScope": "facet",
104
+ "label": "Nutrition info"
105
+ },
106
+ "cooking_steps": {
107
+ "scopes": ["product", "facet"],
108
+ "defaultScope": "product",
109
+ "label": "Cooking steps"
110
+ }
111
+ }
99
112
  }
100
113
  ```
101
114
 
@@ -188,6 +201,30 @@ See the [Deep Link Discovery guide](deep-link-discovery.md) for the full dual-so
188
201
  | `path` | string | ❌ | Hash route within the app (defaults to `"/"` if omitted) |
189
202
  | `params` | object | ❌ | App-specific query params appended to the URL — do **not** include platform params (`collectionId`, `productId`, etc.) |
190
203
 
204
+ #### `records`
205
+
206
+ Declares which `app.records` record types the app stores, and which scopes each type supports. Required for any app that follows the [Records-Based Admin Pattern](records-admin-pattern.md). Omit if the app does not use scoped records.
207
+
208
+ The platform and the `<RecordsAdminShell>` from `@proveanything/ui-utils` read this block to render only the relevant tabs and affordances.
209
+
210
+ ```json
211
+ "records": {
212
+ "<recordType>": {
213
+ "scopes": ["product", "facet", "batch"],
214
+ "defaultScope": "facet",
215
+ "label": "Human-readable label"
216
+ }
217
+ }
218
+ ```
219
+
220
+ | Field | Type | Required | Description |
221
+ |----------------|----------|----------|-------------|
222
+ | `scopes` | string[] | ✅ | Allowed scope kinds in resolution order. Valid values: `"product"`, `"variant"`, `"batch"`, `"facet"`, `"proof"`, `"default"`. |
223
+ | `defaultScope` | string | ✅ | The scope the "Create new" button targets in the admin shell. Must be one of the declared `scopes`. |
224
+ | `label` | string | ✅ | Human-readable label for the record type, used in headings and tabs. |
225
+
226
+ An app may declare multiple record types under different keys (e.g. `"nutrition"` and `"cooking_steps"`).
227
+
191
228
  #### `executor`
192
229
 
193
230
  Declares the executor bundle — a standalone JS library for programmatic configuration, server-side SEO, and LLM content generation. Omit if the app has no executor.
@@ -0,0 +1,162 @@
1
+ # SmartLinks Auth Kit (`@proveanything/smartlinks` — `authKit` namespace)
2
+
3
+ > End-user authentication flows for SmartLinks microapps. Covers email/password, magic links, phone OTP, Google OAuth, profile management, and password/email change flows.
4
+ >
5
+ > **This is part of the core SDK** — no separate install required. Import from `@proveanything/smartlinks`.
6
+
7
+ ---
8
+
9
+ ## What is Auth Kit for?
10
+
11
+ Auth Kit is the **end-user identity layer** for microapps that need users to sign in. It is distinct from the admin/platform authentication (Bearer tokens) used to call admin endpoints.
12
+
13
+ Use Auth Kit when:
14
+ - Your app has a login/register screen for end users (not collection admins)
15
+ - You need to gate features behind a verified user identity
16
+ - You want to store user-specific data with the `userAppData` API (see [app-data-storage.md](app-data-storage.md))
17
+
18
+ Do **not** use Auth Kit for:
19
+ - Admin-side API calls (those use Bearer tokens set by the platform shell)
20
+ - Claiming proofs (see proof claiming methods)
21
+
22
+ ---
23
+
24
+ ## Setup: creating an Auth Kit client
25
+
26
+ Each app requires an Auth Kit configuration, created by a collection admin:
27
+
28
+ ```ts
29
+ // Admin setup (one-time, done in admin console)
30
+ import { authKit } from '@proveanything/smartlinks';
31
+
32
+ // Returns an authKitId to store in your app config
33
+ const config = await authKit.create(collectionId, {
34
+ name: 'My App Auth',
35
+ loginMethods: ['email', 'google', 'magic_link'],
36
+ redirectUrl: 'https://myapp.example.com/auth/callback',
37
+ });
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Key flows
43
+
44
+ ### Email / password
45
+
46
+ ```ts
47
+ import { authKit } from '@proveanything/smartlinks';
48
+
49
+ // Register
50
+ const session = await authKit.register(clientId, {
51
+ email: 'user@example.com',
52
+ password: 'securePassword123',
53
+ displayName: 'Alice',
54
+ });
55
+
56
+ // Login
57
+ const session = await authKit.login(clientId, 'user@example.com', 'securePassword123');
58
+
59
+ // session.token — store this; pass to initializeApi for subsequent calls
60
+ ```
61
+
62
+ ### Magic link (passwordless email)
63
+
64
+ ```ts
65
+ await authKit.sendMagicLink(clientId, {
66
+ email: 'user@example.com',
67
+ redirectUrl: 'https://myapp.example.com/auth/verify',
68
+ });
69
+
70
+ // On callback page, extract token from URL and verify
71
+ const session = await authKit.verifyMagicLink(clientId, tokenFromUrl);
72
+ ```
73
+
74
+ ### Phone OTP
75
+
76
+ ```ts
77
+ await authKit.sendPhoneCode(clientId, '+61400000000');
78
+ const session = await authKit.verifyPhoneCode(clientId, '+61400000000', '123456');
79
+ ```
80
+
81
+ ### Google OAuth
82
+
83
+ ```ts
84
+ // After Google sign-in, pass the id_token to Auth Kit
85
+ const session = await authKit.googleLogin(clientId, googleIdToken);
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Profile management
91
+
92
+ ```ts
93
+ import { authKit } from '@proveanything/smartlinks';
94
+
95
+ // Get current user's profile
96
+ const profile = await authKit.getProfile(clientId);
97
+
98
+ // Update profile
99
+ await authKit.updateProfile(clientId, { displayName: 'Alice B.', avatarUrl: '...' });
100
+
101
+ // Change password
102
+ await authKit.changePassword(clientId, 'currentPass', 'newPass');
103
+
104
+ // Change email (triggers verification)
105
+ await authKit.changeEmail(clientId, 'newemail@example.com', 'password', redirectUrl);
106
+
107
+ // Delete account
108
+ await authKit.deleteAccount(clientId, 'password', 'DELETE');
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Email verification
114
+
115
+ Auth Kit can send and verify email addresses after registration:
116
+
117
+ ```ts
118
+ await authKit.sendEmailVerification(clientId, {
119
+ userId,
120
+ email: 'user@example.com',
121
+ redirectUrl: 'https://myapp.example.com/auth/verified',
122
+ });
123
+
124
+ // On callback page
125
+ await authKit.verifyEmail(clientId, tokenFromUrl);
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Password reset
131
+
132
+ ```ts
133
+ await authKit.requestPasswordReset(clientId, {
134
+ email: 'user@example.com',
135
+ redirectUrl: 'https://myapp.example.com/auth/reset',
136
+ clientName: 'My App',
137
+ });
138
+
139
+ // On reset page — verify token is still valid before showing the form
140
+ await authKit.verifyResetToken(clientId, tokenFromUrl);
141
+
142
+ // Complete reset
143
+ await authKit.completePasswordReset(clientId, tokenFromUrl, 'newSecurePassword');
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Relationship to other parts of the SDK
149
+
150
+ | Concern | Where it lives |
151
+ |---------|---------------|
152
+ | End-user sign-in / register | `authKit` namespace (this doc) |
153
+ | Admin Bearer token auth | Platform shell — not set by your app |
154
+ | Per-user data storage | `userAppData` namespace — see [app-data-storage.md](app-data-storage.md) |
155
+ | User identity in analytics | `userId` field on `analytics` and `interactions` calls |
156
+
157
+ ---
158
+
159
+ ## Further reading
160
+
161
+ - [app-data-storage.md](app-data-storage.md) — storing user-specific data after login
162
+ - [app-manifest.md](app-manifest.md) — `app.admin.json` setup questions for configuring `clientId`
package/docs/forms.md ADDED
@@ -0,0 +1,113 @@
1
+ # SmartLinks Forms
2
+
3
+ > Platform-managed form definitions and submissions. Covers the `form` data API (core SDK) and the `@proveanything/ui-forms` React package for schema-driven form UIs.
4
+
5
+ ---
6
+
7
+ ## Two layers
8
+
9
+ | Layer | Package | What it does |
10
+ |-------|---------|--------------|
11
+ | **Forms data API** | `@proveanything/smartlinks` (`form` namespace) | CRUD for form definitions; stores submission schema |
12
+ | **Forms UI** | `@proveanything/ui-forms` | React components that render a form definition, validate input, and submit |
13
+
14
+ You can use the data API without the UI package (e.g. in an executor), but the UI package requires both.
15
+
16
+ ---
17
+
18
+ ## Forms data API (`form` namespace)
19
+
20
+ The `form` namespace in the core SDK manages **form definitions** — the schema that describes fields, validation rules, and submission behaviour. This is an admin-side API.
21
+
22
+ ```ts
23
+ import { form } from '@proveanything/smartlinks';
24
+
25
+ // List all forms in a collection
26
+ const forms = await form.list(collectionId, /* admin= */ true);
27
+
28
+ // Get a specific form
29
+ const myForm = await form.get(collectionId, formId);
30
+
31
+ // Create a form (admin)
32
+ const created = await form.create(collectionId, {
33
+ name: 'Warranty Registration',
34
+ fields: [
35
+ { id: 'name', type: 'text', label: 'Full name', required: true },
36
+ { id: 'email', type: 'email', label: 'Email address', required: true },
37
+ { id: 'serial', type: 'text', label: 'Serial number', required: true },
38
+ { id: 'receipt', type: 'file', label: 'Proof of purchase' },
39
+ ],
40
+ });
41
+
42
+ // Update a form (admin)
43
+ await form.update(collectionId, formId, { name: 'Warranty Registration v2' });
44
+
45
+ // Delete a form (admin)
46
+ await form.remove(collectionId, formId);
47
+ ```
48
+
49
+ Form definitions are stored per-collection and referenced by `formId`.
50
+
51
+ ---
52
+
53
+ ## Forms UI (`@proveanything/ui-forms`)
54
+
55
+ `@proveanything/ui-forms` provides React components that consume a form definition from the API and render a complete, accessible, validated form.
56
+
57
+ Install: `npm install @proveanything/ui-forms`
58
+
59
+ ### Rendering a form
60
+
61
+ ```tsx
62
+ import { SmartForm } from '@proveanything/ui-forms';
63
+
64
+ // Fetches the form definition and renders it
65
+ <SmartForm
66
+ collectionId={collectionId}
67
+ formId={formId}
68
+ onSubmit={async (values) => {
69
+ // handle submission — e.g. create an app.records entry or send via comms
70
+ }}
71
+ />
72
+ ```
73
+
74
+ ### Headless usage
75
+
76
+ ```tsx
77
+ import { useFormDefinition, FormRenderer } from '@proveanything/ui-forms';
78
+
79
+ const { fields, isLoading } = useFormDefinition(collectionId, formId);
80
+
81
+ // Render fields yourself using the definition
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Common patterns
87
+
88
+ ### Warranty / registration forms
89
+
90
+ Define the form in `app.admin.json` setup or via the admin API. On the public widget, render with `<SmartForm>` and on submit create an `app.records` entry:
91
+
92
+ ```ts
93
+ onSubmit={async (values) => {
94
+ await app.records.create(collectionId, appId, {
95
+ recordType: 'warranty_registration',
96
+ ref: `proof:${proofId}`,
97
+ data: values,
98
+ });
99
+ }}
100
+ ```
101
+
102
+ ### Competition / feedback forms
103
+
104
+ Same pattern — use `<SmartForm>` for capture and write to `app.records` or trigger an `interactions.appendEvent` on submit.
105
+
106
+ ---
107
+
108
+ ## Further reading
109
+
110
+ - [app-objects.md](app-objects.md) — `app.records` for storing submissions
111
+ - [app-data-storage.md](app-data-storage.md) — choosing the right storage model
112
+ - [interactions.md](interactions.md) — firing events on form submission
113
+ - [comms.md](comms.md) — sending confirmation emails after submission
package/docs/overview.md CHANGED
@@ -64,6 +64,10 @@ The SmartLinks SDK (`@proveanything/smartlinks`) includes comprehensive document
64
64
  | **Liquid Templates** | `docs/liquid-templates.md` | Dynamic content rendering with LiquidJS |
65
65
  | **Iframe Responder** | `docs/iframe-responder.md` | Iframe communication and proxy mode internals |
66
66
  | **AI Guide Template** | `docs/ai-guide-template.md` | Template for creating `public/ai-guide.md` — customise per app |
67
+ | **Forms** | `docs/forms.md` | Form definitions, schema-driven rendering, submission patterns |
68
+ | **Auth Kit** | `docs/auth-kit.md` | End-user sign-in: email/password, magic links, phone OTP, Google OAuth |
69
+ | **Records Admin Pattern** | `docs/records-admin-pattern.md` | Standard pattern for per-product/facet/variant/batch admin UIs |
70
+ | **UI Utils** | `docs/ui-utils.md` | `@proveanything/ui-utils` — React shells, hooks, and primitives for records-based apps |
67
71
 
68
72
  ---
69
73