@noverax/courier-sveltekit 0.5.0 → 0.7.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/README.md +1 -1
- package/lib/handle.d.ts +1 -1
- package/lib/handle.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/plugin.d.ts +15 -0
- package/lib/{request-context-Cy7IqxdJ.js → request-context-BW9-Huf7.js} +24 -2
- package/lib/{request-context-C96e5HoI.d.ts → request-context-C62twKzM.d.ts} +16 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -202,7 +202,7 @@ import { requestContextHandle } from "@noverax/courier-sveltekit/handle"
|
|
|
202
202
|
export const handle = requestContextHandle()
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
-
The session cookies the API sets go to `cookies.set()` exactly as the API wrote them, a `load` function's included.
|
|
205
|
+
The session cookies the API sets go to `cookies.set()` exactly as the API wrote them, a `load` function's included, and each call sends the session cookies as `cookies` holds them when it is made, those your code set or deleted since included.
|
|
206
206
|
|
|
207
207
|
<br />
|
|
208
208
|
|
package/lib/handle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as SvelteKitServerEvent } from "./request-context-
|
|
1
|
+
import { t as SvelteKitServerEvent } from "./request-context-C62twKzM.js";
|
|
2
2
|
/** A SvelteKit `handle` hook, as far as it reads its input. */
|
|
3
3
|
export type RequestContextHandle = <TEvent extends SvelteKitServerEvent, TResponse>(input: {
|
|
4
4
|
event: TEvent;
|
package/lib/handle.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as svelteKitIncomingRequest, r as svelteKitRequestContext, t as SvelteKitServerEvent } from "./request-context-
|
|
1
|
+
import { n as svelteKitIncomingRequest, r as svelteKitRequestContext, t as SvelteKitServerEvent } from "./request-context-C62twKzM.js";
|
|
2
2
|
import { ClientConnection, ConnectResult, HandlerConfig } from "@noverax/courier/server";
|
|
3
3
|
/**
|
|
4
4
|
* The parts of SvelteKit's `RequestEvent` the handler reads. `platform.req`
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as svelteKitRequestContext, r as svelteKitClientAddress, t as svelteKitIncomingRequest } from "./request-context-
|
|
1
|
+
import { n as svelteKitRequestContext, r as svelteKitClientAddress, t as svelteKitIncomingRequest } from "./request-context-BW9-Huf7.js";
|
|
2
2
|
import { announceWhenRegistered } from "@noverax/courier/announce";
|
|
3
3
|
import { rememberPeerAddress, serverOriginOf } from "@noverax/courier/internal";
|
|
4
4
|
import { createHandler, handleWhileConnected } from "@noverax/courier/server";
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Vite plugin that builds a SvelteKit app's routes — what each page's
|
|
3
|
+
* proxy client may call — from `courier.config.ts`, for its pages and for
|
|
4
|
+
* the server that renders them. No routes file is written.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* // vite.config.ts
|
|
9
|
+
* import { sveltekit } from "@sveltejs/kit/vite";
|
|
10
|
+
* import { courierRoutes } from "@noverax/courier-sveltekit/plugin";
|
|
11
|
+
* import { defineConfig } from "vite";
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({ plugins: [sveltekit(), courierRoutes()] });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
1
16
|
import { CourierRoutesOptions, courierRoutes } from "@noverax/courier-build/vite";
|
|
2
17
|
export { type CourierRoutesOptions, courierRoutes };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardedChain } from "@noverax/courier/internal";
|
|
1
|
+
import { cookieHeaderAfter, forwardedChain } from "@noverax/courier/internal";
|
|
2
2
|
import { createLogger } from "@noverax/courier/server";
|
|
3
3
|
// src/client-address.ts
|
|
4
4
|
const log$1 = createLogger("SvelteKit");
|
|
@@ -63,7 +63,11 @@ function eventNow(getRequestEvent) {
|
|
|
63
63
|
* A SvelteKit request event, as the session reads it: its origin is the one
|
|
64
64
|
* SvelteKit addresses the app by, its user's address the one the adapter
|
|
65
65
|
* vouches for, and the cookies the API sets go to `cookies.set()` exactly
|
|
66
|
-
* as the API wrote them.
|
|
66
|
+
* as the API wrote them. Each call sends the request's cookies as `cookies`
|
|
67
|
+
* holds them when it is made: one the request's code set goes URL-encoded,
|
|
68
|
+
* as SvelteKit's own `encode` writes it — also when `cookies.set()` was
|
|
69
|
+
* given another, which `cookies` does not tell — one it deleted goes not,
|
|
70
|
+
* and each other goes byte for byte as the browser sent it.
|
|
67
71
|
*
|
|
68
72
|
* @param event - The request event
|
|
69
73
|
* @returns The request, as the session reads it
|
|
@@ -78,12 +82,30 @@ function svelteKitIncomingRequest(event) {
|
|
|
78
82
|
method: event.request.method,
|
|
79
83
|
origin: event.url.origin,
|
|
80
84
|
headers: event.request.headers,
|
|
85
|
+
cookieHeader: () => cookiesHeld(event),
|
|
81
86
|
get clientAddress() {
|
|
82
87
|
return forwardedChain(svelteKitClientAddress(event), event.request.headers.get("x-forwarded-for"));
|
|
83
88
|
},
|
|
84
89
|
setCookie: (relayed) => setCookieIn(event, relayed)
|
|
85
90
|
};
|
|
86
91
|
}
|
|
92
|
+
function cookiesHeld(event) {
|
|
93
|
+
const sent = event.request.headers.get("cookie") ?? "";
|
|
94
|
+
const read = new Map(event.cookies.getAll({ decode: () => "0" }).map(({ name, value }) => [name, value]));
|
|
95
|
+
const changed = [];
|
|
96
|
+
for (const { name, value } of event.cookies.getAll({ decode: () => "1" })) {
|
|
97
|
+
if (read.get(name) !== value) continue;
|
|
98
|
+
changed.push(value === "" ? {
|
|
99
|
+
name,
|
|
100
|
+
value,
|
|
101
|
+
maxAge: 0
|
|
102
|
+
} : {
|
|
103
|
+
name,
|
|
104
|
+
value: encodeURIComponent(value)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return changed.length === 0 ? sent : cookieHeaderAfter(sent, changed);
|
|
108
|
+
}
|
|
87
109
|
function setCookieIn(event, { cookie }) {
|
|
88
110
|
try {
|
|
89
111
|
event.cookies.set(cookie.name, cookie.value, optionsOf(cookie));
|
|
@@ -12,13 +12,21 @@ interface SvelteKitCookieOptions {
|
|
|
12
12
|
priority?: "low" | "medium" | "high";
|
|
13
13
|
encode: (value: string) => string;
|
|
14
14
|
}
|
|
15
|
+
/** The parts of SvelteKit's `cookies` the session uses. */
|
|
16
|
+
interface SvelteKitCookies {
|
|
17
|
+
getAll(options: {
|
|
18
|
+
decode(value: string): string;
|
|
19
|
+
}): Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
value: string;
|
|
22
|
+
}>;
|
|
23
|
+
set(name: string, value: string, options: SvelteKitCookieOptions): void;
|
|
24
|
+
}
|
|
15
25
|
/** The parts of SvelteKit's `RequestEvent` the session reads. */
|
|
16
26
|
interface SvelteKitServerEvent {
|
|
17
27
|
request: Request;
|
|
18
28
|
url: URL;
|
|
19
|
-
cookies:
|
|
20
|
-
set(name: string, value: string, options: SvelteKitCookieOptions): void;
|
|
21
|
-
};
|
|
29
|
+
cookies: SvelteKitCookies;
|
|
22
30
|
getClientAddress(): string;
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
@@ -44,7 +52,11 @@ declare function svelteKitRequestContext(getRequestEvent: () => SvelteKitServerE
|
|
|
44
52
|
* A SvelteKit request event, as the session reads it: its origin is the one
|
|
45
53
|
* SvelteKit addresses the app by, its user's address the one the adapter
|
|
46
54
|
* vouches for, and the cookies the API sets go to `cookies.set()` exactly
|
|
47
|
-
* as the API wrote them.
|
|
55
|
+
* as the API wrote them. Each call sends the request's cookies as `cookies`
|
|
56
|
+
* holds them when it is made: one the request's code set goes URL-encoded,
|
|
57
|
+
* as SvelteKit's own `encode` writes it — also when `cookies.set()` was
|
|
58
|
+
* given another, which `cookies` does not tell — one it deleted goes not,
|
|
59
|
+
* and each other goes byte for byte as the browser sent it.
|
|
48
60
|
*
|
|
49
61
|
* @param event - The request event
|
|
50
62
|
* @returns The request, as the session reads it
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noverax/courier-sveltekit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "SvelteKit adapter for Courier: an endpoint that proxies typed calls to any backend, with the user's session in load functions and form actions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"courier",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"access": "public"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"@noverax/courier": "^0.
|
|
84
|
-
"@noverax/courier-build": "^0.
|
|
83
|
+
"@noverax/courier": "^0.7.0",
|
|
84
|
+
"@noverax/courier-build": "^0.7.0",
|
|
85
85
|
"vite": ">=5.0.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependenciesMeta": {
|