@@ -16,6 +16,18 @@ import type {
1616 World ,
1717} from '@workflow/world' ;
1818import chalk from 'chalk' ;
19+
20+ /** A function that resolves an encryption key for a given runId. */
21+ export type EncryptionKeyResolver =
22+ | ( ( runId : string ) => Promise < Uint8Array | undefined > )
23+ | null ;
24+
25+ /** Create an EncryptionKeyResolver from a World instance */
26+ function createResolver ( world : World ) : EncryptionKeyResolver {
27+ if ( ! world . getEncryptionKeyForRun ) return null ;
28+ return ( runId : string ) => world . getEncryptionKeyForRun ! ( runId ) ;
29+ }
30+
1931import { formatDistance } from 'date-fns' ;
2032import Table from 'easy-table' ;
2133import { logger } from '../config/log.js' ;
@@ -507,6 +519,7 @@ const inlineFormatIO = <T>(io: T, topLevel: boolean = true): string => {
507519} ;
508520
509521export const listRuns = async ( world : World , opts : InspectCLIOptions = { } ) => {
522+ const resolveKey = createResolver ( world ) ;
510523 if ( opts . stepId || opts . runId ) {
511524 logger . warn (
512525 'Filtering by step-id or run-id is not supported in list calls, ignoring filter.'
@@ -535,7 +548,7 @@ export const listRuns = async (world: World, opts: InspectCLIOptions = {}) => {
535548 resolveData,
536549 } ) ;
537550 const runsWithHydratedIO = await Promise . all (
538- runs . data . map ( hydrateResourceIO )
551+ runs . data . map ( ( r ) => hydrateResourceIO ( r , resolveKey ) )
539552 ) ;
540553 showJson ( { ...runs , data : runsWithHydratedIO } ) ;
541554 return ;
@@ -574,7 +587,9 @@ export const listRuns = async (world: World, opts: InspectCLIOptions = {}) => {
574587 }
575588 } ,
576589 displayPage : async ( runs ) => {
577- const runsWithHydratedIO = await Promise . all ( runs . map ( hydrateResourceIO ) ) ;
590+ const runsWithHydratedIO = await Promise . all (
591+ runs . map ( ( r ) => hydrateResourceIO ( r , resolveKey ) )
592+ ) ;
578593 logger . log ( showTable ( runsWithHydratedIO , props , opts ) ) ;
579594 } ,
580595 } ) ;
@@ -584,13 +599,16 @@ export const getRecentRun = async (
584599 world : World ,
585600 opts : InspectCLIOptions = { }
586601) => {
602+ const resolveKey = createResolver ( world ) ;
587603 logger . warn ( `No runId provided, fetching data for latest run instead.` ) ;
588604 try {
589605 const runs = await world . runs . list ( {
590606 pagination : { limit : 1 , sortOrder : opts . sort || 'desc' } ,
591607 resolveData : 'none' , // Don't need data for just getting the ID
592608 } ) ;
593- runs . data = await Promise . all ( runs . data . map ( hydrateResourceIO ) ) ;
609+ runs . data = await Promise . all (
610+ runs . data . map ( ( r ) => hydrateResourceIO ( r , resolveKey ) )
611+ ) ;
594612 return runs . data [ 0 ] ;
595613 } catch ( error ) {
596614 if ( handleApiError ( error , opts . backend ) ) {
@@ -605,12 +623,13 @@ export const showRun = async (
605623 runId : string ,
606624 opts : InspectCLIOptions = { }
607625) => {
626+ const resolveKey = createResolver ( world ) ;
608627 if ( opts . withData ) {
609628 logger . warn ( '`withData` flag is ignored when showing individual resources' ) ;
610629 }
611630 try {
612631 const run = await world . runs . get ( runId , { resolveData : 'all' } ) ;
613- const runWithHydratedIO = await hydrateResourceIO ( run ) ;
632+ const runWithHydratedIO = await hydrateResourceIO ( run , resolveKey ) ;
614633 if ( opts . json ) {
615634 showJson ( runWithHydratedIO ) ;
616635 return ;
@@ -636,6 +655,7 @@ export const listSteps = async (
636655 runId : undefined ,
637656 }
638657) => {
658+ const resolveKey = createResolver ( world ) ;
639659 if ( opts . stepId ) {
640660 logger . warn (
641661 'Filtering by step-id is not supported in list calls, ignoring filter.'
@@ -714,7 +734,7 @@ export const listSteps = async (
714734 } ,
715735 displayPage : async ( steps ) => {
716736 const stepsWithHydratedIO = await Promise . all (
717- steps . map ( hydrateResourceIO )
737+ steps . map ( ( s ) => hydrateResourceIO ( s , resolveKey ) )
718738 ) ;
719739 logger . log ( showTable ( stepsWithHydratedIO , props , opts ) ) ;
720740 showInspectInfoBox ( 'step' ) ;
@@ -727,6 +747,7 @@ export const showStep = async (
727747 stepId : string ,
728748 opts : InspectCLIOptions = { }
729749) => {
750+ const resolveKey = createResolver ( world ) ;
730751 if ( opts . withData ) {
731752 logger . warn ( '`withData` flag is ignored when showing individual resources' ) ;
732753 }
@@ -739,7 +760,7 @@ export const showStep = async (
739760 const step = await world . steps . get ( opts . runId , stepId , {
740761 resolveData : 'all' ,
741762 } ) ;
742- const stepWithHydratedIO = await hydrateResourceIO ( step ) ;
763+ const stepWithHydratedIO = await hydrateResourceIO ( step , resolveKey ) ;
743764 if ( opts . json ) {
744765 showJson ( stepWithHydratedIO ) ;
745766 return ;
@@ -923,6 +944,7 @@ export const listEvents = async (
923944} ;
924945
925946export const listHooks = async ( world : World , opts : InspectCLIOptions = { } ) => {
947+ const resolveKey = createResolver ( world ) ;
926948 if ( opts . workflowName ) {
927949 logger . warn (
928950 'Filtering by workflow-name is not supported for hooks, ignoring filter.'
@@ -955,7 +977,7 @@ export const listHooks = async (world: World, opts: InspectCLIOptions = {}) => {
955977 resolveData,
956978 } ) ;
957979 const hydratedHooks = await Promise . all (
958- hooks . data . map ( hydrateResourceIO )
980+ hooks . data . map ( ( h ) => hydrateResourceIO ( h , resolveKey ) )
959981 ) ;
960982 showJson ( { ...hooks , data : hydratedHooks } ) ;
961983 return ;
@@ -1000,7 +1022,9 @@ export const listHooks = async (world: World, opts: InspectCLIOptions = {}) => {
10001022 }
10011023 } ,
10021024 displayPage : async ( hooks ) => {
1003- const hydratedHooks = await Promise . all ( hooks . map ( hydrateResourceIO ) ) ;
1025+ const hydratedHooks = await Promise . all (
1026+ hooks . map ( ( h ) => hydrateResourceIO ( h , resolveKey ) )
1027+ ) ;
10041028 logger . log ( showTable ( hydratedHooks , HOOK_LISTED_PROPS , opts ) ) ;
10051029 showInspectInfoBox ( 'hook' ) ;
10061030 } ,
@@ -1012,14 +1036,15 @@ export const showHook = async (
10121036 hookId : string ,
10131037 opts : InspectCLIOptions = { }
10141038) => {
1039+ const resolveKey = createResolver ( world ) ;
10151040 if ( opts . withData ) {
10161041 logger . warn ( '`withData` flag is ignored when showing individual resources' ) ;
10171042 }
10181043 try {
10191044 const hook = await world . hooks . get ( hookId , {
10201045 resolveData : 'all' ,
10211046 } ) ;
1022- const hydratedHook = await hydrateResourceIO ( hook ) ;
1047+ const hydratedHook = await hydrateResourceIO ( hook , resolveKey ) ;
10231048 if ( opts . json ) {
10241049 showJson ( hydratedHook ) ;
10251050 return ;
0 commit comments