rollthecloudinc / quell

Climate aware CMS breaking web apps free from carbon emissions.
https://demo.carbonfreed.app/pages/create-panel-page
GNU General Public License v3.0
14 stars 1 forks source link

HEDGE: Integration #344

Open ng-druid opened 1 year ago

ng-druid commented 1 year ago

I kind of like the idea of using context for this. The context might contain the domain and/or region of the least carbon intense available service available.

export config = {
  endpointUrl: "https://[.hedge.store.domain]/rollthecloudinc/vertigoapp-objects/shapshifter/"
}

hedge context:

{
  "servicename": {
    "domain": "https://eu-west-1.climatewarrior.store" // least carbon intense domain at the time for service
  }
}

More generic approach - probably better suited as independent framework agnostic NPM lib.


// Run bounced request
const { res } = await hedge("emissionless").bounce("/rollthecloudinc/hedge-objects/shapeshifter/services/emissionless.json", {});

// Get optimal available region wrapper
const { region } = await hedge("emissionless").region()

// Get the raw region document object literal
const { regionDocument } = await region.document()

// Get CURRENT carbon savings between optimal region and specified region.
const = { savings } = await region.compare("us-east-1").savings()

// Full service config hedge wrapper
const { service } = await hedge("emissionless").service()

// Get the raw service document object literal
const { serviceDocument } = await service.document()

// Full service config
const { res } = await hedge("rtcopensearch").bounce("/...", { body: {}, method: "POST" })

// records carbon savings as well

export const hedge (service, options) => new Promise();

export const service = ({ service, adaptor }) => adaptor({ name: adaptor ? adaptor : "fetch" }).then(adaptor => adaptor(`https://store.hedge.earth/services/${service}`)).then(service => ({ service }))

export const region = ({ service, region }) => service({ service }).then(({ service }) => ({ region: service.regions.find(r => r.region === region) }));

export const adaptor = ({ name }) => new Promise(res => res(fetch));