GithubHelp home page GithubHelp logo

ekkolon / gelato-admin-node Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 3.0 803 KB

Node.js API for Gelato's print-on-demand services.

Home Page: https://ekkolon.github.io/gelato-admin-node/

License: Apache License 2.0

TypeScript 98.48% JavaScript 1.52%
gelato javascript nodejs typescript gelato-api print-on-demand api api-client

gelato-admin-node's Introduction

Gelato Node.js SDK

A lightweight Node.js SDK to seamlessly integrate Gelato's powerful print-on-demand services into your Node applications.

Table of Contents

Features

  • ๐Ÿ“„ Simple and intuitive API
  • โœจ Query and mutate data from different Gelato accounts
  • ๐ŸŒณ Tree-shakable - only use and compile services you need
  • ๐Ÿ›ก๏ธ Battle-tested

Getting Started

Prerequisites

Before you can use this library, you must complete the following steps:

  1. Create a Gelato Account
  2. Generate an API Key

Installation

# npm
npm install gelato-admin

# yarn
yarn add gelato-admin

Usage

Every API service is tied to a GelatoClient instance, whose sole purpose is to handle the request/response life-cycle when querying and mutating your Gelato data.

There are two ways to initialize a GelatoClient:

1. Using an environment variable (recommended)

See .env.example.

# .env

GELATO_API_KEY=my-api-key
import { initializeClient } from 'gelato-admin';

// Auto-detect API key from `.env` file
const client = initializeClient();

// The above snippet is a short-hand equivalent for:
const client = initializeClient({ apiKey: process.env.GELATO_API_KEY });

2. Setting API key explicitly

Useful for on-demand client initialization. Required for named clients.

import { initializeClient } from 'gelato-admin';

const client = initializeClient({ apiKey: 'my-api-key' });

Using named clients

Note: The usage of named clients is not a native Gelato API feature. It is a design decision based on the idea that you may have different Gelato accounts you want to use within the same application context.

You may initialize as many client instances as you like, provided you initialize them with a unique name. If you only have a single Gelato account, however, there is no need to use named clients at all.

To initialize a named client, pass an unique name as the second argument.

import { initializeClient } from 'gelato-admin';

// Auto-detect API key from `.env` file, but use a specific name for the client instance.
const myDefaultNamedClient = initializeClient({}, 'my-named-client');

// Use another Gelato account API key
const myOtherClient = initializeClient({ apiKey: 'other-account-api-key' }, 'other-account-client');

Accessing client instances

import { getClient } from 'gelato-admin';

// Get the default client
const defaultClient = getClient();

// Get a named client
const myNamedClient = getClient('my-named-client');

Using API services

Here is an overview of Gelato API services available in this library.

Name Module Service
Orders gelato-admin/orders getOrdersAPI()
Products gelato-admin/products getProductsAPI()
Shipment gelato-admin/shipment getShipmentAPI()
Ecommerce gelato-admin/ecommerce getEcommerceAPI()

Default client

import { getProductsAPI } from 'gelato-admin/products';

// Get the products API service from the default client.
const productsAPI = getProductsAPI();

// Get a list of all catalogs
const catalogs = await productsAPI.getCatalogs();

Named client

To target a named client, pass the client instance as the first argument to the desired API service function:

import { initializeClient } from 'gelato-admin';
import { getOrdersAPI } from 'gelato-admin/orders';

// Initialize a named client with the API key from the environment variable
const mySpecialClient = initializeClient({ apiKey: 'my-other-api-key' }, 'my-special-client');

// Get the products API service using the named client.
const ordersAPI = getOrdersAPI(mySpecialClient);

// Get a list of all orders
const orders = await ordersAPI.getOrders();

Running tests

Unit tests

yarn run test

E2E tests

yarn run test:e2e

E2E tests only create draft orders. In case E2E tests fail, make sure to check your Gelato dashboard for whether any orders other than draft orders were created. If so, you must delete them manually.

License

This project is licensed under the Apache License (2.0) - see the LICENSE file for more details.

Authors

Disclaimer

Please note that this is not an official Gelato product. I am in no way affiliated with Gelato. However, I started this library to make it easier for developers to work with Gelato's powerful print-on-demand platform.

You bear complete responsibility for your utilization of this library. See LICENSE file for more information.

gelato-admin-node's People

Contributors

dependabot[bot] avatar ekkolon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gelato-admin-node's Issues

Add v3 legacy support

Which Gelato package(s) are relevant/related to the feature request?

orders

Description

The current release only targets the latest API version of Gelato's orders API (v4).
We can confidently assume that there are still many systems relying on the v3 legacy version.

There are two main reasons for providing legacy support:

  1. Maintain compatibility: There may be existing applications that rely on the v3 functionality.
    In many cases it would be undesirable to force consumers of this library to migrate to v4.
  2. Expand user base: By adding legacy support, we appeal to a broader range of users.

Proposed solution

Due to Gelato's API design, it makes sense to keep this libraries namespaces in sync with it.
For example, we can use gelato-admin/v3/orders as the go to namespace for the orders API.

In any case, besides some changes in the return types for endpoints targeting the orders API,
we must provide two additional endpoints:

  1. Get shipping address
  2. Update shipping address

This feature must not introduce any breaking changes, since it should use the same design patterns and parent container (GelatoClient) as the latest orders API version.

Alternatives considered

N/A

Add Webhooks event handlers

Which Gelato package(s) are relevant/related to the feature request?

No response

Description

It would be great to provide a way to intercept the request/response cycle of http servers (express + fastify). The interceptor should provide a callable function signature users can import from the library.

Proposed solution

TBA

Alternatives considered

N/A

[Bug] e2e test fail at `ordersAPI#getOrders`

Which gelato/* package(s) are the source of the bug?

orders

Is this a regression?

No

Description

All E2E test pass, except ordersAPI#getOrders.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

`AxiosError: Request failed with status code 405`

Please provide the environment you discovered this bug in

Node: 18.16.1
Package Manager: yarn 1.22.19
OS: Debian (WSL)

Gelato SDK: 1.1.5

Anything else?

  • In earlier versions test DID pass.
  • A 405 http error code suggest, we are using an disallowed HTTP method.

Unable to eslint workspace

Which gelato/* package(s) are the source of the bug?

orders, products, shipment

Is this a regression?

No

Description

yarn lint or yarn lint:fix fail to execute on Windows machines.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No files matching the pattern "'**/*.ts'" were found.
Please check for typing mistakes in the pattern.

Please provide the environment you discovered this bug in

Node: v18.16.1
Package Manager: yarn 1.22.19
OS: windows 11

Gelato SDK: 1.1.0
-------------------------------------------------------------
ESLint: 8.48.0

Anything else?

The issue comes from the following lines in the package.json file:

https://github.com/ekkolon/gelato-admin-node/blob/105008b114a98063bc10db45bad19904bae4b6c6/package.json#L14C1-L15C42

I suspect the error is caused by using single quotes instead of escaped double quotes.


The following changes should fix this issue:

BEFORE:

"lint": "eslint '**/*.ts'",
"lint:fix": "eslint --fix '**/*.ts'",

AFTER:

"lint": "eslint \"**/*.ts\""
"lint:fix": "eslint --fix \"**/*.ts\""

Improve README

Some paragraphs in the README file are either redundant or need semantic improvements.

[Feature Request] Add support for new `Ecommerce` API feature

Which Gelato package(s) are relevant/related to the feature request?

No response

Description

Gelato added a new Ecommerce API feature that is currently missing in this repo.

Proposed solution

Add support for Ecommerce feature.

Alternatives considered

N/A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.