adapters

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package adapters holds the clients through which the relay performs effects in other systems. The gateway only calls the addresses it was configured with (EDIGATE_ONEC_URL); nothing in a document or a tool argument chooses an address.

Input: an Effect read from the outbox. Output: the reference the other system gave the effect, or an error. An error that wraps *StatusError carries the HTTP status, which tells a permanent refusal from a temporary fault.

Index

Constants

View Source
const (
	EffectCreateOrder = "onec.create_order"
	EffectCancelOrder = "onec.cancel_order"
	EffectWMSReserve  = "wms.reserve"
	EffectWMSRelease  = "wms.release"
	EffectWMSShip     = "wms.ship"
	EffectSend855     = "edi.send_855"
	EffectSend856     = "edi.send_856"
	EffectSend997     = "edi.send_997" // the acknowledgment of an incoming group; no key, no saga
	EffectEmail       = "notify.email"
)

The effect types of the outbox. The first two are the order and the supplier invoice (mock-1c); the rest come with the sagas: the compensations (cancel, release), the warehouse (mock-wms) and the documents sent to a partner.

View Source
const ReplyToHeader = "Edigate-Reply-To"

ReplyToHeader is the stand header that tells the partner emulator where to post the 997: the public address of the gateway process that sent the document.

Variables

This section is empty.

Functions

func IsSend

func IsSend(effectType string) bool

IsSend reports whether the effect is a document sent to a partner.

Types

type AS2

type AS2 struct {
	// contains filtered or unexported fields
}

AS2 sends interchanges to a partner (here: partner-emulator) with POST <base>/as2. It sends once and returns the synchronous MDN; deciding what a missing or wrong MDN means, and when to repeat, is the relay's job.

func NewAS2

func NewAS2(baseURL string) *AS2

NewAS2 builds the client for the partner at baseURL (EDIGATE_PARTNER_URL).

func (*AS2) Transmit

func (a *AS2) Transmit(ctx context.Context, t Transmission) (Receipt, error)

Transmit posts the interchange. Any answer other than 200 with a readable MDN is an error.

func (*AS2) WithReplyTo

func (a *AS2) WithReplyTo(publicURL string) *AS2

WithReplyTo makes the client send the stand header Edigate-Reply-To (see ReplyToHeader).

type Adapter

type Adapter interface {
	// Apply performs the effect and returns the reference of the other system.
	// A second Apply with the same ExternalID returns the same reference.
	Apply(ctx context.Context, e Effect) (ref string, err error)
	// Exists asks whether an effect of this type with this external id is already there.
	Exists(ctx context.Context, effectType, externalID string) (found bool, ref string, err error)
}

Adapter performs effects in one other system.

type Effect

type Effect struct {
	Type       string
	TenantID   string
	ExternalID string
	Payload    json.RawMessage
}

Effect is one outbox row as an adapter sees it. ExternalID is the idempotency key in hex: the other system uses it to take a repeated delivery only once (I4).

type Mail

type Mail struct {
	// contains filtered or unexported fields
}

Mail is the client of the mail service of the stand (the partner emulator takes the letter at POST /email and answers GET /email?external_id= for a lookup). The gateway sends the template, the address and the order number; it never sends a text.

func NewMail

func NewMail(baseURL string) *Mail

NewMail builds the client for the service at baseURL.

func (*Mail) Apply

func (m *Mail) Apply(ctx context.Context, e Effect) (string, error)

Apply posts the letter. The service takes a repeat with the same external id once.

func (*Mail) Exists

func (m *Mail) Exists(ctx context.Context, effectType, externalID string) (bool, string, error)

Exists asks the service whether the letter with this external id is already there.

func (*Mail) WithReplyTo

func (m *Mail) WithReplyTo(publicURL string) *Mail

WithReplyTo makes the client send the stand header Edigate-Reply-To (see ReplyToHeader).

type Mux

type Mux struct {
	Onec Adapter
	WMS  Adapter
	Mail Adapter
}

Mux gives every effect to the adapter that owns its type: onec.* to the ERP, wms.* to the warehouse and notify.* to the mail service. An adapter that is nil was not configured: the effect fails with a temporary error and is tried again, so that configuring it later is enough.

func (Mux) Apply

func (m Mux) Apply(ctx context.Context, e Effect) (string, error)

