@@ -185,7 +185,32 @@ export default class Client {
185
185
return this . fetchJson ( url , 'PUT' , JSON . stringify ( jsonData ) ) ;
186
186
}
187
187
188
- async doAfterSubmit ( addonId , newVersionId , editUrl ) {
188
+ async doFormDataPatch ( data , addonId , versionId ) {
189
+ const patchUrl = new URL (
190
+ `addon/${ addonId } /versions/${ versionId } /` ,
191
+ this . apiUrl ,
192
+ ) ;
193
+ try {
194
+ const formData = new FormData ( ) ;
195
+ for ( const field in data ) {
196
+ formData . set ( field , data [ field ] ) ;
197
+ }
198
+
199
+ const response = await this . fetch ( patchUrl , 'PATCH' , formData ) ;
200
+ if ( ! response . ok ) {
201
+ throw new Error ( `response status was ${ response . status } ` ) ;
202
+ }
203
+ } catch ( error ) {
204
+ log . info ( `Upload of ${ Object . keys ( data ) } failed: ${ error } .` ) ;
205
+ throw new Error ( `Uploading ${ Object . keys ( data ) } failed` ) ;
206
+ }
207
+ }
208
+
209
+ async doAfterSubmit ( addonId , newVersionId , editUrl , patchData ) {
210
+ if ( patchData && patchData . version ) {
211
+ log . info ( `Submitting ${ Object . keys ( patchData . version ) } to version` ) ;
212
+ await this . doFormDataPatch ( patchData . version , addonId , newVersionId ) ;
213
+ }
189
214
if ( this . approvalCheckTimeout > 0 ) {
190
215
const fileUrl = new URL (
191
216
await this . waitForApproval ( addonId , newVersionId ) ,
@@ -237,7 +262,7 @@ export default class Client {
237
262
}
238
263
239
264
async fetch ( url , method = 'GET' , body ) {
240
- log . info ( `Fetching URL: ${ url . href } ` ) ;
265
+ log . info ( `${ method } ing URL: ${ url . href } ` ) ;
241
266
let headers = {
242
267
Authorization : await this . apiAuth . getAuthHeader ( ) ,
243
268
Accept : 'application/json' ,
@@ -350,6 +375,7 @@ export default class Client {
350
375
uploadUuid ,
351
376
savedIdPath ,
352
377
metaDataJson ,
378
+ patchData ,
353
379
saveIdToFileFunc = saveIdToFile ,
354
380
) {
355
381
const {
@@ -362,15 +388,15 @@ export default class Client {
362
388
log . info ( 'You must add the following to your manifest:' ) ;
363
389
log . info ( `"browser_specific_settings": {"gecko": {"id": "${ addonId } "}}` ) ;
364
390
365
- return this . doAfterSubmit ( addonId , newVersionId , editUrl ) ;
391
+ return this . doAfterSubmit ( addonId , newVersionId , editUrl , patchData ) ;
366
392
}
367
393
368
- async putVersion ( uploadUuid , addonId , metaDataJson ) {
394
+ async putVersion ( uploadUuid , addonId , metaDataJson , patchData ) {
369
395
const {
370
396
version : { id : newVersionId , edit_url : editUrl } ,
371
397
} = await this . doNewAddonOrVersionSubmit ( addonId , uploadUuid , metaDataJson ) ;
372
398
373
- return this . doAfterSubmit ( addonId , newVersionId , editUrl ) ;
399
+ return this . doAfterSubmit ( addonId , newVersionId , editUrl , patchData ) ;
374
400
}
375
401
}
376
402
@@ -388,6 +414,7 @@ export async function signAddon({
388
414
savedIdPath,
389
415
savedUploadUuidPath,
390
416
metaDataJson = { } ,
417
+ submissionSource,
391
418
userAgentString,
392
419
SubmitClient = Client ,
393
420
ApiAuthClass = JwtApiAuth ,
@@ -396,7 +423,7 @@ export async function signAddon({
396
423
const stats = await fsPromises . stat ( xpiPath ) ;
397
424
398
425
if ( ! stats . isFile ( ) ) {
399
- throw new Error ( ` not a file: ${ xpiPath } ` ) ;
426
+ throw new Error ( ' not a file' ) ;
400
427
}
401
428
} catch ( statError ) {
402
429
throw new Error ( `error with ${ xpiPath } : ${ statError } ` ) ;
@@ -423,14 +450,33 @@ export async function signAddon({
423
450
channel ,
424
451
savedUploadUuidPath ,
425
452
) ;
453
+ const patchData = { } ;
454
+ // if we have a source file we need to upload we patch after the create
455
+ if ( submissionSource ) {
456
+ try {
457
+ const stats2 = await fsPromises . stat ( submissionSource ) ;
458
+
459
+ if ( ! stats2 . isFile ( ) ) {
460
+ throw new Error ( 'not a file' ) ;
461
+ }
462
+ } catch ( statError ) {
463
+ throw new Error ( `error with ${ submissionSource } : ${ statError } ` ) ;
464
+ }
465
+ patchData . version = { source : client . fileFromSync ( submissionSource ) } ;
466
+ }
426
467
427
468
// We specifically need to know if `id` has not been passed as a parameter because
428
469
// it's the indication that a new add-on should be created, rather than a new version.
429
470
if ( id === undefined ) {
430
- return client . postNewAddon ( uploadUuid , savedIdPath , metaDataJson ) ;
471
+ return client . postNewAddon (
472
+ uploadUuid ,
473
+ savedIdPath ,
474
+ metaDataJson ,
475
+ patchData ,
476
+ ) ;
431
477
}
432
478
433
- return client . putVersion ( uploadUuid , id , metaDataJson ) ;
479
+ return client . putVersion ( uploadUuid , id , metaDataJson , patchData ) ;
434
480
}
435
481
436
482
export async function saveIdToFile ( filePath , id ) {
0 commit comments