@kameleoon/react-sdk 6.1.1 → 6.1.2
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/dist/KameleoonContext.js +7 -3
- package/dist/KameleoonContext.js.map +1 -1
- package/dist/KameleoonError.js +16 -27
- package/dist/KameleoonError.js.map +1 -1
- package/dist/KameleoonProvider.js +18 -19
- package/dist/KameleoonProvider.js.map +1 -1
- package/dist/ProviderError.js +10 -25
- package/dist/ProviderError.js.map +1 -1
- package/dist/constants.js +6 -2
- package/dist/constants.js.map +1 -1
- package/dist/eventSource/browserEventSource.js +40 -30
- package/dist/eventSource/browserEventSource.js.map +1 -1
- package/dist/eventSource/index.js +18 -6
- package/dist/eventSource/index.js.map +1 -1
- package/dist/eventSource/nativeEventSource.js +42 -35
- package/dist/eventSource/nativeEventSource.js.map +1 -1
- package/dist/index.js +288 -51
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.js +27 -22
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonUtils/browserUtils.js +45 -58
- package/dist/kameleoonUtils/browserUtils.js.map +1 -1
- package/dist/kameleoonUtils/nativeUtils.js +38 -54
- package/dist/kameleoonUtils/nativeUtils.js.map +1 -1
- package/dist/requester.d.ts +5 -0
- package/dist/requester.js +29 -0
- package/dist/requester.js.map +1 -0
- package/dist/storage/index.js +18 -6
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/localStorage.js +37 -39
- package/dist/storage/localStorage.js.map +1 -1
- package/dist/storage/nativeStorage.js +36 -36
- package/dist/storage/nativeStorage.js.map +1 -1
- package/dist/useAddData.js +26 -49
- package/dist/useAddData.js.map +1 -1
- package/dist/useBrowserVisitorCode.js +13 -11
- package/dist/useBrowserVisitorCode.js.map +1 -1
- package/dist/useConfigurationUpdate.js +26 -20
- package/dist/useConfigurationUpdate.js.map +1 -1
- package/dist/useError.js +14 -12
- package/dist/useError.js.map +1 -1
- package/dist/useErrors.js +15 -38
- package/dist/useErrors.js.map +1 -1
- package/dist/useExperiments.js +27 -21
- package/dist/useExperiments.js.map +1 -1
- package/dist/useFeatureFlagActive.js +27 -21
- package/dist/useFeatureFlagActive.js.map +1 -1
- package/dist/useFeatureFlagVariationKey.js +27 -21
- package/dist/useFeatureFlagVariationKey.js.map +1 -1
- package/dist/useFeatureFlags.js +27 -21
- package/dist/useFeatureFlags.js.map +1 -1
- package/dist/useFeatureVariable.js +27 -21
- package/dist/useFeatureVariable.js.map +1 -1
- package/dist/useFlushData.js +16 -12
- package/dist/useFlushData.js.map +1 -1
- package/dist/useInitialize.js +27 -65
- package/dist/useInitialize.js.map +1 -1
- package/dist/useKameleoon.js +15 -13
- package/dist/useKameleoon.js.map +1 -1
- package/dist/useNativeVisitorCode.js +13 -11
- package/dist/useNativeVisitorCode.js.map +1 -1
- package/dist/useRemoteData.js +28 -67
- package/dist/useRemoteData.js.map +1 -1
- package/dist/useTrackConversion.js +26 -20
- package/dist/useTrackConversion.js.map +1 -1
- package/dist/useTriggerExperiment.js +28 -22
- package/dist/useTriggerExperiment.js.map +1 -1
- package/dist/useVisitorExperiments.js +27 -21
- package/dist/useVisitorExperiments.js.map +1 -1
- package/dist/useVisitorFeatureFlags.js +27 -21
- package/dist/useVisitorFeatureFlags.js.map +1 -1
- package/package.json +8 -5
package/dist/KameleoonContext.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.KameleoonContext = void 0;
|
|
4
|
-
var
|
|
5
|
-
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
const KameleoonContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
9
|
+
exports.KameleoonContext = KameleoonContext;
|
|
6
10
|
//# sourceMappingURL=KameleoonContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KameleoonContext.js","
|
|
1
|
+
{"version":3,"file":"KameleoonContext.js","names":["_react","require","KameleoonContext","createContext","exports"],"sources":["../src/KameleoonContext.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { KameleoonCore } from '@kameleoon/javascript-sdk-core';\n\nexport const KameleoonContext = createContext<KameleoonCore | null>(null);\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGO,MAAMC,gBAAgB,gBAAG,IAAAC,oBAAa,EAAuB,IAAI,CAAC;AAACC,OAAA,CAAAF,gBAAA,GAAAA,gBAAA"}
|
package/dist/KameleoonError.js
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
18
6
|
exports.KameleoonError = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
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); }
|
|
10
|
+
class KameleoonError extends Error {
|
|
11
|
+
constructor(type) {
|
|
12
|
+
super(`Error: ${type}`);
|
|
13
|
+
_defineProperty(this, "type", void 0);
|
|
14
|
+
this.name = 'KameleoonError';
|
|
15
|
+
this.message = `${this.name}.${type}`;
|
|
16
|
+
this.type = type;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
30
19
|
exports.KameleoonError = KameleoonError;
|
|
31
20
|
//# sourceMappingURL=KameleoonError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KameleoonError.js","
|
|
1
|
+
{"version":3,"file":"KameleoonError.js","names":["KameleoonError","Error","constructor","type","_defineProperty","name","message","exports"],"sources":["../src/KameleoonError.ts"],"sourcesContent":["import { KameleoonException } from '@kameleoon/javascript-sdk-core';\n\nexport class KameleoonError extends Error {\n type: KameleoonException;\n\n constructor(type: KameleoonException) {\n super(`Error: ${type}`);\n this.name = 'KameleoonError';\n this.message = `${this.name}.${type}`;\n this.type = type;\n }\n}\n"],"mappings":";;;;;;;;;AAEO,MAAMA,cAAc,SAASC,KAAK,CAAC;EAGxCC,WAAWA,CAACC,IAAwB,EAAE;IACpC,KAAK,CAAE,UAASA,IAAK,EAAC,CAAC;IAACC,eAAA;IACxB,IAAI,CAACC,IAAI,GAAG,gBAAgB;IAC5B,IAAI,CAACC,OAAO,GAAI,GAAE,IAAI,CAACD,IAAK,IAAGF,IAAK,EAAC;IACrC,IAAI,CAACA,IAAI,GAAGA,IAAI;EAClB;AACF;AAACI,OAAA,CAAAP,cAAA,GAAAA,cAAA"}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
15
|
-
var react_1 = require("react");
|
|
16
|
-
var KameleoonContext_1 = require("./KameleoonContext");
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _KameleoonContext = require("./KameleoonContext");
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
11
|
/**
|
|
18
12
|
* A Provider that wraps the project and provides an access to SDK APIs
|
|
19
13
|
*/
|
|
20
|
-
function KameleoonProvider(
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
function KameleoonProvider({
|
|
15
|
+
client,
|
|
16
|
+
children
|
|
17
|
+
}) {
|
|
18
|
+
return /*#__PURE__*/_react.default.createElement(_KameleoonContext.KameleoonContext.Provider, {
|
|
19
|
+
value: client
|
|
20
|
+
}, children);
|
|
23
21
|
}
|
|
24
|
-
|
|
22
|
+
var _default = /*#__PURE__*/(0, _react.memo)(KameleoonProvider);
|
|
23
|
+
exports.default = _default;
|
|
25
24
|
//# sourceMappingURL=KameleoonProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KameleoonProvider.js","
|
|
1
|
+
{"version":3,"file":"KameleoonProvider.js","names":["_react","_interopRequireWildcard","require","_KameleoonContext","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","KameleoonProvider","client","children","createElement","KameleoonContext","Provider","value","_default","memo","exports"],"sources":["../src/KameleoonProvider.tsx"],"sourcesContent":["import React, { memo, ReactNode } from 'react';\nimport { KameleoonCore } from '@kameleoon/javascript-sdk-core';\nimport { KameleoonContext } from './KameleoonContext';\n\nexport interface IKameleoonProviderProps {\n /** Child elements of the provider. */\n children: ReactNode;\n /** An instance of KameleoonClient. */\n client: KameleoonCore;\n}\n\n/**\n * A Provider that wraps the project and provides an access to SDK APIs\n */\nfunction KameleoonProvider({\n client,\n children,\n}: IKameleoonProviderProps): JSX.Element {\n return (\n <KameleoonContext.Provider value={client}>\n {children}\n </KameleoonContext.Provider>\n );\n}\n\nexport default memo(KameleoonProvider);\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AAAsD,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC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AAEL;EAAO,GACtCC,QAAQ,CACiB;AAEhC;AAAC,IAAAK,QAAA,gBAEc,IAAAC,WAAI,EAACR,iBAAiB,CAAC;AAAAS,OAAA,CAAAxB,OAAA,GAAAsB,QAAA"}
|
package/dist/ProviderError.js
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
18
6
|
exports.ProviderError = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return ProviderError;
|
|
27
|
-
}(Error));
|
|
7
|
+
class ProviderError extends Error {
|
|
8
|
+
constructor(method) {
|
|
9
|
+
super(`${method} must be used within a KameleoonProvider`);
|
|
10
|
+
this.name = 'ProviderError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
28
13
|
exports.ProviderError = ProviderError;
|
|
29
14
|
//# sourceMappingURL=ProviderError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderError.js","
|
|
1
|
+
{"version":3,"file":"ProviderError.js","names":["ProviderError","Error","constructor","method","name","exports"],"sources":["../src/ProviderError.ts"],"sourcesContent":["export class ProviderError extends Error {\n constructor(method: string) {\n super(`${method} must be used within a KameleoonProvider`);\n this.name = 'ProviderError';\n }\n}\n"],"mappings":";;;;;;AAAO,MAAMA,aAAa,SAASC,KAAK,CAAC;EACvCC,WAAWA,CAACC,MAAc,EAAE;IAC1B,KAAK,CAAE,GAAEA,MAAO,0CAAyC,CAAC;IAC1D,IAAI,CAACC,IAAI,GAAG,eAAe;EAC7B;AACF;AAACC,OAAA,CAAAL,aAAA,GAAAA,aAAA"}
|
package/dist/constants.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.DEFAULT_VARIATION_ID = void 0;
|
|
4
|
-
|
|
7
|
+
const DEFAULT_VARIATION_ID = 0;
|
|
8
|
+
exports.DEFAULT_VARIATION_ID = DEFAULT_VARIATION_ID;
|
|
5
9
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","
|
|
1
|
+
{"version":3,"file":"constants.js","names":["DEFAULT_VARIATION_ID","exports"],"sources":["../src/constants.ts"],"sourcesContent":["export const DEFAULT_VARIATION_ID = 0;\n"],"mappings":";;;;;;AAAO,MAAMA,oBAAoB,GAAG,CAAC;AAACC,OAAA,CAAAD,oBAAA,GAAAA,oBAAA"}
|
|
@@ -1,38 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.BrowserEventSourceConstructor = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
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); }
|
|
10
|
+
class BrowserEventSourceConstructor {
|
|
11
|
+
initialize(url) {
|
|
12
|
+
return new ExternalEventSource(url);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
13
16
|
// --- Note ---
|
|
14
17
|
// - `EventSource` has no dedicated tests because same browser instance
|
|
15
18
|
// is tested thoroughly inside core and would just duplicate tests
|
|
16
19
|
// - Moreover we would have to import some unexposed details like constructed url
|
|
17
20
|
// or the `eventType` from the core
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
exports.BrowserEventSourceConstructor = BrowserEventSourceConstructor;
|
|
22
|
+
class ExternalEventSource {
|
|
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
|
+
}
|
|
47
|
+
}
|
|
38
48
|
//# sourceMappingURL=browserEventSource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserEventSource.js","
|
|
1
|
+
{"version":3,"file":"browserEventSource.js","names":["BrowserEventSourceConstructor","initialize","url","ExternalEventSource","exports","constructor","_defineProperty","eventSource","EventSource","open","siteCode","eventType","onEvent","addEventListener","message","event","JSON","parse","data","eventSiteCode","ts","close"],"sources":["../../src/eventSource/browserEventSource.ts"],"sourcesContent":["import {\n RealTimeEventType,\n IExternalEventSource,\n EventSourceOpenParametersType,\n IExternalEventSourceConstructor,\n} from '@kameleoon/javascript-sdk-core';\n\nexport class BrowserEventSourceConstructor\n implements IExternalEventSourceConstructor\n{\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,6BAA6B,CAE1C;EACSC,UAAUA,CAACC,GAAW,EAAwB;IACnD,OAAO,IAAIC,mBAAmB,CAACD,GAAG,CAAC;EACrC;AACF;;AAEA;AACA;AACA;AACA;AACA;AAAAE,OAAA,CAAAJ,6BAAA,GAAAA,6BAAA;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"}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BrowserEventSourceConstructor", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _browserEventSource.BrowserEventSourceConstructor;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "NativeEventSourceConstructor", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _nativeEventSource.NativeEventSourceConstructor;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _browserEventSource = require("./browserEventSource");
|
|
19
|
+
var _nativeEventSource = require("./nativeEventSource");
|
|
8
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_browserEventSource","require","_nativeEventSource"],"sources":["../../src/eventSource/index.ts"],"sourcesContent":["export { BrowserEventSourceConstructor } from './browserEventSource';\nexport { NativeEventSourceConstructor } from './nativeEventSource';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA"}
|
|
@@ -1,39 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
6
|
exports.NativeEventSourceConstructor = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
}
|
|
7
|
+
var _reactNativeEventSource = _interopRequireDefault(require("react-native-event-source"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
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; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
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); }
|
|
12
|
+
class NativeEventSourceConstructor {
|
|
13
|
+
initialize(url) {
|
|
14
|
+
return new ExternalEventSource(url);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
16
17
|
exports.NativeEventSourceConstructor = NativeEventSourceConstructor;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
18
|
+
class ExternalEventSource {
|
|
19
|
+
constructor(url) {
|
|
20
|
+
_defineProperty(this, "eventSource", void 0);
|
|
21
|
+
const eventSource = new _reactNativeEventSource.default(url);
|
|
22
|
+
this.eventSource = eventSource;
|
|
23
|
+
}
|
|
24
|
+
open({
|
|
25
|
+
siteCode,
|
|
26
|
+
eventType,
|
|
27
|
+
onEvent
|
|
28
|
+
}) {
|
|
29
|
+
this.eventSource.addEventListener(eventType, message => {
|
|
30
|
+
if (message.data) {
|
|
31
|
+
const event = JSON.parse(message.data);
|
|
32
|
+
const {
|
|
33
|
+
siteCode: eventSiteCode,
|
|
34
|
+
ts
|
|
35
|
+
} = event;
|
|
36
|
+
if (siteCode === eventSiteCode) {
|
|
37
|
+
onEvent(ts);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
close() {
|
|
43
|
+
this.eventSource.close();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
39
46
|
//# sourceMappingURL=nativeEventSource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeEventSource.js","
|
|
1
|
+
{"version":3,"file":"nativeEventSource.js","names":["_reactNativeEventSource","_interopRequireDefault","require","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","NativeEventSourceConstructor","initialize","url","ExternalEventSource","exports","constructor","eventSource","EventSource","open","siteCode","eventType","onEvent","addEventListener","message","data","event","JSON","parse","eventSiteCode","ts","close"],"sources":["../../src/eventSource/nativeEventSource.ts"],"sourcesContent":["import EventSource from 'react-native-event-source';\nimport {\n RealTimeEventType,\n IExternalEventSource,\n EventSourceOpenParametersType,\n IExternalEventSourceConstructor,\n} from '@kameleoon/javascript-sdk-core';\n\nexport class NativeEventSourceConstructor\n implements IExternalEventSourceConstructor\n{\n public initialize(url: string): IExternalEventSource {\n return new ExternalEventSource(url);\n }\n}\n\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: MessageEvent) => {\n if (message.data) {\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\n public close() {\n this.eventSource.close();\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAoD,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAJ,GAAA,IAAAO,MAAA,CAAAC,cA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