@amplitude/analytics-core
Advanced tools
Comparing version 2.0.0-beta.4 to 2.0.0-beta.5
import { Config, DestinationContext as Context, DestinationPlugin, Event, InvalidResponse, PayloadTooLargeResponse, RateLimitResponse, Response, Result, SuccessResponse } from '@amplitude/analytics-types'; | ||
export declare function getResponseBodyString(res: Response): string; | ||
export declare class Destination implements DestinationPlugin { | ||
@@ -17,3 +18,3 @@ name: string; | ||
send(list: Context[], useRetry?: boolean): Promise<void>; | ||
handleReponse(res: Response, list: Context[]): void; | ||
handleResponse(res: Response, list: Context[]): void; | ||
handleSuccessResponse(res: SuccessResponse, list: Context[]): void; | ||
@@ -23,3 +24,3 @@ handleInvalidResponse(res: InvalidResponse, list: Context[]): void; | ||
handleRateLimitResponse(res: RateLimitResponse, list: Context[]): void; | ||
handleOtherReponse(list: Context[]): void; | ||
handleOtherResponse(list: Context[]): void; | ||
fulfillRequest(list: Context[], code: number, message: string): void; | ||
@@ -26,0 +27,0 @@ /** |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Destination = void 0; | ||
exports.Destination = exports.getResponseBodyString = void 0; | ||
var tslib_1 = require("tslib"); | ||
@@ -10,2 +10,20 @@ var analytics_types_1 = require("@amplitude/analytics-types"); | ||
var config_1 = require("../config"); | ||
function getErrorMessage(error) { | ||
if (error instanceof Error) | ||
return error.message; | ||
return String(error); | ||
} | ||
function getResponseBodyString(res) { | ||
var responseBodyString = ''; | ||
try { | ||
if ('body' in res) { | ||
responseBodyString = JSON.stringify(res.body, null, 2); | ||
} | ||
} | ||
catch (_a) { | ||
// to avoid crash, but don't care about the error, add comment to avoid empty block lint error | ||
} | ||
return responseBodyString; | ||
} | ||
exports.getResponseBodyString = getResponseBodyString; | ||
var Destination = /** @class */ (function () { | ||
@@ -122,3 +140,3 @@ function Destination() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var payload, serverUrl, res, responseBody, e_1; | ||
var payload, serverUrl, res, e_1, errorMessage; | ||
return tslib_1.__generator(this, function (_a) { | ||
@@ -154,10 +172,3 @@ switch (_a.label) { | ||
if ('body' in res) { | ||
responseBody = ''; | ||
try { | ||
responseBody = JSON.stringify(res.body, null, 2); | ||
} | ||
catch (_b) { | ||
// to avoid crash, but don't care about the error, add comment to avoid empty block lint error | ||
} | ||
this.fulfillRequest(list, res.statusCode, "".concat(res.status, ": ").concat(responseBody)); | ||
this.fulfillRequest(list, res.statusCode, "".concat(res.status, ": ").concat(getResponseBodyString(res))); | ||
} | ||
@@ -169,7 +180,9 @@ else { | ||
} | ||
this.handleReponse(res, list); | ||
this.handleResponse(res, list); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
this.fulfillRequest(list, 0, String(e_1)); | ||
errorMessage = getErrorMessage(e_1); | ||
this.config.loggerProvider.error(errorMessage); | ||
this.fulfillRequest(list, 0, errorMessage); | ||
return [3 /*break*/, 4]; | ||
@@ -181,19 +194,27 @@ case 4: return [2 /*return*/]; | ||
}; | ||
Destination.prototype.handleReponse = function (res, list) { | ||
Destination.prototype.handleResponse = function (res, list) { | ||
var status = res.status; | ||
switch (status) { | ||
case analytics_types_1.Status.Success: | ||
case analytics_types_1.Status.Success: { | ||
this.handleSuccessResponse(res, list); | ||
break; | ||
case analytics_types_1.Status.Invalid: | ||
} | ||
case analytics_types_1.Status.Invalid: { | ||
this.handleInvalidResponse(res, list); | ||
break; | ||
case analytics_types_1.Status.PayloadTooLarge: | ||
} | ||
case analytics_types_1.Status.PayloadTooLarge: { | ||
this.handlePayloadTooLargeResponse(res, list); | ||
break; | ||
case analytics_types_1.Status.RateLimit: | ||
} | ||
case analytics_types_1.Status.RateLimit: { | ||
this.handleRateLimitResponse(res, list); | ||
break; | ||
default: | ||
this.handleOtherReponse(list); | ||
} | ||
default: { | ||
// log intermediate event status before retry | ||
this.config.loggerProvider.warn("{code: 0, error: \"Status '".concat(status, "' provided for ").concat(list.length, " events\"}")); | ||
this.handleOtherResponse(list); | ||
break; | ||
} | ||
} | ||
@@ -219,2 +240,6 @@ }; | ||
}); | ||
if (retry.length > 0) { | ||
// log intermediate event status before retry | ||
this.config.loggerProvider.warn(getResponseBodyString(res)); | ||
} | ||
this.addToQueue.apply(this, tslib_1.__spreadArray([], tslib_1.__read(retry), false)); | ||
@@ -227,2 +252,4 @@ }; | ||
} | ||
// log intermediate event status before retry | ||
this.config.loggerProvider.warn(getResponseBodyString(res)); | ||
this.config.flushQueueSize /= 2; | ||
@@ -250,5 +277,9 @@ this.addToQueue.apply(this, tslib_1.__spreadArray([], tslib_1.__read(list), false)); | ||
}); | ||
if (retry.length > 0) { | ||
// log intermediate event status before retry | ||
this.config.loggerProvider.warn(getResponseBodyString(res)); | ||
} | ||
this.addToQueue.apply(this, tslib_1.__spreadArray([], tslib_1.__read(retry), false)); | ||
}; | ||
Destination.prototype.handleOtherReponse = function (list) { | ||
Destination.prototype.handleOtherResponse = function (list) { | ||
var _this = this; | ||
@@ -255,0 +286,0 @@ this.addToQueue.apply(this, tslib_1.__spreadArray([], tslib_1.__read(list.map(function (context) { |
import { Config, DestinationContext as Context, DestinationPlugin, Event, InvalidResponse, PayloadTooLargeResponse, RateLimitResponse, Response, Result, SuccessResponse } from '@amplitude/analytics-types'; | ||
export declare function getResponseBodyString(res: Response): string; | ||
export declare class Destination implements DestinationPlugin { | ||
@@ -17,3 +18,3 @@ name: string; | ||
send(list: Context[], useRetry?: boolean): Promise<void>; | ||
handleReponse(res: Response, list: Context[]): void; | ||
handleResponse(res: Response, list: Context[]): void; | ||
handleSuccessResponse(res: SuccessResponse, list: Context[]): void; | ||
@@ -23,3 +24,3 @@ handleInvalidResponse(res: InvalidResponse, list: Context[]): void; | ||
handleRateLimitResponse(res: RateLimitResponse, list: Context[]): void; | ||
handleOtherReponse(list: Context[]): void; | ||
handleOtherResponse(list: Context[]): void; | ||
fulfillRequest(list: Context[], code: number, message: string): void; | ||
@@ -26,0 +27,0 @@ /** |
@@ -8,2 +8,19 @@ import { __awaiter, __generator, __read, __rest, __spreadArray } from "tslib"; | ||
import { createServerConfig } from '../config'; | ||
function getErrorMessage(error) { | ||
if (error instanceof Error) | ||
return error.message; | ||
return String(error); | ||
} | ||
export function getResponseBodyString(res) { | ||
var responseBodyString = ''; | ||
try { | ||
if ('body' in res) { | ||
responseBodyString = JSON.stringify(res.body, null, 2); | ||
} | ||
} | ||
catch (_a) { | ||
// to avoid crash, but don't care about the error, add comment to avoid empty block lint error | ||
} | ||
return responseBodyString; | ||
} | ||
var Destination = /** @class */ (function () { | ||
@@ -120,3 +137,3 @@ function Destination() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var payload, serverUrl, res, responseBody, e_1; | ||
var payload, serverUrl, res, e_1, errorMessage; | ||
return __generator(this, function (_a) { | ||
@@ -152,10 +169,3 @@ switch (_a.label) { | ||
if ('body' in res) { | ||
responseBody = ''; | ||
try { | ||
responseBody = JSON.stringify(res.body, null, 2); | ||
} | ||
catch (_b) { | ||
// to avoid crash, but don't care about the error, add comment to avoid empty block lint error | ||
} | ||
this.fulfillRequest(list, res.statusCode, "".concat(res.status, ": ").concat(responseBody)); | ||
this.fulfillRequest(list, res.statusCode, "".concat(res.status, ": ").concat(getResponseBodyString(res))); | ||
} | ||
@@ -167,7 +177,9 @@ else { | ||
} | ||
this.handleReponse(res, list); | ||
this.handleResponse(res, list); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
this.fulfillRequest(list, 0, String(e_1)); | ||
errorMessage = getErrorMessage(e_1); | ||
this.config.loggerProvider.error(errorMessage); | ||
this.fulfillRequest(list, 0, errorMessage); | ||
return [3 /*break*/, 4]; | ||
@@ -179,19 +191,27 @@ case 4: return [2 /*return*/]; | ||
}; | ||
Destination.prototype.handleReponse = function (res, list) { | ||
Destination.prototype.handleResponse = function (res, list) { | ||
var status = res.status; | ||
switch (status) { | ||
case Status.Success: | ||
case Status.Success: { | ||
this.handleSuccessResponse(res, list); | ||
break; | ||
case Status.Invalid: | ||
} | ||
case Status.Invalid: { | ||
this.handleInvalidResponse(res, list); | ||
break; | ||
case Status.PayloadTooLarge: | ||
} | ||
case Status.PayloadTooLarge: { | ||
this.handlePayloadTooLargeResponse(res, list); | ||
break; | ||
case Status.RateLimit: | ||
} | ||
case Status.RateLimit: { | ||
this.handleRateLimitResponse(res, list); | ||
break; | ||
default: | ||
this.handleOtherReponse(list); | ||
} | ||
default: { | ||
// log intermediate event status before retry | ||
this.config.loggerProvider.warn("{code: 0, error: \"Status '".concat(status, "' provided for ").concat(list.length, " events\"}")); | ||
this.handleOtherResponse(list); | ||
break; | ||
} | ||
} | ||
@@ -217,2 +237,6 @@ }; | ||
}); | ||
if (retry.length > 0) { | ||
// log intermediate event status before retry | ||
this.config.loggerProvider.warn(getResponseBodyString(res)); | ||
} | ||
this.addToQueue.apply(this, __spreadArray([], __read(retry), false)); | ||
@@ -225,2 +249,4 @@ }; | ||
} | ||
// log intermediate event status before retry | ||
this.config.loggerProvider.warn(getResponseBodyString(res)); | ||
this.config.flushQueueSize /= 2; | ||
@@ -248,5 +274,9 @@ this.addToQueue.apply(this, __spreadArray([], __read(list), false)); | ||
}); | ||
if (retry.length > 0) { | ||
// log intermediate event status before retry | ||
this.config.loggerProvider.warn(getResponseBodyString(res)); | ||
} | ||
this.addToQueue.apply(this, __spreadArray([], __read(retry), false)); | ||
}; | ||
Destination.prototype.handleOtherReponse = function (list) { | ||
Destination.prototype.handleOtherResponse = function (list) { | ||
var _this = this; | ||
@@ -253,0 +283,0 @@ this.addToQueue.apply(this, __spreadArray([], __read(list.map(function (context) { |
{ | ||
"name": "@amplitude/analytics-core", | ||
"version": "2.0.0-beta.4", | ||
"version": "2.0.0-beta.5", | ||
"description": "", | ||
@@ -37,3 +37,3 @@ "author": "Amplitude Inc", | ||
"dependencies": { | ||
"@amplitude/analytics-types": "^2.0.0-beta.4", | ||
"@amplitude/analytics-types": "^2.0.0-beta.5", | ||
"tslib": "^2.4.1" | ||
@@ -44,3 +44,3 @@ }, | ||
], | ||
"gitHead": "195530d7dd4f5283dd5e2f368fb1785a249dbf11" | ||
"gitHead": "13a7abe41cacf525c484b2b324602ad99a6114b5" | ||
} |
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
360904
3522