Skip to content

Commit

Permalink
chore(deps): update dependency prettier to v3 (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored Jul 7, 2023
1 parent c3c074e commit 010203f
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ The `request` option is an instance of [`@octokit/request`](https://github.com/o
```js
const { data: installations } = await auth.hook(
request,
"GET /app/installations"
"GET /app/installations",
);
```

Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1",
"glob": "^10.2.5",
"jest": "^29.0.0",
"prettier": "2.8.8",
"prettier": "3.0.0",
"semantic-release-plugin-update-version-in-files": "^1.0.0",
"ts-jest": "^29.0.0",
"typescript": "^5.0.0"
Expand Down
20 changes: 10 additions & 10 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ import { getInstallationAuthentication } from "./get-installation-authentication
/** GitHub App authentication */
export async function auth(
state: State,
authOptions: AppAuthOptions
authOptions: AppAuthOptions,
): Promise<AppAuthentication>;

/** OAuth App authentication */
export async function auth(
state: State,
authOptions: OAuthAppAuthOptions
authOptions: OAuthAppAuthOptions,
): Promise<OAuthAppAuthentication>;

/** Installation authentication */
export async function auth(
state: State,
authOptions: InstallationAuthOptions
authOptions: InstallationAuthOptions,
): Promise<InstallationAccessTokenAuthentication>;

/** User Authentication via OAuth web flow */
export async function auth(
state: State,
authOptions: OAuthWebFlowAuthOptions
authOptions: OAuthWebFlowAuthOptions,
): Promise<
GitHubAppUserAuthentication | GitHubAppUserAuthenticationWithExpiration
>;
Expand All @@ -49,13 +49,13 @@ export async function auth<T = unknown>(
state: State,
authOptions: OAuthWebFlowAuthOptions & {
factory: OAuthAppAuth.FactoryGitHubWebFlow<T>;
}
},
): Promise<T>;

/** User Authentication via OAuth Device flow */
export async function auth(
state: State,
authOptions: OAuthDeviceFlowAuthOptions
authOptions: OAuthDeviceFlowAuthOptions,
): Promise<
GitHubAppUserAuthentication | GitHubAppUserAuthenticationWithExpiration
>;
Expand All @@ -65,7 +65,7 @@ export async function auth<T = unknown>(
state: State,
authOptions: OAuthDeviceFlowAuthOptions & {
factory: OAuthAppAuth.FactoryGitHubDeviceFlow<T>;
}
},
): Promise<T>;

