@printhive/api 0.3.2 → 0.4.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/CHANGELOG.md +13 -0
- package/README.md +146 -5
- package/dist/{chunk-YZJ5H32X.js → chunk-GOUMDFJR.js} +13520 -6769
- package/dist/{errors-GNC6X3MK.js → errors-4M56UUFV.js} +1 -1
- package/dist/index.cjs +15054 -8248
- package/dist/index.d.cts +1167 -151
- package/dist/index.d.ts +1167 -151
- package/dist/index.js +123 -63
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
apiError,
|
|
5
5
|
apiKey,
|
|
6
6
|
createRequest,
|
|
7
|
+
filamentSearch,
|
|
7
8
|
jobSnapshot,
|
|
8
9
|
model,
|
|
9
10
|
page,
|
|
@@ -12,46 +13,11 @@ import {
|
|
|
12
13
|
preparationInput,
|
|
13
14
|
printJob,
|
|
14
15
|
printer,
|
|
16
|
+
printerSearch,
|
|
15
17
|
printers,
|
|
18
|
+
reviewApproval,
|
|
16
19
|
source
|
|
17
|
-
} from "./chunk-
|
|
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
|
-
};
|
|
20
|
+
} from "./chunk-GOUMDFJR.js";
|
|
55
21
|
|
|
56
22
|
// src/transport.ts
|
|
57
23
|
var MAX_RETRY_AFTER_MS = 6e4;
|
|
@@ -165,6 +131,86 @@ function retryDelay(failure, replayable, attempt, maxRetries) {
|
|
|
165
131
|
const backoff = Math.min(3e4, 250 * 2 ** attempt) * (0.5 + Math.random());
|
|
166
132
|
return Math.max(backoff, retryAfterMs);
|
|
167
133
|
}
|
|
134
|
+
async function decode(response, validate) {
|
|
135
|
+
const value = await response.json().catch((error) => {
|
|
136
|
+
if (error instanceof SyntaxError)
|
|
137
|
+
throw new TypeError("Invalid Print Hive API response");
|
|
138
|
+
throw error;
|
|
139
|
+
});
|
|
140
|
+
if (!validate(value)) throw new TypeError("Invalid Print Hive API response");
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/search.ts
|
|
145
|
+
function searchQuery(input) {
|
|
146
|
+
const query = new URLSearchParams({ q: input.query });
|
|
147
|
+
if (input.limit !== void 0) query.set("limit", String(input.limit));
|
|
148
|
+
if (input.offset !== void 0) query.set("offset", String(input.offset));
|
|
149
|
+
return query;
|
|
150
|
+
}
|
|
151
|
+
var ResourceSearch = class {
|
|
152
|
+
constructor(transport) {
|
|
153
|
+
this.transport = transport;
|
|
154
|
+
}
|
|
155
|
+
async printers(input) {
|
|
156
|
+
const query = searchQuery(input);
|
|
157
|
+
const page2 = await this.transport.request({
|
|
158
|
+
method: "GET",
|
|
159
|
+
path: "/v1/printers/search",
|
|
160
|
+
query,
|
|
161
|
+
signal: input.signal,
|
|
162
|
+
decode: (response) => decode(response, printerSearch)
|
|
163
|
+
});
|
|
164
|
+
return page2;
|
|
165
|
+
}
|
|
166
|
+
async filaments(input) {
|
|
167
|
+
const page2 = await this.transport.request({
|
|
168
|
+
method: "GET",
|
|
169
|
+
path: "/v1/filaments/search",
|
|
170
|
+
query: searchQuery(input),
|
|
171
|
+
signal: input.signal,
|
|
172
|
+
decode: (response) => decode(response, filamentSearch)
|
|
173
|
+
});
|
|
174
|
+
return page2;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// src/filament-catalog.ts
|
|
179
|
+
var FilamentCatalog = class {
|
|
180
|
+
constructor(transport) {
|
|
181
|
+
this.transport = transport;
|
|
182
|
+
}
|
|
183
|
+
upsert(input) {
|
|
184
|
+
const snapshot = JSON.stringify(input);
|
|
185
|
+
return this.transport.request({
|
|
186
|
+
method: "POST",
|
|
187
|
+
path: "/v1/filament-catalog",
|
|
188
|
+
contentType: "application/json",
|
|
189
|
+
body: async () => snapshot,
|
|
190
|
+
idempotencyKey: encodeURIComponent(input.externalId),
|
|
191
|
+
replayable: true,
|
|
192
|
+
decode: async (response) => response.json()
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
list(input = {}) {
|
|
196
|
+
const query = new URLSearchParams();
|
|
197
|
+
for (const [key, value] of Object.entries(input))
|
|
198
|
+
if (value !== void 0) query.set(key, String(value));
|
|
199
|
+
return this.transport.request({
|
|
200
|
+
method: "GET",
|
|
201
|
+
path: "/v1/filament-catalog",
|
|
202
|
+
query,
|
|
203
|
+
decode: async (response) => response.json()
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
get(id) {
|
|
207
|
+
return this.transport.request({
|
|
208
|
+
method: "GET",
|
|
209
|
+
path: `/v1/filament-catalog/${encodeURIComponent(id)}`,
|
|
210
|
+
decode: async (response) => response.json()
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
};
|
|
168
214
|
|
|
169
215
|
// src/print-jobs.ts
|
|
170
216
|
var PrintJobCreateStoppedError = class extends Error {
|
|
@@ -174,7 +220,7 @@ var PrintJobCreateStoppedError = class extends Error {
|
|
|
174
220
|
this.name = "PrintJobCreateStoppedError";
|
|
175
221
|
}
|
|
176
222
|
};
|
|
177
|
-
async function
|
|
223
|
+
async function decode2(response, validate) {
|
|
178
224
|
const value = await response.json().catch((error) => {
|
|
179
225
|
if (error instanceof SyntaxError)
|
|
180
226
|
throw new TypeError("Invalid Print Hive API response");
|
|
@@ -194,7 +240,7 @@ var PrintJobs = class {
|
|
|
194
240
|
method: "GET",
|
|
195
241
|
path: `/v1/print-jobs/${id}`,
|
|
196
242
|
signal,
|
|
197
|
-
decode: (response2) =>
|
|
243
|
+
decode: (response2) => decode2(response2, jobSnapshot)
|
|
198
244
|
});
|
|
199
245
|
if (response.job.id !== id)
|
|
200
246
|
throw new TypeError("Invalid Print Hive API response");
|
|
@@ -225,6 +271,11 @@ var PrintJobs = class {
|
|
|
225
271
|
})) {
|
|
226
272
|
if (value !== void 0) form.set(field, value);
|
|
227
273
|
}
|
|
274
|
+
if (metadata.acceptEngineSettingUpdates !== void 0)
|
|
275
|
+
form.set(
|
|
276
|
+
"acceptEngineSettingUpdates",
|
|
277
|
+
JSON.stringify(metadata.acceptEngineSettingUpdates)
|
|
278
|
+
);
|
|
228
279
|
form.set("plate", String(metadata.plate));
|
|
229
280
|
form.set("filaments", JSON.stringify(metadata.filaments));
|
|
230
281
|
if (metadata.print_options !== void 0)
|
|
@@ -232,7 +283,7 @@ var PrintJobs = class {
|
|
|
232
283
|
form.set("file", new Blob([bytes]), filename);
|
|
233
284
|
return form;
|
|
234
285
|
},
|
|
235
|
-
decode: (response3) =>
|
|
286
|
+
decode: (response3) => decode2(response3, createRequest)
|
|
236
287
|
});
|
|
237
288
|
return { ...response2, idempotencyKey };
|
|
238
289
|
}
|
|
@@ -243,7 +294,7 @@ var PrintJobs = class {
|
|
|
243
294
|
replayable: true,
|
|
244
295
|
contentType: "application/json",
|
|
245
296
|
body: async () => JSON.stringify(bodyInput),
|
|
246
|
-
decode: (response2) =>
|
|
297
|
+
decode: (response2) => decode2(response2, printJob)
|
|
247
298
|
});
|
|
248
299
|
return { ...response, idempotencyKey };
|
|
249
300
|
}
|
|
@@ -252,7 +303,19 @@ var PrintJobs = class {
|
|
|
252
303
|
method: "GET",
|
|
253
304
|
path: `/v1/print-jobs/create-requests/${encodeURIComponent(requestId)}`,
|
|
254
305
|
signal,
|
|
255
|
-
decode: (response) =>
|
|
306
|
+
decode: (response) => decode2(response, createRequest)
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
approveReview(requestId, review, signal) {
|
|
310
|
+
return this.transport.request({
|
|
311
|
+
method: "POST",
|
|
312
|
+
path: `/v1/print-jobs/create-requests/${encodeURIComponent(requestId)}/approve-review`,
|
|
313
|
+
signal,
|
|
314
|
+
idempotencyKey: crypto.randomUUID(),
|
|
315
|
+
replayable: false,
|
|
316
|
+
contentType: "application/json",
|
|
317
|
+
body: async () => JSON.stringify(review),
|
|
318
|
+
decode: (response) => decode2(response, reviewApproval)
|
|
256
319
|
});
|
|
257
320
|
}
|
|
258
321
|
async waitUntilCreated(requestId, options = {}) {
|
|
@@ -278,15 +341,6 @@ var PrintJobs = class {
|
|
|
278
341
|
};
|
|
279
342
|
|
|
280
343
|
// src/index.ts
|
|
281
|
-
async function decode2(response, validate) {
|
|
282
|
-
const value = await response.json().catch((error) => {
|
|
283
|
-
if (error instanceof SyntaxError)
|
|
284
|
-
throw new TypeError("Invalid Print Hive API response");
|
|
285
|
-
throw error;
|
|
286
|
-
});
|
|
287
|
-
if (!validate(value)) throw new TypeError("Invalid Print Hive API response");
|
|
288
|
-
return value;
|
|
289
|
-
}
|
|
290
344
|
function isPath(file) {
|
|
291
345
|
return !(file instanceof Uint8Array) && !(file instanceof ReadableStream);
|
|
292
346
|
}
|
|
@@ -297,19 +351,24 @@ var PrintHive = class {
|
|
|
297
351
|
printers;
|
|
298
352
|
printJobs;
|
|
299
353
|
filamentCatalog;
|
|
354
|
+
filaments;
|
|
300
355
|
preparations;
|
|
301
356
|
constructor(options) {
|
|
302
357
|
const transport = new Transport(options);
|
|
358
|
+
const search = new ResourceSearch(transport);
|
|
359
|
+
this.filaments = {
|
|
360
|
+
search: (input) => search.filaments(input)
|
|
361
|
+
};
|
|
303
362
|
this.printJobs = new PrintJobs(transport);
|
|
304
363
|
this.filamentCatalog = new FilamentCatalog(transport);
|
|
305
364
|
const get = (sourceId, signal) => transport.request({
|
|
306
|
-
decode: (response) =>
|
|
365
|
+
decode: (response) => decode(response, source),
|
|
307
366
|
method: "GET",
|
|
308
367
|
path: `${prefix}/uploads/${encodeURIComponent(sourceId)}`,
|
|
309
368
|
signal
|
|
310
369
|
});
|
|
311
370
|
const getPreparation = (id, signal) => transport.request({
|
|
312
|
-
decode: (response) =>
|
|
371
|
+
decode: (response) => decode(response, preparation),
|
|
313
372
|
method: "GET",
|
|
314
373
|
path: `${prefix}/preparations/${encodeURIComponent(id)}`,
|
|
315
374
|
signal
|
|
@@ -322,7 +381,7 @@ var PrintHive = class {
|
|
|
322
381
|
if (!preparationInput(JSON.parse(snapshot)))
|
|
323
382
|
throw new TypeError("Invalid preparation input");
|
|
324
383
|
const preparation2 = await transport.request({
|
|
325
|
-
decode: (response) =>
|
|
384
|
+
decode: (response) => decode(response, preparation),
|
|
326
385
|
method: "POST",
|
|
327
386
|
path: `${prefix}/preparations`,
|
|
328
387
|
contentType: "application/json",
|
|
@@ -350,33 +409,34 @@ var PrintHive = class {
|
|
|
350
409
|
}
|
|
351
410
|
} catch (error) {
|
|
352
411
|
if (deadline.aborted && !options2.signal?.aborted) {
|
|
353
|
-
const { PrintHiveNetworkError: PrintHiveNetworkError2 } = await import("./errors-
|
|
412
|
+
const { PrintHiveNetworkError: PrintHiveNetworkError2 } = await import("./errors-4M56UUFV.js");
|
|
354
413
|
throw new PrintHiveNetworkError2("timeout");
|
|
355
414
|
}
|
|
356
415
|
throw error;
|
|
357
416
|
}
|
|
358
417
|
},
|
|
359
418
|
downloadInfo: (id, plateId, signal) => transport.request({
|
|
360
|
-
decode: (response) =>
|
|
419
|
+
decode: (response) => decode(response, preparationDownload),
|
|
361
420
|
method: "GET",
|
|
362
421
|
path: `${prefix}/preparations/${encodeURIComponent(id)}/plates/${encodeURIComponent(plateId)}/download`,
|
|
363
422
|
signal
|
|
364
423
|
})
|
|
365
424
|
};
|
|
366
425
|
this.printers = {
|
|
426
|
+
search: (input) => search.printers(input),
|
|
367
427
|
list: (input = {}) => {
|
|
368
428
|
const query = new URLSearchParams();
|
|
369
429
|
if (input.limit !== void 0) query.set("limit", String(input.limit));
|
|
370
430
|
if (input.cursor !== void 0) query.set("cursor", input.cursor);
|
|
371
431
|
return transport.request({
|
|
372
|
-
decode: (response) =>
|
|
432
|
+
decode: (response) => decode(response, printers),
|
|
373
433
|
method: "GET",
|
|
374
434
|
path: "/v1/printers",
|
|
375
435
|
query
|
|
376
436
|
});
|
|
377
437
|
},
|
|
378
438
|
get: (id) => transport.request({
|
|
379
|
-
decode: (response) =>
|
|
439
|
+
decode: (response) => decode(response, printer),
|
|
380
440
|
method: "GET",
|
|
381
441
|
path: `/v1/printers/${encodeURIComponent(id)}`
|
|
382
442
|
})
|
|
@@ -414,7 +474,7 @@ var PrintHive = class {
|
|
|
414
474
|
if (!Number.isSafeInteger(size) || size < 0)
|
|
415
475
|
throw new RangeError("size must be a nonnegative safe integer");
|
|
416
476
|
const source2 = await transport.request({
|
|
417
|
-
decode: (response) =>
|
|
477
|
+
decode: (response) => decode(response, source),
|
|
418
478
|
method: "POST",
|
|
419
479
|
path: `${prefix}/uploads`,
|
|
420
480
|
query,
|
|
@@ -440,7 +500,7 @@ var PrintHive = class {
|
|
|
440
500
|
}
|
|
441
501
|
} catch (error) {
|
|
442
502
|
if (deadline.aborted && !options2.signal?.aborted) {
|
|
443
|
-
const { PrintHiveNetworkError: PrintHiveNetworkError2 } = await import("./errors-
|
|
503
|
+
const { PrintHiveNetworkError: PrintHiveNetworkError2 } = await import("./errors-4M56UUFV.js");
|
|
444
504
|
throw new PrintHiveNetworkError2("timeout");
|
|
445
505
|
}
|
|
446
506
|
throw error;
|
|
@@ -449,7 +509,7 @@ var PrintHive = class {
|
|
|
449
509
|
};
|
|
450
510
|
this.models = {
|
|
451
511
|
findByExternalId: (externalId) => transport.request({
|
|
452
|
-
decode: (response) =>
|
|
512
|
+
decode: (response) => decode(response, model),
|
|
453
513
|
method: "GET",
|
|
454
514
|
path: `${prefix}/models`,
|
|
455
515
|
query: new URLSearchParams({ externalId })
|
|
@@ -460,7 +520,7 @@ var PrintHive = class {
|
|
|
460
520
|
const query = new URLSearchParams();
|
|
461
521
|
if (cursor !== null) query.set("cursor", cursor);
|
|
462
522
|
const page2 = await transport.request({
|
|
463
|
-
decode: (response) =>
|
|
523
|
+
decode: (response) => decode(response, page),
|
|
464
524
|
method: "GET",
|
|
465
525
|
path: `${prefix}/models/${encodeURIComponent(modelId)}/files`,
|
|
466
526
|
query
|