@letscooee/web-sdk 0.0.4 → 0.0.8

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 (59) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/README.md +6 -4
  3. package/dist/constants.js +11 -2
  4. package/dist/index-preview.js +3 -0
  5. package/dist/init/visibility-listener.js +2 -2
  6. package/dist/models/event/event-response.js +1 -0
  7. package/dist/models/trigger/action/click-action-executor.js +260 -0
  8. package/dist/models/trigger/blocks/background.js +33 -0
  9. package/dist/models/trigger/blocks/border.js +49 -0
  10. package/dist/models/trigger/blocks/click-action.js +9 -0
  11. package/dist/models/trigger/blocks/color.js +48 -0
  12. package/dist/models/trigger/blocks/colour.js +1 -0
  13. package/dist/models/trigger/blocks/flex.js +1 -0
  14. package/dist/models/trigger/blocks/font.js +1 -0
  15. package/dist/models/trigger/blocks/glossy.js +25 -0
  16. package/dist/models/trigger/blocks/gradient.js +1 -0
  17. package/dist/models/trigger/blocks/image.js +1 -0
  18. package/dist/models/trigger/blocks/index.js +5 -0
  19. package/dist/models/trigger/blocks/position.js +1 -0
  20. package/dist/models/trigger/blocks/shadow.js +1 -0
  21. package/dist/models/trigger/blocks/spacing.js +1 -0
  22. package/dist/models/trigger/blocks/transform.js +13 -0
  23. package/dist/models/trigger/elements/base-element.js +50 -0
  24. package/dist/models/trigger/elements/base-text-element.js +1 -0
  25. package/dist/models/trigger/elements/group-element.js +1 -0
  26. package/dist/models/trigger/elements/image-element.js +26 -0
  27. package/dist/models/trigger/elements/index.js +4 -0
  28. package/dist/models/trigger/elements/shape-element.js +24 -0
  29. package/dist/models/trigger/elements/text-element.js +81 -0
  30. package/dist/models/trigger/embedded-trigger.js +26 -0
  31. package/dist/models/trigger/inapp/container.js +104 -0
  32. package/dist/models/trigger/inapp/in-app-trigger.js +32 -0
  33. package/dist/models/trigger/inapp/layer.js +1 -0
  34. package/dist/models/trigger/trigger-data.js +9 -3
  35. package/dist/models/trigger/trigger-helper.js +52 -0
  36. package/dist/renderer/base-text-renderer.js +77 -0
  37. package/dist/renderer/block-processor.js +233 -0
  38. package/dist/renderer/block-renderer.js +44 -0
  39. package/dist/renderer/container-renderer.js +46 -0
  40. package/dist/renderer/group-renderer.js +44 -0
  41. package/dist/renderer/iFrame-renderer.js +82 -0
  42. package/dist/renderer/image-renderer.js +44 -0
  43. package/dist/renderer/in-app-renderer.js +84 -0
  44. package/dist/renderer/index.js +26 -0
  45. package/dist/renderer/renderer.js +97 -0
  46. package/dist/renderer/root-container-renderer.js +54 -0
  47. package/dist/renderer/shape-renderer.js +39 -0
  48. package/dist/renderer/text-renderer.js +48 -0
  49. package/dist/sdk-preview.min.js +2 -0
  50. package/dist/sdk-preview.min.js.LICENSE.txt +8 -0
  51. package/dist/sdk.min.js +1 -1
  52. package/dist/services/http-api.service.js +33 -9
  53. package/dist/services/user-auth.service.js +7 -7
  54. package/dist/session/new-session-executor.js +2 -2
  55. package/dist/session/session-manager.js +1 -0
  56. package/dist/utils/local-storage-helper.js +22 -0
  57. package/dist/utils/log.js +17 -13
  58. package/package.json +10 -7
  59. package/webpack-preview.config.js +10 -0
@@ -0,0 +1,26 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { BaseElement } from './base-element';
17
+ var ImageElement = /** @class */ (function (_super) {
18
+ __extends(ImageElement, _super);
19
+ function ImageElement(data) {
20
+ var _this = _super.call(this, data) || this;
21
+ _this.src = data.src;
22
+ return _this;
23
+ }
24
+ return ImageElement;
25
+ }(BaseElement));
26
+ export { ImageElement };
@@ -0,0 +1,4 @@
1
+ export { BaseElement } from './base-element';
2
+ export { ShapeElement } from './shape-element';
3
+ export { ImageElement } from './image-element';
4
+ export { TextElement } from './text-element';
@@ -0,0 +1,24 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { BaseElement } from './base-element';
17
+ var ShapeElement = /** @class */ (function (_super) {
18
+ __extends(ShapeElement, _super);
19
+ function ShapeElement(data) {
20
+ return _super.call(this, data) || this;
21
+ }
22
+ return ShapeElement;
23
+ }(BaseElement));
24
+ export { ShapeElement };
@@ -0,0 +1,81 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { Color } from '../blocks';
17
+ import { BaseElement } from './base-element';
18
+ var TextElement = /** @class */ (function (_super) {
19
+ __extends(TextElement, _super);
20
+ function TextElement(data) {
21
+ var _this = _super.call(this, data) || this;
22
+ _this.alg = TextAlign.START;
23
+ _this.prs = data.prs;
24
+ _this.alg = data.alg;
25
+ if (data.f)
26
+ _this.f = data.f;
27
+ if (data.c)
28
+ _this.c = new Color(data.c);
29
+ return _this;
30
+ }
31
+ Object.defineProperty(TextElement.prototype, "parts", {
32
+ get: function () {
33
+ return this.prs;
34
+ },
35
+ enumerable: false,
36
+ configurable: true
37
+ });
38
+ Object.defineProperty(TextElement.prototype, "color", {
39
+ get: function () {
40
+ return this.c;
41
+ },
42
+ enumerable: false,
43
+ configurable: true
44
+ });
45
+ Object.defineProperty(TextElement.prototype, "font", {
46
+ get: function () {
47
+ return this.f;
48
+ },
49
+ enumerable: false,
50
+ configurable: true
51
+ });
52
+ return TextElement;
53
+ }(BaseElement));
54
+ export { TextElement };
55
+ var TextPart = /** @class */ (function () {
56
+ function TextPart(data) {
57
+ this.txt = data.text;
58
+ this.b = data.b;
59
+ this.i = data.i;
60
+ this.u = data.u;
61
+ this.st = data.st;
62
+ this.sc = data.sc;
63
+ }
64
+ return TextPart;
65
+ }());
66
+ export { TextPart };
67
+ /* eslint-disable no-unused-vars */
68
+ export var TextAlign;
69
+ (function (TextAlign) {
70
+ TextAlign[TextAlign["START"] = 0] = "START";
71
+ TextAlign[TextAlign["CENTER"] = 1] = "CENTER";
72
+ TextAlign[TextAlign["END"] = 2] = "END";
73
+ TextAlign[TextAlign["JUSTIFY"] = 3] = "JUSTIFY";
74
+ })(TextAlign || (TextAlign = {}));
75
+ export var TextScript;
76
+ (function (TextScript) {
77
+ TextScript[TextScript["NORMAL"] = 0] = "NORMAL";
78
+ TextScript[TextScript["SUPER"] = 1] = "SUPER";
79
+ TextScript[TextScript["SUB"] = 2] = "SUB";
80
+ })(TextScript || (TextScript = {}));
81
+ /* eslint-enable no-unused-vars */
@@ -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 };
@@ -0,0 +1,104 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { BaseElement } from '../elements';
17
+ var Container = /** @class */ (function (_super) {
18
+ __extends(Container, _super);
19
+ function Container(data) {
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;
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
+ right: 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
+ styles.overflow = 'hidden';
88
+ return styles;
89
+ };
90
+ return Container;
91
+ }(BaseElement));
92
+ export { Container };
93
+ export var ContainerOrigin;
94
+ (function (ContainerOrigin) {
95
+ ContainerOrigin[ContainerOrigin["NW"] = 1] = "NW";
96
+ ContainerOrigin[ContainerOrigin["N"] = 2] = "N";
97
+ ContainerOrigin[ContainerOrigin["NE"] = 3] = "NE";
98
+ ContainerOrigin[ContainerOrigin["W"] = 4] = "W";
99
+ ContainerOrigin[ContainerOrigin["C"] = 5] = "C";
100
+ ContainerOrigin[ContainerOrigin["E"] = 6] = "E";
101
+ ContainerOrigin[ContainerOrigin["SW"] = 7] = "SW";
102
+ ContainerOrigin[ContainerOrigin["S"] = 8] = "S";
103
+ ContainerOrigin[ContainerOrigin["SE"] = 9] = "SE";
104
+ })(ContainerOrigin || (ContainerOrigin = {}));
@@ -0,0 +1,32 @@
1
+ import { Container } from './container';
2
+ import { ImageElement, ShapeElement, TextElement } from '../elements';
3
+ import { ElementType } from '../elements/base-element';
4
+ /**
5
+ * Stores data present in ian (In App) block in {@link TriggerData}
6
+ *
7
+ * @author Abhishek Taparia
8
+ * @version 0.0.5
9
+ */
10
+ var InAppTrigger = /** @class */ (function () {
11
+ function InAppTrigger(data) {
12
+ var _this = this;
13
+ this.elems = [];
14
+ this.cont = new Container(data.cont);
15
+ data.elems.forEach(function (rawElement) {
16
+ if (rawElement.t === ElementType.IMAGE) {
17
+ _this.elems.push(new ImageElement(rawElement));
18
+ }
19
+ else if (rawElement.t === ElementType.TEXT) {
20
+ _this.elems.push(new TextElement(rawElement));
21
+ }
22
+ else if (rawElement.t === ElementType.BUTTON) {
23
+ _this.elems.push(new TextElement(rawElement));
24
+ }
25
+ else if (rawElement.t === ElementType.SHAPE) {
26
+ _this.elems.push(new ShapeElement(rawElement));
27
+ }
28
+ });
29
+ }
30
+ return InAppTrigger;
31
+ }());
32
+ export { InAppTrigger };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
+ import { InAppTrigger } from './inapp/in-app-trigger';
1
2
  /**
2
3
  * This store the payload sent by server to render trigger.
3
4
  */
