@leadcms/sdk 2.1.5 → 2.2.1
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 +331 -6
- package/dist/cli/index.js +97 -68
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/auth.d.ts +55 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +204 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/cms-config-types.d.ts +57 -0
- package/dist/lib/cms-config-types.d.ts.map +1 -0
- package/dist/lib/cms-config-types.js +64 -0
- package/dist/lib/cms-config-types.js.map +1 -0
- package/dist/lib/cms.d.ts +52 -0
- package/dist/lib/cms.d.ts.map +1 -1
- package/dist/lib/cms.js +113 -0
- package/dist/lib/cms.js.map +1 -1
- package/dist/lib/comment-types.d.ts +73 -0
- package/dist/lib/comment-types.d.ts.map +1 -0
- package/dist/lib/comment-types.js +6 -0
- package/dist/lib/comment-types.js.map +1 -0
- package/dist/lib/comment-utils.d.ts +173 -0
- package/dist/lib/comment-utils.d.ts.map +1 -0
- package/dist/lib/comment-utils.js +338 -0
- package/dist/lib/comment-utils.js.map +1 -0
- package/dist/lib/config.d.ts +4 -2
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +10 -4
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/data-service.d.ts.map +1 -1
- package/dist/lib/data-service.js +22 -6
- package/dist/lib/data-service.js.map +1 -1
- package/dist/scripts/fetch-leadcms-comments.d.ts +26 -0
- package/dist/scripts/fetch-leadcms-comments.d.ts.map +1 -0
- package/dist/scripts/fetch-leadcms-comments.js +352 -0
- package/dist/scripts/fetch-leadcms-comments.js.map +1 -0
- package/dist/scripts/fetch-leadcms-content.d.ts.map +1 -1
- package/dist/scripts/fetch-leadcms-content.js +86 -39
- package/dist/scripts/fetch-leadcms-content.js.map +1 -1
- package/dist/scripts/init-leadcms.d.ts +7 -0
- package/dist/scripts/init-leadcms.d.ts.map +1 -0
- package/dist/scripts/init-leadcms.js +397 -0
- package/dist/scripts/init-leadcms.js.map +1 -0
- package/dist/scripts/leadcms-helpers.d.ts +2 -2
- package/dist/scripts/leadcms-helpers.d.ts.map +1 -1
- package/dist/scripts/leadcms-helpers.js +12 -7
- package/dist/scripts/leadcms-helpers.js.map +1 -1
- package/dist/scripts/login-leadcms.d.ts +10 -0
- package/dist/scripts/login-leadcms.d.ts.map +1 -0
- package/dist/scripts/login-leadcms.js +90 -0
- package/dist/scripts/login-leadcms.js.map +1 -0
- package/dist/scripts/pull-all.d.ts +12 -0
- package/dist/scripts/pull-all.d.ts.map +1 -0
- package/dist/scripts/pull-all.js +81 -0
- package/dist/scripts/pull-all.js.map +1 -0
- package/dist/scripts/pull-comments.d.ts +11 -0
- package/dist/scripts/pull-comments.d.ts.map +1 -0
- package/dist/scripts/pull-comments.js +45 -0
- package/dist/scripts/pull-comments.js.map +1 -0
- package/dist/scripts/pull-content.d.ts +11 -0
- package/dist/scripts/pull-content.d.ts.map +1 -0
- package/dist/scripts/pull-content.js +45 -0
- package/dist/scripts/pull-content.js.map +1 -0
- package/dist/scripts/pull-media.d.ts +12 -0
- package/dist/scripts/pull-media.d.ts.map +1 -0
- package/dist/scripts/pull-media.js +46 -0
- package/dist/scripts/pull-media.js.map +1 -0
- package/dist/scripts/push-leadcms-content.d.ts.map +1 -1
- package/dist/scripts/push-leadcms-content.js +12 -0
- package/dist/scripts/push-leadcms-content.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
export * from './lib/cms.js';
|
|
3
3
|
export * from './lib/config.js';
|
|
4
4
|
export * from './lib/locale-utils.js';
|
|
5
|
+
export * from './lib/comment-types.js';
|
|
6
|
+
export * from './lib/cms-config-types.js';
|
|
7
|
+
export * from './lib/auth.js';
|
|
5
8
|
// LeadCMS SDK - Framework-agnostic content management
|
|
6
9
|
//
|
|
7
10
|
// Core functions for accessing LeadCMS content:
|
|
@@ -10,6 +13,18 @@ export * from './lib/locale-utils.js';
|
|
|
10
13
|
// - getAllContentRoutes() - Get all routes for static generation
|
|
11
14
|
// - getAvailableLanguages() - Get supported languages
|
|
12
15
|
//
|
|
16
|
+
// Comments API:
|
|
17
|
+
// - getComments() - Get comments for any commentable entity
|
|
18
|
+
// - getCommentsForContent() - Get comments for a specific content item
|
|
19
|
+
// - getCommentsStrict() - Get comments with strict error handling
|
|
20
|
+
// - getCommentsForContentStrict() - Get comments for content with strict error handling
|
|
21
|
+
// - getCommentsTree() - Get comments as a hierarchical tree structure with sorting and filtering
|
|
22
|
+
// - getCommentsTreeForContent() - Get comments tree for content (convenience wrapper)
|
|
23
|
+
//
|
|
24
|
+
// Note: Tree building utilities (buildCommentTree, flattenCommentTree, filterComments, etc.)
|
|
25
|
+
// are internal implementation details and not part of the public API. Use getCommentsTree()
|
|
26
|
+
// and getCommentsTreeForContent() for all tree operations.
|
|
27
|
+
//
|
|
13
28
|
// Locale utilities:
|
|
14
29
|
// - isValidLocaleCode() - Validate locale directory names
|
|
15
30
|
//
|
|
@@ -19,8 +34,20 @@ export * from './lib/locale-utils.js';
|
|
|
19
34
|
// 3. Programmatic configuration using configure()
|
|
20
35
|
//
|
|
21
36
|
// CLI utilities:
|
|
22
|
-
// - npx leadcms init - Initialize configuration
|
|
23
|
-
// - npx leadcms
|
|
37
|
+
// - npx leadcms init - Initialize configuration (includes authentication setup)
|
|
38
|
+
// - npx leadcms login - Authenticate with LeadCMS (device auth or manual token)
|
|
39
|
+
// - npx leadcms pull - Pull content and comments from LeadCMS
|
|
40
|
+
// - npx leadcms pull-comments - Pull only comments from LeadCMS
|
|
41
|
+
// - npx leadcms fetch - Alias for pull (backward compatibility)
|
|
24
42
|
// - npx leadcms watch - Watch for real-time updates
|
|
25
43
|
// - npx leadcms generate-env - Generate environment file
|
|
44
|
+
//
|
|
45
|
+
// Authentication API:
|
|
46
|
+
// - authenticate() - Complete authentication flow with version detection
|
|
47
|
+
// - deviceAuthFlow() - Device authentication flow (LeadCMS >= 1.2.88)
|
|
48
|
+
// - manualTokenFlow() - Manual token extraction (legacy versions)
|
|
49
|
+
// - verifyToken() - Verify API token
|
|
50
|
+
// - saveTokenToEnv() - Save token to .env file
|
|
51
|
+
// - getLeadCMSVersion() - Get LeadCMS instance version
|
|
52
|
+
// - supportsDeviceAuth() - Check if device auth is supported
|
|
26
53
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAK9B,sDAAsD;AACtD,EAAE;AACF,gDAAgD;AAChD,yDAAyD;AACzD,0DAA0D;AAC1D,iEAAiE;AACjE,sDAAsD;AACtD,EAAE;AACF,gBAAgB;AAChB,4DAA4D;AAC5D,uEAAuE;AACvE,kEAAkE;AAClE,wFAAwF;AACxF,iGAAiG;AACjG,sFAAsF;AACtF,EAAE;AACF,6FAA6F;AAC7F,4FAA4F;AAC5F,2DAA2D;AAC3D,EAAE;AACF,oBAAoB;AACpB,0DAA0D;AAC1D,EAAE;AACF,yBAAyB;AACzB,4CAA4C;AAC5C,sCAAsC;AACtC,kDAAkD;AAClD,EAAE;AACF,iBAAiB;AACjB,qFAAqF;AACrF,oFAAoF;AACpF,mEAAmE;AACnE,gEAAgE;AAChE,oEAAoE;AACpE,wDAAwD;AACxD,yDAAyD;AACzD,EAAE;AACF,sBAAsB;AACtB,gFAAgF;AAChF,2EAA2E;AAC3E,sEAAsE;AACtE,6CAA6C;AAC7C,oDAAoD;AACpD,yDAAyD;AACzD,8DAA8D"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LeadCMS Authentication Library
|
|
3
|
+
* Shared authentication functions for device auth and manual token flows
|
|
4
|
+
*/
|
|
5
|
+
interface UserDetailsDto {
|
|
6
|
+
email: string;
|
|
7
|
+
userName: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
data?: Record<string, any> | null;
|
|
10
|
+
id?: string;
|
|
11
|
+
createdAt?: string;
|
|
12
|
+
lastTimeLoggedIn?: string | null;
|
|
13
|
+
avatarUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AuthResult {
|
|
16
|
+
token: string;
|
|
17
|
+
user: UserDetailsDto;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get LeadCMS version from /api/version endpoint
|
|
21
|
+
*/
|
|
22
|
+
export declare function getLeadCMSVersion(url: string): Promise<string | null>;
|
|
23
|
+
/**
|
|
24
|
+
* Compare version strings (supports semver with pre-release tags)
|
|
25
|
+
* Returns: 1 if v1 > v2, -1 if v1 < v2, 0 if equal
|
|
26
|
+
*/
|
|
27
|
+
export declare function compareVersions(v1: string, v2: string): number;
|
|
28
|
+
/**
|
|
29
|
+
* Check if device authentication is supported (version >= 1.2.88-pre)
|
|
30
|
+
*/
|
|
31
|
+
export declare function supportsDeviceAuth(version: string | null): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Verify API token by calling /api/users/me
|
|
34
|
+
*/
|
|
35
|
+
export declare function verifyToken(url: string, token: string): Promise<UserDetailsDto>;
|
|
36
|
+
/**
|
|
37
|
+
* Save API token to .env file
|
|
38
|
+
*/
|
|
39
|
+
export declare function saveTokenToEnv(token: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Device authentication flow
|
|
42
|
+
*/
|
|
43
|
+
export declare function deviceAuthFlow(url: string): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Manual token input flow (legacy)
|
|
46
|
+
* Requires a question function for readline compatibility
|
|
47
|
+
*/
|
|
48
|
+
export declare function manualTokenFlow(url: string, question: (prompt: string) => Promise<string>): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Complete authentication flow with version detection
|
|
51
|
+
* Automatically chooses between device auth and manual flow
|
|
52
|
+
*/
|
|
53
|
+
export declare function authenticate(url: string, question: (prompt: string) => Promise<string>): Promise<AuthResult>;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,UAAU,cAAc;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA+BD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,cAAc,CAAC;CACtB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAU3E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAiB9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAGlE;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAQrF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CA0BlD;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiEjE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAC5C,OAAO,CAAC,MAAM,CAAC,CA0BjB;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAC5C,OAAO,CAAC,UAAU,CAAC,CA6BrB"}
|
package/dist/lib/auth.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LeadCMS Authentication Library
|
|
3
|
+
* Shared authentication functions for device auth and manual token flows
|
|
4
|
+
*/
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
/**
|
|
9
|
+
* Get LeadCMS version from /api/version endpoint
|
|
10
|
+
*/
|
|
11
|
+
export async function getLeadCMSVersion(url) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await axios.get(`${url}/api/version`, {
|
|
14
|
+
timeout: 5000,
|
|
15
|
+
});
|
|
16
|
+
return response.data.version;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
// If version endpoint is not available, return null
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compare version strings (supports semver with pre-release tags)
|
|
25
|
+
* Returns: 1 if v1 > v2, -1 if v1 < v2, 0 if equal
|
|
26
|
+
*/
|
|
27
|
+
export function compareVersions(v1, v2) {
|
|
28
|
+
// Extract version numbers (ignore pre-release tags and git hashes)
|
|
29
|
+
const extractVersion = (v) => {
|
|
30
|
+
const match = v.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
31
|
+
if (!match)
|
|
32
|
+
return [0, 0, 0];
|
|
33
|
+
return [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])];
|
|
34
|
+
};
|
|
35
|
+
const parts1 = extractVersion(v1);
|
|
36
|
+
const parts2 = extractVersion(v2);
|
|
37
|
+
for (let i = 0; i < 3; i++) {
|
|
38
|
+
if (parts1[i] > parts2[i])
|
|
39
|
+
return 1;
|
|
40
|
+
if (parts1[i] < parts2[i])
|
|
41
|
+
return -1;
|
|
42
|
+
}
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if device authentication is supported (version >= 1.2.88-pre)
|
|
47
|
+
*/
|
|
48
|
+
export function supportsDeviceAuth(version) {
|
|
49
|
+
if (!version)
|
|
50
|
+
return false;
|
|
51
|
+
return compareVersions(version, '1.2.88-pre') >= 0;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Verify API token by calling /api/users/me
|
|
55
|
+
*/
|
|
56
|
+
export async function verifyToken(url, token) {
|
|
57
|
+
const response = await axios.get(`${url}/api/users/me`, {
|
|
58
|
+
headers: {
|
|
59
|
+
Authorization: `Bearer ${token}`,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
return response.data;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Save API token to .env file
|
|
66
|
+
*/
|
|
67
|
+
export function saveTokenToEnv(token) {
|
|
68
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
69
|
+
let envContent = '';
|
|
70
|
+
// Read existing .env file if it exists
|
|
71
|
+
if (fs.existsSync(envPath)) {
|
|
72
|
+
envContent = fs.readFileSync(envPath, 'utf-8');
|
|
73
|
+
}
|
|
74
|
+
// Check if LEADCMS_API_KEY already exists
|
|
75
|
+
const lines = envContent.split('\n');
|
|
76
|
+
const apiKeyIndex = lines.findIndex((line) => line.startsWith('LEADCMS_API_KEY='));
|
|
77
|
+
if (apiKeyIndex !== -1) {
|
|
78
|
+
// Update existing key
|
|
79
|
+
lines[apiKeyIndex] = `LEADCMS_API_KEY=${token}`;
|
|
80
|
+
envContent = lines.join('\n');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Add new key
|
|
84
|
+
if (envContent && !envContent.endsWith('\n')) {
|
|
85
|
+
envContent += '\n';
|
|
86
|
+
}
|
|
87
|
+
envContent += `LEADCMS_API_KEY=${token}\n`;
|
|
88
|
+
}
|
|
89
|
+
fs.writeFileSync(envPath, envContent, 'utf-8');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Device authentication flow
|
|
93
|
+
*/
|
|
94
|
+
export async function deviceAuthFlow(url) {
|
|
95
|
+
console.log('\n🔐 Starting device authentication...\n');
|
|
96
|
+
// Step 1: Initiate device authentication
|
|
97
|
+
let initData;
|
|
98
|
+
try {
|
|
99
|
+
const response = await axios.post(`${url}/api/identity/device/initiate`, {}, { headers: { 'Content-Type': 'application/json' } });
|
|
100
|
+
initData = response.data;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new Error(`Failed to initiate device authentication: ${error.message}`);
|
|
104
|
+
}
|
|
105
|
+
// Step 2: Display instructions to user
|
|
106
|
+
console.log('📋 To complete authentication, open this link in your browser:\n');
|
|
107
|
+
console.log(` ${initData.verificationUriComplete}\n`);
|
|
108
|
+
console.log(`⏱️ Code expires in ${Math.floor(initData.expiresIn / 60)} minutes`);
|
|
109
|
+
console.log('⏳ Waiting for authorization...\n');
|
|
110
|
+
// Step 3: Poll for completion
|
|
111
|
+
const pollRequest = { deviceCode: initData.deviceCode };
|
|
112
|
+
const startTime = Date.now();
|
|
113
|
+
const expirationTime = startTime + initData.expiresIn * 1000;
|
|
114
|
+
while (Date.now() < expirationTime) {
|
|
115
|
+
await new Promise((resolve) => setTimeout(resolve, initData.interval * 1000));
|
|
116
|
+
try {
|
|
117
|
+
const pollResponse = await axios.post(`${url}/api/identity/device/poll`, pollRequest, { headers: { 'Content-Type': 'application/json' } });
|
|
118
|
+
if (pollResponse.status === 200) {
|
|
119
|
+
// Authentication successful
|
|
120
|
+
return pollResponse.data.token;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (axios.isAxiosError(error)) {
|
|
125
|
+
if (error.response?.status === 202) {
|
|
126
|
+
// Still pending, continue polling
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
else if (error.response?.status === 400) {
|
|
130
|
+
// Device code expired, denied, or invalid
|
|
131
|
+
const errorData = error.response.data;
|
|
132
|
+
throw new Error(errorData.error_description || errorData.message || 'Device authentication failed');
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Other error
|
|
136
|
+
throw new Error(`Authentication failed: ${error.response?.statusText || error.message}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
throw new Error('Authentication timeout: Code expired');
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Manual token input flow (legacy)
|
|
148
|
+
* Requires a question function for readline compatibility
|
|
149
|
+
*/
|
|
150
|
+
export async function manualTokenFlow(url, question) {
|
|
151
|
+
console.log('\n🔐 LeadCMS Authentication\n');
|
|
152
|
+
console.log('⚠️ Note: This instance does not support automatic device authentication.');
|
|
153
|
+
console.log(' (Device authentication requires LeadCMS version 1.2.88 or higher)');
|
|
154
|
+
console.log(' Please follow these steps to obtain your API token:\n');
|
|
155
|
+
console.log('📋 Steps to get your API token:\n');
|
|
156
|
+
console.log(` 1. Open your browser and navigate to: ${url}`);
|
|
157
|
+
console.log(' 2. Open Developer Tools (press F12 or right-click → Inspect)');
|
|
158
|
+
console.log(' 3. Go to the "Network" tab in Developer Tools');
|
|
159
|
+
console.log(' 4. Log in to your LeadCMS account');
|
|
160
|
+
console.log(' 5. After successful login, look for an API call in the Network tab');
|
|
161
|
+
console.log(' → Look for "/api/users/me" request');
|
|
162
|
+
console.log(' 6. Click on that request');
|
|
163
|
+
console.log(' 7. Find the "Request Headers" section');
|
|
164
|
+
console.log(' 8. Locate the "Authorization" header');
|
|
165
|
+
console.log(' 9. Copy the token value (without the "Bearer " prefix)\n');
|
|
166
|
+
// Prompt for token
|
|
167
|
+
const token = await question('🔑 Paste your API token here: ');
|
|
168
|
+
if (!token) {
|
|
169
|
+
throw new Error('No token provided');
|
|
170
|
+
}
|
|
171
|
+
return token;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Complete authentication flow with version detection
|
|
175
|
+
* Automatically chooses between device auth and manual flow
|
|
176
|
+
*/
|
|
177
|
+
export async function authenticate(url, question) {
|
|
178
|
+
// Check LeadCMS version to determine authentication method
|
|
179
|
+
console.log('🔍 Checking LeadCMS version...');
|
|
180
|
+
const version = await getLeadCMSVersion(url);
|
|
181
|
+
let token;
|
|
182
|
+
if (version) {
|
|
183
|
+
console.log(` Version: ${version}`);
|
|
184
|
+
if (supportsDeviceAuth(version)) {
|
|
185
|
+
// Use device authentication flow
|
|
186
|
+
token = await deviceAuthFlow(url);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
// Use manual token flow
|
|
190
|
+
console.log(' Device authentication not supported in this version.\n');
|
|
191
|
+
token = await manualTokenFlow(url, question);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// Version check failed, use manual flow
|
|
196
|
+
console.log(' Could not determine version, using manual authentication.\n');
|
|
197
|
+
token = await manualTokenFlow(url, question);
|
|
198
|
+
}
|
|
199
|
+
// Verify token
|
|
200
|
+
console.log('\n⏳ Verifying token...');
|
|
201
|
+
const user = await verifyToken(url, token);
|
|
202
|
+
return { token, user };
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AA+C7B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAAW;IACjD,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAkB,GAAG,GAAG,cAAc,EAAE;YACtE,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,oDAAoD;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,EAAU,EAAE,EAAU;IACpD,mEAAmE;IACnE,MAAM,cAAc,GAAG,CAAC,CAAS,EAAY,EAAE;QAC7C,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtE,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MAAM,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAE3C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the /api/config endpoint response
|
|
3
|
+
* This endpoint provides information about the LeadCMS instance configuration
|
|
4
|
+
*/
|
|
5
|
+
export interface CMSConfigResponse {
|
|
6
|
+
/** Authentication configuration */
|
|
7
|
+
auth: {
|
|
8
|
+
methods: string[];
|
|
9
|
+
msal?: {
|
|
10
|
+
clientId: string;
|
|
11
|
+
authority: string;
|
|
12
|
+
redirectUri: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/** Available entity types (Content, Comment, Media, Contact, etc.) */
|
|
16
|
+
entities: string[];
|
|
17
|
+
/** Supported languages */
|
|
18
|
+
languages: Array<{
|
|
19
|
+
code: string;
|
|
20
|
+
name: string;
|
|
21
|
+
}>;
|
|
22
|
+
/** CMS settings */
|
|
23
|
+
settings: Record<string, string>;
|
|
24
|
+
/** Default language code */
|
|
25
|
+
defaultLanguage: string;
|
|
26
|
+
/** Enabled modules */
|
|
27
|
+
modules: string[];
|
|
28
|
+
/** CMS capabilities */
|
|
29
|
+
capabilities: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set the cached CMS config
|
|
33
|
+
*/
|
|
34
|
+
export declare function setCMSConfig(config: CMSConfigResponse): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get the cached CMS config if available and not expired
|
|
37
|
+
*/
|
|
38
|
+
export declare function getCachedCMSConfig(): CMSConfigResponse | null;
|
|
39
|
+
/**
|
|
40
|
+
* Check if an entity type is supported by the CMS
|
|
41
|
+
* @param entityType - Entity type to check (case-insensitive)
|
|
42
|
+
* @returns true if entity is supported, false if not or if config is not available
|
|
43
|
+
*/
|
|
44
|
+
export declare function isEntitySupported(entityType: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check if comments are supported
|
|
47
|
+
*/
|
|
48
|
+
export declare function isCommentsSupported(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check if content is supported
|
|
51
|
+
*/
|
|
52
|
+
export declare function isContentSupported(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Check if media is supported
|
|
55
|
+
*/
|
|
56
|
+
export declare function isMediaSupported(): boolean;
|
|
57
|
+
//# sourceMappingURL=cms-config-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cms-config-types.d.ts","sourceRoot":"","sources":["../../src/lib/cms-config-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,IAAI,CAAC,EAAE;YACL,QAAQ,EAAE,MAAM,CAAC;YACjB,SAAS,EAAE,MAAM,CAAC;YAClB,WAAW,EAAE,MAAM,CAAC;SACrB,CAAC;KACH,CAAC;IACF,sEAAsE;IACtE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,0BAA0B;IAC1B,SAAS,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH,mBAAmB;IACnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,sBAAsB;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,uBAAuB;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAaD;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAK5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,iBAAiB,GAAG,IAAI,CAa7D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAU7D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the /api/config endpoint response
|
|
3
|
+
* This endpoint provides information about the LeadCMS instance configuration
|
|
4
|
+
*/
|
|
5
|
+
let cmsConfigCache = null;
|
|
6
|
+
const CMS_CONFIG_CACHE_TTL = 300000; // 5 minutes
|
|
7
|
+
/**
|
|
8
|
+
* Set the cached CMS config
|
|
9
|
+
*/
|
|
10
|
+
export function setCMSConfig(config) {
|
|
11
|
+
cmsConfigCache = {
|
|
12
|
+
config,
|
|
13
|
+
timestamp: Date.now(),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the cached CMS config if available and not expired
|
|
18
|
+
*/
|
|
19
|
+
export function getCachedCMSConfig() {
|
|
20
|
+
if (!cmsConfigCache) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
if (now - cmsConfigCache.timestamp > CMS_CONFIG_CACHE_TTL) {
|
|
25
|
+
// Cache expired
|
|
26
|
+
cmsConfigCache = null;
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return cmsConfigCache.config;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if an entity type is supported by the CMS
|
|
33
|
+
* @param entityType - Entity type to check (case-insensitive)
|
|
34
|
+
* @returns true if entity is supported, false if not or if config is not available
|
|
35
|
+
*/
|
|
36
|
+
export function isEntitySupported(entityType) {
|
|
37
|
+
const config = getCachedCMSConfig();
|
|
38
|
+
if (!config || !Array.isArray(config.entities)) {
|
|
39
|
+
// If config is not available, assume entity is supported (backward compatibility)
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
// Case-insensitive comparison
|
|
43
|
+
const entityLower = entityType.toLowerCase();
|
|
44
|
+
return config.entities.some(e => e.toLowerCase() === entityLower);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if comments are supported
|
|
48
|
+
*/
|
|
49
|
+
export function isCommentsSupported() {
|
|
50
|
+
return isEntitySupported('Comment');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if content is supported
|
|
54
|
+
*/
|
|
55
|
+
export function isContentSupported() {
|
|
56
|
+
return isEntitySupported('Content');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if media is supported
|
|
60
|
+
*/
|
|
61
|
+
export function isMediaSupported() {
|
|
62
|
+
return isEntitySupported('Media');
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=cms-config-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cms-config-types.js","sourceRoot":"","sources":["../../src/lib/cms-config-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqCH,IAAI,cAAc,GAA0B,IAAI,CAAC;AACjD,MAAM,oBAAoB,GAAG,MAAM,CAAC,CAAC,YAAY;AAEjD;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAyB;IACpD,cAAc,GAAG;QACf,MAAM;QACN,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,GAAG,GAAG,cAAc,CAAC,SAAS,GAAG,oBAAoB,EAAE,CAAC;QAC1D,gBAAgB;QAChB,cAAc,GAAG,IAAI,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,cAAc,CAAC,MAAM,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/C,kFAAkF;QAClF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8BAA8B;IAC9B,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAC7C,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,CAAC;AACpE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,iBAAiB,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,iBAAiB,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/lib/cms.d.ts
CHANGED
|
@@ -143,4 +143,56 @@ export declare function makeLocaleAwareLink(href: string, currentLocale: string)
|
|
|
143
143
|
* @throws {Error} With detailed information about missing files including configName, locale, and expected path
|
|
144
144
|
*/
|
|
145
145
|
export declare function loadContentConfigStrict<T>(configName: string, locale?: string, userUid?: string | null): T;
|
|
146
|
+
/**
|
|
147
|
+
* Get comments for a specific commentable entity
|
|
148
|
+
* @param commentableType - The type of entity (e.g., "Content", "Contact")
|
|
149
|
+
* @param commentableId - The ID of the entity
|
|
150
|
+
* @param language - Language code (optional, uses default language if not provided)
|
|
151
|
+
* @returns Array of comments for the entity, or empty array if none found
|
|
152
|
+
*/
|
|
153
|
+
export declare function getComments(commentableType: string, commentableId: number, language?: string): any[];
|
|
154
|
+
/**
|
|
155
|
+
* Get comments for a specific content item by content ID
|
|
156
|
+
* This is a convenience function that calls getComments with commentableType="Content"
|
|
157
|
+
* @param contentId - The ID of the content
|
|
158
|
+
* @param language - Language code (optional, uses default language if not provided)
|
|
159
|
+
* @returns Array of comments for the content, or empty array if none found
|
|
160
|
+
*/
|
|
161
|
+
export declare function getCommentsForContent(contentId: number, language?: string): any[];
|
|
162
|
+
/**
|
|
163
|
+
* Get comments for a specific commentable entity with strict error handling
|
|
164
|
+
* Unlike getComments, this function throws descriptive errors instead of returning empty array
|
|
165
|
+
* @param commentableType - The type of entity (e.g., "Content", "Contact")
|
|
166
|
+
* @param commentableId - The ID of the entity
|
|
167
|
+
* @param language - Language code (optional, uses default language if not provided)
|
|
168
|
+
* @returns Array of comments for the entity
|
|
169
|
+
* @throws {Error} If comments file cannot be read or parsed
|
|
170
|
+
*/
|
|
171
|
+
export declare function getCommentsStrict(commentableType: string, commentableId: number, language?: string): any[];
|
|
172
|
+
/**
|
|
173
|
+
* Get comments for a specific content item with strict error handling
|
|
174
|
+
* This is a convenience function that calls getCommentsStrict with commentableType="Content"
|
|
175
|
+
* @param contentId - The ID of the content
|
|
176
|
+
* @param language - Language code (optional, uses default language if not provided)
|
|
177
|
+
* @returns Array of comments for the content
|
|
178
|
+
* @throws {Error} If comments file cannot be read or parsed
|
|
179
|
+
*/
|
|
180
|
+
export declare function getCommentsForContentStrict(contentId: number, language?: string): any[];
|
|
181
|
+
/**
|
|
182
|
+
* Get comments as a tree structure with parent-child relationships
|
|
183
|
+
* @param commentableType - The type of entity (e.g., "Content", "Contact")
|
|
184
|
+
* @param commentableId - The ID of the entity
|
|
185
|
+
* @param language - Language code (optional, uses default language if not provided)
|
|
186
|
+
* @param options - Tree building options (sorting, filtering, etc.)
|
|
187
|
+
* @returns Array of root-level comment nodes with nested children
|
|
188
|
+
*/
|
|
189
|
+
export declare function getCommentsTree(commentableType: string, commentableId: number, language?: string, options?: import('./comment-utils.js').CommentTreeOptions): import('./comment-utils.js').CommentTreeNode[];
|
|
190
|
+
/**
|
|
191
|
+
* Get comments tree for content with convenience wrapper
|
|
192
|
+
* @param contentId - The ID of the content
|
|
193
|
+
* @param language - Language code (optional, uses default language if not provided)
|
|
194
|
+
* @param options - Tree building options (sorting, filtering, etc.)
|
|
195
|
+
* @returns Array of root-level comment nodes with nested children
|
|
196
|
+
*/
|
|
197
|
+
export declare function getCommentsTreeForContent(contentId: number, language?: string, options?: import('./comment-utils.js').CommentTreeOptions): import('./comment-utils.js').CommentTreeNode[];
|
|
146
198
|
//# sourceMappingURL=cms.d.ts.map
|
package/dist/lib/cms.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../src/lib/cms.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5D,MAAM,WAAW,YAAY;IAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CAAE;AACrD,MAAM,WAAW,YAAY;IAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CAAE;AAerD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAkB3D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,
|
|
1
|
+
{"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../src/lib/cms.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5D,MAAM,WAAW,YAAY;IAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CAAE;AACrD,MAAM,WAAW,YAAY;IAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CAAE;AAerD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,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