Skip to content

Commit 7716cb7

Browse files
Merge pull request #813 from inplayer-org/plans-methods
added plans methods
2 parents c3a7d50 + 7ac2ca0 commit 7716cb7

File tree

9 files changed

+260
-41
lines changed

9 files changed

+260
-41
lines changed

.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"tabWidth": 2,
33
"useTabs": false,
4-
"singleQuote": true
4+
"singleQuote": true,
5+
"trailingComma": "all"
56
}

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

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

5+
# [3.13.24] - 17-06-2024
6+
7+
### Added
8+
9+
- Method `InPlayer.Payment.getSitePlans`
10+
- Method `InPlayer.Payment.getSitePlanPrices`
11+
- Method `InPlayer.Asset.getSiteEntitlements`
12+
513
# [3.13.24] - 16-11-2023
614

715
### Changes

index.d.ts

+73
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,68 @@ export interface SignedMediaResponse {
553553
token: string;
554554
}
555555

556+
type JwListResponse<
557+
N extends string = string,
558+
T extends Record<string, unknown> = Record<string, unknown>
559+
> = {
560+
page: number;
561+
total: number;
562+
page_length: number;
563+
} & {
564+
[P in N]: T[];
565+
};
566+
567+
export type PlanDetailsResponse = {
568+
id: string;
569+
original_id: number;
570+
metadata: {
571+
name: string;
572+
access_model: 'svod' | 'authvod' | 'free';
573+
tags: {
574+
include: string[];
575+
exclude: string[];
576+
};
577+
custom_params: {
578+
include: Record<string, string>;
579+
exclude: Record<string, string>;
580+
};
581+
};
582+
relationships: {
583+
prices?: { id: string; type: 'price' }[];
584+
};
585+
created: string;
586+
last_modified: string;
587+
type: 'plan';
588+
schema: string;
589+
};
590+
591+
export type PlansListResponse = JwListResponse<'plans', PlanDetailsResponse>;
592+
593+
export type PlanPrice = {
594+
id: string;
595+
access: {
596+
period: 'month' | 'year';
597+
quantity: number;
598+
type: 'subscription';
599+
};
600+
metadata: {
601+
amount: number;
602+
currency: string;
603+
name: string;
604+
trial?: { period: 'day'; quantity: number } | null;
605+
};
606+
original_id: number;
607+
relationships: {
608+
plans?: { id: string; type: 'plan' }[];
609+
};
610+
schema: string;
611+
type: 'price';
612+
};
613+
614+
export type PlanPricesResponse = JwListResponse<'prices', PlanPrice>;
615+
616+
export type SiteEntitlementsResponse = PlansListResponse;
617+
556618
export declare class Asset {
557619
constructor(config: Record<string, unknown>, Account: Account);
558620

@@ -599,6 +661,9 @@ export declare class Asset {
599661
appConfigId: string,
600662
mediaId: string
601663
): Promise<AxiosResponse<SignedMediaResponse>>;
664+
getSiteEntitlements(
665+
siteId: string
666+
): Promise<AxiosResponse<SiteEntitlementsResponse>>;
602667
}
603668

