@didomi/react-native 2.0.1 → 2.2.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/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativedidomi/DidomiModule.kt +21 -0
- package/ios/Didomi.m +7 -0
- package/ios/RNDidomi.swift +103 -86
- package/lib/commonjs/Constants.js +1 -1
- package/lib/commonjs/Constants.js.map +1 -1
- package/lib/commonjs/CurrentUserStatusTransaction.js +102 -0
- package/lib/commonjs/CurrentUserStatusTransaction.js.map +1 -0
- package/lib/commonjs/Didomi.js +9 -1
- package/lib/commonjs/Didomi.js.map +1 -1
- package/lib/module/Constants.js +1 -1
- package/lib/module/Constants.js.map +1 -1
- package/lib/module/CurrentUserStatusTransaction.js +95 -0
- package/lib/module/CurrentUserStatusTransaction.js.map +1 -0
- package/lib/module/Didomi.js +9 -1
- package/lib/module/Didomi.js.map +1 -1
- package/lib/typescript/Constants.d.ts +1 -1
- package/lib/typescript/CurrentUserStatusTransaction.d.ts +14 -0
- package/lib/typescript/Didomi.d.ts +8 -0
- package/package.json +1 -1
- package/react-native-didomi.podspec +1 -1
- package/src/Constants.ts +1 -1
- package/src/CurrentUserStatusTransaction.ts +140 -0
- package/src/Didomi.ts +9 -0
package/package.json
CHANGED
package/src/Constants.ts
CHANGED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { PurposeStatus, VendorStatus } from './DidomiTypes';
|
|
2
|
+
|
|
3
|
+
// Transaction type exposed to client's app that allows the enabling and disabling of vendors and purposes.
|
|
4
|
+
export interface CurrentUserStatusTransaction {
|
|
5
|
+
// Function to enable a specific purpose by its ID and returns the updated transaction
|
|
6
|
+
enablePurpose(id: string): CurrentUserStatusTransaction;
|
|
7
|
+
|
|
8
|
+
// Function to enable multiple purposes at once by their IDs and returns the updated transaction
|
|
9
|
+
enablePurposes(ids: string[]): CurrentUserStatusTransaction;
|
|
10
|
+
|
|
11
|
+
// Function to enable a specific vendor by its ID and returns the updated transaction
|
|
12
|
+
enableVendor(id: string): CurrentUserStatusTransaction;
|
|
13
|
+
|
|
14
|
+
// Function to enable multiple vendors at once by their IDs and returns the updated transaction
|
|
15
|
+
enableVendors(ids: string[]): CurrentUserStatusTransaction;
|
|
16
|
+
|
|
17
|
+
// Function to disable a specific purpose by its ID and returns the updated transaction
|
|
18
|
+
disablePurpose(id: string): CurrentUserStatusTransaction;
|
|
19
|
+
|
|
20
|
+
// Function to disable multiple purposes at once by their IDs and returns the updated transaction
|
|
21
|
+
disablePurposes(ids: string[]): CurrentUserStatusTransaction;
|
|
22
|
+
|
|
23
|
+
// Function to disable a specific vendor by its ID and returns the updated transaction
|
|
24
|
+
disableVendor(id: string): CurrentUserStatusTransaction;
|
|
25
|
+
|
|
26
|
+
// Function to disable multiple vendors at once by their IDs and returns the updated transaction
|
|
27
|
+
disableVendors(ids: string[]): CurrentUserStatusTransaction;
|
|
28
|
+
|
|
29
|
+
// Function to commit the changes made to the status of purposes and vendors
|
|
30
|
+
// Returns a Promise that resolves to a boolean indicating whether the commit was successful
|
|
31
|
+
commit(): Promise<boolean>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Interface used to transfer enabled and disabled IDs between internal methods in a more convenient way.
|
|
35
|
+
interface StatusIDs {
|
|
36
|
+
enabled: string[];
|
|
37
|
+
disabled: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Callback executed once changes are committed to the native implementation.
|
|
41
|
+
type NativeCallback = (
|
|
42
|
+
enabledPurposes: string[],
|
|
43
|
+
disabledPurposes: string[],
|
|
44
|
+
enabledVendors: string[],
|
|
45
|
+
disabledVendors: string[]
|
|
46
|
+
) => Promise<boolean>;
|
|
47
|
+
|
|
48
|
+
// Create a `CurrentUserStatusTransaction` object based on the native implementation.
|
|
49
|
+
// Please note that this implementation delays the interaction with the native libraries until the changes are committed.
|
|
50
|
+
export const createCurrentUserStatusTransaction = (nativeCallback: NativeCallback): CurrentUserStatusTransaction => {
|
|
51
|
+
|
|
52
|
+
// Variable used to store statuses before changes are committed against the transaction.
|
|
53
|
+
let purposesStatus: { [key: string]: PurposeStatus } = {};
|
|
54
|
+
let vendorsStatus: { [key: string]: VendorStatus } = {};
|
|
55
|
+
|
|
56
|
+
const enablePurposes = (ids: string[]): CurrentUserStatusTransaction => {
|
|
57
|
+
ids.forEach(enablePurpose);
|
|
58
|
+
return transaction;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const enablePurpose = (id: string): CurrentUserStatusTransaction => {
|
|
62
|
+
purposesStatus[id] = { id, enabled: true };
|
|
63
|
+
return transaction;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const enableVendors = (ids: string[]): CurrentUserStatusTransaction => {
|
|
67
|
+
ids.forEach(enableVendor);
|
|
68
|
+
return transaction;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const enableVendor = (id: string): CurrentUserStatusTransaction => {
|
|
72
|
+
vendorsStatus[id] = { id, enabled: true };
|
|
73
|
+
return transaction;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const disablePurposes = (ids: string[]): CurrentUserStatusTransaction => {
|
|
77
|
+
ids.forEach(disablePurpose);
|
|
78
|
+
return transaction;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const disablePurpose = (id: string): CurrentUserStatusTransaction => {
|
|
82
|
+
purposesStatus[id] = { id, enabled: false };
|
|
83
|
+
return transaction;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const disableVendors = (ids: string[]) => {
|
|
87
|
+
ids.forEach(disableVendor);
|
|
88
|
+
return transaction;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const disableVendor = (id: string): CurrentUserStatusTransaction => {
|
|
92
|
+
vendorsStatus[id] = { id, enabled: false };
|
|
93
|
+
return transaction;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const commit = (): Promise<boolean> => {
|
|
97
|
+
const vendorIdsFromStatus = getIdsFromStatus(vendorsStatus);
|
|
98
|
+
const purposeIdsFromStatus = getIdsFromStatus(purposesStatus);
|
|
99
|
+
|
|
100
|
+
const result = nativeCallback(
|
|
101
|
+
purposeIdsFromStatus.enabled,
|
|
102
|
+
purposeIdsFromStatus.disabled,
|
|
103
|
+
vendorIdsFromStatus.enabled,
|
|
104
|
+
vendorIdsFromStatus.disabled,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const transaction: CurrentUserStatusTransaction = {
|
|
111
|
+
enablePurpose,
|
|
112
|
+
enablePurposes,
|
|
113
|
+
enableVendor,
|
|
114
|
+
enableVendors,
|
|
115
|
+
disablePurpose,
|
|
116
|
+
disablePurposes,
|
|
117
|
+
disableVendor,
|
|
118
|
+
disableVendors,
|
|
119
|
+
commit,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
return transaction;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Separates and returns IDs from the `status` object into `enabled` and `disabled` based on their `enabled` state.
|
|
126
|
+
const getIdsFromStatus = (status: { [key: string]: PurposeStatus } | { [key: string]: VendorStatus }): StatusIDs => {
|
|
127
|
+
let enabled: string[] = [];
|
|
128
|
+
let disabled: string[] = [];
|
|
129
|
+
const keys = Object.keys(status);
|
|
130
|
+
keys.forEach((key) => {
|
|
131
|
+
const value = status[key];
|
|
132
|
+
if (value.enabled) {
|
|
133
|
+
enabled.push(key);
|
|
134
|
+
} else {
|
|
135
|
+
disabled.push(key);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return { enabled, disabled };
|
|
140
|
+
}
|
package/src/Didomi.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { NativeModules } from 'react-native';
|
|
|
2
2
|
import { DidomiListener } from './DidomiListener';
|
|
3
3
|
import { DidomiEventType, Purpose, Vendor, UserStatus, CurrentUserStatus, VendorStatus } from './DidomiTypes';
|
|
4
4
|
import { DIDOMI_USER_AGENT_NAME, DIDOMI_VERSION } from './Constants';
|
|
5
|
+
import { CurrentUserStatusTransaction, createCurrentUserStatusTransaction } from './CurrentUserStatusTransaction';
|
|
5
6
|
|
|
6
7
|
const { Didomi: RNDidomi } = NativeModules;
|
|
7
8
|
|
|
@@ -722,4 +723,12 @@ export const Didomi = {
|
|
|
722
723
|
*/
|
|
723
724
|
updateSelectedLanguage: (languageCode: string): Promise<void> =>
|
|
724
725
|
RNDidomi.updateSelectedLanguage(languageCode),
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Creates a `CurrentUserStatusTransaction` object.
|
|
729
|
+
* This object provides mechanisms to stage updates to the user status regarding purposes and vendors, allowing for batch operations.
|
|
730
|
+
* Updates made through its methods are queued and applied simultaneously to the user status only once the commit method of the returned object is called.
|
|
731
|
+
* @returns A new `CurrentUserStatusTransaction` object.
|
|
732
|
+
*/
|
|
733
|
+
openCurrentUserStatusTransaction: (): CurrentUserStatusTransaction => createCurrentUserStatusTransaction(RNDidomi.commitCurrentUserStatusTransaction),
|
|
725
734
|
};
|