@platformatic/watt-extra 0.1.9 → 1.0.1-alpha.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,6 +4,9 @@
4
4
  let baseUrl = ''
5
5
  // The default headers to send within each request. This can be overridden by calling `setDefaultHeaders`.
6
6
  let defaultHeaders = {}
7
+ // The additional parameters you want to pass to the `fetch` instance.
8
+ let defaultFetchParams = {}
9
+ const defaultJsonType = { 'Content-type': 'application/json; charset=utf-8' }
7
10
 
8
11
  function sanitizeUrl(url) {
9
12
  if (url.endsWith('/')) { return url.slice(0, -1) } else { return url }
@@ -14,6 +17,9 @@ export const setBaseUrl = (newUrl) => { baseUrl = sanitizeUrl(newUrl) }
14
17
  /** @type {import('./compliance-types.d.ts').Compliance['setDefaultHeaders']} */
15
18
  export const setDefaultHeaders = (headers) => { defaultHeaders = headers }
16
19
 
20
+ /** @type {import('./compliance-types.d.ts').Compliance['setDefaultFetchParams']} */
21
+ export const setDefaultFetchParams = (fetchParams) => { defaultFetchParams = fetchParams }
22
+
17
23
  function headersToJSON(headers) {
18
24
  const output = {}
19
25
  headers.forEach((value, key) => {
@@ -23,34 +29,45 @@ function headersToJSON(headers) {
23
29
  }
24
30
 
25
31
  async function _getReports (url, request) {
26
- const queryParameters = ['limit', 'offset', 'totalCount', 'fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.bundleId.eq', 'where.bundleId.neq', 'where.bundleId.gt', 'where.bundleId.gte', 'where.bundleId.lt', 'where.bundleId.lte', 'where.bundleId.like', 'where.bundleId.in', 'where.bundleId.nin', 'where.bundleId.contains', 'where.bundleId.contained', 'where.bundleId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.result.eq', 'where.result.neq', 'where.result.gt', 'where.result.gte', 'where.result.lt', 'where.result.lte', 'where.result.like', 'where.result.in', 'where.result.nin', 'where.result.contains', 'where.result.contained', 'where.result.overlaps', 'where.ruleSet.eq', 'where.ruleSet.neq', 'where.ruleSet.gt', 'where.ruleSet.gte', 'where.ruleSet.lt', 'where.ruleSet.lte', 'where.ruleSet.like', 'where.ruleSet.in', 'where.ruleSet.nin', 'where.ruleSet.contains', 'where.ruleSet.contained', 'where.ruleSet.overlaps', 'where.or', 'orderby.applicationId', 'orderby.bundleId', 'orderby.createdAt', 'orderby.id', 'orderby.result', 'orderby.ruleSet']
32
+ const queryParameters = ['limit', 'offset', 'totalCount', 'cursor', 'startAfter', 'endBefore', 'fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.ilike', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.ilike', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.ilike', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.result.eq', 'where.result.neq', 'where.result.gt', 'where.result.gte', 'where.result.lt', 'where.result.lte', 'where.result.like', 'where.result.ilike', 'where.result.in', 'where.result.nin', 'where.result.contains', 'where.result.contained', 'where.result.overlaps', 'where.ruleSet.eq', 'where.ruleSet.neq', 'where.ruleSet.gt', 'where.ruleSet.gte', 'where.ruleSet.lt', 'where.ruleSet.lte', 'where.ruleSet.like', 'where.ruleSet.ilike', 'where.ruleSet.in', 'where.ruleSet.nin', 'where.ruleSet.contains', 'where.ruleSet.contained', 'where.ruleSet.overlaps', 'where.or', 'orderby.applicationId', 'orderby.createdAt', 'orderby.id', 'orderby.result', 'orderby.ruleSet']
27
33
  const searchParams = new URLSearchParams()
28
- queryParameters.forEach((qp) => {
29
- if (request[qp]) {
30
- if (Array.isArray(request[qp])) {
31
- request[qp].forEach((p) => {
32
- searchParams.append(qp, p)
33
- })
34
- } else {
35
- searchParams.append(qp, request[qp]?.toString() || '')
34
+ if (request.query) {
35
+ queryParameters.forEach((qp) => {
36
+ const queryValue = request.query?.[qp]
37
+ if (queryValue) {
38
+ if (Array.isArray(queryValue)) {
39
+ queryValue.forEach((p) => searchParams.append(qp, p))
40
+ } else {
41
+ searchParams.append(qp, queryValue.toString())
42
+ }
36
43
  }
37
- }
38
- delete request[qp]
39
- })
44
+ delete request.query?.[qp]
45
+ })
46
+ }
40
47
 
41
48
  const headers = {
42
49
  ...defaultHeaders
43
50
  }
44
51
 
45
52
  const response = await fetch(`${url}/reports/?${searchParams.toString()}`, {
46
- headers
53
+ headers,
54
+ ...defaultFetchParams
47
55
  })
48
56
 
49
- if (!response.ok) {
50
- throw new Error(await response.text())
57
+ const jsonResponses = [200]
58
+ if (jsonResponses.includes(response.status)) {
59
+ return {
60
+ statusCode: response.status,
61
+ headers: headersToJSON(response.headers),
62
+ body: await response.json()
63
+ }
64
+ }
65
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
66
+ return {
67
+ statusCode: response.status,
68
+ headers: headersToJSON(response.headers),
69
+ body: await response[responseType]()
51
70
  }
52
-
53
- return await response.json()
54
71
  }
55
72
 
56
73
  /** @type {import('./compliance-types.d.ts').Compliance['getReports']} */
@@ -58,22 +75,50 @@ export const getReports = async (request) => {
58
75
  return await _getReports(baseUrl, request)
59
76
  }
60
77
  async function _createReport (url, request) {
78
+ const queryParameters = ['fields']
79
+ const searchParams = new URLSearchParams()
80
+ if (request.query) {
81
+ queryParameters.forEach((qp) => {
82
+ const queryValue = request.query?.[qp]
83
+ if (queryValue) {
84
+ if (Array.isArray(queryValue)) {
85
+ queryValue.forEach((p) => searchParams.append(qp, p))
86
+ } else {
87
+ searchParams.append(qp, queryValue.toString())
88
+ }
89
+ }
90
+ delete request.query?.[qp]
91
+ })
92
+ }
93
+
94
+ const body = 'body' in request ? (request.body) : undefined
95
+ const isFormData = body instanceof FormData
61
96
  const headers = {
62
97
  ...defaultHeaders,
63
- 'Content-type': 'application/json; charset=utf-8'
98
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
64
99
  }
65
100
 
66
- const response = await fetch(`${url}/reports/`, {
101
+ const response = await fetch(`${url}/reports/?${searchParams.toString()}`, {
67
102
  method: 'POST',
68
- body: JSON.stringify(request),
69
- headers
103
+ body: isFormData ? body : JSON.stringify(body),
104
+ headers,
105
+ ...defaultFetchParams
70
106
  })
71
107
 
72
- if (!response.ok) {
73
- throw new Error(await response.text())
108
+ const jsonResponses = [200]
109
+ if (jsonResponses.includes(response.status)) {
110
+ return {
111
+ statusCode: response.status,
112
+ headers: headersToJSON(response.headers),
113
+ body: await response.json()
114
+ }
115
+ }
116
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
117
+ return {
118
+ statusCode: response.status,
119
+ headers: headersToJSON(response.headers),
120
+ body: await response[responseType]()
74
121
  }
75
-
76
- return await response.json()
77
122
  }
78
123
 
79
124
  /** @type {import('./compliance-types.d.ts').Compliance['createReport']} */
@@ -81,37 +126,50 @@ export const createReport = async (request) => {
81
126
  return await _createReport(baseUrl, request)
82
127
  }
83
128
  async function _updateReports (url, request) {
84
- const queryParameters = ['fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.bundleId.eq', 'where.bundleId.neq', 'where.bundleId.gt', 'where.bundleId.gte', 'where.bundleId.lt', 'where.bundleId.lte', 'where.bundleId.like', 'where.bundleId.in', 'where.bundleId.nin', 'where.bundleId.contains', 'where.bundleId.contained', 'where.bundleId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.result.eq', 'where.result.neq', 'where.result.gt', 'where.result.gte', 'where.result.lt', 'where.result.lte', 'where.result.like', 'where.result.in', 'where.result.nin', 'where.result.contains', 'where.result.contained', 'where.result.overlaps', 'where.ruleSet.eq', 'where.ruleSet.neq', 'where.ruleSet.gt', 'where.ruleSet.gte', 'where.ruleSet.lt', 'where.ruleSet.lte', 'where.ruleSet.like', 'where.ruleSet.in', 'where.ruleSet.nin', 'where.ruleSet.contains', 'where.ruleSet.contained', 'where.ruleSet.overlaps', 'where.or']
129
+ const queryParameters = ['fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.ilike', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.ilike', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.ilike', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.result.eq', 'where.result.neq', 'where.result.gt', 'where.result.gte', 'where.result.lt', 'where.result.lte', 'where.result.like', 'where.result.ilike', 'where.result.in', 'where.result.nin', 'where.result.contains', 'where.result.contained', 'where.result.overlaps', 'where.ruleSet.eq', 'where.ruleSet.neq', 'where.ruleSet.gt', 'where.ruleSet.gte', 'where.ruleSet.lt', 'where.ruleSet.lte', 'where.ruleSet.like', 'where.ruleSet.ilike', 'where.ruleSet.in', 'where.ruleSet.nin', 'where.ruleSet.contains', 'where.ruleSet.contained', 'where.ruleSet.overlaps', 'where.or']
85
130
  const searchParams = new URLSearchParams()
86
- queryParameters.forEach((qp) => {
87
- if (request[qp]) {
88
- if (Array.isArray(request[qp])) {
89
- request[qp].forEach((p) => {
90
- searchParams.append(qp, p)
91
- })
92
- } else {
93
- searchParams.append(qp, request[qp]?.toString() || '')
131
+ if (request.query) {
132
+ queryParameters.forEach((qp) => {
133
+ const queryValue = request.query?.[qp]
134
+ if (queryValue) {
135
+ if (Array.isArray(queryValue)) {
136
+ queryValue.forEach((p) => searchParams.append(qp, p))
137
+ } else {
138
+ searchParams.append(qp, queryValue.toString())
139
+ }
94
140
  }
95
- }
96
- delete request[qp]
97
- })
141
+ delete request.query?.[qp]
142
+ })
143
+ }
98
144
 
145
+ const body = 'body' in request ? (request.body) : undefined
146
+ const isFormData = body instanceof FormData
99
147
  const headers = {
100
148
  ...defaultHeaders,
101
- 'Content-type': 'application/json; charset=utf-8'
149
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
102
150
  }
103
151
 
104
152
  const response = await fetch(`${url}/reports/?${searchParams.toString()}`, {
105
153
  method: 'PUT',
106
- body: JSON.stringify(request),
107
- headers
154
+ body: isFormData ? body : JSON.stringify(body),
155
+ headers,
156
+ ...defaultFetchParams
108
157
  })
109
158
 
110
- if (!response.ok) {
111
- throw new Error(await response.text())
159
+ const jsonResponses = [200]
160
+ if (jsonResponses.includes(response.status)) {
161
+ return {
162
+ statusCode: response.status,
163
+ headers: headersToJSON(response.headers),
164
+ body: await response.json()
165
+ }
166
+ }
167
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
168
+ return {
169
+ statusCode: response.status,
170
+ headers: headersToJSON(response.headers),
171
+ body: await response[responseType]()
112
172
  }
113
-
114
- return await response.json()
115
173
  }
116
174
 
117
175
  /** @type {import('./compliance-types.d.ts').Compliance['updateReports']} */
@@ -121,32 +179,43 @@ export const updateReports = async (request) => {
121
179
  async function _getReportById (url, request) {
122
180
  const queryParameters = ['fields']
123
181
  const searchParams = new URLSearchParams()
124
- queryParameters.forEach((qp) => {
125
- if (request[qp]) {
126
- if (Array.isArray(request[qp])) {
127
- request[qp].forEach((p) => {
128
- searchParams.append(qp, p)
129
- })
130
- } else {
131
- searchParams.append(qp, request[qp]?.toString() || '')
182
+ if (request.query) {
183
+ queryParameters.forEach((qp) => {
184
+ const queryValue = request.query?.[qp]
185
+ if (queryValue) {
186
+ if (Array.isArray(queryValue)) {
187
+ queryValue.forEach((p) => searchParams.append(qp, p))
188
+ } else {
189
+ searchParams.append(qp, queryValue.toString())
190
+ }
132
191
  }
133
- }
134
- delete request[qp]
135
- })
192
+ delete request.query?.[qp]
193
+ })
194
+ }
136
195
 
137
196
  const headers = {
138
197
  ...defaultHeaders
139
198
  }
140
199
 
141
- const response = await fetch(`${url}/reports/${request['id']}?${searchParams.toString()}`, {
142
- headers
200
+ const response = await fetch(`${url}/reports/${request.path['id']}?${searchParams.toString()}`, {
201
+ headers,
202
+ ...defaultFetchParams
143
203
  })
144
204
 
145
- if (!response.ok) {
146
- throw new Error(await response.text())
205
+ const jsonResponses = [200]
206
+ if (jsonResponses.includes(response.status)) {
207
+ return {
208
+ statusCode: response.status,
209
+ headers: headersToJSON(response.headers),
210
+ body: await response.json()
211
+ }
212
+ }
213
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
214
+ return {
215
+ statusCode: response.status,
216
+ headers: headersToJSON(response.headers),
217
+ body: await response[responseType]()
147
218
  }
148
-
149
- return await response.json()
150
219
  }
151
220
 
152
221
  /** @type {import('./compliance-types.d.ts').Compliance['getReportById']} */
@@ -156,35 +225,48 @@ export const getReportById = async (request) => {
156
225
  async function _updateReport (url, request) {
157
226
  const queryParameters = ['fields']
158
227
  const searchParams = new URLSearchParams()
159
- queryParameters.forEach((qp) => {
160
- if (request[qp]) {
161
- if (Array.isArray(request[qp])) {
162
- request[qp].forEach((p) => {
163
- searchParams.append(qp, p)
164
- })
165
- } else {
166
- searchParams.append(qp, request[qp]?.toString() || '')
228
+ if (request.query) {
229
+ queryParameters.forEach((qp) => {
230
+ const queryValue = request.query?.[qp]
231
+ if (queryValue) {
232
+ if (Array.isArray(queryValue)) {
233
+ queryValue.forEach((p) => searchParams.append(qp, p))
234
+ } else {
235
+ searchParams.append(qp, queryValue.toString())
236
+ }
167
237
  }
168
- }
169
- delete request[qp]
170
- })
238
+ delete request.query?.[qp]
239
+ })
240
+ }
171
241
 
242
+ const body = 'body' in request ? (request.body) : undefined
243
+ const isFormData = body instanceof FormData
172
244
  const headers = {
173
245
  ...defaultHeaders,
174
- 'Content-type': 'application/json; charset=utf-8'
246
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
175
247
  }
176
248
 
177
- const response = await fetch(`${url}/reports/${request['id']}?${searchParams.toString()}`, {
249
+ const response = await fetch(`${url}/reports/${request.path['id']}?${searchParams.toString()}`, {
178
250
  method: 'PUT',
179
- body: JSON.stringify(request),
180
- headers
251
+ body: isFormData ? body : JSON.stringify(body),
252
+ headers,
253
+ ...defaultFetchParams
181
254
  })
182
255
 
183
- if (!response.ok) {
184
- throw new Error(await response.text())
256
+ const jsonResponses = [200]
257
+ if (jsonResponses.includes(response.status)) {
258
+ return {
259
+ statusCode: response.status,
260
+ headers: headersToJSON(response.headers),
261
+ body: await response.json()
262
+ }
263
+ }
264
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
265
+ return {
266
+ statusCode: response.status,
267
+ headers: headersToJSON(response.headers),
268
+ body: await response[responseType]()
185
269
  }
186
-
187
- return await response.json()
188
270
  }
189
271
 
190
272
  /** @type {import('./compliance-types.d.ts').Compliance['updateReport']} */
@@ -194,35 +276,48 @@ export const updateReport = async (request) => {
194
276
  async function _deleteReports (url, request) {
195
277
  const queryParameters = ['fields']
196
278
  const searchParams = new URLSearchParams()
197
- queryParameters.forEach((qp) => {
198
- if (request[qp]) {
199
- if (Array.isArray(request[qp])) {
200
- request[qp].forEach((p) => {
201
- searchParams.append(qp, p)
202
- })
203
- } else {
204
- searchParams.append(qp, request[qp]?.toString() || '')
279
+ if (request.query) {
280
+ queryParameters.forEach((qp) => {
281
+ const queryValue = request.query?.[qp]
282
+ if (queryValue) {
283
+ if (Array.isArray(queryValue)) {
284
+ queryValue.forEach((p) => searchParams.append(qp, p))
285
+ } else {
286
+ searchParams.append(qp, queryValue.toString())
287
+ }
205
288
  }
206
- }
207
- delete request[qp]
208
- })
289
+ delete request.query?.[qp]
290
+ })
291
+ }
209
292
 
293
+ const body = 'body' in request ? (request.body) : undefined
294
+ const isFormData = body instanceof FormData
210
295
  const headers = {
211
296
  ...defaultHeaders,
212
- 'Content-type': 'application/json; charset=utf-8'
297
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
213
298
  }
214
299
 
215
- const response = await fetch(`${url}/reports/${request['id']}?${searchParams.toString()}`, {
300
+ const response = await fetch(`${url}/reports/${request.path['id']}?${searchParams.toString()}`, {
216
301
  method: 'DELETE',
217
- body: JSON.stringify(request),
218
- headers
302
+ body: isFormData ? body : JSON.stringify(body),
303
+ headers,
304
+ ...defaultFetchParams
219
305
  })
220
306
 
221
- if (!response.ok) {
222
- throw new Error(await response.text())
307
+ const jsonResponses = [200]
308
+ if (jsonResponses.includes(response.status)) {
309
+ return {
310
+ statusCode: response.status,
311
+ headers: headersToJSON(response.headers),
312
+ body: await response.json()
313
+ }
314
+ }
315
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
316
+ return {
317
+ statusCode: response.status,
318
+ headers: headersToJSON(response.headers),
319
+ body: await response[responseType]()
223
320
  }
224
-
225
- return await response.json()
226
321
  }
227
322
 
228
323
  /** @type {import('./compliance-types.d.ts').Compliance['deleteReports']} */
@@ -230,22 +325,50 @@ export const deleteReports = async (request) => {
230
325
  return await _deleteReports(baseUrl, request)
231
326
  }
232
327
  async function _createRule (url, request) {
328
+ const queryParameters = ['fields']
329
+ const searchParams = new URLSearchParams()
330
+ if (request.query) {
331
+ queryParameters.forEach((qp) => {
332
+ const queryValue = request.query?.[qp]
333
+ if (queryValue) {
334
+ if (Array.isArray(queryValue)) {
335
+ queryValue.forEach((p) => searchParams.append(qp, p))
336
+ } else {
337
+ searchParams.append(qp, queryValue.toString())
338
+ }
339
+ }
340
+ delete request.query?.[qp]
341
+ })
342
+ }
343
+
344
+ const body = 'body' in request ? (request.body) : undefined
345
+ const isFormData = body instanceof FormData
233
346
  const headers = {
234
347
  ...defaultHeaders,
235
- 'Content-type': 'application/json; charset=utf-8'
348
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
236
349
  }
237
350
 
238
- const response = await fetch(`${url}/rules/`, {
351
+ const response = await fetch(`${url}/rules/?${searchParams.toString()}`, {
239
352
  method: 'POST',
240
- body: JSON.stringify(request),
241
- headers
353
+ body: isFormData ? body : JSON.stringify(body),
354
+ headers,
355
+ ...defaultFetchParams
242
356
  })
243
357
 
244
- if (!response.ok) {
245
- throw new Error(await response.text())
358
+ const jsonResponses = [200]
359
+ if (jsonResponses.includes(response.status)) {
360
+ return {
361
+ statusCode: response.status,
362
+ headers: headersToJSON(response.headers),
363
+ body: await response.json()
364
+ }
365
+ }
366
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
367
+ return {
368
+ statusCode: response.status,
369
+ headers: headersToJSON(response.headers),
370
+ body: await response[responseType]()
246
371
  }
247
-
248
- return await response.json()
249
372
  }
250
373
 
251
374
  /** @type {import('./compliance-types.d.ts').Compliance['createRule']} */
@@ -253,37 +376,50 @@ export const createRule = async (request) => {
253
376
  return await _createRule(baseUrl, request)
254
377
  }
255
378
  async function _updateRules (url, request) {
256
- const queryParameters = ['fields', 'where.config.eq', 'where.config.neq', 'where.config.gt', 'where.config.gte', 'where.config.lt', 'where.config.lte', 'where.config.like', 'where.config.in', 'where.config.nin', 'where.config.contains', 'where.config.contained', 'where.config.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.description.eq', 'where.description.neq', 'where.description.gt', 'where.description.gte', 'where.description.lt', 'where.description.lte', 'where.description.like', 'where.description.in', 'where.description.nin', 'where.description.contains', 'where.description.contained', 'where.description.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.label.eq', 'where.label.neq', 'where.label.gt', 'where.label.gte', 'where.label.lt', 'where.label.lte', 'where.label.like', 'where.label.in', 'where.label.nin', 'where.label.contains', 'where.label.contained', 'where.label.overlaps', 'where.name.eq', 'where.name.neq', 'where.name.gt', 'where.name.gte', 'where.name.lt', 'where.name.lte', 'where.name.like', 'where.name.in', 'where.name.nin', 'where.name.contains', 'where.name.contained', 'where.name.overlaps', 'where.or']
379
+ const queryParameters = ['fields', 'where.config.eq', 'where.config.neq', 'where.config.gt', 'where.config.gte', 'where.config.lt', 'where.config.lte', 'where.config.like', 'where.config.ilike', 'where.config.in', 'where.config.nin', 'where.config.contains', 'where.config.contained', 'where.config.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.ilike', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.description.eq', 'where.description.neq', 'where.description.gt', 'where.description.gte', 'where.description.lt', 'where.description.lte', 'where.description.like', 'where.description.ilike', 'where.description.in', 'where.description.nin', 'where.description.contains', 'where.description.contained', 'where.description.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.ilike', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.label.eq', 'where.label.neq', 'where.label.gt', 'where.label.gte', 'where.label.lt', 'where.label.lte', 'where.label.like', 'where.label.ilike', 'where.label.in', 'where.label.nin', 'where.label.contains', 'where.label.contained', 'where.label.overlaps', 'where.name.eq', 'where.name.neq', 'where.name.gt', 'where.name.gte', 'where.name.lt', 'where.name.lte', 'where.name.like', 'where.name.ilike', 'where.name.in', 'where.name.nin', 'where.name.contains', 'where.name.contained', 'where.name.overlaps', 'where.or']
257
380
  const searchParams = new URLSearchParams()
258
- queryParameters.forEach((qp) => {
259
- if (request[qp]) {
260
- if (Array.isArray(request[qp])) {
261
- request[qp].forEach((p) => {
262
- searchParams.append(qp, p)
263
- })
264
- } else {
265
- searchParams.append(qp, request[qp]?.toString() || '')
381
+ if (request.query) {
382
+ queryParameters.forEach((qp) => {
383
+ const queryValue = request.query?.[qp]
384
+ if (queryValue) {
385
+ if (Array.isArray(queryValue)) {
386
+ queryValue.forEach((p) => searchParams.append(qp, p))
387
+ } else {
388
+ searchParams.append(qp, queryValue.toString())
389
+ }
266
390
  }
267
- }
268
- delete request[qp]
269
- })
391
+ delete request.query?.[qp]
392
+ })
393
+ }
270
394
 
395
+ const body = 'body' in request ? (request.body) : undefined
396
+ const isFormData = body instanceof FormData
271
397
  const headers = {
272
398
  ...defaultHeaders,
273
- 'Content-type': 'application/json; charset=utf-8'
399
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
274
400
  }
275
401
 
276
402
  const response = await fetch(`${url}/rules/?${searchParams.toString()}`, {
277
403
  method: 'PUT',
278
- body: JSON.stringify(request),
279
- headers
404
+ body: isFormData ? body : JSON.stringify(body),
405
+ headers,
406
+ ...defaultFetchParams
280
407
  })
281
408
 
282
- if (!response.ok) {
283
- throw new Error(await response.text())
409
+ const jsonResponses = [200]
410
+ if (jsonResponses.includes(response.status)) {
411
+ return {
412
+ statusCode: response.status,
413
+ headers: headersToJSON(response.headers),
414
+ body: await response.json()
415
+ }
416
+ }
417
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
418
+ return {
419
+ statusCode: response.status,
420
+ headers: headersToJSON(response.headers),
421
+ body: await response[responseType]()
284
422
  }
285
-
286
- return await response.json()
287
423
  }
288
424
 
289
425
  /** @type {import('./compliance-types.d.ts').Compliance['updateRules']} */
@@ -293,32 +429,43 @@ export const updateRules = async (request) => {
293
429
  async function _getRuleById (url, request) {
294
430
  const queryParameters = ['fields']
295
431
  const searchParams = new URLSearchParams()
296
- queryParameters.forEach((qp) => {
297
- if (request[qp]) {
298
- if (Array.isArray(request[qp])) {
299
- request[qp].forEach((p) => {
300
- searchParams.append(qp, p)
301
- })
302
- } else {
303
- searchParams.append(qp, request[qp]?.toString() || '')
432
+ if (request.query) {
433
+ queryParameters.forEach((qp) => {
434
+ const queryValue = request.query?.[qp]
435
+ if (queryValue) {
436
+ if (Array.isArray(queryValue)) {
437
+ queryValue.forEach((p) => searchParams.append(qp, p))
438
+ } else {
439
+ searchParams.append(qp, queryValue.toString())
440
+ }
304
441
  }
305
- }
306
- delete request[qp]
307
- })
442
+ delete request.query?.[qp]
443
+ })
444
+ }
308
445
 
309
446
  const headers = {
310
447
  ...defaultHeaders
311
448
  }
312
449
 
313
- const response = await fetch(`${url}/rules/${request['id']}?${searchParams.toString()}`, {
314
- headers
450
+ const response = await fetch(`${url}/rules/${request.path['id']}?${searchParams.toString()}`, {
451
+ headers,
452
+ ...defaultFetchParams
315
453
  })
316
454
 
317
- if (!response.ok) {
318
- throw new Error(await response.text())
455
+ const jsonResponses = [200]
456
+ if (jsonResponses.includes(response.status)) {
457
+ return {
458
+ statusCode: response.status,
459
+ headers: headersToJSON(response.headers),
460
+ body: await response.json()
461
+ }
462
+ }
463
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
464
+ return {
465
+ statusCode: response.status,
466
+ headers: headersToJSON(response.headers),
467
+ body: await response[responseType]()
319
468
  }
320
-
321
- return await response.json()
322
469
  }
323
470
 
324
471
  /** @type {import('./compliance-types.d.ts').Compliance['getRuleById']} */
@@ -328,35 +475,48 @@ export const getRuleById = async (request) => {
328
475
  async function _updateRule (url, request) {
329
476
  const queryParameters = ['fields']
330
477
  const searchParams = new URLSearchParams()
331
- queryParameters.forEach((qp) => {
332
- if (request[qp]) {
333
- if (Array.isArray(request[qp])) {
334
- request[qp].forEach((p) => {
335
- searchParams.append(qp, p)
336
- })
337
- } else {
338
- searchParams.append(qp, request[qp]?.toString() || '')
478
+ if (request.query) {
479
+ queryParameters.forEach((qp) => {
480
+ const queryValue = request.query?.[qp]
481
+ if (queryValue) {
482
+ if (Array.isArray(queryValue)) {
483
+ queryValue.forEach((p) => searchParams.append(qp, p))
484
+ } else {
485
+ searchParams.append(qp, queryValue.toString())
486
+ }
339
487
  }
340
- }
341
- delete request[qp]
342
- })
488
+ delete request.query?.[qp]
489
+ })
490
+ }
343
491
 
492
+ const body = 'body' in request ? (request.body) : undefined
493
+ const isFormData = body instanceof FormData
344
494
  const headers = {
345
495
  ...defaultHeaders,
346
- 'Content-type': 'application/json; charset=utf-8'
496
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
347
497
  }
348
498
 
349
- const response = await fetch(`${url}/rules/${request['id']}?${searchParams.toString()}`, {
499
+ const response = await fetch(`${url}/rules/${request.path['id']}?${searchParams.toString()}`, {
350
500
  method: 'PUT',
351
- body: JSON.stringify(request),
352
- headers
501
+ body: isFormData ? body : JSON.stringify(body),
502
+ headers,
503
+ ...defaultFetchParams
353
504
  })
354
505
 
355
- if (!response.ok) {
356
- throw new Error(await response.text())
506
+ const jsonResponses = [200]
507
+ if (jsonResponses.includes(response.status)) {
508
+ return {
509
+ statusCode: response.status,
510
+ headers: headersToJSON(response.headers),
511
+ body: await response.json()
512
+ }
513
+ }
514
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
515
+ return {
516
+ statusCode: response.status,
517
+ headers: headersToJSON(response.headers),
518
+ body: await response[responseType]()
357
519
  }
358
-
359
- return await response.json()
360
520
  }
361
521
 
362
522
  /** @type {import('./compliance-types.d.ts').Compliance['updateRule']} */
@@ -366,35 +526,48 @@ export const updateRule = async (request) => {
366
526
  async function _deleteRules (url, request) {
367
527
  const queryParameters = ['fields']
368
528
  const searchParams = new URLSearchParams()
369
- queryParameters.forEach((qp) => {
370
- if (request[qp]) {
371
- if (Array.isArray(request[qp])) {
372
- request[qp].forEach((p) => {
373
- searchParams.append(qp, p)
374
- })
375
- } else {
376
- searchParams.append(qp, request[qp]?.toString() || '')
529
+ if (request.query) {
530
+ queryParameters.forEach((qp) => {
531
+ const queryValue = request.query?.[qp]
532
+ if (queryValue) {
533
+ if (Array.isArray(queryValue)) {
534
+ queryValue.forEach((p) => searchParams.append(qp, p))
535
+ } else {
536
+ searchParams.append(qp, queryValue.toString())
537
+ }
377
538
  }
378
- }
379
- delete request[qp]
380
- })
539
+ delete request.query?.[qp]
540
+ })
541
+ }
381
542
 
543
+ const body = 'body' in request ? (request.body) : undefined
544
+ const isFormData = body instanceof FormData
382
545
  const headers = {
383
546
  ...defaultHeaders,
384
- 'Content-type': 'application/json; charset=utf-8'
547
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
385
548
  }
386
549
 
387
- const response = await fetch(`${url}/rules/${request['id']}?${searchParams.toString()}`, {
550
+ const response = await fetch(`${url}/rules/${request.path['id']}?${searchParams.toString()}`, {
388
551
  method: 'DELETE',
389
- body: JSON.stringify(request),
390
- headers
552
+ body: isFormData ? body : JSON.stringify(body),
553
+ headers,
554
+ ...defaultFetchParams
391
555
  })
392
556
 
393
- if (!response.ok) {
394
- throw new Error(await response.text())
557
+ const jsonResponses = [200]
558
+ if (jsonResponses.includes(response.status)) {
559
+ return {
560
+ statusCode: response.status,
561
+ headers: headersToJSON(response.headers),
562
+ body: await response.json()
563
+ }
564
+ }
565
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
566
+ return {
567
+ statusCode: response.status,
568
+ headers: headersToJSON(response.headers),
569
+ body: await response[responseType]()
395
570
  }
396
-
397
- return await response.json()
398
571
  }
399
572
 
400
573
  /** @type {import('./compliance-types.d.ts').Compliance['deleteRules']} */
@@ -402,34 +575,45 @@ export const deleteRules = async (request) => {
402
575
  return await _deleteRules(baseUrl, request)
403
576
  }
404
577
  async function _getRuleConfigsForRule (url, request) {
405
- const queryParameters = ['fields']
578
+ const queryParameters = ['limit', 'offset', 'fields', 'totalCount']
406
579
  const searchParams = new URLSearchParams()
407
- queryParameters.forEach((qp) => {
408
- if (request[qp]) {
409
- if (Array.isArray(request[qp])) {
410
- request[qp].forEach((p) => {
411
- searchParams.append(qp, p)
412
- })
413
- } else {
414
- searchParams.append(qp, request[qp]?.toString() || '')
580
+ if (request.query) {
581
+ queryParameters.forEach((qp) => {
582
+ const queryValue = request.query?.[qp]
583
+ if (queryValue) {
584
+ if (Array.isArray(queryValue)) {
585
+ queryValue.forEach((p) => searchParams.append(qp, p))
586
+ } else {
587
+ searchParams.append(qp, queryValue.toString())
588
+ }
415
589
  }
416
- }
417
- delete request[qp]
418
- })
590
+ delete request.query?.[qp]
591
+ })
592
+ }
419
593
 
420
594
  const headers = {
421
595
  ...defaultHeaders
422
596
  }
423
597
 
424
- const response = await fetch(`${url}/rules/${request['id']}/ruleConfigs?${searchParams.toString()}`, {
425
- headers
598
+ const response = await fetch(`${url}/rules/${request.path['id']}/ruleConfigs?${searchParams.toString()}`, {
599
+ headers,
600
+ ...defaultFetchParams
426
601
  })
427
602
 
428
- if (!response.ok) {
429
- throw new Error(await response.text())
603
+ const jsonResponses = [200]
604
+ if (jsonResponses.includes(response.status)) {
605
+ return {
606
+ statusCode: response.status,
607
+ headers: headersToJSON(response.headers),
608
+ body: await response.json()
609
+ }
610
+ }
611
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
612
+ return {
613
+ statusCode: response.status,
614
+ headers: headersToJSON(response.headers),
615
+ body: await response[responseType]()
430
616
  }
431
-
432
- return await response.json()
433
617
  }
434
618
 
435
619
  /** @type {import('./compliance-types.d.ts').Compliance['getRuleConfigsForRule']} */
@@ -437,34 +621,45 @@ export const getRuleConfigsForRule = async (request) => {
437
621
  return await _getRuleConfigsForRule(baseUrl, request)
438
622
  }
439
623
  async function _getRuleConfigs (url, request) {
440
- const queryParameters = ['limit', 'offset', 'totalCount', 'fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.enabled.eq', 'where.enabled.neq', 'where.enabled.gt', 'where.enabled.gte', 'where.enabled.lt', 'where.enabled.lte', 'where.enabled.like', 'where.enabled.in', 'where.enabled.nin', 'where.enabled.contains', 'where.enabled.contained', 'where.enabled.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.options.eq', 'where.options.neq', 'where.options.gt', 'where.options.gte', 'where.options.lt', 'where.options.lte', 'where.options.like', 'where.options.in', 'where.options.nin', 'where.options.contains', 'where.options.contained', 'where.options.overlaps', 'where.ruleId.eq', 'where.ruleId.neq', 'where.ruleId.gt', 'where.ruleId.gte', 'where.ruleId.lt', 'where.ruleId.lte', 'where.ruleId.like', 'where.ruleId.in', 'where.ruleId.nin', 'where.ruleId.contains', 'where.ruleId.contained', 'where.ruleId.overlaps', 'where.type.eq', 'where.type.neq', 'where.type.gt', 'where.type.gte', 'where.type.lt', 'where.type.lte', 'where.type.like', 'where.type.in', 'where.type.nin', 'where.type.contains', 'where.type.contained', 'where.type.overlaps', 'where.or', 'orderby.applicationId', 'orderby.createdAt', 'orderby.enabled', 'orderby.id', 'orderby.options', 'orderby.ruleId', 'orderby.type']
624
+ const queryParameters = ['limit', 'offset', 'totalCount', 'cursor', 'startAfter', 'endBefore', 'fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.ilike', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.ilike', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.enabled.eq', 'where.enabled.neq', 'where.enabled.gt', 'where.enabled.gte', 'where.enabled.lt', 'where.enabled.lte', 'where.enabled.like', 'where.enabled.ilike', 'where.enabled.in', 'where.enabled.nin', 'where.enabled.contains', 'where.enabled.contained', 'where.enabled.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.ilike', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.options.eq', 'where.options.neq', 'where.options.gt', 'where.options.gte', 'where.options.lt', 'where.options.lte', 'where.options.like', 'where.options.ilike', 'where.options.in', 'where.options.nin', 'where.options.contains', 'where.options.contained', 'where.options.overlaps', 'where.ruleId.eq', 'where.ruleId.neq', 'where.ruleId.gt', 'where.ruleId.gte', 'where.ruleId.lt', 'where.ruleId.lte', 'where.ruleId.like', 'where.ruleId.ilike', 'where.ruleId.in', 'where.ruleId.nin', 'where.ruleId.contains', 'where.ruleId.contained', 'where.ruleId.overlaps', 'where.type.eq', 'where.type.neq', 'where.type.gt', 'where.type.gte', 'where.type.lt', 'where.type.lte', 'where.type.like', 'where.type.ilike', 'where.type.in', 'where.type.nin', 'where.type.contains', 'where.type.contained', 'where.type.overlaps', 'where.or', 'orderby.applicationId', 'orderby.createdAt', 'orderby.enabled', 'orderby.id', 'orderby.options', 'orderby.ruleId', 'orderby.type']
441
625
  const searchParams = new URLSearchParams()
442
- queryParameters.forEach((qp) => {
443
- if (request[qp]) {
444
- if (Array.isArray(request[qp])) {
445
- request[qp].forEach((p) => {
446
- searchParams.append(qp, p)
447
- })
448
- } else {
449
- searchParams.append(qp, request[qp]?.toString() || '')
626
+ if (request.query) {
627
+ queryParameters.forEach((qp) => {
628
+ const queryValue = request.query?.[qp]
629
+ if (queryValue) {
630
+ if (Array.isArray(queryValue)) {
631
+ queryValue.forEach((p) => searchParams.append(qp, p))
632
+ } else {
633
+ searchParams.append(qp, queryValue.toString())
634
+ }
450
635
  }
451
- }
452
- delete request[qp]
453
- })
636
+ delete request.query?.[qp]
637
+ })
638
+ }
454
639
 
455
640
  const headers = {
456
641
  ...defaultHeaders
457
642
  }
458
643
 
459
644
  const response = await fetch(`${url}/ruleConfigs/?${searchParams.toString()}`, {
460
- headers
645
+ headers,
646
+ ...defaultFetchParams
461
647
  })
462
648
 
463
- if (!response.ok) {
464
- throw new Error(await response.text())
649
+ const jsonResponses = [200]
650
+ if (jsonResponses.includes(response.status)) {
651
+ return {
652
+ statusCode: response.status,
653
+ headers: headersToJSON(response.headers),
654
+ body: await response.json()
655
+ }
656
+ }
657
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
658
+ return {
659
+ statusCode: response.status,
660
+ headers: headersToJSON(response.headers),
661
+ body: await response[responseType]()
465
662
  }
466
-
467
- return await response.json()
468
663
  }
469
664
 
470
665
  /** @type {import('./compliance-types.d.ts').Compliance['getRuleConfigs']} */
@@ -472,22 +667,50 @@ export const getRuleConfigs = async (request) => {
472
667
  return await _getRuleConfigs(baseUrl, request)
473
668
  }
474
669
  async function _createRuleConfig (url, request) {
670
+ const queryParameters = ['fields']
671
+ const searchParams = new URLSearchParams()
672
+ if (request.query) {
673
+ queryParameters.forEach((qp) => {
674
+ const queryValue = request.query?.[qp]
675
+ if (queryValue) {
676
+ if (Array.isArray(queryValue)) {
677
+ queryValue.forEach((p) => searchParams.append(qp, p))
678
+ } else {
679
+ searchParams.append(qp, queryValue.toString())
680
+ }
681
+ }
682
+ delete request.query?.[qp]
683
+ })
684
+ }
685
+
686
+ const body = 'body' in request ? (request.body) : undefined
687
+ const isFormData = body instanceof FormData
475
688
  const headers = {
476
689
  ...defaultHeaders,
477
- 'Content-type': 'application/json; charset=utf-8'
690
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
478
691
  }
479
692
 
480
- const response = await fetch(`${url}/ruleConfigs/`, {
693
+ const response = await fetch(`${url}/ruleConfigs/?${searchParams.toString()}`, {
481
694
  method: 'POST',
482
- body: JSON.stringify(request),
483
- headers
695
+ body: isFormData ? body : JSON.stringify(body),
696
+ headers,
697
+ ...defaultFetchParams
484
698
  })
485
699
 
486
- if (!response.ok) {
487
- throw new Error(await response.text())
700
+ const jsonResponses = [200]
701
+ if (jsonResponses.includes(response.status)) {
702
+ return {
703
+ statusCode: response.status,
704
+ headers: headersToJSON(response.headers),
705
+ body: await response.json()
706
+ }
707
+ }
708
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
709
+ return {
710
+ statusCode: response.status,
711
+ headers: headersToJSON(response.headers),
712
+ body: await response[responseType]()
488
713
  }
489
-
490
- return await response.json()
491
714
  }
492
715
 
493
716
  /** @type {import('./compliance-types.d.ts').Compliance['createRuleConfig']} */
@@ -495,37 +718,50 @@ export const createRuleConfig = async (request) => {
495
718
  return await _createRuleConfig(baseUrl, request)
496
719
  }
497
720
  async function _updateRuleConfigs (url, request) {
498
- const queryParameters = ['fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.enabled.eq', 'where.enabled.neq', 'where.enabled.gt', 'where.enabled.gte', 'where.enabled.lt', 'where.enabled.lte', 'where.enabled.like', 'where.enabled.in', 'where.enabled.nin', 'where.enabled.contains', 'where.enabled.contained', 'where.enabled.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.options.eq', 'where.options.neq', 'where.options.gt', 'where.options.gte', 'where.options.lt', 'where.options.lte', 'where.options.like', 'where.options.in', 'where.options.nin', 'where.options.contains', 'where.options.contained', 'where.options.overlaps', 'where.ruleId.eq', 'where.ruleId.neq', 'where.ruleId.gt', 'where.ruleId.gte', 'where.ruleId.lt', 'where.ruleId.lte', 'where.ruleId.like', 'where.ruleId.in', 'where.ruleId.nin', 'where.ruleId.contains', 'where.ruleId.contained', 'where.ruleId.overlaps', 'where.type.eq', 'where.type.neq', 'where.type.gt', 'where.type.gte', 'where.type.lt', 'where.type.lte', 'where.type.like', 'where.type.in', 'where.type.nin', 'where.type.contains', 'where.type.contained', 'where.type.overlaps', 'where.or']
721
+ const queryParameters = ['fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.ilike', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.ilike', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.enabled.eq', 'where.enabled.neq', 'where.enabled.gt', 'where.enabled.gte', 'where.enabled.lt', 'where.enabled.lte', 'where.enabled.like', 'where.enabled.ilike', 'where.enabled.in', 'where.enabled.nin', 'where.enabled.contains', 'where.enabled.contained', 'where.enabled.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.ilike', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.options.eq', 'where.options.neq', 'where.options.gt', 'where.options.gte', 'where.options.lt', 'where.options.lte', 'where.options.like', 'where.options.ilike', 'where.options.in', 'where.options.nin', 'where.options.contains', 'where.options.contained', 'where.options.overlaps', 'where.ruleId.eq', 'where.ruleId.neq', 'where.ruleId.gt', 'where.ruleId.gte', 'where.ruleId.lt', 'where.ruleId.lte', 'where.ruleId.like', 'where.ruleId.ilike', 'where.ruleId.in', 'where.ruleId.nin', 'where.ruleId.contains', 'where.ruleId.contained', 'where.ruleId.overlaps', 'where.type.eq', 'where.type.neq', 'where.type.gt', 'where.type.gte', 'where.type.lt', 'where.type.lte', 'where.type.like', 'where.type.ilike', 'where.type.in', 'where.type.nin', 'where.type.contains', 'where.type.contained', 'where.type.overlaps', 'where.or']
499
722
  const searchParams = new URLSearchParams()
500
- queryParameters.forEach((qp) => {
501
- if (request[qp]) {
502
- if (Array.isArray(request[qp])) {
503
- request[qp].forEach((p) => {
504
- searchParams.append(qp, p)
505
- })
506
- } else {
507
- searchParams.append(qp, request[qp]?.toString() || '')
723
+ if (request.query) {
724
+ queryParameters.forEach((qp) => {
725
+ const queryValue = request.query?.[qp]
726
+ if (queryValue) {
727
+ if (Array.isArray(queryValue)) {
728
+ queryValue.forEach((p) => searchParams.append(qp, p))
729
+ } else {
730
+ searchParams.append(qp, queryValue.toString())
731
+ }
508
732
  }
509
- }
510
- delete request[qp]
511
- })
733
+ delete request.query?.[qp]
734
+ })
735
+ }
512
736
 
737
+ const body = 'body' in request ? (request.body) : undefined
738
+ const isFormData = body instanceof FormData
513
739
  const headers = {
514
740
  ...defaultHeaders,
515
- 'Content-type': 'application/json; charset=utf-8'
741
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
516
742
  }
517
743
 
518
744
  const response = await fetch(`${url}/ruleConfigs/?${searchParams.toString()}`, {
519
745
  method: 'PUT',
520
- body: JSON.stringify(request),
521
- headers
746
+ body: isFormData ? body : JSON.stringify(body),
747
+ headers,
748
+ ...defaultFetchParams
522
749
  })
523
750
 
524
- if (!response.ok) {
525
- throw new Error(await response.text())
751
+ const jsonResponses = [200]
752
+ if (jsonResponses.includes(response.status)) {
753
+ return {
754
+ statusCode: response.status,
755
+ headers: headersToJSON(response.headers),
756
+ body: await response.json()
757
+ }
758
+ }
759
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
760
+ return {
761
+ statusCode: response.status,
762
+ headers: headersToJSON(response.headers),
763
+ body: await response[responseType]()
526
764
  }
527
-
528
- return await response.json()
529
765
  }
530
766
 
531
767
  /** @type {import('./compliance-types.d.ts').Compliance['updateRuleConfigs']} */
@@ -535,32 +771,43 @@ export const updateRuleConfigs = async (request) => {
535
771
  async function _getRuleConfigById (url, request) {
536
772
  const queryParameters = ['fields']
537
773
  const searchParams = new URLSearchParams()
538
- queryParameters.forEach((qp) => {
539
- if (request[qp]) {
540
- if (Array.isArray(request[qp])) {
541
- request[qp].forEach((p) => {
542
- searchParams.append(qp, p)
543
- })
544
- } else {
545
- searchParams.append(qp, request[qp]?.toString() || '')
774
+ if (request.query) {
775
+ queryParameters.forEach((qp) => {
776
+ const queryValue = request.query?.[qp]
777
+ if (queryValue) {
778
+ if (Array.isArray(queryValue)) {
779
+ queryValue.forEach((p) => searchParams.append(qp, p))
780
+ } else {
781
+ searchParams.append(qp, queryValue.toString())
782
+ }
546
783
  }
547
- }
548
- delete request[qp]
549
- })
784
+ delete request.query?.[qp]
785
+ })
786
+ }
550
787
 
551
788
  const headers = {
552
789
  ...defaultHeaders
553
790
  }
554
791
 
555
- const response = await fetch(`${url}/ruleConfigs/${request['id']}?${searchParams.toString()}`, {
556
- headers
792
+ const response = await fetch(`${url}/ruleConfigs/${request.path['id']}?${searchParams.toString()}`, {
793
+ headers,
794
+ ...defaultFetchParams
557
795
  })
558
796
 
559
- if (!response.ok) {
560
- throw new Error(await response.text())
797
+ const jsonResponses = [200]
798
+ if (jsonResponses.includes(response.status)) {
799
+ return {
800
+ statusCode: response.status,
801
+ headers: headersToJSON(response.headers),
802
+ body: await response.json()
803
+ }
804
+ }
805
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
806
+ return {
807
+ statusCode: response.status,
808
+ headers: headersToJSON(response.headers),
809
+ body: await response[responseType]()
561
810
  }
562
-
563
- return await response.json()
564
811
  }
565
812
 
566
813
  /** @type {import('./compliance-types.d.ts').Compliance['getRuleConfigById']} */
@@ -570,35 +817,48 @@ export const getRuleConfigById = async (request) => {
570
817
  async function _updateRuleConfig (url, request) {
571
818
  const queryParameters = ['fields']
572
819
  const searchParams = new URLSearchParams()
573
- queryParameters.forEach((qp) => {
574
- if (request[qp]) {
575
- if (Array.isArray(request[qp])) {
576
- request[qp].forEach((p) => {
577
- searchParams.append(qp, p)
578
- })
579
- } else {
580
- searchParams.append(qp, request[qp]?.toString() || '')
820
+ if (request.query) {
821
+ queryParameters.forEach((qp) => {
822
+ const queryValue = request.query?.[qp]
823
+ if (queryValue) {
824
+ if (Array.isArray(queryValue)) {
825
+ queryValue.forEach((p) => searchParams.append(qp, p))
826
+ } else {
827
+ searchParams.append(qp, queryValue.toString())
828
+ }
581
829
  }
582
- }
583
- delete request[qp]
584
- })
830
+ delete request.query?.[qp]
831
+ })
832
+ }
585
833
 
834
+ const body = 'body' in request ? (request.body) : undefined
835
+ const isFormData = body instanceof FormData
586
836
  const headers = {
587
837
  ...defaultHeaders,
588
- 'Content-type': 'application/json; charset=utf-8'
838
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
589
839
  }
590
840
 
591
- const response = await fetch(`${url}/ruleConfigs/${request['id']}?${searchParams.toString()}`, {
841
+ const response = await fetch(`${url}/ruleConfigs/${request.path['id']}?${searchParams.toString()}`, {
592
842
  method: 'PUT',
593
- body: JSON.stringify(request),
594
- headers
843
+ body: isFormData ? body : JSON.stringify(body),
844
+ headers,
845
+ ...defaultFetchParams
595
846
  })
596
847
 
597
- if (!response.ok) {
598
- throw new Error(await response.text())
848
+ const jsonResponses = [200]
849
+ if (jsonResponses.includes(response.status)) {
850
+ return {
851
+ statusCode: response.status,
852
+ headers: headersToJSON(response.headers),
853
+ body: await response.json()
854
+ }
855
+ }
856
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
857
+ return {
858
+ statusCode: response.status,
859
+ headers: headersToJSON(response.headers),
860
+ body: await response[responseType]()
599
861
  }
600
-
601
- return await response.json()
602
862
  }
603
863
 
604
864
  /** @type {import('./compliance-types.d.ts').Compliance['updateRuleConfig']} */
@@ -608,35 +868,48 @@ export const updateRuleConfig = async (request) => {
608
868
  async function _deleteRuleConfigs (url, request) {
609
869
  const queryParameters = ['fields']
610
870
  const searchParams = new URLSearchParams()
611
- queryParameters.forEach((qp) => {
612
- if (request[qp]) {
613
- if (Array.isArray(request[qp])) {
614
- request[qp].forEach((p) => {
615
- searchParams.append(qp, p)
616
- })
617
- } else {
618
- searchParams.append(qp, request[qp]?.toString() || '')
871
+ if (request.query) {
872
+ queryParameters.forEach((qp) => {
873
+ const queryValue = request.query?.[qp]
874
+ if (queryValue) {
875
+ if (Array.isArray(queryValue)) {
876
+ queryValue.forEach((p) => searchParams.append(qp, p))
877
+ } else {
878
+ searchParams.append(qp, queryValue.toString())
879
+ }
619
880
  }
620
- }
621
- delete request[qp]
622
- })
881
+ delete request.query?.[qp]
882
+ })
883
+ }
623
884
 
885
+ const body = 'body' in request ? (request.body) : undefined
886
+ const isFormData = body instanceof FormData
624
887
  const headers = {
625
888
  ...defaultHeaders,
626
- 'Content-type': 'application/json; charset=utf-8'
889
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
627
890
  }
628
891
 
629
- const response = await fetch(`${url}/ruleConfigs/${request['id']}?${searchParams.toString()}`, {
892
+ const response = await fetch(`${url}/ruleConfigs/${request.path['id']}?${searchParams.toString()}`, {
630
893
  method: 'DELETE',
631
- body: JSON.stringify(request),
632
- headers
894
+ body: isFormData ? body : JSON.stringify(body),
895
+ headers,
896
+ ...defaultFetchParams
633
897
  })
634
898
 
635
- if (!response.ok) {
636
- throw new Error(await response.text())
899
+ const jsonResponses = [200]
900
+ if (jsonResponses.includes(response.status)) {
901
+ return {
902
+ statusCode: response.status,
903
+ headers: headersToJSON(response.headers),
904
+ body: await response.json()
905
+ }
906
+ }
907
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
908
+ return {
909
+ statusCode: response.status,
910
+ headers: headersToJSON(response.headers),
911
+ body: await response[responseType]()
637
912
  }
638
-
639
- return await response.json()
640
913
  }
641
914
 
642
915
  /** @type {import('./compliance-types.d.ts').Compliance['deleteRuleConfigs']} */
@@ -646,32 +919,43 @@ export const deleteRuleConfigs = async (request) => {
646
919
  async function _getRuleForRuleConfig (url, request) {
647
920
  const queryParameters = ['fields']
648
921
  const searchParams = new URLSearchParams()
649
- queryParameters.forEach((qp) => {
650
- if (request[qp]) {
651
- if (Array.isArray(request[qp])) {
652
- request[qp].forEach((p) => {
653
- searchParams.append(qp, p)
654
- })
655
- } else {
656
- searchParams.append(qp, request[qp]?.toString() || '')
922
+ if (request.query) {
923
+ queryParameters.forEach((qp) => {
924
+ const queryValue = request.query?.[qp]
925
+ if (queryValue) {
926
+ if (Array.isArray(queryValue)) {
927
+ queryValue.forEach((p) => searchParams.append(qp, p))
928
+ } else {
929
+ searchParams.append(qp, queryValue.toString())
930
+ }
657
931
  }
658
- }
659
- delete request[qp]
660
- })
932
+ delete request.query?.[qp]
933
+ })
934
+ }
661
935
 
662
936
  const headers = {
663
937
  ...defaultHeaders
664
938
  }
665
939
 
666
- const response = await fetch(`${url}/ruleConfigs/${request['id']}/rule?${searchParams.toString()}`, {
667
- headers
940
+ const response = await fetch(`${url}/ruleConfigs/${request.path['id']}/rule?${searchParams.toString()}`, {
941
+ headers,
942
+ ...defaultFetchParams
668
943
  })
669
944
 
670
- if (!response.ok) {
671
- throw new Error(await response.text())
945
+ const jsonResponses = [200]
946
+ if (jsonResponses.includes(response.status)) {
947
+ return {
948
+ statusCode: response.status,
949
+ headers: headersToJSON(response.headers),
950
+ body: await response.json()
951
+ }
952
+ }
953
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
954
+ return {
955
+ statusCode: response.status,
956
+ headers: headersToJSON(response.headers),
957
+ body: await response[responseType]()
672
958
  }
673
-
674
- return await response.json()
675
959
  }
676
960
 
677
961
  /** @type {import('./compliance-types.d.ts').Compliance['getRuleForRuleConfig']} */
@@ -679,34 +963,45 @@ export const getRuleForRuleConfig = async (request) => {
679
963
  return await _getRuleForRuleConfig(baseUrl, request)
680
964
  }
681
965
  async function _getMetadata (url, request) {
682
- const queryParameters = ['limit', 'offset', 'totalCount', 'fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.bundleId.eq', 'where.bundleId.neq', 'where.bundleId.gt', 'where.bundleId.gte', 'where.bundleId.lt', 'where.bundleId.lte', 'where.bundleId.like', 'where.bundleId.in', 'where.bundleId.nin', 'where.bundleId.contains', 'where.bundleId.contained', 'where.bundleId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.data.eq', 'where.data.neq', 'where.data.gt', 'where.data.gte', 'where.data.lt', 'where.data.lte', 'where.data.like', 'where.data.in', 'where.data.nin', 'where.data.contains', 'where.data.contained', 'where.data.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.or', 'orderby.applicationId', 'orderby.bundleId', 'orderby.createdAt', 'orderby.data', 'orderby.id']
966
+ const queryParameters = ['limit', 'offset', 'totalCount', 'cursor', 'startAfter', 'endBefore', 'fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.ilike', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.ilike', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.data.eq', 'where.data.neq', 'where.data.gt', 'where.data.gte', 'where.data.lt', 'where.data.lte', 'where.data.like', 'where.data.ilike', 'where.data.in', 'where.data.nin', 'where.data.contains', 'where.data.contained', 'where.data.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.ilike', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.or', 'orderby.applicationId', 'orderby.createdAt', 'orderby.data', 'orderby.id']
683
967
  const searchParams = new URLSearchParams()
684
- queryParameters.forEach((qp) => {
685
- if (request[qp]) {
686
- if (Array.isArray(request[qp])) {
687
- request[qp].forEach((p) => {
688
- searchParams.append(qp, p)
689
- })
690
- } else {
691
- searchParams.append(qp, request[qp]?.toString() || '')
968
+ if (request.query) {
969
+ queryParameters.forEach((qp) => {
970
+ const queryValue = request.query?.[qp]
971
+ if (queryValue) {
972
+ if (Array.isArray(queryValue)) {
973
+ queryValue.forEach((p) => searchParams.append(qp, p))
974
+ } else {
975
+ searchParams.append(qp, queryValue.toString())
976
+ }
692
977
  }
693
- }
694
- delete request[qp]
695
- })
978
+ delete request.query?.[qp]
979
+ })
980
+ }
696
981
 
697
982
  const headers = {
698
983
  ...defaultHeaders
699
984
  }
700
985
 
701
986
  const response = await fetch(`${url}/metadata/?${searchParams.toString()}`, {
702
- headers
987
+ headers,
988
+ ...defaultFetchParams
703
989
  })
704
990
 
705
- if (!response.ok) {
706
- throw new Error(await response.text())
991
+ const jsonResponses = [200]
992
+ if (jsonResponses.includes(response.status)) {
993
+ return {
994
+ statusCode: response.status,
995
+ headers: headersToJSON(response.headers),
996
+ body: await response.json()
997
+ }
998
+ }
999
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
1000
+ return {
1001
+ statusCode: response.status,
1002
+ headers: headersToJSON(response.headers),
1003
+ body: await response[responseType]()
707
1004
  }
708
-
709
- return await response.json()
710
1005
  }
711
1006
 
712
1007
  /** @type {import('./compliance-types.d.ts').Compliance['getMetadata']} */
@@ -714,37 +1009,50 @@ export const getMetadata = async (request) => {
714
1009
  return await _getMetadata(baseUrl, request)
715
1010
  }
716
1011
  async function _updateMetadata (url, request) {
717
- const queryParameters = ['fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.bundleId.eq', 'where.bundleId.neq', 'where.bundleId.gt', 'where.bundleId.gte', 'where.bundleId.lt', 'where.bundleId.lte', 'where.bundleId.like', 'where.bundleId.in', 'where.bundleId.nin', 'where.bundleId.contains', 'where.bundleId.contained', 'where.bundleId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.data.eq', 'where.data.neq', 'where.data.gt', 'where.data.gte', 'where.data.lt', 'where.data.lte', 'where.data.like', 'where.data.in', 'where.data.nin', 'where.data.contains', 'where.data.contained', 'where.data.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.or']
1012
+ const queryParameters = ['fields', 'where.applicationId.eq', 'where.applicationId.neq', 'where.applicationId.gt', 'where.applicationId.gte', 'where.applicationId.lt', 'where.applicationId.lte', 'where.applicationId.like', 'where.applicationId.ilike', 'where.applicationId.in', 'where.applicationId.nin', 'where.applicationId.contains', 'where.applicationId.contained', 'where.applicationId.overlaps', 'where.createdAt.eq', 'where.createdAt.neq', 'where.createdAt.gt', 'where.createdAt.gte', 'where.createdAt.lt', 'where.createdAt.lte', 'where.createdAt.like', 'where.createdAt.ilike', 'where.createdAt.in', 'where.createdAt.nin', 'where.createdAt.contains', 'where.createdAt.contained', 'where.createdAt.overlaps', 'where.data.eq', 'where.data.neq', 'where.data.gt', 'where.data.gte', 'where.data.lt', 'where.data.lte', 'where.data.like', 'where.data.ilike', 'where.data.in', 'where.data.nin', 'where.data.contains', 'where.data.contained', 'where.data.overlaps', 'where.id.eq', 'where.id.neq', 'where.id.gt', 'where.id.gte', 'where.id.lt', 'where.id.lte', 'where.id.like', 'where.id.ilike', 'where.id.in', 'where.id.nin', 'where.id.contains', 'where.id.contained', 'where.id.overlaps', 'where.or']
718
1013
  const searchParams = new URLSearchParams()
719
- queryParameters.forEach((qp) => {
720
- if (request[qp]) {
721
- if (Array.isArray(request[qp])) {
722
- request[qp].forEach((p) => {
723
- searchParams.append(qp, p)
724
- })
725
- } else {
726
- searchParams.append(qp, request[qp]?.toString() || '')
1014
+ if (request.query) {
1015
+ queryParameters.forEach((qp) => {
1016
+ const queryValue = request.query?.[qp]
1017
+ if (queryValue) {
1018
+ if (Array.isArray(queryValue)) {
1019
+ queryValue.forEach((p) => searchParams.append(qp, p))
1020
+ } else {
1021
+ searchParams.append(qp, queryValue.toString())
1022
+ }
727
1023
  }
728
- }
729
- delete request[qp]
730
- })
1024
+ delete request.query?.[qp]
1025
+ })
1026
+ }
731
1027
 
1028
+ const body = 'body' in request ? (request.body) : undefined
1029
+ const isFormData = body instanceof FormData
732
1030
  const headers = {
733
1031
  ...defaultHeaders,
734
- 'Content-type': 'application/json; charset=utf-8'
1032
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
735
1033
  }
736
1034
 
737
1035
  const response = await fetch(`${url}/metadata/?${searchParams.toString()}`, {
738
1036
  method: 'PUT',
739
- body: JSON.stringify(request),
740
- headers
1037
+ body: isFormData ? body : JSON.stringify(body),
1038
+ headers,
1039
+ ...defaultFetchParams
741
1040
  })
742
1041
 
743
- if (!response.ok) {
744
- throw new Error(await response.text())
1042
+ const jsonResponses = [200]
1043
+ if (jsonResponses.includes(response.status)) {
1044
+ return {
1045
+ statusCode: response.status,
1046
+ headers: headersToJSON(response.headers),
1047
+ body: await response.json()
1048
+ }
1049
+ }
1050
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
1051
+ return {
1052
+ statusCode: response.status,
1053
+ headers: headersToJSON(response.headers),
1054
+ body: await response[responseType]()
745
1055
  }
746
-
747
- return await response.json()
748
1056
  }
749
1057
 
750
1058
  /** @type {import('./compliance-types.d.ts').Compliance['updateMetadata']} */
@@ -754,32 +1062,43 @@ export const updateMetadata = async (request) => {
754
1062
  async function _getMetadatumById (url, request) {
755
1063
  const queryParameters = ['fields']
756
1064
  const searchParams = new URLSearchParams()
757
- queryParameters.forEach((qp) => {
758
- if (request[qp]) {
759
- if (Array.isArray(request[qp])) {
760
- request[qp].forEach((p) => {
761
- searchParams.append(qp, p)
762
- })
763
- } else {
764
- searchParams.append(qp, request[qp]?.toString() || '')
1065
+ if (request.query) {
1066
+ queryParameters.forEach((qp) => {
1067
+ const queryValue = request.query?.[qp]
1068
+ if (queryValue) {
1069
+ if (Array.isArray(queryValue)) {
1070
+ queryValue.forEach((p) => searchParams.append(qp, p))
1071
+ } else {
1072
+ searchParams.append(qp, queryValue.toString())
1073
+ }
765
1074
  }
766
- }
767
- delete request[qp]
768
- })
1075
+ delete request.query?.[qp]
1076
+ })
1077
+ }
769
1078
 
770
1079
  const headers = {
771
1080
  ...defaultHeaders
772
1081
  }
773
1082
 
774
- const response = await fetch(`${url}/metadata/${request['id']}?${searchParams.toString()}`, {
775
- headers
1083
+ const response = await fetch(`${url}/metadata/${request.path['id']}?${searchParams.toString()}`, {
1084
+ headers,
1085
+ ...defaultFetchParams
776
1086
  })
777
1087
 
778
- if (!response.ok) {
779
- throw new Error(await response.text())
1088
+ const jsonResponses = [200]
1089
+ if (jsonResponses.includes(response.status)) {
1090
+ return {
1091
+ statusCode: response.status,
1092
+ headers: headersToJSON(response.headers),
1093
+ body: await response.json()
1094
+ }
1095
+ }
1096
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
1097
+ return {
1098
+ statusCode: response.status,
1099
+ headers: headersToJSON(response.headers),
1100
+ body: await response[responseType]()
780
1101
  }
781
-
782
- return await response.json()
783
1102
  }
784
1103
 
785
1104
  /** @type {import('./compliance-types.d.ts').Compliance['getMetadatumById']} */
@@ -789,35 +1108,48 @@ export const getMetadatumById = async (request) => {
789
1108
  async function _updateMetadatum (url, request) {
790
1109
  const queryParameters = ['fields']
791
1110
  const searchParams = new URLSearchParams()
792
- queryParameters.forEach((qp) => {
793
- if (request[qp]) {
794
- if (Array.isArray(request[qp])) {
795
- request[qp].forEach((p) => {
796
- searchParams.append(qp, p)
797
- })
798
- } else {
799
- searchParams.append(qp, request[qp]?.toString() || '')
1111
+ if (request.query) {
1112
+ queryParameters.forEach((qp) => {
1113
+ const queryValue = request.query?.[qp]
1114
+ if (queryValue) {
1115
+ if (Array.isArray(queryValue)) {
1116
+ queryValue.forEach((p) => searchParams.append(qp, p))
1117
+ } else {
1118
+ searchParams.append(qp, queryValue.toString())
1119
+ }
800
1120
  }
801
- }
802
- delete request[qp]
803
- })
1121
+ delete request.query?.[qp]
1122
+ })
1123
+ }
804
1124
 
1125
+ const body = 'body' in request ? (request.body) : undefined
1126
+ const isFormData = body instanceof FormData
805
1127
  const headers = {
806
1128
  ...defaultHeaders,
807
- 'Content-type': 'application/json; charset=utf-8'
1129
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
808
1130
  }
809
1131
 
810
- const response = await fetch(`${url}/metadata/${request['id']}?${searchParams.toString()}`, {
1132
+ const response = await fetch(`${url}/metadata/${request.path['id']}?${searchParams.toString()}`, {
811
1133
  method: 'PUT',
812
- body: JSON.stringify(request),
813
- headers
1134
+ body: isFormData ? body : JSON.stringify(body),
1135
+ headers,
1136
+ ...defaultFetchParams
814
1137
  })
815
1138
 
816
- if (!response.ok) {
817
- throw new Error(await response.text())
1139
+ const jsonResponses = [200]
1140
+ if (jsonResponses.includes(response.status)) {
1141
+ return {
1142
+ statusCode: response.status,
1143
+ headers: headersToJSON(response.headers),
1144
+ body: await response.json()
1145
+ }
1146
+ }
1147
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
1148
+ return {
1149
+ statusCode: response.status,
1150
+ headers: headersToJSON(response.headers),
1151
+ body: await response[responseType]()
818
1152
  }
819
-
820
- return await response.json()
821
1153
  }
822
1154
 
823
1155
  /** @type {import('./compliance-types.d.ts').Compliance['updateMetadatum']} */
@@ -827,35 +1159,48 @@ export const updateMetadatum = async (request) => {
827
1159
  async function _deleteMetadata (url, request) {
828
1160
  const queryParameters = ['fields']
829
1161
  const searchParams = new URLSearchParams()
830
- queryParameters.forEach((qp) => {
831
- if (request[qp]) {
832
- if (Array.isArray(request[qp])) {
833
- request[qp].forEach((p) => {
834
- searchParams.append(qp, p)
835
- })
836
- } else {
837
- searchParams.append(qp, request[qp]?.toString() || '')
1162
+ if (request.query) {
1163
+ queryParameters.forEach((qp) => {
1164
+ const queryValue = request.query?.[qp]
1165
+ if (queryValue) {
1166
+ if (Array.isArray(queryValue)) {
1167
+ queryValue.forEach((p) => searchParams.append(qp, p))
1168
+ } else {
1169
+ searchParams.append(qp, queryValue.toString())
1170
+ }
838
1171
  }
839
- }
840
- delete request[qp]
841
- })
1172
+ delete request.query?.[qp]
1173
+ })
1174
+ }
842
1175
 
1176
+ const body = 'body' in request ? (request.body) : undefined
1177
+ const isFormData = body instanceof FormData
843
1178
  const headers = {
844
1179
  ...defaultHeaders,
845
- 'Content-type': 'application/json; charset=utf-8'
1180
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
846
1181
  }
847
1182
 
848
- const response = await fetch(`${url}/metadata/${request['id']}?${searchParams.toString()}`, {
1183
+ const response = await fetch(`${url}/metadata/${request.path['id']}?${searchParams.toString()}`, {
849
1184
  method: 'DELETE',
850
- body: JSON.stringify(request),
851
- headers
1185
+ body: isFormData ? body : JSON.stringify(body),
1186
+ headers,
1187
+ ...defaultFetchParams
852
1188
  })
853
1189
 
854
- if (!response.ok) {
855
- throw new Error(await response.text())
1190
+ const jsonResponses = [200]
1191
+ if (jsonResponses.includes(response.status)) {
1192
+ return {
1193
+ statusCode: response.status,
1194
+ headers: headersToJSON(response.headers),
1195
+ body: await response.json()
1196
+ }
1197
+ }
1198
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
1199
+ return {
1200
+ statusCode: response.status,
1201
+ headers: headersToJSON(response.headers),
1202
+ body: await response[responseType]()
856
1203
  }
857
-
858
- return await response.json()
859
1204
  }
860
1205
 
861
1206
  /** @type {import('./compliance-types.d.ts').Compliance['deleteMetadata']} */
@@ -863,15 +1208,18 @@ export const deleteMetadata = async (request) => {
863
1208
  return await _deleteMetadata(baseUrl, request)
864
1209
  }
865
1210
  async function _postCompliance (url, request) {
1211
+ const body = 'body' in request ? (request.body) : undefined
1212
+ const isFormData = body instanceof FormData
866
1213
  const headers = {
867
1214
  ...defaultHeaders,
868
- 'Content-type': 'application/json; charset=utf-8'
1215
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
869
1216
  }
870
1217
 
871
1218
  const response = await fetch(`${url}/compliance`, {
872
1219
  method: 'POST',
873
- body: JSON.stringify(request),
874
- headers
1220
+ body: isFormData ? body : JSON.stringify(body),
1221
+ headers,
1222
+ ...defaultFetchParams
875
1223
  })
876
1224
 
877
1225
  const textResponses = [200]
@@ -882,17 +1230,11 @@ async function _postCompliance (url, request) {
882
1230
  body: await response.text()
883
1231
  }
884
1232
  }
885
- if (response.headers.get('content-type') === 'application/json') {
886
- return {
887
- statusCode: response.status,
888
- headers: headersToJSON(response.headers),
889
- body: await response.json()
890
- }
891
- }
1233
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
892
1234
  return {
893
1235
  statusCode: response.status,
894
1236
  headers: headersToJSON(response.headers),
895
- body: await response.text()
1237
+ body: await response[responseType]()
896
1238
  }
897
1239
  }
898
1240
 
@@ -901,15 +1243,18 @@ export const postCompliance = async (request) => {
901
1243
  return await _postCompliance(baseUrl, request)
902
1244
  }
903
1245
  async function _postMetadata (url, request) {
1246
+ const body = 'body' in request ? (request.body) : undefined
1247
+ const isFormData = body instanceof FormData
904
1248
  const headers = {
905
1249
  ...defaultHeaders,
906
- 'Content-type': 'application/json; charset=utf-8'
1250
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
907
1251
  }
908
1252
 
909
1253
  const response = await fetch(`${url}/metadata`, {
910
1254
  method: 'POST',
911
- body: JSON.stringify(request),
912
- headers
1255
+ body: isFormData ? body : JSON.stringify(body),
1256
+ headers,
1257
+ ...defaultFetchParams
913
1258
  })
914
1259
 
915
1260
  const textResponses = [200]
@@ -920,17 +1265,11 @@ async function _postMetadata (url, request) {
920
1265
  body: await response.text()
921
1266
  }
922
1267
  }
923
- if (response.headers.get('content-type') === 'application/json') {
924
- return {
925
- statusCode: response.status,
926
- headers: headersToJSON(response.headers),
927
- body: await response.json()
928
- }
929
- }
1268
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
930
1269
  return {
931
1270
  statusCode: response.status,
932
1271
  headers: headersToJSON(response.headers),
933
- body: await response.text()
1272
+ body: await response[responseType]()
934
1273
  }
935
1274
  }
936
1275
 
@@ -939,15 +1278,18 @@ export const postMetadata = async (request) => {
939
1278
  return await _postMetadata(baseUrl, request)
940
1279
  }
941
1280
  async function _postRulesName (url, request) {
1281
+ const body = 'body' in request ? (request.body) : undefined
1282
+ const isFormData = body instanceof FormData
942
1283
  const headers = {
943
1284
  ...defaultHeaders,
944
- 'Content-type': 'application/json; charset=utf-8'
1285
+ ...(isFormData || body === undefined) ? {} : defaultJsonType
945
1286
  }
946
1287
 
947
- const response = await fetch(`${url}/rules/${request['name']}`, {
1288
+ const response = await fetch(`${url}/rules/${request.path['name']}`, {
948
1289
  method: 'POST',
949
- body: JSON.stringify(request),
950
- headers
1290
+ body: isFormData ? body : JSON.stringify(body),
1291
+ headers,
1292
+ ...defaultFetchParams
951
1293
  })
952
1294
 
953
1295
  const textResponses = [200]
@@ -958,17 +1300,11 @@ async function _postRulesName (url, request) {
958
1300
  body: await response.text()
959
1301
  }
960
1302
  }
961
- if (response.headers.get('content-type') === 'application/json') {
962
- return {
963
- statusCode: response.status,
964
- headers: headersToJSON(response.headers),
965
- body: await response.json()
966
- }
967
- }
1303
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
968
1304
  return {
969
1305
  statusCode: response.status,
970
1306
  headers: headersToJSON(response.headers),
971
- body: await response.text()
1307
+ body: await response[responseType]()
972
1308
  }
973
1309
  }
974
1310
 
@@ -982,7 +1318,8 @@ async function _getRules (url, request) {
982
1318
  }
983
1319
 
984
1320
  const response = await fetch(`${url}/rules`, {
985
- headers
1321
+ headers,
1322
+ ...defaultFetchParams
986
1323
  })
987
1324
 
988
1325
  const textResponses = [200]
@@ -993,17 +1330,11 @@ async function _getRules (url, request) {
993
1330
  body: await response.text()
994
1331
  }
995
1332
  }
996
- if (response.headers.get('content-type') === 'application/json') {
997
- return {
998
- statusCode: response.status,
999
- headers: headersToJSON(response.headers),
1000
- body: await response.json()
1001
- }
1002
- }
1333
+ const responseType = response.headers.get('content-type')?.startsWith('application/json') ? 'json' : 'text'
1003
1334
  return {
1004
1335
  statusCode: response.status,
1005
1336
  headers: headersToJSON(response.headers),
1006
- body: await response.text()
1337
+ body: await response[responseType]()
1007
1338
  }
1008
1339
  }
1009
1340