A curated list of open technology projects to sustain a stable climate, energy supply, biodiversity and natural resources.

patch-node

The road to global carbon-neutrality will be through programmatic compensation.
https://github.com/patch-technology/patch-node

Category: Consumption
Sub Category: Computation and Communication

Keywords

carbon carbon-emissions carbon-neutral carbon-offsets carbon-offsetting javascript

Keywords from Contributors

carbon-footprint carbon-dioxide patch climate-change climate carbon-removal measur archiving transforms conversion

Last synced: about 21 hours ago
JSON representation

Repository metadata

Patch's Javascript client library - https://www.patch.io

README.md

Patch JavaScript SDK

Test
npm version
Discord

The official JavaScript package for the Patch API.

Documentation

For a complete API reference, check out Patch's API Reference.

Installation

NPM

npm install @patch-technology/patch --save

Yarn

yarn add @patch-technology/patch

Requirements

  • Node 10+

Usage

Configuration

After installing the package, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard:

// ES6+
import Patch from '@patch-technology/patch';
const patch = Patch('key_test_1234');

// ES5
var patch = require('@patch-technology/patch').default('key_test_1234');

Peer dependencies

For environments that do not include the Node Standard Library, such as React Native, you will need to install the listed peer dependencies in order for the package to work as expected. You can install the peer dependencies by running:

npm install install-peers

Orders

In Patch, orders represent a purchase of carbon offsets or negative emissions by mass.
Place orders directly if you know the amount of carbon dioxide you would like to sequester.
If you do not know how much to purchase, use an estimate.
You can also create an order with a maximum desired price, and we'll allocate enough mass to
fulfill the order for you.

API Reference

Examples

// Create an order - you can create an order
// providing either amount (and unit) or total_price (and currency), but not both

// Create order with amount
const amount = 1_000_000; // Pass in the amount in unit specified
const unit = 'g';
patch.orders.createOrder({ amount: amount, unit: unit });

// Create an order with total price
const totalPrice = 500; // Pass in the total price in smallest currency unit (ie cents for USD).
const currency = 'USD';
patch.orders.createOrder({ total_price: totalPrice, currency: currency });

// Create order with the issued_to field (optional)
const amount = 1_000_000; // Pass in the amount in unit specified
const unit = 'g';
const issued_to = { email: '[email protected]', name: 'Olivia Jones' };
patch.orders.createOrder({ amount: amount, unit: unit, issued_to: issued_to });

// Retrieve an order
orderId = 'ord_test_1234'; // Pass in the order's id
patch.orders.retrieveOrder(orderId);

// Place an order
const orderId = 'ord_test_1234'; // Pass in the order's id
patch.orders.placeOrder(orderId);

// Place an order with the issued_to field (optional)
const orderId = 'ord_test_1234'; // Pass in the order's id
const issued_to = { email: '[email protected]', name: 'Olivia Jones' };
patch.orders.placeOrder(orderId, { issued_to: issued_to });

// Cancel an order
const orderId = 'ord_test_1234'; // Pass in the order's id
patch.orders.cancelOrder(orderId);

// Retrieve a list of orders
const page = 1; // Pass in which page of orders you'd like
patch.orders.retrieveOrders({ page });

Estimates

Estimates allow API users to get a quote for the cost of compensating a certain amount of CO2. When creating an estimate, an order in the draft state will also be created, reserving the allocation of a project for 5 minutes. If you don't place your draft order within those 5 minutes, the order will automatically be cancelled.

API Reference

Examples

// Create a mass estimate
const mass_g = 1000000; // Pass in the mass in grams (i.e. 1 metric tonne)
patch.estimates.createMassEstimate({ mass_g });

// Create a flight estimate
const distance_m = 9000000; // Pass in the distance traveled in meters
patch.estimates.createFlightEstimate({ distance_m });

// Create an ecommerce estimate
const distance_m = 9000000;
// Pass in the shipping distance in meters, the transportation method, and the package mass
patch.estimates.createEcommerceEstimate({
  distance_m,
  package_mass_g: 1000,
  transportation_method: 'air'
});

// Create a bitcoin estimate
const transaction_value_btc_sats = 1000; // [Optional] Pass in the transaction value in satoshis
patch.estimates.createBitcoinEstimate({
  transaction_value_btc_sats
});

// Create a vehicle estimate
const distance_m = 9000000;
// Pass in the driving distance in meters and the model/make/year of the vehicle
patch.estimates.createVehicleEstimate({
  distance_m,
  make: 'Toyota',
  model: 'Corolla',
  year: 1995
});

