- 🔗 Table of Contents
- 📍 Overview
- 👾 Features
- 🚀 Getting Started
- ⚡ Quick Start
- 🔐 Authentication
- 📡 GraphQL
- 🗂️ Project Structure
- 🛠️ Development
- 📄 License
The @work-whiz/sdk is a lightweight TypeScript SDK for the Work Whiz API. It provides a typed client for Better Auth email authentication, authenticated GraphQL operations, and low-level HTTP requests.
- Typed Better Auth email sign up, sign in, sign out, email verification, password reset, and session lookup.
- Authenticated GraphQL helper for
/graphql. - Automatic Better Auth session cookie capture and replay in Node.
- Browser cookie support through Axios
withCredentials. - Generic
get,post,put,patch, anddeletemethods for lower-level API access. - TypeScript request and response types exported from the package root.
Before getting started with @work-whiz/sdk, ensure your runtime environment meets the following requirements:
- Programming Language: TypeScript or JavaScript (ES6+)
- Package Manager: npm
Install @work-whiz/sdk using npm:
❯ npm install @work-whiz/sdkImport the client from the package root:
import { WorkWhizClient } from '@work-whiz/sdk';
const client = new WorkWhizClient({
baseURL: 'http://localhost:3000',
});Run the test suite using the following command:
❯ npm testHere’s a quick example to get started with @work-whiz/sdk:
import { WorkWhizClient } from '@work-whiz/sdk';
const client = new WorkWhizClient({
baseURL: 'http://localhost:3000',
});
async function main() {
await client.signInEmail({
email: 'candidate@example.com',
password: 'AuthTest!12345',
});
const response = await client.graphql<{ me: { id: string; email: string } }>(
'query Me { me { id email } }',
);
console.log(response);
}
main();The SDK maps to the Work Whiz Better Auth REST endpoints under /api/auth.
await client.signUpEmail({
name: 'Candidate User',
email: 'candidate@example.com',
password: 'AuthTest!12345',
phone: '+27821234567',
role: 'candidate',
title: 'Mr',
});
await client.signInEmail({
email: 'candidate@example.com',
password: 'AuthTest!12345',
});
const session = await client.getSession();
await client.signOut();Available auth methods:
signUpEmail(data)signInEmail(data)signOut()verifyEmail(token)requestPasswordReset(data)resetPassword(data)getSession()
In Node, the client stores the Better Auth Set-Cookie header from sign-in and sends it on authenticated calls. In browsers, Axios uses withCredentials so the browser can manage cookies.
Use graphql<TData, TVariables>() for profile and account operations exposed through /graphql.
const result = await client.graphql<
{ me: { id: string; email: string } },
Record<string, never>
>('query Me { me { id email } }');The GraphQL helper sends the stored Better Auth session cookie automatically when one is available.
Feature code is split by responsibility while keeping WorkWhizClient as the single public entrypoint.
src/
config/
client.ts
index.ts
graphql/
graphql.resource.ts
graphql.types.ts
index.ts
interfaces/
client.ts
index.ts
modules/
auth/
auth.resource.ts
auth.types.ts
index.ts
index.ts
src/config/client.ts owns Axios setup, API key handling, generic HTTP methods, and session cookie state. Auth behavior lives in src/modules/auth, and GraphQL behavior lives in src/graphql.
Run tests:
npm testBuild the package:
npm run buildRun lint:
npm run lintThis project is licensed under the MIT License. See the LICENSE file for details.