@letscooee/web-sdk 0.0.6 → 0.0.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ # 0.0.7
4
+
5
+ More feature support in the sdk.
6
+
3
7
  # 0.0.6
4
8
 
5
9
  1. Build: Upgrade TypeScript to 4.4.
package/dist/constants.js CHANGED
@@ -25,7 +25,8 @@ var Constants = /** @class */ (function () {
25
25
  Constants.STORAGE_FIRST_TIME_LAUNCH = 'ifl';
26
26
  Constants.STORAGE_LAST_ACTIVE = 'la';
27
27
  Constants.STORAGE_TRIGGER_START_TIME = 'tst';
28
- Constants.STORAGE_ACTIVE_TRIGGER_ID = 'atid';
28
+ Constants.STORAGE_ACTIVE_TRIGGER = 'at';
29
+ Constants.STORAGE_ACTIVE_TRIGGERS = 'ats';
29
30
  // endregion
30
31
  Constants.IDLE_TIME_IN_SECONDS = 30 * 60;
31
32
  Constants.IN_APP_CONTAINER_NAME = 'cooee-wrapper';
@@ -89,7 +89,7 @@ var VisibilityListener = /** @class */ (function () {
89
89
  }
90
90
  props = {};
91
91
  props[VisibilityListener.INACTIVE_DURATION] = duration;
92
- event = new Event('CE Web Active', props);
92
+ event = new Event('CE App Foreground', props);
93
93
  _a = event;
94
94
  return [4 /*yield*/, new DevicePropertiesCollector().get()];
95
95
  case 1:
@@ -113,7 +113,7 @@ var VisibilityListener = /** @class */ (function () {
113
113
  duration = this.runtimeData.getTimeForActiveInSeconds();
114
114
  props = {};
115
115
  props[VisibilityListener.ACTIVE_DURATION] = duration;
116
- this.apiService.sendEvent(new Event('CE Web Inactive', props));
116
+ this.apiService.sendEvent(new Event('CE App Background', props));
117
117
  return [2 /*return*/];
118
118
  });
119
119
  });
@@ -124,12 +124,13 @@ var ClickActionExecutor = /** @class */ (function () {
124
124
  * Performs close action
125
125
  */
126
126
  ClickActionExecutor.prototype.closeAction = function () {
127
+ var _a;
127
128
  if (!this.action.close) {
128
129
  return;
129
130
  }
130
131
  new RootContainerRenderer().removeInApp();
131
132
  var startTime = LocalStorageHelper.getNumber(Constants.STORAGE_TRIGGER_START_TIME, new Date().getTime());
132
- var triggerID = LocalStorageHelper.getString(Constants.STORAGE_ACTIVE_TRIGGER_ID, '');
133
+ var triggerID = (_a = LocalStorageHelper.getObject(Constants.STORAGE_ACTIVE_TRIGGER)) === null || _a === void 0 ? void 0 : _a.triggerID;
133
134
  var diffInSeconds = (new Date().getTime() - startTime) / 1000;
134
135
  var eventProps = {
135
136
  'triggerID': triggerID,
@@ -138,7 +139,6 @@ var ClickActionExecutor = /** @class */ (function () {
138
139
  };
139
140
  this.apiService.sendEvent(new Event('CE Trigger Closed', eventProps));
140
141
  LocalStorageHelper.remove(Constants.STORAGE_TRIGGER_START_TIME);
141
- LocalStorageHelper.remove(Constants.STORAGE_ACTIVE_TRIGGER_ID);
142
142
  };
143
143
  /**
144
144
  * Performs share action i.e. share some url on CTA.
@@ -152,7 +152,7 @@ var ClickActionExecutor = /** @class */ (function () {
152
152
  // TODO test in mobile browsers
153
153
  var share = navigator.share;
154
154
  if (!share) {
155
- Log.w('Navigator.share is not compatible with this browser');
155
+ Log.warning('Navigator.share is not compatible with this browser');
156
156
  return;
157
157
  }
158
158
  navigator.share({ 'text': this.action.share.text, 'title': 'Share' })
@@ -182,7 +182,7 @@ var ClickActionExecutor = /** @class */ (function () {
182
182
  ClickActionExecutor.prototype.promptPushNotificationPermission = function () {
183
183
  var _this = this;
184
184
  if (!('Notification' in window)) {
185
- Log.w('This browser does not support desktop notification');
185
+ Log.warning('This browser does not support desktop notification');
186
186
  return;
187
187
  }
188
188
  // TODO Need device endpoints to update this property
@@ -0,0 +1,26 @@
1
+ /**
2
+ * This class store data related to triggers which are active/activated by clicking on the trigger notification or by
3
+ * looking an in-app trigger(in future). This would be commonly sent with events as <code>activeTrigger</code>.
4
+ *
5
+ * @author Abhishek Taparia
6
+ * @since 1.1.0
7
+ */
8
+ var EmbeddedTrigger = /** @class */ (function () {
9
+ function EmbeddedTrigger(data) {
10
+ this.triggerID = data.id;
11
+ this.engagementID = data.engagementID;
12
+ this.expireAt = data.expireAt;
13
+ if (this.isExpired) {
14
+ this.expired = this.isExpired;
15
+ }
16
+ }
17
+ Object.defineProperty(EmbeddedTrigger.prototype, "isExpired", {
18
+ get: function () {
19
+ return this.expireAt < new Date().getTime();
20
+ },
21
+ enumerable: false,
22
+ configurable: true
23
+ });
24
+ return EmbeddedTrigger;
25
+ }());
26
+ export { EmbeddedTrigger };
@@ -17,8 +17,87 @@ import { BaseElement } from '../elements';
17
17
  var Container = /** @class */ (function (_super) {
18
18
  __extends(Container, _super);
19
19
  function Container(data) {
20
- return _super.call(this, data) || this;
20
+ var _a;
21
+ var _this = _super.call(this, data) || this;
22
+ _this.o = (_a = data.o) !== null && _a !== void 0 ? _a : ContainerOrigin.C;
23
+ return _this;
21
24
  }
25
+ Container.prototype.getStyles = function () {
26
+ var styles;
27
+ if (this.o === ContainerOrigin.NW) {
28
+ styles = {
29
+ top: 0,
30
+ left: 0,
31
+ };
32
+ }
33
+ else if (this.o === ContainerOrigin.N) {
34
+ styles = {
35
+ top: 0,
36
+ left: '50%',
37
+ transform: 'translateX(-50%)',
38
+ };
39
+ }
40
+ else if (this.o === ContainerOrigin.NE) {
41
+ styles = {
42
+ top: 0,
43
+ right: 0,
44
+ };
45
+ }
46
+ else if (this.o === ContainerOrigin.E) {
47
+ styles = {
48
+ top: '50%',
49
+ left: 0,
50
+ transform: 'translateY(-50%)',
51
+ };
52
+ }
53
+ else if (this.o === ContainerOrigin.SE) {
54
+ styles = {
55
+ bottom: 0,
56
+ right: 0,
57
+ };
58
+ }
59
+ else if (this.o === ContainerOrigin.S) {
60
+ styles = {
61
+ bottom: 0,
62
+ left: '50%',
63
+ transform: 'translateX(-50%)',
64
+ };
65
+ }
66
+ else if (this.o === ContainerOrigin.SW) {
67
+ styles = {
68
+ bottom: 0,
69
+ left: 0,
70
+ };
71
+ }
72
+ else if (this.o === ContainerOrigin.W) {
73
+ styles = {
74
+ top: '50%',
75
+ left: 0,
76
+ transform: 'translateY(-50%)',
77
+ };
78
+ }
79
+ else {
80
+ styles = {
81
+ top: '50%',
82
+ left: '50%',
83
+ transform: 'translateX(-50%) translateY(-50%)',
84
+ };
85
+ }
86
+ styles.position = 'absolute';
87
+ return styles;
88
+ };
22
89
  return Container;
23
90
  }(BaseElement));
24
91
  export { Container };
92
+ export var ContainerOrigin;
93
+ (function (ContainerOrigin) {
94
+ ContainerOrigin[ContainerOrigin["NW"] = 1] = "NW";
95
+ ContainerOrigin[ContainerOrigin["N"] = 2] = "N";
96
+ ContainerOrigin[ContainerOrigin["NE"] = 3] = "NE";
97
+ ContainerOrigin[ContainerOrigin["W"] = 4] = "W";
98
+ ContainerOrigin[ContainerOrigin["C"] = 5] = "C";
99
+ ContainerOrigin[ContainerOrigin["E"] = 6] = "E";
100
+ ContainerOrigin[ContainerOrigin["SW"] = 7] = "SW";
101
+ ContainerOrigin[ContainerOrigin["S"] = 8] = "S";
102
+ ContainerOrigin[ContainerOrigin["SE"] = 9] = "SE";
103
+ })(ContainerOrigin || (ContainerOrigin = {}));
@@ -9,9 +9,9 @@ var TriggerData = /** @class */ (function () {
9
9
  * @param {Props} data payload
10
10
  */
11
11
  function TriggerData(data) {
12
- this.duration = 0;
12
+ this.expireAt = new Date().getTime();
13
13
  this.id = data.id;
14
- this.duration = data.duration;
14
+ this.expireAt = data.expireAt;
15
15
  this.version = data.version;
16
16
  this.engagementID = data.engagementID;
17
17
  this.internal = data.internal;
@@ -0,0 +1,49 @@
1
+ import { LocalStorageHelper } from '../../utils/local-storage-helper';
2
+ import { Constants } from '../../constants';
3
+ import { EmbeddedTrigger } from './embedded-trigger';
4
+ /**
5
+ * A small helper class for any kind of engagement trigger like caching or retrieving from local storage.
6
+ *
7
+ * @author Abhishek Taparia
8
+ * @since 0.0.7
9
+ */
10
+ var TriggerHelper = /** @class */ (function () {
11
+ function TriggerHelper() {
12
+ }
13
+ /**
14
+ * Store the current active trigger details in local storage for "late engagement tracking".
15
+ * @param triggerData trigger data
16
+ */
17
+ TriggerHelper.storeActiveTrigger = function (triggerData) {
18
+ var activeTriggers = LocalStorageHelper.getObject(Constants.STORAGE_ACTIVE_TRIGGERS);
19
+ if (!activeTriggers) {
20
+ activeTriggers = [];
21
+ }
22
+ var embeddedTrigger = new EmbeddedTrigger(triggerData);
23
+ if (!embeddedTrigger.isExpired) {
24
+ activeTriggers.push(embeddedTrigger);
25
+ }
26
+ LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGER, embeddedTrigger);
27
+ LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGERS, activeTriggers);
28
+ };
29
+ /**
30
+ * Get the list of non-expired active triggers from local storage for "late engagement tracking".
31
+ *
32
+ * @return EmbeddedTrigger[] list of active triggers
33
+ */
34
+ TriggerHelper.getActiveTriggers = function () {
35
+ var activeTriggers = LocalStorageHelper.getObject(Constants.STORAGE_ACTIVE_TRIGGERS);
36
+ if (!activeTriggers) {
37
+ return [];
38
+ }
39
+ activeTriggers.forEach(function (trigger, index, array) {
40
+ if (new EmbeddedTrigger(trigger).isExpired) {
41
+ array.splice(index, 1);
42
+ }
43
+ });
44
+ LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGERS, activeTriggers);
45
+ return activeTriggers;
46
+ };
47
+ return TriggerHelper;
48
+ }());
49
+ export { TriggerHelper };
@@ -13,7 +13,7 @@ var __extends = (this && this.__extends) || (function () {
13
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
14
  };
15
15
  })();
16
- import { ShapeRenderer } from './shape-renderer';
16
+ import { BlockProcessor } from './block-processor';
17
17
  /**
18
18
  * Renders container element.
19
19
  *
@@ -24,6 +24,8 @@ var ContainerRenderer = /** @class */ (function (_super) {
24
24
  __extends(ContainerRenderer, _super);
25
25
  function ContainerRenderer(parentElement, inappElement) {
26
26
  var _this = _super.call(this, parentElement, inappElement) || this;
27
+ _this.inappHTMLEl = _this.renderer.createElement('div');
28
+ _this.insertElement();
27
29
  // Need to figure out the best way of doing this
28
30
  _this.inappElement.w = 1080;
29
31
  _this.inappElement.h = 1920;
@@ -34,12 +36,11 @@ var ContainerRenderer = /** @class */ (function (_super) {
34
36
  * @return The instance of this renderer.
35
37
  */
36
38
  ContainerRenderer.prototype.render = function () {
37
- _super.prototype.render.call(this);
39
+ this.processCommonBlocks();
38
40
  this.renderer.setStyle(this.inappHTMLEl, 'position', 'relative');
39
- /* this.renderer.setStyle(this.inappHTMLEl, 'width', '100%');
40
- this.renderer.setStyle(this.inappHTMLEl, 'height', '100%'); */
41
+ Object.assign(this.inappHTMLEl.style, this.inappElement.getStyles());
41
42
  return this;
42
43
  };
43
44
  return ContainerRenderer;
44
- }(ShapeRenderer));
45
+ }(BlockProcessor));
45
46
  export { ContainerRenderer };
@@ -5,6 +5,9 @@ import { LocalStorageHelper } from '../utils/local-storage-helper';
5
5
  import { Constants } from '../constants';
6
6
  import { ImageRenderer, RootContainerRenderer, ShapeRenderer, TextRenderer } from './';
7
7
  import { ContainerRenderer } from './container-renderer';
8
+ import { TriggerHelper } from '../models/trigger/trigger-helper';
9
+ import { SafeHttpService } from '../services/safe-http-service';
10
+ import { Event } from '../models/event/event';
8
11
  /**
9
12
  * Renders In App trigger
10
13
  *
@@ -27,11 +30,13 @@ var InAppRenderer = /** @class */ (function () {
27
30
  this.ian = triggerData.ian;
28
31
  try {
29
32
  this.renderContainer();
33
+ var event_1 = new Event('CE Trigger Displayed', { 'triggerID': triggerData.id });
34
+ SafeHttpService.getInstance().sendEvent(event_1);
30
35
  LocalStorageHelper.setNumber(Constants.STORAGE_TRIGGER_START_TIME, new Date().getTime());
31
- LocalStorageHelper.setString(Constants.STORAGE_ACTIVE_TRIGGER_ID, triggerData.id);
36
+ TriggerHelper.storeActiveTrigger(triggerData);
32
37
  }
33
38
  catch (e) {
34
- Log.e(e);
39
+ Log.error(e);
35
40
  }
36
41
  };
37
42
  /**
@@ -50,7 +55,7 @@ var InAppRenderer = /** @class */ (function () {
50
55
  new ShapeRenderer(parentEl, inappElement).render();
51
56
  }
52
57
  else {
53
- Log.e('Unsupported element type- ' + inappElement.type);
58
+ Log.error('Unsupported element type- ' + inappElement.type);
54
59
  }
55
60
  };
56
61
  /**
@@ -11,12 +11,15 @@ export { IFrameRenderer } from './iFrame-renderer';
11
11
  export function getScalingFactor() {
12
12
  var screenWidth = document.documentElement.clientWidth;
13
13
  var screenHeight = document.documentElement.clientHeight;
14
+ var scalingFactor;
14
15
  if (screenWidth < screenHeight) {
15
16
  var shortEdge = Math.min(Constants.CANVAS_WIDTH, Constants.CANVAS_HEIGHT);
16
- return screenWidth / shortEdge;
17
+ scalingFactor = screenWidth / shortEdge;
17
18
  }
18
19
  else {
19
20
  var longEdge = Math.max(Constants.CANVAS_WIDTH, Constants.CANVAS_HEIGHT);
20
- return screenHeight / longEdge;
21
+ scalingFactor = screenHeight / longEdge;
21
22
  }
23
+ // The in-app should not scale beyond 100%
24
+ return Math.min(scalingFactor, 1);
22
25
  }
@@ -25,9 +25,6 @@ var RootContainerRenderer = /** @class */ (function () {
25
25
  this.renderer.setStyle(rootDiv, 'left', '0');
26
26
  this.renderer.setStyle(rootDiv, 'width', '100%');
27
27
  this.renderer.setStyle(rootDiv, 'height', '100%');
28
- this.renderer.setStyle(rootDiv, 'display', 'flex');
29
- this.renderer.setStyle(rootDiv, 'justify-content', 'center');
30
- this.renderer.setStyle(rootDiv, 'align-items', 'center');
31
28
  this.renderer.appendChild(document.body, rootDiv);
32
29
  return rootDiv;
33
30
  };