diff --git a/.changeset/fair-pillows-sin.md b/.changeset/fair-pillows-sin.md index 136df0a4b..53f43b5dc 100644 --- a/.changeset/fair-pillows-sin.md +++ b/.changeset/fair-pillows-sin.md @@ -3,5 +3,5 @@ --- * Rename `shouldLoad` -> `shouldLoadSegment` -* Rename `ctx.abort({ loadSegmentNormally -> disableConsentRequirement` to be more consistent with the setting that shares that name. +* Remove redundant `shouldDisableConsentRequirement` setting, in favor of shouldLoad's `ctx.abort({ disableConsentRequirement: true/false })` * Create `shouldLoadWrapper` API for waiting for consent script initialization. diff --git a/packages/consent/consent-tools/src/domain/__tests__/create-wrapper.test.ts b/packages/consent/consent-tools/src/domain/__tests__/create-wrapper.test.ts index 47f88635a..b9443fa67 100644 --- a/packages/consent/consent-tools/src/domain/__tests__/create-wrapper.test.ts +++ b/packages/consent/consent-tools/src/domain/__tests__/create-wrapper.test.ts @@ -169,16 +169,26 @@ describe(createWrapper, () => { ) it('should allow segment to be loaded normally (with all consent wrapper behavior disabled) via ctx.abort', async () => { + const mockCdnSettings = settingsBuilder.build() + wrapTestAnalytics({ shouldLoadSegment: (ctx) => { ctx.abort({ - disableConsentRequirement: true, // magic config option + disableConsentRequirement: true, }) }, }) - await analytics.load(DEFAULT_LOAD_SETTINGS) + const loadArgs: [any, any] = [ + { + ...DEFAULT_LOAD_SETTINGS, + cdnSettings: mockCdnSettings, + }, + {}, + ] + await analytics.load(...loadArgs) expect(analyticsLoadSpy).toBeCalled() + expect(getAnalyticsLoadLastCall().args).toEqual(loadArgs) }) it('should allow segment loading to be completely aborted via ctx.abort', async () => { @@ -461,75 +471,6 @@ describe(createWrapper, () => { }) }) - describe('shouldDisableConsentRequirement', () => { - describe('if true on wrapper initialization', () => { - it('should load analytics as usual', async () => { - wrapTestAnalytics({ - shouldDisableConsentRequirement: () => true, - }) - await analytics.load(DEFAULT_LOAD_SETTINGS) - expect(analyticsLoadSpy).toBeCalled() - }) - - it('should not call shouldLoadSegment if called on first', async () => { - const shouldLoadSegment = jest.fn() - wrapTestAnalytics({ - shouldDisableConsentRequirement: () => true, - shouldLoadSegment, - }) - await analytics.load(DEFAULT_LOAD_SETTINGS) - expect(shouldLoadSegment).not.toBeCalled() - }) - - it('should work with promises if false', async () => { - const shouldLoadSegment = jest.fn() - wrapTestAnalytics({ - shouldDisableConsentRequirement: () => Promise.resolve(false), - shouldLoadSegment, - }) - await analytics.load(DEFAULT_LOAD_SETTINGS) - expect(shouldLoadSegment).toBeCalled() - }) - - it('should work with promises if true', async () => { - const shouldLoadSegment = jest.fn() - wrapTestAnalytics({ - shouldDisableConsentRequirement: () => Promise.resolve(true), - shouldLoadSegment, - }) - await analytics.load(DEFAULT_LOAD_SETTINGS) - expect(shouldLoadSegment).not.toBeCalled() - }) - - it('should forward all arguments to the original analytics.load method', async () => { - const mockCdnSettings = settingsBuilder.build() - - wrapTestAnalytics({ - shouldDisableConsentRequirement: () => true, - }) - - const loadArgs: [any, any] = [ - { - ...DEFAULT_LOAD_SETTINGS, - cdnSettings: mockCdnSettings, - }, - {}, - ] - await analytics.load(...loadArgs) - expect(analyticsLoadSpy).toBeCalled() - expect(getAnalyticsLoadLastCall().args).toEqual(loadArgs) - }) - - it('should not stamp the event with consent info', async () => { - wrapTestAnalytics({ - shouldDisableConsentRequirement: () => true, - }) - await analytics.load(DEFAULT_LOAD_SETTINGS) - expect(addSourceMiddlewareSpy).not.toBeCalled() - }) - }) - }) - describe('shouldDisableSegment', () => { it('should load analytics if disableAll returns false', async () => { wrapTestAnalytics({ diff --git a/packages/consent/consent-tools/src/domain/create-wrapper.ts b/packages/consent/consent-tools/src/domain/create-wrapper.ts index ee6ffebd4..9ad5f3922 100644 --- a/packages/consent/consent-tools/src/domain/create-wrapper.ts +++ b/packages/consent/consent-tools/src/domain/create-wrapper.ts @@ -24,7 +24,6 @@ export const createWrapper = ( const { shouldDisableSegment, - shouldDisableConsentRequirement, getCategories, shouldLoadSegment, integrationCategoryMappings, @@ -60,13 +59,9 @@ export const createWrapper = ( let initialCategories: Categories try { await loadWrapper - const ctx = new LoadContext() - if (await shouldDisableConsentRequirement?.()) { - throw ctx.abort({ disableConsentRequirement: true }) - } - initialCategories = - (await shouldLoadSegment?.(ctx)) || (await getCategories()) + (await shouldLoadSegment?.(new LoadContext())) || + (await getCategories()) } catch (e: unknown) { // consumer can call ctx.abort({ disableConsentRequirement: true }) // to load Segment but disable consent requirement diff --git a/packages/consent/consent-tools/src/domain/validation/options-validators.ts b/packages/consent/consent-tools/src/domain/validation/options-validators.ts index 061d1e713..183ac5a52 100644 --- a/packages/consent/consent-tools/src/domain/validation/options-validators.ts +++ b/packages/consent/consent-tools/src/domain/validation/options-validators.ts @@ -35,12 +35,6 @@ export function validateSettings(options: { options.shouldLoadSegment && assertIsFunction(options.shouldLoadSegment, 'shouldLoadSegment') - options.shouldDisableConsentRequirement && - assertIsFunction( - options.shouldDisableConsentRequirement, - 'shouldDisableConsentRequirement' - ) - options.shouldEnableIntegration && assertIsFunction(options.shouldEnableIntegration, 'shouldEnableIntegration') diff --git a/packages/consent/consent-tools/src/types/settings.ts b/packages/consent/consent-tools/src/types/settings.ts index ec28882a4..3f855c112 100644 --- a/packages/consent/consent-tools/src/types/settings.ts +++ b/packages/consent/consent-tools/src/types/settings.ts @@ -90,13 +90,6 @@ export interface CreateWrapperSettings { */ registerOnConsentChanged?: RegisterOnConsentChangedFunction - /** - * This permanently disables the consent requirement (i.e device mode gating, event pref stamping) enforced by the wrapper. - * This is the same as doing "ctx.abort({ disableConsentRequirement: true })" inside of `shouldLoadSegment`. - * Called once on wrapper initialization. **shouldLoadSegment will never be called** - **/ - shouldDisableConsentRequirement?: () => boolean | Promise - /** * Disable the Segment analytics SDK completely. analytics.load() will have no effect. * .track / .identify etc calls should not throw any errors, but analytics settings will never be fetched and no events will be sent to Segment.