@@ -47,6 +47,11 @@ import { addTimeoutToPromise } from '@apify/timeout';
47
47
import type { ChargeOptions , ChargeResult } from './charging.js' ;
48
48
import { ChargingManager } from './charging.js' ;
49
49
import { Configuration } from './configuration.js' ;
50
+ import {
51
+ getDefaultsFromInputSchema ,
52
+ noActorInputSchemaDefinedMarker ,
53
+ readInputSchema ,
54
+ } from './input-schemas.js' ;
50
55
import { KeyValueStore } from './key_value_store.js' ;
51
56
import { PlatformEventManager } from './platform_event_manager.js' ;
52
57
import type { ProxyConfigurationOptions } from './proxy_configuration.js' ;
@@ -1235,18 +1240,27 @@ export class Actor<Data extends Dictionary = Dictionary> {
1235
1240
const inputSecretsPrivateKeyPassphrase = this . config . get (
1236
1241
'inputSecretsPrivateKeyPassphrase' ,
1237
1242
) ;
1238
- const input = await this . getValue < T > ( this . config . get ( 'inputKey' ) ) ;
1243
+ const rawInput = await this . getValue < T > ( this . config . get ( 'inputKey' ) ) ;
1244
+
1245
+ let input = rawInput as T ;
1246
+
1239
1247
if (
1240
- ow . isValid ( input , ow . object . nonEmpty ) &&
1248
+ ow . isValid ( rawInput , ow . object . nonEmpty ) &&
1241
1249
inputSecretsPrivateKeyFile &&
1242
1250
inputSecretsPrivateKeyPassphrase
1243
1251
) {
1244
1252
const privateKey = createPrivateKey ( {
1245
1253
key : Buffer . from ( inputSecretsPrivateKeyFile , 'base64' ) ,
1246
1254
passphrase : inputSecretsPrivateKeyPassphrase ,
1247
1255
} ) ;
1248
- return decryptInputSecrets < T > ( { input, privateKey } ) ;
1256
+
1257
+ input = decryptInputSecrets ( { input : rawInput , privateKey } ) ;
1258
+ }
1259
+
1260
+ if ( ow . isValid ( input , ow . object . nonEmpty ) && ! Buffer . isBuffer ( input ) ) {
1261
+ input = await this . inferDefaultsFromInputSchema ( input ) ;
1249
1262
}
1263
+
1250
1264
return input ;
1251
1265
}
1252
1266
@@ -2299,4 +2313,35 @@ export class Actor<Data extends Dictionary = Dictionary> {
2299
2313
] . join ( '\n' ) ,
2300
2314
) ;
2301
2315
}
2316
+
2317
+ private async inferDefaultsFromInputSchema < T extends Dictionary > (
2318
+ input : T ,
2319
+ ) : Promise < T > {
2320
+ // TODO: https://github.com/apify/apify-shared-js/issues/547
2321
+
2322
+ // On platform, this is already handled
2323
+ if ( this . isAtHome ( ) ) {
2324
+ return input ;
2325
+ }
2326
+
2327
+ // On local, we can get the input schema from the local config
2328
+ const inputSchema = readInputSchema ( ) ;
2329
+
2330
+ // Don't emit warning if there is no input schema defined
2331
+ if ( inputSchema === noActorInputSchemaDefinedMarker ) {
2332
+ return input ;
2333
+ }
2334
+
2335
+ if ( ! inputSchema ) {
2336
+ log . warning (
2337
+ 'Failed to find the input schema for the local run of this Actor. Your input will be missing fields that have default values set if they are missing from the input you are using.' ,
2338
+ ) ;
2339
+
2340
+ return input ;
2341
+ }
2342
+
2343
+ const defaults = getDefaultsFromInputSchema ( inputSchema ) ;
2344
+
2345
+ return { ...defaults , ...input } ;
2346
+ }
2302
2347
}
0 commit comments