@flexacms/astro 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,43 @@
1
- # Temporary Holding Version
1
+ # @flexacms/astro
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
+ Load [Flexa](https://github.com/flexacms) content into Astro content collections (Astro 5+ content layer).
4
+
5
+ ```bash
6
+ npm install @flexacms/astro
7
+ ```
8
+
9
+ ```ts
10
+ // src/content.config.ts
11
+ import { defineCollection } from 'astro:content';
12
+ import { flexaLoader } from '@flexacms/astro';
13
+
14
+ const posts = defineCollection({
15
+ loader: flexaLoader({
16
+ entity: 'posts',
17
+ url: import.meta.env.FLEXA_URL,
18
+ apiKey: import.meta.env.FLEXA_API_KEY,
19
+ }),
20
+ });
21
+
22
+ export const collections = { posts };
23
+ ```
24
+
25
+ ```astro
26
+ ---
27
+ import { getCollection } from 'astro:content';
28
+
29
+ const posts = await getCollection('posts');
30
+ ---
31
+ {posts.map((post) => <a href={`/blog/${post.id}`}>{post.data.title}</a>)}
32
+ ```
33
+
34
+ Each entry is stored with its slug as id (or its numeric id when it has no slug) and the full API entry as `data`. By default only published entries are loaded.
35
+
36
+ | Option | Default | |
37
+ | ---------------- | ----------------------------- | ------------------------------------------------------------- |
38
+ | `entity` | — | Entity slug |
39
+ | `query` | `{ status: 'published' }` | `status`, `search`, `category`, `perPage`, `includeRelations` |
40
+ | `id` | slug, then id | `(entry) => string` |
41
+ | `url` / `apiKey` | `FLEXA_URL` / `FLEXA_API_KEY` | |
42
+
43
+ Add a `schema` to `defineCollection` to validate or reshape `data` with Zod.
@@ -0,0 +1,54 @@
1
+ import { FlexaClientOptions, ListParams, Entry } from '@flexacms/client';
2
+ export * from '@flexacms/client';
3
+
4
+ /**
5
+ * The parts of Astro's loader context this loader uses. Declared here so the
6
+ * package does not depend on a specific Astro version.
7
+ */
8
+ interface FlexaLoaderContext {
9
+ store: {
10
+ set(entry: {
11
+ id: string;
12
+ data: Record<string, unknown>;
13
+ digest?: string | number;
14
+ }): boolean;
15
+ clear(): void;
16
+ };
17
+ logger: {
18
+ info: (message: string) => void;
19
+ };
20
+ parseData: <TData extends Record<string, unknown>>(props: {
21
+ id: string;
22
+ data: TData;
23
+ }) => Promise<TData>;
24
+ generateDigest: (data: Record<string, unknown> | string) => string;
25
+ }
26
+ interface FlexaLoaderOptions extends Partial<FlexaClientOptions> {
27
+ /** Entity slug, e.g. `posts`. */
28
+ entity: string;
29
+ /** Filters for the entries to load. Defaults to published entries only. */
30
+ query?: Omit<ListParams, 'page'>;
31
+ /** Collection id of an entry. Defaults to its slug, or its id when it has none. */
32
+ id?: (entry: Entry) => string;
33
+ }
34
+ interface FlexaLoader {
35
+ name: string;
36
+ load(context: FlexaLoaderContext): Promise<void>;
37
+ }
38
+ /**
39
+ * Load the entries of a Flexa entity into an Astro content collection.
40
+ *
41
+ * // src/content.config.ts
42
+ * const posts = defineCollection({
43
+ * loader: flexaLoader({
44
+ * entity: 'posts',
45
+ * url: import.meta.env.FLEXA_URL,
46
+ * apiKey: import.meta.env.FLEXA_API_KEY,
47
+ * }),
48
+ * });
49
+ *
50
+ * `url` and `apiKey` fall back to the FLEXA_URL and FLEXA_API_KEY environment variables.
51
+ */
52
+ declare function flexaLoader(options: FlexaLoaderOptions): FlexaLoader;
53
+
54
+ export { type FlexaLoader, type FlexaLoaderContext, type FlexaLoaderOptions, flexaLoader };
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ // src/index.ts
2
+ import { createClient } from "@flexacms/client";
3
+ export * from "@flexacms/client";
4
+ function flexaLoader(options) {
5
+ const {
6
+ entity,
7
+ query = { status: "published" },
8
+ id = (entry) => entry.slug ?? String(entry.id),
9
+ ...clientOptions
10
+ } = options;
11
+ return {
12
+ name: "flexa-loader",
13
+ async load({ store, logger, parseData, generateDigest }) {
14
+ const url = clientOptions.url ?? process.env.FLEXA_URL;
15
+ const apiKey = clientOptions.apiKey ?? process.env.FLEXA_API_KEY;
16
+ if (!url || !apiKey) {
17
+ throw new Error(
18
+ `Flexa loader "${entity}": set FLEXA_URL and FLEXA_API_KEY, or pass "url" and "apiKey".`
19
+ );
20
+ }
21
+ const entries = await createClient({
22
+ ...clientOptions,
23
+ url,
24
+ apiKey
25
+ }).entity(entity).all(query);
26
+ store.clear();
27
+ for (const entry of entries) {
28
+ const entryId = id(entry);
29
+ const data = await parseData({
30
+ id: entryId,
31
+ data: entry
32
+ });
33
+ store.set({
34
+ id: entryId,
35
+ data,
36
+ digest: generateDigest(
37
+ entry.updated_at ?? JSON.stringify(entry)
38
+ )
39
+ });
40
+ }
41
+ logger.info(
42
+ `Loaded ${entries.length} ${entries.length === 1 ? "entry" : "entries"} from Flexa "${entity}".`
43
+ );
44
+ }
45
+ };
46
+ }
47
+ export {
48
+ flexaLoader
49
+ };
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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` and `apiKey` fall back to the FLEXA_URL and FLEXA_API_KEY environment variables.\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;\n const apiKey = clientOptions.apiKey ?? process.env.FLEXA_API_KEY;\n\n if (!url || !apiKey) {\n throw new Error(\n `Flexa loader \"${entity}\": set FLEXA_URL and FLEXA_API_KEY, or pass \"url\" and \"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,oBAAoB;AAG7B,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;AAC7C,YAAM,SAAS,cAAc,UAAU,QAAQ,IAAI;AAEnD,UAAI,CAAC,OAAO,CAAC,QAAQ;AACjB,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,51 @@
1
1
  {
2
- "name": "@flexacms/astro",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@flexacms/astro",
3
+ "version": "0.1.0",
4
+ "description": "Astro content loader for the Flexa headless CMS.",
5
+ "keywords": [
6
+ "astro",
7
+ "astro-loader",
8
+ "cms",
9
+ "content-layer",
10
+ "flexa",
11
+ "headless"
12
+ ],
13
+ "homepage": "https://github.com/flexacms/sdk/tree/main/packages/astro#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/flexacms/sdk/issues"
16
+ },
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/flexacms/sdk.git",
21
+ "directory": "packages/astro"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "scripts": {
42
+ "build": "tsup",
43
+ "typecheck": "tsc -p tsconfig.json"
44
+ },
45
+ "dependencies": {
46
+ "@flexacms/client": "^0.1.0"
47
+ },
48
+ "peerDependencies": {
49
+ "astro": ">=5.0.0"
50
+ }
51
+ }