@huaqiu/hardware-artifacts 0.7.13 → 0.7.15
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/lib/index.d.mts +53 -10
- package/lib/index.mjs +80 -8
- package/lib/routes.d.mts +14 -3
- package/lib/routes.mjs +205 -10
- package/lib/service-CtVn7z8b.d.mts +568 -0
- package/lib/service-Yrc2C_eo.mjs +2005 -0
- package/lib/service.d.mts +2 -226
- package/lib/service.mjs +1 -837
- package/package.json +3 -2
- package/src/index.ts +117 -8
- package/src/order.ts +778 -0
- package/src/routes.ts +221 -10
- package/src/service.ts +692 -49
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
import { ChildProcess } from "node:child_process";
|
|
2
|
+
//#region src/order.d.ts
|
|
3
|
+
/** Endpoint paths relative to the order base URL (the host, not a DSH route). */
|
|
4
|
+
declare const ORDER_PATHS: Readonly<{
|
|
5
|
+
pcb: "/openapi/api/hqpcb/External/fileQuote";
|
|
6
|
+
smt: "/openapi/pcba/saveDfmTmpOrder";
|
|
7
|
+
}>;
|
|
8
|
+
/** Default origin serving the two endpoints. */
|
|
9
|
+
declare const DEFAULT_ORDER_BASE_URL = "https://www.eda.cn";
|
|
10
|
+
/** Order page host the webview loads after both submissions. */
|
|
11
|
+
declare const DEFAULT_ORDER_PAGE_BASE = "https://www.hqpcb.com";
|
|
12
|
+
/** `tid` the reference client sends for a board quoted from a file. */
|
|
13
|
+
declare const ORDER_SOURCE_TID = "354";
|
|
14
|
+
interface BoardFacts {
|
|
15
|
+
/** Copper layer count, as KiCad counts them (F.Cu, In*.Cu, B.Cu). */
|
|
16
|
+
readonly layers: number;
|
|
17
|
+
readonly widthMm: number;
|
|
18
|
+
readonly heightMm: number;
|
|
19
|
+
readonly thicknessMm: number;
|
|
20
|
+
readonly minTrackMm?: number;
|
|
21
|
+
readonly minViaDrillMm?: number;
|
|
22
|
+
readonly outerOz?: number;
|
|
23
|
+
readonly innerOz?: number;
|
|
24
|
+
/** Placed pads, used for the assembly form's `patch_pad_number`. */
|
|
25
|
+
readonly padCount?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Derive the fabrication facts the order form needs from a saved board.
|
|
29
|
+
*
|
|
30
|
+
* Only values the file actually carries are returned; the caller keeps the
|
|
31
|
+
* reference defaults for anything missing instead of inventing a measurement.
|
|
32
|
+
*/
|
|
33
|
+
declare function readBoardFacts(text: string): BoardFacts;
|
|
34
|
+
/** Snap a board thickness onto the tier list for its layer count. */
|
|
35
|
+
declare function snapThickness(layers: number, thicknessMm: number): string;
|
|
36
|
+
/** Snap a measured minimum trace/space (mm) onto the mil tier list. */
|
|
37
|
+
declare function snapTraceTier(minTrackMm: number | undefined): string;
|
|
38
|
+
/** Snap a measured hole (mm) onto the drill tiers the form accepts. */
|
|
39
|
+
declare function snapHoleTier(minHoleMm: number | undefined, thicknessMm: number): string;
|
|
40
|
+
interface PcbFormOverrides {
|
|
41
|
+
/** Production quantity (the form's `bcount`). */
|
|
42
|
+
readonly quantity?: number;
|
|
43
|
+
readonly solderMaskColor?: string;
|
|
44
|
+
readonly surfaceFinish?: string;
|
|
45
|
+
readonly thicknessMm?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The PCB order form exactly as the reference client posts it.
|
|
49
|
+
*
|
|
50
|
+
* Every field of `PCB_FORM` is present, including empty optionals, because the
|
|
51
|
+
* endpoint validates the full base/process/special/personalized blocks. Only
|
|
52
|
+
* geometry and process ability are derived from the board; everything else
|
|
53
|
+
* keeps the reference default rather than inventing a preference.
|
|
54
|
+
*/
|
|
55
|
+
declare function pcbOrderForm(facts: BoardFacts, overrides?: PcbFormOverrides): Record<string, string>;
|
|
56
|
+
interface SmtFormOverrides {
|
|
57
|
+
readonly quantity?: number;
|
|
58
|
+
readonly bomFileName: string;
|
|
59
|
+
readonly coordFileName: string;
|
|
60
|
+
readonly materialTypes: number;
|
|
61
|
+
readonly padCount?: number;
|
|
62
|
+
}
|
|
63
|
+
/** The `smt_order` half of `PCB_SMT_FORM`, with file names attached. */
|
|
64
|
+
declare function smtOrderForm(facts: BoardFacts, overrides: SmtFormOverrides): Record<string, string | number>;
|
|
65
|
+
interface PositionRow {
|
|
66
|
+
readonly designator: string;
|
|
67
|
+
readonly footprint: string;
|
|
68
|
+
readonly x: string;
|
|
69
|
+
readonly y: string;
|
|
70
|
+
readonly layer: 'T' | 'B';
|
|
71
|
+
readonly rotation: string;
|
|
72
|
+
readonly comment: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Convert `kicad-cli pcb export pos --format csv` rows into the
|
|
76
|
+
* `Designator,Footprint,PosX,PosY,Layer,Rotation,Comment` table the assembly
|
|
77
|
+
* endpoint parses (see `write_positions_to_csv` in the reference).
|
|
78
|
+
*/
|
|
79
|
+
declare function parsePositions(csv: string): PositionRow[];
|
|
80
|
+
/** The positions table, with the UTF-8 BOM the reference writes. */
|
|
81
|
+
declare function positionsCsv(rows: readonly PositionRow[]): string;
|
|
82
|
+
interface OrderBomRow {
|
|
83
|
+
readonly designators: readonly string[];
|
|
84
|
+
readonly mpn: string;
|
|
85
|
+
readonly description: string;
|
|
86
|
+
readonly footprint: string;
|
|
87
|
+
readonly quantity: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Group placed designators into assembly lines.
|
|
91
|
+
*
|
|
92
|
+
* Positions are the board truth for what will be placed, so they drive the
|
|
93
|
+
* grouping; the schematic BOM only supplies value/MPN for a designator. A
|
|
94
|
+
* designator with no BOM entry keeps its position data instead of being
|
|
95
|
+
* dropped, which is what the reference does (it never consults the schematic).
|
|
96
|
+
*/
|
|
97
|
+
declare function orderBomRows(positions: readonly PositionRow[], bom: readonly BomRow[] | undefined): OrderBomRow[];
|
|
98
|
+
/** The assembly BOM table (`序号,型号,规格参数,封装,品牌,位号,单机用量`). */
|
|
99
|
+
declare function orderBomCsv(rows: readonly OrderBomRow[]): string;
|
|
100
|
+
/** Read `id` / `guid` out of the redirect URL the PCB endpoint returns. */
|
|
101
|
+
declare function orderIdsFromUrl(url: string): {
|
|
102
|
+
id?: string;
|
|
103
|
+
guid?: string;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* The final PCB page KiCad loads into its order webview.
|
|
107
|
+
*
|
|
108
|
+
* Mirrors `place_order_for_pcb.h` exactly:
|
|
109
|
+
* `<page>/mycenter/orders/pcb/quote?type=PCB&id=…&guid=…&tid=354&token=…`, e.g.
|
|
110
|
+
* `https://www.hqpcb.com/mycenter/orders/pcb/quote?type=PCB&id=4679157&guid=19c1…&tid=354&token=7047…`
|
|
111
|
+
*
|
|
112
|
+
* Values are query-encoded, which is the only deviation from the C++ string
|
|
113
|
+
* concatenation — a token with `+` or `/` must not corrupt the query. Parameter
|
|
114
|
+
* order is the reference order; the page is not sensitive to it, but a stable
|
|
115
|
+
* order keeps the URL comparable with a KiCad-generated one.
|
|
116
|
+
*/
|
|
117
|
+
declare function pcbOrderUrl(pageBase: string, ids: {
|
|
118
|
+
id?: string;
|
|
119
|
+
guid?: string;
|
|
120
|
+
}, token: string | undefined): string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* The final assembly page KiCad loads into its order webview.
|
|
123
|
+
*
|
|
124
|
+
* The reference appends `token` and `source=bom` to the URL the SMT endpoint
|
|
125
|
+
* returns (`place_order_for_smt.h`); the endpoint's URL is the hqpcb quote page
|
|
126
|
+
* itself, so the page is composed here from its `id` — the same page, with the
|
|
127
|
+
* query exactly as the webview ends up showing it:
|
|
128
|
+
*
|
|
129
|
+
* `https://www.hqpcb.com/mycenter/orders/smt/quote?id=1309829474627354699&source=bom&token=7047…`
|
|
130
|
+
*
|
|
131
|
+
* Composing rather than patching the backend string keeps the page host
|
|
132
|
+
* independent of whichever origin answered the POST, and keeps `source=bom`
|
|
133
|
+
* (which switches the page into BOM matching) even if the response omits it.
|
|
134
|
+
*/
|
|
135
|
+
declare function smtOrderUrl(pageBase: string, ids: {
|
|
136
|
+
id?: string;
|
|
137
|
+
}, token: string | undefined): string | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Fallback for an SMT response whose URL carries no `id`: append `token` and
|
|
140
|
+
* `source=bom` to the backend URL exactly as the reference does.
|
|
141
|
+
*
|
|
142
|
+
* This is the literal `add_parameter_to_url(result.url, {token, source})`
|
|
143
|
+
* behaviour; it is only used when the response cannot supply an order id.
|
|
144
|
+
*/
|
|
145
|
+
declare function smtOrderUrlFromBackend(orderUrl: string, token: string | undefined): string | undefined;
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/service.d.ts
|
|
148
|
+
type ArtifactKind = 'schematic' | 'pcb' | 'pcb-3d' | 'bom' | 'mechanical-3d';
|
|
149
|
+
/** Native handoff is KiCad-only in this POC; SolidCraft stays agent context. */
|
|
150
|
+
type NativeApplication = 'kicad';
|
|
151
|
+
interface HardwareArtifact {
|
|
152
|
+
readonly id: string;
|
|
153
|
+
readonly kind: ArtifactKind;
|
|
154
|
+
readonly path: string;
|
|
155
|
+
readonly projectPath?: string;
|
|
156
|
+
/** BOM keeps its schematic; PCB 3D keeps its board; sheets keep their root. */
|
|
157
|
+
readonly sourcePath?: string;
|
|
158
|
+
readonly title: string;
|
|
159
|
+
readonly format: string;
|
|
160
|
+
/** Content hash of the saved source, filled when the source is read. */
|
|
161
|
+
readonly revision?: string;
|
|
162
|
+
}
|
|
163
|
+
interface HardwareProject {
|
|
164
|
+
readonly path: string;
|
|
165
|
+
readonly name: string;
|
|
166
|
+
/** Root schematic: the authoritative project entry point. */
|
|
167
|
+
readonly rootSheet?: HardwareArtifact;
|
|
168
|
+
readonly schematic?: HardwareArtifact;
|
|
169
|
+
/** Semantic views; both keep the identity of their source artifact. */
|
|
170
|
+
readonly bom?: HardwareArtifact;
|
|
171
|
+
readonly pcb3d?: HardwareArtifact;
|
|
172
|
+
readonly sheets: readonly HardwareArtifact[];
|
|
173
|
+
/** Deterministic default board, only when ownership is unambiguous. */
|
|
174
|
+
readonly defaultBoard?: string;
|
|
175
|
+
readonly boards: readonly HardwareArtifact[];
|
|
176
|
+
readonly mechanical: readonly HardwareArtifact[];
|
|
177
|
+
readonly selectionRequired: boolean;
|
|
178
|
+
}
|
|
179
|
+
interface DiscoveryResult {
|
|
180
|
+
readonly cwd: string;
|
|
181
|
+
readonly manifestPath?: string;
|
|
182
|
+
readonly projects: readonly HardwareProject[];
|
|
183
|
+
readonly selected?: HardwareProject;
|
|
184
|
+
readonly issue?: {
|
|
185
|
+
readonly code: string;
|
|
186
|
+
readonly message: string;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
interface InstallationInfo {
|
|
190
|
+
readonly configured: boolean;
|
|
191
|
+
readonly root?: string;
|
|
192
|
+
readonly cli?: string;
|
|
193
|
+
readonly projectManager?: string;
|
|
194
|
+
readonly pcbEditor?: string;
|
|
195
|
+
readonly schematicEditor?: string;
|
|
196
|
+
readonly executable?: string;
|
|
197
|
+
readonly version?: string;
|
|
198
|
+
readonly error?: string;
|
|
199
|
+
}
|
|
200
|
+
interface Installations {
|
|
201
|
+
readonly kicad: InstallationInfo;
|
|
202
|
+
readonly solidcraft: InstallationInfo;
|
|
203
|
+
}
|
|
204
|
+
interface OpenArtifactRequest {
|
|
205
|
+
readonly application: NativeApplication;
|
|
206
|
+
readonly artifactPath: string;
|
|
207
|
+
readonly kind: ArtifactKind;
|
|
208
|
+
readonly projectPath?: string;
|
|
209
|
+
}
|
|
210
|
+
interface OpenArtifactResult {
|
|
211
|
+
readonly launched: true;
|
|
212
|
+
readonly command: string;
|
|
213
|
+
readonly args: readonly string[];
|
|
214
|
+
readonly cwd: string;
|
|
215
|
+
readonly pid?: number;
|
|
216
|
+
}
|
|
217
|
+
interface SourceRequest {
|
|
218
|
+
readonly artifactPath: string;
|
|
219
|
+
readonly expectedRevision?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Roots the caller names. They are *added* to the roots the host resolved
|
|
222
|
+
* for {@link sessionId}; naming one never revokes another.
|
|
223
|
+
*/
|
|
224
|
+
readonly roots?: readonly string[];
|
|
225
|
+
/** DSH session the read belongs to; its workspace is the authorization base. */
|
|
226
|
+
readonly sessionId?: string;
|
|
227
|
+
}
|
|
228
|
+
interface SourceResult {
|
|
229
|
+
readonly path: string;
|
|
230
|
+
readonly kind: 'schematic' | 'pcb';
|
|
231
|
+
readonly revision: string;
|
|
232
|
+
readonly bytes: number;
|
|
233
|
+
readonly mtimeMs: number;
|
|
234
|
+
readonly text: string;
|
|
235
|
+
}
|
|
236
|
+
interface GlbRequest {
|
|
237
|
+
readonly artifactPath: string;
|
|
238
|
+
readonly roots?: readonly string[];
|
|
239
|
+
readonly sessionId?: string;
|
|
240
|
+
readonly signal?: AbortSignal;
|
|
241
|
+
}
|
|
242
|
+
interface GlbResult {
|
|
243
|
+
readonly path: string;
|
|
244
|
+
readonly revision: string;
|
|
245
|
+
readonly bytes: number;
|
|
246
|
+
readonly generatedAt: string;
|
|
247
|
+
readonly cached: boolean;
|
|
248
|
+
readonly file: string;
|
|
249
|
+
}
|
|
250
|
+
/** One grouped BOM line, as KiCad's own BOM export groups it. */
|
|
251
|
+
interface BomRow {
|
|
252
|
+
readonly references: readonly string[];
|
|
253
|
+
readonly quantity: number;
|
|
254
|
+
readonly value: string;
|
|
255
|
+
readonly footprint: string;
|
|
256
|
+
readonly dnp: boolean;
|
|
257
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
258
|
+
}
|
|
259
|
+
interface BomResult {
|
|
260
|
+
readonly path: string;
|
|
261
|
+
readonly revision: string;
|
|
262
|
+
readonly generatedAt: string;
|
|
263
|
+
readonly cached: boolean;
|
|
264
|
+
readonly rows: readonly BomRow[];
|
|
265
|
+
readonly source: 'kicad-cli-bom';
|
|
266
|
+
}
|
|
267
|
+
interface OrderPackageSummary {
|
|
268
|
+
readonly zipName: string;
|
|
269
|
+
readonly zipBytes: number;
|
|
270
|
+
readonly files: readonly {
|
|
271
|
+
readonly name: string;
|
|
272
|
+
readonly bytes: number;
|
|
273
|
+
}[];
|
|
274
|
+
}
|
|
275
|
+
/** A prepared fabrication package: what would be uploaded, nothing sent yet. */
|
|
276
|
+
interface FabricationResult {
|
|
277
|
+
readonly boardPath: string;
|
|
278
|
+
readonly revision: string;
|
|
279
|
+
readonly generatedAt: string;
|
|
280
|
+
readonly facts: BoardFacts;
|
|
281
|
+
readonly archive: OrderPackageSummary;
|
|
282
|
+
/** Assembly inputs, present when a schematic was supplied. */
|
|
283
|
+
readonly assembly?: {
|
|
284
|
+
readonly positions: number;
|
|
285
|
+
readonly bomLines: number;
|
|
286
|
+
readonly positionsBytes: number;
|
|
287
|
+
readonly bomBytes: number;
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
interface OrderConfigInfo {
|
|
291
|
+
readonly configured: boolean;
|
|
292
|
+
readonly baseUrl: string;
|
|
293
|
+
/** True when a signed-in session or a configured token can sign the page. */
|
|
294
|
+
readonly hasToken: boolean;
|
|
295
|
+
readonly provider: 'huaqiu';
|
|
296
|
+
}
|
|
297
|
+
interface PlaceOrderRequest {
|
|
298
|
+
readonly kind: 'pcb' | 'smt';
|
|
299
|
+
readonly boardPath: string;
|
|
300
|
+
readonly schematicPath?: string;
|
|
301
|
+
readonly roots?: readonly string[];
|
|
302
|
+
readonly sessionId?: string;
|
|
303
|
+
readonly quantity?: number;
|
|
304
|
+
readonly signal?: AbortSignal;
|
|
305
|
+
/** Open the resulting page in the default browser; defaults to true. */
|
|
306
|
+
readonly launch?: boolean;
|
|
307
|
+
}
|
|
308
|
+
interface PlaceOrderResult {
|
|
309
|
+
readonly kind: 'pcb' | 'smt';
|
|
310
|
+
/** The exact URL KiCad's own action loads into its order webview. */
|
|
311
|
+
readonly orderUrl: string;
|
|
312
|
+
/** The backend's raw URL, before KiCad's own query parameters were added. */
|
|
313
|
+
readonly responseUrl: string;
|
|
314
|
+
/** True when the host handed `orderUrl` to the OS default browser. */
|
|
315
|
+
readonly launched: boolean;
|
|
316
|
+
readonly launcher?: string;
|
|
317
|
+
readonly status: 'launched' | 'ready';
|
|
318
|
+
readonly message: string;
|
|
319
|
+
readonly endpoint: string;
|
|
320
|
+
readonly facts: BoardFacts;
|
|
321
|
+
readonly archive: OrderPackageSummary;
|
|
322
|
+
readonly assembly?: FabricationResult['assembly'];
|
|
323
|
+
}
|
|
324
|
+
interface HardwareArtifactsOptions {
|
|
325
|
+
readonly kicadRoot?: string;
|
|
326
|
+
readonly solidcraftRoot?: string;
|
|
327
|
+
/** Origin for the place-order endpoints; defaults to the Huaqiu host. */
|
|
328
|
+
readonly orderBaseUrl?: string;
|
|
329
|
+
readonly orderPageBase?: string;
|
|
330
|
+
/** Huaqiu access token; only ever sent to the order endpoint. */
|
|
331
|
+
readonly accessToken?: string;
|
|
332
|
+
/**
|
|
333
|
+
* Resolves the signed-in Huaqiu token when no explicit token is configured.
|
|
334
|
+
*
|
|
335
|
+
* hqpcb is a Huaqiu business, so the login that feeds the eda.cn API is also
|
|
336
|
+
* the token the order page expects — there is no second credential.
|
|
337
|
+
*/
|
|
338
|
+
readonly authToken?: () => Promise<string | null>;
|
|
339
|
+
/** Injectable transport for tests; defaults to global fetch. */
|
|
340
|
+
readonly postOrder?: (url: string, init: {
|
|
341
|
+
readonly body: Buffer;
|
|
342
|
+
readonly contentType: string;
|
|
343
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
344
|
+
readonly signal?: AbortSignal;
|
|
345
|
+
}) => Promise<{
|
|
346
|
+
readonly status: number;
|
|
347
|
+
readonly text: string;
|
|
348
|
+
}>;
|
|
349
|
+
/**
|
|
350
|
+
* Live accessor for the user-configured roots.
|
|
351
|
+
*
|
|
352
|
+
* The plugin passes the profile config reference, so a settings write that
|
|
353
|
+
* replaces a volatile field is visible on the next validation without the
|
|
354
|
+
* service caching a start-time snapshot.
|
|
355
|
+
*/
|
|
356
|
+
readonly settings?: () => {
|
|
357
|
+
readonly kicadRoot?: string;
|
|
358
|
+
readonly solidcraftRoot?: string;
|
|
359
|
+
readonly orderBaseUrl?: string;
|
|
360
|
+
readonly accessToken?: string;
|
|
361
|
+
};
|
|
362
|
+
readonly probeVersion?: (executable: string) => string | undefined;
|
|
363
|
+
readonly spawnProcess?: (command: string, args: readonly string[], options: {
|
|
364
|
+
cwd: string;
|
|
365
|
+
detached: boolean;
|
|
366
|
+
stdio: 'ignore';
|
|
367
|
+
windowsHide: boolean;
|
|
368
|
+
shell: false;
|
|
369
|
+
}) => Pick<ChildProcess, 'pid'>;
|
|
370
|
+
/**
|
|
371
|
+
* Command used to hand a URL to the OS. Defaults to `open` on macOS,
|
|
372
|
+
* `rundll32 url.dll,FileProtocolHandler` on Windows and `xdg-open` elsewhere.
|
|
373
|
+
*/
|
|
374
|
+
readonly openExternal?: (url: string) => {
|
|
375
|
+
readonly command: string;
|
|
376
|
+
readonly args: readonly string[];
|
|
377
|
+
};
|
|
378
|
+
/** Runs one short-lived CLI command and returns its exit facts. */
|
|
379
|
+
readonly runCommand?: (command: string, args: readonly string[], options: {
|
|
380
|
+
cwd: string;
|
|
381
|
+
timeoutMs: number;
|
|
382
|
+
signal?: AbortSignal;
|
|
383
|
+
}) => Promise<{
|
|
384
|
+
exitCode: number | null;
|
|
385
|
+
stdout: string;
|
|
386
|
+
stderr: string;
|
|
387
|
+
timedOut: boolean;
|
|
388
|
+
}>;
|
|
389
|
+
/** Cache directory for derived outputs; defaults to a temp subdirectory. */
|
|
390
|
+
readonly cacheRoot?: string;
|
|
391
|
+
readonly glbTimeoutMs?: number;
|
|
392
|
+
/** Source text limit; protects the host from pathological files. */
|
|
393
|
+
readonly maxSourceBytes?: number;
|
|
394
|
+
}
|
|
395
|
+
/** Small, immutable host capability implementation. */
|
|
396
|
+
declare class HardwareArtifactService {
|
|
397
|
+
private readonly config;
|
|
398
|
+
private readonly options;
|
|
399
|
+
private readonly cacheRoot;
|
|
400
|
+
private readonly glbTimeoutMs;
|
|
401
|
+
private readonly maxSourceBytes;
|
|
402
|
+
/**
|
|
403
|
+
* Last discovery per scope — one entry per DSH session, plus the unscoped
|
|
404
|
+
* default used by tests and non-DSH embeds.
|
|
405
|
+
*
|
|
406
|
+
* It is a map rather than one field on purpose: a single "most recent
|
|
407
|
+
* discovery" is shared by every open viewer, so switching to a session in
|
|
408
|
+
* another workspace silently revoked the authorization of the viewer that
|
|
409
|
+
* stayed open. Authorization must never depend on who asked last.
|
|
410
|
+
*/
|
|
411
|
+
private readonly discoveries;
|
|
412
|
+
/** Completed GLB exports keyed by `sourcePath:revision`. */
|
|
413
|
+
private readonly glbCache;
|
|
414
|
+
/** In-flight GLB exports keyed by the same key, so concurrent callers share one run. */
|
|
415
|
+
private readonly glbPending;
|
|
416
|
+
/** BOM projections keyed by `sourcePath:revision`. */
|
|
417
|
+
private readonly bomCache;
|
|
418
|
+
/** Prepared fabrication packages keyed by board, revision and schematic. */
|
|
419
|
+
private readonly packageCache;
|
|
420
|
+
constructor(config?: HardwareArtifactsOptions);
|
|
421
|
+
/** Configured roots, read live so a settings write is visible immediately. */
|
|
422
|
+
private roots;
|
|
423
|
+
/** Resolve configured installations from validated absolute paths only. */
|
|
424
|
+
installations(): Installations;
|
|
425
|
+
/** Paths passed to agent child processes. Never assign these globally. */
|
|
426
|
+
childEnvironment(): Record<string, string>;
|
|
427
|
+
/** Compact agent context: validated paths only, no project inventory dump. */
|
|
428
|
+
environmentText(current?: DiscoveryResult): string;
|
|
429
|
+
/**
|
|
430
|
+
* Deterministic discovery. An explicit project or manifest wins; otherwise
|
|
431
|
+
* exactly one `.kicad_pro` may be selected automatically. Ambiguity is
|
|
432
|
+
* returned as a selection requirement, never resolved by taking the first.
|
|
433
|
+
*
|
|
434
|
+
* @param cwdInput - workspace directory to walk.
|
|
435
|
+
* @param explicitProject - project chosen by the user, absolute or cwd-relative.
|
|
436
|
+
* @param sessionId - DSH session the discovery belongs to. Recording it per
|
|
437
|
+
* session is what keeps one open viewer from revoking another's roots.
|
|
438
|
+
*/
|
|
439
|
+
discover(cwdInput: string, explicitProject?: string, sessionId?: string): DiscoveryResult;
|
|
440
|
+
/** Last discovery for one scope, never another session's. */
|
|
441
|
+
discovery(sessionId?: string): DiscoveryResult | undefined;
|
|
442
|
+
/** The only discovery the host can speak for without being told a session. */
|
|
443
|
+
private soleDiscovery;
|
|
444
|
+
private remember;
|
|
445
|
+
private projectFrom;
|
|
446
|
+
/** Validate and launch a native application without a shell. */
|
|
447
|
+
open(request: OpenArtifactRequest): OpenArtifactResult;
|
|
448
|
+
/**
|
|
449
|
+
* Workspace roots a read may target: what this scope discovered, plus what
|
|
450
|
+
* the caller named.
|
|
451
|
+
*
|
|
452
|
+
* Additive on purpose. The previous shape unioned the caller's roots with one
|
|
453
|
+
* process-wide "last discovery", so any other session's discovery — a
|
|
454
|
+
* workspace switch is exactly that — replaced the root the open viewer was
|
|
455
|
+
* authorized by, and its next read failed with "artifact is outside the
|
|
456
|
+
* authorized workspace". Roots now only ever accumulate within their scope.
|
|
457
|
+
*/
|
|
458
|
+
private authorizedRoots;
|
|
459
|
+
/**
|
|
460
|
+
* Authorize one artifact path: canonical, realpath-checked, inside a
|
|
461
|
+
* workspace root, and of an expected type. A browser request cannot turn
|
|
462
|
+
* this into an arbitrary filesystem read, even from loopback.
|
|
463
|
+
*/
|
|
464
|
+
private authorize;
|
|
465
|
+
/** Saved source text plus a content-addressed revision. */
|
|
466
|
+
readSource(request: SourceRequest): Promise<SourceResult>;
|
|
467
|
+
private sourceRevision;
|
|
468
|
+
/** Cache directory for one board's derived outputs. */
|
|
469
|
+
private glbDirectory;
|
|
470
|
+
/**
|
|
471
|
+
* Generate (or reuse) the GLB for one board.
|
|
472
|
+
*
|
|
473
|
+
* - cache key includes the source content hash, so same-size/same-mtime edits invalidate
|
|
474
|
+
* - one in-flight export is shared by concurrent callers for the same revision
|
|
475
|
+
* - output is written to a temp file and renamed only after it validates
|
|
476
|
+
* - a timeout or abort leaves no partial file behind
|
|
477
|
+
*/
|
|
478
|
+
exportGlb(request: GlbRequest): Promise<GlbResult>;
|
|
479
|
+
/**
|
|
480
|
+
* Grouped BOM for one saved root schematic.
|
|
481
|
+
*
|
|
482
|
+
* Reuses KiCad's own BOM extraction (`kicad-cli sch export bom`), the same
|
|
483
|
+
* authoritative source `analyze_kicad_module` consumes, rather than building a
|
|
484
|
+
* second component analyser. Grouping key is every non-reference column, so
|
|
485
|
+
* different MPNs never merge and DNP stays explicit.
|
|
486
|
+
*/
|
|
487
|
+
exportBom(request: {
|
|
488
|
+
readonly artifactPath: string;
|
|
489
|
+
readonly roots?: readonly string[];
|
|
490
|
+
readonly sessionId?: string;
|
|
491
|
+
readonly signal?: AbortSignal;
|
|
492
|
+
}): Promise<BomResult>;
|
|
493
|
+
/** Live order settings, read at call time so a settings write is immediate. */
|
|
494
|
+
private orderSettings;
|
|
495
|
+
/** What the Order destination may do right now, without contacting anything. */
|
|
496
|
+
orderConfig(): Promise<OrderConfigInfo>;
|
|
497
|
+
/**
|
|
498
|
+
* The token the order page must carry.
|
|
499
|
+
*
|
|
500
|
+
* An explicitly configured token wins (it makes a scripted run possible);
|
|
501
|
+
* otherwise the signed-in Huaqiu session is used, which is the same token the
|
|
502
|
+
* eda.cn API accepts. Absent both, ordering is refused before anything is
|
|
503
|
+
* uploaded — the page would render signed out otherwise.
|
|
504
|
+
*/
|
|
505
|
+
private orderToken;
|
|
506
|
+
/**
|
|
507
|
+
* Build the fabrication archive and the assembly inputs for one board.
|
|
508
|
+
*
|
|
509
|
+
* The gerber/drill export is `kicad-cli`'s own plotter, so the archive is the
|
|
510
|
+
* same set of files a KiCad "Place order" would upload. Cached by source
|
|
511
|
+
* revision: reopening the panel must not re-run the exporter.
|
|
512
|
+
*/
|
|
513
|
+
fabricate(request: {
|
|
514
|
+
readonly boardPath: string;
|
|
515
|
+
readonly schematicPath?: string;
|
|
516
|
+
readonly roots?: readonly string[];
|
|
517
|
+
readonly sessionId?: string;
|
|
518
|
+
readonly signal?: AbortSignal;
|
|
519
|
+
}): Promise<FabricationResult & {
|
|
520
|
+
readonly archiveData: Uint8Array;
|
|
521
|
+
readonly assemblyFiles?: {
|
|
522
|
+
readonly positions: string;
|
|
523
|
+
readonly bom: string;
|
|
524
|
+
};
|
|
525
|
+
}>;
|
|
526
|
+
/**
|
|
527
|
+
* Submit one order to the Huaqiu openapi, exactly as the KiCad action does.
|
|
528
|
+
*
|
|
529
|
+
* PCB: every `PCB_FORM` field plus the gerber/drill archive as `file`.
|
|
530
|
+
* SMT: `pcbFile` + `coordFile` + `bomFile` and `reqParseVO`, with the caller's
|
|
531
|
+
* access token in `authorization`. The backend owns the order; this method
|
|
532
|
+
* forwards the files and composes the final page URL from the returned id the
|
|
533
|
+
* way the reference does.
|
|
534
|
+
*/
|
|
535
|
+
placeOrder(request: PlaceOrderRequest): Promise<PlaceOrderResult>;
|
|
536
|
+
/**
|
|
537
|
+
* Open one order page in the OS default browser.
|
|
538
|
+
*
|
|
539
|
+
* This is the only place a URL reaches an external program; the URL is
|
|
540
|
+
* validated by shape first and passed as a plain argument.
|
|
541
|
+
*/
|
|
542
|
+
openOrderUrl(raw: string): {
|
|
543
|
+
launched: true;
|
|
544
|
+
command: string;
|
|
545
|
+
url: string;
|
|
546
|
+
};
|
|
547
|
+
/** Serve a generated GLB file, re-validating the cache entry first. */
|
|
548
|
+
glbFile(boardPath: string, revision: string): string;
|
|
549
|
+
/** Drop cached derived outputs for one board (or all of them). */
|
|
550
|
+
clearCache(boardPath?: string): void;
|
|
551
|
+
}
|
|
552
|
+
/** RFC4180-style CSV reader: quoted fields, doubled quotes, CRLF rows. */
|
|
553
|
+
declare function parseCsv(text: string): string[][];
|
|
554
|
+
/**
|
|
555
|
+
* Group KiCad's per-reference BOM rows.
|
|
556
|
+
*
|
|
557
|
+
* Identity is every column except the reference and quantity columns, so a
|
|
558
|
+
* different MPN or a DNP flag always produces a separate line; ordering follows
|
|
559
|
+
* the first reference seen, which keeps the table stable between reads.
|
|
560
|
+
*
|
|
561
|
+
* Column names follow `kicad-cli sch export bom`'s default field set, which is
|
|
562
|
+
* `Refs,Value,Footprint,Qty,DNP`; a customized `--fields` header may spell the
|
|
563
|
+
* same columns out in full, and a grouped export may pack several references
|
|
564
|
+
* into one cell, so both spellings and both shapes are accepted.
|
|
565
|
+
*/
|
|
566
|
+
declare function groupBomRows(table: readonly string[][]): BomRow[];
|
|
567
|
+
//#endregion
|
|
568
|
+
export { PositionRow as A, smtOrderUrl as B, groupBomRows as C, DEFAULT_ORDER_PAGE_BASE as D, DEFAULT_ORDER_BASE_URL as E, pcbOrderForm as F, snapHoleTier as H, pcbOrderUrl as I, positionsCsv as L, orderBomRows as M, orderIdsFromUrl as N, ORDER_PATHS as O, parsePositions as P, readBoardFacts as R, SourceResult as S, BoardFacts as T, snapThickness as U, smtOrderUrlFromBackend as V, snapTraceTier as W, OrderConfigInfo as _, FabricationResult as a, PlaceOrderResult as b, HardwareArtifact as c, HardwareProject as d, InstallationInfo as f, OpenArtifactResult as g, OpenArtifactRequest as h, DiscoveryResult as i, orderBomCsv as j, ORDER_SOURCE_TID as k, HardwareArtifactService as l, NativeApplication as m, BomResult as n, GlbRequest as o, Installations as p, BomRow as r, GlbResult as s, ArtifactKind as t, HardwareArtifactsOptions as u, OrderPackageSummary as v, parseCsv as w, SourceRequest as x, PlaceOrderRequest as y, smtOrderForm as z };
|