export async function auth<T = unknown>(
Expand All @@ -81,7 +81,7 @@ export async function auth<T = unknown>(
})
| (OAuthDeviceFlowAuthOptions & {
factory: OAuthAppAuth.FactoryGitHubDeviceFlow<T>;
})
}),
): Promise<Authentication> {
switch (authOptions.type) {
case "app":
Expand All @@ -91,8 +91,8 @@ export async function auth<T = unknown>(
state.log.warn(
// @ts-expect-error `log.warn()` expects string
new Deprecation(
`[@octokit/auth-app] {type: "oauth"} is deprecated. Use {type: "oauth-app"} instead`
)
`[@octokit/auth-app] {type: "oauth"} is deprecated. Use {type: "oauth-app"} instead`,
),
);
case "oauth-app":
return state.oauthApp({ type: "oauth-app" });
Expand Down
6 changes: 3 additions & 3 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getCache() {

export async function get(
cache: Cache,
options: InstallationAuthOptions
options: InstallationAuthOptions,
): Promise<InstallationAccessTokenData | void> {
const cacheKey = optionsToCacheKey(options);
const result = await cache.get(cacheKey);
Expand Down Expand Up @@ -68,15 +68,15 @@ export async function get(
export async function set(
cache: Cache,
options: InstallationAuthOptions,
data: CacheData
data: CacheData,
): Promise<void> {
const key = optionsToCacheKey(options);

const permissionsString = options.permissions
? ""
: Object.keys(data.permissions)
.map(
(name) => `${name}${data.permissions[name] === "write" ? "!" : ""}`
(name) => `${name}${data.permissions[name] === "write" ? "!" : ""}`,
)
.join(",");

Expand Down
2 changes: 1 addition & 1 deletion src/get-app-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function getAppAuthentication({
} catch (error) {
if (privateKey === "-----BEGIN RSA PRIVATE KEY-----") {
throw new Error(
"The 'privateKey` option contains only the first line '-----BEGIN RSA PRIVATE KEY-----'. If you are setting it using a `.env` file, make sure it is set on a single line with newlines replaced by '\n'"
"The 'privateKey` option contains only the first line '-----BEGIN RSA PRIVATE KEY-----'. If you are setting it using a `.env` file, make sure it is set on a single line with newlines replaced by '\n'",
);
} else {
throw error;
Expand Down
8 changes: 4 additions & 4 deletions src/get-installation-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import type {
export async function getInstallationAuthentication(
state: State,
options: InstallationAuthOptions,
customRequest?: RequestInterface
customRequest?: RequestInterface,
): Promise<InstallationAccessTokenAuthentication> {
const installationId = Number(options.installationId || state.installationId);

if (!installationId) {
throw new Error(
"[@octokit/auth-app] installationId option is required for installation authentication."
"[@octokit/auth-app] installationId option is required for installation authentication.",
);
}

Expand All @@ -32,13 +32,13 @@ export async function getInstallationAuthentication(

const optionsWithInstallationTokenFromState = Object.assign(
{ installationId },
options
options,
);

if (!options.refresh) {
const result = await get(
state.cache,
optionsWithInstallationTokenFromState
optionsWithInstallationTokenFromState,
);
if (result) {
const {
Expand Down
18 changes: 9 additions & 9 deletions src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const FIVE_SECONDS_IN_MS = 5 * 1000;
function isNotTimeSkewError(error: RequestError) {
return !(
error.message.match(
/'Expiration time' claim \('exp'\) must be a numeric value representing the future time at which the assertion expires/
/'Expiration time' claim \('exp'\) must be a numeric value representing the future time at which the assertion expires/,
) ||
error.message.match(
/'Issued at' claim \('iat'\) must be an Integer representing the time that the assertion was issued/
/'Issued at' claim \('iat'\) must be an Integer representing the time that the assertion was issued/,
)
);
}
Expand All @@ -30,7 +30,7 @@ export async function hook(
state: State,
request: RequestInterface,
route: Route | EndpointOptions,
parameters?: RequestParameters
parameters?: RequestParameters,
): Promise<AnyResponse> {
const endpoint = request.endpoint.merge(route as string, parameters);
const url = endpoint.url as string;
Expand Down Expand Up @@ -63,12 +63,12 @@ export async function hook(
const diff = Math.floor(
(Date.parse(error.response.headers.date) -
Date.parse(new Date().toString())) /
1000
1000,
);

state.log.warn(error.message);
state.log.warn(
`[@octokit/auth-app] GitHub API time and system time are different by ${diff} seconds. Retrying request with the difference accounted for.`
`[@octokit/auth-app] GitHub API time and system time are different by ${diff} seconds. Retrying request with the difference accounted for.`,
);

const { token } = await getAppAuthentication({
Expand All @@ -92,7 +92,7 @@ export async function hook(
state,
// @ts-expect-error TBD
{},
request
request,
);

endpoint.headers.authorization = `token ${token}`;
Expand All @@ -101,7 +101,7 @@ export async function hook(
state,
request,
endpoint as EndpointOptions,
createdAt
createdAt,
);
}

Expand All @@ -117,7 +117,7 @@ async function sendRequestWithRetries(
request: RequestInterface,
options: EndpointOptions,
createdAt: string,
retries: number = 0
retries: number = 0,
): Promise<AnyResponse> {
const timeSinceTokenCreationInMs = +new Date() - +new Date(createdAt);

Expand All @@ -143,7 +143,7 @@ async function sendRequestWithRetries(
state.log.warn(
`[@octokit/auth-app] Retrying after 401 response to account for token replication delay (retry: ${retries}, wait: ${
awaitTime / 1000
}s)`
}s)`,
);
await new Promise((resolve) => setTimeout(resolve, awaitTime));

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ export function createAppAuth(options: StrategyOptions): AuthInterface {
}
if (!Number.isFinite(+options.appId)) {
throw new Error(
"[@octokit/auth-app] appId option must be a number or numeric string"
"[@octokit/auth-app] appId option must be a number or numeric string",
);
}
if (!options.privateKey) {
throw new Error("[@octokit/auth-app] privateKey option is required");
}
if ("installationId" in options && !options.installationId) {
throw new Error(
"[@octokit/auth-app] installationId is set to a falsy value"
"[@octokit/auth-app] installationId is set to a falsy value",
);
}

const log = Object.assign(
{
warn: console.warn.bind(console),
},
options.log
options.log,
);
const request =
options.request ||
Expand All @@ -76,7 +76,7 @@ export function createAppAuth(options: StrategyOptions): AuthInterface {
clientSecret: options.clientSecret || "",
request,
}),
}
},
);

// @ts-expect-error not worth the extra code to appease TS
Expand Down
2 changes: 1 addition & 1 deletion src/requires-app-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function routeMatcher(paths: string[]) {
p
.split("/")
.map((c) => (c.startsWith("{") ? "(?:.+?)" : c))
.join("/")
.join("/"),
);
// 'regexes' would contain:
/* [
Expand Down
2 changes: 1 addition & 1 deletion src/to-token-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ export function toTokenAuthentication({
},
repositoryIds ? { repositoryIds } : null,
repositoryNames ? { repositoryNames } : null,
singleFileName ? { singleFileName } : null
singleFileName ? { singleFileName } : null,
);
}
16 changes: 10 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,40 @@ export interface AuthInterface {

// installation auth without `factory` option
(
options: InstallationAuthOptions
options: InstallationAuthOptions,
): Promise<InstallationAccessTokenAuthentication>;

// installation auth with `factory` option
<T = unknown>(options: InstallationAuthOptionsWithFactory<T>): Promise<T>;

// user auth without `factory` option
(options: OAuthWebFlowAuthOptions): Promise<
(
options: OAuthWebFlowAuthOptions,
): Promise<
GitHubAppUserAuthentication | GitHubAppUserAuthenticationWithExpiration
>;
(options: OAuthDeviceFlowAuthOptions): Promise<
(
options: OAuthDeviceFlowAuthOptions,
): Promise<
GitHubAppUserAuthentication | GitHubAppUserAuthenticationWithExpiration
>;

// user auth with `factory` option
<T = unknown>(
options: OAuthWebFlowAuthOptions & {
factory: OAuthAppAuth.FactoryGitHubWebFlow<T>;
}
},
): Promise<T>;
<T = unknown>(
options: OAuthDeviceFlowAuthOptions & {
factory: OAuthAppAuth.FactoryGitHubDeviceFlow<T>;
}
},
): Promise<T>;

hook(
request: RequestInterface,
route: Route | EndpointOptions,
parameters?: RequestParameters
parameters?: RequestParameters,
): Promise<OctokitTypes.OctokitResponse<any>>;
}

Expand Down
Loading

0 comments on commit 010203f

Please sign in to comment.