@platformatic/watt-extra 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +87 -0
  2. package/app.js +124 -0
  3. package/cli.js +141 -0
  4. package/clients/compliance/compliance-types.d.ts +887 -0
  5. package/clients/compliance/compliance.mjs +1049 -0
  6. package/clients/compliance/compliance.openapi.json +6127 -0
  7. package/clients/control-plane/control-plane-types.d.ts +2696 -0
  8. package/clients/control-plane/control-plane.mjs +3051 -0
  9. package/clients/control-plane/control-plane.openapi.json +13693 -0
  10. package/clients/cron/cron-types.d.ts +1479 -0
  11. package/clients/cron/cron.mjs +872 -0
  12. package/clients/cron/cron.openapi.json +9330 -0
  13. package/compliance/index.js +21 -0
  14. package/compliance/rules/dependencies.js +76 -0
  15. package/compliance/rules/utils.js +12 -0
  16. package/eslint.config.js +11 -0
  17. package/help/start.txt +12 -0
  18. package/help/watt-extra.txt +12 -0
  19. package/index.js +45 -0
  20. package/lib/banner.js +22 -0
  21. package/lib/errors.js +34 -0
  22. package/lib/utils.js +34 -0
  23. package/lib/wattpro.js +580 -0
  24. package/package.json +50 -0
  25. package/plugins/alerts.js +115 -0
  26. package/plugins/auth.js +89 -0
  27. package/plugins/compliancy.js +70 -0
  28. package/plugins/env.js +58 -0
  29. package/plugins/flamegraphs.js +100 -0
  30. package/plugins/init.js +70 -0
  31. package/plugins/metadata.js +84 -0
  32. package/plugins/scheduler.js +48 -0
  33. package/plugins/update.js +128 -0
  34. package/renovate.json +6 -0
  35. package/test/alerts.test.js +607 -0
  36. package/test/auth.test.js +128 -0
  37. package/test/auto-cache.test.js +401 -0
  38. package/test/cli.test.js +75 -0
  39. package/test/compliancy.test.js +87 -0
  40. package/test/fixtures/runtime-domains/alpha/package.json +5 -0
  41. package/test/fixtures/runtime-domains/alpha/platformatic.json +6 -0
  42. package/test/fixtures/runtime-domains/alpha/plugin.js +16 -0
  43. package/test/fixtures/runtime-domains/beta/package.json +5 -0
  44. package/test/fixtures/runtime-domains/beta/platformatic.json +6 -0
  45. package/test/fixtures/runtime-domains/beta/plugin.js +7 -0
  46. package/test/fixtures/runtime-domains/composer/package.json +5 -0
  47. package/test/fixtures/runtime-domains/composer/platformatic.json +19 -0
  48. package/test/fixtures/runtime-domains/package.json +1 -0
  49. package/test/fixtures/runtime-domains/platformatic.json +27 -0
  50. package/test/fixtures/runtime-health/package.json +20 -0
  51. package/test/fixtures/runtime-health/platformatic.json +16 -0
  52. package/test/fixtures/runtime-health/services/service-1/package.json +17 -0
  53. package/test/fixtures/runtime-health/services/service-1/platformatic.json +16 -0
  54. package/test/fixtures/runtime-health/services/service-1/plugins/example.js +6 -0
  55. package/test/fixtures/runtime-health/services/service-1/routes/root.cjs +8 -0
  56. package/test/fixtures/runtime-health/services/service-2/package.json +17 -0
  57. package/test/fixtures/runtime-health/services/service-2/platformatic.json +16 -0
  58. package/test/fixtures/runtime-health/services/service-2/plugins/example.js +6 -0
  59. package/test/fixtures/runtime-health/services/service-2/routes/root.cjs +8 -0
  60. package/test/fixtures/runtime-next/package.json +5 -0
  61. package/test/fixtures/runtime-next/platformatic.json +9 -0
  62. package/test/fixtures/runtime-next/web/next/next.config.js +2 -0
  63. package/test/fixtures/runtime-next/web/next/package.json +7 -0
  64. package/test/fixtures/runtime-next/web/next/platformatic.json +9 -0
  65. package/test/fixtures/runtime-next/web/next/src/app/direct/route.js +3 -0
  66. package/test/fixtures/runtime-next/web/next/src/app/layout.jsx +7 -0
  67. package/test/fixtures/runtime-next/web/next/src/app/page.jsx +3 -0
  68. package/test/fixtures/runtime-scheduler/main/package.json +5 -0
  69. package/test/fixtures/runtime-scheduler/main/platformatic.json +9 -0
  70. package/test/fixtures/runtime-scheduler/main/routes/root.cjs +11 -0
  71. package/test/fixtures/runtime-scheduler/package.json +1 -0
  72. package/test/fixtures/runtime-scheduler/platformatic.json +27 -0
  73. package/test/fixtures/runtime-service/main/package.json +5 -0
  74. package/test/fixtures/runtime-service/main/platformatic.json +12 -0
  75. package/test/fixtures/runtime-service/main/routes/root.cjs +11 -0
  76. package/test/fixtures/runtime-service/package.json +1 -0
  77. package/test/fixtures/runtime-service/platformatic.json +19 -0
  78. package/test/fixtures/service-1/package.json +7 -0
  79. package/test/fixtures/service-1/platformatic.json +18 -0
  80. package/test/fixtures/service-1/routes/root.cjs +48 -0
  81. package/test/fixtures/service-2/platformatic.json +21 -0
  82. package/test/fixtures/service-2/routes/root.cjs +5 -0
  83. package/test/fixtures/service-3/package.json +5 -0
  84. package/test/fixtures/service-3/platformatic.json +21 -0
  85. package/test/fixtures/service-3/routes/root.cjs +8 -0
  86. package/test/health.test.js +44 -0
  87. package/test/helper.js +274 -0
  88. package/test/init.test.js +243 -0
  89. package/test/patch-config.test.js +434 -0
  90. package/test/scheduler.test.js +71 -0
  91. package/test/send-to-icc-retry.test.js +138 -0
  92. package/test/shared-context.test.js +82 -0
  93. package/test/spawn.test.js +110 -0
  94. package/test/trigger-flamegraphs.test.js +226 -0
  95. package/test/update.test.js +519 -0
