Skip to content

Commit

Permalink
Add Knip configuration & fix unused exports
Browse files Browse the repository at this point in the history
  • Loading branch information
hupf committed Nov 9, 2023
1 parent 0ae39fc commit d0c5097
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
9 changes: 9 additions & 0 deletions .knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"project": ["src/**/*.{ts,js}"],
"ignore": ["public/*"],
"ignoreBinaries": ["knip", "vite-bundle-visualizer"],
"rules": {
"exports": "warn",
"types": "warn"
}
}
6 changes: 6 additions & 0 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Run TypeScript compiler & ESLint:
npm run lint
```

Print a report of unused dependencies, files & exports using [Knip](https://github.com/webpro/knip) (for the configuration, see [.knip.json](../.knip.json)):

```
npm run unused
```

### E2E Tests

Run E2E tests interactively:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"locale:extract": "lit-localize extract",
"locale:build": "lit-localize build",
"format": "prettier --write --ignore-unknown \"./**/*.*\"",
"format:upgrade": "npm install --save-exact prettier@latest && npm run format"
"format:upgrade": "npm install --save-exact prettier@latest && npm run format",
"unused": "npx knip"
},
"dependencies": {
"@badgateway/oauth2-client": "^2.2.4",
Expand Down
2 changes: 1 addition & 1 deletion src/state/portal-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const NAV_ITEM_QUERY_PARAM = "module";

const QUERY_PARAMS = [LOCALE_QUERY_PARAM, NAV_ITEM_QUERY_PARAM];

export class PortalState extends State {
class PortalState extends State {
@property({ value: getInitialLocale() })
locale!: string;

Expand Down
20 changes: 10 additions & 10 deletions src/utils/token-renewal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ export function initializeTokenRenewal(client: OAuth2Client): void {
);
}

export function renewRefreshTokenOnExpiration(
export function clearTokenRenewalTimers(): void {
Object.values(TokenType).forEach((type) => {
if (expirationTimers[type]) {
clearTimeout(expirationTimers[type]);
}
});
}

function renewRefreshTokenOnExpiration(
client: OAuth2Client,
refreshToken: TokenPayload | null,
): void {
Expand All @@ -46,7 +54,7 @@ export function renewRefreshTokenOnExpiration(
});
}

export function renewAccessTokenOnExpiration(
function renewAccessTokenOnExpiration(
client: OAuth2Client,
accessToken: TokenPayload | null,
): void {
Expand All @@ -61,14 +69,6 @@ export function renewAccessTokenOnExpiration(
});
}

export function clearTokenRenewalTimers(): void {
Object.values(TokenType).forEach((type) => {
if (expirationTimers[type]) {
clearTimeout(expirationTimers[type]);
}
});
}

/**
* Calls the given callback when the given token expires, canceling
* ongoing timers for the given token type (if there are any).
Expand Down
20 changes: 10 additions & 10 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
export type TokenPayload = {
instanceId: string;
scope: string;
locale: string;
issueTime: number;
expirationTime: number;
substitutionId?: number;
};

export type RawTokenPayload = {
type RawTokenPayload = {
instance_id: string;
scope: string;
culture_info: string;
Expand All @@ -20,6 +11,15 @@ export type RawTokenPayload = {
substitution_id?: string;
};

export type TokenPayload = {
instanceId: string;
scope: string;
locale: string;
issueTime: number;
expirationTime: number;
substitutionId?: number;
};

export function getTokenPayload(token: string): TokenPayload {
const {
instance_id: instanceId,
Expand Down

0 comments on commit d0c5097

Please sign in to comment.