Skip to content

Commit

Permalink
fix(browser): check for fetch on window (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Nov 23, 2020
1 parent ea8362f commit a80b4de
Show file tree
Hide file tree
Showing 18 changed files with 2,290 additions and 636 deletions.
1,712 changes: 1,619 additions & 93 deletions packages/google-cloud-dialogflow/protos/protos.json

Large diffs are not rendered by default.

110 changes: 59 additions & 51 deletions packages/google-cloud-dialogflow/src/v2/agents_client.ts

Large diffs are not rendered by default.

80 changes: 44 additions & 36 deletions packages/google-cloud-dialogflow/src/v2/contexts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

/* global window */
import * as gax from 'google-gax';
import {
Callback,
Expand All @@ -30,6 +31,11 @@ import * as path from 'path';
import {Transform} from 'stream';
import {RequestType} from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
/**
* Client JSON configuration object, loaded from
* `src/v2/contexts_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './contexts_client_config.json';

const version = require('../../../package.json').version;
Expand Down Expand Up @@ -83,9 +89,9 @@ export class ContextsClient {
* your project ID will be detected automatically.
* @param {string} [options.apiEndpoint] - The domain name of the
* API remote host.
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
* TODO(@alexander-fenster): link to gax documentation.
* @param {boolean} fallback - Use HTTP fallback mode.
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
* Follows the structure of {@link gapicConfig}.
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
Expand All @@ -98,7 +104,9 @@ export class ContextsClient {
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
const port = opts?.port || staticMembers.port;
const clientConfig = opts?.clientConfig ?? {};
const fallback = opts?.fallback ?? typeof window !== 'undefined';
const fallback =
opts?.fallback ??
(typeof window !== 'undefined' && typeof window?.fetch === 'function');
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);

// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
Expand Down Expand Up @@ -339,7 +347,7 @@ export class ContextsClient {
// -------------------
getContext(
request: protos.google.cloud.dialogflow.v2.IGetContextRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.dialogflow.v2.IContext,
Expand All @@ -349,7 +357,7 @@ export class ContextsClient {
>;
getContext(
request: protos.google.cloud.dialogflow.v2.IGetContextRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.dialogflow.v2.IContext,
protos.google.cloud.dialogflow.v2.IGetContextRequest | null | undefined,
Expand Down Expand Up @@ -389,7 +397,7 @@ export class ContextsClient {
getContext(
request: protos.google.cloud.dialogflow.v2.IGetContextRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.dialogflow.v2.IContext,
| protos.google.cloud.dialogflow.v2.IGetContextRequest
Expand All @@ -410,12 +418,12 @@ export class ContextsClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand All @@ -430,7 +438,7 @@ export class ContextsClient {
}
createContext(
request: protos.google.cloud.dialogflow.v2.ICreateContextRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.dialogflow.v2.IContext,
Expand All @@ -440,7 +448,7 @@ export class ContextsClient {
>;
createContext(
request: protos.google.cloud.dialogflow.v2.ICreateContextRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.dialogflow.v2.IContext,
| protos.google.cloud.dialogflow.v2.ICreateContextRequest
Expand Down Expand Up @@ -488,7 +496,7 @@ export class ContextsClient {
createContext(
request: protos.google.cloud.dialogflow.v2.ICreateContextRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.dialogflow.v2.IContext,
| protos.google.cloud.dialogflow.v2.ICreateContextRequest
Expand All @@ -511,12 +519,12 @@ export class ContextsClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand All @@ -531,7 +539,7 @@ export class ContextsClient {
}
updateContext(
request: protos.google.cloud.dialogflow.v2.IUpdateContextRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.dialogflow.v2.IContext,
Expand All @@ -541,7 +549,7 @@ export class ContextsClient {
>;
updateContext(
request: protos.google.cloud.dialogflow.v2.IUpdateContextRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.dialogflow.v2.IContext,
| protos.google.cloud.dialogflow.v2.IUpdateContextRequest
Expand Down Expand Up @@ -582,7 +590,7 @@ export class ContextsClient {
updateContext(
request: protos.google.cloud.dialogflow.v2.IUpdateContextRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.dialogflow.v2.IContext,
| protos.google.cloud.dialogflow.v2.IUpdateContextRequest
Expand All @@ -605,12 +613,12 @@ export class ContextsClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand All @@ -625,7 +633,7 @@ export class ContextsClient {
}
deleteContext(
request: protos.google.cloud.dialogflow.v2.IDeleteContextRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.protobuf.IEmpty,
Expand All @@ -635,7 +643,7 @@ export class ContextsClient {
>;
deleteContext(
request: protos.google.cloud.dialogflow.v2.IDeleteContextRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.protobuf.IEmpty,
| protos.google.cloud.dialogflow.v2.IDeleteContextRequest
Expand Down Expand Up @@ -679,7 +687,7 @@ export class ContextsClient {
deleteContext(
request: protos.google.cloud.dialogflow.v2.IDeleteContextRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.protobuf.IEmpty,
| protos.google.cloud.dialogflow.v2.IDeleteContextRequest
Expand All @@ -702,12 +710,12 @@ export class ContextsClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand All @@ -722,7 +730,7 @@ export class ContextsClient {
}
deleteAllContexts(
request: protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.protobuf.IEmpty,
Expand All @@ -732,7 +740,7 @@ export class ContextsClient {
>;
deleteAllContexts(
request: protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.protobuf.IEmpty,
| protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest
Expand Down Expand Up @@ -776,7 +784,7 @@ export class ContextsClient {
deleteAllContexts(
request: protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.protobuf.IEmpty,
| protos.google.cloud.dialogflow.v2.IDeleteAllContextsRequest
Expand All @@ -799,12 +807,12 @@ export class ContextsClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand All @@ -820,7 +828,7 @@ export class ContextsClient {

listContexts(
request: protos.google.cloud.dialogflow.v2.IListContextsRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.dialogflow.v2.IContext[],
Expand All @@ -830,7 +838,7 @@ export class ContextsClient {
>;
listContexts(
request: protos.google.cloud.dialogflow.v2.IListContextsRequest,
options: gax.CallOptions,
options: CallOptions,
callback: PaginationCallback<
protos.google.cloud.dialogflow.v2.IListContextsRequest,
| protos.google.cloud.dialogflow.v2.IListContextsResponse
Expand Down Expand Up @@ -882,7 +890,7 @@ export class ContextsClient {
listContexts(
request: protos.google.cloud.dialogflow.v2.IListContextsRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| PaginationCallback<
protos.google.cloud.dialogflow.v2.IListContextsRequest,
| protos.google.cloud.dialogflow.v2.IListContextsResponse
Expand All @@ -905,12 +913,12 @@ export class ContextsClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand Down Expand Up @@ -954,7 +962,7 @@ export class ContextsClient {
*/
listContextsStream(
request?: protos.google.cloud.dialogflow.v2.IListContextsRequest,
options?: gax.CallOptions
options?: CallOptions
): Transform {
request = request || {};
options = options || {};
Expand Down Expand Up @@ -1010,7 +1018,7 @@ export class ContextsClient {
*/
listContextsAsync(
request?: protos.google.cloud.dialogflow.v2.IListContextsRequest,
options?: gax.CallOptions
options?: CallOptions
): AsyncIterable<protos.google.cloud.dialogflow.v2.IContext> {
request = request || {};
options = options || {};
Expand Down
Loading

0 comments on commit a80b4de

Please sign in to comment.