@metarisc/metarisc-js 0.0.1-alpha.34 → 0.0.1-alpha.35

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.
@@ -1,13 +1,29 @@
1
1
  import { Core, MetariscConfig } from "../core";
2
+ import type { AxiosResponse } from "axios";
2
3
  import { Client } from "../client";
3
4
  import { Collection } from "../collection";
4
5
  import { AnomalieDECI } from '../model/AnomalieDECI';
5
6
  export declare class AnomaliesAPI extends Core {
6
7
  constructor(config: MetariscConfig, client?: Client);
8
+ /**
9
+ * Suppression d'une anomalie.
10
+ * @param anomalieId Identifiant unique de l'anomalie
11
+ */
12
+ deleteAnomalie(anomalieId: string): Promise<AxiosResponse<void>>;
13
+ /**
14
+ * Détails d'une anomalie.
15
+ * @param anomalieId Identifiant unique de l'anomalie
16
+ */
17
+ getAnomalie(anomalieId: string): Promise<AxiosResponse<AnomalieDECI>>;
7
18
  /**
8
19
  * Liste des anomalies.
9
20
  * @param page Numéro de page
10
21
  * @param perPage Nombre de résultats demandé
11
22
  */
12
23
  paginateAnomalies(page?: number, perPage?: number): Collection<AnomalieDECI>;
24
+ /**
25
+ * Ajout d'une nouvelle anomalie.
26
+ * @param anomalieDECI
27
+ */
28
+ postAnomalie(anomalieDECI?: AnomalieDECI): Promise<AxiosResponse<AnomalieDECI>>;
13
29
  }
@@ -7,6 +7,34 @@ class AnomaliesAPI extends core_1.Core {
7
7
  constructor(config, client) {
8
8
  super(config, client);
9
9
  }
10
+ /**
11
+ * Suppression d'une anomalie.
12
+ * @param anomalieId Identifiant unique de l'anomalie
13
+ */
14
+ async deleteAnomalie(anomalieId) {
15
+ const pathVariable = { 'anomalie_id': anomalieId };
16
+ return this.request({
17
+ method: 'DELETE',
18
+ endpoint: utils_1.Utils.constructPath(pathVariable, '/anomalies/{anomalie_id}'),
19
+ headers: {},
20
+ params: {},
21
+ body: {}
22
+ });
23
+ }
24
+ /**
25
+ * Détails d'une anomalie.
26
+ * @param anomalieId Identifiant unique de l'anomalie
27
+ */
28
+ async getAnomalie(anomalieId) {
29
+ const pathVariable = { 'anomalie_id': anomalieId };
30
+ return this.request({
31
+ method: 'GET',
32
+ endpoint: utils_1.Utils.constructPath(pathVariable, '/anomalies/{anomalie_id}'),
33
+ headers: {},
34
+ params: {},
35
+ body: {}
36
+ });
37
+ }
10
38
  /**
11
39
  * Liste des anomalies.
12
40
  * @param page Numéro de page
@@ -22,5 +50,19 @@ class AnomaliesAPI extends core_1.Core {
22
50
  body: {}
23
51
  });
24
52
  }
53
+ /**
54
+ * Ajout d'une nouvelle anomalie.
55
+ * @param anomalieDECI
56
+ */
57
+ async postAnomalie(anomalieDECI) {
58
+ const pathVariable = {};
59
+ return this.request({
60
+ method: 'POST',
61
+ endpoint: utils_1.Utils.constructPath(pathVariable, '/anomalies'),
62
+ headers: {},
63
+ params: {},
64
+ body: { 'code': anomalieDECI?.code, 'texte': anomalieDECI?.texte, 'indice_de_gravite': anomalieDECI?.indice_de_gravite }
65
+ });
66
+ }
25
67
  }
26
68
  exports.AnomaliesAPI = AnomaliesAPI;
@@ -1,9 +1,15 @@
1
1
  import { Core, MetariscConfig } from "../core";
2
+ import type { AxiosResponse } from "axios";
2
3
  import { Client } from "../client";
3
4
  import { Collection } from "../collection";
4
5
  import { ERP } from '../model/ERP';
5
6
  export declare class ERPAPI extends Core {
6
7
  constructor(config: MetariscConfig, client?: Client);
8
+ /**
9
+ * Récupération des détails de l'ERP.
10
+ * @param erpId Identifiant unique de l'ERP
11
+ */
12
+ getErp(erpId: string): Promise<AxiosResponse<ERP>>;
7
13
  /**
8
14
  * Récupération de la liste des ERP.
9
15
  * @param page Numéro de page
package/lib/api/ERPAPI.js CHANGED
@@ -7,6 +7,20 @@ class ERPAPI extends core_1.Core {
7
7
  constructor(config, client) {
8
8
  super(config, client);
9
9
  }
10
+ /**
11
+ * Récupération des détails de l'ERP.
12
+ * @param erpId Identifiant unique de l'ERP
13
+ */
14
+ async getErp(erpId) {
15
+ const pathVariable = { 'erp_id': erpId };
16
+ return this.request({
17
+ method: 'GET',
18
+ endpoint: utils_1.Utils.constructPath(pathVariable, '/erp/{erp_id}'),
19
+ headers: {},
20
+ params: {},
21
+ body: {}
22
+ });
23
+ }
10
24
  /**
11
25
  * Récupération de la liste des ERP.
12
26
  * @param page Numéro de page
@@ -1,11 +1,20 @@
1
1
  export type PrescriptionSupportReglementaire = {
2
2
  'id'?: string;
3
3
  'nature'?: NatureEnum;
4
+ /**
5
+ * Le CID est l’identifiant commun à l’ensemble des versions d’un objet Legifrance (article, section, texte). Si le CID est renseigné, alors ce support réglementaire est sourcé depuis Legifrance.
6
+ */
4
7
  'legifrance_cid'?: string;
5
8
  'contenu'?: string;
9
+ 'titre'?: string;
10
+ 'etat'?: EtatEnum;
11
+ 'reference'?: string;
6
12
  };
7
13
  export declare enum NatureEnum {
8
14
  Arrete = "arrete",
9
15
  Article = "article",
10
16
  Local = "local"
11
17
  }
18
+ export declare enum EtatEnum {
19
+ EnVigueur = "en_vigueur"
20
+ }
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NatureEnum = void 0;
3
+ exports.EtatEnum = exports.NatureEnum = void 0;
4
4
  var NatureEnum;
5
5
  (function (NatureEnum) {
6
6
  NatureEnum["Arrete"] = "arrete";
7
7
  NatureEnum["Article"] = "article";
8
8
  NatureEnum["Local"] = "local";
9
9
  })(NatureEnum = exports.NatureEnum || (exports.NatureEnum = {}));
10
+ var EtatEnum;
11
+ (function (EtatEnum) {
12
+ EtatEnum["EnVigueur"] = "en_vigueur";
13
+ })(EtatEnum = exports.EtatEnum || (exports.EtatEnum = {}));
package/lib/tus.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Core, MetariscConfig } from "./core";
2
- import { Client } from "./client";
1
+ import { Core, MetariscConfig } from './core';
2
+ import { Client } from './client';
3
3
  export declare class Tus extends Core {
4
4
  constructor(config: MetariscConfig, client: Client);
5
5
  upload(file: File, errorFn: (error: Error) => void, chunckFn: (url: string, progress: number) => void, successFn: () => void): void;
package/lib/tus.js CHANGED
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Tus = void 0;
4
4
  const core_1 = require("./core");
5
5
  const tus_js_client_1 = require("tus-js-client");
6
+ const utils_1 = require("./utils");
7
+ const SessionExpiredError_1 = require("./error/SessionExpiredError");
6
8
  class Tus extends core_1.Core {
7
9
  constructor(config, client) {
8
10
  super(config, client);
@@ -16,8 +18,20 @@ class Tus extends core_1.Core {
16
18
  fileName: file.name,
17
19
  filetype: file.type,
18
20
  },
19
- headers: {
20
- Authorization: this.client.getAccessToken() ?? '',
21
+ onBeforeRequest: async (request) => {
22
+ const access_token = this.client.getAccessToken();
23
+ if (access_token && utils_1.Utils.tokenExpired(access_token)) {
24
+ try {
25
+ await this.refreshToken();
26
+ request.setHeader("Authorization", this.client.getAccessToken() ?? "");
27
+ }
28
+ catch (e) {
29
+ throw new SessionExpiredError_1.SessionExpiredError("La session utilisateur a expirée. " + e.message);
30
+ }
31
+ }
32
+ else {
33
+ request.setHeader("Authorization", this.client.getAccessToken() ?? "");
34
+ }
21
35
  },
22
36
  onError: (error) => {
23
37
  errorFn(error);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@metarisc/metarisc-js",
3
3
  "main": "lib/index.js",
4
4
  "types": "lib/index.d.ts",
5
- "version": "0.0.1-alpha.34",
5
+ "version": "0.0.1-alpha.35",
6
6
  "scripts": {
7
7
  "lint": "eslint . --ext .ts --fix",
8
8
  "compile": "tsc",
@@ -23,6 +23,6 @@
23
23
  "axios-oauth-client": "^2.0.4",
24
24
  "axios-retry": "^3.5.0",
25
25
  "jwt-decode": "^4.0.0",
26
- "tus-js-client": "^3.1.1"
26
+ "tus-js-client": "^4.1.0"
27
27
  }
28
28
  }
@@ -1,5 +1,6 @@
1
1
  import { Core, MetariscConfig } from "../core";
2
2
  import { Utils } from "../utils";
3
+ import type { AxiosResponse } from "axios";
3
4
  import { Client } from "../client";
4
5
  import { Collection } from "../collection";
5
6
  import { AnomalieDECI } from '../model/AnomalieDECI';
@@ -9,6 +10,38 @@ export class AnomaliesAPI extends Core {
9
10
  super(config, client);
10
11
  }
11
12
 
13
+ /**
14
+ * Suppression d'une anomalie.
15
+ * @param anomalieId Identifiant unique de l'anomalie
16
+ */
17
+ async deleteAnomalie(anomalieId: string): Promise<AxiosResponse<void>>
18
+ {
19
+ const pathVariable = { 'anomalie_id': anomalieId };
20
+ return this.request({
21
+ method: 'DELETE',
22
+ endpoint: Utils.constructPath(pathVariable, '/anomalies/{anomalie_id}'),
23
+ headers: { },
24
+ params: { },
25
+ body: {}
26
+ });
27
+ }
28
+
29
+ /**
30
+ * Détails d'une anomalie.
31
+ * @param anomalieId Identifiant unique de l'anomalie
32
+ */
33
+ async getAnomalie(anomalieId: string): Promise<AxiosResponse<AnomalieDECI>>
34
+ {
35
+ const pathVariable = { 'anomalie_id': anomalieId };
36
+ return this.request({
37
+ method: 'GET',
38
+ endpoint: Utils.constructPath(pathVariable, '/anomalies/{anomalie_id}'),
39
+ headers: { },
40
+ params: { },
41
+ body: {}
42
+ });
43
+ }
44
+
12
45
  /**
13
46
  * Liste des anomalies.
14
47
  * @param page Numéro de page
@@ -26,4 +59,20 @@ export class AnomaliesAPI extends Core {
26
59
  });
27
60
  }
28
61
 
62
+ /**
63
+ * Ajout d'une nouvelle anomalie.
64
+ * @param anomalieDECI
65
+ */
66
+ async postAnomalie(anomalieDECI?: AnomalieDECI): Promise<AxiosResponse<AnomalieDECI>>
67
+ {
68
+ const pathVariable = { };
69
+ return this.request({
70
+ method: 'POST',
71
+ endpoint: Utils.constructPath(pathVariable, '/anomalies'),
72
+ headers: { },
73
+ params: { },
74
+ body: { 'code': anomalieDECI?.code, 'texte': anomalieDECI?.texte, 'indice_de_gravite': anomalieDECI?.indice_de_gravite }
75
+ });
76
+ }
77
+
29
78
  }
package/src/api/ERPAPI.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Core, MetariscConfig } from "../core";
2
2
  import { Utils } from "../utils";
3
+ import type { AxiosResponse } from "axios";
3
4
  import { Client } from "../client";
4
5
  import { Collection } from "../collection";
5
6
  import { ERP } from '../model/ERP';
@@ -9,6 +10,22 @@ export class ERPAPI extends Core {
9
10
  super(config, client);
10
11
  }
11
12
 
13
+ /**
14
+ * Récupération des détails de l'ERP.
15
+ * @param erpId Identifiant unique de l'ERP
16
+ */
17
+ async getErp(erpId: string): Promise<AxiosResponse<ERP>>
18
+ {
19
+ const pathVariable = { 'erp_id': erpId };
20
+ return this.request({
21
+ method: 'GET',
22
+ endpoint: Utils.constructPath(pathVariable, '/erp/{erp_id}'),
23
+ headers: { },
24
+ params: { },
25
+ body: {}
26
+ });
27
+ }
28
+
12
29
  /**
13
30
  * Récupération de la liste des ERP.
14
31
  * @param page Numéro de page
@@ -1,8 +1,14 @@
1
1
  export type PrescriptionSupportReglementaire = {
2
2
  'id'?: string;
3
3
  'nature'?: NatureEnum;
4
+ /**
5
+ * Le CID est l’identifiant commun à l’ensemble des versions d’un objet Legifrance (article, section, texte). Si le CID est renseigné, alors ce support réglementaire est sourcé depuis Legifrance.
6
+ */
4
7
  'legifrance_cid'?: string;
5
8
  'contenu'?: string;
9
+ 'titre'?: string;
10
+ 'etat'?: EtatEnum;
11
+ 'reference'?: string;
6
12
  };
7
13
 
8
14
  export enum NatureEnum {
@@ -10,3 +16,7 @@ export enum NatureEnum {
10
16
  Article = 'article',
11
17
  Local = 'local'
12
18
  }
19
+
20
+ export enum EtatEnum {
21
+ EnVigueur = 'en_vigueur'
22
+ }
package/src/tus.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { Core, MetariscConfig } from "./core";
2
- import { Upload } from 'tus-js-client';
3
- import { Client } from "./client";
1
+ import { Core, MetariscConfig } from './core';
2
+ import { HttpRequest, Upload } from 'tus-js-client';
3
+ import { Client } from './client';
4
+ import { Utils } from './utils';
5
+ import { SessionExpiredError } from './error/SessionExpiredError';
4
6
 
5
7
  export class Tus extends Core
6
8
  {
@@ -17,8 +19,26 @@ export class Tus extends Core
17
19
  fileName: file.name,
18
20
  filetype: file.type,
19
21
  },
20
- headers: {
21
- Authorization: this.client.getAccessToken() ?? '',
22
+ onBeforeRequest: async (request: HttpRequest) => {
23
+ const access_token = this.client.getAccessToken();
24
+ if (access_token && Utils.tokenExpired(access_token)) {
25
+ try {
26
+ await this.refreshToken();
27
+ request.setHeader(
28
+ "Authorization",
29
+ this.client.getAccessToken() ?? ""
30
+ );
31
+ } catch (e) {
32
+ throw new SessionExpiredError(
33
+ "La session utilisateur a expirée. " + e.message
34
+ );
35
+ }
36
+ } else {
37
+ request.setHeader(
38
+ "Authorization",
39
+ this.client.getAccessToken() ?? ""
40
+ );
41
+ }
22
42
  },
23
43
  onError: (error) => {
24
44
  errorFn(error);