Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit f9a6702

Browse files
niallzatoNiall Brennan
and
Niall Brennan
authored
Logic to handle Integrations listed under maybeBundledConfigIds (segmentio#564)
* fix: set maybe bundled to unbundled if not added as plugin * fix: set maybe bundled to unbundled if not added as plugin * fix: add test for empty maybeconfig Co-authored-by: Niall Brennan <[email protected]>
1 parent bc43a8b commit f9a6702

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

packages/core/src/plugins/DestinationMetadataEnrichment.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ export class DestinationMetadataEnrichment extends UtilityPlugin {
3737
const unbundled: string[] = [];
3838
const segmentInfo =
3939
(pluginSettings[this.destinationKey] as Record<string, any>) ?? {};
40-
const unbundledIntegrations: string[] =
40+
var unbundledIntegrations: string[] =
4141
segmentInfo.unbundledIntegrations ?? [];
4242

43+
if (segmentInfo.maybeBundledConfigIds) {
44+
const maybeBundledIntegrations: string[] = Object.keys(
45+
segmentInfo.maybeBundledConfigIds
46+
);
47+
unbundledIntegrations = unbundledIntegrations.concat(
48+
maybeBundledIntegrations
49+
);
50+
}
51+
4352
for (const integration of unbundledIntegrations) {
4453
if (!bundled.includes(integration)) {
4554
unbundled.push(integration);

packages/core/src/plugins/__tests__/SegmentDestination.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ describe('SegmentDestination', () => {
9696
settings: {
9797
[SEGMENT_DESTINATION_KEY]: {
9898
unbundledIntegrations: ['firebase'],
99+
maybeBundledConfigIds: {},
99100
},
100101
},
101102
}),
@@ -131,6 +132,43 @@ describe('SegmentDestination', () => {
131132
});
132133
});
133134

135+
it('marks maybeBundled integrations to unbundled if they are not bundled', () => {
136+
const plugin = new SegmentDestination();
137+
const analytics = new SegmentClient({
138+
...clientArgs,
139+
store: new MockSegmentStore({
140+
settings: {
141+
[SEGMENT_DESTINATION_KEY]: {
142+
unbundledIntegrations: ['Amplitude'],
143+
maybeBundledConfigIds: { Mixpanel: ['123'] },
144+
},
145+
},
146+
}),
147+
});
148+
plugin.configure(analytics);
149+
150+
const event: TrackEventType = {
151+
anonymousId: '3534a492-e975-4efa-a18b-3c70c562fec2',
152+
event: 'Awesome event',
153+
type: EventType.TrackEvent,
154+
properties: {},
155+
timestamp: '2000-01-01T00:00:00.000Z',
156+
messageId: '1d1744bf-5beb-41ac-ad7a-943eac33babc',
157+
context: { app: { name: 'TestApp' } },
158+
integrations: {},
159+
};
160+
161+
const result = plugin.execute(event);
162+
expect(result).toEqual({
163+
...event,
164+
_metadata: {
165+
bundled: [],
166+
unbundled: ['Amplitude', 'Mixpanel'],
167+
bundledIds: [],
168+
},
169+
});
170+
});
171+
134172
it('lets plugins/events override destination settings', () => {
135173
const plugin = new SegmentDestination();
136174
// @ts-ignore

0 commit comments

Comments
 (0)