api

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StripeService SubscriptionService = "stripe"
	AppleService  SubscriptionService = "apple"
	GoogleService SubscriptionService = "google"

	SubscriptionTypeOneTime      SubscriptionType = "one_time"
	SubscriptionTypeSubscription SubscriptionType = "subscription"
)
View Source
const (
	TierFree = 0
	TierPro  = 1
)

Variables

View Source
var ErrInvalidCode = errors.New("invalid code")
View Source
var ErrNoSalt = errors.New("not salt available, call GetSalt/Signup first")
View Source
var ErrNotLoggedIn = errors.New("not logged in")

Functions

This section is empty.

Types

type APIClient

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

func NewAPIClient

func NewAPIClient(httpClient *http.Client, userInfo common.UserInfo, dataDir string) *APIClient

func (*APIClient) ActivationCode

func (ac *APIClient) ActivationCode(ctx context.Context, email, resellerCode string) (*PurchaseResponse, error)

ActivationCode is used to purchase a subscription using a reseller code.

func (*APIClient) CompleteChangeEmail

func (a *APIClient) CompleteChangeEmail(ctx context.Context, newEmail, password, code string) error

CompleteChangeEmail completes a change of the email address associated with this user account, using the code recieved via email.

func (*APIClient) CompleteRecoveryByEmail

func (a *APIClient) CompleteRecoveryByEmail(ctx context.Context, email, newPassword, code string) error

CompleteRecoveryByEmail completes account recovery using the code received via email.

func (*APIClient) DataCapInfo

func (a *APIClient) DataCapInfo(ctx context.Context) (*DataCapInfo, error)

DataCapInfo returns information about this user's data cap

func (*APIClient) DeleteAccount

func (a *APIClient) DeleteAccount(ctx context.Context, email, password string) error

DeleteAccount deletes this user account.

func (*APIClient) Devices

func (a *APIClient) Devices() ([]Device, error)

Devices returns a list of devices associated with this user account.

func (*APIClient) Login

func (a *APIClient) Login(ctx context.Context, email string, password string, deviceId string) (*protos.LoginResponse, error)

Login logs the user in.

func (*APIClient) Logout

func (a *APIClient) Logout(ctx context.Context, email string) error

Logout logs the user out. No-op if there is no user account logged in.

func (*APIClient) NewStripeSubscription

func (ac *APIClient) NewStripeSubscription(ctx context.Context, email, planID string) (*SubscriptionResponse, error)

NewStripeSubscription creates a new Stripe subscription for the given email and plan ID.

func (*APIClient) NewUser

func (ac *APIClient) NewUser(ctx context.Context) (*UserDataResponse, error)

NewUser creates a new user account

func (*APIClient) OAuthLoginUrl

func (a *APIClient) OAuthLoginUrl(ctx context.Context, provider string) (string, error)

OAuthLoginUrl initiates the OAuth login process for the specified provider.

func (*APIClient) PaymentRedirect

func (ac *APIClient) PaymentRedirect(ctx context.Context, data PaymentRedirectData) (string, error)

PaymentRedirect is used to get the payment redirect URL with PaymentRedirectData this is used in desktop app and android app

func (*APIClient) ReferralAttach

func (a *APIClient) ReferralAttach(ctx context.Context, code string) (bool, error)

func (*APIClient) RemoveDevice

func (a *APIClient) RemoveDevice(ctx context.Context, deviceID string) (*LinkResponse, error)

RemoveDevice removes a device from the user's account.

func (*APIClient) SignUp

func (a *APIClient) SignUp(ctx context.Context, email, password string) error

SignUp signs the user up for an account.

func (*APIClient) SignupEmailConfirmation

func (a *APIClient) SignupEmailConfirmation(ctx context.Context, email, code string) error

SignupEmailConfirmation confirms the new account using the sign-up code received via email.

func (*APIClient) SignupEmailResendCode

func (a *APIClient) SignupEmailResendCode(ctx context.Context, email string) error

SignupEmailResendCode requests that the sign-up code be resent via email.

func (*APIClient) StartChangeEmail

func (a *APIClient) StartChangeEmail(ctx context.Context, newEmail string, password string) error

StartChangeEmail initializes a change of the email address associated with this user account.

func (*APIClient) StartRecoveryByEmail

func (a *APIClient) StartRecoveryByEmail(ctx context.Context, email string) error

StartRecoveryByEmail initializes the account recovery process for the provided email.

func (*APIClient) StripeBillingPortalUrl

func (ac *APIClient) StripeBillingPortalUrl(ctx context.Context) (string, error)

StripeBillingPortalUrl generates the Stripe billing portal URL for the given user ID.

func (*APIClient) SubscriptionPaymentRedirectURL

func (ac *APIClient) SubscriptionPaymentRedirectURL(ctx context.Context, data PaymentRedirectData) (string, error)

