@viniaraujo68/plinth 0.8.0 → 0.9.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/http.d.ts +2 -1
- package/dist/http.js +9 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/http.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* those belong to whatever the app already uses (TanStack Query, a `load` function, a plain
|
|
4
4
|
* `$effect`). What it does own is the part every hand-rolled client repeats — joining the base
|
|
5
5
|
* URL, sending and reading JSON, injecting auth, and turning a failed response into one typed
|
|
6
|
-
* error the whole app can catch.
|
|
6
|
+
* error the whole app can catch. A file or a form is the one body that is not JSON: it goes out as
|
|
7
|
+
* it is, so an upload shares the auth and the error handling instead of needing its own fetch.
|
|
7
8
|
*/
|
|
8
9
|
/** A failed HTTP response, after the body has been read and reduced to a message. */
|
|
9
10
|
export declare class ApiError extends Error {
|
package/dist/http.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* those belong to whatever the app already uses (TanStack Query, a `load` function, a plain
|
|
4
4
|
* `$effect`). What it does own is the part every hand-rolled client repeats — joining the base
|
|
5
5
|
* URL, sending and reading JSON, injecting auth, and turning a failed response into one typed
|
|
6
|
-
* error the whole app can catch.
|
|
6
|
+
* error the whole app can catch. A file or a form is the one body that is not JSON: it goes out as
|
|
7
|
+
* it is, so an upload shares the auth and the error handling instead of needing its own fetch.
|
|
7
8
|
*/
|
|
8
9
|
/** A failed HTTP response, after the body has been read and reduced to a message. */
|
|
9
10
|
export class ApiError extends Error {
|
|
@@ -22,6 +23,10 @@ const joinUrl = (baseUrl, path) => {
|
|
|
22
23
|
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
23
24
|
return path.startsWith("/") ? `${base}${path}` : `${base}/${path}`;
|
|
24
25
|
};
|
|
26
|
+
// `JSON.stringify` turns either into `{}`, so without this check an upload would silently send an
|
|
27
|
+
// empty object. Left to fetch, a blob declares its own type and a form gets its multipart boundary,
|
|
28
|
+
// which a hand-set `Content-Type` would lose.
|
|
29
|
+
const isRawBody = (body) => body instanceof Blob || body instanceof FormData;
|
|
25
30
|
const nonEmpty = (value) => {
|
|
26
31
|
const trimmed = value?.trim();
|
|
27
32
|
return trimmed === "" ? undefined : trimmed;
|
|
@@ -72,10 +77,11 @@ const extractCode = (body) => {
|
|
|
72
77
|
*/
|
|
73
78
|
export const createHttpClient = ({ baseUrl, credentials, auth, parseError, }) => {
|
|
74
79
|
const request = async (method, path, body, options = {}) => {
|
|
80
|
+
const raw = isRawBody(body);
|
|
75
81
|
const headers = {};
|
|
76
82
|
// GET and DELETE carry no body, and a `Content-Type` on them makes some CORS setups
|
|
77
83
|
// preflight a request that would otherwise be simple.
|
|
78
|
-
if (body !== undefined)
|
|
84
|
+
if (body !== undefined && !raw)
|
|
79
85
|
headers["Content-Type"] = "application/json";
|
|
80
86
|
if (auth) {
|
|
81
87
|
const token = await auth();
|
|
@@ -88,7 +94,7 @@ export const createHttpClient = ({ baseUrl, credentials, auth, parseError, }) =>
|
|
|
88
94
|
method,
|
|
89
95
|
headers,
|
|
90
96
|
credentials,
|
|
91
|
-
body: body === undefined ?
|
|
97
|
+
body: raw || body === undefined ? body : JSON.stringify(body),
|
|
92
98
|
signal: options.signal,
|
|
93
99
|
});
|
|
94
100
|
// Read as text first: 204 and most DELETEs answer with nothing at all, and `response.json()`
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* no portable way to import its own manifest, and a consumer that only wants to log a version
|
|
6
6
|
* should not have to bundle one. `version.spec.ts` fails when this drifts from the manifest.
|
|
7
7
|
*/
|
|
8
|
-
export declare const LIBRARY_VERSION = "0.
|
|
8
|
+
export declare const LIBRARY_VERSION = "0.9.0";
|
|
9
9
|
export { AsyncAction, type AsyncActionStatus, type AsyncFn } from "./async-action.svelte.js";
|
|
10
10
|
export { reportError, setErrorReporter, type ErrorReporter } from "./error.js";
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* no portable way to import its own manifest, and a consumer that only wants to log a version
|
|
6
6
|
* should not have to bundle one. `version.spec.ts` fails when this drifts from the manifest.
|
|
7
7
|
*/
|
|
8
|
-
export const LIBRARY_VERSION = "0.
|
|
8
|
+
export const LIBRARY_VERSION = "0.9.0";
|
|
9
9
|
// The root entry carries only what is not tied to one area: the error channel an app installs
|
|
10
10
|
// once, and the async state machine the components are built on. Everything visual is reached
|
|
11
11
|
// through a subpath — `/theme`, `/attachments`, `/components`, `/toast` — so importing a button
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viniaraujo68/plinth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A personal Svelte 5 design system: theme, application shell, interface primitives, routing metadata, a fetch wrapper and locale-aware formatters.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|