@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.
- package/dist/adminViews.d.ts +85 -0
- package/dist/adminViews.js +259 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/operations.d.ts +36 -0
- package/dist/api/operations.js +56 -0
- package/dist/api/order.d.ts +12 -1
- package/dist/api/order.js +15 -0
- package/dist/api/userGroups.d.ts +78 -0
- package/dist/api/userGroups.js +124 -0
- package/dist/docs/API_SUMMARY.md +604 -42
- package/dist/docs/admin-views.md +125 -0
- package/dist/docs/app-manifest.md +2 -0
- package/dist/docs/operations.md +281 -0
- package/dist/docs/overview.md +3 -0
- package/dist/docs/server-functions.md +18 -0
- package/dist/docs/user-groups.md +168 -0
- package/dist/docs/utils.md +17 -0
- package/dist/http.js +4 -0
- package/dist/iframeResponder.d.ts +15 -0
- package/dist/iframeResponder.js +39 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/openapi.yaml +1238 -276
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.js +55 -0
- package/dist/types/appManifest.d.ts +83 -0
- package/dist/types/containers.d.ts +8 -0
- package/dist/types/iframeResponder.d.ts +16 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/operations.d.ts +598 -0
- package/dist/types/operations.js +8 -0
- package/dist/types/order.d.ts +35 -6
- package/dist/types/userGroups.d.ts +103 -0
- package/dist/types/userGroups.js +5 -0
- package/dist/utils/conditions.d.ts +7 -0
- package/dist/utils/conditions.js +16 -9
- package/docs/API_SUMMARY.md +604 -42
- package/docs/admin-views.md +125 -0
- package/docs/app-manifest.md +2 -0
- package/docs/operations.md +281 -0
- package/docs/overview.md +3 -0
- package/docs/server-functions.md +18 -0
- package/docs/user-groups.md +168 -0
- package/docs/utils.md +17 -0
- package/openapi.yaml +1238 -276
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { AdminView } from './types/appManifest.js';
|
|
2
|
+
export type { AdminView };
|
|
3
|
+
/** What the host asks for. Either a declared `view` (with its params) or a raw hash `path`. */
|
|
4
|
+
export interface NavigateRequest {
|
|
5
|
+
view?: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
params?: Record<string, string>;
|
|
8
|
+
/** Something on the screen to point at: an id the app understands (a row, a field). Optional. */
|
|
9
|
+
highlight?: string;
|
|
10
|
+
}
|
|
11
|
+
/** What the app's handler is given: the resolved hash path (query included) to hand to its router. */
|
|
12
|
+
export interface NavigateTarget {
|
|
13
|
+
/** Hash route, with any optional params as a query string: `/campaigns/c_1?tab=results`. */
|
|
14
|
+
path: string;
|
|
15
|
+
/** The declared view, when the host named one or the path matches one. */
|
|
16
|
+
view?: AdminView;
|
|
17
|
+
params: Record<string, string>;
|
|
18
|
+
highlight?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The hash path for a view: `{name}` placeholders filled from `params` (required — null when one is
|
|
22
|
+
* missing or empty), every other param appended as a query string.
|
|
23
|
+
*
|
|
24
|
+
* @example pathFor({ id: 'campaign', title: 'Campaign', path: '/campaigns/{campaignId}' }, { campaignId: 'c_1' })
|
|
25
|
+
* // → '/campaigns/c_1'
|
|
26
|
+
*/
|
|
27
|
+
export declare function pathFor(view: Pick<AdminView, 'path'>, params?: Record<string, string | undefined>): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Which declared view a hash path is (with its params), or null. When several match, the one with the
|
|
30
|
+
* most fixed segments wins (`/campaigns/new` over `/campaigns/{campaignId}`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function match(views: AdminView[], path: string): {
|
|
33
|
+
view: AdminView;
|
|
34
|
+
params: Record<string, string>;
|
|
35
|
+
} | null;
|
|
36
|
+
/** The side menu: areas in declared order, and Settings for the bottom. Record views are left out. */
|
|
37
|
+
export declare function menu(views: AdminView[]): {
|
|
38
|
+
main: AdminView[];
|
|
39
|
+
settings: AdminView[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The chain from a top-level area down to `id`: `['campaigns', 'campaign', 'campaign.results']`.
|
|
43
|
+
* The first entry is the menu item to show as current; for a record view, the record's first view
|
|
44
|
+
* is `chain[1]`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function trail(views: AdminView[], id: string): AdminView[];
|
|
47
|
+
/**
|
|
48
|
+
* The swapped menu while one record is open: `back` is the area to return to ("← All campaigns"),
|
|
49
|
+
* `items` the record's first view followed by the views within it. Null when `id` isn't a record view.
|
|
50
|
+
*/
|
|
51
|
+
export declare function recordMenu(views: AdminView[], id: string): {
|
|
52
|
+
back?: AdminView;
|
|
53
|
+
record: AdminView;
|
|
54
|
+
items: AdminView[];
|
|
55
|
+
} | null;
|
|
56
|
+
/**
|
|
57
|
+
* Resolve a host's request against the app's views: a named view becomes its path; a raw path is
|
|
58
|
+
* matched to a view where it can be. Null when the view is unknown, a required param is missing, or
|
|
59
|
+
* the path isn't a hash route of this app (`/…`, no scheme, no `//`).
|
|
60
|
+
*/
|
|
61
|
+
export declare function resolve(views: AdminView[], req: NavigateRequest): NavigateTarget | null;
|
|
62
|
+
/**
|
|
63
|
+
* `'none'` when the host opened this page with `chrome=none`: the host's own menu carries this app's
|
|
64
|
+
* views, so the app hides its side menu (and the bar with its toggle) and shows only the content.
|
|
65
|
+
* Read from the address the page was first opened at.
|
|
66
|
+
*/
|
|
67
|
+
export declare function hostChrome(): 'none' | 'full';
|
|
68
|
+
/**
|
|
69
|
+
* Follow the host's `smartlinks:navigate`: the handler gets the resolved hash path and hands it to the
|
|
70
|
+
* app's router (no reload). Registering tells the host this page follows navigate, so it stops
|
|
71
|
+
* reloading the frame to change screens. Only messages from the parent window are taken. Returns a
|
|
72
|
+
* function that stops listening.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* // React Router, with the views from the app's own manifest
|
|
76
|
+
* import manifest from '../public/app.manifest.json'
|
|
77
|
+
* const navigate = useNavigate()
|
|
78
|
+
* useEffect(() => SL.adminViews.onNavigate(manifest.adminViews, (to) => navigate(to.path)), [navigate])
|
|
79
|
+
*/
|
|
80
|
+
export declare function onNavigate(views: AdminView[] | undefined | null, handler: (to: NavigateTarget) => void): () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Ask an embedded app to open a screen. Post this only once the app has said it follows navigate
|
|
83
|
+
* (`smartlinks:navigable`); otherwise reload the frame at the new path as before.
|
|
84
|
+
*/
|
|
85
|
+
export declare function postNavigate(target: Window | null | undefined, req: NavigateRequest, targetOrigin?: string): void;
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// src/adminViews.ts
|
|
2
|
+
// ADMIN VIEWS — an app's admin screens by name (app.manifest.json#adminViews), and the two runtime
|
|
3
|
+
// messages that use them:
|
|
4
|
+
// host → app { type: 'smartlinks:navigate', view?, path?, params?, highlight? } open a screen, no reload
|
|
5
|
+
// app → host 'smartlinks:navigable' (the app follows navigate) 'smartlinks:navigate-result'
|
|
6
|
+
// plus `chrome=none`: the host carries the app's menu itself, so the app hides its own.
|
|
7
|
+
// One list drives the app's own side menu, Studio's workspace menu and the assistant. See
|
|
8
|
+
// docs/admin-views.md.
|
|
9
|
+
const PLACEHOLDER = /\{([A-Za-z0-9_]+)\}/g;
|
|
10
|
+
/**
|
|
11
|
+
* The hash path for a view: `{name}` placeholders filled from `params` (required — null when one is
|
|
12
|
+
* missing or empty), every other param appended as a query string.
|
|
13
|
+
*
|
|
14
|
+
* @example pathFor({ id: 'campaign', title: 'Campaign', path: '/campaigns/{campaignId}' }, { campaignId: 'c_1' })
|
|
15
|
+
* // → '/campaigns/c_1'
|
|
16
|
+
*/
|
|
17
|
+
export function pathFor(view, params = {}) {
|
|
18
|
+
const used = new Set();
|
|
19
|
+
let missing = false;
|
|
20
|
+
const filled = view.path.replace(PLACEHOLDER, (_, name) => {
|
|
21
|
+
used.add(name);
|
|
22
|
+
const v = params[name];
|
|
23
|
+
if (v == null || v === '') {
|
|
24
|
+
missing = true;
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
return encodeURIComponent(v);
|
|
28
|
+
});
|
|
29
|
+
if (missing)
|
|
30
|
+
return null;
|
|
31
|
+
const q = new URLSearchParams();
|
|
32
|
+
for (const [k, v] of Object.entries(params)) {
|
|
33
|
+
if (!used.has(k) && v != null && v !== '')
|
|
34
|
+
q.set(k, v);
|
|
35
|
+
}
|
|
36
|
+
const qs = q.toString();
|
|
37
|
+
return qs ? `${filled}?${qs}` : filled;
|
|
38
|
+
}
|
|
39
|
+
function splitPath(path) {
|
|
40
|
+
const i = path.indexOf('?');
|
|
41
|
+
return i < 0 ? { pathname: path, query: new URLSearchParams() } : { pathname: path.slice(0, i), query: new URLSearchParams(path.slice(i + 1)) };
|
|
42
|
+
}
|
|
43
|
+
const trimSlash = (p) => (p.length > 1 ? p.replace(/\/+$/, '') : p);
|
|
44
|
+
/**
|
|
45
|
+
* Which declared view a hash path is (with its params), or null. When several match, the one with the
|
|
46
|
+
* most fixed segments wins (`/campaigns/new` over `/campaigns/{campaignId}`).
|
|
47
|
+
*/
|
|
48
|
+
export function match(views, path) {
|
|
49
|
+
const { pathname, query } = splitPath(path || '/');
|
|
50
|
+
const segs = trimSlash(pathname).split('/');
|
|
51
|
+
let best = null;
|
|
52
|
+
for (const view of views) {
|
|
53
|
+
const tsegs = trimSlash(view.path).split('/');
|
|
54
|
+
if (tsegs.length !== segs.length)
|
|
55
|
+
continue;
|
|
56
|
+
const params = {};
|
|
57
|
+
let fixed = 0;
|
|
58
|
+
let ok = true;
|
|
59
|
+
for (let i = 0; i < tsegs.length; i++) {
|
|
60
|
+
const t = tsegs[i];
|
|
61
|
+
const m = /^\{([A-Za-z0-9_]+)\}$/.exec(t);
|
|
62
|
+
if (m) {
|
|
63
|
+
if (!segs[i]) {
|
|
64
|
+
ok = false;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
params[m[1]] = decodeURIComponent(segs[i]);
|
|
69
|
+
}
|
|
70
|
+
catch (_a) {
|
|
71
|
+
params[m[1]] = segs[i];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (t === segs[i]) {
|
|
75
|
+
fixed++;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
ok = false;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!ok)
|
|
83
|
+
continue;
|
|
84
|
+
if (!best || fixed > best.fixed)
|
|
85
|
+
best = { view, params, fixed };
|
|
86
|
+
}
|
|
87
|
+
if (!best)
|
|
88
|
+
return null;
|
|
89
|
+
query.forEach((v, k) => { if (best.params[k] == null)
|
|
90
|
+
best.params[k] = v; });
|
|
91
|
+
return { view: best.view, params: best.params };
|
|
92
|
+
}
|
|
93
|
+
/** The side menu: areas in declared order, and Settings for the bottom. Record views are left out. */
|
|
94
|
+
export function menu(views) {
|
|
95
|
+
return {
|
|
96
|
+
main: views.filter((v) => { var _a; return ((_a = v.group) !== null && _a !== void 0 ? _a : 'main') === 'main'; }),
|
|
97
|
+
settings: views.filter((v) => v.group === 'settings'),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The chain from a top-level area down to `id`: `['campaigns', 'campaign', 'campaign.results']`.
|
|
102
|
+
* The first entry is the menu item to show as current; for a record view, the record's first view
|
|
103
|
+
* is `chain[1]`.
|
|
104
|
+
*/
|
|
105
|
+
export function trail(views, id) {
|
|
106
|
+
const byId = new Map(views.map((v) => [v.id, v]));
|
|
107
|
+
const out = [];
|
|
108
|
+
let cur = byId.get(id);
|
|
109
|
+
while (cur && !out.includes(cur)) {
|
|
110
|
+
out.unshift(cur);
|
|
111
|
+
cur = cur.within ? byId.get(cur.within) : undefined;
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The swapped menu while one record is open: `back` is the area to return to ("← All campaigns"),
|
|
117
|
+
* `items` the record's first view followed by the views within it. Null when `id` isn't a record view.
|
|
118
|
+
*/
|
|
119
|
+
export function recordMenu(views, id) {
|
|
120
|
+
const chain = trail(views, id);
|
|
121
|
+
const record = chain.find((v) => v.group === 'record');
|
|
122
|
+
if (!record)
|
|
123
|
+
return null;
|
|
124
|
+
const back = record.within ? views.find((v) => v.id === record.within) : undefined;
|
|
125
|
+
return { back, record, items: [record, ...views.filter((v) => v.within === record.id && v.group === 'record')] };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resolve a host's request against the app's views: a named view becomes its path; a raw path is
|
|
129
|
+
* matched to a view where it can be. Null when the view is unknown, a required param is missing, or
|
|
130
|
+
* the path isn't a hash route of this app (`/…`, no scheme, no `//`).
|
|
131
|
+
*/
|
|
132
|
+
export function resolve(views, req) {
|
|
133
|
+
const params = {};
|
|
134
|
+
for (const [k, v] of Object.entries(req.params || {}))
|
|
135
|
+
if (typeof v === 'string')
|
|
136
|
+
params[k] = v;
|
|
137
|
+
if (req.view) {
|
|
138
|
+
const view = views.find((v) => v.id === req.view);
|
|
139
|
+
if (!view)
|
|
140
|
+
return null;
|
|
141
|
+
const path = pathFor(view, params);
|
|
142
|
+
if (path == null)
|
|
143
|
+
return null;
|
|
144
|
+
return Object.assign({ path, view, params }, (req.highlight ? { highlight: req.highlight } : {}));
|
|
145
|
+
}
|
|
146
|
+
if (typeof req.path !== 'string' || !req.path.startsWith('/') || req.path.startsWith('//') || req.path.includes('://'))
|
|
147
|
+
return null;
|
|
148
|
+
let path = req.path;
|
|
149
|
+
if (Object.keys(params).length) {
|
|
150
|
+
const { pathname, query } = splitPath(path);
|
|
151
|
+
for (const [k, v] of Object.entries(params))
|
|
152
|
+
query.set(k, v);
|
|
153
|
+
path = `${pathname}?${query.toString()}`;
|
|
154
|
+
}
|
|
155
|
+
const m = match(views, path);
|
|
156
|
+
return Object.assign(Object.assign(Object.assign({ path }, (m ? { view: m.view } : {})), { params: m ? Object.assign(Object.assign({}, m.params), params) : params }), (req.highlight ? { highlight: req.highlight } : {}));
|
|
157
|
+
}
|
|
158
|
+
// -----------------------------------------------------------------------------
|
|
159
|
+
// App side
|
|
160
|
+
// -----------------------------------------------------------------------------
|
|
161
|
+
function inIframe() {
|
|
162
|
+
return typeof window !== 'undefined' && !!window.parent && window.parent !== window;
|
|
163
|
+
}
|
|
164
|
+
function postParent(type, payload) {
|
|
165
|
+
if (!inIframe())
|
|
166
|
+
return;
|
|
167
|
+
try {
|
|
168
|
+
window.parent.postMessage({ _smartlinksIframeMessage: true, type, payload }, '*');
|
|
169
|
+
}
|
|
170
|
+
catch (_a) {
|
|
171
|
+
/* ignore */
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** `chrome` as the page was first opened: read once, so the app's own navigation can't lose it. */
|
|
175
|
+
const INITIAL_CHROME = (() => {
|
|
176
|
+
try {
|
|
177
|
+
if (typeof window === 'undefined' || !window.location)
|
|
178
|
+
return 'full';
|
|
179
|
+
const hash = window.location.hash || '';
|
|
180
|
+
const q = hash.indexOf('?');
|
|
181
|
+
const fromHash = q >= 0 ? new URLSearchParams(hash.slice(q + 1)).get('chrome') : null;
|
|
182
|
+
const v = fromHash !== null && fromHash !== void 0 ? fromHash : new URLSearchParams(window.location.search || '').get('chrome');
|
|
183
|
+
return v === 'none' ? 'none' : 'full';
|
|
184
|
+
}
|
|
185
|
+
catch (_a) {
|
|
186
|
+
return 'full';
|
|
187
|
+
}
|
|
188
|
+
})();
|
|
189
|
+
/**
|
|
190
|
+
* `'none'` when the host opened this page with `chrome=none`: the host's own menu carries this app's
|
|
191
|
+
* views, so the app hides its side menu (and the bar with its toggle) and shows only the content.
|
|
192
|
+
* Read from the address the page was first opened at.
|
|
193
|
+
*/
|
|
194
|
+
export function hostChrome() {
|
|
195
|
+
return INITIAL_CHROME;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Follow the host's `smartlinks:navigate`: the handler gets the resolved hash path and hands it to the
|
|
199
|
+
* app's router (no reload). Registering tells the host this page follows navigate, so it stops
|
|
200
|
+
* reloading the frame to change screens. Only messages from the parent window are taken. Returns a
|
|
201
|
+
* function that stops listening.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* // React Router, with the views from the app's own manifest
|
|
205
|
+
* import manifest from '../public/app.manifest.json'
|
|
206
|
+
* const navigate = useNavigate()
|
|
207
|
+
* useEffect(() => SL.adminViews.onNavigate(manifest.adminViews, (to) => navigate(to.path)), [navigate])
|
|
208
|
+
*/
|
|
209
|
+
export function onNavigate(views, handler) {
|
|
210
|
+
if (typeof window === 'undefined' || !inIframe())
|
|
211
|
+
return () => { };
|
|
212
|
+
const list = Array.isArray(views) ? views : [];
|
|
213
|
+
const onMsg = (e) => {
|
|
214
|
+
var _a, _b, _c, _d, _e, _f;
|
|
215
|
+
if (e.source !== window.parent)
|
|
216
|
+
return;
|
|
217
|
+
const d = e.data;
|
|
218
|
+
if (!d || typeof d !== 'object' || d.type !== 'smartlinks:navigate')
|
|
219
|
+
return;
|
|
220
|
+
const req = { view: d.view, path: d.path, params: d.params, highlight: d.highlight };
|
|
221
|
+
const target = resolve(list, req);
|
|
222
|
+
if (!target) {
|
|
223
|
+
postParent('smartlinks:navigate-result', { ok: false, view: (_a = req.view) !== null && _a !== void 0 ? _a : null, path: (_b = req.path) !== null && _b !== void 0 ? _b : null, reason: req.view ? 'unknown-view-or-missing-param' : 'bad-path' });
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
handler(target);
|
|
228
|
+
postParent('smartlinks:navigate-result', { ok: true, view: (_d = (_c = target.view) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : null, path: target.path });
|
|
229
|
+
}
|
|
230
|
+
catch (_g) {
|
|
231
|
+
postParent('smartlinks:navigate-result', { ok: false, view: (_f = (_e = target.view) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : null, path: target.path, reason: 'handler-failed' });
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
window.addEventListener('message', onMsg);
|
|
235
|
+
postParent('smartlinks:navigable', { views: list.map((v) => v.id), chrome: INITIAL_CHROME });
|
|
236
|
+
return () => {
|
|
237
|
+
try {
|
|
238
|
+
window.removeEventListener('message', onMsg);
|
|
239
|
+
}
|
|
240
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
// -----------------------------------------------------------------------------
|
|
244
|
+
// Host side
|
|
245
|
+
// -----------------------------------------------------------------------------
|
|
246
|
+
/**
|
|
247
|
+
* Ask an embedded app to open a screen. Post this only once the app has said it follows navigate
|
|
248
|
+
* (`smartlinks:navigable`); otherwise reload the frame at the new path as before.
|
|
249
|
+
*/
|
|
250
|
+
export function postNavigate(target, req, targetOrigin = '*') {
|
|
251
|
+
if (!target)
|
|
252
|
+
return;
|
|
253
|
+
try {
|
|
254
|
+
target.postMessage(Object.assign({ type: 'smartlinks:navigate' }, req), targetOrigin);
|
|
255
|
+
}
|
|
256
|
+
catch (_a) {
|
|
257
|
+
/* ignore */
|
|
258
|
+
}
|
|
259
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -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 = {}));
|
package/dist/api/order.d.ts
CHANGED
|
@@ -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
|
+
}
|