Skip to content

[APPS] Support uploading backend functions to app definitions#284

Draft
sdkennedy2 wants to merge 2 commits intomasterfrom
sdkennedy2/apps-backend-functions-upload
Draft

[APPS] Support uploading backend functions to app definitions#284
sdkennedy2 wants to merge 2 commits intomasterfrom
sdkennedy2/apps-backend-functions-upload

Conversation

@sdkennedy2
Copy link
Collaborator

@sdkennedy2 sdkennedy2 commented Mar 10, 2026

Motivation

High code apps need the ability to define backend functions that get bundled and published to the app definition after upload. This enables server-side logic to be co-located with the app's frontend code and automatically deployed as part of the build process.

Changes

Added a complete backend functions pipeline that runs after a successful app upload:

  1. Discovery — scans a configurable backendDir (default: backend/) for function modules. Supports both single-file (backend/myFunc.ts) and directory (backend/myFunc/index.ts) patterns.

  2. Bundling — each discovered function is bundled with esbuild into a self-contained ESM module. Node built-ins are externalized. If @datadog/action-catalog is installed, its setExecuteActionImplementation export is forced into the bundle.

  3. Transformation — bundled code is wrapped in the Action Platform script format with a main($) entry point that registers the $.Actions-based executeAction implementation and invokes the function with template-resolved args.

  4. Publishing — transformed functions are sent as ActionQuery objects to the PATCH /api/v2/app-builder/apps/{app_builder_id} endpoint.

Shared constants (NODE_EXTERNALS, ACTION_CATALOG_EXPORT_LINE, SET_EXECUTE_ACTION_SNIPPET) are extracted into backend-shared.ts for reuse by the upcoming dev server middleware.

New configuration option:

{
  apps: {
    backendDir: 'backend', // directory containing backend function modules
  }
}

QA Instructions

  1. Configure an app with a backend/ directory containing one or more function modules
  2. Run a production build with APPS_UPLOAD_ASSETS=1 and valid API/app keys
  3. Verify the app upload succeeds and backend functions are published to the app definition
  4. Confirm the function queries appear in the app definition via the App Builder API

Blast Radius

  • Only affects apps that have a backend/ directory — no impact on existing apps without backend functions
  • The publish step only runs after a successful upload and when valid auth credentials are present
  • Published package.json exports fields were updated to use standard import/require/types conditions

Documentation

@sdkennedy2 sdkennedy2 requested a review from yoannmoinet as a code owner March 10, 2026 17:38
Copy link
Collaborator Author

sdkennedy2 commented Mar 10, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant