Skip to content

Commit 12fc05f

Browse files
committed
Read profiles from the device after provisioning
1 parent 3e7ebab commit 12fc05f

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/cmd/esim.js

+25-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = class eSimCommands extends CLICommandBase {
2121
this.lpa = null;
2222
this.inputJson = null;
2323
this.outputJson = null;
24+
this.downloadedProfiles = [];
2425
}
2526

2627
async provisionCommand(args) {
@@ -78,7 +79,14 @@ module.exports = class eSimCommands extends CLICommandBase {
7879

7980
// Download each profile and update the JSON output
8081
await this._doDownload(profiles, port, eid);
81-
82+
83+
const profilesOnDevice = await this._listProfiles(port);
84+
const iccids = profilesOnDevice.map((line) => line.split(' ')[4]);
85+
console.log(`${os.EOL}Profiles downloaded:`);
86+
for (const iccid of iccids) {
87+
const provider = this.downloadedProfiles.find((profile) => profile.iccid === iccid)?.provider;
88+
console.log(`\t${provider} - ${iccid}`);
89+
}
8290
console.log(`${os.EOL}Provisioning complete`);
8391
}
8492

@@ -192,6 +200,17 @@ module.exports = class eSimCommands extends CLICommandBase {
192200
async _checkForExistingProfiles(port) {
193201
console.log(`${os.EOL}Checking for existing profiles...`);
194202

203+
const profilesList = await this._listProfiles(port);
204+
205+
if (profilesList.length > 0) {
206+
console.error(`${os.EOL}Profile(s) already exist:`, profilesList);
207+
throw new Error('Profile(s) already exist. Troubleshoot manually.');
208+
}
209+
210+
console.log(`${os.EOL}No existing profiles found`);
211+
}
212+
213+
async _listProfiles(port) {
195214
const resProfiles = await execa(this.lpa, ['listProfiles', `--serial=${port}`]);
196215
const profilesOutput = resProfiles.stdout;
197216

@@ -200,12 +219,7 @@ module.exports = class eSimCommands extends CLICommandBase {
200219
.split('\n')
201220
.filter((line) => line.match(/^\d+:\[\w+,\s(?:enabled|disabled),\s?\]$/));
202221

203-
if (profilesList.length > 0) {
204-
console.error(`${os.EOL}Profile(s) already exist:`, profilesList);
205-
throw new Error('Profile(s) already exist. Troubleshoot manually.');
206-
}
207-
208-
console.log(`${os.EOL}No existing profiles found`);
222+
return profilesList;
209223
}
210224

211225
_getProfiles(eid) {
@@ -254,7 +268,10 @@ module.exports = class eSimCommands extends CLICommandBase {
254268
success: true,
255269
output,
256270
};
257-
271+
this.downloadedProfiles.push({
272+
provider: profile.provider,
273+
iccid,
274+
});
258275
this._addToJson(this.outputJson, outputData);
259276
} catch (err) {
260277
const outputData = {

0 commit comments

Comments
 (0)