Skip to content

Commit 754feaf

Browse files
added plans methods
1 parent c3a7d50 commit 754feaf

File tree

8 files changed

+258
-40
lines changed

8 files changed

+258
-40
lines changed

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const API = {
4242
getExternalAsset: (
4343
assetType: string,
4444
externalId: string,
45-
merchantUuid?: string,
45+
merchantUuid?: string
4646
): string => {
4747
let url = `/items/assets/external/${assetType}/${externalId}`;
4848
if (merchantUuid) {
@@ -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',
@@ -92,7 +94,7 @@ export const API = {
9294
page: number,
9395
startDate?: string,
9496
endDate?: string,
95-
type?: string,
97+
type?: string
9698
): string => {
9799
let url = `/payments/transactions?exclude=store-payment&size=${size}&page=${page}`;
98100

@@ -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 => {
@@ -137,7 +148,7 @@ export const API = {
137148
merchantUuid: string,
138149
page: number,
139150
size: number,
140-
filter: string,
151+
filter: string
141152
): string =>
142153
`/v2/nfts/${merchantUuid}?filter=${filter}&page=${page}&size=${size}`,
143154
getMerchantNFT: (merchantUuid: string, nftId: number): string =>

src/endpoints/asset.ts

+43-22
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';
@@ -61,7 +62,7 @@ class Asset extends BaseExtend {
6162
* ```
6263
*/
6364
async checkAccessForAsset(
64-
id: number,
65+
id: number
6566
): Promise<AxiosResponse<GetItemAccessV1>> {
6667
const tokenObject = await this.request.getToken();
6768

@@ -133,7 +134,7 @@ class Asset extends BaseExtend {
133134
*/
134135
async getAsset(
135136
assetId: number,
136-
merchantUuid?: string,
137+
merchantUuid?: string
137138
): Promise<AxiosResponse<ExternalItemDetails>> {
138139
return this.request.get(API.getAsset(assetId, merchantUuid));
139140
}
@@ -257,10 +258,10 @@ class Asset extends BaseExtend {
257258
async getExternalAsset(
258259
assetType: string,
259260
externalId: string,
260-
merchantUuid = '',
261+
merchantUuid = ''
261262
): Promise<AxiosResponse<ExternalItemDetails>> {
262263
return this.request.get(
263-
API.getExternalAsset(assetType, externalId, merchantUuid),
264+
API.getExternalAsset(assetType, externalId, merchantUuid)
264265
);
265266
}
266267

@@ -339,7 +340,7 @@ class Asset extends BaseExtend {
339340
* ```
340341
*/
341342
async getAssetsInPackage(
342-
id: number,
343+
id: number
343344
): Promise<AxiosResponse<GetAssetsInPackage>> {
344345
return this.request.get(API.getAssetsInPackage(id));
345346
}
@@ -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

@@ -530,7 +533,7 @@ class Asset extends BaseExtend {
530533
page = 0,
531534
startDate?: string,
532535
endDate?: string,
533-
type?: string,
536+
type?: string
534537
): Promise<AxiosResponse<AssetsTransactions>> {
535538
const tokenObject = await this.request.getToken();
536539

@@ -540,7 +543,7 @@ class Asset extends BaseExtend {
540543
headers: {
541544
Authorization: `Bearer ${tokenObject.token}`,
542545
},
543-
},
546+
}
544547
);
545548
}
546549

@@ -584,9 +587,9 @@ class Asset extends BaseExtend {
584587
reduce(
585588
browserDetails,
586589
(acc: string, details: Record<string, any>) => `${acc}${details.value}`,
587-
'',
590+
''
588591
),
589-
31,
592+
31
590593
);
591594

592595
formData.set('item_id', String(item_id));
@@ -604,7 +607,7 @@ class Asset extends BaseExtend {
604607

605608
await tokenStorage.setItem(
606609
this.config.INPLAYER_ACCESS_CODE_NAME(item_id),
607-
JSON.stringify(accessCode),
610+
JSON.stringify(accessCode)
608611
);
609612

610613
return response;
@@ -631,15 +634,16 @@ class Asset extends BaseExtend {
631634
* ```
632635
*/
633636
getAccessCode(
634-
assetId: number,
637+
assetId: number
635638
): CodeAccessData | null | Promise<CodeAccessData | null> {
636639
const accessCode = tokenStorage.getItem(
637-
this.config.INPLAYER_ACCESS_CODE_NAME(assetId),
640+
this.config.INPLAYER_ACCESS_CODE_NAME(assetId)
638641
);
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
@@ -668,7 +672,7 @@ class Asset extends BaseExtend {
668672
* ```
669673
*/
670674
async getAccesCodeSessions(
671-
codeId: number,
675+
codeId: number
672676
): Promise<AxiosResponse<Array<CodeAccessSessionsData>>> {
673677
return this.request.get(API.requestAccessCodeSessions(codeId));
674678
}
@@ -691,7 +695,7 @@ class Asset extends BaseExtend {
691695
* ```
692696
*/
693697
async terminateSession(
694-
assetId: number,
698+
assetId: number
695699
): Promise<AxiosResponse<CommonResponse> | null> {
696700
const accessCode: CodeAccessData | null = await this.getAccessCode(assetId);
697701

@@ -700,11 +704,11 @@ class Asset extends BaseExtend {
700704
}
701705

702706
const response = await this.request.delete(
703-
API.terminateSession(accessCode.code_id, accessCode.browser_fingerprint),
707+
API.terminateSession(accessCode.code_id, accessCode.browser_fingerprint)
704708
);
705709

706710
await tokenStorage.removeItem(
707-
this.config.INPLAYER_ACCESS_CODE_NAME(assetId),
711+
this.config.INPLAYER_ACCESS_CODE_NAME(assetId)
708712
);
709713

710714
return response;
@@ -751,7 +755,7 @@ class Asset extends BaseExtend {
751755
return this.request.post(
752756
API.requestDataCaptureNoAuthAccess,
753757
qs.stringify(accessData),
754-
{ headers },
758+
{ headers }
755759
);
756760
}
757761

@@ -774,7 +778,7 @@ class Asset extends BaseExtend {
774778
*/
775779
async getCloudfrontURL(
776780
assetId: number,
777-
videoUrl: string,
781+
videoUrl: string
778782
): Promise<AxiosResponse<CloudfrontUrl>> {
779783
const tokenObject = await this.request.getToken();
780784

@@ -813,7 +817,7 @@ class Asset extends BaseExtend {
813817
* ```
814818
*/
815819
async getDonationOptions(
816-
assetId: number,
820+
assetId: number
817821
): Promise<AxiosResponse<DonationDetails>> {
818822
const tokenObject = await this.request.getToken();
819823

@@ -842,7 +846,7 @@ class Asset extends BaseExtend {
842846
*/
843847
async getSignedMediaToken(
844848
appConfigId: string,
845-
mediaId: string,
849+
mediaId: string
846850
): Promise<AxiosResponse<SignedMediaResponse>> {
847851
const tokenObject = await this.request.getToken();
848852

@@ -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;

0 commit comments

Comments
 (0)