Skip to content

Commit

Permalink
Convert booleans to integeres for prompt settings
Browse files Browse the repository at this point in the history
  • Loading branch information
markusahlstrand committed Sep 3, 2024
1 parent 6d05ea7 commit 1539095
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 15 deletions.
6 changes: 6 additions & 0 deletions packages/kysely/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @authhero/kysely-adapter

## 0.9.6

### Patch Changes

- Convert booleans to integers

## 0.9.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/markusahlstrand/authhero"
},
"version": "0.9.5",
"version": "0.9.6",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/connections/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>) {
return async (
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/connections/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>) {
return async (
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/connections/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>) {
return async (
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/connections/update.ts
Original file line number Diff line number Diff line change
@@ -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<Database>) {
return async (
Expand Down
14 changes: 11 additions & 3 deletions packages/kysely/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
Hook,
loginSchema,
Password,
PromptSetting,
promptSettingSchema,
Session,
SigningKey,
Tenant,
themeSchema,
} 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(),
Expand Down Expand Up @@ -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<typeof sqlApplicationSchema>;
branding: SqlBranding;
Expand All @@ -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<typeof sqlPromptSettingSchema>;
users: SqlUser;
sessions: Session & { tenant_id: string };
tenants: Tenant;
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/logins/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>) {
return async (tenant_id: string, login: LoginInsert) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/logins/get.ts
Original file line number Diff line number Diff line change
@@ -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<Database>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/logins/update.ts
Original file line number Diff line number Diff line change
@@ -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<Database>) {
return async (
Expand Down
21 changes: 19 additions & 2 deletions packages/kysely/src/promptSettings/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PromptSetting>) {
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<Database>) {
return async (tenant_id: string, promptSetting: Partial<PromptSetting>) => {
Expand All @@ -13,14 +30,14 @@ export function set(db: Kysely<Database>) {
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();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/themes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>) {
return async (tenant_id: string, theme: ThemeInsert): Promise<Theme> => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/src/themes/update.ts
Original file line number Diff line number Diff line change
@@ -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<Database>) {
return async (
Expand Down
File renamed without changes.

0 comments on commit 1539095

Please sign in to comment.