oapiex 0.3.8 → 0.3.9

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/bin/cli.mjs CHANGED
@@ -177,7 +177,7 @@ import{JSDOM as e}from"jsdom";import{Window as t}from"happy-dom";import n from"a
177
177
  `;description=`Generate artifacts such as SDK packages from documentation sources or parsed TypeScript outputs`;async handle(){let e=this.app.getConfig(),t=String(this.argument(`artifact`,``)).trim().toLowerCase(),n=String(this.argument(`source`,``)).trim(),i=String(this.option(`browser`,e.browser)).trim().toLowerCase(),a=String(this.option(`timeout`,``)).trim(),o=this.option(`crawl`),s=String(this.option(`baseUrl`,``)).trim()||null,c=await this.resolveOutputDirectory(n),l=this.spinner(`Generating ${t} artifact...`).start(),u=!1;try{let d=Date.now();if(!P(i))throw Error(`Unsupported browser: ${i}`);if(t!==`sdk`)throw Error(`Unsupported artifact: ${t}`);if(!n)throw Error(`The sdk artifact requires a source argument`);if(!this.isTypeScriptArtifactSource(n)&&!P(i))throw Error(`Unsupported browser: ${i}`);let f=this.resolveTimeoutOverride(a,e.requestTimeout),p=this.parseNamespaceStrategy(this.option(`namespaceStrategy`,`smart`)),m=this.parseMethodStrategy(this.option(`methodStrategy`,`smart`)),h=this.parseOutputMode(this.option(`outputMode`,`both`)),g=this.parseSignatureStyle(this.option(`signatureStyle`,`grouped`)),_=String(this.option(`rootTypeName`,`ExtractedApiDocument`)).trim()||`ExtractedApiDocument`;this.app.configure({browser:i,requestTimeout:f}),!this.isTypeScriptArtifactSource(n)&&o&&(await j(this.app.getConfig()),u=!0);let v=await this.resolveSdkSource({source:n,crawl:o,baseUrl:s,rootTypeName:_,namespaceStrategy:p,methodStrategy:m}),y=this.resolvePackageName(c),b=new et().generate(v.document,{outputMode:h,signatureStyle:g,rootTypeName:_,namespaceStrategy:p,methodStrategy:m,schemaModule:v.schemaModule,packageName:String(this.option(`name`,``)).trim()||y});await this.writePackageFiles(c,b);let x=Date.now()-d;r.twoColumnDetail(r.log([[`Generated`,`green`],[`${x/1e3}s`,`gray`]],` `,!1),c.replace(process.cwd(),`.`)),l.succeed(`Artifact generation completed`)}catch(e){let t=e instanceof Error?e.message:`Unknown error`;l.fail(`Failed to generate artifact: ${t}`),process.exitCode=1}finally{u&&await M()}}async resolveSdkSource(e){if(this.isTypeScriptArtifactSource(e.source))return this.loadSdkSourceFromTypeScriptArtifact(e.source);let t=L(await this.app.loadHtmlSource(e.source,!0)),n=e.crawl?await this.app.crawlReadmeOperations(e.source,t,e.baseUrl):t,r=this.buildOpenApiPayload(n);return{document:r,schemaModule:await l.format(Z.generateModule(r,e.rootTypeName,{namespaceStrategy:e.namespaceStrategy,methodStrategy:e.methodStrategy}),{parser:`typescript`,semi:!1,singleQuote:!0})}}async loadSdkSourceFromTypeScriptArtifact(e){let t=i.resolve(process.cwd(),e),n=await a.readFile(t,`utf8`),r=await import(`${d(t).href}?t=${Date.now()}`),o=r.default??Object.values(r).find(e=>this.isOpenApiDocumentLike(e));if(!this.isOpenApiDocumentLike(o))throw Error(`The provided TypeScript source does not export an OpenAPI document`);return{document:o,schemaModule:n}}buildOpenApiPayload(e){return`operations`in e?$.createDocument(e.operations,`Extracted API`,`0.0.0`):$.createDocument([e],`Extracted API`,`0.0.0`)}resolveTimeoutOverride(e,t){if(!e)return t;let n=Number(e);if(!Number.isFinite(n)||n<=0)throw Error(`Invalid timeout override: ${e}`);return n}async resolveOutputDirectory(e,t){t??=String(this.option(`dir`,``)).trim();let n=t?i.resolve(process.cwd(),t):Q.buildArtifactDirectory(process.cwd(),e,`sdk`);if(f(n)&&p(n).length>0)switch(await this.choice(`Output directory (${t}) already exists and is not empty, what would you like to do?`,[{name:`Overwrite`,value:`overwrite`},{name:`Try to merge`,value:`merge`},{name:`Choose a different directory`,value:`choose`},{name:`Cancel`,value:`cancel`}])){case`overwrite`:await a.rm(n,{recursive:!0,force:!0});break;case`choose`:{let n=await this.ask(`Please enter a new output directory (relative to current directory):`,t);return this.resolveOutputDirectory(e,n)}case`cancel`:return this.info(`Operation cancelled by user`),process.exit(0);default:break}return n}resolvePackageName(e){return String(this.option(`name`,``)).trim()||i.basename(e).replace(/[^a-zA-Z0-9._-]+/g,`-`).replace(/^-+|-+$/g,``)||`generated-sdk`}parseOutputMode(e){let t=String(e??`both`).trim().toLowerCase();if(t===`runtime`||t===`classes`||t===`both`)return t;throw Error(`Unsupported sdk output mode: ${t}`)}parseSignatureStyle(e){let t=String(e??`grouped`).trim().toLowerCase();if(t===`flat`||t===`grouped`)return t;throw Error(`Unsupported signature style: ${t}`)}parseNamespaceStrategy(e){let t=String(e??`smart`).trim().toLowerCase();if(t===`smart`||t===`scoped`)return t;throw Error(`Unsupported namespace strategy: ${t}`)}parseMethodStrategy(e){let t=String(e??`smart`).trim().toLowerCase();if(t===`smart`||t===`operation-id`)return t;throw Error(`Unsupported method strategy: ${t}`)}isTypeScriptArtifactSource(e){return/\.(?:[cm]?ts|[cm]?js)$/i.test(e)}isOpenApiDocumentLike(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e,n=t.info;return t.openapi===`3.1.0`&&typeof n==`object`&&!!n&&!Array.isArray(n)&&typeof n.title==`string`&&typeof n.version==`string`&&typeof t.paths==`object`&&t.paths!==null&&!Array.isArray(t.paths)}async writePackageFiles(e,t){await Promise.all(Object.entries(t).map(async([t,n])=>{let r=i.join(e,t);await a.mkdir(i.dirname(r),{recursive:!0}),await a.writeFile(r,n,`utf8`)}))}};const nt=m(import.meta.url);var rt=class extends s{signature=`init
