diff --git a/README.md b/README.md index b5b8a395..ae4ec5b2 100644 --- a/README.md +++ b/README.md @@ -78,17 +78,30 @@ 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 { return ( await client.locations.get({ @@ -96,6 +109,7 @@ async function getLocation(): Promise { }) ).location!; } + async function createOrder() { const location = await getLocation(); await legacyClient.ordersApi.createOrder({ @@ -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. diff --git a/yarn.lock b/yarn.lock index f3972445..de57c750 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"