Skip to content

Commit

Permalink
fix(browser): check for fetch on window (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Nov 23, 2020
1 parent 3b0b935 commit f0ee9e1
Show file tree
Hide file tree
Showing 8 changed files with 833 additions and 323 deletions.
554 changes: 509 additions & 45 deletions packages/google-cloud-monitoring/protos/protos.json

Large diffs are not rendered by default.

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/v3/alert_policy_service_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './alert_policy_service_client_config.json';

const version = require('../../../package.json').version;
Expand Down Expand Up @@ -91,9 +97,9 @@ export class AlertPolicyServiceClient {
* 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 @@ -106,7 +112,9 @@ export class AlertPolicyServiceClient {
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 @@ -392,7 +400,7 @@ export class AlertPolicyServiceClient {
// -------------------
getAlertPolicy(
request: protos.google.monitoring.v3.IGetAlertPolicyRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.monitoring.v3.IAlertPolicy,
Expand All @@ -402,7 +410,7 @@ export class AlertPolicyServiceClient {
>;
getAlertPolicy(
request: protos.google.monitoring.v3.IGetAlertPolicyRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.monitoring.v3.IAlertPolicy,
protos.google.monitoring.v3.IGetAlertPolicyRequest | null | undefined,
Expand Down Expand Up @@ -439,7 +447,7 @@ export class AlertPolicyServiceClient {
getAlertPolicy(
request: protos.google.monitoring.v3.IGetAlertPolicyRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.monitoring.v3.IAlertPolicy,
protos.google.monitoring.v3.IGetAlertPolicyRequest | null | undefined,
Expand All @@ -458,12 +466,12 @@ export class AlertPolicyServiceClient {
]
> | 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 @@ -478,7 +486,7 @@ export class AlertPolicyServiceClient {
}
createAlertPolicy(
request: protos.google.monitoring.v3.ICreateAlertPolicyRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.monitoring.v3.IAlertPolicy,
Expand All @@ -488,7 +496,7 @@ export class AlertPolicyServiceClient {
>;
createAlertPolicy(
request: protos.google.monitoring.v3.ICreateAlertPolicyRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.monitoring.v3.IAlertPolicy,
protos.google.monitoring.v3.ICreateAlertPolicyRequest | null | undefined,
Expand Down Expand Up @@ -536,7 +544,7 @@ export class AlertPolicyServiceClient {
createAlertPolicy(
request: protos.google.monitoring.v3.ICreateAlertPolicyRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.monitoring.v3.IAlertPolicy,
| protos.google.monitoring.v3.ICreateAlertPolicyRequest
Expand All @@ -557,12 +565,12 @@ export class AlertPolicyServiceClient {
]
> | 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 @@ -577,7 +585,7 @@ export class AlertPolicyServiceClient {
}
deleteAlertPolicy(
request: protos.google.monitoring.v3.IDeleteAlertPolicyRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.protobuf.IEmpty,
Expand All @@ -587,7 +595,7 @@ export class AlertPolicyServiceClient {
>;
deleteAlertPolicy(
request: protos.google.monitoring.v3.IDeleteAlertPolicyRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.protobuf.IEmpty,
protos.google.monitoring.v3.IDeleteAlertPolicyRequest | null | undefined,
Expand Down Expand Up @@ -626,7 +634,7 @@ export class AlertPolicyServiceClient {
deleteAlertPolicy(
request: protos.google.monitoring.v3.IDeleteAlertPolicyRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.protobuf.IEmpty,
| protos.google.monitoring.v3.IDeleteAlertPolicyRequest
Expand All @@ -647,12 +655,12 @@ export class AlertPolicyServiceClient {
]
> | 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 @@ -667,7 +675,7 @@ export class AlertPolicyServiceClient {
}
updateAlertPolicy(
request: protos.google.monitoring.v3.IUpdateAlertPolicyRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.monitoring.v3.IAlertPolicy,
Expand All @@ -677,7 +685,7 @@ export class AlertPolicyServiceClient {
>;
updateAlertPolicy(
request: protos.google.monitoring.v3.IUpdateAlertPolicyRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.monitoring.v3.IAlertPolicy,
protos.google.monitoring.v3.IUpdateAlertPolicyRequest | null | undefined,
Expand Down Expand Up @@ -740,7 +748,7 @@ export class AlertPolicyServiceClient {
updateAlertPolicy(
request: protos.google.monitoring.v3.IUpdateAlertPolicyRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.monitoring.v3.IAlertPolicy,
| protos.google.monitoring.v3.IUpdateAlertPolicyRequest
Expand All @@ -761,12 +769,12 @@ export class AlertPolicyServiceClient {
]
> | 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 @@ -782,7 +790,7 @@ export class AlertPolicyServiceClient {

listAlertPolicies(
request: protos.google.monitoring.v3.IListAlertPoliciesRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.monitoring.v3.IAlertPolicy[],
Expand All @@ -792,7 +800,7 @@ export class AlertPolicyServiceClient {
>;
listAlertPolicies(
request: protos.google.monitoring.v3.IListAlertPoliciesRequest,
options: gax.CallOptions,
options: CallOptions,
callback: PaginationCallback<
protos.google.monitoring.v3.IListAlertPoliciesRequest,
protos.google.monitoring.v3.IListAlertPoliciesResponse | null | undefined,
Expand Down Expand Up @@ -857,7 +865,7 @@ export class AlertPolicyServiceClient {
listAlertPolicies(
request: protos.google.monitoring.v3.IListAlertPoliciesRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| PaginationCallback<
protos.google.monitoring.v3.IListAlertPoliciesRequest,
| protos.google.monitoring.v3.IListAlertPoliciesResponse
Expand All @@ -878,12 +886,12 @@ export class AlertPolicyServiceClient {
]
> | 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 @@ -944,7 +952,7 @@ export class AlertPolicyServiceClient {
*/
listAlertPoliciesStream(
request?: protos.google.monitoring.v3.IListAlertPoliciesRequest,
options?: gax.CallOptions
options?: CallOptions
): Transform {
request = request || {};
options = options || {};
Expand Down Expand Up @@ -1017,7 +1025,7 @@ export class AlertPolicyServiceClient {
*/
listAlertPoliciesAsync(
request?: protos.google.monitoring.v3.IListAlertPoliciesRequest,
options?: gax.CallOptions
options?: CallOptions
): AsyncIterable<protos.google.monitoring.v3.IAlertPolicy> {
request = request || {};
options = options || {};
Expand Down
Loading

0 comments on commit f0ee9e1

Please sign in to comment.