common

package
v0.0.0-...-463faa5 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidModuleDeclaration occurs when the identifier used for map indexing in Modules
	// does not match the module's ID.
	ErrInvalidModuleDeclaration = errors.New("supported modules are not correctly defined")

	// ErrMissingModule can be returned when connector cannot resolve ModuleID.
	ErrMissingModule = errors.New("module not found")
)
View Source
var (
	// ErrAccessToken is a token which isn't valid.
	ErrAccessToken = errors.New("access token invalid")

	// ErrApiDisabled means a customer didn't enable this API on their SaaS instance.
	ErrApiDisabled = errors.New("API disabled")

	// ErrForbidden means the user doesn't have access to this resource.
	ErrForbidden = errors.New("forbidden")

	// ErrInvalidSessionId means the session ID is invalid.
	ErrInvalidSessionId = errors.New("invalid session id")

	// ErrUnableToLockRow means the resource couldn't be locked.
	ErrUnableToLockRow = errors.New("unable to lock row")

	// ErrInvalidGrant means the OAuth grant is invalid.
	ErrInvalidGrant = errors.New("invalid grant")

	// ErrLimitExceeded means a quota limit was exceeded.
	ErrLimitExceeded = errors.New("request limit exceeded")

	// ErrRetryable represents a temporary error. Can retry.
	ErrRetryable = errors.New("retryable error")

	// ErrCaller represents non-retryable errors caused by bad input from the caller.
	ErrCaller = errors.New("caller error")

	// ErrServer represents non-retryable errors caused by something on the server.
	ErrServer = errors.New("server error")

	// ErrUnknown represents an unknown status code response.
	ErrUnknown = errors.New("unknown error")

	// ErrNotJSON is returned when a response is not JSON.
	ErrNotJSON = errors.New("response is not JSON")

	// ErrNotXML is returned when a response is not XML.
	ErrNotXML = errors.New("response is not XML")

	// ErrMissingOauthConfig is returned when the OAuth config is missing.
	ErrMissingOauthConfig = errors.New("missing OAuth config")

	// ErrMissingRefreshToken is returned when the refresh token is missing.
	ErrMissingRefreshToken = errors.New("missing refresh token")

	// ErrEmptyBaseURL is returned when the URL is relative, and the base URL is empty.
	ErrEmptyBaseURL = errors.New("empty base URL")

	// ErrNotImplemented is returned when a method is not implemented.
	ErrNotImplemented = errors.New("not implemented")

	// ErrRequestFailed is returned when the request failed.
	ErrRequestFailed = errors.New("request failed")

	// ErrParseError is returned data parsing failed.
	ErrParseError = errors.New("parse error")

	// ErrBadRequest is returned when we get a 400 response from the provider.
	ErrBadRequest = errors.New("bad request")

	// ErrNotFound is returned when we get a 404 response from the provider.
	ErrNotFound = errors.New("not found")

	// ErrMissingExpectedValues is returned when response data doesn't have values expected for processing.
	ErrMissingExpectedValues = errors.New("response data is missing expected values")

	// ErrPreprocessingWritePayload is returned when request payload supplied to connector "Write" method
	// couldn't be processed. Likely, the issue is within provided WriteParams.RecordData or implementation.
	ErrPreprocessingWritePayload = errors.New("failed preprocessing write payload")

	// ErrEmptyJSONHTTPResponse is returned when the JSONHTTPResponse is nil.
	ErrEmptyJSONHTTPResponse = errors.New("empty json http response")

	// ErrEmptyRecordIdResponse is returned when the response body doesn't have record id.
	ErrEmptyRecordIdResponse = errors.New("empty record id in response body")

	// ErrRecordDataNotJSON is returned when the record data in WriteParams is not JSON.
	ErrRecordDataNotJSON = errors.New("record data is not JSON")

	// ErrOperationNotSupportedForObject is returned when operation is not supported for this object.
	ErrOperationNotSupportedForObject = errors.New("operation is not supported for this object in this module")

	// ErrObjectNotSupported is returned when operation is not supported for this object.
	ErrObjectNotSupported = errors.New("operation is not supported for this object")

	// ErrResolvingURLPathForObject is returned when URL cannot be implied for object name.
	ErrResolvingURLPathForObject = errors.New("cannot resolve URL path for given object name")

	// ErrFailedToUnmarshalBody is returned when response body cannot be marshalled into some type.
	ErrFailedToUnmarshalBody = errors.New("failed to unmarshal response body")
)
View Source
var (
	// ErrMissingObjects is returned when no objects are provided in the request.
	ErrMissingObjects = errors.New("no objects provided")

	// ErrMissingRecordID is returned when resource id is missing in the request.
	ErrMissingRecordID = errors.New("no object ID provided")

	// ErrMissingRecordData is returned when write data is missing in the request.
	ErrMissingRecordData = errors.New("no data provided")

	// ErrMissingFields is returned when no fields are provided for reading.
	ErrMissingFields = errors.New("no fields provided in ReadParams")
)
View Source
var (
	ErrNotXMLChildren = errors.New("children must be of type 'XMLData' or 'XMLString'")
	ErrNoSelfClosing  = errors.New("selfClosing cannot be true if children are not present")
	ErrNoParens       = errors.New("value cannot contain < or >")
)
View Source
var ErrMissingCSVData = errors.New("no CSV data provided")

ErrMissingCSVData is returned when no CSV data was given for the upload.

Functions

func AddSuffixIfNotExists

func AddSuffixIfNotExists(str string, suffix string) string

AddSuffixIfNotExists appends the suffix to the provided string.

func ExtractLowercaseFieldsFromRaw

func ExtractLowercaseFieldsFromRaw(fields []string, record map[string]interface{}) map[string]interface{}

ExtractLowercaseFieldsFromRaw returns a map of fields from a record. The fields are all returned in lowercase.

func GetResponseBodyOnce

func GetResponseBodyOnce(response *http.Response) []byte

func InterpretError

func InterpretError(res *http.Response, body []byte) error

InterpretError interprets the given HTTP response (in a fairly straightforward way) and returns an error that can be handled by the caller.

func MakeGetRequest

func MakeGetRequest(ctx context.Context, url string, headers []Header) (*http.Request, error)

MakeGetRequest creates a GET request with the given headers.

func MakeJSONGetRequest

func MakeJSONGetRequest(ctx context.Context, url string, headers []Header) (*http.Request, error)

MakeJSONGetRequest creates a GET request with the given headers and adds the Accept: application/json header. It then returns the request.

func NewHTTPStatusError

func NewHTTPStatusError(status int, err error) error

NewHTTPStatusError creates a new error with the given HTTP status.

func PrintRequestAndResponse

func PrintRequestAndResponse(req *http.Request, rsp *http.Response)

func UnmarshalJSON

func UnmarshalJSON[T any](rsp *JSONHTTPResponse) (*T, error)

UnmarshalJSON deserializes the response body into the given type.

Types

type AuthenticatedHTTPClient

type AuthenticatedHTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
	CloseIdleConnections()
}

AuthenticatedHTTPClient is an interface for an http client which can automatically authenticate itself. This is useful for OAuth authentication, where the access token needs to be refreshed automatically. The signatures are a subset of http.Client, so it can be used as a (mostly) drop-in replacement.

func NewApiKeyHeaderAuthHTTPClient

func NewApiKeyHeaderAuthHTTPClient(
	ctx context.Context,
	headerName, headerValue string,
	opts ...HeaderAuthClientOption,
) (AuthenticatedHTTPClient, error)

NewApiKeyHeaderAuthHTTPClient returns a new http client, with automatic API key authentication. Specifically this means that the client will automatically add the API key (as a header) to every request. HeaderValue must be in the correct format. This sometimes means adding prefix to the API Key.

func NewApiKeyQueryParamAuthHTTPClient

func NewApiKeyQueryParamAuthHTTPClient(
	ctx context.Context,
	queryParamName, apiKey string,
	opts ...QueryParamAuthClientOption,
) (AuthenticatedHTTPClient, error)

NewApiKeyQueryParamAuthHTTPClient returns a new http client, with automatic API key authentication. Specifically this means that the client will automatically add the API key (as a query param) to every request.

func NewBasicAuthHTTPClient

func NewBasicAuthHTTPClient(
	ctx context.Context,
	user, pass string,
	opts ...HeaderAuthClientOption,
) (AuthenticatedHTTPClient, error)

NewBasicAuthHTTPClient returns a new http client, with automatic Basic authentication. Specifically this means that the client will automatically add the Basic auth header to every request. The username and password are provided as arguments.

func NewHeaderAuthHTTPClient

func NewHeaderAuthHTTPClient(
	ctx context.Context,
	opts ...HeaderAuthClientOption,
) (AuthenticatedHTTPClient, error)

NewHeaderAuthHTTPClient returns a new http client, which will do generic header-based authentication. It does this by automatically adding the provided headers to every request. There's no additional logic for refreshing tokens or anything like that. This is appropriate for APIs that use keys or basic auth.

func NewJwtAuthHTTPClient

func NewJwtAuthHTTPClient(
	ctx context.Context,
	opts ...HeaderAuthClientOption,
) (AuthenticatedHTTPClient, error)

NewJwtAuthHTTPClient returns a new http client, with automatic Jwt generation & authentication. Specifically this means that the client will automatically add the Jwt (as a header) to every request, based on the given secret and claims.

func NewOAuthHTTPClient

func NewOAuthHTTPClient(ctx context.Context, opts ...OAuthOption) (AuthenticatedHTTPClient, error)

NewOAuthHTTPClient returns a new http client, with automatic OAuth authentication. Specifically this means that the client will automatically refresh the access token whenever it expires.

func NewQueryParamAuthHTTPClient

func NewQueryParamAuthHTTPClient(
	ctx context.Context,
	opts ...QueryParamAuthClientOption,
) (AuthenticatedHTTPClient, error)

NewQueryParamAuthHTTPClient returns a new http client, which will do generic query-param-based authentication. It does this by automatically adding the provided query params to every request. There's no additional logic for refreshing tokens or anything like that. This is appropriate for APIs that use keys encoded in the query params.

type DeleteParams

type DeleteParams struct {
	// The name of the object we are deleting, e.g. "Account"
	ObjectName string // required

	// The external ID of the object instance we are removing.
	RecordId string // required
}

DeleteParams defines how we are deleting data in SaaS API.

func (DeleteParams) ValidateParams

func (p DeleteParams) ValidateParams() error

type DeleteResult

type DeleteResult struct {
	// Success is true if deletion succeeded.
	Success bool `json:"success"`
}

DeleteResult is what's returned from deleting data via the Delete call.

type DynamicHeadersGenerator

type DynamicHeadersGenerator func(http.Request) ([]Header, error)

type ErrorHandler

type ErrorHandler func(rsp *http.Response, body []byte) error

ErrorHandler allows the caller to inject their own HTTP error handling logic. All non-2xx responses will be passed to the error handler. If the error handler returns nil, then the error is ignored and the caller is responsible for handling the error. If the error handler returns an error, then that error is returned to the caller, as-is. Both the response and the response body are passed to the error handler as arguments.

type ErrorPostProcessor

type ErrorPostProcessor struct {
	Process func(err error) error
}

type HTTPClient

type HTTPClient struct {
	Base            string                  // optional base URL. If not set, then all URLs must be absolute.
	Client          AuthenticatedHTTPClient // underlying HTTP client. Required.
	ErrorHandler    ErrorHandler            // optional error handler. If not set, then the default error handler is used.
	ResponseHandler ResponseHandler         // optional, Allows mutation of the http.Response from the Saas API response.
}

HTTPClient is an HTTP client that handles OAuth access token refreshes.

func (*HTTPClient) Delete

func (h *HTTPClient) Delete(ctx context.Context,
	url string, headers ...Header,
) (*http.Response, []byte, error)

func (*HTTPClient) Get

func (h *HTTPClient) Get(ctx context.Context, url string, headers ...Header) (*http.Response, []byte, error)

Get makes a GET request to the given URL and returns the response. If the response is not a 2xx, an error is returned. If the response is a 401, the caller should refresh the access token and retry the request. If errorHandler is nil, then the default error handler is used. If not, the caller can inject their own error handling logic.

