Skip to content

Commit e374676

Browse files
SDK regeneration
1 parent e66c2d9 commit e374676

File tree

126 files changed

+3105
-9000
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+3105
-9000
lines changed

.fern/metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"cliVersion": "2.2.5",
2+
"cliVersion": "3.20.0",
33
"generatorName": "fernapi/fern-typescript-sdk",
4-
"generatorVersion": "3.33.0",
4+
"generatorVersion": "3.40.0",
55
"generatorConfig": {
66
"namespaceExport": "Square",
77
"allowCustomFetcher": true,

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"name": "square",
3-
"version": "43.2.1",
3+
"version": "43.3.0",
44
"private": false,
5-
"repository": "github:square/square-nodejs-sdk",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/square/square-nodejs-sdk.git"
8+
},
69
"license": "MIT",
710
"main": "./index.js",
811
"types": "./index.d.ts",

src/BaseClient.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// This file was auto-generated by Fern from our API Definition.
22

3+
import { BearerAuthProvider } from "./auth/BearerAuthProvider.js";
34
import * as core from "./core";
45
import { mergeHeaders } from "./core/headers";
56
import type * as environments from "./environments";
67

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

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

42-
export function normalizeClientOptions<T extends BaseClientOptions>(options: T): T {
42+
export type NormalizedClientOptions<T extends BaseClientOptions> = T & {
43+
logging: core.logging.Logger;
44+
authProvider?: core.AuthProvider;
45+
};
46+
47+
export type NormalizedClientOptionsWithAuth<T extends BaseClientOptions> = NormalizedClientOptions<T> & {
48+
authProvider: core.AuthProvider;
49+
};
50+
51+
export function normalizeClientOptions<T extends BaseClientOptions>(options: T): NormalizedClientOptions<T> {
4352
const headers = mergeHeaders(
4453
{
4554
"X-Fern-Language": "JavaScript",
4655
"X-Fern-SDK-Name": "square",
47-
"X-Fern-SDK-Version": "43.2.1",
48-
"User-Agent": "square/43.2.1",
56+
"X-Fern-SDK-Version": "43.3.0",
57+
"User-Agent": "square/43.3.0",
4958
"X-Fern-Runtime": core.RUNTIME.type,
5059
"X-Fern-Runtime-Version": core.RUNTIME.version,
5160
"Square-Version": options?.version ?? "2025-10-16",
@@ -57,5 +66,23 @@ export function normalizeClientOptions<T extends BaseClientOptions>(options: T):
5766
...options,
5867
logging: core.logging.createLogger(options?.logging),
5968
headers,
60-
} as T;
69+
} as NormalizedClientOptions<T>;
70+
}
71+
72+
export function normalizeClientOptionsWithAuth<T extends BaseClientOptions>(
73+
options: T,
74+
): NormalizedClientOptionsWithAuth<T> {
75+
const normalized = normalizeClientOptions(options) as NormalizedClientOptionsWithAuth<T>;
76+
const normalizedWithNoOpAuthProvider = withNoOpAuthProvider(normalized);
77+
normalized.authProvider ??= new BearerAuthProvider(normalizedWithNoOpAuthProvider);
78+
return normalized;
79+
}
80+
81+
function withNoOpAuthProvider<T extends BaseClientOptions>(
82+
options: NormalizedClientOptions<T>,
83+
): NormalizedClientOptionsWithAuth<T> {
84+
return {
85+
...options,
86+
authProvider: new core.NoOpAuthProvider(),
87+
};
6188
}

src/Client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ import { V1TransactionsClient } from "./api/resources/v1Transactions/client/Clie
3737
import { VendorsClient } from "./api/resources/vendors/client/Client";
3838
import { WebhooksClient } from "./api/resources/webhooks/client/Client";
3939
import type { BaseClientOptions, BaseRequestOptions } from "./BaseClient";
40-
import { normalizeClientOptions } from "./BaseClient";
40+
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "./BaseClient";
4141

4242
export declare namespace SquareClient {
43-
export interface Options extends BaseClientOptions {}
43+
export type Options = BaseClientOptions;
4444

4545
export interface RequestOptions extends BaseRequestOptions {}
4646
}
4747

4848
export class SquareClient {
49-
protected readonly _options: SquareClient.Options;
49+
protected readonly _options: NormalizedClientOptionsWithAuth<SquareClient.Options>;
5050
protected _mobile: MobileClient | undefined;
5151
protected _oAuth: OAuthClient | undefined;
5252
protected _v1Transactions: V1TransactionsClient | undefined;
@@ -85,7 +85,7 @@ export class SquareClient {
8585
protected _webhooks: WebhooksClient | undefined;
8686

8787
constructor(options: SquareClient.Options = {}) {
88-
this._options = normalizeClientOptions(options);
88+
this._options = normalizeClientOptionsWithAuth(options);
8989
}
9090

9191
public get mobile(): MobileClient {

src/api/resources/applePay/client/Client.ts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
// This file was auto-generated by Fern from our API Definition.
22

33
import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient";
4-
import { normalizeClientOptions } from "../../../../BaseClient";
4+
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient";
55
import * as core from "../../../../core";
66
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers";
77
import * as environments from "../../../../environments";
8+
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError";
89
import * as errors from "../../../../errors/index";
910
import * as serializers from "../../../../serialization/index";
1011
import type * as Square from "../../../index";
1112

1213
export declare namespace ApplePayClient {
13-
export interface Options extends BaseClientOptions {}
14+
export type Options = BaseClientOptions;
1415

1516
export interface RequestOptions extends BaseRequestOptions {}
1617
}
1718

1819
export class ApplePayClient {
19-
protected readonly _options: ApplePayClient.Options;
20+
protected readonly _options: NormalizedClientOptionsWithAuth<ApplePayClient.Options>;
2021

2122
constructor(options: ApplePayClient.Options = {}) {
22-
this._options = normalizeClientOptions(options);
23+
this._options = normalizeClientOptionsWithAuth(options);
2324
}
2425

2526
/**
@@ -57,12 +58,11 @@ export class ApplePayClient {
5758
request: Square.RegisterDomainRequest,
5859
requestOptions?: ApplePayClient.RequestOptions,
5960
): Promise<core.WithRawResponse<Square.RegisterDomainResponse>> {
61+
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
6062
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
63+
_authRequest.headers,
6164
this._options?.headers,
62-
mergeOnlyDefinedHeaders({
63-
Authorization: await this._getAuthorizationHeader(),
64-
"Square-Version": requestOptions?.version ?? "2025-10-16",
65-
}),
65+
mergeOnlyDefinedHeaders({ "Square-Version": requestOptions?.version ?? "2025-10-16" }),
6666
requestOptions?.headers,
6767
);
6868
const _response = await (this._options.fetcher ?? core.fetcher)({
@@ -108,29 +108,6 @@ export class ApplePayClient {
108108
});
109109
}
110110

111-
switch (_response.error.reason) {
112-
case "non-json":
113-
throw new errors.SquareError({
114-
statusCode: _response.error.statusCode,
115-
body: _response.error.rawBody,
116-
rawResponse: _response.rawResponse,
117-
});
118-
case "timeout":
119-
throw new errors.SquareTimeoutError("Timeout exceeded when calling POST /v2/apple-pay/domains.");
120-
case "unknown":
121-
throw new errors.SquareError({
122-
message: _response.error.errorMessage,
123-
rawResponse: _response.rawResponse,
124-
});
125-
}
126-
}
127-
128-
protected async _getAuthorizationHeader(): Promise<string | undefined> {
129-
const bearer = (await core.Supplier.get(this._options.token)) ?? process?.env.SQUARE_TOKEN;
130-
if (bearer != null) {
131-
return `Bearer ${bearer}`;
132-
}
133-
134-
return undefined;
111+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/v2/apple-pay/domains");
135112
}
136113
}

src/api/resources/bankAccounts/client/Client.ts

Lines changed: 27 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
// This file was auto-generated by Fern from our API Definition.
22

33
import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient";
4-
import { normalizeClientOptions } from "../../../../BaseClient";
4+
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient";
55
import * as core from "../../../../core";
66
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers";
77
import * as environments from "../../../../environments";
8+
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError";
89
import * as errors from "../../../../errors/index";
910
import * as serializers from "../../../../serialization/index";
1011
import type * as Square from "../../../index";
1112

1213
export declare namespace BankAccountsClient {
13-
export interface Options extends BaseClientOptions {}
14+
export type Options = BaseClientOptions;
1415

1516
export interface RequestOptions extends BaseRequestOptions {}
1617
}
1718

1819
export class BankAccountsClient {
19-
protected readonly _options: BankAccountsClient.Options;
20+
protected readonly _options: NormalizedClientOptionsWithAuth<BankAccountsClient.Options>;
2021

2122
constructor(options: BankAccountsClient.Options = {}) {
22-
this._options = normalizeClientOptions(options);
23+
this._options = normalizeClientOptionsWithAuth(options);
2324
}
2425

2526
/**
@@ -54,12 +55,11 @@ export class BankAccountsClient {
5455
if (locationId !== undefined) {
5556
_queryParams.location_id = locationId;
5657
}
58+
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
5759
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
60+
_authRequest.headers,
5861
this._options?.headers,
59-
mergeOnlyDefinedHeaders({
60-
Authorization: await this._getAuthorizationHeader(),
61-
"Square-Version": requestOptions?.version ?? "2025-10-16",
62-
}),
62+
mergeOnlyDefinedHeaders({ "Square-Version": requestOptions?.version ?? "2025-10-16" }),
6363
requestOptions?.headers,
6464
);
6565
const _response = await (this._options.fetcher ?? core.fetcher)({
@@ -97,21 +97,7 @@ export class BankAccountsClient {
9797
rawResponse: _response.rawResponse,
9898
});
9999
}
100-
switch (_response.error.reason) {
101-
case "non-json":
102-
throw new errors.SquareError({
103-
statusCode: _response.error.statusCode,
104-
body: _response.error.rawBody,
105-
rawResponse: _response.rawResponse,
106-
});
107-
case "timeout":
108-
throw new errors.SquareTimeoutError("Timeout exceeded when calling GET /v2/bank-accounts.");
109-
case "unknown":
110-
throw new errors.SquareError({
111-
message: _response.error.errorMessage,
112-
rawResponse: _response.rawResponse,
113-
});
114-
}
100+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v2/bank-accounts");
115101
},
116102
);
117103
const dataWithRawResponse = await list(request).withRawResponse();
@@ -150,12 +136,11 @@ export class BankAccountsClient {
150136
requestOptions?: BankAccountsClient.RequestOptions,
151137
): Promise<core.WithRawResponse<Square.GetBankAccountByV1IdResponse>> {
152138
const { v1BankAccountId } = request;
139+
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
153140
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
141+
_authRequest.headers,
154142
this._options?.headers,
155-
mergeOnlyDefinedHeaders({
156-
Authorization: await this._getAuthorizationHeader(),
157-
"Square-Version": requestOptions?.version ?? "2025-10-16",
158-
}),
143+
mergeOnlyDefinedHeaders({ "Square-Version": requestOptions?.version ?? "2025-10-16" }),
159144
requestOptions?.headers,
160145
);
161146
const _response = await (this._options.fetcher ?? core.fetcher)({
@@ -195,23 +180,12 @@ export class BankAccountsClient {
195180
});
196181
}
197182

198-
switch (_response.error.reason) {
199-
case "non-json":
200-
throw new errors.SquareError({
201-
statusCode: _response.error.statusCode,
202-
body: _response.error.rawBody,
203-
rawResponse: _response.rawResponse,
204-
});
205-
case "timeout":
206-
throw new errors.SquareTimeoutError(
207-
"Timeout exceeded when calling GET /v2/bank-accounts/by-v1-id/{v1_bank_account_id}.",
208-
);
209-
case "unknown":
210-
throw new errors.SquareError({
211-
message: _response.error.errorMessage,
212-
rawResponse: _response.rawResponse,
213-
});
214-
}
183+
return handleNonStatusCodeError(
184+
_response.error,
185+
_response.rawResponse,
186+
"GET",
187+
"/v2/bank-accounts/by-v1-id/{v1_bank_account_id}",
188+
);
215189
}
216190

217191
/**
@@ -238,12 +212,11 @@ export class BankAccountsClient {
238212
requestOptions?: BankAccountsClient.RequestOptions,
239213
): Promise<core.WithRawResponse<Square.GetBankAccountResponse>> {
240214
const { bankAccountId } = request;
215+
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
241216
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
217+
_authRequest.headers,
242218
this._options?.headers,
243-
mergeOnlyDefinedHeaders({
244-
Authorization: await this._getAuthorizationHeader(),
245-
"Square-Version": requestOptions?.version ?? "2025-10-16",
246-
}),
219+
mergeOnlyDefinedHeaders({ "Square-Version": requestOptions?.version ?? "2025-10-16" }),
247220
requestOptions?.headers,
248221
);
249222
const _response = await (this._options.fetcher ?? core.fetcher)({
@@ -283,31 +256,11 @@ export class BankAccountsClient {
283256
});
284257
}
285258

286-
switch (_response.error.reason) {
287-
case "non-json":
288-
throw new errors.SquareError({
289-
statusCode: _response.error.statusCode,
290-
body: _response.error.rawBody,
291-
rawResponse: _response.rawResponse,
292-
});
293-
case "timeout":
294-
throw new errors.SquareTimeoutError(
295-
"Timeout exceeded when calling GET /v2/bank-accounts/{bank_account_id}.",
296-
);
297-
case "unknown":
298-
throw new errors.SquareError({
299-
message: _response.error.errorMessage,
300-
rawResponse: _response.rawResponse,
301-
});
302-
}
303-
}
304-
305-
protected async _getAuthorizationHeader(): Promise<string | undefined> {
306-
const bearer = (await core.Supplier.get(this._options.token)) ?? process?.env.SQUARE_TOKEN;
307-
if (bearer != null) {
308-
return `Bearer ${bearer}`;
309-
}
310-
311-
return undefined;
259+
return handleNonStatusCodeError(
260+
_response.error,
261+
_response.rawResponse,
262+
"GET",
263+
"/v2/bank-accounts/{bank_account_id}",
264+
);
312265
}
313266
}

0 commit comments

Comments
 (0)