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
- func IsSend(effectType string) bool
- type AS2
- type Adapter
- type Effect
- type Mail
- type Mux
- type Onec
- type Receipt
- type ShipLine
- type Shipment
- type StatusError
- type Transmission
- type WMS
- func (w *WMS) Apply(ctx context.Context, e Effect) (string, error)
- func (w *WMS) Exists(ctx context.Context, effectType, externalID string) (bool, string, error)
- func (w *WMS) ShipNow(ctx context.Context, tenantID string, payload json.RawMessage) (Shipment, error)
- func (w *WMS) Shipment(ctx context.Context, externalID string) (Shipment, error)
Constants ¶
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.
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 ¶
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 (*AS2) Transmit ¶
Transmit posts the interchange. Any answer other than 200 with a readable MDN is an error.
func (*AS2) WithReplyTo ¶
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 (*Mail) Apply ¶
Apply posts the letter. The service takes a repeat with the same external id once.
func (*Mail) Exists ¶
Exists asks the service whether the letter with this external id is already there.
func (*Mail) WithReplyTo ¶
WithReplyTo makes the client send the stand header Edigate-Reply-To (see ReplyToHeader).
type Mux ¶
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.
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.
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 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 (*WMS) Apply ¶
Apply performs the effect. A release names the reservation by its own external id.
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.