Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

skynet-js

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skynet-js - npm Package Compare versions

Comparing version 2.0.9 to 2.1.0

dist/client.d.ts

5

CHANGELOG.md
# Changelog
## [2.1.0]
- Add SkyDB support
- Move to Typescript
## [2.0.9]

@@ -4,0 +9,0 @@

168

dist/client.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
exports.SkynetClient = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _axios = _interopRequireDefault(require("axios"));
var _utils = require("./utils.js");
var SkynetClient = /*#__PURE__*/function () {
/**
* The Skynet Client which can be used to access Skynet.
* @constructor
* @param {string} [portalUrl="https://siasky.net"] - The portal URL to use to access Skynet, if specified. To use the default portal while passing custom options, use "".
* @param {Object} [customOptions={}] - Configuration for the client.
* @param {string} [customOptions.method] - HTTP method to use.
* @param {string} [customOptions.APIKey] - Authentication password to use.
* @param {string} [customOptions.customUserAgent=""] - Custom user agent header to set.
* @param {Object} [customOptions.data=null] - Data to send in a POST.
* @param {string} [customOptions.endpointPath=""] - The relative URL path of the portal endpoint to contact.
* @param {string} [customOptions.extraPath=""] - Extra path element to append to the URL.
* @param {Function} [customOptions.onUploadProgress] - Optional callback to track progress.
* @param {Object} [customOptions.query={}] - Query parameters to include in the URl.
*/
function SkynetClient() {
var portalUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _utils.defaultPortalUrl)();
var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
(0, _classCallCheck2["default"])(this, SkynetClient);
this.portalUrl = portalUrl;
this.customOptions = customOptions;
}
/**
* Creates and executes a request.
* @param {Object} config - Configuration for the request. See docs for constructor for the full list of options.
*/
(0, _createClass2["default"])(SkynetClient, [{
key: "executeRequest",
value: function executeRequest(config) {
var url = config.url;
if (!url) {
var _config$extraPath;
url = (0, _utils.makeUrl)(this.portalUrl, config.endpointPath, (_config$extraPath = config.extraPath) !== null && _config$extraPath !== void 0 ? _config$extraPath : "");
url = (0, _utils.addUrlQuery)(url, config.query);
} // No other headers.
var headers = config.customUserAgent && {
"User-Agent": config.customUserAgent
};
return (0, _axios["default"])({
url: url,
method: config.method,
data: config.data,
headers: headers,
auth: config.APIKey && {
username: "",
password: config.APIKey
},
onUploadProgress: config.onUploadProgress && function (_ref) {
var loaded = _ref.loaded,
total = _ref.total;
var progress = loaded / total;
config.onUploadProgress(progress, {
loaded: loaded,
total: total
});
var axios_1 = __importDefault(require("axios"));
var upload_1 = require("./upload");
var encryption_1 = require("./encryption");
var download_1 = require("./download");
var utils_1 = require("./utils");
var skydb_1 = require("./skydb");
var registry_1 = require("./registry");
var SkynetClient = /** @class */ (function () {
/**
* The Skynet Client which can be used to access Skynet.
* @constructor
* @param {string} [portalUrl="https://siasky.net"] - The portal URL to use to access Skynet, if specified. To use the default portal while passing custom options, use "".
* @param {Object} [customOptions={}] - Configuration for the client.
* @param {string} [customOptions.method] - HTTP method to use.
* @param {string} [customOptions.APIKey] - Authentication password to use.
* @param {string} [customOptions.customUserAgent=""] - Custom user agent header to set.
* @param {Object} [customOptions.data=null] - Data to send in a POST.
* @param {string} [customOptions.endpointPath=""] - The relative URL path of the portal endpoint to contact.
* @param {string} [customOptions.extraPath=""] - Extra path element to append to the URL.
* @param {Function} [customOptions.onUploadProgress] - Optional callback to track progress.
* @param {Object} [customOptions.query={}] - Query parameters to include in the URl.
*/
function SkynetClient(portalUrl, customOptions) {
if (portalUrl === void 0) { portalUrl = utils_1.defaultPortalUrl(); }
if (customOptions === void 0) { customOptions = {}; }
this.uploadFile = upload_1.uploadFile;
this.uploadDirectory = upload_1.uploadDirectory;
this.uploadDirectoryRequest = upload_1.uploadDirectoryRequest;
this.uploadFileRequest = upload_1.uploadFileRequest;
this.addSkykey = encryption_1.addSkykey;
this.createSkykey = encryption_1.createSkykey;
this.getSkykeyById = encryption_1.getSkykeyById;
this.getSkykeyByName = encryption_1.getSkykeyByName;
this.getSkykeys = encryption_1.getSkykeys;
this.downloadFile = download_1.downloadFile;
this.downloadFileHns = download_1.downloadFileHns;
this.getSkylinkUrl = download_1.getSkylinkUrl;
this.getHnsUrl = download_1.getHnsUrl;
this.getHnsresUrl = download_1.getHnsresUrl;
this.getMetadata = download_1.getMetadata;
this.openFile = download_1.openFile;
this.openFileHns = download_1.openFileHns;
this.resolveHns = download_1.resolveHns;
// SkyDB
this.getFile = skydb_1.getFile;
this.setFile = skydb_1.setFile;
// SkyDB helpers
this.lookupRegistry = registry_1.lookupRegistry;
this.updateRegistry = registry_1.updateRegistry;
this.portalUrl = portalUrl;
this.customOptions = customOptions;
}
/**
* Creates and executes a request.
* @param {Object} config - Configuration for the request. See docs for constructor for the full list of options.
*/
SkynetClient.prototype.executeRequest = function (config) {
var _a;
var url = config.url;
if (!url) {
url = utils_1.makeUrl(this.portalUrl, config.endpointPath, (_a = config.extraPath) !== null && _a !== void 0 ? _a : "");
url = utils_1.addUrlQuery(url, config.query);
}
});
}
}]);
return SkynetClient;
}();
exports.SkynetClient = SkynetClient;
// No other headers.
var headers = config.customUserAgent && { "User-Agent": config.customUserAgent };
return axios_1["default"]({
url: url,
method: config.method,
data: config.data,
headers: headers,
auth: config.APIKey && { username: "", password: config.APIKey },
onUploadProgress: config.onUploadProgress &&
function (_a) {
var loaded = _a.loaded, total = _a.total;
var progress = loaded / total;
config.onUploadProgress(progress, { loaded: loaded, total: total });
}
});
};
return SkynetClient;
}());
exports.SkynetClient = SkynetClient;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _axios = _interopRequireDefault(require("axios"));
var _client = require("./client.js");
var _utils = require("./utils.js");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var defaultDownloadOptions = _objectSpread({}, (0, _utils.defaultOptions)("/"));
var defaultDownloadHnsOptions = _objectSpread({}, (0, _utils.defaultOptions)("/hns"));
var defaultResolveHnsOptions = _objectSpread({}, (0, _utils.defaultOptions)("/hnsres"));
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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 __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
exports.resolveHns = exports.openFileHns = exports.openFile = exports.getMetadata = exports.getHnsresUrl = exports.getHnsUrl = exports.getSkylinkUrl = exports.downloadFileHns = exports.downloadFile = void 0;
var utils_1 = require("./utils");
var defaultDownloadOptions = __assign({}, utils_1.defaultOptions("/"));
var defaultDownloadHnsOptions = __assign({}, utils_1.defaultOptions("/hns"));
var defaultResolveHnsOptions = __assign({}, utils_1.defaultOptions("/hnsres"));
/**

@@ -32,15 +61,10 @@ * Initiates a download of the content of the skylink within the browser.

*/
_client.SkynetClient.prototype.downloadFile = function (skylink) {
var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var opts = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, defaultDownloadOptions), this.customOptions), customOptions), {}, {
download: true
});
var url = this.getSkylinkUrl(skylink, opts); // Download the url.
window.location = url;
};
function downloadFile(skylink, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
var opts = __assign(__assign(__assign(__assign({}, defaultDownloadOptions), this.customOptions), customOptions), { download: true });
var url = this.getSkylinkUrl(skylink, opts);
// Download the url.
window.location = url;
}
exports.downloadFile = downloadFile;
/**

@@ -52,95 +76,49 @@ * Initiates a download of the content of the skylink at the Handshake domain.

*/
_client.SkynetClient.prototype.downloadFileHns = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(domain) {
var customOptions,
opts,
url,
_args = arguments;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
customOptions = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
opts = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, defaultDownloadHnsOptions), this.customOptions), customOptions), {}, {
download: true
});
url = this.getHnsUrl(domain, opts); // Download the url.
function downloadFileHns(domain, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var opts, url;
return __generator(this, function (_a) {
opts = __assign(__assign(__assign(__assign({}, defaultDownloadHnsOptions), this.customOptions), customOptions), { download: true });
url = this.getHnsUrl(domain, opts);
// Download the url.
window.location = url;
case 4:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
_client.SkynetClient.prototype.getSkylinkUrl = function (skylink) {
var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var opts = _objectSpread(_objectSpread(_objectSpread({}, defaultDownloadOptions), this.customOptions), customOptions);
var query = opts.download ? {
attachment: true
} : {};
var url = (0, _utils.makeUrl)(this.portalUrl, opts.endpointPath, (0, _utils.parseSkylink)(skylink));
return (0, _utils.addUrlQuery)(url, query);
};
_client.SkynetClient.prototype.getHnsUrl = function (domain) {
var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var opts = _objectSpread(_objectSpread(_objectSpread({}, defaultDownloadHnsOptions), this.customOptions), customOptions);
var query = opts.download ? {
attachment: true
} : {};
var url = (0, _utils.makeUrl)(this.portalUrl, opts.endpointPath, (0, _utils.trimUriPrefix)(domain, _utils.uriHandshakePrefix));
return (0, _utils.addUrlQuery)(url, query);
};
_client.SkynetClient.prototype.getHnsresUrl = function (domain) {
var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var opts = _objectSpread(_objectSpread(_objectSpread({}, defaultResolveHnsOptions), this.customOptions), customOptions);
var query = opts.download ? {
attachment: true
} : {};
return (0, _utils.makeUrl)(this.portalUrl, opts.endpointPath, (0, _utils.trimUriPrefix)(domain, _utils.uriHandshakeResolverPrefix));
};
_client.SkynetClient.prototype.getMetadata = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(skylink) {
var customOptions,
opts,
_args2 = arguments;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
customOptions = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
opts = _objectSpread(_objectSpread(_objectSpread({}, defaultDownloadOptions), this.customOptions), customOptions);
return [2 /*return*/];
});
});
}
exports.downloadFileHns = downloadFileHns;
function getSkylinkUrl(skylink, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
var opts = __assign(__assign(__assign({}, defaultDownloadOptions), this.customOptions), customOptions);
var query = opts.download ? { attachment: true } : {};
var url = utils_1.makeUrl(this.portalUrl, opts.endpointPath, utils_1.parseSkylink(skylink));
return utils_1.addUrlQuery(url, query);
}
exports.getSkylinkUrl = getSkylinkUrl;
function getHnsUrl(domain, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
var opts = __assign(__assign(__assign({}, defaultDownloadHnsOptions), this.customOptions), customOptions);
var query = opts.download ? { attachment: true } : {};
var url = utils_1.makeUrl(this.portalUrl, opts.endpointPath, utils_1.trimUriPrefix(domain, utils_1.uriHandshakePrefix));
return utils_1.addUrlQuery(url, query);
}
exports.getHnsUrl = getHnsUrl;
function getHnsresUrl(domain, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
var opts = __assign(__assign(__assign({}, defaultResolveHnsOptions), this.customOptions), customOptions);
return utils_1.makeUrl(this.portalUrl, opts.endpointPath, utils_1.trimUriPrefix(domain, utils_1.uriHandshakeResolverPrefix));
}
exports.getHnsresUrl = getHnsresUrl;
function getMetadata(skylink, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var opts;
return __generator(this, function (_a) {
opts = __assign(__assign(__assign({}, defaultDownloadOptions), this.customOptions), customOptions);
throw new Error("Unimplemented");
case 3:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
return function (_x2) {
return _ref2.apply(this, arguments);
};
}();
});
});
}
exports.getMetadata = getMetadata;
/**

@@ -152,12 +130,9 @@ * Opens the content of the skylink within the browser.

*/
_client.SkynetClient.prototype.openFile = function (skylink) {
var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var opts = _objectSpread(_objectSpread(_objectSpread({}, defaultDownloadOptions), this.customOptions), customOptions);
var url = this.getSkylinkUrl(skylink, opts);
window.open(url, "_blank");
};
function openFile(skylink, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
var opts = __assign(__assign(__assign({}, defaultDownloadOptions), this.customOptions), customOptions);
var url = this.getSkylinkUrl(skylink, opts);
window.open(url, "_blank");
}
exports.openFile = openFile;
/**

@@ -169,32 +144,16 @@ * Opens the content of the skylink from the given Handshake domain within the browser.

*/
_client.SkynetClient.prototype.openFileHns = /*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(domain) {
var customOptions,
opts,
url,
_args3 = arguments;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
customOptions = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
opts = _objectSpread(_objectSpread(_objectSpread({}, defaultDownloadHnsOptions), this.customOptions), customOptions);
url = this.getHnsUrl(domain, opts); // Open the url in a new tab.
function openFileHns(domain, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var opts, url;
return __generator(this, function (_a) {
opts = __assign(__assign(__assign({}, defaultDownloadHnsOptions), this.customOptions), customOptions);
url = this.getHnsUrl(domain, opts);
// Open the url in a new tab.
window.open(url, "_blank");
case 4:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
return function (_x3) {
return _ref3.apply(this, arguments);
};
}();
return [2 /*return*/];
});
});
}
exports.openFileHns = openFileHns;
/**

@@ -205,40 +164,19 @@ * @param {string} domain - Handshake resolver domain.

*/
_client.SkynetClient.prototype.resolveHns = /*#__PURE__*/function () {
var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(domain) {
var customOptions,
opts,
url,
response,
_args4 = arguments;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
customOptions = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
opts = _objectSpread(_objectSpread(_objectSpread({}, defaultResolveHnsOptions), this.customOptions), customOptions);
url = this.getHnsresUrl(domain, opts); // Get the txt record from the hnsres domain on the portal.
_context4.next = 5;
return this.executeRequest(_objectSpread(_objectSpread({}, opts), {}, {
method: "get",
url: url
}));
case 5:
response = _context4.sent;
return _context4.abrupt("return", response.data);
case 7:
case "end":
return _context4.stop();
}
}
}, _callee4, this);
}));
return function (_x4) {
return _ref4.apply(this, arguments);
};
}();
function resolveHns(domain, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var opts, url, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
opts = __assign(__assign(__assign({}, defaultResolveHnsOptions), this.customOptions), customOptions);
url = this.getHnsresUrl(domain, opts);
return [4 /*yield*/, this.executeRequest(__assign(__assign({}, opts), { method: "get", url: url }))];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
exports.resolveHns = resolveHns;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _client = require("./client.js");
var _utils = require("./utils.js");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var defaultAddSkykeyOptions = _objectSpread({}, (0, _utils.defaultOptions)("/skynet/addskykey"));
var defaultCreateSkykeyOptions = _objectSpread({}, (0, _utils.defaultOptions)("/skynet/createskykey"));
var defaultGetSkykeyOptions = _objectSpread({}, (0, _utils.defaultOptions)("/skynet/skykey"));
var defaultGetSkykeysOptions = _objectSpread({}, (0, _utils.defaultOptions)("/skynet/skykeys"));
_client.SkynetClient.prototype.addSkykey = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(skykey) {
var customOptions,
_args = arguments;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
customOptions = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
throw new Error("Unimplemented");
case 2:
case "end":
return _context.stop();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
_client.SkynetClient.prototype.createSkykey = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(skykeyName, skykeyType) {
var customOptions,
_args2 = arguments;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
customOptions = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
return t;
};
return __assign.apply(this, arguments);
};
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 __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
exports.getSkykeys = exports.getSkykeyByName = exports.getSkykeyById = exports.createSkykey = exports.addSkykey = void 0;
var utils_1 = require("./utils");
var defaultAddSkykeyOptions = __assign({}, utils_1.defaultOptions("/skynet/addskykey"));
var defaultCreateSkykeyOptions = __assign({}, utils_1.defaultOptions("/skynet/createskykey"));
var defaultGetSkykeyOptions = __assign({}, utils_1.defaultOptions("/skynet/skykey"));
var defaultGetSkykeysOptions = __assign({}, utils_1.defaultOptions("/skynet/skykeys"));
function addSkykey(skykey, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error("Unimplemented");
case 2:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return function (_x2, _x3) {
return _ref2.apply(this, arguments);
};
}();
_client.SkynetClient.prototype.getSkykeyById = /*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(skykeyId) {
var customOptions,
_args3 = arguments;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
customOptions = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
});
});
}
exports.addSkykey = addSkykey;
function createSkykey(skykeyName, skykeyType, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error("Unimplemented");
case 2:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
return function (_x4) {
return _ref3.apply(this, arguments);
};
}();
_client.SkynetClient.prototype.getSkykeyByName = /*#__PURE__*/function () {
var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(skykeyName) {
var customOptions,
_args4 = arguments;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
customOptions = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
});
});
}
exports.createSkykey = createSkykey;
function getSkykeyById(skykeyId, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error("Unimplemented");
case 2:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
return function (_x5) {
return _ref4.apply(this, arguments);
};
}();
_client.SkynetClient.prototype.getSkykeys = /*#__PURE__*/function () {
var _getSkykeys = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
var customOptions,
_args5 = arguments;
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
customOptions = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
});
});
}
exports.getSkykeyById = getSkykeyById;
function getSkykeyByName(skykeyName, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error("Unimplemented");
case 2:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
function getSkykeys() {
return _getSkykeys.apply(this, arguments);
}
return getSkykeys;
}();
});
});
}
exports.getSkykeyByName = getSkykeyByName;
function getSkykeys(customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error("Unimplemented");
});
});
}
exports.getSkykeys = getSkykeys;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "SkynetClient", {
enumerable: true,
get: function get() {
return _client.SkynetClient;
}
});
Object.defineProperty(exports, "defaultPortalUrl", {
enumerable: true,
get: function get() {
return _utils.defaultPortalUrl;
}
});
Object.defineProperty(exports, "defaultSkynetPortalUrl", {
enumerable: true,
get: function get() {
return _utils.defaultSkynetPortalUrl;
}
});
Object.defineProperty(exports, "getRelativeFilePath", {
enumerable: true,
get: function get() {
return _utils.getRelativeFilePath;
}
});
Object.defineProperty(exports, "getRootDirectory", {
enumerable: true,
get: function get() {
return _utils.getRootDirectory;
}
});
Object.defineProperty(exports, "parseSkylink", {
enumerable: true,
get: function get() {
return _utils.parseSkylink;
}
});
Object.defineProperty(exports, "uriHandshakePrefix", {
enumerable: true,
get: function get() {
return _utils.uriHandshakePrefix;
}
});
Object.defineProperty(exports, "uriHandshakeResolverPrefix", {
enumerable: true,
get: function get() {
return _utils.uriHandshakeResolverPrefix;
}
});
Object.defineProperty(exports, "uriSkynetPrefix", {
enumerable: true,
get: function get() {
return _utils.uriSkynetPrefix;
}
});
var _client = require("./client.js");
require("./download.js");
require("./encryption.js");
require("./upload.js");
var _utils = require("./utils.js");
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
exports.__esModule = true;
exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.parseSkylink = exports.getRootDirectory = exports.getRelativeFilePath = exports.defaultSkynetPortalUrl = exports.defaultPortalUrl = exports.SkyFile = exports.User = exports.FileID = exports.FileType = exports.FILEID_V1 = exports.SkynetClient = void 0;
var client_1 = require("./client");
__createBinding(exports, client_1, "SkynetClient");
var skydb_1 = require("./skydb");
__createBinding(exports, skydb_1, "FILEID_V1");
__createBinding(exports, skydb_1, "FileType");
__createBinding(exports, skydb_1, "FileID");
__createBinding(exports, skydb_1, "User");
__createBinding(exports, skydb_1, "SkyFile");
var utils_1 = require("./utils");
__createBinding(exports, utils_1, "defaultPortalUrl");
__createBinding(exports, utils_1, "defaultSkynetPortalUrl");
__createBinding(exports, utils_1, "getRelativeFilePath");
__createBinding(exports, utils_1, "getRootDirectory");
__createBinding(exports, utils_1, "parseSkylink");
__createBinding(exports, utils_1, "uriHandshakePrefix");
__createBinding(exports, utils_1, "uriHandshakeResolverPrefix");
__createBinding(exports, utils_1, "uriSkynetPrefix");
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _client = require("./client.js");
var _utils = require("./utils.js");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var defaultUploadOptions = _objectSpread(_objectSpread({}, (0, _utils.defaultOptions)("/skynet/skyfile")), {}, {
portalFileFieldname: "file",
portalDirectoryFileFieldname: "files[]",
customFilename: ""
});
_client.SkynetClient.prototype.uploadFile = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(file) {
var customOptions,
response,
_args = arguments;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
customOptions = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
_context.next = 3;
return this.uploadFileRequest(file, customOptions);
case 3:
response = _context.sent;
return _context.abrupt("return", "".concat(_utils.uriSkynetPrefix).concat(response.skylink));
case 5:
case "end":
return _context.stop();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
}
}, _callee, this);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
_client.SkynetClient.prototype.uploadFileRequest = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(file) {
var customOptions,
opts,
formData,
_yield$this$executeRe,
data,
_args2 = arguments;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
customOptions = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
opts = _objectSpread(_objectSpread(_objectSpread({}, defaultUploadOptions), this.customOptions), customOptions);
formData = new FormData();
file = ensureFileObjectConsistency(file);
if (opts.customFilename) {
formData.append(opts.portalFileFieldname, file, opts.customFilename);
} else {
formData.append(opts.portalFileFieldname, file);
return t;
};
return __assign.apply(this, arguments);
};
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 __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
_context2.next = 7;
return this.executeRequest(_objectSpread(_objectSpread({}, opts), {}, {
method: "post",
data: formData
}));
case 7:
_yield$this$executeRe = _context2.sent;
data = _yield$this$executeRe.data;
return _context2.abrupt("return", data);
case 10:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
return function (_x2) {
return _ref2.apply(this, arguments);
};
}();
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
exports.uploadDirectoryRequest = exports.uploadDirectory = exports.uploadFileRequest = exports.uploadFile = void 0;
var utils_1 = require("./utils");
var defaultUploadOptions = __assign(__assign({}, utils_1.defaultOptions("/skynet/skyfile")), { portalFileFieldname: "file", portalDirectoryFileFieldname: "files[]", customFilename: "" });
function uploadFile(file, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.uploadFileRequest(file, customOptions)];
case 1:
response = _a.sent();
return [2 /*return*/, "" + utils_1.uriSkynetPrefix + response.skylink];
}
});
});
}
exports.uploadFile = uploadFile;
function uploadFileRequest(file, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var opts, formData, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
opts = __assign(__assign(__assign({}, defaultUploadOptions), this.customOptions), customOptions);
formData = new FormData();
file = ensureFileObjectConsistency(file);
if (opts.customFilename) {
formData.append(opts.portalFileFieldname, file, opts.customFilename);
}
else {
formData.append(opts.portalFileFieldname, file);
}
return [4 /*yield*/, this.executeRequest(__assign(__assign({}, opts), { method: "post", data: formData }))];
case 1:
data = (_a.sent()).data;
return [2 /*return*/, data];
}
});
});
}
exports.uploadFileRequest = uploadFileRequest;
/**

@@ -119,84 +108,40 @@ * Uploads a local directory to Skynet.

*/
_client.SkynetClient.prototype.uploadDirectory = /*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(directory, filename) {
var customOptions,
response,
_args3 = arguments;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
customOptions = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
_context3.next = 3;
return this.uploadDirectoryRequest(directory, filename, customOptions);
case 3:
response = _context3.sent;
return _context3.abrupt("return", "".concat(_utils.uriSkynetPrefix).concat(response.skylink));
case 5:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
return function (_x3, _x4) {
return _ref3.apply(this, arguments);
};
}();
_client.SkynetClient.prototype.uploadDirectoryRequest = /*#__PURE__*/function () {
var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(directory, filename) {
var customOptions,
opts,
formData,
_yield$this$executeRe2,
data,
_args4 = arguments;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
customOptions = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {};
opts = _objectSpread(_objectSpread(_objectSpread({}, defaultUploadOptions), this.customOptions), customOptions);
formData = new FormData();
Object.entries(directory).forEach(function (_ref5) {
var _ref6 = (0, _slicedToArray2["default"])(_ref5, 2),
path = _ref6[0],
file = _ref6[1];
file = ensureFileObjectConsistency(file);
formData.append(opts.portalDirectoryFileFieldname, file, path);
});
_context4.next = 6;
return this.executeRequest(_objectSpread(_objectSpread({}, opts), {}, {
method: "post",
data: formData,
query: {
filename: filename
}
}));
case 6:
_yield$this$executeRe2 = _context4.sent;
data = _yield$this$executeRe2.data;
return _context4.abrupt("return", data);
case 9:
case "end":
return _context4.stop();
}
}
}, _callee4, this);
}));
return function (_x5, _x6) {
return _ref4.apply(this, arguments);
};
}();
function uploadDirectory(directory, filename, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.uploadDirectoryRequest(directory, filename, customOptions)];
case 1:
response = _a.sent();
return [2 /*return*/, "" + utils_1.uriSkynetPrefix + response.skylink];
}
});
});
}
exports.uploadDirectory = uploadDirectory;
function uploadDirectoryRequest(directory, filename, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var opts, formData, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
opts = __assign(__assign(__assign({}, defaultUploadOptions), this.customOptions), customOptions);
formData = new FormData();
Object.entries(directory).forEach(function (_a) {
var path = _a[0], file = _a[1];
file = ensureFileObjectConsistency(file);
formData.append(opts.portalDirectoryFileFieldname, file, path);
});
return [4 /*yield*/, this.executeRequest(__assign(__assign({}, opts), { method: "post", data: formData, query: { filename: filename } }))];
case 1:
data = (_a.sent()).data;
return [2 /*return*/, data];
}
});
});
}
exports.uploadDirectoryRequest = uploadDirectoryRequest;
/**

@@ -210,8 +155,4 @@ * Sometimes file object might have had the type property defined manually with

*/
function ensureFileObjectConsistency(file) {
return new File([file], file.name, {
type: file.type
});
}
return new File([file], file.name, { type: file.type });
}
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addUrlQuery = addUrlQuery;
exports.defaultOptions = defaultOptions;
exports.defaultPortalUrl = defaultPortalUrl;
exports.getRelativeFilePath = getRelativeFilePath;
exports.getRootDirectory = getRootDirectory;
exports.makeUrl = makeUrl;
exports.parseSkylink = parseSkylink;
exports.trimUriPrefix = trimUriPrefix;
exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.defaultSkynetPortalUrl = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _pathBrowserify = _interopRequireDefault(require("path-browserify"));
var _urlParse = _interopRequireDefault(require("url-parse"));
var _urlJoin = _interopRequireDefault(require("url-join"));
// import axios from "axios";
var defaultSkynetPortalUrl = "https://siasky.net";
exports.defaultSkynetPortalUrl = defaultSkynetPortalUrl;
var uriHandshakePrefix = "hns:";
exports.uriHandshakePrefix = uriHandshakePrefix;
var uriHandshakeResolverPrefix = "hnsres:";
exports.uriHandshakeResolverPrefix = uriHandshakeResolverPrefix;
var uriSkynetPrefix = "sia:";
exports.uriSkynetPrefix = uriSkynetPrefix;
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 __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
exports.hexToUint8Array = exports.stringToUint8Array = exports.timeout = exports.randomNumber = exports.trimUriPrefix = exports.parseSkylink = exports.makeUrl = exports.getRootDirectory = exports.getRelativeFilePath = exports.defaultPortalUrl = exports.defaultOptions = exports.addUrlQuery = exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.defaultSkynetPortalUrl = void 0;
var path_browserify_1 = __importDefault(require("path-browserify"));
var url_parse_1 = __importDefault(require("url-parse"));
var url_join_1 = __importDefault(require("url-join"));
var buffer_1 = require("buffer");
exports.defaultSkynetPortalUrl = "https://siasky.net";
exports.uriHandshakePrefix = "hns:";
exports.uriHandshakeResolverPrefix = "hnsres:";
exports.uriSkynetPrefix = "sia:";
function addUrlQuery(url, query) {
var parsed = (0, _urlParse["default"])(url);
parsed.set("query", query);
return parsed.toString();
var parsed = url_parse_1["default"](url);
parsed.set("query", query);
return parsed.toString();
}
exports.addUrlQuery = addUrlQuery;
function defaultOptions(endpointPath) {
return {
endpointPath: endpointPath,
APIKey: "",
customUserAgent: ""
};
} // TODO: This will be smarter. See
return {
endpointPath: endpointPath,
APIKey: "",
customUserAgent: ""
};
}
exports.defaultOptions = defaultOptions;
// TODO: This will be smarter. See
// https://github.com/NebulousLabs/skynet-docs/issues/21.
function defaultPortalUrl() {
if (typeof window === "undefined") return "/"; // default to path root on ssr
return window.location.origin;
if (typeof window === "undefined")
return "/"; // default to path root on ssr
return window.location.origin;
}
exports.defaultPortalUrl = defaultPortalUrl;
function getFilePath(file) {
return file.webkitRelativePath || file.path || file.name;
return file.webkitRelativePath || file.path || file.name;
}
function getRelativeFilePath(file) {
var filePath = getFilePath(file);
var _path$parse = _pathBrowserify["default"].parse(filePath),
root = _path$parse.root,
dir = _path$parse.dir,
base = _path$parse.base;
var relative = _pathBrowserify["default"].normalize(dir).slice(root.length).split(_pathBrowserify["default"].sep).slice(1);
return _pathBrowserify["default"].join.apply(_pathBrowserify["default"], (0, _toConsumableArray2["default"])(relative).concat([base]));
var filePath = getFilePath(file);
var _a = path_browserify_1["default"].parse(filePath), root = _a.root, dir = _a.dir, base = _a.base;
var relative = path_browserify_1["default"].normalize(dir).slice(root.length).split(path_browserify_1["default"].sep).slice(1);
return path_browserify_1["default"].join.apply(path_browserify_1["default"], __spreadArrays(relative, [base]));
}
exports.getRelativeFilePath = getRelativeFilePath;
function getRootDirectory(file) {
var filePath = getFilePath(file);
var _path$parse2 = _pathBrowserify["default"].parse(filePath),
root = _path$parse2.root,
dir = _path$parse2.dir;
return _pathBrowserify["default"].normalize(dir).slice(root.length).split(_pathBrowserify["default"].sep)[0];
var filePath = getFilePath(file);
var _a = path_browserify_1["default"].parse(filePath), root = _a.root, dir = _a.dir;
return path_browserify_1["default"].normalize(dir).slice(root.length).split(path_browserify_1["default"].sep)[0];
}
exports.getRootDirectory = getRootDirectory;
/**
* Properly joins paths together to create a URL. Takes a variable number of
* arguments.
* @returns {string} url - The URL.
*/
function makeUrl() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return args.reduce(function (acc, cur) {
return (0, _urlJoin["default"])(acc, cur);
});
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return args.reduce(function (acc, cur) { return url_join_1["default"](acc, cur); });
}
exports.makeUrl = makeUrl;
var SKYLINK_MATCHER = "([a-zA-Z0-9_-]{46})";
var SKYLINK_DIRECT_REGEX = new RegExp("^".concat(SKYLINK_MATCHER, "$"));
var SKYLINK_PATHNAME_REGEX = new RegExp("^/?".concat(SKYLINK_MATCHER, "([/?].*)?$"));
var SKYLINK_DIRECT_REGEX = new RegExp("^" + SKYLINK_MATCHER + "$");
var SKYLINK_PATHNAME_REGEX = new RegExp("^/?" + SKYLINK_MATCHER + "([/?].*)?$");
var SKYLINK_REGEXP_MATCH_POSITION = 1;
function parseSkylink(skylink) {
if (typeof skylink !== "string") throw new Error("Skylink has to be a string, ".concat((0, _typeof2["default"])(skylink), " provided")); // check for direct skylink match
var matchDirect = skylink.match(SKYLINK_DIRECT_REGEX);
if (matchDirect) return matchDirect[SKYLINK_REGEXP_MATCH_POSITION]; // check for skylink prefixed with sia: or sia:// and extract it
// example: sia:XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg
// example: sia://XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg
skylink = trimUriPrefix(skylink, uriSkynetPrefix); // check for skylink passed in an url and extract it
// example: https://siasky.net/XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg
// pass empty object as second param to disable using location as base url when parsing in browser
var parsed = (0, _urlParse["default"])(skylink, {});
var matchPathname = parsed.pathname.match(SKYLINK_PATHNAME_REGEX);
if (matchPathname) return matchPathname[SKYLINK_REGEXP_MATCH_POSITION];
throw new Error("Could not extract skylink from '".concat(skylink, "'"));
if (typeof skylink !== "string")
throw new Error("Skylink has to be a string, " + typeof skylink + " provided");
// check for direct skylink match
var matchDirect = skylink.match(SKYLINK_DIRECT_REGEX);
if (matchDirect)
return matchDirect[SKYLINK_REGEXP_MATCH_POSITION];
// check for skylink prefixed with sia: or sia:// and extract it
// example: sia:XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg
// example: sia://XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg
skylink = trimUriPrefix(skylink, exports.uriSkynetPrefix);
// check for skylink passed in an url and extract it
// example: https://siasky.net/XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg
// pass empty object as second param to disable using location as base url when parsing in browser
var parsed = url_parse_1["default"](skylink, {});
var matchPathname = parsed.pathname.match(SKYLINK_PATHNAME_REGEX);
if (matchPathname)
return matchPathname[SKYLINK_REGEXP_MATCH_POSITION];
throw new Error("Could not extract skylink from '" + skylink + "'");
}
exports.parseSkylink = parseSkylink;
function trimUriPrefix(str, prefix) {
var longPrefix = "".concat(prefix, "//");
if (str.startsWith(longPrefix)) {
// longPrefix is exactly at the beginning
return str.slice(longPrefix.length);
}
if (str.startsWith(prefix)) {
// else prefix is exactly at the beginning
return str.slice(prefix.length);
}
return str;
}
var longPrefix = prefix + "//";
if (str.startsWith(longPrefix)) {
// longPrefix is exactly at the beginning
return str.slice(longPrefix.length);
}
if (str.startsWith(prefix)) {
// else prefix is exactly at the beginning
return str.slice(prefix.length);
}
return str;
}
exports.trimUriPrefix = trimUriPrefix;
function randomNumber(low, high) {
return Math.random() * (high - low) + low;
}
exports.randomNumber = randomNumber;
function timeout(ms) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(null);
}, ms);
})];
});
});
}
exports.timeout = timeout;
// stringToUint8Array converts a string to a uint8 array
function stringToUint8Array(str) {
return Uint8Array.from(buffer_1.Buffer.from(str));
}
exports.stringToUint8Array = stringToUint8Array;
// hexToUint8Array converts a hex encoded string to a uint8 array
function hexToUint8Array(str) {
return new Uint8Array(str.match(/.{1,2}/g).map(function (byte) { return parseInt(byte, 16); }));
}
exports.hexToUint8Array = hexToUint8Array;
{
"name": "skynet-js",
"version": "2.0.9",
"version": "2.1.0",
"description": "Sia Skynet Javascript Client",

@@ -11,5 +11,11 @@ "main": "dist/index.js",

"test": "jest",
"build": "rimraf dist && babel src --out-dir dist --ignore src/**/*.test.js",
"build": "rimraf dist && babel src --out-dir dist --extensions .ts --ignore src/**/*.test.ts && tsc --project tsconfig.build.json",
"lint:eslint": "eslint --ext .ts utils src",
"lint:tsc": "tsc",
"prepublishOnly": "yarn build"
},
"jest": {
"clearMocks": true,
"rootDir": "src"
},
"husky": {

@@ -21,4 +27,5 @@ "hooks": {

"lint-staged": {
"*.{js}": [
"eslint --fix",
"*.{js,jsx,ts,tsx}": [
"eslint --ext .ts --fix",
"tsc --esModuleInterop --noemit",
"prettier --write"

@@ -46,3 +53,7 @@ ],

"@babel/runtime": "^7.11.2",
"@types/node-forge": "^0.9.5",
"axios": "^0.20.0",
"blakejs": "^1.1.0",
"buffer": "^5.6.0",
"node-forge": "^0.10.0",
"path-browserify": "^1.0.1",

@@ -55,5 +66,14 @@ "url-join": "^4.0.1",

"@babel/core": "^7.11.6",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-transform-runtime": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"@babel/preset-typescript": "^7.10.4",
"@types/jest": "^26.0.14",
"@types/node": "^14.11.2",
"@types/url-join": "^4.0.0",
"@types/url-parse": "^1.4.3",
"@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^4.3.0",
"axios-mock-adapter": "^1.18.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"eslint": "^7.8.1",

@@ -64,4 +84,5 @@ "husky": "^4.3.0",

"prettier": "^2.1.1",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"typescript": "^4.0.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc