@printy3d/sdk 0.0.0-stage → 0.4.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.
Files changed (47) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +85 -2
  3. package/dist/cad-documents.d.ts +169 -0
  4. package/dist/cad-documents.d.ts.map +1 -0
  5. package/dist/cad-documents.js +17 -0
  6. package/dist/cad-documents.js.map +1 -0
  7. package/dist/client.d.ts +116 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +165 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/errors.d.ts +125 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +202 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/http.d.ts +70 -0
  16. package/dist/http.d.ts.map +1 -0
  17. package/dist/http.js +291 -0
  18. package/dist/http.js.map +1 -0
  19. package/dist/index.d.ts +20 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +19 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/resources.d.ts +222 -0
  24. package/dist/resources.d.ts.map +1 -0
  25. package/dist/resources.js +629 -0
  26. package/dist/resources.js.map +1 -0
  27. package/dist/runtime.d.ts +30 -0
  28. package/dist/runtime.d.ts.map +1 -0
  29. package/dist/runtime.js +88 -0
  30. package/dist/runtime.js.map +1 -0
  31. package/dist/sources.d.ts +13 -0
  32. package/dist/sources.d.ts.map +1 -0
  33. package/dist/sources.js +82 -0
  34. package/dist/sources.js.map +1 -0
  35. package/dist/types.d.ts +776 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +18 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/version.d.ts +2 -0
  40. package/dist/version.d.ts.map +1 -0
  41. package/dist/version.js +2 -0
  42. package/dist/version.js.map +1 -0
  43. package/dist/webhooks.d.ts +24 -0
  44. package/dist/webhooks.d.ts.map +1 -0
  45. package/dist/webhooks.js +95 -0
  46. package/dist/webhooks.js.map +1 -0
  47. package/package.json +48 -4
