-
Notifications
You must be signed in to change notification settings - Fork 824
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
feat: migrates analytics category to support in app messaging channel notifications #11158
Conversation
* feat: in app messaging initial commit
… in-app-messaging
This pull request introduces 3 alerts when merging a867eaf into 015187a - view on LGTM.com new alerts:
|
} | ||
return resourceList; | ||
}; | ||
export const analyticsPluginAPIGetResources = ( |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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> => { |
There was a problem hiding this comment.
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> => { |
There was a problem hiding this comment.
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 | |||
// - |
There was a problem hiding this comment.
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]) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure but when I debug I never hit this, always going through https://github.com/lazpavel/amplify-cli/blob/in-app-messaging-analytics-migrations/packages/amplify-category-analytics/src/index.ts#L105
const cfn = JSONUtilities.readJson(templateFilePath); | ||
const updatedCfn = migratePinpointCFN(cfn); | ||
fs.ensureDirSync(resourcePath); | ||
fs.writeFileSync(templateFilePath, JSON.stringify(updatedCfn, null, 4), 'utf8'); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flip and early return
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) || {}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Codecov Report
@@ 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
📣 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ^ ?
… notifications (#11158) * feat: migrates analytics category to support in app messaging channel notifications
… notifications (#11158) * feat: migrates analytics category to support in app messaging channel notifications
Description of changes
add
,remove
,update
] commands on theanalytics
ornotifications
categoryIssue #11087
Description of how you validated changes
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.