@timbereye/sdk 0.1.0 → 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.
- package/CHANGELOG.md +59 -4
- package/README.md +37 -21
- package/dist/cjs/case.d.ts +1 -1
- package/dist/cjs/case.js +9 -1
- package/dist/cjs/client.d.ts +12 -3
- package/dist/cjs/client.js +13 -3
- package/dist/cjs/generated/schema.d.ts +1531 -105
- package/dist/cjs/http.d.ts +13 -1
- package/dist/cjs/http.js +19 -4
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/resources.d.ts +3484 -168
- package/dist/cjs/resources.js +60 -10
- package/dist/cjs/types.d.ts +135 -11
- package/dist/cjs/webhooks.d.ts +23 -0
- package/dist/cjs/webhooks.js +64 -0
- package/dist/esm/case.d.ts +1 -1
- package/dist/esm/case.js +9 -1
- package/dist/esm/client.d.ts +12 -3
- package/dist/esm/client.js +14 -4
- package/dist/esm/generated/schema.d.ts +1531 -105
- package/dist/esm/http.d.ts +13 -1
- package/dist/esm/http.js +19 -4
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/resources.d.ts +3484 -168
- package/dist/esm/resources.js +60 -10
- package/dist/esm/types.d.ts +135 -11
- package/dist/esm/webhooks.d.ts +23 -0
- package/dist/esm/webhooks.js +64 -1
- package/package.json +5 -5
package/dist/cjs/resources.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.createResources = createResources;
|
|
|
4
4
|
const pagination_js_1 = require("./pagination.js");
|
|
5
5
|
const case_js_1 = require("./case.js");
|
|
6
6
|
const id = (v) => encodeURIComponent(v);
|
|
7
|
-
/** Builds the resource tree. One method per operation in
|
|
7
|
+
/** Builds the resource tree. One method per operation in the OpenAPI document (https://www.timbereye.com/docs/openapi.yaml). */
|
|
8
8
|
function createResources(t) {
|
|
9
9
|
const get = (path, query, o) => t.request({ method: "GET", path, query: query }, o);
|
|
10
10
|
const post = (path, body, o, extra) => t.request({ method: "POST", path, body, ...extra }, o);
|
|
@@ -43,20 +43,32 @@ function createResources(t) {
|
|
|
43
43
|
/** The group's photos, oldest first, with kind, caption, who took them and a 15-minute `downloadUrl`. */
|
|
44
44
|
listImages: (groupId, params, o) => list(`/groups/${id(groupId)}/images`, params, o),
|
|
45
45
|
/**
|
|
46
|
-
* Lumber and panels
|
|
47
|
-
* parent created in the same call (a
|
|
46
|
+
* Lumber and panels: up to 500 groups in one call and one transaction, optionally under a
|
|
47
|
+
* parent created in the same call (a container and its bundles) or an existing `parentId`.
|
|
48
48
|
*/
|
|
49
49
|
createBatch: (params, o) => post("/groups/batch", params, o),
|
|
50
50
|
/** A bundle's tally sheet: the tally with its lines and a `document` block, or with `format: "html"` a printable page. */
|
|
51
51
|
tallySheet: (groupId, params, o) => get(`/groups/${id(groupId)}/tally_sheet`, params, o),
|
|
52
52
|
/**
|
|
53
|
-
* The packing list of
|
|
54
|
-
* thickness × length pivot, `totals` under the list's convention and
|
|
53
|
+
* The packing list of any group that holds bundles or units (a container, truck load, stack): one row per
|
|
54
|
+
* bundle or unit, width classes, the thickness × length pivot, `totals` under the list's convention and
|
|
55
|
+
* `totalsAlternative` under the other. A shipment whose containers sit inside it reads as one list: each
|
|
56
|
+
* row's `inGroup` names its container and `groups` gives each container's totals; `logs` lists its logs.
|
|
57
|
+
*
|
|
58
|
+
* With `format: "pdf"` it resolves to the document itself (`{ data, contentType, fileName }`), made from the
|
|
59
|
+
* group's data on every call: `paper` is `"a4"` or `"letter"`, `detail: "tally"` adds each bundle's tally lines.
|
|
55
60
|
*/
|
|
56
|
-
packingList: (groupId, params, o) =>
|
|
61
|
+
packingList: (groupId, params, o) => (params?.format === "pdf"
|
|
62
|
+
? t.request({
|
|
63
|
+
method: "GET",
|
|
64
|
+
path: `/groups/${id(groupId)}/packing_list`,
|
|
65
|
+
query: params,
|
|
66
|
+
binary: true,
|
|
67
|
+
}, o)
|
|
68
|
+
: get(`/groups/${id(groupId)}/packing_list`, params, o)),
|
|
57
69
|
/** Where a group has been: its parents over time, oldest first, the current one last. */
|
|
58
70
|
listParents: (groupId, o) => list(`/groups/${id(groupId)}/parents`, undefined, o),
|
|
59
|
-
/** A lumber bundle's or panel unit's tally
|
|
71
|
+
/** A lumber bundle's or panel unit's tally. */
|
|
60
72
|
tally: {
|
|
61
73
|
/** The tally: lines, what the rule tallied, totals by length and width, the label beside the count. */
|
|
62
74
|
retrieve: (groupId, params, o) => get(`/groups/${id(groupId)}/tally`, params, o),
|
|
@@ -181,6 +193,8 @@ function createResources(t) {
|
|
|
181
193
|
list: (params, o) => list("/label_templates", params, o),
|
|
182
194
|
retrieve: (templateId, o) => get(`/label_templates/${id(templateId)}`, undefined, o),
|
|
183
195
|
update: (templateId, params, o) => send("PATCH", `/label_templates/${id(templateId)}`, params, o),
|
|
196
|
+
/** Deletes a template; one a batch was made with is kept (409 `label_template_in_use`). */
|
|
197
|
+
delete: (templateId, o) => send("DELETE", `/label_templates/${id(templateId)}`, undefined, o),
|
|
184
198
|
/** One test label (short id TEST0) after a 62 mm ruler label: print it and measure with a ruler. */
|
|
185
199
|
testLabel: (templateId, params, o) => get(`/label_templates/${id(templateId)}/test_label`, params, o),
|
|
186
200
|
};
|
|
@@ -267,6 +281,23 @@ function createResources(t) {
|
|
|
267
281
|
* live mode, because test-mode requests need the test account to exist already.
|
|
268
282
|
*/
|
|
269
283
|
createTestAccount: (o) => post("/account/test_mode", undefined, o),
|
|
284
|
+
/**
|
|
285
|
+
* Changes the organisation's lumber settings in this mode (`account.lumber`): whether phones may open lumber
|
|
286
|
+
* groups, the default board-foot method (`perBoard` or `bundleTotal`), whether new bundles need photos.
|
|
287
|
+
*/
|
|
288
|
+
updateLumber: (params, o) => send("PATCH", "/account/lumber", params, o),
|
|
289
|
+
/**
|
|
290
|
+
* The organisation's logo, printed top left on its documents (the packing list PDF), in both modes. Without
|
|
291
|
+
* one, documents set the organisation's name. PNG or JPEG, at most 256 KB, each side 16 to 4,000 pixels.
|
|
292
|
+
*/
|
|
293
|
+
logo: {
|
|
294
|
+
/** The logo and its image (`data`, base64). 404 when there is none. */
|
|
295
|
+
retrieve: (o) => get("/account/logo", undefined, o),
|
|
296
|
+
/** Sets the logo, replacing any. `data` is the PNG or JPEG image, base64-encoded. */
|
|
297
|
+
set: (params, o) => send("PUT", "/account/logo", params, o),
|
|
298
|
+
/** Removes the logo; documents set the organisation's name again. */
|
|
299
|
+
delete: (o) => send("DELETE", "/account/logo", undefined, o),
|
|
300
|
+
},
|
|
270
301
|
};
|
|
271
302
|
/**
|
|
272
303
|
* The organisation's members, roles and invitations. **Dashboard sessions only** (403 `session_required`
|
|
@@ -287,11 +318,13 @@ function createResources(t) {
|
|
|
287
318
|
invitations: {
|
|
288
319
|
/** Open invitations, newest first; `includeClosed` adds accepted, revoked and expired ones. */
|
|
289
320
|
list: (params, o) => list("/team/invitations", params, o),
|
|
290
|
-
/** `
|
|
321
|
+
/** Emails the invitation; `emailed` says whether it went out, and `token` (once) builds the link to copy. */
|
|
291
322
|
create: (params, o) => post("/team/invitations", params, o),
|
|
292
323
|
revoke: (invitationId, o) => send("DELETE", `/team/invitations/${id(invitationId)}`, undefined, o),
|
|
293
|
-
/**
|
|
324
|
+
/** Emails a new link and restarts the 7 days; the old link stops working. `token` is in the result once. */
|
|
294
325
|
resend: (invitationId, o) => post(`/team/invitations/${id(invitationId)}/resend`, undefined, o),
|
|
326
|
+
/** A pending invitation with its current `token`, to send the link yourself. Nothing is emailed. */
|
|
327
|
+
retrieveLink: (invitationId, o) => get(`/team/invitations/${id(invitationId)}/link`, undefined, o),
|
|
295
328
|
/** Accepts as the signed-in user, whose verified email must be the invited address. Single-use. */
|
|
296
329
|
accept: (params, o) => post("/invitations/accept", params, o, { noIdempotency: true }),
|
|
297
330
|
},
|
|
@@ -368,6 +401,15 @@ function createResources(t) {
|
|
|
368
401
|
list: (o) => get("/console/data_requests", undefined, o),
|
|
369
402
|
create: (params, o) => post("/console/data_requests", params, o),
|
|
370
403
|
},
|
|
404
|
+
/**
|
|
405
|
+
* The console's Contact us form: a message to Timbereye support with the context the console attaches (the
|
|
406
|
+
* page, the session's failed request ids and codes, the browser). Every member may, viewers included; support
|
|
407
|
+
* replies by email. Limited per organisation (429). `list` is the signed-in person's own requests.
|
|
408
|
+
*/
|
|
409
|
+
supportRequests: {
|
|
410
|
+
list: (o) => get("/console/support_requests", undefined, o),
|
|
411
|
+
create: (params, o) => post("/console/support_requests", params, o),
|
|
412
|
+
},
|
|
371
413
|
/**
|
|
372
414
|
* Records, once, the Terms of Service and Privacy Policy versions in force when this person first opens the console
|
|
373
415
|
* after signing up. Nothing is recorded for a person created before `termsEffective`.
|
|
@@ -412,8 +454,16 @@ function createResources(t) {
|
|
|
412
454
|
},
|
|
413
455
|
};
|
|
414
456
|
const models = {
|
|
415
|
-
/**
|
|
457
|
+
/**
|
|
458
|
+
* The detector for a platform: `download_url` serves a Core ML ZIP for `ios` and a `.tflite` for `android`.
|
|
459
|
+
* `variant: "640"` asks for the smaller fallback. 503 `model_unavailable`: this environment has no model file yet.
|
|
460
|
+
*/
|
|
416
461
|
retrieveDetector: (params, o) => get("/models/detector", params, o),
|
|
462
|
+
/**
|
|
463
|
+
* The lumber board-end counter (a preview) for a platform: the detector's fields plus the counting recipe
|
|
464
|
+
* (`tiling`, `count`). `variant: "s"` asks for the smaller model. 503 `model_unavailable`: none in this environment.
|
|
465
|
+
*/
|
|
466
|
+
retrieveBoardEndCounter: (params, o) => get("/models/board-end-counter", params, o),
|
|
417
467
|
};
|
|
418
468
|
/**
|
|
419
469
|
* Test mode only (a `te_test_` key; a live key is refused with 403 `test_mode_only`). Exercises the whole loop
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ export type Schemas = {
|
|
|
6
6
|
[K in keyof S]: Camel<S[K]>;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* A group. Lumber and panel groups
|
|
10
|
-
* `totalsConvention`, `photos` and `images`, and `summary.pieces` and `summary.tally`.
|
|
9
|
+
* A group. Lumber and panel groups also carry `spec`, `bundle`, `rule`, `expected`,
|
|
10
|
+
* `totalsConvention`, `photos` and `images`, and `summary.pieces` and `summary.tally`. Every group's
|
|
11
|
+
* `summary.products` says what it holds, product by product (a group may hold logs, bundles and units).
|
|
11
12
|
*/
|
|
12
13
|
export type Group = Omit<Schemas["Group"], "spec" | "bundle" | "rule" | "expected" | "summary" | "parent"> & {
|
|
13
14
|
summary: Omit<Schemas["Group"]["summary"], "tally"> & {
|
|
@@ -33,6 +34,8 @@ export type Place = Schemas["Place"];
|
|
|
33
34
|
export type PlaceValidation = Schemas["PlaceValidation"];
|
|
34
35
|
export type Species = Schemas["Species"];
|
|
35
36
|
export type Volume = Schemas["Volume"];
|
|
37
|
+
/** One log's volume on an item (`item.volume`): rule, ruleVersion and m3, null while unmeasured. */
|
|
38
|
+
export type ItemVolume = Schemas["ItemVolume"];
|
|
36
39
|
export type VolumeRule = Schemas["VolumeRule"];
|
|
37
40
|
export type Origin = Schemas["Origin"];
|
|
38
41
|
export type Event = Schemas["Event"];
|
|
@@ -41,10 +44,11 @@ export type WebhookEndpoint = Schemas["WebhookEndpoint"];
|
|
|
41
44
|
export type WebhookEndpointDeleted = Schemas["WebhookEndpointDeleted"];
|
|
42
45
|
export type GroupDeleted = Schemas["GroupDeleted"];
|
|
43
46
|
export type PlaceDeleted = Schemas["PlaceDeleted"];
|
|
47
|
+
export type LabelTemplateDeleted = Schemas["LabelTemplateDeleted"];
|
|
44
48
|
export type CaptureToken = Schemas["CaptureToken"];
|
|
45
49
|
export type ApiKey = Schemas["ApiKey"];
|
|
46
50
|
/**
|
|
47
|
-
* Metered usage. Lumber and panels
|
|
51
|
+
* Metered usage. Lumber and panels: `lumber` and `panels` hold the period's figures; only `m3` is
|
|
48
52
|
* billed (at the one price per m³), the rest are counts for display.
|
|
49
53
|
*/
|
|
50
54
|
export type Usage = Omit<Schemas["Usage"], "lumber" | "panels"> & {
|
|
@@ -63,6 +67,7 @@ export type Usage = Omit<Schemas["Usage"], "lumber" | "panels"> & {
|
|
|
63
67
|
};
|
|
64
68
|
export type UsageRecord = Schemas["UsageRecord"];
|
|
65
69
|
export type DetectorModel = Schemas["DetectorModel"];
|
|
70
|
+
export type BoardEndCounterModel = Schemas["BoardEndCounterModel"];
|
|
66
71
|
export type BulkUpdateResult = Schemas["BulkUpdateResult"];
|
|
67
72
|
export type GroupMembership = Schemas["GroupMembership"];
|
|
68
73
|
export type TeamMember = Schemas["TeamMember"];
|
|
@@ -81,6 +86,14 @@ export type WebhookEvent = Event;
|
|
|
81
86
|
export type ItemLengthInput = Schemas["ItemLengthInput"];
|
|
82
87
|
export type LengthInput = Schemas["LengthInput"];
|
|
83
88
|
export type GroupWeightInput = Schemas["GroupWeightInput"];
|
|
89
|
+
/**
|
|
90
|
+
* A group's shipping details, as stored (`group.shipping`): the parties, references, voyage, ports and seal the packing
|
|
91
|
+
* list PDF prints. Display only: Timbereye prints them as given and does not issue, validate or file shipping documents.
|
|
92
|
+
*/
|
|
93
|
+
export type GroupShipping = Schemas["GroupShipping"];
|
|
94
|
+
/** `shipping` on create, open and update: each field optional; on update a field you send replaces it, null removes it. */
|
|
95
|
+
export type GroupShippingInput = Schemas["GroupShippingInput"];
|
|
96
|
+
export type ShippingParty = Schemas["ShippingParty"];
|
|
84
97
|
export type ItemRefSelector = Schemas["ItemRefSelector"];
|
|
85
98
|
export type ItemPatch = Schemas["ItemPatch"];
|
|
86
99
|
export type ScanItemInput = Schemas["ScanItemInput"];
|
|
@@ -103,12 +116,22 @@ export type OnboardingOrganisation = Schemas["OnboardingOrganisation"];
|
|
|
103
116
|
export type OnboardingMeasures = Schemas["OnboardingMeasures"];
|
|
104
117
|
export type ConsoleOrganisation = Schemas["ConsoleOrganisation"];
|
|
105
118
|
export type AccountDataUse = Schemas["AccountDataUse"];
|
|
119
|
+
export type AccountLumberSettings = Schemas["AccountLumberSettings"];
|
|
120
|
+
export type AccountLumberSettingsObject = Schemas["AccountLumberSettingsObject"];
|
|
121
|
+
export type AccountLogo = Camel<Schemas["AccountLogo"]>;
|
|
122
|
+
export type AccountLogoSetParams = Schemas["AccountLogoSet"];
|
|
123
|
+
export type AccountLogoDeleted = Schemas["AccountLogoDeleted"];
|
|
124
|
+
export type AccountLumberSettingsUpdateParams = Schemas["AccountLumberSettingsUpdate"];
|
|
106
125
|
export type AccountDataRequest = Schemas["AccountDataRequest"];
|
|
107
126
|
export type AccountDataRequestList = Schemas["AccountDataRequestList"];
|
|
127
|
+
export type SupportRequest = Schemas["SupportRequest"];
|
|
128
|
+
export type SupportRequestList = Schemas["SupportRequestList"];
|
|
129
|
+
export type SupportRequestCategory = Schemas["SupportRequestCategory"];
|
|
130
|
+
export type SupportRequestContext = Schemas["SupportRequestContext"];
|
|
108
131
|
export type LegalAgreement = Schemas["LegalAgreement"];
|
|
109
132
|
export type ConsoleAgreement = Schemas["ConsoleAgreement"];
|
|
110
133
|
export type LiveAccess = Schemas["LiveAccess"];
|
|
111
|
-
/** Billing. `currentPeriod` gains `lumberM3` and `panelM3`
|
|
134
|
+
/** Billing. `currentPeriod` gains `lumberM3` and `panelM3` where the server reports them. */
|
|
112
135
|
export type Billing = Omit<Schemas["Billing"], "currentPeriod"> & {
|
|
113
136
|
currentPeriod: Schemas["Billing"]["currentPeriod"] & {
|
|
114
137
|
lumberM3?: number;
|
|
@@ -165,6 +188,7 @@ export type ConsoleOnboardingUpdateParams = Schemas["ConsoleOnboardingUpdate"];
|
|
|
165
188
|
export type ConsoleOrganisationCreateParams = Schemas["ConsoleOrganisationCreate"];
|
|
166
189
|
export type ConsoleDataUseUpdateParams = Schemas["ConsoleDataUseUpdate"];
|
|
167
190
|
export type AccountDataRequestCreateParams = Schemas["AccountDataRequestCreate"];
|
|
191
|
+
export type SupportRequestCreateParams = Schemas["SupportRequestCreate"];
|
|
168
192
|
export type ConsoleAgreementCreateParams = Schemas["ConsoleAgreementCreate"];
|
|
169
193
|
export type LiveAccessUpdateParams = Schemas["LiveAccessUpdate"];
|
|
170
194
|
export type BillingUpdateParams = Schemas["BillingUpdate"];
|
|
@@ -228,7 +252,7 @@ export type LumberGroupFields = {
|
|
|
228
252
|
/** One group of a batch: the fields of `groups.create`, including the lumber and panel fields. */
|
|
229
253
|
export type LumberGroupCreateParams = Omit<Schemas["LumberGroupCreate"], keyof LumberGroupFields> & LumberGroupFields;
|
|
230
254
|
export type GroupBatchCreateParams = {
|
|
231
|
-
/** A parent created in the same call (a
|
|
255
|
+
/** A parent created in the same call (a container, truck load or stack). */
|
|
232
256
|
parent?: LumberGroupCreateParams;
|
|
233
257
|
/** Or an existing parent. */
|
|
234
258
|
parentId?: string;
|
|
@@ -274,6 +298,21 @@ export type GroupTallySubmitParams = {
|
|
|
274
298
|
lines: TallyLineInput[];
|
|
275
299
|
/** The submission this one replaces; 409 `tally_replaced` when it is not the current one. */
|
|
276
300
|
replaces?: string;
|
|
301
|
+
/**
|
|
302
|
+
* The bundle's revision the sender last saw (0: no final tally yet); any other current revision is 409
|
|
303
|
+
* `tally_replaced`, so a re-tally never silently replaces a correction made meanwhile.
|
|
304
|
+
*/
|
|
305
|
+
replacesRevision?: number;
|
|
306
|
+
/** Pieces counted on a photo or read off the label, beside the tally's pieces. */
|
|
307
|
+
visionCount?: {
|
|
308
|
+
countedPieces: number;
|
|
309
|
+
imageId?: string;
|
|
310
|
+
regions?: unknown[];
|
|
311
|
+
model?: string;
|
|
312
|
+
confirmed?: boolean;
|
|
313
|
+
/** Who counted: a counting `model`, the operator tapping board ends (`operator_taps`), or the label (`operator_label`). */
|
|
314
|
+
method?: "model" | "operator_taps" | "operator_label";
|
|
315
|
+
};
|
|
277
316
|
/** Photos of the bundle already uploaded with `images.createUploadSession` (subject group). */
|
|
278
317
|
imageIds?: string[];
|
|
279
318
|
device?: Record<string, unknown>;
|
|
@@ -308,8 +347,14 @@ export type TallySheetParams = {
|
|
|
308
347
|
export type PackingListParams = {
|
|
309
348
|
totals?: "exact" | "reported";
|
|
310
349
|
include?: "tally_sheets";
|
|
311
|
-
|
|
312
|
-
|
|
350
|
+
/** `pdf`: the document itself (a `BinaryResponse`). */
|
|
351
|
+
format?: "json" | "html" | "pdf";
|
|
352
|
+
/** With `format: "pdf"`: by default Letter for lumber in inches and feet, else A4. */
|
|
353
|
+
paper?: "a4" | "letter";
|
|
354
|
+
/** With `format: "pdf"`: `tally` adds each bundle's tally lines. */
|
|
355
|
+
detail?: "tally";
|
|
356
|
+
};
|
|
357
|
+
export type { BinaryResponse } from "./http.js";
|
|
313
358
|
export type TallyRevisionListParams = {
|
|
314
359
|
itemId?: string;
|
|
315
360
|
limit?: number;
|
|
@@ -335,6 +380,7 @@ export type PhotosStatus = {
|
|
|
335
380
|
noPhoto: boolean;
|
|
336
381
|
missing: string[];
|
|
337
382
|
count: number;
|
|
383
|
+
/** The count per image kind, keyed by the kind as the API writes it (`bundle_end`), not camelCased. */
|
|
338
384
|
byKind: Record<string, number>;
|
|
339
385
|
ids: string[];
|
|
340
386
|
};
|
|
@@ -373,6 +419,8 @@ export type GroupTally = Omit<Schemas["LumberGroupTally"], "totals" | "lines"> &
|
|
|
373
419
|
revision: number;
|
|
374
420
|
/** Pieces counted on a photo (a vision count sent with the tally), beside the tally's `pieces`. */
|
|
375
421
|
countedPieces: number | null;
|
|
422
|
+
/** Who counted (`visionCount.method`), or null when nothing was counted. */
|
|
423
|
+
countMethod: "model" | "operator_taps" | "operator_label" | null;
|
|
376
424
|
countMatches: boolean | null;
|
|
377
425
|
countDifference: number | null;
|
|
378
426
|
rule: TallyRuleApplied | null;
|
|
@@ -410,6 +458,7 @@ export type GroupTally = Omit<Schemas["LumberGroupTally"], "totals" | "lines"> &
|
|
|
410
458
|
regions: unknown[] | null;
|
|
411
459
|
model: string | null;
|
|
412
460
|
confirmed: boolean;
|
|
461
|
+
method?: "model" | "operator_taps" | "operator_label";
|
|
413
462
|
} | null;
|
|
414
463
|
pieces: number;
|
|
415
464
|
createdAt: string;
|
|
@@ -424,6 +473,9 @@ export type GroupTally = Omit<Schemas["LumberGroupTally"], "totals" | "lines"> &
|
|
|
424
473
|
/** One row of a packing list: a bundle with its pieces, figures and (for width-class tallies) its histogram. */
|
|
425
474
|
export type PackingListRow = {
|
|
426
475
|
groupId: string;
|
|
476
|
+
/** A group may hold bundles and units together: `lumber` or `panel`. */
|
|
477
|
+
product: LumberProduct;
|
|
478
|
+
kind: string | null;
|
|
427
479
|
externalRef: string | null;
|
|
428
480
|
number: string | null;
|
|
429
481
|
qualityCode: string | null;
|
|
@@ -432,13 +484,57 @@ export type PackingListRow = {
|
|
|
432
484
|
final: boolean;
|
|
433
485
|
rule: string | null;
|
|
434
486
|
pieces: number;
|
|
487
|
+
/** The lengths its tally has, shortest first (empty before a tally). */
|
|
488
|
+
lengths?: {
|
|
489
|
+
value: number;
|
|
490
|
+
unit: string;
|
|
491
|
+
}[];
|
|
435
492
|
histogram: Record<string, number> | null;
|
|
493
|
+
/**
|
|
494
|
+
* The group inside the list's group that this row sits in (a shipment's container), or null for a bundle or unit
|
|
495
|
+
* directly in the list's group.
|
|
496
|
+
*/
|
|
497
|
+
inGroup: {
|
|
498
|
+
groupId: string;
|
|
499
|
+
kind: string | null;
|
|
500
|
+
name: string | null;
|
|
501
|
+
externalRef: string | null;
|
|
502
|
+
} | null;
|
|
436
503
|
[field: string]: unknown;
|
|
437
504
|
};
|
|
438
505
|
export type PackingListTotals = LumberTotals & {
|
|
439
506
|
convention: "exact" | "reported";
|
|
440
507
|
bundles: number;
|
|
441
508
|
};
|
|
509
|
+
/** One log of a packing list, as stored: tag, species, grade, length, small-end diameters and JAS volume. */
|
|
510
|
+
export type PackingListLog = {
|
|
511
|
+
itemId: string;
|
|
512
|
+
product: "sawlog";
|
|
513
|
+
/** The tag's payload; null for an untagged log. */
|
|
514
|
+
tag: string | null;
|
|
515
|
+
species: string;
|
|
516
|
+
grade: string | null;
|
|
517
|
+
lengthM: number;
|
|
518
|
+
diameterShortM: number;
|
|
519
|
+
diameterLongM: number;
|
|
520
|
+
/** JAS volume as recorded for the log. */
|
|
521
|
+
m3: number;
|
|
522
|
+
inGroup: PackingListRow["inGroup"];
|
|
523
|
+
};
|
|
524
|
+
/** A group's weighbridge net weight on a packing list. */
|
|
525
|
+
export type PackingListWeight = {
|
|
526
|
+
netKg: number;
|
|
527
|
+
ticketRef: string | null;
|
|
528
|
+
};
|
|
529
|
+
/** A packing list's logs, per group or in all: how many and their JAS volume. */
|
|
530
|
+
export type PackingListSawlogTotals = {
|
|
531
|
+
count: number;
|
|
532
|
+
totals: {
|
|
533
|
+
rule: "jas";
|
|
534
|
+
logs: number;
|
|
535
|
+
m3: number;
|
|
536
|
+
};
|
|
537
|
+
};
|
|
442
538
|
export type PackingList = {
|
|
443
539
|
object: "packing_list";
|
|
444
540
|
livemode: boolean;
|
|
@@ -457,10 +553,39 @@ export type PackingList = {
|
|
|
457
553
|
unit: string;
|
|
458
554
|
}[];
|
|
459
555
|
pivot: Record<string, unknown>[];
|
|
460
|
-
/**
|
|
461
|
-
|
|
556
|
+
/**
|
|
557
|
+
* Under the list's convention: the list's own product's, or, for a group without a product, the one product it
|
|
558
|
+
* holds. Null while a group without a product holds bundles and units (see `totalsByProduct`).
|
|
559
|
+
*/
|
|
560
|
+
totals: PackingListTotals | null;
|
|
462
561
|
/** Under the other convention. */
|
|
463
|
-
totalsAlternative: PackingListTotals;
|
|
562
|
+
totalsAlternative: PackingListTotals | null;
|
|
563
|
+
/** Per product, never added together: how many bundles or units, and their totals under both conventions. */
|
|
564
|
+
totalsByProduct: Partial<Record<LumberProduct, {
|
|
565
|
+
count: number;
|
|
566
|
+
totals: PackingListTotals;
|
|
567
|
+
totalsAlternative: PackingListTotals;
|
|
568
|
+
}>> & {
|
|
569
|
+
sawlog?: PackingListSawlogTotals;
|
|
570
|
+
};
|
|
571
|
+
/** The logs in the group and in the groups inside it, oldest first within each group. */
|
|
572
|
+
logs: PackingListLog[];
|
|
573
|
+
/** More logs than a packing list lists (5,000). */
|
|
574
|
+
logsHasMore: boolean;
|
|
575
|
+
/** The group's weighbridge net weight, when it has one. */
|
|
576
|
+
weight: PackingListWeight | null;
|
|
577
|
+
/**
|
|
578
|
+
* The groups inside this one that hold rows (a shipment's containers), in row order, each with its own totals
|
|
579
|
+
* per product. Empty for a group whose bundles and units sit directly in it.
|
|
580
|
+
*/
|
|
581
|
+
groups: {
|
|
582
|
+
groupId: string;
|
|
583
|
+
kind: string | null;
|
|
584
|
+
name: string | null;
|
|
585
|
+
externalRef: string | null;
|
|
586
|
+
totalsByProduct: PackingList["totalsByProduct"];
|
|
587
|
+
weight: PackingListWeight | null;
|
|
588
|
+
}[];
|
|
464
589
|
tallySheets?: GroupTally[];
|
|
465
590
|
document?: DocumentBlock;
|
|
466
591
|
[field: string]: unknown;
|
|
@@ -522,4 +647,3 @@ export type ScanImageParams = {
|
|
|
522
647
|
file: Blob | Uint8Array | ArrayBuffer;
|
|
523
648
|
filename?: string;
|
|
524
649
|
};
|
|
525
|
-
export {};
|
package/dist/cjs/webhooks.d.ts
CHANGED
|
@@ -42,3 +42,26 @@ export declare function readWebhookRequest(req: WebhookRequest): Promise<{
|
|
|
42
42
|
* It is async because Web Crypto is: `await te.webhooks.verify(...)`.
|
|
43
43
|
*/
|
|
44
44
|
export declare function verifyWebhook(rawBody: string | Uint8Array | ArrayBuffer, headers: HeadersInput, secret: string | string[], options?: VerifyOptions): Promise<WebhookEvent>;
|
|
45
|
+
/** What {@link generateTestWebhookHeaders} signs. */
|
|
46
|
+
export interface TestWebhookParams {
|
|
47
|
+
/** The raw body to sign, exactly as your handler will receive it (a string or bytes, not an object). */
|
|
48
|
+
payload: string | Uint8Array | ArrayBuffer;
|
|
49
|
+
/** The `whsec_…` secret your handler verifies with. */
|
|
50
|
+
secret: string;
|
|
51
|
+
/** `webhook-id`. Default: the payload's `id` when it is an event (as in a real delivery), else `msg_` and random hex. */
|
|
52
|
+
id?: string;
|
|
53
|
+
/** `webhook-timestamp`, in Unix seconds. Default: now. Pass an old one to test your handler's tolerance. */
|
|
54
|
+
timestamp?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The headers Timbereye would send with `payload`, signed with `secret` (Standard Webhooks: `webhook-id`,
|
|
58
|
+
* `webhook-timestamp`, `webhook-signature`), for testing your webhook handler without the network. `verifyWebhook`
|
|
59
|
+
* accepts them. Never use it to accept a request: it signs, it does not check.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const body = JSON.stringify(event)
|
|
63
|
+
* const headers = await generateTestWebhookHeaders({ payload: body, secret: "whsec_…" })
|
|
64
|
+
* await handler(new Request("http://localhost/webhooks", { method: "POST", body, headers }))
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function generateTestWebhookHeaders(params: TestWebhookParams): Promise<Record<string, string>>;
|
package/dist/cjs/webhooks.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readWebhookRequest = readWebhookRequest;
|
|
4
4
|
exports.verifyWebhook = verifyWebhook;
|
|
5
|
+
exports.generateTestWebhookHeaders = generateTestWebhookHeaders;
|
|
5
6
|
const case_js_1 = require("./case.js");
|
|
6
7
|
const errors_js_1 = require("./errors.js");
|
|
7
8
|
const runtime_js_1 = require("./runtime.js");
|
|
@@ -147,3 +148,66 @@ async function verifyWebhook(rawBody, headers, secret, options = {}) {
|
|
|
147
148
|
throw new errors_js_1.WebhookSignatureError("invalid_payload", "Webhook body is not valid JSON");
|
|
148
149
|
}
|
|
149
150
|
}
|
|
151
|
+
function bytesOf(payload) {
|
|
152
|
+
return typeof payload === "string"
|
|
153
|
+
? new TextEncoder().encode(payload)
|
|
154
|
+
: payload instanceof Uint8Array
|
|
155
|
+
? payload
|
|
156
|
+
: new Uint8Array(payload);
|
|
157
|
+
}
|
|
158
|
+
function b64encode(bytes) {
|
|
159
|
+
let bin = "";
|
|
160
|
+
for (let i = 0; i < bytes.length; i++)
|
|
161
|
+
bin += String.fromCharCode(bytes[i]);
|
|
162
|
+
return btoa(bin);
|
|
163
|
+
}
|
|
164
|
+
function defaultMessageId(body) {
|
|
165
|
+
try {
|
|
166
|
+
const parsed = JSON.parse(new TextDecoder().decode(body));
|
|
167
|
+
if (typeof parsed?.id === "string" && parsed.id !== "")
|
|
168
|
+
return parsed.id;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// not JSON: a random id
|
|
172
|
+
}
|
|
173
|
+
return `msg_${(0, runtime_js_1.randomUUID)().replace(/-/g, "").slice(0, 24)}`;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The headers Timbereye would send with `payload`, signed with `secret` (Standard Webhooks: `webhook-id`,
|
|
177
|
+
* `webhook-timestamp`, `webhook-signature`), for testing your webhook handler without the network. `verifyWebhook`
|
|
178
|
+
* accepts them. Never use it to accept a request: it signs, it does not check.
|
|
179
|
+
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* const body = JSON.stringify(event)
|
|
182
|
+
* const headers = await generateTestWebhookHeaders({ payload: body, secret: "whsec_…" })
|
|
183
|
+
* await handler(new Request("http://localhost/webhooks", { method: "POST", body, headers }))
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
async function generateTestWebhookHeaders(params) {
|
|
187
|
+
const { secret } = params;
|
|
188
|
+
if (typeof secret !== "string" || secret === "")
|
|
189
|
+
throw new errors_js_1.WebhookSignatureError("invalid_secret", "generateTestWebhookHeaders needs the whsec_… secret");
|
|
190
|
+
const body = bytesOf(params.payload);
|
|
191
|
+
const id = params.id ?? defaultMessageId(body);
|
|
192
|
+
const timestamp = String(Math.floor(params.timestamp ?? Date.now() / 1000));
|
|
193
|
+
let keyBytes;
|
|
194
|
+
try {
|
|
195
|
+
keyBytes = b64decode(secret.startsWith("whsec_") ? secret.slice(6) : secret);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
throw new errors_js_1.WebhookSignatureError("invalid_secret", "Webhook secret is not whsec_<base64>");
|
|
199
|
+
}
|
|
200
|
+
const prefix = new TextEncoder().encode(`${id}.${timestamp}.`);
|
|
201
|
+
const signed = new Uint8Array(prefix.length + body.length);
|
|
202
|
+
signed.set(prefix);
|
|
203
|
+
signed.set(body, prefix.length);
|
|
204
|
+
const crypto = await (0, runtime_js_1.getWebCrypto)();
|
|
205
|
+
const key = await crypto.subtle.importKey("raw", keyBytes, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
206
|
+
const signature = new Uint8Array(await crypto.subtle.sign("HMAC", key, signed));
|
|
207
|
+
return {
|
|
208
|
+
"content-type": "application/json",
|
|
209
|
+
"webhook-id": id,
|
|
210
|
+
"webhook-timestamp": timestamp,
|
|
211
|
+
"webhook-signature": `v1,${b64encode(signature)}`,
|
|
212
|
+
};
|
|
213
|
+
}
|
package/dist/esm/case.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare function toSnake<T = unknown>(value: unknown): T;
|
|
|
15
15
|
export declare function toCamel<T = unknown>(value: unknown): T;
|
|
16
16
|
/** Type-level twin of `snakeToCamel`. */
|
|
17
17
|
export type CamelKey<S extends string> = S extends `${infer H}_${infer R}` ? `${H}${Capitalize<CamelKey<R>>}` : S;
|
|
18
|
-
type OpaqueKey = "headers" | "metadata" | "rejection_gates";
|
|
18
|
+
type OpaqueKey = "by_kind" | "headers" | "layout" | "metadata" | "msf" | "rejection_gates";
|
|
19
19
|
/** Type-level twin of `toCamel`: every object key camelCased except the contents of opaque maps. */
|
|
20
20
|
export type Camel<T> = T extends readonly (infer U)[] ? Camel<U>[] : T extends object ? {
|
|
21
21
|
[K in keyof T as K extends string ? CamelKey<K> : K]: K extends OpaqueKey ? T[K] : Camel<T[K]>;
|
package/dist/esm/case.js
CHANGED
|
@@ -6,7 +6,15 @@
|
|
|
6
6
|
* listed once here; a test derives the same list from the OpenAPI document so they cannot drift.
|
|
7
7
|
*/
|
|
8
8
|
/** Property names (snake_case, as on the wire) whose value is a free-form map that must not be converted. */
|
|
9
|
-
export const OPAQUE_KEYS = [
|
|
9
|
+
export const OPAQUE_KEYS = [
|
|
10
|
+
"by_kind",
|
|
11
|
+
"details",
|
|
12
|
+
"headers",
|
|
13
|
+
"layout",
|
|
14
|
+
"metadata",
|
|
15
|
+
"msf",
|
|
16
|
+
"rejection_gates",
|
|
17
|
+
];
|
|
10
18
|
const OPAQUE_SNAKE = new Set(OPAQUE_KEYS);
|
|
11
19
|
const OPAQUE_CAMEL = new Set(OPAQUE_KEYS.map(snakeToCamel));
|
|
12
20
|
export function snakeToCamel(key) {
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ClientOptions } from "./http.js";
|
|
2
2
|
import { createResources } from "./resources.js";
|
|
3
|
-
import { type HeadersInput, type VerifyOptions, type WebhookRequest } from "./webhooks.js";
|
|
3
|
+
import { type TestWebhookParams, type HeadersInput, type VerifyOptions, type WebhookRequest } from "./webhooks.js";
|
|
4
4
|
import type { WebhookEvent } from "./types.js";
|
|
5
5
|
/** The client's options: the transport's, plus the webhook signing secret. */
|
|
6
6
|
export interface TimbereyeOptions extends ClientOptions {
|
|
@@ -34,6 +34,14 @@ export interface WebhookHelpers {
|
|
|
34
34
|
* Fetch (Next.js, Hono, Workers): `export const POST = te.webhooks.handler(fn)`.
|
|
35
35
|
*/
|
|
36
36
|
handler(onEvent: (event: WebhookEvent) => unknown, options?: VerifyOptions): WebhookRouteHandler;
|
|
37
|
+
/**
|
|
38
|
+
* For tests: the headers Timbereye would send with `payload`, signed with `secret` (default: the client's
|
|
39
|
+
* webhook secret, else `TIMBEREYE_WEBHOOK_SECRET`). `verify` and `handler` accept them. It signs; it never
|
|
40
|
+
* checks a request.
|
|
41
|
+
*/
|
|
42
|
+
generateTestHeaders(params: Omit<TestWebhookParams, "secret"> & {
|
|
43
|
+
secret?: string;
|
|
44
|
+
}): Promise<Record<string, string>>;
|
|
37
45
|
}
|
|
38
46
|
/** What `webhooks.handler` returns: a Fetch handler, or a Node/Express one. */
|
|
39
47
|
export interface WebhookRouteHandler {
|
|
@@ -53,8 +61,9 @@ export interface WebhookResponse {
|
|
|
53
61
|
* const group = await te.groups.create({ kind: "container", externalRef: "MSKU1234567" })
|
|
54
62
|
* ```
|
|
55
63
|
*
|
|
56
|
-
* `new Timbereye(apiKey, options)` and `new Timbereye({ apiKey, webhookSecret, ... })` also work; an
|
|
57
|
-
* key or
|
|
64
|
+
* `new Timbereye(apiKey, options)` and `new Timbereye({ apiKey, webhookSecret, baseUrl, ... })` also work; an
|
|
65
|
+
* explicit key, secret or `baseUrl` wins over the environment (`TIMBEREYE_SECRET_KEY`, `TIMBEREYE_WEBHOOK_SECRET`,
|
|
66
|
+
* `TIMBEREYE_API_URL`).
|
|
58
67
|
*/
|
|
59
68
|
export declare class Timbereye {
|
|
60
69
|
/** Test mode only: a simulated scan and refinement, so the loop can run with no device and no model. */
|
package/dist/esm/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import { TimbereyeError, WebhookSignatureError } from "./errors.js";
|
|
|
2
2
|
import { Transport } from "./http.js";
|
|
3
3
|
import { createResources } from "./resources.js";
|
|
4
4
|
import { readEnv } from "./runtime.js";
|
|
5
|
-
import { readWebhookRequest, verifyWebhook, } from "./webhooks.js";
|
|
5
|
+
import { generateTestWebhookHeaders, readWebhookRequest, verifyWebhook, } from "./webhooks.js";
|
|
6
6
|
/** Verification failures that mean "not from Timbereye": answered 400. Everything else is a setup mistake. */
|
|
7
7
|
const FORGED_CODES = new Set([
|
|
8
8
|
"missing_headers",
|
|
@@ -17,8 +17,9 @@ const FORGED_CODES = new Set([
|
|
|
17
17
|
* const group = await te.groups.create({ kind: "container", externalRef: "MSKU1234567" })
|
|
18
18
|
* ```
|
|
19
19
|
*
|
|
20
|
-
* `new Timbereye(apiKey, options)` and `new Timbereye({ apiKey, webhookSecret, ... })` also work; an
|
|
21
|
-
* key or
|
|
20
|
+
* `new Timbereye(apiKey, options)` and `new Timbereye({ apiKey, webhookSecret, baseUrl, ... })` also work; an
|
|
21
|
+
* explicit key, secret or `baseUrl` wins over the environment (`TIMBEREYE_SECRET_KEY`, `TIMBEREYE_WEBHOOK_SECRET`,
|
|
22
|
+
* `TIMBEREYE_API_URL`).
|
|
22
23
|
*/
|
|
23
24
|
export class Timbereye {
|
|
24
25
|
constructor(apiKeyOrOptions, options = {}) {
|
|
@@ -46,8 +47,17 @@ export class Timbereye {
|
|
|
46
47
|
return verifyRequest(first, webhookSecret, rest[0]);
|
|
47
48
|
}),
|
|
48
49
|
handler: (onEvent, verifyOptions) => webhookHandler(webhookSecret, onEvent, verifyOptions),
|
|
50
|
+
generateTestHeaders: async (params) => {
|
|
51
|
+
const configured = Array.isArray(webhookSecret) ? webhookSecret[0] : webhookSecret;
|
|
52
|
+
const secret = params.secret ?? configured ?? readEnv("TIMBEREYE_WEBHOOK_SECRET");
|
|
53
|
+
if (secret === undefined)
|
|
54
|
+
throw new WebhookSignatureError("webhook_secret_missing", "No webhook secret: pass { secret }, set TIMBEREYE_WEBHOOK_SECRET, or new Timbereye({ webhookSecret }).");
|
|
55
|
+
return generateTestWebhookHeaders({ ...params, secret });
|
|
56
|
+
},
|
|
49
57
|
};
|
|
50
|
-
|
|
58
|
+
// An explicit baseUrl, else TIMBEREYE_API_URL where the runtime has an environment, else production.
|
|
59
|
+
const baseUrl = transportOptions.baseUrl ?? readEnv("TIMBEREYE_API_URL");
|
|
60
|
+
const r = createResources(new Transport(apiKey, baseUrl === undefined ? transportOptions : { ...transportOptions, baseUrl }));
|
|
51
61
|
this.testMode = r.testMode;
|
|
52
62
|
this.groups = r.groups;
|
|
53
63
|
this.items = r.items;
|