@fto-consult/expo-ui 8.42.0 → 8.43.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/pdf/index.js +45 -4
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.1",
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,54 @@ 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 decryptQRCodeData = (hashedQRCode)=>{
30
+ try {
31
+ return crypToJS.decode(hashedQRCode,QR_CODE_HASH_KEY);
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ export const isValidQRCode = (data)=>{
38
+ if(isJSON(data)){
39
+ data = JSON.parse(data);
40
+ }
41
+ data = defaultObj(data);
42
+ data.data = decryptQRCodeData(data.data);
43
+ if(!data.data || !isJSON(data.data)) return false;
44
+ return QR_CODE_HASH_KEY_PREFIX.toLowerCase() == defaultStr(data.provider).toLowerCase().replace(/\s/g, "");
45
+ }
46
+ export const decryptQRCode = (data)=>{
47
+ if(isJSON(data)){
48
+ data = JSON.parse(data);
49
+ }
50
+ data = defaultObj(data);
51
+ if(!isValidQRCode(data)) return null;
52
+ return data;
53
+ }
13
54
 
14
55
  const {createPdf} = pdfMake;
15
56
  pdfMake.createPdf = (docDefinition,...rest)=>{
@@ -171,9 +212,9 @@ export const getPrintSettings = ({multiple,duplicateDocOnPage,isTableData,tableD
171
212
  },
172
213
  qrCodeFitSize : {
173
214
  type :"number",
174
- defaultValue : 150,
215
+ defaultValue : 120,
175
216
  label : "Taille du QR Code",
176
- validType : "numberGreaterThanOrEquals[100]"
217
+ validType : "numberGreaterThanOrEquals[120]"
177
218
  },
178
219
  }:{})
179
220
  },getFields(formDataProps.data))
@@ -262,7 +303,7 @@ export function printTableData(data,options){
262
303
  const pseudo = Auth.getUserPseudo();
263
304
  const fullName = Auth.getUserFullName() || pseudo || Auth.getLoggedUserCode();
264
305
  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})
306
+ result.content.push({ qr: JSON.stringify({data: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,120), alignment: qrCodeAlignmentPosition})
266
307
  }
267
308
  }
268
309
  return result;