0.4.0 • Published 8 months ago

@atlasrfidsolutions/avancir-sdk v0.4.0

Weekly downloads
-
License
-
Repository
github
Last release
8 months ago

Avancir SDK

Avancir API wrapper for convenience in NodeJS implementations.

Usage in Node-RED Function Nodes

Setup:

  • Double-click on the function node to open its details.
  • Select the "Setup" tab.
  • Click the "+ add" button at the bottom-left of the detail panel.
  • Enter @atlasrfidsolutions/avancir-sdk as the module name.
  • Enter avancir (for example) as the "Import as" name.
  • Select the "On Message" tab.

Create AvancirClient

const { AvancirClient } = avancir;
const api = new AvancirClient("https://dev.avancir.net/api/v1");

Note: Node-RED handles the require/import statements behind the scenes.

Make API Calls

get and getAll

async get(
  resource: string, 
  queryParams?: Record<string, any>, 
  headers?: Record<string, string>
): Promise<ApiResponse>

post

async post(
  resource: string,
  body: any,
  queryParams?: Record<string, any>,
  headers: Record<string, string> = {}
): Promise<ApiResponse>

put

async put(
  resource: string,
  body: any,
  queryParams?: Record<string, any>,
  headers: Record<string, string> = {}
): Promise<ApiResponse>

patch

async patch(
  resource: string,
  body: any,
  queryParams?: Record<string, any>,
  headers: Record<string, string> = {}
): Promise<ApiResponse>

delete

async delete(
  resource: string,
  queryParams?: Record<string, any>,
  headers: Record<string, string> = {}
): Promise<ApiResponse>

All API calls return a response that uses the following interface:

ApiResponse

interface ApiResponse {
  hasError: boolean;
  data: any;
  metadata: any;
}

Examples

const resLogin = await api.post('/auth/login', {
    "identifier": "...username...",
    "password": "...password..."
});

let defaultHeaders = { 
  "x-session-token": resLogin.data.idToken
};

// Establish current account for users with multi-account access:
await api.get('/users/me', { 
  "accountKey": "demo" 
}, defaultHeaders);

// get(...) return the first page of data
const resGetAccessLevels = await api.get('/items', {
  "type": "access_levels",
  "workspaceKey": "default"
}, defaultHeaders);

// getAll(...) returns all pages of data
const resGetAllAccessLevels = await api.getAll('/items', {
  "type": "access_levels",
  "workspaceKey": "default"
}, defaultHeaders);

// post(...) to create an item record
const resCreateItem = await api.post('/items', {
  "name": "Item 001",
  "type": {...TypeRef...},
  "status": {...StatusRef...}
}, {
  "workspaceKey": "default"
}, defaultHeaders);
0.4.0

8 months ago

0.3.1

9 months ago

0.3.0

9 months ago

0.2.2

9 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.1.0

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago