@dads-framework/identity-better-auth 0.0.0-stage → 0.2.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.
- package/LICENSE.md +21 -0
- package/README.md +280 -2
- package/dist/identity-better-auth.tsbuildinfo +1 -0
- package/dist/impersonation-store/index.d.ts +3 -0
- package/dist/impersonation-store/index.d.ts.map +1 -0
- package/dist/impersonation-store/index.js +3 -0
- package/dist/impersonation-store/index.js.map +1 -0
- package/dist/impersonation-store/postgres-impersonation-store.d.ts +4 -0
- package/dist/impersonation-store/postgres-impersonation-store.d.ts.map +1 -0
- package/dist/impersonation-store/postgres-impersonation-store.js +75 -0
- package/dist/impersonation-store/postgres-impersonation-store.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/account-invitations.d.ts +7 -0
- package/dist/lib/account-invitations.d.ts.map +1 -0
- package/dist/lib/account-invitations.js +46 -0
- package/dist/lib/account-invitations.js.map +1 -0
- package/dist/lib/configure-better-auth.d.ts +1509 -0
- package/dist/lib/configure-better-auth.d.ts.map +1 -0
- package/dist/lib/configure-better-auth.js +85 -0
- package/dist/lib/configure-better-auth.js.map +1 -0
- package/dist/lib/create-better-auth-identity.d.ts +9 -0
- package/dist/lib/create-better-auth-identity.d.ts.map +1 -0
- package/dist/lib/create-better-auth-identity.js +37 -0
- package/dist/lib/create-better-auth-identity.js.map +1 -0
- package/dist/lib/enterprise-callback-context.d.ts +9 -0
- package/dist/lib/enterprise-callback-context.d.ts.map +1 -0
- package/dist/lib/enterprise-callback-context.js +9 -0
- package/dist/lib/enterprise-callback-context.js.map +1 -0
- package/dist/lib/enterprise-options.d.ts +31 -0
- package/dist/lib/enterprise-options.d.ts.map +1 -0
- package/dist/lib/enterprise-options.js +119 -0
- package/dist/lib/enterprise-options.js.map +1 -0
- package/dist/lib/enterprise-plugin.d.ts +1038 -0
- package/dist/lib/enterprise-plugin.d.ts.map +1 -0
- package/dist/lib/enterprise-plugin.js +211 -0
- package/dist/lib/enterprise-plugin.js.map +1 -0
- package/dist/lib/enterprise-routes.d.ts +5 -0
- package/dist/lib/enterprise-routes.d.ts.map +1 -0
- package/dist/lib/enterprise-routes.js +215 -0
- package/dist/lib/enterprise-routes.js.map +1 -0
- package/dist/lib/identity-email.d.ts +4 -0
- package/dist/lib/identity-email.d.ts.map +1 -0
- package/dist/lib/identity-email.js +15 -0
- package/dist/lib/identity-email.js.map +1 -0
- package/dist/lib/identity-handler.d.ts +9 -0
- package/dist/lib/identity-handler.d.ts.map +1 -0
- package/dist/lib/identity-handler.js +102 -0
- package/dist/lib/identity-handler.js.map +1 -0
- package/dist/lib/identity-options.d.ts +15 -0
- package/dist/lib/identity-options.d.ts.map +1 -0
- package/dist/lib/identity-options.js +17 -0
- package/dist/lib/identity-options.js.map +1 -0
- package/dist/lib/identity-session-readers.d.ts +23 -0
- package/dist/lib/identity-session-readers.d.ts.map +1 -0
- package/dist/lib/identity-session-readers.js +81 -0
- package/dist/lib/identity-session-readers.js.map +1 -0
- package/dist/lib/install-identity-schema-v2.d.ts +4 -0
- package/dist/lib/install-identity-schema-v2.d.ts.map +1 -0
- package/dist/lib/install-identity-schema-v2.js +8 -0
- package/dist/lib/install-identity-schema-v2.js.map +1 -0
- package/dist/lib/migrations/20261120070500_identity.migration.d.ts +5 -0
- package/dist/lib/migrations/20261120070500_identity.migration.d.ts.map +1 -0
- package/dist/lib/migrations/20261120070500_identity.migration.js +81 -0
- package/dist/lib/migrations/20261120070500_identity.migration.js.map +1 -0
- package/dist/lib/migrations/20261120070530_identity_jwks.migration.d.ts +5 -0
- package/dist/lib/migrations/20261120070530_identity_jwks.migration.d.ts.map +1 -0
- package/dist/lib/migrations/20261120070530_identity_jwks.migration.js +10 -0
- package/dist/lib/migrations/20261120070530_identity_jwks.migration.js.map +1 -0
- package/dist/lib/migrations/20261120070600_enterprise_sso.migration.d.ts +5 -0
- package/dist/lib/migrations/20261120070600_enterprise_sso.migration.d.ts.map +1 -0
- package/dist/lib/migrations/20261120070600_enterprise_sso.migration.js +33 -0
- package/dist/lib/migrations/20261120070600_enterprise_sso.migration.js.map +1 -0
- package/dist/lib/migrations/20261120070700_staff_impersonation.migration.d.ts +6 -0
- package/dist/lib/migrations/20261120070700_staff_impersonation.migration.d.ts.map +1 -0
- package/dist/lib/migrations/20261120070700_staff_impersonation.migration.js +37 -0
- package/dist/lib/migrations/20261120070700_staff_impersonation.migration.js.map +1 -0
- package/package.json +50 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/impersonation-store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,iCAAiC,EAAE,MAAM,mEAAmE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/impersonation-store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,iCAAiC,EAAE,MAAM,mEAAmE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ImpersonationOptions } from "@dads-framework/identity/impersonation";
|
|
2
|
+
import type { PostgresPool } from "kysely";
|
|
3
|
+
export declare function createPostgresImpersonationStore(pool: PostgresPool): Pick<ImpersonationOptions, "store" | "writeAudit">;
|
|
4
|
+
//# sourceMappingURL=postgres-impersonation-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-impersonation-store.d.ts","sourceRoot":"","sources":["../../src/impersonation-store/postgres-impersonation-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACrB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AA2B3C,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,YAAY,GACjB,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,YAAY,CAAC,CA6DpD"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
function storedText(row, column) {
|
|
2
|
+
const value = Reflect.get(row, column);
|
|
3
|
+
if (typeof value !== "string")
|
|
4
|
+
throw new Error("Invalid stored impersonation grant");
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
function parseGrant(row) {
|
|
8
|
+
if (row === undefined)
|
|
9
|
+
return null;
|
|
10
|
+
if (typeof row !== "object" || row === null) {
|
|
11
|
+
throw new Error("Invalid stored impersonation grant");
|
|
12
|
+
}
|
|
13
|
+
const expiresAtMs = Number(storedText(row, "expires_at_ms"));
|
|
14
|
+
if (!Number.isSafeInteger(expiresAtMs))
|
|
15
|
+
throw new Error("Invalid impersonation grant expiry");
|
|
16
|
+
return {
|
|
17
|
+
id: storedText(row, "id"),
|
|
18
|
+
tenantId: storedText(row, "tenant_id"),
|
|
19
|
+
effectiveAccountId: storedText(row, "effective_account_id"),
|
|
20
|
+
staffAccountId: storedText(row, "staff_account_id"),
|
|
21
|
+
staffSessionId: storedText(row, "staff_session_id"),
|
|
22
|
+
expiresAtMs,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function createPostgresImpersonationStore(pool) {
|
|
26
|
+
async function query(sql, parameters) {
|
|
27
|
+
const client = await pool.connect();
|
|
28
|
+
try {
|
|
29
|
+
return await client.query(sql, parameters);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
client.release();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
store: {
|
|
37
|
+
async insert(grant, event) {
|
|
38
|
+
await query(`WITH created AS (
|
|
39
|
+
INSERT INTO identity_staff_impersonation_grants
|
|
40
|
+
(id, tenant_id, staff_account_id, effective_account_id, staff_session_id, expires_at_ms)
|
|
41
|
+
VALUES ($1, $2, $3, $4, $5, $6)
|
|
42
|
+
RETURNING id
|
|
43
|
+
)
|
|
44
|
+
INSERT INTO identity_staff_impersonation_audit (event)
|
|
45
|
+
SELECT $7::jsonb FROM created`, [
|
|
46
|
+
grant.id,
|
|
47
|
+
grant.tenantId,
|
|
48
|
+
grant.staffAccountId,
|
|
49
|
+
grant.effectiveAccountId,
|
|
50
|
+
grant.staffSessionId,
|
|
51
|
+
grant.expiresAtMs,
|
|
52
|
+
JSON.stringify(event),
|
|
53
|
+
]);
|
|
54
|
+
},
|
|
55
|
+
async read(id) {
|
|
56
|
+
const result = await query(`SELECT id, tenant_id, staff_account_id, effective_account_id, staff_session_id, expires_at_ms::text
|
|
57
|
+
FROM identity_staff_impersonation_grants WHERE id = $1`, [id]);
|
|
58
|
+
return parseGrant(result.rows[0]);
|
|
59
|
+
},
|
|
60
|
+
async remove(id, event) {
|
|
61
|
+
const result = await query(`WITH deleted AS (
|
|
62
|
+
DELETE FROM identity_staff_impersonation_grants WHERE id = $1
|
|
63
|
+
RETURNING id
|
|
64
|
+
)
|
|
65
|
+
INSERT INTO identity_staff_impersonation_audit (event)
|
|
66
|
+
SELECT $2::jsonb FROM deleted`, [id, JSON.stringify(event)]);
|
|
67
|
+
return result.rowCount === 1;
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
async writeAudit(event) {
|
|
71
|
+
await query("INSERT INTO identity_staff_impersonation_audit (event) VALUES ($1::jsonb)", [JSON.stringify(event)]);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=postgres-impersonation-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-impersonation-store.js","sourceRoot":"","sources":["../../src/impersonation-store/postgres-impersonation-store.ts"],"names":[],"mappings":"AAMA,SAAS,UAAU,CAAC,GAAW,EAAE,MAAc;IAC7C,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,GA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AAK,EAAE;YACL,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK;gBACvB,MAAM,KAAK,CACT;;;;;;;wCAO8B,EAC9B;oBACE,KAAK,CAAC,EAAE;oBACR,KAAK,CAAC,QAAQ;oBACd,KAAK,CAAC,cAAc;oBACpB,KAAK,CAAC,kBAAkB;oBACxB,KAAK,CAAC,cAAc;oBACpB,KAAK,CAAC,WAAW;oBACjB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBACtB,CACF,CAAC;YACJ,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,EAAE;gBACX,MAAM,MAAM,GAAG,MAAM,KAAK,CACxB;kEACwD,EACxD,CAAC,EAAE,CAAC,CACL,CAAC;gBACF,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,CAAC;YACD,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK;gBACpB,MAAM,MAAM,GAAG,MAAM,KAAK,CACxB;;;;;wCAK8B,EAC9B,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAC5B,CAAC;gBACF,OAAO,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAC;YAC/B,CAAC;SACF;QACD,KAAK,CAAC,UAAU,CAAC,KAAK;YACpB,MAAM,KAAK,CACT,2EAA2E,EAC3E,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CACxB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createBetterAuthIdentity } from "./lib/create-better-auth-identity.js";
|
|
2
|
+
export { IDENTITY_PATH, type BetterAuthIdentityOptions, } from "./lib/identity-options.js";
|
|
3
|
+
export { installIdentitySchemaV2 } from "./lib/install-identity-schema-v2.js";
|
|
4
|
+
export { up as installIdentitySchemaV1 } from "./lib/migrations/20261120070500_identity.migration.js";
|
|
5
|
+
export { createEnterpriseBetterAuthIdentity } from "./lib/create-better-auth-identity.js";
|
|
6
|
+
export { enterpriseSsoDomainChallenge, type EnterpriseSsoProvider, } from "./lib/enterprise-options.js";
|
|
7
|
+
export { up as installIdentityEnterpriseSsoSchema } from "./lib/migrations/20261120070600_enterprise_sso.migration.js";
|
|
8
|
+
export { up as installIdentitySigningKeyMetadataSchema } from "./lib/migrations/20261120070530_identity_jwks.migration.js";
|
|
9
|
+
export type { EnterpriseBetterAuthIdentity, EnterpriseSsoSession, } from "./lib/identity-session-readers.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EACL,aAAa,EACb,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,EAAE,IAAI,uBAAuB,EAAE,MAAM,uDAAuD,CAAC;AAEtG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EACL,4BAA4B,EAC5B,KAAK,qBAAqB,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,EAAE,IAAI,kCAAkC,EAAE,MAAM,6DAA6D,CAAC;AACvH,OAAO,EAAE,EAAE,IAAI,uCAAuC,EAAE,MAAM,4DAA4D,CAAC;AAC3H,YAAY,EACV,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,mCAAmC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createBetterAuthIdentity } from "./lib/create-better-auth-identity.js";
|
|
2
|
+
export { IDENTITY_PATH, } from "./lib/identity-options.js";
|
|
3
|
+
export { installIdentitySchemaV2 } from "./lib/install-identity-schema-v2.js";
|
|
4
|
+
export { up as installIdentitySchemaV1 } from "./lib/migrations/20261120070500_identity.migration.js";
|
|
5
|
+
export { createEnterpriseBetterAuthIdentity } from "./lib/create-better-auth-identity.js";
|
|
6
|
+
export { enterpriseSsoDomainChallenge, } from "./lib/enterprise-options.js";
|
|
7
|
+
export { up as installIdentityEnterpriseSsoSchema } from "./lib/migrations/20261120070600_enterprise_sso.migration.js";
|
|
8
|
+
export { up as installIdentitySigningKeyMetadataSchema } from "./lib/migrations/20261120070530_identity_jwks.migration.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EACL,aAAa,GAEd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,EAAE,IAAI,uBAAuB,EAAE,MAAM,uDAAuD,CAAC;AAEtG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EACL,4BAA4B,GAE7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,EAAE,IAAI,kCAAkC,EAAE,MAAM,6DAA6D,CAAC;AACvH,OAAO,EAAE,EAAE,IAAI,uCAAuC,EAAE,MAAM,4DAA4D,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IdentityEmail, IdentitySession } from "@dads-framework/identity";
|
|
2
|
+
import type { BetterAuthIdentityOptions } from "./identity-options.js";
|
|
3
|
+
export declare function createAccountInvitations(options: BetterAuthIdentityOptions, origin: string, sendEmail: (email: IdentityEmail) => void): {
|
|
4
|
+
issue(session: IdentitySession, email: string): Promise<boolean>;
|
|
5
|
+
accept(session: IdentitySession, token: unknown): Promise<boolean>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=account-invitations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-invitations.d.ts","sourceRoot":"","sources":["../../src/lib/account-invitations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE/E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AASvE,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,yBAAyB,EAClC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI;IAIjC,KAAK,UAAU,eAAe,SAAS,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBhE,MAAM,UAAU,eAAe,SAAS,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;EAiB3E"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
const INVITATION_SECONDS = 24 * 60 * 60;
|
|
3
|
+
const TOKEN = /^[A-Za-z0-9_-]{43}$/u;
|
|
4
|
+
function digest(token) {
|
|
5
|
+
return createHash("sha256").update(token).digest("hex");
|
|
6
|
+
}
|
|
7
|
+
export function createAccountInvitations(options, origin, sendEmail) {
|
|
8
|
+
const { pool } = options.database;
|
|
9
|
+
return {
|
|
10
|
+
async issue(session, email) {
|
|
11
|
+
if (!session.account.emailVerified ||
|
|
12
|
+
!(await options.canInvite(session.account))) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const token = randomBytes(32).toString("base64url");
|
|
16
|
+
await runInvitationQuery(pool, `INSERT INTO identity_account_invitations
|
|
17
|
+
(digest, email, expires_at, issued_by)
|
|
18
|
+
VALUES ($1, $2, clock_timestamp() + make_interval(secs => $3), $4)`, [digest(token), email, INVITATION_SECONDS, session.account.id]);
|
|
19
|
+
const url = new URL("/accept-invitation", origin);
|
|
20
|
+
url.hash = new URLSearchParams({ token }).toString();
|
|
21
|
+
sendEmail({ kind: "account-invitation", to: email, url: url.href });
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
async accept(session, token) {
|
|
25
|
+
if (!session.account.emailVerified ||
|
|
26
|
+
typeof token !== "string" ||
|
|
27
|
+
!TOKEN.test(token)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const deleted = await runInvitationQuery(pool, `DELETE FROM identity_account_invitations
|
|
31
|
+
WHERE digest = $1 AND email = $2 AND expires_at > clock_timestamp()`, [digest(token), session.account.email.trim().toLowerCase()]);
|
|
32
|
+
return deleted === 1;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function runInvitationQuery(pool, statement, parameters) {
|
|
37
|
+
const client = await pool.connect();
|
|
38
|
+
try {
|
|
39
|
+
const result = await client.query(statement, parameters);
|
|
40
|
+
return result.rowCount;
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
client.release();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=account-invitations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-invitations.js","sourceRoot":"","sources":["../../src/lib/account-invitations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAKtD,MAAM,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACxC,MAAM,KAAK,GAAG,sBAAsB,CAAC;AAErC,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,OAAkC,EAClC,MAAc,EACd,SAAyC;IAEzC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,Q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