Skip to content

Commit

Permalink
Release v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Jul 8, 2023
1 parent 2cb4c28 commit dfcf550
Show file tree
Hide file tree
Showing 413 changed files with 6,240 additions and 4,078 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "@mercoa/javascript",
"version": "v0.1.1",
"version": "v0.2.0",
"private": false,
"repository": "https://github.com/mercoa-finance/javascript",
"main": "./index.js",
"types": "./index.d.ts",
"scripts": {
"format": "prettier --write 'src/**/*.ts'",
"build": "tsc && tsc-alias",
"build": "tsc",
"prepack": "cp -rv dist/. ."
},
"dependencies": {
"@ungap/url-search-params": "0.2.2",
"url-join": "4.0.1",
"@types/url-join": "4.0.1",
"js-base64": "3.7.2",
"axios": "0.27.2"
"axios": "1.4.0",
"js-base64": "3.7.2"
},
"devDependencies": {
"@types/node": "17.0.33",
"prettier": "2.7.1",
"tsc-alias": "1.7.1",
"typescript": "4.6.4"
}
}
75 changes: 20 additions & 55 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,98 +4,63 @@

import * as environments from "./environments";
import * as core from "./core";
import { BankLookup } from "./api/resources/bankLookup/client/Client";
import { Counterparty } from "./api/resources/counterparty/client/Client";
import { EntityUsers } from "./api/resources/entityUsers/client/Client";
import { Entity } from "./api/resources/entity/client/Client";
import { Invoice } from "./api/resources/invoice/client/Client";
import { BankLookup } from "./api/resources/bankLookup/client/Client";
import { Ocr } from "./api/resources/ocr/client/Client";
import { Organization } from "./api/resources/organization/client/Client";
import { PaymentMethodSchema } from "./api/resources/paymentMethodSchema/client/Client";
import { PaymentMethod } from "./api/resources/paymentMethod/client/Client";
import { ProcessInvoice } from "./api/resources/processInvoice/client/Client";
import { Representative } from "./api/resources/representative/client/Client";
import { Transaction } from "./api/resources/transaction/client/Client";

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

export class MercoaClient {
constructor(private readonly options: MercoaClient.Options) {}

private _bankLookup: BankLookup | undefined;

public get bankLookup(): BankLookup {
return (this._bankLookup ??= new BankLookup(this.options));
}
constructor(protected readonly _options: MercoaClient.Options) {}

private _counterparty: Counterparty | undefined;
protected _entity: Entity | undefined;

public get counterparty(): Counterparty {
return (this._counterparty ??= new Counterparty(this.options));
}

private _entityUsers: EntityUsers | undefined;

public get entityUsers(): EntityUsers {
return (this._entityUsers ??= new EntityUsers(this.options));
public get entity(): Entity {
return (this._entity ??= new Entity(this._options));
}

private _entity: Entity | undefined;
protected _invoice: Invoice | undefined;

public get entity(): Entity {
return (this._entity ??= new Entity(this.options));
public get invoice(): Invoice {
return (this._invoice ??= new Invoice(this._options));
}

private _invoice: Invoice | undefined;
protected _bankLookup: BankLookup | undefined;

public get invoice(): Invoice {
return (this._invoice ??= new Invoice(this.options));
public get bankLookup(): BankLookup {
return (this._bankLookup ??= new BankLookup(this._options));
}

private _ocr: Ocr | undefined;
protected _ocr: Ocr | undefined;

public get ocr(): Ocr {
return (this._ocr ??= new Ocr(this.options));
return (this._ocr ??= new Ocr(this._options));
}

private _organization: Organization | undefined;
protected _organization: Organization | undefined;

public get organization(): Organization {
return (this._organization ??= new Organization(this.options));
return (this._organization ??= new Organization(this._options));
}

private _paymentMethodSchema: PaymentMethodSchema | undefined;
protected _paymentMethodSchema: PaymentMethodSchema | undefined;

public get paymentMethodSchema(): PaymentMethodSchema {
return (this._paymentMethodSchema ??= new PaymentMethodSchema(this.options));
}

private _paymentMethod: PaymentMethod | undefined;

public get paymentMethod(): PaymentMethod {
return (this._paymentMethod ??= new PaymentMethod(this.options));
}

private _processInvoice: ProcessInvoice | undefined;

public get processInvoice(): ProcessInvoice {
return (this._processInvoice ??= new ProcessInvoice(this.options));
}

private _representative: Representative | undefined;

public get representative(): Representative {
return (this._representative ??= new Representative(this.options));
return (this._paymentMethodSchema ??= new PaymentMethodSchema(this._options));
}

private _transaction: Transaction | undefined;
protected _transaction: Transaction | undefined;

public get transaction(): Transaction {
return (this._transaction ??= new Transaction(this.options));
return (this._transaction ??= new Transaction(this._options));
}
}
60 changes: 45 additions & 15 deletions src/api/resources/bankLookup/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,85 @@

import * as environments from "../../../../environments";
import * as core from "../../../../core";
import { Mercoa } from "@mercoa/javascript";
import * as Mercoa from "../../..";
import { default as URLSearchParams } from "@ungap/url-search-params";
import urlJoin from "url-join";
import * as serializers from "../../../../serialization";
import * as errors from "../../../../errors";

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

export class BankLookup {
constructor(private readonly options: BankLookup.Options) {}
constructor(protected readonly _options: BankLookup.Options) {}

/**
* Find bank account details
* @throws {@link Mercoa.AuthHeaderMissingError}
* @throws {@link Mercoa.AuthHeaderMalformedError}
* @throws {@link Mercoa.Unauthorized}
*/
public async find(request: Mercoa.BankLookupRequest): Promise<Mercoa.BankLookupResponse> {
const { routingNumber } = request;
const _queryParams = new URLSearchParams();
_queryParams.append("routingNumber", routingNumber);
const _response = await core.fetcher({
url: urlJoin(this.options.environment ?? environments.MercoaEnvironment.Production, "/bankLookup"),
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.MercoaEnvironment.Production,
"/bankLookup"
),
method: "GET",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@mercoa/javascript",
"X-Fern-SDK-Version": "v0.2.0",
},
contentType: "application/json",
queryParameters: _queryParams,
timeoutMs: 60000,
});
if (_response.ok) {
return await serializers.BankLookupResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
throw new errors.MercoaError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
switch ((_response.error.body as any)?.["errorName"]) {
case "AuthHeaderMissingError":
throw new Mercoa.AuthHeaderMissingError();
case "AuthHeaderMalformedError":
throw new Mercoa.AuthHeaderMalformedError(
await serializers.AuthHeaderMalformedError.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "Unauthorized":
throw new Mercoa.Unauthorized(
await serializers.Unauthorized.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
default:
throw new errors.MercoaError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}

switch (_response.error.reason) {
Expand All @@ -65,12 +100,7 @@ export class BankLookup {
}
}

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

return undefined;
protected async _getAuthorizationHeader() {
return `Bearer ${await core.Supplier.get(this._options.token)}`;
}
}
2 changes: 1 addition & 1 deletion src/api/resources/bankLookup/types/BankLookupResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file was auto-generated by Fern from our API Definition.
*/

import { Mercoa } from "@mercoa/javascript";
import * as Mercoa from "../../..";

export interface BankLookupResponse {
bankName: string;
Expand Down
15 changes: 15 additions & 0 deletions src/api/resources/commons/errors/AuthHeaderMalformedError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as errors from "../../../../errors";

export class AuthHeaderMalformedError extends errors.MercoaError {
constructor(body: string) {
super({
statusCode: 400,
body: body,
});
Object.setPrototypeOf(this, AuthHeaderMalformedError.prototype);
}
}
14 changes: 14 additions & 0 deletions src/api/resources/commons/errors/AuthHeaderMissingError.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 AuthHeaderMissingError extends errors.MercoaError {
constructor() {
super({
statusCode: 400,
});
Object.setPrototypeOf(this, AuthHeaderMissingError.prototype);
}
}
15 changes: 15 additions & 0 deletions src/api/resources/commons/errors/Unauthorized.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as errors from "../../../../errors";

export class Unauthorized extends errors.MercoaError {
constructor(body: string) {
super({
statusCode: 401,
body: body,
});
Object.setPrototypeOf(this, Unauthorized.prototype);
}
}
15 changes: 0 additions & 15 deletions src/api/resources/commons/errors/UnauthorizedError.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/api/resources/commons/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from "./UnauthorizedError";
export * from "./AuthHeaderMissingError";
export * from "./AuthHeaderMalformedError";
export * from "./Unauthorized";
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* This file was auto-generated by Fern from our API Definition.
*/

export type BankAccountId = string;
export type ApprovalPolicyId = string;
File renamed without changes.
2 changes: 1 addition & 1 deletion src/api/resources/commons/types/IndividualGovernmentId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file was auto-generated by Fern from our API Definition.
*/

import { Mercoa } from "@mercoa/javascript";
import * as Mercoa from "../../..";

export interface IndividualGovernmentId {
ssn?: Mercoa.Ssn;
Expand Down
7 changes: 7 additions & 0 deletions src/api/resources/commons/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export * from "./EntityId";
export * from "./EntityUserId";
export * from "./ApprovalPolicyId";
export * from "./CommentId";
export * from "./InvoiceId";
export * from "./PaymentMethodId";
export * from "./PaymentMethodSchemaId";
export * from "./FullName";
export * from "./BirthDate";
export * from "./Address";
Expand Down
Loading

0 comments on commit dfcf550

Please sign in to comment.