vidspotai-shared 1.0.147 → 1.0.148
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/lib/globals/plans.d.ts +17 -0
- package/lib/globals/plans.d.ts.map +1 -1
- package/lib/globals/plans.js +11 -1
- package/lib/globals/types.d.ts +2 -1
- package/lib/globals/types.d.ts.map +1 -1
- package/lib/globals/types.js +5 -0
- package/lib/models/agent.model.d.ts +6 -0
- package/lib/models/agent.model.d.ts.map +1 -1
- package/lib/models/demoVideoProject.model.d.ts +6 -0
- package/lib/models/demoVideoProject.model.d.ts.map +1 -1
- package/lib/models/image.model.d.ts +6 -0
- package/lib/models/image.model.d.ts.map +1 -1
- package/lib/models/musicJob.model.d.ts +6 -0
- package/lib/models/musicJob.model.d.ts.map +1 -1
- package/lib/models/upscale.model.d.ts +6 -0
- package/lib/models/upscale.model.d.ts.map +1 -1
- package/lib/models/user.model.d.ts +68 -1
- package/lib/models/user.model.d.ts.map +1 -1
- package/lib/models/video.model.d.ts +43 -0
- package/lib/models/video.model.d.ts.map +1 -1
- package/lib/models/videoTool.model.d.ts +6 -0
- package/lib/models/videoTool.model.d.ts.map +1 -1
- package/lib/services/accountStatus/index.d.ts +35 -0
- package/lib/services/accountStatus/index.d.ts.map +1 -1
- package/lib/services/accountStatus/index.js +54 -0
- package/lib/services/agent/repair/engine.d.ts.map +1 -1
- package/lib/services/agent/repair/engine.js +18 -0
- package/lib/services/agent/repair/strategies/llmRepair.strategy.d.ts.map +1 -1
- package/lib/services/agent/repair/strategies/llmRepair.strategy.js +20 -8
- package/lib/services/bullmq.service.d.ts +18 -1
- package/lib/services/bullmq.service.d.ts.map +1 -1
- package/lib/services/bullmq.service.js +13 -0
- package/lib/services/credit.service.d.ts +61 -1
- package/lib/services/credit.service.d.ts.map +1 -1
- package/lib/services/credit.service.js +124 -52
- package/lib/services/credits/grant.d.ts +105 -0
- package/lib/services/credits/grant.d.ts.map +1 -0
- package/lib/services/credits/grant.js +129 -0
- package/lib/services/demo/demoPrefill.d.ts.map +1 -1
- package/lib/services/demo/demoPrefill.js +101 -84
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.d.ts.map +1 -1
- package/lib/services/index.js +1 -0
- package/lib/services/moderation/generationModeration.service.d.ts +52 -0
- package/lib/services/moderation/generationModeration.service.d.ts.map +1 -0
- package/lib/services/moderation/generationModeration.service.js +260 -0
- package/lib/services/moderation/index.d.ts +4 -0
- package/lib/services/moderation/index.d.ts.map +1 -1
- package/lib/services/moderation/index.js +14 -1
- package/lib/services/moderation/moderationStrike.service.d.ts +67 -0
- package/lib/services/moderation/moderationStrike.service.d.ts.map +1 -0
- package/lib/services/moderation/moderationStrike.service.js +134 -0
- package/lib/services/rateLimiter/index.d.ts +1 -0
- package/lib/services/rateLimiter/index.d.ts.map +1 -1
- package/lib/services/rateLimiter/index.js +1 -0
- package/lib/services/rateLimiter/userRateLimiter.service.d.ts +55 -0
- package/lib/services/rateLimiter/userRateLimiter.service.d.ts.map +1 -0
- package/lib/services/rateLimiter/userRateLimiter.service.js +220 -0
- package/lib/services/trialGuard/trialSignals.d.ts.map +1 -1
- package/lib/services/trialGuard/trialSignals.js +15 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -0
- package/lib/utils/ssrfGuard.d.ts +59 -0
- package/lib/utils/ssrfGuard.d.ts.map +1 -0
- package/lib/utils/ssrfGuard.js +253 -0
- package/package.json +1 -1
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CONTENT_POLICY_VIOLATION_CODE = exports.CONTENT_POLICY_VIOLATION_MESSAGE = void 0;
|
|
7
|
+
exports.hasUndressIntent = hasUndressIntent;
|
|
8
|
+
exports.moderateGenerationInput = moderateGenerationInput;
|
|
9
|
+
exports.collectModerationInputs = collectModerationInputs;
|
|
10
|
+
const openai_1 = __importDefault(require("openai"));
|
|
11
|
+
const logger_1 = require("../../utils/logger");
|
|
12
|
+
/** User-facing copy for a blocked generation (422 content_policy_violation). */
|
|
13
|
+
exports.CONTENT_POLICY_VIOLATION_MESSAGE = "This request can't be generated: it appears to involve sexual content involving minors or sexualizing a real person, which our content policy doesn't allow. Repeated attempts will suspend your account.";
|
|
14
|
+
exports.CONTENT_POLICY_VIOLATION_CODE = "content_policy_violation";
|
|
15
|
+
const MODERATION_TIMEOUT_MS = 2500;
|
|
16
|
+
/** Text-only `sexual` score above which we block without an image present. */
|
|
17
|
+
const TEXT_ONLY_SEXUAL_THRESHOLD = 0.8;
|
|
18
|
+
/**
|
|
19
|
+
* Text `sexual` score above which a request WITH an image input is blocked.
|
|
20
|
+
* Was the boolean `sexual` flag; review 2026-11-25 found that flag trips on
|
|
21
|
+
* ordinary swimwear / lingerie / fashion ad prompts with a model photo. The
|
|
22
|
+
* undress keyword prefilter still catches the actual abuse pattern.
|
|
23
|
+
*/
|
|
24
|
+
const TEXT_WITH_IMAGE_SEXUAL_THRESHOLD = 0.5;
|
|
25
|
+
/** Image `sexual` score above which an uploaded image itself is refused. */
|
|
26
|
+
const IMAGE_SEXUAL_THRESHOLD = 0.8;
|
|
27
|
+
/** Cap per request — each image is a separate moderation call. */
|
|
28
|
+
const MAX_IMAGES = 4;
|
|
29
|
+
/** omni-moderation handles long inputs, but there's no value past this. */
|
|
30
|
+
const MAX_TEXT_CHARS = 16000;
|
|
31
|
+
/**
|
|
32
|
+
* Undress / nudify intents in the languages we've seen abuse in (Korean first)
|
|
33
|
+
* plus the major ones. Matched case-insensitively against the joined text. Only
|
|
34
|
+
* BLOCKS when combined with an image input — on its own it's just a signal the
|
|
35
|
+
* OpenAI pass decides on (a text-only prompt has no real person to undress).
|
|
36
|
+
*/
|
|
37
|
+
const UNDRESS_PATTERNS = [
|
|
38
|
+
// English
|
|
39
|
+
/\b(undress(ed|ing)?|unclothe[ds]?|nudif(y|ied|ication)|de-?nud(e|ify)|strip(ped|ping)?\s+(her|him|them|naked|nude)|take\s+(off\s+)?(her|his|their)\s+(clothes|clothing|bra|top|shirt|panties|underwear|bikini)|remove\s+(her|his|their)\s+(clothes|clothing|bra|top|shirt|panties|underwear|bikini)|remove\s+(the|all)\s+(clothes|clothing|underwear)|without\s+(any\s+)?clothes|no\s+clothes|make\s+(her|him|them)\s+(naked|nude)|fully\s+nude|completely\s+naked|see[-\s]?through\s+clothes|x-?ray\s+clothes)\b/i,
|
|
40
|
+
// Korean: 탈의 (undress; not 탈의실 = fitting room), 옷을 벗(기다/겨/어) (take off
|
|
41
|
+
// clothes), 누드로 만들 (make nude — bare 누드 is also a makeup/colour word),
|
|
42
|
+
// 알몸 (naked body), 나체 (nudity), 벌거벗 (stark naked), 옷 없이 (without clothes)
|
|
43
|
+
/(탈의(?!실)|옷\s*을?\s*벗|옷\s*벗|누드\s*로\s*만들|알몸|나체|벌거벗|옷\s*없이|속옷\s*만\s*입|노출\s*시켜)/,
|
|
44
|
+
// Japanese: 脱がせ/脱がす (make undress), 服を脱 (take off clothes), 裸 (naked),
|
|
45
|
+
// 全裸 (fully naked). Bare ヌード skipped: also a colour/makeup word.
|
|
46
|
+
/(脱がせ|脱がす|服を脱|全裸|裸に|はだか)/,
|
|
47
|
+
// Chinese (simplified + traditional): 脱衣, 脱光, 裸体/裸體, 去掉衣服, 一丝不挂
|
|
48
|
+
/(脱衣(?!所|室)|脫衣(?!所|室)|脱光|脫光|裸体|裸體|去掉衣服|脱掉衣服|脫掉衣服|一丝不挂|一絲不掛)/,
|
|
49
|
+
// Spanish / Portuguese
|
|
50
|
+
/\b(desnud(a|o|ar|ala|alo|ez)|quita(r|le|rle)?\s+la\s+ropa|sin\s+ropa|despir(a|ir|ida|ido)?|tirar\s+a\s+roupa|sem\s+roupa|pelad(a|o)\s+(total|completa))\b/i,
|
|
51
|
+
// French / German / Italian
|
|
52
|
+
/\b(d[ée]shabill(er|e|ez|ée)|enl[eè]ve\s+(ses|tes)\s+v[êe]tements|nackt|entkleide[nt]?|spogliar(e|la|lo|si)|svestir(e|la|lo))\b/i,
|
|
53
|
+
// Russian
|
|
54
|
+
/(раздень|раздеть|голая|голый|обнаж[её]нн)/i,
|
|
55
|
+
// Thai / Vietnamese / Indonesian
|
|
56
|
+
/(ถอดเสื้อผ้า|เปลือย|cởi\s*đồ|khỏa\s*thân|telanjang|buka\s+baju)/i,
|
|
57
|
+
];
|
|
58
|
+
function hasUndressIntent(text) {
|
|
59
|
+
if (!text)
|
|
60
|
+
return false;
|
|
61
|
+
return UNDRESS_PATTERNS.some((re) => re.test(text));
|
|
62
|
+
}
|
|
63
|
+
let client = null;
|
|
64
|
+
function getClient() {
|
|
65
|
+
if (!process.env.OPENAI_API_KEY)
|
|
66
|
+
return null;
|
|
67
|
+
if (!client) {
|
|
68
|
+
client = new openai_1.default({
|
|
69
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
70
|
+
timeout: MODERATION_TIMEOUT_MS,
|
|
71
|
+
maxRetries: 0,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return client;
|
|
75
|
+
}
|
|
76
|
+
function isHttpUrl(v) {
|
|
77
|
+
return /^https?:\/\//i.test(v);
|
|
78
|
+
}
|
|
79
|
+
function withTimeout(p, ms) {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const t = setTimeout(() => reject(new Error(`moderation timeout after ${ms}ms`)), ms);
|
|
82
|
+
p.then((v) => {
|
|
83
|
+
clearTimeout(t);
|
|
84
|
+
resolve(v);
|
|
85
|
+
}, (e) => {
|
|
86
|
+
clearTimeout(t);
|
|
87
|
+
reject(e);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async function moderateOne(openai, input) {
|
|
92
|
+
const resp = await withTimeout(openai.moderations.create({ model: "omni-moderation-latest", input }), MODERATION_TIMEOUT_MS);
|
|
93
|
+
return resp.results[0] ?? null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Moderate a generation request's text + image inputs. Never throws.
|
|
97
|
+
*/
|
|
98
|
+
async function moderateGenerationInput(input) {
|
|
99
|
+
const text = input.texts
|
|
100
|
+
.filter((t) => typeof t === "string" && t.trim().length > 0)
|
|
101
|
+
.join("\n")
|
|
102
|
+
.slice(0, MAX_TEXT_CHARS);
|
|
103
|
+
const imageUrls = Array.from(new Set((input.imageUrls ?? []).filter(isHttpUrl))).slice(0, MAX_IMAGES);
|
|
104
|
+
const hasImage = imageUrls.length > 0;
|
|
105
|
+
// ── Cheap deterministic prefilter (works even if OpenAI is down) ─────────
|
|
106
|
+
if (hasImage && hasUndressIntent(text)) {
|
|
107
|
+
return {
|
|
108
|
+
blocked: true,
|
|
109
|
+
categories: ["keyword:undress"],
|
|
110
|
+
reason: "undress/nudify intent combined with an image input",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (!text && !hasImage)
|
|
114
|
+
return { blocked: false, categories: [] };
|
|
115
|
+
const openai = getClient();
|
|
116
|
+
if (!openai) {
|
|
117
|
+
logger_1.logger.warn("generationModeration: OPENAI_API_KEY unset — failing open");
|
|
118
|
+
return { blocked: false, categories: [], failedOpen: true };
|
|
119
|
+
}
|
|
120
|
+
const calls = [];
|
|
121
|
+
if (text) {
|
|
122
|
+
calls.push(moderateOne(openai, text).then((result) => ({ kind: "text", result })));
|
|
123
|
+
}
|
|
124
|
+
for (const url of imageUrls) {
|
|
125
|
+
calls.push(moderateOne(openai, [{ type: "image_url", image_url: { url } }]).then((result) => ({
|
|
126
|
+
kind: "image",
|
|
127
|
+
result,
|
|
128
|
+
})));
|
|
129
|
+
}
|
|
130
|
+
const settled = await Promise.allSettled(calls);
|
|
131
|
+
let failures = 0;
|
|
132
|
+
let textSexual = false;
|
|
133
|
+
let textSexualScore = 0;
|
|
134
|
+
let minors = false;
|
|
135
|
+
let imageSexualScore = 0;
|
|
136
|
+
for (const s of settled) {
|
|
137
|
+
if (s.status === "rejected") {
|
|
138
|
+
failures++;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const r = s.value.result;
|
|
142
|
+
if (!r)
|
|
143
|
+
continue;
|
|
144
|
+
if (r.categories["sexual/minors"])
|
|
145
|
+
minors = true;
|
|
146
|
+
if (s.value.kind === "text") {
|
|
147
|
+
textSexual = textSexual || r.categories.sexual;
|
|
148
|
+
textSexualScore = Math.max(textSexualScore, r.category_scores.sexual);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
imageSexualScore = Math.max(imageSexualScore, r.category_scores.sexual);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (failures > 0) {
|
|
155
|
+
const firstErr = settled.find((s) => s.status === "rejected");
|
|
156
|
+
logger_1.logger.warn("generationModeration: OpenAI moderation call failed — failing open for that input", {
|
|
157
|
+
failures,
|
|
158
|
+
total: settled.length,
|
|
159
|
+
err: firstErr?.reason instanceof Error
|
|
160
|
+
? firstErr.reason.message
|
|
161
|
+
: String(firstErr?.reason ?? ""),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (minors) {
|
|
165
|
+
return { blocked: true, categories: ["sexual/minors"], reason: "sexual/minors flagged" };
|
|
166
|
+
}
|
|
167
|
+
if (textSexual && hasImage && textSexualScore > TEXT_WITH_IMAGE_SEXUAL_THRESHOLD) {
|
|
168
|
+
return {
|
|
169
|
+
blocked: true,
|
|
170
|
+
categories: ["sexual", "image-input"],
|
|
171
|
+
reason: `sexual text (score ${textSexualScore.toFixed(2)}) with an image/reference input`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (imageSexualScore > IMAGE_SEXUAL_THRESHOLD) {
|
|
175
|
+
return {
|
|
176
|
+
blocked: true,
|
|
177
|
+
categories: ["sexual", "image"],
|
|
178
|
+
reason: `sexual input image (score ${imageSexualScore.toFixed(2)})`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (textSexualScore > TEXT_ONLY_SEXUAL_THRESHOLD) {
|
|
182
|
+
return {
|
|
183
|
+
blocked: true,
|
|
184
|
+
categories: ["sexual"],
|
|
185
|
+
reason: `sexual text (score ${textSexualScore.toFixed(2)})`,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
blocked: false,
|
|
190
|
+
categories: [],
|
|
191
|
+
failedOpen: failures > 0 && failures === settled.length ? true : undefined,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
// ── Generic input extraction ────────────────────────────────────────────────
|
|
195
|
+
/**
|
|
196
|
+
* Keys whose string values are user/LLM-authored creative text. Deliberately
|
|
197
|
+
* broad — a general walker instead of per-endpoint field lists, so new fields
|
|
198
|
+
* on existing schemas are covered without touching this file.
|
|
199
|
+
*/
|
|
200
|
+
const TEXT_KEY_RE = /(prompt|lyric|text|script|description|caption|message|content|intent|title|query|goal|idea|theme|note|instruction|narration|voiceover|story|premise|logline|dialog|character|persona|tagline|subject|scene|brief|concept|summary|action|line|name)/i;
|
|
201
|
+
/** Keys that hold an image the generation will be conditioned on. */
|
|
202
|
+
const IMAGE_KEY_RE = /(image|portrait|face|photo|frame|refer|avatar|plate|subject|character|person|selfie|sheet|still|keyframe|cover|poster|asset)/i;
|
|
203
|
+
/** Never image inputs worth moderating (brand marks, fonts, page captures, media). */
|
|
204
|
+
const IMAGE_KEY_EXCLUDE_RE = /(logo|font|screenshot|mask|video|audio|website|page|webhook|callback|success|cancel)/i;
|
|
205
|
+
const ID_KEY_RE = /(id|ids|key|modelKey|provider|lang|language|locale|format|mode|status|aspect|ratio|resolution|quality)$/i;
|
|
206
|
+
const IMAGE_EXT_RE = /\.(png|jpe?g|webp|gif|heic|heif|avif|bmp)(\?|#|$)/i;
|
|
207
|
+
const NON_IMAGE_MEDIA_EXT_RE = /\.(mp4|mov|webm|m4v|mkv|avi|mp3|wav|m4a|aac|ogg|flac|srt|vtt|json|pdf|ttf|otf|woff2?)(\?|#|$)/i;
|
|
208
|
+
const MAX_WALK_DEPTH = 8;
|
|
209
|
+
const MAX_STRINGS = 400;
|
|
210
|
+
/**
|
|
211
|
+
* Walk an arbitrary request body / plan / tool-args object and collect the
|
|
212
|
+
* creative texts and image URLs that a generation would consume.
|
|
213
|
+
*/
|
|
214
|
+
function collectModerationInputs(...roots) {
|
|
215
|
+
const texts = [];
|
|
216
|
+
const imageUrls = [];
|
|
217
|
+
let seen = 0;
|
|
218
|
+
const visit = (value, key, depth, parentIsImage) => {
|
|
219
|
+
if (seen > MAX_STRINGS || depth > MAX_WALK_DEPTH || value == null)
|
|
220
|
+
return;
|
|
221
|
+
if (typeof value === "string") {
|
|
222
|
+
seen++;
|
|
223
|
+
const v = value.trim();
|
|
224
|
+
if (!v)
|
|
225
|
+
return;
|
|
226
|
+
if (isHttpUrl(v)) {
|
|
227
|
+
// Video/audio files can't go through image moderation (OpenAI rejects them).
|
|
228
|
+
if (NON_IMAGE_MEDIA_EXT_RE.test(v))
|
|
229
|
+
return;
|
|
230
|
+
const keyIsImage = IMAGE_KEY_RE.test(key) && !IMAGE_KEY_EXCLUDE_RE.test(key);
|
|
231
|
+
const extIsImage = IMAGE_EXT_RE.test(v) && !IMAGE_KEY_EXCLUDE_RE.test(key);
|
|
232
|
+
if (keyIsImage || parentIsImage || extIsImage)
|
|
233
|
+
imageUrls.push(v);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (/^data:image\//i.test(v))
|
|
237
|
+
return; // inline data URIs: not fetched here
|
|
238
|
+
if (TEXT_KEY_RE.test(key) && !ID_KEY_RE.test(key))
|
|
239
|
+
texts.push(v);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (Array.isArray(value)) {
|
|
243
|
+
const arrIsImage = parentIsImage || (IMAGE_KEY_RE.test(key) && !IMAGE_KEY_EXCLUDE_RE.test(key));
|
|
244
|
+
for (const item of value)
|
|
245
|
+
visit(item, key, depth + 1, arrIsImage);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (typeof value === "object") {
|
|
249
|
+
const objIsImage = parentIsImage && !IMAGE_KEY_EXCLUDE_RE.test(key)
|
|
250
|
+
? true
|
|
251
|
+
: IMAGE_KEY_RE.test(key) && !IMAGE_KEY_EXCLUDE_RE.test(key);
|
|
252
|
+
for (const [k, v] of Object.entries(value)) {
|
|
253
|
+
visit(v, k, depth + 1, objIsImage && (k === "url" || k === "src" || k === "imageUrl"));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
for (const root of roots)
|
|
258
|
+
visit(root, "", 0, false);
|
|
259
|
+
return { texts, imageUrls };
|
|
260
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export { moderateText } from "./textModeration.service";
|
|
2
2
|
export type { TextModerationResult } from "./textModeration.service";
|
|
3
|
+
export { moderateGenerationInput, collectModerationInputs, hasUndressIntent, CONTENT_POLICY_VIOLATION_CODE, CONTENT_POLICY_VIOLATION_MESSAGE, } from "./generationModeration.service";
|
|
4
|
+
export type { GenerationModerationInput, GenerationModerationResult, } from "./generationModeration.service";
|
|
5
|
+
export { recordModerationStrike, isStrikeableProviderRejection, AUTO_BLOCK_REASON, STRIKE_WINDOW_MS, STRIKE_WINDOW_THRESHOLD, STRIKE_LIFETIME_THRESHOLD, } from "./moderationStrike.service";
|
|
6
|
+
export type { ModerationStrikeSource, ModerationStrikeDetail, ModerationStrikeLogEntry, ModerationStrikeOutcome, } from "./moderationStrike.service";
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/moderation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,YAAY,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/moderation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,YAAY,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC7B,gCAAgC,GACjC,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACV,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.moderateText = void 0;
|
|
3
|
+
exports.STRIKE_LIFETIME_THRESHOLD = exports.STRIKE_WINDOW_THRESHOLD = exports.STRIKE_WINDOW_MS = exports.AUTO_BLOCK_REASON = exports.isStrikeableProviderRejection = exports.recordModerationStrike = exports.CONTENT_POLICY_VIOLATION_MESSAGE = exports.CONTENT_POLICY_VIOLATION_CODE = exports.hasUndressIntent = exports.collectModerationInputs = exports.moderateGenerationInput = exports.moderateText = void 0;
|
|
4
4
|
var textModeration_service_1 = require("./textModeration.service");
|
|
5
5
|
Object.defineProperty(exports, "moderateText", { enumerable: true, get: function () { return textModeration_service_1.moderateText; } });
|
|
6
|
+
var generationModeration_service_1 = require("./generationModeration.service");
|
|
7
|
+
Object.defineProperty(exports, "moderateGenerationInput", { enumerable: true, get: function () { return generationModeration_service_1.moderateGenerationInput; } });
|
|
8
|
+
Object.defineProperty(exports, "collectModerationInputs", { enumerable: true, get: function () { return generationModeration_service_1.collectModerationInputs; } });
|
|
9
|
+
Object.defineProperty(exports, "hasUndressIntent", { enumerable: true, get: function () { return generationModeration_service_1.hasUndressIntent; } });
|
|
10
|
+
Object.defineProperty(exports, "CONTENT_POLICY_VIOLATION_CODE", { enumerable: true, get: function () { return generationModeration_service_1.CONTENT_POLICY_VIOLATION_CODE; } });
|
|
11
|
+
Object.defineProperty(exports, "CONTENT_POLICY_VIOLATION_MESSAGE", { enumerable: true, get: function () { return generationModeration_service_1.CONTENT_POLICY_VIOLATION_MESSAGE; } });
|
|
12
|
+
var moderationStrike_service_1 = require("./moderationStrike.service");
|
|
13
|
+
Object.defineProperty(exports, "recordModerationStrike", { enumerable: true, get: function () { return moderationStrike_service_1.recordModerationStrike; } });
|
|
14
|
+
Object.defineProperty(exports, "isStrikeableProviderRejection", { enumerable: true, get: function () { return moderationStrike_service_1.isStrikeableProviderRejection; } });
|
|
15
|
+
Object.defineProperty(exports, "AUTO_BLOCK_REASON", { enumerable: true, get: function () { return moderationStrike_service_1.AUTO_BLOCK_REASON; } });
|
|
16
|
+
Object.defineProperty(exports, "STRIKE_WINDOW_MS", { enumerable: true, get: function () { return moderationStrike_service_1.STRIKE_WINDOW_MS; } });
|
|
17
|
+
Object.defineProperty(exports, "STRIKE_WINDOW_THRESHOLD", { enumerable: true, get: function () { return moderationStrike_service_1.STRIKE_WINDOW_THRESHOLD; } });
|
|
18
|
+
Object.defineProperty(exports, "STRIKE_LIFETIME_THRESHOLD", { enumerable: true, get: function () { return moderationStrike_service_1.STRIKE_LIFETIME_THRESHOLD; } });
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moderation strike ledger (2026-11-25).
|
|
3
|
+
*
|
|
4
|
+
* WHY: the 2026-11 abuser fired ~950 generations (289 undressing prompts on
|
|
5
|
+
* real people's photos) and nothing connected the repeated rejections to the
|
|
6
|
+
* account. Every pre-check block and every provider content-policy rejection
|
|
7
|
+
* now records a strike on `users/{uid}`; crossing the threshold auto-blocks the
|
|
8
|
+
* account by stamping `blockedAt` / `blockedReason` (enforcement of those fields
|
|
9
|
+
* across auth / API / MCP / worker is owned by the account-block work — this
|
|
10
|
+
* module only sets them) and pages Slack via logger.error.
|
|
11
|
+
*
|
|
12
|
+
* Storage: `moderationStrikes` (lifetime counter) + `moderationStrikeLog`
|
|
13
|
+
* (rolling list of the last STRIKE_LOG_MAX entries, used for the 24h window).
|
|
14
|
+
* Written through the raw (converter-less) collection inside a transaction so
|
|
15
|
+
* concurrent strikes from parallel scenes don't lose increments.
|
|
16
|
+
*/
|
|
17
|
+
export type ModerationStrikeSource = "precheck" | "provider";
|
|
18
|
+
export interface ModerationStrikeDetail {
|
|
19
|
+
/** Entry point / tool that saw the violation (e.g. "video.generate", "sceneMonitor"). */
|
|
20
|
+
surface: string;
|
|
21
|
+
/** Classifier categories or provider error code. */
|
|
22
|
+
categories?: string[];
|
|
23
|
+
reason?: string;
|
|
24
|
+
jobId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Stable hash of the offending content. A strike with the same key as one
|
|
27
|
+
* already logged in the last 24h is NOT counted again — re-saving or retrying
|
|
28
|
+
* the same prompt must not walk a user toward an auto-block (review 2026-11-25).
|
|
29
|
+
*/
|
|
30
|
+
dedupeKey?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ModerationStrikeLogEntry {
|
|
33
|
+
at: number;
|
|
34
|
+
source: ModerationStrikeSource;
|
|
35
|
+
surface: string;
|
|
36
|
+
categories?: string[];
|
|
37
|
+
reason?: string;
|
|
38
|
+
jobId?: string;
|
|
39
|
+
dedupeKey?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ModerationStrikeOutcome {
|
|
42
|
+
totalStrikes: number;
|
|
43
|
+
strikesLast24h: number;
|
|
44
|
+
/** True when THIS strike crossed the threshold and set blockedAt. */
|
|
45
|
+
blockedNow: boolean;
|
|
46
|
+
/** True when the strike was a repeat of an already-counted one (not counted). */
|
|
47
|
+
deduped?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export declare const STRIKE_WINDOW_MS: number;
|
|
50
|
+
export declare const STRIKE_WINDOW_THRESHOLD = 5;
|
|
51
|
+
export declare const STRIKE_LIFETIME_THRESHOLD = 15;
|
|
52
|
+
export declare const AUTO_BLOCK_REASON = "auto: repeated content policy violations";
|
|
53
|
+
/**
|
|
54
|
+
* Record a strike. Never throws — a Firestore hiccup must not turn a clean
|
|
55
|
+
* 422 into a 500 (or crash the worker's monitor loop). Returns null on failure.
|
|
56
|
+
*/
|
|
57
|
+
export declare function recordModerationStrike(uid: string, source: ModerationStrikeSource, detail: ModerationStrikeDetail): Promise<ModerationStrikeOutcome | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Whether a provider error message is a SEXUAL/NSFW-type content-policy
|
|
60
|
+
* rejection worth a strike. Narrower than errorPaging.isContentPolicyError on
|
|
61
|
+
* purpose: excludes input-format errors (image too small, unsupported
|
|
62
|
+
* language), real-person/privacy refusals (Seedance PrivacyInformation fires on
|
|
63
|
+
* any photoreal face, incl. users' own), and copyright — a legit user should
|
|
64
|
+
* not drift toward an auto-block for those.
|
|
65
|
+
*/
|
|
66
|
+
export declare function isStrikeableProviderRejection(errorMessage: string | undefined): boolean;
|
|
67
|
+
//# sourceMappingURL=moderationStrike.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moderationStrike.service.d.ts","sourceRoot":"","sources":["../../../src/services/moderation/moderationStrike.service.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,sBAAsB,GAAG,UAAU,GAAG,UAAU,CAAC;AAE7D,MAAM,WAAW,sBAAsB;IACrC,yFAAyF;IACzF,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,sBAAsB,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,UAAU,EAAE,OAAO,CAAC;IACpB,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,gBAAgB,QAAsB,CAAC;AACpD,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,eAAO,MAAM,iBAAiB,6CAA6C,CAAC;AAE5E;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,sBAAsB,EAC9B,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CA2FzC;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAkBvF"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AUTO_BLOCK_REASON = exports.STRIKE_LIFETIME_THRESHOLD = exports.STRIKE_WINDOW_THRESHOLD = exports.STRIKE_WINDOW_MS = void 0;
|
|
4
|
+
exports.recordModerationStrike = recordModerationStrike;
|
|
5
|
+
exports.isStrikeableProviderRejection = isStrikeableProviderRejection;
|
|
6
|
+
const firebase_1 = require("../../libs/firebase");
|
|
7
|
+
const logger_1 = require("../../utils/logger");
|
|
8
|
+
exports.STRIKE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
9
|
+
exports.STRIKE_WINDOW_THRESHOLD = 5;
|
|
10
|
+
exports.STRIKE_LIFETIME_THRESHOLD = 15;
|
|
11
|
+
const STRIKE_LOG_MAX = 25;
|
|
12
|
+
exports.AUTO_BLOCK_REASON = "auto: repeated content policy violations";
|
|
13
|
+
/**
|
|
14
|
+
* Record a strike. Never throws — a Firestore hiccup must not turn a clean
|
|
15
|
+
* 422 into a 500 (or crash the worker's monitor loop). Returns null on failure.
|
|
16
|
+
*/
|
|
17
|
+
async function recordModerationStrike(uid, source, detail) {
|
|
18
|
+
if (!uid)
|
|
19
|
+
return null;
|
|
20
|
+
const ref = firebase_1.firestore.collection("users").doc(uid);
|
|
21
|
+
try {
|
|
22
|
+
const outcome = await firebase_1.firestore.runTransaction(async (tx) => {
|
|
23
|
+
const snap = await tx.get(ref);
|
|
24
|
+
if (!snap.exists)
|
|
25
|
+
return null;
|
|
26
|
+
const data = snap.data() ?? {};
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
const prevTotal = typeof data.moderationStrikes === "number" ? data.moderationStrikes : 0;
|
|
29
|
+
const prevLog = Array.isArray(data.moderationStrikeLog)
|
|
30
|
+
? data.moderationStrikeLog.filter((e) => e && typeof e.at === "number")
|
|
31
|
+
: [];
|
|
32
|
+
// Same content already struck within the window → don't count it again.
|
|
33
|
+
const dedupeKey = detail.dedupeKey ?? (detail.jobId ? `job:${detail.jobId}` : undefined);
|
|
34
|
+
if (dedupeKey &&
|
|
35
|
+
prevLog.some((e) => e.dedupeKey === dedupeKey && now - e.at <= exports.STRIKE_WINDOW_MS)) {
|
|
36
|
+
return {
|
|
37
|
+
totalStrikes: prevTotal,
|
|
38
|
+
strikesLast24h: prevLog.filter((e) => now - e.at <= exports.STRIKE_WINDOW_MS).length,
|
|
39
|
+
blockedNow: false,
|
|
40
|
+
deduped: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const entry = {
|
|
44
|
+
at: now,
|
|
45
|
+
source,
|
|
46
|
+
surface: detail.surface,
|
|
47
|
+
...(detail.categories?.length ? { categories: detail.categories.slice(0, 8) } : {}),
|
|
48
|
+
...(detail.reason ? { reason: detail.reason.slice(0, 300) } : {}),
|
|
49
|
+
...(detail.jobId ? { jobId: detail.jobId } : {}),
|
|
50
|
+
...(dedupeKey ? { dedupeKey } : {}),
|
|
51
|
+
};
|
|
52
|
+
const log = [...prevLog, entry].slice(-STRIKE_LOG_MAX);
|
|
53
|
+
const totalStrikes = prevTotal + 1;
|
|
54
|
+
const strikesLast24h = log.filter((e) => now - e.at <= exports.STRIKE_WINDOW_MS).length;
|
|
55
|
+
const alreadyBlocked = Boolean(data.blockedAt);
|
|
56
|
+
const shouldBlock = !alreadyBlocked &&
|
|
57
|
+
(strikesLast24h >= exports.STRIKE_WINDOW_THRESHOLD || totalStrikes >= exports.STRIKE_LIFETIME_THRESHOLD);
|
|
58
|
+
const patch = {
|
|
59
|
+
moderationStrikes: totalStrikes,
|
|
60
|
+
moderationStrikeLog: log,
|
|
61
|
+
lastModerationStrikeAt: now,
|
|
62
|
+
};
|
|
63
|
+
if (shouldBlock) {
|
|
64
|
+
patch.blockedAt = new Date(now);
|
|
65
|
+
patch.blockedReason = exports.AUTO_BLOCK_REASON;
|
|
66
|
+
patch.blockedBy = "moderation";
|
|
67
|
+
}
|
|
68
|
+
tx.update(ref, patch);
|
|
69
|
+
return { totalStrikes, strikesLast24h, blockedNow: shouldBlock };
|
|
70
|
+
});
|
|
71
|
+
if (!outcome)
|
|
72
|
+
return null;
|
|
73
|
+
if (outcome.deduped)
|
|
74
|
+
return outcome;
|
|
75
|
+
if (outcome.blockedNow) {
|
|
76
|
+
// Pages Slack (logger.error → Slack transport).
|
|
77
|
+
logger_1.logger.error("moderation: account auto-blocked for repeated content policy violations", {
|
|
78
|
+
uid,
|
|
79
|
+
totalStrikes: outcome.totalStrikes,
|
|
80
|
+
strikesLast24h: outcome.strikesLast24h,
|
|
81
|
+
lastSource: source,
|
|
82
|
+
lastSurface: detail.surface,
|
|
83
|
+
lastCategories: detail.categories,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
logger_1.logger.warn("moderation: strike recorded", {
|
|
88
|
+
uid,
|
|
89
|
+
source,
|
|
90
|
+
surface: detail.surface,
|
|
91
|
+
categories: detail.categories,
|
|
92
|
+
totalStrikes: outcome.totalStrikes,
|
|
93
|
+
strikesLast24h: outcome.strikesLast24h,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return outcome;
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
logger_1.logger.warn("moderation: failed to record strike", {
|
|
100
|
+
uid,
|
|
101
|
+
source,
|
|
102
|
+
surface: detail.surface,
|
|
103
|
+
err: err instanceof Error ? err.message : String(err),
|
|
104
|
+
});
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Whether a provider error message is a SEXUAL/NSFW-type content-policy
|
|
110
|
+
* rejection worth a strike. Narrower than errorPaging.isContentPolicyError on
|
|
111
|
+
* purpose: excludes input-format errors (image too small, unsupported
|
|
112
|
+
* language), real-person/privacy refusals (Seedance PrivacyInformation fires on
|
|
113
|
+
* any photoreal face, incl. users' own), and copyright — a legit user should
|
|
114
|
+
* not drift toward an auto-block for those.
|
|
115
|
+
*/
|
|
116
|
+
function isStrikeableProviderRejection(errorMessage) {
|
|
117
|
+
if (!errorMessage)
|
|
118
|
+
return false;
|
|
119
|
+
const lower = errorMessage.toLowerCase();
|
|
120
|
+
if (/privacy|copyright|trademark|celebrity|public\s*figure/.test(lower))
|
|
121
|
+
return false;
|
|
122
|
+
// 2026-11-25 (review): only rejections that explicitly name a sexual / minors
|
|
123
|
+
// category strike. Generic provider codes — Seedance `SensitiveContentDetected`,
|
|
124
|
+
// OpenAI `moderation_blocked`, `safety.*`, "content moderation" — also fire on
|
|
125
|
+
// violence, weapons, logos and other content the owner does NOT want penalized,
|
|
126
|
+
// and each strike also stamps `moderationRejected` (which disables reprocess).
|
|
127
|
+
// REMOVED FOR v1 — kept for reference (too broad: struck action/brand users):
|
|
128
|
+
// if (errorMessage.startsWith("moderation_blocked")) return true;
|
|
129
|
+
// if (/sensitivecontentdetected/i.test(errorMessage)) return true;
|
|
130
|
+
// if (/safety\.(input|output)\.(image|text|video)/i.test(errorMessage)) return true;
|
|
131
|
+
// if (lower.includes("content moderation")) return true;
|
|
132
|
+
// Kling's "risk control" is deliberately NOT counted either.
|
|
133
|
+
return /\b(nsfw|sexual(ly)?|sexual\/minors|nudity|nude|naked|porn(ographic)?|explicit\s+content|child\s+(sexual|abuse)|csam)\b/.test(lower);
|
|
134
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/rateLimiter/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/rateLimiter/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC"}
|
|
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./distributedRateLimiter.service"), exports);
|
|
18
|
+
__exportStar(require("./userRateLimiter.service"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-caller API rate limiter (2026-11-25).
|
|
3
|
+
*
|
|
4
|
+
* WHY: free LLM endpoints (agent plan/chat/persona, /v1/text/*, lyrics, demo
|
|
5
|
+
* prefill/triage, stock search) had no per-user limit at all, and the only
|
|
6
|
+
* limiter in the API (publicOutreach) was in-memory per instance and keyed on
|
|
7
|
+
* the spoofable LEFTMOST x-forwarded-for hop. This is a Redis fixed-window
|
|
8
|
+
* counter shared by every Functions instance, reusing BullMQ's single shared
|
|
9
|
+
* connection (no extra Redis client — prod has a ~30-client ceiling).
|
|
10
|
+
*
|
|
11
|
+
* FAIL-OPEN: if Redis is absent/slow (> REDIS_TIMEOUT_MS) we fall back to a
|
|
12
|
+
* small per-instance in-memory counter — weaker, but never blocks the API on a
|
|
13
|
+
* Redis outage.
|
|
14
|
+
*/
|
|
15
|
+
export interface RateLimitWindow {
|
|
16
|
+
/** Window length in seconds (fixed window aligned to epoch). */
|
|
17
|
+
windowSec: number;
|
|
18
|
+
/** Max requests allowed within one window. */
|
|
19
|
+
max: number;
|
|
20
|
+
}
|
|
21
|
+
export interface RateLimitResult {
|
|
22
|
+
allowed: boolean;
|
|
23
|
+
/** Seconds until the exhausted window resets (0 when allowed). */
|
|
24
|
+
retryAfterSec: number;
|
|
25
|
+
/** The window that was exhausted, when blocked. */
|
|
26
|
+
exceeded?: RateLimitWindow;
|
|
27
|
+
/** "redis" | "memory" — which backend decided. */
|
|
28
|
+
backend: "redis" | "memory";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Consume one request for `subject` (uid or `ip:<addr>`) in `bucket`
|
|
32
|
+
* (logical endpoint group) against every window. Never throws.
|
|
33
|
+
*/
|
|
34
|
+
export declare function consumeRateLimit(bucket: string, subject: string, windows: RateLimitWindow[]): Promise<RateLimitResult>;
|
|
35
|
+
export interface QuotaMeter {
|
|
36
|
+
/** Meter name (part of the key), e.g. "count" / "bytes". */
|
|
37
|
+
name: string;
|
|
38
|
+
/** Amount this request consumes. */
|
|
39
|
+
cost: number;
|
|
40
|
+
/** Max total amount per window. */
|
|
41
|
+
max: number;
|
|
42
|
+
}
|
|
43
|
+
export interface QuotaResult {
|
|
44
|
+
allowed: boolean;
|
|
45
|
+
retryAfterSec: number;
|
|
46
|
+
/** The meter that would be exceeded, when blocked. */
|
|
47
|
+
exceeded?: QuotaMeter;
|
|
48
|
+
backend: "redis" | "memory";
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Consume `cost` from each meter of a fixed window (2026-11-25, upload quota).
|
|
52
|
+
* Same Redis/in-memory fail-open behaviour as consumeRateLimit. Never throws.
|
|
53
|
+
*/
|
|
54
|
+
export declare function consumeQuota(bucket: string, subject: string, windowSec: number, meters: QuotaMeter[]): Promise<QuotaResult>;
|
|
55
|
+
//# sourceMappingURL=userRateLimiter.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRateLimiter.service.d.ts","sourceRoot":"","sources":["../../../src/services/rateLimiter/userRateLimiter.service.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,kEAAkE;IAClE,aAAa,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,kDAAkD;IAClD,OAAO,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC7B;AA2ED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,EAAE,GACzB,OAAO,CAAC,eAAe,CAAC,CAyC1B;AAID,MAAM,WAAW,UAAU;IACzB,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,OAAO,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC7B;AA2BD;;;GAGG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,UAAU,EAAE,GACnB,OAAO,CAAC,WAAW,CAAC,CAgEtB"}
|