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