@kameleoon/react-sdk 7.1.2 → 7.2.1
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/constants.d.ts +2 -0
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.js +1 -1
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/requester.d.ts +2 -1
- package/dist/requester.js +20 -1
- package/dist/requester.js.map +1 -1
- package/dist/useInitialize.d.ts +3 -0
- package/dist/useInitialize.js +2 -2
- package/dist/useInitialize.js.map +1 -1
- package/dist/useRemoteVisitorData.d.ts +21 -0
- package/dist/useRemoteVisitorData.js +25 -0
- package/dist/useRemoteVisitorData.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NUMBER_OF_RETRIES = exports.DELAY_MILLISECONDS = void 0;
|
|
7
|
+
const NUMBER_OF_RETRIES = 3;
|
|
8
|
+
exports.NUMBER_OF_RETRIES = NUMBER_OF_RETRIES;
|
|
9
|
+
const DELAY_MILLISECONDS = 2000;
|
|
10
|
+
exports.DELAY_MILLISECONDS = DELAY_MILLISECONDS;
|
|
11
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":["NUMBER_OF_RETRIES","exports","DELAY_MILLISECONDS"],"sources":["../src/constants.ts"],"sourcesContent":["export const NUMBER_OF_RETRIES = 3;\nexport const DELAY_MILLISECONDS = 2000;\n"],"mappings":";;;;;;AAAO,MAAMA,iBAAiB,GAAG,CAAC;AAACC,OAAA,CAAAD,iBAAA,GAAAA,iBAAA;AAC5B,MAAME,kBAAkB,GAAG,IAAI;AAACD,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { useInitialize, IInitializeHookResult } from './useInitialize';
|
|
|
7
7
|
export { useExperiments, IExperimentsHookResult } from './useExperiments';
|
|
8
8
|
export { useFeatureFlags, IFeatureFlagsHookResult } from './useFeatureFlags';
|
|
9
9
|
export { useRemoteData, IRemoteDataHookResult } from './useRemoteData';
|
|
10
|
+
export { useRemoteVisitorData, IRemoteVisitorDataHookResult, } from './useRemoteVisitorData';
|
|
10
11
|
export { useAddData, IAddDataHookResult } from './useAddData';
|
|
11
12
|
export { useFlushData, IFlushDataHookResult } from './useFlushData';
|
|
12
13
|
export { useBrowserVisitorCode, IBrowserVisitorCodeHookResult, } from './useBrowserVisitorCode';
|
package/dist/index.js
CHANGED
|
@@ -135,6 +135,12 @@ Object.defineProperty(exports, "IRemoteDataHookResult", {
|
|
|
135
135
|
return _useRemoteData.IRemoteDataHookResult;
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
|
+
Object.defineProperty(exports, "IRemoteVisitorDataHookResult", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: function () {
|
|
141
|
+
return _useRemoteVisitorData.IRemoteVisitorDataHookResult;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
138
144
|
Object.defineProperty(exports, "ITrackConversionHookResult", {
|
|
139
145
|
enumerable: true,
|
|
140
146
|
get: function () {
|
|
@@ -303,6 +309,12 @@ Object.defineProperty(exports, "useRemoteData", {
|
|
|
303
309
|
return _useRemoteData.useRemoteData;
|
|
304
310
|
}
|
|
305
311
|
});
|
|
312
|
+
Object.defineProperty(exports, "useRemoteVisitorData", {
|
|
313
|
+
enumerable: true,
|
|
314
|
+
get: function () {
|
|
315
|
+
return _useRemoteVisitorData.useRemoteVisitorData;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
306
318
|
Object.defineProperty(exports, "useTrackConversion", {
|
|
307
319
|
enumerable: true,
|
|
308
320
|
get: function () {
|
|
@@ -336,6 +348,7 @@ var _useInitialize = require("./useInitialize");
|
|
|
336
348
|
var _useExperiments = require("./useExperiments");
|
|
337
349
|
var _useFeatureFlags = require("./useFeatureFlags");
|
|
338
350
|
var _useRemoteData = require("./useRemoteData");
|
|
351
|
+
var _useRemoteVisitorData = require("./useRemoteVisitorData");
|
|
339
352
|
var _useAddData = require("./useAddData");
|
|
340
353
|
var _useFlushData = require("./useFlushData");
|
|
341
354
|
var _useBrowserVisitorCode = require("./useBrowserVisitorCode");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_javascriptSdkCore","require","_KameleoonProvider","_interopRequireWildcard","_KameleoonContext","_kameleoonClient","_useKameleoon","_useInitialize","_useExperiments","_useFeatureFlags","_useRemoteData","_useAddData","_useFlushData","_useBrowserVisitorCode","_useNativeVisitorCode","_useVisitorExperiments","_useVisitorFeatureFlags","_useFeatureFlagVariationKey","_useTriggerExperiment","_useFeatureFlagActive","_useEngineTrackingCode","_useFeatureVariable","_useTrackConversion","_useConfigurationUpdate","_useExperimentVariationData","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sources":["../src/index.ts"],"sourcesContent":["export {\n Device,\n Browser,\n PageView,\n JSONType,\n Conversion,\n CustomData,\n DeviceType,\n BrowserType,\n Environment,\n VariableType,\n KameleoonError,\n KameleoonException,\n KameleoonStorageKey,\n} from '@kameleoon/javascript-sdk-core';\nexport {\n default as KameleoonProvider,\n IKameleoonProviderProps,\n} from './KameleoonProvider';\nexport { KameleoonContext } from './KameleoonContext';\nexport { createClient } from './kameleoonClient';\nexport { useKameleoon } from './useKameleoon';\nexport { useInitialize, IInitializeHookResult } from './useInitialize';\nexport { useExperiments, IExperimentsHookResult } from './useExperiments';\nexport { useFeatureFlags, IFeatureFlagsHookResult } from './useFeatureFlags';\nexport { useRemoteData, IRemoteDataHookResult } from './useRemoteData';\nexport { useAddData, IAddDataHookResult } from './useAddData';\nexport { useFlushData, IFlushDataHookResult } from './useFlushData';\nexport {\n useBrowserVisitorCode,\n IBrowserVisitorCodeHookResult,\n} from './useBrowserVisitorCode';\nexport {\n useNativeVisitorCode,\n INativeVisitorCodeHookResult,\n} from './useNativeVisitorCode';\nexport {\n useVisitorExperiments,\n IVisitorExperimentsHookResult,\n} from './useVisitorExperiments';\nexport {\n useVisitorFeatureFlags,\n IVisitorFeatureFlagsHookResult,\n} from './useVisitorFeatureFlags';\nexport {\n useFeatureFlagVariationKey,\n IFeatureFlagVariationKeyHookResult,\n} from './useFeatureFlagVariationKey';\nexport {\n useTriggerExperiment,\n ITriggerExperimentHookResult,\n} from './useTriggerExperiment';\nexport {\n useFeatureFlagActive,\n IFeatureFlagActiveHookResult,\n} from './useFeatureFlagActive';\nexport {\n useEngineTrackingCode,\n IEngineTrackingCodeHookResult,\n} from './useEngineTrackingCode';\nexport {\n useFeatureVariable,\n IFeatureVariableHookResult,\n} from './useFeatureVariable';\nexport {\n useTrackConversion,\n ITrackConversionHookResult,\n} from './useTrackConversion';\nexport {\n useConfigurationUpdate,\n IConfigurationUpdateHookResult,\n} from './useConfigurationUpdate';\nexport {\n useExperimentVariationData,\n IExperimentVariationDataHookResult,\n} from './useExperimentVariationData';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_javascriptSdkCore","require","_KameleoonProvider","_interopRequireWildcard","_KameleoonContext","_kameleoonClient","_useKameleoon","_useInitialize","_useExperiments","_useFeatureFlags","_useRemoteData","_useRemoteVisitorData","_useAddData","_useFlushData","_useBrowserVisitorCode","_useNativeVisitorCode","_useVisitorExperiments","_useVisitorFeatureFlags","_useFeatureFlagVariationKey","_useTriggerExperiment","_useFeatureFlagActive","_useEngineTrackingCode","_useFeatureVariable","_useTrackConversion","_useConfigurationUpdate","_useExperimentVariationData","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sources":["../src/index.ts"],"sourcesContent":["export {\n Device,\n Browser,\n PageView,\n JSONType,\n Conversion,\n CustomData,\n DeviceType,\n BrowserType,\n Environment,\n VariableType,\n KameleoonError,\n KameleoonException,\n KameleoonStorageKey,\n} from '@kameleoon/javascript-sdk-core';\nexport {\n default as KameleoonProvider,\n IKameleoonProviderProps,\n} from './KameleoonProvider';\nexport { KameleoonContext } from './KameleoonContext';\nexport { createClient } from './kameleoonClient';\nexport { useKameleoon } from './useKameleoon';\nexport { useInitialize, IInitializeHookResult } from './useInitialize';\nexport { useExperiments, IExperimentsHookResult } from './useExperiments';\nexport { useFeatureFlags, IFeatureFlagsHookResult } from './useFeatureFlags';\nexport { useRemoteData, IRemoteDataHookResult } from './useRemoteData';\nexport {\n useRemoteVisitorData,\n IRemoteVisitorDataHookResult,\n} from './useRemoteVisitorData';\nexport { useAddData, IAddDataHookResult } from './useAddData';\nexport { useFlushData, IFlushDataHookResult } from './useFlushData';\nexport {\n useBrowserVisitorCode,\n IBrowserVisitorCodeHookResult,\n} from './useBrowserVisitorCode';\nexport {\n useNativeVisitorCode,\n INativeVisitorCodeHookResult,\n} from './useNativeVisitorCode';\nexport {\n useVisitorExperiments,\n IVisitorExperimentsHookResult,\n} from './useVisitorExperiments';\nexport {\n useVisitorFeatureFlags,\n IVisitorFeatureFlagsHookResult,\n} from './useVisitorFeatureFlags';\nexport {\n useFeatureFlagVariationKey,\n IFeatureFlagVariationKeyHookResult,\n} from './useFeatureFlagVariationKey';\nexport {\n useTriggerExperiment,\n ITriggerExperimentHookResult,\n} from './useTriggerExperiment';\nexport {\n useFeatureFlagActive,\n IFeatureFlagActiveHookResult,\n} from './useFeatureFlagActive';\nexport {\n useEngineTrackingCode,\n IEngineTrackingCodeHookResult,\n} from './useEngineTrackingCode';\nexport {\n useFeatureVariable,\n IFeatureVariableHookResult,\n} from './useFeatureVariable';\nexport {\n useTrackConversion,\n ITrackConversionHookResult,\n} from './useTrackConversion';\nexport {\n useConfigurationUpdate,\n IConfigurationUpdateHookResult,\n} from './useConfigurationUpdate';\nexport {\n useExperimentVariationData,\n IExperimentVariationDataHookResult,\n} from './useExperimentVariationData';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAeA,IAAAC,kBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAIA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,gBAAA,GAAAR,OAAA;AACA,IAAAS,cAAA,GAAAT,OAAA;AACA,IAAAU,qBAAA,GAAAV,OAAA;AAIA,IAAAW,WAAA,GAAAX,OAAA;AACA,IAAAY,aAAA,GAAAZ,OAAA;AACA,IAAAa,sBAAA,GAAAb,OAAA;AAIA,IAAAc,qBAAA,GAAAd,OAAA;AAIA,IAAAe,sBAAA,GAAAf,OAAA;AAIA,IAAAgB,uBAAA,GAAAhB,OAAA;AAIA,IAAAiB,2BAAA,GAAAjB,OAAA;AAIA,IAAAkB,qBAAA,GAAAlB,OAAA;AAIA,IAAAmB,qBAAA,GAAAnB,OAAA;AAIA,IAAAoB,sBAAA,GAAApB,OAAA;AAIA,IAAAqB,mBAAA,GAAArB,OAAA;AAIA,IAAAsB,mBAAA,GAAAtB,OAAA;AAIA,IAAAuB,uBAAA,GAAAvB,OAAA;AAIA,IAAAwB,2BAAA,GAAAxB,OAAA;AAGsC,SAAAyB,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAxB,wBAAA4B,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA"}
|
package/dist/kameleoonClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kameleoonClient.js","names":["_javascriptSdkCore","require","_eventSource","_storage","_requester","createClient","siteCode","configuration","isBrowser","window","Boolean","document","storage","LocalStorageConstructor","NativeStorageConstructor","eventSource","BrowserEventSourceConstructor","NativeEventSourceConstructor","requestDispatcher","RequestDispatcher","client","KameleoonCore","internalConfiguration","externalStorage","externalEventSource","externalRequestDispatcher","externalPackageInfo","type","SDKType","React","version"],"sources":["../src/kameleoonClient.ts"],"sourcesContent":["import {\n KameleoonCore,\n SDKConfigurationType,\n IExternalStorageConstructor,\n IExternalEventSourceConstructor,\n SDKType,\n} from '@kameleoon/javascript-sdk-core';\nimport {\n
|
|
1
|
+
{"version":3,"file":"kameleoonClient.js","names":["_javascriptSdkCore","require","_eventSource","_storage","_requester","createClient","siteCode","configuration","isBrowser","window","Boolean","document","storage","LocalStorageConstructor","NativeStorageConstructor","eventSource","BrowserEventSourceConstructor","NativeEventSourceConstructor","requestDispatcher","RequestDispatcher","client","KameleoonCore","internalConfiguration","externalStorage","externalEventSource","externalRequestDispatcher","externalPackageInfo","type","SDKType","React","version"],"sources":["../src/kameleoonClient.ts"],"sourcesContent":["import {\n KameleoonCore,\n SDKConfigurationType,\n IExternalStorageConstructor,\n IExternalEventSourceConstructor,\n SDKType,\n} from '@kameleoon/javascript-sdk-core';\nimport {\n NativeEventSourceConstructor,\n BrowserEventSourceConstructor,\n} from './eventSource';\nimport { LocalStorageConstructor, NativeStorageConstructor } from './storage';\nimport { RequestDispatcher } from './requester';\n\n/**\n * Creates an instance of KameleoonClient\n * @param {string} siteCode - client's siteCode defined on Kameleoon platform\n * @param {Partial<SDKConfigurationType> | undefined} configuration - client's configuration\n */\nexport function createClient(\n siteCode: string,\n configuration?: Partial<SDKConfigurationType>,\n): KameleoonCore {\n const isBrowser = typeof window !== 'undefined' && Boolean(window.document);\n const storage: IExternalStorageConstructor = isBrowser\n ? new LocalStorageConstructor()\n : new NativeStorageConstructor();\n const eventSource: IExternalEventSourceConstructor = isBrowser\n ? new BrowserEventSourceConstructor()\n : new NativeEventSourceConstructor();\n const requestDispatcher = new RequestDispatcher();\n\n const client = new KameleoonCore({\n siteCode,\n configuration,\n internalConfiguration: {\n externalStorage: storage,\n externalEventSource: eventSource,\n externalRequestDispatcher: requestDispatcher,\n externalPackageInfo: {\n type: SDKType.React,\n version: process.env.npm_package_version as string,\n },\n },\n });\n\n return client;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAOA,IAAAC,YAAA,GAAAD,OAAA;AAIA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA;AACA;AACA;AACA;AACA;AACO,SAASI,YAAYA,CAC1BC,QAAgB,EAChBC,aAA6C,EAC9B;EACf,MAAMC,SAAS,GAAG,OAAOC,MAAM,KAAK,WAAW,IAAIC,OAAO,CAACD,MAAM,CAACE,QAAQ,CAAC;EAC3E,MAAMC,OAAoC,GAAGJ,SAAS,GAClD,IAAIK,gCAAuB,EAAE,GAC7B,IAAIC,iCAAwB,EAAE;EAClC,MAAMC,WAA4C,GAAGP,SAAS,GAC1D,IAAIQ,0CAA6B,EAAE,GACnC,IAAIC,yCAA4B,EAAE;EACtC,MAAMC,iBAAiB,GAAG,IAAIC,4BAAiB,EAAE;EAEjD,MAAMC,MAAM,GAAG,IAAIC,gCAAa,CAAC;IAC/Bf,QAAQ;IACRC,aAAa;IACbe,qBAAqB,EAAE;MACrBC,eAAe,EAAEX,OAAO;MACxBY,mBAAmB,EAAET,WAAW;MAChCU,yBAAyB,EAAEP,iBAAiB;MAC5CQ,mBAAmB,EAAE;QACnBC,IAAI,EAAEC,0BAAO,CAACC,KAAK;QACnBC,OAAO;MACT;IACF;EACF,CAAC,CAAC;EAEF,OAAOV,MAAM;AACf"}
|
package/dist/requester.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JSONType, TrackParametersType, IExternalRequestDispatcher } from '@kameleoon/javascript-sdk-core';
|
|
2
2
|
export declare class RequestDispatcher implements IExternalRequestDispatcher {
|
|
3
3
|
track({ url, headers, body, }: TrackParametersType): Promise<boolean>;
|
|
4
|
-
|
|
4
|
+
getClientConfiguration(url: string): Promise<JSONType>;
|
|
5
|
+
getRemoteData(url: string): Promise<JSONType>;
|
|
5
6
|
}
|
package/dist/requester.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.RequestDispatcher = void 0;
|
|
7
7
|
var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
|
|
8
|
+
var _constants = require("./constants");
|
|
8
9
|
class RequestDispatcher {
|
|
9
10
|
async track({
|
|
10
11
|
url,
|
|
@@ -18,7 +19,25 @@ class RequestDispatcher {
|
|
|
18
19
|
});
|
|
19
20
|
return response.ok;
|
|
20
21
|
}
|
|
21
|
-
async
|
|
22
|
+
async getClientConfiguration(url) {
|
|
23
|
+
for (let i = 1; i <= _constants.NUMBER_OF_RETRIES; i++) {
|
|
24
|
+
try {
|
|
25
|
+
const response = await fetch(url, {
|
|
26
|
+
method: _javascriptSdkCore.HttpMethod.Get
|
|
27
|
+
});
|
|
28
|
+
if (response.status !== 504) {
|
|
29
|
+
return response.json();
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw new _javascriptSdkCore.KameleoonError(_javascriptSdkCore.KameleoonException.ClientConfiguration);
|
|
33
|
+
}
|
|
34
|
+
if (i < _constants.NUMBER_OF_RETRIES) {
|
|
35
|
+
await new Promise(resolve => setTimeout(resolve, _constants.DELAY_MILLISECONDS));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
throw new _javascriptSdkCore.KameleoonError(_javascriptSdkCore.KameleoonException.MaximumRetriesReached);
|
|
39
|
+
}
|
|
40
|
+
async getRemoteData(url) {
|
|
22
41
|
const response = await fetch(url, {
|
|
23
42
|
method: _javascriptSdkCore.HttpMethod.Get
|
|
24
43
|
});
|
package/dist/requester.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requester.js","names":["_javascriptSdkCore","require","RequestDispatcher","track","url","headers","body","response","fetch","method","HttpMethod","Post","ok","
|
|
1
|
+
{"version":3,"file":"requester.js","names":["_javascriptSdkCore","require","_constants","RequestDispatcher","track","url","headers","body","response","fetch","method","HttpMethod","Post","ok","getClientConfiguration","i","NUMBER_OF_RETRIES","Get","status","json","err","KameleoonError","KameleoonException","ClientConfiguration","Promise","resolve","setTimeout","DELAY_MILLISECONDS","MaximumRetriesReached","getRemoteData","exports"],"sources":["../src/requester.ts"],"sourcesContent":["import {\n JSONType,\n HttpMethod,\n TrackParametersType,\n IExternalRequestDispatcher,\n KameleoonException,\n KameleoonError,\n} from '@kameleoon/javascript-sdk-core';\nimport { DELAY_MILLISECONDS, NUMBER_OF_RETRIES } from './constants';\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 getClientConfiguration(url: string): Promise<JSONType> {\n for (let i = 1; i <= NUMBER_OF_RETRIES; i++) {\n try {\n const response = await fetch(url, {\n method: HttpMethod.Get,\n });\n\n if (response.status !== 504) {\n return response.json();\n }\n } catch (err) {\n throw new KameleoonError(KameleoonException.ClientConfiguration);\n }\n\n if (i < NUMBER_OF_RETRIES) {\n await new Promise((resolve) => setTimeout(resolve, DELAY_MILLISECONDS));\n }\n }\n\n throw new KameleoonError(KameleoonException.MaximumRetriesReached);\n }\n\n public async getRemoteData(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;AAQA,IAAAC,UAAA,GAAAD,OAAA;AAEO,MAAME,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,sBAAsBA,CAACT,GAAW,EAAqB;IAClE,KAAK,IAAIU,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIC,4BAAiB,EAAED,CAAC,EAAE,EAAE;MAC3C,IAAI;QACF,MAAMP,QAAQ,GAAG,MAAMC,KAAK,CAACJ,GAAG,EAAE;UAChCK,MAAM,EAAEC,6BAAU,CAACM;QACrB,CAAC,CAAC;QAEF,IAAIT,QAAQ,CAACU,MAAM,KAAK,GAAG,EAAE;UAC3B,OAAOV,QAAQ,CAACW,IAAI,EAAE;QACxB;MACF,CAAC,CAAC,OAAOC,GAAG,EAAE;QACZ,MAAM,IAAIC,iCAAc,CAACC,qCAAkB,CAACC,mBAAmB,CAAC;MAClE;MAEA,IAAIR,CAAC,GAAGC,4BAAiB,EAAE;QACzB,MAAM,IAAIQ,OAAO,CAAEC,OAAO,IAAKC,UAAU,CAACD,OAAO,EAAEE,6BAAkB,CAAC,CAAC;MACzE;IACF;IAEA,MAAM,IAAIN,iCAAc,CAACC,qCAAkB,CAACM,qBAAqB,CAAC;EACpE;EAEA,MAAaC,aAAaA,CAACxB,GAAW,EAAqB;IACzD,MAAMG,QAAQ,GAAG,MAAMC,KAAK,CAACJ,GAAG,EAAE;MAChCK,MAAM,EAAEC,6BAAU,CAACM;IACrB,CAAC,CAAC;IAEF,OAAOT,QAAQ,CAACW,IAAI,EAAE;EACxB;AACF;AAACW,OAAA,CAAA3B,iBAAA,GAAAA,iBAAA"}
|
package/dist/useInitialize.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export interface IInitializeHookResult {
|
|
2
2
|
/**
|
|
3
3
|
* An asynchronous method for KameleoonClient initialization by fetching Kameleoon SDK related data from server or by retrieving data from local source if data is up-to-date or update interval has not been reached.
|
|
4
|
+
*
|
|
5
|
+
* @param {boolean | undefined} useCache - optional parameter for activating SDK offline mode, if `true` is passed failed polls will not return error and will use cached data if such data is available, default value is `false`. Note: if offline mode is on, SDK will still try to retrieve the latest data.
|
|
4
6
|
* @throws `KameleoonError` with one of the following `type` s:
|
|
5
7
|
*
|
|
6
8
|
* - `KameleoonException.StorageWrite` Couldn't update storage data.
|
|
7
9
|
* - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api.
|
|
10
|
+
* - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed
|
|
8
11
|
*/
|
|
9
12
|
initialize: () => Promise<boolean>;
|
|
10
13
|
}
|
package/dist/useInitialize.js
CHANGED
|
@@ -15,8 +15,8 @@ function useInitialize() {
|
|
|
15
15
|
const {
|
|
16
16
|
client
|
|
17
17
|
} = (0, _useKameleoon.useKameleoon)();
|
|
18
|
-
const initialize = (0, _react.useCallback)(async
|
|
19
|
-
return await client.initialize();
|
|
18
|
+
const initialize = (0, _react.useCallback)(async useCache => {
|
|
19
|
+
return await client.initialize(useCache);
|
|
20
20
|
}, [client]);
|
|
21
21
|
return {
|
|
22
22
|
initialize
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInitialize.js","names":["_react","require","_useKameleoon","useInitialize","client","useKameleoon","initialize","useCallback"],"sources":["../src/useInitialize.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useKameleoon } from './useKameleoon';\n\nexport interface IInitializeHookResult {\n /**\n * An asynchronous method for KameleoonClient initialization by fetching Kameleoon SDK related data from server or by retrieving data from local source if data is up-to-date or update interval has not been reached.\n * @throws `KameleoonError` with one of the following `type` s:\n
|
|
1
|
+
{"version":3,"file":"useInitialize.js","names":["_react","require","_useKameleoon","useInitialize","client","useKameleoon","initialize","useCallback","useCache"],"sources":["../src/useInitialize.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useKameleoon } from './useKameleoon';\n\nexport interface IInitializeHookResult {\n /**\n * An asynchronous method for KameleoonClient initialization by fetching Kameleoon SDK related data from server or by retrieving data from local source if data is up-to-date or update interval has not been reached.\n *\n * @param {boolean | undefined} useCache - optional parameter for activating SDK offline mode, if `true` is passed failed polls will not return error and will use cached data if such data is available, default value is `false`. Note: if offline mode is on, SDK will still try to retrieve the latest data.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.StorageWrite` Couldn't update storage data.\n * - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api.\n * - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed\n */\n initialize: () => Promise<boolean>;\n}\n\n/**\n * A React Hook that returns asynchronous `initialize` function.\n *\n * @returns {IInitializeHookResult} an object containing the asynchronous `initialize` function.\n */\nexport function useInitialize(): IInitializeHookResult {\n const { client } = useKameleoon();\n\n const initialize = useCallback(\n async (useCache?: boolean): Promise<boolean> => {\n return await client.initialize(useCache);\n },\n [client],\n );\n\n return {\n initialize,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAgBA;AACA;AACA;AACA;AACA;AACO,SAASE,aAAaA,CAAA,EAA0B;EACrD,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EAEjC,MAAMC,UAAU,GAAG,IAAAC,kBAAW,EAC5B,MAAOC,QAAkB,IAAuB;IAC9C,OAAO,MAAMJ,MAAM,CAACE,UAAU,CAACE,QAAQ,CAAC;EAC1C,CAAC,EACD,CAACJ,MAAM,CAAC,CACT;EAED,OAAO;IACLE;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { KameleoonDataType } from '@kameleoon/javascript-sdk-core';
|
|
2
|
+
export interface IRemoteVisitorDataHookResult {
|
|
3
|
+
/**
|
|
4
|
+
* An asynchronous method for retrieving custom data for the latest visit of `visitorCode` from Kameleoon Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
|
|
7
|
+
* @param {boolean | undefined} shouldAddData - optional parameter for adding retrieved data to the storage like `addData` method does, default value is `true`
|
|
8
|
+
*
|
|
9
|
+
* @returns {KameleoonDataType[]} promise resolved to an array of `KameleoonData` instances, only includes custom data
|
|
10
|
+
* @throws `KameleoonError` with one of the following `type` s:
|
|
11
|
+
*
|
|
12
|
+
* - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server
|
|
13
|
+
*/
|
|
14
|
+
getRemoteVisitorData: (visitorCode: string, shouldAddData?: boolean) => Promise<KameleoonDataType[]>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A React Hook that returns asynchronous getRemoteVisitorData function which retrieves custom data from Kameleoon server and optionally adds it to storage.
|
|
18
|
+
*
|
|
19
|
+
* @returns {IRemoteVisitorDataHookResult} an object containing the `getRemoteVisitorData` function.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useRemoteVisitorData(): IRemoteVisitorDataHookResult;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useRemoteVisitorData = useRemoteVisitorData;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _useKameleoon = require("./useKameleoon");
|
|
9
|
+
/**
|
|
10
|
+
* A React Hook that returns asynchronous getRemoteVisitorData function which retrieves custom data from Kameleoon server and optionally adds it to storage.
|
|
11
|
+
*
|
|
12
|
+
* @returns {IRemoteVisitorDataHookResult} an object containing the `getRemoteVisitorData` function.
|
|
13
|
+
*/
|
|
14
|
+
function useRemoteVisitorData() {
|
|
15
|
+
const {
|
|
16
|
+
client
|
|
17
|
+
} = (0, _useKameleoon.useKameleoon)();
|
|
18
|
+
const getRemoteVisitorData = (0, _react.useCallback)(async (visitorCode, shouldAddData) => {
|
|
19
|
+
return await client.getRemoteVisitorData(visitorCode, shouldAddData);
|
|
20
|
+
}, [client]);
|
|
21
|
+
return {
|
|
22
|
+
getRemoteVisitorData
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=useRemoteVisitorData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRemoteVisitorData.js","names":["_react","require","_useKameleoon","useRemoteVisitorData","client","useKameleoon","getRemoteVisitorData","useCallback","visitorCode","shouldAddData"],"sources":["../src/useRemoteVisitorData.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useKameleoon } from './useKameleoon';\nimport { KameleoonDataType } from '@kameleoon/javascript-sdk-core';\n\nexport interface IRemoteVisitorDataHookResult {\n /**\n * An asynchronous method for retrieving custom data for the latest visit of `visitorCode` from Kameleoon Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {boolean | undefined} shouldAddData - optional parameter for adding retrieved data to the storage like `addData` method does, default value is `true`\n *\n * @returns {KameleoonDataType[]} promise resolved to an array of `KameleoonData` instances, only includes custom data\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getRemoteVisitorData: (\n visitorCode: string,\n shouldAddData?: boolean,\n ) => Promise<KameleoonDataType[]>;\n}\n\n/**\n * A React Hook that returns asynchronous getRemoteVisitorData function which retrieves custom data from Kameleoon server and optionally adds it to storage.\n *\n * @returns {IRemoteVisitorDataHookResult} an object containing the `getRemoteVisitorData` function.\n */\nexport function useRemoteVisitorData(): IRemoteVisitorDataHookResult {\n const { client } = useKameleoon();\n\n const getRemoteVisitorData = useCallback(\n async (\n visitorCode: string,\n shouldAddData?: boolean,\n ): Promise<KameleoonDataType[]> => {\n return await client.getRemoteVisitorData(visitorCode, shouldAddData);\n },\n [client],\n );\n\n return {\n getRemoteVisitorData,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAqBA;AACA;AACA;AACA;AACA;AACO,SAASE,oBAAoBA,CAAA,EAAiC;EACnE,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EAEjC,MAAMC,oBAAoB,GAAG,IAAAC,kBAAW,EACtC,OACEC,WAAmB,EACnBC,aAAuB,KACU;IACjC,OAAO,MAAML,MAAM,CAACE,oBAAoB,CAACE,WAAW,EAAEC,aAAa,CAAC;EACtE,CAAC,EACD,CAACL,MAAM,CAAC,CACT;EAED,OAAO;IACLE;EACF,CAAC;AACH"}
|