Skip to content

Commit

Permalink
chore: make cjs compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Oct 17, 2024
1 parent 8bd03f2 commit 68802b9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 252 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@fern-fern:registry=https://npm.buildwithfern.com/
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fern-api/sdk",
"version": "0.13.0-beta0",
"version": "0.13.0-beta1",
"private": false,
"repository": "https://github.com/fern-api/typescript-sdk",
"license": "MIT",
Expand All @@ -19,7 +19,7 @@
"node-fetch": "2.7.0",
"qs": "6.11.2",
"js-base64": "3.7.2",
"@fern-api/template-resolver": "0.8.1"
"@fern-api/template-resolver": "0.8.2",
},
"devDependencies": {
"@types/url-join": "4.0.1",
Expand Down
34 changes: 23 additions & 11 deletions src/wrapper/Template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fern } from "../index";
import { SnippetTemplateResolver } from "@fern-api/template-resolver";
import { FdrClient, FdrAPI } from "@fern-api/fdr-sdk";
import { FernRegistry, FernRegistryClient } from "@fern-fern/fdr-cjs-sdk";

export class Template implements Fern.templates.EndpointSnippetTemplate {
private endpointSnippetTemplate: Fern.EndpointSnippetTemplate;
Expand All @@ -22,14 +22,20 @@ export class Template implements Fern.templates.EndpointSnippetTemplate {
const _innerResolver = new SnippetTemplateResolver({
payload: {
...payload,
headers: payload.headers?.map((header): FdrAPI.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
pathParameters: payload.pathParameters?.map((header): FdrAPI.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
queryParameters: payload.queryParameters?.map((header): FdrAPI.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
headers: payload.headers?.map((header): FernRegistry.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
pathParameters: payload.pathParameters?.map((header): FernRegistry.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
queryParameters: payload.queryParameters?.map((header): FernRegistry.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
requestBody: payload.requestBody ?? undefined,
auth: payload.auth ?? undefined,
},
endpointSnippetTemplate: this.endpointSnippetTemplate as FdrAPI.EndpointSnippetTemplate,
provideFdrClient: () => new FdrClient(),
endpointSnippetTemplate: this.endpointSnippetTemplate as FernRegistry.EndpointSnippetTemplate,
apiDefinitionGetter: async (id) => {
const response = await new FernRegistryClient().api.v1.read.getApi(FernRegistry.ApiDefinitionId(id));
if (response.ok) {
return response.body;
}
throw new Error(JSON.stringify(response.error));
},
});

return _innerResolver.resolve();
Expand All @@ -45,14 +51,20 @@ export class Template implements Fern.templates.EndpointSnippetTemplate {
const _innerResolver = new SnippetTemplateResolver({
payload: {
...payload,
headers: payload.headers?.map((header): FdrAPI.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
pathParameters: payload.pathParameters?.map((header): FdrAPI.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
queryParameters: payload.queryParameters?.map((header): FdrAPI.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
headers: payload.headers?.map((header): FernRegistry.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
pathParameters: payload.pathParameters?.map((header): FernRegistry.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
queryParameters: payload.queryParameters?.map((header): FernRegistry.ParameterPayload => { return { name: header.name, value: header.value ?? undefined } }),
requestBody: payload.requestBody ?? undefined,
auth: payload.auth ?? undefined,
},
endpointSnippetTemplate: this.endpointSnippetTemplate as FdrAPI.EndpointSnippetTemplate,
provideFdrClient: () => new FdrClient(),
endpointSnippetTemplate: this.endpointSnippetTemplate as FernRegistry.EndpointSnippetTemplate,
apiDefinitionGetter: async (id) => {
const response = await new FernRegistryClient().api.v1.read.getApi(FernRegistry.ApiDefinitionId(id));
if (response.ok) {
return response.body;
}
throw new Error(JSON.stringify(response.error));
},
});

return await _innerResolver.resolveWithFormatting();
Expand Down
Loading

0 comments on commit 68802b9

Please sign in to comment.