ayezee-astro-cms 1.2.0 → 1.2.2

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.
@@ -25,6 +25,11 @@ export interface AyezeeCmsOptions {
25
25
  * @default process.env.PUBLIC_PROJECT_SLUG
26
26
  */
27
27
  projectSlug?: string;
28
+ /**
29
+ * API key or project token for authentication
30
+ * @default process.env.PUBLIC_AYEZEE_API_KEY
31
+ */
32
+ apiKey?: string;
28
33
  /**
29
34
  * Output directory for cached data
30
35
  * @default 'src/data'
@@ -62,6 +62,7 @@ export function ayezeeCms(options = {}) {
62
62
  // Get configuration
63
63
  const cmsDomain = options.cmsDomain || process.env.PUBLIC_CMS_DOMAIN;
64
64
  const projectSlug = options.projectSlug || process.env.PUBLIC_PROJECT_SLUG;
65
+ const apiKey = options.apiKey || process.env.PUBLIC_AYEZEE_API_KEY;
65
66
  const outputDir = options.outputDir || 'src/data';
66
67
  const cacheFileName = options.cacheFileName || 'cms-cache.json';
67
68
  const skipOnError = options.skipOnError || false;
@@ -90,7 +91,11 @@ export function ayezeeCms(options = {}) {
90
91
  const baseUrl = `${domain}/api/v1/projects/${projectSlug}`;
91
92
  // Fetch modules
92
93
  logger.info('📡 Fetching modules...');
93
- const modulesResponse = await fetch(`${baseUrl}/modules`);
94
+ const modulesResponse = await fetch(`${baseUrl}/modules`, {
95
+ headers: {
96
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` }),
97
+ },
98
+ });
94
99
  if (!modulesResponse.ok) {
95
100
  throw new Error(`API error: ${modulesResponse.status} ${modulesResponse.statusText}`);
96
101
  }
@@ -104,7 +109,14 @@ export function ayezeeCms(options = {}) {
104
109
  const modulesWithData = [];
105
110
  for (const module of modules) {
106
111
  try {
107
- const dataResponse = await fetch(`${baseUrl}/modules/${module.instanceKey}/data`);
112
+ const dataResponse = await fetch(`${baseUrl}/modules/${module.instanceKey}/data`, {
113
+ headers: {
114
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` }),
115
+ },
116
+ });
117
+ if (!dataResponse.ok) {
118
+ throw new Error(`HTTP ${dataResponse.status}: ${dataResponse.statusText}`);
119
+ }
108
120
  const dataResult = await dataResponse.json();
109
121
  const itemCount = dataResult.data?.pagination?.total || 0;
110
122
  logger.info(` 📦 ${module.label}: ${itemCount} items`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ayezee-astro-cms",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "AyeZee CMS integration for Astro with automatic data fetching, form handling, and validation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",