@flexacms/sveltekit 0.1.0 → 0.3.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 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ import { env } from '$env/dynamic/private';
|
|
|
12
12
|
import { createFlexaHandle } from '@flexacms/sveltekit';
|
|
13
13
|
|
|
14
14
|
export const handle = createFlexaHandle({
|
|
15
|
+
// url defaults to FLEXA_URL, then https://flexacms.com
|
|
15
16
|
url: env.FLEXA_URL,
|
|
16
17
|
apiKey: env.FLEXA_API_KEY,
|
|
17
18
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ interface HandleInput<TEvent extends {
|
|
|
21
21
|
* export const handle = createFlexaHandle({ url: env.FLEXA_URL, apiKey: env.FLEXA_API_KEY });
|
|
22
22
|
*
|
|
23
23
|
* Combine it with other hooks using `sequence()` from `@sveltejs/kit/hooks`.
|
|
24
|
-
* `url`
|
|
24
|
+
* `url` falls back to FLEXA_URL, then https://flexacms.com. `apiKey` falls back to FLEXA_API_KEY.
|
|
25
25
|
*/
|
|
26
26
|
declare function createFlexaHandle<TSchema extends object = ContentSchema>(options?: Partial<FlexaClientOptions>): <TEvent extends {
|
|
27
27
|
locals: object;
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { createClient } from "@flexacms/client";
|
|
2
|
+
import { createClient, DEFAULT_URL } from "@flexacms/client";
|
|
3
3
|
export * from "@flexacms/client";
|
|
4
4
|
function createFlexaHandle(options = {}) {
|
|
5
|
-
const url = options.url
|
|
5
|
+
const url = options.url || process.env.FLEXA_URL || DEFAULT_URL;
|
|
6
6
|
const apiKey = options.apiKey ?? process.env.FLEXA_API_KEY;
|
|
7
|
-
if (!
|
|
7
|
+
if (!apiKey) {
|
|
8
8
|
throw new Error(
|
|
9
|
-
'Flexa: pass "
|
|
9
|
+
'Flexa: pass "apiKey" (e.g. from $env/dynamic/private) or set FLEXA_API_KEY.'
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
12
|
return async function handle({ event, resolve }) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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`
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createClient, DEFAULT_URL } 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` falls back to FLEXA_URL, then https://flexacms.com. `apiKey` falls back to FLEXA_API_KEY.\n */\nexport function createFlexaHandle<TSchema extends object = ContentSchema>(\n options: Partial<FlexaClientOptions> = {},\n) {\n const url = options.url || process.env.FLEXA_URL || DEFAULT_URL;\n const apiKey = options.apiKey ?? process.env.FLEXA_API_KEY;\n\n if (!apiKey) {\n throw new Error(\n 'Flexa: pass \"apiKey\" (e.g. from $env/dynamic/private) or set 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,cAAc,mBAAmB;AAO1C,cAAc;AAsBP,SAAS,kBACZ,UAAuC,CAAC,GAC1C;AACE,QAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI,aAAa;AACpD,QAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;AAE7C,MAAI,CAAC,QAAQ;AACT,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,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexacms/sveltekit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "SvelteKit integration for the Flexa headless CMS: a server hook that puts a Flexa client on event.locals.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"typecheck": "tsc -p tsconfig.json"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@flexacms/client": "^0.
|
|
45
|
+
"@flexacms/client": "^0.3.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@sveltejs/kit": ">=2.0.0"
|