178
178
  {--f|force : Overwrite existing config}
179
179
  {--S|sdk-kit : Also include default SDK config values.}
180
- `;description=`Generate a default oapiex.config.ts in the current directory`;async handle(){let e=process.cwd(),t=i.join(e,`oapiex.config.js`),n=this.option(`force`,!1),r=this.option(`sdkKit`,!1),o=this.buildConfigTemplate(r);try{await a.access(t),n||(this.error(`Config file already exists at ${t}. Use --force to overwrite.`),process.exit(1))}catch{}await a.writeFile(t,o,`utf8`),this.line(`Created ${t} `)}buildConfigTemplate(e=!1){let t=g;return[`import { defineConfig } from '${nt.includes(`node_modules`)?`oapiex`:`./src/config`}'`,``,`/**`,` * See https://toneflix.github.io/oapiex/configuration for docs`,` */`,`export default defineConfig({`,` outputFormat: '${t.outputFormat}',`,` outputShape: '${t.outputShape}',`,` browser: '${t.browser}',`,` requestTimeout: ${t.requestTimeout},`,` maxRedirects: ${t.maxRedirects},`,` userAgent: '${t.userAgent}',`,` retryCount: ${t.retryCount},`,` retryDelay: ${t.retryDelay},`,e?this.buildSdkConfigTemplate():void 0,`})`].filter(Boolean).join(`
180
+ `;description=`Generate a default oapiex.config.ts in the current directory`;async handle(){let e=process.cwd(),t=i.join(e,`oapiex.config.js`),n=this.option(`force`,!1),r=this.option(`sdkKit`,!1),o=this.buildConfigTemplate(r);try{await a.access(t),n||(this.error(`Config file already exists at ${t}. Use --force to overwrite.`),process.exit(1))}catch{}await a.writeFile(t,o,`utf8`),this.line(`Created ${t} `)}buildConfigTemplate(e=!1){let t=g;return[`import { defineConfig } from '${nt.includes(`node_modules`)?`oapiex`:`./src/config`}'`,``,`/**`,` * See https://toneflix.github.io/oapiex/reference/configuration for docs`,` */`,`export default defineConfig({`,` outputFormat: '${t.outputFormat}',`,` outputShape: '${t.outputShape}',`,` browser: '${t.browser}',`,` requestTimeout: ${t.requestTimeout},`,` maxRedirects: ${t.maxRedirects},`,` userAgent: '${t.userAgent}',`,` retryCount: ${t.retryCount},`,` retryDelay: ${t.retryDelay},`,e?this.buildSdkConfigTemplate():void 0,`})`].filter(Boolean).join(`
181
181
  `)}buildSdkConfigTemplate(){return[` sdkKit: {`,` clientId: 'your-client-id',`,` clientSecret: 'your-client-secret',`,` encryptionKey: 'your-encryption-key',`,` environment: 'sandbox',`,` urls: {`,` live: 'https://live.oapiex.com',`,` sandbox: 'https://sandbox.oapiex.com',`,` },`,` debugLevel: 0,`,` },`].join(`
