@proveanything/smartlinks 2.1.20 → 2.1.23

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.
Files changed (47) hide show
  1. package/dist/adminCardsView.d.ts +1 -1
  2. package/dist/adminCardsView.js +70 -55
  3. package/dist/api/appObjects.d.ts +26 -0
  4. package/dist/api/appObjects.js +31 -1
  5. package/dist/api/conditions.d.ts +51 -0
  6. package/dist/api/conditions.js +57 -0
  7. package/dist/api/contact.d.ts +83 -1
  8. package/dist/api/contact.js +104 -0
  9. package/dist/api/index.d.ts +1 -0
  10. package/dist/api/index.js +1 -0
  11. package/dist/api/products.d.ts +22 -0
  12. package/dist/api/products.js +29 -0
  13. package/dist/api/proof.d.ts +30 -0
  14. package/dist/api/proof.js +37 -0
  15. package/dist/api/realtime.d.ts +19 -0
  16. package/dist/api/realtime.js +26 -1
  17. package/dist/docs/API_SUMMARY.md +396 -170
  18. package/dist/docs/admin-cards.md +1 -1
  19. package/dist/docs/app-manifest.md +19 -0
  20. package/dist/docs/assistant-apps.md +4 -0
  21. package/dist/docs/assistant-context.md +119 -0
  22. package/dist/docs/realtime.md +20 -0
  23. package/dist/docs/standard-query.md +187 -0
  24. package/dist/docs/utils.md +22 -8
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.js +0 -1
  27. package/dist/openapi.yaml +675 -0
  28. package/dist/types/adminCards.d.ts +2 -1
  29. package/dist/types/appManifest.d.ts +64 -1
  30. package/dist/types/contact.d.ts +55 -0
  31. package/dist/types/index.d.ts +1 -0
  32. package/dist/types/index.js +1 -0
  33. package/dist/types/query.d.ts +121 -0
  34. package/dist/types/query.js +5 -0
  35. package/dist/types/realtime.d.ts +7 -1
  36. package/dist/utils/conditions.d.ts +1 -1
  37. package/dist/utils/conditions.js +21 -6
  38. package/docs/API_SUMMARY.md +396 -170
  39. package/docs/admin-cards.md +1 -1
  40. package/docs/app-manifest.md +19 -0
  41. package/docs/assistant-apps.md +4 -0
  42. package/docs/assistant-context.md +119 -0
  43. package/docs/realtime.md +20 -0
  44. package/docs/standard-query.md +187 -0
  45. package/docs/utils.md +22 -8
  46. package/openapi.yaml +675 -0
  47. package/package.json +1 -1
@@ -102,12 +102,13 @@ export interface AdminCardPayload {
102
102
  total: number;
103
103
  label?: string;
104
104
  };
105
- /** A short list — at most 5 are shown. */
105
+ /** A short list — at most 5 are shown. `image` (https) is a small picture beside the row, e.g. a product photo. */
106
106
  items?: Array<{
107
107
  title: string;
108
108
  subtitle?: string;
109
109
  meta?: string;
110
110
  path?: string;
111
+ image?: string;
111
112
  }>;
112
113
  /** Things that need doing — collected into the dashboard's To do strip. */
