authhero 0.2.3 → 0.2.5
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/dist/authhero.cjs +1 -1
- package/dist/authhero.d.ts +2684 -0
- package/dist/authhero.iife.js +1 -1
- package/dist/authhero.mjs +694 -655
- package/package.json +8 -4
- package/CHANGELOG.md +0 -34
- package/src/hooks/index.ts +0 -29
- package/src/hooks/link-users.ts +0 -31
- package/src/hooks/webhooks.ts +0 -77
- package/src/index.ts +0 -41
- package/src/management-app.ts +0 -55
- package/src/middlewares/register-component.ts +0 -36
- package/src/routes/management-api/tenants.ts +0 -224
- package/src/routes/oauth2/index.ts +0 -1
- package/src/routes/oauth2/well-known.ts +0 -178
- package/src/types/Bindings.ts +0 -12
- package/src/types/Query.ts +0 -42
- package/src/types/Variables.ts +0 -3
- package/src/types/index.ts +0 -3
- package/src/utils/parse-sort.ts +0 -18
- package/src/utils/users.ts +0 -130
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -11
- package/tsconfig.node.json +0 -4
- package/vite.config.ts +0 -41
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "authhero",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist"
|
|
6
|
+
],
|
|
4
7
|
"main": "dist/authhero.cjs",
|
|
5
|
-
"types": "dist/authhero.d.ts",
|
|
6
8
|
"module": "dist/authhero.mjs",
|
|
9
|
+
"types": "dist/authhero.d.ts",
|
|
7
10
|
"exports": {
|
|
8
11
|
".": {
|
|
9
12
|
"require": "./dist/authhero.cjs",
|
|
@@ -13,6 +16,7 @@
|
|
|
13
16
|
},
|
|
14
17
|
"devDependencies": {
|
|
15
18
|
"@types/node": "^20.14.9",
|
|
19
|
+
"dts-bundle-generator": "^9.5.1",
|
|
16
20
|
"typescript": "^5.5.2",
|
|
17
21
|
"vite": "^5.3.2",
|
|
18
22
|
"vite-plugin-dts": "^3.9.1"
|
|
@@ -20,11 +24,11 @@
|
|
|
20
24
|
"dependencies": {
|
|
21
25
|
"@hono/zod-openapi": "^0.14.5",
|
|
22
26
|
"hono": "^4.4.10",
|
|
23
|
-
"@authhero/adapter-interfaces": "^0.
|
|
27
|
+
"@authhero/adapter-interfaces": "^0.10.1"
|
|
24
28
|
},
|
|
25
29
|
"scripts": {
|
|
26
30
|
"dev": "bun --watch src/bun.ts",
|
|
27
|
-
"build": "vite build",
|
|
31
|
+
"build": "tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
|
|
28
32
|
"start": "pnpm build && node dist/index.js"
|
|
29
33
|
}
|
|
30
34
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# authhero
|
|
2
|
-
|
|
3
|
-
## 0.2.3
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies
|
|
8
|
-
- @authhero/adapter-interfaces@0.9.2
|
|
9
|
-
|
|
10
|
-
## 0.2.2
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- Centralized all codes to the codes table and added a new logins table for the login sessions. The old tables will be removed in the next update
|
|
15
|
-
- Updated dependencies
|
|
16
|
-
- @authhero/adapter-interfaces@0.9.1
|
|
17
|
-
|
|
18
|
-
## 0.2.1
|
|
19
|
-
|
|
20
|
-
### Patch Changes
|
|
21
|
-
|
|
22
|
-
- Updated the package to reference to correct folder
|
|
23
|
-
|
|
24
|
-
## 0.2.0
|
|
25
|
-
|
|
26
|
-
### Minor Changes
|
|
27
|
-
|
|
28
|
-
- Update the package to support both esm and cjs
|
|
29
|
-
|
|
30
|
-
## 0.1.0
|
|
31
|
-
|
|
32
|
-
### Minor Changes
|
|
33
|
-
|
|
34
|
-
- a1212dc: Added a jwks route with mock data
|
package/src/hooks/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { DataAdapters, User } from "@authhero/adapter-interfaces";
|
|
2
|
-
import { linkUsersHook } from "./link-users";
|
|
3
|
-
import { postUserRegistrationWebhook } from "./webhooks";
|
|
4
|
-
import { Context } from "hono";
|
|
5
|
-
import { Bindings, Variables } from "../types";
|
|
6
|
-
|
|
7
|
-
function createUserHooks(
|
|
8
|
-
ctx: Context<{ Bindings: Bindings; Variables: Variables }>,
|
|
9
|
-
data: DataAdapters,
|
|
10
|
-
) {
|
|
11
|
-
return async (tenant_id: string, user: User) => {
|
|
12
|
-
// Check for existing user with the same email and if so link the users
|
|
13
|
-
let result = await linkUsersHook(data)(tenant_id, user);
|
|
14
|
-
// Invoke post-user-registration webhooks
|
|
15
|
-
await postUserRegistrationWebhook(ctx, data)(tenant_id, result);
|
|
16
|
-
|
|
17
|
-
return result;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function addDataHooks(
|
|
22
|
-
ctx: Context<{ Bindings: Bindings; Variables: Variables }>,
|
|
23
|
-
data: DataAdapters,
|
|
24
|
-
): DataAdapters {
|
|
25
|
-
return {
|
|
26
|
-
...data,
|
|
27
|
-
users: { ...data.users, create: createUserHooks(ctx, data) },
|
|
28
|
-
};
|
|
29
|
-
}
|
package/src/hooks/link-users.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { DataAdapters, User } from "@authhero/adapter-interfaces";
|
|
2
|
-
import { getPrimaryUserByEmail } from "../utils/users";
|
|
3
|
-
|
|
4
|
-
export function linkUsersHook(data: DataAdapters) {
|
|
5
|
-
return async (tenant_id: string, user: User): Promise<User> => {
|
|
6
|
-
// If the user does not have an email or the email is not verified, return the user
|
|
7
|
-
if (!user.email || !user.email_verified) {
|
|
8
|
-
return data.users.create(tenant_id, user);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Search for a user with the same email
|
|
12
|
-
const primaryUser = await getPrimaryUserByEmail({
|
|
13
|
-
userAdapter: data.users,
|
|
14
|
-
tenant_id,
|
|
15
|
-
email: user.email,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// If no user with the same email exists, return the user
|
|
19
|
-
if (!primaryUser) {
|
|
20
|
-
return data.users.create(tenant_id, user);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
await data.users.create(tenant_id, {
|
|
24
|
-
...user,
|
|
25
|
-
linked_to: primaryUser.user_id,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// TODO: add the new user to the identities
|
|
29
|
-
return primaryUser;
|
|
30
|
-
};
|
|
31
|
-
}
|
package/src/hooks/webhooks.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DataAdapters,
|
|
3
|
-
Hook,
|
|
4
|
-
LogTypes,
|
|
5
|
-
User,
|
|
6
|
-
} from "@authhero/adapter-interfaces";
|
|
7
|
-
// import { createLogMessage } from "../utils/create-log-message";
|
|
8
|
-
import { Context } from "hono";
|
|
9
|
-
import { Variables, Bindings } from "../types";
|
|
10
|
-
|
|
11
|
-
async function invokeHooks(
|
|
12
|
-
ctx: Context<{ Bindings: Bindings; Variables: Variables }>,
|
|
13
|
-
hooks: Hook[],
|
|
14
|
-
data: any,
|
|
15
|
-
) {
|
|
16
|
-
for await (const hook of hooks) {
|
|
17
|
-
const response = await fetch(hook.url, {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers: {
|
|
20
|
-
"Content-Type": "application/json",
|
|
21
|
-
},
|
|
22
|
-
body: JSON.stringify(data),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
if (!response.ok) {
|
|
26
|
-
// const log = createLogMessage(ctx, {
|
|
27
|
-
// type: LogTypes.FAILED_LOGIN_INCORRECT_PASSWORD,
|
|
28
|
-
// description: "Invalid password",
|
|
29
|
-
// });
|
|
30
|
-
// await data.logs.create(ctx.var.tenant_id, log);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function postUserRegistrationWebhook(
|
|
36
|
-
ctx: Context<{ Bindings: Bindings; Variables: Variables }>,
|
|
37
|
-
data: DataAdapters,
|
|
38
|
-
) {
|
|
39
|
-
return async (tenant_id: string, user: User): Promise<User> => {
|
|
40
|
-
const { hooks } = await data.hooks.list(tenant_id, {
|
|
41
|
-
q: "trigger_id:post-user-registration",
|
|
42
|
-
page: 0,
|
|
43
|
-
per_page: 100,
|
|
44
|
-
include_totals: false,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
await invokeHooks(ctx, hooks, {
|
|
48
|
-
tenant_id,
|
|
49
|
-
user,
|
|
50
|
-
trigger_id: "post-user-registration",
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return user;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function postUserLoginWebhook(
|
|
58
|
-
ctx: Context<{ Bindings: Bindings; Variables: Variables }>,
|
|
59
|
-
data: DataAdapters,
|
|
60
|
-
) {
|
|
61
|
-
return async (tenant_id: string, user: User): Promise<User> => {
|
|
62
|
-
const { hooks } = await data.hooks.list(tenant_id, {
|
|
63
|
-
q: "trigger_id:post-user-login",
|
|
64
|
-
page: 0,
|
|
65
|
-
per_page: 100,
|
|
66
|
-
include_totals: false,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
await invokeHooks(ctx, hooks, {
|
|
70
|
-
tenant_id,
|
|
71
|
-
user,
|
|
72
|
-
trigger_id: "post-user-login",
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return user;
|
|
76
|
-
};
|
|
77
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
-
import { Context } from "hono";
|
|
3
|
-
import { Bindings, Variables } from "./types";
|
|
4
|
-
import { wellKnownRoutes } from "./routes/oauth2";
|
|
5
|
-
import createManagementApi from "./management-app";
|
|
6
|
-
import { DataAdapters } from "@authhero/adapter-interfaces";
|
|
7
|
-
|
|
8
|
-
export interface AuthHeroConfig {
|
|
9
|
-
dataAdapter: DataAdapters;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function init(options: AuthHeroConfig) {
|
|
13
|
-
const rootApp = new OpenAPIHono<{ Bindings: Bindings }>();
|
|
14
|
-
|
|
15
|
-
rootApp.get("/", (ctx: Context) => {
|
|
16
|
-
return ctx.text("Hello, authhero!");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const managementApp = createManagementApi(options);
|
|
20
|
-
rootApp.route("/api/v2", managementApp);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The oauth routes
|
|
24
|
-
*/
|
|
25
|
-
const oauthApp = new OpenAPIHono<{
|
|
26
|
-
Bindings: Bindings;
|
|
27
|
-
Variables: Variables;
|
|
28
|
-
}>().route("/.well-known", wellKnownRoutes);
|
|
29
|
-
|
|
30
|
-
oauthApp.doc("/spec", {
|
|
31
|
-
openapi: "3.0.0",
|
|
32
|
-
info: {
|
|
33
|
-
version: "1.0.0",
|
|
34
|
-
title: "Oauth endpoints",
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
rootApp.route("/", oauthApp);
|
|
39
|
-
|
|
40
|
-
return rootApp;
|
|
41
|
-
}
|
package/src/management-app.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
-
import { Bindings, Variables } from "./types";
|
|
3
|
-
import { addDataHooks } from "./hooks";
|
|
4
|
-
// import { brandingRoutes } from "./routes/management-api/branding";
|
|
5
|
-
// import { domainRoutes } from "./routes/management-api/domains";
|
|
6
|
-
// import { userRoutes } from "./routes/management-api/users";
|
|
7
|
-
// import { keyRoutes } from "./routes/management-api/keys";
|
|
8
|
-
// import { usersByEmailRoutes } from "./routes/management-api/users-by-email";
|
|
9
|
-
// import { applicationRoutes } from "./routes/management-api/applications";
|
|
10
|
-
import { tenantRoutes } from "./routes/management-api/tenants";
|
|
11
|
-
// import { logRoutes } from "./routes/management-api/logs";
|
|
12
|
-
// import { hooksRoutes } from "./routes/management-api/hooks";
|
|
13
|
-
// import { connectionRoutes } from "./routes/management-api/connections";
|
|
14
|
-
import { registerComponent } from "./middlewares/register-component";
|
|
15
|
-
import { DataAdapters } from "@authhero/adapter-interfaces";
|
|
16
|
-
|
|
17
|
-
export interface CreateAuthParams {
|
|
18
|
-
dataAdapter: DataAdapters;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default function create(params: CreateAuthParams) {
|
|
22
|
-
const app = new OpenAPIHono<{
|
|
23
|
-
Bindings: Bindings;
|
|
24
|
-
Variables: Variables;
|
|
25
|
-
}>();
|
|
26
|
-
|
|
27
|
-
app.use(async (ctx, next) => {
|
|
28
|
-
ctx.env.data = addDataHooks(ctx, params.dataAdapter);
|
|
29
|
-
return next();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const managementApp = app
|
|
33
|
-
// .route("/api/v2/branding", brandingRoutes)
|
|
34
|
-
// .route("/api/v2/domains", domainRoutes)
|
|
35
|
-
// .route("/api/v2/users", userRoutes)
|
|
36
|
-
// .route("/api/v2/keys/signing", keyRoutes)
|
|
37
|
-
// .route("/api/v2/users-by-email", usersByEmailRoutes)
|
|
38
|
-
// .route("/api/v2/applications", applicationRoutes)
|
|
39
|
-
.route("/api/v2/tenants", tenantRoutes);
|
|
40
|
-
// .route("/api/v2/logs", logRoutes)
|
|
41
|
-
// .route("/api/v2/hooks", hooksRoutes)
|
|
42
|
-
// .route("/api/v2/connections", connectionRoutes);
|
|
43
|
-
|
|
44
|
-
registerComponent(managementApp);
|
|
45
|
-
|
|
46
|
-
managementApp.doc("/api/v2/spec", {
|
|
47
|
-
openapi: "3.0.0",
|
|
48
|
-
info: {
|
|
49
|
-
version: "1.0.0",
|
|
50
|
-
title: "Management api",
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return managementApp;
|
|
55
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
-
import { Context, Next } from "hono";
|
|
3
|
-
import { Bindings, Variables } from "../types";
|
|
4
|
-
|
|
5
|
-
let inititated = false;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This registers the security scheme for the application. As it uses an environment variable, it can only be registered once the first request arrives.
|
|
9
|
-
* @param app
|
|
10
|
-
*/
|
|
11
|
-
export function registerComponent(
|
|
12
|
-
app: OpenAPIHono<{ Bindings: Bindings; Variables: Variables }>,
|
|
13
|
-
) {
|
|
14
|
-
app.use(async (ctx: Context<{ Bindings: Bindings }>, next: Next) => {
|
|
15
|
-
if (!inititated) {
|
|
16
|
-
app.openAPIRegistry.registerComponent("securitySchemes", "Bearer", {
|
|
17
|
-
type: "oauth2",
|
|
18
|
-
scheme: "bearer",
|
|
19
|
-
flows: {
|
|
20
|
-
implicit: {
|
|
21
|
-
authorizationUrl: `${ctx.env.AUTH_URL}/authorize`,
|
|
22
|
-
scopes: {
|
|
23
|
-
openid: "Basic user information",
|
|
24
|
-
email: "User email",
|
|
25
|
-
profile: "User profile information",
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
inititated = true;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return await next();
|
|
35
|
-
});
|
|
36
|
-
}
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
2
|
-
import { HTTPException } from "hono/http-exception";
|
|
3
|
-
import { Bindings } from "../../types";
|
|
4
|
-
import { querySchema } from "../../types";
|
|
5
|
-
import { parseSort } from "../../utils/parse-sort";
|
|
6
|
-
// import authenticationMiddleware from "../../middlewares/authentication";
|
|
7
|
-
import {
|
|
8
|
-
tenantInsertSchema,
|
|
9
|
-
tenantSchema,
|
|
10
|
-
totalsSchema,
|
|
11
|
-
} from "@authhero/adapter-interfaces";
|
|
12
|
-
|
|
13
|
-
const tenantsWithTotalsSchema = totalsSchema.extend({
|
|
14
|
-
tenants: z.array(tenantSchema),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export const tenantRoutes = new OpenAPIHono<{ Bindings: Bindings }>()
|
|
18
|
-
// --------------------------------
|
|
19
|
-
// GET /tenants
|
|
20
|
-
// --------------------------------
|
|
21
|
-
.openapi(
|
|
22
|
-
createRoute({
|
|
23
|
-
tags: ["tenants"],
|
|
24
|
-
method: "get",
|
|
25
|
-
path: "/",
|
|
26
|
-
request: {
|
|
27
|
-
query: querySchema,
|
|
28
|
-
},
|
|
29
|
-
// middleware: [authenticationMiddleware({ scopes: ["auth:read"] })],
|
|
30
|
-
security: [
|
|
31
|
-
{
|
|
32
|
-
Bearer: ["auth:read"],
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
responses: {
|
|
36
|
-
200: {
|
|
37
|
-
content: {
|
|
38
|
-
"tenant/json": {
|
|
39
|
-
schema: z.union([z.array(tenantSchema), tenantsWithTotalsSchema]),
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
description: "List of tenants",
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
}),
|
|
46
|
-
async (ctx) => {
|
|
47
|
-
const { page, per_page, include_totals, sort, q } =
|
|
48
|
-
ctx.req.valid("query");
|
|
49
|
-
|
|
50
|
-
const result = await ctx.env.data.tenants.list({
|
|
51
|
-
page,
|
|
52
|
-
per_page,
|
|
53
|
-
include_totals,
|
|
54
|
-
sort: parseSort(sort),
|
|
55
|
-
q,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (include_totals) {
|
|
59
|
-
return ctx.json(result);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return ctx.json(result.tenants);
|
|
63
|
-
},
|
|
64
|
-
)
|
|
65
|
-
// --------------------------------
|
|
66
|
-
// GET /tenants/:id
|
|
67
|
-
// --------------------------------
|
|
68
|
-
.openapi(
|
|
69
|
-
createRoute({
|
|
70
|
-
tags: ["tenants"],
|
|
71
|
-
method: "get",
|
|
72
|
-
path: "/{id}",
|
|
73
|
-
request: {
|
|
74
|
-
params: z.object({
|
|
75
|
-
id: z.string(),
|
|
76
|
-
}),
|
|
77
|
-
},
|
|
78
|
-
// middleware: [authenticationMiddleware({ scopes: ["auth:read"] })],
|
|
79
|
-
security: [
|
|
80
|
-
{
|
|
81
|
-
Bearer: ["auth:read"],
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
responses: {
|
|
85
|
-
200: {
|
|
86
|
-
content: {
|
|
87
|
-
"tenant/json": {
|
|
88
|
-
schema: tenantSchema,
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
description: "A tenant",
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
}),
|
|
95
|
-
async (ctx) => {
|
|
96
|
-
const { id } = ctx.req.valid("param");
|
|
97
|
-
|
|
98
|
-
const tenant = await ctx.env.data.tenants.get(id);
|
|
99
|
-
|
|
100
|
-
if (!tenant) {
|
|
101
|
-
throw new HTTPException(404);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
console.log("tenant", tenant);
|
|
105
|
-
|
|
106
|
-
return ctx.json(tenant);
|
|
107
|
-
},
|
|
108
|
-
)
|
|
109
|
-
// --------------------------------
|
|
110
|
-
// DELETE /tenants/:id
|
|
111
|
-
// --------------------------------
|
|
112
|
-
.openapi(
|
|
113
|
-
createRoute({
|
|
114
|
-
tags: ["tenants"],
|
|
115
|
-
method: "delete",
|
|
116
|
-
path: "/{id}",
|
|
117
|
-
request: {
|
|
118
|
-
params: z.object({
|
|
119
|
-
id: z.string(),
|
|
120
|
-
}),
|
|
121
|
-
},
|
|
122
|
-
// middleware: [authenticationMiddleware({ scopes: ["auth:write"] })],
|
|
123
|
-
security: [
|
|
124
|
-
{
|
|
125
|
-
Bearer: ["auth:write"],
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
responses: {
|
|
129
|
-
200: {
|
|
130
|
-
description: "Status",
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
}),
|
|
134
|
-
async (ctx) => {
|
|
135
|
-
const { id } = ctx.req.valid("param");
|
|
136
|
-
|
|
137
|
-
await ctx.env.data.tenants.remove(id);
|
|
138
|
-
|
|
139
|
-
return ctx.text("OK");
|
|
140
|
-
},
|
|
141
|
-
)
|
|
142
|
-
// --------------------------------
|
|
143
|
-
// PATCH /tenants/:id
|
|
144
|
-
// --------------------------------
|
|
145
|
-
.openapi(
|
|
146
|
-
createRoute({
|
|
147
|
-
tags: ["tenants"],
|
|
148
|
-
method: "patch",
|
|
149
|
-
path: "/{id}",
|
|
150
|
-
request: {
|
|
151
|
-
body: {
|
|
152
|
-
content: {
|
|
153
|
-
"application/json": {
|
|
154
|
-
schema: z.object(tenantInsertSchema.shape).partial(),
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
params: z.object({
|
|
159
|
-
id: z.string(),
|
|
160
|
-
}),
|
|
161
|
-
},
|
|
162
|
-
// middleware: [authenticationMiddleware({ scopes: ["auth:write"] })],
|
|
163
|
-
security: [
|
|
164
|
-
{
|
|
165
|
-
Bearer: ["auth:write"],
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
responses: {
|
|
169
|
-
200: {
|
|
170
|
-
description: "Status",
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
}),
|
|
174
|
-
async (ctx) => {
|
|
175
|
-
const { id } = ctx.req.valid("param");
|
|
176
|
-
const body = ctx.req.valid("json");
|
|
177
|
-
|
|
178
|
-
await ctx.env.data.tenants.update(id, body);
|
|
179
|
-
|
|
180
|
-
return ctx.text("OK");
|
|
181
|
-
},
|
|
182
|
-
)
|
|
183
|
-
// --------------------------------
|
|
184
|
-
// POST /tenants
|
|
185
|
-
// --------------------------------
|
|
186
|
-
.openapi(
|
|
187
|
-
createRoute({
|
|
188
|
-
tags: ["tenants"],
|
|
189
|
-
method: "post",
|
|
190
|
-
path: "/",
|
|
191
|
-
request: {
|
|
192
|
-
body: {
|
|
193
|
-
content: {
|
|
194
|
-
"application/json": {
|
|
195
|
-
schema: z.object(tenantInsertSchema.shape),
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
// middleware: [authenticationMiddleware({ scopes: ["auth:write"] })],
|
|
201
|
-
security: [
|
|
202
|
-
{
|
|
203
|
-
Bearer: ["auth:write"],
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
responses: {
|
|
207
|
-
200: {
|
|
208
|
-
content: {
|
|
209
|
-
"tenant/json": {
|
|
210
|
-
schema: tenantSchema,
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
description: "An tenant",
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
}),
|
|
217
|
-
async (ctx) => {
|
|
218
|
-
const body = ctx.req.valid("json");
|
|
219
|
-
|
|
220
|
-
const tenant = await ctx.env.data.tenants.create(body);
|
|
221
|
-
|
|
222
|
-
return ctx.json(tenant, { status: 201 });
|
|
223
|
-
},
|
|
224
|
-
);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./well-known";
|