@kameleoon/javascript-sdk-core 4.3.0 → 4.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/CHANGELOG.md +11 -0
- package/README.md +0 -2
- package/dist/clientConfiguration/clientConfiguration.d.ts +2 -2
- package/dist/clientConfiguration/clientConfiguration.js +1 -1
- package/dist/clientConfiguration/clientConfiguration.js.map +1 -1
- package/dist/clientConfiguration/constants.js +1 -1
- package/dist/clientConfiguration/constants.js.map +1 -1
- package/dist/clientConfiguration/types.d.ts +1 -2
- package/dist/clientConfiguration/types.js.map +1 -1
- package/dist/clientSettings/clientSettings.d.ts +11 -1
- package/dist/clientSettings/clientSettings.js +1 -1
- package/dist/clientSettings/clientSettings.js.map +1 -1
- package/dist/clientSettings/types.d.ts +5 -1
- package/dist/clientSettings/types.js.map +1 -1
- package/dist/eventSource/eventSource.js +1 -1
- package/dist/eventSource/eventSource.js.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +1 -1
- package/dist/kameleoonClient.js +1 -1
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonClientInterface.d.ts +1 -1
- package/dist/kameleoonClientInterface.js.map +1 -1
- package/dist/kameleoonData/dataManager.d.ts +2 -2
- package/dist/kameleoonData/dataManager.js +1 -1
- package/dist/kameleoonData/dataManager.js.map +1 -1
- package/dist/kameleoonData/dataProcessor.d.ts +2 -2
- package/dist/kameleoonData/dataProcessor.js +1 -1
- package/dist/kameleoonData/dataProcessor.js.map +1 -1
- package/dist/kameleoonData/index.d.ts +0 -1
- package/dist/kameleoonData/index.js +1 -1
- package/dist/kameleoonData/index.js.map +1 -1
- package/dist/kameleoonData/types.d.ts +1 -1
- package/dist/kameleoonData/types.js.map +1 -1
- package/dist/kameleoonUtils.d.ts +29 -5
- package/dist/kameleoonUtils.js +1 -1
- package/dist/kameleoonUtils.js.map +1 -1
- package/dist/requester/constants.d.ts +1 -8
- package/dist/requester/constants.js +1 -1
- package/dist/requester/constants.js.map +1 -1
- package/dist/requester/index.d.ts +2 -2
- package/dist/requester/index.js +1 -1
- package/dist/requester/index.js.map +1 -1
- package/dist/requester/requester.d.ts +6 -2
- package/dist/requester/requester.js +1 -1
- package/dist/requester/requester.js.map +1 -1
- package/dist/requester/types.d.ts +96 -19
- package/dist/requester/types.js +1 -1
- package/dist/requester/types.js.map +1 -1
- package/dist/requester/urlProvider.d.ts +8 -5
- package/dist/requester/urlProvider.js +1 -1
- package/dist/requester/urlProvider.js.map +1 -1
- package/dist/types.d.ts +17 -5
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/constants.d.ts +1 -0
- package/dist/utilities/constants.js +1 -1
- package/dist/utilities/constants.js.map +1 -1
- package/dist/utilities/utilities.js +1 -1
- package/dist/utilities/utilities.js.map +1 -1
- package/dist/visitorCodeManager/visitorCodeManager.js +1 -1
- package/dist/visitorCodeManager/visitorCodeManager.js.map +1 -1
- package/package.json +2 -2
- package/dist/kameleoonData/constants.d.ts +0 -4
- package/dist/kameleoonData/constants.js +0 -2
- package/dist/kameleoonData/constants.js.map +0 -1
|
@@ -4,16 +4,33 @@ import { BrowserIndexMap, BrowserType, OperatingSystemType } from '../kameleoonD
|
|
|
4
4
|
import { DeviceType, KCSType, OperatingSystemIndexMap } from '../kameleoonData/types';
|
|
5
5
|
import { Header } from './constants';
|
|
6
6
|
import { VisitorDataFiltersType } from '../utilities';
|
|
7
|
+
export declare enum UrlType {
|
|
8
|
+
DataApi = "dataApi",
|
|
9
|
+
Events = "events",
|
|
10
|
+
ClientConfiguration = "clientConfiguration"
|
|
11
|
+
}
|
|
12
|
+
export type DomainsType = {
|
|
13
|
+
[key in UrlType]: DomainType;
|
|
14
|
+
};
|
|
15
|
+
export type DomainType = {
|
|
16
|
+
subdomain: string;
|
|
17
|
+
topLevelDomain: string;
|
|
18
|
+
secondLevelDomain: string;
|
|
19
|
+
};
|
|
7
20
|
export type UrlProviderInitializeParamsType = {
|
|
8
21
|
siteCode: string;
|
|
22
|
+
domain: string | null;
|
|
9
23
|
packageInfo: ExternalPackageInfoType;
|
|
10
|
-
environment
|
|
24
|
+
environment: Environment;
|
|
11
25
|
};
|
|
12
26
|
export type RequesterParamsType = {
|
|
13
27
|
siteCode: string;
|
|
14
|
-
|
|
28
|
+
domain: string | null;
|
|
29
|
+
environment: Environment;
|
|
15
30
|
packageInfo: ExternalPackageInfoType;
|
|
16
|
-
|
|
31
|
+
externalRequester: IExternalRequester;
|
|
32
|
+
trackRetryDelay: number;
|
|
33
|
+
requestTimeout: number;
|
|
17
34
|
};
|
|
18
35
|
export type TrackExperimentParamsType = {
|
|
19
36
|
dataUrl: string;
|
|
@@ -170,24 +187,84 @@ export type TrackParametersType = {
|
|
|
170
187
|
body: string;
|
|
171
188
|
};
|
|
172
189
|
/**
|
|
173
|
-
* @
|
|
190
|
+
* @type `RequestParametersType` - a type of parameters available in the request for each request type
|
|
174
191
|
* */
|
|
175
|
-
export
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
192
|
+
export type RequestParametersType = {
|
|
193
|
+
[RequestType.Configuration]: {
|
|
194
|
+
headers?: HeadersType;
|
|
195
|
+
signal: AbortSignal | null;
|
|
196
|
+
method: HttpMethod.Get;
|
|
197
|
+
};
|
|
198
|
+
[RequestType.Tracking]: {
|
|
199
|
+
headers?: HeadersType;
|
|
200
|
+
body: string;
|
|
201
|
+
signal: AbortSignal | null;
|
|
202
|
+
method: HttpMethod.Post;
|
|
203
|
+
};
|
|
204
|
+
[RequestType.RemoteData]: {
|
|
205
|
+
signal: AbortSignal | null;
|
|
206
|
+
method: HttpMethod.Get;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* @enum `RequestType` - an enum of available request types
|
|
211
|
+
* */
|
|
212
|
+
export declare enum RequestType {
|
|
213
|
+
Configuration = "configuration",
|
|
214
|
+
Tracking = "tracking",
|
|
215
|
+
RemoteData = "remoteData"
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @type `RetryCountType` - a type of retry count available for each request type
|
|
219
|
+
* @param {0 | 1 | 2} `RequestType.Configuration` - a count of retries for configuration request (`0` is the initial request)
|
|
220
|
+
* @param {0 | 1 | 2} `RequestType.Tracking` - a count of retries for tracking request (`0` is the initial request)
|
|
221
|
+
* @param {0} `RequestType.RemoteData` - a count of retries for remote data request (`0` is the initial request)
|
|
222
|
+
* */
|
|
223
|
+
export type RetryCountType = {
|
|
224
|
+
[RequestType.Configuration]: 0 | 1 | 2;
|
|
225
|
+
[RequestType.Tracking]: 0 | 1 | 2;
|
|
226
|
+
[RequestType.RemoteData]: 0;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* @type `SendRequestParametersType` - a type of parameters available to send a request
|
|
230
|
+
* @param {T extends RequestType} T - a type of request constrained by `RequestType`
|
|
231
|
+
* @param {string} url - url address
|
|
232
|
+
* @param {RequestParametersType[T]} parameters - parameters of the request depending on the request type
|
|
233
|
+
* @param {RetryCountType | undefined} retryCount - a count of retries, the possible count of retries depends on `RequestType`
|
|
234
|
+
* */
|
|
235
|
+
export type SendRequestParametersType<T extends RequestType> = {
|
|
236
|
+
requestType: T;
|
|
237
|
+
url: string;
|
|
238
|
+
retryCount?: RetryCountType[T];
|
|
239
|
+
parameters: RequestParametersType[T];
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* @type `KameleoonResponse` - a type of response that is assignable to most libraries `Response` objects
|
|
243
|
+
* @property {number} status - a status of the response
|
|
244
|
+
* @property {() => Promise<JSONType>} json - a method to parse the response to JSON
|
|
245
|
+
* @property {boolean} ok - a boolean value that indicates if the response is ok
|
|
246
|
+
* */
|
|
247
|
+
export type KameleoonResponseType = {
|
|
248
|
+
status: number;
|
|
249
|
+
json: () => Promise<JSONType>;
|
|
250
|
+
ok: boolean;
|
|
251
|
+
};
|
|
252
|
+
export type InternalSendRequestParametersType = {
|
|
253
|
+
requestType: RequestType;
|
|
254
|
+
url: string;
|
|
255
|
+
retryCount: number;
|
|
256
|
+
headers?: HeadersType;
|
|
257
|
+
body?: string;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* @interface `IExternalRequester` - an interface of External Requester which will be used to perform requests.
|
|
261
|
+
* */
|
|
262
|
+
export interface IExternalRequester {
|
|
187
263
|
/**
|
|
188
|
-
* @method
|
|
189
|
-
* @param {
|
|
264
|
+
* @method sendRequest - send a request
|
|
265
|
+
* @param {SendRequestParametersType<T>} parameters - parameters of the request depending on the request type
|
|
266
|
+
* @returns {Promise<KameleoonResponseType>} - a promise that resolves to the response
|
|
190
267
|
* */
|
|
191
|
-
|
|
268
|
+
sendRequest: <T extends RequestType>({ requestType, url, parameters, }: SendRequestParametersType<T>) => Promise<KameleoonResponseType>;
|
|
192
269
|
}
|
|
193
270
|
export {};
|
package/dist/requester/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.HttpMethod=exports.DataApiQuery=void 0;let HttpMethod=exports.HttpMethod=function(a){return a.Get="GET",a.Post="POST",a}({}),DataApiQuery=exports.DataApiQuery=function(a){return a[a.VisitEvent=0]="VisitEvent",a[a.VisitData=1]="VisitData",a[a.DataMap=2]="DataMap",a}({});const EVENT_TYPE_KEYS=["customData","staticData","page","conversion","geolocation","activity","experiment"],PARAMETER_KEYS=["valuesCountMap","mappingValue","id","nonce","country","environment","city","region","latitude","geolocation","longitude","mappingIdentifier","postalCode","sdkName","sdkVersion","kcs","browserIndex","browserVersion","siteCode","visitorCode","currentVisit","maxNumberPreviousVisits","customData","negative","revenue","title","os","conversion","staticData","osIndex","browser","referrersIndices","overwrite","index","href","experiment","page","variationId","deviceType","goalId","ts","key"],TRACKING_KEYS=["visit","map"],QUERY_KEYS=["sse","visitor","map","events"];
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlType=exports.RequestType=exports.HttpMethod=exports.DataApiQuery=void 0;let UrlType=exports.UrlType=function(a){return a.DataApi="dataApi",a.Events="events",a.ClientConfiguration="clientConfiguration",a}({}),HttpMethod=exports.HttpMethod=function(a){return a.Get="GET",a.Post="POST",a}({}),DataApiQuery=exports.DataApiQuery=function(a){return a[a.VisitEvent=0]="VisitEvent",a[a.VisitData=1]="VisitData",a[a.DataMap=2]="DataMap",a}({});const EVENT_TYPE_KEYS=["customData","staticData","page","conversion","geolocation","activity","experiment"],PARAMETER_KEYS=["valuesCountMap","mappingValue","id","nonce","country","environment","city","region","latitude","geolocation","longitude","mappingIdentifier","postalCode","sdkName","sdkVersion","kcs","browserIndex","browserVersion","siteCode","visitorCode","currentVisit","maxNumberPreviousVisits","customData","negative","revenue","title","os","conversion","staticData","osIndex","browser","referrersIndices","overwrite","index","href","experiment","page","variationId","deviceType","goalId","ts","key"],TRACKING_KEYS=["visit","map"],QUERY_KEYS=["sse","visitor","map","events"];let RequestType=exports.RequestType=function(a){return a.Configuration="configuration",a.Tracking="tracking",a.RemoteData="remoteData",a}({});
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["HttpMethod","exports","Get","Post","DataApiQuery","VisitEvent","VisitData","DataMap","EVENT_TYPE_KEYS","PARAMETER_KEYS","TRACKING_KEYS","QUERY_KEYS"],"sources":["../../src/requester/types.ts"],"sourcesContent":["import { JSONType } from 'src/clientConfiguration';\nimport { Environment, ExternalPackageInfoType } from 'src/types';\nimport {\n BrowserIndexMap,\n BrowserType,\n OperatingSystemType,\n} from 'src/kameleoonData';\nimport {\n DeviceType,\n KCSType,\n OperatingSystemIndexMap,\n} from 'src/kameleoonData/types';\nimport { Header } from './constants';\nimport { VisitorDataFiltersType } from 'src/utilities';\n\nexport type UrlProviderInitializeParamsType = {\n siteCode: string;\n packageInfo: ExternalPackageInfoType;\n environment?: Environment;\n};\n\nexport type RequesterParamsType = {\n siteCode: string;\n environment?: Environment;\n packageInfo: ExternalPackageInfoType;\n requestDispatcher: IExternalRequestDispatcher;\n};\n\nexport type TrackExperimentParamsType = {\n dataUrl: string;\n variationDataUrl: string;\n visitorCode: string;\n isUnallocated: boolean;\n userAgent?: string;\n isTargetedRule?: boolean;\n};\n\nexport type TrackDataParamsType = {\n visitorCode: string;\n body: string;\n userAgent?: string;\n isMappingIdentifier?: boolean;\n};\n\nexport type GetVisitorDataParamsType = {\n visitorCode: string;\n filters: VisitorDataFiltersType;\n isMappingIdentifier?: boolean;\n};\n\nexport type GetVisitorDataUrlParamsType = {\n visitorCode: string;\n filters: VisitorDataFiltersType;\n isMappingIdentifier?: boolean;\n};\n\ntype EventDataType = {\n sdk?: {\n name: string;\n version: string;\n };\n itp: boolean;\n time: number;\n};\n\ntype CustomDataEventType = {\n data: {\n index: number;\n valuesCountMap: {\n [value: string]: number;\n };\n overwrite: boolean;\n mappingIdentifier: boolean;\n };\n} & EventDataType;\n\ntype ExperimentEventType = {\n data: {\n id: number;\n variationId: number;\n };\n} & EventDataType;\n\ntype ConversionEventType = {\n data: {\n goalId: number;\n revenue: number;\n negative: boolean;\n };\n} & EventDataType;\n\ntype BrowserIndexType = (typeof BrowserIndexMap)[BrowserType];\ntype OperatingSystemIndexType =\n (typeof OperatingSystemIndexMap)[OperatingSystemType];\n\nexport type PageEventType = {\n data: {\n href: string;\n canonicalHref: string | null;\n title: string;\n keyPagesIndices: number[] | [null];\n referrerHref: string | null;\n referrersIndices: number[] | [null];\n };\n} & EventDataType;\n\nexport type GeolocationEventType = {\n data: {\n country: string;\n region: string | null;\n city: string | null;\n postalCode: string | null;\n latitude: number | null;\n longitude: number | null;\n };\n} & EventDataType;\n\nexport type StaticDataEventType = {\n data: {\n visitNumber: number;\n timeSincePreviousVisit: number;\n firstReferrerHref: string | null;\n browser: BrowserType | null;\n browserIndex: BrowserIndexType | null;\n browserVersion: number | null;\n os: OperatingSystemType | null;\n osIndex: OperatingSystemIndexType | null;\n windowWidth: number | null;\n windowHeight: number | null;\n screenWidth: number | null;\n screenHeight: number | null;\n timeZoneId: string | null;\n localeLanguageTag: string | null;\n deviceType: DeviceType | null;\n mappingIdentifier: string | null;\n };\n} & EventDataType;\n\nexport type VisitType = {\n siteCode: string;\n visitorCode: string;\n timeStarted: number;\n customDataEvents?: CustomDataEventType[];\n experimentEvents?: ExperimentEventType[];\n conversionEvents?: ConversionEventType[];\n geolocationEvents?: GeolocationEventType[];\n staticDataEvent?: StaticDataEventType;\n pageEvents?: PageEventType[];\n};\n\nexport type GetVisitorDataResultType = {\n previousVisits?: VisitType[];\n currentVisit?: VisitType;\n kcs?: KCSType;\n};\n\nexport enum HttpMethod {\n Get = 'GET',\n Post = 'POST',\n}\n\nexport enum DataApiQuery {\n VisitEvent,\n VisitData,\n DataMap,\n}\n\nconst EVENT_TYPE_KEYS = [\n 'customData',\n 'staticData',\n 'page',\n 'conversion',\n 'geolocation',\n 'activity',\n 'experiment',\n] as const;\nconst PARAMETER_KEYS = [\n 'valuesCountMap',\n 'mappingValue',\n 'id',\n 'nonce',\n 'country',\n 'environment',\n 'city',\n 'region',\n 'latitude',\n 'geolocation',\n 'longitude',\n 'mappingIdentifier',\n 'postalCode',\n 'sdkName',\n 'sdkVersion',\n 'kcs',\n 'browserIndex',\n 'browserVersion',\n 'siteCode',\n 'visitorCode',\n 'currentVisit',\n 'maxNumberPreviousVisits',\n 'customData',\n 'negative',\n 'revenue',\n 'title',\n 'os',\n 'conversion',\n 'staticData',\n 'osIndex',\n 'browser',\n 'referrersIndices',\n 'overwrite',\n 'index',\n 'href',\n 'experiment',\n 'page',\n 'variationId',\n 'deviceType',\n 'goalId',\n 'ts',\n 'key',\n] as const;\nconst TRACKING_KEYS = ['visit', 'map'] as const;\nconst QUERY_KEYS = ['sse', 'visitor', 'map', 'events'] as const;\n\nexport type TrackingType = Record<\n Capitalize<(typeof TRACKING_KEYS)[number]>,\n string\n>;\nexport type QueryType = Record<Capitalize<(typeof QUERY_KEYS)[number]>, string>;\nexport type ParameterType = Record<\n Capitalize<(typeof PARAMETER_KEYS)[number]>,\n string\n>;\nexport type EventType = Record<\n Capitalize<(typeof EVENT_TYPE_KEYS)[number]>,\n string\n>;\n\nexport type StrictTrackingRecord<T> = {\n [K in keyof T]: `${Uncapitalize<K & string>}/`;\n};\nexport type StrictQueryRecord<T> = {\n [K in keyof T]: `${Uncapitalize<K & string>}?siteCode=`;\n};\nexport type StrictEventTypeRecord<T> = {\n [K in keyof T]: `eventType=${Uncapitalize<K & string>}`;\n};\nexport type StrictParameterRecord<T> = {\n [K in keyof T]: `&${Uncapitalize<K & string>}=`;\n};\nexport type StrictFirstParameterRecord<T> = {\n [K in keyof T]: `?${Uncapitalize<K & string>}=`;\n};\n\n/**\n * @type `HeadersType` - a type of headers available in the request\n * */\nexport type HeadersType = Partial<Record<Header, string>>;\n\nexport type TrackParametersType = {\n url: string;\n headers?: HeadersType;\n body: string;\n};\n\n/**\n * @interface an interface of External Request Dispatcher which will be used to perform requests.\n * */\nexport interface IExternalRequestDispatcher {\n /**\n * @method track - send a track request\n * @param {TrackParametersType} parameters - track parameters\n * */\n track: (params: TrackParametersType) => Promise<boolean>;\n /**\n * @method getClientConfiguration - get client configuration\n * @param {string} url - url address\n * @param {HeadersType} headers - headers\n * */\n getClientConfiguration: (\n url: string,\n headers: HeadersType,\n ) => Promise<JSONType>;\n /**\n * @method getRemoteData - get data from remote server of Kameleoon\n * @param {string} url - url address\n * */\n getRemoteData: (url: string) => Promise<JSONType>;\n}\n"],"mappings":"sHA4JY,CAAAA,UAAU,CAAAC,OAAA,CAAAD,UAAA,UAAVA,CAAU,QAAV,CAAAA,CAAU,CAAAE,GAAA,OAAVF,CAAU,CAAAG,IAAA,QAAVH,CAAU,MAKVI,YAAY,CAAAH,OAAA,CAAAG,YAAA,UAAZA,CAAY,QAAZ,CAAAA,CAAY,CAAZA,CAAY,CAAAC,UAAA,iBAAZD,CAAY,CAAZA,CAAY,CAAAE,SAAA,gBAAZF,CAAY,CAAZA,CAAY,CAAAG,OAAA,cAAZH,CAAY,WAMlB,CAAAI,eAAe,CAAG,CACtB,YAAY,CACZ,YAAY,CACZ,MAAM,CACN,YAAY,CACZ,aAAa,CACb,UAAU,CACV,YAAY,CACJ,CACJC,cAAc,CAAG,CACrB,gBAAgB,CAChB,cAAc,CACd,IAAI,CACJ,OAAO,CACP,SAAS,CACT,aAAa,CACb,MAAM,CACN,QAAQ,CACR,UAAU,CACV,aAAa,CACb,WAAW,CACX,mBAAmB,CACnB,YAAY,CACZ,SAAS,CACT,YAAY,CACZ,KAAK,CACL,cAAc,CACd,gBAAgB,CAChB,UAAU,CACV,aAAa,CACb,cAAc,CACd,yBAAyB,CACzB,YAAY,CACZ,UAAU,CACV,SAAS,CACT,OAAO,CACP,IAAI,CACJ,YAAY,CACZ,YAAY,CACZ,SAAS,CACT,SAAS,CACT,kBAAkB,CAClB,WAAW,CACX,OAAO,CACP,MAAM,CACN,YAAY,CACZ,MAAM,CACN,aAAa,CACb,YAAY,CACZ,QAAQ,CACR,IAAI,CACJ,KAAK,CACG,CACJC,aAAa,CAAG,CAAC,OAAO,CAAE,KAAK,CAAU,CACzCC,UAAU,CAAG,CAAC,KAAK,CAAE,SAAS,CAAE,KAAK,CAAE,QAAQ,CAAU"}
|
|
1
|
+
{"version":3,"file":"types.js","names":["UrlType","exports","DataApi","Events","ClientConfiguration","HttpMethod","Get","Post","DataApiQuery","VisitEvent","VisitData","DataMap","EVENT_TYPE_KEYS","PARAMETER_KEYS","TRACKING_KEYS","QUERY_KEYS","RequestType","Configuration","Tracking","RemoteData"],"sources":["../../src/requester/types.ts"],"sourcesContent":["import { JSONType } from 'src/clientConfiguration';\nimport { Environment, ExternalPackageInfoType } from 'src/types';\nimport {\n BrowserIndexMap,\n BrowserType,\n OperatingSystemType,\n} from 'src/kameleoonData';\nimport {\n DeviceType,\n KCSType,\n OperatingSystemIndexMap,\n} from 'src/kameleoonData/types';\nimport { Header } from './constants';\nimport { VisitorDataFiltersType } from 'src/utilities';\n\nexport enum UrlType {\n DataApi = 'dataApi',\n Events = 'events',\n ClientConfiguration = 'clientConfiguration',\n}\n\nexport type DomainsType = {\n [key in UrlType]: DomainType;\n};\n\nexport type DomainType = {\n subdomain: string;\n topLevelDomain: string;\n secondLevelDomain: string;\n};\n\nexport type UrlProviderInitializeParamsType = {\n siteCode: string;\n domain: string | null;\n packageInfo: ExternalPackageInfoType;\n environment: Environment;\n};\n\nexport type RequesterParamsType = {\n siteCode: string;\n domain: string | null;\n environment: Environment;\n packageInfo: ExternalPackageInfoType;\n externalRequester: IExternalRequester;\n trackRetryDelay: number;\n requestTimeout: number;\n};\n\nexport type TrackExperimentParamsType = {\n dataUrl: string;\n variationDataUrl: string;\n visitorCode: string;\n isUnallocated: boolean;\n userAgent?: string;\n isTargetedRule?: boolean;\n};\n\nexport type TrackDataParamsType = {\n visitorCode: string;\n body: string;\n userAgent?: string;\n isMappingIdentifier?: boolean;\n};\n\nexport type GetVisitorDataParamsType = {\n visitorCode: string;\n filters: VisitorDataFiltersType;\n isMappingIdentifier?: boolean;\n};\n\nexport type GetVisitorDataUrlParamsType = {\n visitorCode: string;\n filters: VisitorDataFiltersType;\n isMappingIdentifier?: boolean;\n};\n\ntype EventDataType = {\n sdk?: {\n name: string;\n version: string;\n };\n itp: boolean;\n time: number;\n};\n\ntype CustomDataEventType = {\n data: {\n index: number;\n valuesCountMap: {\n [value: string]: number;\n };\n overwrite: boolean;\n mappingIdentifier: boolean;\n };\n} & EventDataType;\n\ntype ExperimentEventType = {\n data: {\n id: number;\n variationId: number;\n };\n} & EventDataType;\n\ntype ConversionEventType = {\n data: {\n goalId: number;\n revenue: number;\n negative: boolean;\n };\n} & EventDataType;\n\ntype BrowserIndexType = (typeof BrowserIndexMap)[BrowserType];\ntype OperatingSystemIndexType =\n (typeof OperatingSystemIndexMap)[OperatingSystemType];\n\nexport type PageEventType = {\n data: {\n href: string;\n canonicalHref: string | null;\n title: string;\n keyPagesIndices: number[] | [null];\n referrerHref: string | null;\n referrersIndices: number[] | [null];\n };\n} & EventDataType;\n\nexport type GeolocationEventType = {\n data: {\n country: string;\n region: string | null;\n city: string | null;\n postalCode: string | null;\n latitude: number | null;\n longitude: number | null;\n };\n} & EventDataType;\n\nexport type StaticDataEventType = {\n data: {\n visitNumber: number;\n timeSincePreviousVisit: number;\n firstReferrerHref: string | null;\n browser: BrowserType | null;\n browserIndex: BrowserIndexType | null;\n browserVersion: number | null;\n os: OperatingSystemType | null;\n osIndex: OperatingSystemIndexType | null;\n windowWidth: number | null;\n windowHeight: number | null;\n screenWidth: number | null;\n screenHeight: number | null;\n timeZoneId: string | null;\n localeLanguageTag: string | null;\n deviceType: DeviceType | null;\n mappingIdentifier: string | null;\n };\n} & EventDataType;\n\nexport type VisitType = {\n siteCode: string;\n visitorCode: string;\n timeStarted: number;\n customDataEvents?: CustomDataEventType[];\n experimentEvents?: ExperimentEventType[];\n conversionEvents?: ConversionEventType[];\n geolocationEvents?: GeolocationEventType[];\n staticDataEvent?: StaticDataEventType;\n pageEvents?: PageEventType[];\n};\n\nexport type GetVisitorDataResultType = {\n previousVisits?: VisitType[];\n currentVisit?: VisitType;\n kcs?: KCSType;\n};\n\nexport enum HttpMethod {\n Get = 'GET',\n Post = 'POST',\n}\n\nexport enum DataApiQuery {\n VisitEvent,\n VisitData,\n DataMap,\n}\n\nconst EVENT_TYPE_KEYS = [\n 'customData',\n 'staticData',\n 'page',\n 'conversion',\n 'geolocation',\n 'activity',\n 'experiment',\n] as const;\nconst PARAMETER_KEYS = [\n 'valuesCountMap',\n 'mappingValue',\n 'id',\n 'nonce',\n 'country',\n 'environment',\n 'city',\n 'region',\n 'latitude',\n 'geolocation',\n 'longitude',\n 'mappingIdentifier',\n 'postalCode',\n 'sdkName',\n 'sdkVersion',\n 'kcs',\n 'browserIndex',\n 'browserVersion',\n 'siteCode',\n 'visitorCode',\n 'currentVisit',\n 'maxNumberPreviousVisits',\n 'customData',\n 'negative',\n 'revenue',\n 'title',\n 'os',\n 'conversion',\n 'staticData',\n 'osIndex',\n 'browser',\n 'referrersIndices',\n 'overwrite',\n 'index',\n 'href',\n 'experiment',\n 'page',\n 'variationId',\n 'deviceType',\n 'goalId',\n 'ts',\n 'key',\n] as const;\nconst TRACKING_KEYS = ['visit', 'map'] as const;\nconst QUERY_KEYS = ['sse', 'visitor', 'map', 'events'] as const;\n\nexport type TrackingType = Record<\n Capitalize<(typeof TRACKING_KEYS)[number]>,\n string\n>;\nexport type QueryType = Record<Capitalize<(typeof QUERY_KEYS)[number]>, string>;\nexport type ParameterType = Record<\n Capitalize<(typeof PARAMETER_KEYS)[number]>,\n string\n>;\nexport type EventType = Record<\n Capitalize<(typeof EVENT_TYPE_KEYS)[number]>,\n string\n>;\n\nexport type StrictTrackingRecord<T> = {\n [K in keyof T]: `${Uncapitalize<K & string>}/`;\n};\nexport type StrictQueryRecord<T> = {\n [K in keyof T]: `${Uncapitalize<K & string>}?siteCode=`;\n};\nexport type StrictEventTypeRecord<T> = {\n [K in keyof T]: `eventType=${Uncapitalize<K & string>}`;\n};\nexport type StrictParameterRecord<T> = {\n [K in keyof T]: `&${Uncapitalize<K & string>}=`;\n};\nexport type StrictFirstParameterRecord<T> = {\n [K in keyof T]: `?${Uncapitalize<K & string>}=`;\n};\n\n/**\n * @type `HeadersType` - a type of headers available in the request\n * */\nexport type HeadersType = Partial<Record<Header, string>>;\n\nexport type TrackParametersType = {\n url: string;\n headers?: HeadersType;\n body: string;\n};\n\n/**\n * @type `RequestParametersType` - a type of parameters available in the request for each request type\n * */\nexport type RequestParametersType = {\n [RequestType.Configuration]: {\n headers?: HeadersType;\n signal: AbortSignal | null;\n method: HttpMethod.Get;\n };\n [RequestType.Tracking]: {\n headers?: HeadersType;\n body: string;\n signal: AbortSignal | null;\n method: HttpMethod.Post;\n };\n [RequestType.RemoteData]: {\n signal: AbortSignal | null;\n method: HttpMethod.Get;\n };\n};\n\n/**\n * @enum `RequestType` - an enum of available request types\n * */\nexport enum RequestType {\n Configuration = 'configuration',\n Tracking = 'tracking',\n RemoteData = 'remoteData',\n}\n\n/**\n * @type `RetryCountType` - a type of retry count available for each request type\n * @param {0 | 1 | 2} `RequestType.Configuration` - a count of retries for configuration request (`0` is the initial request)\n * @param {0 | 1 | 2} `RequestType.Tracking` - a count of retries for tracking request (`0` is the initial request)\n * @param {0} `RequestType.RemoteData` - a count of retries for remote data request (`0` is the initial request)\n * */\nexport type RetryCountType = {\n [RequestType.Configuration]: 0 | 1 | 2;\n [RequestType.Tracking]: 0 | 1 | 2;\n [RequestType.RemoteData]: 0;\n};\n\n/**\n * @type `SendRequestParametersType` - a type of parameters available to send a request\n * @param {T extends RequestType} T - a type of request constrained by `RequestType`\n * @param {string} url - url address\n * @param {RequestParametersType[T]} parameters - parameters of the request depending on the request type\n * @param {RetryCountType | undefined} retryCount - a count of retries, the possible count of retries depends on `RequestType`\n * */\nexport type SendRequestParametersType<T extends RequestType> = {\n requestType: T;\n url: string;\n retryCount?: RetryCountType[T];\n parameters: RequestParametersType[T];\n};\n\n/**\n * @type `KameleoonResponse` - a type of response that is assignable to most libraries `Response` objects\n * @property {number} status - a status of the response\n * @property {() => Promise<JSONType>} json - a method to parse the response to JSON\n * @property {boolean} ok - a boolean value that indicates if the response is ok\n * */\nexport type KameleoonResponseType = {\n status: number;\n json: () => Promise<JSONType>;\n ok: boolean;\n};\n\nexport type InternalSendRequestParametersType = {\n requestType: RequestType;\n url: string;\n retryCount: number;\n headers?: HeadersType;\n body?: string;\n};\n\n/**\n * @interface `IExternalRequester` - an interface of External Requester which will be used to perform requests.\n * */\nexport interface IExternalRequester {\n /**\n * @method sendRequest - send a request\n * @param {SendRequestParametersType<T>} parameters - parameters of the request depending on the request type\n * @returns {Promise<KameleoonResponseType>} - a promise that resolves to the response\n * */\n sendRequest: <T extends RequestType>({\n requestType,\n url,\n parameters,\n }: SendRequestParametersType<T>) => Promise<KameleoonResponseType>;\n}\n"],"mappings":"0JAeY,CAAAA,OAAO,CAAAC,OAAA,CAAAD,OAAA,UAAPA,CAAO,QAAP,CAAAA,CAAO,CAAAE,OAAA,WAAPF,CAAO,CAAAG,MAAA,UAAPH,CAAO,CAAAI,mBAAA,uBAAPJ,CAAO,MAiKPK,UAAU,CAAAJ,OAAA,CAAAI,UAAA,UAAVA,CAAU,QAAV,CAAAA,CAAU,CAAAC,GAAA,OAAVD,CAAU,CAAAE,IAAA,QAAVF,CAAU,MAKVG,YAAY,CAAAP,OAAA,CAAAO,YAAA,UAAZA,CAAY,QAAZ,CAAAA,CAAY,CAAZA,CAAY,CAAAC,UAAA,iBAAZD,CAAY,CAAZA,CAAY,CAAAE,SAAA,gBAAZF,CAAY,CAAZA,CAAY,CAAAG,OAAA,cAAZH,CAAY,WAMlB,CAAAI,eAAe,CAAG,CACtB,YAAY,CACZ,YAAY,CACZ,MAAM,CACN,YAAY,CACZ,aAAa,CACb,UAAU,CACV,YAAY,CACJ,CACJC,cAAc,CAAG,CACrB,gBAAgB,CAChB,cAAc,CACd,IAAI,CACJ,OAAO,CACP,SAAS,CACT,aAAa,CACb,MAAM,CACN,QAAQ,CACR,UAAU,CACV,aAAa,CACb,WAAW,CACX,mBAAmB,CACnB,YAAY,CACZ,SAAS,CACT,YAAY,CACZ,KAAK,CACL,cAAc,CACd,gBAAgB,CAChB,UAAU,CACV,aAAa,CACb,cAAc,CACd,yBAAyB,CACzB,YAAY,CACZ,UAAU,CACV,SAAS,CACT,OAAO,CACP,IAAI,CACJ,YAAY,CACZ,YAAY,CACZ,SAAS,CACT,SAAS,CACT,kBAAkB,CAClB,WAAW,CACX,OAAO,CACP,MAAM,CACN,YAAY,CACZ,MAAM,CACN,aAAa,CACb,YAAY,CACZ,QAAQ,CACR,IAAI,CACJ,KAAK,CACG,CACJC,aAAa,CAAG,CAAC,OAAO,CAAE,KAAK,CAAU,CACzCC,UAAU,CAAG,CAAC,KAAK,CAAE,SAAS,CAAE,KAAK,CAAE,QAAQ,CAAU,IAmEnD,CAAAC,WAAW,CAAAf,OAAA,CAAAe,WAAA,UAAXA,CAAW,QAAX,CAAAA,CAAW,CAAAC,aAAA,iBAAXD,CAAW,CAAAE,QAAA,YAAXF,CAAW,CAAAG,UAAA,cAAXH,CAAW"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { GetVisitorDataUrlParamsType, UrlProviderInitializeParamsType } from './types';
|
|
2
2
|
export declare class UrlProvider {
|
|
3
|
-
private static siteCode;
|
|
4
|
-
private static environment?;
|
|
5
3
|
private static ready;
|
|
4
|
+
private static siteCode;
|
|
5
|
+
private static isCustomDomain;
|
|
6
|
+
private static environment;
|
|
6
7
|
private static packageInfo;
|
|
7
|
-
private static
|
|
8
|
-
static dataApiTopLevelDomain
|
|
9
|
-
static initialize({ siteCode, packageInfo, environment, }: UrlProviderInitializeParamsType): void;
|
|
8
|
+
private static domains;
|
|
9
|
+
static dataApiTopLevelDomain?: string;
|
|
10
|
+
static initialize({ siteCode, domain, packageInfo, environment, }: UrlProviderInitializeParamsType): void;
|
|
10
11
|
static setDataApiDomain(domain: string): void;
|
|
11
12
|
static getClientConfigurationUrl(timeStamp?: number): string;
|
|
13
|
+
static getEventSourceUrl(): string;
|
|
12
14
|
static getRemoteDataUrl(key: string): string;
|
|
13
15
|
static getVisitorDataUrl({ visitorCode, filters, isMappingIdentifier, }: GetVisitorDataUrlParamsType): string;
|
|
14
16
|
static getTrackingUrl(visitorCode: string, isMappingIdentifier?: boolean): string;
|
|
15
17
|
private static isInitialized;
|
|
16
18
|
private static getDataApiUrl;
|
|
19
|
+
private static setDomains;
|
|
17
20
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlProvider=void 0;var _constants=require("./constants"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlProvider=void 0;var _types=require("../types"),_constants=require("./constants"),_types2=require("./types");function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class UrlProvider{static initialize(a){let{siteCode:b,domain:c,packageInfo:d,environment:e}=a;this.siteCode=b,this.environment=e,this.packageInfo=d,this.ready=!0,this.setDomains(c)}static setDataApiDomain(a){var b;if(!this.isCustomDomain){const c=a.split(".");if(3===c.length){const[a,d,e]=c;this.domains[_types2.UrlType.DataApi]={subdomain:a,secondLevelDomain:d,topLevelDomain:null!==(b=this.dataApiTopLevelDomain)&&void 0!==b?b:e}}}}static getClientConfigurationUrl(a){this.isInitialized();const{subdomain:b,topLevelDomain:c,secondLevelDomain:d}=this.domains[_types2.UrlType.ClientConfiguration],e="https://".concat(b,".").concat(d,".").concat(c,"/"),f=this.environment===_types.Environment.Production?"":_constants.UrlFirstParameter.Environment+this.environment;let g="";return a&&(f?g=_constants.UrlParameter.Ts+a:g=_constants.UrlFirstParameter.Ts+a),e+this.siteCode+f+g}static getEventSourceUrl(){this.isInitialized();const{subdomain:a,topLevelDomain:b,secondLevelDomain:c}=this.domains[_types2.UrlType.Events];return"https://".concat(a,".").concat(c,".").concat(b,":8110/").concat(_constants.UrlQuery.Sse).concat(this.siteCode)}static getRemoteDataUrl(a){return this.isInitialized(),this.getDataApiUrl(_types2.DataApiQuery.DataMap)+this.siteCode+_constants.UrlParameter.Key+encodeURI(a)}static getVisitorDataUrl(a){let{visitorCode:b,filters:c,isMappingIdentifier:d}=a;this.isInitialized();const{customData:e,previousVisitAmount:f,currentVisit:g,conversions:h,geolocation:i,experiments:j,pageViews:k,device:l,browser:m,operatingSystem:n,kcs:o}=c,p=d?_constants.UrlParameter.MappingValue:_constants.UrlParameter.VisitorCode,q=e?_constants.UrlParameter.CustomData+!0:"",r=h?_constants.UrlParameter.Conversion+!0:"",s=i?_constants.UrlParameter.Geolocation+!0:"",t=j?_constants.UrlParameter.Experiment+!0:"",u=k?_constants.UrlParameter.Page+!0:"",v=!!(l||m||n)?_constants.UrlParameter.StaticData+!0:"",w=g?_constants.UrlParameter.CurrentVisit+!0:"",x=o?_constants.UrlParameter.Kcs+!0:"",y="number"==typeof f?_constants.UrlParameter.MaxNumberPreviousVisits+f:_constants.UrlParameter.MaxNumberPreviousVisits+1;return this.getDataApiUrl(_types2.DataApiQuery.VisitData)+this.siteCode+p+b+y+q+r+s+t+u+v+w+x}static getTrackingUrl(a,b){this.isInitialized();const{type:c,version:d}=this.packageInfo,e=b?_constants.UrlParameter.MappingValue:_constants.UrlParameter.VisitorCode;return this.getDataApiUrl(_types2.DataApiQuery.VisitEvent)+this.siteCode+e+a+_constants.UrlParameter.SdkName+c.toLowerCase()+_constants.UrlParameter.SdkVersion+d}static isInitialized(){if(!this.ready)throw new Error("UrlProvider is not initialized")}static getDataApiUrl(a){const{subdomain:b,topLevelDomain:c,secondLevelDomain:d}=this.domains[_types2.UrlType.DataApi];if(!b||!c||!d)throw new Error("Data API domain is not set");const e="https://".concat(b,".").concat(d,".").concat(c);return a===_types2.DataApiQuery.VisitEvent?"".concat(e,"/").concat(_constants.UrlTracking.Visit+_constants.UrlQuery.Events):a===_types2.DataApiQuery.VisitData?"".concat(e,"/").concat(_constants.UrlTracking.Visit+_constants.UrlQuery.Visitor):a===_types2.DataApiQuery.DataMap?"".concat(e,"/").concat(_constants.UrlTracking.Map+_constants.UrlQuery.Map):void 0}static setDomains(a){if(!a)return;this.isCustomDomain=!0;const b=a.split("."),[c,d]=b,e={secondLevelDomain:c,topLevelDomain:d};this.domains={[_types2.UrlType.DataApi]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.DataApi]),e),[_types2.UrlType.Events]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.Events]),e),[_types2.UrlType.ClientConfiguration]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.ClientConfiguration]),e)}}}exports.UrlProvider=UrlProvider,_defineProperty(UrlProvider,"ready",!1),_defineProperty(UrlProvider,"siteCode",void 0),_defineProperty(UrlProvider,"isCustomDomain",!1),_defineProperty(UrlProvider,"environment",void 0),_defineProperty(UrlProvider,"packageInfo",void 0),_defineProperty(UrlProvider,"domains",{[_types2.UrlType.DataApi]:{subdomain:"data",topLevelDomain:"io",secondLevelDomain:"kameleoon"},[_types2.UrlType.Events]:{subdomain:"events",topLevelDomain:"com",secondLevelDomain:"kameleoon"},[_types2.UrlType.ClientConfiguration]:{subdomain:"sdk-config",topLevelDomain:"eu",secondLevelDomain:"kameleoon"}}),_defineProperty(UrlProvider,"dataApiTopLevelDomain",void 0);
|
|
2
2
|
//# sourceMappingURL=urlProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlProvider.js","names":["UrlProvider","initialize","a","siteCode","packageInfo","environment","ready","setDataApiDomain","domain","dataApiDomain","split","slice","join","getClientConfigurationUrl","timeStamp","isInitialized","environmentParam","UrlFirstParameter","Environment","timeStampParam","UrlParameter","Ts","URL","CLIENT_CONFIGURATION","getRemoteDataUrl","key","getDataApiUrl","DataApiQuery","DataMap","Key","encodeURI","getVisitorDataUrl","visitorCode","filters","isMappingIdentifier","customData","previousVisitAmount","currentVisit","conversions","geolocation","experiments","pageViews","device","browser","operatingSystem","kcs","identifierParameter","MappingValue","VisitorCode","customDataParameter","CustomData","conversionsParameter","Conversion","geolocationParameter","Geolocation","experimentsParameter","Experiment","pageViewsParameter","Page","staticDataParameter","StaticData","currentVisitParameter","CurrentVisit","kcsParameter","Kcs","previousVisitAmountParam","MaxNumberPreviousVisits","VisitData","getTrackingUrl","type","version","VisitEvent","SdkName","toLowerCase","SdkVersion","Error","query","concat","dataApiTopLevelDomain","UrlTracking","Visit","UrlQuery","Events","Visitor","Map","exports","_defineProperty"],"sources":["../../src/requester/urlProvider.ts"],"sourcesContent":["import { Environment, ExternalPackageInfoType } from 'src/types';\nimport {\n UrlFirstParameter,\n UrlParameter,\n URL,\n UrlTracking,\n UrlQuery,\n} from './constants';\nimport {\n DataApiQuery,\n GetVisitorDataUrlParamsType,\n UrlProviderInitializeParamsType,\n} from './types';\n\n// TODO: To be removed in favour of `DependencyManager`\n// which will use protected `KameleoonClient` method to be able to mock every dependency\n// for tests\nexport class UrlProvider {\n private static siteCode: string;\n private static environment?: Environment;\n private static ready = false;\n private static packageInfo: ExternalPackageInfoType;\n private static dataApiDomain = 'data.kameleoon';\n\n public static dataApiTopLevelDomain = '.io';\n\n public static initialize({\n siteCode,\n packageInfo,\n environment,\n }: UrlProviderInitializeParamsType): void {\n this.siteCode = siteCode;\n this.environment = environment;\n this.packageInfo = packageInfo;\n this.ready = true;\n }\n\n public static setDataApiDomain(domain: string): void {\n this.dataApiDomain = domain.split('.').slice(0, -1).join('.');\n }\n\n public static getClientConfigurationUrl(timeStamp?: number): string {\n this.isInitialized();\n\n const environmentParam = this.environment\n ? UrlFirstParameter.Environment + this.environment\n : '';\n let timeStampParam = '';\n\n if (timeStamp) {\n if (environmentParam) {\n timeStampParam = UrlParameter.Ts + timeStamp;\n } else {\n timeStampParam = UrlFirstParameter.Ts + timeStamp;\n }\n }\n\n return (\n URL.CLIENT_CONFIGURATION +\n this.siteCode +\n environmentParam +\n timeStampParam\n );\n }\n\n public static getRemoteDataUrl(key: string): string {\n this.isInitialized();\n\n return (\n this.getDataApiUrl(DataApiQuery.DataMap) +\n this.siteCode +\n UrlParameter.Key +\n encodeURI(key)\n );\n }\n\n public static getVisitorDataUrl({\n visitorCode,\n filters,\n isMappingIdentifier,\n }: GetVisitorDataUrlParamsType): string {\n const {\n customData,\n previousVisitAmount,\n currentVisit,\n conversions,\n geolocation,\n experiments,\n pageViews,\n device,\n browser,\n operatingSystem,\n kcs,\n } = filters;\n\n const identifierParameter = isMappingIdentifier\n ? UrlParameter.MappingValue\n : UrlParameter.VisitorCode;\n\n const customDataParameter = customData\n ? UrlParameter.CustomData + true\n : '';\n const conversionsParameter = conversions\n ? UrlParameter.Conversion + true\n : '';\n const geolocationParameter = geolocation\n ? UrlParameter.Geolocation + true\n : '';\n const experimentsParameter = experiments\n ? UrlParameter.Experiment + true\n : '';\n const pageViewsParameter = pageViews ? UrlParameter.Page + true : '';\n const staticDataParameter = Boolean(device || browser || operatingSystem)\n ? UrlParameter.StaticData + true\n : '';\n const currentVisitParameter = currentVisit\n ? UrlParameter.CurrentVisit + true\n : '';\n\n // --- Note ---\n // `kcs` parameter requires `currentVisit=true`\n let kcsParameter = '';\n\n if (kcs) {\n kcsParameter = UrlParameter.Kcs + true;\n\n if (!currentVisitParameter) {\n kcsParameter += UrlParameter.CurrentVisit + true;\n }\n }\n\n const previousVisitAmountParam =\n typeof previousVisitAmount !== 'number'\n ? UrlParameter.MaxNumberPreviousVisits + 1\n : UrlParameter.MaxNumberPreviousVisits + previousVisitAmount;\n\n return (\n this.getDataApiUrl(DataApiQuery.VisitData) +\n this.siteCode +\n identifierParameter +\n visitorCode +\n previousVisitAmountParam +\n customDataParameter +\n conversionsParameter +\n geolocationParameter +\n experimentsParameter +\n pageViewsParameter +\n staticDataParameter +\n currentVisitParameter +\n kcsParameter\n );\n }\n\n public static getTrackingUrl(\n visitorCode: string,\n isMappingIdentifier?: boolean,\n ): string {\n this.isInitialized();\n\n const { type, version } = this.packageInfo;\n\n const identifierParameter = isMappingIdentifier\n ? UrlParameter.MappingValue\n : UrlParameter.VisitorCode;\n\n return (\n this.getDataApiUrl(DataApiQuery.VisitEvent) +\n this.siteCode +\n identifierParameter +\n visitorCode +\n UrlParameter.SdkName +\n type.toLowerCase() +\n UrlParameter.SdkVersion +\n version\n );\n }\n\n private static isInitialized(): void {\n if (!this.ready) {\n throw new Error('UrlProvider is not initialized');\n }\n }\n\n private static getDataApiUrl(query: DataApiQuery): string {\n const domain = `https://${this.dataApiDomain}${this.dataApiTopLevelDomain}`;\n\n switch (query) {\n case DataApiQuery.VisitEvent:\n return `${domain}/${UrlTracking.Visit + UrlQuery.Events}`;\n case DataApiQuery.VisitData:\n return `${domain}/${UrlTracking.Visit + UrlQuery.Visitor}`;\n case DataApiQuery.DataMap:\n return `${domain}/${UrlTracking.Map + UrlQuery.Map}`;\n }\n }\n}\n"],"mappings":"kqBAiBO,KAAM,CAAAA,WAAY,CASvB,MAAc,CAAAC,UAAUA,CAAAC,CAAA,CAIkB,IAJjB,CACvBC,QAAQ,CAARA,CAAQ,CACRC,WAAW,CAAXA,CAAW,CACXC,WAAW,CAAXA,CAC+B,CAAC,CAAAH,CAAA,CAChC,IAAI,CAACC,QAAQ,CAAGA,CAAQ,CACxB,IAAI,CAACE,WAAW,CAAGA,CAAW,CAC9B,IAAI,CAACD,WAAW,CAAGA,CAAW,CAC9B,IAAI,CAACE,KAAK,GACZ,CAEA,MAAc,CAAAC,gBAAgBA,CAACC,CAAc,CAAQ,CACnD,IAAI,CAACC,aAAa,CAAGD,CAAM,CAACE,KAAK,CAAC,GAAG,CAAC,CAACC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,GAAG,C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eAAA,CAlLYtF,WAAW,oBAAAsF,eAAA,CAAXtF,WAAW,uBAAAsF,eAAA,CAAXtF,WAAW,aAAAsF,eAAA,CAAXtF,WAAW,uBAAAsF,eAAA,CAAXtF,WAAW,iBAKS,gBAAgB,EAAAsF,eAAA,CALpCtF,WAAW,yBAOgB,KAAK"}
|
|
1
|
+
{"version":3,"file":"urlProvider.js","names":["UrlProvider","initialize","a","siteCode","domain","packageInfo","environment","ready","setDomains","setDataApiDomain","b","isCustomDomain","parts","split","length","subdomain","secondLevelDomain","topLevelDomain","domains","UrlType","DataApi","dataApiTopLevelDomain","getClientConfigurationUrl","timeStamp","isInitialized","ClientConfiguration","baseUrl","concat","environmentParam","Environment","Production","UrlFirstParameter","timeStampParam","UrlParameter","Ts","getEventSourceUrl","Events","UrlQuery","Sse","getRemoteDataUrl","key","getDataApiUrl","DataApiQuery","DataMap","Key","encodeURI","getVisitorDataUrl","visitorCode","filters","isMappingIdentifier","customData","previousVisitAmount","currentVisit","conversions","geolocation","experiments","pageViews","device","browser","operatingSystem","kcs","identifierParameter","MappingValue","VisitorCode","customDataParameter","CustomData","conversionsParameter","Conversion","geolocationParameter","Geolocation","experimentsParameter","Experiment","pageViewsParameter","Page","staticDataParameter","StaticData","currentVisitParameter","CurrentVisit","kcsParameter","Kcs","previousVisitAmountParam","MaxNumberPreviousVisits","VisitData","getTrackingUrl","type","version","VisitEvent","SdkName","toLowerCase","SdkVersion","Error","query","UrlTracking","Visit","Visitor","Map","domainData","_objectSpread","exports","_defineProperty"],"sources":["../../src/requester/urlProvider.ts"],"sourcesContent":["import { Environment, ExternalPackageInfoType } from 'src/types';\nimport {\n UrlFirstParameter,\n UrlParameter,\n UrlTracking,\n UrlQuery,\n} from './constants';\nimport {\n DataApiQuery,\n DomainsType,\n GetVisitorDataUrlParamsType,\n UrlProviderInitializeParamsType,\n UrlType,\n} from './types';\n\n// TODO: To be removed in favour of `DependencyManager`\n// which will use protected `KameleoonClient` method to be able to mock every dependency\n// for tests\nexport class UrlProvider {\n private static ready = false;\n private static siteCode: string;\n private static isCustomDomain = false;\n private static environment: Environment;\n private static packageInfo: ExternalPackageInfoType;\n private static domains: DomainsType = {\n [UrlType.DataApi]: {\n subdomain: 'data',\n topLevelDomain: 'io',\n secondLevelDomain: 'kameleoon',\n },\n [UrlType.Events]: {\n subdomain: 'events',\n topLevelDomain: 'com',\n secondLevelDomain: 'kameleoon',\n },\n [UrlType.ClientConfiguration]: {\n subdomain: 'sdk-config',\n topLevelDomain: 'eu',\n secondLevelDomain: 'kameleoon',\n },\n };\n\n // --- Note ---\n // Dirty workaround before the `DependencyManager` implementation\n // see a note above\n public static dataApiTopLevelDomain?: string;\n\n public static initialize({\n siteCode,\n domain,\n packageInfo,\n environment,\n }: UrlProviderInitializeParamsType) {\n this.siteCode = siteCode;\n this.environment = environment;\n this.packageInfo = packageInfo;\n this.ready = true;\n\n this.setDomains(domain);\n }\n\n public static setDataApiDomain(domain: string): void {\n if (this.isCustomDomain) {\n return;\n }\n\n const parts = domain.split('.');\n\n if (parts.length !== 3) {\n return;\n }\n\n const [subdomain, secondLevelDomain, topLevelDomain] = parts;\n\n this.domains[UrlType.DataApi] = {\n subdomain,\n secondLevelDomain,\n topLevelDomain: this.dataApiTopLevelDomain ?? topLevelDomain,\n };\n }\n\n public static getClientConfigurationUrl(timeStamp?: number): string {\n this.isInitialized();\n\n const { subdomain, topLevelDomain, secondLevelDomain } =\n this.domains[UrlType.ClientConfiguration];\n\n const baseUrl = `https://${subdomain}.${secondLevelDomain}.${topLevelDomain}/`;\n const environmentParam =\n this.environment === Environment.Production\n ? ''\n : UrlFirstParameter.Environment + this.environment;\n let timeStampParam = '';\n\n if (timeStamp) {\n if (environmentParam) {\n timeStampParam = UrlParameter.Ts + timeStamp;\n } else {\n timeStampParam = UrlFirstParameter.Ts + timeStamp;\n }\n }\n\n return baseUrl + this.siteCode + environmentParam + timeStampParam;\n }\n\n public static getEventSourceUrl(): string {\n this.isInitialized();\n\n const { subdomain, topLevelDomain, secondLevelDomain } =\n this.domains[UrlType.Events];\n\n return `https://${subdomain}.${secondLevelDomain}.${topLevelDomain}:8110/${UrlQuery.Sse}${this.siteCode}`;\n }\n\n public static getRemoteDataUrl(key: string): string {\n this.isInitialized();\n\n return (\n this.getDataApiUrl(DataApiQuery.DataMap) +\n this.siteCode +\n UrlParameter.Key +\n encodeURI(key)\n );\n }\n\n public static getVisitorDataUrl({\n visitorCode,\n filters,\n isMappingIdentifier,\n }: GetVisitorDataUrlParamsType): string {\n this.isInitialized();\n\n const {\n customData,\n previousVisitAmount,\n currentVisit,\n conversions,\n geolocation,\n experiments,\n pageViews,\n device,\n browser,\n operatingSystem,\n kcs,\n } = filters;\n\n const identifierParameter = isMappingIdentifier\n ? UrlParameter.MappingValue\n : UrlParameter.VisitorCode;\n const customDataParameter = customData\n ? UrlParameter.CustomData + true\n : '';\n const conversionsParameter = conversions\n ? UrlParameter.Conversion + true\n : '';\n const geolocationParameter = geolocation\n ? UrlParameter.Geolocation + true\n : '';\n const experimentsParameter = experiments\n ? UrlParameter.Experiment + true\n : '';\n const pageViewsParameter = pageViews ? UrlParameter.Page + true : '';\n const staticDataParameter = Boolean(device || browser || operatingSystem)\n ? UrlParameter.StaticData + true\n : '';\n const currentVisitParameter = currentVisit\n ? UrlParameter.CurrentVisit + true\n : '';\n const kcsParameter = kcs ? UrlParameter.Kcs + true : '';\n const previousVisitAmountParam =\n typeof previousVisitAmount !== 'number'\n ? UrlParameter.MaxNumberPreviousVisits + 1\n : UrlParameter.MaxNumberPreviousVisits + previousVisitAmount;\n\n return (\n this.getDataApiUrl(DataApiQuery.VisitData) +\n this.siteCode +\n identifierParameter +\n visitorCode +\n previousVisitAmountParam +\n customDataParameter +\n conversionsParameter +\n geolocationParameter +\n experimentsParameter +\n pageViewsParameter +\n staticDataParameter +\n currentVisitParameter +\n kcsParameter\n );\n }\n\n public static getTrackingUrl(\n visitorCode: string,\n isMappingIdentifier?: boolean,\n ): string {\n this.isInitialized();\n\n const { type, version } = this.packageInfo;\n\n const identifierParameter = isMappingIdentifier\n ? UrlParameter.MappingValue\n : UrlParameter.VisitorCode;\n\n return (\n this.getDataApiUrl(DataApiQuery.VisitEvent) +\n this.siteCode +\n identifierParameter +\n visitorCode +\n UrlParameter.SdkName +\n type.toLowerCase() +\n UrlParameter.SdkVersion +\n version\n );\n }\n\n private static isInitialized(): void {\n if (!this.ready) {\n throw new Error('UrlProvider is not initialized');\n }\n }\n\n private static getDataApiUrl(query: DataApiQuery): string {\n const { subdomain, topLevelDomain, secondLevelDomain } =\n this.domains[UrlType.DataApi];\n\n if (!subdomain || !topLevelDomain || !secondLevelDomain) {\n throw new Error('Data API domain is not set');\n }\n\n const domain = `https://${subdomain}.${secondLevelDomain}.${topLevelDomain}`;\n\n switch (query) {\n case DataApiQuery.VisitEvent:\n return `${domain}/${UrlTracking.Visit + UrlQuery.Events}`;\n case DataApiQuery.VisitData:\n return `${domain}/${UrlTracking.Visit + UrlQuery.Visitor}`;\n case DataApiQuery.DataMap:\n return `${domain}/${UrlTracking.Map + UrlQuery.Map}`;\n }\n }\n\n private static setDomains(domain: string | null): void {\n if (!domain) {\n return;\n }\n\n this.isCustomDomain = true;\n\n const parts = domain.split('.');\n\n const [secondLevelDomain, topLevelDomain] = parts;\n\n const domainData = {\n secondLevelDomain,\n topLevelDomain,\n };\n\n this.domains = {\n [UrlType.DataApi]: {\n ...this.domains[UrlType.DataApi],\n ...domainData,\n },\n [UrlType.Events]: {\n ...this.domains[UrlType.Events],\n ...domainData,\n },\n [UrlType.ClientConfiguration]: {\n ...this.domains[UrlType.ClientConfiguration],\n ...domainData,\n },\n };\n }\n}\n"],"mappings":"gyCAkBO,KAAM,CAAAA,WAAY,CA6BvB,MAAc,CAAAC,UAAUA,CAAAC,CAAA,CAKY,IALX,CACvBC,QAAQ,CAARA,CAAQ,CACRC,MAAM,CAANA,CAAM,CACNC,WAAW,CAAXA,CAAW,CACXC,WAAW,CAAXA,CAC+B,CAAC,CAAAJ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,eAAA,CAAXnG,WAAW,uBAAAmG,eAAA,CAAXnG,WAAW,WAMgB,CACpC,CAACmB,eAAO,CAACC,OAAO,EAAG,CACjBL,SAAS,CAAE,MAAM,CACjBE,cAAc,CAAE,IAAI,CACpBD,iBAAiB,CAAE,WACrB,CAAC,CACD,CAACG,eAAO,CAACiB,MAAM,EAAG,CAChBrB,SAAS,CAAE,QAAQ,CACnBE,cAAc,CAAE,KAAK,CACrBD,iBAAiB,CAAE,WACrB,CAAC,CACD,CAACG,eAAO,CAACM,mBAAmB,EAAG,CAC7BV,SAAS,CAAE,YAAY,CACvBE,cAAc,CAAE,IAAI,CACpBD,iBAAiB,CAAE,WACrB,CACF,CAAC,EAAAmF,eAAA,CAtBUnG,WAAW"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ConfigurationDataType, JSONType } from './clientConfiguration/types';
|
|
1
|
+
import { ClientConfigurationDataType, ConfigurationDataType, JSONType } from './clientConfiguration/types';
|
|
2
2
|
import { SdkLanguageType } from './constants';
|
|
3
3
|
import { IExternalEventSource } from './eventSource';
|
|
4
|
-
import {
|
|
4
|
+
import { IExternalRequester, RequestType } from './requester';
|
|
5
5
|
import { IExternalStorage } from './storage';
|
|
6
6
|
import { VisitorDataFiltersType } from './utilities';
|
|
7
7
|
import { IVisitorCodeManager } from './visitorCodeManager';
|
|
@@ -19,7 +19,9 @@ import { IVisitorCodeManager } from './visitorCodeManager';
|
|
|
19
19
|
* - React/React Native SDK: `undefined` (no cleanup)
|
|
20
20
|
* - NodeJS SDK: `30`
|
|
21
21
|
*
|
|
22
|
-
* @param {string | undefined} domain - domain which cookie belongs to
|
|
22
|
+
* @param {string | undefined} domain - domain which cookie which Kameleoon visitor code belongs to. Note: parameter `domain` is deprecated and will be removed in the next major update, use `cookieDomain` instead
|
|
23
|
+
* @param {string | undefined} cookieDomain - domain which cookie which Kameleoon visitor code belongs to
|
|
24
|
+
* @param {string | undefined} networkDomain - custom domain to be used in place of all requests URL, domain format is `example.com`, if the format is incorrect, default Kameleoon domain will be used
|
|
23
25
|
* @param {number | undefined} requestTimeout - timeout in _milliseconds_ for requests
|
|
24
26
|
* @defaultvalue `10_000` (10 seconds)
|
|
25
27
|
* */
|
|
@@ -29,6 +31,8 @@ export type SDKConfigurationType = {
|
|
|
29
31
|
targetingDataCleanupInterval?: number;
|
|
30
32
|
requestTimeout?: number;
|
|
31
33
|
domain?: string;
|
|
34
|
+
networkDomain?: string;
|
|
35
|
+
cookieDomain?: string;
|
|
32
36
|
};
|
|
33
37
|
/**
|
|
34
38
|
* @param {string} siteCode - client's siteCode defined on Kameleoon platform
|
|
@@ -53,7 +57,7 @@ export type ExternalPackageInfoType = {
|
|
|
53
57
|
* @param {IExternalEventSourceConstructor | undefined} externalEventSource - constructor for building external event source implementation
|
|
54
58
|
* @param {ExternalPackageInfoType} externalPackageInfo - external package info, used to get package version and name
|
|
55
59
|
* @param {ConfigurationDataType} externalClientConfiguration - external fetched client configuration
|
|
56
|
-
* @param {
|
|
60
|
+
* @param {IExternalRequester} externalRequester - external requester , used to track or get data
|
|
57
61
|
* @param {IVisitorCodeManager} externalVisitorCodeManager - external visitor code manager, used to get or generate visitor code
|
|
58
62
|
* @param {number} targetingDataCleanupInterval - interval in *minutes* for cleaning up targeting data, minimum value is 1 minute
|
|
59
63
|
* */
|
|
@@ -62,7 +66,7 @@ export type InternalSDKConfigurationType = {
|
|
|
62
66
|
externalEventSource: IExternalEventSource;
|
|
63
67
|
externalVisitorCodeManager: IVisitorCodeManager;
|
|
64
68
|
externalPackageInfo: ExternalPackageInfoType;
|
|
65
|
-
|
|
69
|
+
externalRequester: IExternalRequester;
|
|
66
70
|
externalClientConfiguration?: ConfigurationDataType;
|
|
67
71
|
};
|
|
68
72
|
/**
|
|
@@ -223,3 +227,11 @@ export type SetUserConsentParametersType = {
|
|
|
223
227
|
consent: boolean;
|
|
224
228
|
setData: ({ visitorCode, maxAge, path, }: SetDataCallbackParametersType) => void;
|
|
225
229
|
};
|
|
230
|
+
/**
|
|
231
|
+
* @type `SimulateRequestDataType` a type of data provided to `simulateSuccessRequest` method depending on `RequestType`
|
|
232
|
+
* */
|
|
233
|
+
export type SimulateRequestDataType = {
|
|
234
|
+
[RequestType.Configuration]: ClientConfigurationDataType;
|
|
235
|
+
[RequestType.RemoteData]: JSONType;
|
|
236
|
+
[RequestType.Tracking]: null;
|
|
237
|
+
};
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VariableType=exports.Milliseconds=exports.Environment=void 0;let Environment=exports.Environment=function(a){return a.Production="production",a.Staging="staging",a.Development="development",a}({}),VariableType=exports.VariableType=function(a){return a.BOOLEAN="BOOLEAN",a.NUMBER="NUMBER",a.STRING="STRING",a.JSON="JSON",a}({}),Milliseconds=exports.Milliseconds=function(a){return a[a.Second=1000]="Second",a[a.Minute=60*a.Second]="Minute",a[a.Hour=60*a.Minute]="Hour",a[a.Day=24*a.Hour]="Day",a[a.Week=7*a.Day]="Week",a[a.Month=30*a.Day]="Month",a}({});
|
|
1
|
+
"use strict";var _requester=require("./requester");Object.defineProperty(exports,"__esModule",{value:!0}),exports.VariableType=exports.Milliseconds=exports.Environment=void 0;let Environment=exports.Environment=function(a){return a.Production="production",a.Staging="staging",a.Development="development",a}({}),VariableType=exports.VariableType=function(a){return a.BOOLEAN="BOOLEAN",a.NUMBER="NUMBER",a.STRING="STRING",a.JSON="JSON",a}({}),Milliseconds=exports.Milliseconds=function(a){return a[a.Second=1000]="Second",a[a.Minute=60*a.Second]="Minute",a[a.Hour=60*a.Minute]="Hour",a[a.Day=24*a.Hour]="Day",a[a.Week=7*a.Day]="Week",a[a.Month=30*a.Day]="Month",a}({});
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["Environment","exports","Production","Staging","Development","VariableType","BOOLEAN","NUMBER","STRING","JSON","Milliseconds","Second","Minute","Hour","Day","Week","Month"],"sources":["../src/types.ts"],"sourcesContent":["import { ConfigurationDataType, JSONType } from './clientConfiguration/types';\nimport { SdkLanguageType } from './constants';\nimport { IExternalEventSource } from './eventSource';\nimport { IExternalRequestDispatcher } from './requester';\nimport { IExternalStorage } from './storage';\nimport { VisitorDataFiltersType } from './utilities';\nimport { IVisitorCodeManager } from './visitorCodeManager';\n\n/**\n * @param {number} updateInterval - update interval in _minutes_ for sdk configuration, minimum value is 1 minute\n * @defaultvalue 60\n *\n * @param {Environment} environment - feature flag environment\n * @defaultvalue Environment.Production\n *\n * @param {number | undefined} targetingDataCleanupInterval - interval in _minutes_ for cleaning up targeting data, minimum value is 1 minute\n * Note: if not specified, default value will be used\n * @defaultvalue\n * - JavaScript SDK: `undefined` (no cleanup)\n * - React/React Native SDK: `undefined` (no cleanup)\n * - NodeJS SDK: `30`\n *\n * @param {string | undefined} domain - domain which cookie belongs to\n * @param {number | undefined} requestTimeout - timeout in _milliseconds_ for requests\n * @defaultvalue `10_000` (10 seconds)\n * */\nexport type SDKConfigurationType = {\n updateInterval?: number;\n environment?: Environment;\n targetingDataCleanupInterval?: number;\n requestTimeout?: number;\n domain?: string;\n};\n\n/**\n * @param {string} siteCode - client's siteCode defined on Kameleoon platform\n * @param {Partial<SDKConfigurationType>} configuration - client's configuration\n * @param {InternalSDKConfigurationType} internalConfiguration - internal configuration for sdk core to be initialized with certain parameters to certain type of JavaScript SDK\n * */\nexport type SDKCoreParameters = {\n siteCode: string;\n configuration?: Partial<SDKConfigurationType>;\n internalConfiguration: InternalSDKConfigurationType;\n};\n\n/**\n * @param {SdkLanguageType} type - type of the SDK\n * @param {string} version - version of the package\n * */\nexport type ExternalPackageInfoType = {\n type: SdkLanguageType;\n version: string;\n};\n\n/**\n * @param {IExternalStorage | undefined} externalStorage - external file system storage implemented outside client initialization\n * @param {IExternalEventSourceConstructor | undefined} externalEventSource - constructor for building external event source implementation\n * @param {ExternalPackageInfoType} externalPackageInfo - external package info, used to get package version and name\n * @param {ConfigurationDataType} externalClientConfiguration - external fetched client configuration\n * @param {IExternalRequestDispatcher} externalRequestDispatcher - external request dispatcher, used to track data or get data\n * @param {IVisitorCodeManager} externalVisitorCodeManager - external visitor code manager, used to get or generate visitor code\n * @param {number} targetingDataCleanupInterval - interval in *minutes* for cleaning up targeting data, minimum value is 1 minute\n * */\nexport type InternalSDKConfigurationType = {\n externalStorage: IExternalStorage;\n externalEventSource: IExternalEventSource;\n externalVisitorCodeManager: IVisitorCodeManager;\n externalPackageInfo: ExternalPackageInfoType;\n externalRequestDispatcher: IExternalRequestDispatcher;\n externalClientConfiguration?: ConfigurationDataType;\n};\n\n/**\n * @readonly\n * @enum {string} an Enum containing all possible variants of environment, passed as an argument to KameleoonClient `configuration`s `environment` field\n * */\nexport enum Environment {\n Production = 'production',\n Staging = 'staging',\n Development = 'development',\n}\n\n/**\n * @readonly\n * @enum {string} an Enum containing all possible variants of feature variable types\n * */\nexport enum VariableType {\n BOOLEAN = 'BOOLEAN',\n NUMBER = 'NUMBER',\n STRING = 'STRING',\n JSON = 'JSON',\n}\n\nexport type BooleanVariableType = {\n key: string;\n type: VariableType.BOOLEAN;\n value: boolean;\n};\n\nexport type NumberVariableType = {\n key: string;\n type: VariableType.NUMBER;\n value: number;\n};\n\nexport type StringVariableType = {\n key: string;\n type: VariableType.STRING;\n value: string;\n};\n\nexport type JSONVariableType = {\n key: string;\n type: VariableType.JSON;\n value: JSONType;\n};\n\n/**\n * @type `FeatureVariableResultType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type FeatureVariableResultType =\n | BooleanVariableType\n | NumberVariableType\n | StringVariableType\n | JSONVariableType;\n\n/**\n * @type `FeatureFlagVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type FeatureFlagVariableType = Omit<FeatureVariableResultType, 'key'>;\n\n/**\n * @readonly\n * @enum {number} a helper Enum for getting milliseconds for a second/minute/hour/day/week/month.\n * Month is considered in average of 30 days\n * */\nexport enum Milliseconds {\n Second = 1000,\n Minute = 60 * Milliseconds.Second,\n Hour = 60 * Milliseconds.Minute,\n Day = 24 * Milliseconds.Hour,\n Week = 7 * Milliseconds.Day,\n Month = 30 * Milliseconds.Day,\n}\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {number} goalId - an id of a goal to track\n * @param {number | undefined} revenue - an optional parameter for revenue, default value is `0`\n * @param {boolean | undefined} isUniqueIdentifier - an optional parameter for specifying if the visitorCode is a unique identifier, default value is `false`\n * */\nexport type TrackConversionParamsType = {\n visitorCode: string;\n goalId: number;\n revenue?: number;\n isUniqueIdentifier?: boolean;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {boolean | undefined} shouldAddData - optional parameter for adding retrieved data to the storage like `addData` method does, default value is `true`\n * @param {VisitorDataFiltersType | undefined} filters - optional parameter for specifying the filters for which data should be retrieved from what visit, by default only current and latest previous visits' `customData` is retrieved\n * @param {boolean | undefined} isUniqueIdentifier - an optional parameter for specifying if the visitorCode is a unique identifier, default value is `false`\n * */\nexport type RemoteVisitorDataParamsType = {\n visitorCode: string;\n shouldAddData?: boolean;\n filters?: VisitorDataFiltersType;\n isUniqueIdentifier?: boolean;\n};\n\nexport type GetFeatureVariablesParamsType = {\n visitorCode: string;\n featureKey: string;\n variationKey: string;\n};\n\nexport type FeatureFlagType = {\n id: number;\n key: string;\n};\n\n/**\n * @type `KameleoonVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type KameleoonVariableType = FeatureVariableResultType;\n\n/**\n * @type `KameleoonVariationType` - object containing information about the variation and its variables\n * @param {string} key - key of the variation\n * @param {number | null} id - id of the variation or `null` if the visitor hit default variation\n * @param {number | null} experimentId - id of the experiment or `null` if the visitor hit default variation\n * @param {KameleoonVariableType[]} variables - array of variables for the variation\n * */\nexport type KameleoonVariationType = {\n key: string;\n id: number | null;\n experimentId: number | null;\n variables: KameleoonVariableType[];\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {string} featureKey - key of the feature flag to look for, can be found on Kameleoon Platform\n * @param {string} variableKey - key of the variable to be found for a feature flag with provided `featureKey`, can be found on Kameleoon Platform\n * */\nexport type GetFeatureFlagVariableParamsType = {\n visitorCode: string;\n featureKey: string;\n variableKey: string;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {number} customDataIndex - index of the custom data in the warehouse audience\n * @param {string | undefined} warehouseKey - unique key to identify the warehouse data (usually internal user ID)\n * If not specified, the `visitorCode` will be used as a `warehouseKey`\n * */\nexport type GetVisitorWarehouseAudienceParamsType = {\n visitorCode: string;\n customDataIndex: number;\n warehouseKey?: string;\n};\n\nexport type WarehouseAudienceType = {\n // --- Note ---\n // Using `unknown` type here because we don't care about the type of the value\n warehouseAudiences: Record<string, unknown>;\n};\n\nexport type TrackingCacheItemType = {\n [experimentId: number]: { variationId: number; expirationTime: number };\n};\n\nexport type SetDataCallbackParametersType = {\n visitorCode: string;\n maxAge: number;\n path: string;\n key: string;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {boolean} consent - a value representing the legal consent status. - 'true' indicates the\n * visitor has given legal consent. - 'false' indicates the visitor has withdrawn or not\n * provided legal consent.\n * @param {(visitorCode: string) => void} setData - a callback to set a visitor code in cookie\n * */\nexport type SetUserConsentParametersType = {\n visitorCode: string;\n consent: boolean;\n setData: ({\n visitorCode,\n maxAge,\n path,\n }: SetDataCallbackParametersType) => void;\n};\n"],"mappings":"4IA4EY,CAAAA,WAAW,CAAAC,OAAA,CAAAD,WAAA,UAAXA,CAAW,QAAX,CAAAA,CAAW,CAAAE,UAAA,cAAXF,CAAW,CAAAG,OAAA,WAAXH,CAAW,CAAAI,WAAA,eAAXJ,CAAW,MAUXK,YAAY,CAAAJ,OAAA,CAAAI,YAAA,UAAZA,CAAY,QAAZ,CAAAA,CAAY,CAAAC,OAAA,WAAZD,CAAY,CAAAE,MAAA,UAAZF,CAAY,CAAAG,MAAA,UAAZH,CAAY,CAAAI,IAAA,QAAZJ,CAAY,MAkDZK,YAAY,CAAAT,OAAA,CAAAS,YAAA,UAAZA,CAAY,QAAZ,CAAAA,CAAY,CAAZA,CAAY,CAAAC,MAAA,gBAAZD,CAAY,CAAZA,CAAY,CAAAE,MAAA,CAEb,EAAE,CAAGF,CAAY,CAACC,MAAM,WAFvBD,CAAY,CAAZA,CAAY,CAAAG,IAAA,CAGf,EAAE,CAAGH,CAAY,CAACE,MAAM,SAHrBF,CAAY,CAAZA,CAAY,CAAAI,GAAA,CAIhB,EAAE,CAAGJ,CAAY,CAACG,IAAI,QAJlBH,CAAY,CAAZA,CAAY,CAAAK,IAAA,CAKf,CAAC,CAAGL,CAAY,CAACI,GAAG,SALjBJ,CAAY,CAAZA,CAAY,CAAAM,KAAA,CAMd,EAAE,CAAGN,CAAY,CAACI,GAAG,UANnBJ,CAAY"}
|
|
1
|
+
{"version":3,"file":"types.js","names":["_requester","require","Object","defineProperty","exports","value","VariableType","Milliseconds","Environment","Production","Staging","Development","BOOLEAN","NUMBER","STRING","JSON","Second","Minute","Hour","Day","Week","Month"],"sources":["../src/types.ts"],"sourcesContent":["import {\n ClientConfigurationDataType,\n ConfigurationDataType,\n JSONType,\n} from './clientConfiguration/types';\nimport { SdkLanguageType } from './constants';\nimport { IExternalEventSource } from './eventSource';\nimport { IExternalRequester, RequestType } from './requester';\nimport { IExternalStorage } from './storage';\nimport { VisitorDataFiltersType } from './utilities';\nimport { IVisitorCodeManager } from './visitorCodeManager';\n\n/**\n * @param {number} updateInterval - update interval in _minutes_ for sdk configuration, minimum value is 1 minute\n * @defaultvalue 60\n *\n * @param {Environment} environment - feature flag environment\n * @defaultvalue Environment.Production\n *\n * @param {number | undefined} targetingDataCleanupInterval - interval in _minutes_ for cleaning up targeting data, minimum value is 1 minute\n * Note: if not specified, default value will be used\n * @defaultvalue\n * - JavaScript SDK: `undefined` (no cleanup)\n * - React/React Native SDK: `undefined` (no cleanup)\n * - NodeJS SDK: `30`\n *\n * @param {string | undefined} domain - domain which cookie which Kameleoon visitor code belongs to. Note: parameter `domain` is deprecated and will be removed in the next major update, use `cookieDomain` instead\n * @param {string | undefined} cookieDomain - domain which cookie which Kameleoon visitor code belongs to\n * @param {string | undefined} networkDomain - custom domain to be used in place of all requests URL, domain format is `example.com`, if the format is incorrect, default Kameleoon domain will be used\n * @param {number | undefined} requestTimeout - timeout in _milliseconds_ for requests\n * @defaultvalue `10_000` (10 seconds)\n * */\nexport type SDKConfigurationType = {\n updateInterval?: number;\n environment?: Environment;\n targetingDataCleanupInterval?: number;\n requestTimeout?: number;\n domain?: string;\n networkDomain?: string;\n cookieDomain?: string;\n};\n\n/**\n * @param {string} siteCode - client's siteCode defined on Kameleoon platform\n * @param {Partial<SDKConfigurationType>} configuration - client's configuration\n * @param {InternalSDKConfigurationType} internalConfiguration - internal configuration for sdk core to be initialized with certain parameters to certain type of JavaScript SDK\n * */\nexport type SDKCoreParameters = {\n siteCode: string;\n configuration?: Partial<SDKConfigurationType>;\n internalConfiguration: InternalSDKConfigurationType;\n};\n\n/**\n * @param {SdkLanguageType} type - type of the SDK\n * @param {string} version - version of the package\n * */\nexport type ExternalPackageInfoType = {\n type: SdkLanguageType;\n version: string;\n};\n\n/**\n * @param {IExternalStorage | undefined} externalStorage - external file system storage implemented outside client initialization\n * @param {IExternalEventSourceConstructor | undefined} externalEventSource - constructor for building external event source implementation\n * @param {ExternalPackageInfoType} externalPackageInfo - external package info, used to get package version and name\n * @param {ConfigurationDataType} externalClientConfiguration - external fetched client configuration\n * @param {IExternalRequester} externalRequester - external requester , used to track or get data\n * @param {IVisitorCodeManager} externalVisitorCodeManager - external visitor code manager, used to get or generate visitor code\n * @param {number} targetingDataCleanupInterval - interval in *minutes* for cleaning up targeting data, minimum value is 1 minute\n * */\nexport type InternalSDKConfigurationType = {\n externalStorage: IExternalStorage;\n externalEventSource: IExternalEventSource;\n externalVisitorCodeManager: IVisitorCodeManager;\n externalPackageInfo: ExternalPackageInfoType;\n externalRequester: IExternalRequester;\n externalClientConfiguration?: ConfigurationDataType;\n};\n\n/**\n * @readonly\n * @enum {string} an Enum containing all possible variants of environment, passed as an argument to KameleoonClient `configuration`s `environment` field\n * */\nexport enum Environment {\n Production = 'production',\n Staging = 'staging',\n Development = 'development',\n}\n\n/**\n * @readonly\n * @enum {string} an Enum containing all possible variants of feature variable types\n * */\nexport enum VariableType {\n BOOLEAN = 'BOOLEAN',\n NUMBER = 'NUMBER',\n STRING = 'STRING',\n JSON = 'JSON',\n}\n\nexport type BooleanVariableType = {\n key: string;\n type: VariableType.BOOLEAN;\n value: boolean;\n};\n\nexport type NumberVariableType = {\n key: string;\n type: VariableType.NUMBER;\n value: number;\n};\n\nexport type StringVariableType = {\n key: string;\n type: VariableType.STRING;\n value: string;\n};\n\nexport type JSONVariableType = {\n key: string;\n type: VariableType.JSON;\n value: JSONType;\n};\n\n/**\n * @type `FeatureVariableResultType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type FeatureVariableResultType =\n | BooleanVariableType\n | NumberVariableType\n | StringVariableType\n | JSONVariableType;\n\n/**\n * @type `FeatureFlagVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type FeatureFlagVariableType = Omit<FeatureVariableResultType, 'key'>;\n\n/**\n * @readonly\n * @enum {number} a helper Enum for getting milliseconds for a second/minute/hour/day/week/month.\n * Month is considered in average of 30 days\n * */\nexport enum Milliseconds {\n Second = 1000,\n Minute = 60 * Milliseconds.Second,\n Hour = 60 * Milliseconds.Minute,\n Day = 24 * Milliseconds.Hour,\n Week = 7 * Milliseconds.Day,\n Month = 30 * Milliseconds.Day,\n}\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {number} goalId - an id of a goal to track\n * @param {number | undefined} revenue - an optional parameter for revenue, default value is `0`\n * @param {boolean | undefined} isUniqueIdentifier - an optional parameter for specifying if the visitorCode is a unique identifier, default value is `false`\n * */\nexport type TrackConversionParamsType = {\n visitorCode: string;\n goalId: number;\n revenue?: number;\n isUniqueIdentifier?: boolean;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {boolean | undefined} shouldAddData - optional parameter for adding retrieved data to the storage like `addData` method does, default value is `true`\n * @param {VisitorDataFiltersType | undefined} filters - optional parameter for specifying the filters for which data should be retrieved from what visit, by default only current and latest previous visits' `customData` is retrieved\n * @param {boolean | undefined} isUniqueIdentifier - an optional parameter for specifying if the visitorCode is a unique identifier, default value is `false`\n * */\nexport type RemoteVisitorDataParamsType = {\n visitorCode: string;\n shouldAddData?: boolean;\n filters?: VisitorDataFiltersType;\n isUniqueIdentifier?: boolean;\n};\n\nexport type GetFeatureVariablesParamsType = {\n visitorCode: string;\n featureKey: string;\n variationKey: string;\n};\n\nexport type FeatureFlagType = {\n id: number;\n key: string;\n};\n\n/**\n * @type `KameleoonVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type KameleoonVariableType = FeatureVariableResultType;\n\n/**\n * @type `KameleoonVariationType` - object containing information about the variation and its variables\n * @param {string} key - key of the variation\n * @param {number | null} id - id of the variation or `null` if the visitor hit default variation\n * @param {number | null} experimentId - id of the experiment or `null` if the visitor hit default variation\n * @param {KameleoonVariableType[]} variables - array of variables for the variation\n * */\nexport type KameleoonVariationType = {\n key: string;\n id: number | null;\n experimentId: number | null;\n variables: KameleoonVariableType[];\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {string} featureKey - key of the feature flag to look for, can be found on Kameleoon Platform\n * @param {string} variableKey - key of the variable to be found for a feature flag with provided `featureKey`, can be found on Kameleoon Platform\n * */\nexport type GetFeatureFlagVariableParamsType = {\n visitorCode: string;\n featureKey: string;\n variableKey: string;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {number} customDataIndex - index of the custom data in the warehouse audience\n * @param {string | undefined} warehouseKey - unique key to identify the warehouse data (usually internal user ID)\n * If not specified, the `visitorCode` will be used as a `warehouseKey`\n * */\nexport type GetVisitorWarehouseAudienceParamsType = {\n visitorCode: string;\n customDataIndex: number;\n warehouseKey?: string;\n};\n\nexport type WarehouseAudienceType = {\n // --- Note ---\n // Using `unknown` type here because we don't care about the type of the value\n warehouseAudiences: Record<string, unknown>;\n};\n\nexport type TrackingCacheItemType = {\n [experimentId: number]: { variationId: number; expirationTime: number };\n};\n\nexport type SetDataCallbackParametersType = {\n visitorCode: string;\n maxAge: number;\n path: string;\n key: string;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {boolean} consent - a value representing the legal consent status. - 'true' indicates the\n * visitor has given legal consent. - 'false' indicates the visitor has withdrawn or not\n * provided legal consent.\n * @param {(visitorCode: string) => void} setData - a callback to set a visitor code in cookie\n * */\nexport type SetUserConsentParametersType = {\n visitorCode: string;\n consent: boolean;\n setData: ({\n visitorCode,\n maxAge,\n path,\n }: SetDataCallbackParametersType) => void;\n};\n\n/**\n * @type `SimulateRequestDataType` a type of data provided to `simulateSuccessRequest` method depending on `RequestType`\n * */\nexport type SimulateRequestDataType = {\n [RequestType.Configuration]: ClientConfigurationDataType;\n [RequestType.RemoteData]: JSONType;\n [RequestType.Tracking]: null;\n};\n"],"mappings":"aAOA,IAAAA,UAAA,CAAAC,OAAA,gBAA8DC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,YAAA,CAAAF,OAAA,CAAAG,YAAA,CAAAH,OAAA,CAAAI,WAAA,WA6ElD,CAAAA,WAAW,CAAAJ,OAAA,CAAAI,WAAA,UAAXA,CAAW,QAAX,CAAAA,CAAW,CAAAC,UAAA,cAAXD,CAAW,CAAAE,OAAA,WAAXF,CAAW,CAAAG,WAAA,eAAXH,CAAW,MAUXF,YAAY,CAAAF,OAAA,CAAAE,YAAA,UAAZA,CAAY,QAAZ,CAAAA,CAAY,CAAAM,OAAA,WAAZN,CAAY,CAAAO,MAAA,UAAZP,CAAY,CAAAQ,MAAA,UAAZR,CAAY,CAAAS,IAAA,QAAZT,CAAY,MAkDZC,YAAY,CAAAH,OAAA,CAAAG,YAAA,UAAZA,CAAY,QAAZ,CAAAA,CAAY,CAAZA,CAAY,CAAAS,MAAA,gBAAZT,CAAY,CAAZA,CAAY,CAAAU,MAAA,CAEb,EAAE,CAAGV,CAAY,CAACS,MAAM,WAFvBT,CAAY,CAAZA,CAAY,CAAAW,IAAA,CAGf,EAAE,CAAGX,CAAY,CAACU,MAAM,SAHrBV,CAAY,CAAZA,CAAY,CAAAY,GAAA,CAIhB,EAAE,CAAGZ,CAAY,CAACW,IAAI,QAJlBX,CAAY,CAAZA,CAAY,CAAAa,IAAA,CAKf,CAAC,CAAGb,CAAY,CAACY,GAAG,SALjBZ,CAAY,CAAZA,CAAY,CAAAc,KAAA,CAMd,EAAE,CAAGd,CAAY,CAACY,GAAG,UANnBZ,CAAY"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VISITOR_CODE_MAX_LENGTH=exports.HEX_CHARACTERS=void 0;const VISITOR_CODE_MAX_LENGTH=exports.VISITOR_CODE_MAX_LENGTH=255,HEX_CHARACTERS=exports.HEX_CHARACTERS="0123456789ABCDEF";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VISITOR_CODE_MAX_LENGTH=exports.NONCE_LENGTH=exports.HEX_CHARACTERS=void 0;const VISITOR_CODE_MAX_LENGTH=exports.VISITOR_CODE_MAX_LENGTH=255,HEX_CHARACTERS=exports.HEX_CHARACTERS="0123456789ABCDEF",NONCE_LENGTH=exports.NONCE_LENGTH=16;
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["VISITOR_CODE_MAX_LENGTH","exports","HEX_CHARACTERS"],"sources":["../../src/utilities/constants.ts"],"sourcesContent":["export const VISITOR_CODE_MAX_LENGTH = 255;\nexport const HEX_CHARACTERS = '0123456789ABCDEF';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","names":["VISITOR_CODE_MAX_LENGTH","exports","HEX_CHARACTERS","NONCE_LENGTH"],"sources":["../../src/utilities/constants.ts"],"sourcesContent":["export const VISITOR_CODE_MAX_LENGTH = 255;\nexport const HEX_CHARACTERS = '0123456789ABCDEF';\nexport const NONCE_LENGTH = 16;\n"],"mappings":"4JAAa,CAAAA,uBAAuB,CAAAC,OAAA,CAAAD,uBAAA,CAAG,GAAG,CAC7BE,cAAc,CAAAD,OAAA,CAAAC,cAAA,CAAG,kBAAkB,CACnCC,YAAY,CAAAF,OAAA,CAAAE,YAAA,CAAG,EAAE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const _excluded=["timestamp","isExperiment"];Object.defineProperty(exports,"__esModule",{value:!0}),exports.Utilities=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_types=require("../types"),_kameleoonData=require("../kameleoonData"),_constants=require("../constants"),_requester=require("../requester"),_targeting=require("../targeting"),_visitProcessor=require("../kameleoonData/visitProcessor"),_constants2=require("./constants"),_types2=require("./types");function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Utilities{static checkTargeting(a){let{segment:b,visitorCode:c,targetingData:d,experimentId:e,variationConfiguration:f,clientConfiguration:g,packageInfo:h,dataManager:i}=a;if(!b||!b.conditionsData.firstLevel.length)return(0,_tsRes.Ok)(!0);if(!f)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));let j={};const k=f.getStoredVariations(c);k.ok&&(j=k.data);const l=i.getTree(b);let m,n,o;l.hasTargetingType(_targeting.TargetingType.SEGMENT)&&(m=i.trees,n=g.segments),l.hasTargetingType(_targeting.TargetingType.TARGET_FEATURE_FLAG)&&(o=g.ruleMap);const p=l.evaluate({variationData:j,sdkInfo:h,segments:n,ruleMap:o,trees:m,targetingData:d,experimentId:e,visitorCode:c});return p}static validateVisitorCode(a){return 0===a.length?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeEmpty)):a.length>_constants2.VISITOR_CODE_MAX_LENGTH?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeMaxLength)):(0,_tsRes.Ok)()}static getDataUrl(a){function b(a){if(!a.url)return;const b=a.data.type===_kameleoonData.KameleoonData.Conversion;if(e||b){const c=b?"":_requester.UrlParameter.Nonce+Utilities.getNonce();g.push(a.url+c+"\n")}}let{visitorCode:c,dataManager:d,isConsentProvided:e}=a;const f=d.getUnsentData(c),g=[];if(!f||!f.size)return"";for(const c of f.values())Array.isArray(c)?c.forEach(a=>b(a)):b(c);return g.join("")}static getVariationDataUrlAndSentExperimentIds(a){let{visitorCode:b,isConsentProvided:c,variationConfiguration:d}=a;const e=[],f=new Set,g=d.getUnsentData(b);g.ok&&g.data.length&&g.data.forEach(a=>{(a.isTargetedRule||c)&&(e.push(_requester.UrlEventType.Experiment+_requester.UrlParameter.Id+a.experimentId+_requester.UrlParameter.VariationId+a.variationId+_requester.UrlParameter.Nonce+Utilities.getNonce()+"\n"),f.add(a.experimentId+""))});const h=e.join(""),i=Array.from(f);return[h,i]}static async trackFeatureExperiment(a){let{featureFlagVariation:b,dataManager:c,visitorCode:d,requester:e,isOfflineModeOn:f,isConsentProvided:g,offlineTrackingStorage:h,variationConfiguration:i}=a;const{variationId:j,rule:k}=b,l=this.getUserAgent(d,c),m=this.getDataUrl({visitorCode:d,dataManager:c,isConsentProvided:g}),n=k?k.experimentId:0,[o,p]=this.getVariationDataUrlAndSentExperimentIds({visitorCode:d,isConsentProvided:g,variationConfiguration:i});if(!g&&!m&&!k)return;const q={visitorCode:d,dataUrl:m,variationDataUrl:o,experimentId:n,variationId:j||0,userAgent:l,isUnallocated:null===j},r=await e.trackExperiment(q);r.ok&&(g?c.clearUnsentData(d):c.clearUnsentDataByKey(d,_kameleoonData.KameleoonData.Conversion),p.forEach(a=>{i.markUnsentDataAsSent(d,a)})),!r.ok&&f&&this.addItemToOfflineTracking({item:q,storage:h,isExperiment:!0})}static convertTimeUnit(a,b){const c={[_types2.TimeUnit.Minute]:_types.Milliseconds.Minute,[_types2.TimeUnit.Hour]:_types.Milliseconds.Hour,[_types2.TimeUnit.Day]:_types.Milliseconds.Day,[_types2.TimeUnit.Week]:_types.Milliseconds.Week,[_types2.TimeUnit.Month]:_types.Milliseconds.Month};return a/c[b]}static parseFeatureVariable(a){const{key:b,type:c,value:d}=a;switch(c){case _types.VariableType.BOOLEAN:return(0,_tsRes.Ok)({key:b,type:c,value:!!d});case _types.VariableType.STRING:return(0,_tsRes.Ok)({key:b,type:c,value:d+""});case _types.VariableType.NUMBER:const e=+d;return Number.isNaN(e)?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NumberParse,d+"")):(0,_tsRes.Ok)({key:b,type:c,value:e});case _types.VariableType.JSON:try{const d=JSON.parse(a.value+"");return(0,_tsRes.Ok)({key:b,type:c,value:d})}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a))}default:(0,_kameleoonError.exhaustCheck)(c)}}static parseVisitorData(a){let{data:b,filters:c,visitorCode:d,dataManager:e,variationConfiguration:f}=a;const g=new _visitProcessor.VisitProcessor(c,e),{currentVisit:h,previousVisits:i,kcs:j}=b;let k=[];const l=c.kcs&&!c.currentVisit;if(h&&!l&&k.push(h),i&&k.push(...i),!k.length&&!l)return{visitorData:[],storageVisitorData:[]};k.forEach(a=>{g.processVisit(a)}),g.processKcs(j),g.processMultipleDataTypes();const{visitorData:m,storageVisitorData:n,visitsData:o,experimentData:p}=g.data;return f.updateStoredVariations(d,p),{visitorData:m,storageVisitorData:n,visitsData:o}}static parseRegExp(a){if("/"===a[0]){const[_,b,c]=a.split("/");return new RegExp(b,c)}return new RegExp(a)}static getUserAgent(a,b){const c=b.getTargetingData(a);if(c){const a=c[_kameleoonData.KameleoonData.UserAgent];if(a)return a.value}}static isCustomData(a){return a.data.type===_kameleoonData.KameleoonData.CustomData}static insertInOrderedListMutably(a){let{list:b,element:c,order:d}=a;if(!b.includes(c)){const a=b.findIndex(a=>d===_types2.Order.Ascending?a>=c:a<=c);-1===a?b.push(c):b.splice(a,0,c)}}static updateCache(a){let{cacheManager:b,visitorCode:c,experimentId:d,variationId:e}=a;const f=b.getAliveItem(c),g=f?_objectSpread({},f):{};g[d]={variationId:e,expirationTime:Date.now()+_constants.CACHE_ITEM_LIFETIME*_types.Milliseconds.Second},b.add({key:c,data:g,lifetime:_constants.CACHE_ITEM_LIFETIME})}static getTrackingCode(a,b){let c="window.kameleoonQueue=window.kameleoonQueue||[];";const d=a.getAliveItem(b);if(!d)return c;const e={};return Object.entries(d).forEach(a=>{let[b,{variationId:d,expirationTime:f}]=a;f>Date.now()&&(c+="window.kameleoonQueue.push(['Experiments.assignVariation',".concat(b,",").concat(d,"]);"),c+="window.kameleoonQueue.push(['Experiments.trigger',".concat(b,",true]);"),e[+b]={variationId:d,expirationTime:f})}),a.add({key:b,data:e,lifetime:_constants.CACHE_ITEM_LIFETIME}),c}static async trackData(a){let{visitorCode:b,dataManager:c,requester:d,isOfflineModeOn:e,offlineTrackingStorage:f,isConsentProvided:g,isMappingIdentifier:h}=a;await this.sendOfflineTracking({requester:d,storage:f});const i=this.getDataUrl({visitorCode:b,dataManager:c,isConsentProvided:g});if(!g&&!i)return;const j=this.getUserAgent(b,c),k={visitorCode:b,body:i,userAgent:j,isMappingIdentifier:h},l=await d.trackData(k),m=()=>g?c.clearUnsentData(b):c.clearUnsentDataByKey(b,_kameleoonData.KameleoonData.Conversion);l.ok&&m(),!l.ok&&e&&this.addItemToOfflineTracking({item:k,storage:f,isExperiment:!1,onSuccess:m})}static getNonce(){const a=_constants2.HEX_CHARACTERS.length;let b="";for(let c=0;c<a;c++){const c=Math.floor(Math.random()*a);b+=_constants2.HEX_CHARACTERS.substring(c,c+1)}return b}static compareSemVer(a){let{version:b,compareVersion:c,operator:d}=a;const e=this.validateVersion(b),f=this.validateVersion(c);if(!e.ok)return(0,_tsRes.Err)(e.error);if(!f.ok)return(0,_tsRes.Err)(f.error);const[g,h,i]=e.data,[j,k,l]=f.data,[m,n,o]=[g===j,h===k,i===l];switch(d){case _targeting.VersionMatchType.EQUAL:return(0,_tsRes.Ok)(m&&n&&o);case _targeting.VersionMatchType.GREATER:return(0,_tsRes.Ok)(g>j||m&&h>k||m&&n&&i>l);case _targeting.VersionMatchType.LOWER:return(0,_tsRes.Ok)(g<j||m&&h<k||m&&n&&i<l);default:(0,_kameleoonError.exhaustCheck)(d)}}static generateRandomString(a){const b="abcdefghijklmnopqrstuvwxyz0123456789",c=[];if(0>a)return"";for(let d=0;d<a;d++)c.push(b[Math.floor(Math.random()*b.length)]);return c.join("")}static async sendOfflineTracking(a){let{requester:b,storage:c}=a;const d=c.read();if(d.ok&&d.data.requestParameters){const{requestParameters:a}=d.data,e=[];for(const c of a){const{timestamp:a,isExperiment:d}=c,f=_objectWithoutProperties(c,_excluded);let g;g=d?await b.trackExperiment(f):await b.trackData(f),g.ok&&g.data&&e.push(a)}this.deleteFromOfflineTracking({storage:c,timestamps:e})}}static addItemToOfflineTracking(a){let{item:b,isExperiment:c,storage:d,onSuccess:e}=a;const f=d.read(),g=f.ok?f.data:{},{requestParameters:h}=g,i=_objectSpread(_objectSpread({},b),{},{timestamp:new Date().getTime(),isExperiment:c}),j=h?[...h,i]:[i],k=d.write({requestParameters:j});k.ok&&e&&e()}static deleteFromOfflineTracking(a){let{timestamps:b,storage:c}=a;const d=c.read();if(d.ok){const{requestParameters:a}=d.data,e=null===a||void 0===a?void 0:a.filter(a=>!b.includes(a.timestamp));c.write({requestParameters:e})}}static validateVersion(a){const b=a.split(".").map(a=>parseInt(a,10));for(;3>b.length;)b.push(0);return b.some(a=>isNaN(a))?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.SemanticVersionParse,a)):(0,_tsRes.Ok)(b.slice(0,3))}}exports.Utilities=Utilities;
|
|
1
|
+
"use strict";const _excluded=["timestamp","isExperiment"];Object.defineProperty(exports,"__esModule",{value:!0}),exports.Utilities=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_types=require("../types"),_kameleoonData=require("../kameleoonData"),_constants=require("../constants"),_requester=require("../requester"),_targeting=require("../targeting"),_visitProcessor=require("../kameleoonData/visitProcessor"),_constants2=require("./constants"),_types2=require("./types");function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Utilities{static checkTargeting(a){let{segment:b,visitorCode:c,targetingData:d,experimentId:e,variationConfiguration:f,clientConfiguration:g,packageInfo:h,dataManager:i}=a;if(!b||!b.conditionsData.firstLevel.length)return(0,_tsRes.Ok)(!0);if(!f)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));let j={};const k=f.getStoredVariations(c);k.ok&&(j=k.data);const l=i.getTree(b);let m,n,o;l.hasTargetingType(_targeting.TargetingType.SEGMENT)&&(m=i.trees,n=g.segments),l.hasTargetingType(_targeting.TargetingType.TARGET_FEATURE_FLAG)&&(o=g.ruleMap);const p=l.evaluate({variationData:j,sdkInfo:h,segments:n,ruleMap:o,trees:m,targetingData:d,experimentId:e,visitorCode:c});return p}static validateVisitorCode(a){return 0===a.length?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeEmpty)):a.length>_constants2.VISITOR_CODE_MAX_LENGTH?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeMaxLength)):(0,_tsRes.Ok)()}static getDataUrl(a){function b(a){if(!a.url)return;const b=a.data.type===_kameleoonData.KameleoonData.Conversion;if(e||b){const c=b?"":_requester.UrlParameter.Nonce+Utilities.getNonce();g.push(a.url+c+"\n")}}let{visitorCode:c,dataManager:d,isConsentProvided:e}=a;const f=d.getUnsentData(c),g=[];if(!f||!f.size)return"";for(const c of f.values())Array.isArray(c)?c.forEach(a=>b(a)):b(c);return g.join("")}static getVariationDataUrlAndSentExperimentIds(a){let{visitorCode:b,isConsentProvided:c,variationConfiguration:d}=a;const e=[],f=new Set,g=d.getUnsentData(b);g.ok&&g.data.length&&g.data.forEach(a=>{(a.isTargetedRule||c)&&(e.push(_requester.UrlEventType.Experiment+_requester.UrlParameter.Id+a.experimentId+_requester.UrlParameter.VariationId+a.variationId+_requester.UrlParameter.Nonce+Utilities.getNonce()+"\n"),f.add(a.experimentId+""))});const h=e.join(""),i=Array.from(f);return[h,i]}static async trackFeatureExperiment(a){let{featureFlagVariation:b,dataManager:c,visitorCode:d,requester:e,isOfflineModeOn:f,isConsentProvided:g,offlineTrackingStorage:h,variationConfiguration:i}=a;const{variationId:j,rule:k}=b,l=this.getUserAgent(d,c),m=this.getDataUrl({visitorCode:d,dataManager:c,isConsentProvided:g}),n=k?k.experimentId:0,[o,p]=this.getVariationDataUrlAndSentExperimentIds({visitorCode:d,isConsentProvided:g,variationConfiguration:i});if(!g&&!m&&!k)return;const q={visitorCode:d,dataUrl:m,variationDataUrl:o,experimentId:n,variationId:j||0,userAgent:l,isUnallocated:null===j},r=await e.trackExperiment(q);r.ok&&(g?c.clearUnsentData(d):c.clearUnsentDataByKey(d,_kameleoonData.KameleoonData.Conversion),p.forEach(a=>{i.markUnsentDataAsSent(d,a)})),!r.ok&&f&&this.addItemToOfflineTracking({item:q,storage:h,isExperiment:!0})}static convertTimeUnit(a,b){const c={[_types2.TimeUnit.Minute]:_types.Milliseconds.Minute,[_types2.TimeUnit.Hour]:_types.Milliseconds.Hour,[_types2.TimeUnit.Day]:_types.Milliseconds.Day,[_types2.TimeUnit.Week]:_types.Milliseconds.Week,[_types2.TimeUnit.Month]:_types.Milliseconds.Month};return a/c[b]}static parseFeatureVariable(a){const{key:b,type:c,value:d}=a;switch(c){case _types.VariableType.BOOLEAN:return(0,_tsRes.Ok)({key:b,type:c,value:!!d});case _types.VariableType.STRING:return(0,_tsRes.Ok)({key:b,type:c,value:d+""});case _types.VariableType.NUMBER:const e=+d;return Number.isNaN(e)?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NumberParse,d+"")):(0,_tsRes.Ok)({key:b,type:c,value:e});case _types.VariableType.JSON:try{const d=JSON.parse(a.value+"");return(0,_tsRes.Ok)({key:b,type:c,value:d})}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a))}default:(0,_kameleoonError.exhaustCheck)(c)}}static parseVisitorData(a){let{data:b,filters:c,visitorCode:d,dataManager:e,variationConfiguration:f}=a;const g=new _visitProcessor.VisitProcessor(c,e),{currentVisit:h,previousVisits:i,kcs:j}=b;let k=[];if(h&&k.push(h),i&&k.push(...i),!k.length)return{visitorData:[],storageVisitorData:[]};k.forEach(a=>{g.processVisit(a)}),g.processKcs(j),g.processMultipleDataTypes();const{visitorData:l,storageVisitorData:m,visitsData:n,experimentData:o}=g.data;return f.updateStoredVariations(d,o),{visitorData:l,storageVisitorData:m,visitsData:n}}static parseRegExp(a){if("/"===a[0]){const[_,b,c]=a.split("/");return new RegExp(b,c)}return new RegExp(a)}static getUserAgent(a,b){const c=b.getTargetingData(a);if(c){const a=c[_kameleoonData.KameleoonData.UserAgent];if(a)return a.value}}static isCustomData(a){return a.data.type===_kameleoonData.KameleoonData.CustomData}static insertInOrderedListMutably(a){let{list:b,element:c,order:d}=a;if(!b.includes(c)){const a=b.findIndex(a=>d===_types2.Order.Ascending?a>=c:a<=c);-1===a?b.push(c):b.splice(a,0,c)}}static updateCache(a){let{cacheManager:b,visitorCode:c,experimentId:d,variationId:e}=a;const f=b.getAliveItem(c),g=f?_objectSpread({},f):{};g[d]={variationId:e,expirationTime:Date.now()+_constants.CACHE_ITEM_LIFETIME*_types.Milliseconds.Second},b.add({key:c,data:g,lifetime:_constants.CACHE_ITEM_LIFETIME})}static getTrackingCode(a,b){let c="window.kameleoonQueue=window.kameleoonQueue||[];";const d=a.getAliveItem(b);if(!d)return c;const e={};return Object.entries(d).forEach(a=>{let[b,{variationId:d,expirationTime:f}]=a;f>Date.now()&&(c+="window.kameleoonQueue.push(['Experiments.assignVariation',".concat(b,",").concat(d,"]);"),c+="window.kameleoonQueue.push(['Experiments.trigger',".concat(b,",true]);"),e[+b]={variationId:d,expirationTime:f})}),a.add({key:b,data:e,lifetime:_constants.CACHE_ITEM_LIFETIME}),c}static async trackData(a){let{visitorCode:b,dataManager:c,requester:d,isOfflineModeOn:e,offlineTrackingStorage:f,isConsentProvided:g,isMappingIdentifier:h}=a;const i=this.getDataUrl({visitorCode:b,dataManager:c,isConsentProvided:g});if(!g&&!i)return;const j=this.getUserAgent(b,c),k={visitorCode:b,body:i,userAgent:j,isMappingIdentifier:h},l=await d.trackData(k),m=()=>g?c.clearUnsentData(b):c.clearUnsentDataByKey(b,_kameleoonData.KameleoonData.Conversion);l.ok&&m(),!l.ok&&e&&this.addItemToOfflineTracking({item:k,storage:f,isExperiment:!1,onSuccess:m}),await this.sendOfflineTracking({requester:d,storage:f})}static getNonce(){let a="";for(let b=0;b<_constants2.NONCE_LENGTH;b++){const b=Math.floor(Math.random()*_constants2.NONCE_LENGTH);a+=_constants2.HEX_CHARACTERS.charAt(b)}return a}static compareSemVer(a){let{version:b,compareVersion:c,operator:d}=a;const e=this.validateVersion(b),f=this.validateVersion(c);if(!e.ok)return(0,_tsRes.Err)(e.error);if(!f.ok)return(0,_tsRes.Err)(f.error);const[g,h,i]=e.data,[j,k,l]=f.data,[m,n,o]=[g===j,h===k,i===l];switch(d){case _targeting.VersionMatchType.EQUAL:return(0,_tsRes.Ok)(m&&n&&o);case _targeting.VersionMatchType.GREATER:return(0,_tsRes.Ok)(g>j||m&&h>k||m&&n&&i>l);case _targeting.VersionMatchType.LOWER:return(0,_tsRes.Ok)(g<j||m&&h<k||m&&n&&i<l);default:(0,_kameleoonError.exhaustCheck)(d)}}static generateRandomString(a){const b="abcdefghijklmnopqrstuvwxyz0123456789",c=[];if(0>a)return"";for(let d=0;d<a;d++)c.push(b[Math.floor(Math.random()*b.length)]);return c.join("")}static async sendOfflineTracking(a){let{requester:b,storage:c}=a;const d=c.read();if(d.ok&&d.data.requestParameters){const{requestParameters:a}=d.data,e=[];for(const c of a){const{timestamp:a,isExperiment:d}=c,f=_objectWithoutProperties(c,_excluded);let g;g=d?await b.trackExperiment(f):await b.trackData(f),g.ok&&g.data&&e.push(a)}this.deleteFromOfflineTracking({storage:c,timestamps:e})}}static addItemToOfflineTracking(a){let{item:b,isExperiment:c,storage:d,onSuccess:e}=a;const f=d.read(),g=f.ok?f.data:{},{requestParameters:h}=g,i=_objectSpread(_objectSpread({},b),{},{timestamp:new Date().getTime(),isExperiment:c}),j=h?[...h,i]:[i],k=d.write({requestParameters:j});k.ok&&e&&e()}static deleteFromOfflineTracking(a){let{timestamps:b,storage:c}=a;const d=c.read();if(d.ok){const{requestParameters:a}=d.data,e=null===a||void 0===a?void 0:a.filter(a=>!b.includes(a.timestamp));c.write({requestParameters:e})}}static validateVersion(a){const b=a.split(".").map(a=>parseInt(a,10));for(;3>b.length;)b.push(0);return b.some(a=>isNaN(a))?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.SemanticVersionParse,a)):(0,_tsRes.Ok)(b.slice(0,3))}}exports.Utilities=Utilities;
|
|
2
2
|
//# sourceMappingURL=utilities.js.map
|