@metarisc/metarisc-js 0.0.1-alpha.2 → 0.0.1-alpha.21

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.
Files changed (206) hide show
  1. package/.eslintrc +10 -2
  2. package/.github/workflows/main.yml +29 -0
  3. package/README.md +29 -0
  4. package/lib/api/DossiersAPI.d.ts +62 -0
  5. package/lib/api/DossiersAPI.js +136 -0
  6. package/lib/api/EvenementsAPI.d.ts +41 -0
  7. package/lib/api/EvenementsAPI.js +90 -0
  8. package/lib/api/NotificationsAPI.d.ts +30 -0
  9. package/lib/api/NotificationsAPI.js +71 -0
  10. package/lib/api/OrganisationAPI.d.ts +19 -0
  11. package/lib/api/OrganisationAPI.js +43 -0
  12. package/lib/api/OrganisationsAPI.d.ts +19 -0
  13. package/lib/api/OrganisationsAPI.js +43 -0
  14. package/lib/api/PEIAPI.d.ts +43 -0
  15. package/lib/api/PEIAPI.js +91 -0
  16. package/lib/api/POIAPI.d.ts +50 -0
  17. package/lib/api/POIAPI.js +106 -0
  18. package/lib/api/PingAPI.d.ts +11 -0
  19. package/lib/api/PingAPI.js +27 -0
  20. package/lib/api/SupportAPI.d.ts +25 -0
  21. package/lib/api/SupportAPI.js +57 -0
  22. package/lib/api/UtilisateursAPI.d.ts +19 -0
  23. package/lib/api/UtilisateursAPI.js +42 -0
  24. package/lib/auth/oauth2.d.ts +19 -0
  25. package/lib/auth/oauth2.js +25 -0
  26. package/lib/client.d.ts +33 -0
  27. package/lib/client.js +97 -0
  28. package/lib/collection.d.ts +42 -0
  29. package/lib/collection.js +52 -0
  30. package/lib/core.d.ts +48 -0
  31. package/lib/core.js +28 -0
  32. package/lib/index.d.ts +15 -1
  33. package/lib/index.js +27 -1
  34. package/lib/metarisc.d.ts +20 -18
  35. package/lib/metarisc.js +36 -27
  36. package/lib/model/AdressePostale.d.ts +10 -0
  37. package/lib/model/AdressePostale.js +2 -0
  38. package/lib/model/AnomalieDECI.d.ts +10 -0
  39. package/lib/model/AnomalieDECI.js +9 -0
  40. package/lib/model/Contact.d.ts +13 -0
  41. package/lib/model/Contact.js +2 -0
  42. package/lib/model/DescriptifTechnique.d.ts +40 -0
  43. package/lib/model/DescriptifTechnique.js +45 -0
  44. package/lib/model/DescriptifTechniqueBase.d.ts +5 -0
  45. package/lib/model/DescriptifTechniqueBase.js +2 -0
  46. package/lib/model/DescriptifTechniqueDECIBase.d.ts +16 -0
  47. package/lib/model/DescriptifTechniqueDECIBase.js +9 -0
  48. package/lib/model/DescriptifTechniquePENA.d.ts +43 -0
  49. package/lib/model/DescriptifTechniquePENA.js +40 -0
  50. package/lib/model/DescriptifTechniquePENAAllOfRealimentation.d.ts +10 -0
  51. package/lib/model/DescriptifTechniquePENAAllOfRealimentation.js +9 -0
  52. package/lib/model/DescriptifTechniquePENAAllOfVolumes.d.ts +4 -0
  53. package/lib/model/DescriptifTechniquePENAAllOfVolumes.js +2 -0
  54. package/lib/model/DescriptifTechniquePIBI.d.ts +31 -0
  55. package/lib/model/DescriptifTechniquePIBI.js +25 -0
  56. package/lib/model/DescriptifTechniquePIBIAllOfPesees.d.ts +6 -0
  57. package/lib/model/DescriptifTechniquePIBIAllOfPesees.js +2 -0
  58. package/lib/model/Document.d.ts +3 -0
  59. package/lib/model/Document.js +2 -0
  60. package/lib/model/Dossier.d.ts +17 -0
  61. package/lib/model/Dossier.js +8 -0
  62. package/lib/model/Email.d.ts +6 -0
  63. package/lib/model/Email.js +2 -0
  64. package/lib/model/Evenement.d.ts +14 -0
  65. package/lib/model/Evenement.js +10 -0
  66. package/lib/model/Feature.d.ts +6 -0
  67. package/lib/model/Feature.js +2 -0
  68. package/lib/model/FeatureGeometry.d.ts +5 -0
  69. package/lib/model/FeatureGeometry.js +2 -0
  70. package/lib/model/GetEvenement404Response.d.ts +6 -0
  71. package/lib/model/GetEvenement404Response.js +2 -0
  72. package/lib/model/GetEvenementDetails404Response.d.ts +6 -0
  73. package/lib/model/GetEvenementDetails404Response.js +2 -0
  74. package/lib/model/GetFeature200Response.d.ts +7 -0
  75. package/lib/model/GetFeature200Response.js +2 -0
  76. package/lib/model/GetFeature200ResponseCrs.d.ts +5 -0
  77. package/lib/model/GetFeature200ResponseCrs.js +2 -0
  78. package/lib/model/GetFeature200ResponseCrsProperties.d.ts +3 -0
  79. package/lib/model/GetFeature200ResponseCrsProperties.js +2 -0
  80. package/lib/model/GetNotification404Response.d.ts +6 -0
  81. package/lib/model/GetNotification404Response.js +2 -0
  82. package/lib/model/Notification.d.ts +12 -0
  83. package/lib/model/Notification.js +2 -0
  84. package/lib/model/Organisation.d.ts +9 -0
  85. package/lib/model/Organisation.js +7 -0
  86. package/lib/model/PEI.d.ts +13 -0
  87. package/lib/model/PEI.js +2 -0
  88. package/lib/model/PEIReferencesExterieuresInner.d.ts +4 -0
  89. package/lib/model/PEIReferencesExterieuresInner.js +2 -0
  90. package/lib/model/POI.d.ts +13 -0
  91. package/lib/model/POI.js +2 -0
  92. package/lib/model/POIReferencesExterieuresInner.d.ts +4 -0
  93. package/lib/model/POIReferencesExterieuresInner.js +2 -0
  94. package/lib/model/PatchPoiRequest.d.ts +3 -0
  95. package/lib/model/PatchPoiRequest.js +2 -0
  96. package/lib/model/PieceJointe.d.ts +7 -0
  97. package/lib/model/PieceJointe.js +2 -0
  98. package/lib/model/Ping200Response.d.ts +3 -0
  99. package/lib/model/Ping200Response.js +2 -0
  100. package/lib/model/PostDossierRequest.d.ts +5 -0
  101. package/lib/model/PostDossierRequest.js +2 -0
  102. package/lib/model/PostEvenementRequest.d.ts +7 -0
  103. package/lib/model/PostEvenementRequest.js +2 -0
  104. package/lib/model/PostNotification400Response.d.ts +6 -0
  105. package/lib/model/PostNotification400Response.js +2 -0
  106. package/lib/model/PostNotification500Response.d.ts +6 -0
  107. package/lib/model/PostNotification500Response.js +2 -0
  108. package/lib/model/PostNotificationRequest.d.ts +9 -0
  109. package/lib/model/PostNotificationRequest.js +2 -0
  110. package/lib/model/PostTicketRequest.d.ts +10 -0
  111. package/lib/model/PostTicketRequest.js +2 -0
  112. package/lib/model/SuiviAdministratif.d.ts +6 -0
  113. package/lib/model/SuiviAdministratif.js +2 -0
  114. package/lib/model/Tag.d.ts +3 -0
  115. package/lib/model/Tag.js +2 -0
  116. package/lib/model/Ticket.d.ts +17 -0
  117. package/lib/model/Ticket.js +12 -0
  118. package/lib/model/Type.d.ts +5 -0
  119. package/lib/model/Type.js +2 -0
  120. package/lib/model/Utilisateur.d.ts +12 -0
  121. package/lib/model/Utilisateur.js +2 -0
  122. package/lib/model/Utilisateur1.d.ts +3 -0
  123. package/lib/model/Utilisateur1.js +2 -0
  124. package/lib/model/Workflow.d.ts +4 -0
  125. package/lib/model/Workflow.js +2 -0
  126. package/lib/model/WorkflowBase.d.ts +14 -0
  127. package/lib/model/WorkflowBase.js +2 -0
  128. package/lib/model/WorkflowDossiersLies.d.ts +4 -0
  129. package/lib/model/WorkflowDossiersLies.js +2 -0
  130. package/lib/model/WorkflowPassageCommissionSecurite.d.ts +4 -0
  131. package/lib/model/WorkflowPassageCommissionSecurite.js +2 -0
  132. package/lib/model/WorkflowRemiseEnServicePEI.d.ts +5 -0
  133. package/lib/model/WorkflowRemiseEnServicePEI.js +2 -0
  134. package/lib/tus.d.ts +7 -0
  135. package/lib/tus.js +43 -0
  136. package/lib/utils.d.ts +8 -0
  137. package/lib/utils.js +21 -0
  138. package/package.json +25 -18
  139. package/src/api/DossiersAPI.ts +155 -0
  140. package/src/api/EvenementsAPI.ts +101 -0
  141. package/src/api/NotificationsAPI.ts +79 -0
  142. package/src/api/OrganisationAPI.ts +46 -0
  143. package/src/api/OrganisationsAPI.ts +46 -0
  144. package/src/api/PEIAPI.ts +103 -0
  145. package/src/api/POIAPI.ts +124 -0
  146. package/src/api/PingAPI.ts +27 -0
  147. package/src/api/SupportAPI.ts +63 -0
  148. package/src/api/UtilisateursAPI.ts +46 -0
  149. package/src/auth/oauth2.ts +28 -0
  150. package/src/client.ts +133 -0
  151. package/src/collection.ts +85 -0
  152. package/src/core.ts +70 -0
  153. package/src/index.ts +22 -1
  154. package/src/metarisc.ts +67 -54
  155. package/src/model/AdressePostale.ts +10 -0
  156. package/src/model/AnomalieDECI.ts +11 -0
  157. package/src/model/Contact.ts +13 -0
  158. package/src/model/DescriptifTechnique.ts +46 -0
  159. package/src/model/DescriptifTechniqueBase.ts +5 -0
  160. package/src/model/DescriptifTechniqueDECIBase.ts +19 -0
  161. package/src/model/DescriptifTechniquePENA.ts +49 -0
  162. package/src/model/DescriptifTechniquePENAAllOfRealimentation.ts +11 -0
  163. package/src/model/DescriptifTechniquePENAAllOfVolumes.ts +4 -0
  164. package/src/model/DescriptifTechniquePIBI.ts +36 -0
  165. package/src/model/DescriptifTechniquePIBIAllOfPesees.ts +6 -0
  166. package/src/model/Document.ts +3 -0
  167. package/src/model/Dossier.ts +19 -0
  168. package/src/model/Email.ts +6 -0
  169. package/src/model/Evenement.ts +15 -0
  170. package/src/model/Feature.ts +7 -0
  171. package/src/model/FeatureGeometry.ts +5 -0
  172. package/src/model/GetEvenement404Response.ts +6 -0
  173. package/src/model/GetEvenementDetails404Response.ts +6 -0
  174. package/src/model/GetFeature200Response.ts +8 -0
  175. package/src/model/GetFeature200ResponseCrs.ts +6 -0
  176. package/src/model/GetFeature200ResponseCrsProperties.ts +3 -0
  177. package/src/model/GetNotification404Response.ts +6 -0
  178. package/src/model/Notification.ts +12 -0
  179. package/src/model/Organisation.ts +10 -0
  180. package/src/model/PEI.ts +14 -0
  181. package/src/model/PEIReferencesExterieuresInner.ts +4 -0
  182. package/src/model/POI.ts +14 -0
  183. package/src/model/POIReferencesExterieuresInner.ts +4 -0
  184. package/src/model/PatchPoiRequest.ts +3 -0
  185. package/src/model/PieceJointe.ts +7 -0
  186. package/src/model/Ping200Response.ts +3 -0
  187. package/src/model/PostDossierRequest.ts +5 -0
  188. package/src/model/PostEvenementRequest.ts +7 -0
  189. package/src/model/PostNotification400Response.ts +6 -0
  190. package/src/model/PostNotification500Response.ts +6 -0
  191. package/src/model/PostNotificationRequest.ts +9 -0
  192. package/src/model/PostTicketRequest.ts +10 -0
  193. package/src/model/SuiviAdministratif.ts +6 -0
  194. package/src/model/Tag.ts +3 -0
  195. package/src/model/Ticket.ts +18 -0
  196. package/src/model/Type.ts +5 -0
  197. package/src/model/Utilisateur.ts +12 -0
  198. package/src/model/Utilisateur1.ts +3 -0
  199. package/src/model/Workflow.ts +5 -0
  200. package/src/model/WorkflowBase.ts +14 -0
  201. package/src/model/WorkflowDossiersLies.ts +5 -0
  202. package/src/model/WorkflowPassageCommissionSecurite.ts +5 -0
  203. package/src/model/WorkflowRemiseEnServicePEI.ts +6 -0
  204. package/src/tus.ts +44 -0
  205. package/src/utils.ts +23 -0
  206. package/tsconfig.json +11 -10
