@nekutima/biome-sdk 0.1.18
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/README.md +100 -0
- package/dist/auth/auth.service.d.ts +90 -0
- package/dist/auth/auth.service.d.ts.map +1 -0
- package/dist/auth/auth.service.js +166 -0
- package/dist/auth/auth.service.js.map +1 -0
- package/dist/auth/types.d.ts +19 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +3 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/core/configuration.d.ts +26 -0
- package/dist/core/configuration.d.ts.map +1 -0
- package/dist/core/configuration.js +3 -0
- package/dist/core/configuration.js.map +1 -0
- package/dist/core/error-handler.d.ts +24 -0
- package/dist/core/error-handler.d.ts.map +1 -0
- package/dist/core/error-handler.js +76 -0
- package/dist/core/error-handler.js.map +1 -0
- package/dist/core/http-client.d.ts +43 -0
- package/dist/core/http-client.d.ts.map +1 -0
- package/dist/core/http-client.js +97 -0
- package/dist/core/http-client.js.map +1 -0
- package/dist/core/state-manager.d.ts +16 -0
- package/dist/core/state-manager.d.ts.map +1 -0
- package/dist/core/state-manager.js +33 -0
- package/dist/core/state-manager.js.map +1 -0
- package/dist/files/file-upload.d.ts +60 -0
- package/dist/files/file-upload.d.ts.map +1 -0
- package/dist/files/file-upload.js +121 -0
- package/dist/files/file-upload.js.map +1 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +140 -0
- package/dist/index.js.map +1 -0
- package/dist/models/api-error.model.d.ts +31 -0
- package/dist/models/api-error.model.d.ts.map +1 -0
- package/dist/models/api-error.model.js +53 -0
- package/dist/models/api-error.model.js.map +1 -0
- package/dist/models/api-response.model.d.ts +51 -0
- package/dist/models/api-response.model.d.ts.map +1 -0
- package/dist/models/api-response.model.js +77 -0
- package/dist/models/api-response.model.js.map +1 -0
- package/dist/models/chat.model.d.ts +59 -0
- package/dist/models/chat.model.d.ts.map +1 -0
- package/dist/models/chat.model.js +3 -0
- package/dist/models/chat.model.js.map +1 -0
- package/dist/models/ecosystem.model.d.ts +16 -0
- package/dist/models/ecosystem.model.d.ts.map +1 -0
- package/dist/models/ecosystem.model.js +7 -0
- package/dist/models/ecosystem.model.js.map +1 -0
- package/dist/models/file.model.d.ts +67 -0
- package/dist/models/file.model.d.ts.map +1 -0
- package/dist/models/file.model.js +3 -0
- package/dist/models/file.model.js.map +1 -0
- package/dist/models/notification.model.d.ts +172 -0
- package/dist/models/notification.model.d.ts.map +1 -0
- package/dist/models/notification.model.js +77 -0
- package/dist/models/notification.model.js.map +1 -0
- package/dist/models/person.model.d.ts +94 -0
- package/dist/models/person.model.d.ts.map +1 -0
- package/dist/models/person.model.js +14 -0
- package/dist/models/person.model.js.map +1 -0
- package/dist/models/project.model.d.ts +62 -0
- package/dist/models/project.model.d.ts.map +1 -0
- package/dist/models/project.model.js +93 -0
- package/dist/models/project.model.js.map +1 -0
- package/dist/models/task-update.model.d.ts +28 -0
- package/dist/models/task-update.model.d.ts.map +1 -0
- package/dist/models/task-update.model.js +8 -0
- package/dist/models/task-update.model.js.map +1 -0
- package/dist/models/task-url.model.d.ts +16 -0
- package/dist/models/task-url.model.d.ts.map +1 -0
- package/dist/models/task-url.model.js +3 -0
- package/dist/models/task-url.model.js.map +1 -0
- package/dist/models/task.model.d.ts +120 -0
- package/dist/models/task.model.d.ts.map +1 -0
- package/dist/models/task.model.js +78 -0
- package/dist/models/task.model.js.map +1 -0
- package/dist/models/timezone.model.d.ts +19 -0
- package/dist/models/timezone.model.d.ts.map +1 -0
- package/dist/models/timezone.model.js +12 -0
- package/dist/models/timezone.model.js.map +1 -0
- package/dist/models/user.model.d.ts +101 -0
- package/dist/models/user.model.d.ts.map +1 -0
- package/dist/models/user.model.js +22 -0
- package/dist/models/user.model.js.map +1 -0
- package/dist/profiles/profile.service.d.ts +52 -0
- package/dist/profiles/profile.service.d.ts.map +1 -0
- package/dist/profiles/profile.service.js +119 -0
- package/dist/profiles/profile.service.js.map +1 -0
- package/dist/profiles/types.d.ts +1 -0
- package/dist/profiles/types.d.ts.map +1 -0
- package/dist/profiles/types.js +3 -0
- package/dist/profiles/types.js.map +1 -0
- package/dist/tasks/task-sorting.d.ts +51 -0
- package/dist/tasks/task-sorting.d.ts.map +1 -0
- package/dist/tasks/task-sorting.js +137 -0
- package/dist/tasks/task-sorting.js.map +1 -0
- package/dist/tasks/task.service.d.ts +134 -0
- package/dist/tasks/task.service.d.ts.map +1 -0
- package/dist/tasks/task.service.js +256 -0
- package/dist/tasks/task.service.js.map +1 -0
- package/dist/tasks/types.d.ts +2 -0
- package/dist/tasks/types.d.ts.map +1 -0
- package/dist/tasks/types.js +3 -0
- package/dist/tasks/types.js.map +1 -0
- package/dist/types/actor.types.d.ts +101 -0
- package/dist/types/actor.types.d.ts.map +1 -0
- package/dist/types/actor.types.js +135 -0
- package/dist/types/actor.types.js.map +1 -0
- package/dist/types/api.types.d.ts +43 -0
- package/dist/types/api.types.d.ts.map +1 -0
- package/dist/types/api.types.js +6 -0
- package/dist/types/api.types.js.map +1 -0
- package/dist/types/common.types.d.ts +40 -0
- package/dist/types/common.types.d.ts.map +1 -0
- package/dist/types/common.types.js +6 -0
- package/dist/types/common.types.js.map +1 -0
- package/dist/types/state-machine.types.d.ts +102 -0
- package/dist/types/state-machine.types.d.ts.map +1 -0
- package/dist/types/state-machine.types.js +18 -0
- package/dist/types/state-machine.types.js.map +1 -0
- package/dist/users/user.service.d.ts +49 -0
- package/dist/users/user.service.d.ts.map +1 -0
- package/dist/users/user.service.js +119 -0
- package/dist/users/user.service.js.map +1 -0
- package/dist/utils/date.utils.d.ts +60 -0
- package/dist/utils/date.utils.d.ts.map +1 -0
- package/dist/utils/date.utils.js +125 -0
- package/dist/utils/date.utils.js.map +1 -0
- package/dist/utils/username-generator.d.ts +76 -0
- package/dist/utils/username-generator.d.ts.map +1 -0
- package/dist/utils/username-generator.js +177 -0
- package/dist/utils/username-generator.js.map +1 -0
- package/dist/utils/validation.utils.d.ts +57 -0
- package/dist/utils/validation.utils.d.ts.map +1 -0
- package/dist/utils/validation.utils.js +117 -0
- package/dist/utils/validation.utils.js.map +1 -0
- package/dist/validation/password-strength.d.ts +66 -0
- package/dist/validation/password-strength.d.ts.map +1 -0
- package/dist/validation/password-strength.js +192 -0
- package/dist/validation/password-strength.js.map +1 -0
- package/dist/validation/schemas.d.ts +69 -0
- package/dist/validation/schemas.d.ts.map +1 -0
- package/dist/validation/schemas.js +94 -0
- package/dist/validation/schemas.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Creative Username Generator
|
|
4
|
+
*
|
|
5
|
+
* Generates unique, memorable usernames following the pattern:
|
|
6
|
+
* Adjective + Noun + Number (e.g., "BraveEagle2847", "SilverFox1923")
|
|
7
|
+
*
|
|
8
|
+
* This module is part of the SDK for reusability across frontend and backend.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Generates creative, memorable usernames
|
|
12
|
+
* - Optional uniqueness checking with retry logic
|
|
13
|
+
* - Max 10 retry attempts if collision occurs
|
|
14
|
+
* - Returns predictable format: AdjNounNNNN
|
|
15
|
+
*
|
|
16
|
+
* @module username-generator
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.generateCreativeUsername = generateCreativeUsername;
|
|
20
|
+
exports.generateUsernameSuggestions = generateUsernameSuggestions;
|
|
21
|
+
exports.isValidGeneratedUsername = isValidGeneratedUsername;
|
|
22
|
+
/**
|
|
23
|
+
* List of positive, family-friendly adjectives
|
|
24
|
+
*/
|
|
25
|
+
const ADJECTIVES = [
|
|
26
|
+
'Brave', 'Swift', 'Mighty', 'Noble', 'Wise', 'Bold', 'Calm', 'Eager',
|
|
27
|
+
'Fair', 'Glad', 'Happy', 'Jolly', 'Kind', 'Lively', 'Merry', 'Nice',
|
|
28
|
+
'Proud', 'Quick', 'Royal', 'Silent', 'Tender', 'Unique', 'Vivid', 'Warm',
|
|
29
|
+
'Bright', 'Clever', 'Daring', 'Epic', 'Fancy', 'Grand', 'Heroic', 'Ideal',
|
|
30
|
+
'Joyful', 'Lucky', 'Magic', 'Noble', 'Optimal', 'Prime', 'Radiant', 'Smart',
|
|
31
|
+
'Stellar', 'Super', 'True', 'Ultra', 'Vital', 'Wild', 'Zen', 'Active',
|
|
32
|
+
'Agile', 'Amber', 'Azure', 'Blazing', 'Cosmic', 'Crystal', 'Diamond', 'Dynamic',
|
|
33
|
+
'Electric', 'Emerald', 'Eternal', 'Fiery', 'Frozen', 'Golden', 'Infinite', 'Iron',
|
|
34
|
+
'Jade', 'Lunar', 'Mystic', 'Ocean', 'Phoenix', 'Quantum', 'Ruby', 'Sacred',
|
|
35
|
+
'Shadow', 'Silver', 'Solar', 'Sonic', 'Starlit', 'Thunder', 'Titan', 'Velvet'
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* List of animals, objects, and nature nouns
|
|
39
|
+
*/
|
|
40
|
+
const NOUNS = [
|
|
41
|
+
'Eagle', 'Lion', 'Tiger', 'Bear', 'Wolf', 'Hawk', 'Falcon', 'Dragon',
|
|
42
|
+
'Phoenix', 'Griffin', 'Raven', 'Panther', 'Jaguar', 'Leopard', 'Cheetah', 'Cobra',
|
|
43
|
+
'Shark', 'Orca', 'Dolphin', 'Whale', 'Fox', 'Owl', 'Lynx', 'Puma',
|
|
44
|
+
'Stallion', 'Mustang', 'Thunder', 'Storm', 'Blaze', 'Frost', 'Flame', 'Wave',
|
|
45
|
+
'Mountain', 'River', 'Ocean', 'Forest', 'Desert', 'Valley', 'Canyon', 'Peak',
|
|
46
|
+
'Star', 'Moon', 'Sun', 'Comet', 'Nova', 'Galaxy', 'Nebula', 'Cosmos',
|
|
47
|
+
'Knight', 'Warrior', 'Hunter', 'Guardian', 'Champion', 'Legend', 'Hero', 'Titan',
|
|
48
|
+
'Wizard', 'Sage', 'Oracle', 'Mystic', 'Prophet', 'Seer', 'Druid', 'Mage',
|
|
49
|
+
'Arrow', 'Blade', 'Shield', 'Crown', 'Sword', 'Axe', 'Hammer', 'Lance',
|
|
50
|
+
'Crystal', 'Diamond', 'Ruby', 'Emerald', 'Sapphire', 'Pearl', 'Jade', 'Opal'
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* Generate a random 4-digit number
|
|
54
|
+
* @returns A number between 1000 and 9999
|
|
55
|
+
*/
|
|
56
|
+
function generateRandomNumber() {
|
|
57
|
+
return Math.floor(Math.random() * 9000) + 1000;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get a random element from an array
|
|
61
|
+
* @param array - The array to pick from
|
|
62
|
+
* @returns A random element from the array
|
|
63
|
+
*/
|
|
64
|
+
function getRandomElement(array) {
|
|
65
|
+
return array[Math.floor(Math.random() * array.length)];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generate a creative username following the pattern: Adjective + Noun + Number
|
|
69
|
+
*
|
|
70
|
+
* @param checkUniqueness - Optional function to check if username is already taken.
|
|
71
|
+
* Should return Promise<true> if unique, Promise<false> if taken.
|
|
72
|
+
* @param maxAttempts - Maximum number of retry attempts if collision occurs (default: 10)
|
|
73
|
+
* @returns Promise<string> - A unique username following the pattern AdjNounNNNN
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // Without uniqueness check
|
|
78
|
+
* const username = await generateCreativeUsername();
|
|
79
|
+
* console.log(username); // "BraveEagle2847"
|
|
80
|
+
*
|
|
81
|
+
* // With uniqueness check
|
|
82
|
+
* const username = await generateCreativeUsername(async (name) => {
|
|
83
|
+
* const exists = await db.users.findOne({ username: name });
|
|
84
|
+
* return !exists; // Return true if unique, false if taken
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @throws {Error} If unable to generate unique username after maxAttempts
|
|
89
|
+
*/
|
|
90
|
+
async function generateCreativeUsername(checkUniqueness, maxAttempts = 10) {
|
|
91
|
+
let attempts = 0;
|
|
92
|
+
while (attempts < maxAttempts) {
|
|
93
|
+
attempts++;
|
|
94
|
+
// Generate username: Adjective + Noun + Number
|
|
95
|
+
const adjective = getRandomElement(ADJECTIVES);
|
|
96
|
+
const noun = getRandomElement(NOUNS);
|
|
97
|
+
const number = generateRandomNumber();
|
|
98
|
+
const username = `${adjective}${noun}${number}`;
|
|
99
|
+
// If no uniqueness check provided, return immediately
|
|
100
|
+
if (!checkUniqueness) {
|
|
101
|
+
return username;
|
|
102
|
+
}
|
|
103
|
+
// Check if username is unique
|
|
104
|
+
try {
|
|
105
|
+
const isUnique = await checkUniqueness(username);
|
|
106
|
+
if (isUnique) {
|
|
107
|
+
return username;
|
|
108
|
+
}
|
|
109
|
+
// If not unique, retry
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
// If uniqueness check fails, log error but continue retrying
|
|
113
|
+
console.error('Error checking username uniqueness:', error);
|
|
114
|
+
// On last attempt, throw error
|
|
115
|
+
if (attempts === maxAttempts) {
|
|
116
|
+
throw new Error('Unable to verify username uniqueness after multiple attempts');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// If we've exhausted all attempts
|
|
121
|
+
throw new Error(`Unable to generate unique username after ${maxAttempts} attempts`);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Generate multiple username suggestions
|
|
125
|
+
*
|
|
126
|
+
* @param count - Number of suggestions to generate (default: 3)
|
|
127
|
+
* @returns Promise<string[]> - Array of username suggestions
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const suggestions = await generateUsernameSuggestions(5);
|
|
132
|
+
* console.log(suggestions);
|
|
133
|
+
* // ["BraveEagle2847", "SilverFox1923", "MightyTiger4567", "NobleWolf3892", "SwiftHawk7651"]
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
async function generateUsernameSuggestions(count = 3) {
|
|
137
|
+
const suggestions = [];
|
|
138
|
+
const usedCombinations = new Set();
|
|
139
|
+
while (suggestions.length < count) {
|
|
140
|
+
const adjective = getRandomElement(ADJECTIVES);
|
|
141
|
+
const noun = getRandomElement(NOUNS);
|
|
142
|
+
const combination = `${adjective}${noun}`;
|
|
143
|
+
// Ensure we don't generate duplicate combinations in the same batch
|
|
144
|
+
if (!usedCombinations.has(combination)) {
|
|
145
|
+
usedCombinations.add(combination);
|
|
146
|
+
const number = generateRandomNumber();
|
|
147
|
+
suggestions.push(`${combination}${number}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return suggestions;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Validate username format
|
|
154
|
+
*
|
|
155
|
+
* Checks if a username matches the expected pattern:
|
|
156
|
+
* - Starts with uppercase letter
|
|
157
|
+
* - Followed by lowercase letters
|
|
158
|
+
* - Followed by uppercase letter
|
|
159
|
+
* - Followed by lowercase letters
|
|
160
|
+
* - Ends with 4 digits
|
|
161
|
+
*
|
|
162
|
+
* @param username - The username to validate
|
|
163
|
+
* @returns true if username matches the generated format, false otherwise
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* isValidGeneratedUsername('BraveEagle2847'); // true
|
|
168
|
+
* isValidGeneratedUsername('braveEagle2847'); // false (lowercase start)
|
|
169
|
+
* isValidGeneratedUsername('BraveEagle284'); // false (only 3 digits)
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
function isValidGeneratedUsername(username) {
|
|
173
|
+
// Pattern: Capital letter + lowercase letters + Capital letter + lowercase letters + 4 digits
|
|
174
|
+
const pattern = /^[A-Z][a-z]+[A-Z][a-z]+\d{4}$/;
|
|
175
|
+
return pattern.test(username);
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=username-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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E,CAAC;IACjC,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE3C,OAAO,WAAW,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;QAChC,MAAM,SAAS,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,WAAW,GAAG,GAAG,SAAS,GAAG,IAAI,EAAE,CAAC;QAE1C,oEAAoE;QACpE,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YAClC,MAAM,MAAM,GAAG,oBAAoB,EAAE,CAAC;YACtC,WAAW,CAAC,IAAI,CAAC,GAAG,WAAW,GAAG,MAAM,EAAE,CAAC,CAAC;QAChD,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,wBAAwB,CAAC,QAAgB;IACrD,8FAA8F;IAC9F,MAAM,OAAO,GAAG,+BAA+B,CAAC;IAChD,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for Biome platform
|
|
3
|
+
*/
|
|
4
|
+
import { ValidationError } from '../types/api.types';
|
|
5
|
+
/**
|
|
6
|
+
* Validates if a value is a valid email address
|
|
7
|
+
*/
|
|
8
|
+
export declare const isValidEmail: (email: string) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Validates if a value is a valid URL
|
|
11
|
+
*/
|
|
12
|
+
export declare const isValidUrl: (url: string) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Validates if a value is a valid date
|
|
15
|
+
*/
|
|
16
|
+
export declare const isValidDate: (date: any) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Validates if a value is a valid number
|
|
19
|
+
*/
|
|
20
|
+
export declare const isValidNumber: (value: any) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Validates if a value is a valid integer
|
|
23
|
+
*/
|
|
24
|
+
export declare const isValidInteger: (value: any) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Validates if a value is a valid positive number
|
|
27
|
+
*/
|
|
28
|
+
export declare const isValidPositiveNumber: (value: any) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Validates if a string is not empty
|
|
31
|
+
*/
|
|
32
|
+
export declare const isNotEmpty: (value: string) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Validates if a string has a minimum length
|
|
35
|
+
*/
|
|
36
|
+
export declare const hasMinLength: (value: string, minLength: number) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Validates if a string has a maximum length
|
|
39
|
+
*/
|
|
40
|
+
export declare const hasMaxLength: (value: string, maxLength: number) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Validates if a value is in a given range
|
|
43
|
+
*/
|
|
44
|
+
export declare const isInRange: (value: number, min: number, max: number) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Validates if a value is one of the allowed values
|
|
47
|
+
*/
|
|
48
|
+
export declare const isOneOf: <T>(value: T, allowedValues: T[]) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a validation error object
|
|
51
|
+
*/
|
|
52
|
+
export declare const createValidationError: (field: string, message: string, value?: any) => ValidationError;
|
|
53
|
+
/**
|
|
54
|
+
* Validates an object against a schema
|
|
55
|
+
*/
|
|
56
|
+
export declare const validateObject: <T>(obj: any, schema: Record<keyof T, (value: any) => boolean>) => ValidationError[];
|
|
57
|
+
//# sourceMappingURL=validation.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.utils.d.ts","sourceRoot":"","sources":["../../src/utils/validation.utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,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|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validation utilities for Biome platform
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateObject = exports.createValidationError = exports.isOneOf = exports.isInRange = exports.hasMaxLength = exports.hasMinLength = exports.isNotEmpty = exports.isValidPositiveNumber = exports.isValidInteger = exports.isValidNumber = exports.isValidDate = exports.isValidUrl = exports.isValidEmail = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Validates if a value is a valid email address
|
|
9
|
+
*/
|
|
10
|
+
const isValidEmail = (email) => {
|
|
11
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
12
|
+
return emailRegex.test(email);
|
|
13
|
+
};
|
|
14
|
+
exports.isValidEmail = isValidEmail;
|
|
15
|
+
/**
|
|
16
|
+
* Validates if a value is a valid URL
|
|
17
|
+
*/
|
|
18
|
+
const isValidUrl = (url) => {
|
|
19
|
+
try {
|
|
20
|
+
new URL(url);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.isValidUrl = isValidUrl;
|
|
28
|
+
/**
|
|
29
|
+
* Validates if a value is a valid date
|
|
30
|
+
*/
|
|
31
|
+
const isValidDate = (date) => {
|
|
32
|
+
if (!date)
|
|
33
|
+
return false;
|
|
34
|
+
const d = new Date(date);
|
|
35
|
+
return d instanceof Date && !isNaN(d.getTime());
|
|
36
|
+
};
|
|
37
|
+
exports.isValidDate = isValidDate;
|
|
38
|
+
/**
|
|
39
|
+
* Validates if a value is a valid number
|
|
40
|
+
*/
|
|
41
|
+
const isValidNumber = (value) => {
|
|
42
|
+
return typeof value === 'number' && !isNaN(value) && isFinite(value);
|
|
43
|
+
};
|
|
44
|
+
exports.isValidNumber = isValidNumber;
|
|
45
|
+
/**
|
|
46
|
+
* Validates if a value is a valid integer
|
|
47
|
+
*/
|
|
48
|
+
const isValidInteger = (value) => {
|
|
49
|
+
return (0, exports.isValidNumber)(value) && Number.isInteger(value);
|
|
50
|
+
};
|
|
51
|
+
exports.isValidInteger = isValidInteger;
|
|
52
|
+
/**
|
|
53
|
+
* Validates if a value is a valid positive number
|
|
54
|
+
*/
|
|
55
|
+
const isValidPositiveNumber = (value) => {
|
|
56
|
+
return (0, exports.isValidNumber)(value) && value > 0;
|
|
57
|
+
};
|
|
58
|
+
exports.isValidPositiveNumber = isValidPositiveNumber;
|
|
59
|
+
/**
|
|
60
|
+
* Validates if a string is not empty
|
|
61
|
+
*/
|
|
62
|
+
const isNotEmpty = (value) => {
|
|
63
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
64
|
+
};
|
|
65
|
+
exports.isNotEmpty = isNotEmpty;
|
|
66
|
+
/**
|
|
67
|
+
* Validates if a string has a minimum length
|
|
68
|
+
*/
|
|
69
|
+
const hasMinLength = (value, minLength) => {
|
|
70
|
+
return typeof value === 'string' && value.length >= minLength;
|
|
71
|
+
};
|
|
72
|
+
exports.hasMinLength = hasMinLength;
|
|
73
|
+
/**
|
|
74
|
+
* Validates if a string has a maximum length
|
|
75
|
+
*/
|
|
76
|
+
const hasMaxLength = (value, maxLength) => {
|
|
77
|
+
return typeof value === 'string' && value.length <= maxLength;
|
|
78
|
+
};
|
|
79
|
+
exports.hasMaxLength = hasMaxLength;
|
|
80
|
+
/**
|
|
81
|
+
* Validates if a value is in a given range
|
|
82
|
+
*/
|
|
83
|
+
const isInRange = (value, min, max) => {
|
|
84
|
+
return (0, exports.isValidNumber)(value) && value >= min && value <= max;
|
|
85
|
+
};
|
|
86
|
+
exports.isInRange = isInRange;
|
|
87
|
+
/**
|
|
88
|
+
* Validates if a value is one of the allowed values
|
|
89
|
+
*/
|
|
90
|
+
const isOneOf = (value, allowedValues) => {
|
|
91
|
+
return allowedValues.includes(value);
|
|
92
|
+
};
|
|
93
|
+
exports.isOneOf = isOneOf;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a validation error object
|
|
96
|
+
*/
|
|
97
|
+
const createValidationError = (field, message, value) => ({
|
|
98
|
+
field,
|
|
99
|
+
message,
|
|
100
|
+
value,
|
|
101
|
+
});
|
|
102
|
+
exports.createValidationError = createValidationError;
|
|
103
|
+
/**
|
|
104
|
+
* Validates an object against a schema
|
|
105
|
+
*/
|
|
106
|
+
const validateObject = (obj, schema) => {
|
|
107
|
+
const errors = [];
|
|
108
|
+
for (const [field, validator] of Object.entries(schema)) {
|
|
109
|
+
const value = obj[field];
|
|
110
|
+
if (!validator(value)) {
|
|
111
|
+
errors.push((0, exports.createValidationError)(field, `Invalid ${field}`, value));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return errors;
|
|
115
|
+
};
|
|
116
|
+
exports.validateObject = validateObject;
|
|
117
|
+
//# sourceMappingURL=validation.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.utils.js","sourceRoot":"","sources":["../../src/utils/validation.utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;;GAEG;AACI,MAAM,YAAY,GAAG,CAAC,KAAa,EAAW,EAAE;IACnD,MAAM,UAAU,GAAG,4BAA4B,CAAC;IAChD,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC,CAAC;AAHW,QAAA,YAAY,gBAGvB;AAEF;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,GAAW,EAAW,EAAE;IAC/C,IAAI,CAAC;QACD,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB;AAEF;;GAEG;AACI,MAAM,WAAW,GAAG,CAAC,IAAS,EAAW,EAAE;IAC9C,IAAI,CAAC,IAAI;QAAE,OAAO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AC,CAAC;AAXW,QAAA,cAAc,kBAWzB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password Strength Validator
|
|
3
|
+
*
|
|
4
|
+
* Provides comprehensive password strength analysis for use across frontend and backend.
|
|
5
|
+
* This module is part of the SDK to ensure consistent password validation logic.
|
|
6
|
+
*
|
|
7
|
+
* Requirements:
|
|
8
|
+
* - Minimum 8 characters
|
|
9
|
+
* - At least one uppercase letter
|
|
10
|
+
* - At least one lowercase letter
|
|
11
|
+
* - At least one number
|
|
12
|
+
* - At least one special character (recommended for strong)
|
|
13
|
+
* - Not in common passwords blacklist
|
|
14
|
+
*
|
|
15
|
+
* Scoring:
|
|
16
|
+
* - 0-39: Weak (unacceptable, submit disabled)
|
|
17
|
+
* - 40-69: Medium (acceptable, submit enabled)
|
|
18
|
+
* - 70-100: Strong (excellent)
|
|
19
|
+
*/
|
|
20
|
+
export interface PasswordStrength {
|
|
21
|
+
/** Score from 0-100 based on password complexity */
|
|
22
|
+
score: number;
|
|
23
|
+
/** Category classification */
|
|
24
|
+
category: 'weak' | 'medium' | 'strong';
|
|
25
|
+
/** Array of feedback messages for the user */
|
|
26
|
+
feedback: string[];
|
|
27
|
+
/** Whether password meets minimum requirements */
|
|
28
|
+
meetsMinimumRequirements: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Calculate password strength score and provide feedback
|
|
32
|
+
*
|
|
33
|
+
* @param password - The password to analyze
|
|
34
|
+
* @returns PasswordStrength object with score, category, and feedback
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const result = calculatePasswordStrength('MyP@ssw0rd');
|
|
39
|
+
* console.log(result.category); // 'strong'
|
|
40
|
+
* console.log(result.score); // 85
|
|
41
|
+
* console.log(result.feedback); // ['Great! Your password is strong']
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function calculatePasswordStrength(password: string): PasswordStrength;
|
|
45
|
+
/**
|
|
46
|
+
* Validate password meets minimum requirements (for backend validation)
|
|
47
|
+
*
|
|
48
|
+
* @param password - The password to validate
|
|
49
|
+
* @returns true if password meets minimum requirements, false otherwise
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* if (!isPasswordValid('weak')) {
|
|
54
|
+
* throw new Error('Password does not meet minimum requirements');
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function isPasswordValid(password: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Get password strength category (for quick checks)
|
|
61
|
+
*
|
|
62
|
+
* @param password - The password to check
|
|
63
|
+
* @returns The strength category: 'weak', 'medium', or 'strong'
|
|
64
|
+
*/
|
|
65
|
+
export declare function getPasswordStrengthCategory(password: string): 'weak' | 'medium' | 'strong';
|
|
66
|
+
//# sourceMappingURL=password-strength.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-strength.d.ts","sourceRoot":"","sources":["../../src/validation/password-strength.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,gBAAgB;IAC7B,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IAEd,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAEvC,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,EAAE,CAAC;IAEnB,kDAAkD;IAClD,wBAAwB,EAAE,OAAO,CAAC;CACrC;AAeD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAwH5E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAG1F"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Password Strength Validator
|
|
4
|
+
*
|
|
5
|
+
* Provides comprehensive password strength analysis for use across frontend and backend.
|
|
6
|
+
* This module is part of the SDK to ensure consistent password validation logic.
|
|
7
|
+
*
|
|
8
|
+
* Requirements:
|
|
9
|
+
* - Minimum 8 characters
|
|
10
|
+
* - At least one uppercase letter
|
|
11
|
+
* - At least one lowercase letter
|
|
12
|
+
* - At least one number
|
|
13
|
+
* - At least one special character (recommended for strong)
|
|
14
|
+
* - Not in common passwords blacklist
|
|
15
|
+
*
|
|
16
|
+
* Scoring:
|
|
17
|
+
* - 0-39: Weak (unacceptable, submit disabled)
|
|
18
|
+
* - 40-69: Medium (acceptable, submit enabled)
|
|
19
|
+
* - 70-100: Strong (excellent)
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.calculatePasswordStrength = calculatePasswordStrength;
|
|
23
|
+
exports.isPasswordValid = isPasswordValid;
|
|
24
|
+
exports.getPasswordStrengthCategory = getPasswordStrengthCategory;
|
|
25
|
+
/**
|
|
26
|
+
* Common passwords blacklist
|
|
27
|
+
* These are the most commonly used weak passwords that should be rejected
|
|
28
|
+
*/
|
|
29
|
+
const COMMON_PASSWORDS = [
|
|
30
|
+
'password', 'password123', '12345678', 'qwerty', 'abc123',
|
|
31
|
+
'monkey', '1234567', 'letmein', 'trustno1', 'dragon',
|
|
32
|
+
'baseball', 'iloveyou', 'master', 'sunshine', 'ashley',
|
|
33
|
+
'bailey', 'passw0rd', 'shadow', '123456', 'admin',
|
|
34
|
+
'welcome', 'login', 'admin123', 'root', 'toor',
|
|
35
|
+
'pass', 'test', 'guest', 'changeme', 'password1'
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Calculate password strength score and provide feedback
|
|
39
|
+
*
|
|
40
|
+
* @param password - The password to analyze
|
|
41
|
+
* @returns PasswordStrength object with score, category, and feedback
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const result = calculatePasswordStrength('MyP@ssw0rd');
|
|
46
|
+
* console.log(result.category); // 'strong'
|
|
47
|
+
* console.log(result.score); // 85
|
|
48
|
+
* console.log(result.feedback); // ['Great! Your password is strong']
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function calculatePasswordStrength(password) {
|
|
52
|
+
const feedback = [];
|
|
53
|
+
let score = 0;
|
|
54
|
+
// Early return for empty password
|
|
55
|
+
if (!password || password.length === 0) {
|
|
56
|
+
return {
|
|
57
|
+
score: 0,
|
|
58
|
+
category: 'weak',
|
|
59
|
+
feedback: ['Password is required'],
|
|
60
|
+
meetsMinimumRequirements: false
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Check minimum length (8 characters) - REQUIRED
|
|
64
|
+
const hasMinLength = password.length >= 8;
|
|
65
|
+
if (!hasMinLength) {
|
|
66
|
+
feedback.push('Password must be at least 8 characters long');
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
score += 20; // Base score for meeting minimum length
|
|
70
|
+
// Bonus for longer passwords
|
|
71
|
+
if (password.length >= 12)
|
|
72
|
+
score += 10;
|
|
73
|
+
if (password.length >= 16)
|
|
74
|
+
score += 10;
|
|
75
|
+
}
|
|
76
|
+
// Check for lowercase letters - REQUIRED
|
|
77
|
+
const hasLowercase = /[a-z]/.test(password);
|
|
78
|
+
if (!hasLowercase) {
|
|
79
|
+
feedback.push('Include at least one lowercase letter');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
score += 15;
|
|
83
|
+
}
|
|
84
|
+
// Check for uppercase letters - REQUIRED
|
|
85
|
+
const hasUppercase = /[A-Z]/.test(password);
|
|
86
|
+
if (!hasUppercase) {
|
|
87
|
+
feedback.push('Include at least one uppercase letter');
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
score += 15;
|
|
91
|
+
}
|
|
92
|
+
// Check for numbers - REQUIRED
|
|
93
|
+
const hasNumber = /[0-9]/.test(password);
|
|
94
|
+
if (!hasNumber) {
|
|
95
|
+
feedback.push('Include at least one number');
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
score += 15;
|
|
99
|
+
}
|
|
100
|
+
// Check for special characters - RECOMMENDED (not required)
|
|
101
|
+
const hasSpecial = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password);
|
|
102
|
+
if (hasSpecial) {
|
|
103
|
+
score += 15;
|
|
104
|
+
feedback.push('Excellent! Special characters add extra security');
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
feedback.push('Consider adding special characters (!@#$%^&*) for extra security');
|
|
108
|
+
}
|
|
109
|
+
// Check for common passwords - BLOCKING
|
|
110
|
+
const isCommonPassword = COMMON_PASSWORDS.some(common => password.toLowerCase().includes(common));
|
|
111
|
+
if (isCommonPassword) {
|
|
112
|
+
score = Math.min(score, 20); // Cap score at 20 for common passwords
|
|
113
|
+
feedback.push('This password is too common. Please choose a more unique password');
|
|
114
|
+
}
|
|
115
|
+
// Check for repeated characters (e.g., 'aaa', '111')
|
|
116
|
+
const hasRepeatedChars = /(.)\1{2,}/.test(password);
|
|
117
|
+
if (hasRepeatedChars) {
|
|
118
|
+
score -= 10;
|
|
119
|
+
feedback.push('Avoid repeating the same character multiple times');
|
|
120
|
+
}
|
|
121
|
+
// Check for sequential characters (e.g., 'abc', '123')
|
|
122
|
+
const hasSequentialChars = /(abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789)/i.test(password);
|
|
123
|
+
if (hasSequentialChars) {
|
|
124
|
+
score -= 10;
|
|
125
|
+
feedback.push('Avoid sequential characters (abc, 123, etc.)');
|
|
126
|
+
}
|
|
127
|
+
// Ensure score stays within 0-100 range
|
|
128
|
+
score = Math.max(0, Math.min(100, score));
|
|
129
|
+
// Determine category based on score
|
|
130
|
+
let category;
|
|
131
|
+
if (score < 40) {
|
|
132
|
+
category = 'weak';
|
|
133
|
+
}
|
|
134
|
+
else if (score < 70) {
|
|
135
|
+
category = 'medium';
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
category = 'strong';
|
|
139
|
+
}
|
|
140
|
+
// Check if password meets minimum requirements for submission
|
|
141
|
+
const meetsMinimumRequirements = hasMinLength &&
|
|
142
|
+
hasLowercase &&
|
|
143
|
+
hasUppercase &&
|
|
144
|
+
hasNumber &&
|
|
145
|
+
!isCommonPassword;
|
|
146
|
+
// Add appropriate summary feedback
|
|
147
|
+
if (meetsMinimumRequirements) {
|
|
148
|
+
if (category === 'strong') {
|
|
149
|
+
feedback.unshift('Great! Your password is strong');
|
|
150
|
+
}
|
|
151
|
+
else if (category === 'medium') {
|
|
152
|
+
feedback.unshift('Good! Your password meets requirements');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
feedback.unshift('Password does not meet minimum requirements');
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
score,
|
|
160
|
+
category,
|
|
161
|
+
feedback,
|
|
162
|
+
meetsMinimumRequirements
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Validate password meets minimum requirements (for backend validation)
|
|
167
|
+
*
|
|
168
|
+
* @param password - The password to validate
|
|
169
|
+
* @returns true if password meets minimum requirements, false otherwise
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* if (!isPasswordValid('weak')) {
|
|
174
|
+
* throw new Error('Password does not meet minimum requirements');
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
function isPasswordValid(password) {
|
|
179
|
+
const strength = calculatePasswordStrength(password);
|
|
180
|
+
return strength.meetsMinimumRequirements;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get password strength category (for quick checks)
|
|
184
|
+
*
|
|
185
|
+
* @param password - The password to check
|
|
186
|
+
* @returns The strength category: 'weak', 'medium', or 'strong'
|
|
187
|
+
*/
|
|
188
|
+
function getPasswordStrengthCategory(password) {
|
|
189
|
+
const strength = calculatePasswordStrength(password);
|
|
190
|
+
return strength.category;
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=password-strength.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-strength.js","sourceRoot":"","sources":["../../src/validation/password-strength.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;AA2CH,8DAwHC;AAeD,0CAGC;AAQD,kEAGC;AAhLD;;;GAGG;AACH,MAAM,gBAAgB,GAAG;IACrB,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ;IACzD,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ;IACpD,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ;IACtD,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO;IACjD,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;IAC9C,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW;CACnD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,SAAgB,yBAAyB,CAAC,QAAgB;IACtD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,kCAAkC;IAClC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO;YACH,KAAK,EAAE,CAAC;YACR,QAAQ,EAAE,MAAM;YAChB,QAAQ,EAAE,CAAC,sBAAsB,CAAC;YACl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