@mparticle/web-rokt-kit 1.2.1 → 1.3.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.
@@ -34,6 +34,21 @@ var constructor = function () {
34
34
  self.filteredUser = {};
35
35
  self.userAttributes = {};
36
36
 
37
+ /**
38
+ * Passes attributes to the Rokt Web SDK for client-side hashing
39
+ * @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
40
+ * @param {Object} attributes - The attributes to be hashed
41
+ * @returns {Promise<Object|null>} A Promise resolving to the
42
+ * hashed attributes from the launcher, or `null` if the kit is not initialized
43
+ */
44
+ function hashAttributes(attributes) {
45
+ if (!isInitialized()) {
46
+ console.error('Rokt Kit: Not initialized');
47
+ return null;
48
+ }
49
+ return self.launcher.hashAttributes(attributes);
50
+ }
51
+
37
52
  function initForwarder(
38
53
  settings,
39
54
  _service,
@@ -85,12 +100,15 @@ var constructor = function () {
85
100
  }
86
101
  }
87
102
 
103
+ /**
104
+ * Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options
105
+ * @see https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
106
+ * @param {Object} options - The options object for selecting placements containing:
107
+ * - identifier {string}: The placement identifier
108
+ * - attributes {Object}: Optional attributes to merge with existing attributes
109
+ * @returns {Promise<void>} A Promise resolving to the Rokt launcher's selectPlacements method with processed attributes
110
+ */
88
111
  function selectPlacements(options) {
89
- // https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
90
- // options should contain:
91
- // - identifier
92
- // - attributes
93
-
94
112
  var attributes = (options && options.attributes) || {};
95
113
  var placementAttributes = mergeObjects(self.userAttributes, attributes);
96
114
 
@@ -162,7 +180,7 @@ var constructor = function () {
162
180
  'wsdkv_' +
163
181
  window.mParticle.getVersion() +
164
182
  '_kitv_' +
165
- "1.2.1",
183
+ "1.3.0",
166
184
  })
167
185
  .then(function (launcher) {
168
186
  // Assign the launcher to a global variable for later access
@@ -196,9 +214,6 @@ var constructor = function () {
196
214
  });
197
215
  }
198
216
 
199
- // Called by the mParticle Rokt Manager
200
- this.selectPlacements = selectPlacements;
201
-
202
217
  // mParticle Kit Callback Methods
203
218
  function fetchOptimizely() {
204
219
  var forwarders = window.mParticle
@@ -240,10 +255,27 @@ var constructor = function () {
240
255
  }
241
256
  return {};
242
257
  }
258
+
259
+ // Called by the mParticle Rokt Manager
260
+ this.selectPlacements = selectPlacements;
261
+ this.hashAttributes = hashAttributes;
262
+
263
+ // Kit Callback Methods
243
264
  this.init = initForwarder;
244
265
  this.setUserAttribute = setUserAttribute;
245
266
  this.onUserIdentified = onUserIdentified;
246
267
  this.removeUserAttribute = removeUserAttribute;
268
+
269
+ /**
270
+ * Checks if the kit is properly initialized and ready for use.
271
+ * Both conditions must be true:
272
+ * 1. self.isInitialized - Set after successful initialization of the kit
273
+ * 2. self.launcher - The Rokt launcher instance must be available
274
+ * @returns {boolean} Whether the kit is fully initialized
275
+ */
276
+ function isInitialized() {
277
+ return !!(self.isInitialized && self.launcher);
278
+ }
247
279
  };
248
280
 
249
281
  function getId() {
@@ -33,6 +33,21 @@ var RoktKit = (function (exports) {
33
33
  self.filteredUser = {};
34
34
  self.userAttributes = {};
35
35
 
36
+ /**
37
+ * Passes attributes to the Rokt Web SDK for client-side hashing
38
+ * @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
39
+ * @param {Object} attributes - The attributes to be hashed
40
+ * @returns {Promise<Object|null>} A Promise resolving to the
41
+ * hashed attributes from the launcher, or `null` if the kit is not initialized
42
+ */
43
+ function hashAttributes(attributes) {
44
+ if (!isInitialized()) {
45
+ console.error('Rokt Kit: Not initialized');
46
+ return null;
47
+ }
48
+ return self.launcher.hashAttributes(attributes);
49
+ }
50
+
36
51
  function initForwarder(
37
52
  settings,
38
53
  _service,
@@ -84,12 +99,15 @@ var RoktKit = (function (exports) {
84
99
  }
85
100
  }
86
101
 
102
+ /**
103
+ * Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options
104
+ * @see https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
105
+ * @param {Object} options - The options object for selecting placements containing:
106
+ * - identifier {string}: The placement identifier
107
+ * - attributes {Object}: Optional attributes to merge with existing attributes
108
+ * @returns {Promise<void>} A Promise resolving to the Rokt launcher's selectPlacements method with processed attributes
109
+ */
87
110
  function selectPlacements(options) {
88
- // https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
89
- // options should contain:
90
- // - identifier
91
- // - attributes
92
-
93
111
  var attributes = (options && options.attributes) || {};
94
112
  var placementAttributes = mergeObjects(self.userAttributes, attributes);
95
113
 
@@ -161,7 +179,7 @@ var RoktKit = (function (exports) {
161
179
  'wsdkv_' +
162
180
  window.mParticle.getVersion() +
163
181
  '_kitv_' +
164
- "1.2.1",
182
+ "1.3.0",
165
183
  })
166
184
  .then(function (launcher) {
167
185
  // Assign the launcher to a global variable for later access
@@ -195,9 +213,6 @@ var RoktKit = (function (exports) {
195
213
  });
196
214
  }
197
215
 
198
- // Called by the mParticle Rokt Manager
199
- this.selectPlacements = selectPlacements;
200
-
201
216
  // mParticle Kit Callback Methods
202
217
  function fetchOptimizely() {
203
218
  var forwarders = window.mParticle
@@ -239,10 +254,27 @@ var RoktKit = (function (exports) {
239
254
  }
240
255
  return {};
241
256
  }
257
+
258
+ // Called by the mParticle Rokt Manager
259
+ this.selectPlacements = selectPlacements;
260
+ this.hashAttributes = hashAttributes;
261
+
262
+ // Kit Callback Methods
242
263
  this.init = initForwarder;
243
264
  this.setUserAttribute = setUserAttribute;
244
265
  this.onUserIdentified = onUserIdentified;
245
266
  this.removeUserAttribute = removeUserAttribute;
267
+
268
+ /**
269
+ * Checks if the kit is properly initialized and ready for use.
270
+ * Both conditions must be true:
271
+ * 1. self.isInitialized - Set after successful initialization of the kit
272
+ * 2. self.launcher - The Rokt launcher instance must be available
273
+ * @returns {boolean} Whether the kit is fully initialized
274
+ */
275
+ function isInitialized() {
276
+ return !!(self.isInitialized && self.launcher);
277
+ }
246
278
  };
247
279
 
248
280
  function getId() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-rokt-kit",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "mParticle integration kit for Rokt",
5
5
  "main": "dist/Rokt-Kit.common.js",
6
6
  "files": [
@@ -14,7 +14,7 @@
14
14
  "lint": "eslint src/ test/src/",
15
15
  "lint:fix": "eslint src/ test/src/ --fix",
16
16
  "watch": "rollup --config rollup.config.js -w",
17
- "watch:test": "rollup --config rollup.test.config.js -w",
17
+ "watch:tests": "rollup --config rollup.test.config.js -w",
18
18
  "test": "npm run build && npm run build:test && karma start test/karma.config.js",
19
19
  "test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js"
20
20
  },