@major-tech/resource-client package provides a type-safe, zero-dependency way to interact with your Major resources (Postgres, DynamoDB, S3, etc.) 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 atsrc/clients/ (or client/).
Using the CLI
You can add resources and generate clients using the Major CLI.Manage Resources
Learn how to add and manage resources using the
major resource command.Using the Web Editor
If you are developing in the Major Web Editor, the Major AI assistant will automatically add resources and generate the necessary client code for you as you build your application.Usage
Each resource type has a specific client class with a tailoredinvoke function signature. See the specific pages for details on each client:
Postgres
Execute SQL queries against PostgreSQL databases.
DynamoDB
Perform DynamoDB operations like GetItem and PutItem.
S3 Storage
Manage files and buckets in S3-compatible storage.
Custom API
Call external APIs securely.
HubSpot
Interact with the HubSpot CRM API.
Error Handling
There are two types of errors you may encounter when using the Resource Client:- 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
ResourceInvokeErrorexceptions. - 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 yourinvoke calls in a try/catch block to handle ResourceInvokeError, and check the .ok property of the result to handle resource errors.
Error Response Structure
Whenresult.ok is false, the response follows this structure: