@robosystems/client 0.4.0 → 0.5.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 (56) hide show
  1. package/artifacts/InvestorClient.js +7 -7
  2. package/artifacts/InvestorClient.ts +13 -13
  3. package/artifacts/LedgerClient.d.ts +2 -2
  4. package/artifacts/LedgerClient.js +48 -48
  5. package/artifacts/LedgerClient.ts +91 -91
  6. package/client/client.gen.js +109 -126
  7. package/client/client.gen.ts +129 -139
  8. package/client/types.gen.d.ts +7 -4
  9. package/client/types.gen.ts +10 -5
  10. package/client/utils.gen.d.ts +7 -3
  11. package/client/utils.gen.js +6 -6
  12. package/client/utils.gen.ts +11 -11
  13. package/core/bodySerializer.gen.d.ts +4 -4
  14. package/core/bodySerializer.gen.ts +6 -8
  15. package/core/params.gen.js +5 -5
  16. package/core/params.gen.ts +5 -5
  17. package/core/serverSentEvents.gen.d.ts +1 -1
  18. package/core/serverSentEvents.gen.js +4 -6
  19. package/core/serverSentEvents.gen.ts +4 -5
  20. package/core/types.gen.d.ts +1 -1
  21. package/core/types.gen.ts +1 -1
  22. package/core/utils.gen.js +1 -1
  23. package/core/utils.gen.ts +1 -1
  24. package/index.ts +2 -2
  25. package/package.json +2 -2
  26. package/sdk/client/client.gen.js +109 -126
  27. package/sdk/client/client.gen.ts +129 -139
  28. package/sdk/client/types.gen.d.ts +7 -4
  29. package/sdk/client/types.gen.ts +10 -5
  30. package/sdk/client/utils.gen.d.ts +7 -3
  31. package/sdk/client/utils.gen.js +6 -6
  32. package/sdk/client/utils.gen.ts +11 -11
  33. package/sdk/core/bodySerializer.gen.d.ts +4 -4
  34. package/sdk/core/bodySerializer.gen.ts +6 -8
  35. package/sdk/core/params.gen.js +5 -5
  36. package/sdk/core/params.gen.ts +5 -5
  37. package/sdk/core/serverSentEvents.gen.d.ts +1 -1
  38. package/sdk/core/serverSentEvents.gen.js +4 -6
  39. package/sdk/core/serverSentEvents.gen.ts +4 -5
  40. package/sdk/core/types.gen.d.ts +1 -1
  41. package/sdk/core/types.gen.ts +1 -1
  42. package/sdk/core/utils.gen.js +1 -1
  43. package/sdk/core/utils.gen.ts +1 -1
  44. package/sdk/index.d.ts +2 -2
  45. package/sdk/index.js +68 -68
  46. package/sdk/index.ts +2 -2
  47. package/sdk/sdk.gen.d.ts +80 -80
  48. package/sdk/sdk.gen.js +154 -154
  49. package/sdk/sdk.gen.ts +89 -89
  50. package/sdk/types.gen.d.ts +374 -379
  51. package/sdk/types.gen.ts +379 -384
  52. package/sdk.gen.d.ts +80 -80
  53. package/sdk.gen.js +154 -154
  54. package/sdk.gen.ts +89 -89
  55. package/types.gen.d.ts +374 -379
  56. package/types.gen.ts +379 -384
@@ -22,10 +22,7 @@ const createClient = (config = {}) => {
22
22
  serializedBody: undefined,
23
23
  };
24
24
  if (opts.security) {
25
- await (0, utils_gen_2.setAuthParams)({
26
- ...opts,
27
- security: opts.security,
28
- });
25
+ await (0, utils_gen_2.setAuthParams)(opts);
29
26
  }
