@netlify/agent-runner-cli 1.132.0 → 1.133.0-ex-2327.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -109,6 +109,7 @@ export const config: Config = {
109
109
  | `preferStatic` | `boolean` | If `true`, static file takes precedence over function |
110
110
  | `method` | `string \| string[]` | HTTP method(s) to match (`GET`, `POST`, etc.) |
111
111
  | `schedule` | `string` | Cron expression for scheduled functions |
112
+ | `background` | `boolean` | If `true`, run in background mode (fire-and-forget) |
112
113
 
113
114
  `path` and `excludedPath` support substring patterns or the URLPattern syntax from the web platform.
114
115
 
@@ -261,11 +262,11 @@ Returns `null` outside a function invocation.
261
262
  Background functions operate the same as standard serverless functions and are syntactically the same. They run for up
262
263
  to 15 minutes without blocking the client. The client receives an immediate 202 response.
263
264
 
264
- **Naming convention:** Append `-background` to the filename.
265
+ Enable background mode by setting `background: true` in the function's config:
265
266
 
266
267
  ```typescript
267
- // netlify/functions/process-data-background.mts
268
- import type { Context } from '@netlify/functions'
268
+ // netlify/functions/process-data.mts
269
+ import type { Config, Context } from '@netlify/functions'
269
270
 
270
271
  export default async (req: Request, context: Context) => {
271
272
  const data = await req.json()
@@ -277,10 +278,14 @@ export default async (req: Request, context: Context) => {
277
278
 
278
279
  // Return value is ignored - client already received 202
279
280
  }
281
+
282
+ export const config: Config = {
283
+ background: true,
284
+ }
280
285
  ```
281
286
 
282
287
  ```javascript
283
- // netlify/functions/process-data-background.mjs
288
+ // netlify/functions/process-data.mjs
284
289
  export default async (req, context) => {
285
290
  const data = await req.json()
286
291
 
@@ -288,6 +293,10 @@ export default async (req, context) => {
288
293
  await processItem(item)
289
294
  }
290
295
  }
296
+
297
+ export const config = {
298
+ background: true,
299
+ }
291
300
  ```
292
301
 
293
302
  **Key behavior:**
@@ -295,15 +304,14 @@ export default async (req, context) => {
295
304
  - Function continues executing for up to 15 minutes
296
305
  - Response body is ignored
297
306
  - No streaming support
298
- - Cannot use `config.path` or `config.schedule`
307
+ - Cannot use `config.schedule`
299
308
  - Retry logic: first retry after 1 minute, second retry after 2 minutes on failure
300
309
  - Any data background functions produce should be stored in Netlify Blobs or a database
301
310
 
302
- **Valid background function paths:**
303
- - `netlify/functions/hello-background.mts`
304
- - `netlify/functions/hello-background/index.mts`
311
+ **Legacy filename convention:** Naming the file with a `-background` suffix (e.g., `process-data-background.mts`) is still
312
+ supported and continues to work. New functions should prefer the `config.background` property above.
305
313
 
306
- Invoke like any function: `POST /.netlify/functions/process-data-background`
314
+ Invoke like any function: `POST /.netlify/functions/process-data` (or use the `path` config property).
307
315
 
308
316
  ## Scheduled Functions
309
317
 
@@ -385,6 +393,30 @@ schedule = "@daily"
385
393
  netlify functions:invoke daily-cleanup
386
394
  ```
387
395
 
396
+ ## Region
397
+
398
+ Functions deploy to `cmh` (Ohio) by default. This is a deliberate choice: US East is centrally located for an international audience, has a broad provider ecosystem, and gives most projects the lowest overall latency without any configuration.
399
+
400
+ Do NOT override `config.region` unless the user has stated a specific reason — for example, a database or backend service in another region with measurable roundtrip savings, a data-residency requirement, or an audience concentrated in one region whose compute dependencies (database, backend services) also live in that region.
401
+
402
+ Two constraints to be aware of before adding `config.region`:
403
+
404
+ - A function runs in exactly one region. Don't try to deploy the same function to multiple regions — if the user wants geo-routing, route between distinct functions with an edge function instead.
405
+ - For framework adapter–generated functions (Next.js, Astro, Nuxt, etc.) the region must be set site-wide in the Netlify UI, not via `config.region` in code. The generated files can't carry per-function config.
406
+
407
+ See [Region](https://docs.netlify.com/build/functions/configuration#region) for the full list of supported regions and details.
408
+
409
+ ## Memory or vCPU
410
+
411
+ Functions run with 1024 MB of memory and a proportional amount of compute by default. The default fits most workloads, and raising it has a direct cost impact: function billing scales linearly with the configured size.
412
+
413
+ Do NOT set `config.memory` or `config.vcpu` speculatively. Only reach for them when:
414
+
415
+ - The workload is known to be memory- or compute-intensive (AI inference, image/PDF manipulation, large payload processing, CPU-bound work).
416
+ - The function is hitting out-of-memory errors or timeouts caused by the function's own work, rather than by waiting on an external service or database.
417
+
418
+ `memory` and `vcpu` configure the same underlying resource and are mutually exclusive — set one, not both. See [Memory or vCPU](https://docs.netlify.com/build/functions/configuration#memory-or-vcpu) for accepted values and the exact mapping.
419
+
388
420
  ## Response Streaming
389
421
 
390
422
  Synchronous functions can stream responses for large payloads (up to 20 MB):
@@ -405,6 +437,70 @@ export default async (req: Request) => {
405
437
  }
406
438
  ```
407
439
 
440
+ ## Event Handlers
441
+
442
+ A function can subscribe to platform events by exporting an object instead of a function as its default. Each event has
443
+ a named handler property.
444
+
445
+ ```typescript
446
+ import type { DeploySucceededEvent, UserSignupEvent } from '@netlify/functions'
447
+
448
+ export default {
449
+ deploySucceeded(event: DeploySucceededEvent) {
450
+ console.log(`Deploy ${event.deploy.id} succeeded`)
451
+ },
452
+
453
+ userSignup(event: UserSignupEvent) {
454
+ return {
455
+ user: {
456
+ ...event.user,
457
+ appMetadata: { ...event.user.appMetadata, roles: ['member'] },
458
+ },
459
+ }
460
+ },
461
+ }
462
+ ```
463
+
464
+ A single function can declare multiple handlers; multiple functions can also subscribe to the same event — both will run.
465
+
466
+ The default export can also be an object with a `fetch` method instead of a bare function. Prefer the bare default export shown in [Handler Signature](#handler-signature); reach for the object form only if (1) other functions in the project already use it, or (2) the same function handles HTTP requests AND subscribes to one or more platform events:
467
+
468
+ ```typescript
469
+ export default {
470
+ fetch(req: Request, context: Context) {
471
+ return new Response('Hello')
472
+ },
473
+ }
474
+ ```
475
+
476
+ **Available handlers:**
477
+
478
+ | Handler | Trigger |
479
+ |---|---|
480
+ | `fetch` | HTTP request (equivalent to a bare function default export) |
481
+ | `deployBuilding`, `deploySucceeded`, `deployFailed`, `deployDeleted`, `deployLocked`, `deployUnlocked` | Deploy lifecycle |
482
+ | `userSignup`, `userLogin`, `userValidate`, `userModified`, `userDeleted` | Identity lifecycle |
483
+ | `formSubmitted` | Form submission verified |
484
+
485
+ ### Identity handlers: deny an action
486
+
487
+ `userSignup`, `userLogin`, `userValidate`, and `userModified` can reject the action by calling `event.deny()`. The end user
488
+ receives a 401. Do NOT throw — `event.deny()` is the canonical denial mechanism and does not produce an error in observability.
489
+
490
+ ```typescript
491
+ import type { UserLoginEvent } from '@netlify/functions'
492
+
493
+ export default {
494
+ userLogin(event: UserLoginEvent) {
495
+ if (!event.user.email?.endsWith('@example.com')) {
496
+ return event.deny()
497
+ }
498
+ },
499
+ }
500
+ ```
501
+
502
+ If multiple functions subscribe to the same event, the first to call `event.deny()` aborts the chain.
503
+
408
504
  ## Limits
409
505
 
410
506
  | Resource | Limit |
@@ -418,8 +514,6 @@ export default async (req: Request) => {
418
514
  | Streaming response payload | 20 MB |
419
515
  | Functions per site | Unlimited |
420
516
 
421
- **Default deployment region:** `us-east-2` (configurable on Pro/Enterprise plans)
422
-
423
517
  ## Common Errors & Solutions
424
518
 
425
519
  ### "Function not found" (404)
@@ -404,46 +404,69 @@ TanStack Start, and SvelteKit. Remix `redirect()` is safe because Remix actions
404
404
 
405
405
  ## Identity Event Functions
406
406
 
407
- Special serverless functions that trigger on Identity lifecycle events. These use the **legacy named `handler` export**
408
- (not the modern default export) because they receive `event.body` containing the user payload.
407
+ Subscribe to Identity lifecycle events by exporting an object whose properties are named event handlers. See the
408
+ **netlify-functions** skill for the full event-handler pattern.
409
409
 
410
- Always use the legacy named `handler` export (not default export) for Identity event functions. The filename must match
411
- the event name exactly (e.g., `netlify/functions/identity-signup.mts`).
410
+ **Available identity handlers:**
412
411
 
413
- **Event names:** `identity-validate`, `identity-signup`, `identity-login`
412
+ | Handler | Trigger |
413
+ |---|---|
414
+ | `userValidate` | A user attempts to sign up. Can deny the signup. |
415
+ | `userSignup` | A user completes signup. Can deny or mutate. |
416
+ | `userLogin` | A user logs in. Can deny or mutate. |
417
+ | `userModified` | A user's profile is updated. Can deny or mutate. |
418
+ | `userDeleted` | A user is deleted. Notification only. |
414
419
 
415
- - `identity-signup` - fires when a new user signs up (email/password or OAuth)
416
- - `identity-login` - fires on each login
417
- - `identity-validate` - fires during signup before the user is created; return a non-200 status to reject
420
+ Each handler receives a typed event with a parsed `user` object (camelCase fields: `appMetadata`, `userMetadata`,
421
+ `confirmedAt`, etc.).
418
422
 
419
423
  ### Example: Assign Default Role on Signup
420
424
 
425
+ Return `{ user: ... }` to substitute the user record before it's persisted.
426
+
421
427
  ```typescript
422
- // netlify/functions/identity-signup.mts
423
- import type { Handler, HandlerEvent, HandlerContext } from '@netlify/functions'
424
-
425
- const handler: Handler = async (event: HandlerEvent, context: HandlerContext) => {
426
- const { user } = JSON.parse(event.body || '{}')
427
-
428
- return {
429
- statusCode: 200,
430
- body: JSON.stringify({
431
- app_metadata: {
432
- ...user.app_metadata,
433
- roles: ['member'],
428
+ // netlify/functions/identity.mts
429
+ import type { UserSignupEvent } from '@netlify/functions'
430
+
431
+ export default {
432
+ userSignup(event: UserSignupEvent) {
433
+ return {
434
+ user: {
435
+ ...event.user,
436
+ appMetadata: {
437
+ ...event.user.appMetadata,
438
+ roles: ['member'],
439
+ },
434
440
  },
435
- }),
436
- }
441
+ }
442
+ },
437
443
  }
444
+ ```
445
+
446
+ ### Deny an Action
447
+
448
+ Call `event.deny()` to reject a signup, login, validation, or modification. The end user receives a 401. Do NOT throw —
449
+ `event.deny()` is the canonical denial mechanism and does not produce an error in observability.
438
450
 
439
- export { handler }
451
+ ```typescript
452
+ import type { UserValidateEvent } from '@netlify/functions'
453
+
454
+ export default {
455
+ userValidate(event: UserValidateEvent) {
456
+ if (!event.user.email?.endsWith('@example.com')) {
457
+ return event.deny()
458
+ }
459
+ },
460
+ }
440
461
  ```
441
462
 
442
- The response body replaces `app_metadata` and/or `user_metadata` on the user record - include all fields you want to
443
- keep, not just new ones.
463
+ If multiple functions subscribe to the same event, the first to call `event.deny()` aborts the chain.
464
+
465
+ For bulk user management or role changes outside lifecycle events, use the `admin` API instead of Identity event functions.
444
466
 
445
- For bulk user management or role changes outside lifecycle events, use the `admin` API instead of Identity event
446
- functions.
467
+ **Legacy filename convention:** The previous syntax files named `identity-validate.ts`, `identity-signup.ts`, or
468
+ `identity-login.ts` (with a `-background` suffix for background mode), exporting `handler` and signaling denial via a
469
+ non-2xx response — still works. New functions should prefer the typed handler syntax above.
447
470
 
448
471
  ## Roles and Authorization
449
472
 
@@ -456,7 +479,7 @@ The first admin user cannot be created through code alone. You must direct the u
456
479
  3. After the user accepts the invite, click the user in the Identity list to open their detail page
457
480
  4. In the **Roles** field, add the `admin` role and save
458
481
 
459
- Once the first admin exists, subsequent users can be managed programmatically using Identity event functions (e.g., assigning roles in `identity-signup`) or role-based redirects.
482
+ Once the first admin exists, subsequent users can be managed programmatically using Identity event functions (e.g., assigning roles in the `userSignup` handler) or role-based redirects.
460
483
 
461
484
  ### Metadata Types
462
485
 
@@ -542,13 +565,15 @@ if (newToken) {
542
565
 
543
566
  ### Identity event function not triggering
544
567
 
545
- **Cause:** Filename or export format does not match expected convention.
568
+ **Cause:** Export shape does not match the expected pattern.
546
569
 
547
570
  **Fix:**
548
571
 
549
- 1. Verify filename matches exactly: `identity-signup`, `identity-validate`, or `identity-login`
550
- 2. Place in `netlify/functions/` with `.mts` or `.mjs` extension
551
- 3. Use named `handler` export (not default export)
572
+ 1. Use the typed handler syntax: default export an object with `userSignup`, `userLogin`, `userValidate`, `userModified`,
573
+ or `userDeleted` methods
574
+ 2. Place the function in `netlify/functions/` with `.mts` or `.mjs` extension
575
+ 3. If using the legacy filename convention, verify the filename matches the event exactly (`identity-signup.mts`,
576
+ `identity-validate.mts`, or `identity-login.mts`) and that the file exports a named `handler`
552
577
 
553
578
  ### `MissingIdentityError`
554
579
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@netlify/agent-runner-cli",
3
3
  "type": "module",
4
- "version": "1.132.0",
4
+ "version": "1.133.0-ex-2327.0",
5
5
  "description": "CLI tool for running Netlify agents",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -59,7 +59,7 @@
59
59
  "@commitlint/config-conventional": "^20.0.0",
60
60
  "@eslint/compat": "^2.0.0",
61
61
  "@eslint/js": "^9.35.0",
62
- "@netlify/axis": "^1.15.0",
62
+ "@netlify/axis": "^1.17.0",
63
63
  "@netlify/eslint-config-node": "^7.0.1",
64
64
  "@types/node": "^24.5.0",
65
65
  "@typescript-eslint/eslint-plugin": "^8.0.0",