@proveanything/smartlinks 1.5.6 → 1.6.1
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/contact.d.ts +26 -10
- package/dist/api/contact.js +24 -8
- package/dist/docs/API_SUMMARY.md +54 -28
- package/dist/types/contact.d.ts +107 -40
- package/dist/types/contact.js +60 -26
- package/docs/API_SUMMARY.md +54 -28
- package/package.json +1 -1
package/dist/api/contact.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContactResponse, ContactCreateRequest, ContactUpdateRequest, ContactListResponse, PublicContactUpsertRequest, PublicContactUpsertResponse, UserSearchResponse, ContactPatch, PublicGetMyContactResponse, PublicUpdateMyContactResponse,
|
|
1
|
+
import { ContactResponse, ContactCreateRequest, ContactUpdateRequest, ContactListResponse, PublicContactUpsertRequest, PublicContactUpsertResponse, UserSearchResponse, ContactPatch, PublicGetMyContactResponse, PublicUpdateMyContactResponse, ContactSchemaResponse } from "../types";
|
|
2
2
|
export declare namespace contact {
|
|
3
3
|
function create(collectionId: string, data: ContactCreateRequest): Promise<ContactResponse>;
|
|
4
4
|
function list(collectionId: string, params?: {
|
|
@@ -20,18 +20,34 @@ export declare namespace contact {
|
|
|
20
20
|
function publicGetMine(collectionId: string): Promise<PublicGetMyContactResponse>;
|
|
21
21
|
function publicUpdateMine(collectionId: string, data: ContactPatch): Promise<PublicUpdateMyContactResponse>;
|
|
22
22
|
/**
|
|
23
|
-
* Public: Get contact
|
|
23
|
+
* Public: Get the contact schema for a collection.
|
|
24
|
+
* GET /public/collection/:collectionId/contact/schema
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
* Returns a ContactSchemaResponse describing all publicly visible contact fields.
|
|
27
|
+
* Core fields and collection-defined custom fields are merged into a single flat schema.
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
29
|
+
* Fields not in `publicVisibleFields` are stripped entirely from the response.
|
|
30
|
+
* Fields visible but not in `publicEditableFields` have `ui:disabled: true` in `uiSchema`.
|
|
31
|
+
*
|
|
32
|
+
* Use `fieldOrder` to render fields in the correct sequence, and `evaluateConditions`
|
|
33
|
+
* from the types package to handle conditional field visibility.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { contact, evaluateConditions } from '@proveanything/smartlinks'
|
|
38
|
+
*
|
|
39
|
+
* const schema = await contact.publicGetSchema(collectionId)
|
|
40
|
+
*
|
|
41
|
+
* for (const fieldId of schema.fieldOrder) {
|
|
42
|
+
* const property = schema.schema.properties[fieldId]
|
|
43
|
+
* const ui = schema.uiSchema[fieldId] || {}
|
|
44
|
+
* const visible = evaluateConditions(property.conditions, property.showWhen, formValues)
|
|
45
|
+
* const disabled = ui['ui:disabled'] === true
|
|
46
|
+
* if (visible) renderField({ fieldId, property, ui, disabled })
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
33
49
|
*/
|
|
34
|
-
function publicGetSchema(collectionId: string): Promise<
|
|
50
|
+
function publicGetSchema(collectionId: string): Promise<ContactSchemaResponse>;
|
|
35
51
|
function erase(collectionId: string, contactId: string, body?: any): Promise<ContactResponse>;
|
|
36
52
|
function getUser(collectionId: string, userId: string): Promise<UserSearchResponse>;
|
|
37
53
|
}
|
package/dist/api/contact.js
CHANGED
|
@@ -72,16 +72,32 @@ export var contact;
|
|
|
72
72
|
}
|
|
73
73
|
contact.publicUpdateMine = publicUpdateMine;
|
|
74
74
|
/**
|
|
75
|
-
* Public: Get contact
|
|
75
|
+
* Public: Get the contact schema for a collection.
|
|
76
|
+
* GET /public/collection/:collectionId/contact/schema
|
|
76
77
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
78
|
+
* Returns a ContactSchemaResponse describing all publicly visible contact fields.
|
|
79
|
+
* Core fields and collection-defined custom fields are merged into a single flat schema.
|
|
79
80
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
81
|
+
* Fields not in `publicVisibleFields` are stripped entirely from the response.
|
|
82
|
+
* Fields visible but not in `publicEditableFields` have `ui:disabled: true` in `uiSchema`.
|
|
83
|
+
*
|
|
84
|
+
* Use `fieldOrder` to render fields in the correct sequence, and `evaluateConditions`
|
|
85
|
+
* from the types package to handle conditional field visibility.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { contact, evaluateConditions } from '@proveanything/smartlinks'
|
|
90
|
+
*
|
|
91
|
+
* const schema = await contact.publicGetSchema(collectionId)
|
|
92
|
+
*
|
|
93
|
+
* for (const fieldId of schema.fieldOrder) {
|
|
94
|
+
* const property = schema.schema.properties[fieldId]
|
|
95
|
+
* const ui = schema.uiSchema[fieldId] || {}
|
|
96
|
+
* const visible = evaluateConditions(property.conditions, property.showWhen, formValues)
|
|
97
|
+
* const disabled = ui['ui:disabled'] === true
|
|
98
|
+
* if (visible) renderField({ fieldId, property, ui, disabled })
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
85
101
|
*/
|
|
86
102
|
async function publicGetSchema(collectionId) {
|
|
87
103
|
const path = `/public/collection/${encodeURIComponent(collectionId)}/contact/schema`;
|
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.1 | Generated: 2026-02-26T11:23:15.062Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -2502,36 +2502,64 @@ interface CommsState {
|
|
|
2502
2502
|
**FieldCondition** (interface)
|
|
2503
2503
|
```typescript
|
|
2504
2504
|
interface FieldCondition {
|
|
2505
|
-
|
|
2505
|
+
targetFieldId: string // The field whose value is tested
|
|
2506
2506
|
operator: ConditionOperator
|
|
2507
|
-
value?:
|
|
2507
|
+
value?: unknown // Required for equals / not_equals / contains / not_contains / greater_than / less_than
|
|
2508
2508
|
}
|
|
2509
2509
|
```
|
|
2510
2510
|
|
|
2511
|
-
**
|
|
2511
|
+
**ContactSchemaProperty** (interface)
|
|
2512
2512
|
```typescript
|
|
2513
|
-
interface
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2513
|
+
interface ContactSchemaProperty {
|
|
2514
|
+
type: 'string' | 'number' | 'boolean' | 'array'
|
|
2515
|
+
title?: string
|
|
2516
|
+
description?: string
|
|
2517
|
+
format?: string
|
|
2518
|
+
enum?: string[]
|
|
2519
|
+
* Display labels for `enum` values — parallel array.
|
|
2520
|
+
* `enum[i]` is the stored value; `enumNames[i]` is the display label.
|
|
2521
|
+
* When absent, `enum` values are used as labels.
|
|
2522
|
+
enumNames?: string[]
|
|
2523
|
+
default?: unknown
|
|
2524
|
+
minLength?: number
|
|
2525
|
+
maxLength?: number
|
|
2526
|
+
pattern?: string
|
|
2527
|
+
minimum?: number
|
|
2528
|
+
maximum?: number
|
|
2529
|
+
conditions?: FieldCondition[]
|
|
2530
|
+
showWhen?: 'all' | 'any'
|
|
2531
|
+
}
|
|
2532
|
+
```
|
|
2533
|
+
|
|
2534
|
+
**ContactUiSchemaEntry** (interface)
|
|
2535
|
+
```typescript
|
|
2536
|
+
interface ContactUiSchemaEntry {
|
|
2537
|
+
'ui:disabled'?: true
|
|
2538
|
+
'ui:placeholder'?: string
|
|
2539
|
+
'ui:help'?: string
|
|
2540
|
+
'ui:widget'?: string
|
|
2541
|
+
'ui:options'?: {
|
|
2542
|
+
rows?: number // textarea: number of visible rows
|
|
2543
|
+
accept?: string // file: accepted MIME types
|
|
2544
|
+
label?: boolean // checkbox: show inline label
|
|
2545
|
+
[key: string]: unknown
|
|
2546
|
+
}
|
|
2547
|
+
[key: string]: unknown
|
|
2521
2548
|
}
|
|
2522
2549
|
```
|
|
2523
2550
|
|
|
2524
|
-
**
|
|
2551
|
+
**ContactSchemaResponse** (interface)
|
|
2525
2552
|
```typescript
|
|
2526
|
-
interface
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
publicVisibleFields: string[]
|
|
2532
|
-
publicEditableFields: string[]
|
|
2533
|
-
customFieldsVersion: number
|
|
2553
|
+
interface ContactSchemaResponse {
|
|
2554
|
+
schema: {
|
|
2555
|
+
type: 'object'
|
|
2556
|
+
required?: string[]
|
|
2557
|
+
properties: Record<string, ContactSchemaProperty>
|
|
2534
2558
|
}
|
|
2559
|
+
uiSchema: Record<string, ContactUiSchemaEntry>
|
|
2560
|
+
fieldOrder: string[]
|
|
2561
|
+
settings: Record<string, unknown>
|
|
2562
|
+
styling: Record<string, unknown>
|
|
2535
2563
|
}
|
|
2536
2564
|
```
|
|
2537
2565
|
|
|
@@ -2553,9 +2581,7 @@ interface ContactSchema {
|
|
|
2553
2581
|
|
|
2554
2582
|
**ConditionOperator** = ``
|
|
2555
2583
|
|
|
2556
|
-
**
|
|
2557
|
-
|
|
2558
|
-
**FieldType** = ``
|
|
2584
|
+
**ContactSchema** = `ContactSchemaResponse`
|
|
2559
2585
|
|
|
2560
2586
|
### crate
|
|
2561
2587
|
|
|
@@ -4965,15 +4991,15 @@ Logging: Append many communication events for a list of IDs. POST /admin/collect
|
|
|
4965
4991
|
**publicUpdateMine**(collectionId: string,
|
|
4966
4992
|
data: ContactPatch) → `Promise<PublicUpdateMyContactResponse>`
|
|
4967
4993
|
|
|
4968
|
-
**publicGetSchema**(collectionId: string) → `Promise<
|
|
4969
|
-
Public: Get contact
|
|
4994
|
+
**publicGetSchema**(collectionId: string) → `Promise<ContactSchemaResponse>`
|
|
4995
|
+
Public: Get the contact schema for a collection. GET /public/collection/:collectionId/contact/schema Returns a ContactSchemaResponse describing all publicly visible contact fields. Core fields and collection-defined custom fields are merged into a single flat schema. Fields not in `publicVisibleFields` are stripped entirely from the response. Fields visible but not in `publicEditableFields` have `ui:disabled: true` in `uiSchema`. Use `fieldOrder` to render fields in the correct sequence, and `evaluateConditions` from the types package to handle conditional field visibility. ```typescript import { contact, evaluateConditions } from '@proveanything/smartlinks' const schema = await contact.publicGetSchema(collectionId) for (const fieldId of schema.fieldOrder) { const property = schema.schema.properties[fieldId] const ui = schema.uiSchema[fieldId] || {} const visible = evaluateConditions(property.conditions, property.showWhen, formValues) const disabled = ui['ui:disabled'] === true if (visible) renderField({ fieldId, property, ui, disabled }) } ```
|
|
4970
4996
|
|
|
4971
4997
|
**erase**(collectionId: string, contactId: string, body?: any) → `Promise<ContactResponse>`
|
|
4972
|
-
Public: Get contact
|
|
4998
|
+
Public: Get the contact schema for a collection. GET /public/collection/:collectionId/contact/schema Returns a ContactSchemaResponse describing all publicly visible contact fields. Core fields and collection-defined custom fields are merged into a single flat schema. Fields not in `publicVisibleFields` are stripped entirely from the response. Fields visible but not in `publicEditableFields` have `ui:disabled: true` in `uiSchema`. Use `fieldOrder` to render fields in the correct sequence, and `evaluateConditions` from the types package to handle conditional field visibility. ```typescript import { contact, evaluateConditions } from '@proveanything/smartlinks' const schema = await contact.publicGetSchema(collectionId) for (const fieldId of schema.fieldOrder) { const property = schema.schema.properties[fieldId] const ui = schema.uiSchema[fieldId] || {} const visible = evaluateConditions(property.conditions, property.showWhen, formValues) const disabled = ui['ui:disabled'] === true if (visible) renderField({ fieldId, property, ui, disabled }) } ```
|
|
4973
4999
|
|
|
4974
5000
|
**getUser**(collectionId: string,
|
|
4975
5001
|
userId: string,) → `Promise<UserSearchResponse>`
|
|
4976
|
-
Public: Get contact
|
|
5002
|
+
Public: Get the contact schema for a collection. GET /public/collection/:collectionId/contact/schema Returns a ContactSchemaResponse describing all publicly visible contact fields. Core fields and collection-defined custom fields are merged into a single flat schema. Fields not in `publicVisibleFields` are stripped entirely from the response. Fields visible but not in `publicEditableFields` have `ui:disabled: true` in `uiSchema`. Use `fieldOrder` to render fields in the correct sequence, and `evaluateConditions` from the types package to handle conditional field visibility. ```typescript import { contact, evaluateConditions } from '@proveanything/smartlinks' const schema = await contact.publicGetSchema(collectionId) for (const fieldId of schema.fieldOrder) { const property = schema.schema.properties[fieldId] const ui = schema.uiSchema[fieldId] || {} const visible = evaluateConditions(property.conditions, property.showWhen, formValues) const disabled = ui['ui:disabled'] === true if (visible) renderField({ fieldId, property, ui, disabled }) } ```
|
|
4977
5003
|
|
|
4978
5004
|
### crate
|
|
4979
5005
|
|
package/dist/types/contact.d.ts
CHANGED
|
@@ -131,61 +131,128 @@ export interface CommsState {
|
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
133
|
* Operators for conditional field visibility.
|
|
134
|
-
*
|
|
134
|
+
* Used in ContactSchemaProperty.conditions[].operator.
|
|
135
135
|
*/
|
|
136
|
-
export type ConditionOperator = 'equals' | '
|
|
136
|
+
export type ConditionOperator = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'is_empty' | 'is_not_empty' | 'is_true' | 'is_false' | 'greater_than' | 'less_than';
|
|
137
137
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
138
|
+
* A single visibility condition on a field.
|
|
139
|
+
* The field renders only when its conditions are satisfied (see `showWhen`).
|
|
140
140
|
*/
|
|
141
141
|
export interface FieldCondition {
|
|
142
|
-
|
|
142
|
+
targetFieldId: string;
|
|
143
143
|
operator: ConditionOperator;
|
|
144
|
-
value?:
|
|
144
|
+
value?: unknown;
|
|
145
145
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
146
|
+
/**
|
|
147
|
+
* A single field property as returned by the contact schema endpoint.
|
|
148
|
+
* Follows JSON Schema conventions with rendering hints via `format`.
|
|
149
|
+
*
|
|
150
|
+
* Format values:
|
|
151
|
+
* (none) → plain text input
|
|
152
|
+
* email → email input
|
|
153
|
+
* uri → URL input
|
|
154
|
+
* tel → phone input
|
|
155
|
+
* date → date picker
|
|
156
|
+
* textarea → multi-line text
|
|
157
|
+
* select → single-select dropdown (requires `enum`)
|
|
158
|
+
* multiselect → multi-select (type will be 'array', requires `enum`)
|
|
159
|
+
* radio → radio button group (requires `enum`)
|
|
160
|
+
*/
|
|
161
|
+
export interface ContactSchemaProperty {
|
|
162
|
+
type: 'string' | 'number' | 'boolean' | 'array';
|
|
163
|
+
title?: string;
|
|
164
|
+
description?: string;
|
|
165
|
+
format?: string;
|
|
166
|
+
/** Stored values for select / radio / multiselect fields */
|
|
167
|
+
enum?: string[];
|
|
168
|
+
/**
|
|
169
|
+
* Display labels for `enum` values — parallel array.
|
|
170
|
+
* `enum[i]` is the stored value; `enumNames[i]` is the display label.
|
|
171
|
+
* When absent, `enum` values are used as labels.
|
|
172
|
+
*/
|
|
173
|
+
enumNames?: string[];
|
|
174
|
+
/** Default value pre-populated into the field */
|
|
175
|
+
default?: unknown;
|
|
176
|
+
/** Minimum string length (type: 'string') */
|
|
177
|
+
minLength?: number;
|
|
178
|
+
/** Maximum string length (type: 'string') */
|
|
179
|
+
maxLength?: number;
|
|
180
|
+
/** Regex pattern the value must match (type: 'string') */
|
|
181
|
+
pattern?: string;
|
|
182
|
+
/** Minimum value (type: 'number') */
|
|
183
|
+
minimum?: number;
|
|
184
|
+
/** Maximum value (type: 'number') */
|
|
185
|
+
maximum?: number;
|
|
186
|
+
conditions?: FieldCondition[];
|
|
187
|
+
showWhen?: 'all' | 'any';
|
|
156
188
|
}
|
|
157
|
-
|
|
189
|
+
/**
|
|
190
|
+
* UI rendering hints for a single field, keyed by field ID in `uiSchema`.
|
|
191
|
+
*/
|
|
192
|
+
export interface ContactUiSchemaEntry {
|
|
193
|
+
/** Field is visible but not editable */
|
|
194
|
+
'ui:disabled'?: true;
|
|
195
|
+
/** Placeholder text shown inside the input */
|
|
196
|
+
'ui:placeholder'?: string;
|
|
197
|
+
/** Help text shown below the field (longer than description) */
|
|
198
|
+
'ui:help'?: string;
|
|
199
|
+
/** Override the auto-detected widget (e.g. 'textarea', 'radio', 'checkboxes') */
|
|
200
|
+
'ui:widget'?: string;
|
|
201
|
+
/** Widget-specific options */
|
|
202
|
+
'ui:options'?: {
|
|
203
|
+
rows?: number;
|
|
204
|
+
accept?: string;
|
|
205
|
+
label?: boolean;
|
|
206
|
+
[key: string]: unknown;
|
|
207
|
+
};
|
|
208
|
+
[key: string]: unknown;
|
|
158
209
|
}
|
|
159
210
|
/**
|
|
160
|
-
*
|
|
211
|
+
* Response from GET /public/collection/:collectionId/contact/schema
|
|
212
|
+
*
|
|
213
|
+
* Core fields and collection-defined custom fields are merged into a single
|
|
214
|
+
* flat schema. Fields not in `publicVisibleFields` are stripped entirely.
|
|
215
|
+
* Fields visible but not in `publicEditableFields` have `ui:disabled: true`
|
|
216
|
+
* in `uiSchema`.
|
|
161
217
|
*/
|
|
162
|
-
export interface
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
placeholder?: string;
|
|
168
|
-
description?: string;
|
|
169
|
-
condition?: FieldCondition;
|
|
170
|
-
}
|
|
171
|
-
export interface ContactSchema {
|
|
172
|
-
version: number;
|
|
173
|
-
fields: CoreField[];
|
|
174
|
-
customFields: CustomField[];
|
|
175
|
-
settings: {
|
|
176
|
-
publicVisibleFields: string[];
|
|
177
|
-
publicEditableFields: string[];
|
|
178
|
-
customFieldsVersion: number;
|
|
218
|
+
export interface ContactSchemaResponse {
|
|
219
|
+
schema: {
|
|
220
|
+
type: 'object';
|
|
221
|
+
required?: string[];
|
|
222
|
+
properties: Record<string, ContactSchemaProperty>;
|
|
179
223
|
};
|
|
224
|
+
uiSchema: Record<string, ContactUiSchemaEntry>;
|
|
225
|
+
/** Ordered list of field IDs — core fields first, then custom fields */
|
|
226
|
+
fieldOrder: string[];
|
|
227
|
+
/** Pass-through of the collection's SchemaFormConfig settings block */
|
|
228
|
+
settings: Record<string, unknown>;
|
|
229
|
+
/** Pass-through of the collection's SchemaFormConfig styling block */
|
|
230
|
+
styling: Record<string, unknown>;
|
|
180
231
|
}
|
|
232
|
+
/** @deprecated Use ContactSchemaResponse instead */
|
|
233
|
+
export type ContactSchema = ContactSchemaResponse;
|
|
181
234
|
/**
|
|
182
|
-
* Evaluate whether a field's
|
|
183
|
-
* Returns true if the field should be visible.
|
|
235
|
+
* Evaluate whether a field's conditions are satisfied given the current form values.
|
|
236
|
+
* Returns `true` if the field should be visible.
|
|
237
|
+
*
|
|
238
|
+
* @param conditions The `conditions` array from a ContactSchemaProperty (may be undefined)
|
|
239
|
+
* @param showWhen 'all' requires every condition to pass; 'any' requires at least one
|
|
240
|
+
* @param fieldValues Current form values keyed by field ID
|
|
184
241
|
*
|
|
185
242
|
* @example
|
|
186
243
|
* ```typescript
|
|
187
|
-
* const
|
|
188
|
-
* const
|
|
244
|
+
* const property = schema.schema.properties[fieldId]
|
|
245
|
+
* const visible = evaluateConditions(property.conditions, property.showWhen, formValues)
|
|
189
246
|
* ```
|
|
190
247
|
*/
|
|
191
|
-
export declare function
|
|
248
|
+
export declare function evaluateConditions(conditions: FieldCondition[] | undefined, showWhen: 'all' | 'any' | undefined, fieldValues: Record<string, unknown>): boolean;
|
|
249
|
+
/**
|
|
250
|
+
* @deprecated Use evaluateConditions (plural) instead.
|
|
251
|
+
* Shim for code using the old single-condition API.
|
|
252
|
+
*/
|
|
253
|
+
export declare function evaluateCondition(condition: {
|
|
254
|
+
dependsOn?: string;
|
|
255
|
+
targetFieldId?: string;
|
|
256
|
+
operator: string;
|
|
257
|
+
value?: unknown;
|
|
258
|
+
} | undefined, fieldValues: Record<string, unknown>): boolean;
|
package/dist/types/contact.js
CHANGED
|
@@ -1,35 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Evaluate whether a field's
|
|
3
|
-
* Returns true if the field should be visible.
|
|
2
|
+
* Evaluate whether a field's conditions are satisfied given the current form values.
|
|
3
|
+
* Returns `true` if the field should be visible.
|
|
4
|
+
*
|
|
5
|
+
* @param conditions The `conditions` array from a ContactSchemaProperty (may be undefined)
|
|
6
|
+
* @param showWhen 'all' requires every condition to pass; 'any' requires at least one
|
|
7
|
+
* @param fieldValues Current form values keyed by field ID
|
|
4
8
|
*
|
|
5
9
|
* @example
|
|
6
10
|
* ```typescript
|
|
7
|
-
* const
|
|
8
|
-
* const
|
|
11
|
+
* const property = schema.schema.properties[fieldId]
|
|
12
|
+
* const visible = evaluateConditions(property.conditions, property.showWhen, formValues)
|
|
9
13
|
* ```
|
|
10
14
|
*/
|
|
15
|
+
export function evaluateConditions(conditions, showWhen, fieldValues) {
|
|
16
|
+
if (!conditions || conditions.length === 0)
|
|
17
|
+
return true;
|
|
18
|
+
const results = conditions.map(condition => {
|
|
19
|
+
const value = fieldValues[condition.targetFieldId];
|
|
20
|
+
switch (condition.operator) {
|
|
21
|
+
case 'is_empty':
|
|
22
|
+
return value == null || value === '' || (Array.isArray(value) && value.length === 0);
|
|
23
|
+
case 'is_not_empty':
|
|
24
|
+
return value != null && value !== '' && !(Array.isArray(value) && value.length === 0);
|
|
25
|
+
case 'is_true':
|
|
26
|
+
return value === true;
|
|
27
|
+
case 'is_false':
|
|
28
|
+
return value === false;
|
|
29
|
+
case 'equals':
|
|
30
|
+
return value === condition.value;
|
|
31
|
+
case 'not_equals':
|
|
32
|
+
return value !== condition.value;
|
|
33
|
+
case 'contains':
|
|
34
|
+
return Array.isArray(value)
|
|
35
|
+
? value.includes(condition.value)
|
|
36
|
+
: typeof value === 'string' && value.includes(String(condition.value));
|
|
37
|
+
case 'not_contains':
|
|
38
|
+
return Array.isArray(value)
|
|
39
|
+
? !value.includes(condition.value)
|
|
40
|
+
: typeof value === 'string' && !value.includes(String(condition.value));
|
|
41
|
+
case 'greater_than':
|
|
42
|
+
return typeof value === 'number' && typeof condition.value === 'number'
|
|
43
|
+
? value > condition.value
|
|
44
|
+
: String(value) > String(condition.value);
|
|
45
|
+
case 'less_than':
|
|
46
|
+
return typeof value === 'number' && typeof condition.value === 'number'
|
|
47
|
+
? value < condition.value
|
|
48
|
+
: String(value) < String(condition.value);
|
|
49
|
+
default:
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return (showWhen !== null && showWhen !== void 0 ? showWhen : 'all') === 'any'
|
|
54
|
+
? results.some(Boolean)
|
|
55
|
+
: results.every(Boolean);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use evaluateConditions (plural) instead.
|
|
59
|
+
* Shim for code using the old single-condition API.
|
|
60
|
+
*/
|
|
11
61
|
export function evaluateCondition(condition, fieldValues) {
|
|
62
|
+
var _a;
|
|
12
63
|
if (!condition)
|
|
13
|
-
return true;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
case 'isNotEmpty':
|
|
19
|
-
return value != null && value !== '' && !(Array.isArray(value) && !value.length);
|
|
20
|
-
case 'isTrue':
|
|
21
|
-
return value === true;
|
|
22
|
-
case 'isFalse':
|
|
23
|
-
return value === false;
|
|
24
|
-
case 'equals':
|
|
25
|
-
return value === condition.value;
|
|
26
|
-
case 'notEquals':
|
|
27
|
-
return value !== condition.value;
|
|
28
|
-
case 'contains':
|
|
29
|
-
return Array.isArray(value) && value.includes(condition.value);
|
|
30
|
-
case 'notContains':
|
|
31
|
-
return !Array.isArray(value) || !value.includes(condition.value);
|
|
32
|
-
default:
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
64
|
+
return true;
|
|
65
|
+
const targetFieldId = (_a = condition.dependsOn) !== null && _a !== void 0 ? _a : condition.targetFieldId;
|
|
66
|
+
if (!targetFieldId)
|
|
67
|
+
return true;
|
|
68
|
+
return evaluateConditions([{ targetFieldId, operator: condition.operator, value: condition.value }], 'all', fieldValues);
|
|
35
69
|
}
|
package/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.1 | Generated: 2026-02-26T11:23:15.062Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -2502,36 +2502,64 @@ interface CommsState {
|
|
|
2502
2502
|
**FieldCondition** (interface)
|
|
2503
2503
|
```typescript
|
|
2504
2504
|
interface FieldCondition {
|
|
2505
|
-
|
|
2505
|
+
targetFieldId: string // The field whose value is tested
|
|
2506
2506
|
operator: ConditionOperator
|
|
2507
|
-
value?:
|
|
2507
|
+
value?: unknown // Required for equals / not_equals / contains / not_contains / greater_than / less_than
|
|
2508
2508
|
}
|
|
2509
2509
|
```
|
|
2510
2510
|
|
|
2511
|
-
**
|
|
2511
|
+
**ContactSchemaProperty** (interface)
|
|
2512
2512
|
```typescript
|
|
2513
|
-
interface
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2513
|
+
interface ContactSchemaProperty {
|
|
2514
|
+
type: 'string' | 'number' | 'boolean' | 'array'
|
|
2515
|
+
title?: string
|
|
2516
|
+
description?: string
|
|
2517
|
+
format?: string
|
|
2518
|
+
enum?: string[]
|
|
2519
|
+
* Display labels for `enum` values — parallel array.
|
|
2520
|
+
* `enum[i]` is the stored value; `enumNames[i]` is the display label.
|
|
2521
|
+
* When absent, `enum` values are used as labels.
|
|
2522
|
+
enumNames?: string[]
|
|
2523
|
+
default?: unknown
|
|
2524
|
+
minLength?: number
|
|
2525
|
+
maxLength?: number
|
|
2526
|
+
pattern?: string
|
|
2527
|
+
minimum?: number
|
|
2528
|
+
maximum?: number
|
|
2529
|
+
conditions?: FieldCondition[]
|
|
2530
|
+
showWhen?: 'all' | 'any'
|
|
2531
|
+
}
|
|
2532
|
+
```
|
|
2533
|
+
|
|
2534
|
+
**ContactUiSchemaEntry** (interface)
|
|
2535
|
+
```typescript
|
|
2536
|
+
interface ContactUiSchemaEntry {
|
|
2537
|
+
'ui:disabled'?: true
|
|
2538
|
+
'ui:placeholder'?: string
|
|
2539
|
+
'ui:help'?: string
|
|
2540
|
+
'ui:widget'?: string
|
|
2541
|
+
'ui:options'?: {
|
|
2542
|
+
rows?: number // textarea: number of visible rows
|
|
2543
|
+
accept?: string // file: accepted MIME types
|
|
2544
|
+
label?: boolean // checkbox: show inline label
|
|
2545
|
+
[key: string]: unknown
|
|
2546
|
+
}
|
|
2547
|
+
[key: string]: unknown
|
|
2521
2548
|
}
|
|
2522
2549
|
```
|
|
2523
2550
|
|
|
2524
|
-
**
|
|
2551
|
+
**ContactSchemaResponse** (interface)
|
|
2525
2552
|
```typescript
|
|
2526
|
-
interface
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
publicVisibleFields: string[]
|
|
2532
|
-
publicEditableFields: string[]
|
|
2533
|
-
customFieldsVersion: number
|
|
2553
|
+
interface ContactSchemaResponse {
|
|
2554
|
+
schema: {
|
|
2555
|
+
type: 'object'
|
|
2556
|
+
required?: string[]
|
|
2557
|
+
properties: Record<string, ContactSchemaProperty>
|
|
2534
2558
|
}
|
|
2559
|
+
uiSchema: Record<string, ContactUiSchemaEntry>
|
|
2560
|
+
fieldOrder: string[]
|
|
2561
|
+
settings: Record<string, unknown>
|
|
2562
|
+
styling: Record<string, unknown>
|
|
2535
2563
|
}
|
|
2536
2564
|
```
|
|
2537
2565
|
|
|
@@ -2553,9 +2581,7 @@ interface ContactSchema {
|
|
|
2553
2581
|
|
|
2554
2582
|
**ConditionOperator** = ``
|
|
2555
2583
|
|
|
2556
|
-
**
|
|
2557
|
-
|
|
2558
|
-
**FieldType** = ``
|
|
2584
|
+
**ContactSchema** = `ContactSchemaResponse`
|
|
2559
2585
|
|
|
2560
2586
|
### crate
|
|
2561
2587
|
|
|
@@ -4965,15 +4991,15 @@ Logging: Append many communication events for a list of IDs. POST /admin/collect
|
|
|
4965
4991
|
**publicUpdateMine**(collectionId: string,
|
|
4966
4992
|
data: ContactPatch) → `Promise<PublicUpdateMyContactResponse>`
|
|
4967
4993
|
|
|
4968
|
-
**publicGetSchema**(collectionId: string) → `Promise<
|
|
4969
|
-
Public: Get contact
|
|
4994
|
+
**publicGetSchema**(collectionId: string) → `Promise<ContactSchemaResponse>`
|
|
4995
|
+
Public: Get the contact schema for a collection. GET /public/collection/:collectionId/contact/schema Returns a ContactSchemaResponse describing all publicly visible contact fields. Core fields and collection-defined custom fields are merged into a single flat schema. Fields not in `publicVisibleFields` are stripped entirely from the response. Fields visible but not in `publicEditableFields` have `ui:disabled: true` in `uiSchema`. Use `fieldOrder` to render fields in the correct sequence, and `evaluateConditions` from the types package to handle conditional field visibility. ```typescript import { contact, evaluateConditions } from '@proveanything/smartlinks' const schema = await contact.publicGetSchema(collectionId) for (const fieldId of schema.fieldOrder) { const property = schema.schema.properties[fieldId] const ui = schema.uiSchema[fieldId] || {} const visible = evaluateConditions(property.conditions, property.showWhen, formValues) const disabled = ui['ui:disabled'] === true if (visible) renderField({ fieldId, property, ui, disabled }) } ```
|
|
4970
4996
|
|
|
4971
4997
|
**erase**(collectionId: string, contactId: string, body?: any) → `Promise<ContactResponse>`
|
|
4972
|
-
Public: Get contact
|
|
4998
|
+
Public: Get the contact schema for a collection. GET /public/collection/:collectionId/contact/schema Returns a ContactSchemaResponse describing all publicly visible contact fields. Core fields and collection-defined custom fields are merged into a single flat schema. Fields not in `publicVisibleFields` are stripped entirely from the response. Fields visible but not in `publicEditableFields` have `ui:disabled: true` in `uiSchema`. Use `fieldOrder` to render fields in the correct sequence, and `evaluateConditions` from the types package to handle conditional field visibility. ```typescript import { contact, evaluateConditions } from '@proveanything/smartlinks' const schema = await contact.publicGetSchema(collectionId) for (const fieldId of schema.fieldOrder) { const property = schema.schema.properties[fieldId] const ui = schema.uiSchema[fieldId] || {} const visible = evaluateConditions(property.conditions, property.showWhen, formValues) const disabled = ui['ui:disabled'] === true if (visible) renderField({ fieldId, property, ui, disabled }) } ```
|
|
4973
4999
|
|
|
4974
5000
|
**getUser**(collectionId: string,
|
|
4975
5001
|
userId: string,) → `Promise<UserSearchResponse>`
|
|
4976
|
-
Public: Get contact
|
|
5002
|
+
Public: Get the contact schema for a collection. GET /public/collection/:collectionId/contact/schema Returns a ContactSchemaResponse describing all publicly visible contact fields. Core fields and collection-defined custom fields are merged into a single flat schema. Fields not in `publicVisibleFields` are stripped entirely from the response. Fields visible but not in `publicEditableFields` have `ui:disabled: true` in `uiSchema`. Use `fieldOrder` to render fields in the correct sequence, and `evaluateConditions` from the types package to handle conditional field visibility. ```typescript import { contact, evaluateConditions } from '@proveanything/smartlinks' const schema = await contact.publicGetSchema(collectionId) for (const fieldId of schema.fieldOrder) { const property = schema.schema.properties[fieldId] const ui = schema.uiSchema[fieldId] || {} const visible = evaluateConditions(property.conditions, property.showWhen, formValues) const disabled = ui['ui:disabled'] === true if (visible) renderField({ fieldId, property, ui, disabled }) } ```
|
|
4977
5003
|
|
|
4978
5004
|
### crate
|
|
4979
5005
|
|