Skip to content

Commit

Permalink
Release 0.0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Jul 13, 2023
1 parent 28b4b8a commit ccc604f
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_modules
/dist
/Client.d.ts
/Client.js
/environments.d.ts
/environments.js
/index.d.ts
/index.js
/api
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tristansmp/amethyst",
"version": "0.0.24",
"version": "0.0.26",
"private": false,
"repository": "https://github.com/tristansmp/amethyst.js",
"main": "./index.js",
Expand All @@ -14,7 +14,8 @@
"url-join": "4.0.1",
"@types/url-join": "4.0.1",
"axios": "1.4.0",
"@ungap/url-search-params": "0.2.2"
"@ungap/url-search-params": "0.2.2",
"js-base64": "3.7.2"
},
"devDependencies": {
"@types/node": "17.0.33",
Expand Down
4 changes: 3 additions & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
* This file was auto-generated by Fern from our API Definition.
*/

import * as environments from "./environments";
import * as core from "./core";
import { Applications } from "./api/resources/applications/client/Client";

export declare namespace AmethystClient {
interface Options {
environment: core.Supplier<string>;
environment?: core.Supplier<environments.AmethystEnvironment | string>;
token?: core.Supplier<core.BearerToken | undefined>;
}
}

Expand Down
21 changes: 18 additions & 3 deletions src/api/resources/applications/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* This file was auto-generated by Fern from our API Definition.
*/

import * as environments from "../../../../environments";
import * as core from "../../../../core";
import * as Amethyst from "../../..";
import * as serializers from "../../../../serialization";
Expand All @@ -10,7 +11,8 @@ import * as errors from "../../../../errors";

export declare namespace Applications {
interface Options {
environment: core.Supplier<string>;
environment?: core.Supplier<environments.AmethystEnvironment | string>;
token?: core.Supplier<core.BearerToken | undefined>;
}
}

Expand All @@ -24,12 +26,16 @@ export class Applications {
request: Amethyst.ManageApplicationRequest
): Promise<Amethyst.ApplicationManageStatus> {
const _response = await core.fetcher({
url: urlJoin(await core.Supplier.get(this._options.environment), "/applications/manage-application"),
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.AmethystEnvironment.Production,
"/applications/manage-application"
),
method: "POST",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@tristansmp/amethyst",
"X-Fern-SDK-Version": "0.0.24",
"X-Fern-SDK-Version": "0.0.26",
},
contentType: "application/json",
body: await serializers.ManageApplicationRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -65,4 +71,13 @@ export class Applications {
});
}
}

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

return undefined;
}
}
31 changes: 31 additions & 0 deletions src/core/auth/BasicAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Base64 } from "js-base64";

export interface BasicAuth {
username: string;
password: string;
}

const BASIC_AUTH_HEADER_PREFIX = /^Basic /i;

export const BasicAuth = {
toAuthorizationHeader: (basicAuth: BasicAuth | undefined): string | undefined => {
if (basicAuth == null) {
return undefined;
}
const token = Base64.encode(`${basicAuth.username}:${basicAuth.password}`);
return `Basic ${token}`;
},
fromAuthorizationHeader: (header: string): BasicAuth => {
const credentials = header.replace(BASIC_AUTH_HEADER_PREFIX, "");
const decoded = Base64.decode(credentials);
const [username, password] = decoded.split(":", 2);

if (username == null || password == null) {
throw new Error("Invalid basic auth");
}
return {
username,
password,
};
},
};
15 changes: 15 additions & 0 deletions src/core/auth/BearerToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export type BearerToken = string;

const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;

export const BearerToken = {
toAuthorizationHeader: (token: BearerToken | undefined): string | undefined => {
if (token == null) {
return undefined;
}
return `Bearer ${token}`;
},
fromAuthorizationHeader: (header: string): BearerToken => {
return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim() as BearerToken;
},
};
2 changes: 2 additions & 0 deletions src/core/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { BasicAuth } from "./BasicAuth";
export { BearerToken } from "./BearerToken";
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * as serialization from "./schemas";
export * from "./fetcher";
export * from "./auth";
10 changes: 10 additions & 0 deletions src/environments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export const AmethystEnvironment = {
Production: "https://ame.tristansmp.com",
Development: "http://localhost:8080",
} as const;

export type AmethystEnvironment = typeof AmethystEnvironment.Production | typeof AmethystEnvironment.Development;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * as Amethyst from "./api";
export { AmethystClient } from "./Client";
export { AmethystEnvironment } from "./environments";
export { AmethystError, AmethystTimeoutError } from "./errors";
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

[email protected]:
version "3.7.2"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.2.tgz#816d11d81a8aff241603d19ce5761e13e41d7745"
integrity sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==

[email protected]:
version "1.52.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
Expand Down

0 comments on commit ccc604f

Please sign in to comment.