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

node-apple-vpp

v2.0.1

Published

A NodeJS Apple VPP API Client

Downloads

10

Readme

node-apple-vpp

Travis npm David Coverage Status

This module servers as a NodeJS wrapper around Apple's VPP API. This can be useful when building an MDM server, or anywhere you would like to monitor VPP accounts.

Usage

npm install node-apple-vpp

Methods

All methods return a Promise, except for the constructor

Constructor(options)

  • options An object containing the some of the keys below
let options = {
    stoken_path: '/path/to/token.vpptoken', //REQUIRED: Path to VPP Token File
    country_code: 'au' // Used for content metadata lookups
}

init()

Used to request the vpp service config. Required to be used before all other methods. The apple VPP API specification states that the service config should be redownloaded every 5 minutes. This module leaves that up to you to implement. An example is given below:

let vpp = new NodeAppleVPP({ stoken_path: 'test.vpptoken'});

vpp.init().then(() => {
    // Do VPP Logic Here
});
setInterval(vpp.init(), 300000)

getLicenseBatch(batchToken, sinceModifiedToken)

Retrieves a batch of licenses from VPP. Has assignedOnly set to true to avoid downloading excessive amounts of licenses.

  • batchToken The batchToken returned from a previous request
  • sinceModifiedToken The sinceModifiedToken from a previous request

Returns:

{
    status: 0,
    licenses: [
            {
                adamId:645859810,
                adamIdStr:"645859810",
                isIrrevocable:false,
                licenseId:967494668,
                licenseIdStr:"967494668",
                pricingParam:"STDQ",
                productTypeId:8,
                productTypeName:"Application",
                serialNumber:"C39N3035G68P",
                status:"Associated"
            }
    ],
    totalCount: 1,
    totalBatchCount: 1,
    sinceModifiedToken: "YzA7OSc0pTUoNSSzKLUFJAyQ6CSWgCS88JnkgAAAA=="
}

getAssets()

Retrieves a listing of assets from VPP. has licenseCounts set to true.

Returns:

{
    status: 0,
    assets: [
         {
            adamIdStr:"375380948",
            assignedCount:2,
            availableCount:8,
            deviceAssignable:true,
            isIrrevocable:false,
            pricingParam:"STDQ",
            productTypeId:8,
            productTypeName:"Application",
            retiredCount:0,
            totalCount:10
        }
    ],
    totalCount: 1
}

associateLicenseToSerial(asset, serialNumbers)

Associates a given asset to a given array of serial numbers

  • asset A required object detailing the asset to assign licenses for
let asset = {
    adamIdStr: "375380948",
    pricingParam: "STDQ"
}
  • serialNumbers An array containing serial numbers to assign the asset to
let serialNumbers = ["C39N3035G68P"]

Returns:

{
    status: 0,
    adamIdStr: "375380948",
    pricingParam: "STDQ",
    productTypeId:8,
    productTypeName:"Application",
    associations: [
        {
            "serialNumber":"C39N3035G68P",
            "licenseIdStr":"4"
        }
    ]
}

revokeLicenseToSerial(asset, serialNumbers)

Revokes a given asset from an array of serials

  • asset A required object detailing the asset to revoke licenses for
let asset = {
    adamIdStr: "375380948",
    pricingParam: "STDQ"
}
  • serialNumbers An array containing serial numbers to revoke the asset from
let serialNumbers = ["C39N3035G68P"]

Returns:

{
    status: 0,
    adamIdStr: "375380948",
    pricingParam: "STDQ",
    productTypeId:8,
    productTypeName:"Application",
    disassociations: [
        {
            "serialNumber":"C39N3035G68P",
            "licenseIdStr":"4"
        }
    ]
}

revokeLicenseByLicenseID(asset, licenseIds)

Revokes given asset for devices/users by a given array of licenseIds

  • asset A required object detailing the asset to revoke licenses for
let asset = {
    adamIdStr: "375380948",
    pricingParam: "STDQ"
}
  • licenseIds An array containing license ids to revoke the asset from
let licenseIds = ["4"]

Returns:

{
    status: 0,
    adamIdStr: "375380948",
    pricingParam: "STDQ",
    productTypeId:8,
    productTypeName:"Application",
    disassociations: [
        {
            "serialNumber":"C39N3035G68P",
            "licenseIdStr":"4"
        }
    ]
}

Examples

Multi-Batch License Download

A common problem is how to download all the licenses for a given account, as the VPP API requires batch requests for large license numbers. The code below will execute the saving mechanism before it starts the next round of downloads.

let NodeVPP = require('./src/lib/vpp');
let asyncEach = require('async/each');

let vpp = new NodeVPP({
    stoken_path: 'test.vpptoken',
    country_code: 'au'
});

return vpp.init().then(()=>{
    updateLicenseInStorage().then((sinceModifiedToken) => {
        console.log('License Download Completed!');
    });
});


function updateLicensesInStorage(startingToken){
    function callLicenseApi(batchToken, sinceModifiedToken){
        let roundResponse = {};
        return vpp.getLicenseBatch(batchToken, sinceModifiedToken)
            .then(response => {
                roundResponse = response;
                return response.licenses;
            })
            .then(updateLicenses)
            .then(() => {
                if('batchToken' in roundResponse){
                    console.log('Got Batch Token');
                    return callLicenseApi(roundResponse.batchToken);
                } else {
                    console.log('All Licenses Received, returning sinceModifiedToken');
                    return roundResponse.sinceModifiedToken;
                }

            })
    }
    function updateLicenses(licenses){
        return new Promise((resolve, reject) => {
            console.log('Beginning license import for round');
            asyncEach(licenses, (license, cb) => {
                // Do something with the license here
                console.log(`Got license: $(license.licenceIdStr)`);
            }, (err) => {
                console.log('Finished Round Import');
                if(err){
                    return reject(err)
                } else {
                    return resolve()
                }
            })
        })
    }
    return callLicenseApi(null, startingToken);
}

Testing

To test run npm test