From 2a11fbdfe101f253df554f44d1ac159d658085f1 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:25:59 -0400 Subject: [PATCH] chore(deps): update dependency @octokit/tsconfig to v4 (#646) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Oscar Dominguez --- package-lock.json | 8 ++-- package.json | 4 +- src/get-app-authentication.ts | 15 ++++-- src/get-installation-authentication.ts | 63 ++++++++++++++++++-------- src/types.ts | 6 +-- 5 files changed, 65 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9aadd17c..9f7db924 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "universal-user-agent": "^7.0.0" }, "devDependencies": { - "@octokit/tsconfig": "^3.0.0", + "@octokit/tsconfig": "^4.0.0", "@types/fetch-mock": "^7.3.1", "@types/jest": "^29.0.0", "@types/node": "^20.0.0", @@ -1977,9 +1977,9 @@ } }, "node_modules/@octokit/tsconfig": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-3.1.0.tgz", - "integrity": "sha512-3jGTGqDnnh/MZlg/sf21J/0cghsmaSnG+ZPK+o++sQwUwgrLVtfbUi/BANHgf22SRnxhdYtOoRX90I9/cP+9BA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-4.0.0.tgz", + "integrity": "sha512-hRd6UhX19m+8WhfrEpNLtm9TjuizYSG/dE0a+ivU71ylSxABVe4mEK+JMAGdjj6/gIQ+5DPegTPofi4P8VC5IA==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index 1d9b5d6f..db2a270d 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "lint:fix": "prettier --write '{src,test,scripts}/**/*.{ts,md}' README.md *.json", "pretest": "npm run -s lint", "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage", - "test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --target es2022 --module node16 --moduleResolution node16 test/typescript-validate.ts" + "test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --target es2022 --module node16 --moduleResolution node16 --exactOptionalPropertyTypes test/typescript-validate.ts" }, "repository": "github:octokit/auth-app.js", "keywords": [ @@ -35,7 +35,7 @@ "universal-user-agent": "^7.0.0" }, "devDependencies": { - "@octokit/tsconfig": "^3.0.0", + "@octokit/tsconfig": "^4.0.0", "@types/fetch-mock": "^7.3.1", "@types/jest": "^29.0.0", "@types/node": "^20.0.0", diff --git a/src/get-app-authentication.ts b/src/get-app-authentication.ts index 49075160..a8be1b91 100644 --- a/src/get-app-authentication.ts +++ b/src/get-app-authentication.ts @@ -7,14 +7,21 @@ export async function getAppAuthentication({ privateKey, timeDifference, }: State & { - timeDifference?: number; + timeDifference?: number | undefined; }): Promise { try { - const appAuthentication = await githubAppJwt({ + const authOptions = { id: appId, privateKey, - now: timeDifference && Math.floor(Date.now() / 1000) + timeDifference, - }); + }; + + if (timeDifference) { + Object.assign(authOptions, { + now: Math.floor(Date.now() / 1000) + timeDifference, + }); + } + + const appAuthentication = await githubAppJwt(authOptions); return { type: "app", diff --git a/src/get-installation-authentication.ts b/src/get-installation-authentication.ts index 7d02fab8..9a471fa0 100644 --- a/src/get-installation-authentication.ts +++ b/src/get-installation-authentication.ts @@ -40,6 +40,7 @@ export async function getInstallationAuthentication( state.cache, optionsWithInstallationTokenFromState, ); + if (result) { const { token, @@ -69,6 +70,30 @@ export async function getInstallationAuthentication( const appAuthentication = await getAppAuthentication(state); const request = customRequest || state.request; + const payload = { + installation_id: installationId, + mediaType: { + previews: ["machine-man"], + }, + headers: { + authorization: `bearer ${appAuthentication.token}`, + }, + }; + + if (options.repositoryIds) { + Object.assign(payload, { repository_ids: options.repositoryIds }); + } + + if (options.repositoryNames) { + Object.assign(payload, { + repositories: options.repositoryNames, + }); + } + + if (options.permissions) { + Object.assign(payload, { permissions: options.permissions }); + } + const { data: { token, @@ -78,18 +103,10 @@ export async function getInstallationAuthentication( repository_selection: repositorySelectionOptional, single_file: singleFileName, }, - } = await request("POST /app/installations/{installation_id}/access_tokens", { - installation_id: installationId, - repository_ids: options.repositoryIds, - repositories: options.repositoryNames, - permissions: options.permissions, - mediaType: { - previews: ["machine-man"], - }, - headers: { - authorization: `bearer ${appAuthentication.token}`, - }, - }); + } = await request( + "POST /app/installations/{installation_id}/access_tokens", + payload, + ); /* istanbul ignore next - permissions are optional per OpenAPI spec, but we think that is incorrect */ const permissions = permissionsOptional || {}; @@ -105,7 +122,7 @@ export async function getInstallationAuthentication( : void 0; const createdAt = new Date().toISOString(); - await set(state.cache, optionsWithInstallationTokenFromState, { + const cacheOptions = { token, createdAt, expiresAt, @@ -113,10 +130,15 @@ export async function getInstallationAuthentication( permissions, repositoryIds, repositoryNames, - singleFileName, - }); + }; + + if (singleFileName) { + Object.assign(payload, { singleFileName }); + } + + await set(state.cache, optionsWithInstallationTokenFromState, cacheOptions); - return toTokenAuthentication({ + const cacheData = { installationId, token, createdAt, @@ -125,6 +147,11 @@ export async function getInstallationAuthentication( permissions, repositoryIds, repositoryNames, - singleFileName, - }); + }; + + if (singleFileName) { + Object.assign(cacheData, { singleFileName }); + } + + return toTokenAuthentication(cacheData); } diff --git a/src/types.ts b/src/types.ts index 4fbb6f8c..07543f52 100644 --- a/src/types.ts +++ b/src/types.ts @@ -162,9 +162,9 @@ export type InstallationAccessTokenData = { expiresAt: UTC_TIMESTAMP; permissions: Permissions; repositorySelection: REPOSITORY_SELECTION; - repositoryIds?: number[]; - repositoryNames?: string[]; - singleFileName?: string; + repositoryIds?: number[] | undefined; + repositoryNames?: string[] | undefined; + singleFileName?: string | undefined; }; export type CacheData = InstallationAccessTokenData;