From 07d377879ae8c10397fcc6a7a5268fe0485d53ee Mon Sep 17 00:00:00 2001 From: mirovladimitrovski Date: Mon, 17 Jun 2024 14:26:20 +0200 Subject: [PATCH] update version in package.json --- .eslintrc | 32 ++-- .prettierrc | 2 +- CHANGELOG.md | 2 +- package.json | 2 +- src/constants/index.ts | 8 +- src/endpoints/account.ts | 336 ++++++++++++++++++++------------- src/endpoints/asset.ts | 84 ++++----- src/endpoints/branding.ts | 2 +- src/endpoints/nfts.ts | 49 +++-- src/endpoints/payment.ts | 188 +++++++++--------- src/endpoints/subscription.ts | 114 ++++++----- src/factories/notifications.ts | 20 +- src/factories/request.ts | 77 ++++---- src/helpers/index.ts | 14 +- src/index.ts | 4 +- 15 files changed, 530 insertions(+), 404 deletions(-) diff --git a/.eslintrc b/.eslintrc index ec79a6a5..a521a6e5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -23,14 +23,20 @@ "no-useless-constructor": 0, "max-classes-per-file": 0, "lines-between-class-members": 0, - "spaced-comment": [ - 2, - "always" - ], - "indent": [ + "no-confusing-arrow": "off", + "function-paren-newline": "off", + "comma-dangle": [ "error", - 2 + { + "arrays": "only-multiline", + "objects": "only-multiline", + "imports": "only-multiline", + "exports": "only-multiline", + "functions": "never" + } ], + "spaced-comment": [2, "always"], + "indent": ["error", 2], "quotes": [ 2, "single", @@ -56,21 +62,13 @@ "class-methods-use-this": "off", "no-throw-literal": "off", "no-shadow": "off", - "@typescript-eslint/no-shadow": [ - "warn" - ], + "@typescript-eslint/no-shadow": ["warn"] }, "settings": { "import/resolver": { "node": { - "paths": [ - "src" - ], - "extensions": [ - ".js", - ".jsx", - ".ts" - ] + "paths": ["src"], + "extensions": [".js", ".jsx", ".ts"] } } } diff --git a/.prettierrc b/.prettierrc index edd0f6c4..a59a0c7f 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,5 +2,5 @@ "tabWidth": 2, "useTabs": false, "singleQuote": true, - "trailingComma": "all" + "trailingComma": "none" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fcc42d8..c1bbab61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -# [3.13.24] - 17-06-2024 +# [3.13.25] - 17-06-2024 ### Added diff --git a/package.json b/package.json index 203febec..fc64e4fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@inplayer-org/inplayer.js", - "version": "3.13.24", + "version": "3.13.25", "author": "InPlayer", "license": "MIT", "description": "A Javascript SDK for Inplayer's RESTful API", diff --git a/src/constants/index.ts b/src/constants/index.ts index e344387d..b8ae9caf 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -42,7 +42,7 @@ export const API = { getExternalAsset: ( assetType: string, externalId: string, - merchantUuid?: string, + merchantUuid?: string ): string => { let url = `/items/assets/external/${assetType}/${externalId}`; if (merchantUuid) { @@ -94,7 +94,7 @@ export const API = { page: number, startDate?: string, endDate?: string, - type?: string, + type?: string ): string => { let url = `/payments/transactions?exclude=store-payment&size=${size}&page=${page}`; @@ -148,7 +148,7 @@ export const API = { 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 => @@ -160,5 +160,5 @@ export const API = { makeReservation: (merchantUuid: string, nftId: number): string => `/v2/nfts/${merchantUuid}/${nftId}/reserve`, - featureFlags: '/v2/features', + featureFlags: '/v2/features' }; diff --git a/src/endpoints/account.ts b/src/endpoints/account.ts index 880f7d19..8f946c9b 100644 --- a/src/endpoints/account.ts +++ b/src/endpoints/account.ts @@ -15,9 +15,12 @@ import { CollectionWithCursorArgs, ProfilesData, GetRegisterFieldsResponse, - FeatureFlagData, + FeatureFlagData } from '../models/IAccount&Authentication'; -import { CommonResponse, CustomErrorResponse } from '../models/CommonInterfaces'; +import { + CommonResponse, + CustomErrorResponse +} from '../models/CommonInterfaces'; import { ApiConfig, Request } from '../models/Config'; import BaseExtend from '../extends/base'; import { API } from '../constants'; @@ -133,7 +136,7 @@ class Account extends BaseExtend { clientSecret, refreshToken, referrer, - password, + password }: { email: string; clientId: string; @@ -146,7 +149,7 @@ class Account extends BaseExtend { const body: AuthenticateRequestBody = { client_id: clientId, grant_type: 'password', - referrer, + referrer }; if (clientSecret) { @@ -164,11 +167,15 @@ class Account extends BaseExtend { const respData = await this.request.post(API.signIn, qs.stringify(body), { headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); - await this.request.setToken(respData.data.access_token, respData.data.refresh_token, respData.data.expires); + await this.request.setToken( + respData.data.access_token, + respData.data.refresh_token, + respData.data.expires + ); return respData; } @@ -221,7 +228,7 @@ class Account extends BaseExtend { email, clientId, referrer, - password, + password }: { email: string; clientId: string; @@ -233,16 +240,20 @@ class Account extends BaseExtend { grant_type: 'password', referrer, username: email, - password, + password }; const respData = await this.request.post(API.signInV2, qs.stringify(body), { headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); - await this.request.setToken(respData.data.access_token, respData.data.refresh_token, respData.data.expires); + await this.request.setToken( + respData.data.access_token, + respData.data.refresh_token, + respData.data.expires + ); return respData; } @@ -312,7 +323,7 @@ class Account extends BaseExtend { clientId, referrer, metadata, - brandingId, + brandingId }: { fullName: string; email: string; @@ -334,14 +345,18 @@ class Account extends BaseExtend { referrer, grant_type: 'password', metadata, - branding_id: brandingId, + branding_id: brandingId }; const resp = await this.request.post(API.signUp, qs.stringify(body), { - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }); - await this.request.setToken(resp.data.access_token, resp.data.refresh_token, resp.data.expires); + await this.request.setToken( + resp.data.access_token, + resp.data.refresh_token, + resp.data.expires + ); return resp; } @@ -411,7 +426,7 @@ class Account extends BaseExtend { type = 'consumer', referrer, metadata, - brandingId, + brandingId }: { fullName: string; email: string; @@ -433,14 +448,18 @@ class Account extends BaseExtend { referrer, grant_type: 'password', metadata, - branding_id: brandingId, + branding_id: brandingId }; const resp = await this.request.post(API.signUpV2, qs.stringify(body), { - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }); - await this.request.setToken(resp.data.access_token, resp.data.refresh_token, resp.data.expires); + await this.request.setToken( + resp.data.access_token, + resp.data.refresh_token, + resp.data.expires + ); return resp; } @@ -458,7 +477,7 @@ class Account extends BaseExtend { const tokenObject = await this.request.getToken(); const response = await this.request.get(API.signOut, { - headers: { Authorization: `Bearer ${tokenObject.token}` }, + headers: { Authorization: `Bearer ${tokenObject.token}` } }); await this.request.removeToken(); @@ -507,8 +526,8 @@ class Account extends BaseExtend { status: 401, data: { code: 401, - message: 'The refresh token is not present', - }, + message: 'The refresh token is not present' + } }; // eslint-disable-next-line no-throw-literal @@ -518,12 +537,16 @@ class Account extends BaseExtend { const body = { refresh_token: tokenObject.refreshToken, client_id: clientId, - grant_type: 'refresh_token', + grant_type: 'refresh_token' }; - const responseData = await this.request.post(API.signIn, qs.stringify(body), { - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - }); + const responseData = await this.request.post( + API.signIn, + qs.stringify(body), + { + headers: { 'Content-Type': 'application/x-www-form-urlencoded' } + } + ); return responseData; } @@ -536,7 +559,11 @@ class Account extends BaseExtend { * If it is not set the token won't be deactivated. * @returns {AxiosResponse} */ - async reportSSOtoken(ssoDomain: string, token: string, deactivate = false): Promise> { + async reportSSOtoken( + ssoDomain: string, + token: string, + deactivate = false + ): Promise> { const body = new FormData(); body.append('token', token); @@ -545,7 +572,7 @@ class Account extends BaseExtend { // TODO: Check if global withCredentials works return this.request.post(API.reportSSOtoken(ssoDomain), body, { headers: { 'Content-Type': 'multipart/form-data' }, - withCredentials: true, + withCredentials: true }); } @@ -579,7 +606,7 @@ class Account extends BaseExtend { async requestNewPassword({ email, merchantUuid, - brandingId, + brandingId }: { email: string; merchantUuid: string; @@ -588,11 +615,11 @@ class Account extends BaseExtend { const body = { email, merchant_uuid: merchantUuid, - branding_id: brandingId, + branding_id: brandingId }; return this.request.post(API.requestNewPassword, qs.stringify(body), { - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }); } @@ -622,13 +649,13 @@ class Account extends BaseExtend { { password, passwordConfirmation, - brandingId, + brandingId }: { password: string; passwordConfirmation: string; brandingId: number; }, - token = '', + token = '' ): Promise> { // TODO: check logic // eslint-disable-next-line max-len @@ -637,7 +664,7 @@ class Account extends BaseExtend { const body = `password=${encodePassword}&password_confirmation=${encodePasswordConfirm}&branding_id=${brandingId}`; return this.request.put(API.setNewPassword(token), body, { - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }); } @@ -660,17 +687,24 @@ class Account extends BaseExtend { * } * ``` */ - async syncWithExternalAccount(integration: string, itemId: number): Promise> { + async syncWithExternalAccount( + integration: string, + itemId: number + ): Promise> { const body = { item_id: itemId }; const tokenObject = await this.request.getToken(); - return this.request.post(API.externalAccount(integration), qs.stringify(body), { - headers: { - Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }); + return this.request.post( + API.externalAccount(integration), + qs.stringify(body), + { + headers: { + Authorization: `Bearer ${tokenObject.token}`, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ); } /** @@ -688,15 +722,22 @@ class Account extends BaseExtend { * .then(data => console.log(data)); * @returns {AxiosResponse} */ - async updateExternalAccount(integration: string, body: Record): Promise> { + async updateExternalAccount( + integration: string, + body: Record + ): Promise> { const tokenObject = await this.request.getToken(); - return this.request.patch(API.externalAccount(integration), qs.stringify(body), { - headers: { - Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }); + return this.request.patch( + API.externalAccount(integration), + qs.stringify(body), + { + headers: { + Authorization: `Bearer ${tokenObject.token}`, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ); } /** @@ -730,7 +771,7 @@ class Account extends BaseExtend { const tokenObject = await this.request.getToken(); return this.request.get(API.getAccountInfo, { - headers: { Authorization: `Bearer ${tokenObject.token}` }, + headers: { Authorization: `Bearer ${tokenObject.token}` } }); } @@ -757,7 +798,9 @@ class Account extends BaseExtend { * } * ``` */ - async getSocialLoginUrls(state: string): Promise> { + async getSocialLoginUrls( + state: string + ): Promise> { return this.request.get(API.getSocialLoginUrls(state)); } @@ -781,14 +824,14 @@ class Account extends BaseExtend { async updateAccount({ fullName, metadata, - dateOfBirth, + dateOfBirth }: { fullName: string; metadata?: { [key: string]: string }; dateOfBirth?: string; }): Promise> { const body: UpdateAccountRequestBody = { - full_name: fullName, + full_name: fullName }; if (metadata) { @@ -803,8 +846,8 @@ class Account extends BaseExtend { return this.request.put(API.updateAccount, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -834,7 +877,7 @@ class Account extends BaseExtend { password, passwordConfirmation, oldPassword, - brandingId, + brandingId }: { password: string; passwordConfirmation: string; @@ -845,7 +888,7 @@ class Account extends BaseExtend { old_password: oldPassword, password, password_confirmation: passwordConfirmation, - branding_id: brandingId, + branding_id: brandingId }; const tokenObject = await this.request.getToken(); @@ -853,8 +896,8 @@ class Account extends BaseExtend { return this.request.post(API.changePassword, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -884,7 +927,9 @@ class Account extends BaseExtend { * } * ``` */ - async getRegisterFields(merchantUuid = ''): Promise> { + async getRegisterFields( + merchantUuid = '' + ): Promise> { return this.request.get(API.getRegisterFields(merchantUuid)); } @@ -911,14 +956,14 @@ class Account extends BaseExtend { */ async deleteAccount({ password, - brandingId, + brandingId }: { password: string; brandingId?: number; }): Promise> { const body = { password, - branding_id: brandingId, + branding_id: brandingId }; const tokenObject = await this.request.getToken(); @@ -926,14 +971,14 @@ class Account extends BaseExtend { const response = await this.request.delete(API.deleteAccount, { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': 'application/x-www-form-urlencoded' }, - data: qs.stringify(body), + data: qs.stringify(body) }); await Promise.all([ tokenStorage.removeItem(this.config.INPLAYER_TOKEN_KEY), - tokenStorage.removeItem(this.config.INPLAYER_IOT_KEY), + tokenStorage.removeItem(this.config.INPLAYER_IOT_KEY) ]); return response; @@ -962,14 +1007,14 @@ class Account extends BaseExtend { */ async exportData({ password, - brandingId, + brandingId }: { password?: string; brandingId?: number; }): Promise> { const body = { password, - branding_id: brandingId, + branding_id: brandingId }; const tokenObject = await this.request.getToken(); @@ -977,8 +1022,8 @@ class Account extends BaseExtend { return this.request.post(API.exportData, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -999,9 +1044,11 @@ class Account extends BaseExtend { * } * ``` */ - async sendPinCode(brandingId: number): Promise> { + async sendPinCode( + brandingId: number + ): Promise> { const body = { - branding_id: brandingId, + branding_id: brandingId }; const tokenObject = await this.request.getToken(); @@ -1009,8 +1056,8 @@ class Account extends BaseExtend { return this.request.post(API.sendPinCode, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1031,9 +1078,11 @@ class Account extends BaseExtend { * ``` */ - async validatePinCode(pinCode: string): Promise> { + async validatePinCode( + pinCode: string + ): Promise> { const body = { - pin_code: pinCode, + pin_code: pinCode }; const tokenObject = await this.request.getToken(); @@ -1041,8 +1090,8 @@ class Account extends BaseExtend { return this.request.post(API.validatePinCode, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1067,7 +1116,9 @@ class Account extends BaseExtend { * } * ``` */ - async loadMerchantRestrictionSettings(merchantUuid: string): Promise> { + async loadMerchantRestrictionSettings( + merchantUuid: string + ): Promise> { return this.request.get(API.merchantRestrictionSettings(merchantUuid)); } @@ -1090,13 +1141,15 @@ class Account extends BaseExtend { * } * ``` */ - async getFavorites(): Promise>> { + async getFavorites(): Promise< + AxiosResponse> + > { const tokenObject = await this.request.getToken(); return this.request.get(API.getFavorites, { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1122,8 +1175,8 @@ class Account extends BaseExtend { return this.request.get(API.getFavorite(mediaId), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1146,15 +1199,15 @@ class Account extends BaseExtend { */ async addToFavorites(mediaId: string): Promise> { const body = { - media_id: mediaId, + media_id: mediaId }; const tokenObject = await this.request.getToken(); return this.request.post(API.getFavorites, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1175,14 +1228,16 @@ class Account extends BaseExtend { * } * ``` */ - async deleteFromFavorites(mediaId: string): Promise> { + async deleteFromFavorites( + mediaId: string + ): Promise> { const tokenObject = await this.request.getToken(); return this.request.delete(API.getFavorite(mediaId), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1212,15 +1267,20 @@ class Account extends BaseExtend { */ async getWatchHistory({ filter = 'currently_watching', - cursor = '', - }: CollectionWithCursorArgs): Promise>> { + cursor = '' + }: CollectionWithCursorArgs): Promise< + AxiosResponse> + > { const tokenObject = await this.request.getToken(); - return this.request.get(`${API.getWatchHistory}?filter=${filter}&cursor=${cursor}`, { - headers: { - Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }); + return this.request.get( + `${API.getWatchHistory}?filter=${filter}&cursor=${cursor}`, + { + headers: { + Authorization: `Bearer ${tokenObject.token}`, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ); } /** @@ -1242,13 +1302,15 @@ class Account extends BaseExtend { * } * ``` */ - async getWatchHistoryForItem(mediaId: string): Promise> { + async getWatchHistoryForItem( + mediaId: string + ): Promise> { const tokenObject = await this.request.getToken(); return this.request.get(API.getWatchHistoryForItem(mediaId), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1272,17 +1334,20 @@ class Account extends BaseExtend { * } * ``` */ - async updateWatchHistory(mediaId: string, progress: number): Promise> { + async updateWatchHistory( + mediaId: string, + progress: number + ): Promise> { const body = { media_id: mediaId, - progress, + progress }; const tokenObject = await this.request.getToken(); return this.request.patch(API.getWatchHistory, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1303,13 +1368,15 @@ class Account extends BaseExtend { * } * ``` */ - async deleteWatchHistoryForItem(mediaId: string): Promise> { + async deleteWatchHistoryForItem( + mediaId: string + ): Promise> { const tokenObject = await this.request.getToken(); return this.request.delete(API.getWatchHistoryForItem(mediaId), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1318,42 +1385,49 @@ class Account extends BaseExtend { return this.request.get(API.profiles, { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } - async enterProfile(id: string, pin?: number): Promise> { + async enterProfile( + id: string, + pin?: number + ): Promise> { const body = { - pin, + pin }; const tokenObject = await this.request.getToken(); - return this.request.post(`${API.getProfilesItem(id)}/token`, qs.stringify(body), { - headers: { - Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }); + return this.request.post( + `${API.getProfilesItem(id)}/token`, + qs.stringify(body), + { + headers: { + Authorization: `Bearer ${tokenObject.token}`, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ); } async createProfile( name: string, adult: boolean, avatar_url?: string, - pin?: number, + pin?: number ): Promise> { const body = { name, adult, avatar_url, - pin, + pin }; const tokenObject = await this.request.getToken(); return this.request.post(API.profiles, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1362,27 +1436,27 @@ class Account extends BaseExtend { return this.request.get(API.getProfilesItem(id), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } async updateProfile( id: string, name: string, avatar_url: string, - adult: boolean, + adult: boolean ): Promise> { const body = { name, avatar_url, - adult, + adult }; const tokenObject = await this.request.getToken(); return this.request.put(API.getProfilesItem(id), qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1391,8 +1465,8 @@ class Account extends BaseExtend { return this.request.delete(API.getProfilesItem(id), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1417,8 +1491,8 @@ class Account extends BaseExtend { return this.request.get(API.featureFlags, { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } } diff --git a/src/endpoints/asset.ts b/src/endpoints/asset.ts index 9ed75cf5..57fb184f 100644 --- a/src/endpoints/asset.ts +++ b/src/endpoints/asset.ts @@ -18,7 +18,7 @@ import { ItemDetailsV1, RequestDataCaptureAccessData, SignedMediaResponse, - SiteEntitlementsResponse, + SiteEntitlementsResponse } from '../models/IAsset&Access'; import BaseExtend from '../extends/base'; import { API } from '../constants'; @@ -62,14 +62,14 @@ class Asset extends BaseExtend { * ``` */ async checkAccessForAsset( - id: number, + id: number ): Promise> { const tokenObject = await this.request.getToken(); return this.request.authenticatedGet(API.checkAccessForAsset(id), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -89,8 +89,8 @@ class Asset extends BaseExtend { return this.request.authenticatedGet(API.checkFreeTrial(id), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -134,7 +134,7 @@ class Asset extends BaseExtend { */ async getAsset( assetId: number, - merchantUuid?: string, + merchantUuid?: string ): Promise> { return this.request.get(API.getAsset(assetId, merchantUuid)); } @@ -258,10 +258,10 @@ class Asset extends BaseExtend { async getExternalAsset( assetType: string, externalId: string, - merchantUuid = '', + merchantUuid = '' ): Promise> { return this.request.get( - API.getExternalAsset(assetType, externalId, merchantUuid), + API.getExternalAsset(assetType, externalId, merchantUuid) ); } @@ -340,7 +340,7 @@ class Asset extends BaseExtend { * ``` */ async getAssetsInPackage( - id: number, + id: number ): Promise> { return this.request.get(API.getAssetsInPackage(id)); } @@ -453,7 +453,7 @@ class Asset extends BaseExtend { * ``` */ async getAssetAccessFees( - id: number, + id: number ): Promise> { return this.request.get(API.getAssetAccessFees(id)); } @@ -533,7 +533,7 @@ class Asset extends BaseExtend { page = 0, startDate?: string, endDate?: string, - type?: string, + type?: string ): Promise> { const tokenObject = await this.request.getToken(); @@ -541,9 +541,9 @@ class Asset extends BaseExtend { API.getAssetsHistory(size, page, startDate, endDate, type), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, - }, + Authorization: `Bearer ${tokenObject.token}` + } + } ); } @@ -574,7 +574,7 @@ class Asset extends BaseExtend { */ async requestCodeAccess({ item_id, - code, + code }: { item_id: number; code: string; @@ -587,9 +587,9 @@ class Asset extends BaseExtend { reduce( browserDetails, (acc: string, details: Record) => `${acc}${details.value}`, - '', + '' ), - 31, + 31 ); formData.set('item_id', String(item_id)); @@ -602,12 +602,12 @@ class Asset extends BaseExtend { item_id, code, browser_fingerprint: browserFingerprint, - code_id: response.data.code_id, + code_id: response.data.code_id }; await tokenStorage.setItem( this.config.INPLAYER_ACCESS_CODE_NAME(item_id), - JSON.stringify(accessCode), + JSON.stringify(accessCode) ); return response; @@ -634,15 +634,15 @@ class Asset extends BaseExtend { * ``` */ getAccessCode( - assetId: number, + assetId: number ): CodeAccessData | null | Promise { 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).then((resolvedString) => - resolvedString ? (JSON.parse(resolvedString) as CodeAccessData) : null, + resolvedString ? (JSON.parse(resolvedString) as CodeAccessData) : null ) as Promise; } @@ -672,7 +672,7 @@ class Asset extends BaseExtend { * ``` */ async getAccesCodeSessions( - codeId: number, + codeId: number ): Promise>> { return this.request.get(API.requestAccessCodeSessions(codeId)); } @@ -695,7 +695,7 @@ class Asset extends BaseExtend { * ``` */ async terminateSession( - assetId: number, + assetId: number ): Promise | null> { const accessCode: CodeAccessData | null = await this.getAccessCode(assetId); @@ -704,11 +704,11 @@ class Asset extends BaseExtend { } 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; @@ -735,7 +735,7 @@ class Asset extends BaseExtend { email, full_name, company, - merchant_uuid, + merchant_uuid }: { email: string; full_name: string; @@ -746,16 +746,16 @@ class Asset extends BaseExtend { email, full_name, company, - merchant_uuid, + merchant_uuid }; const headers = { - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': 'application/x-www-form-urlencoded' }; return this.request.post( API.requestDataCaptureNoAuthAccess, qs.stringify(accessData), - { headers }, + { headers } ); } @@ -778,14 +778,14 @@ class Asset extends BaseExtend { */ async getCloudfrontURL( assetId: number, - videoUrl: string, + videoUrl: string ): Promise> { const tokenObject = await this.request.getToken(); return this.request.get(API.getCloudfrontURL(assetId, videoUrl), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -817,14 +817,14 @@ class Asset extends BaseExtend { * ``` */ async getDonationOptions( - assetId: number, + assetId: number ): Promise> { const tokenObject = await this.request.getToken(); return this.request.get(API.getDonations(assetId), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -846,25 +846,25 @@ class Asset extends BaseExtend { */ async getSignedMediaToken( appConfigId: string, - mediaId: string, + mediaId: string ): Promise> { const tokenObject = await this.request.getToken(); return this.request.get(API.getSignedMediaToken(appConfigId, mediaId), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } async getSiteEntitlements( - siteId: string, + siteId: string ): Promise> { const tokenObject = await this.request.getToken(); const headers: Record = { Accept: 'application/json', - 'Content-Type': 'application/json', + 'Content-Type': 'application/json' }; if (tokenObject.token) { diff --git a/src/endpoints/branding.ts b/src/endpoints/branding.ts index 6f9ae9fe..9e01c7cd 100644 --- a/src/endpoints/branding.ts +++ b/src/endpoints/branding.ts @@ -53,7 +53,7 @@ class Branding extends BaseExtend { */ async getBranding( clientId: string, - brandingId: number | 'default' = 'default', + brandingId: number | 'default' = 'default' ): Promise> { return this.request.get(API.getBranding(clientId, brandingId)); } diff --git a/src/endpoints/nfts.ts b/src/endpoints/nfts.ts index 67eb3d6e..195bba3d 100644 --- a/src/endpoints/nfts.ts +++ b/src/endpoints/nfts.ts @@ -8,7 +8,7 @@ import { GetMerchantNFTResponse, GetExchangeRatesResponse, GetMyNFTsResponse, - MakeNFTReservationResponse, + MakeNFTReservationResponse } from '../models/INFTs'; /** @@ -28,7 +28,9 @@ class NFTs extends BaseExtend { * @param {string} merchantUuid The Merchant's unique universal identifier (Merchant UUID). * @returns Promise> */ - async getMerchantMarketplace(merchantUuid: string): Promise> { + async getMerchantMarketplace( + merchantUuid: string + ): Promise> { return this.request.get(API.getMerchantMarketplace(merchantUuid)); } @@ -47,9 +49,11 @@ class NFTs extends BaseExtend { merchantUuid: string, page = 1, size = 50, - filter = 'published', + filter = 'published' ): Promise> { - return this.request.get(API.getMerchantNFTList(merchantUuid, page, size, filter)); + return this.request.get( + API.getMerchantNFTList(merchantUuid, page, size, filter) + ); } /** @@ -60,7 +64,10 @@ class NFTs extends BaseExtend { * @param {number} nftId The unique NFT identifier * @returns Promise> */ - async getMerchantNFT(merchantUuid: string, nftId: number): Promise> { + async getMerchantNFT( + merchantUuid: string, + nftId: number + ): Promise> { return this.request.get(API.getMerchantNFT(merchantUuid, nftId)); } @@ -71,7 +78,10 @@ class NFTs extends BaseExtend { * @param {boolean} invert Whether the returned rates to be in their inverted exchange rates * @returns Promise> */ - async getExchangeRates(fiat: string, invert = false): Promise> { + async getExchangeRates( + fiat: string, + invert = false + ): Promise> { return this.request.get(API.getExchangeRates(fiat, invert)); } @@ -83,13 +93,16 @@ class NFTs extends BaseExtend { * @param {number} size The maximum mumber of items returned in the response. Defaults to 50 * @returns Promise> */ - async getUserBoughtNFTs(page = 1, size = 50): Promise> { + async getUserBoughtNFTs( + page = 1, + size = 50 + ): Promise> { const tokenObject = await this.request.getToken(); return this.request.authenticatedGet(API.getUserBoughtNFTs(page, size), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -101,14 +114,20 @@ class NFTs extends BaseExtend { * @param {number} nftId The unique NFT identifier * @returns Promise> */ - async makeReservation(merchantUuid: string, nftId: number): Promise> { + async makeReservation( + merchantUuid: string, + nftId: number + ): Promise> { const tokenObject = await this.request.getToken(); - return this.request.authenticatedPost(API.makeReservation(merchantUuid, nftId), { - headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, - }); + return this.request.authenticatedPost( + API.makeReservation(merchantUuid, nftId), + { + headers: { + Authorization: `Bearer ${tokenObject.token}` + } + } + ); } } diff --git a/src/endpoints/payment.ts b/src/endpoints/payment.ts index 687aceb0..06262c56 100644 --- a/src/endpoints/payment.ts +++ b/src/endpoints/payment.ts @@ -18,11 +18,11 @@ import { DirectDebitMandateResponse, CreateDirectDebitResponse, PlansListResponse, - PlanPricesResponse, + PlanPricesResponse } from '../models/IPayment'; import { CommonResponse, - CustomErrorResponse, + CustomErrorResponse } from '../models/CommonInterfaces'; import { ApiConfig, Request } from '../models/Config'; import { buildURLwithQueryParams } from '../helpers'; @@ -60,13 +60,13 @@ class Payment extends BaseExtend { */ async getPaymentMethods(): Promise< AxiosResponse> - > { + > { const tokenObject = await this.request.getToken(); return this.request.authenticatedGet(API.getPaymentMethods, { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -133,7 +133,7 @@ class Payment extends BaseExtend { brandingId, returnUrl, receiverEmail, - isGift, + isGift }: { number: number; cardName: string; @@ -159,7 +159,7 @@ class Payment extends BaseExtend { payment_method: paymentMethod, referrer, branding_id: brandingId, - return_url: buildURLwithQueryParams(returnUrl, { ippwat: 'ppv' }), + return_url: buildURLwithQueryParams(returnUrl, { ippwat: 'ppv' }) }; if (voucherCode) { @@ -176,8 +176,8 @@ class Payment extends BaseExtend { return this.request.authenticatedPost(API.payForAsset, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -228,7 +228,7 @@ class Payment extends BaseExtend { * ``` */ async createDonationPayment( - data: CreateDonationPaymentData, + data: CreateDonationPaymentData ): Promise> { const body: CreateDonationPaymentRequestBody = { number: data.number, @@ -243,7 +243,7 @@ class Payment extends BaseExtend { amount: data.amount, item_id: data.assetId, donation_id: data.donationId, - return_url: buildURLwithQueryParams(data.returnUrl, { ippwat: 'ppv' }), + return_url: buildURLwithQueryParams(data.returnUrl, { ippwat: 'ppv' }) }; const tokenObject = await this.request.getToken(); @@ -254,9 +254,9 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } @@ -282,22 +282,22 @@ class Payment extends BaseExtend { * ``` */ async confirmPayment( - paymentIntentId: string, + paymentIntentId: string ): Promise> { if (!paymentIntentId) { const response: CustomErrorResponse = { status: 400, data: { code: 400, - message: 'Payment Intend Id is a required parameter!', - }, + message: 'Payment Intend Id is a required parameter!' + } }; throw { response }; } const body = { - pi_id: paymentIntentId, + pi_id: paymentIntentId }; const tokenObject = await this.request.getToken(); @@ -305,8 +305,8 @@ class Payment extends BaseExtend { return this.request.authenticatedPost(API.payForAsset, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -341,7 +341,7 @@ class Payment extends BaseExtend { paymentIntentId, brandingId, paymentMethod, - donationId, + donationId }: { paymentIntentId: string; brandingId: number; @@ -353,8 +353,8 @@ class Payment extends BaseExtend { status: 400, data: { code: 400, - message: 'Payment Intend Id is a required parameter!', - }, + message: 'Payment Intend Id is a required parameter!' + } }; throw { response }; @@ -364,7 +364,7 @@ class Payment extends BaseExtend { pi_id: paymentIntentId, branding_id: brandingId, payment_method: paymentMethod, - donation_id: donationId, + donation_id: donationId }; const tokenObject = await this.request.getToken(); @@ -375,9 +375,9 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } @@ -421,7 +421,7 @@ class Payment extends BaseExtend { accessFeeId, paymentMethod, voucherCode, - brandingId, + brandingId }: { origin: string; accessFeeId: number; @@ -444,8 +444,8 @@ class Payment extends BaseExtend { return this.request.authenticatedPost(API.getPayPalParams, formData, { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -498,7 +498,7 @@ class Payment extends BaseExtend { async getPurchaseHistory( status = 'active', page = 0, - limit = 5, + limit = 5 ): Promise> { const tokenObject = await this.request.getToken(); @@ -506,9 +506,9 @@ class Payment extends BaseExtend { API.getPurchaseHistory(status, page, limit), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, - }, + Authorization: `Bearer ${tokenObject.token}` + } + } ); } @@ -550,8 +550,8 @@ class Payment extends BaseExtend { return this.request.authenticatedGet(API.getPaymentHistory(), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -567,7 +567,7 @@ class Payment extends BaseExtend { * Contains the data: PDF document (blob) */ async getBillingReceipt({ - trxToken, + trxToken }: { trxToken: string; }): Promise> { @@ -576,8 +576,8 @@ class Payment extends BaseExtend { return this.request.authenticatedGet(API.getBillingReceipt(trxToken), { responseType: 'blob', headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -599,8 +599,8 @@ class Payment extends BaseExtend { return this.request.authenticatedGet(API.getDefaultCreditCard, { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -646,7 +646,7 @@ class Payment extends BaseExtend { cvc, expMonth, expYear, - currency, + currency }: { cardNumber: string; cardName: string; @@ -661,7 +661,7 @@ class Payment extends BaseExtend { cvv: cvc, exp_month: expMonth, exp_year: expYear, - currency_iso: currency, + currency_iso: currency }; const tokenObject = await this.request.getToken(); @@ -672,9 +672,9 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } @@ -705,13 +705,13 @@ class Payment extends BaseExtend { */ async getDirectDebitMandate(): Promise< AxiosResponse - > { + > { const tokenObject = await this.request.getToken(); return this.request.authenticatedGet(API.getDirectDebitMandate, { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -757,7 +757,7 @@ class Payment extends BaseExtend { async createDirectDebitMandate({ name, iban, - address, + address }: { name: string; iban: string; @@ -766,7 +766,7 @@ class Payment extends BaseExtend { const body = { name, iban, - ...(address && { address }), + ...(address && { address }) }; const tokenObject = await this.request.getToken(); @@ -777,9 +777,9 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } @@ -814,7 +814,7 @@ class Payment extends BaseExtend { assetId, voucherCode, brandingId, - referrer, + referrer }: { accessFeeId: number; assetId: number; @@ -828,7 +828,7 @@ class Payment extends BaseExtend { voucher_code: voucherCode, payment_method: 'Direct Debit', branding_id: brandingId, - referrer, + referrer }; const tokenObject = await this.request.getToken(); @@ -839,9 +839,9 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } @@ -879,7 +879,7 @@ class Payment extends BaseExtend { assetId, voucherCode, brandingId, - referrer, + referrer }: { accessFeeId: number; assetId: number; @@ -893,7 +893,7 @@ class Payment extends BaseExtend { voucher_code: voucherCode, payment_method: 'Direct Debit', branding_id: brandingId, - referrer, + referrer }; const tokenObject = await this.request.getToken(); @@ -901,8 +901,8 @@ class Payment extends BaseExtend { return this.request.authenticatedPost(API.subscribeV2, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -946,7 +946,7 @@ class Payment extends BaseExtend { returnUrl, referrer, brandingId, - voucherCode, + voucherCode }: { accessFeeId: number; bank: string; @@ -960,7 +960,7 @@ class Payment extends BaseExtend { access_fee_id: accessFeeId, bank, return_url: buildURLwithQueryParams(returnUrl, { ippwat: 'ppv' }), - referrer, + referrer }; if (brandingId) { @@ -979,9 +979,9 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } @@ -1028,7 +1028,7 @@ class Payment extends BaseExtend { returnUrl, referrer, brandingId, - voucherCode, + voucherCode }: { accessFeeId: number; bank: string; @@ -1042,9 +1042,9 @@ class Payment extends BaseExtend { access_fee_id: accessFeeId, bank, return_url: buildURLwithQueryParams(returnUrl, { - ippwat: 'subscription', + ippwat: 'subscription' }), - referrer, + referrer }; if (brandingId) { @@ -1060,8 +1060,8 @@ class Payment extends BaseExtend { return this.request.authenticatedPost(API.subscribeV2, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -1098,7 +1098,7 @@ class Payment extends BaseExtend { accessFeeId, referrer, brandingId, - voucherCode, + voucherCode }: { accessFeeId: number; referrer: string; @@ -1110,7 +1110,7 @@ class Payment extends BaseExtend { access_fee_id: accessFeeId, voucher_code: voucherCode, branding_id: brandingId, - referrer, + referrer }; const tokenObject = await this.request.getToken(); @@ -1121,9 +1121,9 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } @@ -1160,7 +1160,7 @@ class Payment extends BaseExtend { accessFeeId, referrer, brandingId, - voucherCode, + voucherCode }: { accessFeeId: number; referrer: string; @@ -1172,7 +1172,7 @@ class Payment extends BaseExtend { access_fee_id: accessFeeId, voucher_code: voucherCode, branding_id: brandingId, - referrer, + referrer }; const tokenObject = await this.request.getToken(); @@ -1183,9 +1183,9 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } @@ -1224,7 +1224,7 @@ class Payment extends BaseExtend { productName: product_name, itemId: item_id, accessFeeId: access_fee_id, - amazonUserId: amazon_user_id, + amazonUserId: amazon_user_id }: { platform: ReceiptValidationPlatform; receipt: string; @@ -1238,7 +1238,7 @@ class Payment extends BaseExtend { ...(product_name ? { product_name } : { item_id, access_fee_id }), ...(platform === ReceiptValidationPlatform.AMAZON ? { amazon_user_id } - : {}), + : {}) }; const tokenObject = await this.request.getToken(); @@ -1249,33 +1249,33 @@ class Payment extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } async getSitePlans( siteId: string, - plansIds?: string[], + plansIds?: string[] ): Promise> { return this.request.get(API.getSitePlans(siteId, plansIds), { headers: { Accept: 'application/json', - 'Content-Type': 'application/json', - }, + 'Content-Type': 'application/json' + } }); } async getSitePlanPrices( siteId: string, - planId: string, + planId: string ): Promise> { return this.request.get(API.getSitePlanPrices(siteId, planId), { headers: { Accept: 'application/json', - 'Content-Type': 'application/json', - }, + 'Content-Type': 'application/json' + } }); } } diff --git a/src/endpoints/subscription.ts b/src/endpoints/subscription.ts index 4f339a0d..e2c83a58 100644 --- a/src/endpoints/subscription.ts +++ b/src/endpoints/subscription.ts @@ -9,7 +9,7 @@ import { GetDefaultCard, SetDefaultCard, ChangeSubscriptionPlanRequestBody, - ChangeSubscriptionPlanResponse, + ChangeSubscriptionPlanResponse } from '../models/ISubscription'; import { CommonResponse } from '../models/CommonInterfaces'; import { ApiConfig, Request } from '../models/Config'; @@ -66,16 +66,20 @@ class Subscription extends BaseExtend { * } * ``` */ - async getSubscriptions(page = 0, limit = 15, status = ''): Promise> { + async getSubscriptions( + page = 0, + limit = 15, + status = '' + ): Promise> { const tokenObject = await this.request.getToken(); return this.request.authenticatedGet( API.getSubscriptions(limit, page, status), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, - }, + Authorization: `Bearer ${tokenObject.token}` + } + } ); } @@ -108,13 +112,15 @@ class Subscription extends BaseExtend { * } * ``` */ - async getSubscription(id: string): Promise> { + async getSubscription( + id: string + ): Promise> { const tokenObject = await this.request.getToken(); return this.request.authenticatedGet(API.getSubscription(id), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -139,16 +145,18 @@ class Subscription extends BaseExtend { * } * ``` */ - async cancelSubscription(unsubscribeUrl: string): Promise> { + async cancelSubscription( + unsubscribeUrl: string + ): Promise> { const tokenObject = await this.request.getToken(); return this.request.authenticatedGet( API.cancelSubscription(unsubscribeUrl), { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, - }, + Authorization: `Bearer ${tokenObject.token}` + } + } ); } @@ -209,7 +217,7 @@ class Subscription extends BaseExtend { referrer, voucherCode, brandingId, - returnUrl, + returnUrl }: { number: number; cardName: string; @@ -233,7 +241,7 @@ class Subscription extends BaseExtend { payment_method: paymentMethod, referrer, branding_id: brandingId, - return_url: returnUrl, + return_url: returnUrl }; if (voucherCode) { @@ -245,8 +253,8 @@ class Subscription extends BaseExtend { return this.request.authenticatedPost(API.subscribe, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -270,24 +278,28 @@ class Subscription extends BaseExtend { */ async changeSubscriptionPlan({ access_fee_id, - inplayer_token, + inplayer_token }: { - access_fee_id: number, - inplayer_token: string, - }): Promise> { + access_fee_id: number; + inplayer_token: string; + }): Promise> { const body: ChangeSubscriptionPlanRequestBody = { access_fee_id, - inplayer_token, + inplayer_token }; const tokenObject = await this.request.getToken(); - return this.request.authenticatedPost(API.subscriptionPlanChange, qs.stringify(body), { - headers: { - Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }); + return this.request.authenticatedPost( + API.subscriptionPlanChange, + qs.stringify(body), + { + headers: { + Authorization: `Bearer ${tokenObject.token}`, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ); } /** @@ -321,8 +333,8 @@ class Subscription extends BaseExtend { assetId, voucherCode, brandingId, - referrer, - }:{ + referrer + }: { accessFeeId: number; assetId: number; voucherCode: string; @@ -335,7 +347,7 @@ class Subscription extends BaseExtend { voucher_code: voucherCode, payment_method: 'Direct Debit', branding_id: brandingId, - referrer, + referrer }; const tokenObject = await this.request.getToken(); @@ -343,8 +355,8 @@ class Subscription extends BaseExtend { return this.request.authenticatedPost(API.subscribeV2, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -388,7 +400,7 @@ class Subscription extends BaseExtend { returnUrl, referrer, brandingId, - voucherCode, + voucherCode }: { accessFeeId: number; bank: string; @@ -401,8 +413,10 @@ class Subscription extends BaseExtend { payment_method: 'ideal', access_fee_id: accessFeeId, bank, - return_url: buildURLwithQueryParams(returnUrl, { ippwat: 'subscription' }), - referrer, + return_url: buildURLwithQueryParams(returnUrl, { + ippwat: 'subscription' + }), + referrer }; if (brandingId) { @@ -418,8 +432,8 @@ class Subscription extends BaseExtend { return this.request.authenticatedPost(API.subscribeV2, qs.stringify(body), { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } }); } @@ -448,8 +462,8 @@ class Subscription extends BaseExtend { return this.request.authenticatedGet(API.getDefaultCreditCard, { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, + Authorization: `Bearer ${tokenObject.token}` + } }); } @@ -492,14 +506,14 @@ class Subscription extends BaseExtend { cvc, expMonth, expYear, - currency, + currency }: { - cardNumber: string, - cardName: string, - cvc: number, - expMonth: number, - expYear: number, - currency: string, + cardNumber: string; + cardName: string; + cvc: number; + expMonth: number; + expYear: number; + currency: string; }): Promise> { const body = { number: cardNumber, @@ -507,7 +521,7 @@ class Subscription extends BaseExtend { cvv: cvc, exp_month: expMonth, exp_year: expYear, - currency_iso: currency, + currency_iso: currency }; const tokenObject = await this.request.getToken(); @@ -518,9 +532,9 @@ class Subscription extends BaseExtend { { headers: { Authorization: `Bearer ${tokenObject.token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }, + 'Content-Type': 'application/x-www-form-urlencoded' + } + } ); } } diff --git a/src/factories/notifications.ts b/src/factories/notifications.ts index fcec6a23..a827be90 100644 --- a/src/factories/notifications.ts +++ b/src/factories/notifications.ts @@ -20,21 +20,21 @@ class Notifications extends BaseExtend { this.config.AWS_IOT_URL, { headers: { - Authorization: `Bearer ${tokenObject.token}`, - }, - }, + Authorization: `Bearer ${tokenObject.token}` + } + } ); return { ...iotResponse.data, - iotEndpoint: this.config.IOT_NOTIF_URL, + iotEndpoint: this.config.IOT_NOTIF_URL }; } /* Subscribes to Websocket notifications */ async subscribe( accountUuid = '', - callbackParams: Record void>, + callbackParams: Record void> ): Promise { if (!accountUuid && accountUuid === '') { return false; @@ -59,7 +59,7 @@ class Notifications extends BaseExtend { } const inplayerIotCreds: any = await tokenStorage.getItem( - this.config.INPLAYER_IOT_KEY, + this.config.INPLAYER_IOT_KEY ); if (!inplayerIotCreds) { @@ -82,8 +82,8 @@ class Notifications extends BaseExtend { this.config.INPLAYER_IOT_KEY, JSON.stringify({ ...resp, - expiresAt: new Date().getTime() + HALF_HOUR, - }), + expiresAt: new Date().getTime() + HALF_HOUR + }) ); this.handleSubscribe(resp, callbackParams, accountUuid); @@ -94,7 +94,7 @@ class Notifications extends BaseExtend { handleSubscribe( data: Record, callbackParams: Record, - uuid: string, + uuid: string ): void { const credentials: any = { region: data.region, @@ -103,7 +103,7 @@ class Notifications extends BaseExtend { secretKey: data.secretKey, sessionToken: data.sessionToken, port: 443, - host: data.iotEndpoint, + host: data.iotEndpoint }; /* eslint-disable new-cap */ diff --git a/src/factories/request.ts b/src/factories/request.ts index 78ad6720..3ea3deb5 100644 --- a/src/factories/request.ts +++ b/src/factories/request.ts @@ -1,7 +1,10 @@ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; import Credentials from './credentials'; import { - CustomErrorResponse, Env, CredentialsConfig, Credentials as CredentialInterface, + CustomErrorResponse, + Env, + CredentialsConfig, + Credentials as CredentialInterface } from '../models/CommonInterfaces'; import { ApiConfig } from '../models/Config'; import configOptions from '../config'; @@ -12,8 +15,8 @@ import { isPromise, createCredentials } from '../helpers'; const getHeaders = () => ({ headers: { Accept: 'application/json', - 'Content-Type': 'application/json', - }, + 'Content-Type': 'application/json' + } }); export default class Request { @@ -24,27 +27,30 @@ export default class Request { constructor(config: ApiConfig) { this.config = config; this.basicInstance = axios.create({ - baseURL: this.config.BASE_URL, + baseURL: this.config.BASE_URL }); this.authenticatedInstance = axios.create({ - baseURL: this.config.BASE_URL, + baseURL: this.config.BASE_URL }); this.authenticatedInstance.interceptors.request.use( - this.createAuthInterceptor, + this.createAuthInterceptor ); } - setInstanceConfig = (configEnv: Env, customConfig?: AxiosRequestConfig | undefined): void => { + setInstanceConfig = ( + configEnv: Env, + customConfig?: AxiosRequestConfig | undefined + ): void => { this.config = configOptions[configEnv]; this.basicInstance = axios.create({ baseURL: this.config.BASE_URL, - ...customConfig, + ...customConfig }); this.authenticatedInstance = axios.create({ baseURL: this.config.BASE_URL, - ...customConfig, + ...customConfig }); this.authenticatedInstance.interceptors.request.use( - this.createAuthInterceptor, + this.createAuthInterceptor ); }; @@ -58,8 +64,7 @@ export default class Request { const tokenString = tokenStorage.getItem(this.config.INPLAYER_TOKEN_KEY); if (isPromise(tokenString)) { - return (tokenString as Promise).then((resolvedString) => - createCredentials(resolvedString)); + return (tokenString as Promise).then((resolvedString) => createCredentials(resolvedString)); } return createCredentials(tokenString as string); }; @@ -73,16 +78,20 @@ export default class Request { * InPlayer.Account.setToken('344244-242242', '123123121-d1-t1-1ff',1558529593297) * @returns {void} */ - setToken = (token: string, refreshToken: string, expiresAt: number): void | Promise => { + setToken = ( + token: string, + refreshToken: string, + expiresAt: number + ): void | Promise => { const credentials = new Credentials({ token, refreshToken, - expires: expiresAt, + expires: expiresAt }); return tokenStorage.setItem( this.config.INPLAYER_TOKEN_KEY, - JSON.stringify(credentials), + JSON.stringify(credentials) ); }; @@ -95,7 +104,7 @@ export default class Request { removeToken = (): void | Promise => { const tasks: Array> = [ tokenStorage.removeItem(this.config.INPLAYER_TOKEN_KEY), - tokenStorage.removeItem(this.config.INPLAYER_IOT_KEY), + tokenStorage.removeItem(this.config.INPLAYER_IOT_KEY) ]; if (!tasks.some(isPromise)) { @@ -118,7 +127,7 @@ export default class Request { if (isPromise(tokenObject)) { return (tokenObject as Promise).then( (resolvedCredentials) => - !resolvedCredentials.isExpired() && !!resolvedCredentials.token, + !resolvedCredentials.isExpired() && !!resolvedCredentials.token ); } @@ -130,70 +139,74 @@ export default class Request { // HTTP GET Request - Returns Resolved or Rejected Promise get = ( path: string, - headers?: Record | string | boolean>, + headers?: Record | string | boolean> ): any => this.basicInstance.get(path, headers || getHeaders()); // HTTP POST Request - Returns Resolved or Rejected Promise post = ( path: string, data: any, - headers?: Record | string | boolean>, + headers?: Record | string | boolean> ): any => this.basicInstance.post(path, data, headers || getHeaders()); // HTTP PUT Request - Returns Resolved or Rejected Promise put = ( path: string, data: any, - headers?: Record | string | boolean>, + headers?: Record | string | boolean> ): any => this.basicInstance.put(path, data, headers || getHeaders()); // HTTP PATCH Request - Returns Resolved or Rejected Promise patch = ( path: string, data: any, - headers?: Record | string | boolean>, + headers?: Record | string | boolean> ): any => this.basicInstance.patch(path, data, headers || getHeaders()); // HTTP DELETE Request - Returns Resolved or Rejected Promise delete = ( path: string, - headers?: Record | string | boolean>, + headers?: Record | string | boolean> ): any => this.basicInstance.delete(path, headers || getHeaders()); // HTTP GET Request - Returns Resolved or Rejected Promise authenticatedGet = ( path: string, - headers?: Record | string | boolean>, + headers?: Record | string | boolean> ): any => this.authenticatedInstance.get(path, headers || getHeaders()); // HTTP PATCH Request - Returns Resolved or Rejected Promise authenticatedPatch = ( path: string, data: any, - headers?: Record | string | boolean>, - ): any => this.authenticatedInstance.patch(path, data, headers || getHeaders()); + headers?: Record | string | boolean> + ): any => + this.authenticatedInstance.patch(path, data, headers || getHeaders()); // HTTP POST Request - Returns Resolved or Rejected Promise authenticatedPost = ( path: string, data: any, - headers?: Record | string | boolean>, - ): any => this.authenticatedInstance.post(path, data, headers || getHeaders()); + headers?: Record | string | boolean> + ): any => + this.authenticatedInstance.post(path, data, headers || getHeaders()); // HTTP PUT Request - Returns Resolved or Rejected Promise authenticatedPut = ( path: string, data: any, - headers?: Record | string | boolean>, + headers?: Record | string | boolean> ): any => this.authenticatedInstance.put(path, data, headers || getHeaders()); // HTTP DELETE Request - Returns Resolved or Rejected Promise authenticatedDelete = ( path: string, - headers?: Record | string | boolean>, + headers?: Record | string | boolean> ): any => this.authenticatedInstance.delete(path, headers || getHeaders()); - createAuthInterceptor = (axiosConfig: AxiosRequestConfig): AxiosRequestConfig => { + createAuthInterceptor = ( + axiosConfig: AxiosRequestConfig + ): AxiosRequestConfig => { const auth = this.isAuthenticated(); // Build and Record similar to an Axios error response if (!auth) { @@ -201,8 +214,8 @@ export default class Request { status: 401, data: { code: 401, - message: 'The user is not authenticated.', - }, + message: 'The user is not authenticated.' + } }; throw { response }; } diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 4b49503d..136d5c7f 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1,10 +1,13 @@ import Credentials from '../factories/credentials'; import { CredentialsConfig } from '../models/CommonInterfaces'; -export const buildURLwithQueryParams = (urlString: string, params: Record): string => { +export const buildURLwithQueryParams = ( + urlString: string, + params: Record +): string => { const { url, - url: { searchParams }, + url: { searchParams } } = { url: new URL(urlString) }; Object.keys(params).forEach((key: string) => { @@ -15,7 +18,12 @@ export const buildURLwithQueryParams = (urlString: string, params: Record, + object: + | void + | string + | CredentialsConfig + | null + | Promise ): boolean => { if (Promise && Promise.resolve) { return Promise.resolve(object) === object; diff --git a/src/index.ts b/src/index.ts index 3b6bbf52..cd343d31 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ import config from './config'; // types import { Notifications as NotificationsType, - Env, + Env } from './models/CommonInterfaces'; import { ApiConfig, Request as RequestType } from './models/Config'; import { Account as AccountType } from './models/IAccount&Authentication'; @@ -95,7 +95,7 @@ export class InPlayer { */ subscribe( accountUuid: string, - callbackParams: Record void>, + callbackParams: Record void> ): void { if (this.request.isAuthenticated()) { this.Notifications.subscribe(accountUuid, callbackParams)