Socket
Socket
Sign inDemoInstall

@amplitude/analytics-core

Package Overview
Dependencies
Maintainers
19
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amplitude/analytics-core - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

4

lib/cjs/config.d.ts

@@ -1,2 +0,2 @@

import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plan, Plugin, ServerZone } from '@amplitude/analytics-types';
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plan, ServerZone } from '@amplitude/analytics-types';
import { Logger } from './logger';

@@ -11,3 +11,2 @@ export declare const getDefaultConfig: () => {

optOut: boolean;
plugins: never[];
serverUrl: string;

@@ -26,3 +25,2 @@ serverZone: ServerZone;

plan?: Plan;
plugins: Plugin[];
saveEvents: boolean;

@@ -29,0 +27,0 @@ serverUrl: string | undefined;

@@ -14,3 +14,2 @@ Object.defineProperty(exports, "__esModule", { value: true });

optOut: false,
plugins: [],
serverUrl: constants_1.AMPLITUDE_SERVER_URL,

@@ -34,3 +33,2 @@ serverZone: analytics_types_1.ServerZone.US,

this.plan = options.plan;
this.plugins = defaultConfig.plugins;
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b : defaultConfig.optOut;

@@ -37,0 +35,0 @@ this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c : defaultConfig.saveEvents;

import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
import { Timeline } from './timeline';
export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
name: string;
config: T;
timeline: Timeline;
constructor(name?: string);

@@ -6,0 +8,0 @@ init(_apiKey: string | undefined, _userId: string | undefined, config: T): Promise<void>;

@@ -16,2 +16,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

this.config = config;
this.timeline = new timeline_1.Timeline();
return Promise.resolve();

@@ -44,3 +45,3 @@ };

config = this.config;
return [2 /*return*/, (0, timeline_1.register)(plugin, config)];
return [2 /*return*/, this.timeline.register(plugin, config)];
});

@@ -51,6 +52,4 @@ });

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)];
return [2 /*return*/, this.timeline.deregister(pluginName)];
});

@@ -66,3 +65,3 @@ });

_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, (0, timeline_1.push)(event, this.config)];
return [4 /*yield*/, this.timeline.push(event, this.config)];
case 1:

@@ -92,4 +91,3 @@ result = _a.sent();

AmplitudeCore.prototype.flush = function () {
var config = this.config;
return (0, timeline_1.flush)(config);
return this.timeline.flush();
};

@@ -96,0 +94,0 @@ return AmplitudeCore;

@@ -5,10 +5,8 @@ import { Config, DestinationContext as Context, DestinationPlugin, Event, InvalidResponse, PayloadTooLargeResponse, PluginType, RateLimitResponse, Response, Result, SuccessResponse } from '@amplitude/analytics-types';

type: PluginType.DESTINATION;
backoff: number;
throttle: number;
retryTimeout: number;
throttleTimeout: number;
storageKey: string;
backup: Set<Event>;
config: Config;
scheduled: boolean;
queue: Context[];
queueBuffer: Set<Context>;
setup(config: Config): Promise<undefined>;

@@ -18,4 +16,4 @@ execute(event: Event): Promise<Result>;

schedule(timeout: number): void;
flush(includeQueueBuffer?: boolean): Promise<void>;
send(list: Context[]): Promise<void>;
flush(useRetry?: boolean): Promise<void>;
send(list: Context[], useRetry?: boolean): Promise<void>;
handleReponse(res: Response, list: Context[]): void;

@@ -28,6 +26,10 @@ handleSuccessResponse(res: SuccessResponse, list: Context[]): void;

fulfillRequest(list: Context[], code: number, message: string): void;
addToBackup(...events: Event[]): void;
removeFromBackup(...events: Event[]): void;
snapshot(): void;
/**
* Saves events to storage
* This is called on
* 1) new events are added to queue; or
* 2) response comes back for a request
*/
saveEvents(): void;
}
//# sourceMappingURL=destination.d.ts.map

@@ -14,20 +14,28 @@ Object.defineProperty(exports, "__esModule", { value: true });

this.type = analytics_types_1.PluginType.DESTINATION;
this.backoff = 1000;
this.throttle = 30000;
this.retryTimeout = 1000;
this.throttleTimeout = 30000;
this.storageKey = '';
this.backup = new Set();
this.scheduled = false;
this.queue = [];
this.queueBuffer = new Set();
}
Destination.prototype.setup = function (config) {
var _this = this;
this.config = config;
this.storageKey = "".concat(constants_1.STORAGE_PREFIX, "_").concat(this.config.apiKey.substring(0, 10));
var unsent = this.config.storageProvider.get(this.storageKey);
this.snapshot(); // sets storage to '[]'
if (unsent && unsent.length > 0) {
void Promise.all(unsent.map(function (event) { return _this.execute(event); })).catch();
}
return Promise.resolve(undefined);
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var unsent;
var _this = this;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
this.config = config;
this.storageKey = "".concat(constants_1.STORAGE_PREFIX, "_").concat(this.config.apiKey.substring(0, 10));
return [4 /*yield*/, this.config.storageProvider.get(this.storageKey)];
case 1:
unsent = _a.sent();
this.saveEvents(); // sets storage to '[]'
if (unsent && unsent.length > 0) {
void Promise.all(unsent.map(function (event) { return _this.execute(event); })).catch();
}
return [2 /*return*/, Promise.resolve(undefined)];
}
});
});
};

@@ -41,5 +49,5 @@ Destination.prototype.execute = function (event) {

callback: function (result) { return resolve(result); },
delay: 0,
timeout: 0,
};
_this.addToQueue(context);
void _this.addToQueue(context);
});

@@ -55,26 +63,20 @@ };

