@bitbybit-dev/cad-cloud-sdk 1.0.0-rc.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/LICENSE +21 -0
- package/README.md +83 -0
- package/dist/client.d.ts +66 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +124 -0
- package/dist/client.js.map +1 -0
- package/dist/endpoints/cad.d.ts +29 -0
- package/dist/endpoints/cad.d.ts.map +1 -0
- package/dist/endpoints/cad.js +43 -0
- package/dist/endpoints/cad.js.map +1 -0
- package/dist/endpoints/convert.d.ts +27 -0
- package/dist/endpoints/convert.d.ts.map +1 -0
- package/dist/endpoints/convert.js +39 -0
- package/dist/endpoints/convert.js.map +1 -0
- package/dist/endpoints/files.d.ts +30 -0
- package/dist/endpoints/files.d.ts.map +1 -0
- package/dist/endpoints/files.js +69 -0
- package/dist/endpoints/files.js.map +1 -0
- package/dist/endpoints/index.d.ts +6 -0
- package/dist/endpoints/index.d.ts.map +1 -0
- package/dist/endpoints/index.js +6 -0
- package/dist/endpoints/index.js.map +1 -0
- package/dist/endpoints/models.d.ts +50 -0
- package/dist/endpoints/models.d.ts.map +1 -0
- package/dist/endpoints/models.js +76 -0
- package/dist/endpoints/models.js.map +1 -0
- package/dist/endpoints/tasks.d.ts +37 -0
- package/dist/endpoints/tasks.d.ts.map +1 -0
- package/dist/endpoints/tasks.js +70 -0
- package/dist/endpoints/tasks.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +18 -0
- package/dist/errors.js.map +1 -0
- package/dist/fetch-downloads.d.ts +9 -0
- package/dist/fetch-downloads.d.ts.map +1 -0
- package/dist/fetch-downloads.js +15 -0
- package/dist/fetch-downloads.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/polling.d.ts +18 -0
- package/dist/polling.d.ts.map +1 -0
- package/dist/polling.js +58 -0
- package/dist/polling.js.map +1 -0
- package/dist/types/custom.d.ts +37 -0
- package/dist/types/custom.d.ts.map +1 -0
- package/dist/types/custom.js +7 -0
- package/dist/types/custom.js.map +1 -0
- package/dist/types/generated.d.ts +2168 -0
- package/dist/types/generated.d.ts.map +1 -0
- package/dist/types/generated.js +6 -0
- package/dist/types/generated.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/schema-exports.d.ts +155 -0
- package/dist/types/schema-exports.d.ts.map +1 -0
- package/dist/types/schema-exports.js +5 -0
- package/dist/types/schema-exports.js.map +1 -0
- package/dist/unwrap.d.ts +6 -0
- package/dist/unwrap.d.ts.map +1 -0
- package/dist/unwrap.js +22 -0
- package/dist/unwrap.js.map +1 -0
- package/dist/validation/index.d.ts +2 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +2 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/request-schemas.d.ts +570 -0
- package/dist/validation/request-schemas.d.ts.map +1 -0
- package/dist/validation/request-schemas.js +628 -0
- package/dist/validation/request-schemas.js.map +1 -0
- package/dist/validation/validator.d.ts +17 -0
- package/dist/validation/validator.d.ts.map +1 -0
- package/dist/validation/validator.js +61 -0
- package/dist/validation/validator.js.map +1 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bit by bit developers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @bitbybit-dev/cad-cloud-sdk
|
|
2
|
+
|
|
3
|
+
Type-safe TypeScript SDK for the [Bitbybit CAD Cloud API](https://learn.bitbybit.dev/api/cloud-api). Generate parametric 3D models, run CAD operations, convert STEP files, and manage async tasks — all with full intellisense.
|
|
4
|
+
|
|
5
|
+
> **Server-side only.** Never expose your API key in frontend code.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @bitbybit-dev/cad-cloud-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { BitbybitClient } from "@bitbybit-dev/cad-cloud-sdk";
|
|
17
|
+
|
|
18
|
+
const client = new BitbybitClient({
|
|
19
|
+
apiKey: process.env.BITBYBIT_API_KEY!,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Generate a dragon cup — polls automatically, returns all download URLs
|
|
23
|
+
const { downloads } = await client.models.run("dragon-cup", {
|
|
24
|
+
params: { height: 10, radiusBottom: 5 },
|
|
25
|
+
outputs: { formats: ["gltf"] },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// downloads: [{ format: "glb", downloadUrl, filename }, { format: "metadata", ... }]
|
|
29
|
+
const glb = downloads.find(d => d.format === "glb");
|
|
30
|
+
console.log("GLB download:", glb?.downloadUrl);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## What's included
|
|
34
|
+
|
|
35
|
+
| Endpoint | What it does |
|
|
36
|
+
|----------|-------------|
|
|
37
|
+
| `client.models` | Generate parametric 3D models (single + batch) |
|
|
38
|
+
| `client.cad` | Execute operations, pipelines, and compound tasks |
|
|
39
|
+
| `client.convert` | STEP → glTF conversion (simple + advanced) |
|
|
40
|
+
| `client.tasks` | Poll, list, cancel, retry, and download results |
|
|
41
|
+
| `client.files` | Upload and manage files for conversion |
|
|
42
|
+
|
|
43
|
+
All high-level methods (`models.run`, `cad.executeAndPoll`, `convert.stepToGltfAndPoll`) handle polling automatically and return all download URLs (including metadata) in a single `downloads` array.
|
|
44
|
+
|
|
45
|
+
## Error handling
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { BitbybitApiError } from "@bitbybit-dev/cad-cloud-sdk";
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await client.models.run("dragon-cup", { outputs: { formats: ["gltf"] } });
|
|
52
|
+
} catch (err) {
|
|
53
|
+
if (err instanceof BitbybitApiError) {
|
|
54
|
+
console.error(err.code, err.message, err.statusCode);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
Full guides with examples for every endpoint:
|
|
62
|
+
|
|
63
|
+
- **[SDK Overview](https://learn.bitbybit.dev/api/sdk/typescript/intro)** — setup, polling, error handling, type imports
|
|
64
|
+
- **[Models](https://learn.bitbybit.dev/api/sdk/typescript/models)** — parametric model generation and batch runs
|
|
65
|
+
- **[CAD Operations](https://learn.bitbybit.dev/api/sdk/typescript/cad-operations)** — execute, pipeline, compound
|
|
66
|
+
- **[Conversion](https://learn.bitbybit.dev/api/sdk/typescript/conversion)** — STEP → glTF with simple and advanced options
|
|
67
|
+
- **[Tasks](https://learn.bitbybit.dev/api/sdk/typescript/tasks)** — task lifecycle management
|
|
68
|
+
- **[Files](https://learn.bitbybit.dev/api/sdk/typescript/files)** — file upload and management
|
|
69
|
+
- **[API Reference](https://learn.bitbybit.dev/api/openapi-docs/bitbybit-cad-cloud-api)** — full OpenAPI endpoint reference
|
|
70
|
+
|
|
71
|
+
## Working examples
|
|
72
|
+
|
|
73
|
+
- [Node.js + SDK](https://github.com/bitbybit-dev/bitbybit/tree/master/examples/api/nodejs-sdk) — Express server with Three.js frontend
|
|
74
|
+
- [Hono + SDK](https://github.com/bitbybit-dev/bitbybit/tree/master/examples/api/hono-sdk) — Cloudflare Workers with Three.js frontend
|
|
75
|
+
|
|
76
|
+
## Requirements
|
|
77
|
+
|
|
78
|
+
- Node.js 18+ (or any runtime with native `fetch`)
|
|
79
|
+
- A Bitbybit API key — get one at [bitbybit.dev/auth/pick-plan](https://bitbybit.dev/auth/pick-plan)
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ModelsEndpoint } from "./endpoints/models.js";
|
|
2
|
+
import { TasksEndpoint } from "./endpoints/tasks.js";
|
|
3
|
+
import { CadEndpoint } from "./endpoints/cad.js";
|
|
4
|
+
import { ConvertEndpoint } from "./endpoints/convert.js";
|
|
5
|
+
import { FilesEndpoint } from "./endpoints/files.js";
|
|
6
|
+
export interface BitbybitClientOptions {
|
|
7
|
+
/** Your Bitbybit API key (starts with `bbk_`). */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
/**
|
|
10
|
+
* Base URL of the Bitbybit API.
|
|
11
|
+
* @default "https://api.bitbybit.dev"
|
|
12
|
+
*/
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Validate request bodies against JSON Schema before sending.
|
|
16
|
+
* Catches parameter errors early with clear messages.
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
validate?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Type-safe client for the Bitbybit CAD Cloud API.
|
|
23
|
+
*
|
|
24
|
+
* **Server-side only** — never expose your API key in frontend code.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { BitbybitClient } from "@bitbybit-dev/cad-cloud-sdk";
|
|
29
|
+
*
|
|
30
|
+
* const client = new BitbybitClient({ apiKey: process.env.BITBYBIT_API_KEY! });
|
|
31
|
+
*
|
|
32
|
+
* // Generate a dragon cup and get a GLB download URL
|
|
33
|
+
* const { downloadUrl } = await client.models.run("dragon-cup", {
|
|
34
|
+
* params: { height: 10, radiusBottom: 5 },
|
|
35
|
+
* outputs: { formats: ["gltf"] },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class BitbybitClient {
|
|
40
|
+
/** Parametric model generation. */
|
|
41
|
+
readonly models: ModelsEndpoint;
|
|
42
|
+
/** Task status, polling, and result retrieval. */
|
|
43
|
+
readonly tasks: TasksEndpoint;
|
|
44
|
+
/** Raw CAD operations (execute, pipeline, compound). */
|
|
45
|
+
readonly cad: CadEndpoint;
|
|
46
|
+
/** STEP → glTF conversion. */
|
|
47
|
+
readonly convert: ConvertEndpoint;
|
|
48
|
+
/** File upload and management. */
|
|
49
|
+
readonly files: FilesEndpoint;
|
|
50
|
+
private readonly baseUrl;
|
|
51
|
+
private readonly apiKey;
|
|
52
|
+
private readonly validate;
|
|
53
|
+
constructor(opts: BitbybitClientOptions);
|
|
54
|
+
/** Check API health. */
|
|
55
|
+
health(): Promise<{
|
|
56
|
+
ok: boolean;
|
|
57
|
+
instance: string;
|
|
58
|
+
timestamp: string;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Low-level request method used by all endpoints.
|
|
62
|
+
* Can also be used directly for custom / future endpoints.
|
|
63
|
+
*/
|
|
64
|
+
request(method: string, path: string, body?: unknown): Promise<Response>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAKrD,MAAM,WAAW,qBAAqB;IAClC,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc;IACvB,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAEhC,kDAAkD;IAClD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAE9B,wDAAwD;IACxD,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAE1B,8BAA8B;IAC9B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAElC,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAE9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;gBAEvB,IAAI,EAAE,qBAAqB;IAiBvC,wBAAwB;IAClB,MAAM,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAK7E;;;OAGG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CAyBjF"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// BitbybitClient — main entry point for the SDK
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { ModelsEndpoint } from "./endpoints/models.js";
|
|
5
|
+
import { TasksEndpoint } from "./endpoints/tasks.js";
|
|
6
|
+
import { CadEndpoint } from "./endpoints/cad.js";
|
|
7
|
+
import { ConvertEndpoint } from "./endpoints/convert.js";
|
|
8
|
+
import { FilesEndpoint } from "./endpoints/files.js";
|
|
9
|
+
import { validateRequestBody, getEndpointSchema } from "./validation/index.js";
|
|
10
|
+
const DEFAULT_BASE_URL = "https://api.bitbybit.dev";
|
|
11
|
+
/**
|
|
12
|
+
* Type-safe client for the Bitbybit CAD Cloud API.
|
|
13
|
+
*
|
|
14
|
+
* **Server-side only** — never expose your API key in frontend code.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { BitbybitClient } from "@bitbybit-dev/cad-cloud-sdk";
|
|
19
|
+
*
|
|
20
|
+
* const client = new BitbybitClient({ apiKey: process.env.BITBYBIT_API_KEY! });
|
|
21
|
+
*
|
|
22
|
+
* // Generate a dragon cup and get a GLB download URL
|
|
23
|
+
* const { downloadUrl } = await client.models.run("dragon-cup", {
|
|
24
|
+
* params: { height: 10, radiusBottom: 5 },
|
|
25
|
+
* outputs: { formats: ["gltf"] },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class BitbybitClient {
|
|
30
|
+
/** Parametric model generation. */
|
|
31
|
+
models;
|
|
32
|
+
/** Task status, polling, and result retrieval. */
|
|
33
|
+
tasks;
|
|
34
|
+
/** Raw CAD operations (execute, pipeline, compound). */
|
|
35
|
+
cad;
|
|
36
|
+
/** STEP → glTF conversion. */
|
|
37
|
+
convert;
|
|
38
|
+
/** File upload and management. */
|
|
39
|
+
files;
|
|
40
|
+
baseUrl;
|
|
41
|
+
apiKey;
|
|
42
|
+
validate;
|
|
43
|
+
constructor(opts) {
|
|
44
|
+
if (!opts.apiKey) {
|
|
45
|
+
throw new Error("BitbybitClient requires an apiKey");
|
|
46
|
+
}
|
|
47
|
+
this.apiKey = opts.apiKey;
|
|
48
|
+
this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
49
|
+
this.validate = opts.validate !== false;
|
|
50
|
+
const fetcher = this.request.bind(this);
|
|
51
|
+
this.models = new ModelsEndpoint(fetcher);
|
|
52
|
+
this.tasks = new TasksEndpoint(fetcher);
|
|
53
|
+
this.cad = new CadEndpoint(fetcher);
|
|
54
|
+
this.convert = new ConvertEndpoint(fetcher);
|
|
55
|
+
this.files = new FilesEndpoint(fetcher);
|
|
56
|
+
}
|
|
57
|
+
/** Check API health. */
|
|
58
|
+
async health() {
|
|
59
|
+
const res = await fetch(`${this.baseUrl}/health`);
|
|
60
|
+
return res.json();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Low-level request method used by all endpoints.
|
|
64
|
+
* Can also be used directly for custom / future endpoints.
|
|
65
|
+
*/
|
|
66
|
+
async request(method, path, body) {
|
|
67
|
+
if (this.validate && body != null && method !== "GET") {
|
|
68
|
+
const endpointKey = pathToEndpointKey(path);
|
|
69
|
+
if (endpointKey) {
|
|
70
|
+
const schemaName = getEndpointSchema(endpointKey);
|
|
71
|
+
if (schemaName) {
|
|
72
|
+
validateRequestBody(schemaName, body);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const url = `${this.baseUrl}${path}`;
|
|
77
|
+
const headers = {
|
|
78
|
+
"x-api-key": this.apiKey,
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
};
|
|
81
|
+
const res = await fetch(url, {
|
|
82
|
+
method,
|
|
83
|
+
headers,
|
|
84
|
+
body: body != null ? JSON.stringify(body) : undefined,
|
|
85
|
+
});
|
|
86
|
+
return res;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
// Path → endpoint key mapping for validation lookup
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
const STATIC_PATH_MAP = {
|
|
93
|
+
"/api/v1/cad/execute": "cad.execute",
|
|
94
|
+
"/api/v1/cad/pipeline": "cad.pipeline",
|
|
95
|
+
"/api/v1/cad/compound": "cad.compound",
|
|
96
|
+
"/api/v1/models/definitions": "models.definitions",
|
|
97
|
+
"/api/v1/convert/step-to-gltf": "convert.stepToGltf",
|
|
98
|
+
"/api/v1/convert/step-to-gltf-advanced": "convert.stepToGltfAdvanced",
|
|
99
|
+
"/api/v1/files/upload": "files.upload",
|
|
100
|
+
};
|
|
101
|
+
const MODEL_PATH_RE = /^\/api\/v1\/models\/([a-z][a-z0-9-]*)$/;
|
|
102
|
+
const MODEL_BATCH_PATH_RE = /^\/api\/v1\/models\/([a-z][a-z0-9-]*)\/batch$/;
|
|
103
|
+
function pathToEndpointKey(path) {
|
|
104
|
+
const staticKey = STATIC_PATH_MAP[path];
|
|
105
|
+
if (staticKey)
|
|
106
|
+
return staticKey;
|
|
107
|
+
// /api/v1/models/{slug}/batch → models.batchSubmit
|
|
108
|
+
const batchMatch = MODEL_BATCH_PATH_RE.exec(path);
|
|
109
|
+
if (batchMatch)
|
|
110
|
+
return "models.batchSubmit";
|
|
111
|
+
// /api/v1/models/{slug} → models.submit.{slug} (per-model) or models.submit (generic)
|
|
112
|
+
const modelMatch = MODEL_PATH_RE.exec(path);
|
|
113
|
+
if (modelMatch) {
|
|
114
|
+
const slug = modelMatch[1];
|
|
115
|
+
// Try per-model schema first (e.g. models.submit.dragon-cup)
|
|
116
|
+
// Caller falls back to generic if per-model is not found
|
|
117
|
+
const perModel = `models.submit.${slug}`;
|
|
118
|
+
if (getEndpointSchema(perModel))
|
|
119
|
+
return perModel;
|
|
120
|
+
return "models.submit";
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gDAAgD;AAChD,8EAA8E;AAE9E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/E,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAkBpD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,cAAc;IACvB,mCAAmC;IAC1B,MAAM,CAAiB;IAEhC,kDAAkD;IACzC,KAAK,CAAgB;IAE9B,wDAAwD;IAC/C,GAAG,CAAc;IAE1B,8BAA8B;IACrB,OAAO,CAAkB;IAElC,kCAAkC;IACzB,KAAK,CAAgB;IAEb,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,QAAQ,CAAU;IAEnC,YAAY,IAA2B;QACnC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CA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I,UAAU,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,6DAA6D;QAC7D,yDAAyD;QACzD,MAAM,QAAQ,GAAG,iBAAiB,IAAI,EAAE,CAAC;QACzC,IAAI,iBAAiB,CAAC,QAAQ,CAAC;YAAE,OAAO,QAAQ,CAAC;QACjD,OAAO,eAAe,CAAC;IAC3B,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ExecuteBody, PipelineBody, CompoundExecuteBody, TaskCreatedResult, CompoundTaskCreatedResult, TaskDownload } from "../types/index.js";
|
|
2
|
+
import type { PollOptions } from "../polling.js";
|
|
3
|
+
type Fetcher = (method: string, path: string, body?: unknown) => Promise<Response>;
|
|
4
|
+
export declare class CadEndpoint {
|
|
5
|
+
private readonly fetch;
|
|
6
|
+
constructor(fetch: Fetcher);
|
|
7
|
+
/** Submit a single CAD operation. Returns immediately with task info. */
|
|
8
|
+
execute(body: ExecuteBody): Promise<TaskCreatedResult>;
|
|
9
|
+
/** Submit a CAD pipeline (sequential steps with $ref references). */
|
|
10
|
+
pipeline(body: PipelineBody): Promise<TaskCreatedResult>;
|
|
11
|
+
/** Submit a compound (parallel) CAD execution. */
|
|
12
|
+
compound(body: CompoundExecuteBody): Promise<CompoundTaskCreatedResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Execute a single CAD operation, poll until complete, and return all downloads.
|
|
15
|
+
*/
|
|
16
|
+
executeAndPoll(body: ExecuteBody, opts?: PollOptions): Promise<{
|
|
17
|
+
taskId: string;
|
|
18
|
+
downloads: TaskDownload[];
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Submit a pipeline, poll until complete, and return all downloads.
|
|
22
|
+
*/
|
|
23
|
+
pipelineAndPoll(body: PipelineBody, opts?: PollOptions): Promise<{
|
|
24
|
+
taskId: string;
|
|
25
|
+
downloads: TaskDownload[];
|
|
26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|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// CAD execute endpoint — /api/v1/cad
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { pollTask } from "../polling.js";
|
|
5
|
+
import { unwrap } from "../unwrap.js";
|
|
6
|
+
import { fetchDownloads } from "../fetch-downloads.js";
|
|
7
|
+
export class CadEndpoint {
|
|
8
|
+
fetch;
|
|
9
|
+
constructor(fetch) {
|
|
10
|
+
this.fetch = fetch;
|
|
11
|
+
}
|
|
12
|
+
/** Submit a single CAD operation. Returns immediately with task info. */
|
|
13
|
+
async execute(body) {
|
|
14
|
+
return unwrap(await this.fetch("POST", "/api/v1/cad/execute", body));
|
|
15
|
+
}
|
|
16
|
+
/** Submit a CAD pipeline (sequential steps with $ref references). */
|
|
17
|
+
async pipeline(body) {
|
|
18
|
+
return unwrap(await this.fetch("POST", "/api/v1/cad/pipeline", body));
|
|
19
|
+
}
|
|
20
|
+
/** Submit a compound (parallel) CAD execution. */
|
|
21
|
+
async compound(body) {
|
|
22
|
+
return unwrap(await this.fetch("POST", "/api/v1/cad/compound", body));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Execute a single CAD operation, poll until complete, and return all downloads.
|
|
26
|
+
*/
|
|
27
|
+
async executeAndPoll(body, opts) {
|
|
28
|
+
const created = await this.execute(body);
|
|
29
|
+
const task = await pollTask(this.fetch, created.taskId, opts);
|
|
30
|
+
const downloads = await fetchDownloads(this.fetch, task.taskId);
|
|
31
|
+
return { taskId: task.taskId, downloads };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Submit a pipeline, poll until complete, and return all downloads.
|
|
35
|
+
*/
|
|
36
|
+
async pipelineAndPoll(body, opts) {
|
|
37
|
+
const created = await this.pipeline(body);
|
|
38
|
+
const task = await pollTask(this.fetch, created.taskId, opts);
|
|
39
|
+
const downloads = await fetchDownloads(this.fetch, task.taskId);
|
|
40
|
+
return { taskId: task.taskId, downloads };
|
|
41
|
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,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CACjB,IAAkB,EAClB,IAAkB;QAElB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC9D,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;IAC9C,CAAC;CACJ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { StepToGltfBody, StepToGltfAdvancedBody, TaskCreatedResult, TaskDownload } from "../types/index.js";
|
|
2
|
+
import type { PollOptions } from "../polling.js";
|
|
3
|
+
type Fetcher = (method: string, path: string, body?: unknown) => Promise<Response>;
|
|
4
|
+
export declare class ConvertEndpoint {
|
|
5
|
+
private readonly fetch;
|
|
6
|
+
constructor(fetch: Fetcher);
|
|
7
|
+
/** Convert STEP to glTF (simple mode). Returns task info. */
|
|
8
|
+
stepToGltf(body: StepToGltfBody): Promise<TaskCreatedResult>;
|
|
9
|
+
/** Convert STEP to glTF (advanced mode with full options). Returns task info. */
|
|
10
|
+
stepToGltfAdvanced(body: StepToGltfAdvancedBody): Promise<TaskCreatedResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Convert STEP to glTF (simple), poll until complete, return all downloads.
|
|
13
|
+
*/
|
|
14
|
+
stepToGltfAndPoll(body: StepToGltfBody, opts?: PollOptions): Promise<{
|
|
15
|
+
taskId: string;
|
|
16
|
+
downloads: TaskDownload[];
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Convert STEP to glTF (advanced), poll until complete, return all downloads.
|
|
20
|
+
*/
|
|
21
|
+
stepToGltfAdvancedAndPoll(body: StepToGltfAdvancedBody, opts?: PollOptions): Promise<{
|
|
22
|
+
taskId: string;
|
|
23
|
+
downloads: TaskDownload[];
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/endpoints/convert.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAKjD,KAAK,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEnF,qBAAa,eAAe;IACZ,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAE3C,6DAA6D;IACvD,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIlE,iFAAiF;IAC3E,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIlF;;OAEG;IACG,iBAAiB,CACnB,IAAI,EAAE,cAAc,EACpB,IAAI,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAOzD;;OAEG;IACG,yBAAyB,CAC3B,IAAI,EAAE,sBAAsB,EAC5B,IAAI,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;CAM5D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Convert endpoint — /api/v1/convert
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { pollTask } from "../polling.js";
|
|
5
|
+
import { unwrap } from "../unwrap.js";
|
|
6
|
+
import { fetchDownloads } from "../fetch-downloads.js";
|
|
7
|
+
export class ConvertEndpoint {
|
|
8
|
+
fetch;
|
|
9
|
+
constructor(fetch) {
|
|
10
|
+
this.fetch = fetch;
|
|
11
|
+
}
|
|
12
|
+
/** Convert STEP to glTF (simple mode). Returns task info. */
|
|
13
|
+
async stepToGltf(body) {
|
|
14
|
+
return unwrap(await this.fetch("POST", "/api/v1/convert/step-to-gltf", body));
|
|
15
|
+
}
|
|
16
|
+
/** Convert STEP to glTF (advanced mode with full options). Returns task info. */
|
|
17
|
+
async stepToGltfAdvanced(body) {
|
|
18
|
+
return unwrap(await this.fetch("POST", "/api/v1/convert/step-to-gltf-advanced", body));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert STEP to glTF (simple), poll until complete, return all downloads.
|
|
22
|
+
*/
|
|
23
|
+
async stepToGltfAndPoll(body, opts) {
|
|
24
|
+
const created = await this.stepToGltf(body);
|
|
25
|
+
const task = await pollTask(this.fetch, created.taskId, opts);
|
|
26
|
+
const downloads = await fetchDownloads(this.fetch, task.taskId);
|
|
27
|
+
return { taskId: task.taskId, downloads };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Convert STEP to glTF (advanced), poll until complete, return all downloads.
|
|
31
|
+
*/
|
|
32
|
+
async stepToGltfAdvancedAndPoll(body, opts) {
|
|
33
|
+
const created = await this.stepToGltfAdvanced(body);
|
|
34
|
+
const task = await pollTask(this.fetch, created.taskId, opts);
|
|
35
|
+
const downloads = await fetchDownloads(this.fetch, task.taskId);
|
|
36
|
+
return { taskId: task.taskId, downloads };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/endpoints/convert.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,qCAAqC;AACrC,8EAA8E;AAI9E,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,MAAM,OAAO,eAAe;IACK;IAA7B,YAA6B,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAE/C,6DAA6D;IAC7D,KAAK,CAAC,UAAU,CAAC,IAAoB;QACjC,OAAO,MAAM,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,8BAA8B,EAAE,IAAI,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,iFAAiF;IACjF,KAAK,CAAC,kBAAkB,CAAC,IAA4B;QACjD,OAAO,MAAM,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,uCAAuC,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CACnB,IAAoB,EACpB,IAAkB;QAElB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC9D,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,yBAAyB,CAC3B,IAA4B,EAC5B,IAAkB;QAElB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACpD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC9D,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;IAC9C,CAAC;CACJ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FileUploadBody, UploadResult, ConfirmResult, FileDetail, FileList, FileListQuery } from "../types/index.js";
|
|
2
|
+
type Fetcher = (method: string, path: string, body?: unknown) => Promise<Response>;
|
|
3
|
+
export declare class FilesEndpoint {
|
|
4
|
+
private readonly fetch;
|
|
5
|
+
constructor(fetch: Fetcher);
|
|
6
|
+
/**
|
|
7
|
+
* Request a pre-signed upload URL.
|
|
8
|
+
* After receiving the result, PUT the file bytes to `uploadUrl`, then call `confirm()`.
|
|
9
|
+
*/
|
|
10
|
+
upload(body: FileUploadBody): Promise<UploadResult>;
|
|
11
|
+
/** Confirm that bytes have been uploaded to the pre-signed URL. */
|
|
12
|
+
confirm(fileId: string): Promise<ConfirmResult>;
|
|
13
|
+
/** Get details for a single file. */
|
|
14
|
+
get(fileId: string): Promise<FileDetail>;
|
|
15
|
+
/** List uploaded files with optional filters. */
|
|
16
|
+
list(query?: FileListQuery): Promise<FileList>;
|
|
17
|
+
/** Delete a file. */
|
|
18
|
+
delete(fileId: string): Promise<{
|
|
19
|
+
deleted: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Convenience: upload file bytes end-to-end.
|
|
23
|
+
* 1. Requests a pre-signed URL
|
|
24
|
+
* 2. PUTs the bytes
|
|
25
|
+
* 3. Confirms the upload
|
|
26
|
+
*/
|
|
27
|
+
uploadBytes(filename: string, data: Uint8Array | ArrayBuffer, contentType?: string): Promise<ConfirmResult>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/endpoints/files.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,cAAc,EACd,YAAY,EACZ,aAAa,EACb,UAAU,EACV,QAAQ,EACR,aAAa,EAChB,MAAM,mBAAmB,CAAC;AAI3B,KAAK,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEnF,qBAAa,aAAa;IACV,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAE3C;;;OAGG;IACG,MAAM,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAIzD,mEAAmE;IAC7D,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAMrD,qCAAqC;IAC/B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAM9C,iDAAiD;IAC3C,IAAI,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC;IASpD,qBAAqB;IACf,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAM3D;;;;;OAKG;IACG,WAAW,CACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,GAAG,WAAW,EAC9B,WAAW,SAA6B,GACzC,OAAO,CAAC,aAAa,CAAC;CAuB5B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Files endpoint — /api/v1/files
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { BitbybitApiError } from "../errors.js";
|
|
5
|
+
import { unwrap } from "../unwrap.js";
|
|
6
|
+
export class FilesEndpoint {
|
|
7
|
+
fetch;
|
|
8
|
+
constructor(fetch) {
|
|
9
|
+
this.fetch = fetch;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Request a pre-signed upload URL.
|
|
13
|
+
* After receiving the result, PUT the file bytes to `uploadUrl`, then call `confirm()`.
|
|
14
|
+
*/
|
|
15
|
+
async upload(body) {
|
|
16
|
+
return unwrap(await this.fetch("POST", "/api/v1/files/upload", body));
|
|
17
|
+
}
|
|
18
|
+
/** Confirm that bytes have been uploaded to the pre-signed URL. */
|
|
19
|
+
async confirm(fileId) {
|
|
20
|
+
return unwrap(await this.fetch("POST", `/api/v1/files/${encodeURIComponent(fileId)}/confirm`));
|
|
21
|
+
}
|
|
22
|
+
/** Get details for a single file. */
|
|
23
|
+
async get(fileId) {
|
|
24
|
+
return unwrap(await this.fetch("GET", `/api/v1/files/${encodeURIComponent(fileId)}`));
|
|
25
|
+
}
|
|
26
|
+
/** List uploaded files with optional filters. */
|
|
27
|
+
async list(query) {
|
|
28
|
+
const params = new URLSearchParams();
|
|
29
|
+
if (query?.page != null)
|
|
30
|
+
params.set("page", String(query.page));
|
|
31
|
+
if (query?.limit != null)
|
|
32
|
+
params.set("limit", String(query.limit));
|
|
33
|
+
if (query?.status)
|
|
34
|
+
params.set("status", query.status);
|
|
35
|
+
const qs = params.toString();
|
|
36
|
+
return unwrap(await this.fetch("GET", `/api/v1/files${qs ? `?${qs}` : ""}`));
|
|
37
|
+
}
|
|
38
|
+
/** Delete a file. */
|
|
39
|
+
async delete(fileId) {
|
|
40
|
+
return unwrap(await this.fetch("DELETE", `/api/v1/files/${encodeURIComponent(fileId)}`));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Convenience: upload file bytes end-to-end.
|
|
44
|
+
* 1. Requests a pre-signed URL
|
|
45
|
+
* 2. PUTs the bytes
|
|
46
|
+
* 3. Confirms the upload
|
|
47
|
+
*/
|
|
48
|
+
async uploadBytes(filename, data, contentType = "application/octet-stream") {
|
|
49
|
+
const uploadResult = await this.upload({
|
|
50
|
+
filename,
|
|
51
|
+
contentType,
|
|
52
|
+
bytes: data.byteLength,
|
|
53
|
+
});
|
|
54
|
+
const putRes = await fetch(uploadResult.uploadUrl, {
|
|
55
|
+
method: "PUT",
|
|
56
|
+
headers: { "Content-Type": contentType },
|
|
57
|
+
body: data,
|
|
58
|
+
});
|
|
59
|
+
if (!putRes.ok) {
|
|
60
|
+
throw new BitbybitApiError({
|
|
61
|
+
code: "UPLOAD_FAILED",
|
|
62
|
+
message: `PUT to upload URL failed: ${putRes.status} ${putRes.statusText}`,
|
|
63
|
+
statusCode: putRes.status,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return this.confirm(uploadResult.fileId);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/endpoints/files.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAU9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,MAAM,OAAO,aAAa;IACO;IAA7B,YAA6B,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAE/C;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,IAAoB;QAC7B,OAAO,MAAM,CAAC,MAAM,IAAI,CAAC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3,"file":"index.js","sourceRoot":"","sources":["../../src/endpoints/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|