@gravitek/confluence-mirror-core 0.2.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/README.md +141 -0
- package/dist/client/auth-strategies.d.ts +49 -0
- package/dist/client/auth-strategies.js +69 -0
- package/dist/client/cloud-id-manager.d.ts +34 -0
- package/dist/client/cloud-id-manager.js +56 -0
- package/dist/client/confluence-client.d.ts +98 -0
- package/dist/client/confluence-client.js +222 -0
- package/dist/client/oauth2-token-manager.d.ts +40 -0
- package/dist/client/oauth2-token-manager.js +73 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +14 -0
- package/dist/processors/adf-processor.d.ts +4 -0
- package/dist/processors/adf-processor.js +37 -0
- package/dist/processors/link-processor.d.ts +35 -0
- package/dist/processors/link-processor.js +174 -0
- package/dist/processors/media-processor.d.ts +2 -0
- package/dist/processors/media-processor.js +160 -0
- package/dist/processors/toc-processor.d.ts +5 -0
- package/dist/processors/toc-processor.js +90 -0
- package/dist/types/index.d.ts +67 -0
- package/dist/types/index.js +7 -0
- package/dist/utils/url-transformer.d.ts +80 -0
- package/dist/utils/url-transformer.js +116 -0
- package/package.json +38 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface ADFNode {
|
|
2
|
+
type: string;
|
|
3
|
+
attrs?: Record<string, any>;
|
|
4
|
+
content?: ADFNode[];
|
|
5
|
+
text?: string;
|
|
6
|
+
marks?: Array<{
|
|
7
|
+
type: string;
|
|
8
|
+
attrs?: Record<string, any>;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export interface ADFDocument {
|
|
12
|
+
version: number;
|
|
13
|
+
type: "doc";
|
|
14
|
+
content: ADFNode[];
|
|
15
|
+
}
|
|
16
|
+
export interface ConfluencePage {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
body: {
|
|
20
|
+
atlas_doc_format?: {
|
|
21
|
+
value: string;
|
|
22
|
+
};
|
|
23
|
+
storage?: {
|
|
24
|
+
value: string;
|
|
25
|
+
representation: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
version: {
|
|
29
|
+
number: number;
|
|
30
|
+
when?: string;
|
|
31
|
+
by?: {
|
|
32
|
+
displayName: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
space: {
|
|
37
|
+
key: string;
|
|
38
|
+
name: string;
|
|
39
|
+
};
|
|
40
|
+
_links: {
|
|
41
|
+
webui: string;
|
|
42
|
+
};
|
|
43
|
+
children?: {
|
|
44
|
+
page?: {
|
|
45
|
+
results: ConfluenceChildPage[];
|
|
46
|
+
size: number;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface ConfluenceChildPage {
|
|
51
|
+
id: string;
|
|
52
|
+
title: string;
|
|
53
|
+
type: string;
|
|
54
|
+
status: string;
|
|
55
|
+
_links: {
|
|
56
|
+
webui: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface TocItem {
|
|
60
|
+
id: string;
|
|
61
|
+
title: string;
|
|
62
|
+
level: number;
|
|
63
|
+
}
|
|
64
|
+
export declare class ConfluenceApiError extends Error {
|
|
65
|
+
statusCode?: number;
|
|
66
|
+
constructor(message: string, statusCode?: number);
|
|
67
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform Confluence URLs to local viewer URLs
|
|
3
|
+
*
|
|
4
|
+
* This utility helps convert Confluence page URLs to local application URLs
|
|
5
|
+
* for seamless internal navigation while preserving external Confluence links.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const transformer = new UrlTransformer({
|
|
10
|
+
* confluenceBaseUrl: 'https://mycompany.atlassian.net',
|
|
11
|
+
* localBaseUrl: 'http://localhost:3000'
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* // Transform Confluence page URL to local URL
|
|
15
|
+
* const localUrl = transformer.toLocalUrl('https://mycompany.atlassian.net/wiki/pages/123456/Page+Title');
|
|
16
|
+
* // Returns: 'http://localhost:3000/?pageId=123456'
|
|
17
|
+
*
|
|
18
|
+
* // Check if URL should be transformed
|
|
19
|
+
* if (transformer.shouldTransform('https://mycompany.atlassian.net/wiki/pages/123456')) {
|
|
20
|
+
* // URL points to a Confluence page
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class UrlTransformer {
|
|
25
|
+
private readonly confluenceBaseUrl;
|
|
26
|
+
private readonly localBaseUrl;
|
|
27
|
+
/**
|
|
28
|
+
* Create a URL transformer
|
|
29
|
+
*
|
|
30
|
+
* @param options - Configuration options
|
|
31
|
+
* @param options.confluenceBaseUrl - Base URL of the Confluence instance (e.g., https://your-domain.atlassian.net)
|
|
32
|
+
* @param options.localBaseUrl - Base URL of the local viewer application (e.g., http://localhost:3000)
|
|
33
|
+
*/
|
|
34
|
+
constructor(options: {
|
|
35
|
+
confluenceBaseUrl: string;
|
|
36
|
+
localBaseUrl: string;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Check if a URL should be transformed to a local viewer URL
|
|
40
|
+
*
|
|
41
|
+
* Returns true if:
|
|
42
|
+
* 1. The URL points to the configured Confluence instance
|
|
43
|
+
* 2. A page ID can be extracted from the URL
|
|
44
|
+
*
|
|
45
|
+
* @param url - URL to check
|
|
46
|
+
* @returns true if URL should be transformed
|
|
47
|
+
*/
|
|
48
|
+
shouldTransform(url: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Transform a Confluence URL to a local viewer URL
|
|
51
|
+
*
|
|
52
|
+
* Extracts the page ID from the Confluence URL and creates a local URL
|
|
53
|
+
* with the page ID as a query parameter.
|
|
54
|
+
*
|
|
55
|
+
* @param confluenceUrl - Confluence page URL to transform
|
|
56
|
+
* @returns Local viewer URL with pageId query parameter, or original URL if transformation fails
|
|
57
|
+
*/
|
|
58
|
+
toLocalUrl(confluenceUrl: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Batch transform multiple URLs
|
|
61
|
+
*
|
|
62
|
+
* @param urls - Array of URLs to transform
|
|
63
|
+
* @returns Array of transformed URLs (same order as input)
|
|
64
|
+
*/
|
|
65
|
+
toLocalUrls(urls: string[]): string[];
|
|
66
|
+
/**
|
|
67
|
+
* Get the original Confluence URL from a local viewer URL
|
|
68
|
+
*
|
|
69
|
+
* This is useful for "View in Confluence" links that should always
|
|
70
|
+
* point to the original Confluence instance.
|
|
71
|
+
*
|
|
72
|
+
* Note: This method cannot reconstruct the full original URL (with space and title)
|
|
73
|
+
* because that information is not preserved in the local URL format.
|
|
74
|
+
* It returns a basic /pages/{pageId} format URL.
|
|
75
|
+
*
|
|
76
|
+
* @param localUrl - Local viewer URL
|
|
77
|
+
* @returns Confluence URL, or original URL if not a local viewer URL
|
|
78
|
+
*/
|
|
79
|
+
toConfluenceUrl(localUrl: string): string;
|
|
80
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ConfluenceClient } from "../client/confluence-client";
|
|
2
|
+
/**
|
|
3
|
+
* Transform Confluence URLs to local viewer URLs
|
|
4
|
+
*
|
|
5
|
+
* This utility helps convert Confluence page URLs to local application URLs
|
|
6
|
+
* for seamless internal navigation while preserving external Confluence links.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const transformer = new UrlTransformer({
|
|
11
|
+
* confluenceBaseUrl: 'https://mycompany.atlassian.net',
|
|
12
|
+
* localBaseUrl: 'http://localhost:3000'
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Transform Confluence page URL to local URL
|
|
16
|
+
* const localUrl = transformer.toLocalUrl('https://mycompany.atlassian.net/wiki/pages/123456/Page+Title');
|
|
17
|
+
* // Returns: 'http://localhost:3000/?pageId=123456'
|
|
18
|
+
*
|
|
19
|
+
* // Check if URL should be transformed
|
|
20
|
+
* if (transformer.shouldTransform('https://mycompany.atlassian.net/wiki/pages/123456')) {
|
|
21
|
+
* // URL points to a Confluence page
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class UrlTransformer {
|
|
26
|
+
/**
|
|
27
|
+
* Create a URL transformer
|
|
28
|
+
*
|
|
29
|
+
* @param options - Configuration options
|
|
30
|
+
* @param options.confluenceBaseUrl - Base URL of the Confluence instance (e.g., https://your-domain.atlassian.net)
|
|
31
|
+
* @param options.localBaseUrl - Base URL of the local viewer application (e.g., http://localhost:3000)
|
|
32
|
+
*/
|
|
33
|
+
constructor(options) {
|
|
34
|
+
this.confluenceBaseUrl = options.confluenceBaseUrl.replace(/\/$/, "");
|
|
35
|
+
this.localBaseUrl = options.localBaseUrl.replace(/\/$/, "");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if a URL should be transformed to a local viewer URL
|
|
39
|
+
*
|
|
40
|
+
* Returns true if:
|
|
41
|
+
* 1. The URL points to the configured Confluence instance
|
|
42
|
+
* 2. A page ID can be extracted from the URL
|
|
43
|
+
*
|
|
44
|
+
* @param url - URL to check
|
|
45
|
+
* @returns true if URL should be transformed
|
|
46
|
+
*/
|
|
47
|
+
shouldTransform(url) {
|
|
48
|
+
try {
|
|
49
|
+
// Check if URL starts with the Confluence base URL
|
|
50
|
+
if (!url.startsWith(this.confluenceBaseUrl)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
// Check if we can extract a page ID
|
|
54
|
+
const pageId = ConfluenceClient.extractPageIdFromUrl(url);
|
|
55
|
+
return pageId !== null;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Transform a Confluence URL to a local viewer URL
|
|
63
|
+
*
|
|
64
|
+
* Extracts the page ID from the Confluence URL and creates a local URL
|
|
65
|
+
* with the page ID as a query parameter.
|
|
66
|
+
*
|
|
67
|
+
* @param confluenceUrl - Confluence page URL to transform
|
|
68
|
+
* @returns Local viewer URL with pageId query parameter, or original URL if transformation fails
|
|
69
|
+
*/
|
|
70
|
+
toLocalUrl(confluenceUrl) {
|
|
71
|
+
if (!this.shouldTransform(confluenceUrl)) {
|
|
72
|
+
return confluenceUrl;
|
|
73
|
+
}
|
|
74
|
+
const pageId = ConfluenceClient.extractPageIdFromUrl(confluenceUrl);
|
|
75
|
+
if (!pageId) {
|
|
76
|
+
return confluenceUrl;
|
|
77
|
+
}
|
|
78
|
+
return `${this.localBaseUrl}/?pageId=${pageId}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Batch transform multiple URLs
|
|
82
|
+
*
|
|
83
|
+
* @param urls - Array of URLs to transform
|
|
84
|
+
* @returns Array of transformed URLs (same order as input)
|
|
85
|
+
*/
|
|
86
|
+
toLocalUrls(urls) {
|
|
87
|
+
return urls.map((url) => this.toLocalUrl(url));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the original Confluence URL from a local viewer URL
|
|
91
|
+
*
|
|
92
|
+
* This is useful for "View in Confluence" links that should always
|
|
93
|
+
* point to the original Confluence instance.
|
|
94
|
+
*
|
|
95
|
+
* Note: This method cannot reconstruct the full original URL (with space and title)
|
|
96
|
+
* because that information is not preserved in the local URL format.
|
|
97
|
+
* It returns a basic /pages/{pageId} format URL.
|
|
98
|
+
*
|
|
99
|
+
* @param localUrl - Local viewer URL
|
|
100
|
+
* @returns Confluence URL, or original URL if not a local viewer URL
|
|
101
|
+
*/
|
|
102
|
+
toConfluenceUrl(localUrl) {
|
|
103
|
+
try {
|
|
104
|
+
const url = new URL(localUrl);
|
|
105
|
+
const pageId = url.searchParams.get("pageId");
|
|
106
|
+
if (!pageId) {
|
|
107
|
+
return localUrl;
|
|
108
|
+
}
|
|
109
|
+
// Return basic Confluence URL format
|
|
110
|
+
return `${this.confluenceBaseUrl}/wiki/pages/${pageId}`;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return localUrl;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gravitek/confluence-mirror-core",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Core logic for Confluence page rendering - API client, ADF processing, media handling. Unofficial, not affiliated with Atlassian.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"clean": "rm -rf dist"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"confluence",
|
|
17
|
+
"adf",
|
|
18
|
+
"atlas-document-format",
|
|
19
|
+
"api-client",
|
|
20
|
+
"atlassian"
|
|
21
|
+
],
|
|
22
|
+
"author": "Gravitek <hello@gravitek.io>",
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/Gravitek-io/confluence-mirror.git",
|
|
27
|
+
"directory": "packages/core"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/Gravitek-io/confluence-mirror.git",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5",
|
|
32
|
+
"@types/node": "^20"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|