@molecule/app-http 1.1.3 → 1.1.5

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
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-10-17T00:21:23.012Z
6
+ Generated: 2026-10-17T19:12:43.116Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-http
@@ -13,6 +13,16 @@ Client HTTP interface for molecule.dev.
13
13
  Provides a unified HTTP client API that works across different
14
14
  HTTP libraries (fetch, axios, ky, etc.).
15
15
 
16
+ **The body is the SECOND argument: `post(url, data, config?)` — likewise `put` and `patch`,
17
+ and the response is `HttpResponse<T>` (read `.data` for the body).** `data` IS the request
18
+ body; a plain object is serialized as the JSON body. Passing `{ data: body }` there is NOT a
19
+ config object — it makes the wire body `{"data":{…}}`, so the API sees an object whose only
20
+ key is `data`, finds none of the fields it validates, and answers
21
+ `422 {"errors":{"username":["can't be blank"],…}}`. Write `post('/users', { user })`, never
22
+ `post('/users', { data: { user } })`. The config object (headers, params, timeout,
23
+ `skipAuthGate`) is the THIRD argument. Only `request({ method, url, data, … })` takes `data`
24
+ inside an options object, because there that object IS the config.
25
+
16
26
  > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
17
27
  > It is written to be read by coding agents as much as by people, and is generated from this
18
28
  > package's source — edit `src/index.ts` JSDoc, not this file.
@@ -28,10 +38,13 @@ import { useHttpClient } from '@molecule/app-react'
28
38
  function Plants() {
29
39
  const http = useHttpClient()
30
40
  const load = async () => {
31
- const res = await http.get<Plant[]>('/plants') // baseURL ('/api') is prepended
41
+ const res = await http.get<Plant[]>('/plants') // the bonded client's baseURL ('/api') is prepended
32
42
  setPlants(res.data)
33
43
  }
34
- // http.post(url, body), http.put, http.delete are also available.
44
+ // Body-carrying verbs take the body as the SECOND argument:
45
+ // http.post('/plants', plant) — wire body is `plant`
46
+ // http.post('/plants', { data: plant }) — WRONG: wire body is `{"data": plant}`
47
+ // http.put(url, body), http.patch(url, body) and http.delete(url) are also available.
35
48
  }
36
49
  ```
37
50
 
@@ -68,7 +81,8 @@ interface HttpClient {
68
81
  defaultHeaders: Record<string, string>
69
82
 
70
83
  /**
71
- * Makes a generic HTTP request.
84
+ * Makes a generic HTTP request. `data` is a field of THIS config object — the same body
85
+ * `post(url, data, config)` takes as its second argument.
72
86
  */
73
87
  request<T = unknown>(config: FullRequestConfig): Promise<HttpResponse<T>>
74
88
 
@@ -78,17 +92,21 @@ interface HttpClient {
78
92
  get<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
79
93
 
80
94
  /**
81
- * Makes a POST request.
95
+ * Makes a POST request. `data` is the request BODY, not a config object: the wire body is
96
+ * `data` itself, so `post(url, { data: body })` sends `{"data":body}` — pass `body` directly.
97
+ * A config (headers, params) is the THIRD argument.
82
98
  */
83
99
  post<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
84
100
 
85
101
  /**
86
- * Makes a PUT request.
102
+ * Makes a PUT request. `data` is the request BODY (second argument) — never `{ data: body }`,
103
+ * which sends `{"data":body}`; a config is the THIRD argument.
87
104
  */
88
105
  put<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
89
106
 
90
107
  /**
91
- * Makes a PATCH request.
108
+ * Makes a PATCH request. `data` is the request BODY (second argument) — never `{ data: body }`,
109
+ * which sends `{"data":body}`; a config is the THIRD argument.
92
110
  */
93
111
  patch<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
94
112
 
@@ -229,7 +247,11 @@ interface RequestConfig {
229
247
  signal?: AbortSignal
230
248
 
231
249
  /**
232
- * Request body data.
250
+ * Request body data, as a field of THIS config object — the `request({ method, url, data })`
251
+ * form. The verb methods take the body as their SECOND argument: `post(url, data, config)`,
252
+ * `put(url, data, config)`, `patch(url, data, config)`. Never wrap it there as
253
+ * `{ data: body }`: that object is the body, so the wire sends `{"data":body}` and the API
254
+ * sees none of the fields at its top level.
233
255
  */
234
256
  data?: unknown
235
257
 
@@ -286,7 +308,7 @@ interface FullRequestConfig extends RequestConfig {
286
308
  url: string
287
309
 
288
310
  /**
289
- * Request body data.
311
+ * Request body data — a field of this config object, never a second argument here.
290
312
  */
291
313
  data?: unknown
292
314
  }
@@ -518,6 +540,12 @@ function setClient(client: HttpClient): void
518
540
  Retrieves the bonded HTTP client. If none is bonded, automatically
519
541
  creates a default fetch-based client.
520
542
 
543
+ The fallback has NO `baseURL` — a core cannot know an app's API prefix. A relative
544
+ call then resolves against the page origin, where a dev server answers its own HTML
545
+ shell with a 200. It warns once so the misconfiguration is named instead of showing up
546
+ as a crash three components later; a scaffold bonds the shared client with its API
547
+ prefix, so the fallback only runs in an app that never bonded one.
548
+
521
549
  ```typescript
522
550
  function getClient(): HttpClient
523
551
  ```
@@ -541,13 +569,17 @@ function get(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
541
569
 
542
570
  Makes a POST request using the bonded HTTP client.
543
571
 
572
+ The body is `data` — the SECOND argument. `post(url, { data: body })` sends the JSON body
573
+ `{"data":body}`, not `body`, so the API finds none of its fields at the top level; pass the
574
+ body directly (`post('/users', { user })`). The config is the THIRD argument.
575
+
544
576
  ```typescript
545
577
  function post(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
546
578
  ```
547
579
 
548
580
  - `url` — The request URL.
549
- - `data` — The request body.
550
- - `config` — Optional request configuration.
581
+ - `data` — The request body itself (never `{ data: body }`).
582
+ - `config` — Optional request configuration (headers, params, timeout).
551
583
 
552
584
  **Returns:** The HTTP response with typed data.
553
585
 
@@ -559,9 +591,9 @@ Makes a PUT request using the bonded HTTP client.
559
591
  function put(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
560
592
  ```
561
593
 
562
- - `url` — The request URL.
563
- - `data` — The request body.
564
- - `config` — Optional request configuration.
594
+ - `url` — The request URL. The body is `data` — the SECOND argument, never `{ data: body }`.
595
+ - `data` — The request body itself.
596
+ - `config` — Optional request configuration (the third argument).
565
597
 
566
598
  **Returns:** The HTTP response with typed data.
567
599
 
@@ -573,9 +605,9 @@ Makes a PATCH request using the bonded HTTP client.
573
605
  function patch(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
574
606
  ```
575
607
 
576
- - `url` — The request URL.
577
- - `data` — The request body (partial update).
578
- - `config` — Optional request configuration.
608
+ - `url` — The request URL. The body is `data` — the SECOND argument, never `{ data: body }`.
609
+ - `data` — The request body itself (the partial update).
610
+ - `config` — Optional request configuration (the third argument).
579
611
 
580
612
  **Returns:** The HTTP response with typed data.
581
613
 
@@ -633,11 +665,16 @@ interceptors. Do NOT call `fetch()` / `axios` directly in components — that by
633
665
 
634
666
  Two mistakes that break in preview/production (seen in real imported apps):
635
667
 
636
- - **Pass RELATIVE paths; never a hardcoded host.** Use `'/plants'` (the `baseURL` `'/api'`
637
- is prepended), NOT `'/api/plants'`, and NEVER an absolute dev URL like
638
- `'http://localhost:4000/api/…'`. A hardcoded `localhost`/host works on the author's
639
- machine, then fails cross-origin (CORS) in the preview and points at the wrong server in
640
- production. The base URL is configured ONCE (via `setClient`), not per call.
668
+ - **Pass RELATIVE paths; never a hardcoded host.** Use `'/plants'` (the BONDED client's
669
+ `baseURL` — `'/api'` in a scaffold — is prepended), NOT `'/api/plants'`, and NEVER an
670
+ absolute dev URL like `'http://localhost:4000/api/…'`. A hardcoded `localhost`/host works on
671
+ the author's machine, then fails cross-origin (CORS) in the preview and points at the wrong
672
+ server in production. The base URL is configured ONCE (via `setClient`), not per call.
673
+ - **`getClient()` itself knows no baseURL.** The fallback client it mints when nothing is
674
+ bonded has `baseURL: ''`, so `getClient().get('/articles')` requests the PAGE origin — in
675
+ dev the Vite server answers its own `index.html` with a 200, and the HTML arrives as
676
+ `data` (xr-molecule-flash-m126 lost 6.5 minutes to that). A scaffold bonds
677
+ `'/api'`; an app that builds its own client must pass `{ baseURL }`.
641
678
  - **The client is PUBLIC — never put a secret in it.** Anything the browser sends (an API
642
679
  key, a service-role / `sk_…` key, a signing secret) is visible to every user. Secrets
643
680
  stay in YOUR API; the browser calls your API and the API uses the secret server-side.
package/dist/client.d.ts CHANGED
@@ -22,7 +22,8 @@ export interface HttpClient {
22
22
  */
23
23
  defaultHeaders: Record<string, string>;
24
24
  /**
25
- * Makes a generic HTTP request.
25
+ * Makes a generic HTTP request. `data` is a field of THIS config object — the same body
26
+ * `post(url, data, config)` takes as its second argument.
26
27
  */
27
28
  request<T = unknown>(config: FullRequestConfig): Promise<HttpResponse<T>>;
28
29
  /**
@@ -30,15 +31,19 @@ export interface HttpClient {
30
31
  */
31
32
  get<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
32
33
  /**
33
- * Makes a POST request.
34
+ * Makes a POST request. `data` is the request BODY, not a config object: the wire body is
35
+ * `data` itself, so `post(url, { data: body })` sends `{"data":body}` — pass `body` directly.
36
+ * A config (headers, params) is the THIRD argument.
34
37
  */
35
38
  post<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>;
36
39
  /**
37
- * Makes a PUT request.
40
+ * Makes a PUT request. `data` is the request BODY (second argument) — never `{ data: body }`,
41
+ * which sends `{"data":body}`; a config is the THIRD argument.
38
42
  */
39
43
  put<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>;
40
44
  /**
41
- * Makes a PATCH request.
45
+ * Makes a PATCH request. `data` is the request BODY (second argument) — never `{ data: body }`,
46
+ * which sends `{"data":body}`; a config is the THIRD argument.
42
47
  */
43
48
  patch<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>;
44
49
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"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IACH,sBAAsB,CAAC,WAAW,EAAE,mBAAmB,GAAG,MAAM,IAAI,CAAA;IAEpE;;;OAGG;IACH,mBAAmB,CAAC,WAAW,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAAA;IAE9D;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAExC;;OAEG;IACH,YAAY,IAAI,MAAM,GAAG,IAAI,CAAA;IAE7B;;;;OAIG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEvC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,16 @@
4
4
  * Provides a unified HTTP client API that works across different
5
5
  * HTTP libraries (fetch, axios, ky, etc.).
6
6
  *
7
+ * **The body is the SECOND argument: `post(url, data, config?)` — likewise `put` and `patch`,
8
+ * and the response is `HttpResponse<T>` (read `.data` for the body).** `data` IS the request
9
+ * body; a plain object is serialized as the JSON body. Passing `{ data: body }` there is NOT a
10
+ * config object — it makes the wire body `{"data":{…}}`, so the API sees an object whose only
11
+ * key is `data`, finds none of the fields it validates, and answers
12
+ * `422 {"errors":{"username":["can't be blank"],…}}`. Write `post('/users', { user })`, never
13
+ * `post('/users', { data: { user } })`. The config object (headers, params, timeout,
14
+ * `skipAuthGate`) is the THIRD argument. Only `request({ method, url, data, … })` takes `data`
15
+ * inside an options object, because there that object IS the config.
16
+ *
7
17
  * @example
8
18
  * ```tsx
9
19
  * // In a React component, get the configured client from context and call it.
@@ -14,10 +24,13 @@
14
24
  * function Plants() {
15
25
  * const http = useHttpClient()
16
26
  * const load = async () => {
17
- * const res = await http.get<Plant[]>('/plants') // baseURL ('/api') is prepended
27
+ * const res = await http.get<Plant[]>('/plants') // the bonded client's baseURL ('/api') is prepended
18
28
  * setPlants(res.data)
19
29
  * }
20
- * // http.post(url, body), http.put, http.delete are also available.
30
+ * // Body-carrying verbs take the body as the SECOND argument:
31
+ * // http.post('/plants', plant) — wire body is `plant`
32
+ * // http.post('/plants', { data: plant }) — WRONG: wire body is `{"data": plant}`
33
+ * // http.put(url, body), http.patch(url, body) and http.delete(url) are also available.
21
34
  * }
22
35
  * ```
23
36
  *
@@ -28,11 +41,16 @@
28
41
  * + base-URL config and breaks when the transport is swapped.
29
42
  *
30
43
  * Two mistakes that break in preview/production (seen in real imported apps):
31
- * - **Pass RELATIVE paths; never a hardcoded host.** Use `'/plants'` (the `baseURL` `'/api'`
32
- * is prepended), NOT `'/api/plants'`, and NEVER an absolute dev URL like
33
- * `'http://localhost:4000/api/…'`. A hardcoded `localhost`/host works on the author's
34
- * machine, then fails cross-origin (CORS) in the preview and points at the wrong server in
35
- * production. The base URL is configured ONCE (via `setClient`), not per call.
44
+ * - **Pass RELATIVE paths; never a hardcoded host.** Use `'/plants'` (the BONDED client's
45
+ * `baseURL` — `'/api'` in a scaffold — is prepended), NOT `'/api/plants'`, and NEVER an
46
+ * absolute dev URL like `'http://localhost:4000/api/…'`. A hardcoded `localhost`/host works on
47
+ * the author's machine, then fails cross-origin (CORS) in the preview and points at the wrong
48
+ * server in production. The base URL is configured ONCE (via `setClient`), not per call.
49
+ * - **`getClient()` itself knows no baseURL.** The fallback client it mints when nothing is
50
+ * bonded has `baseURL: ''`, so `getClient().get('/articles')` requests the PAGE origin — in
51
+ * dev the Vite server answers its own `index.html` with a 200, and the HTML arrives as
52
+ * `data` (xr-molecule-flash-m126 lost 6.5 minutes to that). A scaffold bonds
53
+ * `'/api'`; an app that builds its own client must pass `{ baseURL }`.
36
54
  * - **The client is PUBLIC — never put a secret in it.** Anything the browser sends (an API
37
55
  * key, a service-role / `sk_…` key, a signing secret) is visible to every user. Secrets
38
56
  * stay in YOUR API; the browser calls your API and the API uses the secret server-side.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
package/dist/index.js CHANGED
@@ -4,6 +4,16 @@
4
4
  * Provides a unified HTTP client API that works across different
5
5
  * HTTP libraries (fetch, axios, ky, etc.).
6
6
  *
7
+ * **The body is the SECOND argument: `post(url, data, config?)` — likewise `put` and `patch`,
8
+ * and the response is `HttpResponse<T>` (read `.data` for the body).** `data` IS the request
9
+ * body; a plain object is serialized as the JSON body. Passing `{ data: body }` there is NOT a
10
+ * config object — it makes the wire body `{"data":{…}}`, so the API sees an object whose only
11
+ * key is `data`, finds none of the fields it validates, and answers
12
+ * `422 {"errors":{"username":["can't be blank"],…}}`. Write `post('/users', { user })`, never
13
+ * `post('/users', { data: { user } })`. The config object (headers, params, timeout,
14
+ * `skipAuthGate`) is the THIRD argument. Only `request({ method, url, data, … })` takes `data`
15
+ * inside an options object, because there that object IS the config.
16
+ *
7
17
  * @example
8
18
  * ```tsx
9
19
  * // In a React component, get the configured client from context and call it.
@@ -14,10 +24,13 @@
14
24
  * function Plants() {
15
25
  * const http = useHttpClient()
16
26
  * const load = async () => {
17
- * const res = await http.get<Plant[]>('/plants') // baseURL ('/api') is prepended
27
+ * const res = await http.get<Plant[]>('/plants') // the bonded client's baseURL ('/api') is prepended
18
28
  * setPlants(res.data)
19
29
  * }
20
- * // http.post(url, body), http.put, http.delete are also available.
30
+ * // Body-carrying verbs take the body as the SECOND argument:
31
+ * // http.post('/plants', plant) — wire body is `plant`
32
+ * // http.post('/plants', { data: plant }) — WRONG: wire body is `{"data": plant}`
33
+ * // http.put(url, body), http.patch(url, body) and http.delete(url) are also available.
21
34
  * }
22
35
  * ```
23
36
  *
@@ -28,11 +41,16 @@
28
41
  * + base-URL config and breaks when the transport is swapped.
29
42
  *
30
43
  * Two mistakes that break in preview/production (seen in real imported apps):
31
- * - **Pass RELATIVE paths; never a hardcoded host.** Use `'/plants'` (the `baseURL` `'/api'`
32
- * is prepended), NOT `'/api/plants'`, and NEVER an absolute dev URL like
33
- * `'http://localhost:4000/api/…'`. A hardcoded `localhost`/host works on the author's
34
- * machine, then fails cross-origin (CORS) in the preview and points at the wrong server in
35
- * production. The base URL is configured ONCE (via `setClient`), not per call.
44
+ * - **Pass RELATIVE paths; never a hardcoded host.** Use `'/plants'` (the BONDED client's
45
+ * `baseURL` — `'/api'` in a scaffold — is prepended), NOT `'/api/plants'`, and NEVER an
46
+ * absolute dev URL like `'http://localhost:4000/api/…'`. A hardcoded `localhost`/host works on
47
+ * the author's machine, then fails cross-origin (CORS) in the preview and points at the wrong
48
+ * server in production. The base URL is configured ONCE (via `setClient`), not per call.
49
+ * - **`getClient()` itself knows no baseURL.** The fallback client it mints when nothing is
50
+ * bonded has `baseURL: ''`, so `getClient().get('/articles')` requests the PAGE origin — in
51
+ * dev the Vite server answers its own `index.html` with a 200, and the HTML arrives as
52
+ * `data` (xr-molecule-flash-m126 lost 6.5 minutes to that). A scaffold bonds
53
+ * `'/api'`; an app that builds its own client must pass `{ baseURL }`.
36
54
  * - **The client is PUBLIC — never put a secret in it.** Anything the browser sends (an API
37
55
  * key, a service-role / `sk_…` key, a signing secret) is visible to every user. Secrets
38
56
  * stay in YOUR API; the browser calls your API and the API uses the secret server-side.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAK/D;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAQ,gBAAqB,KAAG,UA+VjE,CAAA"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAQ/D;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAQ,gBAAqB,KAAG,UAwXjE,CAAA"}
package/dist/provider.js CHANGED
@@ -9,6 +9,8 @@ import { t } from '@molecule/app-i18n';
9
9
  import { getLogger } from '@molecule/app-logger';
10
10
  import { awaitAuthGate } from './auth-gate.js';
11
11
  import { HttpError } from './types.js';
12
+ /** A response whose body is an HTML document, not JSON. */
13
+ const HTML_CONTENT_TYPE = /^text\/html\b/i;
12
14
  /**
13
15
  * Creates a fetch-based HTTP client using the native Fetch API.
14
16
  *
@@ -159,6 +161,25 @@ export const createFetchClient = (config = {}) => {
159
161
  // Safe to ignore: the raw text is already captured above and used
160
162
  // as the fallback value. Non-JSON responses (plain text, HTML errors)
161
163
  // are a known valid case for some APIs.
164
+ //
165
+ // A 2xx HTML DOCUMENT is not one of those cases: it is the app's page
166
+ // server answering a request that expected JSON — the Vite dev server's
167
+ // SPA fallback when a relative URL had no API baseURL. Resolving with the
168
+ // HTML as `data` turns that into a `Cannot read properties of undefined`
169
+ // crash far from the call (xr-molecule-flash-m126: 6.5 minutes and 22
170
+ // probe scripts to discover `getClient().baseURL` was `''`).
171
+ const contentType = fetchResponse.headers.get('content-type') ?? '';
172
+ if (fetchResponse.ok && HTML_CONTENT_TYPE.test(contentType)) {
173
+ throw new HttpError(`${finalConfig.method} ${url} answered ${contentType.split(';')[0]} instead of ` +
174
+ "JSON — the request reached the page server, not the API; check the client's " +
175
+ 'baseURL (a relative path with no baseURL resolves against the page origin)', fetchResponse.status, {
176
+ data: text,
177
+ status: fetchResponse.status,
178
+ statusText: fetchResponse.statusText,
179
+ headers: responseHeaders,
180
+ config: finalConfig,
181
+ }, finalConfig, 'http.error.requestFailed');
182
+ }
162
183
  logger.debug('Response is not JSON, using raw text', url);
163
184
  data = text;
164
185
  }
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAI9C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAA2B,EAAE,EAAc,EAAE;IAC7E,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;IAChC,IAAI,SAAS,GAAkB,IAAI,CAAA;IACnC,MAAM,mBAAmB,GAAyB,EAAE,CAAA;IACpD,MAAM,oBAAoB,GAA0B,EAAE,CAAA;IACtD,MAAM,iBAAiB,GAAuB,EAAE,CAAA;IAChD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAc,CAAA;IAE/C,kEAAkE;IAClE,0DAA0D;IAC1D,kEAAkE;IAClE,uEAAuE;IACvE,oEAAoE;IACpE,2CAA2C;IAC3C,IAAI,oBAAoB,GAAG,KAAK,CAAA;IAChC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;QACnF,MAAM,OAAO,GAAG,GAAS,EAAE;YACzB,oBAAoB,GAAG,IAAI,CAAA;YAC3B,gEAAgE;YAChE,8DAA8D;YAC9D,2DAA2D;YAC3D,UAAU,CAAC,GAAG,EAAE;gBACd,oBAAoB,GAAG,KAAK,CAAA;YAC9B,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BAAoB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBACvC,CAAC;YACH,CAAC,CAAA;QACH,CAAC;QAED,mBAAmB,CAAC,WAA6B;YAC/C,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACnC,OAAO,GAAG,EAAE;gBACV,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;gBACpD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;oBACjB,iBAAiB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBACpC,CAAC;YACH,CAAC,CAAA;QACH,CAAC;QAED,YAAY,CAAC,KAAoB;YAC/B,SAAS,GAAG,KAAK,CAAA;QACnB,CAAC;QAED,YAAY;YACV,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,WAAW,CAAC,OAAmB;YAC7B,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YAC9B,OAAO,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAChD,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
package/dist/types.d.ts CHANGED
@@ -55,7 +55,11 @@ export interface RequestConfig {
55
55
  */
56
56
  signal?: AbortSignal;
57
57
  /**
58
- * Request body data.
58
+ * Request body data, as a field of THIS config object — the `request({ method, url, data })`
59
+ * form. The verb methods take the body as their SECOND argument: `post(url, data, config)`,
60
+ * `put(url, data, config)`, `patch(url, data, config)`. Never wrap it there as
61
+ * `{ data: body }`: that object is the body, so the wire sends `{"data":body}` and the API
62
+ * sees none of the fields at its top level.
59
63
  */
60
64
  data?: unknown;
61
65
  /**
@@ -99,7 +103,7 @@ export interface FullRequestConfig extends RequestConfig {
99
103
  */
100
104
  url: string;
101
105
  /**
102
- * Request body data.
106
+ * Request body data — a field of this config object, never a second argument here.
103
107
  */
104
108
  data?: unknown;
105
109
  }
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MAAM,EACd,QAAQ,CAAC,EAAE,YAAY,YAAA,EACvB,MAAM,CAAC,EAAE,iBAAiB,YAAA,EAC1B,QAAQ,CAAC,EAAE,MAAM,YAAA;CAK3B"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoJH;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAGzB;IACA;IACA;IACA;IALT,YACE,OAAe,EACR,MAAc,EACd,QAAuB,EACvB,MAA0B,EAC1B,QAAiB;QAExB,KAAK,CAAC,OAAO,CAAC,CAAA;QALP,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAe;QACvB,WAAM,GAAN,MAAM,CAAoB;QAC1B,aAAQ,GAAR,QAAQ,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;IACzB,CAAC;CACF"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwJH;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAGzB;IACA;IACA;IACA;IALT,YACE,OAAe,EACR,MAAc,EACd,QAAuB,EACvB,MAA0B,EAC1B,QAAiB;QAExB,KAAK,CAAC,OAAO,CAAC,CAAA;QALP,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAe;QACvB,WAAM,GAAN,MAAM,CAAoB;QAC1B,aAAQ,GAAR,QAAQ,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;IACzB,CAAC;CACF"}
@@ -25,6 +25,12 @@ export declare const setClient: (client: HttpClient) => void;
25
25
  * Retrieves the bonded HTTP client. If none is bonded, automatically
26
26
  * creates a default fetch-based client.
27
27
  *
28
+ * The fallback has NO `baseURL` — a core cannot know an app's API prefix. A relative
29
+ * call then resolves against the page origin, where a dev server answers its own HTML
30
+ * shell with a 200. It warns once so the misconfiguration is named instead of showing up
31
+ * as a crash three components later; a scaffold bonds the shared client with its API
32
+ * prefix, so the fallback only runs in an app that never bonded one.
33
+ *
28
34
  * @returns The active HTTP client instance.
29
35
  */
30
36
  export declare const getClient: () => HttpClient;
@@ -39,9 +45,13 @@ export declare const get: <T = unknown>(url: string, config?: RequestConfig) =>
39
45
  /**
40
46
  * Makes a POST request using the bonded HTTP client.
41
47
  *
48
+ * The body is `data` — the SECOND argument. `post(url, { data: body })` sends the JSON body
49
+ * `{"data":body}`, not `body`, so the API finds none of its fields at the top level; pass the
50
+ * body directly (`post('/users', { user })`). The config is the THIRD argument.
51
+ *
42
52
  * @param url - The request URL.
43
- * @param data - The request body.
44
- * @param config - Optional request configuration.
53
+ * @param data - The request body itself (never `{ data: body }`).
54
+ * @param config - Optional request configuration (headers, params, timeout).
45
55
  * @returns The HTTP response with typed data.
46
56
  */
47
57
  export declare const post: <T = unknown>(url: string, data?: unknown, config?: RequestConfig) => Promise<HttpResponse<T>>;
@@ -49,8 +59,10 @@ export declare const post: <T = unknown>(url: string, data?: unknown, config?: R
49
59
  * Makes a PUT request using the bonded HTTP client.
50
60
  *
51
61
  * @param url - The request URL.
52
- * @param data - The request body.
53
- * @param config - Optional request configuration.
62
+ * The body is `data` — the SECOND argument, never `{ data: body }`.
63
+ *
64
+ * @param data - The request body itself.
65
+ * @param config - Optional request configuration (the third argument).
54
66
  * @returns The HTTP response with typed data.
55
67
  */
56
68
  export declare const put: <T = unknown>(url: string, data?: unknown, config?: RequestConfig) => Promise<HttpResponse<T>>;
@@ -58,8 +70,10 @@ export declare const put: <T = unknown>(url: string, data?: unknown, config?: Re
58
70
  * Makes a PATCH request using the bonded HTTP client.
59
71
  *
60
72
  * @param url - The request URL.
61
- * @param data - The request body (partial update).
62
- * @param config - Optional request configuration.
73
+ * The body is `data` — the SECOND argument, never `{ data: body }`.
74
+ *
75
+ * @param data - The request body itself (the partial update).
76
+ * @param config - Optional request configuration (the third argument).
63
77
  * @returns The HTTP response with typed data.
64
78
  */
65
79
  export declare const patch: <T = unknown>(url: string, data?: unknown, config?: RequestConfig) => Promise<HttpResponse<T>>;
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAI7D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,KAAG,IAE9C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,QAAO,UAM5B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,GAAG,OAAO,EAAE,KAAK,MAAM,EAAE,SAAS,aAAa,KAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAC7D,CAAA;AAEjC;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,GAAG,OAAO,EAC9B,KAAK,MAAM,EACX,OAAO,OAAO,EACd,SAAS,aAAa,KACrB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAA2C,CAAA;AAErE;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,GAAG,OAAO,EAC7B,KAAK,MAAM,EACX,OAAO,OAAO,EACd,SAAS,aAAa,KACrB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAA0C,CAAA;AAEpE;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,GAAG,OAAO,EAC/B,KAAK,MAAM,EACX,OAAO,OAAO,EACd,SAAS,aAAa,KACrB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAA4C,CAAA;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,GAAG,OAAO,EAAE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G,GAAI,CAAC,GAAG,OAAO,EAAE,KAAK,MAAM,EAAE,SAAS,aAAa,KAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAC1D,CAAA;AAEpC;;;GAGG;AACH,eAAO,MAAM,WAAW,mBAA4D,CAAA"}
package/dist/utilities.js CHANGED
@@ -8,8 +8,11 @@
8
8
  * @module
9
9
  */
10
10
  import { bond, get as bondGet } from '@molecule/app-bond';
11
+ import { getLogger } from '@molecule/app-logger';
11
12
  import { createFetchClient } from './provider.js';
12
13
  const BOND_TYPE = 'http-client';
14
+ /** One warning per page load is enough to name a missing bond. */
15
+ let warnedAboutFallback = false;
13
16
  /**
14
17
  * Registers an HTTP client as the active singleton.
15
18
  *
@@ -28,6 +31,12 @@ export const setClient = (client) => {
28
31
  * Retrieves the bonded HTTP client. If none is bonded, automatically
29
32
  * creates a default fetch-based client.
30
33
  *
34
+ * The fallback has NO `baseURL` — a core cannot know an app's API prefix. A relative
35
+ * call then resolves against the page origin, where a dev server answers its own HTML
36
+ * shell with a 200. It warns once so the misconfiguration is named instead of showing up
37
+ * as a crash three components later; a scaffold bonds the shared client with its API
38
+ * prefix, so the fallback only runs in an app that never bonded one.
39
+ *
31
40
  * @returns The active HTTP client instance.
32
41
  */
33
42
  export const getClient = () => {
@@ -36,6 +45,11 @@ export const getClient = () => {
36
45
  return existing;
37
46
  const fallback = createFetchClient();
38
47
  bond(BOND_TYPE, fallback);
48
+ if (!warnedAboutFallback) {
49
+ warnedAboutFallback = true;
50
+ getLogger('http').warn('@molecule/app-http: no client is bonded — requests go to the page origin with no baseURL. ' +
51
+ "Bond one: setClient(createFetchClient({ baseURL: '/api' })).");
52
+ }
39
53
  return fallback;
40
54
  };
41
55
  /**
@@ -49,9 +63,13 @@ export const get = (url, config) => getClient().get(url, config);
49
63
  /**
50
64
  * Makes a POST request using the bonded HTTP client.
51
65
  *
66
+ * The body is `data` — the SECOND argument. `post(url, { data: body })` sends the JSON body
67
+ * `{"data":body}`, not `body`, so the API finds none of its fields at the top level; pass the
68
+ * body directly (`post('/users', { user })`). The config is the THIRD argument.
69
+ *
52
70
  * @param url - The request URL.
53
- * @param data - The request body.
54
- * @param config - Optional request configuration.
71
+ * @param data - The request body itself (never `{ data: body }`).
72
+ * @param config - Optional request configuration (headers, params, timeout).
55
73
  * @returns The HTTP response with typed data.
56
74
  */
57
75
  export const post = (url, data, config) => getClient().post(url, data, config);
@@ -59,8 +77,10 @@ export const post = (url, data, config) => getClient().post(url, data, config);
59
77
  * Makes a PUT request using the bonded HTTP client.
60
78
  *
61
79
  * @param url - The request URL.
62
- * @param data - The request body.
63
- * @param config - Optional request configuration.
80
+ * The body is `data` — the SECOND argument, never `{ data: body }`.
81
+ *
82
+ * @param data - The request body itself.
83
+ * @param config - Optional request configuration (the third argument).
64
84
  * @returns The HTTP response with typed data.
65
85
  */
66
86
  export const put = (url, data, config) => getClient().put(url, data, config);
@@ -68,8 +88,10 @@ export const put = (url, data, config) => getClient().put(url, data, config);
68
88
  * Makes a PATCH request using the bonded HTTP client.
69
89
  *
70
90
  * @param url - The request URL.
71
- * @param data - The request body (partial update).
72
- * @param config - Optional request configuration.
91
+ * The body is `data` — the SECOND argument, never `{ data: body }`.
92
+ *
93
+ * @param data - The request body itself (the partial update).
94
+ * @param config - Optional request configuration (the third argument).
73
95
  * @returns The HTTP response with typed data.
74
96
  */
75
97
  export const patch = (url, data, config) => getClient().patch(url, data, config);
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAGzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGjD,MAAM,SAAS,GAAG,aAAa,CAAA;AAE/B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAkB,EAAQ,EAAE;I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AAI,GAAG,EAAE,MAAM,CAAC,CAAA;AAEjC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,GAAW,EACX,IAAc,EACd,MAAsB,EACI,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,CAAI,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AAErE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,GAAW,EACX,IAAc,EACd,MAAsB,EACI,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,CAAI,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AAEpE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,GAAW,EACX,IAAc,EACd,MAAsB,EACI,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,CAAI,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AAEtE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAc,GAAW,EAAE,MAAsB,EAA4B,EAAE,CAChG,SAAS,EAAE,CAAC,MAAM,CAAI,GAAG,EAAE,MAAM,CAAC,CAAA;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-http",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Client HTTP interface for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",