ayezee-astro-cms 1.3.0 → 1.4.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/dist/integration.d.ts +15 -0
- package/dist/integration.js +123 -11
- package/package.json +1 -1
package/dist/integration.d.ts
CHANGED
|
@@ -50,6 +50,21 @@ export interface AyezeeCmsOptions {
|
|
|
50
50
|
* @default true
|
|
51
51
|
*/
|
|
52
52
|
enableAnalytics?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Report site version to CMS dashboard for tracking
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
reportVersion?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Site URL for version reporting (auto-detected if not provided)
|
|
60
|
+
* @default process.env.SITE_URL or process.env.URL
|
|
61
|
+
*/
|
|
62
|
+
siteUrl?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Environment name for version reporting
|
|
65
|
+
* @default process.env.NODE_ENV or 'production'
|
|
66
|
+
*/
|
|
67
|
+
environment?: string;
|
|
53
68
|
}
|
|
54
69
|
/**
|
|
55
70
|
* AyeZee CMS Astro Integration
|
package/dist/integration.js
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import fs from 'fs';
|
|
17
17
|
import path from 'path';
|
|
18
|
+
// Package version - automatically updated during build
|
|
19
|
+
const PACKAGE_VERSION = '1.4.0';
|
|
18
20
|
/**
|
|
19
21
|
* Load environment variables from .env file
|
|
20
22
|
*/
|
|
@@ -48,6 +50,57 @@ function slugify(text) {
|
|
|
48
50
|
.replace(/[\s_-]+/g, '-')
|
|
49
51
|
.replace(/^-+|-+$/g, '');
|
|
50
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Get Astro version from package.json
|
|
55
|
+
*/
|
|
56
|
+
function getAstroVersion() {
|
|
57
|
+
try {
|
|
58
|
+
const pkgPath = path.join(process.cwd(), 'node_modules', 'astro', 'package.json');
|
|
59
|
+
if (fs.existsSync(pkgPath)) {
|
|
60
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
61
|
+
return pkg.version;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Ignore errors
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Report site version to CMS dashboard
|
|
71
|
+
*/
|
|
72
|
+
async function reportSiteVersion(baseUrl, apiKey, siteUrl, environment, astroVersion, logger) {
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(`${baseUrl}/sites`, {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
headers: {
|
|
77
|
+
'Content-Type': 'application/json',
|
|
78
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` }),
|
|
79
|
+
},
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
siteUrl,
|
|
82
|
+
environment,
|
|
83
|
+
packageVersion: PACKAGE_VERSION,
|
|
84
|
+
astroVersion,
|
|
85
|
+
metadata: {
|
|
86
|
+
nodeVersion: process.version,
|
|
87
|
+
platform: process.platform,
|
|
88
|
+
buildTime: new Date().toISOString(),
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
});
|
|
92
|
+
if (response.ok) {
|
|
93
|
+
logger.info(`📡 Reported site version to dashboard`);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
logger.warn(`⚠️ Failed to report site version: ${response.status}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
// Don't fail the build if version reporting fails
|
|
101
|
+
logger.warn(`⚠️ Could not report site version (non-critical)`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
51
104
|
/**
|
|
52
105
|
* AyeZee CMS Astro Integration
|
|
53
106
|
*/
|
|
@@ -57,7 +110,7 @@ export function ayezeeCms(options = {}) {
|
|
|
57
110
|
name: 'ayezee-cms',
|
|
58
111
|
hooks: {
|
|
59
112
|
'astro:config:setup': async ({ config, logger, injectScript }) => {
|
|
60
|
-
logger.info(
|
|
113
|
+
logger.info(`🚀 AyeZee CMS v${PACKAGE_VERSION}: Fetching data...`);
|
|
61
114
|
// Load environment variables from .env
|
|
62
115
|
loadEnvFile();
|
|
63
116
|
// Get configuration
|
|
@@ -68,21 +121,44 @@ export function ayezeeCms(options = {}) {
|
|
|
68
121
|
const cacheFileName = options.cacheFileName || 'cms-cache.json';
|
|
69
122
|
const skipOnError = options.skipOnError || false;
|
|
70
123
|
const enableAnalytics = options.enableAnalytics !== false;
|
|
71
|
-
|
|
124
|
+
const reportVersion = options.reportVersion !== false;
|
|
125
|
+
const siteUrl = options.siteUrl || process.env.SITE_URL || process.env.URL || process.env.VERCEL_URL;
|
|
126
|
+
const environment = options.environment || process.env.NODE_ENV || 'production';
|
|
127
|
+
// Validate config with helpful error messages
|
|
72
128
|
if (!cmsDomain || !projectSlug) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
129
|
+
logger.error('');
|
|
130
|
+
logger.error('❌ AyeZee CMS Configuration Error');
|
|
131
|
+
logger.error('═══════════════════════════════════════════════════════════');
|
|
132
|
+
logger.error('');
|
|
133
|
+
logger.error('Missing required environment variables:');
|
|
134
|
+
if (!cmsDomain) {
|
|
135
|
+
logger.error(' ✗ PUBLIC_CMS_DOMAIN - The URL of your CMS dashboard');
|
|
136
|
+
logger.error(' Example: PUBLIC_CMS_DOMAIN=https://cms.yourdomain.com');
|
|
137
|
+
}
|
|
138
|
+
if (!projectSlug) {
|
|
139
|
+
logger.error(' ✗ PUBLIC_PROJECT_SLUG - Your project identifier');
|
|
140
|
+
logger.error(' Example: PUBLIC_PROJECT_SLUG=my-project');
|
|
141
|
+
}
|
|
142
|
+
logger.error('');
|
|
143
|
+
logger.error('Add these to your .env file:');
|
|
144
|
+
logger.error('');
|
|
145
|
+
logger.error(' PUBLIC_CMS_DOMAIN=https://your-cms-domain.com');
|
|
146
|
+
logger.error(' PUBLIC_PROJECT_SLUG=your-project-slug');
|
|
147
|
+
logger.error(' PUBLIC_AYEZEE_API_KEY=AZ_your_api_key (optional)');
|
|
148
|
+
logger.error('');
|
|
149
|
+
logger.error('═══════════════════════════════════════════════════════════');
|
|
150
|
+
logger.error('');
|
|
78
151
|
if (skipOnError) {
|
|
79
152
|
logger.warn('⚠️ Skipping CMS data fetch due to missing config');
|
|
153
|
+
logger.warn(' Build will continue with cached data (if available)');
|
|
80
154
|
return;
|
|
81
155
|
}
|
|
82
|
-
throw new Error(`AyeZee CMS integration requires PUBLIC_CMS_DOMAIN and PUBLIC_PROJECT_SLUG`
|
|
156
|
+
throw new Error(`AyeZee CMS integration requires PUBLIC_CMS_DOMAIN and PUBLIC_PROJECT_SLUG. ` +
|
|
157
|
+
`See the error messages above for details.`);
|
|
83
158
|
}
|
|
84
159
|
logger.info(` Domain: ${cmsDomain}`);
|
|
85
160
|
logger.info(` Project: ${projectSlug}`);
|
|
161
|
+
logger.info(` Environment: ${environment}`);
|
|
86
162
|
try {
|
|
87
163
|
// Build API URL
|
|
88
164
|
let domain = cmsDomain;
|
|
@@ -183,13 +259,49 @@ export function ayezeeCms(options = {}) {
|
|
|
183
259
|
`);
|
|
184
260
|
logger.info('✅ Umami analytics script injected');
|
|
185
261
|
}
|
|
262
|
+
// Report site version to dashboard (non-blocking)
|
|
263
|
+
if (reportVersion && siteUrl) {
|
|
264
|
+
const astroVersion = getAstroVersion();
|
|
265
|
+
reportSiteVersion(baseUrl, apiKey, siteUrl, environment, astroVersion, logger);
|
|
266
|
+
}
|
|
267
|
+
logger.info('');
|
|
268
|
+
logger.info('🎉 AyeZee CMS data fetched successfully!');
|
|
269
|
+
logger.info('');
|
|
186
270
|
}
|
|
187
271
|
catch (error) {
|
|
188
272
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
189
|
-
logger.error('
|
|
190
|
-
logger.error(
|
|
273
|
+
logger.error('');
|
|
274
|
+
logger.error('❌ Failed to fetch CMS data');
|
|
275
|
+
logger.error('═══════════════════════════════════════════════════════════');
|
|
276
|
+
logger.error('');
|
|
277
|
+
logger.error(`Error: ${errorMessage}`);
|
|
278
|
+
logger.error('');
|
|
279
|
+
// Provide helpful troubleshooting tips
|
|
280
|
+
if (errorMessage.includes('ECONNREFUSED') || errorMessage.includes('fetch failed')) {
|
|
281
|
+
logger.error('Troubleshooting tips:');
|
|
282
|
+
logger.error(' 1. Is the CMS dashboard running?');
|
|
283
|
+
logger.error(` 2. Can you access ${cmsDomain} in your browser?`);
|
|
284
|
+
logger.error(' 3. Check your network connection');
|
|
285
|
+
logger.error(' 4. If using localhost, ensure the dashboard is started');
|
|
286
|
+
}
|
|
287
|
+
else if (errorMessage.includes('401') || errorMessage.includes('403')) {
|
|
288
|
+
logger.error('Troubleshooting tips:');
|
|
289
|
+
logger.error(' 1. Check that PUBLIC_AYEZEE_API_KEY is correct');
|
|
290
|
+
logger.error(' 2. Verify the API key has read permissions');
|
|
291
|
+
logger.error(' 3. Ensure the project slug matches your dashboard project');
|
|
292
|
+
}
|
|
293
|
+
else if (errorMessage.includes('404')) {
|
|
294
|
+
logger.error('Troubleshooting tips:');
|
|
295
|
+
logger.error(' 1. Verify PUBLIC_PROJECT_SLUG is correct');
|
|
296
|
+
logger.error(' 2. Check that the project exists in the dashboard');
|
|
297
|
+
logger.error(` 3. Project slug should match: ${projectSlug}`);
|
|
298
|
+
}
|
|
299
|
+
logger.error('');
|
|
300
|
+
logger.error('═══════════════════════════════════════════════════════════');
|
|
301
|
+
logger.error('');
|
|
191
302
|
if (skipOnError) {
|
|
192
|
-
logger.warn('⚠️ Continuing build
|
|
303
|
+
logger.warn('⚠️ Continuing build with cached data (skipOnError: true)');
|
|
304
|
+
logger.warn(' The site will use previously cached CMS data if available.');
|
|
193
305
|
return;
|
|
194
306
|
}
|
|
195
307
|
throw error;
|
package/package.json
CHANGED