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
2 changes: 1 addition & 1 deletion .fern/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
}
}
},
"sdkVersion": "44.1.0"
"sdkVersion": "44.2.0"
}
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ src/core/index.ts
src/core/crypto
tests/unit/error.test.ts
tests/unit/fetcher/stream-wrappers/webpack.test.ts
tests/unit/reporting.test.ts
tests/integration
legacy
jest.config.mjs
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
integration:
env:
TEST_SQUARE_TOKEN: ${{ secrets.TEST_SQUARE_TOKEN }}
TEST_SQUARE_REPORTING: ${{ secrets.TEST_SQUARE_REPORTING }}
runs-on: ubuntu-latest
steps:
- name: Checkout repo
Expand Down
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The Square TypeScript library provides convenient access to the Square APIs from
- [File Uploads](#file-uploads)
- [Pagination](#pagination)
- [Webhook Signature Verification](#webhook-signature-verification)
- [Reporting API](#reporting-api)
- [Advanced](#advanced)
- [Additional Headers](#additional-headers)
- [Additional Query String Parameters](#additional-query-string-parameters)
Expand Down Expand Up @@ -270,6 +271,63 @@ const isValid = WebhooksHelper.verifySignature({
});
```

## Reporting API

The [Reporting API](https://developer.squareup.com/docs/reporting-api/overview) lets you query
aggregated reporting data. Call `reporting.getMetadata` first to discover the available cubes,
measures, and dimensions, then run a query with `reporting.load`.

```ts
import { SquareClient } from "square";

const client = new SquareClient({ token: "YOUR_TOKEN" });

// Discover what you can query.
const metadata = await client.reporting.getMetadata();

// Run a query against the discovered schema.
const response = await client.reporting.load({
query: { measures: ["Orders.count"] },
});
```

`load` is asynchronous: while a query is still being computed, the API returns an HTTP `200` whose
body is `{ "error": "Continue wait" }` instead of results, and the client is expected to re-send the
identical request — with backoff — until the results are ready. The `ReportingHelper.loadAndWait`
utility owns that polling loop for you and returns the resolved results (never the `"Continue wait"`
sentinel):

```ts
import { ReportingHelper, SquareClient } from "square";

const client = new SquareClient({ token: "YOUR_TOKEN" });

const response = await ReportingHelper.loadAndWait(client, {
query: { measures: ["Orders.count"] },
});

console.log(response.results);
```

By default it polls up to 20 times with exponential backoff (2s → 20s). Tune the behavior — and
pass an `AbortSignal` to cancel — via the options argument:

```ts
const controller = new AbortController();

const response = await ReportingHelper.loadAndWait(
client,
{ query: { measures: ["Orders.count"] } },
{
maxAttempts: 10, // default 20
initialDelayMs: 1000, // default 2000
maxDelayMs: 20000, // default 20000
backoffFactor: 2, // default 2
signal: controller.signal,
},
);
```

## Advanced

### Additional Headers
Expand Down
3 changes: 3 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export default {
displayName: "integration",
preset: "ts-jest",
testEnvironment: "node",
// Integration tests hit the live sandbox; multi-step flows (e.g. customers
// "add to group") can exceed jest's 5s default under CI load. Give them headroom.
testTimeout: 30000,
moduleNameMapper: {
"^(\.{1,2}/.*)\.js$": "$1",
},
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": "44.1.0",
"version": "44.2.0",
"private": false,
"repository": {
"type": "git",
Expand Down
119 changes: 119 additions & 0 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13705,6 +13705,125 @@ await client.vendors.update({
</dl>


</dd>
</dl>
</details>

## Reporting
<details><summary><code>client.reporting.<a href="/src/api/resources/reporting/client/Client.ts">getMetadata</a>() -> Square.MetadataResponse</code></summary>
<dl>
<dd>

#### 📝 Description

<dl>
<dd>

<dl>
<dd>

Describes the data available to query: the cubes, views, measures, dimensions, and segments you can reference in a reporting query. Call this first to discover the schema, then pass the members you need to `load`.
</dd>
</dl>
</dd>
</dl>

#### 🔌 Usage

<dl>
<dd>

<dl>
<dd>

```typescript
await client.reporting.getMetadata();

```
</dd>
</dl>
</dd>
</dl>

#### ⚙️ Parameters

<dl>
<dd>

<dl>
<dd>

**requestOptions:** `ReportingClient.RequestOptions`

</dd>
</dl>
</dd>
</dl>


</dd>
</dl>
</details>

<details><summary><code>client.reporting.<a href="/src/api/resources/reporting/client/Client.ts">load</a>({ ...params }) -> Square.LoadResponse</code></summary>
<dl>
<dd>

#### 📝 Description

<dl>
<dd>

<dl>
<dd>

Runs a reporting query against the discovered schema and returns the aggregated results. Long-running queries may return a "Continue wait" response while processing — retry the same request until results are ready.
</dd>
</dl>
</dd>
</dl>

#### 🔌 Usage

<dl>
<dd>

<dl>
<dd>

```typescript
await client.reporting.load();

```
</dd>
</dl>
</dd>
</dl>

#### ⚙️ Parameters

<dl>
<dd>

<dl>
<dd>

**request:** `Square.LoadRequest`

</dd>
</dl>

<dl>
<dd>

**requestOptions:** `ReportingClient.RequestOptions`

</dd>
</dl>
</dd>
</dl>


</dd>
</dl>
</details>
Expand Down
4 changes: 2 additions & 2 deletions src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function normalizeClientOptions<T extends BaseClientOptions = BaseClientO
{
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "square",
"X-Fern-SDK-Version": "44.1.0",
"User-Agent": "square/44.1.0",
"X-Fern-SDK-Version": "44.2.0",
"User-Agent": "square/44.2.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
"Square-Version": options?.version ?? "2026-05-20",
Expand Down
6 changes: 6 additions & 0 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { OrdersClient } from "./api/resources/orders/client/Client";
import { PaymentsClient } from "./api/resources/payments/client/Client";
import { PayoutsClient } from "./api/resources/payouts/client/Client";
import { RefundsClient } from "./api/resources/refunds/client/Client";
import { ReportingClient } from "./api/resources/reporting/client/Client";
import { SitesClient } from "./api/resources/sites/client/Client";
import { SnippetsClient } from "./api/resources/snippets/client/Client";
import { SubscriptionsClient } from "./api/resources/subscriptions/client/Client";
Expand Down Expand Up @@ -79,6 +80,7 @@ export class SquareClient {
protected _terminal: TerminalClient | undefined;
protected _transferOrders: TransferOrdersClient | undefined;
protected _vendors: VendorsClient | undefined;
protected _reporting: ReportingClient | undefined;
protected _cashDrawers: CashDrawersClient | undefined;
protected _webhooks: WebhooksClient | undefined;

Expand Down Expand Up @@ -218,6 +220,10 @@ export class SquareClient {
return (this._vendors ??= new VendorsClient(this._options));
}

public get reporting(): ReportingClient {
return (this._reporting ??= new ReportingClient(this._options));
}

public get cashDrawers(): CashDrawersClient {
return (this._cashDrawers ??= new CashDrawersClient(this._options));
}
Expand Down
2 changes: 2 additions & 0 deletions src/api/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export * as payouts from "./payouts";
export * from "./payouts/client/requests";
export * as refunds from "./refunds";
export * from "./refunds/client/requests";
export * as reporting from "./reporting";
export * from "./reporting/client/requests";
export * as sites from "./sites";
export * as snippets from "./snippets";
export * from "./snippets/client/requests";
Expand Down
Loading
Loading