@mentio-dev/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1190 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/generated/core/bodySerializer.gen.ts
8
+ var jsonBodySerializer = {
9
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
10
+ };
11
+
12
+ // src/generated/core/params.gen.ts
13
+ var extraPrefixesMap = {
14
+ $body_: "body",
15
+ $headers_: "headers",
16
+ $path_: "path",
17
+ $query_: "query"
18
+ };
19
+ var extraPrefixes = Object.entries(extraPrefixesMap);
20
+
21
+ // src/generated/core/serverSentEvents.gen.ts
22
+ function createSseClient({
23
+ onRequest,
24
+ onSseError,
25
+ onSseEvent,
26
+ responseTransformer,
27
+ responseValidator,
28
+ sseDefaultRetryDelay,
29
+ sseMaxRetryAttempts,
30
+ sseMaxRetryDelay,
31
+ sseSleepFn,
32
+ url,
33
+ ...options
34
+ }) {
35
+ let lastEventId;
36
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
37
+ const createStream = async function* () {
38
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
39
+ let attempt = 0;
40
+ const signal = options.signal ?? new AbortController().signal;
41
+ while (true) {
42
+ if (signal.aborted) break;
43
+ attempt++;
44
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
45
+ if (lastEventId !== void 0) {
46
+ headers.set("Last-Event-ID", lastEventId);
47
+ }
48
+ try {
49
+ const requestInit = {
50
+ redirect: "follow",
51
+ ...options,
52
+ body: options.serializedBody,
53
+ headers,
54
+ signal
55
+ };
56
+ let request = new Request(url, requestInit);
57
+ if (onRequest) {
58
+ request = await onRequest(url, requestInit);
59
+ }
60
+ const _fetch = options.fetch ?? globalThis.fetch;
61
+ const response = await _fetch(request);
62
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
63
+ if (!response.body) throw new Error("No body in SSE response");
64
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
65
+ let buffer = "";
66
+ const abortHandler = () => {
67
+ try {
68
+ reader.cancel();
69
+ } catch {
70
+ }
71
+ };
72
+ signal.addEventListener("abort", abortHandler);
73
+ try {
74
+ while (true) {
75
+ const { done, value } = await reader.read();
76
+ if (done) break;
77
+ buffer += value;
78
+ buffer = buffer.replace(/\r\n?/g, "\n");
79
+ const chunks = buffer.split("\n\n");
80
+ buffer = chunks.pop() ?? "";
81
+ for (const chunk of chunks) {
82
+ const lines = chunk.split("\n");
83
+ const dataLines = [];
84
+ let eventName;
85
+ for (const line of lines) {
86
+ if (line.startsWith("data:")) {
87
+ dataLines.push(line.replace(/^data:\s*/, ""));
88
+ } else if (line.startsWith("event:")) {
89
+ eventName = line.replace(/^event:\s*/, "");
90
+ } else if (line.startsWith("id:")) {
91
+ lastEventId = line.replace(/^id:\s*/, "");
92
+ } else if (line.startsWith("retry:")) {
93
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
94
+ if (!Number.isNaN(parsed)) {
95
+ retryDelay = parsed;
96
+ }
97
+ }
98
+ }
99
+ let data;
100
+ let parsedJson = false;
101
+ if (dataLines.length) {
102
+ const rawData = dataLines.join("\n");
103
+ try {
104
+ data = JSON.parse(rawData);
105
+ parsedJson = true;
106
+ } catch {
107
+ data = rawData;
108
+ }
109
+ }
110
+ if (parsedJson) {
111
+ if (responseValidator) {
112
+ await responseValidator(data);
113
+ }
114
+ if (responseTransformer) {
115
+ data = await responseTransformer(data);
116
+ }
117
+ }
118
+ onSseEvent?.({
119
+ data,
120
+ event: eventName,
121
+ id: lastEventId,
122
+ retry: retryDelay
123
+ });
124
+ if (dataLines.length) {
125
+ yield data;
126
+ }
127
+ }
128
+ }
129
+ } finally {
130
+ signal.removeEventListener("abort", abortHandler);
131
+ reader.releaseLock();
132
+ }
133
+ break;
134
+ } catch (error) {
135
+ onSseError?.(error);
136
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
137
+ break;
138
+ }
139
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
140
+ await sleep(backoff);
141
+ }
142
+ }
143
+ };
144
+ const stream = createStream();
145
+ return { stream };
146
+ }
147
+
148
+ // src/generated/core/pathSerializer.gen.ts
149
+ var separatorArrayExplode = (style) => {
150
+ switch (style) {
151
+ case "label":
152
+ return ".";
153
+ case "matrix":
154
+ return ";";
155
+ case "simple":
156
+ return ",";
157
+ default:
158
+ return "&";
159
+ }
160
+ };
161
+ var separatorArrayNoExplode = (style) => {
162
+ switch (style) {
163
+ case "form":
164
+ return ",";
165
+ case "pipeDelimited":
166
+ return "|";
167
+ case "spaceDelimited":
168
+ return "%20";
169
+ default:
170
+ return ",";
171
+ }
172
+ };
173
+ var separatorObjectExplode = (style) => {
174
+ switch (style) {
175
+ case "label":
176
+ return ".";
177
+ case "matrix":
178
+ return ";";
179
+ case "simple":
180
+ return ",";
181
+ default:
182
+ return "&";
183
+ }
184
+ };
185
+ var serializeArrayParam = ({
186
+ allowReserved,
187
+ explode,
188
+ name,
189
+ style,
190
+ value
191
+ }) => {
192
+ if (!explode) {
193
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
194
+ switch (style) {
195
+ case "label":
196
+ return `.${joinedValues2}`;
197
+ case "matrix":
198
+ return `;${name}=${joinedValues2}`;
199
+ case "simple":
200
+ return joinedValues2;
201
+ default:
202
+ return `${name}=${joinedValues2}`;
203
+ }
204
+ }
205
+ const separator = separatorArrayExplode(style);
206
+ const joinedValues = value.map((v) => {
207
+ if (style === "label" || style === "simple") {
208
+ return allowReserved ? v : encodeURIComponent(v);
209
+ }
210
+ return serializePrimitiveParam({
211
+ allowReserved,
212
+ name,
213
+ value: v
214
+ });
215
+ }).join(separator);
216
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
217
+ };
218
+ var serializePrimitiveParam = ({
219
+ allowReserved,
220
+ name,
221
+ value
222
+ }) => {
223
+ if (value === void 0 || value === null) {
224
+ return "";
225
+ }
226
+ if (typeof value === "object") {
227
+ throw new Error(
228
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
229
+ );
230
+ }
231
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
232
+ };
233
+ var serializeObjectParam = ({
234
+ allowReserved,
235
+ explode,
236
+ name,
237
+ style,
238
+ value,
239
+ valueOnly
240
+ }) => {
241
+ if (value instanceof Date) {
242
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
243
+ }
244
+ if (style !== "deepObject" && !explode) {
245
+ let values = [];
246
+ Object.entries(value).forEach(([key, v]) => {
247
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
248
+ });
249
+ const joinedValues2 = values.join(",");
250
+ switch (style) {
251
+ case "form":
252
+ return `${name}=${joinedValues2}`;
253
+ case "label":
254
+ return `.${joinedValues2}`;
255
+ case "matrix":
256
+ return `;${name}=${joinedValues2}`;
257
+ default:
258
+ return joinedValues2;
259
+ }
260
+ }
261
+ const separator = separatorObjectExplode(style);
262
+ const joinedValues = Object.entries(value).map(
263
+ ([key, v]) => serializePrimitiveParam({
264
+ allowReserved,
265
+ name: style === "deepObject" ? `${name}[${key}]` : key,
266
+ value: v
267
+ })
268
+ ).join(separator);
269
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
270
+ };
271
+
272
+ // src/generated/core/utils.gen.ts
273
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
274
+ var defaultPathSerializer = ({ path, url: _url }) => {
275
+ let url = _url;
276
+ const matches = _url.match(PATH_PARAM_RE);
277
+ if (matches) {
278
+ for (const match of matches) {
279
+ let explode = false;
280
+ let name = match.substring(1, match.length - 1);
281
+ let style = "simple";
282
+ if (name.endsWith("*")) {
283
+ explode = true;
284
+ name = name.substring(0, name.length - 1);
285
+ }
286
+ if (name.startsWith(".")) {
287
+ name = name.substring(1);
288
+ style = "label";
289
+ } else if (name.startsWith(";")) {
290
+ name = name.substring(1);
291
+ style = "matrix";
292
+ }
293
+ const value = path[name];
294
+ if (value === void 0 || value === null) {
295
+ continue;
296
+ }
297
+ if (Array.isArray(value)) {
298
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
299
+ continue;
300
+ }
301
+ if (typeof value === "object") {
302
+ url = url.replace(
303
+ match,
304
+ serializeObjectParam({
305
+ explode,
306
+ name,
307
+ style,
308
+ value,
309
+ valueOnly: true
310
+ })
311
+ );
312
+ continue;
313
+ }
314
+ if (style === "matrix") {
315
+ url = url.replace(
316
+ match,
317
+ `;${serializePrimitiveParam({
318
+ name,
319
+ value
320
+ })}`
321
+ );
322
+ continue;
323
+ }
324
+ const replaceValue = encodeURIComponent(
325
+ style === "label" ? `.${value}` : value
326
+ );
327
+ url = url.replace(match, replaceValue);
328
+ }
329
+ }
330
+ return url;
331
+ };
332
+ var getUrl = ({
333
+ baseUrl,
334
+ path,
335
+ query,
336
+ querySerializer,
337
+ url: _url
338
+ }) => {
339
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
340
+ let url = (baseUrl ?? "") + pathUrl;
341
+ if (path) {
342
+ url = defaultPathSerializer({ path, url });
343
+ }
344
+ let search = query ? querySerializer(query) : "";
345
+ if (search.startsWith("?")) {
346
+ search = search.substring(1);
347
+ }
348
+ if (search) {
349
+ url += `?${search}`;
350
+ }
351
+ return url;
352
+ };
353
+ function getValidRequestBody(options) {
354
+ const hasBody = options.body !== void 0;
355
+ const isSerializedBody = hasBody && options.bodySerializer;
356
+ if (isSerializedBody) {
357
+ if ("serializedBody" in options) {
358
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
359
+ return hasSerializedBody ? options.serializedBody : null;
360
+ }
361
+ return options.body !== "" ? options.body : null;
362
+ }
363
+ if (hasBody) {
364
+ return options.body;
365
+ }
366
+ return void 0;
367
+ }
368
+
369
+ // src/generated/core/auth.gen.ts
370
+ var getAuthToken = async (auth, callback) => {
371
+ const token = typeof callback === "function" ? await callback(auth) : callback;
372
+ if (!token) {
373
+ return;
374
+ }
375
+ if (auth.scheme === "bearer") {
376
+ return `Bearer ${token}`;
377
+ }
378
+ if (auth.scheme === "basic") {
379
+ return `Basic ${btoa(token)}`;
380
+ }
381
+ return token;
382
+ };
383
+
384
+ // src/generated/client/utils.gen.ts
385
+ var createQuerySerializer = ({
386
+ parameters = {},
387
+ ...args
388
+ } = {}) => {
389
+ const querySerializer = (queryParams) => {
390
+ const search = [];
391
+ if (queryParams && typeof queryParams === "object") {
392
+ for (const name in queryParams) {
393
+ const value = queryParams[name];
394
+ if (value === void 0 || value === null) {
395
+ continue;
396
+ }
397
+ const options = parameters[name] || args;
398
+ if (Array.isArray(value)) {
399
+ const serializedArray = serializeArrayParam({
400
+ allowReserved: options.allowReserved,
401
+ explode: true,
402
+ name,
403
+ style: "form",
404
+ value,
405
+ ...options.array
406
+ });
407
+ if (serializedArray) search.push(serializedArray);
408
+ } else if (typeof value === "object") {
409
+ const serializedObject = serializeObjectParam({
410
+ allowReserved: options.allowReserved,
411
+ explode: true,
412
+ name,
413
+ style: "deepObject",
414
+ value,
415
+ ...options.object
416
+ });
417
+ if (serializedObject) search.push(serializedObject);
418
+ } else {
419
+ const serializedPrimitive = serializePrimitiveParam({
420
+ allowReserved: options.allowReserved,
421
+ name,
422
+ value
423
+ });
424
+ if (serializedPrimitive) search.push(serializedPrimitive);
425
+ }
426
+ }
427
+ }
428
+ return search.join("&");
429
+ };
430
+ return querySerializer;
431
+ };
432
+ var getParseAs = (contentType) => {
433
+ if (!contentType) {
434
+ return "stream";
435
+ }
436
+ const cleanContent = contentType.split(";")[0]?.trim();
437
+ if (!cleanContent) {
438
+ return;
439
+ }
440
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
441
+ return "json";
442
+ }
443
+ if (cleanContent === "multipart/form-data") {
444
+ return "formData";
445
+ }
446
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
447
+ return "blob";
448
+ }
449
+ if (cleanContent.startsWith("text/")) {
450
+ return "text";
451
+ }
452
+ return;
453
+ };
454
+ var checkForExistence = (options, name) => {
455
+ if (!name) {
456
+ return false;
457
+ }
458
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
459
+ return true;
460
+ }
461
+ return false;
462
+ };
463
+ async function setAuthParams(options) {
464
+ for (const auth of options.security ?? []) {
465
+ if (checkForExistence(options, auth.name)) {
466
+ continue;
467
+ }
468
+ const token = await getAuthToken(auth, options.auth);
469
+ if (!token) {
470
+ continue;
471
+ }
472
+ const name = auth.name ?? "Authorization";
473
+ switch (auth.in) {
474
+ case "query":
475
+ if (!options.query) {
476
+ options.query = {};
477
+ }
478
+ options.query[name] = token;
479
+ break;
480
+ case "cookie":
481
+ options.headers.append("Cookie", `${name}=${token}`);
482
+ break;
483
+ case "header":
484
+ default:
485
+ options.headers.set(name, token);
486
+ break;
487
+ }
488
+ }
489
+ }
490
+ var buildUrl = (options) => getUrl({
491
+ baseUrl: options.baseUrl,
492
+ path: options.path,
493
+ query: options.query,
494
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
495
+ url: options.url
496
+ });
497
+ var mergeConfigs = (a, b) => {
498
+ const config = { ...a, ...b };
499
+ if (config.baseUrl?.endsWith("/")) {
500
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
501
+ }
502
+ config.headers = mergeHeaders(a.headers, b.headers);
503
+ return config;
504
+ };
505
+ var headersEntries = (headers) => {
506
+ const entries = [];
507
+ headers.forEach((value, key) => {
508
+ entries.push([key, value]);
509
+ });
510
+ return entries;
511
+ };
512
+ var mergeHeaders = (...headers) => {
513
+ const mergedHeaders = new Headers();
514
+ for (const header of headers) {
515
+ if (!header) {
516
+ continue;
517
+ }
518
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
519
+ for (const [key, value] of iterator) {
520
+ if (value === null) {
521
+ mergedHeaders.delete(key);
522
+ } else if (Array.isArray(value)) {
523
+ for (const v of value) {
524
+ mergedHeaders.append(key, v);
525
+ }
526
+ } else if (value !== void 0) {
527
+ mergedHeaders.set(
528
+ key,
529
+ typeof value === "object" ? JSON.stringify(value) : value
530
+ );
531
+ }
532
+ }
533
+ }
534
+ return mergedHeaders;
535
+ };
536
+ var Interceptors = class {
537
+ fns = [];
538
+ clear() {
539
+ this.fns = [];
540
+ }
541
+ eject(id) {
542
+ const index = this.getInterceptorIndex(id);
543
+ if (this.fns[index]) {
544
+ this.fns[index] = null;
545
+ }
546
+ }
547
+ exists(id) {
548
+ const index = this.getInterceptorIndex(id);
549
+ return Boolean(this.fns[index]);
550
+ }
551
+ getInterceptorIndex(id) {
552
+ if (typeof id === "number") {
553
+ return this.fns[id] ? id : -1;
554
+ }
555
+ return this.fns.indexOf(id);
556
+ }
557
+ update(id, fn) {
558
+ const index = this.getInterceptorIndex(id);
559
+ if (this.fns[index]) {
560
+ this.fns[index] = fn;
561
+ return id;
562
+ }
563
+ return false;
564
+ }
565
+ use(fn) {
566
+ this.fns.push(fn);
567
+ return this.fns.length - 1;
568
+ }
569
+ };
570
+ var createInterceptors = () => ({
571
+ error: new Interceptors(),
572
+ request: new Interceptors(),
573
+ response: new Interceptors()
574
+ });
575
+ var defaultQuerySerializer = createQuerySerializer({
576
+ allowReserved: false,
577
+ array: {
578
+ explode: true,
579
+ style: "form"
580
+ },
581
+ object: {
582
+ explode: true,
583
+ style: "deepObject"
584
+ }
585
+ });
586
+ var defaultHeaders = {
587
+ "Content-Type": "application/json"
588
+ };
589
+ var createConfig = (override = {}) => ({
590
+ ...jsonBodySerializer,
591
+ headers: defaultHeaders,
592
+ parseAs: "auto",
593
+ querySerializer: defaultQuerySerializer,
594
+ ...override
595
+ });
596
+
597
+ // src/generated/client/client.gen.ts
598
+ var createClient = (config = {}) => {
599
+ let _config = mergeConfigs(createConfig(), config);
600
+ const getConfig = () => ({ ..._config });
601
+ const setConfig = (config2) => {
602
+ _config = mergeConfigs(_config, config2);
603
+ return getConfig();
604
+ };
605
+ const interceptors = createInterceptors();
606
+ const beforeRequest = async (options) => {
607
+ const opts = {
608
+ ..._config,
609
+ ...options,
610
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
611
+ headers: mergeHeaders(_config.headers, options.headers),
612
+ serializedBody: void 0
613
+ };
614
+ if (opts.security) {
615
+ await setAuthParams(opts);
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 resolvedOpts = opts;
627
+ const url = buildUrl(resolvedOpts);
628
+ return { opts: resolvedOpts, url };
629
+ };
630
+ const request = async (options) => {
631
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
632
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
633
+ let request2;
634
+ let response;
635
+ try {
636
+ const { opts, url } = await beforeRequest(options);
637
+ const requestInit = {
638
+ redirect: "follow",
639
+ ...opts,
640
+ body: getValidRequestBody(opts)
641
+ };
642
+ request2 = new Request(url, requestInit);
643
+ for (const fn of interceptors.request.fns) {
644
+ if (fn) {
645
+ request2 = await fn(request2, opts);
646
+ }
647
+ }
648
+ const _fetch = opts.fetch;
649
+ response = await _fetch(request2);
650
+ for (const fn of interceptors.response.fns) {
651
+ if (fn) {
652
+ response = await fn(response, request2, opts);
653
+ }
654
+ }
655
+ const result = {
656
+ request: request2,
657
+ response
658
+ };
659
+ if (response.ok) {
660
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
661
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
662
+ let emptyData;
663
+ switch (parseAs) {
664
+ case "arrayBuffer":
665
+ case "blob":
666
+ case "text":
667
+ emptyData = await response[parseAs]();
668
+ break;
669
+ case "formData":
670
+ emptyData = new FormData();
671
+ break;
672
+ case "stream":
673
+ emptyData = response.body;
674
+ break;
675
+ case "json":
676
+ default:
677
+ emptyData = {};
678
+ break;
679
+ }
680
+ return opts.responseStyle === "data" ? emptyData : {
681
+ data: emptyData,
682
+ ...result
683
+ };
684
+ }
685
+ let data;
686
+ switch (parseAs) {
687
+ case "arrayBuffer":
688
+ case "blob":
689
+ case "formData":
690
+ case "text":
691
+ data = await response[parseAs]();
692
+ break;
693
+ case "json": {
694
+ const text = await response.text();
695
+ data = text ? JSON.parse(text) : {};
696
+ break;
697
+ }
698
+ case "stream":
699
+ return opts.responseStyle === "data" ? response.body : {
700
+ data: response.body,
701
+ ...result
702
+ };
703
+ }
704
+ if (parseAs === "json") {
705
+ if (opts.responseValidator) {
706
+ await opts.responseValidator(data);
707
+ }
708
+ if (opts.responseTransformer) {
709
+ data = await opts.responseTransformer(data);
710
+ }
711
+ }
712
+ return opts.responseStyle === "data" ? data : {
713
+ data,
714
+ ...result
715
+ };
716
+ }
717
+ const textError = await response.text();
718
+ let jsonError;
719
+ try {
720
+ jsonError = JSON.parse(textError);
721
+ } catch {
722
+ }
723
+ throw jsonError ?? textError;
724
+ } catch (error) {
725
+ let finalError = error;
726
+ for (const fn of interceptors.error.fns) {
727
+ if (fn) {
728
+ finalError = await fn(finalError, response, request2, options);
729
+ }
730
+ }
731
+ finalError = finalError || {};
732
+ if (throwOnError) {
733
+ throw finalError;
734
+ }
735
+ return responseStyle === "data" ? void 0 : {
736
+ error: finalError,
737
+ request: request2,
738
+ response
739
+ };
740
+ }
741
+ };
742
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
743
+ const makeSseFn = (method) => async (options) => {
744
+ const { opts, url } = await beforeRequest(options);
745
+ return createSseClient({
746
+ ...opts,
747
+ body: opts.body,
748
+ method,
749
+ onRequest: async (url2, init) => {
750
+ let request2 = new Request(url2, init);
751
+ for (const fn of interceptors.request.fns) {
752
+ if (fn) {
753
+ request2 = await fn(request2, opts);
754
+ }
755
+ }
756
+ return request2;
757
+ },
758
+ serializedBody: getValidRequestBody(opts),
759
+ url
760
+ });
761
+ };
762
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
763
+ return {
764
+ buildUrl: _buildUrl,
765
+ connect: makeMethodFn("CONNECT"),
766
+ delete: makeMethodFn("DELETE"),
767
+ get: makeMethodFn("GET"),
768
+ getConfig,
769
+ head: makeMethodFn("HEAD"),
770
+ interceptors,
771
+ options: makeMethodFn("OPTIONS"),
772
+ patch: makeMethodFn("PATCH"),
773
+ post: makeMethodFn("POST"),
774
+ put: makeMethodFn("PUT"),
775
+ request,
776
+ setConfig,
777
+ sse: {
778
+ connect: makeSseFn("CONNECT"),
779
+ delete: makeSseFn("DELETE"),
780
+ get: makeSseFn("GET"),
781
+ head: makeSseFn("HEAD"),
782
+ options: makeSseFn("OPTIONS"),
783
+ patch: makeSseFn("PATCH"),
784
+ post: makeSseFn("POST"),
785
+ put: makeSseFn("PUT"),
786
+ trace: makeSseFn("TRACE")
787
+ },
788
+ trace: makeMethodFn("TRACE")
789
+ };
790
+ };
791
+
792
+ // src/generated/sdk.gen.ts
793
+ var sdk_gen_exports = {};
794
+ __export(sdk_gen_exports, {
795
+ createAlert: () => createAlert,
796
+ createApiKey: () => createApiKey,
797
+ createChannel: () => createChannel,
798
+ createKeyword: () => createKeyword,
799
+ createSegment: () => createSegment,
800
+ deleteAlert: () => deleteAlert,
801
+ deleteChannel: () => deleteChannel,
802
+ deleteKeyword: () => deleteKeyword,
803
+ deleteSegment: () => deleteSegment,
804
+ exportMentionsCsv: () => exportMentionsCsv,
805
+ exportPeopleCsv: () => exportPeopleCsv,
806
+ getAlert: () => getAlert,
807
+ getAnalyticsBreakdown: () => getAnalyticsBreakdown,
808
+ getAnalyticsSeries: () => getAnalyticsSeries,
809
+ getAnalyticsSummary: () => getAnalyticsSummary,
810
+ getChannel: () => getChannel,
811
+ getCompany: () => getCompany,
812
+ getHealth: () => getHealth,
813
+ getKeyword: () => getKeyword,
814
+ getMention: () => getMention,
815
+ getPerson: () => getPerson,
816
+ getSegment: () => getSegment,
817
+ getShareOfVoice: () => getShareOfVoice,
818
+ listAlerts: () => listAlerts,
819
+ listApiKeys: () => listApiKeys,
820
+ listChannelDeliveries: () => listChannelDeliveries,
821
+ listChannels: () => listChannels,
822
+ listKeywords: () => listKeywords,
823
+ listPeople: () => listPeople,
824
+ listSegments: () => listSegments,
825
+ mergePeople: () => mergePeople,
826
+ revokeApiKey: () => revokeApiKey,
827
+ rotateWebhookSecret: () => rotateWebhookSecret,
828
+ runAlertDigest: () => runAlertDigest,
829
+ searchMentions: () => searchMentions,
830
+ splitPerson: () => splitPerson,
831
+ testAlert: () => testAlert,
832
+ testChannel: () => testChannel,
833
+ updateAlert: () => updateAlert,
834
+ updateChannel: () => updateChannel,
835
+ updateCompany: () => updateCompany,
836
+ updateKeyword: () => updateKeyword,
837
+ updateMention: () => updateMention,
838
+ updatePerson: () => updatePerson,
839
+ updateSegment: () => updateSegment
840
+ });
841
+
842
+ // src/generated/client.gen.ts
843
+ var client = createClient(createConfig({ baseUrl: "https://api.mentio.dev" }));
844
+
845
+ // src/generated/sdk.gen.ts
846
+ var getHealth = (options) => (options?.client ?? client).get({ url: "/v1/health", ...options });
847
+ var listKeywords = (options) => (options?.client ?? client).get({
848
+ security: [{ scheme: "bearer", type: "http" }],
849
+ url: "/v1/keywords",
850
+ ...options
851
+ });
852
+ var createKeyword = (options) => (options.client ?? client).post({
853
+ security: [{ scheme: "bearer", type: "http" }],
854
+ url: "/v1/keywords",
855
+ ...options,
856
+ headers: {
857
+ "Content-Type": "application/json",
858
+ ...options.headers
859
+ }
860
+ });
861
+ var deleteKeyword = (options) => (options.client ?? client).delete({
862
+ security: [{ scheme: "bearer", type: "http" }],
863
+ url: "/v1/keywords/{id}",
864
+ ...options
865
+ });
866
+ var getKeyword = (options) => (options.client ?? client).get({
867
+ security: [{ scheme: "bearer", type: "http" }],
868
+ url: "/v1/keywords/{id}",
869
+ ...options
870
+ });
871
+ var updateKeyword = (options) => (options.client ?? client).patch({
872
+ security: [{ scheme: "bearer", type: "http" }],
873
+ url: "/v1/keywords/{id}",
874
+ ...options,
875
+ headers: {
876
+ "Content-Type": "application/json",
877
+ ...options.headers
878
+ }
879
+ });
880
+ var getMention = (options) => (options.client ?? client).get({
881
+ security: [{ scheme: "bearer", type: "http" }],
882
+ url: "/v1/mentions/{id}",
883
+ ...options
884
+ });
885
+ var updateMention = (options) => (options.client ?? client).patch({
886
+ security: [{ scheme: "bearer", type: "http" }],
887
+ url: "/v1/mentions/{id}",
888
+ ...options,
889
+ headers: {
890
+ "Content-Type": "application/json",
891
+ ...options.headers
892
+ }
893
+ });
894
+ var searchMentions = (options) => (options?.client ?? client).get({
895
+ security: [{ scheme: "bearer", type: "http" }],
896
+ url: "/v1/mentions",
897
+ ...options
898
+ });
899
+ var exportMentionsCsv = (options) => (options?.client ?? client).get({
900
+ security: [{ scheme: "bearer", type: "http" }],
901
+ url: "/v1/mentions/export.csv",
902
+ ...options
903
+ });
904
+ var exportPeopleCsv = (options) => (options?.client ?? client).get({
905
+ security: [{ scheme: "bearer", type: "http" }],
906
+ url: "/v1/people/export.csv",
907
+ ...options
908
+ });
909
+ var listPeople = (options) => (options?.client ?? client).get({
910
+ security: [{ scheme: "bearer", type: "http" }],
911
+ url: "/v1/people",
912
+ ...options
913
+ });
914
+ var getPerson = (options) => (options.client ?? client).get({
915
+ security: [{ scheme: "bearer", type: "http" }],
916
+ url: "/v1/people/{id}",
917
+ ...options
918
+ });
919
+ var updatePerson = (options) => (options.client ?? client).patch({
920
+ security: [{ scheme: "bearer", type: "http" }],
921
+ url: "/v1/people/{id}",
922
+ ...options,
923
+ headers: {
924
+ "Content-Type": "application/json",
925
+ ...options.headers
926
+ }
927
+ });
928
+ var mergePeople = (options) => (options.client ?? client).post({
929
+ security: [{ scheme: "bearer", type: "http" }],
930
+ url: "/v1/people/{id}/merge",
931
+ ...options,
932
+ headers: {
933
+ "Content-Type": "application/json",
934
+ ...options.headers
935
+ }
936
+ });
937
+ var splitPerson = (options) => (options.client ?? client).post({
938
+ security: [{ scheme: "bearer", type: "http" }],
939
+ url: "/v1/people/{id}/split",
940
+ ...options
941
+ });
942
+ var listSegments = (options) => (options?.client ?? client).get({
943
+ security: [{ scheme: "bearer", type: "http" }],
944
+ url: "/v1/segments",
945
+ ...options
946
+ });
947
+ var createSegment = (options) => (options.client ?? client).post({
948
+ security: [{ scheme: "bearer", type: "http" }],
949
+ url: "/v1/segments",
950
+ ...options,
951
+ headers: {
952
+ "Content-Type": "application/json",
953
+ ...options.headers
954
+ }
955
+ });
956
+ var deleteSegment = (options) => (options.client ?? client).delete({
957
+ security: [{ scheme: "bearer", type: "http" }],
958
+ url: "/v1/segments/{id}",
959
+ ...options
960
+ });
961
+ var getSegment = (options) => (options.client ?? client).get({
962
+ security: [{ scheme: "bearer", type: "http" }],
963
+ url: "/v1/segments/{id}",
964
+ ...options
965
+ });
966
+ var updateSegment = (options) => (options.client ?? client).patch({
967
+ security: [{ scheme: "bearer", type: "http" }],
968
+ url: "/v1/segments/{id}",
969
+ ...options,
970
+ headers: {
971
+ "Content-Type": "application/json",
972
+ ...options.headers
973
+ }
974
+ });
975
+ var getCompany = (options) => (options?.client ?? client).get({
976
+ security: [{ scheme: "bearer", type: "http" }],
977
+ url: "/v1/company",
978
+ ...options
979
+ });
980
+ var updateCompany = (options) => (options.client ?? client).patch({
981
+ security: [{ scheme: "bearer", type: "http" }],
982
+ url: "/v1/company",
983
+ ...options,
984
+ headers: {
985
+ "Content-Type": "application/json",
986
+ ...options.headers
987
+ }
988
+ });
989
+ var listApiKeys = (options) => (options?.client ?? client).get({
990
+ security: [{ scheme: "bearer", type: "http" }],
991
+ url: "/v1/api-keys",
992
+ ...options
993
+ });
994
+ var createApiKey = (options) => (options.client ?? client).post({
995
+ security: [{ scheme: "bearer", type: "http" }],
996
+ url: "/v1/api-keys",
997
+ ...options,
998
+ headers: {
999
+ "Content-Type": "application/json",
1000
+ ...options.headers
1001
+ }
1002
+ });
1003
+ var revokeApiKey = (options) => (options.client ?? client).delete({
1004
+ security: [{ scheme: "bearer", type: "http" }],
1005
+ url: "/v1/api-keys/{id}",
1006
+ ...options
1007
+ });
1008
+ var deleteAlert = (options) => (options.client ?? client).delete({
1009
+ security: [{ scheme: "bearer", type: "http" }],
1010
+ url: "/v1/alerts/{id}",
1011
+ ...options
1012
+ });
1013
+ var getAlert = (options) => (options.client ?? client).get({
1014
+ security: [{ scheme: "bearer", type: "http" }],
1015
+ url: "/v1/alerts/{id}",
1016
+ ...options
1017
+ });
1018
+ var updateAlert = (options) => (options.client ?? client).patch({
1019
+ security: [{ scheme: "bearer", type: "http" }],
1020
+ url: "/v1/alerts/{id}",
1021
+ ...options,
1022
+ headers: {
1023
+ "Content-Type": "application/json",
1024
+ ...options.headers
1025
+ }
1026
+ });
1027
+ var listAlerts = (options) => (options?.client ?? client).get({
1028
+ security: [{ scheme: "bearer", type: "http" }],
1029
+ url: "/v1/alerts",
1030
+ ...options
1031
+ });
1032
+ var createAlert = (options) => (options.client ?? client).post({
1033
+ security: [{ scheme: "bearer", type: "http" }],
1034
+ url: "/v1/alerts",
1035
+ ...options,
1036
+ headers: {
1037
+ "Content-Type": "application/json",
1038
+ ...options.headers
1039
+ }
1040
+ });
1041
+ var testAlert = (options) => (options.client ?? client).post({
1042
+ security: [{ scheme: "bearer", type: "http" }],
1043
+ url: "/v1/alerts/{id}/test",
1044
+ ...options
1045
+ });
1046
+ var runAlertDigest = (options) => (options.client ?? client).post({
1047
+ security: [{ scheme: "bearer", type: "http" }],
1048
+ url: "/v1/alerts/{id}/run",
1049
+ ...options
1050
+ });
1051
+ var getAnalyticsSummary = (options) => (options?.client ?? client).get({
1052
+ security: [{ scheme: "bearer", type: "http" }],
1053
+ url: "/v1/analytics/summary",
1054
+ ...options
1055
+ });
1056
+ var getAnalyticsSeries = (options) => (options?.client ?? client).get({
1057
+ security: [{ scheme: "bearer", type: "http" }],
1058
+ url: "/v1/analytics/series",
1059
+ ...options
1060
+ });
1061
+ var getAnalyticsBreakdown = (options) => (options.client ?? client).get({
1062
+ security: [{ scheme: "bearer", type: "http" }],
1063
+ url: "/v1/analytics/breakdown",
1064
+ ...options
1065
+ });
1066
+ var getShareOfVoice = (options) => (options?.client ?? client).get({
1067
+ security: [{ scheme: "bearer", type: "http" }],
1068
+ url: "/v1/analytics/share-of-voice",
1069
+ ...options
1070
+ });
1071
+ var deleteChannel = (options) => (options.client ?? client).delete({
1072
+ security: [{ scheme: "bearer", type: "http" }],
1073
+ url: "/v1/channels/{id}",
1074
+ ...options
1075
+ });
1076
+ var getChannel = (options) => (options.client ?? client).get({
1077
+ security: [{ scheme: "bearer", type: "http" }],
1078
+ url: "/v1/channels/{id}",
1079
+ ...options
1080
+ });
1081
+ var updateChannel = (options) => (options.client ?? client).patch({
1082
+ security: [{ scheme: "bearer", type: "http" }],
1083
+ url: "/v1/channels/{id}",
1084
+ ...options,
1085
+ headers: {
1086
+ "Content-Type": "application/json",
1087
+ ...options.headers
1088
+ }
1089
+ });
1090
+ var testChannel = (options) => (options.client ?? client).post({
1091
+ security: [{ scheme: "bearer", type: "http" }],
1092
+ url: "/v1/channels/{id}/test",
1093
+ ...options
1094
+ });
1095
+ var rotateWebhookSecret = (options) => (options.client ?? client).post({
1096
+ security: [{ scheme: "bearer", type: "http" }],
1097
+ url: "/v1/channels/{id}/rotate-secret",
1098
+ ...options
1099
+ });
1100
+ var listChannelDeliveries = (options) => (options.client ?? client).get({
1101
+ security: [{ scheme: "bearer", type: "http" }],
1102
+ url: "/v1/channels/{id}/deliveries",
1103
+ ...options
1104
+ });
1105
+ var listChannels = (options) => (options?.client ?? client).get({
1106
+ security: [{ scheme: "bearer", type: "http" }],
1107
+ url: "/v1/channels",
1108
+ ...options
1109
+ });
1110
+ var createChannel = (options) => (options.client ?? client).post({
1111
+ security: [{ scheme: "bearer", type: "http" }],
1112
+ url: "/v1/channels",
1113
+ ...options,
1114
+ headers: {
1115
+ "Content-Type": "application/json",
1116
+ ...options.headers
1117
+ }
1118
+ });
1119
+
1120
+ // src/index.ts
1121
+ var DEFAULT_BASE_URL = "https://api.mentio.dev";
1122
+ function createMentio(options) {
1123
+ const client2 = createClient(
1124
+ createConfig({
1125
+ baseUrl: (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, ""),
1126
+ auth: () => options.apiKey,
1127
+ ...options.fetch ? { fetch: options.fetch } : {},
1128
+ ...options.headers ? { headers: options.headers } : {}
1129
+ })
1130
+ );
1131
+ const bound = {};
1132
+ for (const [name, fn] of Object.entries(sdk_gen_exports)) {
1133
+ if (typeof fn !== "function") continue;
1134
+ const call = fn;
1135
+ bound[name] = (callOptions) => call({ ...callOptions, client: callOptions?.client ?? client2 });
1136
+ }
1137
+ return { ...bound, client: client2 };
1138
+ }
1139
+ export {
1140
+ DEFAULT_BASE_URL,
1141
+ createAlert,
1142
+ createApiKey,
1143
+ createChannel,
1144
+ createClient,
1145
+ createConfig,
1146
+ createKeyword,
1147
+ createMentio,
1148
+ createSegment,
1149
+ deleteAlert,
1150
+ deleteChannel,
1151
+ deleteKeyword,
1152
+ deleteSegment,
1153
+ exportMentionsCsv,
1154
+ exportPeopleCsv,
1155
+ getAlert,
1156
+ getAnalyticsBreakdown,
1157
+ getAnalyticsSeries,
1158
+ getAnalyticsSummary,
1159
+ getChannel,
1160
+ getCompany,
1161
+ getHealth,
1162
+ getKeyword,
1163
+ getMention,
1164
+ getPerson,
1165
+ getSegment,
1166
+ getShareOfVoice,
1167
+ listAlerts,
1168
+ listApiKeys,
1169
+ listChannelDeliveries,
1170
+ listChannels,
1171
+ listKeywords,
1172
+ listPeople,
1173
+ listSegments,
1174
+ mergePeople,
1175
+ revokeApiKey,
1176
+ rotateWebhookSecret,
1177
+ runAlertDigest,
1178
+ searchMentions,
1179
+ splitPerson,
1180
+ testAlert,
1181
+ testChannel,
1182
+ updateAlert,
1183
+ updateChannel,
1184
+ updateCompany,
1185
+ updateKeyword,
1186
+ updateMention,
1187
+ updatePerson,
1188
+ updateSegment
1189
+ };
1190
+ //# sourceMappingURL=index.js.map