Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from rivet-gg/max/remove-headers
Browse files Browse the repository at this point in the history
Remove `x-fern-*` headers from TypeScript library for CORS
  • Loading branch information
NathanFlurry authored Feb 19, 2024
2 parents 2f37a60 + aeead95 commit f176201
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import {
VariableDeclaration,
VariableId
} from "@fern-fern/ir-sdk/api";
import { getTextOfTsNode, JavaScriptRuntime, maybeAddDocs, NpmPackage, PackageId } from "@fern-typescript/commons";
import { JavaScriptRuntime, NpmPackage, PackageId, getTextOfTsNode, maybeAddDocs } from "@fern-typescript/commons";
import { GeneratedSdkClientClass, SdkContext } from "@fern-typescript/contexts";
import { ErrorResolver, PackageResolver } from "@fern-typescript/resolvers";
import { InterfaceDeclarationStructure, OptionalKind, PropertySignatureStructure, Scope, ts } from "ts-morph";
import { GeneratedHeader } from "./GeneratedHeader";
import { GeneratedWrappedService } from "./GeneratedWrappedService";
import { GeneratedDefaultEndpointRequest } from "./endpoint-request/GeneratedDefaultEndpointRequest";
import { GeneratedFileUploadEndpointRequest } from "./endpoint-request/GeneratedFileUploadEndpointRequest";
import { GeneratedNonThrowingEndpointResponse } from "./endpoints/default/endpoint-response/GeneratedNonThrowingEndpointResponse";
import { GeneratedThrowingEndpointResponse } from "./endpoints/default/endpoint-response/GeneratedThrowingEndpointResponse";
import { GeneratedDefaultEndpointImplementation } from "./endpoints/default/GeneratedDefaultEndpointImplementation";
import { GeneratedEndpointImplementation } from "./endpoints/GeneratedEndpointImplementation";
import { GeneratedFileDownloadEndpointImplementation } from "./endpoints/GeneratedFileDownloadEndpointImplementation";
import { GeneratedStreamingEndpointImplementation } from "./endpoints/GeneratedStreamingEndpointImplementation";
import { GeneratedDefaultEndpointImplementation } from "./endpoints/default/GeneratedDefaultEndpointImplementation";
import { GeneratedNonThrowingEndpointResponse } from "./endpoints/default/endpoint-response/GeneratedNonThrowingEndpointResponse";
import { GeneratedThrowingEndpointResponse } from "./endpoints/default/endpoint-response/GeneratedThrowingEndpointResponse";
import { getNonVariablePathParameters } from "./endpoints/utils/getNonVariablePathParameters";
import { getParameterNameForPathParameter } from "./endpoints/utils/getParameterNameForPathParameter";
import { getLiteralValueForHeader, isLiteralHeader } from "./endpoints/utils/isLiteralHeader";
import { GeneratedHeader } from "./GeneratedHeader";
import { GeneratedWrappedService } from "./GeneratedWrappedService";

export declare namespace GeneratedSdkClientClassImpl {
export interface Init {
Expand Down Expand Up @@ -483,24 +483,24 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
this.getReferenceToOption(this.getOptionKeyForAuthHeader(header))
)
})),
{
header: this.intermediateRepresentation.sdkConfig.platformHeaders.language,
value: ts.factory.createStringLiteral("JavaScript")
}
// {
// header: this.intermediateRepresentation.sdkConfig.platformHeaders.language,
// value: ts.factory.createStringLiteral("JavaScript")
// }
];

if (this.npmPackage != null) {
headers.push(
{
header: this.intermediateRepresentation.sdkConfig.platformHeaders.sdkName,
value: ts.factory.createStringLiteral(this.npmPackage.packageName)
},
{
header: this.intermediateRepresentation.sdkConfig.platformHeaders.sdkVersion,
value: ts.factory.createStringLiteral(this.npmPackage.version)
}
);
}
// if (this.npmPackage != null) {
// headers.push(
// {
// header: this.intermediateRepresentation.sdkConfig.platformHeaders.sdkName,
// value: ts.factory.createStringLiteral(this.npmPackage.packageName)
// },
// {
// header: this.intermediateRepresentation.sdkConfig.platformHeaders.sdkVersion,
// value: ts.factory.createStringLiteral(this.npmPackage.version)
// }
// );
// }

return headers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export abstract class AbstractGeneratorCli<CustomConfig> {
public async run(pathToConfig: string): Promise<void> {
const configStr = await readFile(pathToConfig);
const rawConfig = JSON.parse(configStr.toString());
// Fix weird bug
rawConfig.whitelabel = false;
const config = await GeneratorExecParsing.GeneratorConfig.parseOrThrow(
{
...rawConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function generateWorkspace({
version: string | undefined;
groupName: string | undefined;
shouldLogS3Url: boolean;
token: FernToken;
token?: FernToken;
useLocalDocker: boolean;
keepDocker: boolean;
}): Promise<void> {
Expand Down Expand Up @@ -64,6 +64,9 @@ export async function generateWorkspace({
context
});
} else {
if (!token) {
return context.failAndThrow("Must provide token if 'useLocalDocker' is false");
}
await runRemoteGenerationForAPIWorkspace({
workspace,
organization,
Expand Down
25 changes: 14 additions & 11 deletions packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createOrganizationIfDoesNotExist } from "@fern-api/auth";
import { createOrganizationIfDoesNotExist, FernToken, FernUserToken } from "@fern-api/auth";
import { askToLogin } from "@fern-api/login";
import { Project } from "@fern-api/project-loader";
import { convertOpenApiWorkspaceToFernWorkspace, FernWorkspace } from "@fern-api/workspace-loader";
Expand All @@ -22,18 +22,21 @@ export async function generateAPIWorkspaces({
useLocalDocker: boolean;
keepDocker: boolean;
}): Promise<void> {
const token = await cliContext.runTask(async (context) => {
return askToLogin(context);
});
let token: FernToken | undefined = undefined;
if (!useLocalDocker) {
token = await cliContext.runTask(async (context) => {
return askToLogin(context);
});

if (token.type === "user") {
await cliContext.runTask(async (context) => {
await createOrganizationIfDoesNotExist({
organization: project.config.organization,
token,
context
if (token.type === "user") {
await cliContext.runTask(async (context) => {
await createOrganizationIfDoesNotExist({
organization: project.config.organization,
token: token as FernUserToken,
context
});
});
});
}
}

cliContext.instrumentPostHogEvent({
Expand Down

0 comments on commit f176201

Please sign in to comment.