events

package
v3.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 10 Imported by: 0

README

events

A Go package to retrieve events from WorkOS.

Install

go get -u github.com/workos/workos-go/v3/pkg/events

How it works

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/workos/workos-go/v3/pkg/events"
)

func main() {
	events.SetAPIKey(os.Getenv("WORKOS_API_KEY"))

	eventTypes := []string{
		"dsync.activated",
		"dsync.deleted",
		"dsync.user.created",
		"dsync.user.updated",
		"dsync.user.deleted",
	}

	events, err := events.ListEvents(context.Background(), events.ListEventsOpts{
		Events: eventTypes,
	})
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n", events)
}

Documentation

Overview

Package `events` provides a client wrapping the WorkOS Events API.

Index

Constants

View Source
const (
	// Connection Events
	ConnectionActivated   = "connection.activated"
	ConnectionDeactivated = "connection.deactived"
	ConnectionDeleted     = "connection.deleted"
	// Directory Events
	DirectoryActivated = "dsync.activated"
	DirectoryDeleted   = "dsync.deleted"
	// Directory User Events
	DirectoryUserCreated = "dsync.user.created"
	DirectoryUserUpdated = "dsync.user.updated"
	DirectoryUserDeleted = "dsync.user.deleted"
	// Directory Group Events
	DirectoryGroupCreated     = "dsync.group.created"
	DirectoryGroupUpdated     = "dsync.group.updated"
	DirectoryGroupDeleted     = "dsync.group.deleted"
	DirectoryGroupUserAdded   = "dsync.group.user_added"
	DirectroyGroupUserRemoved = "dsync.group.user_removed"
	// User Management Events
	UserCreated                   = "user.created"
	UserUpdated                   = "user.updated"
	UserDeleted                   = "user.deleted"
	OrganizationMembershipAdded   = "organization_membership.added"
	OrganizationMembershipRemoved = "organization_membership.removed"
)
View Source
const ResponseLimit = 10

ResponseLimit is the default number of records to limit a response to.

Variables

View Source
var (
	DefaultClient = &Client{
		Endpoint: "https://api.workos.com",
	}
)

DefaultClient is the client used by SetAPIKey and Event functions.

Functions

func SetAPIKey

func SetAPIKey(apiKey string)

SetAPIKey sets the WorkOS API key for Events requests.

Types

type Client

type Client struct {
	// The WorkOS API Key. It can be found in https://dashboard.workos.com/api-keys.
	APIKey string

	// The http.Client that is used to get Event records from WorkOS.
	// Defaults to http.Client.
	HTTPClient *http.Client

	// The endpoint to WorkOS API. Defaults to https://api.workos.com.
	Endpoint string
	// contains filtered or unexported fields
}

Client represents a client that performs Event requests to the WorkOS API.

func (*Client) ListEvents

func (c *Client) ListEvents(
	ctx context.Context,
	opts ListEventsOpts,
) (ListEventsResponse, error)

ListEvents gets a list of Events.

type Event

type Event struct {
	// The Event's unique identifier.
	ID string `json:"id"`

	// The type of Event.
	Event string `json:"event"`

	// The Event's data in raw encoded JSON.
	Data json.RawMessage `json:"data"`

	// The Event's created at date.
	CreatedAt time.Time `json:"created_at"`
}

Event contains data about a particular Event.

type ListEventsOpts

type ListEventsOpts struct {
	// Filter to only return Events of particular types.
	Events []string `url:"events,omitempty"`

	// Maximum number of records to return.
	Limit int `url:"limit"`

	// Pagination cursor to receive records after a provided Event ID.
	After string `url:"after,omitempty"`

	// Date range start for stream of Events.
	RangeStart string `url:"range_start,omitempty"`

	// Date range end for stream of Events.
	RangeEnd string `url:"range_end,omitempty"`
}

ListEventsOpts contains the options to request provisioned Events.

type ListEventsResponse

type ListEventsResponse struct {
	// List of Events.
	Data []Event `json:"data"`

	// Cursor pagination options.
	ListMetadata common.ListMetadata `json:"list_metadata"`
}

GetEventsResponse describes the response structure when requesting Events.

func ListEvents

func ListEvents(
	ctx context.Context,
	opts ListEventsOpts,
) (ListEventsResponse, error)

ListEvents gets a list of Events for an environment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL