eas-cli
Version:
EAS command line tool
90 lines (89 loc) • 4.24 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureAppStoreConnectAppExistsAsync = void 0;
const tslib_1 = require("tslib");
const apple_utils_1 = require("@expo/apple-utils");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const language_1 = require("./utils/language");
const authenticate_1 = require("../../credentials/ios/appstore/authenticate");
const ensureAppExists_1 = require("../../credentials/ios/appstore/ensureAppExists");
const log_1 = tslib_1.__importDefault(require("../../log"));
const bundleIdentifier_1 = require("../../project/ios/bundleIdentifier");
const prompts_1 = require("../../prompts");
async function ensureAppStoreConnectAppExistsAsync(ctx) {
const { exp } = ctx;
const { appName, language } = ctx.profile;
const options = {
...ctx.profile,
bundleIdentifier: ctx.applicationIdentifierOverride ??
ctx.profile.bundleIdentifier ??
(await (0, bundleIdentifier_1.getBundleIdentifierAsync)(ctx.projectDir, exp, ctx.vcsClient)),
appName: appName ?? exp.name ?? (await promptForAppNameAsync()),
language: (0, language_1.sanitizeLanguage)(language),
};
return await createAppStoreConnectAppAsync(ctx, options);
}
exports.ensureAppStoreConnectAppExistsAsync = ensureAppStoreConnectAppExistsAsync;
async function isProvisioningAvailableAsync(requestCtx) {
const session = apple_utils_1.Session.getAnySessionInfo();
// TODO: Investigate if username and email can be different
const username = session?.user.emailAddress;
const [user] = await apple_utils_1.User.getAsync(requestCtx, { query: { filter: { username } } });
return user.attributes.provisioningAllowed;
}
async function createAppStoreConnectAppAsync(ctx, options) {
const { appleId, appleTeamId, bundleIdentifier: bundleId, appName, language, companyName, sku, } = options;
const userAuthCtx = await ctx.credentialsCtx.appStore.ensureUserAuthenticatedAsync({
appleId,
teamId: appleTeamId,
});
const requestCtx = (0, authenticate_1.getRequestContext)(userAuthCtx);
log_1.default.addNewLineIfNone();
if (await isProvisioningAvailableAsync(requestCtx)) {
await (0, ensureAppExists_1.ensureBundleIdExistsWithNameAsync)(userAuthCtx, {
name: appName,
bundleIdentifier: bundleId,
});
}
else {
log_1.default.warn(`Provisioning is not available for Apple User: ${userAuthCtx.appleId}, skipping bundle identifier check.`);
}
let app = null;
try {
app = await (0, ensureAppExists_1.ensureAppExistsAsync)(userAuthCtx, {
name: appName,
language,
companyName,
bundleIdentifier: bundleId,
sku,
});
}
catch (error) {
if (
// Name is invalid
error.message.match(/App Name contains certain Unicode(.*)characters that are not permitted/) ||
// UnexpectedAppleResponse: An attribute value has invalid characters. - App Name contains certain Unicode symbols, emoticons, diacritics, special characters, or private use characters that are not permitted.
// Name is taken
error.message.match(/The App Name you entered is already being used/)
// UnexpectedAppleResponse: The provided entity includes an attribute with a value that has already been used on a different account. - The App Name you entered is already being used. If you have trademark rights to
// this name and would like it released for your use, submit a claim.
) {
log_1.default.addNewLineIfNone();
log_1.default.warn(`Change the name in your app config, or use a custom name with the ${chalk_1.default.bold('--app-name')} flag`);
log_1.default.newLine();
}
throw error;
}
return {
ascAppIdentifier: app.id,
};
}
async function promptForAppNameAsync() {
const { appName } = await (0, prompts_1.promptAsync)({
type: 'text',
name: 'appName',
message: 'What would you like to name your app?',
validate: (val) => val !== '' || 'App name cannot be empty!',
});
return appName;
}
;