Skip to content

Commit 35d21a5

Browse files
authored
Use safe navigation for objects when reading tcf purpose (#171)
1 parent 8edaf0f commit 35d21a5

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/core/regs/consent.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ function tcfPurpose(data: tcf.cmpapi.TCData, purpose: number, vendorID?: number)
9797
}
9898

9999
if (vendorID) {
100-
return data.purpose.consents[purpose] && data.vendor.consents[vendorID];
100+
return !!data.purpose?.consents?.[purpose] && !!data.vendor?.consents?.[vendorID];
101101
}
102-
return !!data.publisher.consents[purpose];
102+
return !!data.publisher?.consents?.[purpose];
103103
}
104104

105105
function gppCanPurpose(data: gpp.cmpapi.PingReturn, purpose: number, vendorID?: number): boolean {

lib/core/regs/tcf/cmpapi.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,41 @@ type TCData = {
1717
useNonStandardStacks: boolean;
1818
publisherCC: string;
1919
purposeOneTreatment: boolean;
20-
purpose: {
21-
consents: {
20+
purpose?: {
21+
consents?: {
2222
[purposeID: string]: boolean;
2323
};
24-
legitimateInterests: {
24+
legitimateInterests?: {
2525
[purposeID: string]: boolean;
2626
};
2727
};
28-
vendor: {
29-
consents: {
28+
vendor?: {
29+
consents?: {
3030
[vendorID: string]: boolean;
3131
};
32-
legitimateInterests: {
32+
legitimateInterests?: {
3333
[vendorID: string]: boolean;
3434
};
3535
};
3636
specialFeatureOptins: {
3737
[featureID: string]: boolean;
3838
};
39-
publisher: {
40-
consents: {
39+
publisher?: {
40+
consents?: {
4141
[purposeID: string]: boolean;
4242
};
43-
legitimateInterests: {
43+
legitimateInterests?: {
4444
[purposeID: string]: boolean;
4545
};
46-
customPurpose: {
47-
consents: {
46+
customPurpose?: {
47+
consents?: {
4848
[purposeID: string]: boolean;
4949
};
50-
legitimateInterests: {
50+
legitimateInterests?: {
5151
[purposeID: string]: boolean;
5252
};
5353
};
54-
restrictions: {
54+
restrictions?: {
5555
[purposeID: string]: {
5656
[vendorID: string]: 0 | 1 | 2;
5757
};

0 commit comments

Comments
 (0)