CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-googleapis-common

A common tooling library that provides standardized interfaces for Google APIs client libraries including authentication, request handling, and HTTP/2 support.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Google APIs Common

Google APIs Common is a TypeScript npm library that provides essential tooling and utilities for Google APIs Node.js client libraries. It serves as a foundational layer that re-exports key dependencies (google-auth-library and gaxios) while providing standardized interfaces for API interactions, authentication, request handling, and HTTP/2 support.

Package Information

  • Package Name: googleapis-common
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install googleapis-common

Core Imports

import { 
  GoogleAuth, 
  OAuth2Client, 
  createAPIRequest, 
  AuthPlus 
} from "googleapis-common";

For CommonJS:

const { 
  GoogleAuth, 
  OAuth2Client, 
  createAPIRequest, 
  AuthPlus 
} = require("googleapis-common");

Basic Usage

import { 
  GoogleAuth, 
  createAPIRequest, 
  APIRequestContext,
  MethodOptions 
} from "googleapis-common";

// Set up authentication
const auth = new GoogleAuth({
  scopes: ['https://www.googleapis.com/auth/cloud-platform']
});

// Create API request context
const context: APIRequestContext = {
  _options: {
    auth: auth
  }
};

// Make an API request
const response = await createAPIRequest({
  options: { url: 'https://example.googleapis.com/v1/resource' } as MethodOptions,
  params: {},
  requiredParams: [],
  pathParams: [],
  context: context
});

Architecture

Google APIs Common is built around several key components:

  • Re-exported Dependencies: Direct access to google-auth-library and gaxios functionality
  • API Request System: Centralized request creation with authentication, retry logic, and HTTP/2 support
  • Authentication Layer: Enhanced authentication classes with memoization and project ID management
  • Discovery System: Dynamic API endpoint generation from Google API schemas
  • Type System: Comprehensive TypeScript definitions for Google API patterns
  • HTTP/2 Support: Native HTTP/2 client implementation for improved performance

Capabilities

Authentication

Enhanced authentication system built on google-auth-library with additional features for Google API client libraries.

class AuthPlus extends GoogleAuth {
  JWT: typeof JWT;
  Compute: typeof Compute;
  OAuth2: typeof OAuth2Client;
  GoogleAuth: typeof GoogleAuth;
  AwsClient: typeof AwsClient;
  IdentityPoolClient: typeof IdentityPoolClient;
  ExternalAccountClient: typeof ExternalAccountClient;
  
  getClient(options?: GoogleAuthOptions): Promise<Compute | JWT | UserRefreshClient | BaseExternalAccountClient | Impersonated>;
  getProjectId(): Promise<string>;
  getProjectId(callback: ProjectIdCallback): void;
}

Authentication

API Request Creation

Core request creation functionality for Google APIs with built-in authentication, retry logic, and HTTP/2 support.

function createAPIRequest<T>(
  parameters: APIRequestParams<T>,
  callback?: BodyResponseCallback<T>
): GaxiosPromise<T>;

interface APIRequestParams<T = any> {
  options: MethodOptions;
  params: T;
  requiredParams: string[];
  pathParams: string[];
  context: APIRequestContext;
  mediaUrl?: string | null;
}

API Requests

Re-exported Dependencies

Direct access to google-auth-library and gaxios functionality for authentication and HTTP operations.

// google-auth-library exports
const googleAuthLibrary: typeof import('google-auth-library');
class OAuth2Client extends import('google-auth-library').OAuth2Client {}
class JWT extends import('google-auth-library').JWT {}
class Compute extends import('google-auth-library').Compute {}
class GoogleAuth extends import('google-auth-library').GoogleAuth {}

// gaxios exports  
const gaxios: typeof import('gaxios');
class Gaxios extends import('gaxios').Gaxios {}
class GaxiosError extends import('gaxios').GaxiosError {}
interface GaxiosOptions extends import('gaxios').GaxiosOptions {}
interface GaxiosResponse<T> extends import('gaxios').GaxiosResponse<T> {}

Re-exported Dependencies

Discovery and Schemas

API discovery system for dynamically generating client endpoints from Google API schemas.

class Discovery {
  constructor(options: DiscoveryOptions);
  discoverAPI(apiDiscoveryUrl: string | {url?: string}): Promise<EndpointCreator>;
  discoverAllAPIs(discoveryUrl: string): Promise<{}>;
}

function getAPI<T>(
  api: string,
  options: ServiceOptions | string,
  versions: {[index: string]: any},
  context?: GoogleConfigurable
): T;

Discovery and Schemas

HTTP/2 Support

Native HTTP/2 client implementation providing improved performance for Google API requests.

interface GaxiosResponseWithHTTP2<T = any> extends GaxiosResponse<T> {
  headers: Record<string, string>;
}

const sessions: {[index: string]: SessionData};
interface SessionData {
  session: http2.ClientHttp2Session;
  timeoutHandle?: NodeJS.Timeout;
}

HTTP/2 Support

Utilities

Helper functions for header manipulation, response marshalling, and browser detection.

type HeadersInit = ConstructorParameters<typeof Headers>[0];

function headersToClassicHeaders<T extends Record<string, string>>(
  headers: HeadersInit
): T;

function marshallGaxiosResponse<T extends GaxiosResponse>(
  res?: T
): GaxiosResponseWithHTTP2;

Utilities

Core Types

API Context and Options

interface APIRequestContext {
  google?: GoogleConfigurable;
  _options: GlobalOptions;
}

interface GoogleConfigurable {
  _options: GlobalOptions;
}

interface GlobalOptions extends MethodOptions {
  auth?: GoogleAuth | OAuth2Client | BaseExternalAccountClient | string;
  universeDomain?: string;
  universe_domain?: string;
}

interface MethodOptions extends GaxiosOptions {
  apiVersion?: string;
  rootUrl?: string;
  http2?: boolean;
  userAgentDirectives?: UserAgentDirective[];
}

interface ServiceOptions extends GlobalOptions {
  version?: string;
}

Response Types

type BodyResponseCallback<T> = (
  err: Error | null,
  res?: GaxiosResponseWithHTTP2<T> | null
) => void;

type APIEndpoint = Readonly<Endpoint & any>;

interface UserAgentDirective {
  product: string;
  version: string;
  comment?: string;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/googleapis-common@8.0.x
Publish Source
CLI
Badge
tessl/npm-googleapis-common badge