@gainsight-customer-hub/widget-service-sdk
v1.3.4
Published
A universal JavaScript SDK for Widget Service connector operations. Available as UMD and ES modules.
Downloads
44
Maintainers
Readme
Widget Service SDK
A JavaScript SDK for executing Widget Service connectors from custom widgets.
Installation
yarn add @gainsight-customer-hub/widget-service-sdk
# or
npm install @gainsight-customer-hub/widget-service-sdkUsage
import { WidgetServiceSDK } from "@gainsight-customer-hub/widget-service-sdk";
const sdk = new WidgetServiceSDK();
const result = await sdk.connectors.execute({
permalink: "connector-permalink",
method: "GET"
});
console.log(result);API
Constructor Options (SDKConfig)
| Option | Type | Default | Description |
| ----------- | ------------------------ | ------------- | --------------------------------------------------------------- |
| csrfToken | string | Auto-detected | CSRF token (auto-detected from DOM element with id csrftoken) |
| headers | Record<string, string> | {} | Additional headers to include with all requests |
| timeout | number | 30000 | Request timeout in milliseconds |
Execute Options (ExecuteConnectorOptions)
| Option | Type | Required | Description |
| ------------- | ------------------------ | -------- | ----------------------------------------------------------------------- |
| permalink | string | Yes | The connector's unique permalink identifier |
| method | HttpMethod | Yes | HTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS |
| payload | ExecutePayload | No | Request body (only sent for POST, PUT, PATCH methods) |
| queryParams | Record<string, string> | No | Query parameters to append to the request URL |
| headers | Record<string, string> | No | Additional headers for this specific request |
Methods
| Method | Returns | Description |
| ------------------------------------------------------ | -------------------------- | ------------------- |
| connectors.execute(options: ExecuteConnectorOptions) | Promise<ExecuteResponse> | Execute a connector |
Types
import type {
HttpMethod,
ExecuteConnectorOptions,
ExecutePayload,
ExecuteResponse,
SDKConfig
} from "@gainsight-customer-hub/widget-service-sdk";
type HttpMethod =
| "GET"
| "POST"
| "PUT"
| "PATCH"
| "DELETE"
| "HEAD"
| "OPTIONS";
interface SDKConfig {
csrfToken?: string;
headers?: Record<string, string>;
timeout?: number;
}
interface ExecuteConnectorOptions {
permalink: string;
method: HttpMethod;
payload?: ExecutePayload;
headers?: Record<string, string>;
queryParams?: Record<string, string>;
}
interface ExecutePayload {
[key: string]: JsonValue;
}
interface ExecuteResponse {
[key: string]: JsonValue;
}