ipadtool/wipebulk.js
2025-06-09 13:32:53 -04:00

67 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
import fs from "fs";
import { info } from "./gum.js";
import { authenticate, bulk, call } from "./mosyle.js";
let serialsTxt = "";
for await (const chunk of process.stdin) {
serialsTxt += chunk;
}
const serials = serialsTxt.split("\n").filter(Boolean);
const accessToken = process.env.MOSYLE_TOKEN;
info("Authenticating...");
const token = await authenticate(
process.env.MOSYLE_USER,
process.env.MOSYLE_PASSWORD,
accessToken,
);
info("Getting devices...");
const devices = await call(
"/listdevices",
{ accessToken, serial_number: serials, options: { os: "ios" } },
token,
)
.then((res) => res.json())
.then((j) =>
j.status == "OK"
? j.response.devices.map((d) => d.deviceudid)
: console.error(j),
);
info("Changing to limbo and wiping...");
console.log(
await (
await bulk(
{
accessToken,
elements: [
{
operation: "change_to_limbo",
devices,
},
{
operation: "wipe_devices",
devices,
options: {
PreserveDataPlan: "true",
DisallowProximitySetup: "true",
RevokeVPPLicenses: "true",
EnableReturnToService: "true",
},
},
],
},
token,
)
).text(),
);
await info(
"To do more, paste this comma-separated list of serial numbers into the Mosyle search box:",
);
console.log(serials.join(","));