jackson/pages/api/admin/directory-sync/[directoryId]/groups/index.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

import type { NextApiRequest, NextApiResponse } from 'next';
import jackson from '@lib/jackson';
import { defaultHandler } from '@lib/api';
import { ApiError } from '@lib/error';
import { parsePaginateApiParams } from '@lib/utils';
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
await defaultHandler(req, res, {
GET: handleGET,
});
};
// Get all groups for a directory
const handleGET = async (req: NextApiRequest, res: NextApiResponse) => {
const { directorySyncController } = await jackson();
const { directoryId } = req.query as { directoryId: string };
const { pageOffset, pageLimit, pageToken } = parsePaginateApiParams(req.query);
const { data: directory, error } = await directorySyncController.directories.get(directoryId);
if (error) {
throw new ApiError(error.message, error.code);
}
const result = await directorySyncController.groups
Google Directory API Integration (#1158) * Add Google Group API * Restructure the Group interface * Rename the methods * wip * temp change * Revert the changes * Fix the groups from Google * wip fetch users * Skip directory check * Convert to SCIM schema * Updates to users sync * Fix the unit test * Rename folder and merge the files * add raw to the user payload * Fix the unit tests * Optimize the Group sync create ops * Reorder import * Remove unused imports * Add type safety to SCIM Schema * Fix the users and groups update * try fixing unit tests * Fix the file extension * Delete groups that are not in the directory anymore * Fix the group update * Compare and find the delete users * Add and update group members * cleanup the test * Fix the test (temp) * dont throw error * Add secondary index if the directory type is `google` * Rename the file * wip * Export functions inline * Hide the SCIM endpoint and token for non-scim provider * Update the `dsync` option key to allow multiple providers * Restructure the folders * Update folder structure * Cleanup * Revert the callback changes * Fix the type * Fix the type * Fix existing unit tests * add callback * Fix the internal callback * Fix the method call * merge the type files * add console.info for testing * Fix the Google OAuth client usage * Reactor the update method * Handle no users or group cases * Refactor the sync method * Fix the pagination * Cleanup * Finish the pagination * Fix the unit tests * Fix the lint errors * Fix the build issues * Pass directory id to the method * Pass directoryId while fetching * apply changes to the UI * display the Google auth URL * Fix the type * add unit tests * add unit test for syncing users * add unit tests * Pass operation to SCIM payload * unit tests wip 1 * updated * Test the events deleted * Test group.user_added events * Finish the tests * Revert and cleanup * update map.js * Revert * update the e2e test * Cleanup * Revert * label tweak * Remove unused import * Protect the cron job using apiKey --------- Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2023-06-15 13:31:38 +00:00
.setTenantAndProduct(directory.tenant, directory.product)
.getAll({ pageOffset, pageLimit, pageToken, directoryId });
if (result.error) {
throw new ApiError(result.error.message, result.error.code);
} else if (result.pageToken) {
res.setHeader('jackson-pagetoken', result.pageToken);
}
res.json({ data: result.data });
};
export default handler;