Skip to content

Commit

Permalink
fix: update the application type
Browse files Browse the repository at this point in the history
  • Loading branch information
markusahlstrand committed Aug 17, 2024
1 parent 1fe78de commit 4c2f6bc
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 45 deletions.
6 changes: 6 additions & 0 deletions apps/demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @authhero/demo

## 0.0.9

### Patch Changes

- [email protected]

## 0.0.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@authhero/demo",
"private": true,
"version": "0.0.8",
"version": "0.0.9",
"scripts": {
"dev": "bun --watch src/bun.ts"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-interfaces/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @authhero/adapter-interfaces

## 0.11.1

### Patch Changes

- Update the application types

## 0.11.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-interfaces/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.11.0",
"version": "0.11.1",
"files": [
"dist"
],
Expand Down
19 changes: 2 additions & 17 deletions packages/adapter-interfaces/src/adapters/Applications.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
import { Application, Totals } from "../types";
import { Application, ApplicationInsert, Totals } from "../types";
import { ListParams } from "../types/ListParams";

export interface CreateApplicationParams {
name: string;
allowed_web_origins: string;
allowed_callback_urls: string;
allowed_logout_urls: string;
email_validation: "enabled" | "disabled" | "enforced";
client_secret: string;
id: string;
disable_sign_ups: boolean;
addons?: Record<string, Record<string, string | number>>;
}

export interface ApplicationsAdapter {
create(
tenant_id: string,
params: CreateApplicationParams,
): Promise<Application>;
create(tenant_id: string, params: ApplicationInsert): Promise<Application>;
get(tenant_id: string, id: string): Promise<Application | null>;
remove(tenant_id: string, id: string): Promise<boolean>;
list(
Expand Down
13 changes: 9 additions & 4 deletions packages/adapter-interfaces/src/types/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export const applicationInsertSchema = z.object({
description:
"Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.",
}),
allowed_logout_urls: z
.string()
.transform((val) => (val === null ? "" : val))
.default("")
.openapi({
description:
"Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains.",
}),
addons: z
.record(z.string(), z.record(z.string(), z.union([z.string(), z.number()])))
.optional()
Expand All @@ -43,10 +51,7 @@ export const applicationInsertSchema = z.object({
.string()
.transform((val) => (val === null ? "" : val))
.default(""),
allowed_logout_urls: z
.string()
.transform((val) => (val === null ? "" : val))
.default(""),

email_validation: z
.enum(["enabled", "disabled", "enforced"])
.default("enforced")
Expand Down
7 changes: 7 additions & 0 deletions packages/authhero/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# authhero

## 0.2.11

### Patch Changes

- Updated dependencies
- @authhero/adapter-interfaces@0.11.1

## 0.2.10

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/authhero/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "authhero",
"version": "0.2.10",
"version": "0.2.11",
"files": [
"dist"
],
Expand Down
7 changes: 7 additions & 0 deletions packages/drizzle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @authhero/drizzle

## 0.1.27

### Patch Changes

- Updated dependencies
- @authhero/adapter-interfaces@0.11.1

## 0.1.26

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle/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.1.26",
"version": "0.1.27",
"files": [
"dist"
],
Expand Down
8 changes: 8 additions & 0 deletions packages/kysely/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @authhero/kysely-adapter

## 0.7.1

### Patch Changes

- Update the application types
- Updated dependencies
- @authhero/adapter-interfaces@0.11.1

## 0.7.0

### Minor 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.7.0",
"version": "0.7.1",
"files": [
"dist"
],
Expand Down
30 changes: 21 additions & 9 deletions packages/kysely/src/applications/create.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import { Kysely } from "kysely";
import {
Application,
CreateApplicationParams,
} from "@authhero/adapter-interfaces";
import { Application, ApplicationInsert } from "@authhero/adapter-interfaces";
import { Database } from "../db";

export function create(db: Kysely<Database>) {
return async (
tenant_id: string,
params: CreateApplicationParams,
params: ApplicationInsert,
): Promise<Application> => {
const application: any = {
const application: Application = {
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
...params,
disable_sign_ups: params.disable_sign_ups ? 1 : 0,
addons: params.addons ? JSON.stringify(params.addons) : null,
// TODO: remove fallbacks
allowed_web_origins: params.allowed_origins,
allowed_callback_urls: params.callbacks,
allowed_origins: params.allowed_origins,
};

const allowed_origins = JSON.stringify(params.allowed_origins.split(","));
const allowed_callback_urls = JSON.stringify(params.callbacks.split(","));
const callbacks = JSON.stringify(params.callbacks.split(","));

await db
.insertInto("applications")
.values({ ...application, tenant_id })
.values({
...application,
tenant_id,
disable_sign_ups: params.disable_sign_ups ? 1 : 0,
addons: params.addons ? JSON.stringify(params.addons) : "{}",
callbacks,
allowed_web_origins: allowed_origins,
allowed_callback_urls,
allowed_origins,
})
.execute();

return application;
Expand Down
16 changes: 10 additions & 6 deletions packages/kysely/src/applications/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ export function get(db: Kysely<Database>) {
return null;
}

application.disable_sign_ups = !!application.disable_sign_ups;
application.addons = application.addons
? JSON.parse(application.addons)
: {};

return removeNullProperties(application);
return removeNullProperties({
...application,
disable_sign_ups: !!application.disable_sign_ups,
addons: JSON.parse(application.addons),
// TODO: add callbacks
callback: JSON.parse(application.callbacks),
allowed_origins: JSON.parse(application.allowed_origins),
allowed_callback_urls: JSON.parse(application.allowed_callback_urls),
allowed_web_origins: JSON.parse(application.allowed_web_origins),
});
};
}
18 changes: 16 additions & 2 deletions packages/kysely/src/applications/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,28 @@ export function update(db: Kysely<Database>) {
application_id: string,
application: Partial<ApplicationInsert>,
): Promise<boolean> => {
const sqlConnection = {
const sqlApplication = {
...application,
updated_at: new Date().toISOString(),
allowed_origins: application.allowed_origins
? JSON.stringify(application.allowed_origins)
: undefined,
allowed_callback_urls: application.allowed_callback_urls
? JSON.stringify(application.allowed_callback_urls)
: undefined,
allowed_web_origins: application.allowed_web_origins
? JSON.stringify(application.allowed_web_origins)
: undefined,
callbacks: application.callbacks
? JSON.stringify(application.callbacks)
: undefined,
addons: application.addons ? JSON.stringify(application.addons) : "{}",
disable_sign_ups: application.disable_sign_ups ? 1 : 0,
};

await db
.updateTable("applications")
.set(sqlConnection)
.set(sqlApplication)
.where("applications.id", "=", application_id)
.where("applications.tenant_id", "=", tenant_id)
.execute();
Expand Down
5 changes: 3 additions & 2 deletions packages/kysely/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { SqlBranding } from "./branding/Branding";
import { SqlAuthenticationCode } from "./authenticationCodes/AuthenticationCode";
import { SqlUser } from "./users/User";
import {
Application,
applicationSchema,
Certificate,
Code,
Expand Down Expand Up @@ -37,7 +36,9 @@ const sqlApplicationSchema = z.object({
...applicationSchema.shape,
tenant_id: z.string(),
// The addons will be stored as JSON in a text column
addons: z.string().optional(),
addons: z.string(),
disable_sign_ups: z.number(),
callbacks: z.string(),
});

export interface Database {
Expand Down

0 comments on commit 4c2f6bc

Please sign in to comment.