Skip to content

Commit

Permalink
test(types): use --exactOptionalPropertyTypes and --strict options (#557
Browse files Browse the repository at this point in the history
)
  • Loading branch information
oscard0m authored Sep 24, 2024
1 parent 2fe541b commit 593b728
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
"pretest": "npm run -s lint",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --allowImportingTsExtensions --moduleResolution node16 --module node16 test/typescript-validate.ts"
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --allowImportingTsExtensions --moduleResolution node16 --module node16 --exactOptionalPropertyTypes --strict test/typescript-validate.ts"
},
"repository": "github:octokit/oauth-app.js",
"keywords": [
Expand All @@ -31,7 +31,7 @@
"universal-user-agent": "^7.0.0"
},
"devDependencies": {
"@octokit/tsconfig": "^3.0.0",
"@octokit/tsconfig": "^4.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"esbuild": "^0.24.0",
Expand Down
29 changes: 21 additions & 8 deletions src/middleware/handle-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,27 @@ export async function handleRequest(

try {
if (route === routes.getLogin) {
const { url } = app.getWebFlowAuthorizationUrl({
state: query.state,
scopes: query.scopes ? query.scopes.split(",") : undefined,
allowSignup: query.allowSignup
? query.allowSignup === "true"
: undefined,
redirectUrl: query.redirectUrl,
});
const authOptions = {};

if (query.state) {
Object.assign(authOptions, { state: query.state });
}

if (query.scopes) {
Object.assign(authOptions, { scopes: query.scopes.split(",") });
}

if (query.allowSignup) {
Object.assign(authOptions, {
allowSignup: query.allowSignup === "true",
});
}

if (query.redirectUrl) {
Object.assign(authOptions, { redirectUrl: query.redirectUrl });
}

const { url } = app.getWebFlowAuthorizationUrl(authOptions);

return { status: 302, headers: { location: url } };
}
Expand Down
11 changes: 8 additions & 3 deletions src/middleware/web-worker/send-response.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { OctokitResponse } from "../types.js";

export function sendResponse(octokitResponse: OctokitResponse): Response {
return new Response(octokitResponse.text, {
const responseOptions = {
status: octokitResponse.status,
headers: octokitResponse.headers,
});
};

if (octokitResponse.headers) {
Object.assign(responseOptions, { headers: octokitResponse.headers });
}

return new Response(octokitResponse.text, responseOptions);
}
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ export type State = {
clientId: ClientId;
clientSecret: ClientSecret;
defaultScopes: Scope[];
allowSignup?: boolean;
baseUrl?: string;
redirectUrl?: string;
log?: typeof console;
allowSignup?: boolean | undefined;
baseUrl?: string | undefined;
redirectUrl?: string | undefined;
log?: typeof console | undefined;
Octokit: OAuthAppOctokitClassType;
octokit: OctokitInstance;
eventHandlers: {
Expand Down
2 changes: 1 addition & 1 deletion test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function GitHubAppTest() {
// @ts-expect-error
context.scopes;

if ("refreshToken" in context.authentication) {
if (context.authentication && "refreshToken" in context.authentication) {
context.authentication.refreshTokenExpiresAt;
}
});
Expand Down

0 comments on commit 593b728

Please sign in to comment.