bananas-commerce
The JavaScript client for bananas-commerce
. It exports both a public client
(BananasCommerce
, from bananas-commerce/public
), to be used in e.g. browser
environments, and a private client (BananasCommercePrivate
from
bananas-commerce/private
), to be used in back-ends.
import { BananasCommerce } from "bananas-commerce";
const client = new BananasCommerce({ siteCode: "test-site" });
const checkout = await client.adyen.begin({
items: [
{
reference: "banan",
quantity: 1337,
},
{
reference: "kontakt",
quantity: 1337,
},
],
});
Prerequisites
Prerequisites apart from having the whole bcom repo cloned and the prerequisites for running the backend is only deno unless you want to publish a new version to npm, but that should not be needed as CI takes care of that.
Coverage
If you want to generate cobertura coverage locally you need two additional
dependencies installed locally from pip: lcov_cobertura
and pycobertura
. The
default behaviour of make coverage
is to generate a cobertura
report but
that comes with a >50% performance hit because of the lcov to cobertura coverage
format conversion (not that it is a huge problem, it's about 0.5s...).
If you want coverage reporting locally without using either lcov or cobertura,
simply run make test
and then deno coverage coverage/ --include src/
which
prints out a detailed coverage report to your console.
Building
When testing and running in deno no build step is required, if however you wish to build a new version of the npm package you will have to run:
make npm
This generates the npm/
directory which contains all relevant builds
(commonjs
, browser
and types
) along with a package.json
with the correct
entrypoints for using either or both of the BananasCommerce
and
BananasCommercePrivate
clients. It is done using the
dnt
(deno-to-node) build tool.
Generating fresh schemas
The automatically generated schema definitions are generated using the openapi-typescript tool. This is done automatically with:
make schemas
Formatting, linting and testing
All of these steps are made using the corresponding make commands:
make fmt
make lint
make test
When running these commands along with the make npm
command typechecking is
automatically done to ensure the typescript types are correct.
Project structure
│ # AUTOMATICALLY GENERATED FILES #########################################################################
├── npm/ - An automatically generated node package! DO EDIT MANUALLY!
├── coverage/ - An automatically generated v8 coverage report used for generating the lcov report
├── coverage.lcov - A lcov coverage report generated as an in-between format for generating cobertura
├── coverage.xml - A cobertura coverage report generated from the lcov report
│ #########################################################################################################
├── scripts/ - A directory containing all development scripts
│ └── npm.ts - This script uses dnt to automatically create the npm package
├── src/ - This directory contains all of the client and related utilities
│ ├── types/ - Automatically generated types from the OpenAPI json schemas
│ ├── private/ - The private bananas-commerce client source
│ ├── public/ - The public bananas-commerce client source
│ ├── mod.ts - The primary entrypoint for using both the private and public api
│ ├── private.ts - The primary entrypoint for using the private api
│ └── public.ts - The primary entrypoint for using the public api
├── mock/ - Mocking utils for writing tests
└── test/ - Tests for the bananas-commerce clients