@shapediver/sdk.geometry-api-sdk-v2 3.6.0 → 4.0.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/README.md +5 -5
- package/dist/UtilsApi.d.ts +16 -29
- package/dist/UtilsApi.d.ts.map +1 -1
- package/dist/UtilsApi.js +133 -135
- package/dist/UtilsApi.js.map +1 -1
- package/dist/base.d.ts +2 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +30 -36
- package/dist/base.js.map +1 -1
- package/dist/client/apis/AnalyticsApi.d.ts +38 -0
- package/dist/client/apis/AnalyticsApi.d.ts.map +1 -0
- package/dist/client/apis/AnalyticsApi.js +245 -0
- package/dist/client/apis/AnalyticsApi.js.map +1 -0
- package/dist/client/apis/ArSceneApi.d.ts +23 -0
- package/dist/client/apis/ArSceneApi.d.ts.map +1 -0
- package/dist/client/apis/ArSceneApi.js +140 -0
- package/dist/client/apis/ArSceneApi.js.map +1 -0
- package/dist/client/apis/AssetsApi.d.ts +54 -0
- package/dist/client/apis/AssetsApi.d.ts.map +1 -0
- package/dist/client/apis/AssetsApi.js +329 -0
- package/dist/client/apis/AssetsApi.js.map +1 -0
- package/dist/client/apis/AuthApi.d.ts +8 -0
- package/dist/client/apis/AuthApi.d.ts.map +1 -0
- package/dist/client/apis/AuthApi.js +77 -0
- package/dist/client/apis/AuthApi.js.map +1 -0
- package/dist/client/apis/AuthGroupApi.d.ts +12 -0
- package/dist/client/apis/AuthGroupApi.d.ts.map +1 -0
- package/dist/client/apis/AuthGroupApi.js +89 -0
- package/dist/client/apis/AuthGroupApi.js.map +1 -0
- package/dist/client/apis/ExportApi.d.ts +38 -0
- package/dist/client/apis/ExportApi.d.ts.map +1 -0
- package/dist/client/apis/ExportApi.js +230 -0
- package/dist/client/apis/ExportApi.js.map +1 -0
- package/dist/client/apis/FileApi.d.ts +45 -0
- package/dist/client/apis/FileApi.d.ts.map +1 -0
- package/dist/client/apis/FileApi.js +271 -0
- package/dist/client/apis/FileApi.js.map +1 -0
- package/dist/client/apis/GltfApi.d.ts +14 -0
- package/dist/client/apis/GltfApi.d.ts.map +1 -0
- package/dist/client/apis/GltfApi.js +96 -0
- package/dist/client/apis/GltfApi.js.map +1 -0
- package/dist/client/apis/LogApi.d.ts +13 -0
- package/dist/client/apis/LogApi.d.ts.map +1 -0
- package/dist/client/apis/LogApi.js +93 -0
- package/dist/client/apis/LogApi.js.map +1 -0
- package/dist/client/apis/ModelApi.d.ts +129 -0
- package/dist/client/apis/ModelApi.d.ts.map +1 -0
- package/dist/client/apis/ModelApi.js +762 -0
- package/dist/client/apis/ModelApi.js.map +1 -0
- package/dist/client/apis/ModelStateApi.d.ts +57 -0
- package/dist/client/apis/ModelStateApi.d.ts.map +1 -0
- package/dist/client/apis/ModelStateApi.js +328 -0
- package/dist/client/apis/ModelStateApi.js.map +1 -0
- package/dist/client/apis/OutputApi.d.ts +38 -0
- package/dist/client/apis/OutputApi.d.ts.map +1 -0
- package/dist/client/apis/OutputApi.js +230 -0
- package/dist/client/apis/OutputApi.js.map +1 -0
- package/dist/client/apis/ScriptApi.d.ts +17 -0
- package/dist/client/apis/ScriptApi.d.ts.map +1 -0
- package/dist/client/apis/ScriptApi.js +127 -0
- package/dist/client/apis/ScriptApi.js.map +1 -0
- package/dist/client/apis/SdtfApi.d.ts +37 -0
- package/dist/client/apis/SdtfApi.d.ts.map +1 -0
- package/dist/client/apis/SdtfApi.js +227 -0
- package/dist/client/apis/SdtfApi.js.map +1 -0
- package/dist/client/apis/SessionApi.d.ts +51 -0
- package/dist/client/apis/SessionApi.d.ts.map +1 -0
- package/dist/client/apis/SessionApi.js +300 -0
- package/dist/client/apis/SessionApi.js.map +1 -0
- package/dist/client/apis/SystemApi.d.ts +28 -0
- package/dist/client/apis/SystemApi.d.ts.map +1 -0
- package/dist/client/apis/SystemApi.js +235 -0
- package/dist/client/apis/SystemApi.js.map +1 -0
- package/dist/client/apis/TextureApi.d.ts +13 -0
- package/dist/client/apis/TextureApi.d.ts.map +1 -0
- package/dist/client/apis/TextureApi.js +91 -0
- package/dist/client/apis/TextureApi.js.map +1 -0
- package/dist/client/apis/index.d.ts +18 -0
- package/dist/client/apis/index.d.ts.map +1 -0
- package/dist/client/apis/index.js +34 -0
- package/dist/client/apis/index.js.map +1 -0
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/models/index.d.ts +1671 -0
- package/dist/client/models/index.d.ts.map +1 -0
- package/dist/client/models/index.js +239 -0
- package/dist/client/models/index.js.map +1 -0
- package/dist/client/runtime.d.ts +154 -0
- package/dist/client/runtime.d.ts.map +1 -0
- package/dist/client/runtime.js +323 -0
- package/dist/client/runtime.js.map +1 -0
- package/dist/configuration.d.ts +2 -7
- package/dist/configuration.d.ts.map +1 -1
- package/dist/configuration.js +36 -16
- package/dist/configuration.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +2 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -13
- package/dist/utils.js.map +1 -1
- package/package.json +3 -9
- package/src/UtilsApi.ts +252 -324
- package/src/base.ts +48 -46
- package/src/client/apis/AnalyticsApi.ts +347 -0
- package/src/client/apis/ArSceneApi.ts +172 -0
- package/src/client/apis/AssetsApi.ts +474 -0
- package/src/client/apis/AuthApi.ts +63 -0
- package/src/client/apis/AuthGroupApi.ts +89 -0
- package/src/client/apis/ExportApi.ts +332 -0
- package/src/client/apis/FileApi.ts +401 -0
- package/src/client/apis/GltfApi.ts +101 -0
- package/src/client/apis/LogApi.ts +96 -0
- package/src/client/apis/ModelApi.ts +1206 -0
- package/src/client/apis/ModelStateApi.ts +479 -0
- package/src/client/apis/OutputApi.ts +333 -0
- package/src/client/apis/ScriptApi.ts +142 -0
- package/src/client/apis/SdtfApi.ts +327 -0
- package/src/client/apis/SessionApi.ts +435 -0
- package/src/client/apis/SystemApi.ts +301 -0
- package/src/client/apis/TextureApi.ts +91 -0
- package/src/client/apis/index.ts +19 -0
- package/src/client/index.ts +3 -16
- package/src/client/models/index.ts +7367 -0
- package/src/client/runtime.ts +442 -0
- package/src/configuration.ts +62 -37
- package/src/error.ts +2 -2
- package/src/index.ts +2 -1
- package/src/utils.ts +53 -25
- package/dist/client/api.d.ts +0 -2111
- package/dist/client/api.d.ts.map +0 -1
- package/dist/client/api.js +0 -3576
- package/dist/client/api.js.map +0 -1
- package/dist/client/base.d.ts +0 -32
- package/dist/client/base.d.ts.map +0 -1
- package/dist/client/base.js +0 -37
- package/dist/client/base.js.map +0 -1
- package/dist/client/common.d.ts +0 -15
- package/dist/client/common.d.ts.map +0 -1
- package/dist/client/common.js +0 -117
- package/dist/client/common.js.map +0 -1
- package/dist/client/configuration.d.ts +0 -37
- package/dist/client/configuration.d.ts.map +0 -1
- package/dist/client/configuration.js +0 -23
- package/dist/client/configuration.js.map +0 -1
- package/src/client/api.ts +0 -11052
- package/src/client/base.ts +0 -62
- package/src/client/common.ts +0 -127
- package/src/client/configuration.ts +0 -121
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Geometry Backend API v2
|
|
5
|
+
* The ShapeDiver Geometry Backend system is used to: * host Grasshopper models in a secure, reliable, scalable, and performant way, * run computations of Grasshopper models, * and cache and output the results of computations and exports.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 2.5.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
|
+
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
|
|
16
|
+
|
|
17
|
+
export interface ConfigurationParameters {
|
|
18
|
+
basePath?: string; // override base path
|
|
19
|
+
fetchApi?: FetchAPI; // override for fetch implementation
|
|
20
|
+
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
|
21
|
+
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
|
|
22
|
+
username?: string; // parameter for basic security
|
|
23
|
+
password?: string; // parameter for basic security
|
|
24
|
+
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
|
|
25
|
+
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
|
|
26
|
+
headers?: HTTPHeaders; //header params we want to use on every request
|
|
27
|
+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class Configuration {
|
|
31
|
+
constructor(private configuration: ConfigurationParameters = {}) {}
|
|
32
|
+
|
|
33
|
+
set config(configuration: Configuration) {
|
|
34
|
+
this.configuration = configuration;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get basePath(): string {
|
|
38
|
+
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get fetchApi(): FetchAPI | undefined {
|
|
42
|
+
return this.configuration.fetchApi;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get middleware(): Middleware[] {
|
|
46
|
+
return this.configuration.middleware || [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get queryParamsStringify(): (params: HTTPQuery) => string {
|
|
50
|
+
return this.configuration.queryParamsStringify || querystring;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get username(): string | undefined {
|
|
54
|
+
return this.configuration.username;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get password(): string | undefined {
|
|
58
|
+
return this.configuration.password;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get apiKey(): ((name: string) => string | Promise<string>) | undefined {
|
|
62
|
+
const apiKey = this.configuration.apiKey;
|
|
63
|
+
if (apiKey) {
|
|
64
|
+
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined {
|
|
70
|
+
const accessToken = this.configuration.accessToken;
|
|
71
|
+
if (accessToken) {
|
|
72
|
+
return typeof accessToken === 'function' ? accessToken : async () => accessToken;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get headers(): HTTPHeaders | undefined {
|
|
78
|
+
return this.configuration.headers;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get credentials(): RequestCredentials | undefined {
|
|
82
|
+
return this.configuration.credentials;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const DefaultConfig = new Configuration();
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* This is the base class for all generated API classes.
|
|
90
|
+
*/
|
|
91
|
+
export class BaseAPI {
|
|
92
|
+
|
|
93
|
+
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
|
|
94
|
+
private middleware: Middleware[];
|
|
95
|
+
|
|
96
|
+
constructor(protected configuration = DefaultConfig) {
|
|
97
|
+
this.middleware = configuration.middleware;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
|
|
101
|
+
const next = this.clone<T>();
|
|
102
|
+
next.middleware = next.middleware.concat(...middlewares);
|
|
103
|
+
return next;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
|
|
107
|
+
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
|
108
|
+
return this.withMiddleware<T>(...middlewares);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
|
|
112
|
+
const middlewares = postMiddlewares.map((post) => ({ post }));
|
|
113
|
+
return this.withMiddleware<T>(...middlewares);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check if the given MIME is a JSON MIME.
|
|
118
|
+
* JSON MIME examples:
|
|
119
|
+
* application/json
|
|
120
|
+
* application/json; charset=UTF8
|
|
121
|
+
* APPLICATION/JSON
|
|
122
|
+
* application/vnd.company+json
|
|
123
|
+
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
124
|
+
* @return True if the given MIME is JSON, false otherwise.
|
|
125
|
+
*/
|
|
126
|
+
protected isJsonMime(mime: string | null | undefined): boolean {
|
|
127
|
+
if (!mime) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return BaseAPI.jsonRegex.test(mime);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response> {
|
|
134
|
+
const { url, init } = await this.createFetchParams(context, initOverrides);
|
|
135
|
+
const response = await this.fetchApi(url, init);
|
|
136
|
+
if (response && (response.status >= 200 && response.status < 300)) {
|
|
137
|
+
return response;
|
|
138
|
+
}
|
|
139
|
+
throw new ResponseError(response, 'Response returned an error code');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) {
|
|
143
|
+
let url = this.configuration.basePath + context.path;
|
|
144
|
+
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
145
|
+
// only add the querystring to the URL if there are query parameters.
|
|
146
|
+
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
147
|
+
// do not handle correctly sometimes.
|
|
148
|
+
url += '?' + this.configuration.queryParamsStringify(context.query);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
152
|
+
Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
|
|
153
|
+
|
|
154
|
+
const initOverrideFn =
|
|
155
|
+
typeof initOverrides === "function"
|
|
156
|
+
? initOverrides
|
|
157
|
+
: async () => initOverrides;
|
|
158
|
+
|
|
159
|
+
const initParams = {
|
|
160
|
+
method: context.method,
|
|
161
|
+
headers,
|
|
162
|
+
body: context.body,
|
|
163
|
+
credentials: this.configuration.credentials,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const overriddenInit: RequestInit = {
|
|
167
|
+
...initParams,
|
|
168
|
+
...(await initOverrideFn({
|
|
169
|
+
init: initParams,
|
|
170
|
+
context,
|
|
171
|
+
}))
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
let body: any;
|
|
175
|
+
if (isFormData(overriddenInit.body)
|
|
176
|
+
|| (overriddenInit.body instanceof URLSearchParams)
|
|
177
|
+
|| isBlob(overriddenInit.body)) {
|
|
178
|
+
body = overriddenInit.body;
|
|
179
|
+
} else if (this.isJsonMime(headers['Content-Type'])) {
|
|
180
|
+
body = JSON.stringify(overriddenInit.body);
|
|
181
|
+
} else {
|
|
182
|
+
body = overriddenInit.body;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const init: RequestInit = {
|
|
186
|
+
...overriddenInit,
|
|
187
|
+
body
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return { url, init };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
protected fetchApi = async (url: string, init: RequestInit) => {
|
|
194
|
+
let fetchParams = { url, init };
|
|
195
|
+
for (const middleware of this.middleware) {
|
|
196
|
+
if (middleware.pre) {
|
|
197
|
+
fetchParams = await middleware.pre({
|
|
198
|
+
fetch: this.fetchApi,
|
|
199
|
+
...fetchParams,
|
|
200
|
+
}) || fetchParams;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
let response: Response | undefined = undefined;
|
|
204
|
+
try {
|
|
205
|
+
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
for (const middleware of this.middleware) {
|
|
208
|
+
if (middleware.onError) {
|
|
209
|
+
response = await middleware.onError({
|
|
210
|
+
fetch: this.fetchApi,
|
|
211
|
+
url: fetchParams.url,
|
|
212
|
+
init: fetchParams.init,
|
|
213
|
+
error: e,
|
|
214
|
+
response: response ? response.clone() : undefined,
|
|
215
|
+
}) || response;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (response === undefined) {
|
|
219
|
+
if (e instanceof Error) {
|
|
220
|
+
throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response');
|
|
221
|
+
} else {
|
|
222
|
+
throw e;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const middleware of this.middleware) {
|
|
227
|
+
if (middleware.post) {
|
|
228
|
+
response = await middleware.post({
|
|
229
|
+
fetch: this.fetchApi,
|
|
230
|
+
url: fetchParams.url,
|
|
231
|
+
init: fetchParams.init,
|
|
232
|
+
response: response.clone(),
|
|
233
|
+
}) || response;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return response;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Create a shallow clone of `this` by constructing a new instance
|
|
241
|
+
* and then shallow cloning data members.
|
|
242
|
+
*/
|
|
243
|
+
private clone<T extends BaseAPI>(this: T): T {
|
|
244
|
+
const constructor = this.constructor as any;
|
|
245
|
+
const next = new constructor(this.configuration);
|
|
246
|
+
next.middleware = this.middleware.slice();
|
|
247
|
+
return next;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
function isBlob(value: any): value is Blob {
|
|
252
|
+
return typeof Blob !== 'undefined' && value instanceof Blob;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function isFormData(value: any): value is FormData {
|
|
256
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export class ResponseError extends Error {
|
|
260
|
+
override name: "ResponseError" = "ResponseError";
|
|
261
|
+
constructor(public response: Response, msg?: string) {
|
|
262
|
+
super(msg);
|
|
263
|
+
|
|
264
|
+
// restore prototype chain
|
|
265
|
+
const actualProto = new.target.prototype;
|
|
266
|
+
if (Object.setPrototypeOf) {
|
|
267
|
+
Object.setPrototypeOf(this, actualProto);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export class FetchError extends Error {
|
|
273
|
+
override name: "FetchError" = "FetchError";
|
|
274
|
+
constructor(public cause: Error, msg?: string) {
|
|
275
|
+
super(msg);
|
|
276
|
+
|
|
277
|
+
// restore prototype chain
|
|
278
|
+
const actualProto = new.target.prototype;
|
|
279
|
+
if (Object.setPrototypeOf) {
|
|
280
|
+
Object.setPrototypeOf(this, actualProto);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export class RequiredError extends Error {
|
|
286
|
+
override name: "RequiredError" = "RequiredError";
|
|
287
|
+
constructor(public field: string, msg?: string) {
|
|
288
|
+
super(msg);
|
|
289
|
+
|
|
290
|
+
// restore prototype chain
|
|
291
|
+
const actualProto = new.target.prototype;
|
|
292
|
+
if (Object.setPrototypeOf) {
|
|
293
|
+
Object.setPrototypeOf(this, actualProto);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export const COLLECTION_FORMATS = {
|
|
299
|
+
csv: ",",
|
|
300
|
+
ssv: " ",
|
|
301
|
+
tsv: "\t",
|
|
302
|
+
pipes: "|",
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
|
|
306
|
+
|
|
307
|
+
export type Json = any;
|
|
308
|
+
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
309
|
+
export type HTTPHeaders = { [key: string]: string };
|
|
310
|
+
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
|
|
311
|
+
export type HTTPBody = Json | FormData | URLSearchParams;
|
|
312
|
+
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
|
|
313
|
+
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
|
|
314
|
+
|
|
315
|
+
export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
|
|
316
|
+
|
|
317
|
+
export interface FetchParams {
|
|
318
|
+
url: string;
|
|
319
|
+
init: RequestInit;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface RequestOpts {
|
|
323
|
+
path: string;
|
|
324
|
+
method: HTTPMethod;
|
|
325
|
+
headers: HTTPHeaders;
|
|
326
|
+
query?: HTTPQuery;
|
|
327
|
+
body?: HTTPBody;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function querystring(params: HTTPQuery, prefix: string = ''): string {
|
|
331
|
+
return Object.keys(params)
|
|
332
|
+
.map(key => querystringSingleKey(key, params[key], prefix))
|
|
333
|
+
.filter(part => part.length > 0)
|
|
334
|
+
.join('&');
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery, keyPrefix: string = ''): string {
|
|
338
|
+
const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
|
|
339
|
+
if (value instanceof Array) {
|
|
340
|
+
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
|
341
|
+
.join(`&${encodeURIComponent(fullKey)}=`);
|
|
342
|
+
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
343
|
+
}
|
|
344
|
+
if (value instanceof Set) {
|
|
345
|
+
const valueAsArray = Array.from(value);
|
|
346
|
+
return querystringSingleKey(key, valueAsArray, keyPrefix);
|
|
347
|
+
}
|
|
348
|
+
if (value instanceof Date) {
|
|
349
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
|
350
|
+
}
|
|
351
|
+
if (value instanceof Object) {
|
|
352
|
+
return querystring(value as HTTPQuery, fullKey);
|
|
353
|
+
}
|
|
354
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function exists(json: any, key: string) {
|
|
358
|
+
const value = json[key];
|
|
359
|
+
return value !== null && value !== undefined;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
export function canConsumeForm(consumes: Consume[]): boolean {
|
|
364
|
+
for (const consume of consumes) {
|
|
365
|
+
if (consume.contentType?.startsWith('multipart/form-data') == true) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface Consume {
|
|
373
|
+
contentType: string;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export interface RequestContext {
|
|
377
|
+
fetch: FetchAPI;
|
|
378
|
+
url: string;
|
|
379
|
+
init: RequestInit;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export interface ResponseContext {
|
|
383
|
+
fetch: FetchAPI;
|
|
384
|
+
url: string;
|
|
385
|
+
init: RequestInit;
|
|
386
|
+
response: Response;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export interface ErrorContext {
|
|
390
|
+
fetch: FetchAPI;
|
|
391
|
+
url: string;
|
|
392
|
+
init: RequestInit;
|
|
393
|
+
error: unknown;
|
|
394
|
+
response?: Response;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface Middleware {
|
|
398
|
+
pre?(context: RequestContext): Promise<FetchParams | void>;
|
|
399
|
+
post?(context: ResponseContext): Promise<Response | void>;
|
|
400
|
+
onError?(context: ErrorContext): Promise<Response | void>;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export interface ApiResponse<T> {
|
|
404
|
+
raw: Response;
|
|
405
|
+
value(): Promise<T>;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export interface ResponseTransformer<T> {
|
|
409
|
+
(json: any): T;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export class JSONApiResponse<T> {
|
|
413
|
+
constructor(public raw: Response, private transformer: ResponseTransformer<T> = (jsonValue: any) => jsonValue) {}
|
|
414
|
+
|
|
415
|
+
async value(): Promise<T> {
|
|
416
|
+
return this.transformer(await this.raw.json());
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export class VoidApiResponse {
|
|
421
|
+
constructor(public raw: Response) {}
|
|
422
|
+
|
|
423
|
+
async value(): Promise<void> {
|
|
424
|
+
return undefined;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export class BlobApiResponse {
|
|
429
|
+
constructor(public raw: Response) {}
|
|
430
|
+
|
|
431
|
+
async value(): Promise<Blob> {
|
|
432
|
+
return await this.raw.blob();
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export class TextApiResponse {
|
|
437
|
+
constructor(public raw: Response) {}
|
|
438
|
+
|
|
439
|
+
async value(): Promise<string> {
|
|
440
|
+
return await this.raw.text();
|
|
441
|
+
};
|
|
442
|
+
}
|
package/src/configuration.ts
CHANGED
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
import { RawAxiosRequestConfig } from 'axios';
|
|
2
1
|
import {
|
|
3
2
|
Configuration as ClientConfig,
|
|
4
3
|
ConfigurationParameters as ClientConfigParams,
|
|
5
|
-
} from './client/
|
|
4
|
+
} from './client/runtime';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
extends Pick<ClientConfigParams, 'accessToken' | 'basePath'> {
|
|
9
|
-
/**
|
|
10
|
-
* Base options for Axios calls.
|
|
11
|
-
*
|
|
12
|
-
* @type {RawAxiosRequestConfig}
|
|
13
|
-
* @memberof ConfigurationParameters
|
|
14
|
-
*/
|
|
15
|
-
baseOptions?: RawAxiosRequestConfig;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Enables the use of a custom Axios instance for all API requests by default, instead of the
|
|
19
|
-
* global Axios instance. This custom instance includes additional functionality to
|
|
20
|
-
* automatically retry requests on `429` and `502` status codes.
|
|
21
|
-
*
|
|
22
|
-
* Default: `true`.
|
|
23
|
-
*/
|
|
24
|
-
useCustomAxios?: boolean;
|
|
6
|
+
const SDK_VERSION = '4.0.0'; // WARNING: This value is updated automatically!
|
|
25
7
|
|
|
8
|
+
export interface ConfigurationParameters
|
|
9
|
+
extends Pick<ClientConfigParams, 'accessToken' | 'basePath' | 'fetchApi' | 'headers' | 'middleware' | 'queryParamsStringify'> {
|
|
26
10
|
/**
|
|
27
11
|
* Specifies the maximum number of automatic HTTP retries for failed requests.
|
|
28
12
|
*
|
|
29
|
-
* **Note:** This setting is only applicable when using a custom
|
|
13
|
+
* **Note:** This setting is only applicable when using a custom Fetch API instance.
|
|
30
14
|
*
|
|
31
15
|
* Default: `5`
|
|
32
16
|
*/
|
|
@@ -34,27 +18,68 @@ export interface ConfigurationParameters
|
|
|
34
18
|
}
|
|
35
19
|
|
|
36
20
|
export class Configuration extends ClientConfig {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
public readonly useCustomAxios: boolean;
|
|
40
|
-
public readonly maxRetries: number;
|
|
21
|
+
readonly maxRetries: number;
|
|
41
22
|
|
|
42
23
|
constructor(param: ConfigurationParameters = {}) {
|
|
43
|
-
super(
|
|
44
|
-
|
|
24
|
+
super({
|
|
25
|
+
...param,
|
|
26
|
+
headers: createHeaders(param.headers),
|
|
27
|
+
});
|
|
28
|
+
|
|
45
29
|
this.maxRetries = param.maxRetries ?? 5;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function createHeaders(
|
|
34
|
+
headers?: ClientConfigParams['headers'],
|
|
35
|
+
): Record<string, string> {
|
|
36
|
+
const result: Record<string, string> = {};
|
|
37
|
+
const normalizedHeaders = new Headers(headers);
|
|
38
|
+
const userAgent = `sd-sdk/typescript/${SDK_VERSION}`;
|
|
39
|
+
|
|
40
|
+
if (detectRuntime() === "node" && !normalizedHeaders.has('User-Agent')) {
|
|
41
|
+
// Overwrite User-Agent on Node.js applications.
|
|
42
|
+
normalizedHeaders.set('User-Agent', userAgent);
|
|
43
|
+
} else if (!normalizedHeaders.has('X-ShapeDiver-UserAgent')) {
|
|
44
|
+
// Set a custom User-Agent header on Browser applications.
|
|
45
|
+
normalizedHeaders.set('X-ShapeDiver-UserAgent', userAgent);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
normalizedHeaders.forEach((value, key) => {
|
|
49
|
+
result[key] = value;
|
|
50
|
+
});
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
function detectRuntime(): "node" | "browser" | "unknown" {
|
|
56
|
+
const global = globalThis as typeof globalThis & {
|
|
57
|
+
process?: {
|
|
58
|
+
versions?: {
|
|
59
|
+
node?: unknown;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
window?: unknown;
|
|
63
|
+
document?: unknown;
|
|
64
|
+
self?: unknown;
|
|
65
|
+
navigator?: unknown;
|
|
66
|
+
};
|
|
51
67
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.baseOptions.headers['User-Agent'] = userAgent;
|
|
55
|
-
} else if (!this.baseOptions.headers['X-ShapeDiver-UserAgent']) {
|
|
56
|
-
// Set a custom User-Agent header on Browser applications.
|
|
57
|
-
this.baseOptions.headers['X-ShapeDiver-UserAgent'] = userAgent;
|
|
58
|
-
}
|
|
68
|
+
if (typeof global.process?.versions?.node === "string") {
|
|
69
|
+
return "node";
|
|
59
70
|
}
|
|
71
|
+
|
|
72
|
+
const isBrowserMainThread =
|
|
73
|
+
global.window === globalThis &&
|
|
74
|
+
typeof global.document !== "undefined";
|
|
75
|
+
|
|
76
|
+
const isBrowserWorker =
|
|
77
|
+
global.self === globalThis &&
|
|
78
|
+
typeof global.navigator !== "undefined";
|
|
79
|
+
|
|
80
|
+
if (isBrowserMainThread || isBrowserWorker) {
|
|
81
|
+
return "browser";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return "unknown";
|
|
60
85
|
}
|
package/src/error.ts
CHANGED
|
@@ -16,7 +16,7 @@ export class SdGeometryError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* This error builds on top of an
|
|
19
|
+
* This error builds on top of an Fetch request error.
|
|
20
20
|
*
|
|
21
21
|
* The request was made but no response was received.
|
|
22
22
|
* @export
|
|
@@ -31,7 +31,7 @@ export class RequestError extends SdGeometryError {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* This error builds on top of an
|
|
34
|
+
* This error builds on top of an Fetch response error.
|
|
35
35
|
*
|
|
36
36
|
* The request was made and the server responded with a status code that falls out of the range of
|
|
37
37
|
* 2xx.
|
package/src/index.ts
CHANGED