-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e84d3fd
Showing
136 changed files
with
3,206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Specify files that shouldn't be modified by Fern |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: ci | ||
|
||
on: [push] | ||
|
||
jobs: | ||
compile: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up node | ||
uses: actions/setup-node@v3 | ||
|
||
- name: Compile | ||
run: yarn && yarn build | ||
|
||
publish: | ||
needs: [ compile ] | ||
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up node | ||
uses: actions/setup-node@v3 | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Build | ||
run: yarn build | ||
|
||
- name: Publish to npm | ||
run: | | ||
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} | ||
npm publish --access public | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
node_modules | ||
.DS_Store | ||
/dist | ||
/Client.d.ts | ||
/Client.js | ||
/environments.d.ts | ||
/environments.js | ||
/index.d.ts | ||
/index.js | ||
/api | ||
/core | ||
/errors | ||
/serialization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules | ||
src | ||
.gitignore | ||
.github | ||
.fernignore | ||
.prettierrc.yml | ||
tsconfig.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tabWidth: 4 | ||
printWidth: 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@fern-api/node-sdk", | ||
"version": "0.0.1", | ||
"private": false, | ||
"repository": "https://github.com/fern-api/node-sdk", | ||
"main": "./index.js", | ||
"types": "./index.d.ts", | ||
"scripts": { | ||
"format": "prettier --write 'src/**/*.ts'", | ||
"build": "tsc", | ||
"prepack": "cp -rv dist/. ." | ||
}, | ||
"dependencies": { | ||
"url-join": "4.0.1", | ||
"@types/url-join": "4.0.1", | ||
"@ungap/url-search-params": "0.2.2", | ||
"axios": "0.27.2", | ||
"js-base64": "3.7.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "17.0.33", | ||
"prettier": "2.7.1", | ||
"typescript": "4.6.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as environments from "./environments"; | ||
import * as core from "./core"; | ||
import { Snippets } from "./api/resources/snippets/client/Client"; | ||
|
||
export declare namespace FernClient { | ||
interface Options { | ||
environment?: core.Supplier<environments.FernEnvironment | string>; | ||
token: core.Supplier<core.BearerToken>; | ||
} | ||
|
||
interface RequestOptions { | ||
timeoutInSeconds?: number; | ||
} | ||
} | ||
|
||
export class FernClient { | ||
constructor(protected readonly _options: FernClient.Options) {} | ||
|
||
protected _snippets: Snippets | undefined; | ||
|
||
public get snippets(): Snippets { | ||
return (this._snippets ??= new Snippets(this._options)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./resources"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as snippets from "./snippets"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as environments from "../../../../environments"; | ||
import * as core from "../../../../core"; | ||
import * as Fern from "../../.."; | ||
import * as serializers from "../../../../serialization"; | ||
import urlJoin from "url-join"; | ||
import * as errors from "../../../../errors"; | ||
import { default as URLSearchParams } from "@ungap/url-search-params"; | ||
|
||
export declare namespace Snippets { | ||
interface Options { | ||
environment?: core.Supplier<environments.FernEnvironment | string>; | ||
token: core.Supplier<core.BearerToken>; | ||
} | ||
|
||
interface RequestOptions { | ||
timeoutInSeconds?: number; | ||
} | ||
} | ||
|
||
export class Snippets { | ||
constructor(protected readonly _options: Snippets.Options) {} | ||
|
||
/** | ||
* Get snippet by endpoint method and path | ||
* @throws {@link Fern.snippets.EndpointNotFound} | ||
* @throws {@link Fern.snippets.SdkNotFound} | ||
* @throws {@link Fern.snippets.ApiIdNotFound} | ||
*/ | ||
public async get( | ||
request: Fern.snippets.GetSnippetRequest, | ||
requestOptions?: Snippets.RequestOptions | ||
): Promise<Fern.snippets.Snippet[]> { | ||
const _response = await core.fetcher({ | ||
url: urlJoin( | ||
(await core.Supplier.get(this._options.environment)) ?? environments.FernEnvironment.Production, | ||
"/snippets" | ||
), | ||
method: "POST", | ||
headers: { | ||
Authorization: await this._getAuthorizationHeader(), | ||
"X-Fern-Language": "JavaScript", | ||
"X-Fern-SDK-Name": "@fern-api/node-sdk", | ||
"X-Fern-SDK-Version": "0.0.1", | ||
}, | ||
contentType: "application/json", | ||
body: await serializers.snippets.GetSnippetRequest.jsonOrThrow(request, { | ||
unrecognizedObjectKeys: "strip", | ||
}), | ||
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, | ||
}); | ||
if (_response.ok) { | ||
return await serializers.snippets.get.Response.parseOrThrow(_response.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}); | ||
} | ||
|
||
if (_response.error.reason === "status-code") { | ||
switch ((_response.error.body as any)?.["error"]) { | ||
case "EndpointNotFound": | ||
throw new Fern.snippets.EndpointNotFound(); | ||
case "SDKNotFound": | ||
throw new Fern.snippets.SdkNotFound(); | ||
case "ApiIdNotFound": | ||
throw new Fern.snippets.ApiIdNotFound(); | ||
default: | ||
throw new errors.FernError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.body, | ||
}); | ||
} | ||
} | ||
|
||
switch (_response.error.reason) { | ||
case "non-json": | ||
throw new errors.FernError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.rawBody, | ||
}); | ||
case "timeout": | ||
throw new errors.FernTimeoutError(); | ||
case "unknown": | ||
throw new errors.FernError({ | ||
message: _response.error.errorMessage, | ||
}); | ||
} | ||
} | ||
|
||
public async load( | ||
request: Fern.snippets.ListSnippetsRequest = {}, | ||
requestOptions?: Snippets.RequestOptions | ||
): Promise<Fern.snippets.SnippetsPage> { | ||
const { page, ..._body } = request; | ||
const _queryParams = new URLSearchParams(); | ||
if (page != null) { | ||
_queryParams.append("page", page.toString()); | ||
} | ||
|
||
const _response = await core.fetcher({ | ||
url: urlJoin( | ||
(await core.Supplier.get(this._options.environment)) ?? environments.FernEnvironment.Production, | ||
"/snippets/load" | ||
), | ||
method: "POST", | ||
headers: { | ||
Authorization: await this._getAuthorizationHeader(), | ||
"X-Fern-Language": "JavaScript", | ||
"X-Fern-SDK-Name": "@fern-api/node-sdk", | ||
"X-Fern-SDK-Version": "0.0.1", | ||
}, | ||
contentType: "application/json", | ||
queryParameters: _queryParams, | ||
body: await serializers.snippets.ListSnippetsRequest.jsonOrThrow(_body, { | ||
unrecognizedObjectKeys: "strip", | ||
}), | ||
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, | ||
}); | ||
if (_response.ok) { | ||
return await serializers.snippets.SnippetsPage.parseOrThrow(_response.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}); | ||
} | ||
|
||
if (_response.error.reason === "status-code") { | ||
throw new errors.FernError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.body, | ||
}); | ||
} | ||
|
||
switch (_response.error.reason) { | ||
case "non-json": | ||
throw new errors.FernError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.rawBody, | ||
}); | ||
case "timeout": | ||
throw new errors.FernTimeoutError(); | ||
case "unknown": | ||
throw new errors.FernError({ | ||
message: _response.error.errorMessage, | ||
}); | ||
} | ||
} | ||
|
||
protected async _getAuthorizationHeader() { | ||
return `Bearer ${await core.Supplier.get(this._options.token)}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./requests"; |
20 changes: 20 additions & 0 deletions
20
src/api/resources/snippets/client/requests/GetSnippetRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as Fern from "../../../.."; | ||
|
||
export interface GetSnippetRequest { | ||
/** | ||
* If you have more than one API, you must specify its ID. | ||
* | ||
*/ | ||
apiId?: Fern.snippets.ApiId; | ||
/** | ||
* The SDKs for which to load snippets. If unspecified, | ||
* snippets for the latest published SDKs will be returned. | ||
* | ||
*/ | ||
sdks?: Fern.snippets.Sdk[]; | ||
endpoint: Fern.snippets.EndpointIdentifier; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/api/resources/snippets/client/requests/ListSnippetsRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as Fern from "../../../.."; | ||
|
||
export interface ListSnippetsRequest { | ||
page?: number; | ||
/** | ||
* If you have more than one API, you must specify its ID. | ||
* | ||
*/ | ||
apiId?: Fern.snippets.ApiId; | ||
/** | ||
* The SDKs for which to load snippets. If unspecified, | ||
* snippets for the latest published SDKs will be returned. | ||
* | ||
*/ | ||
sdks?: Fern.snippets.Sdk[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { GetSnippetRequest } from "./GetSnippetRequest"; | ||
export { ListSnippetsRequest } from "./ListSnippetsRequest"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../../../errors"; | ||
|
||
export class ApiIdNotFound extends errors.FernError { | ||
constructor() { | ||
super({ | ||
statusCode: 404, | ||
}); | ||
Object.setPrototypeOf(this, ApiIdNotFound.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../../../errors"; | ||
|
||
export class EndpointNotFound extends errors.FernError { | ||
constructor() { | ||
super({ | ||
statusCode: 404, | ||
}); | ||
Object.setPrototypeOf(this, EndpointNotFound.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../../../errors"; | ||
|
||
export class SdkNotFound extends errors.FernError { | ||
constructor() { | ||
super({ | ||
statusCode: 404, | ||
}); | ||
Object.setPrototypeOf(this, SdkNotFound.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./EndpointNotFound"; | ||
export * from "./SdkNotFound"; | ||
export * from "./ApiIdNotFound"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./types"; | ||
export * from "./resources"; | ||
export * from "./errors"; | ||
export * from "./client"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./types"; |
Oops, something went wrong.