@proveanything/smartlinks 2.1.17 → 2.1.18

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 (48) hide show
  1. package/dist/adminViews.d.ts +85 -0
  2. package/dist/adminViews.js +259 -0
  3. package/dist/api/index.d.ts +2 -0
  4. package/dist/api/index.js +2 -0
  5. package/dist/api/operations.d.ts +36 -0
  6. package/dist/api/operations.js +56 -0
  7. package/dist/api/order.d.ts +12 -1
  8. package/dist/api/order.js +15 -0
  9. package/dist/api/userGroups.d.ts +78 -0
  10. package/dist/api/userGroups.js +124 -0
  11. package/dist/docs/API_SUMMARY.md +604 -42
  12. package/dist/docs/admin-views.md +125 -0
  13. package/dist/docs/app-manifest.md +2 -0
  14. package/dist/docs/operations.md +281 -0
  15. package/dist/docs/overview.md +3 -0
  16. package/dist/docs/server-functions.md +18 -0
  17. package/dist/docs/user-groups.md +168 -0
  18. package/dist/docs/utils.md +17 -0
  19. package/dist/http.js +4 -0
  20. package/dist/iframeResponder.d.ts +15 -0
  21. package/dist/iframeResponder.js +39 -1
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.js +2 -0
  24. package/dist/openapi.yaml +1238 -276
  25. package/dist/testing/index.d.ts +13 -0
  26. package/dist/testing/index.js +55 -0
  27. package/dist/types/appManifest.d.ts +83 -0
  28. package/dist/types/containers.d.ts +8 -0
  29. package/dist/types/iframeResponder.d.ts +16 -1
  30. package/dist/types/index.d.ts +2 -0
  31. package/dist/types/index.js +2 -0
  32. package/dist/types/operations.d.ts +598 -0
  33. package/dist/types/operations.js +8 -0
  34. package/dist/types/order.d.ts +35 -6
  35. package/dist/types/userGroups.d.ts +103 -0
  36. package/dist/types/userGroups.js +5 -0
  37. package/dist/utils/conditions.d.ts +7 -0
  38. package/dist/utils/conditions.js +16 -9
  39. package/docs/API_SUMMARY.md +604 -42
  40. package/docs/admin-views.md +125 -0
  41. package/docs/app-manifest.md +2 -0
  42. package/docs/operations.md +281 -0
  43. package/docs/overview.md +3 -0
  44. package/docs/server-functions.md +18 -0
  45. package/docs/user-groups.md +168 -0
  46. package/docs/utils.md +17 -0
  47. package/openapi.yaml +1238 -276
  48. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import type { AppFunctionDef, ServerFunctionContext, ServerFunctionInputs } from '../types/appManifest.js';
2
+ import type { WorkOrdersApi, StockApi, BomsApi, MadeFromApi, OperationsApi } from '../types/operations.js';
2
3
  import { type BookingsMemory } from './bookingsMemory.js';
3
4
  export declare class CapabilityError extends Error {
4
5
  capability: string;
@@ -69,6 +70,16 @@ export interface TestSlImpl {
69
70
  * time, idempotent creates, holds) — inspect it via `ctx.memory.bookings`.
70
71
  */
71
72
  bookings?: Record<string, any>;
73
+ /**
74
+ * Work orders, stock, bills of materials and made-from (docs/operations.md). There is no in-memory
75
+ * engine for these: give the methods your function calls, and any other call returns a stub echo.
76
+ * The harness still enforces both production gates: the capability, and collection authority.
77
+ */
78
+ workOrders?: Partial<WorkOrdersApi>;
79
+ stock?: Partial<StockApi>;
80
+ boms?: Partial<BomsApi>;
81
+ madeFrom?: Partial<MadeFromApi>;
82
+ operations?: Partial<OperationsApi>;
72
83
  }
