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

Commit fb28879

Browse files
fix(browser): check for fetch on window (#718)
1 parent e0d9fa6 commit fb28879

18 files changed

+2290
-636
lines changed

protos/protos.json

Lines changed: 1619 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/v2/agents_client.ts

Lines changed: 59 additions & 51 deletions
Large diffs are not rendered by default.

src/v2/contexts_client.ts

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// ** https://github.com/googleapis/gapic-generator-typescript **
1717
// ** All changes to this file may be overwritten. **
1818

19+
/* global window */
1920
import * as gax from 'google-gax';
2021
import {
2122
Callback,
@@ -30,6 +31,11 @@ import * as path from 'path';
3031
import {Transform} from 'stream';
3132
import {RequestType} from 'google-gax/build/src/apitypes';
3233
import * as protos from '../../protos/protos';
34+
/**
35+
* Client JSON configuration object, loaded from
36+
* `src/v2/contexts_client_config.json`.
37+
* This file defines retry strategy and timeouts for all API methods in this library.
38+
*/
3339
import * as gapicConfig from './contexts_client_config.json';
3440

3541
const version = require('../../../package.json').version;
@@ -83,9 +89,9 @@ export class ContextsClient {
8389
* your project ID will be detected automatically.
8490
* @param {string} [options.apiEndpoint] - The domain name of the
8591
* 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.
92+
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
93+
* Follows the structure of {@link gapicConfig}.
94+
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
8995
* In fallback mode, a special browser-compatible transport implementation is used
9096
* instead of gRPC transport. In browser context (if the `window` object is defined)
9197
* the fallback mode is enabled automatically; set `options.fallback` to `false`
@@ -98,7 +104,9 @@ export class ContextsClient {
98104
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
99105
const port = opts?.port || staticMembers.port;
100106
const clientConfig = opts?.clientConfig ?? {};
101-
const fallback = opts?.fallback ?? typeof window !== 'undefined';
107+
const fallback =
108+
opts?.fallback ??
109+
(typeof window !== 'undefined' && typeof window?.fetch === 'function');
102110
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
103111

104112
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
@@ -339,7 +347,7 @@ export class ContextsClient {
339347
// -------------------
340348
getContext(
341349
request: protos.google.cloud.dialogflow.v2.IGetContextRequest,
342-
options?: gax.CallOptions
350+
options?: CallOptions
343351
): Promise<
344352
[
345353
protos.google.cloud.dialogflow.v2.IContext,
@@ -349,7 +357,7 @@ export class ContextsClient {
349357
>;
350358
getContext(
351359
request: protos.google.cloud.dialogflow.v2.IGetContextRequest,
352-
options: gax.CallOptions,
360+
options: CallOptions,
353361
callback: Callback<
354362
protos.google.cloud.dialogflow.v2.IContext,
355363
protos.google.cloud.dialogflow.v2.IGetContextRequest | null | undefined,
@@ -389,7 +397,7 @@ export class ContextsClient {
389397
getContext(
390398
request: protos.google.cloud.dialogflow.v2.IGetContextRequest,
391399
optionsOrCallback?:
392-
| gax.CallOptions
400+
| CallOptions
393401
| Callback<
394402
protos.google.cloud.dialogflow.v2.IContext,
395403
| protos.google.cloud.dialogflow.v2.IGetContextRequest
@@ -410,12 +418,12 @@ export class ContextsClient {
410418
]
411419
> | void {
412420
request = request || {};
413-
let options: gax.CallOptions;
421+
let options: CallOptions;
414422
if (typeof optionsOrCallback === 'function' && callback === undefined) {
415423
callback = optionsOrCallback;
416424
options = {};
417425
} else {
418-
options = optionsOrCallback as gax.CallOptions;
426+
options = optionsOrCallback as CallOptions;
419427
}
420428
options = options || {};
421429
options.otherArgs = options.otherArgs || {};
@@ -430,7 +438,7 @@ export class ContextsClient {
430438
}
431439
createContext(
432440
request: protos.google.cloud.dialogflow.v2.ICreateContextRequest,
433-
options?: gax.CallOptions
441+
options?: CallOptions
434442
): Promise<
435443
[
436444
protos.google.cloud.dialogflow.v2.IContext,
@@ -440,7 +448,7 @@ export class ContextsClient {
440448
>;
441449
createContext(
442450
request: protos.google.cloud.dialogflow.v2.ICreateContextRequest,
443-
options: gax.CallOptions,
451+
options: CallOptions,
444452
callback: Callback<
445453
protos.google.cloud.dialogflow.v2.IContext,
446454
| protos.google.cloud.dialogflow.v2.ICreateContextRequest
@@ -488,7 +496,7 @@ export class ContextsClient {
488496
createContext(
489497
request: protos.google.cloud.dialogflow.v2.ICreateContextRequest,
490498
optionsOrCallback?:
491-
| gax.CallOptions
499+
| CallOptions
492500
| Callback<
493501
protos.google.cloud.dialogflow.v2.IContext,
494502
| protos.google.cloud.dialogflow.v2.ICreateContextRequest
@@ -511,12 +519,12 @@ export class ContextsClient {
511519
]
512520
> | void {
513521
request = request || {};
514-
let options: gax.CallOptions;
522+
let options: CallOptions;
515523
if (typeof optionsOrCallback === 'function' && callback === undefined) {
516524
callback = optionsOrCallback;
517525
options = {};
518526
} else {
519-
options = optionsOrCallback as gax.CallOptions;
527+
options = optionsOrCallback as CallOptions;
520528
}
521529
options = options || {};
522530
options.otherArgs = options.otherArgs || {};
@@ -531,7 +539,7 @@ export class ContextsClient {
531539
}
532540
updateContext(
533541
request: protos.google.cloud.dialogflow.v2.IUpdateContextRequest,
534-
options?: gax.CallOptions
542+
options?: CallOptions
535543
): Promise<
536544
[
537545
protos.google.cloud.dialogflow.v2.IContext,
@@ -541,7 +549,7 @@ export class ContextsClient {
541549
>;
542550
updateContext(
543551
request: protos.google.cloud.dialogflow.v2.IUpdateContextRequest,
544-
options: gax.CallOptions,
552+
options: CallOptions,
545553
callback: Callback<
546554
protos.google.cloud.dialogflow.v2.IContext,
547555
| protos.google.cloud.dialogflow.v2.IUpdateContextRequest
@@ -582,7 +590,7 @@ export class ContextsClient {
582590
updateContext(
583591
request: protos.google.cloud.dialogflow.v2.IUpdateContextRequest,
584592
optionsOrCallback?:
585-
| gax.CallOptions
593+
| CallOptions
586594
| Callback<
587595
protos.google.cloud.dialogflow.v2.IContext,
588596
| protos.google.cloud.dialogflow.v2.IUpdateContextRequest
@@ -605,12 +613,12 @@ export class ContextsClient {
605613
]
606614
> | void {
607615
request = request || {};
608-
let options: gax.CallOptions;
616+
let options: CallOptions;
609617
if (typeof optionsOrCallback === 'function' && callback === undefined) {
610618
callback = optionsOrCallback;
611619
options = {};
612620
} else {
613-
options = optionsOrCallback as gax.CallOptions;
621+
options = optionsOrCallback as CallOptions;
614622
}
615623
options = options || {};
616624
options.otherArgs = options.otherArgs || {};
@@ -625,7 +633,7 @@ export class ContextsClient {
625633
}
626634
deleteContext(
627635
request: protos.google.cloud.dialogflow.v2.IDeleteContextRequest,
628-
options?: gax.CallOptions
636+
options?: CallOptions
629637
): Promise<
630638
[
631639
protos.google.protobuf.IEmpty,
@@ -635,7 +643,7 @@ export class ContextsClient {
635643
>;
636644
deleteContext(
637645
request: protos.google.cloud.dialogflow.v2.IDeleteContextRequest,
638-
options: gax.CallOptions,
646+
options: CallOptions,
639647
callback: Callback<
640648
protos.google.protobuf.IEmpty,
641649
| protos.google.cloud.dialogflow.v2.IDeleteContextRequest
@@ -679,7 +687,7 @@ export class ContextsClient {
679687
deleteContext(
680688
request: protos.google.cloud.dialogflow.v2.IDeleteContextRequest,
681689
optionsOrCallback?:
682-
| gax.CallOptions
690+
| CallOptions
683691
| Callback<
684692
protos.google.protobuf.IEmpty,
685693
| protos.google.cloud.dialogflow.v2.IDeleteContextRequest
@@ -702,12 +710,12 @@ export class ContextsClient {
702710
]
703711
> | void {
704712
request = request || {};
705-
let options: gax.CallOptions;
713+
let options: CallOptions;
706714
if (typeof optionsOrCallback === 'function' && callback === undefined) {
707715
callback = optionsOrCallback;
708716
options = {};
709717
} else {
710-
options = optionsOrCallback as gax.CallOptions;
718+
options = optionsOrCallback as CallOptions;
711719
}
712720
options = options || {};
713721
options.otherArgs = options.otherArgs || {};
@@ -722,7 +730,7 @@ export class ContextsClient {
722730
}
723731
deleteAllContexts(
724732
request: protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest,
725-
options?: gax.CallOptions
733+
options?: CallOptions
726734
): Promise<
727735
[
728736
protos.google.protobuf.IEmpty,
@@ -732,7 +740,7 @@ export class ContextsClient {
732740
>;
733741
deleteAllContexts(
734742
request: protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest,
735-
options: gax.CallOptions,
743+
options: CallOptions,
736744
callback: Callback<
737745
protos.google.protobuf.IEmpty,
738746
| protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest
@@ -776,7 +784,7 @@ export class ContextsClient {
776784
deleteAllContexts(
777785
request: protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest,
778786
optionsOrCallback?:
779-
| gax.CallOptions
787+
| CallOptions
780788
| Callback<
781789
protos.google.protobuf.IEmpty,
782790
| protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest
@@ -799,12 +807,12 @@ export class ContextsClient {
799807
]
800808
> | void {
801809
request = request || {};
802-
let options: gax.CallOptions;
810+
let options: CallOptions;
803811
if (typeof optionsOrCallback === 'function' && callback === undefined) {
804812
callback = optionsOrCallback;
805813
options = {};
806814
} else {
807-
options = optionsOrCallback as gax.CallOptions;
815+
options = optionsOrCallback as CallOptions;
808816
}
809817
options = options || {};
810818
options.otherArgs = options.otherArgs || {};
@@ -820,7 +828,7 @@ export class ContextsClient {
820828

821829
listContexts(
822830
request: protos.google.cloud.dialogflow.v2.IListContextsRequest,
823-
options?: gax.CallOptions
831+
options?: CallOptions
824832
): Promise<
825833
[
826834
protos.google.cloud.dialogflow.v2.IContext[],
@@ -830,7 +838,7 @@ export class ContextsClient {
830838
>;
831839
listContexts(
832840
request: protos.google.cloud.dialogflow.v2.IListContextsRequest,
833-
options: gax.CallOptions,
841+
options: CallOptions,
834842
callback: PaginationCallback<
835843
protos.google.cloud.dialogflow.v2.IListContextsRequest,
836844
| protos.google.cloud.dialogflow.v2.IListContextsResponse
@@ -882,7 +890,7 @@ export class ContextsClient {
882890
listContexts(
883891
request: protos.google.cloud.dialogflow.v2.IListContextsRequest,
884892
optionsOrCallback?:
885-
| gax.CallOptions
893+
| CallOptions
886894
| PaginationCallback<
887895
protos.google.cloud.dialogflow.v2.IListContextsRequest,
888896
| protos.google.cloud.dialogflow.v2.IListContextsResponse
@@ -905,12 +913,12 @@ export class ContextsClient {
905913
]
906914
> | void {
907915
request = request || {};
908-
let options: gax.CallOptions;
916+
let options: CallOptions;
909917
if (typeof optionsOrCallback === 'function' && callback === undefined) {
910918
callback = optionsOrCallback;
911919
options = {};
912920
} else {
913-
options = optionsOrCallback as gax.CallOptions;
921+
options = optionsOrCallback as CallOptions;
914922
}
915923
options = options || {};
916924
options.otherArgs = options.otherArgs || {};
@@ -954,7 +962,7 @@ export class ContextsClient {
954962
*/
955963
listContextsStream(
956964
request?: protos.google.cloud.dialogflow.v2.IListContextsRequest,
957-
options?: gax.CallOptions
965+
options?: CallOptions
958966
): Transform {
959967
request = request || {};
960968
options = options || {};
@@ -1010,7 +1018,7 @@ export class ContextsClient {
10101018
*/
10111019
listContextsAsync(
10121020
request?: protos.google.cloud.dialogflow.v2.IListContextsRequest,
1013-
options?: gax.CallOptions
1021+
options?: CallOptions
10141022
): AsyncIterable<protos.google.cloud.dialogflow.v2.IContext> {
10151023
request = request || {};
10161024
options = options || {};

0 commit comments

Comments
 (0)