minauth
Version:
A TypeScript library for building authentication systems on top of the Mina blockchain and other zero-knowledge proofs solutions.
35 lines • 1.61 kB
JavaScript
import { pipe } from 'fp-ts/lib/function.js';
import * as RTE from 'fp-ts/lib/ReaderTaskEither.js';
import * as R from 'fp-ts/lib/Record.js';
import { launchTE } from '../utils/fp/taskeither.js';
/**
* Use the plugin runtime logger.
*/
export const useLogger = (f) => pipe(askLogger(), RTE.chain((logger) => RTE.fromIO(() => f(logger))));
/**
* Get the plugin runtime logger instance.
*/
export const askLogger = () => RTE.asks(({ logger }) => logger);
/**
* Get all active plugin instances.
*/
export const askActivePlugins = () => RTE.asks(({ plugins }) => plugins);
/**
* Get a running plugin instance by its name.
*/
export const askPluginInstance = (pluginName) => pipe(RTE.Do, RTE.bind('plugins', () => askActivePlugins()), RTE.let('activePluginNames', ({ plugins }) => Object.keys(plugins)), RTE.chain(({ plugins, activePluginNames }) => RTE.fromOption(() => `plugin ${pluginName} not found. Available plugins ${activePluginNames}`)(R.lookup(pluginName)(plugins))));
export const askActivePluginNames = () => pipe(RTE.Do, RTE.bind('plugins', () => askActivePlugins()), RTE.map(({ plugins }) => Object.keys(plugins)));
/**
* Get the plugin runtime environment.
*/
export const askPluginRuntimeEnv = () => RTE.ask();
/**
* Launch a plugin runtime action as a TS promise.
*/
export const launchPluginRuntime = (env) => (a) => launchTE(a(env));
/**
* Tap into the error of a plugin runtime action and log it with
* an additional note.
*/
export const tapAndLogError = (note) => RTE.tapError((err) => useLogger((logger) => logger.error(note, err)));
//# sourceMappingURL=pluginruntime.js.map