@proveanything/smartlinks 2.1.20 → 2.1.22
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 +60 -1
- package/dist/api/contact.js +74 -0
- package/dist/api/realtime.d.ts +19 -0
- package/dist/api/realtime.js +26 -1
- package/dist/docs/API_SUMMARY.md +100 -3
- package/dist/docs/app-manifest.md +19 -0
- package/dist/docs/assistant-apps.md +4 -0
- package/dist/docs/assistant-context.md +119 -0
- package/dist/docs/realtime.md +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +0 -1
- package/dist/openapi.yaml +247 -0
- package/dist/types/appManifest.d.ts +64 -1
- package/dist/types/contact.d.ts +55 -0
- package/dist/types/realtime.d.ts +7 -1
- package/docs/API_SUMMARY.md +100 -3
- package/docs/app-manifest.md +19 -0
- package/docs/assistant-apps.md +4 -0
- package/docs/assistant-context.md +119 -0
- package/docs/realtime.md +20 -0
- package/openapi.yaml +247 -0
- package/package.json +1 -1
package/dist/api/contact.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContactResponse, ContactCreateRequest, ContactUpdateRequest, ContactListResponse, ContactSearchParams, ContactSearchResponse, PublicContactUpsertRequest, PublicContactUpsertResponse, UserSearchResponse, ContactPatch, PublicGetMyContactResponse, PublicUpdateMyContactResponse, ContactSchemaResponse } from "../types/index.js";
|
|
1
|
+
import { ContactResponse, ContactCreateRequest, ContactUpdateRequest, ContactListResponse, ContactSearchParams, ContactSearchResponse, PublicContactUpsertRequest, PublicContactUpsertResponse, UserSearchResponse, ContactPatch, PublicGetMyContactResponse, PublicUpdateMyContactResponse, ContactSchemaResponse, ContactDuplicatesResponse, ContactMergeResponse, ContactLinkLoginResponse } from "../types/index.js";
|
|
2
2
|
export declare namespace contact {
|
|
3
3
|
function create(collectionId: string, data: ContactCreateRequest): Promise<ContactResponse>;
|
|
4
4
|
function list(collectionId: string, params?: {
|
|
@@ -50,5 +50,64 @@ export declare namespace contact {
|
|
|
50
50
|
*/
|
|
51
51
|
function publicGetSchema(collectionId: string): Promise<ContactSchemaResponse>;
|
|
52
52
|
function erase(collectionId: string, contactId: string, body?: any): Promise<ContactResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Admin: pairs of contacts that look like one person.
|
|
55
|
+
* GET /admin/collection/:collectionId/contacts/duplicates
|
|
56
|
+
*
|
|
57
|
+
* The pattern it finds: someone the collection knew by email first (an import, a list, a form) who
|
|
58
|
+
* later signed in. Their sign-in got a second contact, which could not take the email the first one
|
|
59
|
+
* already held — so one contact has the email and no sign-in, the other the sign-in (and everything
|
|
60
|
+
* they did) and no email. The match is made on the server, on verified addresses only.
|
|
61
|
+
*
|
|
62
|
+
* Checks a window of contacts per call; while `more` is true, call again with `offset` moved on by
|
|
63
|
+
* `scanned`.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const { pairs } = await contact.findDuplicates(collectionId)
|
|
68
|
+
* for (const pair of pairs) {
|
|
69
|
+
* await contact.merge(collectionId, pair.keep.contactId, pair.merge.contactId)
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
function findDuplicates(collectionId: string, params?: {
|
|
74
|
+
limit?: number;
|
|
75
|
+
offset?: number;
|
|
76
|
+
}): Promise<ContactDuplicatesResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* Admin: fold contact `fromContactId` INTO contact `keepContactId`.
|
|
79
|
+
* POST /admin/collection/:collectionId/contacts/:keepContactId/merge
|
|
80
|
+
*
|
|
81
|
+
* The kept contact gains the other's sign-in, emails and phones, and anything it had no value for;
|
|
82
|
+
* its own values win. Everything recorded against the other contact moves to the kept one. Consent is
|
|
83
|
+
* never loosened: an opt-out on either contact stays an opt-out. The other contact is soft-deleted and
|
|
84
|
+
* marked with `customFields.mergedInto`.
|
|
85
|
+
*
|
|
86
|
+
* Refused (HTTP 409, `error` = a `ContactMergeErrorCode`) when the two have different sign-ins
|
|
87
|
+
* (`LOGIN_CONFLICT`) or are both members of the same loyalty scheme (`LOYALTY_CONFLICT`).
|
|
88
|
+
*/
|
|
89
|
+
function merge(collectionId: string, keepContactId: string, fromContactId: string): Promise<ContactMergeResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Admin: the contact that carries a sign-in, attaching the sign-in first to the contact that already
|
|
92
|
+
* holds its verified email or phone.
|
|
93
|
+
* POST /admin/collection/:collectionId/contacts/link-login
|
|
94
|
+
*
|
|
95
|
+
* For a service about to create a contact for a `userId`: call this first and only create when it
|
|
96
|
+
* throws 404 (`NOTHING_TO_LINK`), so a person the collection already knows by email stays one contact.
|
|
97
|
+
* The address is read from the sign-in itself and must be verified; nothing the caller says about an
|
|
98
|
+
* email is used. Never creates a contact.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* let contactId: string
|
|
103
|
+
* try {
|
|
104
|
+
* contactId = (await contact.linkLogin(collectionId, userId)).contactId
|
|
105
|
+
* } catch (err) {
|
|
106
|
+
* if (err.statusCode !== 404) throw err
|
|
107
|
+
* contactId = (await contact.create(collectionId, { userId, source: 'my-service' })).contactId
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
function linkLogin(collectionId: string, userId: string): Promise<ContactLinkLoginResponse>;
|
|
53
112
|
function getUser(collectionId: string, userId: string): Promise<UserSearchResponse>;
|
|
54
113
|
}
|
package/dist/api/contact.js
CHANGED
|
@@ -155,6 +155,80 @@ export var contact;
|
|
|
155
155
|
return post(path, body || {});
|
|
156
156
|
}
|
|
157
157
|
contact.erase = erase;
|
|
158
|
+
/**
|
|
159
|
+
* Admin: pairs of contacts that look like one person.
|
|
160
|
+
* GET /admin/collection/:collectionId/contacts/duplicates
|
|
161
|
+
*
|
|
162
|
+
* The pattern it finds: someone the collection knew by email first (an import, a list, a form) who
|
|
163
|
+
* later signed in. Their sign-in got a second contact, which could not take the email the first one
|
|
164
|
+
* already held — so one contact has the email and no sign-in, the other the sign-in (and everything
|
|
165
|
+
* they did) and no email. The match is made on the server, on verified addresses only.
|
|
166
|
+
*
|
|
167
|
+
* Checks a window of contacts per call; while `more` is true, call again with `offset` moved on by
|
|
168
|
+
* `scanned`.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const { pairs } = await contact.findDuplicates(collectionId)
|
|
173
|
+
* for (const pair of pairs) {
|
|
174
|
+
* await contact.merge(collectionId, pair.keep.contactId, pair.merge.contactId)
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
async function findDuplicates(collectionId, params) {
|
|
179
|
+
const query = new URLSearchParams();
|
|
180
|
+
if ((params === null || params === void 0 ? void 0 : params.limit) !== undefined)
|
|
181
|
+
query.set("limit", String(params.limit));
|
|
182
|
+
if ((params === null || params === void 0 ? void 0 : params.offset) !== undefined)
|
|
183
|
+
query.set("offset", String(params.offset));
|
|
184
|
+
const qs = query.toString();
|
|
185
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/contacts/duplicates${qs ? `?${qs}` : ""}`;
|
|
186
|
+
return request(path);
|
|
187
|
+
}
|
|
188
|
+
contact.findDuplicates = findDuplicates;
|
|
189
|
+
/**
|
|
190
|
+
* Admin: fold contact `fromContactId` INTO contact `keepContactId`.
|
|
191
|
+
* POST /admin/collection/:collectionId/contacts/:keepContactId/merge
|
|
192
|
+
*
|
|
193
|
+
* The kept contact gains the other's sign-in, emails and phones, and anything it had no value for;
|
|
194
|
+
* its own values win. Everything recorded against the other contact moves to the kept one. Consent is
|
|
195
|
+
* never loosened: an opt-out on either contact stays an opt-out. The other contact is soft-deleted and
|
|
196
|
+
* marked with `customFields.mergedInto`.
|
|
197
|
+
*
|
|
198
|
+
* Refused (HTTP 409, `error` = a `ContactMergeErrorCode`) when the two have different sign-ins
|
|
199
|
+
* (`LOGIN_CONFLICT`) or are both members of the same loyalty scheme (`LOYALTY_CONFLICT`).
|
|
200
|
+
*/
|
|
201
|
+
async function merge(collectionId, keepContactId, fromContactId) {
|
|
202
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/contacts/${encodeURIComponent(keepContactId)}/merge`;
|
|
203
|
+
return post(path, { fromContactId });
|
|
204
|
+
}
|
|
205
|
+
contact.merge = merge;
|
|
206
|
+
/**
|
|
207
|
+
* Admin: the contact that carries a sign-in, attaching the sign-in first to the contact that already
|
|
208
|
+
* holds its verified email or phone.
|
|
209
|
+
* POST /admin/collection/:collectionId/contacts/link-login
|
|
210
|
+
*
|
|
211
|
+
* For a service about to create a contact for a `userId`: call this first and only create when it
|
|
212
|
+
* throws 404 (`NOTHING_TO_LINK`), so a person the collection already knows by email stays one contact.
|
|
213
|
+
* The address is read from the sign-in itself and must be verified; nothing the caller says about an
|
|
214
|
+
* email is used. Never creates a contact.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* let contactId: string
|
|
219
|
+
* try {
|
|
220
|
+
* contactId = (await contact.linkLogin(collectionId, userId)).contactId
|
|
221
|
+
* } catch (err) {
|
|
222
|
+
* if (err.statusCode !== 404) throw err
|
|
223
|
+
* contactId = (await contact.create(collectionId, { userId, source: 'my-service' })).contactId
|
|
224
|
+
* }
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
async function linkLogin(collectionId, userId) {
|
|
228
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/contacts/link-login`;
|
|
229
|
+
return post(path, { userId });
|
|
230
|
+
}
|
|
231
|
+
contact.linkLogin = linkLogin;
|
|
158
232
|
// get user
|
|
159
233
|
async function getUser(collectionId, userId) {
|
|
160
234
|
const path = `/admin/collection/${encodeURIComponent(collectionId)}/owner/${encodeURIComponent(userId)}`;
|
package/dist/api/realtime.d.ts
CHANGED
|
@@ -30,6 +30,25 @@ export declare function channel(scope: RealtimeScope & {
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
export declare function onChange(scope: RealtimeScope, filter: RealtimeChangeFilter, onChangeFn: (change: RealtimeChangeEvent) => void): () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Something this APP works on changed: one of its work orders, a container or stock it moved, or one of
|
|
35
|
+
* its own records.
|
|
36
|
+
* For the people who use the app, admins or not: someone hears these when they are in one of the app's
|
|
37
|
+
* user groups (the ones its server functions are limited to, or `realtime.staff` in its manifest), and
|
|
38
|
+
* so does a collection admin. IDs only — refetch through your own API.
|
|
39
|
+
*
|
|
40
|
+
* Types: 'workOrder' (`id`, `appId`), 'container' (`id`, `kind` = its container type), 'stock' (`id` =
|
|
41
|
+
* the container, `productId`), 'record' (`id`, `recordType`). Filter as with `onChange`; an empty filter
|
|
42
|
+
* hears them all.
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* // A production app's screens refetch when anything on the floor changes.
|
|
46
|
+
* useEffect(() => realtime.onStaffChange({ collectionId, appId }, {}, () => queryClient.invalidateQueries()), [collectionId, appId])
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function onStaffChange(scope: RealtimeScope & {
|
|
50
|
+
appId: string;
|
|
51
|
+
}, filter: RealtimeChangeFilter, onChangeFn: (change: RealtimeChangeEvent) => void): () => void;
|
|
33
52
|
/**
|
|
34
53
|
* Messages for the signed-in person only (e.g. "scan" — a tag they just scanned on another device).
|
|
35
54
|
*/
|
package/dist/api/realtime.js
CHANGED
|
@@ -193,7 +193,7 @@ export function channel(scope, name) {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
function matches(change, filter) {
|
|
196
|
-
for (const k of ["type", "id", "appId", "recordType", "productId", "proofId"]) {
|
|
196
|
+
for (const k of ["type", "id", "appId", "recordType", "productId", "proofId", "kind"]) {
|
|
197
197
|
if (filter[k] !== undefined && change[k] !== filter[k])
|
|
198
198
|
return false;
|
|
199
199
|
}
|
|
@@ -230,6 +230,31 @@ export function onChange(scope, filter, onChangeFn) {
|
|
|
230
230
|
offPublic();
|
|
231
231
|
};
|
|
232
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Something this APP works on changed: one of its work orders, a container or stock it moved, or one of
|
|
235
|
+
* its own records.
|
|
236
|
+
* For the people who use the app, admins or not: someone hears these when they are in one of the app's
|
|
237
|
+
* user groups (the ones its server functions are limited to, or `realtime.staff` in its manifest), and
|
|
238
|
+
* so does a collection admin. IDs only — refetch through your own API.
|
|
239
|
+
*
|
|
240
|
+
* Types: 'workOrder' (`id`, `appId`), 'container' (`id`, `kind` = its container type), 'stock' (`id` =
|
|
241
|
+
* the container, `productId`), 'record' (`id`, `recordType`). Filter as with `onChange`; an empty filter
|
|
242
|
+
* hears them all.
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* // A production app's screens refetch when anything on the floor changes.
|
|
246
|
+
* useEffect(() => realtime.onStaffChange({ collectionId, appId }, {}, () => queryClient.invalidateQueries()), [collectionId, appId])
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
export function onStaffChange(scope, filter, onChangeFn) {
|
|
250
|
+
return streamFor({ collectionId: scope.collectionId, appId: scope.appId }).add("feed:staff", (m) => {
|
|
251
|
+
if (m.event !== "change" || !m.data || typeof m.data !== "object")
|
|
252
|
+
return;
|
|
253
|
+
const change = m.data;
|
|
254
|
+
if (matches(change, filter))
|
|
255
|
+
onChangeFn(change);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
233
258
|
/**
|
|
234
259
|
* Messages for the signed-in person only (e.g. "scan" — a tag they just scanned on another device).
|
|
235
260
|
*/
|
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.22 | Generated: 2026-11-18T08:01:22.740Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -3186,6 +3186,7 @@ interface AppManifest {
|
|
|
3186
3186
|
};
|
|
3187
3187
|
};
|
|
3188
3188
|
admin?: string;
|
|
3189
|
+
adminPage?: string;
|
|
3189
3190
|
widgets?: AppManifestWidgets;
|
|
3190
3191
|
containers?: {
|
|
3191
3192
|
files: AppManifestFiles;
|
|
@@ -3196,7 +3197,10 @@ interface AppManifest {
|
|
|
3196
3197
|
adminViews?: AdminView[];
|
|
3197
3198
|
executor?: AppManifestExecutor;
|
|
3198
3199
|
functions?: AppManifestFunctions;
|
|
3199
|
-
realtime?: {
|
|
3200
|
+
realtime?: {
|
|
3201
|
+
channels?: RealtimeChannelDeclaration[];
|
|
3202
|
+
staff?: string[];
|
|
3203
|
+
};
|
|
3200
3204
|
adminCards?: AppManifestAdminCards;
|
|
3201
3205
|
data?: AppDataDeclaration;
|
|
3202
3206
|
headless?: AppHeadlessDeclaration;
|
|
@@ -3221,6 +3225,29 @@ interface AppAssistantDeclaration {
|
|
|
3221
3225
|
skills?: AppAssistantFile[];
|
|
3222
3226
|
knowledge?: AppAssistantFile[];
|
|
3223
3227
|
preview?: string;
|
|
3228
|
+
purpose?: string;
|
|
3229
|
+
objects?: AssistantObject[];
|
|
3230
|
+
words?: Record<string, string>;
|
|
3231
|
+
recipes?: AssistantRecipe[];
|
|
3232
|
+
}
|
|
3233
|
+
```
|
|
3234
|
+
|
|
3235
|
+
**AssistantObject** (interface)
|
|
3236
|
+
```typescript
|
|
3237
|
+
interface AssistantObject {
|
|
3238
|
+
object: string;
|
|
3239
|
+
where?: Record<string, string | number | boolean>;
|
|
3240
|
+
means: string;
|
|
3241
|
+
fields?: Record<string, string>;
|
|
3242
|
+
write?: 'direct' | 'actions' | 'none';
|
|
3243
|
+
}
|
|
3244
|
+
```
|
|
3245
|
+
|
|
3246
|
+
**AssistantRecipe** (interface)
|
|
3247
|
+
```typescript
|
|
3248
|
+
interface AssistantRecipe {
|
|
3249
|
+
question: string;
|
|
3250
|
+
answer: string;
|
|
3224
3251
|
}
|
|
3225
3252
|
```
|
|
3226
3253
|
|
|
@@ -7440,6 +7467,56 @@ interface ContactListResponse {
|
|
|
7440
7467
|
}
|
|
7441
7468
|
```
|
|
7442
7469
|
|
|
7470
|
+
**ContactDuplicatePair** (interface)
|
|
7471
|
+
```typescript
|
|
7472
|
+
interface ContactDuplicatePair {
|
|
7473
|
+
keep: Contact
|
|
7474
|
+
merge: Contact
|
|
7475
|
+
matchedOn: "email" | "phone"
|
|
7476
|
+
}
|
|
7477
|
+
```
|
|
7478
|
+
|
|
7479
|
+
**ContactDuplicatesResponse** (interface)
|
|
7480
|
+
```typescript
|
|
7481
|
+
interface ContactDuplicatesResponse {
|
|
7482
|
+
pairs: ContactDuplicatePair[]
|
|
7483
|
+
scanned: number
|
|
7484
|
+
more: boolean
|
|
7485
|
+
}
|
|
7486
|
+
```
|
|
7487
|
+
|
|
7488
|
+
**ContactMergeResponse** (interface)
|
|
7489
|
+
```typescript
|
|
7490
|
+
interface ContactMergeResponse {
|
|
7491
|
+
contactId: string
|
|
7492
|
+
mergedFrom: string
|
|
7493
|
+
moved: {
|
|
7494
|
+
login: boolean
|
|
7495
|
+
identities: number
|
|
7496
|
+
records?: number
|
|
7497
|
+
cases?: number
|
|
7498
|
+
threads?: number
|
|
7499
|
+
bookings?: number
|
|
7500
|
+
loyaltyMembers?: number
|
|
7501
|
+
assets?: number
|
|
7502
|
+
uploadTokens?: number
|
|
7503
|
+
aiSessions?: number
|
|
7504
|
+
messages?: number
|
|
7505
|
+
conversations?: number
|
|
7506
|
+
}
|
|
7507
|
+
contact: Contact
|
|
7508
|
+
}
|
|
7509
|
+
```
|
|
7510
|
+
|
|
7511
|
+
**ContactLinkLoginResponse** (interface)
|
|
7512
|
+
```typescript
|
|
7513
|
+
interface ContactLinkLoginResponse {
|
|
7514
|
+
contactId: string
|
|
7515
|
+
linked: boolean
|
|
7516
|
+
contact: Contact
|
|
7517
|
+
}
|
|
7518
|
+
```
|
|
7519
|
+
|
|
7443
7520
|
**ContactSearchParams** (interface)
|
|
7444
7521
|
```typescript
|
|
7445
7522
|
interface ContactSearchParams {
|
|
@@ -7660,6 +7737,8 @@ interface ContactSchemaResponse {
|
|
|
7660
7737
|
|
|
7661
7738
|
**ContactUpdateRequest** = `Partial<ContactCreateRequest>`
|
|
7662
7739
|
|
|
7740
|
+
**ContactMergeErrorCode** = ``
|
|
7741
|
+
|
|
7663
7742
|
**PublicContactUpsertRequest** = `Partial<`
|
|
7664
7743
|
|
|
7665
7744
|
**ContactPatch** = `Partial<`
|
|
@@ -11336,6 +11415,7 @@ interface RealtimeChangeEvent {
|
|
|
11336
11415
|
productId?: string
|
|
11337
11416
|
proofId?: string
|
|
11338
11417
|
status?: string
|
|
11418
|
+
kind?: string
|
|
11339
11419
|
at: number
|
|
11340
11420
|
}
|
|
11341
11421
|
```
|
|
@@ -11349,6 +11429,7 @@ interface RealtimeChangeFilter {
|
|
|
11349
11429
|
recordType?: string
|
|
11350
11430
|
productId?: string
|
|
11351
11431
|
proofId?: string
|
|
11432
|
+
kind?: string
|
|
11352
11433
|
}
|
|
11353
11434
|
```
|
|
11354
11435
|
|
|
@@ -13804,9 +13885,22 @@ Public: Get the contact schema for a collection. GET /public/collection/:collect
|
|
|
13804
13885
|
**erase**(collectionId: string, contactId: string, body?: any) → `Promise<ContactResponse>`
|
|
13805
13886
|
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 }) } ```
|
|
13806
13887
|
|
|
13888
|
+
**findDuplicates**(collectionId: string,
|
|
13889
|
+
params?: { limit?: number; offset?: number }) → `Promise<ContactDuplicatesResponse>`
|
|
13890
|
+
Admin: pairs of contacts that look like one person. GET /admin/collection/:collectionId/contacts/duplicates The pattern it finds: someone the collection knew by email first (an import, a list, a form) who later signed in. Their sign-in got a second contact, which could not take the email the first one already held — so one contact has the email and no sign-in, the other the sign-in (and everything they did) and no email. The match is made on the server, on verified addresses only. Checks a window of contacts per call; while `more` is true, call again with `offset` moved on by `scanned`. ```typescript const { pairs } = await contact.findDuplicates(collectionId) for (const pair of pairs) { await contact.merge(collectionId, pair.keep.contactId, pair.merge.contactId) } ```
|
|
13891
|
+
|
|
13892
|
+
**merge**(collectionId: string,
|
|
13893
|
+
keepContactId: string,
|
|
13894
|
+
fromContactId: string) → `Promise<ContactMergeResponse>`
|
|
13895
|
+
Admin: fold contact `fromContactId` INTO contact `keepContactId`. POST /admin/collection/:collectionId/contacts/:keepContactId/merge The kept contact gains the other's sign-in, emails and phones, and anything it had no value for; its own values win. Everything recorded against the other contact moves to the kept one. Consent is never loosened: an opt-out on either contact stays an opt-out. The other contact is soft-deleted and marked with `customFields.mergedInto`. Refused (HTTP 409, `error` = a `ContactMergeErrorCode`) when the two have different sign-ins (`LOGIN_CONFLICT`) or are both members of the same loyalty scheme (`LOYALTY_CONFLICT`).
|
|
13896
|
+
|
|
13897
|
+
**linkLogin**(collectionId: string,
|
|
13898
|
+
userId: string) → `Promise<ContactLinkLoginResponse>`
|
|
13899
|
+
Admin: the contact that carries a sign-in, attaching the sign-in first to the contact that already holds its verified email or phone. POST /admin/collection/:collectionId/contacts/link-login For a service about to create a contact for a `userId`: call this first and only create when it throws 404 (`NOTHING_TO_LINK`), so a person the collection already knows by email stays one contact. The address is read from the sign-in itself and must be verified; nothing the caller says about an email is used. Never creates a contact. ```typescript let contactId: string try { contactId = (await contact.linkLogin(collectionId, userId)).contactId } catch (err) { if (err.statusCode !== 404) throw err contactId = (await contact.create(collectionId, { userId, source: 'my-service' })).contactId } ```
|
|
13900
|
+
|
|
13807
13901
|
**getUser**(collectionId: string,
|
|
13808
13902
|
userId: string,) → `Promise<UserSearchResponse>`
|
|
13809
|
-
|
|
13903
|
+
Admin: the contact that carries a sign-in, attaching the sign-in first to the contact that already holds its verified email or phone. POST /admin/collection/:collectionId/contacts/link-login For a service about to create a contact for a `userId`: call this first and only create when it throws 404 (`NOTHING_TO_LINK`), so a person the collection already knows by email stays one contact. The address is read from the sign-in itself and must be verified; nothing the caller says about an email is used. Never creates a contact. ```typescript let contactId: string try { contactId = (await contact.linkLogin(collectionId, userId)).contactId } catch (err) { if (err.statusCode !== 404) throw err contactId = (await contact.create(collectionId, { userId, source: 'my-service' })).contactId } ```
|
|
13810
13904
|
|
|
13811
13905
|
### containers
|
|
13812
13906
|
|
|
@@ -14888,6 +14982,9 @@ One of your app's declared channels (manifest `realtime.channels`). ```ts const
|
|
|
14888
14982
|
**onChange**(scope: RealtimeScope, filter: RealtimeChangeFilter, onChangeFn: (change: RealtimeChangeEvent) → `void`
|
|
14889
14983
|
Something changed: refetch it. IDs only — never data. Admins of the collection see every change; everyone else sees changes to public things (public app records, products). Filter by `type` ('product' | 'proof' | 'asset' | 'record' | 'collection' | 'collection.apps' | 'settings'), `id`, `appId`, `recordType`, `productId`, `proofId`. ```ts const off = realtime.onChange({ collectionId }, { type: "record", appId, recordType: "entry" }, () => refetch()) ```
|
|
14890
14984
|
|
|
14985
|
+
**onStaffChange**(scope: RealtimeScope & { appId: string }, filter: RealtimeChangeFilter, onChangeFn: (change: RealtimeChangeEvent) → `void`
|
|
14986
|
+
Something this APP works on changed: one of its work orders, a container or stock it moved, or one of its own records. For the people who use the app, admins or not: someone hears these when they are in one of the app's user groups (the ones its server functions are limited to, or `realtime.staff` in its manifest), and so does a collection admin. IDs only — refetch through your own API. Types: 'workOrder' (`id`, `appId`), 'container' (`id`, `kind` = its container type), 'stock' (`id` = the container, `productId`), 'record' (`id`, `recordType`). Filter as with `onChange`; an empty filter hears them all. ```ts // A production app's screens refetch when anything on the floor changes. useEffect(() => realtime.onStaffChange({ collectionId, appId }, {}, () => queryClient.invalidateQueries()), [collectionId, appId]) ```
|
|
14987
|
+
|
|
14891
14988
|
**onMine**(scope: RealtimeScope, onMessage: (msg: RealtimeMessage) → `void`
|
|
14892
14989
|
Messages for the signed-in person only (e.g. "scan" — a tag they just scanned on another device).
|
|
14893
14990
|
|
|
@@ -219,6 +219,25 @@ A relative path (from the app's public root) to the `app.admin.json` file. Omit
|
|
|
219
219
|
"admin": "app.admin.json"
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
+
#### `adminPage`
|
|
223
|
+
|
|
224
|
+
The page a host opens as the app's **admin screen**, from the app's root: `"admin.html"` or `"index.html"`.
|
|
225
|
+
Studio, the console and Forge's preview read it rather than guess. Omit it to take the host's default:
|
|
226
|
+
|
|
227
|
+
| App | Default admin page |
|
|
228
|
+
|-----|--------------------|
|
|
229
|
+
| An installed app | `admin.html` |
|
|
230
|
+
| A core app (`core-<name>`, one of Studio's own sections) | the root page, `index.html` |
|
|
231
|
+
|
|
232
|
+
Declare it when the default is wrong. AuthKit (`core-account`) is the example: its root page is the
|
|
233
|
+
**public sign-in screen** every site sends people to, so its admin lives at `admin.html`:
|
|
234
|
+
|
|
235
|
+
```json
|
|
236
|
+
"adminPage": "admin.html"
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Never move a public page off the root to make room for the admin: sign-in links and embeds point at the root.
|
|
240
|
+
|
|
222
241
|
#### `widgets`
|
|
223
242
|
|
|
224
243
|
Declares the widget bundle. Omit if the app has no widget component.
|
|
@@ -37,6 +37,10 @@ and change them through change sets. The declarations make it *good* at your app
|
|
|
37
37
|
The files sit in `public/assistant/` in your project and ship with every release like any other static
|
|
38
38
|
file (they are read from the release's CDN folder, on the channel the collection runs your app on).
|
|
39
39
|
|
|
40
|
+
The same block also says **what your app's data means** to the assistant (`purpose`, `objects`, `words`,
|
|
41
|
+
`recipes`): which standard objects are what in your app, and which may only be changed through your
|
|
42
|
+
actions. See **[assistant-context.md](assistant-context.md)**.
|
|
43
|
+
|
|
40
44
|
### How they are loaded
|
|
41
45
|
|
|
42
46
|
When an admin opens a chat, the assistant's box gets the **index** of every installed app's skills: one
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Telling the assistant what your app's data means
|
|
2
|
+
|
|
3
|
+
SmartLinks keeps a business's data in standard objects: work orders, containers and stock, bookings,
|
|
4
|
+
records, contacts, history. The assistant can read all of them. What it can't know is what they **mean in
|
|
5
|
+
your app**: that a work order is a job, that a container of type `drum` is a drum of juice, that a
|
|
6
|
+
booking with `data.event = "christmas-fair"` is a stall at the school fair.
|
|
7
|
+
|
|
8
|
+
Tell it, in the manifest's `assistant` block, beside any skills and knowledge files
|
|
9
|
+
([assistant-apps.md](assistant-apps.md)). Four keys:
|
|
10
|
+
|
|
11
|
+
```jsonc
|
|
12
|
+
// app.manifest.json
|
|
13
|
+
"assistant": {
|
|
14
|
+
"purpose": "Production manager for a fragrance filling and decorating factory: jobs from sales order to put-away.",
|
|
15
|
+
"objects": [
|
|
16
|
+
{
|
|
17
|
+
"object": "workOrder",
|
|
18
|
+
"where": { "appId": "accord-production" },
|
|
19
|
+
"means": "A job.",
|
|
20
|
+
"fields": {
|
|
21
|
+
"ref": "job number, from the sales order",
|
|
22
|
+
"kind": "job type: FillOnly, DecorateOnly, CompleteJob, PackagingOnly, Conversion",
|
|
23
|
+
"dueAt": "target date",
|
|
24
|
+
"data.stage": "the stage shown on screen",
|
|
25
|
+
"stages": "picking, then decoration, filling, packaging (\"boxing\" on screen), wrapping"
|
|
26
|
+
},
|
|
27
|
+
"write": "actions"
|
|
28
|
+
},
|
|
29
|
+
{ "object": "container", "where": { "containerType": "drum" }, "means": "A drum of bulk juice; its ref is the batch number.", "write": "actions" },
|
|
30
|
+
{ "object": "container", "where": { "containerType": "location" }, "means": "A place in the factory.", "write": "direct" },
|
|
31
|
+
{ "object": "history", "where": { "type": "job.*" }, "means": "A job's timeline.", "write": "none" }
|
|
32
|
+
],
|
|
33
|
+
"words": {
|
|
34
|
+
"GMP": "the batch manufacturing record printed for each job",
|
|
35
|
+
"the diary": "production runs by day"
|
|
36
|
+
},
|
|
37
|
+
"recipes": [
|
|
38
|
+
{ "question": "What's on tomorrow?", "answer": "this app's work order stages planned for that day, by stage; show machine or crew" },
|
|
39
|
+
{ "question": "Which jobs are late?", "answer": "use the action jobs.late: it applies the app's own rule for late" }
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
| Key | What it is | Limit |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `purpose` | One line on what the app or site is for. The assistant always has it in view. | 200 characters |
|
|
47
|
+
| `objects` | What each standard object means here, and whether the assistant may change it. | 20 |
|
|
48
|
+
| `words` | The business's own terms. | 40 |
|
|
49
|
+
| `recipes` | How to answer the questions people actually ask. | 30 |
|
|
50
|
+
|
|
51
|
+
All four together: at most 6,000 characters. The assistant reads this every time a question touches your
|
|
52
|
+
app, so short wins. Anything malformed is left out and anything too long is cut (recipes first), without
|
|
53
|
+
an error: check what you wrote reads well.
|
|
54
|
+
|
|
55
|
+
## Objects
|
|
56
|
+
|
|
57
|
+
- **`object`**: the standard object: `workOrder`, `workOrderStage`, `container`, `stock`, `booking`,
|
|
58
|
+
`record`, `contact`, `product`, `history`.
|
|
59
|
+
- **`where`**: which ones, with the filters the SDK takes (`appId`, `containerType`, `recordType`,
|
|
60
|
+
`data.<field>`).
|
|
61
|
+
- **`means`**: what it is here, in a sentence.
|
|
62
|
+
- **`fields`**: only the fields whose name doesn't say what they hold.
|
|
63
|
+
- **`write`**: may the assistant change it?
|
|
64
|
+
|
|
65
|
+
| `write` | Means |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `direct` | Through the API, as a planned change the person applies. |
|
|
68
|
+
| `actions` | **Only through one of your app's actions**, never another way. |
|
|
69
|
+
| `none` | Never. |
|
|
70
|
+
| absent | Nothing is said; the platform's usual rules apply. |
|
|
71
|
+
|
|
72
|
+
**Record types you declared in the `data` block don't need repeating.** The assistant gets their titles
|
|
73
|
+
and fields from there ([admin-lists-and-pickers.md](admin-lists-and-pickers.md)); add an `objects`
|
|
74
|
+
entry only to say what one means or to set its `write` rule.
|
|
75
|
+
|
|
76
|
+
## Actions, when changing something has rules
|
|
77
|
+
|
|
78
|
+
If creating or changing a thing involves rules that live in your code (a number from a counter, a check,
|
|
79
|
+
someone who must be told), don't describe the rules and hope: mark the object `"write": "actions"` and
|
|
80
|
+
give the assistant an **action** that does it. An action is one of your functions offered as a tool
|
|
81
|
+
([agent-tools.md](agent-tools.md)):
|
|
82
|
+
|
|
83
|
+
```jsonc
|
|
84
|
+
{
|
|
85
|
+
"name": "run.plan",
|
|
86
|
+
"trigger": { "type": "http", "methods": ["POST"] },
|
|
87
|
+
"agent": {
|
|
88
|
+
"tool": true,
|
|
89
|
+
"audience": ["assistant"],
|
|
90
|
+
"title": "Plan a production run",
|
|
91
|
+
"description": "Plan one stage of a job for a day, by hand or on a machine, with its crew.",
|
|
92
|
+
"input": { "type": "object", "properties": { "job": { "type": "string" }, "stage": { "type": "string" }, "date": { "type": "string" } }, "required": ["job", "stage", "date"] },
|
|
93
|
+
"approval": "require"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Your rules then run in code every time. Keep actions few and coarse: one "find jobs" with filters, not
|
|
99
|
+
five narrow ones. Use `"approval": "require"` for anything that changes or sends something: the person
|
|
100
|
+
confirms it on a card.
|
|
101
|
+
|
|
102
|
+
## A site speaks for the business
|
|
103
|
+
|
|
104
|
+
A site is the business's own app, so its description is about the **business**:
|
|
105
|
+
|
|
106
|
+
- its `purpose` leads the assistant's map of the business;
|
|
107
|
+
- it may describe objects that **other installed apps** keep. Narrow them with `where.appId`:
|
|
108
|
+
|
|
109
|
+
```jsonc
|
|
110
|
+
{ "object": "booking", "where": { "appId": "appointment-booking", "data.event": "christmas-fair" }, "means": "A stall at the Christmas fair." }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- where the site and an app describe the same object, the site's meaning comes first.
|
|
114
|
+
|
|
115
|
+
So "how many bookings for the Christmas fair?" is answered from the right bookings.
|
|
116
|
+
|
|
117
|
+
## Types
|
|
118
|
+
|
|
119
|
+
`AppAssistantDeclaration` (`purpose`, `objects`, `words`, `recipes`), `AssistantObject`, `AssistantRecipe`.
|
package/dist/docs/realtime.md
CHANGED
|
@@ -37,6 +37,26 @@ off()
|
|
|
37
37
|
- **A change carries ids, never data.** Refetch through the normal API, which applies the normal
|
|
38
38
|
permissions, so realtime can never show someone data they couldn't read anyway.
|
|
39
39
|
|
|
40
|
+
### Changes to what your app works on: `onStaffChange`
|
|
41
|
+
|
|
42
|
+
Work orders, containers and stock aren't public and aren't only for admins: the people on a production
|
|
43
|
+
floor or in a warehouse need to see them move. Those changes go to the app's **staff feed**:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// Every screen of a production app refetches when a job, a container or stock changes.
|
|
47
|
+
const off = realtime.onStaffChange({ collectionId, appId }, {}, () => queryClient.invalidateQueries())
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **Types:** `workOrder` (`id`, `appId`), `container` (`id`, `kind` = its container type), `stock`
|
|
51
|
+
(`id` = the container, `productId`). Filter as with `onChange`: `{ type: 'workOrder', id }`.
|
|
52
|
+
- **What is sent:** a change to one of the app's work orders; a change to a container or stock made
|
|
53
|
+
**by the app's own server functions**; and a change to one of the app's own records (`type: 'record'`,
|
|
54
|
+
with `recordType`), except a person's private ones. Sent after the change is saved, each thing once.
|
|
55
|
+
- **Who hears it:** someone in one of the app's user groups, and collection admins. By default the
|
|
56
|
+
groups are the ones the app's server functions are limited to (`userGroups` on each function).
|
|
57
|
+
To say otherwise, name them: `"realtime": { "staff": ["manager", "warehouse-operative"] }`.
|
|
58
|
+
- **IDs only**, as always: refetch through your own functions, which apply your own rules.
|
|
59
|
+
|
|
40
60
|
With React Query, invalidate on change:
|
|
41
61
|
|
|
42
62
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export type { AdminCardViewProps, AdminCardTodoItem } from './adminCardsView.js'
|
|
|
20
20
|
export { normaliseAdminCardPayload, ADMIN_CARD_MAX_BYTES } from './adminCardPayload.js';
|
|
21
21
|
export { SHARED_DEPENDENCY_CONTRACT_VERSION, SHARED_DEPENDENCIES, SHARED_DEPENDENCY_SPECIFIERS, importMapPathFor, getHostSharedDependencies, } from './shared-dependencies.js';
|
|
22
22
|
export type { SharedDependency, HostSharedDependencies } from './shared-dependencies.js';
|
|
23
|
+
export type { GuideSurface, GuideInfo, ScreenContent, GuideWhere, GuideNavigate, GuideCard, GuideStartOptions } from './api/aiGuide.js';
|
|
24
|
+
export type { LiveState, LiveHandle, LiveOptions, LiveEndpoints, LiveEvent, LiveMintReply, LiveToolReply, LiveToolHandler } from './live.js';
|
|
23
25
|
export { AI_TOOL_NAMES, BUILTIN_AI_TOOLS, getBuiltinAiTool } from './ai-tools.js';
|
|
24
26
|
export type { BuiltinAiToolDescriptor } from './ai-tools.js';
|
|
25
27
|
export type { PortalPathParams, Gs1DigitalLinkParams, ConditionParams, ConditionDebugOptions, ConditionDebugLogger, ConditionSet, Condition, UserInfo, ProductInfo, ProofInfo, CollectionInfo, } from './utils/index.js';
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,5 @@ export { createAdminCardViews, collectAdminCardTodo, adminCardAge, injectAdminCa
|
|
|
27
27
|
export { normaliseAdminCardPayload, ADMIN_CARD_MAX_BYTES } from './adminCardPayload.js';
|
|
28
28
|
// Shared dependency contract (host↔app) — one source of truth for externalized deps
|
|
29
29
|
export { SHARED_DEPENDENCY_CONTRACT_VERSION, SHARED_DEPENDENCIES, SHARED_DEPENDENCY_SPECIFIERS, importMapPathFor, getHostSharedDependencies, } from './shared-dependencies.js';
|
|
30
|
-
// Built-in AI tool catalog (design-time discovery of the core agentic toolset)
|
|
31
30
|
export { AI_TOOL_NAMES, BUILTIN_AI_TOOLS, getBuiltinAiTool } from './ai-tools.js';
|
|
32
31
|
export { HostCapabilityUnavailableError, HostPermissionDeniedError, HostTimeoutError, HostCancelledError, } from './mobile-admin/errors.js';
|