> ## Documentation Index
> Fetch the complete documentation index at: https://docs.major.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Resource Client

> Type-safe, zero-dependency client for accessing your Major connectors.

The `@major-tech/resource-client` package provides a type-safe, zero-dependency way to interact with your Major connectors from your application code.

## Features

* **Type-safe**: Full TypeScript support for all operations.
* **Universal**: Works in Node.js, browser, and edge environments.
* **Zero-dependency**: Lightweight and fast.

## Client Generation

You typically do not need to instantiate clients manually. Major generates singleton instances for you, which are available at `src/clients/` (or `client/`).

### Using the CLI

You can add connectors and generate clients using the Major CLI.

<Card title="Manage Connectors" icon="box" href="/cli/resource">
  Learn how to add and manage connectors using the `major resource` command.
</Card>

### Using the Web Editor

If you are developing in the Major Web Editor, the Major AI assistant will automatically add connectors and generate the necessary client code for you as you build your application.

## Per-connector usage

Each connector type has a specific client class with a tailored `invoke` function signature. In the web editor, the Major AI assistant wires up the right client and its arguments as you build, and the generated client in `src/clients/` reflects the exact signature for your resource.

<Card title="Connectors" icon="server" href="/connectors">
  Browse all available connectors with setup and client documentation.
</Card>

## Error Handling

There are two types of errors you may encounter when using the Resource Client:

1. **Client Invocation Errors**: These occur when the client fails to communicate with the Major platform (e.g., network issues, protocol errors, authentication failures). These are thrown as `ResourceInvokeError` exceptions.
2. **API/Resource Errors**: These occur when the client successfully communicates with Major, but the underlying resource returns an error (e.g., database query failed, 404 Not Found from an API). These are returned as a successful response with `ok: false`.

### Handling Strategy

You should wrap your `invoke` calls in a `try/catch` block to handle `ResourceInvokeError`, and check the `.ok` property of the result to handle resource errors.

```typescript theme={null}
import { ResourceInvokeError } from "@major-tech/resource-client";

try {
  const result = await client.invoke(...);

  if (!result.ok) {
    // Handle Resource Error (e.g. database query failed)
    console.error("Resource Error:", result.error.message);
    // result.error structure:
    // {
    //   message: string;
    //   httpStatus?: number;
    // }
    return;
  }

  // Success!
  console.log(result.result);

} catch (e) {
  if (e instanceof ResourceInvokeError) {
    // Handle Client Invocation Error (e.g. network failed)
    console.error("Invocation Error:", e.message);
    console.error("Status:", e.httpStatus);
    console.error("Request ID:", e.requestId);
  } else {
    // Handle unexpected errors
    console.error("Unknown Error:", e);
  }
}
```

### Error Response Structure

When `result.ok` is `false`, the response follows this structure:

```typescript theme={null}
interface InvokeFailure {
  ok: false;
  requestId: string;
  error: {
    message: string; // Description of the error
    httpStatus?: number; // HTTP status code from the resource (if applicable)
  };
}
```
