@toolpath/api 0.1.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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +29 -0
  3. package/dist/client.d.ts +14 -0
  4. package/dist/client.js +15 -0
  5. package/dist/generated/apis/FeaturesApi.d.ts +50 -0
  6. package/dist/generated/apis/FeaturesApi.js +102 -0
  7. package/dist/generated/apis/JobsApi.d.ts +79 -0
  8. package/dist/generated/apis/JobsApi.js +165 -0
  9. package/dist/generated/apis/KeysApi.d.ts +32 -0
  10. package/dist/generated/apis/KeysApi.js +58 -0
  11. package/dist/generated/apis/PartsApi.d.ts +76 -0
  12. package/dist/generated/apis/PartsApi.js +157 -0
  13. package/dist/generated/apis/ServiceApi.d.ts +43 -0
  14. package/dist/generated/apis/ServiceApi.js +79 -0
  15. package/dist/generated/apis/index.d.ts +5 -0
  16. package/dist/generated/apis/index.js +7 -0
  17. package/dist/generated/index.d.ts +3 -0
  18. package/dist/generated/index.js +5 -0
  19. package/dist/generated/models/AnalyzeJobResponse.d.ts +51 -0
  20. package/dist/generated/models/AnalyzeJobResponse.js +59 -0
  21. package/dist/generated/models/ComputeFeatureDatasheetsRequest.d.ts +32 -0
  22. package/dist/generated/models/ComputeFeatureDatasheetsRequest.js +43 -0
  23. package/dist/generated/models/ComputeFeatureDatasheetsResponse.d.ts +51 -0
  24. package/dist/generated/models/ComputeFeatureDatasheetsResponse.js +59 -0
  25. package/dist/generated/models/CreatePartResponse.d.ts +50 -0
  26. package/dist/generated/models/CreatePartResponse.js +55 -0
  27. package/dist/generated/models/DirectionZBounds.d.ts +45 -0
  28. package/dist/generated/models/DirectionZBounds.js +52 -0
  29. package/dist/generated/models/FeatureDatasheetEntry.d.ts +52 -0
  30. package/dist/generated/models/FeatureDatasheetEntry.js +53 -0
  31. package/dist/generated/models/FeatureDatasheetsResponse.d.ts +39 -0
  32. package/dist/generated/models/FeatureDatasheetsResponse.js +48 -0
  33. package/dist/generated/models/HealthResponse.d.ts +54 -0
  34. package/dist/generated/models/HealthResponse.js +61 -0
  35. package/dist/generated/models/JobDetail.d.ts +84 -0
  36. package/dist/generated/models/JobDetail.js +80 -0
  37. package/dist/generated/models/JobSummary.d.ts +72 -0
  38. package/dist/generated/models/JobSummary.js +72 -0
  39. package/dist/generated/models/KeyValidationResponse.d.ts +48 -0
  40. package/dist/generated/models/KeyValidationResponse.js +56 -0
  41. package/dist/generated/models/ListJobsResponse.d.ts +51 -0
  42. package/dist/generated/models/ListJobsResponse.js +56 -0
  43. package/dist/generated/models/OpenApiDocument.d.ts +33 -0
  44. package/dist/generated/models/OpenApiDocument.js +45 -0
  45. package/dist/generated/models/PartFeature.d.ts +64 -0
  46. package/dist/generated/models/PartFeature.js +65 -0
  47. package/dist/generated/models/PartFeatureAxis.d.ts +44 -0
  48. package/dist/generated/models/PartFeatureAxis.js +51 -0
  49. package/dist/generated/models/PartReportResponse.d.ts +139 -0
  50. package/dist/generated/models/PartReportResponse.js +120 -0
  51. package/dist/generated/models/ProblemDetails.d.ts +62 -0
  52. package/dist/generated/models/ProblemDetails.js +59 -0
  53. package/dist/generated/models/Region.d.ts +56 -0
  54. package/dist/generated/models/Region.js +59 -0
  55. package/dist/generated/models/ReportUnits.d.ts +52 -0
  56. package/dist/generated/models/ReportUnits.js +63 -0
  57. package/dist/generated/models/Vec3.d.ts +44 -0
  58. package/dist/generated/models/Vec3.js +51 -0
  59. package/dist/generated/models/index.d.ts +20 -0
  60. package/dist/generated/models/index.js +22 -0
  61. package/dist/generated/runtime.d.ts +185 -0
  62. package/dist/generated/runtime.js +351 -0
  63. package/dist/index.d.ts +3 -0
  64. package/dist/index.js +3 -0
  65. package/dist/upload.d.ts +5 -0
  66. package/dist/upload.js +13 -0
  67. package/package.json +48 -0