if (context.attempts < _this.config.flushMaxRetries) {
context.attempts += 1;
return true;
}
_this.fulfillRequest([context], 500, analytics_types_1.Status.Unknown);
void _this.fulfillRequest([context], 500, analytics_types_1.Status.Unknown);
return false;
});
this.addToBackup.apply(this, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(tryable.map(function (context) { return context.event; })), false));
tryable.forEach(function (context) {
context.attempts += 1;
var delay = context.delay;
context.delay = 0;
if (context.attempts === 1 && !context.delay) {
_this.queue = _this.queue.concat(context);
_this.queue = _this.queue.concat(context);
if (context.timeout === 0) {
_this.schedule(_this.config.flushIntervalMillis);
return;
}
_this.queueBuffer.add(context);
setTimeout(function () {
if (_this.queueBuffer.has(context)) {
_this.queueBuffer.delete(context);
_this.queue = _this.queue.concat(context);
_this.schedule(_this.config.flushIntervalMillis);
}
}, delay || context.attempts * _this.backoff);
context.timeout = 0;
_this.schedule(0);
}, context.timeout);
});
this.saveEvents();
};

@@ -87,3 +89,3 @@ Destination.prototype.schedule = function (timeout) {

setTimeout(function () {
void _this.flush().then(function () {
void _this.flush(true).then(function () {
_this.scheduled = false;

@@ -96,6 +98,6 @@ if (_this.queue.length > 0) {

};
Destination.prototype.flush = function (includeQueueBuffer) {
if (includeQueueBuffer === void 0) { includeQueueBuffer = false; }
Destination.prototype.flush = function (useRetry) {
if (useRetry === void 0) { useRetry = false; }
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var list, batches;
var list, later, batches;
var _this = this;

@@ -105,10 +107,8 @@ return (0, tslib_1.__generator)(this, function (_a) {

case 0:
list = this.queue;
this.queue = [];
if (includeQueueBuffer) {
list.push.apply(list, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(this.queueBuffer.values()), false));
this.queueBuffer.clear();
}
list = [];
later = [];
this.queue.forEach(function (context) { return (context.timeout === 0 ? list.push(context) : later.push(context)); });
this.queue = later;
batches = (0, chunk_1.chunk)(list, this.config.flushQueueSize);
return [4 /*yield*/, Promise.all(batches.map(function (batch) { return _this.send(batch); }))];
return [4 /*yield*/, Promise.all(batches.map(function (batch) { return _this.send(batch, useRetry); }))];
case 1:

@@ -121,3 +121,4 @@ _a.sent();

};
Destination.prototype.send = function (list) {
Destination.prototype.send = function (list, useRetry) {
if (useRetry === void 0) { useRetry = true; }
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {

@@ -149,2 +150,6 @@ var payload, serverUrl, res, e_1;

}
if (!useRetry) {
this.fulfillRequest(list, res.statusCode, res.status);
return [2 /*return*/];
}
this.handleReponse(res, list);

@@ -223,3 +228,3 @@ return [3 /*break*/, 4];

if (throttledIndexSet.has(index)) {
context.delay = _this.throttle;
context.timeout = _this.throttleTimeout;
}

@@ -231,36 +236,25 @@ return true;

Destination.prototype.handleOtherReponse = function (list) {
this.addToQueue.apply(this, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(list), false));
var _this = this;
this.addToQueue.apply(this, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(list.map(function (context) {
context.timeout = context.attempts * _this.retryTimeout;
return context;
})), false));
};
Destination.prototype.fulfillRequest = function (list, code, message) {
this.removeFromBackup.apply(this, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(list.map(function (context) { return context.event; })), false));
this.saveEvents();
list.forEach(function (context) { return context.callback((0, result_builder_1.buildResult)(context.event, code, message)); });
};
Destination.prototype.addToBackup = function () {
var _this = this;
var events = [];
for (var _i = 0; _i < arguments.length; _i++) {
events[_i] = arguments[_i];
}
if (!this.config.saveEvents)
/**
* Saves events to storage
* This is called on
* 1) new events are added to queue; or
* 2) response comes back for a request
*/
Destination.prototype.saveEvents = function () {
if (!this.config.saveEvents) {
return;
events.forEach(function (event) { return _this.backup.add(event); });
this.snapshot();
};
Destination.prototype.removeFromBackup = function () {
var _this = this;
var events = [];
for (var _i = 0; _i < arguments.length; _i++) {
events[_i] = arguments[_i];
}
if (!this.config.saveEvents)
return;
events.forEach(function (event) { return _this.backup.delete(event); });
this.snapshot();
var events = Array.from(this.queue.map(function (context) { return context.event; }));
void this.config.storageProvider.set(this.storageKey, events);
};
Destination.prototype.snapshot = function () {
if (!this.config.saveEvents)
return;
var events = Array.from(this.backup);
this.config.storageProvider.set(this.storageKey, events);
};
return Destination;

@@ -267,0 +261,0 @@ }());

import { Storage } from '@amplitude/analytics-types';
export declare class MemoryStorage<T> implements Storage<T> {
memoryStorage: Map<string, T>;
isEnabled(): boolean;
get(key: string): T | undefined;
getRaw(key: string): string | undefined;
set(key: string, value: T): void;
remove(key: string): void;
reset(): void;
isEnabled(): Promise<boolean>;
get(key: string): Promise<T | undefined>;
getRaw(key: string): Promise<string | undefined>;
set(key: string, value: T): Promise<void>;
remove(key: string): Promise<void>;
reset(): Promise<void>;
}
//# sourceMappingURL=memory.d.ts.map
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemoryStorage = void 0;
var tslib_1 = require("tslib");
var MemoryStorage = /** @class */ (function () {

@@ -8,19 +9,51 @@ function MemoryStorage() {

MemoryStorage.prototype.isEnabled = function () {
return true;
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
return [2 /*return*/, true];
});
});
};
MemoryStorage.prototype.get = function (key) {
return this.memoryStorage.get(key);
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
return [2 /*return*/, this.memoryStorage.get(key)];
});
});
};
MemoryStorage.prototype.getRaw = function (key) {
var value = this.get(key);
return value ? JSON.stringify(value) : undefined;
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var value;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.get(key)];
case 1:
value = _a.sent();
return [2 /*return*/, value ? JSON.stringify(value) : undefined];
}
});
});
};
MemoryStorage.prototype.set = function (key, value) {
this.memoryStorage.set(key, value);
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
this.memoryStorage.set(key, value);
return [2 /*return*/];
});
});
};
MemoryStorage.prototype.remove = function (key) {
this.memoryStorage.delete(key);
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
this.memoryStorage.delete(key);
return [2 /*return*/];
});
});
};
MemoryStorage.prototype.reset = function () {
this.memoryStorage.clear();
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
this.memoryStorage.clear();
return [2 /*return*/];
});
});
};

