@kameleoon/javascript-sdk 1.1.0 → 1.2.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.
@@ -1,33 +1,48 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.EventSourceConstructor = void 0;
7
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
9
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
10
  class EventSourceConstructor {
5
- initialize(url) {
6
- return new ExternalEventSource(url);
7
- }
11
+ initialize(url) {
12
+ return new ExternalEventSource(url);
13
+ }
8
14
  }
9
- exports.EventSourceConstructor = EventSourceConstructor;
15
+
10
16
  // --- Note ---
11
17
  // - `EventSource` has no dedicated tests because same browser instance
12
18
  // is tested thoroughly inside core and would just duplicate tests
13
19
  // - Moreover we would have to import some unexposed details like constructed url
14
20
  // or the `eventType` from the core
21
+ exports.EventSourceConstructor = EventSourceConstructor;
15
22
  class ExternalEventSource {
16
- constructor(url) {
17
- const eventSource = new EventSource(url);
18
- this.eventSource = eventSource;
19
- }
20
- open({ siteCode, eventType, onEvent, }) {
21
- this.eventSource.addEventListener(eventType, (message) => {
22
- const event = JSON.parse(message.data);
23
- const { siteCode: eventSiteCode, ts } = event;
24
- if (siteCode === eventSiteCode) {
25
- onEvent(ts);
26
- }
27
- });
28
- }
29
- close() {
30
- this.eventSource.close();
31
- }
23
+ constructor(url) {
24
+ _defineProperty(this, "eventSource", void 0);
25
+ const eventSource = new EventSource(url);
26
+ this.eventSource = eventSource;
27
+ }
28
+ open({
29
+ siteCode,
30
+ eventType,
31
+ onEvent
32
+ }) {
33
+ this.eventSource.addEventListener(eventType, message => {
34
+ const event = JSON.parse(message.data);
35
+ const {
36
+ siteCode: eventSiteCode,
37
+ ts
38
+ } = event;
39
+ if (siteCode === eventSiteCode) {
40
+ onEvent(ts);
41
+ }
42
+ });
43
+ }
44
+ close() {
45
+ this.eventSource.close();
46
+ }
32
47
  }
33
48
  //# sourceMappingURL=eventSource.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventSource.js","sourceRoot":"","sources":["../src/eventSource.ts"],"names":[],"mappings":";;;AAOA,MAAa,sBAAsB;IAC1B,UAAU,CAAC,GAAW;QAC3B,OAAO,IAAI,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;CACF;AAJD,wDAIC;AAED,eAAe;AACf,uEAAuE;AACvE,kEAAkE;AAClE,iFAAiF;AACjF,mCAAmC;AACnC,MAAM,mBAAmB;IAGvB,YAAY,GAAW;QACrB,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC;QAEzC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEM,IAAI,CAAC,EACV,QAAQ,EACR,SAAS,EACT,OAAO,GACuB;QAC9B,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;YACvD,MAAM,KAAK,GAAsB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC1D,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;YAE9C,IAAI,QAAQ,KAAK,aAAa,EAAE;gBAC9B,OAAO,CAAC,EAAE,CAAC,CAAC;aACb;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF"}
1
+ {"version":3,"file":"eventSource.js","names":["EventSourceConstructor","initialize","url","ExternalEventSource","exports","constructor","_defineProperty","eventSource","EventSource","open","siteCode","eventType","onEvent","addEventListener","message","event","JSON","parse","data","eventSiteCode","ts","close"],"sources":["../src/eventSource.ts"],"sourcesContent":["import {\n RealTimeEventType,\n IExternalEventSource,\n EventSourceOpenParametersType,\n IExternalEventSourceConstructor,\n} from '@kameleoon/javascript-sdk-core';\n\nexport class EventSourceConstructor implements IExternalEventSourceConstructor {\n public initialize(url: string): IExternalEventSource {\n return new ExternalEventSource(url);\n }\n}\n\n// --- Note ---\n// - `EventSource` has no dedicated tests because same browser instance\n// is tested thoroughly inside core and would just duplicate tests\n// - Moreover we would have to import some unexposed details like constructed url\n// or the `eventType` from the core\nclass ExternalEventSource implements IExternalEventSource {\n private eventSource: EventSource;\n\n constructor(url: string) {\n const eventSource = new EventSource(url);\n\n this.eventSource = eventSource;\n }\n\n public open({\n siteCode,\n eventType,\n onEvent,\n }: EventSourceOpenParametersType): void {\n this.eventSource.addEventListener(eventType, (message) => {\n const event: RealTimeEventType = JSON.parse(message.data);\n const { siteCode: eventSiteCode, ts } = event;\n\n if (siteCode === eventSiteCode) {\n onEvent(ts);\n }\n });\n }\n\n public close() {\n this.eventSource.close();\n }\n}\n"],"mappings":";;;;;;;;;AAOO,MAAMA,sBAAsB,CAA4C;EACtEC,UAAUA,CAACC,GAAW,EAAwB;IACnD,OAAO,IAAIC,mBAAmB,CAACD,GAAG,CAAC;EACrC;AACF;;AAEA;AACA;AACA;AACA;AACA;AAAAE,OAAA,CAAAJ,sBAAA,GAAAA,sBAAA;AACA,MAAMG,mBAAmB,CAAiC;EAGxDE,WAAWA,CAACH,GAAW,EAAE;IAAAI,eAAA;IACvB,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAACN,GAAG,CAAC;IAExC,IAAI,CAACK,WAAW,GAAGA,WAAW;EAChC;EAEOE,IAAIA,CAAC;IACVC,QAAQ;IACRC,SAAS;IACTC;EAC6B,CAAC,EAAQ;IACtC,IAAI,CAACL,WAAW,CAACM,gBAAgB,CAACF,SAAS,EAAGG,OAAO,IAAK;MACxD,MAAMC,KAAwB,GAAGC,IAAI,CAACC,KAAK,CAACH,OAAO,CAACI,IAAI,CAAC;MACzD,MAAM;QAAER,QAAQ,EAAES,aAAa;QAAEC;MAAG,CAAC,GAAGL,KAAK;MAE7C,IAAIL,QAAQ,KAAKS,aAAa,EAAE;QAC9BP,OAAO,CAACQ,EAAE,CAAC;MACb;IACF,CAAC,CAAC;EACJ;EAEOC,KAAKA,CAAA,EAAG;IACb,IAAI,CAACd,WAAW,CAACc,KAAK,EAAE;EAC1B;AACF"}
package/dist/index.js CHANGED
@@ -1,23 +1,36 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ KameleoonClient: true,
8
+ KameleoonUtils: true
15
9
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.KameleoonUtils = exports.KameleoonClient = void 0;
18
- __exportStar(require("@kameleoon/javascript-sdk-core"), exports);
19
- var kameleoonClient_1 = require("./kameleoonClient");
20
- Object.defineProperty(exports, "KameleoonClient", { enumerable: true, get: function () { return kameleoonClient_1.KameleoonClient; } });
21
- var kameleoonUtils_1 = require("./kameleoonUtils");
22
- Object.defineProperty(exports, "KameleoonUtils", { enumerable: true, get: function () { return kameleoonUtils_1.KameleoonUtils; } });
10
+ Object.defineProperty(exports, "KameleoonClient", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _kameleoonClient.KameleoonClient;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "KameleoonUtils", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _kameleoonUtils.KameleoonUtils;
20
+ }
21
+ });
22
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
23
+ Object.keys(_javascriptSdkCore).forEach(function (key) {
24
+ if (key === "default" || key === "__esModule") return;
25
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
+ if (key in exports && exports[key] === _javascriptSdkCore[key]) return;
27
+ Object.defineProperty(exports, key, {
28
+ enumerable: true,
29
+ get: function () {
30
+ return _javascriptSdkCore[key];
31
+ }
32
+ });
33
+ });
34
+ var _kameleoonClient = require("./kameleoonClient");
35
+ var _kameleoonUtils = require("./kameleoonUtils");
23
36
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA"}
1
+ {"version":3,"file":"index.js","names":["_javascriptSdkCore","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_kameleoonClient","_kameleoonUtils"],"sources":["../src/index.ts"],"sourcesContent":["export * from '@kameleoon/javascript-sdk-core';\nexport { KameleoonClient } from './kameleoonClient';\nexport { KameleoonUtils } from './kameleoonUtils';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,kBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,kBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,kBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,gBAAA,GAAAb,OAAA;AACA,IAAAc,eAAA,GAAAd,OAAA"}
@@ -1,26 +1,36 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.KameleoonClient = void 0;
4
- const javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
5
- const eventSource_1 = require("./eventSource");
6
- const storage_1 = require("./storage");
7
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
8
+ var _eventSource = require("./eventSource");
9
+ var _storage = require("./storage");
10
+ var _requester = require("./requester");
7
11
  /**
8
12
  * @class
9
13
  * KameleoonClient - a class for creating kameleoon client instance
10
14
  * */
11
- class KameleoonClient extends javascript_sdk_core_1.KameleoonCore {
12
- constructor(siteCode, configuration) {
13
- const storage = new storage_1.StorageConstructor();
14
- const eventSource = new eventSource_1.EventSourceConstructor();
15
- super({
16
- siteCode,
17
- configuration,
18
- internalConfiguration: {
19
- externalStorage: storage,
20
- externalEventSource: eventSource,
21
- },
22
- });
23
- }
15
+ class KameleoonClient extends _javascriptSdkCore.KameleoonCore {
16
+ constructor(siteCode, configuration) {
17
+ const storage = new _storage.StorageConstructor();
18
+ const eventSource = new _eventSource.EventSourceConstructor();
19
+ const requestDispatcher = new _requester.RequestDispatcher();
20
+ super({
21
+ siteCode,
22
+ configuration,
23
+ internalConfiguration: {
24
+ externalStorage: storage,
25
+ externalEventSource: eventSource,
26
+ externalRequestDispatcher: requestDispatcher,
27
+ externalPackageInfo: {
28
+ type: _javascriptSdkCore.SDKType.JavaScript,
29
+ version: "1.2.0"
30
+ }
31
+ }
32
+ });
33
+ }
24
34
  }
25
35
  exports.KameleoonClient = KameleoonClient;
26
36
  //# sourceMappingURL=kameleoonClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kameleoonClient.js","sourceRoot":"","sources":["../src/kameleoonClient.ts"],"names":[],"mappings":";;;AAAA,wEAGwC;AACxC,+CAAuD;AACvD,uCAA+C;AAE/C;;;KAGK;AACL,MAAa,eAAgB,SAAQ,mCAAa;IAChD,YAAY,QAAgB,EAAE,aAA6C;QACzE,MAAM,OAAO,GAAG,IAAI,4BAAkB,EAAE,CAAC;QACzC,MAAM,WAAW,GAAG,IAAI,oCAAsB,EAAE,CAAC;QAEjD,KAAK,CAAC;YACJ,QAAQ;YACR,aAAa;YACb,qBAAqB,EAAE;gBACrB,eAAe,EAAE,OAAO;gBACxB,mBAAmB,EAAE,WAAW;aACjC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAdD,0CAcC"}
1
+ {"version":3,"file":"kameleoonClient.js","names":["_javascriptSdkCore","require","_eventSource","_storage","_requester","KameleoonClient","KameleoonCore","constructor","siteCode","configuration","storage","StorageConstructor","eventSource","EventSourceConstructor","requestDispatcher","RequestDispatcher","internalConfiguration","externalStorage","externalEventSource","externalRequestDispatcher","externalPackageInfo","type","SDKType","JavaScript","version","exports"],"sources":["../src/kameleoonClient.ts"],"sourcesContent":["import {\n KameleoonCore,\n SDKConfigurationType,\n SDKType,\n} from '@kameleoon/javascript-sdk-core';\nimport { EventSourceConstructor } from './eventSource';\nimport { StorageConstructor } from './storage';\nimport { RequestDispatcher } from './requester';\n\n/**\n * @class\n * KameleoonClient - a class for creating kameleoon client instance\n * */\nexport class KameleoonClient extends KameleoonCore {\n constructor(siteCode: string, configuration?: Partial<SDKConfigurationType>) {\n const storage = new StorageConstructor();\n const eventSource = new EventSourceConstructor();\n const requestDispatcher = new RequestDispatcher();\n\n super({\n siteCode,\n configuration,\n internalConfiguration: {\n externalStorage: storage,\n externalEventSource: eventSource,\n externalRequestDispatcher: requestDispatcher,\n externalPackageInfo: {\n type: SDKType.JavaScript,\n version: process.env.npm_package_version as string,\n },\n },\n });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMI,eAAe,SAASC,gCAAa,CAAC;EACjDC,WAAWA,CAACC,QAAgB,EAAEC,aAA6C,EAAE;IAC3E,MAAMC,OAAO,GAAG,IAAIC,2BAAkB,EAAE;IACxC,MAAMC,WAAW,GAAG,IAAIC,mCAAsB,EAAE;IAChD,MAAMC,iBAAiB,GAAG,IAAIC,4BAAiB,EAAE;IAEjD,KAAK,CAAC;MACJP,QAAQ;MACRC,aAAa;MACbO,qBAAqB,EAAE;QACrBC,eAAe,EAAEP,OAAO;QACxBQ,mBAAmB,EAAEN,WAAW;QAChCO,yBAAyB,EAAEL,iBAAiB;QAC5CM,mBAAmB,EAAE;UACnBC,IAAI,EAAEC,0BAAO,CAACC,UAAU;UACxBC,OAAO;QACT;MACF;IACF,CAAC,CAAC;EACJ;AACF;AAACC,OAAA,CAAApB,eAAA,GAAAA,eAAA"}
@@ -1,48 +1,59 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.KameleoonUtils = void 0;
4
- const javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
7
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
5
8
  // --- Note ---
6
9
  // Extra class is created:
7
10
  // - To enforce abstract `getVisitorCode` method
8
11
  // - To use extended methods while `KameleoonUtils` itself only operates on static methods
9
12
  // - To keep similar parameters object on inner implementation and disperse it for proprietary implementations
10
- class KameleoonUtilsConstructor extends javascript_sdk_core_1.KameleoonCoreUtils {
11
- getVisitorCode({ domain, defaultVisitorCode, }) {
12
- const cookie = document.cookie;
13
- const visitorCodeResult = this.getCookieVisitorCode(cookie);
14
- if (visitorCodeResult.ok && visitorCodeResult.data) {
15
- return visitorCodeResult.data;
16
- }
17
- const visitorCode = defaultVisitorCode || this.generateRandomString(javascript_sdk_core_1.VISITOR_CODE_LENGTH);
18
- const resultCookie = this.getResultCookie({ domain, visitorCode });
19
- // --- Note ---
20
- // - Browser automatically adds new cookie in the end (without overwrite)
21
- // - Only one key-value pair can be added at a time
22
- resultCookie.split(javascript_sdk_core_1.Cookie.PairsDelimiter).forEach((item) => {
23
- document.cookie = item;
24
- });
25
- return visitorCode;
13
+ class KameleoonUtilsConstructor extends _javascriptSdkCore.KameleoonCoreUtils {
14
+ getVisitorCode({
15
+ domain,
16
+ defaultVisitorCode
17
+ }) {
18
+ const cookie = document.cookie;
19
+ const visitorCodeResult = this.getCookieVisitorCode(cookie);
20
+ if (visitorCodeResult.ok && visitorCodeResult.data) {
21
+ return visitorCodeResult.data;
26
22
  }
23
+ const visitorCode = defaultVisitorCode || this.generateRandomString(_javascriptSdkCore.VISITOR_CODE_LENGTH);
24
+ const resultCookie = this.getResultCookie({
25
+ domain,
26
+ visitorCode
27
+ });
28
+
29
+ // --- Note ---
30
+ // - Browser automatically adds new cookie in the end (without overwrite)
31
+ // - Only one key-value pair can be added at a time
32
+ resultCookie.split(_javascriptSdkCore.Cookie.PairsDelimiter).forEach(item => {
33
+ document.cookie = item;
34
+ });
35
+ return visitorCode;
36
+ }
27
37
  }
38
+
28
39
  /**
29
40
  * @class
30
41
  * KameleoonUtils - a class with containing a number of static helper methods
31
42
  * */
32
43
  class KameleoonUtils {
33
- /**
34
- * @method getVisitorCode obtains visitor code from the browser cookie, if the visitor code doesn't yet exist generates a random visitor code (or uses a provided default) and sets a new visitor code to cookie
35
- * @param {string} domain domain which cookie belongs to
36
- * @param {string | undefined} defaultVisitorCode visitor code to be used in case there is no visitor code in cookies Note: if not passed visitor code will be randomly generated
37
- * @returns {string} result visitor code
38
- * */
39
- static getVisitorCode(domain, defaultVisitorCode) {
40
- const kameleoonUtilsConstructor = new KameleoonUtilsConstructor();
41
- return kameleoonUtilsConstructor.getVisitorCode({
42
- domain,
43
- defaultVisitorCode,
44
- });
45
- }
44
+ /**
45
+ * @method getVisitorCode obtains visitor code from the browser cookie, if the visitor code doesn't yet exist generates a random visitor code (or uses a provided default) and sets a new visitor code to cookie
46
+ * @param {string} domain domain which cookie belongs to
47
+ * @param {string | undefined} defaultVisitorCode visitor code to be used in case there is no visitor code in cookies Note: if not passed visitor code will be randomly generated
48
+ * @returns {string} result visitor code
49
+ * */
50
+ static getVisitorCode(domain, defaultVisitorCode) {
51
+ const kameleoonUtilsConstructor = new KameleoonUtilsConstructor();
52
+ return kameleoonUtilsConstructor.getVisitorCode({
53
+ domain,
54
+ defaultVisitorCode
55
+ });
56
+ }
46
57
  }
47
58
  exports.KameleoonUtils = KameleoonUtils;
48
59
  //# sourceMappingURL=kameleoonUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kameleoonUtils.js","sourceRoot":"","sources":["../src/kameleoonUtils.ts"],"names":[],"mappings":";;;AAAA,wEAKwC;AAExC,eAAe;AACf,0BAA0B;AAC1B,gDAAgD;AAChD,0FAA0F;AAC1F,8GAA8G;AAC9G,MAAM,yBAA0B,SAAQ,wCAAkB;IACjD,cAAc,CAAC,EACpB,MAAM,EACN,kBAAkB,GACiB;QACnC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QAE/B,MAAM,iBAAiB,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAE5D,IAAI,iBAAiB,CAAC,EAAE,IAAI,iBAAiB,CAAC,IAAI,EAAE;YAClD,OAAO,iBAAiB,CAAC,IAAI,CAAC;SAC/B;QAED,MAAM,WAAW,GACf,kBAAkB,IAAI,IAAI,CAAC,oBAAoB,CAAC,yCAAmB,CAAC,CAAC;QAEvE,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;QAEnE,eAAe;QACf,yEAAyE;QACzE,mDAAmD;QACnD,YAAY,CAAC,KAAK,CAAC,4BAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACzD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAED;;;KAGK;AACL,MAAa,cAAc;IACzB;;;;;SAKK;IACL,MAAM,CAAC,cAAc,CAAC,MAAc,EAAE,kBAA2B;QAC/D,MAAM,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;QAElE,OAAO,yBAAyB,CAAC,cAAc,CAAC;YAC9C,MAAM;YACN,kBAAkB;SACnB,CAAC,CAAC;IACL,CAAC;CACF;AAfD,wCAeC"}
1
+ {"version":3,"file":"kameleoonUtils.js","names":["_javascriptSdkCore","require","KameleoonUtilsConstructor","KameleoonCoreUtils","getVisitorCode","domain","defaultVisitorCode","cookie","document","visitorCodeResult","getCookieVisitorCode","ok","data","visitorCode","generateRandomString","VISITOR_CODE_LENGTH","resultCookie","getResultCookie","split","Cookie","PairsDelimiter","forEach","item","KameleoonUtils","kameleoonUtilsConstructor","exports"],"sources":["../src/kameleoonUtils.ts"],"sourcesContent":["import {\n Cookie,\n KameleoonCoreUtils,\n VISITOR_CODE_LENGTH,\n ClientGetVisitorCodeParametersType,\n} from '@kameleoon/javascript-sdk-core';\n\n// --- Note ---\n// Extra class is created:\n// - To enforce abstract `getVisitorCode` method\n// - To use extended methods while `KameleoonUtils` itself only operates on static methods\n// - To keep similar parameters object on inner implementation and disperse it for proprietary implementations\nclass KameleoonUtilsConstructor extends KameleoonCoreUtils {\n public getVisitorCode({\n domain,\n defaultVisitorCode,\n }: ClientGetVisitorCodeParametersType): string {\n const cookie = document.cookie;\n\n const visitorCodeResult = this.getCookieVisitorCode(cookie);\n\n if (visitorCodeResult.ok && visitorCodeResult.data) {\n return visitorCodeResult.data;\n }\n\n const visitorCode =\n defaultVisitorCode || this.generateRandomString(VISITOR_CODE_LENGTH);\n\n const resultCookie = this.getResultCookie({ domain, visitorCode });\n\n // --- Note ---\n // - Browser automatically adds new cookie in the end (without overwrite)\n // - Only one key-value pair can be added at a time\n resultCookie.split(Cookie.PairsDelimiter).forEach((item) => {\n document.cookie = item;\n });\n\n return visitorCode;\n }\n}\n\n/**\n * @class\n * KameleoonUtils - a class with containing a number of static helper methods\n * */\nexport class KameleoonUtils {\n /**\n * @method getVisitorCode obtains visitor code from the browser cookie, if the visitor code doesn't yet exist generates a random visitor code (or uses a provided default) and sets a new visitor code to cookie\n * @param {string} domain domain which cookie belongs to\n * @param {string | undefined} defaultVisitorCode visitor code to be used in case there is no visitor code in cookies Note: if not passed visitor code will be randomly generated\n * @returns {string} result visitor code\n * */\n static getVisitorCode(domain: string, defaultVisitorCode?: string): string {\n const kameleoonUtilsConstructor = new KameleoonUtilsConstructor();\n\n return kameleoonUtilsConstructor.getVisitorCode({\n domain,\n defaultVisitorCode,\n });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAOA;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,SAASC,qCAAkB,CAAC;EAClDC,cAAcA,CAAC;IACpBC,MAAM;IACNC;EACkC,CAAC,EAAU;IAC7C,MAAMC,MAAM,GAAGC,QAAQ,CAACD,MAAM;IAE9B,MAAME,iBAAiB,GAAG,IAAI,CAACC,oBAAoB,CAACH,MAAM,CAAC;IAE3D,IAAIE,iBAAiB,CAACE,EAAE,IAAIF,iBAAiB,CAACG,IAAI,EAAE;MAClD,OAAOH,iBAAiB,CAACG,IAAI;IAC/B;IAEA,MAAMC,WAAW,GACfP,kBAAkB,IAAI,IAAI,CAACQ,oBAAoB,CAACC,sCAAmB,CAAC;IAEtE,MAAMC,YAAY,GAAG,IAAI,CAACC,eAAe,CAAC;MAAEZ,MAAM;MAAEQ;IAAY,CAAC,CAAC;;IAElE;IACA;IACA;IACAG,YAAY,CAACE,KAAK,CAACC,yBAAM,CAACC,cAAc,CAAC,CAACC,OAAO,CAAEC,IAAI,IAAK;MAC1Dd,QAAQ,CAACD,MAAM,GAAGe,IAAI;IACxB,CAAC,CAAC;IAEF,OAAOT,WAAW;EACpB;AACF;;AAEA;AACA;AACA;AACA;AACO,MAAMU,cAAc,CAAC;EAC1B;AACF;AACA;AACA;AACA;AACA;EACE,OAAOnB,cAAcA,CAACC,MAAc,EAAEC,kBAA2B,EAAU;IACzE,MAAMkB,yBAAyB,GAAG,IAAItB,yBAAyB,EAAE;IAEjE,OAAOsB,yBAAyB,CAACpB,cAAc,CAAC;MAC9CC,MAAM;MACNC;IACF,CAAC,CAAC;EACJ;AACF;AAACmB,OAAA,CAAAF,cAAA,GAAAA,cAAA"}
@@ -0,0 +1,5 @@
1
+ import { JSONType, TrackParametersType, IExternalRequestDispatcher } from '@kameleoon/javascript-sdk-core';
2
+ export declare class RequestDispatcher implements IExternalRequestDispatcher {
3
+ track({ url, headers, body, }: TrackParametersType): Promise<boolean>;
4
+ get(url: string): Promise<JSONType>;
5
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RequestDispatcher = void 0;
7
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
8
+ class RequestDispatcher {
9
+ async track({
10
+ url,
11
+ headers,
12
+ body
13
+ }) {
14
+ const response = await fetch(url, {
15
+ method: _javascriptSdkCore.HttpMethod.Post,
16
+ headers,
17
+ body
18
+ });
19
+ return response.ok;
20
+ }
21
+ async get(url) {
22
+ const response = await fetch(url, {
23
+ method: _javascriptSdkCore.HttpMethod.Get
24
+ });
25
+ return response.json();
26
+ }
27
+ }
28
+ exports.RequestDispatcher = RequestDispatcher;
29
+ //# sourceMappingURL=requester.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requester.js","names":["_javascriptSdkCore","require","RequestDispatcher","track","url","headers","body","response","fetch","method","HttpMethod","Post","ok","get","Get","json","exports"],"sources":["../src/requester.ts"],"sourcesContent":["import {\n JSONType,\n HttpMethod,\n TrackParametersType,\n IExternalRequestDispatcher,\n} from '@kameleoon/javascript-sdk-core';\n\nexport class RequestDispatcher implements IExternalRequestDispatcher {\n public async track({\n url,\n headers,\n body,\n }: TrackParametersType): Promise<boolean> {\n const response = await fetch(url, {\n method: HttpMethod.Post,\n headers,\n body,\n });\n\n return response.ok;\n }\n\n public async get(url: string): Promise<JSONType> {\n const response = await fetch(url, {\n method: HttpMethod.Get,\n });\n\n return response.json();\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAOO,MAAMC,iBAAiB,CAAuC;EACnE,MAAaC,KAAKA,CAAC;IACjBC,GAAG;IACHC,OAAO;IACPC;EACmB,CAAC,EAAoB;IACxC,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACJ,GAAG,EAAE;MAChCK,MAAM,EAAEC,6BAAU,CAACC,IAAI;MACvBN,OAAO;MACPC;IACF,CAAC,CAAC;IAEF,OAAOC,QAAQ,CAACK,EAAE;EACpB;EAEA,MAAaC,GAAGA,CAACT,GAAW,EAAqB;IAC/C,MAAMG,QAAQ,GAAG,MAAMC,KAAK,CAACJ,GAAG,EAAE;MAChCK,MAAM,EAAEC,6BAAU,CAACI;IACrB,CAAC,CAAC;IAEF,OAAOP,QAAQ,CAACQ,IAAI,EAAE;EACxB;AACF;AAACC,OAAA,CAAAd,iBAAA,GAAAA,iBAAA"}
package/dist/storage.js CHANGED
@@ -1,36 +1,42 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.StorageConstructor = void 0;
4
- const javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
7
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
11
  class StorageConstructor {
6
- initialize(key) {
7
- const storage = new Storage(key);
8
- return storage;
9
- }
12
+ initialize(key) {
13
+ const storage = new Storage(key);
14
+ return storage;
15
+ }
10
16
  }
11
17
  exports.StorageConstructor = StorageConstructor;
12
18
  class Storage {
13
- constructor(key) {
14
- this.storageKey = key;
15
- }
16
- get key() {
17
- return this.storageKey;
18
- }
19
- read() {
20
- const data = localStorage.getItem(this.storageKey);
21
- if (!data) {
22
- return (0, javascript_sdk_core_1.Err)(new javascript_sdk_core_1.KameleoonError(javascript_sdk_core_1.KameleoonException.StorageRead, this.storageKey));
23
- }
24
- return (0, javascript_sdk_core_1.Ok)(data);
19
+ constructor(key) {
20
+ _defineProperty(this, "storageKey", void 0);
21
+ this.storageKey = key;
22
+ }
23
+ get key() {
24
+ return this.storageKey;
25
+ }
26
+ read() {
27
+ const data = localStorage.getItem(this.storageKey);
28
+ if (!data) {
29
+ return (0, _javascriptSdkCore.Err)(new _javascriptSdkCore.KameleoonError(_javascriptSdkCore.KameleoonException.StorageRead, this.storageKey));
25
30
  }
26
- write(data) {
27
- try {
28
- localStorage.setItem(this.storageKey, data);
29
- return (0, javascript_sdk_core_1.Ok)();
30
- }
31
- catch (err) {
32
- return (0, javascript_sdk_core_1.Err)(new javascript_sdk_core_1.KameleoonError(javascript_sdk_core_1.KameleoonException.StorageWrite, err));
33
- }
31
+ return (0, _javascriptSdkCore.Ok)(data);
32
+ }
33
+ write(data) {
34
+ try {
35
+ localStorage.setItem(this.storageKey, data);
36
+ return (0, _javascriptSdkCore.Ok)();
37
+ } catch (err) {
38
+ return (0, _javascriptSdkCore.Err)(new _javascriptSdkCore.KameleoonError(_javascriptSdkCore.KameleoonException.StorageWrite, err));
34
39
  }
40
+ }
35
41
  }
36
42
  //# sourceMappingURL=storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":";;;AAAA,wEASwC;AAExC,MAAa,kBAAkB;IACtB,UAAU,CAAC,GAAwB;QACxC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;QAEjC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAND,gDAMC;AAED,MAAM,OAAO;IAGX,YAAY,GAAwB;QAClC,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IACxB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEM,IAAI;QACT,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,EAAE;YACT,OAAO,IAAA,yBAAG,EACR,IAAI,oCAAc,CAAC,wCAAkB,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CACpE,CAAC;SACH;QAED,OAAO,IAAA,wBAAE,EAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,IAAY;QACvB,IAAI;YACF,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YAE5C,OAAO,IAAA,wBAAE,GAAE,CAAC;SACb;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,IAAA,yBAAG,EAAC,IAAI,oCAAc,CAAC,wCAAkB,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC;SACtE;IACH,CAAC;CACF"}
1
+ {"version":3,"file":"storage.js","names":["_javascriptSdkCore","require","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","StorageConstructor","initialize","storage","Storage","exports","constructor","storageKey","read","data","localStorage","getItem","Err","KameleoonError","KameleoonException","StorageRead","Ok","write","setItem","err","StorageWrite"],"sources":["../src/storage.ts"],"sourcesContent":["import {\n Ok,\n Err,\n Result,\n KameleoonError,\n IExternalStorage,\n KameleoonException,\n KameleoonStorageKey,\n IExternalStorageConstructor,\n} from '@kameleoon/javascript-sdk-core';\n\nexport class StorageConstructor implements IExternalStorageConstructor {\n public initialize(key: KameleoonStorageKey): IExternalStorage {\n const storage = new Storage(key);\n\n return storage;\n }\n}\n\nclass Storage implements IExternalStorage {\n private storageKey: KameleoonStorageKey;\n\n constructor(key: KameleoonStorageKey) {\n this.storageKey = key;\n }\n\n get key(): KameleoonStorageKey {\n return this.storageKey;\n }\n\n public read(): Result<string, KameleoonError> {\n const data = localStorage.getItem(this.storageKey);\n\n if (!data) {\n return Err(\n new KameleoonError(KameleoonException.StorageRead, this.storageKey),\n );\n }\n\n return Ok(data);\n }\n\n public write(data: string): Result<void, KameleoonError> {\n try {\n localStorage.setItem(this.storageKey, data);\n\n return Ok();\n } catch (err) {\n return Err(new KameleoonError(KameleoonException.StorageWrite, err));\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AASwC,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,GAAA,QAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,2BAAAR,GAAA,gBAAAA,GAAA,GAAAU,MAAA,CAAAV,GAAA;AAAA,SAAAS,aAAAE,KAAA,EAAAC,IAAA,eAAAD,KAAA,iBAAAA,KAAA,kBAAAA,KAAA,MAAAE,IAAA,GAAAF,KAAA,CAAAG,MAAA,CAAAC,WAAA,OAAAF,IAAA,KAAAG,SAAA,QAAAC,GAAA,GAAAJ,IAAA,CAAAK,IAAA,CAAAP,KAAA,EAAAC,IAAA,2BAAAK,GAAA,sBAAAA,GAAA,YAAAE,SAAA,4DAAAP,IAAA,gBAAAF,MAAA,GAAAU,MAAA,EAAAT,KAAA;AAEjC,MAAMU,kBAAkB,CAAwC;EAC9DC,UAAUA,CAACtB,GAAwB,EAAoB;IAC5D,MAAMuB,OAAO,GAAG,IAAIC,OAAO,CAACxB,GAAG,CAAC;IAEhC,OAAOuB,OAAO;EAChB;AACF;AAACE,OAAA,CAAAJ,kBAAA,GAAAA,kBAAA;AAED,MAAMG,OAAO,CAA6B;EAGxCE,WAAWA,CAAC1B,GAAwB,EAAE;IAAAF,eAAA;IACpC,IAAI,CAAC6B,UAAU,GAAG3B,GAAG;EACvB;EAEA,IAAIA,GAAGA,CAAA,EAAwB;IAC7B,OAAO,IAAI,CAAC2B,UAAU;EACxB;EAEOC,IAAIA,CAAA,EAAmC;IAC5C,MAAMC,IAAI,GAAGC,YAAY,CAACC,OAAO,CAAC,IAAI,CAACJ,UAAU,CAAC;IAElD,IAAI,CAACE,IAAI,EAAE;MACT,OAAO,IAAAG,sBAAG,EACR,IAAIC,iCAAc,CAACC,qCAAkB,CAACC,WAAW,EAAE,IAAI,CAACR,UAAU,CAAC,CACpE;IACH;IAEA,OAAO,IAAAS,qBAAE,EAACP,IAAI,CAAC;EACjB;EAEOQ,KAAKA,CAACR,IAAY,EAAgC;IACvD,IAAI;MACFC,YAAY,CAACQ,OAAO,CAAC,IAAI,CAACX,UAAU,EAAEE,IAAI,CAAC;MAE3C,OAAO,IAAAO,qBAAE,GAAE;IACb,CAAC,CAAC,OAAOG,GAAG,EAAE;MACZ,OAAO,IAAAP,sBAAG,EAAC,IAAIC,iCAAc,CAACC,qCAAkB,CAACM,YAAY,EAAED,GAAG,CAAC,CAAC;IACtE;EACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kameleoon/javascript-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Kameleoon JavaScript SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,9 +9,12 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
12
- "build": "npm run clean && tsc",
12
+ "start": "npm run clean && tsc -w",
13
+ "build": "npm run clean && npm run build:types && npm run build:js",
14
+ "build:types": "tsc --emitDeclarationOnly",
15
+ "build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --source-maps true",
13
16
  "deploy": "npm publish --tag latest --access public",
14
- "deploy-nexus": "npm publish --registry=https://nexus.kameleoon.net/repository/npm-kameleoon/",
17
+ "deploy-nexus": "/bin/bash ../../scripts/deploy_nexus.sh javascript-sdk",
15
18
  "release": "/bin/bash ../../scripts/release.sh javascript-sdk",
16
19
  "update-documentation": "/bin/bash ../../scripts/update_documentation.sh js",
17
20
  "test": "jest",
@@ -35,7 +38,6 @@
35
38
  },
36
39
  "devDependencies": {
37
40
  "@types/crypto-js": "^4.1.1",
38
- "@types/node-fetch": "^2.6.2",
39
41
  "rimraf": "^3.0.2",
40
42
  "typescript": "^4.4.4",
41
43
  "jest": "^27.3.1",