@@ -0,0 +1,1049 @@
1
+ // This client was generated by Platformatic from an OpenAPI specification.
2
+
3
+ // The base URL for the API. This can be overridden by calling `setBaseUrl`.
4
+ let baseUrl = ''
5
+ // The default headers to send within each request. This can be overridden by calling `setDefaultHeaders`.
6
+ let defaultHeaders = {}
7
+
8
+ function sanitizeUrl(url) {
9
+ if (url.endsWith('/')) { return url.slice(0, -1) } else { return url }
10
+ }
11
+ /** @type {import('./compliance-types.d.ts').Compliance['setBaseUrl']} */
12
+ export const setBaseUrl = (newUrl) => { baseUrl = sanitizeUrl(newUrl) }
13
+
14
+ /** @type {import('./compliance-types.d.ts').Compliance['setDefaultHeaders']} */
15
+ export const setDefaultHeaders = (headers) => { defaultHeaders = headers }
16
+
17
+ function headersToJSON(headers) {
18
+ const output = {}
19
+ headers.forEach((value, key) => {
20
+ output[key] = value
21
+ })
22
+ return output
23
+ }
24
+
25
+ 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']
27
+ 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() || '')
36
+ }
37
+ }
38
+ delete request[qp]
39
+ })
40
+
41
+ const headers = {
42
+ ...defaultHeaders
43
+ }
44
+
45
+ const response = await fetch(`${url}/reports/?${searchParams.toString()}`, {
46
+ headers
47
+ })
48
+
49
+ if (!response.ok) {
50
+ throw new Error(await response.text())
51
+ }
52
+
53
+ return await response.json()
54
+ }
55
+
56
+ /** @type {import('./compliance-types.d.ts').Compliance['getReports']} */
57
+ export const getReports = async (request) => {
58
+ return await _getReports(baseUrl, request)
59
+ }
60
+ async function _createReport (url, request) {
61
+ const headers = {
62
+ ...defaultHeaders,
63
+ 'Content-type': 'application/json; charset=utf-8'
64
+ }
65
+
66
+ const response = await fetch(`${url}/reports/`, {
67
+ method: 'POST',
68
+ body: JSON.stringify(request),
69
+ headers
70
+ })
71
+
72
+ if (!response.ok) {
73
+ throw new Error(await response.text())
74
+ }
75
+
76
+ return await response.json()
77
+ }
78
+
79
+ /** @type {import('./compliance-types.d.ts').Compliance['createReport']} */
80
+ export const createReport = async (request) => {
81
+ return await _createReport(baseUrl, request)
82
+ }
83
+ 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']
85
+ 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() || '')
94
+ }
95
+ }
96
+ delete request[qp]
97
+ })
98
+
99
+ const headers = {
100
+ ...defaultHeaders,
101
+ 'Content-type': 'application/json; charset=utf-8'
102
+ }
103
+
104
+ const response = await fetch(`${url}/reports/?${searchParams.toString()}`, {
105
+ method: 'PUT',
106
+ body: JSON.stringify(request),
107
+ headers
108
+ })
109
+
110
+ if (!response.ok) {
111
+ throw new Error(await response.text())
112
+ }
113
+
114
+ return await response.json()
115
+ }
116
+
117
+ /** @type {import('./compliance-types.d.ts').Compliance['updateReports']} */
118
+ export const updateReports = async (request) => {
119
+ return await _updateReports(baseUrl, request)
120
+ }
121
+ async function _getReportById (url, request) {
122
+ const queryParameters = ['fields']
123
+ 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() || '')
132
+ }
133
+ }
134
+ delete request[qp]
135
+ })
136
+
137
+ const headers = {
138
+ ...defaultHeaders
139
+ }
140
+
141
+ const response = await fetch(`${url}/reports/${request['id']}?${searchParams.toString()}`, {
142
+ headers
143
+ })
144
+
145
+ if (!response.ok) {
146
+ throw new Error(await response.text())
147
+ }
148
+
149
+ return await response.json()
150
+ }
151
+
152
+ /** @type {import('./compliance-types.d.ts').Compliance['getReportById']} */
153
+ export const getReportById = async (request) => {
154
+ return await _getReportById(baseUrl, request)
155
+ }
156
+ async function _updateReport (url, request) {
157
+ const queryParameters = ['fields']
158
+ 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() || '')
167
+ }
168
+ }
169
+ delete request[qp]
170
+ })
171
+
172
+ const headers = {
173
+ ...defaultHeaders,
174
+ 'Content-type': 'application/json; charset=utf-8'
175
+ }
176
+
177
+ const response = await fetch(`${url}/reports/${request['id']}?${searchParams.toString()}`, {
178
+ method: 'PUT',
179
+ body: JSON.stringify(request),
180
+ headers
181
+ })
182
+
183
+ if (!response.ok) {
184
+ throw new Error(await response.text())
185
+ }
186
+
187
+ return await response.json()
188
+ }
189
+
190
+ /** @type {import('./compliance-types.d.ts').Compliance['updateReport']} */
191
+ export const updateReport = async (request) => {
192
+ return await _updateReport(baseUrl, request)
193
+ }
194
+ async function _deleteReports (url, request) {
195
+ const queryParameters = ['fields']
196
+ 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() || '')
205
+ }
206
+ }
207
+ delete request[qp]
208
+ })
209
+
210
+ const headers = {
211
+ ...defaultHeaders,
212
+ 'Content-type': 'application/json; charset=utf-8'
213
+ }
214
+
215
+ const response = await fetch(`${url}/reports/${request['id']}?${searchParams.toString()}`, {
216
+ method: 'DELETE',
217
+ body: JSON.stringify(request),
218
+ headers
219
+ })
220
+
221
+ if (!response.ok) {
222
+ throw new Error(await response.text())
223
+ }
224
+
225
+ return await response.json()
226
+ }
227
+
228
+ /** @type {import('./compliance-types.d.ts').Compliance['deleteReports']} */
229
+ export const deleteReports = async (request) => {
230
+ return await _deleteReports(baseUrl, request)
231
+ }
232
+ async function _createRule (url, request) {
233
+ const headers = {
234
+ ...defaultHeaders,
235
+ 'Content-type': 'application/json; charset=utf-8'
236
+ }
237
+
238
+ const response = await fetch(`${url}/rules/`, {
239
+ method: 'POST',
240
+ body: JSON.stringify(request),
241
+ headers
242
+ })
243
+
244
+ if (!response.ok) {
245
+ throw new Error(await response.text())
246
+ }
247
+
248
+ return await response.json()
249
+ }
250
+
251
+ /** @type {import('./compliance-types.d.ts').Compliance['createRule']} */
252
+ export const createRule = async (request) => {
253
+ return await _createRule(baseUrl, request)
254
+ }
255
+ 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']
257
+ 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() || '')
266
+ }
267
+ }
268
+ delete request[qp]
269
+ })
270
+
271
+ const headers = {
272
+ ...defaultHeaders,
273
+ 'Content-type': 'application/json; charset=utf-8'
274
+ }
275
+
276
+ const response = await fetch(`${url}/rules/?${searchParams.toString()}`, {
277
+ method: 'PUT',
278
+ body: JSON.stringify(request),
279
+ headers
280
+ })
281
+
282
+ if (!response.ok) {
283
+ throw new Error(await response.text())
284
+ }
285
+
286
+ return await response.json()
287
+ }
288
+
289
+ /** @type {import('./compliance-types.d.ts').Compliance['updateRules']} */
290
+ export const updateRules = async (request) => {
291
+ return await _updateRules(baseUrl, request)
292
+ }
293
+ async function _getRuleById (url, request) {
294
+ const queryParameters = ['fields']
295
+ 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() || '')
304
+ }
305
+ }
306
+ delete request[qp]
307
+ })
308
+
309
+ const headers = {
310
+ ...defaultHeaders
311
+ }
312
+
313
+ const response = await fetch(`${url}/rules/${request['id']}?${searchParams.toString()}`, {
314
+ headers
315
+ })
316
+
317
+ if (!response.ok) {
318
+ throw new Error(await response.text())
319
+ }
320
+
321
+ return await response.json()
322
+ }
323
+
324
+ /** @type {import('./compliance-types.d.ts').Compliance['getRuleById']} */
325
+ export const getRuleById = async (request) => {
326
+ return await _getRuleById(baseUrl, request)
327
+ }
328
+ async function _updateRule (url, request) {
329
+ const queryParameters = ['fields']
330
+ 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() || '')
339
+ }
340
+ }
341
+ delete request[qp]
342
+ })
343
+
344
+ const headers = {
345
+ ...defaultHeaders,
346
+ 'Content-type': 'application/json; charset=utf-8'
347
+ }
348
+
349
+ const response = await fetch(`${url}/rules/${request['id']}?${searchParams.toString()}`, {
350
+ method: 'PUT',
351
+ body: JSON.stringify(request),
352
+ headers
353
+ })
354
+
355
+ if (!response.ok) {
356
+ throw new Error(await response.text())
357
+ }
358
+
359
+ return await response.json()
360
+ }
361
+
362
+ /** @type {import('./compliance-types.d.ts').Compliance['updateRule']} */
363
+ export const updateRule = async (request) => {
364
+ return await _updateRule(baseUrl, request)
365
+ }
366
+ async function _deleteRules (url, request) {
367
+ const queryParameters = ['fields']
368
+ 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() || '')
377
+ }
378
+ }
379
+ delete request[qp]
380
+ })
381
+
382
+ const headers = {
383
+ ...defaultHeaders,
384
+ 'Content-type': 'application/json; charset=utf-8'
385
+ }
386
+
387
+ const response = await fetch(`${url}/rules/${request['id']}?${searchParams.toString()}`, {
388
+ method: 'DELETE',
389
+ body: JSON.stringify(request),
390
+ headers
391
+ })
392
+
393
+ if (!response.ok) {
394
+ throw new Error(await response.text())
395
+ }
396
+
397
+ return await response.json()
398
+ }
399
+
400
+ /** @type {import('./compliance-types.d.ts').Compliance['deleteRules']} */
401
+ export const deleteRules = async (request) => {
402
+ return await _deleteRules(baseUrl, request)
403
+ }
404
+ async function _getRuleConfigsForRule (url, request) {
405
+ const queryParameters = ['fields']
406
+ 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() || '')
415
+ }
416
+ }
417
+ delete request[qp]
418
+ })
419
+
420
+ const headers = {
421
+ ...defaultHeaders
422
+ }
423
+
424
+ const response = await fetch(`${url}/rules/${request['id']}/ruleConfigs?${searchParams.toString()}`, {
425
+ headers
426
+ })
427
+
428
+ if (!response.ok) {
429
+ throw new Error(await response.text())
430
+ }
431
+
432
+ return await response.json()
433
+ }
434
+
435
+ /** @type {import('./compliance-types.d.ts').Compliance['getRuleConfigsForRule']} */
436
+ export const getRuleConfigsForRule = async (request) => {
437
+ return await _getRuleConfigsForRule(baseUrl, request)
438
+ }
439
+ 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']
441
+ 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() || '')
450
+ }
451
+ }
452
+ delete request[qp]
453
+ })
454
+
455
+ const headers = {
456
+ ...defaultHeaders
457
+ }
458
+
459
+ const response = await fetch(`${url}/ruleConfigs/?${searchParams.toString()}`, {
460
+ headers
461
+ })
462
+
463
+ if (!response.ok) {
464
+ throw new Error(await response.text())
465
+ }
466
+
467
+ return await response.json()
468
+ }
469
+
470
+ /** @type {import('./compliance-types.d.ts').Compliance['getRuleConfigs']} */
471
+ export const getRuleConfigs = async (request) => {
472
+ return await _getRuleConfigs(baseUrl, request)
473
+ }
474
+ async function _createRuleConfig (url, request) {
475
+ const headers = {
476
+ ...defaultHeaders,
477
+ 'Content-type': 'application/json; charset=utf-8'
478
+ }
479
+
480
+ const response = await fetch(`${url}/ruleConfigs/`, {
481
+ method: 'POST',
482
+ body: JSON.stringify(request),
483
+ headers
484
+ })
485
+
486
+ if (!response.ok) {
487
+ throw new Error(await response.text())
488
+ }
489
+
490
+ return await response.json()
491
+ }
492
+
493
+ /** @type {import('./compliance-types.d.ts').Compliance['createRuleConfig']} */
494
+ export const createRuleConfig = async (request) => {
495
+ return await _createRuleConfig(baseUrl, request)
496
+ }
497
+ 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']
499
+ 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() || '')
508
+ }
509
+ }
510
+ delete request[qp]
511
+ })
512
+
513
+ const headers = {
514
+ ...defaultHeaders,
515
+ 'Content-type': 'application/json; charset=utf-8'
516
+ }
517
+
518
+ const response = await fetch(`${url}/ruleConfigs/?${searchParams.toString()}`, {
519
+ method: 'PUT',
520
+ body: JSON.stringify(request),
521
+ headers
522
+ })
523
+
524
+ if (!response.ok) {
525
+ throw new Error(await response.text())
526
+ }
527
+
528
+ return await response.json()
529
+ }
530
+
531
+ /** @type {import('./compliance-types.d.ts').Compliance['updateRuleConfigs']} */
532
+ export const updateRuleConfigs = async (request) => {
533
+ return await _updateRuleConfigs(baseUrl, request)
534
+ }
535
+ async function _getRuleConfigById (url, request) {
536
+ const queryParameters = ['fields']
537
+ 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() || '')
546
+ }
547
+ }
548
+ delete request[qp]
549
+ })
550
+
551
+ const headers = {
552
+ ...defaultHeaders
553
+ }
554
+
555
+ const response = await fetch(`${url}/ruleConfigs/${request['id']}?${searchParams.toString()}`, {
556
+ headers
557
+ })
558
+
559
+ if (!response.ok) {
560
+ throw new Error(await response.text())
561
+ }
562
+
563
+ return await response.json()
564
+ }
565
+
566
+ /** @type {import('./compliance-types.d.ts').Compliance['getRuleConfigById']} */
567
+ export const getRuleConfigById = async (request) => {
568
+ return await _getRuleConfigById(baseUrl, request)
569
+ }
570
+ async function _updateRuleConfig (url, request) {
571
+ const queryParameters = ['fields']
572
+ 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() || '')
581
+ }
582
+ }
583
+ delete request[qp]
584
+ })
585
+
586
+ const headers = {
587
+ ...defaultHeaders,
588
+ 'Content-type': 'application/json; charset=utf-8'
589
+ }
590
+
591
+ const response = await fetch(`${url}/ruleConfigs/${request['id']}?${searchParams.toString()}`, {
592
+ method: 'PUT',
593
+ body: JSON.stringify(request),
594
+ headers
595
+ })
596
+
597
+ if (!response.ok) {
598
+ throw new Error(await response.text())
599
+ }
600
+
601
+ return await response.json()
602
+ }
603
+
604
+ /** @type {import('./compliance-types.d.ts').Compliance['updateRuleConfig']} */
605
+ export const updateRuleConfig = async (request) => {
606
+ return await _updateRuleConfig(baseUrl, request)
607
+ }
608
+ async function _deleteRuleConfigs (url, request) {
609
+ const queryParameters = ['fields']
610
+ 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() || '')
619
+ }
620
+ }
621
+ delete request[qp]
622
+ })
623
+
624
+ const headers = {
625
+ ...defaultHeaders,
626
+ 'Content-type': 'application/json; charset=utf-8'
627
+ }
628
+
629
+ const response = await fetch(`${url}/ruleConfigs/${request['id']}?${searchParams.toString()}`, {
630
+ method: 'DELETE',
631
+ body: JSON.stringify(request),
632
+ headers
633
+ })
634
+
635
+ if (!response.ok) {
636
+ throw new Error(await response.text())
637
+ }
638
+
639
+ return await response.json()
640
+ }
641
+
642
+ /** @type {import('./compliance-types.d.ts').Compliance['deleteRuleConfigs']} */
643
+ export const deleteRuleConfigs = async (request) => {
644
+ return await _deleteRuleConfigs(baseUrl, request)
645
+ }
646
+ async function _getRuleForRuleConfig (url, request) {
647
+ const queryParameters = ['fields']
648
+ 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() || '')
657
+ }
658
+ }
659
+ delete request[qp]
660
+ })
661
+
662
+ const headers = {
663
+ ...defaultHeaders
664
+ }
665
+
666
+ const response = await fetch(`${url}/ruleConfigs/${request['id']}/rule?${searchParams.toString()}`, {
667
+ headers
668
+ })
669
+
670
+ if (!response.ok) {
671
+ throw new Error(await response.text())
672
+ }
673
+
674
+ return await response.json()
675
+ }
676
+
677
+ /** @type {import('./compliance-types.d.ts').Compliance['getRuleForRuleConfig']} */
678
+ export const getRuleForRuleConfig = async (request) => {
679
+ return await _getRuleForRuleConfig(baseUrl, request)
680
+ }
681
+ 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']
683
+ 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() || '')
692
+ }
693
+ }
694
+ delete request[qp]
695
+ })
696
+
697
+ const headers = {
698
+ ...defaultHeaders
699
+ }
700
+
701
+ const response = await fetch(`${url}/metadata/?${searchParams.toString()}`, {
702
+ headers
703
+ })
704
+
705
+ if (!response.ok) {
706
+ throw new Error(await response.text())
707
+ }
708
+
709
+ return await response.json()
710
+ }
711
+
712
+ /** @type {import('./compliance-types.d.ts').Compliance['getMetadata']} */
713
+ export const getMetadata = async (request) => {
714
+ return await _getMetadata(baseUrl, request)
715
+ }
716
+ 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']
718
+ 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() || '')
727
+ }
728
+ }
729
+ delete request[qp]
730
+ })
731
+
732
+ const headers = {
733
+ ...defaultHeaders,
734
+ 'Content-type': 'application/json; charset=utf-8'
735
+ }
736
+
737
+ const response = await fetch(`${url}/metadata/?${searchParams.toString()}`, {
738
+ method: 'PUT',
739
+ body: JSON.stringify(request),
740
+ headers
741
+ })
742
+
743
+ if (!response.ok) {
744
+ throw new Error(await response.text())
745
+ }
746
+
747
+ return await response.json()
748
+ }
749
+
750
+ /** @type {import('./compliance-types.d.ts').Compliance['updateMetadata']} */
751
+ export const updateMetadata = async (request) => {
752
+ return await _updateMetadata(baseUrl, request)
753
+ }
754
+ async function _getMetadatumById (url, request) {
755
+ const queryParameters = ['fields']
756
+ 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() || '')
765
+ }
766
+ }
767
+ delete request[qp]
768
+ })
769
+
770
+ const headers = {
771
+ ...defaultHeaders
772
+ }
773
+
774
+ const response = await fetch(`${url}/metadata/${request['id']}?${searchParams.toString()}`, {
775
+ headers
776
+ })
777
+
778
+ if (!response.ok) {
779
+ throw new Error(await response.text())
780
+ }
781
+
782
+ return await response.json()
783
+ }
784
+
785
+ /** @type {import('./compliance-types.d.ts').Compliance['getMetadatumById']} */
786
+ export const getMetadatumById = async (request) => {
787
+ return await _getMetadatumById(baseUrl, request)
788
+ }
789
+ async function _updateMetadatum (url, request) {
790
+ const queryParameters = ['fields']
791
+ 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() || '')
800
+ }
801
+ }
802
+ delete request[qp]
803
+ })
804
+
805
+ const headers = {
806
+ ...defaultHeaders,
807
+ 'Content-type': 'application/json; charset=utf-8'
808
+ }
809
+
810
+ const response = await fetch(`${url}/metadata/${request['id']}?${searchParams.toString()}`, {
811
+ method: 'PUT',
812
+ body: JSON.stringify(request),
813
+ headers
814
+ })
815
+
816
+ if (!response.ok) {
817
+ throw new Error(await response.text())
818
+ }
819
+
820
+ return await response.json()
821
+ }
822
+
823
+ /** @type {import('./compliance-types.d.ts').Compliance['updateMetadatum']} */
824
+ export const updateMetadatum = async (request) => {
825
+ return await _updateMetadatum(baseUrl, request)
826
+ }
827
+ async function _deleteMetadata (url, request) {
828
+ const queryParameters = ['fields']
829
+ 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() || '')
838
+ }
839
+ }
840
+ delete request[qp]
841
+ })
842
+
843
+ const headers = {
844
+ ...defaultHeaders,
845
+ 'Content-type': 'application/json; charset=utf-8'
846
+ }
847
+
848
+ const response = await fetch(`${url}/metadata/${request['id']}?${searchParams.toString()}`, {
849
+ method: 'DELETE',
850
+ body: JSON.stringify(request),
851
+ headers
852
+ })
853
+
854
+ if (!response.ok) {
855
+ throw new Error(await response.text())
856
+ }
857
+
858
+ return await response.json()
859
+ }
860
+
861
+ /** @type {import('./compliance-types.d.ts').Compliance['deleteMetadata']} */
862
+ export const deleteMetadata = async (request) => {
863
+ return await _deleteMetadata(baseUrl, request)
864
+ }
865
+ async function _postCompliance (url, request) {
866
+ const headers = {
867
+ ...defaultHeaders,
868
+ 'Content-type': 'application/json; charset=utf-8'
869
+ }
870
+
871
+ const response = await fetch(`${url}/compliance`, {
872
+ method: 'POST',
873
+ body: JSON.stringify(request),
874
+ headers
875
+ })
876
+
877
+ const textResponses = [200]
878
+ if (textResponses.includes(response.status)) {
879
+ return {
880
+ statusCode: response.status,
881
+ headers: headersToJSON(response.headers),
882
+ body: await response.text()
883
+ }
884
+ }
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
+ }
892
+ return {
893
+ statusCode: response.status,
894
+ headers: headersToJSON(response.headers),
895
+ body: await response.text()
896
+ }
897
+ }
898
+
899
+ /** @type {import('./compliance-types.d.ts').Compliance['postCompliance']} */
900
+ export const postCompliance = async (request) => {
901
+ return await _postCompliance(baseUrl, request)
902
+ }
903
+ async function _postMetadata (url, request) {
904
+ const headers = {
905
+ ...defaultHeaders,
906
+ 'Content-type': 'application/json; charset=utf-8'
907
+ }
908
+
909
+ const response = await fetch(`${url}/metadata`, {
910
+ method: 'POST',
911
+ body: JSON.stringify(request),
912
+ headers
913
+ })
914
+
915
+ const textResponses = [200]
916
+ if (textResponses.includes(response.status)) {
917
+ return {
918
+ statusCode: response.status,
919
+ headers: headersToJSON(response.headers),
920
+ body: await response.text()
921
+ }
922
+ }
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
+ }
930
+ return {
931
+ statusCode: response.status,
932
+ headers: headersToJSON(response.headers),
933
+ body: await response.text()
934
+ }
935
+ }
936
+
937
+ /** @type {import('./compliance-types.d.ts').Compliance['postMetadata']} */
938
+ export const postMetadata = async (request) => {
939
+ return await _postMetadata(baseUrl, request)
940
+ }
941
+ async function _postRulesName (url, request) {
942
+ const headers = {
943
+ ...defaultHeaders,
944
+ 'Content-type': 'application/json; charset=utf-8'
945
+ }
946
+
947
+ const response = await fetch(`${url}/rules/${request['name']}`, {
948
+ method: 'POST',
949
+ body: JSON.stringify(request),
950
+ headers
951
+ })
952
+
953
+ const textResponses = [200]
954
+ if (textResponses.includes(response.status)) {
955
+ return {
956
+ statusCode: response.status,
957
+ headers: headersToJSON(response.headers),
958
+ body: await response.text()
959
+ }
960
+ }
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
+ }
968
+ return {
969
+ statusCode: response.status,
970
+ headers: headersToJSON(response.headers),
971
+ body: await response.text()
972
+ }
973
+ }
974
+
975
+ /** @type {import('./compliance-types.d.ts').Compliance['postRulesName']} */
976
+ export const postRulesName = async (request) => {
977
+ return await _postRulesName(baseUrl, request)
978
+ }
979
+ async function _getRules (url, request) {
980
+ const headers = {
981
+ ...defaultHeaders
982
+ }
983
+
984
+ const response = await fetch(`${url}/rules`, {
985
+ headers
986
+ })
987
+
988
+ const textResponses = [200]
989
+ if (textResponses.includes(response.status)) {
990
+ return {
991
+ statusCode: response.status,
992
+ headers: headersToJSON(response.headers),
993
+ body: await response.text()
994
+ }
995
+ }
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
+ }
1003
+ return {
1004
+ statusCode: response.status,
1005
+ headers: headersToJSON(response.headers),
1006
+ body: await response.text()
1007
+ }
1008
+ }
1009
+
1010
+ /** @type {import('./compliance-types.d.ts').Compliance['getRules']} */
1011
+ export const getRules = async (request) => {
1012
+ return await _getRules(baseUrl, request)
1013
+ }
1014
+ export default function build (url, options) {
1015
+ url = sanitizeUrl(url)
1016
+ if (options?.headers) {
1017
+ defaultHeaders = options.headers
1018
+ }
1019
+ return {
1020
+ getReports: _getReports.bind(url, ...arguments),
1021
+ createReport: _createReport.bind(url, ...arguments),
1022
+ updateReports: _updateReports.bind(url, ...arguments),
1023
+ getReportById: _getReportById.bind(url, ...arguments),
1024
+ updateReport: _updateReport.bind(url, ...arguments),
1025
+ deleteReports: _deleteReports.bind(url, ...arguments),
1026
+ createRule: _createRule.bind(url, ...arguments),
1027
+ updateRules: _updateRules.bind(url, ...arguments),
1028
+ getRuleById: _getRuleById.bind(url, ...arguments),
1029
+ updateRule: _updateRule.bind(url, ...arguments),
1030
+ deleteRules: _deleteRules.bind(url, ...arguments),
1031
+ getRuleConfigsForRule: _getRuleConfigsForRule.bind(url, ...arguments),
1032
+ getRuleConfigs: _getRuleConfigs.bind(url, ...arguments),
1033
+ createRuleConfig: _createRuleConfig.bind(url, ...arguments),
1034
+ updateRuleConfigs: _updateRuleConfigs.bind(url, ...arguments),
1035
+ getRuleConfigById: _getRuleConfigById.bind(url, ...arguments),
1036
+ updateRuleConfig: _updateRuleConfig.bind(url, ...arguments),
1037
+ deleteRuleConfigs: _deleteRuleConfigs.bind(url, ...arguments),
1038
+ getRuleForRuleConfig: _getRuleForRuleConfig.bind(url, ...arguments),
1039
+ getMetadata: _getMetadata.bind(url, ...arguments),
1040
+ updateMetadata: _updateMetadata.bind(url, ...arguments),
1041
+ getMetadatumById: _getMetadatumById.bind(url, ...arguments),
1042
+ updateMetadatum: _updateMetadatum.bind(url, ...arguments),
1043
+ deleteMetadata: _deleteMetadata.bind(url, ...arguments),
1044
+ postCompliance: _postCompliance.bind(url, ...arguments),
1045
+ postMetadata: _postMetadata.bind(url, ...arguments),
1046
+ postRulesName: _postRulesName.bind(url, ...arguments),
1047
+ getRules: _getRules.bind(url, ...arguments)
1048
+ }
1049
+ }