3e8124a2b7
API package endpoints (#388): - PATCH /license-packages/{id} — edit package (master protected) - DELETE /license-packages/{id} — delete package (master protected) - POST /license-packages/{id}/archive — archive package - POST /license-packages/{id}/unarchive — restore package Settings API (#349): - GET /license-settings — read licensing/update stream config - PUT /license-settings — update config (all metadata fields) - New LicenseSettings struct in API types Repo scope UI (#395): - Dropdown in create/edit package forms listing org repos - "All repositories" default option - RepoScope read from form in both repo and org handlers - OrgRepos loaded via GetOrgRepositories in Licenses handlers Refs #341, #346, #349, #388, #395 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
153 lines
5.8 KiB
Go
153 lines
5.8 KiB
Go
// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package structs
|
|
|
|
import "time"
|
|
|
|
// LicensePackage represents a license package (subscription tier).
|
|
type LicensePackage struct {
|
|
ID int64 `json:"id"`
|
|
OwnerID int64 `json:"owner_id"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
DurationDays int `json:"duration_days"`
|
|
MaxSites int `json:"max_sites"`
|
|
RepoScope string `json:"repo_scope"`
|
|
AllowedChannels string `json:"allowed_channels"`
|
|
IsActive bool `json:"is_active"`
|
|
// swagger:strfmt date-time
|
|
Created time.Time `json:"created_at"`
|
|
// swagger:strfmt date-time
|
|
Updated time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// CreateLicensePackageOption options for creating a license package.
|
|
type CreateLicensePackageOption struct {
|
|
Name string `json:"name" binding:"Required"`
|
|
Description string `json:"description"`
|
|
DurationDays int `json:"duration_days"`
|
|
MaxSites int `json:"max_sites"`
|
|
RepoScope string `json:"repo_scope"`
|
|
AllowedChannels string `json:"allowed_channels"`
|
|
}
|
|
|
|
// EditLicensePackageOption options for editing a license package.
|
|
type EditLicensePackageOption struct {
|
|
Name *string `json:"name"`
|
|
Description *string `json:"description"`
|
|
DurationDays *int `json:"duration_days"`
|
|
MaxSites *int `json:"max_sites"`
|
|
RepoScope *string `json:"repo_scope"`
|
|
AllowedChannels *string `json:"allowed_channels"`
|
|
IsActive *bool `json:"is_active"`
|
|
}
|
|
|
|
// LicenseKey represents a license key (response — never includes raw key except on creation).
|
|
type LicenseKey struct {
|
|
ID int64 `json:"id"`
|
|
PackageID int64 `json:"package_id"`
|
|
OwnerID int64 `json:"owner_id"`
|
|
KeyPrefix string `json:"key_prefix"`
|
|
LicenseeName string `json:"licensee_name"`
|
|
LicenseeEmail string `json:"licensee_email"`
|
|
DomainRestriction string `json:"domain_restriction"`
|
|
MaxSites int `json:"max_sites"`
|
|
IsInternal bool `json:"is_internal"`
|
|
IsActive bool `json:"is_active"`
|
|
// swagger:strfmt date-time
|
|
StartsAt *time.Time `json:"starts_at"`
|
|
// swagger:strfmt date-time
|
|
ExpiresAt *time.Time `json:"expires_at"`
|
|
// swagger:strfmt date-time
|
|
LastHeartbeat *time.Time `json:"last_heartbeat,omitempty"`
|
|
// swagger:strfmt date-time
|
|
Created time.Time `json:"created_at"`
|
|
}
|
|
|
|
// LicenseKeyCreated is the response when a key is first created (includes raw key).
|
|
type LicenseKeyCreated struct {
|
|
LicenseKey
|
|
// RawKey is the full license key string. Only returned on creation.
|
|
RawKey string `json:"raw_key"`
|
|
}
|
|
|
|
// CreateLicenseKeyOption options for creating a license key.
|
|
type CreateLicenseKeyOption struct {
|
|
PackageID int64 `json:"package_id" binding:"Required"`
|
|
LicenseeName string `json:"licensee_name"`
|
|
LicenseeEmail string `json:"licensee_email"`
|
|
DomainRestriction string `json:"domain_restriction"`
|
|
MaxSites int `json:"max_sites"`
|
|
// StartsAt is optional; defaults to now.
|
|
StartsAt *time.Time `json:"starts_at"`
|
|
// ExpiresAt is optional; auto-calculated from package duration if not set.
|
|
ExpiresAt *time.Time `json:"expires_at"`
|
|
}
|
|
|
|
// EditLicenseKeyOption options for editing a license key.
|
|
type EditLicenseKeyOption struct {
|
|
LicenseeName *string `json:"licensee_name"`
|
|
LicenseeEmail *string `json:"licensee_email"`
|
|
DomainRestriction *string `json:"domain_restriction"`
|
|
MaxSites *int `json:"max_sites"`
|
|
IsActive *bool `json:"is_active"`
|
|
ExpiresAt *time.Time `json:"expires_at"`
|
|
}
|
|
|
|
// PurchaseLicenseKeyOption options for purchasing a license key via webhook.
|
|
type PurchaseLicenseKeyOption struct {
|
|
PackageID int64 `json:"package_id" binding:"Required"`
|
|
LicenseeName string `json:"licensee_name"`
|
|
LicenseeEmail string `json:"licensee_email"`
|
|
Domain string `json:"domain"`
|
|
PaymentRef string `json:"payment_ref"`
|
|
}
|
|
|
|
// ValidateLicenseKeyOption options for validating a license key.
|
|
type ValidateLicenseKeyOption struct {
|
|
Key string `json:"key" binding:"Required"`
|
|
Domain string `json:"domain"`
|
|
}
|
|
|
|
// ValidateLicenseKeyResponse is the response from license key validation.
|
|
type ValidateLicenseKeyResponse struct {
|
|
Valid bool `json:"valid"`
|
|
Message string `json:"message,omitempty"`
|
|
PackageName string `json:"package_name,omitempty"`
|
|
Channels string `json:"channels,omitempty"`
|
|
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
|
SitesUsed int64 `json:"sites_used"`
|
|
MaxSites int `json:"max_sites"`
|
|
}
|
|
|
|
// LicenseSettings represents the licensing/update stream configuration for a repo.
|
|
type LicenseSettings struct {
|
|
LicensingEnabled bool `json:"licensing_enabled"`
|
|
RequireKey bool `json:"require_key"`
|
|
DownloadGating string `json:"download_gating"`
|
|
Platform string `json:"platform"`
|
|
SupportURL string `json:"support_url"`
|
|
ExtensionName string `json:"extension_name,omitempty"`
|
|
DisplayName string `json:"display_name,omitempty"`
|
|
ExtensionType string `json:"extension_type,omitempty"`
|
|
Maintainer string `json:"maintainer,omitempty"`
|
|
MaintainerURL string `json:"maintainer_url,omitempty"`
|
|
InfoURL string `json:"info_url,omitempty"`
|
|
TargetVersion string `json:"target_version,omitempty"`
|
|
PHPMinimum string `json:"php_minimum,omitempty"`
|
|
}
|
|
|
|
// LicenseKeyUsage represents a usage tracking entry.
|
|
type LicenseKeyUsage struct {
|
|
ID int64 `json:"id"`
|
|
KeyID int64 `json:"key_id"`
|
|
RepoID int64 `json:"repo_id"`
|
|
Domain string `json:"domain"`
|
|
IPAddress string `json:"ip_address"`
|
|
UserAgent string `json:"user_agent"`
|
|
VersionFrom string `json:"version_from"`
|
|
// swagger:strfmt date-time
|
|
Created time.Time `json:"created_at"`
|
|
}
|