@leadcms/sdk 1.2.85-pre

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) 2025 LeadCMS
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 ADDED
@@ -0,0 +1,261 @@
1
+ # LeadCMS SDK
2
+
3
+ A comprehensive, framework-agnostic SDK and CLI tools for integrating with LeadCMS. Provides clean access to your LeadCMS content through simple JavaScript/TypeScript functions that work with any framework or static site generator.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @leadcms/sdk
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ LeadCMS SDK supports multiple configuration methods in order of priority:
14
+
15
+ ### 1. Configuration File (Recommended)
16
+
17
+ Create a `leadcms.config.json` file in your project root:
18
+
19
+ ```bash
20
+ # Initialize configuration file
21
+ npx leadcms init
22
+ ```
23
+
24
+ ```json
25
+ {
26
+ "url": "https://your-leadcms-instance.com",
27
+ "apiKey": "your-api-key-here",
28
+ "defaultLanguage": "en",
29
+ "contentDir": ".leadcms/content",
30
+ "mediaDir": "public/media",
31
+ "enableDrafts": false
32
+ }
33
+ ```
34
+
35
+ > **Note:** Content types are automatically detected from your LeadCMS API - no need to configure them manually!
36
+
37
+ ### 2. Programmatic Configuration
38
+
39
+ ```typescript
40
+ import { configure } from '@leadcms/sdk';
41
+
42
+ configure({
43
+ url: 'https://your-leadcms-instance.com',
44
+ apiKey: 'your-api-key',
45
+ defaultLanguage: 'en'
46
+ });
47
+ ```
48
+
49
+ ### 3. Environment Variables (Fallback)
50
+
51
+ ```bash
52
+ # Required
53
+ LEADCMS_URL=your-leadcms-instance-url
54
+ LEADCMS_API_KEY=your-api-key
55
+
56
+ # Optional
57
+ LEADCMS_DEFAULT_LANGUAGE=en
58
+ LEADCMS_CONTENT_DIR=.leadcms/content
59
+ LEADCMS_MEDIA_DIR=public/media
60
+
61
+ # Next.js users can also use:
62
+ NEXT_PUBLIC_LEADCMS_URL=your-leadcms-instance-url
63
+ NEXT_PUBLIC_LEADCMS_DEFAULT_LANGUAGE=en
64
+ ```
65
+
66
+ ## CLI Usage
67
+
68
+ ### Initialize configuration
69
+ ```bash
70
+ npx leadcms init
71
+ # Creates leadcms.config.json with sample configuration
72
+ ```
73
+
74
+ ### Generate Docker deployment templates
75
+ ```bash
76
+ npx leadcms docker
77
+ # Creates Docker files for production and preview deployments
78
+ ```
79
+
80
+ ### Fetch content from LeadCMS
81
+ ```bash
82
+ npx leadcms fetch
83
+ ```
84
+
85
+ ### Watch for real-time updates
86
+ ```bash
87
+ npx leadcms watch
88
+ ```
89
+
90
+ ### Generate environment variables file
91
+ ```bash
92
+ npx leadcms generate-env
93
+ ```
94
+
95
+ ## Core Functions
96
+
97
+ ```typescript
98
+ import {
99
+ getCMSContentBySlugForLocale,
100
+ getAllContentSlugsForLocale,
101
+ getAllContentRoutes,
102
+ getAvailableLanguages,
103
+ configure
104
+ } from '@leadcms/sdk';
105
+
106
+ // Option 1: Use configuration file (recommended)
107
+ // Content directory from config: .leadcms/content
108
+ const content = getCMSContentBySlugForLocale('about-us', undefined, 'en');
109
+
110
+ // Option 2: Programmatic configuration
111
+ configure({
112
+ url: 'https://your-instance.com',
113
+ apiKey: 'your-key',
114
+ contentDir: '.leadcms/content'
115
+ });
116
+
117
+ // Option 3: Specify content directory explicitly
118
+ const content = getCMSContentBySlugForLocale('about-us', '.leadcms/content', 'en');
119
+
120
+ // Get all content slugs for a locale
121
+ const slugs = getAllContentSlugsForLocale('.leadcms/content', 'en');
122
+
123
+ // Get all routes (framework-agnostic)
124
+ const routes = getAllContentRoutes('.leadcms/content');
125
+ // Returns: [{ locale: 'en', slug: 'about-us', path: '/about-us', ... }]
126
+
127
+ // Get available languages (uses configured contentDir if not specified)
128
+ const languages = getAvailableLanguages();
129
+
130
+ // Get content with draft support
131
+ const draftContent = getCMSContentBySlugForLocaleWithDraftSupport(
132
+ 'about-us',
133
+ '.leadcms/content',
134
+ 'en',
135
+ 'user-uuid-for-drafts'
136
+ );
137
+
138
+ // Load configuration objects
139
+ const headerConfig = getHeaderConfig('.leadcms/content', 'en');
140
+ const footerConfig = getFooterConfig('.leadcms/content', 'en');
141
+ ```
142
+
143
+ ## Framework Integration
144
+
145
+ The SDK provides framework-agnostic data access. You can easily build framework-specific helpers in your project:
146
+
147
+ ```typescript
148
+ // Example: Next.js App Router helper
149
+ export function generateStaticParams() {
150
+ const routes = getAllContentRoutes('.leadcms/content');
151
+ return routes.map(route => ({
152
+ slug: route.slugParts,
153
+ ...(route.isDefaultLocale ? {} : { locale: route.locale })
154
+ }));
155
+ }
156
+
157
+ // Example: Astro helper
158
+ export function getStaticPaths() {
159
+ const routes = getAllContentRoutes('.leadcms/content');
160
+ return routes.map(route => ({
161
+ params: { slug: route.slug },
162
+ props: { locale: route.locale, path: route.path }
163
+ }));
164
+ }
165
+ ```
166
+
167
+ ## Docker Deployment
168
+
169
+ LeadCMS SDK includes framework-agnostic Docker templates for easy deployment:
170
+
171
+ ### Generate Templates
172
+
173
+ ```bash
174
+ npx leadcms docker
175
+ ```
176
+
177
+ This creates:
178
+ - `Dockerfile` - Production static site deployment
179
+ - `nginx.conf` - Optimized nginx configuration
180
+ - `scripts/inject-runtime-env.sh` - Runtime environment injection
181
+ - `preview/Dockerfile` - Development/preview environment
182
+ - `preview/nginx.conf` - Development proxy configuration
183
+ - `preview/supervisord.conf` - Multi-service management
184
+
185
+ ### Production Deployment
186
+
187
+ ```bash
188
+ # 1. Build your static site (framework-specific)
189
+ npm run build # Next.js: creates 'out' directory
190
+ # npm run build # Astro: creates 'dist' directory
191
+ # npm run build # Gatsby: creates 'public' directory
192
+
193
+ # 2. Build Docker image
194
+ docker build -t my-leadcms-site .
195
+
196
+ # 3. Run container
197
+ docker run -p 80:80 \
198
+ -e LEADCMS_URL=https://your-instance.com \
199
+ -e LEADCMS_DEFAULT_LANGUAGE=en \
200
+ my-leadcms-site
201
+ ```
202
+
203
+ ### Preview/Development Mode
204
+
205
+ ```bash
206
+ # 1. Add livepreview script to package.json
207
+ {
208
+ "scripts": {
209
+ "livepreview": "next dev", // Next.js
210
+ // "livepreview": "astro dev", // Astro
211
+ // "livepreview": "gatsby develop", // Gatsby
212
+ // "livepreview": "nuxt dev" // Nuxt
213
+ }
214
+ }
215
+
216
+ # 2. Build preview image
217
+ docker build -f preview/Dockerfile -t my-leadcms-site-preview .
218
+
219
+ # 3. Run with live updates
220
+ docker run -p 80:80 \
221
+ -e LEADCMS_URL=https://your-instance.com \
222
+ -e LEADCMS_API_KEY=your-api-key \
223
+ -e LEADCMS_DEFAULT_LANGUAGE=en \
224
+ my-leadcms-site-preview
225
+ ```
226
+
227
+ ### Template Features
228
+
229
+ ✅ **Framework-agnostic** - Works with any static site generator
230
+ ✅ **Production optimized** - Nginx with proper caching headers
231
+ ✅ **Live preview** - Development mode with hot reload support
232
+ ✅ **Multi-service** - Nginx proxy + dev server + LeadCMS watcher
233
+ ✅ **Runtime configuration** - Environment variables injected at startup
234
+ ✅ **Health checks** - Built-in container health monitoring
235
+
236
+ ### Customizing Templates
237
+
238
+ After generating templates with `npx leadcms docker`, you can customize:
239
+
240
+ 1. **Source directory** in `Dockerfile`:
241
+ ```dockerfile
242
+ # Change 'out' to your framework's build output:
243
+ COPY dist /usr/share/nginx/html # Astro
244
+ COPY public /usr/share/nginx/html # Gatsby
245
+ COPY .output/public /usr/share/nginx/html # Nuxt
246
+ ```
247
+
248
+ 2. **Nginx configuration** in `nginx.conf` for custom routing rules
249
+
250
+ 3. **Development command** in `preview/supervisord.conf`:
251
+ ```ini
252
+ [program:dev-server]
253
+ command=npm run livepreview # Your development command
254
+ ```
255
+
256
+ ## Development
257
+
258
+ ```bash
259
+ npm run build # Build the SDK
260
+ npm run dev # Watch mode for development
261
+ ```
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ const child_process_1 = require("child_process");
41
+ const path_1 = __importDefault(require("path"));
42
+ const command = process.argv[2];
43
+ const scriptDir = path_1.default.join(__dirname, '../scripts');
44
+ function runScript(scriptName) {
45
+ const scriptPath = path_1.default.join(scriptDir, scriptName);
46
+ const child = (0, child_process_1.spawn)('node', [scriptPath], {
47
+ stdio: 'inherit',
48
+ env: process.env
49
+ });
50
+ child.on('exit', (code) => {
51
+ process.exit(code || 0);
52
+ });
53
+ }
54
+ switch (command) {
55
+ case 'fetch':
56
+ runScript('fetch-leadcms-content.mjs');
57
+ break;
58
+ case 'watch':
59
+ runScript('sse-watcher.mjs');
60
+ break;
61
+ case 'generate-env':
62
+ runScript('generate-env-js.mjs');
63
+ break;
64
+ case 'init':
65
+ case 'config':
66
+ initializeConfig();
67
+ break;
68
+ case 'docker':
69
+ case 'templates':
70
+ generateDockerTemplates();
71
+ break;
72
+ default:
73
+ console.log(`
74
+ LeadCMS SDK CLI
75
+
76
+ Usage:
77
+ leadcms init - Initialize LeadCMS configuration
78
+ leadcms docker - Generate Docker deployment templates
79
+ leadcms fetch - Fetch content from LeadCMS
80
+ leadcms watch - Watch for real-time updates
81
+ leadcms generate-env - Generate environment variables file
82
+
83
+ Configuration:
84
+ Create a leadcms.config.json file in your project root, or set environment variables:
85
+
86
+ Config file example:
87
+ {
88
+ "url": "https://your-leadcms-instance.com",
89
+ "apiKey": "your-api-key",
90
+ "defaultLanguage": "en",
91
+ "contentDir": ".leadcms/content",
92
+ "mediaDir": "public/media"
93
+ }
94
+
95
+ Environment variables (fallback):
96
+ LEADCMS_URL - LeadCMS instance URL
97
+ LEADCMS_API_KEY - LeadCMS API key
98
+ LEADCMS_DEFAULT_LANGUAGE - Default language (optional, defaults to 'en')
99
+
100
+ Next.js users can also use:
101
+ NEXT_PUBLIC_LEADCMS_URL - LeadCMS instance URL
102
+ NEXT_PUBLIC_LEADCMS_DEFAULT_LANGUAGE - Default language
103
+ `);
104
+ break;
105
+ }
106
+ function initializeConfig() {
107
+ Promise.resolve().then(() => __importStar(require('fs'))).then(fs => {
108
+ const configPath = 'leadcms.config.json';
109
+ if (fs.existsSync(configPath)) {
110
+ console.log('❓ leadcms.config.json already exists. Overwrite? (y/N)');
111
+ process.stdin.setRawMode(true);
112
+ process.stdin.resume();
113
+ process.stdin.on('data', (key) => {
114
+ if (key.toString().toLowerCase() === 'y') {
115
+ createConfigFile(configPath);
116
+ }
117
+ else {
118
+ console.log('\\n✅ Configuration initialization cancelled.');
119
+ }
120
+ process.exit(0);
121
+ });
122
+ }
123
+ else {
124
+ createConfigFile(configPath);
125
+ }
126
+ });
127
+ }
128
+ function createConfigFile(configPath) {
129
+ Promise.resolve().then(() => __importStar(require('fs'))).then(fs => {
130
+ const sampleConfig = {
131
+ "url": "https://your-leadcms-instance.com",
132
+ "apiKey": "your-api-key-here",
133
+ "defaultLanguage": "en",
134
+ "contentDir": ".leadcms/content",
135
+ "mediaDir": "public/media",
136
+ "enableDrafts": false
137
+ };
138
+ const content = JSON.stringify(sampleConfig, null, 2);
139
+ fs.writeFileSync(configPath, content, 'utf-8');
140
+ console.log(`✅ Created ${configPath}`);
141
+ console.log('📝 Please edit the configuration file with your LeadCMS details.');
142
+ console.log('ℹ️ Content types are automatically detected from your LeadCMS API.');
143
+ });
144
+ }
145
+ function generateDockerTemplates() {
146
+ Promise.all([Promise.resolve().then(() => __importStar(require('fs'))), Promise.resolve().then(() => __importStar(require('path')))]).then(([fs, pathModule]) => {
147
+ const templateDir = pathModule.join(__dirname, '../templates');
148
+ // Check if templates directory exists
149
+ if (!fs.existsSync(templateDir)) {
150
+ console.error('❌ Docker templates not found in SDK. Please update to the latest version.');
151
+ return;
152
+ }
153
+ console.log('🐳 Generating Docker deployment templates...');
154
+ try {
155
+ // Create directories
156
+ const dirs = ['scripts', 'preview'];
157
+ dirs.forEach(dir => {
158
+ if (!fs.existsSync(dir)) {
159
+ fs.mkdirSync(dir, { recursive: true });
160
+ console.log(`📁 Created directory: ${dir}/`);
161
+ }
162
+ });
163
+ // Copy production files
164
+ const productionFiles = [
165
+ { src: 'docker/Dockerfile', dest: 'Dockerfile' },
166
+ { src: 'docker/nginx.conf', dest: 'nginx.conf' },
167
+ { src: 'scripts/inject-runtime-env.sh', dest: 'scripts/inject-runtime-env.sh' }
168
+ ];
169
+ // Copy preview files
170
+ const previewFiles = [
171
+ { src: 'docker/preview/Dockerfile', dest: 'preview/Dockerfile' },
172
+ { src: 'docker/preview/nginx.conf', dest: 'preview/nginx.conf' },
173
+ { src: 'docker/preview/supervisord.conf', dest: 'preview/supervisord.conf' }
174
+ ];
175
+ [...productionFiles, ...previewFiles].forEach(({ src, dest }) => {
176
+ const srcPath = pathModule.join(templateDir, src);
177
+ const destPath = dest;
178
+ if (fs.existsSync(srcPath)) {
179
+ const content = fs.readFileSync(srcPath, 'utf-8');
180
+ fs.writeFileSync(destPath, content, 'utf-8');
181
+ // Make shell scripts executable
182
+ if (dest.endsWith('.sh')) {
183
+ fs.chmodSync(destPath, '755');
184
+ }
185
+ console.log(`✅ Created ${destPath}`);
186
+ }
187
+ else {
188
+ console.warn(`⚠️ Template not found: ${srcPath}`);
189
+ }
190
+ });
191
+ console.log('\\n🎉 Docker templates generated successfully!');
192
+ console.log('\\n📖 Usage:');
193
+ console.log(' Production build: docker build -t my-site .');
194
+ console.log(' Preview mode: docker build -f preview/Dockerfile -t my-site-preview .');
195
+ console.log('\\n💡 Next steps:');
196
+ console.log(' 1. Add "livepreview": "your-dev-command" to package.json scripts');
197
+ console.log(' 2. Adjust the COPY source directory in Dockerfile if needed');
198
+ console.log(' 3. Set LEADCMS_URL and LEADCMS_API_KEY environment variables');
199
+ }
200
+ catch (error) {
201
+ console.error('❌ Failed to generate Docker templates:', error);
202
+ }
203
+ });
204
+ }
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAAsC;AACtC,gDAAwB;AAExB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAChC,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAErD,SAAS,SAAS,CAAC,UAAkB;IACnC,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE;QACxC,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAC,CAAC;IAEH,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACxB,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,QAAQ,OAAO,EAAE,CAAC;IAChB,KAAK,OAAO;QACV,SAAS,CAAC,2BAA2B,CAAC,CAAC;QACvC,MAAM;IACR,KAAK,OAAO;QACV,SAAS,CAAC,iBAAi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AS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;oBAChC,CAAC;oBAED,OAAO,CAAC,GAAG,CAAC,aAAa,QAAQ,EAAE,CAAC,CAAC;gBACvC,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,IAAI,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;gBACrD,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;YAC9D,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;YAC9D,OAAO,CAAC,GAAG,CAAC,8EAA8E,CAAC,CAAC;YAC5F,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;YAClF,OAAO,CAAC,GAAG,CAAC,+DAA+D,CAAC,CAAC;YAC7E,OAAO,CAAC,GAAG,CAAC,gEAAgE,CAAC,CAAC;QAEhF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;QACjE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './lib/cms';
2
+ export * from './lib/config';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Main exports
18
+ __exportStar(require("./lib/cms"), exports);
19
+ __exportStar(require("./lib/config"), exports);
20
+ // LeadCMS SDK - Framework-agnostic content management
21
+ //
22
+ // Core functions for accessing LeadCMS content:
23
+ // - getCMSContentBySlugForLocale() - Get content by slug
24
+ // - getAllContentSlugsForLocale() - Get all content slugs
25
+ // - getAllContentRoutes() - Get all routes for static generation
26
+ // - getAvailableLanguages() - Get supported languages
27
+ //
28
+ // Configuration options:
29
+ // 1. leadcms.config.json file (recommended)
30
+ // 2. Environment variables (fallback)
31
+ // 3. Programmatic configuration using configure()
32
+ //
33
+ // CLI utilities:
34
+ // - npx leadcms init - Initialize configuration
35
+ // - npx leadcms fetch - Fetch content from LeadCMS
36
+ // - npx leadcms watch - Watch for real-time updates
37
+ // - npx leadcms generate-env - Generate environment file
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,eAAe;AACf,4CAA0B;AAC1B,+CAA6B;AAE7B,sDAAsD;AACtD,EAAE;AACF,gDAAgD;AAChD,yDAAyD;AACzD,0DAA0D;AAC1D,iEAAiE;AACjE,sDAAsD;AACtD,EAAE;AACF,yBAAyB;AACzB,4CAA4C;AAC5C,sCAAsC;AACtC,kDAAkD;AAClD,EAAE;AACF,iBAAiB;AACjB,qDAAqD;AACrD,uDAAuD;AACvD,wDAAwD;AACxD,yDAAyD"}
@@ -0,0 +1,104 @@
1
+ import { type LeadCMSConfigOptions } from "./config";
2
+ export interface HeaderConfig {
3
+ [key: string]: any;
4
+ }
5
+ export interface FooterConfig {
6
+ [key: string]: any;
7
+ }
8
+ export declare const DEFAULT_LANGUAGE = "en";
9
+ export interface CMSContentTemplateProps<T = CMSContent> {
10
+ content: T;
11
+ }
12
+ export interface CMSContent {
13
+ id: string | number;
14
+ slug: string;
15
+ type: string;
16
+ title?: string;
17
+ description?: string;
18
+ coverImageUrl?: string;
19
+ coverImageAlt?: string;
20
+ language?: string;
21
+ translationKey?: string;
22
+ publishedAt?: Date;
23
+ draft?: boolean;
24
+ [key: string]: any;
25
+ body: string;
26
+ }
27
+ /**
28
+ * Get all available languages from the content directory structure
29
+ */
30
+ export declare function getAvailableLanguages(contentDir?: string, configOptions?: LeadCMSConfigOptions): string[];
31
+ /**
32
+ * Get content directory for a specific locale
33
+ */
34
+ export declare function getContentDirForLocale(contentDir: string, locale: string, configOptions?: LeadCMSConfigOptions): string;
35
+ /**
36
+ * Get all content slugs for a specific locale with draft filtering options
37
+ * @param contentDir - Content directory path
38
+ * @param locale - Locale code
39
+ * @param contentTypes - Optional array of content types to filter
40
+ * @param includeDrafts - Whether to include draft content (default: null = false)
41
+ * @param draftUserUid - Specific user UID for draft content (only relevant if includeDrafts is true)
42
+ */
43
+ export declare function getAllContentSlugsForLocale(contentDir: string, locale: string, contentTypes?: string[], includeDrafts?: boolean | null, draftUserUid?: string | null): string[];
44
+ /**
45
+ * Get content by slug for a specific locale with optional draft support
46
+ * @param slug - Content slug
47
+ * @param contentDir - Content directory path
48
+ * @param locale - Locale code
49
+ * @param userUid - Optional user UID for draft content
50
+ */
51
+ export declare function getCMSContentBySlugForLocaleWithDraftSupport(slug: string, contentDir: string, locale: string, userUid?: string | null): CMSContent | null;
52
+ /**
53
+ * Get content by slug for a specific locale
54
+ */
55
+ export declare function getCMSContentBySlugForLocale(slug: string, contentDir: string, locale: string): CMSContent | null;
56
+ /**
57
+ * Get all translations of a content item by translationKey
58
+ */
59
+ export declare function getContentTranslations(translationKey: string, contentDir: string): {
60
+ locale: string;
61
+ content: CMSContent;
62
+ }[];
63
+ /**
64
+ * Get all content routes for all locales in a framework-agnostic format
65
+ * Returns an array of route objects with locale and slug information
66
+ */
67
+ export declare function getAllContentRoutes(contentDir: string, contentTypes?: string[], includeDrafts?: boolean | null, draftUserUid?: string | null): {
68
+ locale: string;
69
+ slug: string;
70
+ slugParts: string[];
71
+ isDefaultLocale: boolean;
72
+ path: string;
73
+ }[];
74
+ /**
75
+ * Extract userUid from a draft slug if it exists
76
+ * @param slug - The slug to check for userUid
77
+ * @returns userUid if found, null otherwise
78
+ */
79
+ export declare function extractUserUidFromSlug(slug: string): string | null;
80
+ export declare function getAllContentSlugs(contentDir: string, contentTypes?: string[]): string[];
81
+ export declare function getCMSContentBySlug(slug: string, contentDir: string): CMSContent | null;
82
+ /**
83
+ * Load header configuration for a specific locale with optional draft support
84
+ * @param contentDir - Content directory path
85
+ * @param locale - Locale code
86
+ * @param userUid - Optional user UID for draft content
87
+ */
88
+ export declare function getHeaderConfig(contentDir: string, locale: string, userUid?: string | null): HeaderConfig | null;
89
+ /**
90
+ * Load footer configuration for a specific locale with optional draft support
91
+ * @param contentDir - Content directory path
92
+ * @param locale - Locale code
93
+ * @param userUid - Optional user UID for draft content
94
+ */
95
+ export declare function getFooterConfig(contentDir: string, locale: string, userUid?: string | null): FooterConfig | null;
96
+ /**
97
+ * Get the current locale from a path
98
+ */
99
+ export declare function getLocaleFromPath(pathname: string): string;
100
+ /**
101
+ * Make a link locale-aware by adding the current locale prefix
102
+ */
103
+ export declare function makeLocaleAwareLink(href: string, currentLocale: string): string;
104
+ //# sourceMappingURL=cms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../src/lib/cms.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiC,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGpF,MAAM,WAAW,YA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