Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 807b692

Browse files
fix: do not modify options object, use defaultScopes (#222)
Regenerated the library using [gapic-generator-typescript](https://github.com/googleapis/gapic-generator-typescript) v1.2.1.
1 parent 630d2aa commit 807b692

File tree

7 files changed

+212
-156
lines changed

7 files changed

+212
-156
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"reCAPTCHA Enterprise API"
2626
],
2727
"dependencies": {
28-
"google-gax": "^2.1.0"
28+
"google-gax": "^2.9.2"
2929
},
3030
"devDependencies": {
3131
"@types/mocha": "^8.0.0",

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as v1beta1 from './v1beta1';
2020
import * as v1 from './v1';
2121

2222
const RecaptchaEnterpriseServiceClient = v1.RecaptchaEnterpriseServiceClient;
23+
type RecaptchaEnterpriseServiceClient = v1.RecaptchaEnterpriseServiceClient;
2324

2425
export {v1beta1, v1, RecaptchaEnterpriseServiceClient};
2526
export default {v1beta1, v1, RecaptchaEnterpriseServiceClient};

src/v1/recaptcha_enterprise_service_client.ts

Lines changed: 93 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ export class RecaptchaEnterpriseServiceClient {
6060
/**
6161
* Construct an instance of RecaptchaEnterpriseServiceClient.
6262
*
63-
* @param {object} [options] - The configuration object. See the subsequent
64-
* parameters for more details.
63+
* @param {object} [options] - The configuration object.
64+
* The options accepted by the constructor are described in detail
65+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
66+
* The common options are:
6567
* @param {object} [options.credentials] - Credentials object.
6668
* @param {string} [options.credentials.client_email]
6769
* @param {string} [options.credentials.private_key]
@@ -81,44 +83,34 @@ export class RecaptchaEnterpriseServiceClient {
8183
* your project ID will be detected automatically.
8284
* @param {string} [options.apiEndpoint] - The domain name of the
8385
* API remote host.
86+
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
87+
* TODO(@alexander-fenster): link to gax documentation.
88+
* @param {boolean} fallback - Use HTTP fallback mode.
89+
* In fallback mode, a special browser-compatible transport implementation is used
90+
* instead of gRPC transport. In browser context (if the `window` object is defined)
91+
* the fallback mode is enabled automatically; set `options.fallback` to `false`
92+
* if you need to override this behavior.
8493
*/
85-
8694
constructor(opts?: ClientOptions) {
87-
// Ensure that options include the service address and port.
95+
// Ensure that options include all the required fields.
8896
const staticMembers = this
8997
.constructor as typeof RecaptchaEnterpriseServiceClient;
9098
const servicePath =
91-
opts && opts.servicePath
92-
? opts.servicePath
93-
: opts && opts.apiEndpoint
94-
? opts.apiEndpoint
95-
: staticMembers.servicePath;
96-
const port = opts && opts.port ? opts.port : staticMembers.port;
99+
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
100+
const port = opts?.port || staticMembers.port;
101+
const clientConfig = opts?.clientConfig ?? {};
102+
const fallback = opts?.fallback ?? typeof window !== 'undefined';
103+
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
97104

98-
if (!opts) {
99-
opts = {servicePath, port};
105+
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
106+
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
107+
opts['scopes'] = staticMembers.scopes;
100108
}
101-
opts.servicePath = opts.servicePath || servicePath;
102-
opts.port = opts.port || port;
103-
104-
// users can override the config from client side, like retry codes name.
105-
// The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546
106-
// The way to override client config for Showcase API:
107-
//
108-
// const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}}
109-
// const showcaseClient = new showcaseClient({ projectId, customConfig });
110-
opts.clientConfig = opts.clientConfig || {};
111109

112-
// If we're running in browser, it's OK to omit `fallback` since
113-
// google-gax has `browser` field in its `package.json`.
114-
// For Electron (which does not respect `browser` field),
115-
// pass `{fallback: true}` to the RecaptchaEnterpriseServiceClient constructor.
110+
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
116111
this._gaxModule = opts.fallback ? gax.fallback : gax;
117112

118-
// Create a `gaxGrpc` object, with any grpc-specific options
119-
// sent to the client.
120-
opts.scopes = (this
121-
.constructor as typeof RecaptchaEnterpriseServiceClient).scopes;
113+
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
122114
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
123115

124116
// Save options to use in initialize() method.
@@ -127,6 +119,11 @@ export class RecaptchaEnterpriseServiceClient {
127119
// Save the auth object to the client, for use by other methods.
128120
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;
129121

122+
// Set the default scopes in auth client if needed.
123+
if (servicePath === staticMembers.servicePath) {
124+
this.auth.defaultScopes = staticMembers.scopes;
125+
}
126+
130127
// Determine the client header string.
131128
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
132129
if (typeof process !== 'undefined' && 'versions' in process) {
@@ -268,6 +265,7 @@ export class RecaptchaEnterpriseServiceClient {
268265

269266
/**
270267
* The DNS address for this API service.
268+
* @returns {string} The DNS address for this service.
271269
*/
272270
static get servicePath() {
273271
return 'recaptchaenterprise.googleapis.com';
@@ -276,13 +274,15 @@ export class RecaptchaEnterpriseServiceClient {
276274
/**
277275
* The DNS address for this API service - same as servicePath(),
278276
* exists for compatibility reasons.
277+
* @returns {string} The DNS address for this service.
279278
*/
280279
static get apiEndpoint() {
281280
return 'recaptchaenterprise.googleapis.com';
282281
}
283282

284283
/**
285284
* The port for this API service.
285+
* @returns {number} The default port for this service.
286286
*/
287287
static get port() {
288288
return 443;
@@ -291,6 +291,7 @@ export class RecaptchaEnterpriseServiceClient {
291291
/**
292292
* The scopes needed to make gRPC calls for every method defined
293293
* in this service.
294+
* @returns {string[]} List of default scopes.
294295
*/
295296
static get scopes() {
296297
return ['https://www.googleapis.com/auth/cloud-platform'];
@@ -300,8 +301,7 @@ export class RecaptchaEnterpriseServiceClient {
300301
getProjectId(callback: Callback<string, undefined, undefined>): void;
301302
/**
302303
* Return the project ID used by this class.
303-
* @param {function(Error, string)} callback - the callback to
304-
* be called with the current project Id.
304+
* @returns {Promise} A promise that resolves to string containing the project ID.
305305
*/
306306
getProjectId(
307307
callback?: Callback<string, undefined, undefined>
@@ -364,7 +364,11 @@ export class RecaptchaEnterpriseServiceClient {
364364
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
365365
* @returns {Promise} - The promise which resolves to an array.
366366
* The first element of the array is an object representing [Assessment]{@link google.cloud.recaptchaenterprise.v1.Assessment}.
367-
* The promise has a method named "cancel" which cancels the ongoing API call.
367+
* Please see the
368+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
369+
* for more details and examples.
370+
* @example
371+
* const [response] = await client.createAssessment(request);
368372
*/
369373
createAssessment(
370374
request: protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest,
@@ -462,7 +466,11 @@ export class RecaptchaEnterpriseServiceClient {
462466
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
463467
* @returns {Promise} - The promise which resolves to an array.
464468
* The first element of the array is an object representing [AnnotateAssessmentResponse]{@link google.cloud.recaptchaenterprise.v1.AnnotateAssessmentResponse}.
465-
* The promise has a method named "cancel" which cancels the ongoing API call.
469+
* Please see the
470+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
471+
* for more details and examples.
472+
* @example
473+
* const [response] = await client.annotateAssessment(request);
466474
*/
467475
annotateAssessment(
468476
request: protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest,
@@ -556,7 +564,11 @@ export class RecaptchaEnterpriseServiceClient {
556564
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
557565
* @returns {Promise} - The promise which resolves to an array.
558566
* The first element of the array is an object representing [Key]{@link google.cloud.recaptchaenterprise.v1.Key}.
559-
* The promise has a method named "cancel" which cancels the ongoing API call.
567+
* Please see the
568+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
569+
* for more details and examples.
570+
* @example
571+
* const [response] = await client.createKey(request);
560572
*/
561573
createKey(
562574
request: protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest,
@@ -645,7 +657,11 @@ export class RecaptchaEnterpriseServiceClient {
645657
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
646658
* @returns {Promise} - The promise which resolves to an array.
647659
* The first element of the array is an object representing [Key]{@link google.cloud.recaptchaenterprise.v1.Key}.
648-
* The promise has a method named "cancel" which cancels the ongoing API call.
660+
* Please see the
661+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
662+
* for more details and examples.
663+
* @example
664+
* const [response] = await client.getKey(request);
649665
*/
650666
getKey(
651667
request: protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest,
@@ -736,7 +752,11 @@ export class RecaptchaEnterpriseServiceClient {
736752
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
737753
* @returns {Promise} - The promise which resolves to an array.
738754
* The first element of the array is an object representing [Key]{@link google.cloud.recaptchaenterprise.v1.Key}.
739-
* The promise has a method named "cancel" which cancels the ongoing API call.
755+
* Please see the
756+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
757+
* for more details and examples.
758+
* @example
759+
* const [response] = await client.updateKey(request);
740760
*/
741761
updateKey(
742762
request: protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest,
@@ -825,7 +845,11 @@ export class RecaptchaEnterpriseServiceClient {
825845
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
826846
* @returns {Promise} - The promise which resolves to an array.
827847
* The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}.
828-
* The promise has a method named "cancel" which cancels the ongoing API call.
848+
* Please see the
849+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
850+
* for more details and examples.
851+
* @example
852+
* const [response] = await client.deleteKey(request);
829853
*/
830854
deleteKey(
831855
request: protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest,
@@ -921,19 +945,14 @@ export class RecaptchaEnterpriseServiceClient {
921945
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
922946
* @returns {Promise} - The promise which resolves to an array.
923947
* The first element of the array is Array of [Key]{@link google.cloud.recaptchaenterprise.v1.Key}.
924-
* The client library support auto-pagination by default: it will call the API as many
948+
* The client library will perform auto-pagination by default: it will call the API as many
925949
* times as needed and will merge results from all the pages into this array.
926-
*
927-
* When autoPaginate: false is specified through options, the array has three elements.
928-
* The first element is Array of [Key]{@link google.cloud.recaptchaenterprise.v1.Key} that corresponds to
929-
* the one page received from the API server.
930-
* If the second element is not null it contains the request object of type [ListKeysRequest]{@link google.cloud.recaptchaenterprise.v1.ListKeysRequest}
931-
* that can be used to obtain the next page of the results.
932-
* If it is null, the next page does not exist.
933-
* The third element contains the raw response received from the API server. Its type is
934-
* [ListKeysResponse]{@link google.cloud.recaptchaenterprise.v1.ListKeysResponse}.
935-
*
936-
* The promise has a method named "cancel" which cancels the ongoing API call.
950+
* Note that it can affect your quota.
951+
* We recommend using `listKeysAsync()`
952+
* method described below for async iteration which you can stop as needed.
953+
* Please see the
954+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
955+
* for more details and examples.
937956
*/
938957
listKeys(
939958
request: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest,
@@ -981,18 +1000,7 @@ export class RecaptchaEnterpriseServiceClient {
9811000
}
9821001

9831002
/**
984-
* Equivalent to {@link listKeys}, but returns a NodeJS Stream object.
985-
*
986-
* This fetches the paged responses for {@link listKeys} continuously
987-
* and invokes the callback registered for 'data' event for each element in the
988-
* responses.
989-
*
990-
* The returned object has 'end' method when no more elements are required.
991-
*
992-
* autoPaginate option will be ignored.
993-
*
994-
* @see {@link https://nodejs.org/api/stream.html}
995-
*
1003+
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
9961004
* @param {Object} request
9971005
* The request object that will be sent.
9981006
* @param {string} request.parent
@@ -1008,6 +1016,13 @@ export class RecaptchaEnterpriseServiceClient {
10081016
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
10091017
* @returns {Stream}
10101018
* An object stream which emits an object representing [Key]{@link google.cloud.recaptchaenterprise.v1.Key} on 'data' event.
1019+
* The client library will perform auto-pagination by default: it will call the API as many
1020+
* times as needed. Note that it can affect your quota.
1021+
* We recommend using `listKeysAsync()`
1022+
* method described below for async iteration which you can stop as needed.
1023+
* Please see the
1024+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
1025+
* for more details and examples.
10111026
*/
10121027
listKeysStream(
10131028
request?: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest,
@@ -1032,10 +1047,9 @@ export class RecaptchaEnterpriseServiceClient {
10321047
}
10331048

10341049
/**
1035-
* Equivalent to {@link listKeys}, but returns an iterable object.
1036-
*
1037-
* for-await-of syntax is used with the iterable to recursively get response element on-demand.
1050+
* Equivalent to `listKeys`, but returns an iterable object.
10381051
*
1052+
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
10391053
* @param {Object} request
10401054
* The request object that will be sent.
10411055
* @param {string} request.parent
@@ -1050,7 +1064,18 @@ export class RecaptchaEnterpriseServiceClient {
10501064
* @param {object} [options]
10511065
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
10521066
* @returns {Object}
1053-
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
1067+
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
1068+
* When you iterate the returned iterable, each element will be an object representing
1069+
* [Key]{@link google.cloud.recaptchaenterprise.v1.Key}. The API will be called under the hood as needed, once per the page,
1070+
* so you can stop the iteration when you don't need more results.
1071+
* Please see the
1072+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
1073+
* for more details and examples.
1074+
* @example
1075+
* const iterable = client.listKeysAsync(request);
1076+
* for await (const response of iterable) {
1077+
* // process response
1078+
* }
10541079
*/
10551080
listKeysAsync(
10561081
request?: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest,
@@ -1176,9 +1201,10 @@ export class RecaptchaEnterpriseServiceClient {
11761201
}
11771202

11781203
/**
1179-
* Terminate the GRPC channel and close the client.
1204+
* Terminate the gRPC channel and close the client.
11801205
*
11811206
* The client will no longer be usable and all future behavior is undefined.
1207+
* @returns {Promise} A promise that resolves when the client is closed.
11821208
*/
11831209
close(): Promise<void> {
11841210
this.initialize();

0 commit comments

Comments
 (0)