Documentation
¶
Overview ¶
Package node implements an OBX brand node: the OBX Protocol (read side), the OBX Ingest API (write side), the Node Admin + Portal API used by the shared admin-ui, imports, renditions, exports, webhooks and statistics.
Index ¶
- Constants
- Variables
- func LogHandler(h slog.Handler) slog.Handler
- func RequestID(ctx context.Context) string
- func ValidExternalID(s string) (string, bool)
- type App
- func (a *App) Audit(ctx context.Context, action, targetType, targetID string)
- func (a *App) AuditLog(ctx context.Context, limit int) ([]map[string]any, error)
- func (a *App) Backup(ctx context.Context, dir string) (*BackupManifest, error)
- func (a *App) Changes(ctx context.Context, v *Viewer, cursor string, limit int) (*ChangesPage, *problem.Problem, error)
- func (a *App) Close() error
- func (a *App) CreateIngestToken(ctx context.Context, name string, scopes, brands []string, expiresAt *string) (*ingestToken, string, *problem.Problem)
- func (a *App) Handler() http.Handler
- func (a *App) HasBlob(ctx context.Context, sha string) bool
- func (a *App) ImportErrors(ctx context.Context, jobID string, max int) []string
- func (a *App) ImportLocal(ctx context.Context, li LocalImport) (map[string]any, error)
- func (a *App) LastMails() []SentMail
- func (a *App) NodeID() string
- func (a *App) PersonalData(ctx context.Context, email, retailerID string) (map[string]any, error)
- func (a *App) PortalName(ctx context.Context, lang string) string
- func (a *App) PutBlob(ctx context.Context, r io.Reader, declaredSHA string, limit int64) (*Blob, error)
- func (a *App) PutBlobBytes(ctx context.Context, data []byte) (*Blob, error)
- func (a *App) RenderOriginal(ctx context.Context, sha string) error
- func (a *App) ResetLink(ctx context.Context, email string) (string, error)
- func (a *App) RunJobsNow(ctx context.Context)
- func (a *App) SetDraining()
- func (a *App) SetPassword(ctx context.Context, email, password string) error
- func (a *App) Settings(ctx context.Context) *Settings
- func (a *App) SetupDone(ctx context.Context) bool
- func (a *App) Start()
- func (a *App) Stop()
- func (a *App) WriteOp(ctx context.Context, allowedBrands []string, ...) (*IngestResult, *problem.Problem)
- type Asset
- type AssetData
- type BackupManifest
- type Blob
- type Brand
- type BrandData
- type CareItem
- type Certification
- type Change
- type ChangesPage
- type Color
- type Features
- type Fiber
- type FileRef
- type FootwearMaterials
- type Grant
- type GrantParty
- type ImportRowError
- type IngestRecord
- type IngestResult
- type LiveFile
- type LocalImport
- type LocalizedText
- type Mailer
- type MaterialPart
- type Measurements
- type Product
- type ProductData
- type Provenance
- type Range
- type Rendition
- type Rights
- type SentMail
- type Settings
- type Variant
- type VariantData
- type Viewer
- type WarningDetail
Constants ¶
const ( Software = "obx-node-go" SpecVersion = "0.2.0" OBXVersion = "0.2" )
Software and Version identify this implementation in discovery.
const ( MaxUploadBytes int64 = 100 << 20 MaxObjectBytes int64 = 2 << 30 PartBytes int64 = 8 << 20 MaxBatchOperations = 1000 MaxImportBytes int64 = 2 << 30 )
Limits advertised in IngestInfo (docs/ingest.md §9).
const ( KindBrand = "brand" KindProduct = "product" KindVariant = "variant" KindAsset = "asset" )
Kinds of catalog objects.
Variables ¶
var AllScopes = []string{"catalog:read", "media:read", "media:original", "usage:write"}
AllScopes are the protocol scopes.
var DerivedRenditions = []string{"web", "square", "thumb"}
DerivedRenditions are the renditions derived from the original.
var RenditionNames = []string{"original", "web", "square", "thumb"}
RenditionNames in canonical order.
var SupportedLanguages = []string{"bg", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr", "ga", "hr", "hu", "it", "lt", "lv", "mt", "nl", "nb", "pl", "pt", "ro", "sk", "sl", "sv"}
SupportedLanguages are the UI/e-mail languages.
var Version = "0.2.1-dev"
Version is set at build time (-ldflags "-X .../node.Version=...").
Functions ¶
func LogHandler ¶
LogHandler wraps a slog handler so that every record logged with a request context carries request_id.
func RequestID ¶
RequestID returns the id of the request that ctx belongs to ("" outside a request).
func ValidExternalID ¶
ValidExternalID checks the ExternalId rules (1-200 chars, no control characters, no '/'); the value is trimmed first.
Types ¶
type App ¶
type App struct {
Cfg *config.Config
DB *db.DB
Store blobstore.Store
Keys *secure.Keys
Log *slog.Logger
Mail Mailer
Policy safehttp.Policy
UI fs.FS // admin-ui build (index.html, assets, locales)
// Now can be replaced in tests.
Now func() time.Time
// contains filtered or unexported fields
}
App holds the node's shared state.
func (*App) Backup ¶
Backup writes a consistent copy of the node to dir (which must be empty or missing): the SQLite database as one file (VACUUM INTO, safe while the node runs), the local files and the secret key. Files in a bucket and a PostgreSQL database are not copied; the manifest says so.
func (*App) Changes ¶
func (a *App) Changes(ctx context.Context, v *Viewer, cursor string, limit int) (*ChangesPage, *problem.Problem, error)
Changes returns one feed page for viewer v.
func (*App) CreateIngestToken ¶
func (a *App) CreateIngestToken(ctx context.Context, name string, scopes, brands []string, expiresAt *string) (*ingestToken, string, *problem.Problem)
CreateIngestToken creates a token (admin API and CLI).
func (*App) ImportErrors ¶
ImportErrors returns human-readable problems of an import run.
func (*App) ImportLocal ¶
ImportLocal stages local files, runs the import and returns the ImportRun.
func (*App) PersonalData ¶
PersonalData exports a retailer (id) or an account (e-mail) for the CLI.
func (*App) PortalName ¶
PortalName returns "<Brand> · <local word>" for lang. The word is the brand's own portal_name (language fallback rule) or the glossary word from the vendored admin-ui locale files.
func (*App) PutBlob ¶
func (a *App) PutBlob(ctx context.Context, r io.Reader, declaredSHA string, limit int64) (*Blob, error)
PutBlob stores an uploaded image. declaredSHA (may be "") is verified. Only accepted image types (by magic bytes) are stored.
func (*App) PutBlobBytes ¶
PutBlobBytes stores in-memory bytes (renditions, imports).
func (*App) RenderOriginal ¶
RenderOriginal makes web/square/thumb for an original (idempotent) and updates the assets waiting for them.
func (*App) RunJobsNow ¶
RunJobsNow runs queued jobs synchronously (CLI and tests).
func (*App) SetDraining ¶
func (a *App) SetDraining()
SetDraining marks the node as shutting down: /readyz answers 503 so load balancers stop sending new requests while running ones finish.
func (*App) SetPassword ¶
SetPassword sets a password directly (CLI) and ends all sessions.
func (*App) Start ¶
func (a *App) Start()
Start launches the background workers. With SQLite the node is the only instance, so jobs that were running when the previous process stopped are queued again right away (every job kind is safe to run again).
func (*App) Stop ¶
func (a *App) Stop()
Stop stops the background workers (running jobs finish their step).
func (*App) WriteOp ¶
func (a *App) WriteOp(ctx context.Context, allowedBrands []string, fn func(w *writer) (*IngestResult, *problem.Problem)) (*IngestResult, *problem.Problem)
WriteOp runs one catalog operation in its own transaction. A failed operation is rolled back completely (no change entries).
type Asset ¶
type Asset struct {
ID string `json:"id"`
ExternalID string `json:"external_id"`
ProductID string `json:"product_id"`
BrandID string `json:"brand_id"`
MediaType string `json:"media_type"`
ColorCode *string `json:"color_code"`
VariantIDs []string `json:"variant_ids"`
Role string `json:"role"`
View *string `json:"view"`
Position int `json:"position"`
Filename string `json:"filename"`
AltText LocalizedText `json:"alt_text"`
ContentType string `json:"content_type"`
Width int `json:"width"`
Height int `json:"height"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256"`
Rights Rights `json:"rights"`
Provenance Provenance `json:"provenance"`
Renditions map[string]*Rendition `json:"renditions"`
UpdatedAt string `json:"updated_at"`
}
Asset is the protocol Asset.
type AssetData ¶
type AssetData struct {
ProductExternalID string `json:"product_external_id"`
ColorCode *string `json:"color_code"`
VariantExternalIDs []string `json:"variant_external_ids"`
MediaType string `json:"media_type"`
Role string `json:"role"`
View *string `json:"view"`
Position int `json:"position"`
Filename *string `json:"filename"`
AltText LocalizedText `json:"alt_text"`
Rights map[string]json.RawMessage `json:"rights"`
Provenance map[string]json.RawMessage `json:"provenance"`
Files map[string]FileRef `json:"files"`
}
AssetData is the stored AssetInput (without status). Rights and provenance keep only the fields the brand sent (omitted = node default).
type BackupManifest ¶
type BackupManifest struct {
Format int `json:"format"`
CreatedAt string `json:"created_at"`
NodeGoVersion string `json:"node_go_version"`
SchemaVersion int `json:"schema_version"`
NodeID string `json:"node_id"`
Database string `json:"database"` // "obx.db" or a note
Files string `json:"files"` // "blobs" or a note
FileCount int `json:"file_count"`
SecretKey string `json:"secret_key"` // "secret.key" or a note
SecretFingerprint string `json:"secret_fingerprint"`
}
BackupManifest describes a backup directory made by "node-go backup".
type Blob ¶
type Blob struct {
SHA256 string `json:"sha256"`
Bytes int64 `json:"bytes"`
ContentType string `json:"content_type"`
Width *int `json:"width"`
Height *int `json:"height"`
Created bool `json:"created"`
}
Blob is the Blob schema.
type Brand ¶
type Brand struct {
ID string `json:"id"`
ExternalID string `json:"external_id"`
Name string `json:"name"`
LogoURL *string `json:"logo_url"`
Website *string `json:"website"`
Description LocalizedText `json:"description"`
UpdatedAt string `json:"updated_at"`
}
Brand is the protocol Brand.
type BrandData ¶
type BrandData struct {
Name string `json:"name"`
LogoURL *string `json:"logo_url"`
Website *string `json:"website"`
Description LocalizedText `json:"description"`
}
BrandData is the stored BrandInput (without status).
type CareItem ¶
type CareItem struct {
Code string `json:"code"`
Text LocalizedText `json:"text"`
}
CareItem is one care instruction.
type Certification ¶ added in v0.2.0
type Certification struct {
Scheme string `json:"scheme"`
LicenceNumber *string `json:"licence_number"`
Scope string `json:"scope"`
}
Certification is one voluntary certification the brand states.
type Change ¶
type Change struct {
Seq int64 `json:"seq"`
Type string `json:"type"`
Op string `json:"op"`
ID string `json:"id"`
ExternalID *string `json:"external_id"`
BrandID *string `json:"brand_id"`
ProductID *string `json:"product_id"`
UpdatedAt string `json:"updated_at"`
Data any `json:"data,omitempty"`
Resync *bool `json:"resync,omitempty"`
}
Change is one feed entry.
type ChangesPage ¶
type ChangesPage struct {
Changes []Change `json:"changes"`
NextCursor string `json:"next_cursor"`
HasMore bool `json:"has_more"`
Phase string `json:"phase"`
}
ChangesPage is one page of the feed.
type Color ¶
type Color struct {
Code string `json:"code"`
Name LocalizedText `json:"name"`
SupplierColor *string `json:"supplier_color"`
Family *string `json:"family"`
}
Color of a variant.
type Features ¶ added in v0.2.0
Features are the typed product features (registry keys and other keys, values as decoded from JSON); nil marshals as null.
type Fiber ¶
type Fiber struct {
Fiber string `json:"fiber"`
Percentage float64 `json:"percentage"`
Recycled bool `json:"recycled,omitempty"`
Organic bool `json:"organic,omitempty"`
}
Fiber is one fibre of a material part.
type FileRef ¶
type FileRef struct {
SHA256 string `json:"sha256"`
Width *int `json:"width"`
Height *int `json:"height"`
}
FileRef references a blob in AssetData.files.
type FootwearMaterials ¶ added in v0.2.0
type FootwearMaterials struct {
Upper *string `json:"upper"`
LiningAndSock *string `json:"lining_and_sock"`
OuterSole *string `json:"outer_sole"`
}
FootwearMaterials is the material of the three parts of a shoe (Directive 94/11/EC); responses always include all three parts.
type Grant ¶
type Grant struct {
ID string `json:"id"`
Retailer GrantParty `json:"retailer"`
BrandIDs []string `json:"brand_ids"`
Scopes []string `json:"scopes"`
OriginalAllowed bool `json:"original_allowed"`
Status string `json:"status"`
UpdatedAt string `json:"updated_at"`
}
Grant is the protocol Grant.
type GrantParty ¶
GrantParty names the retailer of a grant.
type ImportRowError ¶
type ImportRowError struct {
File string `json:"file"`
Row *int `json:"row"`
Column *string `json:"column"`
Severity string `json:"severity"`
ObxError string `json:"obx_error"`
Detail string `json:"detail"`
Value *string `json:"value"`
}
ImportRowError is one problem found while importing.
type IngestRecord ¶
type IngestRecord struct {
Kind string `json:"kind"`
ID string `json:"id"`
ExternalID string `json:"external_id"`
Status string `json:"status"`
Visibility string `json:"visibility"`
ETag string `json:"etag"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Data map[string]any `json:"data"`
MissingFiles *[]string `json:"missing_files,omitempty"` // assets only; [] when complete
}
IngestRecord is the GET representation in the ingest API and admin catalog.
type IngestResult ¶
type IngestResult struct {
Index *int `json:"index,omitempty"`
Op string `json:"op"`
Kind string `json:"kind"`
ExternalID string `json:"external_id"`
Result string `json:"result"`
ID *string `json:"id"`
Visibility *string `json:"visibility"`
ETag *string `json:"etag"`
Error any `json:"error"`
Warnings []string `json:"warnings,omitempty"`
// WarningDetails are the warnings with a stable code (label
// completeness); each is also in Warnings as text.
WarningDetails []WarningDetail `json:"warning_details,omitempty"`
}
IngestResult is the result of one ingest write.
type LiveFile ¶
type LiveFile struct {
SHA256 string `json:"sha256"`
ContentType string `json:"content_type"`
Width int `json:"width"`
Height int `json:"height"`
Bytes int64 `json:"bytes"`
}
LiveFile is one resolved file of an asset (stored in assets.live_files).
type LocalImport ¶
type LocalImport struct {
CSV, AssetsCSV, Images, Package string
Mode string
AllowMassUnpublish, DryRun bool
}
LocalImport describes an import from local files (CLI).
type LocalizedText ¶
LocalizedText is text per BCP 47 tag. nil marshals as null.
type Mailer ¶
type Mailer interface {
Send(ctx context.Context, to, subject, body string) error
Configured() bool
}
Mailer sends e-mail.
type MaterialPart ¶
MaterialPart is the composition of one part.
type Measurements ¶ added in v0.2.0
type Measurements struct {
HeightCM *float64 `json:"height_cm,omitempty"`
WidthCM *float64 `json:"width_cm,omitempty"`
DepthCM *float64 `json:"depth_cm,omitempty"`
WeightKG *float64 `json:"weight_kg,omitempty"`
VolumeL *float64 `json:"volume_l,omitempty"`
VolumeExpandedL *float64 `json:"volume_expanded_l,omitempty"`
HandleDropCM *float64 `json:"handle_drop_cm,omitempty"`
StrapLengthCM *Range `json:"strap_length_cm,omitempty"`
LaptopMaxInch *float64 `json:"laptop_max_inch,omitempty"`
HeelHeightCM *float64 `json:"heel_height_cm,omitempty"`
ShaftHeightCM *float64 `json:"shaft_height_cm,omitempty"`
InseamCM *float64 `json:"inseam_cm,omitempty"`
}
Measurements of one variant; nil members are not stated and left out.
func (*Measurements) Cell ¶ added in v0.2.0
func (m *Measurements) Cell(key string) string
Cell returns one measurement as a products.csv cell ("" when not stated).
type Product ¶
type Product struct {
ID string `json:"id"`
ExternalID string `json:"external_id"`
BrandID string `json:"brand_id"`
StyleNumber string `json:"style_number"`
Name LocalizedText `json:"name"`
Description LocalizedText `json:"description"`
ItemType *string `json:"item_type"`
ItemSubtype *string `json:"item_subtype"`
GPCBrick *string `json:"gpc_brick"`
TargetGroup *string `json:"target_group"`
Season *string `json:"season"`
Collection *string `json:"collection"`
Materials []MaterialPart `json:"materials"`
ContainsAnimalOrigin *bool `json:"contains_animal_origin"`
FootwearMaterials *FootwearMaterials `json:"footwear_materials"`
Care []CareItem `json:"care"`
CountryOfOrigin *string `json:"country_of_origin"`
Certifications []Certification `json:"certifications"`
DPPURL *string `json:"dpp_url"`
Features Features `json:"features"`
Attributes map[string]any `json:"attributes"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Variants *[]Variant `json:"variants,omitempty"`
Assets *[]Asset `json:"assets,omitempty"`
}
Product is the protocol Product (Variants/Assets set = ProductDetail).
type ProductData ¶
type ProductData struct {
BrandExternalID string `json:"brand_external_id"`
StyleNumber string `json:"style_number"`
Name LocalizedText `json:"name"`
Description LocalizedText `json:"description"`
ItemType *string `json:"item_type"`
ItemSubtype *string `json:"item_subtype"`
GPCBrick *string `json:"gpc_brick"`
TargetGroup *string `json:"target_group"`
Season *string `json:"season"`
Collection *string `json:"collection"`
Materials []MaterialPart `json:"materials"`
ContainsAnimalOrigin *bool `json:"contains_animal_origin"`
FootwearMaterials *FootwearMaterials `json:"footwear_materials"`
Care []CareItem `json:"care"`
CountryOfOrigin *string `json:"country_of_origin"`
Certifications []Certification `json:"certifications"`
DPPURL *string `json:"dpp_url"`
Features Features `json:"features"`
Attributes map[string]any `json:"attributes"`
}
ProductData is the stored ProductInput (without status).
type Provenance ¶
type Provenance struct {
AIGenerated bool `json:"ai_generated"`
AIEdited bool `json:"ai_edited"`
Source string `json:"source"`
C2PA string `json:"c2pa"`
C2PAManifestURL *string `json:"c2pa_manifest_url"`
Generator *string `json:"generator"`
}
Provenance is the effective provenance object.
type Rendition ¶
type Rendition struct {
Name string `json:"name"`
URL string `json:"url"`
URLExpiresAt *string `json:"url_expires_at"`
ContentType string `json:"content_type"`
Width int `json:"width"`
Height int `json:"height"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256"`
}
Rendition is one downloadable file of an asset.
type Rights ¶
type Rights struct {
License string `json:"license"`
LicenseText *string `json:"license_text"`
Channels []string `json:"channels"`
Territories []string `json:"territories"`
EmbargoUntil *string `json:"embargo_until"`
ExpiresAt *string `json:"expires_at"`
Credit *string `json:"credit"`
ModelRelease *bool `json:"model_release"`
}
Rights is the effective rights object.
func DefaultRights ¶
func DefaultRights() Rights
DefaultRights are the protocol default rights (docs/protocol.md §5.6).
type SentMail ¶
type SentMail struct{ To, Subject, Body string }
SentMail is a mail captured by the log driver (tests).
type Settings ¶
type Settings struct {
Company struct {
Name string `json:"name"`
Website *string `json:"website"`
ContactEmail *string `json:"contact_email"`
Country *string `json:"country"`
} `json:"company"`
Branding struct {
DisplayName string `json:"display_name"`
LogoURL *string `json:"logo_url"`
AccentColor *string `json:"accent_color"`
WelcomeText LocalizedText `json:"welcome_text"`
// PortalName overrides the local word in "<Brand> · <local word>",
// per language (optional; same shape as admin-ui expects).
PortalName LocalizedText `json:"portal_name"`
} `json:"branding"`
Portal struct {
AccessRequestsEnabled bool `json:"access_requests_enabled"`
AllowOriginalDownload bool `json:"allow_original_download"`
AllowArticleDataExport bool `json:"allow_article_data_export"`
RetailerAPISelfService bool `json:"retailer_api_self_service"`
Languages []string `json:"languages"`
DefaultLanguage string `json:"default_language"`
} `json:"portal"`
Defaults struct {
Rights Rights `json:"rights"`
IngestStatus string `json:"ingest_status"`
} `json:"defaults"`
// Retention of personal and usage data, in days (the same settings as
// the other OBX portals; docs/operations.md#personal-data-gdpr).
Retention struct {
DownloadEventsDays int `json:"download_events_days"`
AuditLogDays int `json:"audit_log_days"`
AccessRequestsDays int `json:"access_requests_days"`
} `json:"retention"`
// LogoSHA is the blob hash of the uploaded logo (internal).
LogoSHA string `json:"logo_sha,omitempty"`
// LogoType is the logo media type (internal).
LogoType string `json:"logo_type,omitempty"`
}
Settings is the brand's node configuration (admin Settings, minus the read-only `node` facts which are computed).
func (*Settings) ContentLanguages ¶
Languages returns the content languages (first = default).
type Variant ¶
type Variant struct {
ID string `json:"id"`
ExternalID string `json:"external_id"`
ProductID string `json:"product_id"`
BrandID string `json:"brand_id"`
GTIN *string `json:"gtin"`
GTINOriginal *string `json:"gtin_original"`
SKU *string `json:"sku"`
Color Color `json:"color"`
Size *string `json:"size"`
SizeLength *string `json:"size_length"`
SizeSystem *string `json:"size_system"`
Measurements *Measurements `json:"measurements"`
UpdatedAt string `json:"updated_at"`
}
Variant is the protocol Variant.
type VariantData ¶
type VariantData struct {
ProductExternalID string `json:"product_external_id"`
GTIN *string `json:"gtin"`
SKU *string `json:"sku"`
Color Color `json:"color"`
Size *string `json:"size"`
SizeLength *string `json:"size_length"`
SizeSystem *string `json:"size_system"`
Measurements *Measurements `json:"measurements"`
}
VariantData is the stored VariantInput (without status).
type Viewer ¶
type Viewer struct {
Kind string // client | user | admin
RetailerID string
RetailerName string
BrandIDs []string // nil = all published brands
OriginalAllowed bool
Scopes map[string]bool
ClientRowID string
ClientName string
UserID string
UserName string
Language string
}
Viewer is whoever reads the catalog: a retailer's API client, a retailer user in the portal, or a brand admin previewing the portal.
type WarningDetail ¶ added in v0.2.0
type WarningDetail struct {
Code string `json:"code"`
Pointer *string `json:"pointer"`
Detail string `json:"detail"`
// contains filtered or unexported fields
}
WarningDetail is a warning with a stable code (IngestResult.warning_details).
Source Files
¶
- access.go
- admin_catalog.go
- admin_people.go
- admin_session.go
- admin_settings.go
- app.go
- article.go
- audit.go
- backup.go
- blobs.go
- catalog_recompute.go
- catalog_rows.go
- catalog_write.go
- cli.go
- exports.go
- feed.go
- httputil.go
- import_http.go
- imports.go
- ingest.go
- jobs.go
- mail.go
- metrics.go
- ops.go
- personal.go
- portal.go
- portal_downloads.go
- protocol.go
- protocol_auth.go
- ratelimit.go
- reads.go
- server.go
- sessions.go
- settings.go
- sources.go
- sources_fetch.go
- stats.go
- types.go
- upgrade.go
- uploads.go
- webhooks.go
- writes.go