@@ -27,0 +60,0 @@ return MemoryStorage;

import { Config, Event, EventCallback, Plugin, Result } from '@amplitude/analytics-types';
export declare const queue: [Event, EventCallback, Plugin[]][];
export declare const register: (plugin: Plugin, config: Config) => Promise<void>;
export declare const deregister: (pluginName: string, config: Config) => Promise<void>;
export declare const push: (event: Event, config: Config) => Promise<Result>;
export declare const scheduleApply: (timeout: number) => void;
export declare const apply: () => Promise<void>;
export declare const flush: (config: Config) => Promise<void>;
export declare class Timeline {
queue: [Event, EventCallback][];
applying: boolean;
flushing: boolean;
plugins: Plugin[];
register(plugin: Plugin, config: Config): Promise<void>;
deregister(pluginName: string): Promise<void>;
push(event: Event, config: Config): Promise<Result>;
scheduleApply(timeout: number): void;
apply(item: [Event, EventCallback] | undefined): Promise<void>;
flush(): Promise<void>;
}
//# sourceMappingURL=timeline.d.ts.map

@@ -1,4 +0,3 @@

var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
exports.flush = exports.apply = exports.scheduleApply = exports.push = exports.deregister = exports.register = exports.queue = void 0;
exports.Timeline = void 0;
var tslib_1 = require("tslib");

@@ -8,143 +7,160 @@ var analytics_types_1 = require("@amplitude/analytics-types");

var result_builder_1 = require("./utils/result-builder");
exports.queue = [];
var applying = false;
var register = function (plugin, config) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, plugin.setup(config)];
case 1:
_a.sent();
config.plugins.push(plugin);
return [2 /*return*/];
}
});
}); };
exports.register = register;
var deregister = function (pluginName, config) {
config.plugins.splice(config.plugins.findIndex(function (plugin) { return plugin.name === pluginName; }), 1);
return Promise.resolve();
};
exports.deregister = deregister;
var push = function (event, config) {
return new Promise(function (resolve) {
if (config.optOut) {
resolve((0, result_builder_1.buildResult)(event, 0, messages_1.OPT_OUT_MESSAGE));
return;
}
exports.queue.push([event, resolve, config.plugins]);
(0, exports.scheduleApply)(0);
});
};
exports.push = push;
var scheduleApply = function (timeout) {
if (applying)
return;
applying = true;
setTimeout(function () {
void (0, exports.apply)().then(function () {
applying = false;
if (exports.queue.length > 0) {
(0, exports.scheduleApply)(0);
var Timeline = /** @class */ (function () {
function Timeline() {
this.queue = [];
this.applying = false;
this.flushing = false;
this.plugins = [];
}
Timeline.prototype.register = function (plugin, config) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, plugin.setup(config)];
case 1:
_a.sent();
this.plugins.push(plugin);
return [2 /*return*/];
}
});
});
};
Timeline.prototype.deregister = function (pluginName) {
this.plugins.splice(this.plugins.findIndex(function (plugin) { return plugin.name === pluginName; }), 1);
return Promise.resolve();
};
Timeline.prototype.push = function (event, config) {
var _this = this;
return new Promise(function (resolve) {
if (config.optOut) {
resolve((0, result_builder_1.buildResult)(event, 0, messages_1.OPT_OUT_MESSAGE));
return;
}
_this.queue.push([event, resolve]);
_this.scheduleApply(0);
});
}, timeout);
};
exports.scheduleApply = scheduleApply;
var apply = function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
var item, _a, event, _b, resolve, plugins, before, before_1, before_1_1, plugin, e_1_1, enrichment, enrichment_1, enrichment_1_1, plugin, e_2_1, destination, executeDestinations;
var e_1, _c, e_2, _d;
return (0, tslib_1.__generator)(this, function (_e) {
switch (_e.label) {
case 0:
item = exports.queue.shift();
if (!item) {
return [2 /*return*/];
};
Timeline.prototype.scheduleApply = function (timeout) {
var _this = this;
if (this.applying)
return;
this.applying = true;
setTimeout(function () {
void _this.apply(_this.queue.shift()).then(function () {
_this.applying = false;
if (_this.queue.length > 0) {
_this.scheduleApply(0);
}
_a = (0, tslib_1.__read)(item, 1), event = _a[0];
_b = (0, tslib_1.__read)(item, 3), resolve = _b[1], plugins = _b[2];
before = plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.BEFORE; });
_e.label = 1;
case 1:
_e.trys.push([1, 6, 7, 8]);
before_1 = (0, tslib_1.__values)(before), before_1_1 = before_1.next();
_e.label = 2;
case 2:
if (!!before_1_1.done) return [3 /*break*/, 5];
plugin = before_1_1.value;
return [4 /*yield*/, plugin.execute((0, tslib_1.__assign)({}, event))];
case 3:
event = _e.sent();
_e.label = 4;
case 4:
before_1_1 = before_1.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _e.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (before_1_1 && !before_1_1.done && (_c = before_1.return)) _c.call(before_1);
});
}, timeout);
};
Timeline.prototype.apply = function (item) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var _a, event, _b, resolve, before, before_1, before_1_1, plugin, e_1_1, enrichment, enrichment_1, enrichment_1_1, plugin, e_2_1, destination, executeDestinations;
var e_1, _c, e_2, _d;
return (0, tslib_1.__generator)(this, function (_e) {
switch (_e.label) {
case 0:
if (!item) {
return [2 /*return*/];
}
_a = (0, tslib_1.__read)(item, 1), event = _a[0];
_b = (0, tslib_1.__read)(item, 2), resolve = _b[1];
before = this.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.BEFORE; });
_e.label = 1;
case 1:
_e.trys.push([1, 6, 7, 8]);
before_1 = (0, tslib_1.__values)(before), before_1_1 = before_1.next();
_e.label = 2;
case 2:
if (!!before_1_1.done) return [3 /*break*/, 5];
plugin = before_1_1.value;
return [4 /*yield*/, plugin.execute((0, tslib_1.__assign)({}, event))];
case 3:
event = _e.sent();
_e.label = 4;
case 4:
before_1_1 = before_1.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _e.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (before_1_1 && !before_1_1.done && (_c = before_1.return)) _c.call(before_1);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8:
enrichment = this.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.ENRICHMENT; });
_e.label = 9;
case 9:
_e.trys.push([9, 14, 15, 16]);
enrichment_1 = (0, tslib_1.__values)(enrichment), enrichment_1_1 = enrichment_1.next();
_e.label = 10;
case 10:
if (!!enrichment_1_1.done) return [3 /*break*/, 13];
plugin = enrichment_1_1.value;
return [4 /*yield*/, plugin.execute((0, tslib_1.__assign)({}, event))];
case 11:
event = _e.sent();
_e.label = 12;
case 12:
enrichment_1_1 = enrichment_1.next();
return [3 /*break*/, 10];
case 13: return [3 /*break*/, 16];
case 14:
e_2_1 = _e.sent();
e_2 = { error: e_2_1 };
return [3 /*break*/, 16];
case 15:
try {
if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
}
finally { if (e_2) throw e_2.error; }
return [7 /*endfinally*/];
case 16:
destination = this.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.DESTINATION; });
executeDestinations = destination.map(function (plugin) {
var eventClone = (0, tslib_1.__assign)({}, event);
return plugin.execute(eventClone).catch(function (e) { return (0, result_builder_1.buildResult)(eventClone, 0, String(e)); });
});
void Promise.all(executeDestinations).then(function (_a) {
var _b = (0, tslib_1.__read)(_a, 1), result = _b[0];
resolve(result);
});
return [2 /*return*/];
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8:
enrichment = plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.ENRICHMENT; });
_e.label = 9;
case 9:
_e.trys.push([9, 14, 15, 16]);
enrichment_1 = (0, tslib_1.__values)(enrichment), enrichment_1_1 = enrichment_1.next();
_e.label = 10;
case 10:
if (!!enrichment_1_1.done) return [3 /*break*/, 13];
plugin = enrichment_1_1.value;
return [4 /*yield*/, plugin.execute((0, tslib_1.__assign)({}, event))];
case 11:
event = _e.sent();
_e.label = 12;
case 12:
enrichment_1_1 = enrichment_1.next();
return [3 /*break*/, 10];
case 13: return [3 /*break*/, 16];
case 14:
e_2_1 = _e.sent();
e_2 = { error: e_2_1 };
return [3 /*break*/, 16];
case 15:
try {
if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
});
});
};
Timeline.prototype.flush = function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var queue, destination, executeDestinations;
var _this = this;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
queue = this.queue;
this.queue = [];
return [4 /*yield*/, Promise.all(queue.map(function (item) { return _this.apply(item); }))];
case 1:
_a.sent();
destination = this.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.DESTINATION; });
executeDestinations = destination.map(function (plugin) {
return plugin.flush && plugin.flush();
});
return [4 /*yield*/, Promise.all(executeDestinations)];
case 2:
_a.sent();
return [2 /*return*/];
}
finally { if (e_2) throw e_2.error; }
return [7 /*endfinally*/];
case 16:
destination = plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.DESTINATION; });
executeDestinations = destination.map(function (plugin) {
var eventClone = (0, tslib_1.__assign)({}, event);
return plugin.execute(eventClone).catch(function (e) { return (0, result_builder_1.buildResult)(eventClone, 0, String(e)); });
});
void Promise.all(executeDestinations).then(function (_a) {
var _b = (0, tslib_1.__read)(_a, 1), result = _b[0];
resolve(result);
});
return [2 /*return*/];
}
});
}); };
exports.apply = apply;
var flush = function (config) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
var destination, flushDestinations;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
destination = config.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.DESTINATION; });
flushDestinations = destination.map(function (plugin) { return plugin.flush && plugin.flush(true); });
return [4 /*yield*/, Promise.all(flushDestinations)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); };
exports.flush = flush;
});
});
};
return Timeline;
}());
exports.Timeline = Timeline;
//# sourceMappingURL=timeline.js.map

@@ -1,2 +0,2 @@

import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plan, Plugin, ServerZone } from '@amplitude/analytics-types';
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plan, ServerZone } from '@amplitude/analytics-types';
import { Logger } from './logger';

