package api import ( "atlas9.dev/c/core" "atlas9.dev/c/demo/lib/slack" "atlas9.dev/c/demo/lib/tasks" ) const ( Path_Slack_CreateEndpoint = "POST /Slack_CreateEndpoint" Path_Slack_UpdateEndpoint = "POST /Slack_UpdateEndpoint" Path_Slack_GetEndpoint = "POST /Slack_GetEndpoint" Path_Slack_ListEndpoints = "POST /Slack_ListEndpoints" Path_Slack_DeleteEndpoint = "POST /Slack_DeleteEndpoint" // Path_Slack_Deliver is the internal task endpoint the delivery worker // replays; it is not called by clients. Path_Slack_Deliver = "POST /Slack_Deliver" ) // Slack_CreateEndpointReq creates a Slack subscription. URL is the plaintext // Slack incoming-webhook URL; it is sealed server-side and never stored or // returned in the clear, so it is a request field rather than part of Endpoint. type Slack_CreateEndpointReq struct { Endpoint slack.Endpoint URL string } type Slack_CreateEndpointRes struct { Endpoint slack.Endpoint } // Slack_UpdateEndpointReq updates a Slack subscription. URL is optional: a // non-empty value re-seals and replaces the webhook URL, an empty value leaves // the stored URL unchanged (it is never sent back to the client to echo). type Slack_UpdateEndpointReq struct { Endpoint slack.Endpoint URL string } type Slack_UpdateEndpointRes struct { Endpoint slack.Endpoint } type Slack_GetEndpointReq struct { Tenant core.ID ID core.ID } type Slack_GetEndpointRes struct { Endpoint slack.Endpoint } type Slack_ListEndpointsReq struct { Tenant core.ID Page core.PageReq } type Slack_ListEndpointsRes struct { Page core.Page[slack.Endpoint] } type Slack_DeleteEndpointReq struct { Tenant core.ID ID core.ID } type Slack_DeleteEndpointRes struct{} // Slack_DeliverReq is one queued delivery: the endpoint to POST to and the // already-rendered Slack message body to send. The body is carried in the task // payload rather than looked up, since there is no event table. type Slack_DeliverReq struct { Tenant core.ID Endpoint core.ID Type string Body []byte } type Slack_DeliverRes struct { Task tasks.Result } // Prepare functions func (r *Slack_CreateEndpointReq) Prepare() error { r.Endpoint.ID = core.NewID("slk") // New endpoints are active; deactivate later via Update. The URL is sealed // server-side, so any client-supplied ciphertext is ignored. r.Endpoint.Active = true r.Endpoint.DekID = core.ID{} r.Endpoint.URLEnc = nil var errs []string if r.Endpoint.Name == "" { errs = append(errs, "endpoint name is required") } if r.URL == "" { errs = append(errs, "endpoint url is required") } if len(errs) > 0 { return &ValidationError{Errors: errs} } return nil } func (r *Slack_UpdateEndpointReq) Prepare() error { var errs []string if r.Endpoint.ID.IsEmpty() { errs = append(errs, "endpoint id is required") } if r.Endpoint.Name == "" { errs = append(errs, "endpoint name is required") } if len(errs) > 0 { return &ValidationError{Errors: errs} } return nil } func (r *Slack_GetEndpointReq) Prepare() error { return nil } func (r *Slack_DeleteEndpointReq) Prepare() error { return nil } func (r *Slack_DeliverReq) Prepare() error { return nil } func (r *Slack_ListEndpointsReq) Prepare() error { if r.Tenant.IsEmpty() { return &ValidationError{Errors: []string{"Tenant is required"}} } return nil }