Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@bitblit/ratchet-aws

bitblit2.4kApache-2.05.1.660-alphaTypeScript support: included

Common tools for use with AWS browser and node

wrench, utility

readme

@bitblit/Ratchet

Common utilities for Typescript and Node.

Introduction

This library is very similar to my Wrench library - a set of things that I find myself doing over and over again. As Node/Typescript is a relatively new language for me in 2017/2018 (although Javascript on the client side is not), it is quite likely that there are better ways of doing things than the way I am doing them here.

You may wish to read the changelog

Coming from @bitblit/ratchet or @bitblit/epsilon?

Those libraries are the previous versions of this code before I moved to a mono-repo build process, and split the libaries to be more clear which things are usable on node-only vs usable on both node and browser. In general, packages like @bitblit/ratchet/common are now @bitblit/ratchet-common, etc. Version 4.1.106 of @bitblit/ratchet and 4.1.100 of @bitblit/epsilon are expected to be the final releases of those branches.

Installation

For example, yarn install @bitblit/ratchet-common

Usage

TBD

Barrel Files And Modular Architecture

Although I hate the import pollution, I have gradually been dragged to the belief that barrel files are an antipattern in Typescript given how much they mess up tree shaking, etc. I finally removed them entirely.

Utilities and Stuff

Daemon

The Daemon subpackage is to handle the case on AWS where you want to run a process asynchronously via Lambda (not waiting for the return on a API Gateway request) and check its results until it is finished. Daemon offers a thin wrapper around an S3 object that can be updated until it is finally replaced by the final results themselves. The end customer can be given the key to check on synchronously. Items are broken down by day (for easy flushing later) and by groups if desired.

Site Uploader

There is a tool in here called site uploader that is designed to help put completely static sites into S3 (basically a glorified aws s3 cp --recursive ...), while allowing you to set some of the more popular HTTP headers like Cache-Expires. If you use it you'll need to add this to your dev dependencies (since I didn't want it in the dependencies of Ratchet which is meant to also be used in the browser)

    "walk": "^2.3.14"

It will expect you to provide it a configuration file. I'll document it better later, but here is an example of such a configuration file (an Angular app I use, with a couple of custom HTML files with no extensions)

{
  "customMimeTypeMapping": {
    "md": "text/markdown; charset=UTF-8"
  },

  "mapping": [
    {
      "prefixMatch": "assets.*",
      "fileMatch": ".*",
      "putParams": {
        "CacheControl": "max-age=600",
        "Metadata": {}
      }
    },
    {
      "description": "Files with no extension in the root dir",
      "prefixMatch": "$",
      "fileMatch": "^([^.]+)$",
      "putParams": {
        "CacheControl": "max-age=600",
        "ContentType": "text/html; charset=UTF-8"
      }
    },
    {
      "description": "Javascript bundles in the root dir",
      "prefixMatch": "$",
      "fileMatch": ".*\\.bundle\\.js",
      "putParams": {
        "CacheControl": "max-age=86400"
      }
    },
    {
      "description": "Default rule",
      "putParams": {
        "CacheControl": "max-age=30"
      }
    }
  ]
}

Dependencies

Direct Dependencies

Since this is meant to be a very generic library, I don't want to pull in a bunch of transitive dependencies, I am keeping myself to very, very few upstream libraries. However, I am making the following exceptions, because I use these libraries in literally every project I have ever done:

  • Luxon - because I always need better date handling than what comes with Javascript (was moment before 0.12.x)

Optional Dependencies

Check out the package.json file for libraries that are optional - basically, if you wish to use the code that uses those libraries, you need to also include those libraries. Otherwise, they can be safely ignored.

AWS Library Notes

For most of my non-super-heavy-load stuff I work in us-east-1. I do this both because I am lazy and because that is where AWS releases the new stuff first. Because of this, you will see that while my code allows you to override the region, I always set a biased default. If you don't like that... sorry?

Since AWS version 3 has broken out all the services into separate libraries, there can be issues if you have libraries with different versions since they depend on different versions of the '@aws-sdk/types' library. Therefor, Ratchet when upgraded ships with the most recent version of AWS libraries that ALL the dependant libraries support, so that we don't get weird matching issues. See https://github.com/m-radzikowski/aws-sdk-client-mock/issues/10 for background if you care.

Athena

AthenaRatchet is a special case because the datasets you use with Athena tend to be so large you'll often need to work with only a chunk of them at a time. The AthenaRatchet depends on a couple more libraries that you'll need to use a chunk of the functionality - csv parses output files from Athena locally (much faster than having them do it) and tmp creates local tmp files for storage. It also uses 'fs' so, in case it's not already abundantly clear, this only works in Node, not in the browser. Not that you'd do much Athena work in the browser anyway, but I may break this up later if I see a need for that.

To use the AthenaRatchet, in addition to aws-lib you will need csv and tmp

RXJS

The Observable ratchet is based on Observables through RXJS, you'll need to install it.

Handlebars and CrossFetch

The simplified mailer for SES (aws/ses/mailer) can be provided with a remote template renderer, which assumes the template is a Handlebars template. If you use it, you'll need Handlebars (and Handlebars-Layouts, which isn't required but is highly recommended if you are doing much Handlebars work needing templates) and CrossFetch installed.

I use CrossFetch to keep Ratchet usable on both the client and server side.

ModelValidator Dependencies

Ratchet includes a helper for validating objects that match swagger schemas in the model-validator package. If you use it, you'll need to include js-yaml and swagger-model-validator.

Testing

Ha! No, seriously - all testing is done using ViTest (I moved from Jest when it became clear that it didn't support ESM well and had no intentions to anytime soon). To run them:

yarn test

Why not X? (Where X=Lodash, Underscore, Ramda, etc...)

Originally, my answer would be because I just didn't know about them. I know about them now (2019) and I use them quite a lot myself. Any code has impedence mismatches (either with the problem domain, or just with how I think about the problem) and so Ratchet is how I tackle some of these. If you think like me, Ratchet is for you! If not, it's ok - go use X. We're still friends.

Deployment

I'll write notes-to-self here on how my deployment on Github actions is actually going to work.

Following the notes from here. Important points:

  • Everything in the package that isn't in .gitignore or .npmignore gets uploaded. Review before post

  • Set a release tag and push to Github, Github actions takes care of the rest:

    git commit -m "New stuff"
    mytag release
    git push origin master --tags

Also following notes from here on converting the typescript into usable javascript+mapping stuff.

Contributing

Pull requests are welcome, although I'm not sure why you'd be interested!

Notes on ECMAScript Modules

Ratchet is now ESM only. As a former Java guy who is jealous of how well that module system was ready to go in version 1.0.2 in 1995 (!!!) I find Javascript's module system to be a wretched hive of scum and villainy, but what can you do, other than use the current best available?

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Notes]

The comments above about changelogs and semantic versioning start about 2022-09-05. I'm trying to be better about documenting things now, but earlier versions of Ratchet don't necessarily fully follow semantic versioning.

Alpha releases are exactly what they sound like - places where I am trying out new things that aren't ready for prime time, but I need published to see how they interact with the rest of my software ecosystem. If you use an alpha package without knowing why it is alpha you'll get exactly what you deserve.

[Unreleased]

  • All my work to date on making Ratchet ESM friendly is in cw/feat/esm . See the README for my current rant on the state of this

In Flight

[5.1.x]

Added

  • Acute-common module : Baseline functions and utilities for Angular
  • Acute-warden module : Utilities for using Warden with Angular
  • S3 remote file tracker (aws)
  • ArrayRatchet shuffleInPlace
  • ErrorRatchet generic error handler
  • GlobalRatchet split to handle global env vars vs global variables (needed for module-safe singletons)
  • Logger changed to module-safe singleton
  • ContextUtil (epsilon-common) changed to module-safe singleton
  • Logger RingBuffer only mode for client-side logging
  • Background task browse/launcher for the Epsilon local-container-server and local-server
  • Added 'AnonymousIfNoTokenAvailable' mode for GraphQL
  • Added a very simple local file server to node-only (a lot like 'serve' but supports HTTPS)
  • Changed

  • Upgraded a bunch of dependant libraries
  • Globally switched to for-of structure
  • General linting
  • Refactored epsilon-deployment Cloudfront Cors and HTTPS handling
  • Improved boolean param handling for sqlite

[5.0.x]

Added

  • Echarts module
  • GraphQL module
  • RDBMS module (Including SQLite support)
  • Warden modules for SimpleWebAuthn
  • Added support for Brevo email system
  • Added support for Sobol API (may remove later as it seems a dead branch)

Changed

  • Major change : Moved to monorepo, incorporated epsilon into ratchet repo
  • Moved around a lot of files to remove node-only dependencies in stuff that could be used in the browser, especially removing dependencies on buffer, node style streams and crypto library.
  • Refactored Mailer to allow configurable email systems

[4.0.x]

Added

  • Memory based sync lock implementation to simplify testing

Changed

  • Switched to AWS Library V3.x since they are now deprecating the 2.x one. This has a number of backwards incompatibilities, and I took the opportunity to clean up some API inconsistencies since it was going to be broken anyway. This version uses the AWS-preferred method of sending command objects to a more generic HTTP client, and also uses the AWS provided mock library instead of mocking everything manually with ViTest (for non-AWS stuff, Jest mocks are still used). This handles some issues with type overloading in the AWS library itself.
  • Moved most of the AWS classes into sub-folders for better organization
  • Changed StopWatch pretty significantly to always start a default timer, and remove the need for that parameter

Removed

  • Removed the DynamicImportRatchet - it didn't end up doing what I wanted, and just made Angular whine all the time

[3.2.x] - 2023-02-16

Added

  • New graphql package with the GraphQL ratchet for caching of queries and jwt token handling

    Changed

  • Updated libraries (of course)

[3.1.x] - 2023-01-25

Added

  • New 2d package with various things for handling 2d points without adding a larger library

    Changed

  • Updated libraries (of course)

[3.0.x] - 2022-12-13

Added

  • StringReadable : Adapters from string to readable
  • HandlebarsRatchet : A bunch of useful helpers
  • DynamoRatchetLike : Interface to (hopefully) allow a bit more forgiveness on varying ratchet versions
  • JwtRatchetLike : Interface to (hopefully) allow a bit more forgiveness on varying ratchet versions

    Changed

  • Changed RuntimeParametersRatchet in a backwards-incompatible way to make the datasource pluggable and overrideable
  • Adding a EnvironmentalParameters wrapper to be able to locally override a runtime params object

[2.4.x] - 2022-12-13

Changed

  • Updated dependant libraries
  • Changed minimal Node version to 16.x

[2.3.x] - 2022-12-03

Added

  • JwtRatchet gets helper methods to list time remaining in tokens

    Changed

  • DynamoRatchet refactored so that FullyExecuteScan* and FullyExecuteQuery* methods auto-recover from ProvisionedThroughputExceededException
  • DynamoRatchet refactored so that BatchWrite and BatchDelete methods auto-recover from ProvisionedThroughputExceededException
  • JwtRatchet now correctly handles malformed JWT's with exp values set in MS (this isnt allowed by the spec)

[2.2.x] - 2022-11-21

