payload-better-auth 1.0.5 → 1.0.7
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/dist/components/BetterAuthLoginServer.d.ts +2 -1
- package/dist/components/BetterAuthLoginServer.js +5 -4
- package/dist/components/BetterAuthLoginServer.js.map +1 -1
- package/dist/payload/plugin.d.ts +1 -0
- package/dist/payload/plugin.js +11 -3
- package/dist/payload/plugin.js.map +1 -1
- package/dist/utils/payload-reconcile.d.ts +6 -1
- package/dist/utils/payload-reconcile.js +6 -9
- package/dist/utils/payload-reconcile.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ClientOptions } from 'better-auth';
|
|
2
2
|
import type React from 'react';
|
|
3
3
|
import type { AuthMethod } from 'src/better-auth/helpers.js';
|
|
4
|
-
export declare function fetchAuthMethods({ betterAuthBaseUrl, }: {
|
|
4
|
+
export declare function fetchAuthMethods({ additionalHeaders, betterAuthBaseUrl, }: {
|
|
5
|
+
additionalHeaders?: HeadersInit;
|
|
5
6
|
betterAuthBaseUrl: string;
|
|
6
7
|
}): Promise<{
|
|
7
8
|
data: AuthMethod[];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { EmailPasswordFormClient } from './EmailPasswordFormClient.js';
|
|
3
|
-
export async function fetchAuthMethods({ betterAuthBaseUrl }) {
|
|
3
|
+
export async function fetchAuthMethods({ additionalHeaders, betterAuthBaseUrl }) {
|
|
4
|
+
const headers = new Headers(additionalHeaders);
|
|
5
|
+
headers.append('Content-Type', 'application/json');
|
|
4
6
|
try {
|
|
5
7
|
const response = await fetch(`${betterAuthBaseUrl}/api/auth/auth/methods`, {
|
|
6
|
-
headers
|
|
7
|
-
'Content-Type': 'application/json'
|
|
8
|
-
},
|
|
8
|
+
headers,
|
|
9
9
|
method: 'GET'
|
|
10
10
|
});
|
|
11
11
|
if (!response.ok) {
|
|
@@ -26,6 +26,7 @@ export async function fetchAuthMethods({ betterAuthBaseUrl }) {
|
|
|
26
26
|
}
|
|
27
27
|
export async function BetterAuthLoginServer({ authClientOptions }) {
|
|
28
28
|
const authMethods = await fetchAuthMethods({
|
|
29
|
+
additionalHeaders: authClientOptions.fetchOptions?.headers,
|
|
29
30
|
betterAuthBaseUrl: authClientOptions.baseURL
|
|
30
31
|
});
|
|
31
32
|
return /*#__PURE__*/ _jsx("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/BetterAuthLoginServer.tsx"],"sourcesContent":["import type { ClientOptions } from 'better-auth'\nimport type React from 'react'\nimport type { AuthMethod } from 'src/better-auth/helpers.js'\n\nimport { EmailPasswordFormClient } from './EmailPasswordFormClient.js'\n\nexport async function fetchAuthMethods({\n betterAuthBaseUrl,\n}: {\n betterAuthBaseUrl: string\n}): Promise<{ data: AuthMethod[]; error: null } | { data: null; error: Error }> {\n try {\n const response = await fetch(`${betterAuthBaseUrl}/api/auth/auth/methods`, {\n headers
|
|
1
|
+
{"version":3,"sources":["../../src/components/BetterAuthLoginServer.tsx"],"sourcesContent":["import type { ClientOptions } from 'better-auth'\nimport type React from 'react'\nimport type { AuthMethod } from 'src/better-auth/helpers.js'\n\nimport { EmailPasswordFormClient } from './EmailPasswordFormClient.js'\n\nexport async function fetchAuthMethods({\n additionalHeaders,\n betterAuthBaseUrl,\n}: {\n additionalHeaders?: HeadersInit\n betterAuthBaseUrl: string\n}): Promise<{ data: AuthMethod[]; error: null } | { data: null; error: Error }> {\n const headers = new Headers(additionalHeaders)\n headers.append('Content-Type', 'application/json')\n try {\n const response = await fetch(`${betterAuthBaseUrl}/api/auth/auth/methods`, {\n headers,\n method: 'GET',\n })\n\n if (!response.ok) {\n throw new Error(`Failed to fetch auth methods: ${response.status}`)\n }\n\n const data = await response.json()\n return { data, error: null } as { data: AuthMethod[]; error: null }\n } catch (error) {\n console.error('Error fetching auth methods:', error)\n return { data: null, error: error as Error }\n }\n}\n\nexport type BetterAuthLoginServerProps = {\n authClientOptions: { baseURL: string } & Omit<ClientOptions, 'baseURL'>\n}\n\nexport async function BetterAuthLoginServer({ authClientOptions }: BetterAuthLoginServerProps) {\n const authMethods = await fetchAuthMethods({\n additionalHeaders: authClientOptions.fetchOptions?.headers,\n betterAuthBaseUrl: authClientOptions.baseURL,\n })\n\n return (\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'center',\n }}\n >\n <div\n style={{\n background: 'white',\n borderRadius: '8px',\n boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',\n maxWidth: '400px',\n padding: '2rem',\n width: '100%',\n }}\n >\n <h2\n style={{\n color: '#333',\n fontSize: '1.5rem',\n fontWeight: '600',\n marginBottom: '2rem',\n textAlign: 'center',\n }}\n >\n Sign In to Admin\n </h2>\n\n {authMethods.data?.some(\n (m) => m.method === 'emailAndPassword' || m.method === 'magicLink',\n ) && (\n <EmailPasswordFormClient\n authClientOptions={authClientOptions}\n authMethods={authMethods.data}\n />\n )}\n {authMethods.data?.length === 0 && (\n <div\n style={{\n color: '#666',\n padding: '2rem',\n textAlign: 'center',\n }}\n >\n <p>No authentication methods are currently available.</p>\n <p style={{ fontSize: '0.875rem', marginTop: '1rem' }}>\n Please contact your administrator.\n </p>\n </div>\n )}\n {authMethods.error && (\n <div\n style={{\n color: '#666',\n padding: '2rem',\n textAlign: 'center',\n }}\n >\n <p>Couldn't fetch authentication methods from better-auth</p>\n <p style={{ fontSize: '0.875rem', marginTop: '1rem' }}>\n Please contact your administrator.\n </p>\n </div>\n )}\n </div>\n </div>\n )\n}\n"],"names":["EmailPasswordFormClient","fetchAuthMethods","additionalHeaders","betterAuthBaseUrl","headers","Headers","append","response","fetch","method","ok","Error","status","data","json","error","console","BetterAuthLoginServer","authClientOptions","authMethods","fetchOptions","baseURL","div","style","alignItems","display","justifyContent","background","borderRadius","boxShadow","maxWidth","padding","width","h2","color","fontSize","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BC,aAAaA,YAAYN,IAAI;;gBAGhCM,YAAYN,IAAI,EAAE4B,WAAW,mBAC5B,MAACnB;oBACCC,OAAO;wBACLW,OAAO;wBACPH,SAAS;wBACTO,WAAW;oBACb;;sCAEA,KAACI;sCAAE;;sCACH,KAACA;4BAAEnB,OAAO;gCAAEY,UAAU;gCAAYQ,WAAW;4BAAO;sCAAG;;;;gBAK1DxB,YAAYJ,KAAK,kBAChB,MAACO;oBACCC,OAAO;wBACLW,OAAO;wBACPH,SAAS;wBACTO,WAAW;oBACb;;sCAEA,KAACI;sCAAE;;sCACH,KAACA;4BAAEnB,OAAO;gCAAEY,UAAU;gCAAYQ,WAAW;4BAAO;sCAAG;;;;;;;AAQnE"}
|
package/dist/payload/plugin.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ import type { BetterAuthLoginServerProps } from 'src/components/BetterAuthLoginS
|
|
|
3
3
|
export type BetterAuthPayloadPluginOptions = {
|
|
4
4
|
betterAuthClientOptions: BetterAuthLoginServerProps['authClientOptions'];
|
|
5
5
|
disabled?: boolean;
|
|
6
|
+
reconcileToken?: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const betterAuthPayloadPlugin: (pluginOptions: BetterAuthPayloadPluginOptions) => (config: Config) => Config;
|
package/dist/payload/plugin.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createUsersCollection } from '../collections/Users/index.js';
|
|
2
2
|
import { triggerFullReconcile } from '../utils/payload-reconcile.js';
|
|
3
3
|
export const betterAuthPayloadPlugin = (pluginOptions)=>(config)=>{
|
|
4
|
+
const authClientOptions = pluginOptions.betterAuthClientOptions;
|
|
4
5
|
const Users = createUsersCollection({
|
|
5
|
-
authClientOptions
|
|
6
|
+
authClientOptions
|
|
6
7
|
});
|
|
7
8
|
if (!config.collections) {
|
|
8
9
|
config.collections = [
|
|
@@ -38,7 +39,9 @@ export const betterAuthPayloadPlugin = (pluginOptions)=>(config)=>{
|
|
|
38
39
|
}
|
|
39
40
|
config.admin.components.beforeLogin.push({
|
|
40
41
|
path: `payload-better-auth/rsc#BetterAuthLoginServer`,
|
|
41
|
-
serverProps:
|
|
42
|
+
serverProps: {
|
|
43
|
+
authClientOptions
|
|
44
|
+
}
|
|
42
45
|
});
|
|
43
46
|
if (!config.admin.components.views) {
|
|
44
47
|
config.admin.components.views = {};
|
|
@@ -75,7 +78,12 @@ export const betterAuthPayloadPlugin = (pluginOptions)=>(config)=>{
|
|
|
75
78
|
if (incomingOnInit) {
|
|
76
79
|
await incomingOnInit(payload);
|
|
77
80
|
}
|
|
78
|
-
await triggerFullReconcile(
|
|
81
|
+
await triggerFullReconcile({
|
|
82
|
+
additionalHeaders: pluginOptions.betterAuthClientOptions.fetchOptions?.headers,
|
|
83
|
+
betterAuthUrl: pluginOptions.betterAuthClientOptions.baseURL,
|
|
84
|
+
payload,
|
|
85
|
+
reconcileToken: pluginOptions.reconcileToken
|
|
86
|
+
});
|
|
79
87
|
};
|
|
80
88
|
return config;
|
|
81
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/plugin.ts"],"sourcesContent":["import type { Config } from 'payload'\nimport type { BetterAuthLoginServerProps } from 'src/components/BetterAuthLoginServer.js'\n\nimport { createUsersCollection } from '../collections/Users/index.js'\nimport { triggerFullReconcile } from '../utils/payload-reconcile.js'\n\nexport type BetterAuthPayloadPluginOptions = {\n betterAuthClientOptions: BetterAuthLoginServerProps['authClientOptions']\n disabled?: boolean\n}\n\nexport const betterAuthPayloadPlugin =\n (pluginOptions: BetterAuthPayloadPluginOptions) =>\n (config: Config): Config => {\n const Users = createUsersCollection({\n authClientOptions
|
|
1
|
+
{"version":3,"sources":["../../src/payload/plugin.ts"],"sourcesContent":["import type { Config } from 'payload'\nimport type { BetterAuthLoginServerProps } from 'src/components/BetterAuthLoginServer.js'\n\nimport { createUsersCollection } from '../collections/Users/index.js'\nimport { triggerFullReconcile } from '../utils/payload-reconcile.js'\n\nexport type BetterAuthPayloadPluginOptions = {\n betterAuthClientOptions: BetterAuthLoginServerProps['authClientOptions']\n disabled?: boolean\n reconcileToken?: string\n}\n\nexport const betterAuthPayloadPlugin =\n (pluginOptions: BetterAuthPayloadPluginOptions) =>\n (config: Config): Config => {\n const authClientOptions = pluginOptions.betterAuthClientOptions\n\n const Users = createUsersCollection({\n authClientOptions,\n })\n if (!config.collections) {\n config.collections = [Users]\n } else if (config.collections.find((col) => col.slug === 'users')) {\n throw new Error('Payload-better-auth plugin: Users collection already present')\n } else {\n config.collections.push(Users)\n }\n\n /**\n * If the plugin is disabled, we still want to keep added collections/fields so the database schema is consistent which is important for migrations.\n * If your plugin heavily modifies the database schema, you may want to remove this property.\n */\n if (pluginOptions.disabled) {\n return config\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n\n if (!config.admin) {\n config.admin = {}\n }\n\n if (!config.admin.user) {\n config.admin.user = Users.slug\n } else if (config.admin.user !== Users.slug) {\n throw new Error(\n 'Payload-better-auth plugin: admin.user property already set with conflicting value.',\n )\n }\n\n if (!config.admin.components) {\n config.admin.components = {}\n }\n\n if (!config.admin.components.beforeLogin) {\n config.admin.components.beforeLogin = []\n }\n\n config.admin.components.beforeLogin.push({\n path: `payload-better-auth/rsc#BetterAuthLoginServer`,\n serverProps: { authClientOptions },\n })\n\n if (!config.admin.components.views) {\n config.admin.components.views = {}\n }\n\n if (!config.admin.components.views.login) {\n config.admin.components.views.login = {\n Component: 'payload-better-auth/rsc#BetterAuthLoginServer', // RSC or 'use client' component\n exact: true,\n path: '/auth',\n }\n } else {\n throw new Error(\n 'Payload-better-auth plugin: admin.components.views.login property in config already set.',\n )\n }\n\n if (!config.admin.components.views.verifyEmail) {\n config.admin.components.views.verifyEmail = {\n Component: 'payload-better-auth/client#VerifyEmailInfoViewClient', // RSC or 'use client' component\n exact: true,\n path: '/auth/verify-email',\n }\n } else {\n throw new Error(\n 'Payload-better-auth plugin: admin.components.views.verifyEmail property in config already set.',\n )\n }\n\n if (!config.admin.routes) {\n config.admin.routes = {}\n }\n\n if (!config.admin.routes.login) {\n config.admin.routes.login = '/auth'\n } else {\n throw new Error(\n 'Payload-better-auth plugin: admin.routes.login property in config already set.',\n )\n }\n\n const incomingOnInit = config.onInit\n\n config.onInit = async (payload) => {\n // Ensure we are executing any existing onInit functions before running our own.\n if (incomingOnInit) {\n await incomingOnInit(payload)\n }\n await triggerFullReconcile({\n additionalHeaders: pluginOptions.betterAuthClientOptions.fetchOptions?.headers,\n betterAuthUrl: pluginOptions.betterAuthClientOptions.baseURL,\n payload,\n reconcileToken: pluginOptions.reconcileToken,\n })\n }\n\n return config\n }\n"],"names":["createUsersCollection","triggerFullReconcile","betterAuthPayloadPlugin","pluginOptions","config","authClientOptions","betterAuthClientOptions","Users","collections","find","col","slug","Error","push","disabled","endpoints","admin","user","components","beforeLogin","path","serverProps","views","login","Component","exact","verifyEmail","routes","incomingOnInit","onInit","payload","additionalHeaders","fetchOptions","headers","betterAuthUrl","baseURL","reconcileToken"],"mappings":"AAGA,SAASA,qBAAqB,QAAQ,gCAA+B;AACrE,SAASC,oBAAoB,QAAQ,gCAA+B;AAQpE,OAAO,MAAMC,0BACX,CAACC,gBACD,CAACC;QACC,MAAMC,oBAAoBF,cAAcG,uBAAuB;QAE/D,MAAMC,QAAQP,sBAAsB;YAClCK;QACF;QACA,IAAI,CAACD,OAAOI,WAAW,EAAE;YACvBJ,OAAOI,WAAW,GAAG;gBAACD;aAAM;QAC9B,OAAO,IAAIH,OAAOI,WAAW,CAACC,IAAI,CAAC,CAACC,MAAQA,IAAIC,IAAI,KAAK,UAAU;YACjE,MAAM,IAAIC,MAAM;QAClB,OAAO;YACLR,OAAOI,WAAW,CAACK,IAAI,CAACN;QAC1B;QAEA;;;KAGC,GACD,IAAIJ,cAAcW,QAAQ,EAAE;YAC1B,OAAOV;QACT;QAEA,IAAI,CAACA,OAAOW,SAAS,EAAE;YACrBX,OAAOW,SAAS,GAAG,EAAE;QACvB;QAEA,IAAI,CAACX,OAAOY,KA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AM,EAAE;YACxBvB,OAAOY,KAAK,CAACW,MAAM,GAAG,CAAC;QACzB;QAEA,IAAI,CAACvB,OAAOY,KAAK,CAACW,MAAM,CAACJ,KAAK,EAAE;YAC9BnB,OAAOY,KAAK,CAACW,MAAM,CAACJ,KAAK,GAAG;QAC9B,OAAO;YACL,MAAM,IAAIX,MACR;QAEJ;QAEA,MAAMgB,iBAAiBxB,OAAOyB,MAAM;QAEpCzB,OAAOyB,MAAM,GAAG,OAAOC;YACrB,gFAAgF;YAChF,IAAIF,gBAAgB;gBAClB,MAAMA,eAAeE;YACvB;YACA,MAAM7B,qBAAqB;gBACzB8B,mBAAmB5B,cAAcG,uBAAuB,CAAC0B,YAAY,EAAEC;gBACvEC,eAAe/B,cAAcG,uBAAuB,CAAC6B,OAAO;gBAC5DL;gBACAM,gBAAgBjC,cAAciC,cAAc;YAC9C;QACF;QAEA,OAAOhC;IACT,EAAC"}
|
|
@@ -3,4 +3,9 @@ import type { Payload } from 'payload';
|
|
|
3
3
|
* Triggers a full reconcile operation via the Better Auth reconcile API
|
|
4
4
|
* This is typically called during Payload initialization to ensure data consistency
|
|
5
5
|
*/
|
|
6
|
-
export declare function triggerFullReconcile(payload
|
|
6
|
+
export declare function triggerFullReconcile({ additionalHeaders, betterAuthUrl, payload, reconcileToken, }: {
|
|
7
|
+
additionalHeaders?: HeadersInit;
|
|
8
|
+
betterAuthUrl: string;
|
|
9
|
+
payload: Payload;
|
|
10
|
+
reconcileToken?: string;
|
|
11
|
+
}): Promise<void>;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Triggers a full reconcile operation via the Better Auth reconcile API
|
|
3
3
|
* This is typically called during Payload initialization to ensure data consistency
|
|
4
|
-
*/ export async function triggerFullReconcile(payload) {
|
|
4
|
+
*/ export async function triggerFullReconcile({ additionalHeaders, betterAuthUrl, payload, reconcileToken }) {
|
|
5
5
|
try {
|
|
6
|
-
const reconcileToken = process.env.RECONCILE_TOKEN;
|
|
7
6
|
if (!reconcileToken) {
|
|
8
|
-
payload.logger.warn('
|
|
7
|
+
payload.logger.warn('reconcile token not set, skipping onInit reconcile trigger');
|
|
9
8
|
return;
|
|
10
9
|
}
|
|
11
|
-
// Determine the better-auth server URL
|
|
12
|
-
const betterAuthUrl = process.env.BETTER_AUTH_URL || 'http://localhost:3000';
|
|
13
10
|
const reconcileUrl = `${betterAuthUrl}/api/auth/reconcile/run`;
|
|
14
11
|
payload.logger.info('Triggering full reconcile from Payload onInit...');
|
|
12
|
+
const headers = new Headers(additionalHeaders);
|
|
13
|
+
headers.append('Content-Type', 'application/json');
|
|
14
|
+
headers.append('x-reconcile-token', reconcileToken);
|
|
15
15
|
const response = await fetch(reconcileUrl, {
|
|
16
16
|
body: JSON.stringify({}),
|
|
17
|
-
headers
|
|
18
|
-
'Content-Type': 'application/json',
|
|
19
|
-
'x-reconcile-token': reconcileToken
|
|
20
|
-
},
|
|
17
|
+
headers,
|
|
21
18
|
method: 'POST'
|
|
22
19
|
});
|
|
23
20
|
if (!response.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/payload-reconcile.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n/**\n * Triggers a full reconcile operation via the Better Auth reconcile API\n * This is typically called during Payload initialization to ensure data consistency\n */\nexport async function triggerFullReconcile(payload: Payload): Promise<void> {\n try {\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils/payload-reconcile.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n/**\n * Triggers a full reconcile operation via the Better Auth reconcile API\n * This is typically called during Payload initialization to ensure data consistency\n */\nexport async function triggerFullReconcile({\n additionalHeaders,\n betterAuthUrl,\n payload,\n reconcileToken,\n}: {\n additionalHeaders?: HeadersInit\n betterAuthUrl: string\n payload: Payload\n reconcileToken?: string\n}): Promise<void> {\n try {\n if (!reconcileToken) {\n payload.logger.warn('reconcile token not set, skipping onInit reconcile trigger')\n return\n }\n\n const reconcileUrl = `${betterAuthUrl}/api/auth/reconcile/run`\n\n payload.logger.info('Triggering full reconcile from Payload onInit...')\n\n const headers = new Headers(additionalHeaders)\n headers.append('Content-Type', 'application/json')\n headers.append('x-reconcile-token', reconcileToken)\n\n const response = await fetch(reconcileUrl, {\n body: JSON.stringify({}),\n headers,\n method: 'POST',\n })\n\n if (!response.ok) {\n throw new Error(`Reconcile request failed: ${response.status} ${response.statusText}`)\n }\n\n const result = await response.json()\n payload.logger.info('Full reconcile triggered successfully from Payload onInit', { result })\n } catch (error) {\n payload.logger.error('Failed to trigger full reconcile from Payload onInit', { error })\n // Don't throw - we don't want to prevent Payload from starting if reconcile fails\n }\n}\n"],"names":["triggerFullReconcile","additionalHeaders","betterAuthUrl","payload","reconcileToken","logger","warn","reconcileUrl","info","headers","Headers","append","response","fetch","body","JSON","stringify","method","ok","Error","status","statusText","result","json","error"],"mappings":"AAEA;;;CAGC,GACD,OAAO,eAAeA,qBAAqB,EACzCC,iBAAiB,EACjBC,aAAa,EACbC,OAAO,EACPC,cAAc,EAMf;IACC,IAAI;QACF,IAAI,CAACA,gBAAgB;YACnBD,QAAQE,MAAM,CAACC,IAAI,CAAC;YACpB;QACF;QAEA,MAAMC,eAAe,GAAGL,cAAc,uBAAuB,CAAC;QAE9DC,QAAQE,MAAM,CAACG,IAAI,CAAC;QAEpB,MAAMC,UAAU,IAAIC,QAAQT;QAC5BQ,QAAQE,MAAM,CAAC,gBAAgB;QAC/BF,QAAQE,MAAM,CAAC,qBAAqBP;QAEpC,MAAMQ,WAAW,MAAMC,MAAMN,cAAc;YACzCO,MAAMC,KAAKC,SAAS,CAAC,CAAC;YACtBP;YACAQ,QAAQ;QACV;QAEA,IAAI,CAACL,SAASM,EAAE,EAAE;YAChB,MAAM,IAAIC,MAAM,CAAC,0BAA0B,EAAEP,SAASQ,MAAM,CAAC,CAAC,EAAER,SAASS,UAAU,EAAE;QACvF;QAEA,MAAMC,SAAS,MAAMV,SAASW,IAAI;QAClCpB,QAAQE,MAAM,CAACG,IAAI,CAAC,6DAA6D;YAAEc;QAAO;IAC5F,EAAE,OAAOE,OAAO;QACdrB,QAAQE,MAAM,CAACmB,KAAK,CAAC,wDAAwD;YAAEA;QAAM;IACrF,kFAAkF;IACpF;AACF"}
|