@oxyhq/services 5.7.4 → 5.7.5

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 (59) hide show
  1. package/README.md +121 -264
  2. package/lib/commonjs/core/auth-manager.js +440 -0
  3. package/lib/commonjs/core/auth-manager.js.map +1 -0
  4. package/lib/commonjs/core/index.js +102 -5
  5. package/lib/commonjs/core/index.js.map +1 -1
  6. package/lib/commonjs/core/use-auth.js +244 -0
  7. package/lib/commonjs/core/use-auth.js.map +1 -0
  8. package/lib/commonjs/node/index.js +2 -49
  9. package/lib/commonjs/node/index.js.map +1 -1
  10. package/lib/commonjs/ui/index.js +1 -16
  11. package/lib/commonjs/ui/index.js.map +1 -1
  12. package/lib/module/core/auth-manager.js +432 -0
  13. package/lib/module/core/auth-manager.js.map +1 -0
  14. package/lib/module/core/index.js +41 -5
  15. package/lib/module/core/index.js.map +1 -1
  16. package/lib/module/core/use-auth.js +235 -0
  17. package/lib/module/core/use-auth.js.map +1 -0
  18. package/lib/module/node/index.js +1 -11
  19. package/lib/module/node/index.js.map +1 -1
  20. package/lib/module/ui/index.js +1 -16
  21. package/lib/module/ui/index.js.map +1 -1
  22. package/lib/typescript/core/auth-manager.d.ts +136 -0
  23. package/lib/typescript/core/auth-manager.d.ts.map +1 -0
  24. package/lib/typescript/core/index.d.ts +24 -1
  25. package/lib/typescript/core/index.d.ts.map +1 -1
  26. package/lib/typescript/core/use-auth.d.ts +79 -0
  27. package/lib/typescript/core/use-auth.d.ts.map +1 -0
  28. package/lib/typescript/node/index.d.ts +1 -7
  29. package/lib/typescript/node/index.d.ts.map +1 -1
  30. package/lib/typescript/ui/index.d.ts +1 -2
  31. package/lib/typescript/ui/index.d.ts.map +1 -1
  32. package/package.json +4 -6
  33. package/src/__tests__/zero-config-auth.test.ts +607 -0
  34. package/src/core/auth-manager.ts +500 -0
  35. package/src/core/index.ts +41 -6
  36. package/src/core/use-auth.tsx +245 -0
  37. package/src/node/index.ts +1 -17
  38. package/src/ui/index.ts +1 -19
  39. package/lib/commonjs/node/middleware.js +0 -227
  40. package/lib/commonjs/node/middleware.js.map +0 -1
  41. package/lib/commonjs/ui/zero-config/index.js +0 -25
  42. package/lib/commonjs/ui/zero-config/index.js.map +0 -1
  43. package/lib/commonjs/ui/zero-config/provider.js +0 -278
  44. package/lib/commonjs/ui/zero-config/provider.js.map +0 -1
  45. package/lib/module/node/middleware.js +0 -199
  46. package/lib/module/node/middleware.js.map +0 -1
  47. package/lib/module/ui/zero-config/index.js +0 -8
  48. package/lib/module/ui/zero-config/index.js.map +0 -1
  49. package/lib/module/ui/zero-config/provider.js +0 -270
  50. package/lib/module/ui/zero-config/provider.js.map +0 -1
  51. package/lib/typescript/node/middleware.d.ts +0 -92
  52. package/lib/typescript/node/middleware.d.ts.map +0 -1
  53. package/lib/typescript/ui/zero-config/index.d.ts +0 -5
  54. package/lib/typescript/ui/zero-config/index.d.ts.map +0 -1
  55. package/lib/typescript/ui/zero-config/provider.d.ts +0 -84
  56. package/lib/typescript/ui/zero-config/provider.d.ts.map +0 -1
  57. package/src/node/middleware.ts +0 -234
  58. package/src/ui/zero-config/index.ts +0 -11
  59. package/src/ui/zero-config/provider.tsx +0 -310
@@ -1,270 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Zero-config OxyHQ Provider and Hook for React/React Native
5
- *
6
- * This provides a simplified, one-line setup for frontend authentication
7
- * with automatic token management and API integration.
8
- */
9
-
10
- import React, { createContext, useContext, useEffect, useState, useCallback } from 'react';
11
- import { OxyServices } from '../../core';
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- const OxyZeroConfigContext = /*#__PURE__*/createContext(null);
14
- /**
15
- * Zero-config provider for OxyHQ Services
16
- *
17
- * @example
18
- * ```tsx
19
- * import { OxyZeroConfigProvider } from '@oxyhq/services/ui';
20
- *
21
- * function App() {
22
- * return (
23
- * <OxyZeroConfigProvider>
24
- * <MyApp />
25
- * </OxyZeroConfigProvider>
26
- * );
27
- * }
28
- * ```
29
- */
30
- export const OxyZeroConfigProvider = ({
31
- children,
32
- apiUrl,
33
- onAuthChange,
34
- storagePrefix = 'oxy_zero'
35
- }) => {
36
- // Determine API URL with fallbacks
37
- const finalApiUrl = apiUrl || typeof process !== 'undefined' && process.env?.REACT_APP_OXY_API_URL || 'http://localhost:3001';
38
-
39
- // Initialize OxyServices
40
- const [api] = useState(() => new OxyServices({
41
- baseURL: finalApiUrl
42
- }));
43
-
44
- // State
45
- const [user, setUser] = useState(null);
46
- const [isLoading, setIsLoading] = useState(true);
47
- const [error, setError] = useState(null);
48
- const isAuthenticated = user !== null;
49
-
50
- // Storage helpers
51
- const getStorageKey = key => `${storagePrefix}_${key}`;
52
- const saveToStorage = useCallback((key, value) => {
53
- try {
54
- if (typeof localStorage !== 'undefined') {
55
- localStorage.setItem(getStorageKey(key), value);
56
- }
57
- } catch (error) {
58
- console.warn('Failed to save to storage:', error);
59
- }
60
- }, [storagePrefix]);
61
- const getFromStorage = useCallback(key => {
62
- try {
63
- if (typeof localStorage !== 'undefined') {
64
- return localStorage.getItem(getStorageKey(key));
65
- }
66
- } catch (error) {
67
- console.warn('Failed to read from storage:', error);
68
- }
69
- return null;
70
- }, [storagePrefix]);
71
- const removeFromStorage = useCallback(key => {
72
- try {
73
- if (typeof localStorage !== 'undefined') {
74
- localStorage.removeItem(getStorageKey(key));
75
- }
76
- } catch (error) {
77
- console.warn('Failed to remove from storage:', error);
78
- }
79
- }, [storagePrefix]);
80
-
81
- // Initialize authentication state
82
- useEffect(() => {
83
- const initAuth = async () => {
84
- try {
85
- setIsLoading(true);
86
- setError(null);
87
-
88
- // Try to restore tokens from storage
89
- const savedAccessToken = getFromStorage('accessToken');
90
- const savedRefreshToken = getFromStorage('refreshToken');
91
- if (savedAccessToken && savedRefreshToken) {
92
- // Set tokens in the API client
93
- api.setTokens(savedAccessToken, savedRefreshToken);
94
-
95
- // Validate the token
96
- const isValid = await api.validate();
97
- if (isValid) {
98
- // Load user data
99
- const currentUser = await api.getCurrentUser();
100
- setUser(currentUser);
101
- if (onAuthChange) {
102
- onAuthChange(currentUser);
103
- }
104
- } else {
105
- // Invalid token, clear storage
106
- removeFromStorage('accessToken');
107
- removeFromStorage('refreshToken');
108
- api.clearTokens();
109
- }
110
- }
111
- } catch (error) {
112
- console.warn('Failed to restore authentication:', error);
113
- setError('Failed to restore authentication');
114
-
115
- // Clear invalid tokens
116
- removeFromStorage('accessToken');
117
- removeFromStorage('refreshToken');
118
- api.clearTokens();
119
- } finally {
120
- setIsLoading(false);
121
- }
122
- };
123
- initAuth();
124
- }, [api, getFromStorage, removeFromStorage, onAuthChange]);
125
-
126
- // Login method
127
- const login = useCallback(async (username, password) => {
128
- try {
129
- setIsLoading(true);
130
- setError(null);
131
- const response = await api.login(username, password);
132
-
133
- // Save tokens to storage
134
- if (response.accessToken) {
135
- saveToStorage('accessToken', response.accessToken);
136
- }
137
- if (response.refreshToken) {
138
- saveToStorage('refreshToken', response.refreshToken);
139
- }
140
-
141
- // Update state
142
- setUser(response.user);
143
- if (onAuthChange) {
144
- onAuthChange(response.user);
145
- }
146
- return response.user;
147
- } catch (error) {
148
- const errorMessage = error.message || 'Login failed';
149
- setError(errorMessage);
150
- throw new Error(errorMessage);
151
- } finally {
152
- setIsLoading(false);
153
- }
154
- }, [api, saveToStorage, onAuthChange]);
155
-
156
- // Logout method
157
- const logout = useCallback(async () => {
158
- try {
159
- setIsLoading(true);
160
- await api.logout();
161
- } catch (error) {
162
- console.warn('Logout API call failed:', error);
163
- } finally {
164
- // Always clean up local state and storage
165
- removeFromStorage('accessToken');
166
- removeFromStorage('refreshToken');
167
- api.clearTokens();
168
- setUser(null);
169
- setError(null);
170
- setIsLoading(false);
171
- if (onAuthChange) {
172
- onAuthChange(null);
173
- }
174
- }
175
- }, [api, removeFromStorage, onAuthChange]);
176
-
177
- // Register method
178
- const register = useCallback(async (username, email, password) => {
179
- try {
180
- setIsLoading(true);
181
- setError(null);
182
- const response = await api.signUp(username, email, password);
183
-
184
- // Save token from registration
185
- if (response.token) {
186
- saveToStorage('accessToken', response.token);
187
- // Note: signUp doesn't return refreshToken in current API
188
- }
189
-
190
- // Update state
191
- setUser(response.user);
192
- if (onAuthChange) {
193
- onAuthChange(response.user);
194
- }
195
- return response.user;
196
- } catch (error) {
197
- const errorMessage = error.message || 'Registration failed';
198
- setError(errorMessage);
199
- throw new Error(errorMessage);
200
- } finally {
201
- setIsLoading(false);
202
- }
203
- }, [api, saveToStorage, onAuthChange]);
204
- const contextValue = {
205
- user,
206
- isAuthenticated,
207
- isLoading,
208
- error,
209
- login,
210
- logout,
211
- register,
212
- api
213
- };
214
- return /*#__PURE__*/_jsx(OxyZeroConfigContext.Provider, {
215
- value: contextValue,
216
- children: children
217
- });
218
- };
219
-
220
- /**
221
- * Zero-config hook for OxyHQ Services
222
- *
223
- * @example
224
- * ```tsx
225
- * function MyComponent() {
226
- * const { user, login, logout, isAuthenticated } = useOxyZeroConfig();
227
- *
228
- * const handleLogin = () => {
229
- * login('username', 'password');
230
- * };
231
- *
232
- * if (isAuthenticated) {
233
- * return <div>Welcome, {user?.username}!</div>;
234
- * }
235
- *
236
- * return <button onClick={handleLogin}>Login</button>;
237
- * }
238
- * ```
239
- */
240
- export const useOxyZeroConfig = () => {
241
- const context = useContext(OxyZeroConfigContext);
242
- if (!context) {
243
- throw new Error('useOxyZeroConfig must be used within an OxyZeroConfigProvider');
244
- }
245
- return context;
246
- };
247
-
248
- /**
249
- * Hook for automatic API client with authentication
250
- * This automatically includes the auth token in requests
251
- *
252
- * @example
253
- * ```tsx
254
- * function ProfileComponent() {
255
- * const api = useOxyApi();
256
- *
257
- * const updateProfile = async (data) => {
258
- * const user = await api.updateProfile(data);
259
- * // Token is automatically included
260
- * };
261
- * }
262
- * ```
263
- */
264
- export const useOxyApi = () => {
265
- const {
266
- api
267
- } = useOxyZeroConfig();
268
- return api;
269
- };
270
- //# sourceMappingURL=provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","createContext","useContext","useEffect","useState","useCallback","OxyServices","jsx","_jsx","OxyZeroConfigContext","OxyZeroConfigProvider","children","apiUrl","onAuthChange","storagePrefix","finalApiUrl","process","env","REACT_APP_OXY_API_URL","api","baseURL","user","setUser","isLoading","setIsLoading","error","setError","isAuthenticated","getStorageKey","key","saveToStorage","value","localStorage","setItem","console","warn","getFromStorage","getItem","removeFromStorage","removeItem","initAuth","savedAccessToken","savedRefreshToken","setTokens","isValid","validate","currentUser","getCurrentUser","clearTokens","login","username","password","response","accessToken","refreshToken","errorMessage","message","Error","logout","register","email","signUp","token","contextValue","Provider","useOxyZeroConfig","context","useOxyApi"],"sourceRoot":"../../../../src","sources":["ui/zero-config/provider.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,EAAaC,WAAW,QAAQ,OAAO;AACrG,SAASC,WAAW,QAAQ,YAAY;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAmBzC,MAAMC,oBAAoB,gBAAGR,aAAa,CAA4B,IAAI,CAAC;AAY3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMS,qBAA2D,GAAGA,CAAC;EAC1EC,QAAQ;EACRC,MAAM;EACNC,YAAY;EACZC,aAAa,GAAG;AAClB,CAAC,KAAK;EACJ;EACA,MAAMC,WAAW,GAAGH,MAAM,IACvB,OAAOI,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACC,GAAG,EAAEC,qBAAsB,IACtE,uBAAuB;;EAEzB;EACA,MAAM,CAACC,GAAG,CAAC,GAAGf,QAAQ,CAAC,MAAM,IAAIE,WAAW,CAAC;IAAEc,OAAO,EAAEL;EAAY,CAAC,CAAC,CAAC;;EAEvE;EACA,MAAM,CAACM,IAAI,EAAEC,OAAO,CAAC,GAAGlB,QAAQ,CAAc,IAAI,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CAAC,CAAC;EAEtC,MAAMkD,YAAgC,GAAG;IACvC1C,IAAI;IACJM,eAAe;IACfJ,SAAS;IACTE,KAAK;IACLwB,KAAK;IACLS,MAAM;IACNC,QAAQ;IACRxC;EACF,CAAC;EAED,oBACEX,IAAA,CAACC,oBAAoB,CAACuD,QAAQ;IAACjC,KAAK,EAAEgC,YAAa;IAAApD,QAAA,EAChDA;EAAQ,CACoB,CAAC;AAEpC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMsD,gBAAgB,GAAGA,CAAA,KAA0B;EACxD,MAAMC,OAAO,GAAGhE,UAAU,CAACO,oBAAoB,CAAC;EAChD,IAAI,CAACyD,OAAO,EAAE;IACZ,MAAM,IAAIT,KAAK,CAAC,+DAA+D,CAAC;EAClF;EACA,OAAOS,OAAO;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGA,CAAA,KAAmB;EAC1C,MAAM;IAAEhD;EAAI,CAAC,GAAG8C,gBAAgB,CAAC,CAAC;EAClC,OAAO9C,GAAG;AACZ,CAAC","ignoreList":[]}
@@ -1,92 +0,0 @@
1
- /**
2
- * Zero-config Express middleware for OxyHQ Services authentication
3
- *
4
- * This provides a simple, one-line solution for adding authentication to Express apps.
5
- * Simply import and use: app.use('/api', createOxyAuth())
6
- */
7
- import { ApiError } from '../models/interfaces';
8
- export interface OxyAuthConfig {
9
- /** Base URL of your Oxy API server */
10
- baseURL?: string;
11
- /** Whether to load full user data (default: true) */
12
- loadUser?: boolean;
13
- /** Routes that don't require authentication */
14
- publicPaths?: string[];
15
- /** Custom error handler */
16
- onError?: (error: ApiError, req: any, res: any) => void;
17
- }
18
- export interface AuthenticatedRequest {
19
- user?: any;
20
- userId?: string;
21
- accessToken?: string;
22
- }
23
- /**
24
- * Creates zero-config authentication middleware for Express.js
25
- *
26
- * @example
27
- * ```typescript
28
- * import express from 'express';
29
- * import { createOxyAuth } from '@oxyhq/services/node';
30
- *
31
- * const app = express();
32
- *
33
- * // Zero-config auth for all /api routes
34
- * app.use('/api', createOxyAuth());
35
- *
36
- * // Now all routes under /api automatically have req.user available
37
- * app.get('/api/profile', (req, res) => {
38
- * res.json({ user: req.user }); // req.user is automatically available
39
- * });
40
- * ```
41
- */
42
- export declare function createOxyAuth(config?: OxyAuthConfig): (req: any, res: any, next: any) => Promise<any>;
43
- /**
44
- * Creates optional authentication middleware
45
- * This middleware will attach user data if a valid token is present, but won't fail if missing
46
- *
47
- * @example
48
- * ```typescript
49
- * import { createOptionalOxyAuth } from '@oxyhq/services/node';
50
- *
51
- * app.use('/api', createOptionalOxyAuth());
52
- *
53
- * app.get('/api/content', (req, res) => {
54
- * if (req.user) {
55
- * // User is authenticated, show personalized content
56
- * res.json({ content: 'personalized', user: req.user });
57
- * } else {
58
- * // Anonymous user, show public content
59
- * res.json({ content: 'public' });
60
- * }
61
- * });
62
- * ```
63
- */
64
- export declare function createOptionalOxyAuth(config?: OxyAuthConfig): (req: any, res: any, next: any) => Promise<any>;
65
- /**
66
- * Utility function to quickly set up a complete Express app with authentication
67
- *
68
- * @example
69
- * ```typescript
70
- * import { createOxyExpressApp } from '@oxyhq/services/node';
71
- *
72
- * const app = createOxyExpressApp();
73
- *
74
- * // All routes automatically have authentication and req.user available
75
- * app.get('/api/profile', (req, res) => {
76
- * res.json({ user: req.user });
77
- * });
78
- *
79
- * app.listen(3000);
80
- * ```
81
- */
82
- export declare function createOxyExpressApp(config?: OxyAuthConfig & {
83
- /** Express app configuration */
84
- cors?: boolean;
85
- /** JSON body parser limit */
86
- jsonLimit?: string;
87
- /** Additional middleware to apply */
88
- middleware?: any[];
89
- }): void;
90
- export { OxyServices } from '../core';
91
- export * from '../models/interfaces';
92
- //# sourceMappingURL=middleware.d.ts.map
@@ -1 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@ -1,5 +0,0 @@
1
- /**
2
- * Zero-config exports for OxyHQ Services
3
- */
4
- export { OxyZeroConfigProvider, useOxyZeroConfig, useOxyApi, type OxyZeroConfigState, type OxyZeroConfigProviderProps } from './provider';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/zero-config/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAChC,MAAM,YAAY,CAAC"}
@@ -1,84 +0,0 @@
1
- /**
2
- * Zero-config OxyHQ Provider and Hook for React/React Native
3
- *
4
- * This provides a simplified, one-line setup for frontend authentication
5
- * with automatic token management and API integration.
6
- */
7
- import React, { ReactNode } from 'react';
8
- import { OxyServices } from '../../core';
9
- import { User } from '../../models/interfaces';
10
- export interface OxyZeroConfigState {
11
- user: User | null;
12
- isAuthenticated: boolean;
13
- isLoading: boolean;
14
- error: string | null;
15
- login: (username: string, password: string) => Promise<User>;
16
- logout: () => Promise<void>;
17
- register: (username: string, email: string, password: string) => Promise<User>;
18
- api: OxyServices;
19
- }
20
- export interface OxyZeroConfigProviderProps {
21
- children: ReactNode;
22
- /** Base URL of your Oxy API server (defaults to process.env.REACT_APP_OXY_API_URL or http://localhost:3001) */
23
- apiUrl?: string;
24
- /** Called when authentication state changes */
25
- onAuthChange?: (user: User | null) => void;
26
- /** Storage key prefix (default: 'oxy_zero') */
27
- storagePrefix?: string;
28
- }
29
- /**
30
- * Zero-config provider for OxyHQ Services
31
- *
32
- * @example
33
- * ```tsx
34
- * import { OxyZeroConfigProvider } from '@oxyhq/services/ui';
35
- *
36
- * function App() {
37
- * return (
38
- * <OxyZeroConfigProvider>
39
- * <MyApp />
40
- * </OxyZeroConfigProvider>
41
- * );
42
- * }
43
- * ```
44
- */
45
- export declare const OxyZeroConfigProvider: React.FC<OxyZeroConfigProviderProps>;
46
- /**
47
- * Zero-config hook for OxyHQ Services
48
- *
49
- * @example
50
- * ```tsx
51
- * function MyComponent() {
52
- * const { user, login, logout, isAuthenticated } = useOxyZeroConfig();
53
- *
54
- * const handleLogin = () => {
55
- * login('username', 'password');
56
- * };
57
- *
58
- * if (isAuthenticated) {
59
- * return <div>Welcome, {user?.username}!</div>;
60
- * }
61
- *
62
- * return <button onClick={handleLogin}>Login</button>;
63
- * }
64
- * ```
65
- */
66
- export declare const useOxyZeroConfig: () => OxyZeroConfigState;
67
- /**
68
- * Hook for automatic API client with authentication
69
- * This automatically includes the auth token in requests
70
- *
71
- * @example
72
- * ```tsx
73
- * function ProfileComponent() {
74
- * const api = useOxyApi();
75
- *
76
- * const updateProfile = async (data) => {
77
- * const user = await api.updateProfile(data);
78
- * // Token is automatically included
79
- * };
80
- * }
81
- * ```
82
- */
83
- export declare const useOxyApi: () => OxyServices;
84
- //# sourceMappingURL=provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/ui/zero-config/provider.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAkD,SAAS,EAAe,MAAM,OAAO,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,IAAI,EAAiB,MAAM,yBAAyB,CAAC;AAE9D,MAAM,WAAW,kBAAkB;IAEjC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAGrB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,QAAQ,EAAE,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