30
27
  if (opts.requestValidator) {
31
28
  await opts.requestValidator(opts);
@@ -37,153 +34,139 @@ const createClient = (config = {}) => {
37
34
  if (opts.body === undefined || opts.serializedBody === '') {
38
35
  opts.headers.delete('Content-Type');
39
36
  }
40
- const url = (0, utils_gen_2.buildUrl)(opts);
41
- return { opts, url };
37
+ const resolvedOpts = opts;
38
+ const url = (0, utils_gen_2.buildUrl)(resolvedOpts);
39
+ return { opts: resolvedOpts, url };
42
40
  };
43
41
  const request = async (options) => {
44
- const { opts, url } = await beforeRequest(options);
45
- const requestInit = {
46
- redirect: 'follow',
47
- ...opts,
48
- body: (0, utils_gen_1.getValidRequestBody)(opts),
49
- };
50
- let request = new Request(url, requestInit);
51
- for (const fn of interceptors.request.fns) {
52
- if (fn) {
53
- request = await fn(request, opts);
54
- }
55
- }
56
- // fetch must be assigned here, otherwise it would throw the error:
57
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
58
- const _fetch = opts.fetch;
42
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
43
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
44
+ let request;
59
45
  let response;
60
46
  try {
61
- response = await _fetch(request);
62
- }
63
- catch (error) {
64
- // Handle fetch exceptions (AbortError, network errors, etc.)
65
- let finalError = error;
66
- for (const fn of interceptors.error.fns) {
47
+ const { opts, url } = await beforeRequest(options);
48
+ const requestInit = {
49
+ redirect: 'follow',
50
+ ...opts,
51
+ body: (0, utils_gen_1.getValidRequestBody)(opts),
52
+ };
53
+ request = new Request(url, requestInit);
54
+ for (const fn of interceptors.request.fns) {
67
55
  if (fn) {
68
- finalError = (await fn(error, undefined, request, opts));
56
+ request = await fn(request, opts);
69
57
  }
70
58
  }
71
- finalError = finalError || {};
72
- if (opts.throwOnError) {
73
- throw finalError;
74
- }
75
- // Return error response
76
- return opts.responseStyle === 'data'
77
- ? undefined
78
- : {
79
- error: finalError,
80
- request,
81
- response: undefined,
82
- };
83
- }
84
- for (const fn of interceptors.response.fns) {
85
- if (fn) {
86
- response = await fn(response, request, opts);
59
+ // fetch must be assigned here, otherwise it would throw the error:
60
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
61
+ const _fetch = opts.fetch;
62
+ response = await _fetch(request);
63
+ for (const fn of interceptors.response.fns) {
64
+ if (fn) {
65
+ response = await fn(response, request, opts);
66
+ }
87
67
  }
88
- }
89
- const result = {
90
- request,
91
- response,
92
- };
93
- if (response.ok) {
94
- const parseAs = (opts.parseAs === 'auto'
95
- ? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
96
- : opts.parseAs) ?? 'json';
97
- if (response.status === 204 || response.headers.get('Content-Length') === '0') {
98
- let emptyData;
68
+ const result = {
69
+ request,
70
+ response,
71
+ };
72
+ if (response.ok) {
73
+ const parseAs = (opts.parseAs === 'auto'
74
+ ? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
75
+ : opts.parseAs) ?? 'json';
76
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
77
+ let emptyData;
78
+ switch (parseAs) {
79
+ case 'arrayBuffer':
80
+ case 'blob':
81
+ case 'text':
82
+ emptyData = await response[parseAs]();
83
+ break;
84
+ case 'formData':
85
+ emptyData = new FormData();
86
+ break;
87
+ case 'stream':
88
+ emptyData = response.body;
89
+ break;
90
+ case 'json':
91
+ default:
92
+ emptyData = {};
93
+ break;
94
+ }
95
+ return opts.responseStyle === 'data'
96
+ ? emptyData
97
+ : {
98
+ data: emptyData,
99
+ ...result,
100
+ };
101
+ }
102
+ let data;
99
103
  switch (parseAs) {
100
104
  case 'arrayBuffer':
101
105
  case 'blob':
106
+ case 'formData':
102
107
  case 'text':
103
- emptyData = await response[parseAs]();
108
+ data = await response[parseAs]();
104
109
  break;
105
- case 'formData':
106
- emptyData = new FormData();
110
+ case 'json': {
111
+ // Some servers return 200 with no Content-Length and empty body.
112
+ // response.json() would throw; read as text and parse if non-empty.
113
+ const text = await response.text();
114
+ data = text ? JSON.parse(text) : {};
107
115
  break;
116
+ }
108
117
  case 'stream':
109
- emptyData = response.body;
110
- break;
111
- case 'json':
112
- default:
113
- emptyData = {};
114
- break;
118
+ return opts.responseStyle === 'data'
119
+ ? response.body
120
+ : {
121
+ data: response.body,
122
+ ...result,
123
+ };
124
+ }
125
+ if (parseAs === 'json') {
126
+ if (opts.responseValidator) {
127
+ await opts.responseValidator(data);
128
+ }
129
+ if (opts.responseTransformer) {
130
+ data = await opts.responseTransformer(data);
131
+ }
115
132
  }
116
133
  return opts.responseStyle === 'data'
117
- ? emptyData
134
+ ? data
118
135
  : {
119
- data: emptyData,
136
+ data,
120
137
  ...result,
121
138
  };
122
139
  }
123
- let data;
124
- switch (parseAs) {
125
- case 'arrayBuffer':
126
- case 'blob':
127
- case 'formData':
128
- case 'text':
129
- data = await response[parseAs]();
130
- break;
131
- case 'json': {
132
- // Some servers return 200 with no Content-Length and empty body.
133
- // response.json() would throw; read as text and parse if non-empty.
134
- const text = await response.text();
135
- data = text ? JSON.parse(text) : {};
136
- break;
137
- }
138
- case 'stream':
139
- return opts.responseStyle === 'data'
140
- ? response.body
141
- : {
142
- data: response.body,
143
- ...result,
144
- };
140
+ const textError = await response.text();
141
+ let jsonError;
142
+ try {
143
+ jsonError = JSON.parse(textError);
145
144
  }
146
- if (parseAs === 'json') {
147
- if (opts.responseValidator) {
148
- await opts.responseValidator(data);
149
- }
150
- if (opts.responseTransformer) {
151
- data = await opts.responseTransformer(data);
145
+ catch {
146
+ // noop
147
+ }
148
+ throw jsonError ?? textError;
149
+ }
150
+ catch (error) {
151
+ let finalError = error;
152
+ for (const fn of interceptors.error.fns) {
153
+ if (fn) {
154
+ finalError = await fn(finalError, response, request, options);
152
155
  }
153
156
  }
154
- return opts.responseStyle === 'data'
155
- ? data
157
+ finalError = finalError || {};
158
+ if (throwOnError) {
159
+ throw finalError;
160
+ }
161
+ // TODO: we probably want to return error and improve types
162
+ return responseStyle === 'data'
163
+ ? undefined
156
164
  : {
157
- data,
158
- ...result,
165
+ error: finalError,
166
+ request,
167
+ response,
159
168
  };
160
169
  }
161
- const textError = await response.text();
162
- let jsonError;
163
- try {
164
- jsonError = JSON.parse(textError);
165
- }
166
- catch {
167
- // noop
168
- }
169
- const error = jsonError ?? textError;
170
- let finalError = error;
171
- for (const fn of interceptors.error.fns) {
172
- if (fn) {
173
- finalError = (await fn(error, response, request, opts));
174
- }
175
- }
176
- finalError = finalError || {};
177
- if (opts.throwOnError) {
178
- throw finalError;
179
- }
180
- // TODO: we probably want to return error and improve types
181
- return opts.responseStyle === 'data'
182
- ? undefined
183
- : {
184
- error: finalError,
185
- ...result,
186
- };
187
170
  };
188
171
  const makeMethodFn = (method) => (options) => request({ ...options, method });
189
172
  const makeSseFn = (method) => async (options) => {
@@ -191,7 +174,6 @@ const createClient = (config = {}) => {
191
174
  return (0, serverSentEvents_gen_1.createSseClient)({
192
175
  ...opts,
193
176
  body: opts.body,
194
- headers: opts.headers,
195
177
  method,
196
178
  onRequest: async (url, init) => {
197
179
  let request = new Request(url, init);
@@ -206,8 +188,9 @@ const createClient = (config = {}) => {
206
188
  url,
207
189
  });
208
190
  };
191
+ const _buildUrl = (options) => (0, utils_gen_2.buildUrl)({ ..._config, ...options });
209
192
  return {
210
- buildUrl: utils_gen_2.buildUrl,
193
+ buildUrl: _buildUrl,
211
194
  connect: makeMethodFn('CONNECT'),
212
195
  delete: makeMethodFn('DELETE'),
213
196
  get: makeMethodFn('GET'),
@@ -31,20 +31,24 @@ export const createClient = (config: Config = {}): Client => {
31
31
 
32
32
  const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
33
33
 
34
- const beforeRequest = async (options: RequestOptions) => {
34
+ const beforeRequest = async <
35
+ TData = unknown,
36
+ TResponseStyle extends 'data' | 'fields' = 'fields',
37
+ ThrowOnError extends boolean = boolean,
38
+ Url extends string = string,
39
+ >(
40
+ options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
41
+ ) => {
35
42
  const opts = {
36
43
  ..._config,
37
44
  ...options,
38
45
  fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
39
46
  headers: mergeHeaders(_config.headers, options.headers),
40
- serializedBody: undefined,
47
+ serializedBody: undefined as string | undefined,
41
48
  };
42
49
 
43
50
  if (opts.security) {
44
- await setAuthParams({
45
- ...opts,
46
- security: opts.security,
47
- });
51
+ await setAuthParams(opts);
48
52
  }
49
53
 
50
54
  if (opts.requestValidator) {
@@ -52,7 +56,7 @@ export const createClient = (config: Config = {}): Client => {
52
56
  }
53
57
 
54
58
  if (opts.body !== undefined && opts.bodySerializer) {
55
- opts.serializedBody = opts.bodySerializer(opts.body);
59
+ opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
56
60
  }
57
61
 
58
62
  // remove Content-Type header if body is empty to avoid sending invalid requests
@@ -60,177 +64,162 @@ export const createClient = (config: Config = {}): Client => {
60
64
  opts.headers.delete('Content-Type');
61
65
  }
62
66
 
63
- const url = buildUrl(opts);
67
+ const resolvedOpts = opts as typeof opts &
68
+ ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
69
+ const url = buildUrl(resolvedOpts);
64
70
 
65
- return { opts, url };
71
+ return { opts: resolvedOpts, url };
66
72
  };
67
73
 
68
74
  const request: Client['request'] = async (options) => {
69
- const { opts, url } = await beforeRequest(options);
70
- const requestInit: ReqInit = {
71
- redirect: 'follow',
72
- ...opts,
73
- body: getValidRequestBody(opts),
74
- };
75
-
76
- let request = new Request(url, requestInit);
75
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
76
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
77
77
 
78
- for (const fn of interceptors.request.fns) {
79
- if (fn) {
80
- request = await fn(request, opts);
81
- }
82
- }
83
-
84
- // fetch must be assigned here, otherwise it would throw the error:
85
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
86
- const _fetch = opts.fetch!;
87
- let response: Response;
78
+ let request: Request | undefined;
79
+ let response: Response | undefined;
88
80
 
89
81
  try {
90
- response = await _fetch(request);
91
- } catch (error) {
92
- // Handle fetch exceptions (AbortError, network errors, etc.)
93
- let finalError = error;
82
+ const { opts, url } = await beforeRequest(options);
83
+ const requestInit: ReqInit = {
84
+ redirect: 'follow',
85
+ ...opts,
86
+ body: getValidRequestBody(opts),
87
+ };
94
88
 
95
- for (const fn of interceptors.error.fns) {
89
+ request = new Request(url, requestInit);
90
+
91
+ for (const fn of interceptors.request.fns) {
96
92
  if (fn) {
97
- finalError = (await fn(error, undefined as any, request, opts)) as unknown;
93
+ request = await fn(request, opts);
98
94
  }
99
95
  }
100
96
 
101
- finalError = finalError || ({} as unknown);
97
+ // fetch must be assigned here, otherwise it would throw the error:
98
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
99
+ const _fetch = opts.fetch!;
102
100
 
103
- if (opts.throwOnError) {
104
- throw finalError;
105
- }
106
-
107
- // Return error response
108
- return opts.responseStyle === 'data'
109
- ? undefined
110
- : {
111
- error: finalError,
112
- request,
113
- response: undefined as any,
114
- };
115
- }
101
+ response = await _fetch(request);
116
102
 
117
- for (const fn of interceptors.response.fns) {
118
- if (fn) {
119
- response = await fn(response, request, opts);
103
+ for (const fn of interceptors.response.fns) {
104
+ if (fn) {
105
+ response = await fn(response, request, opts);
106
+ }
120
107
  }
121
- }
122
-
123
- const result = {
124
- request,
125
- response,
126
- };
127
108
 
128
- if (response.ok) {
129
- const parseAs =
130
- (opts.parseAs === 'auto'
131
- ? getParseAs(response.headers.get('Content-Type'))
132
- : opts.parseAs) ?? 'json';
109
+ const result = {
110
+ request,
111
+ response,
112
+ };
113
+
114
+ if (response.ok) {
115
+ const parseAs =
116
+ (opts.parseAs === 'auto'
117
+ ? getParseAs(response.headers.get('Content-Type'))
118
+ : opts.parseAs) ?? 'json';
119
+
120
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
121
+ let emptyData: any;
122
+ switch (parseAs) {
123
+ case 'arrayBuffer':
124
+ case 'blob':
125
+ case 'text':
126
+ emptyData = await response[parseAs]();
127
+ break;
128
+ case 'formData':
129
+ emptyData = new FormData();
130
+ break;
131
+ case 'stream':
132
+ emptyData = response.body;
133
+ break;
134
+ case 'json':
135
+ default:
136
+ emptyData = {};
137
+ break;
138
+ }
139
+ return opts.responseStyle === 'data'
140
+ ? emptyData
141
+ : {
142
+ data: emptyData,
143
+ ...result,
144
+ };
145
+ }
133
146
 
134
- if (response.status === 204 || response.headers.get('Content-Length') === '0') {
135
- let emptyData: any;
147
+ let data: any;
136
148
  switch (parseAs) {
137
149
  case 'arrayBuffer':
138
150
  case 'blob':
151
+ case 'formData':
139
152
  case 'text':
140
- emptyData = await response[parseAs]();
153
+ data = await response[parseAs]();
141
154
  break;
142
- case 'formData':
143
- emptyData = new FormData();
155
+ case 'json': {
156
+ // Some servers return 200 with no Content-Length and empty body.
157
+ // response.json() would throw; read as text and parse if non-empty.
158
+ const text = await response.text();
159
+ data = text ? JSON.parse(text) : {};
144
160
  break;
161
+ }
145
162
  case 'stream':
146
- emptyData = response.body;
147
- break;
148
- case 'json':
149
- default:
150
- emptyData = {};
151
- break;
163
+ return opts.responseStyle === 'data'
164
+ ? response.body
165
+ : {
166
+ data: response.body,
167
+ ...result,
168
+ };
169
+ }
170
+
171
+ if (parseAs === 'json') {
172
+ if (opts.responseValidator) {
173
+ await opts.responseValidator(data);
174
+ }
175
+
176
+ if (opts.responseTransformer) {
177
+ data = await opts.responseTransformer(data);
178
+ }
152
179
  }
180
+
153
181
  return opts.responseStyle === 'data'
154
- ? emptyData
182
+ ? data
155
183
  : {
156
- data: emptyData,
184
+ data,
157
185
  ...result,
158
186
  };
159
187
  }
160
188
 
161
- let data: any;
162
- switch (parseAs) {
163
- case 'arrayBuffer':
164
- case 'blob':
165
- case 'formData':
166
- case 'text':
167
- data = await response[parseAs]();
168
- break;
169
- case 'json': {
170
- // Some servers return 200 with no Content-Length and empty body.
171
- // response.json() would throw; read as text and parse if non-empty.
172
- const text = await response.text();
173
- data = text ? JSON.parse(text) : {};
174
- break;
175
- }
176
- case 'stream':
177
- return opts.responseStyle === 'data'
178
- ? response.body
179
- : {
180
- data: response.body,
181
- ...result,
182
- };
189
+ const textError = await response.text();
190
+ let jsonError: unknown;
191
+
192
+ try {
193
+ jsonError = JSON.parse(textError);
194
+ } catch {
195
+ // noop
183
196
  }
184
197
 
185
- if (parseAs === 'json') {
186
- if (opts.responseValidator) {
187
- await opts.responseValidator(data);
188
- }
198
+ throw jsonError ?? textError;
199
+ } catch (error) {
200
+ let finalError = error;
189
201
 
190
- if (opts.responseTransformer) {
191
- data = await opts.responseTransformer(data);
202
+ for (const fn of interceptors.error.fns) {
203
+ if (fn) {
204
+ finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
192
205
  }
193
206
  }
194
207
 
195
- return opts.responseStyle === 'data'
196
- ? data
197
- : {
198
- data,
199
- ...result,
200
- };
201
- }
208
+ finalError = finalError || {};
202
209
 
203
- const textError = await response.text();
204
- let jsonError: unknown;
205
-
206
- try {
207
- jsonError = JSON.parse(textError);
208
- } catch {
209
- // noop
210
- }
211
-
212
- const error = jsonError ?? textError;
213
- let finalError = error;
214
-
215
- for (const fn of interceptors.error.fns) {
216
- if (fn) {
217
- finalError = (await fn(error, response, request, opts)) as string;
210
+ if (throwOnError) {
211
+ throw finalError;
218
212
  }
219
- }
220
-
221
- finalError = finalError || ({} as string);
222
213
 
223
- if (opts.throwOnError) {
224
- throw finalError;
214
+ // TODO: we probably want to return error and improve types
215
+ return responseStyle === 'data'
216
+ ? undefined
217
+ : {
218
+ error: finalError,
219
+ request,
220
+ response,
221
+ };
225
222
  }
226
-
227
- // TODO: we probably want to return error and improve types
228
- return opts.responseStyle === 'data'
229
- ? undefined
230
- : {
231
- error: finalError,
232
- ...result,
233
- };
234
223
  };
235
224
 
236
225
  const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
@@ -241,7 +230,6 @@ export const createClient = (config: Config = {}): Client => {
241
230
  return createSseClient({
242
231
  ...opts,
243
232
  body: opts.body as BodyInit | null | undefined,
244
- headers: opts.headers as unknown as Record<string, string>,
245
233
  method,
246
234
  onRequest: async (url, init) => {
247
235
  let request = new Request(url, init);
@@ -257,8 +245,10 @@ export const createClient = (config: Config = {}): Client => {
257
245
  });
258
246
  };
259
247
 
248
+ const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options });
249
+
260
250
  return {
261
- buildUrl,
251
+ buildUrl: _buildUrl,
262
252
  connect: makeMethodFn('CONNECT'),
263
253
  delete: makeMethodFn('DELETE'),
264
254
  get: makeMethodFn('GET'),