Skip to content

Commit

Permalink
fix: fully replace inplayer integration key with jwp (#250)
Browse files Browse the repository at this point in the history
* fix: replace inplayer integration key with jwp
* fix: code review feedback
  • Loading branch information
dbudzins authored Feb 21, 2023
1 parent b50e087 commit e1005f3
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 59 deletions.
9 changes: 4 additions & 5 deletions src/hooks/useClientIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ const useClientIntegration = () => {
config: { integrations },
} = useConfigStore.getState();

const isJWP = !!integrations.jwp?.clientId || !!integrations.inplayer?.clientId;
const jwpIntegration = integrations.jwp?.clientId ? integrations.jwp : integrations.inplayer;
const sandbox = isJWP ? jwpIntegration?.useSandbox : integrations.cleeng?.useSandbox;
const isJWP = !!integrations.jwp?.clientId;
const sandbox = isJWP ? integrations.jwp?.useSandbox : integrations.cleeng?.useSandbox;
const client = isJWP ? ClientIntegrations.JWP : ClientIntegrations.CLEENG;
const clientId = isJWP ? jwpIntegration?.clientId : integrations.cleeng?.id;
const clientOffers = isJWP ? [`${jwpIntegration?.assetId}`] : [`${integrations.cleeng?.monthlyOffer}`, `${integrations.cleeng?.yearlyOffer}`];
const clientId = isJWP ? integrations.jwp?.clientId : integrations.cleeng?.id;
const clientOffers = isJWP ? [`${integrations.jwp?.assetId}`] : [`${integrations.cleeng?.monthlyOffer}`, `${integrations.cleeng?.yearlyOffer}`];

return {
sandbox: sandbox ?? true,
Expand Down
9 changes: 4 additions & 5 deletions src/hooks/useService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ function useService<T>(
}) => T,
): T {
const { config, accessModel } = useConfigStore.getState();
const { cleeng, inplayer, jwp } = config.integrations;
const { cleeng, jwp } = config.integrations;

// AUTHVOD or SVOD for InPlayer integration
if (jwp?.clientId || inplayer?.clientId) {
const integration = jwp?.clientId ? jwp : inplayer;
if (jwp?.clientId) {
return callback({
accountService: inplayerAccountService,
subscriptionService: inplayerSubscriptionService,
checkoutService: inplayerCheckoutService,
config,
accessModel,
sandbox: !!integration?.useSandbox,
authProviderId: integration?.clientId?.toString(),
sandbox: !!jwp?.useSandbox,
authProviderId: jwp?.clientId?.toString(),
});
}

Expand Down
11 changes: 0 additions & 11 deletions src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { array, boolean, mixed, number, object, SchemaOf, string, StringSchema }
import i18next from 'i18next';

import type { Cleeng, JWP, Config, Content, Features, Menu, Styling } from '#types/Config';
import { isTruthyCustomParamValue } from '#src/utils/common';

/**
* Set config setup changes in both config.services.ts and config.d.ts
Expand Down Expand Up @@ -65,7 +64,6 @@ const configSchema: SchemaOf<Config> = object({
features: featuresSchema.notRequired(),
integrations: object({
cleeng: cleengSchema.notRequired(),
inplayer: jwpSchema.notRequired(),
jwp: jwpSchema.notRequired(),
}).notRequired(),
custom: object().notRequired(),
Expand Down Expand Up @@ -105,15 +103,6 @@ const enrichConfig = (config: Config): Config => {
const { content, siteName } = config;
const updatedContent = content.map((content) => Object.assign({ featured: false }, content));

// TODO: Remove this once the inplayer integration structure is added to the dashboard
if (!config.integrations.inplayer?.clientId && config.custom?.['inplayer.clientId']) {
config.integrations.inplayer = {
clientId: config.custom?.['inplayer.clientId'] as string,
assetId: Number(config.custom?.['inplayer.assetId']),
useSandbox: isTruthyCustomParamValue(config.custom?.['inplayer.useSandbox']),
};
}

return { ...config, siteName: siteName || i18next.t('common:default_site_name'), content: updatedContent };
};

Expand Down
10 changes: 5 additions & 5 deletions src/services/inplayer.account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum InPlayerEnv {
}

export const setEnvironment = (config: Config) => {
const env: string = config.integrations?.inplayer?.useSandbox ? InPlayerEnv.Daily : InPlayerEnv.Production;
const env: string = config.integrations?.jwp?.useSandbox ? InPlayerEnv.Daily : InPlayerEnv.Production;
InPlayer.setConfig(env as Env);
};

Expand All @@ -43,7 +43,7 @@ export const login: Login = async ({ config, email, password }) => {
const { data } = await InPlayer.Account.signInV2({
email,
password,
clientId: config.integrations.inplayer?.clientId || '',
clientId: config.integrations.jwp?.clientId || '',
referrer: window.location.href,
});

Expand All @@ -68,7 +68,7 @@ export const register: Register = async ({ config, email, password }) => {
passwordConfirmation: password,
fullName: email,
type: 'consumer',
clientId: config.integrations.inplayer?.clientId || '',
clientId: config.integrations.jwp?.clientId || '',
referrer: window.location.href,
});

Expand Down Expand Up @@ -128,8 +128,8 @@ export const updateCustomer: UpdateCustomer = async (customer) => {

export const getPublisherConsents: GetPublisherConsents = async (config) => {
try {
const { inplayer } = config.integrations;
const { data } = await InPlayer.Account.getRegisterFields(inplayer?.clientId || '');
const { jwp } = config.integrations;
const { data } = await InPlayer.Account.getRegisterFields(jwp?.clientId || '');

// @ts-ignore
// wrong data type from InPlayer SDK (will be updated in the SDK)
Expand Down
2 changes: 1 addition & 1 deletion src/services/inplayer.subscription.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface SubscriptionDetails extends InplayerSubscription {

export async function getActiveSubscription({ config }: { config: Config }) {
try {
const assetId = config.integrations.inplayer?.assetId || 0;
const assetId = config.integrations.jwp?.assetId || 0;
const hasAccess = await InPlayer.Asset.checkAccessForAsset(assetId);

if (hasAccess) {
Expand Down
4 changes: 2 additions & 2 deletions src/stores/AccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const authNeedsRefresh = (auth: AuthData): boolean => {
export const setJwtRefreshTimeout = () => {
const auth = useAccountStore.getState().auth;

// if inplayer integration, skip code below
// if jwp integration, skip code below
if (!auth?.refreshToken) return;

window.clearTimeout(refreshTimeout);
Expand All @@ -54,7 +54,7 @@ export const handleVisibilityChange = () => {
// document is visible again, test if we need to renew the token
const auth = useAccountStore.getState().auth;

// user is not logged in / if inplayer integration, skip code below
// user is not logged in / if jwp integration, skip code below
if (!auth || !auth?.refreshToken) return;

// refresh the jwt token if needed. This starts the timeout as well after receiving the refreshed tokens.
Expand Down
2 changes: 1 addition & 1 deletion src/stores/ConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useConfigStore = createStore<ConfigState>('ConfigStore', (_, get) =
cleeng: {
useSandbox: true,
},
inplayer: {
jwp: {
clientId: null,
assetId: null,
useSandbox: true,
Expand Down
25 changes: 7 additions & 18 deletions src/utils/configLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,12 @@ const maybeInjectAnalyticsLibrary = (config: Config) => {
};

const calculateAccessModel = (config: Config): AccessModel => {
if (config?.integrations?.cleeng) {
const { id, monthlyOffer, yearlyOffer } = config?.integrations?.cleeng || {};

if (!id) return 'AVOD';
if (!monthlyOffer && !yearlyOffer) return 'AUTHVOD';

return 'SVOD';
if (config?.integrations?.cleeng?.id) {
return config?.integrations?.cleeng?.monthlyOffer || config?.integrations?.cleeng?.yearlyOffer ? 'SVOD' : 'AUTHVOD';
}

if (config?.integrations?.jwp || config?.integrations?.inplayer) {
const integration = config?.integrations?.jwp ? config?.integrations?.jwp : config?.integrations?.inplayer;
const { clientId, assetId } = integration || {};

if (!clientId) return 'AVOD';
if (!assetId) return 'AUTHVOD';

return 'SVOD';
if (config?.integrations?.jwp?.clientId) {
return config?.integrations?.jwp?.assetId ? 'SVOD' : 'AUTHVOD';
}

return 'AVOD';
Expand Down Expand Up @@ -112,11 +101,11 @@ export async function loadAndValidateConfig(configSource: string | undefined) {

maybeInjectAnalyticsLibrary(config);

// TODO: refactor this once we have more input how integrations will be handled in dashboard
if (config?.integrations?.cleeng?.id && (config?.integrations?.jwp?.clientId || config?.integrations?.inplayer?.clientId)) {
if (config?.integrations?.cleeng?.id && config?.integrations?.jwp?.clientId) {
throw new Error('Invalid client integration. You cannot have both Cleeng and JWP integrations enabled at the same time.');
}
if (config?.integrations?.cleeng?.id || config?.integrations?.jwp?.clientId || config?.integrations?.inplayer?.clientId) {

if (config?.integrations?.cleeng?.id || config?.integrations?.jwp?.clientId) {
await initializeAccount();
}

Expand Down
16 changes: 6 additions & 10 deletions test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ export interface TestConfig {
}

export const testConfigs = {
inplayerAuth: {
id: 'https://web-ott.s3.eu-west-1.amazonaws.com/apps/configs/daily-avod.json',
label: 'InPlayer AUTHVOD',
jwpAuth: {
id: '9qqwmnbx',
label: 'JWP AUTHVOD',
},
inplayerSvod: {
id: 'https://web-ott.s3.eu-west-1.amazonaws.com/apps/configs/demo.json',
label: 'InPlayer SVOD',
},
inplayerHosted: {
jwpSvod: {
id: 'a2kbjdv0',
label: 'InPlayer Hosted',
label: 'JWP SVOD',
},
basicNoAuth: {
id: 'gnnuzabk',
Expand All @@ -38,7 +34,7 @@ export const testConfigs = {
},
svod: {
id: 'ozylzc5m',
label: 'SVOD',
label: 'Cleeng SVOD',
},
};

Expand Down
1 change: 0 additions & 1 deletion types/Config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type Config = {
adSchedule?: string | null;
integrations: {
cleeng?: Cleeng;
inplayer?: JWP;
jwp?: JWP;
};
assets: { banner?: string | null };
Expand Down

0 comments on commit e1005f3

Please sign in to comment.