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