@@ -11,3 +11,2 @@ export declare const getDefaultConfig: () => {

optOut: boolean;
plugins: never[];
serverUrl: string;

@@ -26,3 +25,2 @@ serverZone: ServerZone;

plan?: Plan;
plugins: Plugin[];
saveEvents: boolean;

@@ -29,0 +27,0 @@ serverUrl: string | undefined;

@@ -12,3 +12,2 @@ import { LogLevel, ServerZone, } from '@amplitude/analytics-types';

optOut: false,
plugins: [],
serverUrl: AMPLITUDE_SERVER_URL,

@@ -31,3 +30,2 @@ serverZone: ServerZone.US,

this.plan = options.plan;
this.plugins = defaultConfig.plugins;
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b : defaultConfig.optOut;

@@ -34,0 +32,0 @@ this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c : defaultConfig.saveEvents;

import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
import { Timeline } from './timeline';
export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
name: string;
config: T;
timeline: Timeline;
constructor(name?: string);

@@ -6,0 +8,0 @@ init(_apiKey: string | undefined, _userId: string | undefined, config: T): Promise<void>;

import { __awaiter, __generator } from "tslib";
import { createGroupIdentifyEvent, createIdentifyEvent, createTrackEvent, createRevenueEvent, createGroupEvent, } from './utils/event-builder';
import { deregister, flush, push, register } from './timeline';
import { Timeline } from './timeline';
import { buildResult } from './utils/result-builder';

@@ -14,2 +14,3 @@ var AmplitudeCore = /** @class */ (function () {

this.config = config;
this.timeline = new Timeline();
return Promise.resolve();

@@ -42,3 +43,3 @@ };

config = this.config;
return [2 /*return*/, register(plugin, config)];
return [2 /*return*/, this.timeline.register(plugin, config)];
});

@@ -49,6 +50,4 @@ });

return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
config = this.config;
return [2 /*return*/, deregister(pluginName, config)];
return [2 /*return*/, this.timeline.deregister(pluginName)];
});

@@ -64,3 +63,3 @@ });

_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, push(event, this.config)];
return [4 /*yield*/, this.timeline.push(event, this.config)];
case 1:

@@ -90,4 +89,3 @@ result = _a.sent();

AmplitudeCore.prototype.flush = function () {
var config = this.config;
return flush(config);
return this.timeline.flush();
};

@@ -94,0 +92,0 @@ return AmplitudeCore;

@@ -5,10 +5,8 @@ import { Config, DestinationContext as Context, DestinationPlugin, Event, InvalidResponse, PayloadTooLargeResponse, PluginType, RateLimitResponse, Response, Result, SuccessResponse } from '@amplitude/analytics-types';

type: PluginType.DESTINATION;
backoff: number;
throttle: number;
retryTimeout: number;
throttleTimeout: number;
storageKey: string;
backup: Set<Event>;
config: Config;
scheduled: boolean;
queue: Context[];
queueBuffer: Set<Context>;
setup(config: Config): Promise<undefined>;

@@ -18,4 +16,4 @@ execute(event: Event): Promise<Result>;

schedule(timeout: number): void;
flush(includeQueueBuffer?: boolean): Promise<void>;
send(list: Context[]): Promise<void>;
flush(useRetry?: boolean): Promise<void>;
send(list: Context[], useRetry?: boolean): Promise<void>;
handleReponse(res: Response, list: Context[]): void;

@@ -28,6 +26,10 @@ handleSuccessResponse(res: SuccessResponse, list: Context[]): void;

fulfillRequest(list: Context[], code: number, message: string): void;
addToBackup(...events: Event[]): void;
removeFromBackup(...events: Event[]): void;
snapshot(): void;
/**
* Saves events to storage
* This is called on
* 1) new events are added to queue; or
* 2) response comes back for a request
*/
saveEvents(): void;
}
//# sourceMappingURL=destination.d.ts.map

@@ -12,20 +12,28 @@ import { __awaiter, __generator, __read, __spreadArray } from "tslib";

this.type = PluginType.DESTINATION;
this.backoff = 1000;
this.throttle = 30000;
this.retryTimeout = 1000;
this.throttleTimeout = 30000;
this.storageKey = '';
this.backup = new Set();
this.scheduled = false;
this.queue = [];
this.queueBuffer = new Set();
}
Destination.prototype.setup = function (config) {
var _this = this;
this.config = config;
this.storageKey = "".concat(STORAGE_PREFIX, "_").concat(this.config.apiKey.substring(0, 10));
var unsent = this.config.storageProvider.get(this.storageKey);
this.snapshot(); // sets storage to '[]'
if (unsent && unsent.length > 0) {
void Promise.all(unsent.map(function (event) { return _this.execute(event); })).catch();
}
return Promise.resolve(undefined);
return __awaiter(this, void 0, void 0, function () {
var unsent;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.config = config;
this.storageKey = "".concat(STORAGE_PREFIX, "_").concat(this.config.apiKey.substring(0, 10));
return [4 /*yield*/, this.config.storageProvider.get(this.storageKey)];
case 1:
unsent = _a.sent();
this.saveEvents(); // sets storage to '[]'
if (unsent && unsent.length > 0) {
void Promise.all(unsent.map(function (event) { return _this.execute(event); })).catch();
}
return [2 /*return*/, Promise.resolve(undefined)];
}
});
});
};

@@ -39,5 +47,5 @@ Destination.prototype.execute = function (event) {

callback: function (result) { return resolve(result); },
delay: 0,
timeout: 0,
};
_this.addToQueue(context);
void _this.addToQueue(context);
});

@@ -53,26 +61,20 @@ };