73
84
  export interface TestCaller {
74
85
  userId?: string | null;
@@ -77,6 +88,8 @@ export interface TestCaller {
77
88
  anonymous?: boolean;
78
89
  origin?: string | null;
79
90
  ip?: string | null;
91
+ /** Keys of the user groups the caller is in, for `ctx.caller.userGroups`. Default: none. */
92
+ userGroups?: string[];
80
93
  }
81
94
  export interface CreateFunctionTestContextOptions {
82
95
  /** The manifest declaration under test — its `capabilities` are the enforced envelope. */
@@ -407,6 +407,60 @@ export function createFunctionTestContext(opts) {
407
407
  for (const m of ['create', 'query', 'delete']) {
408
408
  sl.bookings.blocks[m] = gated('bookings', m === 'query' ? 'read' : 'write', bkFn(bk.blocks, m), `bookings.blocks.${m}`);
409
409
  }
410
+ // Work orders, stock, bills of materials, made-from: capability + collection authority, as in production.
411
+ const OPERATIONS = {
412
+ workOrders: { resource: 'workorders', reads: ['get', 'list'], writes: ['create', 'update', 'setStatus', 'remove', 'startStage', 'progress', 'completeStage', 'skipStage', 'planStage', 'setStages'] },
413
+ stock: { resource: 'stock', reads: ['lines', 'totals', 'where', 'position', 'short'], writes: ['receive', 'produce', 'consume', 'move', 'allocate', 'release', 'hold', 'unhold', 'adjust'] },
414
+ boms: { resource: 'boms', reads: ['current', 'versions', 'whereUsed', 'explode'], writes: ['set', 'end'] },
415
+ madeFrom: { resource: 'madefrom', reads: ['of', 'usedIn', 'trace'], writes: ['record', 'end'] },
416
+ };
417
+ const triggerType = (def.trigger && def.trigger.type) || 'http';
418
+ const hasCollectionAuthority = triggerType !== 'http' || def.authority === 'collection';
419
+ const needAuthority = () => {
420
+ if (!hasCollectionAuthority)
421
+ throw Object.assign(new Error('This needs collection authority: declare the function with authority "collection"'), { code: 'NEEDS_COLLECTION_AUTHORITY', status: 403 });
422
+ };
423
+ for (const [group, g] of Object.entries(OPERATIONS)) {
424
+ sl[group] = {};
425
+ const given = impl[group] || {};
426
+ for (const m of [...g.reads, ...g.writes]) {
427
+ const op = g.reads.includes(m) ? 'read' : 'write';
428
+ sl[group][m] = async (...args) => {
429
+ if (!allowsSl(parsed, g.resource, op))
430
+ throw new CapabilityError(`sl:${g.resource}:${op}`);
431
+ needAuthority();
432
+ return typeof given[m] === 'function' ? given[m](...args) : stub(`${group}.${m}`, args);
433
+ };
434
+ }
435
+ }
436
+ sl.operations = {
437
+ // Each step must be a write this function may make; with no impl, the steps run one by one through
438
+ // the methods above (so your stand-ins are called), without the all-or-nothing the platform gives.
439
+ transaction: async (steps) => {
440
+ if (!Array.isArray(steps) || !steps.length)
441
+ throw Object.assign(new Error('A transaction needs at least one step'), { code: 'INVALID_INPUT' });
442
+ for (const st of steps) {
443
+ const [group, m] = String((st && st.op) || '').split('.');
444
+ const g = OPERATIONS[group];
445
+ if (!g || ![...g.reads, ...g.writes].includes(m))
446
+ throw Object.assign(new Error(`There is no "${st && st.op}"`), { code: 'UNKNOWN_OP' });
447
+ if (g.reads.includes(m))
448
+ throw Object.assign(new Error(`${st.op} only reads. Do reads outside the transaction`), { code: 'INVALID_INPUT' });
449
+ if (!allowsSl(parsed, g.resource, 'write'))
450
+ throw new CapabilityError(`sl:${g.resource}:write`);
451
+ }
452
+ needAuthority();
453
+ const own = impl.operations && impl.operations.transaction;
454
+ if (typeof own === 'function')
455
+ return own(steps);
456
+ const results = [];
457
+ for (const st of steps) {
458
+ const [group, m] = st.op.split('.');
459
+ results.push(await sl[group][m](...(st.args || [])));
460
+ }
461
+ return { results };
462
+ },
463
+ };
410
464
  const secretsMap = opts.secrets || {};
411
465
  const baseFetch = opts.fetch || (typeof fetch !== 'undefined' ? fetch : undefined);
412
466
  const via = (def.trigger && def.trigger.type) || 'http';
@@ -434,6 +488,7 @@ export function createFunctionTestContext(opts) {
434
488
  origin: (_f = caller.origin) !== null && _f !== void 0 ? _f : null,
435
489
  ip: (_g = caller.ip) !== null && _g !== void 0 ? _g : null,
436
490
  via,
491
+ userGroups: Object.freeze([...(caller.userGroups || [])]),
437
492
  },
438
493
  fetch: (async (input, init) => {
439
494
  let host = '';
@@ -4,6 +4,7 @@ import type { AppDataDeclaration, AppHeadlessDeclaration } from './headless.js';
4
4
  import type { RealtimeChannelDeclaration } from './realtime.js';
5
5
  import type { AppManifestAdminCards } from './adminCards.js';
6
6
  import type { PaginatedResponse } from './appObjects.js';
7
+ import type { WorkOrdersApi, StockApi, BomsApi, MadeFromApi, OperationsApi } from './operations.js';
7
8
  import type { Booking, BookingSlot, BookingAllocation, CreateBookingInput, UpdateBookingInput, MoveBookingInput, BookingListQueryParams, CreateSlotInput, UpdateSlotInput, SlotListQueryParams, CreateBlockInput, BlockListQueryParams, FreeBusyQuery, FreeBusyResponse, MessageBookersInput, MessageBookersResult } from './bookings.js';
8
9
  /**
9
10
  * A bundle (widget or container) as returned by the collection widgets endpoint.
@@ -295,6 +296,13 @@ export interface AppFunctionDef {
295
296
  * without it, install/validation fails. Ignored for any other visibility/authority combo.
296
297
  */
297
298
  elevated?: boolean;
299
+ /**
300
+ * `http` only. Who may call it: the caller must be signed in and in at least ONE of these user
301
+ * groups (by key, e.g. `['qc-controller', 'manager']`), or be a collection admin. Checked by the
302
+ * platform before any of your code runs: anyone else gets `403 NOT_IN_USER_GROUP` (`401
303
+ * SIGN_IN_REQUIRED` when not signed in). Absent = no user group limit. See docs/user-groups.md.
304
+ */
305
+ userGroups?: string[];
298
306
  /**
299
307
  * Least-privilege capabilities this function needs, surfaced at install for
300
308
  * consent and capped at runtime — even for `collection`-authority functions.
@@ -538,6 +546,23 @@ export interface AppHistoryQuery {
538
546
  limit?: number;
539
547
  }
540
548
  export interface ServerFunctionSl {
549
+ /**
550
+ * Work orders: what work is under way (`sl:workorders:read` / `:write`). Any app may read a work
551
+ * order; only the app that owns it may change it. Needs `authority: 'collection'`. See docs/operations.md.
552
+ */
553
+ workOrders: WorkOrdersApi;
554
+ /**
555
+ * Stock: how much of a product is in each container, changed only through movements, and a product's
556
+ * position (`sl:stock:read` / `:write`). Shared by every app in the collection. Needs
557
+ * `authority: 'collection'`.
558
+ */
559
+ stock: StockApi;
560
+ /** Bills of materials: what a product is made of (`sl:boms:read` / `:write`). Needs `authority: 'collection'`. */
561
+ boms: BomsApi;
562
+ /** What a batch or item was really made from (`sl:madefrom:read` / `:write`). Needs `authority: 'collection'`. */
563
+ madeFrom: MadeFromApi;
564
+ /** Several work order, stock, bill of materials and made-from writes, all or nothing. */
565
+ operations: OperationsApi;
541
566
  /** THIS app's bookings, slots and blocks (`sl:bookings:read` / `sl:bookings:write`). */
542
567
  bookings: ServerFunctionBookings;
543
568
  /**
@@ -664,6 +689,12 @@ export interface ServerFunctionCaller {
664
689
  ip?: string | null;
665
690
  /** How the function was triggered. */
666
691
  via: AppFunctionTriggerType;
692
+ /**
693
+ * Keys of the user groups the caller is in, e.g. `['qc-controller', 'warehouse']`. Empty when nobody
694
+ * is signed in (and for `event`/`cron`). Use it for finer rules than the declaration's `userGroups`
695
+ * allows ("a manager may also override"). See docs/user-groups.md.
696
+ */
697
+ userGroups: readonly string[];
667
698
  }
668
699
  /** The signed-in caller's own contact, as a server function sees it (`ctx.sl.contacts.forCaller()`). */
669
700
  export interface CallerContact {
@@ -881,6 +912,52 @@ export interface PublicView {
881
912
  /** The params the caller supplies via the URL. */
882
913
  params?: PublicViewParams;
883
914
  }
915
+ /**
916
+ * One ADMIN VIEW of the app: a screen of its admin side that a host or the assistant can open by name
917
+ * ("the campaigns list", "one campaign", "bookings for a day"). An app declares them once, in
918
+ * `app.manifest.json#adminViews`, and the same list drives three things:
919
+ * - the app's own side menu (`group` main and settings; see prove docs/design/core-app-layout.md),
920
+ * - Studio's workspace menu, which can carry an app's areas itself (it then opens the app with
921
+ * `chrome=none` and the app hides its own menu),
922
+ * - the Studio assistant, which opens a view while it talks (`smartlinks:navigate`).
923
+ * Admin views are NOT portal pages (`linkable`) and NOT standalone screens (`publicViews`).
924
+ * See docs/admin-views.md and `SL.adminViews`.
925
+ */
926
+ export interface AdminView {
927
+ /** Stable id, unique within the app (`campaigns`, `campaign`, `campaign.results`). Hosts keep it. */
928
+ id: string;
929
+ /** The label in a menu: short, the business's words ("Campaigns", "Message log"). */
930
+ title: string;
931
+ /**
932
+ * Hash route within the admin page, with `{name}` placeholders for the params it needs:
933
+ * `"/campaigns"`, `"/campaigns/{campaignId}"`, `"/day/{date}"`.
934
+ */
935
+ path: string;
936
+ /**
937
+ * Where the view sits:
938
+ * - `main` (default): an area in the side menu, in declared order;
939
+ * - `settings`: pinned at the bottom of the menu;
940
+ * - `record`: inside one record (a campaign, a product). Not in the main menu: opening the record
941
+ * swaps the menu for the record's own views, headed by "← back to" its `within` area.
942
+ */
943
+ group?: 'main' | 'settings' | 'record';
944
+ /**
945
+ * The view this one sits inside. A record's first view names its area (`campaign` within
946
+ * `campaigns`); the record's other views name the record's first view (`campaign.results` within
947
+ * `campaign`).
948
+ */
949
+ within?: string;
950
+ /** A Lucide icon name, kebab-case (`megaphone`, `scroll-text`, `package`). */
951
+ icon?: string;
952
+ /** One line on what the screen shows, for the assistant ("Every message sent and what happened to it"). */
953
+ description?: string;
954
+ /**
955
+ * The params the view takes, each with a few words on what it is (`{ campaignId: "a campaign's id",
956
+ * status: "draft | scheduled | sent" }`). A `{name}` in `path` is required; any other is optional
957
+ * and travels as a query param. Platform context (collectionId, appId, …) is never listed.
958
+ */
959
+ params?: Record<string, string>;
960
+ }
884
961
  export interface AppManifest {
885
962
  $schema?: string;
886
963
  meta?: {
@@ -980,6 +1057,12 @@ export interface AppManifest {
980
1057
  * See PublicView + docs/design/public-views.md.
981
1058
  */
982
1059
  publicViews?: PublicView[];
1060
+ /**
1061
+ * The app's ADMIN VIEWS: its admin screens by name, in menu order. They drive the app's own side
1062
+ * menu, Studio's workspace menu and the assistant's "open this screen". @see AdminView ·
1063
+ * docs/admin-views.md
1064
+ */
1065
+ adminViews?: AdminView[];
983
1066
  /**
984
1067
  * Executor bundle declaration. Present when the app ships a programmatic executor
985
1068
  * for AI-driven configuration, server-side SEO, and LLM content generation.
@@ -41,6 +41,11 @@ export interface Container {
41
41
  metadata?: Record<string, any>;
42
42
  /** UUID of the parent container; `undefined` / `null` for top-level containers */
43
43
  parentContainerId?: string;
44
+ /**
45
+ * A place that doesn't move (a site, a rack, a bin) rather than something carried (a pallet, a drum).
46
+ * "Where is this pallet?" is the first fixed container above it. Default `false`.
47
+ */
48
+ fixed?: boolean;
44
49
  /** Recursively nested children — populated only when `?tree=true` */
45
50
  children?: Container[];
46
51
  /** Current (or historical) items — populated only when `?includeContents=true` */
@@ -91,6 +96,8 @@ export interface CreateContainerInput {
91
96
  metadata?: Record<string, any>;
92
97
  /** UUID of the parent container; omit to create a top-level container */
93
98
  parentContainerId?: string;
99
+ /** A place that doesn't move (a bin), rather than something carried (a pallet). Default `false`. */
100
+ fixed?: boolean;
94
101
  }
95
102
  /**
96
103
  * Request body for `PATCH /containers/:id`.
@@ -105,6 +112,7 @@ export interface UpdateContainerInput {
105
112
  metadata?: Record<string, any>;
106
113
  /** Pass `null` to promote the container to top-level. */
107
114
  parentContainerId?: string | null;
115
+ fixed?: boolean;
108
116
  }
109
117
  /** Request body for `POST /containers/:id/items` — adds items to a container. */
110
118
  export interface AddContainerItemsInput {
@@ -36,6 +36,21 @@ export interface IframeResponderOptions {
36
36
  onAuthLogin?: (token: string, user: any, accountData?: Record<string, any>) => Promise<void>;
37
37
  onAuthLogout?: () => Promise<void>;
38
38
  onRouteChange?: (path: string, state: Record<string, string>) => void;
39
+ /**
40
+ * The app said it follows `smartlinks:navigate` (docs/admin-views.md): from now on `navigate()` moves
41
+ * it without a reload. `views` are the ids it declared.
42
+ */
43
+ onNavigable?: (info: {
44
+ views: string[];
45
+ chrome: 'none' | 'full';
46
+ }) => void;
47
+ /** The app's answer to a `navigate()`: where it went, or why it couldn't. */
48
+ onNavigateResult?: (result: {
49
+ ok: boolean;
50
+ view: string | null;
51
+ path: string | null;
52
+ reason?: string;
53
+ }) => void;
39
54
  /**
40
55
  * Size the iframe to the app's content, for an app placed in a page (a booking form in a website, a
41
56
  * widget in a section): the page scrolls, never the iframe. The responder sets the iframe's height from
@@ -66,7 +81,7 @@ export interface RouteChangeMessage {
66
81
  }
67
82
  export interface SmartlinksIframeMessage {
68
83
  _smartlinksIframeMessage: true;
69
- type: 'smartlinks:resize' | 'smartlinks:redirect' | 'smartlinks:authkit:login' | 'smartlinks:authkit:logout' | 'smartlinks:authkit:redirect';
84
+ type: 'smartlinks:resize' | 'smartlinks:redirect' | 'smartlinks:authkit:login' | 'smartlinks:authkit:logout' | 'smartlinks:authkit:redirect' | 'smartlinks:navigable' | 'smartlinks:navigate-result';
70
85
  payload: Record<string, any>;
71
86
  messageId?: string;
72
87
  }
@@ -15,6 +15,8 @@ export * from "./itemContext.js";
15
15
  export * from "./contact.js";
16
16
  export * from "./broadcasts.js";
17
17
  export * from "./segments.js";
18
+ export * from "./userGroups.js";
19
+ export * from "./operations.js";
18
20
  export * from "./common.js";
19
21
  export * from "./journeys.js";
20
22
  export * from "./journeysAnalytics.js";
@@ -17,6 +17,8 @@ export * from "./itemContext.js";
17
17
  export * from "./contact.js";
18
18
  export * from "./broadcasts.js";
19
19
  export * from "./segments.js";
20
+ export * from "./userGroups.js";
21
+ export * from "./operations.js";
20
22
  export * from "./common.js";
21
23
  export * from "./journeys.js";
22
24
  export * from "./journeysAnalytics.js";