@@ -20,7 +20,7 @@ import { isDeepLinkTarget } from './open-target.ts';
2020import type { RawSnapshotNode } from '../utils/snapshot.ts' ;
2121import type { CliFlags } from '../utils/command-schema.ts' ;
2222import { emitDiagnostic , withDiagnosticTimer } from '../utils/diagnostics.ts' ;
23- import { looksLikeInlineJson } from '../utils/json -input.ts' ;
23+ import { resolvePayloadInput } from '../utils/payload -input.ts' ;
2424
2525export type BatchStep = {
2626 command : string ;
@@ -550,11 +550,10 @@ function clampIosSwipeDuration(durationMs: number): number {
550550}
551551
552552async function readNotificationPayload ( payloadArg : string ) : Promise < Record < string , unknown > > {
553- const trimmed = payloadArg . trim ( ) ;
554- if ( ! trimmed ) {
555- throw new AppError ( 'INVALID_ARGS' , 'push payload cannot be empty' ) ;
556- }
557- const payloadText = await resolvePushPayloadText ( payloadArg , trimmed ) ;
553+ const source = resolvePayloadInput ( payloadArg , { subject : 'Push payload' } ) ;
554+ const payloadText = source . kind === 'inline'
555+ ? source . text
556+ : await readPushPayloadFile ( source . path ) ;
558557 try {
559558 const parsed = JSON . parse ( payloadText ) as unknown ;
560559 if ( ! parsed || typeof parsed !== 'object' || Array . isArray ( parsed ) ) {
@@ -567,26 +566,23 @@ async function readNotificationPayload(payloadArg: string): Promise<Record<strin
567566 }
568567}
569568
570- async function resolvePushPayloadText ( payloadArg : string , trimmedArg : string ) : Promise < string > {
571- const filePayload = await tryReadPushPayloadFile ( payloadArg ) ;
572- if ( filePayload !== null ) return filePayload ;
573- if ( looksLikeInlineJson ( trimmedArg ) ) return trimmedArg ;
574- throw new AppError ( 'INVALID_ARGS' , `Push payload file not found: ${ payloadArg } ` ) ;
575- }
576-
577- async function tryReadPushPayloadFile ( payloadArg : string ) : Promise < string | null > {
569+ async function readPushPayloadFile ( payloadPath : string ) : Promise < string > {
578570 try {
579- return await fs . readFile ( payloadArg , 'utf8' ) ;
571+ return await fs . readFile ( payloadPath , 'utf8' ) ;
580572 } catch ( error ) {
581573 const code = ( error as NodeJS . ErrnoException ) . code ;
582- if ( code === 'ENOENT' ) return null ;
574+ if ( code === 'ENOENT' ) {
575+ throw new AppError ( 'INVALID_ARGS' , `Push payload file not found: ${ payloadPath } ` ) ;
576+ }
583577 if ( code === 'EISDIR' ) {
584- throw new AppError ( 'INVALID_ARGS' , `Push payload path is not a file: ${ payloadArg } ` ) ;
578+ throw new AppError ( 'INVALID_ARGS' , `Push payload path is not a file: ${ payloadPath } ` ) ;
585579 }
586580 if ( code === 'EACCES' || code === 'EPERM' ) {
587- throw new AppError ( 'INVALID_ARGS' , `Push payload file is not readable: ${ payloadArg } ` ) ;
581+ throw new AppError ( 'INVALID_ARGS' , `Push payload file is not readable: ${ payloadPath } ` ) ;
588582 }
589- throw new AppError ( 'COMMAND_FAILED' , `Unable to read push payload file: ${ payloadArg } ` , { cause : String ( error ) } ) ;
583+ throw new AppError ( 'COMMAND_FAILED' , `Unable to read push payload file: ${ payloadPath } ` , {
584+ cause : String ( error ) ,
585+ } ) ;
590586 }
591587}
592588
0 commit comments