@@ -0,0 +1,51 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Toolpath Engine API
5
+ * Public REST API for Toolpath engine operations. **Units.** All dimensional values — in reports and in feature datasheets — are in millimetres; all angles are in degrees. Each report also states this in its `units` field. **Browser use.** CORS is per API key: a request only receives an `Access-Control-Allow-Origin` header when its `Origin` is in the allowlist configured on the key used (set when creating or editing the key in the portal). A key with no allowed origins is server-to-server only. A Bearer API key placed in client-side JavaScript is readable by anyone — restrict its origins, prefer a `read_only` key (read_only keys may call GET operations only; writes are rejected with 403), or proxy requests through your own server.
6
+ *
7
+ * The version of the OpenAPI document: 1.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+ /**
15
+ * Check if a given object implements the Vec3 interface.
16
+ */
17
+ export function instanceOfVec3(value) {
18
+ if (!('x' in value) || value['x'] === undefined)
19
+ return false;
20
+ if (!('y' in value) || value['y'] === undefined)
21
+ return false;
22
+ if (!('z' in value) || value['z'] === undefined)
23
+ return false;
24
+ return true;
25
+ }
26
+ export function Vec3FromJSON(json) {
27
+ return Vec3FromJSONTyped(json, false);
28
+ }
29
+ export function Vec3FromJSONTyped(json, ignoreDiscriminator) {
30
+ if (json == null) {
31
+ return json;
32
+ }
33
+ return {
34
+ x: json['x'],
35
+ y: json['y'],
36
+ z: json['z'],
37
+ };
38
+ }
39
+ export function Vec3ToJSON(json) {
40
+ return Vec3ToJSONTyped(json, false);
41
+ }
42
+ export function Vec3ToJSONTyped(value, ignoreDiscriminator = false) {
43
+ if (value == null) {
44
+ return value;
45
+ }
46
+ return {
47
+ x: value['x'],
48
+ y: value['y'],
49
+ z: value['z'],
50
+ };
51
+ }
@@ -0,0 +1,20 @@
1
+ export * from './AnalyzeJobResponse.js';
2
+ export * from './ComputeFeatureDatasheetsRequest.js';
3
+ export * from './ComputeFeatureDatasheetsResponse.js';
4
+ export * from './CreatePartResponse.js';
5
+ export * from './DirectionZBounds.js';
6
+ export * from './FeatureDatasheetEntry.js';
7
+ export * from './FeatureDatasheetsResponse.js';
8
+ export * from './HealthResponse.js';
9
+ export * from './JobDetail.js';
10
+ export * from './JobSummary.js';
11
+ export * from './KeyValidationResponse.js';
12
+ export * from './ListJobsResponse.js';
13
+ export * from './OpenApiDocument.js';
14
+ export * from './PartFeature.js';
15
+ export * from './PartFeatureAxis.js';
16
+ export * from './PartReportResponse.js';
17
+ export * from './ProblemDetails.js';
18
+ export * from './Region.js';
19
+ export * from './ReportUnits.js';
20
+ export * from './Vec3.js';
@@ -0,0 +1,22 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export * from './AnalyzeJobResponse.js';
4
+ export * from './ComputeFeatureDatasheetsRequest.js';
5
+ export * from './ComputeFeatureDatasheetsResponse.js';
6
+ export * from './CreatePartResponse.js';
7
+ export * from './DirectionZBounds.js';
8
+ export * from './FeatureDatasheetEntry.js';
9
+ export * from './FeatureDatasheetsResponse.js';
10
+ export * from './HealthResponse.js';
11
+ export * from './JobDetail.js';
12
+ export * from './JobSummary.js';
13
+ export * from './KeyValidationResponse.js';
14
+ export * from './ListJobsResponse.js';
15
+ export * from './OpenApiDocument.js';
16
+ export * from './PartFeature.js';
17
+ export * from './PartFeatureAxis.js';
18
+ export * from './PartReportResponse.js';
19
+ export * from './ProblemDetails.js';
20
+ export * from './Region.js';
21
+ export * from './ReportUnits.js';
22
+ export * from './Vec3.js';
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Toolpath Engine API
3
+ * Public REST API for Toolpath engine operations. **Units.** All dimensional values — in reports and in feature datasheets — are in millimetres; all angles are in degrees. Each report also states this in its `units` field. **Browser use.** CORS is per API key: a request only receives an `Access-Control-Allow-Origin` header when its `Origin` is in the allowlist configured on the key used (set when creating or editing the key in the portal). A key with no allowed origins is server-to-server only. A Bearer API key placed in client-side JavaScript is readable by anyone — restrict its origins, prefer a `read_only` key (read_only keys may call GET operations only; writes are rejected with 403), or proxy requests through your own server.
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ export declare const BASE_PATH: string;
13
+ export interface ConfigurationParameters {
14
+ basePath?: string;
15
+ fetchApi?: FetchAPI;
16
+ middleware?: Middleware[];
17
+ queryParamsStringify?: (params: HTTPQuery) => string;
18
+ username?: string;
19
+ password?: string;
20
+ apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>);
21
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>);
22
+ headers?: HTTPHeaders;
23
+ credentials?: RequestCredentials;
24
+ }
25
+ export declare class Configuration {
26
+ private configuration;
27
+ constructor(configuration?: ConfigurationParameters);
28
+ set config(configuration: Configuration);
29
+ get basePath(): string;
30
+ get fetchApi(): FetchAPI | undefined;
31
+ get middleware(): Middleware[];
32
+ get queryParamsStringify(): (params: HTTPQuery) => string;
33
+ get username(): string | undefined;
34
+ get password(): string | undefined;
35
+ get apiKey(): ((name: string) => string | Promise<string>) | undefined;
36
+ get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined;
37
+ get headers(): HTTPHeaders | undefined;
38
+ get credentials(): RequestCredentials | undefined;
39
+ }
40
+ export declare const DefaultConfig: Configuration;
41
+ /**
42
+ * This is the base class for all generated API classes.
43
+ */
44
+ export declare class BaseAPI {
45
+ protected configuration: Configuration;
46
+ private static readonly jsonRegex;
47
+ private middleware;
48
+ constructor(configuration?: Configuration);
49
+ withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]): T;
50
+ withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>): T;
51
+ withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>): T;
52
+ /**
53
+ * Check if the given MIME is a JSON MIME.
54
+ * JSON MIME examples:
55
+ * application/json
56
+ * application/json; charset=UTF8
57
+ * APPLICATION/JSON
58
+ * application/vnd.company+json
59
+ * @param mime - MIME (Multipurpose Internet Mail Extensions)
60
+ * @return True if the given MIME is JSON, false otherwise.
61
+ */
62
+ protected isJsonMime(mime: string | null | undefined): boolean;
63
+ protected request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response>;
64
+ private createFetchParams;
65
+ private fetchApi;
66
+ /**
67
+ * Create a shallow clone of `this` by constructing a new instance
68
+ * and then shallow cloning data members.
69
+ */
70
+ private clone;
71
+ }
72
+ export declare class ResponseError extends Error {
73
+ response: Response;
74
+ name: 'ResponseError';
75
+ constructor(response: Response, msg?: string);
76
+ }
77
+ export declare class FetchError extends Error {
78
+ cause: Error;
79
+ name: 'FetchError';
80
+ constructor(cause: Error, msg?: string);
81
+ }
82
+ export declare class RequiredError extends Error {
83
+ field: string;
84
+ name: 'RequiredError';
85
+ constructor(field: string, msg?: string);
86
+ }
87
+ export declare const COLLECTION_FORMATS: {
88
+ csv: string;
89
+ ssv: string;
90
+ tsv: string;
91
+ pipes: string;
92
+ };
93
+ export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
94
+ export type Json = any;
95
+ export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
96
+ export type HTTPHeaders = {
97
+ [key: string]: string;
98
+ };
99
+ export type HTTPQuery = {
100
+ [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery;
101
+ };
102
+ export type HTTPBody = Json | FormData | URLSearchParams;
103
+ export type HTTPRequestInit = {
104
+ headers?: HTTPHeaders;
105
+ method: HTTPMethod;
106
+ credentials?: RequestCredentials;
107
+ body?: HTTPBody;
108
+ };
109
+ export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
110
+ export type InitOverrideFunction = (requestContext: {
111
+ init: HTTPRequestInit;
112
+ context: RequestOpts;
113
+ }) => Promise<RequestInit>;
114
+ export interface FetchParams {
115
+ url: string;
116
+ init: RequestInit;
117
+ }
118
+ export interface RequestOpts {
119
+ path: string;
120
+ method: HTTPMethod;
121
+ headers: HTTPHeaders;
122
+ query?: HTTPQuery;
123
+ body?: HTTPBody;
124
+ }
125
+ export declare function querystring(params: HTTPQuery, prefix?: string): string;
126
+ export declare function exists(json: any, key: string): boolean;
127
+ export declare function mapValues(data: any, fn: (item: any) => any): {
128
+ [key: string]: any;
129
+ };
130
+ export declare function anyToJSON(value: any): any;
131
+ export declare function canConsumeForm(consumes: Consume[]): boolean;
132
+ export interface Consume {
133
+ contentType: string;
134
+ }
135
+ export interface RequestContext {
136
+ fetch: FetchAPI;
137
+ url: string;
138
+ init: RequestInit;
139
+ }
140
+ export interface ResponseContext {
141
+ fetch: FetchAPI;
142
+ url: string;
143
+ init: RequestInit;
144
+ response: Response;
145
+ }
146
+ export interface ErrorContext {
147
+ fetch: FetchAPI;
148
+ url: string;
149
+ init: RequestInit;
150
+ error: unknown;
151
+ response?: Response;
152
+ }
153
+ export interface Middleware {
154
+ pre?(context: RequestContext): Promise<FetchParams | void>;
155
+ post?(context: ResponseContext): Promise<Response | void>;
156
+ onError?(context: ErrorContext): Promise<Response | void>;
157
+ }
158
+ export interface ApiResponse<T> {
159
+ raw: Response;
160
+ value(): Promise<T>;
161
+ }
162
+ export interface ResponseTransformer<T> {
163
+ (json: any): T;
164
+ }
165
+ export declare class JSONApiResponse<T> {
166
+ raw: Response;
167
+ private transformer;
168
+ constructor(raw: Response, transformer?: ResponseTransformer<T>);
169
+ value(): Promise<T>;
170
+ }
171
+ export declare class VoidApiResponse {
172
+ raw: Response;
173
+ constructor(raw: Response);
174
+ value(): Promise<void>;
175
+ }
176
+ export declare class BlobApiResponse {
177
+ raw: Response;
178
+ constructor(raw: Response);
179
+ value(): Promise<Blob>;
180
+ }
181
+ export declare class TextApiResponse {
182
+ raw: Response;
183
+ constructor(raw: Response);
184
+ value(): Promise<string>;
185
+ }
@@ -0,0 +1,351 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Toolpath Engine API
5
+ * Public REST API for Toolpath engine operations. **Units.** All dimensional values — in reports and in feature datasheets — are in millimetres; all angles are in degrees. Each report also states this in its `units` field. **Browser use.** CORS is per API key: a request only receives an `Access-Control-Allow-Origin` header when its `Origin` is in the allowlist configured on the key used (set when creating or editing the key in the portal). A key with no allowed origins is server-to-server only. A Bearer API key placed in client-side JavaScript is readable by anyone — restrict its origins, prefer a `read_only` key (read_only keys may call GET operations only; writes are rejected with 403), or proxy requests through your own server.
6
+ *
7
+ * The version of the OpenAPI document: 1.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+ export const BASE_PATH = 'https://api.toolpath.com'.replace(/\/+$/, '');
15
+ export class Configuration {
16
+ configuration;
17
+ constructor(configuration = {}) {
18
+ this.configuration = configuration;
19
+ }
20
+ set config(configuration) {
21
+ this.configuration = configuration;
22
+ }
23
+ get basePath() {
24
+ return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
25
+ }
26
+ get fetchApi() {
27
+ return this.configuration.fetchApi;
28
+ }
29
+ get middleware() {
30
+ return this.configuration.middleware || [];
31
+ }
32
+ get queryParamsStringify() {
33
+ return this.configuration.queryParamsStringify || querystring;
34
+ }
35
+ get username() {
36
+ return this.configuration.username;
37
+ }
38
+ get password() {
39
+ return this.configuration.password;
40
+ }
41
+ get apiKey() {
42
+ const apiKey = this.configuration.apiKey;
43
+ if (apiKey) {
44
+ return typeof apiKey === 'function' ? apiKey : () => apiKey;
45
+ }
46
+ return undefined;
47
+ }
48
+ get accessToken() {
49
+ const accessToken = this.configuration.accessToken;
50
+ if (accessToken) {
51
+ return typeof accessToken === 'function' ? accessToken : async () => accessToken;
52
+ }
53
+ return undefined;
54
+ }
55
+ get headers() {
56
+ return this.configuration.headers;
57
+ }
58
+ get credentials() {
59
+ return this.configuration.credentials;
60
+ }
61
+ }
62
+ export const DefaultConfig = new Configuration();
63
+ /**
64
+ * This is the base class for all generated API classes.
65
+ */
66
+ export class BaseAPI {
67
+ configuration;
68
+ static jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
69
+ middleware;
70
+ constructor(configuration = DefaultConfig) {
71
+ this.configuration = configuration;
72
+ this.middleware = configuration.middleware;
73
+ }
74
+ withMiddleware(...middlewares) {
75
+ const next = this.clone();
76
+ next.middleware = next.middleware.concat(...middlewares);
77
+ return next;
78
+ }
79
+ withPreMiddleware(...preMiddlewares) {
80
+ const middlewares = preMiddlewares.map((pre) => ({ pre }));
81
+ return this.withMiddleware(...middlewares);
82
+ }
83
+ withPostMiddleware(...postMiddlewares) {
84
+ const middlewares = postMiddlewares.map((post) => ({ post }));
85
+ return this.withMiddleware(...middlewares);
86
+ }
87
+ /**
88
+ * Check if the given MIME is a JSON MIME.
89
+ * JSON MIME examples:
90
+ * application/json
91
+ * application/json; charset=UTF8
92
+ * APPLICATION/JSON
93
+ * application/vnd.company+json
94
+ * @param mime - MIME (Multipurpose Internet Mail Extensions)
95
+ * @return True if the given MIME is JSON, false otherwise.
96
+ */
97
+ isJsonMime(mime) {
98
+ if (!mime) {
99
+ return false;
100
+ }
101
+ return BaseAPI.jsonRegex.test(mime);
102
+ }
103
+ async request(context, initOverrides) {
104
+ const { url, init } = await this.createFetchParams(context, initOverrides);
105
+ const response = await this.fetchApi(url, init);
106
+ if (response && response.status >= 200 && response.status < 300) {
107
+ return response;
108
+ }
109
+ throw new ResponseError(response, 'Response returned an error code');
110
+ }
111
+ async createFetchParams(context, initOverrides) {
112
+ let url = this.configuration.basePath + context.path;
113
+ if (context.query !== undefined && Object.keys(context.query).length !== 0) {
114
+ // only add the querystring to the URL if there are query parameters.
115
+ // this is done to avoid urls ending with a "?" character which buggy webservers
116
+ // do not handle correctly sometimes.
117
+ url += '?' + this.configuration.queryParamsStringify(context.query);
118
+ }
119
+ const headers = Object.assign({}, this.configuration.headers, context.headers);
120
+ Object.keys(headers).forEach((key) => (headers[key] === undefined ? delete headers[key] : {}));
121
+ const initOverrideFn = typeof initOverrides === 'function' ? initOverrides : async () => initOverrides;
122
+ const initParams = {
123
+ method: context.method,
124
+ headers,
125
+ body: context.body,
126
+ credentials: this.configuration.credentials,
127
+ };
128
+ const overriddenInit = {
129
+ ...initParams,
130
+ ...(await initOverrideFn({
131
+ init: initParams,
132
+ context,
133
+ })),
134
+ };
135
+ let body;
136
+ if (isFormData(overriddenInit.body) ||
137
+ overriddenInit.body instanceof URLSearchParams ||
138
+ isBlob(overriddenInit.body)) {
139
+ body = overriddenInit.body;
140
+ }
141
+ else if (this.isJsonMime(headers['Content-Type'])) {
142
+ body = JSON.stringify(overriddenInit.body);
143
+ }
144
+ else {
145
+ body = overriddenInit.body;
146
+ }
147
+ const init = {
148
+ ...overriddenInit,
149
+ body,
150
+ };
151
+ return { url, init };
152
+ }
153
+ fetchApi = async (url, init) => {
154
+ let fetchParams = { url, init };
155
+ for (const middleware of this.middleware) {
156
+ if (middleware.pre) {
157
+ fetchParams =
158
+ (await middleware.pre({
159
+ fetch: this.fetchApi,
160
+ ...fetchParams,
161
+ })) || fetchParams;
162
+ }
163
+ }
164
+ let response = undefined;
165
+ try {
166
+ response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
167
+ }
168
+ catch (e) {
169
+ for (const middleware of this.middleware) {
170
+ if (middleware.onError) {
171
+ response =
172
+ (await middleware.onError({
173
+ fetch: this.fetchApi,
174
+ url: fetchParams.url,
175
+ init: fetchParams.init,
176
+ error: e,
177
+ response: response ? response.clone() : undefined,
178
+ })) || response;
179
+ }
180
+ }
181
+ if (response === undefined) {
182
+ if (e instanceof Error) {
183
+ throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response');
184
+ }
185
+ else {
186
+ throw e;
187
+ }
188
+ }
189
+ }
190
+ for (const middleware of this.middleware) {
191
+ if (middleware.post) {
192
+ response =
193
+ (await middleware.post({
194
+ fetch: this.fetchApi,
195
+ url: fetchParams.url,
196
+ init: fetchParams.init,
197
+ response: response.clone(),
198
+ })) || response;
199
+ }
200
+ }
201
+ return response;
202
+ };
203
+ /**
204
+ * Create a shallow clone of `this` by constructing a new instance
205
+ * and then shallow cloning data members.
206
+ */
207
+ clone() {
208
+ const constructor = this.constructor;
209
+ const next = new constructor(this.configuration);
210
+ next.middleware = this.middleware.slice();
211
+ return next;
212
+ }
213
+ }
214
+ function isBlob(value) {
215
+ return typeof Blob !== 'undefined' && value instanceof Blob;
216
+ }
217
+ function isFormData(value) {
218
+ return typeof FormData !== 'undefined' && value instanceof FormData;
219
+ }
220
+ export class ResponseError extends Error {
221
+ response;
222
+ name = 'ResponseError';
223
+ constructor(response, msg) {
224
+ super(msg);
225
+ this.response = response;
226
+ // restore prototype chain
227
+ const actualProto = new.target.prototype;
228
+ if (Object.setPrototypeOf) {
229
+ Object.setPrototypeOf(this, actualProto);
230
+ }
231
+ }
232
+ }
233
+ export class FetchError extends Error {
234
+ cause;
235
+ name = 'FetchError';
236
+ constructor(cause, msg) {
237
+ super(msg);
238
+ this.cause = cause;
239
+ // restore prototype chain
240
+ const actualProto = new.target.prototype;
241
+ if (Object.setPrototypeOf) {
242
+ Object.setPrototypeOf(this, actualProto);
243
+ }
244
+ }
245
+ }
246
+ export class RequiredError extends Error {
247
+ field;
248
+ name = 'RequiredError';
249
+ constructor(field, msg) {
250
+ super(msg);
251
+ this.field = field;
252
+ // restore prototype chain
253
+ const actualProto = new.target.prototype;
254
+ if (Object.setPrototypeOf) {
255
+ Object.setPrototypeOf(this, actualProto);
256
+ }
257
+ }
258
+ }
259
+ export const COLLECTION_FORMATS = {
260
+ csv: ',',
261
+ ssv: ' ',
262
+ tsv: '\t',
263
+ pipes: '|',
264
+ };
265
+ export function querystring(params, prefix = '') {
266
+ return Object.keys(params)
267
+ .map((key) => querystringSingleKey(key, params[key], prefix))
268
+ .filter((part) => part.length > 0)
269
+ .join('&');
270
+ }
271
+ function querystringSingleKey(key, value, keyPrefix = '') {
272
+ const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
273
+ if (value instanceof Array) {
274
+ const multiValue = value
275
+ .map((singleValue) => encodeURIComponent(String(singleValue)))
276
+ .join(`&${encodeURIComponent(fullKey)}=`);
277
+ return `${encodeURIComponent(fullKey)}=${multiValue}`;
278
+ }
279
+ if (value instanceof Set) {
280
+ const valueAsArray = Array.from(value);
281
+ return querystringSingleKey(key, valueAsArray, keyPrefix);
282
+ }
283
+ if (value instanceof Date) {
284
+ return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
285
+ }
286
+ if (value instanceof Object) {
287
+ return querystring(value, fullKey);
288
+ }
289
+ return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
290
+ }
291
+ export function exists(json, key) {
292
+ const value = json[key];
293
+ return value !== null && value !== undefined;
294
+ }
295
+ export function mapValues(data, fn) {
296
+ const result = {};
297
+ for (const key of Object.keys(data)) {
298
+ result[key] = fn(data[key]);
299
+ }
300
+ return result;
301
+ }
302
+ // Pass-through serializer for `any`-typed properties in form data. See #1877.
303
+ export function anyToJSON(value) {
304
+ return value;
305
+ }
306
+ export function canConsumeForm(consumes) {
307
+ for (const consume of consumes) {
308
+ if (consume.contentType?.startsWith('multipart/form-data') == true) {
309
+ return true;
310
+ }
311
+ }
312
+ return false;
313
+ }
314
+ export class JSONApiResponse {
315
+ raw;
316
+ transformer;
317
+ constructor(raw, transformer = (jsonValue) => jsonValue) {
318
+ this.raw = raw;
319
+ this.transformer = transformer;
320
+ }
321
+ async value() {
322
+ return this.transformer(await this.raw.json());
323
+ }
324
+ }
325
+ export class VoidApiResponse {
326
+ raw;
327
+ constructor(raw) {
328
+ this.raw = raw;
329
+ }
330
+ async value() {
331
+ return undefined;
332
+ }
333
+ }
334
+ export class BlobApiResponse {
335
+ raw;
336
+ constructor(raw) {
337
+ this.raw = raw;
338
+ }
339
+ async value() {
340
+ return await this.raw.blob();
341
+ }
342
+ }
343
+ export class TextApiResponse {
344
+ raw;
345
+ constructor(raw) {
346
+ this.raw = raw;
347
+ }
348
+ async value() {
349
+ return await this.raw.text();
350
+ }
351
+ }
@@ -0,0 +1,3 @@
1
+ export { createToolpathClient, type ToolpathClient, type ToolpathClientOptions } from './client.js';
2
+ export { uploadToPresignedUrl, type UploadToPresignedUrlOptions } from './upload.js';
3
+ export * from './generated/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createToolpathClient } from './client.js';
2
+ export { uploadToPresignedUrl } from './upload.js';
3
+ export * from './generated/index.js';
@@ -0,0 +1,5 @@
1
+ export interface UploadToPresignedUrlOptions {
2
+ fetch?: typeof globalThis.fetch;
3
+ }
4
+ /** Upload content to the URL returned by the Engine API's create-part operation. */
5
+ export declare const uploadToPresignedUrl: (uploadUrl: string, content: BodyInit, { fetch }?: UploadToPresignedUrlOptions) => Promise<void>;
package/dist/upload.js ADDED
@@ -0,0 +1,13 @@
1
+ /** Upload content to the URL returned by the Engine API's create-part operation. */
2
+ export const uploadToPresignedUrl = async (uploadUrl, content, { fetch = globalThis.fetch } = {}) => {
3
+ let response;
4
+ try {
5
+ response = await fetch(uploadUrl, { method: 'PUT', body: content });
6
+ }
7
+ catch (cause) {
8
+ throw new Error('Could not upload the part to the presigned URL', { cause });
9
+ }
10
+ if (!response.ok) {
11
+ throw new Error(`Could not upload the part to the presigned URL: HTTP ${response.status}`);
12
+ }
13
+ };