@flexacms/sveltekit 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ivan Mercedes
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/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @flexacms/sveltekit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Flexa](https://github.com/flexacms) for SvelteKit: a server hook that puts a client on `event.locals.flexa`, available in every server `load` function and form action.
4
+
5
+ ```bash
6
+ npm install @flexacms/sveltekit
7
+ ```
8
+
9
+ ```ts
10
+ // src/hooks.server.ts
11
+ import { env } from '$env/dynamic/private';
12
+ import { createFlexaHandle } from '@flexacms/sveltekit';
13
+
14
+ export const handle = createFlexaHandle({
15
+ url: env.FLEXA_URL,
16
+ apiKey: env.FLEXA_API_KEY,
17
+ });
18
+ ```
19
+
20
+ ```ts
21
+ // src/app.d.ts
22
+ import type { FlexaClient } from '@flexacms/sveltekit';
23
+ import type { FlexaSchema } from './flexa'; // optional: npx @flexacms/cli generate
24
+
25
+ declare global {
26
+ namespace App {
27
+ interface Locals {
28
+ flexa: FlexaClient<FlexaSchema>;
29
+ }
30
+ }
31
+ }
32
+
33
+ export {};
34
+ ```
35
+
36
+ ```ts
37
+ // src/routes/blog/[slug]/+page.server.ts
38
+ import { error } from '@sveltejs/kit';
39
+
40
+ export async function load({ locals, params }) {
41
+ const post = await locals.flexa.entity('posts').find(params.slug);
42
+
43
+ if (!post) error(404);
44
+
45
+ return { post };
46
+ }
47
+ ```
48
+
49
+ The client uses SvelteKit's `event.fetch`. Combine the hook with others using `sequence()` from `@sveltejs/kit/hooks`.
@@ -0,0 +1,31 @@
1
+ import { ContentSchema, FlexaClientOptions } from '@flexacms/client';
2
+ export * from '@flexacms/client';
3
+
4
+ /**
5
+ * The parts of SvelteKit's `handle` hook this package uses. Declared here so
6
+ * the package does not depend on a specific SvelteKit version.
7
+ */
8
+ interface HandleInput<TEvent extends {
9
+ locals: object;
10
+ fetch: typeof fetch;
11
+ }> {
12
+ event: TEvent;
13
+ resolve: (event: TEvent) => Response | Promise<Response>;
14
+ }
15
+ /**
16
+ * A server `handle` hook that puts a Flexa client on `event.locals.flexa`, so
17
+ * every `load` function and form action can read content with the private key.
18
+ *
19
+ * // src/hooks.server.ts
20
+ * import { env } from '$env/dynamic/private';
21
+ * export const handle = createFlexaHandle({ url: env.FLEXA_URL, apiKey: env.FLEXA_API_KEY });
22
+ *
23
+ * Combine it with other hooks using `sequence()` from `@sveltejs/kit/hooks`.
24
+ * `url` and `apiKey` fall back to the FLEXA_URL and FLEXA_API_KEY environment variables.
25
+ */
26
+ declare function createFlexaHandle<TSchema extends object = ContentSchema>(options?: Partial<FlexaClientOptions>): <TEvent extends {
27
+ locals: object;
28
+ fetch: typeof fetch;
29
+ }>({ event, resolve }: HandleInput<TEvent>) => Promise<Response>;
30
+
31
+ export { createFlexaHandle };
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ // src/index.ts
2
+ import { createClient } from "@flexacms/client";
3
+ export * from "@flexacms/client";
4
+ function createFlexaHandle(options = {}) {
5
+ const url = options.url ?? process.env.FLEXA_URL;
6
+ const apiKey = options.apiKey ?? process.env.FLEXA_API_KEY;
7
+ if (!url || !apiKey) {
8
+ throw new Error(
9
+ 'Flexa: pass "url" and "apiKey" (e.g. from $env/dynamic/private) or set FLEXA_URL and FLEXA_API_KEY.'
10
+ );
11
+ }
12
+ return async function handle({ event, resolve }) {
13
+ event.locals.flexa = createClient({
14
+ ...options,
15
+ url,
16
+ apiKey,
17
+ fetch: options.fetch ?? event.fetch
18
+ });
19
+ return resolve(event);
20
+ };
21
+ }
22
+ export {
23
+ createFlexaHandle
24
+ };
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createClient } from '@flexacms/client';\nimport type {\n ContentSchema,\n FlexaClient,\n FlexaClientOptions,\n} from '@flexacms/client';\n\nexport * from '@flexacms/client';\n\n/**\n * The parts of SvelteKit's `handle` hook this package uses. Declared here so\n * the package does not depend on a specific SvelteKit version.\n */\ninterface HandleInput<TEvent extends { locals: object; fetch: typeof fetch }> {\n event: TEvent;\n resolve: (event: TEvent) => Response | Promise<Response>;\n}\n\n/**\n * A server `handle` hook that puts a Flexa client on `event.locals.flexa`, so\n * every `load` function and form action can read content with the private key.\n *\n * // src/hooks.server.ts\n * import { env } from '$env/dynamic/private';\n * export const handle = createFlexaHandle({ url: env.FLEXA_URL, apiKey: env.FLEXA_API_KEY });\n *\n * Combine it with other hooks using `sequence()` from `@sveltejs/kit/hooks`.\n * `url` and `apiKey` fall back to the FLEXA_URL and FLEXA_API_KEY environment variables.\n */\nexport function createFlexaHandle<TSchema extends object = ContentSchema>(\n options: Partial<FlexaClientOptions> = {},\n) {\n const url = options.url ?? process.env.FLEXA_URL;\n const apiKey = options.apiKey ?? process.env.FLEXA_API_KEY;\n\n if (!url || !apiKey) {\n throw new Error(\n 'Flexa: pass \"url\" and \"apiKey\" (e.g. from $env/dynamic/private) or set FLEXA_URL and FLEXA_API_KEY.',\n );\n }\n\n return async function handle<\n TEvent extends { locals: object; fetch: typeof fetch },\n >({ event, resolve }: HandleInput<TEvent>) {\n (event.locals as { flexa?: FlexaClient<TSchema> }).flexa =\n createClient<TSchema>({\n ...options,\n url,\n apiKey,\n fetch: options.fetch ?? event.fetch,\n });\n\n return resolve(event);\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAO7B,cAAc;AAsBP,SAAS,kBACZ,UAAuC,CAAC,GAC1C;AACE,QAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI;AACvC,QAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;AAE7C,MAAI,CAAC,OAAO,CAAC,QAAQ;AACjB,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,eAAe,OAEpB,EAAE,OAAO,QAAQ,GAAwB;AACvC,IAAC,MAAM,OAA4C,QAC/C,aAAsB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,MACA;AAAA,MACA,OAAO,QAAQ,SAAS,MAAM;AAAA,IAClC,CAAC;AAEL,WAAO,QAAQ,KAAK;AAAA,EACxB;AACJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
- "name": "@flexacms/sveltekit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@flexacms/sveltekit",
3
+ "version": "0.1.0",
4
+ "description": "SvelteKit integration for the Flexa headless CMS: a server hook that puts a Flexa client on event.locals.",
5
+ "keywords": [
6
+ "cms",
7
+ "flexa",
8
+ "headless",
9
+ "svelte",
10
+ "sveltekit"
11
+ ],
12
+ "homepage": "https://github.com/flexacms/sdk/tree/main/packages/sveltekit#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/flexacms/sdk/issues"
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/flexacms/sdk.git",
20
+ "directory": "packages/sveltekit"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ }
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "typecheck": "tsc -p tsconfig.json"
43
+ },
44
+ "dependencies": {
45
+ "@flexacms/client": "^0.1.0"
46
+ },
47
+ "peerDependencies": {
48
+ "@sveltejs/kit": ">=2.0.0"
49
+ }
50
+ }