Skip to content

Commit

Permalink
Merge pull request #813 from inplayer-org/plans-methods
Browse files Browse the repository at this point in the history
added plans methods
  • Loading branch information
mirovladimitrovski authored Jun 17, 2024
2 parents c3a7d50 + 7ac2ca0 commit 7716cb7
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 41 deletions.
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 @@ export const API = {
// 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 @@ export const API = {

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
`/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
`/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 @@ -18,6 +18,7 @@ import {
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
RequestDataCaptureAccessData,
SignedMediaResponse,
SiteEntitlementsResponse,
} from '../models/IAsset&Access';
import BaseExtend from '../extends/base';
import { API } from '../constants';
Expand Down Expand Up @@ -451,7 +452,9 @@ class Asset extends BaseExtend {
* }
* ```
*/
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 @@ -639,7 +642,8 @@ class Asset extends BaseExtend {

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 @@ class Asset extends BaseExtend {
},
});
}

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

0 comments on commit 7716cb7

Please sign in to comment.