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

@lafourche/pvx-node-client

v1.4.0

Published

PVX Client

Downloads

9

Readme

PeopleVox client

The client is related to PVX and is implemented in Typescript

Get started

npm install @lafourche/pvx-node-client

Basic Usage

Init client

To init the pvx client, you will need a credentials and a wsdl url. The client will not try to authenticate until we execute a request.

import { PvxClient } from '@lafourche/pvx-node-client';

const credentials = {
  clientId: '<your-client-id>',
  username: '<your-username-id>',
  password: '<your-password>',
};

const wsdlUrl: 'https://qac.peoplevox.net/<your-client-id>/resources/integrationservicev4.asmx?wsdl';

const pvxClient = new PvxClient(credentials, wsdlUrl);

you can pass additional parameters to constructor.

Custom Logger

It must implement the following interface:

interface LoggerInterface {
  info(message: string): void;
  warn(message: string): void;
  error(message: string): void;
}

Custom Transformer

We created a transformer which roles is to convert csv raw data get from pvx to an AbstractModel. Transformer must implement the following interface:

interface TransformerInterface {
  toCSV<T extends AbstractModel>(model: T): string;
  fromCSV<T extends AbstractModel>(
    className: Constructor<T>,
    csv: string,
  ): Promise<T[]>;
}

Model

To manipulate some client method (getData, getReportData), you will need to use pre-defined Model (Item, Sale, SaleItem...) or defined a custom one by extending AbstractModel.

Structure of a Custom Model

A model must extend AbstractModel and use pre-defined Decorator (Resource and Field) to configure it.

Resource Decorator

Corresponds to Data Type defined in PVX Integration. It map ResourceName in PVX and Classname.

import { Resource } from '@lafourche/pvx-node-client';
// Resource name different with classname
@Resource('Item Type')
class Item {
  // ...
}

// The name of the resource will have the name of the class
@Resource()
class ItemInventoryReport {
  // ...
}

Field Decorator

Help us to map the serialized name with a class attribute.

import { Field } from '@lafourche/pvx-node-client';

...
class Item {
 @Field("Item Code")
 public code;

 @Field() // Field will be serialized as Barcode if not specified
 public Barcode;
}

Example of custom model

import { Field, Resource } from '@lafourche/pvx-node-client';

@Resource('Item Type')
class Item {
  @Field('Item code')
  public itemCode?: string;
  @Field('Name')
  public name?: string;
  @Field('Weight')
  public weight: number;
}

Get Data

getData is a client method for retrieving data.

In next example. We will fetch Item (A model defined in library).

import { PvxClient, Item } from '@lafourche/pvx-node-client';

class ItemRepository {
  private client: PvxClient;

  constructor(client: PvxClient) {
    this.client = client;
  }
  // ...
  async getItem(itemCode: string): Promise<Item | null> {
    const results = await this.client.getData(
      Item, // The model class here is used to retrieve the resource name
      1,
      1,
      `itemCode.Equals("${itemCode}")`,
    );

    if (results.length === 0) {
      return null;
    }

    return results[0];
  }
  // ...
}

Get Report Data

getReportData is a client method for retrieving data from Pvx system report or custom report.

In next example. We will fetch Item inventory summary (A system report from PVX).

import { PvxClient } from '@lafourche/pvx-node-client';

class InventoryReport {
  private client: PvxClient;

  constructor(client: PvxClient) {
    this.client = client;
  }
  // ...
  async getItemInventory(
    itemCode: string,
    site: string,
  ): Promise<ItemIventory[] | null> {
    const results = await this.client.getReportData(
      ItemIventory, // The model class here is used to retrieve the resource name
      1,
      10,
      `[Item code].Equals("${itemCode}") AND [Site reference].Equals("${site}")`,
    );

    if (results.length === 0) {
      return null;
    }

    return results;
  }
  // ...
}

Save Data

For saving a data, use the method saveData.

import { PvxClient, Item, Action } from '@lafourche/pvx-node-client';

class ItemRepository {
  private client: PvxClient;

  constructor(client: PvxClient) {
    this.client = client;
  }

  async addItem(item: Item): Promise<void> {
    await this.client.saveData(item, Action.NO);
  }
}

Subscribe to an event

Event covered by this client:

export enum EventType {
  AVAILABILITY_CHANGES_EVENT = 'AvailabilityChanges',
  SALES_ORDER_STATUS_CHANGES_EVENT = 'SalesOrderStatusChanges',
  GOODS_RECEIVED_EVENT = 'GoodsReceived',
  TRACKING_NUMBER_RECEIVED_EVENT = 'TrackingNumberReceived',
  INCREMENTAL_CHANGES_EVENT = 'IncrementalChanges',
  RETURNS_EVENT = 'Returns',
  DESPATCH_PACKAGE_TRACKING_NUMBER_RECEIVED_EVENT = 'DespatchPackageTrackingNumberReceived',
  DESPATCH_PACKAGE_DESPATCHED_EVENT = 'DespatchPackageDespatched',
}

In PVX we have 3 types of subscription and each one returns an integer.

Subscribe to post event

The endpoint url will be called with POST Method. Documentation

const pvxSubscriptionId = await client.subscribePostEvent(
  EventType.AVAILABILITY_CHANGES_EVENT,
  'https://endpointurl',
);

The are optional parameters:

  • postParams: string
  • filter: string
  • encodeParameterData: boolean

Subscribe to an get event

const pvxSubscriptionId = await client.SubscribeEvent(
  EventType.AVAILABILITY_CHANGES_EVENT,
  'https://myUrl/inventory/update?available={Available}&amp;inventoryItemId={Attribute3}',
);

The are optional parameters:

  • filter: string
  • encodeParameterData: boolean

See documentation for more information.

Subscribe to an event with filter on site

const pvxSubscriptionId = await client.SubscribeEventWithSitesFilters(
  EventType.AVAILABILITY_CHANGES_EVENT,
  'https://myUrl/inventory/update?available={Available}&amp;inventoryItemId={Attribute3}',
  'Site.Reference="mySite"',
);

The are optional parameters:

  • siteFilter: string
  • filter: string
  • encodeParameterData: boolean

See documentation for more information.

Unsubscribe to an event

To unsubscribe you need the id of subscription.

const pvxSubscriptionId = 69;
await client.unsubscribeEvent(pvxSubscriptionId);