Socket
Socket
Sign inDemoInstall

node-apple-vpp

Package Overview
Dependencies
5
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-apple-vpp

A NodeJS Apple VPP API Client


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 25 Feb 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc