CaravanStudios / open-product-recovery

Apache License 2.0
26 stars 20 forks source link

Create "ingest" as a common, installable, endpoint #66

Open ryckmanat opened 1 year ago

ryckmanat commented 1 year ago

The example servers all add an "/ingest" endpoint (which is, optionally, protected). It looks like this today:

    const ingestEndpoint = {
      method: ['POST'],
      handle: async () => {
        const changes = [] as Array<OfferChange>;
        const changeHandler = api.registerChangeHandler(async change => {
          changes.push(change);
        });
        await s.ingest();
        changeHandler.remove();
        return changes;
      },
    } as CustomRequestHandler;

Given that this is commonly wanted, we should move it to the opr-core library and make it easily installable in any server.

This should be created under opr-core/src/server/installable-endpoints/ingest.ts. Then, export the endpoint as a CustomRequestHandler.