Expose commitment CRUD on MCP, CLI, n8n

Sync GraphQL commitment group and item operations
to the remaining API surfaces so automation can
manage compliance portal commitments end to end.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-07-20 19:25:29 +02:00
parent e27a830d76
commit 2db37660d3
24 changed files with 3588 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package commitmentgroup
import (
"github.com/spf13/cobra"
"go.probo.inc/probo/pkg/cmd/cmdutil"
"go.probo.inc/probo/pkg/cmd/trust-center/commitmentgroup/create"
"go.probo.inc/probo/pkg/cmd/trust-center/commitmentgroup/delete"
"go.probo.inc/probo/pkg/cmd/trust-center/commitmentgroup/list"
"go.probo.inc/probo/pkg/cmd/trust-center/commitmentgroup/update"
)
func NewCmdCommitmentGroup(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "commitment-group <command>",
Short: "Manage compliance portal commitment groups",
Aliases: []string{"cg"},
}
cmd.AddCommand(list.NewCmdList(f))
cmd.AddCommand(create.NewCmdCreate(f))
cmd.AddCommand(update.NewCmdUpdate(f))
cmd.AddCommand(delete.NewCmdDelete(f))
return cmd
}

View File

@@ -0,0 +1,216 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package create
import (
"encoding/json"
"fmt"
"github.com/charmbracelet/huh"
"github.com/spf13/cobra"
"go.probo.inc/probo/pkg/cli/api"
"go.probo.inc/probo/pkg/cmd/cmdutil"
)
const trustCenterQuery = `
query($id: ID!) {
node(id: $id) {
__typename
... on Organization {
trustCenter {
id
}
}
}
}
`
const createMutation = `
mutation($input: CreateCompliancePortalCommitmentGroupInput!) {
createCompliancePortalCommitmentGroup(input: $input) {
compliancePortalCommitmentGroupEdge {
node {
id
title
description
rank
}
}
}
}
`
type trustCenterQueryResponse struct {
Node *struct {
Typename string `json:"__typename"`
TrustCenter *struct {
ID string `json:"id"`
} `json:"trustCenter"`
} `json:"node"`
}
type createResponse struct {
CreateCompliancePortalCommitmentGroup struct {
CompliancePortalCommitmentGroupEdge struct {
Node struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Rank int `json:"rank"`
} `json:"node"`
} `json:"compliancePortalCommitmentGroupEdge"`
} `json:"createCompliancePortalCommitmentGroup"`
}
func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
var (
flagOrg string
flagTitle string
flagDescription string
)
cmd := &cobra.Command{
Use: "create",
Short: "Create a compliance portal commitment group",
Example: ` # Create a commitment group interactively
prb trust-center commitment-group create
# Create a commitment group non-interactively
prb trust-center cg create --title "Security" --description "Our security commitments"`,
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := f.Config()
if err != nil {
return err
}
host, hc, err := cfg.DefaultHost()
if err != nil {
return err
}
client := api.NewClient(
host,
hc.Token,
"/api/console/v1/graphql",
cfg.HTTPTimeoutDuration(),
cmdutil.TokenRefreshOption(cfg, host, hc),
)
if flagOrg == "" {
flagOrg = hc.Organization
}
if flagOrg == "" {
return fmt.Errorf("organization is required; pass --org or set a default with 'prb auth login'")
}
data, err := client.Do(
trustCenterQuery,
map[string]any{"id": flagOrg},
)
if err != nil {
return err
}
var tcResp trustCenterQueryResponse
if err := json.Unmarshal(data, &tcResp); err != nil {
return fmt.Errorf("cannot parse response: %w", err)
}
if tcResp.Node == nil {
return fmt.Errorf("organization %s not found", flagOrg)
}
if tcResp.Node.Typename != "Organization" {
return fmt.Errorf("expected Organization node, got %s", tcResp.Node.Typename)
}
if tcResp.Node.TrustCenter == nil {
return fmt.Errorf("trust center not found for organization %s", flagOrg)
}
if f.IOStreams.IsInteractive() {
if flagTitle == "" {
err := huh.NewInput().
Title("Group title").
Value(&flagTitle).
Run()
if err != nil {
return err
}
}
if flagDescription == "" {
err := huh.NewText().
Title("Description").
Value(&flagDescription).
Run()
if err != nil {
return err
}
}
}
if flagTitle == "" {
return fmt.Errorf("title is required; pass --title or run interactively")
}
if flagDescription == "" {
return fmt.Errorf("description is required; pass --description or run interactively")
}
data, err = client.Do(
createMutation,
map[string]any{
"input": map[string]any{
"trustCenterId": tcResp.Node.TrustCenter.ID,
"title": flagTitle,
"description": flagDescription,
},
},
)
if err != nil {
return err
}
var resp createResponse
if err := json.Unmarshal(data, &resp); err != nil {
return fmt.Errorf("cannot parse response: %w", err)
}
g := resp.CreateCompliancePortalCommitmentGroup.CompliancePortalCommitmentGroupEdge.Node
_, _ = fmt.Fprintf(
f.IOStreams.Out,
"Created commitment group %s (%s)\n",
g.ID,
g.Title,
)
return nil
},
}
cmd.Flags().StringVar(&flagOrg, "org", "", "Organization ID")
cmd.Flags().StringVar(&flagTitle, "title", "", "Group title (required)")
cmd.Flags().StringVar(&flagDescription, "description", "", "Group description (required)")
return cmd
}

