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

feat: migrates analytics category to support in app messaging channel notifications #11158

Merged
merged 35 commits into from
Oct 14, 2022
Merged

feat: migrates analytics category to support in app messaging channel notifications #11158

merged 35 commits into from
Oct 14, 2022

Conversation

lazpavel
Copy link
Contributor

@lazpavel lazpavel commented Oct 11, 2022

Description of changes

  • migrates analytics category to support the new in-app messaging channel
  • ensures the migration gets executed when the customer executes any of the [add, remove, update] commands on the analytics or notifications category

Issue #11087

Description of how you validated changes

  • unit and e2e tests pass
  • new e2e tests added to test migration scenarios
  • manual testing

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

lazpavel and others added 28 commits September 26, 2022 15:44
* feat: in app messaging initial commit
@lazpavel lazpavel changed the base branch from dev to in-app-messaging October 11, 2022 15:28
@lazpavel lazpavel marked this pull request as ready for review October 11, 2022 21:05
@lazpavel lazpavel requested a review from a team as a code owner October 11, 2022 21:05
@lazpavel lazpavel changed the title In-app-messaging-analytics-migrations feat: migrates analytics category to support in app messaging channel notifications Oct 11, 2022
@lazpavel lazpavel changed the base branch from in-app-messaging to dev October 12, 2022 00:23
@lazpavel lazpavel changed the base branch from dev to 2493-clear-require-cache-between-lambda-invocations October 13, 2022 22:41
@lazpavel lazpavel changed the base branch from 2493-clear-require-cache-between-lambda-invocations to dev October 13, 2022 22:42
@lgtm-com
Copy link

lgtm-com bot commented Oct 14, 2022

This pull request introduces 3 alerts when merging a867eaf into 015187a - view on LGTM.com

new alerts:

  • 3 for Syntax error

}
return resourceList;
};
export const analyticsPluginAPIGetResources = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body moved as it was needed to be reused for migration logic
packages/amplify-category-analytics/src/utils/pinpoint-helper.ts

}
};

const migratePinpointCFN = (cfn: $TSAny): $TSAny => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adds pinpoint policy and properties required for in app messaging channel

* @param context amplify cli context
* @returns push command response
*/
export const authPush = async (context: $TSContext): Promise<$TSAny> => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export not needed as we could import directly in packages/amplify-category-auth/src/index.js

/**
* checks if pinpoint template contains the in app messaging policy
*/
export const pinpointTemplateHasInAppMessagingPolicy = async (context: $TSContext): Promise<boolean> => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to analytics category since it is checking a template in analytics category and it is reused in a couple of other places there for the migration purposes

@@ -17,4 +17,4 @@ export const install = async (): Promise<void> => {
};

// force minor version bump
// -
Copy link
Contributor Author

@lazpavel lazpavel Oct 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gets the cli and cli-internal version in sync, this change is tied to a feat commit

export const analyticsPluginAPIGetResources = (resourceProviderServiceName?: string, context?: $TSContext): Array<IAnalyticsResource> => {
const resourceList: Array<IAnalyticsResource> = [];
const amplifyMeta = (context) ? context.exeInfo.amplifyMeta : stateManager.getMeta();
if (amplifyMeta?.[AmplifyCategories.ANALYTICS]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method extracted in order to be reused in this category as well: packages/amplify-category-analytics/src/utils/analytics-helper.ts


/**
* Analytics category command router. Invokes functionality for all CLI calls
* @param context amplify cli context
*/
const analyticsRun = async (context:$TSContext): Promise<$TSAny> => {
export const run = async (context: $TSContext): Promise<$TSAny> => {
if (/^win/.test(process.platform)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is existing code, but why is this only executing on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const cfn = JSONUtilities.readJson(templateFilePath);
const updatedCfn = migratePinpointCFN(cfn);
fs.ensureDirSync(resourcePath);
fs.writeFileSync(templateFilePath, JSON.stringify(updatedCfn, null, 4), 'utf8');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use JSONUtilities.writeJson

`pinpoint-cloudformation-template.json`,
);
const { cfnTemplate } = readCFNTemplate(pinpointCloudFormationTemplatePath, { throwIfNotExist: false }) || {};
return !!cfnTemplate?.Parameters?.pinpointInAppMessagingPolicyName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend putting pinpointInAppMessagingPolicyName in a const that is shared between where this value is written and read to ensure it stays in sync

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

*/
export const pinpointHasInAppMessagingPolicy = (context: $TSContext): boolean => {
const resources = getAnalyticsResources(context, AmplifySupportedService.PINPOINT);
if (resources?.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flip and early return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

context.exeInfo = (context.exeInfo) || {};
context.exeInfo.inputParams = (context.exeInfo.inputParams) || {};
context.exeInfo.inputParams.yes = true; // force yes to avoid prompts
await authRunPush(context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this need to assign context.parameters.first = 'push' to force push to run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is working as is

context.exeInfo.inputParams.yes = true; // force yes to avoid prompts
await commandModule.run(context);
const authPushYes = async context => {
const exeInfoClone = Object.assign({}, (context.exeInfo) || {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think {...context?.exeInfo} does the same thing and is a little more concise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@codecov-commenter
Copy link

codecov-commenter commented Oct 14, 2022

Codecov Report

Merging #11158 (9fb0c27) into dev (015187a) will increase coverage by 0.00%.
The diff coverage is 30.00%.

@@           Coverage Diff           @@
##              dev   #11158   +/-   ##
=======================================
  Coverage   49.36%   49.36%           
=======================================
  Files         677      678    +1     
  Lines       32684    32691    +7     
  Branches     6677     6674    -3     
=======================================
+ Hits        16133    16139    +6     
- Misses      15071    15072    +1     
  Partials     1480     1480           
Impacted Files Coverage Δ
...otifications/src/notifications-amplify-meta-api.ts 16.66% <0.00%> (ø)
...lify-category-notifications/src/pinpoint-helper.ts 18.51% <0.00%> (ø)
...s/amplify-cli-core/src/errors/amplify-exception.ts 65.21% <ø> (ø)
...amplify-cli-core/src/state-manager/stateManager.ts 37.75% <0.00%> (+0.19%) ⬆️
...y-provider-awscloudformation/src/push-resources.ts 19.51% <0.00%> (ø)
packages/amplify-category-auth/src/index.js 16.50% <22.22%> (+0.22%) ⬆️
...y-notifications/src/plugin-client-api-analytics.ts 53.33% <50.00%> (-1.22%) ⬇️
...amplify-category-notifications/src/channel-apns.ts 65.04% <100.00%> (ø)
...y-category-notifications/src/channel-in-app-msg.ts 92.64% <100.00%> (+7.12%) ⬆️
...es/amplify-category-auth/src/commands/auth/push.ts 40.00% <0.00%> (ø)
... and 1 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -10224,9 +10224,9 @@ amdefine@>=0.0.4:
resolved "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
integrity sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=

amplify-codegen@^3.2.0:
amplify-codegen@^3.1.0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why is 2 in dev here? we only reference 3.1.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd check with data team. downgrading code gen doesn't feel right.
Do we reference exact 3.1.0 or ^ ?

@lazpavel lazpavel merged commit 9dfbf6c into aws-amplify:dev Oct 14, 2022
awsluja pushed a commit that referenced this pull request Oct 15, 2022
… notifications (#11158)

* feat: migrates analytics category to support in app messaging channel notifications
awsluja pushed a commit that referenced this pull request Oct 17, 2022
… notifications (#11158)

* feat: migrates analytics category to support in app messaging channel notifications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants