Documentation
¶
Overview ¶
Package nahook provides shared types, errors, and an internal HTTP client for the Nahook webhook platform SDKs.
Index ¶
- Constants
- func PathEncode(s string) string
- func ResolveBaseURL(apiKey string) string
- type APIError
- type Application
- type BatchItemError
- type BatchResult
- type BatchResultItem
- type CreateApplicationOptions
- type CreateEndpointOptions
- type CreateEnvironmentOptions
- type CreateEventTypeOptions
- type CreatePortalSessionOptions
- type CreateSubscriptionOptions
- type Delivery
- type DeliveryAttempt
- type DeliveryStatus
- type DeliveryWithPayload
- type Endpoint
- type Environment
- type EventType
- type EventTypeVisibility
- type GetDeliveryOptions
- type HTTPClient
- type HTTPClientConfig
- type ListDeliveriesOptions
- type ListOptions
- type ListResult
- type NetworkError
- type NullableInt
- type PaginatedResult
- type PayloadEnvelope
- type PortalSession
- type RequestOptions
- type SendBatchItem
- type SendOptions
- type SendResult
- type SetVisibilityOptions
- type SubscribeResult
- type Subscription
- type TimeoutError
- type TriggerBatchItem
- type TriggerOptions
- type TriggerResult
- type UpdateApplicationOptions
- type UpdateEndpointOptions
- type UpdateEnvironmentOptions
- type UpdateEventTypeOptions
Constants ¶
const ( DefaultBaseURL = "https://api.nahook.com" DefaultTimeout = 30 * time.Second DefaultRetries = 0 )
Variables ¶
This section is empty.
Functions ¶
func PathEncode ¶
PathEncode encodes a path segment for use in URLs. Internal: not part of the public API.
func ResolveBaseURL ¶
ResolveBaseURL extracts the region slug from an nhk_ API key and returns the regional base URL. Falls back to DefaultBaseURL for legacy keys.
Types ¶
type APIError ¶
APIError represents an error response from the Nahook API.
func (*APIError) IsAuthError ¶
IsAuthError returns true for 401 or 403 with code "token_disabled".
func (*APIError) IsNotFound ¶
IsNotFound returns true for 404 status codes.
func (*APIError) IsRateLimited ¶
IsRateLimited returns true for 429 status codes.
func (*APIError) IsRetryable ¶
IsRetryable returns true for 5xx and 429 status codes.
func (*APIError) IsValidationError ¶
IsValidationError returns true for 400 status codes.
type Application ¶
type Application struct {
ID string `json:"id"`
ExternalID *string `json:"externalId"`
Name string `json:"name"`
Metadata map[string]string `json:"metadata"`
// MaxEndpoints is the maximum number of endpoints this application may
// have (disabled endpoints count). nil means unlimited.
MaxEndpoints *int `json:"maxEndpoints"`
// ShowEventTypes reports whether the Developer Portal exposes the
// event-type catalog to this application.
ShowEventTypes bool `json:"showEventTypes"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
Application represents a developer application.
func (*Application) UnmarshalJSON ¶ added in v0.3.0
func (a *Application) UnmarshalJSON(data []byte) error
UnmarshalJSON applies the server default (true) to ShowEventTypes when the field is absent from a response, matching the other SDKs' fallback.
type BatchItemError ¶
BatchItemError is an error for a specific item in a batch.
type BatchResult ¶
type BatchResult struct {
Items []BatchResultItem `json:"items"`
}
BatchResult is the response from a batch operation.
type BatchResultItem ¶
type BatchResultItem struct {
Index int `json:"index"`
DeliveryID string `json:"deliveryId,omitempty"`
IdempotencyKey string `json:"idempotencyKey,omitempty"`
EventTypeID string `json:"eventTypeId,omitempty"`
DeliveryIDs []string `json:"deliveryIds,omitempty"`
Status string `json:"status,omitempty"`
Error *BatchItemError `json:"error,omitempty"`
}
BatchResultItem is the result for one item in a batch operation.
type CreateApplicationOptions ¶
type CreateApplicationOptions struct {
Name string `json:"name"`
ExternalID string `json:"externalId,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
// MaxEndpoints caps how many endpoints this application may have
// (disabled endpoints count). 0 makes the application read-only.
// nil (omitted) means unlimited.
MaxEndpoints *int `json:"maxEndpoints,omitempty"`
// ShowEventTypes controls whether the Developer Portal exposes the
// event-type catalog. nil (omitted) defaults to true.
ShowEventTypes *bool `json:"showEventTypes,omitempty"`
}
CreateApplicationOptions configures a new application.
type CreateEndpointOptions ¶
type CreateEndpointOptions struct {
URL string `json:"url"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Config map[string]interface{} `json:"config,omitempty"`
AuthUsername string `json:"authUsername,omitempty"`
AuthPassword string `json:"authPassword,omitempty"`
// EnvironmentID is optional. Public id (e.g. "env_abc123") of the environment
// to scope this endpoint. If omitted, the workspace's default environment is used.
EnvironmentID string `json:"environmentId,omitempty"`
}
CreateEndpointOptions configures a new endpoint.
type CreateEnvironmentOptions ¶
CreateEnvironmentOptions configures a new environment.
type CreateEventTypeOptions ¶
type CreateEventTypeOptions struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
CreateEventTypeOptions configures a new event type.
type CreatePortalSessionOptions ¶
type CreatePortalSessionOptions struct {
Metadata map[string]string `json:"metadata,omitempty"`
Role string `json:"role,omitempty"`
ExpiresInMinutes int `json:"expiresInMinutes,omitempty"`
}
CreatePortalSessionOptions configures a new portal session.
type CreateSubscriptionOptions ¶
type CreateSubscriptionOptions struct {
EventTypeIDs []string `json:"eventTypeIds"`
}
CreateSubscriptionOptions configures a new subscription (bulk).
type Delivery ¶ added in v0.2.0
type Delivery struct {
ID string `json:"id"`
IdempotencyKey string `json:"idempotencyKey"`
EndpointID string `json:"endpointId"`
Status string `json:"status"`
TotalAttempts int `json:"totalAttempts"`
FirstAttemptAt *string `json:"firstAttemptAt"`
DeliveredAt *string `json:"deliveredAt"`
NextRetryAt *string `json:"nextRetryAt"`
HasPayload bool `json:"hasPayload"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
Delivery represents a webhook delivery's metadata (no payload body).
type DeliveryAttempt ¶ added in v0.2.0
type DeliveryAttempt struct {
ID string `json:"id"`
AttemptNumber int `json:"attemptNumber"`
Status string `json:"status"`
ResponseStatusCode *int `json:"responseStatusCode"`
ResponseTimeMs *int `json:"responseTimeMs"`
ErrorMessage *string `json:"errorMessage"`
CreatedAt string `json:"createdAt"`
}
DeliveryAttempt represents one HTTP delivery attempt against an endpoint. Status is an opaque worker-emitted string (e.g. "success", "failed") — do not model it as an enum, the set may evolve.
type DeliveryStatus ¶ added in v0.2.0
type DeliveryStatus = string
DeliveryStatus enumerates the lifecycle states of a webhook delivery. Possible values: "pending", "delivering", "delivered", "scheduled_retry", "failed", "dead_letter".
type DeliveryWithPayload ¶ added in v0.2.0
type DeliveryWithPayload struct {
Delivery
Payload *PayloadEnvelope `json:"payload,omitempty"`
}
DeliveryWithPayload is the response shape from get() — Delivery metadata, plus an optional payload envelope when the request included ?include=payload.
type Endpoint ¶
type Endpoint struct {
ID string `json:"id"`
URL string `json:"url"`
Description *string `json:"description"`
IsActive bool `json:"isActive"`
Type string `json:"type"`
Config map[string]interface{} `json:"config"`
Secret string `json:"secret,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
Endpoint represents a webhook endpoint.
type Environment ¶
type Environment struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
IsDefault bool `json:"isDefault"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
Environment represents a workspace environment.
type EventType ¶
type EventType struct {
ID string `json:"id"`
Name string `json:"name"`
Description *string `json:"description"`
CreatedAt string `json:"createdAt"`
}
EventType represents a registered event type.
type EventTypeVisibility ¶
type EventTypeVisibility struct {
EventTypeID string `json:"eventTypeId"`
EventTypeName string `json:"eventTypeName"`
Published bool `json:"published"`
}
EventTypeVisibility represents the visibility of an event type in an environment.
type GetDeliveryOptions ¶ added in v0.2.0
type GetDeliveryOptions struct {
IncludePayload bool
}
GetDeliveryOptions configures a single delivery fetch. Set IncludePayload to true to request the payload envelope alongside metadata.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient is the internal HTTP client shared by the client and management packages. Internal: not part of the public API.
func NewHTTPClient ¶
func NewHTTPClient(cfg HTTPClientConfig) *HTTPClient
NewHTTPClient creates a new internal HTTP client. Internal: not part of the public API.
func (*HTTPClient) Close ¶ added in v0.2.1
func (c *HTTPClient) Close()
Close drains the SDK-owned *http.Transport's idle connection pool. Useful for clean test teardown, graceful shutdown, or explicit reset before recycling long-lived clients. Idempotent. No-op when a caller-owned *http.Client was supplied via HTTPClientConfig.HTTPClient — the caller owns that transport's lifecycle.
func (*HTTPClient) HTTPClient ¶ added in v0.2.0
func (c *HTTPClient) HTTPClient() *http.Client
HTTPClient returns the underlying *http.Client. Useful for callers who want to introspect or attach instrumentation. Mutating the returned client affects all subsequent SDK requests.
func (*HTTPClient) Request ¶
func (c *HTTPClient) Request(ctx context.Context, opts RequestOptions, result interface{}) error
Request performs an HTTP request and decodes the JSON response into result. For DELETE (204) responses, result may be nil.
func (*HTTPClient) RequestWithStatus ¶
func (c *HTTPClient) RequestWithStatus(ctx context.Context, opts RequestOptions, result interface{}) (int, error)
RequestWithStatus performs an HTTP request and returns the status code along with the decoded body.
type HTTPClientConfig ¶
type HTTPClientConfig struct {
Token string
BaseURL string
Timeout time.Duration
Retries int
// HTTPClient, when non-nil, is used verbatim and not mutated. The caller's
// HTTPClient.Timeout governs request timeouts and is what TimeoutError.TimeoutMs
// reports. When nil, the SDK builds a *http.Client with a tuned *http.Transport
// (HTTP/2, TCP keep-alive, MaxIdleConnsPerHost = 50).
HTTPClient *http.Client
}
HTTPClientConfig configures the internal HTTP client. Internal: not part of the public API.
type ListDeliveriesOptions ¶ added in v0.2.0
ListDeliveriesOptions configures a deliveries list query. All fields are optional. Cursor is an opaque token from a previous PaginatedResult's NextCursor — pass it through verbatim.
type ListOptions ¶
ListOptions configures pagination for list operations.
type ListResult ¶
type ListResult[T any] struct { Data []T `json:"data"` }
ListResult wraps a list response.
type NetworkError ¶
type NetworkError struct {
Cause error
}
NetworkError represents a network-level failure where no HTTP response was received.
func (*NetworkError) Error ¶
func (e *NetworkError) Error() string
func (*NetworkError) Unwrap ¶
func (e *NetworkError) Unwrap() error
type NullableInt ¶ added in v0.3.0
type NullableInt struct {
// Value is the number to send; nil marshals as JSON null.
Value *int
}
NullableInt is a JSON field that marshals as either a number or an explicit null. PATCH fields typed *NullableInt are tri-state: a nil pointer is omitted from the body entirely (leave unchanged), IntNull() marshals as null (clear), and IntValue(n) marshals as n (set).
func IntNull ¶ added in v0.3.0
func IntNull() *NullableInt
IntNull returns a NullableInt that marshals as explicit JSON null — on UpdateApplicationOptions.MaxEndpoints this clears the cap (unlimited).
func IntValue ¶ added in v0.3.0
func IntValue(v int) *NullableInt
IntValue returns a NullableInt carrying v.
func (NullableInt) MarshalJSON ¶ added in v0.3.0
func (n NullableInt) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*NullableInt) UnmarshalJSON ¶ added in v0.3.0
func (n *NullableInt) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type PaginatedResult ¶ added in v0.2.0
type PaginatedResult[T any] struct { Data []T `json:"data"` NextCursor *string `json:"nextCursor"` }
PaginatedResult is a generic cursor-paginated read result. NextCursor is an opaque, server-encrypted token — pass it back verbatim on the next request, do not decode or modify it. Nil when there are no more pages.
type PayloadEnvelope ¶ added in v0.2.0
type PayloadEnvelope struct {
Status string `json:"status"`
Data json.RawMessage `json:"data,omitempty"`
ContentType string `json:"contentType,omitempty"`
}
PayloadEnvelope is a flat tagged union describing the access state of a stored delivery payload. The Status field discriminates which other fields are populated:
- "available": Data and ContentType are set.
- "forbidden": workspace plan does not include payload storage.
- "processing": delivery still in flight, payload not yet written.
- "not_found": terminal delivery without a stored payload.
- "error": transient infrastructure failure reading the payload.
Only "available" is a successful read; all four other statuses are returned with HTTP 200 — do not treat them as errors.
type PortalSession ¶
type PortalSession struct {
URL string `json:"url"`
Code string `json:"code"`
ExpiresAt string `json:"expiresAt"`
}
PortalSession represents a portal session for developer self-service.
type RequestOptions ¶
RequestOptions describes an HTTP request to the Nahook API. Internal: not part of the public API.
type SendBatchItem ¶
type SendBatchItem struct {
EndpointID string `json:"endpointId"`
Payload map[string]interface{} `json:"payload"`
IdempotencyKey string `json:"idempotencyKey,omitempty"`
}
SendBatchItem represents one item in a batch send.
type SendOptions ¶
type SendOptions struct {
Payload map[string]interface{} `json:"payload"`
IdempotencyKey string `json:"idempotencyKey,omitempty"`
}
SendOptions configures a direct send to a specific endpoint.
type SendResult ¶
type SendResult struct {
DeliveryID string `json:"deliveryId"`
IdempotencyKey string `json:"idempotencyKey"`
Status string `json:"status"`
}
SendResult is the response from a direct send.
type SetVisibilityOptions ¶
type SetVisibilityOptions struct {
Published bool `json:"published"`
}
SetVisibilityOptions configures event type visibility in an environment.
type SubscribeResult ¶
type SubscribeResult struct {
Subscribed int `json:"subscribed"`
}
SubscribeResult is the response from subscribing an endpoint to event types.
type Subscription ¶
type Subscription struct {
ID string `json:"id"`
EventTypeID string `json:"eventTypeId"`
EventTypeName string `json:"eventTypeName"`
CreatedAt string `json:"createdAt"`
}
Subscription represents an event type subscription on an endpoint.
type TimeoutError ¶
type TimeoutError struct {
TimeoutMs int
}
TimeoutError represents a request that exceeded the configured timeout.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type TriggerBatchItem ¶
type TriggerBatchItem struct {
EventType string `json:"eventType"`
Payload map[string]interface{} `json:"payload"`
Metadata map[string]string `json:"metadata,omitempty"`
}
TriggerBatchItem represents one item in a batch trigger.
type TriggerOptions ¶
type TriggerOptions struct {
Payload map[string]interface{} `json:"payload"`
Metadata map[string]string `json:"metadata,omitempty"`
}
TriggerOptions configures a fan-out trigger by event type.
type TriggerResult ¶
type TriggerResult struct {
EventTypeID string `json:"eventTypeId"`
DeliveryIDs []string `json:"deliveryIds"`
Status string `json:"status"`
}
TriggerResult is the response from a trigger.
type UpdateApplicationOptions ¶
type UpdateApplicationOptions struct {
Name *string `json:"name,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
// MaxEndpoints is tri-state: leave nil to keep the current cap,
// IntNull() to clear it (unlimited), or IntValue(n) to set it.
MaxEndpoints *NullableInt `json:"maxEndpoints,omitempty"`
// ShowEventTypes is omitted (unchanged) when nil.
ShowEventTypes *bool `json:"showEventTypes,omitempty"`
}
UpdateApplicationOptions configures an application update.
type UpdateEndpointOptions ¶
type UpdateEndpointOptions struct {
URL *string `json:"url,omitempty"`
Description *string `json:"description,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
IsActive *bool `json:"isActive,omitempty"`
}
UpdateEndpointOptions configures an endpoint update.
type UpdateEnvironmentOptions ¶
type UpdateEnvironmentOptions struct {
Name *string `json:"name,omitempty"`
}
UpdateEnvironmentOptions configures an environment update.
type UpdateEventTypeOptions ¶
type UpdateEventTypeOptions struct {
Description *string `json:"description,omitempty"`
}
UpdateEventTypeOptions configures an event type update.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client provides the Nahook ingestion client for sending webhooks.
|
Package client provides the Nahook ingestion client for sending webhooks. |
|
Package management provides the Nahook management API client for administering workspaces, endpoints, event types, applications, subscriptions, and portal sessions.
|
Package management provides the Nahook management API client for administering workspaces, endpoints, event types, applications, subscriptions, and portal sessions. |