Documentation
¶
Index ¶
- Constants
- Variables
- func CanRead(s string) bool
- func CanWrite(s string) bool
- func CleanCollectionName(col string) string
- func EncryptExternalLogins(tokens map[string]OAuthConfig) ([]byte, error)
- func GetPermission(col string) (owner string, group string, everyone string)
- type Account
- type Auth
- type BaseConfig
- type Command
- type Customer
- type ExecData
- type ExecHistory
- type File
- type JWTPayload
- type ListParams
- type Login
- type Mailer
- type MetaMessage
- type OAuthConfig
- type PagedResult
- type PermissionLevel
- type Persister
- type PubSuber
- type PublishDocumentEvent
- type SendMailData
- type Storer
- type Task
- type Token
- type UploadFileData
- type Volatilizer
Constants ¶
View Source
const ( PlanFree = iota PlanIdea PleanLaunch PlanTraction PlanGrowth )
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" DataStoreMemory = "memory" )
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.HMACSHA )
Functions ¶
func CleanCollectionName ¶
func EncryptExternalLogins ¶ added in v1.4.0
func EncryptExternalLogins(tokens map[string]OAuthConfig) ([]byte, error)
Types ¶
type Auth ¶
type Auth struct {
AccountID string `json:"accountId"`
UserID string `json:"userId"`
Email string `json:"email"`
Role int `json:"role"`
Token string `json:"-"`
Plan int `json:"-"`
}
Auth represents an authenticated user.
func (Auth) ReconstructToken ¶
type BaseConfig ¶
type Command ¶
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"`
Plan int `json:"plan"`
IsActive bool `bson:"active" json:"-"`
MonthlyEmailSent int `bson:"mes" json:"-"`
Created time.Time `bson:"created" json:"created"`
ExternalLogins []byte `json:"-"`
}
func (*Customer) GetExternalLogins ¶ added in v1.4.0
func (cus *Customer) GetExternalLogins() (map[string]OAuthConfig, error)
func (*Customer) GetProvider ¶ added in v1.4.0
func (cus *Customer) GetProvider(provider string) (cfg OAuthConfig, ok bool)
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 JWTPayload ¶
type JWTPayload struct {
jwt.Payload
Token string `json:"token,omitempty"`
}
JWTPayload contains the current user token
type ListParams ¶
type Mailer ¶
type Mailer interface {
Send(SendMailData) error
}
Mailer is used to have different implementation for sending email
type MetaMessage ¶
type OAuthConfig ¶ added in v1.4.0
type PagedResult ¶
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
CreateIndex(dbName, col, field string) 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, active bool) error
ChangeCustomerPlan(customerID string, plan int) error
EnableExternalLogin(customerID string, config map[string]OAuthConfig) 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 UploadFileData ¶
type UploadFileData struct {
FileKey string
File io.ReadSeeker
}
type Volatilizer ¶ added in v1.4.0
type Volatilizer interface {
Get(key string) (string, error)
Set(key string, value string) error
GetTyped(key string, v any) error
SetTyped(key string, v any) 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 any)
QueueWork(key, value string) error
DequeueWork(key string) (string, error)
}
Click to show internal directories.
Click to hide internal directories.