@heyhef/api-client
v0.0.1
Published
Generated TypeScript API client for the CRO platform
Maintainers
Readme
@heyhef/api-client
Generated TypeScript API client for the CRO platform (from api/openapi.yaml).
Quick start
- Install dependencies (from package root):
cd packages/api-client
npm install- Build the client (produces
dist/with JS + type declarations):
npm run build- Use in your app:
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
fetchto be available. In Node, we recommend installingcross-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.
- Confirm package scope
- The package name in
package.jsonis scoped (e.g.@heyhef/api-client). Make sure the scope (@heyhef) matches your npm organization or change it to your intended scope.
- 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.
- 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
- Verify CI workflow
- A workflow was added at
.github/workflows/publish-api-client.ymlwhich runs on push tomainand will:- Build
packages/api-client - Run
npm publish --access restrictedusingNODE_AUTH_TOKENfrom${{ secrets.NPM_TOKEN }}
- Build
- Dry-run locally (optional)
You can run a dry-run to see what would be published:
cd packages/api-client
npm pack --dry-run
# or
npm publish --access restricted --dry-run- Publish manually (optional)
If you prefer to publish manually (instead of via CI), run:
cd packages/api-client
npm ci
npm run build
npm publish --access restricted- Local development alternatives
- To test the package locally without publishing, you can create a tarball and install it in the consumer project:
cd packages/api-client
npm pack
# in consumer
npm install ../api-client/api-client-0.1.0.tgz- Or use
npm linkfor local linking. If globalnpm linkfails due to permissions, you can use a user prefix and run:
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"- 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.
