medusajs

package module
v0.0.0-...-2808cb5 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 9 Imported by: 0

README

medusajs

Go Reference Go Report Card

go get git.gorbe.io/go/medusajs@latest

Get the latest commit (if Go module proxy is not updated):

go get "git.gorbe.io/go/medusajs@$(curl -s 'https://git.gorbe.io/api/v1/repos/go/medusajs/commits' | jq -r '.[0].sha')"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	ID                string                     `json:"id,omitempty"`
	AddressName       string                     `json:"address_name,omitempty"`
	IsDefaultShipping bool                       `json:"is_default_shipping,omitempty"`
	IsDefaultBilling  bool                       `json:"is_default_billing,omitempty"`
	CustomerID        string                     `json:"customer_id,omitempty"`
	Company           string                     `json:"company,omitempty"`
	FirstName         string                     `json:"first_name,omitempty"`
	LastName          string                     `json:"last_name,omitempty"`
	Address1          string                     `json:"address_1,omitempty"`
	Address2          string                     `json:"address_2,omitempty"`
	City              string                     `json:"city,omitempty"`
	CountryCode       string                     `json:"country_code,omitempty"`
	Province          string                     `json:"province,omitempty"`
	PostalCode        string                     `json:"postal_code,omitempty"`
	Phone             string                     `json:"phone,omitempty"`
	Metadata          map[string]json.RawMessage `json:"metadata,omitempty"`
	CreatedAt         *time.Time                 `json:"created_at,omitempty"`
	UpdatedAt         *time.Time                 `json:"updated_at,omitempty"`
}

type Admin

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

func NewAdmin

func NewAdmin(backendurl string) *Admin

func (*Admin) GetCustomerByEmail

func (a *Admin) GetCustomerByEmail(email string) (*Customer, error)

GetCustomerByEmail returns the customer with the given email.

If no customer found, returns nil.

func (*Admin) ListCustomers

func (a *Admin) ListCustomers() ([]Customer, error)

func (*Admin) Login

func (a *Admin) Login(email string, password string) error

func (*Admin) UpdateCustomer

func (a *Admin) UpdateCustomer(id string, customer *Customer) error

UpdateCustomer updates a customer's details wth id id.

The API returns the customer's object which will be set to customer.

type Client

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

func NewClient

func NewClient(url string) *Client

NewClient creates a new Client.

func (*Client) Get

func (c *Client) Get(path string) (int, []byte, error)

Get do a HTTP GET request to the backend url + path.

Returns the response status code and the body bytes.

func (*Client) ListCustomers

func (c *Client) ListCustomers(path string, params url.Values) ([]Customer, error)

func (*Client) Login

func (c *Client) Login(endpoint string, email string, password string) error

Login obtains a JWT token to send authenticated requests with ObtainJWTToken.

func (*Client) Post

func (c *Client) Post(path string, v any) (int, []byte, error)

Post do a HTTP POST request to the backend url + path.

The JSON encoded v is set to request body.

Returns the response status code and the body bytes.

func (*Client) PostCustomer

func (c *Client) PostCustomer(path string, customer *Customer) error

PostCustomer creates or updates a customer's details based on the API endpoint path.

The API returns the customer's object which will be used to overwrite the given customer arg.

func (*Client) SetPublishableAPIKey

func (c *Client) SetPublishableAPIKey(k *PublishableAPIKey)

type Customer

type Customer struct {
	ID                       string            `json:"id,omitempty"`
	HasAccount               bool              `json:"has_account,omitempty"`
	Groups                   []Group           `json:"groups,omitempty"`
	Email                    string            `json:"email,omitempty"`
	DefaultBillingAddressID  string            `json:"default_billing_address_id,omitempty"`
	DefaultShippingAddressID string            `json:"default_shipping_address_id,omitempty"`
	CompanyName              string            `json:"company_name,omitempty"`
	FirstName                string            `json:"first_name,omitempty"`
	LastName                 string            `json:"last_name,omitempty"`
	Addresses                []Address         `json:"addresses,omitempty"`
	Phone                    string            `json:"phone,omitempty"`
	Metadata                 map[string]string `json:"metadata,omitempty"`
	CreatedBy                string            `json:"created_by,omitempty"`
	CreatedAt                *time.Time        `json:"created_at,omitempty"`
	UpdatedAt                *time.Time        `json:"updated_at,omitempty"`
	DeletedAt                *time.Time        `json:"deleted_at,omitempty"`
}

func (*Customer) AddMetadata

func (c *Customer) AddMetadata(key string, value string)

AddMetadata adds a key/value to the Metadata field.

type Group

type Group struct {
	ID        string                     `json:"id,omitempty"`
	Name      string                     `json:"name,omitempty"`
	Customers []struct{}                 `json:"customers,omitempty"`
	Metadata  map[string]json.RawMessage `json:"metadata,omitempty"`
	CreatedAt *time.Time                 `json:"created_at,omitempty"`
	UpdatedAt *time.Time                 `json:"updated_at,omitempty"`
}

type JWTToken

type JWTToken struct {
	Email    string `json:"email"`
	Password string `json:"password"`
	Token    string `json:"token"`
}

func ObtainJWTToken

func ObtainJWTToken(uri string, email string, password string) (*JWTToken, error)

ObtainJWTToken obtains a JWT token from path with the given credentials.

func (*JWTToken) SetHeader

func (t *JWTToken) SetHeader(r *http.Request)

SetHeader sets the Authorization header for request r.

Example header:

Authorization: Bearer {token}

type PublishableAPIKey

type PublishableAPIKey string

func NewPublishableAPIKey

func NewPublishableAPIKey(k string) *PublishableAPIKey

func (PublishableAPIKey) SetHeader

func (k PublishableAPIKey) SetHeader(r *http.Request)

func (PublishableAPIKey) String

func (k PublishableAPIKey) String() string

type Store

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

func NewStore

func NewStore(url string) *Store

func (*Store) Login

func (s *Store) Login(email string, password string) error

func (*Store) RegisterCustomer

func (s *Store) RegisterCustomer(email string, password string, customer *Customer) error

func (*Store) SetPublishableAPIKey

func (s *Store) SetPublishableAPIKey(k *PublishableAPIKey)

Jump to

Keyboard shortcuts

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