1.0.18 • Published 7 months ago

collectid-api-client v1.0.18

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

CollectID Client Library SDK

A client SDK for Web and Node.js to interact with CollectID API.

API documentation: https://docs.collectid.io/v2

Installation

The CollectID Client Library SDK can be installed with npm:

npm install collectid-api-client

or yarn if you prefer:

yarn add collectid-api-client

Usage

Configure the SDK for your environment

The API client can be used in testing, staging and production environment. For private endpoints, the JWT token needs to be provided via tokenProvider. For public endpoints, the TokenProvider is optional.

import ApiClient from 'collectid-api-client';
import { TokenProviderFn } from './api-client';

const provideToken: TokenProviderFn = async () => {
  // return the token from the Auth0 provider
  return 'xxxxxxxxxxxx';
};

const apiClient = new ApiClient({
  env: 'prod',
  tokenProvider: provideToken,
})

Validate a Tag

To validate a tag, you can use the authenticateTag(tag: string) method. The server shall respond with successful response if the tag is valid, otherwise it will return an UnrecognizedTag exception, or EntityNotFound exception.

apiClient.authenticateTag('1234567890')
  .then((response) => {
    console.log(response);
  })
  .catch((error) => {
    console.log(error);
  });

Get the product information of the Tag

To get the product information of the tag, you can use the getProduct(tag: string, embed: string[]) method, with the optional embeddable entities.

The library is written entirely in TypeScript. The allowed embeddable entities are checked by the typescript compiler, and the IDE will provide the list of available entities.

For example,

const product = apiClient.getProduct('<tagId>', ['cid:model', 'cid:brand']);

will return the product information with the model and brand entities embedded.

To retrieve the model in the embedded section, use the following code:

const model = product.getEmbedded('cid:model');

This shall return the Embedded Model object with the relevant type information.

Features

The client SDK is currently only provide four methods to interact with the API server:

  1. Authenticate the Tag
  2. getProduct() method to retrieve product information
  3. getModel() method to retrieve Model information
  4. getBrand() method to retrieve Brand information

Todo:

  • Add methods for all entities
  • Other RESTful methods: POST, PUT, DELETE
1.0.18

7 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.15

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago