@praxium/sdk 0.2.4

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/dist/index.js ADDED
@@ -0,0 +1,987 @@
1
+ // src/generated/core/bodySerializer.gen.ts
2
+ var jsonBodySerializer = {
3
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
4
+ };
5
+
6
+ // src/generated/core/params.gen.ts
7
+ var extraPrefixesMap = {
8
+ $body_: "body",
9
+ $headers_: "headers",
10
+ $path_: "path",
11
+ $query_: "query"
12
+ };
13
+ var extraPrefixes = Object.entries(extraPrefixesMap);
14
+
15
+ // src/generated/core/serverSentEvents.gen.ts
16
+ var createSseClient = ({
17
+ onRequest,
18
+ onSseError,
19
+ onSseEvent,
20
+ responseTransformer,
21
+ responseValidator,
22
+ sseDefaultRetryDelay,
23
+ sseMaxRetryAttempts,
24
+ sseMaxRetryDelay,
25
+ sseSleepFn,
26
+ url,
27
+ ...options
28
+ }) => {
29
+ let lastEventId;
30
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
31
+ const createStream = async function* () {
32
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
33
+ let attempt = 0;
34
+ const signal = options.signal ?? new AbortController().signal;
35
+ while (true) {
36
+ if (signal.aborted) break;
37
+ attempt++;
38
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
39
+ if (lastEventId !== void 0) {
40
+ headers.set("Last-Event-ID", lastEventId);
41
+ }
42
+ try {
43
+ const requestInit = {
44
+ redirect: "follow",
45
+ ...options,
46
+ body: options.serializedBody,
47
+ headers,
48
+ signal
49
+ };
50
+ let request = new Request(url, requestInit);
51
+ if (onRequest) {
52
+ request = await onRequest(url, requestInit);
53
+ }
54
+ const _fetch = options.fetch ?? globalThis.fetch;
55
+ const response = await _fetch(request);
56
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
57
+ if (!response.body) throw new Error("No body in SSE response");
58
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
59
+ let buffer = "";
60
+ const abortHandler = () => {
61
+ try {
62
+ reader.cancel();
63
+ } catch {
64
+ }
65
+ };
66
+ signal.addEventListener("abort", abortHandler);
67
+ try {
68
+ while (true) {
69
+ const { done, value } = await reader.read();
70
+ if (done) break;
71
+ buffer += value;
72
+ buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
73
+ const chunks = buffer.split("\n\n");
74
+ buffer = chunks.pop() ?? "";
75
+ for (const chunk of chunks) {
76
+ const lines = chunk.split("\n");
77
+ const dataLines = [];
78
+ let eventName;
79
+ for (const line of lines) {
80
+ if (line.startsWith("data:")) {
81
+ dataLines.push(line.replace(/^data:\s*/, ""));
82
+ } else if (line.startsWith("event:")) {
83
+ eventName = line.replace(/^event:\s*/, "");
84
+ } else if (line.startsWith("id:")) {
85
+ lastEventId = line.replace(/^id:\s*/, "");
86
+ } else if (line.startsWith("retry:")) {
87
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
88
+ if (!Number.isNaN(parsed)) {
89
+ retryDelay = parsed;
90
+ }
91
+ }
92
+ }
93
+ let data;
94
+ let parsedJson = false;
95
+ if (dataLines.length) {
96
+ const rawData = dataLines.join("\n");
97
+ try {
98
+ data = JSON.parse(rawData);
99
+ parsedJson = true;
100
+ } catch {
101
+ data = rawData;
102
+ }
103
+ }
104
+ if (parsedJson) {
105
+ if (responseValidator) {
106
+ await responseValidator(data);
107
+ }
108
+ if (responseTransformer) {
109
+ data = await responseTransformer(data);
110
+ }
111
+ }
112
+ onSseEvent?.({
113
+ data,
114
+ event: eventName,
115
+ id: lastEventId,
116
+ retry: retryDelay
117
+ });
118
+ if (dataLines.length) {
119
+ yield data;
120
+ }
121
+ }
122
+ }
123
+ } finally {
124
+ signal.removeEventListener("abort", abortHandler);
125
+ reader.releaseLock();
126
+ }
127
+ break;
128
+ } catch (error) {
129
+ onSseError?.(error);
130
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
131
+ break;
132
+ }
133
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
134
+ await sleep(backoff);
135
+ }
136
+ }
137
+ };
138
+ const stream = createStream();
139
+ return { stream };
140
+ };
141
+
142
+ // src/generated/core/pathSerializer.gen.ts
143
+ var separatorArrayExplode = (style) => {
144
+ switch (style) {
145
+ case "label":
146
+ return ".";
147
+ case "matrix":
148
+ return ";";
149
+ case "simple":
150
+ return ",";
151
+ default:
152
+ return "&";
153
+ }
154
+ };
155
+ var separatorArrayNoExplode = (style) => {
156
+ switch (style) {
157
+ case "form":
158
+ return ",";
159
+ case "pipeDelimited":
160
+ return "|";
161
+ case "spaceDelimited":
162
+ return "%20";
163
+ default:
164
+ return ",";
165
+ }
166
+ };
167
+ var separatorObjectExplode = (style) => {
168
+ switch (style) {
169
+ case "label":
170
+ return ".";
171
+ case "matrix":
172
+ return ";";
173
+ case "simple":
174
+ return ",";
175
+ default:
176
+ return "&";
177
+ }
178
+ };
179
+ var serializeArrayParam = ({
180
+ allowReserved,
181
+ explode,
182
+ name,
183
+ style,
184
+ value
185
+ }) => {
186
+ if (!explode) {
187
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
188
+ switch (style) {
189
+ case "label":
190
+ return `.${joinedValues2}`;
191
+ case "matrix":
192
+ return `;${name}=${joinedValues2}`;
193
+ case "simple":
194
+ return joinedValues2;
195
+ default:
196
+ return `${name}=${joinedValues2}`;
197
+ }
198
+ }
199
+ const separator = separatorArrayExplode(style);
200
+ const joinedValues = value.map((v) => {
201
+ if (style === "label" || style === "simple") {
202
+ return allowReserved ? v : encodeURIComponent(v);
203
+ }
204
+ return serializePrimitiveParam({
205
+ allowReserved,
206
+ name,
207
+ value: v
208
+ });
209
+ }).join(separator);
210
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
211
+ };
212
+ var serializePrimitiveParam = ({
213
+ allowReserved,
214
+ name,
215
+ value
216
+ }) => {
217
+ if (value === void 0 || value === null) {
218
+ return "";
219
+ }
220
+ if (typeof value === "object") {
221
+ throw new Error(
222
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
223
+ );
224
+ }
225
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
226
+ };
227
+ var serializeObjectParam = ({
228
+ allowReserved,
229
+ explode,
230
+ name,
231
+ style,
232
+ value,
233
+ valueOnly
234
+ }) => {
235
+ if (value instanceof Date) {
236
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
237
+ }
238
+ if (style !== "deepObject" && !explode) {
239
+ let values = [];
240
+ Object.entries(value).forEach(([key, v]) => {
241
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
242
+ });
243
+ const joinedValues2 = values.join(",");
244
+ switch (style) {
245
+ case "form":
246
+ return `${name}=${joinedValues2}`;
247
+ case "label":
248
+ return `.${joinedValues2}`;
249
+ case "matrix":
250
+ return `;${name}=${joinedValues2}`;
251
+ default:
252
+ return joinedValues2;
253
+ }
254
+ }
255
+ const separator = separatorObjectExplode(style);
256
+ const joinedValues = Object.entries(value).map(
257
+ ([key, v]) => serializePrimitiveParam({
258
+ allowReserved,
259
+ name: style === "deepObject" ? `${name}[${key}]` : key,
260
+ value: v
261
+ })
262
+ ).join(separator);
263
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
264
+ };
265
+
266
+ // src/generated/core/utils.gen.ts
267
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
268
+ var defaultPathSerializer = ({ path, url: _url }) => {
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 === void 0 || value === null) {
289
+ continue;
290
+ }
291
+ if (Array.isArray(value)) {
292
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
293
+ continue;
294
+ }
295
+ if (typeof value === "object") {
296
+ url = url.replace(
297
+ match,
298
+ serializeObjectParam({
299
+ explode,
300
+ name,
301
+ style,
302
+ value,
303
+ valueOnly: true
304
+ })
305
+ );
306
+ continue;
307
+ }
308
+ if (style === "matrix") {
309
+ url = url.replace(
310
+ match,
311
+ `;${serializePrimitiveParam({
312
+ name,
313
+ value
314
+ })}`
315
+ );
316
+ continue;
317
+ }
318
+ const replaceValue = encodeURIComponent(
319
+ style === "label" ? `.${value}` : value
320
+ );
321
+ url = url.replace(match, replaceValue);
322
+ }
323
+ }
324
+ return url;
325
+ };
326
+ var getUrl = ({
327
+ baseUrl,
328
+ path,
329
+ query,
330
+ querySerializer,
331
+ url: _url
332
+ }) => {
333
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
334
+ let url = (baseUrl ?? "") + pathUrl;
335
+ if (path) {
336
+ url = defaultPathSerializer({ path, url });
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 !== void 0;
349
+ const isSerializedBody = hasBody && options.bodySerializer;
350
+ if (isSerializedBody) {
351
+ if ("serializedBody" in options) {
352
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
353
+ return hasSerializedBody ? options.serializedBody : null;
354
+ }
355
+ return options.body !== "" ? options.body : null;
356
+ }
357
+ if (hasBody) {
358
+ return options.body;
359
+ }
360
+ return void 0;
361
+ }
362
+
363
+ // src/generated/core/auth.gen.ts
364
+ var getAuthToken = async (auth, callback) => {
365
+ const token = typeof callback === "function" ? await callback(auth) : callback;
366
+ if (!token) {
367
+ return;
368
+ }
369
+ if (auth.scheme === "bearer") {
370
+ return `Bearer ${token}`;
371
+ }
372
+ if (auth.scheme === "basic") {
373
+ return `Basic ${btoa(token)}`;
374
+ }
375
+ return token;
376
+ };
377
+
378
+ // src/generated/client/utils.gen.ts
379
+ var createQuerySerializer = ({
380
+ parameters = {},
381
+ ...args
382
+ } = {}) => {
383
+ const querySerializer = (queryParams) => {
384
+ const search = [];
385
+ if (queryParams && typeof queryParams === "object") {
386
+ for (const name in queryParams) {
387
+ const value = queryParams[name];
388
+ if (value === void 0 || value === null) {
389
+ continue;
390
+ }
391
+ const options = parameters[name] || args;
392
+ if (Array.isArray(value)) {
393
+ const serializedArray = serializeArrayParam({
394
+ allowReserved: options.allowReserved,
395
+ explode: true,
396
+ name,
397
+ style: "form",
398
+ value,
399
+ ...options.array
400
+ });
401
+ if (serializedArray) search.push(serializedArray);
402
+ } else if (typeof value === "object") {
403
+ const serializedObject = serializeObjectParam({
404
+ allowReserved: options.allowReserved,
405
+ explode: true,
406
+ name,
407
+ style: "deepObject",
408
+ value,
409
+ ...options.object
410
+ });
411
+ if (serializedObject) search.push(serializedObject);
412
+ } else {
413
+ const serializedPrimitive = serializePrimitiveParam({
414
+ allowReserved: options.allowReserved,
415
+ name,
416
+ value
417
+ });
418
+ if (serializedPrimitive) search.push(serializedPrimitive);
419
+ }
420
+ }
421
+ }
422
+ return search.join("&");
423
+ };
424
+ return querySerializer;
425
+ };
426
+ var getParseAs = (contentType) => {
427
+ if (!contentType) {
428
+ return "stream";
429
+ }
430
+ const cleanContent = contentType.split(";")[0]?.trim();
431
+ if (!cleanContent) {
432
+ return;
433
+ }
434
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
435
+ return "json";
436
+ }
437
+ if (cleanContent === "multipart/form-data") {
438
+ return "formData";
439
+ }
440
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
441
+ return "blob";
442
+ }
443
+ if (cleanContent.startsWith("text/")) {
444
+ return "text";
445
+ }
446
+ return;
447
+ };
448
+ var checkForExistence = (options, name) => {
449
+ if (!name) {
450
+ return false;
451
+ }
452
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
453
+ return true;
454
+ }
455
+ return false;
456
+ };
457
+ var setAuthParams = async ({
458
+ security,
459
+ ...options
460
+ }) => {
461
+ for (const auth of security) {
462
+ if (checkForExistence(options, auth.name)) {
463
+ continue;
464
+ }
465
+ const token = await getAuthToken(auth, options.auth);
466
+ if (!token) {
467
+ continue;
468
+ }
469
+ const name = auth.name ?? "Authorization";
470
+ switch (auth.in) {
471
+ case "query":
472
+ if (!options.query) {
473
+ options.query = {};
474
+ }
475
+ options.query[name] = token;
476
+ break;
477
+ case "cookie":
478
+ options.headers.append("Cookie", `${name}=${token}`);
479
+ break;
480
+ case "header":
481
+ default:
482
+ options.headers.set(name, token);
483
+ break;
484
+ }
485
+ }
486
+ };
487
+ var buildUrl = (options) => getUrl({
488
+ baseUrl: options.baseUrl,
489
+ path: options.path,
490
+ query: options.query,
491
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
492
+ url: options.url
493
+ });
494
+ var mergeConfigs = (a, b) => {
495
+ const config = { ...a, ...b };
496
+ if (config.baseUrl?.endsWith("/")) {
497
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
498
+ }
499
+ config.headers = mergeHeaders(a.headers, b.headers);
500
+ return config;
501
+ };
502
+ var headersEntries = (headers) => {
503
+ const entries = [];
504
+ headers.forEach((value, key) => {
505
+ entries.push([key, value]);
506
+ });
507
+ return entries;
508
+ };
509
+ var mergeHeaders = (...headers) => {
510
+ const mergedHeaders = new Headers();
511
+ for (const header of headers) {
512
+ if (!header) {
513
+ continue;
514
+ }
515
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
516
+ for (const [key, value] of iterator) {
517
+ if (value === null) {
518
+ mergedHeaders.delete(key);
519
+ } else if (Array.isArray(value)) {
520
+ for (const v of value) {
521
+ mergedHeaders.append(key, v);
522
+ }
523
+ } else if (value !== void 0) {
524
+ mergedHeaders.set(
525
+ key,
526
+ typeof value === "object" ? JSON.stringify(value) : value
527
+ );
528
+ }
529
+ }
530
+ }
531
+ return mergedHeaders;
532
+ };
533
+ var Interceptors = class {
534
+ fns = [];
535
+ clear() {
536
+ this.fns = [];
537
+ }
538
+ eject(id) {
539
+ const index = this.getInterceptorIndex(id);
540
+ if (this.fns[index]) {
541
+ this.fns[index] = null;
542
+ }
543
+ }
544
+ exists(id) {
545
+ const index = this.getInterceptorIndex(id);
546
+ return Boolean(this.fns[index]);
547
+ }
548
+ getInterceptorIndex(id) {
549
+ if (typeof id === "number") {
550
+ return this.fns[id] ? id : -1;
551
+ }
552
+ return this.fns.indexOf(id);
553
+ }
554
+ update(id, fn) {
555
+ const index = this.getInterceptorIndex(id);
556
+ if (this.fns[index]) {
557
+ this.fns[index] = fn;
558
+ return id;
559
+ }
560
+ return false;
561
+ }
562
+ use(fn) {
563
+ this.fns.push(fn);
564
+ return this.fns.length - 1;
565
+ }
566
+ };
567
+ var createInterceptors = () => ({
568
+ error: new Interceptors(),
569
+ request: new Interceptors(),
570
+ response: new Interceptors()
571
+ });
572
+ var defaultQuerySerializer = createQuerySerializer({
573
+ allowReserved: false,
574
+ array: {
575
+ explode: true,
576
+ style: "form"
577
+ },
578
+ object: {
579
+ explode: true,
580
+ style: "deepObject"
581
+ }
582
+ });
583
+ var defaultHeaders = {
584
+ "Content-Type": "application/json"
585
+ };
586
+ var createConfig = (override = {}) => ({
587
+ ...jsonBodySerializer,
588
+ headers: defaultHeaders,
589
+ parseAs: "auto",
590
+ querySerializer: defaultQuerySerializer,
591
+ ...override
592
+ });
593
+
594
+ // src/generated/client/client.gen.ts
595
+ var createClient = (config = {}) => {
596
+ let _config = mergeConfigs(createConfig(), config);
597
+ const getConfig = () => ({ ..._config });
598
+ const setConfig = (config2) => {
599
+ _config = mergeConfigs(_config, config2);
600
+ return getConfig();
601
+ };
602
+ const interceptors = createInterceptors();
603
+ const beforeRequest = async (options) => {
604
+ const opts = {
605
+ ..._config,
606
+ ...options,
607
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
608
+ headers: mergeHeaders(_config.headers, options.headers),
609
+ serializedBody: void 0
610
+ };
611
+ if (opts.security) {
612
+ await setAuthParams({
613
+ ...opts,
614
+ security: opts.security
615
+ });
616
+ }
617
+ if (opts.requestValidator) {
618
+ await opts.requestValidator(opts);
619
+ }
620
+ if (opts.body !== void 0 && opts.bodySerializer) {
621
+ opts.serializedBody = opts.bodySerializer(opts.body);
622
+ }
623
+ if (opts.body === void 0 || opts.serializedBody === "") {
624
+ opts.headers.delete("Content-Type");
625
+ }
626
+ const url = buildUrl(opts);
627
+ return { opts, url };
628
+ };
629
+ const request = async (options) => {
630
+ const { opts, url } = await beforeRequest(options);
631
+ const requestInit = {
632
+ redirect: "follow",
633
+ ...opts,
634
+ body: getValidRequestBody(opts)
635
+ };
636
+ let request2 = new Request(url, requestInit);
637
+ for (const fn of interceptors.request.fns) {
638
+ if (fn) {
639
+ request2 = await fn(request2, opts);
640
+ }
641
+ }
642
+ const _fetch = opts.fetch;
643
+ let response;
644
+ try {
645
+ response = await _fetch(request2);
646
+ } catch (error2) {
647
+ let finalError2 = error2;
648
+ for (const fn of interceptors.error.fns) {
649
+ if (fn) {
650
+ finalError2 = await fn(error2, void 0, request2, opts);
651
+ }
652
+ }
653
+ finalError2 = finalError2 || {};
654
+ if (opts.throwOnError) {
655
+ throw finalError2;
656
+ }
657
+ return opts.responseStyle === "data" ? void 0 : {
658
+ error: finalError2,
659
+ request: request2,
660
+ response: void 0
661
+ };
662
+ }
663
+ for (const fn of interceptors.response.fns) {
664
+ if (fn) {
665
+ response = await fn(response, request2, opts);
666
+ }
667
+ }
668
+ const result = {
669
+ request: request2,
670
+ response
671
+ };
672
+ if (response.ok) {
673
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
674
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
675
+ let emptyData;
676
+ switch (parseAs) {
677
+ case "arrayBuffer":
678
+ case "blob":
679
+ case "text":
680
+ emptyData = await response[parseAs]();
681
+ break;
682
+ case "formData":
683
+ emptyData = new FormData();
684
+ break;
685
+ case "stream":
686
+ emptyData = response.body;
687
+ break;
688
+ case "json":
689
+ default:
690
+ emptyData = {};
691
+ break;
692
+ }
693
+ return opts.responseStyle === "data" ? emptyData : {
694
+ data: emptyData,
695
+ ...result
696
+ };
697
+ }
698
+ let data;
699
+ switch (parseAs) {
700
+ case "arrayBuffer":
701
+ case "blob":
702
+ case "formData":
703
+ case "text":
704
+ data = await response[parseAs]();
705
+ break;
706
+ case "json": {
707
+ const text = await response.text();
708
+ data = text ? JSON.parse(text) : {};
709
+ break;
710
+ }
711
+ case "stream":
712
+ return opts.responseStyle === "data" ? response.body : {
713
+ data: response.body,
714
+ ...result
715
+ };
716
+ }
717
+ if (parseAs === "json") {
718
+ if (opts.responseValidator) {
719
+ await opts.responseValidator(data);
720
+ }
721
+ if (opts.responseTransformer) {
722
+ data = await opts.responseTransformer(data);
723
+ }
724
+ }
725
+ return opts.responseStyle === "data" ? data : {
726
+ data,
727
+ ...result
728
+ };
729
+ }
730
+ const textError = await response.text();
731
+ let jsonError;
732
+ try {
733
+ jsonError = JSON.parse(textError);
734
+ } catch {
735
+ }
736
+ const error = jsonError ?? textError;
737
+ let finalError = error;
738
+ for (const fn of interceptors.error.fns) {
739
+ if (fn) {
740
+ finalError = await fn(error, response, request2, opts);
741
+ }
742
+ }
743
+ finalError = finalError || {};
744
+ if (opts.throwOnError) {
745
+ throw finalError;
746
+ }
747
+ return opts.responseStyle === "data" ? void 0 : {
748
+ error: finalError,
749
+ ...result
750
+ };
751
+ };
752
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
753
+ const makeSseFn = (method) => async (options) => {
754
+ const { opts, url } = await beforeRequest(options);
755
+ return createSseClient({
756
+ ...opts,
757
+ body: opts.body,
758
+ headers: opts.headers,
759
+ method,
760
+ onRequest: async (url2, init) => {
761
+ let request2 = new Request(url2, init);
762
+ for (const fn of interceptors.request.fns) {
763
+ if (fn) {
764
+ request2 = await fn(request2, opts);
765
+ }
766
+ }
767
+ return request2;
768
+ },
769
+ serializedBody: getValidRequestBody(opts),
770
+ url
771
+ });
772
+ };
773
+ return {
774
+ buildUrl,
775
+ connect: makeMethodFn("CONNECT"),
776
+ delete: makeMethodFn("DELETE"),
777
+ get: makeMethodFn("GET"),
778
+ getConfig,
779
+ head: makeMethodFn("HEAD"),
780
+ interceptors,
781
+ options: makeMethodFn("OPTIONS"),
782
+ patch: makeMethodFn("PATCH"),
783
+ post: makeMethodFn("POST"),
784
+ put: makeMethodFn("PUT"),
785
+ request,
786
+ setConfig,
787
+ sse: {
788
+ connect: makeSseFn("CONNECT"),
789
+ delete: makeSseFn("DELETE"),
790
+ get: makeSseFn("GET"),
791
+ head: makeSseFn("HEAD"),
792
+ options: makeSseFn("OPTIONS"),
793
+ patch: makeSseFn("PATCH"),
794
+ post: makeSseFn("POST"),
795
+ put: makeSseFn("PUT"),
796
+ trace: makeSseFn("TRACE")
797
+ },
798
+ trace: makeMethodFn("TRACE")
799
+ };
800
+ };
801
+
802
+ // src/generated/client.gen.ts
803
+ var client = createClient(createConfig({ baseUrl: "https://platform.praxium.nl" }));
804
+
805
+ // src/generated/sdk.gen.ts
806
+ var getOpeningHours = (options) => (options.client ?? client).get({
807
+ security: [{ scheme: "bearer", type: "http" }],
808
+ url: "/api/public/{tenantSlug}/opening-hours",
809
+ ...options
810
+ });
811
+ var getContactDetails = (options) => (options.client ?? client).get({
812
+ security: [{ scheme: "bearer", type: "http" }],
813
+ url: "/api/public/{tenantSlug}/contact",
814
+ ...options
815
+ });
816
+ var submitContactForm = (options) => (options.client ?? client).post({
817
+ security: [{ scheme: "bearer", type: "http" }],
818
+ url: "/api/public/{tenantSlug}/contact",
819
+ ...options,
820
+ headers: {
821
+ "Content-Type": "application/json",
822
+ ...options.headers
823
+ }
824
+ });
825
+ var getLocation = (options) => (options.client ?? client).get({
826
+ security: [{ scheme: "bearer", type: "http" }],
827
+ url: "/api/public/{tenantSlug}/location",
828
+ ...options
829
+ });
830
+ var getBusinessName = (options) => (options.client ?? client).get({
831
+ security: [{ scheme: "bearer", type: "http" }],
832
+ url: "/api/public/{tenantSlug}/business",
833
+ ...options
834
+ });
835
+ var getSocialLinks = (options) => (options.client ?? client).get({
836
+ security: [{ scheme: "bearer", type: "http" }],
837
+ url: "/api/public/{tenantSlug}/social-links",
838
+ ...options
839
+ });
840
+ var getTeamMembers = (options) => (options.client ?? client).get({
841
+ security: [{ scheme: "bearer", type: "http" }],
842
+ url: "/api/public/{tenantSlug}/team",
843
+ ...options
844
+ });
845
+ var getFaq = (options) => (options.client ?? client).get({
846
+ security: [{ scheme: "bearer", type: "http" }],
847
+ url: "/api/public/{tenantSlug}/faq",
848
+ ...options
849
+ });
850
+ var getServiceVariants = (options) => (options.client ?? client).get({
851
+ security: [{ scheme: "bearer", type: "http" }],
852
+ url: "/api/public/{tenantSlug}/service-variants",
853
+ ...options
854
+ });
855
+ var getInsuranceInfo = (options) => (options.client ?? client).get({
856
+ security: [{ scheme: "bearer", type: "http" }],
857
+ url: "/api/public/{tenantSlug}/insurance",
858
+ ...options
859
+ });
860
+ var getFeatures = (options) => (options.client ?? client).get({
861
+ security: [{ scheme: "bearer", type: "http" }],
862
+ url: "/api/public/{tenantSlug}/features",
863
+ ...options
864
+ });
865
+ var getPaymentMethods = (options) => (options.client ?? client).get({
866
+ security: [{ scheme: "bearer", type: "http" }],
867
+ url: "/api/public/{tenantSlug}/payments",
868
+ ...options
869
+ });
870
+ var getPolicyInfo = (options) => (options.client ?? client).get({
871
+ security: [{ scheme: "bearer", type: "http" }],
872
+ url: "/api/public/{tenantSlug}/policy",
873
+ ...options
874
+ });
875
+ var getBookableServices = (options) => (options.client ?? client).get({
876
+ security: [{ scheme: "bearer", type: "http" }],
877
+ url: "/api/public/{tenantSlug}/services",
878
+ ...options
879
+ });
880
+
881
+ // src/errors.ts
882
+ var PraxiumError = class extends Error {
883
+ constructor(status, errorCode, message, details) {
884
+ super(message);
885
+ this.status = status;
886
+ this.errorCode = errorCode;
887
+ this.details = details;
888
+ this.name = "PraxiumError";
889
+ Object.setPrototypeOf(this, new.target.prototype);
890
+ }
891
+ name;
892
+ };
893
+ var PraxiumValidationError = class extends PraxiumError {
894
+ constructor(errorCode, message, details) {
895
+ super(400, errorCode, message, details);
896
+ this.name = "PraxiumValidationError";
897
+ }
898
+ };
899
+ var PraxiumAuthError = class extends PraxiumError {
900
+ constructor(errorCode, message) {
901
+ super(401, errorCode, message);
902
+ this.name = "PraxiumAuthError";
903
+ }
904
+ };
905
+ var PraxiumForbiddenError = class extends PraxiumError {
906
+ constructor(errorCode, message) {
907
+ super(403, errorCode, message);
908
+ this.name = "PraxiumForbiddenError";
909
+ }
910
+ };
911
+ var PraxiumNotFoundError = class extends PraxiumError {
912
+ constructor(errorCode, message) {
913
+ super(404, errorCode, message);
914
+ this.name = "PraxiumNotFoundError";
915
+ }
916
+ };
917
+ var PraxiumRateLimitError = class extends PraxiumError {
918
+ constructor(errorCode, message) {
919
+ super(429, errorCode, message);
920
+ this.name = "PraxiumRateLimitError";
921
+ }
922
+ };
923
+ var STATUS_ERROR_MAP = {
924
+ 400: PraxiumValidationError,
925
+ 401: PraxiumAuthError,
926
+ 403: PraxiumForbiddenError,
927
+ 404: PraxiumNotFoundError,
928
+ 429: PraxiumRateLimitError
929
+ };
930
+
931
+ // src/tenant-client.ts
932
+ function unwrapOrThrow(result) {
933
+ if (result.data !== void 0 && result.error === void 0) {
934
+ return result.data.data;
935
+ }
936
+ const status = result.response?.status ?? 500;
937
+ const apiError = result.error;
938
+ const errorCode = apiError?.errorCode ?? "UNKNOWN_ERROR";
939
+ const message = apiError?.message ?? `HTTP ${status} error`;
940
+ const details = apiError?.details;
941
+ const ErrorClass = STATUS_ERROR_MAP[status];
942
+ if (ErrorClass) {
943
+ throw new ErrorClass(errorCode, message, details);
944
+ }
945
+ throw new PraxiumError(status, errorCode, message, details);
946
+ }
947
+ function createTenantClient(config) {
948
+ const clientInstance = createClient(
949
+ createConfig({
950
+ baseUrl: config.baseUrl,
951
+ auth: config.apiKey
952
+ })
953
+ );
954
+ clientInstance.interceptors.request.use((request) => {
955
+ request.headers.set("Accept-Language", config.locale);
956
+ return request;
957
+ });
958
+ const path = { tenantSlug: config.tenantSlug };
959
+ return {
960
+ // ─── Layout Endpoints ───
961
+ getOpeningHours: () => getOpeningHours({ client: clientInstance, path }).then(unwrapOrThrow),
962
+ getContactDetails: () => getContactDetails({ client: clientInstance, path }).then(unwrapOrThrow),
963
+ getLocation: () => getLocation({ client: clientInstance, path }).then(unwrapOrThrow),
964
+ getBusinessName: () => getBusinessName({ client: clientInstance, path }).then(unwrapOrThrow),
965
+ getSocialLinks: () => getSocialLinks({ client: clientInstance, path }).then(unwrapOrThrow),
966
+ // ─── Content Endpoints ───
967
+ getTeamMembers: () => getTeamMembers({ client: clientInstance, path }).then(unwrapOrThrow),
968
+ getFaq: () => getFaq({ client: clientInstance, path }).then(unwrapOrThrow),
969
+ getServiceVariants: () => getServiceVariants({ client: clientInstance, path }).then(unwrapOrThrow),
970
+ getInsuranceInfo: () => getInsuranceInfo({ client: clientInstance, path }).then(unwrapOrThrow),
971
+ getFeatures: () => getFeatures({ client: clientInstance, path }).then(unwrapOrThrow),
972
+ getPaymentMethods: () => getPaymentMethods({ client: clientInstance, path }).then(unwrapOrThrow),
973
+ getPolicyInfo: () => getPolicyInfo({ client: clientInstance, path }).then(unwrapOrThrow),
974
+ getBookableServices: () => getBookableServices({ client: clientInstance, path }).then(unwrapOrThrow),
975
+ // ─── Contact Form ───
976
+ submitContactForm: (body) => submitContactForm({ client: clientInstance, path, body }).then(unwrapOrThrow)
977
+ };
978
+ }
979
+ export {
980
+ PraxiumAuthError,
981
+ PraxiumError,
982
+ PraxiumForbiddenError,
983
+ PraxiumNotFoundError,
984
+ PraxiumRateLimitError,
985
+ PraxiumValidationError,
986
+ createTenantClient
987
+ };