@touhidrahman/auditlog-sdk 1.0.0 → 1.0.2

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.
package/index.esm.js ADDED
@@ -0,0 +1,1077 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ const jsonBodySerializer = {
3
+ bodySerializer: body => JSON.stringify(body, (_key, value) => typeof value === 'bigint' ? value.toString() : value)
4
+ };
5
+
6
+ // This file is auto-generated by @hey-api/openapi-ts
7
+ function createSseClient({
8
+ onRequest,
9
+ onSseError,
10
+ onSseEvent,
11
+ responseTransformer,
12
+ responseValidator,
13
+ sseDefaultRetryDelay,
14
+ sseMaxRetryAttempts,
15
+ sseMaxRetryDelay,
16
+ sseSleepFn,
17
+ url,
18
+ ...options
19
+ }) {
20
+ let lastEventId;
21
+ const sleep = sseSleepFn ?? (ms => new Promise(resolve => setTimeout(resolve, ms)));
22
+ const createStream = async function* () {
23
+ let retryDelay = sseDefaultRetryDelay ?? 3000;
24
+ let attempt = 0;
25
+ const signal = options.signal ?? new AbortController().signal;
26
+ while (true) {
27
+ if (signal.aborted) break;
28
+ attempt++;
29
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
30
+ if (lastEventId !== undefined) {
31
+ headers.set('Last-Event-ID', lastEventId);
32
+ }
33
+ try {
34
+ const requestInit = {
35
+ redirect: 'follow',
36
+ ...options,
37
+ body: options.serializedBody,
38
+ headers,
39
+ signal
40
+ };
41
+ let request = new Request(url, requestInit);
42
+ if (onRequest) {
43
+ request = await onRequest(url, requestInit);
44
+ }
45
+ // fetch must be assigned here, otherwise it would throw the error:
46
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
47
+ const _fetch = options.fetch ?? globalThis.fetch;
48
+ const response = await _fetch(request);
49
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
50
+ if (!response.body) throw new Error('No body in SSE response');
51
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
52
+ let buffer = '';
53
+ const abortHandler = () => {
54
+ try {
55
+ reader.cancel();
56
+ } catch {
57
+ // noop
58
+ }
59
+ };
60
+ signal.addEventListener('abort', abortHandler);
61
+ try {
62
+ while (true) {
63
+ const {
64
+ done,
65
+ value
66
+ } = await reader.read();
67
+ if (done) break;
68
+ buffer += value;
69
+ buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings
70
+ const chunks = buffer.split('\n\n');
71
+ buffer = chunks.pop() ?? '';
72
+ for (const chunk of chunks) {
73
+ const lines = chunk.split('\n');
74
+ const dataLines = [];
75
+ let eventName;
76
+ for (const line of lines) {
77
+ if (line.startsWith('data:')) {
78
+ dataLines.push(line.replace(/^data:\s*/, ''));
79
+ } else if (line.startsWith('event:')) {
80
+ eventName = line.replace(/^event:\s*/, '');
81
+ } else if (line.startsWith('id:')) {
82
+ lastEventId = line.replace(/^id:\s*/, '');
83
+ } else if (line.startsWith('retry:')) {
84
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10);
85
+ if (!Number.isNaN(parsed)) {
86
+ retryDelay = parsed;
87
+ }
88
+ }
89
+ }
90
+ let data;
91
+ let parsedJson = false;
92
+ if (dataLines.length) {
93
+ const rawData = dataLines.join('\n');
94
+ try {
95
+ data = JSON.parse(rawData);
96
+ parsedJson = true;
97
+ } catch {
98
+ data = rawData;
99
+ }
100
+ }
101
+ if (parsedJson) {
102
+ if (responseValidator) {
103
+ await responseValidator(data);
104
+ }
105
+ if (responseTransformer) {
106
+ data = await responseTransformer(data);
107
+ }
108
+ }
109
+ onSseEvent?.({
110
+ data,
111
+ event: eventName,
112
+ id: lastEventId,
113
+ retry: retryDelay
114
+ });
115
+ if (dataLines.length) {
116
+ yield data;
117
+ }
118
+ }
119
+ }
120
+ } finally {
121
+ signal.removeEventListener('abort', abortHandler);
122
+ reader.releaseLock();
123
+ }
124
+ break; // exit loop on normal completion
125
+ } catch (error) {
126
+ // connection failed or aborted; retry after delay
127
+ onSseError?.(error);
128
+ if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) {
129
+ break; // stop after firing error
130
+ }
131
+ // exponential backoff: double retry each attempt, cap at 30s
132
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
133
+ await sleep(backoff);
134
+ }
135
+ }
136
+ };
137
+ const stream = createStream();
138
+ return {
139
+ stream
140
+ };
141
+ }
142
+
143
+ // This file is auto-generated by @hey-api/openapi-ts
144
+ const separatorArrayExplode = style => {
145
+ switch (style) {
146
+ case 'label':
147
+ return '.';
148
+ case 'matrix':
149
+ return ';';
150
+ case 'simple':
151
+ return ',';
152
+ default:
153
+ return '&';
154
+ }
155
+ };
156
+ const separatorArrayNoExplode = style => {
157
+ switch (style) {
158
+ case 'form':
159
+ return ',';
160
+ case 'pipeDelimited':
161
+ return '|';
162
+ case 'spaceDelimited':
163
+ return '%20';
164
+ default:
165
+ return ',';
166
+ }
167
+ };
168
+ const separatorObjectExplode = style => {
169
+ switch (style) {
170
+ case 'label':
171
+ return '.';
172
+ case 'matrix':
173
+ return ';';
174
+ case 'simple':
175
+ return ',';
176
+ default:
177
+ return '&';
178
+ }
179
+ };
180
+ const serializeArrayParam = ({
181
+ allowReserved,
182
+ explode,
183
+ name,
184
+ style,
185
+ value
186
+ }) => {
187
+ if (!explode) {
188
+ const joinedValues = (allowReserved ? value : value.map(v => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
189
+ switch (style) {
190
+ case 'label':
191
+ return `.${joinedValues}`;
192
+ case 'matrix':
193
+ return `;${name}=${joinedValues}`;
194
+ case 'simple':
195
+ return joinedValues;
196
+ default:
197
+ return `${name}=${joinedValues}`;
198
+ }
199
+ }
200
+ const separator = separatorArrayExplode(style);
201
+ const joinedValues = value.map(v => {
202
+ if (style === 'label' || style === 'simple') {
203
+ return allowReserved ? v : encodeURIComponent(v);
204
+ }
205
+ return serializePrimitiveParam({
206
+ allowReserved,
207
+ name,
208
+ value: v
209
+ });
210
+ }).join(separator);
211
+ return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues;
212
+ };
213
+ const serializePrimitiveParam = ({
214
+ allowReserved,
215
+ name,
216
+ value
217
+ }) => {
218
+ if (value === undefined || value === null) {
219
+ return '';
220
+ }
221
+ if (typeof value === 'object') {
222
+ throw new Error('Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.');
223
+ }
224
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
225
+ };
226
+ const serializeObjectParam = ({
227
+ allowReserved,
228
+ explode,
229
+ name,
230
+ style,
231
+ value,
232
+ valueOnly
233
+ }) => {
234
+ if (value instanceof Date) {
235
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
236
+ }
237
+ if (style !== 'deepObject' && !explode) {
238
+ let values = [];
239
+ Object.entries(value).forEach(([key, v]) => {
240
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
241
+ });
242
+ const joinedValues = values.join(',');
243
+ switch (style) {
244
+ case 'form':
245
+ return `${name}=${joinedValues}`;
246
+ case 'label':
247
+ return `.${joinedValues}`;
248
+ case 'matrix':
249
+ return `;${name}=${joinedValues}`;
250
+ default:
251
+ return joinedValues;
252
+ }
253
+ }
254
+ const separator = separatorObjectExplode(style);
255
+ const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
256
+ allowReserved,
257
+ name: style === 'deepObject' ? `${name}[${key}]` : key,
258
+ value: v
259
+ })).join(separator);
260
+ return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues;
261
+ };
262
+
263
+ // This file is auto-generated by @hey-api/openapi-ts
264
+ const PATH_PARAM_RE = /\{[^{}]+\}/g;
265
+ const defaultPathSerializer = ({
266
+ path,
267
+ url: _url
268
+ }) => {
269
+ let url = _url;
270
+ const matches = _url.match(PATH_PARAM_RE);
271
+ if (matches) {
272
+ for (const match of matches) {
273
+ let explode = false;
274
+ let name = match.substring(1, match.length - 1);
275
+ let style = 'simple';
276
+ if (name.endsWith('*')) {
277
+ explode = true;
278
+ name = name.substring(0, name.length - 1);
279
+ }
280
+ if (name.startsWith('.')) {
281
+ name = name.substring(1);
282
+ style = 'label';
283
+ } else if (name.startsWith(';')) {
284
+ name = name.substring(1);
285
+ style = 'matrix';
286
+ }
287
+ const value = path[name];
288
+ if (value === undefined || value === null) {
289
+ continue;
290
+ }
291
+ if (Array.isArray(value)) {
292
+ url = url.replace(match, serializeArrayParam({
293
+ explode,
294
+ name,
295
+ style,
296
+ value
297
+ }));
298
+ continue;
299
+ }
300
+ if (typeof value === 'object') {
301
+ url = url.replace(match, serializeObjectParam({
302
+ explode,
303
+ name,
304
+ style,
305
+ value: value,
306
+ valueOnly: true
307
+ }));
308
+ continue;
309
+ }
310
+ if (style === 'matrix') {
311
+ url = url.replace(match, `;${serializePrimitiveParam({
312
+ name,
313
+ value: value
314
+ })}`);
315
+ continue;
316
+ }
317
+ const replaceValue = encodeURIComponent(style === 'label' ? `.${value}` : value);
318
+ url = url.replace(match, replaceValue);
319
+ }
320
+ }
321
+ return url;
322
+ };
323
+ const getUrl = ({
324
+ baseUrl,
325
+ path,
326
+ query,
327
+ querySerializer,
328
+ url: _url
329
+ }) => {
330
+ const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
331
+ let url = (baseUrl ?? '') + pathUrl;
332
+ if (path) {
333
+ url = defaultPathSerializer({
334
+ path,
335
+ url
336
+ });
337
+ }
338
+ let search = query ? querySerializer(query) : '';
339
+ if (search.startsWith('?')) {
340
+ search = search.substring(1);
341
+ }
342
+ if (search) {
343
+ url += `?${search}`;
344
+ }
345
+ return url;
346
+ };
347
+ function getValidRequestBody(options) {
348
+ const hasBody = options.body !== undefined;
349
+ const isSerializedBody = hasBody && options.bodySerializer;
350
+ if (isSerializedBody) {
351
+ if ('serializedBody' in options) {
352
+ const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== '';
353
+ return hasSerializedBody ? options.serializedBody : null;
354
+ }
355
+ // not all clients implement a serializedBody property (i.e., client-axios)
356
+ return options.body !== '' ? options.body : null;
357
+ }
358
+ // plain/text body
359
+ if (hasBody) {
360
+ return options.body;
361
+ }
362
+ // no body was provided
363
+ return undefined;
364
+ }
365
+
366
+ // This file is auto-generated by @hey-api/openapi-ts
367
+ const getAuthToken = async (auth, callback) => {
368
+ const token = typeof callback === 'function' ? await callback(auth) : callback;
369
+ if (!token) {
370
+ return;
371
+ }
372
+ if (auth.scheme === 'bearer') {
373
+ return `Bearer ${token}`;
374
+ }
375
+ if (auth.scheme === 'basic') {
376
+ return `Basic ${btoa(token)}`;
377
+ }
378
+ return token;
379
+ };
380
+
381
+ // This file is auto-generated by @hey-api/openapi-ts
382
+ const createQuerySerializer = ({
383
+ parameters = {},
384
+ ...args
385
+ } = {}) => {
386
+ const querySerializer = queryParams => {
387
+ const search = [];
388
+ if (queryParams && typeof queryParams === 'object') {
389
+ for (const name in queryParams) {
390
+ const value = queryParams[name];
391
+ if (value === undefined || value === null) {
392
+ continue;
393
+ }
394
+ const options = parameters[name] || args;
395
+ if (Array.isArray(value)) {
396
+ const serializedArray = serializeArrayParam({
397
+ allowReserved: options.allowReserved,
398
+ explode: true,
399
+ name,
400
+ style: 'form',
401
+ value,
402
+ ...options.array
403
+ });
404
+ if (serializedArray) search.push(serializedArray);
405
+ } else if (typeof value === 'object') {
406
+ const serializedObject = serializeObjectParam({
407
+ allowReserved: options.allowReserved,
408
+ explode: true,
409
+ name,
410
+ style: 'deepObject',
411
+ value: value,
412
+ ...options.object
413
+ });
414
+ if (serializedObject) search.push(serializedObject);
415
+ } else {
416
+ const serializedPrimitive = serializePrimitiveParam({
417
+ allowReserved: options.allowReserved,
418
+ name,
419
+ value: value
420
+ });
421
+ if (serializedPrimitive) search.push(serializedPrimitive);
422
+ }
423
+ }
424
+ }
425
+ return search.join('&');
426
+ };
427
+ return querySerializer;
428
+ };
429
+ /**
430
+ * Infers parseAs value from provided Content-Type header.
431
+ */
432
+ const getParseAs = contentType => {
433
+ if (!contentType) {
434
+ // If no Content-Type header is provided, the best we can do is return the raw response body,
435
+ // which is effectively the same as the 'stream' option.
436
+ return 'stream';
437
+ }
438
+ const cleanContent = contentType.split(';')[0]?.trim();
439
+ if (!cleanContent) {
440
+ return;
441
+ }
442
+ if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
443
+ return 'json';
444
+ }
445
+ if (cleanContent === 'multipart/form-data') {
446
+ return 'formData';
447
+ }
448
+ if (['application/', 'audio/', 'image/', 'video/'].some(type => cleanContent.startsWith(type))) {
449
+ return 'blob';
450
+ }
451
+ if (cleanContent.startsWith('text/')) {
452
+ return 'text';
453
+ }
454
+ return;
455
+ };
456
+ const checkForExistence = (options, name) => {
457
+ if (!name) {
458
+ return false;
459
+ }
460
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get('Cookie')?.includes(`${name}=`)) {
461
+ return true;
462
+ }
463
+ return false;
464
+ };
465
+ async function setAuthParams(options) {
466
+ for (const auth of options.security ?? []) {
467
+ if (checkForExistence(options, auth.name)) {
468
+ continue;
469
+ }
470
+ const token = await getAuthToken(auth, options.auth);
471
+ if (!token) {
472
+ continue;
473
+ }
474
+ const name = auth.name ?? 'Authorization';
475
+ switch (auth.in) {
476
+ case 'query':
477
+ if (!options.query) {
478
+ options.query = {};
479
+ }
480
+ options.query[name] = token;
481
+ break;
482
+ case 'cookie':
483
+ options.headers.append('Cookie', `${name}=${token}`);
484
+ break;
485
+ case 'header':
486
+ default:
487
+ options.headers.set(name, token);
488
+ break;
489
+ }
490
+ }
491
+ }
492
+ const buildUrl = options => getUrl({
493
+ baseUrl: options.baseUrl,
494
+ path: options.path,
495
+ query: options.query,
496
+ querySerializer: typeof options.querySerializer === 'function' ? options.querySerializer : createQuerySerializer(options.querySerializer),
497
+ url: options.url
498
+ });
499
+ const mergeConfigs = (a, b) => {
500
+ const config = {
501
+ ...a,
502
+ ...b
503
+ };
504
+ if (config.baseUrl?.endsWith('/')) {
505
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
506
+ }
507
+ config.headers = mergeHeaders(a.headers, b.headers);
508
+ return config;
509
+ };
510
+ const headersEntries = headers => {
511
+ const entries = [];
512
+ headers.forEach((value, key) => {
513
+ entries.push([key, value]);
514
+ });
515
+ return entries;
516
+ };
517
+ const mergeHeaders = (...headers) => {
518
+ const mergedHeaders = new Headers();
519
+ for (const header of headers) {
520
+ if (!header) {
521
+ continue;
522
+ }
523
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
524
+ for (const [key, value] of iterator) {
525
+ if (value === null) {
526
+ mergedHeaders.delete(key);
527
+ } else if (Array.isArray(value)) {
528
+ for (const v of value) {
529
+ mergedHeaders.append(key, v);
530
+ }
531
+ } else if (value !== undefined) {
532
+ // assume object headers are meant to be JSON stringified, i.e., their
533
+ // content value in OpenAPI specification is 'application/json'
534
+ mergedHeaders.set(key, typeof value === 'object' ? JSON.stringify(value) : value);
535
+ }
536
+ }
537
+ }
538
+ return mergedHeaders;
539
+ };
540
+ class Interceptors {
541
+ fns = [];
542
+ clear() {
543
+ this.fns = [];
544
+ }
545
+ eject(id) {
546
+ const index = this.getInterceptorIndex(id);
547
+ if (this.fns[index]) {
548
+ this.fns[index] = null;
549
+ }
550
+ }
551
+ exists(id) {
552
+ const index = this.getInterceptorIndex(id);
553
+ return Boolean(this.fns[index]);
554
+ }
555
+ getInterceptorIndex(id) {
556
+ if (typeof id === 'number') {
557
+ return this.fns[id] ? id : -1;
558
+ }
559
+ return this.fns.indexOf(id);
560
+ }
561
+ update(id, fn) {
562
+ const index = this.getInterceptorIndex(id);
563
+ if (this.fns[index]) {
564
+ this.fns[index] = fn;
565
+ return id;
566
+ }
567
+ return false;
568
+ }
569
+ use(fn) {
570
+ this.fns.push(fn);
571
+ return this.fns.length - 1;
572
+ }
573
+ }
574
+ const createInterceptors = () => ({
575
+ error: new Interceptors(),
576
+ request: new Interceptors(),
577
+ response: new Interceptors()
578
+ });
579
+ const defaultQuerySerializer = createQuerySerializer({
580
+ allowReserved: false,
581
+ array: {
582
+ explode: true,
583
+ style: 'form'
584
+ },
585
+ object: {
586
+ explode: true,
587
+ style: 'deepObject'
588
+ }
589
+ });
590
+ const defaultHeaders = {
591
+ 'Content-Type': 'application/json'
592
+ };
593
+ const createConfig = (override = {}) => ({
594
+ ...jsonBodySerializer,
595
+ headers: defaultHeaders,
596
+ parseAs: 'auto',
597
+ querySerializer: defaultQuerySerializer,
598
+ ...override
599
+ });
600
+
601
+ // This file is auto-generated by @hey-api/openapi-ts
602
+ const createClient = (config = {}) => {
603
+ let _config = mergeConfigs(createConfig(), config);
604
+ const getConfig = () => ({
605
+ ..._config
606
+ });
607
+ const setConfig = config => {
608
+ _config = mergeConfigs(_config, config);
609
+ return getConfig();
610
+ };
611
+ const interceptors = createInterceptors();
612
+ const beforeRequest = async options => {
613
+ const opts = {
614
+ ..._config,
615
+ ...options,
616
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
617
+ headers: mergeHeaders(_config.headers, options.headers),
618
+ serializedBody: undefined
619
+ };
620
+ if (opts.security) {
621
+ await setAuthParams(opts);
622
+ }
623
+ if (opts.requestValidator) {
624
+ await opts.requestValidator(opts);
625
+ }
626
+ if (opts.body !== undefined && opts.bodySerializer) {
627
+ opts.serializedBody = opts.bodySerializer(opts.body);
628
+ }
629
+ // remove Content-Type header if body is empty to avoid sending invalid requests
630
+ if (opts.body === undefined || opts.serializedBody === '') {
631
+ opts.headers.delete('Content-Type');
632
+ }
633
+ const resolvedOpts = opts;
634
+ const url = buildUrl(resolvedOpts);
635
+ return {
636
+ opts: resolvedOpts,
637
+ url
638
+ };
639
+ };
640
+ const request = async options => {
641
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
642
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
643
+ let request;
644
+ let response;
645
+ try {
646
+ const {
647
+ opts,
648
+ url
649
+ } = await beforeRequest(options);
650
+ const requestInit = {
651
+ redirect: 'follow',
652
+ ...opts,
653
+ body: getValidRequestBody(opts)
654
+ };
655
+ request = new Request(url, requestInit);
656
+ for (const fn of interceptors.request.fns) {
657
+ if (fn) {
658
+ request = await fn(request, opts);
659
+ }
660
+ }
661
+ // fetch must be assigned here, otherwise it would throw the error:
662
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
663
+ const _fetch = opts.fetch;
664
+ response = await _fetch(request);
665
+ for (const fn of interceptors.response.fns) {
666
+ if (fn) {
667
+ response = await fn(response, request, opts);
668
+ }
669
+ }
670
+ const result = {
671
+ request,
672
+ response
673
+ };
674
+ if (response.ok) {
675
+ const parseAs = (opts.parseAs === 'auto' ? getParseAs(response.headers.get('Content-Type')) : opts.parseAs) ?? 'json';
676
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
677
+ let emptyData;
678
+ switch (parseAs) {
679
+ case 'arrayBuffer':
680
+ case 'blob':
681
+ case 'text':
682
+ emptyData = await response[parseAs]();
683
+ break;
684
+ case 'formData':
685
+ emptyData = new FormData();
686
+ break;
687
+ case 'stream':
688
+ emptyData = response.body;
689
+ break;
690
+ case 'json':
691
+ default:
692
+ emptyData = {};
693
+ break;
694
+ }
695
+ return opts.responseStyle === 'data' ? emptyData : {
696
+ data: emptyData,
697
+ ...result
698
+ };
699
+ }
700
+ let data;
701
+ switch (parseAs) {
702
+ case 'arrayBuffer':
703
+ case 'blob':
704
+ case 'formData':
705
+ case 'text':
706
+ data = await response[parseAs]();
707
+ break;
708
+ case 'json':
709
+ {
710
+ // Some servers return 200 with no Content-Length and empty body.
711
+ // response.json() would throw; read as text and parse if non-empty.
712
+ const text = await response.text();
713
+ data = text ? JSON.parse(text) : {};
714
+ break;
715
+ }
716
+ case 'stream':
717
+ return opts.responseStyle === 'data' ? response.body : {
718
+ data: response.body,
719
+ ...result
720
+ };
721
+ }
722
+ if (parseAs === 'json') {
723
+ if (opts.responseValidator) {
724
+ await opts.responseValidator(data);
725
+ }
726
+ if (opts.responseTransformer) {
727
+ data = await opts.responseTransformer(data);
728
+ }
729
+ }
730
+ return opts.responseStyle === 'data' ? data : {
731
+ data,
732
+ ...result
733
+ };
734
+ }
735
+ const textError = await response.text();
736
+ let jsonError;
737
+ try {
738
+ jsonError = JSON.parse(textError);
739
+ } catch {
740
+ // noop
741
+ }
742
+ throw jsonError ?? textError;
743
+ } catch (error) {
744
+ let finalError = error;
745
+ for (const fn of interceptors.error.fns) {
746
+ if (fn) {
747
+ finalError = await fn(finalError, response, request, options);
748
+ }
749
+ }
750
+ finalError = finalError || {};
751
+ if (throwOnError) {
752
+ throw finalError;
753
+ }
754
+ // TODO: we probably want to return error and improve types
755
+ return responseStyle === 'data' ? undefined : {
756
+ error: finalError,
757
+ request,
758
+ response
759
+ };
760
+ }
761
+ };
762
+ const makeMethodFn = method => options => request({
763
+ ...options,
764
+ method
765
+ });
766
+ const makeSseFn = method => async options => {
767
+ const {
768
+ opts,
769
+ url
770
+ } = await beforeRequest(options);
771
+ return createSseClient({
772
+ ...opts,
773
+ body: opts.body,
774
+ method,
775
+ onRequest: async (url, init) => {
776
+ let request = new Request(url, init);
777
+ for (const fn of interceptors.request.fns) {
778
+ if (fn) {
779
+ request = await fn(request, opts);
780
+ }
781
+ }
782
+ return request;
783
+ },
784
+ serializedBody: getValidRequestBody(opts),
785
+ url
786
+ });
787
+ };
788
+ const _buildUrl = options => buildUrl({
789
+ ..._config,
790
+ ...options
791
+ });
792
+ return {
793
+ buildUrl: _buildUrl,
794
+ connect: makeMethodFn('CONNECT'),
795
+ delete: makeMethodFn('DELETE'),
796
+ get: makeMethodFn('GET'),
797
+ getConfig,
798
+ head: makeMethodFn('HEAD'),
799
+ interceptors,
800
+ options: makeMethodFn('OPTIONS'),
801
+ patch: makeMethodFn('PATCH'),
802
+ post: makeMethodFn('POST'),
803
+ put: makeMethodFn('PUT'),
804
+ request,
805
+ setConfig,
806
+ sse: {
807
+ connect: makeSseFn('CONNECT'),
808
+ delete: makeSseFn('DELETE'),
809
+ get: makeSseFn('GET'),
810
+ head: makeSseFn('HEAD'),
811
+ options: makeSseFn('OPTIONS'),
812
+ patch: makeSseFn('PATCH'),
813
+ post: makeSseFn('POST'),
814
+ put: makeSseFn('PUT'),
815
+ trace: makeSseFn('TRACE')
816
+ },
817
+ trace: makeMethodFn('TRACE')
818
+ };
819
+ };
820
+
821
+ // This file is auto-generated by @hey-api/openapi-ts
822
+ const client = createClient(createConfig({
823
+ baseUrl: 'https://auditlog-api.mattrika.com'
824
+ }));
825
+
826
+ // This file is auto-generated by @hey-api/openapi-ts
827
+ const postAdminNewTokenResponseTransformer = async data => {
828
+ if (data.data.lastLogin) {
829
+ data.data.lastLogin = new Date(data.data.lastLogin);
830
+ }
831
+ return data;
832
+ };
833
+ const postAdminLoginResponseTransformer = async data => {
834
+ if (data.data.lastLogin) {
835
+ data.data.lastLogin = new Date(data.data.lastLogin);
836
+ }
837
+ return data;
838
+ };
839
+ const getProjectsResponseTransformer = async data => {
840
+ data.data = data.data.map(item => {
841
+ if (item.createdAt) {
842
+ item.createdAt = new Date(item.createdAt);
843
+ }
844
+ if (item.updatedAt) {
845
+ item.updatedAt = new Date(item.updatedAt);
846
+ }
847
+ return item;
848
+ });
849
+ return data;
850
+ };
851
+ const postProjectsResponseTransformer = async data => {
852
+ if (data.data.createdAt) {
853
+ data.data.createdAt = new Date(data.data.createdAt);
854
+ }
855
+ if (data.data.updatedAt) {
856
+ data.data.updatedAt = new Date(data.data.updatedAt);
857
+ }
858
+ return data;
859
+ };
860
+ const deleteProjectsByProjectIdResponseTransformer = async data => {
861
+ if (data.data.createdAt) {
862
+ data.data.createdAt = new Date(data.data.createdAt);
863
+ }
864
+ if (data.data.updatedAt) {
865
+ data.data.updatedAt = new Date(data.data.updatedAt);
866
+ }
867
+ return data;
868
+ };
869
+ const getProjectsByProjectIdResponseTransformer = async data => {
870
+ if (data.data.createdAt) {
871
+ data.data.createdAt = new Date(data.data.createdAt);
872
+ }
873
+ if (data.data.updatedAt) {
874
+ data.data.updatedAt = new Date(data.data.updatedAt);
875
+ }
876
+ return data;
877
+ };
878
+ const putProjectsByProjectIdResponseTransformer = async data => {
879
+ if (data.data.createdAt) {
880
+ data.data.createdAt = new Date(data.data.createdAt);
881
+ }
882
+ if (data.data.updatedAt) {
883
+ data.data.updatedAt = new Date(data.data.updatedAt);
884
+ }
885
+ return data;
886
+ };
887
+ const getSecretKeysResponseTransformer = async data => {
888
+ data.data = data.data.map(item => {
889
+ if (item.expiresAt) {
890
+ item.expiresAt = new Date(item.expiresAt);
891
+ }
892
+ if (item.createdAt) {
893
+ item.createdAt = new Date(item.createdAt);
894
+ }
895
+ return item;
896
+ });
897
+ return data;
898
+ };
899
+ const postSecretKeysResponseTransformer = async data => {
900
+ if (data.data.expiresAt) {
901
+ data.data.expiresAt = new Date(data.data.expiresAt);
902
+ }
903
+ if (data.data.createdAt) {
904
+ data.data.createdAt = new Date(data.data.createdAt);
905
+ }
906
+ return data;
907
+ };
908
+ const deleteSecretKeysByIdResponseTransformer = async data => {
909
+ if (data.data.expiresAt) {
910
+ data.data.expiresAt = new Date(data.data.expiresAt);
911
+ }
912
+ if (data.data.createdAt) {
913
+ data.data.createdAt = new Date(data.data.createdAt);
914
+ }
915
+ return data;
916
+ };
917
+ const getSecretKeysByIdResponseTransformer = async data => {
918
+ if (data.data.expiresAt) {
919
+ data.data.expiresAt = new Date(data.data.expiresAt);
920
+ }
921
+ if (data.data.createdAt) {
922
+ data.data.createdAt = new Date(data.data.createdAt);
923
+ }
924
+ return data;
925
+ };
926
+ const getLogsResponseTransformer = async data => {
927
+ data.data = data.data.map(item => {
928
+ if (item.createdAt) {
929
+ item.createdAt = new Date(item.createdAt);
930
+ }
931
+ if (item.updatedAt) {
932
+ item.updatedAt = new Date(item.updatedAt);
933
+ }
934
+ return item;
935
+ });
936
+ return data;
937
+ };
938
+ const postLogsResponseTransformer = async data => {
939
+ if (data.data.createdAt) {
940
+ data.data.createdAt = new Date(data.data.createdAt);
941
+ }
942
+ if (data.data.updatedAt) {
943
+ data.data.updatedAt = new Date(data.data.updatedAt);
944
+ }
945
+ return data;
946
+ };
947
+ const getLogsIdResponseTransformer = async data => {
948
+ if (data.data.createdAt) {
949
+ data.data.createdAt = new Date(data.data.createdAt);
950
+ }
951
+ if (data.data.updatedAt) {
952
+ data.data.updatedAt = new Date(data.data.updatedAt);
953
+ }
954
+ return data;
955
+ };
956
+
957
+ // This file is auto-generated by @hey-api/openapi-ts
958
+ const get = options => (options?.client ?? client).get({
959
+ url: '/',
960
+ ...options
961
+ });
962
+ const postAdminNewToken = options => (options.client ?? client).post({
963
+ responseTransformer: postAdminNewTokenResponseTransformer,
964
+ url: '/admin/new-token',
965
+ ...options,
966
+ headers: {
967
+ 'Content-Type': 'application/json',
968
+ ...options.headers
969
+ }
970
+ });
971
+ const postAdminLogin = options => (options.client ?? client).post({
972
+ responseTransformer: postAdminLoginResponseTransformer,
973
+ url: '/admin/login',
974
+ ...options,
975
+ headers: {
976
+ 'Content-Type': 'application/json',
977
+ ...options.headers
978
+ }
979
+ });
980
+ const getProjects = options => (options?.client ?? client).get({
981
+ responseTransformer: getProjectsResponseTransformer,
982
+ url: '/projects',
983
+ ...options
984
+ });
985
+ const postProjects = options => (options?.client ?? client).post({
986
+ responseTransformer: postProjectsResponseTransformer,
987
+ url: '/projects',
988
+ ...options,
989
+ headers: {
990
+ 'Content-Type': 'application/json',
991
+ ...options?.headers
992
+ }
993
+ });
994
+ const deleteProjectsByProjectId = options => (options.client ?? client).delete({
995
+ responseTransformer: deleteProjectsByProjectIdResponseTransformer,
996
+ url: '/projects/{projectId}',
997
+ ...options
998
+ });
999
+ const getProjectsByProjectId = options => (options.client ?? client).get({
1000
+ responseTransformer: getProjectsByProjectIdResponseTransformer,
1001
+ url: '/projects/{projectId}',
1002
+ ...options
1003
+ });
1004
+ const putProjectsByProjectId = options => (options.client ?? client).put({
1005
+ responseTransformer: putProjectsByProjectIdResponseTransformer,
1006
+ url: '/projects/{projectId}',
1007
+ ...options,
1008
+ headers: {
1009
+ 'Content-Type': 'application/json',
1010
+ ...options.headers
1011
+ }
1012
+ });
1013
+ const putProjectsByProjectIdChangeId = options => (options.client ?? client).put({
1014
+ url: '/projects/{projectId}/change-id',
1015
+ ...options,
1016
+ headers: {
1017
+ 'Content-Type': 'application/json',
1018
+ ...options.headers
1019
+ }
1020
+ });
1021
+ const getSecretKeys = options => (options?.client ?? client).get({
1022
+ responseTransformer: getSecretKeysResponseTransformer,
1023
+ url: '/secret-keys',
1024
+ ...options
1025
+ });
1026
+ const postSecretKeys = options => (options?.client ?? client).post({
1027
+ responseTransformer: postSecretKeysResponseTransformer,
1028
+ url: '/secret-keys',
1029
+ ...options,
1030
+ headers: {
1031
+ 'Content-Type': 'application/json',
1032
+ ...options?.headers
1033
+ }
1034
+ });
1035
+ const deleteSecretKeysById = options => (options.client ?? client).delete({
1036
+ responseTransformer: deleteSecretKeysByIdResponseTransformer,
1037
+ url: '/secret-keys/{id}',
1038
+ ...options
1039
+ });
1040
+ const getSecretKeysById = options => (options.client ?? client).get({
1041
+ responseTransformer: getSecretKeysByIdResponseTransformer,
1042
+ url: '/secret-keys/{id}',
1043
+ ...options
1044
+ });
1045
+ const getLogs = options => (options?.client ?? client).get({
1046
+ responseTransformer: getLogsResponseTransformer,
1047
+ url: '/logs',
1048
+ ...options
1049
+ });
1050
+ const postLogs = options => (options?.client ?? client).post({
1051
+ responseTransformer: postLogsResponseTransformer,
1052
+ url: '/logs',
1053
+ ...options,
1054
+ headers: {
1055
+ 'Content-Type': 'application/json',
1056
+ ...options?.headers
1057
+ }
1058
+ });
1059
+ const getLogsExportCsv = options => (options?.client ?? client).get({
1060
+ url: '/logs/export/csv',
1061
+ ...options
1062
+ });
1063
+ const deleteLogsId = options => (options.client ?? client).delete({
1064
+ url: '/logs/:id',
1065
+ ...options
1066
+ });
1067
+ const getLogsId = options => (options.client ?? client).get({
1068
+ responseTransformer: getLogsIdResponseTransformer,
1069
+ url: '/logs/:id',
1070
+ ...options
1071
+ });
1072
+ const deleteLogsEntityEntityId = options => (options.client ?? client).delete({
1073
+ url: '/logs/entity/:entityId',
1074
+ ...options
1075
+ });
1076
+
1077
+ export { client, deleteLogsEntityEntityId, deleteLogsId, deleteProjectsByProjectId, deleteSecretKeysById, get, getLogs, getLogsExportCsv, getLogsId, getProjects, getProjectsByProjectId, getSecretKeys, getSecretKeysById, postAdminLogin, postAdminNewToken, postLogs, postProjects, postSecretKeys, putProjectsByProjectId, putProjectsByProjectIdChangeId };