internal

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SystemID = "sb"

	MsgTypeError     = "error"
	MsgTypeOk        = "ok"
	MsgTypeEcho      = "echo"
	MsgTypeInit      = "init"
	MsgTypeAuth      = "auth"
	MsgTypeToken     = "token"
	MsgTypeJoin      = "join"
	MsgTypeJoined    = "joined"
	MsgTypePresence  = "presence"
	MsgTypeChanIn    = "chan_in"
	MsgTypeChanOut   = "chan_out"
	MsgTypeDBCreated = "db_created"
	MsgTypeDBUpdated = "db_updated"
	MsgTypeDBDeleted = "db_deleted"
)
View Source
const (
	TaskTypeFunction = "function"
	TaskTypeMessage  = "message"
)
View Source
const (
	MailProviderDev = "dev"
	MailProviderSES = "ses"
)
View Source
const (
	DataStorePostgreSQL = "postgresql"
	DataStoreMongoDB    = "mongo"
)
View Source
const (
	StorageProviderLocal = "local"
	StorageProviderS3    = "s3"
)

Variables

View Source
var (
	//Tokens     map[string]Auth       = make(map[string]Auth)
	//Bases      map[string]BaseConfig = make(map[string]BaseConfig)
	HashSecret = jwt.NewHS256([]byte(os.Getenv("JWT_SECRET")))
)

Functions

func CanRead

func CanRead(s string) bool

func CanWrite

func CanWrite(s string) bool

func CleanCollectionName

func CleanCollectionName(col string) string

func GetPermission

func GetPermission(col string) (owner string, group string, everyone string)

Types

type Account

type Account struct {
	ID    string `json:"id"`
	Email string `json:"email"`
}

type Auth

type Auth struct {
	AccountID string
	UserID    string
	Email     string
	Role      int
	Token     string
}

Auth represents an authenticated user.

func (Auth) ReconstructToken

func (auth Auth) ReconstructToken() string

type BaseConfig

type BaseConfig struct {
	ID               string    `json:"id"`
	CustomerID       string    `json:"-"`
	Name             string    `json:"name"`
	AllowedDomain    []string  `json:"whitelist"`
	IsActive         bool      `json:"-"`
	MonthlySentEmail int       `json:"-"`
	Created          time.Time `json:"created"`
}

type Command

type Command struct {
	SID           string `json:"sid"`
	Type          string `json:"type"`
	Data          string `json:"data"`
	Channel       string `json:"channel"`
	Token         string `json:"token"`
	IsSystemEvent bool   `json:"-"`
}

func (Command) IsDBEvent

func (msg Command) IsDBEvent() bool

type Customer

type Customer struct {
	ID               string    `bson:"_id" json:"id"`
	Email            string    `bson:"email" json:"email"`
	StripeID         string    `bson:"stripeId" json:"stripeId"`
	SubscriptionID   string    `bson:"subId" json:"subId"`
	IsActive         bool      `bson:"active" json:"-"`
	MonthlyEmailSent int       `bson:"mes" json:"-"`
	Created          time.Time `bson:"created" json:"created"`
}

type ExecData

type ExecData struct {
	ID           string        `json:"id"`
	AccountID    string        `json:"accountId"`
	FunctionName string        `json:"name"`
	TriggerTopic string        `json:"trigger"`
	Code         string        `json:"code"`
	Version      int           `json:"version"`
	LastUpdated  time.Time     `json:"lastUpdated"`
	LastRun      time.Time     `json:"lastRun"`
	History      []ExecHistory `json:"history"`
}

ExecData represents a server-side function with its name, code and execution history

type ExecHistory

type ExecHistory struct {
	ID         string    `json:"id"`
	FunctionID string    `json:"functionId"`
	Version    int       `json:"version"`
	Started    time.Time `json:"started"`
	Completed  time.Time `json:"completed"`
	Success    bool      `json:"success"`
	Output     []string  `json:"output"`
}

ExecHistory represents a function run ending result

type File

type File struct {
	ID        string    `json:"id"`
	AccountID string    `json:"accountId"`
	Key       string    `json:"key"`
	URL       string    `json:"url"`
	Size      int64     `json:"size"`
	Uploaded  time.Time `json:"uploaded"`
}

type JWTPayload

type JWTPayload struct {
	jwt.Payload
	Token string `json:"token,omitempty"`
}

JWTPayload contains the current user token

type ListParams

type ListParams struct {
	Page           int64
	Size           int64
	SortBy         string
	SortDescending bool
}

type Login

type Login struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type Mailer

type Mailer interface {
	Send(SendMailData) error
}

Mailer is used to have different implementation for sending email

type MetaMessage

type MetaMessage struct {
	Data    string `json:"data"`
	Channel string `json:"channel"`
}

type PagedResult

type PagedResult struct {
	Page    int64                    `json:"page"`
	Size    int64                    `json:"size"`
	Total   int64                    `json:"total"`
	Results []map[string]interface{} `json:"results"`
}

type PermissionLevel

type PermissionLevel int
const (
	PermOwner PermissionLevel = iota
	PermGroup
	PermEveryone
)

func ReadPermission

func ReadPermission(col string) PermissionLevel

func WritePermission

func WritePermission(col string) PermissionLevel

type Persister

