UNPKG

chaingate

Version:

Multi-chain cryptocurrency SDK for TypeScript — unified API for Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Cash, Polygon, Arbitrum, and any EVM-compatible chain. Create wallets, query balances, send transactions, and manage tokens and NFTs across UTXO

94 lines (93 loc) 3.45 kB
"use strict"; // This file is auto-generated by @hey-api/openapi-ts Object.defineProperty(exports, "__esModule", { value: true }); exports.getUrl = exports.defaultPathSerializer = exports.PATH_PARAM_RE = void 0; exports.getValidRequestBody = getValidRequestBody; const pathSerializer_gen_1 = require("./pathSerializer.gen"); exports.PATH_PARAM_RE = /\{[^{}]+\}/g; const defaultPathSerializer = ({ path, url: _url }) => { let url = _url; const matches = _url.match(exports.PATH_PARAM_RE); if (matches) { for (const match of matches) { let explode = false; let name = match.substring(1, match.length - 1); let style = 'simple'; if (name.endsWith('*')) { explode = true; name = name.substring(0, name.length - 1); } if (name.startsWith('.')) { name = name.substring(1); style = 'label'; } else if (name.startsWith(';')) { name = name.substring(1); style = 'matrix'; } const value = path[name]; if (value === undefined || value === null) { continue; } if (Array.isArray(value)) { url = url.replace(match, (0, pathSerializer_gen_1.serializeArrayParam)({ explode, name, style, value })); continue; } if (typeof value === 'object') { url = url.replace(match, (0, pathSerializer_gen_1.serializeObjectParam)({ explode, name, style, value: value, valueOnly: true, })); continue; } if (style === 'matrix') { url = url.replace(match, `;${(0, pathSerializer_gen_1.serializePrimitiveParam)({ name, value: value, })}`); continue; } const replaceValue = encodeURIComponent(style === 'label' ? `.${value}` : value); url = url.replace(match, replaceValue); } } return url; }; exports.defaultPathSerializer = defaultPathSerializer; const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) => { const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; let url = (baseUrl ?? '') + pathUrl; if (path) { url = (0, exports.defaultPathSerializer)({ path, url }); } let search = query ? querySerializer(query) : ''; if (search.startsWith('?')) { search = search.substring(1); } if (search) { url += `?${search}`; } return url; }; exports.getUrl = getUrl; function getValidRequestBody(options) { const hasBody = options.body !== undefined; const isSerializedBody = hasBody && options.bodySerializer; if (isSerializedBody) { if ('serializedBody' in options) { const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== ''; return hasSerializedBody ? options.serializedBody : null; } // not all clients implement a serializedBody property (i.e. client-axios) return options.body !== '' ? options.body : null; } // plain/text body if (hasBody) { return options.body; } // no body was provided return undefined; }