func (*HTTPClient) Patch

func (h *HTTPClient) Patch(ctx context.Context,
	url string, reqBody any, headers ...Header,
) (*http.Response, []byte, error)

Patch makes a PATCH request to the given URL and returns the response & response body. If the response is not a 2xx, an error is returned. If the response is a 401, the caller should refresh the access token and retry the request. If errorHandler is nil, then the default error handler is used. If not, the caller can inject their own error handling logic.

func (*HTTPClient) Post

func (h *HTTPClient) Post(ctx context.Context,
	url string, reqBody []byte, headers ...Header,
) (*http.Response, []byte, error)

Post makes a POST request to the given URL and returns the response & response body. If the response is not a 2xx, an error is returned. If the response is a 401, the caller should refresh the access token and retry the request. If errorHandler is nil, then the default error handler is used. If not, the caller can inject their own error handling logic.

func (*HTTPClient) Put

func (h *HTTPClient) Put(ctx context.Context,
	url string, reqBody any, headers ...Header,
) (*http.Response, []byte, error)

type HTTPStatusError

type HTTPStatusError struct {
	// HTTPStatus is the original HTTP status.
	HTTPStatus int
	// contains filtered or unexported fields
}

HTTPStatusError is an error that contains an HTTP status code.

func (HTTPStatusError) Error

func (r HTTPStatusError) Error() string

func (HTTPStatusError) Unwrap

func (r HTTPStatusError) Unwrap() error
type Header struct {
	Key   string
	Value string
}

Header is a key/value pair that can be added to a request.

type HeaderAuthClientOption

type HeaderAuthClientOption func(params *headerClientParams)

func WithDynamicHeaders

func WithDynamicHeaders(f DynamicHeadersGenerator) HeaderAuthClientOption

WithDynamicHeaders sets a function that will be called on every request to get additional headers to use. Use this for things like time-based tokens or loading headers from some external authority. The function can access a copy of the request object to use its metadata for generating headers.

func WithHeaderClient

func WithHeaderClient(client *http.Client) HeaderAuthClientOption

WithHeaderClient sets the http client to use for the connector. Its usage is optional.

func WithHeaderDebug

func WithHeaderDebug(f func(req *http.Request, rsp *http.Response)) HeaderAuthClientOption

WithHeaderDebug sets a debug function to be called on every request and response, after the response has been received from the downstream API.

func WithHeaderUnauthorizedHandler

func WithHeaderUnauthorizedHandler(
	f func(hdrs []Header, req *http.Request, rsp *http.Response) (*http.Response, error),
) HeaderAuthClientOption

WithHeaderUnauthorizedHandler sets the function to call whenever the response is 401 unauthorized. This is useful for handling the case where the server has invalidated the credentials, and the client needs to refresh. It's optional.

func WithHeaders

func WithHeaders(headers ...Header) HeaderAuthClientOption

WithHeaders sets the headers to use for the connector. Its usage is optional.

type JSONHTTPClient

type JSONHTTPClient struct {
	HTTPClient         *HTTPClient        // underlying HTTP client. Required.
	ErrorPostProcessor ErrorPostProcessor // Errors returned from CRUD methods will go via this method. Optional.
}

JSONHTTPClient is an HTTP client which makes certain assumptions, such as that the response body is JSON. It also handles OAuth access token refreshes.

func (*JSONHTTPClient) Delete

func (j *JSONHTTPClient) Delete(ctx context.Context, url string, headers ...Header) (*JSONHTTPResponse, error)

func (*JSONHTTPClient) Get

func (j *JSONHTTPClient) Get(ctx context.Context, url string, headers ...Header) (*JSONHTTPResponse, error)

Get makes a GET request to the given URL and returns the response body as a JSON object. If the response is not a 2xx, an error is returned. If the response is a 401, the caller should refresh the access token and retry the request. If errorHandler is nil, then the default error handler is used. If not, the caller can inject their own error handling logic.

func (*JSONHTTPClient) Patch

func (j *JSONHTTPClient) Patch(ctx context.Context,
	url string, reqBody any, headers ...Header,
) (*JSONHTTPResponse, error)

