@pagopa/io-react-native-wallet 2.0.0-next.9 → 2.1.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/README.md +3 -3
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +42 -122
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +3 -2
- package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -1
- package/lib/commonjs/credential/status/02-status-assertion.js.map +1 -1
- package/lib/commonjs/credential/status/03-verify-and-parse-status-assertion.js.map +1 -1
- package/lib/commonjs/sd-jwt/__test__/types.test.js +40 -0
- package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -1
- package/lib/commonjs/sd-jwt/types.js +13 -5
- package/lib/commonjs/sd-jwt/types.js.map +1 -1
- package/lib/commonjs/trust/types.js +6 -0
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/utils/credentials.js +2 -1
- package/lib/commonjs/utils/credentials.js.map +1 -1
- package/lib/commonjs/utils/misc.js +3 -1
- package/lib/commonjs/utils/misc.js.map +1 -1
- package/lib/commonjs/utils/nestedProperty.js +142 -0
- package/lib/commonjs/utils/nestedProperty.js.map +1 -0
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js +41 -121
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/module/credential/presentation/07-evaluate-dcql-query.js +3 -2
- package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -1
- package/lib/module/credential/status/02-status-assertion.js.map +1 -1
- package/lib/module/credential/status/03-verify-and-parse-status-assertion.js.map +1 -1
- package/lib/module/sd-jwt/__test__/types.test.js +41 -1
- package/lib/module/sd-jwt/__test__/types.test.js.map +1 -1
- package/lib/module/sd-jwt/types.js +11 -3
- package/lib/module/sd-jwt/types.js.map +1 -1
- package/lib/module/trust/types.js +6 -0
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/utils/credentials.js +2 -1
- package/lib/module/utils/credentials.js.map +1 -1
- package/lib/module/utils/misc.js +1 -0
- package/lib/module/utils/misc.js.map +1 -1
- package/lib/module/utils/nestedProperty.js +136 -0
- package/lib/module/utils/nestedProperty.js.map +1 -0
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +1 -1
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +2 -2
- package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -1
- package/lib/typescript/credential/status/02-status-assertion.d.ts +2 -1
- package/lib/typescript/credential/status/02-status-assertion.d.ts.map +1 -1
- package/lib/typescript/credential/status/03-verify-and-parse-status-assertion.d.ts +2 -1
- package/lib/typescript/credential/status/03-verify-and-parse-status-assertion.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/types.d.ts +12 -6
- package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +4 -0
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/utils/credentials.d.ts +2 -1
- package/lib/typescript/utils/credentials.d.ts.map +1 -1
- package/lib/typescript/utils/misc.d.ts +1 -0
- package/lib/typescript/utils/misc.d.ts.map +1 -1
- package/lib/typescript/utils/nestedProperty.d.ts +23 -0
- package/lib/typescript/utils/nestedProperty.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/credential/issuance/07-verify-and-parse-credential.ts +2 -112
- package/src/credential/presentation/07-evaluate-dcql-query.ts +4 -4
- package/src/credential/status/02-status-assertion.ts +2 -1
- package/src/credential/status/03-verify-and-parse-status-assertion.ts +2 -1
- package/src/sd-jwt/__test__/types.test.ts +49 -1
- package/src/sd-jwt/types.ts +11 -3
- package/src/trust/types.ts +4 -0
- package/src/utils/credentials.ts +6 -2
- package/src/utils/misc.ts +3 -0
- package/src/utils/nestedProperty.ts +198 -0
@@ -0,0 +1,198 @@
|
|
1
|
+
import { isObject } from "./misc";
|
2
|
+
|
3
|
+
// The data used to create localized names
|
4
|
+
type DisplayData = { locale: string; name: string }[];
|
5
|
+
|
6
|
+
// The resulting object of localized names { en: "Name", it: "Nome" }
|
7
|
+
type LocalizedNames = Record<string, string>;
|
8
|
+
|
9
|
+
// The core structure being built: a node containing the actual value and its localized names
|
10
|
+
type PropertyNode<T> = {
|
11
|
+
value: T;
|
12
|
+
name: LocalizedNames;
|
13
|
+
};
|
14
|
+
|
15
|
+
// A path can consist of object keys, array indices, or null for mapping
|
16
|
+
type Path = (string | number | null)[];
|
17
|
+
|
18
|
+
// A union of all possible shapes. It can be a custom PropertyNode or a standard object/array structure
|
19
|
+
type NodeOrStructure = Partial<PropertyNode<any>> | Record<string, any> | any[];
|
20
|
+
|
21
|
+
// Helper to build localized names from the display data.
|
22
|
+
const buildName = (display: DisplayData): LocalizedNames =>
|
23
|
+
display.reduce(
|
24
|
+
(names, { locale, name }) => ({ ...names, [locale]: name }),
|
25
|
+
{}
|
26
|
+
);
|
27
|
+
|
28
|
+
// Handles the case where the path key is `null`
|
29
|
+
const handleNullKeyCase = (
|
30
|
+
currentObject: NodeOrStructure,
|
31
|
+
rest: Path,
|
32
|
+
sourceValue: unknown,
|
33
|
+
displayData: DisplayData
|
34
|
+
): NodeOrStructure => {
|
35
|
+
if (!Array.isArray(sourceValue)) return currentObject;
|
36
|
+
|
37
|
+
// We assert the type here because we know this branch handles PropertyNodes
|
38
|
+
const node = currentObject as Partial<PropertyNode<unknown[]>>;
|
39
|
+
const existingValue = Array.isArray(node.value) ? node.value : [];
|
40
|
+
|
41
|
+
const mappedArray = sourceValue.map((item, idx) =>
|
42
|
+
createNestedProperty(existingValue[idx] || {}, rest, item, displayData)
|
43
|
+
);
|
44
|
+
|
45
|
+
return {
|
46
|
+
...node,
|
47
|
+
value: mappedArray,
|
48
|
+
name: node.name ?? buildName(displayData),
|
49
|
+
};
|
50
|
+
};
|
51
|
+
|
52
|
+
// Handles the case where the path key is a string
|
53
|
+
const handleStringKeyCase = (
|
54
|
+
currentObject: NodeOrStructure,
|
55
|
+
key: string,
|
56
|
+
rest: Path,
|
57
|
+
sourceValue: unknown,
|
58
|
+
displayData: DisplayData
|
59
|
+
): NodeOrStructure => {
|
60
|
+
let nextSourceValue = sourceValue;
|
61
|
+
const isLeaf = rest.length === 0;
|
62
|
+
|
63
|
+
if (isObject(sourceValue)) {
|
64
|
+
// Check if any remaining string keys in the path exist in current sourceValue
|
65
|
+
// This handles nested object paths (unlike arrays which use null in the path)
|
66
|
+
const hasRestKey = rest.some(
|
67
|
+
(r) => typeof r === "string" && r in sourceValue
|
68
|
+
);
|
69
|
+
|
70
|
+
if (hasRestKey) {
|
71
|
+
return handleRestKey(currentObject, key, rest, sourceValue, displayData);
|
72
|
+
}
|
73
|
+
|
74
|
+
// Skip processing when the key is not found within the claim object
|
75
|
+
if (!(key in sourceValue)) {
|
76
|
+
// Leaf node: create a node with an empty value and display name
|
77
|
+
if (isLeaf) {
|
78
|
+
return {
|
79
|
+
...currentObject,
|
80
|
+
[key]: { value: {}, name: buildName(displayData) },
|
81
|
+
};
|
82
|
+
}
|
83
|
+
// Skip processing when the key is not found within the claim object
|
84
|
+
return currentObject;
|
85
|
+
}
|
86
|
+
|
87
|
+
nextSourceValue = sourceValue[key];
|
88
|
+
}
|
89
|
+
|
90
|
+
// base case
|
91
|
+
if (isLeaf) {
|
92
|
+
return {
|
93
|
+
...currentObject,
|
94
|
+
[key]: { value: nextSourceValue, name: buildName(displayData) },
|
95
|
+
};
|
96
|
+
}
|
97
|
+
|
98
|
+
// recursive step
|
99
|
+
const nextObject =
|
100
|
+
(currentObject as Record<string, NodeOrStructure>)[key] || {};
|
101
|
+
|
102
|
+
return {
|
103
|
+
...currentObject,
|
104
|
+
[key]: createNestedProperty(nextObject, rest, nextSourceValue, displayData),
|
105
|
+
};
|
106
|
+
};
|
107
|
+
|
108
|
+
// Handles the case where the path key is a number
|
109
|
+
const handleNumberKeyCase = (
|
110
|
+
currentObject: NodeOrStructure,
|
111
|
+
key: number,
|
112
|
+
rest: Path,
|
113
|
+
sourceValue: unknown,
|
114
|
+
displayData: DisplayData
|
115
|
+
): NodeOrStructure => {
|
116
|
+
const newArray = Array.isArray(currentObject) ? [...currentObject] : [];
|
117
|
+
const nextValue = Array.isArray(sourceValue) ? sourceValue[key] : undefined;
|
118
|
+
|
119
|
+
newArray[key] = createNestedProperty(
|
120
|
+
newArray[key] || {},
|
121
|
+
rest,
|
122
|
+
nextValue,
|
123
|
+
displayData
|
124
|
+
);
|
125
|
+
return newArray;
|
126
|
+
};
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Recursively constructs a nested object with descriptive properties from a path.
|
130
|
+
*
|
131
|
+
* @param currentObject - The object or array being built upon.
|
132
|
+
* @param path - The path segments to follow.
|
133
|
+
* @param sourceValue - The raw value to place at the end of the path.
|
134
|
+
* @param displayData - The data for generating localized names.
|
135
|
+
* @returns The new object or array structure.
|
136
|
+
*/
|
137
|
+
export const createNestedProperty = (
|
138
|
+
currentObject: NodeOrStructure,
|
139
|
+
path: Path,
|
140
|
+
sourceValue: unknown, // Use `unknown` for type-safe input
|
141
|
+
displayData: DisplayData
|
142
|
+
): NodeOrStructure => {
|
143
|
+
const [key, ...rest] = path;
|
144
|
+
|
145
|
+
switch (true) {
|
146
|
+
case key === null:
|
147
|
+
return handleNullKeyCase(currentObject, rest, sourceValue, displayData);
|
148
|
+
|
149
|
+
case typeof key === "string":
|
150
|
+
return handleStringKeyCase(
|
151
|
+
currentObject,
|
152
|
+
key as string,
|
153
|
+
rest,
|
154
|
+
sourceValue,
|
155
|
+
displayData
|
156
|
+
);
|
157
|
+
|
158
|
+
case typeof key === "number":
|
159
|
+
return handleNumberKeyCase(
|
160
|
+
currentObject,
|
161
|
+
key as number,
|
162
|
+
rest,
|
163
|
+
sourceValue,
|
164
|
+
displayData
|
165
|
+
);
|
166
|
+
|
167
|
+
default:
|
168
|
+
return currentObject;
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
// Handles the case where the next key in the path exists in the source object
|
173
|
+
const handleRestKey = (
|
174
|
+
currentObject: Record<string, any>,
|
175
|
+
key: string,
|
176
|
+
rest: Path,
|
177
|
+
sourceValue: Record<string, unknown>,
|
178
|
+
displayData: DisplayData
|
179
|
+
): NodeOrStructure => {
|
180
|
+
const currentNode = currentObject[key] ?? {};
|
181
|
+
// Take the first key in the remaining path
|
182
|
+
const restKey = rest[0] as string;
|
183
|
+
const nextSourceValue = sourceValue[restKey];
|
184
|
+
|
185
|
+
// Merge the current node with the updated nested property for the remaining path.
|
186
|
+
return {
|
187
|
+
...currentObject,
|
188
|
+
[key]: {
|
189
|
+
...currentNode,
|
190
|
+
value: createNestedProperty(
|
191
|
+
currentNode.value ?? {},
|
192
|
+
rest,
|
193
|
+
nextSourceValue,
|
194
|
+
displayData
|
195
|
+
),
|
196
|
+
},
|
197
|
+
};
|
198
|
+
};
|