@flexacms/astro 0.2.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 +3 -2
- 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
|
@@ -14,8 +14,8 @@ import { flexaLoader } from '@flexacms/astro';
|
|
|
14
14
|
const posts = defineCollection({
|
|
15
15
|
loader: flexaLoader({
|
|
16
16
|
entity: 'posts',
|
|
17
|
-
url: import.meta.env.FLEXA_URL,
|
|
18
17
|
apiKey: import.meta.env.FLEXA_API_KEY,
|
|
18
|
+
// url: import.meta.env.FLEXA_URL, // optional, defaults to https://flexacms.com
|
|
19
19
|
}),
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -38,6 +38,7 @@ Each entry is stored with its slug as id (or its numeric id when it has no slug)
|
|
|
38
38
|
| `entity` | — | Entity slug |
|
|
39
39
|
| `query` | `{ status: 'published' }` | `status`, `search`, `category`, `perPage`, `includeRelations` |
|
|
40
40
|
| `id` | slug, then id | `(entry) => string` |
|
|
41
|
-
| `url`
|
|
41
|
+
| `url` | `FLEXA_URL`, then `https://flexacms.com` | |
|
|
42
|
+
| `apiKey` | `FLEXA_API_KEY` | |
|
|
42
43
|
|
|
43
44
|
Add a `schema` to `defineCollection` to validate or reshape `data` with Zod.
|
package/dist/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ interface FlexaLoader {
|
|
|
47
47
|
* }),
|
|
48
48
|
* });
|
|
49
49
|
*
|
|
50
|
-
* `url`
|
|
50
|
+
* `url` falls back to FLEXA_URL, then https://flexacms.com. `apiKey` falls back to FLEXA_API_KEY.
|
|
51
51
|
*/
|
|
52
52
|
declare function flexaLoader(options: FlexaLoaderOptions): FlexaLoader;
|
|
53
53
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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 flexaLoader(options) {
|
|
5
5
|
const {
|
|
@@ -11,11 +11,11 @@ function flexaLoader(options) {
|
|
|
11
11
|
return {
|
|
12
12
|
name: "flexa-loader",
|
|
13
13
|
async load({ store, logger, parseData, generateDigest }) {
|
|
14
|
-
const url = clientOptions.url
|
|
14
|
+
const url = clientOptions.url || process.env.FLEXA_URL || DEFAULT_URL;
|
|
15
15
|
const apiKey = clientOptions.apiKey ?? process.env.FLEXA_API_KEY;
|
|
16
|
-
if (!
|
|
16
|
+
if (!apiKey) {
|
|
17
17
|
throw new Error(
|
|
18
|
-
`Flexa loader "${entity}": set
|
|
18
|
+
`Flexa loader "${entity}": set FLEXA_API_KEY, or pass "apiKey".`
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
const entries = await createClient({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createClient } from '@flexacms/client';\nimport type { Entry, FlexaClientOptions, ListParams } from '@flexacms/client';\n\nexport * from '@flexacms/client';\n\n/**\n * The parts of Astro's loader context this loader uses. Declared here so the\n * package does not depend on a specific Astro version.\n */\nexport interface FlexaLoaderContext {\n store: {\n set(entry: {\n id: string;\n data: Record<string, unknown>;\n digest?: string | number;\n }): boolean;\n clear(): void;\n };\n logger: { info: (message: string) => void };\n parseData: <TData extends Record<string, unknown>>(props: {\n id: string;\n data: TData;\n }) => Promise<TData>;\n generateDigest: (data: Record<string, unknown> | string) => string;\n}\n\nexport interface FlexaLoaderOptions extends Partial<FlexaClientOptions> {\n /** Entity slug, e.g. `posts`. */\n entity: string;\n /** Filters for the entries to load. Defaults to published entries only. */\n query?: Omit<ListParams, 'page'>;\n /** Collection id of an entry. Defaults to its slug, or its id when it has none. */\n id?: (entry: Entry) => string;\n}\n\nexport interface FlexaLoader {\n name: string;\n load(context: FlexaLoaderContext): Promise<void>;\n}\n\n/**\n * Load the entries of a Flexa entity into an Astro content collection.\n *\n * // src/content.config.ts\n * const posts = defineCollection({\n * loader: flexaLoader({\n * entity: 'posts',\n * url: import.meta.env.FLEXA_URL,\n * apiKey: import.meta.env.FLEXA_API_KEY,\n * }),\n * });\n *\n * `url`
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createClient, DEFAULT_URL } from '@flexacms/client';\nimport type { Entry, FlexaClientOptions, ListParams } from '@flexacms/client';\n\nexport * from '@flexacms/client';\n\n/**\n * The parts of Astro's loader context this loader uses. Declared here so the\n * package does not depend on a specific Astro version.\n */\nexport interface FlexaLoaderContext {\n store: {\n set(entry: {\n id: string;\n data: Record<string, unknown>;\n digest?: string | number;\n }): boolean;\n clear(): void;\n };\n logger: { info: (message: string) => void };\n parseData: <TData extends Record<string, unknown>>(props: {\n id: string;\n data: TData;\n }) => Promise<TData>;\n generateDigest: (data: Record<string, unknown> | string) => string;\n}\n\nexport interface FlexaLoaderOptions extends Partial<FlexaClientOptions> {\n /** Entity slug, e.g. `posts`. */\n entity: string;\n /** Filters for the entries to load. Defaults to published entries only. */\n query?: Omit<ListParams, 'page'>;\n /** Collection id of an entry. Defaults to its slug, or its id when it has none. */\n id?: (entry: Entry) => string;\n}\n\nexport interface FlexaLoader {\n name: string;\n load(context: FlexaLoaderContext): Promise<void>;\n}\n\n/**\n * Load the entries of a Flexa entity into an Astro content collection.\n *\n * // src/content.config.ts\n * const posts = defineCollection({\n * loader: flexaLoader({\n * entity: 'posts',\n * url: import.meta.env.FLEXA_URL,\n * apiKey: import.meta.env.FLEXA_API_KEY,\n * }),\n * });\n *\n * `url` falls back to FLEXA_URL, then https://flexacms.com. `apiKey` falls back to FLEXA_API_KEY.\n */\nexport function flexaLoader(options: FlexaLoaderOptions): FlexaLoader {\n const {\n entity,\n query = { status: 'published' },\n id = (entry) => entry.slug ?? String(entry.id),\n ...clientOptions\n } = options;\n\n return {\n name: 'flexa-loader',\n async load({ store, logger, parseData, generateDigest }) {\n const url = clientOptions.url || process.env.FLEXA_URL || DEFAULT_URL;\n const apiKey = clientOptions.apiKey ?? process.env.FLEXA_API_KEY;\n\n if (!apiKey) {\n throw new Error(\n `Flexa loader \"${entity}\": set FLEXA_API_KEY, or pass \"apiKey\".`,\n );\n }\n\n const entries = await createClient({\n ...clientOptions,\n url,\n apiKey,\n })\n .entity(entity)\n .all(query);\n\n store.clear();\n\n for (const entry of entries) {\n const entryId = id(entry);\n const data = await parseData({\n id: entryId,\n data: entry as unknown as Record<string, unknown>,\n });\n\n store.set({\n id: entryId,\n data,\n digest: generateDigest(\n entry.updated_at ?? JSON.stringify(entry),\n ),\n });\n }\n\n logger.info(\n `Loaded ${entries.length} ${entries.length === 1 ? 'entry' : 'entries'} from Flexa \"${entity}\".`,\n );\n },\n };\n}\n"],"mappings":";AAAA,SAAS,cAAc,mBAAmB;AAG1C,cAAc;AAmDP,SAAS,YAAY,SAA0C;AAClE,QAAM;AAAA,IACF;AAAA,IACA,QAAQ,EAAE,QAAQ,YAAY;AAAA,IAC9B,KAAK,CAAC,UAAU,MAAM,QAAQ,OAAO,MAAM,EAAE;AAAA,IAC7C,GAAG;AAAA,EACP,IAAI;AAEJ,SAAO;AAAA,IACH,MAAM;AAAA,IACN,MAAM,KAAK,EAAE,OAAO,QAAQ,WAAW,eAAe,GAAG;AACrD,YAAM,MAAM,cAAc,OAAO,QAAQ,IAAI,aAAa;AAC1D,YAAM,SAAS,cAAc,UAAU,QAAQ,IAAI;AAEnD,UAAI,CAAC,QAAQ;AACT,cAAM,IAAI;AAAA,UACN,iBAAiB,MAAM;AAAA,QAC3B;AAAA,MACJ;AAEA,YAAM,UAAU,MAAM,aAAa;AAAA,QAC/B,GAAG;AAAA,QACH;AAAA,QACA;AAAA,MACJ,CAAC,EACI,OAAO,MAAM,EACb,IAAI,KAAK;AAEd,YAAM,MAAM;AAEZ,iBAAW,SAAS,SAAS;AACzB,cAAM,UAAU,GAAG,KAAK;AACxB,cAAM,OAAO,MAAM,UAAU;AAAA,UACzB,IAAI;AAAA,UACJ,MAAM;AAAA,QACV,CAAC;AAED,cAAM,IAAI;AAAA,UACN,IAAI;AAAA,UACJ;AAAA,UACA,QAAQ;AAAA,YACJ,MAAM,cAAc,KAAK,UAAU,KAAK;AAAA,UAC5C;AAAA,QACJ,CAAC;AAAA,MACL;AAEA,aAAO;AAAA,QACH,UAAU,QAAQ,MAAM,IAAI,QAAQ,WAAW,IAAI,UAAU,SAAS,gBAAgB,MAAM;AAAA,MAChG;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexacms/astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Astro content loader for the Flexa headless CMS.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"typecheck": "tsc -p tsconfig.json"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@flexacms/client": "^0.
|
|
46
|
+
"@flexacms/client": "^0.3.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"astro": ">=5.0.0"
|