@wtfalch/calendar 0.3.0 → 0.3.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/calendar/client.js +25 -1
- package/package.json +3 -3
package/dist/calendar/client.js
CHANGED
|
@@ -32,6 +32,30 @@ export const CORE_CAPABILITY = 'urn:ietf:params:jmap:core';
|
|
|
32
32
|
* ambient browser credentials keeps a refused token from popping the
|
|
33
33
|
* browser's native Basic-auth prompt over the application's own error. */
|
|
34
34
|
const NO_BROWSER_CREDENTIALS = { credentials: 'omit' };
|
|
35
|
+
/** Put an absolute URL from the session document onto `origin`, keeping its
|
|
36
|
+
* path, query and `{template}` parts byte for byte. A relative URL, or one
|
|
37
|
+
* already on `origin`, is returned as it came. */
|
|
38
|
+
function onOrigin(url, origin) {
|
|
39
|
+
const authority = /^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(url)?.[0];
|
|
40
|
+
return authority && authority !== origin ? origin + url.slice(authority.length) : url;
|
|
41
|
+
}
|
|
42
|
+
/** A server behind a proxy writes its own host into the session document.
|
|
43
|
+
* A browser that follows those URLs leaves the origin it fetched the session
|
|
44
|
+
* from, so every URL is moved back onto that origin. */
|
|
45
|
+
function keepOnOrigin(doc, sessionUrl) {
|
|
46
|
+
let origin;
|
|
47
|
+
try {
|
|
48
|
+
origin = new URL(sessionUrl).origin;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return doc;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...doc,
|
|
55
|
+
apiUrl: onOrigin(doc.apiUrl, origin),
|
|
56
|
+
eventSourceUrl: onOrigin(doc.eventSourceUrl, origin),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
35
59
|
function looksLikeSession(value) {
|
|
36
60
|
return (typeof value === 'object' &&
|
|
37
61
|
value !== null &&
|
|
@@ -116,7 +140,7 @@ export class CalendarConnection {
|
|
|
116
140
|
if (!looksLikeSession(parsed)) {
|
|
117
141
|
throw new CalendarError(`${this.#sessionUrl} did not answer with a JMAP session document (${response.status}): ${body.slice(0, 200)}`, { status: response.status, operation: 'client.connect' });
|
|
118
142
|
}
|
|
119
|
-
return parsed;
|
|
143
|
+
return keepOnOrigin(parsed, this.#sessionUrl);
|
|
120
144
|
}
|
|
121
145
|
/** The account id this connection reads and writes. */
|
|
122
146
|
async accountId() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtfalch/calendar",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A JMAP calendar client for Agora, the wtfalch communications app: events, invites, sharing and free/busy over Stalwart, and the React UI on react-big-calendar.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dev": "vite --config dev/vite.config.ts"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@wtfalch/design": "^0.
|
|
40
|
+
"@wtfalch/design": "^0.30.0",
|
|
41
41
|
"react": "^19.0.0",
|
|
42
42
|
"react-big-calendar": "^1.20.0",
|
|
43
43
|
"react-dom": "^19.0.0"
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@types/react-big-calendar": "^1.16.3",
|
|
63
63
|
"@types/react-dom": "^19",
|
|
64
64
|
"@vitejs/plugin-react": "^6.1.1",
|
|
65
|
-
"@wtfalch/design": "0.
|
|
65
|
+
"@wtfalch/design": "0.30.0",
|
|
66
66
|
"jsdom": "^30.0.1",
|
|
67
67
|
"react": "^19",
|
|
68
68
|
"react-big-calendar": "^1.20.0",
|