@shapediver/sdk.geometry-api-sdk-v2 2.9.1 → 3.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.
@@ -4,7 +4,7 @@
4
4
  * Geometry Backend API v2
5
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
6
  *
7
- * The version of the OpenAPI document: 1.13.0
7
+ * The version of the OpenAPI document: 2.0.0
8
8
  *
9
9
  *
10
10
  * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -21,10 +21,6 @@ import globalAxios from 'axios';
21
21
 
22
22
  export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
23
23
 
24
- /**
25
- *
26
- * @export
27
- */
28
24
  export const COLLECTION_FORMATS = {
29
25
  csv: ",",
30
26
  ssv: " ",
@@ -32,21 +28,11 @@ export const COLLECTION_FORMATS = {
32
28
  pipes: "|",
33
29
  };
34
30
 
35
- /**
36
- *
37
- * @export
38
- * @interface RequestArgs
39
- */
40
31
  export interface RequestArgs {
41
32
  url: string;
42
33
  options: RawAxiosRequestConfig;
43
34
  }
44
35
 
45
- /**
46
- *
47
- * @export
48
- * @class BaseAPI
49
- */
50
36
  export class BaseAPI {
51
37
  protected configuration: Configuration | undefined;
52
38
 
@@ -58,12 +44,6 @@ export class BaseAPI {
58
44
  }
59
45
  };
60
46
 
61
- /**
62
- *
63
- * @export
64
- * @class RequiredError
65
- * @extends {Error}
66
- */
67
47
  export class RequiredError extends Error {
68
48
  constructor(public field: string, msg?: string) {
69
49
  super(msg);
@@ -78,9 +58,5 @@ interface ServerMap {
78
58
  }[];
79
59
  }
80
60
 
81
- /**
82
- *
83
- * @export
84
- */
85
61
  export const operationServerMap: ServerMap = {
86
62
  }
@@ -4,7 +4,7 @@
4
4
  * Geometry Backend API v2
5
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
6
  *
7
- * The version of the OpenAPI document: 1.13.0
7
+ * The version of the OpenAPI document: 2.0.0
8
8
  *
9
9
  *
10
10
  * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -12,22 +12,16 @@
12
12
  * Do not edit the class manually.
13
13
  */
14
14
 
15
-
16
15
  import type { Configuration } from "./configuration";
17
16
  import type { RequestArgs } from "./base";
18
17
  import type { AxiosInstance, AxiosResponse } from 'axios';
19
18
  import { RequiredError } from "./base";
20
19
 
21
- /**
22
- *
23
- * @export
24
- */
25
20
  export const DUMMY_BASE_URL = 'https://example.com'
26
21
 
27
22
  /**
28
23
  *
29
24
  * @throws {RequiredError}
30
- * @export
31
25
  */
32
26
  export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
33
27
  if (paramValue === null || paramValue === undefined) {
@@ -35,10 +29,6 @@ export const assertParamExists = function (functionName: string, paramName: stri
35
29
  }
36
30
  }
37
31
 
38
- /**
39
- *
40
- * @export
41
- */
42
32
  export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
43
33
  if (configuration && configuration.apiKey) {
44
34
  const localVarApiKeyValue = typeof configuration.apiKey === 'function'
@@ -48,20 +38,12 @@ export const setApiKeyToObject = async function (object: any, keyParamName: stri
48
38
  }
49
39
  }
50
40
 
51
- /**
52
- *
53
- * @export
54
- */
55
41
  export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
56
42
  if (configuration && (configuration.username || configuration.password)) {
57
43
  object["auth"] = { username: configuration.username, password: configuration.password };
58
44
  }
59
45
  }
60
46
 
61
- /**
62
- *
63
- * @export
64
- */
65
47
  export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
66
48
  if (configuration && configuration.accessToken) {
67
49
  const accessToken = typeof configuration.accessToken === 'function'
@@ -71,10 +53,6 @@ export const setBearerAuthToObject = async function (object: any, configuration?
71
53
  }
72
54
  }
73
55
 
74
- /**
75
- *
76
- * @export
77
- */
78
56
  export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
79
57
  if (configuration && configuration.accessToken) {
80
58
  const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
@@ -84,42 +62,35 @@ export const setOAuthToObject = async function (object: any, name: string, scope
84
62
  }
85
63
  }
86
64
 
65
+
87
66
  function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
88
67
  if (parameter == null) return;
89
68
  if (typeof parameter === "object") {
90
69
  if (Array.isArray(parameter)) {
91
70
  (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92
- }
71
+ }
93
72
  else {
94
- Object.keys(parameter).forEach(currentKey =>
73
+ Object.keys(parameter).forEach(currentKey =>
95
74
  setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
96
75
  );
97
76
  }
98
- }
77
+ }
99
78
  else {
100
79
  if (urlSearchParams.has(key)) {
101
80
  urlSearchParams.append(key, parameter);
102
- }
81
+ }
103
82
  else {
104
83
  urlSearchParams.set(key, parameter);
105
84
  }
106
85
  }
