@robinmordasiewicz/f5xc-auth 1.0.0

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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -0
  3. package/dist/auth/credential-manager.d.ts +177 -0
  4. package/dist/auth/credential-manager.d.ts.map +1 -0
  5. package/dist/auth/credential-manager.js +417 -0
  6. package/dist/auth/credential-manager.js.map +1 -0
  7. package/dist/auth/http-client.d.ts +86 -0
  8. package/dist/auth/http-client.d.ts.map +1 -0
  9. package/dist/auth/http-client.js +255 -0
  10. package/dist/auth/http-client.js.map +1 -0
  11. package/dist/auth/index.d.ts +6 -0
  12. package/dist/auth/index.d.ts.map +1 -0
  13. package/dist/auth/index.js +6 -0
  14. package/dist/auth/index.js.map +1 -0
  15. package/dist/config/index.d.ts +5 -0
  16. package/dist/config/index.d.ts.map +1 -0
  17. package/dist/config/index.js +5 -0
  18. package/dist/config/index.js.map +1 -0
  19. package/dist/config/paths.d.ts +36 -0
  20. package/dist/config/paths.d.ts.map +1 -0
  21. package/dist/config/paths.js +68 -0
  22. package/dist/config/paths.js.map +1 -0
  23. package/dist/index.d.ts +30 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +34 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/profile/index.d.ts +6 -0
  28. package/dist/profile/index.d.ts.map +1 -0
  29. package/dist/profile/index.js +6 -0
  30. package/dist/profile/index.js.map +1 -0
  31. package/dist/profile/manager.d.ts +74 -0
  32. package/dist/profile/manager.d.ts.map +1 -0
  33. package/dist/profile/manager.js +326 -0
  34. package/dist/profile/manager.js.map +1 -0
  35. package/dist/profile/types.d.ts +53 -0
  36. package/dist/profile/types.d.ts.map +1 -0
  37. package/dist/profile/types.js +7 -0
  38. package/dist/profile/types.js.map +1 -0
  39. package/dist/utils/errors.d.ts +66 -0
  40. package/dist/utils/errors.d.ts.map +1 -0
  41. package/dist/utils/errors.js +179 -0
  42. package/dist/utils/errors.js.map +1 -0
  43. package/dist/utils/index.d.ts +6 -0
  44. package/dist/utils/index.d.ts.map +1 -0
  45. package/dist/utils/index.js +6 -0
  46. package/dist/utils/index.js.map +1 -0
  47. package/dist/utils/logging.d.ts +75 -0
  48. package/dist/utils/logging.d.ts.map +1 -0
  49. package/dist/utils/logging.js +131 -0
  50. package/dist/utils/logging.js.map +1 -0
  51. package/package.json +54 -0
@@ -0,0 +1,417 @@
1
+ /**
2
+ * Credential Manager for F5 Distributed Cloud API
3
+ *
4
+ * Handles authentication configuration and URL normalization.
5
+ * Supports dual-mode operation:
6
+ * - Documentation mode: No credentials required
7
+ * - Execution mode: API token or P12/Certificate authentication
8
+ *
9
+ * Uses XDG-compliant profile storage at ~/.config/f5xc/
10
+ */
11
+ import { readFileSync } from "fs";
12
+ import { logger } from "../utils/logging.js";
13
+ import { getProfileManager } from "../profile/index.js";
14
+ /**
15
+ * Authentication modes supported by the server
16
+ */
17
+ export var AuthMode;
18
+ (function (AuthMode) {
19
+ /** No authentication - documentation mode only */
20
+ AuthMode["NONE"] = "none";
21
+ /** API token authentication */
22
+ AuthMode["TOKEN"] = "token";
23
+ /** P12 certificate authentication (mTLS) */
24
+ AuthMode["CERTIFICATE"] = "certificate";
25
+ })(AuthMode || (AuthMode = {}));
26
+ /**
27
+ * Environment variable names for authentication
28
+ * These take priority over profile settings
29
+ */
30
+ export const AUTH_ENV_VARS = {
31
+ API_URL: "F5XC_API_URL",
32
+ API_TOKEN: "F5XC_API_TOKEN",
33
+ P12_BUNDLE: "F5XC_P12_BUNDLE",
34
+ CERT: "F5XC_CERT",
35
+ KEY: "F5XC_KEY",
36
+ NAMESPACE: "F5XC_NAMESPACE",
37
+ // TLS configuration
38
+ TLS_INSECURE: "F5XC_TLS_INSECURE",
39
+ CA_BUNDLE: "F5XC_CA_BUNDLE",
40
+ };
41
+ /**
42
+ * URL normalization patterns
43
+ */
44
+ const URL_PATTERNS = {
45
+ // Match staging short-form URLs: tenant.staging.volterra.us (keep as-is)
46
+ STAGING_SHORT_FORM: /^https?:\/\/([^./]+)\.staging\.volterra\.us\/?/i,
47
+ // Match production short-form URLs: tenant.volterra.us (convert to console.ves)
48
+ PROD_SHORT_FORM: /^https?:\/\/([^./]+)\.volterra\.us\/?/i,
49
+ // Match console URLs: tenant.console.ves.volterra.io or tenant.staging.console.ves.volterra.io
50
+ CONSOLE_FORM: /^https?:\/\/([^./]+)\.(staging\.)?console\.ves\.volterra\.io\/?/i,
51
+ // Trailing slashes and /api suffix
52
+ TRAILING_CLEANUP: /\/+$|\/api\/?$/gi,
53
+ };
54
+ /**
55
+ * Normalize F5XC tenant URL to standard API endpoint format
56
+ *
57
+ * Handles various input formats:
58
+ * - tenant.volterra.us -> tenant.console.ves.volterra.io/api (production)
59
+ * - tenant.staging.volterra.us -> tenant.staging.volterra.us/api (staging - keep as-is)
60
+ * - tenant.console.ves.volterra.io -> tenant.console.ves.volterra.io/api
61
+ * - Any of the above with trailing slashes or /api suffix
62
+ *
63
+ * @param input - Raw URL from user configuration
64
+ * @returns Normalized API URL
65
+ */
66
+ export function normalizeApiUrl(input) {
67
+ // Remove trailing slashes and existing /api suffix
68
+ let url = input.replace(URL_PATTERNS.TRAILING_CLEANUP, "");
69
+ // Handle staging short-form URLs - keep as-is (don't convert to console.ves)
70
+ const stagingMatch = url.match(URL_PATTERNS.STAGING_SHORT_FORM);
71
+ if (stagingMatch) {
72
+ const tenant = stagingMatch[1];
73
+ url = `https://${tenant}.staging.volterra.us`;
74
+ // Ensure /api suffix and return early
75
+ return `${url}/api`;
76
+ }
77
+ // Handle production short-form URLs (tenant.volterra.us -> tenant.console.ves.volterra.io)
78
+ const prodMatch = url.match(URL_PATTERNS.PROD_SHORT_FORM);
79
+ if (prodMatch) {
80
+ const tenant = prodMatch[1];
81
+ url = `https://${tenant}.console.ves.volterra.io`;
82
+ }
83
+ // Handle console URLs - ensure https
84
+ const consoleMatch = url.match(URL_PATTERNS.CONSOLE_FORM);
85
+ if (consoleMatch) {
86
+ const tenant = consoleMatch[1];
87
+ const staging = consoleMatch[2] ?? "";
88
+ url = `https://${tenant}.${staging}console.ves.volterra.io`;
89
+ }
90
+ // Ensure /api suffix
91
+ return `${url}/api`;
92
+ }
93
+ /**
94
+ * Extract tenant name from a normalized URL
95
+ *
96
+ * @param url - Normalized API URL
97
+ * @returns Tenant name or null if not parseable
98
+ */
99
+ export function extractTenantFromUrl(url) {
100
+ const match = url.match(/https?:\/\/([^./]+)\./);
101
+ return match?.[1] ?? null;
102
+ }
103
+ /**
104
+ * Credential Manager
105
+ *
106
+ * Manages authentication credentials for F5 Distributed Cloud API.
107
+ * Supports credential loading with priority:
108
+ * 1. Environment variables (highest priority - overrides all)
109
+ * 2. Active profile from ~/.config/f5xc/ (XDG Base Directory compliant)
110
+ * 3. No credentials (documentation mode - lowest priority)
111
+ */
112
+ export class CredentialManager {
113
+ credentials;
114
+ activeProfileName = null;
115
+ initialized = false;
116
+ constructor() {
117
+ // Initialize with empty credentials - will be loaded async
118
+ this.credentials = {
119
+ mode: AuthMode.NONE,
120
+ apiUrl: null,
121
+ token: null,
122
+ p12Certificate: null,
123
+ cert: null,
124
+ key: null,
125
+ namespace: null,
126
+ tlsInsecure: false,
127
+ caBundle: null,
128
+ };
129
+ }
130
+ /**
131
+ * Initialize credentials asynchronously
132
+ * Must be called before using credentials
133
+ */
134
+ async initialize() {
135
+ if (this.initialized)
136
+ return;
137
+ this.credentials = await this.loadCredentials();
138
+ this.initialized = true;
139
+ }
140
+ /**
141
+ * Load credentials from environment variables
142
+ */
143
+ loadFromEnvironment() {
144
+ const apiUrl = process.env[AUTH_ENV_VARS.API_URL];
145
+ const apiToken = process.env[AUTH_ENV_VARS.API_TOKEN];
146
+ const p12Bundle = process.env[AUTH_ENV_VARS.P12_BUNDLE];
147
+ const cert = process.env[AUTH_ENV_VARS.CERT];
148
+ const key = process.env[AUTH_ENV_VARS.KEY];
149
+ const defaultNamespace = process.env[AUTH_ENV_VARS.NAMESPACE];
150
+ const tlsInsecure = process.env[AUTH_ENV_VARS.TLS_INSECURE]?.toLowerCase() === "true";
151
+ const caBundle = process.env[AUTH_ENV_VARS.CA_BUNDLE];
152
+ const hasAuth = !!(apiToken || p12Bundle || (cert && key));
153
+ return {
154
+ name: "__env__",
155
+ apiUrl: apiUrl || "",
156
+ apiToken,
157
+ p12Bundle,
158
+ cert,
159
+ key,
160
+ defaultNamespace,
161
+ hasAuth,
162
+ tlsInsecure,
163
+ caBundle,
164
+ };
165
+ }
166
+ /**
167
+ * Load credentials from active profile
168
+ */
169
+ async loadFromProfile() {
170
+ try {
171
+ const profileManager = getProfileManager();
172
+ const profile = await profileManager.getActiveProfile();
173
+ if (profile) {
174
+ this.activeProfileName = profile.name;
175
+ return profile;
176
+ }
177
+ return null;
178
+ }
179
+ catch (error) {
180
+ logger.debug("Failed to load credentials from profile", {
181
+ error: error instanceof Error ? error.message : String(error),
182
+ });
183
+ return null;
184
+ }
185
+ }
186
+ /**
187
+ * Build credentials object from profile data
188
+ */
189
+ buildCredentials(profile) {
190
+ const apiUrl = profile.apiUrl;
191
+ // Determine authentication mode
192
+ let mode = AuthMode.NONE;
193
+ let normalizedUrl = null;
194
+ let p12Certificate = null;
195
+ let cert = null;
196
+ let key = null;
197
+ // TLS configuration
198
+ const tlsInsecure = profile.tlsInsecure ?? false;
199
+ let caBundle = null;
200
+ // Load CA bundle if specified
201
+ if (profile.caBundle) {
202
+ try {
203
+ caBundle = readFileSync(profile.caBundle);
204
+ logger.info("Loaded CA bundle", { file: profile.caBundle });
205
+ }
206
+ catch (error) {
207
+ logger.warn("Failed to load CA bundle", {
208
+ file: profile.caBundle,
209
+ error: error instanceof Error ? error.message : String(error),
210
+ });
211
+ }
212
+ }
213
+ // Log TLS insecure mode warning
214
+ if (tlsInsecure) {
215
+ logger.warn("TLS certificate verification is DISABLED. This is insecure and should only be used for staging/development environments.");
216
+ }
217
+ if (apiUrl) {
218
+ normalizedUrl = normalizeApiUrl(apiUrl);
219
+ if (profile.p12Bundle) {
220
+ // P12 certificate authentication
221
+ mode = AuthMode.CERTIFICATE;
222
+ try {
223
+ p12Certificate = readFileSync(profile.p12Bundle);
224
+ logger.info("Loaded P12 certificate", { file: profile.p12Bundle });
225
+ }
226
+ catch (error) {
227
+ logger.error("Failed to load P12 certificate", {
228
+ file: profile.p12Bundle,
229
+ error: error instanceof Error ? error.message : String(error),
230
+ });
231
+ // Fall back to token auth if certificate load fails
232
+ if (profile.apiToken) {
233
+ mode = AuthMode.TOKEN;
234
+ logger.info("Falling back to token authentication");
235
+ }
236
+ else {
237
+ mode = AuthMode.NONE;
238
+ }
239
+ }
240
+ }
241
+ else if (profile.cert && profile.key) {
242
+ // Certificate + key authentication
243
+ mode = AuthMode.CERTIFICATE;
244
+ try {
245
+ cert = readFileSync(profile.cert, "utf-8");
246
+ key = readFileSync(profile.key, "utf-8");
247
+ logger.info("Loaded certificate and key", {
248
+ cert: profile.cert,
249
+ key: profile.key,
250
+ });
251
+ }
252
+ catch (error) {
253
+ logger.error("Failed to load certificate/key", {
254
+ error: error instanceof Error ? error.message : String(error),
255
+ });
256
+ if (profile.apiToken) {
257
+ mode = AuthMode.TOKEN;
258
+ logger.info("Falling back to token authentication");
259
+ }
260
+ else {
261
+ mode = AuthMode.NONE;
262
+ }
263
+ }
264
+ }
265
+ else if (profile.apiToken) {
266
+ mode = AuthMode.TOKEN;
267
+ }
268
+ }
269
+ return {
270
+ mode,
271
+ apiUrl: normalizedUrl,
272
+ token: profile.apiToken ?? null,
273
+ p12Certificate,
274
+ cert,
275
+ key,
276
+ namespace: profile.defaultNamespace ?? null,
277
+ tlsInsecure,
278
+ caBundle,
279
+ };
280
+ }
281
+ /**
282
+ * Load credentials with priority order:
283
+ * 1. Environment variables (highest)
284
+ * 2. Active profile from ~/.config/f5xc/
285
+ * 3. No credentials - documentation mode (lowest)
286
+ */
287
+ async loadCredentials() {
288
+ // Step 1: Check environment variables first (highest priority)
289
+ const envCreds = this.loadFromEnvironment();
290
+ if (envCreds.apiUrl && envCreds.hasAuth) {
291
+ const credentials = this.buildCredentials(envCreds);
292
+ const tenant = credentials.apiUrl ? extractTenantFromUrl(credentials.apiUrl) : null;
293
+ logger.info("Credentials loaded from environment variables", {
294
+ mode: credentials.mode,
295
+ tenant,
296
+ });
297
+ return credentials;
298
+ }
299
+ // Step 2: Try active profile from ~/.config/f5xc/
300
+ const profile = await this.loadFromProfile();
301
+ if (profile) {
302
+ const credentials = this.buildCredentials(profile);
303
+ if (credentials.mode !== AuthMode.NONE) {
304
+ const tenant = credentials.apiUrl ? extractTenantFromUrl(credentials.apiUrl) : null;
305
+ logger.info("Credentials loaded from profile", {
306
+ mode: credentials.mode,
307
+ tenant,
308
+ profile: this.activeProfileName,
309
+ });
310
+ return credentials;
311
+ }
312
+ }
313
+ // Step 3: No credentials - documentation mode (lowest priority)
314
+ logger.info("No credentials configured - running in documentation mode");
315
+ return {
316
+ mode: AuthMode.NONE,
317
+ apiUrl: null,
318
+ token: null,
319
+ p12Certificate: null,
320
+ cert: null,
321
+ key: null,
322
+ namespace: null,
323
+ tlsInsecure: false,
324
+ caBundle: null,
325
+ };
326
+ }
327
+ /**
328
+ * Get the active profile name (if any)
329
+ * Returns null if credentials are from environment variables or no profile is active
330
+ */
331
+ getActiveProfile() {
332
+ return this.activeProfileName;
333
+ }
334
+ /**
335
+ * Get the current authentication mode
336
+ */
337
+ getAuthMode() {
338
+ return this.credentials.mode;
339
+ }
340
+ /**
341
+ * Check if the server is in authenticated mode
342
+ */
343
+ isAuthenticated() {
344
+ return this.credentials.mode !== AuthMode.NONE;
345
+ }
346
+ /**
347
+ * Get the normalized API URL
348
+ */
349
+ getApiUrl() {
350
+ return this.credentials.apiUrl;
351
+ }
352
+ /**
353
+ * Get the tenant name
354
+ */
355
+ getTenant() {
356
+ return this.credentials.apiUrl ? extractTenantFromUrl(this.credentials.apiUrl) : null;
357
+ }
358
+ /**
359
+ * Get API token (for token authentication)
360
+ */
361
+ getToken() {
362
+ return this.credentials.token;
363
+ }
364
+ /**
365
+ * Get P12 certificate buffer (for certificate authentication)
366
+ */
367
+ getP12Certificate() {
368
+ return this.credentials.p12Certificate;
369
+ }
370
+ /**
371
+ * Get certificate content (for mTLS)
372
+ */
373
+ getCert() {
374
+ return this.credentials.cert;
375
+ }
376
+ /**
377
+ * Get private key content (for mTLS)
378
+ */
379
+ getKey() {
380
+ return this.credentials.key;
381
+ }
382
+ /**
383
+ * Get default namespace
384
+ */
385
+ getNamespace() {
386
+ return this.credentials.namespace;
387
+ }
388
+ /**
389
+ * Check if TLS certificate verification is disabled
390
+ * WARNING: Only use for staging/development environments
391
+ */
392
+ getTlsInsecure() {
393
+ return this.credentials.tlsInsecure;
394
+ }
395
+ /**
396
+ * Get custom CA bundle for TLS verification
397
+ */
398
+ getCaBundle() {
399
+ return this.credentials.caBundle;
400
+ }
401
+ /**
402
+ * Get full credentials object
403
+ */
404
+ getCredentials() {
405
+ return Object.freeze({ ...this.credentials });
406
+ }
407
+ /**
408
+ * Reload credentials from environment/profile
409
+ * Useful for testing or when credentials change
410
+ */
411
+ async reload() {
412
+ this.initialized = false;
413
+ this.activeProfileName = null;
414
+ await this.initialize();
415
+ }
416
+ }
417
+ //# sourceMappingURL=credential-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-manager.js","sourceRoot":"","sources":["../../src/auth/credential-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAgB,MAAM,qBAAqB,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,kDAAkD;IAClD,yBAAa,CAAA;IACb,+BAA+B;IAC/B,2BAAe,CAAA;IACf,4CAA4C;IAC5C,uCAA2B,CAAA;AAC7B,CAAC,EAPW,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,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Authenticated HTTP Client for F5 Distributed Cloud API
3
+ *
4
+ * Provides a configured Axios client for making authenticated API requests.
5
+ * Supports both API token and P12 certificate (mTLS) authentication.
6
+ */
7
+ import { AxiosInstance, AxiosRequestConfig } from "axios";
8
+ import { CredentialManager } from "./credential-manager.js";
9
+ /**
10
+ * HTTP client configuration options
11
+ */
12
+ export interface HttpClientConfig {
13
+ /** Request timeout in milliseconds */
14
+ timeout?: number;
15
+ /** Custom headers to include in all requests */
16
+ headers?: Record<string, string>;
17
+ /** Enable request/response logging */
18
+ debug?: boolean;
19
+ }
20
+ /**
21
+ * API response wrapper with metadata
22
+ */
23
+ export interface ApiResponse<T = unknown> {
24
+ /** Response data */
25
+ data: T;
26
+ /** HTTP status code */
27
+ status: number;
28
+ /** Response headers */
29
+ headers: Record<string, string>;
30
+ /** Request duration in milliseconds */
31
+ duration: number;
32
+ }
33
+ /**
34
+ * HTTP Client for F5XC API
35
+ *
36
+ * Creates and manages an authenticated Axios instance for making
37
+ * API requests to F5 Distributed Cloud.
38
+ */
39
+ export declare class HttpClient {
40
+ private client;
41
+ private credentialManager;
42
+ private config;
43
+ constructor(credentialManager: CredentialManager, config?: HttpClientConfig);
44
+ /**
45
+ * Build HTTPS agent options from credential manager TLS configuration
46
+ * Handles SSL/TLS configuration including insecure mode and custom CA
47
+ */
48
+ private buildHttpsAgentOptions;
49
+ /**
50
+ * Create configured Axios client
51
+ */
52
+ private createClient;
53
+ /**
54
+ * Check if the client is available (authenticated mode)
55
+ */
56
+ isAvailable(): boolean;
57
+ /**
58
+ * Make a GET request
59
+ */
60
+ get<T = unknown>(path: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
61
+ /**
62
+ * Make a POST request
63
+ */
64
+ post<T = unknown>(path: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
65
+ /**
66
+ * Make a PUT request
67
+ */
68
+ put<T = unknown>(path: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
69
+ /**
70
+ * Make a DELETE request
71
+ */
72
+ delete<T = unknown>(path: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
73
+ /**
74
+ * Make a generic request
75
+ */
76
+ private request;
77
+ /**
78
+ * Get the underlying Axios instance
79
+ */
80
+ getAxiosInstance(): AxiosInstance | null;
81
+ }
82
+ /**
83
+ * Create HTTP client from credential manager
84
+ */
85
+ export declare function createHttpClient(credentialManager: CredentialManager, config?: HttpClientConfig): HttpClient;
86
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/auth/http-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EACZ,aAAa,EACb,kBAAkB,EAGnB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,iBAAiB,EAAY,MAAM,yBAAyB,CAAC;AAItE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,sCAAsC;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAWD;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,oBAAoB;IACpB,IAAI,EAAE,CAAC,CAAC;IACR,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;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