func (*JSONHTTPClient) Post

func (j *JSONHTTPClient) Post(ctx context.Context,
	url string, reqBody any, headers ...Header,
) (*JSONHTTPResponse, error)

Post makes a POST request to the given URL and returns the response body as a JSON object. ReqBody must be JSON-serializable. If it is not, an error is returned. If the response is not a 2xx, an error is returned. If the response is a 401, the caller should refresh the access token and retry the request. If errorHandler is nil, then the default error handler is used. If not, the caller can inject their own error handling logic.

func (*JSONHTTPClient) Put

func (j *JSONHTTPClient) Put(ctx context.Context,
	url string, reqBody any, headers ...Header,
) (*JSONHTTPResponse, error)

func (*JSONHTTPClient) PutCSV

func (j *JSONHTTPClient) PutCSV(ctx context.Context, url string, reqBody []byte, headers ...Header) ([]byte, error)

type JSONHTTPResponse

type JSONHTTPResponse struct {

	// Code is the HTTP status code of the response.
	Code int

	// Headers are the HTTP headers of the response.
	Headers http.Header
	// contains filtered or unexported fields
}

JSONHTTPResponse is a JSON response from an HTTP request. Consider using Body to operate on ajson.Node or Unmarshal into the struct of your choosing via UnmarshalJSON.

func (*JSONHTTPResponse) Body

func (j *JSONHTTPResponse) Body() (*ajson.Node, bool)

Body returns JSON node. If it is empty the flag will indicate so. Empty response body is a special case and should be handled explicitly.

type ListObjectMetadataResult

type ListObjectMetadataResult struct {
	// Result is a map of object names to object metadata
	Result map[string]ObjectMetadata

	// Errors is a map of object names to errors
	Errors map[string]error
}

type Module

type Module struct {
	ID      ModuleID
	Label   string // e.g. "crm"
	Version string // e.g. "v3"
}

Module represents a set of endpoints and functionality available by provider. Single provider may support multiple modules, requiring the user to choose a module before making requests. Modules may differ by version or by theme, covering different systems or functionalities.

func (Module) Path

func (a Module) Path() string

type ModuleID

type ModuleID string

type ModuleObjectNameToFieldName

type ModuleObjectNameToFieldName map[ModuleID]datautils.DefaultMap[string, string]

ModuleObjectNameToFieldName is a grouping of ObjectName to response field name mappings defined for each Module.

Explanation: modules have objects, each object is located under certain field name in the response body. This mapping stores the general relationship between the said ObjectName and FieldName. Those objects that do not follow the pattern described in the fallback method are hard code as exceptions.

Ex:

Given:	Connector has 2 modules -- Commerce, Messaging.
		Commerce module has objects stored under "data" field name, except "carts".
		Messaging module has objects stored under the same name as object, except "chats".
Then:	It will be represented as follows:

	ModuleObjectNameToFieldName{
		ModuleCommerce: datautils.NewDefaultMap(map[string]string{
			"carts": "carts",
		},
			func(objectName string) string {
				return "data" // always under "data" field {"data": [{},{},...]}
			},
		),
		ModuleHelpCenter: datautils.NewDefaultMap(map[string]string{
			"chats":        "active_chats",
		}, func(objectName string) string {
			fieldName := objectName // Object "messages" is stored under {"messages": [{},{},...]}
			return fieldName
		}),
	}

type Modules

type Modules = datautils.Map[ModuleID, Module]

type NextPageFunc

type NextPageFunc func(*ajson.Node) (string, error)

type NextPageToken

type NextPageToken string

NextPageToken is an opaque token that can be used to get the next page of results. Callers are encouraged to treat this as an opaque string, and not attempt to parse it. And although each provider will be different, callers should expect that this token will expire after some period of time. So long-term storage of this token is not recommended.

func (NextPageToken) String

func (t NextPageToken) String() string

type OAuthOption

type OAuthOption func(*oauthClientParams)

func WithOAuthClient

func WithOAuthClient(client *http.Client) OAuthOption

WithOAuthClient sets the http client to use for the connector. Its usage is optional.

