ci: regenerated with OpenAPI Doc latest, Speakeasy CLI 1.360.0

This commit is contained in:
speakeasybot
2024-08-10 00:23:32 +00:00
parent c8c28064c7
commit d91ffcb778
10 changed files with 150 additions and 17 deletions

View File

@@ -3,10 +3,10 @@ id: 599a9576-4665-431e-be1e-44cc13ef28aa
management: management:
docChecksum: dd4d04e62622de8f631720b5be68964d docChecksum: dd4d04e62622de8f631720b5be68964d
docVersion: latest docVersion: latest
speakeasyVersion: 1.358.0 speakeasyVersion: 1.360.0
generationVersion: 2.390.6 generationVersion: 2.392.0
releaseVersion: 0.5.0 releaseVersion: 0.6.0
configChecksum: 76366dee2b6c919409101b279e0d2575 configChecksum: 10b03678b9f493d15f149a0580702c40
repoURL: https://github.com/LukeHagar/discoursejs.git repoURL: https://github.com/LukeHagar/discoursejs.git
repoSubDirectory: . repoSubDirectory: .
installationURL: https://github.com/LukeHagar/discoursejs installationURL: https://github.com/LukeHagar/discoursejs
@@ -16,7 +16,7 @@ features:
additionalDependencies: 0.1.0 additionalDependencies: 0.1.0
additionalProperties: 0.1.1 additionalProperties: 0.1.1
constsAndDefaults: 0.1.6 constsAndDefaults: 0.1.6
core: 3.12.3 core: 3.13.0
defaultEnabledRetries: 0.1.0 defaultEnabledRetries: 0.1.0
deprecations: 2.81.1 deprecations: 2.81.1
envVarSecurityUsage: 0.1.1 envVarSecurityUsage: 0.1.1
@@ -157,6 +157,7 @@ generatedFiles:
- src/lib/encodings.ts - src/lib/encodings.ts
- src/lib/http.ts - src/lib/http.ts
- src/lib/is-plain-object.ts - src/lib/is-plain-object.ts
- src/lib/logger.ts
- src/lib/matchers.ts - src/lib/matchers.ts
- src/lib/primitives.ts - src/lib/primitives.ts
- src/lib/retries.ts - src/lib/retries.ts

View File

@@ -460,6 +460,21 @@ run();
``` ```
<!-- End Retries [retries] --> <!-- End Retries [retries] -->
<!-- Start Debugging [debug] -->
## Debugging
To log HTTP requests and responses, you can pass a logger that matches `console`'s interface as an SDK option.
> [!WARNING]
> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
```typescript
import { SDK } from "@lukehagar/discoursejs";
const sdk = new SDK({ debugLogger: console });
```
<!-- End Debugging [debug] -->
<!-- Placeholder for Future Speakeasy SDK Sections --> <!-- Placeholder for Future Speakeasy SDK Sections -->
# Development # Development

View File

@@ -179,3 +179,13 @@ Based on:
- [typescript v0.5.0] . - [typescript v0.5.0] .
### Releases ### Releases
- [NPM v0.5.0] https://www.npmjs.com/package/@lukehagar/discoursejs/v/0.5.0 - . - [NPM v0.5.0] https://www.npmjs.com/package/@lukehagar/discoursejs/v/0.5.0 - .
## 2024-08-10 00:22:12
### Changes
Based on:
- OpenAPI Doc latest
- Speakeasy CLI 1.360.0 (2.392.0) https://github.com/speakeasy-api/speakeasy
### Generated
- [typescript v0.6.0] .
### Releases
- [NPM v0.6.0] https://www.npmjs.com/package/@lukehagar/discoursejs/v/0.6.0 - .

View File

@@ -11,7 +11,7 @@ generation:
auth: auth:
oAuth2ClientCredentialsEnabled: false oAuth2ClientCredentialsEnabled: false
typescript: typescript:
version: 0.5.0 version: 0.6.0
additionalDependencies: additionalDependencies:
dependencies: {} dependencies: {}
devDependencies: {} devDependencies: {}

View File

@@ -2,7 +2,7 @@
{ {
"name": "@lukehagar/discoursejs", "name": "@lukehagar/discoursejs",
"version": "0.5.0", "version": "0.6.0",
"exports": { "exports": {
".": "./src/index.ts", ".": "./src/index.ts",
"./sdk/models/errors": "./src/sdk/models/errors/index.ts", "./sdk/models/errors": "./src/sdk/models/errors/index.ts",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@lukehagar/discoursejs", "name": "@lukehagar/discoursejs",
"version": "0.5.0", "version": "0.6.0",
"author": "LukeHagar", "author": "LukeHagar",
"main": "./index.js", "main": "./index.js",
"sideEffects": false, "sideEffects": false,

View File

@@ -3,6 +3,7 @@
*/ */
import { HTTPClient } from "./http.js"; import { HTTPClient } from "./http.js";
import { Logger } from "./logger.js";
import { RetryConfig } from "./retries.js"; import { RetryConfig } from "./retries.js";
import { Params, pathToFunc } from "./url.js"; import { Params, pathToFunc } from "./url.js";
@@ -30,6 +31,7 @@ export type SDKOptions = {
*/ */
retryConfig?: RetryConfig; retryConfig?: RetryConfig;
timeoutMs?: number; timeoutMs?: number;
debugLogger?: Logger;
}; };
export function serverURLFromOptions(options: SDKOptions): URL | null { export function serverURLFromOptions(options: SDKOptions): URL | null {
@@ -58,7 +60,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
export const SDK_METADATA = { export const SDK_METADATA = {
language: "typescript", language: "typescript",
openapiDocVersion: "latest", openapiDocVersion: "latest",
sdkVersion: "0.5.0", sdkVersion: "0.6.0",
genVersion: "2.390.6", genVersion: "2.392.0",
userAgent: "speakeasy-sdk/typescript 0.5.0 2.390.6 latest @lukehagar/discoursejs", userAgent: "speakeasy-sdk/typescript 0.6.0 2.392.0 latest @lukehagar/discoursejs",
} as const; } as const;

View File

@@ -157,7 +157,7 @@ export type StatusCodePredicate = number | string | (number | string)[];
// segments in a media type string. // segments in a media type string.
const mediaParamSeparator = /\s*;\s*/g; const mediaParamSeparator = /\s*;\s*/g;
function matchContentType(response: Response, pattern: string): boolean { export function matchContentType(response: Response, pattern: string): boolean {
// `*` is a special case which means anything is acceptable. // `*` is a special case which means anything is acceptable.
if (pattern === "*") { if (pattern === "*") {
return true; return true;

9
src/lib/logger.ts Normal file
View File

@@ -0,0 +1,9 @@
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
export interface Logger {
group(label?: string): void;
groupEnd(): void;
log(message: any, ...args: any[]): void;
}

View File

@@ -4,6 +4,7 @@
import { import {
HTTPClient, HTTPClient,
matchContentType,
matchStatusCode, matchStatusCode,
isAbortError, isAbortError,
isTimeoutError, isTimeoutError,
@@ -11,6 +12,7 @@ import {
} from "./http.js"; } from "./http.js";
import { SecurityState } from "./security.js"; import { SecurityState } from "./security.js";
import { retry, RetryConfig } from "./retries.js"; import { retry, RetryConfig } from "./retries.js";
import { Logger } from "./logger.js";
import { encodeForm } from "./encodings.js"; import { encodeForm } from "./encodings.js";
import { stringToBase64 } from "./base64.js"; import { stringToBase64 } from "./base64.js";
import { SDKOptions, SDK_METADATA, serverURLFromOptions } from "./config.js"; import { SDKOptions, SDK_METADATA, serverURLFromOptions } from "./config.js";
@@ -74,6 +76,7 @@ export class ClientSDK {
private readonly httpClient: HTTPClient; private readonly httpClient: HTTPClient;
protected readonly baseURL: URL | null; protected readonly baseURL: URL | null;
protected readonly hooks$: SDKHooks; protected readonly hooks$: SDKHooks;
protected readonly logger?: Logger | undefined;
public readonly options$: SDKOptions & { hooks?: SDKHooks }; public readonly options$: SDKOptions & { hooks?: SDKHooks };
constructor(options: SDKOptions = {}) { constructor(options: SDKOptions = {}) {
@@ -100,6 +103,7 @@ export class ClientSDK {
}); });
this.baseURL = baseURL; this.baseURL = baseURL;
this.httpClient = client; this.httpClient = client;
this.logger = options.debugLogger;
} }
public createRequest$( public createRequest$(
@@ -217,12 +221,13 @@ export class ClientSDK {
return retry( return retry(
async () => { async () => {
const req = request.clone(); const req = await this.hooks$.beforeRequest(context, request.clone());
await logRequest(this.logger, req).catch((e) =>
let response = await this.httpClient.request( this.logger?.log("Failed to log request:", e)
await this.hooks$.beforeRequest(context, req)
); );
let response = await this.httpClient.request(req);
if (matchStatusCode(response, errorCodes)) { if (matchStatusCode(response, errorCodes)) {
const result = await this.hooks$.afterError(context, response, null); const result = await this.hooks$.afterError(context, response, null);
if (result.error) { if (result.error) {
@@ -233,6 +238,10 @@ export class ClientSDK {
response = await this.hooks$.afterSuccess(context, response); response = await this.hooks$.afterSuccess(context, response);
} }
await logResponse(this.logger, response, req).catch((e) =>
this.logger?.log("Failed to log response:", e)
);
return response; return response;
}, },
{ config: retryConfig, statusCodes: retryCodes } { config: retryConfig, statusCodes: retryCodes }
@@ -259,3 +268,90 @@ export class ClientSDK {
); );
} }
} }
const jsonLikeContentTypeRE = /^application\/(?:.{0,100}\+)?json/;
async function logRequest(logger: Logger | undefined, req: Request) {
if (!logger) {
return;
}
const contentType = req.headers.get("content-type");
const ct = contentType?.split(";")[0] || "";
logger.group(`> Request: ${req.method} ${req.url}`);
logger.group("Headers:");
for (const [k, v] of req.headers.entries()) {
logger.log(`${k}: ${v}`);
}
logger.groupEnd();
logger.group("Body:");
switch (true) {
case jsonLikeContentTypeRE.test(ct):
logger.log(await req.clone().json());
break;
case ct.startsWith("text/"):
logger.log(await req.clone().text());
break;
case ct === "multipart/form-data": {
const body = await req.clone().formData();
for (const [k, v] of body) {
const vlabel = v instanceof Blob ? "<Blob>" : v;
logger.log(`${k}: ${vlabel}`);
}
break;
}
default:
logger.log(`<${contentType}>`);
break;
}
logger.groupEnd();
logger.groupEnd();
}
async function logResponse(logger: Logger | undefined, res: Response, req: Request) {
if (!logger) {
return;
}
const contentType = res.headers.get("content-type");
const ct = contentType?.split(";")[0] || "";
logger.group(`< Response: ${req.method} ${req.url}`);
logger.log("Status Code:", res.status, res.statusText);
logger.group("Headers:");
for (const [k, v] of res.headers.entries()) {
logger.log(`${k}: ${v}`);
}
logger.groupEnd();
logger.group("Body:");
switch (true) {
case matchContentType(res, "application/json") || jsonLikeContentTypeRE.test(ct):
logger.log(await res.clone().json());
break;
case matchContentType(res, "text/event-stream"):
logger.log(`<${contentType}>`);
break;
case matchContentType(res, "text/*"):
logger.log(await res.clone().text());
break;
case matchContentType(res, "multipart/form-data"): {
const body = await res.clone().formData();
for (const [k, v] of body) {
const vlabel = v instanceof Blob ? "<Blob>" : v;
logger.log(`${k}: ${vlabel}`);
}
break;
}
default:
logger.log(`<${contentType}>`);
break;
}
logger.groupEnd();
logger.groupEnd();
}