Added

  • Added JwtTokenBase to more clearly follow spec
  • Added ability for JwtRatchet to accept multiple encryption keys and select one at random
  • Changed JwtRatchet to use Epoch seconds instead of milliseconds (see https://www.rfc-editor.org/rfc/rfc7519#section-2, NumericDate)
  • Added RefreshToken ability to JwtRatchet
  • Added PrototypeDao for simple website prototyping

    Changed

  • Updated sub libraries

[2.1.x] - 2022-11-14

Added

  • Adding expiring code support

    Changed

  • Updated sub libraries

[2.0.x] - 2022-09-05

Changed

  • Changed out the cli params to use the correct node package.json approach

[1.0.x] - 2022-08-23

Added

  • New logger instances, structured logging support for AWS

    Changed

  • CSV library major version and fixes for that
  • Moved things that we're causing libraries to be sucked in via barrel.

[0.22.x] - 2022-08-10

Changed

-TBD for when I feel like doing repo diving

[0.21.x] - 2022-07-08

Changed

  • Updated libraries
  • Made backwards-incompatible change to make EnvironmentService non-static and extensible (Thanks to Bilal Shahid)

[0.20.x] - 2022-02-25

Added

  • Aws-batch-ratchet
  • Inbound-email
  • s3-cache-to-local
  • s3-location-sync
  • sync-lock
  • jwt
  • google-recaptcha ratchets

Changed

  • Updated dependant libs

[0.19.x] - 2022-02-15

Changed

  • Generic update of dependant libraries

[0.18.x] - 2022-01-25

Changed

  • Moved to github actions
  • Refactored CI settings to support both Github actions and CircleCI

[0.17.x] - 2021-11-18

Added

  • TransactionRatchet

    Changed

  • Moved/Refactored SimpleCache to use different storage tech, in a non-backwards compatible way

[0.16.x] - 2021-08-04

Changed

  • Replaced isomorphic-fetch with cross-fetch since it has a "realFetch.call is not a fn" bug and is less supported

[0.15.x] - 2021-07-15

Changed

  • Replaced portable-fetch with isomorphic-fetch once I saw that portable is just a less-supported branch

[0.14.x] - 2021-06-18

Added

  • Streaming processors to DynamoRatchet

    Changed

  • Updated libraries

[0.13.x] - 2021-02-28

Added

  • Model-validator

    Changed

  • Updated libraries
  • Moving to Barrelsby

[0.12.x] - 2021-02-26

Changed

-Switched to Jest internally

  • Updated libraries
  • Switched from Moment to Luxon

[0.11.x] - 2021-01-25

Added

  • Ec2 ratchet
  • Barrel files MapRatchet expander
  • Max sizes to mailer config
  • StringWritableStream
  • Streaming CSV writer
  • Ability to stream to a Daemon target

    Changed

  • Wrap classes with CLI extensions
  • Trying a new module output

[0.10.x] - 2021-01-08

Added

  • CSV comparison
  • Logger passthru functions for console on browser

    Changed

  • Updating dependant libraries

[0.9.x] - 2020-09-11

Added

  • CLI Ratchet

    Changed

  • Updating dependant libraries for security holes

[0.8.x] - 2020-06-09

Added

  • Adding cloudwatch insights helpers

    Changed

  • Updated to require Node 12.x.
  • Switched to eslint

[0.7.x] - 2020-05-04

Changed

  • Breaking change to SesMailSendingProvider (switch to config object, add allowedDestinationEmails handling)
  • Removed Gulp for security reasons.

[0.6.x] - 2020-04-22

Changed

-Breaking change to SesMailSendingProvider (adding Handlebars layouts)

[0.5.x] - 2019-10-19

Changed

-Breaking change to AthenaRatchet

[0.4.x] - 2019-09-06

Changed

-TBD for when I feel like doing repo diving

[0.3.x] - 2019-07-26

Changed

-TBD for when I feel like doing repo diving

[0.2.x] - 2019-07-08

Changed

-TBD for when I feel like doing repo diving

[0.1.x] - 2019-06-14

Changed

-TBD for when I feel like doing repo diving

[0.0.x] - 2018-03-23

Initial Release

-TBD for when I feel like doing repo diving