Skip to content

Commit

Permalink
Merge pull request #421 from HubSpot/feature/marketingForms
Browse files Browse the repository at this point in the history
Marketing forms
  • Loading branch information
ksvirkou-hubspot authored Nov 16, 2023
2 parents ff225d3 + 2690059 commit 5fe5b10
Show file tree
Hide file tree
Showing 65 changed files with 6,581 additions and 0 deletions.
541 changes: 541 additions & 0 deletions codegen/marketing/forms/apis/FormsApi.ts

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions codegen/marketing/forms/apis/baseapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Configuration } from '../configuration'

/**
*
* @export
*/
export const COLLECTION_FORMATS = {
csv: ",",
ssv: " ",
tsv: "\t",
pipes: "|",
};


/**
*
* @export
* @class BaseAPI
*/
export class BaseAPIRequestFactory {

constructor(protected configuration: Configuration) {
}
};

/**
*
* @export
* @class RequiredError
* @extends {Error}
*/
export class RequiredError extends Error {
name: "RequiredError" = "RequiredError";
constructor(public api: string, public method: string, public field: string) {
super("Required parameter " + field + " was null or undefined when calling " + api + "." + method + ".");
}
}
15 changes: 15 additions & 0 deletions codegen/marketing/forms/apis/exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Represents an error caused by an api call i.e. it has attributes for a HTTP status code
* and the returned body object.
*
* Example
* API returns a ErrorMessageObject whenever HTTP status code is not in [200, 299]
* => ApiException(404, someErrorMessageObject)
*
*/
export class ApiException<T> extends Error {
public constructor(public code: number, message: string, public body: T, public headers: { [key: string]: string; }) {
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body) + "\nHeaders: " +
JSON.stringify(headers))
}
}
79 changes: 79 additions & 0 deletions codegen/marketing/forms/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { RequestContext } from "../http/http";

/**
* Interface authentication schemes.
*/
export interface SecurityAuthentication {
/*
* @return returns the name of the security authentication as specified in OAI
*/
getName(): string;

/**
* Applies the authentication scheme to the request context
*
* @params context the request context which should use this authentication scheme
*/
applySecurityAuthentication(context: RequestContext): void | Promise<void>;
}

export interface TokenProvider {
getToken(): Promise<string> | string;
}

/**
* Applies oauth2 authentication to the request context.
*/
export class Oauth2Authentication implements SecurityAuthentication {
/**
* Configures OAuth2 with the necessary properties
*
* @param accessToken: The access token to be used for every request
*/
public constructor(private accessToken: string) {}

public getName(): string {
return "oauth2";
}

public applySecurityAuthentication(context: RequestContext) {
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
}
}


export type AuthMethods = {
"default"?: SecurityAuthentication,
"oauth2"?: SecurityAuthentication
}

export type ApiKeyConfiguration = string;
export type HttpBasicConfiguration = { "username": string, "password": string };
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
export type OAuth2Configuration = { accessToken: string };

export type AuthMethodsConfiguration = {
"default"?: SecurityAuthentication,
"oauth2"?: OAuth2Configuration
}

/**
* Creates the authentication methods from a swagger description.
*
*/
export function configureAuthMethods(config: AuthMethodsConfiguration | undefined): AuthMethods {
let authMethods: AuthMethods = {}

if (!config) {
return authMethods;
}
authMethods["default"] = config["default"]

if (config["oauth2"]) {
authMethods["oauth2"] = new Oauth2Authentication(
config["oauth2"]["accessToken"]
);
}

return authMethods;
}
82 changes: 82 additions & 0 deletions codegen/marketing/forms/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { HttpLibrary } from "./http/http";
import { Middleware, PromiseMiddleware, PromiseMiddlewareWrapper } from "./middleware";
import { IsomorphicFetchHttpLibrary as DefaultHttpLibrary } from "./http/isomorphic-fetch";
import { BaseServerConfiguration, server1 } from "./servers";
import { configureAuthMethods, AuthMethods, AuthMethodsConfiguration } from "./auth/auth";

export interface Configuration {
readonly baseServer: BaseServerConfiguration;
readonly httpApi: HttpLibrary;
readonly middleware: Middleware[];
readonly authMethods: AuthMethods;
}


/**
* Interface with which a configuration object can be configured.
*/
export interface ConfigurationParameters {
/**
* Default server to use - a list of available servers (according to the
* OpenAPI yaml definition) is included in the `servers` const in `./servers`. You can also
* create your own server with the `ServerConfiguration` class from the same
* file.
*/
baseServer?: BaseServerConfiguration;
/**
* HTTP library to use e.g. IsomorphicFetch. This can usually be skipped as
* all generators come with a default library.
* If available, additional libraries can be imported from `./http/*`
*/
httpApi?: HttpLibrary;

/**
* The middlewares which will be applied to requests and responses. You can
* add any number of middleware components to modify requests before they
* are sent or before they are deserialized by implementing the `Middleware`
* interface defined in `./middleware`
*/
middleware?: Middleware[];
/**
* Configures middleware functions that return promises instead of
* Observables (which are used by `middleware`). Otherwise allows for the
* same functionality as `middleware`, i.e., modifying requests before they
* are sent and before they are deserialized.
*/
promiseMiddleware?: PromiseMiddleware[];
/**
* Configuration for the available authentication methods (e.g., api keys)
* according to the OpenAPI yaml definition. For the definition, please refer to
* `./auth/auth`
*/
authMethods?: AuthMethodsConfiguration
}

/**
* Provide your `ConfigurationParameters` to this function to get a `Configuration`
* object that can be used to configure your APIs (in the constructor or
* for each request individually).
*
* If a property is not included in conf, a default is used:
* - baseServer: server1
* - httpApi: IsomorphicFetchHttpLibrary
* - middleware: []
* - promiseMiddleware: []
* - authMethods: {}
*
* @param conf partial configuration
*/
export function createConfiguration(conf: ConfigurationParameters = {}): Configuration {
const configuration: Configuration = {
baseServer: conf.baseServer !== undefined ? conf.baseServer : server1,
httpApi: conf.httpApi || new DefaultHttpLibrary(),
middleware: conf.middleware || [],
authMethods: configureAuthMethods(conf.authMethods)
};
if (conf.promiseMiddleware) {
conf.promiseMiddleware.forEach(
m => configuration.middleware.push(new PromiseMiddlewareWrapper(m))
);
}
return configuration;
}
Loading

0 comments on commit 5fe5b10

Please sign in to comment.