Skip to content
Merged
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
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,38 @@ await client.payments.create({

## Legacy SDK

> If you're using TypeScript, make sure that the `moduleResolution` setting in your `tsconfig.json` is equal to `node16`, `nodenext`, > or `bundler` to consume the legacy SDK.
While the new SDK has a lot of improvements, we at Square understand that it takes time to upgrade when there are breaking changes. To make the migration easier, the new SDK also exports the legacy SDK as `square/legacy`. Here's an example of how you can use the legacy SDK alongside the new SDK inside a single file:
```typescript import { randomUUID } from "crypto"; import { Square, SquareClient } from "square"; import { Client } from "square/legacy";
## Legacy SDK

> If you're using TypeScript, make sure that the `moduleResolution` setting in your `tsconfig.json` is equal to `node16`, `nodenext`,
> or `bundler` to consume the legacy SDK.

While the new SDK has a lot of improvements, we at Square understand that it takes time to upgrade when there are breaking changes.
To make the migration easier, the new SDK also exports the legacy SDK as `square/legacy`. Here's an example of how you can use the
legacy SDK alongside the new SDK inside a single file:

```typescript
import { randomUUID } from "crypto";
import { Square, SquareClient } from "square";
import { Client } from "square/legacy";

const client = new SquareClient({
token: process.env.SQUARE_ACCESS_TOKEN,
});

const legacyClient = new Client({
bearerAuthCredentials: {
accessToken: process.env.SQUARE_ACCESS_TOKEN!,
},
});

async function getLocation(): Promise<Square.Location> {
return (
await client.locations.get({
locationId: "YOUR_LOCATION_ID",
})
).location!;
}

async function createOrder() {
const location = await getLocation();
await legacyClient.ordersApi.createOrder({
Expand All @@ -115,10 +129,19 @@ async function createOrder() {
},
});
}
createOrder(); ```

createOrder();
```

We recommend migrating to the new SDK using the following steps:
1. Upgrade the NPM module to `^40.0.0` 2. Search and replace all requires and imports from `"square"` to `"square/legacy"`
- For required, replace `require("square")` with `require("square/legacy")` - For imports, replace `from "square"` with `from "square/legacy"` - For dynamic imports, replace `import("square")` with `import("square/legacy")`

1. Upgrade the NPM module to `^40.0.0` or later.
2. Search and replace all requires and imports from `"square"` to `"square/legacy"`

- For required, replace `require("square")` with `require("square/legacy")`
- For imports, replace `from "square"` with `from "square/legacy"`
- For dynamic imports, replace `import("square")` with `import("square/legacy")`

3. Gradually move over to use the new SDK by importing it from the `"square"` import.


Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,9 @@ asynckit@^0.4.0:
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==

axios@^1.8.4:
version "1.13.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.13.2.tgz#9ada120b7b5ab24509553ec3e40123521117f687"
integrity sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==
version "1.13.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.13.3.tgz#f123e77356630a22b0163920662556944f2be1a1"
integrity sha512-ERT8kdX7DZjtUm7IitEyV7InTHAF42iJuMArIiDIV5YtPanJkgw4hw5Dyg9fh0mihdWNn1GKaeIWErfe56UQ1g==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.4"
Expand Down
Loading