func WithOAuthConfig

func WithOAuthConfig(config *oauth2.Config) OAuthOption

WithOAuthConfig sets the oauth config to use for the connector. It's required, unless a token source is provided.

func WithOAuthDebug

func WithOAuthDebug(f func(req *http.Request, rsp *http.Response)) OAuthOption

WithOAuthDebug sets a debug function to be called on every request and response, after the response has been received from the downstream API.

func WithOAuthToken

func WithOAuthToken(token *oauth2.Token) OAuthOption

WithOAuthToken sets the oauth token to use for the connector. It's required, unless a token source is provided.

func WithOAuthUnauthorizedHandler

func WithOAuthUnauthorizedHandler(
	f func(token *oauth2.Token, req *http.Request, rsp *http.Response) (*http.Response, error),
) OAuthOption

WithOAuthUnauthorizedHandler sets the function to call whenever the response is 401 unauthorized. This is useful for handling the case where the server has invalidated the token, and the client needs to forcefully refresh. It's optional.

func WithTokenSource

func WithTokenSource(tokenSource oauth2.TokenSource) OAuthOption

WithTokenSource sets the oauth token source to use for the connector. Whenever the token expires, this will be called to refresh it.

func WithTokenUpdated

func WithTokenUpdated(onTokenUpdated func(oldToken, newToken *oauth2.Token) error) OAuthOption

WithTokenUpdated sets the function to call whenever the oauth token is updated. This is useful for persisting the refreshed tokens somewhere, so that it can be used later. It's optional.

type ObjectMetadata

type ObjectMetadata struct {
	// Provider's display name for the object
	DisplayName string

	// FieldsMap is a map of field names to field display names
	FieldsMap map[string]string
}

type PostAuthInfo

type PostAuthInfo struct {
	CatalogVars          *map[string]string
	RawResponse          *JSONHTTPResponse
	ProviderWorkspaceRef string
}

type QueryParam

type QueryParam struct {
	Key   string
	Value string
}

type QueryParamAuthClientOption

type QueryParamAuthClientOption func(params *queryParamClientParams)

func WithQueryParamClient

func WithQueryParamClient(client *http.Client) QueryParamAuthClientOption

WithQueryParamClient sets the http client to use for the connector. Its usage is optional.

func WithQueryParamDebug

func WithQueryParamDebug(f func(req *http.Request, rsp *http.Response)) QueryParamAuthClientOption

WithQueryParamDebug sets a debug function to be called on every request and response, after the response has been received from the downstream API.

func WithQueryParamUnauthorizedHandler

func WithQueryParamUnauthorizedHandler(
	f func(params []QueryParam, req *http.Request, rsp *http.Response) (*http.Response, error),
) QueryParamAuthClientOption

WithQueryParamUnauthorizedHandler sets the function to call whenever the response is 401 unauthorized. This is useful for handling the case where the server has invalidated the credentials, and the client needs to refresh. It's optional.

func WithQueryParams

func WithQueryParams(ps ...QueryParam) QueryParamAuthClientOption

type ReadParams

type ReadParams struct {
	// The name of the object we are reading, e.g. "Account"
	ObjectName string // required

	// The fields we are reading from the object, e.g. ["Id", "Name", "BillingCity"]
	Fields datautils.StringSet // required, at least one field needed

	// NextPage is an opaque token that can be used to get the next page of results.
	NextPage NextPageToken // optional, only set this if you want to read the next page of results

	// Since is a timestamp that can be used to get only records that have changed since that time.
	Since time.Time // optional, omit this to fetch all records

	// Deleted is true if we want to read deleted records instead of active records.
	Deleted bool // optional, defaults to false

	// Filter is supported for the following connectors:
	//	* Salesforce: it is a SOQL string that comes after the WHERE clause which will be used to filter the records.
	//		Reference: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm
	//	* Klaviyo: comma separated methods following JSON:API filtering syntax.
	//		Note: timing is already handled by Since argument.
	//		Reference: https://developers.klaviyo.com/en/docs/filtering_
	Filter string // optional
}

ReadParams defines how we are reading data from a SaaS API.

func (ReadParams) ValidateParams

func (p ReadParams) ValidateParams(withRequiredFields bool) error

type ReadResult

type ReadResult struct {
	// Rows is the number of total rows in the result.
	Rows int64 `json:"rows"`
	// Data is an array where each element represents a ReadResultRow.
	Data []ReadResultRow `json:"data"`
	// NextPage is an opaque token that can be used to get the next page of results.
	NextPage NextPageToken `json:"nextPage,omitempty"`
	// Done is true if there are no more pages to read.
	Done bool `json:"done,omitempty"`
}

ReadResult is what's returned from reading data via the Read call.

func ParseResult

func ParseResult(
	resp *JSONHTTPResponse,
	recordsFunc func(*ajson.Node) ([]map[string]any, error),
	nextPageFunc func(*ajson.Node) (string, error),
	marshalFunc func([]map[string]any, []string) ([]ReadResultRow, error),
	fields datautils.Set[string],
) (*ReadResult, error)

ParseResult parses the response from a provider into a ReadResult. A 2xx return type is assumed. The sizeFunc returns the total number of records in the response. The recordsFunc returns the records in the response. The nextPageFunc returns the URL for the next page of results. The marshalFunc is used to structure the data into an array of ReadResultRows. The fields are used to populate ReadResultRow.Fields.

type ReadResultRow

type ReadResultRow struct {
	// Fields is a map of requested provider field names to values.
	// All field names are in lowercase (eg: accountid, name, billingcityid)
	Fields map[string]any `json:"fields"`
	// Raw is the raw JSON response from the provider.
	Raw map[string]any `json:"raw"`
	// RecordId is the ID of the record. Currently only populated for hubspot GetRecord and GetRecordsWithId function
	Id string `json:"id,omitempty"`
}

ReadResultRow is a single row of data returned from a Read call, which contains the requested fields, as well as the raw JSON response from the provider.

func GetMarshaledData

func GetMarshaledData(records []map[string]any, fields []string) ([]ReadResultRow, error)

type RecordsFunc

type RecordsFunc func(*ajson.Node) ([]map[string]any, error)

func GetOptionalRecordsUnderJSONPath

func GetOptionalRecordsUnderJSONPath(jsonPath string) RecordsFunc

func GetRecordsUnderJSONPath

func GetRecordsUnderJSONPath(jsonPath string) RecordsFunc

type ResponseHandler

type ResponseHandler func(rsp *http.Response) (*http.Response, error)

type SubscriptionEvent

type SubscriptionEvent interface {
	EventType() (SubscriptionEventType, error)
	RawEventName() (string, error)
	ObjectName() (string, error)
	Workspace() (string, error)
}

SubscribeEvent is an interface for webhook events coming from the provider. This interface defines methods to extract information from the webhook event.

type SubscriptionEventType

type SubscriptionEventType string
const (
	SubscriptionEventTypeCreate SubscriptionEventType = "create"
	SubscriptionEventTypeUpdate SubscriptionEventType = "update"
	SubscriptionEventTypeDelete SubscriptionEventType = "delete"
	SubscriptionEventTypeOther  SubscriptionEventType = "other"
)

type TokenSourceWithContext

type TokenSourceWithContext interface {
	oauth2.TokenSource

	// TokenWithContext returns a token or an error.
	// Token must be safe for concurrent use by multiple goroutines.
	// The returned Token must not be modified.
	// Similar semantics to oauth2.TokenSource, but with a context.
	TokenWithContext(ctx context.Context) (*oauth2.Token, error)
}

TokenSourceWithContext is an interface that extends the oauth2.TokenSource interface with a context. This is useful for token sources that need to be aware of the context in which they are being called. The use of this interface is optional, but if the token source conforms to it, then the context version of the Token method will be called instead of the normal one.

type WebhookVerificationParameters

type WebhookVerificationParameters struct {
	Headers      http.Header
	Body         []byte
	URL          string
	ClientSecret string
	Method       string
}

WebhookVerificationParameters is a struct that contains the parameters required to verify a webhook.

type WriteMethod

type WriteMethod func(context.Context, string, any, ...Header) (*JSONHTTPResponse, error)

