@hey-api/openapi-ts 0.86.4 → 0.86.6

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.cjs CHANGED
@@ -1,1318 +1 @@
1
- const e=require(`./getSpec-6kHHn13e.cjs`);let t=require(`@hey-api/codegen-core`);t=e.R(t);let n=require(`ansi-colors`);n=e.R(n);let r=require(`color-support`);r=e.R(r);let i=require(`node:fs`);i=e.R(i);let a=require(`node:path`);a=e.R(a);let o=require(`@hey-api/json-schema-ref-parser`);o=e.R(o);let s=require(`handlebars`);s=e.R(s);const c=()=>{if(typeof Bun<`u`){let[t]=Bun.version.split(`.`).map(Number);if(t<1)throw new e.D(`Unsupported Bun version ${Bun.version}. Please use Bun 1.0.0 or newer.`)}else if(typeof process<`u`&&process.versions?.node){let[t]=process.versions.node.split(`.`).map(Number);if(t<20)throw new e.D(`Unsupported Node version ${process.versions.node}. Please use Node 20 or newer.`)}},l=e=>{switch(e){case`legacy/angular`:return`AngularHttpRequest`;case`legacy/axios`:return`AxiosHttpRequest`;case`legacy/fetch`:return`FetchHttpRequest`;case`legacy/node`:return`NodeHttpRequest`;case`legacy/xhr`:return`XHRHttpRequest`;default:return``}},u=async(t,n,r,o)=>{let s=e.C(),c=e.E(s),u=o.client({$config:s,...r,httpRequest:l(c.name),models:e.f(r.models),services:e.f(r.services)});e.T(s)&&(e.P(n),i.default.writeFileSync(a.default.resolve(n,`${e.T(s)}.ts`),u))},d=async(t,n,r)=>{let o=e.C();if(o.exportCore){let s=e.E(o),c={httpRequest:l(s.name),server:o.base===void 0?n.server:o.base,version:n.version};if(i.default.rmSync(a.default.resolve(t),{force:!0,recursive:!0}),i.default.mkdirSync(a.default.resolve(t),{recursive:!0}),await i.default.writeFileSync(a.default.resolve(t,`OpenAPI.ts`),r.core.settings({$config:o,...c})),await i.default.writeFileSync(a.default.resolve(t,`ApiError.ts`),r.core.apiError({$config:o,...c})),await i.default.writeFileSync(a.default.resolve(t,`ApiRequestOptions.ts`),r.core.apiRequestOptions({$config:o,...c})),await i.default.writeFileSync(a.default.resolve(t,`ApiResult.ts`),r.core.apiResult({$config:o,...c})),s.name!==`legacy/angular`&&await i.default.writeFileSync(a.default.resolve(t,`CancelablePromise.ts`),r.core.cancelablePromise({$config:o,...c})),await i.default.writeFileSync(a.default.resolve(t,`request.ts`),r.core.request({$config:o,...c})),e.T(o)&&(await i.default.writeFileSync(a.default.resolve(t,`BaseHttpRequest.ts`),r.core.baseHttpRequest({$config:o,...c})),await i.default.writeFileSync(a.default.resolve(t,`${c.httpRequest}.ts`),r.core.httpRequest({$config:o,...c}))),o.request){let e=a.default.resolve(process.cwd(),o.request);if(!await i.default.existsSync(e))throw Error(`Custom request file "${e}" does not exists`);await i.default.copyFileSync(e,a.default.resolve(t,`request.ts`))}}},f=({files:t})=>{let n=e.C();t.index=new e.i({dir:n.output.path,id:`index`,name:`index.ts`}),e.T(n)&&t.index.add(e.v.exportNamedDeclaration({exports:e.T(n),module:`./${e.T(n)}`})),n.exportCore&&(t.index.add(e.v.exportNamedDeclaration({exports:`ApiError`,module:`./core/ApiError`})),n.plugins[`@hey-api/sdk`]?.config.response===`response`&&t.index.add(e.v.exportNamedDeclaration({exports:{asType:!0,name:`ApiResult`},module:`./core/ApiResult`})),e.T(n)&&t.index.add(e.v.exportNamedDeclaration({exports:`BaseHttpRequest`,module:`./core/BaseHttpRequest`})),e.E(n).name!==`legacy/angular`&&t.index.add(e.v.exportNamedDeclaration({exports:[`CancelablePromise`,`CancelError`],module:`./core/CancelablePromise`})),t.index.add(e.v.exportNamedDeclaration({exports:[`OpenAPI`,{asType:!0,name:`OpenAPIConfig`}],module:`./core/OpenAPI`}))),Object.keys(t).sort().forEach(n=>{let r=t[n];n===`index`||r.isEmpty()||r.exportFromIndex&&t.index.add(e.v.exportAllDeclaration({module:`./${r.nameWithoutExtension()}`}))})},p=async({client:t,openApi:n,templates:r})=>{let i=e.C(),o=n;if(t){if(i.plugins[`@hey-api/sdk`]?.config.include&&i.plugins[`@hey-api/sdk`].config.asClass){let e=new RegExp(i.plugins[`@hey-api/sdk`].config.include);t.services=t.services.filter(t=>e.test(t.name))}if(i.plugins[`@hey-api/typescript`]?.config.include){let e=new RegExp(i.plugins[`@hey-api/typescript`].config.include);t.models=t.models.filter(t=>e.test(t.name))}}let s=a.default.resolve(i.output.path);i.output.clean&&e.F(s);let c=e.E(i);!e.w(i)&&`bundle`in c.config&&c.config.bundle&&e.o({meta:{importFileExtension:i.output.importFileExtension},outputPath:s,plugin:c}),await u(o,s,t,r),await d(a.default.resolve(i.output.path,`core`),t,r);let l={};for(let n of i.pluginOrder){let r=i.plugins[n],s=(r.output??``).split(`/`),c=a.default.resolve(i.output.path,...s.slice(0,s.length-1));l[r.name]=new e.i({dir:c,id:`legacy-unused-${r.name}`,name:`${s[s.length-1]}.ts`}),r.handlerLegacy?.({client:t,files:l,openApi:o,plugin:r})}f({files:l}),Object.entries(l).forEach(([e,t])=>{i.dryRun||(e===`index`?t.write(`
2
- `,i.output.tsConfig):t.write(`
3
-
4
- `,i.output.tsConfig))})},m=async({context:t})=>{let n=a.default.resolve(t.config.output.path);t.config.output.clean&&e.F(n);let r={importFileExtension:t.config.output.importFileExtension},o=e.E(t.config);`bundle`in o.config&&o.config.bundle&&(t.config._FRAGILE_CLIENT_BUNDLE_RENAMED=e.o({meta:r,outputPath:n,plugin:o,project:t.gen}));for(let e of t.registerPlugins())await e.run();for(let e of t.gen.render(r)){let r=a.default.resolve(n,e.path),o=a.default.dirname(r);t.config.dryRun||(i.default.mkdirSync(o,{recursive:!0}),i.default.writeFileSync(r,e.content,{encoding:`utf8`}))}},h=({patchOptions:e,spec:t})=>{if(!e)return;let n=t;if(`swagger`in n){if(e.version&&n.swagger&&(n.swagger=typeof e.version==`string`?e.version:e.version(n.swagger)),e.meta&&n.info&&e.meta(n.info),e.schemas&&n.definitions)for(let t in e.schemas){let r=n.definitions[t];if(!r||typeof r!=`object`)continue;let i=e.schemas[t];i(r)}if(e.operations&&n.paths)for(let t in e.operations){let[r,i]=t.split(` `);if(!r||!i)continue;let a=n.paths[i];if(!a)continue;let o=a[r.toLocaleLowerCase()]||a[r.toLocaleUpperCase()];if(!o||typeof o!=`object`)continue;let s=e.operations[t];s(o)}return}if(e.version&&n.openapi&&(n.openapi=typeof e.version==`string`?e.version:e.version(n.openapi)),e.meta&&n.info&&e.meta(n.info),n.components){if(e.schemas&&n.components.schemas)for(let t in e.schemas){let r=n.components.schemas[t];if(!r||typeof r!=`object`)continue;let i=e.schemas[t];i(r)}if(e.parameters&&n.components.parameters)for(let t in e.parameters){let r=n.components.parameters[t];if(!r||typeof r!=`object`)continue;let i=e.parameters[t];i(r)}if(e.requestBodies&&n.components.requestBodies)for(let t in e.requestBodies){let r=n.components.requestBodies[t];if(!r||typeof r!=`object`)continue;let i=e.requestBodies[t];i(r)}if(e.responses&&n.components.responses)for(let t in e.responses){let r=n.components.responses[t];if(!r||typeof r!=`object`)continue;let i=e.responses[t];i(r)}}if(e.operations&&n.paths)for(let t in e.operations){let[r,i]=t.split(` `);if(!r||!i)continue;let a=n.paths[i];if(!a)continue;let o=a[r.toLocaleLowerCase()]||a[r.toLocaleUpperCase()];if(!o||typeof o!=`object`)continue;let s=e.operations[t];s(o)}};var g=e.L(((e,t)=>{t.exports=a,a.sync=o;var n=require(`fs`);function r(e,t){var n=t.pathExt===void 0?process.env.PATHEXT:t.pathExt;if(!n||(n=n.split(`;`),n.indexOf(``)!==-1))return!0;for(var r=0;r<n.length;r++){var i=n[r].toLowerCase();if(i&&e.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(e,t,n){return!e.isSymbolicLink()&&!e.isFile()?!1:r(t,n)}function a(e,t,r){n.stat(e,function(n,a){r(n,n?!1:i(a,e,t))})}function o(e,t){return i(n.statSync(e),e,t)}})),_=e.L(((e,t)=>{t.exports=r,r.sync=i;var n=require(`fs`);function r(e,t,r){n.stat(e,function(e,n){r(e,e?!1:a(n,t))})}function i(e,t){return a(n.statSync(e),t)}function a(e,t){return e.isFile()&&o(e,t)}function o(e,t){var n=e.mode,r=e.uid,i=e.gid,a=t.uid===void 0?process.getuid&&process.getuid():t.uid,o=t.gid===void 0?process.getgid&&process.getgid():t.gid,s=64,c=8,l=1,u=s|c;return n&l||n&c&&i===o||n&s&&r===a||n&u&&a===0}})),v=e.L(((e,t)=>{require(`fs`);var n=process.platform===`win32`||global.TESTING_WINDOWS?g():_();t.exports=r,r.sync=i;function r(e,t,i){if(typeof t==`function`&&(i=t,t={}),!i){if(typeof Promise!=`function`)throw TypeError(`callback not provided`);return new Promise(function(n,i){r(e,t||{},function(e,t){e?i(e):n(t)})})}n(e,t||{},function(e,n){e&&(e.code===`EACCES`||t&&t.ignoreErrors)&&(e=null,n=!1),i(e,n)})}function i(e,t){try{return n.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||e.code===`EACCES`)return!1;throw e}}})),y=e.L(((e,t)=>{let n=process.platform===`win32`||process.env.OSTYPE===`cygwin`||process.env.OSTYPE===`msys`,r=require(`path`),i=n?`;`:`:`,a=v(),o=e=>Object.assign(Error(`not found: ${e}`),{code:`ENOENT`}),s=(e,t)=>{let r=t.colon||i,a=e.match(/\//)||n&&e.match(/\\/)?[``]:[...n?[process.cwd()]:[],...(t.path||process.env.PATH||``).split(r)],o=n?t.pathExt||process.env.PATHEXT||`.EXE;.CMD;.BAT;.COM`:``,s=n?o.split(r):[``];return n&&e.indexOf(`.`)!==-1&&s[0]!==``&&s.unshift(``),{pathEnv:a,pathExt:s,pathExtExe:o}},c=(e,t,n)=>{typeof t==`function`&&(n=t,t={}),t||={};let{pathEnv:i,pathExt:c,pathExtExe:l}=s(e,t),u=[],d=n=>new Promise((a,s)=>{if(n===i.length)return t.all&&u.length?a(u):s(o(e));let c=i[n],l=/^".*"$/.test(c)?c.slice(1,-1):c,d=r.join(l,e);a(f(!l&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d,n,0))}),f=(e,n,r)=>new Promise((i,o)=>{if(r===c.length)return i(d(n+1));let s=c[r];a(e+s,{pathExt:l},(a,o)=>{if(!a&&o)if(t.all)u.push(e+s);else return i(e+s);return i(f(e,n,r+1))})});return n?d(0).then(e=>n(null,e),n):d(0)};t.exports=c,c.sync=(e,t)=>{t||={};let{pathEnv:n,pathExt:i,pathExtExe:c}=s(e,t),l=[];for(let o=0;o<n.length;o++){let s=n[o],u=/^".*"$/.test(s)?s.slice(1,-1):s,d=r.join(u,e),f=!u&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d;for(let e=0;e<i.length;e++){let n=f+i[e];try{if(a.sync(n,{pathExt:c}))if(t.all)l.push(n);else return n}catch{}}}if(t.all&&l.length)return l;if(t.nothrow)return null;throw o(e)}})),b=e.L(((e,t)=>{let n=(e={})=>{let t=e.env||process.env;return(e.platform||process.platform)===`win32`?Object.keys(t).reverse().find(e=>e.toUpperCase()===`PATH`)||`Path`:`PATH`};t.exports=n,t.exports.default=n})),x=e.L(((e,t)=>{let n=require(`path`),r=y(),i=b();function a(e,t){let a=e.options.env||process.env,o=process.cwd(),s=e.options.cwd!=null,c=s&&process.chdir!==void 0&&!process.chdir.disabled;if(c)try{process.chdir(e.options.cwd)}catch{}let l;try{l=r.sync(e.command,{path:a[i({env:a})],pathExt:t?n.delimiter:void 0})}catch{}finally{c&&process.chdir(o)}return l&&=n.resolve(s?e.options.cwd:``,l),l}function o(e){return a(e)||a(e,!0)}t.exports=o})),S=e.L(((e,t)=>{let n=/([()\][%!^"`<>&|;, *?])/g;function r(e){return e=e.replace(n,`^$1`),e}function i(e,t){return e=`${e}`,e=e.replace(/(?=(\\+?)?)\1"/g,`$1$1\\"`),e=e.replace(/(?=(\\+?)?)\1$/,`$1$1`),e=`"${e}"`,e=e.replace(n,`^$1`),t&&(e=e.replace(n,`^$1`)),e}t.exports.command=r,t.exports.argument=i})),ee=e.L(((e,t)=>{t.exports=/^#!(.*)/})),C=e.L(((e,t)=>{let n=ee();t.exports=(e=``)=>{let t=e.match(n);if(!t)return null;let[r,i]=t[0].replace(/#! ?/,``).split(` `),a=r.split(`/`).pop();return a===`env`?i:i?`${a} ${i}`:a}})),w=e.L(((e,t)=>{let n=require(`fs`),r=C();function i(e){let t=Buffer.alloc(150),i;try{i=n.openSync(e,`r`),n.readSync(i,t,0,150,0),n.closeSync(i)}catch{}return r(t.toString())}t.exports=i})),te=e.L(((e,t)=>{let n=require(`path`),r=x(),i=S(),a=w(),o=process.platform===`win32`,s=/\.(?:com|exe)$/i,c=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function l(e){e.file=r(e);let t=e.file&&a(e.file);return t?(e.args.unshift(e.file),e.command=t,r(e)):e.file}function u(e){if(!o)return e;let t=l(e),r=!s.test(t);if(e.options.forceShell||r){let r=c.test(t);e.command=n.normalize(e.command),e.command=i.command(e.command),e.args=e.args.map(e=>i.argument(e,r)),e.args=[`/d`,`/s`,`/c`,`"${[e.command].concat(e.args).join(` `)}"`],e.command=process.env.comspec||`cmd.exe`,e.options.windowsVerbatimArguments=!0}return e}function d(e,t,n){t&&!Array.isArray(t)&&(n=t,t=null),t=t?t.slice(0):[],n=Object.assign({},n);let r={command:e,args:t,options:n,file:void 0,original:{command:e,args:t}};return n.shell?r:u(r)}t.exports=d})),ne=e.L(((e,t)=>{let n=process.platform===`win32`;function r(e,t){return Object.assign(Error(`${t} ${e.command} ENOENT`),{code:`ENOENT`,errno:`ENOENT`,syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}function i(e,t){if(!n)return;let r=e.emit;e.emit=function(n,i){if(n===`exit`){let n=a(i,t);if(n)return r.call(e,`error`,n)}return r.apply(e,arguments)}}function a(e,t){return n&&e===1&&!t.file?r(t.original,`spawn`):null}function o(e,t){return n&&e===1&&!t.file?r(t.original,`spawnSync`):null}t.exports={hookChildProcess:i,verifyENOENT:a,verifyENOENTSync:o,notFoundError:r}})),re=e.L(((e,t)=>{let n=require(`child_process`),r=te(),i=ne();function a(e,t,a){let o=r(e,t,a),s=n.spawn(o.command,o.args,o.options);return i.hookChildProcess(s,o),s}function o(e,t,a){let o=r(e,t,a),s=n.spawnSync(o.command,o.args,o.options);return s.error=s.error||i.verifyENOENTSync(s.status,o),s}t.exports=a,t.exports.spawn=a,t.exports.sync=o,t.exports._parse=r,t.exports._enoent=i})),T=e.R(re(),1);const ie={biome:{args:e=>[`format`,`--write`,e],command:`biome`,name:`Biome (Format)`},prettier:{args:e=>[`--ignore-unknown`,e,`--write`,`--ignore-path`,`./.prettierignore`],command:`prettier`,name:`Prettier`}},ae={biome:{args:e=>[`lint`,`--apply`,e],command:`biome`,name:`Biome (Lint)`},eslint:{args:e=>[e,`--fix`],command:`eslint`,name:`ESLint`},oxlint:{args:e=>[`--fix`,e],command:`oxlint`,name:`oxlint`}},oe=({config:e})=>{if(e.output.format){let t=ie[e.output.format];console.log(`✨ Running ${t.name}`),(0,T.sync)(t.command,t.args(e.output.path))}if(e.output.lint){let t=ae[e.output.lint];console.log(`✨ Running ${t.name}`),(0,T.sync)(t.command,t.args(e.output.path))}};function E(e,t){return{...e,config:t,models:e.models.map(e=>D(e)),services:O(e.operations).map(k),types:{}}}const D=t=>({...t,$refs:t.$refs.filter((t,n,r)=>e.p(t,n,r)),enum:t.enum.filter((e,t,n)=>n.findIndex(t=>t.value===e.value)===t),enums:t.enums.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t),imports:t.imports.filter((n,r,i)=>e.p(n,r,i)&&n!==t.name).sort(e.d)}),O=t=>{let n=e.C(),r=new Map;return t.forEach(t=>{(t.tags?.length&&(n.plugins[`@hey-api/sdk`]?.config.asClass||e.T(n))?t.tags.filter(e.p):[`Default`]).forEach(e=>{let n={...t,service:M(e)},i=r.get(n.service)||j(n);i.$refs=[...i.$refs,...n.$refs],i.imports=[...i.imports,...n.imports],i.operations=[...i.operations,n],r.set(n.service,i)})}),Array.from(r.values())},k=t=>{let n={...t};return n.operations=A(n),n.operations.forEach(e=>{n.imports.push(...e.imports)}),n.imports=n.imports.filter(e.p).sort(e.d),n},A=e=>{let t=new Map;return e.operations.map(e=>{let n={...e};n.imports.push(...n.parameters.flatMap(e=>e.imports));let r=n.responses.filter(e=>e.responseTypes.includes(`success`));n.imports.push(...r.flatMap(e=>e.imports));let i=n.name,a=t.get(i)||0;return a>0&&(n.name=`${i}${a}`),t.set(i,a+1),n})},j=e=>({$refs:[],imports:[],name:e.service,operations:[]}),M=t=>e.y({case:`PascalCase`,value:e.g(t)}),N=e=>{let t={...e,path:``};if(e.path&&(typeof e.path!=`string`||e.registry!==`hey-api`))return t.path=e.path,t;let[n,r]=e.path.split(`?`),i=(r||``).split(`&`).map(e=>e.split(`=`)),a=n||``;a.endsWith(`/`)&&(a=a.slice(0,a.length-1));let[,o]=a.split(`://`),[s,c,l]=(o||``).split(`/`);t.organization=c||e.organization,t.project=l||e.project;let u=[],d=`api_key`;t.api_key=i.find(([e])=>e===d)?.[1]||e.api_key||process.env.HEY_API_TOKEN,t.api_key&&u.push(`${d}=${t.api_key}`);let f=`branch`;t.branch=i.find(([e])=>e===f)?.[1]||e.branch,t.branch&&u.push(`${f}=${t.branch}`);let p=`commit_sha`;t.commit_sha=i.find(([e])=>e===p)?.[1]||e.commit_sha,t.commit_sha&&u.push(`${p}=${t.commit_sha}`);let m=`tags`;t.tags=i.find(([e])=>e===m)?.[1]?.split(`,`)||e.tags,t.tags?.length&&u.push(`${m}=${t.tags.join(`,`)}`);let h=`version`;if(t.version=i.find(([e])=>e===h)?.[1]||e.version,t.version&&u.push(`${h}=${t.version}`),!t.organization)throw Error(`missing organization - from which Hey API Platform organization do you want to generate your output?`);if(!t.project)throw Error(`missing project - from which Hey API Platform project do you want to generate your output?`);let g=u.join(`&`),_=s||`get.heyapi.dev`,v=_.startsWith(`localhost`),y=[v?`http`:`https`,_].join(`://`),b=v?[y,`v1`,`get`,t.organization,t.project].join(`/`):[y,t.organization,t.project].join(`/`);return t.path=g?`${b}?${g}`:b,t},P=(e,t)=>{let r=[],i=n.default.gray(`[Job ${t+1}] `),a=e.length,o=n.default.cyan(`Generating from ${a} ${a===1?`input`:`inputs`}:`);r.push(`${i}⏳ ${o}`),e.forEach((e,t)=>{let a=` [${t+1}] `,o=n.default.cyan(a),s=` `.repeat(a.length);if(typeof e.path!=`string`){r.push(`${i}${o}raw OpenAPI specification`);return}switch(e.registry){case`hey-api`:{let t=[e.organization,e.project].filter(Boolean).join(`/`);r.push(`${i}${o}${t}`),e.branch&&r.push(`${i}${s}${n.default.gray(`branch:`)} ${n.default.green(e.branch)}`),e.commit_sha&&r.push(`${i}${s}${n.default.gray(`commit:`)} ${n.default.green(e.commit_sha)}`),e.tags?.length&&r.push(`${i}${s}${n.default.gray(`tags:`)} ${n.default.green(e.tags.join(`, `))}`),e.version&&r.push(`${i}${s}${n.default.gray(`version:`)} ${n.default.green(e.version)}`),r.push(`${i}${s}${n.default.gray(`registry:`)} ${n.default.green(`Hey API`)}`);break}case`readme`:{let t=[e.organization,e.project].filter(Boolean).join(`/`);t?r.push(`${i}${o}${t}`):r.push(`${i}${o}${e.path}`),e.uuid&&r.push(`${i}${s}${n.default.gray(`uuid:`)} ${n.default.green(e.uuid)}`),r.push(`${i}${s}${n.default.gray(`registry:`)} ${n.default.green(`ReadMe`)}`);break}case`scalar`:{let t=[e.organization,e.project].filter(Boolean).join(`/`);r.push(`${i}${o}${t}`),r.push(`${i}${s}${n.default.gray(`registry:`)} ${n.default.green(`Scalar`)}`);break}default:r.push(`${i}${o}${e.path}`);break}});for(let e of r)console.log(e)},F=async({config:t,dependencies:r,jobIndex:i,logger:s,templates:c,watches:l})=>{let u=l||Array.from({length:t.input.length},()=>({headers:new Headers})),d=t.input.map(e=>N(e));t.logs.level!==`silent`&&!l&&P(d,i);let f=async(t,n)=>{let r=s.timeEvent(`spec`),{arrayBuffer:i,error:a,resolvedInput:o,response:c}=await e.t({fetchOptions:t.fetch,inputPath:d[n].path,timeout:t.watch.timeout,watch:u[n]});if(r.timeEnd(),a&&!l)throw Error(`Request failed with status ${c.status}: ${c.statusText}`);return{arrayBuffer:i,resolvedInput:o}},g=(await Promise.all(t.input.map((e,t)=>f(e,t)))).filter(e=>e.arrayBuffer||e.resolvedInput),_,v;if(g.length){let u=new o.$RefParser,f=g.length>1?await u.bundleMany({arrayBuffer:g.map(e=>e.arrayBuffer),pathOrUrlOrSchemas:[],resolvedInputs:g.map(e=>e.resolvedInput)}):await u.bundle({arrayBuffer:g[0].arrayBuffer,pathOrUrlOrSchema:void 0,resolvedInput:g[0].resolvedInput});t.logs.level!==`silent`&&l&&(console.clear(),P(d,i));let y=s.timeEvent(`input.patch`);h({patchOptions:t.parser.patch,spec:f}),y.timeEnd();let b=s.timeEvent(`parser`);t.experimentalParser&&!e.w(t)&&!e.T(t)&&(v=e.u({config:t,dependencies:r,logger:s,spec:f})),v?v.graph=e.h(v.ir,s).graph:_=E(e.l({openApi:f}),t),b.timeEnd();let x=s.timeEvent(`generator`);v?await m({context:v}):_&&await p({client:_,openApi:f,templates:c}),x.timeEnd();let S=s.timeEvent(`postprocess`);if(!t.dryRun&&(oe({config:t}),t.logs.level!==`silent`)){let e=process.env.INIT_CWD?`./${a.default.relative(process.env.INIT_CWD,t.output.path)}`:t.output.path,r=n.default.gray(`[Job ${i+1}] `);console.log(`${r}${n.default.green(`✅ Done!`)} Your output is in ${n.default.cyanBright(e)}`)}S.timeEnd()}let y=t.input.find((e,t)=>e.watch.enabled&&typeof d[t].path==`string`);return y&&setTimeout(()=>{F({config:t,dependencies:r,jobIndex:i,logger:s,templates:c,watches:u})},y.watch.interval),v||_},se=`
5
- 888 | e 888~-_ 888
6
- 888___| e88~~8e Y88b / d8b 888 \\ 888
7
- 888 | d888 88b Y888/ /Y88b 888 | 888
8
- 888 | 8888__888 Y8/ / Y88b 888 / 888
9
- 888 | Y888 , Y /____Y88b 888_-~ 888
10
- 888 | "88___/ / / Y88b 888 888
11
- _/
12
- `,I=(e,t)=>{let n=[],r=Array.from({length:t?.padding??0}).fill(``);n.push(...r);let i=0,a=``;for(let t of e)t===`
13
- `?a&&=(n.push(a),i=Math.max(i,a.length),``):a+=t;return n.push(...r),{lines:n,maxLineLength:i}};function L(){let t=e.I(),r=I(`
14
- 888 | e 888~-_ 888
15
- 888___| e88~~8e Y88b / d8b 888 \\ 888
16
- 888 | d888 88b Y888/ /Y88b 888 | 888
17
- 888 | 8888__888 Y8/ / Y88b 888 / 888
18
- 888 | Y888 , Y /____Y88b 888_-~ 888
19
- 888 | "88___/ / / Y88b 888 888
20
- _/
21
- `,{padding:1});for(let e of r.lines)console.log(n.default.cyan(e));console.log(n.default.gray(`${t.name} v${t.version}`)),console.log(``)}var R={1:function(e,t,n,r,i){return`import { NgModule} from '@angular/core';
22
- import { HttpClientModule } from '@angular/common/http';
23
-
24
- import { AngularHttpRequest } from './core/AngularHttpRequest';
25
- import { BaseHttpRequest } from './core/BaseHttpRequest';
26
- import type { OpenAPIConfig } from './core/OpenAPI';
27
- import { OpenAPI } from './core/OpenAPI';
28
- import { Interceptors } from './core/OpenAPI';
29
- `},3:function(e,t,n,r,i){var a=e.strict,o=e.lambda;return`import type { BaseHttpRequest } from './core/BaseHttpRequest';
30
- import type { OpenAPIConfig } from './core/OpenAPI';
31
- import { Interceptors } from './core/OpenAPI';
32
- import { `+(o(a(t,`httpRequest`,{start:{line:14,column:12},end:{line:14,column:23}}),t)??``)+` } from './core/`+(o(a(t,`httpRequest`,{start:{line:14,column:45},end:{line:14,column:56}}),t)??``)+`';
33
- `},5:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return a(n,`each`).call(t??(e.nullContext||{}),a(t,`services`),{name:`each`,hash:{},fn:e.program(6,i,0),inverse:e.noop,data:i,loc:{start:{line:18,column:0},end:{line:20,column:9}}})??``},6:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`import { `+(a(n,`transformServiceName`).call(t??(e.nullContext||{}),a(t,`name`),{name:`transformServiceName`,hash:{},data:i,loc:{start:{line:19,column:9},end:{line:19,column:40}}})??``)+` } from './sdk.gen';
34
- `},8:function(e,t,n,r,i){var a=e.strict,o=e.lambda,s=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`@NgModule({
35
- imports: [HttpClientModule],
36
- providers: [
37
- {
38
- provide: OpenAPI,
39
- useValue: {
40
- BASE: OpenAPI?.BASE ?? '`+(o(a(t,`server`,{start:{line:30,column:31},end:{line:30,column:37}}),t)??``)+`',
41
- VERSION: OpenAPI?.VERSION ?? '`+(o(a(t,`version`,{start:{line:31,column:37},end:{line:31,column:44}}),t)??``)+`',
42
- WITH_CREDENTIALS: OpenAPI?.WITH_CREDENTIALS ?? false,
43
- CREDENTIALS: OpenAPI?.CREDENTIALS ?? 'include',
44
- TOKEN: OpenAPI?.TOKEN,
45
- USERNAME: OpenAPI?.USERNAME,
46
- PASSWORD: OpenAPI?.PASSWORD,
47
- HEADERS: OpenAPI?.HEADERS,
48
- ENCODE_PATH: OpenAPI?.ENCODE_PATH,
49
- interceptors: {
50
- response: OpenAPI?.interceptors?.response ?? new Interceptors(),
51
- },
52
- } as OpenAPIConfig,
53
- },
54
- {
55
- provide: BaseHttpRequest,
56
- useClass: AngularHttpRequest,
57
- },
58
- `+(s(n,`each`).call(t??(e.nullContext||{}),s(t,`services`),{name:`each`,hash:{},fn:e.program(9,i,0),inverse:e.noop,data:i,loc:{start:{line:48,column:2},end:{line:50,column:11}}})??``)+` ]
59
- })
60
- export class `+(o(a(s(s(i,`root`),`$config`),`name`,{start:{line:53,column:16},end:{line:53,column:34}}),t)??``)+` {}
61
- `},9:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return` `+(a(n,`transformServiceName`).call(t??(e.nullContext||{}),a(t,`name`),{name:`transformServiceName`,hash:{},data:i,loc:{start:{line:49,column:2},end:{line:49,column:33}}})??``)+`,
62
- `},11:function(e,t,n,r,i){var a=e.strict,o=e.lambda,s=t??(e.nullContext||{}),c=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
63
-
64
- export class `+(o(a(c(c(i,`root`),`$config`),`name`,{start:{line:57,column:16},end:{line:57,column:34}}),t)??``)+` {
65
-
66
- `+(c(n,`each`).call(s,c(t,`services`),{name:`each`,hash:{},fn:e.program(12,i,0),inverse:e.noop,data:i,loc:{start:{line:59,column:1},end:{line:61,column:10}}})??``)+`
67
- public readonly request: BaseHttpRequest;
68
-
69
- constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = `+(o(a(t,`httpRequest`,{start:{line:65,column:87},end:{line:65,column:98}}),t)??``)+`) {
70
- this.request = new HttpRequest({
71
- BASE: config?.BASE ?? '`+(o(a(t,`server`,{start:{line:67,column:29},end:{line:67,column:35}}),t)??``)+`',
72
- VERSION: config?.VERSION ?? '`+(o(a(t,`version`,{start:{line:68,column:35},end:{line:68,column:42}}),t)??``)+`',
73
- WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
74
- CREDENTIALS: config?.CREDENTIALS ?? 'include',
75
- TOKEN: config?.TOKEN,
76
- USERNAME: config?.USERNAME,
77
- PASSWORD: config?.PASSWORD,
78
- HEADERS: config?.HEADERS,
79
- ENCODE_PATH: config?.ENCODE_PATH,
80
- interceptors: {
81
- request: config?.interceptors?.request ?? new Interceptors(),
82
- response: config?.interceptors?.response ?? new Interceptors(),
83
- },
84
- });
85
-
86
- `+(c(n,`each`).call(s,c(t,`services`),{name:`each`,hash:{},fn:e.program(14,i,0),inverse:e.noop,data:i,loc:{start:{line:82,column:2},end:{line:84,column:11}}})??``)+` }
87
- }
88
- `},12:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return` public readonly `+(o(n,`camelCase`).call(a,o(t,`name`),{name:`camelCase`,hash:{},data:i,loc:{start:{line:60,column:17},end:{line:60,column:37}}})??``)+`: `+(o(n,`transformServiceName`).call(a,o(t,`name`),{name:`transformServiceName`,hash:{},data:i,loc:{start:{line:60,column:39},end:{line:60,column:70}}})??``)+`;
89
- `},14:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return` this.`+(o(n,`camelCase`).call(a,o(t,`name`),{name:`camelCase`,hash:{},data:i,loc:{start:{line:83,column:7},end:{line:83,column:27}}})??``)+` = new `+(o(n,`transformServiceName`).call(a,o(t,`name`),{name:`transformServiceName`,hash:{},data:i,loc:{start:{line:83,column:34},end:{line:83,column:65}}})??``)+`(this.request);
90
- `},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:1,column:0},end:{line:15,column:11}}})??``)+`
91
- `+(o(n,`if`).call(a,o(t,`services`),{name:`if`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:17,column:0},end:{line:21,column:7}}})??``)+`
92
- `+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(8,i,0),inverse:e.program(11,i,0),data:i,loc:{start:{line:23,column:0},end:{line:87,column:11}}})??``)},useData:!0},z={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getHeaders = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Observable<HttpHeaders> => {
93
- return forkJoin({
94
- // @ts-ignore
95
- token: resolve(options, config.TOKEN),
96
- // @ts-ignore
97
- username: resolve(options, config.USERNAME),
98
- // @ts-ignore
99
- password: resolve(options, config.PASSWORD),
100
- // @ts-ignore
101
- additionalHeaders: resolve(options, config.HEADERS),
102
- }).pipe(
103
- map(({ token, username, password, additionalHeaders }) => {
104
- const headers = Object.entries({
105
- Accept: 'application/json',
106
- ...additionalHeaders,
107
- ...options.headers,
108
- })
109
- .filter(([, value]) => value !== undefined && value !== null)
110
- .reduce((headers, [key, value]) => ({
111
- ...headers,
112
- [key]: String(value),
113
- }), {} as Record<string, string>);
114
-
115
- if (isStringWithValue(token)) {
116
- headers['Authorization'] = \`Bearer \${token}\`;
117
- }
118
-
119
- if (isStringWithValue(username) && isStringWithValue(password)) {
120
- const credentials = base64(\`\${username}:\${password}\`);
121
- headers['Authorization'] = \`Basic \${credentials}\`;
122
- }
123
-
124
- if (options.body !== undefined) {
125
- if (options.mediaType) {
126
- headers['Content-Type'] = options.mediaType;
127
- } else if (isBlob(options.body)) {
128
- headers['Content-Type'] = options.body.type || 'application/octet-stream';
129
- } else if (isString(options.body)) {
130
- headers['Content-Type'] = 'text/plain';
131
- } else if (!isFormData(options.body)) {
132
- headers['Content-Type'] = 'application/json';
133
- }
134
- }
135
-
136
- return new HttpHeaders(headers);
137
- }),
138
- );
139
- };`},useData:!0},B={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getRequestBody = (options: ApiRequestOptions): unknown => {
140
- if (options.body) {
141
- if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
142
- return JSON.stringify(options.body);
143
- } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
144
- return options.body;
145
- } else {
146
- return JSON.stringify(options.body);
147
- }
148
- }
149
- return undefined;
150
- };`},useData:!0},V={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseBody = <T>(response: HttpResponse<T>): T | undefined => {
151
- if (response.status !== 204 && response.body !== null) {
152
- return response.body;
153
- }
154
- return undefined;
155
- };`},useData:!0},H={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseHeader = <T>(response: HttpResponse<T>, responseHeader?: string): string | undefined => {
156
- if (responseHeader) {
157
- const value = response.headers.get(responseHeader);
158
- if (isString(value)) {
159
- return value;
160
- }
161
- }
162
- return undefined;
163
- };`},useData:!0},U={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`import { HttpClient, HttpHeaders } from '@angular/common/http';
164
- import type { HttpResponse, HttpErrorResponse } from '@angular/common/http';
165
- import { forkJoin, of, throwError } from 'rxjs';
166
- import { catchError, map, switchMap } from 'rxjs/operators';
167
- import type { Observable } from 'rxjs';
168
-
169
- import { ApiError } from './ApiError';
170
- import type { ApiRequestOptions } from './ApiRequestOptions';
171
- import type { ApiResult } from './ApiResult';
172
- import type { OpenAPIConfig } from './OpenAPI';
173
-
174
- `+(e.invokePartial(a(r,`functions/isString`),t,{name:`functions/isString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
175
-
176
- `+(e.invokePartial(a(r,`functions/isStringWithValue`),t,{name:`functions/isStringWithValue`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
177
-
178
- `+(e.invokePartial(a(r,`functions/isBlob`),t,{name:`functions/isBlob`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
179
-
180
- `+(e.invokePartial(a(r,`functions/isFormData`),t,{name:`functions/isFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
181
-
182
- `+(e.invokePartial(a(r,`functions/base64`),t,{name:`functions/base64`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
183
-
184
- `+(e.invokePartial(a(r,`functions/getQueryString`),t,{name:`functions/getQueryString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
185
-
186
- `+(e.invokePartial(a(r,`functions/getUrl`),t,{name:`functions/getUrl`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
187
-
188
- `+(e.invokePartial(a(r,`functions/getFormData`),t,{name:`functions/getFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
189
-
190
- `+(e.invokePartial(a(r,`functions/resolve`),t,{name:`functions/resolve`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
191
-
192
- `+(e.invokePartial(a(r,`angular/getHeaders`),t,{name:`angular/getHeaders`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
193
-
194
- `+(e.invokePartial(a(r,`angular/getRequestBody`),t,{name:`angular/getRequestBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
195
-
196
- `+(e.invokePartial(a(r,`angular/sendRequest`),t,{name:`angular/sendRequest`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
197
-
198
- `+(e.invokePartial(a(r,`angular/getResponseHeader`),t,{name:`angular/getResponseHeader`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
199
-
200
- `+(e.invokePartial(a(r,`angular/getResponseBody`),t,{name:`angular/getResponseBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
201
-
202
- `+(e.invokePartial(a(r,`functions/catchErrorCodes`),t,{name:`functions/catchErrorCodes`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
203
-
204
- /**
205
- * Request method
206
- * @param config The OpenAPI configuration object
207
- * @param http The Angular HTTP client
208
- * @param options The request options from the service
209
- * @returns Observable<T>
210
- * @throws ApiError
211
- */
212
- export const request = <T>(config: OpenAPIConfig, http: HttpClient, options: ApiRequestOptions<T>): Observable<T> => {
213
- const url = getUrl(config, options);
214
- const formData = getFormData(options);
215
- const body = getRequestBody(options);
216
-
217
- return getHeaders(config, options).pipe(
218
- switchMap(headers => {
219
- return sendRequest<T>(config, options, http, url, body, formData, headers);
220
- }),
221
- switchMap(async response => {
222
- for (const fn of config.interceptors.response._fns) {
223
- response = await fn(response);
224
- }
225
- const responseBody = getResponseBody(response);
226
- const responseHeader = getResponseHeader(response, options.responseHeader);
227
-
228
- let transformedBody = responseBody;
229
- if (options.responseTransformer && response.ok) {
230
- transformedBody = await options.responseTransformer(responseBody)
231
- }
232
-
233
- return {
234
- url,
235
- ok: response.ok,
236
- status: response.status,
237
- statusText: response.statusText,
238
- body: responseHeader ?? transformedBody,
239
- } as ApiResult;
240
- }),
241
- catchError((error: HttpErrorResponse) => {
242
- if (!error.status) {
243
- return throwError(() => error);
244
- }
245
- return of({
246
- url,
247
- ok: error.ok,
248
- status: error.status,
249
- statusText: error.statusText,
250
- body: error.error ?? error.statusText,
251
- } as ApiResult);
252
- }),
253
- map(result => {
254
- catchErrorCodes(options, result);
255
- return result.body as T;
256
- }),
257
- catchError((error: ApiError) => {
258
- return throwError(() => error);
259
- }),
260
- );
261
- };`},usePartial:!0,useData:!0},W={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const sendRequest = <T>(
262
- config: OpenAPIConfig,
263
- options: ApiRequestOptions<T>,
264
- http: HttpClient,
265
- url: string,
266
- body: unknown,
267
- formData: FormData | undefined,
268
- headers: HttpHeaders
269
- ): Observable<HttpResponse<T>> => {
270
- return http.request<T>(options.method, url, {
271
- headers,
272
- body: body ?? formData,
273
- withCredentials: config.WITH_CREDENTIALS,
274
- observe: 'response',
275
- });
276
- };`},useData:!0},G={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`import type { ApiRequestOptions } from './ApiRequestOptions';
277
- import type { ApiResult } from './ApiResult';
278
-
279
- export class ApiError extends Error {
280
- public readonly url: string;
281
- public readonly status: number;
282
- public readonly statusText: string;
283
- public readonly body: unknown;
284
- public readonly request: ApiRequestOptions;
285
-
286
- constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
287
- super(message);
288
-
289
- this.name = 'ApiError';
290
- this.url = response.url;
291
- this.status = response.status;
292
- this.statusText = response.statusText;
293
- this.body = response.body;
294
- this.request = request;
295
- }
296
- }`},useData:!0},K={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export type ApiRequestOptions<T = unknown> = {
297
- readonly body?: any;
298
- readonly cookies?: Record<string, unknown>;
299
- readonly errors?: Record<number | string, string>;
300
- readonly formData?: Record<string, unknown> | any[] | Blob | File;
301
- readonly headers?: Record<string, unknown>;
302
- readonly mediaType?: string;
303
- readonly method:
304
- | 'DELETE'
305
- | 'GET'
306
- | 'HEAD'
307
- | 'OPTIONS'
308
- | 'PATCH'
309
- | 'POST'
310
- | 'PUT';
311
- readonly path?: Record<string, unknown>;
312
- readonly query?: Record<string, unknown>;
313
- readonly responseHeader?: string;
314
- readonly responseTransformer?: (data: unknown) => Promise<T>;
315
- readonly url: string;
316
- };`},useData:!0},q={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export type ApiResult<TData = any> = {
317
- readonly body: TData;
318
- readonly ok: boolean;
319
- readonly status: number;
320
- readonly statusText: string;
321
- readonly url: string;
322
- };`},useData:!0},ce={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getHeaders = async <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Promise<Record<string, string>> => {
323
- const [token, username, password, additionalHeaders] = await Promise.all([
324
- // @ts-ignore
325
- resolve(options, config.TOKEN),
326
- // @ts-ignore
327
- resolve(options, config.USERNAME),
328
- // @ts-ignore
329
- resolve(options, config.PASSWORD),
330
- // @ts-ignore
331
- resolve(options, config.HEADERS),
332
- ]);
333
-
334
- const headers = Object.entries({
335
- Accept: 'application/json',
336
- ...additionalHeaders,
337
- ...options.headers,
338
- })
339
- .filter(([, value]) => value !== undefined && value !== null)
340
- .reduce((headers, [key, value]) => ({
341
- ...headers,
342
- [key]: String(value),
343
- }), {} as Record<string, string>);
344
-
345
- if (isStringWithValue(token)) {
346
- headers['Authorization'] = \`Bearer \${token}\`;
347
- }
348
-
349
- if (isStringWithValue(username) && isStringWithValue(password)) {
350
- const credentials = base64(\`\${username}:\${password}\`);
351
- headers['Authorization'] = \`Basic \${credentials}\`;
352
- }
353
-
354
- if (options.body !== undefined) {
355
- if (options.mediaType) {
356
- headers['Content-Type'] = options.mediaType;
357
- } else if (isBlob(options.body)) {
358
- headers['Content-Type'] = options.body.type || 'application/octet-stream';
359
- } else if (isString(options.body)) {
360
- headers['Content-Type'] = 'text/plain';
361
- } else if (!isFormData(options.body)) {
362
- headers['Content-Type'] = 'application/json';
363
- }
364
- } else if (options.formData !== undefined) {
365
- if (options.mediaType) {
366
- headers['Content-Type'] = options.mediaType;
367
- }
368
- }
369
-
370
- return headers;
371
- };`},useData:!0},le={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getRequestBody = (options: ApiRequestOptions): unknown => {
372
- if (options.body) {
373
- return options.body;
374
- }
375
- return undefined;
376
- };`},useData:!0},ue={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseBody = (response: AxiosResponse<unknown>): unknown => {
377
- if (response.status !== 204) {
378
- return response.data;
379
- }
380
- return undefined;
381
- };`},useData:!0},de={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseHeader = (response: AxiosResponse<unknown>, responseHeader?: string): string | undefined => {
382
- if (responseHeader) {
383
- const content = response.headers[responseHeader];
384
- if (isString(content)) {
385
- return content;
386
- }
387
- }
388
- return undefined;
389
- };`},useData:!0},fe={1:function(e,t,n,r,i){return`ApiResult<T>`},3:function(e,t,n,r,i){return`T`},5:function(e,t,n,r,i){return`result.body`},7:function(e,t,n,r,i){return`result`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`import axios from 'axios';
390
- import type { AxiosError, AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
391
-
392
- import { ApiError } from './ApiError';
393
- import type { ApiRequestOptions } from './ApiRequestOptions';
394
- import type { ApiResult } from './ApiResult';
395
- import { CancelablePromise } from './CancelablePromise';
396
- import type { OnCancel } from './CancelablePromise';
397
- import type { OpenAPIConfig } from './OpenAPI';
398
-
399
- `+(e.invokePartial(o(r,`functions/isString`),t,{name:`functions/isString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
400
-
401
- `+(e.invokePartial(o(r,`functions/isStringWithValue`),t,{name:`functions/isStringWithValue`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
402
-
403
- `+(e.invokePartial(o(r,`functions/isBlob`),t,{name:`functions/isBlob`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
404
-
405
- `+(e.invokePartial(o(r,`functions/isFormData`),t,{name:`functions/isFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
406
-
407
- `+(e.invokePartial(o(r,`functions/isSuccess`),t,{name:`functions/isSuccess`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
408
-
409
- `+(e.invokePartial(o(r,`functions/base64`),t,{name:`functions/base64`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
410
-
411
- `+(e.invokePartial(o(r,`functions/getQueryString`),t,{name:`functions/getQueryString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
412
-
413
- `+(e.invokePartial(o(r,`functions/getUrl`),t,{name:`functions/getUrl`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
414
-
415
- `+(e.invokePartial(o(r,`functions/getFormData`),t,{name:`functions/getFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
416
-
417
- `+(e.invokePartial(o(r,`functions/resolve`),t,{name:`functions/resolve`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
418
-
419
- `+(e.invokePartial(o(r,`axios/getHeaders`),t,{name:`axios/getHeaders`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
420
-
421
- `+(e.invokePartial(o(r,`axios/getRequestBody`),t,{name:`axios/getRequestBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
422
-
423
- `+(e.invokePartial(o(r,`axios/sendRequest`),t,{name:`axios/sendRequest`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
424
-
425
- `+(e.invokePartial(o(r,`axios/getResponseHeader`),t,{name:`axios/getResponseHeader`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
426
-
427
- `+(e.invokePartial(o(r,`axios/getResponseBody`),t,{name:`axios/getResponseBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
428
-
429
- `+(e.invokePartial(o(r,`functions/catchErrorCodes`),t,{name:`functions/catchErrorCodes`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
430
-
431
- /**
432
- * Request method
433
- * @param config The OpenAPI configuration object
434
- * @param options The request options from the service
435
- * @param axiosClient The axios client instance to use
436
- * @returns CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:64,column:30},end:{line:64,column:108}}})??``)+`>
437
- * @throws ApiError
438
- */
439
- export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>, axiosClient: AxiosInstance = axios): CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:67,column:136},end:{line:67,column:214}}})??``)+`> => {
440
- return new CancelablePromise(async (resolve, reject, onCancel) => {
441
- try {
442
- const url = getUrl(config, options);
443
- const formData = getFormData(options);
444
- const body = getRequestBody(options);
445
- const headers = await getHeaders(config, options);
446
-
447
- if (!onCancel.isCancelled) {
448
- let response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel, axiosClient);
449
-
450
- for (const fn of config.interceptors.response._fns) {
451
- response = await fn(response);
452
- }
453
-
454
- const responseBody = getResponseBody(response);
455
- const responseHeader = getResponseHeader(response, options.responseHeader);
456
-
457
- let transformedBody = responseBody;
458
- if (options.responseTransformer && isSuccess(response.status)) {
459
- transformedBody = await options.responseTransformer(responseBody)
460
- }
461
-
462
- const result: ApiResult = {
463
- url,
464
- ok: isSuccess(response.status),
465
- status: response.status,
466
- statusText: response.statusText,
467
- body: responseHeader ?? transformedBody,
468
- };
469
-
470
- catchErrorCodes(options, result);
471
-
472
- resolve(`+(o(n,`ifServicesResponse`).call(a,`body`,{name:`ifServicesResponse`,hash:{},fn:e.program(5,i,0),inverse:e.program(7,i,0),data:i,loc:{start:{line:100,column:12},end:{line:100,column:90}}})??``)+`);
473
- }
474
- } catch (error) {
475
- reject(error);
476
- }
477
- });
478
- };`},usePartial:!0,useData:!0},pe={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const sendRequest = async <T>(
479
- config: OpenAPIConfig,
480
- options: ApiRequestOptions<T>,
481
- url: string,
482
- body: unknown,
483
- formData: FormData | undefined,
484
- headers: Record<string, string>,
485
- onCancel: OnCancel,
486
- axiosClient: AxiosInstance
487
- ): Promise<AxiosResponse<T>> => {
488
- const controller = new AbortController();
489
-
490
- let requestConfig: AxiosRequestConfig = {
491
- data: body ?? formData,
492
- headers,
493
- method: options.method,
494
- signal: controller.signal,
495
- url,
496
- withCredentials: config.WITH_CREDENTIALS,
497
- };
498
-
499
- onCancel(() => controller.abort());
500
-
501
- for (const fn of config.interceptors.request._fns) {
502
- requestConfig = await fn(requestConfig);
503
- }
504
-
505
- try {
506
- return await axiosClient.request(requestConfig);
507
- } catch (error) {
508
- const axiosError = error as AxiosError<T>;
509
- if (axiosError.response) {
510
- return axiosError.response;
511
- }
512
- throw error;
513
- }
514
- };`},useData:!0},me={1:function(e,t,n,r,i){return`import type { HttpClient } from '@angular/common/http';
515
- import type { Observable } from 'rxjs';
516
-
517
- import type { ApiRequestOptions } from './ApiRequestOptions';
518
- import type { OpenAPIConfig } from './OpenAPI';
519
- `},3:function(e,t,n,r,i){return`import type { ApiRequestOptions } from './ApiRequestOptions';
520
- import type { CancelablePromise } from './CancelablePromise';
521
- import type { OpenAPIConfig } from './OpenAPI';
522
- `},5:function(e,t,n,r,i){return` constructor(
523
- public readonly config: OpenAPIConfig,
524
- public readonly http: HttpClient,
525
- ) {}
526
- `},7:function(e,t,n,r,i){return` constructor(public readonly config: OpenAPIConfig) {}
527
- `},9:function(e,t,n,r,i){return` public abstract request<T>(options: ApiRequestOptions<T>): Observable<T>;
528
- `},11:function(e,t,n,r,i){return` public abstract request<T>(options: ApiRequestOptions<T>): CancelablePromise<T>;
529
- `},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:1,column:0},end:{line:11,column:11}}})??``)+`
530
- export abstract class BaseHttpRequest {
531
-
532
- `+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.program(7,i,0),data:i,loc:{start:{line:15,column:1},end:{line:22,column:12}}})??``)+`
533
- `+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(9,i,0),inverse:e.program(11,i,0),data:i,loc:{start:{line:24,column:1},end:{line:28,column:12}}})??``)+`}`},useData:!0},he={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export class CancelError extends Error {
534
- constructor(message: string) {
535
- super(message);
536
- this.name = 'CancelError';
537
- }
538
-
539
- public get isCancelled(): boolean {
540
- return true;
541
- }
542
- }
543
-
544
- export interface OnCancel {
545
- readonly isResolved: boolean;
546
- readonly isRejected: boolean;
547
- readonly isCancelled: boolean;
548
-
549
- (cancelHandler: () => void): void;
550
- }
551
-
552
- export class CancelablePromise<T> implements Promise<T> {
553
- private _isResolved: boolean;
554
- private _isRejected: boolean;
555
- private _isCancelled: boolean;
556
- readonly cancelHandlers: (() => void)[];
557
- readonly promise: Promise<T>;
558
- private _resolve?: (value: T | PromiseLike<T>) => void;
559
- private _reject?: (reason?: unknown) => void;
560
-
561
- constructor(
562
- executor: (
563
- resolve: (value: T | PromiseLike<T>) => void,
564
- reject: (reason?: unknown) => void,
565
- onCancel: OnCancel
566
- ) => void
567
- ) {
568
- this._isResolved = false;
569
- this._isRejected = false;
570
- this._isCancelled = false;
571
- this.cancelHandlers = [];
572
- this.promise = new Promise<T>((resolve, reject) => {
573
- this._resolve = resolve;
574
- this._reject = reject;
575
-
576
- const onResolve = (value: T | PromiseLike<T>): void => {
577
- if (this._isResolved || this._isRejected || this._isCancelled) {
578
- return;
579
- }
580
- this._isResolved = true;
581
- if (this._resolve) this._resolve(value);
582
- };
583
-
584
- const onReject = (reason?: unknown): void => {
585
- if (this._isResolved || this._isRejected || this._isCancelled) {
586
- return;
587
- }
588
- this._isRejected = true;
589
- if (this._reject) this._reject(reason);
590
- };
591
-
592
- const onCancel = (cancelHandler: () => void): void => {
593
- if (this._isResolved || this._isRejected || this._isCancelled) {
594
- return;
595
- }
596
- this.cancelHandlers.push(cancelHandler);
597
- };
598
-
599
- Object.defineProperty(onCancel, 'isResolved', {
600
- get: (): boolean => this._isResolved,
601
- });
602
-
603
- Object.defineProperty(onCancel, 'isRejected', {
604
- get: (): boolean => this._isRejected,
605
- });
606
-
607
- Object.defineProperty(onCancel, 'isCancelled', {
608
- get: (): boolean => this._isCancelled,
609
- });
610
-
611
- return executor(onResolve, onReject, onCancel as OnCancel);
612
- });
613
- }
614
-
615
- get [Symbol.toStringTag](): string {
616
- return "Cancellable Promise";
617
- }
618
-
619
- public then<TResult1 = T, TResult2 = never>(
620
- onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
621
- onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null
622
- ): Promise<TResult1 | TResult2> {
623
- return this.promise.then(onFulfilled, onRejected);
624
- }
625
-
626
- public catch<TResult = never>(
627
- onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null
628
- ): Promise<T | TResult> {
629
- return this.promise.catch(onRejected);
630
- }
631
-
632
- public finally(onFinally?: (() => void) | null): Promise<T> {
633
- return this.promise.finally(onFinally);
634
- }
635
-
636
- public cancel(): void {
637
- if (this._isResolved || this._isRejected || this._isCancelled) {
638
- return;
639
- }
640
- this._isCancelled = true;
641
- if (this.cancelHandlers.length) {
642
- try {
643
- for (const cancelHandler of this.cancelHandlers) {
644
- cancelHandler();
645
- }
646
- } catch (error) {
647
- console.warn('Cancellation threw an error', error);
648
- return;
649
- }
650
- }
651
- this.cancelHandlers.length = 0;
652
- if (this._reject) this._reject(new CancelError('Request aborted'));
653
- }
654
-
655
- public get isCancelled(): boolean {
656
- return this._isCancelled;
657
- }
658
- }`},useData:!0},ge={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getHeaders = async <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Promise<Headers> => {
659
- const [token, username, password, additionalHeaders] = await Promise.all([
660
- // @ts-ignore
661
- resolve(options, config.TOKEN),
662
- // @ts-ignore
663
- resolve(options, config.USERNAME),
664
- // @ts-ignore
665
- resolve(options, config.PASSWORD),
666
- // @ts-ignore
667
- resolve(options, config.HEADERS),
668
- ]);
669
-
670
- const headers = Object.entries({
671
- Accept: 'application/json',
672
- ...additionalHeaders,
673
- ...options.headers,
674
- })
675
- .filter(([, value]) => value !== undefined && value !== null)
676
- .reduce((headers, [key, value]) => ({
677
- ...headers,
678
- [key]: String(value),
679
- }), {} as Record<string, string>);
680
-
681
- if (isStringWithValue(token)) {
682
- headers['Authorization'] = \`Bearer \${token}\`;
683
- }
684
-
685
- if (isStringWithValue(username) && isStringWithValue(password)) {
686
- const credentials = base64(\`\${username}:\${password}\`);
687
- headers['Authorization'] = \`Basic \${credentials}\`;
688
- }
689
-
690
- if (options.body !== undefined) {
691
- if (options.mediaType) {
692
- headers['Content-Type'] = options.mediaType;
693
- } else if (isBlob(options.body)) {
694
- headers['Content-Type'] = options.body.type || 'application/octet-stream';
695
- } else if (isString(options.body)) {
696
- headers['Content-Type'] = 'text/plain';
697
- } else if (!isFormData(options.body)) {
698
- headers['Content-Type'] = 'application/json';
699
- }
700
- }
701
-
702
- return new Headers(headers);
703
- };`},useData:!0},_e={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getRequestBody = (options: ApiRequestOptions): unknown => {
704
- if (options.body !== undefined) {
705
- if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
706
- return JSON.stringify(options.body);
707
- } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
708
- return options.body;
709
- } else {
710
- return JSON.stringify(options.body);
711
- }
712
- }
713
- return undefined;
714
- };`},useData:!0},ve={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseBody = async (response: Response): Promise<unknown> => {
715
- if (response.status !== 204) {
716
- try {
717
- const contentType = response.headers.get('Content-Type');
718
- if (contentType) {
719
- const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/'];
720
- if (contentType.includes('application/json') || contentType.includes('+json')) {
721
- return await response.json();
722
- } else if (binaryTypes.some(type => contentType.includes(type))) {
723
- return await response.blob();
724
- } else if (contentType.includes('multipart/form-data')) {
725
- return await response.formData();
726
- } else if (contentType.includes('text/')) {
727
- return await response.text();
728
- }
729
- }
730
- } catch (error) {
731
- console.error(error);
732
- }
733
- }
734
- return undefined;
735
- };`},useData:!0},ye={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => {
736
- if (responseHeader) {
737
- const content = response.headers.get(responseHeader);
738
- if (isString(content)) {
739
- return content;
740
- }
741
- }
742
- return undefined;
743
- };`},useData:!0},be={1:function(e,t,n,r,i){return`import fetch, { FormData, Headers } from 'node-fetch';
744
- import type { RequestInit, Response } from 'node-fetch';
745
-
746
- `},3:function(e,t,n,r,i){return`ApiResult<T>`},5:function(e,t,n,r,i){return`T`},7:function(e,t,n,r,i){return`result.body`},9:function(e,t,n,r,i){return`result`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/node`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i,loc:{start:{line:1,column:0},end:{line:5,column:11}}})??``)+`import { ApiError } from './ApiError';
747
- import type { ApiRequestOptions } from './ApiRequestOptions';
748
- import type { ApiResult } from './ApiResult';
749
- import { CancelablePromise } from './CancelablePromise';
750
- import type { OnCancel } from './CancelablePromise';
751
- import type { OpenAPIConfig } from './OpenAPI';
752
-
753
- `+(e.invokePartial(o(r,`functions/isString`),t,{name:`functions/isString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
754
-
755
- `+(e.invokePartial(o(r,`functions/isStringWithValue`),t,{name:`functions/isStringWithValue`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
756
-
757
- `+(e.invokePartial(o(r,`functions/isBlob`),t,{name:`functions/isBlob`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
758
-
759
- `+(e.invokePartial(o(r,`functions/isFormData`),t,{name:`functions/isFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
760
-
761
- `+(e.invokePartial(o(r,`functions/base64`),t,{name:`functions/base64`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
762
-
763
- `+(e.invokePartial(o(r,`functions/getQueryString`),t,{name:`functions/getQueryString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
764
-
765
- `+(e.invokePartial(o(r,`functions/getUrl`),t,{name:`functions/getUrl`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
766
-
767
- `+(e.invokePartial(o(r,`functions/getFormData`),t,{name:`functions/getFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
768
-
769
- `+(e.invokePartial(o(r,`functions/resolve`),t,{name:`functions/resolve`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
770
-
771
- `+(e.invokePartial(o(r,`fetch/getHeaders`),t,{name:`fetch/getHeaders`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
772
-
773
- `+(e.invokePartial(o(r,`fetch/getRequestBody`),t,{name:`fetch/getRequestBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
774
-
775
- `+(e.invokePartial(o(r,`fetch/sendRequest`),t,{name:`fetch/sendRequest`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
776
-
777
- `+(e.invokePartial(o(r,`fetch/getResponseHeader`),t,{name:`fetch/getResponseHeader`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
778
-
779
- `+(e.invokePartial(o(r,`fetch/getResponseBody`),t,{name:`fetch/getResponseBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
780
-
781
- `+(e.invokePartial(o(r,`functions/catchErrorCodes`),t,{name:`functions/catchErrorCodes`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
782
-
783
- /**
784
- * Request method
785
- * @param config The OpenAPI configuration object
786
- * @param options The request options from the service
787
- * @returns CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(3,i,0),inverse:e.program(5,i,0),data:i,loc:{start:{line:62,column:30},end:{line:62,column:108}}})??``)+`>
788
- * @throws ApiError
789
- */
790
- export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(3,i,0),inverse:e.program(5,i,0),data:i,loc:{start:{line:65,column:100},end:{line:65,column:178}}})??``)+`> => {
791
- return new CancelablePromise(async (resolve, reject, onCancel) => {
792
- try {
793
- const url = getUrl(config, options);
794
- const formData = getFormData(options);
795
- const body = getRequestBody(options);
796
- const headers = await getHeaders(config, options);
797
-
798
- if (!onCancel.isCancelled) {
799
- let response = await sendRequest(config, options, url, body, formData, headers, onCancel);
800
-
801
- for (const fn of config.interceptors.response._fns) {
802
- response = await fn(response);
803
- }
804
-
805
- const responseBody = await getResponseBody(response);
806
- const responseHeader = getResponseHeader(response, options.responseHeader);
807
-
808
- let transformedBody = responseBody;
809
- if (options.responseTransformer && response.ok) {
810
- transformedBody = await options.responseTransformer(responseBody)
811
- }
812
-
813
- const result: ApiResult = {
814
- url,
815
- ok: response.ok,
816
- status: response.status,
817
- statusText: response.statusText,
818
- body: responseHeader ?? transformedBody,
819
- };
820
-
821
- catchErrorCodes(options, result);
822
-
823
- resolve(`+(o(n,`ifServicesResponse`).call(a,`body`,{name:`ifServicesResponse`,hash:{},fn:e.program(7,i,0),inverse:e.program(9,i,0),data:i,loc:{start:{line:98,column:12},end:{line:98,column:90}}})??``)+`);
824
- }
825
- } catch (error) {
826
- reject(error);
827
- }
828
- });
829
- };`},usePartial:!0,useData:!0},xe={1:function(e,t,n,r,i){return` if (config.WITH_CREDENTIALS) {
830
- request.credentials = config.CREDENTIALS;
831
- }
832
- `},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`export const sendRequest = async (
833
- config: OpenAPIConfig,
834
- options: ApiRequestOptions,
835
- url: string,
836
- body: any,
837
- formData: FormData | undefined,
838
- headers: Headers,
839
- onCancel: OnCancel
840
- ): Promise<Response> => {
841
- const controller = new AbortController();
842
-
843
- let request: RequestInit = {
844
- headers,
845
- body: body ?? formData,
846
- method: options.method,
847
- signal: controller.signal,
848
- };
849
-
850
- `+(a(n,`equals`).call(t??(e.nullContext||{}),a(a(a(a(i,`root`),`$config`),`client`),`name`),`legacy/fetch`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i,loc:{start:{line:19,column:1},end:{line:23,column:12}}})??``)+`
851
- for (const fn of config.interceptors.request._fns) {
852
- request = await fn(request);
853
- }
854
-
855
- onCancel(() => controller.abort());
856
-
857
- return await fetch(url, request);
858
- };`},useData:!0},Se={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const base64 = (str: string): string => {
859
- try {
860
- return btoa(str);
861
- } catch (err) {
862
- // @ts-ignore
863
- return Buffer.from(str).toString('base64');
864
- }
865
- };`},useData:!0},Ce={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
866
- const errors: Record<number, string> = {
867
- 400: 'Bad Request',
868
- 401: 'Unauthorized',
869
- 402: 'Payment Required',
870
- 403: 'Forbidden',
871
- 404: 'Not Found',
872
- 405: 'Method Not Allowed',
873
- 406: 'Not Acceptable',
874
- 407: 'Proxy Authentication Required',
875
- 408: 'Request Timeout',
876
- 409: 'Conflict',
877
- 410: 'Gone',
878
- 411: 'Length Required',
879
- 412: 'Precondition Failed',
880
- 413: 'Payload Too Large',
881
- 414: 'URI Too Long',
882
- 415: 'Unsupported Media Type',
883
- 416: 'Range Not Satisfiable',
884
- 417: 'Expectation Failed',
885
- 418: 'Im a teapot',
886
- 421: 'Misdirected Request',
887
- 422: 'Unprocessable Content',
888
- 423: 'Locked',
889
- 424: 'Failed Dependency',
890
- 425: 'Too Early',
891
- 426: 'Upgrade Required',
892
- 428: 'Precondition Required',
893
- 429: 'Too Many Requests',
894
- 431: 'Request Header Fields Too Large',
895
- 451: 'Unavailable For Legal Reasons',
896
- 500: 'Internal Server Error',
897
- 501: 'Not Implemented',
898
- 502: 'Bad Gateway',
899
- 503: 'Service Unavailable',
900
- 504: 'Gateway Timeout',
901
- 505: 'HTTP Version Not Supported',
902
- 506: 'Variant Also Negotiates',
903
- 507: 'Insufficient Storage',
904
- 508: 'Loop Detected',
905
- 510: 'Not Extended',
906
- 511: 'Network Authentication Required',
907
- ...options.errors,
908
- }
909
-
910
- const error = errors[result.status];
911
- if (error) {
912
- throw new ApiError(options, result, error);
913
- }
914
-
915
- if (!result.ok) {
916
- const errorStatus = result.status ?? 'unknown';
917
- const errorStatusText = result.statusText ?? 'unknown';
918
- const errorBody = (() => {
919
- try {
920
- return JSON.stringify(result.body, null, 2);
921
- } catch (e) {
922
- return undefined;
923
- }
924
- })();
925
-
926
- throw new ApiError(options, result,
927
- \`Generic Error: status: \${errorStatus}; status text: \${errorStatusText}; body: \${errorBody}\`
928
- );
929
- }
930
- };`},useData:!0},we={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
931
- if (options.formData) {
932
- const formData = new FormData();
933
-
934
- const process = (key: string, value: unknown) => {
935
- if (isString(value) || isBlob(value)) {
936
- formData.append(key, value);
937
- } else {
938
- formData.append(key, JSON.stringify(value));
939
- }
940
- };
941
-
942
- Object.entries(options.formData)
943
- .filter(([, value]) => value !== undefined && value !== null)
944
- .forEach(([key, value]) => {
945
- if (Array.isArray(value)) {
946
- value.forEach(v => process(key, v));
947
- } else {
948
- process(key, value);
949
- }
950
- });
951
-
952
- return formData;
953
- }
954
- return undefined;
955
- };`},useData:!0},Te={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getQueryString = (params: Record<string, unknown>): string => {
956
- const qs: string[] = [];
957
-
958
- const append = (key: string, value: unknown) => {
959
- qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`);
960
- };
961
-
962
- const encodePair = (key: string, value: unknown) => {
963
- if (value === undefined || value === null) {
964
- return;
965
- }
966
-
967
- if (value instanceof Date) {
968
- append(key, value.toISOString());
969
- } else if (Array.isArray(value)) {
970
- value.forEach(v => encodePair(key, v));
971
- } else if (typeof value === 'object') {
972
- Object.entries(value).forEach(([k, v]) => encodePair(\`\${key}[\${k}]\`, v));
973
- } else {
974
- append(key, value);
975
- }
976
- };
977
-
978
- Object.entries(params).forEach(([key, value]) => encodePair(key, value));
979
-
980
- return qs.length ? \`?\${qs.join('&')}\` : '';
981
- };`},useData:!0},Ee={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
982
- const encoder = config.ENCODE_PATH || encodeURI;
983
-
984
- const path = options.url
985
- .replace('{api-version}', config.VERSION)
986
- .replace(/{(.*?)}/g, (substring: string, group: string) => {
987
- if (options.path?.hasOwnProperty(group)) {
988
- return encoder(String(options.path[group]));
989
- }
990
- return substring;
991
- });
992
-
993
- const url = config.BASE + path;
994
- return options.query ? url + getQueryString(options.query) : url;
995
- };`},useData:!0},De={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isBlob = (value: any): value is Blob => {
996
- return value instanceof Blob;
997
- };`},useData:!0},Oe={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isFormData = (value: unknown): value is FormData => {
998
- return value instanceof FormData;
999
- };`},useData:!0},ke={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isString = (value: unknown): value is string => {
1000
- return typeof value === 'string';
1001
- };`},useData:!0},Ae={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isStringWithValue = (value: unknown): value is string => {
1002
- return isString(value) && value !== '';
1003
- };`},useData:!0},je={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isSuccess = (status: number): boolean => {
1004
- return status >= 200 && status < 300;
1005
- };`},useData:!0},Me={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
1006
-
1007
- export const resolve = async <T>(options: ApiRequestOptions<T>, resolver?: T | Resolver<T>): Promise<T | undefined> => {
1008
- if (typeof resolver === 'function') {
1009
- return (resolver as Resolver<T>)(options);
1010
- }
1011
- return resolver;
1012
- };`},useData:!0},Ne={1:function(e,t,n,r,i){return`import { Inject, Injectable } from '@angular/core';
1013
- import { HttpClient } from '@angular/common/http';
1014
- import type { Observable } from 'rxjs';
1015
-
1016
- import type { ApiRequestOptions } from './ApiRequestOptions';
1017
- import { BaseHttpRequest } from './BaseHttpRequest';
1018
- import type { OpenAPIConfig } from './OpenAPI';
1019
- import { OpenAPI } from './OpenAPI';
1020
- import { request as __request } from './request';
1021
- `},3:function(e,t,n,r,i){return`import type { ApiRequestOptions } from './ApiRequestOptions';
1022
- import { BaseHttpRequest } from './BaseHttpRequest';
1023
- import type { CancelablePromise } from './CancelablePromise';
1024
- import type { OpenAPIConfig } from './OpenAPI';
1025
- import { request as __request } from './request';
1026
- `},5:function(e,t,n,r,i){return`@Injectable()
1027
- `},7:function(e,t,n,r,i){return` constructor(
1028
- @Inject(OpenAPI)
1029
- config: OpenAPIConfig,
1030
- http: HttpClient,
1031
- ) {
1032
- super(config, http);
1033
- }
1034
- `},9:function(e,t,n,r,i){return` constructor(config: OpenAPIConfig) {
1035
- super(config);
1036
- }
1037
- `},11:function(e,t,n,r,i){return` /**
1038
- * Request method
1039
- * @param options The request options from the service
1040
- * @returns Observable<T>
1041
- * @throws ApiError
1042
- */
1043
- public override request<T>(options: ApiRequestOptions<T>): Observable<T> {
1044
- return __request(this.config, this.http, options);
1045
- }
1046
- `},13:function(e,t,n,r,i){return` /**
1047
- * Request method
1048
- * @param options The request options from the service
1049
- * @returns CancelablePromise<T>
1050
- * @throws ApiError
1051
- */
1052
- public override request<T>(options: ApiRequestOptions<T>): CancelablePromise<T> {
1053
- return __request(this.config, options);
1054
- }
1055
- `},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:1,column:0},end:{line:17,column:11}}})??``)+`
1056
- `+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:19,column:0},end:{line:21,column:11}}})??``)+`export class `+(e.lambda(e.strict(t,`httpRequest`,{start:{line:22,column:15},end:{line:22,column:26}}),t)??``)+` extends BaseHttpRequest {
1057
-
1058
- `+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(7,i,0),inverse:e.program(9,i,0),data:i,loc:{start:{line:24,column:1},end:{line:36,column:12}}})??``)+`
1059
- `+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(11,i,0),inverse:e.program(13,i,0),data:i,loc:{start:{line:38,column:1},end:{line:58,column:12}}})??``)+`}`},useData:!0},Pe={1:function(e,t,n,r,i){return`import type { HttpResponse } from '@angular/common/http';
1060
- `},3:function(e,t,n,r,i){return`import type { AxiosRequestConfig, AxiosResponse } from 'axios';
1061
- `},5:function(e,t,n,r,i){return`import type { RequestInit, Response } from 'node-fetch';
1062
- `},7:function(e,t,n,r,i){return` response: Interceptors<HttpResponse<any>>;
1063
- `},9:function(e,t,n,r,i){return` request: Interceptors<AxiosRequestConfig>;
1064
- response: Interceptors<AxiosResponse>;
1065
- `},11:function(e,t,n,r,i){return` request: Interceptors<RequestInit>;
1066
- response: Interceptors<Response>;
1067
- `},13:function(e,t,n,r,i){return` request: Interceptors<XMLHttpRequest>;
1068
- response: Interceptors<XMLHttpRequest>;
1069
- `},15:function(e,t,n,r,i){return` request: new Interceptors(),
1070
- `},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.strict,s=e.lambda,c=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i,loc:{start:{line:1,column:0},end:{line:3,column:11}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/axios`,{name:`equals`,hash:{},fn:e.program(3,i,0),inverse:e.noop,data:i,loc:{start:{line:4,column:0},end:{line:6,column:11}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/node`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:7,column:0},end:{line:9,column:11}}})??``)+`import type { ApiRequestOptions } from './ApiRequestOptions';
1071
-
1072
- type Headers = Record<string, string>;
1073
- type Middleware<T> = (value: T) => T | Promise<T>;
1074
- type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
1075
-
1076
- export class Interceptors<T> {
1077
- _fns: Middleware<T>[];
1078
-
1079
- constructor() {
1080
- this._fns = [];
1081
- }
1082
-
1083
- eject(fn: Middleware<T>): void {
1084
- const index = this._fns.indexOf(fn);
1085
- if (index !== -1) {
1086
- this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
1087
- }
1088
- }
1089
-
1090
- use(fn: Middleware<T>): void {
1091
- this._fns = [...this._fns, fn];
1092
- }
1093
- }
1094
-
1095
- export type OpenAPIConfig = {
1096
- BASE: string;
1097
- CREDENTIALS: 'include' | 'omit' | 'same-origin';
1098
- ENCODE_PATH?: ((path: string) => string) | undefined;
1099
- HEADERS?: Headers | Resolver<Headers> | undefined;
1100
- PASSWORD?: string | Resolver<string> | undefined;
1101
- TOKEN?: string | Resolver<string> | undefined;
1102
- USERNAME?: string | Resolver<string> | undefined;
1103
- VERSION: string;
1104
- WITH_CREDENTIALS: boolean;
1105
- interceptors: {
1106
- `+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(7,i,0),inverse:e.noop,data:i,loc:{start:{line:46,column:2},end:{line:48,column:13}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/axios`,{name:`equals`,hash:{},fn:e.program(9,i,0),inverse:e.noop,data:i,loc:{start:{line:49,column:2},end:{line:52,column:13}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/fetch`,{name:`equals`,hash:{},fn:e.program(11,i,0),inverse:e.noop,data:i,loc:{start:{line:53,column:2},end:{line:56,column:13}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/node`,{name:`equals`,hash:{},fn:e.program(11,i,0),inverse:e.noop,data:i,loc:{start:{line:57,column:2},end:{line:60,column:13}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/xhr`,{name:`equals`,hash:{},fn:e.program(13,i,0),inverse:e.noop,data:i,loc:{start:{line:61,column:2},end:{line:64,column:13}}})??``)+` };
1107
- };
1108
-
1109
- export const OpenAPI: OpenAPIConfig = {
1110
- BASE: '`+(s(o(t,`server`,{start:{line:69,column:11},end:{line:69,column:17}}),t)??``)+`',
1111
- CREDENTIALS: 'include',
1112
- ENCODE_PATH: undefined,
1113
- HEADERS: undefined,
1114
- PASSWORD: undefined,
1115
- TOKEN: undefined,
1116
- USERNAME: undefined,
1117
- VERSION: '`+(s(o(t,`version`,{start:{line:76,column:14},end:{line:76,column:21}}),t)??``)+`',
1118
- WITH_CREDENTIALS: false,
1119
- interceptors: {
1120
- `+(c(n,`notEquals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`notEquals`,hash:{},fn:e.program(15,i,0),inverse:e.noop,data:i,loc:{start:{line:79,column:2},end:{line:81,column:16}}})??``)+` response: new Interceptors(),
1121
- },
1122
- };`},useData:!0},Fe={1:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.invokePartial(a(r,`angular/request`),t,{name:`angular/request`,data:i,helpers:n,partials:r,decorators:e.decorators})??``},3:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.invokePartial(a(r,`axios/request`),t,{name:`axios/request`,data:i,helpers:n,partials:r,decorators:e.decorators})??``},5:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.invokePartial(a(r,`fetch/request`),t,{name:`fetch/request`,data:i,helpers:n,partials:r,decorators:e.decorators})??``},7:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.invokePartial(a(r,`xhr/request`),t,{name:`xhr/request`,data:i,helpers:n,partials:r,decorators:e.decorators})??``},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i,loc:{start:{line:1,column:0},end:{line:1,column:87}}})??``)+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/axios`,{name:`equals`,hash:{},fn:e.program(3,i,0),inverse:e.noop,data:i,loc:{start:{line:2,column:0},end:{line:2,column:83}}})??``)+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/fetch`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:3,column:0},end:{line:3,column:83}}})??``)+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/node`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:4,column:0},end:{line:4,column:82}}})??``)+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/xhr`,{name:`equals`,hash:{},fn:e.program(7,i,0),inverse:e.noop,data:i,loc:{start:{line:5,column:0},end:{line:5,column:79}}})??``)},usePartial:!0,useData:!0},Ie={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getHeaders = async <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Promise<Headers> => {
1123
- const [token, username, password, additionalHeaders] = await Promise.all([
1124
- // @ts-ignore
1125
- resolve(options, config.TOKEN),
1126
- // @ts-ignore
1127
- resolve(options, config.USERNAME),
1128
- // @ts-ignore
1129
- resolve(options, config.PASSWORD),
1130
- // @ts-ignore
1131
- resolve(options, config.HEADERS),
1132
- ]);
1133
-
1134
- const headers = Object.entries({
1135
- Accept: 'application/json',
1136
- ...additionalHeaders,
1137
- ...options.headers,
1138
- })
1139
- .filter(([, value]) => value !== undefined && value !== null)
1140
- .reduce((headers, [key, value]) => ({
1141
- ...headers,
1142
- [key]: String(value),
1143
- }), {} as Record<string, string>);
1144
-
1145
- if (isStringWithValue(token)) {
1146
- headers['Authorization'] = \`Bearer \${token}\`;
1147
- }
1148
-
1149
- if (isStringWithValue(username) && isStringWithValue(password)) {
1150
- const credentials = base64(\`\${username}:\${password}\`);
1151
- headers['Authorization'] = \`Basic \${credentials}\`;
1152
- }
1153
-
1154
- if (options.body !== undefined) {
1155
- if (options.mediaType) {
1156
- headers['Content-Type'] = options.mediaType;
1157
- } else if (isBlob(options.body)) {
1158
- headers['Content-Type'] = options.body.type || 'application/octet-stream';
1159
- } else if (isString(options.body)) {
1160
- headers['Content-Type'] = 'text/plain';
1161
- } else if (!isFormData(options.body)) {
1162
- headers['Content-Type'] = 'application/json';
1163
- }
1164
- }
1165
-
1166
- return new Headers(headers);
1167
- };`},useData:!0},Le={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getRequestBody = (options: ApiRequestOptions): unknown => {
1168
- if (options.body !== undefined) {
1169
- if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
1170
- return JSON.stringify(options.body);
1171
- } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
1172
- return options.body;
1173
- } else {
1174
- return JSON.stringify(options.body);
1175
- }
1176
- }
1177
- return undefined;
1178
- };`},useData:!0},Re={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseBody = (xhr: XMLHttpRequest): unknown => {
1179
- if (xhr.status !== 204) {
1180
- try {
1181
- const contentType = xhr.getResponseHeader('Content-Type');
1182
- if (contentType) {
1183
- if (contentType.includes('application/json') || contentType.includes('+json')) {
1184
- return JSON.parse(xhr.responseText);
1185
- } else {
1186
- return xhr.responseText;
1187
- }
1188
- }
1189
- } catch (error) {
1190
- console.error(error);
1191
- }
1192
- }
1193
- return undefined;
1194
- };`},useData:!0},ze={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseHeader = (xhr: XMLHttpRequest, responseHeader?: string): string | undefined => {
1195
- if (responseHeader) {
1196
- const content = xhr.getResponseHeader(responseHeader);
1197
- if (isString(content)) {
1198
- return content;
1199
- }
1200
- }
1201
- return undefined;
1202
- };`},useData:!0},J={1:function(e,t,n,r,i){return`ApiResult<T>`},3:function(e,t,n,r,i){return`T`},5:function(e,t,n,r,i){return`result.body`},7:function(e,t,n,r,i){return`result`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`import { ApiError } from './ApiError';
1203
- import type { ApiRequestOptions } from './ApiRequestOptions';
1204
- import type { ApiResult } from './ApiResult';
1205
- import { CancelablePromise } from './CancelablePromise';
1206
- import type { OnCancel } from './CancelablePromise';
1207
- import type { OpenAPIConfig } from './OpenAPI';
1208
-
1209
- `+(e.invokePartial(o(r,`functions/isString`),t,{name:`functions/isString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1210
-
1211
- `+(e.invokePartial(o(r,`functions/isStringWithValue`),t,{name:`functions/isStringWithValue`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1212
-
1213
- `+(e.invokePartial(o(r,`functions/isBlob`),t,{name:`functions/isBlob`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1214
-
1215
- `+(e.invokePartial(o(r,`functions/isFormData`),t,{name:`functions/isFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1216
-
1217
- `+(e.invokePartial(o(r,`functions/isSuccess`),t,{name:`functions/isSuccess`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1218
-
1219
- `+(e.invokePartial(o(r,`functions/base64`),t,{name:`functions/base64`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1220
-
1221
- `+(e.invokePartial(o(r,`functions/getQueryString`),t,{name:`functions/getQueryString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1222
-
1223
- `+(e.invokePartial(o(r,`functions/getUrl`),t,{name:`functions/getUrl`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1224
-
1225
- `+(e.invokePartial(o(r,`functions/getFormData`),t,{name:`functions/getFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1226
-
1227
- `+(e.invokePartial(o(r,`functions/resolve`),t,{name:`functions/resolve`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1228
-
1229
- `+(e.invokePartial(o(r,`fetch/getHeaders`),t,{name:`fetch/getHeaders`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1230
-
1231
- `+(e.invokePartial(o(r,`xhr/getRequestBody`),t,{name:`xhr/getRequestBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1232
-
1233
- `+(e.invokePartial(o(r,`xhr/sendRequest`),t,{name:`xhr/sendRequest`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1234
-
1235
- `+(e.invokePartial(o(r,`xhr/getResponseHeader`),t,{name:`xhr/getResponseHeader`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1236
-
1237
- `+(e.invokePartial(o(r,`xhr/getResponseBody`),t,{name:`xhr/getResponseBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1238
-
1239
- `+(e.invokePartial(o(r,`functions/catchErrorCodes`),t,{name:`functions/catchErrorCodes`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
1240
-
1241
- /**
1242
- * Request method
1243
- * @param config The OpenAPI configuration object
1244
- * @param options The request options from the service
1245
- * @returns CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:60,column:30},end:{line:60,column:108}}})??``)+`>
1246
- * @throws ApiError
1247
- */
1248
- export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:63,column:100},end:{line:63,column:178}}})??``)+`> => {
1249
- return new CancelablePromise(async (resolve, reject, onCancel) => {
1250
- try {
1251
- const url = getUrl(config, options);
1252
- const formData = getFormData(options);
1253
- const body = getRequestBody(options);
1254
- const headers = await getHeaders(config, options);
1255
-
1256
- if (!onCancel.isCancelled) {
1257
- let response = await sendRequest(config, options, url, body, formData, headers, onCancel);
1258
-
1259
- for (const fn of config.interceptors.response._fns) {
1260
- response = await fn(response);
1261
- }
1262
-
1263
- const responseBody = getResponseBody(response);
1264
- const responseHeader = getResponseHeader(response, options.responseHeader);
1265
-
1266
- let transformedBody = responseBody;
1267
- if (options.responseTransformer && isSuccess(response.status)) {
1268
- transformedBody = await options.responseTransformer(responseBody)
1269
- }
1270
-
1271
- const result: ApiResult = {
1272
- url,
1273
- ok: isSuccess(response.status),
1274
- status: response.status,
1275
- statusText: response.statusText,
1276
- body: responseHeader ?? transformedBody,
1277
- };
1278
-
1279
- catchErrorCodes(options, result);
1280
-
1281
- resolve(`+(o(n,`ifServicesResponse`).call(a,`body`,{name:`ifServicesResponse`,hash:{},fn:e.program(5,i,0),inverse:e.program(7,i,0),data:i,loc:{start:{line:96,column:12},end:{line:96,column:90}}})??``)+`);
1282
- }
1283
- } catch (error) {
1284
- reject(error);
1285
- }
1286
- });
1287
- };`},usePartial:!0,useData:!0},Be={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const sendRequest = async (
1288
- config: OpenAPIConfig,
1289
- options: ApiRequestOptions,
1290
- url: string,
1291
- body: any,
1292
- formData: FormData | undefined,
1293
- headers: Headers,
1294
- onCancel: OnCancel
1295
- ): Promise<XMLHttpRequest> => {
1296
- let xhr = new XMLHttpRequest();
1297
- xhr.open(options.method, url, true);
1298
- xhr.withCredentials = config.WITH_CREDENTIALS;
1299
-
1300
- headers.forEach((value, key) => {
1301
- xhr.setRequestHeader(key, value);
1302
- });
1303
-
1304
- return new Promise<XMLHttpRequest>(async (resolve, reject) => {
1305
- xhr.onload = () => resolve(xhr);
1306
- xhr.onabort = () => reject(new Error('Request aborted'));
1307
- xhr.onerror = () => reject(new Error('Network error'));
1308
-
1309
- for (const fn of config.interceptors.request._fns) {
1310
- xhr = await fn(xhr);
1311
- }
1312
-
1313
- xhr.send(body ?? formData);
1314
-
1315
- onCancel(() => xhr.abort());
1316
- });
1317
- };`},useData:!0};const Ve=()=>{s.default.registerHelper(`camelCase`,function(t){return e.y({case:`camelCase`,value:t})}),s.default.registerHelper(`equals`,function(e,t,n){return e===t?n.fn(this):n.inverse(this)}),s.default.registerHelper(`ifServicesResponse`,function(t,n){return e.C().plugins[`@hey-api/sdk`]?.config.response===t?n.fn(this):n.inverse(this)}),s.default.registerHelper(`ifdef`,function(...e){let t=e.pop();return e.every(e=>!e)?t.inverse(this):t.fn(this)}),s.default.registerHelper(`notEquals`,function(e,t,n){return e===t?n.inverse(this):n.fn(this)}),s.default.registerHelper(`transformServiceName`,function(t){return e.m({config:e.C(),name:t})})},He=()=>{Ve();let e={client:s.default.template(R),core:{apiError:s.default.template(G),apiRequestOptions:s.default.template(K),apiResult:s.default.template(q),baseHttpRequest:s.default.template(me),cancelablePromise:s.default.template(he),httpRequest:s.default.template(Ne),request:s.default.template(Fe),settings:s.default.template(Pe)}};return s.default.registerPartial(`functions/base64`,s.default.template(Se)),s.default.registerPartial(`functions/catchErrorCodes`,s.default.template(Ce)),s.default.registerPartial(`functions/getFormData`,s.default.template(we)),s.default.registerPartial(`functions/getQueryString`,s.default.template(Te)),s.default.registerPartial(`functions/getUrl`,s.default.template(Ee)),s.default.registerPartial(`functions/isBlob`,s.default.template(De)),s.default.registerPartial(`functions/isFormData`,s.default.template(Oe)),s.default.registerPartial(`functions/isString`,s.default.template(ke)),s.default.registerPartial(`functions/isStringWithValue`,s.default.template(Ae)),s.default.registerPartial(`functions/isSuccess`,s.default.template(je)),s.default.registerPartial(`functions/resolve`,s.default.template(Me)),s.default.registerPartial(`fetch/getHeaders`,s.default.template(ge)),s.default.registerPartial(`fetch/getRequestBody`,s.default.template(_e)),s.default.registerPartial(`fetch/getResponseBody`,s.default.template(ve)),s.default.registerPartial(`fetch/getResponseHeader`,s.default.template(ye)),s.default.registerPartial(`fetch/request`,s.default.template(be)),s.default.registerPartial(`fetch/sendRequest`,s.default.template(xe)),s.default.registerPartial(`xhr/getHeaders`,s.default.template(Ie)),s.default.registerPartial(`xhr/getRequestBody`,s.default.template(Le)),s.default.registerPartial(`xhr/getResponseBody`,s.default.template(Re)),s.default.registerPartial(`xhr/getResponseHeader`,s.default.template(ze)),s.default.registerPartial(`xhr/request`,s.default.template(J)),s.default.registerPartial(`xhr/sendRequest`,s.default.template(Be)),s.default.registerPartial(`axios/getHeaders`,s.default.template(ce)),s.default.registerPartial(`axios/getRequestBody`,s.default.template(le)),s.default.registerPartial(`axios/getResponseBody`,s.default.template(ue)),s.default.registerPartial(`axios/getResponseHeader`,s.default.template(de)),s.default.registerPartial(`axios/request`,s.default.template(fe)),s.default.registerPartial(`axios/sendRequest`,s.default.template(pe)),s.default.registerPartial(`angular/getHeaders`,s.default.template(z)),s.default.registerPartial(`angular/getRequestBody`,s.default.template(B)),s.default.registerPartial(`angular/getResponseBody`,s.default.template(V)),s.default.registerPartial(`angular/getResponseHeader`,s.default.template(H)),s.default.registerPartial(`angular/request`,s.default.template(U)),s.default.registerPartial(`angular/sendRequest`,s.default.template(W)),e};let Ue=0;const Y=e=>`${e}-${Ue++}`,X=e=>`${e}-end`,Z=e=>`${e}-length`,Q=e=>`${e}-start`,We=(e,t)=>{if(e>200)return{color:n.default.red,type:`duration`};if(t>30)return{color:n.default.red,type:`percentage`};if(e>50)return{color:n.default.yellow,type:`duration`};if(t>10)return{color:n.default.yellow,type:`percentage`}};var $=class{events=[];end(e){let t,n=this.events;for(let r of e.position)t=n[r],t?.events&&(n=t.events);t&&!t.end&&(t.end=performance.mark(X(t.id)))}report(e=!0){let t=this.events[0];if(!t)return;let n=this.events[this.events.length-1],r=`root`,i=Y(r),a=performance.measure(Z(i),Q(t.id),X(n.id));return e&&this.reportEvent({end:n.end,events:this.events,id:i,indent:0,measure:a,name:r,start:t.start}),a}reportEvent({indent:e,...t}){let r=e?n.default.gray:n.default.cyan,i=t.events.length-1;t.events.forEach((a,o)=>{let s=performance.measure(Z(a.id),Q(a.id),X(a.id)),c=Math.ceil(s.duration*100)/100,l=Math.ceil(s.duration/t.measure.duration*100*100)/100,u=e?We(c,l):void 0,d=`${c.toFixed(2).padStart(8)}ms`;u?.type===`duration`&&(d=u.color(d));let f=o===i?`└─ `:`├─ `,p=e?`│ `.repeat(e-1)+f:``,m=38-p.length,h=e?`↳ `:``,g=`${e?` `.repeat(e-1)+h:``}${l.toFixed(2)}%`;u?.type===`percentage`&&(g=u.color(g));let _=n.default.gray(`[root] `);console.log(`${_}${n.default.gray(p)}${r(`${a.name.padEnd(m)} ${d} (${g})`)}`),this.reportEvent({...a,indent:e+1,measure:s})})}start(e){return performance.mark(Q(e))}storeEvent({result:e,...t}){let n=t.events.length-1,r=t.events[n];if(r&&!r.end){e.position=[...e.position,n],this.storeEvent({...t,events:r.events,result:e});return}let i=t.events.push({...t,events:[]});e.position=[...e.position,i-1]}timeEvent(e){let t=Y(e),n=this.start(t),r={events:this.events,id:t,name:e,start:n},i={position:[]};return this.storeEvent({...r,result:i}),{mark:n,timeEnd:()=>this.end(i)}}};const Ge={stringCase:e.y};n.default.enabled=(0,r.default)().hasBasic;const Ke=async(t,n=new $)=>{let r=typeof t==`function`?await t():t,i=r?r instanceof Array?r:[r]:[],a=i.find(t=>e.S(t).level!==`silent`)?.logs;typeof a==`string`&&(a=e.S({logs:a}));let o;try{c();let t=n.timeEvent(`createClient`),r=n.timeEvent(`config`);o=await e.n({logger:n,userConfigs:i}),o.results.some(e=>e.config.logs.level!==`silent`)&&L(),r.timeEnd();let a=o.results.flatMap(e=>e.errors.map(t=>({error:t,jobIndex:e.jobIndex})));if(a.length)throw new e.O(a);let s=n.timeEvent(`handlebars`),l=He();s.timeEnd();let u=(await Promise.all(o.results.map(async t=>{try{return await F({config:t.config,dependencies:o.dependencies,jobIndex:t.jobIndex,logger:n,templates:l})}catch(n){throw new e.k(``,{error:n,jobIndex:t.jobIndex})}}))).filter(e=>!!e);t.timeEnd();let d=o.results.some(e=>e.config.logs.level===`debug`);return n.report(d),u}catch(t){let n=o?.results??[],r=n.find(e=>e.config.logs.level!==`silent`)?.config.logs??n[0]?.config.logs??a,s=n.some(e=>e.config.dryRun)??i.some(e=>e.dryRun)??!1,c=r?.file&&!s?e.A(t,r.path??``):void 0;throw(!r||r.level!==`silent`)&&(e.M({error:t,logPath:c}),await e.N({error:t,isInteractive:n.some(e=>e.config.interactive)??i.some(e=>e.interactive)??!1})&&await e.j(t)),t}},qe=async e=>typeof e==`function`?await e():e;exports.Logger=$,exports.clientDefaultConfig=e.s,exports.clientDefaultMeta=e.c,exports.clientPluginHandler=e.a,exports.compiler=e._,exports.createClient=Ke,exports.defaultPaginationKeywords=e.x,exports.defaultPlugins=e.r,exports.defineConfig=qe,exports.definePluginConfig=e.b,exports.tsc=e.v,exports.utils=Ge;
1318
- //# sourceMappingURL=index.cjs.map
1
+ const e=require(`./getSpec-dCAz_woE.cjs`),t=require(`./src-ZtEOUDGN.cjs`);exports.Logger=t.i,exports.clientDefaultConfig=e.s,exports.clientDefaultMeta=e.c,exports.clientPluginHandler=e.a,exports.compiler=e._,exports.createClient=t.r,exports.defaultPaginationKeywords=e.x,exports.defaultPlugins=e.r,exports.defineConfig=t.t,exports.definePluginConfig=e.b,exports.tsc=e.v,exports.utils=t.n;