loanshub-shared
v1.0.0
Published
shared package for loanshub
Readme
loansHub Shared
Purpose
I want to share typescript models between backend and frontend to reduce complexity and errors.
How to think about shared models
Priorities
- Use salestrekker enums where possible. Eg the applicant's
titlefield would use the salestrekker enum value as they are 1:1 mapped. - If the value doesn't flow through to salestrekker, export the enum from the App directory instead.
Applying changes to Models
In the shared project:
- Make your changes to the models
- Run
npm run buildso that dependant projects can refer to these new models - Projects that bundle this dependency (eg
functions) need to re-pack their bundle, and then re-install this new bundle
Depending on this project
Web applications can simply import these models, but Firebase functions that depend on this project need a bit more work.
Firebase functions
The Google Cloud platform downloads your dependencies from npm when functions are deployed, but the loanshub-shared module only exists locally and isn't accessible.
So we package the module at build-time so that its included in the deployment, and we tell the project to use this packaged dependency rather than the local one.
Notice in the functions project's package.json:
- the
buildscript callsnpm run pack-loanshub-shared - the
update-modelsscript repacks the dependency and reinstalls from the package - the dependency for
loanshub-sharedis a.tgzfile rather than a package name
When the functions project builds, pack-loanshub-shared is called to package up the loanshub-shared module in the ./shared directory into a .tgz file, so that the local dependency is uploaded to the cloud when deploying.
Salestrekker Typings
To update Salestrekker typings after an API update on their side:
Download the GraphQL schema from the salestrekker API playground
Then use this tool to convert to Typescript with the following config:
generates:
types.ts:
plugins:
- typescript
config:
skipTypename: true
namingConvention: keepIt may generate some enums with a dodgy enum that's REALLY long, you'll need to prune these before building
Then build the
sharedproject and runupdate-modelsin thefunctionsproject, and resolve any typescript issues
