@yielded/auth-persistence-drizzle 0.1.0-beta.22 → 0.1.0-beta.24
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 +3 -0
- package/dist/D1.d.mts +11 -11
- package/dist/D1.mjs +2 -1
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +40 -56
- package/dist/Libsql.mjs +2 -1
- package/dist/Libsql.mjs.map +1 -1
- package/dist/Mysql2.d.mts +16 -17
- package/dist/Pglite.d.mts +18 -18
- package/dist/Pglite.mjs +2 -1
- package/dist/Pglite.mjs.map +1 -1
- package/dist/Postgres.d.mts +24 -24
- package/dist/Postgres.mjs +2 -1
- package/dist/Postgres.mjs.map +1 -1
- package/dist/SqliteBun.d.mts +39 -55
- package/dist/SqliteBun.mjs +2 -1
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +48 -64
- package/dist/SqliteDo.mjs +2 -1
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +45 -61
- package/dist/SqliteNode.mjs +2 -1
- package/dist/SqliteNode.mjs.map +1 -1
- package/dist/SqliteWasm.d.mts +48 -64
- package/dist/SqliteWasm.mjs +2 -1
- package/dist/SqliteWasm.mjs.map +1 -1
- package/dist/drizzle/crypto.mjs +1 -1
- package/dist/drizzle/d1-emails.d.mts +1 -1
- package/dist/drizzle/d1-oauth.d.mts +14 -14
- package/dist/drizzle/d1-passkey.d.mts +1 -1
- package/dist/drizzle/d1-password-prepared.d.mts +4 -4
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +18 -35
- package/dist/drizzle/d1-passwords.mjs +78 -290
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-phone.d.mts +1 -1
- package/dist/drizzle/d1-proofs.d.mts +2 -2
- package/dist/drizzle/d1-sessions.d.mts +3 -3
- package/dist/drizzle/d1-sessions.mjs +11 -6
- package/dist/drizzle/d1-sessions.mjs.map +1 -1
- package/dist/drizzle/d1-totp.d.mts +1 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +5 -5
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
- package/dist/drizzle/mysql-passwords.d.mts +16 -32
- package/dist/drizzle/mysql-passwords.mjs.map +1 -1
- package/dist/drizzle/mysql-sessions.d.mts +1 -1
- package/dist/drizzle/native-sql-table.mjs +135 -0
- package/dist/drizzle/native-sql-table.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-model.d.mts +20 -281
- package/dist/drizzle/oauth-connected-model.mjs +3 -17
- package/dist/drizzle/oauth-connected-model.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-reference.d.mts +1 -3
- package/dist/drizzle/oauth-connected-reference.mjs +4 -53
- package/dist/drizzle/oauth-connected-reference.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-target.d.mts +3 -990
- package/dist/drizzle/oauth-connected-target.mjs +8 -92
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
- package/dist/drizzle/oauth-kernel.mjs +11 -0
- package/dist/drizzle/oauth-kernel.mjs.map +1 -0
- package/dist/drizzle/oauth-model.d.mts +35 -438
- package/dist/drizzle/oauth-model.mjs +6 -44
- package/dist/drizzle/oauth-model.mjs.map +1 -1
- package/dist/drizzle/oauth-mysql.mjs +2 -2
- package/dist/drizzle/oauth-mysql.mjs.map +1 -1
- package/dist/drizzle/oauth-proxy.d.mts +10 -0
- package/dist/drizzle/oauth-proxy.mjs +54 -0
- package/dist/drizzle/oauth-proxy.mjs.map +1 -0
- package/dist/drizzle/oauth-target.d.mts +6 -107
- package/dist/drizzle/oauth-target.mjs +15 -245
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/password-model.d.mts +5 -8
- package/dist/drizzle/password-prepared-model.d.mts +5 -5
- package/dist/drizzle/password-prepared-model.mjs.map +1 -1
- package/dist/drizzle/password-prepared-state.mjs +1 -1
- package/dist/drizzle/password-sql.mjs +2 -1
- package/dist/drizzle/password-sql.mjs.map +1 -1
- package/dist/drizzle/password-target.mjs +13 -2
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-password-prepared.d.mts +5 -5
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
- package/dist/drizzle/pg-passwords.d.mts +16 -32
- package/dist/drizzle/pg-passwords.mjs.map +1 -1
- package/dist/drizzle/pg-sessions.d.mts +1 -1
- package/dist/drizzle/phone-target.d.mts +2 -2
- package/dist/drizzle/phone-target.mjs +1 -1
- package/dist/drizzle/query-operations.mjs +3 -1
- package/dist/drizzle/query-operations.mjs.map +1 -1
- package/dist/drizzle/session-sql.mjs +2 -1
- package/dist/drizzle/session-sql.mjs.map +1 -1
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/storage-validation.mjs +10 -198
- package/dist/drizzle/storage-validation.mjs.map +1 -1
- package/dist/drizzle/totp-target.d.mts +3 -3
- package/dist/drizzle/totp-target.mjs +2 -2
- package/dist/drizzle/transaction-execution.d.mts +2 -2
- package/dist/drizzle/transaction-owner.d.mts +1 -2
- package/dist/index.d.mts +3 -2
- package/dist/internal/drizzle-postgres-oauth-proxy.d.mts +138 -0
- package/dist/internal/drizzle-postgres-oauth-proxy.mjs +29 -0
- package/dist/internal/drizzle-postgres-oauth-proxy.mjs.map +1 -0
- package/dist/internal/drizzle-postgres.mjs +2 -0
- package/dist/internal/drizzle-postgres.mjs.map +1 -1
- package/dist/internal/drizzle-sqlite-oauth-proxy.d.mts +146 -0
- package/dist/internal/drizzle-sqlite-oauth-proxy.mjs +29 -0
- package/dist/internal/drizzle-sqlite-oauth-proxy.mjs.map +1 -0
- package/dist/internal/drizzle-sqlite.mjs +2 -0
- package/dist/internal/drizzle-sqlite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/D1.ts +2 -0
- package/src/Libsql.ts +2 -0
- package/src/Pglite.ts +2 -0
- package/src/Postgres.ts +2 -0
- package/src/SqliteBun.ts +2 -0
- package/src/SqliteDo.ts +2 -0
- package/src/SqliteNode.ts +2 -0
- package/src/SqliteWasm.ts +2 -0
- package/src/drizzle/d1-password-prepared.ts +2 -23
- package/src/drizzle/d1-passwords.ts +158 -780
- package/src/drizzle/d1-sessions.ts +21 -6
- package/src/drizzle/mysql-password-prepared.ts +4 -16
- package/src/drizzle/mysql-passwords.ts +5 -20
- package/src/drizzle/native-sql-table.ts +259 -0
- package/src/drizzle/oauth-connected-model.ts +97 -315
- package/src/drizzle/oauth-connected-reference.ts +13 -93
- package/src/drizzle/oauth-connected-target.ts +14 -271
- package/src/drizzle/oauth-kernel.ts +10 -0
- package/src/drizzle/oauth-model.ts +188 -541
- package/src/drizzle/oauth-mysql.ts +2 -2
- package/src/drizzle/oauth-proxy.ts +101 -0
- package/src/drizzle/oauth-target.ts +33 -737
- package/src/drizzle/password-model.ts +0 -33
- package/src/drizzle/password-prepared-model.ts +0 -18
- package/src/drizzle/password-sql.ts +3 -0
- package/src/drizzle/password-target.ts +41 -4
- package/src/drizzle/pg-password-prepared.ts +4 -16
- package/src/drizzle/pg-passwords.ts +5 -20
- package/src/drizzle/query-operations.ts +4 -0
- package/src/drizzle/session-sql.ts +2 -1
- package/src/drizzle/sqlite-password-prepared.ts +4 -52
- package/src/drizzle/sqlite-passwords.ts +7 -28
- package/src/drizzle/storage-validation.ts +13 -222
- package/src/index.ts +2 -8
- package/src/internal/drizzle-postgres-oauth-proxy.ts +37 -0
- package/src/internal/drizzle-postgres.ts +2 -0
- package/src/internal/drizzle-sqlite-oauth-proxy.ts +44 -0
- package/src/internal/drizzle-sqlite.ts +2 -0
- package/dist/_virtual/_rolldown/runtime.mjs +0 -13
- package/dist/drizzle/oauth-accounts.mjs +0 -359
- package/dist/drizzle/oauth-accounts.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-access.mjs +0 -212
- package/dist/drizzle/oauth-connected-access.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-collection.mjs +0 -202
- package/dist/drizzle/oauth-connected-collection.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-custody.mjs +0 -147
- package/dist/drizzle/oauth-connected-custody.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-flow.mjs +0 -297
- package/dist/drizzle/oauth-connected-flow.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-input.mjs +0 -122
- package/dist/drizzle/oauth-connected-input.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-maintenance.mjs +0 -214
- package/dist/drizzle/oauth-connected-maintenance.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-management.mjs +0 -229
- package/dist/drizzle/oauth-connected-management.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-settlement.mjs +0 -128
- package/dist/drizzle/oauth-connected-settlement.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-sign-in.mjs +0 -265
- package/dist/drizzle/oauth-connected-sign-in.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-state.d.mts +0 -2062
- package/dist/drizzle/oauth-connected-state.mjs +0 -430
- package/dist/drizzle/oauth-connected-state.mjs.map +0 -1
- package/dist/drizzle/oauth-flow.d.mts +0 -22
- package/dist/drizzle/oauth-flow.mjs +0 -253
- package/dist/drizzle/oauth-flow.mjs.map +0 -1
- package/dist/drizzle/oauth-input.mjs +0 -127
- package/dist/drizzle/oauth-input.mjs.map +0 -1
- package/dist/drizzle/oauth-owner.d.mts +0 -10
- package/dist/drizzle/oauth-owner.mjs +0 -10
- package/dist/drizzle/oauth-owner.mjs.map +0 -1
- package/dist/drizzle/oauth-registration.d.mts +0 -5
- package/dist/drizzle/oauth-registration.mjs +0 -374
- package/dist/drizzle/oauth-registration.mjs.map +0 -1
- package/dist/drizzle/oauth-state.mjs +0 -107
- package/dist/drizzle/oauth-state.mjs.map +0 -1
- package/src/drizzle/oauth-accounts.ts +0 -805
- package/src/drizzle/oauth-connected-access.ts +0 -361
- package/src/drizzle/oauth-connected-collection.ts +0 -324
- package/src/drizzle/oauth-connected-custody.ts +0 -279
- package/src/drizzle/oauth-connected-flow.ts +0 -529
- package/src/drizzle/oauth-connected-input.ts +0 -147
- package/src/drizzle/oauth-connected-maintenance.ts +0 -346
- package/src/drizzle/oauth-connected-management.ts +0 -365
- package/src/drizzle/oauth-connected-settlement.ts +0 -251
- package/src/drizzle/oauth-connected-sign-in.ts +0 -443
- package/src/drizzle/oauth-connected-state.ts +0 -872
- package/src/drizzle/oauth-flow.ts +0 -462
- package/src/drizzle/oauth-input.ts +0 -201
- package/src/drizzle/oauth-owner.ts +0 -29
- package/src/drizzle/oauth-registration.ts +0 -640
- package/src/drizzle/oauth-state.ts +0 -218
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { unavailable } from "./oauth-state.mjs";
|
|
2
1
|
import { mysqlTransaction } from "./transaction-mysql.mjs";
|
|
2
|
+
import { OAuthUnavailable } from "@yielded/auth/OAuth";
|
|
3
3
|
//#region src/drizzle/oauth-mysql.ts
|
|
4
|
-
const mysqlOAuthTransaction = (database, body) => mysqlTransaction(
|
|
4
|
+
const mysqlOAuthTransaction = (database, body) => mysqlTransaction(() => OAuthUnavailable.make({}), database, body);
|
|
5
5
|
//#endregion
|
|
6
6
|
export { mysqlOAuthTransaction };
|
|
7
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-mysql.mjs","names":[],"sources":["../../src/drizzle/oauth-mysql.ts"],"sourcesContent":["/* oxlint-disable no-explicit-any -- private native transaction adapter. */\nimport type { Effect } from \"effect\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"oauth-mysql.mjs","names":[],"sources":["../../src/drizzle/oauth-mysql.ts"],"sourcesContent":["import { OAuthUnavailable } from \"@yielded/auth/OAuth\";\n/* oxlint-disable no-explicit-any -- private native transaction adapter. */\nimport type { Effect } from \"effect\";\n\nimport { mysqlTransaction } from \"./transaction-mysql\";\n\nexport const mysqlOAuthTransaction = <A, E, R>(\n database: any,\n body: (transaction: any) => Effect.Effect<A, E, R>,\n) => mysqlTransaction(() => OAuthUnavailable.make({}), database, body);\n"],"mappings":";;;AAMA,MAAa,yBACX,UACA,SACG,uBAAuB,iBAAiB,KAAK,CAAC,CAAC,GAAG,UAAU,IAAI"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OAuthProxySqlTable } from "@yielded/auth-persistence/Adapter";
|
|
2
|
+
import { Table } from "drizzle-orm";
|
|
3
|
+
import { Layer } from "effect";
|
|
4
|
+
import { ConfigurationError, Persistence } from "@yielded/auth/OAuthProxy";
|
|
5
|
+
import { SqlClient } from "effect/sql";
|
|
6
|
+
//#region src/drizzle/oauth-proxy.d.ts
|
|
7
|
+
/** Override logical column keys when using an application-owned table. */
|
|
8
|
+
export type OAuthProxyColumns<T extends Table> = Partial<{ readonly [K in keyof OAuthProxySqlTable["columns"]]: Extract<keyof T["_"]["columns"], string>; }>;
|
|
9
|
+
//#endregion
|
|
10
|
+
//# sourceMappingURL=oauth-proxy.d.mts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { makeOAuthProxyPersistence, validateStorage } from "@yielded/auth-persistence/Adapter";
|
|
2
|
+
import { getTableColumns, is } from "drizzle-orm";
|
|
3
|
+
import { Effect, Layer } from "effect";
|
|
4
|
+
import { PgTable, getTableConfig } from "drizzle-orm/pg-core";
|
|
5
|
+
import { SQLiteTable, getTableConfig as getTableConfig$1 } from "drizzle-orm/sqlite-core";
|
|
6
|
+
import { ConfigurationError, Persistence } from "@yielded/auth/OAuthProxy";
|
|
7
|
+
import { SqlClient } from "effect/sql";
|
|
8
|
+
//#region src/drizzle/oauth-proxy.ts
|
|
9
|
+
/** The shared SQL kernel writes plain text and integer milliseconds directly;
|
|
10
|
+
* Drizzle value codecs and write hooks do not run for these storage columns. */
|
|
11
|
+
const oauthProxyLayer = (dialect, table, columns = {}) => Layer.effect(Persistence, Effect.gen(function* () {
|
|
12
|
+
const client = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
13
|
+
if (client.onDialectOrElse({
|
|
14
|
+
sqlite: () => "sqlite",
|
|
15
|
+
pg: () => "pg",
|
|
16
|
+
orElse: () => "other"
|
|
17
|
+
}) !== dialect) return yield* ConfigurationError.make({});
|
|
18
|
+
const mapping = yield* Effect.try({
|
|
19
|
+
try: () => {
|
|
20
|
+
const config = dialect === "pg" && is(table, PgTable) ? getTableConfig(table) : dialect === "sqlite" && is(table, SQLiteTable) ? getTableConfig$1(table) : void 0;
|
|
21
|
+
if (config === void 0) throw ConfigurationError.make({});
|
|
22
|
+
const declared = getTableColumns(table);
|
|
23
|
+
const column = (key) => {
|
|
24
|
+
const field = declared[columns[key] ?? key];
|
|
25
|
+
if (field === void 0 || !(key === "expiresAtMillis" || key === "handoffExpiresAtMillis" ? ["integer", "bigint"].includes(field.getSQLType()) : field.getSQLType() === "text") || field.notNull !== (key !== "handoffExpiresAtMillis")) throw ConfigurationError.make({});
|
|
26
|
+
return field.name;
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
name: config.name,
|
|
30
|
+
..."schema" in config && config.schema !== void 0 ? { schema: config.schema } : {},
|
|
31
|
+
columns: {
|
|
32
|
+
namespace: column("namespace"),
|
|
33
|
+
flowId: column("flowId"),
|
|
34
|
+
version: column("version"),
|
|
35
|
+
stage: column("stage"),
|
|
36
|
+
context: column("context"),
|
|
37
|
+
expiresAtMillis: column("expiresAtMillis"),
|
|
38
|
+
handoffExpiresAtMillis: column("handoffExpiresAtMillis"),
|
|
39
|
+
payload: column("payload")
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
catch: () => ConfigurationError.make({})
|
|
44
|
+
});
|
|
45
|
+
yield* validateStorage(dialect, {
|
|
46
|
+
...mapping,
|
|
47
|
+
columns: Object.fromEntries(Object.entries(mapping.columns).map(([key, name]) => [key, { name }]))
|
|
48
|
+
}, [["namespace", "flowId"]]).pipe(Effect.provideService(SqlClient.SqlClient, client), Effect.mapError(() => ConfigurationError.make({})));
|
|
49
|
+
return yield* makeOAuthProxyPersistence(mapping);
|
|
50
|
+
}));
|
|
51
|
+
//#endregion
|
|
52
|
+
export { oauthProxyLayer };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=oauth-proxy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-proxy.mjs","names":["pgConfig","sqliteConfig"],"sources":["../../src/drizzle/oauth-proxy.ts"],"sourcesContent":["import {\n makeOAuthProxyPersistence,\n validateStorage,\n type OAuthProxySqlTable,\n} from \"@yielded/auth-persistence/Adapter\";\nimport { ConfigurationError, Persistence } from \"@yielded/auth/OAuthProxy\";\nimport { getTableColumns, is, type Table } from \"drizzle-orm\";\nimport { getTableConfig as pgConfig, PgTable } from \"drizzle-orm/pg-core\";\nimport { getTableConfig as sqliteConfig, SQLiteTable } from \"drizzle-orm/sqlite-core\";\nimport { Effect, Layer } from \"effect\";\nimport { SqlClient } from \"effect/sql\";\n\n/** Override logical column keys when using an application-owned table. */\nexport type OAuthProxyColumns<T extends Table> = Partial<{\n readonly [K in keyof OAuthProxySqlTable[\"columns\"]]: Extract<keyof T[\"_\"][\"columns\"], string>;\n}>;\n\n/** The shared SQL kernel writes plain text and integer milliseconds directly;\n * Drizzle value codecs and write hooks do not run for these storage columns. */\nexport const oauthProxyLayer = <T extends Table>(\n dialect: \"sqlite\" | \"pg\",\n table: T,\n columns: OAuthProxyColumns<T> = {},\n) =>\n Layer.effect(\n Persistence,\n Effect.gen(function* () {\n const client = (yield* SqlClient.SqlClient).withoutTransforms();\n\n if (\n client.onDialectOrElse({\n sqlite: () => \"sqlite\",\n pg: () => \"pg\",\n orElse: () => \"other\",\n }) !== dialect\n )\n return yield* ConfigurationError.make({});\n\n const mapping = yield* Effect.try({\n try: (): OAuthProxySqlTable => {\n const config =\n dialect === \"pg\" && is(table, PgTable)\n ? pgConfig(table)\n : dialect === \"sqlite\" && is(table, SQLiteTable)\n ? sqliteConfig(table)\n : undefined;\n\n if (config === undefined) throw ConfigurationError.make({});\n const declared = getTableColumns(table);\n\n const column = (key: keyof OAuthProxySqlTable[\"columns\"]) => {\n const field = declared[columns[key] ?? key];\n const integer = key === \"expiresAtMillis\" || key === \"handoffExpiresAtMillis\";\n\n if (\n field === undefined ||\n !(integer\n ? [\"integer\", \"bigint\"].includes(field.getSQLType())\n : field.getSQLType() === \"text\") ||\n field.notNull !== (key !== \"handoffExpiresAtMillis\")\n )\n throw ConfigurationError.make({});\n\n return field.name;\n };\n\n return {\n name: config.name,\n ...(\"schema\" in config && config.schema !== undefined ? { schema: config.schema } : {}),\n columns: {\n namespace: column(\"namespace\"),\n flowId: column(\"flowId\"),\n version: column(\"version\"),\n stage: column(\"stage\"),\n context: column(\"context\"),\n expiresAtMillis: column(\"expiresAtMillis\"),\n handoffExpiresAtMillis: column(\"handoffExpiresAtMillis\"),\n payload: column(\"payload\"),\n },\n };\n },\n catch: () => ConfigurationError.make({}),\n });\n\n yield* validateStorage(\n dialect,\n {\n ...mapping,\n columns: Object.fromEntries(\n Object.entries(mapping.columns).map(([key, name]) => [key, { name }]),\n ),\n },\n [[\"namespace\", \"flowId\"]],\n ).pipe(\n Effect.provideService(SqlClient.SqlClient, client),\n Effect.mapError(() => ConfigurationError.make({})),\n );\n\n return yield* makeOAuthProxyPersistence(mapping);\n }),\n );\n"],"mappings":";;;;;;;;;;AAmBA,MAAa,mBACX,SACA,OACA,UAAgC,CAAC,MAEjC,MAAM,OACJ,aACA,OAAO,IAAI,aAAa;CACtB,MAAM,UAAU,OAAO,UAAU,UAAA,CAAW,kBAAkB;CAE9D,IACE,OAAO,gBAAgB;EACrB,cAAc;EACd,UAAU;EACV,cAAc;CAChB,CAAC,MAAM,SAEP,OAAO,OAAO,mBAAmB,KAAK,CAAC,CAAC;CAE1C,MAAM,UAAU,OAAO,OAAO,IAAI;EAChC,WAA+B;GAC7B,MAAM,SACJ,YAAY,QAAQ,GAAG,OAAO,OAAO,IACjCA,eAAS,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
|
@@ -1,110 +1,9 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import { OAuthRegistrationAuthority } from "./oauth-model.mjs";
|
|
3
|
-
import "./oauth-owner.mjs";
|
|
4
|
-
import "./oauth-registration.mjs";
|
|
5
|
-
import { TransactionCoordinatorError, TransactionTargetConfiguration } from "./transaction-execution.mjs";
|
|
6
|
-
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
7
|
-
import { Context, Crypto, Effect, Layer } from "effect";
|
|
8
|
-
import { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
9
|
-
import { OAuthAccountRevision, OAuthAccountsPersistence, OAuthClaim, OAuthClaimDecision, OAuthCleanupInput, OAuthCredentialSnapshot, OAuthIssueDecision, OAuthLinkClaimDecision, OAuthLinkDecision, OAuthLinkIssueDecision, OAuthLinkPendingFlow, OAuthPendingFlow, OAuthRegistrationIntent, OAuthRegistrationIntents, OAuthSettlementDecision, OAuthSignInPersistence, OAuthUnavailable, OAuthUnlinkDecision, OAuthUnlinkInspection, OAuthVerifiedExternalIdentity, PrepareOAuthCommit } from "@yielded/auth/OAuth";
|
|
10
|
-
import { Statement } from "effect/sql/Statement";
|
|
1
|
+
import { OAuthCoordinatorError, OAuthKernel } from "@yielded/auth-persistence/Adapter";
|
|
11
2
|
//#region src/drizzle/oauth-target.d.ts
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export declare const
|
|
15
|
-
|
|
16
|
-
readonly issue: <A>(input: OAuthPendingFlow, prepare: PrepareOAuthCommit<OAuthIssueDecision, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
17
|
-
readonly claim: <A>(input: {
|
|
18
|
-
readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
|
|
19
|
-
readonly generation: number;
|
|
20
|
-
readonly flowId: import("@yielded/auth/Operations").RequestBindingFlowId;
|
|
21
|
-
readonly provider: import("@yielded/auth/OAuth").OAuthProviderKey;
|
|
22
|
-
readonly callbackId: string & import("effect/Brand").Brand<"effect-auth/OAuthCallbackId">;
|
|
23
|
-
readonly stateDigest: import("@yielded/auth/Schema").TokenDigest;
|
|
24
|
-
readonly requestBindingVerifier: import("@yielded/auth/Schema").TokenDigest;
|
|
25
|
-
readonly requestBindingExpiresAtMillis: number;
|
|
26
|
-
readonly responseIssuer?: string & import("effect/Brand").Brand<"effect-auth/OAuthIssuer">;
|
|
27
|
-
readonly claimId: string & import("effect/Brand").Brand<"effect-auth/OAuthClaimId">;
|
|
28
|
-
readonly nowMillis: number;
|
|
29
|
-
}, prepare: PrepareOAuthCommit<OAuthClaimDecision, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
30
|
-
readonly settle: <A>(input: {
|
|
31
|
-
readonly claim: OAuthClaim;
|
|
32
|
-
readonly outcome: {
|
|
33
|
-
readonly _tag: "Verified";
|
|
34
|
-
readonly identity: OAuthVerifiedExternalIdentity;
|
|
35
|
-
} | {
|
|
36
|
-
readonly _tag: "Cancelled" | "Rejected" | "Ambiguous";
|
|
37
|
-
};
|
|
38
|
-
readonly nowMillis: number;
|
|
39
|
-
}, prepare: PrepareOAuthCommit<OAuthSettlementDecision, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
40
|
-
readonly cleanup: <A>(input: OAuthCleanupInput, prepare: PrepareOAuthCommit<{
|
|
41
|
-
readonly terminalized: number;
|
|
42
|
-
readonly removed: number;
|
|
43
|
-
readonly hasMore: boolean;
|
|
44
|
-
}, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
45
|
-
};
|
|
46
|
-
}, OAuthUnavailable, Crypto.Crypto | LifecycleHooks | NativeDatabase>;
|
|
47
|
-
export declare const makeTargetOAuthRegistrationIntentServices: (mapping: any, configuration: OAuthTargetConfiguration) => Effect.Effect<{
|
|
48
|
-
oauthRegistrationIntents: {
|
|
49
|
-
readonly settle: <A>(input: {
|
|
50
|
-
readonly claim: OAuthClaim;
|
|
51
|
-
readonly identity: OAuthVerifiedExternalIdentity;
|
|
52
|
-
readonly intent?: OAuthRegistrationIntent;
|
|
53
|
-
readonly nowMillis: number;
|
|
54
|
-
}, prepare: PrepareOAuthCommit<import("@yielded/auth/OAuth").OAuthRegistrationSettlement, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
55
|
-
};
|
|
56
|
-
}, OAuthUnavailable, Crypto.Crypto | LifecycleHooks | NativeDatabase>;
|
|
57
|
-
export declare const makeTargetOAuthAccountsServices: (mapping: any, configuration: OAuthTargetConfiguration) => Effect.Effect<{
|
|
58
|
-
oauthAccountsPersistence: {
|
|
59
|
-
readonly capture: (input: {
|
|
60
|
-
readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
|
|
61
|
-
readonly subjectId: import("@yielded/auth/Schema").SubjectId;
|
|
62
|
-
}) => Effect.Effect<OAuthAccountRevision | undefined, OAuthUnavailable>;
|
|
63
|
-
readonly issue: <A>(input: {
|
|
64
|
-
readonly flow: OAuthLinkPendingFlow;
|
|
65
|
-
readonly authorization: import("@yielded/auth/OAuth").OAuthActionAuthorization;
|
|
66
|
-
}, prepare: PrepareOAuthCommit<typeof OAuthLinkIssueDecision.Type, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
67
|
-
readonly preflight: (input: import("@yielded/auth/OAuth").OAuthLinkAccess) => Effect.Effect<OAuthLinkPendingFlow | undefined, OAuthUnavailable>;
|
|
68
|
-
readonly claim: <A>(input: {
|
|
69
|
-
readonly access: import("@yielded/auth/OAuth").OAuthLinkAccess;
|
|
70
|
-
readonly flow: OAuthLinkPendingFlow;
|
|
71
|
-
readonly claimId: import("@yielded/auth/OAuth").OAuthLinkClaim["claimId"];
|
|
72
|
-
readonly authorization: import("@yielded/auth/OAuth").OAuthActionAuthorization;
|
|
73
|
-
}, prepare: PrepareOAuthCommit<typeof OAuthLinkClaimDecision.Type, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
74
|
-
readonly settle: <A>(input: {
|
|
75
|
-
readonly claim: import("@yielded/auth/OAuth").OAuthLinkClaim;
|
|
76
|
-
readonly outcome: import("@yielded/auth/OAuth").OAuthLinkOutcome;
|
|
77
|
-
readonly authorization: import("@yielded/auth/OAuth").OAuthActionAuthorization;
|
|
78
|
-
readonly invalidation: import("@yielded/auth/Sessions").SessionInvalidationWindow;
|
|
79
|
-
readonly nowMillis: number;
|
|
80
|
-
}, prepare: PrepareOAuthCommit<typeof OAuthLinkDecision.Type, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
81
|
-
readonly inspectUnlink: (input: {
|
|
82
|
-
readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
|
|
83
|
-
readonly subjectId: import("@yielded/auth/Schema").SubjectId;
|
|
84
|
-
readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
|
|
85
|
-
readonly credentialId: string;
|
|
86
|
-
}) => Effect.Effect<typeof OAuthUnlinkInspection.Type, OAuthUnavailable>;
|
|
87
|
-
readonly unlink: <A>(input: {
|
|
88
|
-
readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
|
|
89
|
-
readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
|
|
90
|
-
readonly credential: OAuthCredentialSnapshot;
|
|
91
|
-
readonly authorization: import("@yielded/auth/OAuth").OAuthActionAuthorization;
|
|
92
|
-
readonly invalidation: import("@yielded/auth/Sessions").SessionInvalidationWindow;
|
|
93
|
-
readonly nowMillis: number;
|
|
94
|
-
readonly retentionUntilMillis: number;
|
|
95
|
-
}, prepare: PrepareOAuthCommit<typeof OAuthUnlinkDecision.Type, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
96
|
-
readonly cleanup: <A>(input: OAuthCleanupInput, prepare: PrepareOAuthCommit<{
|
|
97
|
-
readonly terminalized: number;
|
|
98
|
-
readonly removed: number;
|
|
99
|
-
readonly hasMore: boolean;
|
|
100
|
-
}, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
|
|
101
|
-
};
|
|
102
|
-
}, OAuthUnavailable, Crypto.Crypto | LifecycleHooks | NativeDatabase>;
|
|
103
|
-
export declare const oauthAccountsPersistenceLayer: <E, R>(services: Effect.Effect<Effect.Success<ReturnType<typeof makeTargetOAuthAccountsServices>>, E, R>) => Layer.Layer<OAuthAccountsPersistence, E, Exclude<R, import("effect/Scope").Scope>>;
|
|
104
|
-
export declare const oauthSignInPersistenceLayer: <E, R>(services: Effect.Effect<Effect.Success<ReturnType<typeof makeTargetOAuthSignInServices>>, E, R>) => Layer.Layer<OAuthSignInPersistence, E, Exclude<R, import("effect/Scope").Scope>>;
|
|
105
|
-
export declare const oauthRegistrationIntentsLayer: <E, R>(services: Effect.Effect<Effect.Success<ReturnType<typeof makeTargetOAuthRegistrationIntentServices>>, E, R>) => Layer.Layer<OAuthRegistrationIntents, E, Exclude<R, import("effect/Scope").Scope>>;
|
|
106
|
-
export declare const oauthRegistrationAuthorityLayer: <Id, Registration, E, R>(tag: Context.Key<Id, OAuthRegistrationAuthority<Registration>>, services: Effect.Effect<{
|
|
107
|
-
readonly registrationAuthority: OAuthRegistrationAuthority<Registration>;
|
|
108
|
-
}, E, R>) => Layer.Layer<Id, E, Exclude<R, import("effect/Scope").Scope>>;
|
|
3
|
+
export declare const oauthAccountsPersistenceLayer: OAuthKernel["target"]["oauthAccountsPersistenceLayer"];
|
|
4
|
+
export declare const oauthSignInPersistenceLayer: OAuthKernel["target"]["oauthSignInPersistenceLayer"];
|
|
5
|
+
export declare const oauthRegistrationIntentsLayer: OAuthKernel["target"]["oauthRegistrationIntentsLayer"];
|
|
6
|
+
export declare const oauthRegistrationAuthorityLayer: OAuthKernel["target"]["oauthRegistrationAuthorityLayer"];
|
|
109
7
|
//#endregion
|
|
8
|
+
export type { OAuthCoordinatorError };
|
|
110
9
|
//# sourceMappingURL=oauth-target.d.mts.map
|
|
@@ -1,249 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { captureOAuthMapping, invariant, nonce, unavailable } from "./oauth-state.mjs";
|
|
3
|
-
import { both } from "./transaction-owner.mjs";
|
|
4
|
-
import { CurrentOAuthTransaction, col, equal } from "./oauth-owner.mjs";
|
|
5
|
-
import { claimFlow, cleanupFlows, discoverOwned, exactClaim, issueFlow, matchesAccess, readFlow, resolveOwned, terminalFlow } from "./oauth-flow.mjs";
|
|
6
|
-
import { inspectIntent, register, registrationData, registrationResources, settleRegistrationIntent } from "./oauth-registration.mjs";
|
|
7
|
-
import { accountCurrent, claimLink, inspectUnlink, issueLink, preflightLink, settleLink, unlink } from "./oauth-accounts.mjs";
|
|
8
|
-
import { accountsInputs, capturedOAuthService, registrationInputs, registrationIntentInputs, signInInputs } from "./oauth-input.mjs";
|
|
9
|
-
import { coordinateTransactionOwner, makeTransactionExecution, sqlClientTransactionStandaloneGuard } from "./transaction-execution.mjs";
|
|
10
|
-
import { eq, sql } from "drizzle-orm";
|
|
11
|
-
import { Effect, Layer } from "effect";
|
|
12
|
-
import { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
13
|
-
import { OAuthAccountRevision, OAuthAccountsPersistence, OAuthClaim, OAuthClaimDecision, OAuthCleanupInput, OAuthCredentialSnapshot, OAuthIssueDecision, OAuthLinkClaimDecision, OAuthLinkDecision, OAuthLinkIssueDecision, OAuthLinkPendingFlow, OAuthPendingFlow, OAuthRegistrationFingerprint, OAuthRegistrationIntent, OAuthRegistrationIntents, OAuthSettlementDecision, OAuthSignInPersistence, OAuthUnlinkDecision, OAuthUnlinkInspection, OAuthVerifiedExternalIdentity, snapshotOAuthSync } from "@yielded/auth/OAuth";
|
|
1
|
+
import { oauthKernel } from "./oauth-kernel.mjs";
|
|
14
2
|
//#region src/drizzle/oauth-target.ts
|
|
15
|
-
const sqlClientOAuthStandaloneGuard =
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}));
|
|
29
|
-
const makeOAuthSignIn = (mapping, execute) => capturedOAuthService({
|
|
30
|
-
issue: (original, prepare) => execute.run(Effect.gen(function* () {
|
|
31
|
-
const input = snapshotOAuthSync(OAuthPendingFlow, original);
|
|
32
|
-
const value = yield* issueFlow(mapping, input, "sign-in");
|
|
33
|
-
return yield* prepareValue(snapshotOAuthSync(OAuthIssueDecision, value), prepare);
|
|
34
|
-
})),
|
|
35
|
-
claim: (input, prepare) => execute.run(Effect.gen(function* () {
|
|
36
|
-
const read = yield* readFlow(mapping, input, "sign-in");
|
|
37
|
-
const claim = read.row !== void 0 && read.flow !== void 0 && matchesAccess(read.flow, input) ? yield* claimFlow(mapping, {
|
|
38
|
-
row: read.row,
|
|
39
|
-
flow: read.flow
|
|
40
|
-
}, input.claimId) : void 0;
|
|
41
|
-
return yield* prepareValue(snapshotOAuthSync(OAuthClaimDecision, claim === void 0 ? { _tag: "Rejected" } : {
|
|
42
|
-
_tag: "Claimed",
|
|
43
|
-
claim
|
|
44
|
-
}), prepare);
|
|
45
|
-
})),
|
|
46
|
-
settle: (original, prepare) => execute.run(Effect.gen(function* () {
|
|
47
|
-
const claim = snapshotOAuthSync(OAuthClaim, original.claim);
|
|
48
|
-
const outcome = original.outcome;
|
|
49
|
-
const identity = outcome._tag === "Verified" ? snapshotOAuthSync(OAuthVerifiedExternalIdentity, outcome.identity).identity : void 0;
|
|
50
|
-
if (identity !== void 0) invariant(identity.provider === claim.flow.context.provider && identity.issuer === claim.flow.context.issuer);
|
|
51
|
-
const found = identity === void 0 ? void 0 : yield* discoverOwned(mapping, identity);
|
|
52
|
-
const exact = yield* exactClaim(mapping, claim, "sign-in");
|
|
53
|
-
let value = { _tag: "Rejected" };
|
|
54
|
-
if (exact !== void 0) {
|
|
55
|
-
const credential = identity === void 0 ? void 0 : resolveOwned(mapping, claim.flow.context.moduleId, identity, found);
|
|
56
|
-
value = outcome._tag !== "Verified" ? { _tag: outcome._tag } : credential === void 0 ? { _tag: "Rejected" } : {
|
|
57
|
-
_tag: "Verified",
|
|
58
|
-
credential
|
|
59
|
-
};
|
|
60
|
-
yield* terminalFlow(mapping, claim.flow, value._tag);
|
|
61
|
-
}
|
|
62
|
-
return yield* prepareValue(snapshotOAuthSync(OAuthSettlementDecision, value), prepare);
|
|
63
|
-
})),
|
|
64
|
-
cleanup: (input, prepare) => execute.run(Effect.gen(function* () {
|
|
65
|
-
const value = yield* cleanupFlows(mapping, input, "sign-in");
|
|
66
|
-
return yield* prepareValue(value, prepare);
|
|
67
|
-
}))
|
|
68
|
-
}, signInInputs, execute.active, execute.poison);
|
|
69
|
-
const makeOAuthRegistrationIntents = (mapping, execute) => capturedOAuthService({ settle: (input, prepare) => execute.run(Effect.gen(function* () {
|
|
70
|
-
const value = yield* settleRegistrationIntent(mapping, {
|
|
71
|
-
claim: snapshotOAuthSync(OAuthClaim, input.claim),
|
|
72
|
-
identity: snapshotOAuthSync(OAuthVerifiedExternalIdentity, input.identity),
|
|
73
|
-
...input.intent === void 0 ? {} : { intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent) }
|
|
74
|
-
});
|
|
75
|
-
return yield* prepareValue(value, prepare);
|
|
76
|
-
})) }, registrationIntentInputs, execute.active, execute.poison);
|
|
77
|
-
const makeOAuthRegistration = (mapping, execute, allocated) => capturedOAuthService({
|
|
78
|
-
read: (input) => execute.run(Effect.map(inspectIntent(mapping, input), (result) => result?.inspection), false),
|
|
79
|
-
inspect: (input) => Effect.gen(function* () {
|
|
80
|
-
yield* execute.admit;
|
|
81
|
-
const intent = snapshotOAuthSync(OAuthRegistrationIntent, input.intent);
|
|
82
|
-
const stored = mapping.application.encode(input.registration);
|
|
83
|
-
invariant(typeof stored === "string" && new TextEncoder().encode(stored).length <= 1048576);
|
|
84
|
-
const detached = {
|
|
85
|
-
intent,
|
|
86
|
-
registration: mapping.application.decode(stored)
|
|
87
|
-
};
|
|
88
|
-
const checked = execute.bound ? (invariant(mapping.inspectSync !== void 0), mapping.inspectSync(detached)) : yield* mapping.inspect(detached);
|
|
89
|
-
invariant(typeof checked.eligible === "boolean");
|
|
90
|
-
return {
|
|
91
|
-
fingerprint: snapshotOAuthSync(OAuthRegistrationFingerprint, checked.fingerprint),
|
|
92
|
-
eligible: checked.eligible
|
|
93
|
-
};
|
|
94
|
-
}).pipe((effect) => execute.bound ? execute.run(effect, false) : effect, Effect.onExit((exit) => Effect.sync(() => {
|
|
95
|
-
if (exit._tag === "Failure") execute.poison();
|
|
96
|
-
})), Effect.mapError(unavailable), Effect.catchDefect(() => Effect.fail(unavailable()))),
|
|
97
|
-
register: (input, prepare) => Effect.gen(function* () {
|
|
98
|
-
yield* execute.admit;
|
|
99
|
-
const data = yield* registrationData(mapping, input, execute.bound);
|
|
100
|
-
const resources = allocated ?? (yield* registrationResources(mapping));
|
|
101
|
-
return yield* execute.run(Effect.gen(function* () {
|
|
102
|
-
const value = yield* register(mapping, input, data, resources);
|
|
103
|
-
return yield* prepareValue(value, prepare);
|
|
104
|
-
}));
|
|
105
|
-
}).pipe(Effect.onExit((exit) => Effect.sync(() => {
|
|
106
|
-
if (exit._tag === "Failure") execute.poison();
|
|
107
|
-
})), Effect.mapError(unavailable), Effect.catchDefect(() => Effect.fail(unavailable()))),
|
|
108
|
-
cleanup: (original, prepare) => execute.run(Effect.gen(function* () {
|
|
109
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
110
|
-
const input = snapshotOAuthSync(OAuthCleanupInput, original), i = mapping.intent, r = mapping.command;
|
|
111
|
-
const now = yield* owner.now(mapping.clock);
|
|
112
|
-
const candidates = yield* owner.read(i.table, both(eq(col(i.table, i.moduleId), input.moduleId), sql`${col(i.table, i.state)} <> 'ProvisioningPending' and ${col(i.table, i.retentionUntil)} < ${mapping.clock.encodeInstant(now)}`), {
|
|
113
|
-
limit: input.limit,
|
|
114
|
-
observe: false,
|
|
115
|
-
takeOnly: true
|
|
116
|
-
});
|
|
117
|
-
let removed = 0;
|
|
118
|
-
for (const candidate of candidates.rows) {
|
|
119
|
-
const row = (yield* owner.read(i.table, equal(i.table, {
|
|
120
|
-
[i.moduleId]: input.moduleId,
|
|
121
|
-
[i.reference]: candidate[i.reference]
|
|
122
|
-
}), { limit: 1 })).rows[0];
|
|
123
|
-
if (row === void 0 || row[i.state] === "ProvisioningPending") continue;
|
|
124
|
-
let horizon = mapping.clock.decodeInstant(row[i.retentionUntil]);
|
|
125
|
-
if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock))) continue;
|
|
126
|
-
if (row[i.commandId] !== null) {
|
|
127
|
-
const command = (yield* owner.read(r.table, equal(r.table, {
|
|
128
|
-
[r.moduleId]: input.moduleId,
|
|
129
|
-
[r.commandId]: row[i.commandId]
|
|
130
|
-
}), { limit: 1 })).rows[0];
|
|
131
|
-
if (command === void 0) continue;
|
|
132
|
-
horizon = Math.max(horizon, mapping.clock.decodeInstant(command[r.retentionUntil]));
|
|
133
|
-
if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock))) continue;
|
|
134
|
-
yield* owner.remove(r.table, {
|
|
135
|
-
[r.moduleId]: input.moduleId,
|
|
136
|
-
[r.commandId]: row[i.commandId]
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
yield* owner.remove(i.table, {
|
|
140
|
-
[i.moduleId]: input.moduleId,
|
|
141
|
-
[i.reference]: row[i.reference]
|
|
142
|
-
});
|
|
143
|
-
owner.postconditions.push(sql`${mapping.clock.engineNowMillis} > ${horizon}`);
|
|
144
|
-
removed++;
|
|
145
|
-
}
|
|
146
|
-
return yield* prepareValue({
|
|
147
|
-
removed,
|
|
148
|
-
hasMore: candidates.rows.length === input.limit
|
|
149
|
-
}, prepare);
|
|
150
|
-
}))
|
|
151
|
-
}, registrationInputs(mapping.application), execute.active, execute.poison);
|
|
152
|
-
const makeTargetOAuthSignInServices = (mapping, configuration) => {
|
|
153
|
-
const captured = captureOAuthMapping(mapping);
|
|
154
|
-
return Effect.map(makeOAuthExecution(configuration, captured), (execution) => ({ oauthSignInPersistence: makeOAuthSignIn(captured, execution) }));
|
|
155
|
-
};
|
|
156
|
-
const makeTargetOAuthRegistrationIntentServices = (mapping, configuration) => {
|
|
157
|
-
const captured = captureOAuthMapping(mapping);
|
|
158
|
-
return Effect.map(makeOAuthExecution(configuration, captured), (execution) => ({ oauthRegistrationIntents: makeOAuthRegistrationIntents(captured, execution) }));
|
|
159
|
-
};
|
|
160
|
-
const makeTargetOAuthRegistrationServices = (mapping, configuration) => {
|
|
161
|
-
const captured = captureOAuthMapping(mapping);
|
|
162
|
-
return Effect.map(makeOAuthExecution(configuration, captured), (execution) => ({ registrationAuthority: makeOAuthRegistration(captured, execution) }));
|
|
163
|
-
};
|
|
164
|
-
const coordinateOAuthOwner = (database, mapping, configuration, allocate, services, owner) => {
|
|
165
|
-
const captured = captureOAuthMapping(mapping);
|
|
166
|
-
return Effect.flatMap(LifecycleHooks, (hooks) => coordinateTransactionOwner(database, CurrentOAuthTransaction, configuration, validateDrizzleStorage(captured).pipe(Effect.andThen(Effect.suspend(() => allocate(captured)))), unavailable, nonce, (execution, resources) => services(captured, {
|
|
167
|
-
...execution,
|
|
168
|
-
run: (operation, mutation) => execution.run(operation, mutation).pipe(Effect.provideService(LifecycleHooks, hooks))
|
|
169
|
-
}, resources), owner).pipe(Effect.provideService(LifecycleHooks, hooks)));
|
|
170
|
-
};
|
|
171
|
-
const accountResources = (mapping) => Effect.gen(function* () {
|
|
172
|
-
return {
|
|
173
|
-
credentialId: snapshotOAuthSync(OAuthCredentialSnapshot.fields.credentialId, yield* mapping.allocateCredentialId),
|
|
174
|
-
revision: snapshotOAuthSync(OAuthCredentialSnapshot.fields.credentialRevision, yield* mapping.allocateRevision)
|
|
175
|
-
};
|
|
176
|
-
});
|
|
177
|
-
const coordinateTargetOAuthRegistration = (database, mapping, configuration, owner) => coordinateOAuthOwner(database, mapping, configuration, registrationResources, (captured, execute, resources) => ({ registrationAuthority: makeOAuthRegistration(captured, execute, resources) }), owner);
|
|
178
|
-
const coordinateTargetOAuthSignIn = (database, mapping, configuration, owner) => coordinateOAuthOwner(database, mapping, configuration, () => Effect.void, (captured, execute) => ({ oauthSignInPersistence: makeOAuthSignIn(captured, execute) }), owner);
|
|
179
|
-
const coordinateTargetOAuthRegistrationIntents = (database, mapping, configuration, owner) => coordinateOAuthOwner(database, mapping, configuration, () => Effect.void, (captured, execute) => ({ oauthRegistrationIntents: makeOAuthRegistrationIntents(captured, execute) }), owner);
|
|
180
|
-
const coordinateTargetOAuthAccounts = (database, mapping, configuration, owner) => coordinateOAuthOwner(database, mapping, configuration, accountResources, (captured, execute, resources) => ({ oauthAccountsPersistence: makeOAuthAccounts(captured, execute, resources) }), owner);
|
|
181
|
-
const makeOAuthAccounts = (mapping, execute, resources) => capturedOAuthService({
|
|
182
|
-
capture: (input) => execute.run(Effect.map(accountCurrent(mapping, input.subjectId), (current) => current === void 0 ? void 0 : snapshotOAuthSync(OAuthAccountRevision, current.revision)), false),
|
|
183
|
-
issue: (input, prepare) => execute.run(Effect.gen(function* () {
|
|
184
|
-
const value = yield* issueLink(mapping, input);
|
|
185
|
-
return yield* prepareValue(snapshotOAuthSync(OAuthLinkIssueDecision, value), prepare);
|
|
186
|
-
})),
|
|
187
|
-
preflight: (input) => execute.run(Effect.map(preflightLink(mapping, input), (current) => current === void 0 ? void 0 : snapshotOAuthSync(OAuthLinkPendingFlow, current.flow)), false),
|
|
188
|
-
claim: (input, prepare) => execute.run(Effect.gen(function* () {
|
|
189
|
-
const value = yield* claimLink(mapping, input);
|
|
190
|
-
return yield* prepareValue(snapshotOAuthSync(OAuthLinkClaimDecision, value), prepare);
|
|
191
|
-
})),
|
|
192
|
-
settle: (input, prepare) => Effect.gen(function* () {
|
|
193
|
-
yield* execute.admit;
|
|
194
|
-
const allocated = resources ?? (yield* accountResources(mapping));
|
|
195
|
-
return yield* execute.run(Effect.gen(function* () {
|
|
196
|
-
const value = yield* settleLink(mapping, input, allocated);
|
|
197
|
-
return yield* prepareValue(snapshotOAuthSync(OAuthLinkDecision, value), prepare);
|
|
198
|
-
}));
|
|
199
|
-
}).pipe(Effect.mapError(unavailable), Effect.catchDefect(() => Effect.fail(unavailable()))),
|
|
200
|
-
inspectUnlink: (input) => execute.run(Effect.map(inspectUnlink(mapping, input), (value) => snapshotOAuthSync(OAuthUnlinkInspection, value)), false),
|
|
201
|
-
unlink: (input, prepare) => execute.run(Effect.gen(function* () {
|
|
202
|
-
const value = yield* unlink(mapping, input);
|
|
203
|
-
return yield* prepareValue(snapshotOAuthSync(OAuthUnlinkDecision, value), prepare);
|
|
204
|
-
})),
|
|
205
|
-
cleanup: (input, prepare) => execute.run(Effect.gen(function* () {
|
|
206
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
207
|
-
const value = yield* cleanupFlows(mapping, input, "link");
|
|
208
|
-
const remaining = input.limit - value.terminalized - value.removed;
|
|
209
|
-
const now = yield* owner.now(mapping.clock), r = mapping.command;
|
|
210
|
-
let removed = 0;
|
|
211
|
-
if (remaining > 0) {
|
|
212
|
-
const rows = yield* owner.read(r.table, both(eq(col(r.table, r.moduleId), input.moduleId), sql`${col(r.table, r.retentionUntil)} < ${mapping.clock.encodeInstant(now)}`), {
|
|
213
|
-
limit: remaining,
|
|
214
|
-
observe: false,
|
|
215
|
-
takeOnly: true
|
|
216
|
-
});
|
|
217
|
-
for (const row of rows.rows) {
|
|
218
|
-
const key = {
|
|
219
|
-
[r.moduleId]: input.moduleId,
|
|
220
|
-
[r.commandId]: row[r.commandId]
|
|
221
|
-
};
|
|
222
|
-
const current = (yield* owner.read(r.table, equal(r.table, key), { limit: 1 })).rows[0];
|
|
223
|
-
if (current === void 0) continue;
|
|
224
|
-
const horizon = mapping.clock.decodeInstant(current[r.retentionUntil]);
|
|
225
|
-
if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock))) continue;
|
|
226
|
-
yield* owner.remove(r.table, key);
|
|
227
|
-
owner.postconditions.push(sql`${mapping.clock.engineNowMillis} > ${horizon}`);
|
|
228
|
-
removed++;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return yield* prepareValue({
|
|
232
|
-
...value,
|
|
233
|
-
removed: value.removed + removed,
|
|
234
|
-
hasMore: value.hasMore || remaining === removed
|
|
235
|
-
}, prepare);
|
|
236
|
-
}))
|
|
237
|
-
}, accountsInputs, execute.active, execute.poison);
|
|
238
|
-
const makeTargetOAuthAccountsServices = (mapping, configuration) => {
|
|
239
|
-
const captured = captureOAuthMapping(mapping);
|
|
240
|
-
return Effect.map(makeOAuthExecution(configuration, captured), (execution) => ({ oauthAccountsPersistence: makeOAuthAccounts(captured, execution) }));
|
|
241
|
-
};
|
|
242
|
-
const oauthAccountsPersistenceLayer = (services) => Layer.effect(OAuthAccountsPersistence, Effect.map(services, (value) => value.oauthAccountsPersistence));
|
|
243
|
-
const oauthSignInPersistenceLayer = (services) => Layer.effect(OAuthSignInPersistence, Effect.map(services, (value) => value.oauthSignInPersistence));
|
|
244
|
-
const oauthRegistrationIntentsLayer = (services) => Layer.effect(OAuthRegistrationIntents, Effect.map(services, (value) => value.oauthRegistrationIntents));
|
|
245
|
-
const oauthRegistrationAuthorityLayer = (tag, services) => Layer.effect(tag, Effect.map(services, (value) => value.registrationAuthority));
|
|
3
|
+
const sqlClientOAuthStandaloneGuard = oauthKernel.target.sqlClientOAuthStandaloneGuard;
|
|
4
|
+
const makeTargetOAuthSignInServices = oauthKernel.target.makeTargetOAuthSignInServices;
|
|
5
|
+
const makeTargetOAuthRegistrationIntentServices = oauthKernel.target.makeTargetOAuthRegistrationIntentServices;
|
|
6
|
+
const makeTargetOAuthRegistrationServices = oauthKernel.target.makeTargetOAuthRegistrationServices;
|
|
7
|
+
const coordinateTargetOAuthRegistration = oauthKernel.target.coordinateTargetOAuthRegistration;
|
|
8
|
+
const coordinateTargetOAuthSignIn = oauthKernel.target.coordinateTargetOAuthSignIn;
|
|
9
|
+
const coordinateTargetOAuthRegistrationIntents = oauthKernel.target.coordinateTargetOAuthRegistrationIntents;
|
|
10
|
+
const coordinateTargetOAuthAccounts = oauthKernel.target.coordinateTargetOAuthAccounts;
|
|
11
|
+
const makeTargetOAuthAccountsServices = oauthKernel.target.makeTargetOAuthAccountsServices;
|
|
12
|
+
const oauthAccountsPersistenceLayer = oauthKernel.target.oauthAccountsPersistenceLayer;
|
|
13
|
+
const oauthSignInPersistenceLayer = oauthKernel.target.oauthSignInPersistenceLayer;
|
|
14
|
+
const oauthRegistrationIntentsLayer = oauthKernel.target.oauthRegistrationIntentsLayer;
|
|
15
|
+
const oauthRegistrationAuthorityLayer = oauthKernel.target.oauthRegistrationAuthorityLayer;
|
|
246
16
|
//#endregion
|
|
247
|
-
export {
|
|
17
|
+
export { coordinateTargetOAuthAccounts, coordinateTargetOAuthRegistration, coordinateTargetOAuthRegistrationIntents, coordinateTargetOAuthSignIn, makeTargetOAuthAccountsServices, makeTargetOAuthRegistrationIntentServices, makeTargetOAuthRegistrationServices, makeTargetOAuthSignInServices, oauthAccountsPersistenceLayer, oauthRegistrationAuthorityLayer, oauthRegistrationIntentsLayer, oauthSignInPersistenceLayer, sqlClientOAuthStandaloneGuard };
|
|
248
18
|
|
|
249
19
|
//# sourceMappingURL=oauth-target.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-target.mjs","names":[],"sources":["../../src/drizzle/oauth-target.ts"],"sourcesContent":["import type { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport { LifecycleHooks } from \"@yielded/auth/Hooks\";\nimport {\n OAuthAccountRevision,\n OAuthLinkClaimDecision,\n OAuthLinkDecision,\n OAuthLinkIssueDecision,\n OAuthLinkPendingFlow,\n OAuthUnlinkDecision,\n OAuthUnlinkInspection,\n OAuthAccountsPersistence,\n OAuthRegistrationIntents,\n OAuthSignInPersistence,\n type PrepareOAuthCommit,\n OAuthRegistrationIntent,\n OAuthRegistrationFingerprint,\n OAuthClaim,\n OAuthClaimDecision,\n OAuthCleanupInput,\n OAuthIssueDecision,\n OAuthPendingFlow,\n OAuthSettlementDecision,\n OAuthVerifiedExternalIdentity,\n OAuthCredentialSnapshot,\n snapshotOAuthSync,\n type OAuthUnavailable,\n} from \"@yielded/auth/OAuth\";\nimport type { SecurityRevision } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- concrete driver entry points restore table/database generics. */\nimport { eq, sql } from \"drizzle-orm\";\nimport { type Crypto, type Context, Effect, Layer } from \"effect\";\nimport type { Statement } from \"effect/sql/Statement\";\n\nimport type { PersistenceMappingError } from \"./model\";\nimport {\n accountCurrent,\n claimLink,\n inspectUnlink,\n issueLink,\n preflightLink,\n settleLink,\n unlink,\n} from \"./oauth-accounts\";\nimport {\n claimFlow,\n cleanupFlows,\n discoverOwned,\n exactClaim,\n issueFlow,\n matchesAccess,\n readFlow,\n resolveOwned,\n terminalFlow,\n} from \"./oauth-flow\";\nimport {\n accountsInputs,\n capturedOAuthService,\n registrationInputs,\n registrationIntentInputs,\n signInInputs,\n} from \"./oauth-input\";\nimport type { OAuthRegistrationAuthority } from \"./oauth-model\";\nimport { both, col, equal, CurrentOAuthTransaction, type OAuthNativeDatabase } from \"./oauth-owner\";\nimport {\n inspectIntent,\n register,\n registrationData,\n registrationResources,\n type RegistrationCallbacks,\n settleRegistrationIntent,\n} from \"./oauth-registration\";\nimport { captureOAuthMapping, invariant, nonce, unavailable } from \"./oauth-state\";\nimport { validateDrizzleStorage } from \"./storage-validation\";\nimport {\n coordinateTransactionOwner,\n makeTransactionExecution,\n sqlClientTransactionStandaloneGuard,\n type TransactionTargetConfiguration,\n type TransactionCoordinatorError,\n type TransactionExecution,\n} from \"./transaction-execution\";\n\nexport type OAuthTargetConfiguration = TransactionTargetConfiguration<OAuthUnavailable>;\nexport type OAuthCoordinatorError<E> = TransactionCoordinatorError<E, OAuthUnavailable>;\nexport type OAuthExecution = TransactionExecution<OAuthUnavailable, CurrentOAuthTransaction, never>;\n\nexport const sqlClientOAuthStandaloneGuard = (\n service: Parameters<typeof sqlClientTransactionStandaloneGuard>[1],\n) => sqlClientTransactionStandaloneGuard(unavailable, service);\n\nexport const makeOAuthExecution = Effect.fnUntraced(function* (\n configuration: OAuthTargetConfiguration,\n mapping: unknown,\n): Effect.fn.Return<\n OAuthExecution,\n OAuthUnavailable,\n LifecycleHooks | NativeDatabase | Crypto.Crypto\n> {\n const hooks = yield* LifecycleHooks;\n\n yield* validateDrizzleStorage(mapping).pipe(Effect.mapError(unavailable));\n\n const execution = yield* makeTransactionExecution(\n CurrentOAuthTransaction,\n configuration,\n unavailable,\n nonce,\n );\n\n return {\n ...execution,\n run: (operation, mutation) =>\n execution.run(operation, mutation).pipe(Effect.provideService(LifecycleHooks, hooks)),\n };\n});\n\nconst prepareValue = <Value, A>(value: Value, prepare: PrepareOAuthCommit<Value, A>) =>\n Effect.flatMap(CurrentOAuthTransaction, (owner) =>\n Effect.sync(() => {\n owner.guards.push(owner.journal.prepare(undefined));\n\n return prepare(value, owner.journal);\n }),\n );\n\nexport const makeOAuthSignIn = (\n mapping: any,\n execute: OAuthExecution,\n): OAuthSignInPersistence[\"Service\"] =>\n capturedOAuthService<OAuthSignInPersistence[\"Service\"]>(\n {\n issue: (original, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const input = snapshotOAuthSync(OAuthPendingFlow, original);\n const value = yield* issueFlow(mapping, input, \"sign-in\");\n\n return yield* prepareValue(\n snapshotOAuthSync(OAuthIssueDecision, value as never),\n prepare,\n );\n }),\n ),\n claim: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const read = yield* readFlow(mapping, input, \"sign-in\");\n\n const claim =\n read.row !== undefined && read.flow !== undefined && matchesAccess(read.flow, input)\n ? yield* claimFlow(mapping, { row: read.row, flow: read.flow }, input.claimId)\n : undefined;\n\n return yield* prepareValue(\n snapshotOAuthSync(\n OAuthClaimDecision,\n claim === undefined\n ? { _tag: \"Rejected\" }\n : { _tag: \"Claimed\", claim: claim as typeof OAuthClaim.Type },\n ),\n prepare,\n );\n }),\n ),\n settle: (original, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const claim = snapshotOAuthSync(OAuthClaim, original.claim);\n const outcome = original.outcome;\n\n const identity =\n outcome._tag === \"Verified\"\n ? snapshotOAuthSync(OAuthVerifiedExternalIdentity, outcome.identity).identity\n : undefined;\n\n if (identity !== undefined)\n invariant(\n identity.provider === claim.flow.context.provider &&\n identity.issuer === claim.flow.context.issuer,\n );\n\n // Discover/lock the existing subject before locking its claimed flow.\n const found =\n identity === undefined ? undefined : yield* discoverOwned(mapping, identity);\n\n const exact = yield* exactClaim(mapping, claim, \"sign-in\");\n let value: typeof OAuthSettlementDecision.Type = { _tag: \"Rejected\" };\n\n if (exact !== undefined) {\n const credential =\n identity === undefined\n ? undefined\n : resolveOwned(mapping, claim.flow.context.moduleId, identity, found);\n\n value =\n outcome._tag !== \"Verified\"\n ? { _tag: outcome._tag }\n : credential === undefined\n ? { _tag: \"Rejected\" }\n : { _tag: \"Verified\", credential };\n yield* terminalFlow(mapping, claim.flow, value._tag);\n }\n\n return yield* prepareValue(snapshotOAuthSync(OAuthSettlementDecision, value), prepare);\n }),\n ),\n cleanup: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* cleanupFlows(mapping, input, \"sign-in\");\n\n return yield* prepareValue(value, prepare);\n }),\n ),\n },\n signInInputs,\n execute.active,\n execute.poison,\n );\n\nexport const makeOAuthRegistrationIntents = (\n mapping: any,\n execute: OAuthExecution,\n): OAuthRegistrationIntents[\"Service\"] =>\n capturedOAuthService<OAuthRegistrationIntents[\"Service\"]>(\n {\n settle: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* settleRegistrationIntent(mapping, {\n claim: snapshotOAuthSync(OAuthClaim, input.claim),\n identity: snapshotOAuthSync(OAuthVerifiedExternalIdentity, input.identity),\n ...(input.intent === undefined\n ? {}\n : { intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent) }),\n });\n\n return yield* prepareValue(value, prepare);\n }),\n ),\n },\n registrationIntentInputs,\n execute.active,\n execute.poison,\n );\n\nexport const makeOAuthRegistration = <Registration>(\n mapping: any,\n execute: OAuthExecution,\n allocated?: Awaited<ReturnType<typeof registrationResources>> extends Effect.Effect<\n infer A,\n any,\n any\n >\n ? A\n : never,\n): OAuthRegistrationAuthority<Registration> =>\n capturedOAuthService<OAuthRegistrationAuthority<Registration>>(\n {\n read: (input) =>\n execute.run(\n Effect.map(inspectIntent(mapping, input), (result) => result?.inspection),\n false,\n ),\n inspect: (input) =>\n Effect.gen(function* () {\n yield* execute.admit;\n const intent = snapshotOAuthSync(OAuthRegistrationIntent, input.intent);\n const stored = mapping.application.encode(input.registration);\n\n invariant(\n typeof stored === \"string\" && new TextEncoder().encode(stored).length <= 1048576,\n );\n const detached = { intent, registration: mapping.application.decode(stored) };\n\n const checked = execute.bound\n ? (invariant(mapping.inspectSync !== undefined), mapping.inspectSync(detached))\n : yield* (mapping as RegistrationCallbacks<Registration>).inspect(detached);\n\n invariant(typeof checked.eligible === \"boolean\");\n\n return {\n fingerprint: snapshotOAuthSync(OAuthRegistrationFingerprint, checked.fingerprint),\n eligible: checked.eligible,\n };\n }).pipe(\n (effect) => (execute.bound ? execute.run(effect, false) : effect),\n Effect.onExit((exit) =>\n Effect.sync(() => {\n if (exit._tag === \"Failure\") execute.poison();\n }),\n ),\n Effect.mapError(unavailable),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n ) as never,\n register: (input, prepare) =>\n Effect.gen(function* () {\n yield* execute.admit;\n const data = yield* registrationData(mapping, input, execute.bound);\n const resources = allocated ?? (yield* registrationResources(mapping));\n\n return yield* execute.run(\n Effect.gen(function* () {\n const value = yield* register(mapping, input, data, resources);\n\n return yield* prepareValue(value, prepare);\n }),\n );\n }).pipe(\n Effect.onExit((exit) =>\n Effect.sync(() => {\n if (exit._tag === \"Failure\") execute.poison();\n }),\n ),\n Effect.mapError(unavailable),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n ) as never,\n cleanup: (original, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const owner = yield* CurrentOAuthTransaction;\n\n const input = snapshotOAuthSync(OAuthCleanupInput, original),\n i = mapping.intent,\n r = mapping.command;\n\n const now = yield* owner.now(mapping.clock);\n\n const candidates = yield* owner.read(\n i.table,\n both(\n eq(col(i.table, i.moduleId), input.moduleId),\n sql`${col(i.table, i.state)} <> 'ProvisioningPending' and ${col(i.table, i.retentionUntil)} < ${mapping.clock.encodeInstant(now)}`,\n ),\n { limit: input.limit, observe: false, takeOnly: true },\n );\n\n let removed = 0;\n\n for (const candidate of candidates.rows) {\n const selected = yield* owner.read(\n i.table,\n equal(i.table, {\n [i.moduleId]: input.moduleId,\n [i.reference]: candidate[i.reference],\n }),\n { limit: 1 },\n );\n\n const row = selected.rows[0];\n\n if (row === undefined || row[i.state] === \"ProvisioningPending\") continue;\n let horizon = mapping.clock.decodeInstant(row[i.retentionUntil]);\n\n if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock)))\n continue;\n if (row[i.commandId] !== null) {\n const commands = yield* owner.read(\n r.table,\n equal(r.table, {\n [r.moduleId]: input.moduleId,\n [r.commandId]: row[i.commandId],\n }),\n { limit: 1 },\n );\n\n const command = commands.rows[0];\n\n if (command === undefined) continue;\n horizon = Math.max(horizon, mapping.clock.decodeInstant(command[r.retentionUntil]));\n if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock)))\n continue;\n yield* owner.remove(r.table, {\n [r.moduleId]: input.moduleId,\n [r.commandId]: row[i.commandId],\n });\n }\n yield* owner.remove(i.table, {\n [i.moduleId]: input.moduleId,\n [i.reference]: row[i.reference],\n });\n owner.postconditions.push(sql`${mapping.clock.engineNowMillis} > ${horizon}`);\n removed++;\n }\n\n return yield* prepareValue(\n { removed, hasMore: candidates.rows.length === input.limit },\n prepare,\n );\n }),\n ),\n },\n registrationInputs(mapping.application),\n execute.active,\n execute.poison,\n );\n\nexport const makeTargetOAuthSignInServices = (\n mapping: any,\n configuration: OAuthTargetConfiguration,\n) => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.map(makeOAuthExecution(configuration, captured), (execution) => ({\n oauthSignInPersistence: makeOAuthSignIn(captured, execution),\n }));\n};\n\nexport const makeTargetOAuthRegistrationIntentServices = (\n mapping: any,\n configuration: OAuthTargetConfiguration,\n) => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.map(makeOAuthExecution(configuration, captured), (execution) => ({\n oauthRegistrationIntents: makeOAuthRegistrationIntents(captured, execution),\n }));\n};\n\nexport const makeTargetOAuthRegistrationServices = <Registration>(\n mapping: any,\n configuration: OAuthTargetConfiguration,\n) => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.map(makeOAuthExecution(configuration, captured), (execution) => ({\n registrationAuthority: makeOAuthRegistration<Registration>(captured, execution),\n }));\n};\n\nexport const coordinateOAuthOwner = <Services, Transaction, A, E, R>(\n database: OAuthNativeDatabase,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n allocate: (mapping: any) => Effect.Effect<any, PersistenceMappingError>,\n services: (mapping: any, execution: OAuthExecution, resources: any) => Services,\n owner: (\n transaction: Transaction,\n services: Services,\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n OAuthCoordinatorError<E>,\n R | Crypto.Crypto | LifecycleHooks | NativeDatabase\n> => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.flatMap(LifecycleHooks, (hooks) =>\n coordinateTransactionOwner(\n database,\n CurrentOAuthTransaction,\n configuration,\n validateDrizzleStorage(captured).pipe(\n Effect.andThen(Effect.suspend(() => allocate(captured))),\n ),\n unavailable,\n nonce,\n (execution, resources) =>\n services(\n captured,\n {\n ...execution,\n run: (operation, mutation) =>\n execution.run(operation, mutation).pipe(Effect.provideService(LifecycleHooks, hooks)),\n },\n resources,\n ),\n owner,\n ).pipe(Effect.provideService(LifecycleHooks, hooks)),\n );\n};\n\nconst accountResources = (mapping: any) =>\n Effect.gen(function* () {\n return {\n credentialId: snapshotOAuthSync(\n OAuthCredentialSnapshot.fields.credentialId,\n yield* mapping.allocateCredentialId as Effect.Effect<string, PersistenceMappingError>,\n ),\n revision: snapshotOAuthSync(\n OAuthCredentialSnapshot.fields.credentialRevision,\n yield* mapping.allocateRevision as Effect.Effect<SecurityRevision, PersistenceMappingError>,\n ),\n };\n });\n\nexport const coordinateTargetOAuthRegistration = <Registration, Transaction, A, E, R>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n owner: (\n transaction: Transaction,\n services: { readonly registrationAuthority: OAuthRegistrationAuthority<Registration> },\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateOAuthOwner(\n database,\n mapping,\n configuration,\n registrationResources,\n (captured, execute, resources) => ({\n registrationAuthority: makeOAuthRegistration<Registration>(captured, execute, resources),\n }),\n owner,\n );\n\nexport const coordinateTargetOAuthSignIn = <Transaction, A, E, R>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n owner: (\n transaction: Transaction,\n services: { readonly oauthSignInPersistence: OAuthSignInPersistence[\"Service\"] },\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateOAuthOwner(\n database,\n mapping,\n configuration,\n () => Effect.void,\n (captured, execute) => ({ oauthSignInPersistence: makeOAuthSignIn(captured, execute) }),\n owner,\n );\n\nexport const coordinateTargetOAuthRegistrationIntents = <Transaction, A, E, R>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n owner: (\n transaction: Transaction,\n services: { readonly oauthRegistrationIntents: OAuthRegistrationIntents[\"Service\"] },\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateOAuthOwner(\n database,\n mapping,\n configuration,\n () => Effect.void,\n (captured, execute) => ({\n oauthRegistrationIntents: makeOAuthRegistrationIntents(captured, execute),\n }),\n owner,\n );\n\nexport const coordinateTargetOAuthAccounts = <Transaction, A, E, R>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n owner: (\n transaction: Transaction,\n services: { readonly oauthAccountsPersistence: OAuthAccountsPersistence[\"Service\"] },\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateOAuthOwner(\n database,\n mapping,\n configuration,\n accountResources,\n (captured, execute, resources) => ({\n oauthAccountsPersistence: makeOAuthAccounts(captured, execute, resources),\n }),\n owner,\n );\n\nexport const makeOAuthAccounts = (\n mapping: any,\n execute: OAuthExecution,\n resources?: any,\n): OAuthAccountsPersistence[\"Service\"] =>\n capturedOAuthService<OAuthAccountsPersistence[\"Service\"]>(\n {\n capture: (input) =>\n execute.run(\n Effect.map(accountCurrent(mapping, input.subjectId), (current) =>\n current === undefined\n ? undefined\n : snapshotOAuthSync(OAuthAccountRevision, current.revision),\n ),\n false,\n ),\n issue: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* issueLink(mapping, input);\n\n return yield* prepareValue(\n snapshotOAuthSync(OAuthLinkIssueDecision, value as never),\n prepare,\n );\n }),\n ),\n preflight: (input) =>\n execute.run(\n Effect.map(preflightLink(mapping, input), (current) =>\n current === undefined\n ? undefined\n : snapshotOAuthSync(OAuthLinkPendingFlow, current.flow),\n ),\n false,\n ),\n claim: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* claimLink(mapping, input);\n\n return yield* prepareValue(\n snapshotOAuthSync(OAuthLinkClaimDecision, value as never),\n prepare,\n );\n }),\n ),\n settle: (input, prepare) =>\n Effect.gen(function* () {\n yield* execute.admit;\n const allocated = resources ?? (yield* accountResources(mapping));\n\n return yield* execute.run(\n Effect.gen(function* () {\n const value = yield* settleLink(mapping, input, allocated as never);\n\n return yield* prepareValue(snapshotOAuthSync(OAuthLinkDecision, value), prepare);\n }),\n );\n }).pipe(\n Effect.mapError(unavailable),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n ) as never,\n inspectUnlink: (input) =>\n execute.run(\n Effect.map(inspectUnlink(mapping, input), (value) =>\n snapshotOAuthSync(OAuthUnlinkInspection, value),\n ),\n false,\n ),\n unlink: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* unlink(mapping, input);\n\n return yield* prepareValue(snapshotOAuthSync(OAuthUnlinkDecision, value), prepare);\n }),\n ),\n cleanup: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const owner = yield* CurrentOAuthTransaction;\n const value = yield* cleanupFlows(mapping, input, \"link\");\n const remaining = input.limit - value.terminalized - value.removed;\n\n const now = yield* owner.now(mapping.clock),\n r = mapping.command;\n\n let removed = 0;\n\n if (remaining > 0) {\n const rows = yield* owner.read(\n r.table,\n both(\n eq(col(r.table, r.moduleId), input.moduleId),\n sql`${col(r.table, r.retentionUntil)} < ${mapping.clock.encodeInstant(now)}`,\n ),\n { limit: remaining, observe: false, takeOnly: true },\n );\n\n for (const row of rows.rows) {\n const key = { [r.moduleId]: input.moduleId, [r.commandId]: row[r.commandId] };\n const selected = yield* owner.read(r.table, equal(r.table, key), { limit: 1 });\n const current = selected.rows[0];\n\n if (current === undefined) continue;\n const horizon = mapping.clock.decodeInstant(current[r.retentionUntil]);\n\n if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock)))\n continue;\n yield* owner.remove(r.table, key);\n owner.postconditions.push(sql`${mapping.clock.engineNowMillis} > ${horizon}`);\n removed++;\n }\n }\n\n return yield* prepareValue(\n {\n ...value,\n removed: value.removed + removed,\n hasMore: value.hasMore || remaining === removed,\n },\n prepare,\n );\n }),\n ),\n },\n accountsInputs,\n execute.active,\n execute.poison,\n );\n\nexport const makeTargetOAuthAccountsServices = (\n mapping: any,\n configuration: OAuthTargetConfiguration,\n) => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.map(makeOAuthExecution(configuration, captured), (execution) => ({\n oauthAccountsPersistence: makeOAuthAccounts(captured, execution),\n }));\n};\n\nexport const oauthAccountsPersistenceLayer = <E, R>(\n services: Effect.Effect<Effect.Success<ReturnType<typeof makeTargetOAuthAccountsServices>>, E, R>,\n) =>\n Layer.effect(\n OAuthAccountsPersistence,\n Effect.map(services, (value) => value.oauthAccountsPersistence),\n );\n\nexport const oauthSignInPersistenceLayer = <E, R>(\n services: Effect.Effect<Effect.Success<ReturnType<typeof makeTargetOAuthSignInServices>>, E, R>,\n) =>\n Layer.effect(\n OAuthSignInPersistence,\n Effect.map(services, (value) => value.oauthSignInPersistence),\n );\n\nexport const oauthRegistrationIntentsLayer = <E, R>(\n services: Effect.Effect<\n Effect.Success<ReturnType<typeof makeTargetOAuthRegistrationIntentServices>>,\n E,\n R\n >,\n) =>\n Layer.effect(\n OAuthRegistrationIntents,\n Effect.map(services, (value) => value.oauthRegistrationIntents),\n );\n\nexport const oauthRegistrationAuthorityLayer = <Id, Registration, E, R>(\n tag: Context.Key<Id, OAuthRegistrationAuthority<Registration>>,\n services: Effect.Effect<\n { readonly registrationAuthority: OAuthRegistrationAuthority<Registration> },\n E,\n R\n >,\n) =>\n Layer.effect(\n tag,\n Effect.map(services, (value) => value.registrationAuthority),\n );\n"],"mappings":";;;;;;;;;;;;;;AAsFA,MAAa,iCACX,YACG,oCAAoC,aAAa,OAAO;AAE7D,MAAa,qBAAqB,OAAO,WAAW,WAClD,eACA,SAKA;CACA,MAAM,QAAQ,OAAO;CAErB,OAAO,uBAAuB,OAAO,CAAC,CAAC,KAAK,OAAO,SAAS,WAAW,CAAC;CAExE,MAAM,YAAY,OAAO,yBACvB,yBACA,eACA,aACA,KACF;CAEA,OAAO;EACL,GAAG;EACH,MA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AgB,KAAK,SAAS;IAC5E;GACF;EACF;EAEA,OAAO,OAAO,aACZ;GACE,GAAG;GACH,SAAS,MAAM,UAAU;GACzB,SAAS,MAAM,WAAW,cAAc;EAC1C,GACA,OACF;CACF,CAAC,CACH;AACJ,GACA,gBACA,QAAQ,QACR,QAAQ,MACV;AAEF,MAAa,mCACX,SACA,kBACG;CACH,MAAM,WAAW,oBAAoB,OAAO;CAE5C,OAAO,OAAO,IAAI,mBAAmB,eAAe,QAAQ,IAAI,eAAe,EAC7E,0BAA0B,kBAAkB,UAAU,SAAS,EACjE,EAAE;AACJ;AAEA,MAAa,iCACX,aAEA,MAAM,OACJ,0BACA,OAAO,IAAI,WAAW,UAAU,MAAM,wBAAwB,CAChE;AAEF,MAAa,+BACX,aAEA,MAAM,OACJ,wBACA,OAAO,IAAI,WAAW,UAAU,MAAM,sBAAsB,CAC9D;AAEF,MAAa,iCACX,aAMA,MAAM,OACJ,0BACA,OAAO,IAAI,WAAW,UAAU,MAAM,wBAAwB,CAChE;AAEF,MAAa,mCACX,KACA,aAMA,MAAM,OACJ,KACA,OAAO,IAAI,WAAW,UAAU,MAAM,qBAAqB,CAC7D"}
|
|
1
|
+
{"version":3,"file":"oauth-target.mjs","names":[],"sources":["../../src/drizzle/oauth-target.ts"],"sourcesContent":["import type { OAuthKernel } from \"@yielded/auth-persistence/Adapter\";\n\nimport { oauthKernel } from \"./oauth-kernel\";\n\nexport const sqlClientOAuthStandaloneGuard: OAuthKernel[\"target\"][\"sqlClientOAuthStandaloneGuard\"] =\n oauthKernel.target.sqlClientOAuthStandaloneGuard;\n\nexport const makeTargetOAuthSignInServices: OAuthKernel[\"target\"][\"makeTargetOAuthSignInServices\"] =\n oauthKernel.target.makeTargetOAuthSignInServices;\n\nexport const makeTargetOAuthRegistrationIntentServices: OAuthKernel[\"target\"][\"makeTargetOAuthRegistrationIntentServices\"] =\n oauthKernel.target.makeTargetOAuthRegistrationIntentServices;\n\nexport const makeTargetOAuthRegistrationServices: OAuthKernel[\"target\"][\"makeTargetOAuthRegistrationServices\"] =\n oauthKernel.target.makeTargetOAuthRegistrationServices;\n\nexport const coordinateTargetOAuthRegistration: OAuthKernel[\"target\"][\"coordinateTargetOAuthRegistration\"] =\n oauthKernel.target.coordinateTargetOAuthRegistration;\n\nexport const coordinateTargetOAuthSignIn: OAuthKernel[\"target\"][\"coordinateTargetOAuthSignIn\"] =\n oauthKernel.target.coordinateTargetOAuthSignIn;\n\nexport const coordinateTargetOAuthRegistrationIntents: OAuthKernel[\"target\"][\"coordinateTargetOAuthRegistrationIntents\"] =\n oauthKernel.target.coordinateTargetOAuthRegistrationIntents;\n\nexport const coordinateTargetOAuthAccounts: OAuthKernel[\"target\"][\"coordinateTargetOAuthAccounts\"] =\n oauthKernel.target.coordinateTargetOAuthAccounts;\n\nexport const makeTargetOAuthAccountsServices: OAuthKernel[\"target\"][\"makeTargetOAuthAccountsServices\"] =\n oauthKernel.target.makeTargetOAuthAccountsServices;\n\nexport const oauthAccountsPersistenceLayer: OAuthKernel[\"target\"][\"oauthAccountsPersistenceLayer\"] =\n oauthKernel.target.oauthAccountsPersistenceLayer;\n\nexport const oauthSignInPersistenceLayer: OAuthKernel[\"target\"][\"oauthSignInPersistenceLayer\"] =\n oauthKernel.target.oauthSignInPersistenceLayer;\n\nexport const oauthRegistrationIntentsLayer: OAuthKernel[\"target\"][\"oauthRegistrationIntentsLayer\"] =\n oauthKernel.target.oauthRegistrationIntentsLayer;\n\nexport const oauthRegistrationAuthorityLayer: OAuthKernel[\"target\"][\"oauthRegistrationAuthorityLayer\"] =\n oauthKernel.target.oauthRegistrationAuthorityLayer;\n\nexport type {\n OAuthTargetConfiguration,\n OAuthCoordinatorError,\n OAuthExecution,\n} from \"@yielded/auth-persistence/Adapter\";\n"],"mappings":";;AAIA,MAAa,gCACX,YAAY,OAAO;AAErB,MAAa,gCACX,YAAY,OAAO;AAErB,MAAa,4CACX,YAAY,OAAO;AAErB,MAAa,sCACX,YAAY,OAAO;AAErB,MAAa,oCACX,YAAY,OAAO;AAErB,MAAa,8BACX,YAAY,OAAO;AAErB,MAAa,2CACX,YAAY,OAAO;AAErB,MAAa,gCACX,YAAY,OAAO;AAErB,MAAa,kCACX,YAAY,OAAO;AAErB,MAAa,gCACX,YAAY,OAAO;AAErB,MAAa,8BACX,YAAY,OAAO;AAErB,MAAa,gCACX,YAAY,OAAO;AAErB,MAAa,kCACX,YAAY,OAAO"}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { DrizzleTableModel } from "./table-model.mjs";
|
|
2
2
|
import * as Shared from "@yielded/auth-persistence/Adapter";
|
|
3
|
-
import {
|
|
3
|
+
import { PasswordConstraintClassifier, PasswordRegistrationConstraintClassifier, PasswordRegistrationIntent, PasswordRegistrationState, RequiredPasswordConstraints, RequiredPasswordRegistrationConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints } from "@yielded/auth-persistence/Adapter";
|
|
4
4
|
import { SQL, Table } from "drizzle-orm";
|
|
5
5
|
//#region src/drizzle/password-model.d.ts
|
|
6
6
|
export type PasswordSubjectTable<Subject extends Table, _NativeSubjectId> = Shared.PasswordSubjectTable<DrizzleTableModel<Subject>, _NativeSubjectId>;
|
|
7
7
|
export type PasswordIdentifierTable<Identifier extends Table, NativeSubjectId> = Shared.PasswordIdentifierTable<DrizzleTableModel<Identifier>, NativeSubjectId, SQL>;
|
|
8
8
|
export type PasswordAuthorityCredentialTable<Credential extends Table, NativeSubjectId> = Shared.PasswordAuthorityCredentialTable<DrizzleTableModel<Credential>, NativeSubjectId>;
|
|
9
9
|
export type PasswordCredentialTable<Subject extends Table, Identifier extends Table, Credential extends Table, NativeSubjectId> = Shared.PasswordCredentialTable<DrizzleTableModel<Subject>, DrizzleTableModel<Identifier>, DrizzleTableModel<Credential>, NativeSubjectId>;
|
|
10
|
-
export type PasswordAttemptTable<Attempt extends Table, NativeSubjectId> = Shared.PasswordAttemptTable<DrizzleTableModel<Attempt>, NativeSubjectId>;
|
|
11
|
-
export type PasswordRateScopeTable<RateScope extends Table> = Shared.PasswordRateScopeTable<DrizzleTableModel<RateScope>>;
|
|
12
|
-
export type PasswordChargeTable<Charge extends Table> = Shared.PasswordChargeTable<DrizzleTableModel<Charge>>;
|
|
13
10
|
export type PasswordCommandTable<Command extends Table> = Shared.PasswordCommandTable<DrizzleTableModel<Command>>;
|
|
14
11
|
export type PasswordD1Clock = Shared.PasswordD1Clock<SQL>;
|
|
15
|
-
export type PasswordPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table,
|
|
16
|
-
export type D1PasswordPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table,
|
|
12
|
+
export type PasswordPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Command extends Table, NativeSubjectId> = Shared.PasswordPersistenceMapping<DrizzleTableModel<Subject>, DrizzleTableModel<Identifier>, DrizzleTableModel<Credential>, DrizzleTableModel<AuthorityCredential>, DrizzleTableModel<Command>, NativeSubjectId, SQL>;
|
|
13
|
+
export type D1PasswordPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Command extends Table, NativeSubjectId> = Shared.D1PasswordPersistenceMapping<DrizzleTableModel<Subject>, DrizzleTableModel<Identifier>, DrizzleTableModel<Credential>, DrizzleTableModel<AuthorityCredential>, DrizzleTableModel<Command>, NativeSubjectId, SQL>;
|
|
17
14
|
export type PasswordRegistrationTable<Registration, Request extends Table, NativeSubjectId> = Shared.PasswordRegistrationTable<Registration, DrizzleTableModel<Request>, NativeSubjectId>;
|
|
18
15
|
export type PasswordRegistrationProvisioning<Registration, Subject extends Table, NativeSubjectId> = Shared.PasswordRegistrationProvisioning<Registration, DrizzleTableModel<Subject>, NativeSubjectId>;
|
|
19
16
|
export type PasswordRegistrationMapping<Registration, Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Request extends Table, NativeSubjectId> = Shared.PasswordRegistrationMapping<Registration, DrizzleTableModel<Subject>, DrizzleTableModel<Identifier>, DrizzleTableModel<Credential>, DrizzleTableModel<AuthorityCredential>, DrizzleTableModel<Request>, NativeSubjectId, SQL>;
|
|
20
|
-
export type AnyPasswordPersistenceMapping = PasswordPersistenceMapping<Table, Table, Table, Table, Table,
|
|
17
|
+
export type AnyPasswordPersistenceMapping = PasswordPersistenceMapping<Table, Table, Table, Table, Table, unknown>;
|
|
21
18
|
export type AnyPasswordRegistrationMapping<Registration = unknown> = PasswordRegistrationMapping<Registration, Table, Table, Table, Table, Table, unknown>;
|
|
22
19
|
//#endregion
|
|
23
|
-
export { type
|
|
20
|
+
export { type PasswordConstraintClassifier, type PasswordRegistrationConstraintClassifier, type PasswordRegistrationIntent, type PasswordRegistrationState, type RequiredPasswordConstraints, type RequiredPasswordRegistrationConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints };
|
|
24
21
|
//# sourceMappingURL=password-model.d.mts.map
|