{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\n## Functions\n\n```go\nfunc NewRouter(stores Stores, cfg Config) http.Handler\n```\nNewRouter creates an http.Handler with all API v1 routes registered.\n\n```go\nfunc NewRouterWithIAM(stores Stores, cfg Config, iamResolver *iam.IAMResolver) http.Handler\n```\nNewRouterWithIAM creates an http.Handler with all API v1 routes and optional IAM resolver.\n\n```go\nfunc RequestIDFromContext(ctx context.Context) uuid.UUID\n```\nRequestIDFromContext extracts the request ID from context.\n\n```go\nfunc RoleAtLeast(role, minRole store.Role) bool\n```\nRoleAtLeast returns true if role has at least the given minimum role level.\n\n```go\nfunc SetRequestID(ctx context.Context, id uuid.UUID) context.Context\n```\nSetRequestID returns a new context with the request ID attached.\n\n```go\nfunc SetUserContext(ctx context.Context, u *store.User) context.Context\n```\nSetUserContext returns a new context with the user attached.\n\n```go\nfunc UserFromContext(ctx context.Context) *store.User\n```\nUserFromContext extracts the authenticated user from context, or nil.\n\n```go\nfunc WriteError(w http.ResponseWriter, status int, message string)\n```\nWriteError writes a JSON error response.\n\n```go\nfunc WriteJSON(w http.ResponseWriter, status int, data any)\n```\nWriteJSON writes a JSON response with the given status code.\n\n```go\nfunc WritePaginated(w http.ResponseWriter, items any, total, page, pageSize int)\n```\nWritePaginated writes a paginated JSON response.\n\n## Types\n\n```go\ntype AuditHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nAuditHandler handles audit log query endpoints.\n\n```go\nfunc NewAuditHandler(audit store.AuditStore, permissions *PermissionService) *AuditHandler\n```\nNewAuditHandler creates a new AuditHandler.\n\n```go\nfunc (h *AuditHandler) Query(w http.ResponseWriter, r *http.Request)\n```\nQuery handles GET /api/v1/companies/{id}/audit.\n\n```go\ntype AuthHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nAuthHandler handles authentication endpoints.\n\n```go\nfunc NewAuthHandler(users store.UserStore, sessions store.SessionStore, secret []byte, issuer string, accessTTL, refreshTTL time.Duration) *AuthHandler\n```\nNewAuthHandler creates a new AuthHandler.\n\n```go\nfunc (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request)\n```\nLogin handles POST /api/v1/auth/login.\n\n```go\nfunc (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request)\n```\nLogout handles POST /api/v1/auth/logout.\n\n```go\nfunc (h *AuthHandler) Me(w http.ResponseWriter, r *http.Request)\n```\nMe handles GET /api/v1/auth/me.\n\n```go\nfunc (h *AuthHandler) Refresh(w http.ResponseWriter, r *http.Request)\n```\nRefresh handles POST /api/v1/auth/refresh.\n\n```go\nfunc (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request)\n```\nRegister handles POST /api/v1/auth/register.\n\n```go\nfunc (h *AuthHandler) UpdateMe(w http.ResponseWriter, r *http.Request)\n```\nUpdateMe handles PUT /api/v1/auth/me.\n\n```go\ntype CompanyHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nCompanyHandler handles company CRUD endpoints.\n\n```go\nfunc NewCompanyHandler(companies store.CompanyStore, memberships store.MembershipStore, permissions *PermissionService) *CompanyHandler\n```\nNewCompanyHandler creates a new CompanyHandler.\n\n```go\nfunc (h *CompanyHandler) AddMember(w http.ResponseWriter, r *http.Request)\n```\nAddMember handles POST /api/v1/companies/{id}/members.\n\n```go\nfunc (h *CompanyHandler) Create(w http.ResponseWriter, r *http.Request)\n```\nCreate handles POST /api/v1/companies.\n\n```go\nfunc (h *CompanyHandler) Delete(w http.ResponseWriter, r *http.Request)\n```\nDelete handles DELETE /api/v1/companies/{id}.\n\n```go\nfunc (h *CompanyHandler) Get(w http.ResponseWriter, r *http.Request)\n```\nGet handles GET /api/v1/companies/{id}.\n\n```go\nfunc (h *CompanyHandler) List(w http.ResponseWriter, r *http.Request)\n```\nList handles GET /api/v1/companies.\n\n```go\nfunc (h *CompanyHandler) ListMembers(w http.ResponseWriter, r *http.Request)\n```\nListMembers handles GET /api/v1/companies/{id}/members.\n\n```go\nfunc (h *CompanyHandler) RemoveMember(w http.ResponseWriter, r *http.Request)\n```\nRemoveMember handles DELETE /api/v1/companies/{id}/members/{uid}.\n\n```go\nfunc (h *CompanyHandler) Update(w http.ResponseWriter, r *http.Request)\n```\nUpdate handles PUT /api/v1/companies/{id}.\n\n```go\nfunc (h *CompanyHandler) UpdateMember(w http.ResponseWriter, r *http.Request)\n```\nUpdateMember handles PUT /api/v1/companies/{id}/members/{uid}.\n\n```go\ntype Config struct {\n\tJWTSecret  string //nolint:gosec // G117: config field\n\tJWTIssuer  string\n\tAccessTTL  time.Duration\n\tRefreshTTL time.Duration\n\n\t// AuthRateLimit is the maximum number of requests per minute per IP\n\t// allowed on the /auth/register and /auth/login endpoints.\n\t// Defaults to 10 when zero.\n\tAuthRateLimit int\n\n\t// OAuth providers keyed by provider name (e.g. \"google\", \"okta\").\n\tOAuthProviders map[string]*OAuthProviderConfig\n\n\t// Engine is an optional engine lifecycle manager used by the workflow\n\t// deploy/stop endpoints to actually start and stop workflow engines.\n\tEngine EngineRunner\n}\n```\nConfig holds configuration for the API layer.\n\n```go\ntype DashboardHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nDashboardHandler handles system and per-workflow dashboard endpoints.\n\n```go\nfunc NewDashboardHandler(\n\texecutions store.ExecutionStore,\n\tlogs store.LogStore,\n\tworkflows store.WorkflowStore,\n\tprojects store.ProjectStore,\n\tpermissions *PermissionService,\n) *DashboardHandler\n```\nNewDashboardHandler creates a new DashboardHandler.\n\n```go\nfunc (h *DashboardHandler) System(w http.ResponseWriter, r *http.Request)\n```\nSystem handles GET /api/v1/dashboard.\n\n```go\nfunc (h *DashboardHandler) Workflow(w http.ResponseWriter, r *http.Request)\n```\nWorkflow handles GET /api/v1/workflows/{id}/dashboard.\n\n```go\ntype EngineRunner interface {\n\tDeployWorkflow(ctx context.Context, workflowID uuid.UUID) error\n\tStopWorkflow(ctx context.Context, workflowID uuid.UUID) error\n}\n```\nEngineRunner is an optional engine lifecycle manager that the workflow handler uses to actually start and stop workflow engines when deploying/stopping workflows.\n\n```go\ntype EventsHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nEventsHandler handles event inspection and streaming endpoints.\n\n```go\nfunc NewEventsHandler(executions store.ExecutionStore, logs store.LogStore, permissions *PermissionService) *EventsHandler\n```\nNewEventsHandler creates a new EventsHandler.\n\n```go\nfunc (h *EventsHandler) List(w http.ResponseWriter, r *http.Request)\n```\nList handles GET /api/v1/workflows/{id}/events - lists recent execution events.\n\n```go\nfunc (h *EventsHandler) Stream(w http.ResponseWriter, r *http.Request)\n```\nStream handles GET /api/v1/workflows/{id}/events/stream (SSE).\n\n```go\ntype ExecutionHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nExecutionHandler handles execution tracking endpoints.\n\n```go\nfunc NewExecutionHandler(executions store.ExecutionStore, workflows store.WorkflowStore, permissions *PermissionService) *ExecutionHandler\n```\nNewExecutionHandler creates a new ExecutionHandler.\n\n```go\nfunc (h *ExecutionHandler) Cancel(w http.ResponseWriter, r *http.Request)\n```\nCancel handles POST /api/v1/executions/{id}/cancel.\n\n```go\nfunc (h *ExecutionHandler) Get(w http.ResponseWriter, r *http.Request)\n```\nGet handles GET /api/v1/executions/{id}.\n\n```go\nfunc (h *ExecutionHandler) List(w http.ResponseWriter, r *http.Request)\n```\nList handles GET /api/v1/workflows/{id}/executions.\n\n```go\nfunc (h *ExecutionHandler) Steps(w http.ResponseWriter, r *http.Request)\n```\nSteps handles GET /api/v1/executions/{id}/steps.\n\n```go\nfunc (h *ExecutionHandler) Trigger(w http.ResponseWriter, r *http.Request)\n```\nTrigger handles POST /api/v1/workflows/{id}/trigger.\n\n```go\ntype IAMHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nIAMHandler handles IAM provider and role mapping endpoints.\n\n```go\nfunc NewIAMHandler(iamStore store.IAMStore, resolver *iam.IAMResolver, permissions *PermissionService) *IAMHandler\n```\nNewIAMHandler creates a new IAMHandler.\n\n```go\nfunc (h *IAMHandler) CreateMapping(w http.ResponseWriter, r *http.Request)\n```\nCreateMapping handles POST /api/v1/iam/providers/{id}/mappings.\n\n```go\nfunc (h *IAMHandler) CreateProvider(w http.ResponseWriter, r *http.Request)\n```\nCreateProvider handles POST /api/v1/companies/{id}/iam/providers.\n\n```go\nfunc (h *IAMHandler) DeleteMapping(w http.ResponseWriter, r *http.Request)\n```\nDeleteMapping handles DELETE /api/v1/iam/mappings/{id}.\n\n```go\nfunc (h *IAMHandler) DeleteProvider(w http.ResponseWriter, r *http.Request)\n```\nDeleteProvider handles DELETE /api/v1/iam/providers/{id}.\n\n```go\nfunc (h *IAMHandler) GetProvider(w http.ResponseWriter, r *http.Request)\n```\nGetProvider handles GET /api/v1/iam/providers/{id}.\n\n```go\nfunc (h *IAMHandler) ListMappings(w http.ResponseWriter, r *http.Request)\n```\nListMappings handles GET /api/v1/iam/providers/{id}/mappings.\n\n```go\nfunc (h *IAMHandler) ListProviders(w http.ResponseWriter, r *http.Request)\n```\nListProviders handles GET /api/v1/companies/{id}/iam/providers.\n\n```go\nfunc (h *IAMHandler) TestConnection(w http.ResponseWriter, r *http.Request)\n```\nTestConnection handles POST /api/v1/iam/providers/{id}/test.\n\n```go\nfunc (h *IAMHandler) UpdateProvider(w http.ResponseWriter, r *http.Request)\n```\nUpdateProvider handles PUT /api/v1/iam/providers/{id}.\n\n```go\ntype LinkHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nLinkHandler handles cross-workflow link endpoints.\n\n```go\nfunc NewLinkHandler(links store.CrossWorkflowLinkStore, workflows store.WorkflowStore) *LinkHandler\n```\nNewLinkHandler creates a new LinkHandler.\n\n```go\nfunc (h *LinkHandler) Create(w http.ResponseWriter, r *http.Request)\n```\nCreate handles POST /api/v1/workflows/{id}/links.\n\n```go\nfunc (h *LinkHandler) Delete(w http.ResponseWriter, r *http.Request)\n```\nDelete handles DELETE /api/v1/workflows/{id}/links/{linkId}.\n\n```go\nfunc (h *LinkHandler) List(w http.ResponseWriter, r *http.Request)\n```\nList handles GET /api/v1/workflows/{id}/links.\n\n```go\ntype LogHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nLogHandler handles log query and streaming endpoints.\n\n```go\nfunc NewLogHandler(logs store.LogStore, permissions *PermissionService) *LogHandler\n```\nNewLogHandler creates a new LogHandler.\n\n```go\nfunc (h *LogHandler) Query(w http.ResponseWriter, r *http.Request)\n```\nQuery handles GET /api/v1/workflows/{id}/logs.\n\n```go\nfunc (h *LogHandler) Stream(w http.ResponseWriter, r *http.Request)\n```\nStream handles GET /api/v1/workflows/{id}/logs/stream (SSE).\n\n```go\ntype Middleware struct {\n\t// contains filtered or unexported fields\n}\n```\nMiddleware holds dependencies needed by authentication middleware.\n\n```go\nfunc NewMiddleware(jwtSecret []byte, users store.UserStore, permissions *PermissionService) *Middleware\n```\nNewMiddleware creates a new Middleware.\n\n```go\nfunc (m *Middleware) OptionalAuth(next http.Handler) http.Handler\n```\nOptionalAuth is like RequireAuth but does not fail when no token is present.\n\n```go\nfunc (m *Middleware) RateLimit(requestsPerMinute int) func(http.Handler) http.Handler\n```\nRateLimit returns middleware that limits requests per IP to requestsPerMinute. When requestsPerMinute is zero, the default of 10 is used. Requests that exceed the limit receive HTTP 429 with a Retry-After header. The middleware shares a single per-IP store on this Middleware instance so only one cleanup goroutine runs; call Stop() to release it.\n\n```go\nfunc (m *Middleware) RequireAuth(next http.Handler) http.Handler\n```\nRequireAuth validates the JWT Bearer token and loads the user into context. Returns 401 if the token is missing, invalid, or the user cannot be found.\n\n```go\nfunc (m *Middleware) RequireRole(minRole store.Role, resourceType, idKey string) func(http.Handler) http.Handler\n```\nRequireRole returns middleware that checks the authenticated user has at least minRole on the resource identified by resourceType and the path parameter idKey.\n\n```go\nfunc (m *Middleware) Stop()\n```\nStop shuts down the background cleanup goroutine started by RateLimit. It is safe to call multiple times.\n\n```go\ntype OAuthHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nOAuthHandler handles OAuth2 login flows.\n\n```go\nfunc NewOAuthHandler(users store.UserStore, providers map[string]*OAuthProviderConfig, secret []byte, issuer string, accessTTL, refreshTTL time.Duration) *OAuthHandler\n```\nNewOAuthHandler creates a new OAuthHandler.\n\n```go\nfunc (h *OAuthHandler) Authorize(w http.ResponseWriter, r *http.Request)\n```\nAuthorize handles GET /api/v1/auth/oauth2/{provider}. Generates a state parameter, stores it in a cookie, and redirects.\n\n```go\nfunc (h *OAuthHandler) Callback(w http.ResponseWriter, r *http.Request)\n```\nCallback handles GET /api/v1/auth/oauth2/{provider}/callback.\n\n```go\ntype OAuthProviderConfig struct {\n\tClientID     string   `json:\"client_id\"`\n\tClientSecret string   `json:\"client_secret\"` //nolint:gosec // G117: OAuth config field\n\tRedirectURL  string   `json:\"redirect_url\"`\n\tScopes       []string `json:\"scopes\"`\n\tAuthURL      string   `json:\"auth_url\"`\n\tTokenURL     string   `json:\"token_url\"`\n\tUserInfoURL  string   `json:\"user_info_url\"`\n}\n```\nOAuthProviderConfig describes one OAuth2 provider.\n\n```go\ntype OrgHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nOrgHandler handles organization CRUD endpoints. Organizations are companies nested under a parent company. The store treats Company and Organization as the same type.\n\n```go\nfunc NewOrgHandler(companies store.CompanyStore, memberships store.MembershipStore, permissions *PermissionService) *OrgHandler\n```\nNewOrgHandler creates a new OrgHandler.\n\n```go\nfunc (h *OrgHandler) Create(w http.ResponseWriter, r *http.Request)\n```\nCreate handles POST /api/v1/companies/{cid}/organizations.\n\n```go\nfunc (h *OrgHandler) Delete(w http.ResponseWriter, r *http.Request)\n```\nDelete handles DELETE /api/v1/organizations/{id}.\n\n```go\nfunc (h *OrgHandler) Get(w http.ResponseWriter, r *http.Request)\n```\nGet handles GET /api/v1/organizations/{id}.\n\n```go\nfunc (h *OrgHandler) List(w http.ResponseWriter, r *http.Request)\n```\nList handles GET /api/v1/companies/{cid}/organizations.\n\n```go\nfunc (h *OrgHandler) Update(w http.ResponseWriter, r *http.Request)\n```\nUpdate handles PUT /api/v1/organizations/{id}.\n\n```go\ntype PermissionService struct {\n\t// contains filtered or unexported fields\n}\n```\nPermissionService resolves effective permissions across the resource hierarchy.\n\n```go\nfunc NewPermissionService(memberships store.MembershipStore, workflows store.WorkflowStore, projects store.ProjectStore) *PermissionService\n```\nNewPermissionService creates a new PermissionService.\n\n```go\nfunc (ps *PermissionService) CanAccess(ctx context.Context, userID uuid.UUID, resourceType string, resourceID uuid.UUID, minRole store.Role) bool\n```\nCanAccess returns true if the user has at least minRole on the given resource.\n\n```go\nfunc (ps *PermissionService) GetEffectiveRole(ctx context.Context, userID uuid.UUID, resourceType string, resourceID uuid.UUID) (store.Role, error)\n```\nGetEffectiveRole resolves the cascading effective role for a user on a resource. Cascade: workflow\\_permissions -\u003e project\\_memberships -\u003e company\\_memberships.\n\n```go\ntype ProjectHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nProjectHandler handles project CRUD and member endpoints.\n\n```go\nfunc NewProjectHandler(projects store.ProjectStore, companies store.CompanyStore, memberships store.MembershipStore, permissions *PermissionService) *ProjectHandler\n```\nNewProjectHandler creates a new ProjectHandler.\n\n```go\nfunc (h *ProjectHandler) AddMember(w http.ResponseWriter, r *http.Request)\n```\nAddMember handles POST /api/v1/projects/{id}/members.\n\n```go\nfunc (h *ProjectHandler) Create(w http.ResponseWriter, r *http.Request)\n```\nCreate handles POST /api/v1/organizations/{oid}/projects.\n\n```go\nfunc (h *ProjectHandler) Delete(w http.ResponseWriter, r *http.Request)\n```\nDelete handles DELETE /api/v1/projects/{id}.\n\n```go\nfunc (h *ProjectHandler) Get(w http.ResponseWriter, r *http.Request)\n```\nGet handles GET /api/v1/projects/{id}.\n\n```go\nfunc (h *ProjectHandler) List(w http.ResponseWriter, r *http.Request)\n```\nList handles GET /api/v1/organizations/{oid}/projects.\n\n```go\nfunc (h *ProjectHandler) ListMembers(w http.ResponseWriter, r *http.Request)\n```\nListMembers handles GET /api/v1/projects/{id}/members.\n\n```go\nfunc (h *ProjectHandler) Update(w http.ResponseWriter, r *http.Request)\n```\nUpdate handles PUT /api/v1/projects/{id}.\n\n```go\ntype Stores struct {\n\tUsers       store.UserStore\n\tSessions    store.SessionStore\n\tCompanies   store.CompanyStore\n\tProjects    store.ProjectStore\n\tWorkflows   store.WorkflowStore\n\tMemberships store.MembershipStore\n\tLinks       store.CrossWorkflowLinkStore\n\tExecutions  store.ExecutionStore\n\tLogs        store.LogStore\n\tAudit       store.AuditStore\n\tIAM         store.IAMStore\n}\n```\nStores groups all store interfaces needed by the API.\n\n```go\ntype WorkflowHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nWorkflowHandler handles workflow CRUD and lifecycle endpoints.\n\n```go\nfunc NewWorkflowHandler(workflows store.WorkflowStore, projects store.ProjectStore, memberships store.MembershipStore, permissions *PermissionService) *WorkflowHandler\n```\nNewWorkflowHandler creates a new WorkflowHandler.\n\n```go\nfunc (h *WorkflowHandler) Create(w http.ResponseWriter, r *http.Request)\n```\nCreate handles POST /api/v1/projects/{pid}/workflows.\n\n```go\nfunc (h *WorkflowHandler) Delete(w http.ResponseWriter, r *http.Request)\n```\nDelete handles DELETE /api/v1/workflows/{id}.\n\n```go\nfunc (h *WorkflowHandler) Deploy(w http.ResponseWriter, r *http.Request)\n```\nDeploy handles POST /api/v1/workflows/{id}/deploy.\n\n```go\nfunc (h *WorkflowHandler) Get(w http.ResponseWriter, r *http.Request)\n```\nGet handles GET /api/v1/workflows/{id}.\n\n```go\nfunc (h *WorkflowHandler) GetVersion(w http.ResponseWriter, r *http.Request)\n```\nGetVersion handles GET /api/v1/workflows/{id}/versions/{v}.\n\n```go\nfunc (h *WorkflowHandler) ListAll(w http.ResponseWriter, r *http.Request)\n```\nListAll handles GET /api/v1/workflows (all accessible workflows).\n\n```go\nfunc (h *WorkflowHandler) ListInProject(w http.ResponseWriter, r *http.Request)\n```\nListInProject handles GET /api/v1/projects/{pid}/workflows.\n\n```go\nfunc (h *WorkflowHandler) ListPermissions(w http.ResponseWriter, r *http.Request)\n```\nListPermissions handles GET /api/v1/workflows/{id}/permissions.\n\n```go\nfunc (h *WorkflowHandler) ListVersions(w http.ResponseWriter, r *http.Request)\n```\nListVersions handles GET /api/v1/workflows/{id}/versions.\n\n```go\nfunc (h *WorkflowHandler) SetPermission(w http.ResponseWriter, r *http.Request)\n```\nSetPermission handles POST /api/v1/workflows/{id}/permissions.\n\n```go\nfunc (h *WorkflowHandler) Status(w http.ResponseWriter, r *http.Request)\n```\nStatus handles GET /api/v1/workflows/{id}/status.\n\n```go\nfunc (h *WorkflowHandler) Stop(w http.ResponseWriter, r *http.Request)\n```\nStop handles POST /api/v1/workflows/{id}/stop.\n\n```go\nfunc (h *WorkflowHandler) Update(w http.ResponseWriter, r *http.Request)\n```\nUpdate handles PUT /api/v1/workflows/{id}.\n\n```go\nfunc (h *WorkflowHandler) WithEngine(engine EngineRunner) *WorkflowHandler\n```\nWithEngine sets the optional engine runner used by Deploy and Stop.\n\n","path":"github.com/GoCodeAlone/workflow/api","name":"api","synopsis":"","isRedistributable":true}