604669
export interface BrandingDetails {
@@ -951,6 +1016,14 @@ export declare class Payment {
9511016
validateReceipt: (
9521017
data: ValidateReceiptData
9531018
) => Promise<AxiosResponse<CommonResponse>>;
1019+
getSitePlans: (
1020+
siteId: string,
1021+
plansIds?: string[]
1022+
) => Promise<AxiosResponse<PlansListResponse>>;
1023+
getSitePlanPrices: (
1024+
siteId: string,
1025+
planId: string
1026+
) => Promise<AxiosResponse<PlanPricesResponse>>;
9541027
}
9551028

9561029
export interface CreateSubscriptionData {

src/constants/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export const API = {
7373
// media signer
7474
getSignedMediaToken: (appConfigId: string, mediaId: string): string =>
7575
`v2/items/jw-media/token?app_config_id=${appConfigId}&media_id=${mediaId}`,
76+
getSiteEntitlements: (siteId: string): string =>
77+
`/v3/sites/${siteId}/entitlements`,
7678

7779
// Payments
7880
getPaymentMethods: '/payments/methods',
@@ -108,6 +110,15 @@ export const API = {
108110

109111
return url;
110112
},
113+
getSitePlans: (siteId: string, plansIds: string[] = []) =>
114+
`/v3/sites/${siteId}/plans${
115+
plansIds.length
116+
? `q=id:(${plansIds.map((planId) => `"${planId}"`).join(' OR ')})`
117+
: ''
118+
}`,
119+
120+
getSitePlanPrices: (siteId: string, planId: string) =>
121+
`/v3/sites/${siteId}/plans/${planId}/prices`,
111122

112123
// Subscriptions
113124
getSubscriptions: (limit: number, page: number, status?: string): string => {

src/endpoints/asset.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ItemDetailsV1,
1919
RequestDataCaptureAccessData,
2020
SignedMediaResponse,
21+
SiteEntitlementsResponse,
2122
} from '../models/IAsset&Access';
2223
import BaseExtend from '../extends/base';
2324
import { API } from '../constants';
@@ -451,7 +452,9 @@ class Asset extends BaseExtend {
451452
* }
452453
* ```
453454
*/
454-
async getAssetAccessFees(id: number): Promise<AxiosResponse<GetAccessFeesResponse>> {
455+
async getAssetAccessFees(
456+
id: number,
457+
): Promise<AxiosResponse<GetAccessFeesResponse>> {
455458
return this.request.get(API.getAssetAccessFees(id));
456459
}
457460

@@ -639,7 +642,8 @@ class Asset extends BaseExtend {
639642

640643
if (isPromise(accessCode)) {
641644
return (accessCode as Promise<string>).then((resolvedString) =>
642-
(resolvedString ? (JSON.parse(resolvedString) as CodeAccessData) : null)) as Promise<CodeAccessData | null>;
645+
resolvedString ? (JSON.parse(resolvedString) as CodeAccessData) : null,
646+
) as Promise<CodeAccessData | null>;
643647
}
644648

645649
return accessCode
@@ -852,6 +856,23 @@ class Asset extends BaseExtend {
852856
},
853857
});
854858
}
859+
860+
async getSiteEntitlements(
861+
siteId: string,
862+
): Promise<AxiosResponse<SiteEntitlementsResponse>> {
863+
const tokenObject = await this.request.getToken();
864+
865+
const headers: Record<string, string> = {
866+
Accept: 'application/json',
867+
'Content-Type': 'application/json',
868+
};
869+
870+
if (tokenObject.token) {
871+
headers.Authorization = `Bearer ${tokenObject.token}`;
872+
}
873+
874+
return this.request.get(API.getSiteEntitlements(siteId), { headers });
875+
}
855876
}
856877

857878
export default Asset;

src/endpoints/payment.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
SetDefaultCard,
1818
DirectDebitMandateResponse,
1919
CreateDirectDebitResponse,
20+
PlansListResponse,
21+
PlanPricesResponse,
2022
} from '../models/IPayment';
2123
import {
2224
CommonResponse,
@@ -58,7 +60,7 @@ class Payment extends BaseExtend {
5860
*/
5961
async getPaymentMethods(): Promise<
6062
AxiosResponse<Array<MerchantPaymentMethod>>
61-
> {
63+
> {
6264
const tokenObject = await this.request.getToken();
6365

6466
return this.request.authenticatedGet(API.getPaymentMethods, {
@@ -703,7 +705,7 @@ class Payment extends BaseExtend {
703705
*/
704706
async getDirectDebitMandate(): Promise<
705707
AxiosResponse<DirectDebitMandateResponse>
706-
> {
708+
> {
707709
const tokenObject = await this.request.getToken();
708710

709711
return this.request.authenticatedGet(API.getDirectDebitMandate, {
@@ -1252,6 +1254,30 @@ class Payment extends BaseExtend {
12521254
},
12531255
);
12541256
}
1257+
1258+
async getSitePlans(
1259+
siteId: string,
1260+
plansIds?: string[],
1261+
): Promise<AxiosResponse<PlansListResponse>> {
1262+
return this.request.get(API.getSitePlans(siteId, plansIds), {
1263+
headers: {
1264+
Accept: 'application/json',
1265+
'Content-Type': 'application/json',
1266+
},
1267+
});
1268+
}
1269+
1270+
async getSitePlanPrices(
1271+
siteId: string,
1272+
planId: string,
1273+
): Promise<AxiosResponse<PlanPricesResponse>> {
1274+
return this.request.get(API.getSitePlanPrices(siteId, planId), {
1275+
headers: {
1276+
Accept: 'application/json',
1277+
'Content-Type': 'application/json',
1278+
},
1279+
});
1280+
}
12551281
}
12561282

12571283
export default Payment;

src/models/Config.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface ApiEndpoints {
3535
getExternalAsset: (
3636
assetType: string,
3737
externalId: string,
38-
merchantUuid?: string
38+
merchantUuid?: string,
3939
) => string;
4040
checkAccessForAsset: (id: number) => string;
4141
checkFreeTrial: (id: number) => string;
@@ -47,6 +47,7 @@ export interface ApiEndpoints {
4747
getPaymentHistory: string;
4848
getBillingReceipt: (trxToken: string) => string;
4949
getSignedMediaToken: (appConfigId: string, mediaId: string) => string;
50+
getSiteEntitlements: (siteId: string) => string;
5051
// code only
5152
requestCodeAccess: string;
5253
requestAccessCodeSessions: (codeId: number) => string;
@@ -65,12 +66,14 @@ export interface ApiEndpoints {
6566
payForAssetDonation: string;
6667
confirmForAssetDonation: string;
6768
validateReceipt: (platform: string) => string;
69+
getSitePlans: (siteId: string, plansIds?: string[]) => string;
70+
getSitePlanPrices: (siteId: string, planId: string) => string;
6871
getAssetsHistory: (
6972
size: number,
7073
page: number,
7174
startDate?: string,
7275
endDate?: string,
73-
type?: string
76+
type?: string,
7477
) => string;
7578
// Subscriptions
7679
getSubscriptions: (limit: number, page: number) => string;
@@ -80,7 +83,7 @@ export interface ApiEndpoints {
8083
subscribeV2: string;
8184
changeSubscriptionPlan: (
8285
access_fee_id: number,
83-
inplayer_token: string
86+
inplayer_token: string,
8487
) => string;
8588
// Voucher
8689
getDiscount: string;
@@ -96,57 +99,57 @@ export interface Request {
9699
setToken(
97100
token: string,
98101
refreshToken: string,
99-
expiresAt: number
102+
expiresAt: number,
100103
): void | Promise<void>;
101104
removeToken(): void | Promise<void>;
102105
get(
103106
path: string,
104-
headers?: Record<string, Record<string, unknown> | string | boolean>
107+
headers?: Record<string, Record<string, unknown> | string | boolean>,
105108
): any;
106109
post(
107110
path: string,
108111
data: any,
109-
headers?: Record<string, Record<string, unknown> | string | boolean>
112+
headers?: Record<string, Record<string, unknown> | string | boolean>,
110113
): any;
111114
put(
112115
path: string,
113116
data: any,
114-
headers?: Record<string, Record<string, unknown> | string | boolean>
117+
headers?: Record<string, Record<string, unknown> | string | boolean>,
115118
): any;
116119
patch(
117120
path: string,
118121
data: any,
119-
headers?: Record<string, Record<string, unknown> | string | boolean>
122+
headers?: Record<string, Record<string, unknown> | string | boolean>,
120123
): any;
121124
delete(
122125
path: string,
123126
headers?: Record<
124127
string,
125128
Record<string, unknown> | FormData | string | boolean
126-
>
129+
>,
127130
): any;
128131
authenticatedGet(
129132
path: string,
130-
headers?: Record<string, Record<string, unknown> | string | boolean>
133+
headers?: Record<string, Record<string, unknown> | string | boolean>,
131134
): any;
132135
authenticatedPatch(
133136
path: string,
134137
data: any,
135-
headers?: Record<string, Record<string, unknown> | string | boolean>
138+
headers?: Record<string, Record<string, unknown> | string | boolean>,
136139
): any;
137140
authenticatedPost(
138141
path: string,
139142
data: any,
140-
headers?: Record<string, Record<string, unknown> | string | boolean>
143+
headers?: Record<string, Record<string, unknown> | string | boolean>,
141144
): any;
142145
authenticatedPut(
143146
path: string,
144147
data: any,
145-
headers?: Record<string, Record<string, unknown> | string | boolean>
148+
headers?: Record<string, Record<string, unknown> | string | boolean>,
146149
): any;
147150
authenticatedDelete(
148151
path: string,
149-
headers?: Record<string, Record<string, unknown> | string | boolean>
152+
headers?: Record<string, Record<string, unknown> | string | boolean>,
150153
): any;
151154
setInstanceConfig(configEnv: Env, axiosConfig?: AxiosRequestConfig): void;
152155
}

0 commit comments

Comments
 (0)