@@ -5,12 +6,17 @@ var TriggerData = /** @class */ (function () {
5
6
  /**
6
7
  * Public constructor
7
8
  *
8
- * @param {any} data payload
9
+ * @param {Props} data payload
9
10
  */
10
11
  function TriggerData(data) {
11
- this.duration = 0;
12
+ this.expireAt = new Date().getTime();
12
13
  this.id = data.id;
13
- this.duration = data.duration;
14
+ this.expireAt = data.expireAt;
15
+ this.version = data.version;
16
+ this.engagementID = data.engagementID;
17
+ this.internal = data.internal;
18
+ this.pn = data.pn;
19
+ this.ian = new InAppTrigger(data.ian);
14
20
  }
15
21
  return TriggerData;
16
22
  }());
@@ -0,0 +1,52 @@
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
+ if (triggerData.id === 'test') {
19
+ return;
20
+ }
21
+ var activeTriggers = LocalStorageHelper.getObject(Constants.STORAGE_ACTIVE_TRIGGERS);
22
+ if (!activeTriggers) {
23
+ activeTriggers = [];
24
+ }
25
+ var embeddedTrigger = new EmbeddedTrigger(triggerData);
26
+ if (!embeddedTrigger.isExpired) {
27
+ activeTriggers.push(embeddedTrigger);
28
+ }
29
+ LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGER, embeddedTrigger);
30
+ LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGERS, activeTriggers);
31
+ };
32
+ /**
33
+ * Get the list of non-expired active triggers from local storage for "late engagement tracking".
34
+ *
35
+ * @return EmbeddedTrigger[] list of active triggers
36
+ */
37
+ TriggerHelper.getActiveTriggers = function () {
38
+ var activeTriggers = LocalStorageHelper.getObject(Constants.STORAGE_ACTIVE_TRIGGERS);
39
+ if (!activeTriggers) {
40
+ return [];
41
+ }
42
+ activeTriggers.forEach(function (trigger, index, array) {
43
+ if (new EmbeddedTrigger(trigger).isExpired) {
44
+ array.splice(index, 1);
45
+ }
46
+ });
47
+ LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGERS, activeTriggers);
48
+ return activeTriggers;
49
+ };
50
+ return TriggerHelper;
51
+ }());
52
+ export { TriggerHelper };
@@ -0,0 +1,77 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { BlockProcessor } from './block-processor';
17
+ import { TextAlign } from '../models/trigger/elements/text-element';
18
+ /**
19
+ * Base class for rendering any text extending block from in-app.
20
+ *
21
+ * @author Abhishek Taparia
22
+ * @version 0.0.5
23
+ */
24
+ var BaseTextRenderer = /** @class */ (function (_super) {
25
+ __extends(BaseTextRenderer, _super);
26
+ function BaseTextRenderer(parentElement, inappElement) {
27
+ return _super.call(this, parentElement, inappElement) || this;
28
+ }
29
+ /**
30
+ * Process all the common block in in-app.
31
+ */
32
+ BaseTextRenderer.prototype.processCommonBlocks = function () {
33
+ _super.prototype.processCommonBlocks.call(this);
34
+ this.processFontBlock();
35
+ this.processColourBlock(this.inappElement.color);
36
+ this.processAlignment();
37
+ };
38
+ /**
39
+ * Process font block of the element
40
+ */
41
+ BaseTextRenderer.prototype.processFontBlock = function () {
42
+ var font = this.inappElement.font;
43
+ if (!font) {
44
+ return;
45
+ }
46
+ this.renderer.setStyle(this.inappHTMLEl, 'font-size', this.getSizePx(font.s));
47
+ this.renderer.setStyle(this.inappHTMLEl, 'font-family', font.ff);
48
+ this.renderer.setStyle(this.inappHTMLEl, 'line-height', font.lh);
49
+ };
50
+ BaseTextRenderer.prototype.processPart = function (partHTMLEl, part) {
51
+ var _a;
52
+ var decoration = [];
53
+ if (part.u)
54
+ decoration.push('underline');
55
+ if (part.st)
56
+ decoration.push('line-through');
57
+ if (!decoration.length)
58
+ decoration.push('normal');
59
+ this.renderer.setStyle(partHTMLEl, 'font-weight', part.b ? 'bold' : 'normal');
60
+ this.renderer.setStyle(partHTMLEl, 'font-style', part.i ? 'italic' : 'normal');
61
+ this.renderer.setStyle(partHTMLEl, 'text-decoration', decoration.join(' '));
62
+ this.renderer.setStyle(partHTMLEl, 'color', (_a = part.c) !== null && _a !== void 0 ? _a : 'inherit');
63
+ };
64
+ /**
65
+ * Process text alignment block of the element
66
+ * @private
67
+ */
68
+ BaseTextRenderer.prototype.processAlignment = function () {
69
+ var _a;
70
+ var value = (_a = TextAlign[this.inappElement.alg]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
71
+ if (!value)
72
+ value = 'start';
73
+ this.renderer.setStyle(this.inappHTMLEl, 'text-align', value);
74
+ };
75
+ return BaseTextRenderer;
76
+ }(BlockProcessor));
77
+ export { BaseTextRenderer };