if (context.attempts < _this.config.flushMaxRetries) {
context.attempts += 1;
return true;
}
_this.fulfillRequest([context], 500, Status.Unknown);
void _this.fulfillRequest([context], 500, Status.Unknown);
return false;
});
this.addToBackup.apply(this, __spreadArray([], __read(tryable.map(function (context) { return context.event; })), false));
tryable.forEach(function (context) {
context.attempts += 1;
var delay = context.delay;
context.delay = 0;
if (context.attempts === 1 && !context.delay) {
_this.queue = _this.queue.concat(context);
_this.queue = _this.queue.concat(context);
if (context.timeout === 0) {
_this.schedule(_this.config.flushIntervalMillis);
return;
}
_this.queueBuffer.add(context);
setTimeout(function () {
if (_this.queueBuffer.has(context)) {
_this.queueBuffer.delete(context);
_this.queue = _this.queue.concat(context);
_this.schedule(_this.config.flushIntervalMillis);
}
}, delay || context.attempts * _this.backoff);
context.timeout = 0;
_this.schedule(0);
}, context.timeout);
});
this.saveEvents();
};

@@ -85,3 +87,3 @@ Destination.prototype.schedule = function (timeout) {

setTimeout(function () {
void _this.flush().then(function () {
void _this.flush(true).then(function () {
_this.scheduled = false;

@@ -94,6 +96,6 @@ if (_this.queue.length > 0) {

};
Destination.prototype.flush = function (includeQueueBuffer) {
if (includeQueueBuffer === void 0) { includeQueueBuffer = false; }
Destination.prototype.flush = function (useRetry) {
if (useRetry === void 0) { useRetry = false; }
return __awaiter(this, void 0, void 0, function () {
var list, batches;
var list, later, batches;
var _this = this;

@@ -103,10 +105,8 @@ return __generator(this, function (_a) {

case 0:
list = this.queue;
this.queue = [];
if (includeQueueBuffer) {
list.push.apply(list, __spreadArray([], __read(this.queueBuffer.values()), false));
this.queueBuffer.clear();
}
list = [];
later = [];
this.queue.forEach(function (context) { return (context.timeout === 0 ? list.push(context) : later.push(context)); });
this.queue = later;
batches = chunk(list, this.config.flushQueueSize);
return [4 /*yield*/, Promise.all(batches.map(function (batch) { return _this.send(batch); }))];
return [4 /*yield*/, Promise.all(batches.map(function (batch) { return _this.send(batch, useRetry); }))];
case 1:

@@ -119,3 +119,4 @@ _a.sent();

};
Destination.prototype.send = function (list) {
Destination.prototype.send = function (list, useRetry) {
if (useRetry === void 0) { useRetry = true; }
return __awaiter(this, void 0, void 0, function () {

@@ -147,2 +148,6 @@ var payload, serverUrl, res, e_1;

}
if (!useRetry) {
this.fulfillRequest(list, res.statusCode, res.status);
return [2 /*return*/];
}
this.handleReponse(res, list);

@@ -221,3 +226,3 @@ return [3 /*break*/, 4];

if (throttledIndexSet.has(index)) {
context.delay = _this.throttle;
context.timeout = _this.throttleTimeout;
}

@@ -229,36 +234,25 @@ return true;

Destination.prototype.handleOtherReponse = function (list) {
this.addToQueue.apply(this, __spreadArray([], __read(list), false));
var _this = this;
this.addToQueue.apply(this, __spreadArray([], __read(list.map(function (context) {
context.timeout = context.attempts * _this.retryTimeout;
return context;
})), false));
};
Destination.prototype.fulfillRequest = function (list, code, message) {
this.removeFromBackup.apply(this, __spreadArray([], __read(list.map(function (context) { return context.event; })), false));
this.saveEvents();
list.forEach(function (context) { return context.callback(buildResult(context.event, code, message)); });
};
Destination.prototype.addToBackup = function () {
var _this = this;
var events = [];
for (var _i = 0; _i < arguments.length; _i++) {
events[_i] = arguments[_i];
}
if (!this.config.saveEvents)
/**
* Saves events to storage
* This is called on
* 1) new events are added to queue; or
* 2) response comes back for a request
*/
Destination.prototype.saveEvents = function () {
if (!this.config.saveEvents) {
return;
events.forEach(function (event) { return _this.backup.add(event); });
this.snapshot();
};
Destination.prototype.removeFromBackup = function () {
var _this = this;
var events = [];
for (var _i = 0; _i < arguments.length; _i++) {
events[_i] = arguments[_i];
}
if (!this.config.saveEvents)
return;
events.forEach(function (event) { return _this.backup.delete(event); });
this.snapshot();
var events = Array.from(this.queue.map(function (context) { return context.event; }));
void this.config.storageProvider.set(this.storageKey, events);
};
Destination.prototype.snapshot = function () {
if (!this.config.saveEvents)
return;
var events = Array.from(this.backup);
this.config.storageProvider.set(this.storageKey, events);
};
return Destination;

@@ -265,0 +259,0 @@ }());

import { Storage } from '@amplitude/analytics-types';
export declare class MemoryStorage<T> implements Storage<T> {
memoryStorage: Map<string, T>;
isEnabled(): boolean;
get(key: string): T | undefined;
getRaw(key: string): string | undefined;
set(key: string, value: T): void;
remove(key: string): void;
reset(): void;
isEnabled(): Promise<boolean>;
get(key: string): Promise<T | undefined>;
getRaw(key: string): Promise<string | undefined>;
set(key: string, value: T): Promise<void>;
remove(key: string): Promise<void>;
reset(): Promise<void>;
}
//# sourceMappingURL=memory.d.ts.map

@@ -0,1 +1,2 @@

import { __awaiter, __generator } from "tslib";
var MemoryStorage = /** @class */ (function () {

@@ -6,19 +7,51 @@ function MemoryStorage() {

MemoryStorage.prototype.isEnabled = function () {
return true;
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, true];
});
});
};
MemoryStorage.prototype.get = function (key) {
return this.memoryStorage.get(key);
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.memoryStorage.get(key)];
});
});
};
MemoryStorage.prototype.getRaw = function (key) {
var value = this.get(key);
return value ? JSON.stringify(value) : undefined;
return __awaiter(this, void 0, void 0, function () {
var value;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.get(key)];
case 1:
value = _a.sent();
return [2 /*return*/, value ? JSON.stringify(value) : undefined];
}
});
});
};
MemoryStorage.prototype.set = function (key, value) {
this.memoryStorage.set(key, value);
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.memoryStorage.set(key, value);
return [2 /*return*/];
});
});
};
MemoryStorage.prototype.remove = function (key) {
this.memoryStorage.delete(key);
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.memoryStorage.delete(key);
return [2 /*return*/];
});
});
};
MemoryStorage.prototype.reset = function () {
this.memoryStorage.clear();
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.memoryStorage.clear();
return [2 /*return*/];
});
});
};