Apply performs the effect in the system that owns its type.

func (Mux) Exists

func (m Mux) Exists(ctx context.Context, effectType, externalID string) (bool, string, error)

Exists asks the system that owns the type.

type Onec

type Onec struct {
	// contains filtered or unexported fields
}

Onec is the client of the 1C HTTP service (here: mock-1c). It sends an effect to POST <path> and looks it up with GET <path>?external_id=, where the path depends on the effect type (orders and supplier invoices); an order is cancelled with POST /hs/orders/{external_id}/cancel.

func NewOnec

func NewOnec(baseURL string) *Onec

NewOnec builds the client for the service at baseURL (no trailing slash needed).

func (*Onec) Apply

func (o *Onec) Apply(ctx context.Context, e Effect) (string, error)

Apply performs the effect. The cancel names the order by its own external id (the payload holds it), not by the key of the compensation.

func (*Onec) Exists

func (o *Onec) Exists(ctx context.Context, effectType, externalID string) (bool, string, error)

Exists asks mock-1c whether the effect is there. A cancel is idempotent and is simply sent again, so for it the answer is always no.

type Receipt

type Receipt struct {
	MessageID         string `json:"message_id"`
	OriginalMessageID string `json:"original_message_id"`
	MICSHA256         string `json:"mic_sha256"`
	Disposition       string `json:"disposition"`
}

Receipt is the MDN the partner answers with (the JSON form of wave 2-2).

func (Receipt) Counts

func (r Receipt) Counts(t Transmission) bool

Counts reports whether the receipt is the MDN of this transmission: it names our Message-Id, carries the SHA-256 of the bytes we sent, and says "processed".

type ShipLine

type ShipLine struct {
	SKU  string `json:"sku"`
	Qty  string `json:"qty"`
	Unit string `json:"unit"`
}

ShipLine is one line of a shipment as the warehouse recorded it.

type Shipment

type Shipment struct {
	ExternalID string     `json:"external_id"`
	OrderRef   string     `json:"order_ref"`
	Lines      []ShipLine `json:"lines"`
	SSCC       []string   `json:"sscc"`
}

Shipment is the fact of the warehouse: what left and the SSCC of each line (the same order).

type StatusError

type StatusError struct{ Code int }

StatusError is an answer of the other system with an unexpected HTTP status.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Permanent

func (e *StatusError) Permanent() bool

Permanent reports whether repeating the request cannot help: a 4xx answer other than 408 (timeout) and 429 (too many requests).

type Transmission

type Transmission struct {
	DocID     string `json:"doc_id"`
	MessageID string `json:"message_id"`
	From      string `json:"from"` // AS2-From: the interchange id of the tenant
	To        string `json:"to"`   // AS2-To: the partner
	ISA13     string `json:"isa13"`
	Body      string `json:"body"` // the X12 interchange; printable ASCII, so a string holds it
}

Transmission is the payload of an outbox row of a document sent to a partner. It is written once, when the row is made (control numbers and bytes included), and every repeat of the transmission sends exactly this.

type WMS

type WMS struct {
	// contains filtered or unexported fields
}

WMS is the client of the warehouse service (here: mock-wms): a reservation, its release, and the shipment with the facts (the SSCC of every pack and the quantity that left).

func NewWMS

func NewWMS(baseURL string) *WMS

NewWMS builds the client for the service at baseURL.

func (*WMS) Apply

func (w *WMS) Apply(ctx context.Context, e Effect) (string, error)

Apply performs the effect. A release names the reservation by its own external id.

func (*WMS) Exists

func (w *WMS) Exists(ctx context.Context, effectType, externalID string) (bool, string, error)

Exists asks the warehouse whether the reservation or the shipment is there.

func (*WMS) ShipNow

func (w *WMS) ShipNow(ctx context.Context, tenantID string, payload json.RawMessage) (Shipment, error)

ShipNow ships without an external id and returns what the warehouse recorded, with the SSCC of every line (the answer of POST /shipments carries them). The open tools use it: they have no key, so there is nothing to look the shipment up by afterwards.

func (*WMS) Shipment

func (w *WMS) Shipment(ctx context.Context, externalID string) (Shipment, error)

Shipment reads the shipment with this external id (the key of the step wms.ship in hex).

Jump to

Keyboard shortcuts

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