107
86
  }
108
87
 
109
- /**
110
- *
111
- * @export
112
- */
113
88
  export const setSearchParams = function (url: URL, ...objects: any[]) {
114
89
  const searchParams = new URLSearchParams(url.search);
115
90
  setFlattenedQueryParams(searchParams, objects);
116
91
  url.search = searchParams.toString();
117
92
  }
118
93
 
119
- /**
120
- *
121
- * @export
122
- */
123
94
  export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
124
95
  const nonString = typeof value !== 'string';
125
96
  const needsSerialization = nonString && configuration && configuration.isJsonMime
@@ -130,18 +101,10 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any,
130
101
  : (value || "");
131
102
  }
132
103
 
133
- /**
134
- *
135
- * @export
136
- */
137
104
  export const toPathString = function (url: URL) {
138
105
  return url.pathname + url.search + url.hash
139
106
  }
140
107
 
141
- /**
142
- *
143
- * @export
144
- */
145
108
  export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
146
109
  return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
147
110
  const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
@@ -1,10 +1,9 @@
1
1
  /* tslint:disable */
2
- /* eslint-disable */
3
2
  /**
4
3
  * Geometry Backend API v2
5
4
  * 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
5
  *
7
- * The version of the OpenAPI document: 1.13.0
6
+ * The version of the OpenAPI document: 2.0.0
8
7
  *
9
8
  *
10
9
  * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -12,12 +11,24 @@
12
11
  * Do not edit the class manually.
13
12
  */
14
13
 
14
+ interface AWSv4Configuration {
15
+ options?: {
16
+ region?: string
17
+ service?: string
18
+ }
19
+ credentials?: {
20
+ accessKeyId?: string
21
+ secretAccessKey?: string,
22
+ sessionToken?: string
23
+ }
24
+ }
15
25
 
16
26
  export interface ConfigurationParameters {
17
27
  apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
18
28
  username?: string;
19
29
  password?: string;
20
30
  accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
31
+ awsv4?: AWSv4Configuration;
21
32
  basePath?: string;
22
33
  serverIndex?: number;
23
34
  baseOptions?: any;
@@ -28,49 +39,43 @@ export class Configuration {
28
39
  /**
29
40
  * parameter for apiKey security
30
41
  * @param name security name
31
- * @memberof Configuration
32
42
  */
33
43
  apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
34
44
  /**
35
45
  * parameter for basic security
36
- *
37
- * @type {string}
38
- * @memberof Configuration
39
46
  */
40
47
  username?: string;
41
48
  /**
42
49
  * parameter for basic security
43
- *
44
- * @type {string}
45
- * @memberof Configuration
46
50
  */
47
51
  password?: string;
48
52
  /**
49
53
  * parameter for oauth2 security
50
54
  * @param name security name
51
55
  * @param scopes oauth2 scope
52
- * @memberof Configuration
53
56
  */
54
57
  accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
55
58
  /**
56
- * override base path
57
- *
58
- * @type {string}
59
+ * parameter for aws4 signature security
60
+ * @param {Object} AWS4Signature - AWS4 Signature security
61
+ * @param {string} options.region - aws region
62
+ * @param {string} options.service - name of the service.
63
+ * @param {string} credentials.accessKeyId - aws access key id
64
+ * @param {string} credentials.secretAccessKey - aws access key
65
+ * @param {string} credentials.sessionToken - aws session token
59
66
  * @memberof Configuration
60
67
  */
68
+ awsv4?: AWSv4Configuration;
69
+ /**
70
+ * override base path
71
+ */
61
72
  basePath?: string;
62
73
  /**
63
74
  * override server index
64
- *
65
- * @type {number}
66
- * @memberof Configuration
67
75
  */
68
76
  serverIndex?: number;
69
77
  /**
70
78
  * base options for axios calls
71
- *
72
- * @type {any}
73
- * @memberof Configuration
74
79
  */
75
80
  baseOptions?: any;
76
81
  /**
@@ -87,6 +92,7 @@ export class Configuration {
87
92
  this.username = param.username;
88
93
  this.password = param.password;
89
94
  this.accessToken = param.accessToken;
95
+ this.awsv4 = param.awsv4;
90
96
  this.basePath = param.basePath;
91
97
  this.serverIndex = param.serverIndex;
92
98
  this.baseOptions = {
@@ -4,7 +4,7 @@
4
4
  * Geometry Backend API v2
5
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
6
  *
7
- * The version of the OpenAPI document: 1.13.0
7
+ * The version of the OpenAPI document: 2.0.0
8
8
  *
9
9
  *
10
10
  * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -34,7 +34,7 @@ export interface ConfigurationParameters
34
34
  }
35
35
 
36
36
  export class Configuration extends ClientConfig {
37
- protected readonly sdkVersion = '2.9.1'; // WARNING: This value is updated automatically!
37
+ protected readonly sdkVersion = '3.0.0'; // WARNING: This value is updated automatically!
38
38
 
39
39
  public readonly useCustomAxios: boolean;
40
40
  public readonly maxRetries: number;
package/src/utils.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import { AxiosError, AxiosPromise } from 'axios';
2
2
  import { RequestError, ResponseError } from './error';
3
3
 
4
+ /** ShapeDiver error object structure. */
5
+ type SdErrorObject = {
6
+ error: string;
7
+ desc: string;
8
+ message: string;
9
+ };
10
+
4
11
  /** Delays the response for the given number of milliseconds */
5
12
  export function sleep(ms: number): Promise<void> {
6
13
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -92,28 +99,81 @@ export async function exists(apiCall: () => AxiosPromise<unknown>): Promise<bool
92
99
  });
93
100
  }
94
101
 
102
+ /** Type Guard for the ShapeDiver error data object. */
103
+ function isErrorObject(value: unknown): value is SdErrorObject {
104
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
105
+
106
+ const obj = value as Record<string, unknown>;
107
+ return (
108
+ typeof obj.error === 'string' &&
109
+ typeof obj.desc === 'string' &&
110
+ typeof obj.message === 'string'
111
+ );
112
+ }
113
+
114
+ /** Helper function that wraps JSON.parse and returns undefined on failure. */
115
+ async function tryParseJson(
116
+ input: string | (() => string) | (() => Promise<string>)
117
+ ): Promise<unknown | undefined> {
118
+ try {
119
+ const text = typeof input === 'function' ? await input() : input;
120
+ return JSON.parse(text);
121
+ } catch {
122
+ return undefined;
123
+ }
124
+ }
125
+
126
+ function isArrayBuffer(value: unknown): value is ArrayBuffer {
127
+ return Object.prototype.toString.call(value) === '[object ArrayBuffer]';
128
+ }
129
+
130
+ function isArrayBufferView(value: unknown): value is ArrayBufferView {
131
+ return ArrayBuffer.isView(value);
132
+ }
133
+
134
+ /**
135
+ * Tries to extract an error object from various Axios response data types.
136
+ * @param data The data to extract from.
137
+ * @returns The extracted error object, or undefined if none could be found.
138
+ */
139
+ export async function tryExtractErrorObject(data: unknown): Promise<SdErrorObject | undefined> {
140
+ let candidate: unknown;
141
+
142
+ if (typeof data === 'string') {
143
+ candidate = await tryParseJson(data);
144
+ } else if (isArrayBufferView(data)) {
145
+ candidate = await tryParseJson(() =>
146
+ new TextDecoder().decode(new Uint8Array(data.buffer, data.byteOffset, data.byteLength))
147
+ );
148
+ } else if (isArrayBuffer(data)) {
149
+ candidate = await tryParseJson(() => new TextDecoder().decode(new Uint8Array(data)));
150
+ } else if (typeof Blob !== 'undefined' && data instanceof Blob) {
151
+ candidate = await tryParseJson(async () => await data.text());
152
+ } else {
153
+ candidate = data;
154
+ }
155
+
156
+ return isErrorObject(candidate)
157
+ ? { error: candidate.error, desc: candidate.desc, message: candidate.message }
158
+ : undefined;
159
+ }
160
+
95
161
  /**
96
162
  * Tries to convert a generic Axios error into a more specific ShapeDiver error. When no match is
97
163
  * found, the original error is returned instead.
98
164
  * @param error The Axios error to convert.
99
165
  */
100
- export function processError(error: AxiosError | Error): Error | RequestError | ResponseError {
166
+ export async function processError(
167
+ error: AxiosError | Error
168
+ ): Promise<Error | RequestError | ResponseError> {
101
169
  if ('response' in error) {
102
170
  const err = error as AxiosError,
103
171
  status = err.response!.status,
104
172
  data = err.response!.data;
105
173
 
106
- if (
107
- data &&
108
- typeof data === 'object' &&
109
- 'desc' in data &&
110
- typeof data.desc === 'string' &&
111
- 'error' in data &&
112
- typeof data.error === 'string' &&
113
- 'message' in data &&
114
- typeof data.message === 'string'
115
- ) {
116
- return new ResponseError(status, data.message, data.desc, data.error);
174
+ const errorObj = await tryExtractErrorObject(data);
175
+ if (errorObj) {
176
+ return new ResponseError(status, errorObj.message, errorObj.desc, errorObj.error);
117
177
  } else {
118
178
  return new ResponseError(status, err.message, 'No error description provided');
119
179
  }