@fto-consult/expo-ui 8.42.0 → 8.43.0

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/pdf/index.js +30 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "8.42.0",
3
+ "version": "8.43.0",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "scripts": {
6
6
  "clear-npx-cache": "npx clear-npx-cache",
package/src/pdf/index.js CHANGED
@@ -3,13 +3,40 @@ import Preloader from "$preloader";
3
3
  import pdfMake from "$cpdf/pdfmake";
4
4
  import notify from "$cnotify";
5
5
  import DialogProvider from "$ecomponents/Form/FormData/DialogProvider";
6
- import {isNonNullString,defaultObj,defaultStr,extendObj,defaultNumber} from "$cutils";
6
+ import {isNonNullString,defaultObj,defaultStr,extendObj,defaultNumber,isJSON} from "$cutils";
7
7
  import session from "$session";
8
8
  import printPdfMake from "./print";
9
9
  import appConfig from "$capp/config";
10
10
  import Auth from "$cauth";
11
11
  import DateLib from "$clib/date";
12
+ import crypToJS from "$clib/crypto-js";
12
13
 
14
+ export const QR_CODE_HASH_KEY_PREFIX = defaultStr(appConfig.name).replace(/\s/g, "");
15
+ export const QR_CODE_HASH_KEY = `${QR_CODE_HASH_KEY_PREFIX}-QR_CODE_HASH_KEY`;//la clé de décryptage du QRCODE
16
+
17
+
18
+ /****
19
+ génère la valeur haschée de la données d'un qrCode
20
+ */
21
+ export const hashQRCode = (data)=>{
22
+ try {
23
+ return crypToJS.encode(JSON.stringify(data),QR_CODE_HASH_KEY).toString()
24
+ } catch(Exception){
25
+ return null;
26
+ }
27
+ }
28
+
29
+ export const decryptQRCode = (hashedQRCode)=>{
30
+ return crypToJS.decode(hashedQRCode,QR_CODE_HASH_KEY);
31
+ }
32
+
33
+ export const isValidQRCode = (data)=>{
34
+ if(isJSON(data)){
35
+ data = JSON.parse(data);
36
+ }
37
+ data = defaultObj(data);
38
+ return hashQRCode(data.data) === data.hash && QR_CODE_HASH_KEY_PREFIX.toLowerCase() == defaultStr(data.provider).toLowerCase().replace(/\s/g, "");
39
+ }
13
40
 
14
41
  const {createPdf} = pdfMake;
15
42
  pdfMake.createPdf = (docDefinition,...rest)=>{
@@ -173,7 +200,7 @@ export const getPrintSettings = ({multiple,duplicateDocOnPage,isTableData,tableD
173
200
  type :"number",
174
201
  defaultValue : 150,
175
202
  label : "Taille du QR Code",
176
- validType : "numberGreaterThanOrEquals[100]"
203
+ validType : "numberGreaterThanOrEquals[120]"
177
204
  },
178
205
  }:{})
179
206
  },getFields(formDataProps.data))
@@ -262,7 +289,7 @@ export function printTableData(data,options){
262
289
  const pseudo = Auth.getUserPseudo();
263
290
  const fullName = Auth.getUserFullName() || pseudo || Auth.getLoggedUserCode();
264
291
  const printBy = isNonNullString(fullName)? (`${fullName}${uEmail?`[${uEmail}]`:""}`) : "";
265
- result.content.push({ qr: JSON.stringify({data:qrData,printBy,printDate:new Date().toFormat(DateLib.defaultDateTimeFormat),foreignKeyTable:table,table}),margin:[0,8,0,5], fit: defaultNumber(data.qrCodeFitSize,150), alignment: qrCodeAlignmentPosition})
292
+ result.content.push({ qr: JSON.stringify({data:qrData,hash:hashQRCode(qrData),provider:defaultStr(appConfig.name).replace(/\s/g, ""),printBy,printDate:new Date().toFormat(DateLib.defaultDateTimeFormat),tableName:table}),margin:[0,8,0,5], fit: defaultNumber(data.qrCodeFitSize,150), alignment: qrCodeAlignmentPosition})
266
293
  }
267
294
  }
268
295
  return result;