@lab-anssi/lib 1.2.0 → 1.3.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 +3 -1
- package/dist/cms/adaptateurCmsCrisp.js +10 -7
- package/dist/cms/crispMarkdown.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/profilAnssi/adaptateurProfilAnssi.d.ts +29 -0
- package/dist/profilAnssi/adaptateurProfilAnssi.js +52 -0
- package/dist/services/serviceMiseEnForme.d.ts +2 -0
- package/dist/services/serviceMiseEnForme.js +13 -0
- package/package.json +6 -4
@@ -6,7 +6,9 @@ export type ArticleMarkdownCrisp = {
|
|
6
6
|
export declare class AdaptateurCmsCrisp {
|
7
7
|
readonly urlBase: string;
|
8
8
|
readonly enteteCrisp: {
|
9
|
-
|
9
|
+
headers: {
|
10
|
+
[cle: string]: string;
|
11
|
+
};
|
10
12
|
};
|
11
13
|
constructor(idSite: string, cleApi: string);
|
12
14
|
recupereArticle: (idArticle: string) => Promise<ArticleMarkdownCrisp>;
|
@@ -1,22 +1,25 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.AdaptateurCmsCrisp = void 0;
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
4
8
|
class AdaptateurCmsCrisp {
|
5
9
|
urlBase;
|
6
10
|
enteteCrisp;
|
7
11
|
constructor(idSite, cleApi) {
|
8
12
|
this.urlBase = `https://api.crisp.chat/v1/website/${idSite}/`;
|
9
13
|
this.enteteCrisp = {
|
10
|
-
|
11
|
-
|
14
|
+
headers: {
|
15
|
+
Authorization: `Basic ${btoa(cleApi)}`,
|
16
|
+
'X-Crisp-Tier': 'plugin',
|
17
|
+
}
|
12
18
|
};
|
13
19
|
}
|
14
20
|
recupereArticle = async (idArticle) => {
|
15
|
-
const reponse = await
|
16
|
-
|
17
|
-
headers: this.enteteCrisp,
|
18
|
-
});
|
19
|
-
const donnees = await reponse.json();
|
21
|
+
const reponse = await axios_1.default.get(`${this.urlBase}helpdesk/locale/fr/article/${idArticle}`, this.enteteCrisp);
|
22
|
+
const donnees = reponse.data;
|
20
23
|
return {
|
21
24
|
contenuMarkdown: donnees.data.content,
|
22
25
|
titre: donnees.data.title,
|
@@ -114,7 +114,8 @@ class CrispMarkdown {
|
|
114
114
|
});
|
115
115
|
}
|
116
116
|
parseLeMarkdown() {
|
117
|
-
|
117
|
+
const avecCorrectionLigneHorizontale = this.contenuMarkdown.replaceAll("\n---", "\n\n---");
|
118
|
+
this.contenuHTML = this.marked.parse(avecCorrectionLigneHorizontale);
|
118
119
|
this.aDejaParse = true;
|
119
120
|
}
|
120
121
|
versHTML() {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.CmsCrisp = void 0;
|
3
|
+
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
|
+
var adaptateurProfilAnssi_1 = require("./profilAnssi/adaptateurProfilAnssi");
|
7
|
+
Object.defineProperty(exports, "AdaptateurProfilAnssi", { enumerable: true, get: function () { return adaptateurProfilAnssi_1.AdaptateurProfilAnssi; } });
|
@@ -0,0 +1,29 @@
|
|
1
|
+
type Profil = {
|
2
|
+
nom: string;
|
3
|
+
prenom: string;
|
4
|
+
email: string;
|
5
|
+
entite: {
|
6
|
+
nom: string;
|
7
|
+
departement: string;
|
8
|
+
siret: string;
|
9
|
+
};
|
10
|
+
telephone?: string;
|
11
|
+
domainesSpecialite: string[];
|
12
|
+
};
|
13
|
+
type ProfilsAInscrire = {
|
14
|
+
dateInscription: Date;
|
15
|
+
donneesProfil: Profil;
|
16
|
+
}[];
|
17
|
+
export declare class AdaptateurProfilAnssi {
|
18
|
+
private urlBase;
|
19
|
+
readonly entete: {
|
20
|
+
headers: {
|
21
|
+
[cle: string]: string;
|
22
|
+
};
|
23
|
+
};
|
24
|
+
constructor(urlBase: string, cleApi: string);
|
25
|
+
metsAJour({ nom, prenom, email, entite, telephone, domainesSpecialite }: Profil): Promise<void>;
|
26
|
+
recupere(email: string): Promise<any>;
|
27
|
+
inscris(profils: ProfilsAInscrire): Promise<void>;
|
28
|
+
}
|
29
|
+
export {};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.AdaptateurProfilAnssi = void 0;
|
7
|
+
const html_entities_1 = require("html-entities");
|
8
|
+
const serviceMiseEnForme_1 = require("../services/serviceMiseEnForme");
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
10
|
+
class AdaptateurProfilAnssi {
|
11
|
+
urlBase;
|
12
|
+
entete;
|
13
|
+
constructor(urlBase, cleApi) {
|
14
|
+
this.urlBase = urlBase;
|
15
|
+
this.entete = {
|
16
|
+
headers: {
|
17
|
+
Authorization: `Bearer ${cleApi}`
|
18
|
+
}
|
19
|
+
};
|
20
|
+
}
|
21
|
+
async metsAJour({ nom, prenom, email, entite, telephone, domainesSpecialite }) {
|
22
|
+
const urlProfil = `${this.urlBase}/profil/${email}`;
|
23
|
+
await axios_1.default.put(urlProfil, {
|
24
|
+
nom: (0, html_entities_1.decode)(nom),
|
25
|
+
prenom: (0, html_entities_1.decode)(prenom),
|
26
|
+
entite,
|
27
|
+
telephone,
|
28
|
+
domainesSpecialite,
|
29
|
+
}, this.entete);
|
30
|
+
}
|
31
|
+
;
|
32
|
+
async recupere(email) {
|
33
|
+
const urlProfil = `${this.urlBase}/profil/${email}`;
|
34
|
+
try {
|
35
|
+
const reponse = await axios_1.default.get(urlProfil, this.entete);
|
36
|
+
return reponse.data;
|
37
|
+
}
|
38
|
+
catch (e) {
|
39
|
+
if (axios_1.default.isAxiosError(e) && e?.response?.status === 404)
|
40
|
+
return undefined;
|
41
|
+
throw e;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
;
|
45
|
+
async inscris(profils) {
|
46
|
+
const urlInscriptions = `${this.urlBase}/inscriptions`;
|
47
|
+
const profilsParTrancheDe500 = (0, serviceMiseEnForme_1.decoupeTableau)(profils, 500);
|
48
|
+
const promesses = profilsParTrancheDe500.map(profils => axios_1.default.post(urlInscriptions, profils, this.entete));
|
49
|
+
await Promise.all(promesses);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
exports.AdaptateurProfilAnssi = AdaptateurProfilAnssi;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.decoupeTableau = void 0;
|
4
|
+
const decoupeTableau = (tableau, taille) => {
|
5
|
+
if (taille <= 0)
|
6
|
+
throw new RangeError();
|
7
|
+
const resultat = [];
|
8
|
+
for (let i = 0; i < tableau.length; i += taille) {
|
9
|
+
resultat.push(tableau.slice(i, i + taille));
|
10
|
+
}
|
11
|
+
return resultat;
|
12
|
+
};
|
13
|
+
exports.decoupeTableau = decoupeTableau;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lab-anssi/lib",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.3.1",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "git+https://github.com/betagouv/lab-anssi-lib.git"
|
@@ -18,7 +18,7 @@
|
|
18
18
|
"dist"
|
19
19
|
],
|
20
20
|
"types": "./dist/index.d.ts",
|
21
|
-
"type": "
|
21
|
+
"type": "commonjs",
|
22
22
|
"exports": {
|
23
23
|
".": {
|
24
24
|
"types": "./dist/index.d.ts",
|
@@ -27,11 +27,13 @@
|
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
29
|
"@types/node": "^22.14.1",
|
30
|
+
"prettier": "^3.5.3",
|
30
31
|
"tsx": "^4.19.3",
|
31
|
-
"typescript": "^5.8.3"
|
32
|
-
"prettier": "^3.5.3"
|
32
|
+
"typescript": "^5.8.3"
|
33
33
|
},
|
34
34
|
"dependencies": {
|
35
|
+
"axios": "^1.9.0",
|
36
|
+
"html-entities": "^2.6.0",
|
35
37
|
"marked": "^13.0.3"
|
36
38
|
}
|
37
39
|
}
|