package/dist/client.js ADDED
@@ -0,0 +1,165 @@
1
+ /** The `Printy3D` client: configuration, resource groups and the high-level helpers. */
2
+ import { Printy3DError } from "./errors.js";
3
+ import { Transport } from "./http.js";
4
+ import { ApiKeys, Artifacts, BalanceResource, Exports, Files, Formats, Jobs, Org, Profiles, Technologies, WebhookEndpoints, defaultFilename, settledExport, } from "./resources.js";
5
+ import { verifyWebhook } from "./webhooks.js";
6
+ import { env, nodeFsPromises, nodePath, sleep as realSleep } from "./runtime.js";
7
+ /** The Printy3D API (beta). */
8
+ export const DEFAULT_BASE_URL = "https://api.printy3d.ai";
9
+ const FILE_ID = /^file_[0-9A-HJKMNP-TV-Z]{26}$/;
10
+ /** Client for the Printy3D `/v1` API. */
11
+ export class Printy3D {
12
+ baseUrl;
13
+ org;
14
+ formats;
15
+ profiles;
16
+ apiKeys;
17
+ files;
18
+ jobs;
19
+ artifacts;
20
+ exports;
21
+ balance;
22
+ technologies;
23
+ webhookEndpoints;
24
+ /** Receiver helpers: `webhooks.verify(rawBody, header, secret)`. */
25
+ webhooks = { verify: verifyWebhook };
26
+ transport;
27
+ constructor(options = {}) {
28
+ const apiKey = (options.apiKey ?? env("PRINTY3D_API_KEY") ?? "").trim();
29
+ if (!apiKey) {
30
+ throw new Printy3DError("No API key: pass { apiKey } or set the PRINTY3D_API_KEY environment variable");
31
+ }
32
+ let baseUrl = (options.baseUrl ?? env("PRINTY3D_API_URL") ?? DEFAULT_BASE_URL).trim().replace(/\/+$/, "");
33
+ if (baseUrl.endsWith("/v1"))
34
+ baseUrl = baseUrl.slice(0, -3);
35
+ this.baseUrl = baseUrl;
36
+ const fetchImpl = options.fetch ?? globalThis.fetch?.bind(globalThis);
37
+ if (!fetchImpl)
38
+ throw new Printy3DError("No global fetch: use Node 18+ or pass { fetch }");
39
+ this.transport = new Transport({
40
+ apiKey,
41
+ baseUrl,
42
+ timeoutMs: options.timeoutMs ?? 150_000,
43
+ transferTimeoutMs: options.transferTimeoutMs ?? 120_000,
44
+ maxRetries: options.maxRetries ?? 4,
45
+ maxRetryDelayMs: options.maxRetryDelayMs ?? 60_000,
46
+ userAgent: options.userAgent,
47
+ fetch: fetchImpl,
48
+ sleep: options.sleep ?? realSleep,
49
+ random: options.random ?? Math.random,
50
+ });
51
+ // The key lives only inside the transport; keep it out of logs and inspection.
52
+ Object.defineProperty(this, "transport", { enumerable: false });
53
+ this.org = new Org(this.transport);
54
+ this.formats = new Formats(this.transport);
55
+ this.profiles = new Profiles(this.transport);
56
+ this.apiKeys = new ApiKeys(this.transport);
57
+ this.files = new Files(this.transport);
58
+ this.jobs = new Jobs(this.transport);
59
+ this.artifacts = new Artifacts(this.transport);
60
+ this.exports = new Exports(this.transport);
61
+ this.balance = new BalanceResource(this.transport);
62
+ this.technologies = new Technologies(this.transport);
63
+ this.webhookEndpoints = new WebhookEndpoints(this.transport);
64
+ }
65
+ toJSON() {
66
+ return { baseUrl: this.baseUrl };
67
+ }
68
+ // --- Uploads -----------------------------------------------------------------------
69
+ /** Upload and return the file `ready`. See `Files.upload`. */
70
+ upload(source, options = {}) {
71
+ return this.files.upload(source, options);
72
+ }
73
+ async fileId(source, options) {
74
+ if (typeof source === "string" && FILE_ID.test(source))
75
+ return source;
76
+ if (isFile(source))
77
+ return source.id;
78
+ return (await this.files.upload(source, options ?? {})).id;
79
+ }
80
+ // --- Jobs --------------------------------------------------------------------------
81
+ /**
82
+ * Upload `source` when needed, create a job and wait for it. `source` is a path (Node),
83
+ * bytes, a Blob, an uploaded `File` or a `file_...` id.
84
+ */
85
+ async run(source, body, options = {}) {
86
+ const inputFileId = await this.fileId(source, options.upload);
87
+ const request = { input_file_id: inputFileId, recipe: body.recipe ?? "inspect" };
88
+ if (body.tool !== undefined)
89
+ request["tool"] = body.tool;
90
+ if (body.params !== undefined && body.params !== null)
91
+ request["params"] = body.params;
92
+ if (body.notify !== undefined && body.notify !== null)
93
+ request["notify"] = body.notify;
94
+ const job = await this.jobs.create(request, options);
95
+ if (options.wait === false)
96
+ return job;
97
+ return this.jobs.wait(job.id, options);
98
+ }
99
+ /**
100
+ * Analysis of the mesh: `job.analysis` (dimensions, volume, watertightness, recommended
101
+ * repair params) plus thumbnails, preview and report artifacts.
102
+ */
103
+ inspect(source, options = {}) {
104
+ return this.run(source, { recipe: "inspect" }, options);
105
+ }
106
+ /**
107
+ * Repair for print. `profile` chooses where unset params come from (`recommended` by
108
+ * default); every field of `params` overrides that field.
109
+ */
110
+ repair(source, options = {}) {
111
+ const params = { ...(options.params ?? {}) };
112
+ if (options.profile !== undefined)
113
+ params.profile = options.profile;
114
+ return this.run(source, { recipe: "repair", ...(Object.keys(params).length ? { params } : {}) }, options);
115
+ }
116
+ /** Run one tool (`cut`, `measure`, `convert`, ...) with its params. */
117
+ tool(source, tool, params, options = {}) {
118
+ return this.run(source, { recipe: "tool", tool, ...(params !== undefined ? { params } : {}) }, options);
119
+ }
120
+ // --- Artifacts and exports ---------------------------------------------------------
121
+ /** Save one artifact, verified (Node). `dest` is a file path or a directory. */
122
+ download(artifact, dest = ".", options = {}) {
123
+ return this.artifacts.download(artifact, dest, options);
124
+ }
125
+ /**
126
+ * Save every artifact of a succeeded job (or only `labels`) into `destDir` as
127
+ * `<label><ext>`, each verified against its size and SHA-256 (Node).
128
+ */
129
+ async downloadArtifacts(jobId, destDir, options = {}) {
130
+ const [fs, path] = await Promise.all([nodeFsPromises(), nodePath()]);
131
+ await fs.mkdir(destDir, { recursive: true });
132
+ const wanted = options.labels ? new Set(options.labels) : undefined;
133
+ const saved = [];
134
+ for (const artifact of await this.artifacts.list(jobId, options)) {
135
+ if (wanted && !wanted.has(artifact.label))
136
+ continue;
137
+ const target = path.join(destDir, defaultFilename(artifact));
138
+ saved.push({ artifact, path: await this.artifacts.download(artifact, target, options) });
139
+ }
140
+ return saved;
141
+ }
142
+ /**
143
+ * Ask for the job's output in `format`; by default poll until `ready`. A format the job
144
+ * did not generate starts one conversion job on the GPU fleet, held and charged like any
145
+ * `convert` job (test keys: `501`). Download with `client.download(export.artifact!, dir)`.
146
+ */
147
+ async export(jobId, format, options = {}) {
148
+ const exported = await this.exports.create(jobId, format, options);
149
+ if (exported.status === "failed")
150
+ return settledExport(exported);
151
+ if (options.wait === false || exported.status === "ready")
152
+ return exported;
153
+ return this.exports.wait(jobId, format, options);
154
+ }
155
+ }
156
+ function isFile(value) {
157
+ return (!!value &&
158
+ typeof value === "object" &&
159
+ !(value instanceof Uint8Array) &&
160
+ !(value instanceof ArrayBuffer) &&
161
+ !(typeof Blob !== "undefined" && value instanceof Blob) &&
162
+ typeof value.id === "string" &&
163
+ typeof value.status === "string");
164
+ }
165
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,wFAAwF;AAExF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAkB,MAAM,WAAW,CAAC;AACtD,OAAO,EACL,OAAO,EACP,SAAS,EACT,eAAe,EACf,OAAO,EACP,KAAK,EACL,OAAO,EACP,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,aAAa,GAMd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AAejF,+BAA+B;AAC/B,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAC1D,MAAM,OAAO,GAAG,+BAA+B,CAAC;AA6ChD,yCAAyC;AACzC,MAAM,OAAO,QAAQ;IACV,OAAO,CAAS;IAChB,GAAG,CAAM;IACT,OAAO,CAAU;IACjB,QAAQ,CAAW;IACnB,OAAO,CAAU;IACjB,KAAK,CAAQ;IACb,I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AAK,CAAC,MAAM,CAAC,KAAa,EAAE,MAAoB,EAAE,UAAyB,EAAE;QAC3E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACnE,IAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ;YAAE,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC;QACjE,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,IAAI,QAAQ,CAAC,MAAM,KAAK,OAAO;YAAE,OAAO,QAAQ,CAAC;QAC3E,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACF;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC;QAC9B,CAAC,CAAC,KAAK,YAAY,WAAW,CAAC;QAC/B,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI,CAAC;QACvD,OAAQ,KAA0B,CAAC,EAAE,KAAK,QAAQ;QAClD,OAAQ,KAA8B,CAAC,MAAM,KAAK,QAAQ,CAC3D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * The one error type of the SDK, and the few non-HTTP outcomes built on it.
3
+ *
4
+ * Every HTTP error the API returns is an RFC 9457 `application/problem+json` body
5
+ * (`spec/openapi.json` `Problem`): `type`, `title`, `status`, `code`, `detail`, `instance`,
6
+ * `errors[]`, `request_id`, plus code-specific extras such as `required` and `available` on
7
+ * `insufficient_credits`. `Printy3DError` carries all of them; branch on `code`.
8
+ */
9
+ import type { Export, File, Job, ProblemField } from "./types.js";
10
+ export interface Printy3DErrorInit {
11
+ status?: number | undefined;
12
+ code?: string | undefined;
13
+ type?: string | undefined;
14
+ title?: string | undefined;
15
+ detail?: string | undefined;
16
+ instance?: string | undefined;
17
+ errors?: ProblemField[] | undefined;
18
+ requestId?: string | undefined;
19
+ /** Seconds from the `Retry-After` header. */
20
+ retryAfter?: number | undefined;
21
+ extra?: Record<string, unknown> | undefined;
22
+ headers?: Record<string, string> | undefined;
23
+ body?: Record<string, unknown> | undefined;
24
+ cause?: unknown;
25
+ }
26
+ /** An error from the Printy3D API or from an SDK helper. */
27
+ export declare class Printy3DError extends Error {
28
+ /**
29
+ * The class name, set explicitly on every error class so it survives bundlers and minifiers
30
+ * that rename or strip class names. Prefer `instanceof`; this is for logs and plain checks.
31
+ */
32
+ readonly name: string;
33
+ /** HTTP status, or `undefined` when no HTTP response produced the error. */
34
+ readonly status: number | undefined;
35
+ /**
36
+ * The problem `code` (`insufficient_credits`, `not_found`, ...), a job's `error_code`,
37
+ * a file's `rejected_reason` or an export's `error_code`.
38
+ */
39
+ readonly code: string | undefined;
40
+ readonly type: string | undefined;
41
+ readonly title: string | undefined;
42
+ readonly detail: string | undefined;
43
+ readonly instance: string | undefined;
44
+ /** Field-level validation failures. */
45
+ readonly errors: ProblemField[];
46
+ /** The `X-Request-Id` response header, else the body's `request_id`. */
47
+ readonly requestId: string | undefined;
48
+ /** Seconds from the `Retry-After` header, when present. */
49
+ readonly retryAfter: number | undefined;
50
+ /** Code-specific fields of the problem body (`required`, `available`, `reason`, ...). */
51
+ readonly extra: Record<string, unknown>;
52
+ /** Response headers, lower-cased names. */
53
+ readonly headers: Record<string, string>;
54
+ /** The parsed problem body, or `undefined` when the response was not JSON. */
55
+ readonly body: Record<string, unknown> | undefined;
56
+ constructor(message: string, init?: Printy3DErrorInit);
57
+ /** `insufficient_credits`: the credits the job needs held. */
58
+ get required(): number | undefined;
59
+ /** `insufficient_credits`: the credits available now. */
60
+ get available(): number | undefined;
61
+ /** `insufficient_scope`: the scope the key lacks. */
62
+ get requiredScope(): string | undefined;
63
+ /** `capacity_exhausted`: `paused`, `spend_limit`, `no_gpu_available` or `controller_offline`. */
64
+ get reason(): string | undefined;
65
+ /** Build the error for a non-2xx response; a non-JSON body (an edge 502) is fine. */
66
+ static fromResponse(status: number, headers: Record<string, string>, text: string, retryAfter?: number): Printy3DError;
67
+ }
68
+ /** The request never produced an HTTP response (DNS, refused, reset, TLS). */
69
+ export declare class APIConnectionError extends Printy3DError {
70
+ readonly name: string;
71
+ }
72
+ /** The request timed out. A write may or may not have reached the API. */
73
+ export declare class APITimeoutError extends APIConnectionError {
74
+ readonly name: string;
75
+ }
76
+ /** A job ended without succeeding; `job` is its final state. */
77
+ export declare class JobError extends Printy3DError {
78
+ readonly name: string;
79
+ readonly job: Job;
80
+ constructor(message: string, job: Job);
81
+ }
82
+ /** The job ended `failed`; `code` is the job's `error_code`. */
83
+ export declare class JobFailedError extends JobError {
84
+ readonly name: string;
85
+ }
86
+ /** The job ended `cancelled`. */
87
+ export declare class JobCancelledError extends JobError {
88
+ readonly name: string;
89
+ }
90
+ /** A wait helper gave up; the job, verification or export continues server-side. */
91
+ export declare class WaitTimeoutError extends Printy3DError {
92
+ readonly name: string;
93
+ /** The last state seen (a Job, File or Export), or `undefined`. */
94
+ readonly last: unknown;
95
+ constructor(message: string, last?: unknown);
96
+ }
97
+ /** Upload verification rejected the file; `code` is its `rejected_reason`. */
98
+ export declare class FileRejectedError extends Printy3DError {
99
+ readonly name: string;
100
+ readonly file: File;
101
+ constructor(message: string, file: File);
102
+ }
103
+ /** The export's conversion failed; `code` is its `error_code`. Ask again to retry. */
104
+ export declare class ExportFailedError extends Printy3DError {
105
+ readonly name: string;
106
+ readonly export: Export;
107
+ constructor(message: string, exported: Export);
108
+ }
109
+ /** Downloaded bytes did not match the artifact's declared size or SHA-256. */
110
+ export declare class IntegrityError extends Printy3DError {
111
+ readonly name: string;
112
+ }
113
+ /** Upload parts were still missing after every resume round. */
114
+ export declare class UploadIncompleteError extends Printy3DError {
115
+ readonly name: string;
116
+ }
117
+ export type WebhookSignatureReason = "signature_mismatch" | "timestamp_out_of_tolerance" | "missing_header" | "malformed_header";
118
+ /** A webhook delivery failed verification; do not trust its body. */
119
+ export declare class WebhookSignatureError extends Printy3DError {
120
+ readonly name: string;
121
+ constructor(message: string, reason: WebhookSignatureReason);
122
+ /** Why verification failed. */
123
+ get reason(): WebhookSignatureReason;
124
+ }
125
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAalE,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC3C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAMD,4DAA4D;AAC5D,qBAAa,aAAc,SAAQ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AAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAI9C;AAED,8EAA8E;AAC9E,qBAAa,cAAe,SAAQ,aAAa;IAC/C,SAAkB,IAAI,EAAE,MAAM,CAAoB;CACnD;AAED,gEAAgE;AAChE,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,SAAkB,IAAI,EAAE,MAAM,CAA2B;CAC1D;AAED,MAAM,MAAM,sBAAsB,GAC9B,oBAAoB,GACpB,4BAA4B,GAC5B,gBAAgB,GAChB,kBAAkB,CAAC;AAEvB,qEAAqE;AACrE,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,SAAkB,IAAI,EAAE,MAAM,CAA2B;gBAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB;IAI3D,+BAA+B;IAC/B,IAAa,MAAM,IAAI,sBAAsB,CAE5C;CACF"}
package/dist/errors.js ADDED
@@ -0,0 +1,202 @@
1
+ /**
2
+ * The one error type of the SDK, and the few non-HTTP outcomes built on it.
3
+ *
4
+ * Every HTTP error the API returns is an RFC 9457 `application/problem+json` body
5
+ * (`spec/openapi.json` `Problem`): `type`, `title`, `status`, `code`, `detail`, `instance`,
6
+ * `errors[]`, `request_id`, plus code-specific extras such as `required` and `available` on
7
+ * `insufficient_credits`. `Printy3DError` carries all of them; branch on `code`.
8
+ */
9
+ const PROBLEM_FIELDS = new Set([
10
+ "type",
11
+ "title",
12
+ "status",
13
+ "detail",
14
+ "instance",
15
+ "code",
16
+ "errors",
17
+ "request_id",
18
+ ]);
19
+ function str(value) {
20
+ return typeof value === "string" ? value : undefined;
21
+ }
22
+ /** An error from the Printy3D API or from an SDK helper. */
23
+ export class Printy3DError extends Error {
24
+ /**
25
+ * The class name, set explicitly on every error class so it survives bundlers and minifiers
26
+ * that rename or strip class names. Prefer `instanceof`; this is for logs and plain checks.
27
+ */
28
+ name = "Printy3DError";
29
+ /** HTTP status, or `undefined` when no HTTP response produced the error. */
30
+ status;
31
+ /**
32
+ * The problem `code` (`insufficient_credits`, `not_found`, ...), a job's `error_code`,
33
+ * a file's `rejected_reason` or an export's `error_code`.
34
+ */
35
+ code;
36
+ type;
37
+ title;
38
+ detail;
39
+ instance;
40
+ /** Field-level validation failures. */
41
+ errors;
42
+ /** The `X-Request-Id` response header, else the body's `request_id`. */
43
+ requestId;
44
+ /** Seconds from the `Retry-After` header, when present. */
45
+ retryAfter;
46
+ /** Code-specific fields of the problem body (`required`, `available`, `reason`, ...). */
47
+ extra;
48
+ /** Response headers, lower-cased names. */
49
+ headers;
50
+ /** The parsed problem body, or `undefined` when the response was not JSON. */
51
+ body;
52
+ constructor(message, init = {}) {
53
+ super(message, init.cause === undefined ? undefined : { cause: init.cause });
54
+ this.status = init.status;
55
+ this.code = init.code;
56
+ this.type = init.type;
57
+ this.title = init.title;
58
+ this.detail = init.detail;
59
+ this.instance = init.instance;
60
+ this.errors = init.errors ?? [];
61
+ this.requestId = init.requestId;
62
+ this.retryAfter = init.retryAfter;
63
+ this.extra = init.extra ?? {};
64
+ this.headers = init.headers ?? {};
65
+ this.body = init.body;
66
+ }
67
+ /** `insufficient_credits`: the credits the job needs held. */
68
+ get required() {
69
+ const value = this.extra["required"];
70
+ return typeof value === "number" ? value : undefined;
71
+ }
72
+ /** `insufficient_credits`: the credits available now. */
73
+ get available() {
74
+ const value = this.extra["available"];
75
+ return typeof value === "number" ? value : undefined;
76
+ }
77
+ /** `insufficient_scope`: the scope the key lacks. */
78
+ get requiredScope() {
79
+ return str(this.extra["required_scope"]);
80
+ }
81
+ /** `capacity_exhausted`: `paused`, `spend_limit`, `no_gpu_available` or `controller_offline`. */
82
+ get reason() {
83
+ return str(this.extra["reason"]);
84
+ }
85
+ /** Build the error for a non-2xx response; a non-JSON body (an edge 502) is fine. */
86
+ static fromResponse(status, headers, text, retryAfter) {
87
+ let body;
88
+ if (text) {
89
+ try {
90
+ const parsed = JSON.parse(text);
91
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
92
+ body = parsed;
93
+ }
94
+ }
95
+ catch {
96
+ body = undefined;
97
+ }
98
+ }
99
+ const problem = body ?? {};
100
+ const code = str(problem["code"]);
101
+ const title = str(problem["title"]);
102
+ const detail = str(problem["detail"]);
103
+ const requestId = headers["x-request-id"] ?? str(problem["request_id"]);
104
+ const extra = {};
105
+ for (const [key, value] of Object.entries(problem)) {
106
+ if (!PROBLEM_FIELDS.has(key))
107
+ extra[key] = value;
108
+ }
109
+ const text_ = detail ?? title ?? (code ? code.replace(/_/g, " ") : "request failed");
110
+ let message = `HTTP ${status}${code ? ` ${code}` : ""}: ${text_}`;
111
+ if (requestId)
112
+ message += ` (request ${requestId})`;
113
+ const errors = Array.isArray(problem["errors"]) ? problem["errors"] : [];
114
+ return new Printy3DError(message, {
115
+ status,
116
+ code,
117
+ type: str(problem["type"]),
118
+ title,
119
+ detail,
120
+ instance: str(problem["instance"]),
121
+ errors,
122
+ requestId,
123
+ retryAfter,
124
+ extra,
125
+ headers,
126
+ body,
127
+ });
128
+ }
129
+ }
130
+ /** The request never produced an HTTP response (DNS, refused, reset, TLS). */
131
+ export class APIConnectionError extends Printy3DError {
132
+ name = "APIConnectionError";
133
+ }
134
+ /** The request timed out. A write may or may not have reached the API. */
135
+ export class APITimeoutError extends APIConnectionError {
136
+ name = "APITimeoutError";
137
+ }
138
+ /** A job ended without succeeding; `job` is its final state. */
139
+ export class JobError extends Printy3DError {
140
+ name = "JobError";
141
+ job;
142
+ constructor(message, job) {
143
+ super(message, { code: job.error_code ?? undefined, detail: job.error_detail ?? undefined });
144
+ this.job = job;
145
+ }
146
+ }
147
+ /** The job ended `failed`; `code` is the job's `error_code`. */
148
+ export class JobFailedError extends JobError {
149
+ name = "JobFailedError";
150
+ }
151
+ /** The job ended `cancelled`. */
152
+ export class JobCancelledError extends JobError {
153
+ name = "JobCancelledError";
154
+ }
155
+ /** A wait helper gave up; the job, verification or export continues server-side. */
156
+ export class WaitTimeoutError extends Printy3DError {
157
+ name = "WaitTimeoutError";
158
+ /** The last state seen (a Job, File or Export), or `undefined`. */
159
+ last;
160
+ constructor(message, last) {
161
+ super(message);
162
+ this.last = last;
163
+ }
164
+ }
165
+ /** Upload verification rejected the file; `code` is its `rejected_reason`. */
166
+ export class FileRejectedError extends Printy3DError {
167
+ name = "FileRejectedError";
168
+ file;
169
+ constructor(message, file) {
170
+ super(message, { code: file.rejected_reason ?? undefined });
171
+ this.file = file;
172
+ }
173
+ }
174
+ /** The export's conversion failed; `code` is its `error_code`. Ask again to retry. */
175
+ export class ExportFailedError extends Printy3DError {
176
+ name = "ExportFailedError";
177
+ export;
178
+ constructor(message, exported) {
179
+ super(message, { code: exported.error_code ?? undefined });
180
+ this.export = exported;
181
+ }
182
+ }
183
+ /** Downloaded bytes did not match the artifact's declared size or SHA-256. */
184
+ export class IntegrityError extends Printy3DError {
185
+ name = "IntegrityError";
186
+ }
187
+ /** Upload parts were still missing after every resume round. */
188
+ export class UploadIncompleteError extends Printy3DError {
189
+ name = "UploadIncompleteError";
190
+ }
191
+ /** A webhook delivery failed verification; do not trust its body. */
192
+ export class WebhookSignatureError extends Printy3DError {
193
+ name = "WebhookSignatureError";
194
+ constructor(message, reason) {
195
+ super(message, { extra: { reason } });
196
+ }
197
+ /** Why verification failed. */
198
+ get reason() {
199
+ return this.extra["reason"];
200
+ }
201
+ }
202
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,MAAM;IACN,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,MAAM;IACN,QAAQ;IACR,YAAY;CACb,CAAC,CAAC;AAmBH,SAAS,GAAG,CAAC,KAAc;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS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IAAI,GAAW,mBAAmB,CAAC;IAE5C,IAAI,CAAO;IAEpB,YAAY,OAAe,EAAE,IAAU;QACrC,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,eAAe,IAAI,SAAS,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,sFAAsF;AACtF,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAChC,IAAI,GAAW,mBAAmB,CAAC;IAE5C,MAAM,CAAS;IAExB,YAAY,OAAe,EAAE,QAAgB;QAC3C,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,UAAU,IAAI,SAAS,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;IACzB,CAAC;CACF;AAED,8EAA8E;AAC9E,MAAM,OAAO,cAAe,SAAQ,aAAa;IAC7B,IAAI,GAAW,gBAAgB,CAAC;CACnD;AAED,gEAAgE;AAChE,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACpC,IAAI,GAAW,uBAAuB,CAAC;CAC1D;AAQD,qEAAqE;AACrE,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACpC,IAAI,GAAW,uBAAuB,CAAC;IAEzD,YAAY,OAAe,EAAE,MAA8B;QACzD,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,+BAA+B;IAC/B,IAAa,MAAM;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAA2B,CAAC;IACxD,CAAC;CACF"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * HTTP transport on the global `fetch` (Node >= 18, modern browsers).
3
+ *
4
+ * API requests carry `Authorization: Bearer <key>`, never follow redirects (a redirect must
5
+ * not carry the key elsewhere) and turn every non-2xx into `Printy3DError`. Storage
6
+ * requests go to presigned URLs, carry no credential and never appear in error messages.
7
+ *
8
+ * Retries: an idempotent request (GET, DELETE, or a POST carrying an `Idempotency-Key`) is
9
+ * retried on connection errors and timeouts, 429, 502, 503, 504 and
10
+ * `409 idempotency_in_progress`, with bounded exponential backoff and jitter. `Retry-After`
11
+ * replaces the backoff delay; one longer than `maxRetryDelayMs` is raised at once with
12
+ * `retryAfter` set. Other writes are never repeated.
13
+ */
14
+ export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
15
+ export interface TransportConfig {
16
+ apiKey: string;
17
+ baseUrl: string;
18
+ timeoutMs: number;
19
+ transferTimeoutMs: number;
20
+ maxRetries: number;
21
+ maxRetryDelayMs: number;
22
+ userAgent?: string | undefined;
23
+ fetch: FetchLike;
24
+ sleep: (ms: number) => Promise<void>;
25
+ random: () => number;
26
+ }
27
+ export type Query = Record<string, string | number | boolean | null | undefined>;
28
+ export interface RequestOptions {
29
+ query?: Query | undefined;
30
+ body?: unknown;
31
+ headers?: Record<string, string> | undefined;
32
+ idempotencyKey?: string | undefined;
33
+ /** Force retrying on or off; by default only idempotent requests retry. */
34
+ retry?: boolean | undefined;
35
+ signal?: AbortSignal | undefined;
36
+ }
37
+ export interface ApiResponse<T> {
38
+ status: number;
39
+ headers: Record<string, string>;
40
+ data: T;
41
+ /** The `X-Request-Id` response header. */
42
+ requestId: string | undefined;
43
+ /** `Idempotent-Replayed: true`: answered from the API's idempotency record. */
44
+ replayed: boolean;
45
+ }
46
+ /** Seconds from a `Retry-After` header: delta-seconds or an HTTP-date. */
47
+ export declare function parseRetryAfter(value: string | null | undefined, nowMs?: number): number | undefined;
48
+ export declare class Transport {
49
+ #private;
50
+ readonly baseUrl: string;
51
+ readonly maxRetries: number;
52
+ readonly backoffInitialMs = 500;
53
+ readonly backoffMaxMs = 20000;
54
+ private readonly userAgent;
55
+ constructor(config: TransportConfig);
56
+ get sleep(): (ms: number) => Promise<void>;
57
+ /** Exponential backoff with jitter: half the step plus a random half (milliseconds). */
58
+ backoff(attempt: number): number;
59
+ url(path: string, query?: Query): string;
60
+ request<T>(method: string, path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
61
+ private send;
62
+ /** PUT bytes to a presigned URL; returns the HTTP status. The URL never appears in errors. */
63
+ storagePut(url: string, data: Uint8Array, headers?: Record<string, string>): Promise<number>;
64
+ /**
65
+ * Stream a GET from a presigned URL into `onChunk`. `transferTimeoutMs` is an idle
66
+ * timeout: it restarts with every chunk.
67
+ */
68
+ storageGet(url: string, headers: Record<string, string>, onChunk: (chunk: Uint8Array) => void | Promise<void>): Promise<void>;
69
+ }
70
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEjF,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,EAAE,MAAM,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAEjF,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;I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