@growy/strapi-plugin-encrypted-field 1.2.1 → 1.3.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.
- package/admin/src/components/Input.jsx +13 -48
- package/package.json +1 -1
- package/server/bootstrap.js +1 -43
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
-
import { Field,
|
|
4
|
-
import { Eye, EyeStriked, Duplicate, Check } from '@strapi/icons';
|
|
3
|
+
import { Field, Typography } from '@strapi/design-system';
|
|
5
4
|
|
|
6
5
|
const Input = (props) => {
|
|
7
6
|
const {
|
|
@@ -18,27 +17,13 @@ const Input = (props) => {
|
|
|
18
17
|
} = props;
|
|
19
18
|
|
|
20
19
|
const { formatMessage } = useIntl();
|
|
21
|
-
const [showValue, setShowValue] = useState(false);
|
|
22
|
-
const [copied, setCopied] = useState(false);
|
|
23
|
-
|
|
24
|
-
const handleCopy = async () => {
|
|
25
|
-
if (value) {
|
|
26
|
-
try {
|
|
27
|
-
await navigator.clipboard.writeText(value);
|
|
28
|
-
setCopied(true);
|
|
29
|
-
setTimeout(() => setCopied(false), 2000);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
console.error('Error al copiar:', err);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
20
|
|
|
36
21
|
const handleChange = (e) => {
|
|
37
22
|
onChange({
|
|
38
23
|
target: {
|
|
39
24
|
name,
|
|
40
25
|
value: e.target.value,
|
|
41
|
-
type: attribute?.type || '
|
|
26
|
+
type: attribute?.type || 'string',
|
|
42
27
|
},
|
|
43
28
|
});
|
|
44
29
|
};
|
|
@@ -53,29 +38,11 @@ const Input = (props) => {
|
|
|
53
38
|
hint={description?.id ? formatMessage(description) : description}
|
|
54
39
|
required={required}
|
|
55
40
|
>
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
</Field.Label>
|
|
60
|
-
<Flex gap={2}>
|
|
61
|
-
<IconButton
|
|
62
|
-
label={showValue ? 'Ocultar valor' : 'Mostrar valor'}
|
|
63
|
-
icon={showValue ? <EyeStriked /> : <Eye />}
|
|
64
|
-
onClick={() => setShowValue(!showValue)}
|
|
65
|
-
variant="ghost"
|
|
66
|
-
disabled={!value}
|
|
67
|
-
/>
|
|
68
|
-
<IconButton
|
|
69
|
-
label={copied ? 'Copiado' : 'Copiar valor'}
|
|
70
|
-
icon={copied ? <Check /> : <Duplicate />}
|
|
71
|
-
onClick={handleCopy}
|
|
72
|
-
variant="ghost"
|
|
73
|
-
disabled={!value}
|
|
74
|
-
/>
|
|
75
|
-
</Flex>
|
|
76
|
-
</Flex>
|
|
41
|
+
<Field.Label action={labelAction}>
|
|
42
|
+
{intlLabel?.id ? formatMessage(intlLabel) : intlLabel}
|
|
43
|
+
</Field.Label>
|
|
77
44
|
<Field.Input
|
|
78
|
-
type=
|
|
45
|
+
type="password"
|
|
79
46
|
placeholder={formatMessage({
|
|
80
47
|
id: 'encrypted-field.placeholder',
|
|
81
48
|
defaultMessage: 'Ingresa el texto a cifrar...',
|
|
@@ -84,14 +51,12 @@ const Input = (props) => {
|
|
|
84
51
|
onChange={handleChange}
|
|
85
52
|
disabled={disabled}
|
|
86
53
|
/>
|
|
87
|
-
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
)}
|
|
94
|
-
</Flex>
|
|
54
|
+
{charCount > 0 && (
|
|
55
|
+
<Typography variant="pi" textColor="neutral600" marginTop={1}>
|
|
56
|
+
{charCount} {charCount === 1 ? 'carácter' : 'caracteres'}
|
|
57
|
+
</Typography>
|
|
58
|
+
)}
|
|
59
|
+
<Field.Hint />
|
|
95
60
|
<Field.Error />
|
|
96
61
|
</Field.Root>
|
|
97
62
|
);
|
package/package.json
CHANGED
package/server/bootstrap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { encrypt,
|
|
1
|
+
const { encrypt, validateValue, isEncryptedField } = require('./utils/crypto');
|
|
2
2
|
|
|
3
3
|
module.exports = ({ strapi }) => {
|
|
4
4
|
strapi.db.lifecycles.subscribe({
|
|
@@ -49,47 +49,5 @@ module.exports = ({ strapi }) => {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
-
|
|
53
|
-
async afterFindOne(event) {
|
|
54
|
-
const { result } = event;
|
|
55
|
-
if (!result) return;
|
|
56
|
-
if (!event.model?.uid) return;
|
|
57
|
-
|
|
58
|
-
const model = strapi.getModel(event.model.uid);
|
|
59
|
-
|
|
60
|
-
if (!model?.attributes) return;
|
|
61
|
-
|
|
62
|
-
for (const [key, attribute] of Object.entries(model.attributes)) {
|
|
63
|
-
if (!isEncryptedField(attribute)) continue;
|
|
64
|
-
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
65
|
-
const value = result[key];
|
|
66
|
-
if (typeof value === 'string') {
|
|
67
|
-
result[key] = decrypt(value, strapi);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
async afterFindMany(event) {
|
|
74
|
-
const { result } = event;
|
|
75
|
-
if (!result || !Array.isArray(result)) return;
|
|
76
|
-
if (!event.model?.uid) return;
|
|
77
|
-
|
|
78
|
-
const model = strapi.getModel(event.model.uid);
|
|
79
|
-
|
|
80
|
-
if (!model?.attributes) return;
|
|
81
|
-
|
|
82
|
-
for (const item of result) {
|
|
83
|
-
for (const [key, attribute] of Object.entries(model.attributes)) {
|
|
84
|
-
if (!isEncryptedField(attribute)) continue;
|
|
85
|
-
if (Object.prototype.hasOwnProperty.call(item, key)) {
|
|
86
|
-
const value = item[key];
|
|
87
|
-
if (typeof value === 'string') {
|
|
88
|
-
item[key] = decrypt(value, strapi);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
52
|
});
|
|
95
53
|
};
|