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 AuditDetails
- type AuditOptions
- type AuditResult
- type Client
- func (c *Client) Account(ctx context.Context) (*Account, error)
- func (c *Client) AllRuns(ctx context.Context, fn func(Run) bool) error
- func (c *Client) Audit(ctx context.Context, files []Table, opts *AuditOptions) (*AuditResult, error)
- func (c *Client) AuditStored(ctx context.Context, fileIDs []string, model string) (*AuditResult, error)
- func (c *Client) CreateModel(ctx context.Context, runID, name string) (string, error)
- func (c *Client) DeleteFile(ctx context.Context, id string) error
- func (c *Client) DeleteModel(ctx context.Context, id string) error
- func (c *Client) Estimate(ctx context.Context, files []Table, opts *EstimateOptions) (*EstimateResult, error)
- func (c *Client) EstimateStored(ctx context.Context, fileIDs []string, model string) (*EstimateResult, error)
- func (c *Client) FileContent(ctx context.Context, id string) ([]byte, error)
- func (c *Client) GetFile(ctx context.Context, id string) (*StoredFile, error)
- func (c *Client) GetModel(ctx context.Context, id string) (*Model, error)
- func (c *Client) GetRun(ctx context.Context, id string) (*RunDetail, error)
- func (c *Client) ListFiles(ctx context.Context) ([]StoredFile, error)
- func (c *Client) ListModels(ctx context.Context) ([]Model, error)
- func (c *Client) ListRuns(ctx context.Context, limit int, before string) (*RunPage, error)
- func (c *Client) Match(ctx context.Context, left, right Table, opts *MatchOptions) (*MatchResult, error)
- func (c *Client) MatchFiles(ctx context.Context, files []Table, opts *MatchOptions) (*MatchResult, error)
- func (c *Client) MatchStored(ctx context.Context, in StoredInput, model string) (*MatchResult, 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) ReconcileStored(ctx context.Context, in StoredInput, opts *StoredOptions) (*StoredResult, error)
- func (c *Client) UploadFiles(ctx context.Context, files ...Table) ([]StoredFile, error)
- func (c *Client) Usage(ctx context.Context) (*Usage, error)
- type Details
- type Error
- type EstimateDetails
- type EstimateOptions
- type EstimateResult
- type Finding
- type MatchDetails
- type MatchOptions
- type MatchPair
- type MatchResult
- type Model
- type Option
- type Pair
- type Plan
- type ReconcileOptions
- type ReconcileResult
- type Row
- type Run
- type RunDetail
- type RunPage
- type StoredFile
- type StoredInput
- type StoredOptions
- type StoredResult
- type Table
- type Usage
- type UsageMetric
Constants ¶
const DefaultBaseURL = "https://trueup-cloud.merchantprotocol.workers.dev"
DefaultBaseURL is the hosted TrueUp API.
const Version = "0.5.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 AuditDetails ¶ added in v0.4.0
type AuditDetails struct {
Laws []struct {
Scope string `json:"scope"`
Law string `json:"law"`
Held string `json:"held"`
} `json:"laws"`
Model struct {
Learned bool `json:"learned"`
} `json:"model"`
// Weights: pass back as AuditOptions.Weights to check new documents against the same laws.
Weights json.RawMessage `json:"weights"`
}
AuditDetails are the laws learned (or applied) and what to pass back to apply them again.
type AuditOptions ¶ added in v0.4.0
type AuditOptions struct {
Weights json.RawMessage
}
AuditOptions are optional settings for an audit call.
type AuditResult ¶ added in v0.4.0
type AuditResult struct {
Analysis string `json:"analysis"`
Title string `json:"title"`
Headline string `json:"headline"`
Stats map[string]float64 `json:"stats"`
// Findings: Kind is arithmetic (the numbers break a law; Amount is how far off) or duplicate_row.
Findings []Finding `json:"findings"`
Details AuditDetails `json:"details"`
Inputs []string `json:"inputs"`
Engine string `json:"engine"`
RunID string `json:"run_id"`
}
AuditResult is the answer to an audit call: documents (Analysis "audit") or a table's rows ("table-audit").
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) AllRuns ¶ added in v0.2.0
AllRuns calls fn for every run, newest first, fetching page after page. Return false from fn to stop.
func (*Client) Audit ¶ added in v0.4.0
func (c *Client) Audit(ctx context.Context, files []Table, opts *AuditOptions) (*AuditResult, error)
Audit finds what doesn't add up. Text documents (invoices, statements, 4 or more of a kind): TrueUp learns the arithmetic each kind obeys and flags the ones that break it. One table: the same for its rows, plus repeated rows. opts may be nil. One analysis.
func (*Client) AuditStored ¶ added in v0.4.0
func (c *Client) AuditStored(ctx context.Context, fileIDs []string, model string) (*AuditResult, error)
AuditStored audits files already stored in the team, by id. model (a saved audit model id) may be "".
func (*Client) CreateModel ¶ added in v0.2.0
CreateModel saves what a run learned as a model and returns the model's id.
func (*Client) DeleteFile ¶ added in v0.2.0
DeleteFile deletes a stored file.
func (*Client) DeleteModel ¶ added in v0.2.0
DeleteModel deletes a saved model.
func (*Client) Estimate ¶ added in v0.5.0
func (c *Client) Estimate(ctx context.Context, files []Table, opts *EstimateOptions) (*EstimateResult, error)
Estimate prices a new job from past estimates: a domain file for the trade (.tu), at least 3 past estimates in any format, and one request describing the new job; or, with opts.Weights, just the request. One analysis.
func (*Client) EstimateStored ¶ added in v0.5.0
func (c *Client) EstimateStored(ctx context.Context, fileIDs []string, model string) (*EstimateResult, error)
EstimateStored prices from files already stored in the team, by id. model (a saved estimate model id) may be "".
func (*Client) FileContent ¶ added in v0.2.0
FileContent returns a stored file's bytes, exactly as uploaded.
func (*Client) ListFiles ¶ added in v0.2.0
func (c *Client) ListFiles(ctx context.Context) ([]StoredFile, error)
ListFiles returns the team's stored files.
func (*Client) ListModels ¶ added in v0.2.0
ListModels returns the team's saved models.
func (*Client) ListRuns ¶ added in v0.2.0
ListRuns returns one page of runs on stored files, newest first. limit is 1-100 (0 for the default of 100); before is a run id ("" for the newest).
func (*Client) Match ¶ added in v0.3.0
func (c *Client) Match(ctx context.Context, left, right Table, opts *MatchOptions) (*MatchResult, error)
Match pairs the records of two lists that describe the same things in different words (two catalogs, a price book and an invoice): each record on left (the list to go through) with its counterpart on right (the list to search), or reports it has none. opts may be nil. One analysis.
func (*Client) MatchFiles ¶ added in v0.3.0
func (c *Client) MatchFiles(ctx context.Context, files []Table, opts *MatchOptions) (*MatchResult, error)
MatchFiles sends two or more lists; TrueUp picks the pair to match and puts the shorter on the left. opts may be nil. One analysis.
func (*Client) MatchStored ¶ added in v0.3.0
func (c *Client) MatchStored(ctx context.Context, in StoredInput, model string) (*MatchResult, error)
MatchStored matches lists already stored in the team, by id. model (a saved match model id) may be "". The run is kept: its id is RunID. One analysis.
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.
func (*Client) ReconcileStored ¶ added in v0.2.0
func (c *Client) ReconcileStored(ctx context.Context, in StoredInput, opts *StoredOptions) (*StoredResult, error)
ReconcileStored reconciles files already stored in the team, by id. The run is kept: its id is RunID. opts may be nil. One analysis.
func (*Client) UploadFiles ¶ added in v0.2.0
UploadFiles stores one or more files in the team. Each comes back with its ID, Rows, Columns and Roles.
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 EstimateDetails ¶ added in v0.5.0
type EstimateDetails struct {
Scope []struct {
Category string `json:"category"`
Include bool `json:"include"`
Confidence float64 `json:"confidence"`
Why string `json:"why"`
} `json:"scope"`
Total map[string]any `json:"total"`
Model struct {
Learned bool `json:"learned"`
} `json:"model"`
// Weights: the trade and its labeled past estimates; pass back as EstimateOptions.Weights with just a request.
Weights json.RawMessage `json:"weights"`
}
EstimateDetails are the job's scope, its total, and what was learned.
type EstimateOptions ¶ added in v0.5.0
type EstimateOptions struct {
Weights json.RawMessage
}
EstimateOptions are optional settings for an estimate call.
type EstimateResult ¶ added in v0.5.0
type EstimateResult struct {
Analysis string `json:"analysis"`
Title string `json:"title"`
Headline string `json:"headline"`
// Stats: total, low, high (the 80% range), categories priced, past estimates, ...
Stats map[string]float64 `json:"stats"`
// Findings: Kind "priced_line" is one cost category (Amount is its price); status "unsure" is for a person.
Findings []Finding `json:"findings"`
Details EstimateDetails `json:"details"`
Inputs []string `json:"inputs"`
Engine string `json:"engine"`
RunID string `json:"run_id"`
}
EstimateResult is the answer to an estimate call: the new job priced part by part, with an 80% range.
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 MatchDetails ¶ added in v0.3.0
type MatchDetails struct {
Columns struct {
Left map[string]string `json:"left"`
Right map[string]string `json:"right"`
} `json:"columns"`
// Pairs are [left id, right id, confidence].
Pairs []MatchPair `json:"pairs"`
Model struct {
Learned bool `json:"learned"`
} `json:"model"`
// Weights: pass back as MatchOptions.Weights to match the same way without learning.
Weights json.RawMessage `json:"weights"`
}
MatchDetails are how the columns lined up, every pair, and what was learned.
type MatchOptions ¶ added in v0.3.0
type MatchOptions struct {
// Weights is Details.Weights from an earlier match: apply what was learned then instead of learning again.
Weights json.RawMessage
}
MatchOptions are optional settings for a match call.
type MatchPair ¶ added in v0.3.0
MatchPair is one pair: the left record's id, the right record's id, and the confidence.
func (*MatchPair) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON reads a pair from the API's [left id, right id, confidence].
type MatchResult ¶ added in v0.3.0
type MatchResult struct {
Analysis string `json:"analysis"`
Title string `json:"title"`
Headline string `json:"headline"`
Stats map[string]float64 `json:"stats"`
// Findings: Kind is match, unsure_match (a person should check), only_left or only_right.
Findings []Finding `json:"findings"`
Details MatchDetails `json:"details"`
Inputs []string `json:"inputs"`
Engine string `json:"engine"`
// RunID is the kept run, for MatchStored.
RunID string `json:"run_id"`
}
MatchResult is the answer to a match call.
type Model ¶ added in v0.2.0
type Model struct {
ID string `json:"id"`
Name string `json:"name"`
Analysis string `json:"analysis"`
SourceRunID *string `json:"source_run_id"`
CreatedAt string `json:"created_at"`
// Weights is set only by GetModel.
Weights json.RawMessage `json:"weights,omitempty"`
}
Model is a saved model: what a run learned, reusable on next month's files.
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 Run ¶ added in v0.2.0
type Run struct {
ID string `json:"id"`
Analysis string `json:"analysis"`
// Status is "done" or "failed".
Status string `json:"status"`
// Via is "api" or "portal".
Via string `json:"via"`
Inputs []string `json:"inputs"`
Model *struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"model"`
Headline *string `json:"headline"`
Stats map[string]float64 `json:"stats"`
// Findings is how many findings the run has.
Findings *int `json:"findings"`
Error *string `json:"error"`
CreatedAt string `json:"created_at"`
}
Run is a run on stored files, from the API or the dashboard.
type RunDetail ¶ added in v0.2.0
type RunDetail struct {
Run Run `json:"run"`
Result *ReconcileResult `json:"result"`
}
RunDetail is one run and its full result (nil if the run failed).
type StoredFile ¶ added in v0.2.0
type StoredFile struct {
ID string `json:"id"`
Name string `json:"name"`
Size int64 `json:"size"`
// Kind is "table" or "document".
Kind string `json:"kind"`
Rows *int `json:"rows"`
Columns []string `json:"columns"`
// Roles is what TrueUp read each column as: "date", "number", "text", ...
Roles map[string]string `json:"roles"`
CreatedAt string `json:"created_at"`
}
StoredFile is a file stored in the team (uploaded through the API or the dashboard).
type StoredInput ¶ added in v0.2.0
StoredInput names stored files by id: LeftFileID and RightFileID, or FileIDs for TrueUp to pick the pair.
type StoredOptions ¶ added in v0.2.0
type StoredOptions struct {
// Model is a saved model id: apply what it learned instead of learning again.
Model string
Answers *Answers
}
StoredOptions are optional settings for ReconcileStored.
type StoredResult ¶ added in v0.2.0
type StoredResult struct {
ReconcileResult
RunID string `json:"run_id"`
}
StoredResult is a reconcile result on stored files, with the id of the run that was kept.
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.