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

@onflow/config

Package Overview
Dependencies
Maintainers
12
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.2.0-alpha.0 to 1.3.0-typescript.0

dist/config.d.ts

18

.eslintrc.json

@@ -9,7 +9,8 @@ {

"extends": [
"plugin:jsdoc/recommended"
"plugin:jsdoc/recommended-typescript",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"plugins": [
"jsdoc"
],
"plugins": ["jsdoc", "@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {

@@ -21,9 +22,4 @@ "ecmaVersion": "latest",

"rules": {
"jsdoc/require-jsdoc": [
"error",
{
"publicOnly": true
}
]
"@typescript-eslint/no-explicit-any": "off"
}
}
}
# @onflow/config
## 1.3.0-typescript.0
### Minor Changes
- [#1731](https://github.com/onflow/fcl-js/pull/1731) [`fb3bd37e`](https://github.com/onflow/fcl-js/commit/fb3bd37e02bf0de046ea164e6c2f1a0c27e515c1) Thanks [@jribbink](https://github.com/jribbink)! - Add Typescript to @onflow/config
## 1.2.0
### Minor Changes
- [#1728](https://github.com/onflow/fcl-js/pull/1728) [`a4f8c00c`](https://github.com/onflow/fcl-js/commit/a4f8c00c4cf292d3a4afac610dedbc89ff3affea) Thanks [@nialexsan](https://github.com/nialexsan)! - TS build
### Patch Changes
- Updated dependencies [[`a4f8c00c`](https://github.com/onflow/fcl-js/commit/a4f8c00c4cf292d3a4afac610dedbc89ff3affea), [`92b966d3`](https://github.com/onflow/fcl-js/commit/92b966d39936ba0a90629ee320e62e4fed5d2296)]:
- @onflow/util-actor@1.3.0
## 1.2.0-alpha.0

@@ -14,2 +31,8 @@

## 1.1.2
### Patch Changes
- [#1771](https://github.com/onflow/fcl-js/pull/1771) [`5edbd823`](https://github.com/onflow/fcl-js/commit/5edbd823b1a6d25eb7bb52dc55338f95beae73b1) Thanks [@jribbink](https://github.com/jribbink)! - Fix @onflow/util-logger <-> @onflow/config circular dependency
## 1.1.1

@@ -16,0 +39,0 @@

@@ -42,4 +42,4 @@ 'use strict';

* Merge multiple functions returning objects into one object.
* @param {...function(*): object} funcs - Functions to merge
* @return {object} - Merged object
* @param funcs - Functions to merge
* @return Merged object
*/

@@ -62,4 +62,4 @@ const mergePipe = function () {

* @description Object check
* @param {*} value - Value to check
* @returns {boolean} - Is object status
* @param value - Value to check
* @returns Is object status
*/

@@ -70,5 +70,5 @@ const isObject = value => value && typeof value === "object" && !Array.isArray(value);

* @description Deep merge multiple objects.
* @param {object} target - Target object
* @param {...object[]} sources - Source objects
* @returns {object} - Merged object
* @param target - Target object
* @param sources - Source objects
* @returns Merged object
*/

@@ -100,4 +100,4 @@ const mergeDeep = function (target) {

* @description Deep merge multiple Flow JSON.
* @param {object|object[]} value - Flow JSON or array of Flow JSONs
* @returns {object} - Merged Flow JSON
* @param value - Flow JSON or array of Flow JSONs
* @returns Merged Flow JSON
*/

@@ -108,4 +108,4 @@ const mergeFlowJSONs = value => Array.isArray(value) ? mergeDeep({}, ...value) : value;

* @description Filter out contracts section of flow.json.
* @param {object|object[]} obj - Flow JSON or array of Flow JSONs
* @returns {object} - Contracts section of Flow JSON
* @param obj - Flow JSON
* @returns Contracts section of Flow JSON
*/

@@ -116,4 +116,4 @@ const filterContracts = obj => obj.contracts ? obj.contracts : {};

* @description Gathers contract addresses by network
* @param {string} network - Network to gather addresses for
* @returns {object} - Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
* @param network - Network to gather addresses for
* @returns Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
*/

@@ -155,5 +155,5 @@ const mapContractAliasesToNetworkAddress = network => contracts => {

* @description Take in flow.json files and return contract to address mapping by network
* @param {object|object[]} jsons - Flow JSON or array of Flow JSONs
* @param {string} network - Network to gather addresses for
* @returns {object} - Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
* @param jsons - Flow JSON or array of Flow JSONs
* @param network - Network to gather addresses for
* @returns Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
*/

@@ -166,4 +166,4 @@ const getContracts = (jsons, network) => {

* @description Checks if string is hexidecimal
* @param {string} str - String to check
* @returns {boolean} - Is hexidecimal status
* @param str - String to check
* @returns Is hexidecimal status
*/

@@ -178,10 +178,10 @@ const isHexidecimal = str => {

* @description Checks flow.json file for private keys
* @param {object} flowJSON - Flow JSON
* @returns {boolean} - Has private keys status
* @param flowJSON - Flow JSON
* @returns Has private keys status
*/
const hasPrivateKeys = flowJSON => {
return Object.entries(flowJSON?.accounts).reduce((hasPrivateKey, _ref4) => {
let [key, value] = _ref4;
return Object.entries(flowJSON?.accounts ?? []).reduce((hasPrivateKey, _ref4) => {
let [, value] = _ref4;
if (hasPrivateKey) return true;
return value?.hasOwnProperty("key") && isHexidecimal(value?.key);
return value && Object.prototype.hasOwnProperty.call(value, "key") && isHexidecimal(value?.key);
}, false);

@@ -192,8 +192,8 @@ };

* @description Take in flow.json or array of flow.json files and checks for private keys
* @param {object|object[]} value - Flow JSON or array of Flow JSONs
* @returns {boolean} - Has private keys status
* @param value - Flow JSON or array of Flow JSONs
* @returns Has private keys status
*/
const anyHasPrivateKeys = value => {
if (isObject(value)) return hasPrivateKeys(value);
return value.some(hasPrivateKeys);
if (Array.isArray(value)) return value.some(hasPrivateKeys);
return hasPrivateKeys(value);
};

@@ -203,7 +203,13 @@

* @description Format network to always be 'emulator', 'testnet', or 'mainnet'
* @param {string} network - Network to format
* @returns {string} - Formatted network name (either 'emulator', 'testnet', or 'mainnet')
* @param network - Network to format
* @returns Formatted network name (either 'emulator', 'testnet', or 'mainnet')
*/
const cleanNetwork = network => network?.toLowerCase() === "local" ? "emulator" : network?.toLowerCase();
const cleanNetwork = network => {
const cleanedNetwork = network?.toLowerCase() === "local" ? "emulator" : network?.toLowerCase();
if (cleanedNetwork === "emulator" || cleanedNetwork === "testnet" || cleanedNetwork === "mainnet") return cleanedNetwork;
throw new Error(`Invalid network "${network}". Must be one of "emulator", "local", "testnet", or "mainnet"`);
};
// Inject config into logger to break circular dependency
logger__namespace.setConfig(config);
const NAME = "config";

@@ -265,5 +271,5 @@ const PUT = "PUT_CONFIG";

},
[CLEAR]: (ctx, letter) => {
let keys = Object.keys(ctx.all());
for (let key of keys) ctx.delete(key);
[CLEAR]: ctx => {
const keys = Object.keys(ctx.all());
for (const key of keys) ctx.delete(key);
ctx.broadcast(UPDATED, {

@@ -294,5 +300,5 @@ ...ctx.all()

* @description Adds a key-value pair to the config
* @param {string} key - The key to add
* @param {*} value - The value to add
* @returns {Promise<object>} - The current config
* @param key - The key to add
* @param value - The value to add
* @returns The config object
*/

@@ -309,5 +315,5 @@ function put(key, value) {

* @description Gets a key-value pair with a fallback from the config
* @param {string} key - The key to add
* @param {*} [fallback] - The fallback value to return if key is not found
* @returns {Promise<*>} - The value found at key or fallback
* @param key - The key to add
* @param fallback - The fallback value to return if key is not found
* @returns The value found at key or fallback
*/

@@ -326,5 +332,5 @@ function get(key, fallback) {

* @description Returns the first non null config value or the fallback
* @param {string[]} wants - The keys to search for
* @param {*} fallback - The fallback value to return if key is not found
* @returns {Promise<*>} - The value found at key or fallback
* @param wants - The keys to search for
* @param fallback - The fallback value to return if key is not found
* @returns The value found at key or fallback
*/

@@ -343,3 +349,3 @@ async function first() {

* @description Returns the current config
* @returns {Promise<object>} - The current config
* @returns The config object
*/

@@ -355,5 +361,5 @@ function all() {

* @description Updates a key-value pair in the config
* @param {string} key - The key to update
* @param {Function} fn - The function to update the value with
* @returns {Promise<object>} - The current config
* @param key - The key to update
* @param fn - The function to update the value with
* @returns The config object
*/

@@ -371,4 +377,4 @@ function update(key) {

* @description Deletes a key-value pair from the config
* @param {string} key - The key to delete
* @returns {Promise<object>} - The current config
* @param key - The key to delete
* @returns The config object
*/

@@ -384,4 +390,4 @@ function _delete(key) {

* @description Returns a subset of the config based on a pattern
* @param {string} pattern - The pattern to match keys against
* @returns {Promise<object>} - The subset of the config
* @param pattern - The pattern to match keys against
* @returns The subset of the config
*/

@@ -399,4 +405,4 @@ function where(pattern) {

* @description Subscribes to config updates
* @param {Function} callback - The callback to call when config is updated
* @returns {Function} - The unsubscribe function
* @param callback - The callback to call when config is updated
* @returns The unsubscribe function
*/

@@ -409,6 +415,5 @@ function subscribe(callback) {

* @description Clears the config
* @returns {void}
*/
function clearConfig() {
return utilActor.send(NAME, CLEAR);
async function clearConfig() {
await utilActor.send(NAME, CLEAR);
}

@@ -418,7 +423,7 @@

* @description Resets the config to a previous state
* @param {object} oldConfig - The previous config state
* @returns {Promise<object>} - The current config
* @param oldConfig - The previous config state
* @returns The config object
*/
function resetConfig(oldConfig) {
return clearConfig().then(config(oldConfig));
async function resetConfig(oldConfig) {
return clearConfig().then(() => config(oldConfig));
}

@@ -428,4 +433,4 @@

* @description Takes in flow.json or array of flow.json files and creates contract placeholders
* @param {object|object[]} data - The flow.json or array of flow.json files
* @returns {void}
* @param data - The data to load
* @param data.flowJSON - The flow.json or array of flow.json files
*/

@@ -439,3 +444,3 @@ async function load(data) {

utilInvariant.invariant(Boolean(flowJSON), "config.load -- 'flowJSON' must be defined");
utilInvariant.invariant(cleanedNetwork, `Flow Network Required -- In order for FCL to load your contracts please define "flow.network" to "emulator", "local", "testnet", or "mainnet" in your config. See more here: https://developers.flow.com/tools/fcl-js/reference/configure-fcl`);
utilInvariant.invariant(!!cleanedNetwork, `Flow Network Required -- In order for FCL to load your contracts please define "flow.network" to "emulator", "local", "testnet", or "mainnet" in your config. See more here: https://developers.flow.com/tools/fcl-js/reference/configure-fcl`);
if (anyHasPrivateKeys(flowJSON)) {

@@ -476,6 +481,6 @@ const isEmulator = cleanedNetwork === "emulator";

// eslint-disable-next-line jsdoc/require-returns
/**
* @description Sets the config
* @param {object} [values] - The values to set
* @param values - The values to set
* @returns The config object
*/

@@ -509,18 +514,18 @@ function config(values) {

config.load = load;
const noop = v => v;
function overload() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
return new Promise(async (resolve, reject) => {
const oldConfig = await all();
try {
config(opts);
var result = await callback(await all());
await resetConfig(oldConfig);
resolve(result);
} catch (error) {
await resetConfig(oldConfig);
reject(error);
}
});
/**
* @description Temporarily overloads the config with the given values and calls the callback
* @param values - The values to overload the config with
* @param callback - The callback to call with the overloaded config
* @returns The result of the callback
*/
async function overload(values, callback) {
const oldConfig = await all();
try {
config(values);
const result = await callback(await all());
return result;
} finally {
await resetConfig(oldConfig);
}
}

@@ -527,0 +532,0 @@

@@ -18,4 +18,4 @@ import { spawn, SUBSCRIBE, UNSUBSCRIBE, send, subscriber } from '@onflow/util-actor';

* Merge multiple functions returning objects into one object.
* @param {...function(*): object} funcs - Functions to merge
* @return {object} - Merged object
* @param funcs - Functions to merge
* @return Merged object
*/

@@ -38,4 +38,4 @@ const mergePipe = function () {

* @description Object check
* @param {*} value - Value to check
* @returns {boolean} - Is object status
* @param value - Value to check
* @returns Is object status
*/

@@ -46,5 +46,5 @@ const isObject = value => value && typeof value === "object" && !Array.isArray(value);

* @description Deep merge multiple objects.
* @param {object} target - Target object
* @param {...object[]} sources - Source objects
* @returns {object} - Merged object
* @param target - Target object
* @param sources - Source objects
* @returns Merged object
*/

@@ -76,4 +76,4 @@ const mergeDeep = function (target) {

* @description Deep merge multiple Flow JSON.
* @param {object|object[]} value - Flow JSON or array of Flow JSONs
* @returns {object} - Merged Flow JSON
* @param value - Flow JSON or array of Flow JSONs
* @returns Merged Flow JSON
*/

@@ -84,4 +84,4 @@ const mergeFlowJSONs = value => Array.isArray(value) ? mergeDeep({}, ...value) : value;

* @description Filter out contracts section of flow.json.
* @param {object|object[]} obj - Flow JSON or array of Flow JSONs
* @returns {object} - Contracts section of Flow JSON
* @param obj - Flow JSON
* @returns Contracts section of Flow JSON
*/

@@ -92,4 +92,4 @@ const filterContracts = obj => obj.contracts ? obj.contracts : {};

* @description Gathers contract addresses by network
* @param {string} network - Network to gather addresses for
* @returns {object} - Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
* @param network - Network to gather addresses for
* @returns Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
*/

@@ -131,5 +131,5 @@ const mapContractAliasesToNetworkAddress = network => contracts => {

* @description Take in flow.json files and return contract to address mapping by network
* @param {object|object[]} jsons - Flow JSON or array of Flow JSONs
* @param {string} network - Network to gather addresses for
* @returns {object} - Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
* @param jsons - Flow JSON or array of Flow JSONs
* @param network - Network to gather addresses for
* @returns Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
*/

@@ -142,4 +142,4 @@ const getContracts = (jsons, network) => {

* @description Checks if string is hexidecimal
* @param {string} str - String to check
* @returns {boolean} - Is hexidecimal status
* @param str - String to check
* @returns Is hexidecimal status
*/

@@ -154,10 +154,10 @@ const isHexidecimal = str => {

* @description Checks flow.json file for private keys
* @param {object} flowJSON - Flow JSON
* @returns {boolean} - Has private keys status
* @param flowJSON - Flow JSON
* @returns Has private keys status
*/
const hasPrivateKeys = flowJSON => {
return Object.entries(flowJSON?.accounts).reduce((hasPrivateKey, _ref4) => {
let [key, value] = _ref4;
return Object.entries(flowJSON?.accounts ?? []).reduce((hasPrivateKey, _ref4) => {
let [, value] = _ref4;
if (hasPrivateKey) return true;
return value?.hasOwnProperty("key") && isHexidecimal(value?.key);
return value && Object.prototype.hasOwnProperty.call(value, "key") && isHexidecimal(value?.key);
}, false);

@@ -168,8 +168,8 @@ };

* @description Take in flow.json or array of flow.json files and checks for private keys
* @param {object|object[]} value - Flow JSON or array of Flow JSONs
* @returns {boolean} - Has private keys status
* @param value - Flow JSON or array of Flow JSONs
* @returns Has private keys status
*/
const anyHasPrivateKeys = value => {
if (isObject(value)) return hasPrivateKeys(value);
return value.some(hasPrivateKeys);
if (Array.isArray(value)) return value.some(hasPrivateKeys);
return hasPrivateKeys(value);
};

@@ -179,7 +179,13 @@

* @description Format network to always be 'emulator', 'testnet', or 'mainnet'
* @param {string} network - Network to format
* @returns {string} - Formatted network name (either 'emulator', 'testnet', or 'mainnet')
* @param network - Network to format
* @returns Formatted network name (either 'emulator', 'testnet', or 'mainnet')
*/
const cleanNetwork = network => network?.toLowerCase() === "local" ? "emulator" : network?.toLowerCase();
const cleanNetwork = network => {
const cleanedNetwork = network?.toLowerCase() === "local" ? "emulator" : network?.toLowerCase();
if (cleanedNetwork === "emulator" || cleanedNetwork === "testnet" || cleanedNetwork === "mainnet") return cleanedNetwork;
throw new Error(`Invalid network "${network}". Must be one of "emulator", "local", "testnet", or "mainnet"`);
};
// Inject config into logger to break circular dependency
logger.setConfig(config);
const NAME = "config";

@@ -241,5 +247,5 @@ const PUT = "PUT_CONFIG";

},
[CLEAR]: (ctx, letter) => {
let keys = Object.keys(ctx.all());
for (let key of keys) ctx.delete(key);
[CLEAR]: ctx => {
const keys = Object.keys(ctx.all());
for (const key of keys) ctx.delete(key);
ctx.broadcast(UPDATED, {

@@ -270,5 +276,5 @@ ...ctx.all()

* @description Adds a key-value pair to the config
* @param {string} key - The key to add
* @param {*} value - The value to add
* @returns {Promise<object>} - The current config
* @param key - The key to add
* @param value - The value to add
* @returns The config object
*/

@@ -285,5 +291,5 @@ function put(key, value) {

* @description Gets a key-value pair with a fallback from the config
* @param {string} key - The key to add
* @param {*} [fallback] - The fallback value to return if key is not found
* @returns {Promise<*>} - The value found at key or fallback
* @param key - The key to add
* @param fallback - The fallback value to return if key is not found
* @returns The value found at key or fallback
*/

@@ -302,5 +308,5 @@ function get(key, fallback) {

* @description Returns the first non null config value or the fallback
* @param {string[]} wants - The keys to search for
* @param {*} fallback - The fallback value to return if key is not found
* @returns {Promise<*>} - The value found at key or fallback
* @param wants - The keys to search for
* @param fallback - The fallback value to return if key is not found
* @returns The value found at key or fallback
*/

@@ -319,3 +325,3 @@ async function first() {

* @description Returns the current config
* @returns {Promise<object>} - The current config
* @returns The config object
*/

@@ -331,5 +337,5 @@ function all() {

* @description Updates a key-value pair in the config
* @param {string} key - The key to update
* @param {Function} fn - The function to update the value with
* @returns {Promise<object>} - The current config
* @param key - The key to update
* @param fn - The function to update the value with
* @returns The config object
*/

@@ -347,4 +353,4 @@ function update(key) {

* @description Deletes a key-value pair from the config
* @param {string} key - The key to delete
* @returns {Promise<object>} - The current config
* @param key - The key to delete
* @returns The config object
*/

@@ -360,4 +366,4 @@ function _delete(key) {

* @description Returns a subset of the config based on a pattern
* @param {string} pattern - The pattern to match keys against
* @returns {Promise<object>} - The subset of the config
* @param pattern - The pattern to match keys against
* @returns The subset of the config
*/

@@ -375,4 +381,4 @@ function where(pattern) {

* @description Subscribes to config updates
* @param {Function} callback - The callback to call when config is updated
* @returns {Function} - The unsubscribe function
* @param callback - The callback to call when config is updated
* @returns The unsubscribe function
*/

@@ -385,6 +391,5 @@ function subscribe(callback) {

* @description Clears the config
* @returns {void}
*/
function clearConfig() {
return send(NAME, CLEAR);
async function clearConfig() {
await send(NAME, CLEAR);
}

@@ -394,7 +399,7 @@

* @description Resets the config to a previous state
* @param {object} oldConfig - The previous config state
* @returns {Promise<object>} - The current config
* @param oldConfig - The previous config state
* @returns The config object
*/
function resetConfig(oldConfig) {
return clearConfig().then(config(oldConfig));
async function resetConfig(oldConfig) {
return clearConfig().then(() => config(oldConfig));
}

@@ -404,4 +409,4 @@

* @description Takes in flow.json or array of flow.json files and creates contract placeholders
* @param {object|object[]} data - The flow.json or array of flow.json files
* @returns {void}
* @param data - The data to load
* @param data.flowJSON - The flow.json or array of flow.json files
*/

@@ -415,3 +420,3 @@ async function load(data) {

invariant(Boolean(flowJSON), "config.load -- 'flowJSON' must be defined");
invariant(cleanedNetwork, `Flow Network Required -- In order for FCL to load your contracts please define "flow.network" to "emulator", "local", "testnet", or "mainnet" in your config. See more here: https://developers.flow.com/tools/fcl-js/reference/configure-fcl`);
invariant(!!cleanedNetwork, `Flow Network Required -- In order for FCL to load your contracts please define "flow.network" to "emulator", "local", "testnet", or "mainnet" in your config. See more here: https://developers.flow.com/tools/fcl-js/reference/configure-fcl`);
if (anyHasPrivateKeys(flowJSON)) {

@@ -452,6 +457,6 @@ const isEmulator = cleanedNetwork === "emulator";

// eslint-disable-next-line jsdoc/require-returns
/**
* @description Sets the config
* @param {object} [values] - The values to set
* @param values - The values to set
* @returns The config object
*/

@@ -485,18 +490,18 @@ function config(values) {

config.load = load;
const noop = v => v;
function overload() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
return new Promise(async (resolve, reject) => {
const oldConfig = await all();
try {
config(opts);
var result = await callback(await all());
await resetConfig(oldConfig);
resolve(result);
} catch (error) {
await resetConfig(oldConfig);
reject(error);
}
});
/**
* @description Temporarily overloads the config with the given values and calls the callback
* @param values - The values to overload the config with
* @param callback - The callback to call with the overloaded config
* @returns The result of the callback
*/
async function overload(values, callback) {
const oldConfig = await all();
try {
config(values);
const result = await callback(await all());
return result;
} finally {
await resetConfig(oldConfig);
}
}

@@ -503,0 +508,0 @@

@@ -40,4 +40,4 @@ (function (global, factory) {

* Merge multiple functions returning objects into one object.
* @param {...function(*): object} funcs - Functions to merge
* @return {object} - Merged object
* @param funcs - Functions to merge
* @return Merged object
*/

@@ -60,4 +60,4 @@ const mergePipe = function () {

* @description Object check
* @param {*} value - Value to check
* @returns {boolean} - Is object status
* @param value - Value to check
* @returns Is object status
*/

@@ -68,5 +68,5 @@ const isObject = value => value && typeof value === "object" && !Array.isArray(value);

* @description Deep merge multiple objects.
* @param {object} target - Target object
* @param {...object[]} sources - Source objects
* @returns {object} - Merged object
* @param target - Target object
* @param sources - Source objects
* @returns Merged object
*/

@@ -98,4 +98,4 @@ const mergeDeep = function (target) {

* @description Deep merge multiple Flow JSON.
* @param {object|object[]} value - Flow JSON or array of Flow JSONs
* @returns {object} - Merged Flow JSON
* @param value - Flow JSON or array of Flow JSONs
* @returns Merged Flow JSON
*/

@@ -106,4 +106,4 @@ const mergeFlowJSONs = value => Array.isArray(value) ? mergeDeep({}, ...value) : value;

* @description Filter out contracts section of flow.json.
* @param {object|object[]} obj - Flow JSON or array of Flow JSONs
* @returns {object} - Contracts section of Flow JSON
* @param obj - Flow JSON
* @returns Contracts section of Flow JSON
*/

@@ -114,4 +114,4 @@ const filterContracts = obj => obj.contracts ? obj.contracts : {};

* @description Gathers contract addresses by network
* @param {string} network - Network to gather addresses for
* @returns {object} - Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
* @param network - Network to gather addresses for
* @returns Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
*/

@@ -153,5 +153,5 @@ const mapContractAliasesToNetworkAddress = network => contracts => {

* @description Take in flow.json files and return contract to address mapping by network
* @param {object|object[]} jsons - Flow JSON or array of Flow JSONs
* @param {string} network - Network to gather addresses for
* @returns {object} - Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
* @param jsons - Flow JSON or array of Flow JSONs
* @param network - Network to gather addresses for
* @returns Contract names by addresses mapping e.g { "HelloWorld": "0x123" }
*/

@@ -164,4 +164,4 @@ const getContracts = (jsons, network) => {

* @description Checks if string is hexidecimal
* @param {string} str - String to check
* @returns {boolean} - Is hexidecimal status
* @param str - String to check
* @returns Is hexidecimal status
*/

@@ -176,10 +176,10 @@ const isHexidecimal = str => {

* @description Checks flow.json file for private keys
* @param {object} flowJSON - Flow JSON
* @returns {boolean} - Has private keys status
* @param flowJSON - Flow JSON
* @returns Has private keys status
*/
const hasPrivateKeys = flowJSON => {
return Object.entries(flowJSON?.accounts).reduce((hasPrivateKey, _ref4) => {
let [key, value] = _ref4;
return Object.entries(flowJSON?.accounts ?? []).reduce((hasPrivateKey, _ref4) => {
let [, value] = _ref4;
if (hasPrivateKey) return true;
return value?.hasOwnProperty("key") && isHexidecimal(value?.key);
return value && Object.prototype.hasOwnProperty.call(value, "key") && isHexidecimal(value?.key);
}, false);

@@ -190,8 +190,8 @@ };

* @description Take in flow.json or array of flow.json files and checks for private keys
* @param {object|object[]} value - Flow JSON or array of Flow JSONs
* @returns {boolean} - Has private keys status
* @param value - Flow JSON or array of Flow JSONs
* @returns Has private keys status
*/
const anyHasPrivateKeys = value => {
if (isObject(value)) return hasPrivateKeys(value);
return value.some(hasPrivateKeys);
if (Array.isArray(value)) return value.some(hasPrivateKeys);
return hasPrivateKeys(value);
};

@@ -201,7 +201,13 @@

* @description Format network to always be 'emulator', 'testnet', or 'mainnet'
* @param {string} network - Network to format
* @returns {string} - Formatted network name (either 'emulator', 'testnet', or 'mainnet')
* @param network - Network to format
* @returns Formatted network name (either 'emulator', 'testnet', or 'mainnet')
*/
const cleanNetwork = network => network?.toLowerCase() === "local" ? "emulator" : network?.toLowerCase();
const cleanNetwork = network => {
const cleanedNetwork = network?.toLowerCase() === "local" ? "emulator" : network?.toLowerCase();
if (cleanedNetwork === "emulator" || cleanedNetwork === "testnet" || cleanedNetwork === "mainnet") return cleanedNetwork;
throw new Error(`Invalid network "${network}". Must be one of "emulator", "local", "testnet", or "mainnet"`);
};
// Inject config into logger to break circular dependency
logger__namespace.setConfig(config);
const NAME = "config";

@@ -263,5 +269,5 @@ const PUT = "PUT_CONFIG";

},
[CLEAR]: (ctx, letter) => {
let keys = Object.keys(ctx.all());
for (let key of keys) ctx.delete(key);
[CLEAR]: ctx => {
const keys = Object.keys(ctx.all());
for (const key of keys) ctx.delete(key);
ctx.broadcast(UPDATED, {

@@ -292,5 +298,5 @@ ...ctx.all()

* @description Adds a key-value pair to the config
* @param {string} key - The key to add
* @param {*} value - The value to add
* @returns {Promise<object>} - The current config
* @param key - The key to add
* @param value - The value to add
* @returns The config object
*/

@@ -307,5 +313,5 @@ function put(key, value) {

* @description Gets a key-value pair with a fallback from the config
* @param {string} key - The key to add
* @param {*} [fallback] - The fallback value to return if key is not found
* @returns {Promise<*>} - The value found at key or fallback
* @param key - The key to add
* @param fallback - The fallback value to return if key is not found
* @returns The value found at key or fallback
*/

@@ -324,5 +330,5 @@ function get(key, fallback) {

* @description Returns the first non null config value or the fallback
* @param {string[]} wants - The keys to search for
* @param {*} fallback - The fallback value to return if key is not found
* @returns {Promise<*>} - The value found at key or fallback
* @param wants - The keys to search for
* @param fallback - The fallback value to return if key is not found
* @returns The value found at key or fallback
*/

@@ -341,3 +347,3 @@ async function first() {

* @description Returns the current config
* @returns {Promise<object>} - The current config
* @returns The config object
*/

@@ -353,5 +359,5 @@ function all() {

* @description Updates a key-value pair in the config
* @param {string} key - The key to update
* @param {Function} fn - The function to update the value with
* @returns {Promise<object>} - The current config
* @param key - The key to update
* @param fn - The function to update the value with
* @returns The config object
*/

@@ -369,4 +375,4 @@ function update(key) {

* @description Deletes a key-value pair from the config
* @param {string} key - The key to delete
* @returns {Promise<object>} - The current config
* @param key - The key to delete
* @returns The config object
*/

@@ -382,4 +388,4 @@ function _delete(key) {

* @description Returns a subset of the config based on a pattern
* @param {string} pattern - The pattern to match keys against
* @returns {Promise<object>} - The subset of the config
* @param pattern - The pattern to match keys against
* @returns The subset of the config
*/

@@ -397,4 +403,4 @@ function where(pattern) {

* @description Subscribes to config updates
* @param {Function} callback - The callback to call when config is updated
* @returns {Function} - The unsubscribe function
* @param callback - The callback to call when config is updated
* @returns The unsubscribe function
*/

@@ -407,6 +413,5 @@ function subscribe(callback) {

* @description Clears the config
* @returns {void}
*/
function clearConfig() {
return utilActor.send(NAME, CLEAR);
async function clearConfig() {
await utilActor.send(NAME, CLEAR);
}

@@ -416,7 +421,7 @@

* @description Resets the config to a previous state
* @param {object} oldConfig - The previous config state
* @returns {Promise<object>} - The current config
* @param oldConfig - The previous config state
* @returns The config object
*/
function resetConfig(oldConfig) {
return clearConfig().then(config(oldConfig));
async function resetConfig(oldConfig) {
return clearConfig().then(() => config(oldConfig));
}

@@ -426,4 +431,4 @@

* @description Takes in flow.json or array of flow.json files and creates contract placeholders
* @param {object|object[]} data - The flow.json or array of flow.json files
* @returns {void}
* @param data - The data to load
* @param data.flowJSON - The flow.json or array of flow.json files
*/

@@ -437,3 +442,3 @@ async function load(data) {

utilInvariant.invariant(Boolean(flowJSON), "config.load -- 'flowJSON' must be defined");
utilInvariant.invariant(cleanedNetwork, `Flow Network Required -- In order for FCL to load your contracts please define "flow.network" to "emulator", "local", "testnet", or "mainnet" in your config. See more here: https://developers.flow.com/tools/fcl-js/reference/configure-fcl`);
utilInvariant.invariant(!!cleanedNetwork, `Flow Network Required -- In order for FCL to load your contracts please define "flow.network" to "emulator", "local", "testnet", or "mainnet" in your config. See more here: https://developers.flow.com/tools/fcl-js/reference/configure-fcl`);
if (anyHasPrivateKeys(flowJSON)) {

@@ -474,6 +479,6 @@ const isEmulator = cleanedNetwork === "emulator";

// eslint-disable-next-line jsdoc/require-returns
/**
* @description Sets the config
* @param {object} [values] - The values to set
* @param values - The values to set
* @returns The config object
*/

@@ -507,18 +512,18 @@ function config(values) {

config.load = load;
const noop = v => v;
function overload() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
return new Promise(async (resolve, reject) => {
const oldConfig = await all();
try {
config(opts);
var result = await callback(await all());
await resetConfig(oldConfig);
resolve(result);
} catch (error) {
await resetConfig(oldConfig);
reject(error);
}
});
/**
* @description Temporarily overloads the config with the given values and calls the callback
* @param values - The values to overload the config with
* @param callback - The callback to call with the overloaded config
* @returns The result of the callback
*/
async function overload(values, callback) {
const oldConfig = await all();
try {
config(values);
const result = await callback(await all());
return result;
} finally {
await resetConfig(oldConfig);
}
}

@@ -525,0 +530,0 @@

{
"name": "@onflow/config",
"version": "1.2.0-alpha.0",
"version": "1.3.0-typescript.0",
"description": "Config for FCL-JS",

@@ -16,19 +16,25 @@ "license": "Apache-2.0",

"devDependencies": {
"@babel/preset-typescript": "^7.22.11",
"@onflow/fcl-bundle": "^1.4.0-alpha.0",
"@types/estree": "^1.0.1",
"@types/jest": "^29.5.4",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"eslint": "^8.48.0",
"eslint-plugin-jsdoc": "^46.5.1",
"jest": "^29.5.0",
"typescript": "^4.9.5"
},
"source": "src/config.js",
"source": "src/config.ts",
"main": "dist/config.js",
"module": "dist/config.module.js",
"unpkg": "dist/config.umd.js",
"types": "types/src/config.d.ts",
"types": "dist/config.d.ts",
"scripts": {
"prepublishOnly": "npm test && npm run build",
"test": "jest",
"build": "tsc && npm run lint && fcl-bundle",
"build": "npm run lint && fcl-bundle",
"test:watch": "jest --watch",
"start": "fcl-bundle --watch",
"lint": "eslint ."
"lint": "eslint src"
},

@@ -38,2 +44,4 @@ "dependencies": {

"@onflow/util-actor": "^1.3.0-alpha.0",
"@onflow/util-invariant": "^1.2.0-alpha.0",
"@onflow/util-logger": "^1.3.0-alpha.0",
"eslint": "^8.34.0",

@@ -40,0 +48,0 @@ "eslint-plugin-jsdoc": "^40.0.0"

@@ -9,4 +9,4 @@ {

// next to the .js files
"outDir": "types",
"outDir": "types"
}
}
}

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 not supported yet

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