<commit_before>/**
 * @flow
 * @providesModule XDLCredentials
 */

import Api from './Api';
import ErrorCode from './ErrorCode';
import XDLError from './XDLError';

export type AndroidCredentials = {
  keystore: string,
  keystoreAlias: string,
  keystorePassword: string,
  keyPassword: string,
};

export type IOSCredentials = {
  appleId?: string,
  password?: string,
  teamId?: string,
  certP12?: string,
  certPassword?: string,
  pushP12?: string,
  pushPassword?: string,
};

export type Credentials = IOSCredentials & AndroidCredentials;

export type CredentialMetadata = {
  username: string,
  experienceName: string,
  bundleIdentifier: string,
  platform: string
}

export async function credentialsExistForPlatformAsync({
  username,
  experienceName,
  bundleIdentifier,
  platform,
}: CredentialMetadata): Promise<?Credentials> {
  const { err, credentials } = await Api.callMethodAsync('getCredentials', [], 'post', {
    username,
    experienceName,
    bundleIdentifier,
    platform,
    decrypt: false,
  });

  if (err) {
    throw new Error('Error fetching credentials.');
  }

  return credentials;
}

export async function updateCredentialsForPlatform(platform: string, newCredentials: Credentials, metadata: CredentialMetadata): Promise<void> {
  const { err, credentials } = await Api.callMethodAsync('updateCredentials', [], 'post', {
    credentials: newCredentials,
    platform,
    ...metadata,
  });

  if (err || !credentials) {
    throw new Error('Error updating credentials.');
  }

  return;
}

export async function removeCredentialsForPlatform(platform: string, metadata: CredentialMetadata): Promise<void> {
  const { err } = await Api.callMethodAsync('deleteCredentials', [], 'post', {
    platform,
    ...metadata,
  });

  if (err) {
    throw new Error('Error deleting credentials.');
  }

  return;
}

export async function validateCredentialsForPlatform(
  platform: string,
  validationType: string,
  credentials: ?Credentials,
  metadata: CredentialMetadata
): Promise<void> {
  const { isValid, error, errorCode } = await Api.callMethodAsync('validateCredentials', [], 'post', {
    credentials,
    platform,
    validationType,
    ...metadata,
  });

  if (!isValid || error) {
    switch (errorCode) {
      case "ERROR_CREDENTIALS_VALIDATION_TWOFACTOR":
        throw new XDLError(ErrorCode.CREDENTIAL_ERROR, 'Two factor authentication is not yet supported. Stay tuned!');
      case "ERROR_CREDENTIALS_VALIDATION_USERPASS":
        throw new XDLError(ErrorCode.CREDENTIAL_ERROR, 'Username/Password is incorrect.');
      default:
        throw new Error('Server error when validating credentials.');
    }
  }

  return;
}

export async function fetchAppleCertificates(
  metadata: CredentialMetadata,
): Promise<void> {
  const { err, success, error, errorCode } = await Api.callMethodAsync('fetchAppleCertificates', [], 'post', {
    ...metadata,
  });

  if (err || !success || error) {
    switch (errorCode) {
      case 'ERROR_CERT_VALIDATION_MAXIMUM_CERTS_REACHED':
        throw new XDLError(ErrorCode.CREDENTIAL_ERROR, 'Maximum number of certificates have been reached in your developer portal. Please delete them or choose one of them to upload to Exponent.');
      default:
        throw new Error('Unable to fetch new certificates.');
    }
  }

  return success;
}

export async function ensureAppId(
  metadata: CredentialMetadata,
): Promise<void> {
  const { err, success } = await Api.callMethodAsync('ensureAppId', [], 'post', {
    ...metadata,
  });

  if (err || !success) {
    throw new Error('Unable to create app id.');
  }

  return success;
}

