jackson/pages/api/v1/dsync/setuplinks/product.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

import type { NextApiRequest, NextApiResponse } from 'next';
import type { SetupLinkService } from '@boxyhq/saml-jackson';
import jackson from '@lib/jackson';
Pagination fixes (#2347) * `offset` -> `pageOffset`, `limit`-> `pageLimit` * Be backward compatible in API * Cleanup types and handle pagination qs * Cleanup unused code * Import type * Cleanup and fix lint error * Align params for sso-tracer * Move parsing to a common util function * pageLimit shouldn't be optional * Cap pageLimit to max value, split the boolean * Revert typings and assert non null * Refactor var name * Use util function to normalize pagination params across getAll and getByIndex * Normalize offset/limit for dynamo/mongo * Update query params in `FederatedSAMLApps` * Cap to max limit if passed limit is 0 * Sync lock file * Add a 3rd record and supply opts.pageLimit * Normalize offset/limit for mem/redis * Save the 3rd record in the store * Fix getAll tests * Give precedence to standard params over legacy * Use util function * Parse using util function * Refactor * Standardise pagination for `api/v1/dsync/events` * Standardise pagination for api/admin/connections * Standardise pagination for api/admin/directory-sync * Standardise pagination for `api/v1/dsync/groups` * Standardise pagination for `v1/dsync/users`, `v1/dsync/product` * Standardise pagination in fetchByProduct APIs * Update swagger for groups * Fix pagination params definition, add the params for users api * More swagger updates * Swagger spec update for dsync events * Add pagination params to apis fetching by product * Update qs in internal-ui * Remove type assertion * [Swagger WIP] Fix response format for paginated APIs * Add dsync events to swagger spec * Fix swagger spec for sso tracer * Fix swagger spec for federated-saml apps of a product * Update pageLimit to 50 * Use pageLimit value from internal-ui * Update UI SDK * Cleanup local pagination component * Update swagger version * Remove unused keys from locale * Fix tag for trace api spec * Fix param name for swagger * Fix swagger tag for trace * updated package-lock * updated package-lock --------- Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2024-03-06 20:14:14 +00:00
import { parsePaginateApiParams } from '@lib/utils';
const service: SetupLinkService = 'dsync';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
switch (req.method) {
case 'GET':
await handleGET(req, res);
break;
default:
res.setHeader('Allow', 'GET');
res.status(405).json({
error: { message: `Method ${req.method} Not Allowed` },
});
}
} catch (error: any) {
const { message, statusCode = 500 } = error;
res.status(statusCode).json({ error: { message } });
}
}
// Get the setup links filtered by the product
const handleGET = async (req: NextApiRequest, res: NextApiResponse) => {
const { setupLinkController } = await jackson();
Pagination fixes (#2347) * `offset` -> `pageOffset`, `limit`-> `pageLimit` * Be backward compatible in API * Cleanup types and handle pagination qs * Cleanup unused code * Import type * Cleanup and fix lint error * Align params for sso-tracer * Move parsing to a common util function * pageLimit shouldn't be optional * Cap pageLimit to max value, split the boolean * Revert typings and assert non null * Refactor var name * Use util function to normalize pagination params across getAll and getByIndex * Normalize offset/limit for dynamo/mongo * Update query params in `FederatedSAMLApps` * Cap to max limit if passed limit is 0 * Sync lock file * Add a 3rd record and supply opts.pageLimit * Normalize offset/limit for mem/redis * Save the 3rd record in the store * Fix getAll tests * Give precedence to standard params over legacy * Use util function * Parse using util function * Refactor * Standardise pagination for `api/v1/dsync/events` * Standardise pagination for api/admin/connections * Standardise pagination for api/admin/directory-sync * Standardise pagination for `api/v1/dsync/groups` * Standardise pagination for `v1/dsync/users`, `v1/dsync/product` * Standardise pagination in fetchByProduct APIs * Update swagger for groups * Fix pagination params definition, add the params for users api * More swagger updates * Swagger spec update for dsync events * Add pagination params to apis fetching by product * Update qs in internal-ui * Remove type assertion * [Swagger WIP] Fix response format for paginated APIs * Add dsync events to swagger spec * Fix swagger spec for sso tracer * Fix swagger spec for federated-saml apps of a product * Update pageLimit to 50 * Use pageLimit value from internal-ui * Update UI SDK * Cleanup local pagination component * Update swagger version * Remove unused keys from locale * Fix tag for trace api spec * Fix param name for swagger * Fix swagger tag for trace * updated package-lock * updated package-lock --------- Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2024-03-06 20:14:14 +00:00
const { product } = req.query as {
product: string;
};
if (!product) {
throw new Error('Please provide a product');
}
Pagination fixes (#2347) * `offset` -> `pageOffset`, `limit`-> `pageLimit` * Be backward compatible in API * Cleanup types and handle pagination qs * Cleanup unused code * Import type * Cleanup and fix lint error * Align params for sso-tracer * Move parsing to a common util function * pageLimit shouldn't be optional * Cap pageLimit to max value, split the boolean * Revert typings and assert non null * Refactor var name * Use util function to normalize pagination params across getAll and getByIndex * Normalize offset/limit for dynamo/mongo * Update query params in `FederatedSAMLApps` * Cap to max limit if passed limit is 0 * Sync lock file * Add a 3rd record and supply opts.pageLimit * Normalize offset/limit for mem/redis * Save the 3rd record in the store * Fix getAll tests * Give precedence to standard params over legacy * Use util function * Parse using util function * Refactor * Standardise pagination for `api/v1/dsync/events` * Standardise pagination for api/admin/connections * Standardise pagination for api/admin/directory-sync * Standardise pagination for `api/v1/dsync/groups` * Standardise pagination for `v1/dsync/users`, `v1/dsync/product` * Standardise pagination in fetchByProduct APIs * Update swagger for groups * Fix pagination params definition, add the params for users api * More swagger updates * Swagger spec update for dsync events * Add pagination params to apis fetching by product * Update qs in internal-ui * Remove type assertion * [Swagger WIP] Fix response format for paginated APIs * Add dsync events to swagger spec * Fix swagger spec for sso tracer * Fix swagger spec for federated-saml apps of a product * Update pageLimit to 50 * Use pageLimit value from internal-ui * Update UI SDK * Cleanup local pagination component * Update swagger version * Remove unused keys from locale * Fix tag for trace api spec * Fix param name for swagger * Fix swagger tag for trace * updated package-lock * updated package-lock --------- Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2024-03-06 20:14:14 +00:00
const { pageOffset, pageLimit, pageToken } = parsePaginateApiParams(req.query);
const setupLinks = await setupLinkController.filterBy({
product,
service,
Pagination fixes (#2347) * `offset` -> `pageOffset`, `limit`-> `pageLimit` * Be backward compatible in API * Cleanup types and handle pagination qs * Cleanup unused code * Import type * Cleanup and fix lint error * Align params for sso-tracer * Move parsing to a common util function * pageLimit shouldn't be optional * Cap pageLimit to max value, split the boolean * Revert typings and assert non null * Refactor var name * Use util function to normalize pagination params across getAll and getByIndex * Normalize offset/limit for dynamo/mongo * Update query params in `FederatedSAMLApps` * Cap to max limit if passed limit is 0 * Sync lock file * Add a 3rd record and supply opts.pageLimit * Normalize offset/limit for mem/redis * Save the 3rd record in the store * Fix getAll tests * Give precedence to standard params over legacy * Use util function * Parse using util function * Refactor * Standardise pagination for `api/v1/dsync/events` * Standardise pagination for api/admin/connections * Standardise pagination for api/admin/directory-sync * Standardise pagination for `api/v1/dsync/groups` * Standardise pagination for `v1/dsync/users`, `v1/dsync/product` * Standardise pagination in fetchByProduct APIs * Update swagger for groups * Fix pagination params definition, add the params for users api * More swagger updates * Swagger spec update for dsync events * Add pagination params to apis fetching by product * Update qs in internal-ui * Remove type assertion * [Swagger WIP] Fix response format for paginated APIs * Add dsync events to swagger spec * Fix swagger spec for sso tracer * Fix swagger spec for federated-saml apps of a product * Update pageLimit to 50 * Use pageLimit value from internal-ui * Update UI SDK * Cleanup local pagination component * Update swagger version * Remove unused keys from locale * Fix tag for trace api spec * Fix param name for swagger * Fix swagger tag for trace * updated package-lock * updated package-lock --------- Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2024-03-06 20:14:14 +00:00
pageOffset,
pageLimit,
pageToken,
});
res.json(setupLinks);
};