@memobit/libs 3.12.0 → 3.12.1
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/helpers/Http.js +57 -48
- package/dist/helpers/VersionInfo.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/version.js +2 -2
- package/dist/version.json +4 -4
- package/package.json +1 -1
package/dist/helpers/Http.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger as
|
|
2
|
-
var
|
|
1
|
+
import { logger as c } from "@memobit/core";
|
|
2
|
+
var u = {
|
|
3
3
|
Continue: 100,
|
|
4
4
|
SwitchingProtocols: 101,
|
|
5
5
|
Ok: 200,
|
|
@@ -39,21 +39,21 @@ var c = {
|
|
|
39
39
|
Put: "PUT",
|
|
40
40
|
Patch: "PATCH",
|
|
41
41
|
Delete: "DELETE"
|
|
42
|
-
},
|
|
43
|
-
const e = document.cookie.match(new RegExp(`(?:^|;\\s*)${
|
|
42
|
+
}, U = (e) => e >= 200 && e < 300, N = (e) => e >= 400 && e < 500, b = (e) => e >= 500 && e < 600, S = "csrf_token", y = "X-CSRF-Token", T = () => {
|
|
43
|
+
const e = document.cookie.match(new RegExp(`(?:^|;\\s*)${S}=([^;]+)`));
|
|
44
44
|
return e ? decodeURIComponent(e[1]) : null;
|
|
45
45
|
}, m = (e, t = !0) => {
|
|
46
46
|
const n = t ? { "Content-Type": "application/json" } : {};
|
|
47
47
|
if (e !== s.Get) {
|
|
48
|
-
const
|
|
49
|
-
|
|
48
|
+
const d = T();
|
|
49
|
+
d && (n[y] = d);
|
|
50
50
|
}
|
|
51
51
|
return n;
|
|
52
|
-
},
|
|
52
|
+
}, w = class extends Error {
|
|
53
53
|
constructor(e, t) {
|
|
54
54
|
super(e), this.name = "ApiError", this.status = t;
|
|
55
55
|
}
|
|
56
|
-
},
|
|
56
|
+
}, g = async (e) => {
|
|
57
57
|
try {
|
|
58
58
|
const t = await e.json();
|
|
59
59
|
if (t && typeof t == "object") {
|
|
@@ -63,68 +63,77 @@ var c = {
|
|
|
63
63
|
} catch {
|
|
64
64
|
}
|
|
65
65
|
return `Request failed (${e.status}${e.statusText ? ` ${e.statusText}` : ""})`;
|
|
66
|
-
},
|
|
67
|
-
t instanceof
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
}, v = (e) => e instanceof DOMException && e.name === "AbortError", A = /^(Failed to fetch|NetworkError when attempting to fetch resource\.?|Load failed)$/, P = (e) => e instanceof TypeError && A.test(e.message), G = (e, t, n) => {
|
|
67
|
+
if (!(t instanceof w || v(t))) {
|
|
68
|
+
if (P(t)) {
|
|
69
|
+
c.warn(e, {
|
|
70
|
+
...n,
|
|
71
|
+
error: String(t)
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
c.error(e, t, n);
|
|
76
|
+
}
|
|
77
|
+
}, C = /* @__PURE__ */ new Set([
|
|
78
|
+
u.BadGateway,
|
|
79
|
+
u.ServiceUnavailable,
|
|
80
|
+
u.GatewayTimeout
|
|
81
|
+
]), F = ({ baseUrl: e, loginPath: t = "/login" }) => {
|
|
73
82
|
let n = !1;
|
|
74
|
-
const
|
|
83
|
+
const d = (r) => `${e.replace(/\/$/, "")}/${r.replace(/^\//, "")}`, l = async (r, a, f, E = !0) => {
|
|
75
84
|
const h = {
|
|
76
|
-
method:
|
|
85
|
+
method: a,
|
|
77
86
|
path: r.split("?")[0]
|
|
78
87
|
};
|
|
79
|
-
let
|
|
88
|
+
let o;
|
|
80
89
|
try {
|
|
81
|
-
|
|
82
|
-
method:
|
|
83
|
-
headers: m(
|
|
90
|
+
o = await fetch(d(r), {
|
|
91
|
+
method: a,
|
|
92
|
+
headers: m(a, E),
|
|
84
93
|
credentials: "include",
|
|
85
|
-
body:
|
|
94
|
+
body: f
|
|
86
95
|
});
|
|
87
96
|
} catch (i) {
|
|
88
|
-
throw
|
|
97
|
+
throw v(i) ? i : (c.warn("API request could not reach the server", h), new w("Could not reach the server", 0));
|
|
89
98
|
}
|
|
90
|
-
if (
|
|
99
|
+
if (o.status === u.Unauthorized && !window.location.pathname.startsWith(t))
|
|
91
100
|
return n || (n = !0, window.location.href = `${t}?session_expired=true`), new Promise(() => {
|
|
92
101
|
});
|
|
93
|
-
if (!
|
|
94
|
-
throw
|
|
102
|
+
if (!o.ok)
|
|
103
|
+
throw C.has(o.status) && c.warn("API gateway failure", {
|
|
95
104
|
...h,
|
|
96
|
-
status:
|
|
97
|
-
}), new
|
|
98
|
-
if (
|
|
105
|
+
status: o.status
|
|
106
|
+
}), new w(await g(o), o.status);
|
|
107
|
+
if (o.status !== u.NoContent)
|
|
99
108
|
try {
|
|
100
|
-
return await
|
|
109
|
+
return await o.json();
|
|
101
110
|
} catch (i) {
|
|
102
|
-
throw
|
|
111
|
+
throw c.error("API response was not valid JSON", i, {
|
|
103
112
|
...h,
|
|
104
|
-
status:
|
|
113
|
+
status: o.status
|
|
105
114
|
}), i;
|
|
106
115
|
}
|
|
107
|
-
},
|
|
116
|
+
}, p = (r, a, f) => l(r, a, f === void 0 ? void 0 : JSON.stringify(f));
|
|
108
117
|
return {
|
|
109
|
-
get: (r) =>
|
|
110
|
-
post: (r,
|
|
111
|
-
put: (r,
|
|
112
|
-
patch: (r,
|
|
113
|
-
delete: (r) =>
|
|
114
|
-
upload: (r,
|
|
118
|
+
get: (r) => l(r, s.Get),
|
|
119
|
+
post: (r, a) => p(r, s.Post, a),
|
|
120
|
+
put: (r, a) => p(r, s.Put, a),
|
|
121
|
+
patch: (r, a) => p(r, s.Patch, a),
|
|
122
|
+
delete: (r) => l(r, s.Delete),
|
|
123
|
+
upload: (r, a) => l(r, s.Post, a, !1)
|
|
115
124
|
};
|
|
116
125
|
};
|
|
117
126
|
export {
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
w as ApiError,
|
|
128
|
+
y as CSRF_HEADER,
|
|
120
129
|
s as HttpMethod,
|
|
121
|
-
|
|
130
|
+
u as HttpStatus,
|
|
122
131
|
m as buildRequestHeaders,
|
|
123
|
-
|
|
132
|
+
F as createApiClient,
|
|
124
133
|
T as getCsrfToken,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
N as isClientErrorStatus,
|
|
135
|
+
b as isServerErrorStatus,
|
|
136
|
+
U as isSuccessStatus,
|
|
137
|
+
G as logUnexpectedError,
|
|
138
|
+
g as readErrorMessage
|
|
130
139
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2394,8 +2394,9 @@ export declare interface LoginResponse {
|
|
|
2394
2394
|
|
|
2395
2395
|
/**
|
|
2396
2396
|
* For the catch around an API call: reports `error` unless it is an `ApiError` (the client and
|
|
2397
|
-
* the backend already report those that matter) or an aborted request.
|
|
2398
|
-
* the code around the call, e.g.
|
|
2397
|
+
* the backend already report those that matter) or an aborted request. A bare fetch() that could
|
|
2398
|
+
* not reach the server is a warning. What is left is a bug in the code around the call, e.g.
|
|
2399
|
+
* mapping the response.
|
|
2399
2400
|
*/
|
|
2400
2401
|
export declare const logUnexpectedError: (message: string, error: unknown, context?: ErrorReportContext) => void;
|
|
2401
2402
|
|
package/dist/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var I = "3.12.
|
|
1
|
+
var I = "3.12.1", B = 517, L = "020f557", _ = "2026-10-17T06:11:23.897Z", r = "517";
|
|
2
2
|
export {
|
|
3
3
|
_ as LIB_BUILD_DATE,
|
|
4
|
-
|
|
4
|
+
r as LIB_BUILD_ID,
|
|
5
5
|
B as LIB_BUILD_NUMBER,
|
|
6
6
|
L as LIB_COMMIT,
|
|
7
7
|
I as LIB_VERSION
|
package/dist/version.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memobit/libs",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.1",
|
|
4
4
|
"description": "React component library powering the Memobit apps — 100+ components, helpers and hooks. Icons ship as @memobit/icons and themes as @memobit/themes. TypeScript-first, ESM-only, React 19.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|