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 1 commit
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
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
17 changes: 14 additions & 3 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
getExternalAsset: (
assetType: string,
externalId: string,
merchantUuid?: string,
merchantUuid?: string
): string => {
let url = `/items/assets/external/${assetType}/${externalId}`;
if (merchantUuid) {
Expand Down 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 All @@ -92,7 +94,7 @@
page: number,
startDate?: string,
endDate?: string,
type?: string,
type?: string
): string => {
let url = `/payments/transactions?exclude=store-payment&size=${size}&page=${page}`;

Expand All @@ -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 Expand Up @@ -137,7 +148,7 @@
merchantUuid: string,
page: number,
size: number,
filter: string,
filter: string
): string =>
`/v2/nfts/${merchantUuid}?filter=${filter}&page=${page}&size=${size}`,
getMerchantNFT: (merchantUuid: string, nftId: number): string =>
Expand Down
65 changes: 43 additions & 22 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 @@ -61,7 +62,7 @@
* ```
*/
async checkAccessForAsset(
id: number,
id: number
): Promise<AxiosResponse<GetItemAccessV1>> {
const tokenObject = await this.request.getToken();

Expand Down Expand Up @@ -133,7 +134,7 @@
*/
async getAsset(
assetId: number,
merchantUuid?: string,
merchantUuid?: string
): Promise<AxiosResponse<ExternalItemDetails>> {
return this.request.get(API.getAsset(assetId, merchantUuid));
}
Expand Down Expand Up @@ -257,10 +258,10 @@
async getExternalAsset(
assetType: string,
externalId: string,
merchantUuid = '',
merchantUuid = ''
): Promise<AxiosResponse<ExternalItemDetails>> {
return this.request.get(
API.getExternalAsset(assetType, externalId, merchantUuid),
API.getExternalAsset(assetType, externalId, merchantUuid)
);
}

Expand Down Expand Up @@ -339,7 +340,7 @@
* ```
*/
async getAssetsInPackage(
id: number,
id: number
): Promise<AxiosResponse<GetAssetsInPackage>> {
return this.request.get(API.getAssetsInPackage(id));
}
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 @@ -530,7 +533,7 @@
page = 0,
startDate?: string,
endDate?: string,
type?: string,
type?: string
): Promise<AxiosResponse<AssetsTransactions>> {
const tokenObject = await this.request.getToken();

Expand All @@ -540,7 +543,7 @@
headers: {
Authorization: `Bearer ${tokenObject.token}`,
},
},
}
);
}

Expand Down Expand Up @@ -583,10 +586,10 @@
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,
31
);

formData.set('item_id', String(item_id));
Expand All @@ -604,7 +607,7 @@

await tokenStorage.setItem(
this.config.INPLAYER_ACCESS_CODE_NAME(item_id),
JSON.stringify(accessCode),
JSON.stringify(accessCode)
);

return response;
Expand All @@ -631,15 +634,16 @@
* ```
*/
getAccessCode(
assetId: number,
assetId: number
): CodeAccessData | null | Promise<CodeAccessData | null> {
const accessCode = tokenStorage.getItem(
this.config.INPLAYER_ACCESS_CODE_NAME(assetId),
this.config.INPLAYER_ACCESS_CODE_NAME(assetId)
);

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 @@ -668,7 +672,7 @@
* ```
*/
async getAccesCodeSessions(
codeId: number,
codeId: number
): Promise<AxiosResponse<Array<CodeAccessSessionsData>>> {
return this.request.get(API.requestAccessCodeSessions(codeId));
}
Expand All @@ -691,7 +695,7 @@
* ```
*/
async terminateSession(
assetId: number,
assetId: number
): Promise<AxiosResponse<CommonResponse> | null> {
const accessCode: CodeAccessData | null = await this.getAccessCode(assetId);

Expand All @@ -700,11 +704,11 @@
}

const response = await this.request.delete(
API.terminateSession(accessCode.code_id, accessCode.browser_fingerprint),
API.terminateSession(accessCode.code_id, accessCode.browser_fingerprint)
);

await tokenStorage.removeItem(
this.config.INPLAYER_ACCESS_CODE_NAME(assetId),
this.config.INPLAYER_ACCESS_CODE_NAME(assetId)
);

return response;
Expand Down Expand Up @@ -751,7 +755,7 @@
return this.request.post(
API.requestDataCaptureNoAuthAccess,
qs.stringify(accessData),
{ headers },
{ headers }
);
}

Expand All @@ -774,7 +778,7 @@
*/
async getCloudfrontURL(
assetId: number,
videoUrl: string,
videoUrl: string
): Promise<AxiosResponse<CloudfrontUrl>> {
const tokenObject = await this.request.getToken();

Expand Down Expand Up @@ -813,7 +817,7 @@
* ```
*/
async getDonationOptions(
assetId: number,
assetId: number
): Promise<AxiosResponse<DonationDetails>> {
const tokenObject = await this.request.getToken();

Expand Down Expand Up @@ -842,7 +846,7 @@
*/
async getSignedMediaToken(
appConfigId: string,
mediaId: string,
mediaId: string
): Promise<AxiosResponse<SignedMediaResponse>> {
const tokenObject = await this.request.getToken();

Expand All @@ -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;
Loading
Loading