Skip to content

feat(fn-secrets): add package for resolving function secrets from database#48

Open
theothersideofgod wants to merge 1 commit into
mainfrom
feat/fn-secrets-package
Open

feat(fn-secrets): add package for resolving function secrets from database#48
theothersideofgod wants to merge 1 commit into
mainfrom
feat/fn-secrets-package

Conversation

@theothersideofgod
Copy link
Copy Markdown
Contributor

Summary

Adds @constructive-io/fn-secrets package that enables cloud functions to resolve encrypted secrets at runtime via GraphQL instead of relying on environment variables.

  • resolveSecrets(context, functionName) - Returns Record<string, string> of resolved secrets
  • resolveSecretsRaw(options) - Returns full details including secretSource (database/global)

Motivation

Cloud functions need access to secrets (e.g., Twilio credentials) that:

  1. May differ per-tenant (database-scoped overrides)
  2. Should be stored encrypted in database, not in env vars
  3. Need fallback to global defaults when tenant-specific not set

How it works

import { resolveSecrets } from '@constructive-io/fn-secrets';

const handler = async (params, context) => {
  const secrets = await resolveSecrets(context, 'send-sms');
  // secrets = { TWILIO_ACCOUNT_SID: '...', TWILIO_AUTH_TOKEN: '...' }
};

Internally:

  1. Creates GraphQL client with X-Database-Id and X-Schemata: infra_private,infra_public
  2. Looks up function ID from default_function_definitions
  3. Calls resolveFunctionSecrets() which checks:
    • namespace = database_id (tenant-specific) first
    • Falls back to namespace = 'default' (global)

Files

File Description
src/resolve.ts Core resolution logic
src/types.ts TypeScript types
src/index.ts Public exports
__tests__/resolve.test.ts 10 unit tests

Test plan

  • pnpm test - 10 tests passing
  • pnpm build - TypeScript compiles
  • Integration test with live database (future PR)

🤖 Generated with Claude Code

…abase

Adds @constructive-io/fn-secrets package that enables cloud functions to
resolve encrypted secrets at runtime via GraphQL. Supports per-tenant
secret overrides with fallback to global defaults.

- resolveSecrets(context, functionName) - returns SecretsMap
- resolveSecretsRaw() - returns full secret details with source
- 10 unit tests covering all error cases

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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