@timbereye/sdk 0.0.0-stage → 0.2.0

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 (53) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/LICENSE +202 -0
  3. package/README.md +346 -2
  4. package/dist/cjs/case.d.ts +23 -0
  5. package/dist/cjs/case.js +54 -0
  6. package/dist/cjs/client.d.ts +98 -0
  7. package/dist/cjs/client.js +132 -0
  8. package/dist/cjs/errors.d.ts +63 -0
  9. package/dist/cjs/errors.js +107 -0
  10. package/dist/cjs/generated/schema.d.ts +14862 -0
  11. package/dist/cjs/generated/schema.js +6 -0
  12. package/dist/cjs/http.d.ts +104 -0
  13. package/dist/cjs/http.js +253 -0
  14. package/dist/cjs/index.d.ts +14 -0
  15. package/dist/cjs/index.js +29 -0
  16. package/dist/cjs/package.json +1 -0
  17. package/dist/cjs/pagination.d.ts +31 -0
  18. package/dist/cjs/pagination.js +52 -0
  19. package/dist/cjs/resources.d.ts +11195 -0
  20. package/dist/cjs/resources.js +506 -0
  21. package/dist/cjs/runtime.d.ts +20 -0
  22. package/dist/cjs/runtime.js +74 -0
  23. package/dist/cjs/types.d.ts +649 -0
  24. package/dist/cjs/types.js +2 -0
  25. package/dist/cjs/units.d.ts +26 -0
  26. package/dist/cjs/units.js +45 -0
  27. package/dist/cjs/webhooks.d.ts +67 -0
  28. package/dist/cjs/webhooks.js +213 -0
  29. package/dist/esm/case.d.ts +23 -0
  30. package/dist/esm/case.js +47 -0
  31. package/dist/esm/client.d.ts +98 -0
  32. package/dist/esm/client.js +128 -0
  33. package/dist/esm/errors.d.ts +63 -0
  34. package/dist/esm/errors.js +93 -0
  35. package/dist/esm/generated/schema.d.ts +14862 -0
  36. package/dist/esm/generated/schema.js +5 -0
  37. package/dist/esm/http.d.ts +104 -0
  38. package/dist/esm/http.js +247 -0
  39. package/dist/esm/index.d.ts +14 -0
  40. package/dist/esm/index.js +6 -0
  41. package/dist/esm/pagination.d.ts +31 -0
  42. package/dist/esm/pagination.js +49 -0
  43. package/dist/esm/resources.d.ts +11195 -0
  44. package/dist/esm/resources.js +503 -0
  45. package/dist/esm/runtime.d.ts +20 -0
  46. package/dist/esm/runtime.js +46 -0
  47. package/dist/esm/types.d.ts +649 -0
  48. package/dist/esm/types.js +1 -0
  49. package/dist/esm/units.d.ts +26 -0
  50. package/dist/esm/units.js +38 -0
  51. package/dist/esm/webhooks.d.ts +67 -0
  52. package/dist/esm/webhooks.js +208 -0
  53. package/package.json +51 -5
