Skip to content

Commit

Permalink
🚨 Fix lint in packages/shared
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jul 27, 2024
1 parent 8262331 commit f93b1d0
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 46 deletions.
17 changes: 0 additions & 17 deletions apps/magic-link/src/hooks/queries/useLinkedUser.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion apps/magic-link/src/hooks/useOAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ type UseOAuthProps = {
returnUrl: string; // Return URL after OAuth flow
projectId: string; // Project ID
linkedUserId: string; // Linked User ID
redirectIngressUri: string | null; // URL of the User's Server
redirectIngressUri: {
status: boolean;
value: string | null;
} // URL of the User's Server
onSuccess: () => void;
};

Expand Down
17 changes: 13 additions & 4 deletions apps/magic-link/src/lib/ProviderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ const ProviderModal = () => {
const [openSuccessDialog,setOpenSuccessDialog] = useState<boolean>(false);
const [currentProviderLogoURL,setCurrentProviderLogoURL] = useState<string>('')
const [currentProvider,setCurrentProvider] = useState<string>('')
const [redirectIngressUri, setRedirectIngressUri] = useState<string | null>(null);
const [redirectIngressUri, setRedirectIngressUri] = useState<{
status: boolean;
value: string | null;
}>({
status: false,
value: null
});
const {mutate : createApiKeyConnection} = useCreateApiKeyConnection();
const {data: magicLink} = useUniqueMagicLink(uniqueMagicLinkId);
const {data: connectorsForProject} = useProjectConnectors(isProjectIdReady ? projectId : null);
Expand All @@ -88,9 +94,12 @@ const ProviderModal = () => {

useEffect(() => {
const queryParams = new URLSearchParams(window.location.search);
const redirectIngressUri = queryParams.get('redirectIngressUri');
if (redirectIngressUri) {
setRedirectIngressUri(redirectIngressUri);
const param = queryParams.get('redirectIngressUri');
if (param !== null && param !== undefined) {
setRedirectIngressUri({
status: true,
value: param
});
}
}, []);

Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/hooks/create/useCreateBatchLinkedUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ILinkedUserDto {
}
const useCreateBatchLinkedUser = () => {
const add = async (linkedUserData: ILinkedUserDto) => {
const response = await fetch(`${config.API_URL}/linked-users/batch`, {
const response = await fetch(`${config.API_URL}/linked-users/internal/batch`, {
method: 'POST',
body: JSON.stringify(linkedUserData),
headers: {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/hooks/create/useCreateLinkedUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ILinkedUserDto {
}
const useCreateLinkedUser = () => {
const add = async (linkedUserData: ILinkedUserDto) => {
const response = await fetch(`${config.API_URL}/linked-users`, {
const response = await fetch(`${config.API_URL}/linked-users/internal`, {
method: 'POST',
body: JSON.stringify(linkedUserData),
headers: {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/hooks/get/useLinkedUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const useLinkedUsers = () => {
return useQuery({
queryKey: ['linked-users'],
queryFn: async (): Promise<LinkedUser[]> => {
const response = await fetch(`${config.API_URL}/linked-users`,
const response = await fetch(`${config.API_URL}/linked-users/internal`,
{
method: 'GET',
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ export class CreateLinkedUserDto {
linked_user_origin_id: string;
@ApiProperty()
alias: string;
@ApiProperty()
id_project: string;
}

export class CreateBatchLinkedUserDto {
@ApiProperty()
linked_user_origin_ids: string[];
@ApiProperty()
alias: string;
@ApiProperty()
id_project: string;
}
106 changes: 97 additions & 9 deletions packages/api/src/@core/linked-users/linked-users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import {
} from './dto/create-linked-user.dto';
import {
ApiBody,
ApiExcludeEndpoint,
ApiOperation,
ApiQuery,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { JwtAuthGuard } from '@@core/auth/guards/jwt-auth.guard';
import { ApiKeyAuthGuard } from '@@core/auth/guards/api-key.guard';

@ApiTags('linkedUsers')
@Controller('linked-users')
Expand All @@ -35,10 +37,17 @@ export class LinkedUsersController {
@ApiOperation({ operationId: 'createLinkedUser', summary: 'Add Linked User' })
@ApiBody({ type: CreateLinkedUserDto })
@ApiResponse({ status: 201 })
@UseGuards(JwtAuthGuard)
@UseGuards(ApiKeyAuthGuard)
@Post()
addLinkedUser(@Body() linkedUserCreateDto: CreateLinkedUserDto) {
return this.linkedUsersService.addLinkedUser(linkedUserCreateDto);
addLinkedUser(
@Request() req: any,
@Body() linkedUserCreateDto: CreateLinkedUserDto,
) {
const projectId = req.user.id_project;
return this.linkedUsersService.addLinkedUser(
linkedUserCreateDto,
projectId,
);
}

@ApiOperation({
Expand All @@ -47,18 +56,22 @@ export class LinkedUsersController {
})
@ApiBody({ type: CreateBatchLinkedUserDto })
@ApiResponse({ status: 201 })
@UseGuards(JwtAuthGuard)
@UseGuards(ApiKeyAuthGuard)
@Post('batch')
addBatchLinkedUsers(@Body() data: CreateBatchLinkedUserDto) {
return this.linkedUsersService.addBatchLinkedUsers(data);
addBatchLinkedUsers(
@Request() req: any,
@Body() data: CreateBatchLinkedUserDto,
) {
const projectId = req.user.id_project;
return this.linkedUsersService.addBatchLinkedUsers(data, projectId);
}

@ApiOperation({
operationId: 'listLinkedUsers',
summary: 'Retrieve Linked Users',
})
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@UseGuards(ApiKeyAuthGuard)
@Get()
fetchLinkedUsers(@Request() req: any) {
const { id_project } = req.user;
Expand All @@ -71,7 +84,7 @@ export class LinkedUsersController {
})
@ApiQuery({ name: 'id', required: true, type: String })
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@UseGuards(ApiKeyAuthGuard)
@Get('single')
getLinkedUser(@Query('id') id: string) {
// validate project_id against user
Expand All @@ -84,10 +97,85 @@ export class LinkedUsersController {
})
@ApiQuery({ name: 'remoteId', required: true, type: String })
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@UseGuards(ApiKeyAuthGuard)
@Get('fromRemoteId')
linkedUserFromRemoteId(@Query('remoteId') id: string) {
// validate project_id against user
return this.linkedUsersService.getLinkedUserV2(id);
}

@ApiOperation({ operationId: 'createLinkedUser', summary: 'Add Linked User' })
@ApiBody({ type: CreateLinkedUserDto })
@ApiResponse({ status: 201 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Post('internal')
addLinkedUserInternal(
@Request() req: any,
@Body() linkedUserCreateDto: CreateLinkedUserDto,
) {
const { id_project } = req.user;
return this.linkedUsersService.addLinkedUser(
linkedUserCreateDto,
id_project,
);
}

@ApiOperation({
operationId: 'importBatch',
summary: 'Add Batch Linked Users',
})
@ApiBody({ type: CreateBatchLinkedUserDto })
@ApiResponse({ status: 201 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Post('internal/batch')
addBatchLinkedUsersInternal(
@Request() req: any,
@Body() data: CreateBatchLinkedUserDto,
) {
const { id_project } = req.user;
return this.linkedUsersService.addBatchLinkedUsers(data, id_project);
}

@ApiOperation({
operationId: 'listLinkedUsers',
summary: 'Retrieve Linked Users',
})
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@ApiExcludeEndpoint()
@Get('internal')
fetchLinkedUsersInternal(@Request() req: any) {
const { id_project } = req.user;
return this.linkedUsersService.getLinkedUsers(id_project);
}

@ApiOperation({
operationId: 'retrieveLinkedUser',
summary: 'Retrieve a Linked User',
})
@ApiQuery({ name: 'id', required: true, type: String })
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@ApiExcludeEndpoint()
@Get('internal/single')
getLinkedUserInternal(@Query('id') id: string) {
// validate project_id against user
return this.linkedUsersService.getLinkedUser(id);
}

@ApiOperation({
operationId: 'remoteId',
summary: 'Retrieve a Linked User From A Remote Id',
})
@ApiQuery({ name: 'remoteId', required: true, type: String })
@ApiResponse({ status: 200 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Get('internal/fromRemoteId')
linkedUserFromRemoteIdInternal(@Query('remoteId') id: string) {
// validate project_id against user
return this.linkedUsersService.getLinkedUserV2(id);
}
}
12 changes: 7 additions & 5 deletions packages/api/src/@core/linked-users/linked-users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ export class LinkedUsersService {
throw error;
}
}
async addLinkedUser(data: CreateLinkedUserDto) {
async addLinkedUser(data: CreateLinkedUserDto, id_project: string) {
try {
const { id_project, ...rest } = data;
const res = await this.prisma.linked_users.create({
data: {
...rest,
...data,
id_linked_user: uuidv4(),
id_project: id_project,
},
Expand All @@ -60,9 +59,12 @@ export class LinkedUsersService {
throw error;
}
}
async addBatchLinkedUsers(data: CreateBatchLinkedUserDto) {
async addBatchLinkedUsers(
data: CreateBatchLinkedUserDto,
id_project: string,
) {
try {
const { linked_user_origin_ids, alias, id_project } = data;
const { linked_user_origin_ids, alias } = data;

const linkedUsersData = linked_user_origin_ids.map((id) => ({
id_linked_user: uuidv4(), // Ensure each user gets a unique ID
Expand Down
7 changes: 5 additions & 2 deletions packages/shared/src/authUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ interface AuthParams {
returnUrl: string;
apiUrl: string;
vertical: string;
rediectUriIngress?: string | null;
rediectUriIngress?: {
status: boolean;
value: string | null;
};
}

// make sure to check wether its api_key or oauth2 to build the right auth
// make sure to check if client has own credentials to connect or panora managed ones
export const constructAuthUrl = async ({ projectId, linkedUserId, providerName, returnUrl, apiUrl, vertical, rediectUriIngress }: AuthParams) => {
const encodedRedirectUrl = encodeURIComponent(`${rediectUriIngress !== null && rediectUriIngress ? rediectUriIngress : apiUrl}/connections/oauth/callback`);
const encodedRedirectUrl = encodeURIComponent(`${rediectUriIngress && rediectUriIngress.status == true ? rediectUriIngress.value : apiUrl}/connections/oauth/callback`);
const state = encodeURIComponent(JSON.stringify({ projectId, linkedUserId, providerName, vertical, returnUrl }));
// console.log('State : ', JSON.stringify({ projectId, linkedUserId, providerName, vertical, returnUrl }));
// console.log('encodedRedirect URL : ', encodedRedirectUrl);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ export type VerticalConfig = {

export type ProvidersConfig = {
[vertical: string]: VerticalConfig;
}
}

0 comments on commit f93b1d0

Please sign in to comment.