UNPKG

@windingtree/wt-write-api

Version:

API to write data to the Winding Tree platform

73 lines (66 loc) 2.12 kB
const winston = require('winston'); const YAML = require('yamljs'); const { WtJsLibs } = require('@windingtree/wt-js-libs'); const SwarmAdapter = require('@windingtree/off-chain-adapter-swarm'); const HttpAdapter = require('@windingtree/off-chain-adapter-http'); const InMemoryAdapter = require('@windingtree/off-chain-adapter-in-memory'); const env = process.env.WT_CONFIG || 'dev'; const getSchemaVersion = (packageName) => { const refDef = YAML.load(`node_modules/${packageName}/dist/swagger.yaml`); return refDef.info.version; }; const config = Object.assign({ logger: winston.createLogger({ level: process.env.LOG_LEVEL || 'info', transports: [ new winston.transports.Console({ format: winston.format.simple(), stderrLevels: ['error'], }), ], }), // Limit allowed uploaders to prevent dummy uploaders // from being used in production. allowedUploaders: ['s3', 'swarm'], baseUrl: process.env.BASE_URL || 'http://localhost:8000', port: process.env.PORT || 8000, // Data format version to which all validations and data structuring conform. dataFormatVersions: { hotels: getSchemaVersion('@windingtree/wt-hotel-schemas'), orgJson: getSchemaVersion('@windingtree/wt-organization-schemas'), }, }, require(`./${env}`)); config.wtLibs = WtJsLibs.createInstance({ onChainDataOptions: { provider: config.ethereumProvider, }, offChainDataOptions: { adapters: { 'in-memory': { create: (options) => { return new InMemoryAdapter(options); }, }, 'bzz-raw': { options: { swarmProviderUrl: config.swarm.provider, timeout: config.swarm.timeout, timeoutRead: config.swarm.timeoutRead, timeoutWrite: config.swarm.timeoutWrite, }, create: (options) => { return new SwarmAdapter(options); }, }, https: { create: () => { return new HttpAdapter(); }, }, }, }, }); if (!config.ethereumProvider) { throw new Error('ETH_NETWORK_PROVIDER not set'); } module.exports = config;