feat: updated more types to avoid infer

This commit is contained in:
=
2025-06-13 23:52:40 +05:30
parent 5311daed64
commit 7a00ade119
125 changed files with 1974 additions and 571 deletions
@@ -1,10 +1,10 @@
import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
import { ormify } from "@app/lib/knex";
import { ormify, TOrmify } from "@app/lib/knex";
export type TCertificateAuthorityCrlDALFactory = ReturnType<typeof certificateAuthorityCrlDALFactory>;
export type TCertificateAuthorityCrlDALFactory = TOrmify<TableName.CertificateAuthorityCrl>;
export const certificateAuthorityCrlDALFactory = (db: TDbClient) => {
export const certificateAuthorityCrlDALFactory = (db: TDbClient): TCertificateAuthorityCrlDALFactory => {
const caCrlOrm = ormify(db, TableName.CertificateAuthorityCrl);
return caCrlOrm;
};
@@ -3,7 +3,7 @@ import * as x509 from "@peculiar/x509";
import { ActionProjectType } from "@app/db/schemas";
import { TCertificateAuthorityCrlDALFactory } from "@app/ee/services/certificate-authority-crl/certificate-authority-crl-dal";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { NotFoundError } from "@app/lib/errors";
import { TCertificateAuthorityDALFactory } from "@app/services/certificate-authority/certificate-authority-dal";
@@ -12,7 +12,7 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { TProjectDALFactory } from "@app/services/project/project-dal";
import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns";
import { TGetCaCrlsDTO, TGetCrlById } from "./certificate-authority-crl-types";
import { TCertificateAuthorityCrlServiceFactory } from "./certificate-authority-crl-types";
type TCertificateAuthorityCrlServiceFactoryDep = {
certificateAuthorityDAL: Pick<TCertificateAuthorityDALFactory, "findByIdWithAssociatedCa">;
@@ -22,19 +22,17 @@ type TCertificateAuthorityCrlServiceFactoryDep = {
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
};
export type TCertificateAuthorityCrlServiceFactory = ReturnType<typeof certificateAuthorityCrlServiceFactory>;
export const certificateAuthorityCrlServiceFactory = ({
certificateAuthorityDAL,
certificateAuthorityCrlDAL,
projectDAL,
kmsService,
permissionService // licenseService
}: TCertificateAuthorityCrlServiceFactoryDep) => {
}: TCertificateAuthorityCrlServiceFactoryDep): TCertificateAuthorityCrlServiceFactory => {
/**
* Return CRL with id [crlId]
*/
const getCrlById = async (crlId: TGetCrlById) => {
const getCrlById: TCertificateAuthorityCrlServiceFactory["getCrlById"] = async (crlId) => {
const caCrl = await certificateAuthorityCrlDAL.findById(crlId);
if (!caCrl) throw new NotFoundError({ message: `CRL with ID '${crlId}' not found` });
@@ -65,7 +63,13 @@ export const certificateAuthorityCrlServiceFactory = ({
/**
* Returns a list of CRL ids for CA with id [caId]
*/
const getCaCrls = async ({ caId, actorId, actorAuthMethod, actor, actorOrgId }: TGetCaCrlsDTO) => {
const getCaCrls: TCertificateAuthorityCrlServiceFactory["getCaCrls"] = async ({
caId,
actorId,
actorAuthMethod,
actor,
actorOrgId
}) => {
const ca = await certificateAuthorityDAL.findByIdWithAssociatedCa(caId);
if (!ca?.internalCa?.id) throw new NotFoundError({ message: `Internal CA with ID '${caId}' not found` });
@@ -5,3 +5,137 @@ export type TGetCrlById = string;
export type TGetCaCrlsDTO = {
caId: string;
} & Omit<TProjectPermission, "projectId">;
export type TCertificateAuthorityCrlServiceFactory = {
getCrlById: (crlId: TGetCrlById) => Promise<{
ca: {
readonly requireTemplateForIssuance: boolean;
readonly internalCa:
| {
id: string;
parentCaId: string | null | undefined;
type: string;
friendlyName: string;
organization: string;
ou: string;
country: string;
province: string;
locality: string;
commonName: string;
dn: string;
serialNumber: string | null | undefined;
maxPathLength: number | null | undefined;
keyAlgorithm: string;
notBefore: string | undefined;
notAfter: string | undefined;
activeCaCertId: string | null | undefined;
}
| undefined;
readonly externalCa:
| {
id: string;
type: string;
configuration: unknown;
dnsAppConnectionId: string | null | undefined;
appConnectionId: string | null | undefined;
credentials: Buffer | null | undefined;
}
| undefined;
readonly name: string;
readonly status: string;
readonly id: string;
readonly createdAt: Date;
readonly updatedAt: Date;
readonly projectId: string;
readonly enableDirectIssuance: boolean;
readonly parentCaId: string | null | undefined;
readonly type: string;
readonly friendlyName: string;
readonly organization: string;
readonly ou: string;
readonly country: string;
readonly province: string;
readonly locality: string;
readonly commonName: string;
readonly dn: string;
readonly serialNumber: string | null | undefined;
readonly maxPathLength: number | null | undefined;
readonly keyAlgorithm: string;
readonly notBefore: string | undefined;
readonly notAfter: string | undefined;
readonly activeCaCertId: string | null | undefined;
};
caCrl: {
id: string;
createdAt: Date;
updatedAt: Date;
caId: string;
caSecretId: string;
encryptedCrl: Buffer;
};
crl: ArrayBuffer;
}>;
getCaCrls: ({ caId, actorId, actorAuthMethod, actor, actorOrgId }: TGetCaCrlsDTO) => Promise<{
ca: {
readonly requireTemplateForIssuance: boolean;
readonly internalCa:
| {
id: string;
parentCaId: string | null | undefined;
type: string;
friendlyName: string;
organization: string;
ou: string;
country: string;
province: string;
locality: string;
commonName: string;
dn: string;
serialNumber: string | null | undefined;
maxPathLength: number | null | undefined;
keyAlgorithm: string;
notBefore: string | undefined;
notAfter: string | undefined;
activeCaCertId: string | null | undefined;
}
| undefined;
readonly externalCa:
| {
id: string;
type: string;
configuration: unknown;
dnsAppConnectionId: string | null | undefined;
appConnectionId: string | null | undefined;
credentials: Buffer | null | undefined;
}
| undefined;
readonly name: string;
readonly status: string;
readonly id: string;
readonly createdAt: Date;
readonly updatedAt: Date;
readonly projectId: string;
readonly enableDirectIssuance: boolean;
readonly parentCaId: string | null | undefined;
readonly type: string;
readonly friendlyName: string;
readonly organization: string;
readonly ou: string;
readonly country: string;
readonly province: string;
readonly locality: string;
readonly commonName: string;
readonly dn: string;
readonly serialNumber: string | null | undefined;
readonly maxPathLength: number | null | undefined;
readonly keyAlgorithm: string;
readonly notBefore: string | undefined;
readonly notAfter: string | undefined;
readonly activeCaCertId: string | null | undefined;
};
crls: {
id: string;
crl: string;
}[];
}>;
};