sfc-utils 1.4.93 → 1.4.94

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/personalize.js +29 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfc-utils",
3
- "version": "1.4.93",
3
+ "version": "1.4.94",
4
4
  "author": "ewagstaff <evanjwagstaff@gmail.com>",
5
5
  "dependencies": {
6
6
  "archieml": "^0.4.2",
package/personalize.js CHANGED
@@ -40,7 +40,7 @@ const setProfileProperty = (property, value, merge = false) => {
40
40
  return new Promise((resolve, reject) => {
41
41
  if (window) {
42
42
  if (window.blueConicClient) {
43
- // Prepare merging
43
+ // Prepare merging (note: this only handles objects, not arrays or other types)
44
44
  let conditionalPromise = Promise.resolve();
45
45
  if (merge && typeof value === "object") {
46
46
  conditionalPromise = getProfileProperty(property);
@@ -49,8 +49,10 @@ const setProfileProperty = (property, value, merge = false) => {
49
49
  conditionalPromise.then((existingValue) => {
50
50
  // Finish merging
51
51
  if (merge && typeof value === "object") {
52
- console.log("Merging values...", existingValue, value);
53
- value = JSON.stringify({ ...existingValue, ...value });
52
+ console.log("Merging values...", JSON.parse(existingValue), value);
53
+ value = JSON.stringify(
54
+ Object.assign({}, JSON.parse(existingValue), value)
55
+ );
54
56
  console.log("Merged value", value);
55
57
  }
56
58
  // Make sure property to save is a string
@@ -77,4 +79,27 @@ const setProfileProperty = (property, value, merge = false) => {
77
79
  });
78
80
  };
79
81
 
80
- module.exports = { getProfileProperty, setProfileProperty };
82
+ const clearProfileProperty = (property) => {
83
+ return new Promise((resolve, reject) => {
84
+ if (window) {
85
+ if (window.blueConicClient) {
86
+ const profile = window.blueConicClient.profile.getProfile();
87
+ const properties = [property];
88
+ profile.loadValues(properties, this, function () {
89
+ profile.setValue(property, "");
90
+ resolve(true);
91
+ });
92
+ } else {
93
+ resolve("Personalize: No BlueConic client found");
94
+ }
95
+ } else {
96
+ resolve("Personalize: No window found");
97
+ }
98
+ });
99
+ };
100
+
101
+ module.exports = {
102
+ getProfileProperty,
103
+ setProfileProperty,
104
+ clearProfileProperty,
105
+ };