View File

@@ -0,0 +1,111 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package delete
import (
"fmt"
"github.com/charmbracelet/huh"
"github.com/spf13/cobra"
"go.probo.inc/probo/pkg/cli/api"
"go.probo.inc/probo/pkg/cmd/cmdutil"
)
const deleteMutation = `
mutation($input: DeleteCompliancePortalCommitmentGroupInput!) {
deleteCompliancePortalCommitmentGroup(input: $input) {
deletedCompliancePortalCommitmentGroupId
}
}
`
func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
var flagYes bool
cmd := &cobra.Command{
Use: "delete <id>",
Short: "Delete a compliance portal commitment group",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if !flagYes {
if !f.IOStreams.IsInteractive() {
return fmt.Errorf("cannot delete commitment group: confirmation required, use --yes to confirm")
}
var confirmed bool
err := huh.NewConfirm().
Title(fmt.Sprintf("Delete commitment group %s?", args[0])).
Value(&confirmed).
Run()
if err != nil {
return err
}
if !confirmed {
return nil
}
}
cfg, err := f.Config()
if err != nil {
return err
}
host, hc, err := cfg.DefaultHost()
if err != nil {
return err
}
client := api.NewClient(
host,
hc.Token,
"/api/console/v1/graphql",
cfg.HTTPTimeoutDuration(),
cmdutil.TokenRefreshOption(cfg, host, hc),
)
_, err = client.Do(
deleteMutation,
map[string]any{
"input": map[string]any{
"id": args[0],
},
},
)
if err != nil {
return err
}
_, _ = fmt.Fprintf(
f.IOStreams.Out,
"Deleted commitment group %s\n",
args[0],
)
return nil
},
}
cmd.Flags().BoolVarP(&flagYes, "yes", "y", false, "Skip confirmation prompt")
return cmd
}

View File

