{"id":13696746,"url":"https://github.com/square/connect-nodejs-sdk","last_synced_at":"2025-05-03T17:32:14.087Z","repository":{"id":52660487,"uuid":"113892509","full_name":"square/connect-nodejs-sdk","owner":"square","description":"Javascript client library for the Square Connect APIs ","archived":true,"fork":false,"pushed_at":"2021-04-21T22:31:52.000Z","size":3026,"stargazers_count":81,"open_issues_count":6,"forks_count":41,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-25T19:27:56.614Z","etag":null,"topics":["sdk"],"latest_commit_sha":null,"homepage":"https://developer.squareup.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/square.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-11T18:14:02.000Z","updated_at":"2025-02-05T01:08:23.000Z","dependencies_parsed_at":"2022-09-05T19:20:18.877Z","dependency_job_id":null,"html_url":"https://github.com/square/connect-nodejs-sdk","commit_stats":null,"previous_names":["square/connect-javascript-sdk"],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fconnect-nodejs-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fconnect-nodejs-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fconnect-nodejs-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fconnect-nodejs-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/square","download_url":"https://codeload.github.com/square/connect-nodejs-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252226834,"owners_count":21714877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sdk"],"created_at":"2024-08-02T18:00:46.188Z","updated_at":"2025-05-03T17:32:13.314Z","avatar_url":"https://github.com/square.png","language":"JavaScript","funding_links":[],"categories":["Node JS"],"sub_categories":[],"readme":"# Square Connect Node.js SDK - RETIRED\n\n---\n\n[![Build Status](https://travis-ci.org/square/connect-nodejs-sdk.svg?branch=master)](https://travis-ci.org/square/connect-nodejs-sdk)\n[![npm version](https://badge.fury.io/js/square-connect.svg)](https://badge.fury.io/js/square-connect)\n[![Apache-2 license](https://img.shields.io/badge/license-Apache2-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n==================\n\n## NOTICE: The Square Connect Node.js SDK is retired and replaced by [square/square-nodejs-sdk]\nThis Connect Node.js SDK is retired as of 2021-04-21 and will not receive any updates. To continue receiving API and SDK improvements, bug fixes, and security patches, please follow the instructions below to migrate to the new [Square Node.js SDK].\n\nThe old Connect SDK documentation is available under the [/docs] folder.\n\n\u003cbr/\u003e\n\n---\n\n* [Migrate to the Square Node.js SDK](#migrate-to-the-square-nodejs-sdk)\n  * [Install the SDK](#install-the-sdk)\n  * [Update your code](#update-your-code)\n* [Example code migration](#example-code-migration)\n* [Ask the Community](#ask-the-community)\n\n---\n\n\u003cbr/\u003e\n\n## Migrate to the Square Node.js SDK\n\nFollow the instructions below to migrate your apps from this retired Connect Node.js SDK to the new [Square Node.js SDK]. You will need to install the new SDK and update your application code.\n\n### Install the Square Node.js SDK\n\n```sh\n$ npm install square\n```\n\n### Update your application code\nMake the following changes to migrate your application code to the new Square SDK:\n\n1. Change all instances that import the `square-connect` library to import the `square` library.\n1. Update the instantiation and initialization of the API client to follow the method described below.\n1. Replace `square-connect` models with the new `square` equivalents with camel case parameter names.\n1. Update code for calling Square APIs and accessing response data to follow the method described below.\n\n**Note:** The new SDK supports TypeScript. It exports type files that you can use to type-check the SDK usage in TypeScript codebases.\n\n### Client instantiation and initialization\nUse the following examples to compare client instantiation and initialization in the retired SDK versus the new SDK.\n\n#### Retired Connect SDK\nThis is how you import the `square-connect` library, and instantiate and initialize the API client.\n```javascript\nvar SquareConnect = require('square-connect');\nvar defaultClient = SquareConnect.ApiClient.instance;\n\n// To access sandbox resources, set the basePath to the sandbox URL\n//defaultClient.basePath = 'https://connect.squareupsandbox.com';\n\n// Configure OAuth2 access token for authorization: oauth2\nvar oauth2 = defaultClient.authentications['oauth2'];\noauth2.accessToken = process.env.SQUARE_ACCESS_TOKEN;\n```\n\n#### New Square SDK\nThis 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.\n\n**Option 1: ES module import example** (recommended)\n```javascript\nimport {  ApiError, Client, Environment  } from 'square'\n\nconst client = new Client({\n  timeout:3000,\n  environment: Environment.Production, // `Environment.Sandbox` to access sandbox resources\n  accessToken: process.env.SQUARE_ACCESS_TOKEN,\n})\n```\n**Option 2: CommonJS module import example**  \n```javascript\nconst {  ApiError, Client, Environment  } = require('square')\n\nconst client = new Client({\n  timeout:3000,\n  environment: Environment.Production, // `Environment.Sandbox` to access sandbox resources\n  accessToken: process.env.SQUARE_ACCESS_TOKEN,\n})\n```\n\n### Example code migration\nAs a specific example, consider the code for creating a customer in the sandbox environment.\n\n#### Retired Connect SDK\nThe following example uses the `square-connect` library to create a customer.\n```javascript\nvar SquareConnect = require('square-connect');\n\n// Instantiate and initialize the API client\nvar defaultClient = SquareConnect.ApiClient.instance;\ndefaultClient.basePath = 'https://connect.squareupsandbox.com';\nvar oauth2 = defaultClient.authentications['oauth2'];\noauth2.accessToken = process.env.SQUARE_ACCESS_TOKEN;\n\n// Unique key to ensure this operation runs only once if you need to retry\nvar idempotencyKey = \"unique_key\";\n\nvar requestBody = SquareConnect.CreateCustomerRequest.constructFromObject({\n  idempotency_key: idempotencyKey, // Parameters use snake case\n  given_name: \"Amelia\",\n  family_name: \"Earhart\",\n  email_address: \"Amelia.Earhart@aviators.com\"\n});\n\n// Get an instance of the Square API you want call\nvar customersApi = new SquareConnect.CustomersApi();\n\n// Call the API\ncustomersApi.createCustomer(requestBody).then(function(result) {\n  console.log('API called successfully. Returned data: ' + JSON.stringify(result, 0, 1));\n}, function(error) {\n  console.error(error);\n});\n```\n\n#### New Square SDK\nNow consider equivalent code that uses the new `square` library. Note the following:\n   * Calls to a Square API must be wrapped in an asynchronous function.\n   * Parameter names must be changed from snake case to camel case, for example from `location_id` to `locationId`.\n   * Square API calls return an ApiResponse or throw an ApiError. Use a try/catch statement to check whether the response succeeded or failed. Both objects contain properties that describe the request (`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.\n\n```javascript\nimport { ApiError, Client, Environment } from 'square'\n\n// Instantiate and initialize the API client\nconst client = new Client({\n  environment: Environment.Sandbox,\n  accessToken: process.env.SQUARE_ACCESS_TOKEN,\n})\n\n// Get an instance of the Square API you want call\nconst { customersApi }  = client\n\n// Unique key to ensure this operation runs only once if you need to retry\nlet idempotencyKey = \"unique_key\"\n\n// Call the API from within an async function\nconst createCustomer = async () =\u003e {\n  let requestBody = {\n    idempotencyKey: idempotencyKey,  // Parameters use camel case\n    givenName: \"Amelia\",  \n    familyName: \"Earhart\",\n    emailAddress: \"Amelia.Earhart@aviators.com\"\n  }\n\n  // Use a try/catch statement to check if the response succeeded or failed\n  try {\n    let { result } = await customersApi.createCustomer(requestBody)     \n    console.log('API called successfully. Returned data: 'result)\n  } catch (error) {\n    if (error instanceof ApiError) {\n      console.log(\"Errors: \", error.errors)\n    } else {\n      console.log(\"Unexpected Error: \", error)\n    }\n  }\n}\ncreateCustomer()\n```\n\nThat's it!\n\nFor more information about using the new Square SDK, see the [Square Node.js SDK] on GitHub.\n\nFor more examples that use the new Square SDK, see the [Square Connect API Examples] on GitHub.\n\n---\n\n\u003cbr/\u003e\n\n## Ask the community\n\nPlease join us in our [Square developer community] if you have any questions or feedback!\n\n[//]: # \"Link anchor definitions\"\n[square/square-nodejs-sdk]: https://github.com/square/square-nodejs-sdk\n[Square Node.js SDK]: https://github.com/square/square-nodejs-sdk\n[Square API Lifecycle documentation]: https://developer.squareup.com/docs/build-basics/api-lifecycle#deprecated-apis\n[/docs]: https://github.com/square/connect-nodejs-sdk/tree/master/docs/README.md\n[Square Connect API Examples]: https://github.com/square/connect-api-examples/tree/master/connect-examples/v2\n[Square developer community]: https://squ.re/slack\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fconnect-nodejs-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquare%2Fconnect-nodejs-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fconnect-nodejs-sdk/lists"}