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

added plans methods #813

Merged
merged 2 commits into from
Jun 17, 2024
Merged
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
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true
"singleQuote": true,
"trailingComma": "all"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

# [3.13.24] - 17-06-2024

### Added

- Method `InPlayer.Payment.getSitePlans`
- Method `InPlayer.Payment.getSitePlanPrices`
- Method `InPlayer.Asset.getSiteEntitlements`

# [3.13.24] - 16-11-2023

### Changes
Expand Down
73 changes: 73 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,68 @@ export interface SignedMediaResponse {
token: string;
}

type JwListResponse<
N extends string = string,
T extends Record<string, unknown> = Record<string, unknown>
> = {
page: number;
total: number;
page_length: number;
} & {
[P in N]: T[];
};

export type PlanDetailsResponse = {
id: string;
original_id: number;
metadata: {
name: string;
access_model: 'svod' | 'authvod' | 'free';
tags: {
include: string[];
exclude: string[];
};
custom_params: {
include: Record<string, string>;
exclude: Record<string, string>;
};
};
relationships: {
prices?: { id: string; type: 'price' }[];
};
created: string;
last_modified: string;
type: 'plan';
schema: string;
};

export type PlansListResponse = JwListResponse<'plans', PlanDetailsResponse>;

export type PlanPrice = {
id: string;
access: {
period: 'month' | 'year';
quantity: number;
type: 'subscription';
};
metadata: {
amount: number;
currency: string;
name: string;
trial?: { period: 'day'; quantity: number } | null;
};
original_id: number;
relationships: {
plans?: { id: string; type: 'plan' }[];
};
schema: string;
type: 'price';
};

export type PlanPricesResponse = JwListResponse<'prices', PlanPrice>;

export type SiteEntitlementsResponse = PlansListResponse;

export declare class Asset {
constructor(config: Record<string, unknown>, Account: Account);

Expand Down Expand Up @@ -599,6 +661,9 @@ export declare class Asset {
appConfigId: string,
mediaId: string
): Promise<AxiosResponse<SignedMediaResponse>>;
getSiteEntitlements(
siteId: string
): Promise<AxiosResponse<SiteEntitlementsResponse>>;
}

