Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"cliVersion": "2.2.5",
"cliVersion": "3.20.0",
"generatorName": "fernapi/fern-typescript-sdk",
"generatorVersion": "3.33.0",
"generatorVersion": "3.40.0",
"generatorConfig": {
"namespaceExport": "Square",
"allowCustomFetcher": true,
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ jobs:
uses: actions/setup-node@v3

- name: Compile
run: yarn && yarn test:unit
run: yarn && yarn build

- name: Unit Test
run: yarn test:unit

- name: Wire Test
run: yarn test:wire

publish:
needs: [ compile ]
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "square",
"version": "43.2.1",
"version": "43.3.0",
"private": false,
"repository": "github:square/square-nodejs-sdk",
"repository": {
"type": "git",
"url": "git+https://github.com/square/square-nodejs-sdk.git"
},
"license": "MIT",
"main": "./index.js",
"types": "./index.d.ts",
Expand Down
41 changes: 34 additions & 7 deletions src/BaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// This file was auto-generated by Fern from our API Definition.

import { BearerAuthProvider } from "./auth/BearerAuthProvider.js";
import * as core from "./core";
import { mergeHeaders } from "./core/headers";
import type * as environments from "./environments";

export interface BaseClientOptions {
export type BaseClientOptions = {
environment?: core.Supplier<environments.SquareEnvironment | string>;
/** Specify a custom URL to connect the client to. */
baseUrl?: core.Supplier<string>;
token?: core.Supplier<core.BearerToken | undefined>;
/** Override the Square-Version header */
version?: "2025-10-16";
/** Additional headers to include in requests. */
Expand All @@ -22,7 +22,7 @@ export interface BaseClientOptions {
fetcher?: core.FetchFunction;
/** Configure logging for the client. */
logging?: core.logging.LogConfig | core.logging.Logger;
}
} & BearerAuthProvider.AuthOptions;

export interface BaseRequestOptions {
/** The maximum time to wait for a response in seconds. */
Expand All @@ -39,13 +39,22 @@ export interface BaseRequestOptions {
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
}

export function normalizeClientOptions<T extends BaseClientOptions>(options: T): T {
export type NormalizedClientOptions<T extends BaseClientOptions> = T & {
logging: core.logging.Logger;
authProvider?: core.AuthProvider;
};

export type NormalizedClientOptionsWithAuth<T extends BaseClientOptions> = NormalizedClientOptions<T> & {
authProvider: core.AuthProvider;
};

export function normalizeClientOptions<T extends BaseClientOptions>(options: T): NormalizedClientOptions<T> {
const headers = mergeHeaders(
{
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "square",
"X-Fern-SDK-Version": "43.2.1",
"User-Agent": "square/43.2.1",
"X-Fern-SDK-Version": "43.3.0",
"User-Agent": "square/43.3.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
"Square-Version": options?.version ?? "2025-10-16",
Expand All @@ -57,5 +66,23 @@ export function normalizeClientOptions<T extends BaseClientOptions>(options: T):
...options,
logging: core.logging.createLogger(options?.logging),
headers,
} as T;
} as NormalizedClientOptions<T>;
}

export function normalizeClientOptionsWithAuth<T extends BaseClientOptions>(
options: T,
): NormalizedClientOptionsWithAuth<T> {
const normalized = normalizeClientOptions(options) as NormalizedClientOptionsWithAuth<T>;
const normalizedWithNoOpAuthProvider = withNoOpAuthProvider(normalized);
normalized.authProvider ??= new BearerAuthProvider(normalizedWithNoOpAuthProvider);
return normalized;
}

function withNoOpAuthProvider<T extends BaseClientOptions>(
options: NormalizedClientOptions<T>,
): NormalizedClientOptionsWithAuth<T> {
return {
...options,
authProvider: new core.NoOpAuthProvider(),
};
}
8 changes: 4 additions & 4 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ import { V1TransactionsClient } from "./api/resources/v1Transactions/client/Clie
import { VendorsClient } from "./api/resources/vendors/client/Client";
import { WebhooksClient } from "./api/resources/webhooks/client/Client";
import type { BaseClientOptions, BaseRequestOptions } from "./BaseClient";
import { normalizeClientOptions } from "./BaseClient";
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "./BaseClient";

export declare namespace SquareClient {
export interface Options extends BaseClientOptions {}
export type Options = BaseClientOptions;

export interface RequestOptions extends BaseRequestOptions {}
}

export class SquareClient {
protected readonly _options: SquareClient.Options;
protected readonly _options: NormalizedClientOptionsWithAuth<SquareClient.Options>;
protected _mobile: MobileClient | undefined;
protected _oAuth: OAuthClient | undefined;
protected _v1Transactions: V1TransactionsClient | undefined;
Expand Down Expand Up @@ -85,7 +85,7 @@ export class SquareClient {
protected _webhooks: WebhooksClient | undefined;

constructor(options: SquareClient.Options = {}) {
this._options = normalizeClientOptions(options);
this._options = normalizeClientOptionsWithAuth(options);
}

public get mobile(): MobileClient {
Expand Down
41 changes: 9 additions & 32 deletions src/api/resources/applePay/client/Client.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// This file was auto-generated by Fern from our API Definition.

import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient";
import { normalizeClientOptions } from "../../../../BaseClient";
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient";
import * as core from "../../../../core";
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers";
import * as environments from "../../../../environments";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError";
import * as errors from "../../../../errors/index";
import * as serializers from "../../../../serialization/index";
import type * as Square from "../../../index";

export declare namespace ApplePayClient {
export interface Options extends BaseClientOptions {}
export type Options = BaseClientOptions;

export interface RequestOptions extends BaseRequestOptions {}
}

export class ApplePayClient {
protected readonly _options: ApplePayClient.Options;
protected readonly _options: NormalizedClientOptionsWithAuth<ApplePayClient.Options>;

constructor(options: ApplePayClient.Options = {}) {
this._options = normalizeClientOptions(options);
this._options = normalizeClientOptionsWithAuth(options);
}

/**
Expand Down Expand Up @@ -57,12 +58,11 @@ export class ApplePayClient {
request: Square.RegisterDomainRequest,
requestOptions?: ApplePayClient.RequestOptions,
): Promise<core.WithRawResponse<Square.RegisterDomainResponse>> {
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
_authRequest.headers,
this._options?.headers,
mergeOnlyDefinedHeaders({
Authorization: await this._getAuthorizationHeader(),
"Square-Version": requestOptions?.version ?? "2025-10-16",
}),
mergeOnlyDefinedHeaders({ "Square-Version": requestOptions?.version ?? "2025-10-16" }),
requestOptions?.headers,
);
const _response = await (this._options.fetcher ?? core.fetcher)({
Expand Down Expand Up @@ -108,29 +108,6 @@ export class ApplePayClient {
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.SquareError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
rawResponse: _response.rawResponse,
});
case "timeout":
throw new errors.SquareTimeoutError("Timeout exceeded when calling POST /v2/apple-pay/domains.");
case "unknown":
throw new errors.SquareError({
message: _response.error.errorMessage,
rawResponse: _response.rawResponse,
});
}
}

protected async _getAuthorizationHeader(): Promise<string | undefined> {
const bearer = (await core.Supplier.get(this._options.token)) ?? process?.env.SQUARE_TOKEN;
if (bearer != null) {
return `Bearer ${bearer}`;
}

return undefined;
return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/v2/apple-pay/domains");
}
}
101 changes: 27 additions & 74 deletions src/api/resources/bankAccounts/client/Client.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// This file was auto-generated by Fern from our API Definition.

import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient";
import { normalizeClientOptions } from "../../../../BaseClient";
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient";
import * as core from "../../../../core";
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers";
import * as environments from "../../../../environments";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError";
import * as errors from "../../../../errors/index";
import * as serializers from "../../../../serialization/index";
import type * as Square from "../../../index";

export declare namespace BankAccountsClient {
export interface Options extends BaseClientOptions {}
export type Options = BaseClientOptions;

export interface RequestOptions extends BaseRequestOptions {}
}

export class BankAccountsClient {
protected readonly _options: BankAccountsClient.Options;
protected readonly _options: NormalizedClientOptionsWithAuth<BankAccountsClient.Options>;

constructor(options: BankAccountsClient.Options = {}) {
this._options = normalizeClientOptions(options);
this._options = normalizeClientOptionsWithAuth(options);
}

/**
Expand Down Expand Up @@ -54,12 +55,11 @@ export class BankAccountsClient {
if (locationId !== undefined) {
_queryParams.location_id = locationId;
}
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
_authRequest.headers,
this._options?.headers,
mergeOnlyDefinedHeaders({
Authorization: await this._getAuthorizationHeader(),
"Square-Version": requestOptions?.version ?? "2025-10-16",
}),
mergeOnlyDefinedHeaders({ "Square-Version": requestOptions?.version ?? "2025-10-16" }),
requestOptions?.headers,
);
const _response = await (this._options.fetcher ?? core.fetcher)({
Expand Down Expand Up @@ -97,21 +97,7 @@ export class BankAccountsClient {
rawResponse: _response.rawResponse,
});
}
switch (_response.error.reason) {
case "non-json":
throw new errors.SquareError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
rawResponse: _response.rawResponse,
});
case "timeout":
throw new errors.SquareTimeoutError("Timeout exceeded when calling GET /v2/bank-accounts.");
case "unknown":
throw new errors.SquareError({
message: _response.error.errorMessage,
rawResponse: _response.rawResponse,
});
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v2/bank-accounts");
},
);
const dataWithRawResponse = await list(request).withRawResponse();
Expand Down Expand Up @@ -150,12 +136,11 @@ export class BankAccountsClient {
requestOptions?: BankAccountsClient.RequestOptions,
): Promise<core.WithRawResponse<Square.GetBankAccountByV1IdResponse>> {
const { v1BankAccountId } = request;
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
_authRequest.headers,
this._options?.headers,
mergeOnlyDefinedHeaders({
Authorization: await this._getAuthorizationHeader(),
"Square-Version": requestOptions?.version ?? "2025-10-16",
}),
mergeOnlyDefinedHeaders({ "Square-Version": requestOptions?.version ?? "2025-10-16" }),
requestOptions?.headers,
);
const _response = await (this._options.fetcher ?? core.fetcher)({
Expand Down Expand Up @@ -195,23 +180,12 @@ export class BankAccountsClient {
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.SquareError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
rawResponse: _response.rawResponse,
});
case "timeout":
throw new errors.SquareTimeoutError(
"Timeout exceeded when calling GET /v2/bank-accounts/by-v1-id/{v1_bank_account_id}.",
);
case "unknown":
throw new errors.SquareError({
message: _response.error.errorMessage,
rawResponse: _response.rawResponse,
});
}
return handleNonStatusCodeError(
_response.error,
_response.rawResponse,
"GET",
"/v2/bank-accounts/by-v1-id/{v1_bank_account_id}",
);
}

/**
Expand All @@ -238,12 +212,11 @@ export class BankAccountsClient {
requestOptions?: BankAccountsClient.RequestOptions,
): Promise<core.WithRawResponse<Square.GetBankAccountResponse>> {
const { bankAccountId } = request;
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
_authRequest.headers,
this._options?.headers,
mergeOnlyDefinedHeaders({
Authorization: await this._getAuthorizationHeader(),
"Square-Version": requestOptions?.version ?? "2025-10-16",
}),
mergeOnlyDefinedHeaders({ "Square-Version": requestOptions?.version ?? "2025-10-16" }),
requestOptions?.headers,
);
const _response = await (this._options.fetcher ?? core.fetcher)({
Expand Down Expand Up @@ -283,31 +256,11 @@ export class BankAccountsClient {
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.SquareError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
rawResponse: _response.rawResponse,
});
case "timeout":
throw new errors.SquareTimeoutError(
"Timeout exceeded when calling GET /v2/bank-accounts/{bank_account_id}.",
);
case "unknown":
throw new errors.SquareError({
message: _response.error.errorMessage,
rawResponse: _response.rawResponse,
});
}
}

protected async _getAuthorizationHeader(): Promise<string | undefined> {
const bearer = (await core.Supplier.get(this._options.token)) ?? process?.env.SQUARE_TOKEN;
if (bearer != null) {
return `Bearer ${bearer}`;
}

return undefined;
return handleNonStatusCodeError(
_response.error,
_response.rawResponse,
"GET",
"/v2/bank-accounts/{bank_account_id}",
);
}
}
Loading
Loading