@@ -53,6 +53,69 @@ await client.payments.create({
5353});
5454```
5555
56+ ## Legacy SDK
57+
58+ While the new SDK has a lot of improvements, we at Square understand that it takes time to upgrade when there are breaking changes.
59+ 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
60+ legacy SDK alongside the new SDK inside a single file:
61+
62+ ``` typescript
63+ import { randomUUID } from " crypto" ;
64+ import { Square , SquareClient } from " square" ;
65+ import { Client } from " square/legacy" ;
66+
67+ const client = new SquareClient ({
68+ token: process .env .SQUARE_ACCESS_TOKEN ,
69+ });
70+
71+ const legacyClient = new Client ({
72+ bearerAuthCredentials: {
73+ accessToken: process .env .SQUARE_ACCESS_TOKEN ! ,
74+ },
75+ });
76+
77+ async function getLocation(): Promise <Square .Location > {
78+ return (
79+ await client .locations .get ({
80+ locationId: " YOUR_LOCATION_ID" ,
81+ })
82+ ).location ! ;
83+ }
84+
85+ async function createOrder() {
86+ const location = await getLocation ();
87+ await legacyClient .ordersApi .createOrder ({
88+ idempotencyKey: randomUUID (),
89+ order: {
90+ locationId: location .id ! ,
91+ lineItems: [
92+ {
93+ name: " New Item" ,
94+ quantity: " 1" ,
95+ basePriceMoney: {
96+ amount: BigInt (100 ),
97+ currency: " USD" ,
98+ },
99+ },
100+ ],
101+ },
102+ });
103+ }
104+
105+ createOrder ();
106+ ```
107+
108+ We recommend migrating to the new SDK using the following steps:
109+
110+ 1 . Upgrade the NPM module to ` ^40.0.0 `
111+ 2 . Search and replace all requires and imports from ` "square" ` to ` "square/legacy" `
112+
113+ - For required, replace ` require("square") ` with ` require("square/legacy") `
114+ - For imports, replace ` from "square" ` with ` from "square/legacy" `
115+ - For dynamic imports, replace ` import("square") ` with ` import("square/legacy") `
116+
117+ 3 . Gradually move over to use the new SDK by importing it from the ` "square" ` import.
118+
56119## Request And Response Types
57120
58121The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
0 commit comments