UNPKG

@interaktiv/mibuilder-core

Version:

Core libraries to interact with MiBuilder projects.

157 lines (135 loc) 4.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AppleAccountManager = void 0; var _dxl = require("@interaktiv/dxl"); var _travelingFastlane = require("@interaktiv/traveling-fastlane"); var _mibuilderError = require("../mibuilder-error"); var _ux = require("../ux"); class AppleAccountManager extends _dxl.AsyncOptionalCreatable { constructor(options = {}) { super(options); this.user = options.user; this.team = options.team; this.ascTeam = options.ascTeam; } async init() { this.cliUx = await _ux.UX.create('apple-account-manager'); } async getTeam(askIfMissing = true) { if (this.team || askIfMissing !== true) return this.team; const developerTeams = await this.getTeams(); const result = await this.cliUx.prompt('Wähle dein App Store Connect Team', { name: 'teamId', options: developerTeams.map(({ id, name, type }) => ({ value: id, name: `${name} (${id}) (${type})`, short: `${id}` })) }); this.cliUx.log(''); this.team = result.teamId; return this.team; } async getTeams() { if (this.teams == null) await this.authenticate(); return this.teams.filter(Boolean).filter(t => t.status === 'active').map(({ teamId, type, name }) => ({ id: teamId, name, type })); } async getAppStoreConnectTeam(askIfMissing = true) { if (this.ascTeam || askIfMissing !== true) return this.ascTeam; const ascTeams = await this.getAppStoreConnectTeams(); const result = await this.cliUx.prompt('Wähle dein App Store Connect Team', { name: 'ascTeamId', options: ascTeams.map(({ id, name }) => ({ value: id, name: `${name} (${id})`, short: `${id}` })) }); this.cliUx.log(''); this.ascTeam = result.ascTeamId; return this.ascTeam; } async getAppStoreConnectTeams() { if (this.ascTeams) return this.ascTeams; const appleId = await this.getUser(true); const result = await (0, _travelingFastlane.runAction)(_travelingFastlane.travelingFastlane.getItcTeams, [appleId]); this.ascTeams = result.teams.map(({ contentProvider }) => ({ id: contentProvider.contentProviderId, name: contentProvider.name })); return this.ascTeams; } async findAppOnAppStoreConnect(bundleIdentifier) { const appleId = await this.getUser(true); const ascTeamId = await this.getAppStoreConnectTeam(true); const result = await (0, _travelingFastlane.runAction)(_travelingFastlane.travelingFastlane.findAppOnItc, [appleId, bundleIdentifier], { env: { FASTLANE_ITC_TEAM_ID: ascTeamId } }); return result; } async findAppOnPortal(bundleIdentifier) { const appleId = await this.getUser(true); const teamId = await this.getTeam(true); const result = await (0, _travelingFastlane.runAction)(_travelingFastlane.travelingFastlane.findAppOnPortal, [appleId, bundleIdentifier], { env: { FASTLANE_TEAM_ID: teamId } }); return result; } async getUser(askIfMissing = true) { if (this.user) return this.user; if (askIfMissing) { await this.askForLogin(); if (Boolean(this.user) === false) { throw new _mibuilderError.MiBuilderError('Fehler Apple ID Benutzername', 'InvalidAppleIdUserError'); } } return this.user; } async askForLogin() { if (this.user == null || this.user.length === 0) { const newUser = await this.cliUx.prompt('\nBenutzername (Apple Developer Account)'); if (newUser) this.user = newUser; } } async authenticate() { const appleId = await this.getUser(true); const result = await (0, _travelingFastlane.runAction)(_travelingFastlane.travelingFastlane.authenticate, [appleId]); if (result.stdout) this.cliUx.log(''); this.teams = result.teams; this.session = result.fastlaneSession; } async getAppVersions(bundleIdentifier) { const appleId = await this.getUser(true); const ascTeamId = await this.getAppStoreConnectTeam(true); const result = await (0, _travelingFastlane.runAction)(_travelingFastlane.travelingFastlane.getiOSAppVersions, [appleId, bundleIdentifier], { env: { FASTLANE_ITC_TEAM_ID: ascTeamId } }); return result; } } exports.AppleAccountManager = AppleAccountManager;