caplyr 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -1
- package/dist/index.mjs +16 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -124,6 +124,9 @@ var Heartbeat = class {
|
|
|
124
124
|
};
|
|
125
125
|
/** Current protection status */
|
|
126
126
|
this.status = "ACTIVE";
|
|
127
|
+
/** Local budget limits set via config (not from server) */
|
|
128
|
+
this.localDailyLimit = null;
|
|
129
|
+
this.localMonthlyLimit = null;
|
|
127
130
|
this.endpoint = config.endpoint ?? "https://caplyr.com";
|
|
128
131
|
this.apiKey = config.apiKey;
|
|
129
132
|
this.interval = config.heartbeatInterval ?? 6e4;
|
|
@@ -137,9 +140,11 @@ var Heartbeat = class {
|
|
|
137
140
|
*/
|
|
138
141
|
applyLocalLimits(budget) {
|
|
139
142
|
if (budget.daily !== void 0) {
|
|
143
|
+
this.localDailyLimit = budget.daily;
|
|
140
144
|
this.budgetStatus.daily_limit = budget.daily;
|
|
141
145
|
}
|
|
142
146
|
if (budget.monthly !== void 0) {
|
|
147
|
+
this.localMonthlyLimit = budget.monthly;
|
|
143
148
|
this.budgetStatus.monthly_limit = budget.monthly;
|
|
144
149
|
}
|
|
145
150
|
}
|
|
@@ -169,7 +174,17 @@ var Heartbeat = class {
|
|
|
169
174
|
throw new Error(`Heartbeat failed: ${res.status}`);
|
|
170
175
|
}
|
|
171
176
|
const data = await res.json();
|
|
172
|
-
this.budgetStatus
|
|
177
|
+
const localDailyUsed = this.budgetStatus.daily_used;
|
|
178
|
+
const localMonthlyUsed = this.budgetStatus.monthly_used;
|
|
179
|
+
this.budgetStatus = {
|
|
180
|
+
...data,
|
|
181
|
+
// Use whichever spend is higher — server or local tracking
|
|
182
|
+
daily_used: Math.max(data.daily_used ?? 0, localDailyUsed),
|
|
183
|
+
monthly_used: Math.max(data.monthly_used ?? 0, localMonthlyUsed),
|
|
184
|
+
// Preserve local limits if server doesn't provide them
|
|
185
|
+
daily_limit: data.daily_limit ?? this.localDailyLimit,
|
|
186
|
+
monthly_limit: data.monthly_limit ?? this.localMonthlyLimit
|
|
187
|
+
};
|
|
173
188
|
this.consecutiveFailures = 0;
|
|
174
189
|
const newStatus = data.kill_switch_active ? "OFF" : data.status;
|
|
175
190
|
if (newStatus !== this.status) {
|
package/dist/index.mjs
CHANGED
|
@@ -91,6 +91,9 @@ var Heartbeat = class {
|
|
|
91
91
|
};
|
|
92
92
|
/** Current protection status */
|
|
93
93
|
this.status = "ACTIVE";
|
|
94
|
+
/** Local budget limits set via config (not from server) */
|
|
95
|
+
this.localDailyLimit = null;
|
|
96
|
+
this.localMonthlyLimit = null;
|
|
94
97
|
this.endpoint = config.endpoint ?? "https://caplyr.com";
|
|
95
98
|
this.apiKey = config.apiKey;
|
|
96
99
|
this.interval = config.heartbeatInterval ?? 6e4;
|
|
@@ -104,9 +107,11 @@ var Heartbeat = class {
|
|
|
104
107
|
*/
|
|
105
108
|
applyLocalLimits(budget) {
|
|
106
109
|
if (budget.daily !== void 0) {
|
|
110
|
+
this.localDailyLimit = budget.daily;
|
|
107
111
|
this.budgetStatus.daily_limit = budget.daily;
|
|
108
112
|
}
|
|
109
113
|
if (budget.monthly !== void 0) {
|
|
114
|
+
this.localMonthlyLimit = budget.monthly;
|
|
110
115
|
this.budgetStatus.monthly_limit = budget.monthly;
|
|
111
116
|
}
|
|
112
117
|
}
|
|
@@ -136,7 +141,17 @@ var Heartbeat = class {
|
|
|
136
141
|
throw new Error(`Heartbeat failed: ${res.status}`);
|
|
137
142
|
}
|
|
138
143
|
const data = await res.json();
|
|
139
|
-
this.budgetStatus
|
|
144
|
+
const localDailyUsed = this.budgetStatus.daily_used;
|
|
145
|
+
const localMonthlyUsed = this.budgetStatus.monthly_used;
|
|
146
|
+
this.budgetStatus = {
|
|
147
|
+
...data,
|
|
148
|
+
// Use whichever spend is higher — server or local tracking
|
|
149
|
+
daily_used: Math.max(data.daily_used ?? 0, localDailyUsed),
|
|
150
|
+
monthly_used: Math.max(data.monthly_used ?? 0, localMonthlyUsed),
|
|
151
|
+
// Preserve local limits if server doesn't provide them
|
|
152
|
+
daily_limit: data.daily_limit ?? this.localDailyLimit,
|
|
153
|
+
monthly_limit: data.monthly_limit ?? this.localMonthlyLimit
|
|
154
|
+
};
|
|
140
155
|
this.consecutiveFailures = 0;
|
|
141
156
|
const newStatus = data.kill_switch_active ? "OFF" : data.status;
|
|
142
157
|
if (newStatus !== this.status) {
|