Documentation
¶
Overview ¶
Package subscription is the facade of the subscription module: plan and group management plus the public storefront listings (subscription delivery joins as migration proceeds). See docs/adr-001-modular-monolith.md.
Index ¶
Constants ¶
const ( NotifyKindPurchase = fulfillment.NotifyPurchase NotifyKindRenewal = fulfillment.NotifyRenewal NotifyKindResetTraffic = fulfillment.NotifyResetTraffic )
Variables ¶
var ErrQuotaTaskUnretryable = quotatask.ErrUnretryable
ErrQuotaTaskUnretryable re-exports the quota subdomain's skip-retry sentinel for the queue shell.
Functions ¶
func NewRepoBuilder ¶ added in v1.15.2
func NewRepoBuilder() repository.SubscriptionBuilder
NewRepoBuilder exports the module-owned repository implementations for store assembly (ADR-001 step-6 preparation).
Types ¶
type DeliveryConfig ¶
DeliveryConfig re-exports the delivery subdomain's runtime snapshot.
type Deps ¶
type Deps struct {
Plans repository.SubscribeRepo
UserSubs repository.UserSubscriptionRepo
Nodes repository.NodeRepo
Store SubscriptionTransactor
// NotifyPlanChanged broadcasts a plan update to connected devices.
NotifyPlanChanged func()
// Host is the site host list (first line is used for node fallbacks).
Host string
// IsTrialPlan reports whether the plan is the configured trial plan.
IsTrialPlan func(planID int64) bool
// Delivery dependencies.
Clients repository.ClientRepo
Users repository.UserRepo
Logs repository.LogRepo
// DeliveryConfig reads the runtime-mutable delivery configuration.
DeliveryConfig func() DeliveryConfig
// User-subscription administration dependencies.
Devices repository.UserDeviceRepo
Cache repository.UserCacheRepo
Traffic repository.TrafficRepo
// FullStore is the transitional full-store dependency for the admin and
// self-service subscription transactions.
FullStore repository.Store
Orders repository.OrderRepo
Inbox repository.InboxRepo
// SingleModel forbids holding more than one blocking subscription;
// runtime-mutable, read per request.
SingleModel func() bool
// TrialPolicy snapshots the runtime-mutable registration-trial settings
// per call.
TrialPolicy func() TrialPolicy
// UserAuths and LifecycleNotify serve the lifecycle sweep: the identity
// email lookup and the owner notification channel.
UserAuths sweep.OwnerEmailReader
LifecycleNotify sweep.Notifier
}
Deps declares everything the module needs; the composition root (internal/svc) provides them.
type FulfillmentOutcome ¶ added in v1.15.1
type FulfillmentOutcome = fulfillment.Outcome
FulfillmentOutcome re-exports the fulfillment subdomain's notification context, and the NotifyKind* constants label which notice applies.
type RequestMeta ¶
type RequestMeta = delivery.RequestMeta
RequestMeta re-exports the delivery subdomain's transport details.
type Service ¶
type Service interface {
// CheckSubscriptions runs the lifecycle sweeps (traffic exceeded,
// expired), committing status flips in subscription transactions with
// notification and cache invalidation as post-commit side effects.
CheckSubscriptions(ctx context.Context) error
// ProcessQuotaTask executes an admin-scheduled quota grant (time
// extension / gift credit) for the task's subscription scope.
ProcessQuotaTask(ctx context.Context, taskID int64) error
// FulfillPaidOrder applies a paid order's business effect (new
// subscription, renewal or traffic reset) exactly once and returns the
// notification context.
FulfillPaidOrder(ctx context.Context, orderNo string) (*FulfillmentOutcome, error)
// GrantTrial consumes the identity.user_registered event: applies the
// registration trial exactly once (a disabled policy still consumes the
// event).
GrantTrial(ctx context.Context, userID int64) error
// The client-application management for subscription delivery.
CreateSubscribeApplication(ctx context.Context, req *dto.CreateSubscribeApplicationRequest) (*dto.SubscribeApplication, error)
UpdateSubscribeApplication(ctx context.Context, req *dto.UpdateSubscribeApplicationRequest) (*dto.SubscribeApplication, error)
DeleteSubscribeApplication(ctx context.Context, req *dto.DeleteSubscribeApplicationRequest) error
GetSubscribeApplicationList(ctx context.Context, req *dto.GetSubscribeApplicationListRequest) (*dto.GetSubscribeApplicationListResponse, error)
PreviewSubscribeTemplate(ctx context.Context, req *dto.PreviewSubscribeTemplateRequest) (*dto.PreviewSubscribeTemplateResponse, error)
CreateSubscribe(ctx context.Context, req *dto.CreateSubscribeRequest) error
UpdateSubscribe(ctx context.Context, req *dto.UpdateSubscribeRequest) error
DeleteSubscribe(ctx context.Context, req *dto.DeleteSubscribeRequest) error
BatchDeleteSubscribe(ctx context.Context, req *dto.BatchDeleteSubscribeRequest) error
GetSubscribeList(ctx context.Context, req *dto.GetSubscribeListRequest) (*dto.GetSubscribeListResponse, error)
GetSubscribeDetails(ctx context.Context, req *dto.GetSubscribeDetailsRequest) (*dto.Subscribe, error)
SubscribeSort(ctx context.Context, req *dto.SubscribeSortRequest) error
ResetAllSubscribeToken(ctx context.Context) (*dto.ResetAllSubscribeTokenResponse, error)
CreateSubscribeGroup(ctx context.Context, req *dto.CreateSubscribeGroupRequest) error
UpdateSubscribeGroup(ctx context.Context, req *dto.UpdateSubscribeGroupRequest) error
DeleteSubscribeGroup(ctx context.Context, req *dto.DeleteSubscribeGroupRequest) error
BatchDeleteSubscribeGroup(ctx context.Context, req *dto.BatchDeleteSubscribeGroupRequest) error
GetSubscribeGroupList(ctx context.Context) (*dto.GetSubscribeGroupListResponse, error)
QuerySubscribeList(ctx context.Context, req *dto.QuerySubscribeListRequest) (*dto.QuerySubscribeListResponse, error)
QuerySubscribeGroupList(ctx context.Context) (*dto.QuerySubscribeGroupListResponse, error)
QueryUserSubscribeNodeList(ctx context.Context) (*dto.QueryUserSubscribeNodeListResponse, error)
// Deliver renders the client configuration for a subscription token.
Deliver(ctx context.Context, meta RequestMeta, req *dto.SubscribeRequest) (*dto.SubscribeResponse, error)
// IsUserAgentAllowed gates delivery by the configured user-agent allowlist.
IsUserAgentAllowed(ctx context.Context, userAgent string) bool
// User self-service subscription management.
QueryUserSubscribe(ctx context.Context) (*dto.QueryUserSubscribeListResponse, error)
// ResetOwnSubscribeToken is the self-service variant; ownership of the
// subscription is enforced against the request context.
ResetOwnSubscribeToken(ctx context.Context, req *dto.ResetUserSubscribeTokenRequest) error
GetSubscribeLog(ctx context.Context, req *dto.GetSubscribeLogRequest) (*dto.GetSubscribeLogResponse, error)
UpdateUserSubscribeNote(ctx context.Context, req *dto.UpdateUserSubscribeNoteRequest) error
PreUnsubscribe(ctx context.Context, req *dto.PreUnsubscribeRequest) (*dto.PreUnsubscribeResponse, error)
// Unsubscribe cancels in a subscription transaction and settles the
// refund in a billing transaction, resumable via the idempotent inbox.
Unsubscribe(ctx context.Context, req *dto.UnsubscribeRequest) error
// Admin-side user subscription management.
CreateUserSubscribe(ctx context.Context, req *dto.CreateUserSubscribeRequest) error
DeleteUserSubscribe(ctx context.Context, req *dto.DeleteUserSubscribeRequest) error
UpdateUserSubscribe(ctx context.Context, req *dto.UpdateUserSubscribeRequest) error
GetUserSubscribe(ctx context.Context, req *dto.GetUserSubscribeListRequest) (*dto.GetUserSubscribeListResponse, error)
GetUserSubscribeById(ctx context.Context, req *dto.GetUserSubscribeByIdRequest) (*dto.UserSubscribeDetail, error)
GetUserSubscribeDevices(ctx context.Context, req *dto.GetUserSubscribeDevicesRequest) (*dto.GetUserSubscribeDevicesResponse, error)
GetUserSubscribeLogs(ctx context.Context, req *dto.GetUserSubscribeLogsRequest) (*dto.GetUserSubscribeLogsResponse, error)
GetUserSubscribeResetTrafficLogs(ctx context.Context, req *dto.GetUserSubscribeResetTrafficLogsRequest) (*dto.GetUserSubscribeResetTrafficLogsResponse, error)
GetUserSubscribeTrafficLogs(ctx context.Context, req *dto.GetUserSubscribeTrafficLogsRequest) (*dto.GetUserSubscribeTrafficLogsResponse, error)
ResetUserSubscribeToken(ctx context.Context, req *dto.ResetUserSubscribeTokenRequest) error
ResetUserSubscribeTraffic(ctx context.Context, req *dto.ResetUserSubscribeTrafficRequest) error
ToggleUserSubscribeStatus(ctx context.Context, req *dto.ToggleUserSubscribeStatusRequest) error
}
Service is the only surface other code may depend on; the implementation lives under internal/ where the compiler seals it off.
type SubscriptionTransactor ¶
type SubscriptionTransactor = plan.SubscriptionTransactor
SubscriptionTransactor re-exports the plan subdomain's transaction port.
type TrialPolicy ¶ added in v1.15.2
TrialPolicy re-exports the trial subdomain's policy snapshot for the composition root.
Directories
¶
| Path | Synopsis |
|---|---|
|
entity
|
|
|
usersub
Package usersub holds the subscription domain's user-subscription entities (ADR-001 step 5: entity packages follow table ownership).
|
Package usersub holds the subscription domain's user-subscription entities (ADR-001 step 5: entity packages follow table ownership). |
|
internal
|
|
|
application
Service assembly for the client-application subdomain of the subscription module: managing the subscribe clients and previewing their delivery templates.
|
Service assembly for the client-application subdomain of the subscription module: managing the subscribe clients and previewing their delivery templates. |
|
delivery
Package delivery implements the subscription delivery subdomain of the subscription module: token-authenticated rendering of client configs via the adapter, with notice placeholders for expired/exhausted subscriptions.
|
Package delivery implements the subscription delivery subdomain of the subscription module: token-authenticated rendering of client configs via the adapter, with notice placeholders for expired/exhausted subscriptions. |
|
fulfillment
Package fulfillment applies a paid order's business effect: creating, renewing or traffic-resetting the user subscription in the fulfillment transaction, idempotent via the inbox marker.
|
Package fulfillment applies a paid order's business effect: creating, renewing or traffic-resetting the user subscription in the fulfillment transaction, idempotent via the inbox marker. |
|
plan
Package plan implements the subscription plan management subdomain of the subscription module: plan and group CRUD, ordering and token resets.
|
Package plan implements the subscription plan management subdomain of the subscription module: plan and group CRUD, ordering and token resets. |
|
quotatask
Package quotatask processes the admin-scheduled quota grants: extending subscription time and crediting gift money for a scope of subscriptions.
|
Package quotatask processes the admin-scheduled quota grants: extending subscription time and crediting gift money for a scope of subscriptions. |
|
selfsub
Package selfsub implements the user self-service subscription management of the subscription module: viewing, token reset, notes, and the two-phase cancellation with its billing refund.
|
Package selfsub implements the user self-service subscription management of the subscription module: viewing, token reset, notes, and the two-phase cancellation with its billing refund. |
|
storefront
Package storefront implements the public subscription listings of the subscription module.
|
Package storefront implements the public subscription listings of the subscription module. |
|
sweep
Package sweep implements the subscription lifecycle sweep: marking traffic-exceeded and expired subscriptions finished, then firing the retryable side effects (owner notification, cache invalidation).
|
Package sweep implements the subscription lifecycle sweep: marking traffic-exceeded and expired subscriptions finished, then firing the retryable side effects (owner notification, cache invalidation). |
|
trial
Package trial grants the registration trial subscription.
|
Package trial grants the registration trial subscription. |
|
usersub
Package usersub implements the admin-side user subscription management of the subscription module.
|
Package usersub implements the admin-side user subscription management of the subscription module. |