@printhive/api 0.2.0 → 0.3.2
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 +16 -0
- package/README.md +94 -3
- package/dist/{chunk-7UULMDS5.js → chunk-YZJ5H32X.js} +7666 -749
- package/dist/{errors-TJFN2M7S.js → errors-GNC6X3MK.js} +1 -1
- package/dist/index.cjs +7801 -780
- package/dist/index.d.cts +2038 -155
- package/dist/index.d.ts +2038 -155
- package/dist/index.js +115 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,13 +4,54 @@ import {
|
|
|
4
4
|
apiError,
|
|
5
5
|
apiKey,
|
|
6
6
|
createRequest,
|
|
7
|
+
jobSnapshot,
|
|
7
8
|
model,
|
|
8
9
|
page,
|
|
10
|
+
preparation,
|
|
11
|
+
preparationDownload,
|
|
12
|
+
preparationInput,
|
|
9
13
|
printJob,
|
|
10
14
|
printer,
|
|
11
15
|
printers,
|
|
12
16
|
source
|
|
13
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-YZJ5H32X.js";
|
|
18
|
+
|
|
19
|
+
// src/filament-catalog.ts
|
|
20
|
+
var FilamentCatalog = class {
|
|
21
|
+
constructor(transport) {
|
|
22
|
+
this.transport = transport;
|
|
23
|
+
}
|
|
24
|
+
upsert(input) {
|
|
25
|
+
const snapshot = JSON.stringify(input);
|
|
26
|
+
return this.transport.request({
|
|
27
|
+
method: "POST",
|
|
28
|
+
path: "/v1/filament-catalog",
|
|
29
|
+
contentType: "application/json",
|
|
30
|
+
body: async () => snapshot,
|
|
31
|
+
idempotencyKey: encodeURIComponent(input.externalId),
|
|
32
|
+
replayable: true,
|
|
33
|
+
decode: async (response) => response.json()
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
list(input = {}) {
|
|
37
|
+
const query = new URLSearchParams();
|
|
38
|
+
for (const [key, value] of Object.entries(input))
|
|
39
|
+
if (value !== void 0) query.set(key, String(value));
|
|
40
|
+
return this.transport.request({
|
|
41
|
+
method: "GET",
|
|
42
|
+
path: "/v1/filament-catalog",
|
|
43
|
+
query,
|
|
44
|
+
decode: async (response) => response.json()
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
get(id) {
|
|
48
|
+
return this.transport.request({
|
|
49
|
+
method: "GET",
|
|
50
|
+
path: `/v1/filament-catalog/${encodeURIComponent(id)}`,
|
|
51
|
+
decode: async (response) => response.json()
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
14
55
|
|
|
15
56
|
// src/transport.ts
|
|
16
57
|
var MAX_RETRY_AFTER_MS = 6e4;
|
|
@@ -117,7 +158,7 @@ var Transport = class {
|
|
|
117
158
|
}
|
|
118
159
|
};
|
|
119
160
|
function retryDelay(failure, replayable, attempt, maxRetries) {
|
|
120
|
-
const retryable = failure instanceof PrintHiveApiError ? failure.status === 429 || failure.status === 503 : failure.reason === "network";
|
|
161
|
+
const retryable = failure instanceof PrintHiveApiError ? failure.code !== "preparation_disabled" && (failure.status === 429 || failure.status === 503) : failure.reason === "network";
|
|
121
162
|
if (!retryable || !replayable || attempt >= maxRetries) throw failure;
|
|
122
163
|
const retryAfterMs = failure instanceof PrintHiveApiError ? failure.retryAfterMs ?? 0 : 0;
|
|
123
164
|
if (retryAfterMs > MAX_RETRY_AFTER_MS) throw failure;
|
|
@@ -146,6 +187,19 @@ var PrintJobs = class {
|
|
|
146
187
|
constructor(transport) {
|
|
147
188
|
this.transport = transport;
|
|
148
189
|
}
|
|
190
|
+
async get(id, signal) {
|
|
191
|
+
if (!Number.isSafeInteger(id) || id < 1)
|
|
192
|
+
throw new RangeError("Print job id must be a positive safe integer");
|
|
193
|
+
const response = await this.transport.request({
|
|
194
|
+
method: "GET",
|
|
195
|
+
path: `/v1/print-jobs/${id}`,
|
|
196
|
+
signal,
|
|
197
|
+
decode: (response2) => decode(response2, jobSnapshot)
|
|
198
|
+
});
|
|
199
|
+
if (response.job.id !== id)
|
|
200
|
+
throw new TypeError("Invalid Print Hive API response");
|
|
201
|
+
return response.job;
|
|
202
|
+
}
|
|
149
203
|
async create(input) {
|
|
150
204
|
const { idempotencyKey: suppliedKey, ...bodyInput } = input;
|
|
151
205
|
const idempotencyKey = suppliedKey ?? crypto.randomUUID();
|
|
@@ -242,15 +296,73 @@ var PrintHive = class {
|
|
|
242
296
|
models;
|
|
243
297
|
printers;
|
|
244
298
|
printJobs;
|
|
299
|
+
filamentCatalog;
|
|
300
|
+
preparations;
|
|
245
301
|
constructor(options) {
|
|
246
302
|
const transport = new Transport(options);
|
|
247
303
|
this.printJobs = new PrintJobs(transport);
|
|
304
|
+
this.filamentCatalog = new FilamentCatalog(transport);
|
|
248
305
|
const get = (sourceId, signal) => transport.request({
|
|
249
306
|
decode: (response) => decode2(response, source),
|
|
250
307
|
method: "GET",
|
|
251
308
|
path: `${prefix}/uploads/${encodeURIComponent(sourceId)}`,
|
|
252
309
|
signal
|
|
253
310
|
});
|
|
311
|
+
const getPreparation = (id, signal) => transport.request({
|
|
312
|
+
decode: (response) => decode2(response, preparation),
|
|
313
|
+
method: "GET",
|
|
314
|
+
path: `${prefix}/preparations/${encodeURIComponent(id)}`,
|
|
315
|
+
signal
|
|
316
|
+
});
|
|
317
|
+
this.preparations = {
|
|
318
|
+
get: getPreparation,
|
|
319
|
+
async create(input) {
|
|
320
|
+
const idempotencyKey = input.idempotencyKey ?? crypto.randomUUID();
|
|
321
|
+
const snapshot = JSON.stringify({ items: input.items });
|
|
322
|
+
if (!preparationInput(JSON.parse(snapshot)))
|
|
323
|
+
throw new TypeError("Invalid preparation input");
|
|
324
|
+
const preparation2 = await transport.request({
|
|
325
|
+
decode: (response) => decode2(response, preparation),
|
|
326
|
+
method: "POST",
|
|
327
|
+
path: `${prefix}/preparations`,
|
|
328
|
+
contentType: "application/json",
|
|
329
|
+
body: async () => snapshot,
|
|
330
|
+
size: new TextEncoder().encode(snapshot).byteLength,
|
|
331
|
+
idempotencyKey,
|
|
332
|
+
replayable: true,
|
|
333
|
+
signal: input.signal
|
|
334
|
+
});
|
|
335
|
+
return { ...preparation2, idempotencyKey };
|
|
336
|
+
},
|
|
337
|
+
async waitUntilSettled(id, options2 = {}) {
|
|
338
|
+
const interval = positive(options2.intervalMs ?? 1e3, "intervalMs");
|
|
339
|
+
const deadline = AbortSignal.timeout(
|
|
340
|
+
positive(options2.timeoutMs ?? 12e4, "timeoutMs")
|
|
341
|
+
);
|
|
342
|
+
const signal = options2.signal ? AbortSignal.any([options2.signal, deadline]) : deadline;
|
|
343
|
+
try {
|
|
344
|
+
for (; ; ) {
|
|
345
|
+
const preparation2 = await getPreparation(id, signal);
|
|
346
|
+
const status = preparation2.status;
|
|
347
|
+
if (status === "ready" || status === "held" || status === "failed")
|
|
348
|
+
return { ...preparation2, status };
|
|
349
|
+
await pause(interval, signal);
|
|
350
|
+
}
|
|
351
|
+
} catch (error) {
|
|
352
|
+
if (deadline.aborted && !options2.signal?.aborted) {
|
|
353
|
+
const { PrintHiveNetworkError: PrintHiveNetworkError2 } = await import("./errors-GNC6X3MK.js");
|
|
354
|
+
throw new PrintHiveNetworkError2("timeout");
|
|
355
|
+
}
|
|
356
|
+
throw error;
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
downloadInfo: (id, plateId, signal) => transport.request({
|
|
360
|
+
decode: (response) => decode2(response, preparationDownload),
|
|
361
|
+
method: "GET",
|
|
362
|
+
path: `${prefix}/preparations/${encodeURIComponent(id)}/plates/${encodeURIComponent(plateId)}/download`,
|
|
363
|
+
signal
|
|
364
|
+
})
|
|
365
|
+
};
|
|
254
366
|
this.printers = {
|
|
255
367
|
list: (input = {}) => {
|
|
256
368
|
const query = new URLSearchParams();
|
|
@@ -328,7 +440,7 @@ var PrintHive = class {
|
|
|
328
440
|
}
|
|
329
441
|
} catch (error) {
|
|
330
442
|
if (deadline.aborted && !options2.signal?.aborted) {
|
|
331
|
-
const { PrintHiveNetworkError: PrintHiveNetworkError2 } = await import("./errors-
|
|
443
|
+
const { PrintHiveNetworkError: PrintHiveNetworkError2 } = await import("./errors-GNC6X3MK.js");
|
|
332
444
|
throw new PrintHiveNetworkError2("timeout");
|
|
333
445
|
}
|
|
334
446
|
throw error;
|