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

Commit b7b016e

Browse files
fix(browser): check for fetch on window (#131)
1 parent dccd43e commit b7b016e

File tree

4 files changed

+182
-47
lines changed

4 files changed

+182
-47
lines changed

protos/protos.json

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

src/v1beta2/document_understanding_service_client.ts

Lines changed: 22 additions & 14 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,
@@ -27,6 +28,11 @@ import {
2728
import * as path from 'path';
2829

2930
import * as protos from '../../protos/protos';
31+
/**
32+
* Client JSON configuration object, loaded from
33+
* `src/v1beta2/document_understanding_service_client_config.json`.
34+
* This file defines retry strategy and timeouts for all API methods in this library.
35+
*/
3036
import * as gapicConfig from './document_understanding_service_client_config.json';
3137
import {operationsProtos} from 'google-gax';
3238
const version = require('../../../package.json').version;
@@ -82,9 +88,9 @@ export class DocumentUnderstandingServiceClient {
8288
* your project ID will be detected automatically.
8389
* @param {string} [options.apiEndpoint] - The domain name of the
8490
* API remote host.
85-
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
86-
* TODO(@alexander-fenster): link to gax documentation.
87-
* @param {boolean} fallback - Use HTTP fallback mode.
91+
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
92+
* Follows the structure of {@link gapicConfig}.
93+
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
8894
* In fallback mode, a special browser-compatible transport implementation is used
8995
* instead of gRPC transport. In browser context (if the `window` object is defined)
9096
* the fallback mode is enabled automatically; set `options.fallback` to `false`
@@ -98,7 +104,9 @@ export class DocumentUnderstandingServiceClient {
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 set scopes.
@@ -314,7 +322,7 @@ export class DocumentUnderstandingServiceClient {
314322
// -------------------
315323
processDocument(
316324
request: protos.google.cloud.documentai.v1beta2.IProcessDocumentRequest,
317-
options?: gax.CallOptions
325+
options?: CallOptions
318326
): Promise<
319327
[
320328
protos.google.cloud.documentai.v1beta2.IDocument,
@@ -327,7 +335,7 @@ export class DocumentUnderstandingServiceClient {
327335
>;
328336
processDocument(
329337
request: protos.google.cloud.documentai.v1beta2.IProcessDocumentRequest,
330-
options: gax.CallOptions,
338+
options: CallOptions,
331339
callback: Callback<
332340
protos.google.cloud.documentai.v1beta2.IDocument,
333341
| protos.google.cloud.documentai.v1beta2.IProcessDocumentRequest
@@ -395,7 +403,7 @@ export class DocumentUnderstandingServiceClient {
395403
processDocument(
396404
request: protos.google.cloud.documentai.v1beta2.IProcessDocumentRequest,
397405
optionsOrCallback?:
398-
| gax.CallOptions
406+
| CallOptions
399407
| Callback<
400408
protos.google.cloud.documentai.v1beta2.IDocument,
401409
| protos.google.cloud.documentai.v1beta2.IProcessDocumentRequest
@@ -421,12 +429,12 @@ export class DocumentUnderstandingServiceClient {
421429
]
422430
> | void {
423431
request = request || {};
424-
let options: gax.CallOptions;
432+
let options: CallOptions;
425433
if (typeof optionsOrCallback === 'function' && callback === undefined) {
426434
callback = optionsOrCallback;
427435
options = {};
428436
} else {
429-
options = optionsOrCallback as gax.CallOptions;
437+
options = optionsOrCallback as CallOptions;
430438
}
431439
options = options || {};
432440
options.otherArgs = options.otherArgs || {};
@@ -442,7 +450,7 @@ export class DocumentUnderstandingServiceClient {
442450

443451
batchProcessDocuments(
444452
request: protos.google.cloud.documentai.v1beta2.IBatchProcessDocumentsRequest,
445-
options?: gax.CallOptions
453+
options?: CallOptions
446454
): Promise<
447455
[
448456
LROperation<
@@ -455,7 +463,7 @@ export class DocumentUnderstandingServiceClient {
455463
>;
456464
batchProcessDocuments(
457465
request: protos.google.cloud.documentai.v1beta2.IBatchProcessDocumentsRequest,
458-
options: gax.CallOptions,
466+
options: CallOptions,
459467
callback: Callback<
460468
LROperation<
461469
protos.google.cloud.documentai.v1beta2.IBatchProcessDocumentsResponse,
@@ -506,7 +514,7 @@ export class DocumentUnderstandingServiceClient {
506514
batchProcessDocuments(
507515
request: protos.google.cloud.documentai.v1beta2.IBatchProcessDocumentsRequest,
508516
optionsOrCallback?:
509-
| gax.CallOptions
517+
| CallOptions
510518
| Callback<
511519
LROperation<
512520
protos.google.cloud.documentai.v1beta2.IBatchProcessDocumentsResponse,
@@ -534,12 +542,12 @@ export class DocumentUnderstandingServiceClient {
534542
]
535543
> | void {
536544
request = request || {};
537-
let options: gax.CallOptions;
545+
let options: CallOptions;
538546
if (typeof optionsOrCallback === 'function' && callback === undefined) {
539547
callback = optionsOrCallback;
540548
options = {};
541549
} else {
542-
options = optionsOrCallback as gax.CallOptions;
550+
options = optionsOrCallback as CallOptions;
543551
}
544552
options = options || {};
545553
options.otherArgs = options.otherArgs || {};

0 commit comments

Comments
 (0)