0.15.1 • Published 12 months ago

shoper-ts v0.15.1

Weekly downloads
27
License
MIT
Repository
github
Last release
12 months ago

Shoper REST API TypeScript client

Installation

npm i shoper-ts

Example

import { Client, AuthMethod } from "shoper-ts";

const shoper_client = new Client({
  shop_url: "https://sklep9999999.shoparena.pl",
  auth: {
    method: AuthMethod.UserPassword,
    username: "user-with-api-access",
    password: "pass",
  },
});

// Get a single product
const single_product = await shoper_client.get("products", 123);

// Get all products
const all_products = await shoper_client.list("products");

// Update product
await shoper_client.update("products", 123, {
  translations: {
    pl_PL: {
      name: "Foo Bar Deluxe",
    },
  },
});

// Insert product
await shoper_client.insert("products", {
  category_id: 1,
  translations: {
    pl_PL: {
      name: "Foo Bar Deluxe",
      active: true,
    },
  },
  // more fields go here...
});

// Lazily iterate products with stock level >= 10, sorted from latest to oldest
for await (const product of shoper_client.iterate("products", {
  sort: "edit_date desc",
  filters: {
    "stock.stock": {
      ">=": 10,
    },
  },
})) {
  console.log(product);
  if (some_condition) {
    break; // you can stop iterating at any time
  }
}

// Get categories tree
const categories_tree = await shoper_client.get("categories-tree");

Supported resources

This client supports all resources listed in Shoper REST API docs as of May 2023. The API exposes some additional resources, but because they are undocumented, this client doesn't support them.

Type checking

The client currently only checks if you are calling a valid resource/method. Only resource names are typed, otherwise everything you pass to or receive from is of any type. See official REST API docs for examples and resource schemas.

Development

You can generate a fresh list of resources to be pasted into src/resources.ts using generate-resources.js script. Go to Shoper REST API docs, open your browser's dev tools, inspect the ul element REST API -> Resources, and execute the script in the console.

0.15.0

12 months ago

0.15.1

12 months ago

0.14.7

3 years ago

0.14.5

3 years ago

0.14.6

3 years ago

0.14.2

3 years ago

0.14.3

3 years ago

0.14.4

3 years ago

0.14.1

4 years ago

0.14.0

4 years ago

0.13.0

4 years ago

0.12.0

4 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago