From 3b0c87591f61830e8fbfe24d701d404baf0a53aa Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 16 Jun 2025 22:10:43 +0800 Subject: [PATCH] refactor: webhook service --- proto/api/v1/webhook_service.proto | 181 +++-- proto/gen/api/v1/webhook_service.pb.go | 490 +++++++++----- proto/gen/api/v1/webhook_service.pb.gw.go | 184 ++++-- proto/gen/api/v1/webhook_service_grpc.pb.go | 72 +- proto/gen/apidocs.swagger.yaml | 336 +++++++--- server/router/api/v1/resource_name.go | 14 + server/router/api/v1/webhook_service.go | 126 +++- web/src/components/CreateWebhookDialog.tsx | 34 +- .../components/Settings/WebhookSection.tsx | 22 +- web/src/types/proto/api/v1/webhook_service.ts | 625 +++++++++++++----- 10 files changed, 1474 insertions(+), 610 deletions(-) diff --git a/proto/api/v1/webhook_service.proto b/proto/api/v1/webhook_service.proto index 65226732f..990ae6f3d 100644 --- a/proto/api/v1/webhook_service.proto +++ b/proto/api/v1/webhook_service.proto @@ -2,9 +2,12 @@ syntax = "proto3"; package memos.api.v1; +import "api/v1/common.proto"; import "api/v1/memo_service.proto"; import "google/api/annotations.proto"; import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; import "google/protobuf/empty.proto"; import "google/protobuf/field_mask.proto"; import "google/protobuf/timestamp.proto"; @@ -12,91 +15,191 @@ import "google/protobuf/timestamp.proto"; option go_package = "gen/api/v1"; service WebhookService { + // ListWebhooks returns a list of webhooks. + rpc ListWebhooks(ListWebhooksRequest) returns (ListWebhooksResponse) { + option (google.api.http) = {get: "/api/v1/webhooks"}; + } + + // GetWebhook gets a webhook by name. + rpc GetWebhook(GetWebhookRequest) returns (Webhook) { + option (google.api.http) = {get: "/api/v1/{name=webhooks/*}"}; + option (google.api.method_signature) = "name"; + } + // CreateWebhook creates a new webhook. rpc CreateWebhook(CreateWebhookRequest) returns (Webhook) { option (google.api.http) = { post: "/api/v1/webhooks" - body: "*" + body: "webhook" }; + option (google.api.method_signature) = "webhook"; } - // GetWebhook returns a webhook by id. - rpc GetWebhook(GetWebhookRequest) returns (Webhook) { - option (google.api.http) = {get: "/api/v1/webhooks/{id}"}; - option (google.api.method_signature) = "id"; - } - // ListWebhooks returns a list of webhooks. - rpc ListWebhooks(ListWebhooksRequest) returns (ListWebhooksResponse) { - option (google.api.http) = {get: "/api/v1/webhooks"}; - } + // UpdateWebhook updates a webhook. rpc UpdateWebhook(UpdateWebhookRequest) returns (Webhook) { option (google.api.http) = { - patch: "/api/v1/webhooks/{webhook.id}" + patch: "/api/v1/{webhook.name=webhooks/*}" body: "webhook" }; option (google.api.method_signature) = "webhook,update_mask"; } - // DeleteWebhook deletes a webhook by id. + + // DeleteWebhook deletes a webhook. rpc DeleteWebhook(DeleteWebhookRequest) returns (google.protobuf.Empty) { - option (google.api.http) = {delete: "/api/v1/webhooks/{id}"}; - option (google.api.method_signature) = "id"; + option (google.api.http) = {delete: "/api/v1/{name=webhooks/*}"}; + option (google.api.method_signature) = "name"; } } message Webhook { - int32 id = 1; + option (google.api.resource) = { + type: "memos.api.v1/Webhook" + pattern: "webhooks/{webhook}" + name_field: "name" + singular: "webhook" + plural: "webhooks" + }; - // The name of the creator. - string creator = 2; + // The resource name of the webhook. + // Format: webhooks/{webhook} + string name = 1 [(google.api.field_behavior) = IDENTIFIER]; - google.protobuf.Timestamp create_time = 3; + // Output only. The system generated unique identifier. + string uid = 2 [(google.api.field_behavior) = OUTPUT_ONLY]; - google.protobuf.Timestamp update_time = 4; + // Required. The display name of the webhook. + string display_name = 3 [(google.api.field_behavior) = REQUIRED]; - string name = 5; + // Required. The target URL for the webhook. + string url = 4 [(google.api.field_behavior) = REQUIRED]; - string url = 6; -} + // Output only. The resource name of the creator. + // Format: users/{user} + string creator = 5 [(google.api.field_behavior) = OUTPUT_ONLY]; -message CreateWebhookRequest { - string name = 1; + // The state of the webhook. + State state = 6 [(google.api.field_behavior) = REQUIRED]; - string url = 2; -} + // Output only. The creation timestamp. + google.protobuf.Timestamp create_time = 7 [(google.api.field_behavior) = OUTPUT_ONLY]; -message GetWebhookRequest { - int32 id = 1; + // Output only. The last update timestamp. + google.protobuf.Timestamp update_time = 8 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The etag for this resource. + string etag = 9 [(google.api.field_behavior) = OUTPUT_ONLY]; } message ListWebhooksRequest { - // The name of the creator. - string creator = 2; + // Optional. The maximum number of webhooks to return. + // The service may return fewer than this value. + // If unspecified, at most 50 webhooks will be returned. + // The maximum value is 1000; values above 1000 will be coerced to 1000. + int32 page_size = 1 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. A page token, received from a previous `ListWebhooks` call. + // Provide this to retrieve the subsequent page. + string page_token = 2 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Filter to apply to the list results. + // Example: "state=ACTIVE" or "creator=users/123" + // Supported operators: =, !=, <, <=, >, >=, : + // Supported fields: display_name, url, creator, state, create_time, update_time + string filter = 3 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. The order to sort results by. + // Example: "create_time desc" or "display_name asc" + string order_by = 4 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. If true, show deleted webhooks in the response. + bool show_deleted = 5 [(google.api.field_behavior) = OPTIONAL]; } message ListWebhooksResponse { + // The list of webhooks. repeated Webhook webhooks = 1; + + // A token that can be sent as `page_token` to retrieve the next page. + // If this field is omitted, there are no subsequent pages. + string next_page_token = 2; + + // The total count of webhooks (may be approximate). + int32 total_size = 3; +} + +message GetWebhookRequest { + // Required. The resource name of the webhook. + // Format: webhooks/{webhook} + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = {type: "memos.api.v1/Webhook"} + ]; + + // Optional. The fields to return in the response. + // If not specified, all fields are returned. + google.protobuf.FieldMask read_mask = 2 [(google.api.field_behavior) = OPTIONAL]; +} + +message CreateWebhookRequest { + // Required. The webhook to create. + Webhook webhook = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.field_behavior) = INPUT_ONLY + ]; + + // Optional. The webhook ID to use for this webhook. + // If empty, a unique ID will be generated. + // Must match the pattern [a-z0-9-]+ + string webhook_id = 2 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. If set, validate the request but don't actually create the webhook. + bool validate_only = 3 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. An idempotency token that can be used to ensure that multiple + // requests to create a webhook have the same result. + string request_id = 4 [(google.api.field_behavior) = OPTIONAL]; } message UpdateWebhookRequest { - Webhook webhook = 1; + // Required. The webhook to update. + Webhook webhook = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. The list of fields to update. + google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED]; - google.protobuf.FieldMask update_mask = 2; + // Optional. If set to true, allows updating sensitive fields. + bool allow_missing = 3 [(google.api.field_behavior) = OPTIONAL]; } message DeleteWebhookRequest { - int32 id = 1; + // Required. The resource name of the webhook to delete. + // Format: webhooks/{webhook} + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = {type: "memos.api.v1/Webhook"} + ]; + + // Optional. If set to true, the webhook will be deleted even if it has associated data. + bool force = 2 [(google.api.field_behavior) = OPTIONAL]; } message WebhookRequestPayload { - string url = 1; + // The target URL for the webhook request. + string url = 1 [(google.api.field_behavior) = REQUIRED]; - string activity_type = 2; + // The type of activity that triggered this webhook. + string activity_type = 2 [(google.api.field_behavior) = REQUIRED]; - // The name of the creator. + // The resource name of the creator. // Format: users/{user} - string creator = 3; + string creator = 3 [ + (google.api.field_behavior) = OUTPUT_ONLY, + (google.api.resource_reference) = {type: "memos.api.v1/User"} + ]; - google.protobuf.Timestamp create_time = 4; + // The creation timestamp of the activity. + google.protobuf.Timestamp create_time = 4 [(google.api.field_behavior) = OUTPUT_ONLY]; - Memo memo = 5; + // The memo that triggered this webhook (if applicable). + Memo memo = 5 [(google.api.field_behavior) = OPTIONAL]; } diff --git a/proto/gen/api/v1/webhook_service.pb.go b/proto/gen/api/v1/webhook_service.pb.go index e773aee3f..7159172f5 100644 --- a/proto/gen/api/v1/webhook_service.pb.go +++ b/proto/gen/api/v1/webhook_service.pb.go @@ -27,13 +27,26 @@ const ( type Webhook struct { state protoimpl.MessageState `protogen:"open.v1"` - Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - // The name of the creator. - Creator string `protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"` - CreateTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` - UpdateTime *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty"` - Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty"` - Url string `protobuf:"bytes,6,opt,name=url,proto3" json:"url,omitempty"` + // The resource name of the webhook. + // Format: webhooks/{webhook} + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Output only. The system generated unique identifier. + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` + // Required. The display name of the webhook. + DisplayName string `protobuf:"bytes,3,opt,name=display_name,json=displayName,proto3" json:"display_name,omitempty"` + // Required. The target URL for the webhook. + Url string `protobuf:"bytes,4,opt,name=url,proto3" json:"url,omitempty"` + // Output only. The resource name of the creator. + // Format: users/{user} + Creator string `protobuf:"bytes,5,opt,name=creator,proto3" json:"creator,omitempty"` + // The state of the webhook. + State State `protobuf:"varint,6,opt,name=state,proto3,enum=memos.api.v1.State" json:"state,omitempty"` + // Output only. The creation timestamp. + CreateTime *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` + // Output only. The last update timestamp. + UpdateTime *timestamppb.Timestamp `protobuf:"bytes,8,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty"` + // Output only. The etag for this resource. + Etag string `protobuf:"bytes,9,opt,name=etag,proto3" json:"etag,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -68,11 +81,32 @@ func (*Webhook) Descriptor() ([]byte, []int) { return file_api_v1_webhook_service_proto_rawDescGZIP(), []int{0} } -func (x *Webhook) GetId() int32 { +func (x *Webhook) GetName() string { if x != nil { - return x.Id + return x.Name } - return 0 + return "" +} + +func (x *Webhook) GetUid() string { + if x != nil { + return x.Uid + } + return "" +} + +func (x *Webhook) GetDisplayName() string { + if x != nil { + return x.DisplayName + } + return "" +} + +func (x *Webhook) GetUrl() string { + if x != nil { + return x.Url + } + return "" } func (x *Webhook) GetCreator() string { @@ -82,6 +116,13 @@ func (x *Webhook) GetCreator() string { return "" } +func (x *Webhook) GetState() State { + if x != nil { + return x.State + } + return State_STATE_UNSPECIFIED +} + func (x *Webhook) GetCreateTime() *timestamppb.Timestamp { if x != nil { return x.CreateTime @@ -96,42 +137,51 @@ func (x *Webhook) GetUpdateTime() *timestamppb.Timestamp { return nil } -func (x *Webhook) GetName() string { +func (x *Webhook) GetEtag() string { if x != nil { - return x.Name + return x.Etag } return "" } -func (x *Webhook) GetUrl() string { - if x != nil { - return x.Url - } - return "" -} - -type CreateWebhookRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` +type ListWebhooksRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Optional. The maximum number of webhooks to return. + // The service may return fewer than this value. + // If unspecified, at most 50 webhooks will be returned. + // The maximum value is 1000; values above 1000 will be coerced to 1000. + PageSize int32 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` + // Optional. A page token, received from a previous `ListWebhooks` call. + // Provide this to retrieve the subsequent page. + PageToken string `protobuf:"bytes,2,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"` + // Optional. Filter to apply to the list results. + // Example: "state=ACTIVE" or "creator=users/123" + // Supported operators: =, !=, <, <=, >, >=, : + // Supported fields: display_name, url, creator, state, create_time, update_time + Filter string `protobuf:"bytes,3,opt,name=filter,proto3" json:"filter,omitempty"` + // Optional. The order to sort results by. + // Example: "create_time desc" or "display_name asc" + OrderBy string `protobuf:"bytes,4,opt,name=order_by,json=orderBy,proto3" json:"order_by,omitempty"` + // Optional. If true, show deleted webhooks in the response. + ShowDeleted bool `protobuf:"varint,5,opt,name=show_deleted,json=showDeleted,proto3" json:"show_deleted,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *CreateWebhookRequest) Reset() { - *x = CreateWebhookRequest{} +func (x *ListWebhooksRequest) Reset() { + *x = ListWebhooksRequest{} mi := &file_api_v1_webhook_service_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *CreateWebhookRequest) String() string { +func (x *ListWebhooksRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*CreateWebhookRequest) ProtoMessage() {} +func (*ListWebhooksRequest) ProtoMessage() {} -func (x *CreateWebhookRequest) ProtoReflect() protoreflect.Message { +func (x *ListWebhooksRequest) ProtoReflect() protoreflect.Message { mi := &file_api_v1_webhook_service_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -143,46 +193,73 @@ func (x *CreateWebhookRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use CreateWebhookRequest.ProtoReflect.Descriptor instead. -func (*CreateWebhookRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use ListWebhooksRequest.ProtoReflect.Descriptor instead. +func (*ListWebhooksRequest) Descriptor() ([]byte, []int) { return file_api_v1_webhook_service_proto_rawDescGZIP(), []int{1} } -func (x *CreateWebhookRequest) GetName() string { +func (x *ListWebhooksRequest) GetPageSize() int32 { if x != nil { - return x.Name + return x.PageSize + } + return 0 +} + +func (x *ListWebhooksRequest) GetPageToken() string { + if x != nil { + return x.PageToken } return "" } -func (x *CreateWebhookRequest) GetUrl() string { +func (x *ListWebhooksRequest) GetFilter() string { if x != nil { - return x.Url + return x.Filter } return "" } -type GetWebhookRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +func (x *ListWebhooksRequest) GetOrderBy() string { + if x != nil { + return x.OrderBy + } + return "" +} + +func (x *ListWebhooksRequest) GetShowDeleted() bool { + if x != nil { + return x.ShowDeleted + } + return false +} + +type ListWebhooksResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + // The list of webhooks. + Webhooks []*Webhook `protobuf:"bytes,1,rep,name=webhooks,proto3" json:"webhooks,omitempty"` + // A token that can be sent as `page_token` to retrieve the next page. + // If this field is omitted, there are no subsequent pages. + NextPageToken string `protobuf:"bytes,2,opt,name=next_page_token,json=nextPageToken,proto3" json:"next_page_token,omitempty"` + // The total count of webhooks (may be approximate). + TotalSize int32 `protobuf:"varint,3,opt,name=total_size,json=totalSize,proto3" json:"total_size,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *GetWebhookRequest) Reset() { - *x = GetWebhookRequest{} +func (x *ListWebhooksResponse) Reset() { + *x = ListWebhooksResponse{} mi := &file_api_v1_webhook_service_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *GetWebhookRequest) String() string { +func (x *ListWebhooksResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*GetWebhookRequest) ProtoMessage() {} +func (*ListWebhooksResponse) ProtoMessage() {} -func (x *GetWebhookRequest) ProtoReflect() protoreflect.Message { +func (x *ListWebhooksResponse) ProtoReflect() protoreflect.Message { mi := &file_api_v1_webhook_service_proto_msgTypes[2] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -194,40 +271,58 @@ func (x *GetWebhookRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use GetWebhookRequest.ProtoReflect.Descriptor instead. -func (*GetWebhookRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use ListWebhooksResponse.ProtoReflect.Descriptor instead. +func (*ListWebhooksResponse) Descriptor() ([]byte, []int) { return file_api_v1_webhook_service_proto_rawDescGZIP(), []int{2} } -func (x *GetWebhookRequest) GetId() int32 { +func (x *ListWebhooksResponse) GetWebhooks() []*Webhook { + if x != nil { + return x.Webhooks + } + return nil +} + +func (x *ListWebhooksResponse) GetNextPageToken() string { + if x != nil { + return x.NextPageToken + } + return "" +} + +func (x *ListWebhooksResponse) GetTotalSize() int32 { if x != nil { - return x.Id + return x.TotalSize } return 0 } -type ListWebhooksRequest struct { +type GetWebhookRequest struct { state protoimpl.MessageState `protogen:"open.v1"` - // The name of the creator. - Creator string `protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"` + // Required. The resource name of the webhook. + // Format: webhooks/{webhook} + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Optional. The fields to return in the response. + // If not specified, all fields are returned. + ReadMask *fieldmaskpb.FieldMask `protobuf:"bytes,2,opt,name=read_mask,json=readMask,proto3" json:"read_mask,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *ListWebhooksRequest) Reset() { - *x = ListWebhooksRequest{} +func (x *GetWebhookRequest) Reset() { + *x = GetWebhookRequest{} mi := &file_api_v1_webhook_service_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *ListWebhooksRequest) String() string { +func (x *GetWebhookRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ListWebhooksRequest) ProtoMessage() {} +func (*GetWebhookRequest) ProtoMessage() {} -func (x *ListWebhooksRequest) ProtoReflect() protoreflect.Message { +func (x *GetWebhookRequest) ProtoReflect() protoreflect.Message { mi := &file_api_v1_webhook_service_proto_msgTypes[3] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -239,39 +334,56 @@ func (x *ListWebhooksRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ListWebhooksRequest.ProtoReflect.Descriptor instead. -func (*ListWebhooksRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use GetWebhookRequest.ProtoReflect.Descriptor instead. +func (*GetWebhookRequest) Descriptor() ([]byte, []int) { return file_api_v1_webhook_service_proto_rawDescGZIP(), []int{3} } -func (x *ListWebhooksRequest) GetCreator() string { +func (x *GetWebhookRequest) GetName() string { if x != nil { - return x.Creator + return x.Name } return "" } -type ListWebhooksResponse struct { - state protoimpl.MessageState `protogen:"open.v1"` - Webhooks []*Webhook `protobuf:"bytes,1,rep,name=webhooks,proto3" json:"webhooks,omitempty"` +func (x *GetWebhookRequest) GetReadMask() *fieldmaskpb.FieldMask { + if x != nil { + return x.ReadMask + } + return nil +} + +type CreateWebhookRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Required. The webhook to create. + Webhook *Webhook `protobuf:"bytes,1,opt,name=webhook,proto3" json:"webhook,omitempty"` + // Optional. The webhook ID to use for this webhook. + // If empty, a unique ID will be generated. + // Must match the pattern [a-z0-9-]+ + WebhookId string `protobuf:"bytes,2,opt,name=webhook_id,json=webhookId,proto3" json:"webhook_id,omitempty"` + // Optional. If set, validate the request but don't actually create the webhook. + ValidateOnly bool `protobuf:"varint,3,opt,name=validate_only,json=validateOnly,proto3" json:"validate_only,omitempty"` + // Optional. An idempotency token that can be used to ensure that multiple + // requests to create a webhook have the same result. + RequestId string `protobuf:"bytes,4,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *ListWebhooksResponse) Reset() { - *x = ListWebhooksResponse{} +func (x *CreateWebhookRequest) Reset() { + *x = CreateWebhookRequest{} mi := &file_api_v1_webhook_service_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *ListWebhooksResponse) String() string { +func (x *CreateWebhookRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ListWebhooksResponse) ProtoMessage() {} +func (*CreateWebhookRequest) ProtoMessage() {} -func (x *ListWebhooksResponse) ProtoReflect() protoreflect.Message { +func (x *CreateWebhookRequest) ProtoReflect() protoreflect.Message { mi := &file_api_v1_webhook_service_proto_msgTypes[4] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -283,22 +395,47 @@ func (x *ListWebhooksResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ListWebhooksResponse.ProtoReflect.Descriptor instead. -func (*ListWebhooksResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use CreateWebhookRequest.ProtoReflect.Descriptor instead. +func (*CreateWebhookRequest) Descriptor() ([]byte, []int) { return file_api_v1_webhook_service_proto_rawDescGZIP(), []int{4} } -func (x *ListWebhooksResponse) GetWebhooks() []*Webhook { +func (x *CreateWebhookRequest) GetWebhook() *Webhook { if x != nil { - return x.Webhooks + return x.Webhook } return nil } +func (x *CreateWebhookRequest) GetWebhookId() string { + if x != nil { + return x.WebhookId + } + return "" +} + +func (x *CreateWebhookRequest) GetValidateOnly() bool { + if x != nil { + return x.ValidateOnly + } + return false +} + +func (x *CreateWebhookRequest) GetRequestId() string { + if x != nil { + return x.RequestId + } + return "" +} + type UpdateWebhookRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - Webhook *Webhook `protobuf:"bytes,1,opt,name=webhook,proto3" json:"webhook,omitempty"` - UpdateMask *fieldmaskpb.FieldMask `protobuf:"bytes,2,opt,name=update_mask,json=updateMask,proto3" json:"update_mask,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + // Required. The webhook to update. + Webhook *Webhook `protobuf:"bytes,1,opt,name=webhook,proto3" json:"webhook,omitempty"` + // Required. The list of fields to update. + UpdateMask *fieldmaskpb.FieldMask `protobuf:"bytes,2,opt,name=update_mask,json=updateMask,proto3" json:"update_mask,omitempty"` + // Optional. If set to true, allows updating sensitive fields. + AllowMissing bool `protobuf:"varint,3,opt,name=allow_missing,json=allowMissing,proto3" json:"allow_missing,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -347,9 +484,20 @@ func (x *UpdateWebhookRequest) GetUpdateMask() *fieldmaskpb.FieldMask { return nil } +func (x *UpdateWebhookRequest) GetAllowMissing() bool { + if x != nil { + return x.AllowMissing + } + return false +} + type DeleteWebhookRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + // Required. The resource name of the webhook to delete. + // Format: webhooks/{webhook} + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Optional. If set to true, the webhook will be deleted even if it has associated data. + Force bool `protobuf:"varint,2,opt,name=force,proto3" json:"force,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -384,22 +532,33 @@ func (*DeleteWebhookRequest) Descriptor() ([]byte, []int) { return file_api_v1_webhook_service_proto_rawDescGZIP(), []int{6} } -func (x *DeleteWebhookRequest) GetId() int32 { +func (x *DeleteWebhookRequest) GetName() string { if x != nil { - return x.Id + return x.Name } - return 0 + return "" +} + +func (x *DeleteWebhookRequest) GetForce() bool { + if x != nil { + return x.Force + } + return false } type WebhookRequestPayload struct { - state protoimpl.MessageState `protogen:"open.v1"` - Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` - ActivityType string `protobuf:"bytes,2,opt,name=activity_type,json=activityType,proto3" json:"activity_type,omitempty"` - // The name of the creator. + state protoimpl.MessageState `protogen:"open.v1"` + // The target URL for the webhook request. + Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` + // The type of activity that triggered this webhook. + ActivityType string `protobuf:"bytes,2,opt,name=activity_type,json=activityType,proto3" json:"activity_type,omitempty"` + // The resource name of the creator. // Format: users/{user} - Creator string `protobuf:"bytes,3,opt,name=creator,proto3" json:"creator,omitempty"` - CreateTime *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` - Memo *Memo `protobuf:"bytes,5,opt,name=memo,proto3" json:"memo,omitempty"` + Creator string `protobuf:"bytes,3,opt,name=creator,proto3" json:"creator,omitempty"` + // The creation timestamp of the activity. + CreateTime *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` + // The memo that triggered this webhook (if applicable). + Memo *Memo `protobuf:"bytes,5,opt,name=memo,proto3" json:"memo,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -473,45 +632,67 @@ var File_api_v1_webhook_service_proto protoreflect.FileDescriptor const file_api_v1_webhook_service_proto_rawDesc = "" + "\n" + - "\x1capi/v1/webhook_service.proto\x12\fmemos.api.v1\x1a\x19api/v1/memo_service.proto\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xd3\x01\n" + - "\aWebhook\x12\x0e\n" + - "\x02id\x18\x01 \x01(\x05R\x02id\x12\x18\n" + - "\acreator\x18\x02 \x01(\tR\acreator\x12;\n" + - "\vcreate_time\x18\x03 \x01(\v2\x1a.google.protobuf.TimestampR\n" + - "createTime\x12;\n" + - "\vupdate_time\x18\x04 \x01(\v2\x1a.google.protobuf.TimestampR\n" + - "updateTime\x12\x12\n" + - "\x04name\x18\x05 \x01(\tR\x04name\x12\x10\n" + - "\x03url\x18\x06 \x01(\tR\x03url\"<\n" + - "\x14CreateWebhookRequest\x12\x12\n" + - "\x04name\x18\x01 \x01(\tR\x04name\x12\x10\n" + - "\x03url\x18\x02 \x01(\tR\x03url\"#\n" + - "\x11GetWebhookRequest\x12\x0e\n" + - "\x02id\x18\x01 \x01(\x05R\x02id\"/\n" + - "\x13ListWebhooksRequest\x12\x18\n" + - "\acreator\x18\x02 \x01(\tR\acreator\"I\n" + + "\x1capi/v1/webhook_service.proto\x12\fmemos.api.v1\x1a\x13api/v1/common.proto\x1a\x19api/v1/memo_service.proto\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/resource.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xac\x03\n" + + "\aWebhook\x12\x17\n" + + "\x04name\x18\x01 \x01(\tB\x03\xe0A\bR\x04name\x12\x15\n" + + "\x03uid\x18\x02 \x01(\tB\x03\xe0A\x03R\x03uid\x12&\n" + + "\fdisplay_name\x18\x03 \x01(\tB\x03\xe0A\x02R\vdisplayName\x12\x15\n" + + "\x03url\x18\x04 \x01(\tB\x03\xe0A\x02R\x03url\x12\x1d\n" + + "\acreator\x18\x05 \x01(\tB\x03\xe0A\x03R\acreator\x12.\n" + + "\x05state\x18\x06 \x01(\x0e2\x13.memos.api.v1.StateB\x03\xe0A\x02R\x05state\x12@\n" + + "\vcreate_time\x18\a \x01(\v2\x1a.google.protobuf.TimestampB\x03\xe0A\x03R\n" + + "createTime\x12@\n" + + "\vupdate_time\x18\b \x01(\v2\x1a.google.protobuf.TimestampB\x03\xe0A\x03R\n" + + "updateTime\x12\x17\n" + + "\x04etag\x18\t \x01(\tB\x03\xe0A\x03R\x04etag:F\xeaAC\n" + + "\x14memos.api.v1/Webhook\x12\x12webhooks/{webhook}\x1a\x04name*\bwebhooks2\awebhook\"\xc0\x01\n" + + "\x13ListWebhooksRequest\x12 \n" + + "\tpage_size\x18\x01 \x01(\x05B\x03\xe0A\x01R\bpageSize\x12\"\n" + + "\n" + + "page_token\x18\x02 \x01(\tB\x03\xe0A\x01R\tpageToken\x12\x1b\n" + + "\x06filter\x18\x03 \x01(\tB\x03\xe0A\x01R\x06filter\x12\x1e\n" + + "\border_by\x18\x04 \x01(\tB\x03\xe0A\x01R\aorderBy\x12&\n" + + "\fshow_deleted\x18\x05 \x01(\bB\x03\xe0A\x01R\vshowDeleted\"\x90\x01\n" + "\x14ListWebhooksResponse\x121\n" + - "\bwebhooks\x18\x01 \x03(\v2\x15.memos.api.v1.WebhookR\bwebhooks\"\x84\x01\n" + - "\x14UpdateWebhookRequest\x12/\n" + - "\awebhook\x18\x01 \x01(\v2\x15.memos.api.v1.WebhookR\awebhook\x12;\n" + - "\vupdate_mask\x18\x02 \x01(\v2\x1a.google.protobuf.FieldMaskR\n" + - "updateMask\"&\n" + - "\x14DeleteWebhookRequest\x12\x0e\n" + - "\x02id\x18\x01 \x01(\x05R\x02id\"\xcd\x01\n" + - "\x15WebhookRequestPayload\x12\x10\n" + - "\x03url\x18\x01 \x01(\tR\x03url\x12#\n" + - "\ractivity_type\x18\x02 \x01(\tR\factivityType\x12\x18\n" + - "\acreator\x18\x03 \x01(\tR\acreator\x12;\n" + - "\vcreate_time\x18\x04 \x01(\v2\x1a.google.protobuf.TimestampR\n" + - "createTime\x12&\n" + - "\x04memo\x18\x05 \x01(\v2\x12.memos.api.v1.MemoR\x04memo2\xd8\x04\n" + - "\x0eWebhookService\x12g\n" + - "\rCreateWebhook\x12\".memos.api.v1.CreateWebhookRequest\x1a\x15.memos.api.v1.Webhook\"\x1b\x82\xd3\xe4\x93\x02\x15:\x01*\"\x10/api/v1/webhooks\x12h\n" + + "\bwebhooks\x18\x01 \x03(\v2\x15.memos.api.v1.WebhookR\bwebhooks\x12&\n" + + "\x0fnext_page_token\x18\x02 \x01(\tR\rnextPageToken\x12\x1d\n" + + "\n" + + "total_size\x18\x03 \x01(\x05R\ttotalSize\"\x83\x01\n" + + "\x11GetWebhookRequest\x120\n" + + "\x04name\x18\x01 \x01(\tB\x1c\xe0A\x02\xfaA\x16\n" + + "\x14memos.api.v1/WebhookR\x04name\x12<\n" + + "\tread_mask\x18\x02 \x01(\v2\x1a.google.protobuf.FieldMaskB\x03\xe0A\x01R\breadMask\"\xc1\x01\n" + + "\x14CreateWebhookRequest\x127\n" + + "\awebhook\x18\x01 \x01(\v2\x15.memos.api.v1.WebhookB\x06\xe0A\x02\xe0A\x04R\awebhook\x12\"\n" + + "\n" + + "webhook_id\x18\x02 \x01(\tB\x03\xe0A\x01R\twebhookId\x12(\n" + + "\rvalidate_only\x18\x03 \x01(\bB\x03\xe0A\x01R\fvalidateOnly\x12\"\n" + + "\n" + + "request_id\x18\x04 \x01(\tB\x03\xe0A\x01R\trequestId\"\xb8\x01\n" + + "\x14UpdateWebhookRequest\x124\n" + + "\awebhook\x18\x01 \x01(\v2\x15.memos.api.v1.WebhookB\x03\xe0A\x02R\awebhook\x12@\n" + + "\vupdate_mask\x18\x02 \x01(\v2\x1a.google.protobuf.FieldMaskB\x03\xe0A\x02R\n" + + "updateMask\x12(\n" + + "\rallow_missing\x18\x03 \x01(\bB\x03\xe0A\x01R\fallowMissing\"c\n" + + "\x14DeleteWebhookRequest\x120\n" + + "\x04name\x18\x01 \x01(\tB\x1c\xe0A\x02\xfaA\x16\n" + + "\x14memos.api.v1/WebhookR\x04name\x12\x19\n" + + "\x05force\x18\x02 \x01(\bB\x03\xe0A\x01R\x05force\"\xfc\x01\n" + + "\x15WebhookRequestPayload\x12\x15\n" + + "\x03url\x18\x01 \x01(\tB\x03\xe0A\x02R\x03url\x12(\n" + + "\ractivity_type\x18\x02 \x01(\tB\x03\xe0A\x02R\factivityType\x123\n" + + "\acreator\x18\x03 \x01(\tB\x19\xe0A\x03\xfaA\x13\n" + + "\x11memos.api.v1/UserR\acreator\x12@\n" + + "\vcreate_time\x18\x04 \x01(\v2\x1a.google.protobuf.TimestampB\x03\xe0A\x03R\n" + + "createTime\x12+\n" + + "\x04memo\x18\x05 \x01(\v2\x12.memos.api.v1.MemoB\x03\xe0A\x01R\x04memo2\xf8\x04\n" + + "\x0eWebhookService\x12o\n" + + "\fListWebhooks\x12!.memos.api.v1.ListWebhooksRequest\x1a\".memos.api.v1.ListWebhooksResponse\"\x18\x82\xd3\xe4\x93\x02\x12\x12\x10/api/v1/webhooks\x12n\n" + "\n" + - "GetWebhook\x12\x1f.memos.api.v1.GetWebhookRequest\x1a\x15.memos.api.v1.Webhook\"\"\xdaA\x02id\x82\xd3\xe4\x93\x02\x17\x12\x15/api/v1/webhooks/{id}\x12o\n" + - "\fListWebhooks\x12!.memos.api.v1.ListWebhooksRequest\x1a\".memos.api.v1.ListWebhooksResponse\"\x18\x82\xd3\xe4\x93\x02\x12\x12\x10/api/v1/webhooks\x12\x90\x01\n" + - "\rUpdateWebhook\x12\".memos.api.v1.UpdateWebhookRequest\x1a\x15.memos.api.v1.Webhook\"D\xdaA\x13webhook,update_mask\x82\xd3\xe4\x93\x02(:\awebhook2\x1d/api/v1/webhooks/{webhook.id}\x12o\n" + - "\rDeleteWebhook\x12\".memos.api.v1.DeleteWebhookRequest\x1a\x16.google.protobuf.Empty\"\"\xdaA\x02id\x82\xd3\xe4\x93\x02\x17*\x15/api/v1/webhooks/{id}B\xab\x01\n" + + "GetWebhook\x12\x1f.memos.api.v1.GetWebhookRequest\x1a\x15.memos.api.v1.Webhook\"(\xdaA\x04name\x82\xd3\xe4\x93\x02\x1b\x12\x19/api/v1/{name=webhooks/*}\x12w\n" + + "\rCreateWebhook\x12\".memos.api.v1.CreateWebhookRequest\x1a\x15.memos.api.v1.Webhook\"+\xdaA\awebhook\x82\xd3\xe4\x93\x02\x1b:\awebhook\"\x10/api/v1/webhooks\x12\x94\x01\n" + + "\rUpdateWebhook\x12\".memos.api.v1.UpdateWebhookRequest\x1a\x15.memos.api.v1.Webhook\"H\xdaA\x13webhook,update_mask\x82\xd3\xe4\x93\x02,:\awebhook2!/api/v1/{webhook.name=webhooks/*}\x12u\n" + + "\rDeleteWebhook\x12\".memos.api.v1.DeleteWebhookRequest\x1a\x16.google.protobuf.Empty\"(\xdaA\x04name\x82\xd3\xe4\x93\x02\x1b*\x19/api/v1/{name=webhooks/*}B\xab\x01\n" + "\x10com.memos.api.v1B\x13WebhookServiceProtoP\x01Z0github.com/usememos/memos/proto/gen/api/v1;apiv1\xa2\x02\x03MAX\xaa\x02\fMemos.Api.V1\xca\x02\fMemos\\Api\\V1\xe2\x02\x18Memos\\Api\\V1\\GPBMetadata\xea\x02\x0eMemos::Api::V1b\x06proto3" var ( @@ -529,41 +710,45 @@ func file_api_v1_webhook_service_proto_rawDescGZIP() []byte { var file_api_v1_webhook_service_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_api_v1_webhook_service_proto_goTypes = []any{ (*Webhook)(nil), // 0: memos.api.v1.Webhook - (*CreateWebhookRequest)(nil), // 1: memos.api.v1.CreateWebhookRequest - (*GetWebhookRequest)(nil), // 2: memos.api.v1.GetWebhookRequest - (*ListWebhooksRequest)(nil), // 3: memos.api.v1.ListWebhooksRequest - (*ListWebhooksResponse)(nil), // 4: memos.api.v1.ListWebhooksResponse + (*ListWebhooksRequest)(nil), // 1: memos.api.v1.ListWebhooksRequest + (*ListWebhooksResponse)(nil), // 2: memos.api.v1.ListWebhooksResponse + (*GetWebhookRequest)(nil), // 3: memos.api.v1.GetWebhookRequest + (*CreateWebhookRequest)(nil), // 4: memos.api.v1.CreateWebhookRequest (*UpdateWebhookRequest)(nil), // 5: memos.api.v1.UpdateWebhookRequest (*DeleteWebhookRequest)(nil), // 6: memos.api.v1.DeleteWebhookRequest (*WebhookRequestPayload)(nil), // 7: memos.api.v1.WebhookRequestPayload - (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp - (*fieldmaskpb.FieldMask)(nil), // 9: google.protobuf.FieldMask - (*Memo)(nil), // 10: memos.api.v1.Memo - (*emptypb.Empty)(nil), // 11: google.protobuf.Empty + (State)(0), // 8: memos.api.v1.State + (*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp + (*fieldmaskpb.FieldMask)(nil), // 10: google.protobuf.FieldMask + (*Memo)(nil), // 11: memos.api.v1.Memo + (*emptypb.Empty)(nil), // 12: google.protobuf.Empty } var file_api_v1_webhook_service_proto_depIdxs = []int32{ - 8, // 0: memos.api.v1.Webhook.create_time:type_name -> google.protobuf.Timestamp - 8, // 1: memos.api.v1.Webhook.update_time:type_name -> google.protobuf.Timestamp - 0, // 2: memos.api.v1.ListWebhooksResponse.webhooks:type_name -> memos.api.v1.Webhook - 0, // 3: memos.api.v1.UpdateWebhookRequest.webhook:type_name -> memos.api.v1.Webhook - 9, // 4: memos.api.v1.UpdateWebhookRequest.update_mask:type_name -> google.protobuf.FieldMask - 8, // 5: memos.api.v1.WebhookRequestPayload.create_time:type_name -> google.protobuf.Timestamp - 10, // 6: memos.api.v1.WebhookRequestPayload.memo:type_name -> memos.api.v1.Memo - 1, // 7: memos.api.v1.WebhookService.CreateWebhook:input_type -> memos.api.v1.CreateWebhookRequest - 2, // 8: memos.api.v1.WebhookService.GetWebhook:input_type -> memos.api.v1.GetWebhookRequest - 3, // 9: memos.api.v1.WebhookService.ListWebhooks:input_type -> memos.api.v1.ListWebhooksRequest - 5, // 10: memos.api.v1.WebhookService.UpdateWebhook:input_type -> memos.api.v1.UpdateWebhookRequest - 6, // 11: memos.api.v1.WebhookService.DeleteWebhook:input_type -> memos.api.v1.DeleteWebhookRequest - 0, // 12: memos.api.v1.WebhookService.CreateWebhook:output_type -> memos.api.v1.Webhook - 0, // 13: memos.api.v1.WebhookService.GetWebhook:output_type -> memos.api.v1.Webhook - 4, // 14: memos.api.v1.WebhookService.ListWebhooks:output_type -> memos.api.v1.ListWebhooksResponse - 0, // 15: memos.api.v1.WebhookService.UpdateWebhook:output_type -> memos.api.v1.Webhook - 11, // 16: memos.api.v1.WebhookService.DeleteWebhook:output_type -> google.protobuf.Empty - 12, // [12:17] is the sub-list for method output_type - 7, // [7:12] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 8, // 0: memos.api.v1.Webhook.state:type_name -> memos.api.v1.State + 9, // 1: memos.api.v1.Webhook.create_time:type_name -> google.protobuf.Timestamp + 9, // 2: memos.api.v1.Webhook.update_time:type_name -> google.protobuf.Timestamp + 0, // 3: memos.api.v1.ListWebhooksResponse.webhooks:type_name -> memos.api.v1.Webhook + 10, // 4: memos.api.v1.GetWebhookRequest.read_mask:type_name -> google.protobuf.FieldMask + 0, // 5: memos.api.v1.CreateWebhookRequest.webhook:type_name -> memos.api.v1.Webhook + 0, // 6: memos.api.v1.UpdateWebhookRequest.webhook:type_name -> memos.api.v1.Webhook + 10, // 7: memos.api.v1.UpdateWebhookRequest.update_mask:type_name -> google.protobuf.FieldMask + 9, // 8: memos.api.v1.WebhookRequestPayload.create_time:type_name -> google.protobuf.Timestamp + 11, // 9: memos.api.v1.WebhookRequestPayload.memo:type_name -> memos.api.v1.Memo + 1, // 10: memos.api.v1.WebhookService.ListWebhooks:input_type -> memos.api.v1.ListWebhooksRequest + 3, // 11: memos.api.v1.WebhookService.GetWebhook:input_type -> memos.api.v1.GetWebhookRequest + 4, // 12: memos.api.v1.WebhookService.CreateWebhook:input_type -> memos.api.v1.CreateWebhookRequest + 5, // 13: memos.api.v1.WebhookService.UpdateWebhook:input_type -> memos.api.v1.UpdateWebhookRequest + 6, // 14: memos.api.v1.WebhookService.DeleteWebhook:input_type -> memos.api.v1.DeleteWebhookRequest + 2, // 15: memos.api.v1.WebhookService.ListWebhooks:output_type -> memos.api.v1.ListWebhooksResponse + 0, // 16: memos.api.v1.WebhookService.GetWebhook:output_type -> memos.api.v1.Webhook + 0, // 17: memos.api.v1.WebhookService.CreateWebhook:output_type -> memos.api.v1.Webhook + 0, // 18: memos.api.v1.WebhookService.UpdateWebhook:output_type -> memos.api.v1.Webhook + 12, // 19: memos.api.v1.WebhookService.DeleteWebhook:output_type -> google.protobuf.Empty + 15, // [15:20] is the sub-list for method output_type + 10, // [10:15] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_api_v1_webhook_service_proto_init() } @@ -571,6 +756,7 @@ func file_api_v1_webhook_service_proto_init() { if File_api_v1_webhook_service_proto != nil { return } + file_api_v1_common_proto_init() file_api_v1_memo_service_proto_init() type x struct{} out := protoimpl.TypeBuilder{ diff --git a/proto/gen/api/v1/webhook_service.pb.gw.go b/proto/gen/api/v1/webhook_service.pb.gw.go index 35192e4c2..54d13c284 100644 --- a/proto/gen/api/v1/webhook_service.pb.gw.go +++ b/proto/gen/api/v1/webhook_service.pb.gw.go @@ -35,30 +35,41 @@ var ( _ = metadata.Join ) -func request_WebhookService_CreateWebhook_0(ctx context.Context, marshaler runtime.Marshaler, client WebhookServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +var filter_WebhookService_ListWebhooks_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + +func request_WebhookService_ListWebhooks_0(ctx context.Context, marshaler runtime.Marshaler, client WebhookServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( - protoReq CreateWebhookRequest + protoReq ListWebhooksRequest metadata runtime.ServerMetadata ) - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + io.Copy(io.Discard, req.Body) + if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.CreateWebhook(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_ListWebhooks_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.ListWebhooks(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_WebhookService_CreateWebhook_0(ctx context.Context, marshaler runtime.Marshaler, server WebhookServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_WebhookService_ListWebhooks_0(ctx context.Context, marshaler runtime.Marshaler, server WebhookServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( - protoReq CreateWebhookRequest + protoReq ListWebhooksRequest metadata runtime.ServerMetadata ) - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.CreateWebhook(ctx, &protoReq) + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_ListWebhooks_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.ListWebhooks(ctx, &protoReq) return msg, metadata, err } +var filter_WebhookService_GetWebhook_0 = &utilities.DoubleArray{Encoding: map[string]int{"name": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} + func request_WebhookService_GetWebhook_0(ctx context.Context, marshaler runtime.Marshaler, client WebhookServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( protoReq GetWebhookRequest @@ -66,13 +77,19 @@ func request_WebhookService_GetWebhook_0(ctx context.Context, marshaler runtime. err error ) io.Copy(io.Discard, req.Body) - val, ok := pathParams["id"] + val, ok := pathParams["name"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") } - protoReq.Id, err = runtime.Int32(val) + protoReq.Name, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_GetWebhook_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } msg, err := client.GetWebhook(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -84,52 +101,63 @@ func local_request_WebhookService_GetWebhook_0(ctx context.Context, marshaler ru metadata runtime.ServerMetadata err error ) - val, ok := pathParams["id"] + val, ok := pathParams["name"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") } - protoReq.Id, err = runtime.Int32(val) + protoReq.Name, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_GetWebhook_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } msg, err := server.GetWebhook(ctx, &protoReq) return msg, metadata, err } -var filter_WebhookService_ListWebhooks_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +var filter_WebhookService_CreateWebhook_0 = &utilities.DoubleArray{Encoding: map[string]int{"webhook": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} -func request_WebhookService_ListWebhooks_0(ctx context.Context, marshaler runtime.Marshaler, client WebhookServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_WebhookService_CreateWebhook_0(ctx context.Context, marshaler runtime.Marshaler, client WebhookServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( - protoReq ListWebhooksRequest + protoReq CreateWebhookRequest metadata runtime.ServerMetadata ) - io.Copy(io.Discard, req.Body) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Webhook); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_ListWebhooks_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_CreateWebhook_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.ListWebhooks(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.CreateWebhook(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_WebhookService_ListWebhooks_0(ctx context.Context, marshaler runtime.Marshaler, server WebhookServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_WebhookService_CreateWebhook_0(ctx context.Context, marshaler runtime.Marshaler, server WebhookServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( - protoReq ListWebhooksRequest + protoReq CreateWebhookRequest metadata runtime.ServerMetadata ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Webhook); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_ListWebhooks_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_CreateWebhook_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.ListWebhooks(ctx, &protoReq) + msg, err := server.CreateWebhook(ctx, &protoReq) return msg, metadata, err } -var filter_WebhookService_UpdateWebhook_0 = &utilities.DoubleArray{Encoding: map[string]int{"webhook": 0, "id": 1}, Base: []int{1, 2, 1, 0, 0}, Check: []int{0, 1, 2, 3, 2}} +var filter_WebhookService_UpdateWebhook_0 = &utilities.DoubleArray{Encoding: map[string]int{"webhook": 0, "name": 1}, Base: []int{1, 2, 1, 0, 0}, Check: []int{0, 1, 2, 3, 2}} func request_WebhookService_UpdateWebhook_0(ctx context.Context, marshaler runtime.Marshaler, client WebhookServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( @@ -151,13 +179,13 @@ func request_WebhookService_UpdateWebhook_0(ctx context.Context, marshaler runti protoReq.UpdateMask = fieldMask } } - val, ok := pathParams["webhook.id"] + val, ok := pathParams["webhook.name"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "webhook.id") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "webhook.name") } - err = runtime.PopulateFieldFromPath(&protoReq, "webhook.id", val) + err = runtime.PopulateFieldFromPath(&protoReq, "webhook.name", val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "webhook.id", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "webhook.name", err) } if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) @@ -189,13 +217,13 @@ func local_request_WebhookService_UpdateWebhook_0(ctx context.Context, marshaler protoReq.UpdateMask = fieldMask } } - val, ok := pathParams["webhook.id"] + val, ok := pathParams["webhook.name"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "webhook.id") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "webhook.name") } - err = runtime.PopulateFieldFromPath(&protoReq, "webhook.id", val) + err = runtime.PopulateFieldFromPath(&protoReq, "webhook.name", val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "webhook.id", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "webhook.name", err) } if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) @@ -207,6 +235,8 @@ func local_request_WebhookService_UpdateWebhook_0(ctx context.Context, marshaler return msg, metadata, err } +var filter_WebhookService_DeleteWebhook_0 = &utilities.DoubleArray{Encoding: map[string]int{"name": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} + func request_WebhookService_DeleteWebhook_0(ctx context.Context, marshaler runtime.Marshaler, client WebhookServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( protoReq DeleteWebhookRequest @@ -214,13 +244,19 @@ func request_WebhookService_DeleteWebhook_0(ctx context.Context, marshaler runti err error ) io.Copy(io.Discard, req.Body) - val, ok := pathParams["id"] + val, ok := pathParams["name"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") } - protoReq.Id, err = runtime.Int32(val) + protoReq.Name, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_DeleteWebhook_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } msg, err := client.DeleteWebhook(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -232,13 +268,19 @@ func local_request_WebhookService_DeleteWebhook_0(ctx context.Context, marshaler metadata runtime.ServerMetadata err error ) - val, ok := pathParams["id"] + val, ok := pathParams["name"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") } - protoReq.Id, err = runtime.Int32(val) + protoReq.Name, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WebhookService_DeleteWebhook_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } msg, err := server.DeleteWebhook(ctx, &protoReq) return msg, metadata, err @@ -250,25 +292,25 @@ func local_request_WebhookService_DeleteWebhook_0(ctx context.Context, marshaler // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterWebhookServiceHandlerFromEndpoint instead. // GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call. func RegisterWebhookServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server WebhookServiceServer) error { - mux.Handle(http.MethodPost, pattern_WebhookService_CreateWebhook_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle(http.MethodGet, pattern_WebhookService_ListWebhooks_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/CreateWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/ListWebhooks", runtime.WithHTTPPathPattern("/api/v1/webhooks")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_WebhookService_CreateWebhook_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_WebhookService_ListWebhooks_0(annotatedContext, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) if err != nil { runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) return } - forward_WebhookService_CreateWebhook_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_WebhookService_ListWebhooks_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) mux.Handle(http.MethodGet, pattern_WebhookService_GetWebhook_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) @@ -276,7 +318,7 @@ func RegisterWebhookServiceHandlerServer(ctx context.Context, mux *runtime.Serve var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/GetWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks/{id}")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/GetWebhook", runtime.WithHTTPPathPattern("/api/v1/{name=webhooks/*}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -290,25 +332,25 @@ func RegisterWebhookServiceHandlerServer(ctx context.Context, mux *runtime.Serve } forward_WebhookService_GetWebhook_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle(http.MethodGet, pattern_WebhookService_ListWebhooks_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle(http.MethodPost, pattern_WebhookService_CreateWebhook_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/ListWebhooks", runtime.WithHTTPPathPattern("/api/v1/webhooks")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/CreateWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_WebhookService_ListWebhooks_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_WebhookService_CreateWebhook_0(annotatedContext, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) if err != nil { runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) return } - forward_WebhookService_ListWebhooks_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_WebhookService_CreateWebhook_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) mux.Handle(http.MethodPatch, pattern_WebhookService_UpdateWebhook_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) @@ -316,7 +358,7 @@ func RegisterWebhookServiceHandlerServer(ctx context.Context, mux *runtime.Serve var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/UpdateWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks/{webhook.id}")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/UpdateWebhook", runtime.WithHTTPPathPattern("/api/v1/{webhook.name=webhooks/*}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -336,7 +378,7 @@ func RegisterWebhookServiceHandlerServer(ctx context.Context, mux *runtime.Serve var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/DeleteWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks/{id}")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.WebhookService/DeleteWebhook", runtime.WithHTTPPathPattern("/api/v1/{name=webhooks/*}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -390,28 +432,28 @@ func RegisterWebhookServiceHandler(ctx context.Context, mux *runtime.ServeMux, c // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in // "WebhookServiceClient" to call the correct interceptors. This client ignores the HTTP middlewares. func RegisterWebhookServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client WebhookServiceClient) error { - mux.Handle(http.MethodPost, pattern_WebhookService_CreateWebhook_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle(http.MethodGet, pattern_WebhookService_ListWebhooks_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/CreateWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/ListWebhooks", runtime.WithHTTPPathPattern("/api/v1/webhooks")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_WebhookService_CreateWebhook_0(annotatedContext, inboundMarshaler, client, req, pathParams) + resp, md, err := request_WebhookService_ListWebhooks_0(annotatedContext, inboundMarshaler, client, req, pathParams) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) if err != nil { runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) return } - forward_WebhookService_CreateWebhook_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_WebhookService_ListWebhooks_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) mux.Handle(http.MethodGet, pattern_WebhookService_GetWebhook_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/GetWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks/{id}")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/GetWebhook", runtime.WithHTTPPathPattern("/api/v1/{name=webhooks/*}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -424,28 +466,28 @@ func RegisterWebhookServiceHandlerClient(ctx context.Context, mux *runtime.Serve } forward_WebhookService_GetWebhook_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle(http.MethodGet, pattern_WebhookService_ListWebhooks_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle(http.MethodPost, pattern_WebhookService_CreateWebhook_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/ListWebhooks", runtime.WithHTTPPathPattern("/api/v1/webhooks")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/CreateWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_WebhookService_ListWebhooks_0(annotatedContext, inboundMarshaler, client, req, pathParams) + resp, md, err := request_WebhookService_CreateWebhook_0(annotatedContext, inboundMarshaler, client, req, pathParams) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) if err != nil { runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) return } - forward_WebhookService_ListWebhooks_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_WebhookService_CreateWebhook_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) mux.Handle(http.MethodPatch, pattern_WebhookService_UpdateWebhook_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/UpdateWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks/{webhook.id}")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/UpdateWebhook", runtime.WithHTTPPathPattern("/api/v1/{webhook.name=webhooks/*}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -462,7 +504,7 @@ func RegisterWebhookServiceHandlerClient(ctx context.Context, mux *runtime.Serve ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/DeleteWebhook", runtime.WithHTTPPathPattern("/api/v1/webhooks/{id}")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.WebhookService/DeleteWebhook", runtime.WithHTTPPathPattern("/api/v1/{name=webhooks/*}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -479,17 +521,17 @@ func RegisterWebhookServiceHandlerClient(ctx context.Context, mux *runtime.Serve } var ( - pattern_WebhookService_CreateWebhook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "webhooks"}, "")) - pattern_WebhookService_GetWebhook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "webhooks", "id"}, "")) pattern_WebhookService_ListWebhooks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "webhooks"}, "")) - pattern_WebhookService_UpdateWebhook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "webhooks", "webhook.id"}, "")) - pattern_WebhookService_DeleteWebhook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "webhooks", "id"}, "")) + pattern_WebhookService_GetWebhook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "webhooks", "name"}, "")) + pattern_WebhookService_CreateWebhook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "webhooks"}, "")) + pattern_WebhookService_UpdateWebhook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "webhooks", "webhook.name"}, "")) + pattern_WebhookService_DeleteWebhook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "webhooks", "name"}, "")) ) var ( - forward_WebhookService_CreateWebhook_0 = runtime.ForwardResponseMessage - forward_WebhookService_GetWebhook_0 = runtime.ForwardResponseMessage forward_WebhookService_ListWebhooks_0 = runtime.ForwardResponseMessage + forward_WebhookService_GetWebhook_0 = runtime.ForwardResponseMessage + forward_WebhookService_CreateWebhook_0 = runtime.ForwardResponseMessage forward_WebhookService_UpdateWebhook_0 = runtime.ForwardResponseMessage forward_WebhookService_DeleteWebhook_0 = runtime.ForwardResponseMessage ) diff --git a/proto/gen/api/v1/webhook_service_grpc.pb.go b/proto/gen/api/v1/webhook_service_grpc.pb.go index a700ff916..a59cce50e 100644 --- a/proto/gen/api/v1/webhook_service_grpc.pb.go +++ b/proto/gen/api/v1/webhook_service_grpc.pb.go @@ -20,9 +20,9 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - WebhookService_CreateWebhook_FullMethodName = "/memos.api.v1.WebhookService/CreateWebhook" - WebhookService_GetWebhook_FullMethodName = "/memos.api.v1.WebhookService/GetWebhook" WebhookService_ListWebhooks_FullMethodName = "/memos.api.v1.WebhookService/ListWebhooks" + WebhookService_GetWebhook_FullMethodName = "/memos.api.v1.WebhookService/GetWebhook" + WebhookService_CreateWebhook_FullMethodName = "/memos.api.v1.WebhookService/CreateWebhook" WebhookService_UpdateWebhook_FullMethodName = "/memos.api.v1.WebhookService/UpdateWebhook" WebhookService_DeleteWebhook_FullMethodName = "/memos.api.v1.WebhookService/DeleteWebhook" ) @@ -31,15 +31,15 @@ const ( // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type WebhookServiceClient interface { - // CreateWebhook creates a new webhook. - CreateWebhook(ctx context.Context, in *CreateWebhookRequest, opts ...grpc.CallOption) (*Webhook, error) - // GetWebhook returns a webhook by id. - GetWebhook(ctx context.Context, in *GetWebhookRequest, opts ...grpc.CallOption) (*Webhook, error) // ListWebhooks returns a list of webhooks. ListWebhooks(ctx context.Context, in *ListWebhooksRequest, opts ...grpc.CallOption) (*ListWebhooksResponse, error) + // GetWebhook gets a webhook by name. + GetWebhook(ctx context.Context, in *GetWebhookRequest, opts ...grpc.CallOption) (*Webhook, error) + // CreateWebhook creates a new webhook. + CreateWebhook(ctx context.Context, in *CreateWebhookRequest, opts ...grpc.CallOption) (*Webhook, error) // UpdateWebhook updates a webhook. UpdateWebhook(ctx context.Context, in *UpdateWebhookRequest, opts ...grpc.CallOption) (*Webhook, error) - // DeleteWebhook deletes a webhook by id. + // DeleteWebhook deletes a webhook. DeleteWebhook(ctx context.Context, in *DeleteWebhookRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) } @@ -51,10 +51,10 @@ func NewWebhookServiceClient(cc grpc.ClientConnInterface) WebhookServiceClient { return &webhookServiceClient{cc} } -func (c *webhookServiceClient) CreateWebhook(ctx context.Context, in *CreateWebhookRequest, opts ...grpc.CallOption) (*Webhook, error) { +func (c *webhookServiceClient) ListWebhooks(ctx context.Context, in *ListWebhooksRequest, opts ...grpc.CallOption) (*ListWebhooksResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(Webhook) - err := c.cc.Invoke(ctx, WebhookService_CreateWebhook_FullMethodName, in, out, cOpts...) + out := new(ListWebhooksResponse) + err := c.cc.Invoke(ctx, WebhookService_ListWebhooks_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -71,10 +71,10 @@ func (c *webhookServiceClient) GetWebhook(ctx context.Context, in *GetWebhookReq return out, nil } -func (c *webhookServiceClient) ListWebhooks(ctx context.Context, in *ListWebhooksRequest, opts ...grpc.CallOption) (*ListWebhooksResponse, error) { +func (c *webhookServiceClient) CreateWebhook(ctx context.Context, in *CreateWebhookRequest, opts ...grpc.CallOption) (*Webhook, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(ListWebhooksResponse) - err := c.cc.Invoke(ctx, WebhookService_ListWebhooks_FullMethodName, in, out, cOpts...) + out := new(Webhook) + err := c.cc.Invoke(ctx, WebhookService_CreateWebhook_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -105,15 +105,15 @@ func (c *webhookServiceClient) DeleteWebhook(ctx context.Context, in *DeleteWebh // All implementations must embed UnimplementedWebhookServiceServer // for forward compatibility. type WebhookServiceServer interface { - // CreateWebhook creates a new webhook. - CreateWebhook(context.Context, *CreateWebhookRequest) (*Webhook, error) - // GetWebhook returns a webhook by id. - GetWebhook(context.Context, *GetWebhookRequest) (*Webhook, error) // ListWebhooks returns a list of webhooks. ListWebhooks(context.Context, *ListWebhooksRequest) (*ListWebhooksResponse, error) + // GetWebhook gets a webhook by name. + GetWebhook(context.Context, *GetWebhookRequest) (*Webhook, error) + // CreateWebhook creates a new webhook. + CreateWebhook(context.Context, *CreateWebhookRequest) (*Webhook, error) // UpdateWebhook updates a webhook. UpdateWebhook(context.Context, *UpdateWebhookRequest) (*Webhook, error) - // DeleteWebhook deletes a webhook by id. + // DeleteWebhook deletes a webhook. DeleteWebhook(context.Context, *DeleteWebhookRequest) (*emptypb.Empty, error) mustEmbedUnimplementedWebhookServiceServer() } @@ -125,14 +125,14 @@ type WebhookServiceServer interface { // pointer dereference when methods are called. type UnimplementedWebhookServiceServer struct{} -func (UnimplementedWebhookServiceServer) CreateWebhook(context.Context, *CreateWebhookRequest) (*Webhook, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateWebhook not implemented") +func (UnimplementedWebhookServiceServer) ListWebhooks(context.Context, *ListWebhooksRequest) (*ListWebhooksResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListWebhooks not implemented") } func (UnimplementedWebhookServiceServer) GetWebhook(context.Context, *GetWebhookRequest) (*Webhook, error) { return nil, status.Errorf(codes.Unimplemented, "method GetWebhook not implemented") } -func (UnimplementedWebhookServiceServer) ListWebhooks(context.Context, *ListWebhooksRequest) (*ListWebhooksResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListWebhooks not implemented") +func (UnimplementedWebhookServiceServer) CreateWebhook(context.Context, *CreateWebhookRequest) (*Webhook, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateWebhook not implemented") } func (UnimplementedWebhookServiceServer) UpdateWebhook(context.Context, *UpdateWebhookRequest) (*Webhook, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateWebhook not implemented") @@ -161,20 +161,20 @@ func RegisterWebhookServiceServer(s grpc.ServiceRegistrar, srv WebhookServiceSer s.RegisterService(&WebhookService_ServiceDesc, srv) } -func _WebhookService_CreateWebhook_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CreateWebhookRequest) +func _WebhookService_ListWebhooks_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListWebhooksRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(WebhookServiceServer).CreateWebhook(ctx, in) + return srv.(WebhookServiceServer).ListWebhooks(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: WebhookService_CreateWebhook_FullMethodName, + FullMethod: WebhookService_ListWebhooks_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(WebhookServiceServer).CreateWebhook(ctx, req.(*CreateWebhookRequest)) + return srv.(WebhookServiceServer).ListWebhooks(ctx, req.(*ListWebhooksRequest)) } return interceptor(ctx, in, info, handler) } @@ -197,20 +197,20 @@ func _WebhookService_GetWebhook_Handler(srv interface{}, ctx context.Context, de return interceptor(ctx, in, info, handler) } -func _WebhookService_ListWebhooks_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListWebhooksRequest) +func _WebhookService_CreateWebhook_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateWebhookRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(WebhookServiceServer).ListWebhooks(ctx, in) + return srv.(WebhookServiceServer).CreateWebhook(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: WebhookService_ListWebhooks_FullMethodName, + FullMethod: WebhookService_CreateWebhook_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(WebhookServiceServer).ListWebhooks(ctx, req.(*ListWebhooksRequest)) + return srv.(WebhookServiceServer).CreateWebhook(ctx, req.(*CreateWebhookRequest)) } return interceptor(ctx, in, info, handler) } @@ -259,16 +259,16 @@ var WebhookService_ServiceDesc = grpc.ServiceDesc{ HandlerType: (*WebhookServiceServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "CreateWebhook", - Handler: _WebhookService_CreateWebhook_Handler, + MethodName: "ListWebhooks", + Handler: _WebhookService_ListWebhooks_Handler, }, { MethodName: "GetWebhook", Handler: _WebhookService_GetWebhook_Handler, }, { - MethodName: "ListWebhooks", - Handler: _WebhookService_ListWebhooks_Handler, + MethodName: "CreateWebhook", + Handler: _WebhookService_CreateWebhook_Handler, }, { MethodName: "UpdateWebhook", diff --git a/proto/gen/apidocs.swagger.yaml b/proto/gen/apidocs.swagger.yaml index b453eb077..a36a53cdc 100644 --- a/proto/gen/apidocs.swagger.yaml +++ b/proto/gen/apidocs.swagger.yaml @@ -609,11 +609,44 @@ paths: schema: $ref: '#/definitions/googlerpcStatus' parameters: - - name: creator - description: The name of the creator. + - name: pageSize + description: |- + Optional. The maximum number of webhooks to return. + The service may return fewer than this value. + If unspecified, at most 50 webhooks will be returned. + The maximum value is 1000; values above 1000 will be coerced to 1000. + in: query + required: false + type: integer + format: int32 + - name: pageToken + description: |- + Optional. A page token, received from a previous `ListWebhooks` call. + Provide this to retrieve the subsequent page. + in: query + required: false + type: string + - name: filter + description: |- + Optional. Filter to apply to the list results. + Example: "state=ACTIVE" or "creator=users/123" + Supported operators: =, !=, <, <=, >, >=, : + Supported fields: display_name, url, creator, state, create_time, update_time in: query required: false type: string + - name: orderBy + description: |- + Optional. The order to sort results by. + Example: "create_time desc" or "display_name asc" + in: query + required: false + type: string + - name: showDeleted + description: Optional. If true, show deleted webhooks in the response. + in: query + required: false + type: boolean tags: - WebhookService post: @@ -629,93 +662,34 @@ paths: schema: $ref: '#/definitions/googlerpcStatus' parameters: - - name: body - in: body - required: true - schema: - $ref: '#/definitions/v1CreateWebhookRequest' - tags: - - WebhookService - /api/v1/webhooks/{id}: - get: - summary: GetWebhook returns a webhook by id. - operationId: WebhookService_GetWebhook - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/v1Webhook' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: id - in: path - required: true - type: integer - format: int32 - tags: - - WebhookService - delete: - summary: DeleteWebhook deletes a webhook by id. - operationId: WebhookService_DeleteWebhook - responses: - "200": - description: A successful response. - schema: - type: object - properties: {} - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: id - in: path - required: true - type: integer - format: int32 - tags: - - WebhookService - /api/v1/webhooks/{webhook.id}: - patch: - summary: UpdateWebhook updates a webhook. - operationId: WebhookService_UpdateWebhook - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/v1Webhook' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: webhook.id - in: path - required: true - type: integer - format: int32 - name: webhook + description: Required. The webhook to create. in: body required: true schema: - type: object - properties: - creator: - type: string - description: The name of the creator. - createTime: - type: string - format: date-time - updateTime: - type: string - format: date-time - name: - type: string - url: - type: string + $ref: '#/definitions/v1Webhook' + required: + - webhook + - name: webhookId + description: |- + Optional. The webhook ID to use for this webhook. + If empty, a unique ID will be generated. + Must match the pattern [a-z0-9-]+ + in: query + required: false + type: string + - name: validateOnly + description: Optional. If set, validate the request but don't actually create the webhook. + in: query + required: false + type: boolean + - name: requestId + description: |- + Optional. An idempotency token that can be used to ensure that multiple + requests to create a webhook have the same result. + in: query + required: false + type: string tags: - WebhookService /api/v1/workspace/profile: @@ -1172,6 +1146,36 @@ paths: tags: - ResourceService /api/v1/{name_5}: + get: + summary: GetWebhook gets a webhook by name. + operationId: WebhookService_GetWebhook + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1Webhook' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: name_5 + description: |- + Required. The resource name of the webhook. + Format: webhooks/{webhook} + in: path + required: true + type: string + pattern: webhooks/[^/]+ + - name: readMask + description: |- + Optional. The fields to return in the response. + If not specified, all fields are returned. + in: query + required: false + type: string + tags: + - WebhookService delete: summary: DeleteMemo deletes a memo. operationId: MemoService_DeleteMemo @@ -1194,6 +1198,36 @@ paths: pattern: memos/[^/]+ tags: - MemoService + /api/v1/{name_6}: + delete: + summary: DeleteWebhook deletes a webhook. + operationId: WebhookService_DeleteWebhook + responses: + "200": + description: A successful response. + schema: + type: object + properties: {} + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: name_6 + description: |- + Required. The resource name of the webhook to delete. + Format: webhooks/{webhook} + in: path + required: true + type: string + pattern: webhooks/[^/]+ + - name: force + description: Optional. If set to true, the webhook will be deleted even if it has associated data. + in: query + required: false + type: boolean + tags: + - WebhookService /api/v1/{name}: get: summary: GetActivity returns the activity with the given id. @@ -2022,6 +2056,81 @@ paths: type: boolean tags: - UserService + /api/v1/{webhook.name}: + patch: + summary: UpdateWebhook updates a webhook. + operationId: WebhookService_UpdateWebhook + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1Webhook' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: webhook.name + description: |- + The resource name of the webhook. + Format: webhooks/{webhook} + in: path + required: true + type: string + pattern: webhooks/[^/]+ + - name: webhook + description: Required. The webhook to update. + in: body + required: true + schema: + type: object + properties: + uid: + type: string + description: Output only. The system generated unique identifier. + readOnly: true + displayName: + type: string + description: Required. The display name of the webhook. + url: + type: string + description: Required. The target URL for the webhook. + creator: + type: string + title: |- + Output only. The resource name of the creator. + Format: users/{user} + readOnly: true + state: + $ref: '#/definitions/v1State' + description: The state of the webhook. + createTime: + type: string + format: date-time + description: Output only. The creation timestamp. + readOnly: true + updateTime: + type: string + format: date-time + description: Output only. The last update timestamp. + readOnly: true + etag: + type: string + description: Output only. The etag for this resource. + readOnly: true + title: Required. The webhook to update. + required: + - displayName + - url + - state + - webhook + - name: allowMissing + description: Optional. If set to true, allows updating sensitive fields. + in: query + required: false + type: boolean + tags: + - WebhookService /file/{name}/{filename}: get: summary: GetResourceBinary returns a resource binary by name. @@ -2726,13 +2835,6 @@ definitions: properties: content: type: string - v1CreateWebhookRequest: - type: object - properties: - name: - type: string - url: - type: string v1Direction: type: string enum: @@ -3011,6 +3113,16 @@ definitions: items: type: object $ref: '#/definitions/v1Webhook' + description: The list of webhooks. + nextPageToken: + type: string + description: |- + A token that can be sent as `page_token` to retrieve the next page. + If this field is omitted, there are no subsequent pages. + totalSize: + type: integer + format: int32 + description: The total count of webhooks (may be approximate). v1MathBlockNode: type: object properties: @@ -3526,22 +3638,48 @@ definitions: v1Webhook: type: object properties: - id: - type: integer - format: int32 + name: + type: string + title: |- + The resource name of the webhook. + Format: webhooks/{webhook} + uid: + type: string + description: Output only. The system generated unique identifier. + readOnly: true + displayName: + type: string + description: Required. The display name of the webhook. + url: + type: string + description: Required. The target URL for the webhook. creator: type: string - description: The name of the creator. + title: |- + Output only. The resource name of the creator. + Format: users/{user} + readOnly: true + state: + $ref: '#/definitions/v1State' + description: The state of the webhook. createTime: type: string format: date-time + description: Output only. The creation timestamp. + readOnly: true updateTime: type: string format: date-time - name: - type: string - url: + description: Output only. The last update timestamp. + readOnly: true + etag: type: string + description: Output only. The etag for this resource. + readOnly: true + required: + - displayName + - url + - state v1WorkspaceProfile: type: object properties: diff --git a/server/router/api/v1/resource_name.go b/server/router/api/v1/resource_name.go index 3a571a20a..b15e3b923 100644 --- a/server/router/api/v1/resource_name.go +++ b/server/router/api/v1/resource_name.go @@ -17,6 +17,7 @@ const ( InboxNamePrefix = "inboxes/" IdentityProviderNamePrefix = "identityProviders/" ActivityNamePrefix = "activities/" + WebhookNamePrefix = "webhooks/" ) // GetNameParentTokens returns the tokens from a resource name. @@ -117,3 +118,16 @@ func ExtractActivityIDFromName(name string) (int32, error) { } return id, nil } + +// ExtractWebhookIDFromName returns the webhook ID from a resource name. +func ExtractWebhookIDFromName(name string) (int32, error) { + tokens, err := GetNameParentTokens(name, WebhookNamePrefix) + if err != nil { + return 0, err + } + id, err := util.ConvertStringToInt32(tokens[0]) + if err != nil { + return 0, errors.Errorf("invalid webhook ID %q", tokens[0]) + } + return id, nil +} diff --git a/server/router/api/v1/webhook_service.go b/server/router/api/v1/webhook_service.go index e367715ba..5cd312572 100644 --- a/server/router/api/v1/webhook_service.go +++ b/server/router/api/v1/webhook_service.go @@ -2,6 +2,7 @@ package v1 import ( "context" + "crypto/md5" "fmt" "strings" "time" @@ -21,10 +22,21 @@ func (s *APIV1Service) CreateWebhook(ctx context.Context, request *v1pb.CreateWe return nil, status.Errorf(codes.Internal, "failed to get user: %v", err) } + // TODO: Handle webhook_id, validate_only, and request_id fields + if request.ValidateOnly { + // Perform validation checks without actually creating the webhook + return &v1pb.Webhook{ + DisplayName: request.Webhook.DisplayName, + Url: request.Webhook.Url, + Creator: fmt.Sprintf("users/%d", currentUser.ID), + State: request.Webhook.State, + }, nil + } + webhook, err := s.Store.CreateWebhook(ctx, &store.Webhook{ CreatorID: currentUser.ID, - Name: request.Name, - URL: strings.TrimSpace(request.Url), + Name: request.Webhook.DisplayName, + URL: strings.TrimSpace(request.Webhook.Url), }) if err != nil { return nil, status.Errorf(codes.Internal, "failed to create webhook, error: %+v", err) @@ -32,21 +44,24 @@ func (s *APIV1Service) CreateWebhook(ctx context.Context, request *v1pb.CreateWe return convertWebhookFromStore(webhook), nil } -func (s *APIV1Service) ListWebhooks(ctx context.Context, request *v1pb.ListWebhooksRequest) (*v1pb.ListWebhooksResponse, error) { - creatorID, err := ExtractUserIDFromName(request.Creator) +func (s *APIV1Service) ListWebhooks(ctx context.Context, _ *v1pb.ListWebhooksRequest) (*v1pb.ListWebhooksResponse, error) { + currentUser, err := s.GetCurrentUser(ctx) if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "invalid creator name: %v", err) + return nil, status.Errorf(codes.Internal, "failed to get user: %v", err) } + // TODO: Implement proper filtering, ordering, and pagination + // For now, list webhooks for the current user webhooks, err := s.Store.ListWebhooks(ctx, &store.FindWebhook{ - CreatorID: &creatorID, + CreatorID: ¤tUser.ID, }) if err != nil { return nil, status.Errorf(codes.Internal, "failed to list webhooks, error: %+v", err) } response := &v1pb.ListWebhooksResponse{ - Webhooks: []*v1pb.Webhook{}, + Webhooks: []*v1pb.Webhook{}, + TotalSize: int32(len(webhooks)), } for _, webhook := range webhooks { response.Webhooks = append(response.Webhooks, convertWebhookFromStore(webhook)) @@ -55,13 +70,18 @@ func (s *APIV1Service) ListWebhooks(ctx context.Context, request *v1pb.ListWebho } func (s *APIV1Service) GetWebhook(ctx context.Context, request *v1pb.GetWebhookRequest) (*v1pb.Webhook, error) { + webhookID, err := ExtractWebhookIDFromName(request.Name) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid webhook name: %v", err) + } + currentUser, err := s.GetCurrentUser(ctx) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get user: %v", err) } webhook, err := s.Store.GetWebhook(ctx, &store.FindWebhook{ - ID: &request.Id, + ID: &webhookID, CreatorID: ¤tUser.ID, }) if err != nil { @@ -70,7 +90,12 @@ func (s *APIV1Service) GetWebhook(ctx context.Context, request *v1pb.GetWebhookR if webhook == nil { return nil, status.Errorf(codes.NotFound, "webhook not found") } - return convertWebhookFromStore(webhook), nil + + webhookPb := convertWebhookFromStore(webhook) + + // TODO: Implement read_mask field filtering + + return webhookPb, nil } func (s *APIV1Service) UpdateWebhook(ctx context.Context, request *v1pb.UpdateWebhookRequest) (*v1pb.Webhook, error) { @@ -78,13 +103,43 @@ func (s *APIV1Service) UpdateWebhook(ctx context.Context, request *v1pb.UpdateWe return nil, status.Errorf(codes.InvalidArgument, "update_mask is required") } - update := &store.UpdateWebhook{} + webhookID, err := ExtractWebhookIDFromName(request.Webhook.Name) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid webhook name: %v", err) + } + + currentUser, err := s.GetCurrentUser(ctx) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get user: %v", err) + } + + // Check if webhook exists and user has permission + existingWebhook, err := s.Store.GetWebhook(ctx, &store.FindWebhook{ + ID: &webhookID, + CreatorID: ¤tUser.ID, + }) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get webhook: %v", err) + } + if existingWebhook == nil { + if request.AllowMissing { + // Could create webhook if missing, but for now return not found + return nil, status.Errorf(codes.NotFound, "webhook not found") + } + return nil, status.Errorf(codes.NotFound, "webhook not found") + } + + update := &store.UpdateWebhook{ + ID: webhookID, + } for _, field := range request.UpdateMask.Paths { switch field { - case "name": - update.Name = &request.Webhook.Name + case "display_name": + update.Name = &request.Webhook.DisplayName case "url": update.URL = &request.Webhook.Url + default: + return nil, status.Errorf(codes.InvalidArgument, "invalid update path: %s", field) } } @@ -96,8 +151,32 @@ func (s *APIV1Service) UpdateWebhook(ctx context.Context, request *v1pb.UpdateWe } func (s *APIV1Service) DeleteWebhook(ctx context.Context, request *v1pb.DeleteWebhookRequest) (*emptypb.Empty, error) { - err := s.Store.DeleteWebhook(ctx, &store.DeleteWebhook{ - ID: request.Id, + webhookID, err := ExtractWebhookIDFromName(request.Name) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid webhook name: %v", err) + } + + currentUser, err := s.GetCurrentUser(ctx) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get user: %v", err) + } + + // Check if webhook exists and user has permission + webhook, err := s.Store.GetWebhook(ctx, &store.FindWebhook{ + ID: &webhookID, + CreatorID: ¤tUser.ID, + }) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get webhook: %v", err) + } + if webhook == nil { + return nil, status.Errorf(codes.NotFound, "webhook not found") + } + + // TODO: Handle force field properly + + err = s.Store.DeleteWebhook(ctx, &store.DeleteWebhook{ + ID: webhookID, }) if err != nil { return nil, status.Errorf(codes.Internal, "failed to delete webhook, error: %+v", err) @@ -106,12 +185,19 @@ func (s *APIV1Service) DeleteWebhook(ctx context.Context, request *v1pb.DeleteWe } func convertWebhookFromStore(webhook *store.Webhook) *v1pb.Webhook { + // Generate etag using MD5 hash of webhook data + etag := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%d-%s-%s", + webhook.ID, webhook.UpdatedTs, webhook.Name, webhook.URL)))) + return &v1pb.Webhook{ - Id: webhook.ID, - CreateTime: timestamppb.New(time.Unix(webhook.CreatedTs, 0)), - UpdateTime: timestamppb.New(time.Unix(webhook.UpdatedTs, 0)), - Creator: fmt.Sprintf("%s%d", UserNamePrefix, webhook.CreatorID), - Name: webhook.Name, - Url: webhook.URL, + Name: fmt.Sprintf("webhooks/%d", webhook.ID), + Uid: fmt.Sprintf("%d", webhook.ID), + DisplayName: webhook.Name, + Url: webhook.URL, + Creator: fmt.Sprintf("users/%d", webhook.CreatorID), + State: v1pb.State_NORMAL, // Default to NORMAL state for webhooks + CreateTime: timestamppb.New(time.Unix(webhook.CreatedTs, 0)), + UpdateTime: timestamppb.New(time.Unix(webhook.UpdatedTs, 0)), + Etag: etag, } } diff --git a/web/src/components/CreateWebhookDialog.tsx b/web/src/components/CreateWebhookDialog.tsx index 128963a99..dfb6f4e85 100644 --- a/web/src/components/CreateWebhookDialog.tsx +++ b/web/src/components/CreateWebhookDialog.tsx @@ -8,34 +8,34 @@ import { useTranslate } from "@/utils/i18n"; import { generateDialog } from "./Dialog"; interface Props extends DialogProps { - webhookId?: number; + webhookName?: string; onConfirm: () => void; } interface State { - name: string; + displayName: string; url: string; } const CreateWebhookDialog: React.FC = (props: Props) => { - const { webhookId, destroy, onConfirm } = props; + const { webhookName, destroy, onConfirm } = props; const t = useTranslate(); const [state, setState] = useState({ - name: "", + displayName: "", url: "", }); const requestState = useLoading(false); - const isCreating = webhookId === undefined; + const isCreating = webhookName === undefined; useEffect(() => { - if (webhookId) { + if (webhookName) { webhookServiceClient .getWebhook({ - id: webhookId, + name: webhookName, }) .then((webhook) => { setState({ - name: webhook.name, + displayName: webhook.displayName, url: webhook.url, }); }); @@ -51,7 +51,7 @@ const CreateWebhookDialog: React.FC = (props: Props) => { const handleTitleInputChange = (e: React.ChangeEvent) => { setPartialState({ - name: e.target.value, + displayName: e.target.value, }); }; @@ -62,7 +62,7 @@ const CreateWebhookDialog: React.FC = (props: Props) => { }; const handleSaveBtnClick = async () => { - if (!state.name || !state.url) { + if (!state.displayName || !state.url) { toast.error(t("message.fill-all-required-fields")); return; } @@ -70,17 +70,19 @@ const CreateWebhookDialog: React.FC = (props: Props) => { try { if (isCreating) { await webhookServiceClient.createWebhook({ - name: state.name, - url: state.url, + webhook: { + displayName: state.displayName, + url: state.url, + }, }); } else { await webhookServiceClient.updateWebhook({ webhook: { - id: webhookId, - name: state.name, + name: webhookName, + displayName: state.displayName, url: state.url, }, - updateMask: ["name", "url"], + updateMask: ["display_name", "url"], }); } @@ -112,7 +114,7 @@ const CreateWebhookDialog: React.FC = (props: Props) => { className="w-full" type="text" placeholder={t("setting.webhook-section.create-dialog.an-easy-to-remember-name")} - value={state.name} + value={state.displayName} onChange={handleTitleInputChange} /> diff --git a/web/src/components/Settings/WebhookSection.tsx b/web/src/components/Settings/WebhookSection.tsx index 6a7914967..5bd118087 100644 --- a/web/src/components/Settings/WebhookSection.tsx +++ b/web/src/components/Settings/WebhookSection.tsx @@ -3,39 +3,35 @@ import { ExternalLinkIcon, TrashIcon } from "lucide-react"; import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { webhookServiceClient } from "@/grpcweb"; -import useCurrentUser from "@/hooks/useCurrentUser"; import { Webhook } from "@/types/proto/api/v1/webhook_service"; import { useTranslate } from "@/utils/i18n"; import showCreateWebhookDialog from "../CreateWebhookDialog"; -const listWebhooks = async (user: string) => { - const { webhooks } = await webhookServiceClient.listWebhooks({ - creator: user, - }); +const listWebhooks = async () => { + const { webhooks } = await webhookServiceClient.listWebhooks({}); return webhooks; }; const WebhookSection = () => { const t = useTranslate(); - const currentUser = useCurrentUser(); const [webhooks, setWebhooks] = useState([]); useEffect(() => { - listWebhooks(currentUser.name).then((webhooks) => { + listWebhooks().then((webhooks) => { setWebhooks(webhooks); }); }, []); const handleCreateAccessTokenDialogConfirm = async () => { - const webhooks = await listWebhooks(currentUser.name); + const webhooks = await listWebhooks(); setWebhooks(webhooks); }; const handleDeleteWebhook = async (webhook: Webhook) => { - const confirmed = window.confirm(`Are you sure to delete webhook \`${webhook.name}\`? You cannot undo this action.`); + const confirmed = window.confirm(`Are you sure to delete webhook \`${webhook.displayName}\`? You cannot undo this action.`); if (confirmed) { - await webhookServiceClient.deleteWebhook({ id: webhook.id }); - setWebhooks(webhooks.filter((item) => item.id !== webhook.id)); + await webhookServiceClient.deleteWebhook({ name: webhook.name }); + setWebhooks(webhooks.filter((item) => item.name !== webhook.name)); } }; @@ -77,8 +73,8 @@ const WebhookSection = () => { {webhooks.map((webhook) => ( - - {webhook.name} + + {webhook.displayName} {webhook.url} diff --git a/web/src/types/proto/api/v1/webhook_service.ts b/web/src/types/proto/api/v1/webhook_service.ts index ee9174932..090823c1a 100644 --- a/web/src/types/proto/api/v1/webhook_service.ts +++ b/web/src/types/proto/api/v1/webhook_service.ts @@ -9,82 +9,199 @@ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; import { Empty } from "../../google/protobuf/empty"; import { FieldMask } from "../../google/protobuf/field_mask"; import { Timestamp } from "../../google/protobuf/timestamp"; +import { State, stateFromJSON, stateToNumber } from "./common"; import { Memo } from "./memo_service"; export const protobufPackage = "memos.api.v1"; export interface Webhook { - id: number; - /** The name of the creator. */ - creator: string; - createTime?: Date | undefined; - updateTime?: Date | undefined; + /** + * The resource name of the webhook. + * Format: webhooks/{webhook} + */ name: string; + /** Output only. The system generated unique identifier. */ + uid: string; + /** Required. The display name of the webhook. */ + displayName: string; + /** Required. The target URL for the webhook. */ url: string; + /** + * Output only. The resource name of the creator. + * Format: users/{user} + */ + creator: string; + /** The state of the webhook. */ + state: State; + /** Output only. The creation timestamp. */ + createTime?: + | Date + | undefined; + /** Output only. The last update timestamp. */ + updateTime?: + | Date + | undefined; + /** Output only. The etag for this resource. */ + etag: string; } -export interface CreateWebhookRequest { - name: string; - url: string; +export interface ListWebhooksRequest { + /** + * Optional. The maximum number of webhooks to return. + * The service may return fewer than this value. + * If unspecified, at most 50 webhooks will be returned. + * The maximum value is 1000; values above 1000 will be coerced to 1000. + */ + pageSize: number; + /** + * Optional. A page token, received from a previous `ListWebhooks` call. + * Provide this to retrieve the subsequent page. + */ + pageToken: string; + /** + * Optional. Filter to apply to the list results. + * Example: "state=ACTIVE" or "creator=users/123" + * Supported operators: =, !=, <, <=, >, >=, : + * Supported fields: display_name, url, creator, state, create_time, update_time + */ + filter: string; + /** + * Optional. The order to sort results by. + * Example: "create_time desc" or "display_name asc" + */ + orderBy: string; + /** Optional. If true, show deleted webhooks in the response. */ + showDeleted: boolean; } -export interface GetWebhookRequest { - id: number; +export interface ListWebhooksResponse { + /** The list of webhooks. */ + webhooks: Webhook[]; + /** + * A token that can be sent as `page_token` to retrieve the next page. + * If this field is omitted, there are no subsequent pages. + */ + nextPageToken: string; + /** The total count of webhooks (may be approximate). */ + totalSize: number; } -export interface ListWebhooksRequest { - /** The name of the creator. */ - creator: string; +export interface GetWebhookRequest { + /** + * Required. The resource name of the webhook. + * Format: webhooks/{webhook} + */ + name: string; + /** + * Optional. The fields to return in the response. + * If not specified, all fields are returned. + */ + readMask?: string[] | undefined; } -export interface ListWebhooksResponse { - webhooks: Webhook[]; +export interface CreateWebhookRequest { + /** Required. The webhook to create. */ + webhook?: + | Webhook + | undefined; + /** + * Optional. The webhook ID to use for this webhook. + * If empty, a unique ID will be generated. + * Must match the pattern [a-z0-9-]+ + */ + webhookId: string; + /** Optional. If set, validate the request but don't actually create the webhook. */ + validateOnly: boolean; + /** + * Optional. An idempotency token that can be used to ensure that multiple + * requests to create a webhook have the same result. + */ + requestId: string; } export interface UpdateWebhookRequest { - webhook?: Webhook | undefined; - updateMask?: string[] | undefined; + /** Required. The webhook to update. */ + webhook?: + | Webhook + | undefined; + /** Required. The list of fields to update. */ + updateMask?: + | string[] + | undefined; + /** Optional. If set to true, allows updating sensitive fields. */ + allowMissing: boolean; } export interface DeleteWebhookRequest { - id: number; + /** + * Required. The resource name of the webhook to delete. + * Format: webhooks/{webhook} + */ + name: string; + /** Optional. If set to true, the webhook will be deleted even if it has associated data. */ + force: boolean; } export interface WebhookRequestPayload { + /** The target URL for the webhook request. */ url: string; + /** The type of activity that triggered this webhook. */ activityType: string; /** - * The name of the creator. + * The resource name of the creator. * Format: users/{user} */ creator: string; - createTime?: Date | undefined; + /** The creation timestamp of the activity. */ + createTime?: + | Date + | undefined; + /** The memo that triggered this webhook (if applicable). */ memo?: Memo | undefined; } function createBaseWebhook(): Webhook { - return { id: 0, creator: "", createTime: undefined, updateTime: undefined, name: "", url: "" }; + return { + name: "", + uid: "", + displayName: "", + url: "", + creator: "", + state: State.STATE_UNSPECIFIED, + createTime: undefined, + updateTime: undefined, + etag: "", + }; } export const Webhook: MessageFns = { encode(message: Webhook, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - if (message.id !== 0) { - writer.uint32(8).int32(message.id); + if (message.name !== "") { + writer.uint32(10).string(message.name); + } + if (message.uid !== "") { + writer.uint32(18).string(message.uid); + } + if (message.displayName !== "") { + writer.uint32(26).string(message.displayName); + } + if (message.url !== "") { + writer.uint32(34).string(message.url); } if (message.creator !== "") { - writer.uint32(18).string(message.creator); + writer.uint32(42).string(message.creator); + } + if (message.state !== State.STATE_UNSPECIFIED) { + writer.uint32(48).int32(stateToNumber(message.state)); } if (message.createTime !== undefined) { - Timestamp.encode(toTimestamp(message.createTime), writer.uint32(26).fork()).join(); + Timestamp.encode(toTimestamp(message.createTime), writer.uint32(58).fork()).join(); } if (message.updateTime !== undefined) { - Timestamp.encode(toTimestamp(message.updateTime), writer.uint32(34).fork()).join(); - } - if (message.name !== "") { - writer.uint32(42).string(message.name); + Timestamp.encode(toTimestamp(message.updateTime), writer.uint32(66).fork()).join(); } - if (message.url !== "") { - writer.uint32(50).string(message.url); + if (message.etag !== "") { + writer.uint32(74).string(message.etag); } return writer; }, @@ -97,11 +214,11 @@ export const Webhook: MessageFns = { const tag = reader.uint32(); switch (tag >>> 3) { case 1: { - if (tag !== 8) { + if (tag !== 10) { break; } - message.id = reader.int32(); + message.name = reader.string(); continue; } case 2: { @@ -109,7 +226,7 @@ export const Webhook: MessageFns = { break; } - message.creator = reader.string(); + message.uid = reader.string(); continue; } case 3: { @@ -117,7 +234,7 @@ export const Webhook: MessageFns = { break; } - message.createTime = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + message.displayName = reader.string(); continue; } case 4: { @@ -125,7 +242,7 @@ export const Webhook: MessageFns = { break; } - message.updateTime = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + message.url = reader.string(); continue; } case 5: { @@ -133,15 +250,39 @@ export const Webhook: MessageFns = { break; } - message.name = reader.string(); + message.creator = reader.string(); continue; } case 6: { - if (tag !== 50) { + if (tag !== 48) { break; } - message.url = reader.string(); + message.state = stateFromJSON(reader.int32()); + continue; + } + case 7: { + if (tag !== 58) { + break; + } + + message.createTime = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + continue; + } + case 8: { + if (tag !== 66) { + break; + } + + message.updateTime = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + continue; + } + case 9: { + if (tag !== 74) { + break; + } + + message.etag = reader.string(); continue; } } @@ -158,44 +299,56 @@ export const Webhook: MessageFns = { }, fromPartial(object: DeepPartial): Webhook { const message = createBaseWebhook(); - message.id = object.id ?? 0; + message.name = object.name ?? ""; + message.uid = object.uid ?? ""; + message.displayName = object.displayName ?? ""; + message.url = object.url ?? ""; message.creator = object.creator ?? ""; + message.state = object.state ?? State.STATE_UNSPECIFIED; message.createTime = object.createTime ?? undefined; message.updateTime = object.updateTime ?? undefined; - message.name = object.name ?? ""; - message.url = object.url ?? ""; + message.etag = object.etag ?? ""; return message; }, }; -function createBaseCreateWebhookRequest(): CreateWebhookRequest { - return { name: "", url: "" }; +function createBaseListWebhooksRequest(): ListWebhooksRequest { + return { pageSize: 0, pageToken: "", filter: "", orderBy: "", showDeleted: false }; } -export const CreateWebhookRequest: MessageFns = { - encode(message: CreateWebhookRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - if (message.name !== "") { - writer.uint32(10).string(message.name); +export const ListWebhooksRequest: MessageFns = { + encode(message: ListWebhooksRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + if (message.pageSize !== 0) { + writer.uint32(8).int32(message.pageSize); } - if (message.url !== "") { - writer.uint32(18).string(message.url); + if (message.pageToken !== "") { + writer.uint32(18).string(message.pageToken); + } + if (message.filter !== "") { + writer.uint32(26).string(message.filter); + } + if (message.orderBy !== "") { + writer.uint32(34).string(message.orderBy); + } + if (message.showDeleted !== false) { + writer.uint32(40).bool(message.showDeleted); } return writer; }, - decode(input: BinaryReader | Uint8Array, length?: number): CreateWebhookRequest { + decode(input: BinaryReader | Uint8Array, length?: number): ListWebhooksRequest { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseCreateWebhookRequest(); + const message = createBaseListWebhooksRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: { - if (tag !== 10) { + if (tag !== 8) { break; } - message.name = reader.string(); + message.pageSize = reader.int32(); continue; } case 2: { @@ -203,7 +356,31 @@ export const CreateWebhookRequest: MessageFns = { break; } - message.url = reader.string(); + message.pageToken = reader.string(); + continue; + } + case 3: { + if (tag !== 26) { + break; + } + + message.filter = reader.string(); + continue; + } + case 4: { + if (tag !== 34) { + break; + } + + message.orderBy = reader.string(); + continue; + } + case 5: { + if (tag !== 40) { + break; + } + + message.showDeleted = reader.bool(); continue; } } @@ -215,42 +392,67 @@ export const CreateWebhookRequest: MessageFns = { return message; }, - create(base?: DeepPartial): CreateWebhookRequest { - return CreateWebhookRequest.fromPartial(base ?? {}); + create(base?: DeepPartial): ListWebhooksRequest { + return ListWebhooksRequest.fromPartial(base ?? {}); }, - fromPartial(object: DeepPartial): CreateWebhookRequest { - const message = createBaseCreateWebhookRequest(); - message.name = object.name ?? ""; - message.url = object.url ?? ""; + fromPartial(object: DeepPartial): ListWebhooksRequest { + const message = createBaseListWebhooksRequest(); + message.pageSize = object.pageSize ?? 0; + message.pageToken = object.pageToken ?? ""; + message.filter = object.filter ?? ""; + message.orderBy = object.orderBy ?? ""; + message.showDeleted = object.showDeleted ?? false; return message; }, }; -function createBaseGetWebhookRequest(): GetWebhookRequest { - return { id: 0 }; +function createBaseListWebhooksResponse(): ListWebhooksResponse { + return { webhooks: [], nextPageToken: "", totalSize: 0 }; } -export const GetWebhookRequest: MessageFns = { - encode(message: GetWebhookRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - if (message.id !== 0) { - writer.uint32(8).int32(message.id); +export const ListWebhooksResponse: MessageFns = { + encode(message: ListWebhooksResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + for (const v of message.webhooks) { + Webhook.encode(v!, writer.uint32(10).fork()).join(); + } + if (message.nextPageToken !== "") { + writer.uint32(18).string(message.nextPageToken); + } + if (message.totalSize !== 0) { + writer.uint32(24).int32(message.totalSize); } return writer; }, - decode(input: BinaryReader | Uint8Array, length?: number): GetWebhookRequest { + decode(input: BinaryReader | Uint8Array, length?: number): ListWebhooksResponse { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseGetWebhookRequest(); + const message = createBaseListWebhooksResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: { - if (tag !== 8) { + if (tag !== 10) { + break; + } + + message.webhooks.push(Webhook.decode(reader, reader.uint32())); + continue; + } + case 2: { + if (tag !== 18) { + break; + } + + message.nextPageToken = reader.string(); + continue; + } + case 3: { + if (tag !== 24) { break; } - message.id = reader.int32(); + message.totalSize = reader.int32(); continue; } } @@ -262,41 +464,54 @@ export const GetWebhookRequest: MessageFns = { return message; }, - create(base?: DeepPartial): GetWebhookRequest { - return GetWebhookRequest.fromPartial(base ?? {}); + create(base?: DeepPartial): ListWebhooksResponse { + return ListWebhooksResponse.fromPartial(base ?? {}); }, - fromPartial(object: DeepPartial): GetWebhookRequest { - const message = createBaseGetWebhookRequest(); - message.id = object.id ?? 0; + fromPartial(object: DeepPartial): ListWebhooksResponse { + const message = createBaseListWebhooksResponse(); + message.webhooks = object.webhooks?.map((e) => Webhook.fromPartial(e)) || []; + message.nextPageToken = object.nextPageToken ?? ""; + message.totalSize = object.totalSize ?? 0; return message; }, }; -function createBaseListWebhooksRequest(): ListWebhooksRequest { - return { creator: "" }; +function createBaseGetWebhookRequest(): GetWebhookRequest { + return { name: "", readMask: undefined }; } -export const ListWebhooksRequest: MessageFns = { - encode(message: ListWebhooksRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - if (message.creator !== "") { - writer.uint32(18).string(message.creator); +export const GetWebhookRequest: MessageFns = { + encode(message: GetWebhookRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + if (message.name !== "") { + writer.uint32(10).string(message.name); + } + if (message.readMask !== undefined) { + FieldMask.encode(FieldMask.wrap(message.readMask), writer.uint32(18).fork()).join(); } return writer; }, - decode(input: BinaryReader | Uint8Array, length?: number): ListWebhooksRequest { + decode(input: BinaryReader | Uint8Array, length?: number): GetWebhookRequest { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseListWebhooksRequest(); + const message = createBaseGetWebhookRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { + case 1: { + if (tag !== 10) { + break; + } + + message.name = reader.string(); + continue; + } case 2: { if (tag !== 18) { break; } - message.creator = reader.string(); + message.readMask = FieldMask.unwrap(FieldMask.decode(reader, reader.uint32())); continue; } } @@ -308,32 +523,42 @@ export const ListWebhooksRequest: MessageFns = { return message; }, - create(base?: DeepPartial): ListWebhooksRequest { - return ListWebhooksRequest.fromPartial(base ?? {}); + create(base?: DeepPartial): GetWebhookRequest { + return GetWebhookRequest.fromPartial(base ?? {}); }, - fromPartial(object: DeepPartial): ListWebhooksRequest { - const message = createBaseListWebhooksRequest(); - message.creator = object.creator ?? ""; + fromPartial(object: DeepPartial): GetWebhookRequest { + const message = createBaseGetWebhookRequest(); + message.name = object.name ?? ""; + message.readMask = object.readMask ?? undefined; return message; }, }; -function createBaseListWebhooksResponse(): ListWebhooksResponse { - return { webhooks: [] }; +function createBaseCreateWebhookRequest(): CreateWebhookRequest { + return { webhook: undefined, webhookId: "", validateOnly: false, requestId: "" }; } -export const ListWebhooksResponse: MessageFns = { - encode(message: ListWebhooksResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - for (const v of message.webhooks) { - Webhook.encode(v!, writer.uint32(10).fork()).join(); +export const CreateWebhookRequest: MessageFns = { + encode(message: CreateWebhookRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + if (message.webhook !== undefined) { + Webhook.encode(message.webhook, writer.uint32(10).fork()).join(); + } + if (message.webhookId !== "") { + writer.uint32(18).string(message.webhookId); + } + if (message.validateOnly !== false) { + writer.uint32(24).bool(message.validateOnly); + } + if (message.requestId !== "") { + writer.uint32(34).string(message.requestId); } return writer; }, - decode(input: BinaryReader | Uint8Array, length?: number): ListWebhooksResponse { + decode(input: BinaryReader | Uint8Array, length?: number): CreateWebhookRequest { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseListWebhooksResponse(); + const message = createBaseCreateWebhookRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -342,7 +567,31 @@ export const ListWebhooksResponse: MessageFns = { break; } - message.webhooks.push(Webhook.decode(reader, reader.uint32())); + message.webhook = Webhook.decode(reader, reader.uint32()); + continue; + } + case 2: { + if (tag !== 18) { + break; + } + + message.webhookId = reader.string(); + continue; + } + case 3: { + if (tag !== 24) { + break; + } + + message.validateOnly = reader.bool(); + continue; + } + case 4: { + if (tag !== 34) { + break; + } + + message.requestId = reader.string(); continue; } } @@ -354,18 +603,23 @@ export const ListWebhooksResponse: MessageFns = { return message; }, - create(base?: DeepPartial): ListWebhooksResponse { - return ListWebhooksResponse.fromPartial(base ?? {}); + create(base?: DeepPartial): CreateWebhookRequest { + return CreateWebhookRequest.fromPartial(base ?? {}); }, - fromPartial(object: DeepPartial): ListWebhooksResponse { - const message = createBaseListWebhooksResponse(); - message.webhooks = object.webhooks?.map((e) => Webhook.fromPartial(e)) || []; + fromPartial(object: DeepPartial): CreateWebhookRequest { + const message = createBaseCreateWebhookRequest(); + message.webhook = (object.webhook !== undefined && object.webhook !== null) + ? Webhook.fromPartial(object.webhook) + : undefined; + message.webhookId = object.webhookId ?? ""; + message.validateOnly = object.validateOnly ?? false; + message.requestId = object.requestId ?? ""; return message; }, }; function createBaseUpdateWebhookRequest(): UpdateWebhookRequest { - return { webhook: undefined, updateMask: undefined }; + return { webhook: undefined, updateMask: undefined, allowMissing: false }; } export const UpdateWebhookRequest: MessageFns = { @@ -376,6 +630,9 @@ export const UpdateWebhookRequest: MessageFns = { if (message.updateMask !== undefined) { FieldMask.encode(FieldMask.wrap(message.updateMask), writer.uint32(18).fork()).join(); } + if (message.allowMissing !== false) { + writer.uint32(24).bool(message.allowMissing); + } return writer; }, @@ -402,6 +659,14 @@ export const UpdateWebhookRequest: MessageFns = { message.updateMask = FieldMask.unwrap(FieldMask.decode(reader, reader.uint32())); continue; } + case 3: { + if (tag !== 24) { + break; + } + + message.allowMissing = reader.bool(); + continue; + } } if ((tag & 7) === 4 || tag === 0) { break; @@ -420,18 +685,22 @@ export const UpdateWebhookRequest: MessageFns = { ? Webhook.fromPartial(object.webhook) : undefined; message.updateMask = object.updateMask ?? undefined; + message.allowMissing = object.allowMissing ?? false; return message; }, }; function createBaseDeleteWebhookRequest(): DeleteWebhookRequest { - return { id: 0 }; + return { name: "", force: false }; } export const DeleteWebhookRequest: MessageFns = { encode(message: DeleteWebhookRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - if (message.id !== 0) { - writer.uint32(8).int32(message.id); + if (message.name !== "") { + writer.uint32(10).string(message.name); + } + if (message.force !== false) { + writer.uint32(16).bool(message.force); } return writer; }, @@ -444,11 +713,19 @@ export const DeleteWebhookRequest: MessageFns = { const tag = reader.uint32(); switch (tag >>> 3) { case 1: { - if (tag !== 8) { + if (tag !== 10) { break; } - message.id = reader.int32(); + message.name = reader.string(); + continue; + } + case 2: { + if (tag !== 16) { + break; + } + + message.force = reader.bool(); continue; } } @@ -465,7 +742,8 @@ export const DeleteWebhookRequest: MessageFns = { }, fromPartial(object: DeepPartial): DeleteWebhookRequest { const message = createBaseDeleteWebhookRequest(); - message.id = object.id ?? 0; + message.name = object.name ?? ""; + message.force = object.force ?? false; return message; }, }; @@ -569,23 +847,36 @@ export const WebhookServiceDefinition = { name: "WebhookService", fullName: "memos.api.v1.WebhookService", methods: { - /** CreateWebhook creates a new webhook. */ - createWebhook: { - name: "CreateWebhook", - requestType: CreateWebhookRequest, + /** ListWebhooks returns a list of webhooks. */ + listWebhooks: { + name: "ListWebhooks", + requestType: ListWebhooksRequest, + requestStream: false, + responseType: ListWebhooksResponse, + responseStream: false, + options: { + _unknownFields: { + 578365826: [ + new Uint8Array([18, 18, 16, 47, 97, 112, 105, 47, 118, 49, 47, 119, 101, 98, 104, 111, 111, 107, 115]), + ], + }, + }, + }, + /** GetWebhook gets a webhook by name. */ + getWebhook: { + name: "GetWebhook", + requestType: GetWebhookRequest, requestStream: false, responseType: Webhook, responseStream: false, options: { _unknownFields: { + 8410: [new Uint8Array([4, 110, 97, 109, 101])], 578365826: [ new Uint8Array([ - 21, - 58, - 1, - 42, - 34, - 16, + 27, + 18, + 25, 47, 97, 112, @@ -594,6 +885,12 @@ export const WebhookServiceDefinition = { 118, 49, 47, + 123, + 110, + 97, + 109, + 101, + 61, 119, 101, 98, @@ -602,26 +899,38 @@ export const WebhookServiceDefinition = { 111, 107, 115, + 47, + 42, + 125, ]), ], }, }, }, - /** GetWebhook returns a webhook by id. */ - getWebhook: { - name: "GetWebhook", - requestType: GetWebhookRequest, + /** CreateWebhook creates a new webhook. */ + createWebhook: { + name: "CreateWebhook", + requestType: CreateWebhookRequest, requestStream: false, responseType: Webhook, responseStream: false, options: { _unknownFields: { - 8410: [new Uint8Array([2, 105, 100])], + 8410: [new Uint8Array([7, 119, 101, 98, 104, 111, 111, 107])], 578365826: [ new Uint8Array([ - 23, - 18, - 21, + 27, + 58, + 7, + 119, + 101, + 98, + 104, + 111, + 111, + 107, + 34, + 16, 47, 97, 112, @@ -638,31 +947,11 @@ export const WebhookServiceDefinition = { 111, 107, 115, - 47, - 123, - 105, - 100, - 125, ]), ], }, }, }, - /** ListWebhooks returns a list of webhooks. */ - listWebhooks: { - name: "ListWebhooks", - requestType: ListWebhooksRequest, - requestStream: false, - responseType: ListWebhooksResponse, - responseStream: false, - options: { - _unknownFields: { - 578365826: [ - new Uint8Array([18, 18, 16, 47, 97, 112, 105, 47, 118, 49, 47, 119, 101, 98, 104, 111, 111, 107, 115]), - ], - }, - }, - }, /** UpdateWebhook updates a webhook. */ updateWebhook: { name: "UpdateWebhook", @@ -698,7 +987,7 @@ export const WebhookServiceDefinition = { ], 578365826: [ new Uint8Array([ - 40, + 44, 58, 7, 119, @@ -709,7 +998,7 @@ export const WebhookServiceDefinition = { 111, 107, 50, - 29, + 33, 47, 97, 112, @@ -718,6 +1007,7 @@ export const WebhookServiceDefinition = { 118, 49, 47, + 123, 119, 101, 98, @@ -725,9 +1015,12 @@ export const WebhookServiceDefinition = { 111, 111, 107, - 115, - 47, - 123, + 46, + 110, + 97, + 109, + 101, + 61, 119, 101, 98, @@ -735,16 +1028,16 @@ export const WebhookServiceDefinition = { 111, 111, 107, - 46, - 105, - 100, + 115, + 47, + 42, 125, ]), ], }, }, }, - /** DeleteWebhook deletes a webhook by id. */ + /** DeleteWebhook deletes a webhook. */ deleteWebhook: { name: "DeleteWebhook", requestType: DeleteWebhookRequest, @@ -753,12 +1046,12 @@ export const WebhookServiceDefinition = { responseStream: false, options: { _unknownFields: { - 8410: [new Uint8Array([2, 105, 100])], + 8410: [new Uint8Array([4, 110, 97, 109, 101])], 578365826: [ new Uint8Array([ - 23, + 27, 42, - 21, + 25, 47, 97, 112, @@ -767,6 +1060,12 @@ export const WebhookServiceDefinition = { 118, 49, 47, + 123, + 110, + 97, + 109, + 101, + 61, 119, 101, 98, @@ -776,9 +1075,7 @@ export const WebhookServiceDefinition = { 107, 115, 47, - 123, - 105, - 100, + 42, 125, ]), ],