Skip to content

Commit

Permalink
[eas-cli] make apple team optional in appropriate cases (#468)
Browse files Browse the repository at this point in the history
* [eas-cli] make apple team optional in appropriate cases

* pr feedback
  • Loading branch information
quinlanj authored Jun 25, 2021
1 parent 2534a46 commit db29b3f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ApplePushKeyFragment, CommonIosAppCredentialsFragment } from '../../../
import Log from '../../../log';
import { Context } from '../../context';
import { AppLookupParams } from '../api/GraphqlClient';
import { AppleTeamMissingError } from '../errors';
import { resolveAppleTeamIfAuthenticatedAsync } from './AppleTeamUtils';

export class AssignPushKey {
Expand All @@ -14,15 +13,9 @@ export class AssignPushKey {
): Promise<CommonIosAppCredentialsFragment> {
const appleTeam =
(await resolveAppleTeamIfAuthenticatedAsync(ctx, this.app)) ?? pushKey.appleTeam ?? null;
if (!appleTeam) {
// TODO(quin): make this optional
throw new AppleTeamMissingError(
'An Apple Team is required to proceed. You must be authenticated to your Apple account'
);
}
const appCredentials = await ctx.ios.createOrGetIosAppCredentialsWithCommonFieldsAsync(
this.app,
{ appleTeam }
{ appleTeam: appleTeam ?? undefined }
);
const updatedAppCredentials = await ctx.ios.updateIosAppCredentialsAsync(appCredentials, {
applePushKeyId: pushKey.id,
Expand Down
21 changes: 12 additions & 9 deletions packages/eas-cli/src/credentials/ios/api/GraphqlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
IosAppBuildCredentialsFragment,
IosDistributionType,
} from '../../../graphql/generated';
import { isWildcardBundleIdentifier } from '../../../project/ios/bundleIdentifier';
import { Account } from '../../../user/Account';
import { DistributionCertificate, PushKey } from '../appstore/Credentials.types';
import { AppleTeamMissingError } from '../errors';
Expand Down Expand Up @@ -138,7 +139,7 @@ export async function createOrGetIosAppCredentialsWithCommonFieldsAsync(
{
appleTeam,
}: {
appleTeam: AppleTeamFragment;
appleTeam?: AppleTeamFragment;
}
): Promise<CommonIosAppCredentialsFragment> {
const maybeIosAppCredentials = await getIosAppCredentialsWithCommonFieldsAsync(appLookupParams);
Expand All @@ -147,10 +148,10 @@ export async function createOrGetIosAppCredentialsWithCommonFieldsAsync(
}
const [app, appleAppIdentifier] = await Promise.all([
getAppAsync(appLookupParams),
createOrGetExistingAppleAppIdentifierAsync(appLookupParams, appleTeam),
createOrGetExistingAppleAppIdentifierAsync(appLookupParams, appleTeam ?? null),
]);
return await IosAppCredentialsMutation.createIosAppCredentialsAsync(
{ appleTeamId: appleTeam.id },
{ appleTeamId: appleTeam?.id },
app.id,
appleAppIdentifier.id
);
Expand Down Expand Up @@ -181,7 +182,7 @@ async function createOrGetExistingIosAppCredentialsWithBuildCredentialsAsync(
appleAppIdentifierId,
iosDistributionType,
}: {
appleTeam: AppleTeamFragment;
appleTeam?: AppleTeamFragment;
appleAppIdentifierId: string;
iosDistributionType: IosDistributionType;
}
Expand All @@ -197,10 +198,10 @@ async function createOrGetExistingIosAppCredentialsWithBuildCredentialsAsync(
} else {
const [app, appleAppIdentifier] = await Promise.all([
getAppAsync(appLookupParams),
createOrGetExistingAppleAppIdentifierAsync(appLookupParams, appleTeam),
createOrGetExistingAppleAppIdentifierAsync(appLookupParams, appleTeam ?? null),
]);
await IosAppCredentialsMutation.createIosAppCredentialsAsync(
{ appleTeamId: appleTeam.id },
{ appleTeamId: appleTeam?.id },
app.id,
appleAppIdentifier.id
);
Expand Down Expand Up @@ -243,8 +244,10 @@ export async function createOrGetExistingAppleAppIdentifierAsync(
if (appleAppIdentifier) {
return appleAppIdentifier;
} else {
if (!appleTeam) {
throw new AppleTeamMissingError();
if (isWildcardBundleIdentifier(bundleIdentifier) && !appleTeam) {
throw new AppleTeamMissingError(
`An Apple Team is required for wildcard bundle identifier: ${bundleIdentifier}`
);
}
const parentAppleAppIdentifier = parentBundleIdentifier
? await createOrGetExistingAppleAppIdentifierAsync(
Expand All @@ -255,7 +258,7 @@ export async function createOrGetExistingAppleAppIdentifierAsync(
return await AppleAppIdentifierMutation.createAppleAppIdentifierAsync(
{
bundleIdentifier,
appleTeamId: appleTeam.id,
appleTeamId: appleTeam?.id,
parentAppleAppId: parentAppleAppIdentifier?.id,
},
account.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { promptAsync } from '../../../prompts';
import {
ensureBundleIdentifierIsDefinedForManagedProjectAsync,
getBundleIdentifier,
isWildcardBundleIdentifier,
} from '../bundleIdentifier';

jest.mock('fs');
Expand Down Expand Up @@ -141,3 +142,15 @@ describe(ensureBundleIdentifierIsDefinedForManagedProjectAsync, () => {
});
});
});

describe(isWildcardBundleIdentifier, () => {
it('classifies wildcard bundle identifiers correctly', async () => {
expect(isWildcardBundleIdentifier('doge.doge.*')).toBe(true);
expect(isWildcardBundleIdentifier('doge*')).toBe(true);

expect(isWildcardBundleIdentifier('*')).toBe(false);
expect(isWildcardBundleIdentifier('*.doge')).toBe(false);
expect(isWildcardBundleIdentifier('doge')).toBe(false);
expect(isWildcardBundleIdentifier('doge.doge.doge')).toBe(false);
});
});
5 changes: 5 additions & 0 deletions packages/eas-cli/src/project/ios/bundleIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,8 @@ function _warnIfBundleIdentifierDefinedInAppConfigForGenericProject(
export const warnIfBundleIdentifierDefinedInAppConfigForGenericProject = once(
_warnIfBundleIdentifierDefinedInAppConfigForGenericProject
);

export function isWildcardBundleIdentifier(bundleIdentifier: string): boolean {
const wildcardRegex = /^[A-Za-z0-9.-]+\*$/;
return wildcardRegex.test(bundleIdentifier);
}

0 comments on commit db29b3f

Please sign in to comment.