New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/synthetics-sdk-api

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/synthetics-sdk-api

NodeJS distribution of the API Specification that must be complied with for integrating with Google Cloud Monitoring Synthetics

  • 0.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

npm version

Synthetics SDK API

Note: This is an experimental package under active development. New releases may include breaking changes.

Installation

npm install --save @google-cloud/synthetics-sdk-api

Usage With Cloud Function V2

Google Cloud Monitoring Synthetics requires a Cloud Function v2 target, and as such, this guide explains how to set up a simple function that uses the @google-cloud/synthetics-sdk-api package.

$ npm init
$ npm install --save @google-cloud/synthetics-sdk-api
$ npm install --save @google-cloud/functions-framework

# This example uses node-fetch for http requests
$ npm install --save node-fetch

Usage With runSyntheticHandler Middleware

This package provides an easy to use express compatible middleware for writing code that is invoked by Google Cloud Monitoring Synthetics. When a user written function is provided to it, a response is sent that may be consumed by Google's services. The following is an example index.js file that can be used as the entrypoint for a cloud function.

// index.js
const assert = require("node:assert");
const functions = require('@google-cloud/functions-framework');
const fetch = require("node-fetch");
const GcmSynthetics = require('@google-cloud/synthetics-sdk-api');

functions.http('SyntheticFunction', GcmSynthetics.runSyntheticHandler(async () => {
  const url = 'https://www.google.com/'; // URL to send the request to
  return await assert.doesNotReject(fetch(url));
}));

Usage Without Framework

As long as a Google Cloud Function exposes an http endpoint that complies with the API spec as defined in the Synthetics SDK API package, the Cloud Function will work as a target for a Synthetic Monitor. As such, this package includes a proto definition that contains the api spec, as well as typescript types that are generated from that proto.

This is predominantly important if you want to run a programmatic workflow for which other SyntheticSDKs are not a good fit, or if you want to use another language for your Google Cloud function for which there is no direct support.

const functions = require('@google-cloud/functions-framework');
const { SyntheticResult, GenericResultV1 } = require('@google-cloud/synthetics-sdk-api');

FAQs

Package last updated on 18 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc