Skip to content

Commit

Permalink
chore: move template resolver to it's own package (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo authored Apr 28, 2024
1 parent 48c76ed commit 4d3c30d
Show file tree
Hide file tree
Showing 210 changed files with 2,319 additions and 386 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/publish-template-resolver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Template Resolver Package

on:
push: {}
release:
types:
- published

env:
PACKAGE_NAME: "@fern-api/template-resolver"
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: "buildwithfern"
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
GITHUB_TOKEN: ${{ secrets.FERN_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.FERN_NPM_TOKEN }}

jobs:
publish_package:
if: github.event_name == 'release' && startsWith(github.event.release.tag_name, 'python@')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: 📥 Install
uses: ./.github/actions/install

- name: 🧪 Build and test
run: pnpm turbo codegen build test --filter=${{ env.PACKAGE_NAME }}

- name: Publish Template Resolver Package
env:
NPM_TOKEN: ${{ secrets.FERN_NPM_TOKEN }}
# Currently follows the same version as FDR, which is probably fine for now
run: |
tag=${{ github.event.release.tag_name }}
prefix="template-resolver@"
VERSION="${tag#$prefix}"
cd packages/template-resolver
mv package.json package.json.tmp
version_replace="s/0.0.0/${VERSION}/"
cat package.json.tmp| sed "${version_replace}" > package.json
rm -rf package.json.tmp
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
npm publish --access public
2 changes: 1 addition & 1 deletion fern/apis/fdr/definition/snippets-factory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

imports:
commons: commons.yml
snippets: __package__.yml
snippets: snippets.yml

service:
auth: true
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
imports:
commons: commons.yml
snippets: __package__.yml
snippets: snippets.yml

service:
auth: true
Expand Down
41 changes: 22 additions & 19 deletions fern/apis/fdr/generators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,11 @@ groups:
extraDevDependencies:
"@types/mime": "3.0.4"

fdr-test:
generators:
- name: fernapi/fern-typescript-node-sdk
version: 0.12.8-rc0
output:
location: npm
url: npm.buildwithfern.com
package-name: "@fern-fern/fdr-test-sdk"
config:
noSerdeLayer: true
outputSourceFiles: true
neverThrowErrors: true
timeoutInSeconds: infinity
outputEsm: true
extraDevDependencies:
"@types/mime": "3.0.4"

sdk-generators:
internal-snippets-sdks:
audiences:
- snippets
generators:
# Internal, unadulterated for the use of the APIs
- name: fernapi/fern-python-sdk
version: 1.2.0-rc1
output:
Expand All @@ -65,11 +49,30 @@ groups:
output:
location: npm
url: npm.buildwithfern.com
package-name: "@fern-fern/snippet-template-sdk"
package-name: "@fern-fern/snippet-sdk"
config:
namespaceExport: FdrSnippetTemplate
includeUtilsOnUnionMembers: true

external-sdks:
audiences:
- external
- snippets
generators:
- name: fernapi/fern-typescript-node-sdk
version: 0.12.8-rc0
output:
location: npm
package-name: "@fern/typescript-sdk"
# token: ${NPM_TOKEN}
github:
repository: fern-api/fern-typescript
mode: pull-request
license: MIT
config:
namespaceExport: Fern
includeApiReference: true

fiddle:
audiences:
- fiddle
Expand Down
142 changes: 8 additions & 134 deletions packages/fdr-sdk/src/client/generated/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

import * as environments from "./environments";
import * as core from "./core";
import * as FernRegistry from "./api";
import urlJoin from "url-join";
import { Api } from "./api/resources/api/client/Client";
import { Docs } from "./api/resources/docs/client/Client";
import { SnippetsFactory } from "./api/resources/snippetsFactory/client/Client";
import { Template } from "./api/resources/template/client/Client";
import { Snippets } from "./api/resources/snippets/client/Client";
import { Templates } from "./api/resources/templates/client/Client";

