Skip to content

Commit

Permalink
Release 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Oct 2, 2023
0 parents commit e84d3fd
Show file tree
Hide file tree
Showing 136 changed files with 3,206 additions and 0 deletions.
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Specify files that shouldn't be modified by Fern
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
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 }}
13 changes: 13 additions & 0 deletions .gitignore
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
8 changes: 8 additions & 0 deletions .npmignore
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
2 changes: 2 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tabWidth: 4
printWidth: 120
25 changes: 25 additions & 0 deletions package.json
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"
}
}
28 changes: 28 additions & 0 deletions src/Client.ts
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));
}
}
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./resources";
1 change: 1 addition & 0 deletions src/api/resources/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as snippets from "./snippets";
158 changes: 158 additions & 0 deletions src/api/resources/snippets/client/Client.ts
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)}`;
}
}
1 change: 1 addition & 0 deletions src/api/resources/snippets/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./requests";
20 changes: 20 additions & 0 deletions src/api/resources/snippets/client/requests/GetSnippetRequest.ts
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 src/api/resources/snippets/client/requests/ListSnippetsRequest.ts
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[];
}
2 changes: 2 additions & 0 deletions src/api/resources/snippets/client/requests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { GetSnippetRequest } from "./GetSnippetRequest";
export { ListSnippetsRequest } from "./ListSnippetsRequest";
14 changes: 14 additions & 0 deletions src/api/resources/snippets/errors/ApiIdNotFound.ts
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);
}
}
14 changes: 14 additions & 0 deletions src/api/resources/snippets/errors/EndpointNotFound.ts
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);
}
}
14 changes: 14 additions & 0 deletions src/api/resources/snippets/errors/SdkNotFound.ts
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);
}
}
3 changes: 3 additions & 0 deletions src/api/resources/snippets/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./EndpointNotFound";
export * from "./SdkNotFound";
export * from "./ApiIdNotFound";
4 changes: 4 additions & 0 deletions src/api/resources/snippets/index.ts
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";
1 change: 1 addition & 0 deletions src/api/resources/snippets/resources/commons/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./types";
Loading

0 comments on commit e84d3fd

Please sign in to comment.