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

@prism-solutions/usf-node

v1.2.3

Published

USF Node plugin

Downloads

759

Readme

USF-NODE

This node module allows you to interact with USF APIs, providing a type-safe interface for inventory management operations.

Installation

npm install usf-node

Usage

Initialize the USF object with your credentials and options:

import USF from "usf-node";

const usf = new USF({
  authorizerId: "your_authorizerId",
  secret: "your_secret",
  privateKey: "your_privateKey",
}, true); // silentReturn = true

Basic Operations

Finding Items

// Basic find
const query = {
  "entities.factoryId": "123",
  "packageQuantity": { $gt: 10 }
};
const options = {
  sort: { packageQuantity: -1 },
  limit: 10,
  select: { hardcode: 1 }
};

const items = await usf.find(query, options);

// Find with complex query
const complexQuery = {
  $or: [
    { "brandDetails.productType": "TYPE1" },
    { "factoryDetails.productType": "TYPE2" }
  ],
  "availability.reserved": { $exists: false }
};

Finding a Single Item

const item = await usf.findOne({
  hardcode: "ABC123"
}, {
  select: {
    hardcode: 1,
    "entities.factoryId": 1
  }
});

Creating Items

// Single item creation
const newItem = {
  entities: {
    factoryId: "factory123",
    brandId: "brand456"
  },
  brandDetails: {
    productReference: "REF123",
    productType: "TYPE1"
  },
  factoryDetails: {
    productId: "PROD789",
    productType: "TYPE1"
  },
  packageQuantity: 100,
  color: {
    name: "Blue"
  },
  metadata: {
    types: ["type1", "type2"]
  }
};

const created = await usf.create(newItem);

// Batch creation
const batchCreate = {
  items: [newItem, {...}],
  options: {
    ordered: true, // stops on first error
    bypassValidation: false
  }
};

const batchResult = await usf.createBatch(batchCreate);

Updating Items

// Single update
const updateQuery = { "hardcode": "ABC123" };
const updateOp = {
  $set: {
    "currentLocation.name": "New Location",
    packageQuantity: 50
  },
  $push: {
    "metadata.types": "newType"
  }
};

const updated = await usf.updateOne(updateQuery, updateOp);

// Batch update
const batchUpdates = [
  {
    filter: { "packageQuantity": { $lt: 10 } },
    update: { $set: { "availability.status": "LOW_STOCK" } },
    options: { multi: true }
  },
  {
    filter: { "hardcode": "DEF456" },
    update: { $inc: { packageQuantity: 5 } }
  }
];

const batchResult = await usf.updateBatch(batchUpdates);

Deleting Items

// Delete single item
const deleteOne = await usf.deleteOne({ hardcode: "ABC123" });

// Delete multiple items
const deleteMany = await usf.deleteMany({
  "currentLocation.id": "LOC123",
  "deleted.status": true
});

Aggregation Pipeline

const pipeline = [
  {
    $match: {
      "entities.factoryId": "factory123"
    }
  },
  {
    $group: {
      _id: "$brandDetails.productType",
      totalQuantity: { $sum: "$packageQuantity" }
    }
  },
  {
    $sort: { totalQuantity: -1 }
  }
];

const aggregateResult = await usf.aggregate(pipeline);

Response Types

Success Responses

Find Operations

interface USFItemResponse {
  id: string;
  hardcode?: string;
  entities: {
    apiId: string;
    entityId: string;
    factoryId: string;
    brandId: string;
  };
  // ... other fields
}

Batch Operations

interface BatchOperationResult {
  success: boolean;
  matchedCount?: number;
  modifiedCount?: number;
  upsertedCount?: number;
  insertedCount?: number;
  errors?: Array<{
    index: number;
    error: string;
    document?: CreateUSFItem | UpdateQuery;
  }>;
}

Error Response

interface ErrorResponse {
  error: {
    message: string;
    code: string;
  }
}

Options

FindOptions

interface FindOptions {
  sort?: { [key: string]: 1 | -1 };
  limit?: number;
  skip?: number;
  select?: { [key: string]: 0 | 1 };
}

BatchOptions

interface BatchOptions {
  ordered?: boolean;     // Stop on first error
  bypassValidation?: boolean;
  multi?: boolean;       // For updates
  upsert?: boolean;      // For updates
}

Error Handling

With silentReturn: true:

const result = await usf.find({ invalid: true });
if ('error' in result) {
  console.error('Error:', result.error);
} else {
  console.log('Items:', result);
}

With silentReturn: false:

try {
  const items = await usf.find({ invalid: true });
  console.log('Items:', items);
} catch (error) {
  console.error('Error:', error.message);
}