internal type fixes

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-12-19 22:01:33 +01:00
parent 189e96695f
commit b664b2ae09
9 changed files with 23 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-module-addons-contrib': patch
---
Internal refactor for safer handling of possible null value.
@@ -22,8 +22,8 @@ import {
} from '@backstage/backend-plugin-api';
import { ConflictError, stringifyError } from '@backstage/errors';
// Direct internal import to avoid duplication
// eslint-disable-next-line @backstage/no-forbidden-package-imports
import { InternalServiceFactory } from '@backstage/backend-plugin-api/src/services/system/types';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import { InternalServiceFactory } from '../../../backend-plugin-api/src/services/system/types';
import { DependencyGraph } from '../lib/DependencyGraph';
/**
* Keep in sync with `@backstage/backend-plugin-api/src/services/system/types.ts`
@@ -22,7 +22,7 @@ import {
FlattenedJWSInput,
JWSHeaderParameters,
} from 'jose';
import { GetKeyFunction } from 'jose/dist/types/types';
import { GetKeyFunction } from 'jose';
const CLOCK_MARGIN_S = 10;
@@ -18,7 +18,7 @@ import { Config } from '@backstage/config';
import { HumanDuration, durationToMilliseconds } from '@backstage/types';
import { promises as fs } from 'fs';
import { JWK, exportJWK, importPKCS8, importSPKI } from 'jose';
import { KeyLike } from 'jose/dist/types/types';
import { KeyLike } from 'jose';
import { KeyPayload } from './types';
import { PluginKeySource } from './types';
@@ -17,7 +17,6 @@
import { Config } from '@backstage/config';
import helmet from 'helmet';
import { HelmetOptions } from 'helmet';
import { ContentSecurityPolicyOptions } from 'helmet/dist/types/middlewares/content-security-policy';
import kebabCase from 'lodash/kebabCase';
/**
@@ -81,10 +80,15 @@ function readCspDirectives(config?: Config): CspDirectives {
return result;
}
type ContentSecurityPolicyDirectives = Exclude<
HelmetOptions['contentSecurityPolicy'],
boolean | undefined
>['directives'];
export function applyCspDirectives(
directives: CspDirectives,
): ContentSecurityPolicyOptions['directives'] {
const result: ContentSecurityPolicyOptions['directives'] =
): ContentSecurityPolicyDirectives {
const result: ContentSecurityPolicyDirectives =
helmet.contentSecurityPolicy.getDefaultDirectives();
// TODO(Rugvip): We currently use non-precompiled AJV for validation in the frontend, which uses eval.
@@ -27,11 +27,11 @@ import { mockServices } from '../services';
import { ConfigReader } from '@backstage/config';
import express from 'express';
// Direct internal import to avoid duplication
// eslint-disable-next-line @backstage/no-forbidden-package-imports
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import {
InternalBackendFeature,
InternalBackendRegistrations,
} from '@backstage/backend-plugin-api/src/wiring/types';
} from '../../../../backend-plugin-api/src/wiring/types';
import {
DefaultRootHttpRouter,
ExtendedHttpServer,
@@ -15,7 +15,7 @@
*/
import { AnyJWK, KeyStore, StoredKey } from './types';
import { exportJWK, importPKCS8, importSPKI, JWK } from 'jose';
import { KeyLike } from 'jose/dist/types/types';
import { KeyLike } from 'jose';
import { promises as fs } from 'fs';
import { Config } from '@backstage/config';
@@ -24,7 +24,7 @@ import {
JWSHeaderParameters,
jwtVerify,
} from 'jose';
import { GetKeyFunction } from 'jose/dist/types/types';
import { GetKeyFunction } from 'jose';
import { getBearerTokenFromAuthorizationHeader } from './getBearerTokenFromAuthorizationHeader';
import { IdentityApi, IdentityApiGetIdentityRequest } from './IdentityApi';
import { BackstageIdentityResponse } from '../types';
@@ -28,7 +28,7 @@ export const LightBoxAddon = () => {
useEffect(() => {
let dataSourceImages: DataSource | null = null;
let lightbox = new PhotoSwipeLightbox({
let lightbox: PhotoSwipeLightbox | null = new PhotoSwipeLightbox({
pswpModule: PhotoSwipe,
initialZoomLevel: 1,
secondaryZoomLevel: (zoomLevelObject: ZoomLevel) => {
@@ -71,14 +71,14 @@ export const LightBoxAddon = () => {
};
});
}
lightbox.loadAndOpen(index, dataSourceImages);
lightbox?.loadAndOpen(index, dataSourceImages);
return false;
};
});
lightbox.init();
return () => {
lightbox.destroy();
lightbox?.destroy();
lightbox = null;
};
}, [images]);