@salesforcedevs/docs-components 1.3.209-alpha.10 → 1.3.209-alpha2
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/lwc.config.json +2 -0
- package/package.json +3 -1
- package/src/modules/doc/atlasContent/atlasContent.css +52 -0
- package/src/modules/doc/atlasContent/atlasContent.html +48 -0
- package/src/modules/doc/atlasContent/atlasContent.ts +111 -0
- package/src/modules/doc/contentLayout/contentLayout.ts +13 -15
- package/src/modules/doc/xmlContent/types.ts +106 -0
- package/src/modules/doc/xmlContent/utils.ts +1 -3
- package/src/modules/doc/zoominContent/mockResponses.ts +5226 -0
- package/src/modules/doc/zoominContent/zoominContent.css +52 -0
- package/src/modules/doc/zoominContent/zoominContent.html +48 -0
- package/src/modules/doc/zoominContent/zoominContent.ts +484 -0
- package/src/modules/doc/zoominContent/zoominUtils.ts +93 -0
- package/src/modules/docBaseElements/baseContentElement/baseContentElement.ts +780 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
--button-primary-color: var(--dx-g-blue-vibrant-50);
|
|
3
|
+
--button-primary-color-hover: var(--dx-g-blue-vibrant-40);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
doc-content-layout {
|
|
7
|
+
--dx-c-content-sidebar-sticky-top: calc(
|
|
8
|
+
var(--dx-g-global-header-height) +
|
|
9
|
+
var(--dx-g-doc-header-main-nav-height)
|
|
10
|
+
);
|
|
11
|
+
--dx-c-sidebar-height: calc(
|
|
12
|
+
100vh -
|
|
13
|
+
calc(
|
|
14
|
+
var(--dx-g-global-header-height) +
|
|
15
|
+
var(--dx-g-doc-header-main-nav-height)
|
|
16
|
+
)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
doc-breadcrumbs {
|
|
21
|
+
--dx-c-popover-z-index: 5;
|
|
22
|
+
|
|
23
|
+
display: block;
|
|
24
|
+
margin-bottom: var(--dx-g-spacing-md);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
dx-dropdown {
|
|
28
|
+
--dx-c-dropdown-option-font-size: var(--dx-g-text-sm);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
dx-dropdown > dx-button {
|
|
32
|
+
--dx-c-button-primary-color: var(--button-primary-color);
|
|
33
|
+
--dx-c-button-primary-color-hover: var(--button-primary-color-hover);
|
|
34
|
+
--border-color: var(--button-primary-color);
|
|
35
|
+
|
|
36
|
+
border-bottom: 1px dashed var(--border-color);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
dx-dropdown > dx-button:hover {
|
|
40
|
+
--border-color: var(--button-primary-color-hover);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.document-pickers {
|
|
44
|
+
margin-left: auto;
|
|
45
|
+
margin-right: var(--dx-g-spacing-sm);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
doc-phase {
|
|
49
|
+
--doc-c-phase-top: calc(
|
|
50
|
+
var(--dx-g-global-header-height) + var(--dx-g-doc-header-height)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<doc-content-layout
|
|
3
|
+
if:true={loaded}
|
|
4
|
+
coveo-organization-id={coveoOrganizationId}
|
|
5
|
+
coveo-public-access-token={coveoPublicAccessToken}
|
|
6
|
+
coveo-analytics-token={coveoAnalyticsToken}
|
|
7
|
+
coveo-search-hub={coveoSearchHub}
|
|
8
|
+
coveo-advanced-query-config={coveoAdvancedQueryConfig}
|
|
9
|
+
sidebar-header="Pages"
|
|
10
|
+
sidebar-content={sidebarContent}
|
|
11
|
+
sidebar-value={sidebarValue}
|
|
12
|
+
onselect={handleSelect}
|
|
13
|
+
use-old-sidebar={useOldSidebar}
|
|
14
|
+
>
|
|
15
|
+
<doc-phase
|
|
16
|
+
slot="version-banner"
|
|
17
|
+
if:true={showVersionBanner}
|
|
18
|
+
doc-phase-info={oldVersionInfo}
|
|
19
|
+
icon-name="warning"
|
|
20
|
+
dismissible="true"
|
|
21
|
+
ondismissphase={handleDismissVersionBanner}
|
|
22
|
+
></doc-phase>
|
|
23
|
+
<div slot="sidebar-header" class="document-pickers">
|
|
24
|
+
<dx-dropdown
|
|
25
|
+
data-type="version"
|
|
26
|
+
analytics-event="custEv_ctaLinkClick"
|
|
27
|
+
analytics-payload={ANALYTICS_PAYLOAD}
|
|
28
|
+
options={versionOptions}
|
|
29
|
+
value={version.id}
|
|
30
|
+
width="290px"
|
|
31
|
+
>
|
|
32
|
+
<dx-button variant="inline" disabled={disableVersion}>
|
|
33
|
+
{version.releaseVersion}
|
|
34
|
+
</dx-button>
|
|
35
|
+
</dx-dropdown>
|
|
36
|
+
</div>
|
|
37
|
+
<doc-breadcrumbs
|
|
38
|
+
if:true={showBreadcrumbs}
|
|
39
|
+
breadcrumbs={breadcrumbs}
|
|
40
|
+
pixel-per-character={breadcrumbPixelPerCharacter}
|
|
41
|
+
></doc-breadcrumbs>
|
|
42
|
+
<doc-content
|
|
43
|
+
docs-data={docContent}
|
|
44
|
+
page-reference={pageReference}
|
|
45
|
+
onnavclick={handleNavClick}
|
|
46
|
+
></doc-content>
|
|
47
|
+
</doc-content-layout>
|
|
48
|
+
</template>
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiDocLanguage,
|
|
3
|
+
ApiDocVersion,
|
|
4
|
+
ApiNavItem,
|
|
5
|
+
DocLanguage,
|
|
6
|
+
DocVersion,
|
|
7
|
+
DocumentData,
|
|
8
|
+
HistoryState,
|
|
9
|
+
PageReference,
|
|
10
|
+
TocMap,
|
|
11
|
+
TreeNode,
|
|
12
|
+
ZoominApiNavItem,
|
|
13
|
+
ZoominDocContent
|
|
14
|
+
} from "../xmlContent/types";
|
|
15
|
+
import { Language } from "typings/custom";
|
|
16
|
+
import { BaseContentElement } from "docBaseElements/baseContentElement";
|
|
17
|
+
|
|
18
|
+
import mockResponses from "./mockResponses";
|
|
19
|
+
import { ZoominFetchContent } from "./zoominUtils";
|
|
20
|
+
|
|
21
|
+
export default class DocZoomInContent extends BaseContentElement {
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
this.contentProvider = new ZoominFetchContent(
|
|
24
|
+
this.apiDomain,
|
|
25
|
+
this.allLanguages
|
|
26
|
+
);
|
|
27
|
+
this.fetchDocument().then(() => (this.loaded = true));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getReferenceFromUrl(): PageReference {
|
|
31
|
+
//console.log(`get Reference from URL ${window.location.pathname}`);
|
|
32
|
+
|
|
33
|
+
// const [
|
|
34
|
+
// page,
|
|
35
|
+
// docId,
|
|
36
|
+
// deliverable,
|
|
37
|
+
// contentDocumentId
|
|
38
|
+
// ] = window.location.pathname.substr(1).split("/");
|
|
39
|
+
|
|
40
|
+
// const { origin: domain, hash, search } = window.location;
|
|
41
|
+
|
|
42
|
+
const [page, docId, deliverable, contentDocumentId] =
|
|
43
|
+
"/docs/atlas.en-us.bi_dev_guide_ext_data.meta/bi_dev_guide_ext_data/bi_ext_data_overview.htm"
|
|
44
|
+
.substr(1)
|
|
45
|
+
.split("/");
|
|
46
|
+
|
|
47
|
+
const domain = "localhost:3000";
|
|
48
|
+
const hash = "";
|
|
49
|
+
const search = "";
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
contentDocumentId,
|
|
53
|
+
deliverable,
|
|
54
|
+
docId,
|
|
55
|
+
domain,
|
|
56
|
+
hash,
|
|
57
|
+
page,
|
|
58
|
+
search
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// async fetchDocument(): Promise<void> {
|
|
63
|
+
// this.setState({
|
|
64
|
+
// isFetchingDocument: true
|
|
65
|
+
// });
|
|
66
|
+
// console.log(`Fetching doc --> ${this.pageReference.docId}`)
|
|
67
|
+
// // const data = await this.contentProvider!.fetchDocumentData(
|
|
68
|
+
// // this.pageReference.docId!
|
|
69
|
+
// // );
|
|
70
|
+
// // const {
|
|
71
|
+
// // available_languages,
|
|
72
|
+
// // available_versions,
|
|
73
|
+
// // toc,
|
|
74
|
+
// // content,
|
|
75
|
+
// // version,
|
|
76
|
+
// // language,
|
|
77
|
+
// // content_document_id,
|
|
78
|
+
// // title,
|
|
79
|
+
// // doc_title,
|
|
80
|
+
// // pdf_url,
|
|
81
|
+
// // deliverable
|
|
82
|
+
// // } = zoominResponse;
|
|
83
|
+
|
|
84
|
+
// const toc = zoominToc;
|
|
85
|
+
// this.docTitle = toc.title || "";
|
|
86
|
+
// this.tocMap = data.tocMap;
|
|
87
|
+
// this.sidebarContent = data.toc;
|
|
88
|
+
// this.version = data.version;
|
|
89
|
+
// this.language = data.language;
|
|
90
|
+
// this.availableLanguages = data.availableLanguages;
|
|
91
|
+
// this.availableVersions = data.availableVersions;
|
|
92
|
+
// this.pdfUrl = data.pdfUrl;
|
|
93
|
+
|
|
94
|
+
// const { normalizedToc, tocMap } = this.normalizeToc(toc);
|
|
95
|
+
|
|
96
|
+
// const data = {
|
|
97
|
+
// availableLanguages:
|
|
98
|
+
// available_languages &&
|
|
99
|
+
// available_languages.map(this.normalizeLanguage.bind(this)),
|
|
100
|
+
// availableVersions:
|
|
101
|
+
// available_versions &&
|
|
102
|
+
// available_versions.map(this.normalizeVersion.bind(this)),
|
|
103
|
+
// content,
|
|
104
|
+
// version: this.normalizeVersion(version),
|
|
105
|
+
// id: content_document_id,
|
|
106
|
+
// language: this.normalizeLanguage(language),
|
|
107
|
+
// title,
|
|
108
|
+
// toc: normalizedToc,
|
|
109
|
+
// tocMap,
|
|
110
|
+
// docTitle: doc_title,
|
|
111
|
+
// pdfUrl: pdf_url,
|
|
112
|
+
// deliverable
|
|
113
|
+
// };
|
|
114
|
+
|
|
115
|
+
// //const data = zoominResponse;
|
|
116
|
+
|
|
117
|
+
// // This could be a 404 scenario.
|
|
118
|
+
// if (!data) {
|
|
119
|
+
// this.setState({
|
|
120
|
+
// isFetchingDocument: false
|
|
121
|
+
// });
|
|
122
|
+
// return;
|
|
123
|
+
// }
|
|
124
|
+
|
|
125
|
+
// this.docTitle = data.docTitle;
|
|
126
|
+
// this.tocMap = data.tocMap;
|
|
127
|
+
// this.sidebarContent = data.toc;
|
|
128
|
+
// this.version = data.version;
|
|
129
|
+
// this.language = data.language;
|
|
130
|
+
// this.availableLanguages = data.availableLanguages;
|
|
131
|
+
// this.availableVersions = data.availableVersions;
|
|
132
|
+
// this.pdfUrl = data.pdfUrl;
|
|
133
|
+
|
|
134
|
+
// this.updateHeader();
|
|
135
|
+
|
|
136
|
+
// this.buildBreadcrumbs();
|
|
137
|
+
|
|
138
|
+
// if (this.pageReference.deliverable !== data.deliverable) {
|
|
139
|
+
// this.pageReference.deliverable = data.deliverable;
|
|
140
|
+
// this.updateUrl(HistoryState.REPLACE_STATE);
|
|
141
|
+
// }
|
|
142
|
+
|
|
143
|
+
// if (this.oldVersionInfo) {
|
|
144
|
+
// this.showVersionBanner = true;
|
|
145
|
+
// }
|
|
146
|
+
|
|
147
|
+
// if (
|
|
148
|
+
// this.pageReference?.contentDocumentId?.replace(/\.htm$/, "") !==
|
|
149
|
+
// data.id
|
|
150
|
+
// ) {
|
|
151
|
+
// try {
|
|
152
|
+
// await this.fetchContent();
|
|
153
|
+
// this.setState({
|
|
154
|
+
// isFetchingDocument: false
|
|
155
|
+
// });
|
|
156
|
+
// return;
|
|
157
|
+
// } catch (error) {
|
|
158
|
+
// this.pageReference.contentDocumentId = `${data.id}.htm`;
|
|
159
|
+
// this.pageReference.hash = "";
|
|
160
|
+
// this.pageReference.search = "";
|
|
161
|
+
// this.updateUrl(HistoryState.REPLACE_STATE);
|
|
162
|
+
// }
|
|
163
|
+
// }
|
|
164
|
+
|
|
165
|
+
// this.docContent = data.content;
|
|
166
|
+
// this.addMetatags();
|
|
167
|
+
// this.setState({
|
|
168
|
+
// isFetchingDocument: false
|
|
169
|
+
// });
|
|
170
|
+
// }
|
|
171
|
+
|
|
172
|
+
async fetchDocument(): Promise<void> {
|
|
173
|
+
this.setState({
|
|
174
|
+
isFetchingDocument: true
|
|
175
|
+
});
|
|
176
|
+
// const data = await this.contentProvider!.fetchDocumentData(
|
|
177
|
+
// this.pageReference.docId!
|
|
178
|
+
// );
|
|
179
|
+
|
|
180
|
+
console.log("Get this doc ID now ---> " + this.pageReference.docId);
|
|
181
|
+
|
|
182
|
+
const data = await this.mockedFetchDocumentData(
|
|
183
|
+
this.pageReference.docId!
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
//const data = zoominResponse;
|
|
187
|
+
|
|
188
|
+
// This could be a 404 scenario.
|
|
189
|
+
if (!data) {
|
|
190
|
+
this.setState({
|
|
191
|
+
isFetchingDocument: false
|
|
192
|
+
});
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
this.docTitle = data.docTitle;
|
|
197
|
+
this.tocMap = data.tocMap;
|
|
198
|
+
this.sidebarContent = data.toc;
|
|
199
|
+
this.version = data.version;
|
|
200
|
+
this.language = data.language;
|
|
201
|
+
this.availableLanguages = data.availableLanguages;
|
|
202
|
+
this.availableVersions = data.availableVersions;
|
|
203
|
+
this.pdfUrl = data.pdfUrl;
|
|
204
|
+
|
|
205
|
+
this.updateHeader();
|
|
206
|
+
|
|
207
|
+
this.buildBreadcrumbs();
|
|
208
|
+
|
|
209
|
+
if (this.pageReference.deliverable !== data.deliverable) {
|
|
210
|
+
this.pageReference.deliverable = data.deliverable;
|
|
211
|
+
// we need the below line - commented for testing only
|
|
212
|
+
//this.updateUrl(HistoryState.REPLACE_STATE);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (this.oldVersionInfo) {
|
|
216
|
+
this.showVersionBanner = true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (
|
|
220
|
+
this.pageReference?.contentDocumentId?.replace(/\.htm$/, "") !==
|
|
221
|
+
data.id
|
|
222
|
+
) {
|
|
223
|
+
try {
|
|
224
|
+
await this.fetchContent();
|
|
225
|
+
this.setState({
|
|
226
|
+
isFetchingDocument: false
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
} catch (error) {
|
|
230
|
+
this.pageReference.contentDocumentId = `${data.id}.htm`;
|
|
231
|
+
this.pageReference.hash = "";
|
|
232
|
+
this.pageReference.search = "";
|
|
233
|
+
this.updateUrl(HistoryState.REPLACE_STATE);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
this.docContent = data.content;
|
|
238
|
+
this.addMetatags();
|
|
239
|
+
this.setState({
|
|
240
|
+
isFetchingDocument: false
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async fetchContent(): Promise<void> {
|
|
245
|
+
this.setState({
|
|
246
|
+
isFetchingContent: true
|
|
247
|
+
});
|
|
248
|
+
// const data = await this.contentProvider!.fetchContent(
|
|
249
|
+
// this.pageReference.deliverable!,
|
|
250
|
+
// this.pageReference.contentDocumentId!,
|
|
251
|
+
// {
|
|
252
|
+
// language: this.language!.id,
|
|
253
|
+
// version: this.version!.id
|
|
254
|
+
// }
|
|
255
|
+
// );
|
|
256
|
+
// Working
|
|
257
|
+
//const data = mockResponses.zoominFetchDocContent;
|
|
258
|
+
|
|
259
|
+
const data: ZoominDocContent = await this.contentProvider!.fetchContent(
|
|
260
|
+
this.pageReference.deliverable!,
|
|
261
|
+
this.pageReference.contentDocumentId!,
|
|
262
|
+
{
|
|
263
|
+
language: this.language!.id,
|
|
264
|
+
version: this.version!.id
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// const data = await this.contentProvider!.zoominFetchContent(
|
|
269
|
+
// this.pageReference.deliverable!,
|
|
270
|
+
// this.pageReference.contentDocumentId!,
|
|
271
|
+
// {
|
|
272
|
+
// language: this.language!.id,
|
|
273
|
+
// version: this.version!.id
|
|
274
|
+
// }
|
|
275
|
+
// )
|
|
276
|
+
|
|
277
|
+
if (data) {
|
|
278
|
+
this.docContent = data.topic_html;
|
|
279
|
+
this.addMetatags();
|
|
280
|
+
|
|
281
|
+
if (!this.pageReference.hash) {
|
|
282
|
+
document.body.scrollIntoView();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
this.setState({
|
|
286
|
+
isFetchingContent: false
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async mockedFetchDocumentData(docId: string): Promise<DocumentData | null> {
|
|
291
|
+
try {
|
|
292
|
+
console.log(`Doc requested ${docId} `);
|
|
293
|
+
//const zoominToc: Array<ZoominApiNavItem> = mockResponses.zoominToc;
|
|
294
|
+
const zoominToc: Array<ZoominApiNavItem> =
|
|
295
|
+
await this.contentProvider!.fetchDocumentData(
|
|
296
|
+
this.pageReference.docId!
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
const atlastToc = this.transformZoominTocToAtlasToc(zoominToc);
|
|
300
|
+
const { normalizedToc, tocMap } = this.normalizeToc(atlastToc);
|
|
301
|
+
|
|
302
|
+
const zoominDocData = mockResponses.zoominFetchDocContent;
|
|
303
|
+
|
|
304
|
+
// const {
|
|
305
|
+
// available_languages,
|
|
306
|
+
// available_versions=[],
|
|
307
|
+
// content,
|
|
308
|
+
// version,
|
|
309
|
+
// language,
|
|
310
|
+
// content_document_id,
|
|
311
|
+
// title,
|
|
312
|
+
// doc_title,
|
|
313
|
+
// pdf_url,
|
|
314
|
+
// deliverable
|
|
315
|
+
// } = zoominDocData;
|
|
316
|
+
|
|
317
|
+
//const available_languages = zoominDocData.available_languages;
|
|
318
|
+
//const available_versions: ApiDocVersion[] = [];
|
|
319
|
+
const pdf_url = zoominDocData.preprocessed_PDF || "";
|
|
320
|
+
const deliverable = zoominDocData.page_id;
|
|
321
|
+
const docContent = zoominDocData.labels_text;
|
|
322
|
+
const docTitle = zoominDocData.title;
|
|
323
|
+
const version = "atlas.en-us.apexcode.meta";
|
|
324
|
+
const language = "en-us";
|
|
325
|
+
const content_document_id = zoominDocData.bundle_id;
|
|
326
|
+
const title = zoominDocData.title;
|
|
327
|
+
|
|
328
|
+
const mock_available_versions = [
|
|
329
|
+
{
|
|
330
|
+
version_text: "Winter '24 (API version 59.0)",
|
|
331
|
+
release_version: "59.0",
|
|
332
|
+
doc_version: "246.0",
|
|
333
|
+
version_url: "atlas.en-us.apexcode.meta"
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
version_text: "Summer '23 (API version 58.0)",
|
|
337
|
+
release_version: "58.0",
|
|
338
|
+
doc_version: "244.0",
|
|
339
|
+
version_url: "atlas.en-us.244.0.apexcode.meta"
|
|
340
|
+
}
|
|
341
|
+
];
|
|
342
|
+
const mock_available_languages = [
|
|
343
|
+
{
|
|
344
|
+
label: "ENGLISH",
|
|
345
|
+
code: "EN",
|
|
346
|
+
locale: "en-us",
|
|
347
|
+
url: "atlas.en-us.246.0.apexcode.meta"
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
label: "JAPANESE",
|
|
351
|
+
code: "JA",
|
|
352
|
+
locale: "ja-jp",
|
|
353
|
+
url: "atlas.ja-jp.246.0.apexcode.meta"
|
|
354
|
+
}
|
|
355
|
+
];
|
|
356
|
+
|
|
357
|
+
return {
|
|
358
|
+
availableLanguages:
|
|
359
|
+
mock_available_languages &&
|
|
360
|
+
mock_available_languages.map(
|
|
361
|
+
this.normalizeLanguage.bind(this)
|
|
362
|
+
),
|
|
363
|
+
availableVersions:
|
|
364
|
+
mock_available_versions &&
|
|
365
|
+
mock_available_versions.map(
|
|
366
|
+
this.normalizeVersion.bind(this)
|
|
367
|
+
),
|
|
368
|
+
content: docContent,
|
|
369
|
+
version: this.normalizeVersion(version),
|
|
370
|
+
id: content_document_id,
|
|
371
|
+
language: this.normalizeLanguage(language),
|
|
372
|
+
title,
|
|
373
|
+
toc: normalizedToc,
|
|
374
|
+
tocMap,
|
|
375
|
+
docTitle,
|
|
376
|
+
pdfUrl: pdf_url,
|
|
377
|
+
deliverable
|
|
378
|
+
};
|
|
379
|
+
} catch (error) {
|
|
380
|
+
console.log(error);
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
transformZoominTocToAtlasToc(
|
|
386
|
+
zoominToc: ZoominApiNavItem[]
|
|
387
|
+
): Array<ApiNavItem> {
|
|
388
|
+
if (!zoominToc) {
|
|
389
|
+
return [];
|
|
390
|
+
}
|
|
391
|
+
console.log(`transformZoominTocToAtlasToc ${zoominToc}`);
|
|
392
|
+
|
|
393
|
+
return zoominToc.map((zoominTocItem) => ({
|
|
394
|
+
text: zoominTocItem.title,
|
|
395
|
+
id: zoominTocItem.bundle_id,
|
|
396
|
+
children: zoominTocItem.childEntries
|
|
397
|
+
? this.transformZoominTocToAtlasToc(zoominTocItem.childEntries)
|
|
398
|
+
: []
|
|
399
|
+
}));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private normalizeToc(apiToc: Array<ApiNavItem>): {
|
|
403
|
+
tocMap: { [key: string]: TreeNode };
|
|
404
|
+
normalizedToc: Array<TreeNode>;
|
|
405
|
+
} {
|
|
406
|
+
const tocMap = {};
|
|
407
|
+
const normalizedToc =
|
|
408
|
+
apiToc &&
|
|
409
|
+
apiToc.map((navItem) => this.normalizeNavItem(navItem, tocMap));
|
|
410
|
+
|
|
411
|
+
return { normalizedToc, tocMap };
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
private normalizeNavItem(
|
|
415
|
+
navItem: ApiNavItem,
|
|
416
|
+
tocMap: TocMap,
|
|
417
|
+
parentNavItem?: TreeNode
|
|
418
|
+
): TreeNode {
|
|
419
|
+
const name = this.calculateNavItemName(navItem, tocMap);
|
|
420
|
+
const node: TreeNode = {
|
|
421
|
+
label: navItem.text,
|
|
422
|
+
name,
|
|
423
|
+
parent: parentNavItem
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
if (name) {
|
|
427
|
+
tocMap[name] = node;
|
|
428
|
+
}
|
|
429
|
+
node.children = navItem.children?.map((child) =>
|
|
430
|
+
this.normalizeNavItem(child, tocMap, node)
|
|
431
|
+
);
|
|
432
|
+
return node;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
private calculateNavItemName(navItem: ApiNavItem, tocMap: TocMap): string {
|
|
436
|
+
let href = navItem.a_attr?.href || "";
|
|
437
|
+
if (href.includes("#")) {
|
|
438
|
+
const [pathUrl] = href.split("#");
|
|
439
|
+
href = pathUrl in tocMap ? href : pathUrl;
|
|
440
|
+
}
|
|
441
|
+
return href || navItem.id;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private normalizeVersion(version: ApiDocVersion): DocVersion {
|
|
445
|
+
return (
|
|
446
|
+
version && {
|
|
447
|
+
label: version.version_text,
|
|
448
|
+
releaseVersion:
|
|
449
|
+
version.release_version &&
|
|
450
|
+
!version.release_version.startsWith("v")
|
|
451
|
+
? `v${version.release_version}`
|
|
452
|
+
: version.release_version,
|
|
453
|
+
id: version.doc_version,
|
|
454
|
+
url: version.version_url
|
|
455
|
+
}
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
private normalizeLanguage(language: ApiDocLanguage): DocLanguage {
|
|
460
|
+
return (
|
|
461
|
+
language && {
|
|
462
|
+
// label:
|
|
463
|
+
// this.getLanguageDisplayTextById(
|
|
464
|
+
// this.languages,
|
|
465
|
+
// language.locale
|
|
466
|
+
// ) || language.label,
|
|
467
|
+
label: "English",
|
|
468
|
+
id: "en-us",
|
|
469
|
+
code: "EN",
|
|
470
|
+
url: "atlas.en-us.246.0.apexcode.meta"
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
private getLanguageDisplayTextById(
|
|
476
|
+
languages: Language[],
|
|
477
|
+
languageId: string
|
|
478
|
+
): string {
|
|
479
|
+
const language = languages.find(
|
|
480
|
+
(languageItem) => languageItem.id === languageId
|
|
481
|
+
);
|
|
482
|
+
return language ? language.displayText : "";
|
|
483
|
+
}
|
|
484
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Language } from "typings/custom";
|
|
2
|
+
import {
|
|
3
|
+
ContentApiOptions,
|
|
4
|
+
ZoominApiNavItem,
|
|
5
|
+
ZoominDocContent
|
|
6
|
+
} from "../xmlContent/types";
|
|
7
|
+
//import jsonwebtoken from 'jsonwebtoken'
|
|
8
|
+
import mockResponses from "./mockResponses";
|
|
9
|
+
|
|
10
|
+
export class ZoominFetchContent {
|
|
11
|
+
private apiDomain: string;
|
|
12
|
+
private languages: Array<Language> = [];
|
|
13
|
+
|
|
14
|
+
constructor(apiDomain: string, languages: Array<Language>) {
|
|
15
|
+
this.apiDomain = apiDomain;
|
|
16
|
+
this.languages = languages;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async fetchDocumentData(docId: string): Promise<Array<ZoominApiNavItem>> {
|
|
20
|
+
try {
|
|
21
|
+
// const token = this.fetchZoomInToken();
|
|
22
|
+
// console.log(`Doc Id ${docId}`)
|
|
23
|
+
// const data = await this.fetchResource<DocumentData>(
|
|
24
|
+
// `https://salesforce-be-dev.zoominsoftware.io/api/bundle/pardot-guides/toc?jwt=${token}`
|
|
25
|
+
// );
|
|
26
|
+
// return data;
|
|
27
|
+
console.log(`Doc Id ${docId} `);
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
// Simulating an asynchronous operation, such as fetching data from a server
|
|
30
|
+
setTimeout(() => {
|
|
31
|
+
return resolve(mockResponses.zoominToc); // Resolve the promise with the string value
|
|
32
|
+
}, 50); // Simulating a delay of 1 second
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.log(error);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fetchContent(
|
|
41
|
+
deliverable: string,
|
|
42
|
+
contentId: string,
|
|
43
|
+
options: ContentApiOptions
|
|
44
|
+
): Promise<ZoominDocContent> {
|
|
45
|
+
// console.log(`ZoominContent ${deliverable} ${contentId} ${options}`)
|
|
46
|
+
// const token = this.fetchZoomInToken();
|
|
47
|
+
// const data = this.fetchResource<ContentData>(
|
|
48
|
+
// `https://salesforce-be-dev.zoominsoftware.io/api/bundle/sample_md/page/b2c-developer-sandboxes.html?jwt=${token}`
|
|
49
|
+
// );
|
|
50
|
+
// return data;
|
|
51
|
+
console.log(`ZoominContent ${deliverable} ${contentId} ${options}`);
|
|
52
|
+
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
// Simulating an asynchronous operation, such as fetching data from a server
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
return resolve(mockResponses.zoominFetchDocContent); // Resolve the promise with the string value
|
|
57
|
+
}, 50); // Simulating a delay of 1 second
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private async fetchResource<T>(url: string): Promise<T> {
|
|
62
|
+
const response = await fetch(url);
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw new Error(response.statusText);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const json = await response.json();
|
|
68
|
+
|
|
69
|
+
return json;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private fetchZoomInToken() {
|
|
73
|
+
const payload = {
|
|
74
|
+
aud: "https://salesforce-be-dev.zoominsoftware.io",
|
|
75
|
+
iss: "https://salesforce.com",
|
|
76
|
+
iat: Math.floor(Date.now() / 1000),
|
|
77
|
+
exp: Math.floor(Date.now() / 1000) + 360,
|
|
78
|
+
sub: "lnemalipuri@salesforce.com",
|
|
79
|
+
data: {
|
|
80
|
+
ZoominRole: "admin",
|
|
81
|
+
fullName: "kishore"
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
console.log(`${payload}`);
|
|
85
|
+
|
|
86
|
+
// Need to update the token while running
|
|
87
|
+
//const token = jsonwebtoken.sign(payload, 'fcrvBbXi1Aimu6sIiZMlcvIP9CqjYjVd');
|
|
88
|
+
//console.log(token);
|
|
89
|
+
// return token;
|
|
90
|
+
|
|
91
|
+
return `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL3NhbGVzZm9yY2UtYmUtZGV2Lnpvb21pbnNvZnR3YXJlLmlvIiwiaXNzIjoiaHR0cHM6Ly9zYWxlc2ZvcmNlLmNvbSIsImlhdCI6MTcwODQxOTkxMCwiZXhwIjoxNzA4Nzc5OTEwLCJzdWIiOiJsbmVtYWxpcHVyaUBzYWxlc2ZvcmNlLmNvbSIsImRhdGEiOnsiWm9vbWluUm9sZSI6ImFkbWluIiwiZnVsbE5hbWUiOiJraXNob3JlIn19.1ekF_78Mq5136do4TdpQaPTy-CUroom0N1DdczcirSk`;
|
|
92
|
+
}
|
|
93
|
+
}
|