Skip to content

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph committed Jan 2, 2025
1 parent 2f833cb commit b5dfd1c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
17 changes: 11 additions & 6 deletions front/lib/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
Result,
UserMetadataType,
UserType,
UserTypeWithExtensionWorkspaces,
UserTypeWithWorkspaces,
} from "@dust-tt/types";
import { Err, Ok } from "@dust-tt/types";
Expand Down Expand Up @@ -139,10 +140,12 @@ export async function fetchRevokedWorkspace(
return new Ok(workspace);
}

export async function getUserWithWorkspaces(
export async function getUserWithWorkspaces<T extends boolean>(
user: UserResource,
populateExtensionConfig = false
): Promise<UserTypeWithWorkspaces> {
populateExtensionConfig: T = false as T
): Promise<
T extends true ? UserTypeWithExtensionWorkspaces : UserTypeWithWorkspaces
> {
const { memberships } = await MembershipResource.getActiveMemberships({
users: [user],
});
Expand Down Expand Up @@ -170,9 +173,11 @@ export async function getUserWithWorkspaces(
segmentation: w.segmentation || null,
whiteListedProviders: w.whiteListedProviders,
defaultEmbeddingProvider: w.defaultEmbeddingProvider,
extensionBlacklistedDomains:
configs.find((c) => c.workspaceId === w.id)?.blacklistedDomains ??
undefined,
...(populateExtensionConfig && {
blacklistedDomains:
configs.find((c) => c.workspaceId === w.id)?.blacklistedDomains ??
null,
}),
};
}),
};
Expand Down
11 changes: 9 additions & 2 deletions sdks/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,10 @@ export type LightWorkspaceType = z.infer<typeof LightWorkspaceSchema>;

const WorkspaceSchema = LightWorkspaceSchema.extend({
ssoEnforced: z.boolean().optional(),
extensionBlacklistedDomains: z.array(z.string()).optional(),
});

const ExtensionWorkspaceSchema = WorkspaceSchema.extend({
blacklistedDomains: z.array(z.string()).nullable(),
});

const UserProviderSchema = FlexibleEnumSchema<
Expand Down Expand Up @@ -2200,7 +2203,11 @@ export type FileUploadedRequestResponseType = z.infer<
>;

export const MeResponseSchema = z.object({
user: UserSchema.and(z.object({ workspaces: WorkspaceSchema.array() })),
user: UserSchema.and(
z.object({
workspaces: WorkspaceSchema.array().or(ExtensionWorkspaceSchema.array()),
})
),
});

export type MeResponseType = z.infer<typeof MeResponseSchema>;
Expand Down
9 changes: 8 additions & 1 deletion types/src/front/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export type LightWorkspaceType = {

export type WorkspaceType = LightWorkspaceType & {
ssoEnforced?: boolean;
extensionBlacklistedDomains?: string[];
};

export type ExtensionWorkspaceType = WorkspaceType & {
blacklistedDomains: string[] | null;
};

export type UserProviderType =
Expand Down Expand Up @@ -73,6 +76,10 @@ export type UserTypeWithWorkspaces = UserType & {
workspaces: WorkspaceType[];
};

export type UserTypeWithExtensionWorkspaces = UserType & {
workspaces: ExtensionWorkspaceType[];
};

export type UserMetadataType = {
key: string;
value: string;
Expand Down

0 comments on commit b5dfd1c

Please sign in to comment.