Skip to content

Commit

Permalink
use cmp from libs (#26971)
Browse files Browse the repository at this point in the history
* use cmp from libs

* lint fixes

* use newer canaries version

* fix lint

* cmp from libs and new commercial version

* merge imports

* remove lint disabling

* remove type from requireActual
  • Loading branch information
vlkerag authored Apr 11, 2024
1 parent fe116e5 commit a676b18
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 62 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
"@emotion/styled": "^10.0.27",
"@guardian/ab-core": "^5.0.0",
"@guardian/automat-modules": "^0.3.8",
"@guardian/commercial": "17.8.0",
"@guardian/consent-management-platform": "13.12.1",
"@guardian/commercial": "17.9.0",
"@guardian/core-web-vitals": "^5.0.0",
"@guardian/identity-auth": "2.1.0",
"@guardian/identity-auth-frontend": "4.0.0",
"@guardian/libs": "16.0.2",
"@guardian/libs": "16.1.0",
"@guardian/shimport": "^1.0.2",
"@guardian/source-foundations": "^13.2.1",
"@guardian/source-react-components": "^12.0.0",
Expand Down
3 changes: 1 addition & 2 deletions static/src/javascripts/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import config from 'lib/config';
import { markTime } from 'lib/user-timing';
import { captureOphanInfo } from 'lib/capture-ophan-info';
import { reportError } from 'lib/report-error';
import { cmp, onConsentChange } from '@guardian/consent-management-platform';
import { getLocale, loadScript } from '@guardian/libs';
import { cmp, getLocale, loadScript, onConsentChange } from '@guardian/libs';
import { getCookie } from 'lib/cookies';
import { trackPerformance } from 'common/modules/analytics/google';
import { init as detectAdBlockers } from 'commercial/detect-adblock';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onConsent } from '@guardian/consent-management-platform';
import { onConsent } from '@guardian/libs';

/**
* This local storage item is used to target ads if a user has the correct consents
Expand Down
2 changes: 1 addition & 1 deletion static/src/javascripts/projects/atoms/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isAdFreeUser } from 'common/modules/commercial/user-features';
import {
onConsentChange,
getConsentFor,
} from '@guardian/consent-management-platform';
} from '@guardian/libs';
import { viewport } from './services/viewport';

// Need to pass in the API to native services, something that looks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import type {
AdsConfigCCPAorAus,
AdsConfigTCFV2,
} from '@guardian/commercial/dist/cjs/core/types';
import type {
Callback,
ConsentState,
} from '@guardian/consent-management-platform/dist/types';
import type { ConsentState, OnConsentChangeCallback } from '@guardian/libs';
import { _ as youtubePlayer } from 'common/modules/atoms/youtube-player';

jest.mock('common/modules/commercial/build-page-targeting', () => ({
Expand Down Expand Up @@ -34,8 +31,9 @@ jest.mock('lib/config', () => ({
}),
}));

jest.mock('@guardian/consent-management-platform', () => ({
onConsentChange: jest.fn((callback: Callback) =>
jest.mock('@guardian/libs', () => ({
...jest.requireActual('@guardian/libs'),
onConsentChange: jest.fn((callback: OnConsentChangeCallback) =>
callback({
tcfv2: {
consents: { 1: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type {
AdsConfigEnabled,
AdsConfigTCFV2,
} from '@guardian/commercial/dist/cjs/core/types';
import { onConsentChange } from '@guardian/consent-management-platform';
import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
import { loadScript, log } from '@guardian/libs';
import type { ConsentState } from '@guardian/libs';
import { loadScript, log, onConsentChange } from '@guardian/libs';
import fastdom from 'fastdom';
import { getPageTargeting } from 'common/modules/commercial/build-page-targeting';
import { commercialFeatures } from 'common/modules/commercial/commercial-features';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render } from 'react-dom';
import {
onConsentChange,
getConsentFor,
} from '@guardian/consent-management-platform';
} from '@guardian/libs';
import { isAdFreeUser } from 'common/modules/commercial/user-features';
import config from 'lib/config';
import { AudioPlayer } from './AudioPlayer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import type {
Callback,
ConsentState,
GetConsentFor,
} from '@guardian/consent-management-platform/dist/types';
import type { ConsentState, OnConsentChangeCallback } from '@guardian/libs';
import { hasRequiredConsents } from './hasRequiredConsents';

const brazeVendorId = '5ed8c49c4b8ce4571c7ad801';

let mockOnConsentChangeResult: ConsentState | undefined;
jest.mock('@guardian/consent-management-platform', () => ({
onConsentChange: (callback: Callback) => {
jest.mock('@guardian/libs', () => ({
...jest.requireActual('@guardian/libs'),
onConsentChange: (callback: OnConsentChangeCallback) => {
if (mockOnConsentChangeResult) {
callback(mockOnConsentChangeResult);
}
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- we know getConsentFor is available here
getConsentFor: jest.requireActual('@guardian/consent-management-platform')
.getConsentFor as GetConsentFor,
}));

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
getConsentFor,
onConsentChange,
} from '@guardian/consent-management-platform';
import { getConsentFor, onConsentChange } from '@guardian/libs';

const hasRequiredConsents = (): Promise<boolean> =>
new Promise((resolve, reject) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { buildPageTargeting as buildPageTargeting_ } from '@guardian/commercial';
import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
import type { ConsentState } from '@guardian/libs';
import { getPageTargeting } from './build-page-targeting';

const buildPageTargeting = buildPageTargeting_ as jest.MockedFunction<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import type { PageTargeting } from '@guardian/commercial';
import { buildPageTargeting } from '@guardian/commercial';
import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
import type { ConsentState } from '@guardian/libs';
import { isString, log } from '@guardian/libs';
import { once } from 'lodash-es';
import { getSynchronousParticipations } from 'common/modules/experiments/ab';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
isInABTestSynchronous,
} from 'common/modules/experiments/ab';
import { isUserLoggedIn } from 'common/modules/identity/api';
import { cmp } from '@guardian/consent-management-platform';
import { cmp } from '@guardian/libs';
import { submitClickEventTracking } from './component-event-tracking';

// Helper for setGatePageTargeting function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jest.mock('@guardian/libs', () => ({
local: {
get: jest.fn(() => undefined),
},
}
},
get: jest.fn(() => undefined),
}));

jest.mock('common/modules/experiments/ab', () => ({
Expand All @@ -54,10 +55,6 @@ jest.mock('common/modules/ui/cmp-ui', () => ({
get: jest.fn(() => undefined),
}));

jest.mock('@guardian/consent-management-platform', () => ({
get: jest.fn(() => undefined),
}));

jest.mock('./component-event-tracking', () => ({
get: jest.fn(() => undefined),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jest.mock('@guardian/libs', () => ({
local: {
get: jest.fn(() => [{ count: 2, day: 1 }]),
},
}
},
get: jest.fn(() => undefined)
}));

jest.mock('common/modules/identity/api', () => ({
Expand All @@ -43,10 +44,6 @@ jest.mock('common/modules/ui/cmp-ui', () => ({
get: jest.fn(() => undefined),
}));

jest.mock('@guardian/consent-management-platform', () => ({
get: jest.fn(() => undefined),
}));

jest.mock('lib/cookies', () => ({
getCookie: jest.fn(() => ''),
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onConsentChange } from '@guardian/consent-management-platform';
import { onConsentChange } from '@guardian/libs';
import type {
PageTracking,
Tag,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
getConsentFor,
onConsentChange,
} from '@guardian/consent-management-platform';
import { getConsentFor, onConsentChange } from '@guardian/libs';
import { mediator } from 'lib/mediator';

export const init = (): void => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'lib/config';
import { cmp } from '@guardian/consent-management-platform';
import { cmp } from '@guardian/libs';
import { getPrivacyFramework } from 'lib/getPrivacyFramework';

export const addPrivacySettingsLink = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import config from 'lib/config';
import { cmp } from '@guardian/consent-management-platform';
import { cmp } from '@guardian/libs';
import { cmpBannerCandidate } from './cmp-ui';

jest.mock('lib/raven');

jest.mock('@guardian/consent-management-platform', () => ({
jest.mock('@guardian/libs', () => ({
...jest.requireActual<typeof import('@guardian/libs')>('@guardian/libs'),
cmp: {
willShowPrivacyMessage: jest.fn(),
},
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2380,10 +2380,10 @@
react "^16.13.1"
react-dom "^16.13.1"

"@guardian/commercial@17.8.0":
version "17.8.0"
resolved "https://registry.yarnpkg.com/@guardian/commercial/-/commercial-17.8.0.tgz#1aa3ac254146d5cbfb6253e7f2623119f4743290"
integrity sha512-h3KvoybpvPJOrzrKiSU0Vo09pKQ2OLQ20zqNTbteO5DLrtY0d+0B1qrW2+BjPPb+qCAyTrx6oMFCZrkeGooWBA==
"@guardian/commercial@17.9.0":
version "17.9.0"
resolved "https://registry.yarnpkg.com/@guardian/commercial/-/commercial-17.9.0.tgz#45f1d276bb0253262beb94a28733b0a0368c0704"
integrity sha512-XC9SJ7wXgBHbsBdtOY3X4c17CnOvg7XLSAIGSvQWguKnNSCAW2CwG/o6NP4ybJtySPYP5T99n1+6XjpsnNd+2Q==
dependencies:
"@changesets/cli" "^2.26.2"
"@guardian/ophan-tracker-js" "2.0.4"
Expand All @@ -2397,11 +2397,6 @@
web-vitals "^3.3.2"
wolfy87-eventemitter "^5.2.9"

"@guardian/[email protected]":
version "13.12.1"
resolved "https://registry.yarnpkg.com/@guardian/consent-management-platform/-/consent-management-platform-13.12.1.tgz#699ee56cc695baeb26a1ec702e098d98b1ead255"
integrity sha512-ng6Pl760icPXobdm3qBhV82ATipW/o0nlnBTQTMuYvKVWFEebqFJ5su77/DSaCXyqJkXIKn3UeDTU8JyFQnBtQ==

"@guardian/core-web-vitals@^5.0.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@guardian/core-web-vitals/-/core-web-vitals-5.1.0.tgz#1a7224ff69e773e30698fa16bdd5be608a554ebf"
Expand Down Expand Up @@ -2436,7 +2431,12 @@
resolved "https://registry.yarnpkg.com/@guardian/identity-auth/-/identity-auth-2.1.0.tgz#836f72df35d127a7239987e5fc53155130d0cb4d"
integrity sha512-+AM0pcmRvRZUf92RYGJ2Q6KK1JpnQIxZ6pafsaBMGnF0IwiIk9DdfhaYZl0cyPQ3PwLTJJw2aSl453ivPAmHbw==

"@guardian/[email protected]", "@guardian/libs@^16.0.0":
"@guardian/[email protected]":
version "16.1.0"
resolved "https://registry.yarnpkg.com/@guardian/libs/-/libs-16.1.0.tgz#70d986a312a04e609a89ef1a631f6a3000e322da"
integrity sha512-nb7r0C+UO4P6f0wH8sATtGYnGrfqCzOX4M1Pp2G+uj9c3tehMRSum4mgnqxSAVXN50LtkL2bwd4u3Ichk6670Q==

"@guardian/libs@^16.0.0":
version "16.0.2"
resolved "https://registry.yarnpkg.com/@guardian/libs/-/libs-16.0.2.tgz#df739ffa67f938e125330b52587b33622f8ff797"
integrity sha512-GC3DTyRAWMYNOheSnQES24CA2k9WKZiv+WnZbe3hPu6MsZwjeSeRvylJ+VXk7d2ndX5uDW1OdwkWBX45fVXqsA==
Expand Down

0 comments on commit a676b18

Please sign in to comment.