cli

package
v0.205.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package cli contains the functionality for the GOBL CLI

Index

Constants

View Source
const (
	StatusBadRequest          int = 400
	StatusConflict            int = 409
	StatusUnprocessableEntity int = 422
)

Status codes used in the CLI that map to HTTP status codes

Variables

This section is empty.

Functions

func Build

func Build(ctx context.Context, opts *BuildOptions) (any, error)

Build builds and validates GOBL data. Only structured errors are returned, which is a break from regular Go convention and replicated on all the main internal CLI functions. The object is to ensure that errors are always structured in a consistent manner.

func Bulk

func Bulk(ctx context.Context, opts *BulkOptions) <-chan *BulkResponse

Bulk processes a stream of bulk requests.

func Correct

func Correct(ctx context.Context, opts *CorrectOptions) (interface{}, error)

Correct takes a base document as input and builds a corrective document for the output. If the "ShowOptions" boolean is true, we'll attempt to determine what options are available.

func FindType

func FindType(term string) schema.ID

FindType can be used to match a partial schema name with a complete schema ID.

func Replicate

func Replicate(ctx context.Context, opts *ReplicateOptions) (interface{}, error)

Replicate takes a base document as input and builds a replicated document for the output.

func Sign

func Sign(ctx context.Context, opts *SignOptions) (*gobl.Envelope, error)

Sign parses a GOBL document into an envelope, performs calculations, validates it, and finally signs its headers. The parsed envelope *must* be a draft, or else an error is returned.

func Validate

func Validate(ctx context.Context, r io.Reader) error

Validate asserts the contents of the envelope and document are correct.

func Verify

func Verify(ctx context.Context, in io.Reader, key *dsig.PublicKey) error

Verify reads a GOBL document from in, and returns an error if there are any validation errors.

Types

type BuildOptions

type BuildOptions struct {
	*ParseOptions
}

BuildOptions are the options used for building and validating GOBL data.

type BuildRequest

type BuildRequest struct {
	Template []byte `json:"template"`
	Data     []byte `json:"data"`
	DocType  string `json:"type"`
	Envelop  bool   `json:"envelop"`
}

BuildRequest is the payload for a build request.

type BulkOptions

type BulkOptions struct {
	// In is the input stream of requests
	In io.Reader
	// DefaultPrivateKey is the default private key to use with sign requests
	DefaultPrivateKey *dsig.PrivateKey
}

BulkOptions are the options used for processing a stream of bulk requests.

type BulkRequest

type BulkRequest struct {
	// Action is the action to perform on the payload.
	Action string `json:"action"`
	// ReqID is an opaque request ID, which is returned with the associated
	// response.
	ReqID string `json:"req_id"`
	// Payload is the payload upon which to perform the action.
	Payload json.RawMessage `json:"payload"`
	// When true, responses are indented for easier human consumption
	Indent bool `json:"indent"`
}

BulkRequest represents a single request in the stream of bulk requests.

type BulkResponse

type BulkResponse struct {
	// ReqID is an exact copy of the value provided in the request, if any.
	ReqID string `json:"req_id,omitempty"`
	// SeqID is the sequence ID of the request this response correspond to,
	// starting at 1.
	SeqID int64 `json:"seq_id"`
	// Payload is the response payload.
	Payload json.RawMessage `json:"payload,omitempty"`
	// Error represents an error processing a request item.
	Error *Error `json:"error"`
	// IsFinal will be true once the end of the request input stream has been
	// reached, or an unrecoverable error has occurred.
	IsFinal bool `json:"is_final"`
}

BulkResponse represents a single response in the stream of bulk responses.

type CorrectOptions

type CorrectOptions struct {
	// we don't need all of the parse options
	*ParseOptions
	OptionsSchema bool
	Credit        bool
	Debit         bool
	Date          cal.Date
	Data          []byte // raw json of correction options
}

CorrectOptions define all the basic options required to build a corrective document from the input.

type CorrectRequest

type CorrectRequest struct {
	Data    []byte `json:"data"`
	Options []byte `json:"options"`
	Schema  bool   `json:"schema"`
}

CorrectRequest is the payload used to generate a corrected document. If the schema option is true, the options data is ignored.

type Error

type Error struct {
	Code    int              `json:"code"`             // HTTP status code
	Key     cbc.Key          `json:"key,omitempty"`    // For GOBL errors
	Fields  gobl.FieldErrors `json:"fields,omitempty"` // Structured error messages for fields
	Message string           `json:"message,omitempty"`
}

Error wraps around around any messages generated by the cli and attempts to provide a structured output that can be interpreted.

func (*Error) Error

func (e *Error) Error() string

Error provides a string representation of the error. This should only really be used for testing purposes.

type KeygenResponse

type KeygenResponse struct {
	Private *dsig.PrivateKey `json:"private"`
	Public  *dsig.PublicKey  `json:"public"`
}

KeygenResponse is the payload for a key generation response.

type ParseOptions

type ParseOptions struct {
	Template  io.Reader
	Input     io.Reader
	DocType   string
	SetYAML   map[string]string
	SetString map[string]string
	SetFile   map[string]string

	// When set to `true`, the parsed data is wrapped in an envelope (if needed).
	Envelop bool
}

ParseOptions are the options used for parsing incoming GOBL data.

type RegimeRequest

type RegimeRequest struct {
	Code string `json:"code"`
}

RegimeRequest defines a body used to request the definition of a Tax Regime.

type ReplicateOptions

type ReplicateOptions struct {
	*ParseOptions
}

ReplicateOptions define all the basic options required to build a replicated document from the input.

type ReplicateRequest

type ReplicateRequest struct {
	Data []byte `json:"data"`
}

ReplicateRequest defines the payload used to generate a replicated document.

type SchemaRequest

type SchemaRequest struct {
	Path string `json:"path"`
}

SchemaRequest defines a body used to request a specific JSON schema

type SignOptions

type SignOptions struct {
	*ParseOptions
	PrivateKey *dsig.PrivateKey
}

SignOptions are the options used for signing a GOBL document.

type SignRequest

type SignRequest struct {
	Template   []byte           `json:"template"`
	Data       []byte           `json:"data"`
	PrivateKey *dsig.PrivateKey `json:"privatekey"`
	DocType    string           `json:"type"`
	Envelop    bool             `json:"envelop"`
}

SignRequest is the payload for a sign request.

type ValidateRequest

type ValidateRequest struct {
	Data []byte `json:"data"`
}

ValidateRequest is the payload for a validate request.

type ValidateResponse

type ValidateResponse struct {
	OK bool `json:"ok"`
}

ValidateResponse is the response to a validate request.

type VerifyRequest

type VerifyRequest struct {
	Data      []byte          `json:"data"`
	PublicKey *dsig.PublicKey `json:"publickey"`
}

VerifyRequest is the payload for a verification request.

type VerifyResponse

type VerifyResponse struct {
	OK bool `json:"ok"`
}

VerifyResponse is the response to a verification request.

Jump to

Keyboard shortcuts

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