patch-node

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

https://github.com/patch-technology/patch-node

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.5%) to scientific vocabulary

Keywords

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

Keywords from Contributors

projection interactive serializer measurement cycles packaging charts network-simulation archival shellcodes
Last synced: 6 months ago · JSON representation

Repository

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

Basic Info
  • Host: GitHub
  • Owner: patch-technology
  • Language: JavaScript
  • Default Branch: main
  • Homepage: https://www.patch.io
  • Size: 1.03 MB
Statistics
  • Stars: 69
  • Watchers: 11
  • Forks: 6
  • Open Issues: 0
  • Releases: 52
Topics
carbon carbon-emissions carbon-neutral carbon-offsets carbon-offsetting javascript
Created over 5 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog

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

shell npm install @patch-technology/patch --save

Yarn

shell 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:

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

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

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

```javascript // 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 = 1000000; // 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 issuedto field (optional) const amount = 1000000; // Pass in the amount in unit specified const unit = 'g'; const issuedto = { email: 'issuee@companya.com', name: 'Olivia Jones' }; patch.orders.createOrder({ amount: amount, unit: unit, issuedto: issuedto });

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

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

// Place an order with the issuedto field (optional) const orderId = 'ordtest1234'; // Pass in the order's id const issuedto = { email: 'issuee@companya.com', name: 'Olivia Jones' }; patch.orders.placeOrder(orderId, { issuedto: issuedto });

// Cancel an order const orderId = 'ordtest1234'; // 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

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

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

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

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

// Retrieve an estimate const estimateId = 'esttest1234'; 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

```javascript // Retrieve a project const projectId = 'protest1234'; // 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 = 'protest1234'; 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:

sh $ 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:

sh $ npm link

Navigate to a different, empty folder:

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

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

sh $ 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.

sh SANDBOX_API_KEY=xxx node

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.

sh $ export SANDBOX_API_KEY=<PATCH_TEST_API_KEY>

Then you are ready to run the tests:

sh $ npm run test

Owner

  • Name: Patch
  • Login: patch-technology
  • Kind: organization
  • Email: engineering@patch.io
  • Location: San Francisco

Rebalance the planet

GitHub Events

Total
  • Release event: 4
  • Delete event: 9
  • Issue comment event: 4
  • Push event: 9
  • Pull request review comment event: 1
  • Pull request review event: 5
  • Pull request event: 17
  • Create event: 11
Last Year
  • Release event: 4
  • Delete event: 9
  • Issue comment event: 4
  • Push event: 9
  • Pull request review comment event: 1
  • Pull request review event: 5
  • Pull request event: 17
  • Create event: 11

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 110
  • Total Committers: 18
  • Avg Commits per committer: 6.111
  • Development Distribution Score (DDS): 0.709
Past Year
  • Commits: 8
  • Committers: 4
  • Avg Commits per committer: 2.0
  • Development Distribution Score (DDS): 0.5
Top Committers
Name Email Commits
Paul Cothenet p****t@g****m 32
Brennan Spellacy b****y@g****m 23
Lovisa Svallingson l****a@u****m 13
dependabot[bot] 4****] 13
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 (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 111
  • Average time to close issues: 2 months
  • Average time to close pull requests: 5 days
  • Total issue authors: 1
  • Total pull request authors: 18
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.36
  • Merged pull requests: 97
  • Bot issues: 1
  • Bot pull requests: 20
Past Year
  • Issues: 1
  • Pull requests: 16
  • Average time to close issues: 2 months
  • Average time to close pull requests: 7 days
  • Issue authors: 1
  • Pull request authors: 4
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.5
  • Merged pull requests: 13
  • Bot issues: 1
  • Bot pull requests: 7
Top Authors
Issue Authors
Pull Request Authors
  • pcothenet (36)
  • dependabot[bot] (23)
  • biglovisa (17)
  • holtbp (6)
  • kleinjm (5)
  • thdaraujo (5)
  • bspellacy (4)
  • rmody3 (4)
  • davidcornu (3)
  • venalen (2)
  • jbredeche (2)
  • alianam (2)
  • fredrikolovsson (1)
  • joustrich (1)
  • johnnyman727 (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (23) Ready (7) Needs Review (4) javascript (3) Reviewed (1)

Packages

  • Total packages: 2
  • Total downloads:
    • npm 829 last-month
  • Total dependent packages: 2
    (may contain duplicates)
  • Total dependent repositories: 1
    (may contain duplicates)
  • Total versions: 60
  • Total maintainers: 4
proxy.golang.org: github.com/patch-technology/patch-node
  • Versions: 9
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 6 months ago
npmjs.org: @patch-technology/patch

Node.js wrapper for the Patch API

  • Versions: 51
  • Dependent Packages: 2
  • Dependent Repositories: 1
  • Downloads: 829 Last month
Rankings
Downloads: 4.7%
Stargazers count: 5.7%
Forks count: 7.2%
Average: 7.4%
Dependent packages count: 8.7%
Dependent repos count: 10.7%
Last synced: 6 months ago

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