@@ -33,13 +33,24 @@ try {
3333 // Use Google Auth Library for proper JWT handling
3434 console . log ( '🔐 Getting access token using Google Auth Library...' ) ;
3535
36+ // Parse and validate service account key
37+ let serviceAccountData ;
38+ try {
39+ serviceAccountData = JSON . parse ( config . serviceAccountKey ) ;
40+ console . log ( '✅ Service account key parsed successfully' ) ;
41+ console . log ( ` Service account: ${ serviceAccountData . client_email } ` ) ;
42+ } catch ( error ) {
43+ console . error ( '❌ Failed to parse service account key:' , error . message ) ;
44+ throw new Error ( 'Invalid service account key format' ) ;
45+ }
46+
3647 const { GoogleAuth } = await import ( 'google-auth-library' ) ;
3748
3849 const auth = new GoogleAuth ( {
3950 scopes : [ 'https://www.googleapis.com/auth/chromewebstore' ] ,
4051 credentials : {
41- client_email : JSON . parse ( config . serviceAccountKey ) . client_email ,
42- private_key : JSON . parse ( config . serviceAccountKey ) . private_key ,
52+ client_email : serviceAccountData . client_email ,
53+ private_key : serviceAccountData . private_key ,
4354 }
4455 } ) ;
4556
@@ -48,21 +59,34 @@ try {
4859
4960 console . log ( '✅ Access token obtained successfully' ) ;
5061
51- // Read ZIP file
52- const zipData = fs . readFileSync ( config . zipPath ) ;
62+ // Check if we should use CRX or ZIP format
63+ const crxPath = config . zipPath . replace ( '.zip' , '.crx' ) ;
64+ let uploadData , contentType , uploadType ;
65+
66+ if ( fs . existsSync ( crxPath ) ) {
67+ console . log ( '📦 Using CRX file for upload (Chrome Web Store preferred format)' ) ;
68+ uploadData = fs . readFileSync ( crxPath ) ;
69+ contentType = 'application/x-chrome-extension' ;
70+ uploadType = 'CRX' ;
71+ } else {
72+ console . log ( '📦 Using ZIP file for upload' ) ;
73+ uploadData = fs . readFileSync ( config . zipPath ) ;
74+ contentType = 'application/zip' ;
75+ uploadType = 'ZIP' ;
76+ }
5377
5478 // Upload extension using Chrome Web Store API V2 (correct service account endpoints)
55- console . log ( ' 📤 Uploading extension...' ) ;
79+ console . log ( ` 📤 Uploading extension ( ${ uploadType } format) ...` ) ;
5680
5781 // First, initiate upload with V2 API
5882 const uploadResponse = await fetch ( `https://chromewebstore.googleapis.com/upload/v2/publishers/${ config . publisherId } /items/${ config . extensionId } :upload` , {
5983 method : 'POST' ,
6084 headers : {
6185 'Authorization' : `Bearer ${ accessToken } ` ,
62- 'Content-Type' : 'application/zip' ,
86+ 'Content-Type' : contentType ,
6387 'x-goog-upload-protocol' : 'raw'
6488 } ,
65- body : zipData
89+ body : uploadData
6690 } ) ;
6791
6892 if ( ! uploadResponse . ok ) {
77101 // Publish extension using V2 API
78102 console . log ( '🚀 Publishing extension...' ) ;
79103
80- const publishResponse = await fetch ( `https://chromewebstore.googleapis.com/v2/publishers/${ config . publisherId } /items/${ config . extensionId } / publish` , {
104+ const publishResponse = await fetch ( `https://chromewebstore.googleapis.com/v2/publishers/${ config . publisherId } /items/${ config . extensionId } : publish` , {
81105 method : 'POST' ,
82106 headers : {
83107 'Authorization' : `Bearer ${ accessToken } ` ,
0 commit comments