Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eas-cli] make apple team optional in appropriate cases #468

Merged
merged 2 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions packages/eas-cli/graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7934,6 +7934,30 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "iosAppCredentialsList",
"description": "",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "IosAppCredentials",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down Expand Up @@ -17397,13 +17421,9 @@
"name": "appleTeamId",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
"kind": "SCALAR",
"name": "ID",
"ofType": null
},
"defaultValue": null
},
Expand Down Expand Up @@ -20249,6 +20269,12 @@
"description": "",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "DEV_CLIENT_USERS",
"description": "",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
Expand Down
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
6 changes: 4 additions & 2 deletions packages/eas-cli/src/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ export type ApplePushKey = {
keyP8: Scalars['String'];
createdAt: Scalars['DateTime'];
updatedAt: Scalars['DateTime'];
iosAppCredentialsList: Array<IosAppCredentials>;
};

export type IosAppBuildCredentialsFilter = {
Expand Down Expand Up @@ -2650,7 +2651,7 @@ export type IosAppCredentialsMutationSetAppSpecificPasswordArgs = {
};

export type IosAppCredentialsInput = {
appleTeamId: Scalars['ID'];
appleTeamId?: Maybe<Scalars['ID']>;
pushKeyId?: Maybe<Scalars['ID']>;
appSpecificPasswordId?: Maybe<Scalars['ID']>;
};
Expand Down Expand Up @@ -3182,7 +3183,8 @@ export type AddUserInput = {
};

export enum MailchimpTag {
EasMasterList = 'EAS_MASTER_LIST'
EasMasterList = 'EAS_MASTER_LIST',
DevClientUsers = 'DEV_CLIENT_USERS'
}

export enum MailchimpAudience {
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);
}