tickethead-sdk
Version:
SDK for the Tickethead API
169 lines • 7.22 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NftService = void 0;
const query_string_1 = __importDefault(require("query-string"));
const query_1 = require("../common/query");
/**
* Service class for NFT API calls.
*/
class NftService {
constructor(client, version) {
this.client = client;
this.version = version;
}
/**
* Returns true if the service is reachable
*
* @returns Services' online status
*/
health() {
return __awaiter(this, void 0, void 0, function* () {
try {
const res = yield this.client.get(`nft/health`);
if (res.data.status === 'ok') {
return { online: true };
}
}
catch (e) {
// Do nothing
}
return { online: false };
});
}
/**
* Returns all nfts for the logged in user
*/
getMyNfts() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.get(`nft/${this.version}/my_nfts`);
return res.data.data.nfts;
});
}
/**
* Returns all nfts with the given query
*/
listNfts(req) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
// Only fetch nft attributes if the with parameter is not defined
const relationsFetched = (_a = req.with) !== null && _a !== void 0 ? _a : { attribute: true };
const query = query_string_1.default.stringify(Object.assign(Object.assign({}, req), { with: (0, query_1.buildQuery)(relationsFetched) }), { arrayFormat: 'comma', skipNull: true, skipEmptyString: true });
const res = yield this.client.get(`nft/${this.version}/nft?${query}`);
return res.data;
});
}
/**
* Returns a specific NFT with the given relations
*/
getNft(req) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
// Only fetch nft attributes if the with parameter is not defined
const relationsFetched = (_a = req.with) !== null && _a !== void 0 ? _a : { attribute: true };
const query = query_string_1.default.stringify({ with: (0, query_1.buildQuery)(relationsFetched) }, { arrayFormat: 'comma', skipNull: true, skipEmptyString: true });
const res = yield this.client.get(`nft/${this.version}/nft/${req.id}?${query}`);
return res.data.data;
});
}
createNft(nft) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.post(`nft/${this.version}/nft`, nft);
return res.data.data;
});
}
updateNft(nft) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.patch(`nft/${this.version}/nft/${nft.id}`, nft);
return res.data.data;
});
}
deleteNft(id) {
return __awaiter(this, void 0, void 0, function* () {
yield this.client.delete(`nft/${this.version}/nft/${id.id}`);
});
}
mintNft(req) {
return __awaiter(this, void 0, void 0, function* () {
yield this.client.post(`nft/${this.version}/chaincode/${req.chaincodeId}/nft/${req.nftId}/mint`, { account: req.account });
});
}
/**
* Returns all collections with the given query
*/
listCollections(req) {
return __awaiter(this, void 0, void 0, function* () {
const query = query_string_1.default.stringify(Object.assign(Object.assign({}, req), { with: req.with ? (0, query_1.buildQuery)(req.with) : undefined }), { arrayFormat: 'comma', skipNull: true, skipEmptyString: true });
const res = yield this.client.get(`nft/${this.version}/collection?${query}`);
return res.data;
});
}
/**
* Returns a specific NFT collection with the given relations
*/
getCollection(req) {
return __awaiter(this, void 0, void 0, function* () {
const query = query_string_1.default.stringify({ with: req.with ? (0, query_1.buildQuery)(req.with) : undefined }, { arrayFormat: 'comma', skipNull: true, skipEmptyString: true });
const res = yield this.client.get(`nft/${this.version}/collection/${req.id}?${query}`);
return res.data.data;
});
}
createCollection(collection) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.post(`nft/${this.version}/collection`, collection);
return res.data.data;
});
}
updateCollection(collection) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.patch(`nft/${this.version}/collection/${collection.id}`, collection);
return res.data.data;
});
}
deleteCollection(id) {
return __awaiter(this, void 0, void 0, function* () {
yield this.client.delete(`nft/${this.version}/collection/${id.id}`);
});
}
createOrder(order) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.post(`nft/${this.version}/order`, order);
return res.data.data;
});
}
getOrder(req) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.get(`nft/${this.version}/order/${req.id}`);
return res.data.data;
});
}
getOrders(req) {
return __awaiter(this, void 0, void 0, function* () {
const query = query_string_1.default.stringify({ with: req.with ? (0, query_1.buildQuery)(req.with) : undefined }, { arrayFormat: 'comma', skipNull: true, skipEmptyString: true });
const res = yield this.client.get(`nft/${this.version}/order?${query}`);
return res.data;
});
}
createBatchNfts(req) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.post(`nft/${this.version}/collection/${req.collectionId}/nft/batch`, {
nft: req.nft,
quantity: req.quantity,
});
return res.data.data;
});
}
}
exports.NftService = NftService;
//# sourceMappingURL=service.js.map