Skip to content

Releases: crossplane/function-sdk-typescript

v0.3.0

10 Feb 19:18

Choose a tag to compare

v0.3.0 - CI/CD, Linting, and Dependency Updates

This release adds continuous integration workflows, code quality tooling, and updates dependencies to their latest versions.

Installation

npm install @crossplane-org/function-sdk-typescript@0.3.0

What's New

GitHub Actions CI/CD

Added comprehensive CI/CD pipeline with automated testing and validation:

  • Automated Testing: Test suite runs on every push and pull request
  • Build Validation: Ensures the project builds successfully
  • Linting: Automatic code quality checks with ESLint
  • Protobuf Generation Check: Validates that generated protobuf files are up-to-date and committed
    • CI will fail if npm run protoc-gen produces different output than what's committed
    • Ensures consistency between proto definitions and generated code

The CI workflow runs on:

  • Pushes to main branch
  • Pushes to release-* branches
  • All pull requests

Code Quality Tools

ESLint Integration: Modern ESLint configuration with TypeScript support

  • Configured with @eslint/js and typescript-eslint
  • Flat config format (eslint.config.js)
  • Lint command: npm run lint
  • Auto-fix command: npm run lint:fix

Prettier Integration: Consistent code formatting across the project

  • Configured for TypeScript, JSON, and Markdown files
  • Format command: npm run format
  • Format check: npm run format:check

VSCode Integration: Development experience improvements

  • Recommended extensions (ESLint, Prettier)
  • Auto-format on save
  • Consistent settings across contributors

Dependency Updates

Production Dependencies:

  • @grpc/grpc-js: ^1.12.4 → ^1.14.3
  • google-protobuf: ^4.0.0 → ^4.0.1
  • ts-proto: ^2.8.3 → ^2.10.1

Development Dependencies:

  • @types/node: ^22.10.5 → ^25.0.3
  • Added ESLint toolchain: eslint@^9.39.2, @eslint/js@^9.39.2, typescript-eslint@^8.52.0
  • Added prettier@^3.7.4 for code formatting

Code Formatting

All source files have been formatted with Prettier to ensure consistency:

  • Updated 23 files with consistent formatting
  • Applied modern TypeScript formatting standards
  • Improved code readability throughout the project

Testing

All existing tests continue to pass with the updated dependencies:

  • ✅ Full test suite passing
  • ✅ Coverage maintained
  • ✅ CI/CD pipeline validates all changes

Documentation

📖 README.md - Complete documentation
📖 USAGE.md - Usage guide

Requirements

  • Node.js 18+
  • TypeScript 5.9+
  • Compatible with Crossplane Function Runtime API v1

Full Changelog

Full Changelog: v0.2.0...v0.3.0

Pull Requests

  • #11: Add protobuf generation check to GitHub Actions CI
  • #10: Add GitHub Actions CI workflow
  • #9: Add ESLint and Prettier for code quality
  • #8: Update dependencies to latest versions

Commits

v0.2.0

10 Feb 19:16

Choose a tag to compare

v0.2.0 - Fixes status updates when desired Composite is undefined

This release fixes an issue where the status was not updated if the XR is undefined.

Added in this release is the the setDesiredResources function, an alternative to setDesiredComposedResources.

Installation

npm install @crossplane-org/function-sdk-typescript@0.2.0

What's New

Update Status When Composite is undefined.

Breaking Change Fix: setDesiredCompositeStatus now always sets the status field, even when the composite resource doesn't exist yet in the desired state. Previously, this function would silently fail if the composite resource wasn't already present.

This ensures that functions can reliably set status fields on composite resources without having to manually initialize the composite resource structure first.

New Helper Function

setDesiredResources: A simpler alternative to setDesiredComposedResources for common use cases.

// Before - more verbose
dcds["my-bucket"] = Resource.fromJSON({
    resource: {
        apiVersion: "s3.aws.upbound.io/v1beta1",
        kind: "Bucket",
        metadata: { name: "my-bucket" },
        spec: { forProvider: { region: "us-west-2" } }
    }
});
rsp = setDesiredComposedResources(rsp, dcds);

// After - simpler
rsp = setDesiredResources(rsp, {
    "my-bucket": {
        apiVersion: "s3.aws.upbound.io/v1beta1",
        kind: "Bucket",
        metadata: { name: "my-bucket" },
        spec: { forProvider: { region: "us-west-2" } }
    }
});

This helper automatically converts unstructured Kubernetes objects to the protobuf Resource format, reducing boilerplate when you don't need to specify readiness or connection details.

Bug Fixes

  • Fixed setDesiredCompositeStatus to properly initialize the composite resource structure before setting status, preventing silent failures

Documentation

📖 README.md - Complete documentation
📖 USAGE.md - Usage guide

Requirements

  • Node.js 18+
  • TypeScript 5.7+
  • Compatible with Crossplane Function Runtime API v1

Full Changelog

Full Changelog: v0.1.0...v0.2.0

