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

warehouse-companies

v1.0.1

Published

Helper methods to create initial share ledgers for warehouse companies using Reguity

Downloads

1

Readme

warehouse-companies

Helper methods to create a initial share ledger for a warehouse company using Reguity

Installation

npm install warehouse-companies

createShareLedgerEventsParams can be used in a scenario where you want to sell a warehouse company that has one owner and one sharetype, given the following parameters:

  • companyId The id of the company to sell
  • sharetypeId The id of the sharetype
  • startCapital The amount of share capital that exists from the start
  • endCapital The amount of share capital to exist once the new owners have bought it
  • startQuantity The amount of shares that exist from the start
  • firstShareownerId The id of the initial owner of the first shares
  • firstDate The date on which the company was founded
  • endDate The date on which the company was sold
  • shareownerAndQuantityTuples List of objects on the form { shareownerId, quantity }, where shareownerId is the id of a new shareowner and quantity is the amount of shares that he/she should receive
  • firstRefusal Whether first refusal should be set

Example call.

Scenario: Warehouse company initially has 1000 shares and a share capital of 50000. Two shareowners want to buy it but end up owning 1200 and 1100 shares respectively, with a new share capital of 100000.

This will yeild a initial setup where we say that we initially own the 1000 shares, two transactions where we distribute the 1000 shares proportionaly to the new owners, a new share issue (doesn't change quotient value) and a split (that changes quotient value):

const { createShareLedgerEventsParams } = require('warehouse-companies');

createShareLedgerEventsParams({
  companyId: "42",
  sharetypeId: 55,
  startCapital: 50000,
  endCapital: 100000,
  startQuantity: 1000,
  firstShareownerId: "1",
  firstDate: '2018-01-01T00:00:00.000Z',
  endDate: '2018-01-02T00:00:00.000Z',
  shareownerAndQuantityTuples: [{
    shareownerId: "2",
    quantity: 1200
  }, {
    shareownerId: "3",
    quantity: 1100
  }],
  firstRefusal: true
});

/*
  =>
  [{
    companyId: "42",
    type: "Setup",
    date: "2018-01-01T00:00:00.000Z",
    shareCapitalChange: 50000,
    shareholdingChanges: [{
      startNr: 1,
      stopNr: 1000,
      buyDate: "2018-01-01T00:00:00.000Z",
      shareownerId: "1",
      sharetypeId: 55
    }]
  }, {
    companyId: "42",
    type: "Transaction",
    date: "2018-01-02T00:00:00.000Z",
    shareholdingChanges: [{
      startNr: 1,
      stopNr: 522,
      shareownerId: "2"
    }, {
      startNr: 523,
      stopNr: 1000,
      shareownerId: "1"
    }]
  }, {
    companyId: "42",
    type: "Transaction",
    date: "2018-01-02T00:00:00.000Z",
    shareholdingChanges: [{
      startNr: 523,
      stopNr: 1000,
      shareownerId: "3"
    }]
  }, {
    companyId: "42",
    type: "Newshareissue",
    shareCapitalChange: 50000,
    date: "2018-01-02T00:00:00.000Z",
    shareholdingChanges: [{
      startNr: 1001,
      stopNr: 1521,
      shareownerId: "2",
      sharetypeId: 55
    }, {
      startNr: 1522,
      stopNr: 2000,
      shareownerId: "3",
      sharetypeId: 55
    }]
  }, {
    companyId: "42",
    type: "Split",
    date: "2018-01-02T00:00:00.000Z",
    shareholdingChanges: [{
      startNr: 2001,
      stopNr: 2157,
      shareownerId: "2",
      sharetypeId: 55
    }, {
      startNr: 2158,
      stopNr: 2300,
      shareownerId: "3",
      sharetypeId: 55
    }]
  }, {
    companyId: "42",
    type: "Reservationupdate",
    date: "2018-01-02T00:00:00.000Z",
    shareholdingChanges: [{
      startNr: 1,
      stopNr: 522,
      firstRefusal: true
    }, {
      startNr: 523,
      stopNr: 1000,
      firstRefusal: true
    }, {
      startNr: 1001,
      stopNr: 1521,
      firstRefusal: true
    }, {
      startNr: 1522,
      stopNr: 2000,
      firstRefusal: true
    }, {
      startNr: 2001,
      stopNr: 2157,
      firstRefusal: true
    }, {
      startNr: 2158,
      stopNr: 2300,
      firstRefusal: true
    }]
  }]
*/

Usage with Reguity GraphQL API

The response from createShareLedgerEventsParams is an array of parameters that can used as consecutive calls to the createShareLedgerEvent mutation. One just has to iterate the response from createShareLedgerEventParams, and supply each element as the value for variable $params.

#Example using graphql-request and the example call

const { createShareLedgerEventsParams } = require('warehouse-companies');
const { request } = require('graphql-request');
const endpoint = 'https://api-dev.reguity.com';
const query = `mutation CreateShareLedgerEvent ($params: EventCreationInput!) {
  createShareLedgerEvent (params: $params) {
    code
    message
  }
}`;
let result = createShareLedgerEventsParams({
  companyId: "42",
  sharetypeId: 55,
  startCapital: 50000,
  endCapital: 100000,
  startQuantity: 1000,
  firstShareownerId: "1",
  firstDate: '2018-01-01T00:00:00.000Z',
  endDate: '2018-01-02T00:00:00.000Z',
  shareownerAndQuantityTuples: [{
    shareownerId: "2",
    quantity: 1200
  }, {
    shareownerId: "3",
    quantity: 1100
  }],
  firstRefusal: true
});
result.reduce((ack, params) => ack.then(async () => request(endpoint, query, { params })), Promise.all([]));

Done!