export interface BrandingDetails {
Expand Down Expand Up @@ -951,6 +1016,14 @@ export declare class Payment {
validateReceipt: (
data: ValidateReceiptData
) => Promise<AxiosResponse<CommonResponse>>;
getSitePlans: (
siteId: string,
plansIds?: string[]
) => Promise<AxiosResponse<PlansListResponse>>;
getSitePlanPrices: (
siteId: string,
planId: string
) => Promise<AxiosResponse<PlanPricesResponse>>;
}

export interface CreateSubscriptionData {
Expand Down
11 changes: 11 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
// media signer
getSignedMediaToken: (appConfigId: string, mediaId: string): string =>
`v2/items/jw-media/token?app_config_id=${appConfigId}&media_id=${mediaId}`,
getSiteEntitlements: (siteId: string): string =>
`/v3/sites/${siteId}/entitlements`,

// Payments
getPaymentMethods: '/payments/methods',
Expand Down Expand Up @@ -108,6 +110,15 @@

return url;
},
getSitePlans: (siteId: string, plansIds: string[] = []) =>

Check warning on line 113 in src/constants/index.ts

View workflow job for this annotation

GitHub Actions / Build

Missing return type on function

Check warning on line 113 in src/constants/index.ts

View workflow job for this annotation

GitHub Actions / Build

Missing return type on function
`/v3/sites/${siteId}/plans${
plansIds.length
? `q=id:(${plansIds.map((planId) => `"${planId}"`).join(' OR ')})`
: ''
}`,

getSitePlanPrices: (siteId: string, planId: string) =>

Check warning on line 120 in src/constants/index.ts

View workflow job for this annotation

GitHub Actions / Build

Missing return type on function

Check warning on line 120 in src/constants/index.ts

View workflow job for this annotation

GitHub Actions / Build

Missing return type on function
`/v3/sites/${siteId}/plans/${planId}/prices`,

// Subscriptions
getSubscriptions: (limit: number, page: number, status?: string): string => {
Expand Down
25 changes: 23 additions & 2 deletions src/endpoints/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
GetAssetsInPackage,
GetItemAccessV1,
GetMerchantPackage,
ItemDetailsV1,

Check warning on line 18 in src/endpoints/asset.ts

View workflow job for this annotation

GitHub Actions / Build

'ItemDetailsV1' is defined but never used

Check warning on line 18 in src/endpoints/asset.ts

View workflow job for this annotation

GitHub Actions / Build

'ItemDetailsV1' is defined but never used
RequestDataCaptureAccessData,
SignedMediaResponse,
SiteEntitlementsResponse,
} from '../models/IAsset&Access';
import BaseExtend from '../extends/base';
import { API } from '../constants';
Expand Down Expand Up @@ -451,7 +452,9 @@
* }
* ```
*/
async getAssetAccessFees(id: number): Promise<AxiosResponse<GetAccessFeesResponse>> {
async getAssetAccessFees(
id: number,
): Promise<AxiosResponse<GetAccessFeesResponse>> {
return this.request.get(API.getAssetAccessFees(id));
}

Expand Down Expand Up @@ -583,7 +586,7 @@
const browserFingerprint = Fingerprint2.x64hash128(
reduce(
browserDetails,
(acc: string, details: Record<string, any>) => `${acc}${details.value}`,

Check warning on line 589 in src/endpoints/asset.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type

Check warning on line 589 in src/endpoints/asset.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
'',
),
31,
Expand Down Expand Up @@ -639,7 +642,8 @@

if (isPromise(accessCode)) {
return (accessCode as Promise<string>).then((resolvedString) =>
(resolvedString ? (JSON.parse(resolvedString) as CodeAccessData) : null)) as Promise<CodeAccessData | null>;
resolvedString ? (JSON.parse(resolvedString) as CodeAccessData) : null,
) as Promise<CodeAccessData | null>;
}

return accessCode
Expand Down Expand Up @@ -852,6 +856,23 @@
},
});
}

async getSiteEntitlements(
siteId: string,
): Promise<AxiosResponse<SiteEntitlementsResponse>> {
const tokenObject = await this.request.getToken();

const headers: Record<string, string> = {
Accept: 'application/json',
'Content-Type': 'application/json',
};

if (tokenObject.token) {
headers.Authorization = `Bearer ${tokenObject.token}`;
}

return this.request.get(API.getSiteEntitlements(siteId), { headers });
}
}

export default Asset;
30 changes: 28 additions & 2 deletions src/endpoints/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
SetDefaultCard,
DirectDebitMandateResponse,
CreateDirectDebitResponse,
PlansListResponse,
PlanPricesResponse,
} from '../models/IPayment';
import {
CommonResponse,
Expand Down Expand Up @@ -58,7 +60,7 @@ class Payment extends BaseExtend {
*/
async getPaymentMethods(): Promise<
AxiosResponse<Array<MerchantPaymentMethod>>
> {
> {
const tokenObject = await this.request.getToken();

return this.request.authenticatedGet(API.getPaymentMethods, {
Expand Down Expand Up @@ -703,7 +705,7 @@ class Payment extends BaseExtend {
*/
async getDirectDebitMandate(): Promise<
AxiosResponse<DirectDebitMandateResponse>
> {
> {
const tokenObject = await this.request.getToken();

return this.request.authenticatedGet(API.getDirectDebitMandate, {
Expand Down Expand Up @@ -1252,6 +1254,30 @@ class Payment extends BaseExtend {
},
);
}

async getSitePlans(
siteId: string,
plansIds?: string[],
): Promise<AxiosResponse<PlansListResponse>> {
return this.request.get(API.getSitePlans(siteId, plansIds), {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
});
}

async getSitePlanPrices(
siteId: string,
planId: string,
): Promise<AxiosResponse<PlanPricesResponse>> {
return this.request.get(API.getSitePlanPrices(siteId, planId), {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
});
}
}

export default Payment;
31 changes: 17 additions & 14 deletions src/models/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ApiEndpoints {
getExternalAsset: (
assetType: string,
externalId: string,
merchantUuid?: string
merchantUuid?: string,
) => string;
checkAccessForAsset: (id: number) => string;
checkFreeTrial: (id: number) => string;
Expand All @@ -47,6 +47,7 @@ export interface ApiEndpoints {
getPaymentHistory: string;
getBillingReceipt: (trxToken: string) => string;
getSignedMediaToken: (appConfigId: string, mediaId: string) => string;
getSiteEntitlements: (siteId: string) => string;
// code only
requestCodeAccess: string;
requestAccessCodeSessions: (codeId: number) => string;
Expand All @@ -65,12 +66,14 @@ export interface ApiEndpoints {
payForAssetDonation: string;
confirmForAssetDonation: string;
validateReceipt: (platform: string) => string;
getSitePlans: (siteId: string, plansIds?: string[]) => string;
getSitePlanPrices: (siteId: string, planId: string) => string;
getAssetsHistory: (
size: number,
page: number,
startDate?: string,
endDate?: string,
type?: string
type?: string,
) => string;
// Subscriptions
getSubscriptions: (limit: number, page: number) => string;
Expand All @@ -80,7 +83,7 @@ export interface ApiEndpoints {
subscribeV2: string;
changeSubscriptionPlan: (
access_fee_id: number,
inplayer_token: string
inplayer_token: string,
) => string;
// Voucher
getDiscount: string;
Expand All @@ -96,57 +99,57 @@ export interface Request {
setToken(
token: string,
refreshToken: string,
expiresAt: number
expiresAt: number,
): void | Promise<void>;
removeToken(): void | Promise<void>;
get(
path: string,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
post(
path: string,
data: any,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
put(
path: string,
data: any,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
patch(
path: string,
data: any,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
delete(
path: string,
headers?: Record<
string,
Record<string, unknown> | FormData | string | boolean
>
>,
): any;
authenticatedGet(
path: string,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
authenticatedPatch(
path: string,
data: any,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
authenticatedPost(
path: string,
data: any,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
authenticatedPut(
path: string,
data: any,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
authenticatedDelete(
path: string,
headers?: Record<string, Record<string, unknown> | string | boolean>
headers?: Record<string, Record<string, unknown> | string | boolean>,
): any;
setInstanceConfig(configEnv: Env, axiosConfig?: AxiosRequestConfig): void;
}
Loading
Loading