@proveanything/smartlinks 2.1.17 → 2.1.19

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 (80) hide show
  1. package/dist/adminViews.d.ts +104 -0
  2. package/dist/adminViews.js +275 -0
  3. package/dist/api/ai.d.ts +15 -5
  4. package/dist/api/ai.js +15 -9
  5. package/dist/api/aiGuide.d.ts +108 -0
  6. package/dist/api/aiGuide.js +161 -0
  7. package/dist/api/appObjects.d.ts +21 -0
  8. package/dist/api/appObjects.js +33 -1
  9. package/dist/api/authKit.d.ts +37 -1
  10. package/dist/api/authKit.js +51 -0
  11. package/dist/api/index.d.ts +2 -0
  12. package/dist/api/index.js +2 -0
  13. package/dist/api/operations.d.ts +36 -0
  14. package/dist/api/operations.js +56 -0
  15. package/dist/api/order.d.ts +12 -1
  16. package/dist/api/order.js +15 -0
  17. package/dist/api/userGroups.d.ts +78 -0
  18. package/dist/api/userGroups.js +124 -0
  19. package/dist/docs/API_SUMMARY.md +1111 -80
  20. package/dist/docs/admin-lists-and-pickers.md +140 -0
  21. package/dist/docs/admin-views.md +147 -0
  22. package/dist/docs/app-data-storage.md +277 -276
  23. package/dist/docs/app-manifest.md +2 -0
  24. package/dist/docs/auth-kit.md +872 -741
  25. package/dist/docs/comms.md +686 -644
  26. package/dist/docs/customer-guide.md +70 -0
  27. package/dist/docs/headless-providers.md +112 -112
  28. package/dist/docs/operations.md +281 -0
  29. package/dist/docs/overview.md +3 -0
  30. package/dist/docs/server-functions.md +87 -1
  31. package/dist/docs/ui-utils.md +123 -121
  32. package/dist/docs/user-groups.md +175 -0
  33. package/dist/docs/utils.md +17 -0
  34. package/dist/headless.js +38 -2
  35. package/dist/http.js +8 -0
  36. package/dist/iframeResponder.d.ts +15 -0
  37. package/dist/iframeResponder.js +39 -1
  38. package/dist/index.d.ts +3 -1
  39. package/dist/index.js +2 -0
  40. package/dist/live.d.ts +80 -0
  41. package/dist/live.js +315 -0
  42. package/dist/openapi.yaml +1864 -48
  43. package/dist/testing/index.d.ts +35 -0
  44. package/dist/testing/index.js +86 -0
  45. package/dist/types/appManifest.d.ts +297 -1
  46. package/dist/types/appOptions.d.ts +32 -0
  47. package/dist/types/appOptions.js +3 -0
  48. package/dist/types/authKit.d.ts +193 -4
  49. package/dist/types/comms.d.ts +41 -2
  50. package/dist/types/containers.d.ts +8 -0
  51. package/dist/types/headless.d.ts +49 -1
  52. package/dist/types/iframeResponder.d.ts +16 -1
  53. package/dist/types/index.d.ts +3 -0
  54. package/dist/types/index.js +3 -0
  55. package/dist/types/operations.d.ts +598 -0
  56. package/dist/types/operations.js +8 -0
  57. package/dist/types/order.d.ts +35 -6
  58. package/dist/types/userGroups.d.ts +103 -0
  59. package/dist/types/userGroups.js +5 -0
  60. package/dist/utils/conditions.d.ts +7 -0
  61. package/dist/utils/conditions.js +16 -9
  62. package/docs/API_SUMMARY.md +1111 -80
  63. package/docs/admin-lists-and-pickers.md +140 -0
  64. package/docs/admin-views.md +147 -0
  65. package/docs/app-data-storage.md +277 -276
  66. package/docs/app-manifest.md +2 -0
  67. package/docs/auth-kit.md +872 -741
  68. package/docs/comms.md +686 -644
  69. package/docs/customer-guide.md +70 -0
  70. package/docs/headless-providers.md +112 -112
  71. package/docs/operations.md +281 -0
  72. package/docs/overview.md +3 -0
  73. package/docs/server-functions.md +87 -1
  74. package/docs/ui-utils.md +123 -121
  75. package/docs/user-groups.md +175 -0
  76. package/docs/utils.md +17 -0
  77. package/openapi.yaml +1864 -48
  78. package/package.json +1 -1
  79. package/scripts/doctor.mjs +454 -428
  80. package/scripts/lib/keyed-app-data.mjs +21 -0
