Skip to content

Commit

Permalink
release(v2.0.2-beta): update endpoints for Feb 2025
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerlepine committed Feb 8, 2025
1 parent 1c5f511 commit f32580c
Show file tree
Hide file tree
Showing 11 changed files with 1,838 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docs
src/**/*.js

examples/typescript/*.js
# Logs
logs
*.log
Expand Down
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.2-beta] - 2025-02-07

- Updated to the latest OpenAPI spec (Feb 2025).

## [2.0.1-beta] - 2024-08-12

Refactor: replace `@openapitools/openapi-generator-cli` with `openapi-typescript-codegen`
- Replaced `@openapitools/openapi-generator-cli` with `openapi-typescript-codegen`.

## [2.0.0-beta] - 2024-08-04

Initial release for Printful API v2-beta
- Initial release for Printful API v2-beta.
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ export { Placement } from './models/Placement';
+ export type { Placement as PlacementType } from './models/Placement';
```

### Local Testing

```sh
# (optional) test the bundle locally
cd examples/typescript && yarn && cd ../../
yarn
rm -rf examples/typescript/node_modules/printful-sdk-js-v2/dist && mv dist examples/typescript/node_modules/printful-sdk-js-v2
cd examples/typescript
yarn start
```

## Appendix

- **SDK Generator:**
Expand Down
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
# Printful SDK for TypeScript (Node.js)
# Printful SDK for Node.js (TypeScript)

[![NPM Version](https://img.shields.io/npm/v/printful-sdk-js-v2)](https://www.npmjs.com/package/printful-sdk-js-v2)
![MIT license](https://img.shields.io/badge/License-MIT-blue.svg) ![Project Status: WIP](https://www.repostatus.org/badges/latest/wip.svg)

> 📢 Printful API 2.0.0 is still in beta ([documentation](https://developers.printful.com/docs/v2-beta/)). This SDK will be in development until the official 2.0.0 release
> (by 2025)
> 📢 Notice: Printful API v2 is in beta, and this package is still in development. Expect changes until the stable release.
Printful SDK for Node.js. A basic TypeScript wrapper for the Printful REST API (v2). Guidelines and source endpoints can be found here:
[developers.printful.com](https://developers.printful.com).
Guidelines and source endpoints can be found here: [developers.printful.com](https://developers.printful.com).

## Getting started

### Prerequisites
## Documentation

- Printful API Token ([documentation](https://developers.printful.com))
View the site here: [spencerlepine.github.io/printful-sdk-js-v2](https://spencerlepine.github.io/printful-sdk-js-v2/classes/PrintfulClient.html)

### Installation
## Installation

```sh
# Npm
# npm
npm install printful-sdk-js-v2

# Yarn
# yarn
yarn add printful-sdk-js-v2

# Pnpm
# pnpm
pnpm add printful-sdk-js-v2
```

### Usage
## Usage

> For security purposes, this is intended only for server-side use only
The package needs to be configured with your private token (create one [here](https://developers.printful.com/tokens)).

```ts
// getCountries.ts
Expand All @@ -49,14 +45,19 @@ const printful = new PrintfulClient({
})();
```

## Example Code [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?style=flat-square&logo=codesandbox)](https://codesandbox.io/p/devbox/printful-sdk-js-v2-example-pzwn4m)
## Configuration

- **JavaScript:** [examples/javascript](./examples/javascript)
- **TypeScript:** [examples/typescript](./examples/typescript)
```js
import { PrintfulClient } from 'printful-sdk-js-v2';

## Documentation
const printful = new PrintfulClient({
TOKEN: '<PRINTFUL_API_TOKEN>',
});
```

View the site here: [spencerlepine.github.io/printful-sdk-js-v2](https://spencerlepine.github.io/printful-sdk-js-v2/classes/PrintfulClient.html)
| Option | Default | Description |
| ------- | ------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `TOKEN` | `null` | The private token for authenticating requests. Generate one at [Printful Developers](https://developers.printful.com/tokens). |

## Contributing

Expand Down
4 changes: 2 additions & 2 deletions examples/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"start": "node getCountries.js"
},
"dependencies": {
"printful-sdk-js-v2": "^2.0.1-beta"
"printful-sdk-js-v2": "*"
}
}
}
18 changes: 18 additions & 0 deletions examples/typescript/getStoresV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// tsc && node getStoresV2.ts

import { PrintfulClient } from 'printful-sdk-js-v2';

const printful = new PrintfulClient({
TOKEN: '<PRINTFUL_API_TOKEN>',
});

(async () => {
const response = await printful.storesV2.getStores();
const stores = response.data;
console.log(stores);
// Expected response:
// [
// { id: 1234567, name: 'MyStoreName', type: 'etsy' }
// ...
// ]
})();
4 changes: 2 additions & 2 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "typescript-examples",
"scripts": {
"start": "tsc && node getCountries.js"
"start": "tsc && node getStoresV2.js"
},
"dependencies": {
"printful-sdk-js-v2": "^2.0.1-beta"
"printful-sdk-js-v2": "*"
},
"devDependencies": {
"typescript": "^5.5.4"
Expand Down
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
testEnvironment: 'node',
// setupFilesAfterEnv: ['<rootDir>/tests/jest.setup.ts'],
transform: {
'^.+.tsx?$': ['ts-jest', {}],
},
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "printful-sdk-js-v2",
"version": "2.0.1-beta",
"version": "2.0.2-beta",
"description": "Printful SDK for Node.js / TypeScript. A wrapper for the Printful REST API (v2)",
"author": "Spencer Lepine <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -44,7 +44,7 @@
"node": ">= 18"
},
"scripts": {
"test": "echo 'No unit tests found.' && exit 0",
"test": "jest",
"bundle": "rollup -c",
"generate-sdk": "openapi --input ./openapi.json --output ./src --name PrintfulClient",
"generate-docs": "typedoc src/index.ts",
Expand All @@ -54,8 +54,10 @@
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.1.0",
"husky": "4.3.8",
"jest": "^29.7.0",
"lint-staged": "10.5.4",
"openapi-typescript-codegen": "^0.29.0",
"prettier": "2.8.8",
Expand All @@ -66,6 +68,7 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.36.0",
"ts-jest": "^29.2.3",
"tslib": "^2.6.3",
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
Expand Down
45 changes: 45 additions & 0 deletions tests/printful.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
ApprovalSheetsV2Service,
CatalogV2Service,
CountriesV2Service,
FilesV2Service,
MockupGeneratorV2Service,
OAuthScopesV2Service,
OrdersV2Service,
PrintfulClient,
ShippingRatesV2Service,
StoresV2Service,
WarehouseProductsV2Service,
WebhookV2Service,
} from '../src/index';

describe('PrintfulClient', () => {
let printful: PrintfulClient;
const accessToken = 'mockAccessToken';
const config = { TOKEN: accessToken };

beforeEach(() => {
printful = new PrintfulClient(config);
});

it('should initialize with provided config', () => {
expect(printful.request).toBeDefined();
expect(printful.approvalSheetsV2).toBeInstanceOf(ApprovalSheetsV2Service);
expect(printful.catalogV2).toBeInstanceOf(CatalogV2Service);
expect(printful.countriesV2).toBeInstanceOf(CountriesV2Service);
expect(printful.filesV2).toBeInstanceOf(FilesV2Service);
expect(printful.mockupGeneratorV2).toBeInstanceOf(MockupGeneratorV2Service);
expect(printful.oAuthScopesV2).toBeInstanceOf(OAuthScopesV2Service);
expect(printful.ordersV2).toBeInstanceOf(OrdersV2Service);
expect(printful.shippingRatesV2).toBeInstanceOf(ShippingRatesV2Service);
expect(printful.storesV2).toBeInstanceOf(StoresV2Service);
expect(printful.warehouseProductsV2).toBeInstanceOf(WarehouseProductsV2Service);
expect(printful.webhookV2).toBeInstanceOf(WebhookV2Service);
});

it('should handle missing accessToken gracefully', () => {
// @ts-expect-error - Testing for missing accessToken
const printfulMissingToken = () => new PrintfulClient({ foo: 'bar' });
expect(printfulMissingToken).not.toThrowError('accessToken is required');
});
});
Loading

0 comments on commit f32580c

Please sign in to comment.