UNPKG

pinata-sdk

Version:

Unofficial SDK for [Pinata](https://pinata.cloud), implemented in ReasonML and compiled to Javascript.

32 lines (27 loc) 1.39 kB
// Generated by BUCKLESCRIPT VERSION 4.0.18, PLEASE EDIT WITH CARE 'use strict'; var Fetch = require("bs-fetch/lib/js/src/Fetch.js"); var Caml_option = require("bs-platform/lib/js/caml_option.js"); var Json_decode = require("@glennsl/bs-json/lib/js/src/Json_decode.bs.js"); function decodeResponse(response) { return Promise.resolve(/* record */[/* ipfsHash */Json_decode.field("IpfsHash", Json_decode.string, response)]); } function pinHashToIPFS(config, hash) { var url = config.apiURL + "/pinning/pinHashToIPFS"; var payload = { }; payload["hashToPin"] = hash; return fetch(url, Fetch.RequestInit[/* make */0](/* Post */2, { "Content-Type": "application/json", pinata_api_key: config.apiKey, pinata_secret_api_key: config.privateApiKey }, Caml_option.some(JSON.stringify(payload)), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined)(/* () */0)).then((function (prim) { return prim.json(); })).then(decodeResponse).then((function (response) { return Promise.resolve({ ipfsHash: response[/* ipfsHash */0] }); })); } exports.decodeResponse = decodeResponse; exports.pinHashToIPFS = pinHashToIPFS; /* No side effect */