@@ -0,0 +1,161 @@
1
+ // The customer guide, and "what's on my screen" for AI (browser side of prove docs/design/customer-assistant.md).
2
+ //
3
+ // ai.guide.get(collectionId, surface) is the guide on here, its name, modes and opening questions
4
+ // ai.guide.start(collectionId, options) a live conversation with it, by voice or by text
5
+ // ai.content.provide(handler) an app says what its screen shows, in words
6
+ // ai.content.request(options) a host asks the app on screen what it shows
7
+ //
8
+ // The guide runs as the visitor (anonymous, or signed in with Auth Kit). Everything that shapes it — its
9
+ // instructions, voice and tools — is fixed by SmartLinks when the conversation starts; the page only says
10
+ // where the visitor is and what is on their screen.
11
+ import { post, request } from '../http.js';
12
+ import { startLive } from '../live.js';
13
+ const base = (collectionId) => `/public/collection/${encodeURIComponent(collectionId)}/ai/guide`;
14
+ export var guide;
15
+ (function (guide) {
16
+ /** Is the guide on for this surface, and how does it present itself? */
17
+ async function get(collectionId, surface) {
18
+ return request(`${base(collectionId)}${surface ? `?surface=${surface}` : ''}`);
19
+ }
20
+ guide.get = get;
21
+ /** Start a live conversation with the guide. Resolves once connected; the handle pauses, stops, sends text. */
22
+ async function start(collectionId, options) {
23
+ let handoff = null;
24
+ const language = options.language || (typeof navigator !== 'undefined' ? (navigator.language || '').split('-')[0] : '') || undefined;
25
+ const screenTools = {
26
+ read_screen: async () => {
27
+ var _a;
28
+ const s = options.readScreen ? await options.readScreen() : await content.request({ timeoutMs: 1500 });
29
+ return s && s.content ? { title: (_a = s.title) !== null && _a !== void 0 ? _a : null, content: String(s.content).slice(0, 12000) } : { error: 'Nothing to read on the screen right now.' };
30
+ },
31
+ show_app: async (args) => {
32
+ var _a, _b;
33
+ if (!options.showApp)
34
+ return { error: "That can't be opened from here." };
35
+ await options.showApp(String((_a = args['appId']) !== null && _a !== void 0 ? _a : ''));
36
+ return { opened: String((_b = args['appId']) !== null && _b !== void 0 ? _b : '') };
37
+ },
38
+ go_to: async (args) => {
39
+ var _a;
40
+ const id = String((_a = args['productId']) !== null && _a !== void 0 ? _a : '');
41
+ if (!id)
42
+ return { error: 'Which product?' };
43
+ if (!options.goTo)
44
+ return { error: "That can't be opened from here." };
45
+ await options.goTo(id);
46
+ return { opened: id };
47
+ },
48
+ offer_person: async () => {
49
+ var _a;
50
+ if (!handoff)
51
+ return { error: 'There is no way to reach a person set up.' };
52
+ await ((_a = options.offerPerson) === null || _a === void 0 ? void 0 : _a.call(options, handoff));
53
+ return { shown: handoff.kind };
54
+ },
55
+ };
56
+ const opts = {
57
+ mode: options.mode,
58
+ build: 'sdk-guide-1',
59
+ screenTools,
60
+ endpoints: {
61
+ mint: async () => {
62
+ var _a, _b, _c;
63
+ const reply = await post(`${base(collectionId)}/session`, {
64
+ surface: options.surface,
65
+ mode: options.mode,
66
+ productId: (_a = options.productId) !== null && _a !== void 0 ? _a : undefined,
67
+ proofId: (_b = options.proofId) !== null && _b !== void 0 ? _b : undefined,
68
+ apps: options.apps,
69
+ where: options.where,
70
+ language,
71
+ screen: options.screen,
72
+ });
73
+ handoff = (_c = reply.handoff) !== null && _c !== void 0 ? _c : null;
74
+ return reply;
75
+ },
76
+ tool: (name, args, sessionId) => post(`${base(collectionId)}/tool`, { name, args, sessionId }),
77
+ event: (event) => { void post(`${base(collectionId)}/event`, event).catch(() => undefined); },
78
+ },
79
+ onToolReply: async (_name, reply) => {
80
+ var _a, _b;
81
+ if (reply['show'])
82
+ (_a = options.onShow) === null || _a === void 0 ? void 0 : _a.call(options, reply['show']);
83
+ if (reply['navigate'])
84
+ await ((_b = options.openPage) === null || _b === void 0 ? void 0 : _b.call(options, reply['navigate']));
85
+ },
86
+ onState: options.onState,
87
+ onCaption: options.onCaption,
88
+ onReply: options.onReply,
89
+ onError: options.onError,
90
+ };
91
+ return startLive(opts);
92
+ }
93
+ guide.start = start;
94
+ })(guide || (guide = {}));
95
+ const REQUEST = 'smartlinks:ai-content-request';
96
+ const REPLY = 'smartlinks:ai-content';
97
+ const local = new Set();
98
+ export var content;
99
+ (function (content) {
100
+ /**
101
+ * An app says what its screen shows, in words (an exhibit's text, a recipe, a form's purpose). Called
102
+ * whenever an assistant needs it. Works in an iframe (the host asks by message) and in the same page
103
+ * (a direct component). Returns a function that stops providing.
104
+ */
105
+ function provide(handler) {
106
+ local.add(handler);
107
+ let onMessage = null;
108
+ if (typeof window !== 'undefined' && window.parent && window.parent !== window) {
109
+ onMessage = (e) => {
110
+ const d = e.data;
111
+ if (e.source !== window.parent || !d || d.type !== REQUEST || !d.id)
112
+ return;
113
+ void Promise.resolve(handler({ reason: d.reason }))
114
+ .catch(() => null)
115
+ .then((c) => window.parent.postMessage({ type: REPLY, id: d.id, content: c !== null && c !== void 0 ? c : null }, '*'));
116
+ };
117
+ window.addEventListener('message', onMessage);
118
+ }
119
+ return () => {
120
+ local.delete(handler);
121
+ if (onMessage)
122
+ window.removeEventListener('message', onMessage);
123
+ };
124
+ }
125
+ content.provide = provide;
126
+ /**
127
+ * A host asks what the app on screen shows: an app in an iframe (pass its window as `frame`), or apps in
128
+ * this page that called `provide`. Resolves null if nothing answers within the time.
129
+ */
130
+ async function request(options = {}) {
131
+ var _a;
132
+ const timeoutMs = (_a = options.timeoutMs) !== null && _a !== void 0 ? _a : 1000;
133
+ if (options.frame) {
134
+ const frame = options.frame;
135
+ const id = Math.random().toString(36).slice(2);
136
+ return new Promise((resolve) => {
137
+ const done = (c) => { clearTimeout(timer); window.removeEventListener('message', onMessage); resolve(c); };
138
+ const onMessage = (e) => {
139
+ var _a;
140
+ const d = e.data;
141
+ if (e.source === frame && d && d.type === REPLY && d.id === id)
142
+ done((_a = d.content) !== null && _a !== void 0 ? _a : null);
143
+ };
144
+ const timer = setTimeout(() => done(null), timeoutMs);
145
+ window.addEventListener('message', onMessage);
146
+ frame.postMessage({ type: REQUEST, id, reason: options.reason }, '*');
147
+ });
148
+ }
149
+ for (const handler of [...local].reverse()) {
150
+ const c = await Promise.race([
151
+ Promise.resolve(handler({ reason: options.reason })).catch(() => null),
152
+ new Promise((r) => setTimeout(() => r(null), timeoutMs)),
153
+ ]);
154
+ if (c && c.content)
155
+ return c;
156
+ }
157
+ return null;
158
+ }
159
+ content.request = request;
160
+ })(content || (content = {}));
161
+ export { startLive };
@@ -1,5 +1,26 @@
1
1
  import type { AppCase, CreateCaseInput, UpdateCaseInput, AppendHistoryInput, CaseSummaryRequest, CaseSummaryResponse, CaseListQueryParams, AppThread, CreateThreadInput, UpdateThreadInput, ReplyInput, ThreadListQueryParams, AppRecord, CreateRecordInput, CreateRecordResponse, UpdateRecordInput, UpsertRecordInput, UpsertRecordResponse, MatchRecordsInput, MatchResult, BulkUpsertItem, BulkUpsertResult, BulkDeleteResult, BulkDeleteInput, RecordListQueryParams, ResolveAllParams, ResolveAllResult, PreviewRuleParams, PreviewRuleResult, PaginatedResponse, AggregateRequest, AggregateResponse, RelatedResponse } from '../types/appObjects.js';
