@lab-anssi/lib 1.3.1 → 1.4.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/dist/cms/adaptateurCmsCrisp.d.ts +15 -0
- package/dist/cms/adaptateurCmsCrisp.js +69 -5
- package/dist/cms/cmsCrisp.d.ts +18 -1
- package/dist/cms/cmsCrisp.js +32 -0
- package/dist/erreurs.d.ts +2 -0
- package/dist/erreurs.js +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +1 -1
@@ -3,6 +3,19 @@ export type ArticleMarkdownCrisp = {
|
|
3
3
|
contenuMarkdown: string;
|
4
4
|
description: string;
|
5
5
|
};
|
6
|
+
export type ResumeArticleCrisp = {
|
7
|
+
id: string;
|
8
|
+
url: string;
|
9
|
+
titre: string;
|
10
|
+
section: {
|
11
|
+
id?: string;
|
12
|
+
nom?: string;
|
13
|
+
};
|
14
|
+
};
|
15
|
+
export type SectionCrisp = {
|
16
|
+
id: string;
|
17
|
+
nom: string;
|
18
|
+
};
|
6
19
|
export declare class AdaptateurCmsCrisp {
|
7
20
|
readonly urlBase: string;
|
8
21
|
readonly enteteCrisp: {
|
@@ -12,4 +25,6 @@ export declare class AdaptateurCmsCrisp {
|
|
12
25
|
};
|
13
26
|
constructor(idSite: string, cleApi: string);
|
14
27
|
recupereArticle: (idArticle: string) => Promise<ArticleMarkdownCrisp>;
|
28
|
+
recupereArticlesCategorie: (idCategorie: string) => Promise<ResumeArticleCrisp[]>;
|
29
|
+
recupereSectionsCategorie: (idCategorie: string) => Promise<SectionCrisp[]>;
|
15
30
|
}
|
@@ -1,10 +1,40 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
5
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
36
|
exports.AdaptateurCmsCrisp = void 0;
|
7
|
-
const axios_1 =
|
37
|
+
const axios_1 = __importStar(require("axios"));
|
8
38
|
class AdaptateurCmsCrisp {
|
9
39
|
urlBase;
|
10
40
|
enteteCrisp;
|
@@ -14,7 +44,7 @@ class AdaptateurCmsCrisp {
|
|
14
44
|
headers: {
|
15
45
|
Authorization: `Basic ${btoa(cleApi)}`,
|
16
46
|
'X-Crisp-Tier': 'plugin',
|
17
|
-
}
|
47
|
+
},
|
18
48
|
};
|
19
49
|
}
|
20
50
|
recupereArticle = async (idArticle) => {
|
@@ -26,5 +56,39 @@ class AdaptateurCmsCrisp {
|
|
26
56
|
description: donnees.data.description,
|
27
57
|
};
|
28
58
|
};
|
59
|
+
recupereArticlesCategorie = async (idCategorie) => {
|
60
|
+
const params = new URLSearchParams({
|
61
|
+
filter_category_id: idCategorie,
|
62
|
+
});
|
63
|
+
let termine = false;
|
64
|
+
let pageActuelle = 1;
|
65
|
+
let donnees = [];
|
66
|
+
while (!termine) {
|
67
|
+
const reponse = await axios_1.default.get(`${this.urlBase}helpdesk/locale/fr/articles/${pageActuelle}?${params}`, this.enteteCrisp);
|
68
|
+
donnees = [
|
69
|
+
...donnees,
|
70
|
+
...reponse.data.data.map((a) => ({
|
71
|
+
id: a.article_id,
|
72
|
+
url: a.url,
|
73
|
+
titre: a.title,
|
74
|
+
section: {
|
75
|
+
id: a.category?.section?.section_id,
|
76
|
+
nom: a.category?.section?.name,
|
77
|
+
},
|
78
|
+
})),
|
79
|
+
];
|
80
|
+
if (reponse.status !== axios_1.HttpStatusCode.PartialContent)
|
81
|
+
termine = true;
|
82
|
+
pageActuelle += 1;
|
83
|
+
}
|
84
|
+
return donnees;
|
85
|
+
};
|
86
|
+
recupereSectionsCategorie = async (idCategorie) => {
|
87
|
+
const reponse = await axios_1.default.get(`${this.urlBase}helpdesk/locale/fr/category/${idCategorie}/sections/0`, this.enteteCrisp);
|
88
|
+
return reponse.data.data.map((section) => ({
|
89
|
+
id: section.section_id,
|
90
|
+
nom: section.name,
|
91
|
+
}));
|
92
|
+
};
|
29
93
|
}
|
30
94
|
exports.AdaptateurCmsCrisp = AdaptateurCmsCrisp;
|
package/dist/cms/cmsCrisp.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AdaptateurCmsCrisp } from './adaptateurCmsCrisp';
|
1
|
+
import { AdaptateurCmsCrisp, ResumeArticleCrisp, SectionCrisp } from './adaptateurCmsCrisp';
|
2
2
|
import CrispMarkdown from './crispMarkdown';
|
3
3
|
export type PageHtmlCrisp = {
|
4
4
|
titre: string;
|
@@ -6,9 +6,26 @@ export type PageHtmlCrisp = {
|
|
6
6
|
description: string;
|
7
7
|
tableDesMatieres: any[];
|
8
8
|
};
|
9
|
+
type ArticleMarkdownCrispAvecSection = {
|
10
|
+
titre: string;
|
11
|
+
contenuMarkdown: string;
|
12
|
+
description: string;
|
13
|
+
section: {
|
14
|
+
id?: string;
|
15
|
+
nom?: string;
|
16
|
+
};
|
17
|
+
};
|
18
|
+
type ResumeArticleCrispAvecSlug = ResumeArticleCrisp & {
|
19
|
+
slug: string | null;
|
20
|
+
};
|
9
21
|
export declare class CmsCrisp {
|
10
22
|
adaptateurCmsCrisp: AdaptateurCmsCrisp;
|
11
23
|
constructeurCrispMarkdown: (contenuMarkdown: string) => CrispMarkdown;
|
12
24
|
constructor(idSite: string, cleApi: string);
|
13
25
|
recupereArticle(id: string): Promise<PageHtmlCrisp>;
|
26
|
+
recupereArticleCategorie(slug: string, idCategorie: string): Promise<ArticleMarkdownCrispAvecSection>;
|
27
|
+
recupereSectionsCategorie(idCategorie: string): Promise<SectionCrisp[]>;
|
28
|
+
recupereArticlesCategorie(idCategorie: string): Promise<ResumeArticleCrispAvecSlug[]>;
|
29
|
+
private extraitSlugArticle;
|
14
30
|
}
|
31
|
+
export {};
|
package/dist/cms/cmsCrisp.js
CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CmsCrisp = void 0;
|
7
7
|
const adaptateurCmsCrisp_1 = require("./adaptateurCmsCrisp");
|
8
8
|
const crispMarkdown_1 = __importDefault(require("./crispMarkdown"));
|
9
|
+
const erreurs_1 = require("../erreurs");
|
9
10
|
class CmsCrisp {
|
10
11
|
adaptateurCmsCrisp;
|
11
12
|
constructeurCrispMarkdown;
|
@@ -24,5 +25,36 @@ class CmsCrisp {
|
|
24
25
|
tableDesMatieres: crispMarkdown.tableDesMatieres(),
|
25
26
|
};
|
26
27
|
}
|
28
|
+
async recupereArticleCategorie(slug, idCategorie) {
|
29
|
+
const articles = await this.adaptateurCmsCrisp.recupereArticlesCategorie(idCategorie);
|
30
|
+
const article = articles.find((a) => this.extraitSlugArticle(a) === slug);
|
31
|
+
if (!article) {
|
32
|
+
throw new erreurs_1.ErreurArticleCrispIntrouvable();
|
33
|
+
}
|
34
|
+
const articleCrisp = await this.adaptateurCmsCrisp.recupereArticle(article.id);
|
35
|
+
return {
|
36
|
+
...articleCrisp,
|
37
|
+
section: { id: article.section.id, nom: article.section.nom },
|
38
|
+
};
|
39
|
+
}
|
40
|
+
async recupereSectionsCategorie(idCategorie) {
|
41
|
+
return this.adaptateurCmsCrisp.recupereSectionsCategorie(idCategorie);
|
42
|
+
}
|
43
|
+
async recupereArticlesCategorie(idCategorie) {
|
44
|
+
const articles = await this.adaptateurCmsCrisp.recupereArticlesCategorie(idCategorie);
|
45
|
+
return articles.map((article) => {
|
46
|
+
const slug = this.extraitSlugArticle(article);
|
47
|
+
return { ...article, slug: slug || null };
|
48
|
+
});
|
49
|
+
}
|
50
|
+
extraitSlugArticle(article) {
|
51
|
+
try {
|
52
|
+
const regex = /\/article\/(.*)-[a-zA-Z0-9]{1,10}\//gm;
|
53
|
+
return regex.exec(article.url)?.[1];
|
54
|
+
}
|
55
|
+
catch (e) {
|
56
|
+
return null;
|
57
|
+
}
|
58
|
+
}
|
27
59
|
}
|
28
60
|
exports.CmsCrisp = CmsCrisp;
|
package/dist/erreurs.js
ADDED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.AdaptateurProfilAnssi = exports.CmsCrisp = void 0;
|
3
|
+
exports.ErreurArticleCrispIntrouvable = exports.AdaptateurProfilAnssi = exports.CmsCrisp = void 0;
|
4
4
|
var cmsCrisp_1 = require("./cms/cmsCrisp");
|
5
5
|
Object.defineProperty(exports, "CmsCrisp", { enumerable: true, get: function () { return cmsCrisp_1.CmsCrisp; } });
|
6
6
|
var adaptateurProfilAnssi_1 = require("./profilAnssi/adaptateurProfilAnssi");
|
7
7
|
Object.defineProperty(exports, "AdaptateurProfilAnssi", { enumerable: true, get: function () { return adaptateurProfilAnssi_1.AdaptateurProfilAnssi; } });
|
8
|
+
var erreurs_1 = require("./erreurs");
|
9
|
+
Object.defineProperty(exports, "ErreurArticleCrispIntrouvable", { enumerable: true, get: function () { return erreurs_1.ErreurArticleCrispIntrouvable; } });
|