@kameleoon/javascript-sdk 1.3.2 → 1.4.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.
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -0
- package/dist/kameleoonClient.d.ts +12 -1
- package/dist/kameleoonClient.js +16 -2
- 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/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"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SDKConfigurationType, KameleoonCore } from '@kameleoon/javascript-sdk-core';
|
|
2
2
|
/**
|
|
3
3
|
* @class
|
|
4
4
|
* KameleoonClient - a class for creating kameleoon client instance
|
|
5
5
|
* */
|
|
6
6
|
export declare class KameleoonClient extends KameleoonCore {
|
|
7
7
|
constructor(siteCode: string, configuration?: Partial<SDKConfigurationType>);
|
|
8
|
+
/**
|
|
9
|
+
* @method initialize - 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
|
|
10
|
+
* @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.
|
|
11
|
+
* @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail
|
|
12
|
+
* @throws `KameleoonError` with one of the following `type` s:
|
|
13
|
+
*
|
|
14
|
+
* - `KameleoonException.StorageWrite` Couldn't update storage data
|
|
15
|
+
* - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api
|
|
16
|
+
* - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed
|
|
17
|
+
*/
|
|
18
|
+
initialize(useCache?: boolean): Promise<boolean>;
|
|
8
19
|
}
|
package/dist/kameleoonClient.js
CHANGED
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.KameleoonClient = void 0;
|
|
7
7
|
var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
|
|
8
|
-
var _storage = require("./storage");
|
|
9
8
|
var _requester = require("./requester");
|
|
9
|
+
var _storage = require("./storage");
|
|
10
10
|
var _eventSource = require("./eventSource");
|
|
11
11
|
/**
|
|
12
12
|
* @class
|
|
@@ -26,11 +26,25 @@ class KameleoonClient extends _javascriptSdkCore.KameleoonCore {
|
|
|
26
26
|
externalRequestDispatcher: requestDispatcher,
|
|
27
27
|
externalPackageInfo: {
|
|
28
28
|
type: _javascriptSdkCore.SDKType.JavaScript,
|
|
29
|
-
version: "1.
|
|
29
|
+
version: "1.4.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @method initialize - 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
|
|
37
|
+
* @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.
|
|
38
|
+
* @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail
|
|
39
|
+
* @throws `KameleoonError` with one of the following `type` s:
|
|
40
|
+
*
|
|
41
|
+
* - `KameleoonException.StorageWrite` Couldn't update storage data
|
|
42
|
+
* - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api
|
|
43
|
+
* - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed
|
|
44
|
+
*/
|
|
45
|
+
async initialize(useCache) {
|
|
46
|
+
return super.initialize(useCache);
|
|
47
|
+
}
|
|
34
48
|
}
|
|
35
49
|
exports.KameleoonClient = KameleoonClient;
|
|
36
50
|
//# sourceMappingURL=kameleoonClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kameleoonClient.js","names":["_javascriptSdkCore","require","
|
|
1
|
+
{"version":3,"file":"kameleoonClient.js","names":["_javascriptSdkCore","require","_requester","_storage","_eventSource","KameleoonClient","KameleoonCore","constructor","siteCode","configuration","storage","StorageConstructor","eventSource","EventSourceConstructor","requestDispatcher","RequestDispatcher","internalConfiguration","externalStorage","externalEventSource","externalRequestDispatcher","externalPackageInfo","type","SDKType","JavaScript","version","initialize","useCache","exports"],"sources":["../src/kameleoonClient.ts"],"sourcesContent":["import {\n SDKConfigurationType,\n KameleoonCore,\n SDKType,\n} from '@kameleoon/javascript-sdk-core';\nimport { RequestDispatcher } from './requester';\nimport { StorageConstructor } from './storage';\nimport { EventSourceConstructor } from './eventSource';\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 /**\n * @method initialize - 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 * @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 * @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail\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 public async initialize(useCache?: boolean): Promise<boolean> {\n return super.initialize(useCache);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,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;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAaC,UAAUA,CAACC,QAAkB,EAAoB;IAC5D,OAAO,KAAK,CAACD,UAAU,CAACC,QAAQ,CAAC;EACnC;AACF;AAACC,OAAA,CAAAtB,eAAA,GAAAA,eAAA"}
|
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 KameleoonError,\n KameleoonException,\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"}
|