@@ -0,0 +1,212 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package list
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"go.probo.inc/probo/pkg/cli/api"
"go.probo.inc/probo/pkg/cmd/cmdutil"
)
const listQuery = `
query($id: ID!, $first: Int, $after: CursorKey, $orderBy: CompliancePortalCommitmentGroupOrder) {
node(id: $id) {
__typename
... on Organization {
trustCenter {
commitmentGroups(first: $first, after: $after, orderBy: $orderBy) {
totalCount
edges {
node {
id
title
description
rank
createdAt
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
}
`
type commitmentGroup struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Rank int `json:"rank"`
CreatedAt string `json:"createdAt"`
}
func NewCmdList(f *cmdutil.Factory) *cobra.Command {
var (
flagOrg string
flagLimit int
flagOrderBy string
flagOrderDir string
flagOutput *string
)
cmd := &cobra.Command{
Use: "list",
Short: "List compliance portal commitment groups",
Aliases: []string{"ls"},
Example: ` # List commitment groups in the default organization
prb trust-center commitment-group list
# List commitment groups sorted by rank
prb trust-center cg ls --order-by RANK`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmdutil.ValidateOutputFlag(flagOutput); err != nil {
return err
}
cfg, err := f.Config()
if err != nil {
return err
}
host, hc, err := cfg.DefaultHost()
if err != nil {
return err
}
client := api.NewClient(
host,
hc.Token,
"/api/console/v1/graphql",
cfg.HTTPTimeoutDuration(),
cmdutil.TokenRefreshOption(cfg, host, hc),
)
if flagOrg == "" {
flagOrg = hc.Organization
}
if flagOrg == "" {
return fmt.Errorf("organization is required; pass --org or set a default with 'prb auth login'")
}
variables := map[string]any{
"id": flagOrg,
}
if flagOrderBy != "" {
if err := cmdutil.ValidateEnum("order-by", flagOrderBy, []string{"RANK", "CREATED_AT", "UPDATED_AT"}); err != nil {
return err
}
variables["orderBy"] = map[string]any{
"field": flagOrderBy,
"direction": flagOrderDir,
}
}
groups, totalCount, err := api.Paginate(
client,
listQuery,
variables,
flagLimit,
func(data json.RawMessage) (*api.Connection[commitmentGroup], error) {
var resp struct {
Node *struct {
Typename string `json:"__typename"`
TrustCenter *struct {
CommitmentGroups api.Connection[commitmentGroup] `json:"commitmentGroups"`
} `json:"trustCenter"`
} `json:"node"`
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, err
}
if resp.Node == nil {
return nil, fmt.Errorf("organization %s not found", flagOrg)
}
if resp.Node.Typename != "Organization" {
return nil, fmt.Errorf("expected Organization node, got %s", resp.Node.Typename)
}
if resp.Node.TrustCenter == nil {
return nil, fmt.Errorf("trust center not found for organization %s", flagOrg)
}
return &resp.Node.TrustCenter.CommitmentGroups, nil
},
)
if err != nil {
return err
}
if *flagOutput == cmdutil.OutputJSON {
return cmdutil.PrintJSON(f.IOStreams.Out, groups)
}
if len(groups) == 0 {
_, _ = fmt.Fprintln(f.IOStreams.Out, "No commitment groups found.")
return nil
}
rows := make([][]string, 0, len(groups))
for _, g := range groups {
rows = append(rows, []string{
g.ID,
g.Title,
fmt.Sprintf("%d", g.Rank),
})
}
t := cmdutil.NewTable("ID", "TITLE", "RANK").Rows(rows...)
_, _ = fmt.Fprintln(f.IOStreams.Out, t)
if totalCount > len(groups) {
_, _ = fmt.Fprintf(
f.IOStreams.ErrOut,
"\nShowing %d of %d commitment groups\n",
len(groups),
totalCount,
)
}
return nil
},
}
cmd.Flags().StringVar(&flagOrg, "org", "", "Organization ID")
cmd.Flags().IntVarP(&flagLimit, "limit", "L", 30, "Maximum number of commitment groups to list")
cmd.Flags().StringVar(&flagOrderBy, "order-by", "", "Order by field (RANK, CREATED_AT, UPDATED_AT)")
cmd.Flags().StringVar(&flagOrderDir, "order-direction", "DESC", "Sort direction (ASC, DESC)")
flagOutput = cmdutil.AddOutputFlag(cmd)
return cmd
}

View File

@@ -0,0 +1,141 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package update
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"go.probo.inc/probo/pkg/cli/api"
"go.probo.inc/probo/pkg/cmd/cmdutil"
)
const updateMutation = `
mutation($input: UpdateCompliancePortalCommitmentGroupInput!) {
updateCompliancePortalCommitmentGroup(input: $input) {
compliancePortalCommitmentGroup {
id
title
description
rank
}
}
}
`
type updateResponse struct {
UpdateCompliancePortalCommitmentGroup struct {
CompliancePortalCommitmentGroup struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Rank int `json:"rank"`
} `json:"compliancePortalCommitmentGroup"`
} `json:"updateCompliancePortalCommitmentGroup"`
}
func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
var (
flagTitle string
flagDescription string
flagRank int
)
cmd := &cobra.Command{
Use: "update <id>",
Short: "Update a compliance portal commitment group",
Example: ` # Update a commitment group title
prb trust-center commitment-group update <id> --title "Privacy"
# Update rank
prb trust-center cg update <id> --rank 2`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := f.Config()
if err != nil {
return err
}
host, hc, err := cfg.DefaultHost()
if err != nil {
return err
}
client := api.NewClient(
host,
hc.Token,
"/api/console/v1/graphql",
cfg.HTTPTimeoutDuration(),
cmdutil.TokenRefreshOption(cfg, host, hc),
)
input := map[string]any{
"id": args[0],
}
if cmd.Flags().Changed("title") {
input["title"] = flagTitle
}
if cmd.Flags().Changed("description") {
input["description"] = flagDescription
}
if cmd.Flags().Changed("rank") {
input["rank"] = flagRank
}
if len(input) == 1 {
return fmt.Errorf("at least one field must be specified for update")
}
data, err := client.Do(
updateMutation,
map[string]any{"input": input},
)
if err != nil {
return err
}
var resp updateResponse
if err := json.Unmarshal(data, &resp); err != nil {
return fmt.Errorf("cannot parse response: %w", err)
}
g := resp.UpdateCompliancePortalCommitmentGroup.CompliancePortalCommitmentGroup
_, _ = fmt.Fprintf(
f.IOStreams.Out,
"Updated commitment group %s (%s)\n",
g.ID,
g.Title,
)
return nil
},
}
cmd.Flags().StringVar(&flagTitle, "title", "", "Group title")
cmd.Flags().StringVar(&flagDescription, "description", "", "Group description")
cmd.Flags().IntVar(&flagRank, "rank", 0, "Display rank")
return cmd
}