Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Nov 20, 2024
1 parent f57ad8d commit 02e6323
Show file tree
Hide file tree
Showing 466 changed files with 30,108 additions and 22,280 deletions.
11 changes: 11 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.42.0] - 2024-11-15

- Feat: Added support for `.asRaw()` which allows users to access raw response data including headers. For example:

```ts
const response = await client.someEndpoint().asRaw();
console.log(response.headers['X-My-Header']);
console.log(response.body);
```


## [0.41.1] - 2024-11-02

- Fix: Remove dev dependency on `jest-fetch-mock`.
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.41.1
0.42.0
11 changes: 9 additions & 2 deletions generators/typescript/sdk/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ features:
description: |
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
will be thrown.
- id: RAW_RESPONSES
advanced: true
description: |
The SDK provides access to raw response data, including headers, through the `.asRaw()` method. When using `.asRaw()`,
the parsed response body will be available in the `body` field, along with the response headers:
- id: RETRIES
advanced: true
description: |
Expand Down Expand Up @@ -54,4 +60,5 @@ features:
### Customizing Fetch Client
The SDK provides a way for your to customize the underlying HTTP client / Fetch function. If you're running in an
unsupported environment, this provides a way for you to break glass and ensure the SDK works.
unsupported environment, this provides a way for you to break glass and ensure the SDK works.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import {
FeatureId,
FernFilepath,
HttpEndpoint,
HttpService,
ReadmeConfig,
SdkRequestWrapper,
ServiceId
} from "@fern-fern/ir-sdk/api";
import { getTextOfTsNode, NpmPackage } from "@fern-typescript/commons";
import { getTextOfTsNode } from "@fern-typescript/commons";
import { SdkContext } from "@fern-typescript/contexts";
import { code, Code } from "ts-poet";
import { AbstractReadmeSnippetBuilder } from "@fern-api/generator-commons";
Expand All @@ -32,6 +29,7 @@ export class ReadmeSnippetBuilder extends AbstractReadmeSnippetBuilder {
private static RUNTIME_COMPATIBILITY_FEATURE_ID: FernGeneratorCli.FeatureId = "RUNTIME_COMPATIBILITY";
private static STREAMING_FEATURE_ID: FernGeneratorCli.FeatureId = "STREAMING";
private static PAGINATION_FEATURE_ID: FernGeneratorCli.FeatureId = "PAGINATION";
private static RAW_RESPONSES_FEATURE_ID: FernGeneratorCli.FeatureId = "RAW_RESPONSES";

private readonly context: SdkContext;
private readonly isPaginationEnabled: boolean;
Expand Down Expand Up @@ -71,10 +69,12 @@ export class ReadmeSnippetBuilder extends AbstractReadmeSnippetBuilder {
snippets[FernGeneratorCli.StructuredFeatureId.Usage] = this.buildUsageSnippets();
snippets[FernGeneratorCli.StructuredFeatureId.Retries] = this.buildRetrySnippets();
snippets[FernGeneratorCli.StructuredFeatureId.Timeouts] = this.buildTimeoutSnippets();

snippets[ReadmeSnippetBuilder.ABORTING_REQUESTS_FEATURE_ID] = this.buildAbortSignalSnippets();
snippets[ReadmeSnippetBuilder.EXCEPTION_HANDLING_FEATURE_ID] = this.buildExceptionHandlingSnippets();
snippets[ReadmeSnippetBuilder.RUNTIME_COMPATIBILITY_FEATURE_ID] = this.buildRuntimeCompatibilitySnippets();
snippets[ReadmeSnippetBuilder.STREAMING_FEATURE_ID] = this.buildStreamingSnippets();
snippets[ReadmeSnippetBuilder.RAW_RESPONSES_FEATURE_ID] = this.buildRawResponseSnippets();

if (this.isPaginationEnabled) {
snippets[ReadmeSnippetBuilder.PAGINATION_FEATURE_ID] = this.buildPaginationSnippets();
Expand Down Expand Up @@ -152,6 +152,20 @@ const request: ${requestTypeName} = {
];
}

private buildRawResponseSnippets(): string[] {
const rawResponseEndpoints = this.getEndpointsForFeature(ReadmeSnippetBuilder.RAW_RESPONSES_FEATURE_ID);
return rawResponseEndpoints.map((rawResponseEndpoint) =>
this.writeCode(
code`
const response = await ${this.getMethodCall(rawResponseEndpoint)}(...).asRaw();
console.log(response.headers['X-My-Header']);
console.log(response.body);
`
)
);
}

private buildRetrySnippets(): string[] {
const retryEndpoints = this.getEndpointsForFeature(FernGeneratorCli.StructuredFeatureId.Retries);
return retryEndpoints.map((retryEndpoint) =>
Expand Down
12 changes: 12 additions & 0 deletions seed/ts-sdk/alias-extends/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 49 additions & 43 deletions seed/ts-sdk/alias-extends/src/Client.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions seed/ts-sdk/alias-extends/src/core/api-promise/APIPromise.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/alias-extends/src/core/api-promise/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/alias-extends/src/core/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions seed/ts-sdk/alias/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 47 additions & 44 deletions seed/ts-sdk/alias/src/Client.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 02e6323

Please sign in to comment.