@amplitude/experiment-js-client
Advanced tools
Comparing version 1.7.3 to 1.7.4
@@ -69,3 +69,2 @@ import { AnalyticsConnector } from '@amplitude/analytics-connector'; | ||
} | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
@@ -79,3 +78,2 @@ function fulfilled(value) { | ||
} | ||
function rejected(value) { | ||
@@ -88,7 +86,5 @@ try { | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -101,38 +97,37 @@ }); | ||
var s = new XMLHttpRequest(), | ||
o = [], | ||
u = [], | ||
i = {}, | ||
a = function a() { | ||
return { | ||
ok: 2 == (s.status / 100 | 0), | ||
statusText: s.statusText, | ||
status: s.status, | ||
url: s.responseURL, | ||
text: function text() { | ||
return Promise.resolve(s.responseText); | ||
}, | ||
json: function json() { | ||
return Promise.resolve(JSON.parse(s.responseText)); | ||
}, | ||
blob: function blob() { | ||
return Promise.resolve(new Blob([s.response])); | ||
}, | ||
clone: a, | ||
headers: { | ||
keys: function keys() { | ||
return o; | ||
o = [], | ||
u = [], | ||
i = {}, | ||
a = function a() { | ||
return { | ||
ok: 2 == (s.status / 100 | 0), | ||
statusText: s.statusText, | ||
status: s.status, | ||
url: s.responseURL, | ||
text: function text() { | ||
return Promise.resolve(s.responseText); | ||
}, | ||
entries: function entries() { | ||
return u; | ||
json: function json() { | ||
return Promise.resolve(JSON.parse(s.responseText)); | ||
}, | ||
get: function get(e) { | ||
return i[e.toLowerCase()]; | ||
blob: function blob() { | ||
return Promise.resolve(new Blob([s.response])); | ||
}, | ||
has: function has(e) { | ||
return e.toLowerCase() in i; | ||
clone: a, | ||
headers: { | ||
keys: function keys() { | ||
return o; | ||
}, | ||
entries: function entries() { | ||
return u; | ||
}, | ||
get: function get(e) { | ||
return i[e.toLowerCase()]; | ||
}, | ||
has: function has(e) { | ||
return e.toLowerCase() in i; | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
}; | ||
for (var l in s.open(n.method || "get", e, !0), s.onload = function () { | ||
@@ -142,6 +137,3 @@ s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (e, n, t) { | ||
}), t(a()); | ||
}, s.onerror = r, s.withCredentials = "include" == n.credentials, n.headers) { | ||
s.setRequestHeader(l, n.headers[l]); | ||
} | ||
}, s.onerror = r, s.withCredentials = "include" == n.credentials, n.headers) s.setRequestHeader(l, n.headers[l]); | ||
s.send(n.body || null); | ||
@@ -278,3 +270,3 @@ }); | ||
var version = "1.7.3"; | ||
var version = "1.7.4"; | ||
@@ -292,3 +284,3 @@ class ConnectorUserProvider { | ||
const listener = () => { | ||
resolve(); | ||
resolve(undefined); | ||
this.identityStore.removeIdentityListener(listener); | ||
@@ -487,23 +479,12 @@ }; | ||
var lookup = []; | ||
var revLookup = []; | ||
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
for (var i = 0, len = code.length; i < len; ++i) { | ||
lookup[i] = code[i]; | ||
revLookup[code.charCodeAt(i)] = i; | ||
} // Support decoding URL-safe base64 strings, as Node.js does. | ||
// See: https://en.wikipedia.org/wiki/Base64#URL_applications | ||
revLookup['-'.charCodeAt(0)] = 62; | ||
revLookup['_'.charCodeAt(0)] = 63; | ||
} | ||
function tripletToBase64(num) { | ||
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; | ||
} | ||
function encodeChunk(uint8, start, end) { | ||
var tmp; | ||
var output = []; | ||
for (var i = start; i < end; i += 3) { | ||
@@ -513,6 +494,4 @@ tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF); | ||
} | ||
return output.join(''); | ||
} | ||
function fromByteArray(uint8) { | ||
@@ -522,12 +501,11 @@ var tmp; | ||
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes | ||
var parts = []; | ||
var maxChunkLength = 16383; // must be multiple of 3 | ||
// go through the array every three bytes, we'll deal with trailing stuff later | ||
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { | ||
parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); | ||
} // pad the end with zeros, but make sure to not forget the extra bytes | ||
} | ||
// pad the end with zeros, but make sure to not forget the extra bytes | ||
if (extraBytes === 1) { | ||
@@ -540,3 +518,2 @@ tmp = uint8[len - 1]; | ||
} | ||
return parts.join(''); | ||
@@ -543,0 +520,0 @@ } |
@@ -67,3 +67,3 @@ import { AnalyticsConnector } from '@amplitude/analytics-connector'; | ||
/*! ***************************************************************************** | ||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
@@ -86,9 +86,6 @@ | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
@@ -102,3 +99,2 @@ }; | ||
} | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
@@ -112,3 +108,2 @@ function fulfilled(value) { | ||
} | ||
function rejected(value) { | ||
@@ -121,7 +116,5 @@ try { | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -132,14 +125,14 @@ }); | ||
var _ = { | ||
label: 0, | ||
sent: function () { | ||
if (t[0] & 1) throw t[1]; | ||
return t[1]; | ||
label: 0, | ||
sent: function () { | ||
if (t[0] & 1) throw t[1]; | ||
return t[1]; | ||
}, | ||
trys: [], | ||
ops: [] | ||
}, | ||
trys: [], | ||
ops: [] | ||
}, | ||
f, | ||
y, | ||
t, | ||
g; | ||
f, | ||
y, | ||
t, | ||
g; | ||
return g = { | ||
@@ -152,3 +145,2 @@ next: verb(0), | ||
}), g; | ||
function verb(n) { | ||
@@ -159,10 +151,7 @@ return function (v) { | ||
} | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
@@ -173,3 +162,2 @@ case 0: | ||
break; | ||
case 4: | ||
@@ -181,3 +169,2 @@ _.label++; | ||
}; | ||
case 5: | ||
@@ -188,10 +175,6 @@ _.label++; | ||
continue; | ||
case 7: | ||
op = _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
default: | ||
@@ -202,3 +185,2 @@ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { | ||
} | ||
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { | ||
@@ -208,3 +190,2 @@ _.label = op[1]; | ||
} | ||
if (op[0] === 6 && _.label < t[1]) { | ||
@@ -215,18 +196,11 @@ _.label = t[1]; | ||
} | ||
if (t && _.label < t[2]) { | ||
_.label = t[2]; | ||
_.ops.push(op); | ||
break; | ||
} | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
} | ||
op = body.call(thisArg, _); | ||
@@ -239,3 +213,2 @@ } catch (e) { | ||
} | ||
if (op[0] & 5) throw op[1]; | ||
@@ -248,10 +221,10 @@ return { | ||
} | ||
/** @deprecated */ | ||
function __spreadArrays() { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; | ||
return r; | ||
function __spreadArray(to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
} | ||
@@ -262,38 +235,37 @@ | ||
var s = new XMLHttpRequest(), | ||
o = [], | ||
u = [], | ||
i = {}, | ||
a = function () { | ||
return { | ||
ok: 2 == (s.status / 100 | 0), | ||
statusText: s.statusText, | ||
status: s.status, | ||
url: s.responseURL, | ||
text: function () { | ||
return Promise.resolve(s.responseText); | ||
}, | ||
json: function () { | ||
return Promise.resolve(JSON.parse(s.responseText)); | ||
}, | ||
blob: function () { | ||
return Promise.resolve(new Blob([s.response])); | ||
}, | ||
clone: a, | ||
headers: { | ||
keys: function () { | ||
return o; | ||
o = [], | ||
u = [], | ||
i = {}, | ||
a = function () { | ||
return { | ||
ok: 2 == (s.status / 100 | 0), | ||
statusText: s.statusText, | ||
status: s.status, | ||
url: s.responseURL, | ||
text: function () { | ||
return Promise.resolve(s.responseText); | ||
}, | ||
entries: function () { | ||
return u; | ||
json: function () { | ||
return Promise.resolve(JSON.parse(s.responseText)); | ||
}, | ||
get: function (e) { | ||
return i[e.toLowerCase()]; | ||
blob: function () { | ||
return Promise.resolve(new Blob([s.response])); | ||
}, | ||
has: function (e) { | ||
return e.toLowerCase() in i; | ||
clone: a, | ||
headers: { | ||
keys: function () { | ||
return o; | ||
}, | ||
entries: function () { | ||
return u; | ||
}, | ||
get: function (e) { | ||
return i[e.toLowerCase()]; | ||
}, | ||
has: function (e) { | ||
return e.toLowerCase() in i; | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
}; | ||
for (var l in s.open(n.method || "get", e, !0), s.onload = function () { | ||
@@ -304,3 +276,2 @@ s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (e, n, t) { | ||
}, s.onerror = r, s.withCredentials = "include" == n.credentials, n.headers) s.setRequestHeader(l, n.headers[l]); | ||
s.send(n.body || null); | ||
@@ -335,3 +306,4 @@ }); | ||
var call = function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var response, simpleResponse, _a; | ||
var response, simpleResponse; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
@@ -448,3 +420,3 @@ switch (_b.label) { | ||
var version = "1.7.3"; | ||
var version = "1.7.4"; | ||
@@ -465,3 +437,3 @@ var ConnectorUserProvider = /** @class */ (function () { | ||
var listener = function () { | ||
resolve(); | ||
resolve(undefined); | ||
_this.identityStore.removeIdentityListener(listener); | ||
@@ -533,3 +505,3 @@ }; | ||
var shortApiKey = apiKey.substring(apiKey.length - 6); | ||
this.namespace = "amp-exp-" + instanceName + "-" + shortApiKey; | ||
this.namespace = "amp-exp-".concat(instanceName, "-").concat(shortApiKey); | ||
} | ||
@@ -600,3 +572,3 @@ LocalStorage.prototype.put = function (key, value) { | ||
var value = variant === null || variant === void 0 ? void 0 : variant.value; | ||
var userProperty = "[Experiment] " + key; | ||
var userProperty = "[Experiment] ".concat(key); | ||
return { | ||
@@ -693,23 +665,12 @@ name: name, | ||
var lookup = []; | ||
var revLookup = []; | ||
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
for (var i = 0, len = code.length; i < len; ++i) { | ||
lookup[i] = code[i]; | ||
revLookup[code.charCodeAt(i)] = i; | ||
} // Support decoding URL-safe base64 strings, as Node.js does. | ||
// See: https://en.wikipedia.org/wiki/Base64#URL_applications | ||
revLookup['-'.charCodeAt(0)] = 62; | ||
revLookup['_'.charCodeAt(0)] = 63; | ||
} | ||
function tripletToBase64(num) { | ||
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; | ||
} | ||
function encodeChunk(uint8, start, end) { | ||
var tmp; | ||
var output = []; | ||
for (var i = start; i < end; i += 3) { | ||
@@ -719,6 +680,4 @@ tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF); | ||
} | ||
return output.join(''); | ||
} | ||
function fromByteArray(uint8) { | ||
@@ -728,12 +687,11 @@ var tmp; | ||
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes | ||
var parts = []; | ||
var maxChunkLength = 16383; // must be multiple of 3 | ||
// go through the array every three bytes, we'll deal with trailing stuff later | ||
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { | ||
parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); | ||
} // pad the end with zeros, but make sure to not forget the extra bytes | ||
} | ||
// pad the end with zeros, but make sure to not forget the extra bytes | ||
if (extraBytes === 1) { | ||
@@ -746,3 +704,2 @@ tmp = uint8[len - 1]; | ||
} | ||
return parts.join(''); | ||
@@ -956,3 +913,3 @@ } | ||
} | ||
this.debug("[Experiment] variant for " + key + " is " + variant.value); | ||
this.debug("[Experiment] variant for ".concat(key, " is ").concat(variant.value)); | ||
return variant; | ||
@@ -1132,3 +1089,3 @@ }; | ||
} | ||
this.debug("[Experiment] Fetch all: retry=" + retry); | ||
this.debug("[Experiment] Fetch all: retry=".concat(retry)); | ||
// Proactively cancel retries if active in order to avoid unecessary API | ||
@@ -1169,7 +1126,7 @@ // requests. A new failure will restart the retries. | ||
if (this.config.debug) { | ||
queryString = "?d=" + randomString(8); | ||
queryString = "?d=".concat(randomString(8)); | ||
} | ||
endpoint = this.config.serverUrl + "/sdk/vardata" + queryString; | ||
endpoint = "".concat(this.config.serverUrl, "/sdk/vardata").concat(queryString); | ||
headers = { | ||
Authorization: "Api-Key " + this.apiKey, | ||
Authorization: "Api-Key ".concat(this.apiKey), | ||
'X-Amp-Exp-User': encodedContext, | ||
@@ -1185,3 +1142,3 @@ }; | ||
if (response.status != 200) { | ||
throw Error("Fetch error response: status=" + response.status); | ||
throw Error("Fetch error response: status=".concat(response.status)); | ||
} | ||
@@ -1255,3 +1212,3 @@ this.debug('[Experiment] Received fetch response: ', response); | ||
var mergedUserProperties = __assign(__assign({}, user === null || user === void 0 ? void 0 : user.user_properties), providedUser === null || providedUser === void 0 ? void 0 : providedUser.user_properties); | ||
return __assign(__assign(__assign({ library: "experiment-js-client/" + version }, (_b = this.userProvider) === null || _b === void 0 ? void 0 : _b.getUser()), user), { user_properties: mergedUserProperties }); | ||
return __assign(__assign(__assign({ library: "experiment-js-client/".concat(version) }, (_b = this.userProvider) === null || _b === void 0 ? void 0 : _b.getUser()), user), { user_properties: mergedUserProperties }); | ||
}; | ||
@@ -1330,3 +1287,3 @@ ExperimentClient.prototype.addContextOrWait = function (user, ms) { | ||
if (this.config.debug) { | ||
console.debug.apply(console, __spreadArrays([message], optionalParams)); | ||
console.debug.apply(console, __spreadArray([message], optionalParams, false)); | ||
} | ||
@@ -1349,3 +1306,3 @@ }; | ||
var instanceName = (config === null || config === void 0 ? void 0 : config.instanceName) || Defaults.instanceName; | ||
var instanceKey = instanceName + "." + apiKey; | ||
var instanceKey = "".concat(instanceName, ".").concat(apiKey); | ||
var connector = AnalyticsConnector.getInstance(instanceName); | ||
@@ -1373,3 +1330,3 @@ if (!instances[instanceKey]) { | ||
var instanceName = (config === null || config === void 0 ? void 0 : config.instanceName) || Defaults.instanceName; | ||
var instanceKey = instanceName + "." + apiKey; | ||
var instanceKey = "".concat(instanceName, ".").concat(apiKey); | ||
var connector = AnalyticsConnector.getInstance(instanceName); | ||
@@ -1376,0 +1333,0 @@ if (!instances[instanceKey]) { |
import { ExperimentAnalyticsEvent, ExperimentAnalyticsProvider } from '../types/analytics'; | ||
import { ExperimentUserProvider } from '../types/provider'; | ||
import { ExperimentUser } from '../types/user'; | ||
declare type AmplitudeIdentify = { | ||
type AmplitudeIdentify = { | ||
set(property: string, value: unknown): void; | ||
unset(property: string): void; | ||
}; | ||
declare type AmplitudeInstance = { | ||
type AmplitudeInstance = { | ||
options?: AmplitudeOptions; | ||
@@ -15,3 +15,3 @@ _ua?: AmplitudeUAParser; | ||
}; | ||
declare type AmplitudeOptions = { | ||
type AmplitudeOptions = { | ||
deviceId?: string; | ||
@@ -23,3 +23,3 @@ userId?: string; | ||
}; | ||
declare type AmplitudeUAParser = { | ||
type AmplitudeUAParser = { | ||
browser?: { | ||
@@ -26,0 +26,0 @@ name?: string; |
import { ExperimentUserProvider } from './provider'; | ||
import { ExperimentUser } from './user'; | ||
import { Variant, Variants } from './variant'; | ||
export declare type FetchOptions = { | ||
export type FetchOptions = { | ||
flagKeys: string[]; | ||
@@ -6,0 +6,0 @@ }; |
@@ -26,3 +26,3 @@ /** | ||
*/ | ||
export declare type Exposure = { | ||
export type Exposure = { | ||
flag_key: string; | ||
@@ -29,0 +29,0 @@ variant?: string; |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
export declare type ExperimentUser = { | ||
export type ExperimentUser = { | ||
/** | ||
@@ -11,0 +11,0 @@ * Device ID for associating with an identity in Amplitude |
/** | ||
* @category Types | ||
*/ | ||
export declare type Variant = { | ||
export type Variant = { | ||
/** | ||
@@ -17,4 +17,4 @@ * The value of the variant. | ||
*/ | ||
export declare type Variants = { | ||
export type Variants = { | ||
[key: string]: Variant; | ||
}; |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
export declare const safeGlobal: typeof globalThis | (NodeJS.Global & typeof globalThis); | ||
export declare const safeGlobal: typeof globalThis; |
{ | ||
"name": "@amplitude/experiment-js-client", | ||
"version": "1.7.3", | ||
"version": "1.7.4", | ||
"description": "Amplitude Experiment Javascript Client SDK", | ||
@@ -37,3 +37,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@amplitude/analytics-connector": "^1.4.6", | ||
"@amplitude/analytics-connector": "^1.4.7", | ||
"base64-js": "1.5.1", | ||
@@ -49,3 +49,3 @@ "unfetch": "4.1.0" | ||
], | ||
"gitHead": "55991bd7696f4092a2b7ecd1e0a33d988352bbd3" | ||
"gitHead": "af1adbad4304115aa81e1f22d20932dde768c8ef" | ||
} |
Sorry, the diff of this file is too big to display
5496
228051
31