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

@onflow/config

Package Overview
Dependencies
Maintainers
11
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/config - npm Package Compare versions

Comparing version 1.1.0-alpha.0 to 1.1.0-alpha.1

8

CHANGELOG.md
# @onflow/config
## 1.1.0-alpha.1
### Minor Changes
- [#1511](https://github.com/onflow/fcl-js/pull/1511) [`de7ffa47`](https://github.com/onflow/fcl-js/commit/de7ffa4768ea19e9378e7db74c85750b6554027c) Thanks [@justinbarry](https://github.com/justinbarry)! - Put contract addr in `system.contracts.*` namespace
- [#1511](https://github.com/onflow/fcl-js/pull/1511) [`48ff4330`](https://github.com/onflow/fcl-js/commit/48ff43303c30bab86274bd281f6af28affdb2f25) Thanks [@justinbarry](https://github.com/justinbarry)! - Add support for `import "ContractName"` syntax in scripts and transactions.
## 1.1.0-alpha.0

@@ -4,0 +12,0 @@

317

dist/config.js

@@ -26,2 +26,10 @@ 'use strict';

/**
* Asserts fact is true, otherwise throw an error with invariant message
* @param {boolean} fact
* @param {string} msg
* @param {Array} rest
* @returns {void}
*/
function invariant$1(fact, msg) {

@@ -57,2 +65,20 @@ if (!fact) {

};
/***
* Merge multiple functions returning objects into one object.
* @param {...function(*): Object} funcs
* @return {Object}
*/
var mergePipe$1 = function mergePipe() {
for (var _len2 = arguments.length, funcs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
funcs[_key2] = arguments[_key2];
}
return function (v) {
return funcs.reduce(function (res, func) {
return _objectSpread__default["default"](_objectSpread__default["default"]({}, res), func(v));
}, {});
};
};
/**

@@ -66,3 +92,3 @@ * Object check.

var isObject$1 = function isObject(value) {
return value && _typeof__default["default"](value) === 'object' && !Array.isArray(value);
return value && _typeof__default["default"](value) === "object" && !Array.isArray(value);
};

@@ -72,3 +98,3 @@ /**

* @param {Object} target
* @param {Object[]} ...sources
* @param {...Object[]} sources
* @returns {Object}

@@ -79,4 +105,4 @@ */

var mergeDeep$1 = function mergeDeep(target) {
for (var _len2 = arguments.length, sources = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
sources[_key2 - 1] = arguments[_key2];
for (var _len3 = arguments.length, sources = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
sources[_key3 - 1] = arguments[_key3];
}

@@ -127,3 +153,3 @@

var mapContractToNetworkAddress$1 = function mapContractToNetworkAddress(network) {
var mapContractAliasesToNetworkAddress$1 = function mapContractAliasesToNetworkAddress(network) {
return function (contracts) {

@@ -147,2 +173,28 @@ return Object.entries(contracts).reduce(function (c, _ref) {

};
var mapDeploymentsToNetworkAddress$1 = function mapDeploymentsToNetworkAddress(network) {
return function (_ref3) {
var _ref3$deployments = _ref3.deployments,
deployments = _ref3$deployments === void 0 ? {} : _ref3$deployments,
_ref3$accounts = _ref3.accounts,
accounts = _ref3$accounts === void 0 ? {} : _ref3$accounts;
var networkDeployment = deployments === null || deployments === void 0 ? void 0 : deployments[network];
if (!networkDeployment) return {};
return Object.entries(networkDeployment).reduce(function (c, _ref4) {
var _accounts$key;
var _ref5 = _slicedToArray__default["default"](_ref4, 2),
key = _ref5[0],
value = _ref5[1]; // Resolve account address
var accountAddress = (_accounts$key = accounts[key]) === null || _accounts$key === void 0 ? void 0 : _accounts$key.address;
if (!accountAddress) return c; // Create an object assigning the address to the contract name.
return value.reduce(function (c, contract) {
return _objectSpread__default["default"](_objectSpread__default["default"]({}, c), {}, _defineProperty__default["default"]({}, contract, accountAddress));
}, {});
}, {});
};
};
/**

@@ -157,3 +209,3 @@ * Take in flow.json files and return contract to address mapping by network

var getContracts$1 = function getContracts(jsons, network) {
return pipe$1(mergeFlowJSONs$1, filterContracts$1, mapContractToNetworkAddress$1(network))(jsons);
return pipe$1(mergeFlowJSONs$1, mergePipe$1(mapDeploymentsToNetworkAddress$1(network), pipe$1(filterContracts$1, mapContractAliasesToNetworkAddress$1(network))))(jsons);
};

@@ -168,9 +220,11 @@ /**

var hasPrivateKeys$1 = function hasPrivateKeys(flowJSON) {
return Object.entries(flowJSON === null || flowJSON === void 0 ? void 0 : flowJSON.accounts).reduce(function (hasPrivateKey, _ref3) {
var _ref4 = _slicedToArray__default["default"](_ref3, 2);
return Object.entries(flowJSON === null || flowJSON === void 0 ? void 0 : flowJSON.accounts).reduce(function (hasPrivateKey, _ref6) {
var _value$key;
_ref4[0];
var value = _ref4[1];
var _ref7 = _slicedToArray__default["default"](_ref6, 2);
_ref7[0];
var value = _ref7[1];
if (hasPrivateKey) return true;
return value === null || value === void 0 ? void 0 : value.hasOwnProperty("key");
return (value === null || value === void 0 ? void 0 : value.hasOwnProperty("key")) && !(value !== null && value !== void 0 && (_value$key = value.key) !== null && _value$key !== void 0 && _value$key.startsWith("$"));
}, false);

@@ -197,3 +251,3 @@ };

var cleanNetwork$1 = function cleanNetwork(network) {
return (network === null || network === void 0 ? void 0 : network.toLowerCase()) === 'local' ? 'emulator' : network === null || network === void 0 ? void 0 : network.toLowerCase();
return (network === null || network === void 0 ? void 0 : network.toLowerCase()) === "local" ? "emulator" : network === null || network === void 0 ? void 0 : network.toLowerCase();
};

@@ -391,6 +445,28 @@

}
/**
* Takes an object of config keys and returns an object with config methods
*
* @param {Object} values
* @returns {Object} config
* @returns {Function} config.put
* @returns {Function} config.get
* @returns {Function} config.all
* @returns {Function} config.first
* @returns {Function} config.update
* @returns {Function} config.delete
* @returns {Function} config.where
* @returns {Function} config.subscribe
* @returns {Function} config.overload
* @returns {Function} config.load
*
* @example
* import {config} from "@onflow/fcl"
* config({ "flow.network": "testnet" })
*
*/
function _load$1() {
_load$1 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(data) {
var network, cleanedNetwork, flowJSON, isEmulator, _i2, _Object$entries, _Object$entries$_i, key, value, contractConfigKey, existingContractConfigKey;
var network, cleanedNetwork, flowJSON, isEmulator, _i2, _Object$entries, _Object$entries$_i, key, value, contractConfigKey, existingContractConfigKey, systemContractConfigKey, systemExistingContractConfigKeyValue;

@@ -416,3 +492,3 @@ return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {

isEmulator = cleanedNetwork === 'emulator';
isEmulator = cleanedNetwork === "emulator";
log({

@@ -436,3 +512,3 @@ title: "Private Keys Detected",

if (!(_i2 < _Object$entries.length)) {
_context3.next = 23;
_context3.next = 28;
break;

@@ -449,6 +525,6 @@ }

if (existingContractConfigKey) {
if (existingContractConfigKey && existingContractConfigKey !== value) {
log({
title: "Contract Placeholder Conflict Detected",
message: "A generated contract placeholder from config.load and a placeholder you've set manually in config have the same name.",
message: "A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.",
level: LEVELS.warn

@@ -460,3 +536,20 @@ });

case 20:
systemContractConfigKey = "system.contracts.".concat(key);
_context3.next = 23;
return get$1(systemContractConfigKey);
case 23:
systemExistingContractConfigKeyValue = _context3.sent;
if (systemExistingContractConfigKeyValue && systemExistingContractConfigKeyValue !== value) {
log({
title: "Contract Placeholder Conflict Detected",
message: "A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.",
level: LEVELS.warn
});
} else {
put$1(systemContractConfigKey, value);
}
case 25:
_i2++;

@@ -466,3 +559,3 @@ _context3.next = 13;

case 23:
case 28:
case "end":

@@ -572,2 +665,14 @@ return _context3.stop();

/**
* The levels of the logger
*
* @typedef {Object} LEVELS
* @property {number} debug - The debug level
* @property {number} info - The info level
* @property {number} log - The log level
* @property {number} warn - The warn level
* @property {number} error - The error level
*
*/
var LEVELS = Object.freeze({

@@ -580,2 +685,13 @@ debug: 5,

});
/**
* Builds a message formatted for the logger
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @returns {Array<string>} - The message formatted for the logger
*
* @example
* buildLoggerMessageArgs({ title: "My Title", message: "My Message" })
*/

@@ -587,3 +703,18 @@ var buildLoggerMessageArgs = function buildLoggerMessageArgs(_ref) {

};
/**
* Logs messages based on the level of the message and the level set in the config
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @param {number} options.level - The level of the log
* @param {boolean} options.always - Whether to always show the log
* @returns {Promise<void>}
*
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*
*/
var log = /*#__PURE__*/function () {

@@ -657,3 +788,20 @@ var _ref3 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(_ref2) {

}();
/**
* Logs a deprecation notice
*
* @param {Object} options - The options for the log
* @param {string} options.pkg - The package that is being deprecated
* @param {string} options.subject - The subject of the deprecation
* @param {string} options.transition - The transition path for the deprecation
* @param {number} options.level - The level of the log
* @param {string} options.message - The message of the log
* @param {Function} options.callback - A callback to run after the log
* @returns {Promise<void>}
*
* @example
* log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/onflow/flow-js-sdk", message: "Descriptive message", level: LEVELS.warn, callback: () => {} })
*
*/
log.deprecate = function (_ref4) {

@@ -711,2 +859,9 @@ var pkg = _ref4.pkg,

/**
* Asserts fact is true, otherwise throw an error with invariant message
* @param {boolean} fact
* @param {string} msg
* @param {Array} rest
* @returns {void}
*/
function invariant(fact, msg) {

@@ -742,2 +897,20 @@ if (!fact) {

};
/***
* Merge multiple functions returning objects into one object.
* @param {...function(*): Object} funcs
* @return {Object}
*/
var mergePipe = function mergePipe() {
for (var _len2 = arguments.length, funcs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
funcs[_key2] = arguments[_key2];
}
return function (v) {
return funcs.reduce(function (res, func) {
return _objectSpread__default["default"](_objectSpread__default["default"]({}, res), func(v));
}, {});
};
};
/**

@@ -751,3 +924,3 @@ * Object check.

var isObject = function isObject(value) {
return value && _typeof__default["default"](value) === 'object' && !Array.isArray(value);
return value && _typeof__default["default"](value) === "object" && !Array.isArray(value);
};

@@ -757,3 +930,3 @@ /**

* @param {Object} target
* @param {Object[]} ...sources
* @param {...Object[]} sources
* @returns {Object}

@@ -764,4 +937,4 @@ */

var mergeDeep = function mergeDeep(target) {
for (var _len2 = arguments.length, sources = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
sources[_key2 - 1] = arguments[_key2];
for (var _len3 = arguments.length, sources = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
sources[_key3 - 1] = arguments[_key3];
}

@@ -791,3 +964,2 @@

var mergeFlowJSONs = function mergeFlowJSONs(value) {

@@ -813,3 +985,3 @@ return Array.isArray(value) ? mergeDeep.apply(void 0, [{}].concat(_toConsumableArray__default["default"](value))) : value;

var mapContractToNetworkAddress = function mapContractToNetworkAddress(network) {
var mapContractAliasesToNetworkAddress = function mapContractAliasesToNetworkAddress(network) {
return function (contracts) {

@@ -833,2 +1005,28 @@ return Object.entries(contracts).reduce(function (c, _ref) {

};
var mapDeploymentsToNetworkAddress = function mapDeploymentsToNetworkAddress(network) {
return function (_ref3) {
var _ref3$deployments = _ref3.deployments,
deployments = _ref3$deployments === void 0 ? {} : _ref3$deployments,
_ref3$accounts = _ref3.accounts,
accounts = _ref3$accounts === void 0 ? {} : _ref3$accounts;
var networkDeployment = deployments === null || deployments === void 0 ? void 0 : deployments[network];
if (!networkDeployment) return {};
return Object.entries(networkDeployment).reduce(function (c, _ref4) {
var _accounts$key;
var _ref5 = _slicedToArray__default["default"](_ref4, 2),
key = _ref5[0],
value = _ref5[1];
// Resolve account address
var accountAddress = (_accounts$key = accounts[key]) === null || _accounts$key === void 0 ? void 0 : _accounts$key.address;
if (!accountAddress) return c; // Create an object assigning the address to the contract name.
return value.reduce(function (c, contract) {
return _objectSpread__default["default"](_objectSpread__default["default"]({}, c), {}, _defineProperty__default["default"]({}, contract, accountAddress));
}, {});
}, {});
};
};
/**

@@ -843,3 +1041,3 @@ * Take in flow.json files and return contract to address mapping by network

var getContracts = function getContracts(jsons, network) {
return pipe(mergeFlowJSONs, filterContracts, mapContractToNetworkAddress(network))(jsons);
return pipe(mergeFlowJSONs, mergePipe(mapDeploymentsToNetworkAddress(network), pipe(filterContracts, mapContractAliasesToNetworkAddress(network))))(jsons);
};

@@ -853,9 +1051,11 @@ /**

var hasPrivateKeys = function hasPrivateKeys(flowJSON) {
return Object.entries(flowJSON === null || flowJSON === void 0 ? void 0 : flowJSON.accounts).reduce(function (hasPrivateKey, _ref3) {
var _ref4 = _slicedToArray__default["default"](_ref3, 2);
_ref4[0];
var value = _ref4[1];
return Object.entries(flowJSON === null || flowJSON === void 0 ? void 0 : flowJSON.accounts).reduce(function (hasPrivateKey, _ref6) {
var _value$key;
var _ref7 = _slicedToArray__default["default"](_ref6, 2);
_ref7[0];
var value = _ref7[1];
if (hasPrivateKey) return true;
return value === null || value === void 0 ? void 0 : value.hasOwnProperty("key");
return (value === null || value === void 0 ? void 0 : value.hasOwnProperty("key")) && !(value !== null && value !== void 0 && (_value$key = value.key) !== null && _value$key !== void 0 && _value$key.startsWith("$"));
}, false);

@@ -881,3 +1081,3 @@ };

var cleanNetwork = function cleanNetwork(network) {
return (network === null || network === void 0 ? void 0 : network.toLowerCase()) === 'local' ? 'emulator' : network === null || network === void 0 ? void 0 : network.toLowerCase();
return (network === null || network === void 0 ? void 0 : network.toLowerCase()) === "local" ? "emulator" : network === null || network === void 0 ? void 0 : network.toLowerCase();
};

@@ -1074,6 +1274,28 @@

}
/**
* Takes an object of config keys and returns an object with config methods
*
* @param {Object} values
* @returns {Object} config
* @returns {Function} config.put
* @returns {Function} config.get
* @returns {Function} config.all
* @returns {Function} config.first
* @returns {Function} config.update
* @returns {Function} config.delete
* @returns {Function} config.where
* @returns {Function} config.subscribe
* @returns {Function} config.overload
* @returns {Function} config.load
*
* @example
* import {config} from "@onflow/fcl"
* config({ "flow.network": "testnet" })
*
*/
function _load() {
_load = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(data) {
var network, cleanedNetwork, flowJSON, isEmulator, _i2, _Object$entries, _Object$entries$_i, key, value, contractConfigKey, existingContractConfigKey;
var network, cleanedNetwork, flowJSON, isEmulator, _i2, _Object$entries, _Object$entries$_i, key, value, contractConfigKey, existingContractConfigKey, systemContractConfigKey, systemExistingContractConfigKeyValue;

@@ -1099,3 +1321,3 @@ return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {

isEmulator = cleanedNetwork === 'emulator';
isEmulator = cleanedNetwork === "emulator";
log({

@@ -1119,3 +1341,3 @@ title: "Private Keys Detected",

if (!(_i2 < _Object$entries.length)) {
_context3.next = 23;
_context3.next = 28;
break;

@@ -1132,6 +1354,6 @@ }

if (existingContractConfigKey) {
if (existingContractConfigKey && existingContractConfigKey !== value) {
log({
title: "Contract Placeholder Conflict Detected",
message: "A generated contract placeholder from config.load and a placeholder you've set manually in config have the same name.",
message: "A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.",
level: LEVELS.warn

@@ -1143,3 +1365,20 @@ });

case 20:
systemContractConfigKey = "system.contracts.".concat(key);
_context3.next = 23;
return get(systemContractConfigKey);
case 23:
systemExistingContractConfigKeyValue = _context3.sent;
if (systemExistingContractConfigKeyValue && systemExistingContractConfigKeyValue !== value) {
log({
title: "Contract Placeholder Conflict Detected",
message: "A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.",
level: LEVELS.warn
});
} else {
put(systemContractConfigKey, value);
}
case 25:
_i2++;

@@ -1149,3 +1388,3 @@ _context3.next = 13;

case 23:
case 28:
case "end":

@@ -1152,0 +1391,0 @@ return _context3.stop();

@@ -11,2 +11,10 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';

/**
* Asserts fact is true, otherwise throw an error with invariant message
* @param {boolean} fact
* @param {string} msg
* @param {Array} rest
* @returns {void}
*/
function invariant$1(fact, msg) {

@@ -42,2 +50,20 @@ if (!fact) {

};
/***
* Merge multiple functions returning objects into one object.
* @param {...function(*): Object} funcs
* @return {Object}
*/
var mergePipe$1 = function mergePipe() {
for (var _len2 = arguments.length, funcs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
funcs[_key2] = arguments[_key2];
}
return function (v) {
return funcs.reduce(function (res, func) {
return _objectSpread(_objectSpread({}, res), func(v));
}, {});
};
};
/**

@@ -51,3 +77,3 @@ * Object check.

var isObject$1 = function isObject(value) {
return value && _typeof(value) === 'object' && !Array.isArray(value);
return value && _typeof(value) === "object" && !Array.isArray(value);
};

@@ -57,3 +83,3 @@ /**

* @param {Object} target
* @param {Object[]} ...sources
* @param {...Object[]} sources
* @returns {Object}

@@ -64,4 +90,4 @@ */

var mergeDeep$1 = function mergeDeep(target) {
for (var _len2 = arguments.length, sources = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
sources[_key2 - 1] = arguments[_key2];
for (var _len3 = arguments.length, sources = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
sources[_key3 - 1] = arguments[_key3];
}

@@ -112,3 +138,3 @@

var mapContractToNetworkAddress$1 = function mapContractToNetworkAddress(network) {
var mapContractAliasesToNetworkAddress$1 = function mapContractAliasesToNetworkAddress(network) {
return function (contracts) {

@@ -132,2 +158,28 @@ return Object.entries(contracts).reduce(function (c, _ref) {

};
var mapDeploymentsToNetworkAddress$1 = function mapDeploymentsToNetworkAddress(network) {
return function (_ref3) {
var _ref3$deployments = _ref3.deployments,
deployments = _ref3$deployments === void 0 ? {} : _ref3$deployments,
_ref3$accounts = _ref3.accounts,
accounts = _ref3$accounts === void 0 ? {} : _ref3$accounts;
var networkDeployment = deployments === null || deployments === void 0 ? void 0 : deployments[network];
if (!networkDeployment) return {};
return Object.entries(networkDeployment).reduce(function (c, _ref4) {
var _accounts$key;
var _ref5 = _slicedToArray(_ref4, 2),
key = _ref5[0],
value = _ref5[1]; // Resolve account address
var accountAddress = (_accounts$key = accounts[key]) === null || _accounts$key === void 0 ? void 0 : _accounts$key.address;
if (!accountAddress) return c; // Create an object assigning the address to the contract name.
return value.reduce(function (c, contract) {
return _objectSpread(_objectSpread({}, c), {}, _defineProperty({}, contract, accountAddress));
}, {});
}, {});
};
};
/**

@@ -142,3 +194,3 @@ * Take in flow.json files and return contract to address mapping by network

var getContracts$1 = function getContracts(jsons, network) {
return pipe$1(mergeFlowJSONs$1, filterContracts$1, mapContractToNetworkAddress$1(network))(jsons);
return pipe$1(mergeFlowJSONs$1, mergePipe$1(mapDeploymentsToNetworkAddress$1(network), pipe$1(filterContracts$1, mapContractAliasesToNetworkAddress$1(network))))(jsons);
};

@@ -153,9 +205,11 @@ /**

var hasPrivateKeys$1 = function hasPrivateKeys(flowJSON) {
return Object.entries(flowJSON === null || flowJSON === void 0 ? void 0 : flowJSON.accounts).reduce(function (hasPrivateKey, _ref3) {
var _ref4 = _slicedToArray(_ref3, 2);
return Object.entries(flowJSON === null || flowJSON === void 0 ? void 0 : flowJSON.accounts).reduce(function (hasPrivateKey, _ref6) {
var _value$key;
_ref4[0];
var value = _ref4[1];
var _ref7 = _slicedToArray(_ref6, 2);
_ref7[0];
var value = _ref7[1];
if (hasPrivateKey) return true;
return value === null || value === void 0 ? void 0 : value.hasOwnProperty("key");
return (value === null || value === void 0 ? void 0 : value.hasOwnProperty("key")) && !(value !== null && value !== void 0 && (_value$key = value.key) !== null && _value$key !== void 0 && _value$key.startsWith("$"));
}, false);

@@ -182,3 +236,3 @@ };

var cleanNetwork$1 = function cleanNetwork(network) {
return (network === null || network === void 0 ? void 0 : network.toLowerCase()) === 'local' ? 'emulator' : network === null || network === void 0 ? void 0 : network.toLowerCase();
return (network === null || network === void 0 ? void 0 : network.toLowerCase()) === "local" ? "emulator" : network === null || network === void 0 ? void 0 : network.toLowerCase();
};

@@ -376,6 +430,28 @@

}
/**
* Takes an object of config keys and returns an object with config methods
*
* @param {Object} values
* @returns {Object} config
* @returns {Function} config.put
* @returns {Function} config.get
* @returns {Function} config.all
* @returns {Function} config.first
* @returns {Function} config.update
* @returns {Function} config.delete
* @returns {Function} config.where
* @returns {Function} config.subscribe
* @returns {Function} config.overload
* @returns {Function} config.load
*
* @example
* import {config} from "@onflow/fcl"
* config({ "flow.network": "testnet" })
*
*/
function _load$1() {
_load$1 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
var network, cleanedNetwork, flowJSON, isEmulator, _i2, _Object$entries, _Object$entries$_i, key, value, contractConfigKey, existingContractConfigKey;
var network, cleanedNetwork, flowJSON, isEmulator, _i2, _Object$entries, _Object$entries$_i, key, value, contractConfigKey, existingContractConfigKey, systemContractConfigKey, systemExistingContractConfigKeyValue;

@@ -401,3 +477,3 @@ return _regeneratorRuntime.wrap(function _callee3$(_context3) {

isEmulator = cleanedNetwork === 'emulator';
isEmulator = cleanedNetwork === "emulator";
log({

@@ -421,3 +497,3 @@ title: "Private Keys Detected",

if (!(_i2 < _Object$entries.length)) {
_context3.next = 23;
_context3.next = 28;
break;

@@ -434,6 +510,6 @@ }

if (existingContractConfigKey) {
if (existingContractConfigKey && existingContractConfigKey !== value) {
log({
title: "Contract Placeholder Conflict Detected",
message: "A generated contract placeholder from config.load and a placeholder you've set manually in config have the same name.",
message: "A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.",
level: LEVELS.warn

@@ -445,3 +521,20 @@ });

case 20:
systemContractConfigKey = "system.contracts.".concat(key);
_context3.next = 23;
return get$1(systemContractConfigKey);
case 23:
systemExistingContractConfigKeyValue = _context3.sent;
if (systemExistingContractConfigKeyValue && systemExistingContractConfigKeyValue !== value) {
log({
title: "Contract Placeholder Conflict Detected",
message: "A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.",
level: LEVELS.warn
});
} else {
put$1(systemContractConfigKey, value);
}
case 25:
_i2++;

@@ -451,3 +544,3 @@ _context3.next = 13;

case 23:
case 28:
case "end":

@@ -557,2 +650,14 @@ return _context3.stop();

/**
* The levels of the logger
*
* @typedef {Object} LEVELS
* @property {number} debug - The debug level
* @property {number} info - The info level
* @property {number} log - The log level
* @property {number} warn - The warn level
* @property {number} error - The error level
*
*/
var LEVELS = Object.freeze({

@@ -565,2 +670,13 @@ debug: 5,

});
/**
* Builds a message formatted for the logger
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @returns {Array<string>} - The message formatted for the logger
*
* @example
* buildLoggerMessageArgs({ title: "My Title", message: "My Message" })
*/

@@ -572,3 +688,18 @@ var buildLoggerMessageArgs = function buildLoggerMessageArgs(_ref) {

};
/**
* Logs messages based on the level of the message and the level set in the config
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @param {number} options.level - The level of the log
* @param {boolean} options.always - Whether to always show the log
* @returns {Promise<void>}
*
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*
*/
var log = /*#__PURE__*/function () {

@@ -642,3 +773,20 @@ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {

}();
/**
* Logs a deprecation notice
*
* @param {Object} options - The options for the log
* @param {string} options.pkg - The package that is being deprecated
* @param {string} options.subject - The subject of the deprecation
* @param {string} options.transition - The transition path for the deprecation
* @param {number} options.level - The level of the log
* @param {string} options.message - The message of the log
* @param {Function} options.callback - A callback to run after the log
* @returns {Promise<void>}
*
* @example
* log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/onflow/flow-js-sdk", message: "Descriptive message", level: LEVELS.warn, callback: () => {} })
*
*/
log.deprecate = function (_ref4) {

@@ -696,2 +844,9 @@ var pkg = _ref4.pkg,

/**
* Asserts fact is true, otherwise throw an error with invariant message
* @param {boolean} fact
* @param {string} msg
* @param {Array} rest
* @returns {void}
*/
function invariant(fact, msg) {

@@ -727,2 +882,20 @@ if (!fact) {

};
/***
* Merge multiple functions returning objects into one object.
* @param {...function(*): Object} funcs
* @return {Object}
*/
var mergePipe = function mergePipe() {
for (var _len2 = arguments.length, funcs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
funcs[_key2] = arguments[_key2];
}
return function (v) {
return funcs.reduce(function (res, func) {
return _objectSpread(_objectSpread({}, res), func(v));
}, {});
};
};
/**

@@ -736,3 +909,3 @@ * Object check.

var isObject = function isObject(value) {
return value && _typeof(value) === 'object' && !Array.isArray(value);
return value && _typeof(value) === "object" && !Array.isArray(value);
};

@@ -742,3 +915,3 @@ /**

* @param {Object} target
* @param {Object[]} ...sources
* @param {...Object[]} sources
* @returns {Object}

@@ -749,4 +922,4 @@ */

var mergeDeep = function mergeDeep(target) {
for (var _len2 = arguments.length, sources = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
sources[_key2 - 1] = arguments[_key2];
for (var _len3 = arguments.length, sources = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
sources[_key3 - 1] = arguments[_key3];
}

@@ -776,3 +949,2 @@

var mergeFlowJSONs = function mergeFlowJSONs(value) {

@@ -798,3 +970,3 @@ return Array.isArray(value) ? mergeDeep.apply(void 0, [{}].concat(_toConsumableArray(value))) : value;

var mapContractToNetworkAddress = function mapContractToNetworkAddress(network) {
var mapContractAliasesToNetworkAddress = function mapContractAliasesToNetworkAddress(network) {
return function (contracts) {

@@ -818,2 +990,28 @@ return Object.entries(contracts).reduce(function (c, _ref) {

};
var mapDeploymentsToNetworkAddress = function mapDeploymentsToNetworkAddress(network) {
return function (_ref3) {
var _ref3$deployments = _ref3.deployments,
deployments = _ref3$deployments === void 0 ? {} : _ref3$deployments,
_ref3$accounts = _ref3.accounts,
accounts = _ref3$accounts === void 0 ? {} : _ref3$accounts;
var networkDeployment = deployments === null || deployments === void 0 ? void 0 : deployments[network];
if (!networkDeployment) return {};
return Object.entries(networkDeployment).reduce(function (c, _ref4) {
var _accounts$key;
var _ref5 = _slicedToArray(_ref4, 2),
key = _ref5[0],
value = _ref5[1];
// Resolve account address
var accountAddress = (_accounts$key = accounts[key]) === null || _accounts$key === void 0 ? void 0 : _accounts$key.address;
if (!accountAddress) return c; // Create an object assigning the address to the contract name.
return value.reduce(function (c, contract) {
return _objectSpread(_objectSpread({}, c), {}, _defineProperty({}, contract, accountAddress));
}, {});
}, {});
};
};
/**

@@ -828,3 +1026,3 @@ * Take in flow.json files and return contract to address mapping by network

var getContracts = function getContracts(jsons, network) {
return pipe(mergeFlowJSONs, filterContracts, mapContractToNetworkAddress(network))(jsons);
return pipe(mergeFlowJSONs, mergePipe(mapDeploymentsToNetworkAddress(network), pipe(filterContracts, mapContractAliasesToNetworkAddress(network))))(jsons);
};

@@ -838,9 +1036,11 @@ /**

var hasPrivateKeys = function hasPrivateKeys(flowJSON) {
return Object.entries(flowJSON === null || flowJSON === void 0 ? void 0 : flowJSON.accounts).reduce(function (hasPrivateKey, _ref3) {
var _ref4 = _slicedToArray(_ref3, 2);
_ref4[0];
var value = _ref4[1];
return Object.entries(flowJSON === null || flowJSON === void 0 ? void 0 : flowJSON.accounts).reduce(function (hasPrivateKey, _ref6) {
var _value$key;
var _ref7 = _slicedToArray(_ref6, 2);
_ref7[0];
var value = _ref7[1];
if (hasPrivateKey) return true;
return value === null || value === void 0 ? void 0 : value.hasOwnProperty("key");
return (value === null || value === void 0 ? void 0 : value.hasOwnProperty("key")) && !(value !== null && value !== void 0 && (_value$key = value.key) !== null && _value$key !== void 0 && _value$key.startsWith("$"));
}, false);

@@ -866,3 +1066,3 @@ };

var cleanNetwork = function cleanNetwork(network) {
return (network === null || network === void 0 ? void 0 : network.toLowerCase()) === 'local' ? 'emulator' : network === null || network === void 0 ? void 0 : network.toLowerCase();
return (network === null || network === void 0 ? void 0 : network.toLowerCase()) === "local" ? "emulator" : network === null || network === void 0 ? void 0 : network.toLowerCase();
};

@@ -1059,6 +1259,28 @@

}
/**
* Takes an object of config keys and returns an object with config methods
*
* @param {Object} values
* @returns {Object} config
* @returns {Function} config.put
* @returns {Function} config.get
* @returns {Function} config.all
* @returns {Function} config.first
* @returns {Function} config.update
* @returns {Function} config.delete
* @returns {Function} config.where
* @returns {Function} config.subscribe
* @returns {Function} config.overload
* @returns {Function} config.load
*
* @example
* import {config} from "@onflow/fcl"
* config({ "flow.network": "testnet" })
*
*/
function _load() {
_load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
var network, cleanedNetwork, flowJSON, isEmulator, _i2, _Object$entries, _Object$entries$_i, key, value, contractConfigKey, existingContractConfigKey;
var network, cleanedNetwork, flowJSON, isEmulator, _i2, _Object$entries, _Object$entries$_i, key, value, contractConfigKey, existingContractConfigKey, systemContractConfigKey, systemExistingContractConfigKeyValue;

@@ -1084,3 +1306,3 @@ return _regeneratorRuntime.wrap(function _callee3$(_context3) {

isEmulator = cleanedNetwork === 'emulator';
isEmulator = cleanedNetwork === "emulator";
log({

@@ -1104,3 +1326,3 @@ title: "Private Keys Detected",

if (!(_i2 < _Object$entries.length)) {
_context3.next = 23;
_context3.next = 28;
break;

@@ -1117,6 +1339,6 @@ }

if (existingContractConfigKey) {
if (existingContractConfigKey && existingContractConfigKey !== value) {
log({
title: "Contract Placeholder Conflict Detected",
message: "A generated contract placeholder from config.load and a placeholder you've set manually in config have the same name.",
message: "A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.",
level: LEVELS.warn

@@ -1128,3 +1350,20 @@ });

case 20:
systemContractConfigKey = "system.contracts.".concat(key);
_context3.next = 23;
return get(systemContractConfigKey);
case 23:
systemExistingContractConfigKeyValue = _context3.sent;
if (systemExistingContractConfigKeyValue && systemExistingContractConfigKeyValue !== value) {
log({
title: "Contract Placeholder Conflict Detected",
message: "A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.",
level: LEVELS.warn
});
} else {
put(systemContractConfigKey, value);
}
case 25:
_i2++;

@@ -1134,3 +1373,3 @@ _context3.next = 13;

case 23:
case 28:
case "end":

@@ -1137,0 +1376,0 @@ return _context3.stop();

2

package.json
{
"name": "@onflow/config",
"version": "1.1.0-alpha.0",
"version": "1.1.0-alpha.1",
"description": "Config for FCL-JS",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -122,8 +122,5 @@ import {

const cleanedNetwork = cleanNetwork(network)
const { flowJSON } = data
const {flowJSON} = data
invariant(
Boolean(flowJSON),
"config.load -- 'flowJSON' must be defined"
)
invariant(Boolean(flowJSON), "config.load -- 'flowJSON' must be defined")

@@ -136,3 +133,3 @@ invariant(

if (anyHasPrivateKeys(flowJSON)) {
const isEmulator = cleanedNetwork === 'emulator'
const isEmulator = cleanedNetwork === "emulator"

@@ -148,10 +145,11 @@ logger.log({

for (const [key, value] of Object.entries(getContracts(flowJSON, cleanedNetwork))) {
for (const [key, value] of Object.entries(
getContracts(flowJSON, cleanedNetwork)
)) {
const contractConfigKey = `0x${key}`
const existingContractConfigKey = await get(contractConfigKey)
if (existingContractConfigKey) {
if (existingContractConfigKey && existingContractConfigKey !== value) {
logger.log({
title: "Contract Placeholder Conflict Detected",
message: `A generated contract placeholder from config.load and a placeholder you've set manually in config have the same name.`,
message: `A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.`,
level: logger.LEVELS.warn,

@@ -162,5 +160,43 @@ })

}
const systemContractConfigKey = `system.contracts.${key}`
const systemExistingContractConfigKeyValue = await get(
systemContractConfigKey
)
if (
systemExistingContractConfigKeyValue &&
systemExistingContractConfigKeyValue !== value
) {
logger.log({
title: "Contract Placeholder Conflict Detected",
message: `A generated contract placeholder from config.load conflicts with a placeholder you've set manually in config have the same name.`,
level: logger.LEVELS.warn,
})
} else {
put(systemContractConfigKey, value)
}
}
}
/**
* Takes an object of config keys and returns an object with config methods
*
* @param {Object} values
* @returns {Object} config
* @returns {Function} config.put
* @returns {Function} config.get
* @returns {Function} config.all
* @returns {Function} config.first
* @returns {Function} config.update
* @returns {Function} config.delete
* @returns {Function} config.where
* @returns {Function} config.subscribe
* @returns {Function} config.overload
* @returns {Function} config.load
*
* @example
* import {config} from "@onflow/fcl"
* config({ "flow.network": "testnet" })
*
*/
function config(values) {

@@ -167,0 +203,0 @@ if (values != null && typeof values === "object") {

@@ -6,76 +6,81 @@ import {config, clearConfig} from "./config"

describe("config()", () => {
clearConfig()
config({
"config.test.init": "rawr",
beforeEach(async () => {
clearConfig()
})
config()
.put("config.test.t", "t")
.put("config.test.z", "z")
.put("config.test.foo.bar", "bar")
.put("config.test.foo.baz", "baz")
.put("config.test.wat.bar", "foo")
describe("crud methods", () => {
beforeEach(async () => {
config({
"config.test.init": "rawr",
})
test("get", async () => {
expect(await config().get("config.test.foo.bar")).toBe("bar")
expect(await config().get("config.test.init")).toBe("rawr")
})
config()
.put("config.test.t", "t")
.put("config.test.z", "z")
.put("config.test.foo.bar", "bar")
.put("config.test.foo.baz", "baz")
.put("config.test.wat.bar", "foo")
})
test("get with fallback", async () => {
expect(await config().get("config.test.not.a.thing", "fallback")).toBe(
"fallback"
)
})
test("get", async () => {
expect(await config().get("config.test.foo.bar")).toBe("bar")
expect(await config().get("config.test.init")).toBe("rawr")
})
test("update", async () => {
config().update("config.test.t", v => v + v)
expect(await config().get("config.test.t")).toBe("tt")
})
test("get with fallback", async () => {
expect(await config().get("config.test.not.a.thing", "fallback")).toBe(
"fallback"
)
})
test("delete", async () => {
config().delete("config.test.z")
expect(await config().get("config.test.z")).toBe(undefined)
})
test("update", async () => {
config().update("config.test.t", v => v + v)
expect(await config().get("config.test.t")).toBe("tt")
})
test("where", async () => {
expect(await config().where(/^config.test.foo/)).toEqual({
"config.test.foo.bar": "bar",
"config.test.foo.baz": "baz",
test("delete", async () => {
config().delete("config.test.z")
expect(await config().get("config.test.z")).toBe(undefined)
})
})
test("subscribe", async () => {
const fn1 = jest.fn()
const unsub = config().subscribe(fn1)
await idle()
test("where", async () => {
expect(await config().where(/^config.test.foo/)).toEqual({
"config.test.foo.bar": "bar",
"config.test.foo.baz": "baz",
})
})
config().put("config.test.y", "y").put("config.test.x", "x")
test("subscribe", async () => {
const fn1 = jest.fn()
const unsub = config().subscribe(fn1)
await idle()
await idle()
unsub()
await idle()
config().put("config.test.y", "y").put("config.test.x", "x")
config().update("config.test.y", v => v + v)
await idle()
unsub()
await idle()
await idle()
config().update("config.test.y", v => v + v)
expect(fn1).toHaveBeenCalledTimes(3)
})
await idle()
test("all", async () => {
expect(await config().all()).toEqual({
"config.test.foo.bar": "bar",
"config.test.foo.baz": "baz",
"config.test.init": "rawr",
"config.test.t": "tt",
"config.test.wat.bar": "foo",
"config.test.x": "x",
"config.test.y": "yy",
expect(fn1).toHaveBeenCalledTimes(3)
})
await clearConfig()
test("all", async () => {
expect(await config().all()).toEqual({
"config.test.foo.bar": "bar",
"config.test.foo.baz": "baz",
"config.test.init": "rawr",
"config.test.t": "t",
"config.test.wat.bar": "foo",
"config.test.z": "z",
})
})
})
test("empty", async () => {
clearConfig()
await idle()
expect(await config().all()).toEqual({})

@@ -85,4 +90,2 @@ })

describe("sans ()", () => {
afterEach(clearConfig)
test("config(data)", async () => {

@@ -106,4 +109,2 @@ const data = {

describe("overload", () => {
afterEach(clearConfig)
test("overload", async () => {

@@ -124,3 +125,3 @@ const PRE = {

expect(await config.all()).toEqual(PRE)
const ret = await config.overload(POST, async d => {
const ret = await config.overload(POST, async () => {
expect(await config.all()).toEqual({...PRE, ...POST})

@@ -160,2 +161,181 @@ return "WOOT WOOT"

})
describe("load method", () => {
describe("with a set network", () => {
beforeEach(async () => {
// Just picked a random network. Behavior might differ based on network selection at a future date.
await config().put("flow.network", "emulator")
})
describe("flow.json v1", () => {
let flowJSON
describe("without aliases", () => {
beforeEach(async () => {
flowJSON = {
accounts: {
"emulator-account": {
fromFile: "./emulator.private.json",
},
},
contracts: {
HelloWorld: {
source: "./cadence/contracts/HelloWorld.cdc",
aliases: {
emulator: "0x1",
testnet: "0x01",
mainnet: "0x001",
},
},
SecondLife: {
aliases: {
testnet: "0x02",
mainnet: "0x002",
},
},
},
deployments: {
emulator: {
"emulator-account": ["HelloWorld"],
},
},
networks: {
emulator: "127.0.0.1:3569",
},
}
})
describe("with single config loaded", () => {
beforeEach(async () => {
await config().load({flowJSON})
await idle()
})
test("should load the contract location wrt the currently set network", async () => {
await expect(config().get("0xHelloWorld")).resolves.toBe("0x1")
await expect(
config().get("system.contracts.HelloWorld")
).resolves.toBe("0x1")
})
test("should not set a contract if it does not have an alias", async () => {
await expect(
config().get("0xSecondLife")
).resolves.toBeUndefined()
await expect(
config().get("system.contracts.SecondLife")
).resolves.toBeUndefined()
})
})
describe("with an array of configs loaded", () => {
beforeEach(async () => {
let secondFlowJSON = {
accounts: {},
contracts: {
ThirdContract: {
aliases: {
emulator: "0x3",
testnet: "0x03",
mainnet: "0x003",
},
},
},
deployments: {},
networks: {},
}
await config().load({flowJSON: [flowJSON, secondFlowJSON]})
await idle()
})
test("should load the contract locations from the secondFlowJSON", async () => {
await expect(config().get("0xThirdContract")).resolves.toBe("0x3")
await expect(
config().get("system.contracts.ThirdContract")
).resolves.toBe("0x3")
})
})
})
describe("without contract aliases", () => {
beforeEach(async () => {
flowJSON = {
networks: {
emulator: "127.0.0.1:3569",
},
accounts: {
default: {
address: "f8d6e0586b0a20c7",
key: "ba68d45a5acaa52f3cacf4ad3a64d9523e0ce0ae3addb1ee6805385b380b7646",
},
},
contracts: {
HelloWorld: "./cadence/contracts/HelloWorld.cdc",
},
deployments: {
emulator: {
default: ["HelloWorld"],
},
},
}
await config().load({flowJSON})
await idle()
})
test("should resolve to the default address through the deployment link", async () => {
await expect(config().get("0xHelloWorld")).resolves.toBe(
"f8d6e0586b0a20c7"
)
await expect(
config().get("system.contracts.HelloWorld")
).resolves.toBe("f8d6e0586b0a20c7")
})
})
describe("with both contract aliases and deployments", () => {
beforeEach(async () => {
flowJSON = {
networks: {
emulator: "127.0.0.1:3569",
},
accounts: {
default: {
address: "f8d6e0586b0a20c7",
key: "ba68d45a5acaa52f3cacf4ad3a64d9523e0ce0ae3addb1ee6805385b380b7646",
},
},
contracts: {
HelloWorld: {
source: "./cadence/contracts/HelloWorld.cdc",
aliases: {
emulator: "0x1",
},
},
},
deployments: {
emulator: {
default: ["HelloWorld"],
},
},
}
await config().load({flowJSON})
await idle()
})
test("should return the alias, not the deployment address", async () => {
await expect(config().get("0xHelloWorld")).resolves.toBe("0x1")
await expect(
config().get("system.contracts.HelloWorld")
).resolves.toBe("0x1")
})
})
})
})
})
describe("without a network set", () => {
test("should throw an error", async () => {
await expect(() => config().load({flowJSON: {}})).rejects.toThrowError()
})
})
})

@@ -1,7 +0,22 @@

const pipe = (...funcs) => v => {
return funcs.reduce((res, func) => {
return func(res)
}, v)
}
const pipe =
(...funcs) =>
v => {
return funcs.reduce((res, func) => {
return func(res)
}, v)
}
/***
* Merge multiple functions returning objects into one object.
* @param {...function(*): Object} funcs
* @return {Object}
*/
const mergePipe =
(...funcs) =>
v => {
return funcs.reduce((res, func) => {
return {...res, ...func(v)}
}, {})
}
/**

@@ -12,3 +27,4 @@ * Object check.

*/
const isObject = value => value && typeof value === 'object' && !Array.isArray(value)
const isObject = value =>
value && typeof value === "object" && !Array.isArray(value)

@@ -18,3 +34,3 @@ /**

* @param {Object} target
* @param {Object[]} ...sources
* @param {...Object[]} sources
* @returns {Object}

@@ -29,6 +45,6 @@ */

if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} })
if (!target[key]) Object.assign(target, {[key]: {}})
mergeDeep(target[key], source[key])
} else {
Object.assign(target, { [key]: source[key] })
Object.assign(target, {[key]: source[key]})
}

@@ -42,2 +58,12 @@ }

/**
* Support if/then/else behavior in a function way.
* @param{function(Object): boolean} testFn
* @param{function(Object): *} posCond - Function to run if testFn is true
* @param{function(Object): *} negCond - Function to run it testFn is false
* @returns {function(*): *}
*/
export const ifElse = (testFn, posCond, negCond) => obj =>
testFn(obj) ? posCond(obj) : negCond(obj)
/**
* Deep merge multiple Flow JSON.

@@ -47,3 +73,4 @@ * @param {Object|Object[]} value

*/
const mergeFlowJSONs = value => Array.isArray(value) ? mergeDeep({}, ...value) : value
const mergeFlowJSONs = value =>
Array.isArray(value) ? mergeDeep({}, ...value) : value

@@ -55,3 +82,3 @@ /**

*/
const filterContracts = obj => obj.contracts ? obj.contracts : {}
const filterContracts = obj => (obj.contracts ? obj.contracts : {})

@@ -63,3 +90,3 @@ /**

*/
const mapContractToNetworkAddress = network => contracts => {
const mapContractAliasesToNetworkAddress = network => contracts => {
return Object.entries(contracts).reduce((c, [key, value]) => {

@@ -75,2 +102,20 @@ const networkContractAlias = value?.aliases?.[network]

const mapDeploymentsToNetworkAddress =
network =>
({deployments = {}, accounts = {}}) => {
const networkDeployment = deployments?.[network]
if (!networkDeployment) return {}
return Object.entries(networkDeployment).reduce((c, [key, value]) => {
// Resolve account address
const accountAddress = accounts[key]?.address
if (!accountAddress) return c
// Create an object assigning the address to the contract name.
return value.reduce((c, contract) => {
return {...c, [contract]: accountAddress}
}, {})
}, {})
}
/**

@@ -85,4 +130,6 @@ * Take in flow.json files and return contract to address mapping by network

mergeFlowJSONs,
filterContracts,
mapContractToNetworkAddress(network)
mergePipe(
mapDeploymentsToNetworkAddress(network),
pipe(filterContracts, mapContractAliasesToNetworkAddress(network))
)
)(jsons)

@@ -97,6 +144,9 @@ }

const hasPrivateKeys = flowJSON => {
return Object.entries(flowJSON?.accounts).reduce((hasPrivateKey, [key, value]) => {
if (hasPrivateKey) return true
return value?.hasOwnProperty("key")
}, false)
return Object.entries(flowJSON?.accounts).reduce(
(hasPrivateKey, [key, value]) => {
if (hasPrivateKey) return true
return value?.hasOwnProperty("key") && !value?.key?.startsWith("$")
},
false
)
}

@@ -119,2 +169,3 @@

*/
export const cleanNetwork = network => network?.toLowerCase() === 'local' ? 'emulator' : network?.toLowerCase()
export const cleanNetwork = network =>
network?.toLowerCase() === "local" ? "emulator" : network?.toLowerCase()

@@ -6,51 +6,51 @@ import {getContracts, anyHasPrivateKeys} from "./utils"

const flowJSON = {
"networks": {
"emulator": "127.0.0.1:3569",
"mainnet": "access.mainnet.nodes.onflow.org:9000",
"testnet": "access.devnet.nodes.onflow.org:9000"
networks: {
emulator: "127.0.0.1:3569",
mainnet: "access.mainnet.nodes.onflow.org:9000",
testnet: "access.devnet.nodes.onflow.org:9000",
},
"contracts": {
"HelloWorld": {
"source": "./cadence/contracts/HelloWorld.cdc",
"aliases": {
"emulator": "0x123",
"testnet": "0x124",
"mainnet": "0x125"
}
contracts: {
HelloWorld: {
source: "./cadence/contracts/HelloWorld.cdc",
aliases: {
emulator: "0x123",
testnet: "0x124",
mainnet: "0x125",
},
},
"FooBar": {
"source": "./cadence/contracts/FooBar.cdc",
"aliases": {
"emulator": "0x223",
"testnet": "0x224",
"mainnet": "0x225"
}
}
FooBar: {
source: "./cadence/contracts/FooBar.cdc",
aliases: {
emulator: "0x223",
testnet: "0x224",
mainnet: "0x225",
},
},
},
"accounts": {
accounts: {
"emulator-account": {
"address": "f8d6e0586b0a20c7",
"key": "ba68d45a5acaa52f3cacf4ad3a64d9523e0ce0ae3addb1ee6805385b380b7646"
}
address: "f8d6e0586b0a20c7",
key: "ba68d45a5acaa52f3cacf4ad3a64d9523e0ce0ae3addb1ee6805385b380b7646",
},
},
"deployments": {
"emulator": {
"emulator-account": ["HelloWorld"]
}
}
deployments: {
emulator: {
"emulator-account": ["HelloWorld"],
},
},
}
const emulatorMappings = {
"HelloWorld": "0x123",
"FooBar": "0x223"
HelloWorld: "0x123",
FooBar: "0x223",
}
const testnetMappings = {
"HelloWorld": "0x124",
"FooBar": "0x224"
HelloWorld: "0x124",
FooBar: "0x224",
}
const mainnetMappings = {
"HelloWorld": "0x125",
"FooBar": "0x225"
HelloWorld: "0x125",
FooBar: "0x225",
}

@@ -72,25 +72,25 @@

const flowJSON = {
"accounts": {
accounts: {
"emulator-account": {
"address": "f8d6e0586b0a20c7",
"key": "ba68d45a5acaa52f3cacf4ad3a64d9523e0ce0ae3addb1ee6805385b380b7646"
}
}
address: "f8d6e0586b0a20c7",
key: "ba68d45a5acaa52f3cacf4ad3a64d9523e0ce0ae3addb1ee6805385b380b7646",
},
},
}
const flowJSONTwo = {
"accounts": {
accounts: {
"testnet-account": {
"address": "f8d6e0586b0a20c7",
"key": "ba68d45a5acaa52f3cacf4ad3a64d9523e0ce0ae3addb1ee6805385b380b7646"
}
}
address: "f8d6e0586b0a20c7",
key: "ba68d45a5acaa52f3cacf4ad3a64d9523e0ce0ae3addb1ee6805385b380b7646",
},
},
}
const flowJSONThree = {
"accounts": {
accounts: {
"emulator-account": {
"address": "f8d6e0586b0a20c7"
}
}
address: "f8d6e0586b0a20c7",
},
},
}

@@ -103,17 +103,30 @@

test("should return false for environmental variables", async () => {
const flowJSON = {
accounts: {
"emulator-account": {
address: "f8d6e0586b0a20c7",
key: "$FLOW_EMULATOR_PRIVATE_KEY",
},
},
}
expect(anyHasPrivateKeys(flowJSON)).toBe(false)
})
test("it should return false if no private keys exist in account", () => {
const flowJSON = {
"accounts": {
accounts: {
"emulator-account": {
"address": "f8d6e0586b0a20c7"
}
}
address: "f8d6e0586b0a20c7",
},
},
}
const flowJSONTwo = {
"accounts": {
accounts: {
"emulator-account": {
"address": "f8d6e0586b0a20c7"
}
}
address: "f8d6e0586b0a20c7",
},
},
}

@@ -124,2 +137,2 @@

})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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