@bitbybit-dev/cad-cloud-sdk 1.1.1 → 1.2.0-rc.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.
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -15
- package/dist/client.js.map +1 -1
- package/dist/endpoints/cad.d.ts.map +1 -1
- package/dist/endpoints/cad.js +0 -3
- package/dist/endpoints/cad.js.map +1 -1
- package/dist/endpoints/convert.d.ts.map +1 -1
- package/dist/endpoints/convert.js +0 -3
- package/dist/endpoints/convert.js.map +1 -1
- package/dist/endpoints/files.d.ts.map +1 -1
- package/dist/endpoints/files.js +0 -3
- package/dist/endpoints/files.js.map +1 -1
- package/dist/endpoints/models.d.ts.map +1 -1
- package/dist/endpoints/models.js +0 -3
- package/dist/endpoints/models.js.map +1 -1
- package/dist/endpoints/tasks.d.ts.map +1 -1
- package/dist/endpoints/tasks.js +0 -3
- package/dist/endpoints/tasks.js.map +1 -1
- package/dist/errors.d.ts +4 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -3
- package/dist/errors.js.map +1 -1
- package/dist/fetch-downloads.d.ts.map +1 -1
- package/dist/fetch-downloads.js +0 -3
- package/dist/fetch-downloads.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +1 -1
- package/dist/polling.d.ts.map +1 -1
- package/dist/polling.js +0 -3
- package/dist/polling.js.map +1 -1
- package/dist/types/custom.d.ts.map +1 -1
- package/dist/types/custom.js +0 -5
- package/dist/types/custom.js.map +1 -1
- package/dist/types/generated.d.ts +19 -6
- package/dist/types/generated.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -7
- package/dist/types/index.js.map +1 -1
- package/dist/types/pipeline-operations.d.ts +54 -46
- package/dist/types/pipeline-operations.d.ts.map +1 -1
- package/dist/types/pipeline-operations.js +1 -1
- package/dist/types/pipeline-operations.js.map +1 -1
- package/dist/unwrap.d.ts.map +1 -1
- package/dist/unwrap.js +0 -3
- package/dist/unwrap.js.map +1 -1
- package/dist/validation/validator.d.ts.map +1 -1
- package/dist/validation/validator.js +0 -8
- package/dist/validation/validator.js.map +1 -1
- package/package.json +6 -3
- package/src/__test__/helpers.ts +71 -0
- package/src/__test__/index.ts +1 -0
- package/src/client.test.ts +206 -0
- package/src/client.ts +153 -0
- package/src/endpoints/cad.test.ts +101 -0
- package/src/endpoints/cad.ts +53 -0
- package/src/endpoints/convert.test.ts +154 -0
- package/src/endpoints/convert.ts +83 -0
- package/src/endpoints/files.test.ts +170 -0
- package/src/endpoints/files.ts +89 -0
- package/src/endpoints/index.ts +5 -0
- package/src/endpoints/models.test.ts +228 -0
- package/src/endpoints/models.ts +131 -0
- package/src/endpoints/tasks.test.ts +193 -0
- package/src/endpoints/tasks.ts +93 -0
- package/src/errors.test.ts +57 -0
- package/src/errors.ts +21 -0
- package/src/fetch-downloads.test.ts +67 -0
- package/src/fetch-downloads.ts +18 -0
- package/src/index.ts +19 -0
- package/src/polling.test.ts +194 -0
- package/src/polling.ts +81 -0
- package/src/types/custom.ts +45 -0
- package/src/types/generated.ts +3136 -0
- package/src/types/index.ts +3 -0
- package/src/types/pipeline-operations.ts +9008 -0
- package/src/types/schema-exports.ts +228 -0
- package/src/unwrap.test.ts +75 -0
- package/src/unwrap.ts +20 -0
- package/src/validation/index.ts +1 -0
- package/src/validation/request-schemas.ts +1001 -0
- package/src/validation/validator.test.ts +218 -0
- package/src/validation/validator.ts +60 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// AUTO-GENERATED — do not edit manually.
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
import type { components, paths } from "./generated.js";
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Schema re-exports (1:1 from OpenAPI component schemas, names unchanged)
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/** Submit multiple parameter variations of the same model for parallel generation */
|
|
12
|
+
export type BatchModelSubmissionBody = components["schemas"]["BatchModelSubmissionBody"];
|
|
13
|
+
/** Confirmation that a task was successfully cancelled */
|
|
14
|
+
export type CancelResult = components["schemas"]["CancelResult"];
|
|
15
|
+
/** Success response for task cancellation */
|
|
16
|
+
export type CancelTaskResponse = components["schemas"]["CancelTaskResponse"];
|
|
17
|
+
/** Conditional execution - evaluate a condition and run the matching branch. */
|
|
18
|
+
export type ChoiceStep = components["schemas"]["ChoiceStep"];
|
|
19
|
+
/** Comparison operator: 'eq' (equal), 'neq' (not equal), 'gt' (greater than), 'gte' (greater or equal), 'lt' (less than), 'lte' (less or equal), 'exists' (value is not null/undefined). */
|
|
20
|
+
export type ComparisonOperator = components["schemas"]["ComparisonOperator"];
|
|
21
|
+
/** Execute multiple independent Bitbybit CAD operations in parallel. Each item runs as a separate sub-task and can be polled individually. */
|
|
22
|
+
export type CompoundExecuteBody = components["schemas"]["CompoundExecuteBody"];
|
|
23
|
+
/** A single operation within a compound (parallel) task. Each item runs independently. */
|
|
24
|
+
export type CompoundItem = components["schemas"]["CompoundItem"];
|
|
25
|
+
/** Status/result info for one sub-task in a compound manifest */
|
|
26
|
+
export type CompoundResultEntry = components["schemas"]["CompoundResultEntry"];
|
|
27
|
+
/** Result manifest for a completed compound task */
|
|
28
|
+
export type CompoundResultManifest = components["schemas"]["CompoundResultManifest"];
|
|
29
|
+
/** Success envelope containing the compound task result manifest with per-sub-task download links */
|
|
30
|
+
export type CompoundResultManifestResponse = components["schemas"]["CompoundResultManifestResponse"];
|
|
31
|
+
/** HTTP 202 response when a compound (parallel) task is accepted */
|
|
32
|
+
export type CompoundTaskAcceptedResponse = components["schemas"]["CompoundTaskAcceptedResponse"];
|
|
33
|
+
/** Returned when a compound (parallel) task is accepted. Contains initial status for all sub-tasks. */
|
|
34
|
+
export type CompoundTaskCreatedResult = components["schemas"]["CompoundTaskCreatedResult"];
|
|
35
|
+
/** Success envelope confirming a file upload was verified */
|
|
36
|
+
export type ConfirmResponse = components["schemas"]["ConfirmResponse"];
|
|
37
|
+
/** Returned after a file upload is verified. The file is now ready to be used in CAD operations. */
|
|
38
|
+
export type ConfirmResult = components["schemas"]["ConfirmResult"];
|
|
39
|
+
/** Fine-grained options controlling STEP → glTF conversion: tessellation quality, attribute extraction, coordinate systems, and output format. */
|
|
40
|
+
export type ConvertAdvancedOptions = components["schemas"]["ConvertAdvancedOptions"];
|
|
41
|
+
/** Fetch parameter definitions for one or more parametric models. Returns available parameters, types, defaults, and constraints. */
|
|
42
|
+
export type DefinitionsBody = components["schemas"]["DefinitionsBody"];
|
|
43
|
+
/** Success response for file deletion */
|
|
44
|
+
export type DeleteFileResponse = components["schemas"]["DeleteFileResponse"];
|
|
45
|
+
/** Confirmation that a resource was successfully deleted */
|
|
46
|
+
export type DeleteResult = components["schemas"]["DeleteResult"];
|
|
47
|
+
/** Draco geometry compression options applied during glTF export. */
|
|
48
|
+
export type DracoCompressionOptions = components["schemas"]["DracoCompressionOptions"];
|
|
49
|
+
/** Request body for the Dragon Cup model */
|
|
50
|
+
export type DragonCupBody = components["schemas"]["DragonCupBody"];
|
|
51
|
+
/** Dragon Cup model parameters - all optional, sane defaults apply */
|
|
52
|
+
export type DragonCupParams = components["schemas"]["DragonCupParams"];
|
|
53
|
+
/** Structured error information with machine-readable code and optional debugging context */
|
|
54
|
+
export type ErrorDetail = components["schemas"]["ErrorDetail"];
|
|
55
|
+
/** Standard error envelope */
|
|
56
|
+
export type ErrorResponse = components["schemas"]["ErrorResponse"];
|
|
57
|
+
/** Execute a single Bitbybit CAD operation. The operation runs asynchronously and returns a task ID for polling. */
|
|
58
|
+
export type ExecuteBody = components["schemas"]["ExecuteBody"];
|
|
59
|
+
/** Full metadata for an uploaded file */
|
|
60
|
+
export type FileDetail = components["schemas"]["FileDetail"];
|
|
61
|
+
/** Success envelope containing a single file's metadata */
|
|
62
|
+
export type FileDetailResponse = components["schemas"]["FileDetailResponse"];
|
|
63
|
+
/** Paginated list of uploaded files with total count */
|
|
64
|
+
export type FileList = components["schemas"]["FileList"];
|
|
65
|
+
/** Success envelope containing a paginated file list */
|
|
66
|
+
export type FileListResponse = components["schemas"]["FileListResponse"];
|
|
67
|
+
/** File lifecycle state: 'pending' (upload URL issued, awaiting PUT), 'confirmed' (upload verified and file is usable), 'expired' (upload URL expired before completion) */
|
|
68
|
+
export type FileStatus = components["schemas"]["FileStatus"];
|
|
69
|
+
/** Request a pre-signed upload URL. After receiving the URL, PUT the raw file bytes to it within the expiration window. */
|
|
70
|
+
export type FileUploadBody = components["schemas"]["FileUploadBody"];
|
|
71
|
+
/** How node/mesh names are derived from STEP product/instance labels */
|
|
72
|
+
export type GltfNameFormat = components["schemas"]["GltfNameFormat"];
|
|
73
|
+
/** Transform representation in glTF output */
|
|
74
|
+
export type GltfTransformFormat = components["schemas"]["GltfTransformFormat"];
|
|
75
|
+
/** Success envelope for health check */
|
|
76
|
+
export type HealthResponse = components["schemas"]["HealthResponse"];
|
|
77
|
+
/** API health check result indicating overall system status */
|
|
78
|
+
export type HealthStatus = components["schemas"]["HealthStatus"];
|
|
79
|
+
/** Reference to an uploaded file to be used as input */
|
|
80
|
+
export type InputFileItem = components["schemas"]["InputFileItem"];
|
|
81
|
+
/** Iterate over an array, executing sub-steps for each element. Produces an array of results (or a reduced value). */
|
|
82
|
+
export type MapStep = components["schemas"]["MapStep"];
|
|
83
|
+
/** Mesh angular deflection in radians. Range: [0.01, π] */
|
|
84
|
+
export type MeshAngle = components["schemas"]["MeshAngle"];
|
|
85
|
+
/** Mesh tessellation precision (lower = finer). Range: [0.0001, 10] */
|
|
86
|
+
export type MeshPrecision = components["schemas"]["MeshPrecision"];
|
|
87
|
+
/** Definitions for multiple models in a single response */
|
|
88
|
+
export type ModelBatchDefinitions = components["schemas"]["ModelBatchDefinitions"];
|
|
89
|
+
/** Success envelope containing multiple model definitions */
|
|
90
|
+
export type ModelBatchDefinitionsResponse = components["schemas"]["ModelBatchDefinitionsResponse"];
|
|
91
|
+
/** Full definition of a parametric model including all parameters and their constraints */
|
|
92
|
+
export type ModelDefinition = components["schemas"]["ModelDefinition"];
|
|
93
|
+
/** Success envelope containing a single model's definition */
|
|
94
|
+
export type ModelDefinitionResponse = components["schemas"]["ModelDefinitionResponse"];
|
|
95
|
+
/** List of all available parametric models */
|
|
96
|
+
export type ModelList = components["schemas"]["ModelList"];
|
|
97
|
+
/** Success envelope containing the list of available models */
|
|
98
|
+
export type ModelListResponse = components["schemas"]["ModelListResponse"];
|
|
99
|
+
/** Data type of a model parameter: 'number' (float), 'integer' (whole number), 'boolean' (true/false), 'array' (list of values) */
|
|
100
|
+
export type ModelParamApiType = components["schemas"]["ModelParamApiType"];
|
|
101
|
+
/** Schema definition for a single model parameter */
|
|
102
|
+
export type ModelParamDefinition = components["schemas"]["ModelParamDefinition"];
|
|
103
|
+
/** Submit a parametric model for generation with specified parameters and output formats */
|
|
104
|
+
export type ModelSubmissionBody = components["schemas"]["ModelSubmissionBody"];
|
|
105
|
+
/** Output file format: 'step' (raw STEP), 'stpz' (gzip-compressed STEP), 'decomposed-mesh' (triangulated JSON), 'gltf' (glTF 2.0 binary .glb). Note: 'step' and 'stpz' are mutually exclusive - choose one or the other, not both. */
|
|
106
|
+
export type OutputFormat = components["schemas"]["OutputFormat"];
|
|
107
|
+
/** Controls which output formats are generated and their quality settings */
|
|
108
|
+
export type OutputOptions = components["schemas"]["OutputOptions"];
|
|
109
|
+
/** Request body for the Phone Nest model */
|
|
110
|
+
export type PhoneNestBody = components["schemas"]["PhoneNestBody"];
|
|
111
|
+
/** Phone Nest model parameters - all optional, sane defaults apply */
|
|
112
|
+
export type PhoneNestParams = components["schemas"]["PhoneNestParams"];
|
|
113
|
+
/** A pipeline step - either a plain operation, a map (iteration), or a choice (conditional). */
|
|
114
|
+
export type PipelineAnyStep = components["schemas"]["PipelineAnyStep"];
|
|
115
|
+
/** Execute a chain of Bitbybit CAD operations sequentially. Supports $ref:N step references, $file:N file inputs, map iteration, and choice conditionals. */
|
|
116
|
+
export type PipelineBody = components["schemas"]["PipelineBody"];
|
|
117
|
+
/** Pipeline output file format. Includes all standard formats plus: 'json' (JSON data), 'csv' (CSV text), 'stl' (binary STL mesh - Manifold/JSCAD only), '3mf' (3MF mesh package - Manifold/JSCAD only). */
|
|
118
|
+
export type PipelineOutputFormat = components["schemas"]["PipelineOutputFormat"];
|
|
119
|
+
/** Controls which output formats are generated for pipeline results. Supports additional formats (json, csv, stl, 3mf) beyond standard model outputs. */
|
|
120
|
+
export type PipelineOutputOptions = components["schemas"]["PipelineOutputOptions"];
|
|
121
|
+
/** A single step in a sequential CAD pipeline. Steps can reference outputs of earlier steps via $ref or input files via $file. */
|
|
122
|
+
export type PipelineStep = components["schemas"]["PipelineStep"];
|
|
123
|
+
/** 3D point as [x, y, z] tuple, each coordinate in [-1000, 1000] */
|
|
124
|
+
export type Point3 = components["schemas"]["Point3"];
|
|
125
|
+
/** Uniform scale factor. Range: [1e-6, 1000] */
|
|
126
|
+
export type PositiveScale = components["schemas"]["PositiveScale"];
|
|
127
|
+
/** Metadata about a single downloadable result part */
|
|
128
|
+
export type ResultPartMeta = components["schemas"]["ResultPartMeta"];
|
|
129
|
+
/** Convert a STEP file to glTF with full control over tessellation, naming, coordinate systems, and output format. */
|
|
130
|
+
export type StepToGltfAdvancedBody = components["schemas"]["StepToGltfAdvancedBody"];
|
|
131
|
+
/** Convert a STEP file to Draco-compressed glTF with full control over tessellation, naming, coordinate systems, output format, and Draco quantization. */
|
|
132
|
+
export type StepToGltfAdvancedWithDracoBody = components["schemas"]["StepToGltfAdvancedWithDracoBody"];
|
|
133
|
+
/** Convert a STEP file to glTF format with default settings. Upload the STEP file first, then pass its ID here. */
|
|
134
|
+
export type StepToGltfBody = components["schemas"]["StepToGltfBody"];
|
|
135
|
+
/** Convert a STEP file to Draco-compressed glTF with default settings. Upload the STEP file first, then pass its ID here. */
|
|
136
|
+
export type StepToGltfWithDracoBody = components["schemas"]["StepToGltfWithDracoBody"];
|
|
137
|
+
/** Status summary for one sub-task within a compound (parallel) task */
|
|
138
|
+
export type SubTaskSummary = components["schemas"]["SubTaskSummary"];
|
|
139
|
+
/** HTTP 202 response when a task is accepted for async processing */
|
|
140
|
+
export type TaskAcceptedResponse = components["schemas"]["TaskAcceptedResponse"];
|
|
141
|
+
/** Returned when a CAD task is accepted. Poll the statusUrl to track progress. */
|
|
142
|
+
export type TaskCreatedResult = components["schemas"]["TaskCreatedResult"];
|
|
143
|
+
/** Complete task status including lifecycle timestamps, progress, and result metadata */
|
|
144
|
+
export type TaskDetail = components["schemas"]["TaskDetail"];
|
|
145
|
+
/** Success envelope containing a single task's full details */
|
|
146
|
+
export type TaskDetailResponse = components["schemas"]["TaskDetailResponse"];
|
|
147
|
+
/** Type of work: 'cad' (single operation), 'model' (parametric model), 'convert-simple'/'convert-advanced' (file conversion), 'pipeline' (sequential chain), 'compound' (parallel batch), 'tenant' (tenant-scoped) */
|
|
148
|
+
export type TaskKind = components["schemas"]["TaskKind"];
|
|
149
|
+
/** Paginated list of tasks with total count */
|
|
150
|
+
export type TaskList = components["schemas"]["TaskList"];
|
|
151
|
+
/** Success envelope containing a paginated task list */
|
|
152
|
+
export type TaskListResponse = components["schemas"]["TaskListResponse"];
|
|
153
|
+
/** Result download link for standard tasks, or a compound manifest with per-sub-task download links */
|
|
154
|
+
export type TaskOrCompoundResultResponse = components["schemas"]["TaskOrCompoundResultResponse"];
|
|
155
|
+
/** Download information for a completed task result */
|
|
156
|
+
export type TaskResultDownload = components["schemas"]["TaskResultDownload"];
|
|
157
|
+
/** Success envelope containing a download link for a task result */
|
|
158
|
+
export type TaskResultResponse = components["schemas"]["TaskResultResponse"];
|
|
159
|
+
/** Download information for all available result formats of a completed task */
|
|
160
|
+
export type TaskResultsDownload = components["schemas"]["TaskResultsDownload"];
|
|
161
|
+
/** Success envelope containing download links for all result formats */
|
|
162
|
+
export type TaskResultsResponse = components["schemas"]["TaskResultsResponse"];
|
|
163
|
+
/** Task lifecycle state: waiting (pending dependencies), queued (in queue), processing (actively computing), completed (result available), failed (error occurred), cancelled (user-cancelled), expired (result TTL exceeded) */
|
|
164
|
+
export type TaskStatus = components["schemas"]["TaskStatus"];
|
|
165
|
+
/** One bend: line, angle, radii (inner/outer/neutral and per-end for cones), and developed lengths. */
|
|
166
|
+
export type UnfoldBend = components["schemas"]["UnfoldBend"];
|
|
167
|
+
/** One bend: line, angle, radii (inner/outer/neutral and per-end for cones), and developed lengths. */
|
|
168
|
+
export type UnfoldBendOutput = components["schemas"]["UnfoldBendOutput"];
|
|
169
|
+
/** A classified source face: stable key (index + BRepGraph uid), role, and label anchors. */
|
|
170
|
+
export type UnfoldFaceEntry = components["schemas"]["UnfoldFaceEntry"];
|
|
171
|
+
/** A classified source face: stable key (index + BRepGraph uid), role, and label anchors. */
|
|
172
|
+
export type UnfoldFaceEntryOutput = components["schemas"]["UnfoldFaceEntryOutput"];
|
|
173
|
+
/** Sheet-metal unfold metrics for a single face (surface type, developability, area before/after). */
|
|
174
|
+
export type UnfoldFaceReport = components["schemas"]["UnfoldFaceReport"];
|
|
175
|
+
/** Compute the sheet-metal unfold metrics report for a single face of an uploaded STEP shape. */
|
|
176
|
+
export type UnfoldFaceReportBody = components["schemas"]["UnfoldFaceReportBody"];
|
|
177
|
+
/** Unfold a single developable face of an uploaded STEP shape to a flat face. */
|
|
178
|
+
export type UnfoldFaceToFlatBody = components["schemas"]["UnfoldFaceToFlatBody"];
|
|
179
|
+
/** A sub-shape laid into the flat compound, mapped back to its source face (compound order). */
|
|
180
|
+
export type UnfoldPlaced = components["schemas"]["UnfoldPlaced"];
|
|
181
|
+
/** A sub-shape laid into the flat compound, mapped back to its source face (compound order). */
|
|
182
|
+
export type UnfoldPlacedOutput = components["schemas"]["UnfoldPlacedOutput"];
|
|
183
|
+
/** Returned when a shape/face cannot be processed by the unfold. */
|
|
184
|
+
export type UnfoldReportError = components["schemas"]["UnfoldReportError"];
|
|
185
|
+
/** Returned when a shape/face cannot be processed by the unfold. */
|
|
186
|
+
export type UnfoldReportErrorOutput = components["schemas"]["UnfoldReportErrorOutput"];
|
|
187
|
+
/** Flatten every constant-thickness sheet-metal solid in an uploaded STEP file AND return the per-solid metrics report - both in one call. */
|
|
188
|
+
export type UnfoldSolidBody = components["schemas"]["UnfoldSolidBody"];
|
|
189
|
+
/** Per-solid sheet-metal unfold metrics - one entry per solid in the STEP file (each carries its solidIndex). */
|
|
190
|
+
export type UnfoldSolidReport = components["schemas"]["UnfoldSolidReport"];
|
|
191
|
+
/** Compute per-solid sheet-metal unfold metrics for every solid in an uploaded STEP file. */
|
|
192
|
+
export type UnfoldSolidReportBody = components["schemas"]["UnfoldSolidReportBody"];
|
|
193
|
+
/** Returned when a solid cannot be fully unfolded; carries the partial diagnostics gathered before the failure (classified faces with roles, detected thickness, warnings) so the reason can be inspected. */
|
|
194
|
+
export type UnfoldSolidReportError = components["schemas"]["UnfoldSolidReportError"];
|
|
195
|
+
/** Returned when a solid cannot be fully unfolded; carries the partial diagnostics gathered before the failure (classified faces with roles, detected thickness, warnings) so the reason can be inspected. */
|
|
196
|
+
export type UnfoldSolidReportErrorOutput = components["schemas"]["UnfoldSolidReportErrorOutput"];
|
|
197
|
+
/** Sheet-metal unfold metrics for ONE solid (bend table + face roles + original->flat map). On failure, the ok:false branch still carries the partial diagnostics gathered before the failure. */
|
|
198
|
+
export type UnfoldSolidReportItem = components["schemas"]["UnfoldSolidReportItem"];
|
|
199
|
+
/** Sheet-metal unfold metrics for ONE solid (bend table + face roles + original->flat map). On failure, the ok:false branch still carries the partial diagnostics gathered before the failure. */
|
|
200
|
+
export type UnfoldSolidReportItemOutput = components["schemas"]["UnfoldSolidReportItemOutput"];
|
|
201
|
+
/** Flatten every constant-thickness sheet-metal solid in an uploaded STEP file to flat patterns. */
|
|
202
|
+
export type UnfoldSolidToFlatBody = components["schemas"]["UnfoldSolidToFlatBody"];
|
|
203
|
+
/** Success envelope containing the pre-signed upload URL and file metadata */
|
|
204
|
+
export type UploadResponse = components["schemas"]["UploadResponse"];
|
|
205
|
+
/** Response after requesting a file upload. Contains the pre-signed URL to PUT your file to. */
|
|
206
|
+
export type UploadResult = components["schemas"]["UploadResult"];
|
|
207
|
+
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// Path-derived query parameter types
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
|
|
212
|
+
/** Query parameters for listing tasks (pagination, status filter, kind filter) */
|
|
213
|
+
export type TaskListQuery = NonNullable<paths["/api/v1/tasks"]["get"]["parameters"]["query"]>;
|
|
214
|
+
/** Query parameters for listing files (pagination, status filter) */
|
|
215
|
+
export type FileListQuery = NonNullable<paths["/api/v1/files"]["get"]["parameters"]["query"]>;
|
|
216
|
+
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
// Derived convenience types
|
|
219
|
+
// ---------------------------------------------------------------------------
|
|
220
|
+
|
|
221
|
+
/** A single download entry (element of TaskResultsDownload.downloads). */
|
|
222
|
+
export type TaskDownload = TaskResultsDownload["downloads"][number];
|
|
223
|
+
|
|
224
|
+
/** Maps known model slugs to their typed param interfaces for intellisense. */
|
|
225
|
+
export interface ModelParamMap {
|
|
226
|
+
"dragon-cup": DragonCupParams;
|
|
227
|
+
"phone-nest": PhoneNestParams;
|
|
228
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { unwrap } from "./unwrap.js";
|
|
3
|
+
import { BitbybitApiError } from "./errors.js";
|
|
4
|
+
|
|
5
|
+
describe("unwrap", () => {
|
|
6
|
+
it("returns data from a successful response envelope", async () => {
|
|
7
|
+
// Arrange
|
|
8
|
+
const body = { ok: true, data: { taskId: "t-1", status: "queued" } };
|
|
9
|
+
const res = new Response(JSON.stringify(body), { status: 200 });
|
|
10
|
+
|
|
11
|
+
// Act
|
|
12
|
+
const result = await unwrap<{ taskId: string; status: string }>(res);
|
|
13
|
+
|
|
14
|
+
// Assert
|
|
15
|
+
expect(result).toStrictEqual({ taskId: "t-1", status: "queued" });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("throws BitbybitApiError for error envelope", async () => {
|
|
19
|
+
// Arrange
|
|
20
|
+
const body = {
|
|
21
|
+
ok: false,
|
|
22
|
+
error: { code: "NOT_FOUND", message: "Task not found" },
|
|
23
|
+
};
|
|
24
|
+
const res = new Response(JSON.stringify(body), { status: 404 });
|
|
25
|
+
|
|
26
|
+
// Act & Assert
|
|
27
|
+
await expect(unwrap(res)).rejects.toThrow(BitbybitApiError);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("populates error fields from response envelope", async () => {
|
|
31
|
+
// Arrange
|
|
32
|
+
const body = {
|
|
33
|
+
ok: false,
|
|
34
|
+
error: {
|
|
35
|
+
code: "VALIDATION_ERROR",
|
|
36
|
+
message: "Invalid params",
|
|
37
|
+
details: { field: "height" },
|
|
38
|
+
requestId: "req-abc",
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const res = new Response(JSON.stringify(body), { status: 400 });
|
|
42
|
+
|
|
43
|
+
// Act
|
|
44
|
+
let error: BitbybitApiError | undefined;
|
|
45
|
+
try {
|
|
46
|
+
await unwrap(res);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
error = e as BitbybitApiError;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Assert
|
|
52
|
+
expect(error!.code).toBe("VALIDATION_ERROR");
|
|
53
|
+
expect(error!.message).toBe("Invalid params");
|
|
54
|
+
expect(error!.statusCode).toBe(400);
|
|
55
|
+
expect(error!.details).toStrictEqual({ field: "height" });
|
|
56
|
+
expect(error!.requestId).toBe("req-abc");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("sets statusCode from the HTTP response status", async () => {
|
|
60
|
+
// Arrange
|
|
61
|
+
const body = { ok: false, error: { code: "FORBIDDEN", message: "denied" } };
|
|
62
|
+
const res = new Response(JSON.stringify(body), { status: 403 });
|
|
63
|
+
|
|
64
|
+
// Act
|
|
65
|
+
let error: BitbybitApiError | undefined;
|
|
66
|
+
try {
|
|
67
|
+
await unwrap(res);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
error = e as BitbybitApiError;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Assert
|
|
73
|
+
expect(error!.statusCode).toBe(403);
|
|
74
|
+
});
|
|
75
|
+
});
|
package/src/unwrap.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ApiResponse } from "./types/index.js";
|
|
2
|
+
import { BitbybitApiError } from "./errors.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Unwrap a standard `{ ok, data } | { ok, error }` API response envelope.
|
|
6
|
+
* Throws `BitbybitApiError` when the response indicates failure.
|
|
7
|
+
*/
|
|
8
|
+
export async function unwrap<T>(res: Response): Promise<T> {
|
|
9
|
+
const body: ApiResponse<T> = await res.json() as ApiResponse<T>;
|
|
10
|
+
if (!body.ok) {
|
|
11
|
+
throw new BitbybitApiError({
|
|
12
|
+
code: body.error.code,
|
|
13
|
+
message: body.error.message,
|
|
14
|
+
statusCode: res.status,
|
|
15
|
+
details: body.error.details,
|
|
16
|
+
requestId: body.error.requestId,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return body.data;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BitbybitValidationError, validateRequestBody, getEndpointSchema } from "./validator.js";
|