connector
Use these helpers when writing a connector for a public JSON API. They provide request handling, consistent error messages, limit clamping, and timestamp conversion.
import { clampLimit, dateStrToEpochMs } from "std::data/connector"
node main() {
return {
limit: clampLimit(500, 100),
timestamp: dateStrToEpochMs("2026-01-01T00:00:00Z")
}
}Functions
connectorFetch
connectorFetch(
base: string,
domains: string[],
path: string,
headers: Record<string, any> = {},
method: HttpMethod = "GET",
body: Record<string, any> | string | null = null,
): Result raises <std::http::fetchJSON>Fetch a JSON API path within the allowed domains.
In a custom connector, raise your connector's effect before calling this helper with with approve. That avoids a separate interactive prompt for each HTTP request. Outer handlers still receive the HTTP interrupt and can reject it. Calling this helper directly requires an HTTP decision.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| base | string | The API base URL to resolve the path against. | |
| domains | string[] | Hostnames that the request is allowed to reach. | |
| path | string | The API path and query string, with user-supplied values URL-encoded. | |
| headers | Record<string, any> | {} | |
| method | HttpMethod | "GET" | |
| body | Record<string, any> | string | null | null |
Returns: Result
Throws: std::http::fetchJSON
Needs: network
(source)
connectorError
connectorError(source: string, err: any): stringFormat a connector request failure with its source name.
Keep request failures consistent across connector operations.
Parameters:
| Name | Type | Default |
|---|---|---|
| source | string | |
| err | any |
Returns: string
(source)
shapeError
shapeError(source: string, endpoint: string, err: any): stringFormat a connector response-validation failure with its source and endpoint.
Preserve validation details so a caller can identify changed API fields.
Parameters:
| Name | Type | Default |
|---|---|---|
| source | string | |
| endpoint | string | |
| err | any |
Returns: string
(source)
clampLimit
clampLimit(n: number, cap: number): numberClamp a limit to the range from zero through the supplied cap.
Use for connector limits that should be clamped instead of rejected.
Parameters:
| Name | Type | Default |
|---|---|---|
| n | number | |
| cap | number |
Returns: number
(source)
dateStrToEpochMs
dateStrToEpochMs(iso: string): numberConvert an ISO 8601 timestamp to epoch milliseconds, returning zero if it cannot be parsed.
Normalize source timestamps so results from different connectors can be compared.
Parameters:
| Name | Type | Default |
|---|---|---|
| iso | string |
Returns: number
(source)