Commits

  • update version to v0.2.0 (be73cc6)
  • update sdk to always set status (cc6e79e)

v0.1.0

10 Feb 19:15
fcddf53

Choose a tag to compare

Release Notes - v0.1.0

Initial Release

This is the first official release of the Crossplane Function SDK for TypeScript! This SDK provides a type-safe, developer-friendly way to build Crossplane Composition Functions using TypeScript/JavaScript.

Installation

npm install @crossplane-org/function-sdk-typescript

Features

Core Functionality

  • Type-Safe Function Interface - Implement the FunctionHandler interface for building custom composition functions
  • Request Helpers - Easy access to observed and desired composite resources, composed resources, input configuration, and context
  • Response Helpers - Utilities for setting desired resources, updating status, managing context, and reporting results
  • Resource Management - Full support for creating, reading, and manipulating Kubernetes resources with Protocol Buffer conversion
  • Credentials Support - Secure access to credentials passed from Crossplane
  • Context Passing - Share data between functions in a pipeline

Developer Experience

  • Full TypeScript Support - Comprehensive type definitions for all SDK interfaces and Protocol Buffer types
  • Testing Framework - Built-in Vitest testing support with coverage reporting
  • Kubernetes Integration - Seamless integration with kubernetes-models for type-safe resource creation
  • Runtime Utilities - gRPC server creation with TLS/mTLS support
  • Structured Logging - Built on Pino for fast, structured JSON logging

API Reference

Request Helpers

  • getObservedCompositeResource(req) - Get observed XR
  • getDesiredCompositeResource(req) - Get desired XR
  • getDesiredComposedResources(req) - Get desired composed resources
  • getObservedComposedResources(req) - Get observed composed resources
  • getInput(req) - Get function input configuration
  • getContextKey(req, key) - Read context from previous function
  • getRequiredResources(req) - Get required resources
  • getCredentials(req, name) - Get credentials by name

Response Helpers

  • to(req, ttl?) - Initialize response from request
  • setDesiredComposedResources(rsp, resources) - Set composed resources
  • setDesiredCompositeResource(rsp, resource) - Set desired XR
  • setDesiredCompositeStatus({rsp, status}) - Update XR status
  • setContextKey(rsp, key, value) - Set context for next function
  • setOutput(rsp, output) - Set function output
  • normal(rsp, message) - Add info result
  • warning(rsp, message) - Add warning result
  • fatal(rsp, message) - Add fatal error result
  • update(source, target) - Deep merge resources

Resource Helpers

  • fromObject(obj) - Create Resource from plain object
  • toObject(resource) - Extract plain object from Resource
  • asStruct(obj) / asObject(struct) - Convert between formats
  • newDesiredComposed() - Create new empty DesiredComposed

Runtime

  • newGrpcServer(runner, logger) - Create gRPC server
  • startServer(server, opts, logger) - Start server
  • getServerCredentials(opts) - Create server credentials

🔧 Dependencies

Runtime

  • @grpc/grpc-js ^1.12.4
  • google-protobuf ^4.0.0
  • pino ^10.1.0
  • ts-deepmerge ^7.0.3
  • ts-proto ^2.8.3
  • kubernetes-models ^4.5.1

Development

  • typescript ^5.7.2
  • vitest ^2.1.8
  • @vitest/coverage-v8 ^2.1.8
  • @types/node ^22.10.5

Documentation

  • README.md - Complete SDK documentation with examples
  • USAGE.md - Detailed usage guide and API reference

Testing

Run tests with:

npm test              # Run tests once
npm run test:watch    # Run in watch mode
npm run test:coverage # Run with coverage

🏗️ Quick Start

import {
    FunctionHandler,
    RunFunctionRequest,
    RunFunctionResponse,
    to,
    normal,
    getDesiredComposedResources,
    setDesiredComposedResources,
    Resource,
} from "@crossplane-org/function-sdk-typescript";
import type { Logger } from "@crossplane-org/function-sdk-typescript";

export class MyFunction implements FunctionHandler {
    async RunFunction(req: RunFunctionRequest, logger?: Logger): Promise<RunFunctionResponse> {
        let rsp = to(req);

        try {
            let dcds = getDesiredComposedResources(req);

            // Create resources
            dcds["my-configmap"] = Resource.fromJSON({
                resource: {
                    apiVersion: "v1",
                    kind: "ConfigMap",
                    metadata: { name: "my-config" },
                    data: { key: "value" }
                }
            });

            rsp = setDesiredComposedResources(rsp, dcds);
            normal(rsp, "Resources created successfully");

            return rsp;
        } catch (error) {
            logger?.error({ error }, "Function failed");
            fatal(rsp, error instanceof Error ? error.message : String(error));
            return rsp;
        }
    }
}

Resources


Full Changelog: Initial release v0.1.0

What's Changed

New Contributors

Full Changelog: https://github.com/upbound/function-sdk-typescript/commits/v0.1.0