Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
node-apple-vpp
Advanced tools
Readme
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.
npm install node-apple-vpp
All methods return a Promise, except for the constructor
options
An object containing the some of the keys belowlet options = {
stoken_path: '/path/to/token.vpptoken', //REQUIRED: Path to VPP Token File
country_code: 'au' // Used for content metadata lookups
}
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)
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 requestsinceModifiedToken
The sinceModifiedToken from a previous requestReturns:
{
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=="
}
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
}
Associates a given asset to a given array of serial numbers
asset
A required object detailing the asset to assign licenses forlet asset = {
adamIdStr: "375380948",
pricingParam: "STDQ"
}
serialNumbers
An array containing serial numbers to assign the asset tolet serialNumbers = ["C39N3035G68P"]
Returns:
{
status: 0,
adamIdStr: "375380948",
pricingParam: "STDQ",
productTypeId:8,
productTypeName:"Application",
associations: [
{
"serialNumber":"C39N3035G68P",
"licenseIdStr":"4"
}
]
}
Revokes a given asset from an array of serials
asset
A required object detailing the asset to revoke licenses forlet asset = {
adamIdStr: "375380948",
pricingParam: "STDQ"
}
serialNumbers
An array containing serial numbers to revoke the asset fromlet serialNumbers = ["C39N3035G68P"]
Returns:
{
status: 0,
adamIdStr: "375380948",
pricingParam: "STDQ",
productTypeId:8,
productTypeName:"Application",
disassociations: [
{
"serialNumber":"C39N3035G68P",
"licenseIdStr":"4"
}
]
}
Revokes given asset for devices/users by a given array of licenseIds
asset
A required object detailing the asset to revoke licenses forlet asset = {
adamIdStr: "375380948",
pricingParam: "STDQ"
}
licenseIds
An array containing license ids to revoke the asset fromlet licenseIds = ["4"]
Returns:
{
status: 0,
adamIdStr: "375380948",
pricingParam: "STDQ",
productTypeId:8,
productTypeName:"Application",
disassociations: [
{
"serialNumber":"C39N3035G68P",
"licenseIdStr":"4"
}
]
}
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);
}
To test run npm test
FAQs
A NodeJS Apple VPP API Client
We found that node-apple-vpp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).