README
Incident Response SDK for TypeScript
Developer-friendly & type-safe TypeScript SDK specifically catered to leverage Incident Response API.
Summary
Squadcast: ## Overview The Squadcast API provides developers the capability to extend and utilize Squadcast in conjunction with other services. Our API has resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.
Note: Customers using the V2 version of the Squadcast API would need to migrate to Squadcast API V3, as the former would be deprecated shortly.
Service Regions
Squadcast allows customers to choose the geographic region of the Squadcast data centers that host their account. When signing up, you can choose the service region. Currently, the available options are the United States (US) and Europe (EU).
US
Authentication: https://auth.squadcast.com · Other APIs: https://api.squadcast.com
EU
Authentication: https://auth.eu.squadcast.com · Other APIs: https://api.eu.squadcast.com
Authentication
In order to access the API programmatically, HTTP bearer authentication needs to be used. HTTP bearer authentication must be constructed using an access_token, passed as the Authorization header for each request, for example Authorization: Bearer eyJleHAiOjE2MzU1OTE1OTIsImp0aSI6Im.
Steps to procure the access_token:
Generate a
refresh_token(API Token) from the Squadcast web app. More details on how to get therefresh_tokencan be found in the Squadcast support documentation.Call the authentication API with the
refresh_tokento obtain anaccess_token.Use the
access_tokenas a Bearer token in theAuthorizationheader for all subsequent API requests.
Example — Generating an Access Token
The API response will look similar to:
Access Control
There are three different types of user roles in Squadcast: account_owner, stakeholder, and user. Refresh tokens upon creation are mapped with one of the mentioned user roles, and access to different resources is dependent on the permissions granted to these roles. For more information, please refer to the Squadcast support documentation.
Authorization
The access token authorizes users the ability to access different APIs, based on the user roles described above. Pass the access token as a Bearer token in the Authorization header of every request.
Table of Contents
SDK Installation
The SDK can be installed with either npm, pnpm, bun or yarn package managers.
NPM
PNPM
Bun
Yarn
[!NOTE] This package is published with CommonJS and ES Modules (ESM) support.
Requirements
For supported JavaScript runtimes, please consult RUNTIMES.md.
SDK Example Usage
Example
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
refreshTokenAuth
http
Custom HTTP
To authenticate with the API the refreshTokenAuth parameter must be set when initializing the SDK client instance. For example:
Available Resources and Operations
Standalone functions
All the methods listed above are available as standalone functions. These functions are ideal for use in applications running in the browser, serverless runtimes or other environments where application bundle size is a primary concern. When using a bundler to build your application, all unused functionality will be either excluded from the final bundle or tree-shaken away.
To read more about standalone functions, check FUNCTIONS.md.
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the returned response object will also be an async iterable that can be consumed using the for await...of syntax.
Here's an example of one such pagination call:
File uploads
Certain SDK methods accept files as part of a multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
[!TIP]
Depending on your JavaScript runtime, there are convenient utilities that return a handle to a file without reading the entire contents into memory:
Node.js v20+: Since v20, Node.js comes with a native
openAsBlobfunction innode:fs.Bun: The native
Bun.filefunction produces a file handle that can be used for streaming file uploads.Browsers: All supported browsers return an instance to a
Filewhen reading the value from an<input type="file">element.Node.js v18: A file stream can be created using the
fileFromhelper fromfetch-blob/from.js.
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
Error Handling
SquadcastSDKError is the base class for all HTTP error responses. It has the following properties:
error.message
string
Error message
error.statusCode
number
HTTP response status code eg 404
error.headers
Headers
HTTP response headers
error.body
string
HTTP body. Can be empty string if no body is returned.
error.rawResponse
Response
Raw HTTP response
Example
Error Classes
Primary errors:
SquadcastSDKError: The base class for HTTP error responses.PaymentRequiredError: Client error. Status code402. *ForbiddenError: Access is forbidden. Status code403. *NotFoundError: The server cannot find the requested resource. Status code404. *ConflictError: The request conflicts with the current state of the server. Status code409. *UnprocessableEntityError: Client error. Status code422. *InternalServerError: Server error. Status code500. *BadGatewayError: Server error. Status code502. *ServiceUnavailableError: Service unavailable. Status code503. *GatewayTimeoutError: Server error. Status code504. *UnauthorizedError: Access is unauthorized. Status code401. *BadRequestError: The server could not understand the request due to invalid syntax. Status code400. *
* Check the method documentation to see if the error is applicable.
Server Selection
Select Server by Index
You can override the default server globally by passing a server index to the serverIdx: number optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
0
https://api.squadcast.com
production US env
1
https://api.eu.squadcast.com
production EU env
Example
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the serverURL: string optional parameter when initializing the SDK client instance. For example:
Custom HTTP Client
The TypeScript SDK makes API calls using an HTTPClient that wraps the native Fetch API. This client is a thin wrapper around fetch and provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle errors and response.
The HTTPClient constructor takes an optional fetcher argument that can be used to integrate a third-party HTTP client or when writing tests to mock out the HTTP client and feed in fixtures.
The following example shows how to:
route requests through a proxy server using undici's ProxyAgent
use the
"beforeRequest"hook to add a custom header and a timeout to requestsuse the
"requestError"hook to log errors
Debugging
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass a logger that matches console's interface as an SDK option.
[!WARNING] Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
SDK Created by Speakeasy
Last updated