users

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiPermission

type ApiPermission struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type ApiQuota

type ApiQuota struct {
	Name      string    `json:"name"`
	Usage     int       `json:"usage"`
	ExpiresAt time.Time `json:"expires_at"`
	Remaining int       `json:"remaining"`
	Limit     int       `json:"limit"`
}

type ApiUser

type ApiUser struct {
	ID         string         `json:"id"`
	Email      string         `json:"email"`
	Name       *string        `json:"name"`
	CreatedAt  time.Time      `json:"created_at"`
	IsVerified bool           `json:"is_verified"`
	Metadata   map[string]any `json:"metadata"`
}

type Config

type Config struct {
	Http *utils.HttpClient
}

type CreateUserPayload

type CreateUserPayload struct {
	Email                     string         `json:"email,omitempty"`
	Name                      string         `json:"name,omitempty"`
	PhoneNumber               string         `json:"phone_number,omitempty"`
	Metadata                  map[string]any `json:"metadata,omitempty"`
	MarkEmailAsVerified       bool           `json:"mark_email_as_verified,omitempty"`
	MarkPhoneNumberAsVerified bool           `json:"mark_phone_number_as_verified,omitempty"`
}

type DecrementQuotaOptions added in v1.0.1

type DecrementQuotaOptions struct {
	DecrementBy int
}

type GetUserOptions

type GetUserOptions struct {
	IncludeMetadata bool `json:"include_metadata,omitempty"`
}

type HasPermissionOptions added in v1.0.1

type HasPermissionOptions struct {
	NoCache bool
}

type HasRemainingQuotaOptions added in v1.0.1

type HasRemainingQuotaOptions struct {
	NoCache bool
}

type IncrementQuotaOptions added in v1.0.1

type IncrementQuotaOptions struct {
	IncrementBy int
}

type IsAllowedOptions added in v1.0.1

type IsAllowedOptions struct {
	NoCache bool
}

type IsAllowedPayload

type IsAllowedPayload struct {
	PermissionNames []string `json:"permissionNames"`
	QuotaNames      []string `json:"quotaNames"`
}

type IsForbiddenOptions added in v1.0.1

type IsForbiddenOptions struct {
	NoCache bool
}

type KobbleUsers

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

KobbleUsers is the client to interact with the users API on your Kobble instance.

You can use this client to create, retrieve, update, and delete users on your Kobble instance. You can also use it to manage user metadata, permissions, and quotas.

func NewKobbleUsers

func NewKobbleUsers(config Config) *KobbleUsers

NewKobbleUsers creates a new instance of the KobbleUsers client.

@param config - The configuration for the Kobble instance.

func (KobbleUsers) Create

func (k KobbleUsers) Create(payload CreateUserPayload) (*User, error)

Create a new user on your Kobble instance manually.

While both email and phoneNumber are optional, at least one of them must be provided. If an email is provided, it will be marked as verified by default. Note that the phone number should be in E.164 format (e.g. +14155552671). Other formats will be rejected.

func (k KobbleUsers) CreateLoginLink(userId string) (UrlLink, error)

CreateLoginLink creates a login link for a user.

  • @param userId - The unique identifier for the user to create a login link for.

func (KobbleUsers) DecrementQuotaUsage

func (k KobbleUsers) DecrementQuotaUsage(userId string, quotaName string, opts *DecrementQuotaOptions) error

DecrementQuotaUsage asynchronously decrements the quota usage for a specific user and quota.

	This function allows decrementing a user's quota usage by a specified amount, which defaults to 1 if not provided.

 - @param userId - The unique identifier for the user whose quota is being decremented.
 - @param quotaName - The name of the quota to decrement.
 - @param decrementBy - The amount by which to decrement the quota usage. Optional and defaults to 1.

func (KobbleUsers) FindByMetadata

func (k KobbleUsers) FindByMetadata(metadata map[string]any, options *ListUsersOptions) (common.Pagination[User], error)

FindByMetadata fetches users by their metadata.

You can also include the user's metadata in the response by setting the `IncludeMetadata` option to `true`.

func (KobbleUsers) GetActiveProducts

func (k KobbleUsers) GetActiveProducts(userId string) (*UserActiveProduct, error)

