@d2sutils/shopper
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

Utils

https://www.npmjs.com/package/@d2sutils/shopper

Description

This is a simple utility service that provides a set of utility functions for the shopper service. The utils-npm package provides a convenient and efficient way to manage and interact with user data in your applications. Built with TypeScript, it offers strong typing and easy integration for projects using Axios for HTTP requests.

Installation

npm install 
import {user,notification, api } from "@d2sutils/shopper";

User

import {user} from "@d2sutils/shopper";
  • Users: list of users
  • List shoppers: Retrieve a list of shoppers based on provided parameters.
  • List clients: Retrieve a list of clients based on provided parameters.
  • Global Settings: Retrieve global settings for the user service.
  • Groups (Filter): Filter groups based on provided parameters.
  • Check Client ID: Verify if a user is a client based on their ID.
  • Check User ID: Quickly verify the existence of a user by their ID.
  • Get User by ID: Retrieve detailed user information by ID.
  • Current User Information: Obtain the current user's information based on a provided token.
  • Send Notifications: Easily send notifications with customizable parameters including action types, user details, and message content.

List all users

user.users({
    filter: {
        name: 'Test', // Optional filter by name
    },
    limit: 10,    
}).then(users => {
    console.log(users);
})

List shoppers

user.shoppers({
    filter: {
        name: 'Test', // Optional filter by name
    },
    limit: 10,    
}).then(users => {
    console.log(users);
})

List clients

user.clients({
    filter: {
        name: 'Test', // Optional filter by name
    },
    limit: 10,
}).then(users => {
    console.log(users);
})

Global setting

user.getSettings().then(setting => {
    console.log(setting);
})

Groups (filter)

user.groups({filter: {name:1}}).then(setting => {
    console.log(setting);
})

Check client id

const userId = 1; // Example user ID

user.isClient(userId).then(clients => {
    console.log(clients);
})

Checking if a User Exists

const userId = 1; // Example user ID
user.checkUserId(userId).then(exists => {
    console.log(exists ? 'User exists.' : 'User does not exist.');
});

Getting a User by ID

const userId = 1; // Example user ID
user.getById(userId).then(user => {
    console.log(user);
}).catch(error => {
console.error(error);
});

Getting Current User Information

const token = 'your_token_here'; // User's token
user.me(token).then(currentUser => {
    console.log(currentUser);
}).catch(error => {
console.error(error);
});

API Utils

import { api } from '@d2sutils/shopper';

API Utils provides a simple way to make HTTP requests to a RESTful API. It supports GET, POST, PUT requests with customizable headers and parameters.

api.get('users', 'list', { age: 25 })
.then(data => console.log('Users:', data))
.catch(err => console.error('Error fetching users:', err));
api.post('users', 'create', { name: 'John', age: 30 })
.then(data => console.log('User created:', data))
.catch(err => console.error('Error creating user:', err));
api.put('users', 'update/123', { name: 'Jane', age: 31 })
.then(data => console.log('User updated:', data))
.catch(err => console.error('Error updating user:', err));

Format data Utils

  • body: Format data to be sent in the body of a request.
import { format } from '@d2sutils/shopper';

Body

const data = format.body(req.body);

Locations

  • All: All locations based on parameters.
  • Groups: All groups based on parameters.
import { location } from '@d2sutils/shopper';

All locations

location.all({
    filter: {
        client_id: 1, // Optional client ID
        name: 'Test', // Optional location name
    },
    limit: 10,
    id: 1, // Optional location ID
}).then(response => {
    console.log('Locations:', response);
}).catch(error => {
    console.error('Failed to get locations:', error);
});

All groups location

location.groups({
    limit: 10,
    parent_id: 1, // Optional client ID
    name: 'Test', // Optional location name
    id: 1, // Optional location ID
}).then(response => {
    console.log('Locations:', response);
}).catch(error => {
    console.error('Failed to get locations:', error);
});

Notification

  • Send Notifications: Easily send notifications with customizable parameters including action types, user details, and message content.
import { notification } from '@d2sutils/shopper';

Sending a Notification

notification.send({
    action: 'UserRegistration', // Example action
    user_id: '12345', // Optional user ID
    contact: 'email@example.com', // Optional contact detail
    communication_id: 'abcde', // Optional communication ID
    communication_name: 'WelcomeEmail', // Optional communication name
    subject: 'Welcome to Our Service', // Optional email subject
    message: 'Thank you for registering.', // Required message content
    params: {}, // Optional additional parameters
    header: { 'Authorization': 'Bearer your_token_here' } // Optional additional headers
}).then(response => {
    console.log('Notification sent successfully:', response);
}).catch(error => {
    console.error('Failed to send notification:', error);
});

Readme

Keywords

none

Package Sidebar

Install

npm i @d2sutils/shopper

Weekly Downloads

78

Version

1.3.3

License

ISC

Unpacked Size

45.2 kB

Total Files

38

Last publish

Collaborators

  • dev2studio