Skip to content

Commit

Permalink
Enable profile after manufacturing
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Dec 27, 2024
1 parent e6aee70 commit 6878622
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/cmd/esim.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const CTRL_REQUEST_APP_CUSTOM = 10;
const GET_AT_COMMAND_STATUS = 4;

const TEST_ICCID = ['89000123456789012341', '89000123456789012358'];
const TWILIO_ICCID_PREFIX = '8988307';

module.exports = class ESimCommands extends CLICommandBase {
constructor() { // TODO: Bring ui class
Expand Down Expand Up @@ -204,6 +205,26 @@ module.exports = class ESimCommands extends CLICommandBase {
return;
}

const iccidToEnable = this._getIccidToEnable(profilesMatch.details.iccidsOnDevice);
if (iccidToEnable === null) {
success = false;
await processOutput('No profile found on the device to enable');
return;
}
const enableResp = await this._enableProfile(port, iccidToEnable);
provisionOutputLogs.push(enableResp);
if (enableResp.status === 'failed') {
await processOutput();
return;
}

const verifyIccidEnabledResp = await this._verifyIccidEnaled(port, iccidToEnable);
provisionOutputLogs.push(verifyIccidEnabledResp);
if (verifyIccidEnabledResp.status === 'failed') {
await processOutput();
return;
}

success = true;
console.log(`${os.EOL}Provisioning complete for EID ${eid}`);
await processOutput();
Expand Down Expand Up @@ -592,6 +613,57 @@ module.exports = class ESimCommands extends CLICommandBase {
return stepOutput();
}

_getIccidToEnable(iccidList) {
// get the first available Twilio ICCID and if not found, get the first available profile
const twilioIccid = iccidList.find((iccid) => iccid.startsWith(TWILIO_ICCID_PREFIX));
return twilioIccid || iccidList[0] || null;
}

async _enableProfile(port, iccid) {
const res = {
step: 'enable_profile',
timestamp: new Date().toISOString().replace(/:/g, '-'),
status: 'failed',
details: {
iccid: iccid,
rawLogs: []
}
};

const enableProfileCmd = `${this.lpa} enable ${iccid} --serial=${port}`;
const enableProfileResp = await execa(this.lpa, ['enable', `${iccid}`, `--serial=${port}`]);
res.details.rawLogs.push(enableProfileResp.stdout);
res.status = enableProfileResp.stdout.includes('Profile enabled successfully') ? 'success' : 'failed';
res.details.command = enableProfileCmd;
}

async _verifyIccidEnaled(port, iccid) {
const res = {
step: 'verify_iccid_enabled',
timestamp: new Date().toISOString().replace(/:/g, '-'),
status: 'failed',
details: {
iccid: iccid,
rawLogs: []
}
};

const profilesOnDeviceAfterEnable = await this._listProfiles(port);
const iccidString = profilesOnDeviceAfterEnable.some((line) => line.includes(iccid));
if (iccidString) {
// check that you see the string 'enabled'
if (iccidString.includes('enabled')) {
res.status = 'success';
res.details.rawLogs.push(`ICCID ${iccid} enabled successfully`);
} else {
res.details.rawLogs.push(`ICCID ${iccid} not enabled`);
}
}
res.rawLogs.push(...profilesOnDeviceAfterEnable);
return res;
}


// Add the output logs to the output JSON file
// If previous data exists, append to it
_addToJson(jsonFile, data) {
Expand Down

0 comments on commit 6878622

Please sign in to comment.