npm package: @heyhef/api-client
Description: Generated TypeScript API client for the CRO platform
Author: Michael Hefner
Latest version: 0.0.1

# @heyhef/api-client

Generated TypeScript API client for the CRO platform (from `api/openapi.yaml`).

Quick start

1. Install dependencies (from package root):

```bash
cd packages/api-client
npm install
```

2. Build the client (produces `dist/` with JS + type declarations):

```bash
npm run build
```

3. Use in your app:

```ts
import { OpenAPI, ExperimentsService } from '@heyhef/api-client';

OpenAPI.BASE = process.env.API_BASE || 'http://localhost:3000';
OpenAPI.TOKEN = async () => localStorage.getItem('token') || undefined;

const cfg = await ExperimentsService.fetchExperimentConfig('exp-id', 'visitor-123');
```

Notes
- The client expects `fetch` to be available. In Node, we recommend installing `cross-fetch`.
- The package includes a minimal TypeScript config for building and producing declaration files.

Publishing & CI
----------------

This package can be published to npm as a private (restricted) scoped package and automated via GitHub Actions.

1) Confirm package scope

- The package name in `package.json` is scoped (e.g. `@heyhef/api-client`). Make sure the scope (`@heyhef`) matches your npm organization or change it to your intended scope.

2) Create an npm automation token

- Go to https://www.npmjs.com/ (log in), then Account Settings -> Access Tokens -> Create New Token -> choose "Automation" (read & publish) and create the token. Copy it somewhere safe.

3) Add the token to GitHub Secrets

- In the GitHub repo: Settings -> Secrets -> Actions -> New repository secret
- Name: `NPM_TOKEN`
- Value: the token you created on npm

4) Verify CI workflow

- A workflow was added at `.github/workflows/publish-api-client.yml` which runs on push to `main` and will:
	- Build `packages/api-client`
	- Run `npm publish --access restricted` using `NODE_AUTH_TOKEN` from `${{ secrets.NPM_TOKEN }}`

5) Dry-run locally (optional)

You can run a dry-run to see what would be published:

```bash
cd packages/api-client
npm pack --dry-run
# or
npm publish --access restricted --dry-run
```

6) Publish manually (optional)

If you prefer to publish manually (instead of via CI), run:

```bash
cd packages/api-client
npm ci
npm run build
npm publish --access restricted
```

7) Local development alternatives

- To test the package locally without publishing, you can create a tarball and install it in the consumer project:

```bash
cd packages/api-client
npm pack
# in consumer
npm install ../api-client/api-client-0.1.0.tgz
```

- Or use `npm link` for local linking. If global `npm link` fails due to permissions, you can use a user prefix and run:

```bash
mkdir -p ~/.npm-global
npm_config_prefix=~/.npm-global npm link
# Then in consumer project:
npm_config_prefix=~/.npm-global npm link @heyhef/api-client
# ensure ~/.npm-global/bin is in your PATH:
export PATH="$HOME/.npm-global/bin:$PATH"
```

8) Token security

- Use an automation token scoped to publishing and rotate it periodically. Revoke tokens from npm account settings if compromised.

If you'd like, I can run a local `npm publish --access restricted --dry-run` for you to preview the publish contents, or prepare a PR that updates the package scope to your real npm org before you publish.