
Security News
npm βisβ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
@speakeasy-api/speakeasy-client-sdk-typescript
Advanced tools
<!-- Start SDK Installation [installation] --> ## SDK Installation
npm add @speakeasy-api/speakeasy-client-sdk-typescript
yarn add @speakeasy-api/speakeasy-client-sdk-typescript
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.apis.getApis({
metadata: {
key: ["<value>"],
},
op: {
and: false,
},
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Example
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
let res;
try {
res = await sdk.apis.deleteApi({
apiID: "<value>",
versionID: "<value>",
});
} catch (err) {
if (err instanceof errors.SDKError) {
console.error(err); // handle exception
throw err;
}
}
if (res.statusCode == 200) {
// handle response
}
}
run();
You can override the default server globally by passing a server name to the server: string
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 names associated with the available servers:
Name | Server | Variables |
---|---|---|
prod | https://api.prod.speakeasyapi.dev | None |
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
server: "prod",
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.apis.deleteApi({
apiID: "<value>",
versionID: "<value>",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
The default server can also be overridden globally by passing a URL to the serverURL: str
optional parameter when initializing the SDK client instance. For example:
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
serverURL: "https://api.prod.speakeasyapi.dev",
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.apis.deleteApi({
apiID: "<value>",
versionID: "<value>",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
The Typescript SDK makes API calls using the axios HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom AxiosInstance
object.
For example, you could specify a header for every request that your sdk makes as follows:
import { @speakeasy-api/speakeasy-client-sdk-typescript } from "Speakeasy";
import axios from "axios";
const httpClient = axios.create({
headers: {'x-custom-header': 'someValue'}
})
const sdk = new Speakeasy({defaultClient: httpClient});
This SDK supports the following security schemes globally:
Name | Type | Scheme |
---|---|---|
apiKey | apiKey | API key |
bearer | http | HTTP Bearer |
You can set the security parameters through the security
optional parameter when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.apis.deleteApi({
apiID: "<value>",
versionID: "<value>",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set workspaceID
to "<value>"
at SDK initialization and then you do not have to pass the same value on calls to operations like getWorkspaceEventsByTarget
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
The following global parameter is available.
Name | Type | Required | Description |
---|---|---|---|
workspaceID | string | The workspaceID parameter. |
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.events.getWorkspaceEventsByTarget({
targetID: "<value>",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
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:
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.auth.getWorkspaceAccess(
{},
{
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
}
);
if (res.statusCode == 200) {
// handle response
}
}
run();
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
retry_config: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.auth.getWorkspaceAccess({});
if (res.statusCode == 200) {
// handle response
}
}
run();
FAQs
<source media="(prefers-color-scheme: light)" srcset="https://github.com/user-attachments/assets/21dd5d3a-aefc-4cd3-abee-5e17ef1d4dad"> <source media="(
The npm package @speakeasy-api/speakeasy-client-sdk-typescript receives a total of 1,290 weekly downloads. As such, @speakeasy-api/speakeasy-client-sdk-typescript popularity was classified as popular.
We found that @speakeasy-api/speakeasy-client-sdk-typescript demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.