22 * microCMS API SDK
33 * https://github.com/microcmsio/microcms-js-sdk
44 */
5- import fetch , { RequestInit } from 'node-fetch' ;
65import { parseQuery } from './utils/parseQuery' ;
76import { isString } from './utils/isCheckValue' ;
87import {
@@ -21,11 +20,16 @@ import {
2120 DeleteRequest ,
2221} from './types' ;
2322import { API_VERSION , BASE_DOMAIN } from './utils/constants' ;
23+ import { generateFetchClient } from './lib/fetch' ;
2424
2525/**
2626 * Initialize SDK Client
2727 */
28- export const createClient = ( { serviceDomain, apiKey } : MicroCMSClient ) => {
28+ export const createClient = ( {
29+ serviceDomain,
30+ apiKey,
31+ customFetch,
32+ } : MicroCMSClient ) => {
2933 if ( ! serviceDomain || ! apiKey ) {
3034 throw new Error ( 'parameter is required (check serviceDomain and apiKey)' ) ;
3135 }
@@ -50,20 +54,19 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
5054 customHeaders,
5155 customBody,
5256 } : MakeRequest ) => {
53- const queryString = parseQuery ( queries ) ;
54-
55- const baseHeaders : RequestInit = {
56- headers : { ...customHeaders , 'X-MICROCMS-API-KEY' : apiKey } ,
57- body : customBody ,
58- method,
59- } ;
57+ const fetchClient = generateFetchClient ( apiKey , customFetch ) ;
6058
59+ const queryString = parseQuery ( queries ) ;
6160 const url = `${ baseUrl } /${ endpoint } ${ contentId ? `/${ contentId } ` : '' } ${
6261 queryString ? `?${ queryString } ` : ''
6362 } `;
6463
6564 try {
66- const response = await fetch ( url , baseHeaders ) ;
65+ const response = await fetchClient ( url , {
66+ method : method || 'GET' ,
67+ headers : customHeaders ,
68+ body : customBody ,
69+ } ) ;
6770
6871 if ( ! response . ok ) {
6972 throw new Error ( `fetch API response status: ${ response . status } ` ) ;
@@ -179,7 +182,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
179182 } ;
180183
181184 /**
182- * Update content in ther microCMS list and object API data
185+ * Update content in their microCMS list and object API data
183186 */
184187 const update = async < T extends Record < string | number , any > > ( {
185188 endpoint,
@@ -206,7 +209,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
206209 } ;
207210
208211 /**
209- * Delete content in ther microCMS list and object API data
212+ * Delete content in their microCMS list and object API data
210213 */
211214 const _delete = async ( {
212215 endpoint,
0 commit comments