GetActiveProducts retrieves the active product a given user is assigned to.

  • @param userId - The unique identifier for the user whose active product is being retrieved.
  • @returns UserActiveProduct or nil - The active product assigned to the user, or nil if the user has no active product.

func (KobbleUsers) GetByEmail

func (k KobbleUsers) GetByEmail(email string, options *GetUserOptions) (*User, error)

GetByEmail fetches a user by their email.

You can also include the user's metadata in the response by setting the `IncludeMetadata` option to `true`.

func (KobbleUsers) GetById

func (k KobbleUsers) GetById(userId string, options *GetUserOptions) (*User, error)

GetById fetches a user by their ID.

You can also include the user's metadata in the response by setting the `IncludeMetadata` option to `true`.

func (KobbleUsers) GetByPhoneNumber

func (k KobbleUsers) GetByPhoneNumber(phoneNumber string, options *GetUserOptions) (*User, error)

GetByPhoneNumber fetches a user by their phone number.

Note that the phone number should be in E.164 format (e.g. +14155552671). Other formats will be rejected. You can also include the user's metadata in the response by setting the `IncludeMetadata` option to `true`.

func (KobbleUsers) GetQuotaUsage

func (k KobbleUsers) GetQuotaUsage(userId string, quotaName string) (*QuotaUsage, error)

GetQuotaUsage retrieves the quota usage for a given user based on the product assigned to them.

  • @param userId - The unique identifier for the user whose quota usage is being retrieved.
  • @param quotaName - The name of the quota to retrieve.

func (KobbleUsers) HasPermission

func (k KobbleUsers) HasPermission(userId string, permissionNames []string, opts *HasPermissionOptions) (bool, error)

HasPermission checks if a user has all permissions specified as arguments.

  • @param userId - The unique identifier for the user whose permissions are being checked.
  • @param permissionNames - The names of the permission(s) to check. Can be a single permission name or an array of names.
  • @param noCache - Set to true to bypass cache and fetch fresh data. Default is false.

func (KobbleUsers) HasRemainingQuota

func (k KobbleUsers) HasRemainingQuota(userId string, quotaNames []string, opts *HasRemainingQuotaOptions) (bool, error)

HasRemainingQuota checks if a user has remaining credit for all specified quota(s).

  • @param userId - The unique identifier for the user whose quotas are being checked.
  • @param quotaNames - The names of the quotas to check. Can be a single name or an array of names.
  • @param noCache - Set to true to bypass cache and fetch fresh data. Default is false.

func (KobbleUsers) IncrementQuotaUsage

func (k KobbleUsers) IncrementQuotaUsage(userId string, quotaName string, opts *IncrementQuotaOptions) error

IncrementQuotaUsage asynchronously increments the quota usage for a specific user and quota.

	This function allows incrementing a user's quota usage by a specified amount, which defaults to 1 if not provided.

 - @param userId - The unique identifier for the user whose quota is being incremented.
 - @param quotaName - The name of the quota to increment.
 - @param incrementBy - The amount by which to increment the quota usage. Optional and defaults to 1.

func (KobbleUsers) IsAllowed

func (k KobbleUsers) IsAllowed(userId string, payload IsAllowedPayload, opts *IsAllowedOptions) (bool, error)

IsAllowed this function is a helper to check if a user has all permissions and quotas specified in the payload.

		If both permissionNames and quotaNames are provided, the user must have all permissions and quotas to be allowed.
		If only permissionNames are provided, the user must have all permissions to be allowed.
		If only quotaNames are provided, the user must have all quotas to be allowed.

 - @param userId - The unique identifier for the user whose quotas are being checked.
 - @param payload - The payload containing the permission and quota names to check.
 - @param payload.permissionNames - The names of the permissions to check.
 - @param payload.quotaNames - The names of the quotas to check.
 - @param noCache - Set to true to bypass cache and fetch fresh data. Default is false.

func (KobbleUsers) IsForbidden

func (k KobbleUsers) IsForbidden(userId string, payload IsAllowedPayload, opts *IsForbiddenOptions) (bool, error)

