Skip to content

Commit

Permalink
feat: Split console_session auth into `console_session_with_workspace…
Browse files Browse the repository at this point in the history
…` and `console_session_without_workspace` (#232)

Co-authored-by: Seam Bot <seambot@getseam.com>
  • Loading branch information
andrii-balitskyi and seambot authored Dec 17, 2024
1 parent 61462ed commit 8114d87
Show file tree
Hide file tree
Showing 73 changed files with 444 additions and 81 deletions.
14 changes: 12 additions & 2 deletions src/lib/middleware/with-route-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export const withRouteSpec = createWithRouteSpec({
scheme: "bearer",
bearerFormat: "API Token",
},
console_session: {
console_session_with_workspace: {
type: "http",
scheme: "bearer",
bearerFormat: "Console Session Token",
},
console_session_without_workspace: {
type: "http",
scheme: "bearer",
bearerFormat: "Console Session Token",
Expand All @@ -49,7 +54,12 @@ export const withRouteSpec = createWithRouteSpec({
access_token: withAccessToken({ is_workspace_id_required: true }),
pat_with_workspace: withAccessToken({ is_workspace_id_required: true }),
pat_without_workspace: withAccessToken({ is_workspace_id_required: false }),
console_session: withSessionAuth({ is_workspace_id_required: true }),
console_session_with_workspace: withSessionAuth({
is_workspace_id_required: true,
}),
console_session_without_workspace: withSessionAuth({
is_workspace_id_required: false,
}),
api_key: withApiKey,
client_session: withClientSession,
},
Expand Down
12 changes: 6 additions & 6 deletions src/lib/middleware/with-session-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const withSessionAuth =
AuthenticatedRequest["auth"],
{
type: RequiresWorkspaceId extends true
? "user_session"
: "user_session_without_workspace"
? "console_session_with_workspace"
: "console_session_without_workspace"
}
>
},
Expand Down Expand Up @@ -101,20 +101,20 @@ export const withSessionAuth =
;(req.auth as Extract<
AuthenticatedRequest["auth"],
{
type: "user_session"
type: "console_session_with_workspace"
}
>) = {
type: "user_session",
type: "console_session_with_workspace",
user_session_id: user_session.user_session_id,
workspace_id,
user_id,
}
} else {
;(req.auth as Extract<
AuthenticatedRequest["auth"],
{ type: "user_session_without_workspace" }
{ type: "console_session_without_workspace" }
>) = {
type: "user_session_without_workspace",
type: "console_session_without_workspace",
user_session_id: user_session.user_session_id,
user_id,
}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export const json_body = z.object({
})

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["POST"],
jsonBody: json_body
.refine((value) => {
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/create_multiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const json_body = z
)

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["POST"],
jsonBody: json_body,
jsonResponse: z.object({
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const json_body = z.object({
})

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["POST", "DELETE"],
jsonBody: json_body,
jsonResponse: z.object({
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/generate_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { z } from "zod"
import { withRouteSpec } from "lib/middleware/with-route-spec.ts"

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["GET", "POST"],
commonParams: z.object({
device_id: z.string(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export const commonParams = z
})

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["GET", "POST"],
commonParams,
jsonResponse: z.object({
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { access_code } from "lib/zod/index.ts"
import { withRouteSpec } from "lib/middleware/with-route-spec.ts"

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["GET", "POST"],
commonParams: z
.object({
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/pull_backup_access_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { access_code } from "lib/zod/index.ts"
import { withRouteSpec } from "lib/middleware/with-route-spec.ts"

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["POST"],
jsonBody: z.object({
access_code_id: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { access_code } from "lib/zod/index.ts"
import { withRouteSpec } from "lib/middleware/with-route-spec.ts"

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["POST"],
jsonBody: z.object({
device_id: z.string(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/unmanaged/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { access_code } from "lib/zod/index.ts"
import { withRouteSpec } from "lib/middleware/with-route-spec.ts"

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["GET", "POST"],
commonParams: z.object({
device_id: z.string(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/unmanaged/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { z } from "zod"
import { withRouteSpec } from "lib/middleware/with-route-spec.ts"

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["POST", "PATCH"],
commonParams: z.object({
access_code_id: z.string(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/access_codes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ const json_body = z
}, "Both starts_at and ends_at must be provided if one is")

export default withRouteSpec({
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
methods: ["POST"],
jsonBody: json_body,
jsonResponse: z.object({
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/entrances/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { cloneWithoutUnderscoreKeys } from "lib/util/clone-without-underscore-ke

export default withRouteSpec({
methods: ["GET", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
commonParams: z.object({
acs_entrance_id: z.string(),
}),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/entrances/grant_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { withRouteSpec } from "lib/middleware/index.ts"

export default withRouteSpec({
methods: ["POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
jsonBody: z.object({
acs_entrance_id: z.string(),
acs_user_id: z.string(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/entrances/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { cloneWithoutUnderscoreKeys } from "lib/util/clone-without-underscore-ke

export default withRouteSpec({
methods: ["GET", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
commonParams: z.object({
acs_system_id: z.string().optional(),
acs_credential_id: z.string().optional(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/systems/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { acs_system } from "lib/zod/index.ts"

export default withRouteSpec({
methods: ["GET", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
commonParams: z.object({
acs_system_id: z.string(),
}),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/systems/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { acs_system } from "lib/zod/index.ts"

export default withRouteSpec({
methods: ["GET", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
commonParams: z.object({
connected_account_id: z.string().optional(),
}),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/users/add_to_access_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { withRouteSpec } from "lib/middleware/index.ts"

export default withRouteSpec({
methods: ["PUT", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
jsonBody: z.object({
acs_user_id: z.string(),
acs_access_group_id: z.string(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/users/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { acs_user } from "lib/zod/index.ts"

export default withRouteSpec({
methods: ["POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
jsonBody: z
.object({
acs_system_id: z.string(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/users/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { withRouteSpec } from "lib/middleware/index.ts"

export default withRouteSpec({
methods: ["DELETE", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
commonParams: z.object({
acs_user_id: z.string(),
}),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/users/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { acs_user } from "lib/zod/index.ts"

export default withRouteSpec({
methods: ["GET", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
commonParams: z.object({
acs_user_id: z.string(),
}),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/users/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { acs_user, phone_number } from "lib/zod/index.ts"

export default withRouteSpec({
methods: ["GET", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
commonParams: z.object({
user_identity_id: z.string().optional(),
user_identity_phone_number: phone_number.optional(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/users/remove_from_access_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { withRouteSpec } from "lib/middleware/index.ts"

export default withRouteSpec({
methods: ["DELETE", "POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
jsonBody: z.object({
acs_user_id: z.string(),
acs_access_group_id: z.string(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/users/suspend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { withRouteSpec } from "lib/middleware/index.ts"

export default withRouteSpec({
methods: ["POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
jsonBody: z.object({
acs_user_id: z.string(),
}),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/api/acs/users/unsuspend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { withRouteSpec } from "lib/middleware/index.ts"

export default withRouteSpec({
methods: ["POST"],
auth: ["client_session", "pat_with_workspace", "console_session", "api_key"],
auth: [
"client_session",
"pat_with_workspace",
"console_session_with_workspace",
"api_key",
],
jsonBody: z.object({
acs_user_id: z.string(),
}),
Expand Down
Loading

0 comments on commit 8114d87

Please sign in to comment.