npm package: @maxim_mazurok/gapi.client.servicecontrol-v2
Description: TypeScript typings for Service Control API v2
Author: Maxim Mazurok
Latest version: 0.2.20260220

# TypeScript typings for Service Control API v2

Provides admission control and telemetry reporting for services integrated with Service Infrastructure.
For detailed description please check [documentation](https://cloud.google.com/service-control/).

## Installing

Install typings for Service Control API:

```
npm install @types/gapi.client.servicecontrol-v2 --save-dev
```

## Usage

You need to initialize Google API client in your code:

```typescript
gapi.load('client', () => {
  // now we can use gapi.client
  // ...
});
```

Then load api client wrapper:

```typescript
gapi.client.load(
  'https://servicecontrol.googleapis.com/$discovery/rest?version=v2',
  () => {
    // now we can use:
    // gapi.client.servicecontrol
  },
);
```

```typescript
// Deprecated, use discovery document URL, see https://github.com/google/google-api-javascript-client/blob/master/docs/reference.md#----gapiclientloadname----version----callback--
gapi.client.load('servicecontrol', 'v2', () => {
  // now we can use:
  // gapi.client.servicecontrol
});
```

Don't forget to authenticate your client before sending any request to resources:

```typescript
// declare client_id registered in Google Developers Console
var client_id = '',
  scope = [
    // See, edit, configure, and delete your Google Cloud data and see the email address for your Google Account.
    'https://www.googleapis.com/auth/cloud-platform',

    // Manage your Google Service Control data
    'https://www.googleapis.com/auth/servicecontrol',
  ],
  immediate = true;
// ...

gapi.auth.authorize(
  {client_id: client_id, scope: scope, immediate: immediate},
  authResult => {
    if (authResult && !authResult.error) {
      /* handle successful authorization */
    } else {
      /* handle authorization error */
    }
  },
);
```

After that you can use Service Control API resources: <!-- TODO: make this work for multiple namespaces -->

```typescript
/*
This method provides admission control for services that are integrated with [Service Infrastructure](https://cloud.google.com/service-infrastructure). It checks whether an operation should be allowed based on the service configuration and relevant policies. It must be called before the operation is executed. For more information, see [Admission Control](https://cloud.google.com/service-infrastructure/docs/admission-control). NOTE: The admission control has an expected policy propagation delay of 60s. The caller **must** not depend on the most recent policy changes. NOTE: The admission control has a hard limit of 1 referenced resources per call. If an operation refers to more than 1 resources, the caller must call the Check method multiple times. This method requires the `servicemanagement.services.check` permission on the specified service. For more information, see [Service Control API Access Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
*/
await gapi.client.servicecontrol.services.check({serviceName: 'serviceName'});

/*
This method provides telemetry reporting for services that are integrated with [Service Infrastructure](https://cloud.google.com/service-infrastructure). It reports a list of operations that have occurred on a service. It must be called after the operations have been executed. For more information, see [Telemetry Reporting](https://cloud.google.com/service-infrastructure/docs/telemetry-reporting). NOTE: The telemetry reporting has a hard limit of 100 operations and 1MB per Report call. This method requires the `servicemanagement.services.report` permission on the specified service. For more information, see [Service Control API Access Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
*/
await gapi.client.servicecontrol.services.report({serviceName: 'serviceName'});
```

For provenance information see [Provenance section on NPM](https://www.npmjs.com/package/@maxim_mazurok/gapi.client.servicecontrol-v2#Provenance:~:text=none-,Provenance,-Built%20and%20signed)