4.7.2 • Published 1 day ago

@stackone/stackone-client-ts v4.7.2

Weekly downloads
-
License
-
Repository
github
Last release
1 day ago

@stackone/stackone-client-ts

SDK Installation

NPM

npm add @stackone/stackone-client-ts

Yarn

yarn add @stackone/stackone-client-ts

SDK Example Usage

List Employees

import { StackOne } from "@stackone/stackone-client-ts";

const stackOne = new StackOne({
    security: {
        password: "<YOUR_PASSWORD_HERE>",
    },
});

async function run() {
    const result = await stackOne.hris.listEmployees({
        expand: "company,employments,work_location,home_location,custom_fields,groups",
        fields: "id,first_name,last_name,name,display_name,gender,ethnicity,date_of_birth,birthday,marital_status,avatar_url,avatar,personal_email,personal_phone_number,work_email,work_phone_number,job_title,job_description,department,cost_centers,benefits,manager_id,hire_date,start_date,tenure,work_anniversary,employment_type,employment_contract_type,employment_status,termination_date,company_name,preferred_language,citizenships,home_location,work_location,employments,custom_fields,documents,created_at,updated_at,employee_number",
        filterUpdatedAfter: "2020-01-01T00:00:00.000Z",
        include: "avatar_url,avatar,custom_fields,job_description,benefits",
        updatedAfter: "2020-01-01T00:00:00.000Z",
        xAccountId: "<value>",
    });

    for await (const page of result) {
        // handle page
    }
}

run();

Available Resources and Operations

accounts

connectSessions

connectors

ats

crm

hris

iam

marketing

proxy

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:

import { StackOne } from "@stackone/stackone-client-ts";

const stackOne = new StackOne({
    security: {
        password: "<YOUR_PASSWORD_HERE>",
    },
});

async function run() {
    const result = await stackOne.hris.listEmployees({
        expand: "company,employments,work_location,home_location,custom_fields,groups",
        fields: "id,first_name,last_name,name,display_name,gender,ethnicity,date_of_birth,birthday,marital_status,avatar_url,avatar,personal_email,personal_phone_number,work_email,work_phone_number,job_title,job_description,department,cost_centers,benefits,manager_id,hire_date,start_date,tenure,work_anniversary,employment_type,employment_contract_type,employment_status,termination_date,company_name,preferred_language,citizenships,home_location,work_location,employments,custom_fields,documents,created_at,updated_at,employee_number",
        filterUpdatedAfter: "2020-01-01T00:00:00.000Z",
        include: "avatar_url,avatar,custom_fields,job_description,benefits",
        updatedAfter: "2020-01-01T00:00:00.000Z",
        xAccountId: "<value>",
    });

    for await (const page of result) {
        // handle page
    }
}

run();

Error Handling

All SDK methods 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 ObjectStatus CodeContent Type
errors.SDKError4xx-5xx/

Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The SDKValidationError that is thrown as a result will capture the raw value that failed validation in an attribute called rawValue. Additionally, a pretty() method is available on this error that can be used to log a nicely formatted string since validation errors can list many issues and the plain error string may be difficult read when debugging.

import { StackOne } from "@stackone/stackone-client-ts";
import * as errors from "@stackone/stackone-client-ts/sdk/models/errors";

const stackOne = new StackOne({
    security: {
        password: "<YOUR_PASSWORD_HERE>",
    },
});

async function run() {
    let result;
    try {
        result = await stackOne.accounts.deleteAccount({
            id: "<id>",
        });
    } catch (err) {
        switch (true) {
            case err instanceof errors.SDKValidationError: {
                // Validation errors can be pretty-printed
                console.error(err.pretty());
                // Raw value may also be inspected
                console.error(err.rawValue);
                return;
            }
            default: {
                throw err;
            }
        }
    }

    // Handle the result
    console.log(result);
}

run();

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 use the "beforeRequest" hook to to add a custom header and a timeout to requests and how to use the "requestError" hook to log errors:

import { StackOne } from "@stackone/stackone-client-ts";
import { HTTPClient } from "@stackone/stackone-client-ts/lib/http";

const httpClient = new HTTPClient({
  // fetcher takes a function that has the same signature as native `fetch`.
  fetcher: (request) => {
    return fetch(request);
  }
});

httpClient.addHook("beforeRequest", (request) => {
  const nextRequest = new Request(request, {
    signal: request.signal || AbortSignal.timeout(5000);
  });

  nextRequest.headers.set("x-custom-header", "custom value");

  return nextRequest;
});

httpClient.addHook("requestError", (error, request) => {
  console.group("Request Error");
  console.log("Reason:", `${error}`);
  console.log("Endpoint:", `${request.method} ${request.url}`);
  console.groupEnd();
});

const sdk = new StackOne({ httpClient });

Authentication

Per-Client Security Schemes

This SDK supports the following security schemes globally:

NameTypeScheme
passwordhttpHTTP Basic
usernamehttpHTTP Basic

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 { StackOne } from "@stackone/stackone-client-ts";

const stackOne = new StackOne({
    security: {
        password: "<YOUR_PASSWORD_HERE>",
    },
});

async function run() {
    const result = await stackOne.accounts.deleteAccount({
        id: "<id>",
    });

    // Handle the result
    console.log(result);
}

run();

Requirements

For supported JavaScript runtimes, please consult RUNTIMES.md.

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. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!

SDK Created by Speakeasy

4.7.2

1 day ago

4.7.1

9 days ago

4.7.0

9 days ago

4.6.0

17 days ago

4.5.0

21 days ago

4.4.9

21 days ago

4.4.8

22 days ago

4.4.7

22 days ago

4.4.6

23 days ago

4.4.5

27 days ago

4.4.3

1 month ago

4.4.4

1 month ago

4.4.2

1 month ago

4.3.3

1 month ago

4.3.2

2 months ago

4.3.1

2 months ago

4.3.0

2 months ago

4.2.2

2 months ago

4.2.1

2 months ago

4.2.0

2 months ago

4.1.0

2 months ago

4.0.2

3 months ago

4.0.1

3 months ago

4.0.0

3 months ago

3.0.1

3 months ago

3.0.0

3 months ago

2.3.5

3 months ago

2.3.4

4 months ago

2.3.3

4 months ago

2.3.2

4 months ago

2.3.1

4 months ago

2.2.0

4 months ago

2.3.0

4 months ago

2.1.2

4 months ago

2.1.4

4 months ago

2.1.1

4 months ago

2.1.0

4 months ago

2.0.0

4 months ago

1.1.3

5 months ago

1.1.1

5 months ago

1.1.2

5 months ago

1.1.0

5 months ago

0.12.0

5 months ago

0.11.11

5 months ago

0.11.10

5 months ago

0.11.9

6 months ago

0.11.8

6 months ago

0.11.7

6 months ago

0.11.4

6 months ago

0.11.3

6 months ago

0.11.2

6 months ago

0.11.0

6 months ago

0.10.10

6 months ago

0.10.9

6 months ago

0.10.8

6 months ago

0.10.7

6 months ago

0.10.6

6 months ago

0.10.5

6 months ago

0.10.4

6 months ago

0.10.3

6 months ago

0.10.2

6 months ago

0.10.1

7 months ago

0.10.0

7 months ago

0.9.2

7 months ago

0.9.1

7 months ago

0.9.0

7 months ago

0.8.2

7 months ago

0.8.1

7 months ago

0.8.0

7 months ago

0.7.0

7 months ago

0.6.2

7 months ago

0.6.1

7 months ago

0.6.0

7 months ago

0.5.0

7 months ago

0.4.1

8 months ago

0.4.0

8 months ago

0.3.0

8 months ago

0.2.4

8 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

8 months ago