@open-mercato/client
v0.3.5
Published
Typed API client for the Open Mercato platform, generated directly from the monorepo's OpenAPI specification. Full product docs live at https://docs.openmercato.com and the hosted API explorer is available at https://demo.openmercato.com/docs/api. Project
Readme
@open-mercato/client
Typed API client for the Open Mercato platform, generated directly from the monorepo's OpenAPI specification. Full product docs live at https://docs.openmercato.com and the hosted API explorer is available at https://demo.openmercato.com/docs/api. Project homepage: https://github.com/open-mercato/open-mercato.
Installation
npm install @open-mercato/clientUsage
import { createOpenMercatoClient } from '@open-mercato/client'
const client = createOpenMercatoClient({
baseUrl: 'https://api.your-mercato.com/api',
accessToken: async () => process.env.OPEN_MERCATO_TOKEN,
})
const { data, error } = await client.GET('/customers/customers/people', {
params: { query: { page: 1, pageSize: 20 } },
})
if (error) throw new Error(error.message ?? 'Request failed')
console.log('people', data?.items)The call above is fully typed: data is inferred from the OpenAPI definition for /customers/customers/people. You can also extract the generated type for explicit reuse:
import type { operations } from '@open-mercato/client'
type ListPeopleResponse = operations['customers_get_customers_customers_people']['responses']['200']['content']['application/json']To discover every available operation name, inspect keyof operations:
import type { operations } from '@open-mercato/client'
type OperationName = keyof operations
// hover OperationName to see strings like 'auth_get_auth_users', 'customers_post_customers_customers_people', etc.Base URL resolution
If baseUrl is omitted the client tries, in order, OPEN_MERCATO_API_BASE_URL, NEXT_PUBLIC_API_BASE_URL, NEXT_PUBLIC_APP_URL, APP_URL, then defaults to http://localhost:3000/api.
Authentication
Pass a string or async function via accessToken. Values are normalized to Authorization: Bearer <token> automatically. You may also register custom Middleware when creating the client for advanced flows (retry, tracing, etc.).
Regenerating types locally
yarn client:generateThis script builds the OpenAPI document from enabled modules, normalizes recursive schemas, and re-runs openapi-typescript to refresh src/generated/openapi.types.ts.
Publishing to npm
- Ensure artifacts are up to date:
yarn client:generate && yarn workspace @open-mercato/client build. - From repo root, publish the workspace:
(Or usenpm publish packages/client --access publicyarn npm publish --access public --workspace @open-mercato/client). - Tag/commit as needed for release automation.
The package's
filesentry only shipsdist/andsrc/generated/, so remember to runtscbefore publishing.
