Skip to content
Closed
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": "2.8.1",
"generatorName": "fernapi/fern-typescript-sdk",
"generatorVersion": "3.33.0",
"generatorVersion": "3.34.0",
"generatorConfig": {
"namespaceExport": "Square",
"allowCustomFetcher": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "square",
"version": "43.2.1",
"version": "43.2.2",
"private": false,
"repository": "github:square/square-nodejs-sdk",
"license": "MIT",
Expand Down
26 changes: 22 additions & 4 deletions src/BaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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";
Expand Down Expand Up @@ -39,13 +40,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.2.2",
"User-Agent": "square/43.2.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
"Square-Version": options?.version ?? "2025-10-16",
Expand All @@ -57,5 +67,13 @@ 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>;
normalized.authProvider ??= new BearerAuthProvider(options);
return normalized;
}
6 changes: 3 additions & 3 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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 {}
Expand All @@ -46,7 +46,7 @@ export declare namespace SquareClient {
}

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
22 changes: 6 additions & 16 deletions src/api/resources/applePay/client/Client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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";
Expand All @@ -16,10 +16,10 @@ export declare namespace ApplePayClient {
}

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 +57,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 @@ -124,13 +123,4 @@ export class ApplePayClient {
});
}
}

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;
}
}
36 changes: 12 additions & 24 deletions src/api/resources/bankAccounts/client/Client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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";
Expand All @@ -16,10 +16,10 @@ export declare namespace BankAccountsClient {
}

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 +54,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 @@ -150,12 +149,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 @@ -238,12 +236,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 @@ -301,13 +298,4 @@ export class BankAccountsClient {
});
}
}

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;
}
}
Loading
Loading