npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@d2sutils/shopper

v1.5.5

Published

This is a simple utility service that provides a set of utility functions for the shopper service.

Downloads

59

Readme

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
//const userId = [1,2,3]; // Example users ID

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

Check manager id

const userId = 1; // Example user ID
//const userId = [1,2,3]; // Example users ID

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

Checking if a User Exists

const userId = 1; // Example user ID
//const userId = [1,2,3]; // Example users 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));

Cache Utils

  • Get Cache: Retrieve data from the cache based on a key.
  • Set Cache: Store data in the cache based on a key.
  • Delete Cache: Remove data from the cache based on a key.
  • Clear Cache: Clear all data from the cache.

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);

Apply filters

import AnyModel from 'any-model';
const filter = req.params.filter; // Example filter

const data = format.applyFilter(AnyModel,filter);

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 protected]', // 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);
});