182
182
  `)}},it=class extends s{signature=`parse
183
183
  {source : Local HTML file path or remote URL}
package/dist/index.cjs CHANGED
@@ -3812,7 +3812,7 @@ var InitCommand = class extends _h3ravel_musket.Command {
3812
3812
  `import { defineConfig } from '${__filename$1.includes("node_modules") ? "oapiex" : "./src/config"}'`,
3813
3813
  "",
3814
3814
  "/**",
3815
- " * See https://toneflix.github.io/oapiex/configuration for docs",
3815
+ " * See https://toneflix.github.io/oapiex/reference/configuration for docs",
3816
3816
  " */",
3817
3817
  "export default defineConfig({",
3818
3818
  ` outputFormat: '${def.outputFormat}',`,
package/dist/index.mjs CHANGED
@@ -3780,7 +3780,7 @@ var InitCommand = class extends Command {
3780
3780
  `import { defineConfig } from '${__filename.includes("node_modules") ? "oapiex" : "./src/config"}'`,
3781
3781
  "",
3782
3782
  "/**",
3783
- " * See https://toneflix.github.io/oapiex/configuration for docs",
3783
+ " * See https://toneflix.github.io/oapiex/reference/configuration for docs",
3784
3784
  " */",
3785
3785
  "export default defineConfig({",
3786
3786
  ` outputFormat: '${def.outputFormat}',`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oapiex",
3
3
  "type": "module",
4
- "version": "0.3.8",
4
+ "version": "0.3.9",
5
5
  "description": "CLI and TypeScript toolkit for turning documentation pages into usable developer artifacts.",
6
6
  "main": "./dist/index.cjs",
7
7
  "private": false,