Skip to content

Commit

Permalink
Simplify the client
Browse files Browse the repository at this point in the history
  • Loading branch information
markusahlstrand committed Aug 18, 2024
1 parent ae7ae19 commit 008068d
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 36 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.11

### Patch Changes

- [email protected]

## 0.0.10

### 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.10",
"version": "0.0.11",
"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.3

### Patch Changes

- Simplify client

## 0.11.2

### Patch 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.2",
"version": "0.11.3",
"files": [
"dist"
],
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-interfaces/src/adapters/Clients.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PartialClient } from "../types";
import { Client } from "../types";

export interface ClientsAdapter {
get: (id: string) => Promise<PartialClient | null>;
get: (id: string) => Promise<Client | null>;
}
11 changes: 5 additions & 6 deletions packages/adapter-interfaces/src/types/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ export const applicationInsertSchema = z.object({
});
export type ApplicationInsert = z.infer<typeof applicationInsertSchema>;

export const applicationSchema = z
.object({
created_at: z.string().transform((val) => (val === null ? "" : val)),
updated_at: z.string().transform((val) => (val === null ? "" : val)),
})
.extend(applicationInsertSchema.shape);
export const applicationSchema = z.object({
created_at: z.string().transform((val) => (val === null ? "" : val)),
updated_at: z.string().transform((val) => (val === null ? "" : val)),
...applicationInsertSchema.shape,
});

export type Application = z.infer<typeof applicationSchema>;
23 changes: 3 additions & 20 deletions packages/adapter-interfaces/src/types/Client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from "@hono/zod-openapi";
import { connectionSchema } from "./Connection";
import { applicationSchema } from "./Application";
import { tenantSchema } from "./Tenant";

const ClientDomainSchema = z.object({
domain: z.string(),
Expand All @@ -12,29 +13,11 @@ const ClientDomainSchema = z.object({
.optional(),
});

const BaseClientSchema = z.object({
const ClientSchema = z.object({
...applicationSchema.shape,
domains: z.array(ClientDomainSchema),
tenant: z.object({
name: z.string(),
audience: z.string().optional(),
logo: z.string().optional(),
primary_color: z.string().optional(),
secondary_color: z.string().optional(),
sender_email: z.string(),
sender_name: z.string(),
support_url: z.string().optional(),
language: z.string().length(2).optional(),
}),
});

export const ClientSchema = BaseClientSchema.extend({
tenant: tenantSchema,
connections: z.array(connectionSchema),
});

export const PartialClientSchema = BaseClientSchema.extend({
connections: z.array(connectionSchema.partial()),
});

export type Client = z.infer<typeof ClientSchema>;
export type PartialClient = z.infer<typeof PartialClientSchema>;
4 changes: 3 additions & 1 deletion packages/adapter-interfaces/src/types/Tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export const tenantInsertSchema = z.object({
language: z.string().optional(),
});

export const tenantSchema = tenantInsertSchema.extend({
export const tenantSchema = z.object({
created_at: z.string().transform((val) => (val === null ? "" : val)),
updated_at: z.string().transform((val) => (val === null ? "" : val)),
id: z.string(),
...tenantInsertSchema.shape,
});

export interface Tenant {
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.13

### Patch Changes

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

## 0.2.12

### 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.12",
"version": "0.2.13",
"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.29

### Patch Changes

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

## 0.1.28

### 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.28",
"version": "0.1.29",
"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.5

### Patch Changes

- Simplify client
- Updated dependencies
- @authhero/adapter-interfaces@0.11.3

## 0.7.4

### 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.7.4",
"version": "0.7.5",
"files": [
"dist"
],
Expand Down
4 changes: 2 additions & 2 deletions packages/kysely/src/clients/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Kysely } from "kysely";
import { HTTPException } from "hono/http-exception";
import { removeNullProperties } from "../helpers/remove-nulls";
import { PartialClient, connectionSchema } from "@authhero/adapter-interfaces";
import { Client, connectionSchema } from "@authhero/adapter-interfaces";
import { Database } from "../db";

export function createClientsAdapter(db: Kysely<Database>) {
Expand Down Expand Up @@ -39,7 +39,7 @@ export function createClientsAdapter(db: Kysely<Database>) {
.selectAll()
.execute();

const client: PartialClient = {
const client: Client = {
...application,
connections: connections.map((connection) =>
connectionSchema.parse(removeNullProperties(connection)),
Expand Down

0 comments on commit 008068d

Please sign in to comment.