由 gruntsmoke 出售

A dynamically generated Netlify OpenAPI client that works in both Node.js and the browser, enabling authenticated REST calls to all Netlify API operations with minimal setup.
This block provides a typed, OpenAPI-driven HTTP client for the Netlify REST API. It dynamically generates methods from the Netlify OpenAPI specification, handles authentication, request building, retries, and response parsing. The typical buyer is a Node.js or TypeScript backend, CLI tool, or Netlify Build plugin that needs to automate Netlify site, deploy, or DNS management.
index.js — Exports NetlifyAPI, the main client class with constructor, accessToken getter/setter, basePath getter, and getAccessToken for OAuth ticket exchange.open_api.js — Loads and re-exports the raw @netlify/open-api OpenAPI specification object used to drive all method generation.operations.js — Parses the OpenAPI spec into a flat list of operation descriptors (verb, path, parameters) consumed by the method factory.operations.test.js.md — Documentation/test reference for operations (not a runtime file).methods/index.js — Iterates operations and returns an object of async methods keyed by operationId.methods/body.js — Serialises params.body to JSON or streams it for binary endpoints.methods/params.js — Extracts and validates path, query, and header parameters from the caller's params object.methods/response.js — Parses node-fetch responses, throws on HTTP ≥ 400.methods/retry.js — Implements exponential-backoff retry logic with a configurable maximum attempt count.methods/url.js — Builds the final request URL by interpolating path parameters and appending query strings.npm install @netlify/open-api lodash.camelcase node-fetch omit.js p-wait-for qs
No native build steps, pod installs, or prebuild commands are required. This is a pure JavaScript/Node.js package. Node.js 14 or later is recommended because the source uses ES modules (import/export).
Copy the source/ directory into your project, for example at src/netlify-client/.
Ensure your project runs ES modules. In package.json:
{
"type": "module"
}
启动隔离沙箱并在服务器端直接运行 — 无需本地配置。
此版本的 Tetrees AI Review
This JavaScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
管道 avcp-2026-08-04.1 · SHA-256 e21e5fdf675e0c70…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
审查日期 2026年8月4日
将此产品直接导入你的 AI IDE、网页构建器或云端 IDE。
将 Tetrees 连接到兼容的 AI IDE,列出你拥有的产品并获取已验证 ZIP,同时不会开放卖家上传权限。
暂无评价。
Sign in to join the discussion
Loading discussion…
Or, if using TypeScript with CommonJS output, add a loader or use a bundler (esbuild, Rollup) that handles ES module interop.
If using TypeScript, add a path alias in tsconfig.json (optional but convenient):
{
"compilerOptions": {
"paths": {
"@netlify-client": ["./src/netlify-client/index.js"]
}
}
}
Set your Netlify personal access token as an environment variable:
export NETLIFY_ACCESS_TOKEN=your_token_here
Load it in your entry point:
import { NetlifyAPI } from './src/netlify-client/index.js'
const client = new NetlifyAPI(process.env.NETLIFY_ACCESS_TOKEN)
No database migrations, no framework bindings, no additional CLI steps are needed.
class NetlifyAPI {
constructor(accessToken?: string, opts?: {
userAgent?: string
scheme?: string
host?: string
pathPrefix?: string
accessToken?: string
globalParams?: Record<string, unknown>
agent?: unknown // e.g. HttpsProxyAgent
})
constructor(opts: { accessToken?: string; [key: string]: unknown })
get accessToken(): string | null
set accessToken(token: string | null)
get basePath(): string
async getAccessToken(
ticket: { id: string },
opts?: { poll?: number; timeout?: number }
): Promise<string>
// Dynamically generated per OpenAPI operationId, e.g.:
[operationId: string]: (
params?: Record<string, unknown>,
opts?: RequestInit
) => Promise<unknown>
}
The main entry point. Instantiate once per access token and reuse across all API calls. The constructor is variadic: pass a token string alone, an options object alone, or both.
function getOperations(): Array<{
operationId: string
verb: string
path: string
parameters: {
path: Record<string, unknown>
query: Record<string, unknown>
body: Record<string, unknown>
}
[key: string]: unknown
}>
Returns the full list of parsed OpenAPI operations. Useful for introspection, testing, or building tooling on top of the spec without instantiating a client.
function getMethods(opts: {
basePath: string
defaultHeaders: Record<string, string>
agent?: unknown
globalParams?: Record<string, unknown>
}): Record<string, (params?: unknown, opts?: unknown) => Promise<unknown>>
Generates and returns the map of operationId → async function from the parsed operations. Called internally by NetlifyAPI but can be used standalone if you need a bare method map without the class wrapper.
Authenticate with a token, retrieve all sites belonging to the account, and log their names and URLs.
import { NetlifyAPI } from './src/netlify-client/index.js'
const client = new NetlifyAPI(process.env.NETLIFY_ACCESS_TOKEN)
const sites = await client.listSites({ filter: 'all' })
for (const site of sites) {
console.log(site.name, site.ssl_url)
}
Create a new site with a custom subdomain, then deploy a local build directory using a readable stream.
import { NetlifyAPI } from './src/netlify-client/index.js'
import fs from 'fs'
const client = new NetlifyAPI(process.env.NETLIFY_ACCESS_TOKEN)
// Create the site
const site = await client.createSite({
body: {
name: 'my-automated-site',
custom_domain: null,
},
})
console.log('Created site:', site.id)
// Upload a deploy (binary body via stream)
const deploy = await client.createSiteDeploy(
{
site_id: site.id,
body: () => fs.createReadStream('./dist/build.zip'),
},
)
console.log('Deploy id:', deploy.id, 'state:', deploy.state)
Demonstrates the accessToken setter for multi-tenant scenarios, then deletes a site by ID.
import { NetlifyAPI } from './src/netlify-client/index.js'
// Start with no token
const client = new NetlifyAPI({ globalParams: {} })
// Swap in the token later (e.g. after OAuth flow)
client.accessToken = process.env.NETLIFY_ACCESS_TOKEN
const siteId = 'abcd-1234-efgh-5678'
await client.deleteSite({ site_id: siteId })
console.log('Site deleted. basePath was:', client.basePath)
// Clear the token
client.accessToken = null
console.log('Token cleared:', client.accessToken) // null
index.js — Defines and exports NetlifyAPI. Handles constructor overloading, default headers, basePath construction, the accessToken getter/setter, and the getAccessToken OAuth polling helper.open_api.js — Uses createRequire to load the @netlify/open-api JSON spec in an ESM context and re-exports it as openApiSpec.operations.js — Exports getOperations, which flattens openApiSpec.paths into an array of operation objects, merging path-level and operation-level parameters into typed buckets (path, query, body).operations.test.js.md — Not a runtime module; documents expected operation shapes for testing reference.methods/index.js — Exports getMethods. Calls getOperations, maps each to an async function, and merges them into a plain object. Also owns the fetch-and-retry loop.methods/body.js — Handles serialisation of params.body to a JSON string or passes through streams for binary uploads.methods/params.js — Exports getRequestParams to extract and validate parameters against an OpenAPI parameter definition map.methods/response.js — Exports parseResponse (deserialises JSON/text body) and getFetchError (builds a descriptive error from a failed response).methods/retry.js — Exports shouldRetry, waitForRetry, and MAX_RETRY; implements retry logic for transient network and 5xx errors.methods/url.js — Exports getUrl; interpolates path parameters into the URL template and appends query string via qs.import/export. In a CommonJS project use a bundler (esbuild, Rollup) or set "type": "module" and use .mjs extensions as needed.@netlify/open-api not found: open_api.js calls require('@netlify/open-api') — ensure this package is installed; it is a mandatory runtime dependency even though it looks like a dev tool.node-fetch v3 vs v2 ESM interop: node-fetch v3 is ESM-only. If your bundler targets CJS, pin node-fetch to ^2.6.x and update the import, or configure your bundler for ESM output.params.body as a function: For retried requests the body factory pattern (body: () => fs.createReadStream(...)) is required; a consumed stream cannot be re-read on retry.accessToken setter writes to defaultHeaders; calls made before setting the token will be unauthenticated and return 401. Set the token in the constructor or immediately after instantiation.globalParams leaking between tenants: globalParams is merged into every request. In multi-tenant use cases, create a separate NetlifyAPI instance per user rather than mutating globalParams on a shared instance.I have a Netlify API client block located at `source/` in my project.
The integration guide is in `USAGE.md` (also in this context).
The upstream package is `user@example.com`.
Please help me integrate this client into my project step by step:
1. Read `USAGE.md` and `source/index.js` to understand the exported API.
2. Install all required npm dependencies listed in USAGE.md.
3. Create a singleton client module that reads NETLIFY_ACCESS_TOKEN from
environment variables and exports a ready-to-use `NetlifyAPI` instance.
4. Add a helper function that lists all sites and returns their IDs and names.
5. Add a helper that creates a site given a name string and returns the site object.
6. Ensure all code is TypeScript-compatible and uses async/await.
7. Show me where to place each file relative to my project root.
8. Point out any ESM/CJS issues given my current `package.json` settings.
The upstream source is published as netlify (version 12.0.1) by the Netlify team. The license is MIT; see source/LICENSE if present, or refer to the upstream repository for the authoritative license text.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
完整安装指南与集成提示词将在购买后解锁。
Automation, Utilities & Developer Tools
免费