export async function fetchPushCertificates(
  metadata: CredentialMetadata,
): Promise<void> {
  const { err, success } = await Api.callMethodAsync('fetchPushCertificates', [], 'post', {
    ...metadata,
  });

  if (err || !success) {
    throw new Error('Unable to fetch push certificates.');
  }

  return success;
}
<commit_msg>Use turtle error codes and messages for iOS shell builds. (#34)<commit_after>/**
 * @flow
 * @providesModule XDLCredentials
 */

import Api from './Api';
import XDLError from './XDLError';

export type AndroidCredentials = {
  keystore: string,
  keystoreAlias: string,
  keystorePassword: string,
  keyPassword: string,
};

export type IOSCredentials = {
  appleId?: string,
  password?: string,
  teamId?: string,
  certP12?: string,
  certPassword?: string,
  pushP12?: string,
  pushPassword?: string,
};

export type Credentials = IOSCredentials & AndroidCredentials;

export type CredentialMetadata = {
  username: string,
  experienceName: string,
  bundleIdentifier: string,
  platform: string
}

export async function credentialsExistForPlatformAsync({
  username,
  experienceName,
  bundleIdentifier,
  platform,
}: CredentialMetadata): Promise<?Credentials> {
  const { err, credentials } = await Api.callMethodAsync('getCredentials', [], 'post', {
    username,
    experienceName,
    bundleIdentifier,
    platform,
    decrypt: false,
  });

  if (err) {
    throw new Error('Error fetching credentials.');
  }

  return credentials;
}

export async function updateCredentialsForPlatform(platform: string, newCredentials: Credentials, metadata: CredentialMetadata): Promise<void> {
  const { err, credentials } = await Api.callMethodAsync('updateCredentials', [], 'post', {
    credentials: newCredentials,
    platform,
    ...metadata,
  });

  if (err || !credentials) {
    throw new Error('Error updating credentials.');
  }

  return;
}

export async function removeCredentialsForPlatform(platform: string, metadata: CredentialMetadata): Promise<void> {
  const { err } = await Api.callMethodAsync('deleteCredentials', [], 'post', {
    platform,
    ...metadata,
  });

  if (err) {
    throw new Error('Error deleting credentials.');
  }

  return;
}

export async function validateCredentialsForPlatform(
  platform: string,
  validationType: string,
  credentials: ?Credentials,
  metadata: CredentialMetadata
): Promise<void> {
  const { isValid, error, errorCode, errorMessage } = await Api.callMethodAsync('validateCredentials', [], 'post', {
    credentials,
    platform,
    validationType,
    ...metadata,
  });

  if (!isValid || error) {
    throw new XDLError(errorCode, `Unable to validate credentials: ${errorMessage}`);
  }

  return;
}

export async function fetchAppleCertificates(
  metadata: CredentialMetadata,
): Promise<void> {
  const { err, success, error, errorCode, errorMessage } = await Api.callMethodAsync('fetchAppleCertificates', [], 'post', {
    ...metadata,
  });

  if (err || !success || error) {
    throw new XDLError(errorCode, `Unable to fetch distribution certificate: ${errorMessage}`);
  }

  return success;
}

export async function ensureAppId(
  metadata: CredentialMetadata,
): Promise<void> {
  const { err, success, errorCode, errorMessage } = await Api.callMethodAsync('ensureAppId', [], 'post', {
    ...metadata,
  });

  if (err || !success) {
    throw new XDLError(errorCode, `Unable to create app id: ${errorMessage}`);
  }

  return success;
}

export async function fetchPushCertificates(
  metadata: CredentialMetadata,
): Promise<void> {
  const result = await Api.callMethodAsync('fetchPushCertificates', [], 'post', {
    ...metadata,
  });



  if (result.err || !result.success) {
    throw new XDLError(result.errorCode, `Unable to fetch push certificate: ${result.errorMessage}`);
  }

  return result.success;
}

{'fraction_non_alphanumeric': 0.12197081269246218, 'fraction_numerical': 0.0013388673182487616, 'mean_word_length': 4.16955017301038, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1956111', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2166, 'n_words': 590}