@oliver_nexro/zod_api
Advanced tools
Comparing version 0.7.4 to 0.7.5
@@ -19,3 +19,3 @@ import type { ApiBodyfullActionConfig, ApiClientConfig, ApiResourceConfig, Fetcher, Path, PathlessApiResourceConfig, PossibleApiClientActionParams } from "../types.js"; | ||
*/ | ||
export declare function createRequestParams(apiClientConfig: ApiClientConfig<Fetcher>, params: PossibleApiClientActionParams | undefined): RequestInit; | ||
export declare function createRequestParams(apiClientConfig: ApiClientConfig<Fetcher>, actionConfig: ApiBodyfullActionConfig, params: PossibleApiClientActionParams | undefined): RequestInit; | ||
/** | ||
@@ -22,0 +22,0 @@ * Create request body |
@@ -83,3 +83,3 @@ export function parseParams(resourceConfig, actionConfig, params) { | ||
*/ | ||
export function createRequestParams(apiClientConfig, params) { | ||
export function createRequestParams(apiClientConfig, actionConfig, params) { | ||
// Create param headers | ||
@@ -89,2 +89,12 @@ const paramHeaderEntries = Object.entries(params?.headers ?? {}); | ||
const paramHeaders = Object.fromEntries(stringifiedParamHeaderEntries); | ||
// Set content type header if request contains body | ||
const bodyType = actionConfig?.bodyType ?? "JSON"; | ||
const contentType = bodyType === "JSON" | ||
? "application/json" | ||
: "application/x-www-form-urlencoded"; | ||
const contentTypeHeaderEntry = actionConfig.bodySchema | ||
? { | ||
"Content-Type": contentType, | ||
} | ||
: undefined; | ||
// Merge in increasing priority | ||
@@ -95,2 +105,3 @@ return { | ||
headers: { | ||
...contentTypeHeaderEntry, | ||
...apiClientConfig.requestParams?.headers, | ||
@@ -97,0 +108,0 @@ ...paramHeaders, |
@@ -19,3 +19,3 @@ import { createBody, createRequestParams, createUrl, parseParams, } from "./request_params.js"; | ||
const url = createUrl(resourceConfig, apiClientConfig, parsedParams); | ||
const requestParams = createRequestParams(apiClientConfig, parsedParams); | ||
const requestParams = createRequestParams(apiClientConfig, actionConfig, parsedParams); | ||
const body = createBody(actionConfig, parsedParams); | ||
@@ -22,0 +22,0 @@ const requestInit = { |
@@ -5,3 +5,3 @@ { | ||
"name": "@oliver_nexro/zod_api", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"description": "Configure API clients using Zod schemas for type-safety and interpreted action methods.", | ||
@@ -8,0 +8,0 @@ "license": "MIT", |
@@ -19,3 +19,3 @@ import type { ApiBodyfullActionConfig, ApiClientConfig, ApiResourceConfig, Fetcher, Path, PathlessApiResourceConfig, PossibleApiClientActionParams } from "../types.js"; | ||
*/ | ||
export declare function createRequestParams(apiClientConfig: ApiClientConfig<Fetcher>, params: PossibleApiClientActionParams | undefined): RequestInit; | ||
export declare function createRequestParams(apiClientConfig: ApiClientConfig<Fetcher>, actionConfig: ApiBodyfullActionConfig, params: PossibleApiClientActionParams | undefined): RequestInit; | ||
/** | ||
@@ -22,0 +22,0 @@ * Create request body |
@@ -88,3 +88,3 @@ "use strict"; | ||
*/ | ||
function createRequestParams(apiClientConfig, params) { | ||
function createRequestParams(apiClientConfig, actionConfig, params) { | ||
// Create param headers | ||
@@ -94,2 +94,12 @@ const paramHeaderEntries = Object.entries(params?.headers ?? {}); | ||
const paramHeaders = Object.fromEntries(stringifiedParamHeaderEntries); | ||
// Set content type header if request contains body | ||
const bodyType = actionConfig?.bodyType ?? "JSON"; | ||
const contentType = bodyType === "JSON" | ||
? "application/json" | ||
: "application/x-www-form-urlencoded"; | ||
const contentTypeHeaderEntry = actionConfig.bodySchema | ||
? { | ||
"Content-Type": contentType, | ||
} | ||
: undefined; | ||
// Merge in increasing priority | ||
@@ -100,2 +110,3 @@ return { | ||
headers: { | ||
...contentTypeHeaderEntry, | ||
...apiClientConfig.requestParams?.headers, | ||
@@ -102,0 +113,0 @@ ...paramHeaders, |
@@ -22,3 +22,3 @@ "use strict"; | ||
const url = (0, request_params_js_1.createUrl)(resourceConfig, apiClientConfig, parsedParams); | ||
const requestParams = (0, request_params_js_1.createRequestParams)(apiClientConfig, parsedParams); | ||
const requestParams = (0, request_params_js_1.createRequestParams)(apiClientConfig, actionConfig, parsedParams); | ||
const body = (0, request_params_js_1.createBody)(actionConfig, parsedParams); | ||
@@ -25,0 +25,0 @@ const requestInit = { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73573
1749