// Create a hotel estimate
const country_code = 'US'; // ISO3166 alpha-2 country code
const city = 'New York'; // [Optional]
const region = 'New York'; // [Optional]
const star_rating = 4; // [Optional] Star rating of the hotel from 2 to 5
const number_of_nights = 2; // [Optional] Default value is 1
const number_of_rooms = 2; // [Optional] Default value is 1
patch.estimates.createHotelEstimate({
  country_code,
  city,
  region,
  star_rating,
  number_of_nights,
  number_of_rooms
});

// Retrieve an estimate
const estimateId = 'est_test_1234';
patch.estimates.retrieveEstimate(estimate_id);

// Retrieve a list of estimates
const page = 1; // Pass in which page of estimates you'd like
patch.estimates.retrieveEstimates({ page });

Projects

Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project.

When fetching Projects, you can add filters to the query to narrow the result. Currently supported filters are:

  • country
  • type
  • minimumAvailableMass

You can also set the acceptLanguage option to retrieve projects in a different language.

API Reference

Examples

// Retrieve a project
const projectId = 'pro_test_1234'; // Pass in the project's ID
patch.projects.retrieveProject(projectId);

// Retrieve a list of projects
const page = 1; // Pass in which page of projects you'd like
patch.projects.retrieveProjects({ page });

// Retrieve a filtered list of projects
const country = 'CA'; // Pass in the country you'd like to get projects from
patch.projects.retrieveProjects({ country });

// Retrieve a filtered list of projects
const type = 'biomass'; // Pass in the project type you'd like to filter by
patch.projects.retrieveProjects({ type });

// Retrieve a filtered list of projects
const minimumAvailableMass = 100; // Pass in the minimum available inventory the projects should have
patch.projects.retrieveProjects({ minimumAvailableMass });

// Retrieve a project in another language
// See http://docs.patch.test:3000/#/internationalization for more information and support languages
const projectId = 'pro_test_1234';
patch.projects.retrieveProject(projectId, { acceptLanguage: 'fr' });

Contributing

While we value open-source contributions to this SDK, the core of this library is generated programmatically. Complex additions made directly to the library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README, as well as new test cases are always very welcome!

Build and manually test

To build and test the package locally, run:

$ npm run build

This will generate a dist folder with the compiled code. Next you want to link the package and use it in a different folder.

In the patch-node folder, run:

$ npm link

Navigate to a different, empty folder:

$ cd ..
$ mkdir test-patch-node
$ cd test-patch-node

In that repository, run the following command to use the locally built package:

$ npm link @patch-technology/patch

This will create a node_modules directory in your test repository which will symlink to your locally built package. To test out the package, open a node REPL and import the package and run some queries.

SANDBOX_API_KEY=xxx node
const Patch = require('@patch-technology/patch');
const patch = Patch.default(process.env.SANDBOX_API_KEY);
patch.projects.retrieveProjects().then((response) => console.log(response));

Run the specs

Before running the tests, make sure you set the test API key! Please use test API keys and not production ones, they usually start with key_test_.
Be sure you navigate back to the root patch-node directory to run the tests.

$ export SANDBOX_API_KEY=<PATCH_TEST_API_KEY>

Then you are ready to run the tests:

$ npm run test

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 4 days ago

Total Commits: 108
Total Committers: 18
Avg Commits per committer: 6.0
Development Distribution Score (DDS): 0.713

Commits in past year: 8
Committers in past year: 4
Avg Commits per committer in past year: 2.0
Development Distribution Score (DDS) in past year: 0.5

Name Email Commits
Paul Cothenet p****t@g****m 31
Brennan Spellacy b****y@g****m 23
Lovisa Svallingson l****a@u****m 13
dependabot[bot] 4****] 12
Brett Holt b****t@u****m 5
James Klein k****7@g****m 5
Rahul Mody r****l@u****m 4
Thiago Araujo t****o@g****m 3
Vicky Enalen v****n 2
Aliana Melendez a****m 2
Jeremy Oustrich j****y@u****m 1
Lovisa Svallingson l****a@j****m 1
Brendan O'Connell b****5@g****m 1
David Cornu me@d****m 1
Fredrik Olovsson f****n 1
Jean Bredeche b****e@g****m 1
Jon j****n@j****g 1
Piper p****r 1

Committer domains:


Issue and Pull Request metadata

Last synced: 2 days ago

Total issues: 0
Total pull requests: 102
Average time to close issues: N/A
Average time to close pull requests: 5 days
Total issue authors: 0
Total pull request authors: 18
Average comments per issue: 0
Average comments per pull request: 0.32
Merged pull request: 90
Bot issues: 0
Bot pull requests: 17

Past year issues: 0
Past year pull requests: 9
Past year average time to close issues: N/A
Past year average time to close pull requests: 1 day
Past year issue authors: 0
Past year pull request authors: 4
Past year average comments per issue: 0
Past year average comments per pull request: 0.11
Past year merged pull request: 8
Past year bot issues: 0
Past year bot pull requests: 5

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/patch-technology/patch-node

Top Issue Authors

Top Pull Request Authors

  • pcothenet (31)
  • dependabot[bot] (17)
  • biglovisa (17)
  • kleinjm (5)
  • thdaraujo (5)
  • holtbp (5)
  • bspellacy (4)
  • rmody3 (4)
  • venalen (2)
  • jbredeche (2)
  • alianam (2)
  • davidcornu (2)
  • boconnell2 (1)
  • fredrikolovsson (1)
  • joustrich (1)

Top Issue Labels

Top Pull Request Labels

  • dependencies (17)
  • Ready (7)
  • Needs Review (4)
  • Reviewed (1)

Package metadata

npmjs.org: @patch-technology/patch

Node.js wrapper for the Patch API

  • Homepage: https://github.com/patch-technology/patch-node#readme
  • Licenses: MIT
  • Latest release: 2.3.0 (published 4 months ago)
  • Last Synced: 2025-04-25T13:05:33.638Z (2 days ago)
  • Versions: 48
  • Dependent Packages: 2
  • Dependent Repositories: 1
  • Downloads: 648 Last month
  • Rankings:
    • Downloads: 4.674%
    • Stargazers count: 5.657%
    • Forks count: 7.209%
    • Average: 7.401%
    • Dependent packages count: 8.732%
    • Dependent repos count: 10.733%
  • Maintainers (4)

Dependencies

package-lock.json npm
  • 396 dependencies
package.json npm
  • @babel/cli ^7.16.0 development
  • @babel/core ^7.16.0 development
  • @babel/plugin-proposal-class-properties ^7.0.0 development
  • @babel/plugin-proposal-decorators ^7.0.0 development
  • @babel/plugin-proposal-do-expressions ^7.0.0 development
  • @babel/plugin-proposal-export-default-from ^7.0.0 development
  • @babel/plugin-proposal-export-namespace-from ^7.0.0 development
  • @babel/plugin-proposal-function-bind ^7.0.0 development
  • @babel/plugin-proposal-function-sent ^7.0.0 development
  • @babel/plugin-proposal-json-strings ^7.0.0 development
  • @babel/plugin-proposal-logical-assignment-operators ^7.0.0 development
  • @babel/plugin-proposal-nullish-coalescing-operator ^7.0.0 development
  • @babel/plugin-proposal-numeric-separator ^7.0.0 development
  • @babel/plugin-proposal-optional-chaining ^7.0.0 development
  • @babel/plugin-proposal-pipeline-operator ^7.0.0 development
  • @babel/plugin-proposal-throw-expressions ^7.0.0 development
  • @babel/plugin-syntax-dynamic-import ^7.0.0 development
  • @babel/plugin-syntax-import-meta ^7.0.0 development
  • @babel/preset-env ^7.16.0 development
  • @babel/register ^7.16.0 development
  • chai ^4.3.0 development
  • husky ^4.2.5 development
  • lint-staged ^10.5.4 development
  • mocha ^9.1.0 development
  • prettier ^2.0.5 development
  • sinon ^7.2.0 development
  • query-string ^7.0.1
  • superagent ^5.3.1
yarn.lock npm
  • 396 dependencies
.github/workflows/health_check.yml actions
  • actions/checkout v2 composite
  • actions/setup-node v3 composite
  • kpritam/slack-job-status-action v1 composite
.github/workflows/publish.yml actions
  • actions/checkout v2 composite
  • actions/setup-node v3 composite
  • chrnorm/deployment-action releases/v1 composite
  • chrnorm/deployment-status releases/v1 composite
.github/workflows/test.yml actions
  • actions/checkout v2 composite
  • actions/setup-node v3 composite
Dockerfile docker
  • node 16.16 build

Score: 13.623502235580776