square-sdk-cli 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Karthik Dilliraj
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -55,11 +55,20 @@ square payments --help
55
55
  square terminal actions create --help
56
56
 
57
57
  # Call methods
58
- square payments list
58
+ square locations list
59
+ square catalog list
60
+ square payments list --sortField CREATED_AT
61
+ square customers list --sortField DEFAULT --sortOrder ASC
59
62
  square payments create --json '{"sourceId":"...","idempotencyKey":"..."}' --amountMoney.amount 100 --amountMoney.currency USD
60
- square customers list --stream
63
+ square customers list --sortField DEFAULT --sortOrder ASC --stream
61
64
  ```
62
65
 
66
+ > Note: some `list` endpoints (e.g. `payments`, `customers`) require explicit
67
+ > sort flags — the Square SDK serializes a missing sort field as an empty string
68
+ > and the API rejects it with `INVALID_ENUM_VALUE ... sort_field`. Pass
69
+ > `--sortField` (and `--sortOrder` for `customers`) as shown above. Endpoints
70
+ > like `locations` and `catalog` need no arguments.
71
+
63
72
  ### Request body
64
73
 
65
74
  - `--json '<json>'` — full request body as JSON
package/dist/square.js CHANGED
@@ -377,19 +377,72 @@ function print(value, options = {}) {
377
377
  write(JSON.stringify(value, bigIntReplacer, 2));
378
378
  }
379
379
  }
380
+ var STATUS_REASON = {
381
+ 400: "Bad Request",
382
+ 401: "Unauthorized",
383
+ 403: "Forbidden",
384
+ 404: "Not Found",
385
+ 405: "Method Not Allowed",
386
+ 409: "Conflict",
387
+ 422: "Unprocessable Entity",
388
+ 429: "Too Many Requests",
389
+ 500: "Internal Server Error",
390
+ 503: "Service Unavailable"
391
+ };
392
+ function hintFor(e) {
393
+ const field = e.field ?? "";
394
+ if (e.code === "INVALID_ENUM_VALUE" && /^sort_/.test(field)) {
395
+ if (field === "sort_field")
396
+ return "This list endpoint needs an explicit sort field, e.g. `--sortField CREATED_AT`.";
397
+ if (field === "sort_order")
398
+ return "This list endpoint needs an explicit sort order, e.g. `--sortOrder ASC`.";
399
+ }
400
+ switch (e.code) {
401
+ case "UNAUTHORIZED":
402
+ case "ACCESS_TOKEN_EXPIRED":
403
+ case "ACCESS_TOKEN_REVOKED":
404
+ case "AUTHENTICATION_ERROR":
405
+ return "Check your access token (`square config set <profile> --token ...` or $SQUARE_ACCESS_TOKEN).";
406
+ case "FORBIDDEN":
407
+ case "INSUFFICIENT_SCOPES":
408
+ return "Your token lacks the OAuth scope/permission for this endpoint.";
409
+ case "NOT_FOUND":
410
+ return "The referenced resource does not exist in this environment (sandbox vs production?).";
411
+ case "RATE_LIMITED":
412
+ return "You hit the API rate limit — retry after a short delay.";
413
+ case "VALUE_EMPTY":
414
+ case "MISSING_REQUIRED_PARAMETER":
415
+ return e.field ? `Provide the required field: \`--${camelize(e.field)} <value>\` or via \`--json\`.` : "A required field is missing — pass it with `--<field> <value>` or `--json`.";
416
+ default:
417
+ return;
418
+ }
419
+ }
420
+ function camelize(field) {
421
+ return field.split(".").map((seg) => seg.replace(/_([a-z])/g, (_, c) => c.toUpperCase())).join(".");
422
+ }
380
423
  function renderError(err, options = {}) {
381
424
  const write = options.writeFn ?? ((msg) => process.stderr.write(msg + `
382
425
  `));
383
426
  if (err instanceof SquareError) {
384
- write(`Square API Error: HTTP ${err.statusCode}`);
385
- for (const e of err.errors) {
386
- const detail = e.detail;
387
- write(` [${e.category}] ${e.code}${detail ? ": " + detail : ""}`);
427
+ const status = err.statusCode;
428
+ const reason = status ? STATUS_REASON[status] : undefined;
429
+ const statusText = status ? `HTTP ${status}${reason ? " " + reason : ""}` : "request failed";
430
+ write(`✗ Square API request failed (${statusText})`);
431
+ const errors = err.errors ?? [];
432
+ for (const e of errors) {
433
+ write("");
434
+ write(` • ${e.detail ?? e.code}`);
435
+ if (e.field)
436
+ write(` field: ${e.field}`);
437
+ write(` code: ${e.category} / ${e.code}`);
438
+ const hint = hintFor(e);
439
+ if (hint)
440
+ write(` hint: ${hint}`);
388
441
  }
389
442
  } else if (err instanceof Error) {
390
- write(`Error: ${err.message}`);
443
+ write(`✗ Error: ${err.message}`);
391
444
  } else {
392
- write(`Error: ${String(err)}`);
445
+ write(`✗ Error: ${String(err)}`);
393
446
  }
394
447
  return 1;
395
448
  }
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "square-sdk-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Command-line interface for the Square API, exposing every SDK namespace and method via runtime introspection.",
5
+ "keywords": [
6
+ "square",
7
+ "square-api",
8
+ "square-sdk",
9
+ "cli",
10
+ "payments",
11
+ "checkout",
12
+ "bun",
13
+ "sdk"
14
+ ],
5
15
  "module": "bin/square.ts",
6
16
  "type": "module",
7
17
  "license": "MIT",