UNPKG

@neardefi/shade-agent-js

Version:

This library is intended to be used in conjunction with the [shade agent template](https://github.com/NearDeFi/shade-agent-template/).

72 lines (70 loc) 2.17 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/api.ts var api_exports = {}; __export(api_exports, { agent: () => agent, agentAccountId: () => agentAccountId, agentCall: () => agentCall, agentInfo: () => agentInfo, agentView: () => agentView, requestSignature: () => requestSignature }); module.exports = __toCommonJS(api_exports); var API_PORT = process.env.API_PORT || 3140; var API_PATH = /sandbox/gim.test(process.env.NEXT_PUBLIC_contractId) ? "shade-agent-api" : "localhost"; async function agent(methodName, args = {}) { const res = await fetch( `http://${API_PATH}:${API_PORT}/api/agent/${methodName}`, { method: "POST", body: JSON.stringify(args) } ).then((r) => r.json()); return res; } var agentAccountId = async () => agent("getAccountId"); var agentInfo = async () => agent("view", { methodName: "get_agent", args: { account_id: (await agentAccountId()).accountId } }); var agentView = async (args) => agent("view", args); var agentCall = async (args) => agent("call", args); var requestSignature = async ({ path, payload, keyType = "Ecdsa" }) => { return agent("call", { methodName: "request_signature", args: { path, payload, key_type: keyType } }); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { agent, agentAccountId, agentCall, agentInfo, agentView, requestSignature });