Line data Source code
1 : import { zErrorResponse } from '@comfyorg/ingest-types/zod'
2 :
3 : /**
4 : * ingest's 403 `code` for an account or workspace an SSO organization holds,
5 : * reached with a credential that is not an SSO sign-in. Every route answers
6 : * it, anonymous ones included.
7 : */
8 2356 : export const SSO_REQUIRED_SERVER_CODE = 'sso_required'
9 :
10 0 : export function isSsoRequiredRefusal(status: number, body: unknown): boolean {
11 0 : return (
12 : status === 403 &&
13 : zErrorResponse.safeParse(body).data?.code === SSO_REQUIRED_SERVER_CODE
14 : )
15 : }
16 :
17 : /**
18 : * The organization whose SSO the refusal asks for, when ingest names one. A
19 : * workspace accepts only its own organization's sign-in, so this outranks the
20 : * organization the email's domain would discover.
21 : */
22 0 : export function ssoRequiredOrganizationId(body: unknown): string | undefined {
23 0 : return zErrorResponse.safeParse(body).data?.organization_id || undefined
24 : }
25 :
26 : /**
27 : * ingest's 403 `code` for an account off the verified domains of the SSO
28 : * organization that holds the workspace: no sign-in admits it there.
29 : */
30 2356 : const ACCOUNT_OUTSIDE_ORGANIZATION_SERVER_CODE = 'account_outside_organization'
31 :
32 0 : export function isAccountOutsideOrganizationRefusal(
33 : status: number,
34 : body: unknown
35 : ): boolean {
36 0 : return (
37 : status === 403 &&
38 : zErrorResponse.safeParse(body).data?.code ===
39 : ACCOUNT_OUTSIDE_ORGANIZATION_SERVER_CODE
40 : )
41 : }
|