@@ -3,6 +3,8 @@ import { printer, prompter } from '@aws-amplify/amplify-prompts';
33import ora from 'ora' ;
44import { ChannelAction , ChannelConfigDeploymentType , IChannelAPIResponse } from './channel-types' ;
55import { buildPinpointChannelResponseSuccess } from './pinpoint-helper' ;
6+ import { validateFilePath } from './validate-filepath' ;
7+ import fs from 'fs-extra' ;
68
79const channelName = 'FCM' ;
810const spinner = ora ( '' ) ;
@@ -42,19 +44,19 @@ export const enable = async (context: $TSContext, successMessage: string | undef
4244 if ( context . exeInfo . pinpointInputParams ?. [ channelName ] ) {
4345 answers = validateInputParams ( context . exeInfo . pinpointInputParams [ channelName ] ) ;
4446 } else {
45- let channelOutput : $TSAny = { } ;
46- if ( context . exeInfo . serviceMeta . output [ channelName ] ) {
47- channelOutput = context . exeInfo . serviceMeta . output [ channelName ] ;
48- }
4947 answers = {
50- ApiKey : await prompter . input ( 'Server Key' , { initial : channelOutput . ApiKey , transform : ( input ) => input . trim ( ) } ) ,
48+ ServiceJson : await fs . readFile (
49+ await prompter . input ( 'The service account file path (.json): ' , { validate : validateFilePath } ) ,
50+ 'utf8' ,
51+ ) ,
5152 } ;
5253 }
5354
5455 const params = {
5556 ApplicationId : context . exeInfo . serviceMeta . output . Id ,
5657 GCMChannelRequest : {
5758 ...answers ,
59+ DefaultAuthenticationMethod : 'TOKEN' ,
5860 Enabled : true ,
5961 } ,
6062 } ;
@@ -78,10 +80,10 @@ export const enable = async (context: $TSContext, successMessage: string | undef
7880} ;
7981
8082const validateInputParams = ( channelInput : $TSAny ) : $TSAny => {
81- if ( ! channelInput . ApiKey ) {
83+ if ( ! channelInput . ServiceJson ) {
8284 throw new AmplifyError ( 'UserInputError' , {
83- message : 'Server Key is missing for the FCM channel' ,
84- resolution : 'Server Key for the FCM channel ' ,
85+ message : 'ServiceJson is missing for the FCM channel' ,
86+ resolution : 'Provide the JSON from your Firebase service account json file ' ,
8587 } ) ;
8688 }
8789 return channelInput ;
@@ -97,18 +99,18 @@ export const disable = async (context: $TSContext): Promise<$TSAny> => {
9799 if ( context . exeInfo . pinpointInputParams ?. [ channelName ] ) {
98100 answers = validateInputParams ( context . exeInfo . pinpointInputParams [ channelName ] ) ;
99101 } else {
100- let channelOutput : $TSAny = { } ;
101- if ( context . exeInfo . serviceMeta . output [ channelName ] ) {
102- channelOutput = context . exeInfo . serviceMeta . output [ channelName ] ;
103- }
104102 answers = {
105- ApiKey : await prompter . input ( 'Server Key' , { initial : channelOutput . ApiKey , transform : ( input ) => input . trim ( ) } ) ,
103+ ServiceJson : await fs . readFile (
104+ await prompter . input ( 'The service account file path (.json): ' , { validate : validateFilePath } ) ,
105+ 'utf8' ,
106+ ) ,
106107 } ;
107108 }
108109 const params = {
109110 ApplicationId : context . exeInfo . serviceMeta . output . Id ,
110111 GCMChannelRequest : {
111112 ...answers ,
113+ DefaultAuthenticationMethod : 'TOKEN' ,
112114 Enabled : false ,
113115 } ,
114116 } ;
0 commit comments