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

@onflow/config

Package Overview
Dependencies
Maintainers
7
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/config

A mechanism for configuring the Flow JS SDK and FCL

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18K
increased by17.19%
Maintainers
7
Weekly downloads
 
Created
Source

@onflow/config

Reactive configuration for Flow JS SDK and FCL

Status

  • Status Last Updated: July 17th 2020
  • Stable: Yes
  • Risk of Breaking Change: Low

Overview

  • Install
  • Usage
  • Configurations

Install

npm install --save @onflow/config

Usage

import {config} from "@onflow/config"

// Reactively subscribe to config changes
config().subscribe(configData => console.log("CONFIG", configData))

// Set a config value
config().put("foo", "bar")

// .put can be chained
config()
  .put("foo", "bar")
  .put("baz", "rawr")

// Get a config value (its async)
var configValue = await config().get("woot")
console.log(configValue) // undefined

// A fallback can be supplied for .get
var configValue = await config().get("woot", "fallback")
console.log(configValue) // "fallback"

config.put("woot", "woot")
var configValue = await config().get("woot", "fallback")
console.log(configValue) // "woot"

// Update a config value
config().put("count", 1)
var count = await config().get("count", 0)
console.log(count) // 1

config().update("count", oldValue => oldValue + 1)
var count = await config().get("count", 0)
console.log(count) // 2

// Delete a config value
config().delete("woot")
var configValue = await config().get("woot", "fallback")
console.log(configValue) // "fallback"

// Configs that match a pattern
config()
  .put("scope.A", 1)
  .put("scope.B", 1)

var scopeValues = await config().where(/^scope\.\s+/)
console.log(scopeValues) // { "scope.A": 1, "scope.B": 2 }

Configurations

Known configuration values in FCL

Access Node

  • accessNode.api (default: emulator url) -- Where FCL will used to communicate with the Flow blockchain.
  • accessNode.key (default: null) -- Some Access Nodes require an api key.
import {config} from "@onflow/config"

if (process.env.NODE_ENV === "production") {
  config()
    .put("accessNode.api", process.env.ACCESS_NODE_API)
    .put("accessNode.key", process.env.ACCESS_NODE_KEY)
}

Decode

See fcl.decode for more details on decode.

decoder.* -- Custom decoders for parsing JSON-CDC

import {config} from "@onflow/config"
import * as fcl from "@onflow/fcl"

function Woot({x, y}) {
  this.x = x
  this.y = y
}

config().put("decoder.Woot", woot => new Woot(woot))

var response = await fcl.send([
  fcl.script`
    pub struct Woot {
      pub var x: Int
      pub var y: Int

      init(x: Int, y: Int) {
        self.x = x
        self.y = y
      }
    }

    pub fun main(): [Woot] {
      return [Woot(x: 1, y: 2), Woot(x: 3, y: 4), Woot(x: 5, y: 6)]
    }
  `,
])

var data = await fcl.decode(response)
console.log(data) // [ Woot{x:1, y:2}, Woot{x:3, y:4}, Woot{x:5, y:6} ]

Wallets

See fcl.currentUser for more details on authentication.

challenge.handshake (default: FCL wallet discovery service url) -- Where FCL will attempt to authenticate

import {config} from "@onflow/config"

if (process.env.NODE_ENV === "development") {
  // Use dev wallet during development
  config().put("challenge.handshake", "http://localhost:8701/flow/authenticate")
}

FAQs

Package last updated on 13 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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