Skip to content

Commit

Permalink
docs: cleanup README and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerlepine committed Dec 27, 2024
1 parent afeb530 commit d079c13
Show file tree
Hide file tree
Showing 61 changed files with 250 additions and 217 deletions.
4 changes: 1 addition & 3 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
*

# Except for the following files and directories:
!dist/index.cjs.js
!dist/index.esm.js
!dist/types/index.d.mts
!dist
!package.json
!README.md
!LICENSE
Expand Down
24 changes: 0 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@

Welcome! We're thrilled that you are interested in contributing to our project. By participating in this project, you agree to abide by the [Code of Conduct](./CODE_OF_CONDUCT.md).

## Local Development

### Prerequisites

1. Git
1. Node: any 18.x version starting with v16.0.0 or greater
1. Yarn: See [Yarn website for installation instructions](https://yarnpkg.com/lang/en/docs/install/) (`npm install yarn -g`)

### Installation

```sh
git clone https://github.com/spencerlepine/printify-sdk-js.git
cd printify-sdk-js
yarn install
```

### Testing

Add/update tests in the `tests/` directory, ensuring to follow unit test coding conventions

```sh
yarn test
```

## How Can I Contribute?

### Reporting Bugs
Expand Down
113 changes: 42 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,75 @@
![Coverage](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) ![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)
![Project Status Badge](./.github/status-maintained-badge.svg)

Printify SDK for Node.js. A basic TypeScript wrapper for the Printify REST API (v1). Guidelines and source endpoints can be found here:
[developers.printify.com](https://developers.printify.com).
The Printify Node SDK provides convenient access to the Printify API from applications written in server-side JavaScript.

## Getting started
Guidelines and source endpoints can be found here: [developers.printify.com](https://developers.printify.com).

### Prerequisites
> 📢 Note: This SDK currently supports V1 API endpoints only. A 2.0.0 release is planned once the majority of V2 endpoints have been migrated.
- Printify Personal Access Token (create one [here](https://printify.com/app/account/api))
## Documentation

### Installation
See the [`printify-sdk-js` API docs](./docs/API.md) for Node.js

- [Shops](./docs/API.md#shops) - `printify.shops.*`
- [Catalog](./docs/API.md#catalog) - `printify.catalog.*`
- [Products](./docs/API.md#products) - `printify.products.*`
- [Orders](./docs/API.md#orders) - `printify.orders.*`
- [Uploads](./docs/API.md#uploads) - `printify.uploads.*`
- [Webhooks](./docs/API.md#webhooks) - `printify.webhooks.*`

## Installation

```sh
# Npm
npm install printify-sdk-js

# Yarn
# or
yarn add printify-sdk-js

# Pnpm
# or
pnpm add printify-sdk-js
```

## Usage

> ⚠️ For security purposes, this is intended only for server-side use, the API does not support CORS and will not process requests from a frontend application
The package needs to be configured with your account's Personal Access Token (create one [here](https://printify.com/app/account/api)).

```sh
# generate a token: https://printify.com/app/account/api
export PRINTIFY_API_TOKEN="asdfASDFasdfASDFasdfASDF"
```js
import Printify from 'printify-sdk-js';

# fetch your shopId
curl -X GET https://api.printify.com/v1/shops.json --header "Authorization: Bearer $PRINTIFY_API_TOKEN"
# Expected response: [{"id":1234567,"title":"My Store Name","sales_channel":"custom_integration"}]
const printify = new Printify({
shopId: '123456', // (optional) find using printify.shops.list()
accessToken: 'asdf0123asdf0123asdf0123', // generate a token: https://printify.com/app/account/api
enableLogging: true, // (optional) enabled by default
});

# store for process.env.PRINTIFY_API_TOKEN
echo "PRINTIFY_API_TOKEN=\"$PRINTIFY_API_TOKEN\"" >> .env
const orders = await printify.orders.list({ limit: 5, status: 'fulfilled' });
console.log(orders); // { current_page: 1, data: [{ id: "5a9", address_to: {}, line_items: [], total_price: 2200, status: "fulfilled" } ]
```

### Usage with CommonJS

```js
import Printify from 'printify-sdk-js';
// const Printify = require('printify-sdk-js'); // CommonJS
const Printify = require('printify-sdk-js');

const printify = new Printify({
shopId: '123456', // global query by shop_id
accessToken: process.env.PRINTIFY_API_TOKEN,
enableLogging: true, // on by default
shopId: '123456',
accessToken: 'asdf0123asdf0123asdf0123',
enableLogging: true,
});

const orderData = {
label: order_123456,
line_items: [
{
print_provider_id: '12345',
blueprint_id: '67890',
variant_id: '112233',
print_areas: {
front: 'https://example.com/path/to/sticker.png', // **must be public
},
quantity: 1,
},
// ...
],
shipping_method: 1,
is_printify_express: false,
is_economy_shipping: false,
send_shipping_notification: true, // send email
address_to: {
first_name: 'John',
last_name: 'Doe',
email: 'johndoe@gmail.com',
phone: '0574 69 21 90',
country: 'US',
region: 'NY',
address1: '123 Main Street',
address2: '',
city: 'New York',
zip: '10001',
},
};

try {
const result = await printify.orders.submit(orderData);
console.log(result); // { "id": "5a96f649b2439217d070f507" }
} catch (error) {
console.error('Error submitting order:', error);
}
printify.orders
.list({ limit: 5, status: 'fulfilled' })
.then(orders => console.log(orders))
.catch(error => console.error(error));
```

## API
## Development

For the full documentation, please see [`API.md`](./docs/API.md)
```sh
yarn install
yarn test
```

- [Shops](./docs/API.md#shops) - `printify.shops.*`
- [Catalog](./docs/API.md#catalog) - `printify.catalog.*`
- [Products](./docs/API.md#products) - `printify.products.*`
- [Orders](./docs/API.md#orders) - `printify.orders.*`
- [Uploads](./docs/API.md#uploads) - `printify.uploads.*`
- [Webhooks](./docs/API.md#webhooks) - `printify.webhooks.*`
> If you do not have yarn installed, you can get it with `npm install --global yarn`.
## Contributing

Expand Down
71 changes: 0 additions & 71 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,5 @@
# Printify SDK Documentation (Node.js)

## Introduction

The Printify SDK for Node.js. A basic TypeScript wrapper for the Printify REST API (v1). Guidelines and source endpoints can be found here:
[developers.printify.com](https://developers.printify.com/).

## Usage

```sh
# generate a token: https://printify.com/app/account/api
export PRINTIFY_API_TOKEN="asdfASDFasdfASDFasdfASDF"

# fetch your shopId
curl -X GET https://api.printify.com/v1/shops.json --header "Authorization: Bearer $PRINTIFY_API_TOKEN"
# Expected response: [{"id":1234567,"title":"My Store Name","sales_channel":"custom_integration"}]

# store for process.env.PRINTIFY_API_TOKEN
echo "PRINTIFY_API_TOKEN=\"$PRINTIFY_API_TOKEN\"" >> .env
```

```js
import Printify from 'printify-sdk-js';
// const Printify = require('printify-sdk-js'); // CommonJS

const printify = new Printify({
shopId: '123456', // global query by shop_id
accessToken: process.env.PRINTIFY_API_TOKEN,
enableLogging: true, // on by default
});

const orderData = {
label: 'order_123456',
line_items: [
{
print_provider_id: '12345',
blueprint_id: '67890',
variant_id: '112233',
print_areas: {
front: 'https://example.com/path/to/sticker.png', // **must be public
},
quantity: 1,
},
// ...
],
shipping_method: 1,
is_printify_express: false,
is_economy_shipping: false,
send_shipping_notification: true, // send email
address_to: {
first_name: 'John',
last_name: 'Doe',
email: 'johndoe@gmail.com',
phone: '0574 69 21 90',
country: 'US',
region: 'NY',
address1: '123 Main Street',
address2: '',
city: 'New York',
zip: '10001',
},
};

try {
const result = await printify.orders.submit(orderData);
console.log(result); // { "id": "5a96f649b2439217d070f507" }
} catch (error) {
console.error('Error submitting order:', error);
}
```

## API

- [Shops](#shops)
- [Catalog](#catalog)
- [Products](#products)
Expand Down
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Printify SDK Examples

## Usage

```sh
$ npm install
$ npm start
```
12 changes: 12 additions & 0 deletions examples/commonjs/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Printify = require('printify-sdk-js');

const printify = new Printify({
shopId: '123456',
accessToken: 'asdf0123asdf0123asdf0123',
enableLogging: true,
});

printify.orders
.list({ limit: 5, status: 'fulfilled' })
.then(orders => console.log(orders))
.catch(error => console.error(error));
10 changes: 10 additions & 0 deletions examples/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "printify-node-examples",
"type": "module",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"printify-sdk-js": "*"
}
}
45 changes: 45 additions & 0 deletions examples/node/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Printify from 'printify-sdk-js';

const printify = new Printify({
shopId: '123456',
accessToken: 'asdfasdf',
enableLogging: true,
});

const orderData = {
external_id: 'unique_external_id',
label: 'Order Label',
line_items: [
{
print_provider_id: 12345,
blueprint_id: 67890,
variant_id: 112233,
print_areas: {
front: 'https://example.com/path/to/sticker.png',
},
quantity: 1,
},
// ...
],
shipping_method: 1,
is_printify_express: true,
is_economy_shipping: false,
send_shipping_notification: true,
address_to: {
first_name: 'string',
last_name: 'string',
email: 'string',
phone: 'string',
region: 'NY',
address1: '123 Main Street',
address2: '',
city: 'New York',
zip: '10001',
country: 'US',
},
};

(async () => {
const result = await printify.orders.submit(orderData);
console.log(result); // { "id": "5a96f649b2439217d070f507" }
})();
9 changes: 9 additions & 0 deletions examples/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "printify-node-examples",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"printify-sdk-js": "*"
}
}
Loading

0 comments on commit d079c13

Please sign in to comment.