@protoboardai/cloud 0.0.0-stage → 0.2.1
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/LICENSE +202 -0
- package/NOTICE +13 -0
- package/README.md +39 -2
- package/package.json +43 -4
- package/src/api.ts +351 -0
- package/src/client.ts +479 -0
- package/src/envelope.ts +607 -0
- package/src/kits.ts +101 -0
- package/src/taxonomy.ts +135 -0
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/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Protoboard Stack: @protoboardai/cloud
|
|
2
|
+
Copyright 2026 Delta Robotics, Inc.
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Delta Robotics, Inc.
|
|
5
|
+
(https://deltaroboticsinc.com).
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
8
|
+
See the LICENSE file in this package for full terms.
|
|
9
|
+
|
|
10
|
+
"Protoboard", the Protoboard logo and the "0" mark are trademarks of
|
|
11
|
+
Delta Robotics, Inc. The License grants no rights to them (section 6);
|
|
12
|
+
see TRADEMARKS.md in the Protoboard Stack repository
|
|
13
|
+
(https://github.com/Delta-Robotics-Inc/protoboard-stack).
|
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @protoboardai/cloud
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The typed client of the Protoboard parts service (API v1), and of any other
|
|
4
|
+
`uhd-library/v1` library. Apache-2.0 (`LICENSE`, `NOTICE`).
|
|
5
|
+
|
|
6
|
+
Everything it downloads is verified before it is returned: an envelope
|
|
7
|
+
against its digest and its definition digest, a file against its sha256.
|
|
8
|
+
Node 22.13 or later; no dependencies (global `fetch`, `node:crypto`,
|
|
9
|
+
`node:fs`). The package ships its TypeScript sources; Protoboard runs them
|
|
10
|
+
through tsx.
|
|
11
|
+
|
|
12
|
+
| Module | What |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| `src/client.ts` | `PartsClient` (`@protoboardai/cloud/client`), with the envelope helpers re-exported. |
|
|
15
|
+
| `src/envelope.ts` | The `protoboard.part-revision/v1` envelope (`@protoboardai/cloud/envelope`): types, canonical JSON, digests, validation. Pure. |
|
|
16
|
+
| `src/api.ts` | Request and response types of API v1. |
|
|
17
|
+
| `src/taxonomy.ts` | The category taxonomy as the service serves it: ancestors, tree with counts, shape checks. Pure. |
|
|
18
|
+
| `src/kits.ts` | The service's kit manifests (`x-kits`): types and shape checks. Pure. |
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { PartsClient, vendoredDefinition } from "@protoboardai/cloud/client";
|
|
22
|
+
|
|
23
|
+
const cloud = new PartsClient({ baseUrl: process.env.PROTOBOARD_CLOUD_URL ?? "http://localhost:8787" });
|
|
24
|
+
const { parts } = await cloud.search({ q: "2207 motor", domain: "mechanical" });
|
|
25
|
+
const { revisions } = await cloud.getClosure(parts[0].partId, parts[0].recommendedRevision!); // verified, dependencies first
|
|
26
|
+
for (const env of revisions) writeFileSync(`parts/catalog/${env.partId}.json`, vendoredDefinition(env));
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
With `discover: true` the client finds a library's API root from its
|
|
30
|
+
`/.well-known/uhd-library` document.
|
|
31
|
+
|
|
32
|
+
## The service
|
|
33
|
+
|
|
34
|
+
This package is the client only. The parts service it talks to is hosted
|
|
35
|
+
by Protoboard; any other server that speaks `uhd-library/v1` works with it
|
|
36
|
+
too (`discover: true`).
|
|
37
|
+
|
|
38
|
+
The package is `"private": true` in this repository, so a plain `npm
|
|
39
|
+
publish` refuses it; `scripts/registry/publish-stack.mjs` publishes a staged
|
|
40
|
+
copy with the rest of the stack.
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protoboardai/cloud",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Client for the Protoboard parts library: search, part revisions and verified downloads.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Delta Robotics, Inc.",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Delta-Robotics-Inc/protoboard-stack.git",
|
|
10
|
+
"directory": "packages/cloud"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22.13"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./src/client.ts",
|
|
18
|
+
"./client": "./src/client.ts",
|
|
19
|
+
"./envelope": "./src/envelope.ts"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src/client.ts",
|
|
23
|
+
"src/api.ts",
|
|
24
|
+
"src/envelope.ts",
|
|
25
|
+
"src/taxonomy.ts",
|
|
26
|
+
"src/kits.ts",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"NOTICE"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"protoboard",
|
|
36
|
+
"hardware",
|
|
37
|
+
"parts",
|
|
38
|
+
"library",
|
|
39
|
+
"client"
|
|
40
|
+
],
|
|
41
|
+
"homepage": "https://protoboard.ai",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/Delta-Robotics-Inc/protoboard-stack/issues"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response and request shapes of the parts API v1, shared by the server and
|
|
3
|
+
* the client: types, and the few constant lists both sides check against.
|
|
4
|
+
*/
|
|
5
|
+
import type { PartRef, PartRevisionEnvelope } from "./envelope.js";
|
|
6
|
+
import type { TaxonomyTreeNode } from "./taxonomy.js";
|
|
7
|
+
|
|
8
|
+
export type { TaxonomyTreeNode, ServiceTaxonomyDocument } from "./taxonomy.js";
|
|
9
|
+
|
|
10
|
+
export interface Deprecation {
|
|
11
|
+
reason: string;
|
|
12
|
+
at: string;
|
|
13
|
+
replacedBy?: PartRef;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RevisionRow {
|
|
17
|
+
partId: string;
|
|
18
|
+
revision: number;
|
|
19
|
+
digest: string;
|
|
20
|
+
definitionDigest: string;
|
|
21
|
+
uhdSchema: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
publisher: string;
|
|
24
|
+
deprecated?: Deprecation;
|
|
25
|
+
/**
|
|
26
|
+
* Service extra: whether this revision and every dependency it pins can
|
|
27
|
+
* be given out (every file backing a definition artifact is
|
|
28
|
+
* redistributable, UHD library protocol § 4.5).
|
|
29
|
+
*/
|
|
30
|
+
redistributable?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Which files a request may see. `all` (the default) is the team's view:
|
|
35
|
+
* every file whatever its terms. `redistributable` serves only parts whose
|
|
36
|
+
* revision is redistributable, and only files whose terms say
|
|
37
|
+
* `redistributable`: the view under `/distributable/v1`, or `?distribution=redistributable` on `/v1`.
|
|
38
|
+
*/
|
|
39
|
+
export type DistributionScope = "all" | "redistributable";
|
|
40
|
+
|
|
41
|
+
/** A file by content address (`GET /v1/blobs/:sha256`). */
|
|
42
|
+
export interface BlobRef {
|
|
43
|
+
sha256: string;
|
|
44
|
+
size: number;
|
|
45
|
+
mediaType: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface PartSummary {
|
|
49
|
+
partId: string;
|
|
50
|
+
name: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
manufacturer?: string;
|
|
53
|
+
partNumber?: string;
|
|
54
|
+
/** Taxonomy paths the definition lists (`ModuleDef.categories`), in its order. */
|
|
55
|
+
categories: string[];
|
|
56
|
+
/** Free-form tags and the category paths, merged (as the library manifest's `taxonomy`). */
|
|
57
|
+
tags: string[];
|
|
58
|
+
protocols: string[];
|
|
59
|
+
domains: string[];
|
|
60
|
+
/** Highest revision. */
|
|
61
|
+
latestRevision: number;
|
|
62
|
+
/** Highest revision that is not deprecated (absent when all are). */
|
|
63
|
+
recommendedRevision?: number;
|
|
64
|
+
deprecated?: Deprecation;
|
|
65
|
+
/** The recommended revision's thumbnail file, when it carries one. */
|
|
66
|
+
thumbnail?: BlobRef;
|
|
67
|
+
/**
|
|
68
|
+
* Service extra (capability `x-sort`): the part's relevance in this library,
|
|
69
|
+
* 0 and up, higher first. A library-side value about the part (a seed the
|
|
70
|
+
* library's owners set, plus recent use; docs/relevance.md), never part of
|
|
71
|
+
* a revision or its digest. Absent from libraries that do not rank.
|
|
72
|
+
*/
|
|
73
|
+
relevance?: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The orders `GET /v1/parts` takes in `sort` (capability `x-sort`; docs/relevance.md). */
|
|
77
|
+
export const SEARCH_SORTS = ["relevance", "name", "manufacturer", "updated"] as const;
|
|
78
|
+
export type SearchSort = (typeof SEARCH_SORTS)[number];
|
|
79
|
+
|
|
80
|
+
/** One price break: the unit price from `quantity` pieces up, in the offer's currency. */
|
|
81
|
+
export interface OfferPriceBreak {
|
|
82
|
+
quantity: number;
|
|
83
|
+
unitPrice: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A supplier offer: commercial data about a part, kept apart from its
|
|
88
|
+
* technical facts. An offer is for one ordering code (`mpn`): a series part
|
|
89
|
+
* (one catalog part per manufacturer series, e.g. a resistor family) is
|
|
90
|
+
* placed at many values, each its own MPN, and each is priced only by offers
|
|
91
|
+
* for that MPN.
|
|
92
|
+
*
|
|
93
|
+
* Prices are per piece of the part. A pack sold as one item is stated per
|
|
94
|
+
* piece, with the pack in `packaging` and `minQuantity`.
|
|
95
|
+
*/
|
|
96
|
+
export interface Offer {
|
|
97
|
+
id?: number;
|
|
98
|
+
partId: string;
|
|
99
|
+
/** The ordering code this offer is for, as the manufacturer states it (packaging suffix included). Offers stored before MPNs were required carry the part's own `part_number`. */
|
|
100
|
+
mpn: string;
|
|
101
|
+
supplier: string;
|
|
102
|
+
/** The supplier's own code for the item. */
|
|
103
|
+
sku?: string;
|
|
104
|
+
url?: string;
|
|
105
|
+
/** Price per piece at the first break (`minQuantity`, else 1): what a client that reads one price quotes. */
|
|
106
|
+
unitPrice?: number;
|
|
107
|
+
/** ISO 4217. Prices are never converted. */
|
|
108
|
+
currency?: string;
|
|
109
|
+
/** Every price break shown, ascending by quantity; the first one's price is `unitPrice`. */
|
|
110
|
+
priceBreaks?: OfferPriceBreak[];
|
|
111
|
+
/** Minimum order quantity, in pieces. */
|
|
112
|
+
minQuantity?: number;
|
|
113
|
+
/** Pieces in stock at the supplier when observed; 0 when it showed none. */
|
|
114
|
+
stock?: number;
|
|
115
|
+
/** Lead time the supplier states, in weeks. */
|
|
116
|
+
leadTimeWeeks?: number;
|
|
117
|
+
/** Packaging or sale unit as listed: "Tape & Reel", "pack of 10". */
|
|
118
|
+
packaging?: string;
|
|
119
|
+
/** Storefront or market: "US", "DE", "CN". */
|
|
120
|
+
market?: string;
|
|
121
|
+
/** A franchised distributor or the manufacturer's own store; absent when not known. */
|
|
122
|
+
authorized?: boolean;
|
|
123
|
+
/** INTERNAL, publishers only: what the observer wrote down about the listing and how it was read. Never served to users. */
|
|
124
|
+
note?: string;
|
|
125
|
+
/** When the offer was observed at the supplier (when the price was fetched). */
|
|
126
|
+
observedAt: string;
|
|
127
|
+
/**
|
|
128
|
+
* INTERNAL, publishers only: where the observation came from (a URL, a quote
|
|
129
|
+
* reference; "protopart-import" for prices carried over from ProtoPart).
|
|
130
|
+
* Required when an offer is recorded; never served to users (`PUBLIC_OFFER_FIELDS`).
|
|
131
|
+
*/
|
|
132
|
+
source?: string;
|
|
133
|
+
/** The observation is too old, or the product discontinued, to quote as a current price: history, not a quote. Absent means not known to be stale. */
|
|
134
|
+
stale?: boolean;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The members of an offer a user is served (`GET /v1/parts/:id/offers`): the
|
|
139
|
+
* result of pricing, by source. Everything else an offer record holds
|
|
140
|
+
* (`source`, `note`: how and where the price was read) stays in the service
|
|
141
|
+
* and is given only to a publisher who asks for the internal view. A new
|
|
142
|
+
* member is internal until it is added here; test/offers-public.test.ts pins
|
|
143
|
+
* the list.
|
|
144
|
+
*/
|
|
145
|
+
export const PUBLIC_OFFER_FIELDS = [
|
|
146
|
+
"id",
|
|
147
|
+
"partId",
|
|
148
|
+
"mpn",
|
|
149
|
+
"supplier",
|
|
150
|
+
"sku",
|
|
151
|
+
"url",
|
|
152
|
+
"unitPrice",
|
|
153
|
+
"currency",
|
|
154
|
+
"priceBreaks",
|
|
155
|
+
"minQuantity",
|
|
156
|
+
"stock",
|
|
157
|
+
"leadTimeWeeks",
|
|
158
|
+
"packaging",
|
|
159
|
+
"market",
|
|
160
|
+
"authorized",
|
|
161
|
+
"observedAt",
|
|
162
|
+
"stale",
|
|
163
|
+
] as const;
|
|
164
|
+
/** An offer as users see it. */
|
|
165
|
+
export type PublicOffer = Pick<Offer, (typeof PUBLIC_OFFER_FIELDS)[number]>;
|
|
166
|
+
|
|
167
|
+
export interface SearchQuery {
|
|
168
|
+
q?: string;
|
|
169
|
+
/** Taxonomy path: parts with a category at it or below it. */
|
|
170
|
+
taxonomy?: string;
|
|
171
|
+
domain?: string;
|
|
172
|
+
protocol?: string;
|
|
173
|
+
tag?: string;
|
|
174
|
+
/** The same filter as `taxonomy` (this service's name for it before the protocol); `taxonomy` wins when both are given. */
|
|
175
|
+
category?: string;
|
|
176
|
+
includeDeprecated?: boolean;
|
|
177
|
+
limit?: number;
|
|
178
|
+
/** `nextCursor` of the previous page. */
|
|
179
|
+
cursor?: string;
|
|
180
|
+
/** Before cursors; still accepted. */
|
|
181
|
+
offset?: number;
|
|
182
|
+
/** Return facet counts. */
|
|
183
|
+
facets?: boolean;
|
|
184
|
+
/** `redistributable`: only parts whose recommended revision is redistributable (`DistributionScope`). */
|
|
185
|
+
distribution?: "redistributable";
|
|
186
|
+
/**
|
|
187
|
+
* The order of the results (capability `x-sort`, this library's extension):
|
|
188
|
+
* `relevance` (the default: with search words, the closeness of the text
|
|
189
|
+
* match first and relevance within it), `name`, `manufacturer` or `updated`
|
|
190
|
+
* (newest revision first). Ties end on the part id, so every order is
|
|
191
|
+
* stable. A library without the capability ignores it.
|
|
192
|
+
*/
|
|
193
|
+
sort?: SearchSort;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Counts of matching parts per value, over every page; taxonomy counts each path and every ancestor. */
|
|
197
|
+
export interface SearchFacets {
|
|
198
|
+
taxonomy: Record<string, number>;
|
|
199
|
+
domain: Record<string, number>;
|
|
200
|
+
protocol: Record<string, number>;
|
|
201
|
+
tag: Record<string, number>;
|
|
202
|
+
/**
|
|
203
|
+
* Service extra (not part of the protocol): parts per taxonomy path (each
|
|
204
|
+
* part counted once at every ancestor of its categories), over every filter
|
|
205
|
+
* of the query except the taxonomy filter, so a drill-down shows the counts
|
|
206
|
+
* of siblings and children alike.
|
|
207
|
+
*/
|
|
208
|
+
categories: Record<string, number>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** `GET /v1/parts`: the uhd-library/v1 search response. */
|
|
212
|
+
export interface SearchResult {
|
|
213
|
+
total: number;
|
|
214
|
+
parts: PartSummary[];
|
|
215
|
+
/** Pass as `cursor` for the next page; null on the last. */
|
|
216
|
+
nextCursor: string | null;
|
|
217
|
+
facets?: SearchFacets;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** `GET /.well-known/uhd-library` and `GET /v1`: the uhd-library/v1 discovery document, plus the service's counts. */
|
|
221
|
+
export interface Discovery {
|
|
222
|
+
protocol: "uhd-library/v1";
|
|
223
|
+
name: string;
|
|
224
|
+
id: string;
|
|
225
|
+
description?: string;
|
|
226
|
+
version: string;
|
|
227
|
+
api: string;
|
|
228
|
+
envelopeSchemas: string[];
|
|
229
|
+
uhdSchema: { min: string; below: string };
|
|
230
|
+
/** `id` is a service extra: the taxonomy's id ("uhd"). */
|
|
231
|
+
taxonomy: { id?: string; version: string; namespaces?: string[] } | null;
|
|
232
|
+
capabilities: string[];
|
|
233
|
+
auth: { read: "none" } | { read: "bearer"; realm?: string; documentation?: string };
|
|
234
|
+
limits: { defaultPageSize: number; maxPageSize: number };
|
|
235
|
+
/** Service extras (not part of the protocol). */
|
|
236
|
+
service: string;
|
|
237
|
+
publishing: boolean;
|
|
238
|
+
/** The scope this document describes; on the team's view, where the redistributable view lives. */
|
|
239
|
+
distribution: DistributionScope;
|
|
240
|
+
views?: { redistributable: string };
|
|
241
|
+
/** With capability `x-sort`: the values `sort` takes in a search, and the order without it. */
|
|
242
|
+
sort?: { values: SearchSort[]; default: SearchSort };
|
|
243
|
+
/**
|
|
244
|
+
* How to sign in, when the service authenticates users (PB-911). From
|
|
245
|
+
* 0.2.0 (PB-928) every read of the library needs a signed-in user:
|
|
246
|
+
* `required` lists them (search, taxonomy, parts, revisions, files, kits,
|
|
247
|
+
* offers, downloads), and `auth.read` is `bearer`. Firebase details are
|
|
248
|
+
* identifiers for clients, never secrets.
|
|
249
|
+
*/
|
|
250
|
+
account?: {
|
|
251
|
+
required: string[];
|
|
252
|
+
provider: "firebase";
|
|
253
|
+
projectId?: string;
|
|
254
|
+
apiKey?: string;
|
|
255
|
+
signInUrl?: string;
|
|
256
|
+
deviceUrl?: string;
|
|
257
|
+
emulator?: string;
|
|
258
|
+
};
|
|
259
|
+
/** The library's counts: left out for a request that is not signed in, when the service authenticates users. */
|
|
260
|
+
parts?: number;
|
|
261
|
+
revisions?: number;
|
|
262
|
+
blobs?: number;
|
|
263
|
+
blobBytes?: number;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** `GET /v1/taxonomy`: the taxonomy the service uses, with part counts. */
|
|
267
|
+
export interface TaxonomyResult {
|
|
268
|
+
taxonomy: {
|
|
269
|
+
id: string;
|
|
270
|
+
version: string;
|
|
271
|
+
extensions: { library: string; root: string; taxonomyVersion: string }[];
|
|
272
|
+
/** When it was given to the service. */
|
|
273
|
+
setAt: string;
|
|
274
|
+
};
|
|
275
|
+
/** Parts counted (the query's filters apply, the taxonomy filter excepted). */
|
|
276
|
+
total: number;
|
|
277
|
+
/** Of those, parts with no category. */
|
|
278
|
+
uncategorised: number;
|
|
279
|
+
nodes: TaxonomyTreeNode[];
|
|
280
|
+
/** Category paths parts list that the taxonomy does not have, with their part counts. */
|
|
281
|
+
unknown: { path: string; count: number }[];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** `GET /v1/parts/:partId/revisions/:revision/closure`. */
|
|
285
|
+
export interface Closure {
|
|
286
|
+
root: PartRef;
|
|
287
|
+
/** The root and every transitive dependency, each at its pinned revision; dependencies first. */
|
|
288
|
+
revisions: PartRevisionEnvelope[];
|
|
289
|
+
/** Parts reached at more than one revision (a project can hold only one). */
|
|
290
|
+
conflicts: { partId: string; revisions: number[] }[];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Every error response: `{ error: ApiError }`. */
|
|
294
|
+
export interface ApiError {
|
|
295
|
+
code: string;
|
|
296
|
+
message: string;
|
|
297
|
+
[detail: string]: unknown;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** A part's relevance seed: the value the library's owners gave it (library/relevance.json), with the reason. */
|
|
301
|
+
export interface RelevanceSeed {
|
|
302
|
+
partId: string;
|
|
303
|
+
seed: number;
|
|
304
|
+
reason?: string;
|
|
305
|
+
setAt?: string;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** `PUT /v1/relevance`: every seed, as `{ <partId>: { seed, reason? } }`; a part left out is cleared to 0. */
|
|
309
|
+
export type RelevanceSeeds = Record<string, { seed: number; reason?: string }>;
|
|
310
|
+
|
|
311
|
+
export interface RelevanceSeedsResult {
|
|
312
|
+
/** Seeds written (new, or a changed value or reason). */
|
|
313
|
+
set: number;
|
|
314
|
+
unchanged: number;
|
|
315
|
+
/** Parts that had a seed and are not in the body: now 0. */
|
|
316
|
+
cleared: number;
|
|
317
|
+
/** Seeded part ids the catalog does not hold (kept: they apply when the part is published). */
|
|
318
|
+
unknown: string[];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** What a recorded download is counted as: a revision asked for by itself, or one pulled in as a pinned dependency of another. */
|
|
322
|
+
export type UsageKind = "revision" | "dependency";
|
|
323
|
+
|
|
324
|
+
/** One part in `GET /v1/usage` (publishers only). */
|
|
325
|
+
export interface UsageRow {
|
|
326
|
+
partId: string;
|
|
327
|
+
name?: string;
|
|
328
|
+
/** Requests for the full revision in the period, every one counted: adds, and looks (a detail page, an update check). */
|
|
329
|
+
downloads: number;
|
|
330
|
+
/** Closure downloads (`parts add`, an applied `parts update`, the VS Code add), once per account, part revision and day: what informs relevance. */
|
|
331
|
+
adds: number;
|
|
332
|
+
/** The same two numbers for the revisions downloaded, by revision. */
|
|
333
|
+
revisions: Record<string, { downloads: number; adds: number }>;
|
|
334
|
+
/** Times the part came along as a pinned dependency of another (once per account, revision and day). */
|
|
335
|
+
asDependency: number;
|
|
336
|
+
seed: number;
|
|
337
|
+
relevance: number;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** `GET /v1/usage`: the most added parts over a period (publishers only). */
|
|
341
|
+
export interface UsageReport {
|
|
342
|
+
/** First and last day counted (UTC, `YYYY-MM-DD`), inclusive. */
|
|
343
|
+
from: string;
|
|
344
|
+
to: string;
|
|
345
|
+
days: number;
|
|
346
|
+
totals: { downloads: number; adds: number; parts: number };
|
|
347
|
+
/** By adds, then downloads, then part id. */
|
|
348
|
+
parts: UsageRow[];
|
|
349
|
+
/** Adds per day over the period, days without any left out. */
|
|
350
|
+
daily: { day: string; downloads: number; adds: number }[];
|
|
351
|
+
}
|