Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+55
@@ -0,0 +1,55 @@
|
||||
// @vitest-environment node
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createClient } from "./generated/client/client.gen.js";
|
||||
import { createAnalyticsEvent, getAdminAnalyticsOverview, getPublicAnalyticsOverview } from "./generated/sdk.gen.js";
|
||||
|
||||
describe("generated analytics client contract", () => {
|
||||
it("keeps ingest, public read, and operator admin credentials separate", async () => {
|
||||
const requests: Request[] = [];
|
||||
const client = createClient({
|
||||
auth: ({ name, scheme }) => {
|
||||
if (name === "x-analytics-token") return "ingest-secret";
|
||||
if (scheme === "bearer") return "service-secret";
|
||||
return undefined;
|
||||
},
|
||||
baseUrl: "https://api.example.test",
|
||||
fetch: async (requestInfo) => {
|
||||
requests.push(requestInfo as Request);
|
||||
return new Response("{}", { headers: { "Content-Type": "application/json" } });
|
||||
},
|
||||
responseStyle: "data",
|
||||
});
|
||||
|
||||
await createAnalyticsEvent({
|
||||
body: {
|
||||
action: "opened",
|
||||
category: "navigation",
|
||||
analytics: { userAnalyticsId: "anonymous-visitor" },
|
||||
},
|
||||
client,
|
||||
});
|
||||
await getPublicAnalyticsOverview({ client, query: { period: "last-7-days" } });
|
||||
await getAdminAnalyticsOverview({
|
||||
client,
|
||||
headers: { "x-hivegrid-operator-user-id": "operator_1" },
|
||||
query: { period: "last-30-days", portalId: "portal_1", tenantId: "tenant_1" },
|
||||
});
|
||||
|
||||
expect(requests).toHaveLength(3);
|
||||
expect(requests[0]?.headers.get("x-analytics-token")).toBe("ingest-secret");
|
||||
expect(await requests[0]?.json()).toEqual({
|
||||
action: "opened",
|
||||
category: "navigation",
|
||||
analytics: { userAnalyticsId: "anonymous-visitor" },
|
||||
});
|
||||
|
||||
expect(requests[1]?.url).toBe("https://api.example.test/v1/analytics/public?period=last-7-days");
|
||||
expect(requests[1]?.headers.get("x-analytics-token")).toBeNull();
|
||||
expect(requests[1]?.headers.get("authorization")).toBeNull();
|
||||
|
||||
expect(requests[2]?.url).toBe("https://api.example.test/v1/analytics/admin?period=last-30-days&portalId=portal_1&tenantId=tenant_1");
|
||||
expect(requests[2]?.headers.get("authorization")).toBe("Bearer service-secret");
|
||||
expect(requests[2]?.headers.get("x-hivegrid-operator-user-id")).toBe("operator_1");
|
||||
});
|
||||
});
|
||||
+42
-3
@@ -71,7 +71,7 @@ describe("createHiveGridClient — idempotency edge cases", () => {
|
||||
});
|
||||
|
||||
describe("createHiveGridClient — URL building", () => {
|
||||
it("uses an absolute path verbatim instead of prefixing the base url", async () => {
|
||||
it("allows an absolute path only when it stays on the configured origin", async () => {
|
||||
const captured: { url: string | null } = { url: null };
|
||||
const stub: typeof fetch = (async (url: string) => {
|
||||
captured.url = url;
|
||||
@@ -79,8 +79,47 @@ describe("createHiveGridClient — URL building", () => {
|
||||
}) as unknown as typeof fetch;
|
||||
|
||||
const client = createHiveGridClient({ baseUrl: "https://api.example.com", fetch: stub });
|
||||
await client.request({ method: "GET", path: "https://other.example.test/v2/thing" });
|
||||
expect(captured.url).toBe("https://other.example.test/v2/thing");
|
||||
await client.request({ method: "GET", path: "https://api.example.com/v2/thing" });
|
||||
expect(captured.url).toBe("https://api.example.com/v2/thing");
|
||||
});
|
||||
|
||||
it.each(["https://other.example.test/v2/thing", "//other.example.test/v2/thing"])(
|
||||
"fails closed for a cross-origin request path: %s",
|
||||
async (path) => {
|
||||
let calls = 0;
|
||||
const stub: typeof fetch = (async () => {
|
||||
calls += 1;
|
||||
return jsonResponse(200, {});
|
||||
}) as unknown as typeof fetch;
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com",
|
||||
auth: { apiKey: "must-not-leak" },
|
||||
tenantId: "tenant-must-not-leak",
|
||||
fetch: stub,
|
||||
});
|
||||
|
||||
await expect(client.request({ method: "GET", path })).rejects.toThrow(/cross-origin/);
|
||||
expect(calls).toBe(0);
|
||||
},
|
||||
);
|
||||
|
||||
it("disables automatic redirects so custom credentials cannot cross origins", async () => {
|
||||
const captured: { redirect: RequestRedirect | undefined; calls: number } = { redirect: undefined, calls: 0 };
|
||||
const stub: typeof fetch = (async (_url: unknown, init: RequestInit) => {
|
||||
captured.calls += 1;
|
||||
captured.redirect = init.redirect;
|
||||
return new Response(null, { status: 302, headers: { location: "https://other.example.test/collect" } });
|
||||
}) as unknown as typeof fetch;
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com",
|
||||
auth: { apiKey: "must-not-leak" },
|
||||
retry: { maxAttempts: 1 },
|
||||
fetch: stub,
|
||||
});
|
||||
|
||||
await expect(client.request({ method: "GET", path: "/v1/redirect" })).rejects.toMatchObject({ status: 302 });
|
||||
expect(captured.redirect).toBe("manual");
|
||||
expect(captured.calls).toBe(1);
|
||||
});
|
||||
|
||||
it("skips undefined query values while serializing the rest", async () => {
|
||||
|
||||
+101
-1
@@ -1,5 +1,10 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { createHiveGridClient, HiveGridApiError, HiveGridNetworkError } from "./client.js";
|
||||
import {
|
||||
createHiveGridClient,
|
||||
HiveGridApiError,
|
||||
HiveGridNetworkError,
|
||||
HiveGridResponseTooLargeError,
|
||||
} from "./client.js";
|
||||
|
||||
function mockFetchSequence(responses: Array<Response | Error>): typeof fetch {
|
||||
let index = 0;
|
||||
@@ -25,6 +30,33 @@ describe("createHiveGridClient", () => {
|
||||
expect(() => createHiveGridClient({ baseUrl: "" } as never)).toThrow(/baseUrl/);
|
||||
});
|
||||
|
||||
it("requires HTTPS unless insecure loopback development is explicitly enabled", () => {
|
||||
expect(() => createHiveGridClient({ baseUrl: "http://api.example.com", fetch: mockFetchSequence([]) })).toThrow(/HTTPS/);
|
||||
expect(() => createHiveGridClient({ baseUrl: "http://localhost:3000", fetch: mockFetchSequence([]) })).toThrow(/HTTPS/);
|
||||
expect(
|
||||
createHiveGridClient({
|
||||
baseUrl: "http://127.0.0.1:3000",
|
||||
allowInsecureLocalhost: true,
|
||||
fetch: mockFetchSequence([]),
|
||||
}).baseUrl,
|
||||
).toBe("http://127.0.0.1:3000");
|
||||
expect(() =>
|
||||
createHiveGridClient({
|
||||
baseUrl: "http://api.example.com",
|
||||
allowInsecureLocalhost: true,
|
||||
fetch: mockFetchSequence([]),
|
||||
}),
|
||||
).toThrow(/HTTPS/);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"https://user:pass@api.example.com",
|
||||
"https://api.example.com?target=other",
|
||||
"https://api.example.com#fragment",
|
||||
])("rejects ambiguous or credential-bearing base URLs: %s", (baseUrl) => {
|
||||
expect(() => createHiveGridClient({ baseUrl, fetch: mockFetchSequence([]) })).toThrow(/baseUrl/);
|
||||
});
|
||||
|
||||
it("strips trailing slashes from the base url", () => {
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com///",
|
||||
@@ -146,6 +178,28 @@ describe("createHiveGridClient", () => {
|
||||
expect(captured.headers!.get("baggage")).toBe("k=v");
|
||||
});
|
||||
|
||||
it.each(["Authorization", "authorization", "X-API-Key", "x-tenant-id", "Host", "Content-Length"])(
|
||||
"rejects caller overrides for protected header %s",
|
||||
async (header) => {
|
||||
let calls = 0;
|
||||
const stub: typeof fetch = (async () => {
|
||||
calls += 1;
|
||||
return jsonResponse(200, {});
|
||||
}) as unknown as typeof fetch;
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com",
|
||||
auth: { bearerToken: "configured-secret" },
|
||||
tenantId: "tenant-configured",
|
||||
fetch: stub,
|
||||
});
|
||||
|
||||
await expect(client.request({ method: "GET", path: "/v1/me", headers: { [header]: "attacker-value" } })).rejects.toThrow(
|
||||
/cannot be overridden/,
|
||||
);
|
||||
expect(calls).toBe(0);
|
||||
},
|
||||
);
|
||||
|
||||
it("retries on 5xx then succeeds", async () => {
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com",
|
||||
@@ -196,6 +250,52 @@ describe("createHiveGridClient", () => {
|
||||
await expect(client.request({ method: "GET", path: "/v1/ping" })).rejects.toBeInstanceOf(HiveGridNetworkError);
|
||||
});
|
||||
|
||||
it("aborts each network attempt after the configured timeout", async () => {
|
||||
const stub: typeof fetch = ((_url: unknown, init: RequestInit) =>
|
||||
new Promise<Response>((_resolve, reject) => {
|
||||
init.signal?.addEventListener("abort", () => reject(init.signal?.reason), { once: true });
|
||||
})) as unknown as typeof fetch;
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com",
|
||||
retry: { maxAttempts: 1 },
|
||||
timeoutMs: 5,
|
||||
fetch: stub,
|
||||
});
|
||||
|
||||
await expect(client.request({ method: "GET", path: "/v1/slow" })).rejects.toBeInstanceOf(HiveGridNetworkError);
|
||||
});
|
||||
|
||||
it("rejects a response whose declared body exceeds the configured limit", async () => {
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com",
|
||||
maxResponseBodyBytes: 4,
|
||||
fetch: mockFetchSequence([
|
||||
new Response("12345", { status: 200, headers: { "content-type": "text/plain", "content-length": "5" } }),
|
||||
]),
|
||||
});
|
||||
|
||||
await expect(client.request({ method: "GET", path: "/v1/large" })).rejects.toBeInstanceOf(HiveGridResponseTooLargeError);
|
||||
});
|
||||
|
||||
it("enforces the response limit while streaming when Content-Length is absent", async () => {
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode("123"));
|
||||
controller.enqueue(new TextEncoder().encode("45"));
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com",
|
||||
maxResponseBodyBytes: 4,
|
||||
fetch: mockFetchSequence([new Response(stream, { status: 200, headers: { "content-type": "text/plain" } })]),
|
||||
});
|
||||
|
||||
await expect(client.request({ method: "GET", path: "/v1/chunked-large" })).rejects.toBeInstanceOf(
|
||||
HiveGridResponseTooLargeError,
|
||||
);
|
||||
});
|
||||
|
||||
it("paginate auto-follows nextCursor and stops on null", async () => {
|
||||
const client = createHiveGridClient({
|
||||
baseUrl: "https://api.example.com",
|
||||
|
||||
@@ -39,6 +39,8 @@ export interface HiveGridIdempotencyConfig {
|
||||
export interface HiveGridClientConfig {
|
||||
/** Base URL of the hivegrid API, e.g. `https://api.hivegrid.de`. */
|
||||
baseUrl: string;
|
||||
/** Explicit development-only escape hatch for http://localhost/loopback base URLs. */
|
||||
allowInsecureLocalhost?: boolean;
|
||||
/** Auth configuration. Exactly one of bearerToken / apiKey / getToken should be set. */
|
||||
auth?: HiveGridAuthConfig;
|
||||
/** Optional tenant scope; forwarded as `X-Tenant-ID` on every call. */
|
||||
@@ -53,6 +55,10 @@ export interface HiveGridClientConfig {
|
||||
fetch?: typeof fetch;
|
||||
/** Sentry trace headers to forward (optional). */
|
||||
sentry?: { trace?: string; baggage?: string };
|
||||
/** Per-attempt request timeout in milliseconds (default 30000, maximum 300000). */
|
||||
timeoutMs?: number;
|
||||
/** Maximum decoded response body size in bytes (default 10 MiB, maximum 100 MiB). */
|
||||
maxResponseBodyBytes?: number;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
@@ -94,6 +100,15 @@ export class HiveGridNetworkError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export class HiveGridResponseTooLargeError extends Error {
|
||||
public readonly limitBytes: number;
|
||||
constructor(limitBytes: number) {
|
||||
super(`HiveGrid API response exceeds the configured ${limitBytes}-byte limit`);
|
||||
this.name = "HiveGridResponseTooLargeError";
|
||||
this.limitBytes = limitBytes;
|
||||
}
|
||||
}
|
||||
|
||||
export interface HiveGridClient {
|
||||
/** Issue a typed request against the API. */
|
||||
request<T = unknown>(input: {
|
||||
@@ -115,8 +130,23 @@ export interface HiveGridClient {
|
||||
const DEFAULT_RETRY_MAX_ATTEMPTS = 5;
|
||||
const DEFAULT_RETRY_BASE_MS = 1000;
|
||||
const DEFAULT_RETRY_MAX_MS = 30_000;
|
||||
const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
|
||||
const MAX_REQUEST_TIMEOUT_MS = 5 * 60_000;
|
||||
const DEFAULT_MAX_RESPONSE_BODY_BYTES = 10 * 1024 * 1024;
|
||||
const MAX_RESPONSE_BODY_BYTES = 100 * 1024 * 1024;
|
||||
const MUTATING_METHODS = new Set(["POST", "PUT", "PATCH"]);
|
||||
const RETRY_STATUS = new Set([408, 425, 429, 500, 502, 503, 504]);
|
||||
const PROTECTED_REQUEST_HEADERS = new Set([
|
||||
"authorization",
|
||||
"proxy-authorization",
|
||||
"x-api-key",
|
||||
"x-tenant-id",
|
||||
"host",
|
||||
"content-length",
|
||||
"transfer-encoding",
|
||||
"connection",
|
||||
"cookie",
|
||||
]);
|
||||
const PACKAGE_VERSION = "0.1.0";
|
||||
|
||||
function sleep(ms: number): Promise<void> {
|
||||
@@ -145,17 +175,79 @@ function parseRetryAfter(header: string | null): number | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
async function readBody(response: Response): Promise<unknown> {
|
||||
async function readBody(response: Response, maxBytes: number): Promise<unknown> {
|
||||
const text = await readResponseText(response, maxBytes);
|
||||
if (text.length === 0) return null;
|
||||
const contentType = response.headers.get("content-type") ?? "";
|
||||
if (contentType.includes("application/json")) {
|
||||
try {
|
||||
return await response.json();
|
||||
return JSON.parse(text) as unknown;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const text = await response.text();
|
||||
return text.length === 0 ? null : text;
|
||||
return text;
|
||||
}
|
||||
|
||||
async function readResponseText(response: Response, maxBytes: number): Promise<string> {
|
||||
const contentLength = response.headers.get("content-length");
|
||||
if (contentLength && /^\d+$/u.test(contentLength.trim()) && Number(contentLength) > maxBytes) {
|
||||
await response.body?.cancel().catch(() => undefined);
|
||||
throw new HiveGridResponseTooLargeError(maxBytes);
|
||||
}
|
||||
if (!response.body) return "";
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const chunks: Uint8Array[] = [];
|
||||
let totalBytes = 0;
|
||||
try {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
totalBytes += value.byteLength;
|
||||
if (totalBytes > maxBytes) {
|
||||
await reader.cancel().catch(() => undefined);
|
||||
throw new HiveGridResponseTooLargeError(maxBytes);
|
||||
}
|
||||
chunks.push(value);
|
||||
}
|
||||
} finally {
|
||||
reader.releaseLock();
|
||||
}
|
||||
|
||||
const bytes = new Uint8Array(totalBytes);
|
||||
let offset = 0;
|
||||
for (const chunk of chunks) {
|
||||
bytes.set(chunk, offset);
|
||||
offset += chunk.byteLength;
|
||||
}
|
||||
return new TextDecoder().decode(bytes);
|
||||
}
|
||||
|
||||
function normalizeBaseUrl(rawBaseUrl: string, allowInsecureLocalhost: boolean): URL {
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(rawBaseUrl);
|
||||
} catch {
|
||||
throw new Error("createHiveGridClient: baseUrl must be an absolute URL");
|
||||
}
|
||||
if (url.username || url.password || url.search || url.hash) {
|
||||
throw new Error("createHiveGridClient: baseUrl must not contain credentials, a query, or a fragment");
|
||||
}
|
||||
const isLoopback = ["localhost", "127.0.0.1", "::1", "[::1]"].includes(url.hostname.toLowerCase());
|
||||
if (url.protocol !== "https:" && !(allowInsecureLocalhost && url.protocol === "http:" && isLoopback)) {
|
||||
throw new Error("createHiveGridClient: baseUrl must use HTTPS (or explicit insecure localhost development mode)");
|
||||
}
|
||||
url.pathname = url.pathname.replace(/\/+$/u, "") || "/";
|
||||
return url;
|
||||
}
|
||||
|
||||
function resolvePositiveBoundedInteger(value: number | undefined, fallback: number, maximum: number, field: string): number {
|
||||
const resolved = value ?? fallback;
|
||||
if (!Number.isSafeInteger(resolved) || resolved <= 0 || resolved > maximum) {
|
||||
throw new Error(`createHiveGridClient: ${field} must be an integer between 1 and ${maximum}`);
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClient {
|
||||
@@ -163,7 +255,9 @@ export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClie
|
||||
throw new Error("createHiveGridClient: baseUrl is required");
|
||||
}
|
||||
|
||||
const baseUrl = config.baseUrl.replace(/\/+$/, "");
|
||||
const parsedBaseUrl = normalizeBaseUrl(config.baseUrl, config.allowInsecureLocalhost === true);
|
||||
const baseUrl = parsedBaseUrl.toString().replace(/\/+$/u, "");
|
||||
const baseOrigin = parsedBaseUrl.origin;
|
||||
const fetchImpl: typeof fetch =
|
||||
config.fetch ?? (typeof fetch !== "undefined" ? fetch.bind(globalThis) : (undefined as unknown as typeof fetch));
|
||||
if (!fetchImpl) {
|
||||
@@ -172,6 +266,13 @@ export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClie
|
||||
const retryMaxAttempts = config.retry?.maxAttempts ?? DEFAULT_RETRY_MAX_ATTEMPTS;
|
||||
const retryBaseMs = config.retry?.baseDelayMs ?? DEFAULT_RETRY_BASE_MS;
|
||||
const retryMaxMs = config.retry?.maxDelayMs ?? DEFAULT_RETRY_MAX_MS;
|
||||
const timeoutMs = resolvePositiveBoundedInteger(config.timeoutMs, DEFAULT_REQUEST_TIMEOUT_MS, MAX_REQUEST_TIMEOUT_MS, "timeoutMs");
|
||||
const maxResponseBodyBytes = resolvePositiveBoundedInteger(
|
||||
config.maxResponseBodyBytes,
|
||||
DEFAULT_MAX_RESPONSE_BODY_BYTES,
|
||||
MAX_RESPONSE_BODY_BYTES,
|
||||
"maxResponseBodyBytes",
|
||||
);
|
||||
const autoIdempotency = config.idempotency?.autoGenerate ?? true;
|
||||
let cachedToken: string | undefined = config.auth?.bearerToken;
|
||||
|
||||
@@ -190,7 +291,12 @@ export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClie
|
||||
return {};
|
||||
}
|
||||
|
||||
function buildHeaders(method: string, extra?: Record<string, string>, idempotencyKey?: string): Headers {
|
||||
function buildHeaders(
|
||||
method: string,
|
||||
authHeaders: Record<string, string>,
|
||||
extra?: Record<string, string>,
|
||||
idempotencyKey?: string,
|
||||
): Headers {
|
||||
const headers = new Headers();
|
||||
headers.set("Accept", "application/json");
|
||||
headers.set("Content-Type", "application/json");
|
||||
@@ -203,8 +309,14 @@ export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClie
|
||||
} else if (idempotencyKey) {
|
||||
headers.set("Idempotency-Key", idempotencyKey);
|
||||
}
|
||||
for (const [key, value] of Object.entries(authHeaders)) {
|
||||
headers.set(key, value);
|
||||
}
|
||||
if (extra) {
|
||||
for (const [key, value] of Object.entries(extra)) {
|
||||
if (PROTECTED_REQUEST_HEADERS.has(key.toLowerCase())) {
|
||||
throw new Error(`createHiveGridClient: request header ${key} is managed by the client and cannot be overridden`);
|
||||
}
|
||||
headers.set(key, value);
|
||||
}
|
||||
}
|
||||
@@ -212,7 +324,18 @@ export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClie
|
||||
}
|
||||
|
||||
function buildUrl(path: string, query?: Record<string, string | number | boolean | undefined>): string {
|
||||
const url = new URL(path.startsWith("http") ? path : `${baseUrl}${path.startsWith("/") ? "" : "/"}${path}`);
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(path, `${baseUrl}/`);
|
||||
} catch {
|
||||
throw new Error("createHiveGridClient: request path is not a valid URL");
|
||||
}
|
||||
if (url.origin !== baseOrigin) {
|
||||
throw new Error("createHiveGridClient: cross-origin request paths are not allowed");
|
||||
}
|
||||
if (url.username || url.password || url.hash) {
|
||||
throw new Error("createHiveGridClient: request path must not contain credentials or a fragment");
|
||||
}
|
||||
if (query) {
|
||||
for (const [key, value] of Object.entries(query)) {
|
||||
if (value === undefined) continue;
|
||||
@@ -228,15 +351,21 @@ export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClie
|
||||
headers: Headers,
|
||||
body: string | undefined,
|
||||
): Promise<{ response: Response | null; error: unknown }> {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(new Error(`HiveGrid API request timed out after ${timeoutMs}ms`)), timeoutMs);
|
||||
try {
|
||||
const response = await fetchImpl(url, {
|
||||
method,
|
||||
headers,
|
||||
body,
|
||||
redirect: "manual",
|
||||
signal: controller.signal,
|
||||
});
|
||||
return { response, error: null };
|
||||
} catch (err) {
|
||||
return { response: null, error: err };
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +380,7 @@ export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClie
|
||||
const method = input.method.toUpperCase();
|
||||
const url = buildUrl(input.path, input.query);
|
||||
const authHeaders = await resolveAuthHeader();
|
||||
const headers = buildHeaders(method, { ...authHeaders, ...input.headers }, input.idempotencyKey);
|
||||
const headers = buildHeaders(method, authHeaders, input.headers, input.idempotencyKey);
|
||||
const body = input.body === undefined ? undefined : JSON.stringify(input.body);
|
||||
|
||||
let attempt = 1;
|
||||
@@ -261,19 +390,20 @@ export function createHiveGridClient(config: HiveGridClientConfig): HiveGridClie
|
||||
|
||||
if (response) {
|
||||
if (response.ok) {
|
||||
return (await readBody(response)) as T;
|
||||
return (await readBody(response, maxResponseBodyBytes)) as T;
|
||||
}
|
||||
|
||||
// Retry conditions
|
||||
if (RETRY_STATUS.has(response.status) && attempt < retryMaxAttempts) {
|
||||
const retryAfter = parseRetryAfter(response.headers.get("Retry-After"));
|
||||
const delay = retryAfter !== null ? Math.min(retryMaxMs, retryAfter) : computeBackoff(attempt, retryBaseMs, retryMaxMs);
|
||||
await response.body?.cancel().catch(() => undefined);
|
||||
await sleep(delay);
|
||||
attempt += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
const errorBody = await readBody(response);
|
||||
const errorBody = await readBody(response, maxResponseBodyBytes);
|
||||
const requestId = response.headers.get("x-request-id") ?? undefined;
|
||||
const message =
|
||||
errorBody && typeof errorBody === "object" && "error" in errorBody && errorBody.error && typeof errorBody.error === "object"
|
||||
|
||||
+1
-4
@@ -40,10 +40,7 @@ export const createClient = (config: Config = {}): Client => {
|
||||
};
|
||||
|
||||
if (opts.security) {
|
||||
await setAuthParams({
|
||||
...opts,
|
||||
security: opts.security,
|
||||
});
|
||||
await setAuthParams(opts);
|
||||
}
|
||||
|
||||
if (opts.requestValidator) {
|
||||
|
||||
+8
-2
@@ -132,9 +132,15 @@ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean
|
||||
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">
|
||||
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
||||
|
||||
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(
|
||||
type SseFn = <
|
||||
TData = unknown,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_TError = unknown,
|
||||
ThrowOnError extends boolean = false,
|
||||
TResponseStyle extends ResponseStyle = "fields",
|
||||
>(
|
||||
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, "method">
|
||||
) => Promise<ServerSentEventsResult<TData, TError>>;
|
||||
) => Promise<ServerSentEventsResult<TData>>;
|
||||
|
||||
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(
|
||||
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">
|
||||
|
||||
+6
-8
@@ -105,14 +105,12 @@ const checkForExistence = (
|
||||
return false;
|
||||
};
|
||||
|
||||
export const setAuthParams = async ({
|
||||
security,
|
||||
...options
|
||||
}: Pick<Required<RequestOptions>, "security"> &
|
||||
Pick<RequestOptions, "auth" | "query"> & {
|
||||
export async function setAuthParams(
|
||||
options: Pick<RequestOptions, "auth" | "query" | "security"> & {
|
||||
headers: Headers;
|
||||
}) => {
|
||||
for (const auth of security) {
|
||||
}
|
||||
): Promise<void> {
|
||||
for (const auth of options.security ?? []) {
|
||||
if (checkForExistence(options, auth.name)) {
|
||||
continue;
|
||||
}
|
||||
@@ -141,7 +139,7 @@ export const setAuthParams = async ({
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const buildUrl: Client["buildUrl"] = (options) =>
|
||||
getUrl({
|
||||
|
||||
+4
-4
@@ -104,10 +104,10 @@ const stripEmptySlots = (params: Params) => {
|
||||
|
||||
export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => {
|
||||
const params: Params = {
|
||||
body: {},
|
||||
headers: {},
|
||||
path: {},
|
||||
query: {},
|
||||
body: Object.create(null),
|
||||
headers: Object.create(null),
|
||||
path: Object.create(null),
|
||||
query: Object.create(null),
|
||||
};
|
||||
|
||||
const map = buildKeyMap(fields);
|
||||
|
||||
+42
-6
@@ -4,6 +4,7 @@ export {
|
||||
acceptWorkspaceInvite,
|
||||
createAnalyticsEvent,
|
||||
createAnalyticsPageView,
|
||||
createPlatformLead,
|
||||
createSupportTicketFromInboundEmail,
|
||||
createWorkspaceInvite,
|
||||
enqueueExportArtifactRetention,
|
||||
@@ -21,6 +22,8 @@ export {
|
||||
getReadyz,
|
||||
getStatus,
|
||||
getV1Health,
|
||||
ingestAdminSalesEmailBccCopy,
|
||||
ingestTenantInboundEmailFromMailjet,
|
||||
listAccounts,
|
||||
listPublicApiCompanies,
|
||||
listPublicApiContacts,
|
||||
@@ -35,7 +38,12 @@ export {
|
||||
type Options,
|
||||
postDeviceRegister,
|
||||
postDeviceRevoke,
|
||||
receiveAdminAircallTelephonyWebhook,
|
||||
receiveAdminSalesEmailProviderEvent,
|
||||
receiveAircallTelephonyWebhook,
|
||||
receiveEmailSequenceMailjetWebhook,
|
||||
receiveHalloPetraTelephonyWebhook,
|
||||
receiveLagoBillingWebhook,
|
||||
receiveMollieBillingWebhook,
|
||||
receivePublicApiIncomingWebhook,
|
||||
refreshJwtToken,
|
||||
@@ -43,7 +51,6 @@ export {
|
||||
revalidateWorkspaceContext,
|
||||
revokeWorkspaceInvite,
|
||||
streamNotifications,
|
||||
uploadAiFile,
|
||||
validateApiKey,
|
||||
} from "./sdk.gen";
|
||||
export type {
|
||||
@@ -63,6 +70,11 @@ export type {
|
||||
CreateAnalyticsPageViewErrors,
|
||||
CreateAnalyticsPageViewResponse,
|
||||
CreateAnalyticsPageViewResponses,
|
||||
CreatePlatformLeadData,
|
||||
CreatePlatformLeadError,
|
||||
CreatePlatformLeadErrors,
|
||||
CreatePlatformLeadResponse,
|
||||
CreatePlatformLeadResponses,
|
||||
CreateSupportTicketFromInboundEmailData,
|
||||
CreateSupportTicketFromInboundEmailError,
|
||||
CreateSupportTicketFromInboundEmailErrors,
|
||||
@@ -137,6 +149,15 @@ export type {
|
||||
GetV1HealthData,
|
||||
GetV1HealthResponse,
|
||||
GetV1HealthResponses,
|
||||
IngestAdminSalesEmailBccCopyData,
|
||||
IngestAdminSalesEmailBccCopyError,
|
||||
IngestAdminSalesEmailBccCopyErrors,
|
||||
IngestAdminSalesEmailBccCopyResponses,
|
||||
IngestTenantInboundEmailFromMailjetData,
|
||||
IngestTenantInboundEmailFromMailjetError,
|
||||
IngestTenantInboundEmailFromMailjetErrors,
|
||||
IngestTenantInboundEmailFromMailjetResponse,
|
||||
IngestTenantInboundEmailFromMailjetResponses,
|
||||
ListAccountsData,
|
||||
ListAccountsError,
|
||||
ListAccountsErrors,
|
||||
@@ -200,10 +221,30 @@ export type {
|
||||
PostDeviceRevokeErrors,
|
||||
PostDeviceRevokeResponse,
|
||||
PostDeviceRevokeResponses,
|
||||
ReceiveAdminAircallTelephonyWebhookData,
|
||||
ReceiveAdminAircallTelephonyWebhookError,
|
||||
ReceiveAdminAircallTelephonyWebhookErrors,
|
||||
ReceiveAdminAircallTelephonyWebhookResponses,
|
||||
ReceiveAdminSalesEmailProviderEventData,
|
||||
ReceiveAdminSalesEmailProviderEventError,
|
||||
ReceiveAdminSalesEmailProviderEventErrors,
|
||||
ReceiveAdminSalesEmailProviderEventResponses,
|
||||
ReceiveAircallTelephonyWebhookData,
|
||||
ReceiveAircallTelephonyWebhookError,
|
||||
ReceiveAircallTelephonyWebhookErrors,
|
||||
ReceiveAircallTelephonyWebhookResponses,
|
||||
ReceiveEmailSequenceMailjetWebhookData,
|
||||
ReceiveEmailSequenceMailjetWebhookError,
|
||||
ReceiveEmailSequenceMailjetWebhookErrors,
|
||||
ReceiveEmailSequenceMailjetWebhookResponses,
|
||||
ReceiveHalloPetraTelephonyWebhookData,
|
||||
ReceiveHalloPetraTelephonyWebhookError,
|
||||
ReceiveHalloPetraTelephonyWebhookErrors,
|
||||
ReceiveHalloPetraTelephonyWebhookResponses,
|
||||
ReceiveLagoBillingWebhookData,
|
||||
ReceiveLagoBillingWebhookError,
|
||||
ReceiveLagoBillingWebhookErrors,
|
||||
ReceiveLagoBillingWebhookResponses,
|
||||
ReceiveMollieBillingWebhookData,
|
||||
ReceiveMollieBillingWebhookError,
|
||||
ReceiveMollieBillingWebhookErrors,
|
||||
@@ -236,11 +277,6 @@ export type {
|
||||
StreamNotificationsErrors,
|
||||
StreamNotificationsResponse,
|
||||
StreamNotificationsResponses,
|
||||
UploadAiFileData,
|
||||
UploadAiFileError,
|
||||
UploadAiFileErrors,
|
||||
UploadAiFileResponse,
|
||||
UploadAiFileResponses,
|
||||
ValidateApiKeyData,
|
||||
ValidateApiKeyError,
|
||||
ValidateApiKeyErrors,
|
||||
|
||||
+157
-16
@@ -12,6 +12,9 @@ import type {
|
||||
CreateAnalyticsPageViewData,
|
||||
CreateAnalyticsPageViewErrors,
|
||||
CreateAnalyticsPageViewResponses,
|
||||
CreatePlatformLeadData,
|
||||
CreatePlatformLeadErrors,
|
||||
CreatePlatformLeadResponses,
|
||||
CreateSupportTicketFromInboundEmailData,
|
||||
CreateSupportTicketFromInboundEmailErrors,
|
||||
CreateSupportTicketFromInboundEmailResponses,
|
||||
@@ -59,6 +62,12 @@ import type {
|
||||
GetStatusResponses,
|
||||
GetV1HealthData,
|
||||
GetV1HealthResponses,
|
||||
IngestAdminSalesEmailBccCopyData,
|
||||
IngestAdminSalesEmailBccCopyErrors,
|
||||
IngestAdminSalesEmailBccCopyResponses,
|
||||
IngestTenantInboundEmailFromMailjetData,
|
||||
IngestTenantInboundEmailFromMailjetErrors,
|
||||
IngestTenantInboundEmailFromMailjetResponses,
|
||||
ListAccountsData,
|
||||
ListAccountsErrors,
|
||||
ListAccountsResponses,
|
||||
@@ -98,9 +107,24 @@ import type {
|
||||
PostDeviceRevokeData,
|
||||
PostDeviceRevokeErrors,
|
||||
PostDeviceRevokeResponses,
|
||||
ReceiveAdminAircallTelephonyWebhookData,
|
||||
ReceiveAdminAircallTelephonyWebhookErrors,
|
||||
ReceiveAdminAircallTelephonyWebhookResponses,
|
||||
ReceiveAdminSalesEmailProviderEventData,
|
||||
ReceiveAdminSalesEmailProviderEventErrors,
|
||||
ReceiveAdminSalesEmailProviderEventResponses,
|
||||
ReceiveAircallTelephonyWebhookData,
|
||||
ReceiveAircallTelephonyWebhookErrors,
|
||||
ReceiveAircallTelephonyWebhookResponses,
|
||||
ReceiveEmailSequenceMailjetWebhookData,
|
||||
ReceiveEmailSequenceMailjetWebhookErrors,
|
||||
ReceiveEmailSequenceMailjetWebhookResponses,
|
||||
ReceiveHalloPetraTelephonyWebhookData,
|
||||
ReceiveHalloPetraTelephonyWebhookErrors,
|
||||
ReceiveHalloPetraTelephonyWebhookResponses,
|
||||
ReceiveLagoBillingWebhookData,
|
||||
ReceiveLagoBillingWebhookErrors,
|
||||
ReceiveLagoBillingWebhookResponses,
|
||||
ReceiveMollieBillingWebhookData,
|
||||
ReceiveMollieBillingWebhookErrors,
|
||||
ReceiveMollieBillingWebhookResponses,
|
||||
@@ -123,9 +147,6 @@ import type {
|
||||
StreamNotificationsErrors,
|
||||
StreamNotificationsResponse,
|
||||
StreamNotificationsResponses,
|
||||
UploadAiFileData,
|
||||
UploadAiFileErrors,
|
||||
UploadAiFileResponses,
|
||||
ValidateApiKeyData,
|
||||
ValidateApiKeyErrors,
|
||||
ValidateApiKeyResponses,
|
||||
@@ -219,11 +240,18 @@ export const validateApiKey = <ThrowOnError extends boolean = false>(options?: O
|
||||
},
|
||||
});
|
||||
|
||||
export const uploadAiFile = <ThrowOnError extends boolean = false>(options?: Options<UploadAiFileData, ThrowOnError>) =>
|
||||
(options?.client ?? client).post<UploadAiFileResponses, UploadAiFileErrors, ThrowOnError>({
|
||||
/**
|
||||
* Creates a tenantless platform sales lead for the source authenticated by a rotatable bearer capability. The source cannot be supplied by the request body. Persistence, first activity, outbox event, and idempotency response commit atomically.
|
||||
*/
|
||||
export const createPlatformLead = <ThrowOnError extends boolean = false>(options: Options<CreatePlatformLeadData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<CreatePlatformLeadResponses, CreatePlatformLeadErrors, ThrowOnError>({
|
||||
security: [{ scheme: "bearer", type: "http" }],
|
||||
url: "/v1/ai/upload",
|
||||
url: "/v1/platform/leads",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -242,6 +270,22 @@ export const createSupportTicketFromInboundEmail = <ThrowOnError extends boolean
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Accepts Mailjet inbound (parse) email webhooks authenticated with HTTP Basic Auth, resolves the tenant inbound address, persists the mail, and creates the matching lead/contact activity.
|
||||
*/
|
||||
export const ingestTenantInboundEmailFromMailjet = <ThrowOnError extends boolean = false>(
|
||||
options: Options<IngestTenantInboundEmailFromMailjetData, ThrowOnError>
|
||||
) =>
|
||||
(options.client ?? client).post<IngestTenantInboundEmailFromMailjetResponses, IngestTenantInboundEmailFromMailjetErrors, ThrowOnError>({
|
||||
security: [{ scheme: "basic", type: "http" }],
|
||||
url: "/v1/email/inbound-mailjet",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
export const createAnalyticsEvent = <ThrowOnError extends boolean = false>(options: Options<CreateAnalyticsEventData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<CreateAnalyticsEventResponses, CreateAnalyticsEventErrors, ThrowOnError>({
|
||||
security: [{ name: "x-analytics-token", type: "apiKey" }],
|
||||
@@ -264,9 +308,11 @@ export const createAnalyticsPageView = <ThrowOnError extends boolean = false>(op
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns tenantless platform analytics aggregates only when the operator-controlled public setting is enabled.
|
||||
*/
|
||||
export const getPublicAnalyticsOverview = <ThrowOnError extends boolean = false>(options?: Options<GetPublicAnalyticsOverviewData, ThrowOnError>) =>
|
||||
(options?.client ?? client).get<GetPublicAnalyticsOverviewResponses, GetPublicAnalyticsOverviewErrors, ThrowOnError>({
|
||||
security: [{ name: "x-analytics-token", type: "apiKey" }],
|
||||
url: "/v1/analytics/public",
|
||||
...options,
|
||||
});
|
||||
@@ -347,8 +393,8 @@ export const revokeWorkspaceInvite = <ThrowOnError extends boolean = false>(opti
|
||||
},
|
||||
});
|
||||
|
||||
export const getAdminAnalyticsOverview = <ThrowOnError extends boolean = false>(options?: Options<GetAdminAnalyticsOverviewData, ThrowOnError>) =>
|
||||
(options?.client ?? client).get<GetAdminAnalyticsOverviewResponses, GetAdminAnalyticsOverviewErrors, ThrowOnError>({
|
||||
export const getAdminAnalyticsOverview = <ThrowOnError extends boolean = false>(options: Options<GetAdminAnalyticsOverviewData, ThrowOnError>) =>
|
||||
(options.client ?? client).get<GetAdminAnalyticsOverviewResponses, GetAdminAnalyticsOverviewErrors, ThrowOnError>({
|
||||
security: [{ scheme: "bearer", type: "http" }],
|
||||
url: "/v1/analytics/admin",
|
||||
...options,
|
||||
@@ -367,17 +413,17 @@ export const streamNotifications = <ThrowOnError extends boolean = false>(
|
||||
});
|
||||
|
||||
/**
|
||||
* Lists tenant account metadata and subscription summaries for service-token callers from the canonical API runtime.
|
||||
* Lists tenant account metadata and subscription summaries after service-token authentication and an explicit RLS-verified platform operator identity.
|
||||
*/
|
||||
export const listAccounts = <ThrowOnError extends boolean = false>(options?: Options<ListAccountsData, ThrowOnError>) =>
|
||||
(options?.client ?? client).get<ListAccountsResponses, ListAccountsErrors, ThrowOnError>({
|
||||
export const listAccounts = <ThrowOnError extends boolean = false>(options: Options<ListAccountsData, ThrowOnError>) =>
|
||||
(options.client ?? client).get<ListAccountsResponses, ListAccountsErrors, ThrowOnError>({
|
||||
security: [{ scheme: "bearer", type: "http" }],
|
||||
url: "/v1/accounts",
|
||||
...options,
|
||||
});
|
||||
|
||||
/**
|
||||
* Looks up one tenant account by id or slug for service-token callers from the canonical API runtime.
|
||||
* Looks up one tenant account by id or slug after service-token authentication and an explicit RLS-verified platform operator identity.
|
||||
*/
|
||||
export const getAccount = <ThrowOnError extends boolean = false>(options: Options<GetAccountData, ThrowOnError>) =>
|
||||
(options.client ?? client).get<GetAccountResponses, GetAccountErrors, ThrowOnError>({
|
||||
@@ -457,7 +503,7 @@ export const listPublicApiLeads = <ThrowOnError extends boolean = false>(options
|
||||
});
|
||||
|
||||
/**
|
||||
* Tenant-scoped incoming lead webhook. The endpoint authenticates by the endpoint's configured mode: API key, HMAC token/signature, or URL/header token. Successful requests create an InboxLead and queue webhook.received automation executions.
|
||||
* Tenant-scoped incoming lead webhook. Credentials are verified before payload, billing, or ingestion work. HMAC timestamps have a five-minute freshness window and exact signed replays are deduplicated through the persistent idempotency store. Successful requests create an InboxLead and queue webhook.received automation executions.
|
||||
*/
|
||||
export const receivePublicApiIncomingWebhook = <ThrowOnError extends boolean = false>(options: Options<ReceivePublicApiIncomingWebhookData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<ReceivePublicApiIncomingWebhookResponses, ReceivePublicApiIncomingWebhookErrors, ThrowOnError>({
|
||||
@@ -474,6 +520,24 @@ export const receivePublicApiIncomingWebhook = <ThrowOnError extends boolean = f
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Canonical API-host entry point for Lago lifecycle webhooks. The API verifies Lago's HMAC-SHA256 signature over the exact JSON request body, binds the embedded customer tenant, and applies subscription changes idempotently using the provider event key.
|
||||
*/
|
||||
export const receiveLagoBillingWebhook = <ThrowOnError extends boolean = false>(options: Options<ReceiveLagoBillingWebhookData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<ReceiveLagoBillingWebhookResponses, ReceiveLagoBillingWebhookErrors, ThrowOnError>({
|
||||
security: [
|
||||
{ name: "X-Lago-Signature", type: "apiKey" },
|
||||
{ name: "X-Lago-Signature-Algorithm", type: "apiKey" },
|
||||
{ name: "X-Lago-Unique-Key", type: "apiKey" },
|
||||
],
|
||||
url: "/v1/billing/lago/webhooks",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Canonical API-host entry point for Mollie payment lifecycle webhooks. Mollie posts a payment id; the API refetches that payment from Mollie server-side before syncing tenant billing state.
|
||||
*/
|
||||
@@ -488,6 +552,50 @@ export const receiveMollieBillingWebhook = <ThrowOnError extends boolean = false
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Canonical API-host entry point for Aircall call lifecycle webhooks. The provider token is supplied in the JSON body, resolved to an RLS identity through its stored hash, and never echoed or persisted in the event payload.
|
||||
*/
|
||||
export const receiveAircallTelephonyWebhook = <ThrowOnError extends boolean = false>(options: Options<ReceiveAircallTelephonyWebhookData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<ReceiveAircallTelephonyWebhookResponses, ReceiveAircallTelephonyWebhookErrors, ThrowOnError>({
|
||||
url: "/v1/webhooks/telephony/aircall",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Canonical API-host entry point for HalloPetra post-call webhooks. A separately generated webhook secret is supplied as an Authorization Bearer credential, resolved to one RLS identity through its stored hash, and never echoed or persisted in the event payload.
|
||||
*/
|
||||
export const receiveHalloPetraTelephonyWebhook = <ThrowOnError extends boolean = false>(
|
||||
options: Options<ReceiveHalloPetraTelephonyWebhookData, ThrowOnError>
|
||||
) =>
|
||||
(options.client ?? client).post<ReceiveHalloPetraTelephonyWebhookResponses, ReceiveHalloPetraTelephonyWebhookErrors, ThrowOnError>({
|
||||
security: [{ scheme: "bearer", type: "http" }],
|
||||
url: "/v1/webhooks/telephony/hallopetra",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Canonical API-host entry point for tenantless Admin Sales Aircall lifecycle webhooks. The provider token is supplied in the JSON body, resolved to an AdminUser RLS identity through its stored hash, and never echoed or persisted in the event payload.
|
||||
*/
|
||||
export const receiveAdminAircallTelephonyWebhook = <ThrowOnError extends boolean = false>(
|
||||
options: Options<ReceiveAdminAircallTelephonyWebhookData, ThrowOnError>
|
||||
) =>
|
||||
(options.client ?? client).post<ReceiveAdminAircallTelephonyWebhookResponses, ReceiveAdminAircallTelephonyWebhookErrors, ThrowOnError>({
|
||||
url: "/v1/webhooks/admin-telephony/aircall",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Accepts Mailjet provider event webhooks for email sequences, authenticated with HTTP Basic Auth. Bounce, blocked, and spam events correlate by provider message id (Message_GUID), mark the sequence delivery bounced, and fail the in-flight run without echoing provider payloads.
|
||||
*/
|
||||
@@ -504,6 +612,39 @@ export const receiveEmailSequenceMailjetWebhook = <ThrowOnError extends boolean
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Accepts provider-neutral delivery and bounce events for the tenantless Admin Sales workspace. The exact request body is authenticated with a timestamp-bound HMAC before the AdminUser RLS context is bound; consented open and click events use HiveGrid's signed tracking routes.
|
||||
*/
|
||||
export const receiveAdminSalesEmailProviderEvent = <ThrowOnError extends boolean = false>(
|
||||
options: Options<ReceiveAdminSalesEmailProviderEventData, ThrowOnError>
|
||||
) =>
|
||||
(options.client ?? client).post<ReceiveAdminSalesEmailProviderEventResponses, ReceiveAdminSalesEmailProviderEventErrors, ThrowOnError>({
|
||||
security: [
|
||||
{ name: "X-HiveGrid-Signature", type: "apiKey" },
|
||||
{ name: "X-HiveGrid-Timestamp", type: "apiKey" },
|
||||
],
|
||||
url: "/v1/admin-sales/email/provider-events",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Logs an externally sent message in the tenantless Admin Sales workspace. Mailjet HTTP Basic authentication and exactly one signed, rotatable BCC recipient capability are verified before the capability's AdminUser RLS context is bound.
|
||||
*/
|
||||
export const ingestAdminSalesEmailBccCopy = <ThrowOnError extends boolean = false>(options: Options<IngestAdminSalesEmailBccCopyData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<IngestAdminSalesEmailBccCopyResponses, IngestAdminSalesEmailBccCopyErrors, ThrowOnError>({
|
||||
security: [{ scheme: "basic", type: "http" }],
|
||||
url: "/v1/admin-sales/email/bcc-inbound",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
export const retryEventWebhookAttempt = <ThrowOnError extends boolean = false>(options: Options<RetryEventWebhookAttemptData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<RetryEventWebhookAttemptResponses, RetryEventWebhookAttemptErrors, ThrowOnError>({
|
||||
security: [{ scheme: "basic", type: "http" }],
|
||||
@@ -552,7 +693,7 @@ export const getExportJobProgress = <ThrowOnError extends boolean = false>(optio
|
||||
});
|
||||
|
||||
/**
|
||||
* Register or update a Web Push token for the authenticated principal. Requires a service-token bearer credential; the body's userId + tenantId are reconciled downstream against the authenticated principal. Tokens are upserted by their globally unique value so cold-start replays are idempotent.
|
||||
* Register or update a Web Push token for the owner of a verified, active API session JWT. The user identity comes exclusively from signed session claims; body or header identity overrides are rejected. An optional tenantId is accepted only after active membership is revalidated inside the tenant/user RLS context. Same-owner cold-start replays are idempotent, while foreign token ownership fails closed.
|
||||
*/
|
||||
export const postDeviceRegister = <ThrowOnError extends boolean = false>(options: Options<PostDeviceRegisterData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<PostDeviceRegisterResponses, PostDeviceRegisterErrors, ThrowOnError>({
|
||||
@@ -566,7 +707,7 @@ export const postDeviceRegister = <ThrowOnError extends boolean = false>(options
|
||||
});
|
||||
|
||||
/**
|
||||
* Revoke a Web Push token. Requires a service-token bearer credential; the handler revokes by token hash and never echoes the raw token in the response.
|
||||
* Revoke a Web Push token for the owner of a verified, active API session JWT. The user identity comes exclusively from signed session claims; body or header identity overrides are rejected. An optional tenantId is membership-revalidated. The ownership-constrained write treats foreign user or tenant tokens as not found and never echoes the raw token.
|
||||
*/
|
||||
export const postDeviceRevoke = <ThrowOnError extends boolean = false>(options: Options<PostDeviceRevokeData, ThrowOnError>) =>
|
||||
(options.client ?? client).post<PostDeviceRevokeResponses, PostDeviceRevokeErrors, ThrowOnError>({
|
||||
|
||||
+949
-96
File diff suppressed because it is too large.
Load diff
@@ -15,6 +15,7 @@ export {
|
||||
createHiveGridClient,
|
||||
HiveGridApiError,
|
||||
HiveGridNetworkError,
|
||||
HiveGridResponseTooLargeError,
|
||||
type HiveGridClient,
|
||||
type HiveGridClientConfig,
|
||||
type HiveGridAuthConfig,
|
||||
|
||||
Reference in new issue
Block a user