@segment/analytics-core
Advanced tools
Comparing version 1.5.1 to 1.6.0
@@ -34,2 +34,3 @@ "use strict"; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var handleLoadError, err_1; | ||
var _this = this; | ||
@@ -39,4 +40,4 @@ return tslib_1.__generator(this, function (_a) { | ||
case 0: | ||
if (!(plugin.type === 'destination' && plugin.name !== 'Segment.io')) return [3 /*break*/, 1]; | ||
plugin.load(ctx, instance).catch(function (err) { | ||
this.plugins.push(plugin); | ||
handleLoadError = function (err) { | ||
_this.failedInitializations.push(plugin.name); | ||
@@ -51,11 +52,17 @@ _this.emit('initialization_failure', plugin); | ||
_this.plugins = _this.plugins.filter(function (p) { return p !== plugin; }); | ||
}); | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, plugin.load(ctx, instance)]; | ||
}; | ||
if (!(plugin.type === 'destination' && plugin.name !== 'Segment.io')) return [3 /*break*/, 1]; | ||
plugin.load(ctx, instance).catch(handleLoadError); | ||
return [3 /*break*/, 4]; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, plugin.load(ctx, instance)]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
this.plugins.push(plugin); | ||
return [2 /*return*/]; | ||
err_1 = _a.sent(); | ||
handleLoadError(err_1); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -169,3 +176,3 @@ }); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var start, done, err_1, error; | ||
var start, done, err_2, error; | ||
return tslib_1.__generator(this, function (_a) { | ||
@@ -189,8 +196,8 @@ switch (_a.label) { | ||
case 4: | ||
err_1 = _a.sent(); | ||
error = err_1; | ||
err_2 = _a.sent(); | ||
error = err_2; | ||
ctx.log('error', 'Failed to deliver', error); | ||
this.emit('delivery_failure', ctx, error); | ||
ctx.stats.increment('delivery_failed'); | ||
throw err_1; | ||
throw err_2; | ||
case 5: return [2 /*return*/]; | ||
@@ -210,3 +217,3 @@ } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var ctx, err_2, accepted; | ||
var ctx, err_3, accepted; | ||
return tslib_1.__generator(this, function (_a) { | ||
@@ -232,6 +239,6 @@ switch (_a.label) { | ||
case 3: | ||
err_2 = _a.sent(); | ||
accepted = this.enqueuRetry(err_2, ctx); | ||
err_3 = _a.sent(); | ||
accepted = this.enqueuRetry(err_3, ctx); | ||
if (!accepted) { | ||
ctx.setFailedDelivery({ reason: err_2 }); | ||
ctx.setFailedDelivery({ reason: err_3 }); | ||
this.emit('flush', ctx, false); | ||
@@ -238,0 +245,0 @@ } |
@@ -31,2 +31,3 @@ import { __awaiter, __extends, __generator } from "tslib"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var handleLoadError, err_1; | ||
var _this = this; | ||
@@ -36,4 +37,4 @@ return __generator(this, function (_a) { | ||
case 0: | ||
if (!(plugin.type === 'destination' && plugin.name !== 'Segment.io')) return [3 /*break*/, 1]; | ||
plugin.load(ctx, instance).catch(function (err) { | ||
this.plugins.push(plugin); | ||
handleLoadError = function (err) { | ||
_this.failedInitializations.push(plugin.name); | ||
@@ -48,11 +49,17 @@ _this.emit('initialization_failure', plugin); | ||
_this.plugins = _this.plugins.filter(function (p) { return p !== plugin; }); | ||
}); | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, plugin.load(ctx, instance)]; | ||
}; | ||
if (!(plugin.type === 'destination' && plugin.name !== 'Segment.io')) return [3 /*break*/, 1]; | ||
plugin.load(ctx, instance).catch(handleLoadError); | ||
return [3 /*break*/, 4]; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, plugin.load(ctx, instance)]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
this.plugins.push(plugin); | ||
return [2 /*return*/]; | ||
err_1 = _a.sent(); | ||
handleLoadError(err_1); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -166,3 +173,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var start, done, err_1, error; | ||
var start, done, err_2, error; | ||
return __generator(this, function (_a) { | ||
@@ -186,8 +193,8 @@ switch (_a.label) { | ||
case 4: | ||
err_1 = _a.sent(); | ||
error = err_1; | ||
err_2 = _a.sent(); | ||
error = err_2; | ||
ctx.log('error', 'Failed to deliver', error); | ||
this.emit('delivery_failure', ctx, error); | ||
ctx.stats.increment('delivery_failed'); | ||
throw err_1; | ||
throw err_2; | ||
case 5: return [2 /*return*/]; | ||
@@ -207,3 +214,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var ctx, err_2, accepted; | ||
var ctx, err_3, accepted; | ||
return __generator(this, function (_a) { | ||
@@ -229,6 +236,6 @@ switch (_a.label) { | ||
case 3: | ||
err_2 = _a.sent(); | ||
accepted = this.enqueuRetry(err_2, ctx); | ||
err_3 = _a.sent(); | ||
accepted = this.enqueuRetry(err_3, ctx); | ||
if (!accepted) { | ||
ctx.setFailedDelivery({ reason: err_2 }); | ||
ctx.setFailedDelivery({ reason: err_3 }); | ||
this.emit('flush', ctx, false); | ||
@@ -235,0 +242,0 @@ } |
import type { CoreAnalytics } from '../analytics'; | ||
import type { CoreContext } from '../context'; | ||
interface CorePluginConfig { | ||
options: any; | ||
priority: 'critical' | 'non-critical'; | ||
} | ||
export type PluginType = 'before' | 'after' | 'destination' | 'enrichment' | 'utility'; | ||
@@ -14,3 +10,3 @@ export interface CorePlugin<Ctx extends CoreContext = CoreContext, Analytics extends CoreAnalytics = any> { | ||
isLoaded: () => boolean; | ||
load: (ctx: Ctx, instance: Analytics, config?: CorePluginConfig) => Promise<unknown>; | ||
load: (ctx: Ctx, instance: Analytics) => Promise<unknown>; | ||
unload?: (ctx: Ctx, instance: Analytics) => Promise<unknown> | unknown; | ||
@@ -25,3 +21,2 @@ ready?: () => Promise<unknown>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@segment/analytics-core", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
import type { CoreAnalytics } from '../analytics' | ||
import type { CoreContext } from '../context' | ||
interface CorePluginConfig { | ||
options: any | ||
priority: 'critical' | 'non-critical' // whether AJS should expect this plugin to be loaded before starting event delivery | ||
} | ||
export type PluginType = | ||
@@ -29,7 +24,3 @@ | 'before' | ||
isLoaded: () => boolean | ||
load: ( | ||
ctx: Ctx, | ||
instance: Analytics, | ||
config?: CorePluginConfig | ||
) => Promise<unknown> | ||
load: (ctx: Ctx, instance: Analytics) => Promise<unknown> | ||
@@ -36,0 +27,0 @@ unload?: (ctx: Ctx, instance: Analytics) => Promise<unknown> | unknown |
@@ -53,21 +53,30 @@ import { CoreAnalytics } from '../analytics' | ||
): Promise<void> { | ||
if (plugin.type === 'destination' && plugin.name !== 'Segment.io') { | ||
plugin.load(ctx, instance).catch((err) => { | ||
this.failedInitializations.push(plugin.name) | ||
this.emit('initialization_failure', plugin) | ||
console.warn(plugin.name, err) | ||
this.plugins.push(plugin) | ||
ctx.log('warn', 'Failed to load destination', { | ||
plugin: plugin.name, | ||
error: err, | ||
}) | ||
const handleLoadError = (err: any) => { | ||
this.failedInitializations.push(plugin.name) | ||
this.emit('initialization_failure', plugin) | ||
console.warn(plugin.name, err) | ||
// Filter out the failed plugin by excluding it from the list | ||
this.plugins = this.plugins.filter((p) => p !== plugin) | ||
ctx.log('warn', 'Failed to load destination', { | ||
plugin: plugin.name, | ||
error: err, | ||
}) | ||
// Filter out the failed plugin by excluding it from the list | ||
this.plugins = this.plugins.filter((p) => p !== plugin) | ||
} | ||
if (plugin.type === 'destination' && plugin.name !== 'Segment.io') { | ||
plugin.load(ctx, instance).catch(handleLoadError) | ||
} else { | ||
await plugin.load(ctx, instance) | ||
// for non-destinations plugins, we do need to wait for them to load | ||
// reminder: action destinations can require plugins that are not of type "destination". | ||
// For example, GA4 loads a type 'before' plugins and addition to a type 'destination' plugin | ||
try { | ||
await plugin.load(ctx, instance) | ||
} catch (err) { | ||
handleLoadError(err) | ||
} | ||
} | ||
this.plugins.push(plugin) | ||
} | ||
@@ -74,0 +83,0 @@ |
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
283657
5132