Install
Requirements
- Node.js >= 18 (native
fetch,crypto) - TypeScript >= 4.5 (optional)
Quick start
API overview
| Method | Description |
|---|---|
getProject() | Get project info |
listCodes(options?) | List codes (page, pageSize, status, search) |
getCode(codeId) | Get one code by ID |
getCodeByCode(code) | Get one code by code string |
verifyCode({ code, verifiedBy? }) | Verify (redeem) a code |
reactivateCode({ code, reactivatedBy?, reason? }) | Reactivate a used code |
getStatistics() | Project statistics |
pageSize, verifiedBy); the client converts to API snake_case.
Usage details
Pagination and filters
Verify result and error_code
Aside from 4xx/5xx (which throwCodeGateApiError), verify uses success and error_code:
Error handling
4xx/5xx throw CodeGateApiError with status and detail:
Retry and resilience
Retry a limited number of times on 5xx or network errors:Custom requests and generateSignature
For your own HTTP client, usegenerateSignature:
Environment variables
Use env vars for credentials in different environments:Development
Build
dist/: index.js (ESM), index.cjs, index.d.ts.
Tests
Examples
CODEGATE_API_KEY, CODEGATE_SECRET, CODEGATE_PROJECT_ID, CODEGATE_BASE_URL (optional).