export declare namespace FernRegistryClient {
interface Options {
Expand All @@ -26,128 +25,6 @@ export declare namespace FernRegistryClient {
export class FernRegistryClient {
constructor(protected readonly _options: FernRegistryClient.Options = {}) {}

/**
* Get snippet by endpoint method and path
*
* @example
* await fernRegistry.get({
* endpoint: {
* method: FernRegistry.EndpointMethod.Get,
* path: "/v1/search"
* }
* })
*/
public async get(
request: FernRegistry.GetSnippetRequest,
requestOptions?: FernRegistryClient.RequestOptions
): Promise<core.APIResponse<FernRegistry.Snippet[], FernRegistry.get.Error>> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.FernRegistryEnvironment.Dev,
"/snippets"
),
method: "POST",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : undefined,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return {
ok: true,
body: _response.body as FernRegistry.Snippet[],
};
}

if (_response.error.reason === "status-code") {
switch ((_response.error.body as FernRegistry.get.Error)?.error) {
case "UnauthorizedError":
case "UserNotInOrgError":
case "UnavailableError":
case "ApiIdRequiredError":
case "OrgIdRequiredError":
case "OrgIdAndApiIdNotFound":
case "OrgIdNotFound":
case "EndpointNotFound":
case "SDKNotFound":
return {
ok: false,
error: _response.error.body as FernRegistry.get.Error,
};
}
}

return {
ok: false,
error: FernRegistry.get.Error._unknown(_response.error),
};
}

public async load(
request: FernRegistry.ListSnippetsRequest = {},
requestOptions?: FernRegistryClient.RequestOptions
): Promise<core.APIResponse<FernRegistry.SnippetsPage, FernRegistry.load.Error>> {
const { page, ..._body } = request;
const _queryParams: Record<string, string | string[] | object | object[]> = {};
if (page != null) {
_queryParams["page"] = page.toString();
}

const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.FernRegistryEnvironment.Dev,
"/snippets/load"
),
method: "POST",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
queryParameters: _queryParams,
body: _body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : undefined,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return {
ok: true,
body: _response.body as FernRegistry.SnippetsPage,
};
}

if (_response.error.reason === "status-code") {
switch ((_response.error.body as FernRegistry.load.Error)?.error) {
case "UnauthorizedError":
case "UserNotInOrgError":
case "UnavailableError":
case "InvalidPageError":
case "ApiIdRequiredError":
case "OrgIdRequiredError":
case "OrgIdAndApiIdNotFound":
case "OrgIdNotFound":
case "SDKNotFound":
return {
ok: false,
error: _response.error.body as FernRegistry.load.Error,
};
}
}

return {
ok: false,
error: FernRegistry.load.Error._unknown(_response.error),
};
}

protected _api: Api | undefined;

public get api(): Api {
Expand All @@ -166,18 +43,15 @@ export class FernRegistryClient {
return (this._snippetsFactory ??= new SnippetsFactory(this._options));
}

protected _template: Template | undefined;
protected _snippets: Snippets | undefined;

public get template(): Template {
return (this._template ??= new Template(this._options));
public get snippets(): Snippets {
return (this._snippets ??= new Snippets(this._options));
}

protected async _getAuthorizationHeader() {
const bearer = await core.Supplier.get(this._options.token);
if (bearer != null) {
return `Bearer ${bearer}`;
}
protected _templates: Templates | undefined;

return undefined;
public get templates(): Templates {
return (this._templates ??= new Templates(this._options));
}
}
2 changes: 0 additions & 2 deletions packages/fdr-sdk/src/client/generated/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from "./types";
export * from "./resources";
export * from "./client";
9 changes: 6 additions & 3 deletions packages/fdr-sdk/src/client/generated/api/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export * as commons from "./commons";
export * from "./commons/types";
export * as snippetsFactory from "./snippetsFactory";
export * from "./snippetsFactory/types";
export * as template from "./template";
export * from "./template/types";
export * as snippets from "./snippets";
export * from "./snippets/types";
export * as templates from "./templates";
export * from "./templates/types";
export * from "./snippetsFactory/client/requests";
export * from "./template/client/requests";
export * from "./snippets/client/requests";
export * from "./templates/client/requests";
Loading

0 comments on commit 4d3c30d

Please sign in to comment.