@google-cloud/synthetics-sdk-api

中文文档
0.7.0发布于 2025/06/11Apache-2.0TypeScriptCommonJS近 30 天下载 1.7万

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

原始使用文档
文档目录3 节
  1. Usage With Cloud Function V2
  2. Usage With runSyntheticHandler Middleware
  3. Usage Without Framework

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');

Useful Links

版本与发布记录

@google-cloud/synthetics-sdk-api 共发布 10 个版本,首次发布于 2023/06/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.7.0latest2025/06/111.4 年前
0.6.02024/04/182 年前
0.5.12024/01/252 年前
0.5.02023/11/023 年前
0.4.12023/10/253 年前
0.4.02023/10/203 年前

关于 @google-cloud/synthetics-sdk-api 的常见问题

@google-cloud/synthetics-sdk-api 是什么?

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

如何安装 @google-cloud/synthetics-sdk-api?

在项目目录运行 npm install @google-cloud/synthetics-sdk-api,或使用 pnpm add / yarn add / bun add。

@google-cloud/synthetics-sdk-api 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@google-cloud/synthetics-sdk-api 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@google-cloud/synthetics-sdk-api 可以商用吗?

@google-cloud/synthetics-sdk-api 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@google-cloud/synthetics-sdk-api 的下载量有多少?

根据 npm 官方下载统计,@google-cloud/synthetics-sdk-api 在 2026/10/17 – 2026/11/15 这 30 天内被下载 16,593 次,日均约 553 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@google-cloud/synthetics-sdk-api 还在维护吗?

最新版本 0.7.0 发布于 2025/06/11(1.4 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/06/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。