Skip to content

Commit cd2230d

Browse files
Merge pull request #760 from inplayer-org/add-nft-endpoints
Add NFT endpoints
2 parents 6ad5d93 + dc13b6f commit cd2230d

File tree

9 files changed

+346
-10
lines changed

9 files changed

+346
-10
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
webpack.config.js
33
node_modules
44
coverage
5+
clientside_test
56
*.lock
67
*.log

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555
"@typescript-eslint/no-empty-interface": "off",
5656
"class-methods-use-this": "off",
5757
"no-throw-literal": "off",
58-
"no-shadow": "warn",
58+
"no-shadow": "off",
59+
"@typescript-eslint/no-shadow": [
60+
"warn"
61+
],
5962
},
6063
"settings": {
6164
"import/resolver": {

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

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

5+
# [3.13.0] - 26-06-2022
6+
7+
### Added
8+
9+
- Introduced a new object `NFTs` with NFT-related endpoints
10+
511
# [3.12.8] - 05-05-2022
612

713
### Changes

index.d.ts

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { AxiosResponse } from 'axios';
22

3-
// eslint-disable-next-line no-shadow
43
export enum Env {
54
Development = 'development',
65
Production = 'production',
@@ -450,7 +449,6 @@ export interface RequestDataCaptureAccessData {
450449
}
451450

452451
export declare class Asset {
453-
// eslint-disable-next-line no-shadow
454452
constructor(config: Record<string, unknown>, Account: Account);
455453

456454
checkAccessForAsset(id: number): Promise<AxiosResponse<GetItemAccessV1>>;
@@ -703,7 +701,6 @@ export declare interface GoogleOrApplePaymentData {
703701
voucherCode?: string;
704702
}
705703

706-
// eslint-disable-next-line no-shadow
707704
export enum ReceiptValidationPlatform {
708705
AMAZON = 'amazon',
709706
APPLE = 'apple',
@@ -744,7 +741,6 @@ type ReceiptData =
744741
export type ValidateReceiptData = CommonPlatformData & ReceiptData;
745742

746743
export declare class Payment {
747-
// eslint-disable-next-line no-shadow
748744
constructor(config: Record<string, unknown>, Account: Account);
749745

750746
getPaymentMethods(): Promise<AxiosResponse<MerchantPaymentMethod[]>>;
@@ -860,7 +856,6 @@ export interface ChangeSubscriptionPlanResponse {
860856
message: string;
861857
}
862858
export declare class Subscription {
863-
// eslint-disable-next-line no-shadow
864859
constructor(config: Record<string, unknown>, Account: Account);
865860

866861
getSubscriptions(
@@ -891,12 +886,108 @@ export interface VoucherDiscountPrice {
891886
}
892887

893888
export declare class Voucher {
894-
// eslint-disable-next-line no-shadow
895889
constructor(config: Record<string, unknown>, Account: Account);
896890

897891
getDiscount(data: DiscountData): Promise<AxiosResponse<VoucherDiscountPrice>>;
898892
}
899893

894+
type FiatCurrency = string;
895+
896+
export enum CryptoCurrency {
897+
ETH = 'ETH',
898+
MATIC = 'MATIC',
899+
USDC = 'USDC',
900+
}
901+
902+
export interface GetMerchantMarketplaceResponse {
903+
id: number;
904+
merchant_uuid: string;
905+
name: string;
906+
logo_url: string;
907+
banner_url: string;
908+
created_at: number;
909+
updated_at: number;
910+
engagement_mode: boolean;
911+
url: string;
912+
currency: FiatCurrency;
913+
}
914+
915+
export interface CryptoPrice {
916+
amount: number;
917+
currency: CryptoCurrency;
918+
}
919+
920+
export enum Prices {
921+
CRYPTO = 'crypto',
922+
FIAT = 'fiat',
923+
}
924+
925+
export interface GetMerchantNFTResponse {
926+
id: number;
927+
title: string;
928+
description: string;
929+
thumbnail: string;
930+
token_uri: string;
931+
merchant_uuid: string;
932+
prices: Partial<{
933+
[Prices.CRYPTO]: CryptoPrice;
934+
[Prices.FIAT]: GetAccessFee
935+
}>;
936+
published: boolean;
937+
supply: number;
938+
created_at: number;
939+
updated_at: number;
940+
}
941+
942+
export interface GetMerchantNFTListResponse {
943+
collection: GetMerchantNFTResponse[] | null;
944+
page: number;
945+
size: number;
946+
total: number;
947+
}
948+
949+
interface ExchangeRate {
950+
asset_id_quote: CryptoCurrency;
951+
rate: number;
952+
}
953+
954+
export interface GetExchangeRatesResponse {
955+
asset_id_base: FiatCurrency;
956+
rates: ExchangeRate[];
957+
}
958+
959+
export type GetUserBoughtNFTsResponse = GetMerchantNFTListResponse;
960+
961+
export interface MakeReservationResponse {
962+
created_at: number;
963+
updated_at: number;
964+
description: string;
965+
id: number;
966+
merchant_uuid: string;
967+
prices: Record<string, unknown>;
968+
published: boolean;
969+
reservation_expires_at: number;
970+
reservation_id: number;
971+
reservation_owner_id: number;
972+
supply: number;
973+
thumbnail: string;
974+
title: string;
975+
token_id: number;
976+
token_uri: string;
977+
}
978+
979+
export declare class NFTs {
980+
constructor(config: Record<string, unknown>, Account: Account);
981+
982+
getMerchantMarketplace(merchantUuid: string): Promise<AxiosResponse<GetMerchantMarketplaceResponse>>;
983+
getMerchantNFTList(merchantUuid: string, page?: number, size?: number, filter?: string):
984+
Promise<AxiosResponse<GetMerchantNFTListResponse>>;
985+
getMerchantNFT(merchantUuid: string, nftId: number): Promise<AxiosResponse<GetMerchantNFTResponse>>;
986+
getExchangeRates(fiat: string, invert?: boolean): Promise<AxiosResponse<GetExchangeRatesResponse>>;
987+
getUserBoughtNFTs(page?: number, size?: number): Promise<AxiosResponse<GetUserBoughtNFTsResponse>>;
988+
makeReservation(merchantUuid: string, nftId: number): Promise<AxiosResponse<MakeReservationResponse>>;
989+
}
990+
900991
export interface ApiEndpoints {
901992
// Account
902993
signIn: string;
@@ -956,6 +1047,13 @@ export interface ApiEndpoints {
9561047
getDiscount: string;
9571048
// Branding
9581049
getBranding: (clientId: string, brandingId: string) => string;
1050+
// NFTs
1051+
getMerchantMarketplace: (merchantUuid: string) => string,
1052+
getMerchantNFTList: (merchantUuid: string, page: number, size: number, filter: string) => string;
1053+
getMerchantNFT: (merchantUuid: string, nftId: number) => string;
1054+
getExchangeRates: (fiat: string, invert: boolean) => string;
1055+
getUserBoughtNFTs: (page: number, size: number) => string;
1056+
makeReservation: (merchantUuid: string, nftId: number) => string;
9591057
}
9601058

9611059
export interface ApiConfig {
@@ -970,7 +1068,6 @@ export interface ApiConfig {
9701068
export declare const API: ApiEndpoints;
9711069

9721070
export declare class Notifications {
973-
// eslint-disable-next-line no-shadow
9741071
constructor(config: Record<string, unknown>, Account: Account);
9751072

9761073
getIotToken(): Promise<Record<string, unknown>>;
@@ -1003,6 +1100,7 @@ declare const InPlayer: {
10031100
Subscription: Subscription;
10041101
Voucher: Voucher;
10051102
Branding: Branding;
1103+
NFTs: NFTs;
10061104
Notifications: Notifications;
10071105
tokenStorage: TokenStorageType;
10081106

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inplayer-org/inplayer.js",
3-
"version": "3.12.8",
3+
"version": "3.13.0",
44
"author": "InPlayer",
55
"license": "MIT",
66
"description": "A Javascript SDK for Inplayer's RESTful API",
@@ -21,7 +21,7 @@
2121
"prebuild": "rimraf dist",
2222
"build:dev": "cross-env NODE_ENV=development webpack --config ./webpack.config.js",
2323
"build:prod": "cross-env NODE_ENV=production webpack --config ./webpack.config.js",
24-
"lint": "eslint 'src/**/*.{js,ts,tsx}' --quiet --fix",
24+
"lint": "eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix",
2525
"lint:js:fix": "eslint src/** --fix",
2626
"analyze-bundle": "babel-node ./tools/analyzeBundle.js",
2727
"prepublishOnly": "yarn build:prod",

src/constants/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,14 @@ export const API = {
107107
// Branding
108108
getBranding: (clientId: string, brandingId: string | number): string =>
109109
`/branding/paywall/${clientId}/${brandingId}`,
110+
111+
// NFTs
112+
getMerchantMarketplace: (merchantUuid: string): string => `/v2/nfts/marketplaces/${merchantUuid}`,
113+
getMerchantNFTList: (merchantUuid: string, page: number, size: number, filter: string): string =>
114+
`/v2/nfts/${merchantUuid}?filter=${filter}&page=${page}&size=${size}`,
115+
getMerchantNFT: (merchantUuid: string, nftId: number): string => `/v2/nfts/${merchantUuid}/${nftId}`,
116+
getExchangeRates: (fiat: string, invert: boolean): string =>
117+
`/v2/nfts/exchange-rate/${fiat}${invert ? '?invert=true' : ''}`,
118+
getUserBoughtNFTs: (page: number, size: number): string => `/v2/nfts?page=${page}&size=${size}`,
119+
makeReservation: (merchantUuid: string, nftId: number): string => `/v2/nfts/${merchantUuid}/${nftId}/reserve`,
110120
};

src/endpoints/nfts.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { AxiosResponse } from 'axios';
2+
import { ApiConfig, Request } from '../models/Config';
3+
import BaseExtend from '../extends/base';
4+
import { API } from '../constants';
5+
import {
6+
GetMerchantMarketplaceResponse,
7+
GetMerchantNFTListResponse,
8+
GetMerchantNFTResponse,
9+
GetExchangeRatesResponse,
10+
GetMyNFTsResponse,
11+
MakeNFTReservationResponse,
12+
} from '../models/INFTs';
13+
14+
/**
15+
* Contains all Requests connected with NFTs
16+
*
17+
* @class NFTs
18+
*/
19+
class NFTs extends BaseExtend {
20+
constructor(config: ApiConfig, request: Request) {
21+
super(config, request);
22+
}
23+
24+
/**
25+
* Returns a merchant's Marketplace data if there is one
26+
* @method getMerchantMarketplace
27+
* @async
28+
* @param {string} merchantUuid The Merchant's unique universal identifier (Merchant UUID).
29+
* @returns Promise<AxiosResponse<GetMerchantMarketplaceResponse>>
30+
*/
31+
async getMerchantMarketplace(merchantUuid: string): Promise<AxiosResponse<GetMerchantMarketplaceResponse>> {
32+
return this.request.get(API.getMerchantMarketplace(merchantUuid));
33+
}
34+
35+
/**
36+
* Returns a list of NFT items sold by a merchant
37+
* @method getMerchantNFTList
38+
* @async
39+
* @param {string} merchantUuid The Merchant's unique universal identifier (Merchant UUID).
40+
* @param {number} page The current page number.
41+
* If it is not set the starting page will be returned. Defaults to 1
42+
* @param {number} size The maximum mumber of items returned in the response. Defaults to 50
43+
* @param {string} filter Parameter by which the returned items in the list to be filtered. Defaults to "published"
44+
* @returns Promise<AxiosResponse<GetMerchantNFTListResponse>>
45+
*/
46+
async getMerchantNFTList(
47+
merchantUuid: string,
48+
page = 1,
49+
size = 50,
50+
filter = 'published',
51+
): Promise<AxiosResponse<GetMerchantNFTListResponse>> {
52+
return this.request.get(API.getMerchantNFTList(merchantUuid, page, size, filter));
53+
}
54+
55+
/**
56+
* Returns a specific NFT item sold by a merchant
57+
* @method getMerchantNFT
58+
* @async
59+
* @param {string} merchantUuid The Merchant's unique universal identifier (Merchant UUID).
60+
* @param {number} nftId The unique NFT identifier
61+
* @returns Promise<AxiosResponse<GetMerchantNFTResponse>>
62+
*/
63+
async getMerchantNFT(merchantUuid: string, nftId: number): Promise<AxiosResponse<GetMerchantNFTResponse>> {
64+
return this.request.get(API.getMerchantNFT(merchantUuid, nftId));
65+
}
66+
67+
/**
68+
* Returns exchange rates of a specific FIAT currency in respect to a list crypto currencies
69+
* @method getExchangeRates
70+
* @param {string} fiat The FIAT currency
71+
* @param {boolean} invert Whether the returned rates to be in their inverted exchange rates
72+
* @returns Promise<AxiosResponse<GetExchangeRatesResponse>>
73+
*/
74+
async getExchangeRates(fiat: string, invert = false): Promise<AxiosResponse<GetExchangeRatesResponse>> {
75+
return this.request.get(API.getExchangeRates(fiat, invert));
76+
}
77+
78+
/**
79+
* Returns a list of NFTs bought and owned by an authenticated user
80+
* @method getUserBoughtNFTs
81+
* @param {number} page The current page number.
82+
* If it is not set the starting page will be returned. Defaults to 1
83+
* @param {number} size The maximum mumber of items returned in the response. Defaults to 50
84+
* @returns Promise<AxiosResponse<GetMyNFTsResponse>>
85+
*/
86+
async getUserBoughtNFTs(page = 1, size = 50): Promise<AxiosResponse<GetMyNFTsResponse>> {
87+
const tokenObject = await this.request.getToken();
88+
89+
return this.request.authenticatedGet(API.getUserBoughtNFTs(page, size), {
90+
headers: {
91+
Authorization: `Bearer ${tokenObject.token}`,
92+
},
93+
});
94+
}
95+
96+
/**
97+
* Makes a reservation request for a specific NFT and returns the relevant data when
98+
* that reservation is completed successfully
99+
* @method makeReservation
100+
* @param {string} merchantUuid The Merchant's unique universal identifier (Merchant UUID).
101+
* @param {number} nftId The unique NFT identifier
102+
* @returns Promise<AxiosResponse<MakeNFTReservationResponse>>
103+
*/
104+
async makeReservation(merchantUuid: string, nftId: number): Promise<AxiosResponse<MakeNFTReservationResponse>> {
105+
const tokenObject = await this.request.getToken();
106+
107+
return this.request.authenticatedPost(API.makeReservation(merchantUuid, nftId), {
108+
headers: {
109+
Authorization: `Bearer ${tokenObject.token}`,
110+
},
111+
});
112+
}
113+
}
114+
115+
export default NFTs;

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Payment from './endpoints/payment';
77
import Subscription from './endpoints/subscription';
88
import Branding from './endpoints/branding';
99
import Voucher from './endpoints/voucher';
10+
import NFTs from './endpoints/nfts';
1011
import Notifications from './factories/notifications';
1112
import RequestFactory from './factories/request';
1213
import tokenStorage, { TokenStorageType } from './factories/tokenStorage';
@@ -23,6 +24,7 @@ import { Asset as AssetType } from './models/IAsset&Access';
2324
import { Payment as PaymentType } from './models/IPayment';
2425
import { Subscription as SubscriptionType } from './models/ISubscription';
2526
import { Voucher as VoucherType } from './models/IVoucher&Promotion';
27+
import { NFTs as NFTsType } from './models/INFTs';
2628
import { Branding as BrandingType } from './models/IBrand';
2729

2830
/**
@@ -44,6 +46,8 @@ export class InPlayer {
4446
/** @internal */
4547
Voucher: VoucherType;
4648
/** @internal */
49+
NFTs: NFTsType;
50+
/** @internal */
4751
Branding: BrandingType;
4852
/** @internal */
4953
Notifications: NotificationsType;
@@ -62,6 +66,7 @@ export class InPlayer {
6266
this.Voucher = new Voucher(this.config, this.request);
6367
this.Branding = new Branding(this.config, this.request);
6468
this.Notifications = new Notifications(this.config, this.request);
69+
this.NFTs = new NFTs(this.config, this.request);
6570
}
6671

6772
/**

0 commit comments

Comments
 (0)