front-end-monorepo icon indicating copy to clipboard operation
front-end-monorepo copied to clipboard

PanoptesJS: remove superagent

Open shaunanoordin opened this issue 5 months ago • 1 comments

PR Overview

Package: panoptes-js

This PR attempts to remove superagent from the PanoptesJS client

  • Reason: superagent is a dependency that we don't technically need anymore, since the standard fetch API works fine, while maintaining superagent can be a bit of a faff.
  • Observation: superagent() is only used in the get(), post(), put(), and del() (i.e. delete) functions of panoptes.js, so replacing the dependency should be very easy.
    • (Spoiler: it wasn't)
  • Priority: low priority, for now. Removing superagent is a "nice to have" item that will eventually escalate to "gotta get it done" once the maintenance cost gets too high in the future (or the library stops getting updates, whichever comes first).

Dev Notes

As of 12 Sep 2024, this PR is in an experimental stage. The biggest lessons we've learnt are:

  1. it's actually easy to replace the superagent() calls in panoptes.js, as initially observed.
  2. however, there are MULTIPLE places in the FEM code that expects a very specific superagent-shaped response from panoptes.get()/panoptes.put()/panoptes.post()/panoptes.del(),
Comparison of the default response data we get from superagent vs the default response data we get from fetch().

Superagent response:

Screenshot 2024-09-12 at 15 56 50

Fetch API response:

Screenshot 2024-09-12 at 16 00 18

So in practice, we either need to...

  1. accept the cost of going through the hundred(s?) instances in the FEM code (and any other project that uses PanoptesJS) that expects a superagent response and make changes there, OR
  2. create a transformer/adapter that transform Fetch API responses into superagent-compatible responses.

Status

Experimental. Put on pause as of 12 Sep 2024 while higher priority items in PanoptesJS is addressed.

As of commit 96096e: panoptes.get experimental: replace superagent with fetch, the get() function has superagent() successfully replaced with fetch(), with a very rudimentary fetch-response-to-superagent-response transformer in place. You can run lib-classifier > yarn dev and load a local test project, and the data will be fetched fine for this instance.

shaunanoordin avatar Sep 12 '24 22:09 shaunanoordin