Skip to content

Commit

Permalink
Get the build working
Browse files Browse the repository at this point in the history
  • Loading branch information
mividtim committed Apr 4, 2024
1 parent 0ed5ac5 commit 8b52d32
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 93 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"scripts": {
"clean": "del dist",
"build": "tsc .",
"build": "tsc --project ./",
"rebuild": "yarn clean && yarn build",
"start": "yarn start",
"start:dev": "NODE_OPTIONS='--trace-warnings --require tsconfig-paths/register' nodemon src/index.ts | pjl"
Expand All @@ -38,6 +38,7 @@
"zod": "^3.22.2"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@types/json-stringify-safe": "^5.0.3",
"@types/luxon": "^3.4.2",
"del-cli": "^5.1.0",
Expand Down
67 changes: 3 additions & 64 deletions render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,16 @@ envVarGroups:
# separate configurable option, so they can be changed independent of the environment
- key: NODE_ENV
value: production
- key: API_CLIENT_BEARER_TOKEN
generateValue: true
- key: PROOF_WEBHOOK_BEARER_TOKEN
generateValue: true
- key: VALIDATION_BEARER_TOKEN
generateValue: true
# Staging Environment
- name: fabrica-staging
envVars:
# No code should directly reference this, except for reporting purposes (e.g. logging) and cache keys
# (since every release stage shares a cache, and sometimes you want to cache things separately per
# release stage, e.g. to track if an email was sent). Instead, env vars should be created for each
# separate configurable option, so they can be changed independent of the environment
- key: NODE_ENV
value: staging
- key: API_CLIENT_BEARER_TOKEN
generateValue: true
- key: PROOF_WEBHOOK_BEARER_TOKEN
generateValue: true
- key: VALIDATION_BEARER_TOKEN
generateValue: true

services:
# Production Services
- type: redis
name: bullmq-production
plan: standard
region: oregon
maxmemoryPolicy: noeviction
ipAllowList:
- source: 0.0.0.0/0
description: everywhere
- type: web
name: fabrica-v3
env: node
plan: standard
region: oregon
domains:
- media3.fabrica.land
- metadata.fabrica.land
repo: https://github.com/fabrica-land/fabrica-v3-api
branch: prod
healthCheckPath: /
buildCommand: 'yarn ci'
startCommand: 'yarn start'
autoDeploy: true
envVars:
- key: APP_CACHE_URL
fromService:
type: redis
name: redis-starter
property: connectionString
- key: DB_CONN_STRING
fromDatabase:
name: fabrica-db
property: connectionString
- key: QUEUE_URL
fromService:
type: redis
name: bullmq-production
property: connectionString
- fromGroup: fabrica
- fromGroup: fabrica-secrets-production
- type: worker
name: worker-production
name: loan-offer-bot
env: node
region: oregon
repo: https://github.com/fabrica-land/fabrica-v3-api
branch: prod
buildCommand: 'yarn ci'
startCommand: 'yarn worker'
buildCommand: 'yarn && yarn build'
startCommand: 'yarn start'
autoDeploy: true
envVars:
- key: APP_CACHE_URL
Expand Down
9 changes: 5 additions & 4 deletions src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StatusCodes } from 'http-status-codes'
import stringify from 'json-stringify-safe'

import { ErrorLike } from './types/error-like'
import { asErrorLike, ErrorLike } from './types/error-like'
import { ErrorWithCause } from './types/error-with-cause'

const DEFAULT_TIMEOUT_MILLIS = 60_000
Expand Down Expand Up @@ -62,7 +62,7 @@ export const fetchOrThrow = async (
responseBody: undefined,
},
)
throw new FetchError(message, url, 0, statusText, undefined, error)
throw new FetchError(message, url, 0, statusText, undefined, asErrorLike(error))
} finally {
clearTimeout(timeout)
}
Expand All @@ -84,13 +84,14 @@ export const fetchOrThrow = async (
'Error processing result of fetch request',
{ err, options, url, responseType, response, body: response.body },
)
const error = asErrorLike(err)
throw new FetchError(
err.message,
error.message,
url,
response.status,
response.statusText,
response.body,
err,
error,
)
}
if (
Expand Down
17 changes: 8 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import { BigNumber } from 'ethers'
const WAIT_FOR_ESTIMATED_VALUE_SECONDS = 10

class FabricaLoanBot {
private blockchain: Blockchain
private config: Config
private fabrica: Fabrica
private nftfi: Nftfi
private readonly blockchain: Blockchain
private readonly config: Config
private readonly fabrica: Fabrica
private readonly nftfi: Nftfi

public readonly start = async () => {
this.config = await getConfig()
constructor(config: Config) {
this.config = config
this.blockchain = new Blockchain(this.config)
this.fabrica = new Fabrica(this.blockchain, this.config)
this.fabrica.addMintListener(this.processMint)
this.nftfi = new Nftfi(this.blockchain, this.config)
this.fabrica.addMintListener(this.processMint)
}

private readonly processMint = async (
Expand Down Expand Up @@ -142,5 +142,4 @@ class FabricaLoanBot {
Math.ceil(DateTime.utc().plus(duration).diffNow().as('seconds'))
}

const bot = new FabricaLoanBot()
void bot.start()
const bot = new FabricaLoanBot(getConfig())
15 changes: 7 additions & 8 deletions src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import SecureJson from 'secure-json-parse'
import * as fs from 'node:fs'
import * as asyncFs from 'node:fs/promises'
import { z } from 'zod'
import { NetworkConfig } from './network.config'
import { SerializableObject } from './serializable'
Expand Down Expand Up @@ -29,7 +28,7 @@ export const Config = z.object({
})
export type Config = z.infer<typeof Config>

export const loadFile = async (fileName: NonEmptyString, required = false): Promise<SerializableObject> => {
export const loadFile = (fileName: NonEmptyString, required = false): SerializableObject => {
let fullPath = path.resolve(__dirname, '..', '..', 'config', fileName)
if (!fs.existsSync(fullPath)) {
fullPath = path.resolve(__dirname, '..', '..', fileName)
Expand All @@ -42,7 +41,7 @@ export const loadFile = async (fileName: NonEmptyString, required = false): Prom
}
}
try {
const content = await asyncFs.readFile(fullPath, { encoding: 'utf-8' })
const content = fs.readFileSync(fullPath, { encoding: 'utf-8' })
const json = SecureJson.parse(content)
return SerializableObject.parse(json)
} catch (err) {
Expand All @@ -56,15 +55,15 @@ export const loadFile = async (fileName: NonEmptyString, required = false): Prom
}
}

export const getConfig = async (): Promise<Config> => {
export const getConfig = (): Config => {
const localEnvConfig: Partial<Config> = {
nodeEnv: process.env.NODE_ENV || `local:{${os.hostname()}}`,
}
const nodeEnv = process.env.NODE_ENV || DEVELOP_ENV
const nodeEnvConfig = await loadFile(`${nodeEnv}.config.json`, true)
const nodeEnvSecrets = await loadFile(`${nodeEnv}.secrets.json`, true)
const localConfig = await loadFile('local.config.json', nodeEnv === DEVELOP_ENV)
const localSecrets = await loadFile('local.secrets.json', nodeEnv === DEVELOP_ENV)
const nodeEnvConfig = loadFile(`${nodeEnv}.config.json`, true)
const nodeEnvSecrets = loadFile(`${nodeEnv}.secrets.json`, true)
const localConfig = loadFile('local.config.json', nodeEnv === DEVELOP_ENV)
const localSecrets = loadFile('local.secrets.json', nodeEnv === DEVELOP_ENV)
const config = merge(
{},
localEnvConfig,
Expand Down
4 changes: 3 additions & 1 deletion src/types/url-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export const buildUrl = (
? queryParams
: queryParams &&
Object.entries(queryParams).reduce(
// @ts-ignore
(soFar, [key, value]) => [...soFar, [key, value]],
[],
[] as Array<[string, SerializableLiteral]>,
)
const queryParamsAsArrayOfStringToString:
| Array<[string, string]>
| undefined =
queryParamsAsArrayOfArrays &&
// @ts-ignore
queryParamsAsArrayOfArrays.map((item) => [String(item[0]), String(item[1])])
const url = new URL(path, baseUrl)
if (queryParamsAsArrayOfArrays) {
Expand Down
4 changes: 0 additions & 4 deletions tsconfig.build.json

This file was deleted.

4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"extends": "@tsconfig/node20",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"baseUrl": "./src/",
"declaration": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": false,
"incremental": true,
"lib": ["ES2022"],
"module": "CommonJS",
"moduleResolution": "Node",
"noFallthroughCasesInSwitch": false,
"noImplicitAny": true,
"outDir": "./dist/",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.4.tgz#0b92dcc0cc1c81f6f306a381f28e31b1a56536e9"
integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==

"@tsconfig/node20@^20.1.4":
version "20.1.4"
resolved "https://registry.yarnpkg.com/@tsconfig/node20/-/node20-20.1.4.tgz#3457d42eddf12d3bde3976186ab0cd22b85df928"
integrity sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==

"@types/bn.js@^5.1.0", "@types/bn.js@^5.1.1":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.5.tgz#2e0dacdcce2c0f16b905d20ff87aedbc6f7b4bf0"
Expand Down

0 comments on commit 8b52d32

Please sign in to comment.