@@ -0,0 +1,124 @@
1
+ import { Core, MetariscConfig } from "../core";
2
+ import Utils from "../utils";
3
+ import type { AxiosResponse } from "axios";
4
+ import { Client } from "../client";
5
+ import { Collection } from "../collection";
6
+ import { POI } from '../model/POI';
7
+ import { PatchPoiRequest } from '../model/PatchPoiRequest';
8
+
9
+ import { Contact } from '../model/Contact';
10
+
11
+ import { DescriptifTechnique } from '../model/DescriptifTechnique';
12
+
13
+ import { PieceJointe } from '../model/PieceJointe';
14
+
15
+ export class POIAPI extends Core {
16
+ constructor(config: MetariscConfig, client?: Client) {
17
+ super(config, client);
18
+ }
19
+
20
+ /**
21
+ * Récupération de l'ensemble des données d'un POI.
22
+ * @param poiId ID du POI
23
+ */
24
+ async getPoi(poiId: string): Promise<AxiosResponse<POI>>
25
+ {
26
+ const pathVariable = { 'poi_id': poiId };
27
+ return this.request({
28
+ method: 'GET',
29
+ endpoint: Utils.constructPath(pathVariable, '/poi/{poi_id}'),
30
+ headers: { },
31
+ params: { },
32
+ body: {}
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Récupération de la liste des contacts d'un POI.
38
+ * @param poiId ID du POI
39
+ * @param page Numéro de page
40
+ * @param perPage Nombre de résultats demandé
41
+ */
42
+ paginateContacts(poiId: string, page?: number, perPage?: number): Collection<Contact>
43
+ {
44
+ const pathVariable = { 'poi_id': poiId };
45
+ return this.collect<Contact>({
46
+ method: 'GET',
47
+ endpoint: Utils.constructPath(pathVariable, '/poi/{poi_id}/contacts'),
48
+ headers: { },
49
+ params: { 'page': page.toString(), 'per_page': perPage.toString() },
50
+ body: {}
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Récupération de l'historique d'un POI.
56
+ * @param poiId ID du POI
57
+ * @param page Numéro de page
58
+ * @param perPage Nombre de résultats demandé
59
+ */
60
+ paginateHistorique(poiId: string, page?: number, perPage?: number): Collection<DescriptifTechnique>
61
+ {
62
+ const pathVariable = { 'poi_id': poiId };
63
+ return this.collect<DescriptifTechnique>({
64
+ method: 'GET',
65
+ endpoint: Utils.constructPath(pathVariable, '/poi/{poi_id}/historique'),
66
+ headers: { },
67
+ params: { 'page': page.toString(), 'per_page': perPage.toString() },
68
+ body: {}
69
+ });
70
+ }
71
+
72
+ /**
73
+ * Récupération de la liste des pièces jointes d'un POI.
74
+ * @param poiId ID du POI
75
+ * @param page Numéro de page
76
+ * @param perPage Nombre de résultats demandé
77
+ */
78
+ paginatePiecesJointes(poiId: string, page?: number, perPage?: number): Collection<PieceJointe>
79
+ {
80
+ const pathVariable = { 'poi_id': poiId };
81
+ return this.collect<PieceJointe>({
82
+ method: 'GET',
83
+ endpoint: Utils.constructPath(pathVariable, '/poi/{poi_id}/pieces_jointes'),
84
+ headers: { },
85
+ params: { 'page': page.toString(), 'per_page': perPage.toString() },
86
+ body: {}
87
+ });
88
+ }
89
+
90
+ /**
91
+ * Récupération de la liste des POI selon des critères de recherche.
92
+ * @param page Numéro de page
93
+ * @param perPage Nombre de résultats demandé
94
+ */
95
+ paginatePoi(page?: number, perPage?: number): Collection<POI>
96
+ {
97
+ const pathVariable = { };
98
+ return this.collect<POI>({
99
+ method: 'GET',
100
+ endpoint: Utils.constructPath(pathVariable, '/poi/'),
101
+ headers: { },
102
+ params: { 'page': page.toString(), 'per_page': perPage.toString() },
103
+ body: {}
104
+ });
105
+ }
106
+
107
+ /**
108
+ * Modifier un POI existant.
109
+ * @param poiId ID du POI
110
+ * @param patchPoiRequest
111
+ */
112
+ async patchPoi(poiId: string, patchPoiRequest?: PatchPoiRequest): Promise<AxiosResponse<POI>>
113
+ {
114
+ const pathVariable = { 'poi_id': poiId };
115
+ return this.request({
116
+ method: 'PATCH',
117
+ endpoint: Utils.constructPath(pathVariable, '/poi/{poi_id}'),
118
+ headers: { },
119
+ params: { },
120
+ body: { 'test': patchPoiRequest?.test }
121
+ });
122
+ }
123
+
124
+ }
@@ -0,0 +1,27 @@
1
+ import { Core, MetariscConfig } from "../core";
2
+ import Utils from "../utils";
3
+ import type { AxiosResponse } from "axios";
4
+ import { Client } from "../client";
5
+ import { Ping200Response } from '../model/Ping200Response';
6
+
7
+ export class PingAPI extends Core {
8
+ constructor(config: MetariscConfig, client?: Client) {
9
+ super(config, client);
10
+ }
11
+
12
+ /**
13
+ * Permet de s'assurer que le service Metarisc est en ligne. Ping ... Pong !
14
+ */
15
+ async ping(): Promise<AxiosResponse<Ping200Response>>
16
+ {
17
+ const pathVariable = { };
18
+ return this.request({
19
+ method: 'GET',
20
+ endpoint: Utils.constructPath(pathVariable, '/ping'),
21
+ headers: { },
22
+ params: { },
23
+ body: {}
24
+ });
25
+ }
26
+
27
+ }
@@ -0,0 +1,63 @@
1
+ import { Core, MetariscConfig } from "../core";
2
+ import Utils from "../utils";
3
+ import type { AxiosResponse } from "axios";
4
+ import { Client } from "../client";
5
+ import { Collection } from "../collection";
6
+ import { PostTicketRequest } from '../model/PostTicketRequest';
7
+ import { Ticket } from '../model/Ticket';
8
+
9
+ export class SupportAPI extends Core {
10
+ constructor(config: MetariscConfig, client?: Client) {
11
+ super(config, client);
12
+ }
13
+
14
+ /**
15
+ * Récupération des détails du ticket
16
+ * @param ticketId ID du ticket
17
+ */
18
+ async getTicket(ticketId: string): Promise<AxiosResponse<Ticket>>
19
+ {
20
+ const pathVariable = { 'ticket_id': ticketId };
21
+ return this.request({
22
+ method: 'GET',
23
+ endpoint: Utils.constructPath(pathVariable, '/support/{ticket_id}'),
24
+ headers: { },
25
+ params: { },
26
+ body: {}
27
+ });
28
+ }
29
+
30
+ /**
31
+ * Récupération de la liste des tickets de support.
32
+ * @param page Numéro de page
33
+ * @param perPage Nombre de résultats demandé
34
+ */
35
+ paginateTickets(page?: number, perPage?: number): Collection<Ticket>
36
+ {
37
+ const pathVariable = { };
38
+ return this.collect<Ticket>({
39
+ method: 'GET',
40
+ endpoint: Utils.constructPath(pathVariable, '/support/'),
41
+ headers: { },
42
+ params: { 'page': page.toString(), 'per_page': perPage.toString() },
43
+ body: {}
44
+ });
45
+ }
46
+
47
+ /**
48
+ * Création d'un nouveau ticket de support.
49
+ * @param postTicketRequest
50
+ */
51
+ async postTicket(postTicketRequest?: PostTicketRequest): Promise<AxiosResponse<Ticket>>
52
+ {
53
+ const pathVariable = { };
54
+ return this.request({
55
+ method: 'POST',
56
+ endpoint: Utils.constructPath(pathVariable, '/support/'),
57
+ headers: { },
58
+ params: { },
59
+ body: { 'subject': postTicketRequest?.subject, 'description': postTicketRequest?.description }
60
+ });
61
+ }
62
+
63
+ }
@@ -0,0 +1,46 @@
1
+ import { Core, MetariscConfig } from "../core";
2
+ import Utils from "../utils";
3
+ import type { AxiosResponse } from "axios";
4
+ import { Client } from "../client";
5
+ import { Collection } from "../collection";
6
+ import { Utilisateur } from '../model/Utilisateur';
7
+ import { Email } from '../model/Email';
8
+
9
+ export class UtilisateursAPI extends Core {
10
+ constructor(config: MetariscConfig, client?: Client) {
11
+ super(config, client);
12
+ }
13
+
14
+ /**
15
+ * L'utilisateur connecté retourné par ce point de terminaison utilise le token d'accès généré par le service OpenID Connect afin de le lier à une identité connue de Metarisc. Si l'utilisateur est inconnu une erreur est retournée.
16
+ */
17
+ async getUtilisateursMoi(): Promise<AxiosResponse<Utilisateur>>
18
+ {
19
+ const pathVariable = { };
20
+ return this.request({
21
+ method: 'GET',
22
+ endpoint: Utils.constructPath(pathVariable, '/utilisateurs/@moi'),
23
+ headers: { },
24
+ params: { },
25
+ body: {}
26
+ });
27
+ }
28
+
29
+ /**
30
+ * Liste toutes les adresses mail de l'utilisateur connecté, y compris les adresses non publiquement accessibles.
31
+ * @param page Numéro de page
32
+ * @param perPage Nombre de résultats demandé
33
+ */
34
+ paginateMoiEmails(page?: number, perPage?: number): Collection<Email>
35
+ {
36
+ const pathVariable = { };
37
+ return this.collect<Email>({
38
+ method: 'GET',
39
+ endpoint: Utils.constructPath(pathVariable, '/utilisateurs/@moi/emails'),
40
+ headers: { },
41
+ params: { 'page': page?.toString(), 'per_page': perPage?.toString() },
42
+ body: {}
43
+ });
44
+ }
45
+
46
+ }
@@ -0,0 +1,28 @@
1
+ import { OAuth2Options } from "../core";
2
+
3
+ export class OAuth2
4
+ {
5
+ public static AUTHORIZATION_URL = 'https://lemur-17.cloud-iam.com/auth/realms/metariscoidc/protocol/openid-connect/auth';
6
+ public static ACCESS_TOKEN_URL = 'https://lemur-17.cloud-iam.com/auth/realms/metariscoidc/protocol/openid-connect/token';
7
+
8
+ /**
9
+ * Utilisation d'OAuth2 pour récupérer un access token utilisable dans Metarisc.
10
+ *
11
+ * La configuration doit contenir au moins :
12
+ * - CLIENT_ID (Le client_id de l'application inscrite sur Metarisc ID pour communiquer avec Metarisc)
13
+ * - CLIENT_SECRET (Le client_secret de l'application inscrite sur Metarisc ID pour communiquer avec Metarisc)
14
+ *
15
+ * La configuration peut contenir aussi :
16
+ * - ACCESS_TOKEN_URL
17
+ **/
18
+
19
+ /**
20
+ * OAuth2 Authorize URL Generator helper.
21
+ */
22
+ public static authorizeUrl(options: OAuth2Options) : string
23
+ {
24
+ const params = new URLSearchParams(options);
25
+
26
+ return OAuth2.AUTHORIZATION_URL + '?' + params.toString();
27
+ }
28
+ }
package/src/client.ts ADDED
@@ -0,0 +1,133 @@
1
+ import axios, { AxiosInstance, AxiosResponse, RawAxiosRequestHeaders } from "axios";
2
+ import axiosRetry from "axios-retry";
3
+ import oauth from "axios-oauth-client";
4
+ import { GrantResponse, MetariscConfig, OAuth2Options } from './core';
5
+ import { OAuth2 } from "./auth/oauth2";
6
+ import { setupCache } from 'axios-cache-interceptor';
7
+
8
+ interface RequestConfig {
9
+ body?: any;
10
+ headers?: { [name: string]: string | string[] };
11
+ params?: { [param: string]: string | string[] };
12
+ endpoint?: string;
13
+ method?: string;
14
+ }
15
+
16
+ export enum AuthMethod {
17
+ CLIENT_CREDENTIALS,
18
+ AUTHORIZATION_CODE
19
+ }
20
+
21
+ export class Client {
22
+
23
+ private axios : AxiosInstance;
24
+
25
+ private access_token: string;
26
+
27
+ constructor(config : MetariscConfig) {
28
+ this.axios = axios.create({
29
+ baseURL: config.metarisc_url ?? 'https://api.metarisc.fr/',
30
+ 'headers': {
31
+ 'common': this.getDefaultHeaders()
32
+ }
33
+ });
34
+
35
+ // Axios Interceptors
36
+ // Request interceptors are FILO (First In Last Out)
37
+ // Response interceptors are FIFO (First In First Out)
38
+
39
+ // Axios interceptor : Enable HTTP Caching
40
+ // When combining axios-cache-interceptors with other interceptors, you may encounter some inconsistences.
41
+ // See : https://github.com/arthurfiorette/axios-cache-interceptor/issues/449#issuecomment-1370327566
42
+ this.axios = setupCache(this.axios);
43
+
44
+ // Axios interceptor : Retry strategy
45
+ axiosRetry(this.axios, {
46
+ retries: 3,
47
+ retryDelay: axiosRetry.exponentialDelay
48
+ });
49
+ }
50
+
51
+ async authenticate(auth_method: AuthMethod, options: OAuth2Options): Promise<GrantResponse> {
52
+ let result;
53
+ switch (auth_method) {
54
+ case AuthMethod.AUTHORIZATION_CODE:
55
+ result = await this.getAuthorizationCode(options);
56
+ break;
57
+ case AuthMethod.CLIENT_CREDENTIALS:
58
+ result = await this.getClientCredentials(options);
59
+ break;
60
+ default:
61
+ return;
62
+ }
63
+
64
+ if (result) {
65
+ const token = result.token_type + ' ' + result.access_token;
66
+ this.setAccessToken(token);
67
+ }
68
+
69
+ return result;
70
+ }
71
+
72
+ async request<T>(config: RequestConfig): Promise<AxiosResponse<T>> {
73
+ config.headers['Authorization'] = this.getAccessToken();
74
+ return this.axios.request<T>({
75
+ method: config.method || 'GET',
76
+ url: config.endpoint || '/',
77
+ params: config.params,
78
+ data: config.body,
79
+ headers: config.headers
80
+ });
81
+ }
82
+
83
+ async getAuthorizationCode(options: OAuth2Options): Promise<GrantResponse> {
84
+ const fn = oauth.authorizationCode(
85
+ axios.create(),
86
+ OAuth2.ACCESS_TOKEN_URL,
87
+ options.client_id ?? '',
88
+ options.client_secret ?? '',
89
+ options.redirect_uri ?? '',
90
+ options.code ?? '',
91
+ options.scope ?? ''
92
+ )
93
+ return await fn(options.code ?? '', options.scope ?? '')
94
+ }
95
+
96
+ async getClientCredentials(options: OAuth2Options): Promise<GrantResponse> {
97
+ const fn = oauth.clientCredentials(
98
+ axios.create(),
99
+ OAuth2.ACCESS_TOKEN_URL,
100
+ options.client_id ?? '',
101
+ options.client_secret ?? ''
102
+ )
103
+ return await fn(options.scope ?? '');
104
+ }
105
+
106
+ setAccessToken(access_token: string): void {
107
+ this.access_token = access_token;
108
+ this.axios.interceptors.request.use(function (config) {
109
+ config.headers['Authorization'] = access_token;
110
+ return config;
111
+ });
112
+ }
113
+
114
+ getAccessToken(): string {
115
+ return this.access_token;
116
+ }
117
+
118
+ /**
119
+ * Retourne les headers HTTP par défauts devant être présents dans toutes les requêtes Metarisc.
120
+ */
121
+ private getDefaultHeaders() : RawAxiosRequestHeaders
122
+ {
123
+ const headers : RawAxiosRequestHeaders = {};
124
+
125
+ // UA Headers
126
+ headers['User-Agent'] = 'MetariscJs/dev'; // Format User-Agent (https://www.rfc-editor.org/rfc/rfc9110#name-user-agent)
127
+ headers['Metarisc-User-Agent'] = JSON.stringify({
128
+ 'lang': 'js'
129
+ });
130
+
131
+ return headers;
132
+ }
133
+ }
@@ -0,0 +1,85 @@
1
+ import { AxiosResponse } from "axios";
2
+ import { Core } from "./core";
3
+
4
+ export type PaginationResults<T> = {
5
+ data?: Array<T>;
6
+ meta?: {
7
+ pagination?: PaginationData;
8
+ };
9
+ };
10
+
11
+ export type PaginationData = {
12
+ total: number;
13
+ count: number;
14
+ per_page: number;
15
+ current_page: number;
16
+ total_pages: number;
17
+ };
18
+
19
+ type PaginationRequestConfig = {
20
+ headers ?: {[name: string]: string | string[]};
21
+ params ?: {[param: string]: string | string[]};
22
+ endpoint ?: string;
23
+ };
24
+
25
+ export class Collection<T>
26
+ {
27
+ constructor(
28
+ private client : Core,
29
+ private config : PaginationRequestConfig
30
+ ) {}
31
+
32
+ /**
33
+ * Fetch current page results.
34
+ */
35
+ async fetchPage(page : number, per_page : number) : Promise<AxiosResponse<PaginationResults<T>>>
36
+ {
37
+ return this.client.request({
38
+ method: 'GET',
39
+ endpoint: this.config.endpoint,
40
+ headers: this.config.headers,
41
+ params: {...this.config.params, ...{
42
+ page: page.toString(),
43
+ per_page: per_page.toString()
44
+ }},
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Generates an iterator to automatically iterate over all pages in a result set.
50
+ */
51
+ async * autoPagingIterator() : AsyncGenerator<T, void, unknown>
52
+ {
53
+ let current_page : number = this.config.params && 'page' in this.config.params ? parseInt(this.config.params['page'].toString()) : 1;
54
+ const per_page : number = this.config.params && 'per_page' in this.config.params ? parseInt(this.config.params['per_page'].toString()) : 100;
55
+
56
+ while (true) {
57
+ const response = <AxiosResponse<PaginationResults<T>>> await this.fetchPage(current_page, per_page);
58
+
59
+ for (const element of response.data.data) {
60
+ yield element;
61
+ }
62
+
63
+ if (response.data.meta.pagination.current_page === response.data.meta.pagination.total_pages) {
64
+ break;
65
+ }
66
+
67
+ current_page++;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Generates an array with all results set.
73
+ */
74
+ async autoPagingIteratorToArray() : Promise<Array<T>>
75
+ {
76
+ const generator = this.autoPagingIterator();
77
+ const results = [];
78
+
79
+ for await (const item of generator) {
80
+ results.push(item);
81
+ }
82
+
83
+ return results;
84
+ }
85
+ }
package/src/core.ts ADDED
@@ -0,0 +1,70 @@
1
+ import { AxiosResponse } from "axios";
2
+ import { AuthMethod, Client } from "./client";
3
+ import { Collection } from "./collection";
4
+
5
+ interface RequestConfig {
6
+ body?: any;
7
+ headers?: { [name: string]: string | string[] };
8
+ params?: { [param: string]: string | string[] };
9
+ endpoint?: string;
10
+ method?: string;
11
+ }
12
+
13
+ export interface MetariscConfig {
14
+ metarisc_url?: string;
15
+ }
16
+
17
+ export interface OAuth2Options {
18
+ client_id?: string;
19
+ client_secret?: string;
20
+ response_type?: string;
21
+ redirect_uri?: string;
22
+ state?: string;
23
+ code?: string;
24
+ scope?: string;
25
+ [name: string]: string;
26
+ }
27
+
28
+ export interface GrantResponse {
29
+ access_token?: string;
30
+ expires_in?: number;
31
+ id_token?: string;
32
+ refresh_token?: string;
33
+ refresh_expires_in?: number;
34
+ session_state?: string;
35
+ token_type?: string;
36
+ error?: string;
37
+ error_description?: string;
38
+ }
39
+
40
+ export class Core {
41
+ protected client: Client;
42
+ protected config: MetariscConfig;
43
+
44
+ constructor(config: MetariscConfig, client?: Client) {
45
+ this.config = config;
46
+ this.client = client ?? new Client(config);
47
+ }
48
+
49
+ async request<T>(config : RequestConfig) : Promise<AxiosResponse<T>>
50
+ {
51
+ return this.client.request<T>(config);
52
+ }
53
+
54
+ collect<T>(config : RequestConfig) : Collection<T>
55
+ {
56
+ return new Collection<T>(this, {
57
+ endpoint: config.endpoint || '/',
58
+ params: config.params,
59
+ headers: config.headers
60
+ });
61
+ }
62
+
63
+ async authenticate(auth_method: AuthMethod, options: OAuth2Options): Promise<GrantResponse> {
64
+ return await this.client.authenticate(auth_method, options);
65
+ }
66
+
67
+ setAccessToken(access_token: string): void {
68
+ this.client.setAccessToken(access_token);
69
+ }
70
+ }
package/src/index.ts CHANGED
@@ -1 +1,22 @@
1
- export { Metarisc } from './metarisc';
1
+ export { Metarisc } from "./metarisc";
2
+ export { OAuth2 } from "./auth/oauth2";
3
+ export { Core } from "./core";
4
+ export { Collection } from "./collection";
5
+ export { PaginationResults } from "./collection"
6
+ export { AuthMethod } from "./client";
7
+ export { Client } from "./client";
8
+ export { Tus } from "./tus";
9
+
10
+ export { DossiersAPI } from './api/DossiersAPI';
11
+
12
+ export { EvenementsAPI } from './api/EvenementsAPI';
13
+
14
+ export { NotificationsAPI } from './api/NotificationsAPI';
15
+
16
+ export { OrganisationsAPI } from './api/OrganisationsAPI';
17
+
18
+ export { PEIAPI } from './api/PEIAPI';
19
+
20
+ export { PingAPI } from './api/PingAPI';
21
+
22
+ export { UtilisateursAPI } from './api/UtilisateursAPI';