@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
Lumber and panels (in development): `groups.createBatch`, `groups.tally.retrieve`, `groups.tally.submit`,
|
|
6
|
+
`groups.tally.correct`, `groups.tally.listRevisions`, `groups.tallySheet`, `groups.packingList`, `groups.listParents`
|
|
7
|
+
and `testMode.simulatePackingList`, with the `GroupTally`, `PackingList`, `LumberHtmlDocument`, `TallyLineInput` and
|
|
8
|
+
related types. `groups.create` accepts `product`, `spec`, `bundle`, `rule`, `expected`, `totals` and `photos`, and
|
|
9
|
+
`Group` gains the lumber fields. Nothing existing was renamed.
|
|
10
|
+
Deleting: `groups.delete(groupId, { cascade })` returns `GroupDeleted` and `places.delete(placeId, { detach })`
|
|
11
|
+
returns `PlaceDeleted`. Only an unused group or place can be deleted (otherwise 409 `group_not_empty`, `group_billed`
|
|
12
|
+
or `place_in_use`); `cascade` and `detach` are test mode only. New event types `group.deleted` and `place.deleted` in
|
|
13
|
+
the `WebhookEvent` union.
|
|
14
|
+
|
|
15
|
+
Tag printing: `tagBatches.create`, `.list`, `.retrieve`, `.listTags`, `.printFile({ format, layout, header })` and
|
|
16
|
+
`labelTemplates.create`, `.list`, `.retrieve`, `.update`, `.testLabel`, with the `TagBatch`, `PrintedTag`,
|
|
17
|
+
`LabelTemplate`, `PrintFile` and `TagQrGeometry` types. A print file arrives inline (`data`: ZPL text or a base64 PDF).
|
|
18
|
+
Batches and templates belong to the organisation, not to a mode: a test key and a live key return the same ones, and
|
|
19
|
+
`TagBatch`, `LabelTemplate` and `PrintFile` have no `livemode`. A `PrintedTag`'s `itemId` / `groupId` and a batch's
|
|
20
|
+
`seenCount` follow the key's mode.
|
|
21
|
+
|
|
22
|
+
Billing: `billing.retrieve()`, `billing.update({ spendCap })`, `billing.acceptTerms`, `billing.startCardSetup`,
|
|
23
|
+
`billing.confirmCardSetup`, `billing.createPortalSession`, `billing.stop()`, `billing.invoices.list()` and
|
|
24
|
+
`console.setBillingPlan` (staff), dashboard sessions only, with the `Billing`, `BillingInvoice` and `AccountBilling`
|
|
25
|
+
types. `Account` gains `liveWrites` and `billing`. A `402` (`payment_overdue`, `spend_cap_reached`) arrives as an
|
|
26
|
+
`InvalidRequestError` and is not retried.
|
|
27
|
+
|
|
28
|
+
`maxRetryWaitMs` client option: a `Retry-After` longer than it is thrown at once (with `retryAfterSeconds`)
|
|
29
|
+
instead of being waited out, for apps where a person is waiting for the answer.
|
|
30
|
+
|
|
31
|
+
Developer console: `console.bootstrap()` and `console.updateOnboarding({ organisationName, useCase, complete })`,
|
|
32
|
+
dashboard sessions only (`x-session-only`), with the `ConsoleBootstrap`, `ConsoleOnboarding` and `OnboardingUseCase`
|
|
33
|
+
types. They have no CLI command.
|
|
34
|
+
|
|
35
|
+
Mobile contract (`docs/timbereye-sync-protocol.md`): `images.createSession`, `scans.list({ clientId })` for capture
|
|
36
|
+
tokens, `scans.uploadImage` with `sha256`, `width`, `height`, `location`, `region`, `sourceImageId`, `itemClientId` and
|
|
37
|
+
`detections`, `scans.submit(id, { endedAt })`, `scans.addItems` entries typed `ScanItemResult` (with `created`),
|
|
38
|
+
`models.retrieveDetector({ platform })`, and the new request and response fields (`appVersion`, `tagCorners`,
|
|
39
|
+
`diameterLines`, `measuredRect`, `uploadSession`, `sightings`).
|
|
40
|
+
|
|
41
|
+
First version, written against `Timbereye/OpenApi/timbereye.v1.yaml` (one method per operation) and checked end to end against
|
|
42
|
+
the real server by `SdkEndToEndTest`.
|
|
43
|
+
|
|
44
|
+
- `Timbereye` client with resources for groups (and group items), items, scans, images, places,
|
|
45
|
+
species, volume rules, events, webhook endpoints, capture tokens, usage and models.
|
|
46
|
+
- Types generated from the OpenAPI document with `openapi-typescript`; a test fails when
|
|
47
|
+
`src/generated/schema.ts` is out of date.
|
|
48
|
+
- camelCase in the SDK, snake_case on the wire, `metadata` never converted.
|
|
49
|
+
- Automatic `Idempotency-Key`, retries with backoff and `Retry-After`, typed errors, auto-paging
|
|
50
|
+
iterators, `expand`, `If-Match`, per-request `idempotencyKey`, `timeoutMs`, `signal`.
|
|
51
|
+
- `te.webhooks.verify` (Standard Webhooks, Web Crypto).
|
|
52
|
+
- Display-only unit formatters.
|
|
53
|
+
- `te.account.retrieve()`; the formatters accept the account object.
|
|
54
|
+
- `webhookEndpoints.rollSecret`, `WebhookTest` result for `webhookEndpoints.test`, endpoint `description`.
|
|
55
|
+
- `te.apiKeys` (list, create, roll, revoke) and `te.account.createTestAccount()`, documented as dashboard-session only.
|
|
56
|
+
- List results keep paging when returned from an `async` function: the awaited page is itself iterable.
|
|
57
|
+
- `onResponse` on every call exposes the status, request id, `Idempotent-Replayed` and rate-limit headers.
|
|
58
|
+
- `groups.list` takes a `metadata` map (`metadata[key]=value`), `originPlaceId`, `createdAfter` and `createdBefore`.
|
|
59
|
+
- `te.testMode.simulateScan` and `te.testMode.runRefinements` (test mode only).
|
|
60
|
+
- Input unions now come straight from the generated types; the hand-written input types and the
|
|
61
|
+
Geometry discriminator patch were removed.
|
|
62
|
+
- ESM and CommonJS builds from `tsc` alone.
|
|
63
|
+
- Consistency pass against the server: 422 for `unit_ambiguous`, `group_cycle`, `group_depth_exceeded` and
|
|
64
|
+
`weight_inconsistent`; `GroupSummary.assignedCount`; `Origin.empty` and `Origin.unattributed`; `areaHa` on
|
|
65
|
+
place create and update; quickstart 1 passes a group (a `photo_count` scan needs one) and says that its
|
|
66
|
+
count is client-supplied and its status ends at `estimated`.
|
|
67
|
+
- `te.team.members`, `te.team.invitations` and `te.auditLog` (dashboard sessions only); `details` on audit
|
|
68
|
+
entries is never case-converted.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,331 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @timbereye/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for the Timbereye API: counts, measurements and tallies of forest products (sawlogs today) as
|
|
4
|
+
versioned data, grouped the way you group wood (containers, truck loads, stacks), bound to an origin place.
|
|
5
|
+
Apache-2.0.
|
|
6
|
+
|
|
7
|
+
Status: version 0.1.0, written from the OpenAPI document (https://www.timbereye.com/docs/openapi.yaml, one method
|
|
8
|
+
per operation) and exercised end to end against the real server. The contract may still change. Only
|
|
9
|
+
`models.retrieveDetector` answers `501 not_implemented` in the current build, and an environment that has no
|
|
10
|
+
image storage configured answers uploads with `503 storage_unavailable`.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npm install @timbereye/sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Supported runtimes: Node 18 or later, current browsers, and edge runtimes (Cloudflare Workers, Deno,
|
|
19
|
+
Vercel Edge, Bun) that provide `fetch` and Web Crypto. ESM and CommonJS builds with bundled types (`import Timbereye from "@timbereye/sdk"`, or
|
|
20
|
+
`const { Timbereye } = require("@timbereye/sdk")`; under `require` the default export is `.default`). No runtime dependencies, and no Node-only imports in the main entry. On Node 18,
|
|
21
|
+
which has no global `crypto`, the SDK loads `node:crypto`'s Web Crypto lazily when it first needs it.
|
|
22
|
+
|
|
23
|
+
Never put a secret key (`te_live_sk_...`, `te_test_sk_...`) or a restricted key in a browser or app. The
|
|
24
|
+
client refuses to start with one there. Apps use a publishable key or a capture token that your server
|
|
25
|
+
mints ([Keys](https://www.timbereye.com/docs/keys/)).
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
The three steps of an integration, **Create → Scan → Sync**, in test mode, as in
|
|
30
|
+
[the docs' quickstart](https://www.timbereye.com/docs/quickstart/). Set your test secret key and the endpoint's signing
|
|
31
|
+
secret where your server reads them:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
export TIMBEREYE_SECRET_KEY=te_test_sk_...
|
|
35
|
+
export TIMBEREYE_WEBHOOK_SECRET=whsec_... # from creating the webhook endpoint
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 1. Create
|
|
39
|
+
|
|
40
|
+
When your backend creates its record for a container, it creates the Timbereye group and keeps the group's id.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import Timbereye from "@timbereye/sdk"
|
|
44
|
+
|
|
45
|
+
const timbereye = new Timbereye() // reads TIMBEREYE_SECRET_KEY
|
|
46
|
+
const group = await timbereye.groups.create({
|
|
47
|
+
kind: "container",
|
|
48
|
+
externalRef: "ctr_4821", // your record's id
|
|
49
|
+
name: "MSKU1234567",
|
|
50
|
+
defaults: { species: "PINE_TAEDA", length: { valueM: 5.8 } },
|
|
51
|
+
})
|
|
52
|
+
await db.containers.update("ctr_4821", { timbereyeGroupId: group.id }) // "grp_7QxV3m"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`db.containers.update` stands for your own database.
|
|
56
|
+
|
|
57
|
+
### 2. Scan
|
|
58
|
+
|
|
59
|
+
In production a worker scans the logs with a phone and the server refines them. In test mode the simulator does
|
|
60
|
+
both: 35 synthetic logs, refined at once.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
await timbereye.testMode.simulateScan({ groupId: group.id, logs: 35, refine: true })
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Sync
|
|
67
|
+
|
|
68
|
+
Once its logs are measured the group sends `group.measured` with its tally to your webhook endpoint. The handler updates your record:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import express from "express"
|
|
72
|
+
|
|
73
|
+
const app = express()
|
|
74
|
+
const onEvent = timbereye.webhooks.handler(async (event) => {
|
|
75
|
+
if (event.type === "group.measured") {
|
|
76
|
+
const tally = event.data.object
|
|
77
|
+
await db.containers.update(tally.externalRef, {
|
|
78
|
+
pieces: tally.pieces,
|
|
79
|
+
volumeM3: tally.volume.m3,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
app.post("/webhooks/timbereye", express.raw({ type: "application/json" }), onEvent)
|
|
84
|
+
app.listen(3000)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`handler` verifies the signature with `TIMBEREYE_WEBHOOK_SECRET` and answers `200`; a request Timbereye did not
|
|
88
|
+
sign gets `400`. Register the endpoint once with
|
|
89
|
+
`timbereye.webhookEndpoints.create({ url, enabledEvents: ["group.measured"] })`; its `secret` is returned only
|
|
90
|
+
then. With no public URL yet, read the same event from the feed:
|
|
91
|
+
`(await timbereye.events.list({ type: "group.measured", limit: 1 })).data[0]`.
|
|
92
|
+
|
|
93
|
+
Every log stays readable afterwards:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
for await (const item of timbereye.groups.items.list(group.id)) {
|
|
97
|
+
console.log(item.tag?.payload, item.measurement?.effectiveShortM)
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Conventions
|
|
102
|
+
|
|
103
|
+
**Names.** Methods follow the API's resources: `te.groups.create / open / lookup / retrieve / update / list /
|
|
104
|
+
setWeight / volume / origin / listImages`, `te.groups.items.add / remove / bulkUpdate / list`,
|
|
105
|
+
`te.items.list / retrieve / update / remove / listMeasurements / createMeasurement / volume /
|
|
106
|
+
listGroups / listImages`, `te.scans.create / list / retrieve / addItems / addObservations / submit /
|
|
107
|
+
uploadImage`, `te.images.createUploadSession / createSession / retrieve / complete`, `te.places.create / list /
|
|
108
|
+
retrieve / update / validate`, `te.species.list / create / update`, `te.volumeRules.list`,
|
|
109
|
+
`te.events.list / retrieve`, `te.webhookEndpoints.create / list / retrieve / update / delete / test /
|
|
110
|
+
rollSecret`, `te.captureTokens.create`, `te.usage.retrieve / listRecords`, and
|
|
111
|
+
`te.models.retrieveDetector({ platform })`, and `te.account.retrieve` (`GET /account`: name, mode, `displayUnits`,
|
|
112
|
+
`defaultVolumeRule`). There is one method per operation in the OpenAPI document.
|
|
113
|
+
|
|
114
|
+
**camelCase in, camelCase out.** The REST API is snake_case; the SDK takes and returns camelCase
|
|
115
|
+
(`externalRef`, `originPlaceId`, `densityKgM3`). The mapping is mechanical and applies to keys only.
|
|
116
|
+
`metadata` is yours: its keys and values are sent and returned exactly as written. Query parameters
|
|
117
|
+
follow the same rule, and `expand: ["origin_place"]` becomes `expand[]=origin_place`. Error `param`
|
|
118
|
+
values and event type strings are wire names and are not converted.
|
|
119
|
+
|
|
120
|
+
**Units.** Responses carry SI values named in the field (`lengthM`, `netKg`, `m3`). Inputs also accept
|
|
121
|
+
`{ value, unit }` for lengths (`m`, `cm`, `ft`, `in`) and weights (`kg`, `lb`, `t`, `short_ton`); the
|
|
122
|
+
value as entered is echoed back in `entered`. A bare `ton` is rejected. Lengths take one shape everywhere:
|
|
123
|
+
`{ value, unit }` or `{ valueM }`.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
await te.groups.setWeight(group.id, { gross: 52480, tare: 14120, unit: "lb", ticketRef: "WT-88213" })
|
|
127
|
+
await te.groups.items.bulkUpdate(group.id, {
|
|
128
|
+
selector: { scanId: "scn_2Pq8" },
|
|
129
|
+
patch: { length: { valueM: 5.8 } },
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Display units
|
|
134
|
+
|
|
135
|
+
An account's `displayUnits` is `metric` or `imperial`. The formatters show SI values that way and take
|
|
136
|
+
either the string or the account object; they never affect requests.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { formatLength, formatDiameter, formatWeight, formatVolume } from "@timbereye/sdk"
|
|
140
|
+
|
|
141
|
+
const account = await te.account.retrieve()
|
|
142
|
+
formatLength(11.8, account) // follows account.displayUnits
|
|
143
|
+
|
|
144
|
+
formatLength(11.8, "imperial") // "38.71 ft"
|
|
145
|
+
formatDiameter(0.2315, "metric") // "23.2 cm"
|
|
146
|
+
formatWeight(21400, "metric") // "21.4 t"
|
|
147
|
+
formatVolume(21.384, "imperial") // "755.169 ft³"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Board-foot rule outputs are available as `volume.native`; they are not converted.
|
|
151
|
+
|
|
152
|
+
## Errors
|
|
153
|
+
|
|
154
|
+
Failures throw subclasses of `TimbereyeError`, chosen by the API's error `type`:
|
|
155
|
+
`InvalidRequestError` (400, 404, 409, 412, 413, 422), `AuthenticationError` (401), `PermissionError`
|
|
156
|
+
(403), `RateLimitError` (429, with `retryAfterSeconds`) and `ApiError` (5xx). Each carries `code`,
|
|
157
|
+
`param`, `requestId`, `status`, `type` and `docUrl`. Network failures throw `ConnectionError`, an
|
|
158
|
+
elapsed timeout `TimeoutError`, and your own abort `AbortError`.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { InvalidRequestError } from "@timbereye/sdk"
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
await te.groups.update(id, { name: "North stack" }, { ifMatch: group.version })
|
|
165
|
+
} catch (e) {
|
|
166
|
+
if (e instanceof InvalidRequestError && e.code === "version_mismatch") {
|
|
167
|
+
// someone else changed the group: re-read and retry
|
|
168
|
+
} else {
|
|
169
|
+
throw e // quote e.requestId to support
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`code` is a string. Codes in use include `resource_missing`, `parameter_invalid`, `parameter_unknown`,
|
|
175
|
+
`invalid_cursor`, `idempotency_key_reused`, `idempotency_key_missing`, `idempotency_request_in_progress`,
|
|
176
|
+
`version_mismatch`, `payload_too_large`, `group_not_empty`, `scope_missing`, `secret_key_required`,
|
|
177
|
+
`capture_token_not_allowed`, `key_mode_mismatch`, `rate_limited`, the 422 codes `unit_ambiguous`,
|
|
178
|
+
`group_cycle`, `group_depth_exceeded`, `weight_inconsistent` and `area_ha_not_allowed`, `not_implemented` and
|
|
179
|
+
`service_unavailable`; the YAML lists them all. New codes may appear within v1; treat unknown ones as the
|
|
180
|
+
generic case.
|
|
181
|
+
|
|
182
|
+
## Retries, timeouts and cancellation
|
|
183
|
+
|
|
184
|
+
The client retries network errors and timeouts, `409 idempotency_request_in_progress`, `429` (waiting
|
|
185
|
+
for `Retry-After` when sent, up to 60 s) and `5xx` other than `501 not_implemented`, with exponential backoff (500 ms doubling to 8 s,
|
|
186
|
+
jittered). It never retries any other 4xx. Defaults are `maxRetries: 2` and `timeoutMs: 60000` per
|
|
187
|
+
attempt. Where a person is waiting for the answer, set `maxRetryWaitMs`: a `429` or `503` that asks for a longer
|
|
188
|
+
wait (an hourly or daily limit) is then thrown at once, with `retryAfterSeconds`, instead of being waited out.
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
const te = new Timbereye(key, { maxRetries: 4, timeoutMs: 10_000 })
|
|
192
|
+
|
|
193
|
+
const ac = new AbortController()
|
|
194
|
+
await te.groups.retrieve(id, undefined, { timeoutMs: 2000, signal: ac.signal })
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Idempotency
|
|
198
|
+
|
|
199
|
+
Every state-changing `POST` gets an `Idempotency-Key` (a UUID) automatically. One key is generated per
|
|
200
|
+
call and reused by every retry of it, so a retry cannot create a duplicate. Supply your own to make a
|
|
201
|
+
whole workflow step safe to repeat, and on `PATCH`, `PUT` and `DELETE`, where it is optional:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
await te.groups.create({ externalRef: "MSKU1234567" }, { idempotencyKey: "booking-BK-2231-group" })
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
`POST /places/validate` only computes, so no key is sent. Keys are remembered for 24 hours; the same
|
|
208
|
+
key with a different body fails with `409 idempotency_key_reused`.
|
|
209
|
+
|
|
210
|
+
## Pagination
|
|
211
|
+
|
|
212
|
+
List methods return a promise of one page (`data`, `hasMore`, `nextCursor`) that is also an async
|
|
213
|
+
iterator over every item:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
const page = await te.groups.list({ status: "open", limit: 50 })
|
|
217
|
+
|
|
218
|
+
for await (const group of te.groups.list({ status: "open" })) {
|
|
219
|
+
console.log(group.id)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const first200 = await te.groups.list().autoPagingToArray({ limit: 200 })
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The awaited page is itself iterable, so a list returned from an `async` function keeps paging (the extra members are
|
|
226
|
+
not enumerable, so the page still serialises as a plain `{ object, data, hasMore, nextCursor }`):
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
const firstPage = await findGroups() // an async function that returns te.groups.list(...)
|
|
230
|
+
for await (const group of firstPage) console.log(group.id) // this page, then every later one
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Find groups by your own metadata with a `metadata` map: `te.groups.list({ metadata: { booking: "B123" } })` sends
|
|
234
|
+
`metadata[booking]=B123` (up to five keys, all must match). `originPlaceId`, `createdAfter` and `createdBefore` filter
|
|
235
|
+
too.
|
|
236
|
+
|
|
237
|
+
## Response headers
|
|
238
|
+
|
|
239
|
+
Every call takes `onResponse`, called with the status, `requestId`, `idempotentReplayed`, `rateLimit` (`limit`,
|
|
240
|
+
`remaining`), all headers (lower-cased) and the idempotency key the call sent, for each response it receives (also the
|
|
241
|
+
attempts that are retried):
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
await te.groups.update(
|
|
245
|
+
"grp_1",
|
|
246
|
+
{ name: "MSKU1234567" },
|
|
247
|
+
{ onResponse: (r) => console.log(r.requestId, r.rateLimit.remaining) },
|
|
248
|
+
)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Test mode simulator
|
|
252
|
+
|
|
253
|
+
With a `te_test_` key, `te.testMode.simulateScan({ groupId, logs: 12, species: "PINE_TAEDA", length: { valueM: 5.8 }, seed: 7 })`
|
|
254
|
+
creates a scan of synthetic, tagged logs and completes it, and `te.testMode.runRefinements()` resolves the pending
|
|
255
|
+
refinements now. The numbers are simulated (`provenance.simulated` is `true`), never billed, and a live key is refused
|
|
256
|
+
with `403 test_mode_only`.
|
|
257
|
+
|
|
258
|
+
## Lumber and panels (in development)
|
|
259
|
+
|
|
260
|
+
No phone app tallies lumber yet; the API and the test-mode simulator do. `te.groups.createBatch({ parent, groups })`
|
|
261
|
+
creates a packing list and its bundles in one call, `te.groups.tally.submit(id, { clientId, lines })` sends a
|
|
262
|
+
bundle's tally (final when submitted), `te.groups.tally.correct` and `te.groups.tally.listRevisions` correct and audit it, and
|
|
263
|
+
`te.groups.packingList(id)` and `te.groups.tallySheet(id)` return the documents as JSON (or, with `format: "html"`, a
|
|
264
|
+
printable page). `te.groups.listParents(id)` is where a bundle has been. `te.testMode.simulatePackingList({ scenario })`
|
|
265
|
+
builds a whole tallied list. See `developer-docs/lumber-and-panels.md`.
|
|
266
|
+
|
|
267
|
+
## Webhooks
|
|
268
|
+
|
|
269
|
+
`te.webhooks.handler(onEvent)` is the route handler: it verifies each delivery with `TIMBEREYE_WEBHOOK_SECRET` (or
|
|
270
|
+
the `webhookSecret` option), calls `onEvent(event)` and answers `200`. A request Timbereye did not sign gets `400`
|
|
271
|
+
and never reaches `onEvent`; a setup mistake or an error from `onEvent` goes to `next` in Express (or is thrown from
|
|
272
|
+
a Fetch handler), so the delivery is retried. Express needs the raw body:
|
|
273
|
+
`app.post(path, express.raw({ type: "application/json" }), te.webhooks.handler(onEvent))`; a Fetch route handler is
|
|
274
|
+
`export const POST = te.webhooks.handler(onEvent)`.
|
|
275
|
+
|
|
276
|
+
`te.webhooks.verify(req)`, or `te.webhooks.verify(rawBody, headers, secret, { toleranceSeconds? })`, is the same
|
|
277
|
+
check for code that answers the request itself. It implements Standard Webhooks:
|
|
278
|
+
HMAC-SHA256 over `${webhook-id}.${webhook-timestamp}.${body}` with the `whsec_<base64>` secret,
|
|
279
|
+
compared in constant time, timestamps within 5 minutes by default. Pass the raw body, not parsed JSON.
|
|
280
|
+
It accepts several space-separated signatures (secret rotation), and `secret` may be an array to
|
|
281
|
+
hold old and new secrets together. It returns the event, camelCased, as a union you narrow on `type`,
|
|
282
|
+
and throws `WebhookSignatureError` (with a `code` such as `signature_mismatch` or
|
|
283
|
+
`timestamp_out_of_tolerance`) on failure. It is async, because Web Crypto is: use `await`.
|
|
284
|
+
|
|
285
|
+
`te.webhookEndpoints.rollSecret(id)` rolls a signing secret: the new `secret` is returned once, the old one
|
|
286
|
+
stays valid until `previousSecretExpiresAt` (24 hours), and until then each delivery carries two
|
|
287
|
+
space-separated signatures, either of which verifies. `te.webhookEndpoints.test(id)` sends a test
|
|
288
|
+
delivery to that endpoint only and returns a `WebhookTest` reference (it is not in `events.list`).
|
|
289
|
+
`te.webhookEndpoints.listDeliveries(id, { status, type })` is the endpoint's delivery log (30 days),
|
|
290
|
+
`retrieveDelivery(deliveryId)` gives every attempt as sent and as received, and `resendDelivery(deliveryId)` sends one
|
|
291
|
+
again now. `verifyWebhook` is also exported on its own for code that has no client.
|
|
292
|
+
|
|
293
|
+
## Key management (dashboard sessions only)
|
|
294
|
+
|
|
295
|
+
`te.apiKeys.list/create/roll/revoke` and `te.account.createTestAccount()` are for the Timbereye dashboard: they
|
|
296
|
+
need a signed-in user's session token (`new Timbereye(sessionToken, { mode: "test" })`) and every API key or
|
|
297
|
+
capture token is refused with 403 `session_required`, so a key can never mint or list keys. `create` and `roll`
|
|
298
|
+
return the full `secret` once; show it to the person, then drop it.
|
|
299
|
+
|
|
300
|
+
`te.team.members` (list, update, remove, transferOwnership), `te.team.invitations` (list, create, revoke,
|
|
301
|
+
resend, accept) and `te.auditLog.list` are dashboard-session only too. What a session may do depends on the
|
|
302
|
+
user's role in the organisation (owner, developer, editor or viewer; see the team roles guide): a refusal is a
|
|
303
|
+
`PermissionError` with code `role_required`, and a change that would leave no owner an `InvalidRequestError`
|
|
304
|
+
with code `last_owner`. `invitations.create` and `resend` return the accept `token` once.
|
|
305
|
+
|
|
306
|
+
## Types
|
|
307
|
+
|
|
308
|
+
Types come from the OpenAPI document with `openapi-typescript` (`npm run generate`, output committed
|
|
309
|
+
in `src/generated/schema.ts`); a test fails if the file no longer matches the document. The public types
|
|
310
|
+
(`Group`, `Item`, `Scan`, `Event`, and `Schemas["..."]` for the rest) are the same types with camelCase
|
|
311
|
+
keys, derived by a type-level mapping. Two lists are single pages by contract (`volumeRules.list`, `scans.addItems`); they return a `Page` with `hasMore: false`. `scans.addItems` returns one entry per input item, in input order, each with the input's `clientId` and `created`. The API ignores unknown fields and enum values in v1, so do the same.
|
|
312
|
+
|
|
313
|
+
## Development
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
npm test # mocha, fake fetch, no network
|
|
317
|
+
npm run typecheck
|
|
318
|
+
npm run build
|
|
319
|
+
npm run generate # regenerate src/generated/schema.ts
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Licensed under the Apache License 2.0. Using the hosted Timbereye service through this package is governed by the [Terms of Service](https://www.timbereye.com/terms); what the service collects is in the [Privacy Policy](https://www.timbereye.com/privacy).
|
|
323
|
+
|
|
324
|
+
### Syncing a capture queue
|
|
325
|
+
|
|
326
|
+
The offline-queue protocol that the mobile SDKs follow (order of steps, idempotency keys, retries) is
|
|
327
|
+
`docs/timbereye-sync-protocol.md`. The calls it relies on are all here: `scans.list({ clientId })` finds a scan
|
|
328
|
+
again after a lost response (a capture token may call it, within its groups), `scans.create`, `scans.addItems`
|
|
329
|
+
and `scans.addObservations` are idempotent by `clientId` and tag, `images.createSession` opens a new upload
|
|
330
|
+
session, `scans.uploadImage` takes `sha256`, `width`, `height`, `location`, `region`, `sourceImageId`,
|
|
331
|
+
`itemClientId` and `detections`, and `scans.submit(id, { endedAt })` is idempotent.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Case mapping between the API (snake_case JSON) and the SDK (camelCase).
|
|
3
|
+
*
|
|
4
|
+
* The mapping is purely mechanical: it is applied to object keys only, never to values, and the
|
|
5
|
+
* contents of free-form maps are left exactly as the caller or server wrote them. Opaque keys are
|
|
6
|
+
* listed once here; a test derives the same list from the OpenAPI document so they cannot drift.
|
|
7
|
+
*/
|
|
8
|
+
/** Property names (snake_case, as on the wire) whose value is a free-form map that must not be converted. */
|
|
9
|
+
export declare const OPAQUE_KEYS: readonly string[];
|
|
10
|
+
export declare function snakeToCamel(key: string): string;
|
|
11
|
+
export declare function camelToSnake(key: string): string;
|
|
12
|
+
/** Convert a request value from the SDK's camelCase to the API's snake_case. */
|
|
13
|
+
export declare function toSnake<T = unknown>(value: unknown): T;
|
|
14
|
+
/** Convert a response value from the API's snake_case to the SDK's camelCase. */
|
|
15
|
+
export declare function toCamel<T = unknown>(value: unknown): T;
|
|
16
|
+
/** Type-level twin of `snakeToCamel`. */
|
|
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";
|
|
19
|
+
/** Type-level twin of `toCamel`: every object key camelCased except the contents of opaque maps. */
|
|
20
|
+
export type Camel<T> = T extends readonly (infer U)[] ? Camel<U>[] : T extends object ? {
|
|
21
|
+
[K in keyof T as K extends string ? CamelKey<K> : K]: K extends OpaqueKey ? T[K] : Camel<T[K]>;
|
|
22
|
+
} : T;
|
|
23
|
+
export {};
|