IsForbidden this function is a helper to check if a user is forbidden from performing an action.

	It is the opposite of isAllowed.

 - @param userId - The unique identifier for the user whose quotas are being checked.
 - @param payload - The payload containing the permission and quota names to check.
 - @param payload.permissionNames - The names of the permissions to check.
 - @param payload.quotaNames - The names of the quotas to check.
 - @param noCache - Set to true to bypass cache and fetch fresh data. Default is false.

func (KobbleUsers) ListAll

func (k KobbleUsers) ListAll(options *ListUsersOptions) (common.Pagination[User], error)

ListAll fetches all users on your Kobble instance.

Options:

  • Page: The page number to fetch. Defaults to 1.
  • Limit: The number of users to fetch per page. Defaults to 50.
  • IncludeMetadata: Whether to include the user's metadata in the response. Defaults to false.

func (KobbleUsers) ListPermissions

func (k KobbleUsers) ListPermissions(userId string, opts *ListPermissionsOptions) ([]permissions.Permission, error)

ListPermissions retrieves the list of permissions for a given user based on the product assigned to them.

  • @param userId - The unique identifier for the user whose permissions are being retrieved.
  • @param noCache - Set to true to bypass cache and fetch fresh data. Default is false.

func (KobbleUsers) ListQuotas

func (k KobbleUsers) ListQuotas(userId string, opts *ListQuotasOptions) ([]QuotaUsage, error)

ListQuotas retrieves the list of quota usages for a given user based on the product assigned to them.

  • @param userId - The unique identifier for the user whose quota usage is being retrieved.
  • @param noCache - Set to true to bypass cache and fetch fresh data. Default is false.
  • @returns []QuotaUsage - An array of QuotaUsage objects, each representing a quota for the user.

func (KobbleUsers) PatchMetadata

func (k KobbleUsers) PatchMetadata(userId string, metadata map[string]any) (map[string]any, error)

PatchMetadata updates a user's metadata.

func (KobbleUsers) SetQuotaUsage

func (k KobbleUsers) SetQuotaUsage(userId string, quotaName string, usage int) error

SetQuotaUsage asynchronously set the quota usage for a given user to a given number.

	Unlike incrementQuotaUsage and decrementQuotaUsage, this will set the usage to the specific number.

 - @param userId - The unique identifier for the user whose quota is being changed.
 - @param quotaName - The name of the quota to change.
 - @param usage - The new usage you want to set.

func (KobbleUsers) UpdateMetadata

func (k KobbleUsers) UpdateMetadata(userId string, metadata map[string]any) (map[string]any, error)

UpdateMetadata replaces a user's metadata.

type ListApiPermissionResponse

type ListApiPermissionResponse struct {
	Permissions []ApiPermission `json:"permissions"`
}

type ListApiQuotaResponse

type ListApiQuotaResponse struct {
	Quotas []ApiQuota `json:"quotas"`
}

type ListPermissionsOptions added in v1.0.1

type ListPermissionsOptions struct {
	NoCache bool
}

type ListQuotasOptions added in v1.0.1

type ListQuotasOptions struct {
	NoCache bool
}

type ListUsersOptions

type ListUsersOptions struct {
	Limit           int  `json:"limit,omitempty"`
	Page            int  `json:"page,omitempty"`
	IncludeMetadata bool `json:"include_metadata,omitempty"`
}

type Product

type Product struct {
	ID    string  `json:"id"`
	Name  string  `json:"name"`
	Price float64 `json:"price"`
}

type QuotaUsage

type QuotaUsage struct {
	Name      string    `json:"name"`
	Usage     int       `json:"usage"`
	ExpiresAt time.Time `json:"expires_at"`
	Remaining *int      `json:"remaining"`
	Limit     *int      `json:"limit"`
}
type UrlLink struct {
	Url       string    `json:"url"`
	ExpiresAt time.Time `json:"expires_at"`
}

type User

type User struct {
	ID         string         `json:"id"`
	Email      string         `json:"email"`
	Name       *string        `json:"name"`
	CreatedAt  time.Time      `json:"created_at"`
	IsVerified bool           `json:"is_verified"`
	Metadata   map[string]any `json:"metadata"`
}

type UserActiveProduct

type UserActiveProduct struct {
	Product
}

Jump to

Keyboard shortcuts

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