Skip to content

Commit

Permalink
build!: Set Node v12 to minimum supported version & Upgrade TypeScript (
Browse files Browse the repository at this point in the history
  • Loading branch information
d-goog authored Apr 20, 2022
1 parent e4a5430 commit b7bcedb
Show file tree
Hide file tree
Showing 28 changed files with 77 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ branchProtectionRules:
- "ci/kokoro: System test"
- docs
- lint
- test (10)
- test (12)
- test (14)
- test (16)
- cla/google
- windows
- OwlBot Post Processor
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [10, 12, 14]
node: [12, 14, 16]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
34 changes: 0 additions & 34 deletions .kokoro/continuous/node10/common.cfg

This file was deleted.

4 changes: 0 additions & 4 deletions .kokoro/continuous/node10/docs.cfg

This file was deleted.

9 changes: 0 additions & 9 deletions .kokoro/continuous/node10/test.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .kokoro/continuous/node8/browser-test.cfg

This file was deleted.

24 changes: 0 additions & 24 deletions .kokoro/continuous/node8/common.cfg

This file was deleted.

Empty file removed .kokoro/continuous/node8/test.cfg
Empty file.
34 changes: 0 additions & 34 deletions .kokoro/presubmit/node10/common.cfg

This file was deleted.

4 changes: 0 additions & 4 deletions .kokoro/presubmit/node10/docs.cfg

This file was deleted.

4 changes: 0 additions & 4 deletions .kokoro/presubmit/node10/lint.cfg

This file was deleted.

Empty file removed .kokoro/presubmit/node10/test.cfg
Empty file.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Google Inc.",
"description": "Google APIs Authentication Client Library for Node.js",
"engines": {
"node": ">=10"
"node": ">=12"
},
"main": "./build/src/index.js",
"types": "./build/src/index.d.ts",
Expand Down Expand Up @@ -44,7 +44,7 @@
"chai": "^4.2.0",
"codecov": "^3.0.2",
"execa": "^5.0.0",
"gts": "^2.0.0",
"gts": "^3.1.0",
"is-docker": "^2.0.0",
"karma": "^6.0.0",
"karma-chrome-launcher": "^3.0.0",
Expand All @@ -65,7 +65,7 @@
"sinon": "^13.0.0",
"tmp": "^0.2.0",
"ts-loader": "^8.0.0",
"typescript": "^3.8.3",
"typescript": "^4.6.3",
"webpack": "^5.21.2",
"webpack-cli": "^4.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "mocha --timeout 60000"
},
"engines": {
"node": ">=10"
"node": ">=12"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion samples/puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "An example of using puppeteer to orchestrate a Google sign in flow.",
"main": "oauth2-test.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"start": "node oauth2-test.js"
Expand Down
2 changes: 1 addition & 1 deletion src/auth/baseexternalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export abstract class BaseExternalAccountClient extends AuthClient {
* the type of external credential used.
* @return A promise that resolves with the external subject token.
*/
abstract async retrieveSubjectToken(): Promise<string>;
abstract retrieveSubjectToken(): Promise<string>;

/**
* @return A promise that resolves with the current GCP access token
Expand Down
12 changes: 9 additions & 3 deletions src/auth/computeclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ export class Compute extends OAuth2Client {
}
data = await gcpMetadata.instance(instanceOptions);
} catch (e) {
e.message = `Could not refresh access token: ${e.message}`;
this.wrapError(e);
if (e instanceof GaxiosError) {
e.message = `Could not refresh access token: ${e.message}`;
this.wrapError(e);
}

throw e;
}
const tokens = data as Credentials;
Expand All @@ -101,7 +104,10 @@ export class Compute extends OAuth2Client {
};
idToken = await gcpMetadata.instance(instanceOptions);
} catch (e) {
e.message = `Could not fetch ID token: ${e.message}`;
if (e instanceof Error) {
e.message = `Could not fetch ID token: ${e.message}`;
}

throw e;
}

Expand Down
5 changes: 4 additions & 1 deletion src/auth/identitypoolclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ export class IdentityPoolClient extends BaseExternalAccountClient {
throw new Error();
}
} catch (err) {
err.message = `The file at ${filePath} does not exist, or it is not a file. ${err.message}`;
if (err instanceof Error) {
err.message = `The file at ${filePath} does not exist, or it is not a file. ${err.message}`;
}

throw err;
}

Expand Down
13 changes: 11 additions & 2 deletions src/auth/impersonated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {GetTokenResponse, OAuth2Client, RefreshOptions} from './oauth2client';
import {AuthClient} from './authclient';
import {GaxiosError} from 'gaxios';

export interface ImpersonatedOptions extends RefreshOptions {
/**
Expand Down Expand Up @@ -132,8 +133,16 @@ export class Impersonated extends OAuth2Client {
res,
};
} catch (error) {
const status = error?.response?.data?.error?.status;
const message = error?.response?.data?.error?.message;
if (!(error instanceof Error)) throw error;

let status = 0;
let message = '';

if (error instanceof GaxiosError) {
status = error?.response?.data?.error?.status;
message = error?.response?.data?.error?.message;
}

if (status && message) {
error.message = `${status}: unable to impersonate: ${message}`;
throw error;
Expand Down
19 changes: 15 additions & 4 deletions src/auth/oauth2client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,10 @@ export class OAuth2Client extends AuthClient {
try {
res = await this.transporter.request({url});
} catch (e) {
e.message = `Failed to retrieve verification certificates: ${e.message}`;
if (e instanceof Error) {
e.message = `Failed to retrieve verification certificates: ${e.message}`;
}

throw e;
}

Expand Down Expand Up @@ -1220,7 +1223,10 @@ export class OAuth2Client extends AuthClient {
try {
res = await this.transporter.request({url});
} catch (e) {
e.message = `Failed to retrieve verification certificates: ${e.message}`;
if (e instanceof Error) {
e.message = `Failed to retrieve verification certificates: ${e.message}`;
}

throw e;
}

Expand Down Expand Up @@ -1271,7 +1277,10 @@ export class OAuth2Client extends AuthClient {
try {
envelope = JSON.parse(crypto.decodeBase64StringUtf8(segments[0]));
} catch (err) {
err.message = `Can't parse token envelope: ${segments[0]}': ${err.message}`;
if (err instanceof Error) {
err.message = `Can't parse token envelope: ${segments[0]}': ${err.message}`;
}

throw err;
}

Expand All @@ -1282,7 +1291,9 @@ export class OAuth2Client extends AuthClient {
try {
payload = JSON.parse(crypto.decodeBase64StringUtf8(segments[1]));
} catch (err) {
err.message = `Can't parse token payload '${segments[0]}`;
if (err instanceof Error) {
err.message = `Can't parse token payload '${segments[0]}`;
}
throw err;
}

Expand Down
4 changes: 2 additions & 2 deletions src/auth/stscredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {GaxiosOptions, GaxiosResponse} from 'gaxios';
import {GaxiosError, GaxiosOptions, GaxiosResponse} from 'gaxios';
import * as querystring from 'querystring';

import {DefaultTransporter} from '../transporters';
Expand Down Expand Up @@ -216,7 +216,7 @@ export class StsCredentials extends OAuthClientAuthHandler {
return stsSuccessfulResponse;
} catch (error) {
// Translate error to OAuthError.
if (error.response) {
if (error instanceof GaxiosError && error.response) {
throw getErrorFromOAuthErrorResponse(
error.response.data as OAuthErrorResponse,
// Preserve other fields from the original error.
Expand Down
2 changes: 1 addition & 1 deletion src/transporters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class DefaultTransporter {
validate(opts);
} catch (e) {
if (callback) {
return callback(e);
return callback(e as Error);
} else {
throw e;
}
Expand Down
18 changes: 14 additions & 4 deletions test/test.awsclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ describe('AwsClient', () => {
{},
awsCredentialSource
);
delete missingUrlCredentialSource.url;
delete (
missingUrlCredentialSource as Partial<typeof awsCredentialSource>
).url;
const invalidOptions = {
type: 'external_account',
audience,
Expand All @@ -435,7 +437,11 @@ describe('AwsClient', () => {
{},
awsCredentialSource
);
delete missingRegionUrlCredentialSource.region_url;
delete (
missingRegionUrlCredentialSource as Partial<
typeof awsCredentialSource
>
).region_url;
const invalidOptions = {
type: 'external_account',
audience,
Expand Down Expand Up @@ -707,8 +713,12 @@ describe('AwsClient', () => {
awsCredentialSource
);
// Remove all optional fields.
delete requiredOnlyCredentialSource.region_url;
delete requiredOnlyCredentialSource.url;
delete (
requiredOnlyCredentialSource as Partial<typeof awsCredentialSource>
).region_url;
delete (
requiredOnlyCredentialSource as Partial<typeof awsCredentialSource>
).url;
const requiredOnlyOptions = {
type: 'external_account',
audience,
Expand Down
3 changes: 2 additions & 1 deletion test/test.externalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ describe('ExternalAccountClient', () => {

it('should throw when given invalid ExternalAccountClient', () => {
const invalidOptions = Object.assign({}, fileSourcedOptions);
delete invalidOptions.credential_source;
delete (invalidOptions as Partial<typeof fileSourcedOptions>)
.credential_source;

assert.throws(() => {
return ExternalAccountClient.fromJSON(invalidOptions);
Expand Down
Loading

0 comments on commit b7bcedb

Please sign in to comment.