@spoosh/core 0.13.2 → 0.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -62,6 +62,7 @@ declare function urlencoded<T>(value: T): SpooshBody<T>;
62
62
  declare function resolveRequestBody(rawBody: unknown): {
63
63
  body: BodyInit;
64
64
  headers?: Record<string, string>;
65
+ removeHeaders?: string[];
65
66
  } | undefined;
66
67
 
67
68
  interface TransportResponse {
@@ -1723,6 +1724,7 @@ declare function setHeaders(requestOptions: {
1723
1724
  * Returns undefined if no Content-Type is set.
1724
1725
  */
1725
1726
  declare function getContentType(headers?: HeadersInit): string | undefined;
1727
+ declare function removeHeaderKeys(headers: HeadersInit | undefined, keysToRemove: string[]): HeadersInit | undefined;
1726
1728
 
1727
1729
  declare function objectToFormData(obj: Record<string, unknown>): FormData;
1728
1730
 
@@ -2017,4 +2019,4 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
2017
2019
  };
2018
2020
  declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest>): InfiniteReadController<TData, TItem, TError>;
2019
2021
 
2020
- export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
2022
+ export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, removeHeaderKeys, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
package/dist/index.d.ts CHANGED
@@ -62,6 +62,7 @@ declare function urlencoded<T>(value: T): SpooshBody<T>;
62
62
  declare function resolveRequestBody(rawBody: unknown): {
63
63
  body: BodyInit;
64
64
  headers?: Record<string, string>;
65
+ removeHeaders?: string[];
65
66
  } | undefined;
66
67
 
67
68
  interface TransportResponse {
@@ -1723,6 +1724,7 @@ declare function setHeaders(requestOptions: {
1723
1724
  * Returns undefined if no Content-Type is set.
1724
1725
  */
1725
1726
  declare function getContentType(headers?: HeadersInit): string | undefined;
1727
+ declare function removeHeaderKeys(headers: HeadersInit | undefined, keysToRemove: string[]): HeadersInit | undefined;
1726
1728
 
1727
1729
  declare function objectToFormData(obj: Record<string, unknown>): FormData;
1728
1730
 
@@ -2017,4 +2019,4 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
2017
2019
  };
2018
2020
  declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest>): InfiniteReadController<TData, TItem, TError>;
2019
2021
 
2020
- export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
2022
+ export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, removeHeaderKeys, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
package/dist/index.js CHANGED
@@ -52,6 +52,7 @@ __export(src_exports, {
52
52
  mergeHeaders: () => mergeHeaders,
53
53
  objectToFormData: () => objectToFormData,
54
54
  objectToUrlEncoded: () => objectToUrlEncoded,
55
+ removeHeaderKeys: () => removeHeaderKeys,
55
56
  resolveHeadersToRecord: () => resolveHeadersToRecord,
56
57
  resolvePath: () => resolvePath,
57
58
  resolvePathString: () => resolvePathString,
@@ -171,6 +172,15 @@ function getContentType(headers) {
171
172
  const headersObj = new Headers(headers);
172
173
  return headersObj.get("content-type") ?? void 0;
173
174
  }
175
+ function removeHeaderKeys(headers, keysToRemove) {
176
+ if (!headers) return void 0;
177
+ const headersObj = new Headers(headers);
178
+ for (const key of keysToRemove) {
179
+ headersObj.delete(key);
180
+ }
181
+ const entries = [...headersObj.entries()];
182
+ return entries.length > 0 ? Object.fromEntries(entries) : void 0;
183
+ }
174
184
 
175
185
  // src/utils/objectToFormData.ts
176
186
  function objectToFormData(obj) {
@@ -278,7 +288,8 @@ function resolveRequestBody(rawBody) {
278
288
  switch (body.kind) {
279
289
  case "form":
280
290
  return {
281
- body: objectToFormData(body.value)
291
+ body: objectToFormData(body.value),
292
+ removeHeaders: ["Content-Type"]
282
293
  };
283
294
  case "json":
284
295
  return {
@@ -303,6 +314,9 @@ function resolveRequestBody(rawBody) {
303
314
  headers: { "Content-Type": "application/json" }
304
315
  };
305
316
  }
317
+ if (rawBody instanceof FormData) {
318
+ return { body: rawBody, removeHeaders: ["Content-Type"] };
319
+ }
306
320
  return { body: rawBody };
307
321
  }
308
322
 
@@ -590,12 +604,13 @@ async function executeCoreFetch(config) {
590
604
  const resolved = resolveRequestBody(requestOptions.body);
591
605
  if (resolved) {
592
606
  fetchInit.body = resolved.body;
607
+ if (resolved.removeHeaders) {
608
+ headers = removeHeaderKeys(headers, resolved.removeHeaders);
609
+ }
593
610
  if (resolved.headers) {
594
611
  headers = await mergeHeaders(headers, resolved.headers);
595
- if (headers) {
596
- fetchInit.headers = headers;
597
- }
598
612
  }
613
+ fetchInit.headers = headers;
599
614
  }
600
615
  }
601
616
  const resolvedTransport = resolveTransport(
package/dist/index.mjs CHANGED
@@ -105,6 +105,15 @@ function getContentType(headers) {
105
105
  const headersObj = new Headers(headers);
106
106
  return headersObj.get("content-type") ?? void 0;
107
107
  }
108
+ function removeHeaderKeys(headers, keysToRemove) {
109
+ if (!headers) return void 0;
110
+ const headersObj = new Headers(headers);
111
+ for (const key of keysToRemove) {
112
+ headersObj.delete(key);
113
+ }
114
+ const entries = [...headersObj.entries()];
115
+ return entries.length > 0 ? Object.fromEntries(entries) : void 0;
116
+ }
108
117
 
109
118
  // src/utils/objectToFormData.ts
110
119
  function objectToFormData(obj) {
@@ -212,7 +221,8 @@ function resolveRequestBody(rawBody) {
212
221
  switch (body.kind) {
213
222
  case "form":
214
223
  return {
215
- body: objectToFormData(body.value)
224
+ body: objectToFormData(body.value),
225
+ removeHeaders: ["Content-Type"]
216
226
  };
217
227
  case "json":
218
228
  return {
@@ -237,6 +247,9 @@ function resolveRequestBody(rawBody) {
237
247
  headers: { "Content-Type": "application/json" }
238
248
  };
239
249
  }
250
+ if (rawBody instanceof FormData) {
251
+ return { body: rawBody, removeHeaders: ["Content-Type"] };
252
+ }
240
253
  return { body: rawBody };
241
254
  }
242
255
 
@@ -524,12 +537,13 @@ async function executeCoreFetch(config) {
524
537
  const resolved = resolveRequestBody(requestOptions.body);
525
538
  if (resolved) {
526
539
  fetchInit.body = resolved.body;
540
+ if (resolved.removeHeaders) {
541
+ headers = removeHeaderKeys(headers, resolved.removeHeaders);
542
+ }
527
543
  if (resolved.headers) {
528
544
  headers = await mergeHeaders(headers, resolved.headers);
529
- if (headers) {
530
- fetchInit.headers = headers;
531
- }
532
545
  }
546
+ fetchInit.headers = headers;
533
547
  }
534
548
  }
535
549
  const resolvedTransport = resolveTransport(
@@ -1781,6 +1795,7 @@ export {
1781
1795
  mergeHeaders,
1782
1796
  objectToFormData,
1783
1797
  objectToUrlEncoded,
1798
+ removeHeaderKeys,
1784
1799
  resolveHeadersToRecord,
1785
1800
  resolvePath,
1786
1801
  resolvePathString,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/core",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "license": "MIT",
5
5
  "description": "Type-safe API toolkit with plugin middleware system",
6
6
  "keywords": [