import { shopifyRequestRaw } from './lib/client.ts'
import type { ShopifyClientOptions } from './types.ts'
export type ShopifyRequestParams = ShopifyClientOptions & {
/** REST path such as `/products.json` or a full `/admin/...` path. */
path: string
method?: string
query?: Record<string, string | number | boolean | undefined | null>
body?: unknown
headers?: Record<string, string>
}
/**
* Send a raw Admin REST request (escape hatch for unwrapped resources).
*
* Paths without `/admin/` are prefixed with `/admin/api/{version}`.
*
* @example
* import { shopifyRequest } from 'kody:@kody/shopify/request'
* const result = await shopifyRequest({ shop: 'acme', path: '/shop.json' })
* // => { status: 200, body: { shop: { name: 'Acme' } }, shop: 'acme' }
*
* @see https://shopify.dev/docs/api/admin-rest
*/
export async function shopifyRequest(params: ShopifyRequestParams) {
const result = await shopifyRequestRaw(params)
return {
status: result.status,
ok: result.ok,
body: result.body,
shop: result.shop,
link: result.headers.link || result.headers.Link || null,
callLimit:
result.headers['x-shopify-shop-api-call-limit'] ||
result.headers['X-Shopify-Shop-Api-Call-Limit'] ||
null,
}
}
/** Default export: raw REST escape hatch. */
export default shopifyRequest