SubscriptionPaymentRedirectURL generates a redirect URL for subscription payment.

func (*APIClient) SubscriptionPlans

func (ac *APIClient) SubscriptionPlans(ctx context.Context, channel string) (*SubscriptionPlans, error)

SubscriptionPlans retrieves available subscription plans for a given channel.

func (*APIClient) UserData

func (ac *APIClient) UserData(ctx context.Context) (*UserDataResponse, error)

UserData returns the user data

func (*APIClient) ValidateEmailRecoveryCode

func (a *APIClient) ValidateEmailRecoveryCode(ctx context.Context, email, code string) error

ValidateEmailRecoveryCode validates the recovery code received via email.

func (*APIClient) VerifySubscription

func (ac *APIClient) VerifySubscription(ctx context.Context, service SubscriptionService, data map[string]string) (status, subID string, err error)

VerifySubscription verifies a subscription for a given service (Google or Apple). data should contain the information required by service to verify the subscription, such as the purchase token for Google Play or the receipt for Apple. The status and subscription ID are returned along with any error that occurred during the verification process.

type AuthClient

type AuthClient interface {
	// Sign up methods
	SignUp(ctx context.Context, email string, password string) ([]byte, error)
	SignupEmailResendCode(ctx context.Context, data *protos.SignupEmailResendRequest) error
	SignupEmailConfirmation(ctx context.Context, data *protos.ConfirmSignupRequest) error
	// Login methods
	GetSalt(ctx context.Context, email string) (*protos.GetSaltResponse, error)
	LoginPrepare(ctx context.Context, loginData *protos.PrepareRequest) (*protos.PrepareResponse, error)
	Login(ctx context.Context, email, password, deviceID string, salt []byte) (*protos.LoginResponse, error)
	// Recovery methods
	StartRecoveryByEmail(ctx context.Context, loginData *protos.StartRecoveryByEmailRequest) error
	CompleteRecoveryByEmail(ctx context.Context, loginData *protos.CompleteRecoveryByEmailRequest) error
	ValidateEmailRecoveryCode(ctx context.Context, loginData *protos.ValidateRecoveryCodeRequest) (*protos.ValidateRecoveryCodeResponse, error)
	// Change email methods
	ChangeEmail(ctx context.Context, loginData *protos.ChangeEmailRequest) error
	// Complete change email methods
	CompleteChangeEmail(ctx context.Context, loginData *protos.CompleteChangeEmailRequest) error
	DeleteAccount(ctc context.Context, loginData *protos.DeleteUserRequest) error
	// Logout
	SignOut(ctx context.Context, logoutData *protos.LogoutRequest) error
}

type DataCapInfo

type DataCapInfo struct {
	BytesAllotted, BytesRemaining int
	AllotmentStart, AllotmentEnd  time.Time
}

DataCapInfo represents information about the data cap for a user account.

type Device

type Device struct {
	ID   string
	Name string
}

Device is a machine registered to a user account (e.g. an Android phone or a Windows desktop).

type LinkResponse

type LinkResponse struct {
	*protos.BaseResponse `json:",inline"`
	UserID               int    `json:"userID"`
	ProToken             string `json:"token"`
}

type PaymentRedirectData

type PaymentRedirectData struct {
	Plan        string           `json:"plan" validate:"required"`
	Provider    string           `json:"provider" validate:"required"`
	Email       string           `json:"email"`
	DeviceName  string           `json:"deviceName" validate:"required" errorId:"device-name"`
	BillingType SubscriptionType `json:"billingType"`
}

PaymentRedirectData contains the data required to generate a payment redirect URL.

type PurchaseResponse

type PurchaseResponse struct {
	*protos.BaseResponse `json:",inline"`
	PaymentStatus        string      `json:"paymentStatus"`
	Plan                 protos.Plan `json:"plan"`
	Status               string      `json:"status"`
}

type SubscriptionPlans

type SubscriptionPlans struct {
	*protos.BaseResponse `json:",inline"`
	Providers            map[string][]*protos.PaymentMethod `json:"providers"`
	Plans                []*protos.Plan                     `json:"plans"`
}

SubscriptionPlans contains information about available subscription plans and payment providers.

type SubscriptionResponse

type SubscriptionResponse struct {
	CustomerId     string `json:"customerId"`
	SubscriptionId string `json:"subscriptionId"`
	ClientSecret   string `json:"clientSecret"`
	PublishableKey string `json:"publishableKey"`
}

SubscriptionResponse contains information about a created subscription.

type SubscriptionService

type SubscriptionService string

type SubscriptionType

type SubscriptionType string

type Tier

type Tier int

Tier is the level of subscription a user is currently at.

type UserDataResponse

type UserDataResponse struct {
	*protos.BaseResponse           `json:",inline"`
	*protos.LoginResponse_UserData `json:",inline"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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