@eidolon-labs/player-sdk
Version:
@eidolon-labs/player-sdk is a lightweight API wrapper for the Eidolon Player API; the invisible gaming layer for blockchain.
100 lines (99 loc) • 4.42 kB
JavaScript
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _PlayerApi_apiKey, _PlayerApi_url;
import { chainIds } from "./chains";
import { urls } from "./urls";
class PlayerApi {
constructor({ region, apiKey, }) {
_PlayerApi_apiKey.set(this, void 0);
_PlayerApi_url.set(this, void 0);
__classPrivateFieldSet(this, _PlayerApi_apiKey, apiKey, "f");
__classPrivateFieldSet(this, _PlayerApi_url, urls[region], "f");
}
changeRegion(region) {
__classPrivateFieldSet(this, _PlayerApi_url, urls[region], "f");
}
setApiKey(apiKey) {
__classPrivateFieldSet(this, _PlayerApi_apiKey, apiKey, "f");
}
async createPlayer({ chainName, suppliedId, }) {
const response = await fetch(`${__classPrivateFieldGet(this, _PlayerApi_url, "f")}/v1/players`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": __classPrivateFieldGet(this, _PlayerApi_apiKey, "f"),
},
body: JSON.stringify({
chainName,
suppliedId,
}),
});
return await response.json();
}
async sendTransaction({ chainName, data, playerId, value, to, }) {
const response = await fetch(`${__classPrivateFieldGet(this, _PlayerApi_url, "f")}/v1/transactions`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": __classPrivateFieldGet(this, _PlayerApi_apiKey, "f"),
},
body: JSON.stringify({
chainId: chainIds[chainName],
data,
playerId,
value,
to,
}),
});
return await response.json();
}
async estimateGas({ chainName, data, playerId, value, to, }) {
const response = await fetch(`${__classPrivateFieldGet(this, _PlayerApi_url, "f")}/v1/transactions/estimate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": __classPrivateFieldGet(this, _PlayerApi_apiKey, "f"),
},
body: JSON.stringify({
chainId: chainIds[chainName],
data,
playerId,
value,
to,
}),
});
return await response.json();
}
async getPlayer({ playerId }) {
const response = await fetch(`${__classPrivateFieldGet(this, _PlayerApi_url, "f")}/v1/players/${playerId}`, {
headers: {
"Content-Type": "application/json",
"x-api-key": __classPrivateFieldGet(this, _PlayerApi_apiKey, "f"),
},
});
return await response.json();
}
async getPlayerBySuppliedId({ suppliedId }) {
const response = await fetch(`${__classPrivateFieldGet(this, _PlayerApi_url, "f")}/v1/players/recover/${suppliedId}`, {
headers: {
"Content-Type": "application/json",
"x-api-key": __classPrivateFieldGet(this, _PlayerApi_apiKey, "f"),
},
});
return await response.json();
}
}
_PlayerApi_apiKey = new WeakMap(), _PlayerApi_url = new WeakMap();
export { PlayerApi };
export * from "./regions";
export * from "./types";
export * from "./urls";