Skip to content

Commit

Permalink
Merge pull request #781 from inplayer-org/add-media-signer-method
Browse files Browse the repository at this point in the history
Add new method for media signing, bump axios version to newest
  • Loading branch information
kiremitrov123 authored Mar 10, 2023
2 parents 63bc768 + e6026b9 commit a1cfcb2
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

# [3.13.6] - 10-03-2023

### Added

- Axios version upgraded to newest
- New `Assets` method `getSignedMediaToken`

# [3.13.5] - 02-02-2023

### Added
Expand Down
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ export interface RequestDataCaptureAccessData {
company: string;
merchant_uuid: string;
}
export interface SignedMediaResponse {
token: string;
}

export declare class Asset {
constructor(config: Record<string, unknown>, Account: Account);
Expand Down Expand Up @@ -537,6 +540,10 @@ export declare class Asset {
requestDataCaptureNoAuthAccess(
accessData: RequestDataCaptureAccessData
): Promise<AxiosResponse<CommonResponse>>;
getSignedMediaToken(
appConfigId: string,
mediaId: string
): Promise<AxiosResponse<SignedMediaResponse>>;
}

export interface BrandingDetails {
Expand Down Expand Up @@ -1102,6 +1109,7 @@ export interface ApiEndpoints {
getFreemiumAsset: string;
getCloudfrontURL: (assetId: number, videoUrl: string) => string;
requestCodeAccess: string;
getSignedMediaToken: (assetId: number, merchantUuid: string) => string;
releaseAccessCode: (code: number) => string;
requestDataCaptureNoAuthAccess: string;
// Payment
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@inplayer-org/inplayer.js",
"version": "3.13.5",
"version": "3.13.6",
"author": "InPlayer",
"license": "MIT",
"description": "A Javascript SDK for Inplayer's RESTful API",
Expand Down
3 changes: 3 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export const API = {
`items/access/codes/${codeId}/${fingerprint}`,
// donation
getDonations: (id: number): string => `v2/items/${id}/donations`,
// media signer
getSignedMediaToken: (appConfigId: string, mediaId: string): string =>
`v2/items/jw-media/token?app_config_id=${appConfigId}&media_id=${mediaId}`,

// Payments
getPaymentMethods: '/payments/methods',
Expand Down
69 changes: 60 additions & 9 deletions src/endpoints/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
GetMerchantPackage,
ItemDetailsV1,
RequestDataCaptureAccessData,
SignedMediaPayload,
SignedMediaResponse,
} from '../models/IAsset&Access';
import BaseExtend from '../extends/base';
import { API } from '../constants';
Expand Down Expand Up @@ -59,7 +61,9 @@ class Asset extends BaseExtend {
* }
* ```
*/
async checkAccessForAsset(id: number): Promise<AxiosResponse<GetItemAccessV1>> {
async checkAccessForAsset(
id: number,
): Promise<AxiosResponse<GetItemAccessV1>> {
const tokenObject = await this.request.getToken();

return this.request.authenticatedGet(API.checkAccessForAsset(id), {
Expand Down Expand Up @@ -128,7 +132,10 @@ class Asset extends BaseExtend {
* }
* ```
*/
async getAsset(assetId: number, merchantUuid: string): Promise<AxiosResponse<ItemDetailsV1>> {
async getAsset(
assetId: number,
merchantUuid: string,
): Promise<AxiosResponse<ItemDetailsV1>> {
return this.request.get(API.getAsset(assetId, merchantUuid));
}

Expand Down Expand Up @@ -332,7 +339,9 @@ class Asset extends BaseExtend {
* }
* ```
*/
async getAssetsInPackage(id: number): Promise<AxiosResponse<GetAssetsInPackage>> {
async getAssetsInPackage(
id: number,
): Promise<AxiosResponse<GetAssetsInPackage>> {
return this.request.get(API.getAssetsInPackage(id));
}

Expand Down Expand Up @@ -622,7 +631,9 @@ class Asset extends BaseExtend {
* }
* ```
*/
getAccessCode(assetId: number): CodeAccessData | null | Promise<CodeAccessData | null> {
getAccessCode(
assetId: number,
): CodeAccessData | null | Promise<CodeAccessData | null> {
const accessCode = tokenStorage.getItem(
this.config.INPLAYER_ACCESS_CODE_NAME(assetId),
);
Expand All @@ -632,7 +643,9 @@ class Asset extends BaseExtend {
(resolvedString ? (JSON.parse(resolvedString) as CodeAccessData) : null)) as Promise<CodeAccessData | null>;
}

return accessCode ? (JSON.parse(accessCode as string) as CodeAccessData) : null;
return accessCode
? (JSON.parse(accessCode as string) as CodeAccessData)
: null;
}

/**
Expand All @@ -655,7 +668,9 @@ class Asset extends BaseExtend {
* }]
* ```
*/
async getAccesCodeSessions(codeId: number): Promise<AxiosResponse<Array<CodeAccessSessionsData>>> {
async getAccesCodeSessions(
codeId: number,
): Promise<AxiosResponse<Array<CodeAccessSessionsData>>> {
return this.request.get(API.requestAccessCodeSessions(codeId));
}

Expand All @@ -676,7 +691,9 @@ class Asset extends BaseExtend {
* }
* ```
*/
async terminateSession(assetId: number): Promise<AxiosResponse<CommonResponse> | null> {
async terminateSession(
assetId: number,
): Promise<AxiosResponse<CommonResponse> | null> {
const accessCode: CodeAccessData | null = await this.getAccessCode(assetId);

if (!accessCode) {
Expand Down Expand Up @@ -756,7 +773,10 @@ class Asset extends BaseExtend {
* }
* ```
*/
async getCloudfrontURL(assetId: number, videoUrl: string): Promise<AxiosResponse<CloudfrontUrl>> {
async getCloudfrontURL(
assetId: number,
videoUrl: string,
): Promise<AxiosResponse<CloudfrontUrl>> {
const tokenObject = await this.request.getToken();

return this.request.get(API.getCloudfrontURL(assetId, videoUrl), {
Expand Down Expand Up @@ -793,7 +813,9 @@ class Asset extends BaseExtend {
* }
* ```
*/
async getDonationOptions(assetId: number): Promise<AxiosResponse<DonationDetails>> {
async getDonationOptions(
assetId: number,
): Promise<AxiosResponse<DonationDetails>> {
const tokenObject = await this.request.getToken();

return this.request.get(API.getDonations(assetId), {
Expand All @@ -802,6 +824,35 @@ class Asset extends BaseExtend {
},
});
}

/**
* Retrieves a signed token for media protection
* @method getSignedMediaToken
* @async
* @param {number} appConfigId The id of the config used on the OTT Web App
* @param {number} mediaId The id of the requested media to watch on the OTT Web App
* @example
* InPlayer.Asset
* .getSignedMediaToken('slgaIsfX', 'kAscZclP)
* .then(data => console.log(data));
* @returns {AxiosResponse<SignedMediaResponse>} Contains the data:
* ```typescript
* {
* token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX...
* }
*/
async getSignedMediaToken({
appConfigId,
mediaId,
}: SignedMediaPayload): Promise<AxiosResponse<SignedMediaResponse>> {
const tokenObject = await this.request.getToken();

return this.request.get(API.getSignedMediaToken(appConfigId, mediaId), {
headers: {
Authorization: `Bearer ${tokenObject.token}`,
},
});
}
}

export default Asset;
1 change: 1 addition & 0 deletions src/models/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface ApiEndpoints {
getAssetAccessFees: (id: number) => string;
getCloudfrontURL: (assetId: number, videoUrl: string) => string;
getPurchaseHistory: (status: string, page?: number, size?: number) => string;
getSignedMediaToken: (assetId: number, merchantUuid: string) => string;
// code only
requestCodeAccess: string;
requestAccessCodeSessions: (codeId: number) => string;
Expand Down
32 changes: 26 additions & 6 deletions src/models/IAsset&Access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export interface Gift {
export interface TransactionsDetails {
access_fee_description: string;
action_type: string;
charged_amount: number
charged_amount: number;
client_id: string;
consumer_email: string;
consumer_id: number;
Expand Down Expand Up @@ -357,6 +357,14 @@ export interface AssetsTransactions {
unique_paying_customers: number;
}

export interface SignedMediaPayload {
mediaId: string;
appConfigId: string;
}
export interface SignedMediaResponse {
token: string;
}

export interface Asset extends BaseExtend {
checkAccessForAsset(id: number): Promise<AxiosResponse<GetItemAccessV1>>;
isFreeTrialUsed(id: number): Promise<AxiosResponse<boolean>>;
Expand All @@ -377,15 +385,27 @@ export interface Asset extends BaseExtend {
page?: number,
startDate?: string,
endDate?: string,
type?: string,
type?: string
): Promise<AxiosResponse<AssetsTransactions>>;
getAccessCode(assetId: number): CodeAccessData | null | Promise<CodeAccessData | null>;
requestCodeAccess(data: RequestCodeAccessData): Promise<AxiosResponse<CodeAccessData>>;
getAccesCodeSessions(codeId: number): Promise<AxiosResponse<Array<CodeAccessSessionsData>>>;
terminateSession(assetId: number): Promise<AxiosResponse<CommonResponse> | null>;
getAccessCode(
assetId: number
): CodeAccessData | null | Promise<CodeAccessData | null>;
requestCodeAccess(
data: RequestCodeAccessData
): Promise<AxiosResponse<CodeAccessData>>;
getAccesCodeSessions(
codeId: number
): Promise<AxiosResponse<Array<CodeAccessSessionsData>>>;
terminateSession(
assetId: number
): Promise<AxiosResponse<CommonResponse> | null>;
getCloudfrontURL(
assetId: number,
videoUrl: string
): Promise<AxiosResponse<CloudfrontUrl>>;
getDonationOptions(assetId: number): Promise<AxiosResponse<DonationDetails>>;
getSignedMediaToken(
appConfigId: string,
mediaId: string
): Promise<AxiosResponse<SignedMediaResponse>>;
}

0 comments on commit a1cfcb2

Please sign in to comment.