Skip to content

Commit

Permalink
fix: format files touched by tscontext typing (#11963)
Browse files Browse the repository at this point in the history
* fix: format
  • Loading branch information
sdstolworthy committed Feb 10, 2023
1 parent 7148d44 commit 64f8354
Show file tree
Hide file tree
Showing 30 changed files with 405 additions and 383 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"trailingComma": "all",
"singleQuote": true
}
}
61 changes: 35 additions & 26 deletions packages/amplify-category-analytics/src/analytics-resource-api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
/* eslint-disable max-depth */
/* eslint-disable spellcheck/spell-checker */
import {
AmplifyCategories, AmplifySupportedService, stateManager, IAmplifyResource,
pathManager, $TSContext, IAnalyticsResource, PluginAPIError, NotificationChannels, IPluginCapabilityAPIResponse, $TSAny, AmplifyError,
AmplifyCategories,
AmplifySupportedService,
stateManager,
IAmplifyResource,
pathManager,
$TSContext,
IAnalyticsResource,
PluginAPIError,
NotificationChannels,
IPluginCapabilityAPIResponse,
$TSAny,
AmplifyError,
} from 'amplify-cli-core';
import { getEnvParamManager } from '@aws-amplify/amplify-environment-parameters';
import { addResource } from './provider-utils/awscloudformation/index';
Expand All @@ -18,10 +28,8 @@ import { analyticsMigrations } from './migrations';
* then only return resources matching the service.
* @returns Array of resources in Analytics category (IAmplifyResource type)
*/
export const analyticsPluginAPIGetResources = (
resourceProviderServiceName?: string,
context?: $TSContext,
): Array<IAnalyticsResource> => getAnalyticsResources(context, resourceProviderServiceName);
export const analyticsPluginAPIGetResources = (resourceProviderServiceName?: string, context?: $TSContext): Array<IAnalyticsResource> =>
getAnalyticsResources(context, resourceProviderServiceName);

/**
* Create an Analytics resource of the given provider type. e.g Pinpoint or Kinesis
Expand All @@ -33,7 +41,7 @@ export const analyticsPluginAPICreateResource = async (
context: $TSContext,
resourceProviderServiceName: string,
): Promise<IAmplifyResource> => {
const resources : Array<IAmplifyResource> = analyticsPluginAPIGetResources(resourceProviderServiceName);
const resources: Array<IAmplifyResource> = analyticsPluginAPIGetResources(resourceProviderServiceName);
if (resources.length > 0) {
return resources[0];
}
Expand Down Expand Up @@ -151,10 +159,10 @@ export const analyticsPushYes = async (context: $TSContext): Promise<void> => {
const exeInfoClone = { ...context?.exeInfo };
const parametersClone = { ...context?.parameters };
try {
context.exeInfo = (context.exeInfo) || {};
context.exeInfo.inputParams = (context.exeInfo.inputParams) || {};
context.exeInfo = context.exeInfo || {};
context.exeInfo.inputParams = context.exeInfo.inputParams || {};
context.exeInfo.inputParams.yes = true; // force yes to avoid prompts
context.parameters = (context.parameters) || {};
context.parameters = context.parameters || {};
context.parameters.options.yes = true;
context.parameters.first = undefined;
await analyticsPush(context);
Expand All @@ -167,14 +175,16 @@ export const analyticsPushYes = async (context: $TSContext): Promise<void> => {
/**
* Invoke post push hook for all dependent plugins ( e.g. notifications )
*/
export const analyticsPluginAPIPostPush = async (context: $TSContext) : Promise<$TSContext> => {
export const analyticsPluginAPIPostPush = async (context: $TSContext): Promise<$TSContext> => {
const amplifyMeta = stateManager.getMeta();
let pinpointNotificationsMeta; // build this to update amplify-meta and team-provider-info.json
// update state only if analytics and notifications resources are present
if (amplifyMeta?.[AmplifyCategories.ANALYTICS]
&& Object.keys(amplifyMeta[AmplifyCategories.ANALYTICS]).length > 0
&& amplifyMeta[AmplifyCategories.NOTIFICATIONS]
&& Object.keys(amplifyMeta[AmplifyCategories.NOTIFICATIONS]).length > 0) {
if (
amplifyMeta?.[AmplifyCategories.ANALYTICS] &&
Object.keys(amplifyMeta[AmplifyCategories.ANALYTICS]).length > 0 &&
amplifyMeta[AmplifyCategories.NOTIFICATIONS] &&
Object.keys(amplifyMeta[AmplifyCategories.NOTIFICATIONS]).length > 0
) {
// Fetch Analytics data from persistent amplify-meta.json. This is expected to be updated by the push operation.
const analyticsResourceList = analyticsPluginAPIGetResources(AmplifySupportedService.PINPOINT);
const notificationsResourceName = Object.keys(amplifyMeta[AmplifyCategories.NOTIFICATIONS])[0];
Expand All @@ -185,7 +195,7 @@ export const analyticsPluginAPIPostPush = async (context: $TSContext) : Promise<
// Check if the resource is deployed to the cloud.
if (analyticsResource?.output?.Id) {
pinpointNotificationsMeta = amplifyMeta[AmplifyCategories.NOTIFICATIONS][analyticsResource.resourceName];
pinpointNotificationsMeta.Name = (pinpointNotificationsMeta.Name) || analyticsResource.output.appName;
pinpointNotificationsMeta.Name = pinpointNotificationsMeta.Name || analyticsResource.output.appName;
pinpointNotificationsMeta.Id = analyticsResource.output.Id;
pinpointNotificationsMeta.Region = analyticsResource.output.Region;
// Update Notifications output and channel metadata
Expand Down Expand Up @@ -250,7 +260,9 @@ const writeNotificationsTeamProviderInfo = async (pinpointMeta: $TSAny): Promise
// set params in the notifications and analytics resource param manager
[AmplifyCategories.NOTIFICATIONS, AmplifyCategories.ANALYTICS]
.map(category => envParamManager.getResourceParamManager(category, AmplifySupportedService.PINPOINT))
.forEach(resourceParamManager => { resourceParamManager.setAllParams(params); });
.forEach(resourceParamManager => {
resourceParamManager.setAllParams(params);
});
};

/**
Expand All @@ -263,11 +275,11 @@ const buildPolicyName = (channel: string, pinpointPolicyName: string): string =>
};

// Capability: In the future replace with "capabilities" lookup
const isSupportNotifications = (resourceProviderName: string): boolean => (resourceProviderName === AmplifySupportedService.PINPOINT);
const isSupportNotifications = (resourceProviderName: string): boolean => resourceProviderName === AmplifySupportedService.PINPOINT;

// Capability: In the future replace with "capabilities" lookup
const isSupportAnalytics = (resourceProviderName: string): boolean => (resourceProviderName === AmplifySupportedService.PINPOINT)
|| (resourceProviderName === AmplifySupportedService.KINESIS);
const isSupportAnalytics = (resourceProviderName: string): boolean =>
resourceProviderName === AmplifySupportedService.PINPOINT || resourceProviderName === AmplifySupportedService.KINESIS;

const pinpointAPIEnableNotificationChannel = (
pinpointResource: IAmplifyResource,
Expand Down Expand Up @@ -320,13 +332,10 @@ const pinpointAPIDisableNotificationChannel = (
/**
* Checks if analytics pinpoint resource has in-app messaging policy
*/
export const analyticsPluginAPIPinpointHasInAppMessagingPolicy = async (
context: $TSContext,
): Promise<boolean> => pinpointHasInAppMessagingPolicy(context);
export const analyticsPluginAPIPinpointHasInAppMessagingPolicy = async (context: $TSContext): Promise<boolean> =>
pinpointHasInAppMessagingPolicy(context);

/**
* Exposes the analytics migration API
*/
export const analyticsPluginAPIMigrations = (
context: $TSContext,
): Promise<void> => analyticsMigrations(context);
export const analyticsPluginAPIMigrations = (context: $TSContext): Promise<void> => analyticsMigrations(context);
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
$TSContext, AmplifyError,
} from 'amplify-cli-core';
import { $TSContext, AmplifyError } from 'amplify-cli-core';
import { checkResourceInUseByNotifications } from '../../plugin-client-api-notifications';

const subcommand = 'remove';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
JSONUtilities,
pathManager,
stateManager,
readCFNTemplate, writeCFNTemplate,
readCFNTemplate,
writeCFNTemplate,
} from 'amplify-cli-core';
import fs from 'fs-extra';
import * as path from 'path';
Expand Down Expand Up @@ -59,7 +60,14 @@ export const inAppMessagingMigrationCheck = async (context: $TSContext): Promise
const templateFileName = 'pinpoint-cloudformation-template.json';
const templateFilePath = path.join(analyticsResourcePath, templateFileName);
if (!fs.existsSync(templateFilePath)) {
const templateSourceFilePath = path.join(__dirname, '..', 'provider-utils', 'awscloudformation', 'cloudformation-templates', templateFileName);
const templateSourceFilePath = path.join(
__dirname,
'..',
'provider-utils',
'awscloudformation',
'cloudformation-templates',
templateFileName,
);
const { cfnTemplate } = readCFNTemplate(templateSourceFilePath);
cfnTemplate.Mappings = await getPinpointRegionMappings(context);
await writeCFNTemplate(cfnTemplate, templateFilePath);
Expand All @@ -72,7 +80,7 @@ export const inAppMessagingMigrationCheck = async (context: $TSContext): Promise
context.amplify.updateamplifyMetaAfterResourceAdd(AmplifyCategories.ANALYTICS, resource, options);

context.parameters.options.yes = true;
context.exeInfo.inputParams = (context.exeInfo.inputParams) || {};
context.exeInfo.inputParams = context.exeInfo.inputParams || {};
context.exeInfo.inputParams.yes = true;

await invokeAuthPush(context);
Expand Down Expand Up @@ -121,9 +129,7 @@ const migratePinpointCFN = (cfn: $TSAny): $TSAny => {
Statement: [
{
Effect: 'Allow',
Action: [
'mobiletargeting:GetInAppMessages',
],
Action: ['mobiletargeting:GetInAppMessages'],
Resource: [
{
'Fn::Join': [
Expand All @@ -145,10 +151,7 @@ const migratePinpointCFN = (cfn: $TSAny): $TSAny => {
},
':apps/',
{
'Fn::GetAtt': [
'PinpointFunctionOutputs',
'Id',
],
'Fn::GetAtt': ['PinpointFunctionOutputs', 'Id'],
},
'*',
],
Expand Down

0 comments on commit 64f8354

Please sign in to comment.