@@ -25,0 +58,0 @@ return MemoryStorage;

import { Config, Event, EventCallback, Plugin, Result } from '@amplitude/analytics-types';
export declare const queue: [Event, EventCallback, Plugin[]][];
export declare const register: (plugin: Plugin, config: Config) => Promise<void>;
export declare const deregister: (pluginName: string, config: Config) => Promise<void>;
export declare const push: (event: Event, config: Config) => Promise<Result>;
export declare const scheduleApply: (timeout: number) => void;
export declare const apply: () => Promise<void>;
export declare const flush: (config: Config) => Promise<void>;
export declare class Timeline {
queue: [Event, EventCallback][];
applying: boolean;
flushing: boolean;
plugins: Plugin[];
register(plugin: Plugin, config: Config): Promise<void>;
deregister(pluginName: string): Promise<void>;
push(event: Event, config: Config): Promise<Result>;
scheduleApply(timeout: number): void;
apply(item: [Event, EventCallback] | undefined): Promise<void>;
flush(): Promise<void>;
}
//# sourceMappingURL=timeline.d.ts.map

@@ -5,137 +5,160 @@ import { __assign, __awaiter, __generator, __read, __values } from "tslib";

import { buildResult } from './utils/result-builder';
export var queue = [];
var applying = false;
export var register = function (plugin, config) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, plugin.setup(config)];
case 1:
_a.sent();
config.plugins.push(plugin);
return [2 /*return*/];
}
});
}); };
export var deregister = function (pluginName, config) {
config.plugins.splice(config.plugins.findIndex(function (plugin) { return plugin.name === pluginName; }), 1);
return Promise.resolve();
};
export var push = function (event, config) {
return new Promise(function (resolve) {
if (config.optOut) {
resolve(buildResult(event, 0, OPT_OUT_MESSAGE));
return;
}
queue.push([event, resolve, config.plugins]);
scheduleApply(0);
});
};
export var scheduleApply = function (timeout) {
if (applying)
return;
applying = true;
setTimeout(function () {
void apply().then(function () {
applying = false;
if (queue.length > 0) {
scheduleApply(0);
var Timeline = /** @class */ (function () {
function Timeline() {
this.queue = [];
this.applying = false;
this.flushing = false;
this.plugins = [];
}
Timeline.prototype.register = function (plugin, config) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, plugin.setup(config)];
case 1:
_a.sent();
this.plugins.push(plugin);
return [2 /*return*/];
}
});
});
};
Timeline.prototype.deregister = function (pluginName) {
this.plugins.splice(this.plugins.findIndex(function (plugin) { return plugin.name === pluginName; }), 1);
return Promise.resolve();
};
Timeline.prototype.push = function (event, config) {
var _this = this;
return new Promise(function (resolve) {
if (config.optOut) {
resolve(buildResult(event, 0, OPT_OUT_MESSAGE));
return;
}
_this.queue.push([event, resolve]);
_this.scheduleApply(0);
});
}, timeout);
};
export var apply = function () { return __awaiter(void 0, void 0, void 0, function () {
var item, _a, event, _b, resolve, plugins, before, before_1, before_1_1, plugin, e_1_1, enrichment, enrichment_1, enrichment_1_1, plugin, e_2_1, destination, executeDestinations;
var e_1, _c, e_2, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
item = queue.shift();
if (!item) {
return [2 /*return*/];
};
Timeline.prototype.scheduleApply = function (timeout) {
var _this = this;
if (this.applying)
return;
this.applying = true;
setTimeout(function () {
void _this.apply(_this.queue.shift()).then(function () {
_this.applying = false;
if (_this.queue.length > 0) {
_this.scheduleApply(0);
}
_a = __read(item, 1), event = _a[0];
_b = __read(item, 3), resolve = _b[1], plugins = _b[2];
before = plugins.filter(function (plugin) { return plugin.type === PluginType.BEFORE; });
_e.label = 1;
case 1:
_e.trys.push([1, 6, 7, 8]);
before_1 = __values(before), before_1_1 = before_1.next();
_e.label = 2;
case 2:
if (!!before_1_1.done) return [3 /*break*/, 5];
plugin = before_1_1.value;
return [4 /*yield*/, plugin.execute(__assign({}, event))];
case 3:
event = _e.sent();
_e.label = 4;
case 4:
before_1_1 = before_1.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _e.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (before_1_1 && !before_1_1.done && (_c = before_1.return)) _c.call(before_1);
});
}, timeout);
};
Timeline.prototype.apply = function (item) {
return __awaiter(this, void 0, void 0, function () {
var _a, event, _b, resolve, before, before_1, before_1_1, plugin, e_1_1, enrichment, enrichment_1, enrichment_1_1, plugin, e_2_1, destination, executeDestinations;
var e_1, _c, e_2, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
if (!item) {
return [2 /*return*/];
}
_a = __read(item, 1), event = _a[0];
_b = __read(item, 2), resolve = _b[1];
before = this.plugins.filter(function (plugin) { return plugin.type === PluginType.BEFORE; });
_e.label = 1;
case 1:
_e.trys.push([1, 6, 7, 8]);
before_1 = __values(before), before_1_1 = before_1.next();
_e.label = 2;
case 2:
if (!!before_1_1.done) return [3 /*break*/, 5];
plugin = before_1_1.value;
return [4 /*yield*/, plugin.execute(__assign({}, event))];
case 3:
event = _e.sent();
_e.label = 4;
case 4:
before_1_1 = before_1.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _e.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (before_1_1 && !before_1_1.done && (_c = before_1.return)) _c.call(before_1);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8:
enrichment = this.plugins.filter(function (plugin) { return plugin.type === PluginType.ENRICHMENT; });
_e.label = 9;
case 9:
_e.trys.push([9, 14, 15, 16]);
enrichment_1 = __values(enrichment), enrichment_1_1 = enrichment_1.next();
_e.label = 10;
case 10:
if (!!enrichment_1_1.done) return [3 /*break*/, 13];
plugin = enrichment_1_1.value;
return [4 /*yield*/, plugin.execute(__assign({}, event))];
case 11:
event = _e.sent();
_e.label = 12;
case 12:
enrichment_1_1 = enrichment_1.next();
return [3 /*break*/, 10];
case 13: return [3 /*break*/, 16];
case 14:
e_2_1 = _e.sent();
e_2 = { error: e_2_1 };
return [3 /*break*/, 16];
case 15:
try {
if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
}
finally { if (e_2) throw e_2.error; }
return [7 /*endfinally*/];
case 16:
destination = this.plugins.filter(function (plugin) { return plugin.type === PluginType.DESTINATION; });
executeDestinations = destination.map(function (plugin) {
var eventClone = __assign({}, event);
return plugin.execute(eventClone).catch(function (e) { return buildResult(eventClone, 0, String(e)); });
});
void Promise.all(executeDestinations).then(function (_a) {
var _b = __read(_a, 1), result = _b[0];
resolve(result);
});
return [2 /*return*/];
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8:
enrichment = plugins.filter(function (plugin) { return plugin.type === PluginType.ENRICHMENT; });
_e.label = 9;
case 9:
_e.trys.push([9, 14, 15, 16]);
enrichment_1 = __values(enrichment), enrichment_1_1 = enrichment_1.next();
_e.label = 10;
case 10:
if (!!enrichment_1_1.done) return [3 /*break*/, 13];
plugin = enrichment_1_1.value;
return [4 /*yield*/, plugin.execute(__assign({}, event))];
case 11:
event = _e.sent();
_e.label = 12;
case 12:
enrichment_1_1 = enrichment_1.next();
return [3 /*break*/, 10];
case 13: return [3 /*break*/, 16];
case 14:
e_2_1 = _e.sent();
e_2 = { error: e_2_1 };
return [3 /*break*/, 16];
case 15:
try {
if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
});
});
};
Timeline.prototype.flush = function () {
return __awaiter(this, void 0, void 0, function () {
var queue, destination, executeDestinations;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
queue = this.queue;
this.queue = [];
return [4 /*yield*/, Promise.all(queue.map(function (item) { return _this.apply(item); }))];
case 1:
_a.sent();
destination = this.plugins.filter(function (plugin) { return plugin.type === PluginType.DESTINATION; });
executeDestinations = destination.map(function (plugin) {
return plugin.flush && plugin.flush();
});
return [4 /*yield*/, Promise.all(executeDestinations)];
case 2:
_a.sent();
return [2 /*return*/];
}
finally { if (e_2) throw e_2.error; }
return [7 /*endfinally*/];
case 16:
destination = plugins.filter(function (plugin) { return plugin.type === PluginType.DESTINATION; });
executeDestinations = destination.map(function (plugin) {
var eventClone = __assign({}, event);
return plugin.execute(eventClone).catch(function (e) { return buildResult(eventClone, 0, String(e)); });
});
void Promise.all(executeDestinations).then(function (_a) {
var _b = __read(_a, 1), result = _b[0];
resolve(result);
});
return [2 /*return*/];
}
});
}); };
export var flush = function (config) { return __awaiter(void 0, void 0, void 0, function () {
var destination, flushDestinations;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
destination = config.plugins.filter(function (plugin) { return plugin.type === PluginType.DESTINATION; });
flushDestinations = destination.map(function (plugin) { return plugin.flush && plugin.flush(true); });
return [4 /*yield*/, Promise.all(flushDestinations)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); };
});
});
};
return Timeline;
}());
export { Timeline };
//# sourceMappingURL=timeline.js.map
{
"name": "@amplitude/analytics-core",
"version": "0.5.0",
"version": "0.6.0",
"description": "",

@@ -35,3 +35,3 @@ "author": "Amplitude Inc",

"dependencies": {
"@amplitude/analytics-types": "^0.4.0",
"@amplitude/analytics-types": "^0.5.0",
"tslib": "^2.3.1"

@@ -42,3 +42,3 @@ },

],
"gitHead": "139379f59cb6ba6031a01355d1125d6b78c12b9c"
"gitHead": "84a7c2295d7a3720fe3b77c57e8f779c4879e57f"
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc