@superfunctions/auth 0.1.0 → 0.1.1
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 +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +53 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +96 -0
- package/dist/middleware.js.map +1 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +41 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @superfunctions/auth - Framework-agnostic authentication abstraction layer
|
|
3
|
+
*/
|
|
4
|
+
export type { AuthSession, AuthProvider, AuthProviderConfig, } from './types.js';
|
|
5
|
+
export { AuthError, AuthenticationError, AuthorizationError, InvalidCredentialsError, ExpiredCredentialsError, } from './types.js';
|
|
6
|
+
export { createAuthMiddleware, createResourceAuthMiddleware, } from './middleware.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @superfunctions/auth - Framework-agnostic authentication abstraction layer
|
|
3
|
+
*/
|
|
4
|
+
// Errors
|
|
5
|
+
export { AuthError, AuthenticationError, AuthorizationError, InvalidCredentialsError, ExpiredCredentialsError, } from './types.js';
|
|
6
|
+
// Middleware utilities
|
|
7
|
+
export { createAuthMiddleware, createResourceAuthMiddleware, } from './middleware.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,SAAS;AACT,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAEpB,uBAAuB;AACvB,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Middleware utilities for integrating auth with @superfunctions/http
|
|
3
|
+
*/
|
|
4
|
+
import type { AuthProvider, AuthSession } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Create authentication middleware for @superfunctions/http
|
|
7
|
+
*
|
|
8
|
+
* This middleware authenticates requests using the provided auth provider
|
|
9
|
+
* and attaches the session to the context.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createAuthMiddleware } from '@superfunctions/auth';
|
|
14
|
+
* import { createRouter } from '@superfunctions/http';
|
|
15
|
+
*
|
|
16
|
+
* const authMiddleware = createAuthMiddleware(authProvider);
|
|
17
|
+
*
|
|
18
|
+
* const router = createRouter({
|
|
19
|
+
* middleware: [authMiddleware],
|
|
20
|
+
* routes: [...]
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createAuthMiddleware<TSession extends AuthSession>(provider: AuthProvider<TSession>, options?: {
|
|
25
|
+
/** Skip authentication for specific paths */
|
|
26
|
+
skipPaths?: string[];
|
|
27
|
+
/** Custom context key for session (default: 'auth') */
|
|
28
|
+
contextKey?: string;
|
|
29
|
+
}): (request: Request, context: any, next: () => Promise<Response>) => Promise<Response>;
|
|
30
|
+
/**
|
|
31
|
+
* Create resource authorization middleware
|
|
32
|
+
*
|
|
33
|
+
* This middleware checks if the authenticated session has access to a specific resource.
|
|
34
|
+
* Requires that authentication middleware has already run.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { createResourceAuthMiddleware } from '@superfunctions/auth';
|
|
39
|
+
*
|
|
40
|
+
* const resourceAuth = createResourceAuthMiddleware(authProvider, {
|
|
41
|
+
* resourceHeader: 'x-project-id'
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function createResourceAuthMiddleware<TSession extends AuthSession>(provider: AuthProvider<TSession>, options?: {
|
|
46
|
+
/** Header name containing the resource ID (default: 'x-resource-id') */
|
|
47
|
+
resourceHeader?: string;
|
|
48
|
+
/** Custom context key where session is stored (default: 'auth') */
|
|
49
|
+
contextKey?: string;
|
|
50
|
+
/** Skip paths that don't require resource authorization */
|
|
51
|
+
skipPaths?: string[];
|
|
52
|
+
}): (request: Request, context: any, next: () => Promise<Response>) => Promise<Response>;
|
|
53
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG5D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,SAAS,WAAW,EAC/D,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,EAChC,OAAO,CAAC,EAAE;IACR,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,IAMC,SAAS,OAAO,EAChB,SAAS,GAAG,EACZ,MAAM,MAAM,OAAO,CAAC,QAAQ,CAAC,KAC5B,OAAO,CAAC,QAAQ,CAAC,CAmBrB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,SAAS,WAAW,EACvE,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,EAChC,OAAO,CAAC,EAAE;IACR,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,IAOC,SAAS,OAAO,EAChB,SAAS,GAAG,EACZ,MAAM,MAAM,OAAO,CAAC,QAAQ,CAAC,KAC5B,OAAO,CAAC,QAAQ,CAAC,CAuCrB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Middleware utilities for integrating auth with @superfunctions/http
|
|
3
|
+
*/
|
|
4
|
+
import { AuthenticationError, AuthorizationError } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Create authentication middleware for @superfunctions/http
|
|
7
|
+
*
|
|
8
|
+
* This middleware authenticates requests using the provided auth provider
|
|
9
|
+
* and attaches the session to the context.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createAuthMiddleware } from '@superfunctions/auth';
|
|
14
|
+
* import { createRouter } from '@superfunctions/http';
|
|
15
|
+
*
|
|
16
|
+
* const authMiddleware = createAuthMiddleware(authProvider);
|
|
17
|
+
*
|
|
18
|
+
* const router = createRouter({
|
|
19
|
+
* middleware: [authMiddleware],
|
|
20
|
+
* routes: [...]
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function createAuthMiddleware(provider, options) {
|
|
25
|
+
const skipPaths = options?.skipPaths || [];
|
|
26
|
+
const contextKey = options?.contextKey || 'auth';
|
|
27
|
+
return async (request, context, next) => {
|
|
28
|
+
// Check if path should skip authentication
|
|
29
|
+
const url = new URL(request.url);
|
|
30
|
+
if (skipPaths.some(path => url.pathname === path || url.pathname.endsWith(path))) {
|
|
31
|
+
return next();
|
|
32
|
+
}
|
|
33
|
+
// Authenticate request
|
|
34
|
+
const session = await provider.authenticate(request);
|
|
35
|
+
if (!session) {
|
|
36
|
+
throw new AuthenticationError('Authentication required');
|
|
37
|
+
}
|
|
38
|
+
// Attach session to context
|
|
39
|
+
context[contextKey] = session;
|
|
40
|
+
return next();
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create resource authorization middleware
|
|
45
|
+
*
|
|
46
|
+
* This middleware checks if the authenticated session has access to a specific resource.
|
|
47
|
+
* Requires that authentication middleware has already run.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { createResourceAuthMiddleware } from '@superfunctions/auth';
|
|
52
|
+
*
|
|
53
|
+
* const resourceAuth = createResourceAuthMiddleware(authProvider, {
|
|
54
|
+
* resourceHeader: 'x-project-id'
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function createResourceAuthMiddleware(provider, options) {
|
|
59
|
+
const resourceHeader = options?.resourceHeader || 'x-resource-id';
|
|
60
|
+
const contextKey = options?.contextKey || 'auth';
|
|
61
|
+
const skipPaths = options?.skipPaths || [];
|
|
62
|
+
return async (request, context, next) => {
|
|
63
|
+
// Check if path should skip resource authorization
|
|
64
|
+
const url = new URL(request.url);
|
|
65
|
+
if (skipPaths.some(path => url.pathname === path || url.pathname.endsWith(path))) {
|
|
66
|
+
return next();
|
|
67
|
+
}
|
|
68
|
+
const session = context[contextKey];
|
|
69
|
+
// If no session exists, skip (auth middleware should have already handled this)
|
|
70
|
+
if (!session) {
|
|
71
|
+
return next();
|
|
72
|
+
}
|
|
73
|
+
// Get resource ID from header
|
|
74
|
+
const resourceId = request.headers.get(resourceHeader);
|
|
75
|
+
if (!resourceId) {
|
|
76
|
+
throw new AuthorizationError(`Missing ${resourceHeader} header`);
|
|
77
|
+
}
|
|
78
|
+
// Check authorization using provider if it supports it
|
|
79
|
+
if (provider.authorize) {
|
|
80
|
+
const authorized = await provider.authorize(session, resourceId);
|
|
81
|
+
if (!authorized) {
|
|
82
|
+
throw new AuthorizationError('Access denied to resource');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Default: check if resource ID is in session's resourceIds
|
|
87
|
+
if (!session.resourceIds.includes(resourceId)) {
|
|
88
|
+
throw new AuthorizationError('Access denied to resource');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Store resource ID in context for convenience
|
|
92
|
+
context.resourceId = resourceId;
|
|
93
|
+
return next();
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"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"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the authentication abstraction layer
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Authenticated session data returned by auth providers
|
|
6
|
+
*/
|
|
7
|
+
export interface AuthSession<TMetadata = any> {
|
|
8
|
+
/** Unique identifier for the authenticated entity (user, API key, etc.) */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Type of authentication (e.g., 'api-key', 'session', 'jwt', 'oauth') */
|
|
11
|
+
type: string;
|
|
12
|
+
/** Resource IDs this session has access to (e.g., project IDs, organization IDs) */
|
|
13
|
+
resourceIds: string[];
|
|
14
|
+
/** Optional: Scopes or permissions */
|
|
15
|
+
scopes?: string[];
|
|
16
|
+
/** Optional: Expiration timestamp */
|
|
17
|
+
expiresAt?: Date;
|
|
18
|
+
/** Optional: Additional metadata */
|
|
19
|
+
metadata?: TMetadata;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Core authentication provider interface
|
|
23
|
+
* All auth implementations must conform to this interface
|
|
24
|
+
*/
|
|
25
|
+
export interface AuthProvider<TSession extends AuthSession = AuthSession> {
|
|
26
|
+
/**
|
|
27
|
+
* Authenticate a request and return session data
|
|
28
|
+
* Returns null if authentication fails
|
|
29
|
+
*/
|
|
30
|
+
authenticate(request: Request): Promise<TSession | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Optional: Validate if a session has access to a specific resource
|
|
33
|
+
*/
|
|
34
|
+
authorize?(session: TSession, resourceId: string): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Optional: Revoke/invalidate a session
|
|
37
|
+
*/
|
|
38
|
+
revoke?(sessionId: string): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Common configuration options for auth providers
|
|
42
|
+
*/
|
|
43
|
+
export interface AuthProviderConfig {
|
|
44
|
+
/** Optional: Custom header names for authentication */
|
|
45
|
+
headers?: {
|
|
46
|
+
authorization?: string;
|
|
47
|
+
resourceId?: string;
|
|
48
|
+
};
|
|
49
|
+
/** Optional: Skip authentication for specific paths */
|
|
50
|
+
skipPaths?: string[];
|
|
51
|
+
}
|
|
52
|
+
export declare class AuthError extends Error {
|
|
53
|
+
code: string;
|
|
54
|
+
statusCode: number;
|
|
55
|
+
constructor(message: string, code: string, statusCode?: number);
|
|
56
|
+
}
|
|
57
|
+
export declare class AuthenticationError extends AuthError {
|
|
58
|
+
constructor(message?: string);
|
|
59
|
+
}
|
|
60
|
+
export declare class AuthorizationError extends AuthError {
|
|
61
|
+
constructor(message?: string);
|
|
62
|
+
}
|
|
63
|
+
export declare class InvalidCredentialsError extends AuthError {
|
|
64
|
+
constructor(message?: string);
|
|
65
|
+
}
|
|
66
|
+
export declare class ExpiredCredentialsError extends AuthError {
|
|
67
|
+
constructor(message?: string);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,SAAS,GAAG,GAAG;IAC1C,2EAA2E;IAC3E,EAAE,EAAE,MAAM,CAAC;IAEX,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IAEb,oFAAoF;IACpF,WAAW,EAAE,MAAM,EAAE,CAAC;IAEtB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,qCAAqC;IACrC,SAAS,CAAC,EAAE,IAAI,CAAC;IAEjB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAMD;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,QAAQ,SAAS,WAAW,GAAG,WAAW;IACtE;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAEzD;;OAEG;IACH,SAAS,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpE;;OAEG;IACH,MAAM,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAMD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,OAAO,CAAC,EAAE;QACR,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IAEF,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAMD,qBAAa,SAAU,SAAQ,KAAK;IACE,IAAI,EAAE,MAAM;IAAS,UAAU,EAAE,MAAM;gBAA/D,OAAO,EAAE,MAAM,EAAS,IAAI,EAAE,MAAM,EAAS,UAAU,GAAE,MAAY;CAIlF;AAED,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,GAAE,MAAgC;CAItD;AAED,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,OAAO,GAAE,MAAwB;CAI9C;AAED,qBAAa,uBAAwB,SAAQ,SAAS;gBACxC,OAAO,GAAE,MAA8B;CAIpD;AAED,qBAAa,uBAAwB,SAAQ,SAAS;gBACxC,OAAO,GAAE,MAA8B;CAIpD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the authentication abstraction layer
|
|
3
|
+
*/
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Auth Errors
|
|
6
|
+
// ============================================================================
|
|
7
|
+
export class AuthError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
statusCode;
|
|
10
|
+
constructor(message, code, statusCode = 401) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.name = 'AuthError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class AuthenticationError extends AuthError {
|
|
18
|
+
constructor(message = 'Authentication failed') {
|
|
19
|
+
super(message, 'AUTHENTICATION_FAILED', 401);
|
|
20
|
+
this.name = 'AuthenticationError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class AuthorizationError extends AuthError {
|
|
24
|
+
constructor(message = 'Access denied') {
|
|
25
|
+
super(message, 'AUTHORIZATION_FAILED', 403);
|
|
26
|
+
this.name = 'AuthorizationError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class InvalidCredentialsError extends AuthError {
|
|
30
|
+
constructor(message = 'Invalid credentials') {
|
|
31
|
+
super(message, 'INVALID_CREDENTIALS', 401);
|
|
32
|
+
this.name = 'InvalidCredentialsError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class ExpiredCredentialsError extends AuthError {
|
|
36
|
+
constructor(message = 'Credentials expired') {
|
|
37
|
+
super(message, 'EXPIRED_CREDENTIALS', 401);
|
|
38
|
+
this.name = 'ExpiredCredentialsError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAyEH,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E,MAAM,OAAO,SAAU,SAAQ,KAAK;IACE;IAAqB;IAAzD,YAAY,OAAe,EAAS,IAAY,EAAS,aAAqB,GAAG;QAC/E,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,SAAI,GAAJ,IAAI,CAAQ;QAAS,eAAU,GAAV,UAAU,CAAc;QAE/E,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAChD,YAAY,UAAkB,uBAAuB;QACnD,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,GAAG,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAC/C,YAAY,UAAkB,eAAe;QAC3C,KAAK,CAAC,OAAO,EAAE,sBAAsB,EAAE,GAAG,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACpD,YAAY,UAAkB,qBAAqB;QACjD,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACpD,YAAY,UAAkB,qBAAqB;QACjD,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF"}
|