Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .redocly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ preprocessors: {}
rules:
boolean-parameter-prefixes:
severity: error
prefixes: ['should', 'is', 'has']
prefixes: ['should', 'is', 'has', 'only']
no-unused-components:
severity: error
no-empty-servers: off
Expand Down
124 changes: 111 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/auth-manager/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ paths:
tags:
- client
parameters:
- in: query
name: name
description: search by client name (partial match, case-insensitive)
schema:
type: string
- in: query
name: branch
description: search by branch name
Expand Down Expand Up @@ -281,6 +286,17 @@ paths:
tags:
- connection
parameters:
- in: query
name: name
description: search by client name (partial match, case-insensitive)
schema:
type: string
- in: query
name: onlyLatest
description: if true, returns only the latest version per (name, environment) pair
schema:
type: boolean
default: false
- $ref: '#/components/parameters/environmentQueryParam'
- in: query
name: isEnabled
Expand Down
1 change: 1 addition & 0 deletions packages/auth-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"compression": "^1.7.4",
"config": "^3.3.9",
"cors": "^2.8.5",
"date-fns": "^4.1.0",
"express": "^4.18.2",
"express-openapi-validator": "^5.0.3",
"http-status-codes": "^2.2.0",
Expand Down
16 changes: 8 additions & 8 deletions packages/auth-manager/src/client/controllers/clientController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type Logger } from '@map-colonies/js-logger';
import httpStatus from 'http-status-codes';
import { injectable, inject } from 'tsyringe';
import { IClient } from '@map-colonies/auth-core';
import { parseISO } from 'date-fns';
import type { TypedRequestHandlers, components, operations } from '@openapi';
import { SERVICES } from '@common/constants';
import { DEFAULT_PAGE_SIZE } from '@src/common/db/pagination';
Expand All @@ -20,14 +21,13 @@ function responseClientToOpenApi(client: IClient): components['schemas']['client
}

function queryParamsToSearchParams(query: NonNullable<operations['getClients']['parameters']['query']>): ClientSearchParams {
const { branch, tags, createdAfter, createdBefore, updatedAfter, updatedBefore } = query;
const { createdAfter, createdBefore, updatedAfter, updatedBefore, ...rest } = query;
return {
branch,
tags,
createdAfter: createdAfter !== undefined ? new Date(createdAfter) : undefined,
createdBefore: createdBefore !== undefined ? new Date(createdBefore) : undefined,
updatedAfter: updatedAfter !== undefined ? new Date(updatedAfter) : undefined,
updatedBefore: updatedBefore !== undefined ? new Date(updatedBefore) : undefined,
...rest,
createdAfter: createdAfter !== undefined ? parseISO(createdAfter) : undefined,
createdBefore: createdBefore !== undefined ? parseISO(createdBefore) : undefined,
updatedAfter: updatedAfter !== undefined ? parseISO(updatedAfter) : undefined,
updatedBefore: updatedBefore !== undefined ? parseISO(updatedBefore) : undefined,
};
}

Expand All @@ -51,7 +51,7 @@ export class ClientController {
public getClients: TypedRequestHandlers['getClients'] = async (req, res, next) => {
try {
this.logger.debug({ msg: 'executing #getClients handler', query: req.query });
const searchParams = queryParamsToSearchParams(req.query as NonNullable<operations['getClients']['parameters']['query']>);
const searchParams = queryParamsToSearchParams(req.query ?? {});

const paginationParams = {
/* istanbul ignore next */
Expand Down
14 changes: 5 additions & 9 deletions packages/auth-manager/src/client/models/client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { IClient } from '@map-colonies/auth-core';
import type { operations } from '@src/openapi';

export interface ClientSearchParams {
branch?: IClient['branch'];
createdBefore?: IClient['createdAt'];
createdAfter?: IClient['createdAt'];
updatedBefore?: IClient['createdAt'];
updatedAfter?: IClient['createdAt'];
tags?: IClient['tags'];
}
type DateKeys = 'createdBefore' | 'createdAfter' | 'updatedBefore' | 'updatedAfter';

// Converts date string query parameters to Date objects
export type ClientSearchParams = Omit<NonNullable<operations['getClients']['parameters']['query']>, DateKeys> & { [P in DateKeys]?: Date };
27 changes: 13 additions & 14 deletions packages/auth-manager/src/client/models/clientManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Logger } from '@map-colonies/js-logger';
import { inject, injectable } from 'tsyringe';
import { ArrayContains, QueryFailedError } from 'typeorm';
import { ArrayContains, ILike, QueryFailedError } from 'typeorm';
import { DatabaseError } from 'pg';
import { Client, type IClient } from '@map-colonies/auth-core';
import { SERVICES } from '@common/constants';
Expand All @@ -9,8 +9,8 @@ import { createDatesComparison } from '@common/db/utils';
import { SortOptions } from '@src/common/db/sort';
import { PaginationParams, paginationParamsToFindOptions } from '@src/common/db/pagination';
import { type ClientRepository } from '../DAL/clientRepository';
import { ClientSearchParams } from './client';
import { ClientAlreadyExistsError, ClientNotFoundError } from './errors';
import { ClientSearchParams } from './client';

@injectable()
export class ClientManager {
Expand All @@ -20,7 +20,7 @@ export class ClientManager {
) {}

public async getClients(
searchParams?: ClientSearchParams,
searchParams: ClientSearchParams,
paginationParams?: PaginationParams,
sortParams?: SortOptions<Client>
): Promise<[IClient[], number]> {
Expand All @@ -29,17 +29,16 @@ export class ClientManager {

// eslint doesn't recognize this as valid because its in the type definition
let findOptions: Parameters<typeof this.clientRepository.find>[0] = {};
if (searchParams !== undefined) {
const { branch, tags, createdAfter, createdBefore, updatedAfter, updatedBefore } = searchParams;
findOptions = {
where: {
tags: tags ? ArrayContains(tags) : undefined,
branch,
createdAt: createDatesComparison(createdAfter, createdBefore),
updatedAt: createDatesComparison(updatedAfter, updatedBefore),
},
};
}
const { name, branch, tags, createdAfter, createdBefore, updatedAfter, updatedBefore } = searchParams;
findOptions = {
where: {
name: name !== undefined ? ILike(`%${name}%`) : undefined,
tags: tags ? ArrayContains(tags) : undefined,
branch,
createdAt: createDatesComparison(createdAfter, createdBefore),
updatedAt: createDatesComparison(updatedAfter, updatedBefore),
},
};

if (paginationParams !== undefined) {
findOptions = {
Expand Down
10 changes: 0 additions & 10 deletions packages/auth-manager/src/connection/models/connection.ts

This file was deleted.

Loading
Loading