Initial commit for Greenlens

This commit is contained in:
Timo Knuth
2026-03-16 21:31:46 +01:00
parent 307135671f
commit 05d4f6e78b
573 changed files with 54233 additions and 1891 deletions

17
utils/idempotency.ts Normal file
View File

@@ -0,0 +1,17 @@
const sanitizeSeed = (value: string): string => {
return value
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '')
.slice(0, 36);
};
export const createIdempotencyKey = (scope: string, seed?: string): string => {
const base = sanitizeSeed(scope || 'action') || 'action';
const seedPart = seed ? sanitizeSeed(seed) : '';
const timestamp = Date.now().toString(36);
const random = Math.random().toString(36).slice(2, 10);
return seedPart
? `${base}-${seedPart}-${timestamp}-${random}`
: `${base}-${timestamp}-${random}`;
};