diff --git a/packages/kysely/CHANGELOG.md b/packages/kysely/CHANGELOG.md index 2c65ba8..f8dc155 100644 --- a/packages/kysely/CHANGELOG.md +++ b/packages/kysely/CHANGELOG.md @@ -1,5 +1,11 @@ # @authhero/kysely-adapter +## 0.9.6 + +### Patch Changes + +- Convert booleans to integers + ## 0.9.5 ### Patch Changes diff --git a/packages/kysely/package.json b/packages/kysely/package.json index 4a534e9..45f06aa 100644 --- a/packages/kysely/package.json +++ b/packages/kysely/package.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/markusahlstrand/authhero" }, - "version": "0.9.5", + "version": "0.9.6", "files": [ "dist" ], diff --git a/packages/kysely/src/connections/create.ts b/packages/kysely/src/connections/create.ts index e9ea6a5..08c950b 100644 --- a/packages/kysely/src/connections/create.ts +++ b/packages/kysely/src/connections/create.ts @@ -2,7 +2,7 @@ import { nanoid } from "nanoid"; import { Kysely } from "kysely"; import { Connection, ConnectionInsert } from "@authhero/adapter-interfaces"; import { Database } from "../db"; -import { flattenObject } from "../flatten"; +import { flattenObject } from "../utils/flatten"; export function create(db: Kysely) { return async ( diff --git a/packages/kysely/src/connections/get.ts b/packages/kysely/src/connections/get.ts index a820222..b1206ff 100644 --- a/packages/kysely/src/connections/get.ts +++ b/packages/kysely/src/connections/get.ts @@ -2,7 +2,7 @@ import { Kysely } from "kysely"; import { removeNullProperties } from "../helpers/remove-nulls"; import { Connection } from "@authhero/adapter-interfaces"; import { Database } from "../db"; -import { unflattenObject } from "../flatten"; +import { unflattenObject } from "../utils/flatten"; export function get(db: Kysely) { return async ( diff --git a/packages/kysely/src/connections/list.ts b/packages/kysely/src/connections/list.ts index 63ddae1..f3978ea 100644 --- a/packages/kysely/src/connections/list.ts +++ b/packages/kysely/src/connections/list.ts @@ -7,7 +7,7 @@ import { } from "@authhero/adapter-interfaces"; import { Database } from "../db"; import getCountAsInt from "../utils/getCountAsInt"; -import { unflattenObject } from "../flatten"; +import { unflattenObject } from "../utils/flatten"; export function list(db: Kysely) { return async ( diff --git a/packages/kysely/src/connections/update.ts b/packages/kysely/src/connections/update.ts index 796b142..94a9078 100644 --- a/packages/kysely/src/connections/update.ts +++ b/packages/kysely/src/connections/update.ts @@ -1,7 +1,7 @@ import { Kysely } from "kysely"; import { ConnectionInsert } from "@authhero/adapter-interfaces"; import { Database } from "../db"; -import { flattenObject } from "../flatten"; +import { flattenObject } from "../utils/flatten"; export function update(db: Kysely) { return async ( diff --git a/packages/kysely/src/db.ts b/packages/kysely/src/db.ts index 3c1c230..715135e 100644 --- a/packages/kysely/src/db.ts +++ b/packages/kysely/src/db.ts @@ -9,7 +9,7 @@ import { Hook, loginSchema, Password, - PromptSetting, + promptSettingSchema, Session, SigningKey, Tenant, @@ -17,7 +17,7 @@ import { } from "@authhero/adapter-interfaces"; import { SqlTicket } from "./tickets/Ticket"; import { SqlLog } from "./logs/Log"; -import { flattenSchema } from "./flatten"; +import { flattenSchema } from "./utils/flatten"; const sqlThemeSchema = flattenSchema(themeSchema).extend({ tenant_id: z.string(), @@ -47,6 +47,14 @@ const sqlApplicationSchema = z.object({ allowed_logout_urls: z.string(), }); +const sqlPromptSettingSchema = z.object({ + ...promptSettingSchema.shape, + identifier_first: z.number(), + password_first: z.number(), + webauthn_platform_first_factor: z.number(), + tenant_id: z.string(), +}); + export interface Database { applications: z.infer; branding: SqlBranding; @@ -58,7 +66,7 @@ export interface Database { logins: SqlLogin; logs: SqlLog; passwords: Password & { tenant_id: string }; - prompt_settings: PromptSetting & { tenant_id: string }; + prompt_settings: z.infer; users: SqlUser; sessions: Session & { tenant_id: string }; tenants: Tenant; diff --git a/packages/kysely/src/logins/create.ts b/packages/kysely/src/logins/create.ts index f25afcd..6546ee3 100644 --- a/packages/kysely/src/logins/create.ts +++ b/packages/kysely/src/logins/create.ts @@ -2,7 +2,7 @@ import { Login, LoginInsert } from "@authhero/adapter-interfaces"; import { Kysely } from "kysely"; import { nanoid } from "nanoid"; import { Database } from "../db"; -import { flattenObject } from "../flatten"; +import { flattenObject } from "../utils/flatten"; export function create(db: Kysely) { return async (tenant_id: string, login: LoginInsert) => { diff --git a/packages/kysely/src/logins/get.ts b/packages/kysely/src/logins/get.ts index 0935eaa..8065daa 100644 --- a/packages/kysely/src/logins/get.ts +++ b/packages/kysely/src/logins/get.ts @@ -1,7 +1,7 @@ import { Kysely } from "kysely"; import { Login, loginSchema } from "@authhero/adapter-interfaces"; import { Database } from "../db"; -import { unflattenObject } from "../flatten"; +import { unflattenObject } from "../utils/flatten"; import { removeNullProperties } from "../helpers/remove-nulls"; export function get(db: Kysely) { diff --git a/packages/kysely/src/logins/update.ts b/packages/kysely/src/logins/update.ts index 1fd317e..885cd4b 100644 --- a/packages/kysely/src/logins/update.ts +++ b/packages/kysely/src/logins/update.ts @@ -1,7 +1,7 @@ import { LoginInsert } from "@authhero/adapter-interfaces"; import { Kysely } from "kysely"; import { Database } from "../db"; -import { flattenObject } from "../flatten"; +import { flattenObject } from "../utils/flatten"; export function update(db: Kysely) { return async ( diff --git a/packages/kysely/src/promptSettings/set.ts b/packages/kysely/src/promptSettings/set.ts index 55d37fa..ab31efe 100644 --- a/packages/kysely/src/promptSettings/set.ts +++ b/packages/kysely/src/promptSettings/set.ts @@ -4,6 +4,23 @@ import { } from "@authhero/adapter-interfaces"; import { Kysely } from "kysely"; import { Database } from "../db"; +import { removeNullProperties } from "../helpers/remove-nulls"; + +function convertToBooleans(promptSetting: Partial) { + return removeNullProperties({ + ...promptSetting, + webauthn_platform_first_factor: promptSetting.webauthn_platform_first_factor + ? !!promptSetting.webauthn_platform_first_factor + : undefined, + identifier_first: promptSetting.identifier_first + ? !!promptSetting.identifier_first + : undefined, + password_first: promptSetting.password_first + ? !!promptSetting.password_first + : undefined, + universal_login_experience: promptSetting.universal_login_experience, + }); +} export function set(db: Kysely) { return async (tenant_id: string, promptSetting: Partial) => { @@ -13,14 +30,14 @@ export function set(db: Kysely) { await db .insertInto("prompt_settings") .values({ - ...promptSettingsWithDefaults, + ...convertToBooleans(promptSettingsWithDefaults), tenant_id, }) .execute(); } catch (error) { await db .updateTable("prompt_settings") - .set(promptSetting) + .set(convertToBooleans(promptSetting)) .where("tenant_id", "=", tenant_id) .execute(); } diff --git a/packages/kysely/src/themes/create.ts b/packages/kysely/src/themes/create.ts index 6d64022..2c22c7e 100644 --- a/packages/kysely/src/themes/create.ts +++ b/packages/kysely/src/themes/create.ts @@ -2,7 +2,7 @@ import { nanoid } from "nanoid"; import { Kysely } from "kysely"; import { Theme, ThemeInsert } from "@authhero/adapter-interfaces"; import { Database } from "../db"; -import { flattenObject } from "../flatten"; +import { flattenObject } from "../utils/flatten"; export function create(db: Kysely) { return async (tenant_id: string, theme: ThemeInsert): Promise => { diff --git a/packages/kysely/src/themes/update.ts b/packages/kysely/src/themes/update.ts index 2de707b..7041f00 100644 --- a/packages/kysely/src/themes/update.ts +++ b/packages/kysely/src/themes/update.ts @@ -1,7 +1,7 @@ import { Kysely } from "kysely"; import { ThemeInsert } from "@authhero/adapter-interfaces"; import { Database } from "../db"; -import { flattenObject } from "../flatten"; +import { flattenObject } from "../utils/flatten"; export function update(db: Kysely) { return async ( diff --git a/packages/kysely/src/flatten.ts b/packages/kysely/src/utils/flatten.ts similarity index 100% rename from packages/kysely/src/flatten.ts rename to packages/kysely/src/utils/flatten.ts