Socket
Socket
Sign inDemoInstall

@amplitude/analytics-core

Package Overview
Dependencies
Maintainers
21
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 2.2.0-featadddiagnostics.0 to 2.2.0

7

lib/cjs/config.d.ts

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

import { Event, Config as IConfig, Diagnostic, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types';
import { Event, Config as IConfig, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType, OfflineDisabled } from '@amplitude/analytics-types';
import { Logger } from './logger';
import { BaseDiagnostic } from './diagnostics/diagnostic';
export declare const getDefaultConfig: () => {

@@ -11,2 +10,3 @@ flushMaxRetries: number;

loggerProvider: Logger;
offline: boolean;
optOut: boolean;

@@ -16,3 +16,2 @@ serverUrl: string;

useBatch: boolean;
diagnosticProvider: BaseDiagnostic;
};

@@ -28,2 +27,3 @@ export declare class Config implements IConfig {

minIdLength?: number;
offline?: boolean | typeof OfflineDisabled;
plan?: Plan;

@@ -36,3 +36,2 @@ ingestionMetadata?: IngestionMetadata;

useBatch: boolean;
diagnosticProvider: Diagnostic;
protected _optOut: boolean;

@@ -39,0 +38,0 @@ get optOut(): boolean;

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

var logger_1 = require("./logger");
var diagnostic_1 = require("./diagnostics/diagnostic");
var getDefaultConfig = function () { return ({

@@ -15,2 +14,3 @@ flushMaxRetries: 12,

loggerProvider: new logger_1.Logger(),
offline: false,
optOut: false,

@@ -20,3 +20,2 @@ serverUrl: constants_1.AMPLITUDE_SERVER_URL,

useBatch: false,
diagnosticProvider: new diagnostic_1.BaseDiagnostic(),
}); };

@@ -26,3 +25,3 @@ exports.getDefaultConfig = getDefaultConfig;

function Config(options) {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d;
this._optOut = false;

@@ -40,2 +39,3 @@ var defaultConfig = (0, exports.getDefaultConfig)();

this.ingestionMetadata = options.ingestionMetadata;
this.offline = options.offline !== undefined ? options.offline : defaultConfig.offline;
this.optOut = (_c = options.optOut) !== null && _c !== void 0 ? _c : defaultConfig.optOut;

@@ -47,6 +47,2 @@ this.serverUrl = options.serverUrl;

this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : defaultConfig.useBatch;
this.diagnosticProvider = (_e = options.diagnosticProvider) !== null && _e !== void 0 ? _e : defaultConfig.diagnosticProvider;
if (!this.diagnosticProvider.apiKey) {
this.diagnosticProvider.apiKey = this.apiKey;
}
this.loggerProvider.enable(this.logLevel);

@@ -53,0 +49,0 @@ var serverConfig = (0, exports.createServerConfig)(options.serverUrl, options.serverZone, options.useBatch);

@@ -5,4 +5,2 @@ export { AmplitudeCore } from './core-client';

export { Destination } from './plugins/destination';
export { BaseDiagnostic } from './diagnostics/diagnostic';
export { DIAGNOSTIC_MESSAGES, DIAGNOSTIC_METADATA_TYPE, DIAGNOSTIC_ENDPOINT } from './diagnostics/constants';
export { Config } from './config';

@@ -17,3 +15,2 @@ export { Logger } from './logger';

export { createIdentifyEvent } from './utils/event-builder';
export { buildResult } from './utils/result-builder';
//# sourceMappingURL=index.d.ts.map
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildResult = exports.createIdentifyEvent = exports.BaseTransport = exports.MemoryStorage = exports.UUID = exports.getClientStates = exports.getClientLogConfig = exports.debugWrapper = exports.returnWrapper = exports.STORAGE_PREFIX = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.DIAGNOSTIC_ENDPOINT = exports.DIAGNOSTIC_METADATA_TYPE = exports.DIAGNOSTIC_MESSAGES = exports.BaseDiagnostic = exports.Destination = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0;
exports.createIdentifyEvent = exports.BaseTransport = exports.MemoryStorage = exports.UUID = exports.getClientStates = exports.getClientLogConfig = exports.debugWrapper = exports.returnWrapper = exports.STORAGE_PREFIX = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0;
var core_client_1 = require("./core-client");

@@ -11,8 +11,2 @@ Object.defineProperty(exports, "AmplitudeCore", { enumerable: true, get: function () { return core_client_1.AmplitudeCore; } });

Object.defineProperty(exports, "Destination", { enumerable: true, get: function () { return destination_1.Destination; } });
var diagnostic_1 = require("./diagnostics/diagnostic");
Object.defineProperty(exports, "BaseDiagnostic", { enumerable: true, get: function () { return diagnostic_1.BaseDiagnostic; } });
var constants_1 = require("./diagnostics/constants");
Object.defineProperty(exports, "DIAGNOSTIC_MESSAGES", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_MESSAGES; } });
Object.defineProperty(exports, "DIAGNOSTIC_METADATA_TYPE", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_METADATA_TYPE; } });
Object.defineProperty(exports, "DIAGNOSTIC_ENDPOINT", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_ENDPOINT; } });
var config_1 = require("./config");

