Skip to content

Commit

Permalink
Release 0.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Jul 10, 2024
1 parent 3f716e0 commit 3cde181
Show file tree
Hide file tree
Showing 69 changed files with 775 additions and 386 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mercoa/javascript",
"version": "0.4.5",
"version": "0.4.6",
"private": false,
"repository": "https://github.com/mercoa-finance/javascript",
"main": "./index.js",
Expand Down
14 changes: 7 additions & 7 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Entity } from "./api/resources/entity/client/Client";
import { Invoice } from "./api/resources/invoice/client/Client";
import { Organization } from "./api/resources/organization/client/Client";
import { BankLookup } from "./api/resources/bankLookup/client/Client";
import { Calculate } from "./api/resources/calculate/client/Client";
import { CustomPaymentMethodSchema } from "./api/resources/customPaymentMethodSchema/client/Client";
import { Fees } from "./api/resources/fees/client/Client";
import { Ocr } from "./api/resources/ocr/client/Client";

export declare namespace MercoaClient {
Expand Down Expand Up @@ -59,16 +59,16 @@ export class MercoaClient {
return (this._bankLookup ??= new BankLookup(this._options));
}

protected _customPaymentMethodSchema: CustomPaymentMethodSchema | undefined;
protected _calculate: Calculate | undefined;

public get customPaymentMethodSchema(): CustomPaymentMethodSchema {
return (this._customPaymentMethodSchema ??= new CustomPaymentMethodSchema(this._options));
public get calculate(): Calculate {
return (this._calculate ??= new Calculate(this._options));
}

protected _fees: Fees | undefined;
protected _customPaymentMethodSchema: CustomPaymentMethodSchema | undefined;

public get fees(): Fees {
return (this._fees ??= new Fees(this._options));
public get customPaymentMethodSchema(): CustomPaymentMethodSchema {
return (this._customPaymentMethodSchema ??= new CustomPaymentMethodSchema(this._options));
}

protected _ocr: Ocr | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/api/resources/bankLookup/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class BankLookup {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@mercoa/javascript",
"X-Fern-SDK-Version": "0.4.5",
"X-Fern-SDK-Version": "0.4.6",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
Expand Down
317 changes: 317 additions & 0 deletions src/api/resources/calculate/client/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as environments from "../../../../environments";
import * as core from "../../../../core";
import * as Mercoa from "../../../index";
import * as serializers from "../../../../serialization/index";
import urlJoin from "url-join";
import * as errors from "../../../../errors/index";

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

interface RequestOptions {
timeoutInSeconds?: number;
maxRetries?: number;
abortSignal?: AbortSignal;
}
}

export class Calculate {
constructor(protected readonly _options: Calculate.Options) {}

/**
* Calculate the estimated fees associated with an payment given the amount, payment source, and disbursement method. Can be used to calculate fees for a payment before creating an invoice.
*
* @param {Mercoa.CalculateFeesRequest} request
* @param {Calculate.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Mercoa.BadRequest}
* @throws {@link Mercoa.Unauthorized}
* @throws {@link Mercoa.Forbidden}
* @throws {@link Mercoa.NotFound}
* @throws {@link Mercoa.Conflict}
* @throws {@link Mercoa.InternalServerError}
* @throws {@link Mercoa.Unimplemented}
*
* @example
* await client.calculate.fee({
* amount: 100,
* paymentSourceId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769",
* paymentDestinationId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769"
* })
*/
public async fee(
request: Mercoa.CalculateFeesRequest,
requestOptions?: Calculate.RequestOptions
): Promise<Mercoa.InvoiceFeesResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.MercoaEnvironment.Production,
"fees"
),
method: "POST",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@mercoa/javascript",
"X-Fern-SDK-Version": "0.4.6",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
body: await serializers.CalculateFeesRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return await serializers.InvoiceFeesResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
switch ((_response.error.body as any)?.["errorName"]) {
case "BadRequest":
throw new Mercoa.BadRequest(
await serializers.BadRequest.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"],
})
);
case "Forbidden":
throw new Mercoa.Forbidden(
await serializers.Forbidden.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "NotFound":
throw new Mercoa.NotFound(
await serializers.NotFound.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "Conflict":
throw new Mercoa.Conflict(
await serializers.Conflict.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "InternalServerError":
throw new Mercoa.InternalServerError(
await serializers.InternalServerError.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "Unimplemented":
throw new Mercoa.Unimplemented(
await serializers.Unimplemented.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) {
case "non-json":
throw new errors.MercoaError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.MercoaTimeoutError();
case "unknown":
throw new errors.MercoaError({
message: _response.error.errorMessage,
});
}
}

/**
* Calculate the estimated payment timing given the deduction date, payment source, and disbursement method. Can be used to calculate timing for a payment.
*
* @param {Mercoa.CalculatePaymentTimingRequest} request
* @param {Calculate.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Mercoa.BadRequest}
* @throws {@link Mercoa.Unauthorized}
* @throws {@link Mercoa.Forbidden}
* @throws {@link Mercoa.NotFound}
* @throws {@link Mercoa.Conflict}
* @throws {@link Mercoa.InternalServerError}
* @throws {@link Mercoa.Unimplemented}
*
* @example
* await client.calculate.paymentTiming({
* estimatedDeductionDate: new Date("2024-01-02T00:00:00.000Z"),
* paymentSourceId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769",
* paymentDestinationId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769"
* })
*/
public async paymentTiming(
request: Mercoa.CalculatePaymentTimingRequest,
requestOptions?: Calculate.RequestOptions
): Promise<Mercoa.CalculatePaymentTimingResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.MercoaEnvironment.Production,
"paymentTiming"
),
method: "POST",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@mercoa/javascript",
"X-Fern-SDK-Version": "0.4.6",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
body: await serializers.CalculatePaymentTimingRequest.jsonOrThrow(request, {
unrecognizedObjectKeys: "strip",
}),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return await serializers.CalculatePaymentTimingResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
switch ((_response.error.body as any)?.["errorName"]) {
case "BadRequest":
throw new Mercoa.BadRequest(
await serializers.BadRequest.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"],
})
);
case "Forbidden":
throw new Mercoa.Forbidden(
await serializers.Forbidden.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "NotFound":
throw new Mercoa.NotFound(
await serializers.NotFound.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "Conflict":
throw new Mercoa.Conflict(
await serializers.Conflict.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "InternalServerError":
throw new Mercoa.InternalServerError(
await serializers.InternalServerError.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
})
);
case "Unimplemented":
throw new Mercoa.Unimplemented(
await serializers.Unimplemented.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) {
case "non-json":
throw new errors.MercoaError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.MercoaTimeoutError();
case "unknown":
throw new errors.MercoaError({
message: _response.error.errorMessage,
});
}
}

protected async _getAuthorizationHeader(): Promise<string> {
return `Bearer ${await core.Supplier.get(this._options.token)}`;
}
}
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions src/api/resources/calculate/types/CalculatePaymentTimingRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as Mercoa from "../../../index";

/**
* @example
* {
* estimatedDeductionDate: new Date("2024-01-02T00:00:00.000Z"),
* paymentSourceId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769",
* paymentDestinationId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769"
* }
*/
export interface CalculatePaymentTimingRequest {
/** Date the payment is scheduled to be deducted from the payer's account. Use this field if the payment has not yet been deducted. */
estimatedDeductionDate?: Date;
/** Date the payment was processed. Use this field if the payment has already been deducted. */
processedAt?: Date;
/** ID of payment source. */
paymentSourceId: Mercoa.PaymentMethodId;
/** ID of payment destination. */
paymentDestinationId: Mercoa.PaymentMethodId;
/** Options for the payment destination. Depending on the payment destination, this may include things such as check delivery method. */
paymentDestinationOptions?: Mercoa.PaymentDestinationOptions;
}
Loading

0 comments on commit 3cde181

Please sign in to comment.