type Persister interface {
	Ping() error

	// customer / app related
	CreateCustomer(Customer) (Customer, error)
	CreateBase(BaseConfig) (BaseConfig, error)
	EmailExists(email string) (bool, error)
	FindAccount(customerID string) (Customer, error)
	FindDatabase(baseID string) (BaseConfig, error)
	DatabaseExists(name string) (bool, error)
	ListDatabases() ([]BaseConfig, error)
	IncrementMonthlyEmailSent(baseID string) error
	GetCustomerByStripeID(stripeID string) (cus Customer, err error)
	ActivateCustomer(customerID string) error
	NewID() string
	DeleteCustomer(dbName, email string) error

	// system user account function s
	FindToken(dbName, tokenID, token string) (Token, error)
	FindRootToken(dbName, tokenID, accountID, token string) (Token, error)
	GetRootForBase(dbName string) (Token, error)
	FindTokenByEmail(dbName, email string) (Token, error)
	UserEmailExists(dbName, email string) (exists bool, err error)
	GetFirstTokenFromAccountID(dbName, accountID string) (tok Token, err error)

	// membership / account & user functions
	CreateUserAccount(dbName, email string) (id string, err error)
	CreateUserToken(dbName string, tok Token) (id string, err error)
	SetPasswordResetCode(dbName, tokenID, code string) error
	ResetPassword(dbName, email, code, password string) error
	SetUserRole(dbName, email string, role int) error
	UserSetPassword(dbName, tokenID, password string) error

	// base CRUD
	CreateDocument(auth Auth, dbName, col string, doc map[string]interface{}) (map[string]interface{}, error)
	BulkCreateDocument(auth Auth, dbName, col string, docs []interface{}) error
	ListDocuments(auth Auth, dbName, col string, params ListParams) (PagedResult, error)
	QueryDocuments(auth Auth, dbName, col string, filter map[string]interface{}, params ListParams) (PagedResult, error)
	GetDocumentByID(auth Auth, dbName, col, id string) (map[string]interface{}, error)
	UpdateDocument(auth Auth, dbName, col, id string, doc map[string]interface{}) (map[string]interface{}, error)
	IncrementValue(auth Auth, dbName, col, id, field string, n int) error
	DeleteDocument(auth Auth, dbName, col, id string) (int64, error)
	ListCollections(dbName string) ([]string, error)
	ParseQuery(clauses [][]interface{}) (map[string]interface{}, error)

	// form functions
	AddFormSubmission(dbName, form string, doc map[string]interface{}) error
	ListFormSubmissions(dbName, name string) ([]map[string]interface{}, error)
	GetForms(dbName string) ([]string, error)

	// Function functions
	AddFunction(dbName string, data ExecData) (string, error)
	UpdateFunction(dbName, id, code, trigger string) error
	GetFunctionForExecution(dbName, name string) (ExecData, error)
	GetFunctionByID(dbName, id string) (ExecData, error)
	GetFunctionByName(dbName, name string) (ExecData, error)
	ListFunctions(dbName string) ([]ExecData, error)
	ListFunctionsByTrigger(dbName, trigger string) ([]ExecData, error)
	DeleteFunction(dbName, name string) error
	RanFunction(dbName, id string, rh ExecHistory) error

	// schedule tasks
	ListTasks() ([]Task, error)

	// Files / storage
	AddFile(dbName string, f File) (id string, err error)
	GetFileByID(dbName, fileID string) (f File, err error)
	DeleteFile(dbName, fileID string) error
}

type PubSuber

type PubSuber interface {
	Get(key string) (string, error)
	Set(key string, value string) error
	GetTyped(key string, v interface{}) error
	SetTyped(key string, v interface{}) error
	Inc(key string, by int64) (int64, error)
	Dec(key string, by int64) (int64, error)
	Subscribe(send chan Command, token, channel string, close chan bool)
	Publish(msg Command) error
	PublishDocument(channel, typ string, v interface{})
}

PubSuber contains functions to make realtime communication distributed

type PublishDocumentEvent

type PublishDocumentEvent func(channel, typ string, v interface{})

type SendMailData

type SendMailData struct {
	From     string `json:"from"`
	FromName string `json:"fromName"`
	To       string `json:"to"`
	ToName   string `json:"toName"`
	Subject  string `json:"subject"`
	HTMLBody string `json:"htmlBody"`
	TextBody string `json:"textBody"`
	ReplyTo  string `json:"replyTo"`

	Body string `json:"body"`
}

SendMailData contains necessary fields to send an email

type Storer

type Storer interface {
	Save(UploadFileData) (string, error)
	Delete(string) error
}

type Task

type Task struct {
	ID       string      `json:"id"`
	Name     string      `json:"name"`
	Type     string      ` json:"type"`
	Value    string      ` json:"value"`
	Meta     interface{} ` json:"meta"`
	Interval string      ` json:"interval"`
	LastRun  time.Time   ` json:"last"`

	BaseName string `json:"base"`
}

type Token

type Token struct {
	ID        string    `json:"id"`
	AccountID string    `json:"accountId"`
	Token     string    `json:"token"`
	Email     string    `json:"email"`
	Password  string    `json:"-"`
	Role      int       `json:"role"`
	ResetCode string    `json:"-"`
	Created   time.Time `json:"created"`
}

type UploadFileData

type UploadFileData struct {
	FileKey string
	File    io.ReadSeeker
}

Jump to

Keyboard shortcuts

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