# Service provider SDK — proposed v0.1

Every application dependency is a typed resource with a full lifecycle, not just a container definition. Shared engines, app-specific resources and bindings are separate entities. Example: one Postgres engine, multiple databases/roles, several application processes with specifically allowed bindings. Never delete the engine as part of deleting one app's database. An external service implementation may declare unsupported local backup or other operations; UI and policy must report that accurately.

## Interface semantics

```ts
interface ServiceProvider {
  describe(): ServiceDefinition; // kind, versions, license, config schema, topology, isolation, capacity
  discover(scope: Scope): ServiceInventory;
  plan(intent: ServiceIntent): Plan; // deterministic diff, effects, risk, recovery, estimated cost
  provision(plan: ApprovedPlan, key: IdempotencyKey): Operation;
  bind(intent: BindingIntent): Operation; // scoped credential handle, never raw secret in response
  rotate(intent: RotationIntent): Operation; // overlap, verify new credential, revoke old
  verify(intent: VerifyIntent): Receipt[]; // from app vantage, controls, coverage, freshness
  observe(resource: ResourceRef): ObservedState;
  operate(plan: ApprovedPlan, key: IdempotencyKey): Operation; // allowlisted typed jobs
  backup(intent: BackupIntent): Operation;
  restore(plan: ApprovedPlan, key: IdempotencyKey): Operation; // sandbox by default; production approval
  export(intent: ExportIntent): Operation; // data stays under customer control
  deprovision(plan: ApprovedPlan, key: IdempotencyKey): Operation;
  poll(operation: OperationRef): Operation;
  reconcile(operation: OperationRef): Operation;
}
```

This is pseudocode, not an implemented SDK. Share common operation/plan, auth, approval, idempotency, evidence and error schemas with infrastructure SDK. Provider declares required role/capability and per-operation risk. Provider runner receives only scoped secrets handles and permitted endpoints. Untrusted plugin execution is sandboxed. No raw Docker API, unrestricted host access or data exfiltration through probes. Bindings are generated locally by secret broker, no returned credentials in notices or agent context; app processes get explicit bindings via file or env injection. `Report` is required: resource lifecycle events, health, usage, notices, receipts and dependencies go through durable event bus with correlation and redaction. Provider data export/deletion and retention terms included in docs.

## Adapter requirements

| Capability | Required assertions |
|---|---|
| Provision | correct org/app/env ownership and limits; idempotent; no unintended shared-engine changes |
| Bind | per-process mapping and least privilege; no secret material in control plane; negative auth check |
| Verify | positive/negative control; scoped synthetic functional test from app network; coverage and freshness |
| Operate | bounded signed typed jobs; policy and risk checked; no arbitrary shell; independent verification |
| Rotate | validate new key before revoking old; credential expiration monitored; revoked keys fail |
| Recover | backup integrity; isolated restore; data/schema and application checks; measured recovery |
| Export | documented native format, checksum, data location, compatible import; credentials reissued |
| Delete | scoped ownership; retention/export preconditions; independent approval; no cross-app effects |

## First certified services

- `postgres`: scoped DB and roles; distinct owner/migration/runtime permissions, synthetic test schema and no destructive writes to user data, pg_dump or physical backup strategy documented, restore assertions, version and extension compatibility.
- `object-storage`: separate bucket and scoped key, enforced quotas/limits where supported, synthetic round-trip, object integrity and export. Engine choice pending maintenance/license review.
- `oidc`: per-app/environment realm/client or external provider, issuer/audience and redirect checks, delegated admin, synthetic login flow, user export policy, rotation and revoke.
- `email`: customer-owned approved SMTP/API relay, domain verification (DNS), scoped keys, test send, bounce/accepted/delivered distinctions, event correlation. Optional Postal on customer infrastructure only after deliverability/licensing support policy.
- `llm-gateway`: authorized keys per tenant/app, model and region allowlist, hard budget reservation before dispatch, concurrency/idempotency, fallback only within allowed policy, response records actual served model, no personal pooled subscription lanes, synthetic inference and accounting failure tests.
- `secrets`: local broker with scoped handles, external vault plugin optional, rotation, metadata-only API, fail on unknown/expired secrets.

All P0 adapters must pass both positive and negative contract tests, provider/runtime version upgrade, safe restore/export and isolation testing. Do not market optional components as OSS unless their exact licenses allow it. n8n is not a default bundled open-source hosted service. Reference upstream license matrix in PRD.
