@shapediver/sdk.geometry-api-sdk-v2 3.7.0 → 4.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 (153) hide show
  1. package/README.md +5 -5
  2. package/dist/UtilsApi.d.ts +19 -29
  3. package/dist/UtilsApi.d.ts.map +1 -1
  4. package/dist/UtilsApi.js +140 -135
  5. package/dist/UtilsApi.js.map +1 -1
  6. package/dist/base.d.ts +2 -5
  7. package/dist/base.d.ts.map +1 -1
  8. package/dist/base.js +30 -36
  9. package/dist/base.js.map +1 -1
  10. package/dist/client/apis/AnalyticsApi.d.ts +38 -0
  11. package/dist/client/apis/AnalyticsApi.d.ts.map +1 -0
  12. package/dist/client/apis/AnalyticsApi.js +245 -0
  13. package/dist/client/apis/AnalyticsApi.js.map +1 -0
  14. package/dist/client/apis/ArSceneApi.d.ts +23 -0
  15. package/dist/client/apis/ArSceneApi.d.ts.map +1 -0
  16. package/dist/client/apis/ArSceneApi.js +140 -0
  17. package/dist/client/apis/ArSceneApi.js.map +1 -0
  18. package/dist/client/apis/AssetsApi.d.ts +54 -0
  19. package/dist/client/apis/AssetsApi.d.ts.map +1 -0
  20. package/dist/client/apis/AssetsApi.js +329 -0
  21. package/dist/client/apis/AssetsApi.js.map +1 -0
  22. package/dist/client/apis/AuthApi.d.ts +8 -0
  23. package/dist/client/apis/AuthApi.d.ts.map +1 -0
  24. package/dist/client/apis/AuthApi.js +77 -0
  25. package/dist/client/apis/AuthApi.js.map +1 -0
  26. package/dist/client/apis/AuthGroupApi.d.ts +12 -0
  27. package/dist/client/apis/AuthGroupApi.d.ts.map +1 -0
  28. package/dist/client/apis/AuthGroupApi.js +89 -0
  29. package/dist/client/apis/AuthGroupApi.js.map +1 -0
  30. package/dist/client/apis/ExportApi.d.ts +38 -0
  31. package/dist/client/apis/ExportApi.d.ts.map +1 -0
  32. package/dist/client/apis/ExportApi.js +230 -0
  33. package/dist/client/apis/ExportApi.js.map +1 -0
  34. package/dist/client/apis/FileApi.d.ts +45 -0
  35. package/dist/client/apis/FileApi.d.ts.map +1 -0
  36. package/dist/client/apis/FileApi.js +271 -0
  37. package/dist/client/apis/FileApi.js.map +1 -0
  38. package/dist/client/apis/GltfApi.d.ts +14 -0
  39. package/dist/client/apis/GltfApi.d.ts.map +1 -0
  40. package/dist/client/apis/GltfApi.js +96 -0
  41. package/dist/client/apis/GltfApi.js.map +1 -0
  42. package/dist/client/apis/LogApi.d.ts +13 -0
  43. package/dist/client/apis/LogApi.d.ts.map +1 -0
  44. package/dist/client/apis/LogApi.js +93 -0
  45. package/dist/client/apis/LogApi.js.map +1 -0
  46. package/dist/client/apis/ModelApi.d.ts +129 -0
  47. package/dist/client/apis/ModelApi.d.ts.map +1 -0
  48. package/dist/client/apis/ModelApi.js +762 -0
  49. package/dist/client/apis/ModelApi.js.map +1 -0
  50. package/dist/client/apis/ModelStateApi.d.ts +57 -0
  51. package/dist/client/apis/ModelStateApi.d.ts.map +1 -0
  52. package/dist/client/apis/ModelStateApi.js +328 -0
  53. package/dist/client/apis/ModelStateApi.js.map +1 -0
  54. package/dist/client/apis/OutputApi.d.ts +38 -0
  55. package/dist/client/apis/OutputApi.d.ts.map +1 -0
  56. package/dist/client/apis/OutputApi.js +230 -0
  57. package/dist/client/apis/OutputApi.js.map +1 -0
  58. package/dist/client/apis/ScriptApi.d.ts +17 -0
  59. package/dist/client/apis/ScriptApi.d.ts.map +1 -0
  60. package/dist/client/apis/ScriptApi.js +127 -0
  61. package/dist/client/apis/ScriptApi.js.map +1 -0
  62. package/dist/client/apis/SdtfApi.d.ts +37 -0
  63. package/dist/client/apis/SdtfApi.d.ts.map +1 -0
  64. package/dist/client/apis/SdtfApi.js +227 -0
  65. package/dist/client/apis/SdtfApi.js.map +1 -0
  66. package/dist/client/apis/SessionApi.d.ts +51 -0
  67. package/dist/client/apis/SessionApi.d.ts.map +1 -0
  68. package/dist/client/apis/SessionApi.js +300 -0
  69. package/dist/client/apis/SessionApi.js.map +1 -0
  70. package/dist/client/apis/SystemApi.d.ts +28 -0
  71. package/dist/client/apis/SystemApi.d.ts.map +1 -0
  72. package/dist/client/apis/SystemApi.js +235 -0
  73. package/dist/client/apis/SystemApi.js.map +1 -0
  74. package/dist/client/apis/TextureApi.d.ts +13 -0
  75. package/dist/client/apis/TextureApi.d.ts.map +1 -0
  76. package/dist/client/apis/TextureApi.js +91 -0
  77. package/dist/client/apis/TextureApi.js.map +1 -0
  78. package/dist/client/apis/index.d.ts +18 -0
  79. package/dist/client/apis/index.d.ts.map +1 -0
  80. package/dist/client/apis/index.js +34 -0
  81. package/dist/client/apis/index.js.map +1 -0
  82. package/dist/client/index.d.ts +3 -2
  83. package/dist/client/index.d.ts.map +1 -1
  84. package/dist/client/index.js +3 -2
  85. package/dist/client/index.js.map +1 -1
  86. package/dist/client/models/index.d.ts +1671 -0
  87. package/dist/client/models/index.d.ts.map +1 -0
  88. package/dist/client/models/index.js +239 -0
  89. package/dist/client/models/index.js.map +1 -0
  90. package/dist/client/runtime.d.ts +154 -0
  91. package/dist/client/runtime.d.ts.map +1 -0
  92. package/dist/client/runtime.js +323 -0
  93. package/dist/client/runtime.js.map +1 -0
  94. package/dist/configuration.d.ts +2 -7
  95. package/dist/configuration.d.ts.map +1 -1
  96. package/dist/configuration.js +21 -16
  97. package/dist/configuration.js.map +1 -1
  98. package/dist/index.d.ts +2 -1
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +2 -1
  101. package/dist/index.js.map +1 -1
  102. package/dist/utils.d.ts +2 -3
  103. package/dist/utils.d.ts.map +1 -1
  104. package/dist/utils.js +16 -13
  105. package/dist/utils.js.map +1 -1
  106. package/package.json +3 -9
  107. package/src/UtilsApi.ts +265 -318
  108. package/src/base.ts +48 -46
  109. package/src/client/apis/AnalyticsApi.ts +347 -0
  110. package/src/client/apis/ArSceneApi.ts +172 -0
  111. package/src/client/apis/AssetsApi.ts +474 -0
  112. package/src/client/apis/AuthApi.ts +63 -0
  113. package/src/client/apis/AuthGroupApi.ts +89 -0
  114. package/src/client/apis/ExportApi.ts +332 -0
  115. package/src/client/apis/FileApi.ts +401 -0
  116. package/src/client/apis/GltfApi.ts +101 -0
  117. package/src/client/apis/LogApi.ts +96 -0
  118. package/src/client/apis/ModelApi.ts +1206 -0
  119. package/src/client/apis/ModelStateApi.ts +479 -0
  120. package/src/client/apis/OutputApi.ts +333 -0
  121. package/src/client/apis/ScriptApi.ts +142 -0
  122. package/src/client/apis/SdtfApi.ts +327 -0
  123. package/src/client/apis/SessionApi.ts +435 -0
  124. package/src/client/apis/SystemApi.ts +301 -0
  125. package/src/client/apis/TextureApi.ts +91 -0
  126. package/src/client/apis/index.ts +19 -0
  127. package/src/client/index.ts +3 -16
  128. package/src/client/models/index.ts +7367 -0
  129. package/src/client/runtime.ts +442 -0
  130. package/src/configuration.ts +31 -38
  131. package/src/error.ts +2 -2
  132. package/src/index.ts +2 -1
  133. package/src/utils.ts +53 -25
  134. package/dist/client/api.d.ts +0 -2111
  135. package/dist/client/api.d.ts.map +0 -1
  136. package/dist/client/api.js +0 -3576
  137. package/dist/client/api.js.map +0 -1
  138. package/dist/client/base.d.ts +0 -32
  139. package/dist/client/base.d.ts.map +0 -1
  140. package/dist/client/base.js +0 -37
  141. package/dist/client/base.js.map +0 -1
  142. package/dist/client/common.d.ts +0 -15
  143. package/dist/client/common.d.ts.map +0 -1
  144. package/dist/client/common.js +0 -117
  145. package/dist/client/common.js.map +0 -1
  146. package/dist/client/configuration.d.ts +0 -37
  147. package/dist/client/configuration.d.ts.map +0 -1
  148. package/dist/client/configuration.js +0 -23
  149. package/dist/client/configuration.js.map +0 -1
  150. package/src/client/api.ts +0 -11052
  151. package/src/client/base.ts +0 -62
  152. package/src/client/common.ts +0 -127
  153. 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
+ }
@@ -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/configuration';
4
+ } from './client/runtime';
6
5
 
7
- export interface ConfigurationParameters
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.1.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 Axios instance.
13
+ * **Note:** This setting is only applicable when using a custom Fetch API instance.
30
14
  *
31
15
  * Default: `5`
32
16
  */
@@ -34,29 +18,38 @@ export interface ConfigurationParameters
34
18
  }
35
19
 
36
20
  export class Configuration extends ClientConfig {
37
- protected readonly sdkVersion = '3.7.0'; // WARNING: This value is updated automatically!
38
-
39
- public readonly useCustomAxios: boolean;
40
- public readonly maxRetries: number;
21
+ readonly maxRetries: number;
41
22
 
42
23
  constructor(param: ConfigurationParameters = {}) {
43
- super(param);
44
- this.useCustomAxios = param.useCustomAxios ?? true;
45
- this.maxRetries = param.maxRetries ?? 5;
24
+ super({
25
+ ...param,
26
+ headers: createHeaders(param.headers),
27
+ });
46
28
 
47
- this.baseOptions = this.baseOptions ?? {};
48
- this.baseOptions.headers = this.baseOptions.headers ?? {};
29
+ this.maxRetries = param.maxRetries ?? 5;
30
+ }
31
+ }
49
32
 
50
- const userAgent = `sd-sdk/typescript/${this.sdkVersion}`;
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}`;
51
39
 
52
- if (detectRuntime() === "node" && !this.baseOptions.headers['User-Agent']) {
53
- // Overwrite User-Agent on Node.js applications.
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
- }
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);
59
46
  }
47
+
48
+ normalizedHeaders.forEach((value, key) => {
49
+ result[key] = value;
50
+ });
51
+
52
+ return result;
60
53
  }
61
54
 
62
55
  function detectRuntime(): "node" | "browser" | "unknown" {
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 Axios request error.
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 Axios response error.
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
@@ -1,4 +1,5 @@
1
- export * from './client/api';
1
+ export * from './client/apis';
2
+ export * from './client/models';
2
3
  export * from './UtilsApi';
3
4
  export * from './configuration';
4
5
  export * from './error';
package/src/utils.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { AxiosError, AxiosPromise } from 'axios';
1
+ import {
2
+ FetchError,
3
+ ResponseError as ClientResponseError,
4
+ } from './client/runtime';
2
5
  import { RequestError, ResponseError } from './error';
3
6
 
4
7
  /** ShapeDiver error object structure. */
@@ -15,7 +18,7 @@ export function sleep(ms: number): Promise<void> {
15
18
 
16
19
  /**
17
20
  * Parse HTTP headers to extract size and filename information.
18
- * @param {Record<string, any>} headers The HTTP headers of a file-metadata response.
21
+ * @param headers The HTTP headers of a file-metadata response.
19
22
  * @return An object with 'size' and 'filename' properties.
20
23
  */
21
24
  export function extractFileInfo(headers: Record<string, any> | undefined): {
@@ -39,7 +42,7 @@ export function extractFileInfo(headers: Record<string, any> | undefined): {
39
42
 
40
43
  /**
41
44
  * Set content headers according to RFC 5987.
42
- * @param {string} filename The file name to use.
45
+ * @param filename The file name to use.
43
46
  * @return A content-disposition header string.
44
47
  */
45
48
  export function contentDispositionFromFilename(filename: string): string {
@@ -58,7 +61,7 @@ export function contentDispositionFromFilename(filename: string): string {
58
61
  /**
59
62
  * Extract and return the filename from a content-disposition HTTP header.
60
63
  * Decodes the `filename*` property if set.
61
- * @param {string} contentDisposition Content-Disposition header value.
64
+ * @param contentDisposition Content-Disposition header value.
62
65
  * @return The extracted filename.
63
66
  */
64
67
  export function filenameFromContentDisposition(contentDisposition: string): string | undefined {
@@ -90,7 +93,7 @@ export function filenameFromContentDisposition(contentDisposition: string): stri
90
93
  * @returns A promise that resolves to `true` if the API call resulted in a `200` HTTP status, and
91
94
  * `false` for a `404` HTTP error status. Any other error status will be propagated.
92
95
  */
93
- export async function exists(apiCall: () => AxiosPromise<unknown>): Promise<boolean> {
96
+ export async function exists(apiCall: () => Promise<unknown>): Promise<boolean> {
94
97
  return apiCall()
95
98
  .then(() => true)
96
99
  .catch((error) => {
@@ -132,7 +135,7 @@ function isArrayBufferView(value: unknown): value is ArrayBufferView {
132
135
  }
133
136
 
134
137
  /**
135
- * Tries to extract an error object from various Axios response data types.
138
+ * Tries to extract an error object from various Fetch response data types.
136
139
  * @param data The data to extract from.
137
140
  * @returns The extracted error object, or undefined if none could be found.
138
141
  */
@@ -159,27 +162,52 @@ export async function tryExtractErrorObject(data: unknown): Promise<SdErrorObjec
159
162
  }
160
163
 
161
164
  /**
162
- * Tries to convert a generic Axios error into a more specific ShapeDiver error. When no match is
163
- * found, the original error is returned instead.
164
- * @param error The Axios error to convert.
165
+ * Converts a Fetch response or generated Fetch error into a ShapeDiver error.
166
+ *
167
+ * Fetch resolves HTTP failures as `Response` objects and rejects only when the
168
+ * request cannot be completed. The generated runtime wraps those rejections in
169
+ * `FetchError`, which lets ordinary setup errors remain unchanged.
170
+ *
171
+ * @param error The response or error to convert.
165
172
  */
166
173
  export async function processError(
167
- error: AxiosError | Error
174
+ error: Response | Error
168
175
  ): Promise<Error | RequestError | ResponseError> {
169
- if ('response' in error) {
170
- const err = error as AxiosError,
171
- status = err.response!.status,
172
- data = err.response!.data;
173
-
174
- const errorObj = await tryExtractErrorObject(data);
175
- if (errorObj) {
176
- return new ResponseError(status, errorObj.message, errorObj.desc, errorObj.error);
177
- } else {
178
- return new ResponseError(status, err.message, 'No error description provided');
179
- }
180
- } else if ('request' in error) {
181
- return new RequestError(error.message);
182
- } else {
183
- return error;
176
+ if (error instanceof ClientResponseError) {
177
+ return processResponseError(error.response, error.message);
178
+ }
179
+
180
+ if (typeof Response !== 'undefined' && error instanceof Response) {
181
+ return processResponseError(
182
+ error,
183
+ error.statusText || 'Response returned an error code'
184
+ );
184
185
  }
186
+
187
+ if (error instanceof FetchError) {
188
+ return new RequestError(error.cause.message);
189
+ }
190
+
191
+ return error instanceof Error ? error : new Error(String(error));
192
+ }
193
+
194
+ /** Converts a non-success Fetch response into the SDK's public response error. */
195
+ async function processResponseError(
196
+ response: Response,
197
+ fallbackMessage: string
198
+ ): Promise<ResponseError> {
199
+ const errorObj = await tryExtractErrorObject(await response.clone().text());
200
+
201
+ return errorObj
202
+ ? new ResponseError(
203
+ response.status,
204
+ errorObj.message,
205
+ errorObj.desc,
206
+ errorObj.error
207
+ )
208
+ : new ResponseError(
209
+ response.status,
210
+ fallbackMessage,
211
+ 'No error description provided'
212
+ );
185
213
  }