2
2
  export declare namespace app {
3
+ /**
4
+ * Pickers: the small, cached list behind "pick a machine" or "pick a hold reason".
5
+ * docs/admin-lists-and-pickers.md
6
+ */
7
+ namespace options {
8
+ /**
9
+ * `source` = `type:<record type or declared type id>` | `list:<list id>`. Admins (`admin: true`)
10
+ * see every entry; the public API lists public records and lists the app declares public. Hold on
11
+ * to `version` and pass it back to get `{ unchanged: true }` when nothing changed.
12
+ */
13
+ function get(collectionId: string, appId: string, source: string, opts?: {
14
+ q?: string;
15
+ version?: string;
16
+ admin?: boolean;
17
+ }): Promise<import('../types/appOptions.js').AppOptionsResponse>;
18
+ /**
19
+ * Save a value list's values, in order (admins). Codes never change and are never lost: a value left
20
+ * out stays, switched off, at the end. → the list as saved.
21
+ */
22
+ function saveList(collectionId: string, appId: string, listId: string, values: import('../types/appOptions.js').AppOptionValueInput[]): Promise<import('../types/appOptions.js').AppOptionsResponse>;
23
+ }
3
24
  namespace cases {
4
25
  /**
5
26
  * Create a new case
@@ -1,8 +1,40 @@
1
1
  // src/api/appObjects.ts
2
- import { request, post, patch, del } from '../http.js';
2
+ import { request, post, patch, del, put } from '../http.js';
3
3
  // ==================== APP NAMESPACE ====================
4
4
  export var app;
5
5
  (function (app) {
6
+ // ==================== OPTIONS (pickers) ====================
7
+ /**
8
+ * Pickers: the small, cached list behind "pick a machine" or "pick a hold reason".
9
+ * docs/admin-lists-and-pickers.md
10
+ */
11
+ let options;
12
+ (function (options) {
13
+ /**
14
+ * `source` = `type:<record type or declared type id>` | `list:<list id>`. Admins (`admin: true`)
15
+ * see every entry; the public API lists public records and lists the app declares public. Hold on
16
+ * to `version` and pass it back to get `{ unchanged: true }` when nothing changed.
17
+ */
18
+ async function get(collectionId, appId, source, opts = {}) {
19
+ const zone = opts.admin ? 'admin' : 'public';
20
+ const qs = new URLSearchParams();
21
+ if (opts.q)
22
+ qs.set('q', opts.q);
23
+ if (opts.version)
24
+ qs.set('version', opts.version);
25
+ const query = qs.toString();
26
+ return request(`/${zone}/collection/${encodeURIComponent(collectionId)}/app/${encodeURIComponent(appId)}/options/${encodeURIComponent(source)}${query ? `?${query}` : ''}`);
27
+ }
28
+ options.get = get;
29
+ /**
30
+ * Save a value list's values, in order (admins). Codes never change and are never lost: a value left
31
+ * out stays, switched off, at the end. → the list as saved.
32
+ */
33
+ async function saveList(collectionId, appId, listId, values) {
34
+ return put(`/admin/collection/${encodeURIComponent(collectionId)}/app/${encodeURIComponent(appId)}/options/${encodeURIComponent(`list:${listId}`)}`, { values });
35
+ }
36
+ options.saveList = saveList;
37
+ })(options = app.options || (app.options = {}));
6
38
  // ==================== CASES ====================
7
39
  let cases;
8
40
  (function (cases) {
@@ -1,4 +1,4 @@
1
- import type { AuthLoginResponse, AppleLoginOptions, MicrosoftLoginOptions, RefreshResponse, LogoutResponse, PhoneSendCodeResponse, PhoneVerifyResponse, PasswordResetRequestResponse, VerifyResetTokenResponse, PasswordResetCompleteResponse, EmailVerificationActionResponse, EmailVerifyTokenResponse, AuthKitConfig, AuthKitConfigInput, AuthKitSetIdentityResponse, AuthKitInviteRequest, AuthKitInviteResponse, MagicLinkSendResponse, MagicLinkVerifyResponse, UserProfile, UpdateProfileResponse, ProfileUpdateData, SuccessResponse, SendWhatsAppRequest, SendWhatsAppResponse, ExchangeWhatsAppSessionResponse, VerifyWhatsAppResponse, WhatsAppStatusResponse, SendSmsVerifyRequest, SendSmsVerifyResponse, VerifySmsResponse, UpsertContactRequest, UpsertContactResponse, MfaChallengeSendResponse, MfaFinalizeResponse, MfaEnrollSendResponse, MfaTotpEnrollResponse, MfaEnrolledResponse, MfaFactor, MfaFactorsResponse, TrustedDevice } from "../types/authKit.js";
1
+ import type { AuthLoginResponse, AppleLoginOptions, MicrosoftLoginOptions, RefreshResponse, LogoutResponse, PhoneSendCodeResponse, PhoneVerifyResponse, PasswordResetRequestResponse, VerifyResetTokenResponse, PasswordResetCompleteResponse, EmailVerificationActionResponse, EmailVerifyTokenResponse, AuthKitConfig, AuthKitConfigInput, AuthKitSetIdentityResponse, AuthKitInviteRequest, AuthKitInviteResponse, AuthKitSchema, AuthKitSettingsResponse, AuthKitSetupRequest, AuthKitSetupResponse, AuthKitEmailKind, AuthKitEmailPreview, AuthKitSecretLink, MagicLinkSendResponse, MagicLinkVerifyResponse, UserProfile, UpdateProfileResponse, ProfileUpdateData, SuccessResponse, SendWhatsAppRequest, SendWhatsAppResponse, ExchangeWhatsAppSessionResponse, VerifyWhatsAppResponse, WhatsAppStatusResponse, SendSmsVerifyRequest, SendSmsVerifyResponse, VerifySmsResponse, UpsertContactRequest, UpsertContactResponse, MfaChallengeSendResponse, MfaFinalizeResponse, MfaEnrollSendResponse, MfaTotpEnrollResponse, MfaEnrolledResponse, MfaFactor, MfaFactorsResponse, TrustedDevice } from "../types/authKit.js";
2
2
  /**
3
3
  * Namespace containing helper functions for the new AuthKit API.
4
4
  * Legacy collection-based authKit helpers retained (marked as *Legacy*).
@@ -321,5 +321,41 @@ export declare namespace authKit {
321
321
  * this site's addresses), `TOO_MANY_INVITES` (429, 5 an hour per address).
322
322
  */
323
323
  function invite(collectionId: string, authKitId: string, body: AuthKitInviteRequest): Promise<AuthKitInviteResponse>;
324
+ /** Every sign-in setting: its path, default, what reads it (`screens` / `server` / `both`), in plain words. */
325
+ function schema(collectionId: string): Promise<AuthKitSchema>;
326
+ /**
327
+ * Set up the collection's sign-in in one call, safe to repeat: finds its sign-in (or makes one, with
328
+ * email + Google and confirm-then-signed-in, and makes it the collection's default), optionally gives it
329
+ * its own logins (ONE WAY — members of this site only; needed for invite-only) and saves a first
330
+ * settings patch. Errors: `INVALID_CONFIG` (400, `problems`), `OWN_LOGINS_REQUIRED` (409),
331
+ * `MEMBER_POOL_CONFLICT` (409), `SECRET_IN_SETTINGS` (400).
332
+ */
333
+ function setup(collectionId: string, body?: AuthKitSetupRequest): Promise<AuthKitSetupResponse>;
334
+ /** What sign-in does now: the stored config, every default filled in, which secrets are set (masked), and checks. */
335
+ function settings(collectionId: string, authKitId: string): Promise<AuthKitSettingsResponse>;
336
+ /**
337
+ * A one-time SmartLinks page where the PERSON types a secret (e.g. `linkedInClientSecret`) — so it never
338
+ * passes through a chat or your code. Give them the `url`; it works once, for 30 minutes. Asking again
339
+ * replaces the link. Check it landed with {@link settings} (`secrets.<name>.set`).
340
+ */
341
+ function secretEntryLink(collectionId: string, authKitId: string, name: string, opts?: {
342
+ label?: string;
343
+ }): Promise<AuthKitSecretLink>;
344
+ /** Store a secret you already hold (server-side code only — never ask a person to paste one to you). Returns the masked hint. */
345
+ function setSecret(collectionId: string, authKitId: string, name: string, value: string): Promise<{
346
+ name: string;
347
+ hint: string;
348
+ setAt: string;
349
+ }>;
350
+ /** Remove a secret (that provider then uses SmartLinks' own app). */
351
+ function removeSecret(collectionId: string, authKitId: string, name: string): Promise<{
352
+ name: string;
353
+ removed: true;
354
+ }>;
355
+ /**
356
+ * An account email as it would be sent now — or with draft settings (`emailTemplates`, `emailBranding`,
357
+ * `branding`; checked like a save, nothing stored). Sample values stand in for the person and the link.
358
+ */
359
+ function previewEmail(collectionId: string, authKitId: string, kind: AuthKitEmailKind, draft?: Pick<AuthKitConfigInput, 'emailTemplates' | 'emailBranding' | 'branding'>): Promise<AuthKitEmailPreview>;
324
360
  function remove(collectionId: string, authKitId: string): Promise<void>;
325
361
  }
@@ -583,6 +583,57 @@ export var authKit;
583
583
  return post(path, body);
584
584
  }
585
585
  authKit.invite = invite;
586
+ /* ===================================
587
+ * Setting up sign-in (admin) — everything an assistant needs; see docs/auth-kit.md "Setting up sign-in"
588
+ * =================================== */
589
+ /** Every sign-in setting: its path, default, what reads it (`screens` / `server` / `both`), in plain words. */
590
+ async function schema(collectionId) {
591
+ return request(`/admin/collection/${encodeURIComponent(collectionId)}/authKit/schema`);
592
+ }
593
+ authKit.schema = schema;
594
+ /**
595
+ * Set up the collection's sign-in in one call, safe to repeat: finds its sign-in (or makes one, with
596
+ * email + Google and confirm-then-signed-in, and makes it the collection's default), optionally gives it
597
+ * its own logins (ONE WAY — members of this site only; needed for invite-only) and saves a first
598
+ * settings patch. Errors: `INVALID_CONFIG` (400, `problems`), `OWN_LOGINS_REQUIRED` (409),
599
+ * `MEMBER_POOL_CONFLICT` (409), `SECRET_IN_SETTINGS` (400).
600
+ */
601
+ async function setup(collectionId, body = {}) {
602
+ return post(`/admin/collection/${encodeURIComponent(collectionId)}/authKit/setup`, body);
603
+ }
604
+ authKit.setup = setup;
605
+ /** What sign-in does now: the stored config, every default filled in, which secrets are set (masked), and checks. */
606
+ async function settings(collectionId, authKitId) {
607
+ return request(`/admin/collection/${encodeURIComponent(collectionId)}/authKit/${encodeURIComponent(authKitId)}/settings`);
608
+ }
609
+ authKit.settings = settings;
610
+ /**
611
+ * A one-time SmartLinks page where the PERSON types a secret (e.g. `linkedInClientSecret`) — so it never
612
+ * passes through a chat or your code. Give them the `url`; it works once, for 30 minutes. Asking again
613
+ * replaces the link. Check it landed with {@link settings} (`secrets.<name>.set`).
614
+ */
615
+ async function secretEntryLink(collectionId, authKitId, name, opts = {}) {
616
+ return post(`/admin/collection/${encodeURIComponent(collectionId)}/authKit/${encodeURIComponent(authKitId)}/secrets/${encodeURIComponent(name)}/link`, opts);
617
+ }
618
+ authKit.secretEntryLink = secretEntryLink;
619
+ /** Store a secret you already hold (server-side code only — never ask a person to paste one to you). Returns the masked hint. */
620
+ async function setSecret(collectionId, authKitId, name, value) {
621
+ return put(`/admin/collection/${encodeURIComponent(collectionId)}/authKit/${encodeURIComponent(authKitId)}/secrets/${encodeURIComponent(name)}`, { value });
622
+ }
623
+ authKit.setSecret = setSecret;
624
+ /** Remove a secret (that provider then uses SmartLinks' own app). */
625
+ async function removeSecret(collectionId, authKitId, name) {
626
+ return del(`/admin/collection/${encodeURIComponent(collectionId)}/authKit/${encodeURIComponent(authKitId)}/secrets/${encodeURIComponent(name)}`);
627
+ }
628
+ authKit.removeSecret = removeSecret;
629
+ /**
630
+ * An account email as it would be sent now — or with draft settings (`emailTemplates`, `emailBranding`,
631
+ * `branding`; checked like a save, nothing stored). Sample values stand in for the person and the link.
632
+ */
633
+ async function previewEmail(collectionId, authKitId, kind, draft = {}) {
634
+ return post(`/admin/collection/${encodeURIComponent(collectionId)}/authKit/${encodeURIComponent(authKitId)}/emails/${encodeURIComponent(kind)}/preview`, draft);
635
+ }
636
+ authKit.previewEmail = previewEmail;
586
637
  async function remove(collectionId, authKitId) {
587
638
  const path = `/admin/collection/${encodeURIComponent(collectionId)}/authKit/${encodeURIComponent(authKitId)}`;
588
639
  return del(path);
@@ -23,6 +23,8 @@ export { broadcasts } from "./broadcasts.js";
23
23
  export { async } from "./async.js";
24
24
  export { jobs } from "./jobs.js";
25
25
  export { segments } from "./segments.js";
26
+ export { userGroups } from "./userGroups.js";
27
+ export { operations } from "./operations.js";
26
28
  export { journeys } from "./journeys.js";
27
29
  export { journeysAnalytics } from "./journeysAnalytics.js";
28
30
  export { qr } from "./qr.js";
package/dist/api/index.js CHANGED
@@ -25,6 +25,8 @@ export { broadcasts } from "./broadcasts.js";
25
25
  export { async } from "./async.js";
26
26
  export { jobs } from "./jobs.js";
27
27
  export { segments } from "./segments.js";
28
+ export { userGroups } from "./userGroups.js";
29
+ export { operations } from "./operations.js";
28
30
  export { journeys } from "./journeys.js";
29
31
  export { journeysAnalytics } from "./journeysAnalytics.js";
30
32
  export { qr } from "./qr.js";
@@ -0,0 +1,36 @@
1
+ import type { OperationsAdmin } from "../types/operations.js";
2
+ /**
3
+ * Operations: work orders, stock, bills of materials and made-from, for admin screens.
4
+ *
5
+ * `operations.admin(collectionId)` gives the same calls a server function has as `ctx.sl.workOrders`,
6
+ * `ctx.sl.stock`, `ctx.sl.boms` and `ctx.sl.madeFrom`, with the same arguments and results.
7
+ *
8
+ * See docs/operations.md.
9
+ */
10
+ export declare namespace operations {
11
+ /**
12
+ * The operations objects for one collection (admin).
13
+ *
14
+ * @param opts.appId - the app a NEW work order belongs to. An admin may change any app's work order,
15
+ * but a work order is always created for an app, so `workOrders.create` needs this.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const ops = operations.admin('coll_123', { appId: 'production' })
20
+ *
21
+ * const caps = await ops.stock.position({ productId: 'brass-cap', horizonDays: 90 })
22
+ * caps.onHand.available // 400
23
+ * caps.shortfall // { quantity: 140, firstShortOn: '2026-12-14' } | null
24
+ *
25
+ * await ops.stock.move({ from: binId, to: cageId, productId: 'brass-cap', quantity: 100 })
26
+ * await ops.workOrders.setStatus('19264', 'on-hold', { reason: 'Waiting for caps' })
27
+ * ```
28
+ */
29
+ function admin(collectionId: string, opts?: {
30
+ appId?: string;
31
+ }): OperationsAdmin;
32
+ /** What the server offers, by group: `{ workOrders: [...], stock: [...], boms: [...], madeFrom: [...] }`. */
33
+ function describe(collectionId: string): Promise<{
34
+ groups: Record<string, string[]>;
35
+ }>;
36
+ }
@@ -0,0 +1,56 @@
1
+ import { request, post } from "../http.js";
2
+ /**
3
+ * Operations: work orders, stock, bills of materials and made-from, for admin screens.
4
+ *
5
+ * `operations.admin(collectionId)` gives the same calls a server function has as `ctx.sl.workOrders`,
6
+ * `ctx.sl.stock`, `ctx.sl.boms` and `ctx.sl.madeFrom`, with the same arguments and results.
7
+ *
8
+ * See docs/operations.md.
9
+ */
10
+ export var operations;
11
+ (function (operations) {
12
+ // What each group offers. The server refuses any name it doesn't know, so this list only decides
13
+ // what the handle exposes.
14
+ const GROUPS = {
15
+ workOrders: ['get', 'list', 'create', 'update', 'setStatus', 'remove', 'startStage', 'progress', 'completeStage', 'skipStage', 'planStage', 'setStages'],
16
+ stock: ['lines', 'totals', 'where', 'position', 'short', 'receive', 'produce', 'consume', 'move', 'allocate', 'release', 'hold', 'unhold', 'adjust'],
17
+ boms: ['current', 'versions', 'whereUsed', 'explode', 'set', 'end'],
18
+ madeFrom: ['of', 'usedIn', 'trace', 'record', 'end'],
19
+ };
20
+ const base = (collectionId) => `/admin/collection/${encodeURIComponent(collectionId)}/operations`;
21
+ /**
22
+ * The operations objects for one collection (admin).
23
+ *
24
+ * @param opts.appId - the app a NEW work order belongs to. An admin may change any app's work order,
25
+ * but a work order is always created for an app, so `workOrders.create` needs this.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const ops = operations.admin('coll_123', { appId: 'production' })
30
+ *
31
+ * const caps = await ops.stock.position({ productId: 'brass-cap', horizonDays: 90 })
32
+ * caps.onHand.available // 400
33
+ * caps.shortfall // { quantity: 140, firstShortOn: '2026-12-14' } | null
34
+ *
35
+ * await ops.stock.move({ from: binId, to: cageId, productId: 'brass-cap', quantity: 100 })
36
+ * await ops.workOrders.setStatus('19264', 'on-hold', { reason: 'Waiting for caps' })
37
+ * ```
38
+ */
39
+ function admin(collectionId, opts = {}) {
40
+ const qs = opts.appId ? `?appId=${encodeURIComponent(opts.appId)}` : '';
41
+ const group = (name) => Object.fromEntries(GROUPS[name].map((method) => [method, (...args) => post(`${base(collectionId)}/${name}/${method}${qs}`, { args })]));
42
+ return {
43
+ workOrders: group('workOrders'),
44
+ stock: group('stock'),
45
+ boms: group('boms'),
46
+ madeFrom: group('madeFrom'),
47
+ transaction: (steps) => post(`${base(collectionId)}/transaction${qs}`, { steps }),
48
+ };
49
+ }
50
+ operations.admin = admin;
51
+ /** What the server offers, by group: `{ workOrders: [...], stock: [...], boms: [...], madeFrom: [...] }`. */
52
+ async function describe(collectionId) {
53
+ return request(base(collectionId));
54
+ }
55
+ operations.describe = describe;
56
+ })(operations || (operations = {}));
@@ -1,4 +1,4 @@
1
- import { CreateOrderRequest, CreateOrderResponse, GetOrderParams, GetOrderResponse, UpdateOrderRequest, UpdateOrderResponse, DeleteOrderResponse, ListOrdersRequest, ListOrdersResponse, GetOrderItemsParams, GetOrderItemsResponse, AddItemsRequest, AddItemsResponse, RemoveItemsRequest, RemoveItemsResponse, QueryOrdersRequest, QueryOrdersResponse, ReportsParams, ReportsResponse, LookupOrdersRequest, LookupOrdersResponse, LookupByProductParams, LookupByProductResponse, OrderAnalyticsResponse, TimelineRequest, TimelineResponse, LocationRequest, LocationResponse, BulkAnalyticsRequest, BulkAnalyticsResponse, SummaryRequest, CollectionSummaryResponse, FindOrdersByAttributeParams, FindOrdersByAttributeResponse, FindItemsByAttributeParams, FindItemsByAttributeResponse, GetOrderIdsParams, GetOrderIdsResponse } from "../types/order.js";
1
+ import { OrderItem, CreateOrderRequest, CreateOrderResponse, GetOrderParams, GetOrderResponse, UpdateOrderRequest, UpdateOrderResponse, DeleteOrderResponse, ListOrdersRequest, ListOrdersResponse, GetOrderItemsParams, GetOrderItemsResponse, AddItemsRequest, AddItemsResponse, RemoveItemsRequest, RemoveItemsResponse, QueryOrdersRequest, QueryOrdersResponse, ReportsParams, ReportsResponse, LookupOrdersRequest, LookupOrdersResponse, LookupByProductParams, LookupByProductResponse, OrderAnalyticsResponse, TimelineRequest, TimelineResponse, LocationRequest, LocationResponse, BulkAnalyticsRequest, BulkAnalyticsResponse, SummaryRequest, CollectionSummaryResponse, FindOrdersByAttributeParams, FindOrdersByAttributeResponse, FindItemsByAttributeParams, FindItemsByAttributeResponse, GetOrderIdsParams, GetOrderIdsResponse } from "../types/order.js";
2
2
  /**
3
3
  * Order Management API
4
4
  *
@@ -182,6 +182,17 @@ export declare namespace order {
182
182
  * })
183
183
  * ```
184
184
  */
185
+ /**
186
+ * Add to (or take from) how much of a line has been shipped or received. Atomic, so two receipts at
187
+ * once both count; it can't go below zero.
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * // 20 more caps arrived against a purchase order line
192
+ * await order.lineDone('coll_123', orderId, lineId, 20)
193
+ * ```
194
+ */
195
+ function lineDone(collectionId: string, orderId: string, itemId: string, by: number): Promise<OrderItem>;
185
196
  function removeItems(collectionId: string, orderId: string, data: RemoveItemsRequest): Promise<RemoveItemsResponse>;
186
197
  /**
187
198
  * Find all orders containing specific items (tags, proofs, or serial numbers).
package/dist/api/order.js CHANGED
@@ -236,6 +236,21 @@ export var order;
236
236
  * })
237
237
  * ```
238
238
  */
239
+ /**
240
+ * Add to (or take from) how much of a line has been shipped or received. Atomic, so two receipts at
241
+ * once both count; it can't go below zero.
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * // 20 more caps arrived against a purchase order line
246
+ * await order.lineDone('coll_123', orderId, lineId, 20)
247
+ * ```
248
+ */
249
+ async function lineDone(collectionId, orderId, itemId, by) {
250
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}/items/${encodeURIComponent(itemId)}/done`;
251
+ return post(path, { by });
252
+ }
253
+ order.lineDone = lineDone;
239
254
  async function removeItems(collectionId, orderId, data) {
240
255
  const path = `/admin/collection/${encodeURIComponent(collectionId)}/orders/${encodeURIComponent(orderId)}/items`;
241
256
  // DELETE with body requires requestWithOptions since del() doesn't send body
@@ -0,0 +1,78 @@
1
+ import type { UserGroup, CreateUserGroupRequest, UpdateUserGroupRequest, UserGroupMember, AddUserGroupMemberRequest, UserGroupRef, MyUserGroups, UserGroupChange, UserGroupHistoryParams } from "../types/userGroups.js";
2
+ /**
3
+ * User groups: named lists of people in a collection, used to say who may do what.
4
+ *
5
+ * - An admin manages them here (`list`, `create`, `addMember`, …).
6
+ * - A signed-in person asks which ones they are in with `mine()`, so a screen can show or hide things.
7
+ * - A server function is limited to user groups in its manifest declaration (`userGroups: ['manager']`)
8
+ * and reads the caller's with `ctx.caller.userGroups`. That is where things are actually protected.
9
+ *
10
+ * See docs/user-groups.md.
11
+ */
12
+ export declare namespace userGroups {
13
+ /**
14
+ * The signed-in person's own user groups in this collection. Not signed in → both lists empty.
15
+ * Nobody can ask about anyone else with this.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const { userGroups: mine } = await userGroups.mine('coll_123')
20
+ * const canRelease = mine.includes('qc-controller')
21
+ * ```
22
+ */
23
+ function mine(collectionId: string): Promise<MyUserGroups>;
24
+ /** Every user group in the collection (admin). */
25
+ function list(collectionId: string): Promise<UserGroup[]>;
26
+ /** One user group (admin). */
27
+ function get(collectionId: string, userGroupId: string): Promise<UserGroup>;
28
+ /**
29
+ * Create a user group (admin). Its key is made from the name unless you give one.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const qc = await userGroups.create('coll_123', { name: 'QC Controllers' })
34
+ * qc.key // 'qc-controllers'
35
+ * ```
36
+ * @throws `KEY_INVALID` / `KEY_TAKEN` for a bad or already-used key
37
+ */
38
+ function create(collectionId: string, data: CreateUserGroupRequest): Promise<UserGroup>;
39
+ /**
40
+ * Change a user group (admin): its name, description, or anything else you keep on it. The key stays.
41
+ * To change who is in it, prefer `addMember` / `removeMember`: saving a whole `members` list here can
42
+ * overwrite a change someone else made at the same moment.
43
+ *
44
+ * @throws `KEY_FIXED` if you try to change a key that is already set
45
+ */
46
+ function update(collectionId: string, userGroupId: string, data: UpdateUserGroupRequest): Promise<UserGroup>;
47
+ /** Delete a user group (admin). Its members lose whatever it allowed. */
48
+ function remove(collectionId: string, userGroupId: string): Promise<UserGroup>;
49
+ /** The people in a user group, with name and email (admin). */
50
+ function members(collectionId: string, userGroupId: string): Promise<UserGroupMember[]>;
51
+ /**
52
+ * Add one person (admin), by user id or by email. By email, the person is found in the collection's
53
+ * logins or added to them (no welcome email is sent). Adding someone who is already in changes nothing.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * await userGroups.addMember('coll_123', qc.id, { email: 'sam@example.com', name: 'Sam' })
58
+ * ```
59
+ */
60
+ function addMember(collectionId: string, userGroupId: string, who: AddUserGroupMemberRequest): Promise<UserGroup>;
61
+ /** Remove one person (admin). */
62
+ function removeMember(collectionId: string, userGroupId: string, userId: string): Promise<UserGroup>;
63
+ /**
64
+ * What changed, newest first (admin): user groups created, renamed and deleted, and every person added
65
+ * or removed, each with the admin who did it (`actorId`) and when (`at`). Give `userGroupId` for one
66
+ * user group, `userId` for everything about one person, or neither for the whole collection.
67
+ * Covers the last 30 days unless you give `from` / `to` (at most 400 days). Takes about a second.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const who = await userGroups.history('coll_123', { userId: 'uid_1' })
72
+ * // [{ at, type: 'usergroup.member-added', actorId: 'uid_admin', data: { key: 'qc-controllers', userId: 'uid_1', … } }]
73
+ * ```
74
+ */
75
+ function history(collectionId: string, params?: UserGroupHistoryParams): Promise<UserGroupChange[]>;
76
+ /** The user groups one person is in (admin). */
77
+ function ofUser(collectionId: string, userId: string): Promise<UserGroupRef[]>;
78
+ }