@amplitude/analytics-core
Advanced tools
Comparing version 0.2.4 to 0.3.0
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plugin, ServerZone } from '@amplitude/analytics-types'; | ||
import { Logger } from './logger'; | ||
export declare const serverUrls: { | ||
US: (useBatch: boolean) => "https://api2.amplitude.com/2/httpapi" | "https://api2.amplitude.com/batch"; | ||
EU: (useBatch: boolean) => "https://api.eu.amplitude.com/2/httpapi" | "https://api.eu.amplitude.com/batch"; | ||
}; | ||
export declare const defaultConfig: { | ||
export declare const getDefaultConfig: () => { | ||
flushMaxRetries: number; | ||
@@ -15,2 +11,3 @@ flushQueueSize: number; | ||
optOut: boolean; | ||
plugins: never[]; | ||
serverUrl: string; | ||
@@ -22,2 +19,3 @@ serverZone: ServerZone; | ||
apiKey: string; | ||
appVersion?: string; | ||
userId?: string; | ||
@@ -42,6 +40,7 @@ deviceId?: string; | ||
} | ||
export declare const createConfig: (config: IConfig) => IConfig; | ||
export declare const getConfig: () => IConfig; | ||
export declare const resetInstances: () => void; | ||
export declare const getApiHost: (config: IConfig) => string; | ||
export declare const getServerUrl: (serverZone: ServerZone, useBatch: boolean) => "https://api2.amplitude.com/2/httpapi" | "https://api.eu.amplitude.com/2/httpapi" | "https://api2.amplitude.com/batch" | "https://api.eu.amplitude.com/batch"; | ||
export declare const createServerConfig: (serverZone?: ServerZone, useBatch?: boolean) => { | ||
serverZone: ServerZone; | ||
serverUrl: string; | ||
}; | ||
//# sourceMappingURL=config.d.ts.map |
@@ -1,14 +0,7 @@ | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getApiHost = exports.resetInstances = exports.getConfig = exports.createConfig = exports.Config = exports.defaultConfig = exports.serverUrls = void 0; | ||
exports.createServerConfig = exports.getServerUrl = exports.Config = exports.getDefaultConfig = void 0; | ||
var analytics_types_1 = require("@amplitude/analytics-types"); | ||
var constants_1 = require("./constants"); | ||
var logger_1 = require("./logger"); | ||
var DEFAULT_INSTANCE = 'default'; | ||
var instances = {}; | ||
exports.serverUrls = (_a = {}, | ||
_a[analytics_types_1.ServerZone.US] = function (useBatch) { return (useBatch ? constants_1.AMPLITUDE_BATCH_SERVER_URL : constants_1.AMPLITUDE_SERVER_URL); }, | ||
_a[analytics_types_1.ServerZone.EU] = function (useBatch) { return (useBatch ? constants_1.EU_AMPLITUDE_BATCH_SERVER_URL : constants_1.EU_AMPLITUDE_SERVER_URL); }, | ||
_a); | ||
exports.defaultConfig = { | ||
var getDefaultConfig = function () { return ({ | ||
flushMaxRetries: 5, | ||
@@ -21,29 +14,35 @@ flushQueueSize: 10, | ||
optOut: false, | ||
plugins: [], | ||
serverUrl: constants_1.AMPLITUDE_SERVER_URL, | ||
serverZone: analytics_types_1.ServerZone.US, | ||
useBatch: false, | ||
}; | ||
}); }; | ||
exports.getDefaultConfig = getDefaultConfig; | ||
var Config = /** @class */ (function () { | ||
function Config(options) { | ||
var _a, _b, _c, _d; | ||
var defaultConfig = (0, exports.getDefaultConfig)(); | ||
this.apiKey = options.apiKey; | ||
this.appVersion = options.appVersion; | ||
this.userId = options.userId; | ||
this.deviceId = options.deviceId; | ||
this.sessionId = options.sessionId; | ||
this.flushIntervalMillis = options.flushIntervalMillis || exports.defaultConfig.flushIntervalMillis; | ||
this.flushMaxRetries = options.flushMaxRetries || exports.defaultConfig.flushMaxRetries; | ||
this.flushQueueSize = options.flushQueueSize || exports.defaultConfig.flushQueueSize; | ||
this.loggerProvider = options.loggerProvider || exports.defaultConfig.loggerProvider; | ||
this.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : exports.defaultConfig.logLevel; | ||
this.flushIntervalMillis = options.flushIntervalMillis || defaultConfig.flushIntervalMillis; | ||
this.flushMaxRetries = options.flushMaxRetries || defaultConfig.flushMaxRetries; | ||
this.flushQueueSize = options.flushQueueSize || defaultConfig.flushQueueSize; | ||
this.loggerProvider = options.loggerProvider || defaultConfig.loggerProvider; | ||
this.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : defaultConfig.logLevel; | ||
this.partnerId = options.partnerId; | ||
this.plugins = []; | ||
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b : exports.defaultConfig.optOut; | ||
this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c : exports.defaultConfig.saveEvents; | ||
this.plugins = defaultConfig.plugins; | ||
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b : defaultConfig.optOut; | ||
this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c : defaultConfig.saveEvents; | ||
this.serverUrl = options.serverUrl; | ||
this.serverZone = options.serverZone || exports.defaultConfig.serverZone; | ||
this.serverZone = options.serverZone || defaultConfig.serverZone; | ||
this.storageProvider = options.storageProvider; | ||
this.transportProvider = options.transportProvider; | ||
this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : exports.defaultConfig.useBatch; | ||
this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : defaultConfig.useBatch; | ||
this.loggerProvider.enable(this.logLevel); | ||
configApiHost(this); | ||
var serverConfig = (0, exports.createServerConfig)(options.serverZone, options.useBatch); | ||
this.serverZone = serverConfig.serverZone; | ||
this.serverUrl = serverConfig.serverUrl; | ||
} | ||
@@ -53,36 +52,19 @@ return Config; | ||
exports.Config = Config; | ||
var createConfig = function (config) { | ||
// If config for an instance already exists, perform Object.assign() to reuse reference | ||
// to config object. This is useful when config object reference is used in plugins | ||
instances[DEFAULT_INSTANCE] = instances[DEFAULT_INSTANCE] | ||
? Object.assign(instances[DEFAULT_INSTANCE], config) | ||
: config; | ||
return instances[DEFAULT_INSTANCE]; | ||
}; | ||
exports.createConfig = createConfig; | ||
var getConfig = function () { | ||
return instances[DEFAULT_INSTANCE]; | ||
}; | ||
exports.getConfig = getConfig; | ||
var resetInstances = function () { | ||
for (var name in instances) { | ||
delete instances[name]; | ||
var getServerUrl = function (serverZone, useBatch) { | ||
if (serverZone === analytics_types_1.ServerZone.EU) { | ||
return useBatch ? constants_1.EU_AMPLITUDE_BATCH_SERVER_URL : constants_1.EU_AMPLITUDE_SERVER_URL; | ||
} | ||
return useBatch ? constants_1.AMPLITUDE_BATCH_SERVER_URL : constants_1.AMPLITUDE_SERVER_URL; | ||
}; | ||
exports.resetInstances = resetInstances; | ||
var getApiHost = function (config) { | ||
return configApiHost(config); | ||
exports.getServerUrl = getServerUrl; | ||
var createServerConfig = function (serverZone, useBatch) { | ||
if (serverZone === void 0) { serverZone = (0, exports.getDefaultConfig)().serverZone; } | ||
if (useBatch === void 0) { useBatch = (0, exports.getDefaultConfig)().useBatch; } | ||
var _serverZone = [analytics_types_1.ServerZone.US, analytics_types_1.ServerZone.EU].includes(serverZone) ? serverZone : (0, exports.getDefaultConfig)().serverZone; | ||
return { | ||
serverZone: _serverZone, | ||
serverUrl: (0, exports.getServerUrl)(_serverZone, useBatch), | ||
}; | ||
}; | ||
exports.getApiHost = getApiHost; | ||
var configApiHost = function (config) { | ||
if (!config.serverUrl) { | ||
// Log a warning if server zone is neither US nor EU | ||
if (![analytics_types_1.ServerZone.US, analytics_types_1.ServerZone.EU].includes(config.serverZone)) { | ||
config.loggerProvider.warn("Unknown server zone \"".concat(config.serverZone, "\". Replaced with US server zone")); | ||
config.serverZone = analytics_types_1.ServerZone.US; | ||
} | ||
config.serverUrl = exports.serverUrls[config.serverZone](config.useBatch); | ||
} | ||
return config.serverUrl; | ||
}; | ||
exports.createServerConfig = createServerConfig; | ||
//# sourceMappingURL=config.js.map |
@@ -1,13 +0,18 @@ | ||
import { Config, Event, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types'; | ||
export declare const init: (config: Config) => Config; | ||
export declare const track: (eventType: string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const logEvent: (eventType: string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const identify: (userId: string | undefined, deviceId: string | undefined, identify: Identify, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const groupIdentify: (userId: string | undefined, deviceId: string | undefined, groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const setGroup: (groupType: string, groupName: string | string[]) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const revenue: (revenue: Revenue, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const add: (plugin: Plugin) => Promise<void>; | ||
export declare const remove: (pluginName: string) => Promise<void>; | ||
export declare const dispatch: (event: Event, config: Config) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const setOptOut: (optOut: boolean) => void; | ||
import { Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types'; | ||
export declare class AmplitudeCore<T extends Config> { | ||
name: string; | ||
config: T; | ||
constructor(name?: string); | ||
init(_apiKey: string | undefined, _userId: string | undefined, config: T): Promise<void>; | ||
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>; | ||
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
identify(identify: Identify, eventOptions?: EventOptions, userId?: string, deviceId?: string): Promise<import("@amplitude/analytics-types").Result>; | ||
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions, userId?: string, deviceId?: string): Promise<import("@amplitude/analytics-types").Result>; | ||
setGroup(groupType: string, groupName: string | string[]): Promise<import("@amplitude/analytics-types").Result>; | ||
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>; | ||
add(plugin: Plugin): Promise<void>; | ||
remove(pluginName: string): Promise<void>; | ||
dispatch(event: Event): Promise<import("@amplitude/analytics-types").Result>; | ||
setOptOut(optOut: boolean): void; | ||
} | ||
//# sourceMappingURL=core-client.d.ts.map |
@@ -1,91 +0,90 @@ | ||
var _this = this; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setOptOut = exports.dispatch = exports.remove = exports.add = exports.revenue = exports.setGroup = exports.groupIdentify = exports.identify = exports.logEvent = exports.track = exports.init = void 0; | ||
exports.AmplitudeCore = void 0; | ||
var tslib_1 = require("tslib"); | ||
var config_1 = require("./config"); | ||
var event_builder_1 = require("./utils/event-builder"); | ||
var timeline_1 = require("./timeline"); | ||
var result_builder_1 = require("./utils/result-builder"); | ||
var init = function (config) { | ||
return (0, config_1.createConfig)(config); | ||
}; | ||
exports.init = init; | ||
var track = function (eventType, eventProperties, eventOptions) { | ||
var config = (0, config_1.getConfig)(); | ||
var event = (0, event_builder_1.createTrackEvent)(eventType, eventProperties, eventOptions); | ||
return (0, exports.dispatch)(event, config); | ||
}; | ||
exports.track = track; | ||
exports.logEvent = exports.track; | ||
var identify = function (userId, deviceId, identify, eventOptions) { | ||
var config = (0, config_1.getConfig)(); | ||
var event = (0, event_builder_1.createIdentifyEvent)(userId, deviceId, identify, eventOptions); | ||
return (0, exports.dispatch)(event, config); | ||
}; | ||
exports.identify = identify; | ||
var groupIdentify = function (userId, deviceId, groupType, groupName, identify, eventOptions) { | ||
var config = (0, config_1.getConfig)(); | ||
var event = (0, event_builder_1.createGroupIdentifyEvent)(userId, deviceId, groupType, groupName, identify, eventOptions); | ||
return (0, exports.dispatch)(event, config); | ||
}; | ||
exports.groupIdentify = groupIdentify; | ||
var setGroup = function (groupType, groupName) { | ||
var config = (0, config_1.getConfig)(); | ||
var event = (0, event_builder_1.createGroupEvent)(groupType, groupName); | ||
return (0, exports.dispatch)(event, config); | ||
}; | ||
exports.setGroup = setGroup; | ||
var revenue = function (revenue, eventOptions) { | ||
var config = (0, config_1.getConfig)(); | ||
var event = (0, event_builder_1.createRevenueEvent)(revenue, eventOptions); | ||
return (0, exports.dispatch)(event, config); | ||
}; | ||
exports.revenue = revenue; | ||
var add = function (plugin) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { | ||
var config; | ||
return (0, tslib_1.__generator)(this, function (_a) { | ||
config = (0, config_1.getConfig)(); | ||
return [2 /*return*/, (0, timeline_1.register)(plugin, config)]; | ||
}); | ||
}); }; | ||
exports.add = add; | ||
var remove = function (pluginName) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { | ||
var config; | ||
return (0, tslib_1.__generator)(this, function (_a) { | ||
config = (0, config_1.getConfig)(); | ||
return [2 /*return*/, (0, timeline_1.deregister)(pluginName, config)]; | ||
}); | ||
}); }; | ||
exports.remove = remove; | ||
var dispatch = function (event, config) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { | ||
var result, e_1, message; | ||
return (0, tslib_1.__generator)(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, (0, timeline_1.push)(event, config)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (result.code === 200) { | ||
config.loggerProvider.log(result.message); | ||
var AmplitudeCore = /** @class */ (function () { | ||
function AmplitudeCore(name) { | ||
if (name === void 0) { name = '$default'; } | ||
this.logEvent = this.track.bind(this); | ||
this.name = name; | ||
} | ||
// NOTE: Do not use `_apiKey` and `_userId` here | ||
AmplitudeCore.prototype.init = function (_apiKey, _userId, config) { | ||
this.config = config; | ||
return Promise.resolve(); | ||
}; | ||
AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) { | ||
var event = (0, event_builder_1.createTrackEvent)(eventInput, eventProperties, eventOptions); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.identify = function (identify, eventOptions, userId, deviceId) { | ||
var event = (0, event_builder_1.createIdentifyEvent)(userId, deviceId, identify, eventOptions); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.groupIdentify = function (groupType, groupName, identify, eventOptions, userId, deviceId) { | ||
var event = (0, event_builder_1.createGroupIdentifyEvent)(userId, deviceId, groupType, groupName, identify, eventOptions); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.setGroup = function (groupType, groupName) { | ||
var event = (0, event_builder_1.createGroupEvent)(groupType, groupName); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.revenue = function (revenue, eventOptions) { | ||
var event = (0, event_builder_1.createRevenueEvent)(revenue, eventOptions); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.add = function (plugin) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { | ||
var config; | ||
return (0, tslib_1.__generator)(this, function (_a) { | ||
config = this.config; | ||
return [2 /*return*/, (0, timeline_1.register)(plugin, config)]; | ||
}); | ||
}); | ||
}; | ||
AmplitudeCore.prototype.remove = function (pluginName) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { | ||
var config; | ||
return (0, tslib_1.__generator)(this, function (_a) { | ||
config = this.config; | ||
return [2 /*return*/, (0, timeline_1.deregister)(pluginName, config)]; | ||
}); | ||
}); | ||
}; | ||
AmplitudeCore.prototype.dispatch = function (event) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { | ||
var result, e_1, message; | ||
return (0, tslib_1.__generator)(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, (0, timeline_1.push)(event, this.config)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (result.code === 200) { | ||
this.config.loggerProvider.log(result.message); | ||
} | ||
else { | ||
this.config.loggerProvider.error(result.message); | ||
} | ||
return [2 /*return*/, result]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
message = String(e_1); | ||
this.config.loggerProvider.error(message); | ||
return [2 /*return*/, (0, result_builder_1.buildResult)(event, 0, message)]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
else { | ||
config.loggerProvider.error(result.message); | ||
} | ||
return [2 /*return*/, result]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
message = String(e_1); | ||
config.loggerProvider.error(message); | ||
return [2 /*return*/, (0, result_builder_1.buildResult)(event, 0, message)]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
exports.dispatch = dispatch; | ||
var setOptOut = function (optOut) { | ||
var config = (0, config_1.getConfig)(); | ||
config.optOut = Boolean(optOut); | ||
}; | ||
exports.setOptOut = setOptOut; | ||
}); | ||
}); | ||
}; | ||
AmplitudeCore.prototype.setOptOut = function (optOut) { | ||
var config = this.config; | ||
config.optOut = Boolean(optOut); | ||
}; | ||
return AmplitudeCore; | ||
}()); | ||
exports.AmplitudeCore = AmplitudeCore; | ||
//# sourceMappingURL=core-client.js.map |
@@ -1,3 +0,2 @@ | ||
export { init, track, logEvent, identify, groupIdentify, setGroup, revenue, add, remove, setOptOut, } from './core-client'; | ||
export { getConfig } from './config'; | ||
export { AmplitudeCore } from './core-client'; | ||
export { buildResponse } from './utils/response-builder'; | ||
@@ -10,2 +9,3 @@ export { Identify } from './identify'; | ||
export { AMPLITUDE_PREFIX } from './constants'; | ||
export { returnWrapper } from './utils/return-wrapper'; | ||
//# sourceMappingURL=index.d.ts.map |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.buildResponse = exports.getConfig = exports.setOptOut = exports.remove = exports.add = exports.revenue = exports.setGroup = exports.groupIdentify = exports.identify = exports.logEvent = exports.track = exports.init = void 0; | ||
exports.returnWrapper = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.buildResponse = exports.AmplitudeCore = void 0; | ||
var core_client_1 = require("./core-client"); | ||
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return core_client_1.init; } }); | ||
Object.defineProperty(exports, "track", { enumerable: true, get: function () { return core_client_1.track; } }); | ||
Object.defineProperty(exports, "logEvent", { enumerable: true, get: function () { return core_client_1.logEvent; } }); | ||
Object.defineProperty(exports, "identify", { enumerable: true, get: function () { return core_client_1.identify; } }); | ||
Object.defineProperty(exports, "groupIdentify", { enumerable: true, get: function () { return core_client_1.groupIdentify; } }); | ||
Object.defineProperty(exports, "setGroup", { enumerable: true, get: function () { return core_client_1.setGroup; } }); | ||
Object.defineProperty(exports, "revenue", { enumerable: true, get: function () { return core_client_1.revenue; } }); | ||
Object.defineProperty(exports, "add", { enumerable: true, get: function () { return core_client_1.add; } }); | ||
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return core_client_1.remove; } }); | ||
Object.defineProperty(exports, "setOptOut", { enumerable: true, get: function () { return core_client_1.setOptOut; } }); | ||
var config_1 = require("./config"); | ||
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } }); | ||
Object.defineProperty(exports, "AmplitudeCore", { enumerable: true, get: function () { return core_client_1.AmplitudeCore; } }); | ||
var response_builder_1 = require("./utils/response-builder"); | ||
@@ -24,4 +13,4 @@ Object.defineProperty(exports, "buildResponse", { enumerable: true, get: function () { return response_builder_1.buildResponse; } }); | ||
Object.defineProperty(exports, "Destination", { enumerable: true, get: function () { return destination_1.Destination; } }); | ||
var config_2 = require("./config"); | ||
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_2.Config; } }); | ||
var config_1 = require("./config"); | ||
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } }); | ||
var logger_1 = require("./logger"); | ||
@@ -31,2 +20,4 @@ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } }); | ||
Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return constants_1.AMPLITUDE_PREFIX; } }); | ||
var return_wrapper_1 = require("./utils/return-wrapper"); | ||
Object.defineProperty(exports, "returnWrapper", { enumerable: true, get: function () { return return_wrapper_1.returnWrapper; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ export declare const SUCCESS_MESSAGE = "Event tracked successfully"; | ||
export declare const OPT_OUT_MESSAGE = "Event skipped due to optOut config"; | ||
export declare const MISSING_API_KEY_MESSAGE = "Event skipped due to optOut config"; | ||
export declare const MISSING_API_KEY_MESSAGE = "Event rejected due to missing API key"; | ||
//# sourceMappingURL=messages.d.ts.map |
@@ -7,3 +7,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OPT_OUT_MESSAGE = 'Event skipped due to optOut config'; | ||
exports.MISSING_API_KEY_MESSAGE = 'Event skipped due to optOut config'; | ||
exports.MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key'; | ||
//# sourceMappingURL=messages.js.map |
@@ -107,3 +107,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { | ||
var payload, res, e_1; | ||
var payload, serverUrl, res, e_1; | ||
return (0, tslib_1.__generator)(this, function (_a) { | ||
@@ -122,3 +122,4 @@ switch (_a.label) { | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.config.transportProvider.send((0, config_1.getApiHost)(this.config), payload)]; | ||
serverUrl = (0, config_1.createServerConfig)(this.config.serverZone, this.config.useBatch).serverUrl; | ||
return [4 /*yield*/, this.config.transportProvider.send(serverUrl, payload)]; | ||
case 2: | ||
@@ -169,3 +170,3 @@ res = _a.sent(); | ||
} | ||
var dropIndex = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(Object.values(res.body.eventsWithInvalidFields)), false), (0, tslib_1.__read)(Object.values(res.body.eventsWithMissingFields)), false), (0, tslib_1.__read)(res.body.silencedEvents), false).flat(); | ||
var dropIndex = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(Object.values(res.body.eventsWithInvalidFields)), false), (0, tslib_1.__read)(Object.values(res.body.eventsWithMissingFields)), false), (0, tslib_1.__read)(Object.values(res.body.eventsWithInvalidIdLengths)), false), (0, tslib_1.__read)(res.body.silencedEvents), false).flat(); | ||
var dropIndexSet = new Set(dropIndex); | ||
@@ -172,0 +173,0 @@ var retry = list.filter(function (context, index) { |
@@ -1,3 +0,3 @@ | ||
import { TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as IIdentify, Revenue, RevenueEvent, EventOptions } from '@amplitude/analytics-types'; | ||
export declare const createTrackEvent: (eventType: string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent; | ||
import { BaseEvent, TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as IIdentify, Revenue, RevenueEvent, EventOptions } from '@amplitude/analytics-types'; | ||
export declare const createTrackEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent; | ||
export declare const createIdentifyEvent: (userId: string | undefined, deviceId: string | undefined, identify: IIdentify, eventOptions?: EventOptions | undefined) => IdentifyEvent; | ||
@@ -4,0 +4,0 @@ export declare const createGroupIdentifyEvent: (userId: string | undefined, deviceId: string | undefined, groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => GroupIdentifyEvent; |
@@ -6,4 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var identify_1 = require("../identify"); | ||
var createTrackEvent = function (eventType, eventProperties, eventOptions) { | ||
return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventOptions), { event_type: eventType }), (eventProperties && { event_properties: eventProperties })); | ||
var createTrackEvent = function (eventInput, eventProperties, eventOptions) { | ||
var baseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput; | ||
return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, baseEvent), eventOptions), (eventProperties && { event_properties: eventProperties })); | ||
}; | ||
@@ -10,0 +11,0 @@ exports.createTrackEvent = createTrackEvent; |
@@ -9,3 +9,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var buildResponse = function (responseJSON) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; | ||
if (typeof responseJSON !== 'object') { | ||
@@ -36,8 +36,9 @@ return null; | ||
eventsWithMissingFields: (_g = responseJSON.events_with_missing_fields) !== null && _g !== void 0 ? _g : {}, | ||
epsThreshold: (_h = responseJSON.eps_threshold) !== null && _h !== void 0 ? _h : 0, | ||
exceededDailyQuotaDevices: (_j = responseJSON.exceeded_daily_quota_devices) !== null && _j !== void 0 ? _j : {}, | ||
silencedDevices: (_k = responseJSON.silenced_devices) !== null && _k !== void 0 ? _k : [], | ||
silencedEvents: (_l = responseJSON.silenced_events) !== null && _l !== void 0 ? _l : [], | ||
throttledDevices: (_m = responseJSON.throttled_devices) !== null && _m !== void 0 ? _m : {}, | ||
throttledEvents: (_o = responseJSON.throttled_events) !== null && _o !== void 0 ? _o : [], | ||
eventsWithInvalidIdLengths: (_h = responseJSON.events_with_invalid_id_lengths) !== null && _h !== void 0 ? _h : {}, | ||
epsThreshold: (_j = responseJSON.eps_threshold) !== null && _j !== void 0 ? _j : 0, | ||
exceededDailyQuotaDevices: (_k = responseJSON.exceeded_daily_quota_devices) !== null && _k !== void 0 ? _k : {}, | ||
silencedDevices: (_l = responseJSON.silenced_devices) !== null && _l !== void 0 ? _l : [], | ||
silencedEvents: (_m = responseJSON.silenced_events) !== null && _m !== void 0 ? _m : [], | ||
throttledDevices: (_o = responseJSON.throttled_devices) !== null && _o !== void 0 ? _o : {}, | ||
throttledEvents: (_p = responseJSON.throttled_events) !== null && _p !== void 0 ? _p : [], | ||
}, | ||
@@ -50,3 +51,3 @@ }; | ||
body: { | ||
error: (_p = responseJSON.error) !== null && _p !== void 0 ? _p : '', | ||
error: (_q = responseJSON.error) !== null && _q !== void 0 ? _q : '', | ||
}, | ||
@@ -59,9 +60,9 @@ }; | ||
body: { | ||
error: (_q = responseJSON.error) !== null && _q !== void 0 ? _q : '', | ||
epsThreshold: (_r = responseJSON.eps_threshold) !== null && _r !== void 0 ? _r : 0, | ||
throttledDevices: (_s = responseJSON.throttled_devices) !== null && _s !== void 0 ? _s : {}, | ||
throttledUsers: (_t = responseJSON.throttled_users) !== null && _t !== void 0 ? _t : {}, | ||
exceededDailyQuotaDevices: (_u = responseJSON.exceeded_daily_quota_devices) !== null && _u !== void 0 ? _u : {}, | ||
exceededDailyQuotaUsers: (_v = responseJSON.exceeded_daily_quota_users) !== null && _v !== void 0 ? _v : {}, | ||
throttledEvents: (_w = responseJSON.throttled_events) !== null && _w !== void 0 ? _w : [], | ||
error: (_r = responseJSON.error) !== null && _r !== void 0 ? _r : '', | ||
epsThreshold: (_s = responseJSON.eps_threshold) !== null && _s !== void 0 ? _s : 0, | ||
throttledDevices: (_t = responseJSON.throttled_devices) !== null && _t !== void 0 ? _t : {}, | ||
throttledUsers: (_u = responseJSON.throttled_users) !== null && _u !== void 0 ? _u : {}, | ||
exceededDailyQuotaDevices: (_v = responseJSON.exceeded_daily_quota_devices) !== null && _v !== void 0 ? _v : {}, | ||
exceededDailyQuotaUsers: (_w = responseJSON.exceeded_daily_quota_users) !== null && _w !== void 0 ? _w : {}, | ||
throttledEvents: (_x = responseJSON.throttled_events) !== null && _x !== void 0 ? _x : [], | ||
}, | ||
@@ -68,0 +69,0 @@ }; |
@@ -23,2 +23,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
if (Array.isArray(value)) { | ||
var isValid = true; | ||
try { | ||
@@ -31,3 +32,3 @@ for (var value_1 = (0, tslib_1.__values)(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) { | ||
else if (typeof valueElement === 'object') { | ||
return (0, exports.isValidObject)(value); | ||
isValid = isValid && (0, exports.isValidObject)(valueElement); | ||
} | ||
@@ -37,2 +38,5 @@ else if (!['number', 'string'].includes(typeof valueElement)) { | ||
} | ||
if (!isValid) { | ||
return false; | ||
} | ||
} | ||
@@ -39,0 +43,0 @@ } |
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plugin, ServerZone } from '@amplitude/analytics-types'; | ||
import { Logger } from './logger'; | ||
export declare const serverUrls: { | ||
US: (useBatch: boolean) => "https://api2.amplitude.com/2/httpapi" | "https://api2.amplitude.com/batch"; | ||
EU: (useBatch: boolean) => "https://api.eu.amplitude.com/2/httpapi" | "https://api.eu.amplitude.com/batch"; | ||
}; | ||
export declare const defaultConfig: { | ||
export declare const getDefaultConfig: () => { | ||
flushMaxRetries: number; | ||
@@ -15,2 +11,3 @@ flushQueueSize: number; | ||
optOut: boolean; | ||
plugins: never[]; | ||
serverUrl: string; | ||
@@ -22,2 +19,3 @@ serverZone: ServerZone; | ||
apiKey: string; | ||
appVersion?: string; | ||
userId?: string; | ||
@@ -42,6 +40,7 @@ deviceId?: string; | ||
} | ||
export declare const createConfig: (config: IConfig) => IConfig; | ||
export declare const getConfig: () => IConfig; | ||
export declare const resetInstances: () => void; | ||
export declare const getApiHost: (config: IConfig) => string; | ||
export declare const getServerUrl: (serverZone: ServerZone, useBatch: boolean) => "https://api2.amplitude.com/2/httpapi" | "https://api.eu.amplitude.com/2/httpapi" | "https://api2.amplitude.com/batch" | "https://api.eu.amplitude.com/batch"; | ||
export declare const createServerConfig: (serverZone?: ServerZone, useBatch?: boolean) => { | ||
serverZone: ServerZone; | ||
serverUrl: string; | ||
}; | ||
//# sourceMappingURL=config.d.ts.map |
@@ -1,12 +0,5 @@ | ||
var _a; | ||
import { LogLevel, ServerZone, } from '@amplitude/analytics-types'; | ||
import { AMPLITUDE_SERVER_URL, AMPLITUDE_BATCH_SERVER_URL, EU_AMPLITUDE_SERVER_URL, EU_AMPLITUDE_BATCH_SERVER_URL, } from './constants'; | ||
import { Logger } from './logger'; | ||
var DEFAULT_INSTANCE = 'default'; | ||
var instances = {}; | ||
export var serverUrls = (_a = {}, | ||
_a[ServerZone.US] = function (useBatch) { return (useBatch ? AMPLITUDE_BATCH_SERVER_URL : AMPLITUDE_SERVER_URL); }, | ||
_a[ServerZone.EU] = function (useBatch) { return (useBatch ? EU_AMPLITUDE_BATCH_SERVER_URL : EU_AMPLITUDE_SERVER_URL); }, | ||
_a); | ||
export var defaultConfig = { | ||
export var getDefaultConfig = function () { return ({ | ||
flushMaxRetries: 5, | ||
@@ -19,10 +12,13 @@ flushQueueSize: 10, | ||
optOut: false, | ||
plugins: [], | ||
serverUrl: AMPLITUDE_SERVER_URL, | ||
serverZone: ServerZone.US, | ||
useBatch: false, | ||
}; | ||
}); }; | ||
var Config = /** @class */ (function () { | ||
function Config(options) { | ||
var _a, _b, _c, _d; | ||
var defaultConfig = getDefaultConfig(); | ||
this.apiKey = options.apiKey; | ||
this.appVersion = options.appVersion; | ||
this.userId = options.userId; | ||
@@ -37,3 +33,3 @@ this.deviceId = options.deviceId; | ||
this.partnerId = options.partnerId; | ||
this.plugins = []; | ||
this.plugins = defaultConfig.plugins; | ||
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b : defaultConfig.optOut; | ||
@@ -47,3 +43,5 @@ this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c : defaultConfig.saveEvents; | ||
this.loggerProvider.enable(this.logLevel); | ||
configApiHost(this); | ||
var serverConfig = createServerConfig(options.serverZone, options.useBatch); | ||
this.serverZone = serverConfig.serverZone; | ||
this.serverUrl = serverConfig.serverUrl; | ||
} | ||
@@ -53,32 +51,17 @@ return Config; | ||
export { Config }; | ||
export var createConfig = function (config) { | ||
// If config for an instance already exists, perform Object.assign() to reuse reference | ||
// to config object. This is useful when config object reference is used in plugins | ||
instances[DEFAULT_INSTANCE] = instances[DEFAULT_INSTANCE] | ||
? Object.assign(instances[DEFAULT_INSTANCE], config) | ||
: config; | ||
return instances[DEFAULT_INSTANCE]; | ||
}; | ||
export var getConfig = function () { | ||
return instances[DEFAULT_INSTANCE]; | ||
}; | ||
export var resetInstances = function () { | ||
for (var name in instances) { | ||
delete instances[name]; | ||
export var getServerUrl = function (serverZone, useBatch) { | ||
if (serverZone === ServerZone.EU) { | ||
return useBatch ? EU_AMPLITUDE_BATCH_SERVER_URL : EU_AMPLITUDE_SERVER_URL; | ||
} | ||
return useBatch ? AMPLITUDE_BATCH_SERVER_URL : AMPLITUDE_SERVER_URL; | ||
}; | ||
export var getApiHost = function (config) { | ||
return configApiHost(config); | ||
export var createServerConfig = function (serverZone, useBatch) { | ||
if (serverZone === void 0) { serverZone = getDefaultConfig().serverZone; } | ||
if (useBatch === void 0) { useBatch = getDefaultConfig().useBatch; } | ||
var _serverZone = [ServerZone.US, ServerZone.EU].includes(serverZone) ? serverZone : getDefaultConfig().serverZone; | ||
return { | ||
serverZone: _serverZone, | ||
serverUrl: getServerUrl(_serverZone, useBatch), | ||
}; | ||
}; | ||
var configApiHost = function (config) { | ||
if (!config.serverUrl) { | ||
// Log a warning if server zone is neither US nor EU | ||
if (![ServerZone.US, ServerZone.EU].includes(config.serverZone)) { | ||
config.loggerProvider.warn("Unknown server zone \"".concat(config.serverZone, "\". Replaced with US server zone")); | ||
config.serverZone = ServerZone.US; | ||
} | ||
config.serverUrl = serverUrls[config.serverZone](config.useBatch); | ||
} | ||
return config.serverUrl; | ||
}; | ||
//# sourceMappingURL=config.js.map |
@@ -1,13 +0,18 @@ | ||
import { Config, Event, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types'; | ||
export declare const init: (config: Config) => Config; | ||
export declare const track: (eventType: string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const logEvent: (eventType: string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const identify: (userId: string | undefined, deviceId: string | undefined, identify: Identify, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const groupIdentify: (userId: string | undefined, deviceId: string | undefined, groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const setGroup: (groupType: string, groupName: string | string[]) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const revenue: (revenue: Revenue, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const add: (plugin: Plugin) => Promise<void>; | ||
export declare const remove: (pluginName: string) => Promise<void>; | ||
export declare const dispatch: (event: Event, config: Config) => Promise<import("@amplitude/analytics-types").Result>; | ||
export declare const setOptOut: (optOut: boolean) => void; | ||
import { Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types'; | ||
export declare class AmplitudeCore<T extends Config> { | ||
name: string; | ||
config: T; | ||
constructor(name?: string); | ||
init(_apiKey: string | undefined, _userId: string | undefined, config: T): Promise<void>; | ||
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>; | ||
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>; | ||
identify(identify: Identify, eventOptions?: EventOptions, userId?: string, deviceId?: string): Promise<import("@amplitude/analytics-types").Result>; | ||
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions, userId?: string, deviceId?: string): Promise<import("@amplitude/analytics-types").Result>; | ||
setGroup(groupType: string, groupName: string | string[]): Promise<import("@amplitude/analytics-types").Result>; | ||
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>; | ||
add(plugin: Plugin): Promise<void>; | ||
remove(pluginName: string): Promise<void>; | ||
dispatch(event: Event): Promise<import("@amplitude/analytics-types").Result>; | ||
setOptOut(optOut: boolean): void; | ||
} | ||
//# sourceMappingURL=core-client.d.ts.map |
import { __awaiter, __generator } from "tslib"; | ||
import { createConfig, getConfig } from './config'; | ||
import { createGroupIdentifyEvent, createIdentifyEvent, createTrackEvent, createRevenueEvent, createGroupEvent, } from './utils/event-builder'; | ||
import { deregister, push, register } from './timeline'; | ||
import { buildResult } from './utils/result-builder'; | ||
export var init = function (config) { | ||
return createConfig(config); | ||
}; | ||
export var track = function (eventType, eventProperties, eventOptions) { | ||
var config = getConfig(); | ||
var event = createTrackEvent(eventType, eventProperties, eventOptions); | ||
return dispatch(event, config); | ||
}; | ||
export var logEvent = track; | ||
export var identify = function (userId, deviceId, identify, eventOptions) { | ||
var config = getConfig(); | ||
var event = createIdentifyEvent(userId, deviceId, identify, eventOptions); | ||
return dispatch(event, config); | ||
}; | ||
export var groupIdentify = function (userId, deviceId, groupType, groupName, identify, eventOptions) { | ||
var config = getConfig(); | ||
var event = createGroupIdentifyEvent(userId, deviceId, groupType, groupName, identify, eventOptions); | ||
return dispatch(event, config); | ||
}; | ||
export var setGroup = function (groupType, groupName) { | ||
var config = getConfig(); | ||
var event = createGroupEvent(groupType, groupName); | ||
return dispatch(event, config); | ||
}; | ||
export var revenue = function (revenue, eventOptions) { | ||
var config = getConfig(); | ||
var event = createRevenueEvent(revenue, eventOptions); | ||
return dispatch(event, config); | ||
}; | ||
export var add = function (plugin) { return __awaiter(void 0, void 0, void 0, function () { | ||
var config; | ||
return __generator(this, function (_a) { | ||
config = getConfig(); | ||
return [2 /*return*/, register(plugin, config)]; | ||
}); | ||
}); }; | ||
export var remove = function (pluginName) { return __awaiter(void 0, void 0, void 0, function () { | ||
var config; | ||
return __generator(this, function (_a) { | ||
config = getConfig(); | ||
return [2 /*return*/, deregister(pluginName, config)]; | ||
}); | ||
}); }; | ||
export var dispatch = function (event, config) { return __awaiter(void 0, void 0, void 0, function () { | ||
var result, e_1, message; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, push(event, config)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (result.code === 200) { | ||
config.loggerProvider.log(result.message); | ||
var AmplitudeCore = /** @class */ (function () { | ||
function AmplitudeCore(name) { | ||
if (name === void 0) { name = '$default'; } | ||
this.logEvent = this.track.bind(this); | ||
this.name = name; | ||
} | ||
// NOTE: Do not use `_apiKey` and `_userId` here | ||
AmplitudeCore.prototype.init = function (_apiKey, _userId, config) { | ||
this.config = config; | ||
return Promise.resolve(); | ||
}; | ||
AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) { | ||
var event = createTrackEvent(eventInput, eventProperties, eventOptions); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.identify = function (identify, eventOptions, userId, deviceId) { | ||
var event = createIdentifyEvent(userId, deviceId, identify, eventOptions); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.groupIdentify = function (groupType, groupName, identify, eventOptions, userId, deviceId) { | ||
var event = createGroupIdentifyEvent(userId, deviceId, groupType, groupName, identify, eventOptions); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.setGroup = function (groupType, groupName) { | ||
var event = createGroupEvent(groupType, groupName); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.revenue = function (revenue, eventOptions) { | ||
var event = createRevenueEvent(revenue, eventOptions); | ||
return this.dispatch(event); | ||
}; | ||
AmplitudeCore.prototype.add = function (plugin) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config; | ||
return __generator(this, function (_a) { | ||
config = this.config; | ||
return [2 /*return*/, register(plugin, config)]; | ||
}); | ||
}); | ||
}; | ||
AmplitudeCore.prototype.remove = function (pluginName) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config; | ||
return __generator(this, function (_a) { | ||
config = this.config; | ||
return [2 /*return*/, deregister(pluginName, config)]; | ||
}); | ||
}); | ||
}; | ||
AmplitudeCore.prototype.dispatch = function (event) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, e_1, message; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, push(event, this.config)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (result.code === 200) { | ||
this.config.loggerProvider.log(result.message); | ||
} | ||
else { | ||
this.config.loggerProvider.error(result.message); | ||
} | ||
return [2 /*return*/, result]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
message = String(e_1); | ||
this.config.loggerProvider.error(message); | ||
return [2 /*return*/, buildResult(event, 0, message)]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
else { | ||
config.loggerProvider.error(result.message); | ||
} | ||
return [2 /*return*/, result]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
message = String(e_1); | ||
config.loggerProvider.error(message); | ||
return [2 /*return*/, buildResult(event, 0, message)]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
export var setOptOut = function (optOut) { | ||
var config = getConfig(); | ||
config.optOut = Boolean(optOut); | ||
}; | ||
}); | ||
}); | ||
}; | ||
AmplitudeCore.prototype.setOptOut = function (optOut) { | ||
var config = this.config; | ||
config.optOut = Boolean(optOut); | ||
}; | ||
return AmplitudeCore; | ||
}()); | ||
export { AmplitudeCore }; | ||
//# sourceMappingURL=core-client.js.map |
@@ -1,3 +0,2 @@ | ||
export { init, track, logEvent, identify, groupIdentify, setGroup, revenue, add, remove, setOptOut, } from './core-client'; | ||
export { getConfig } from './config'; | ||
export { AmplitudeCore } from './core-client'; | ||
export { buildResponse } from './utils/response-builder'; | ||
@@ -10,2 +9,3 @@ export { Identify } from './identify'; | ||
export { AMPLITUDE_PREFIX } from './constants'; | ||
export { returnWrapper } from './utils/return-wrapper'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,2 @@ | ||
export { init, track, logEvent, identify, groupIdentify, setGroup, revenue, add, remove, setOptOut, } from './core-client'; | ||
export { getConfig } from './config'; | ||
export { AmplitudeCore } from './core-client'; | ||
export { buildResponse } from './utils/response-builder'; | ||
@@ -10,2 +9,3 @@ export { Identify } from './identify'; | ||
export { AMPLITUDE_PREFIX } from './constants'; | ||
export { returnWrapper } from './utils/return-wrapper'; | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ export declare const SUCCESS_MESSAGE = "Event tracked successfully"; | ||
export declare const OPT_OUT_MESSAGE = "Event skipped due to optOut config"; | ||
export declare const MISSING_API_KEY_MESSAGE = "Event skipped due to optOut config"; | ||
export declare const MISSING_API_KEY_MESSAGE = "Event rejected due to missing API key"; | ||
//# sourceMappingURL=messages.d.ts.map |
@@ -5,3 +5,3 @@ export var SUCCESS_MESSAGE = 'Event tracked successfully'; | ||
export var OPT_OUT_MESSAGE = 'Event skipped due to optOut config'; | ||
export var MISSING_API_KEY_MESSAGE = 'Event skipped due to optOut config'; | ||
export var MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key'; | ||
//# sourceMappingURL=messages.js.map |
@@ -7,3 +7,3 @@ import { __awaiter, __generator, __read, __spreadArray } from "tslib"; | ||
import { buildResult } from '../utils/result-builder'; | ||
import { getApiHost } from '../config'; | ||
import { createServerConfig } from '../config'; | ||
var Destination = /** @class */ (function () { | ||
@@ -106,3 +106,3 @@ function Destination() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var payload, res, e_1; | ||
var payload, serverUrl, res, e_1; | ||
return __generator(this, function (_a) { | ||
@@ -121,3 +121,4 @@ switch (_a.label) { | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.config.transportProvider.send(getApiHost(this.config), payload)]; | ||
serverUrl = createServerConfig(this.config.serverZone, this.config.useBatch).serverUrl; | ||
return [4 /*yield*/, this.config.transportProvider.send(serverUrl, payload)]; | ||
case 2: | ||
@@ -168,3 +169,3 @@ res = _a.sent(); | ||
} | ||
var dropIndex = __spreadArray(__spreadArray(__spreadArray([], __read(Object.values(res.body.eventsWithInvalidFields)), false), __read(Object.values(res.body.eventsWithMissingFields)), false), __read(res.body.silencedEvents), false).flat(); | ||
var dropIndex = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(Object.values(res.body.eventsWithInvalidFields)), false), __read(Object.values(res.body.eventsWithMissingFields)), false), __read(Object.values(res.body.eventsWithInvalidIdLengths)), false), __read(res.body.silencedEvents), false).flat(); | ||
var dropIndexSet = new Set(dropIndex); | ||
@@ -171,0 +172,0 @@ var retry = list.filter(function (context, index) { |
@@ -1,3 +0,3 @@ | ||
import { TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as IIdentify, Revenue, RevenueEvent, EventOptions } from '@amplitude/analytics-types'; | ||
export declare const createTrackEvent: (eventType: string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent; | ||
import { BaseEvent, TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as IIdentify, Revenue, RevenueEvent, EventOptions } from '@amplitude/analytics-types'; | ||
export declare const createTrackEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent; | ||
export declare const createIdentifyEvent: (userId: string | undefined, deviceId: string | undefined, identify: IIdentify, eventOptions?: EventOptions | undefined) => IdentifyEvent; | ||
@@ -4,0 +4,0 @@ export declare const createGroupIdentifyEvent: (userId: string | undefined, deviceId: string | undefined, groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => GroupIdentifyEvent; |
import { __assign } from "tslib"; | ||
import { SpecialEventType, } from '@amplitude/analytics-types'; | ||
import { Identify } from '../identify'; | ||
export var createTrackEvent = function (eventType, eventProperties, eventOptions) { | ||
return __assign(__assign(__assign({}, eventOptions), { event_type: eventType }), (eventProperties && { event_properties: eventProperties })); | ||
export var createTrackEvent = function (eventInput, eventProperties, eventOptions) { | ||
var baseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput; | ||
return __assign(__assign(__assign({}, baseEvent), eventOptions), (eventProperties && { event_properties: eventProperties })); | ||
}; | ||
@@ -7,0 +8,0 @@ export var createIdentifyEvent = function (userId, deviceId, identify, eventOptions) { |
@@ -7,3 +7,3 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
export var buildResponse = function (responseJSON) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; | ||
if (typeof responseJSON !== 'object') { | ||
@@ -34,8 +34,9 @@ return null; | ||
eventsWithMissingFields: (_g = responseJSON.events_with_missing_fields) !== null && _g !== void 0 ? _g : {}, | ||
epsThreshold: (_h = responseJSON.eps_threshold) !== null && _h !== void 0 ? _h : 0, | ||
exceededDailyQuotaDevices: (_j = responseJSON.exceeded_daily_quota_devices) !== null && _j !== void 0 ? _j : {}, | ||
silencedDevices: (_k = responseJSON.silenced_devices) !== null && _k !== void 0 ? _k : [], | ||
silencedEvents: (_l = responseJSON.silenced_events) !== null && _l !== void 0 ? _l : [], | ||
throttledDevices: (_m = responseJSON.throttled_devices) !== null && _m !== void 0 ? _m : {}, | ||
throttledEvents: (_o = responseJSON.throttled_events) !== null && _o !== void 0 ? _o : [], | ||
eventsWithInvalidIdLengths: (_h = responseJSON.events_with_invalid_id_lengths) !== null && _h !== void 0 ? _h : {}, | ||
epsThreshold: (_j = responseJSON.eps_threshold) !== null && _j !== void 0 ? _j : 0, | ||
exceededDailyQuotaDevices: (_k = responseJSON.exceeded_daily_quota_devices) !== null && _k !== void 0 ? _k : {}, | ||
silencedDevices: (_l = responseJSON.silenced_devices) !== null && _l !== void 0 ? _l : [], | ||
silencedEvents: (_m = responseJSON.silenced_events) !== null && _m !== void 0 ? _m : [], | ||
throttledDevices: (_o = responseJSON.throttled_devices) !== null && _o !== void 0 ? _o : {}, | ||
throttledEvents: (_p = responseJSON.throttled_events) !== null && _p !== void 0 ? _p : [], | ||
}, | ||
@@ -48,3 +49,3 @@ }; | ||
body: { | ||
error: (_p = responseJSON.error) !== null && _p !== void 0 ? _p : '', | ||
error: (_q = responseJSON.error) !== null && _q !== void 0 ? _q : '', | ||
}, | ||
@@ -57,9 +58,9 @@ }; | ||
body: { | ||
error: (_q = responseJSON.error) !== null && _q !== void 0 ? _q : '', | ||
epsThreshold: (_r = responseJSON.eps_threshold) !== null && _r !== void 0 ? _r : 0, | ||
throttledDevices: (_s = responseJSON.throttled_devices) !== null && _s !== void 0 ? _s : {}, | ||
throttledUsers: (_t = responseJSON.throttled_users) !== null && _t !== void 0 ? _t : {}, | ||
exceededDailyQuotaDevices: (_u = responseJSON.exceeded_daily_quota_devices) !== null && _u !== void 0 ? _u : {}, | ||
exceededDailyQuotaUsers: (_v = responseJSON.exceeded_daily_quota_users) !== null && _v !== void 0 ? _v : {}, | ||
throttledEvents: (_w = responseJSON.throttled_events) !== null && _w !== void 0 ? _w : [], | ||
error: (_r = responseJSON.error) !== null && _r !== void 0 ? _r : '', | ||
epsThreshold: (_s = responseJSON.eps_threshold) !== null && _s !== void 0 ? _s : 0, | ||
throttledDevices: (_t = responseJSON.throttled_devices) !== null && _t !== void 0 ? _t : {}, | ||
throttledUsers: (_u = responseJSON.throttled_users) !== null && _u !== void 0 ? _u : {}, | ||
exceededDailyQuotaDevices: (_v = responseJSON.exceeded_daily_quota_devices) !== null && _v !== void 0 ? _v : {}, | ||
exceededDailyQuotaUsers: (_w = responseJSON.exceeded_daily_quota_users) !== null && _w !== void 0 ? _w : {}, | ||
throttledEvents: (_x = responseJSON.throttled_events) !== null && _x !== void 0 ? _x : [], | ||
}, | ||
@@ -66,0 +67,0 @@ }; |
@@ -20,2 +20,3 @@ import { __values } from "tslib"; | ||
if (Array.isArray(value)) { | ||
var isValid = true; | ||
try { | ||
@@ -28,3 +29,3 @@ for (var value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) { | ||
else if (typeof valueElement === 'object') { | ||
return isValidObject(value); | ||
isValid = isValid && isValidObject(valueElement); | ||
} | ||
@@ -34,2 +35,5 @@ else if (!['number', 'string'].includes(typeof valueElement)) { | ||
} | ||
if (!isValid) { | ||
return false; | ||
} | ||
} | ||
@@ -36,0 +40,0 @@ } |
{ | ||
"name": "@amplitude/analytics-core", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -35,3 +35,3 @@ "author": "Amplitude Inc", | ||
"dependencies": { | ||
"@amplitude/analytics-types": "^0.1.3", | ||
"@amplitude/analytics-types": "^0.2.0", | ||
"tslib": "^2.3.1" | ||
@@ -42,3 +42,3 @@ }, | ||
], | ||
"gitHead": "20e112d6df8a5a9bb84c21ae758d6c4c76902933" | ||
"gitHead": "3899a210e9848fcf66a4cd2b353ea2c0c6dd45dc" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
266187
155
2478
+ Added@amplitude/analytics-types@0.2.1(transitive)
- Removed@amplitude/analytics-types@0.1.3(transitive)