113
114
  todo?: Array<{
@@ -1244,6 +1244,14 @@ export interface AppManifest {
1244
1244
  * Absent when the app has no admin UI.
1245
1245
  */
1246
1246
  admin?: string;
1247
+ /**
1248
+ * The page a host opens as this app's ADMIN screen, from the app's root: `"admin.html"` or
1249
+ * `"index.html"`. Hosts (Studio, the console, Forge's preview) read it instead of guessing.
1250
+ * Absent → the host's default: `admin.html` for an installed app, the root page (`index.html`) for a
1251
+ * core app. Declare it when that default is wrong — e.g. AuthKit (`core-account`), whose root page
1252
+ * is the PUBLIC sign-in screen every site redirects to, and whose admin is `admin.html`.
1253
+ */
1254
+ adminPage?: string;
1247
1255
  /** Widget bundle definition. Presence means a widget bundle exists for this app. */
1248
1256
  widgets?: AppManifestWidgets;
1249
1257
  /** Container bundle definition. Presence means a container bundle exists. */
@@ -1297,7 +1305,13 @@ export interface AppManifest {
1297
1305
  * ```
1298
1306
  */
1299
1307
  realtime?: {
1300
- channels: RealtimeChannelDeclaration[];
1308
+ channels?: RealtimeChannelDeclaration[];
1309
+ /**
1310
+ * Who hears changes to what this app works on (`realtime.onStaffChange`: its work orders, the
1311
+ * containers and stock it moves), as user group keys. Absent: every user group the app's server
1312
+ * functions are limited to. `[]`: nobody but collection admins.
1313
+ */
1314
+ staff?: string[];
1301
1315
  };
1302
1316
  /**
1303
1317
  * Cards this app adds to the collection's dashboard in Studio. A `data` card names an ADMIN server
@@ -1376,6 +1390,55 @@ export interface AppAssistantDeclaration {
1376
1390
  * Relative to the app's admin surface, e.g. `"/admin/preview?changeSet={id}"`.
1377
1391
  */
1378
1392
  preview?: string;
1393
+ /**
1394
+ * One line (≤ 200 characters): what this app or site is for. Always in the assistant's view, in the
1395
+ * line for this app: "Production manager for a fragrance filling and decorating factory".
1396
+ */
1397
+ purpose?: string;
1398
+ /**
1399
+ * What each standard object MEANS in this app ("a work order here is a job"), and whether the
1400
+ * assistant may change it directly or only through one of the app's actions. Up to 20. Record types
1401
+ * declared in the manifest's `data` block needn't be repeated: the assistant gets their titles and
1402
+ * fields from there. @see AssistantObject
1403
+ */
1404
+ objects?: AssistantObject[];
1405
+ /** The business's own terms: `{ "GMP": "the batch manufacturing record printed for each job" }`. Up to 40. */
1406
+ words?: Record<string, string>;
1407
+ /** How to answer the questions people actually ask. Up to 30. @see AssistantRecipe */
1408
+ recipes?: AssistantRecipe[];
1409
+ }
1410
+ /**
1411
+ * What one standard object means in this app. A SITE may also describe objects other installed apps
1412
+ * keep (narrow them with `where: { appId }`); there, what the site says wins over the app's own words.
1413
+ */
1414
+ export interface AssistantObject {
1415
+ /** The standard object: `workOrder`, `workOrderStage`, `container`, `stock`, `booking`, `record`, `contact`, `product`, `history`. */
1416
+ object: string;
1417
+ /**
1418
+ * Which ones, with the same filters the SDK takes: `{ appId: "accord-production" }`,
1419
+ * `{ containerType: "drum" }`, `{ recordType: "smell-test" }`, `{ "data.event": "christmas-fair" }`.
1420
+ */
1421
+ where?: Record<string, string | number | boolean>;
1422
+ /** What it is here, in a sentence (≤ 300 characters): "A job." */
1423
+ means: string;
1424
+ /** What its fields hold, where the name doesn't say: `{ "ref": "job number", "data.stage": "the stage shown on screen" }`. Up to 20. */
1425
+ fields?: Record<string, string>;
1426
+ /**
1427
+ * May the assistant change it?
1428
+ * - `direct`: through the API, as a planned change the person applies;
1429
+ * - `actions`: ONLY through one of this app's actions (functions with `agent.tool`), because the
1430
+ * app's rules live in its code (numbering, checks, who is told);
1431
+ * - `none`: never.
1432
+ * Absent: nothing is said (the platform's usual rules apply).
1433
+ */
1434
+ write?: 'direct' | 'actions' | 'none';
1435
+ }
1436
+ /** One common question and how to answer it: an object query in plain words, or the action that knows. */
1437
+ export interface AssistantRecipe {
1438
+ /** The question as people ask it (≤ 160 characters): "What's on tomorrow?" */
1439
+ question: string;
1440
+ /** How to answer (≤ 400 characters): "work order stages of this app planned for that day, by stage; show machine or crew". */
1441
+ answer: string;
1379
1442
  }
1380
1443
  /** One field of a connector's "Connect" form. */
1381
1444
  export interface ConnectorConnectionField {
@@ -34,6 +34,61 @@ export interface ContactListResponse {
34
34
  limit: number;
35
35
  offset: number;
36
36
  }
37
+ /**
38
+ * Two contacts that look like one person (`contact.findDuplicates`): `keep` has a sign-in but no email
39
+ * (or phone); `merge` has no sign-in and holds that sign-in's verified email (or phone).
40
+ */
41
+ export interface ContactDuplicatePair {
42
+ /** The contact with the sign-in — the one `contact.merge` should keep. */
43
+ keep: Contact;
44
+ /** The contact holding the address — the one to fold into `keep`. */
45
+ merge: Contact;
46
+ /** What ties them together. */
47
+ matchedOn: "email" | "phone";
48
+ }
49
+ export interface ContactDuplicatesResponse {
50
+ pairs: ContactDuplicatePair[];
51
+ /** How many contacts with a sign-in were checked in this call. */
52
+ scanned: number;
53
+ /** More contacts remain beyond this window: call again with `offset` + `scanned`. */
54
+ more: boolean;
55
+ }
56
+ /** What `contact.merge` did. */
57
+ export interface ContactMergeResponse {
58
+ /** The contact that was kept. */
59
+ contactId: string;
60
+ /** The contact that was retired (soft-deleted, marked `customFields.mergedInto`). */
61
+ mergedFrom: string;
62
+ moved: {
63
+ /** The sign-in moved onto the kept contact. */
64
+ login: boolean;
65
+ /** Emails and phones moved across. */
66
+ identities: number;
67
+ records?: number;
68
+ cases?: number;
69
+ threads?: number;
70
+ bookings?: number;
71
+ loyaltyMembers?: number;
72
+ assets?: number;
73
+ uploadTokens?: number;
74
+ aiSessions?: number;
75
+ /** One-to-one messages and Inbox conversations with them. */
76
+ messages?: number;
77
+ conversations?: number;
78
+ };
79
+ /** The kept contact after the merge. */
80
+ contact: Contact;
81
+ }
82
+ /** What `contact.linkLogin` found. */
83
+ export interface ContactLinkLoginResponse {
84
+ /** The contact that carries the sign-in. */
85
+ contactId: string;
86
+ /** True when this call attached the sign-in to that contact (or merged a duplicate into it). */
87
+ linked: boolean;
88
+ contact: Contact;
89
+ }
90
+ /** `error` codes `contact.merge` can refuse with. */
91
+ export type ContactMergeErrorCode = "INVALID_CONTACT" | "SAME_CONTACT" | "NOT_FOUND" | "KEEP_DELETED" | "LOGIN_CONFLICT" | "LOYALTY_CONFLICT";
37
92
  export interface ContactSearchParams {
38
93
  collectionId: string;
39
94
  q?: string;
@@ -18,6 +18,7 @@ export * from "./segments.js";
18
18
  export * from "./userGroups.js";
19
19
  export * from "./operations.js";
20
20
  export * from "./common.js";
21
+ export * from "./query.js";
21
22
  export * from "./journeys.js";
22
23
  export * from "./journeysAnalytics.js";
23
24
  export * from "./qr.js";
@@ -20,6 +20,7 @@ export * from "./segments.js";
20
20
  export * from "./userGroups.js";
21
21
  export * from "./operations.js";
22
22
  export * from "./common.js";
23
+ export * from "./query.js";
23
24
  export * from "./journeys.js";
24
25
  export * from "./journeysAnalytics.js";
25
26
  export * from "./qr.js";
@@ -0,0 +1,121 @@
1
+ /** A value a field can be compared with. Dates are ISO 8601 strings. */
2
+ export type QueryValue = string | number | boolean;
3
+ /** How one field is tested. Several tests on one field must all hold. */
4
+ export interface QueryFieldTest {
5
+ eq?: QueryValue;
6
+ ne?: QueryValue;
7
+ gt?: QueryValue;
8
+ gte?: QueryValue;
9
+ lt?: QueryValue;
10
+ lte?: QueryValue;
11
+ /** One of these values (1 to 100). */
12
+ in?: QueryValue[];
13
+ /** None of these values (1 to 100). */
14
+ nin?: QueryValue[];
15
+ /** Text containing this, in any case. */
16
+ contains?: string;
17
+ /** Text starting with this, in any case. */
18
+ startsWith?: string;
19
+ /** true: the field is empty. false: it has a value. */
20
+ isNull?: boolean;
21
+ /** A list field (e.g. a contact's tags) holds this value. */
22
+ has?: string;
23
+ /** A list field holds at least one of these. */
24
+ hasAny?: string[];
25
+ /** A list field holds all of these. */
26
+ hasAll?: string[];
27
+ }
28
+ /**
29
+ * A keyed field (e.g. a product's `facets`) is filtered key by key: `{ brand: "Breville" }` or
30
+ * `{ category: { in: ["Toasters", "Kettles"] } }`. Every key must match.
31
+ */
32
+ export type QueryKeyedTest = Record<string, QueryValue | {
33
+ eq?: QueryValue;
34
+ in?: QueryValue[];
35
+ }>;
36
+ /**
37
+ * What to match. Each entry is `field: value` (equal to) or `field: { op: value }`; all entries must
38
+ * hold. `and`, `or` and `not` combine further conditions (nested up to 4 levels).
39
+ *
40
+ * A document field (an app record's `data`) is reached by path, as a field name: `"data.status"`.
41
+ */
42
+ export interface QueryWhere {
43
+ and?: QueryWhere[];
44
+ or?: QueryWhere[];
45
+ not?: QueryWhere;
46
+ [field: string]: QueryValue | QueryFieldTest | QueryKeyedTest | QueryWhere | QueryWhere[] | undefined;
47
+ }
48
+ /** One total. `count` counts rows; the others take a field (or a path into a document). */
49
+ export type QueryAggregate = {
50
+ count: true;
51
+ } | {
52
+ countDistinct: string;
53
+ } | {
54
+ sum: string;
55
+ } | {
56
+ avg: string;
57
+ } | {
58
+ min: string;
59
+ } | {
60
+ max: string;
61
+ };
62
+ /** The standard query body. Everything is optional: an empty query returns the first page. */
63
+ export interface StandardQuery {
64
+ where?: QueryWhere;
65
+ /** e.g. `[{ createdAt: "desc" }]`. Only fields that can be sorted on (never an empty-able one). */
66
+ orderBy?: Array<Record<string, 'asc' | 'desc'>>;
67
+ /** Rows per page (1 to 200, default 50), or groups (1 to 500) with groupBy / aggregates. */
68
+ limit?: number;
69
+ /** `nextCursor` from the previous page, with the same `where` and `orderBy`. */
70
+ cursor?: string | null;
71
+ /** Which fields to return. A path into a document can be selected: `"data.status"`. */
72
+ select?: string[];
73
+ /** Also return how many rows match `where` in all (not just this page). */
74
+ count?: boolean;
75
+ /** Group rows by up to 3 fields (or document paths). Returns groups, not rows. */
76
+ groupBy?: string[];
77
+ /** Named totals, e.g. `{ owners: { countDistinct: "userId" } }`. Returns groups, not rows. */
78
+ aggregates?: Record<string, QueryAggregate>;
79
+ /**
80
+ * Follow a link and return the linked thing inside each row: `["product", "owner"]`, or with the
81
+ * fields wanted `{ owner: ["firstName", "email"] }`. Rows only. Null where there is nothing linked.
82
+ */
83
+ expand?: string[] | Record<string, string[] | true>;
84
+ }
85
+ /** A page of rows. */
86
+ export interface QueryRows<T = Record<string, unknown>> {
87
+ items: T[];
88
+ /** Pass as `cursor` for the next page; null on the last page. */
89
+ nextCursor: string | null;
90
+ /** Present when the query asked for `count: true`. */
91
+ count?: number;
92
+ }
93
+ /** The answer to a query with `groupBy` and/or `aggregates`. */
94
+ export interface QueryGroups<G = Record<string, unknown>> {
95
+ groups: G[];
96
+ /** True when there were more groups than `limit`. */
97
+ more: boolean;
98
+ }
99
+ export type QueryResult<T = Record<string, unknown>, G = Record<string, unknown>> = QueryRows<T> | QueryGroups<G>;
100
+ /** What a resource's query can use (from `GET …/query`). */
101
+ export interface QueryDescription {
102
+ name: string;
103
+ fields: Record<string, {
104
+ type: 'string' | 'number' | 'boolean' | 'date' | 'list' | 'keyed' | 'json';
105
+ about?: string;
106
+ can: string[];
107
+ }>;
108
+ count: boolean;
109
+ aggregates: boolean;
110
+ links: Record<string, {
111
+ to: string;
112
+ by: string;
113
+ about?: string;
114
+ }>;
115
+ limits: {
116
+ limit: number;
117
+ groups: number;
118
+ };
119
+ /** The query shape in a few lines of plain words. */
120
+ shape: string;
121
+ }
@@ -0,0 +1,5 @@
1
+ // src/types/query.ts
2
+ //
3
+ // The STANDARD QUERY: one request body for filtering, sorting, paging, counting and totalling, the same
4
+ // on every resource that takes it (proofs, contacts, products, app records). See docs/standard-query.md.
5
+ export {};
@@ -57,7 +57,10 @@ export interface RealtimeMessage {
57
57
  }
58
58
  /** "This changed" — ids only; refetch through the normal API. */
59
59
  export interface RealtimeChangeEvent {
60
- /** 'product' | 'proof' | 'asset' | 'record' | 'collection' | 'collection.apps' | 'settings' | … */
60
+ /**
61
+ * 'product' | 'proof' | 'asset' | 'record' | 'collection' | 'collection.apps' | 'settings' | …
62
+ * and, on an app's staff feed (`onStaffChange`): 'workOrder' | 'container' | 'stock'.
63
+ */
61
64
  type: string;
62
65
  id?: string;
63
66
  appId?: string;
@@ -66,6 +69,8 @@ export interface RealtimeChangeEvent {
66
69
  proofId?: string;
67
70
  /** 'created' | 'updated' | 'deleted' (records) or 'create' | 'update' | 'delete' (products, proofs…) */
68
71
  status?: string;
72
+ /** A container's type ("drum", "pallet"), on a 'container' change. */
73
+ kind?: string;
69
74
  at: number;
70
75
  }
71
76
  /** Which changes to hear about — every field given must match. */
@@ -76,6 +81,7 @@ export interface RealtimeChangeFilter {
76
81
  recordType?: string;
77
82
  productId?: string;
78
83
  proofId?: string;
84
+ kind?: string;
79
85
  }
80
86
  /** A channel an app declares in its manifest (`realtime.channels`). */
81
87
  export interface RealtimeChannelDeclaration {
@@ -296,7 +296,7 @@ export interface ConditionParams {
296
296
  itemContext?: ItemContext;
297
297
  /** Statistics/tracking information */
298
298
  stats?: StatsInfo;
299
- /** Function to fetch conditions by ID (optional) */
299
+ /** Load a saved condition by id (optional; by default the collection's saved conditions are read with `conditions.get`) */
300
300
  fetchCondition?: (collectionId: string, conditionId: string) => Promise<ConditionSet | null>;
301
301
  /** Function to get user's current location (optional) */
302
302
  getLocation?: () => Promise<{
@@ -1,4 +1,5 @@
1
1
  // src/utils/conditions.ts
2
+ import { request } from '../http.js';
2
3
  /**
3
4
  * Geographic region definitions for country-based conditions
4
5
  */
@@ -16,6 +17,15 @@ export const REGION_COUNTRIES = {
16
17
  };
17
18
  // Condition cache
18
19
  const conditionCache = {};
20
+ /** The default loader: a collection's saved condition, from the public API; null when there isn't one. */
21
+ async function fetchSavedCondition(collectionId, conditionId) {
22
+ try {
23
+ return await request(`/public/collection/${encodeURIComponent(collectionId)}/condition/${encodeURIComponent(conditionId)}`);
24
+ }
25
+ catch (_a) {
26
+ return null;
27
+ }
28
+ }
19
29
  const CONDITION_DEBUG_GLOBAL_KEY = 'SMARTLINKS_CONDITION_DEBUG';
20
30
  function defaultConditionDebugLogger(...args) {
21
31
  if (typeof console === 'undefined')
@@ -227,7 +237,7 @@ async function evaluateConditionEntry(condition, params) {
227
237
  * ```
228
238
  */
229
239
  export async function validateCondition(params) {
230
- var _a, _b, _c;
240
+ var _a, _b, _c, _d;
231
241
  const internalParams = params;
232
242
  (_a = internalParams.__conditionDebugState) !== null && _a !== void 0 ? _a : (internalParams.__conditionDebugState = resolveConditionDebugState(params));
233
243
  const debugState = internalParams.__conditionDebugState;
@@ -242,9 +252,9 @@ export async function validateCondition(params) {
242
252
  // Check cache first
243
253
  if (!conditionCache[params.conditionId]) {
244
254
  logConditionDebug(debugState, 'Condition cache miss.', { conditionId: params.conditionId });
245
- // Try to fetch if function provided
246
- if (params.fetchCondition && params.collection) {
247
- const fetchedCond = await params.fetchCondition(params.collection.id, params.conditionId);
255
+ // Fetch it: the caller's own loader, else the collection's saved conditions
256
+ if (params.collection) {
257
+ const fetchedCond = await ((_b = params.fetchCondition) !== null && _b !== void 0 ? _b : fetchSavedCondition)(params.collection.id, params.conditionId);
248
258
  if (fetchedCond) {
249
259
  conditionCache[params.conditionId] = fetchedCond;
250
260
  logConditionDebug(debugState, 'Fetched condition into cache.', {
@@ -259,7 +269,7 @@ export async function validateCondition(params) {
259
269
  return true;
260
270
  }
261
271
  // Prevent infinite recursion
262
- (_b = params.conditionStack) !== null && _b !== void 0 ? _b : (params.conditionStack = []);
272
+ (_c = params.conditionStack) !== null && _c !== void 0 ? _c : (params.conditionStack = []);
263
273
  params.conditionStack.push(params.conditionId);
264
274
  cond = conditionCache[params.conditionId];
265
275
  }
@@ -268,12 +278,17 @@ export async function validateCondition(params) {
268
278
  conditionSet: cond ? summarizeConditionSet(cond) : 'none',
269
279
  });
270
280
  }
281
+ // A switched-off condition passes for everyone
282
+ if (cond === null || cond === void 0 ? void 0 : cond.disabled) {
283
+ logConditionDebug(debugState, 'Condition is switched off; passing.');
284
+ return true;
285
+ }
271
286
  if (!cond) {
272
287
  logConditionDebug(debugState, 'Resolved condition set is empty; passing by default.');
273
288
  return true;
274
289
  }
275
290
  // Default to AND logic
276
- const conditionType = (_c = cond.type) !== null && _c !== void 0 ? _c : 'and';
291
+ const conditionType = (_d = cond.type) !== null && _d !== void 0 ? _d : 'and';
277
292
  // Empty condition set passes
278
293
  if (!cond.conditions || cond.conditions.length === 0) {
279
294
  logConditionDebug(debugState, 'Condition set has no entries; passing by default.', {