feat(clients): renew on a calendar day instead of a rolling interval (#6239)

* feat(clients): renew on a calendar day instead of a rolling interval

Auto-renew advances the expiry by a fixed number of milliseconds, so a client
set to 30 days drifts against the calendar: renewing on 31 January lands on
2 March, and by the end of the year the billing day has wandered a fortnight
from where the operator's own plan resets.

Add a per-client renewal day. When set, the expiry steps whole calendar months
at midnight in the panel's time zone. A month too short for the chosen day
renews on its last day and the following month returns to the chosen one, so
the 31st does not decay into the 28th permanently.

Zero keeps the interval mode, so existing clients are untouched.

The interval branch now also refuses a zero step. It is unreachable while the
selection filter holds, but that loop runs on the single traffic writer, and a
zero interval there would hang every panel mutation behind it.

* fix(clients): persist the calendar renewal day on the client record

resetDay lived only in the inbound settings JSON and client_traffics, so
every path that rebuilds a client from the clients table wrote it back as
zero: an ordinary edit, an attach to a second inbound, a traffic reset on
a disabled client. Calendar mode turned itself off during normal use and
the operator only found out a month later.

Adds reset_day to ClientRecord and threads it through ToRecord, ToClient,
applyClientRecordMerge and the record update map, so the value survives
the round trip. The clients page filter and ClientSlim now recognise the
mode, nodeClientRenewed classifies a calendar renewal as a renewal, the
node snapshot merge carries reset_day, and the service layer rejects a
day outside 0-31 rather than clamping it silently.

Also renames the label keys to renewOnDay to keep them apart from the
existing renewDays, translates them and the new RESET_DAY subscription
placeholder in all 13 locales, adds the field to the bulk-add modal, and
drops the stray internal/web/dist/.gitkeep build stub.

* fix(clients): let the billing day be changed after creation

ClientService.Update writes the record columns directly only for a client
with no inbounds. The normal path goes through SyncInbound and
applyClientRecordMerge, which this change had not extended, so moving a
client from the 20th to the 5th updated the inbound settings JSON while
clients.reset_day kept the old value and the renewal kept using it.

The existing test did not catch it: it asserted the day survived an
unrelated edit, and it survived precisely because nothing on that path
ever wrote it. TestClientEditChangesTheBillingDay moves the day and then
switches calendar mode off again; removing the record write turns it red.

* chore: drop the accidentally committed dist build stub

internal/web/dist/.gitkeep is what make dist-stub creates locally. Committing
it changes fresh-clone behaviour for everyone: today a bare go build fails
loudly on //go:embed all:dist, which is the documented signal to run the stub
target; with the file present the build succeeds and the panel serves an empty
dist instead.

---------

Co-authored-by: n0ctal <n0ctal@users.noreply.github.com>
Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
n0ctal
2026-08-18 15:46:00 +05:00
committed by GitHub
parent 1872659d83
commit b8903fadf4
34 changed files with 730 additions and 10 deletions
+15
View File
@@ -1092,6 +1092,10 @@ export const SCHEMAS: Record<string, unknown> = {
"description": "Reset period in days",
"type": "integer"
},
"resetDay": {
"description": "Calendar renewal day 1-31, 0 = interval mode",
"type": "integer"
},
"resetMax": {
"description": "Max auto-renew count, 0 = unlimited",
"type": "integer"
@@ -1140,6 +1144,7 @@ export const SCHEMAS: Record<string, unknown> = {
"expiryTime",
"limitIp",
"reset",
"resetDay",
"resetMax",
"security",
"subId",
@@ -1233,6 +1238,9 @@ export const SCHEMAS: Record<string, unknown> = {
"reset": {
"type": "integer"
},
"resetDay": {
"type": "integer"
},
"resetMax": {
"type": "integer"
},
@@ -1282,6 +1290,7 @@ export const SCHEMAS: Record<string, unknown> = {
"privateKey",
"publicKey",
"reset",
"resetDay",
"resetMax",
"reverse",
"secret",
@@ -1353,6 +1362,11 @@ export const SCHEMAS: Record<string, unknown> = {
"example": 0,
"type": "integer"
},
"resetDay": {
"description": "ResetDay renews on that day of each calendar month instead of every\nReset days; 0 keeps the interval behaviour.",
"example": 0,
"type": "integer"
},
"resetMax": {
"description": "ResetMax caps how many times auto-renew may fire; 0 means no cap.",
"example": 0,
@@ -1388,6 +1402,7 @@ export const SCHEMAS: Record<string, unknown> = {
"lastSubFetch",
"reset",
"resetCount",
"resetDay",
"resetMax",
"subId",
"total",