Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transcend.setAuth() #168

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/transcend-io/consent-manager-ui.git"
},
"homepage": "https://github.com/transcend-io/consent-manager-ui",
"version": "4.15.0",
"version": "4.16.0",
"license": "MIT",
"main": "build/ui",
"files": [
Expand Down Expand Up @@ -44,7 +44,7 @@
},
"devDependencies": {
"@monaco-editor/react": "^4.4.5",
"@transcend-io/airgap.js-types": "^10.12.5",
"@transcend-io/airgap.js-types": "^10.13.0",
"@transcend-io/type-utils": "^1.0.7",
"@types/node": "^17.0.21",
"@typescript-eslint/eslint-plugin": "^5.12.1",
Expand Down
8 changes: 8 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ConsentManagerAPI,
ViewState,
InitialViewState,
AirgapAuth,
} from '@transcend-io/airgap.js-types';
import { isViewStateClosed } from './hooks';
import { logger } from './logger';
Expand All @@ -12,6 +13,7 @@ import {
HandleSetLanguage,
HandleChangePrivacyPolicy,
HandleSetViewState,
HandleChangeAuthKey,
} from './types';
import { VERSION } from './constants';

Expand All @@ -20,6 +22,8 @@ interface MakeConsentManagerAPIInput {
eventTarget: EventTarget;
/** Property for the current view state of the consent manager UI */
viewState: ViewState;
/** Method to change the current auth key */
handleChangeAuthKey: HandleChangeAuthKey;
/** Method to change language */
handleChangeLanguage: HandleSetLanguage;
/** Method to change view state */
Expand All @@ -43,6 +47,7 @@ let promptSuppressionNoticeShown = false;
export function makeConsentManagerAPI({
eventTarget,
viewState,
handleChangeAuthKey,
handleChangeLanguage,
handleChangePrivacyPolicy,
handleChangeSecondaryPolicy,
Expand Down Expand Up @@ -137,6 +142,9 @@ export function makeConsentManagerAPI({
handleSetViewState('open', undefined, true);
return Promise.resolve();
},
setAuth: (key: AirgapAuth): void => {
handleChangeAuthKey(key);
},
version: VERSION,
};

Expand Down
5 changes: 3 additions & 2 deletions src/components/AcceptAll.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h, JSX } from 'preact';
import { useIntl } from 'react-intl';
import { useAirgap } from '../hooks';
import { useAirgap, useAuth } from '../hooks';
import { messages } from '../messages';
import type { HandleSetViewState } from '../types';
import { Button } from './Button';
Expand All @@ -15,6 +15,7 @@ export function AcceptAll({
handleSetViewState: HandleSetViewState;
}): JSX.Element {
const { airgap } = useAirgap();
const { auth } = useAuth();
const { formatMessage } = useIntl();

// Opt in to all purposes
Expand All @@ -24,7 +25,7 @@ export function AcceptAll({
event: JSX.TargetedEvent<HTMLButtonElement, MouseEvent>,
): void => {
event.preventDefault();
airgap.optIn(event);
airgap.optIn(auth || event);
handleSetViewState('close');
};

Expand Down
5 changes: 3 additions & 2 deletions src/components/AcceptAllOrMoreChoices.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h, JSX } from 'preact';
import { useIntl } from 'react-intl';
import { useAirgap } from '../hooks';
import { useAirgap, useAuth } from '../hooks';
import { messages } from '../messages';
import type { HandleSetViewState } from '../types';
import { Button } from './Button';
Expand All @@ -15,6 +15,7 @@ export function AcceptAllOrMoreChoices({
handleSetViewState: HandleSetViewState;
}): JSX.Element {
const { airgap } = useAirgap();
const { auth } = useAuth();
const { formatMessage } = useIntl();

// Opt in to all purposes
Expand All @@ -24,7 +25,7 @@ export function AcceptAllOrMoreChoices({
event: JSX.TargetedEvent<HTMLButtonElement, MouseEvent>,
): void => {
event.preventDefault();
airgap.optIn(event);
airgap.optIn(auth || event);
handleSetViewState('close');
};

Expand Down
5 changes: 3 additions & 2 deletions src/components/AcceptAllRejectAllToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
fontColor: string;
}): JSX.Element {
const { airgap } = useAirgap();
const { auth } = useAuth();

Check failure on line 28 in src/components/AcceptAllRejectAllToggle.tsx

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Cannot find name 'useAuth'.
const { formatMessage } = useIntl();
const [saving, setSaving] = useState<boolean | null>(null);
const [consentLocal, setConsentLocal] = useState(
Expand All @@ -38,10 +39,10 @@
): void => {
if (checked) {
event.preventDefault();
airgap.optIn(event);
airgap.optIn(auth || event);
} else {
event.preventDefault();
airgap.optOut(event);
airgap.optOut(auth || event);
}

setConsentLocal(checked);
Expand Down
15 changes: 12 additions & 3 deletions src/components/AcceptOrRejectAdvertising.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h, JSX } from 'preact';
import { useIntl } from 'react-intl';
import { CONSENT_OPTIONS } from '../constants';
import { useAirgap } from '../hooks';
import { useAirgap, useAuth } from '../hooks';
import { messages } from '../messages';
import type { HandleSetViewState } from '../types';
import { Button } from './Button';
Expand All @@ -16,6 +16,7 @@ export function AcceptOrRejectAdvertising({
handleSetViewState: HandleSetViewState;
}): JSX.Element {
const { airgap } = useAirgap();
const { auth } = useAuth();
const { formatMessage } = useIntl();

return (
Expand Down Expand Up @@ -53,7 +54,11 @@ export function AcceptOrRejectAdvertising({
primaryText={formatMessage(messages.rejectAdvertising)}
handleClick={(event) => {
event.preventDefault();
airgap.setConsent(event, { Advertising: false }, CONSENT_OPTIONS);
airgap.setConsent(
auth || event,
{ Advertising: false },
CONSENT_OPTIONS,
);
handleSetViewState('close');
}}
initialFocus
Expand All @@ -62,7 +67,11 @@ export function AcceptOrRejectAdvertising({
primaryText={formatMessage(messages.acceptAdvertising)}
handleClick={(event) => {
event.preventDefault();
airgap.setConsent(event, { Advertising: true }, CONSENT_OPTIONS);
airgap.setConsent(
auth || event,
{ Advertising: true },
CONSENT_OPTIONS,
);
handleSetViewState('close');
}}
/>
Expand Down
7 changes: 4 additions & 3 deletions src/components/AcceptOrRejectAll.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h, JSX } from 'preact';
import { useIntl } from 'react-intl';
import { useAirgap } from '../hooks';
import { useAirgap, useAuth } from '../hooks';
import { messages } from '../messages';
import type { HandleSetViewState } from '../types';
import { Button } from './Button';
Expand All @@ -15,6 +15,7 @@ export function AcceptOrRejectAll({
handleSetViewState: HandleSetViewState;
}): JSX.Element {
const { airgap } = useAirgap();
const { auth } = useAuth();
const { formatMessage } = useIntl();

// Opt in to all purposes
Expand All @@ -24,7 +25,7 @@ export function AcceptOrRejectAll({
event: JSX.TargetedEvent<HTMLButtonElement, MouseEvent>,
): void => {
event.preventDefault();
airgap.optIn(event);
airgap.optIn(auth || event);
handleSetViewState('close');
};

Expand All @@ -35,7 +36,7 @@ export function AcceptOrRejectAll({
event: JSX.TargetedEvent<HTMLButtonElement, MouseEvent>,
): void => {
event.preventDefault();
airgap.optOut(event);
airgap.optOut(auth || event);
handleSetViewState('close');
};

Expand Down
7 changes: 4 additions & 3 deletions src/components/AcceptOrRejectAllOrMoreChoices.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h, JSX } from 'preact';
import { useIntl } from 'react-intl';
import { useAirgap } from '../hooks';
import { useAirgap, useAuth } from '../hooks';
import { messages } from '../messages';
import type { HandleSetViewState } from '../types';
import { Button } from './Button';
Expand All @@ -15,6 +15,7 @@ export function AcceptOrRejectAllOrMoreChoices({
handleSetViewState: HandleSetViewState;
}): JSX.Element {
const { airgap } = useAirgap();
const { auth } = useAuth();
const { formatMessage } = useIntl();

// Opt in to all purposes
Expand All @@ -24,7 +25,7 @@ export function AcceptOrRejectAllOrMoreChoices({
event: JSX.TargetedEvent<HTMLButtonElement, MouseEvent>,
): void => {
event.preventDefault();
airgap.optIn(event);
airgap.optIn(auth || event);
handleSetViewState('close');
};

Expand All @@ -35,7 +36,7 @@ export function AcceptOrRejectAllOrMoreChoices({
event: JSX.TargetedEvent<HTMLButtonElement, MouseEvent>,
): void => {
event.preventDefault();
airgap.optOut(event);
airgap.optOut(auth || event);
handleSetViewState('close');
};

Expand Down
15 changes: 12 additions & 3 deletions src/components/AcceptOrRejectAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h, JSX } from 'preact';
import { useIntl } from 'react-intl';
import { CONSENT_OPTIONS } from '../constants';
import { useAirgap } from '../hooks';
import { useAirgap, useAuth } from '../hooks';
import { messages } from '../messages';
import type { HandleSetViewState } from '../types';
import { Button } from './Button';
Expand All @@ -16,6 +16,7 @@ export function AcceptOrRejectAnalytics({
handleSetViewState: HandleSetViewState;
}): JSX.Element {
const { airgap } = useAirgap();
const { auth } = useAuth();
const { formatMessage } = useIntl();

return (
Expand Down Expand Up @@ -53,7 +54,11 @@ export function AcceptOrRejectAnalytics({
primaryText={formatMessage(messages.rejectAnalytics)}
handleClick={(event) => {
event.preventDefault();
airgap.setConsent(event, { Analytics: false }, CONSENT_OPTIONS);
airgap.setConsent(
auth || event,
{ Analytics: false },
CONSENT_OPTIONS,
);
handleSetViewState('close');
}}
initialFocus
Expand All @@ -62,7 +67,11 @@ export function AcceptOrRejectAnalytics({
primaryText={formatMessage(messages.acceptAnalytics)}
handleClick={(event) => {
event.preventDefault();
airgap.setConsent(event, { Analytics: true }, CONSENT_OPTIONS);
airgap.setConsent(
auth || event,
{ Analytics: true },
CONSENT_OPTIONS,
);
handleSetViewState('close');
}}
/>
Expand Down
32 changes: 21 additions & 11 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { TranscendEventTarget } from '../event-target';
import { useState } from 'preact/hooks';
import { MergedConsentManagerConfig } from '../types';
import { useAuth } from 'src/hooks/useAuth';

// TODO: https://transcend.height.app/T-13483
// Fix IntlProvider JSX types
Expand Down Expand Up @@ -52,18 +53,26 @@
privacyRegime as keyof typeof initialViewStateByPrivacyRegime
] || 'Hidden';

// Auth key setup
const { auth: storedAuth, handleChangeAuthKey } = useAuth();

Check failure on line 57 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

'storedAuth' is declared but its value is never read.

// View state controller. Defaults based on regime and config.
const { viewState, firstSelectedViewState, handleSetViewState, auth } =
useViewState({
initialViewState,
dismissedViewState,
eventTarget,
savedActiveElement:
document.activeElement instanceof HTMLElement &&
document.activeElement !== document.body
? document.activeElement
: null,
});
const {
viewState,
firstSelectedViewState,
handleSetViewState,
/** auth for triggering authenticated/side-effect view states */
auth,
} = useViewState({
initialViewState,
dismissedViewState,
eventTarget,
savedActiveElement:
document.activeElement instanceof HTMLElement &&
document.activeElement !== document.body
? document.activeElement
: null,
});

// Language setup
const { language, handleChangeLanguage, messages } = useLanguage({
Expand All @@ -80,6 +89,7 @@
const consentManagerAPI = makeConsentManagerAPI({
eventTarget,
viewState,
handleChangeAuthKey,
handleChangeLanguage,
handleSetViewState,
handleChangePrivacyPolicy: (privacyPolicyUrl) =>
Expand Down
5 changes: 3 additions & 2 deletions src/components/CompleteOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h, JSX } from 'preact';
import { useState } from 'preact/hooks';
import { useIntl } from 'react-intl';
import { useAirgap, useGetPurposeMessageKeys } from '../hooks';
import { useAirgap, useAuth, useGetPurposeMessageKeys } from '../hooks';
import { messages, completeOptionsMessages } from '../messages';
import type { ConsentSelection, HandleSetViewState } from '../types';
import { getConsentSelections } from '../consent-selections';
Expand All @@ -22,6 +22,7 @@ export function CompleteOptions({
}): JSX.Element {
const { formatMessage } = useIntl();
const { airgap } = useAirgap();
const { auth } = useAuth();

// Get the tracking purposes from Airgap for display
const initialConsentSelections = getConsentSelections(airgap);
Expand Down Expand Up @@ -54,7 +55,7 @@ export function CompleteOptions({
Object.entries(consentSelections).forEach(([purpose, isChecked]) => {
newConsent.purposes[purpose] = isChecked;
});
airgap.setConsent(event, newConsent.purposes, CONSENT_OPTIONS);
airgap.setConsent(auth || event, newConsent.purposes, CONSENT_OPTIONS);
handleSetViewState('close');
};

Expand Down
Loading
Loading