@@ -22,5 +16,5 @@ Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });

Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
var constants_2 = require("./constants");
Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return constants_2.AMPLITUDE_PREFIX; } });
Object.defineProperty(exports, "STORAGE_PREFIX", { enumerable: true, get: function () { return constants_2.STORAGE_PREFIX; } });
var constants_1 = require("./constants");
Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return constants_1.AMPLITUDE_PREFIX; } });
Object.defineProperty(exports, "STORAGE_PREFIX", { enumerable: true, get: function () { return constants_1.STORAGE_PREFIX; } });
var return_wrapper_1 = require("./utils/return-wrapper");

@@ -40,4 +34,2 @@ Object.defineProperty(exports, "returnWrapper", { enumerable: true, get: function () { return return_wrapper_1.returnWrapper; } });

Object.defineProperty(exports, "createIdentifyEvent", { enumerable: true, get: function () { return event_builder_1.createIdentifyEvent; } });
var result_builder_1 = require("./utils/result-builder");
Object.defineProperty(exports, "buildResult", { enumerable: true, get: function () { return result_builder_1.buildResult; } });
//# sourceMappingURL=index.js.map

@@ -18,3 +18,2 @@ import { Config, DestinationContext as Context, DestinationPlugin, Event, InvalidResponse, PayloadTooLargeResponse, RateLimitResponse, Response, Result, SuccessResponse } from '@amplitude/analytics-types';

send(list: Context[], useRetry?: boolean): Promise<void>;
processResponseDiagnostics(res: Response, list: Context[]): void;
handleResponse(res: Response, list: Context[]): void;

@@ -21,0 +20,0 @@ handleSuccessResponse(res: SuccessResponse, list: Context[]): void;

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

var config_1 = require("../config");
var constants_2 = require("../diagnostics/constants");
function getErrorMessage(error) {

@@ -86,3 +85,2 @@ if (error instanceof Error)

void _this.fulfillRequest([context], 500, messages_1.MAX_RETRIES_EXCEEDED_MESSAGE);
_this.config.diagnosticProvider.track(list.length, 500, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_MAX_RETRY);
return false;

@@ -105,4 +103,5 @@ });

