sfc-utils 1.4.92 → 1.4.93
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/package.json +1 -1
- package/personalize.js +28 -6
package/package.json
CHANGED
package/personalize.js
CHANGED
|
@@ -36,15 +36,37 @@ const getProfileProperty = (property) => {
|
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
const setProfileProperty = (property, value) => {
|
|
39
|
+
const setProfileProperty = (property, value, merge = false) => {
|
|
40
40
|
return new Promise((resolve, reject) => {
|
|
41
41
|
if (window) {
|
|
42
42
|
if (window.blueConicClient) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
// Prepare merging
|
|
44
|
+
let conditionalPromise = Promise.resolve();
|
|
45
|
+
if (merge && typeof value === "object") {
|
|
46
|
+
conditionalPromise = getProfileProperty(property);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
conditionalPromise.then((existingValue) => {
|
|
50
|
+
// Finish merging
|
|
51
|
+
if (merge && typeof value === "object") {
|
|
52
|
+
console.log("Merging values...", existingValue, value);
|
|
53
|
+
value = JSON.stringify({ ...existingValue, ...value });
|
|
54
|
+
console.log("Merged value", value);
|
|
55
|
+
}
|
|
56
|
+
// Make sure property to save is a string
|
|
57
|
+
// If object, stringify it
|
|
58
|
+
if (typeof value === "object") {
|
|
59
|
+
value = JSON.stringify(value);
|
|
60
|
+
} else if (typeof value === "boolean" || typeof value === "number") {
|
|
61
|
+
value = value.toString();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const profile = window.blueConicClient.profile.getProfile();
|
|
65
|
+
const properties = [property];
|
|
66
|
+
profile.loadValues(properties, this, function () {
|
|
67
|
+
profile.setValue(property, value);
|
|
68
|
+
resolve(true);
|
|
69
|
+
});
|
|
48
70
|
});
|
|
49
71
|
} else {
|
|
50
72
|
resolve("Personalize: No BlueConic client found");
|