Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
square-connect
Advanced tools
This Square Connect Node.js SDK is deprecated. This SDK entered security maintenance phase on 2020-12-16 and will be RETIRED (EOL) in Q2, 2021. In the security maintenance phase, this SDK will continue to receive support and security patches but will no longer receive bug fixes or API updates. Once it is retired, support and security patches will no longer be available.
This SDK itself will continue to work indefinitely until such time that the underlying APIs are retired, at which point portions of this SDK may stop functioning. For a full list of API retirement dates, please see our Square API Lifecycle documentation.
Security Maintenance | Retired (EOL) |
---|---|
December 16, 2020 | Q2, 2021 |
To ensure that you continue to receive API updates and SDK improvements, you should migrate to the new Square Node.js SDK. Please follow the instructions below to migrate to the new SDK.
The old Connect SDK documentation is available under the /docs folder.
Follow the instructions below to migrate your apps from this deprecated Connect Node.js SDK to the new Square Node.js SDK. You need to install the new SDK and update your application code.
$ npm install square
Make the following changes to migrate your application code to the new Square SDK:
square-connect
library to import the square
library.square-connect
models with the new square
equivalents with camel case parameter names.Note: The new SDK supports TypeScript. It exports type files that you can use to type-check the SDK usage in TypeScript codebases.
Use the following examples to compare client instantiation and initialization in the deprecated SDK versus the new SDK.
This is how you import the square-connect
library, and instantiate and initialize the API client.
var SquareConnect = require('square-connect');
var defaultClient = SquareConnect.ApiClient.instance;
// To access sandbox resources, set the basePath to the sandbox URL
//defaultClient.basePath = 'https://connect.squareupsandbox.com';
// Configure OAuth2 access token for authorization: oauth2
var oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = process.env.SQUARE_ACCESS_TOKEN;
This is how you can do the same thing with the new square
library. You can import using the ES module or CommonJS module syntax, but you should not mix the two import styles in the same codebase.
Option 1: ES module import example (recommended)
import { ApiError, Client, Environment } from 'square'
const client = new Client({
timeout:3000,
environment: Environment.Production, // `Environment.Sandbox` to access sandbox resources
accessToken: process.env.SQUARE_ACCESS_TOKEN,
})
Option 2: CommonJS module import example
const { ApiError, Client, Environment } = require('square')
const client = new Client({
timeout:3000,
environment: Environment.Production, // `Environment.Sandbox` to access sandbox resources
accessToken: process.env.SQUARE_ACCESS_TOKEN,
})
As a specific example, consider the code for creating a customer in the sandbox environment.
The following example uses the square-connect
library to create a customer.
var SquareConnect = require('square-connect');
// Instantiate and initialize the API client
var defaultClient = SquareConnect.ApiClient.instance;
defaultClient.basePath = 'https://connect.squareupsandbox.com';
var oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = process.env.SQUARE_ACCESS_TOKEN;
// Unique key to ensure this operation runs only once if you need to retry
var idempotencyKey = "unique_key";
var requestBody = SquareConnect.CreateCustomerRequest.constructFromObject({
idempotency_key: idempotencyKey, // Parameters use snake case
given_name: "Amelia",
family_name: "Earhart",
email_address: "Amelia.Earhart@aviators.com"
});
// Get an instance of the Square API you want call
var customersApi = new SquareConnect.CustomersApi();
// Call the API
customersApi.createCustomer(requestBody).then(function(result) {
console.log('API called successfully. Returned data: ' + JSON.stringify(result, 0, 1));
}, function(error) {
console.error(error);
});
Now consider equivalent code that uses the new square
library. Note the following:
location_id
to locationId
.headers
and request
) and the response (statusCode
, body
, and result
). The response payload is returned as text in the body
property or as a dictionary in the result
property.import { ApiError, Client, Environment } from 'square'
// Instantiate and initialize the API client
const client = new Client({
environment: Environment.Sandbox,
accessToken: process.env.SQUARE_ACCESS_TOKEN,
})
// Get an instance of the Square API you want call
const { customersApi } = client
// Unique key to ensure this operation runs only once if you need to retry
let idempotencyKey = "unique_key"
// Call the API from within an async function
const createCustomer = async () => {
let requestBody = {
idempotencyKey: idempotencyKey, // Parameters use camel case
givenName: "Amelia",
familyName: "Earhart",
emailAddress: "Amelia.Earhart@aviators.com"
}
// Use a try/catch statement to check if the response succeeded or failed
try {
let { result } = await customersApi.createCustomer(requestBody)
console.log('API called successfully. Returned data: 'result)
} catch (error) {
if (error instanceof ApiError) {
console.log("Errors: ", error.errors)
} else {
console.log("Unexpected Error: ", error)
}
}
}
createCustomer()
That's it!
For more information about using the new Square SDK, see the Square Node.js SDK on GitHub.
For more examples that use the new Square SDK, see the Square Connect API Examples on GitHub.
Please join us in our Square developer community if you have any questions or feedback!
Version 6.20201216.0 (2020-12-16T00:00)
Orders API:
OrderLineItemPricingBlocklists. You can explicitly specify taxes and discounts in an order or automatically apply preconfigured taxes and discounts to an order. In addition, you can now block applying these taxes and discounts to a specific OrderLineItem in an order. You add the pricing_blocklists
attribute to individual line items and specify the blocked_discounts
and blocked_taxes
that you do not want to apply. For more information, see Apply Taxes and Discounts. For example walkthroughs, see Automatically Apply Discounts and Automatically Apply Taxes.
OrderPricingOptions. Previously, the pricing_options
field in an order supported only auto_apply_discounts
to enable the automatic application of preconfigured discounts. Now it also supports auto_apply_taxes
to enable the automatic application of preconfigured taxes. For more information, see Automatically apply preconfigured catalog taxes or discounts.
OrderLineItemTax. It now includes the new auto_applied
field. It indicates whether the tax was automatically applied using a preconfigured CatalogTax.
Bookings API:
Catalog API:
catalog_version
filter to return catalog objects of the specified version.Customers API:
email_address
, group_ids
, phone_number
, and reference_id
query filters are now generally available (GA).Invoices API: (beta)
custom_fields
field, which contains up to two customer-facing, seller-defined fields to display on the invoice. For more information, see Custom fields.Loyalty API: (beta)
definition
field in this type is deprecated and replaced by the new pricing_rule_reference
field. You can use pricing_rule_reference
fields to retrieve catalog objects that define the discount details for the reward tier. For more information, see Get discount details for a reward tier.Square Node.js SDK:
The new Square Node.js SDK is now GA and replaces the deprecated Connect Node.js SDK. For migration information, see the Connect SDK README.
FAQs
JavaScript client library for the Square Connect v2 API
The npm package square-connect receives a total of 3,121 weekly downloads. As such, square-connect popularity was classified as popular.
We found that square-connect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.