# new InsightsService(tokenSource, serviceUrl)
Parameters:
| Name | Type | Description |
|---|---|---|
tokenSource |
string
|
function
|
|
serviceUrl |
string
|
Example
const insights = sdk.asAdmin().Insights()
// Read source metadata by name
const { result } = await insights.Source('Orders').get()
// Create a document
await insights.Source('Orders').Doc.create({ temperature: 21.5, unit: 'C' })
Extends
Methods
# Source(nameOrId) → {SourceHandle}
Returns a scoped handle for the given source, identified by name or sourceId.
The name is resolved to a sourceId via a local cache on first call. If the name is not found in the cache, the cache is refreshed once before falling back to using the value as-is.
Parameters:
| Name | Type | Description |
|---|---|---|
nameOrId |
string
|
The source's human-readable name (e.g. |
SourceHandle
Example
const src = insights.Source('Orders')
const { result } = await src.get(true) // include formulator schema
# Sources(namesOrIds) → {Object}
Returns a handle for fetching documents across multiple sources at once.
Source names (e.g. ['Orders', 'Inventory']) are resolved to sourceIds via
the local cache. Results are grouped by source name in the response.
Parameters:
| Name | Type | Description |
|---|---|---|
namesOrIds |
Array.<string>
|
List of source names or sourceIds. |
Object
Example
const { result } = await insights.Sources(['Orders', 'Inventory'])
.Docs.find({ humanId: 'HT-4d44d' })
// result.total, result.Orders, result.Inventory
# delete(call, bodyopt) → {Promise.<ServiceResponse>}
Sends an authenticated DELETE request.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
call |
string
|
Path relative to |
|
body |
*
|
<optional> |
Optional request body, serialised to JSON. |
Promise.<ServiceResponse>
# get(call) → {Promise.<ServiceResponse>}
Sends an authenticated GET request.
Parameters:
| Name | Type | Description |
|---|---|---|
call |
string
|
Path relative to |
Promise.<ServiceResponse>
# async makeRequest(method, call, bodyopt) → {Promise.<ServiceResponse>}
Makes an authenticated HTTP request to the service and returns the parsed response.
Acquires a token, constructs the full endpoint URL, serialises the body as JSON when provided, and parses the JSON response. Throws a typed error on network failure or non-JSON responses.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
method |
string
|
HTTP method ( |
|
call |
string
|
Path to call relative to |
|
body |
*
|
<optional> |
Request body. Serialised to JSON unless already a string. |
sdk/fetch-failed – network-level failure.
Error
sdk/endpoint-invalid – service returned 404 with non-JSON body.
Error
sdk/non-json-response – response body could not be parsed.
Error
Promise.<ServiceResponse>
# post(call, bodyopt) → {Promise.<ServiceResponse>}
Sends an authenticated POST request.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
call |
string
|
Path relative to |
|
body |
*
|
<optional> |
Request body, serialised to JSON. |
Promise.<ServiceResponse>
# put(call, body) → {Promise.<ServiceResponse>}
Sends an authenticated PUT request.
Parameters:
| Name | Type | Description |
|---|---|---|
call |
string
|
Path relative to |
body |
*
|
Request body, serialised to JSON. |
Promise.<ServiceResponse>