Skip to content

Commit a1cfcb2

Browse files
Merge pull request #781 from inplayer-org/add-media-signer-method
Add new method for media signing, bump axios version to newest
2 parents 63bc768 + e6026b9 commit a1cfcb2

File tree

7 files changed

+106
-16
lines changed

7 files changed

+106
-16
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

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

5+
# [3.13.6] - 10-03-2023
6+
7+
### Added
8+
9+
- Axios version upgraded to newest
10+
- New `Assets` method `getSignedMediaToken`
11+
512
# [3.13.5] - 02-02-2023
613

714
### Added

index.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@ export interface RequestDataCaptureAccessData {
494494
company: string;
495495
merchant_uuid: string;
496496
}
497+
export interface SignedMediaResponse {
498+
token: string;
499+
}
497500

498501
export declare class Asset {
499502
constructor(config: Record<string, unknown>, Account: Account);
@@ -537,6 +540,10 @@ export declare class Asset {
537540
requestDataCaptureNoAuthAccess(
538541
accessData: RequestDataCaptureAccessData
539542
): Promise<AxiosResponse<CommonResponse>>;
543+
getSignedMediaToken(
544+
appConfigId: string,
545+
mediaId: string
546+
): Promise<AxiosResponse<SignedMediaResponse>>;
540547
}
541548

542549
export interface BrandingDetails {
@@ -1102,6 +1109,7 @@ export interface ApiEndpoints {
11021109
getFreemiumAsset: string;
11031110
getCloudfrontURL: (assetId: number, videoUrl: string) => string;
11041111
requestCodeAccess: string;
1112+
getSignedMediaToken: (assetId: number, merchantUuid: string) => string;
11051113
releaseAccessCode: (code: number) => string;
11061114
requestDataCaptureNoAuthAccess: string;
11071115
// Payment

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inplayer-org/inplayer.js",
3-
"version": "3.13.5",
3+
"version": "3.13.6",
44
"author": "InPlayer",
55
"license": "MIT",
66
"description": "A Javascript SDK for Inplayer's RESTful API",

src/constants/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export const API = {
6363
`items/access/codes/${codeId}/${fingerprint}`,
6464
// donation
6565
getDonations: (id: number): string => `v2/items/${id}/donations`,
66+
// media signer
67+
getSignedMediaToken: (appConfigId: string, mediaId: string): string =>
68+
`v2/items/jw-media/token?app_config_id=${appConfigId}&media_id=${mediaId}`,
6669

6770
// Payments
6871
getPaymentMethods: '/payments/methods',

src/endpoints/asset.ts

+60-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
GetMerchantPackage,
1818
ItemDetailsV1,
1919
RequestDataCaptureAccessData,
20+
SignedMediaPayload,
21+
SignedMediaResponse,
2022
} from '../models/IAsset&Access';
2123
import BaseExtend from '../extends/base';
2224
import { API } from '../constants';
@@ -59,7 +61,9 @@ class Asset extends BaseExtend {
5961
* }
6062
* ```
6163
*/
62-
async checkAccessForAsset(id: number): Promise<AxiosResponse<GetItemAccessV1>> {
64+
async checkAccessForAsset(
65+
id: number,
66+
): Promise<AxiosResponse<GetItemAccessV1>> {
6367
const tokenObject = await this.request.getToken();
6468

6569
return this.request.authenticatedGet(API.checkAccessForAsset(id), {
@@ -128,7 +132,10 @@ class Asset extends BaseExtend {
128132
* }
129133
* ```
130134
*/
131-
async getAsset(assetId: number, merchantUuid: string): Promise<AxiosResponse<ItemDetailsV1>> {
135+
async getAsset(
136+
assetId: number,
137+
merchantUuid: string,
138+
): Promise<AxiosResponse<ItemDetailsV1>> {
132139
return this.request.get(API.getAsset(assetId, merchantUuid));
133140
}
134141

@@ -332,7 +339,9 @@ class Asset extends BaseExtend {
332339
* }
333340
* ```
334341
*/
335-
async getAssetsInPackage(id: number): Promise<AxiosResponse<GetAssetsInPackage>> {
342+
async getAssetsInPackage(
343+
id: number,
344+
): Promise<AxiosResponse<GetAssetsInPackage>> {
336345
return this.request.get(API.getAssetsInPackage(id));
337346
}
338347

@@ -622,7 +631,9 @@ class Asset extends BaseExtend {
622631
* }
623632
* ```
624633
*/
625-
getAccessCode(assetId: number): CodeAccessData | null | Promise<CodeAccessData | null> {
634+
getAccessCode(
635+
assetId: number,
636+
): CodeAccessData | null | Promise<CodeAccessData | null> {
626637
const accessCode = tokenStorage.getItem(
627638
this.config.INPLAYER_ACCESS_CODE_NAME(assetId),
628639
);
@@ -632,7 +643,9 @@ class Asset extends BaseExtend {
632643
(resolvedString ? (JSON.parse(resolvedString) as CodeAccessData) : null)) as Promise<CodeAccessData | null>;
633644
}
634645

635-
return accessCode ? (JSON.parse(accessCode as string) as CodeAccessData) : null;
646+
return accessCode
647+
? (JSON.parse(accessCode as string) as CodeAccessData)
648+
: null;
636649
}
637650

638651
/**
@@ -655,7 +668,9 @@ class Asset extends BaseExtend {
655668
* }]
656669
* ```
657670
*/
658-
async getAccesCodeSessions(codeId: number): Promise<AxiosResponse<Array<CodeAccessSessionsData>>> {
671+
async getAccesCodeSessions(
672+
codeId: number,
673+
): Promise<AxiosResponse<Array<CodeAccessSessionsData>>> {
659674
return this.request.get(API.requestAccessCodeSessions(codeId));
660675
}
661676

@@ -676,7 +691,9 @@ class Asset extends BaseExtend {
676691
* }
677692
* ```
678693
*/
679-
async terminateSession(assetId: number): Promise<AxiosResponse<CommonResponse> | null> {
694+
async terminateSession(
695+
assetId: number,
696+
): Promise<AxiosResponse<CommonResponse> | null> {
680697
const accessCode: CodeAccessData | null = await this.getAccessCode(assetId);
681698

682699
if (!accessCode) {
@@ -756,7 +773,10 @@ class Asset extends BaseExtend {
756773
* }
757774
* ```
758775
*/
759-
async getCloudfrontURL(assetId: number, videoUrl: string): Promise<AxiosResponse<CloudfrontUrl>> {
776+
async getCloudfrontURL(
777+
assetId: number,
778+
videoUrl: string,
779+
): Promise<AxiosResponse<CloudfrontUrl>> {
760780
const tokenObject = await this.request.getToken();
761781

762782
return this.request.get(API.getCloudfrontURL(assetId, videoUrl), {
@@ -793,7 +813,9 @@ class Asset extends BaseExtend {
793813
* }
794814
* ```
795815
*/
796-
async getDonationOptions(assetId: number): Promise<AxiosResponse<DonationDetails>> {
816+
async getDonationOptions(
817+
assetId: number,
818+
): Promise<AxiosResponse<DonationDetails>> {
797819
const tokenObject = await this.request.getToken();
798820

799821
return this.request.get(API.getDonations(assetId), {
@@ -802,6 +824,35 @@ class Asset extends BaseExtend {
802824
},
803825
});
804826
}
827+
828+
/**
829+
* Retrieves a signed token for media protection
830+
* @method getSignedMediaToken
831+
* @async
832+
* @param {number} appConfigId The id of the config used on the OTT Web App
833+
* @param {number} mediaId The id of the requested media to watch on the OTT Web App
834+
* @example
835+
* InPlayer.Asset
836+
* .getSignedMediaToken('slgaIsfX', 'kAscZclP)
837+
* .then(data => console.log(data));
838+
* @returns {AxiosResponse<SignedMediaResponse>} Contains the data:
839+
* ```typescript
840+
* {
841+
* token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX...
842+
* }
843+
*/
844+
async getSignedMediaToken({
845+
appConfigId,
846+
mediaId,
847+
}: SignedMediaPayload): Promise<AxiosResponse<SignedMediaResponse>> {
848+
const tokenObject = await this.request.getToken();
849+
850+
return this.request.get(API.getSignedMediaToken(appConfigId, mediaId), {
851+
headers: {
852+
Authorization: `Bearer ${tokenObject.token}`,
853+
},
854+
});
855+
}
805856
}
806857

807858
export default Asset;

src/models/Config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface ApiEndpoints {
4343
getAssetAccessFees: (id: number) => string;
4444
getCloudfrontURL: (assetId: number, videoUrl: string) => string;
4545
getPurchaseHistory: (status: string, page?: number, size?: number) => string;
46+
getSignedMediaToken: (assetId: number, merchantUuid: string) => string;
4647
// code only
4748
requestCodeAccess: string;
4849
requestAccessCodeSessions: (codeId: number) => string;

src/models/IAsset&Access.ts

+26-6
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export interface Gift {
315315
export interface TransactionsDetails {
316316
access_fee_description: string;
317317
action_type: string;
318-
charged_amount: number
318+
charged_amount: number;
319319
client_id: string;
320320
consumer_email: string;
321321
consumer_id: number;
@@ -357,6 +357,14 @@ export interface AssetsTransactions {
357357
unique_paying_customers: number;
358358
}
359359

360+
export interface SignedMediaPayload {
361+
mediaId: string;
362+
appConfigId: string;
363+
}
364+
export interface SignedMediaResponse {
365+
token: string;
366+
}
367+
360368
export interface Asset extends BaseExtend {
361369
checkAccessForAsset(id: number): Promise<AxiosResponse<GetItemAccessV1>>;
362370
isFreeTrialUsed(id: number): Promise<AxiosResponse<boolean>>;
@@ -377,15 +385,27 @@ export interface Asset extends BaseExtend {
377385
page?: number,
378386
startDate?: string,
379387
endDate?: string,
380-
type?: string,
388+
type?: string
381389
): Promise<AxiosResponse<AssetsTransactions>>;
382-
getAccessCode(assetId: number): CodeAccessData | null | Promise<CodeAccessData | null>;
383-
requestCodeAccess(data: RequestCodeAccessData): Promise<AxiosResponse<CodeAccessData>>;
384-
getAccesCodeSessions(codeId: number): Promise<AxiosResponse<Array<CodeAccessSessionsData>>>;
385-
terminateSession(assetId: number): Promise<AxiosResponse<CommonResponse> | null>;
390+
getAccessCode(
391+
assetId: number
392+
): CodeAccessData | null | Promise<CodeAccessData | null>;
393+
requestCodeAccess(
394+
data: RequestCodeAccessData
395+
): Promise<AxiosResponse<CodeAccessData>>;
396+
getAccesCodeSessions(
397+
codeId: number
398+
): Promise<AxiosResponse<Array<CodeAccessSessionsData>>>;
399+
terminateSession(
400+
assetId: number
401+
): Promise<AxiosResponse<CommonResponse> | null>;
386402
getCloudfrontURL(
387403
assetId: number,
388404
videoUrl: string
389405
): Promise<AxiosResponse<CloudfrontUrl>>;
390406
getDonationOptions(assetId: number): Promise<AxiosResponse<DonationDetails>>;
407+
getSignedMediaToken(
408+
appConfigId: string,
409+
mediaId: string
410+
): Promise<AxiosResponse<SignedMediaResponse>>;
391411
}

0 commit comments

Comments
 (0)