var _this = this;
if (this.scheduled)
if (this.scheduled || this.config.offline) {
return;
}
this.scheduled = setTimeout(function () {

@@ -124,2 +123,7 @@ void _this.flush(true).then(function () {

case 0:
// Skip flush if offline
if (this.config.offline) {
this.config.loggerProvider.debug('Skipping flush while offline.');
return [2 /*return*/];
}
list = [];

@@ -172,3 +176,2 @@ later = [];

if (res === null) {
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
this.fulfillRequest(list, 0, messages_1.UNEXPECTED_ERROR_MESSAGE);

@@ -184,3 +187,2 @@ return [2 /*return*/];

}
this.processResponseDiagnostics(res, list);
return [2 /*return*/];

@@ -195,3 +197,2 @@ }

this.fulfillRequest(list, 0, errorMessage);
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
return [3 /*break*/, 4];

@@ -203,28 +204,2 @@ case 4: return [2 /*return*/];

};
Destination.prototype.processResponseDiagnostics = function (res, list) {
var status = res.status;
switch (status) {
case analytics_types_1.Status.Invalid: {
if (res.body.missingField && !res.body.error.startsWith(messages_1.INVALID_API_KEY)) {
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS);
}
else {
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.EVENT_ERROR);
}
break;
}
case analytics_types_1.Status.PayloadTooLarge: {
this.config.diagnosticProvider.track(list.length, 413, constants_2.DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE);
break;
}
case analytics_types_1.Status.RateLimit: {
this.config.diagnosticProvider.track(list.length, 429, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA);
break;
}
default: {
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
break;
}
}
};
Destination.prototype.handleResponse = function (res, list) {

@@ -262,5 +237,2 @@ var status = res.status;

var _this = this;
if (res.body.missingField && !res.body.error.startsWith(messages_1.INVALID_API_KEY)) {
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS);
}
if (res.body.missingField || res.body.error.startsWith(messages_1.INVALID_API_KEY)) {

@@ -272,5 +244,2 @@ this.fulfillRequest(list, res.statusCode, res.body.error);

var dropIndexSet = new Set(dropIndex);
if (dropIndexSet.size) {
this.config.diagnosticProvider.track(dropIndexSet.size, 400, constants_2.DIAGNOSTIC_MESSAGES.EVENT_ERROR);
}
var retry = list.filter(function (context, index) {

@@ -291,3 +260,2 @@ if (dropIndexSet.has(index)) {

if (list.length === 1) {
this.config.diagnosticProvider.track(list.length, 413, constants_2.DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE);
this.fulfillRequest(list, res.statusCode, res.body.error);

@@ -309,3 +277,2 @@ return;

var throttledIndexSet = new Set(throttledIndex);
var dropList = [];
var retry = list.filter(function (context, index) {

@@ -315,3 +282,2 @@ if ((context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||

_this.fulfillRequest([context], res.statusCode, res.body.error);
dropList.push(context);
return;

@@ -324,5 +290,2 @@ }

});
if (dropList.length > 0) {
this.config.diagnosticProvider.track(dropList.length, 429, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA);
}
if (retry.length > 0) {

@@ -329,0 +292,0 @@ // log intermediate event status before retry

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

import { Event, Config as IConfig, Diagnostic, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types';
import { Event, Config as IConfig, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType, OfflineDisabled } from '@amplitude/analytics-types';
import { Logger } from './logger';
import { BaseDiagnostic } from './diagnostics/diagnostic';
export declare const getDefaultConfig: () => {

@@ -11,2 +10,3 @@ flushMaxRetries: number;

loggerProvider: Logger;
offline: boolean;
optOut: boolean;

@@ -16,3 +16,2 @@ serverUrl: string;

useBatch: boolean;
diagnosticProvider: BaseDiagnostic;
};

@@ -28,2 +27,3 @@ export declare class Config implements IConfig {

minIdLength?: number;
offline?: boolean | typeof OfflineDisabled;
plan?: Plan;

@@ -36,3 +36,2 @@ ingestionMetadata?: IngestionMetadata;

useBatch: boolean;
diagnosticProvider: Diagnostic;
protected _optOut: boolean;

@@ -39,0 +38,0 @@ get optOut(): boolean;

import { LogLevel, } 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';
import { BaseDiagnostic } from './diagnostics/diagnostic';
export var getDefaultConfig = function () { return ({

@@ -12,2 +11,3 @@ flushMaxRetries: 12,

loggerProvider: new Logger(),
offline: false,
optOut: false,

@@ -17,7 +17,6 @@ serverUrl: AMPLITUDE_SERVER_URL,

useBatch: false,
diagnosticProvider: new BaseDiagnostic(),
}); };
var Config = /** @class */ (function () {
function Config(options) {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d;
this._optOut = false;

@@ -35,2 +34,3 @@ var defaultConfig = getDefaultConfig();

this.ingestionMetadata = options.ingestionMetadata;
this.offline = options.offline !== undefined ? options.offline : defaultConfig.offline;
this.optOut = (_c = options.optOut) !== null && _c !== void 0 ? _c : defaultConfig.optOut;

@@ -42,6 +42,2 @@ this.serverUrl = options.serverUrl;

this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : defaultConfig.useBatch;
this.diagnosticProvider = (_e = options.diagnosticProvider) !== null && _e !== void 0 ? _e : defaultConfig.diagnosticProvider;
if (!this.diagnosticProvider.apiKey) {
this.diagnosticProvider.apiKey = this.apiKey;
}
this.loggerProvider.enable(this.logLevel);

@@ -48,0 +44,0 @@ var serverConfig = createServerConfig(options.serverUrl, options.serverZone, options.useBatch);

@@ -5,4 +5,2 @@ export { AmplitudeCore } from './core-client';

export { Destination } from './plugins/destination';
export { BaseDiagnostic } from './diagnostics/diagnostic';
export { DIAGNOSTIC_MESSAGES, DIAGNOSTIC_METADATA_TYPE, DIAGNOSTIC_ENDPOINT } from './diagnostics/constants';
export { Config } from './config';

@@ -17,3 +15,2 @@ export { Logger } from './logger';

export { createIdentifyEvent } from './utils/event-builder';
export { buildResult } from './utils/result-builder';
//# sourceMappingURL=index.d.ts.map

@@ -5,4 +5,2 @@ export { AmplitudeCore } from './core-client';

export { Destination } from './plugins/destination';
export { BaseDiagnostic } from './diagnostics/diagnostic';
export { DIAGNOSTIC_MESSAGES, DIAGNOSTIC_METADATA_TYPE, DIAGNOSTIC_ENDPOINT } from './diagnostics/constants';
export { Config } from './config';

@@ -17,3 +15,2 @@ export { Logger } from './logger';

export { createIdentifyEvent } from './utils/event-builder';
export { buildResult } from './utils/result-builder';
//# sourceMappingURL=index.js.map

@@ -18,3 +18,2 @@ import { Config, DestinationContext as Context, DestinationPlugin, Event, InvalidResponse, PayloadTooLargeResponse, RateLimitResponse, Response, Result, SuccessResponse } from '@amplitude/analytics-types';

send(list: Context[], useRetry?: boolean): Promise<void>;
processResponseDiagnostics(res: Response, list: Context[]): void;
handleResponse(res: Response, list: Context[]): void;

@@ -21,0 +20,0 @@ handleSuccessResponse(res: SuccessResponse, list: Context[]): void;

@@ -8,3 +8,2 @@ import { __awaiter, __generator, __read, __rest, __spreadArray } from "tslib";

import { createServerConfig } from '../config';
import { DIAGNOSTIC_MESSAGES } from '../diagnostics/constants';
function getErrorMessage(error) {

@@ -83,3 +82,2 @@ if (error instanceof Error)

void _this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);
_this.config.diagnosticProvider.track(list.length, 500, DIAGNOSTIC_MESSAGES.EXCEEDED_MAX_RETRY);
return false;

@@ -102,4 +100,5 @@ });

var _this = this;
if (this.scheduled)
if (this.scheduled || this.config.offline) {
return;
}
this.scheduled = setTimeout(function () {

@@ -121,2 +120,7 @@ void _this.flush(true).then(function () {

case 0:
// Skip flush if offline
if (this.config.offline) {
this.config.loggerProvider.debug('Skipping flush while offline.');
return [2 /*return*/];
}
list = [];

@@ -169,3 +173,2 @@ later = [];

if (res === null) {
this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);

@@ -181,3 +184,2 @@ return [2 /*return*/];

}
this.processResponseDiagnostics(res, list);
return [2 /*return*/];

@@ -192,3 +194,2 @@ }

this.fulfillRequest(list, 0, errorMessage);
this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
return [3 /*break*/, 4];

@@ -200,28 +201,2 @@ case 4: return [2 /*return*/];

};
Destination.prototype.processResponseDiagnostics = function (res, list) {
var status = res.status;
switch (status) {
case Status.Invalid: {
if (res.body.missingField && !res.body.error.startsWith(INVALID_API_KEY)) {
this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS);
}
else {
this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.EVENT_ERROR);
}
break;
}
case Status.PayloadTooLarge: {
this.config.diagnosticProvider.track(list.length, 413, DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE);
break;
}
case Status.RateLimit: {
this.config.diagnosticProvider.track(list.length, 429, DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA);
break;
}
default: {
this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
break;
}
}
};
Destination.prototype.handleResponse = function (res, list) {

@@ -259,5 +234,2 @@ var status = res.status;

var _this = this;
if (res.body.missingField && !res.body.error.startsWith(INVALID_API_KEY)) {
this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS);
}
if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {

@@ -269,5 +241,2 @@ this.fulfillRequest(list, res.statusCode, res.body.error);

var dropIndexSet = new Set(dropIndex);
if (dropIndexSet.size) {
this.config.diagnosticProvider.track(dropIndexSet.size, 400, DIAGNOSTIC_MESSAGES.EVENT_ERROR);
}
var retry = list.filter(function (context, index) {

@@ -288,3 +257,2 @@ if (dropIndexSet.has(index)) {

if (list.length === 1) {
this.config.diagnosticProvider.track(list.length, 413, DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE);
this.fulfillRequest(list, res.statusCode, res.body.error);

@@ -306,3 +274,2 @@ return;

var throttledIndexSet = new Set(throttledIndex);
var dropList = [];
var retry = list.filter(function (context, index) {

@@ -312,3 +279,2 @@ if ((context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||

_this.fulfillRequest([context], res.statusCode, res.body.error);
dropList.push(context);
return;

@@ -321,5 +287,2 @@ }

});
if (dropList.length > 0) {
this.config.diagnosticProvider.track(dropList.length, 429, DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA);
}
if (retry.length > 0) {

@@ -326,0 +289,0 @@ // log intermediate event status before retry

{
"name": "@amplitude/analytics-core",
"version": "2.2.0-featadddiagnostics.0",
"version": "2.2.0",
"description": "",

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

"dependencies": {
"@amplitude/analytics-types": "^2.4.0-featadddiagnostics.0",
"@amplitude/analytics-types": "^2.4.0",
"tslib": "^2.4.1"

@@ -45,3 +45,3 @@ },

],
"gitHead": "62aaa6f7715b2f084474ad5834bc41423cae338e"
"gitHead": "4be6ee05615bb80434aafdb9276df239a452328f"
}

@@ -10,2 +10,2 @@ <p align="center">

> Internal Node package for Amplitude
Internal Node package for Amplitude

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