1.0.0 • Published 5 months ago

loanshub-shared v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

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

  1. Use salestrekker enums where possible. Eg the applicant's title field would use the salestrekker enum value as they are 1:1 mapped.
  2. 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:

  1. Make your changes to the models
  2. Run npm run build so that dependant projects can refer to these new models
  3. 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 build script calls npm run pack-loanshub-shared
  • the update-models script repacks the dependency and reinstalls from the package
  • the dependency for loanshub-shared is a .tgz file 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: keep
  • It may generate some enums with a dodgy enum that's REALLY long, you'll need to prune these before building

  • Then build the shared project and run update-models in the functions project, and resolve any typescript issues

1.0.0

5 months ago