@eudiplo/sdk-core 1.14.0-main.a39e98f → 1.14.0-main.a4bf740

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/README.md CHANGED
@@ -82,6 +82,158 @@ await waitForCompletion();
82
82
  | `verifyAndWait(options)` | One-liner: create request + wait for result |
83
83
  | `issueAndWait(options)` | One-liner: create offer + wait for result |
84
84
 
85
+ ### Digital Credentials API (Browser Native)
86
+
87
+ The SDK includes utilities for the [Digital Credentials API](https://wicg.github.io/digital-credentials/), enabling browser-native credential presentation without QR codes.
88
+
89
+ ```typescript
90
+ import { isDcApiAvailable, verifyWithDcApi } from '@eudiplo/sdk-core';
91
+
92
+ // Check if browser supports DC API
93
+ if (isDcApiAvailable()) {
94
+ const result = await verifyWithDcApi({
95
+ baseUrl: 'https://eudiplo.example.com',
96
+ clientId: 'my-demo',
97
+ clientSecret: 'secret',
98
+ configId: 'age-over-18',
99
+ });
100
+
101
+ console.log('Verified!', result.session.credentials);
102
+ } else {
103
+ // Fall back to QR code flow
104
+ const session = await verifyAndWait({...});
105
+ }
106
+ ```
107
+
108
+ #### DC API Functions
109
+
110
+ | Function | Description |
111
+ | ---------------------- | --------------------------------------------------- |
112
+ | `isDcApiAvailable()` | Check if browser supports Digital Credentials API |
113
+ | `verifyWithDcApi()` | Complete verification flow using browser-native API |
114
+ | `createDcApiRequest()` | Create a `DigitalCredentialRequestOptions` object |
115
+
116
+ #### Lower-level DC API Usage
117
+
118
+ ```typescript
119
+ import { createDcApiRequest, EudiploClient } from '@eudiplo/sdk-core';
120
+
121
+ const client = new EudiploClient({...});
122
+
123
+ // Create presentation request
124
+ const { uri, sessionId } = await client.createPresentationRequest({
125
+ configId: 'age-over-18',
126
+ responseType: 'dc-api',
127
+ });
128
+
129
+ // Create the browser request object
130
+ const request = createDcApiRequest(uri);
131
+
132
+ // Call the browser API directly
133
+ const credential = await navigator.credentials.get(request);
134
+
135
+ // Submit the response and get verified session
136
+ const session = await client.submitDcApiResponse(sessionId, credential);
137
+ ```
138
+
139
+ #### Secure Server/Client Deployment (Recommended for Production)
140
+
141
+ When deploying to production, you should **never expose your client credentials to the browser**. The SDK provides helper functions to split the DC API flow between your server (where credentials are safe) and the browser (where the DC API runs).
142
+
143
+ **Server-side Functions:**
144
+
145
+ | Function | Description |
146
+ | -------------------------------- | ------------------------------------------------------ |
147
+ | `createDcApiRequestForBrowser()` | Create request on server, return safe data for browser |
148
+ | `submitDcApiWalletResponse()` | Submit wallet response to EUDIPLO from server |
149
+
150
+ **Browser-side Functions:**
151
+
152
+ | Function | Description |
153
+ | ------------- | ------------------------------------------------------ |
154
+ | `callDcApi()` | Call the native DC API with a request from your server |
155
+
156
+ ##### Example: Express.js Backend + Browser Frontend
157
+
158
+ **Server (Express.js / Next.js API route):**
159
+
160
+ ```typescript
161
+ import {
162
+ createDcApiRequestForBrowser,
163
+ submitDcApiWalletResponse,
164
+ } from '@eudiplo/sdk-core';
165
+
166
+ // POST /api/start-verification
167
+ app.post('/api/start-verification', async (req, res) => {
168
+ const requestData = await createDcApiRequestForBrowser({
169
+ baseUrl: process.env.EUDIPLO_URL,
170
+ clientId: process.env.EUDIPLO_CLIENT_ID, // ✅ Safe on server
171
+ clientSecret: process.env.EUDIPLO_SECRET, // ✅ Safe on server
172
+ configId: 'age-over-18',
173
+ });
174
+
175
+ // Only safe data is sent to browser (no secrets)
176
+ res.json(requestData);
177
+ });
178
+
179
+ // POST /api/complete-verification
180
+ app.post('/api/complete-verification', async (req, res) => {
181
+ const { responseUri, walletResponse } = req.body;
182
+
183
+ const result = await submitDcApiWalletResponse({
184
+ responseUri,
185
+ walletResponse,
186
+ sendResponse: true, // Get verified claims back
187
+ });
188
+
189
+ // result.credentials contains the verified data
190
+ res.json(result);
191
+ });
192
+ ```
193
+
194
+ **Browser (React / vanilla JS):**
195
+
196
+ ```typescript
197
+ import { callDcApi, isDcApiAvailable } from '@eudiplo/sdk-core';
198
+
199
+ async function verifyAge() {
200
+ // 1. Get the request from your server (credentials stay on server)
201
+ const requestData = await fetch('/api/start-verification', {
202
+ method: 'POST',
203
+ }).then((r) => r.json());
204
+
205
+ // 2. Check DC API support and call it locally
206
+ if (!isDcApiAvailable()) {
207
+ throw new Error('Digital Credentials API not supported');
208
+ }
209
+
210
+ const walletResponse = await callDcApi(requestData.requestObject);
211
+
212
+ // 3. Send the wallet response back to your server for verification
213
+ const result = await fetch('/api/complete-verification', {
214
+ method: 'POST',
215
+ headers: { 'Content-Type': 'application/json' },
216
+ body: JSON.stringify({
217
+ responseUri: requestData.responseUri,
218
+ walletResponse,
219
+ }),
220
+ }).then((r) => r.json());
221
+
222
+ console.log('Verified!', result.credentials);
223
+ return result;
224
+ }
225
+ ```
226
+
227
+ **What stays where:**
228
+
229
+ | Data | Location | Safe to expose? |
230
+ | ------------------------------ | ---------------- | ------------------- |
231
+ | `clientId` / `clientSecret` | Server only | ❌ Never expose |
232
+ | `requestObject` (signed JWT) | Server → Browser | ✅ Yes |
233
+ | `responseUri` | Server → Browser | ✅ Yes |
234
+ | Wallet response (encrypted VP) | Browser → Server | ✅ Yes |
235
+ | Verified credentials | Server only | Depends on use case |
236
+
85
237
  ### Class-based API (More Control)
86
238
 
87
239
  ```typescript
@@ -175,6 +327,43 @@ const session = await client.waitForSession(sessionId, {
175
327
  });
176
328
  ```
177
329
 
330
+ ### `subscribeToSession(sessionId, options)`
331
+
332
+ Subscribe to real-time session status updates via Server-Sent Events (SSE).
333
+ This is more efficient than polling and provides instant updates.
334
+
335
+ ```typescript
336
+ const subscription = await client.subscribeToSession(sessionId, {
337
+ onStatusChange: (event) => {
338
+ console.log(`Status: ${event.status}`);
339
+ if (['completed', 'expired', 'failed'].includes(event.status)) {
340
+ subscription.close();
341
+ }
342
+ },
343
+ onError: (error) => console.error('SSE error:', error),
344
+ onOpen: () => console.log('Connected'),
345
+ });
346
+
347
+ // Later, to close the connection:
348
+ subscription.close();
349
+ ```
350
+
351
+ ### `waitForSessionWithSse(sessionId, options)`
352
+
353
+ Wait for session completion using SSE instead of polling. Returns a Promise
354
+ that resolves when the session completes.
355
+
356
+ ```typescript
357
+ try {
358
+ const finalStatus = await client.waitForSessionWithSse(sessionId, {
359
+ onStatusChange: (event) => console.log('Status:', event.status),
360
+ });
361
+ console.log('Session completed:', finalStatus);
362
+ } catch (error) {
363
+ console.error('Session failed:', error);
364
+ }
365
+ ```
366
+
178
367
  ## Examples
179
368
 
180
369
  ### Age Verification in a Web Shop
@@ -1,4 +1,4 @@
1
- import { C as Config, a as Client } from '../../types.gen-CIiveH8G.mjs';
1
+ import { b as Config, C as Client } from '../../types.gen-CVkHMB8b.mjs';
2
2
 
3
3
  declare const createClient: (config?: Config) => Client;
4
4
 
@@ -1,4 +1,4 @@
1
- import { C as Config, a as Client } from '../../types.gen-CIiveH8G.js';
1
+ import { b as Config, C as Client } from '../../types.gen-CVkHMB8b.js';
2
2
 
3
3
  declare const createClient: (config?: Config) => Client;
4
4
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // src/api/core/serverSentEvents.gen.ts
4
- var createSseClient = ({
4
+ function createSseClient({
5
5
  onRequest,
6
6
  onSseError,
7
7
  onSseEvent,
@@ -13,7 +13,7 @@ var createSseClient = ({
13
13
  sseSleepFn,
14
14
  url,
15
15
  ...options
16
- }) => {
16
+ }) {
17
17
  let lastEventId;
18
18
  const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
19
19
  const createStream = async function* () {
@@ -60,7 +60,7 @@ var createSseClient = ({
60
60
  const { done, value } = await reader.read();
61
61
  if (done) break;
62
62
  buffer += value;
63
- buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
63
+ buffer = buffer.replace(/\r\n?/g, "\n");
64
64
  const chunks = buffer.split("\n\n");
65
65
  buffer = chunks.pop() ?? "";
66
66
  for (const chunk of chunks) {
@@ -134,7 +134,7 @@ var createSseClient = ({
134
134
  };
135
135
  const stream = createStream();
136
136
  return { stream };
137
- };
137
+ }
138
138
 
139
139
  // src/api/core/pathSerializer.gen.ts
140
140
  var separatorArrayExplode = (style) => {
@@ -637,8 +637,9 @@ var createClient = (config = {}) => {
637
637
  if (opts.body === void 0 || opts.serializedBody === "") {
638
638
  opts.headers.delete("Content-Type");
639
639
  }
640
- const url = buildUrl(opts);
641
- return { opts, url };
640
+ const resolvedOpts = opts;
641
+ const url = buildUrl(resolvedOpts);
642
+ return { opts: resolvedOpts, url };
642
643
  };
643
644
  const request = async (options) => {
644
645
  const { opts, url } = await beforeRequest(options);
@@ -719,10 +720,14 @@ var createClient = (config = {}) => {
719
720
  case "arrayBuffer":
720
721
  case "blob":
721
722
  case "formData":
722
- case "json":
723
723
  case "text":
724
724
  data = await response[parseAs]();
725
725
  break;
726
+ case "json": {
727
+ const text = await response.text();
728
+ data = text ? JSON.parse(text) : {};
729
+ break;
730
+ }
726
731
  case "stream":
727
732
  return opts.responseStyle === "data" ? response.body : {
728
733
  data: response.body,
@@ -785,8 +790,9 @@ var createClient = (config = {}) => {
785
790
  url
786
791
  });
787
792
  };
793
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
788
794
  return {
789
- buildUrl,
795
+ buildUrl: _buildUrl,
790
796
  connect: makeMethodFn("CONNECT"),
791
797
  delete: makeMethodFn("DELETE"),
792
798
  get: makeMethodFn("GET"),
@@ -1,5 +1,5 @@
1
1
  // src/api/core/serverSentEvents.gen.ts
2
- var createSseClient = ({
2
+ function createSseClient({
3
3
  onRequest,
4
4
  onSseError,
5
5
  onSseEvent,
@@ -11,7 +11,7 @@ var createSseClient = ({
11
11
  sseSleepFn,
12
12
  url,
13
13
  ...options
14
- }) => {
14
+ }) {
15
15
  let lastEventId;
16
16
  const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
17
17
  const createStream = async function* () {
@@ -58,7 +58,7 @@ var createSseClient = ({
58
58
  const { done, value } = await reader.read();
59
59
  if (done) break;
60
60
  buffer += value;
61
- buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
61
+ buffer = buffer.replace(/\r\n?/g, "\n");
62
62
  const chunks = buffer.split("\n\n");
63
63
  buffer = chunks.pop() ?? "";
64
64
  for (const chunk of chunks) {
@@ -132,7 +132,7 @@ var createSseClient = ({
132
132
  };
133
133
  const stream = createStream();
134
134
  return { stream };
135
- };
135
+ }
136
136
 
137
137
  // src/api/core/pathSerializer.gen.ts
138
138
  var separatorArrayExplode = (style) => {
@@ -635,8 +635,9 @@ var createClient = (config = {}) => {
635
635
  if (opts.body === void 0 || opts.serializedBody === "") {
636
636
  opts.headers.delete("Content-Type");
637
637
  }
638
- const url = buildUrl(opts);
639
- return { opts, url };
638
+ const resolvedOpts = opts;
639
+ const url = buildUrl(resolvedOpts);
640
+ return { opts: resolvedOpts, url };
640
641
  };
641
642
  const request = async (options) => {
642
643
  const { opts, url } = await beforeRequest(options);
@@ -717,10 +718,14 @@ var createClient = (config = {}) => {
717
718
  case "arrayBuffer":
718
719
  case "blob":
719
720
  case "formData":
720
- case "json":
721
721
  case "text":
722
722
  data = await response[parseAs]();
723
723
  break;
724
+ case "json": {
725
+ const text = await response.text();
726
+ data = text ? JSON.parse(text) : {};
727
+ break;
728
+ }
724
729
  case "stream":
725
730
  return opts.responseStyle === "data" ? response.body : {
726
731
  data: response.body,
@@ -783,8 +788,9 @@ var createClient = (config = {}) => {
783
788
  url
784
789
  });
785
790
  };
791
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
786
792
  return {
787
- buildUrl,
793
+ buildUrl: _buildUrl,
788
794
  connect: makeMethodFn("CONNECT"),
789
795
  delete: makeMethodFn("DELETE"),
790
796
  get: makeMethodFn("GET"),
@@ -1,4 +1,4 @@
1
- export { A as Auth, a as Client, b as ClientOptions, C as Config, c as CreateClientConfig, O as Options, Q as QuerySerializerOptions, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape, g as createConfig, h as formDataBodySerializer, j as jsonBodySerializer, m as mergeHeaders, u as urlSearchParamsBodySerializer } from '../../types.gen-CIiveH8G.mjs';
1
+ export { A as Auth, C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, Q as QuerySerializerOptions, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape, g as createConfig, h as formDataBodySerializer, j as jsonBodySerializer, m as mergeHeaders, u as urlSearchParamsBodySerializer } from '../../types.gen-CVkHMB8b.mjs';
2
2
  export { createClient } from './client.gen.mjs';
3
3
 
4
4
  type Slot = "body" | "headers" | "path" | "query";
@@ -1,4 +1,4 @@
1
- export { A as Auth, a as Client, b as ClientOptions, C as Config, c as CreateClientConfig, O as Options, Q as QuerySerializerOptions, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape, g as createConfig, h as formDataBodySerializer, j as jsonBodySerializer, m as mergeHeaders, u as urlSearchParamsBodySerializer } from '../../types.gen-CIiveH8G.js';
1
+ export { A as Auth, C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, Q as QuerySerializerOptions, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape, g as createConfig, h as formDataBodySerializer, j as jsonBodySerializer, m as mergeHeaders, u as urlSearchParamsBodySerializer } from '../../types.gen-CVkHMB8b.js';
2
2
  export { createClient } from './client.gen.js';
3
3
 
4
4
  type Slot = "body" | "headers" | "path" | "query";
@@ -88,7 +88,7 @@ var buildKeyMap = (fields, map) => {
88
88
  };
89
89
  var stripEmptySlots = (params) => {
90
90
  for (const [slot, value] of Object.entries(params)) {
91
- if (value && typeof value === "object" && !Object.keys(value).length) {
91
+ if (value && typeof value === "object" && !Array.isArray(value) && !Object.keys(value).length) {
92
92
  delete params[slot];
93
93
  }
94
94
  }
@@ -231,7 +231,7 @@ var serializeQueryKeyValue = (value) => {
231
231
  };
232
232
 
233
233
  // src/api/core/serverSentEvents.gen.ts
234
- var createSseClient = ({
234
+ function createSseClient({
235
235
  onRequest,
236
236
  onSseError,
237
237
  onSseEvent,
@@ -243,7 +243,7 @@ var createSseClient = ({
243
243
  sseSleepFn,
244
244
  url,
245
245
  ...options
246
- }) => {
246
+ }) {
247
247
  let lastEventId;
248
248
  const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
249
249
  const createStream = async function* () {
@@ -290,7 +290,7 @@ var createSseClient = ({
290
290
  const { done, value } = await reader.read();
291
291
  if (done) break;
292
292
  buffer += value;
293
- buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
293
+ buffer = buffer.replace(/\r\n?/g, "\n");
294
294
  const chunks = buffer.split("\n\n");
295
295
  buffer = chunks.pop() ?? "";
296
296
  for (const chunk of chunks) {
@@ -364,7 +364,7 @@ var createSseClient = ({
364
364
  };
365
365
  const stream = createStream();
366
366
  return { stream };
367
- };
367
+ }
368
368
 
369
369
  // src/api/core/pathSerializer.gen.ts
370
370
  var separatorArrayExplode = (style) => {
@@ -859,8 +859,9 @@ var createClient = (config = {}) => {
859
859
  if (opts.body === void 0 || opts.serializedBody === "") {
860
860
  opts.headers.delete("Content-Type");
861
861
  }
862
- const url = buildUrl(opts);
863
- return { opts, url };
862
+ const resolvedOpts = opts;
863
+ const url = buildUrl(resolvedOpts);
864
+ return { opts: resolvedOpts, url };
864
865
  };
865
866
  const request = async (options) => {
866
867
  const { opts, url } = await beforeRequest(options);
@@ -941,10 +942,14 @@ var createClient = (config = {}) => {
941
942
  case "arrayBuffer":
942
943
  case "blob":
943
944
  case "formData":
944
- case "json":
945
945
  case "text":
946
946
  data = await response[parseAs]();
947
947
  break;
948
+ case "json": {
949
+ const text = await response.text();
950
+ data = text ? JSON.parse(text) : {};
951
+ break;
952
+ }
948
953
  case "stream":
949
954
  return opts.responseStyle === "data" ? response.body : {
950
955
  data: response.body,
@@ -1007,8 +1012,9 @@ var createClient = (config = {}) => {
1007
1012
  url
1008
1013
  });
1009
1014
  };
1015
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
1010
1016
  return {
1011
- buildUrl,
1017
+ buildUrl: _buildUrl,
1012
1018
  connect: makeMethodFn("CONNECT"),
1013
1019
  delete: makeMethodFn("DELETE"),
1014
1020
  get: makeMethodFn("GET"),
@@ -86,7 +86,7 @@ var buildKeyMap = (fields, map) => {
86
86
  };
87
87
  var stripEmptySlots = (params) => {
88
88
  for (const [slot, value] of Object.entries(params)) {
89
- if (value && typeof value === "object" && !Object.keys(value).length) {
89
+ if (value && typeof value === "object" && !Array.isArray(value) && !Object.keys(value).length) {
90
90
  delete params[slot];
91
91
  }
92
92
  }
@@ -229,7 +229,7 @@ var serializeQueryKeyValue = (value) => {
229
229
  };
230
230
 
231
231
  // src/api/core/serverSentEvents.gen.ts
232
- var createSseClient = ({
232
+ function createSseClient({
233
233
  onRequest,
234
234
  onSseError,
235
235
  onSseEvent,
@@ -241,7 +241,7 @@ var createSseClient = ({
241
241
  sseSleepFn,
242
242
  url,
243
243
  ...options
244
- }) => {
244
+ }) {
245
245
  let lastEventId;
246
246
  const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
247
247
  const createStream = async function* () {
@@ -288,7 +288,7 @@ var createSseClient = ({
288
288
  const { done, value } = await reader.read();
289
289
  if (done) break;
290
290
  buffer += value;
291
- buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
291
+ buffer = buffer.replace(/\r\n?/g, "\n");
292
292
  const chunks = buffer.split("\n\n");
293
293
  buffer = chunks.pop() ?? "";
294
294
  for (const chunk of chunks) {
@@ -362,7 +362,7 @@ var createSseClient = ({
362
362
  };
363
363
  const stream = createStream();
364
364
  return { stream };
365
- };
365
+ }
366
366
 
367
367
  // src/api/core/pathSerializer.gen.ts
368
368
  var separatorArrayExplode = (style) => {
@@ -857,8 +857,9 @@ var createClient = (config = {}) => {
857
857
  if (opts.body === void 0 || opts.serializedBody === "") {
858
858
  opts.headers.delete("Content-Type");
859
859
  }
860
- const url = buildUrl(opts);
861
- return { opts, url };
860
+ const resolvedOpts = opts;
861
+ const url = buildUrl(resolvedOpts);
862
+ return { opts: resolvedOpts, url };
862
863
  };
863
864
  const request = async (options) => {
864
865
  const { opts, url } = await beforeRequest(options);
@@ -939,10 +940,14 @@ var createClient = (config = {}) => {
939
940
  case "arrayBuffer":
940
941
  case "blob":
941
942
  case "formData":
942
- case "json":
943
943
  case "text":
944
944
  data = await response[parseAs]();
945
945
  break;
946
+ case "json": {
947
+ const text = await response.text();
948
+ data = text ? JSON.parse(text) : {};
949
+ break;
950
+ }
946
951
  case "stream":
947
952
  return opts.responseStyle === "data" ? response.body : {
948
953
  data: response.body,
@@ -1005,8 +1010,9 @@ var createClient = (config = {}) => {
1005
1010
  url
1006
1011
  });
1007
1012
  };
1013
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
1008
1014
  return {
1009
- buildUrl,
1015
+ buildUrl: _buildUrl,
1010
1016
  connect: makeMethodFn("CONNECT"),
1011
1017
  delete: makeMethodFn("DELETE"),
1012
1018
  get: makeMethodFn("GET"),
@@ -1 +1 @@
1
- export { a as Client, b as ClientOptions, C as Config, c as CreateClientConfig, O as Options, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape } from '../../types.gen-CIiveH8G.mjs';
1
+ export { C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape } from '../../types.gen-CVkHMB8b.mjs';
@@ -1 +1 @@
1
- export { a as Client, b as ClientOptions, C as Config, c as CreateClientConfig, O as Options, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape } from '../../types.gen-CIiveH8G.js';
1
+ export { C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape } from '../../types.gen-CVkHMB8b.js';
@@ -1,2 +1,15 @@
1
- import '../types.gen-CIiveH8G.mjs';
2
- export { ed as CreateClientConfig, ec as client } from '../client.gen-CU56lLgT.mjs';
1
+ import { C as Client, a as ClientOptions, b as Config } from '../types.gen-CVkHMB8b.mjs';
2
+ import { ai as ClientOptions$1 } from '../types.gen-8DOlTBVq.mjs';
3
+
4
+ /**
5
+ * The `createClientConfig()` function will be called on client initialization
6
+ * and the returned object will become the client's initial configuration.
7
+ *
8
+ * You may want to initialize your client this way instead of calling
9
+ * `setConfig()`. This is useful for example if you're using Next.js
10
+ * to ensure your client always has the correct values.
11
+ */
12
+ type CreateClientConfig<T extends ClientOptions = ClientOptions$1> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
13
+ declare const client: Client;
14
+
15
+ export { type CreateClientConfig, client };
@@ -1,2 +1,15 @@
1
- import '../types.gen-CIiveH8G.js';
2
- export { ed as CreateClientConfig, ec as client } from '../client.gen-CsfHl8pY.js';
1
+ import { C as Client, a as ClientOptions, b as Config } from '../types.gen-CVkHMB8b.js';
2
+ import { ai as ClientOptions$1 } from '../types.gen-8DOlTBVq.js';
3
+
4
+ /**
5
+ * The `createClientConfig()` function will be called on client initialization
6
+ * and the returned object will become the client's initial configuration.
7
+ *
8
+ * You may want to initialize your client this way instead of calling
9
+ * `setConfig()`. This is useful for example if you're using Next.js
10
+ * to ensure your client always has the correct values.
11
+ */
12
+ type CreateClientConfig<T extends ClientOptions = ClientOptions$1> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
13
+ declare const client: Client;
14
+
15
+ export { type CreateClientConfig, client };
@@ -9,7 +9,7 @@ var jsonBodySerializer = {
9
9
  };
10
10
 
11
11
  // src/api/core/serverSentEvents.gen.ts
12
- var createSseClient = ({
12
+ function createSseClient({
13
13
  onRequest,
14
14
  onSseError,
15
15
  onSseEvent,
@@ -21,7 +21,7 @@ var createSseClient = ({
21
21
  sseSleepFn,
22
22
  url,
23
23
  ...options
24
- }) => {
24
+ }) {
25
25
  let lastEventId;
26
26
  const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
27
27
  const createStream = async function* () {
@@ -68,7 +68,7 @@ var createSseClient = ({
68
68
  const { done, value } = await reader.read();
69
69
  if (done) break;
70
70
  buffer += value;
71
- buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
71
+ buffer = buffer.replace(/\r\n?/g, "\n");
72
72
  const chunks = buffer.split("\n\n");
73
73
  buffer = chunks.pop() ?? "";
74
74
  for (const chunk of chunks) {
@@ -142,7 +142,7 @@ var createSseClient = ({
142
142
  };
143
143
  const stream = createStream();
144
144
  return { stream };
145
- };
145
+ }
146
146
 
147
147
  // src/api/core/pathSerializer.gen.ts
148
148
  var separatorArrayExplode = (style) => {
@@ -637,8 +637,9 @@ var createClient = (config = {}) => {
637
637
  if (opts.body === void 0 || opts.serializedBody === "") {
638
638
  opts.headers.delete("Content-Type");
639
639
  }
640
- const url = buildUrl(opts);
641
- return { opts, url };
640
+ const resolvedOpts = opts;
641
+ const url = buildUrl(resolvedOpts);
642
+ return { opts: resolvedOpts, url };
642
643
  };
643
644
  const request = async (options) => {
644
645
  const { opts, url } = await beforeRequest(options);
@@ -719,10 +720,14 @@ var createClient = (config = {}) => {
719
720
  case "arrayBuffer":
720
721
  case "blob":
721
722
  case "formData":
722
- case "json":
723
723
  case "text":
724
724
  data = await response[parseAs]();
725
725
  break;
726
+ case "json": {
727
+ const text = await response.text();
728
+ data = text ? JSON.parse(text) : {};
729
+ break;
730
+ }
726
731
  case "stream":
727
732
  return opts.responseStyle === "data" ? response.body : {
728
733
  data: response.body,
@@ -785,8 +790,9 @@ var createClient = (config = {}) => {
785
790
  url
786
791
  });
787
792
  };
793
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
788
794
  return {
789
- buildUrl,
795
+ buildUrl: _buildUrl,
790
796
  connect: makeMethodFn("CONNECT"),
791
797
  delete: makeMethodFn("DELETE"),
792
798
  get: makeMethodFn("GET"),