Documentation
¶
Overview ¶
Package trueup is the official client for the TrueUp API.
Send TrueUp two ledgers (a supplier statement and your receiving log, your books and the bank feed, invoices and payments) and it pairs every row, then tells you what's only on one side, what was counted twice and where the numbers disagree.
client, err := trueup.NewClient() // reads TRUEUP_API_KEY
result, err := client.Reconcile(ctx, trueup.File("statement.csv"), trueup.File("receiving.csv"), nil)
for _, f := range result.Findings {
fmt.Println(f.Kind, f.Subject, f.Detail)
}
Index ¶
- Constants
- Variables
- type Account
- type Answers
- type Client
- func (c *Client) Account(ctx context.Context) (*Account, error)
- func (c *Client) Plans(ctx context.Context) ([]Plan, error)
- func (c *Client) Reconcile(ctx context.Context, left, right Table, opts *ReconcileOptions) (*ReconcileResult, error)
- func (c *Client) ReconcileFiles(ctx context.Context, files []Table, opts *ReconcileOptions) (*ReconcileResult, error)
- func (c *Client) Usage(ctx context.Context) (*Usage, error)
- type Details
- type Error
- type Finding
- type Option
- type Pair
- type Plan
- type ReconcileOptions
- type ReconcileResult
- type Row
- type Table
- type Usage
- type UsageMetric
Constants ¶
const DefaultBaseURL = "https://trueup-cloud.merchantprotocol.workers.dev"
DefaultBaseURL is the hosted TrueUp API.
const Version = "0.1.0"
Version of this SDK.
Variables ¶
var ( ErrAuthentication = errors.New("authentication") // 401: missing, unknown or revoked API key ErrInvalidRequest = errors.New("invalid request") // 400, 413, 415, 422: the request or the files need fixing ErrNotFound = errors.New("not found") // 404, 405 ErrRateLimited = errors.New("rate limited") // 429 rate_limited ErrQuotaExceeded = errors.New("quota exceeded") // 429 quota_exceeded: retrying won't help ErrServer = errors.New("server error") // 5xx ErrConnection = errors.New("connection") // the API couldn't be reached )
Kinds of error, for errors.Is.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
Team struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"team"`
Plan *struct {
Slug string `json:"slug"`
Name string `json:"name"`
} `json:"plan"`
Key struct {
ID string `json:"id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
} `json:"key"`
}
Account is the team, plan and key behind an API key.
type Answers ¶
type Answers struct {
Same [][2]string `json:"same,omitempty"`
Different [][2]string `json:"different,omitempty"`
}
Answers are decisions a person made about pairs: [left row, right row], e.g. {"statement.csv:row 3", "receiving.csv:row 4"}.
type Client ¶
type Client struct {
BaseURL string
HTTPClient *http.Client
MaxRetries int
// contains filtered or unexported fields
}
Client talks to the TrueUp API. It is safe for concurrent use.
func (*Client) Reconcile ¶
func (c *Client) Reconcile(ctx context.Context, left, right Table, opts *ReconcileOptions) (*ReconcileResult, error)
Reconcile reconciles two tables. left is the side that bills or claims (a statement, your books), right the other side (receiving log, bank feed). opts may be nil. Counts as one analysis.
func (*Client) ReconcileFiles ¶
func (c *Client) ReconcileFiles(ctx context.Context, files []Table, opts *ReconcileOptions) (*ReconcileResult, error)
ReconcileFiles sends two or more files; TrueUp picks the pair to reconcile and which side is which. opts may be nil. One analysis.
type Details ¶
type Details struct {
Model map[string]any `json:"model"`
Weights json.RawMessage `json:"weights"`
Pairs []Pair `json:"pairs"`
}
Details are what the run learned and every pair it made.
type Error ¶
type Error struct {
Status int
Code string
Message string
RetryAfter time.Duration
Body []byte
// contains filtered or unexported fields
}
Error is any error the API returned, or a failure to reach it. Code is the API's error code; branch on it (or use errors.Is with the sentinel kinds below).
type Finding ¶
type Finding struct {
// Kind: phantom, unbilled, duplicate, received_duplicate, qty_mismatch, price_change, amount_mismatch, unsure_pair.
Kind string `json:"kind"`
Label string `json:"label"`
Subject string `json:"subject"`
Detail string `json:"detail"`
// Confidence is how likely the pairing is right; nil for rows with no pair.
Confidence *float64 `json:"confidence"`
Status string `json:"status"`
Amount *float64 `json:"amount"`
Provenance []string `json:"provenance"`
Data map[string]any `json:"data"`
}
Finding is one thing TrueUp found.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithAPIKey ¶
WithAPIKey sets the API key (default: TRUEUP_API_KEY).
func WithBaseURL ¶
WithBaseURL sets the API address (default: TRUEUP_BASE_URL, then the hosted API).
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client (default: 300 s timeout; big ledgers take a while).
func WithMaxRetries ¶
WithMaxRetries sets retries for rate limits, server errors and dropped connections (default 2).
type Pair ¶
type Pair struct {
Left string `json:"left"`
Right string `json:"right"`
Confidence float64 `json:"confidence"`
}
Pair is one pairing of a left row with a right row.
type Plan ¶
type Plan struct {
Slug string `json:"slug"`
Name string `json:"name"`
Description string `json:"description"`
PriceCents int `json:"price_cents"`
Interval string `json:"interval"`
Purchasable bool `json:"purchasable"`
Limits []struct {
Metric string `json:"metric"`
Included int `json:"included"`
HardCap bool `json:"hard_cap"`
OverageMicrosPerUnit *int `json:"overage_micros_per_unit"`
} `json:"limits"`
}
Plan is a plan a team can be on.
type ReconcileOptions ¶
type ReconcileOptions struct {
// Weights is Details.Weights from an earlier result: apply what was learned then instead of learning again.
Weights json.RawMessage
Answers *Answers
}
ReconcileOptions are optional settings for a reconcile call.
type ReconcileResult ¶
type ReconcileResult struct {
Analysis string `json:"analysis"`
Title string `json:"title"`
Headline string `json:"headline"`
Stats map[string]float64 `json:"stats"`
Findings []Finding `json:"findings"`
Details Details `json:"details"`
Inputs []string `json:"inputs"`
Engine string `json:"engine"`
}
ReconcileResult is the answer to a reconcile call.
type Table ¶
type Table struct {
Name string
// contains filtered or unexported fields
}
Table is one table to reconcile: a file, file contents, or rows. Name is how findings refer to its rows ("statement.csv:row 5"). Build one with File, Content or Rows.
func Content ¶
Content is a table from file contents; name's extension says the format (.csv, .tsv, .json, .jsonl).
type Usage ¶
type Usage struct {
Period string `json:"period"`
ResetsAt string `json:"resets_at"`
Metrics []UsageMetric `json:"metrics"`
}
Usage is this month's usage for a team.