{
  "version": 3,
  "sources": ["../../src/middlewares/root-url.ts"],
  "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\nimport namespaceAndEndpointMiddleware from './namespace-endpoint';\n\n/**\n * @param rootURL\n * @return  Root URL middleware.\n */\nconst createRootURLMiddleware =\n\t( rootURL: string ): APIFetchMiddleware =>\n\t( options, next ) => {\n\t\treturn namespaceAndEndpointMiddleware( options, ( optionsWithPath ) => {\n\t\t\tlet url = optionsWithPath.url;\n\t\t\tlet path = optionsWithPath.path;\n\t\t\tlet apiRoot;\n\n\t\t\tif ( typeof path === 'string' ) {\n\t\t\t\tapiRoot = rootURL;\n\n\t\t\t\tif ( -1 !== rootURL.indexOf( '?' ) ) {\n\t\t\t\t\tpath = path.replace( '?', '&' );\n\t\t\t\t}\n\n\t\t\t\tpath = path.replace( /^\\//, '' );\n\n\t\t\t\t// API root may already include query parameter prefix if site is\n\t\t\t\t// configured to use plain permalinks.\n\t\t\t\tif (\n\t\t\t\t\t'string' === typeof apiRoot &&\n\t\t\t\t\t-1 !== apiRoot.indexOf( '?' )\n\t\t\t\t) {\n\t\t\t\t\tpath = path.replace( '?', '&' );\n\t\t\t\t}\n\n\t\t\t\turl = apiRoot + path;\n\t\t\t}\n\n\t\t\treturn next( {\n\t\t\t\t...optionsWithPath,\n\t\t\t\turl,\n\t\t\t} );\n\t\t} );\n\t};\n\nexport default createRootURLMiddleware;\n"],
  "mappings": ";AAIA,OAAO,oCAAoC;AAM3C,IAAM,0BACL,CAAE,YACF,CAAE,SAAS,SAAU;AACpB,SAAO,+BAAgC,SAAS,CAAE,oBAAqB;AACtE,QAAI,MAAM,gBAAgB;AAC1B,QAAI,OAAO,gBAAgB;AAC3B,QAAI;AAEJ,QAAK,OAAO,SAAS,UAAW;AAC/B,gBAAU;AAEV,UAAK,OAAO,QAAQ,QAAS,GAAI,GAAI;AACpC,eAAO,KAAK,QAAS,KAAK,GAAI;AAAA,MAC/B;AAEA,aAAO,KAAK,QAAS,OAAO,EAAG;AAI/B,UACC,aAAa,OAAO,WACpB,OAAO,QAAQ,QAAS,GAAI,GAC3B;AACD,eAAO,KAAK,QAAS,KAAK,GAAI;AAAA,MAC/B;AAEA,YAAM,UAAU;AAAA,IACjB;AAEA,WAAO,KAAM;AAAA,MACZ,GAAG;AAAA,MACH;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AACH;AAED,IAAO,mBAAQ;",
  "names": []
}
