@krantho/server-sveltekit 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/page-cache.d.ts +43 -0
- package/dist/page-cache.d.ts.map +1 -0
- package/dist/page-cache.js +35 -0
- package/dist/page-cache.js.map +1 -0
- package/package.json +44 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Descoped
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { KranthoHandlerOptions } from '@krantho/server';
|
|
2
|
+
export type { PageRequestOptions, PageRequestResult } from '@krantho/server';
|
|
3
|
+
export { createContentLoader, runPageRequest, verifyPreviewRequest } from '@krantho/server';
|
|
4
|
+
export { createPageCacheHandle } from './page-cache.js';
|
|
5
|
+
export type { KranthoHandlerOptions };
|
|
6
|
+
/**
|
|
7
|
+
* Minimal RequestEvent shape — matches SvelteKit's RequestEvent
|
|
8
|
+
* without requiring @sveltejs/kit as a build dependency.
|
|
9
|
+
*/
|
|
10
|
+
interface RequestEvent {
|
|
11
|
+
request: Request;
|
|
12
|
+
}
|
|
13
|
+
type SvelteKitHandler = (event: RequestEvent) => Promise<Response>;
|
|
14
|
+
interface ApiHandlers {
|
|
15
|
+
GET: SvelteKitHandler;
|
|
16
|
+
POST: SvelteKitHandler;
|
|
17
|
+
PUT: SvelteKitHandler;
|
|
18
|
+
DELETE: SvelteKitHandler;
|
|
19
|
+
PATCH: SvelteKitHandler;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create SvelteKit endpoint handlers from krantho config.
|
|
23
|
+
*
|
|
24
|
+
* Returns { GET, POST, PUT, DELETE, PATCH } matching the export convention
|
|
25
|
+
* for `src/routes/api/[...path]/+server.ts`.
|
|
26
|
+
*
|
|
27
|
+
* Each handler extracts `event.request` and delegates to the krantho handler.
|
|
28
|
+
* The handler is initialized lazily on first request and reused (singleton).
|
|
29
|
+
*/
|
|
30
|
+
export declare function createApiHandlers(options: KranthoHandlerOptions): ApiHandlers;
|
|
31
|
+
/**
|
|
32
|
+
* Create a SvelteKit Studio route handler.
|
|
33
|
+
*
|
|
34
|
+
* Serves the @krantho/studio built SPA from the package's dist directory.
|
|
35
|
+
* Pass the app's configuration to apply `auth.oidc.studioEntry`.
|
|
36
|
+
* Use in `src/routes/studio/[...path]/+server.ts`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createStudioHandler(options?: {
|
|
39
|
+
config?: KranthoHandlerOptions['config'];
|
|
40
|
+
}): {
|
|
41
|
+
GET: SvelteKitHandler;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAG5D,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC3F,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,YAAY,EAAE,qBAAqB,EAAE,CAAA;AAErC;;;GAGG;AACH,UAAU,YAAY;IACpB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,KAAK,gBAAgB,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAElE,UAAU,WAAW;IACnB,GAAG,EAAE,gBAAgB,CAAA;IACrB,IAAI,EAAE,gBAAgB,CAAA;IACtB,GAAG,EAAE,gBAAgB,CAAA;IACrB,MAAM,EAAE,gBAAgB,CAAA;IACxB,KAAK,EAAE,gBAAgB,CAAA;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,WAAW,CAe7E;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,qBAAqB,CAAC,QAAQ,CAAC,CAAA;CAAO,GAAG;IAC/F,GAAG,EAAE,gBAAgB,CAAA;CACtB,CAWA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createLazyHandler, createStudioServer } from '@krantho/server';
|
|
2
|
+
export { createContentLoader, runPageRequest, verifyPreviewRequest } from '@krantho/server';
|
|
3
|
+
export { createPageCacheHandle } from './page-cache.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create SvelteKit endpoint handlers from krantho config.
|
|
6
|
+
*
|
|
7
|
+
* Returns { GET, POST, PUT, DELETE, PATCH } matching the export convention
|
|
8
|
+
* for `src/routes/api/[...path]/+server.ts`.
|
|
9
|
+
*
|
|
10
|
+
* Each handler extracts `event.request` and delegates to the krantho handler.
|
|
11
|
+
* The handler is initialized lazily on first request and reused (singleton).
|
|
12
|
+
*/
|
|
13
|
+
export function createApiHandlers(options) {
|
|
14
|
+
const getHandler = createLazyHandler({ ...options, framework: 'sveltekit' });
|
|
15
|
+
async function handle(event) {
|
|
16
|
+
const handler = await getHandler();
|
|
17
|
+
return handler.handle(event.request);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
GET: handle,
|
|
21
|
+
POST: handle,
|
|
22
|
+
PUT: handle,
|
|
23
|
+
DELETE: handle,
|
|
24
|
+
PATCH: handle,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a SvelteKit Studio route handler.
|
|
29
|
+
*
|
|
30
|
+
* Serves the @krantho/studio built SPA from the package's dist directory.
|
|
31
|
+
* Pass the app's configuration to apply `auth.oidc.studioEntry`.
|
|
32
|
+
* Use in `src/routes/studio/[...path]/+server.ts`.
|
|
33
|
+
*/
|
|
34
|
+
export function createStudioHandler(options = {}) {
|
|
35
|
+
const serve = createStudioServer(options.config);
|
|
36
|
+
return {
|
|
37
|
+
async GET(event) {
|
|
38
|
+
const { request } = event;
|
|
39
|
+
return serve({
|
|
40
|
+
url: new URL(request.url),
|
|
41
|
+
cookie: request.headers.get('cookie') ?? undefined,
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 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1
|
+
import type { KranthoHandlerOptions } from '@krantho/server';
|
|
2
|
+
/**
|
|
3
|
+
* The part of SvelteKit's RequestEvent the page cache reads, without
|
|
4
|
+
* requiring @sveltejs/kit as a build dependency. `url` is the page's URL —
|
|
5
|
+
* for a `__data.json` request SvelteKit strips the suffix, so a preview token
|
|
6
|
+
* signed for the page verifies on its data request too.
|
|
7
|
+
*/
|
|
8
|
+
interface PageCacheEvent {
|
|
9
|
+
url: URL;
|
|
10
|
+
request: Request;
|
|
11
|
+
}
|
|
12
|
+
/** SvelteKit's `handle` hook input, generic so the hook assigns to `Handle` */
|
|
13
|
+
interface PageCacheHandleInput<E extends PageCacheEvent> {
|
|
14
|
+
event: E;
|
|
15
|
+
resolve: (event: E) => Response | Promise<Response>;
|
|
16
|
+
}
|
|
17
|
+
type PageCacheHandle = <E extends PageCacheEvent>(input: PageCacheHandleInput<E>) => Promise<Response>;
|
|
18
|
+
/**
|
|
19
|
+
* A SvelteKit `handle` hook that serves pages under the page cache rules.
|
|
20
|
+
*
|
|
21
|
+
* Every `GET` and `HEAD` outside `/api` and `/studio` — `__data.json` requests
|
|
22
|
+
* included — renders inside a page request scope, so the content loader
|
|
23
|
+
* records its tags. A verified signed preview link reads drafts and answers
|
|
24
|
+
* `private, no-store`, `noindex`, with no referrer. Under `cache.pages: 'cdn'`
|
|
25
|
+
* a published `200` or `404` that sets no cookie is cached at the CDN, tagged
|
|
26
|
+
* with every read that rendered it — unless its own `Cache-Control` says
|
|
27
|
+
* `private`, `no-store` or `no-cache`, which is then left as it is.
|
|
28
|
+
*
|
|
29
|
+
* Start every read inside a `load` (or the page itself), never in another
|
|
30
|
+
* hook: a read made before `resolve`, or streamed after it returns, records no
|
|
31
|
+
* tags. Never read `loader.preview` in a hook — that puts a draft into a page
|
|
32
|
+
* the CDN caches.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* // src/hooks.server.ts
|
|
36
|
+
* export const handle = createPageCacheHandle({ config })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function createPageCacheHandle(options: {
|
|
40
|
+
config: KranthoHandlerOptions['config'];
|
|
41
|
+
}): PageCacheHandle;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=page-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-cache.d.ts","sourceRoot":"","sources":["../src/page-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAG5D;;;;;GAKG;AACH,UAAU,cAAc;IACtB,GAAG,EAAE,GAAG,CAAA;IACR,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,+EAA+E;AAC/E,UAAU,oBAAoB,CAAC,CAAC,SAAS,cAAc;IACrD,KAAK,EAAE,CAAC,CAAA;IACR,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CACpD;AAED,KAAK,eAAe,GAAG,CAAC,CAAC,SAAS,cAAc,EAC9C,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAC3B,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,MAAM,EAAE,qBAAqB,CAAC,QAAQ,CAAC,CAAA;CACxC,GAAG,eAAe,CAclB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { servePageRequest } from '@krantho/server';
|
|
2
|
+
/**
|
|
3
|
+
* A SvelteKit `handle` hook that serves pages under the page cache rules.
|
|
4
|
+
*
|
|
5
|
+
* Every `GET` and `HEAD` outside `/api` and `/studio` — `__data.json` requests
|
|
6
|
+
* included — renders inside a page request scope, so the content loader
|
|
7
|
+
* records its tags. A verified signed preview link reads drafts and answers
|
|
8
|
+
* `private, no-store`, `noindex`, with no referrer. Under `cache.pages: 'cdn'`
|
|
9
|
+
* a published `200` or `404` that sets no cookie is cached at the CDN, tagged
|
|
10
|
+
* with every read that rendered it — unless its own `Cache-Control` says
|
|
11
|
+
* `private`, `no-store` or `no-cache`, which is then left as it is.
|
|
12
|
+
*
|
|
13
|
+
* Start every read inside a `load` (or the page itself), never in another
|
|
14
|
+
* hook: a read made before `resolve`, or streamed after it returns, records no
|
|
15
|
+
* tags. Never read `loader.preview` in a hook — that puts a draft into a page
|
|
16
|
+
* the CDN caches.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* // src/hooks.server.ts
|
|
20
|
+
* export const handle = createPageCacheHandle({ config })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function createPageCacheHandle(options) {
|
|
24
|
+
return async ({ event, resolve }) => {
|
|
25
|
+
const { value: response, headers } = await servePageRequest({ url: event.url, method: event.request.method }, options.config, async () => resolve(event), (page) => ({ status: page.status, header: (name) => page.headers.get(name) }));
|
|
26
|
+
const names = Object.keys(headers);
|
|
27
|
+
if (names.length === 0)
|
|
28
|
+
return response;
|
|
29
|
+
const copy = new Response(response.body, response);
|
|
30
|
+
for (const name of names)
|
|
31
|
+
copy.headers.set(name, headers[name]);
|
|
32
|
+
return copy;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=page-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-cache.js","sourceRoot":"","sources":["../src/page-cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAuBlD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAErC;IACC,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;QAClC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,CACzD,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAChD,OAAO,CAAC,MAAM,EACd,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAC1B,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAC9E,CAAA;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,QAAQ,CAAA;QACvC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAClD,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAW,CAAC,CAAA;QACzE,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krantho/server-sveltekit",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "The krantho adapter for SvelteKit: API and Studio endpoints, the content loader and CDN page caching.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://krantho.com",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/descoped/krantho.git",
|
|
10
|
+
"directory": "packages/server-sveltekit"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/descoped/krantho/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@krantho/server": "1.0.1"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@sveltejs/kit": ">=2.0.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependenciesMeta": {
|
|
32
|
+
"@sveltejs/kit": {
|
|
33
|
+
"optional": true
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^25.9.9",
|
|
38
|
+
"typescript": "^6.0.3",
|
|
39
|
+
"zod": "^4.6.7",
|
|
40
|
+
"@krantho/schema": "1.0.1"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"clean": "rm -rf dist"
|
|
46
|
+
}
|
|
6
47
|
}
|
package/README.md
DELETED