mirror of
https://github.com/arthur-pbty/flint.git
synced 2026-08-05 12:42:41 +02:00
25 lines
675 B
TypeScript
25 lines
675 B
TypeScript
const sanitizeSegment = (segment: string): string =>
|
|
segment.replace(/[^a-zA-Z0-9:_-]/g, "_");
|
|
|
|
export const tenantRedisKey = (
|
|
tenantId: string,
|
|
...parts: string[]
|
|
): string => {
|
|
const tail = parts.map(sanitizeSegment).join(":");
|
|
return tail.length > 0
|
|
? `tenant:${sanitizeSegment(tenantId)}:${tail}`
|
|
: `tenant:${sanitizeSegment(tenantId)}`;
|
|
};
|
|
|
|
export const tenantRateLimitKey = (tenantId: string, scope: string): string => {
|
|
return tenantRedisKey(tenantId, "ratelimit", scope);
|
|
};
|
|
|
|
export const tenantBotRedisKey = (
|
|
tenantId: string,
|
|
botId: string,
|
|
...parts: string[]
|
|
): string => {
|
|
return tenantRedisKey(tenantId, "bot", botId, ...parts);
|
|
};
|