@@ -0,0 +1,503 @@
1
+ import { makeList } from "./pagination.js";
2
+ import { toSnake } from "./case.js";
3
+ const id = (v) => encodeURIComponent(v);
4
+ /** Builds the resource tree. One method per operation in the OpenAPI document (https://www.timbereye.com/docs/openapi.yaml). */
5
+ export function createResources(t) {
6
+ const get = (path, query, o) => t.request({ method: "GET", path, query: query }, o);
7
+ const post = (path, body, o, extra) => t.request({ method: "POST", path, body, ...extra }, o);
8
+ const send = (method, path, body, o, headers, query) => t.request({ method, path, body, headers, query: query }, o);
9
+ const list = (path, params, o) => makeList((p, oo) => get(path, p, oo), params, o);
10
+ const groups = {
11
+ create: (params = {}, o) => post("/groups", params, o),
12
+ /**
13
+ * A group for a kind and reference (trimmed, case-insensitive), continued or created: `existing: "auto"`
14
+ * (the default) continues the newest group with the reference if it was active in the last 12 hours, else
15
+ * starts a new one; `"continue"` and `"new"` choose. `name` is the display name, set at creation. With a
16
+ * publishable key the result is a `CaptureGroup` (`T.CaptureGroup`), a subset of `Group`.
17
+ */
18
+ open: (params, o) => post("/groups/open", params, o),
19
+ /** The newest group with a kind and reference, its pieces and last scan, and what to offer by default. */
20
+ lookup: (params, o) => get("/groups/lookup", params, o),
21
+ retrieve: (groupId, params, o) => get(`/groups/${id(groupId)}`, params, o),
22
+ /** With a publishable key the result is a `CaptureGroup` (`T.CaptureGroup`: id, kind, externalRef, name, defaults, version); the type here is the server's `Group`. `o.ifMatch` is the group's `version`; a stale value fails with 412 `version_mismatch`. */
23
+ update: (groupId, params, o) => send("PATCH", `/groups/${id(groupId)}`, params, o, o?.ifMatch === undefined ? undefined : { "If-Match": String(o.ifMatch) }),
24
+ list: (params, o) => list("/groups", params, o),
25
+ /**
26
+ * Deletes a group that never held anything (no logs, scans, nested groups or photos, and no phone that may
27
+ * still capture into it); otherwise 409 `group_not_empty` or `group_billed`, and it stays as the record. In test
28
+ * mode `{ cascade: true }` deletes it with everything in it; in live mode `cascade` is 400.
29
+ */
30
+ delete: (groupId, params, o) => send("DELETE", `/groups/${id(groupId)}`, undefined, o, undefined, params),
31
+ /**
32
+ * Sets or replaces the group's weighbridge ticket (gross and tare, or net, in one unit; `ticketRef`, and
33
+ * `ticketImageId` for the ticket's photo). Timbereye does not measure weight. Emits `group.updated`.
34
+ */
35
+ setWeight: (groupId, weight, o) => send("PUT", `/groups/${id(groupId)}/weight`, weight, o),
36
+ /** Removes the group's weight and the per-log shares allocated from it. Emits `group.updated`. */
37
+ clearWeight: (groupId, o) => send("DELETE", `/groups/${id(groupId)}/weight`, undefined, o),
38
+ volume: (groupId, params, o) => get(`/groups/${id(groupId)}/volume`, params, o),
39
+ origin: (groupId, o) => get(`/groups/${id(groupId)}/origin`, undefined, o),
40
+ /** The group's photos, oldest first, with kind, caption, who took them and a 15-minute `downloadUrl`. */
41
+ listImages: (groupId, params, o) => list(`/groups/${id(groupId)}/images`, params, o),
42
+ /**
43
+ * Lumber and panels: up to 500 groups in one call and one transaction, optionally under a
44
+ * parent created in the same call (a container and its bundles) or an existing `parentId`.
45
+ */
46
+ createBatch: (params, o) => post("/groups/batch", params, o),
47
+ /** A bundle's tally sheet: the tally with its lines and a `document` block, or with `format: "html"` a printable page. */
48
+ tallySheet: (groupId, params, o) => get(`/groups/${id(groupId)}/tally_sheet`, params, o),
49
+ /**
50
+ * The packing list of any group that holds bundles or units (a container, truck load, stack): one row per
51
+ * bundle or unit, width classes, the thickness × length pivot, `totals` under the list's convention and
52
+ * `totalsAlternative` under the other. A shipment whose containers sit inside it reads as one list: each
53
+ * row's `inGroup` names its container and `groups` gives each container's totals; `logs` lists its logs.
54
+ *
55
+ * With `format: "pdf"` it resolves to the document itself (`{ data, contentType, fileName }`), made from the
56
+ * group's data on every call: `paper` is `"a4"` or `"letter"`, `detail: "tally"` adds each bundle's tally lines.
57
+ */
58
+ packingList: (groupId, params, o) => (params?.format === "pdf"
59
+ ? t.request({
60
+ method: "GET",
61
+ path: `/groups/${id(groupId)}/packing_list`,
62
+ query: params,
63
+ binary: true,
64
+ }, o)
65
+ : get(`/groups/${id(groupId)}/packing_list`, params, o)),
66
+ /** Where a group has been: its parents over time, oldest first, the current one last. */
67
+ listParents: (groupId, o) => list(`/groups/${id(groupId)}/parents`, undefined, o),
68
+ /** A lumber bundle's or panel unit's tally. */
69
+ tally: {
70
+ /** The tally: lines, what the rule tallied, totals by length and width, the label beside the count. */
71
+ retrieve: (groupId, params, o) => get(`/groups/${id(groupId)}/tally`, params, o),
72
+ /**
73
+ * Replaces the bundle's lines atomically. Idempotent by `clientId`. A submitted tally is final: it is the
74
+ * bundle's next revision and sends `group.measured` (its photos must be in, or waived).
75
+ */
76
+ submit: (groupId, params, o) => post(`/groups/${id(groupId)}/tally`, params, o),
77
+ /** Update, split, remove or add lines, each with a `reason`; every change is kept as a revision. */
78
+ correct: (groupId, params, o) => post(`/groups/${id(groupId)}/tally/corrections`, params, o),
79
+ /** Every change after upload, oldest first. */
80
+ listRevisions: (groupId, params, o) => list(`/groups/${id(groupId)}/tally/revisions`, params, o),
81
+ },
82
+ items: {
83
+ add: (groupId, refs, o) => post(`/groups/${id(groupId)}/items/add`, refs, o),
84
+ remove: (groupId, refs, o) => post(`/groups/${id(groupId)}/items/remove`, refs, o),
85
+ bulkUpdate: (groupId, params, o) => post(`/groups/${id(groupId)}/items/bulk_update`, params, o),
86
+ list: (groupId, params, o) => list(`/groups/${id(groupId)}/items`, params, o),
87
+ },
88
+ };
89
+ const items = {
90
+ list: (params, o) => list("/items", params, o),
91
+ retrieve: (itemId, params, o) => get(`/items/${id(itemId)}`, params, o),
92
+ update: (itemId, patch, o) => send("PATCH", `/items/${id(itemId)}`, patch, o),
93
+ /** `DELETE /items/{id}`: marks the item `removed`. */
94
+ remove: (itemId, o) => send("DELETE", `/items/${id(itemId)}`, undefined, o),
95
+ listMeasurements: (itemId, params, o) => list(`/items/${id(itemId)}/measurements`, params, o),
96
+ /** A manual override measurement. */
97
+ createMeasurement: (itemId, params, o) => post(`/items/${id(itemId)}/measurements`, params, o),
98
+ volume: (itemId, params, o) => get(`/items/${id(itemId)}/volume`, params, o),
99
+ listGroups: (itemId, params, o) => list(`/items/${id(itemId)}/groups`, params, o),
100
+ listImages: (itemId, params, o) => list(`/items/${id(itemId)}/images`, params, o),
101
+ };
102
+ const scans = {
103
+ create: (params, o) => post("/scans", params, o),
104
+ list: (params, o) => list("/scans", params, o),
105
+ retrieve: (scanId, params, o) => get(`/scans/${id(scanId)}`, params, o),
106
+ /**
107
+ * Device estimates, at most 100 per call. Returns one entry per input item, in input order, each the item
108
+ * with `clientId` set to the input's and `created`. Items are identified by the scan and their `clientId`,
109
+ * so posting a batch again under any idempotency key stores nothing twice.
110
+ */
111
+ addItems: (scanId, params, o) => post(`/scans/${id(scanId)}/items`, params, o),
112
+ /**
113
+ * The logs this scan measured, each with the scan's own latest measurement and whether it is `final`
114
+ * (refinement finished). A phone with a publishable key may read its own scans only.
115
+ */
116
+ listItems: (scanId, params, o) => list(`/scans/${id(scanId)}/items`, params, o),
117
+ /** QR-count observations. */
118
+ addObservations: (scanId, params, o) => post(`/scans/${id(scanId)}/observations`, params, o),
119
+ /**
120
+ * Closes capture. Idempotent: a scan that was submitted already is returned as it is. `endedAt` is when
121
+ * capture ended on the device.
122
+ */
123
+ submit: (scanId, o) => post(`/scans/${id(scanId)}/submit`, o?.endedAt === undefined ? undefined : { endedAt: o.endedAt }, o),
124
+ /**
125
+ * Multipart upload of one JPEG up to 10 MB with its metadata in one request. For larger or resumable
126
+ * uploads use `images.createUploadSession`.
127
+ */
128
+ uploadImage: (scanId, params, o) => {
129
+ const form = new FormData();
130
+ form.append("subject", params.subject);
131
+ form.append("kind", params.kind);
132
+ const text = (name, value) => {
133
+ if (value !== undefined)
134
+ form.append(name, String(value));
135
+ };
136
+ const json = (name, value) => {
137
+ if (value !== undefined)
138
+ form.append(name, JSON.stringify(toSnake(value)));
139
+ };
140
+ text("item_id", params.itemId);
141
+ text("item_client_id", params.itemClientId);
142
+ text("client_id", params.clientId);
143
+ text("captured_at", params.capturedAt);
144
+ text("sha256", params.sha256);
145
+ text("width", params.width);
146
+ text("height", params.height);
147
+ text("source_image_id", params.sourceImageId);
148
+ json("location", params.location);
149
+ json("region", params.region);
150
+ json("detections", params.detections);
151
+ const blob = params.file instanceof Blob
152
+ ? params.file
153
+ : new Blob([params.file], { type: "image/jpeg" });
154
+ form.append("file", blob, params.filename ?? "image.jpg");
155
+ return t.request({ method: "POST", path: `/scans/${id(scanId)}/images`, form }, o);
156
+ },
157
+ };
158
+ const images = {
159
+ /** Starts a resumable upload: returns the image and a session URI to PUT the bytes to. */
160
+ createUploadSession: (params, o) => post("/images", params, o),
161
+ /**
162
+ * A new upload session for an image that is still `pending_upload` (it starts at byte 0). After a
163
+ * refused `complete`, ask for one, upload again, then complete under a new idempotency key.
164
+ */
165
+ createSession: (imageId, o) => post(`/images/${id(imageId)}/session`, undefined, o),
166
+ retrieve: (imageId, o) => get(`/images/${id(imageId)}`, undefined, o),
167
+ complete: (imageId, o) => post(`/images/${id(imageId)}/complete`, undefined, o),
168
+ /**
169
+ * Removes a group photo from the group's photos (soft and audited: it keeps its record with `removedAt` and
170
+ * `removedBy`). A log's photo cannot be removed. Emits `group.updated`.
171
+ */
172
+ remove: (imageId, o) => send("DELETE", `/images/${id(imageId)}`, undefined, o),
173
+ };
174
+ const places = {
175
+ create: (params, o) => post("/places", params, o),
176
+ list: (params, o) => list("/places", params, o),
177
+ retrieve: (placeId, o) => get(`/places/${id(placeId)}`, undefined, o),
178
+ update: (placeId, params, o) => send("PATCH", `/places/${id(placeId)}`, params, o),
179
+ /**
180
+ * Deletes a place no group uses as its origin; otherwise 409 `place_in_use`. In test mode
181
+ * `{ detach: true }` clears those groups' origin first; in live mode `detach` is 400.
182
+ */
183
+ delete: (placeId, params, o) => send("DELETE", `/places/${id(placeId)}`, undefined, o, undefined, params),
184
+ /** Computes only; the API ignores an idempotency key here, so none is sent. */
185
+ validate: (params, o) => post("/places/validate", params, o, { noIdempotency: true }),
186
+ };
187
+ /** Tag printing: label templates (the QR code always prints at 62 mm; it is not a setting). */
188
+ const labelTemplates = {
189
+ create: (params, o) => post("/label_templates", params, o),
190
+ list: (params, o) => list("/label_templates", params, o),
191
+ retrieve: (templateId, o) => get(`/label_templates/${id(templateId)}`, undefined, o),
192
+ update: (templateId, params, o) => send("PATCH", `/label_templates/${id(templateId)}`, params, o),
193
+ /** Deletes a template; one a batch was made with is kept (409 `label_template_in_use`). */
194
+ delete: (templateId, o) => send("DELETE", `/label_templates/${id(templateId)}`, undefined, o),
195
+ /** One test label (short id TEST0) after a 62 mm ruler label: print it and measure with a ruler. */
196
+ testLabel: (templateId, params, o) => get(`/label_templates/${id(templateId)}/test_label`, params, o),
197
+ };
198
+ /** Tag printing: batches of tags, their tags (with the log a scan made of each) and print files. */
199
+ const tagBatches = {
200
+ create: (params, o) => post("/tag_batches", params, o),
201
+ list: (params, o) => list("/tag_batches", params, o),
202
+ retrieve: (batchId, o) => get(`/tag_batches/${id(batchId)}`, undefined, o),
203
+ listTags: (batchId, params, o) => list(`/tag_batches/${id(batchId)}/tags`, params, o),
204
+ /** The print file inline: `data` is ZPL text (`encoding: "utf8"`) or a base64 PDF. */
205
+ printFile: (batchId, params, o) => get(`/tag_batches/${id(batchId)}/print_file`, params, o),
206
+ };
207
+ const species = {
208
+ list: (params, o) => list("/species", params, o),
209
+ create: (params, o) => post("/species", params, o),
210
+ update: (speciesId, params, o) => send("PATCH", `/species/${id(speciesId)}`, params, o),
211
+ };
212
+ const volumeRules = {
213
+ list: (o) => get("/volume_rules", undefined, o),
214
+ };
215
+ const events = {
216
+ list: (params, o) => list("/events", params, o),
217
+ retrieve: (eventId, o) => get(`/events/${id(eventId)}`, undefined, o),
218
+ };
219
+ const webhookEndpoints = {
220
+ /** The signing `secret` is returned here once and never again. */
221
+ create: (params, o) => post("/webhook_endpoints", params, o),
222
+ list: (params, o) => list("/webhook_endpoints", params, o),
223
+ retrieve: (endpointId, o) => get(`/webhook_endpoints/${id(endpointId)}`, undefined, o),
224
+ update: (endpointId, params, o) => send("PATCH", `/webhook_endpoints/${id(endpointId)}`, params, o),
225
+ delete: (endpointId, o) => send("DELETE", `/webhook_endpoints/${id(endpointId)}`, undefined, o),
226
+ /** Sends a test delivery to this endpoint only (it is not in `events.list`) and returns a reference to it. */
227
+ test: (endpointId, params, o) => post(`/webhook_endpoints/${id(endpointId)}/test`, params, o),
228
+ /** Rolls the signing secret. The new `secret` is returned once; the old one stays valid until `previousSecretExpiresAt` (24 h), and deliveries carry both signatures meanwhile. */
229
+ rollSecret: (endpointId, o) => post(`/webhook_endpoints/${id(endpointId)}/roll_secret`, undefined, o),
230
+ /** The endpoint's delivery log, newest first; filter by `status` and `type`. Kept 30 days. */
231
+ listDeliveries: (endpointId, params, o) => list(`/webhook_endpoints/${id(endpointId)}/deliveries`, params, o),
232
+ /** One delivery with every attempt: the request as sent and the response as received. */
233
+ retrieveDelivery: (deliveryId, o) => get(`/webhook_deliveries/${id(deliveryId)}`, undefined, o),
234
+ /** Sends a delivery again now, with a fresh set of retries. */
235
+ resendDelivery: (deliveryId, o) => post(`/webhook_deliveries/${id(deliveryId)}/resend`, undefined, o),
236
+ };
237
+ const captureTokens = {
238
+ /** Secret keys only. The `secret` in the result is shown once. */
239
+ create: (params, o) => post("/capture_tokens", params, o),
240
+ };
241
+ const usage = {
242
+ retrieve: (params, o) => get("/usage", params, o),
243
+ listRecords: (params, o) => list("/usage/records", params, o),
244
+ };
245
+ /**
246
+ * Key management. **Dashboard sessions only**: these routes refuse every API key and capture token
247
+ * (403 `session_required`), so construct the client with a signed-in user's session token. `create` and `roll`
248
+ * return the secret; `reveal` shows a secret, restricted or publishable key again, test or live. Every organisation
249
+ * already has default keys (`isDefault`).
250
+ */
251
+ const apiKeys = {
252
+ /** Secret and restricted keys, newest first; revoked, expired and capture keys only when asked for. Never returns a secret. */
253
+ list: (params, o) => list("/api_keys", params, o),
254
+ /** `secret` in the result is the full key; a replay of the same idempotency key returns `secret: null`. `reveal` shows it again. */
255
+ create: (params, o) => post("/api_keys", params, o),
256
+ /** Returns the new key with its `secret`; the old one stops working at once or after `expireOldAfterSeconds` (up to 7 days). */
257
+ roll: (keyId, params, o) => post(`/api_keys/${id(keyId)}/roll`, params, o),
258
+ /**
259
+ * The full key of a secret, restricted or publishable key, test or live, when `revealable` is true. Whoever may roll
260
+ * the key (a live secret key: owners only); each call is in the audit log.
261
+ */
262
+ reveal: (keyId, params, o) => post(`/api_keys/${id(keyId)}/reveal`, params, o, { noIdempotency: true }),
263
+ /** Renames any key; for a publishable key also changes `allowedAppIds` (null clears) or `limits` (null resets one). */
264
+ update: (keyId, params, o) => send("PATCH", `/api_keys/${id(keyId)}`, params, o),
265
+ /**
266
+ * Publishable keys: removes the items captured by the key inside a time window and voids their usage.
267
+ * Call again while `hasMore` is true.
268
+ */
269
+ voidRecords: (keyId, params, o) => post(`/api_keys/${id(keyId)}/void_records`, params, o),
270
+ /** Revokes at once; repeating it changes nothing. */
271
+ revoke: (keyId, o) => send("DELETE", `/api_keys/${id(keyId)}`, undefined, o),
272
+ };
273
+ const account = {
274
+ /** The calling key\'s account, including `displayUnits`, which the unit formatters accept. */
275
+ retrieve: (o) => get("/account", undefined, o),
276
+ /**
277
+ * Dashboard sessions only: returns the organisation's test account, creating it on first use. Call it in
278
+ * live mode, because test-mode requests need the test account to exist already.
279
+ */
280
+ createTestAccount: (o) => post("/account/test_mode", undefined, o),
281
+ /**
282
+ * Changes the organisation's lumber settings in this mode (`account.lumber`): whether phones may open lumber
283
+ * groups, the default board-foot method (`perBoard` or `bundleTotal`), whether new bundles need photos.
284
+ */
285
+ updateLumber: (params, o) => send("PATCH", "/account/lumber", params, o),
286
+ /**
287
+ * The organisation's logo, printed top left on its documents (the packing list PDF), in both modes. Without
288
+ * one, documents set the organisation's name. PNG or JPEG, at most 256 KB, each side 16 to 4,000 pixels.
289
+ */
290
+ logo: {
291
+ /** The logo and its image (`data`, base64). 404 when there is none. */
292
+ retrieve: (o) => get("/account/logo", undefined, o),
293
+ /** Sets the logo, replacing any. `data` is the PNG or JPEG image, base64-encoded. */
294
+ set: (params, o) => send("PUT", "/account/logo", params, o),
295
+ /** Removes the logo; documents set the organisation's name again. */
296
+ delete: (o) => send("DELETE", "/account/logo", undefined, o),
297
+ },
298
+ };
299
+ /**
300
+ * The organisation's members, roles and invitations. **Dashboard sessions only** (403 `session_required`
301
+ * for any API key). Only owners change the team; every role may read it. The team is the same in test
302
+ * and live mode.
303
+ */
304
+ const team = {
305
+ members: {
306
+ /** Every member, owners first, on one page. */
307
+ list: (o) => list("/team/members", undefined, o),
308
+ /** Changes a member's role; the last owner cannot be demoted (409 `last_owner`). */
309
+ update: (memberId, params, o) => send("PATCH", `/team/members/${id(memberId)}`, params, o),
310
+ /** Removes a member, or yourself (leaving). Their API keys keep working: keys belong to the account. */
311
+ remove: (memberId, o) => send("DELETE", `/team/members/${id(memberId)}`, undefined, o),
312
+ /** Makes the member an owner and gives the calling owner `newRoleForSelf` (developer by default), in one step. */
313
+ transferOwnership: (memberId, params = {}, o) => post(`/team/members/${id(memberId)}/transfer_ownership`, params, o),
314
+ },
315
+ invitations: {
316
+ /** Open invitations, newest first; `includeClosed` adds accepted, revoked and expired ones. */
317
+ list: (params, o) => list("/team/invitations", params, o),
318
+ /** Emails the invitation; `emailed` says whether it went out, and `token` (once) builds the link to copy. */
319
+ create: (params, o) => post("/team/invitations", params, o),
320
+ revoke: (invitationId, o) => send("DELETE", `/team/invitations/${id(invitationId)}`, undefined, o),
321
+ /** Emails a new link and restarts the 7 days; the old link stops working. `token` is in the result once. */
322
+ resend: (invitationId, o) => post(`/team/invitations/${id(invitationId)}/resend`, undefined, o),
323
+ /** A pending invitation with its current `token`, to send the link yourself. Nothing is emailed. */
324
+ retrieveLink: (invitationId, o) => get(`/team/invitations/${id(invitationId)}/link`, undefined, o),
325
+ /** Accepts as the signed-in user, whose verified email must be the invited address. Single-use. */
326
+ accept: (params, o) => post("/invitations/accept", params, o, { noIdempotency: true }),
327
+ },
328
+ /**
329
+ * Workers who scan: people added by email who may use the Timbereye app and nothing else. Not members,
330
+ * not seats. Owners and developers add and remove them; every role may read the list.
331
+ */
332
+ scanners: {
333
+ /** Every scanner, on one page. */
334
+ list: (o) => list("/team/scanners", undefined, o),
335
+ /** Adds an address; the worker then signs in to the app with a code sent to it. Adding it again returns it. */
336
+ add: (params, o) => post("/team/scanners", params, o),
337
+ /** Removes a scanner and signs out every phone they signed in on. What they uploaded stays. */
338
+ remove: (scannerId, o) => send("DELETE", `/team/scanners/${id(scannerId)}`, undefined, o),
339
+ },
340
+ /** Phones signed in to the Timbereye app, test and live, newest first. */
341
+ deviceSignIns: {
342
+ list: (params, o) => list("/team/device_sign_ins", params, o),
343
+ /** Signs one phone out at once. Owners and developers. */
344
+ revoke: (deviceSignInId, o) => send("DELETE", `/team/device_sign_ins/${id(deviceSignInId)}`, undefined, o),
345
+ },
346
+ };
347
+ /** Who changed the team, the keys and the webhook secrets, newest first. Dashboard sessions only; owners and developers. */
348
+ const auditLog = {
349
+ list: (params, o) => list("/audit_log", params, o),
350
+ };
351
+ /**
352
+ * The developer console's own calls. **Dashboard sessions only** (403 `session_required` for any API key);
353
+ * there is no CLI command for them.
354
+ */
355
+ const consoleApi = {
356
+ /**
357
+ * `timbereye login`'s requests, for the console's approval page: read the one the CLI printed a code for, then
358
+ * approve it (the CLI receives the organisation's default test secret key once; send it in test mode) or refuse
359
+ * it. Owners and developers. The CLI's own steps take no credential and have no SDK method.
360
+ */
361
+ cliLogins: {
362
+ retrieve: (code, o) => get(`/cli_logins/${id(code)}`, undefined, o),
363
+ approve: (code, o) => post(`/cli_logins/${id(code)}/approve`, undefined, o, {
364
+ noIdempotency: true,
365
+ }),
366
+ deny: (code, o) => post(`/cli_logins/${id(code)}/deny`, undefined, o, {
367
+ noIdempotency: true,
368
+ }),
369
+ },
370
+ /**
371
+ * The signed-in person, the organisation and their role, which modes exist, onboarding and sign-up state
372
+ * and the setup checklist, in one call. Works for a session with no account (`account` is null).
373
+ */
374
+ bootstrap: (o) => get("/console/bootstrap", undefined, o),
375
+ /**
376
+ * Names the organisation, records the first-run answers and the step reached (so a person resumes where they
377
+ * left off) and, with `complete: true`, finishes first-run onboarding. Owners only.
378
+ */
379
+ updateOnboarding: (params, o) => post("/console/onboarding", params, o),
380
+ /**
381
+ * Starts a new organisation for a signed-in person who belongs to none, and makes them its owner. Capped per
382
+ * person (403 `organisationLimit`) and limited per hour (429). Retrying with the same idempotency key returns
383
+ * the same organisation.
384
+ */
385
+ createOrganisation: (params, o) => post("/console/organisations", params, o),
386
+ /**
387
+ * The organisation's data-use setting: whether Timbereye may use its live images and measurements to train its
388
+ * models (test-mode data never is). Owners only; audited.
389
+ */
390
+ dataUse: {
391
+ update: (params, o) => send("PATCH", "/console/data_use", params, o),
392
+ },
393
+ /**
394
+ * Requests for an export of the organisation's data or for closing it. Recording one emails Timbereye support,
395
+ * which replies within 30 days; nothing is exported or deleted by the call. Owners create them; every member lists them.
396
+ */
397
+ dataRequests: {
398
+ list: (o) => get("/console/data_requests", undefined, o),
399
+ create: (params, o) => post("/console/data_requests", params, o),
400
+ },
401
+ /**
402
+ * The console's Contact us form: a message to Timbereye support with the context the console attaches (the
403
+ * page, the session's failed request ids and codes, the browser). Every member may, viewers included; support
404
+ * replies by email. Limited per organisation (429). `list` is the signed-in person's own requests.
405
+ */
406
+ supportRequests: {
407
+ list: (o) => get("/console/support_requests", undefined, o),
408
+ create: (params, o) => post("/console/support_requests", params, o),
409
+ },
410
+ /**
411
+ * Records, once, the Terms of Service and Privacy Policy versions in force when this person first opens the console
412
+ * after signing up. Nothing is recorded for a person created before `termsEffective`.
413
+ */
414
+ recordAgreement: (params, o) => post("/console/agreements", params, o, { noIdempotency: true }),
415
+ /**
416
+ * **Timbereye staff only** (403 `staff_required`): turns live mode on or off for an organisation once its
417
+ * agreement and billing details are in place. Recorded in its audit log.
418
+ */
419
+ setLiveAccess: (accountId, params, o) => send("PUT", `/staff/accounts/${id(accountId)}/live_access`, params, o),
420
+ /**
421
+ * **Timbereye staff only** (403 `staff_required`): puts an organisation on a contract (invoiced by hand, or by
422
+ * an emailed invoice with terms, at a contract price per m³) or back on self-serve card billing.
423
+ */
424
+ setBillingPlan: (accountId, params, o) => send("PUT", `/staff/accounts/${id(accountId)}/billing`, params, o),
425
+ };
426
+ /**
427
+ * The organisation's billing: going live, the card, invoices and the spend cap. **Dashboard sessions only** (403
428
+ * `session_required` for any API key); every member may read it, owners change it. Billing belongs to the
429
+ * organisation, so it is the same in test and live mode. There is no CLI command for it.
430
+ */
431
+ const billing = {
432
+ /** Status, whether live work may start, terms, card on file, prices, this month so far, any overdue payment. */
433
+ retrieve: (o) => get("/billing", undefined, o),
434
+ /** Sets or removes the monthly spend cap (`spendCap: null` removes it). Owners only. */
435
+ update: (params, o) => send("PATCH", "/billing", params, o),
436
+ /** Accepts the live terms of the version `retrieve` shows. With a card on file, live mode turns on at once. */
437
+ acceptTerms: (params, o) => post("/billing/terms/accept", params, o),
438
+ /** The payment provider's page where an owner saves a card; it returns to `returnUrl` with `setup_session`. */
439
+ startCardSetup: (params, o) => post("/billing/card_setup", params, o),
440
+ /** Finishes saving the card once the owner is back (the provider's webhook does it too). */
441
+ confirmCardSetup: (params = {}, o) => post("/billing/card_setup/confirm", params, o),
442
+ /** The payment provider's portal: change the card, download receipts. */
443
+ createPortalSession: (params, o) => post("/billing/portal", params, o),
444
+ /** Stops live billing: live mode off at once, usage so far invoiced at the next monthly close, data kept. */
445
+ stop: (o) => post("/billing/stop", undefined, o),
446
+ /** Test payment provider only (local and preview): saves a test card that pays or declines. */
447
+ completeTestCard: (params, o) => post("/billing/test_card", params, o),
448
+ invoices: {
449
+ /** Monthly invoices, newest month first. */
450
+ list: (params, o) => list("/billing/invoices", params, o),
451
+ },
452
+ };
453
+ const models = {
454
+ /**
455
+ * The detector for a platform: `download_url` serves a Core ML ZIP for `ios` and a `.tflite` for `android`.
456
+ * `variant: "640"` asks for the smaller fallback. 503 `model_unavailable`: this environment has no model file yet.
457
+ */
458
+ retrieveDetector: (params, o) => get("/models/detector", params, o),
459
+ /**
460
+ * The lumber board-end counter (a preview) for a platform: the detector's fields plus the counting recipe
461
+ * (`tiling`, `count`). `variant: "s"` asks for the smaller model. 503 `model_unavailable`: none in this environment.
462
+ */
463
+ retrieveBoardEndCounter: (params, o) => get("/models/board-end-counter", params, o),
464
+ };
465
+ /**
466
+ * Test mode only (a `te_test_` key; a live key is refused with 403 `test_mode_only`). Exercises the whole loop
467
+ * with no phone and no segmentation service.
468
+ */
469
+ const testMode = {
470
+ /** Creates a scan of synthetic, tagged logs in a group and completes it. Safe to retry (idempotency key). */
471
+ simulateScan: (params, o) => post("/test/scans/simulate", params, o),
472
+ /** Resolves every pending refinement of the account with the simulator now, instead of waiting for the scheduler. */
473
+ runRefinements: (o) => post("/test/refinements/run", undefined, o),
474
+ /**
475
+ * Creates a packing list and its bundles or units from a scenario and tallies them, so `group.measured`
476
+ * arrives for each and, once all are final, for the list. Deterministic for a `seed`; never billed.
477
+ */
478
+ simulatePackingList: (params, o) => post("/test/packing_lists/simulate", params, o),
479
+ };
480
+ return {
481
+ testMode,
482
+ groups,
483
+ items,
484
+ scans,
485
+ images,
486
+ places,
487
+ labelTemplates,
488
+ tagBatches,
489
+ species,
490
+ volumeRules,
491
+ events,
492
+ webhookEndpoints,
493
+ captureTokens,
494
+ apiKeys,
495
+ team,
496
+ auditLog,
497
+ usage,
498
+ billing,
499
+ models,
500
+ account,
501
+ console: consoleApi,
502
+ };
503
+ }
@@ -0,0 +1,20 @@
1
+ /** Runtime helpers that must work in Node 18+, browsers and edge runtimes without Node-only imports. */
2
+ type CryptoLike = {
3
+ subtle: SubtleCrypto;
4
+ getRandomValues<T extends ArrayBufferView>(a: T): T;
5
+ randomUUID?: () => string;
6
+ };
7
+ /**
8
+ * Web Crypto. Node 19+, browsers and edge runtimes expose it as a global. Node 18 does not, so there
9
+ * the `node:crypto` module's `webcrypto` is loaded lazily through a non-literal specifier (which keeps
10
+ * bundlers from pulling it into browser builds).
11
+ */
12
+ export declare function getWebCrypto(): Promise<CryptoLike>;
13
+ /** A v4 UUID for idempotency keys. Uses crypto when present; uniqueness is all that matters here. */
14
+ export declare function randomUUID(): string;
15
+ /**
16
+ * An environment variable, or undefined where the runtime has no environment (browsers, some edge runtimes)
17
+ * or the value is empty.
18
+ */
19
+ export declare function readEnv(name: string): string | undefined;
20
+ export {};
@@ -0,0 +1,46 @@
1
+ /** Runtime helpers that must work in Node 18+, browsers and edge runtimes without Node-only imports. */
2
+ /**
3
+ * Web Crypto. Node 19+, browsers and edge runtimes expose it as a global. Node 18 does not, so there
4
+ * the `node:crypto` module's `webcrypto` is loaded lazily through a non-literal specifier (which keeps
5
+ * bundlers from pulling it into browser builds).
6
+ */
7
+ export async function getWebCrypto() {
8
+ const g = globalThis.crypto;
9
+ if (g?.subtle)
10
+ return g;
11
+ const spec = "node:crypto";
12
+ try {
13
+ const m = (await import(/* webpackIgnore: true */ /* @vite-ignore */ spec));
14
+ if (m.webcrypto?.subtle)
15
+ return m.webcrypto;
16
+ }
17
+ catch {
18
+ // fall through
19
+ }
20
+ throw new Error("timbereye: Web Crypto (crypto.subtle) is not available in this runtime");
21
+ }
22
+ /** A v4 UUID for idempotency keys. Uses crypto when present; uniqueness is all that matters here. */
23
+ export function randomUUID() {
24
+ const g = globalThis.crypto;
25
+ if (g?.randomUUID)
26
+ return g.randomUUID();
27
+ const b = new Uint8Array(16);
28
+ if (g?.getRandomValues)
29
+ g.getRandomValues(b);
30
+ else
31
+ for (let i = 0; i < 16; i++)
32
+ b[i] = Math.floor(Math.random() * 256);
33
+ b[6] = (b[6] & 0x0f) | 0x40;
34
+ b[8] = (b[8] & 0x3f) | 0x80;
35
+ const h = Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
36
+ return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
37
+ }
38
+ /**
39
+ * An environment variable, or undefined where the runtime has no environment (browsers, some edge runtimes)
40
+ * or the value is empty.
41
+ */
42
+ export function readEnv(name) {
43
+ const env = globalThis.process?.env;
44
+ const value = env?.[name]?.trim();
45
+ return value === undefined || value === "" ? undefined : value;
46
+ }