WriteMethod is signature for any HTTP method that performs write modifications. Ex: Post/Put/Patch.

type WriteParams

type WriteParams struct {
	// The name of the object we are writing, e.g. "Account"
	ObjectName string // required

	// The external ID of the object instance we are updating. Provided in the case of UPDATE, but not CREATE.
	RecordId string // optional

	// RecordData is a JSON node representing the record of data we want to insert in the case of CREATE
	// or fields of data we want to modify in case of an update
	RecordData any // required

	// Associations contains associations between the object and other objects.
	Associations any // optional
}

WriteParams defines how we are writing data to a SaaS API.

func (WriteParams) ValidateParams

func (p WriteParams) ValidateParams() error

type WriteResult

type WriteResult struct {
	// Success is true if write succeeded.
	Success bool `json:"success"`
	// RecordId is the ID of the written record.
	RecordId string `json:"recordId,omitempty"` // optional
	// Errors is list of error record returned by the API.
	Errors []any `json:"errors,omitempty"` // optional
	// Data is a JSON node containing data about the properties that were updated.
	Data map[string]any `json:"data,omitempty"` // optional
}

WriteResult is what's returned from writing data via the Write call.

type XMLAttributes

type XMLAttributes struct {
	Key   string `json:"key"   validate:"required,excludesall=<>,excludesrune=<>"`
	Value string `json:"value" validate:"excludesall=<>,excludesrune=<>"`
}

func (*XMLAttributes) String

func (attr *XMLAttributes) String() string

func (*XMLAttributes) Validate

func (attr *XMLAttributes) Validate() error

type XMLData

type XMLData struct {
	XMLName     string           `json:"xmlName,omitempty"     validate:"required,excludesall=<>"`
	Attributes  []*XMLAttributes `json:"attributes,omitempty"`
	Children    []XMLSchema      `json:"children,omitempty"`
	SelfClosing bool             `json:"selfClosing,omitempty"`
}

func (*XMLData) String

func (x *XMLData) String() string

func (*XMLData) UnmarshalJSON

func (x *XMLData) UnmarshalJSON(b []byte) error

func (*XMLData) Validate

func (x *XMLData) Validate() error

type XMLHTTPClient

type XMLHTTPClient struct {
	HTTPClient         *HTTPClient        // underlying HTTP client. Required.
	ErrorPostProcessor ErrorPostProcessor // Errors returned from CRUD methods will go via this method. Optional.
}

XMLHTTPClient is an HTTP client that can parse XML response.

func (*XMLHTTPClient) Get

func (c *XMLHTTPClient) Get(ctx context.Context, url string, headers ...Header) (*XMLHTTPResponse, error)

Get makes a GET request to the given URL and returns the response body as a XML object. If the response is not a 2xx, an error is returned. If the response is a 401, the caller should refresh the access token and retry the request. If errorHandler is nil, then the default error handler is used. If not, the caller can inject their own error handling logic.

func (*XMLHTTPClient) Post

func (c *XMLHTTPClient) Post(ctx context.Context,
	url string, node *xquery.XML, headers ...Header,
) (*XMLHTTPResponse, error)

Post sends XML request and receives XML as a response.

type XMLHTTPResponse

type XMLHTTPResponse struct {

	// Code is the HTTP status code of the response.
	Code int

	// Headers are the HTTP headers of the response.
	Headers http.Header

	// Body is the unmarshalled response body in XML form. Content is the same as bodyBytes
	Body *xquery.XML
	// contains filtered or unexported fields
}

type XMLSchema

type XMLSchema interface {
	String() string
	Validate() error
}

type XMLString

type XMLString string

func (XMLString) String

func (str XMLString) String() string

func (XMLString) Validate

func (str XMLString) Validate() error

Directories

Path Synopsis
nolint:ireturn
nolint:ireturn
Package paramsbuilder provides common parameters used to initialize connectors.
Package paramsbuilder provides common parameters used to initialize connectors.
nolint: ireturn
nolint: ireturn
credscanning
Package credscanning is a wrapper for scanning package.
Package credscanning is a wrapper for scanning package.

Jump to

Keyboard shortcuts

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