npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gelato-api

v1.0.5

Published

Gelato API Client in JavaScript/TypeScript

Downloads

17

Readme

Gelato API Client in JavaScript/TypeScript

License: MIT npm version

This library provides support for TypeScript/JavaScript Gelato's API. See full documentation on Gelato API docs.

Install

# npm
npm i -S gelato-api

# yarn
yarn add gelato-api

Usage

Before you can utilize the API you need:

  1. An account on Gelato.com.
  2. Create an API key in Dashboard > Developer > API Keys
import { GelatoApi } from 'gelato-api';

const gelato = new GelatoApi({ apiKey: 'YOUR-API-KEY' });

Examples

Catalogs & Products

// Get all catalogs
const allCatalogs = await gelato.products.getCatalogs();

// Get specific catalog
const cardCatalog = await gelato.products.getCatalog('cards');

// Get/Search products in catalog
const cardProducts = await gelato.products.getProductsInCatalog('cards', { limit: 5 });

// Get specific product
const card1 = await gelato.products.getProduct('cards_pf_bb_pt_350...');

// Get cover dimensions
const dims = await gelato.products.getCoverDimensions('photobooks-softcover_pf_140x...', {
  pageCount: 30,
});

// Get prices
const cardPrices = await gelato.products.getPrices('cards_pf_bb_pt_350...', {
  country: 'SE',
  currency: 'SEK',
});

// Get stock availability
const stockInfo = await gelato.products.getStockAvailability([
  'cards_pf_bb_pt_350...',
  'photobooks-softcover_pf_140x140...',
]);

Shipment Methods

// Get available shipment methods in Sweden
const shipments = await gelato.shipment.getMethods({ country: 'SE' });

Orders

import { Gelato, GelatoApi } from 'gelato-api';

// Create order
const myOrder: Gelato.OrderCreateRequest = {
  orderType: 'draft',
  orderReferenceId: 'my-internal-order-id',
  customerReferenceId: 'my-internal-customer-id',
  currency: 'EUR',
  items: [
    {
      itemReferenceId: 'my-internal-item-id',
      productUid: 'cards_pf_bb_pt_350-gsm-coated-silk_cl_4-4_hor',
      quantity: 1,
      fileUrl: 'https://i1.sndcdn.com/artworks-000398776953-cwfbd0-t500x500.jpg',
    },
  ],
  shippingAddress: {
    firstName: 'Test',
    lastName: 'Testson',
    addressLine1: 'Test Street 123',
    city: 'Testville',
    postCode: '123 45',
    country: 'SE',
    email: '[email protected]',
  },
};
const createdOrder = await gelato.orders.v3.create(myOrder);

// And more...
const createdOrder = await gelato.orders.v3.get('gelato-order-id');
const foundOrders = await gelato.orders.v3.search({ ... });

const patchedOrder = await gelato.orders.v3.patchDraft('gelato-order-id', { orderType: 'order'});
const updatedOrder = await gelato.orders.v3.update('gelato-order-id', { ... });

await gelato.orders.v3.deleteDraft('gelato-order-id');
await gelato.orders.v3.cancel('gelato-order-id');

const quotedOrder = await gelato.orders.v3.quote({ ... });
const shippingAddress = await gelato.orders.v3.getShippingAddress('gelato-order-id');
const updatedShippingAddress = await gelato.orders.v3.updateShippingAddress('gelato-order-id', { ... });

NOTE Orders V2 is not supported for now.

Run end-to-end tests

The E2E tests will utilize each feature supported, meaning it will list, create, update and delete actual data in the API. However, when it runs successfully it should have cleaned up any test orders. If not - it might be worth to take a look in the Dashboard > Orders to see if any manual clean up is required.

To run the e2e tests, follow these steps:

  1. Rename .env-SAMPLE to .env and add your Gelato API key.
  2. Run tests:
    npm run test:e2e
    # or
    yarn test:e2e

Go nuts! 🥳